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,123 @@
1
+ # Parsing Specification
2
+
3
+ > Generated by spec-gen on 2025-01-30
4
+ > Source files: src/core/parsers/markdown-parser.ts, src/core/parsers/change-parser.ts, src/core/parsers/requirement-blocks.ts
5
+
6
+ ## Purpose
7
+
8
+ Handles parsing of markdown-based specification files into structured data. Supports section-based extraction, requirement normalization, and delta block parsing for changes.
9
+
10
+ ## Entities
11
+
12
+ ### ParsedSection
13
+
14
+ | Property | Type | Description |
15
+ |----------|------|-------------|
16
+ | heading | string | Section heading text |
17
+ | level | number | Heading level (1-6) |
18
+ | content | string | Section body content |
19
+ | children | ParsedSection[] | Nested subsections |
20
+
21
+ ### ParsedRequirement
22
+
23
+ | Property | Type | Description |
24
+ |----------|------|-------------|
25
+ | name | string | Requirement identifier |
26
+ | text | string | Full requirement text |
27
+ | scenarios | ParsedScenario[] | Associated test scenarios |
28
+ | line | number | Source line number |
29
+
30
+ ### DeltaBlock
31
+
32
+ | Property | Type | Description |
33
+ |----------|------|-------------|
34
+ | operation | 'ADDED' \| 'MODIFIED' \| 'REMOVED' \| 'RENAMED' | Delta type |
35
+ | specPath | string | Target spec file path |
36
+ | content | string | Delta content |
37
+
38
+ ## Requirements
39
+
40
+ ### Requirement: SectionParsing
41
+
42
+ The system SHALL parse markdown files into hierarchical section structures based on heading levels.
43
+
44
+ #### Scenario: NestedHeadingExtraction
45
+ - **GIVEN** a markdown file with h1, h2, and h3 headings
46
+ - **WHEN** the file is parsed
47
+ - **THEN** sections are organized hierarchically
48
+ - **AND** h2 sections are children of h1 sections
49
+
50
+ #### Scenario: ContentExtraction
51
+ - **GIVEN** a section with paragraph text and code blocks
52
+ - **WHEN** the section is parsed
53
+ - **THEN** all content between headings is captured
54
+ - **AND** code blocks are preserved with formatting
55
+
56
+ ### Requirement: RequirementExtraction
57
+
58
+ The system SHALL extract requirements from spec files following the "### Requirement:" pattern.
59
+
60
+ #### Scenario: StandardRequirementParsing
61
+ - **GIVEN** a spec with "### Requirement: UserAuth" heading
62
+ - **WHEN** requirements are extracted
63
+ - **THEN** a requirement named "UserAuth" is returned
64
+ - **AND** the requirement text includes the paragraph below the heading
65
+
66
+ #### Scenario: RequirementWithScenarios
67
+ - **GIVEN** a requirement followed by "#### Scenario:" subsections
68
+ - **WHEN** the requirement is parsed
69
+ - **THEN** all scenarios are associated with the requirement
70
+ - **AND** Given/When/Then content is captured
71
+
72
+ ### Requirement: DeltaBlockParsing
73
+
74
+ The system SHALL parse delta blocks (ADDED, MODIFIED, REMOVED, RENAMED) from change spec files.
75
+
76
+ #### Scenario: AddedRequirementParsing
77
+ - **GIVEN** a change file with "## ADDED Requirements" section
78
+ - **WHEN** deltas are extracted
79
+ - **THEN** delta blocks with operation "ADDED" are returned
80
+ - **AND** the spec path and content are captured
81
+
82
+ #### Scenario: ModifiedRequirementParsing
83
+ - **GIVEN** a change file with "## MODIFIED Requirements" section
84
+ - **WHEN** deltas are extracted
85
+ - **THEN** delta blocks with operation "MODIFIED" are returned
86
+ - **AND** the full updated requirement content is included
87
+
88
+ #### Scenario: RemovedRequirementParsing
89
+ - **GIVEN** a change file with "## REMOVED Requirements" section containing "Reason:"
90
+ - **WHEN** deltas are extracted
91
+ - **THEN** delta blocks with operation "REMOVED" are returned
92
+ - **AND** the removal reason is preserved
93
+
94
+ ### Requirement: GivenWhenThenExtraction
95
+
96
+ The system SHALL extract Given/When/Then scenario content with proper formatting.
97
+
98
+ #### Scenario: BoldLabelExtraction
99
+ - **GIVEN** a scenario with "- **GIVEN** user is logged in"
100
+ - **WHEN** the scenario is parsed
101
+ - **THEN** the "GIVEN" clause is extracted as "user is logged in"
102
+
103
+ #### Scenario: MultipleThens
104
+ - **GIVEN** a scenario with THEN and AND clauses
105
+ - **WHEN** the scenario is parsed
106
+ - **THEN** all outcome clauses are captured
107
+ - **AND** the AND clause is included in outcomes
108
+
109
+ ### Requirement: ErrorRecovery
110
+
111
+ The system SHOULD attempt partial parsing when encountering malformed content.
112
+
113
+ #### Scenario: MalformedSectionRecovery
114
+ - **GIVEN** a spec file with one malformed section among valid sections
115
+ - **WHEN** parsing is attempted
116
+ - **THEN** valid sections are still extracted
117
+ - **AND** a warning is reported for the malformed section
118
+
119
+ ## Technical Notes
120
+
121
+ - **Implementation**: `src/core/parsers/markdown-parser.ts`, `src/core/parsers/change-parser.ts`
122
+ - **Pattern**: Regex-based extraction with fallback strategies
123
+ - **Dependencies**: None (pure TypeScript implementation)
@@ -0,0 +1,108 @@
1
+ # Validation Specification
2
+
3
+ > Generated by spec-gen on 2025-01-30
4
+ > Source files: src/core/validation/validator.ts, src/core/schemas/*.ts
5
+
6
+ ## Purpose
7
+
8
+ Provides comprehensive validation of specs and changes using Zod schemas and custom semantic rules. Ensures all specifications follow RFC 2119 conventions and contain required elements.
9
+
10
+ ## Entities
11
+
12
+ ### ValidationReport
13
+
14
+ | Property | Type | Description |
15
+ |----------|------|-------------|
16
+ | isValid | boolean | Overall validation result |
17
+ | errors | ValidationMessage[] | Critical issues that must be fixed |
18
+ | warnings | ValidationMessage[] | Issues that should be addressed |
19
+ | info | ValidationMessage[] | Informational notes |
20
+
21
+ ### ValidationMessage
22
+
23
+ | Property | Type | Description |
24
+ |----------|------|-------------|
25
+ | code | string | Error code (e.g., "MISSING_SHALL") |
26
+ | message | string | Human-readable description |
27
+ | location | string | File path or section reference |
28
+
29
+ ## Requirements
30
+
31
+ ### Requirement: SchemaValidation
32
+
33
+ The system SHALL validate specs and changes against Zod schemas before processing.
34
+
35
+ #### Scenario: ValidSpecStructure
36
+ - **GIVEN** a spec file with valid YAML frontmatter and markdown body
37
+ - **WHEN** validation is performed
38
+ - **THEN** the schema validation passes
39
+ - **AND** no structural errors are reported
40
+
41
+ #### Scenario: InvalidSpecStructure
42
+ - **GIVEN** a spec file missing required sections
43
+ - **WHEN** validation is performed
44
+ - **THEN** schema validation fails
45
+ - **AND** specific missing sections are identified in errors
46
+
47
+ ### Requirement: RFC2119Keywords
48
+
49
+ The system SHALL require RFC 2119 keywords (SHALL, MUST, SHOULD, MAY) in all requirements.
50
+
51
+ #### Scenario: RequirementWithShall
52
+ - **GIVEN** a requirement containing "The system SHALL validate input"
53
+ - **WHEN** keyword validation is performed
54
+ - **THEN** validation passes for this requirement
55
+
56
+ #### Scenario: RequirementWithoutKeyword
57
+ - **GIVEN** a requirement stating "The system validates input" (no keyword)
58
+ - **WHEN** keyword validation is performed
59
+ - **THEN** validation fails with error code "MISSING_SHALL"
60
+ - **AND** the error message indicates the requirement needs RFC 2119 keyword
61
+
62
+ ### Requirement: ScenarioPresence
63
+
64
+ The system SHALL require at least one scenario for each requirement.
65
+
66
+ #### Scenario: RequirementWithScenarios
67
+ - **GIVEN** a requirement with two scenarios defined
68
+ - **WHEN** scenario validation is performed
69
+ - **THEN** validation passes
70
+
71
+ #### Scenario: RequirementWithoutScenarios
72
+ - **GIVEN** a requirement with no scenarios
73
+ - **WHEN** scenario validation is performed
74
+ - **THEN** validation fails with error "MISSING_SCENARIOS"
75
+
76
+ ### Requirement: ChangeWhyValidation
77
+
78
+ The system SHALL validate that change proposals include a "Why" section between 50-500 characters.
79
+
80
+ #### Scenario: ValidWhySection
81
+ - **GIVEN** a change with Why section of 150 characters
82
+ - **WHEN** change validation is performed
83
+ - **THEN** validation passes
84
+
85
+ #### Scenario: WhySectionTooShort
86
+ - **GIVEN** a change with Why section of 30 characters
87
+ - **WHEN** change validation is performed
88
+ - **THEN** validation fails with "WHY_TOO_SHORT" error
89
+
90
+ ### Requirement: DeltaLimitEnforcement
91
+
92
+ The system SHALL enforce a maximum of 20 deltas per change to maintain focused changes.
93
+
94
+ #### Scenario: ChangeWithinLimit
95
+ - **GIVEN** a change with 15 delta operations
96
+ - **WHEN** delta count validation is performed
97
+ - **THEN** validation passes
98
+
99
+ #### Scenario: ChangeExceedsLimit
100
+ - **GIVEN** a change with 25 delta operations
101
+ - **WHEN** delta count validation is performed
102
+ - **THEN** validation fails with "TOO_MANY_DELTAS" error
103
+
104
+ ## Technical Notes
105
+
106
+ - **Implementation**: `src/core/validation/validator.ts`, `src/core/schemas/`
107
+ - **Pattern**: Zod schemas + custom rule validators
108
+ - **Dependencies**: Zod library for schema validation
@@ -0,0 +1,104 @@
1
+ # spec-gen extension for spec-kit
2
+
3
+ Adds structural risk analysis and spec drift verification to the
4
+ [spec-kit](https://github.com/github/spec-kit) Spec-Driven Development workflow.
5
+
6
+ Part of the [spec-gen agentic workflow pattern](../../docs/agentic-workflows/README.md).
7
+
8
+ ## What it does
9
+
10
+ | Hook | Command | When |
11
+ |---|---|---|
12
+ | `before_implement` | `speckit.spec-gen.orient` | Before `/speckit.implement` — orient + risk gate |
13
+ | `after_implement` | `speckit.spec-gen.drift` | After implementation + green tests — drift check |
14
+
15
+ ## When to use it
16
+
17
+ **Brownfield** (existing codebase): always useful. `orient` surfaces high-risk functions
18
+ before you touch them; `drift` confirms the implementation stays aligned with specs.
19
+
20
+ **Greenfield** (new project, no existing code): skip `orient` (nothing to analyse yet).
21
+ `drift` is useful once `spec-gen generate` has been run at least once.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ # In your project directory
27
+ specify extension add spec-gen
28
+ ```
29
+
30
+ Or manually copy this directory into `.specify/extensions/spec-gen/`.
31
+
32
+ ## Prerequisites
33
+
34
+ 1. spec-gen MCP server running and configured in your AI agent
35
+ 2. `spec-gen analyze $PROJECT_ROOT` run at least once
36
+
37
+ ## Workflow
38
+
39
+ ```mermaid
40
+ flowchart TD
41
+ A["/speckit.specify\nspec from requirements"] --> B["/speckit.plan\ntechnical plan"]
42
+ B --> C["/speckit.tasks\ntask breakdown"]
43
+ C --> ORIENT
44
+
45
+ subgraph SG_PRE ["spec-gen — pre-flight (brownfield)"]
46
+ ORIENT["speckit.spec-gen.orient\norient + analyze_impact"]
47
+ ORIENT --> GATE{risk ≥ 70?}
48
+ GATE -- yes --> BLOCKED["🔴 blocked\nadd refactor task"]
49
+ GATE -- no --> RISK_CTX["Risk Context\npasted into tasks.md"]
50
+ end
51
+
52
+ RISK_CTX --> D["/speckit.implement\nexecute tasks"]
53
+ BLOCKED --> C
54
+
55
+ D --> TESTS["tests green ✅"]
56
+ TESTS --> DRIFT
57
+
58
+ subgraph SG_POST ["spec-gen — post-flight"]
59
+ DRIFT["speckit.spec-gen.drift\ncheck_spec_drift"]
60
+ DRIFT --> E{drift?}
61
+ E -- stale --> FIX["fix spec reference now"]
62
+ E -- gap/uncovered --> NOTE["note for post-sprint\nspec-gen generate"]
63
+ E -- none --> CLEAN["✅ clean"]
64
+ end
65
+
66
+ style BLOCKED fill:#fdd,stroke:#c00
67
+ style TESTS fill:#d4edda,stroke:#28a745
68
+ ```
69
+
70
+ ```
71
+ /speckit.specify → spec from requirements
72
+ /speckit.plan → technical plan from spec
73
+ /speckit.tasks → task breakdown from plan
74
+
75
+ # spec-gen pre-flight (brownfield only)
76
+ /speckit.spec-gen.orient → orient + risk gate → paste Risk Context into tasks.md
77
+
78
+ /speckit.implement → execute tasks
79
+
80
+ # spec-gen post-flight (once tests are green)
81
+ /speckit.spec-gen.drift → drift check → note any spec updates needed
82
+ ```
83
+
84
+ ## OpenSpec spec baseline
85
+
86
+ `speckit.spec-gen.orient` uses `search_specs` to surface relevant requirements, and
87
+ `speckit.spec-gen.drift` uses `check_spec_drift` to verify alignment. Both require
88
+ OpenSpec specs to exist — without them, results are empty or everything shows as uncovered.
89
+
90
+ | State | What to do |
91
+ |---|---|
92
+ | No specs yet | Run `spec-gen generate $PROJECT_ROOT` once before the first sprint |
93
+ | Specs exist | Both commands work as expected |
94
+ | New code not yet spec'd | `drift` will flag it as `uncovered` — run `spec-gen generate` to update |
95
+
96
+ Both commands detect missing specs automatically and offer to run `spec-gen generate`.
97
+
98
+ ## Risk gate
99
+
100
+ | Score | Level | Action |
101
+ |---|---|---|
102
+ | < 40 | 🟢 low | Proceed |
103
+ | 40–69 | 🟡 medium | Proceed — protect listed callers |
104
+ | ≥ 70 | 🔴 high / critical | Stop — refactor first |
@@ -0,0 +1,87 @@
1
+ ---
2
+ description: "Post-implementation spec drift check — verify the implementation matches existing OpenSpec specifications."
3
+ tools:
4
+ - 'spec-gen/check_spec_drift'
5
+ ---
6
+
7
+ # spec-gen: Drift Check
8
+
9
+ Run this command **after** `/speckit.implement` and **only once tests are green**.
10
+
11
+ It compares the implementation against existing OpenSpec specifications and reports
12
+ gaps, stale references, and uncovered files.
13
+
14
+ > **No specs yet?** If `spec-gen generate` has not been run on this project,
15
+ > this command will report everything as uncovered — that is expected and not a problem.
16
+ >
17
+ > **What to do:** Run `spec-gen generate $PROJECT_ROOT` now to create a spec baseline
18
+ > from the current codebase. Once generated, re-run this command — future drift checks
19
+ > will be meaningful. A baseline only needs to be created once.
20
+
21
+ ## Prerequisites
22
+
23
+ 1. spec-gen MCP server configured in your AI agent settings
24
+ 2. Tests passing — do not run drift check on a red test suite
25
+ 3. `spec-gen analyze` run at least once (same requirement as orient)
26
+
27
+ ## User Input
28
+
29
+ $ARGUMENTS
30
+
31
+ If a project directory is provided, use it. Otherwise use the current working directory.
32
+
33
+ ## Step 1 — Check spec baseline
34
+
35
+ ```bash
36
+ ls $PROJECT_ROOT/openspec/specs/ 2>/dev/null | wc -l
37
+ ```
38
+
39
+ **If 0 specs found:**
40
+ > "No OpenSpec specs exist yet. Running `check_spec_drift` now will flag all files as
41
+ > uncovered, which is not actionable.
42
+ >
43
+ > Run `spec-gen generate $PROJECT_ROOT` first to create a spec baseline, then re-run
44
+ > this command. The generate step takes a few minutes and only needs to be done once."
45
+ >
46
+ > Ask: "Run `spec-gen generate` now? (yes/no)"
47
+ > - Yes → trigger generate, then proceed to Step 2
48
+ > - No → stop here, remind user to run it before next drift check
49
+
50
+ **If specs exist**: proceed.
51
+
52
+ ## Step 2 — Confirm tests are green
53
+
54
+ Ask the user: "Are all tests passing?"
55
+
56
+ If the answer is no: "Run tests first and fix any failures. Drift check is only
57
+ meaningful on a green test suite." Stop here.
58
+
59
+ ## Step 3 — Run drift check
60
+
61
+ ```
62
+ spec-gen check_spec_drift
63
+ directory: $PROJECT_ROOT
64
+ ```
65
+
66
+ ## Step 4 — Interpret results
67
+
68
+ | Drift type | Meaning | Action |
69
+ |---|---|---|
70
+ | `uncovered` on new files | New code not yet in any spec | Note for post-sprint spec update |
71
+ | `gap` on existing domain | Existing spec missing coverage of new behaviour | Run `spec-gen generate --domains $DOMAIN` |
72
+ | `stale` | Spec references a function that no longer exists | Fix the reference in the spec file |
73
+ | No drift | ✅ Implementation matches specs | Done |
74
+
75
+ ## Step 5 — Output
76
+
77
+ Report findings in a compact table. For each gap or uncovered item:
78
+ - Which file / domain is affected
79
+ - Recommended action (generate, update, or fix)
80
+
81
+ If drift is found on domains touched by this implementation:
82
+ > "Spec drift detected. These updates can be applied now with `spec-gen generate`
83
+ > or batched post-sprint. Recommend: note them in `.specify/{feature}/plan.md`
84
+ > under a `## Spec Updates` section rather than interrupting the current sprint."
85
+
86
+ If no drift:
87
+ > "✅ No spec drift. Implementation is consistent with existing OpenSpec specifications."
@@ -0,0 +1,138 @@
1
+ ---
2
+ description: "Pre-flight structural risk check — orient + analyze_impact before implementation. Gates on riskScore ≥ 70."
3
+ tools:
4
+ - 'spec-gen/orient'
5
+ - 'spec-gen/analyze_impact'
6
+ - 'spec-gen/search_specs'
7
+ ---
8
+
9
+ # spec-gen: Pre-flight Check
10
+
11
+ Run this command **before** `/speckit.implement` on an existing codebase.
12
+ It identifies the functions affected by the planned tasks, scores their blast radius,
13
+ and surfaces any spec requirements that apply — so you don't discover high-risk
14
+ areas mid-implementation.
15
+
16
+ > **Greenfield projects** (no existing codebase): skip this command.
17
+ > It is only useful when implementing against an existing codebase.
18
+
19
+ ## Prerequisites
20
+
21
+ 1. spec-gen MCP server configured in your AI agent settings
22
+ 2. `spec-gen analyze` run at least once on the project directory
23
+ (produces the `.spec-gen/` cache used by orient)
24
+
25
+ ## User Input
26
+
27
+ $ARGUMENTS
28
+
29
+ If a project directory is provided, use it. Otherwise use the current working directory.
30
+
31
+ ## Step 1 — Read tasks.md
32
+
33
+ Read `.specify/{feature}/tasks.md` to extract the list of planned tasks.
34
+ Summarise the implementation intent in one sentence — this is the `$TASK_DESCRIPTION`
35
+ passed to orient.
36
+
37
+ If tasks.md does not exist, ask the user for a brief description of what they are about
38
+ to implement.
39
+
40
+ ## Step 2 — Orient
41
+
42
+ ```
43
+ spec-gen orient
44
+ directory: $PROJECT_ROOT
45
+ task: $TASK_DESCRIPTION
46
+ limit: 7
47
+ ```
48
+
49
+ If orient returns `"error": "no cache"`:
50
+ > "spec-gen has no analysis cache for this project. Run `spec-gen analyze $PROJECT_ROOT`
51
+ > first (takes ~1 min), then re-run `/speckit.spec-gen.orient`."
52
+ > Stop here.
53
+
54
+ ## Step 3 — Check spec baseline
55
+
56
+ Check whether OpenSpec specifications exist for this project:
57
+
58
+ ```bash
59
+ ls $PROJECT_ROOT/openspec/specs/ 2>/dev/null | head -5
60
+ ```
61
+
62
+ **If no specs exist** (`openspec/specs/` is absent or empty):
63
+ > "No OpenSpec specs found. `search_specs` and `check_spec_drift` will return empty
64
+ > results until specs are generated.
65
+ >
66
+ > Recommended: run `spec-gen generate $PROJECT_ROOT` after this sprint to create a
67
+ > spec baseline from the existing code. You only need to do this once — subsequent
68
+ > sprints will have specs to align against.
69
+ >
70
+ > Continuing with structural analysis only (orient + impact)."
71
+
72
+ **If specs exist**: proceed to search_specs below.
73
+
74
+ ## Step 4 — Check existing requirements
75
+
76
+ ```
77
+ spec-gen search_specs
78
+ directory: $PROJECT_ROOT
79
+ query: $TASK_DESCRIPTION
80
+ limit: 5
81
+ ```
82
+
83
+ If relevant requirements are found, list them. Note any constraints that apply to the
84
+ planned implementation.
85
+
86
+ If `search_specs` returns no results despite specs existing, note it — the planned
87
+ change may be in an area not yet covered by specs.
88
+
89
+ ## Step 5 — Impact analysis
90
+
91
+ For each of the top 2 functions returned by orient:
92
+
93
+ ```
94
+ spec-gen analyze_impact
95
+ directory: $PROJECT_ROOT
96
+ symbol: $FUNCTION_NAME
97
+ depth: 2
98
+ ```
99
+
100
+ Build a risk summary table:
101
+
102
+ | Function | File | Risk Score | Level | Callers |
103
+ |----------|------|-----------|-------|---------|
104
+
105
+ ## Step 6 — Decision gate
106
+
107
+ | Max risk score | Action |
108
+ |---|---|
109
+ | < 40 | 🟢 Proceed — risk is low. Show insertion points from orient. |
110
+ | 40–69 | 🟡 Proceed with caution — protect the callers listed above. |
111
+ | ≥ 70 | 🔴 **Stop.** Do not implement until the high-risk function is refactored. |
112
+
113
+ **If any function has riskScore ≥ 70:**
114
+
115
+ > "⚠️ High structural risk detected on `$FUNCTION_NAME` (score: $SCORE).
116
+ > Implementing against this function risks breaking $CALLER_COUNT callers.
117
+ >
118
+ > Recommended: add a refactor task to tasks.md for `$FUNCTION_NAME` and schedule
119
+ > it before the tasks that touch it. Then re-run `/speckit.spec-gen.orient`."
120
+ >
121
+ > Stop and wait for user confirmation before proceeding.
122
+
123
+ ## Step 7 — Summary
124
+
125
+ Output a compact block to paste into tasks.md or plan.md as a `## Risk Context` note:
126
+
127
+ ```
128
+ ## Risk Context (spec-gen)
129
+ - Domains: {domains}
130
+ - Max risk: {score} {badge}
131
+ - Functions in scope: {fn1} ({file1}), {fn2} ({file2})
132
+ - Callers to protect: {callers}
133
+ - Blocking refactors: {none | list}
134
+ - Insertion point: {top insertion point}
135
+ ```
136
+
137
+ Ask the user: "Paste this into your tasks.md? (yes/no)"
138
+ If yes, append it before the first task phase.
@@ -0,0 +1,54 @@
1
+ schema_version: "1.0"
2
+
3
+ extension:
4
+ id: "spec-gen"
5
+ name: "spec-gen structural analysis"
6
+ version: "1.0.0"
7
+ description: "Pre-flight structural risk check and post-implementation spec drift verification via spec-gen MCP."
8
+ author: "spec-gen contributors"
9
+ repository: "https://github.com/clay-good/spec-gen"
10
+ license: "MIT"
11
+ homepage: "https://github.com/clay-good/spec-gen"
12
+
13
+ requires:
14
+ speckit_version: ">=0.1.0"
15
+ tools:
16
+ - name: "spec-gen"
17
+ version: ">=1.2.0"
18
+ required: true
19
+
20
+ provides:
21
+ commands:
22
+ - name: "speckit.spec-gen.orient"
23
+ file: "commands/orient.md"
24
+ description: "Pre-flight check — orient + analyze_impact before implementation. Gates on riskScore ≥ 70."
25
+
26
+ - name: "speckit.spec-gen.drift"
27
+ file: "commands/drift.md"
28
+ description: "Post-implementation spec drift check. Run after tests are green."
29
+
30
+ hooks:
31
+ before_implement:
32
+ command: "speckit.spec-gen.orient"
33
+ optional: true
34
+ prompt: "Run spec-gen structural risk check before implementing?"
35
+ description: "Identifies high-risk functions and spec requirements relevant to the planned tasks."
36
+
37
+ after_implement:
38
+ command: "speckit.spec-gen.drift"
39
+ optional: true
40
+ prompt: "Run spec-gen drift check to verify implementation matches specs?"
41
+ description: "Detects gaps between the implementation and existing OpenSpec specifications."
42
+
43
+ tags:
44
+ - "static-analysis"
45
+ - "risk-management"
46
+ - "spec-driven"
47
+ - "brownfield"
48
+ - "mcp"
49
+
50
+ defaults:
51
+ analysis:
52
+ orient_limit: 7
53
+ impact_depth: 2
54
+ risk_threshold: 70
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-gen-cli",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Reverse-engineer OpenSpec specifications from existing codebases",
5
5
  "type": "module",
6
6
  "main": "dist/api/index.js",
@@ -64,6 +64,7 @@
64
64
  "dist",
65
65
  "!dist/**/*.test.*",
66
66
  "src/viewer",
67
+ "examples",
67
68
  "README.md",
68
69
  "LICENSE"
69
70
  ],
@@ -102,8 +103,7 @@
102
103
  "yaml": "^2.6.1"
103
104
  },
104
105
  "optionalDependencies": {
105
- "@lancedb/lancedb-darwin-x64": "^0.26.2",
106
- "@lancedb/lancedb-linux-x64-gnu": "^0.26.2"
106
+ "tree-sitter-cli": "^0.23"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@eslint/js": "^9.17.0",
@@ -116,8 +116,5 @@
116
116
  "typescript": "^5.7.2",
117
117
  "typescript-eslint": "^8.19.1",
118
118
  "vitest": "^4.0.18"
119
- },
120
- "optionalDependencies": {
121
- "tree-sitter-cli": "^0.23"
122
119
  }
123
120
  }