en un clic
feature-build-loop
// Use when modifying build loop code, debugging stats/token tracking, adding CLI features, changing iteration prompts, or understanding how spectre-build works end-to-end
// Use when modifying build loop code, debugging stats/token tracking, adding CLI features, changing iteration prompts, or understanding how spectre-build works end-to-end
| name | feature-build-loop |
| description | Use when modifying build loop code, debugging stats/token tracking, adding CLI features, changing iteration prompts, or understanding how spectre-build works end-to-end |
| user-invocable | false |
Trigger: build loop, spectre-build, build iteration, validation cycle, promise tags, build stats, code review, phase awareness Confidence: high Created: 2026-02-07 Updated: 2026-02-18 Version: 3
spectre-build is an automated task execution CLI that runs Claude Code (or Codex) in a loop, completing one parent task per iteration. The CLI handles the loop; the agent handles task tracking and progress writing. It supports recursive validation cycles that catch gaps and auto-remediate, multi-agent backends, manifest-driven configs, and a pipeline abstraction for multi-stage workflows.
| Problem | How Build Loop Solves It |
|---|---|
| Manual re-prompting for multi-task builds | Runs autonomously, one task per iteration, until all tasks complete |
| No quality gate after build | Code review + validation stages catch issues before moving on |
| Session interruptions lose progress | Session persistence in .spectre/build-session.json enables spectre-build resume |
| Configuring builds is repetitive | Manifest mode: YAML frontmatter in .md files makes builds self-documenting |
| Multi-phase plans need per-phase validation | Phase-aware signals route through review/validate per phase boundary |
spectre-build --tasks docs/tasks.md --context docs/scope.md --validate --max-iterations 15
When --validate is used without --pipeline, the CLI routes through run_default_pipeline() which creates a 3-stage pipeline:
Stage lifecycle hooks (hooks.py) snapshot HEAD before build, then inject changed_files and commit_messages into context for the code review prompt.
spectre-build --tasks docs/tasks.md --context docs/scope.md
Without --validate, uses run_build_validate_cycle() with validate=False — simple build loop only, no pipeline.
spectre-build --pipeline .spectre/pipelines/full-feature.yaml --tasks docs/tasks.md
Uses run_pipeline() to load and execute a custom YAML pipeline definition.
spectre-build build.md
YAML frontmatter in .md file. If validate: true, routes to default pipeline.
spectre-build resume # prompts for confirmation
spectre-build resume -y # skip confirmation
parse_args()
├─ --pipeline → run_pipeline() (load YAML, execute)
├─ --validate (no --pipeline) → run_default_pipeline() (3-stage build/review/validate)
└─ no --validate, no --pipeline → run_build_validate_cycle(validate=False) (legacy build-only)
Same routing logic applies in run_resume() and run_manifest().
run_default_pipeline()
├─ create_default_pipeline() → PipelineConfig with 3 stages
├─ Build context dict (tasks_file_path, progress_file_path, etc.)
├─ Wire on_event callback for stats loop counting
├─ PipelineExecutor(config, runner, on_event, context, before_stage, after_stage)
└─ executor.run(stats)
├─ For each stage transition:
│ ├─ before_stage_hook(stage_name, context)
│ │ └─ For "build": snapshot HEAD into context["_phase_start_commit"]
│ ├─ stage.run(context, stats)
│ ├─ after_stage_hook(stage_name, context, result)
│ │ ├─ For "build": collect git diff, inject changed_files/commit_messages/review_fixes_path
│ │ └─ For "validate": track validated phases in context["_validated_phases"]
│ ├─ context.update(result.artifacts) — propagates phase metadata from build
│ └─ Transition based on signal → transitions map
└─ End when signal in end_signals (ALL_VALIDATED)
The agent signals completion via tags in its output text:
[[PROMISE:TASK_COMPLETE]] → task done, loop back to build[[PROMISE:PHASE_COMPLETE]] → phase done, transition to code_review[[PROMISE:BUILD_COMPLETE]] → all tasks done, transition to code_reviewPhase rules: If the tasks file has no ## Phase N: headers, never emit PHASE_COMPLETE.
When the build agent emits PHASE_COMPLETE or BUILD_COMPLETE, it also outputs a JSON block with phase metadata:
{"phase_completed": "Phase 1: ...", "completed_phase_tasks": "- [x] ...", "remaining_phases": "Phase 2: ..."}
PromiseCompletion(extract_artifacts=True) extracts this JSON into result.artifacts. The executor's context.update(result.artifacts) propagates these values to downstream stages. Code review and validate prompts use {phase_completed}, {completed_phase_tasks}, {remaining_phases}, and {validated_phases} to scope their work to the current phase.
Validated phases are tracked via after_stage_hook("validate") which appends completed phase names to context["_validated_phases"].
Prompt receives {changed_files} and {commit_messages} injected by after_stage_hook.
{review_fixes_path}, loops back to build{review_fixes_path} existence and addresses fixes firstALL_VALIDATED → all parent tasks [x] and verified → pipeline endsVALIDATED → current work verified, but unchecked tasks remain → loop back to buildGAPS_FOUND → gaps in completed work → after_stage_hook sets context["remediation_tasks_path"] to the gaps file path, loops back to buildWhen validate returns GAPS_FOUND with a gaps_file artifact:
after_stage_hook("validate") injects remediation_tasks_path into contextremediation_tasks_path is clearedPipelineExecutor accepts optional before_stage and after_stage callbacks:
before_stage: Callable[[str, dict[str, Any]], None] | None
after_stage: Callable[[str, dict[str, Any], CompletionResult], None] | None
Called in run() immediately before/after stage.run(). Errors caught and logged (don't crash pipeline).
BuildStats has build_loops, review_loops, validate_loops fieldson_event callback listening for StageCompletedEventLOOPS B:3 R:2 V:1 line between COMMITS and TOKENSresult events, model-specific pricing in _MODEL_PRICINGto_dict()/from_dict()/merge() methods on BuildStats.spectre/build-stats.json at each stage boundary via save_stats()load_stats() and merged into fresh statsclear_stats()[🪳 TEMP STATS] debug logging in stream.py and stats.py for token count diagnosisAllowed: Bash, Read, Write, Edit, Glob, Grep, LS, TodoRead, TodoWrite, Skill, Task Denied: AskUserQuestion, WebFetch, WebSearch, EnterPlanMode, NotebookEdit
"Definition != Connection != Reachability"
Three levels: Defined → Connected → Reachable
| File | Purpose | When to Modify |
|---|---|---|
build-loop/src/build_loop/cli.py | CLI orchestration, routing, run_default_pipeline | Adding CLI flags, changing execution modes |
build-loop/src/build_loop/loop.py | Core iteration loop, promise detection | Changing iteration behavior (legacy path) |
build-loop/src/build_loop/agent.py | Agent runners (Claude/Codex), tool filtering | Adding agent backends, changing tool allowlists |
build-loop/src/build_loop/stream.py | Stream-JSON event parsing, model/usage capture | Fixing stats tracking, adding event types |
build-loop/src/build_loop/stats.py | BuildStats dataclass, cost calculation, dashboard | Adding metrics, updating pricing |
build-loop/src/build_loop/validate.py | Legacy validation, JSON result parsing | Changing legacy validation flow |
build-loop/src/build_loop/hooks.py | Stage lifecycle hooks (git scope injection) | Changing what context flows between stages |
build-loop/src/build_loop/git_scope.py | Git diff utilities (snapshot_head, collect_diff) | Changing git scope capture |
build-loop/src/build_loop/prompt.py | Template loading + variable substitution | Changing prompt variables |
build-loop/src/build_loop/prompts/build.md | Build iteration prompt (phase-aware) | Changing agent instructions |
build-loop/src/build_loop/prompts/code_review.md | Code review prompt with scope injection | Changing review criteria |
build-loop/src/build_loop/prompts/validate.md | Validation prompt with D!=C!=R | Changing validation criteria |
build-loop/src/build_loop/pipeline/executor.py | PipelineExecutor with before/after hooks | Changing orchestration logic |
build-loop/src/build_loop/pipeline/loader.py | YAML loading + create_default_pipeline() | Adding pipeline factories |
build-loop/src/build_loop/pipeline/stage.py | Stage iteration + completion detection | Changing stage behavior |
build-loop/src/build_loop/pipeline/completion.py | Promise/JSON/Composite strategies | Adding completion strategies |
build-loop/src/build_loop/manifest.py | YAML frontmatter parsing | Adding manifest fields |
prompts/ directorycreate_default_pipeline() in loader.pyhooks.py.spectre/pipelines/prompts/code_review.mdprompts/validate.mdhooks.py (after_stage_hook)loader.py:create_default_pipeline()BuildStats dataclass in stats.pystream.py:process_stream_event() or via on_event callbackstats.py:print_summary()Edit build-loop/src/build_loop/prompts/build.md. Variables available:
{tasks_file_path} — absolute path to tasks file{progress_file_path} — absolute path to progress file{additional_context_paths_or_none} — formatted context paths or "None"{review_fixes_path} — path to review remediation file (if exists)assistant events are unreliable: Only result events have authoritative totals.owns_stats flag: When run_build_loop() receives external stats, it does NOT print summary.## Phase N: headers, PHASE_COMPLETE is never emitted.run_build_validate_cycle() is used for non-validate builds. Don't break it..spectre/build-stats.json at stage boundaries. Merged on resume. Cleared on successful completion.Use when modifying the plan loop, debugging plan stages, changing clarification flow, scope isolation, or understanding how spectre-build --plan works end-to-end
Use when modifying the ship loop, debugging ship stages, changing clean/test/rebase behavior, or understanding how spectre-build --ship works end-to-end
Use when user wants to search for existing knowledge, recall a specific learning, or discover what knowledge is available.
Use when planning product scaling, adding GUI/server layers, multi-model support, adversarial reviews, live steering, telemetry, scheduling/triggers, or node-based pipeline editors to spectre-build
Use when working with pipeline stages, completion strategies, build loop orchestration, or the web GUI for spectre-build
Use this skill when you see @name or /name patterns in user input without file identifiers. This means the user is trying to call a subagent or slash command using Spectre Agent Tools. The @ prefix dispatches to a subagent (e.g., '@tdd-agent write tests', '@code-reviewer check this file'). The / prefix executes a slash command (e.g., '/spectre:scope', '/spectre:plan'). Both require Spectre CLI to run specialized agents and predefined prompts.