Implement code from a finalized Level 3 spec (final.md). Uses an adaptive loop with build verification — the same ASSESS→action→VERIFY pattern as spec creation.
Implement the spec for recipe: $ARGUMENTS
Read .bts/config/settings.yaml for project-specific limits.
Use settings values if present, otherwise use defaults noted in each step.
Resolve recipe ID: If $ARGUMENTS is empty or not a recipe ID,
run bts recipe status to find the active recipe. Use its ID for
all {id} references below. If no active recipe → "No active recipe. Run /recipe blueprint first."
Verify final.md exists:
ls .bts/specs/recipes/{id}/final.md
If not found → "Run /recipe blueprint first."
Verify spec quality gate:
verify-log.jsonlCheck recipe phase:
bts recipe status
Load design context:
.bts/specs/project-map.md) for layer-specific
build and test commands. When implementing files across multiple layers,
use each layer's build command for verification (not a single global command).If tasks.json exists in the recipe directory:
Stale check: Compare tasks.json updated_at with final.md modification time.
If final.md is newer → use AskUserQuestion:
Task status recovery: Read tasks.json and find resume point:
in_progress tasks → the last session was interrupted mid-task. Read the actual file
to assess how much was written. Complete or rewrite as needed.pending tasks → start from the first pending taskdone/skipped → skip to Step 4Retry count preservation: Each task's retry_count persists across sessions.
Resume from the saved count, not from 0. If a task has retry_count=4 and max is 5,
it gets ONE more attempt before being blocked.
Read .bts/specs/recipes/{id}/final.md
Extract file-level tasks: each file to create or modify becomes a task
Determine dependency order (shared types first, then modules, then integration)
Save task list to .bts/specs/recipes/{id}/tasks.json:
{
"recipe_id": "{id}",
"started_at": "ISO8601",
"updated_at": "ISO8601",
"tasks": [
{
"id": "t-001",
"file": "src/auth/types.ts",
"action": "create",
"status": "pending",
"description": "Auth type definitions — see final.md Section 3.1",
"depends_on": [],
"retry_count": 0,
"last_error": ""
}
]
}
Update phase and log:
bts recipe log {id} --phase implement --action implement --output tasks.json --based-on final.md --result "N tasks decomposed"
Validate:
bts validate
npm install / yarn addgo mod tidypip install / poetry addEnvironment check: Run the build command once before writing any code. If it fails with "command not found" or similar environment error → stop immediately and report: "Build tool not available. Install [tool] before proceeding." Do NOT proceed to task implementation if the build environment is broken.
Reservations check: If .bts/specs/recipes/{id}/reservations.md exists,
read it before starting. When implementing a file listed in the "Affected Files"
section, warn: "[RESERVATION] This area has unresolved concerns from debate:
{concern}. Proceed with extra caution."
For each task in dependency order:
Dependency check: If a task's depends_on includes a blocked or skipped task,
auto-skip it with status "skipped" and last_error "dependency blocked: {id}".
in_progress → file may be partially written. Read the actual file
and decide: complete the remaining parts, or rewrite from scratch.pending → fresh start for this taskin_progress and save tasks.json immediatelyRun the project's build command:
# Detect and run appropriate build
# TypeScript: npx tsc --noEmit
# Go: go build ./...
# Rust: cargo check
# Python: python -m py_compile
If build fails:
retry_count in tasks.json and save last_errorlast_error.
If the error message is substantially the same as the previous attempt →
try a fundamentally different approach (different algorithm, different API, etc.)
Do NOT repeat the same fix.retry_count < implement.max_build_retries from settings, default: 5)blocked, save error, move to next taskIf build passes:
done, clear last_errorupdated_atCrash safety: tasks.json is the source of truth for implementation progress. It is written to disk (via Write tool) after every task status change. If the session crashes, the next resume reads tasks.json and knows exactly where to continue. No separate work-state save is needed during the loop — tasks.json IS the checkpoint.
bts recipe log {id} --action implement --result "task {task-id} done"
Review task status:
done or skipped → continue to Step 5blocked → use AskUserQuestion ("N task(s) blocked. How to proceed?"):
skipped, continuepending, go back to Step 3Checkpoint: Implementation tasks complete. Proceed directly to testing. Do NOT /clear — test/simulate/review steps need implementation context.
Update phase and run tests:
bts recipe log {id} --phase test
Use Skill("bts-test") with arguments: {id} The test skill will read final.md for test scenarios and tasks.json for the list of implemented files.
If tests fail (bts-test does not output <bts>TESTS PASS</bts>):
Use Skill("bts-simulate") with arguments: "code" to verify all code paths are covered.
This reads tasks.json for implemented files and final.md for expected scenarios, then walks through each scenario against the actual code.
If simulation finds GAPs or ISSUEs:
If no gaps → proceed to Step 5.5 (Review).
bts recipe log {id} --action simulate --result "N scenarios, N gaps"
Update phase:
bts recipe log {id} --phase review
Use Skill("bts-review") (full mode, no arguments — uses tasks.json for scope).
After review.md is generated, read it and fix all [ACTIONABLE] critical and major items:
If no actionable items → proceed directly to Step 6.
bts recipe log {id} --action review --output review.md --result "N critical, N major (N actionable)"
Always run sync (even if deviation.md exists from a previous run — code may have changed since then, and sync is idempotent).
After tests pass, update phase and sync:
bts recipe log {id} --phase sync
Use Skill("bts-sync") with arguments: {id}
After sync:
bts recipe log {id} --phase status
Use Skill("bts-status") with arguments: {id}
When all steps are done:
done or skippedblocked tasks remain (all resolved or skipped)<bts>IMPLEMENT DONE</bts>Implementation complete —
{id}done. Checkdeviation.mdfor any follow-up items. Next: run/bts-recipe-blueprintto start the next roadmap item, or/bts-recipe-fixfor any bugs.
If unresolved blocked tasks remain: