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,226 @@
1
+ # Agent: Architect — spec-gen extension
2
+
3
+ > **This file is a sidecar for the BMAD `architect` agent.**
4
+ >
5
+ > **Setup (one-time):**
6
+ > ```bash
7
+ > # 1. Copy this file into your BMAD project
8
+ > cp examples/bmad/agents/architect.md _bmad/_memory/architect-sidecar/spec-gen.md
9
+ >
10
+ > # 2. Install the customization that tells BMAD to load it
11
+ > cp examples/bmad/setup/architect.customize.yaml \
12
+ > _bmad/_config/customizations/architect.customize.yaml
13
+ >
14
+ > # 3. Recompile BMAD agents
15
+ > npx bmad-method install
16
+ > ```
17
+ >
18
+ > After that, the Architect agent loads this file automatically at session start.
19
+ > No manual step needed in the conversation.
20
+ >
21
+ > Requires: spec-gen MCP server connected and onboarding completed
22
+ > (see `tasks/onboarding.md`).
23
+
24
+ ---
25
+
26
+ ## Core Principle
27
+
28
+ The architecture document MUST reflect the reality of the code,
29
+ not just the desired target state. An architecture written without reading the code
30
+ produces a plan that the codebase cannot support.
31
+
32
+ **Produce two documents:**
33
+ 1. **Structural Reality** — what the code actually is (spec-gen output)
34
+ 2. **Target Architecture** — what you want it to become (your design)
35
+
36
+ The gap between them is the technical debt backlog.
37
+
38
+ ---
39
+
40
+ ## Phase 0 — Structural Reality (run before any design work)
41
+
42
+ ### Step 0.1 — Architecture overview
43
+
44
+ ```xml
45
+ <use_mcp_tool>
46
+ <server_name>spec-gen</server_name>
47
+ <tool_name>get_architecture_overview</tool_name>
48
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
49
+ </use_mcp_tool>
50
+ ```
51
+
52
+ Extract:
53
+ - **Domain clusters** → existing logical boundaries
54
+ - **Cross-cluster dependencies** → where coupling is highest
55
+ - **Critical hubs** → functions that act as bottlenecks
56
+ - **Entry points** → where control enters the system
57
+
58
+ If this returns an error, run `analyze_codebase` first.
59
+
60
+ ### Step 0.2 — Risk landscape
61
+
62
+ ```xml
63
+ <use_mcp_tool>
64
+ <server_name>spec-gen</server_name>
65
+ <tool_name>get_refactor_report</tool_name>
66
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
67
+ </use_mcp_tool>
68
+ ```
69
+
70
+ Classify each high-priority candidate:
71
+
72
+ | Function | Issues | Priority | Classification |
73
+ |---|---|---|---|
74
+ | ... | high_fan_out | 85 | 🔴 no-touch zone |
75
+ | ... | in_cycle | 62 | 🟠 isolate before touching |
76
+ | ... | multi_requirement | 38 | 🟡 document carefully |
77
+
78
+ **No-touch zones** (priority ≥ 70): any story touching these functions is **blocked**
79
+ until a refactor story is completed first.
80
+
81
+ ### Step 0.3 — Structural debt
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 clone groups — they amplify the cost of any feature that touches duplicated logic.
92
+
93
+ ### Step 0.4 — Critical hubs
94
+
95
+ ```xml
96
+ <use_mcp_tool>
97
+ <server_name>spec-gen</server_name>
98
+ <tool_name>get_critical_hubs</tool_name>
99
+ <arguments>{"directory": "$PROJECT_ROOT", "limit": 10, "minFanIn": 3}</arguments>
100
+ </use_mcp_tool>
101
+ ```
102
+
103
+ Hubs with high fan-in are the riskiest insertion points. Note their recommended approach
104
+ (`extract`, `split`, `facade`, `delegate`).
105
+
106
+ ---
107
+
108
+ ## Phase 1 — Feature / Epic Impact Assessment
109
+
110
+ For each epic or major feature in scope, generate a change proposal:
111
+
112
+ ```xml
113
+ <use_mcp_tool>
114
+ <server_name>spec-gen</server_name>
115
+ <tool_name>generate_change_proposal</tool_name>
116
+ <arguments>{
117
+ "directory": "$PROJECT_ROOT",
118
+ "description": "$EPIC_DESCRIPTION",
119
+ "slug": "$EPIC_SLUG"
120
+ }</arguments>
121
+ </use_mcp_tool>
122
+ ```
123
+
124
+ From each proposal:
125
+ - **domainsAffected** → which spec domains this epic touches
126
+ - **maxRiskScore** → overall risk level of this epic
127
+ - **requirementsTouched** → existing requirements this epic overlaps or extends
128
+
129
+ Build an epic risk matrix:
130
+
131
+ | Epic | Domains | Max Risk | Blocking Refactors |
132
+ |---|---|---|---|
133
+ | Add payment retry | payment, api | 🔴 82 | refactor `processPayment` first |
134
+ | User email validation | auth, user | 🟢 18 | none |
135
+
136
+ ---
137
+
138
+ ## Phase 2 — Architecture Document
139
+
140
+ Write `docs/architecture.md` (or the BMAD equivalent) with two mandatory sections:
141
+
142
+ ### Section: Structural Reality
143
+
144
+ ```markdown
145
+ ## Structural Reality (as-is)
146
+
147
+ > Generated from spec-gen analysis on {date}.
148
+ > Re-run `spec-gen analyze --force` before each planning cycle.
149
+
150
+ ### Domain Map
151
+
152
+ {paste architecture overview clusters and dependencies}
153
+
154
+ ### No-Touch Zones
155
+
156
+ Functions that MUST NOT be modified without a prior refactor story:
157
+
158
+ | Function | File | Risk | Issues |
159
+ |---|---|---|---|
160
+
161
+ ### Known Debt
162
+
163
+ - N clone groups detected
164
+ - N cyclic dependencies
165
+
166
+ ### Critical Hubs
167
+
168
+ Functions requiring the most careful change management:
169
+
170
+ | Function | Fan-in | Recommended approach |
171
+ |---|---|---|
172
+ ```
173
+
174
+ ### Section: Target Architecture
175
+
176
+ Design the future state here — new domains, desired boundaries, patterns to introduce.
177
+ **For each structural gap between reality and target, create a technical debt story.**
178
+
179
+ ---
180
+
181
+ ## Phase 3 — Technical Debt Backlog
182
+
183
+ For every no-touch zone, create a **refactor story** in the BMAD backlog:
184
+
185
+ Use the template `bmad/templates/story.md` with:
186
+ - Story type: `technical-debt`
187
+ - Title: `Refactor {function}: {issue}`
188
+ - Blocking: list stories that cannot proceed until this is done
189
+ - **Won't Do**: at minimum one item — scope the refactor tightly (e.g. "Won't change the public API", "Won't refactor callers")
190
+ - **Acceptance Criteria**: must be testable — state observable outcomes (e.g. "riskScore drops below 70", "no caller changes required")
191
+
192
+ These stories MUST be sprint-scheduled before any story that depends on the refactored function.
193
+
194
+ ---
195
+
196
+ ## Phase 4 — Annotate Stories with Risk Context
197
+
198
+ For each story in the backlog, run `annotate_story` — do not fill `risk_context` manually.
199
+
200
+ ```xml
201
+ <use_mcp_tool>
202
+ <server_name>spec-gen</server_name>
203
+ <tool_name>annotate_story</tool_name>
204
+ <arguments>{
205
+ "directory": "$PROJECT_ROOT",
206
+ "storyFilePath": "$STORY_FILE_PATH",
207
+ "description": "$STORY_TITLE — $PRIMARY_AC"
208
+ }</arguments>
209
+ </use_mcp_tool>
210
+ ```
211
+
212
+ The tool reads the story file, runs `orient` + `analyze_impact`, and writes the
213
+ `risk_context` section directly. Existing sections are replaced, not appended.
214
+
215
+ Re-run after any completed refactor story — risk scores change as the code evolves.
216
+
217
+ The Dev Agent reads this context at sprint time — it does **not** discover it.
218
+
219
+ ---
220
+
221
+ ## Absolute Constraints
222
+
223
+ - Never write a target architecture without first completing Phase 0
224
+ - Never assign a story touching a no-touch zone without a blocking refactor story in the backlog
225
+ - Always run `annotate_story` on stories before they enter a sprint — never fill risk_context manually
226
+ - Re-run Phase 0 at the start of each planning cycle — the structural reality changes
@@ -0,0 +1,69 @@
1
+ # Agent: Developer — No-Planning Fallback
2
+
3
+ > **Load this ONLY when:**
4
+ > - No architect analysis was done and stories have no `risk_context`
5
+ > - Onboarding to a completely unknown codebase mid-project
6
+ > - The sprint planning task was skipped
7
+ >
8
+ > In normal usage, `bmad/tasks/implement-story.md` is sufficient —
9
+ > the risk context from planning makes this override unnecessary.
10
+
11
+ ---
12
+
13
+ ## What this adds
14
+
15
+ When `risk_context` is absent from a story, this override enforces a full
16
+ structural gate at implementation time as a safety net.
17
+
18
+ For every story, before writing code:
19
+
20
+ 1. Call `orient` with the story description
21
+ 2. Call `analyze_impact` on the top 3 functions
22
+ 3. If any `riskScore ≥ 70`: stop, propose a refactor story, do not proceed
23
+
24
+ This replicates at dev time what should have happened at planning time.
25
+
26
+ ---
27
+
28
+ ## When to stop using this
29
+
30
+ Once the Architect Agent has run `bmad/tasks/onboarding.md` and
31
+ `bmad/agents/architect.md`, and stories have `risk_context` populated,
32
+ **remove this override**. It adds cost (extra MCP calls) with no benefit
33
+ once planning is done correctly.
34
+
35
+ ---
36
+
37
+ ## Gate
38
+
39
+ ```xml
40
+ <use_mcp_tool>
41
+ <server_name>spec-gen</server_name>
42
+ <tool_name>orient</tool_name>
43
+ <arguments>{
44
+ "directory": "$PROJECT_ROOT",
45
+ "task": "$STORY_TITLE — $AC1",
46
+ "limit": 7
47
+ }</arguments>
48
+ </use_mcp_tool>
49
+ ```
50
+
51
+ For each of the top 3 functions:
52
+
53
+ ```xml
54
+ <use_mcp_tool>
55
+ <server_name>spec-gen</server_name>
56
+ <tool_name>analyze_impact</tool_name>
57
+ <arguments>{
58
+ "directory": "$PROJECT_ROOT",
59
+ "symbol": "$FUNCTION_NAME",
60
+ "depth": 2
61
+ }</arguments>
62
+ </use_mcp_tool>
63
+ ```
64
+
65
+ | riskScore | Action |
66
+ |---|---|
67
+ | < 40 | Proceed |
68
+ | 40–69 | Proceed with care — protect listed callers |
69
+ | ≥ 70 | Stop — create refactor story, block this story |
@@ -0,0 +1,14 @@
1
+ # spec-gen extension for the BMAD Architect agent
2
+ #
3
+ # Drop this file at: _bmad/_config/customizations/architect.customize.yaml
4
+ # Then re-run: npx bmad-method install
5
+ #
6
+ # What it does: instructs the Architect agent to load the spec-gen structural
7
+ # analysis instructions as a sidecar before starting any design work.
8
+
9
+ customize:
10
+ metadata:
11
+ hasSidecar: true
12
+ critical-actions:
13
+ Appends:
14
+ - "Load COMPLETE file {project-root}/_bmad/_memory/architect-sidecar/spec-gen.md"
@@ -0,0 +1,254 @@
1
+ # Task: Implement Story
2
+
3
+ **Purpose**: Implement a BMAD story on any codebase — new or existing.
4
+ Structural analysis is used proportionally to the risk level already known from planning.
5
+
6
+ ---
7
+
8
+ ## Inputs
9
+
10
+ From the story file:
11
+ - `$STORY_TITLE`, `$AC`, `$PROJECT_ROOT`
12
+ - `$RISK_CONTEXT` — the `risk_context` section (pre-filled by Architect Agent at planning time)
13
+
14
+ If `.claude/antipatterns.md` exists, read it and store as `$ANTIPATTERNS`.
15
+ This list will be cross-checked at Step 4b.
16
+
17
+ ---
18
+
19
+ ## Step 1 — Read the risk context
20
+
21
+ Open the story file and check whether `risk_context` is populated.
22
+
23
+ ### If risk_context IS present (normal case — planning was done)
24
+
25
+ Use it directly. Do not re-run structural analysis unless something feels wrong.
26
+
27
+ | Risk level in story | Approach |
28
+ |---|---|
29
+ | 🟢 low (< 40) | Proceed to Step 3. Quick orient to confirm insertion point. |
30
+ | 🟡 medium (40–69) | Run Step 2 impact check. Proceed with callers protected. |
31
+ | 🔴 high / critical (≥ 70) | Story should have a blocking refactor. If not scheduled, stop and flag it. |
32
+
33
+ ### If risk_context is ABSENT (planning was skipped or story is new)
34
+
35
+ Run the full orientation in Step 2 before proceeding.
36
+
37
+ ---
38
+
39
+ ## Step 2 — Orient (full or confirm)
40
+
41
+ **Full orient** (risk_context absent, or medium+ risk):
42
+
43
+ ```xml
44
+ <use_mcp_tool>
45
+ <server_name>spec-gen</server_name>
46
+ <tool_name>orient</tool_name>
47
+ <arguments>{
48
+ "directory": "$PROJECT_ROOT",
49
+ "task": "$STORY_TITLE — $AC1",
50
+ "limit": 7
51
+ }</arguments>
52
+ </use_mcp_tool>
53
+ ```
54
+
55
+ If orient returns `"error": "no cache"` → run `analyze_codebase` first, then retry.
56
+
57
+ **For medium+ risk**, also run impact on the top 2 functions:
58
+
59
+ ```xml
60
+ <use_mcp_tool>
61
+ <server_name>spec-gen</server_name>
62
+ <tool_name>analyze_impact</tool_name>
63
+ <arguments>{
64
+ "directory": "$PROJECT_ROOT",
65
+ "symbol": "$FUNCTION_NAME",
66
+ "depth": 2
67
+ }</arguments>
68
+ </use_mcp_tool>
69
+ ```
70
+
71
+ If a function has `riskScore ≥ 70` that was NOT flagged at planning: **stop**.
72
+ Create a blocking refactor story and do not implement until it's resolved.
73
+
74
+ ---
75
+
76
+ ## Step 2.5 — Audit spec coverage of the target domain
77
+
78
+ Run a parity audit to check if the domain you're about to touch has spec gaps.
79
+
80
+ ```xml
81
+ <use_mcp_tool>
82
+ <server_name>spec-gen</server_name>
83
+ <tool_name>audit_spec_coverage</tool_name>
84
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
85
+ </use_mcp_tool>
86
+ ```
87
+
88
+ From the result, check:
89
+ - `staleDomains` — if the target domain appears here, its spec is outdated.
90
+ Recommend running `spec-gen generate --domains $DOMAIN` before implementing.
91
+ - `hubGaps` — uncovered hub functions. If the feature touches one of these,
92
+ add it to the adversarial check in Step 4b (high blast radius + no spec = risk).
93
+
94
+ If both are clean, continue to Step 3 without action.
95
+
96
+ ---
97
+
98
+ ## Step 3 — Check the spec
99
+
100
+ First verify that OpenSpec specs exist for this project:
101
+
102
+ ```bash
103
+ ls $PROJECT_ROOT/openspec/specs/ 2>/dev/null | wc -l
104
+ ```
105
+
106
+ **If 0 specs found:**
107
+ > No OpenSpec specs exist yet for this project. `search_specs` will return empty
108
+ > results and `check_spec_drift` (Step 7) will flag all files as uncovered.
109
+ >
110
+ > The Architect agent should have run `spec-gen generate` during onboarding.
111
+ > If it hasn't been run yet, note it in the Dev Agent Record and proceed with
112
+ > structural analysis only. The spec baseline can be created post-sprint with
113
+ > `spec-gen generate $PROJECT_ROOT`.
114
+
115
+ Skip `search_specs` and go to Step 4.
116
+
117
+ **If specs exist:**
118
+
119
+ ```xml
120
+ <use_mcp_tool>
121
+ <server_name>spec-gen</server_name>
122
+ <tool_name>search_specs</tool_name>
123
+ <arguments>{
124
+ "directory": "$PROJECT_ROOT",
125
+ "query": "$STORY_TITLE",
126
+ "limit": 5
127
+ }</arguments>
128
+ </use_mcp_tool>
129
+ ```
130
+
131
+ If relevant requirements are found, read the domain spec before writing code.
132
+ Note any constraints that apply to the implementation.
133
+
134
+ ---
135
+
136
+ ## Step 4 — Find the insertion point
137
+
138
+ Use the `insertion_points` from `risk_context` if present. Otherwise:
139
+
140
+ ```xml
141
+ <use_mcp_tool>
142
+ <server_name>spec-gen</server_name>
143
+ <tool_name>suggest_insertion_points</tool_name>
144
+ <arguments>{
145
+ "directory": "$PROJECT_ROOT",
146
+ "description": "$STORY_TITLE",
147
+ "limit": 5
148
+ }</arguments>
149
+ </use_mcp_tool>
150
+ ```
151
+
152
+ Read the skeleton of the target file:
153
+
154
+ ```xml
155
+ <use_mcp_tool>
156
+ <server_name>spec-gen</server_name>
157
+ <tool_name>get_function_skeleton</tool_name>
158
+ <arguments>{
159
+ "directory": "$PROJECT_ROOT",
160
+ "filePath": "$TARGET_FILE"
161
+ }</arguments>
162
+ </use_mcp_tool>
163
+ ```
164
+
165
+ Confirm the approach with the user before writing code.
166
+
167
+ ### Step 4b — Adversarial self-check
168
+
169
+ Before writing any code, state explicitly what could break with this approach.
170
+ If `$ANTIPATTERNS` was loaded (see Inputs), include any applicable patterns.
171
+
172
+ > "Risk check on `$INSERTION_POINT`:
173
+ > - `$CALLER_A` and `$CALLER_B` depend on this function — verify their assumptions hold after the change.
174
+ > - `$EDGE_CASE` is not covered by the current test suite — add it in Step 6.
175
+ > - [if antipatterns apply] AP-NNN (`$PATTERN_NAME`) — `$RULE` — applies here because `$REASON`."
176
+
177
+ This is not a gate — do not wait for user input. It is a mandatory self-check
178
+ that must appear in the output before the first line of code is written.
179
+
180
+ ---
181
+
182
+ ## Step 5 — Implement
183
+
184
+ Apply changes in this order:
185
+ 1. New types/interfaces (if needed)
186
+ 2. Core logic at the insertion point
187
+ 3. Updated call sites (if any)
188
+
189
+ Do not touch functions outside the scope from Step 2/risk_context without re-running the gate.
190
+
191
+ ---
192
+
193
+ ## Step 6 — Tests
194
+
195
+ Two levels, both required before proceeding:
196
+
197
+ **Mandatory — existing tests must not regress:**
198
+ Run the full test suite. If any pre-existing test breaks, fix the regression before continuing.
199
+ A green CI on existing tests is the minimum gate.
200
+
201
+ **Recommended — at least one new test per AC:**
202
+ Write a test that directly exercises the new behaviour described in the acceptance criterion.
203
+ This is the proof that the implementation matches the intent — without it, the spec update in Step 7 has no evidence.
204
+
205
+ | Situation | Action |
206
+ |---|---|
207
+ | All tests green, new tests written | Proceed to Step 7 |
208
+ | Existing test broken | Fix regression. Do not proceed. |
209
+ | New test reveals a misunderstanding of the AC | Return to Step 5, adjust implementation |
210
+ | Brownfield: no existing test coverage | Write the new test anyway. Note the coverage gap in the Dev Agent Record. |
211
+
212
+ ---
213
+
214
+ ## Step 7 — Verify drift
215
+
216
+ Only run once tests are green.
217
+
218
+ ```xml
219
+ <use_mcp_tool>
220
+ <server_name>spec-gen</server_name>
221
+ <tool_name>check_spec_drift</tool_name>
222
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
223
+ </use_mcp_tool>
224
+ ```
225
+
226
+ | Drift type | Resolution |
227
+ |---|---|
228
+ | `uncovered` on new files | Propose `spec-gen generate` post-sprint |
229
+ | `gap` on existing domain | Run `spec-gen generate --domains $DOMAIN` |
230
+ | `stale` | Fix the reference |
231
+ | No drift | ✅ |
232
+
233
+ If drift is found on a domain touched by this story, note it in the Dev Agent Record — the spec update can be proposed after the sprint, not mid-implementation.
234
+
235
+ ---
236
+
237
+ ## Step 8 — Update the story
238
+
239
+ Fill in the **Dev Agent Record** section of the story file and mark as `Review`.
240
+
241
+ Include:
242
+ - test files written / modified
243
+ - whether existing coverage was sufficient or a gap remains
244
+ - any drift found in Step 7
245
+
246
+ ---
247
+
248
+ ## Absolute constraints
249
+
250
+ - Do not write code before Step 4 confirmation
251
+ - Step 4b adversarial self-check is mandatory — never skip it
252
+ - If riskScore ≥ 70 was not caught at planning — stop, do not work around it
253
+ - Do not run `check_spec_drift` before tests are green
254
+ - Do not propose a spec update on untested code