spec-gen-cli 1.2.6 → 1.2.8

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 (198) hide show
  1. package/README.md +175 -55
  2. package/dist/api/analyze.d.ts.map +1 -1
  3. package/dist/api/analyze.js +6 -1
  4. package/dist/api/analyze.js.map +1 -1
  5. package/dist/api/audit.d.ts +10 -0
  6. package/dist/api/audit.d.ts.map +1 -0
  7. package/dist/api/audit.js +117 -0
  8. package/dist/api/audit.js.map +1 -0
  9. package/dist/api/generate.d.ts.map +1 -1
  10. package/dist/api/generate.js +10 -1
  11. package/dist/api/generate.js.map +1 -1
  12. package/dist/api/index.d.ts +3 -2
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/index.js +1 -0
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/api/run.d.ts.map +1 -1
  17. package/dist/api/run.js +5 -1
  18. package/dist/api/run.js.map +1 -1
  19. package/dist/api/types.d.ts +15 -4
  20. package/dist/api/types.d.ts.map +1 -1
  21. package/dist/cli/commands/analyze.d.ts +3 -0
  22. package/dist/cli/commands/analyze.d.ts.map +1 -1
  23. package/dist/cli/commands/analyze.js +112 -17
  24. package/dist/cli/commands/analyze.js.map +1 -1
  25. package/dist/cli/commands/audit.d.ts +9 -0
  26. package/dist/cli/commands/audit.d.ts.map +1 -0
  27. package/dist/cli/commands/audit.js +98 -0
  28. package/dist/cli/commands/audit.js.map +1 -0
  29. package/dist/cli/commands/drift.d.ts.map +1 -1
  30. package/dist/cli/commands/drift.js +8 -10
  31. package/dist/cli/commands/drift.js.map +1 -1
  32. package/dist/cli/commands/generate.d.ts.map +1 -1
  33. package/dist/cli/commands/generate.js +15 -37
  34. package/dist/cli/commands/generate.js.map +1 -1
  35. package/dist/cli/commands/mcp.d.ts +102 -2
  36. package/dist/cli/commands/mcp.d.ts.map +1 -1
  37. package/dist/cli/commands/mcp.js +134 -2
  38. package/dist/cli/commands/mcp.js.map +1 -1
  39. package/dist/cli/commands/run.d.ts.map +1 -1
  40. package/dist/cli/commands/run.js +9 -47
  41. package/dist/cli/commands/run.js.map +1 -1
  42. package/dist/cli/commands/setup.d.ts +17 -0
  43. package/dist/cli/commands/setup.d.ts.map +1 -0
  44. package/dist/cli/commands/setup.js +201 -0
  45. package/dist/cli/commands/setup.js.map +1 -0
  46. package/dist/cli/commands/verify.d.ts.map +1 -1
  47. package/dist/cli/commands/verify.js +7 -8
  48. package/dist/cli/commands/verify.js.map +1 -1
  49. package/dist/cli/index.js +14 -8
  50. package/dist/cli/index.js.map +1 -1
  51. package/dist/constants.d.ts +14 -0
  52. package/dist/constants.d.ts.map +1 -1
  53. package/dist/constants.js +14 -0
  54. package/dist/constants.js.map +1 -1
  55. package/dist/core/analyzer/ai-config-generator.d.ts +54 -0
  56. package/dist/core/analyzer/ai-config-generator.d.ts.map +1 -0
  57. package/dist/core/analyzer/ai-config-generator.js +85 -0
  58. package/dist/core/analyzer/ai-config-generator.js.map +1 -0
  59. package/dist/core/analyzer/artifact-generator.d.ts +27 -2
  60. package/dist/core/analyzer/artifact-generator.d.ts.map +1 -1
  61. package/dist/core/analyzer/artifact-generator.js +86 -8
  62. package/dist/core/analyzer/artifact-generator.js.map +1 -1
  63. package/dist/core/analyzer/codebase-digest.d.ts.map +1 -1
  64. package/dist/core/analyzer/codebase-digest.js +12 -11
  65. package/dist/core/analyzer/codebase-digest.js.map +1 -1
  66. package/dist/core/analyzer/env-extractor.d.ts +33 -0
  67. package/dist/core/analyzer/env-extractor.d.ts.map +1 -0
  68. package/dist/core/analyzer/env-extractor.js +196 -0
  69. package/dist/core/analyzer/env-extractor.js.map +1 -0
  70. package/dist/core/analyzer/http-route-parser.d.ts +36 -1
  71. package/dist/core/analyzer/http-route-parser.d.ts.map +1 -1
  72. package/dist/core/analyzer/http-route-parser.js +276 -0
  73. package/dist/core/analyzer/http-route-parser.js.map +1 -1
  74. package/dist/core/analyzer/middleware-extractor.d.ts +29 -0
  75. package/dist/core/analyzer/middleware-extractor.d.ts.map +1 -0
  76. package/dist/core/analyzer/middleware-extractor.js +195 -0
  77. package/dist/core/analyzer/middleware-extractor.js.map +1 -0
  78. package/dist/core/analyzer/schema-extractor.d.ts +41 -0
  79. package/dist/core/analyzer/schema-extractor.d.ts.map +1 -0
  80. package/dist/core/analyzer/schema-extractor.js +229 -0
  81. package/dist/core/analyzer/schema-extractor.js.map +1 -0
  82. package/dist/core/analyzer/spec-snapshot-generator.d.ts +17 -0
  83. package/dist/core/analyzer/spec-snapshot-generator.d.ts.map +1 -0
  84. package/dist/core/analyzer/spec-snapshot-generator.js +201 -0
  85. package/dist/core/analyzer/spec-snapshot-generator.js.map +1 -0
  86. package/dist/core/analyzer/ui-component-extractor.d.ts +43 -0
  87. package/dist/core/analyzer/ui-component-extractor.d.ts.map +1 -0
  88. package/dist/core/analyzer/ui-component-extractor.js +245 -0
  89. package/dist/core/analyzer/ui-component-extractor.js.map +1 -0
  90. package/dist/core/generator/openspec-format-generator.d.ts.map +1 -1
  91. package/dist/core/generator/openspec-format-generator.js +8 -0
  92. package/dist/core/generator/openspec-format-generator.js.map +1 -1
  93. package/dist/core/generator/spec-pipeline.d.ts +9 -0
  94. package/dist/core/generator/spec-pipeline.d.ts.map +1 -1
  95. package/dist/core/generator/spec-pipeline.js +94 -2
  96. package/dist/core/generator/spec-pipeline.js.map +1 -1
  97. package/dist/core/generator/stages/stage1-survey.d.ts.map +1 -1
  98. package/dist/core/generator/stages/stage1-survey.js +43 -0
  99. package/dist/core/generator/stages/stage1-survey.js.map +1 -1
  100. package/dist/core/generator/stages/stage2-entities.d.ts.map +1 -1
  101. package/dist/core/generator/stages/stage2-entities.js +6 -2
  102. package/dist/core/generator/stages/stage2-entities.js.map +1 -1
  103. package/dist/core/generator/stages/stage3-services.d.ts.map +1 -1
  104. package/dist/core/generator/stages/stage3-services.js +9 -2
  105. package/dist/core/generator/stages/stage3-services.js.map +1 -1
  106. package/dist/core/generator/stages/stage4-api.d.ts.map +1 -1
  107. package/dist/core/generator/stages/stage4-api.js +6 -2
  108. package/dist/core/generator/stages/stage4-api.js.map +1 -1
  109. package/dist/core/services/llm-service.d.ts +26 -10
  110. package/dist/core/services/llm-service.d.ts.map +1 -1
  111. package/dist/core/services/llm-service.js +171 -16
  112. package/dist/core/services/llm-service.js.map +1 -1
  113. package/dist/core/services/mcp-handlers/analysis.d.ts +32 -1
  114. package/dist/core/services/mcp-handlers/analysis.d.ts.map +1 -1
  115. package/dist/core/services/mcp-handlers/analysis.js +185 -2
  116. package/dist/core/services/mcp-handlers/analysis.js.map +1 -1
  117. package/dist/core/verifier/verification-engine.d.ts +67 -6
  118. package/dist/core/verifier/verification-engine.d.ts.map +1 -1
  119. package/dist/core/verifier/verification-engine.js +316 -90
  120. package/dist/core/verifier/verification-engine.js.map +1 -1
  121. package/dist/types/index.d.ts +70 -1
  122. package/dist/types/index.d.ts.map +1 -1
  123. package/dist/types/pipeline.d.ts +9 -0
  124. package/dist/types/pipeline.d.ts.map +1 -1
  125. package/dist/utils/command-helpers.d.ts +30 -0
  126. package/dist/utils/command-helpers.d.ts.map +1 -1
  127. package/dist/utils/command-helpers.js +69 -1
  128. package/dist/utils/command-helpers.js.map +1 -1
  129. package/examples/bmad/README.md +113 -0
  130. package/examples/bmad/agents/architect.md +226 -0
  131. package/examples/bmad/agents/dev-brownfield.md +69 -0
  132. package/examples/bmad/setup/architect.customize.yaml +14 -0
  133. package/examples/bmad/tasks/implement-story.md +254 -0
  134. package/examples/bmad/tasks/onboarding.md +169 -0
  135. package/examples/bmad/tasks/refactor.md +178 -0
  136. package/examples/bmad/tasks/sprint-planning.md +168 -0
  137. package/examples/bmad/templates/story.md +108 -0
  138. package/examples/cline-workflows/spec-gen-analyze-codebase.md +100 -0
  139. package/examples/cline-workflows/spec-gen-check-spec-drift.md +102 -0
  140. package/examples/cline-workflows/spec-gen-execute-refactor.md +194 -0
  141. package/examples/cline-workflows/spec-gen-implement-feature.md +238 -0
  142. package/examples/cline-workflows/spec-gen-plan-refactor.md +255 -0
  143. package/examples/cline-workflows/spec-gen-refactor-codebase.md +16 -0
  144. package/examples/drift-demo/openspec/config.yaml +14 -0
  145. package/examples/drift-demo/openspec/specs/architecture/spec.md +30 -0
  146. package/examples/drift-demo/openspec/specs/auth/spec.md +71 -0
  147. package/examples/drift-demo/openspec/specs/database/spec.md +33 -0
  148. package/examples/drift-demo/openspec/specs/overview/spec.md +20 -0
  149. package/examples/drift-demo/openspec/specs/projects/spec.md +55 -0
  150. package/examples/drift-demo/openspec/specs/tasks/spec.md +78 -0
  151. package/examples/drift-demo/package.json +21 -0
  152. package/examples/drift-demo/src/auth/auth-middleware.ts +30 -0
  153. package/examples/drift-demo/src/auth/auth-routes.ts +29 -0
  154. package/examples/drift-demo/src/auth/auth-service.ts +45 -0
  155. package/examples/drift-demo/src/database/connection.ts +27 -0
  156. package/examples/drift-demo/src/index.ts +16 -0
  157. package/examples/drift-demo/src/projects/project-model.ts +15 -0
  158. package/examples/drift-demo/src/projects/project-service.ts +34 -0
  159. package/examples/drift-demo/src/tasks/task-model.ts +37 -0
  160. package/examples/drift-demo/src/tasks/task-routes.ts +53 -0
  161. package/examples/drift-demo/src/tasks/task-service.ts +60 -0
  162. package/examples/drift-demo/src/utils/validation.ts +11 -0
  163. package/examples/drift-demo/tests/auth.test.ts +4 -0
  164. package/examples/drift-demo/tests/tasks.test.ts +4 -0
  165. package/examples/drift-demo/tsconfig.json +10 -0
  166. package/examples/drift-test/run-drift-test.sh +1087 -0
  167. package/examples/gsd/README.md +119 -0
  168. package/examples/gsd/commands/gsd/spec-gen-drift.md +111 -0
  169. package/examples/gsd/commands/gsd/spec-gen-orient.md +191 -0
  170. package/examples/mistral-vibe/README.md +101 -0
  171. package/examples/mistral-vibe/antipatterns-template.md +18 -0
  172. package/examples/mistral-vibe/skills/spec-gen-analyze-codebase/SKILL.md +123 -0
  173. package/examples/mistral-vibe/skills/spec-gen-brainstorm/SKILL.md +379 -0
  174. package/examples/mistral-vibe/skills/spec-gen-debug/SKILL.md +320 -0
  175. package/examples/mistral-vibe/skills/spec-gen-execute-refactor/SKILL.md +210 -0
  176. package/examples/mistral-vibe/skills/spec-gen-generate/SKILL.md +245 -0
  177. package/examples/mistral-vibe/skills/spec-gen-implement-story/SKILL.md +274 -0
  178. package/examples/mistral-vibe/skills/spec-gen-plan-refactor/SKILL.md +251 -0
  179. package/examples/openspec-analysis/README.md +59 -0
  180. package/examples/openspec-analysis/SUMMARY.md +72 -0
  181. package/examples/openspec-analysis/config.json +16 -0
  182. package/examples/openspec-analysis/dependencies.mermaid +35 -0
  183. package/examples/openspec-analysis/dependency-graph.json +12116 -0
  184. package/examples/openspec-analysis/llm-context.json +119 -0
  185. package/examples/openspec-analysis/repo-structure.json +871 -0
  186. package/examples/openspec-cli/README.md +67 -0
  187. package/examples/openspec-cli/openspec/config.yaml +26 -0
  188. package/examples/openspec-cli/openspec/specs/architecture/spec.md +178 -0
  189. package/examples/openspec-cli/openspec/specs/artifact-graph/spec.md +143 -0
  190. package/examples/openspec-cli/openspec/specs/cli/spec.md +138 -0
  191. package/examples/openspec-cli/openspec/specs/overview/spec.md +60 -0
  192. package/examples/openspec-cli/openspec/specs/parsing/spec.md +123 -0
  193. package/examples/openspec-cli/openspec/specs/validation/spec.md +108 -0
  194. package/examples/spec-kit/README.md +104 -0
  195. package/examples/spec-kit/commands/drift.md +87 -0
  196. package/examples/spec-kit/commands/orient.md +138 -0
  197. package/examples/spec-kit/extension.yml +54 -0
  198. package/package.json +3 -6
@@ -0,0 +1,169 @@
1
+ # Task: Brownfield Onboarding
2
+
3
+ **Purpose**: Establish a structural baseline on an existing codebase.
4
+ **Phase**: Architecture — run this BEFORE writing architecture documents, planning epics, or creating stories.
5
+ Run once per project, then re-run at the start of each planning cycle (quarterly or after major refactors).
6
+
7
+ **Who runs this**: Architect Agent (not Dev Agent).
8
+
9
+ **Output**: populated `openspec/` + `.spec-gen/` + risk register embedded in architecture doc.
10
+
11
+ **Estimated time**: 5–15 minutes depending on codebase size.
12
+
13
+ ---
14
+
15
+ ## Prerequisites
16
+
17
+ - spec-gen MCP server connected
18
+ - `spec-gen` CLI available (`npx spec-gen` or local install)
19
+ - Read access to the project directory
20
+
21
+ ---
22
+
23
+ ## Step 1 — Run static analysis
24
+
25
+ ```xml
26
+ <use_mcp_tool>
27
+ <server_name>spec-gen</server_name>
28
+ <tool_name>analyze_codebase</tool_name>
29
+ <arguments>{
30
+ "directory": "$PROJECT_ROOT",
31
+ "force": false
32
+ }</arguments>
33
+ </use_mcp_tool>
34
+ ```
35
+
36
+ Expected output: summary with module count, function count, cycle count.
37
+ If `cycles_detected > 0`, note it — this is a brownfield risk signal.
38
+
39
+ ---
40
+
41
+ ## Step 2 — Understand the architecture
42
+
43
+ ```xml
44
+ <use_mcp_tool>
45
+ <server_name>spec-gen</server_name>
46
+ <tool_name>get_architecture_overview</tool_name>
47
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
48
+ </use_mcp_tool>
49
+ ```
50
+
51
+ From the result, record:
52
+ - **Domain clusters** (the logical groupings spec-gen detected)
53
+ - **Cross-cluster dependencies** (coupling risks)
54
+ - **Entry points** (where requests enter the system)
55
+ - **Critical hubs** (high fan-in functions — touch with care)
56
+
57
+ ---
58
+
59
+ ## Step 3 — Identify hotspots
60
+
61
+ ```xml
62
+ <use_mcp_tool>
63
+ <server_name>spec-gen</server_name>
64
+ <tool_name>get_refactor_report</tool_name>
65
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
66
+ </use_mcp_tool>
67
+ ```
68
+
69
+ Create a brownfield risk register — a simple table:
70
+
71
+ | Function | File | Issues | Priority | Action |
72
+ |---|---|---|---|---|
73
+ | ... | ... | high_fan_out | 85 | Refactor before touching |
74
+ | ... | ... | in_cycle | 60 | Isolate cycle first |
75
+ | ... | ... | multi_requirement | 40 | Document carefully |
76
+
77
+ Functions with priority > 70 are **no-touch zones** until refactored.
78
+
79
+ ---
80
+
81
+ ## Step 4 — Check for duplicate code
82
+
83
+ ```xml
84
+ <use_mcp_tool>
85
+ <server_name>spec-gen</server_name>
86
+ <tool_name>get_duplicate_report</tool_name>
87
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
88
+ </use_mcp_tool>
89
+ ```
90
+
91
+ Note any clone groups — they indicate debt that will multiply if features are added naively.
92
+
93
+ ---
94
+
95
+ ## Step 5 — Generate OpenSpec (if no specs exist)
96
+
97
+ If `openspec/` does not exist or has no specs, generate them:
98
+
99
+ ```bash
100
+ spec-gen analyze --embed
101
+ spec-gen generate
102
+ ```
103
+
104
+ Or trigger the spec-gen skill in your AI agent:
105
+
106
+ > "Run spec-gen on this codebase and generate OpenSpec specifications."
107
+
108
+ This creates `openspec/specs/{domain}/spec.md` for each detected domain.
109
+ Commit the result — these become the baseline for drift detection.
110
+
111
+ ---
112
+
113
+ ## Step 6 — Verify spec coverage
114
+
115
+ ```xml
116
+ <use_mcp_tool>
117
+ <server_name>spec-gen</server_name>
118
+ <tool_name>check_spec_drift</tool_name>
119
+ <arguments>{
120
+ "directory": "$PROJECT_ROOT",
121
+ "base": "HEAD"
122
+ }</arguments>
123
+ </use_mcp_tool>
124
+ ```
125
+
126
+ At this point drift should be zero (we just generated specs from HEAD).
127
+ If `uncovered` files appear, add them to the backlog as "spec missing" items.
128
+
129
+ ---
130
+
131
+ ## Step 7 — Record the baseline
132
+
133
+ Create or update `openspec/specs/architecture/spec.md` with a **brownfield baseline** section:
134
+
135
+ ```markdown
136
+ ## Brownfield Baseline
137
+
138
+ > Established: {date}
139
+
140
+ ### Risk Register
141
+
142
+ | Function | Issues | Priority |
143
+ |---|---|---|
144
+ | ... | ... | ... |
145
+
146
+ ### No-touch zones (priority > 70)
147
+
148
+ - `functionName` in `path/to/file.ts` — reason
149
+
150
+ ### Known duplicate groups
151
+
152
+ - N clone groups detected (see `.spec-gen/analysis/`)
153
+
154
+ ### Onboarding notes
155
+
156
+ - ...
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Completion Criteria
162
+
163
+ - [ ] `spec-gen analyze` completed without error
164
+ - [ ] Architecture overview reviewed and understood
165
+ - [ ] Risk register created with functions priority > 70 flagged
166
+ - [ ] `openspec/` populated (generated or pre-existing)
167
+ - [ ] `check_spec_drift` shows zero drift on HEAD
168
+ - [ ] Baseline documented in `openspec/specs/architecture/spec.md`
169
+ - [ ] BMAD project backlog updated with any "spec missing" items
@@ -0,0 +1,178 @@
1
+ # Task: Brownfield Refactor
2
+
3
+ **Purpose**: Plan and execute a safe refactoring on a brownfield codebase before implementing a story.
4
+ Typically triggered by the `dev-brownfield` agent gate when `riskScore ≥ 70`.
5
+
6
+ **Output**: `.spec-gen/refactor-plan.md` applied and verified.
7
+
8
+ ---
9
+
10
+ ## Inputs
11
+
12
+ - `$TARGET_FUNCTION` — function identified as high-risk by `analyze_impact`
13
+ - `$PROJECT_ROOT` — absolute path to the project
14
+
15
+ ---
16
+
17
+ ## Step 1 — Confirm target and scope
18
+
19
+ Present the risk signal to the user:
20
+
21
+ > "`$TARGET_FUNCTION` has a risk score of $SCORE ($ISSUES).
22
+ > Implementing the planned story on this function as-is risks breaking $CALLERS.
23
+ > This task will refactor it first. Proceed?"
24
+
25
+ If the user declines, mark the story as blocked with dependency: "Refactor `$TARGET_FUNCTION` first."
26
+
27
+ ---
28
+
29
+ ## Step 2 — Get the refactor report
30
+
31
+ ```xml
32
+ <use_mcp_tool>
33
+ <server_name>spec-gen</server_name>
34
+ <tool_name>get_refactor_report</tool_name>
35
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
36
+ </use_mcp_tool>
37
+ ```
38
+
39
+ Confirm `$TARGET_FUNCTION` appears in the report and note its issues and priority score.
40
+
41
+ ---
42
+
43
+ ## Step 3 — Check for clones
44
+
45
+ ```xml
46
+ <use_mcp_tool>
47
+ <server_name>spec-gen</server_name>
48
+ <tool_name>get_duplicate_report</tool_name>
49
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
50
+ </use_mcp_tool>
51
+ ```
52
+
53
+ If `$TARGET_FUNCTION` appears in a clone group:
54
+ > "⚠️ This function has N near-clones. Consolidate them first to reduce blast radius."
55
+ Propose consolidation as Change 0 in the plan.
56
+
57
+ ---
58
+
59
+ ## Step 4 — Analyse the call neighbourhood
60
+
61
+ ```xml
62
+ <use_mcp_tool>
63
+ <server_name>spec-gen</server_name>
64
+ <tool_name>analyze_impact</tool_name>
65
+ <arguments>{
66
+ "directory": "$PROJECT_ROOT",
67
+ "symbol": "$TARGET_FUNCTION",
68
+ "depth": 3
69
+ }</arguments>
70
+ </use_mcp_tool>
71
+ ```
72
+
73
+ ```xml
74
+ <use_mcp_tool>
75
+ <server_name>spec-gen</server_name>
76
+ <tool_name>get_subgraph</tool_name>
77
+ <arguments>{
78
+ "directory": "$PROJECT_ROOT",
79
+ "functionName": "$TARGET_FUNCTION",
80
+ "direction": "both",
81
+ "format": "mermaid"
82
+ }</arguments>
83
+ </use_mcp_tool>
84
+ ```
85
+
86
+ Show the Mermaid diagram. Identify extraction candidates in the downstream subgraph.
87
+
88
+ ---
89
+
90
+ ## Step 5 — Find safe extraction targets
91
+
92
+ ```xml
93
+ <use_mcp_tool>
94
+ <server_name>spec-gen</server_name>
95
+ <tool_name>get_low_risk_refactor_candidates</tool_name>
96
+ <arguments>{
97
+ "directory": "$PROJECT_ROOT",
98
+ "filePattern": "$TARGET_FILE",
99
+ "limit": 5
100
+ }</arguments>
101
+ </use_mcp_tool>
102
+ ```
103
+
104
+ Cross-reference with the subgraph: good extraction candidates are already callees of `$TARGET_FUNCTION`.
105
+
106
+ ---
107
+
108
+ ## Step 6 — Find landing zones for extracted helpers
109
+
110
+ ```xml
111
+ <use_mcp_tool>
112
+ <server_name>spec-gen</server_name>
113
+ <tool_name>suggest_insertion_points</tool_name>
114
+ <arguments>{
115
+ "directory": "$PROJECT_ROOT",
116
+ "description": "extract helper from $TARGET_FUNCTION",
117
+ "limit": 5
118
+ }</arguments>
119
+ </use_mcp_tool>
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Step 7 — Design the change sequence
125
+
126
+ Design an ordered sequence of atomic changes. Each change must specify:
127
+
128
+ - **What**: the exact block to extract (description or line range)
129
+ - **New name**: function name
130
+ - **Target file**: where to place it (existing or new)
131
+ - **Call sites to update**: list each file that calls `$TARGET_FUNCTION` or the extracted block
132
+
133
+ **Present the full sequence to the user and wait for explicit approval before writing the plan.**
134
+
135
+ ---
136
+
137
+ ## Step 8 — Execute (delegate to spec-gen-execute-refactor)
138
+
139
+ Once the plan is approved, hand off to the `spec-gen-execute-refactor` skill:
140
+
141
+ 1. Write `.spec-gen/refactor-plan.md` with the full plan (see skill template)
142
+ 2. Invoke `/spec-gen-execute-refactor`
143
+
144
+ The execute skill handles:
145
+ - Green baseline verification
146
+ - Restore point setup
147
+ - Atomic change application with tests after each step
148
+ - Post-refactor risk score verification
149
+
150
+ ---
151
+
152
+ ## Step 9 — Re-run the gate
153
+
154
+ After the refactor is complete, re-run `analyze_impact` on `$TARGET_FUNCTION`:
155
+
156
+ ```xml
157
+ <use_mcp_tool>
158
+ <server_name>spec-gen</server_name>
159
+ <tool_name>analyze_impact</tool_name>
160
+ <arguments>{
161
+ "directory": "$PROJECT_ROOT",
162
+ "symbol": "$TARGET_FUNCTION",
163
+ "depth": 2
164
+ }</arguments>
165
+ </use_mcp_tool>
166
+ ```
167
+
168
+ - If `riskScore` is now < 70 → return to the story implementation task
169
+ - If `riskScore` is still ≥ 70 → repeat from Step 4 with the updated subgraph
170
+
171
+ ---
172
+
173
+ ## Completion Criteria
174
+
175
+ - [ ] `riskScore` for `$TARGET_FUNCTION` < 70
176
+ - [ ] Full test suite passes (green)
177
+ - [ ] `check_spec_drift` clean or addressed
178
+ - [ ] Story unblocked — return to `implement-story-brownfield`
@@ -0,0 +1,168 @@
1
+ # Task: Sprint Planning
2
+
3
+ **Purpose**: Validate a sprint candidate before committing to it.
4
+ Detects conflicts, blocked stories, and ordering constraints using structural analysis.
5
+
6
+ **Who runs this**: Scrum Master Agent or Architect Agent, during sprint planning.
7
+ **When**: Before the sprint is locked — after stories are written, before they're assigned.
8
+
9
+ **Output**: sprint risk report + recommended story order + blocking issues list.
10
+
11
+ ---
12
+
13
+ ## Prerequisites
14
+
15
+ - Onboarding completed (`bmad/tasks/onboarding.md`)
16
+ - All sprint candidate stories have a `risk_context` section
17
+ - If `risk_context` is missing on any story, run `annotate_story` on it first (not manually)
18
+
19
+ ---
20
+
21
+ ## Step 1 — Refresh the structural analysis
22
+
23
+ If the last `analyze_codebase` run was more than 24 hours ago, or if code changed since then:
24
+
25
+ ```xml
26
+ <use_mcp_tool>
27
+ <server_name>spec-gen</server_name>
28
+ <tool_name>analyze_codebase</tool_name>
29
+ <arguments>{"directory": "$PROJECT_ROOT", "force": false}</arguments>
30
+ </use_mcp_tool>
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Step 2 — Collect risk data per story
36
+
37
+ For each story in the sprint candidate list:
38
+
39
+ **If `risk_context` is already populated** (normal case — architect did their job):
40
+ Read it directly from the story file. No MCP call needed.
41
+
42
+ **If `risk_context` is absent**, run `annotate_story` now:
43
+
44
+ ```xml
45
+ <use_mcp_tool>
46
+ <server_name>spec-gen</server_name>
47
+ <tool_name>annotate_story</tool_name>
48
+ <arguments>{
49
+ "directory": "$PROJECT_ROOT",
50
+ "storyFilePath": "$STORY_FILE_PATH",
51
+ "description": "$STORY_TITLE — $PRIMARY_AC"
52
+ }</arguments>
53
+ </use_mcp_tool>
54
+ ```
55
+
56
+ Collect from each story's `risk_context`:
57
+ - `Domains` → which spec domains are touched
58
+ - `Max risk score` + level
59
+ - `Blocking refactors` → any listed
60
+ - `Functions in scope` → for conflict detection
61
+
62
+ **Also verify story quality:**
63
+ - `## Won't Do` section must be present with at least 1 item
64
+ - Every AC must be testable (specific observable outcome, not a vague quality)
65
+
66
+ Flag non-compliant stories:
67
+ > "⚠️ Story S-NN is missing `## Won't Do` / has vague ACs — return to author before sprint lock."
68
+
69
+ ---
70
+
71
+ ## Step 3 — Build the sprint risk matrix
72
+
73
+ | Story | Domains | Risk | Blocking Refactors | Status |
74
+ |---|---|---|---|---|
75
+ | S-01 Add retry | payment | 🔴 82 | `processPayment` | ⛔ blocked |
76
+ | S-02 Email validation | auth | 🟢 18 | none | ✅ ready |
77
+ | S-03 Rate limiting | api | 🟡 45 | none | ⚠️ caution |
78
+
79
+ **Status rules:**
80
+ - ⛔ **blocked**: max risk ≥ 70 and no refactor story scheduled before it
81
+ - ⚠️ **caution**: max risk 40–69, or story touches a critical hub
82
+ - ✅ **ready**: max risk < 40 and no hub involvement
83
+
84
+ ---
85
+
86
+ ## Step 4 — Detect function conflicts
87
+
88
+ Find stories whose `functions in scope` overlap.
89
+
90
+ Get the full hub list to cross-reference:
91
+
92
+ ```xml
93
+ <use_mcp_tool>
94
+ <server_name>spec-gen</server_name>
95
+ <tool_name>get_critical_hubs</tool_name>
96
+ <arguments>{"directory": "$PROJECT_ROOT", "limit": 15}</arguments>
97
+ </use_mcp_tool>
98
+ ```
99
+
100
+ For each hub that appears in two or more stories' function scope:
101
+
102
+ > "⚠️ Stories S-01 and S-04 both touch `processPayment` (fan-in: 12).
103
+ > Parallel risk: merge conflicts and silent regressions.
104
+ > Recommend: sequence them, or assign to the same developer."
105
+
106
+ ---
107
+
108
+ ## Step 5 — Check spec coverage gaps
109
+
110
+ ```xml
111
+ <use_mcp_tool>
112
+ <server_name>spec-gen</server_name>
113
+ <tool_name>check_spec_drift</tool_name>
114
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
115
+ </use_mcp_tool>
116
+ ```
117
+
118
+ For any `uncovered` files already present:
119
+ > "Stories touching these files cannot use `check_spec_drift` as a completion gate.
120
+ > Add a `spec-gen generate` task to the sprint."
121
+
122
+ ---
123
+
124
+ ## Step 6 — Determine story ordering
125
+
126
+ **Rules:**
127
+ 1. Refactor stories before the stories they unblock
128
+ 2. Stories touching the same hub: sequence, do not parallelise
129
+ 3. Low-risk stories can be parallelised freely
130
+ 4. `spec-gen generate` after any story that adds new source files
131
+
132
+ ---
133
+
134
+ ## Step 7 — Sprint readiness verdict
135
+
136
+ | Criterion | Status |
137
+ |---|---|
138
+ | No ⛔ stories without prior refactor scheduled | ✅ / ⛔ |
139
+ | No parallel stories on the same hub | ✅ / ⚠️ |
140
+ | All stories have `risk_context` | ✅ / ⛔ |
141
+ | All stories have `## Won't Do` and testable ACs | ✅ / ⚠️ |
142
+ | Spec coverage adequate for drift detection | ✅ / ⚠️ |
143
+
144
+ **If any ⛔ remain: do not lock the sprint.** Resolve blockers first.
145
+
146
+ ---
147
+
148
+ ## Output
149
+
150
+ Write the sprint plan to `.spec-gen/sprints/sprint-{N}.md`:
151
+
152
+ ```markdown
153
+ # Sprint {N} — Risk Report
154
+
155
+ Generated: {date}
156
+
157
+ ## Risk Matrix
158
+ {table from Step 3}
159
+
160
+ ## Conflicts
161
+ {list from Step 4}
162
+
163
+ ## Recommended Order
164
+ {from Step 6}
165
+
166
+ ## Readiness
167
+ {verdict from Step 7}
168
+ ```
@@ -0,0 +1,108 @@
1
+ # Story {ID}: {Title}
2
+
3
+ **Type**: feature | technical-debt | bug | spike
4
+ **Epic**: {epic name}
5
+ **Status**: Draft | Ready | In Progress | Review | Done
6
+
7
+ ---
8
+
9
+ ## User Story
10
+
11
+ As a **{role}**,
12
+ I want **{capability}**,
13
+ so that **{benefit}**.
14
+
15
+ ---
16
+
17
+ ## Acceptance Criteria
18
+
19
+ > Each criterion must be testable: describe a specific observable outcome, not a vague quality.
20
+ > ✗ "The UX should be responsive" — not a criterion
21
+ > ✓ "Submitting the form with an empty email field shows a validation error" — testable
22
+
23
+ - [ ] AC1: {criterion}
24
+ - [ ] AC2: {criterion}
25
+ - [ ] AC3: {criterion}
26
+
27
+ ---
28
+
29
+ ## Won't Do
30
+
31
+ > What this story explicitly does NOT cover. Minimum 1 item.
32
+ > Prevents scope creep and removes ambiguity for the Dev Agent.
33
+
34
+ - {out-of-scope item}
35
+
36
+ ---
37
+
38
+ ## Risk Context
39
+
40
+ > Pre-filled by the Architect Agent using spec-gen.
41
+ > Dev Agent reads this — does NOT rediscover it at implementation time.
42
+
43
+ - **Domains in scope**: {e.g. auth, api}
44
+ - **Max risk score**: {0–100} {🟢 low | 🟡 medium | 🟠 high | 🔴 critical}
45
+ - **Functions in scope**: {function1 (file), function2 (file)}
46
+ - **Blocking refactors**: {none | "Refactor X first — Story {ID}"}
47
+ - **Parallel risk**: {none | "Conflicts with Story {ID} on function X"}
48
+ - **Insertion points**: {function (strategy, score)}
49
+ - **Spec domains linked**: {domain1/spec.md, domain2/spec.md}
50
+
51
+ ### Structural Notes
52
+
53
+ {Any architectural constraints, patterns to follow, anti-patterns to avoid.
54
+ Filled by Architect Agent based on get_architecture_overview output.}
55
+
56
+ ---
57
+
58
+ ## Technical Constraints
59
+
60
+ - {constraint 1}
61
+ - {constraint 2}
62
+
63
+ ---
64
+
65
+ ## Tasks
66
+
67
+ > Filled by Dev Agent during implementation.
68
+
69
+ - [ ] {task 1}
70
+ - [ ] {task 2}
71
+ - [ ] Add/update tests
72
+ - [ ] Run `check_spec_drift` — confirm clean
73
+
74
+ ---
75
+
76
+ ## Dev Agent Record
77
+
78
+ > Filled by Dev Agent on completion.
79
+
80
+ ### Implementation Summary
81
+
82
+ - **Insertion point used**: {function} in {file}
83
+ - **Files changed**: {list}
84
+ - **Tests added**: {N}
85
+ - **Spec drift**: ✅ clean | ⚠️ {details}
86
+
87
+ ### Risk Notes
88
+
89
+ | Function | Actual Risk Score | Delta vs Estimate |
90
+ |---|---|---|
91
+ | | | |
92
+
93
+ ### Scope Notes
94
+
95
+ {Were any functions touched outside the planned scope? Why?}
96
+
97
+ ---
98
+
99
+ ## Dependencies
100
+
101
+ - **Blocked by**: {Story ID — reason} | none
102
+ - **Blocks**: {Story ID} | none
103
+
104
+ ---
105
+
106
+ ## Story Points
107
+
108
+ {estimate} — basis: {risk level, insertion complexity, test surface}