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,274 @@
1
+ ---
2
+ name: spec-gen-implement-story
3
+ description: Implement a story on a brownfield codebase using spec-gen structural context. Runs orient + risk check before coding, validates against specs, enforces a test gate before drift check.
4
+ license: MIT
5
+ compatibility: spec-gen MCP server
6
+ user-invocable: true
7
+ allowed-tools:
8
+ - ask_followup_question
9
+ - use_mcp_tool
10
+ - read_file
11
+ - write_file
12
+ - str_replace_based_edit
13
+ - replace_in_file
14
+ - run_command
15
+ - spec-gen-execute-refactor
16
+ ---
17
+
18
+ # spec-gen: Implement Story
19
+
20
+ ## When to use this skill
21
+
22
+ Trigger this skill when the user asks to **implement a story or task** on a codebase that has
23
+ spec-gen analysis available, with phrasings like:
24
+ - "implement story X"
25
+ - "work on task Y"
26
+ - "start implementing this feature"
27
+ - explicit command `/spec-gen-implement-story`
28
+
29
+ **Prerequisite**: spec-gen analysis must exist (`spec-gen analyze` has been run).
30
+ If `orient` returns `"error": "no cache"` → run `analyze_codebase` first, then retry.
31
+
32
+ ---
33
+
34
+ ## Step 1 — Read the story and risk context
35
+
36
+ Read the story file. Extract:
37
+ - `$STORY_TITLE`, `$AC` (acceptance criteria), `$PROJECT_ROOT`
38
+ - `$RISK_CONTEXT` — the `risk_context` section if present (pre-filled by Architect Agent)
39
+
40
+ | Situation | Approach |
41
+ |---|---|
42
+ | `risk_context` present, risk 🟢 < 40 | Skip to Step 3 — use insertion point from context |
43
+ | `risk_context` present, risk 🟡 40–69 | Run Step 2 impact check, then proceed |
44
+ | `risk_context` present, risk 🔴 ≥ 70 | Stop — a blocking refactor story must be resolved first |
45
+ | `risk_context` absent | Run the full Step 2 orientation |
46
+
47
+ ---
48
+
49
+ ## Step 2 — Orient and assess risk
50
+
51
+ ```xml
52
+ <use_mcp_tool>
53
+ <server_name>spec-gen</server_name>
54
+ <tool_name>orient</tool_name>
55
+ <arguments>{
56
+ "directory": "$PROJECT_ROOT",
57
+ "task": "$STORY_TITLE",
58
+ "limit": 7
59
+ }</arguments>
60
+ </use_mcp_tool>
61
+ ```
62
+
63
+ For the top 2 functions returned, check risk:
64
+
65
+ ```xml
66
+ <use_mcp_tool>
67
+ <server_name>spec-gen</server_name>
68
+ <tool_name>analyze_impact</tool_name>
69
+ <arguments>{
70
+ "directory": "$PROJECT_ROOT",
71
+ "symbol": "$FUNCTION_NAME",
72
+ "depth": 2
73
+ }</arguments>
74
+ </use_mcp_tool>
75
+ ```
76
+
77
+ **If any function has `riskScore ≥ 70`: stop.**
78
+ Do not implement. Run `/spec-gen-execute-refactor` on the blocking function first, or create a
79
+ blocking refactor task and return to this story once the risk is resolved.
80
+
81
+ ---
82
+
83
+ ## Step 2.5 — Stack inventory (conditional)
84
+
85
+ Based on the story title and orient results, call the relevant inventory tool(s) **before reading any source file**. Skip if the story clearly involves none of these areas.
86
+
87
+ | Story involves | Tool | Purpose |
88
+ |---|---|---|
89
+ | Data models / ORM / database / tables | `get_schema_inventory` | See existing tables and fields — don't re-invent what already exists |
90
+ | HTTP routes / API / endpoints | `get_route_inventory` | See existing routes before adding new ones |
91
+ | Config / env vars / secrets | `get_env_vars` | Identify which vars are required vs have defaults |
92
+ | UI components | `get_ui_components` | See existing component props and framework |
93
+
94
+ ```xml
95
+ <use_mcp_tool>
96
+ <server_name>spec-gen</server_name>
97
+ <tool_name>get_schema_inventory</tool_name>
98
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
99
+ </use_mcp_tool>
100
+ ```
101
+
102
+ Use the results to ground the implementation in existing schemas/routes — the plan cannot contradict what already exists.
103
+
104
+ ---
105
+
106
+
107
+ ## Step 3 — Check the spec
108
+
109
+ First, verify that OpenSpec specs exist:
110
+
111
+ ```bash
112
+ ls $PROJECT_ROOT/openspec/specs/ 2>/dev/null | wc -l
113
+ ```
114
+
115
+ **If 0 specs found:**
116
+ > No OpenSpec specs exist yet. `search_specs` will return empty results and
117
+ > `check_spec_drift` (Step 7) will flag everything as uncovered.
118
+ >
119
+ > Recommended: run `/spec-gen-generate` after this story to create a spec baseline.
120
+ > You only need to do this once.
121
+ >
122
+ > Continuing with structural analysis only.
123
+
124
+ Skip the `search_specs` call and go to Step 4.
125
+
126
+ **If specs exist:**
127
+
128
+ ```xml
129
+ <use_mcp_tool>
130
+ <server_name>spec-gen</server_name>
131
+ <tool_name>search_specs</tool_name>
132
+ <arguments>{
133
+ "directory": "$PROJECT_ROOT",
134
+ "query": "$STORY_TITLE",
135
+ "limit": 5
136
+ }</arguments>
137
+ </use_mcp_tool>
138
+ ```
139
+
140
+ If relevant requirements are found, read the domain spec before writing any code.
141
+ Note any constraints that apply.
142
+
143
+ ---
144
+
145
+ ## Step 3.5 — Audit spec coverage of the target domain
146
+
147
+ Run a parity audit to check if the domain you're about to touch has spec gaps.
148
+
149
+ ```xml
150
+ <use_mcp_tool>
151
+ <server_name>spec-gen</server_name>
152
+ <tool_name>audit_spec_coverage</tool_name>
153
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
154
+ </use_mcp_tool>
155
+ ```
156
+
157
+ From the result, check:
158
+ - `staleDomains` — if the target domain appears here, its spec is outdated.
159
+ Recommend running `spec-gen generate --domains $DOMAIN` before implementing.
160
+ - `hubGaps` — uncovered hub functions. If the feature touches one of these,
161
+ add it to the adversarial check in Step 4b (high blast radius + no spec = risk).
162
+
163
+ If both are clean, continue to Step 4 without action.
164
+
165
+ ---
166
+
167
+ ## Step 4 — Find the insertion point
168
+
169
+ Use `insertion_points` from `risk_context` if present. Otherwise:
170
+
171
+ ```xml
172
+ <use_mcp_tool>
173
+ <server_name>spec-gen</server_name>
174
+ <tool_name>suggest_insertion_points</tool_name>
175
+ <arguments>{
176
+ "directory": "$PROJECT_ROOT",
177
+ "description": "$STORY_TITLE",
178
+ "limit": 5
179
+ }</arguments>
180
+ </use_mcp_tool>
181
+ ```
182
+
183
+ Read the skeleton of the target file:
184
+
185
+ ```xml
186
+ <use_mcp_tool>
187
+ <server_name>spec-gen</server_name>
188
+ <tool_name>get_function_skeleton</tool_name>
189
+ <arguments>{
190
+ "directory": "$PROJECT_ROOT",
191
+ "filePath": "$TARGET_FILE"
192
+ }</arguments>
193
+ </use_mcp_tool>
194
+ ```
195
+
196
+ **Confirm the approach with the user before writing code.**
197
+
198
+ ### Step 4b — Adversarial challenge
199
+
200
+ Before writing any code, state explicitly what could break with this approach.
201
+ If `.claude/antipatterns.md` exists, read it and include any applicable patterns.
202
+
203
+ > "Risk check on `$INSERTION_POINT`:
204
+ > - `$CALLER_A` and `$CALLER_B` depend on this function — verify their assumptions
205
+ > hold after the change.
206
+ > - `$EDGE_CASE` is not covered by the current test suite — add it in Step 6.
207
+ > - [if antipatterns apply] AP-NNN (`$PATTERN_NAME`) — `$RULE` — applies here because `$REASON`."
208
+
209
+ This is not a gate — do not wait for user input. It is a mandatory self-check
210
+ that must appear in the output before the first line of code is written.
211
+
212
+ ---
213
+
214
+ ## Step 5 — Implement
215
+
216
+ Apply changes in this order:
217
+ 1. New types/interfaces (if needed)
218
+ 2. Core logic at the insertion point
219
+ 3. Updated call sites (if any)
220
+
221
+ Do not touch functions outside the scope identified in Step 2 / `risk_context` without
222
+ re-running the gate.
223
+
224
+ **Small model constraint**: if the model is under 13B parameters (Mistral Small, Phi, Gemma…),
225
+ each edit must touch a contiguous block of at most 50 lines. Split larger changes.
226
+
227
+ ---
228
+
229
+ ## Step 6 — Tests
230
+
231
+ Both levels required before proceeding to Step 7.
232
+
233
+ **Mandatory — existing tests must not regress:**
234
+ Run the full test suite. If any pre-existing test breaks, fix the regression before continuing.
235
+
236
+ **Recommended — at least one new test per AC:**
237
+ Write a test that directly exercises the behaviour described in the acceptance criterion.
238
+
239
+ | Situation | Action |
240
+ |---|---|
241
+ | All tests green, new tests written | Proceed to Step 7 |
242
+ | Existing test broken | Fix regression. Do not proceed. |
243
+ | New test reveals a misunderstanding of the AC | Return to Step 5, adjust implementation |
244
+ | Brownfield: no existing test coverage | Write the new test anyway. Note the coverage gap. |
245
+
246
+ ---
247
+
248
+ ## Step 7 — Verify drift
249
+
250
+ Only run once tests are green.
251
+
252
+ ```xml
253
+ <use_mcp_tool>
254
+ <server_name>spec-gen</server_name>
255
+ <tool_name>check_spec_drift</tool_name>
256
+ <arguments>{"directory": "$PROJECT_ROOT"}</arguments>
257
+ </use_mcp_tool>
258
+ ```
259
+
260
+ | Drift type | Resolution |
261
+ |---|---|
262
+ | `uncovered` on new files | Note it — propose `spec-gen generate` post-sprint |
263
+ | `gap` on existing domain | Run `spec-gen generate --domains $DOMAIN` |
264
+ | `stale` | Fix the reference |
265
+ | No drift | Done |
266
+
267
+ ---
268
+
269
+ ## Absolute constraints
270
+
271
+ - Do not write code before Step 4 confirmation
272
+ - If `riskScore ≥ 70` — stop, do not work around it, run `/spec-gen-execute-refactor` first
273
+ - Do not run `check_spec_drift` before tests are green
274
+ - Do not propose a spec update on untested code
@@ -0,0 +1,251 @@
1
+ ---
2
+ name: spec-gen-plan-refactor
3
+ description: Identify the highest-priority refactoring target using static analysis, assess its blast radius, and produce a detailed written plan saved to .spec-gen/refactor-plan.md. Makes no code changes.
4
+ license: MIT
5
+ compatibility: spec-gen MCP server
6
+ user-invocable: true
7
+ allowed-tools:
8
+ - ask_followup_question
9
+ - use_mcp_tool
10
+ - read_file
11
+ - write_file
12
+ - spec-gen-analyze-codebase
13
+ - spec-gen-execute-refactor
14
+ ---
15
+
16
+ # spec-gen: Plan Refactor
17
+
18
+ ## When to use this skill
19
+
20
+ Trigger this skill whenever the user asks to **plan a refactoring** on a codebase, with phrasings like:
21
+ - "plan a refactoring of X"
22
+ - "analyze my code and prepare a refactor plan"
23
+ - "generate a refactoring plan"
24
+ - "I want to refactor this function / this file"
25
+ - explicit command `/spec-gen-plan-refactor`
26
+
27
+ **This skill modifies no code files.** It only produces `.spec-gen/refactor-plan.md`.
28
+ To apply the plan, use the `spec-gen-execute-refactor` skill.
29
+
30
+ ---
31
+
32
+ ## Step 1 — Confirm the project directory
33
+
34
+ Ask the user which project to analyze, or confirm the current workspace root.
35
+
36
+ ---
37
+
38
+ ## Step 2 — Run static analysis
39
+
40
+ Analyze the project via the `spec-gen` MCP server. If a recent analysis already exists, skip unless the user explicitly requests a fresh run.
41
+
42
+ ```xml
43
+ <use_mcp_tool>
44
+ <server_name>spec-gen</server_name>
45
+ <tool_name>analyze_codebase</tool_name>
46
+ <arguments>{"directory": "$DIRECTORY"}</arguments>
47
+ </use_mcp_tool>
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Step 3 — Get the refactoring report
53
+
54
+ ```xml
55
+ <use_mcp_tool>
56
+ <server_name>spec-gen</server_name>
57
+ <tool_name>get_refactor_report</tool_name>
58
+ <arguments>{"directory": "$DIRECTORY"}</arguments>
59
+ </use_mcp_tool>
60
+ ```
61
+
62
+ Present the top 5 candidates:
63
+
64
+ | Function | File | Issues | Priority score |
65
+ |---|---|---|---|
66
+
67
+ ---
68
+
69
+ ## Step 3b — Check for duplicate code
70
+
71
+ ```xml
72
+ <use_mcp_tool>
73
+ <server_name>spec-gen</server_name>
74
+ <tool_name>get_duplicate_report</tool_name>
75
+ <arguments>{"directory": "$DIRECTORY"}</arguments>
76
+ </use_mcp_tool>
77
+ ```
78
+
79
+ If a top candidate appears in a clone group, prepend a **deduplication note** to the plan:
80
+ > "⚠️ `<function>` has N near-clones. Consolidate them first to reduce the blast radius of this refactor."
81
+
82
+ ---
83
+
84
+ ## Step 3c — Check test coverage
85
+
86
+ Detect the coverage tool from the project and run it on the candidate files:
87
+
88
+ | Ecosystem | Command |
89
+ |---|---|
90
+ | Node.js | `npm test -- --coverage --collectCoverageFrom="<files>"` |
91
+ | Python | `pytest --cov=<module> --cov-report=term-missing` |
92
+ | Rust | `cargo tarpaulin --include-files <files>` |
93
+ | Go | `go test -cover ./...` |
94
+
95
+ Enrich the candidate table:
96
+
97
+ | Function | File | Priority | Coverage |
98
+ |---|---|---|---|
99
+ | ... | ... | ... | 72% ✅ / 35% ⚠️ / 0% 🚫 |
100
+
101
+ **Thresholds:**
102
+
103
+ | Coverage | Badge | Meaning |
104
+ |---|---|---|
105
+ | ≥ 70% lines | ✅ | Safe to refactor |
106
+ | 40–69% lines | ⚠️ | Write characterisation tests first |
107
+ | < 40% lines | 🛑 | Strongly discouraged |
108
+ | 0% (no tests) | 🚫 | Blocked — propose a test harness first |
109
+
110
+ If **all candidates are below 40%**:
111
+ > "Every high-priority target has insufficient test coverage (< 40%). I recommend writing a minimal test harness for at least one target before proceeding. Would you like me to suggest test cases based on the function signatures?"
112
+
113
+ ---
114
+
115
+ ## Step 4 — Analyze impact
116
+
117
+ ```xml
118
+ <use_mcp_tool>
119
+ <server_name>spec-gen</server_name>
120
+ <tool_name>analyze_impact</tool_name>
121
+ <arguments>{"directory": "$DIRECTORY", "symbol": "$FUNCTION_NAME"}</arguments>
122
+ </use_mcp_tool>
123
+ ```
124
+
125
+ Note: risk score (0–100), recommended strategy (`extract` / `split` / `facade` / `delegate`), top 5 upstream callers and downstream callees.
126
+
127
+ ---
128
+
129
+ ## Step 5 — Visualise the call neighbourhood
130
+
131
+ ```xml
132
+ <use_mcp_tool>
133
+ <server_name>spec-gen</server_name>
134
+ <tool_name>get_subgraph</tool_name>
135
+ <arguments>{"directory": "$DIRECTORY", "functionName": "$FUNCTION_NAME", "direction": "both", "format": "mermaid"}</arguments>
136
+ </use_mcp_tool>
137
+ ```
138
+
139
+ Show the Mermaid diagram to the user.
140
+
141
+ ---
142
+
143
+ ## Step 6 — Find safe entry points (bottom-up)
144
+
145
+ ```xml
146
+ <use_mcp_tool>
147
+ <server_name>spec-gen</server_name>
148
+ <tool_name>get_low_risk_refactor_candidates</tool_name>
149
+ <arguments>{"directory": "$DIRECTORY", "filePattern": "$TARGET_FILE", "limit": 5}</arguments>
150
+ </use_mcp_tool>
151
+ ```
152
+
153
+ Cross-reference with the subgraph from Step 5: a good first extraction candidate already appears as a callee of the target function.
154
+
155
+ ---
156
+
157
+ ## Step 7 — Design the change sequence
158
+
159
+ Design an ordered sequence of atomic changes based on the strategy from Step 4. Each change must specify:
160
+
161
+ - **What**: the exact block to move (line range or description)
162
+ - **New name**: the function or method name to give it
163
+ - **Target file**: existing or new file (with justification)
164
+ - **Target class** (if applicable)
165
+ - **Call sites to update**: list each `file:line`
166
+
167
+ **Rules per strategy:**
168
+
169
+ | Strategy | Rule |
170
+ |---|---|
171
+ | `split` | Decompose into N sub-functions in the same file unless they clearly belong elsewhere |
172
+ | `extract` | Place in the nearest cohesive module or create a new file if none exists |
173
+ | `facade` | Keep the original signature, delegate to smaller functions; companion module if > 300 lines |
174
+ | `delegate` | Move ownership logic to callers; update every caller file in the upstream chain |
175
+
176
+ **Present the full sequence and wait for confirmation before writing the plan file.**
177
+
178
+ ---
179
+
180
+ ## Step 8 — Write `.spec-gen/refactor-plan.md`
181
+
182
+ Fill every section — **leave nothing as "TBD"**.
183
+
184
+ ```markdown
185
+ # Refactor Plan
186
+
187
+ Generated: <ISO date>
188
+ Workflow: /spec-gen-plan-refactor → /spec-gen-execute-refactor
189
+
190
+ ## Target
191
+ - **Function**: <name>
192
+ - **File**: <relative path>
193
+ - **Lines**: <start>–<end>
194
+ - **Risk score**: <0–100>
195
+ - **Strategy**: <extract | split | facade | delegate>
196
+ - **Priority score before refactor**: <value>
197
+
198
+ ## Why
199
+ - <issue 1>
200
+ - <issue 2>
201
+
202
+ ## Callers (upstream — must not break)
203
+ | Caller | File |
204
+ |---|---|
205
+
206
+ ## Callees (downstream — candidates for extraction)
207
+ | Callee | File |
208
+ |---|---|
209
+
210
+ ## Coverage baseline
211
+ - **File**: <target file>
212
+ - **Coverage**: <X>% lines, <Y>% branches
213
+ - **Status**: ✅ safe / ⚠️ caution / 🛑 discouraged
214
+ - **Test command**: <exact command>
215
+
216
+ ## Change sequence
217
+ Apply in order. Run tests after each step.
218
+
219
+ ### Change 1 — <short label>
220
+ - **What**: extract lines <start>–<end> (logic: <one-line description>)
221
+ - **New function name**: `<name>`
222
+ - **Target file**: `<path>` (<new file | existing file — reason>)
223
+ - **Target class**: `<ClassName>` or none
224
+ - **Call sites to update**: <list each file:line>
225
+ - **Expected diff**: +<N> lines in <target file>, -<M> lines in <source file>
226
+
227
+ ### Change 2 — <short label>
228
+ ...
229
+
230
+ ## Acceptance criteria
231
+ - Priority score drops below <target score> in `get_refactor_report`
232
+ - Function exits the top-5 list
233
+ - Full test suite passes (green)
234
+ - `git diff --stat` shows only the expected files
235
+
236
+ ## Restore point
237
+ Hash: <to be filled by the execute workflow>
238
+ ```
239
+
240
+ Once the file is written:
241
+ > "Plan written to `.spec-gen/refactor-plan.md`. Review it, then run `/spec-gen-execute-refactor` to apply the changes."
242
+
243
+ ---
244
+
245
+ ## Absolute constraints
246
+
247
+ - **No code modifications** in this workflow
248
+ - Always read the source file to confirm exact line numbers
249
+ - Never leave a section empty or as "TBD"
250
+ - Prefer candidates with higher coverage when scores are otherwise close
251
+ - If the user does not pick a target, default to the top candidate
@@ -0,0 +1,59 @@
1
+ # Example: OpenSpec CLI Analysis
2
+
3
+ This directory contains the output of running `spec-gen analyze` against the OpenSpec CLI codebase itself.
4
+
5
+ ## How This Was Generated
6
+
7
+ ```bash
8
+ cd /path/to/OpenSpec-main
9
+ spec-gen init
10
+ spec-gen analyze
11
+ ```
12
+
13
+ ## Output Files
14
+
15
+ | File | Description |
16
+ |------|-------------|
17
+ | `config.json` | spec-gen configuration for the project |
18
+ | `SUMMARY.md` | Human-readable analysis summary |
19
+ | `repo-structure.json` | Complete file metadata and significance scores |
20
+ | `dependency-graph.json` | Import/export relationships between files |
21
+ | `llm-context.json` | Optimized context for LLM generation |
22
+ | `dependencies.mermaid` | Visual dependency graph |
23
+
24
+ ## Key Findings
25
+
26
+ From analyzing the OpenSpec CLI:
27
+
28
+ - **221 files analyzed** (TypeScript, Markdown, JSON)
29
+ - **50 high-value files** identified for spec generation
30
+ - **37 domain clusters** detected
31
+
32
+ ### Detected Domains
33
+
34
+ 1. **completions** - Shell completion providers (16 files)
35
+ 2. **command-generation** - IDE command generation (26 files)
36
+ 3. **artifact-graph** - Artifact dependency resolution (7 files)
37
+ 4. **schemas** - Configuration schemas (9 files)
38
+ 5. **validation** - Spec validation (3 files)
39
+ 6. **commands** - CLI commands (14 files)
40
+ 7. **parsers** - Markdown/requirement parsing (3 files)
41
+
42
+ ### Top Significant Files
43
+
44
+ 1. `src/core/completions/types.ts` (score: 65)
45
+ 2. `src/core/command-generation/types.ts` (score: 65)
46
+ 3. `src/core/artifact-graph/types.ts` (score: 65)
47
+ 4. `src/core/config-schema.ts` (score: 65)
48
+ 5. `src/core/schemas/change.schema.ts` (score: 60)
49
+
50
+ ## Next Steps
51
+
52
+ To generate full specifications, run:
53
+
54
+ ```bash
55
+ export ANTHROPIC_API_KEY=sk-ant-...
56
+ spec-gen generate
57
+ ```
58
+
59
+ This will create OpenSpec-format specifications in `openspec/specs/`.
@@ -0,0 +1,72 @@
1
+ # Repository Analysis: @fission-ai/openspec
2
+
3
+ ## Overview
4
+ - **Type**: Node.js/TypeScript
5
+ - **Frameworks**: Vitest, GitHub Actions
6
+ - **Files Analyzed**: 221 of 231 (10 skipped)
7
+ - **Analysis Date**: 2026-01-31T15:45:00.646Z
8
+
9
+ ## Architecture Pattern
10
+ This appears to be a **unknown** architecture.
11
+
12
+ **Detected Layers:**
13
+ - Infrastructure Layer: Configuration, middleware, and utilities (30 files)
14
+
15
+ ## Language Breakdown
16
+ | Language | Files | Percentage |
17
+ |----------|-------|------------|
18
+ | TypeScript | 172 | 78.0% |
19
+ | Markdown | 26 | 12.0% |
20
+ | JSON | 7 | 3.0% |
21
+ | | 4 | 2.0% |
22
+ | JavaScript | 3 | 1.0% |
23
+
24
+ ## Detected Domains
25
+ These domains will become OpenSpec specifications:
26
+
27
+ | Domain | Files | Key Entities | Spec Path |
28
+ |--------|-------|--------------|-----------|
29
+ | completions | 16 | CompletionProvider, Factory, BashGenerator | `openspec/specs/completions/spec.md` |
30
+ | command-generation | 26 | Registry, Cursor, Windsurf | `openspec/specs/command-generation/spec.md` |
31
+ | artifact-graph | 7 | Schema, Resolver, InstructionLoader | `openspec/specs/artifact-graph/spec.md` |
32
+ | schemas | 9 | ChangeSchema, BaseSchema, SchemaYaml | `openspec/specs/schemas/spec.md` |
33
+ | validation | 3 | Validator | `openspec/specs/validation/spec.md` |
34
+ | commands | 14 | Schemas, Feedback, Schema | `openspec/specs/commands/spec.md` |
35
+ | parsers | 3 | RequirementBlocks, ChangeParser, MarkdownParser | `openspec/specs/parsers/spec.md` |
36
+ | templates | 2 | SkillTemplates | `openspec/specs/templates/spec.md` |
37
+ | users | 5 | LlmContextJson, SUMMARYMd, DependencyGraphJson | `openspec/specs/users/spec.md` |
38
+ | ui | 2 | AsciiPatterns, WelcomeScreen | `openspec/specs/ui/spec.md` |
39
+
40
+ ## Dependency Insights
41
+
42
+ **Most Connected Files:**
43
+ - `package.json` (5 connections)
44
+ - `src/commands/feedback.ts` (1 connections)
45
+ - `src/core/init.ts` (1 connections)
46
+
47
+ **Orphan Files**: 215 file(s) with no imports or exports
48
+
49
+ ## Files Selected for Deep Analysis
50
+ The following files were selected as most significant:
51
+
52
+ 1. `src/core/completions/types.ts` (score: 65) - high-value-name
53
+ 2. `src/core/command-generation/types.ts` (score: 65) - high-value-name
54
+ 3. `src/core/artifact-graph/types.ts` (score: 65) - high-value-name
55
+ 4. `src/core/config-schema.ts` (score: 65) - schema, high-value-name
56
+ 5. `src/core/schemas/change.schema.ts` (score: 60) - schema, high-value-name
57
+ 6. `src/core/schemas/base.schema.ts` (score: 60) - schema, high-value-name
58
+ 7. `src/core/validation/types.ts` (score: 60) - high-value-name
59
+ 8. `src/core/artifact-graph/schema.ts` (score: 60) - schema, high-value-name
60
+ 9. `src/core/global-config.ts` (score: 60) - config, high-value-name
61
+ 10. `src/core/project-config.ts` (score: 60) - config, high-value-name
62
+ 11. `src/core/completions/completion-provider.ts` (score: 55) - service
63
+ 12. `src/core/config.ts` (score: 55) - config, high-value-name
64
+ 13. `src/commands/workflow/schemas.ts` (score: 55) - schema, high-value-name
65
+ 14. `src/commands/feedback.ts` (score: 55) - high-value-name
66
+ 15. `src/telemetry/config.ts` (score: 55) - config, high-value-name
67
+
68
+ ## Recommendations
69
+ - Review 215 orphan file(s) that may be unused
70
+
71
+ ---
72
+ *Generated by spec-gen v1.0.0*
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "projectType": "nodejs",
4
+ "openspecPath": "./openspec",
5
+ "analysis": {
6
+ "maxFiles": 500,
7
+ "includePatterns": [],
8
+ "excludePatterns": []
9
+ },
10
+ "generation": {
11
+ "model": "claude-sonnet-4-20250514",
12
+ "domains": "auto"
13
+ },
14
+ "createdAt": "2026-01-31T15:44:29.845Z",
15
+ "lastRun": null
16
+ }