specdx 0.4.0-alpha.2 → 0.4.0-alpha.21
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.
- package/.claude-plugin/plugin.json +7 -2
- package/LICENSE +21 -0
- package/README.md +477 -0
- package/dist/{check-PZFBVQIP.js → check-GGGHTDTH.js} +37 -11
- package/dist/check-GGGHTDTH.js.map +1 -0
- package/dist/{chunk-QEUZJWBY.js → chunk-3YXRWQGX.js} +373 -63
- package/dist/chunk-3YXRWQGX.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-6IVWJKMQ.js +103 -0
- package/dist/chunk-6IVWJKMQ.js.map +1 -0
- package/dist/{chunk-YDU26YTH.js → chunk-HCJDCS26.js} +121 -17
- package/dist/chunk-HCJDCS26.js.map +1 -0
- package/dist/chunk-IEW62WR2.js +185 -0
- package/dist/chunk-IEW62WR2.js.map +1 -0
- package/dist/chunk-PXQML7NE.js +2846 -0
- package/dist/chunk-PXQML7NE.js.map +1 -0
- package/dist/{chunk-PHWUK7TH.js → chunk-QOP2KHW3.js} +290 -52
- package/dist/chunk-QOP2KHW3.js.map +1 -0
- package/dist/{chunk-FZWT4HVX.js → chunk-SNQNQ2MP.js} +157 -3
- package/dist/chunk-SNQNQ2MP.js.map +1 -0
- package/dist/{chunk-YRDOYUKF.js → chunk-YRQPY5NF.js} +124 -19
- package/dist/chunk-YRQPY5NF.js.map +1 -0
- package/dist/diff-VHVSXLKU.js +188 -0
- package/dist/diff-VHVSXLKU.js.map +1 -0
- package/dist/{dist-2B2MR5AM.js → dist-QRCEQ5WI.js} +53 -14
- package/dist/dist-QRCEQ5WI.js.map +1 -0
- package/dist/dist-ROHCFKYT.js +16 -0
- package/dist/dist-ROHCFKYT.js.map +1 -0
- package/dist/generate-WMJ37LCN.js +21 -0
- package/dist/generate-WMJ37LCN.js.map +1 -0
- package/dist/{generate-story-AOALIKSD.js → generate-story-ORJX24P7.js} +48 -20
- package/dist/generate-story-ORJX24P7.js.map +1 -0
- package/dist/{generate-test-plan-34L6RGOB.js → generate-test-plan-Z46W3N3B.js} +63 -10
- package/dist/generate-test-plan-Z46W3N3B.js.map +1 -0
- package/dist/graph-TG2CONHV.js +103 -0
- package/dist/graph-TG2CONHV.js.map +1 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.js +2648 -390
- package/dist/index.js.map +1 -1
- package/dist/{lint-XGVQ6LCP.js → lint-ZFG6ALIT.js} +23 -8
- package/dist/lint-ZFG6ALIT.js.map +1 -0
- package/dist/main.js +11 -146
- package/dist/main.js.map +1 -1
- package/dist/mcp-WBHZANS5.js +35 -0
- package/dist/mcp-WBHZANS5.js.map +1 -0
- package/dist/{migrate-KDJZQKP7.js → migrate-FKFC7UAO.js} +20 -8
- package/dist/migrate-FKFC7UAO.js.map +1 -0
- package/dist/{pack-OJ3CDZHD.js → pack-VDEO7GRF.js} +39 -11
- package/dist/pack-VDEO7GRF.js.map +1 -0
- package/dist/ready-VDOH3XCV.js +257 -0
- package/dist/ready-VDOH3XCV.js.map +1 -0
- package/dist/skills/{specdx-author-spec.md → core/specdx-author-spec/SKILL.md} +10 -6
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-01-frontmatter.md +1 -1
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-02-sections.md +41 -0
- package/dist/skills/{specdx-onboard.md → core/specdx-onboard/SKILL.md} +8 -3
- package/dist/skills/{specdx-plan-from-spec.md → core/specdx-plan-from-spec/SKILL.md} +5 -1
- package/dist/skills/{specdx-pre-commit.md → core/specdx-pre-commit/SKILL.md} +16 -2
- package/dist/skills/{specdx-review-spec.md → core/specdx-review-spec/SKILL.md} +5 -1
- package/dist/skills/core/specdx-router/SKILL.md +67 -0
- package/dist/skills/{specdx-sprint-review.md → core/specdx-sprint-review/SKILL.md} +5 -1
- package/dist/skills/{specdx-start-task.md → core/specdx-start-task/SKILL.md} +5 -1
- package/dist/skills/{specdx-check-drift.md → experimental/specdx-check-drift/SKILL.md} +10 -4
- package/dist/skills/{specdx-verify.md → experimental/specdx-verify/SKILL.md} +17 -2
- package/dist/skills-36SRUEMR.js +121 -0
- package/dist/skills-36SRUEMR.js.map +1 -0
- package/dist/{status-JVIXK73H.js → status-JIQUF6MX.js} +48 -34
- package/dist/status-JIQUF6MX.js.map +1 -0
- package/dist/{update-HFLDULNJ.js → update-DNXF5Q64.js} +10 -9
- package/dist/update-DNXF5Q64.js.map +1 -0
- package/dist/validate-TSAMI65E.js +87 -0
- package/dist/validate-TSAMI65E.js.map +1 -0
- package/hooks/hooks.json +12 -6
- package/hooks/session-start +35 -3
- package/package.json +68 -21
- package/dist/changelog-G6XDIAZP.js +0 -86
- package/dist/changelog-G6XDIAZP.js.map +0 -1
- package/dist/check-PZFBVQIP.js.map +0 -1
- package/dist/chunk-7C3BAVCP.js +0 -1147
- package/dist/chunk-7C3BAVCP.js.map +0 -1
- package/dist/chunk-FZWT4HVX.js.map +0 -1
- package/dist/chunk-PHWUK7TH.js.map +0 -1
- package/dist/chunk-QEUZJWBY.js.map +0 -1
- package/dist/chunk-YDU26YTH.js.map +0 -1
- package/dist/chunk-YRDOYUKF.js.map +0 -1
- package/dist/diff-BEZARP53.js +0 -100
- package/dist/diff-BEZARP53.js.map +0 -1
- package/dist/dist-2B2MR5AM.js.map +0 -1
- package/dist/dist-WIK7F2PJ.js +0 -11
- package/dist/explain-PCZKDEM4.js +0 -102
- package/dist/explain-PCZKDEM4.js.map +0 -1
- package/dist/generate-OMEBJQFQ.js +0 -13
- package/dist/generate-OMEBJQFQ.js.map +0 -1
- package/dist/generate-story-AOALIKSD.js.map +0 -1
- package/dist/generate-test-plan-34L6RGOB.js.map +0 -1
- package/dist/graph-RR5UTY3R.js +0 -54
- package/dist/graph-RR5UTY3R.js.map +0 -1
- package/dist/lint-XGVQ6LCP.js.map +0 -1
- package/dist/mcp-GUFW37BE.js +0 -17
- package/dist/mcp-GUFW37BE.js.map +0 -1
- package/dist/migrate-KDJZQKP7.js.map +0 -1
- package/dist/pack-OJ3CDZHD.js.map +0 -1
- package/dist/ready-WTNO5W7C.js +0 -165
- package/dist/ready-WTNO5W7C.js.map +0 -1
- package/dist/skills-3GBBWZW2.js +0 -93
- package/dist/skills-3GBBWZW2.js.map +0 -1
- package/dist/status-JVIXK73H.js.map +0 -1
- package/dist/update-HFLDULNJ.js.map +0 -1
- package/dist/validate-O7W5YLR6.js +0 -34
- package/dist/validate-O7W5YLR6.js.map +0 -1
- /package/dist/{dist-WIK7F2PJ.js.map → chunk-5WRI5ZAA.js.map} +0 -0
- /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
- /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
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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+(\
|
|
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
|
|
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
|
|
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[
|
|
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
|
-
|
|
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({
|
|
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
|
|
343
|
-
const
|
|
344
|
-
|
|
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
|
|
635
|
-
const
|
|
636
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -789,7 +919,11 @@ function matchTypes(specTypes, codeTypes, specId) {
|
|
|
789
919
|
specSection: "Data Models",
|
|
790
920
|
expected: `Type: ${specType.name}`,
|
|
791
921
|
severity: "error",
|
|
792
|
-
suggestion: `Implement type "${specType.name}" in code
|
|
922
|
+
suggestion: `Implement type "${specType.name}" in code`,
|
|
923
|
+
// The score's types denominator counts fields; an absent type must
|
|
924
|
+
// subtract all of its fields, not 1, or a project that implements
|
|
925
|
+
// nothing of an N-field model scores (N-1)/N.
|
|
926
|
+
weight: specType.fields.length
|
|
793
927
|
});
|
|
794
928
|
continue;
|
|
795
929
|
}
|
|
@@ -857,7 +991,10 @@ function matchTests(specCases, codeTests, specId) {
|
|
|
857
991
|
category: "test",
|
|
858
992
|
specId,
|
|
859
993
|
specSection: specCase.section,
|
|
860
|
-
expected
|
|
994
|
+
// `expected` keeps the case ID so the finding can be traced back to a
|
|
995
|
+
// line in the test plan; the suggestion is the test name to write, and
|
|
996
|
+
// the spec's own label is no part of that.
|
|
997
|
+
expected: specCase.id ? `${specCase.id}: ${specCase.description}` : specCase.description,
|
|
861
998
|
severity: "warn",
|
|
862
999
|
suggestion: `Add a test matching: "${specCase.description}"`
|
|
863
1000
|
});
|
|
@@ -866,18 +1003,143 @@ function matchTests(specCases, codeTests, specId) {
|
|
|
866
1003
|
return findings;
|
|
867
1004
|
}
|
|
868
1005
|
|
|
1006
|
+
// ../check/dist/artifacts.js
|
|
1007
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1008
|
+
import { join as join8 } from "path";
|
|
1009
|
+
var ENFORCED_STATUSES = /* @__PURE__ */ new Set(["approved"]);
|
|
1010
|
+
function artifactsEnforced(status) {
|
|
1011
|
+
return typeof status === "string" && ENFORCED_STATUSES.has(status);
|
|
1012
|
+
}
|
|
1013
|
+
function parseArtifacts(spec) {
|
|
1014
|
+
const raw = spec.frontmatter.artifacts;
|
|
1015
|
+
if (!Array.isArray(raw))
|
|
1016
|
+
return [];
|
|
1017
|
+
const out = [];
|
|
1018
|
+
for (const item of raw) {
|
|
1019
|
+
if (!item || typeof item !== "object")
|
|
1020
|
+
continue;
|
|
1021
|
+
const decl = item;
|
|
1022
|
+
if (typeof decl.path !== "string" || decl.path.length === 0)
|
|
1023
|
+
continue;
|
|
1024
|
+
const exports = Array.isArray(decl.exports) ? decl.exports.filter((e) => typeof e === "string" && e.length > 0) : void 0;
|
|
1025
|
+
out.push({ path: decl.path, exports });
|
|
1026
|
+
}
|
|
1027
|
+
return out;
|
|
1028
|
+
}
|
|
1029
|
+
async function getExportedNames(filePath) {
|
|
1030
|
+
try {
|
|
1031
|
+
const { Project } = await import("ts-morph");
|
|
1032
|
+
const project = new Project({
|
|
1033
|
+
skipAddingFilesFromTsConfig: true,
|
|
1034
|
+
compilerOptions: { allowJs: true }
|
|
1035
|
+
});
|
|
1036
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
1037
|
+
return new Set(sourceFile.getExportedDeclarations().keys());
|
|
1038
|
+
} catch {
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
1043
|
+
const findings = [];
|
|
1044
|
+
const notes = [];
|
|
1045
|
+
let total = 0;
|
|
1046
|
+
let pending = 0;
|
|
1047
|
+
let skippedExports = 0;
|
|
1048
|
+
for (const spec of specs) {
|
|
1049
|
+
const specId = String(spec.frontmatter.id);
|
|
1050
|
+
const status = spec.frontmatter.status;
|
|
1051
|
+
const enforced = artifactsEnforced(status);
|
|
1052
|
+
for (const artifact of parseArtifacts(spec)) {
|
|
1053
|
+
const absolute = join8(projectDir, artifact.path);
|
|
1054
|
+
if (!existsSync7(absolute)) {
|
|
1055
|
+
if (enforced) {
|
|
1056
|
+
total += 1;
|
|
1057
|
+
findings.push({
|
|
1058
|
+
type: "missing",
|
|
1059
|
+
category: "artifact",
|
|
1060
|
+
specId,
|
|
1061
|
+
expected: `file "${artifact.path}"`,
|
|
1062
|
+
severity: "error",
|
|
1063
|
+
suggestion: `Create ${artifact.path} or update the artifacts list in ${specId}.`
|
|
1064
|
+
});
|
|
1065
|
+
} else {
|
|
1066
|
+
pending += 1;
|
|
1067
|
+
findings.push({
|
|
1068
|
+
type: "pending",
|
|
1069
|
+
category: "artifact",
|
|
1070
|
+
specId,
|
|
1071
|
+
expected: `file "${artifact.path}"`,
|
|
1072
|
+
severity: "info",
|
|
1073
|
+
suggestion: `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
total += 1;
|
|
1079
|
+
if (!artifact.exports || artifact.exports.length === 0)
|
|
1080
|
+
continue;
|
|
1081
|
+
if (!tsMorphAvailable) {
|
|
1082
|
+
skippedExports += artifact.exports.length;
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
const exported = await getExportedNames(absolute);
|
|
1086
|
+
if (exported === null) {
|
|
1087
|
+
skippedExports += artifact.exports.length;
|
|
1088
|
+
continue;
|
|
1089
|
+
}
|
|
1090
|
+
for (const name of artifact.exports) {
|
|
1091
|
+
if (exported.has(name)) {
|
|
1092
|
+
total += 1;
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
if (enforced) {
|
|
1096
|
+
total += 1;
|
|
1097
|
+
findings.push({
|
|
1098
|
+
type: "missing",
|
|
1099
|
+
category: "artifact",
|
|
1100
|
+
specId,
|
|
1101
|
+
codeLocation: { file: artifact.path, line: 1 },
|
|
1102
|
+
expected: `export "${name}" from ${artifact.path}`,
|
|
1103
|
+
severity: "error",
|
|
1104
|
+
suggestion: `Export ${name} from ${artifact.path} or update the artifacts list in ${specId}.`
|
|
1105
|
+
});
|
|
1106
|
+
} else {
|
|
1107
|
+
pending += 1;
|
|
1108
|
+
findings.push({
|
|
1109
|
+
type: "pending",
|
|
1110
|
+
category: "artifact",
|
|
1111
|
+
specId,
|
|
1112
|
+
codeLocation: { file: artifact.path, line: 1 },
|
|
1113
|
+
expected: `export "${name}" from ${artifact.path}`,
|
|
1114
|
+
severity: "info",
|
|
1115
|
+
suggestion: `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
if (skippedExports > 0) {
|
|
1122
|
+
notes.push(`artifact export checks skipped for ${skippedExports} export(s): ts-morph is not available or the file could not be parsed.`);
|
|
1123
|
+
}
|
|
1124
|
+
if (pending > 0) {
|
|
1125
|
+
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.`);
|
|
1126
|
+
}
|
|
1127
|
+
return { findings, total, checked: total, pending, notes };
|
|
1128
|
+
}
|
|
1129
|
+
|
|
869
1130
|
// ../check/dist/score.js
|
|
870
1131
|
function computeScore(findings, totals) {
|
|
871
|
-
const missingByCategory = { route: 0, type: 0, test: 0 };
|
|
1132
|
+
const missingByCategory = { route: 0, type: 0, test: 0, artifact: 0 };
|
|
872
1133
|
for (const f of findings) {
|
|
873
1134
|
if (f.type === "missing" || f.type === "mismatch") {
|
|
874
|
-
missingByCategory[f.category] = (missingByCategory[f.category] ?? 0) + 1;
|
|
1135
|
+
missingByCategory[f.category] = (missingByCategory[f.category] ?? 0) + (f.weight ?? 1);
|
|
875
1136
|
}
|
|
876
1137
|
}
|
|
877
1138
|
const categoryMap = {
|
|
878
1139
|
routes: { total: totals.routes, categoryKey: "route" },
|
|
879
1140
|
types: { total: totals.types, categoryKey: "type" },
|
|
880
|
-
tests: { total: totals.tests, categoryKey: "test" }
|
|
1141
|
+
tests: { total: totals.tests, categoryKey: "test" },
|
|
1142
|
+
artifacts: { total: totals.artifacts, categoryKey: "artifact" }
|
|
881
1143
|
};
|
|
882
1144
|
const byCategory = {};
|
|
883
1145
|
let totalItems = 0;
|
|
@@ -889,13 +1151,16 @@ function computeScore(findings, totals) {
|
|
|
889
1151
|
totalItems += total;
|
|
890
1152
|
totalMatched += matched;
|
|
891
1153
|
}
|
|
892
|
-
|
|
893
|
-
|
|
1154
|
+
if (totalItems === 0) {
|
|
1155
|
+
return { overall: 0, assessed: false, byCategory };
|
|
1156
|
+
}
|
|
1157
|
+
const overall = Math.round(totalMatched / totalItems * 100);
|
|
1158
|
+
return { overall, assessed: true, byCategory };
|
|
894
1159
|
}
|
|
895
1160
|
|
|
896
1161
|
// ../check/dist/detect-framework.js
|
|
897
1162
|
import { readFile as readFile2 } from "fs/promises";
|
|
898
|
-
import { join as
|
|
1163
|
+
import { join as join9 } from "path";
|
|
899
1164
|
var FRAMEWORK_PACKAGES = [
|
|
900
1165
|
["express", "express"],
|
|
901
1166
|
["hono", "hono"],
|
|
@@ -904,7 +1169,7 @@ var FRAMEWORK_PACKAGES = [
|
|
|
904
1169
|
async function detectFramework(projectDir) {
|
|
905
1170
|
let pkg;
|
|
906
1171
|
try {
|
|
907
|
-
const content = await readFile2(
|
|
1172
|
+
const content = await readFile2(join9(projectDir, "package.json"), "utf-8");
|
|
908
1173
|
pkg = JSON.parse(content);
|
|
909
1174
|
} catch {
|
|
910
1175
|
return null;
|
|
@@ -919,50 +1184,103 @@ async function detectFramework(projectDir) {
|
|
|
919
1184
|
}
|
|
920
1185
|
|
|
921
1186
|
// ../check/dist/check.js
|
|
1187
|
+
async function usesPrisma(projectDir) {
|
|
1188
|
+
try {
|
|
1189
|
+
const pkg = JSON.parse(await readFile3(join10(projectDir, "package.json"), "utf-8"));
|
|
1190
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
1191
|
+
return "prisma" in deps || "@prisma/client" in deps;
|
|
1192
|
+
} catch {
|
|
1193
|
+
return false;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
922
1196
|
async function runCheck(specs, projectDir, config = {}) {
|
|
923
1197
|
const findings = [];
|
|
1198
|
+
const notes = [];
|
|
924
1199
|
let routeTotal = 0;
|
|
925
1200
|
let typeTotal = 0;
|
|
926
1201
|
let testTotal = 0;
|
|
1202
|
+
let codeRouteCount = null;
|
|
1203
|
+
let codeTypeCount = null;
|
|
1204
|
+
let codeTestCount = null;
|
|
1205
|
+
const tsMorphAvailable = await import("ts-morph").then(() => true, () => false);
|
|
1206
|
+
if (!tsMorphAvailable) {
|
|
1207
|
+
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.");
|
|
1208
|
+
}
|
|
1209
|
+
const framework = config.framework && config.framework !== "auto" ? config.framework : await detectFramework(projectDir);
|
|
927
1210
|
const apiContractSpecs = specs.filter((s) => s.frontmatter.type === "api-contract");
|
|
928
|
-
if (apiContractSpecs.length > 0) {
|
|
929
|
-
const codeRoutes = await extractRoutes(projectDir, config);
|
|
1211
|
+
if (apiContractSpecs.length > 0 && tsMorphAvailable) {
|
|
1212
|
+
const codeRoutes = await extractRoutes(projectDir, config, framework);
|
|
1213
|
+
codeRouteCount = codeRoutes.length;
|
|
930
1214
|
for (const spec of apiContractSpecs) {
|
|
931
1215
|
const specEndpoints = parseEndpoints(spec.content);
|
|
932
1216
|
routeTotal += specEndpoints.length;
|
|
933
1217
|
findings.push(...matchRoutes(specEndpoints, codeRoutes, spec.frontmatter.id));
|
|
1218
|
+
if (specEndpoints.length === 0 && hasEndpointsSection(spec.content)) {
|
|
1219
|
+
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.`);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (framework === null) {
|
|
1223
|
+
notes.push("no supported framework detected (express, hono, nextjs) \u2014 route extraction ran in fallback mode across all extractors.");
|
|
934
1224
|
}
|
|
935
1225
|
}
|
|
936
1226
|
const designSpecs = specs.filter((s) => s.frontmatter.type === "technical-design");
|
|
937
|
-
|
|
1227
|
+
const prismaSchemaFound = (await findPrismaSchemas(projectDir)).length > 0;
|
|
1228
|
+
if (designSpecs.length > 0 && (tsMorphAvailable || prismaSchemaFound)) {
|
|
938
1229
|
const codeTypes = [
|
|
939
|
-
...await extractTypeScriptTypes(projectDir, config.types_dir),
|
|
940
|
-
...await extractZodSchemas(projectDir, config.types_dir),
|
|
1230
|
+
...tsMorphAvailable ? await extractTypeScriptTypes(projectDir, config.types_dir) : [],
|
|
1231
|
+
...tsMorphAvailable ? await extractZodSchemas(projectDir, config.types_dir) : [],
|
|
941
1232
|
...await extractPrismaModels(projectDir)
|
|
942
1233
|
];
|
|
1234
|
+
codeTypeCount = codeTypes.length;
|
|
1235
|
+
if (await usesPrisma(projectDir) && !prismaSchemaFound) {
|
|
1236
|
+
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.");
|
|
1237
|
+
}
|
|
943
1238
|
for (const spec of designSpecs) {
|
|
944
1239
|
const specTypes = parseTypeDefinitions(spec.content);
|
|
945
|
-
|
|
1240
|
+
const fieldCount = specTypes.reduce((sum, t) => sum + t.fields.length, 0);
|
|
1241
|
+
typeTotal += fieldCount;
|
|
946
1242
|
findings.push(...matchTypes(specTypes, codeTypes, spec.frontmatter.id));
|
|
1243
|
+
if (fieldCount === 0 && /^##\s+Data Model\s*$/im.test(spec.content)) {
|
|
1244
|
+
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).`);
|
|
1245
|
+
}
|
|
1246
|
+
for (const name of unreadableTypeBlocks(spec.content)) {
|
|
1247
|
+
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\`.`);
|
|
1248
|
+
}
|
|
947
1249
|
}
|
|
948
1250
|
}
|
|
949
1251
|
const testPlanSpecs = specs.filter((s) => s.frontmatter.type === "test-plan");
|
|
950
|
-
if (testPlanSpecs.length > 0) {
|
|
1252
|
+
if (testPlanSpecs.length > 0 && tsMorphAvailable) {
|
|
951
1253
|
const codeTests = await extractTestDescriptions(projectDir, config.tests_dir);
|
|
1254
|
+
codeTestCount = codeTests.length;
|
|
952
1255
|
for (const spec of testPlanSpecs) {
|
|
953
1256
|
const specCases = parseTestCases(spec.content);
|
|
954
1257
|
testTotal += specCases.length;
|
|
955
1258
|
findings.push(...matchTests(specCases, codeTests, spec.frontmatter.id));
|
|
956
1259
|
}
|
|
957
1260
|
}
|
|
958
|
-
const
|
|
1261
|
+
const artifactResult = await checkArtifacts(specs, projectDir, tsMorphAvailable);
|
|
1262
|
+
findings.push(...artifactResult.findings);
|
|
1263
|
+
notes.push(...artifactResult.notes);
|
|
1264
|
+
const score = computeScore(findings, {
|
|
1265
|
+
routes: routeTotal,
|
|
1266
|
+
types: typeTotal,
|
|
1267
|
+
tests: testTotal,
|
|
1268
|
+
artifacts: artifactResult.total
|
|
1269
|
+
});
|
|
959
1270
|
const errors = findings.filter((f) => f.severity === "error").length;
|
|
960
1271
|
const warnings = findings.filter((f) => f.severity === "warn").length;
|
|
961
|
-
const summary = `${score.overall}% implementation coverage \u2014 ${errors} errors, ${warnings} warnings
|
|
962
|
-
|
|
1272
|
+
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)";
|
|
1273
|
+
const scanned = {
|
|
1274
|
+
framework: framework ?? null,
|
|
1275
|
+
codeRoutes: codeRouteCount,
|
|
1276
|
+
codeTypes: codeTypeCount,
|
|
1277
|
+
codeTests: codeTestCount,
|
|
1278
|
+
artifacts: artifactResult.total > 0 ? artifactResult.checked : null,
|
|
1279
|
+
artifactsPending: artifactResult.pending
|
|
1280
|
+
};
|
|
1281
|
+
return { findings, score, summary, scanned, notes };
|
|
963
1282
|
}
|
|
964
|
-
async function extractRoutes(projectDir, config) {
|
|
965
|
-
const framework = config.framework ?? "auto";
|
|
1283
|
+
async function extractRoutes(projectDir, config, framework) {
|
|
966
1284
|
if (framework === "express") {
|
|
967
1285
|
return extractExpressRoutes(projectDir, config.routes_dir);
|
|
968
1286
|
}
|
|
@@ -972,16 +1290,6 @@ async function extractRoutes(projectDir, config) {
|
|
|
972
1290
|
if (framework === "nextjs") {
|
|
973
1291
|
return extractNextjsRoutes(projectDir, config.app_dir);
|
|
974
1292
|
}
|
|
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
1293
|
const [express, hono, nextjs] = await Promise.all([
|
|
986
1294
|
extractExpressRoutes(projectDir, config.routes_dir),
|
|
987
1295
|
extractHonoRoutes(projectDir, config.routes_dir),
|
|
@@ -994,7 +1302,7 @@ async function extractRoutes(projectDir, config) {
|
|
|
994
1302
|
async function analyzeWithAi(findings, context) {
|
|
995
1303
|
const apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
996
1304
|
if (!apiKey) {
|
|
997
|
-
throw new Error("ANTHROPIC_API_KEY environment variable is required for --ai mode. Set it or use the
|
|
1305
|
+
throw new Error("ANTHROPIC_API_KEY environment variable is required for --ai mode. Set it or use the specdx-verify skill instead (no API key needed).");
|
|
998
1306
|
}
|
|
999
1307
|
if (findings.length === 0) {
|
|
1000
1308
|
return { findings, assessments: [], summary: "No findings to analyze." };
|
|
@@ -1044,8 +1352,10 @@ Only output the JSON array, no other text.`;
|
|
|
1044
1352
|
}
|
|
1045
1353
|
|
|
1046
1354
|
export {
|
|
1355
|
+
parseArtifacts,
|
|
1356
|
+
checkArtifacts,
|
|
1047
1357
|
detectFramework,
|
|
1048
1358
|
runCheck,
|
|
1049
1359
|
analyzeWithAi
|
|
1050
1360
|
};
|
|
1051
|
-
//# sourceMappingURL=chunk-
|
|
1361
|
+
//# sourceMappingURL=chunk-3YXRWQGX.js.map
|