Orchestrator Agent
The Orchestrator is the director of the pipeline. It never builds â it enforces gates, manages state, routes to the correct template, coordinates spec changes, and captures patterns. Every session starts and ends with the Orchestrator.
If a user asks the Orchestrator to write code, it refuses and redirects to Agent 3 (Builder). Its role is coordination and gate enforcement only.
Activation
Start agent 0
On activation, the Orchestrator runs a two-path startup check before anything else.
Startup Protocol
On Start agent 0 (case-insensitive, whitespace-forgiving), the Orchestrator
executes a fixed startup sequence â no HANDOFF.json or TASK-GRAPH.md is read first because
they don't exist on a cold start. The protocol runs identically in every supported CLI and IDE.
-
1Read
config/context.jsonChecks_setup_complete. Iffalseor file is absent, outputs the setup block and stops:â Setup required before starting the pipeline. Run: bash SETUP.sh (Linux / macOS) .\SETUP.ps1 (Windows) -
2Check registered projectsIf
registered_projectshas entries, displays a numbered resume menu and waits. The user picks a number to resume fromlast_active_agent, or types N for a new project. If empty, continues immediately. -
3Output status line
â Setup verified â no registered projects found. Starting new project kickoff. -
4Output ASCII banner + info tableDisplays the CodeSleuth ASCII art banner followed by the info table with live values from
config/context.json: Pipeline stages, Context Backends (coordination, semantic search, agent memory, external registry), Design Contract status, and the full command reference. -
5Output build targets + welcomeDisplays the CodeSleuth Build Targets table (Web, Linux, Windows, macOS, Android, iOS) then the welcome message asking for: what the project does, the target platform, and the project directory (must be outside the agents directory).
The protocol outputs blocks verbatim without narrating each step. Models that output "Step 1 complete â , now checking..." are not following the protocol correctly â the rule file explicitly forbids this.
Agent 3 (Builder) calls register_project.py at build completion â
even if the user stops there and never proceeds to Critic or Verifier.
Agents 4, 5, and 6 advance the stage from built â critiqued
â secured â shipped as the pipeline progresses.
Once registered, the project is always resident in the pipeline for every future session.
Human Gate Protocol
The Orchestrator enforces all human gates. No agent advances automatically â every transition requires an explicit command from the human.
| Gate Command | Transition | What happens |
|---|---|---|
| !plan | Discovery â Planning | Loads Agent 2; full contract planning begins immediately (TDD, INTERFACES, SCHEMA, TASK-GRAPH) |
| !build | Planning â Builder | Loads Agent 3; continuous execution begins |
| !critic | Builder â Critic | Loads Agent 4; 12-Dimension Product Scorecard and critique begins |
| !security | Critic â Security | Loads Agent 5; 20-domain security review begins |
| !verify | Security â Verifier | Loads Agent 6; QA and release gate begins |
| (resume selection) | Any stage â Maintenance | Registered projects at stage shipped or maintenance route to Agent 7 automatically |
Spec Change Protocol
The !change command initiates a formal spec change review. No implementation changes happen until the human approves the blast radius report.
-
1Human issues !change [description]Example:
!change add a dark mode toggle to the settings page -
2Orchestrator emits Blast Radius ReportLists affected tasks (PENDING/IN-PROGRESS/DONE), files, contracts, and tests. Classifies scope as Small / Medium / Large. Warns about any DONE tasks that will become STALE.
-
3Human approves or cancels!change-approve proceeds. !change-cancel discards the change and resumes normal pipeline.
-
4CHANGE_LOG.md updated; affected tasks marked STALEThe Builder detects STALE tasks and re-derives their implementation before execution.
Pattern Library Commands
The Orchestrator manages the Pattern Library across projects.
| Command | Behavior |
|---|---|
| !pattern-add | Captures the most recently completed task's implementation as a PATTERN-NNN entry in PATTERN_LIBRARY.md and indexes it in PATTERN_INDEX.md. |
| !pattern-list | Displays all patterns in the library with their domain, stack, and reuse signal keywords. |
Living Documentation
The !docs command generates human-readable documentation from the current pipeline artifacts â useful for onboarding, handoffs, and project wikis.
| Command | Generates |
|---|---|
| !docs | artifacts/docs/OVERVIEW.md â project summary, tech stack, features, and deployment notes derived from TDD.md, feature-spec.md, and HANDOFF.json |
| !docs changelog | artifacts/docs/CHANGELOG.md â human-readable change history from CHANGE_LOG.md and DECISIONS.md |
| !docs api | artifacts/docs/API.md â endpoint reference derived from openapi.yaml |
Platform Routing
The Orchestrator detects the target platform from the project brief and surfaces the correct toolchain, signing, and distribution requirements. See Platform Capabilities for the full reference.
| Detected Platform | Toolchain surfaced | Notes |
|---|---|---|
| đ Web | Next.js / React / Node.js | Design contract auto-activated |
| đ§ Linux | GTK4 / Tauri / Python/PySide6 / Rust | Packaging format selected at Planning |
| đĒ Windows | WinUI 3 / .NET / Tauri / Electron | Authenticode signing required for release |
| đ macOS | Swift/SwiftUI / Tauri / Electron | â Requires macOS hardware for signing/notarization |
| đ¤ Android | Kotlin/Compose / Flutter / React Native | Keystore signing required for Play Store |
| đą iOS | Swift/SwiftUI / Flutter / React Native | â Requires macOS/Xcode for build and signing |
All Orchestrator Commands
| Command | Behavior |
|---|---|
| !help | Show available commands for the current stage |
| !status | Display pipeline stage and agent status |
| !state | Full pipeline state including HANDOFF version and task summary |
| !pipeline | Visual pipeline diagram with current stage highlighted |
| !budget | Token budget usage for current stage |
| !plan | Gate: Discovery â Planning |
| !build | Gate: Planning â Builder |
| !critic | Gate: Builder â Critic |
| !security | Gate: Critic â Security |
| !verify | Gate: Security â Verifier |
| !change [desc] | Initiate spec change review; produces blast radius report |
| !change-approve | Approve pending spec change; mark affected tasks STALE |
| !change-cancel | Discard pending spec change; resume normal pipeline |
| !pattern-add | Capture current implementation as PATTERN-NNN entry |
| !pattern-list | List all patterns in PATTERN_LIBRARY.md |
| !docs | Generate OVERVIEW.md from current artifacts |
| !docs changelog | Generate CHANGELOG.md from CHANGE_LOG.md |
| !docs api | Generate API.md from openapi.yaml |
| !fork [name] | Create a named pipeline branch for parallel exploration |
| !pause | Pause the current agent and save state |
| !reset | Reset pipeline to initial state (requires confirmation) |
Session Forking (!fork)
The !fork command creates two isolated copies of the current project, each on its own git branch, and runs two independent pipeline paths in parallel.
-
1Human issues !fork [name]The Orchestrator calls
session_fork.py, which creates two project copies with branchesfork/[name]-Aandfork/[name]-B. -
2Orchestrator spawns two parallel Agent callsBoth branches execute concurrently in a single Claude Code response â each with its own isolated working directory and pipeline state.
-
3Human reviews both branches and issues !merge [A|B]
session_fork.pymerges the winning branch back into main and cleans up the losing branch. The pipeline resumes on the merged codebase.
When two implementation approaches are both viable and it's not clear which will be faster or cleaner, fork and build both. The parallel execution cost is lower than the cost of choosing wrong and refactoring later.
Pipeline Replay (!replay)
The !replay command restores the codebase to the git checkpoint immediately after a specific task completed, then resumes the Builder from that point.
!replay TASK-003
Internally, pipeline_replay.py:
- Reads the git commit SHA stored in
TASK-003's checkpoint entry in HANDOFF.json - Performs a git reset to that commit
- Marks all tasks after TASK-003 as PENDING in TASK-GRAPH.md
- Resumes Builder execution from TASK-004
All code written after the replay target task is discarded. Ensure commit_by_task.py has been run so each task has a clean checkpoint to restore to.
Natural Language Gate Hints
The Orchestrator monitors user messages for intent phrases that indicate readiness to advance the pipeline. When detected, it surfaces the correct gate command without auto-advancing.
| Detected phrase | Suggested command |
|---|---|
| "looks good", "that looks right", "happy with this" (after Discovery) | !plan |
| "let's build", "start building", "go ahead and build" | !build |
| "ready to ship", "looks shippable", "we're done" | !verify |
| "check security", "run the security review" | !security |
Natural language detection never automatically advances the pipeline. It only displays a suggestion like: "It sounds like you're ready to proceed â type !build to activate the Builder." The human must still type the gate command.
Token Budget (!budget)
The !budget command runs token_tracker.py and displays a real-time cost summary for the current session.
| Metric | Description |
|---|---|
| Context window % | Current context fill as a percentage of the model's maximum window |
| Cumulative tokens | Total input + output tokens consumed since session start |
| Per-agent breakdown | Token count attributed to each agent (0â6) in this session |
| Total cost (USD) | Estimated spend based on current model pricing |
token_tracker.py runs automatically after every agent turn and appends a telemetry row to artifacts/telemetry/token_log.jsonl. Use !budget at any time to see the live summary.
Migration Sub-Commands
When migration_safety.py detects a HIGH severity schema change risk, it emits a Migration Risk Report and the pipeline pauses. Two sub-commands become available â they exist only while an active migration risk report is pending:
| Command | Behavior |
|---|---|
| !migration-approve | Confirms the migration plan. Records the acceptance in HANDOFF.json and unblocks the pipeline. The Builder proceeds with the schema change and its generated SQL. |
| !migration-cancel | Discards the schema change. The SCHEMA.md edit is reverted and the task is marked STALE for replanning without the risky migration. |
!migration-approve and !migration-cancel are only valid when a Migration Risk Report is active. Issuing them outside that context produces an error.