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
@@ -0,0 +1,835 @@
1
+ import {
2
+ buildRelationResolver,
3
+ resolveGlob
4
+ } from "./chunk-SNQNQ2MP.js";
5
+ import {
6
+ REQUIRED_SECTIONS
7
+ } from "./chunk-HCJDCS26.js";
8
+
9
+ // ../lint/dist/engine.js
10
+ function createLintEngine(options) {
11
+ return {
12
+ lint(specs) {
13
+ const diagnostics = [];
14
+ const ignored = new Set(options.ignore ?? []);
15
+ for (const spec of specs) {
16
+ if (ignored.has(spec.filePath))
17
+ continue;
18
+ for (const rule of options.rules) {
19
+ const results = rule.run({
20
+ spec,
21
+ allSpecs: specs,
22
+ config: options.config,
23
+ graph: options.graph
24
+ });
25
+ for (const diagnostic of results) {
26
+ if (ignored.has(diagnostic.filePath))
27
+ continue;
28
+ diagnostics.push({ ...diagnostic, severity: rule.severity });
29
+ }
30
+ }
31
+ }
32
+ return {
33
+ diagnostics,
34
+ hasErrors: diagnostics.some((d) => d.severity === "error"),
35
+ hasWarnings: diagnostics.some((d) => d.severity === "warn")
36
+ };
37
+ }
38
+ };
39
+ }
40
+
41
+ // ../lint/dist/rules/story-coverage.js
42
+ var STOPWORDS = /* @__PURE__ */ new Set([
43
+ "a",
44
+ "an",
45
+ "the",
46
+ "and",
47
+ "or",
48
+ "of",
49
+ "to",
50
+ "for",
51
+ "with",
52
+ "its",
53
+ "it",
54
+ "in",
55
+ "on",
56
+ "at",
57
+ "by",
58
+ "from",
59
+ "into",
60
+ "every",
61
+ "each",
62
+ "that",
63
+ "this",
64
+ "be",
65
+ "is",
66
+ "are",
67
+ "as",
68
+ "can",
69
+ "will",
70
+ "must",
71
+ "so",
72
+ "their",
73
+ "them",
74
+ "when",
75
+ "which",
76
+ "who"
77
+ ]);
78
+ var OVERLAP_THRESHOLD = 0.5;
79
+ var REFERENCED_THRESHOLD = 0.34;
80
+ function tokenise(text) {
81
+ const words = text.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length > 2 && !STOPWORDS.has(w)).map((w) => w.length > 3 && w.endsWith("s") && !w.endsWith("ss") ? w.slice(0, -1) : w);
82
+ return new Set(words);
83
+ }
84
+ function extractFeatureSection(content) {
85
+ const lines = content.split("\n");
86
+ const start = lines.findIndex((l) => /^##\s+Features\s*$/.test(l.trim()));
87
+ if (start === -1)
88
+ return null;
89
+ const body = [];
90
+ for (let i = start + 1; i < lines.length; i++) {
91
+ if (/^##\s/.test(lines[i]))
92
+ break;
93
+ body.push(lines[i]);
94
+ }
95
+ return body.join("\n");
96
+ }
97
+ function parseFeatures(content) {
98
+ return parseFeatureEntries(content).map((f) => f.text);
99
+ }
100
+ function parseFeatureEntries(content) {
101
+ const section = extractFeatureSection(content);
102
+ if (section === null)
103
+ return [];
104
+ const ID_PREFIX = /^\*{0,2}F(\d+)\*{0,2}\s*[:.-]\s*/i;
105
+ const features = [];
106
+ for (const rawLine of section.split("\n")) {
107
+ const line = rawLine.trim();
108
+ if (!line)
109
+ continue;
110
+ const bullet = /^[-*]\s+(.*)$/.exec(line);
111
+ const text = bullet ? (bullet[1] ?? "").trim() : ID_PREFIX.test(line) ? line : "";
112
+ if (!text)
113
+ continue;
114
+ const idMatch = ID_PREFIX.exec(text);
115
+ const stripped = text.replace(ID_PREFIX, "").trim();
116
+ if (stripped)
117
+ features.push({ text: stripped, num: idMatch?.[1] });
118
+ }
119
+ return features;
120
+ }
121
+ function overlap(featureTokens, storyTokens) {
122
+ if (featureTokens.size === 0)
123
+ return 0;
124
+ let shared = 0;
125
+ for (const token of featureTokens)
126
+ if (storyTokens.has(token))
127
+ shared++;
128
+ return shared / featureTokens.size;
129
+ }
130
+ function referencesSpec(story, specId) {
131
+ const refs = story.frontmatter.references;
132
+ if (!Array.isArray(refs))
133
+ return false;
134
+ return refs.some((r) => r?.id === specId);
135
+ }
136
+ function uncoveredFeatures(features, stories, prdId) {
137
+ const scored = stories.map((story) => ({
138
+ tokens: tokenise(`${String(story.frontmatter.title ?? "")} ${story.content}`),
139
+ threshold: referencesSpec(story, prdId) ? REFERENCED_THRESHOLD : OVERLAP_THRESHOLD
140
+ }));
141
+ const tokenised = features.map(tokenise);
142
+ return features.filter((_feature, i) => {
143
+ const featureTokens = tokenised[i];
144
+ const distinctive = distinctiveTokens(featureTokens, tokenised, i);
145
+ return !scored.some((s) => overlap(featureTokens, s.tokens) >= s.threshold && covers(distinctive, featureTokens, s.tokens));
146
+ });
147
+ }
148
+ function covers(distinctive, featureTokens, storyTokens) {
149
+ if (distinctive.size === 0 || distinctive.size === featureTokens.size)
150
+ return true;
151
+ let matched = 0;
152
+ for (const token of distinctive)
153
+ if (storyTokens.has(token))
154
+ matched++;
155
+ return matched > distinctive.size / 2;
156
+ }
157
+ function distinctiveTokens(featureTokens, allFeatureTokens, index) {
158
+ const distinctive = new Set(featureTokens);
159
+ for (let i = 0; i < allFeatureTokens.length; i++) {
160
+ if (i === index)
161
+ continue;
162
+ for (const token of allFeatureTokens[i])
163
+ distinctive.delete(token);
164
+ }
165
+ return distinctive;
166
+ }
167
+ var storyCoverageRule = {
168
+ id: "completeness/story-coverage",
169
+ description: "Every feature listed in a PRD has at least one corresponding user story",
170
+ severity: "warn",
171
+ run(context) {
172
+ if (context.spec.frontmatter.type !== "prd")
173
+ return [];
174
+ const features = parseFeatures(context.spec.content);
175
+ if (features.length === 0)
176
+ return [];
177
+ const stories = context.allSpecs.filter((s) => s.frontmatter.type === "user-story");
178
+ return uncoveredFeatures(features, stories, context.spec.frontmatter.id).map((feature) => ({
179
+ ruleId: "completeness/story-coverage",
180
+ severity: "warn",
181
+ message: `Feature "${feature}" has no corresponding user story`,
182
+ filePath: context.spec.filePath
183
+ }));
184
+ }
185
+ };
186
+
187
+ // ../lint/dist/resolve-lint-config.js
188
+ import { isAbsolute, resolve } from "path";
189
+
190
+ // ../lint/dist/rules/valid-frontmatter.js
191
+ function readablePath(instancePath) {
192
+ return instancePath.split("/").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? `[${segment}]` : `.${segment}`).join("").replace(/^\./, "");
193
+ }
194
+ function describeValidationError(err) {
195
+ const path = readablePath(err.instancePath ?? "");
196
+ const allowed = err.params?.allowedValues;
197
+ let detail = err.message ?? JSON.stringify(err);
198
+ if (Array.isArray(allowed) && allowed.length > 0) {
199
+ detail += `: ${allowed.map((v) => JSON.stringify(v)).join(", ")}`;
200
+ }
201
+ return path ? `${path} ${detail}` : detail;
202
+ }
203
+ var validFrontmatterRule = {
204
+ id: "structure/valid-frontmatter",
205
+ description: "Frontmatter matches the schema for the declared spec type",
206
+ severity: "error",
207
+ run(context) {
208
+ if (context.spec.valid)
209
+ return [];
210
+ const errors = context.spec.validationErrors ?? [];
211
+ return errors.map((err) => ({
212
+ ruleId: "structure/valid-frontmatter",
213
+ severity: "error",
214
+ message: `Invalid frontmatter: ${describeValidationError(err)}`,
215
+ filePath: context.spec.filePath
216
+ }));
217
+ }
218
+ };
219
+
220
+ // ../lint/dist/rules/required-sections.js
221
+ var requiredSectionsRule = {
222
+ id: "structure/required-sections",
223
+ description: "Spec body contains all required sections for its type",
224
+ severity: "error",
225
+ run(context) {
226
+ const ext = context.spec.filePath.split(".").pop()?.toLowerCase();
227
+ if (ext === "yaml" || ext === "yml")
228
+ return [];
229
+ const specType = context.spec.frontmatter.type;
230
+ const required = REQUIRED_SECTIONS[specType];
231
+ if (!required)
232
+ return [];
233
+ const missing = required.filter((s) => !context.spec.sections.includes(s));
234
+ return missing.map((section) => ({
235
+ ruleId: "structure/required-sections",
236
+ severity: "error",
237
+ message: `Missing required section: "${section}"`,
238
+ filePath: context.spec.filePath,
239
+ section
240
+ }));
241
+ }
242
+ };
243
+
244
+ // ../lint/dist/rules/valid-references.js
245
+ var validReferencesRule = {
246
+ id: "structure/valid-references",
247
+ description: "All references in frontmatter point to specs that exist in the suite",
248
+ severity: "error",
249
+ run(context) {
250
+ const refs = context.spec.frontmatter.references;
251
+ if (!refs || refs.length === 0)
252
+ return [];
253
+ const allIds = new Set(context.allSpecs.map((s) => s.frontmatter.id));
254
+ return refs.filter((ref) => !allIds.has(ref.id)).map((ref) => ({
255
+ ruleId: "structure/valid-references",
256
+ severity: "error",
257
+ message: `Reference "${ref.id}" does not match any spec in the suite`,
258
+ filePath: context.spec.filePath
259
+ }));
260
+ }
261
+ };
262
+
263
+ // ../lint/dist/rules/no-circular-deps.js
264
+ var noCircularDepsRule = {
265
+ id: "structure/no-circular-deps",
266
+ description: "The dependency graph has no cycles",
267
+ severity: "error",
268
+ run() {
269
+ return [];
270
+ }
271
+ };
272
+
273
+ // ../lint/dist/rules/staleness-check.js
274
+ function groupByEntry(config, specs) {
275
+ const byEntry = /* @__PURE__ */ new Map();
276
+ for (const key of Object.keys(config.specs))
277
+ byEntry.set(key, []);
278
+ for (const spec of specs) {
279
+ let bestKey;
280
+ let bestLen = -1;
281
+ for (const [key, entry] of Object.entries(config.specs)) {
282
+ const prefix = entry.path.split("*")[0] ?? "";
283
+ const normalized = spec.filePath.replace(/\\/g, "/");
284
+ if (normalized.includes(prefix) && prefix.length > bestLen) {
285
+ bestKey = key;
286
+ bestLen = prefix.length;
287
+ }
288
+ }
289
+ if (bestKey)
290
+ byEntry.get(bestKey).push(spec);
291
+ }
292
+ return byEntry;
293
+ }
294
+ function lastUpdated(spec) {
295
+ return spec.frontmatter.updated ?? spec.frontmatter.created ?? "";
296
+ }
297
+ var stalenessCheckRule = {
298
+ id: "freshness/staleness-check",
299
+ description: "Warns if a spec hasn't been updated since its upstream dependency changed",
300
+ severity: "warn",
301
+ run(context) {
302
+ const specId = context.spec.frontmatter.id;
303
+ if (typeof specId !== "string")
304
+ return [];
305
+ const specUpdated = lastUpdated(context.spec);
306
+ if (!specUpdated)
307
+ return [];
308
+ const specDate = new Date(specUpdated);
309
+ const byEntry = context.config ? groupByEntry(context.config, context.allSpecs) : /* @__PURE__ */ new Map([["", context.allSpecs]]);
310
+ const relations = buildRelationResolver(context.config, byEntry);
311
+ const upstreamIds = relations.getUpstream(specId);
312
+ const diagnostics = [];
313
+ for (const upstreamId of upstreamIds) {
314
+ const upstream = context.allSpecs.find((s) => s.frontmatter.id === upstreamId);
315
+ if (!upstream)
316
+ continue;
317
+ const upstreamUpdated = lastUpdated(upstream);
318
+ if (!upstreamUpdated)
319
+ continue;
320
+ if (new Date(upstreamUpdated) > specDate) {
321
+ diagnostics.push({
322
+ ruleId: "freshness/staleness-check",
323
+ severity: "warn",
324
+ message: `Potentially stale: upstream "${upstreamId}" was updated on ${upstreamUpdated}, but this spec was last updated on ${specUpdated}`,
325
+ filePath: context.spec.filePath
326
+ });
327
+ }
328
+ }
329
+ return diagnostics;
330
+ }
331
+ };
332
+
333
+ // ../lint/dist/rules/no-vague-language.js
334
+ var DEFAULT_VAGUE_PATTERNS = [
335
+ "as appropriate",
336
+ "handle edge cases",
337
+ "as needed",
338
+ "etc\\.",
339
+ "TBD",
340
+ "TODO",
341
+ "and so on",
342
+ "various",
343
+ "somehow",
344
+ "straightforward",
345
+ "obviously",
346
+ "simply",
347
+ "just need to"
348
+ ];
349
+ var noVagueLanguageRule = {
350
+ id: "clarity/no-vague-language",
351
+ description: "Flags known ambiguous phrases",
352
+ severity: "warn",
353
+ run(context) {
354
+ if (!context.spec.content)
355
+ return [];
356
+ const diagnostics = [];
357
+ for (const pattern of DEFAULT_VAGUE_PATTERNS) {
358
+ const regex = new RegExp(`\\b${pattern}`, "gi");
359
+ let match;
360
+ while ((match = regex.exec(context.spec.content)) !== null) {
361
+ diagnostics.push({
362
+ ruleId: "clarity/no-vague-language",
363
+ severity: "warn",
364
+ message: `Vague language: "${match[0]}"`,
365
+ filePath: context.spec.filePath
366
+ });
367
+ }
368
+ }
369
+ return diagnostics;
370
+ }
371
+ };
372
+
373
+ // ../lint/dist/rules/single-project-context.js
374
+ var singleProjectContextRule = {
375
+ id: "structure/single-project-context",
376
+ description: "Only one project-context spec should exist per suite",
377
+ severity: "warn",
378
+ run(context) {
379
+ if (context.spec.frontmatter.type !== "project-context")
380
+ return [];
381
+ const contextSpecs = context.allSpecs.filter((s) => s.frontmatter.type === "project-context");
382
+ if (contextSpecs.length > 1) {
383
+ return [
384
+ {
385
+ ruleId: "structure/single-project-context",
386
+ severity: "warn",
387
+ message: `Multiple project-context specs found (${contextSpecs.length}). Only one should exist per suite.`,
388
+ filePath: context.spec.filePath
389
+ }
390
+ ];
391
+ }
392
+ return [];
393
+ }
394
+ };
395
+
396
+ // ../lint/dist/rules/terminology.js
397
+ function normalizeCompound(term) {
398
+ return term.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").toLowerCase().trim();
399
+ }
400
+ function extractCompoundTerms(content) {
401
+ const terms = [];
402
+ const camelCaseRegex = /\b[a-zA-Z]*[a-z][A-Z][a-zA-Z]*\b/g;
403
+ let match;
404
+ while ((match = camelCaseRegex.exec(content)) !== null) {
405
+ terms.push(match[0]);
406
+ }
407
+ const hyphenatedRegex = /\b[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)+\b/g;
408
+ while ((match = hyphenatedRegex.exec(content)) !== null) {
409
+ terms.push(match[0]);
410
+ }
411
+ return terms;
412
+ }
413
+ var terminologyRule = {
414
+ id: "consistency/terminology",
415
+ description: "Detects terminology drift (e.g., user-profile vs UserProfile vs user profile) across specs",
416
+ severity: "warn",
417
+ run(context) {
418
+ if (context.spec !== context.allSpecs[0])
419
+ return [];
420
+ const termMap = /* @__PURE__ */ new Map();
421
+ for (const spec of context.allSpecs) {
422
+ if (!spec.content)
423
+ continue;
424
+ const terms = extractCompoundTerms(spec.content);
425
+ for (const term of terms) {
426
+ const normalized = normalizeCompound(term);
427
+ if (!normalized.includes(" "))
428
+ continue;
429
+ if (!termMap.has(normalized)) {
430
+ termMap.set(normalized, /* @__PURE__ */ new Set());
431
+ }
432
+ termMap.get(normalized).add(term);
433
+ }
434
+ }
435
+ const diagnostics = [];
436
+ for (const [normalized, variants] of termMap) {
437
+ if (variants.size >= 2) {
438
+ const variantList = [...variants].join(", ");
439
+ diagnostics.push({
440
+ ruleId: "consistency/terminology",
441
+ severity: "warn",
442
+ message: `Inconsistent terminology for "${normalized}": found variants [${variantList}]. Standardize terminology across specs.`,
443
+ filePath: context.spec.filePath
444
+ });
445
+ }
446
+ }
447
+ return diagnostics;
448
+ }
449
+ };
450
+
451
+ // ../lint/dist/rules/edge-case-coverage.js
452
+ var EDGE_CASE_KEYWORDS = [
453
+ "error",
454
+ "invalid",
455
+ "empty",
456
+ "timeout",
457
+ "fails",
458
+ "failure",
459
+ "boundary",
460
+ "edge case",
461
+ "null",
462
+ "undefined",
463
+ "reject",
464
+ "unauthorized",
465
+ "forbidden",
466
+ "missing",
467
+ "malformed",
468
+ "overflow",
469
+ "duplicate",
470
+ "graceful",
471
+ "fall back",
472
+ "fallback",
473
+ "crash",
474
+ "nonexistent",
475
+ "corrupt",
476
+ // Vocabulary that names a failure without using any of the words above.
477
+ "conflict",
478
+ "denied",
479
+ "expired",
480
+ "not found",
481
+ "retry",
482
+ "rate limit",
483
+ "unavailable",
484
+ "unprocessable"
485
+ ];
486
+ var ERROR_STATUS_CODE = /\b[45]\d{2}\b/;
487
+ var EDGE_CASE_SECTION = "edge cases";
488
+ var PLACEHOLDER_BODIES = /^(todo|tbd|fixme|n\/a|na|none|xxx|\.{2,}|-|\*)$/i;
489
+ var DISCLAIMED_BODIES = /^(none|no|nothing|n\/a)\b[\s\S]{0,40}$/i;
490
+ function meaningfulContent(content) {
491
+ return content.replace(/<!--[\s\S]*?-->/g, "").split("\n").map((line) => line.replace(/^\s*[-*+]\s+/, "").trim()).filter((line) => line.length > 0 && !/^-{3,}$/.test(line)).join("\n").trim();
492
+ }
493
+ var edgeCaseCoverageRule = {
494
+ id: "completeness/edge-case-coverage",
495
+ description: "Flag user stories or test plans that don't mention error states or edge cases",
496
+ severity: "warn",
497
+ run(context) {
498
+ const type = context.spec.frontmatter.type;
499
+ if (type !== "user-story" && type !== "test-plan")
500
+ return [];
501
+ const section = context.spec.parsedSections.find((s) => s.heading.trim().toLowerCase() === EDGE_CASE_SECTION);
502
+ if (type === "test-plan" && section) {
503
+ const body = meaningfulContent(section.content);
504
+ const written = body !== "" && !PLACEHOLDER_BODIES.test(body) && !DISCLAIMED_BODIES.test(body);
505
+ if (written)
506
+ return [];
507
+ return [
508
+ {
509
+ ruleId: "completeness/edge-case-coverage",
510
+ severity: "warn",
511
+ message: `The "${section.heading}" section lists no cases \u2014 describe the boundary conditions and failure modes this plan covers, or the plan asserts only the happy path.`,
512
+ filePath: context.spec.filePath,
513
+ section: section.heading
514
+ }
515
+ ];
516
+ }
517
+ const content = context.spec.content.toLowerCase();
518
+ const hasEdgeCases = EDGE_CASE_KEYWORDS.some((kw) => content.includes(kw)) || ERROR_STATUS_CODE.test(content);
519
+ if (hasEdgeCases)
520
+ return [];
521
+ return [
522
+ {
523
+ ruleId: "completeness/edge-case-coverage",
524
+ severity: "warn",
525
+ message: "No error states or edge cases mentioned. Consider adding error handling, boundary conditions, or failure mode scenarios.",
526
+ filePath: context.spec.filePath
527
+ }
528
+ ];
529
+ }
530
+ };
531
+
532
+ // ../lint/dist/rules/naming-conventions.js
533
+ var namingConventionsRule = {
534
+ id: "consistency/naming-conventions",
535
+ description: "Enforce consistent naming conventions across specs",
536
+ severity: "warn",
537
+ run(context) {
538
+ const { spec } = context;
539
+ const type = spec.frontmatter.type;
540
+ const diagnostics = [];
541
+ if (type === "prd") {
542
+ const sectionParts = spec.content.split(/^(?=## )/m);
543
+ const featuresSection = sectionParts.find((p) => /^## Features\b/.test(p));
544
+ if (featuresSection) {
545
+ const bullets = featuresSection.match(/^- .+$/gm) ?? [];
546
+ for (const bullet of bullets) {
547
+ if (bullet.match(/^- \*\*F\d+\*\*:/) === null && bullet.trim().length > 2) {
548
+ diagnostics.push({
549
+ ruleId: "consistency/naming-conventions",
550
+ severity: "warn",
551
+ message: `PRD feature missing feature ID pattern (**F<N>**:): "${bullet.slice(0, 60)}"`,
552
+ filePath: spec.filePath
553
+ });
554
+ }
555
+ }
556
+ }
557
+ }
558
+ if (type === "user-story") {
559
+ const id = spec.frontmatter.id;
560
+ if (!id.startsWith("story-")) {
561
+ diagnostics.push({
562
+ ruleId: "consistency/naming-conventions",
563
+ severity: "warn",
564
+ message: `User story ID "${id}" should start with "story-" (e.g., "story-${id}")`,
565
+ filePath: spec.filePath
566
+ });
567
+ }
568
+ }
569
+ if (type === "api-contract") {
570
+ const endpointRe = /^###\s+(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/gm;
571
+ let match;
572
+ while ((match = endpointRe.exec(spec.content)) !== null) {
573
+ const path = match[2];
574
+ if (/\/[a-z]+[A-Z]/.test(path)) {
575
+ diagnostics.push({
576
+ ruleId: "consistency/naming-conventions",
577
+ severity: "warn",
578
+ message: `Endpoint path "${path}" uses camelCase \u2014 use kebab-case instead (e.g., "${path.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}")`,
579
+ filePath: spec.filePath
580
+ });
581
+ }
582
+ }
583
+ }
584
+ return diagnostics;
585
+ }
586
+ };
587
+
588
+ // ../lint/dist/rules/threat-coverage.js
589
+ var STOPWORDS2 = /* @__PURE__ */ new Set(["the", "and", "for", "with", "from", "that", "this", "into", "via"]);
590
+ function extractThreats(content) {
591
+ const parts = content.split(/^(?=## )/m);
592
+ const threats = [];
593
+ for (const part of parts) {
594
+ if (!/^##\s+(Threats|Security)\b/i.test(part))
595
+ continue;
596
+ const bullets = part.match(/^- .+$/gm) ?? [];
597
+ threats.push(...bullets.map((b) => b.slice(2).trim()));
598
+ }
599
+ return threats;
600
+ }
601
+ function extractKeyTerms(text) {
602
+ return text.toLowerCase().split(/\W+/).filter((w) => w.length > 3).filter((w) => !STOPWORDS2.has(w));
603
+ }
604
+ var threatCoverageRule = {
605
+ id: "security/threat-coverage",
606
+ description: "Technical design specs must address threats identified in other specs",
607
+ severity: "warn",
608
+ run(context) {
609
+ if (context.spec.frontmatter.type !== "technical-design")
610
+ return [];
611
+ const allThreats = [];
612
+ for (const spec of context.allSpecs) {
613
+ if (spec.filePath === context.spec.filePath)
614
+ continue;
615
+ allThreats.push(...extractThreats(spec.content));
616
+ }
617
+ if (allThreats.length === 0)
618
+ return [];
619
+ const techContent = context.spec.content.toLowerCase();
620
+ const diagnostics = [];
621
+ for (const threat of allThreats) {
622
+ const keyTerms = extractKeyTerms(threat);
623
+ const covered = keyTerms.some((term) => techContent.includes(term));
624
+ if (!covered) {
625
+ diagnostics.push({
626
+ ruleId: "security/threat-coverage",
627
+ severity: "warn",
628
+ message: `Threat not addressed in technical design: "${threat}". Ensure the design covers this threat.`,
629
+ filePath: context.spec.filePath
630
+ });
631
+ }
632
+ }
633
+ return diagnostics;
634
+ }
635
+ };
636
+
637
+ // ../lint/dist/rules/ambiguity-score-ai.js
638
+ var ambiguityScoreAiRule = {
639
+ id: "clarity/ambiguity-score-ai",
640
+ description: "AI-powered ambiguity detection (requires ANTHROPIC_API_KEY)",
641
+ severity: "info",
642
+ run(context) {
643
+ if (!process.env["ANTHROPIC_API_KEY"])
644
+ return [];
645
+ return [
646
+ {
647
+ ruleId: "clarity/ambiguity-score-ai",
648
+ severity: "info",
649
+ message: "AI ambiguity analysis available \u2014 run `specdx check --ai` for LLM-powered ambiguity detection",
650
+ filePath: context.spec.filePath
651
+ }
652
+ ];
653
+ }
654
+ };
655
+
656
+ // ../lint/dist/rules/no-placeholder-sections.js
657
+ var PLACEHOLDER_BODIES2 = /^(todo|tbd|fixme|n\/a|na|none|xxx|\.{2,}|-|\*)$/i;
658
+ function meaningfulContent2(content) {
659
+ return content.replace(/<!--[\s\S]*?-->/g, "").split("\n").map((line) => line.replace(/^\s*[-*+]\s+/, "").trim()).filter((line) => line.length > 0 && !/^-{3,}$/.test(line)).join("\n").trim();
660
+ }
661
+ var noPlaceholderSectionsRule = {
662
+ id: "completeness/no-placeholder-sections",
663
+ description: "Spec sections contain content, not scaffolding placeholders",
664
+ severity: "warn",
665
+ run(context) {
666
+ return context.spec.parsedSections.filter((section) => section.heading !== "").filter((section) => {
667
+ const body = meaningfulContent2(section.content);
668
+ return body === "" || PLACEHOLDER_BODIES2.test(body);
669
+ }).map((section) => ({
670
+ ruleId: "completeness/no-placeholder-sections",
671
+ severity: "warn",
672
+ message: `Section "${section.heading}" is still a placeholder \u2014 write its content or remove the section`,
673
+ filePath: context.spec.filePath,
674
+ section: section.heading
675
+ }));
676
+ }
677
+ };
678
+
679
+ // ../lint/dist/rules/id-matches-config-key.js
680
+ import { basename } from "path";
681
+ var idMatchesConfigKeyRule = {
682
+ id: "structure/id-matches-config-key",
683
+ description: "A spec's frontmatter id should match the key it is registered under in the config",
684
+ severity: "warn",
685
+ run(context) {
686
+ const { spec, config } = context;
687
+ if (!config)
688
+ return [];
689
+ const id = spec.frontmatter.id;
690
+ if (typeof id !== "string" || id.length === 0)
691
+ return [];
692
+ const specFile = basename(spec.filePath);
693
+ const candidates = Object.entries(config.specs).filter(([, entry]) => {
694
+ const target = basename(entry.path);
695
+ return !target.includes("*") && target === specFile;
696
+ });
697
+ if (candidates.length !== 1)
698
+ return [];
699
+ const key = candidates[0][0];
700
+ if (key === id)
701
+ return [];
702
+ return [
703
+ {
704
+ ruleId: "structure/id-matches-config-key",
705
+ severity: "warn",
706
+ message: `Spec declares id "${id}" but is registered in spec.config.yaml as "${key}". Frontmatter references resolve against "${id}" and config requires against "${key}", so the dependency graph shows them as two things. Rename one so they agree.`,
707
+ filePath: spec.filePath
708
+ }
709
+ ];
710
+ }
711
+ };
712
+
713
+ // ../lint/dist/rules/index.js
714
+ var structureRules = [
715
+ validFrontmatterRule,
716
+ requiredSectionsRule,
717
+ validReferencesRule,
718
+ noCircularDepsRule,
719
+ singleProjectContextRule,
720
+ idMatchesConfigKeyRule
721
+ ];
722
+ var contentRules = [
723
+ storyCoverageRule,
724
+ stalenessCheckRule,
725
+ noVagueLanguageRule,
726
+ terminologyRule,
727
+ edgeCaseCoverageRule,
728
+ namingConventionsRule,
729
+ threatCoverageRule,
730
+ ambiguityScoreAiRule,
731
+ noPlaceholderSectionsRule
732
+ ];
733
+ var allBuiltinRules = [...structureRules, ...contentRules];
734
+
735
+ // ../lint/dist/presets.js
736
+ function getPreset(name) {
737
+ switch (name) {
738
+ case "minimal":
739
+ return structureRules;
740
+ case "recommended":
741
+ return allBuiltinRules;
742
+ case "strict":
743
+ return allBuiltinRules.map((rule) => rule.severity === "warn" ? { ...rule, severity: "error" } : rule);
744
+ default:
745
+ throw new Error(`Unknown preset: "${name}". Use "minimal", "recommended", or "strict", or resolve external presets via resolvePreset() from @specdx/core.`);
746
+ }
747
+ }
748
+
749
+ // ../lint/dist/custom-rule-loader.js
750
+ import { pathToFileURL } from "url";
751
+ async function loadCustomRule(filePath) {
752
+ const module = await import(pathToFileURL(filePath).href);
753
+ const rule = module.default ?? module.rule;
754
+ if (!rule || !rule.id || !rule.run) {
755
+ throw new Error(`Custom rule at ${filePath} must export a default LintRule with id and run function`);
756
+ }
757
+ return rule;
758
+ }
759
+
760
+ // ../lint/dist/resolve-lint-config.js
761
+ var SEVERITIES = /* @__PURE__ */ new Set(["error", "warn", "info"]);
762
+ function isOff(value) {
763
+ return value === false || value === null || value === "off";
764
+ }
765
+ function severityOf(value) {
766
+ return typeof value === "string" && SEVERITIES.has(value) ? value : void 0;
767
+ }
768
+ function describe(value) {
769
+ return typeof value === "string" ? `"${value}"` : JSON.stringify(value);
770
+ }
771
+ async function resolveLintConfig({ config, preset, configDir }) {
772
+ const presetName = preset ?? config?.lint?.extends ?? "recommended";
773
+ const byId = new Map(getPreset(presetName).map((rule) => [rule.id, rule]));
774
+ const builtins = new Map(allBuiltinRules.map((rule) => [rule.id, rule]));
775
+ for (const [id, value] of Object.entries(config?.lint?.rules ?? {})) {
776
+ if (isOff(value)) {
777
+ if (!builtins.has(id)) {
778
+ throw new Error(`lint.rules["${id}"]: cannot turn off "${id}" \u2014 no built-in rule has that id. Check the spelling.`);
779
+ }
780
+ byId.delete(id);
781
+ continue;
782
+ }
783
+ let severity;
784
+ let rulePath;
785
+ if (Array.isArray(value)) {
786
+ severity = severityOf(value[0]);
787
+ if (severity === void 0) {
788
+ throw new Error(`lint.rules["${id}"]: ${describe(value[0])} is not a severity. Use "error", "warn", "info", or "off".`);
789
+ }
790
+ const options = value[1];
791
+ if (options !== void 0) {
792
+ if (typeof options !== "object" || options === null || Array.isArray(options)) {
793
+ throw new Error(`lint.rules["${id}"]: expected options like { path: "./rule.js" }, got ${describe(options)}.`);
794
+ }
795
+ const declared = options.path;
796
+ if (declared !== void 0) {
797
+ if (typeof declared !== "string" || declared.length === 0) {
798
+ throw new Error(`lint.rules["${id}"]: \`path\` must be a non-empty string.`);
799
+ }
800
+ rulePath = declared;
801
+ }
802
+ }
803
+ } else {
804
+ severity = severityOf(value);
805
+ if (severity === void 0) {
806
+ throw new Error(`lint.rules["${id}"]: ${describe(value)} is not a severity. Use "error", "warn", "info", or "off".`);
807
+ }
808
+ }
809
+ if (rulePath !== void 0) {
810
+ const absolute = isAbsolute(rulePath) ? rulePath : resolve(configDir, rulePath);
811
+ const custom = await loadCustomRule(absolute);
812
+ byId.set(id, { ...custom, id, severity });
813
+ continue;
814
+ }
815
+ const existing = byId.get(id) ?? builtins.get(id);
816
+ if (!existing) {
817
+ throw new Error(`lint.rules["${id}"]: no built-in rule with that id. For a custom rule, give it a file: ["${severity}", { path: "./rules/my-rule.js" }].`);
818
+ }
819
+ byId.set(id, { ...existing, severity });
820
+ }
821
+ const ignore = [];
822
+ for (const pattern of config?.lint?.ignore ?? []) {
823
+ ignore.push(...await resolveGlob(pattern, configDir));
824
+ }
825
+ return { rules: [...byId.values()], ignore };
826
+ }
827
+
828
+ export {
829
+ createLintEngine,
830
+ parseFeatures,
831
+ parseFeatureEntries,
832
+ uncoveredFeatures,
833
+ resolveLintConfig
834
+ };
835
+ //# sourceMappingURL=chunk-LJTLNXGV.js.map