đŸŽ¯ Agent 0

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.

âš ī¸
The Orchestrator does not build code

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.

  1. 1
    Read config/context.json
    Checks _setup_complete. If false or file is absent, outputs the setup block and stops:
    ⛔ Setup required before starting the pipeline.
    Run:  bash SETUP.sh       (Linux / macOS)
          .\SETUP.ps1          (Windows)
  2. 2
    Check registered projects
    If registered_projects has entries, displays a numbered resume menu and waits. The user picks a number to resume from last_active_agent, or types N for a new project. If empty, continues immediately.
  3. 3
    Output status line
    ✅ Setup verified — no registered projects found. Starting new project kickoff.
  4. 4
    Output ASCII banner + info table
    Displays 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.
  5. 5
    Output build targets + welcome
    Displays 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).
💡
No step narration

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.

💡
When does a project get registered?

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 CommandTransitionWhat happens
!planDiscovery → PlanningLoads Agent 2; full contract planning begins immediately (TDD, INTERFACES, SCHEMA, TASK-GRAPH)
!buildPlanning → BuilderLoads Agent 3; continuous execution begins
!criticBuilder → CriticLoads Agent 4; 12-Dimension Product Scorecard and critique begins
!securityCritic → SecurityLoads Agent 5; 20-domain security review begins
!verifySecurity → VerifierLoads Agent 6; QA and release gate begins
(resume selection)Any stage → MaintenanceRegistered 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.

  1. 1
    Human issues !change [description]
    Example: !change add a dark mode toggle to the settings page
  2. 2
    Orchestrator emits Blast Radius Report
    Lists 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.
  3. 3
    Human approves or cancels
    !change-approve proceeds. !change-cancel discards the change and resumes normal pipeline.
  4. 4
    CHANGE_LOG.md updated; affected tasks marked STALE
    The Builder detects STALE tasks and re-derives their implementation before execution.

Pattern Library Commands

The Orchestrator manages the Pattern Library across projects.

CommandBehavior
!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.

CommandGenerates
!docsartifacts/docs/OVERVIEW.md — project summary, tech stack, features, and deployment notes derived from TDD.md, feature-spec.md, and HANDOFF.json
!docs changelogartifacts/docs/CHANGELOG.md — human-readable change history from CHANGE_LOG.md and DECISIONS.md
!docs apiartifacts/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 PlatformToolchain surfacedNotes
🌐 WebNext.js / React / Node.jsDesign contract auto-activated
🐧 LinuxGTK4 / Tauri / Python/PySide6 / RustPackaging format selected at Planning
đŸĒŸ WindowsWinUI 3 / .NET / Tauri / ElectronAuthenticode signing required for release
🍎 macOSSwift/SwiftUI / Tauri / Electron⚠ Requires macOS hardware for signing/notarization
🤖 AndroidKotlin/Compose / Flutter / React NativeKeystore signing required for Play Store
📱 iOSSwift/SwiftUI / Flutter / React Native⚠ Requires macOS/Xcode for build and signing

All Orchestrator Commands

CommandBehavior
!helpShow available commands for the current stage
!statusDisplay pipeline stage and agent status
!stateFull pipeline state including HANDOFF version and task summary
!pipelineVisual pipeline diagram with current stage highlighted
!budgetToken budget usage for current stage
!planGate: Discovery → Planning
!buildGate: Planning → Builder
!criticGate: Builder → Critic
!securityGate: Critic → Security
!verifyGate: Security → Verifier
!change [desc]Initiate spec change review; produces blast radius report
!change-approveApprove pending spec change; mark affected tasks STALE
!change-cancelDiscard pending spec change; resume normal pipeline
!pattern-addCapture current implementation as PATTERN-NNN entry
!pattern-listList all patterns in PATTERN_LIBRARY.md
!docsGenerate OVERVIEW.md from current artifacts
!docs changelogGenerate CHANGELOG.md from CHANGE_LOG.md
!docs apiGenerate API.md from openapi.yaml
!fork [name]Create a named pipeline branch for parallel exploration
!pausePause the current agent and save state
!resetReset 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.

  1. 1
    Human issues !fork [name]
    The Orchestrator calls session_fork.py, which creates two project copies with branches fork/[name]-A and fork/[name]-B.
  2. 2
    Orchestrator spawns two parallel Agent calls
    Both branches execute concurrently in a single Claude Code response — each with its own isolated working directory and pipeline state.
  3. 3
    Human reviews both branches and issues !merge [A|B]
    session_fork.py merges the winning branch back into main and cleans up the losing branch. The pipeline resumes on the merged codebase.
â„šī¸
Use forking for high-uncertainty architecture decisions

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:

  1. Reads the git commit SHA stored in TASK-003's checkpoint entry in HANDOFF.json
  2. Performs a git reset to that commit
  3. Marks all tasks after TASK-003 as PENDING in TASK-GRAPH.md
  4. Resumes Builder execution from TASK-004
âš ī¸
Replay is destructive

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 phraseSuggested 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
â„šī¸
Hints, not auto-advance

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.

MetricDescription
Context window %Current context fill as a percentage of the model's maximum window
Cumulative tokensTotal input + output tokens consumed since session start
Per-agent breakdownToken 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:

CommandBehavior
!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.
âš ī¸
These commands are context-sensitive

!migration-approve and !migration-cancel are only valid when a Migration Risk Report is active. Issuing them outside that context produces an error.