forge-workflow 0.0.1

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 (105) hide show
  1. package/.claude/commands/dev.md +314 -0
  2. package/.claude/commands/plan.md +389 -0
  3. package/.claude/commands/premerge.md +179 -0
  4. package/.claude/commands/research.md +42 -0
  5. package/.claude/commands/review.md +442 -0
  6. package/.claude/commands/rollback.md +721 -0
  7. package/.claude/commands/ship.md +134 -0
  8. package/.claude/commands/sonarcloud.md +152 -0
  9. package/.claude/commands/status.md +77 -0
  10. package/.claude/commands/validate.md +237 -0
  11. package/.claude/commands/verify.md +221 -0
  12. package/.claude/rules/greptile-review-process.md +285 -0
  13. package/.claude/rules/workflow.md +105 -0
  14. package/.claude/scripts/greptile-resolve.sh +526 -0
  15. package/.claude/scripts/load-env.sh +32 -0
  16. package/.forge/hooks/check-tdd.js +240 -0
  17. package/.github/PLUGIN_TEMPLATE.json +32 -0
  18. package/.mcp.json.example +12 -0
  19. package/AGENTS.md +169 -0
  20. package/CLAUDE.md +99 -0
  21. package/LICENSE +21 -0
  22. package/README.md +414 -0
  23. package/bin/forge-cmd.js +313 -0
  24. package/bin/forge-validate.js +303 -0
  25. package/bin/forge.js +4228 -0
  26. package/docs/AGENT_INSTALL_PROMPT.md +342 -0
  27. package/docs/ENHANCED_ONBOARDING.md +602 -0
  28. package/docs/EXAMPLES.md +482 -0
  29. package/docs/GREPTILE_SETUP.md +400 -0
  30. package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
  31. package/docs/ROADMAP.md +359 -0
  32. package/docs/SETUP.md +632 -0
  33. package/docs/TOOLCHAIN.md +849 -0
  34. package/docs/VALIDATION.md +363 -0
  35. package/docs/WORKFLOW.md +400 -0
  36. package/docs/planning/PROGRESS.md +396 -0
  37. package/docs/plans/.gitkeep +0 -0
  38. package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
  39. package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
  40. package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
  41. package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
  42. package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
  43. package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
  44. package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
  45. package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
  46. package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
  47. package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
  48. package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
  49. package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
  50. package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
  51. package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
  52. package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
  53. package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
  54. package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
  55. package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
  56. package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
  57. package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
  58. package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
  59. package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
  60. package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
  61. package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
  62. package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
  63. package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
  64. package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
  65. package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
  66. package/docs/research/TEMPLATE.md +292 -0
  67. package/docs/research/advanced-testing.md +297 -0
  68. package/docs/research/agent-permissions.md +167 -0
  69. package/docs/research/dependency-chain.md +328 -0
  70. package/docs/research/forge-workflow-v2.md +550 -0
  71. package/docs/research/plugin-architecture.md +772 -0
  72. package/docs/research/pr4-cli-automation.md +326 -0
  73. package/docs/research/premerge-verify-restructure.md +205 -0
  74. package/docs/research/skills-restructure.md +508 -0
  75. package/docs/research/sonarcloud-perfection-plan.md +166 -0
  76. package/docs/research/sonarcloud-quality-gate.md +184 -0
  77. package/docs/research/superpowers-integration.md +403 -0
  78. package/docs/research/superpowers.md +319 -0
  79. package/docs/research/test-environment.md +519 -0
  80. package/install.sh +1062 -0
  81. package/lefthook.yml +39 -0
  82. package/lib/agents/README.md +198 -0
  83. package/lib/agents/claude.plugin.json +28 -0
  84. package/lib/agents/cline.plugin.json +22 -0
  85. package/lib/agents/codex.plugin.json +19 -0
  86. package/lib/agents/copilot.plugin.json +24 -0
  87. package/lib/agents/cursor.plugin.json +25 -0
  88. package/lib/agents/kilocode.plugin.json +22 -0
  89. package/lib/agents/opencode.plugin.json +20 -0
  90. package/lib/agents/roo.plugin.json +23 -0
  91. package/lib/agents-config.js +2112 -0
  92. package/lib/commands/dev.js +513 -0
  93. package/lib/commands/plan.js +696 -0
  94. package/lib/commands/recommend.js +119 -0
  95. package/lib/commands/ship.js +377 -0
  96. package/lib/commands/status.js +378 -0
  97. package/lib/commands/validate.js +602 -0
  98. package/lib/context-merge.js +359 -0
  99. package/lib/plugin-catalog.js +360 -0
  100. package/lib/plugin-manager.js +166 -0
  101. package/lib/plugin-recommender.js +141 -0
  102. package/lib/project-discovery.js +491 -0
  103. package/lib/setup.js +118 -0
  104. package/lib/workflow-profiles.js +203 -0
  105. package/package.json +115 -0
@@ -0,0 +1,314 @@
1
+ ---
2
+ description: Subagent-driven TDD implementation per task from /plan task list
3
+ ---
4
+
5
+ Implement each task from the /plan task list using a subagent-driven loop: implementer → spec compliance reviewer → code quality reviewer per task.
6
+
7
+ # Dev
8
+
9
+ This command reads the task list created by `/plan` and implements each task using a three-stage subagent loop. TDD is enforced inside each implementer subagent.
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ /dev
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Setup
20
+
21
+ ### Step 1: Load context
22
+
23
+ ```bash
24
+ # Find task list and design doc
25
+ ls docs/plans/
26
+ ```
27
+
28
+ Read:
29
+ - **Task list**: `docs/plans/YYYY-MM-DD-<slug>-tasks.md` — extract ALL task text upfront
30
+ - **Design doc**: `docs/plans/YYYY-MM-DD-<slug>-design.md` — including ambiguity policy section
31
+
32
+ ### Step 2: Create decisions log
33
+
34
+ Create an empty decisions log at the start of every /dev session:
35
+
36
+ ```bash
37
+ # docs/plans/YYYY-MM-DD-<slug>-decisions.md
38
+ ```
39
+
40
+ Format for each entry:
41
+ ```
42
+ ## Decision N
43
+ **Date**: YYYY-MM-DD
44
+ **Task**: Task N — <title>
45
+ **Gap**: [what the spec didn't cover]
46
+ **Score**: [filled checklist total]
47
+ **Route**: PROCEED / SPEC-REVIEWER / BLOCKED
48
+ **Choice made**: [if PROCEED: what was decided and why]
49
+ **Status**: RESOLVED / PENDING-DEVELOPER-INPUT
50
+ ```
51
+
52
+ ### Step 3: Pre-flight checks
53
+
54
+ ```
55
+ <HARD-GATE: /dev start>
56
+ Do NOT write any code until ALL confirmed:
57
+ 1. git branch --show-current output is NOT main or master
58
+ 2. git worktree list shows the worktree path for this feature
59
+ 3. Task list file confirmed to exist (use Read tool — do not assume)
60
+ 4. Decisions log file created
61
+ </HARD-GATE>
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Per-Task Loop
67
+
68
+ Repeat for each task in the task list, in order:
69
+
70
+ ### Step A: Dispatch implementer subagent
71
+
72
+ Provide the subagent with:
73
+ - **Full task text** (copy the complete task content — do NOT send just the file path)
74
+ - **Relevant design doc sections** for this task
75
+ - **Recent git log** showing what has already been implemented
76
+
77
+ The implementer subagent:
78
+ 1. Asks clarifying questions before writing any code
79
+ 2. Implements using RED-GREEN-REFACTOR
80
+ 3. Self-reviews for correctness
81
+ 4. Commits with a descriptive message
82
+
83
+ ```
84
+ <HARD-GATE: TDD enforcement (inside implementer subagent)>
85
+ Do NOT write any production code until:
86
+ 1. A FAILING test exists for that code
87
+ 2. The test has been run and output shows it FAILING
88
+ 3. The failure reason matches the expected missing behavior
89
+
90
+ If code was written before its test: delete it. Start with the test.
91
+ "The test would obviously fail" is not evidence. Run it and show the output.
92
+ </HARD-GATE>
93
+ ```
94
+
95
+ ---
96
+
97
+ ### Step B: Decision gate (when implementer hits a spec gap)
98
+
99
+ If the implementer encounters something not specified in the design doc, STOP and fill this checklist BEFORE deciding how to proceed:
100
+
101
+ ```
102
+ Gap: [describe exactly what the spec doesn't cover]
103
+
104
+ Score each dimension (0=No / 1=Possibly / 2=Yes):
105
+ [ ] 1. Files affected beyond the current task?
106
+ [ ] 2. Changes a function signature or public export?
107
+ [ ] 3. Changes a shared module used by other tasks?
108
+ [ ] 4. Changes or touches persistent data or schema?
109
+ [ ] 5. Changes user-visible behavior not discussed in design doc?
110
+ [ ] 6. Affects auth, permissions, or data exposure?
111
+ [ ] 7. Hard to reverse without cascading changes to other files?
112
+ TOTAL: ___ / 14
113
+
114
+ Mandatory overrides — any of these = automatically BLOCKED:
115
+ [ ] Security dimension (6) scored 2
116
+ [ ] Schema migration or data model change
117
+ [ ] Removes or changes an existing public API endpoint
118
+ [ ] Affects a task that is already implemented and committed
119
+ ```
120
+
121
+ **Score routing**:
122
+ - **0-3**: PROCEED — make the decision, document in decisions log with full reasoning
123
+ - **4-7**: SPEC-REVIEWER — route this decision to spec reviewer. Continue other independent tasks while waiting
124
+ - **8+, or any mandatory override triggered**: BLOCKED — document in decisions log with Status=PENDING-DEVELOPER-INPUT. Complete all other independent tasks first. Surface to developer at /dev exit
125
+
126
+ Log the decision entry before continuing.
127
+
128
+ ---
129
+
130
+ ### Step C: Spec compliance review
131
+
132
+ After the implementer finishes the task, dispatch a **spec compliance reviewer** subagent.
133
+
134
+ Provide:
135
+ - Full task text (what was supposed to be implemented)
136
+ - Relevant design doc sections
137
+ - `git diff` for this task's commits
138
+
139
+ Reviewer checks:
140
+ - All requirements from the task text are implemented
141
+ - Nothing extra was added beyond task scope
142
+ - Edge cases documented in design doc are handled
143
+ - TDD evidence: test exists, test was run failing, then passing
144
+
145
+ If spec issues found: implementer fixes → re-review → repeat until ✅
146
+
147
+ ```
148
+ <HARD-GATE: spec before quality>
149
+ Do NOT dispatch code quality reviewer until spec compliance reviewer returns ✅ for this task.
150
+ Running quality review before spec compliance is the wrong order.
151
+ </HARD-GATE>
152
+ ```
153
+
154
+ ---
155
+
156
+ ### Step D: Code quality review
157
+
158
+ After spec ✅, dispatch a **code quality reviewer** subagent.
159
+
160
+ Provide:
161
+ - git SHAs for this task's commits
162
+ - The changed code (`git diff`)
163
+
164
+ Reviewer checks:
165
+ - Naming: clear, descriptive, consistent with codebase conventions
166
+ - Structure: functions not too long, proper separation of concerns
167
+ - Duplication: no copy-paste that could be extracted
168
+ - Test coverage: tests cover happy path and at least one error path
169
+ - No magic numbers, no commented-out code, no TODO without a Beads issue
170
+
171
+ If quality issues found: implementer fixes → re-review → repeat until ✅
172
+
173
+ ---
174
+
175
+ ### Step E: Task completion
176
+
177
+ ```
178
+ <HARD-GATE: task completion>
179
+ NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE.
180
+
181
+ Do NOT mark task complete or move to next task until ALL confirmed in this session:
182
+ 1. Spec compliance reviewer returned ✅
183
+ 2. Code quality reviewer returned ✅
184
+ 3. Identify what command proves this task is done (e.g. `bun test`, a CLI invocation, a script run).
185
+ 4. Run it fresh — show the actual output. "Last run was fine" is not evidence.
186
+ 5. Tests run fresh — actual output shows passing.
187
+ 6. Implementer has committed (git log shows the commit).
188
+ 7. `bash scripts/beads-context.sh update-progress <id> <task-num> <total> "<title>" <commit-sha> <test-count> <gate-count>` ran successfully (exit code 0). If it fails: STOP. Show error. Do not proceed to next task.
189
+
190
+ Forbidden phrases (these are not evidence):
191
+ - "should pass"
192
+ - "looks good"
193
+ - "seems to work"
194
+ </HARD-GATE>
195
+ ```
196
+
197
+ Mark task complete. Move to next task.
198
+
199
+ ---
200
+
201
+ ## /dev Completion
202
+
203
+ After all tasks are complete (or BLOCKED):
204
+
205
+ ### Final code review
206
+
207
+ Dispatch a final code reviewer for the full implementation:
208
+ - Overall coherence: does the feature hang together as a whole?
209
+ - Cross-task consistency: naming, patterns, style consistent across all tasks?
210
+ - Integration: do all the pieces connect correctly?
211
+
212
+ ### Surface BLOCKED decisions
213
+
214
+ If any decisions have Status=PENDING-DEVELOPER-INPUT:
215
+
216
+ ```
217
+ ⏸️ /dev blocked — developer input needed
218
+
219
+ The following decisions were deferred during implementation:
220
+
221
+ Decision 1: [gap description]
222
+ Task: Task N — <title>
223
+ Score: 11/14 (mandatory override: schema change)
224
+ Options considered: [A] vs [B]
225
+ Recommendation: [A] because [reason]
226
+ Blocked tasks: Task 6, Task 7 (depend on this decision)
227
+
228
+ Decision 2: ...
229
+
230
+ Please review and respond. After decisions are resolved, the implementer
231
+ will complete the blocked tasks and re-run spec + quality review.
232
+ ```
233
+
234
+ Wait for developer input. After decisions resolved: implement blocked tasks → spec review → quality review → complete.
235
+
236
+ ### /dev exit gate
237
+
238
+ ```
239
+ <HARD-GATE: /dev exit>
240
+ Do NOT declare /dev complete until:
241
+ 1. All tasks are marked complete OR have BLOCKED status with PENDING-DEVELOPER-INPUT
242
+ 2. BLOCKED decisions have been surfaced to developer and are awaiting input
243
+ 3. Final code reviewer has approved (or issues fixed and re-reviewed)
244
+ 4. All decisions in decisions log have Status of RESOLVED or PENDING-DEVELOPER-INPUT
245
+ 5. No unresolved spec or quality issues remain
246
+ </HARD-GATE>
247
+ ```
248
+
249
+ ### Beads update
250
+
251
+ ```bash
252
+ bash scripts/beads-context.sh stage-transition <id> dev validate
253
+ ```
254
+
255
+ ---
256
+
257
+ ## Decision Gate Calibration
258
+
259
+ The frequency of decision gates is a **plan quality metric**:
260
+ - **0 gates fired**: Excellent — Phase 1 Q&A covered all cases
261
+ - **1-2 gates fired**: Good — minor gaps, normal
262
+ - **3-5 gates fired**: Plan was incomplete — note for Phase 1 improvement next feature
263
+ - **5+ gates fired**: Phase 1 Q&A was insufficient — the ambiguity policy field needed to be more specific
264
+
265
+ Document the gate count in the final commit message.
266
+
267
+ ---
268
+
269
+ ## Example Output (all tasks complete)
270
+
271
+ ```
272
+ ✓ Task 1: Types and interfaces — COMPLETE
273
+ Spec: ✅ Quality: ✅ Tests: 4/4 passing Commit: abc1234
274
+ Decision gates: 0
275
+
276
+ ✓ Task 2: Validation logic — COMPLETE
277
+ Spec: ✅ Quality: ✅ Tests: 8/8 passing Commit: def5678
278
+ Decision gates: 1 (PROCEED, score 2 — documented in decisions log)
279
+
280
+ ✓ Task 3: API endpoint — COMPLETE
281
+ Spec: ✅ Quality: ✅ Tests: 6/6 passing Commit: ghi9012
282
+ Decision gates: 0
283
+
284
+ ✓ Final code review: ✅ (coherent, consistent, correctly integrated)
285
+
286
+ ✓ Decisions log: docs/plans/2026-02-26-stripe-billing-decisions.md
287
+ - Decision 1: RESOLVED (score 2, proceeded with conservative choice)
288
+ - Decision gates fired: 1 (plan quality: Good)
289
+
290
+ ✓ Beads updated: forge-xyz → implementation complete
291
+
292
+ Ready for /validate
293
+ ```
294
+
295
+ ## Integration with Workflow
296
+
297
+ ```
298
+ Utility: /status → Understand current context before starting
299
+ Stage 1: /plan → Design intent → research → branch + worktree + task list
300
+ Stage 2: /dev → Implement each task with subagent-driven TDD (you are here)
301
+ Stage 3: /validate → Type check, lint, tests, security — all fresh output
302
+ Stage 4: /ship → Push + create PR
303
+ Stage 5: /review → Address GitHub Actions, Greptile, SonarCloud
304
+ Stage 6: /premerge → Update docs, hand off PR to user
305
+ Stage 7: /verify → Post-merge CI check on main
306
+ ```
307
+
308
+ ## Tips
309
+
310
+ - **Send full task text to subagents**: Never send the file path — copy the complete task text directly into the subagent prompt
311
+ - **TDD lives inside the implementer**: The implementer subagent is responsible for RED-GREEN-REFACTOR, not the orchestrating /dev session
312
+ - **Spec before quality — always**: A task that passes quality review but fails spec compliance has still failed
313
+ - **Decision gates are rare with a good plan**: If gates fire frequently, the Phase 1 Q&A needs more depth next time
314
+ - **BLOCKED ≠ failed**: Surfacing a blocked decision with documentation and a recommendation is the correct behavior
@@ -0,0 +1,389 @@
1
+ ---
2
+ description: Design intent → research → branch + worktree + task list
3
+ ---
4
+
5
+ Plan a feature from scratch: brainstorm design intent, research technical approach, then set up branch, worktree, and a complete task list ready for /dev.
6
+
7
+ # Plan
8
+
9
+ This command runs in **3 phases**. Each phase ends with a HARD-GATE. Do not skip phases.
10
+
11
+ ---
12
+
13
+ ```
14
+ <HARD-GATE: /plan entry — worktree isolation>
15
+ Before ANY planning work begins:
16
+
17
+ 1. Run: git branch --show-current
18
+ 2. If the current branch is NOT master/main:
19
+ - STOP. Do not begin Phase 1.
20
+ - Tell the user: "You are on '<branch>'. Planning must start from a clean worktree on master.
21
+ Run: git checkout master — then re-run /plan."
22
+ 3. If on master, create the worktree NOW before asking any questions:
23
+ a. git worktree add -b feat/<slug> .worktrees/<slug>
24
+ b. cd .worktrees/<slug>
25
+ 4. Confirm: "Working in isolated worktree: .worktrees/<slug> (branch: feat/<slug>)"
26
+ 5. ONLY THEN begin Phase 1.
27
+
28
+ Rationale: Planning commits (design docs, task lists) belong only to this feature's branch.
29
+ If planning runs in the main directory on a non-master branch, those commits contaminate
30
+ whatever branch is currently checked out. The worktree ensures zero cross-contamination
31
+ between parallel features or sessions.
32
+ </HARD-GATE>
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Usage
38
+
39
+ ```bash
40
+ /plan <feature-slug>
41
+ /plan <feature-slug> --strategic # Major architecture change: creates design doc PR before Phase 2
42
+ /plan <feature-slug> --continue # After --strategic PR is merged: run Phase 2 + 3
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Phase 1: Design Intent (Brainstorming)
48
+
49
+ **Goal**: Capture WHAT to build — purpose, constraints, success criteria, edge cases, approach.
50
+
51
+ ### Step 1: Explore project context
52
+
53
+ Before asking any questions, read relevant files:
54
+ - Recent commits related to this area
55
+ - Existing code in affected modules
56
+ - Any related docs, tests, or prior research
57
+
58
+ ### Step 2: Ask clarifying questions — one at a time
59
+
60
+ Ask each question in sequence. Wait for user response. Use multiple choice where possible.
61
+
62
+ Questions to cover (adapt to feature, don't ask mechanical copies):
63
+ 1. **Purpose** — What problem does this solve? Who benefits?
64
+ 2. **Constraints** — What must this NOT do? What are the hard limits?
65
+ 3. **Success criteria** — How will we know it's done? What is the minimum viable result?
66
+ 4. **Edge cases** — What happens when [key dependency] fails / [input] is missing / [state] is ambiguous?
67
+ 5. **Technical preferences** — Library A or B? Pattern X or Y? (when real options exist)
68
+ 6. **Ambiguity policy** — If a spec gap is found mid-dev, should the agent: (a) make a reasonable choice and document it, or (b) pause and wait for input?
69
+
70
+ ### Step 3: Propose approaches
71
+
72
+ Propose 2-3 concrete approaches with:
73
+ - Trade-offs (speed vs safety, complexity vs flexibility)
74
+ - A clear recommendation with reasoning
75
+ - Get user approval on the chosen approach
76
+
77
+ ### Step 4: Write design doc
78
+
79
+ Save to `docs/plans/YYYY-MM-DD-<slug>-design.md` with these sections:
80
+ - **Feature**: slug, date, status
81
+ - **Purpose**: what problem it solves
82
+ - **Success criteria**: measurable, specific
83
+ - **Out of scope**: explicit boundaries
84
+ - **Approach selected**: which option and why
85
+ - **Constraints**: hard limits
86
+ - **Edge cases**: decisions made during Q&A
87
+ - **Ambiguity policy**: agent's fallback when spec gaps arise mid-dev
88
+
89
+ Commit the design doc:
90
+ ```bash
91
+ git add docs/plans/YYYY-MM-DD-<slug>-design.md
92
+ git commit -m "docs: add design doc for <slug>"
93
+ ```
94
+
95
+ ---
96
+
97
+ **--strategic flag** (for major architecture changes):
98
+
99
+ After committing the design doc, push to a proposal branch and open PR:
100
+ ```bash
101
+ git checkout -b feat/<slug>-proposal
102
+ git push -u origin feat/<slug>-proposal
103
+ gh pr create --title "Design: <feature-name>" \
104
+ --body "Design doc for review. See docs/plans/YYYY-MM-DD-<slug>-design.md"
105
+ ```
106
+
107
+ **STOP here.** Present the PR URL. Wait for the user to merge the proposal PR.
108
+ After merge, run `/plan <slug> --continue` to proceed to Phase 2 + 3.
109
+
110
+ ---
111
+
112
+ ```
113
+ <HARD-GATE: Phase 1 exit>
114
+ Do NOT begin Phase 2 (web research) until:
115
+ 1. User has approved the design in this session
116
+ 2. Design doc exists at docs/plans/YYYY-MM-DD-<slug>-design.md
117
+ 3. Design doc includes: success criteria, edge cases, out-of-scope, ambiguity policy
118
+ 4. Design doc is committed to git
119
+ </HARD-GATE>
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Phase 2: Technical Research
125
+
126
+ **Goal**: Find HOW to build it — best practices, known issues, security risks, TDD scenarios.
127
+
128
+ Run these in parallel:
129
+
130
+ ### Web research (parallel-deep-research skill)
131
+ ```
132
+ Skill("parallel-deep-research")
133
+ ```
134
+ Search for:
135
+ - "[tech stack] [feature] best practices [year]"
136
+ - "[library/framework] [feature] implementation patterns"
137
+ - "Known issues / gotchas with [approach selected]"
138
+
139
+ ### OWASP Top 10 analysis
140
+
141
+ For this feature's risk surface, document each relevant OWASP category:
142
+ - What the risk is
143
+ - Whether it applies to this feature
144
+ - What mitigation will be implemented
145
+
146
+ ### Codebase exploration (Explore agent)
147
+ - Similar existing patterns to reuse
148
+ - Files this feature will affect
149
+ - Existing test infrastructure to leverage
150
+
151
+ ### DRY check (mandatory — use actual search tools)
152
+
153
+ Before finalizing the approach, run Grep/Glob/Read searches for existing implementations of the planned function or pattern. Do not rely on memory or assumptions — execute the searches.
154
+
155
+ ```
156
+ Grep(searchTerm) # e.g., the function or concept name
157
+ Glob("**/*.js") # narrow to affected file types if needed
158
+ Read(matchedFile) # inspect any match in context
159
+ ```
160
+
161
+ If a match is found:
162
+ - Update the design doc's "Approach selected" section to say "extend existing [file/function]" — not "create new".
163
+ - Note the existing file path and line number in the design doc.
164
+
165
+ If no match is found: proceed. The DRY gate is cleared.
166
+
167
+ ### Blast-radius search (mandatory for remove/rename/replace features)
168
+
169
+ If this feature involves **removing**, **renaming**, or **replacing** a concept, tool, or dependency:
170
+
171
+ 1. Grep the ENTIRE codebase for the thing being removed/renamed:
172
+ ```
173
+ Grep("<thing-being-removed>") # exact name
174
+ Grep("<thing-being-removed>", -i) # case-insensitive variant
175
+ Glob("**/*<thing>*") # files named after it
176
+ ```
177
+
178
+ 2. For EVERY match found:
179
+ - Note the file path and line number in the design doc
180
+ - Add a cleanup task to the task list (Phase 3)
181
+ - Flag matches in unexpected packages or config files explicitly
182
+
183
+ 3. Common hiding spots to check:
184
+ - `package.json` (scripts, dependencies, description)
185
+ - `install.sh` / setup scripts
186
+ - CI/CD workflows (`.github/workflows/`)
187
+ - Agent config files (`lib/agents/`, `.cursorrules`, etc.)
188
+ - Documentation (`docs/`, `README.md`, `AGENTS.md`)
189
+ - Import statements and require() calls
190
+
191
+ If no removal/rename is involved, this section is skipped.
192
+
193
+ ### TDD test scenarios
194
+
195
+ Identify at minimum 3 test scenarios:
196
+ - Happy path
197
+ - Error / failure path
198
+ - Edge case from Phase 1
199
+
200
+ Append all research findings to the design doc under a `## Technical Research` section (not a separate file).
201
+
202
+ ---
203
+
204
+ ```
205
+ <HARD-GATE: Phase 2 exit>
206
+ Do NOT begin Phase 3 (setup) until:
207
+ 1. OWASP analysis is documented in design doc
208
+ 2. At least 3 TDD test scenarios are identified
209
+ 3. Approach selection is confirmed (which library/pattern to use)
210
+ 4. If feature involves removal/rename: blast-radius search completed, all references added to task list
211
+ </HARD-GATE>
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Phase 3: Setup + Task List
217
+
218
+ **Goal**: Create branch, worktree, Beads issue, and a complete task list ready for /dev.
219
+
220
+ ### Step 1: Beads issue
221
+
222
+ ```bash
223
+ bd create --title="<feature-name>" --type=feature
224
+ bd update <id> --status=in_progress
225
+ ```
226
+
227
+ ### Step 2: Branch + worktree
228
+
229
+ **ALWAYS branch from master, never from the current branch.** If the working directory is on any branch other than master, the new feature branch would inherit all unmerged changes from that branch — contaminating the new feature's history.
230
+
231
+ **Note**: If the Entry HARD-GATE already created the branch and worktree (and you are already inside `.worktrees/<slug>`), skip Steps 2b–2d — they are already done.
232
+
233
+ ```bash
234
+ # Step 2a: Check if branch and worktree were already created by Entry HARD-GATE
235
+ CURRENT=$(git branch --show-current)
236
+ if [ "$CURRENT" = "feat/<slug>" ]; then
237
+ echo "✓ Branch feat/<slug> already exists (Entry HARD-GATE created it) — skipping 2b–2d"
238
+ else
239
+ # Step 2b: Verify .worktrees/ is gitignored — add if missing
240
+ git check-ignore -v .worktrees/ || echo ".worktrees/" >> .gitignore
241
+
242
+ # Step 2c: Create branch + worktree in one command (from master)
243
+ # Using -b with worktree add avoids "branch already checked out" error
244
+ git checkout master
245
+ git worktree add -b feat/<slug> .worktrees/<slug>
246
+ cd .worktrees/<slug>
247
+ fi
248
+ ```
249
+
250
+ **Why this matters**: Multiple parallel features or sessions each get their own isolated worktree. Changes to one feature never bleed into another. The main working directory can stay on any branch without affecting new feature branches.
251
+
252
+ ### Step 3: Project setup in worktree
253
+
254
+ Auto-detect and run install:
255
+ ```bash
256
+ # e.g., bun install / npm install / pip install -r requirements.txt
257
+ ```
258
+
259
+ ### Step 4: Baseline test run
260
+
261
+ ```bash
262
+ # Run full test suite in worktree
263
+ bun test # or project test command
264
+ ```
265
+
266
+ If tests fail: report which tests are failing and ask user whether to investigate or proceed anyway. Do not silently proceed past failing baseline tests.
267
+
268
+ ### Step 5: Task list creation
269
+
270
+ Read the design doc. Break implementation into granular tasks.
271
+
272
+ **Task format** (each task MUST have ALL of these):
273
+ ```
274
+ Task N: <descriptive title>
275
+ File(s): <exact file paths>
276
+ What to implement: <complete description — not "add feature X", but what specifically>
277
+ TDD steps:
278
+ 1. Write test: <test file path, what assertion, what input/output>
279
+ 2. Run test: confirm it fails with [specific expected error message]
280
+ 3. Implement: <exact function/class/component to write>
281
+ 4. Run test: confirm it passes
282
+ 5. Commit: `<type>: <message>`
283
+ Expected output: <what running the test/code produces when done>
284
+ ```
285
+
286
+ **Ordering rules**:
287
+ - Foundational/shared modules FIRST (types, utils, constants)
288
+ - Feature logic SECOND
289
+ - Integration/wiring THIRD
290
+ - Uncertain/ambiguous tasks LAST (so they can be deferred if blocked)
291
+
292
+ **YAGNI filter** (after initial task draft, before saving):
293
+
294
+ For each task, confirm it maps to a specific requirement, success criterion, or edge case in the design doc. Run `applyYAGNIFilter({ task, designDoc })` for each task.
295
+
296
+ - Tasks that match → keep as-is.
297
+ - Tasks with no anchor → flagged as "potential scope creep". Present flagged tasks to the user: "These tasks have no anchor in the design doc. Keep (specify which requirement it serves) or remove?"
298
+ - If ALL tasks are flagged → return `allFlagged: true` and tell the user: "Design doc doesn't cover all tasks — needs amendment." Do not save the task list until the design doc is updated or tasks are removed.
299
+
300
+ **Before finalizing**: flag any tasks that touch areas not fully specified in the design doc. Present flagged tasks to user for quick clarification before saving.
301
+
302
+ Save to `docs/plans/YYYY-MM-DD-<slug>-tasks.md`.
303
+
304
+ ### Step 5b: Beads context
305
+
306
+ After saving the task list, attach design context and acceptance criteria to the Beads issue so downstream stages (`/dev`, `/validate`, `/review`) can retrieve it without re-reading the design doc.
307
+
308
+ ```bash
309
+ # Link design metadata (task count + task file path) to the Beads issue
310
+ bash scripts/beads-context.sh set-design <id> <task-count> docs/plans/YYYY-MM-DD-<slug>-tasks.md
311
+
312
+ # Record the success criteria from the design doc on the issue
313
+ bash scripts/beads-context.sh set-acceptance <id> "<success-criteria from design doc>"
314
+ ```
315
+
316
+ Both commands must exit with code 0. If either fails, investigate (wrong issue ID? missing script?) before continuing.
317
+
318
+ ### Step 6: User review
319
+
320
+ Present the full task list. Allow the user to reorder, split, or remove tasks.
321
+
322
+ ---
323
+
324
+ ```
325
+ <HARD-GATE: /plan exit>
326
+ Do NOT proceed to /dev until ALL are confirmed:
327
+ 1. git branch --show-current output shows feat/<slug>
328
+ 2. git worktree list shows .worktrees/<slug>
329
+ 3. Baseline tests ran — either passing OR user confirmed to proceed past failures
330
+ 4. Beads issue is created with status=in_progress
331
+ 5. Task list exists at docs/plans/YYYY-MM-DD-<slug>-tasks.md
332
+ 6. User has confirmed task list is correct
333
+ 7. `beads-context.sh set-design` ran successfully (exit code 0)
334
+ 8. `beads-context.sh set-acceptance` ran successfully (exit code 0)
335
+ </HARD-GATE>
336
+ ```
337
+
338
+ After all HARD-GATE items pass, record the stage transition on the Beads issue:
339
+
340
+ ```bash
341
+ bash scripts/beads-context.sh stage-transition <id> plan dev
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Example Output (Phase 3 complete)
347
+
348
+ ```
349
+ ✓ Phase 1: Design intent captured
350
+ - Design doc: docs/plans/2026-02-26-stripe-billing-design.md
351
+ - Approach: Stripe SDK v4 (selected over v3)
352
+ - Ambiguity policy: Make conservative choice + document in decisions log
353
+
354
+ ✓ Phase 2: Technical research complete
355
+ - OWASP Top 10: 3 risks identified, 3 mitigations planned
356
+ - TDD scenarios: 5 identified
357
+ - Sources: 8 references
358
+
359
+ ✓ Phase 3: Setup complete
360
+ - Beads: forge-xyz (in_progress)
361
+ - Branch: feat/stripe-billing
362
+ - Worktree: .worktrees/stripe-billing (baseline: 24/24 tests passing)
363
+ - Task list: docs/plans/2026-02-26-stripe-billing-tasks.md (8 tasks)
364
+
365
+ ⏸️ Task list ready for review. Confirm to proceed.
366
+
367
+ After confirming, run: /dev
368
+ ```
369
+
370
+ ## Integration with Workflow
371
+
372
+ ```
373
+ Utility: /status → Understand current context before starting
374
+ Stage 1: /plan → Design intent → research → branch + worktree + task list (you are here)
375
+ Stage 2: /dev → Implement each task with subagent-driven TDD
376
+ Stage 3: /validate → Type check, lint, tests, security — all fresh output
377
+ Stage 4: /ship → Push + create PR
378
+ Stage 5: /review → Address GitHub Actions, Greptile, SonarCloud
379
+ Stage 6: /premerge → Update docs, hand off PR to user
380
+ Stage 7: /verify → Post-merge CI check on main
381
+ ```
382
+
383
+ ## Tips
384
+
385
+ - **Phase 1 quality = /dev autonomy**: Every ambiguity resolved in Phase 1 is a decision gate that won't fire during /dev
386
+ - **One question at a time**: Don't dump all questions at once — dialogue produces better design decisions than a questionnaire
387
+ - **Task granularity**: Target 2-5 minutes per task. If a task takes longer, split it
388
+ - **Uncertain tasks go last**: Anything ambiguous at the end of the task list can be deferred if blocked without stopping other work
389
+ - **Baseline failures matter**: Pre-existing test failures hide regressions. Fix or explicitly document them before /dev starts