specdx 0.4.0-alpha.9 → 0.4.0

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 (114) hide show
  1. package/.claude-plugin/plugin.json +7 -2
  2. package/README.md +259 -0
  3. package/dist/{check-4FSSC6HN.js → check-PHXXA7VY.js} +68 -30
  4. package/dist/check-PHXXA7VY.js.map +1 -0
  5. package/dist/chunk-2BZIG7OE.js +185 -0
  6. package/dist/chunk-2BZIG7OE.js.map +1 -0
  7. package/dist/{chunk-N77RNV7J.js → chunk-3YXRWQGX.js} +217 -42
  8. package/dist/chunk-3YXRWQGX.js.map +1 -0
  9. package/dist/chunk-5WRI5ZAA.js +31 -0
  10. package/dist/chunk-DMGABJ6T.js +41 -0
  11. package/dist/chunk-DMGABJ6T.js.map +1 -0
  12. package/dist/{chunk-7JXW2GTJ.js → chunk-HCJDCS26.js} +9 -2
  13. package/dist/chunk-HCJDCS26.js.map +1 -0
  14. package/dist/chunk-LJTLNXGV.js +835 -0
  15. package/dist/chunk-LJTLNXGV.js.map +1 -0
  16. package/dist/chunk-NAWYG4VV.js +2846 -0
  17. package/dist/chunk-NAWYG4VV.js.map +1 -0
  18. package/dist/chunk-NHD44ZYN.js +20 -0
  19. package/dist/chunk-NHD44ZYN.js.map +1 -0
  20. package/dist/chunk-OVIKIIR4.js +103 -0
  21. package/dist/chunk-OVIKIIR4.js.map +1 -0
  22. package/dist/{chunk-IHTYAW7C.js → chunk-SNQNQ2MP.js} +111 -7
  23. package/dist/chunk-SNQNQ2MP.js.map +1 -0
  24. package/dist/{chunk-AKNPCB37.js → chunk-YRQPY5NF.js} +32 -12
  25. package/dist/chunk-YRQPY5NF.js.map +1 -0
  26. package/dist/diff-6C5LJ7SH.js +200 -0
  27. package/dist/diff-6C5LJ7SH.js.map +1 -0
  28. package/dist/{dist-4DIRTBJH.js → dist-PK52GA7M.js} +43 -20
  29. package/dist/dist-PK52GA7M.js.map +1 -0
  30. package/dist/{dist-RL2DT3ZE.js → dist-ROHCFKYT.js} +3 -2
  31. package/dist/dist-ROHCFKYT.js.map +1 -0
  32. package/dist/generate-K72WD455.js +21 -0
  33. package/dist/generate-K72WD455.js.map +1 -0
  34. package/dist/{generate-story-EFHGINHA.js → generate-story-NUCNYL3I.js} +43 -19
  35. package/dist/generate-story-NUCNYL3I.js.map +1 -0
  36. package/dist/{generate-test-plan-BO7444RG.js → generate-test-plan-Z46W3N3B.js} +61 -11
  37. package/dist/generate-test-plan-Z46W3N3B.js.map +1 -0
  38. package/dist/{graph-5XINV7PT.js → graph-4RNURBNP.js} +49 -11
  39. package/dist/graph-4RNURBNP.js.map +1 -0
  40. package/dist/index.d.ts +275 -0
  41. package/dist/index.js +2660 -371
  42. package/dist/index.js.map +1 -1
  43. package/dist/{lint-PTMWMLDQ.js → lint-2VZPNLE3.js} +46 -18
  44. package/dist/lint-2VZPNLE3.js.map +1 -0
  45. package/dist/main.js +10 -229
  46. package/dist/main.js.map +1 -1
  47. package/dist/mcp-E6PJWBDQ.js +35 -0
  48. package/dist/mcp-E6PJWBDQ.js.map +1 -0
  49. package/dist/{migrate-4KF6GHLO.js → migrate-FKFC7UAO.js} +21 -9
  50. package/dist/migrate-FKFC7UAO.js.map +1 -0
  51. package/dist/{pack-DSOODXAN.js → pack-DE4UBTCC.js} +41 -13
  52. package/dist/pack-DE4UBTCC.js.map +1 -0
  53. package/dist/{ready-6DNKIHP6.js → ready-K74SLQ24.js} +55 -14
  54. package/dist/ready-K74SLQ24.js.map +1 -0
  55. package/dist/skills/{specdx-author-spec.md → core/specdx-author-spec/SKILL.md} +10 -6
  56. package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-01-frontmatter.md +1 -1
  57. package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-02-sections.md +41 -0
  58. package/dist/skills/{specdx-onboard.md → core/specdx-onboard/SKILL.md} +8 -3
  59. package/dist/skills/{specdx-plan-from-spec.md → core/specdx-plan-from-spec/SKILL.md} +5 -1
  60. package/dist/skills/{specdx-pre-commit.md → core/specdx-pre-commit/SKILL.md} +16 -2
  61. package/dist/skills/{specdx-review-spec.md → core/specdx-review-spec/SKILL.md} +5 -1
  62. package/dist/skills/core/specdx-router/SKILL.md +67 -0
  63. package/dist/skills/{specdx-sprint-review.md → core/specdx-sprint-review/SKILL.md} +6 -2
  64. package/dist/skills/{specdx-start-task.md → core/specdx-start-task/SKILL.md} +5 -1
  65. package/dist/skills/{specdx-check-drift.md → experimental/specdx-check-drift/SKILL.md} +10 -4
  66. package/dist/skills/{specdx-verify.md → experimental/specdx-verify/SKILL.md} +6 -2
  67. package/dist/skills-36SRUEMR.js +121 -0
  68. package/dist/skills-36SRUEMR.js.map +1 -0
  69. package/dist/{status-WZK247CI.js → status-IAE3BB77.js} +63 -32
  70. package/dist/status-IAE3BB77.js.map +1 -0
  71. package/dist/{update-JTNSYX3B.js → update-UFOHZEAK.js} +22 -12
  72. package/dist/update-UFOHZEAK.js.map +1 -0
  73. package/dist/{validate-LBDYWUDX.js → validate-EZHUB5TW.js} +36 -17
  74. package/dist/validate-EZHUB5TW.js.map +1 -0
  75. package/hooks/hooks.json +12 -6
  76. package/hooks/session-start +35 -3
  77. package/package.json +28 -13
  78. package/dist/changelog-XUVHY3QK.js +0 -93
  79. package/dist/changelog-XUVHY3QK.js.map +0 -1
  80. package/dist/check-4FSSC6HN.js.map +0 -1
  81. package/dist/chunk-7JXW2GTJ.js.map +0 -1
  82. package/dist/chunk-AKNPCB37.js.map +0 -1
  83. package/dist/chunk-DAZCOUVK.js +0 -496
  84. package/dist/chunk-DAZCOUVK.js.map +0 -1
  85. package/dist/chunk-GAM4MXPC.js +0 -15
  86. package/dist/chunk-GAM4MXPC.js.map +0 -1
  87. package/dist/chunk-IHTYAW7C.js.map +0 -1
  88. package/dist/chunk-N77RNV7J.js.map +0 -1
  89. package/dist/chunk-SRZ33RJP.js +0 -1147
  90. package/dist/chunk-SRZ33RJP.js.map +0 -1
  91. package/dist/diff-OXZ34NU4.js +0 -107
  92. package/dist/diff-OXZ34NU4.js.map +0 -1
  93. package/dist/dist-4DIRTBJH.js.map +0 -1
  94. package/dist/explain-QBV3AESQ.js +0 -109
  95. package/dist/explain-QBV3AESQ.js.map +0 -1
  96. package/dist/generate-7GNPT2WJ.js +0 -13
  97. package/dist/generate-7GNPT2WJ.js.map +0 -1
  98. package/dist/generate-story-EFHGINHA.js.map +0 -1
  99. package/dist/generate-test-plan-BO7444RG.js.map +0 -1
  100. package/dist/graph-5XINV7PT.js.map +0 -1
  101. package/dist/lint-PTMWMLDQ.js.map +0 -1
  102. package/dist/mcp-BGFAPM6G.js +0 -17
  103. package/dist/mcp-BGFAPM6G.js.map +0 -1
  104. package/dist/migrate-4KF6GHLO.js.map +0 -1
  105. package/dist/pack-DSOODXAN.js.map +0 -1
  106. package/dist/ready-6DNKIHP6.js.map +0 -1
  107. package/dist/skills-3GBBWZW2.js +0 -93
  108. package/dist/skills-3GBBWZW2.js.map +0 -1
  109. package/dist/status-WZK247CI.js.map +0 -1
  110. package/dist/update-JTNSYX3B.js.map +0 -1
  111. package/dist/validate-LBDYWUDX.js.map +0 -1
  112. /package/dist/{dist-RL2DT3ZE.js.map → chunk-5WRI5ZAA.js.map} +0 -0
  113. /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
  114. /package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-03-finalize.md +0 -0
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "specdx",
3
- "version": "0.4.0-alpha.1",
3
+ "version": "0.4.0",
4
4
  "description": "Spec-driven development skills for Claude Code",
5
- "commands": "./dist/skills"
5
+ "author": {
6
+ "name": "umxr",
7
+ "url": "https://github.com/umxr"
8
+ },
9
+ "skills": "./dist/skills/core",
10
+ "hooks": "./hooks/hooks.json"
6
11
  }
package/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # specdx
2
+
3
+ > Keep AI coding sessions grounded in specs your team actually maintains.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/specdx)](https://www.npmjs.com/package/specdx)
6
+ [![license](https://img.shields.io/npm/l/specdx)](LICENSE)
7
+ [![CI](https://github.com/umxr/specdx/actions/workflows/ci.yml/badge.svg)](https://github.com/umxr/specdx/actions/workflows/ci.yml)
8
+
9
+ specdx gives your PRDs, technical designs, user stories and API contracts a
10
+ schema, lints them for the gaps an LLM will trip over, and packs the relevant
11
+ ones into a token budget before you start coding. No LLM calls in the pipeline,
12
+ no API key, deterministic enough to gate a pull request on.
13
+
14
+ ```bash
15
+ npm install -D specdx
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```bash
21
+ npx specdx init --template lightweight # scaffold specs/ and spec.config.yaml
22
+ npx specdx lint # find the gaps
23
+ ```
24
+
25
+ `init` writes specs with placeholder sections, and `lint` tells you which ones
26
+ still need filling in. Once they have real content, pack it for a task:
27
+
28
+ ```bash
29
+ npx specdx pack --task "add rate limiting" --copy
30
+ ```
31
+
32
+ This scores every spec for relevance to the task, fits the best of them into a
33
+ token budget, strips boilerplate, and puts the result on your clipboard. Paste
34
+ it into your LLM session — or let the Claude Code plugin run it for you.
35
+
36
+ It exits 3 and packs nothing if no spec is relevant yet, rather than handing you
37
+ an empty context that looks like an answer.
38
+
39
+ ## Why
40
+
41
+ An LLM writing code against your project is only as good as the context it was
42
+ given. In practice that context is pasted by hand, half-remembered, and stale.
43
+
44
+ specdx makes it a build artifact:
45
+
46
+ - **Specs are validated, not vibes.** Required sections per type, cross-references
47
+ that must resolve, dependency cycles caught. Thirteen rules, three presets.
48
+ - **Context is budgeted, not dumped.** `pack` picks what is relevant to the task
49
+ at hand and fits it to a token limit, instead of pasting the whole folder.
50
+ - **Drift is visible.** Change the PRD and `diff` tells you which downstream
51
+ specs the change reached, before the gap compounds.
52
+
53
+ ## The loop
54
+
55
+ ```bash
56
+ specdx pack --task "what you're about to build" --copy # before you code
57
+ specdx lint # before you commit
58
+ specdx diff # what changed, and what it affects
59
+ specdx ready # is this fit to build from?
60
+ ```
61
+
62
+ `ready` is the gate between planning and building: required specs present, lint
63
+ clean, references resolving, nothing stale, and every PRD feature carrying a
64
+ user story.
65
+
66
+ ## Configuration
67
+
68
+ `spec.config.yaml` at the project root. Only `version` and `specs` are required.
69
+
70
+ ```yaml
71
+ version: "1.0"
72
+ project:
73
+ name: "my-project"
74
+
75
+ specs:
76
+ prd:
77
+ path: specs/prd.md
78
+ type: prd
79
+ required: true
80
+ technical:
81
+ path: specs/technical-design.md
82
+ type: technical-design
83
+ requires: ["prd"]
84
+ stories:
85
+ path: "specs/stories/*.md"
86
+ type: user-story
87
+ requires: ["prd"]
88
+
89
+ lint:
90
+ extends: "recommended" # minimal | recommended | strict
91
+ ```
92
+
93
+ `requires` is what builds the dependency graph, and the graph is what makes
94
+ `diff` able to tell you that changing the PRD stales the test plan.
95
+
96
+ **→ [Full configuration reference](docs/configuration.md)** — lint rule
97
+ overrides, custom rules, pack budgets, staleness thresholds, `check` paths.
98
+
99
+ ## Spec format
100
+
101
+ Markdown with YAML frontmatter. Nine types, each with required sections.
102
+
103
+ ```markdown
104
+ ---
105
+ id: "prd-001"
106
+ type: "prd"
107
+ title: "User authentication"
108
+ status: "approved"
109
+ version: "1.0"
110
+ created: "2026-03-01"
111
+ authors: ["alice"]
112
+ ---
113
+
114
+ ## Problem Statement
115
+
116
+ The application has no authentication, so every endpoint is public.
117
+ ```
118
+
119
+ `created` must be quoted, or YAML turns it into a date object.
120
+
121
+ **→ [Spec format reference](docs/spec-format.md)** — all nine types and their
122
+ required sections, cross-references, declared artifacts, and the three sections
123
+ `check` parses.
124
+
125
+ ## Editor and agent integration
126
+
127
+ ### Claude Code
128
+
129
+ specdx ships as a plugin with **ten skills**. Install it as a dev dependency and
130
+ the plugin is discovered automatically:
131
+
132
+ ```bash
133
+ npm install -D specdx
134
+ ```
135
+
136
+ Or write the skill files into `.claude/skills/` yourself:
137
+
138
+ ```bash
139
+ npx specdx skills install # the eight promoted skills
140
+ npx specdx skills install --experimental # also the two check-based ones
141
+ ```
142
+
143
+ | Skill | What it does |
144
+ |-------|-------------|
145
+ | `specdx-router` | Maps every skill and when to reach for it. Start here. |
146
+ | `specdx-start-task` | Loads spec context before coding |
147
+ | `specdx-author-spec` | Guides spec writing, linting between sections |
148
+ | `specdx-plan-from-spec` | Turns specs into an implementation plan |
149
+ | `specdx-review-spec` | Multi-layer quality review of a new spec |
150
+ | `specdx-pre-commit` | Catches drift before it enters git history |
151
+ | `specdx-onboard` | Guided tour of an unfamiliar spec suite |
152
+ | `specdx-sprint-review` | Shareable spec health summary |
153
+ | `specdx-verify` | *(experimental)* Checks implementation against specs |
154
+ | `specdx-check-drift` | *(experimental)* Cross-references code changes vs specs |
155
+
156
+ ### MCP
157
+
158
+ Every tool is exposed over the Model Context Protocol:
159
+
160
+ ```bash
161
+ specdx mcp
162
+ ```
163
+
164
+ Seven tools: `sdx_validate`, `sdx_lint`, `sdx_pack`, `sdx_status`, `sdx_check`,
165
+ `sdx_diff`, `sdx_graph`.
166
+
167
+ **→ [Cursor and Gemini CLI setup](docs/other-platforms.md)**
168
+
169
+ ## CI
170
+
171
+ ```yaml
172
+ permissions:
173
+ contents: read
174
+ pull-requests: write
175
+
176
+ steps:
177
+ - uses: actions/checkout@v4
178
+ with: { fetch-depth: 0 }
179
+ - uses: umxr/specdx/packages/github-action@v0
180
+ with:
181
+ preset: recommended
182
+ github-token: ${{ secrets.GITHUB_TOKEN }}
183
+ ```
184
+
185
+ The action lints and diffs every pull request, posts a health comment it updates
186
+ in place, and fails the job when spec paths resolve to no files — zero specs
187
+ checked is not a pass.
188
+
189
+ Any CI can run the CLI directly instead: `specdx lint --format github` emits
190
+ inline annotations and exits non-zero on failure.
191
+
192
+ **→ [CI reference](docs/ci.md)**
193
+
194
+ ## CLI
195
+
196
+ | Command | Description |
197
+ |---------|-------------|
198
+ | `specdx init` | Scaffold a spec suite (`--template lightweight\|bmad\|api-first\|quick\|context`) |
199
+ | `specdx lint` | Lint all specs (`--preset`, `--fix`) |
200
+ | `specdx validate` | Validate `spec.config.yaml` |
201
+ | `specdx pack --task <task>` | Pack specs into token-budgeted context (`--copy`, `--full`) |
202
+ | `specdx status` | Spec suite health overview |
203
+ | `specdx diff` | Spec changes and downstream impact (`--working`, `--base`, `--head`) |
204
+ | `specdx graph` | Print the dependency graph |
205
+ | `specdx ready` | Is the suite fit to implement from? |
206
+ | `specdx generate story --from <id>` | Generate story stubs from a PRD |
207
+ | `specdx skills install` | Install Claude Code skills |
208
+ | `specdx mcp` | Start the MCP server |
209
+ | `specdx check` | *(experimental)* Spec-to-implementation drift |
210
+ | `specdx update` | *(experimental)* Suggest spec updates from drift |
211
+ | `specdx generate test-plan` | *(experimental)* Test plan stub from stories |
212
+ | `specdx migrate` | *(experimental)* Migrate spec suite schema |
213
+
214
+ `--quiet` and `--verbose` are available on the reporting commands — run
215
+ `specdx <command> --help` for what each one takes.
216
+
217
+ `--format` is per command, because not every command renders every format.
218
+ Asking for one a command does not render is an error, not a silent fallback.
219
+
220
+ | Formats | Commands |
221
+ |---|---|
222
+ | `pretty`, `json`, `github` | `lint`, `status`, `check` |
223
+ | `pretty`, `json` | `validate`, `ready`, `update` |
224
+ | `pretty`, `json`, `dot` | `graph` |
225
+ | `pretty`, `json`, `changelog` | `diff` |
226
+ | `xml`, `markdown`, `json` | `pack` |
227
+
228
+ ## Experimental
229
+
230
+ These ship with specdx but sit outside the stable surface — they lean on static
231
+ code analysis, which is inherently fuzzy, so their output and interfaces may
232
+ change. They are flagged `[experimental]` in `--help`.
233
+
234
+ `specdx check` extracts routes (Express, Hono, Next.js), types (TypeScript, Zod,
235
+ Prisma) and tests from your code and compares them against your specs. Where no
236
+ framework extractor applies — static sites, CLIs, libraries — a spec can declare
237
+ [artifacts](docs/spec-format.md#declared-artifacts) instead: files that must
238
+ exist and names they must export.
239
+
240
+ Accuracy feedback is what graduates these to stable.
241
+
242
+ ## How it compares
243
+
244
+ **Markdown linters** (markdownlint, remark-lint) check formatting. specdx checks
245
+ semantics: required sections by spec type, cross-reference validity, dependency
246
+ cycles, downstream staleness.
247
+
248
+ **JSON Schema validators** check structure. specdx adds document-level rules
249
+ that understand how specs relate to each other — and a packer that turns the
250
+ suite into context an LLM can actually use.
251
+
252
+ ## Contributing
253
+
254
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, writing custom
255
+ lint rules, and the PR process.
256
+
257
+ ## License
258
+
259
+ MIT — see [LICENSE](LICENSE).
@@ -1,35 +1,49 @@
1
1
  import {
2
2
  runCheck
3
- } from "./chunk-N77RNV7J.js";
3
+ } from "./chunk-3YXRWQGX.js";
4
4
  import {
5
+ createOutput
6
+ } from "./chunk-NHD44ZYN.js";
7
+ import {
8
+ resolveFormat,
5
9
  sharedArgs
6
- } from "./chunk-GAM4MXPC.js";
10
+ } from "./chunk-DMGABJ6T.js";
7
11
  import {
8
12
  createLogger,
9
13
  loadConfig,
10
14
  parseSpec,
11
15
  resolveGlob
12
- } from "./chunk-IHTYAW7C.js";
13
- import "./chunk-7JXW2GTJ.js";
16
+ } from "./chunk-SNQNQ2MP.js";
17
+ import "./chunk-HCJDCS26.js";
18
+ import "./chunk-5WRI5ZAA.js";
14
19
 
15
- // src/commands/check.ts
20
+ // src/commands/experimental/check.ts
16
21
  import { defineCommand } from "citty";
22
+ var FORMATS = ["pretty", "json", "github"];
17
23
  var check_default = defineCommand({
18
24
  meta: {
19
25
  name: "check",
20
- description: "[experimental] Check spec-to-implementation drift. Exit codes: 0 ok, 1 errors found, 3 nothing checkable (coverage not assessed)"
26
+ description: "Check spec-to-implementation drift. Exit codes: 0 ok, 1 errors found, 3 nothing checkable (coverage not assessed)"
21
27
  },
22
28
  args: {
23
- ...sharedArgs,
29
+ ...sharedArgs(FORMATS),
24
30
  spec: { type: "string", description: "Check a specific spec by ID" },
25
31
  framework: { type: "string", description: "Framework override: express, hono, nextjs" },
26
32
  ai: {
27
33
  type: "boolean",
28
- description: "[experimental] Use AI to assess findings (requires ANTHROPIC_API_KEY)"
34
+ description: "Use AI to assess findings (requires ANTHROPIC_API_KEY)"
29
35
  }
30
36
  },
31
37
  async run({ args }) {
38
+ const format = resolveFormat(args.format, FORMATS);
39
+ if (!format.ok) {
40
+ console.error(`
41
+ \u2717 ${format.message}
42
+ `);
43
+ process.exit(1);
44
+ }
32
45
  const logger = createLogger({ quiet: args.quiet, verbose: args.verbose });
46
+ const output = createOutput({ quiet: args.quiet });
33
47
  const configDir = process.cwd();
34
48
  const config = await loadConfig(void 0, configDir);
35
49
  logger.debug("Loading specs...");
@@ -49,13 +63,21 @@ var check_default = defineCommand({
49
63
  logger.debug(`Checking ${specs.length} specs...`);
50
64
  const result = await runCheck(specs, configDir, checkConfig);
51
65
  if (args.ai) {
52
- const { analyzeWithAi } = await import("./dist-RL2DT3ZE.js");
53
- const aiResult = await analyzeWithAi(result.findings, args.spec ?? "full suite check");
54
- if (args.format === "json") {
66
+ const { analyzeWithAi } = await import("./dist-ROHCFKYT.js");
67
+ let aiResult;
68
+ try {
69
+ aiResult = await analyzeWithAi(result.findings, args.spec ?? "full suite check");
70
+ } catch (err) {
71
+ console.error(`
72
+ \u2717 ${err.message}
73
+ `);
74
+ process.exit(1);
75
+ }
76
+ if (format.format === "json") {
55
77
  console.log(JSON.stringify({ ...result, ai: aiResult }, null, 2));
56
78
  } else {
57
79
  console.log(`
58
- sdx check --ai \u2014 ${result.score.overall}% coverage
80
+ specdx check --ai \u2014 ${result.score.overall}% coverage
59
81
  `);
60
82
  console.log(` AI Assessment: ${aiResult.summary}
61
83
  `);
@@ -77,48 +99,64 @@ var check_default = defineCommand({
77
99
  }
78
100
  return;
79
101
  }
80
- if (args.format === "json") {
102
+ if (format.format === "json") {
81
103
  console.log(JSON.stringify(result, null, 2));
104
+ } else if (format.format === "github") {
105
+ console.log(
106
+ `::notice::specdx check \u2014 ${result.score.assessed ? `${result.score.overall}% implementation coverage` : "coverage not assessed \u2014 no checkable surfaces found"}`
107
+ );
108
+ for (const note of result.notes) {
109
+ console.log(`::notice::${note}`);
110
+ }
111
+ for (const f of result.findings) {
112
+ const level = f.severity === "error" ? "error" : f.severity === "warn" ? "warning" : "notice";
113
+ const location = f.codeLocation ? ` file=${f.codeLocation.file},line=${f.codeLocation.line}` : "";
114
+ const detail = f.actual ? ` \u2014 ${f.actual}` : "";
115
+ console.log(`::${level}${location}::[${f.specId}] ${f.expected}${detail}`);
116
+ }
82
117
  } else {
83
118
  const headline = result.score.assessed ? `${result.score.overall}% implementation coverage` : "coverage not assessed \u2014 no checkable surfaces found";
84
- console.log(`
85
- sdx check \u2014 ${headline}
119
+ output.info(`
120
+ specdx check \u2014 ${headline}
86
121
  `);
87
122
  for (const note of result.notes) {
88
- console.log(` \u26A0 ${note}`);
123
+ output.out(` \u26A0 ${note}`);
89
124
  }
90
- if (result.notes.length > 0) console.log();
125
+ if (result.notes.length > 0) output.out();
91
126
  if (args.verbose) {
92
127
  const fmt = (n) => n === null ? "not scanned" : `${n} found`;
93
- console.log(` Scanned: framework=${result.scanned.framework ?? "none detected"}`);
94
- console.log(` routes: ${fmt(result.scanned.codeRoutes)}`);
95
- console.log(` types: ${fmt(result.scanned.codeTypes)}`);
96
- console.log(` tests: ${fmt(result.scanned.codeTests)}`);
97
- const artifacts = result.scanned.artifacts === null ? "none declared" : `${result.scanned.artifacts} verified`;
128
+ output.out(` Scanned: framework=${result.scanned.framework ?? "none detected"}`);
129
+ output.out(` routes: ${fmt(result.scanned.codeRoutes)}`);
130
+ output.out(` types: ${fmt(result.scanned.codeTypes)}`);
131
+ output.out(` tests: ${fmt(result.scanned.codeTests)}`);
132
+ const artifacts = result.scanned.artifacts === null ? "none declared" : `${result.scanned.artifacts} assessed`;
98
133
  const pending = result.scanned.artifactsPending > 0 ? `, ${result.scanned.artifactsPending} pending` : "";
99
- console.log(` artifacts: ${artifacts}${pending}
134
+ output.out(` artifacts: ${artifacts}${pending}
100
135
  `);
101
136
  }
102
137
  for (const [category, stats] of Object.entries(result.score.byCategory)) {
103
138
  if (stats.total === 0) continue;
104
- console.log(` ${category} (${stats.matched}/${stats.total}):`);
105
139
  const categoryFindings = result.findings.filter(
106
140
  (f) => f.category === category.replace(/s$/, "")
107
141
  );
142
+ const header = ` ${category} (${stats.matched}/${stats.total}):`;
143
+ if (categoryFindings.length === 0) {
144
+ output.info(header);
145
+ output.info(" \u2713 all matched");
146
+ continue;
147
+ }
148
+ output.out(header);
108
149
  for (const f of categoryFindings) {
109
150
  const icon = f.severity === "error" ? "\u2717" : f.severity === "warn" ? "\u26A0" : "\u2139";
110
151
  const detail = f.actual ? ` \u2014 ${f.actual}` : "";
111
152
  const suggestion = f.suggestion ? ` (${f.suggestion})` : "";
112
- console.log(` ${icon} ${f.expected}${detail}${suggestion}`);
113
- }
114
- if (categoryFindings.length === 0) {
115
- console.log(" \u2713 all matched");
153
+ output.out(` ${icon} ${f.expected}${detail}${suggestion}`);
116
154
  }
117
155
  }
118
156
  const errors = result.findings.filter((f) => f.severity === "error").length;
119
157
  const warnings = result.findings.filter((f) => f.severity === "warn").length;
120
158
  const info = result.findings.filter((f) => f.severity === "info").length;
121
- console.log(`
159
+ output.info(`
122
160
  ${errors} errors, ${warnings} warnings, ${info} info
123
161
  `);
124
162
  }
@@ -133,4 +171,4 @@ var check_default = defineCommand({
133
171
  export {
134
172
  check_default as default
135
173
  };
136
- //# sourceMappingURL=check-4FSSC6HN.js.map
174
+ //# sourceMappingURL=check-PHXXA7VY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/experimental/check.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { loadConfig, parseSpec, resolveGlob, createLogger } from \"@specdx/core\";\nimport { runCheck } from \"@specdx/check\";\nimport type { ParsedSpec } from \"@specdx/core\";\nimport type { CheckConfig } from \"@specdx/check\";\nimport { sharedArgs, resolveFormat } from \"../../shared-args.js\";\nimport { createOutput } from \"../../output.js\";\n\nconst FORMATS = [\"pretty\", \"json\", \"github\"] as const;\n\nexport default defineCommand({\n meta: {\n name: \"check\",\n description:\n \"Check spec-to-implementation drift. Exit codes: 0 ok, 1 errors found, 3 nothing checkable (coverage not assessed)\",\n },\n args: {\n ...sharedArgs(FORMATS),\n spec: { type: \"string\", description: \"Check a specific spec by ID\" },\n framework: { type: \"string\", description: \"Framework override: express, hono, nextjs\" },\n ai: {\n type: \"boolean\",\n description: \"Use AI to assess findings (requires ANTHROPIC_API_KEY)\",\n },\n },\n async run({ args }) {\n const format = resolveFormat(args.format, FORMATS);\n if (!format.ok) {\n console.error(`\\n ✗ ${format.message}\\n`);\n process.exit(1);\n }\n\n const logger = createLogger({ quiet: args.quiet, verbose: args.verbose });\n const output = createOutput({ quiet: args.quiet });\n const configDir = process.cwd();\n const config = await loadConfig(undefined, configDir);\n\n logger.debug(\"Loading specs...\");\n\n // Resolve and parse all specs\n const specs: ParsedSpec[] = [];\n for (const [, entry] of Object.entries(config.specs)) {\n const paths = await resolveGlob(entry.path, configDir);\n for (const p of paths) {\n const spec = await parseSpec(p);\n if (args.spec && spec.frontmatter.id !== args.spec) continue;\n specs.push(spec);\n }\n }\n\n const checkConfig: CheckConfig = {\n ...config.check,\n ...(args.framework ? { framework: args.framework as CheckConfig[\"framework\"] } : {}),\n };\n\n logger.debug(`Checking ${specs.length} specs...`);\n const result = await runCheck(specs, configDir, checkConfig);\n\n // AI analysis (opt-in)\n if (args.ai) {\n const { analyzeWithAi } = await import(\"@specdx/check\");\n // A missing key is a user error, not a crash. It used to surface as an\n // uncaught Error with the full Node trace through citty, where every\n // other user-error path in the CLI prints \"✗ …\" (audit run 5, F7).\n let aiResult;\n try {\n aiResult = await analyzeWithAi(result.findings, args.spec ?? \"full suite check\");\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`);\n process.exit(1);\n }\n\n if (format.format === \"json\") {\n console.log(JSON.stringify({ ...result, ai: aiResult }, null, 2));\n } else {\n console.log(`\\n specdx check --ai — ${result.score.overall}% coverage\\n`);\n console.log(` AI Assessment: ${aiResult.summary}\\n`);\n\n for (const assessment of aiResult.assessments) {\n const finding = result.findings[assessment.findingIndex];\n if (!finding) continue;\n const icon = assessment.isRealIssue ? \"✗\" : \"✓\";\n const label = assessment.isRealIssue ? \"REAL\" : \"FALSE POSITIVE\";\n console.log(` ${icon} [${label}] ${finding.expected}`);\n console.log(` ${assessment.reasoning}`);\n if (assessment.suggestedFix) {\n console.log(` Fix: ${assessment.suggestedFix}`);\n }\n }\n console.log();\n }\n\n if (aiResult.assessments.some((a) => a.isRealIssue)) {\n process.exit(1);\n }\n return;\n }\n\n if (format.format === \"json\") {\n console.log(JSON.stringify(result, null, 2));\n } else if (format.format === \"github\") {\n // Annotations for CI. A finding about missing code has no file to point\n // at, so the spec ID carries the location instead. The headline always\n // prints: a clean or unassessable run must still say something, or the\n // format is silent for exactly the projects that most need telling.\n console.log(\n `::notice::specdx check — ${\n result.score.assessed\n ? `${result.score.overall}% implementation coverage`\n : \"coverage not assessed — no checkable surfaces found\"\n }`,\n );\n for (const note of result.notes) {\n console.log(`::notice::${note}`);\n }\n for (const f of result.findings) {\n const level =\n f.severity === \"error\" ? \"error\" : f.severity === \"warn\" ? \"warning\" : \"notice\";\n const location = f.codeLocation\n ? ` file=${f.codeLocation.file},line=${f.codeLocation.line}`\n : \"\";\n const detail = f.actual ? ` — ${f.actual}` : \"\";\n console.log(`::${level}${location}::[${f.specId}] ${f.expected}${detail}`);\n }\n } else {\n // Pretty format\n const headline = result.score.assessed\n ? `${result.score.overall}% implementation coverage`\n : \"coverage not assessed — no checkable surfaces found\";\n output.info(`\\n specdx check — ${headline}\\n`);\n\n for (const note of result.notes) {\n output.out(` ⚠ ${note}`);\n }\n if (result.notes.length > 0) output.out();\n\n if (args.verbose) {\n const fmt = (n: number | null) => (n === null ? \"not scanned\" : `${n} found`);\n output.out(` Scanned: framework=${result.scanned.framework ?? \"none detected\"}`);\n output.out(` routes: ${fmt(result.scanned.codeRoutes)}`);\n output.out(` types: ${fmt(result.scanned.codeTypes)}`);\n output.out(` tests: ${fmt(result.scanned.codeTests)}`);\n // \"assessed\", not \"verified\": this counts the assertions considered,\n // and a failed one is reported below. Calling six verified while the\n // next line says 5/6 made the output contradict itself (F6).\n const artifacts =\n result.scanned.artifacts === null\n ? \"none declared\"\n : `${result.scanned.artifacts} assessed`;\n const pending =\n result.scanned.artifactsPending > 0 ? `, ${result.scanned.artifactsPending} pending` : \"\";\n output.out(` artifacts: ${artifacts}${pending}\\n`);\n }\n\n for (const [category, stats] of Object.entries(result.score.byCategory)) {\n if (stats.total === 0) continue;\n const categoryFindings = result.findings.filter(\n (f) => f.category === category.replace(/s$/, \"\"),\n );\n const header = ` ${category} (${stats.matched}/${stats.total}):`;\n if (categoryFindings.length === 0) {\n output.info(header);\n output.info(\" ✓ all matched\");\n continue;\n }\n output.out(header);\n for (const f of categoryFindings) {\n const icon = f.severity === \"error\" ? \"✗\" : f.severity === \"warn\" ? \"⚠\" : \"ℹ\";\n const detail = f.actual ? ` — ${f.actual}` : \"\";\n const suggestion = f.suggestion ? ` (${f.suggestion})` : \"\";\n output.out(` ${icon} ${f.expected}${detail}${suggestion}`);\n }\n }\n\n const errors = result.findings.filter((f) => f.severity === \"error\").length;\n const warnings = result.findings.filter((f) => f.severity === \"warn\").length;\n const info = result.findings.filter((f) => f.severity === \"info\").length;\n output.info(`\\n ${errors} errors, ${warnings} warnings, ${info} info\\n`);\n }\n\n if (result.findings.some((f) => f.severity === \"error\")) {\n process.exit(1);\n }\n // Distinct exit code so CI cannot mistake \"nothing was checkable\" for a pass\n if (!result.score.assessed) {\n process.exit(3);\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAQ9B,IAAM,UAAU,CAAC,UAAU,QAAQ,QAAQ;AAE3C,IAAO,gBAAQ,cAAc;AAAA,EAC3B,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aACE;AAAA,EACJ;AAAA,EACA,MAAM;AAAA,IACJ,GAAG,WAAW,OAAO;AAAA,IACrB,MAAM,E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
3
+ } from "./chunk-HCJDCS26.js";
4
+
5
+ // src/commands/core/init.ts
6
+ import { defineCommand } from "citty";
7
+ import { mkdir, writeFile } from "fs/promises";
8
+ import { join, basename, resolve } from "path";
9
+ var TEMPLATE_SPECS = {
10
+ lightweight: [
11
+ { filename: "prd.md", type: "prd" },
12
+ { filename: "technical-design.md", type: "technical-design" }
13
+ ],
14
+ bmad: [
15
+ { filename: "prd.md", type: "prd" },
16
+ { filename: "technical-design.md", type: "technical-design" },
17
+ { filename: "test-plan.md", type: "test-plan" }
18
+ ],
19
+ "api-first": [
20
+ { filename: "technical-design.md", type: "technical-design" },
21
+ { filename: "api-contract.md", type: "api-contract" },
22
+ { filename: "test-plan.md", type: "test-plan" }
23
+ ],
24
+ quick: [{ filename: "quick-spec.md", type: "quick-spec" }],
25
+ context: [{ filename: "project-context.md", type: "project-context" }]
26
+ };
27
+ var TEMPLATE_EXTRA_DIRS = {
28
+ lightweight: [],
29
+ bmad: ["specs/stories", "specs/adr"],
30
+ "api-first": [],
31
+ quick: [],
32
+ context: []
33
+ };
34
+ function specIdFromFilename(filename) {
35
+ return filename.replace(/\.md$/, "");
36
+ }
37
+ function specTitleFromType(type) {
38
+ return type.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
39
+ }
40
+ function buildSpecFile(filename, type, projectName, today) {
41
+ const id = specIdFromFilename(filename);
42
+ const title = `${specTitleFromType(type)} \u2014 ${projectName}`;
43
+ const sections = REQUIRED_SECTIONS[type];
44
+ const frontmatter = [
45
+ "---",
46
+ `id: ${id}`,
47
+ `type: ${type}`,
48
+ `title: "${title}"`,
49
+ `status: draft`,
50
+ `version: "0.1"`,
51
+ `created: "${today}"`,
52
+ `authors: ["author"]`,
53
+ "---"
54
+ ].join("\n");
55
+ const body = sections.map((section) => `
56
+ ## ${section}
57
+
58
+ <!-- placeholder -->`).join("\n");
59
+ return `${frontmatter}
60
+ ${body}
61
+ `;
62
+ }
63
+ function buildConfigYaml(projectName, specs) {
64
+ const specEntries = specs.map(({ filename, type }) => {
65
+ const key = specIdFromFilename(filename);
66
+ return ` ${key}:
67
+ path: specs/${filename}
68
+ type: ${type}`;
69
+ }).join("\n");
70
+ return [`version: "1.0"`, `project:`, ` name: "${projectName}"`, `specs:`, specEntries].join("\n") + "\n";
71
+ }
72
+ async function scaffoldProject({
73
+ projectName,
74
+ template,
75
+ targetDir
76
+ }) {
77
+ if (!targetDir) {
78
+ throw new TypeError("scaffoldProject requires `targetDir` \u2014 where to create the project.");
79
+ }
80
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
81
+ const specsDir = join(targetDir, "specs");
82
+ await mkdir(specsDir, { recursive: true });
83
+ for (const extraDir of TEMPLATE_EXTRA_DIRS[template]) {
84
+ await mkdir(join(targetDir, extraDir), { recursive: true });
85
+ }
86
+ const specs = TEMPLATE_SPECS[template];
87
+ for (const { filename, type } of specs) {
88
+ const content = buildSpecFile(filename, type, projectName, today);
89
+ await writeFile(join(specsDir, filename), content, "utf-8");
90
+ }
91
+ const configContent = buildConfigYaml(projectName, specs);
92
+ await writeFile(join(targetDir, "spec.config.yaml"), configContent, "utf-8");
93
+ }
94
+ function defaultProjectName(dir) {
95
+ return basename(resolve(dir)) || "my-project";
96
+ }
97
+ var VALID_TEMPLATES = ["lightweight", "bmad", "api-first", "quick", "context"];
98
+ var init_default = defineCommand({
99
+ meta: {
100
+ name: "init",
101
+ description: "Initialize a new specdx project with spec scaffolding"
102
+ },
103
+ args: {
104
+ name: {
105
+ type: "string",
106
+ description: "Project name (default: the target directory's name)"
107
+ },
108
+ template: {
109
+ type: "string",
110
+ description: `Template to use (${VALID_TEMPLATES.join(", ")})`,
111
+ default: "lightweight"
112
+ },
113
+ dir: {
114
+ type: "string",
115
+ description: "Target directory",
116
+ default: "."
117
+ }
118
+ },
119
+ async run({ args }) {
120
+ const { template, dir } = args;
121
+ if (!VALID_TEMPLATES.includes(template)) {
122
+ console.error(`Unknown template: ${template}. Choose from: ${VALID_TEMPLATES.join(", ")}`);
123
+ process.exit(1);
124
+ }
125
+ const name = args.name || defaultProjectName(dir);
126
+ console.log(`Scaffolding "${name}" with template "${template}" in ${dir}...`);
127
+ await scaffoldProject({ projectName: name, template, targetDir: dir });
128
+ console.log(`Done! Project "${name}" scaffolded successfully.`);
129
+ }
130
+ });
131
+
132
+ // src/commands/registry.ts
133
+ var CORE_COMMANDS = [
134
+ "init",
135
+ "lint",
136
+ "validate",
137
+ "graph",
138
+ "skills",
139
+ "pack",
140
+ "diff",
141
+ "status",
142
+ "ready",
143
+ "generate",
144
+ "generate story",
145
+ "mcp"
146
+ ];
147
+ var EXPERIMENTAL_COMMANDS = ["check", "update", "migrate", "generate test-plan"];
148
+ var COMMAND_NAMES = [...CORE_COMMANDS, ...EXPERIMENTAL_COMMANDS];
149
+ function bucketOf(name) {
150
+ return EXPERIMENTAL_COMMANDS.includes(name) ? "experimental" : "core";
151
+ }
152
+ function labelled(name, cmd) {
153
+ if (bucketOf(name) === "core") return cmd;
154
+ const meta = cmd.meta;
155
+ if (typeof meta !== "object" || meta === null || "then" in meta) return cmd;
156
+ return {
157
+ ...cmd,
158
+ meta: { ...meta, description: `[experimental] ${meta.description ?? ""}`.trim() }
159
+ };
160
+ }
161
+ function bucketed(name, load) {
162
+ return () => load().then((cmd) => labelled(name, cmd));
163
+ }
164
+ var subCommands = {
165
+ init: init_default,
166
+ lint: bucketed("lint", () => import("./lint-2VZPNLE3.js").then((m) => m.default)),
167
+ validate: bucketed("validate", () => import("./validate-EZHUB5TW.js").then((m) => m.default)),
168
+ graph: bucketed("graph", () => import("./graph-4RNURBNP.js").then((m) => m.default)),
169
+ skills: bucketed("skills", () => import("./skills-36SRUEMR.js").then((m) => m.default)),
170
+ pack: bucketed("pack", () => import("./pack-DE4UBTCC.js").then((m) => m.default)),
171
+ diff: bucketed("diff", () => import("./diff-6C5LJ7SH.js").then((m) => m.default)),
172
+ status: bucketed("status", () => import("./status-IAE3BB77.js").then((m) => m.default)),
173
+ check: bucketed("check", () => import("./check-PHXXA7VY.js").then((m) => m.default)),
174
+ ready: bucketed("ready", () => import("./ready-K74SLQ24.js").then((m) => m.default)),
175
+ update: bucketed("update", () => import("./update-UFOHZEAK.js").then((m) => m.default)),
176
+ generate: bucketed("generate", () => import("./generate-K72WD455.js").then((m) => m.default)),
177
+ migrate: bucketed("migrate", () => import("./migrate-FKFC7UAO.js").then((m) => m.default)),
178
+ mcp: bucketed("mcp", () => import("./mcp-E6PJWBDQ.js").then((m) => m.default))
179
+ };
180
+
181
+ export {
182
+ labelled,
183
+ subCommands
184
+ };
185
+ //# sourceMappingURL=chunk-2BZIG7OE.js.map