@dv.nghiem/flowdeck 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/hooks/orchestrator-guard-hook.d.ts +2 -1
  2. package/dist/hooks/orchestrator-guard-hook.d.ts.map +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +209 -146
  5. package/dist/services/telemetry.d.ts +1 -1
  6. package/dist/services/telemetry.d.ts.map +1 -1
  7. package/dist/tools/run-parallel.d.ts.map +1 -1
  8. package/docs/configuration.md +2 -0
  9. package/docs/parallel-execution.md +28 -0
  10. package/docs/workflows.md +72 -320
  11. package/package.json +1 -2
  12. package/src/commands/fd-deploy-check.md +67 -32
  13. package/src/commands/fd-discuss.md +44 -6
  14. package/src/commands/fd-fix-bug.md +47 -20
  15. package/src/commands/fd-map-codebase.md +66 -18
  16. package/src/commands/fd-multi-repo.md +130 -6
  17. package/src/commands/fd-new-feature.md +164 -21
  18. package/src/commands/fd-plan.md +66 -44
  19. package/src/commands/fd-review-code.md +69 -35
  20. package/src/commands/fd-write-docs.md +55 -23
  21. package/src/workflows/debug-flow.md +0 -119
  22. package/src/workflows/deploy-check-flow.md +0 -98
  23. package/src/workflows/discuss-flow.md +0 -97
  24. package/src/workflows/execute-flow.md +0 -233
  25. package/src/workflows/execute-phase.md +0 -145
  26. package/src/workflows/fix-bug-flow.md +0 -210
  27. package/src/workflows/map-codebase-flow.md +0 -92
  28. package/src/workflows/multi-repo-flow.md +0 -226
  29. package/src/workflows/parallel-execution-flow.md +0 -236
  30. package/src/workflows/plan-flow.md +0 -126
  31. package/src/workflows/plan-phase.md +0 -101
  32. package/src/workflows/refactor-flow.md +0 -122
  33. package/src/workflows/review-code-flow.md +0 -105
  34. package/src/workflows/spec-driven-flow.md +0 -43
  35. package/src/workflows/write-docs-flow.md +0 -95
@@ -15,9 +15,34 @@ Run a structured requirements discussion session and capture decisions.
15
15
  2. Read current phase from STATE.md.
16
16
  3. Create `.planning/phases/phase-<N>/` directory if it does not exist.
17
17
 
18
- ## Discussion Process
18
+ ## Process
19
19
 
20
- Act as `@discusser` a requirements analyst. Ask the user focused questions about the topic: **$ARGUMENTS**
20
+ ### Step 1: Load Context
21
+
22
+ Read `.planning/PROJECT.md` to understand the project vision and goals.
23
+ Read `.planning/STATE.md` to determine the current phase and context.
24
+
25
+ ### Step 2: Determine Phase
26
+
27
+ Extract the current phase number from STATE.md.
28
+ Decisions will be saved to `.planning/phases/phase-{N}/DISCUSS.md`.
29
+
30
+ ### Step 3: Invoke Discusser
31
+
32
+ Spawn @discusser agent with:
33
+ - Project context (from PROJECT.md)
34
+ - Current phase number
35
+ - Instructions to ask ONE question per turn
36
+
37
+ ### Step 4: Q&A Loop
38
+
39
+ The @discusser agent asks one question at a time.
40
+ After each user response:
41
+ - Assign D-XX number to any new decision
42
+ - Record: topic, choice, rationale
43
+ - If response conflicts with previous decision, flag the conflict
44
+
45
+ Continue until all required topics are covered or user says to stop early.
21
46
 
22
47
  Structure the discussion:
23
48
 
@@ -30,8 +55,6 @@ Ask questions one at a time. Wait for answers before proceeding.
30
55
 
31
56
  ## Decision Recording
32
57
 
33
- As the user answers, extract decisions and number them `D-01`, `D-02`, etc.
34
-
35
58
  After the discussion, write `.planning/phases/phase-<N>/DISCUSS.md`:
36
59
 
37
60
  ```markdown
@@ -43,8 +66,8 @@ After the discussion, write `.planning/phases/phase-<N>/DISCUSS.md`:
43
66
 
44
67
  ## Decisions
45
68
 
46
- D-01: <decision>
47
- D-02: <decision>
69
+ D-01: [Topic] — [Decision] ([Rationale])
70
+ D-02: [Topic] — [Decision] ([Rationale])
48
71
  ...
49
72
 
50
73
  ## Open Questions
@@ -56,6 +79,21 @@ D-02: <decision>
56
79
  - Run /fd-plan to create implementation plan from these decisions
57
80
  ```
58
81
 
82
+ ## D-05 Compliance
83
+
84
+ - Loads PROJECT.md + current phase STATE.md
85
+ - Invokes @discusser agent
86
+ - Saves decisions with D-XX numbering to DISCUSS.md
87
+ - One question at a time (no compound questions)
88
+
59
89
  ## Completion
60
90
 
61
91
  Report: decisions captured, file path, and suggest running `/fd-plan`.
92
+
93
+ ## Error Handling
94
+
95
+ D-03: Fail fast with clear error
96
+ - If PROJECT.md not found: error with "Run /new-project first"
97
+ - If STATE.md not found: error with "Project not initialized"
98
+ - If @discusser fails: error with "Discusser agent unavailable"
99
+ - No partial state saved on error
@@ -9,6 +9,22 @@ Fix a bug using the TDD red-green-refactor discipline.
9
9
 
10
10
  **Input:** $ARGUMENTS — description of the bug. Optional `--scope=<path>` to limit search scope.
11
11
 
12
+ ## Prerequisites
13
+
14
+ - `.planning/` initialized
15
+ - Bug description or reproduction steps available
16
+
17
+ ## TDD Cycle
18
+
19
+ The workflow enforces the TDD cycle with guards at each transition:
20
+
21
+ ```
22
+ BEHAVIOR → RED → GREEN → REFACTOR → complete
23
+ ↑______________| |
24
+ (loop if needed) |
25
+ Only if GREEN
26
+ ```
27
+
12
28
  ## Pre-flight
13
29
 
14
30
  1. Check `.planning/STATE.md` exists — if not, error: "Run /fd-new-project first."
@@ -16,49 +32,44 @@ Fix a bug using the TDD red-green-refactor discipline.
16
32
  3. Read `.codebase/ARCHITECTURE.md` if available — pass as context.
17
33
  4. Check `.codebase/FAILURES.json` for prior failures matching the bug description.
18
34
 
19
- ## TDD Fix Pipeline (12 steps)
20
-
21
- ```
22
- [1-2] Explore + Research → isolate root cause
23
- [3] Define behaviors → acceptance cases for the fix
24
- [4] RED → @tester writes failing regression test
25
- [5] Confirm → test MUST fail before proceeding
26
- [6] GREEN → @coder implements minimum fix
27
- [7] Confirm → test MUST pass before proceeding
28
- [8] REFACTOR → clean up (only if GREEN)
29
- [9-10] Verify → full test suite passes
30
- [11] Review → @reviewer confirms + TDD discipline check
31
- [12] Record → log fix + regression test in FAILURES.json
32
- ```
35
+ ## Process
33
36
 
34
37
  ### Steps 1-2: Explore & Research
35
38
 
36
39
  - **@researcher**: Investigate bug scope, trace root cause via ARCHITECTURE.md and source files
37
40
  - **@researcher**: Identify all affected components, list prior similar failures from FAILURES.json
38
41
 
42
+ Reproduce the bug with minimal case; document inputs and expected vs actual.
43
+
39
44
  ### Step 3: Define Behaviors
40
45
 
41
46
  Write acceptance cases describing the fix (what should happen after the bug is fixed).
42
47
 
43
- ### Step 4: RED Write Failing Test
48
+ ### Step 4: Isolate Root Cause
49
+
50
+ Spawn `@researcher` to investigate:
51
+ - Trace the execution path
52
+ - Read stack trace completely
53
+ - Check recent changes: `git log --oneline -20 -- <file>`
54
+ - Identify root cause (not symptom)
55
+
56
+ ### Step 5: RED — Write Failing Test
44
57
 
45
58
  - **@tester**: Write a regression test that reproduces the bug (it MUST fail right now)
46
59
  - Show test output proving it fails
47
60
 
48
61
  **GUARD: Do NOT proceed if test does not fail RED.**
49
62
 
50
- ### Step 5: Confirm RED
63
+ ### Step 6: Confirm RED
51
64
 
52
65
  Confirm test fails. If it passes, the bug may already be fixed or the test is wrong.
53
66
 
54
- ### Step 6: GREEN — Implement Fix
67
+ ### Step 7: GREEN — Implement Fix
55
68
 
56
69
  - **@coder**: Implement the minimum code change that makes the regression test pass
57
70
  - Do not refactor yet
58
71
 
59
- ### Step 7: Confirm GREEN
60
-
61
- Run test. It MUST pass. **GUARD: Do NOT proceed if test does not pass GREEN.**
72
+ **GUARD: Do NOT proceed if test does not pass GREEN.**
62
73
 
63
74
  ### Step 8: REFACTOR
64
75
 
@@ -88,6 +99,22 @@ Append entry to `.codebase/FAILURES.json`:
88
99
  }
89
100
  ```
90
101
 
102
+ ## Error Handling
103
+
104
+ - **GUARD VIOLATION**: If coder attempts to skip RED or GREEN phase, block and return to correct phase
105
+ - **Override mechanism**: User can override with `/fd-fix-bug --override` but every override is logged in `override_log`
106
+ - If root cause unclear: spawn `@debug-specialist` for deeper analysis
107
+ - If fix breaks tests: revert, reassess root cause, never suppress error
108
+
109
+ ## Guards Summary
110
+
111
+ | Transition | Guard | If Violated |
112
+ |-----------|-------|-------------|
113
+ | behavior → red | Test written and fails | Block until test fails |
114
+ | red → green | Test exists and fails | Block until test passes |
115
+ | green → refactor | Tests are green | Block until green |
116
+ | refactor → complete | All tests pass | Block until all pass |
117
+
91
118
  ## Completion
92
119
 
93
120
  Report: root cause, fix applied, regression test location, reviewer sign-off.
@@ -9,28 +9,76 @@ Analyze the current codebase and generate comprehensive documentation under `.co
9
9
 
10
10
  **Input:** $ARGUMENTS (pass `--incremental` to only process changed files)
11
11
 
12
- ## Steps
12
+ ## Pre-flight
13
13
 
14
- 1. Create `.codebase/` directory if it does not exist.
14
+ Check if `.codebase/` directory already exists. If present, warn and require confirmation to overwrite.
15
15
 
16
- 2. Run parallel analysis — delegate to specialist agents:
17
- - **@researcher**: Scan package files (`package.json`, `go.mod`, `pyproject.toml`, `Cargo.toml`, etc.) to identify tech stack, frameworks, and dependencies
18
- - **@architect**: Analyze directory structure, module boundaries, key entry points, and architectural patterns
19
- - **@code-explorer**: Scan source files for naming conventions, code style patterns, import conventions, and anti-patterns
20
- - **@tester**: Find test files, identify testing frameworks, coverage configuration, and testing patterns
21
- - **@researcher** (second pass): Scan for TODO/FIXME/HACK comments, large files (>500 lines), duplicated code patterns, and security concerns
16
+ ## Process
22
17
 
23
- 3. Write the following files based on analysis results:
18
+ ### Step 1: Check Existing
24
19
 
25
- - **`.codebase/STACK.md`** tech stack, frameworks, key dependencies with versions
26
- - **`.codebase/ARCHITECTURE.md`** — system design, module boundaries, key flows, data models
27
- - **`.codebase/STRUCTURE.md`** directory layout with explanations of each major directory
28
- - **`.codebase/CONVENTIONS.md`** — naming rules, code style, import conventions, patterns to follow
29
- - **`.codebase/TESTING.md`** — test frameworks, test patterns, how to run tests, coverage targets
30
- - **`.codebase/CONCERNS.md`** — technical debt, risky areas, TODO clusters, large files, security flags
20
+ If `.codebase/` directory already exists:
21
+ ```
22
+ Warning: .codebase/ already exists. Running /map-codebase will overwrite existing docs.
23
+ Continue? (y/n)
24
+ ```
25
+ If user declines, abort. If user confirms, proceed.
31
26
 
32
- 4. If `--incremental`: only update files where the underlying source has changed since the last map (check `.codebase/last_mapped` timestamp).
27
+ ### Step 2: Initialize Worktrees
33
28
 
34
- 5. Write timestamp to `.codebase/last_mapped`.
29
+ D-04: Each mapper runs in its own isolated worktree to prevent conflicts.
30
+ Create worktrees:
31
+ - `flowdeck-mapper-stack`
32
+ - `flowdeck-mapper-arch`
33
+ - `flowdeck-mapper-structure`
34
+ - `flowdeck-mapper-conventions`
35
+ - `flowdeck-mapper-testing`
36
+ - `flowdeck-mapper-concerns`
35
37
 
36
- 6. Report summary: files created/updated, key findings per category.
38
+ ### Step 3: Invoke Mappers
39
+
40
+ Spawn 6 @mapper agents in parallel:
41
+ - @mapper → STACK.md (tech stack, dependencies, versions)
42
+ - @mapper → ARCHITECTURE.md (system design, components, data flow)
43
+ - @mapper → STRUCTURE.md (file organization, directory layout)
44
+ - @mapper → CONVENTIONS.md (coding standards, naming, patterns)
45
+ - @mapper → TESTING.md (test strategy, coverage, frameworks)
46
+ - @mapper → CONCERNS.md (known issues, technical debt, risks)
47
+
48
+ Each mapper:
49
+ - Reads source files directly (no guessing)
50
+ - Outputs factual analysis only
51
+ - Writes to assigned .codebase/ doc file
52
+
53
+ ### Step 4: Wait for Completion
54
+
55
+ Wait for all 6 mapper agents to complete. If any fails:
56
+ - Log the failure
57
+ - Continue with remaining mappers
58
+ - Report which docs were not generated
59
+
60
+ ### Step 5: Cleanup
61
+
62
+ Remove all worktrees regardless of outcome (cleanup happens after all agents complete).
63
+
64
+ ### Step 6: Verify
65
+
66
+ Check that all 6 .codebase/ doc files exist and contain non-empty content.
67
+ If any are missing or empty, report which ones need regeneration.
68
+
69
+ If `--incremental`: only update files where the underlying source has changed since the last map (check `.codebase/last_mapped` timestamp).
70
+
71
+ ### Step 7: Write Timestamp
72
+
73
+ Write timestamp to `.codebase/last_mapped`.
74
+
75
+ ## Output
76
+
77
+ Report summary: files created/updated, key findings per category.
78
+
79
+ ## Error Handling
80
+
81
+ D-03: Fail fast with clear error
82
+ - If .codebase/ check fails: show clear error with remediation
83
+ - If worktree creation fails: report which worktree failed
84
+ - Do NOT save partial state on error
@@ -1,14 +1,32 @@
1
1
  ---
2
- description: Manage multi-repo registry in .planning/config.json add, list, status, or remove repos
2
+ description: Cross-repo change orchestrationanalyze-repos identify-dependencies plan-changes → execute-per-repo → verify-integration
3
3
  argument-hint: [list | add <path> [name] | remove <name> | status]
4
4
  ---
5
5
 
6
6
  # Multi-Repo
7
7
 
8
- Manage a multi-repository workspace registry.
8
+ Orchestrates a feature or fix that spans multiple repositories in a microservice architecture.
9
9
 
10
10
  **Input:** $ARGUMENTS
11
11
 
12
+ ## When to Use
13
+
14
+ - A feature requires changes in two or more services
15
+ - An API contract is changing in an upstream service with downstream consumers
16
+ - A shared library is being upgraded with a breaking change
17
+ - You need a coordinated rollout across services
18
+
19
+ Do not use for single-repo work. Use `/new-feature` instead.
20
+
21
+ ## Prerequisites
22
+
23
+ Before running this flow:
24
+ 1. `.planning/config.json` has a `sub_repos` array with the relevant repos registered
25
+ 2. All `path` values in the registry resolve to actual directories on disk
26
+ 3. A description of the intended change is available (from `/discuss` or passed directly)
27
+
28
+ If the registry is empty or not set up, run `/multi-repo --add` first.
29
+
12
30
  ## Behavior
13
31
 
14
32
  ### List (`list` or no arguments)
@@ -19,10 +37,12 @@ Read `.planning/config.json` → `repos` array. Display:
19
37
  ════════════════════════════════════
20
38
  MULTI-REPO REGISTRY
21
39
  ════════════════════════════════════
22
- frontend — ./packages/frontend (phase 2, in_progress)
23
- backend — ./packages/backend (phase 3, completed)
24
- shared — ./packages/shared (phase 1, planned)
25
- ════════════════════════════════════
40
+ user-service ../user-service upstream-api node+typescript
41
+ order-service ../order-service downstream-consumer node+typescript
42
+ shared-types ../shared-types shared-lib node+typescript
43
+ api-gateway ../api-gateway gateway nginx+lua
44
+
45
+ Path check: all 4 repos resolved ✅
26
46
  ```
27
47
 
28
48
  ### Add (`add <path> [name]`)
@@ -51,6 +71,110 @@ WORKSPACE STATUS
51
71
  Overall: 1 in progress, 1 complete, 1 planned
52
72
  ```
53
73
 
74
+ ## Execution Flow
75
+
76
+ ### Step 1: Analyze Repos
77
+
78
+ `@multi-repo-coordinator` reads `.planning/config.json` and produces a registry summary.
79
+
80
+ If any path fails to resolve, the flow stops here with a clear error. The registry must be clean before proceeding.
81
+
82
+ ### Step 2: Identify Dependencies
83
+
84
+ `@multi-repo-coordinator` and `@architect` work together to:
85
+
86
+ 1. Build the dependency graph from service roles and actual API references (scan client code, package.json, service mesh config)
87
+ 2. Classify the requested change as breaking or non-breaking for each affected service
88
+ 3. Produce the ordered change list
89
+
90
+ If any circular dependency is detected, the flow stops and reports the cycle. Circular dependencies cannot be resolved automatically.
91
+
92
+ ### Step 3: Plan Changes
93
+
94
+ `@architect` produces the cross-repo CHANGE PLAN using contract-first development:
95
+
96
+ 1. Write the new API contract or type definition before any implementation starts
97
+ 2. Confirm the contract covers all required changes without unnecessary scope creep
98
+ 3. Produce a per-repo task list ordered by the dependency graph
99
+
100
+ ### Step 4: Execute Per Repo
101
+
102
+ Changes execute in dependency order. For each repo:
103
+
104
+ 1. `@coder` implements the changes in that repo
105
+ 2. `@tester` writes and runs tests for that repo's changes
106
+ 3. No downstream repo starts until the upstream repo's changes pass tests
107
+
108
+ For non-breaking changes, `@coder` and `@tester` for a given repo run in parallel. For breaking changes, `@tester` must verify the upstream before `@coder` starts on any downstream.
109
+
110
+ If a repo's `@coder` or `@tester` fails, that repo and all downstream repos in the dependency chain are paused. Upstream repos that completed are not rolled back — they remain deployed. The flow resumes once the failing repo is fixed.
111
+
112
+ ### Step 5: Verify Integration
113
+
114
+ After all per-repo changes are complete, `@tester` and `@reviewer` run cross-repo verification:
115
+
116
+ **@tester (integration):**
117
+ ```
118
+ Task: Run end-to-end integration tests covering the full change path
119
+ Scope: user-service → order-service interaction via the new preferences endpoint
120
+ Test environment: staging (all services deployed to stage)
121
+ ```
122
+
123
+ **@reviewer (cross-repo review):**
124
+ ```
125
+ Task: Review all changed files across all repos
126
+ Check: contract adherence, no breaking changes introduced unintentionally,
127
+ consistent error handling patterns across services
128
+ ```
129
+
130
+ Both run in parallel. Integration tests failing in stage block the production rollout for the entire change set.
131
+
132
+ ## Rollout After Integration Pass
133
+
134
+ Once integration is verified in staging, deploy in dependency order:
135
+
136
+ ```
137
+ 1. shared-types → publish to package registry (semver minor)
138
+ 2. user-service → canary (5% traffic, 15 min) → stage ✅ → prod
139
+ 3. order-service → canary (after user-service prod) → stage ✅ → prod
140
+ 4. api-gateway → canary (after order-service prod) → stage ✅ → prod
141
+ ```
142
+
143
+ No downstream service enters its canary phase until the upstream service is confirmed stable in production.
144
+
145
+ ## Conflict Handling
146
+
147
+ If `@multi-repo-coordinator` detects a conflict during Step 2 or Step 3 (two concurrent changes that are incompatible), the flow pauses:
148
+
149
+ ```
150
+ FLOW PAUSED — Conflict Requires Resolution
151
+
152
+ Service A (user-service): removing `legacyUserId` from response
153
+ Service B (order-service PR #47): new consumer of `legacyUserId`
154
+ Classification: Breaking API collision
155
+
156
+ Resolution options:
157
+ A. Versioned endpoint: keep /v1/users (with legacyUserId) + add /v2/users (without)
158
+ B. Coordinate: block order-service PR #47 until user-service migration is complete
159
+ C. Reverse: defer the user-service removal until order-service removes its dependency
160
+
161
+ Owner teams: platform (user-service), commerce (order-service)
162
+ Decision required before this flow can continue.
163
+ ```
164
+
165
+ The flow does not auto-resolve conflicts. It surfaces them clearly, names the options, and waits for human direction.
166
+
167
+ ## Error Handling
168
+
169
+ | Condition | Action |
170
+ |-----------|--------|
171
+ | Registry path not found on disk | Stop at Step 1; report which path failed |
172
+ | Circular dependency in graph | Stop at Step 2; show the cycle |
173
+ | Contract review rejected | Stop at Step 3; rework contract before proceeding |
174
+ | Repo's tests fail | Pause that repo and all dependents; upstream remains deployed |
175
+ | Integration test fails | Block production rollout; report which test failed and why |
176
+ | Conflict detected | Pause flow; surface options; wait for human decision |
177
+
54
178
  ## Config Format
55
179
 
56
180
  `.planning/config.json` repos entry:
@@ -11,38 +11,181 @@ Implement a new feature using the full FlowDeck agent pipeline.
11
11
 
12
12
  ## Pre-flight
13
13
 
14
- 1. Check `.planning/STATE.md` exists — if not, error: "Run /fd-new-project first."
14
+ 1. Check `.planning/` exists — if not, error: "Run /fd-new-project first."
15
15
  2. Check `plan_confirmed: true` in STATE.md — if not, error: "Confirm plan first with /fd-plan."
16
16
  3. Read `.planning/phases/phase-<N>/PLAN.md` to get implementation steps.
17
17
  4. Read `.codebase/ARCHITECTURE.md` if it exists — pass as context.
18
18
 
19
- ## Execution Pipeline
19
+ ## TDD Cycle Per Step
20
20
 
21
- Run the following agent pipeline for feature: **$ARGUMENTS**
21
+ Each plan step follows the TDD cycle:
22
22
 
23
- ### Phase 1 — Analysis (parallel)
24
- - **@researcher**: Trace how $ARGUMENTS touches existing code, find relevant files, identify API contracts at risk
25
- - **@architect**: Identify architectural boundaries, flag integration points, check for pattern compliance
23
+ ```
24
+ BEHAVIOR RED GREEN REFACTOR next step
25
+ ↑_________| |
26
+ (loop if needed) Only if GREEN
27
+ ```
26
28
 
27
- ### Phase 2 — Implementation
28
- - **@coder**: Implement the feature following PLAN.md steps, CONVENTIONS.md patterns, and TDD discipline
29
- - Write failing tests FIRST (RED)
30
- - Implement minimum code to pass (GREEN)
31
- - Refactor if needed (REFACTOR)
29
+ ## Process
32
30
 
33
- ### Phase 3 Validation (parallel)
34
- - **@tester**: Run test suite, verify new tests pass, check coverage
35
- - **@reviewer**: Review implementation for quality, security, and convention compliance
31
+ ### Step 1: Guard Check
36
32
 
37
- ### Phase 4 — State Update
38
- - Update `.planning/STATE.md` with completed steps
39
- - Write summary to `.planning/phases/phase-<N>/RESULT.md`
33
+ Verify prerequisites:
34
+ - `.planning/` directory exists
35
+ - `.codebase/` directory exists
36
+ - `STATE.md` has `plan_confirmed: true`
37
+ - `PLAN.md` exists in current phase directory
40
38
 
41
- ## Guard Rails
39
+ Initialize TDD state:
40
+ ```yaml
41
+ tdd:
42
+ stage: behavior
43
+ cycle: 1
44
+ behaviors: []
45
+ regression_test_links: []
46
+ ```
42
47
 
43
- - Block if `tdd_enforced: true` and no tests were written
44
- - Block if any CRITICAL security issues found
45
- - Require explicit confirmation before overwriting existing public APIs
48
+ ### Step 2: Load Plan
49
+
50
+ Read the active PLAN.md from the current phase directory.
51
+ Parse the tasks list and identify which steps are complete.
52
+
53
+ ### Step 3: Define Behaviors
54
+
55
+ Spawn `@orchestrator` to generate behavior checklist from PLAN.md:
56
+ - Acceptance cases for each step
57
+ - Edge cases to test
58
+ - Expected behaviors
59
+
60
+ Store in TDD state.
61
+
62
+ ### Step 4: Identify Next Step
63
+
64
+ From PLAN.md, find the first step NOT in `steps_complete`.
65
+ Check TDD stage — only proceed if stage is appropriate for the step.
66
+
67
+ ### Step 5: Write Failing Tests (RED)
68
+
69
+ Spawn `@tester` to write tests for the step's behavior:
70
+ - **Tests MUST fail** before implementation
71
+ - Cover acceptance cases and edge cases
72
+ - Use AAA pattern (Arrange-Act-Assert)
73
+
74
+ ### Step 6: Confirm RED
75
+
76
+ Run failing tests:
77
+ - **GUARD: Do NOT proceed to Step 7 until tests fail**
78
+ - If tests pass unexpectedly, tests don't correctly describe behavior
79
+
80
+ ### Step 7: Implement Minimum (GREEN)
81
+
82
+ Spawn `@coder` to implement:
83
+ - **Minimum code** to make failing tests pass
84
+ - No speculative features
85
+ - No over-engineering
86
+
87
+ ### Step 8: Confirm GREEN
88
+
89
+ Run tests:
90
+ - **GUARD: Do NOT proceed to Step 9 until tests pass**
91
+ - If tests fail, return to Step 7
92
+
93
+ ### Step 9: Refactor (REFACTOR)
94
+
95
+ Only if GREEN:
96
+ - Clean up code for this step
97
+ - Remove dead code
98
+ - Improve readability
99
+ - **GUARD: Do not refactor if not GREEN**
100
+
101
+ ### Step 10: Verify
102
+
103
+ Run full test suite:
104
+ - All tests must pass
105
+ - If any fails, revert refactoring
106
+
107
+ ### Step 11: Review Step
108
+
109
+ Spawn `@reviewer` to check:
110
+ - Code quality, security, conventions
111
+ - TDD discipline followed
112
+ - Test coverage >= 80%
113
+ - No missing or weak tests (flag as major finding)
114
+
115
+ ### Step 12: Update State
116
+
117
+ Mark step complete via planning-state tool:
118
+ ```yaml
119
+ steps_complete: [N, ...]
120
+ last_action: "Step N complete via TDD: [behavior]"
121
+ tdd:
122
+ stage: behavior # Ready for next step
123
+ ```
124
+
125
+ ### Step 13: Loop or Complete
126
+
127
+ If more steps pending:
128
+ - Return to Step 3 (define behaviors for next step)
129
+
130
+ If all steps complete:
131
+ - Update phase status to "complete"
132
+ - Update ROADMAP.md progress
133
+ - Present completion summary
134
+
135
+ ## Wave-Based Execution
136
+
137
+ WF-03 respects wave structure from PLAN.md:
138
+ - Wave 1 steps execute first (with TDD cycle per step)
139
+ - Wave 2 steps execute after Wave 1 completes
140
+ - Wave 3 steps execute after Wave 2 completes
141
+ - No intra-wave dependencies (parallel execution)
142
+
143
+ ## Guards Summary
144
+
145
+ | Transition | Guard | If Violated |
146
+ |-----------|-------|-------------|
147
+ | behavior → red | Test written and fails | Block until test fails |
148
+ | red → green | Test exists and fails | Block until test passes |
149
+ | green → refactor | Tests are green | Block until green |
150
+ | refactor → verify | All tests pass | Block until all pass |
151
+
152
+ ## Override Mechanism
153
+
154
+ User can override with `/fd-new-feature --override`:
155
+ - Every override is logged in `override_log`
156
+ - Surface override in next review
157
+ - Flag in deploy check
158
+
159
+ ## Error Handling
160
+
161
+ D-03: Fail fast with clear error
162
+ - If guard check fails: abort with clear error and remediation
163
+ - If @coder fails: report failure, offer retry or skip
164
+ - If @reviewer finds critical issues: return to Step 7 for fixes
165
+ - No partial state saved on error
166
+
167
+ ## State Updates
168
+
169
+ STATE.md updates after each step:
170
+ ```yaml
171
+ steps_complete: [1, 2] # Added after step 2
172
+ steps_pending: [3, 4, 5] # Removed step 2
173
+ last_action: "Step 2 TDD complete: [behavior] (RED→GREEN→REFACTOR)"
174
+ tdd:
175
+ stage: behavior
176
+ cycle: 2
177
+ behaviors_completed: 2
178
+ ```
179
+
180
+ Full phase completion:
181
+ ```yaml
182
+ status: complete
183
+ last_action: "Phase N TDD complete — all steps finished"
184
+ tdd:
185
+ stage: complete
186
+ cycles_used: N
187
+ behaviors_completed: M
188
+ ```
46
189
 
47
190
  ## Completion
48
191