-
Notifications
You must be signed in to change notification settings - Fork 4
template_builderpy Workspace Assembly
The template_builder.py script is the core utility responsible for generating the analytical workspace for an investigator. It assembles discrete Markdown templates into a unified document based on the current phase, step, or specific task requirements of the intelligence cycle. By integrating with template-index.json and reference-index.json, it ensures that every stage of the investigation is equipped with the correct structured frameworks (e.g., STEEPLES, Admiralty 6x6, ACH) and database registers.
In the Claude Sleuth ecosystem, an investigation is driven by structured documentation. template_builder.py serves as the "factory" for these documents. It eliminates the manual overhead of finding and combining files by providing a CLI interface to pull together specific templates defined in the system configuration.
-
Dynamic Assembly: Combines multiple Markdown files from
skills/claude-sleuth/templates/into a single output stream or file. -
Context Awareness: Uses
skills/claude-sleuth/scripts/config.pyto resolve which templates belong to which phase or step. -
Reference Integration: Injects phase-specific guidance from
skills/claude-sleuth/references/to provide the AI agent with immediate context on the required tradecraft.
The assembly process is governed by the mapping of investigation steps to template categories (Research, Analysis, Database, and Working).
This diagram illustrates how template_builder.py (referred to here by its CLI entry point sleuth-template) resolves user flags into file paths.
graph TD
subgraph "CLI Input"
A["--phase [1-6]"]
B["--step [1-15]"]
C["--task [e.g. t3.xb]"]
D["--templates [list]"]
end
subgraph "Logic: template_builder.py"
E{"Resolve Request"}
F["Lookup PHASES / PHASE_FOLDERS"]
G["Lookup STEP_TEMPLATES"]
H["Lookup template_index.json"]
end
subgraph "Filesystem: skills/claude-sleuth/"
I["templates/research/*.md"]
J["templates/analysis/*.md"]
K["templates/database/*.md"]
L["templates/working/*.md"]
end
A --> E
B --> E
C --> E
D --> E
E --> F
E --> G
E --> H
F --> I
G --> J
H --> K
H --> L
I & J & K & L --> M["Unified Workspace Document"]
The builder relies on three primary data sources to locate and validate templates:
This file contains the STEP_TEMPLATES dictionary, which is the "source of truth" for which files are required to complete a specific step in the 15-step workflow.
| Step | Phase | Key Templates Assembled |
|---|---|---|
| 1 | 1 (OppStrat) | research/case-decision-log.md |
| 3 | 2 (IntelEpi) | research/source-grading.md |
| 6 | 3 (ColEnt) | analysis/pole.md |
| 9 | 4 (ChronRel) | analysis/chronological-matrix.md |
| 12 | 5 (HypCog) | analysis/ach.md |
Maps the six phases of the intelligence cycle to their respective folders and primary reference guidance files. This allows the builder to prepend "how-to" instructions to the generated workspace.
-
Phase 1 (oppstrat): Maps to
direction-foundation.md. -
Phase 4 (chronrel): Maps to
process.md.
While not a template itself, template_builder.py can reference tooling.md to provide the investigator with a catalog of 150+ OSINT tools verified for programmatic use, such as Sherlock, Maigret, and Holehe.
The script implements a sequential assembly pattern:
-
Argument Parsing: Handles
--phase,--step, and--task. Note that a "Task" (e.g.,t8.x) is a sub-unit of a "Step" (e.g., Step 8). -
Path Resolution: Converts template names (e.g.,
analysis/pole.md) into absolute paths within theskills/claude-sleuth/templates/directory. - Header Injection: For each template added to the workspace, the builder injects a Markdown header indicating the source file to maintain traceability.
-
Reference Appending: If a phase is specified, the script fetches the corresponding reference file from
skills/claude-sleuth/references/and appends it as an appendix to the workspace.
This diagram shows the internal function flow when sleuth-template --step 8 is invoked.
sequenceDiagram
participant CLI as "sleuth-template CLI"
participant TB as "template_builder.py"
participant CFG as "config.py"
participant REF as "reference-index.json"
participant FS as "Filesystem (Templates)"
CLI->>TB: main(step=8)
TB->>CFG: get STEP_TEMPLATES[8]
CFG-->>TB: ["subject-profiles.md", "family-network-research.md", ...]
TB->>REF: get phase for step 8
REF-->>TB: Phase 3 (colent)
loop for each template
TB->>FS: read templates/database/subject-profiles.md
FS-->>TB: content
TB->>TB: append to workspace buffer
end
TB->>FS: read references/colent/resolution.md
FS-->>TB: reference content
TB->>TB: append as "Guidance" section
TB-->>CLI: return final Markdown string
template_builder.py is frequently called as a subprocess by task_runner.py. When a user executes sleuth-task next, the task runner:
- Determines the next required step from
.sleuth-progress.json. - Calls
template_builder.pyto generate the workspace for that step. - Writes the output to the
investigation-notebook.md, providing the AI with its primary working environment skills/claude-sleuth/scripts/config.py:174.