specdx 0.4.0-alpha.9 → 0.5.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 (115) hide show
  1. package/.claude-plugin/plugin.json +7 -2
  2. package/README.md +283 -0
  3. package/dist/{check-4FSSC6HN.js → check-RH5SCXWW.js} +68 -30
  4. package/dist/check-RH5SCXWW.js.map +1 -0
  5. package/dist/{chunk-N77RNV7J.js → chunk-3YXRWQGX.js} +217 -42
  6. package/dist/chunk-3YXRWQGX.js.map +1 -0
  7. package/dist/chunk-5WRI5ZAA.js +31 -0
  8. package/dist/chunk-6EQIDZ4D.js +185 -0
  9. package/dist/chunk-6EQIDZ4D.js.map +1 -0
  10. package/dist/chunk-6WFNZH7F.js +2846 -0
  11. package/dist/chunk-6WFNZH7F.js.map +1 -0
  12. package/dist/{chunk-AKNPCB37.js → chunk-BMOOLUPG.js} +32 -12
  13. package/dist/chunk-BMOOLUPG.js.map +1 -0
  14. package/dist/{chunk-IHTYAW7C.js → chunk-BP3SB35W.js} +111 -7
  15. package/dist/chunk-BP3SB35W.js.map +1 -0
  16. package/dist/chunk-CQETLJTZ.js +103 -0
  17. package/dist/chunk-CQETLJTZ.js.map +1 -0
  18. package/dist/chunk-DMGABJ6T.js +41 -0
  19. package/dist/chunk-DMGABJ6T.js.map +1 -0
  20. package/dist/chunk-NHD44ZYN.js +20 -0
  21. package/dist/chunk-NHD44ZYN.js.map +1 -0
  22. package/dist/{chunk-7JXW2GTJ.js → chunk-XRWLPU24.js} +18 -2
  23. package/dist/chunk-XRWLPU24.js.map +1 -0
  24. package/dist/chunk-ZIODMXST.js +1146 -0
  25. package/dist/chunk-ZIODMXST.js.map +1 -0
  26. package/dist/diff-QO7HMAK3.js +200 -0
  27. package/dist/diff-QO7HMAK3.js.map +1 -0
  28. package/dist/{dist-4DIRTBJH.js → dist-JPWHWMV2.js} +88 -26
  29. package/dist/dist-JPWHWMV2.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-MS4BM7RU.js +21 -0
  33. package/dist/generate-MS4BM7RU.js.map +1 -0
  34. package/dist/{generate-story-EFHGINHA.js → generate-story-OMM322L7.js} +43 -19
  35. package/dist/generate-story-OMM322L7.js.map +1 -0
  36. package/dist/{generate-test-plan-BO7444RG.js → generate-test-plan-75W7SZIO.js} +61 -11
  37. package/dist/generate-test-plan-75W7SZIO.js.map +1 -0
  38. package/dist/{graph-5XINV7PT.js → graph-QOTMXENE.js} +49 -11
  39. package/dist/graph-QOTMXENE.js.map +1 -0
  40. package/dist/index.d.ts +302 -0
  41. package/dist/index.js +2996 -357
  42. package/dist/index.js.map +1 -1
  43. package/dist/lint-LPFLHVO4.js +184 -0
  44. package/dist/lint-LPFLHVO4.js.map +1 -0
  45. package/dist/main.js +10 -229
  46. package/dist/main.js.map +1 -1
  47. package/dist/mcp-OEC43SPF.js +35 -0
  48. package/dist/mcp-OEC43SPF.js.map +1 -0
  49. package/dist/{migrate-4KF6GHLO.js → migrate-CBP2AVLH.js} +21 -9
  50. package/dist/migrate-CBP2AVLH.js.map +1 -0
  51. package/dist/{pack-DSOODXAN.js → pack-X6FSWORJ.js} +41 -13
  52. package/dist/pack-X6FSWORJ.js.map +1 -0
  53. package/dist/{ready-6DNKIHP6.js → ready-7MJWRGLT.js} +55 -14
  54. package/dist/ready-7MJWRGLT.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-UUPZYX3J.js} +63 -32
  70. package/dist/status-UUPZYX3J.js.map +1 -0
  71. package/dist/{update-JTNSYX3B.js → update-EI7IJRHG.js} +22 -12
  72. package/dist/update-EI7IJRHG.js.map +1 -0
  73. package/dist/{validate-LBDYWUDX.js → validate-HTTZLQWI.js} +36 -17
  74. package/dist/validate-HTTZLQWI.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 +0 -122
  102. package/dist/lint-PTMWMLDQ.js.map +0 -1
  103. package/dist/mcp-BGFAPM6G.js +0 -17
  104. package/dist/mcp-BGFAPM6G.js.map +0 -1
  105. package/dist/migrate-4KF6GHLO.js.map +0 -1
  106. package/dist/pack-DSOODXAN.js.map +0 -1
  107. package/dist/ready-6DNKIHP6.js.map +0 -1
  108. package/dist/skills-3GBBWZW2.js +0 -93
  109. package/dist/skills-3GBBWZW2.js.map +0 -1
  110. package/dist/status-WZK247CI.js.map +0 -1
  111. package/dist/update-JTNSYX3B.js.map +0 -1
  112. package/dist/validate-LBDYWUDX.js.map +0 -1
  113. /package/dist/{dist-RL2DT3ZE.js.map → chunk-5WRI5ZAA.js.map} +0 -0
  114. /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
  115. /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.5.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,283 @@
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
+ ### Linting AGENTS.md and CLAUDE.md
97
+
98
+ specdx also lints the instruction files you already have. Add the `agents` key
99
+ to `spec.config.yaml`:
100
+
101
+ ```yaml
102
+ agents:
103
+ paths: ["AGENTS.md", "CLAUDE.md"]
104
+ max_tokens: 8000
105
+ ```
106
+
107
+ It checks that the file is organised under headings, that every path it names
108
+ still exists, and that it fits a token budget. The middle one is the one that
109
+ earns its keep — a `CLAUDE.md` pointing at a file that moved sends every agent
110
+ session to the wrong place, confidently.
111
+
112
+ These files are not specs. They stay out of the dependency graph, out of
113
+ `pack`, and out of `diff`. Adding the `agents` key is what switches this on, and
114
+ the spec presets never promote its findings.
115
+
116
+ This currently runs as part of `specdx lint`, so it needs a `spec.config.yaml`
117
+ to hang off. Linting an `AGENTS.md` in a project with no spec suite at all is
118
+ not supported yet.
119
+
120
+ **→ [Full configuration reference](docs/configuration.md)** — lint rule
121
+ overrides, custom rules, pack budgets, staleness thresholds, `check` paths.
122
+
123
+ ## Spec format
124
+
125
+ Markdown with YAML frontmatter. Nine types, each with required sections.
126
+
127
+ ```markdown
128
+ ---
129
+ id: "prd-001"
130
+ type: "prd"
131
+ title: "User authentication"
132
+ status: "approved"
133
+ version: "1.0"
134
+ created: "2026-03-01"
135
+ authors: ["alice"]
136
+ ---
137
+
138
+ ## Problem Statement
139
+
140
+ The application has no authentication, so every endpoint is public.
141
+ ```
142
+
143
+ `created` must be quoted, or YAML turns it into a date object.
144
+
145
+ **→ [Spec format reference](docs/spec-format.md)** — all nine types and their
146
+ required sections, cross-references, declared artifacts, and the three sections
147
+ `check` parses.
148
+
149
+ ## Editor and agent integration
150
+
151
+ ### Claude Code
152
+
153
+ specdx ships as a plugin with **ten skills**. Install it as a dev dependency and
154
+ the plugin is discovered automatically:
155
+
156
+ ```bash
157
+ npm install -D specdx
158
+ ```
159
+
160
+ Or write the skill files into `.claude/skills/` yourself:
161
+
162
+ ```bash
163
+ npx specdx skills install # the eight promoted skills
164
+ npx specdx skills install --experimental # also the two check-based ones
165
+ ```
166
+
167
+ | Skill | What it does |
168
+ |-------|-------------|
169
+ | `specdx-router` | Maps every skill and when to reach for it. Start here. |
170
+ | `specdx-start-task` | Loads spec context before coding |
171
+ | `specdx-author-spec` | Guides spec writing, linting between sections |
172
+ | `specdx-plan-from-spec` | Turns specs into an implementation plan |
173
+ | `specdx-review-spec` | Multi-layer quality review of a new spec |
174
+ | `specdx-pre-commit` | Catches drift before it enters git history |
175
+ | `specdx-onboard` | Guided tour of an unfamiliar spec suite |
176
+ | `specdx-sprint-review` | Shareable spec health summary |
177
+ | `specdx-verify` | *(experimental)* Checks implementation against specs |
178
+ | `specdx-check-drift` | *(experimental)* Cross-references code changes vs specs |
179
+
180
+ ### MCP
181
+
182
+ Every tool is exposed over the Model Context Protocol:
183
+
184
+ ```bash
185
+ specdx mcp
186
+ ```
187
+
188
+ Seven tools: `sdx_validate`, `sdx_lint`, `sdx_pack`, `sdx_status`, `sdx_check`,
189
+ `sdx_diff`, `sdx_graph`.
190
+
191
+ **→ [Cursor and Gemini CLI setup](docs/other-platforms.md)**
192
+
193
+ ## CI
194
+
195
+ ```yaml
196
+ permissions:
197
+ contents: read
198
+ pull-requests: write
199
+
200
+ steps:
201
+ - uses: actions/checkout@v4
202
+ with: { fetch-depth: 0 }
203
+ - uses: umxr/specdx/packages/github-action@v0
204
+ with:
205
+ preset: recommended
206
+ github-token: ${{ secrets.GITHUB_TOKEN }}
207
+ ```
208
+
209
+ The action lints and diffs every pull request, posts a health comment it updates
210
+ in place, and fails the job when spec paths resolve to no files — zero specs
211
+ checked is not a pass.
212
+
213
+ Any CI can run the CLI directly instead: `specdx lint --format github` emits
214
+ inline annotations and exits non-zero on failure.
215
+
216
+ **→ [CI reference](docs/ci.md)**
217
+
218
+ ## CLI
219
+
220
+ | Command | Description |
221
+ |---------|-------------|
222
+ | `specdx init` | Scaffold a spec suite (`--template lightweight\|bmad\|api-first\|quick\|context`) |
223
+ | `specdx lint [path]` | Lint the suite, or just `path` (`--preset`, `--fix`) |
224
+ | `specdx validate` | Validate `spec.config.yaml` |
225
+ | `specdx pack --task <task>` | Pack specs into token-budgeted context (`--copy`, `--full`) |
226
+ | `specdx status` | Spec suite health overview |
227
+ | `specdx diff` | Spec changes and downstream impact (`--working`, `--base`, `--head`) |
228
+ | `specdx graph` | Print the dependency graph |
229
+ | `specdx ready` | Is the suite fit to implement from? |
230
+ | `specdx generate story --from <id>` | Generate story stubs from a PRD |
231
+ | `specdx skills install` | Install Claude Code skills |
232
+ | `specdx mcp` | Start the MCP server |
233
+ | `specdx check` | *(experimental)* Spec-to-implementation drift |
234
+ | `specdx update` | *(experimental)* Suggest spec updates from drift |
235
+ | `specdx generate test-plan` | *(experimental)* Test plan stub from stories |
236
+ | `specdx migrate` | *(experimental)* Migrate spec suite schema |
237
+
238
+ `--quiet` and `--verbose` are available on the reporting commands — run
239
+ `specdx <command> --help` for what each one takes.
240
+
241
+ `--format` is per command, because not every command renders every format.
242
+ Asking for one a command does not render is an error, not a silent fallback.
243
+
244
+ | Formats | Commands |
245
+ |---|---|
246
+ | `pretty`, `json`, `github` | `lint`, `status`, `check` |
247
+ | `pretty`, `json` | `validate`, `ready`, `update` |
248
+ | `pretty`, `json`, `dot` | `graph` |
249
+ | `pretty`, `json`, `changelog` | `diff` |
250
+ | `xml`, `markdown`, `json` | `pack` |
251
+
252
+ ## Experimental
253
+
254
+ These ship with specdx but sit outside the stable surface — they lean on static
255
+ code analysis, which is inherently fuzzy, so their output and interfaces may
256
+ change. They are flagged `[experimental]` in `--help`.
257
+
258
+ `specdx check` extracts routes (Express, Hono, Next.js), types (TypeScript, Zod,
259
+ Prisma) and tests from your code and compares them against your specs. Where no
260
+ framework extractor applies — static sites, CLIs, libraries — a spec can declare
261
+ [artifacts](docs/spec-format.md#declared-artifacts) instead: files that must
262
+ exist and names they must export.
263
+
264
+ Accuracy feedback is what graduates these to stable.
265
+
266
+ ## How it compares
267
+
268
+ **Markdown linters** (markdownlint, remark-lint) check formatting. specdx checks
269
+ semantics: required sections by spec type, cross-reference validity, dependency
270
+ cycles, downstream staleness.
271
+
272
+ **JSON Schema validators** check structure. specdx adds document-level rules
273
+ that understand how specs relate to each other — and a packer that turns the
274
+ suite into context an LLM can actually use.
275
+
276
+ ## Contributing
277
+
278
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, writing custom
279
+ lint rules, and the PR process.
280
+
281
+ ## License
282
+
283
+ 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-BP3SB35W.js";
17
+ import "./chunk-XRWLPU24.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-RH5SCXWW.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,EAAE,MAAM,UAAU,aAAa,8BAA8B;AAAA,IACnE,WAAW,EAAE,MAAM,UAAU,aAAa,4CAA4C;AAAA,IACtF,IAAI;AAAA,MACF,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,MAAM,IAAI,EAAE,KAAK,GAAG;AAClB,UAAM,SAAS,cAAc,KAAK,QAAQ,OAAO;AACjD,QAAI,CAAC,OAAO,IAAI;AACd,cAAQ,MAAM;AAAA,WAAS,OAAO,OAAO;AAAA,CAAI;AACzC,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,UAAM,SAAS,aAAa,EAAE,OAAO,KAAK,OAAO,SAAS,KAAK,QAAQ,CAAC;AACxE,UAAM,SAAS,aAAa,EAAE,OAAO,KAAK,MAAM,CAAC;AACjD,UAAM,YAAY,QAAQ,IAAI;AAC9B,UAAM,SAAS,MAAM,WAAW,QAAW,SAAS;AAEpD,WAAO,MAAM,kBAAkB;AAG/B,UAAM,QAAsB,CAAC;AAC7B,eAAW,CAAC,EAAE,KAAK,KAAK,OAAO,QAAQ,OAAO,KAAK,GAAG;AACpD,YAAM,QAA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