Flow Implement
Execute tasks from a flow's plan using TDD workflow.
Usage
flow-implement {flow_id} or flow-implement (uses current flow)
Phase 1: Load Context
PROTOCOL: Load Flow, Project, and Parent Context.
- Read Artifacts:
.agent/specs/{flow_id}/spec.md(unified spec+plan).agent/specs/{flow_id}/learnings.md
- Read Project Context:
.agent/patterns.md - Read Parent Context:
- Check if this flow has a parent PRD/Saga.
- If yes, read
.agent/specs/<parent_id>/prd.md.
- Load Beads context:
br status(workspace overview)br ready(list unblocked tasks)br list --status in_progress(resume active work)
CRITICAL: Before starting, check .gitignore. If .agent/ is ignored, do NOT commit changes to artifacts inside it using git. Update them on disk only.
Phase 2: Select Task (Beads-First)
CRITICAL: Beads is the source of truth for task status. Do NOT update spec.md markers.
2.1 Check for Resume State
cat .agent/specs/{flow_id}/implement_state.json 2>/dev/null
2.2 Find Next Task
Primary: Use Beads
br ready
Fallback: Parse spec.md
If Beads unavailable, parse spec.md Implementation Plan section for pending tasks.
Phase 3: Task Execution (TDD)
3.1 Mark In Progress
If task not in Beads, create it first:
br create "{task_description}" --parent {epic_id} -p 2 \
--description="{what_needs_to_be_done_and_why}"
br update {new_task_id} --notes "Phase {N}, Task {M}. Files: {affected_files}. Created by flow-implement"
Then mark in progress:
br update {task_id} --status in_progress
CRITICAL: Do NOT write [~] markers to spec.md. Beads is source of truth.
3.2 Red Phase - Write Failing Tests
- Create/update test file
- Write tests that define expected behavior
- Run tests to confirm they fail
# Run tests
npm test # or pytest, cargo test, etc.
3.3 Green Phase - Implement
- Write minimum code to pass tests
- Run tests until green
3.4 Refactor Phase
- Clean up while tests pass
- Apply patterns from patterns.md
3.5 Verify Coverage
npm test -- --coverage
Target: 80% minimum
Phase 4: Commit
git add -A
git commit -m "<type>(<scope>): <description>"
Format: conventional commits
Phase 5: Sync to Beads (Source of Truth)
CRITICAL: Only update Beads. Do NOT write [x] markers to spec.md.
br close {task_id} --reason "commit: {sha}"
5.1 Log Learnings
If any patterns discovered, add to .agent/specs/{flow_id}/learnings.md
Phase 6: Save State
Save progress to .agent/specs/{flow_id}/implement_state.json:
{
"current_phase": 1,
"current_task": "1.2",
"last_commit": "abc1234",
"timestamp": "ISO timestamp"
}
Phase 7: Phase Checkpoint
At end of each phase:
- Run full test suite
- Ensure phase completion is committed
- Prompt for pattern elevation
- Ask user to verify
Continue or Stop
After each task:
Task complete. Continue to next task? [Y/n]
If continuing, loop back to Phase 2.
Critical Rules
- TDD ALWAYS - Write tests before implementation
- SMALL COMMITS - One task = one commit
- BEADS IS SOURCE OF TRUTH - Never write markers to spec.md
- LOG LEARNINGS - Capture patterns as you go
- LOCAL ONLY - Never push automatically
- USE
br ready- Always check Beads for next task
微信扫一扫