specdx 0.4.0-alpha.2 → 0.4.0-alpha.20

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 (112) hide show
  1. package/.claude-plugin/plugin.json +7 -2
  2. package/LICENSE +21 -0
  3. package/README.md +477 -0
  4. package/dist/{check-PZFBVQIP.js → check-GGQB3SHI.js} +36 -10
  5. package/dist/check-GGQB3SHI.js.map +1 -0
  6. package/dist/chunk-5WRI5ZAA.js +31 -0
  7. package/dist/chunk-CI7KYTC7.js +103 -0
  8. package/dist/chunk-CI7KYTC7.js.map +1 -0
  9. package/dist/chunk-FBMYBYFB.js +182 -0
  10. package/dist/chunk-FBMYBYFB.js.map +1 -0
  11. package/dist/{chunk-FZWT4HVX.js → chunk-MM325DR6.js} +156 -2
  12. package/dist/chunk-MM325DR6.js.map +1 -0
  13. package/dist/chunk-RY5CDUNN.js +2846 -0
  14. package/dist/chunk-RY5CDUNN.js.map +1 -0
  15. package/dist/{chunk-YRDOYUKF.js → chunk-T232GZ2L.js} +124 -19
  16. package/dist/chunk-T232GZ2L.js.map +1 -0
  17. package/dist/{chunk-PHWUK7TH.js → chunk-UZKOJL2N.js} +288 -50
  18. package/dist/chunk-UZKOJL2N.js.map +1 -0
  19. package/dist/{chunk-QEUZJWBY.js → chunk-ZB5R5SK5.js} +364 -59
  20. package/dist/chunk-ZB5R5SK5.js.map +1 -0
  21. package/dist/{chunk-YDU26YTH.js → chunk-ZIPGRLYE.js} +120 -16
  22. package/dist/chunk-ZIPGRLYE.js.map +1 -0
  23. package/dist/diff-PHEX3HUT.js +188 -0
  24. package/dist/diff-PHEX3HUT.js.map +1 -0
  25. package/dist/{dist-2B2MR5AM.js → dist-DQ6NNKZO.js} +53 -14
  26. package/dist/dist-DQ6NNKZO.js.map +1 -0
  27. package/dist/dist-RT3MTIUW.js +16 -0
  28. package/dist/dist-RT3MTIUW.js.map +1 -0
  29. package/dist/generate-5VO6M4PB.js +21 -0
  30. package/dist/generate-5VO6M4PB.js.map +1 -0
  31. package/dist/{generate-story-AOALIKSD.js → generate-story-CJMV2F5K.js} +48 -20
  32. package/dist/generate-story-CJMV2F5K.js.map +1 -0
  33. package/dist/{generate-test-plan-34L6RGOB.js → generate-test-plan-XBAFJKJI.js} +63 -10
  34. package/dist/generate-test-plan-XBAFJKJI.js.map +1 -0
  35. package/dist/graph-UZJMLX4J.js +103 -0
  36. package/dist/graph-UZJMLX4J.js.map +1 -0
  37. package/dist/index.d.ts +171 -0
  38. package/dist/index.js +2635 -386
  39. package/dist/index.js.map +1 -1
  40. package/dist/{lint-XGVQ6LCP.js → lint-TVL2ILOQ.js} +20 -8
  41. package/dist/lint-TVL2ILOQ.js.map +1 -0
  42. package/dist/main.js +11 -146
  43. package/dist/main.js.map +1 -1
  44. package/dist/mcp-F7LJBZ4X.js +35 -0
  45. package/dist/mcp-F7LJBZ4X.js.map +1 -0
  46. package/dist/{migrate-KDJZQKP7.js → migrate-DEFCNOAH.js} +20 -8
  47. package/dist/migrate-DEFCNOAH.js.map +1 -0
  48. package/dist/{pack-OJ3CDZHD.js → pack-PNLD5AYW.js} +36 -11
  49. package/dist/pack-PNLD5AYW.js.map +1 -0
  50. package/dist/ready-2PHBPWJD.js +257 -0
  51. package/dist/ready-2PHBPWJD.js.map +1 -0
  52. package/dist/skills/{specdx-author-spec.md → core/specdx-author-spec/SKILL.md} +10 -6
  53. package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-01-frontmatter.md +1 -1
  54. package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-02-sections.md +41 -0
  55. package/dist/skills/{specdx-onboard.md → core/specdx-onboard/SKILL.md} +8 -3
  56. package/dist/skills/{specdx-plan-from-spec.md → core/specdx-plan-from-spec/SKILL.md} +5 -1
  57. package/dist/skills/{specdx-pre-commit.md → core/specdx-pre-commit/SKILL.md} +16 -2
  58. package/dist/skills/{specdx-review-spec.md → core/specdx-review-spec/SKILL.md} +5 -1
  59. package/dist/skills/core/specdx-router/SKILL.md +67 -0
  60. package/dist/skills/{specdx-sprint-review.md → core/specdx-sprint-review/SKILL.md} +5 -1
  61. package/dist/skills/{specdx-start-task.md → core/specdx-start-task/SKILL.md} +5 -1
  62. package/dist/skills/{specdx-check-drift.md → experimental/specdx-check-drift/SKILL.md} +10 -4
  63. package/dist/skills/{specdx-verify.md → experimental/specdx-verify/SKILL.md} +17 -2
  64. package/dist/skills-LHFTTEJ7.js +121 -0
  65. package/dist/skills-LHFTTEJ7.js.map +1 -0
  66. package/dist/{status-JVIXK73H.js → status-UKLQV4AI.js} +48 -34
  67. package/dist/status-UKLQV4AI.js.map +1 -0
  68. package/dist/{update-HFLDULNJ.js → update-KLDLDQZM.js} +6 -5
  69. package/dist/update-KLDLDQZM.js.map +1 -0
  70. package/dist/validate-FXD5WS4C.js +87 -0
  71. package/dist/validate-FXD5WS4C.js.map +1 -0
  72. package/hooks/hooks.json +12 -6
  73. package/hooks/session-start +35 -3
  74. package/package.json +68 -21
  75. package/dist/changelog-G6XDIAZP.js +0 -86
  76. package/dist/changelog-G6XDIAZP.js.map +0 -1
  77. package/dist/check-PZFBVQIP.js.map +0 -1
  78. package/dist/chunk-7C3BAVCP.js +0 -1147
  79. package/dist/chunk-7C3BAVCP.js.map +0 -1
  80. package/dist/chunk-FZWT4HVX.js.map +0 -1
  81. package/dist/chunk-PHWUK7TH.js.map +0 -1
  82. package/dist/chunk-QEUZJWBY.js.map +0 -1
  83. package/dist/chunk-YDU26YTH.js.map +0 -1
  84. package/dist/chunk-YRDOYUKF.js.map +0 -1
  85. package/dist/diff-BEZARP53.js +0 -100
  86. package/dist/diff-BEZARP53.js.map +0 -1
  87. package/dist/dist-2B2MR5AM.js.map +0 -1
  88. package/dist/dist-WIK7F2PJ.js +0 -11
  89. package/dist/explain-PCZKDEM4.js +0 -102
  90. package/dist/explain-PCZKDEM4.js.map +0 -1
  91. package/dist/generate-OMEBJQFQ.js +0 -13
  92. package/dist/generate-OMEBJQFQ.js.map +0 -1
  93. package/dist/generate-story-AOALIKSD.js.map +0 -1
  94. package/dist/generate-test-plan-34L6RGOB.js.map +0 -1
  95. package/dist/graph-RR5UTY3R.js +0 -54
  96. package/dist/graph-RR5UTY3R.js.map +0 -1
  97. package/dist/lint-XGVQ6LCP.js.map +0 -1
  98. package/dist/mcp-GUFW37BE.js +0 -17
  99. package/dist/mcp-GUFW37BE.js.map +0 -1
  100. package/dist/migrate-KDJZQKP7.js.map +0 -1
  101. package/dist/pack-OJ3CDZHD.js.map +0 -1
  102. package/dist/ready-WTNO5W7C.js +0 -165
  103. package/dist/ready-WTNO5W7C.js.map +0 -1
  104. package/dist/skills-3GBBWZW2.js +0 -93
  105. package/dist/skills-3GBBWZW2.js.map +0 -1
  106. package/dist/status-JVIXK73H.js.map +0 -1
  107. package/dist/update-HFLDULNJ.js.map +0 -1
  108. package/dist/validate-O7W5YLR6.js +0 -34
  109. package/dist/validate-O7W5YLR6.js.map +0 -1
  110. /package/dist/{dist-WIK7F2PJ.js.map → chunk-5WRI5ZAA.js.map} +0 -0
  111. /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
  112. /package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-03-finalize.md +0 -0
@@ -1,3 +1,7 @@
1
+ // ../check/dist/check.js
2
+ import { readFile as readFile3 } from "fs/promises";
3
+ import { join as join10 } from "path";
4
+
1
5
  // ../check/dist/spec-parsers.js
2
6
  function extractSection(content, heading) {
3
7
  const headingPattern = new RegExp(`^##\\s+${escapeRegex(heading)}\\s*$`, "im");
@@ -13,34 +17,55 @@ function escapeRegex(str) {
13
17
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14
18
  }
15
19
  var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
20
+ function pathParams(path) {
21
+ return (path.match(/:([A-Za-z_][A-Za-z0-9_]*)/g) ?? []).map((p) => p.slice(1));
22
+ }
23
+ function hasEndpointsSection(content) {
24
+ return extractSection(content, "Endpoints") !== null;
25
+ }
16
26
  function parseEndpoints(content) {
17
27
  const section = extractSection(content, "Endpoints");
18
28
  if (!section)
19
29
  return [];
20
30
  const results = [];
31
+ const seen = /* @__PURE__ */ new Set();
32
+ const push = (rawMethod, path, description) => {
33
+ const method = rawMethod.toUpperCase();
34
+ if (!HTTP_METHODS.has(method))
35
+ return;
36
+ const key = `${method} ${path}`;
37
+ if (seen.has(key))
38
+ return;
39
+ seen.add(key);
40
+ results.push({
41
+ method,
42
+ path,
43
+ params: pathParams(path),
44
+ description: description && description.length > 0 ? description : void 0
45
+ });
46
+ };
21
47
  const headingPattern = /^###\s+(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/im;
22
- const blocks = section.split(/^(?=###\s)/m);
23
- for (const block of blocks) {
48
+ for (const block of section.split(/^(?=###\s)/m)) {
24
49
  const headingMatch = headingPattern.exec(block);
25
50
  if (!headingMatch)
26
51
  continue;
27
- const rawMethod = headingMatch[1].toUpperCase();
28
- if (!HTTP_METHODS.has(rawMethod))
29
- continue;
30
- const method = rawMethod;
31
- const path = headingMatch[2];
32
- const params = (path.match(/:([A-Za-z_][A-Za-z0-9_]*)/g) ?? []).map((p) => p.slice(1));
33
52
  const afterHeading = block.slice(headingMatch.index + headingMatch[0].length);
34
53
  const descriptionLine = afterHeading.split("\n").map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith("#") && !l.startsWith("-"));
35
- results.push({
36
- method,
37
- path,
38
- params,
39
- description: descriptionLine
40
- });
54
+ push(headingMatch[1], headingMatch[2], descriptionLine);
55
+ }
56
+ const bulletPattern = new RegExp(
57
+ "^\\s*[-*+]\\s+[`*_]*\\s*(GET|POST|PUT|PATCH|DELETE)[`*_]*\\s+[`*_]*(/[^\\s`*_]*)[`*_]*\\s*(?:[\u2014\u2013:-]\\s*(.*))?$",
58
+ // optional description
59
+ "gim"
60
+ );
61
+ let bulletMatch;
62
+ while ((bulletMatch = bulletPattern.exec(section)) !== null) {
63
+ push(bulletMatch[1], bulletMatch[2], bulletMatch[3]?.trim());
41
64
  }
42
65
  return results;
43
66
  }
67
+ var TYPE_SHAPE = /^[A-Za-z_$][\w$.<>[\]]*(?:\s*[|&]\s*[A-Za-z_$][\w$.<>[\]]*)*$/;
68
+ var TYPE_NAME_SHAPE = /^[A-Za-z_$][\w$]*(?:<[\w$,\s[\]]+>)?$/;
44
69
  function parseTypeDefinitions(content) {
45
70
  const section = extractSection(content, "Data Model");
46
71
  if (!section)
@@ -48,25 +73,94 @@ function parseTypeDefinitions(content) {
48
73
  const results = [];
49
74
  const blocks = section.split(/^(?=###\s)/m);
50
75
  for (const block of blocks) {
51
- const headingMatch = /^###\s+(\S+)/m.exec(block);
76
+ const headingMatch = /^###\s+(.+?)\s*$/m.exec(block);
52
77
  if (!headingMatch)
53
78
  continue;
54
- const name = headingMatch[1];
79
+ const name = headingMatch[1].trim().replace(/^`|`$/g, "");
80
+ if (!TYPE_NAME_SHAPE.test(name))
81
+ continue;
55
82
  const fields = [];
56
- const fieldPattern = /^-\s+`([^`]+)`\s*:\s*(.+)/gm;
83
+ const fieldPattern = /^-\s+(?:`([^`]+)`|([A-Za-z_$][\w$]*\??))\s*:\s*(.+)/gm;
57
84
  let fieldMatch;
58
85
  while ((fieldMatch = fieldPattern.exec(block)) !== null) {
59
- const rawName = fieldMatch[1];
86
+ const backticked = fieldMatch[1] !== void 0;
87
+ const rawName = fieldMatch[1] ?? fieldMatch[2];
60
88
  const optional = rawName.endsWith("?");
61
89
  const fieldName = optional ? rawName.slice(0, -1) : rawName;
62
- const rawType = fieldMatch[2].trim();
90
+ const rawType = fieldMatch[3].trim();
63
91
  const type = rawType.replace(/\s*\(.*?\)\s*$/, "").trim();
92
+ if (!backticked && !TYPE_SHAPE.test(type))
93
+ continue;
64
94
  fields.push({ name: fieldName, type, optional });
65
95
  }
96
+ if (fields.length === 0)
97
+ fields.push(...parseFieldTable(block));
98
+ if (fields.length === 0)
99
+ continue;
66
100
  results.push({ name, fields });
67
101
  }
68
102
  return results;
69
103
  }
104
+ function tableCells(line) {
105
+ const trimmed = line.trim();
106
+ if (!trimmed.startsWith("|"))
107
+ return null;
108
+ return trimmed.replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim().replace(/^`|`$/g, ""));
109
+ }
110
+ function isTableRule(cells) {
111
+ return cells.every((cell) => /^:?-{2,}:?$/.test(cell));
112
+ }
113
+ function parseFieldTable(block) {
114
+ const rows = block.split("\n").map(tableCells);
115
+ const headerIndex = rows.findIndex((r) => r !== null);
116
+ if (headerIndex === -1)
117
+ return [];
118
+ const header = rows[headerIndex];
119
+ const nameColumn = header.findIndex((h) => /^(field|name|property|attribute|key)s?$/i.test(h));
120
+ const typeColumn = header.findIndex((h) => /^types?$/i.test(h));
121
+ if (nameColumn === -1 || typeColumn === -1)
122
+ return [];
123
+ const fields = [];
124
+ for (const cells of rows.slice(headerIndex + 1)) {
125
+ if (cells === null)
126
+ continue;
127
+ if (isTableRule(cells))
128
+ continue;
129
+ const rawName = cells[nameColumn];
130
+ const rawType = cells[typeColumn];
131
+ if (!rawName || !rawType)
132
+ continue;
133
+ const optional = rawName.endsWith("?");
134
+ const name = optional ? rawName.slice(0, -1) : rawName;
135
+ if (!/^[A-Za-z_$][\w$]*$/.test(name))
136
+ continue;
137
+ fields.push({ name, type: rawType.replace(/\s*\(.*?\)\s*$/, "").trim(), optional });
138
+ }
139
+ return fields;
140
+ }
141
+ function unreadableTypeBlocks(content) {
142
+ const section = extractSection(content, "Data Model");
143
+ if (!section)
144
+ return [];
145
+ const unreadable = [];
146
+ for (const block of section.split(/^(?=###\s)/m)) {
147
+ const headingMatch = /^###\s+(.+?)\s*$/m.exec(block);
148
+ if (!headingMatch)
149
+ continue;
150
+ const name = headingMatch[1].trim().replace(/^`|`$/g, "");
151
+ if (!TYPE_NAME_SHAPE.test(name))
152
+ continue;
153
+ const hasTable = block.split("\n").some((line) => tableCells(line) !== null);
154
+ if (!hasTable)
155
+ continue;
156
+ const parsed = parseTypeDefinitions(`## Data Model
157
+
158
+ ${block}`);
159
+ if (parsed.length === 0)
160
+ unreadable.push(name);
161
+ }
162
+ return unreadable;
163
+ }
70
164
  function parseTestCases(content) {
71
165
  const section = extractSection(content, "Test Cases");
72
166
  if (!section)
@@ -83,7 +177,15 @@ function parseTestCases(content) {
83
177
  const bulletMatch = /^-\s+(.+)/.exec(line);
84
178
  if (!bulletMatch)
85
179
  continue;
86
- const bulletText = bulletMatch[1].trim();
180
+ let bulletText = bulletMatch[1].trim();
181
+ let caseId;
182
+ const idMatch = /^\*{0,2}(TC\d+)\*{0,2}\s*[:.-]\s*/i.exec(bulletText);
183
+ if (idMatch) {
184
+ caseId = idMatch[1].toUpperCase();
185
+ bulletText = bulletText.slice(idMatch[0].length).trim();
186
+ if (!bulletText)
187
+ continue;
188
+ }
87
189
  const colonIdx = bulletText.indexOf(":");
88
190
  if (colonIdx !== -1) {
89
191
  const label = bulletText.slice(0, colonIdx).trim();
@@ -92,11 +194,15 @@ function parseTestCases(content) {
92
194
  for (const item of items) {
93
195
  const trimmed = item.trim();
94
196
  if (trimmed) {
95
- results.push({ description: `${label}: ${trimmed}`, section: currentSection });
197
+ results.push({
198
+ description: `${label}: ${trimmed}`,
199
+ section: currentSection,
200
+ id: caseId
201
+ });
96
202
  }
97
203
  }
98
204
  } else {
99
- results.push({ description: bulletText, section: currentSection });
205
+ results.push({ description: bulletText, section: currentSection, id: caseId });
100
206
  }
101
207
  }
102
208
  return results;
@@ -339,9 +445,10 @@ async function walkAppDir(dir, pathPrefix, results) {
339
445
  }
340
446
  }
341
447
  }
342
- async function extractNextjsRoutes(projectDir, appDir = "app") {
343
- const scanDir = join3(projectDir, appDir);
344
- if (!existsSync3(scanDir)) {
448
+ async function extractNextjsRoutes(projectDir, appDir) {
449
+ const candidates = appDir !== void 0 ? [appDir] : ["app", "src/app"];
450
+ const scanDir = candidates.map((dir) => join3(projectDir, dir)).find((dir) => existsSync3(dir));
451
+ if (!scanDir) {
345
452
  return [];
346
453
  }
347
454
  let tsMorph;
@@ -618,7 +725,7 @@ function inferZodType(node, SyntaxKind) {
618
725
  }
619
726
 
620
727
  // ../check/dist/extractors/prisma.js
621
- import { readFile } from "fs/promises";
728
+ import { readFile, readdir as readdir2 } from "fs/promises";
622
729
  import { join as join6 } from "path";
623
730
  var PRISMA_TYPE_MAP = {
624
731
  String: "string",
@@ -631,14 +738,37 @@ var PRISMA_TYPE_MAP = {
631
738
  Json: "unknown",
632
739
  Bytes: "Buffer"
633
740
  };
634
- async function extractPrismaModels(projectDir) {
635
- const schemaPath = join6(projectDir, "schema.prisma");
636
- let content;
741
+ async function findPrismaSchemas(projectDir) {
742
+ const found = [];
743
+ for (const relative of ["prisma/schema.prisma", "schema.prisma"]) {
744
+ const path = join6(projectDir, relative);
745
+ try {
746
+ await readFile(path, "utf-8");
747
+ found.push(path);
748
+ } catch {
749
+ }
750
+ }
751
+ const schemaDir = join6(projectDir, "prisma", "schema");
637
752
  try {
638
- content = await readFile(schemaPath, "utf-8");
753
+ for (const entry of await readdir2(schemaDir)) {
754
+ if (entry.endsWith(".prisma"))
755
+ found.push(join6(schemaDir, entry));
756
+ }
639
757
  } catch {
758
+ }
759
+ return found;
760
+ }
761
+ async function extractPrismaModels(projectDir) {
762
+ const schemaPaths = await findPrismaSchemas(projectDir);
763
+ if (schemaPaths.length === 0)
640
764
  return [];
765
+ const models = [];
766
+ for (const schemaPath of schemaPaths) {
767
+ models.push(...parseSchema(await readFile(schemaPath, "utf-8"), schemaPath));
641
768
  }
769
+ return models;
770
+ }
771
+ function parseSchema(content, schemaPath) {
642
772
  const models = [];
643
773
  const modelRe = /^model\s+(\w+)\s*\{([^}]+)\}/gm;
644
774
  let modelMatch;
@@ -857,7 +987,10 @@ function matchTests(specCases, codeTests, specId) {
857
987
  category: "test",
858
988
  specId,
859
989
  specSection: specCase.section,
860
- expected: specCase.description,
990
+ // `expected` keeps the case ID so the finding can be traced back to a
991
+ // line in the test plan; the suggestion is the test name to write, and
992
+ // the spec's own label is no part of that.
993
+ expected: specCase.id ? `${specCase.id}: ${specCase.description}` : specCase.description,
861
994
  severity: "warn",
862
995
  suggestion: `Add a test matching: "${specCase.description}"`
863
996
  });
@@ -866,9 +999,133 @@ function matchTests(specCases, codeTests, specId) {
866
999
  return findings;
867
1000
  }
868
1001
 
1002
+ // ../check/dist/artifacts.js
1003
+ import { existsSync as existsSync7 } from "fs";
1004
+ import { join as join8 } from "path";
1005
+ var ENFORCED_STATUSES = /* @__PURE__ */ new Set(["approved"]);
1006
+ function artifactsEnforced(status) {
1007
+ return typeof status === "string" && ENFORCED_STATUSES.has(status);
1008
+ }
1009
+ function parseArtifacts(spec) {
1010
+ const raw = spec.frontmatter.artifacts;
1011
+ if (!Array.isArray(raw))
1012
+ return [];
1013
+ const out = [];
1014
+ for (const item of raw) {
1015
+ if (!item || typeof item !== "object")
1016
+ continue;
1017
+ const decl = item;
1018
+ if (typeof decl.path !== "string" || decl.path.length === 0)
1019
+ continue;
1020
+ const exports = Array.isArray(decl.exports) ? decl.exports.filter((e) => typeof e === "string" && e.length > 0) : void 0;
1021
+ out.push({ path: decl.path, exports });
1022
+ }
1023
+ return out;
1024
+ }
1025
+ async function getExportedNames(filePath) {
1026
+ try {
1027
+ const { Project } = await import("ts-morph");
1028
+ const project = new Project({
1029
+ skipAddingFilesFromTsConfig: true,
1030
+ compilerOptions: { allowJs: true }
1031
+ });
1032
+ const sourceFile = project.addSourceFileAtPath(filePath);
1033
+ return new Set(sourceFile.getExportedDeclarations().keys());
1034
+ } catch {
1035
+ return null;
1036
+ }
1037
+ }
1038
+ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
1039
+ const findings = [];
1040
+ const notes = [];
1041
+ let total = 0;
1042
+ let pending = 0;
1043
+ let skippedExports = 0;
1044
+ for (const spec of specs) {
1045
+ const specId = String(spec.frontmatter.id);
1046
+ const status = spec.frontmatter.status;
1047
+ const enforced = artifactsEnforced(status);
1048
+ for (const artifact of parseArtifacts(spec)) {
1049
+ const absolute = join8(projectDir, artifact.path);
1050
+ if (!existsSync7(absolute)) {
1051
+ if (enforced) {
1052
+ total += 1;
1053
+ findings.push({
1054
+ type: "missing",
1055
+ category: "artifact",
1056
+ specId,
1057
+ expected: `file "${artifact.path}"`,
1058
+ severity: "error",
1059
+ suggestion: `Create ${artifact.path} or update the artifacts list in ${specId}.`
1060
+ });
1061
+ } else {
1062
+ pending += 1;
1063
+ findings.push({
1064
+ type: "pending",
1065
+ category: "artifact",
1066
+ specId,
1067
+ expected: `file "${artifact.path}"`,
1068
+ severity: "info",
1069
+ suggestion: `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`
1070
+ });
1071
+ }
1072
+ continue;
1073
+ }
1074
+ total += 1;
1075
+ if (!artifact.exports || artifact.exports.length === 0)
1076
+ continue;
1077
+ if (!tsMorphAvailable) {
1078
+ skippedExports += artifact.exports.length;
1079
+ continue;
1080
+ }
1081
+ const exported = await getExportedNames(absolute);
1082
+ if (exported === null) {
1083
+ skippedExports += artifact.exports.length;
1084
+ continue;
1085
+ }
1086
+ for (const name of artifact.exports) {
1087
+ if (exported.has(name)) {
1088
+ total += 1;
1089
+ continue;
1090
+ }
1091
+ if (enforced) {
1092
+ total += 1;
1093
+ findings.push({
1094
+ type: "missing",
1095
+ category: "artifact",
1096
+ specId,
1097
+ codeLocation: { file: artifact.path, line: 1 },
1098
+ expected: `export "${name}" from ${artifact.path}`,
1099
+ severity: "error",
1100
+ suggestion: `Export ${name} from ${artifact.path} or update the artifacts list in ${specId}.`
1101
+ });
1102
+ } else {
1103
+ pending += 1;
1104
+ findings.push({
1105
+ type: "pending",
1106
+ category: "artifact",
1107
+ specId,
1108
+ codeLocation: { file: artifact.path, line: 1 },
1109
+ expected: `export "${name}" from ${artifact.path}`,
1110
+ severity: "info",
1111
+ suggestion: `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`
1112
+ });
1113
+ }
1114
+ }
1115
+ }
1116
+ }
1117
+ if (skippedExports > 0) {
1118
+ notes.push(`artifact export checks skipped for ${skippedExports} export(s): ts-morph is not available or the file could not be parsed.`);
1119
+ }
1120
+ if (pending > 0) {
1121
+ notes.push(`${pending} declared artifact assertion(s) pending: files or exports planned by specs that are not yet approved. They are excluded from the score and become enforceable when the spec status changes to approved.`);
1122
+ }
1123
+ return { findings, total, checked: total, pending, notes };
1124
+ }
1125
+
869
1126
  // ../check/dist/score.js
870
1127
  function computeScore(findings, totals) {
871
- const missingByCategory = { route: 0, type: 0, test: 0 };
1128
+ const missingByCategory = { route: 0, type: 0, test: 0, artifact: 0 };
872
1129
  for (const f of findings) {
873
1130
  if (f.type === "missing" || f.type === "mismatch") {
874
1131
  missingByCategory[f.category] = (missingByCategory[f.category] ?? 0) + 1;
@@ -877,7 +1134,8 @@ function computeScore(findings, totals) {
877
1134
  const categoryMap = {
878
1135
  routes: { total: totals.routes, categoryKey: "route" },
879
1136
  types: { total: totals.types, categoryKey: "type" },
880
- tests: { total: totals.tests, categoryKey: "test" }
1137
+ tests: { total: totals.tests, categoryKey: "test" },
1138
+ artifacts: { total: totals.artifacts, categoryKey: "artifact" }
881
1139
  };
882
1140
  const byCategory = {};
883
1141
  let totalItems = 0;
@@ -889,13 +1147,16 @@ function computeScore(findings, totals) {
889
1147
  totalItems += total;
890
1148
  totalMatched += matched;
891
1149
  }
892
- const overall = totalItems === 0 ? 100 : Math.round(totalMatched / totalItems * 100);
893
- return { overall, byCategory };
1150
+ if (totalItems === 0) {
1151
+ return { overall: 0, assessed: false, byCategory };
1152
+ }
1153
+ const overall = Math.round(totalMatched / totalItems * 100);
1154
+ return { overall, assessed: true, byCategory };
894
1155
  }
895
1156
 
896
1157
  // ../check/dist/detect-framework.js
897
1158
  import { readFile as readFile2 } from "fs/promises";
898
- import { join as join8 } from "path";
1159
+ import { join as join9 } from "path";
899
1160
  var FRAMEWORK_PACKAGES = [
900
1161
  ["express", "express"],
901
1162
  ["hono", "hono"],
@@ -904,7 +1165,7 @@ var FRAMEWORK_PACKAGES = [
904
1165
  async function detectFramework(projectDir) {
905
1166
  let pkg;
906
1167
  try {
907
- const content = await readFile2(join8(projectDir, "package.json"), "utf-8");
1168
+ const content = await readFile2(join9(projectDir, "package.json"), "utf-8");
908
1169
  pkg = JSON.parse(content);
909
1170
  } catch {
910
1171
  return null;
@@ -919,50 +1180,102 @@ async function detectFramework(projectDir) {
919
1180
  }
920
1181
 
921
1182
  // ../check/dist/check.js
1183
+ async function usesPrisma(projectDir) {
1184
+ try {
1185
+ const pkg = JSON.parse(await readFile3(join10(projectDir, "package.json"), "utf-8"));
1186
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
1187
+ return "prisma" in deps || "@prisma/client" in deps;
1188
+ } catch {
1189
+ return false;
1190
+ }
1191
+ }
922
1192
  async function runCheck(specs, projectDir, config = {}) {
923
1193
  const findings = [];
1194
+ const notes = [];
924
1195
  let routeTotal = 0;
925
1196
  let typeTotal = 0;
926
1197
  let testTotal = 0;
1198
+ let codeRouteCount = null;
1199
+ let codeTypeCount = null;
1200
+ let codeTestCount = null;
1201
+ const tsMorphAvailable = await import("ts-morph").then(() => true, () => false);
1202
+ if (!tsMorphAvailable) {
1203
+ notes.push("route, type and test extraction skipped: ts-morph is not installed. Install specdx and ts-morph as devDependencies (pnpm add -D specdx ts-morph) \u2014 an ephemeral runner like pnpm dlx cannot provide it.");
1204
+ }
1205
+ const framework = config.framework && config.framework !== "auto" ? config.framework : await detectFramework(projectDir);
927
1206
  const apiContractSpecs = specs.filter((s) => s.frontmatter.type === "api-contract");
928
- if (apiContractSpecs.length > 0) {
929
- const codeRoutes = await extractRoutes(projectDir, config);
1207
+ if (apiContractSpecs.length > 0 && tsMorphAvailable) {
1208
+ const codeRoutes = await extractRoutes(projectDir, config, framework);
1209
+ codeRouteCount = codeRoutes.length;
930
1210
  for (const spec of apiContractSpecs) {
931
1211
  const specEndpoints = parseEndpoints(spec.content);
932
1212
  routeTotal += specEndpoints.length;
933
1213
  findings.push(...matchRoutes(specEndpoints, codeRoutes, spec.frontmatter.id));
1214
+ if (specEndpoints.length === 0 && hasEndpointsSection(spec.content)) {
1215
+ notes.push(`${spec.frontmatter.id}: no endpoints recognised in its Endpoints section, so routes were not assessed. Write each endpoint as \`- GET /path \u2014 description\` or as a \`### GET /path\` heading.`);
1216
+ }
1217
+ }
1218
+ if (framework === null) {
1219
+ notes.push("no supported framework detected (express, hono, nextjs) \u2014 route extraction ran in fallback mode across all extractors.");
934
1220
  }
935
1221
  }
936
1222
  const designSpecs = specs.filter((s) => s.frontmatter.type === "technical-design");
937
1223
  if (designSpecs.length > 0) {
938
1224
  const codeTypes = [
939
- ...await extractTypeScriptTypes(projectDir, config.types_dir),
940
- ...await extractZodSchemas(projectDir, config.types_dir),
1225
+ ...tsMorphAvailable ? await extractTypeScriptTypes(projectDir, config.types_dir) : [],
1226
+ ...tsMorphAvailable ? await extractZodSchemas(projectDir, config.types_dir) : [],
941
1227
  ...await extractPrismaModels(projectDir)
942
1228
  ];
1229
+ codeTypeCount = codeTypes.length;
1230
+ if (await usesPrisma(projectDir) && (await findPrismaSchemas(projectDir)).length === 0) {
1231
+ notes.push("a prisma dependency is declared but no schema was found at prisma/schema.prisma, schema.prisma or prisma/schema/*.prisma \u2014 Prisma models were not assessed.");
1232
+ }
943
1233
  for (const spec of designSpecs) {
944
1234
  const specTypes = parseTypeDefinitions(spec.content);
945
- typeTotal += specTypes.reduce((sum, t) => sum + t.fields.length, 0);
1235
+ const fieldCount = specTypes.reduce((sum, t) => sum + t.fields.length, 0);
1236
+ typeTotal += fieldCount;
946
1237
  findings.push(...matchTypes(specTypes, codeTypes, spec.frontmatter.id));
1238
+ if (fieldCount === 0 && /^##\s+Data Model\s*$/im.test(spec.content)) {
1239
+ notes.push(`${spec.frontmatter.id}: no fields recognised in its Data Model, so types were not assessed. Write fields as \`- name: type\` (one per line, under a \`### TypeName\` heading).`);
1240
+ }
1241
+ for (const name of unreadableTypeBlocks(spec.content)) {
1242
+ notes.push(`${spec.frontmatter.id}: no fields recognised under \`### ${name}\`, so that type was not assessed. A table needs a field column and a type column, or write fields as \`- name: type\`.`);
1243
+ }
947
1244
  }
948
1245
  }
949
1246
  const testPlanSpecs = specs.filter((s) => s.frontmatter.type === "test-plan");
950
- if (testPlanSpecs.length > 0) {
1247
+ if (testPlanSpecs.length > 0 && tsMorphAvailable) {
951
1248
  const codeTests = await extractTestDescriptions(projectDir, config.tests_dir);
1249
+ codeTestCount = codeTests.length;
952
1250
  for (const spec of testPlanSpecs) {
953
1251
  const specCases = parseTestCases(spec.content);
954
1252
  testTotal += specCases.length;
955
1253
  findings.push(...matchTests(specCases, codeTests, spec.frontmatter.id));
956
1254
  }
957
1255
  }
958
- const score = computeScore(findings, { routes: routeTotal, types: typeTotal, tests: testTotal });
1256
+ const artifactResult = await checkArtifacts(specs, projectDir, tsMorphAvailable);
1257
+ findings.push(...artifactResult.findings);
1258
+ notes.push(...artifactResult.notes);
1259
+ const score = computeScore(findings, {
1260
+ routes: routeTotal,
1261
+ types: typeTotal,
1262
+ tests: testTotal,
1263
+ artifacts: artifactResult.total
1264
+ });
959
1265
  const errors = findings.filter((f) => f.severity === "error").length;
960
1266
  const warnings = findings.filter((f) => f.severity === "warn").length;
961
- const summary = `${score.overall}% implementation coverage \u2014 ${errors} errors, ${warnings} warnings`;
962
- return { findings, score, summary };
1267
+ const summary = score.assessed ? `${score.overall}% implementation coverage \u2014 ${errors} errors, ${warnings} warnings` : "coverage not assessed \u2014 no checkable surfaces found (no spec'd routes, types, test cases, or declared artifacts)";
1268
+ const scanned = {
1269
+ framework: framework ?? null,
1270
+ codeRoutes: codeRouteCount,
1271
+ codeTypes: codeTypeCount,
1272
+ codeTests: codeTestCount,
1273
+ artifacts: artifactResult.total > 0 ? artifactResult.checked : null,
1274
+ artifactsPending: artifactResult.pending
1275
+ };
1276
+ return { findings, score, summary, scanned, notes };
963
1277
  }
964
- async function extractRoutes(projectDir, config) {
965
- const framework = config.framework ?? "auto";
1278
+ async function extractRoutes(projectDir, config, framework) {
966
1279
  if (framework === "express") {
967
1280
  return extractExpressRoutes(projectDir, config.routes_dir);
968
1281
  }
@@ -972,16 +1285,6 @@ async function extractRoutes(projectDir, config) {
972
1285
  if (framework === "nextjs") {
973
1286
  return extractNextjsRoutes(projectDir, config.app_dir);
974
1287
  }
975
- const detected = await detectFramework(projectDir);
976
- if (detected === "express") {
977
- return extractExpressRoutes(projectDir, config.routes_dir);
978
- }
979
- if (detected === "hono") {
980
- return extractHonoRoutes(projectDir, config.routes_dir);
981
- }
982
- if (detected === "nextjs") {
983
- return extractNextjsRoutes(projectDir, config.app_dir);
984
- }
985
1288
  const [express, hono, nextjs] = await Promise.all([
986
1289
  extractExpressRoutes(projectDir, config.routes_dir),
987
1290
  extractHonoRoutes(projectDir, config.routes_dir),
@@ -1044,8 +1347,10 @@ Only output the JSON array, no other text.`;
1044
1347
  }
1045
1348
 
1046
1349
  export {
1350
+ parseArtifacts,
1351
+ checkArtifacts,
1047
1352
  detectFramework,
1048
1353
  runCheck,
1049
1354
  analyzeWithAi
1050
1355
  };
1051
- //# sourceMappingURL=chunk-QEUZJWBY.js.map
1356
+ //# sourceMappingURL=chunk-ZB5R5SK5.js.map