The Orchestrator (Brain)
The brain is specdacular’s central orchestrator. It reads pipeline.json, determines the next step from task state, dispatches step workflows, executes hooks, updates state, and loops. All flow control lives here.
Design principle
Section titled “Design principle”Step workflows are pure execution — they do their work and return. They never decide what comes next. That’s exclusively the brain’s job.
This separation means:
- Any step can be replaced without touching control flow
- Hooks can modify state between steps without special treatment
- Execution modes (default, interactive, auto) are handled in one place
The brain loop
Section titled “The brain loop”┌─────────────────────────────────────────────┐│ BRAIN ││ ││ 1. Read state (config.json, STATE.md) ││ 2. Determine next step from pipeline ││ 3. Pre-hooks → step workflow → post-hooks ││ 4. Update state ││ 5. Loop back to 1 │└─────────────────────────────────────────────┘State is persisted before each dispatch. If a session ends mid-execution, the next continue picks up from the last saved state.
State machine
Section titled “State machine”The brain maintains a state machine across the task lifecycle. Each stage maps to a step in the pipeline:
discussion → research → planning → execution → completeWithin execution, there’s a nested sub-pipeline per phase:
phase-plan → execute → review → revise → (next phase)State is stored in two files:
config.json— Machine-readable: stage, phase number, phase status, timestampsSTATE.md— Human-readable: current position, next actions, plan completion table
Routing logic
Section titled “Routing logic”On each loop iteration, the brain determines $NEXT_STEP by reading the task’s current state:
| Current state | Next step |
|---|---|
Stage: discussion, gray areas remain | discuss |
Stage: discussion, all resolved | research |
Stage: research | plan (task-level) |
Stage: planning | phase-execution pipeline |
Phase status: pending, no PLAN.md | phase-plan |
Phase status: pending, PLAN.md exists | execute |
Phase status: executed | review |
Phase status: needs-revision | revise |
Phase status: completed, more phases | advance phase, phase-plan |
Phase status: completed, no more phases | task complete |
Execution modes
Section titled “Execution modes”The brain supports three modes, passed as flags to /specd.continue:
Default mode
Section titled “Default mode”Auto-runs steps that don’t have pause: true. Pauses before steps marked pause: true (execute and review in the default pipeline). Smart-skips steps that add no value:
- discuss: skipped if no gray areas remain in
CONTEXT.md - research: skipped for simple tasks with clear requirements and no external dependencies
Interactive mode (--interactive)
Section titled “Interactive mode (--interactive)”Prompts at every stage transition, regardless of the pause field. At each step, presents options:
- The recommended action (the natural next step)
- Skip options (e.g., “Skip to planning”)
- Jump options (e.g., “Discuss more”)
Does not auto-skip steps — instead marks the skip option as “Recommended” if skipping is appropriate.
Auto mode (--auto)
Section titled “Auto mode (--auto)”Runs the entire pipeline without prompting. Applies smart skipping. Stops only on:
- Pipeline errors
- Required hook failures
- Task completion
Useful for fully automated execution in CI environments or when you trust the pipeline to handle everything.
Hook execution
Section titled “Hook execution”The brain executes hooks at four points around each step:
Global pre-step hook │Step pre-hook │ ▼ Step runs │Step post-hook │Global post-step hookHooks are markdown workflow files — the same format as step workflows. They can read and modify task files, commit changes, or call external services.
Required hooks (optional: false) stop the pipeline on failure. Optional hooks log a warning and continue.
See Pipeline customization for hook configuration.
Orchestrator mode (multi-project)
Section titled “Orchestrator mode (multi-project)”When the root .specd/config.json has "type": "orchestrator", the brain operates in orchestrator mode. The pipeline is the same — orchestrator awareness lives in the step workflows that need it:
new.mddetects orchestrator mode and creates per-project tasksplan.mddetects orchestrator mode and createsDEPENDENCIES.mdexecute.mdreadsDEPENDENCIES.mdto schedule phases across projects in dependency order
The brain itself doesn’t change routing logic for orchestrator mode. Multi-project complexity is encapsulated in the step workflows.
Pipeline resolution
Section titled “Pipeline resolution”On each invocation, the brain resolves the pipeline in this order:
- Check
.specd/pipeline.json(project-level override — full replace) - Fall back to the installed default
pipeline.json
Validation checks:
schema_versionis"1.0"- All referenced workflow paths exist
- All referenced pipeline names exist
- No circular pipeline references
State persistence
Section titled “State persistence”Before dispatching any step, the brain commits:
docs({task-name}): starting {step-name}After the step completes, it commits:
docs({task-name}): {step-name} completeThis creates a dense git history that doubles as an audit trail. If a session ends between these two commits, the brain detects the incomplete state on next invocation and re-dispatches the step.
Related concepts
Section titled “Related concepts”- Pipeline lifecycle — The stages and what each produces
- Codebase mapping — How context is built before planning