specdx 0.5.0 → 0.6.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.
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +31 -15
- package/dist/{check-RH5SCXWW.js → check-5EA2MTNN.js} +120 -26
- package/dist/check-5EA2MTNN.js.map +1 -0
- package/dist/{chunk-3YXRWQGX.js → chunk-2UUQJ2ER.js} +242 -53
- package/dist/chunk-2UUQJ2ER.js.map +1 -0
- package/dist/{chunk-6WFNZH7F.js → chunk-5XOWCPP2.js} +2 -2
- package/dist/{chunk-6EQIDZ4D.js → chunk-BZL2XXMA.js} +13 -13
- package/dist/{chunk-BP3SB35W.js → chunk-JGD3BOPH.js} +15 -5
- package/dist/chunk-JGD3BOPH.js.map +1 -0
- package/dist/{chunk-BMOOLUPG.js → chunk-MOYYF7Q6.js} +2 -2
- package/dist/{chunk-CQETLJTZ.js → chunk-QAJZCJUJ.js} +4 -3
- package/dist/chunk-QAJZCJUJ.js.map +1 -0
- package/dist/{chunk-ZIODMXST.js → chunk-VVZUJ6H4.js} +52 -14
- package/dist/{chunk-ZIODMXST.js.map → chunk-VVZUJ6H4.js.map} +1 -1
- package/dist/{diff-QO7HMAK3.js → diff-ZT6HXHK5.js} +3 -3
- package/dist/dist-6WDWUOCV.js +26 -0
- package/dist/{dist-JPWHWMV2.js → dist-A3CWALDC.js} +30 -9
- package/dist/dist-A3CWALDC.js.map +1 -0
- package/dist/{generate-MS4BM7RU.js → generate-M6YKXUDE.js} +4 -4
- package/dist/{generate-story-OMM322L7.js → generate-story-BXGNKWC6.js} +3 -3
- package/dist/{generate-test-plan-75W7SZIO.js → generate-test-plan-PZUNCNN3.js} +2 -2
- package/dist/{graph-QOTMXENE.js → graph-GKXD2IGW.js} +2 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +109 -22
- package/dist/index.js.map +1 -1
- package/dist/{lint-LPFLHVO4.js → lint-GZX5C5EQ.js} +55 -10
- package/dist/lint-GZX5C5EQ.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{mcp-OEC43SPF.js → mcp-VQAYNJQ7.js} +3 -3
- package/dist/{migrate-CBP2AVLH.js → migrate-VASWPA3L.js} +2 -2
- package/dist/{pack-X6FSWORJ.js → pack-DFUCNWVR.js} +3 -3
- package/dist/{ready-7MJWRGLT.js → ready-5OFSV2OD.js} +4 -4
- package/dist/{status-UUPZYX3J.js → status-5MDODW4N.js} +4 -4
- package/dist/{update-EI7IJRHG.js → update-NFXC45UT.js} +3 -3
- package/dist/{validate-HTTZLQWI.js → validate-LWRLZR3H.js} +2 -2
- package/package.json +6 -5
- package/skills/core/specdx-author-spec/SKILL.md +33 -0
- package/skills/core/specdx-author-spec/references/spec-type-reference.md +57 -0
- package/skills/core/specdx-author-spec/references/step-01-frontmatter.md +66 -0
- package/skills/core/specdx-author-spec/references/step-02-sections.md +111 -0
- package/skills/core/specdx-author-spec/references/step-03-finalize.md +48 -0
- package/skills/core/specdx-onboard/SKILL.md +54 -0
- package/skills/core/specdx-plan-from-spec/SKILL.md +76 -0
- package/skills/core/specdx-pre-commit/SKILL.md +70 -0
- package/skills/core/specdx-review-spec/SKILL.md +81 -0
- package/skills/core/specdx-router/SKILL.md +67 -0
- package/skills/core/specdx-sprint-review/SKILL.md +73 -0
- package/skills/core/specdx-start-task/SKILL.md +62 -0
- package/skills/experimental/specdx-check-drift/SKILL.md +77 -0
- package/skills/experimental/specdx-verify/SKILL.md +85 -0
- package/dist/check-RH5SCXWW.js.map +0 -1
- package/dist/chunk-3YXRWQGX.js.map +0 -1
- package/dist/chunk-BP3SB35W.js.map +0 -1
- package/dist/chunk-CQETLJTZ.js.map +0 -1
- package/dist/dist-JPWHWMV2.js.map +0 -1
- package/dist/dist-ROHCFKYT.js +0 -16
- package/dist/lint-LPFLHVO4.js.map +0 -1
- /package/dist/{chunk-6WFNZH7F.js.map → chunk-5XOWCPP2.js.map} +0 -0
- /package/dist/{chunk-6EQIDZ4D.js.map → chunk-BZL2XXMA.js.map} +0 -0
- /package/dist/{chunk-BMOOLUPG.js.map → chunk-MOYYF7Q6.js.map} +0 -0
- /package/dist/{diff-QO7HMAK3.js.map → diff-ZT6HXHK5.js.map} +0 -0
- /package/dist/{dist-ROHCFKYT.js.map → dist-6WDWUOCV.js.map} +0 -0
- /package/dist/{generate-MS4BM7RU.js.map → generate-M6YKXUDE.js.map} +0 -0
- /package/dist/{generate-story-OMM322L7.js.map → generate-story-BXGNKWC6.js.map} +0 -0
- /package/dist/{generate-test-plan-75W7SZIO.js.map → generate-test-plan-PZUNCNN3.js.map} +0 -0
- /package/dist/{graph-QOTMXENE.js.map → graph-GKXD2IGW.js.map} +0 -0
- /package/dist/{mcp-OEC43SPF.js.map → mcp-VQAYNJQ7.js.map} +0 -0
- /package/dist/{migrate-CBP2AVLH.js.map → migrate-VASWPA3L.js.map} +0 -0
- /package/dist/{pack-X6FSWORJ.js.map → pack-DFUCNWVR.js.map} +0 -0
- /package/dist/{ready-7MJWRGLT.js.map → ready-5OFSV2OD.js.map} +0 -0
- /package/dist/{status-UUPZYX3J.js.map → status-5MDODW4N.js.map} +0 -0
- /package/dist/{update-EI7IJRHG.js.map → update-NFXC45UT.js.map} +0 -0
- /package/dist/{validate-HTTZLQWI.js.map → validate-LWRLZR3H.js.map} +0 -0
|
@@ -64,35 +64,98 @@ function parseEndpoints(content) {
|
|
|
64
64
|
}
|
|
65
65
|
return results;
|
|
66
66
|
}
|
|
67
|
-
var
|
|
67
|
+
var GROUP = "\xA7";
|
|
68
|
+
var TYPE_ATOM = `(?:[A-Za-z_$][\\w$.]*|-?\\d+(?:\\.\\d+)?|${GROUP})${GROUP}*`;
|
|
69
|
+
var TYPE_SHAPE = new RegExp(`^${TYPE_ATOM}(?:\\s*(?:[|&]|=>)\\s*${TYPE_ATOM})*$`);
|
|
70
|
+
function collapseGroups(type) {
|
|
71
|
+
let collapsed = type.replace(/"[^"]*"|'[^']*'|`[^`]*`/g, GROUP);
|
|
72
|
+
let previous = "";
|
|
73
|
+
while (collapsed !== previous) {
|
|
74
|
+
previous = collapsed;
|
|
75
|
+
collapsed = collapsed.replace(/<[^<>]*>|\{[^{}]*\}|\([^()]*\)|\[[^[\]]*\]/g, GROUP);
|
|
76
|
+
}
|
|
77
|
+
return collapsed;
|
|
78
|
+
}
|
|
79
|
+
function looksLikeType(type) {
|
|
80
|
+
return type.length > 0 && TYPE_SHAPE.test(collapseGroups(type));
|
|
81
|
+
}
|
|
82
|
+
function descriptionStart(raw) {
|
|
83
|
+
let depth = 0;
|
|
84
|
+
let quote = null;
|
|
85
|
+
for (let i = 0; i < raw.length; i++) {
|
|
86
|
+
const ch = raw[i];
|
|
87
|
+
if (quote !== null) {
|
|
88
|
+
if (ch === quote)
|
|
89
|
+
quote = null;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
93
|
+
quote = ch;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (ch === "(" || ch === "[" || ch === "{" || ch === "<") {
|
|
97
|
+
depth += 1;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (ch === ")" || ch === "]" || ch === "}" || ch === ">") {
|
|
101
|
+
depth = Math.max(0, depth - 1);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (depth > 0 || !/\s/.test(ch))
|
|
105
|
+
continue;
|
|
106
|
+
if (/^\s+(?:—|–|-{1,2})\s+/.test(raw.slice(i)))
|
|
107
|
+
return i;
|
|
108
|
+
}
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
function normaliseFieldType(raw) {
|
|
112
|
+
const cut = descriptionStart(raw);
|
|
113
|
+
const type = (cut === -1 ? raw : raw.slice(0, cut)).trim();
|
|
114
|
+
const withoutNote = type.replace(/\s*\(.*?\)\s*$/, "").trim();
|
|
115
|
+
return withoutNote.length > 0 ? withoutNote : type;
|
|
116
|
+
}
|
|
68
117
|
var TYPE_NAME_SHAPE = /^[A-Za-z_$][\w$]*(?:<[\w$,\s[\]]+>)?$/;
|
|
118
|
+
var FIELD_LINE = /^[ \t]*[-*+]\s+(?:`([^`]+)`|([A-Za-z_$][\w$]*\??))\s*:\s*(.+)$/;
|
|
119
|
+
function parseFieldLine(line) {
|
|
120
|
+
const match = FIELD_LINE.exec(line);
|
|
121
|
+
if (!match)
|
|
122
|
+
return null;
|
|
123
|
+
const backticked = match[1] !== void 0;
|
|
124
|
+
const rawName = match[1] ?? match[2];
|
|
125
|
+
const optional = rawName.endsWith("?");
|
|
126
|
+
const type = normaliseFieldType(match[3]);
|
|
127
|
+
if (type.length === 0)
|
|
128
|
+
return null;
|
|
129
|
+
if (!backticked && !looksLikeType(type))
|
|
130
|
+
return null;
|
|
131
|
+
return { name: optional ? rawName.slice(0, -1) : rawName, type, optional };
|
|
132
|
+
}
|
|
133
|
+
function typeHeading(block) {
|
|
134
|
+
const headingMatch = /^###\s+(.+?)\s*$/m.exec(block);
|
|
135
|
+
if (!headingMatch)
|
|
136
|
+
return null;
|
|
137
|
+
const name = headingMatch[1].trim().replace(/^`|`$/g, "");
|
|
138
|
+
return TYPE_NAME_SHAPE.test(name) ? name : null;
|
|
139
|
+
}
|
|
140
|
+
function parseFieldBullets(block) {
|
|
141
|
+
const fields = [];
|
|
142
|
+
for (const line of block.split("\n")) {
|
|
143
|
+
const field = parseFieldLine(line);
|
|
144
|
+
if (field)
|
|
145
|
+
fields.push(field);
|
|
146
|
+
}
|
|
147
|
+
return fields;
|
|
148
|
+
}
|
|
69
149
|
function parseTypeDefinitions(content) {
|
|
70
150
|
const section = extractSection(content, "Data Model");
|
|
71
151
|
if (!section)
|
|
72
152
|
return [];
|
|
73
153
|
const results = [];
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (!headingMatch)
|
|
78
|
-
continue;
|
|
79
|
-
const name = headingMatch[1].trim().replace(/^`|`$/g, "");
|
|
80
|
-
if (!TYPE_NAME_SHAPE.test(name))
|
|
154
|
+
for (const block of section.split(/^(?=###\s)/m)) {
|
|
155
|
+
const name = typeHeading(block);
|
|
156
|
+
if (name === null)
|
|
81
157
|
continue;
|
|
82
|
-
const fields =
|
|
83
|
-
const fieldPattern = /^-\s+(?:`([^`]+)`|([A-Za-z_$][\w$]*\??))\s*:\s*(.+)/gm;
|
|
84
|
-
let fieldMatch;
|
|
85
|
-
while ((fieldMatch = fieldPattern.exec(block)) !== null) {
|
|
86
|
-
const backticked = fieldMatch[1] !== void 0;
|
|
87
|
-
const rawName = fieldMatch[1] ?? fieldMatch[2];
|
|
88
|
-
const optional = rawName.endsWith("?");
|
|
89
|
-
const fieldName = optional ? rawName.slice(0, -1) : rawName;
|
|
90
|
-
const rawType = fieldMatch[3].trim();
|
|
91
|
-
const type = rawType.replace(/\s*\(.*?\)\s*$/, "").trim();
|
|
92
|
-
if (!backticked && !TYPE_SHAPE.test(type))
|
|
93
|
-
continue;
|
|
94
|
-
fields.push({ name: fieldName, type, optional });
|
|
95
|
-
}
|
|
158
|
+
const fields = parseFieldBullets(block);
|
|
96
159
|
if (fields.length === 0)
|
|
97
160
|
fields.push(...parseFieldTable(block));
|
|
98
161
|
if (fields.length === 0)
|
|
@@ -134,7 +197,7 @@ function parseFieldTable(block) {
|
|
|
134
197
|
const name = optional ? rawName.slice(0, -1) : rawName;
|
|
135
198
|
if (!/^[A-Za-z_$][\w$]*$/.test(name))
|
|
136
199
|
continue;
|
|
137
|
-
fields.push({ name, type: rawType
|
|
200
|
+
fields.push({ name, type: normaliseFieldType(rawType), optional });
|
|
138
201
|
}
|
|
139
202
|
return fields;
|
|
140
203
|
}
|
|
@@ -144,11 +207,8 @@ function unreadableTypeBlocks(content) {
|
|
|
144
207
|
return [];
|
|
145
208
|
const unreadable = [];
|
|
146
209
|
for (const block of section.split(/^(?=###\s)/m)) {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
continue;
|
|
150
|
-
const name = headingMatch[1].trim().replace(/^`|`$/g, "");
|
|
151
|
-
if (!TYPE_NAME_SHAPE.test(name))
|
|
210
|
+
const name = typeHeading(block);
|
|
211
|
+
if (name === null)
|
|
152
212
|
continue;
|
|
153
213
|
const hasTable = block.split("\n").some((line) => tableCells(line) !== null);
|
|
154
214
|
if (!hasTable)
|
|
@@ -161,6 +221,21 @@ ${block}`);
|
|
|
161
221
|
}
|
|
162
222
|
return unreadable;
|
|
163
223
|
}
|
|
224
|
+
function unattachedFieldLines(content) {
|
|
225
|
+
const section = extractSection(content, "Data Model");
|
|
226
|
+
if (!section)
|
|
227
|
+
return [];
|
|
228
|
+
const unattached = [];
|
|
229
|
+
for (const block of section.split(/^(?=###\s)/m)) {
|
|
230
|
+
if (typeHeading(block) !== null)
|
|
231
|
+
continue;
|
|
232
|
+
for (const line of block.split("\n")) {
|
|
233
|
+
if (parseFieldLine(line) !== null)
|
|
234
|
+
unattached.push(line.trim());
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return unattached;
|
|
238
|
+
}
|
|
164
239
|
function parseTestCases(content) {
|
|
165
240
|
const section = extractSection(content, "Test Cases");
|
|
166
241
|
if (!section)
|
|
@@ -891,6 +966,15 @@ function matchRoutes(specEndpoints, codeRoutes, specId) {
|
|
|
891
966
|
return findings;
|
|
892
967
|
}
|
|
893
968
|
|
|
969
|
+
// ../check/dist/status.js
|
|
970
|
+
var ENFORCED_STATUSES = /* @__PURE__ */ new Set(["approved"]);
|
|
971
|
+
function enforcedByStatus(status) {
|
|
972
|
+
return typeof status === "string" && ENFORCED_STATUSES.has(status);
|
|
973
|
+
}
|
|
974
|
+
function plannedSuggestion(specId, status) {
|
|
975
|
+
return `planned by ${specId} (status: ${String(status)}) \u2014 not yet implemented; enforced once the spec is approved.`;
|
|
976
|
+
}
|
|
977
|
+
|
|
894
978
|
// ../check/dist/matchers/types.js
|
|
895
979
|
var STRIP_SUFFIXES = ["Schema", "Model", "Type", "Interface", "Entity"];
|
|
896
980
|
function normaliseTypeName(name) {
|
|
@@ -907,22 +991,24 @@ function findMatchingCodeType(specType, codeTypes) {
|
|
|
907
991
|
const specNorm = normaliseTypeName(specType.name);
|
|
908
992
|
return codeTypes.find((ct) => normaliseTypeName(ct.name) === specNorm);
|
|
909
993
|
}
|
|
910
|
-
function matchTypes(specTypes, codeTypes, specId) {
|
|
994
|
+
function matchTypes(specTypes, codeTypes, specId, options = {}) {
|
|
911
995
|
const findings = [];
|
|
996
|
+
const enforced = "status" in options ? enforcedByStatus(options.status) : true;
|
|
912
997
|
for (const specType of specTypes) {
|
|
913
998
|
const codeType = findMatchingCodeType(specType, codeTypes);
|
|
914
999
|
if (!codeType) {
|
|
915
1000
|
findings.push({
|
|
916
|
-
type: "missing",
|
|
1001
|
+
type: enforced ? "missing" : "pending",
|
|
917
1002
|
category: "type",
|
|
918
1003
|
specId,
|
|
919
1004
|
specSection: "Data Models",
|
|
920
1005
|
expected: `Type: ${specType.name}`,
|
|
921
|
-
severity: "error",
|
|
922
|
-
suggestion: `Implement type "${specType.name}" in code
|
|
1006
|
+
severity: enforced ? "error" : "info",
|
|
1007
|
+
suggestion: enforced ? `Implement type "${specType.name}" in code` : plannedSuggestion(specId, options.status),
|
|
923
1008
|
// The score's types denominator counts fields; an absent type must
|
|
924
1009
|
// subtract all of its fields, not 1, or a project that implements
|
|
925
|
-
// nothing of an N-field model scores (N-1)/N.
|
|
1010
|
+
// nothing of an N-field model scores (N-1)/N. A pending type carries
|
|
1011
|
+
// the same weight so its fields can leave the denominator entirely.
|
|
926
1012
|
weight: specType.fields.length
|
|
927
1013
|
});
|
|
928
1014
|
continue;
|
|
@@ -1006,10 +1092,6 @@ function matchTests(specCases, codeTests, specId) {
|
|
|
1006
1092
|
// ../check/dist/artifacts.js
|
|
1007
1093
|
import { existsSync as existsSync7 } from "fs";
|
|
1008
1094
|
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
1095
|
function parseArtifacts(spec) {
|
|
1014
1096
|
const raw = spec.frontmatter.artifacts;
|
|
1015
1097
|
if (!Array.isArray(raw))
|
|
@@ -1048,7 +1130,7 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
1048
1130
|
for (const spec of specs) {
|
|
1049
1131
|
const specId = String(spec.frontmatter.id);
|
|
1050
1132
|
const status = spec.frontmatter.status;
|
|
1051
|
-
const enforced =
|
|
1133
|
+
const enforced = enforcedByStatus(status);
|
|
1052
1134
|
for (const artifact of parseArtifacts(spec)) {
|
|
1053
1135
|
const absolute = join8(projectDir, artifact.path);
|
|
1054
1136
|
if (!existsSync7(absolute)) {
|
|
@@ -1070,7 +1152,7 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
1070
1152
|
specId,
|
|
1071
1153
|
expected: `file "${artifact.path}"`,
|
|
1072
1154
|
severity: "info",
|
|
1073
|
-
suggestion:
|
|
1155
|
+
suggestion: plannedSuggestion(specId, status)
|
|
1074
1156
|
});
|
|
1075
1157
|
}
|
|
1076
1158
|
continue;
|
|
@@ -1112,7 +1194,7 @@ async function checkArtifacts(specs, projectDir, tsMorphAvailable) {
|
|
|
1112
1194
|
codeLocation: { file: artifact.path, line: 1 },
|
|
1113
1195
|
expected: `export "${name}" from ${artifact.path}`,
|
|
1114
1196
|
severity: "info",
|
|
1115
|
-
suggestion:
|
|
1197
|
+
suggestion: plannedSuggestion(specId, status)
|
|
1116
1198
|
});
|
|
1117
1199
|
}
|
|
1118
1200
|
}
|
|
@@ -1148,6 +1230,8 @@ function computeScore(findings, totals) {
|
|
|
1148
1230
|
const missing = missingByCategory[categoryKey] ?? 0;
|
|
1149
1231
|
const matched = Math.max(0, total - missing);
|
|
1150
1232
|
byCategory[name] = { matched, total };
|
|
1233
|
+
if (name === "tests")
|
|
1234
|
+
continue;
|
|
1151
1235
|
totalItems += total;
|
|
1152
1236
|
totalMatched += matched;
|
|
1153
1237
|
}
|
|
@@ -1196,30 +1280,40 @@ async function usesPrisma(projectDir) {
|
|
|
1196
1280
|
async function runCheck(specs, projectDir, config = {}) {
|
|
1197
1281
|
const findings = [];
|
|
1198
1282
|
const notes = [];
|
|
1283
|
+
const unassessed = [];
|
|
1284
|
+
const noteUnassessed = (message) => {
|
|
1285
|
+
notes.push(message);
|
|
1286
|
+
unassessed.push(message);
|
|
1287
|
+
};
|
|
1199
1288
|
let routeTotal = 0;
|
|
1200
1289
|
let typeTotal = 0;
|
|
1201
1290
|
let testTotal = 0;
|
|
1291
|
+
let typesPending = 0;
|
|
1202
1292
|
let codeRouteCount = null;
|
|
1203
1293
|
let codeTypeCount = null;
|
|
1204
1294
|
let codeTestCount = null;
|
|
1205
1295
|
const tsMorphAvailable = await import("ts-morph").then(() => true, () => false);
|
|
1206
1296
|
if (!tsMorphAvailable) {
|
|
1207
|
-
|
|
1297
|
+
noteUnassessed("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
1298
|
}
|
|
1209
1299
|
const framework = config.framework && config.framework !== "auto" ? config.framework : await detectFramework(projectDir);
|
|
1210
1300
|
const apiContractSpecs = specs.filter((s) => s.frontmatter.type === "api-contract");
|
|
1211
1301
|
if (apiContractSpecs.length > 0 && tsMorphAvailable) {
|
|
1212
1302
|
const codeRoutes = await extractRoutes(projectDir, config, framework);
|
|
1213
1303
|
codeRouteCount = codeRoutes.length;
|
|
1214
|
-
|
|
1304
|
+
const unreadableStack = framework === null && codeRoutes.length === 0;
|
|
1305
|
+
if (unreadableStack) {
|
|
1306
|
+
noteUnassessed("no supported framework detected (express, hono, nextjs) and no routes were readable, so routes were not assessed. Set check.framework in spec.config.yaml, or pass --framework, if this project does use one of them.");
|
|
1307
|
+
}
|
|
1308
|
+
for (const spec of unreadableStack ? [] : apiContractSpecs) {
|
|
1215
1309
|
const specEndpoints = parseEndpoints(spec.content);
|
|
1216
1310
|
routeTotal += specEndpoints.length;
|
|
1217
1311
|
findings.push(...matchRoutes(specEndpoints, codeRoutes, spec.frontmatter.id));
|
|
1218
1312
|
if (specEndpoints.length === 0 && hasEndpointsSection(spec.content)) {
|
|
1219
|
-
|
|
1313
|
+
noteUnassessed(`${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
1314
|
}
|
|
1221
1315
|
}
|
|
1222
|
-
if (framework === null) {
|
|
1316
|
+
if (framework === null && !unreadableStack) {
|
|
1223
1317
|
notes.push("no supported framework detected (express, hono, nextjs) \u2014 route extraction ran in fallback mode across all extractors.");
|
|
1224
1318
|
}
|
|
1225
1319
|
}
|
|
@@ -1233,20 +1327,30 @@ async function runCheck(specs, projectDir, config = {}) {
|
|
|
1233
1327
|
];
|
|
1234
1328
|
codeTypeCount = codeTypes.length;
|
|
1235
1329
|
if (await usesPrisma(projectDir) && !prismaSchemaFound) {
|
|
1236
|
-
|
|
1330
|
+
noteUnassessed("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
1331
|
}
|
|
1238
1332
|
for (const spec of designSpecs) {
|
|
1333
|
+
const specId = spec.frontmatter.id;
|
|
1239
1334
|
const specTypes = parseTypeDefinitions(spec.content);
|
|
1240
1335
|
const fieldCount = specTypes.reduce((sum, t) => sum + t.fields.length, 0);
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1336
|
+
const typeFindings = matchTypes(specTypes, codeTypes, specId, {
|
|
1337
|
+
status: spec.frontmatter.status
|
|
1338
|
+
});
|
|
1339
|
+
findings.push(...typeFindings);
|
|
1340
|
+
const pendingTypes = typeFindings.filter((f) => f.type === "pending");
|
|
1341
|
+
typeTotal += fieldCount - pendingTypes.reduce((sum, f) => sum + (f.weight ?? 1), 0);
|
|
1342
|
+
typesPending += pendingTypes.length;
|
|
1343
|
+
const unattached = unattachedFieldLines(spec.content);
|
|
1344
|
+
if (unattached.length > 0) {
|
|
1345
|
+
noteUnassessed(`${specId}: ${unattached.length} field line(s) in its Data Model sit under no \`### TypeName\` heading, so they were not assessed \u2014 the first is \`${unattached[0]}\`.`);
|
|
1245
1346
|
}
|
|
1246
1347
|
for (const name of unreadableTypeBlocks(spec.content)) {
|
|
1247
|
-
|
|
1348
|
+
noteUnassessed(`${specId}: 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
1349
|
}
|
|
1249
1350
|
}
|
|
1351
|
+
if (typesPending > 0) {
|
|
1352
|
+
notes.push(`${typesPending} declared type(s) pending: types planned by specs that are not yet approved. They are excluded from the score and become enforceable when the spec status changes to approved.`);
|
|
1353
|
+
}
|
|
1250
1354
|
}
|
|
1251
1355
|
const testPlanSpecs = specs.filter((s) => s.frontmatter.type === "test-plan");
|
|
1252
1356
|
if (testPlanSpecs.length > 0 && tsMorphAvailable) {
|
|
@@ -1276,9 +1380,10 @@ async function runCheck(specs, projectDir, config = {}) {
|
|
|
1276
1380
|
codeTypes: codeTypeCount,
|
|
1277
1381
|
codeTests: codeTestCount,
|
|
1278
1382
|
artifacts: artifactResult.total > 0 ? artifactResult.checked : null,
|
|
1279
|
-
artifactsPending: artifactResult.pending
|
|
1383
|
+
artifactsPending: artifactResult.pending,
|
|
1384
|
+
typesPending
|
|
1280
1385
|
};
|
|
1281
|
-
return { findings, score, summary, scanned, notes };
|
|
1386
|
+
return { findings, score, summary, scanned, notes, unassessed };
|
|
1282
1387
|
}
|
|
1283
1388
|
async function extractRoutes(projectDir, config, framework) {
|
|
1284
1389
|
if (framework === "express") {
|
|
@@ -1298,6 +1403,85 @@ async function extractRoutes(projectDir, config, framework) {
|
|
|
1298
1403
|
return [...express, ...hono, ...nextjs];
|
|
1299
1404
|
}
|
|
1300
1405
|
|
|
1406
|
+
// ../check/dist/baseline.js
|
|
1407
|
+
var SEP = String.fromCharCode(31);
|
|
1408
|
+
function fingerprint(f) {
|
|
1409
|
+
return [f.type, f.category, f.specId, f.expected, f.actual ?? ""].join(SEP);
|
|
1410
|
+
}
|
|
1411
|
+
function toEntry(f, count) {
|
|
1412
|
+
return {
|
|
1413
|
+
type: f.type,
|
|
1414
|
+
category: f.category,
|
|
1415
|
+
specId: f.specId,
|
|
1416
|
+
expected: f.expected,
|
|
1417
|
+
// Omitted rather than written as undefined, so the JSON stays clean.
|
|
1418
|
+
...f.actual === void 0 ? {} : { actual: f.actual },
|
|
1419
|
+
count
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
function createBaseline(findings) {
|
|
1423
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1424
|
+
const first = /* @__PURE__ */ new Map();
|
|
1425
|
+
for (const f of findings) {
|
|
1426
|
+
const key = fingerprint(f);
|
|
1427
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
1428
|
+
if (!first.has(key))
|
|
1429
|
+
first.set(key, f);
|
|
1430
|
+
}
|
|
1431
|
+
const entries = [...counts].map(([key, count]) => toEntry(first.get(key), count)).sort((a, b) => fingerprint(a).localeCompare(fingerprint(b)));
|
|
1432
|
+
return { version: 1, entries };
|
|
1433
|
+
}
|
|
1434
|
+
function serializeBaseline(baseline) {
|
|
1435
|
+
return JSON.stringify(baseline, null, 2) + "\n";
|
|
1436
|
+
}
|
|
1437
|
+
function parseBaseline(source) {
|
|
1438
|
+
let raw;
|
|
1439
|
+
try {
|
|
1440
|
+
raw = JSON.parse(source);
|
|
1441
|
+
} catch {
|
|
1442
|
+
throw new Error("baseline file could not be parsed as JSON");
|
|
1443
|
+
}
|
|
1444
|
+
if (typeof raw !== "object" || raw === null) {
|
|
1445
|
+
throw new Error("baseline file could not be parsed: expected a JSON object");
|
|
1446
|
+
}
|
|
1447
|
+
const { version, entries } = raw;
|
|
1448
|
+
if (version !== 1) {
|
|
1449
|
+
throw new Error(`baseline file declares version ${String(version)}, which this version of specdx cannot read`);
|
|
1450
|
+
}
|
|
1451
|
+
if (!Array.isArray(entries)) {
|
|
1452
|
+
throw new Error("baseline file has no entries array");
|
|
1453
|
+
}
|
|
1454
|
+
for (const entry of entries) {
|
|
1455
|
+
const e = entry;
|
|
1456
|
+
const ok = typeof entry === "object" && entry !== null && typeof e.type === "string" && typeof e.category === "string" && typeof e.specId === "string" && typeof e.expected === "string" && (e.actual === void 0 || typeof e.actual === "string") && Number.isInteger(e.count);
|
|
1457
|
+
if (!ok) {
|
|
1458
|
+
throw new Error("baseline file has entries missing type, category, specId, expected or count");
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
return { version: 1, entries };
|
|
1462
|
+
}
|
|
1463
|
+
function applyBaseline(findings, baseline) {
|
|
1464
|
+
const budget = /* @__PURE__ */ new Map();
|
|
1465
|
+
for (const entry of baseline.entries) {
|
|
1466
|
+
const key = fingerprint(entry);
|
|
1467
|
+
budget.set(key, (budget.get(key) ?? 0) + entry.count);
|
|
1468
|
+
}
|
|
1469
|
+
const remaining = [];
|
|
1470
|
+
const suppressed = [];
|
|
1471
|
+
for (const f of findings) {
|
|
1472
|
+
const key = fingerprint(f);
|
|
1473
|
+
const left = budget.get(key) ?? 0;
|
|
1474
|
+
if (left > 0) {
|
|
1475
|
+
budget.set(key, left - 1);
|
|
1476
|
+
suppressed.push(f);
|
|
1477
|
+
} else {
|
|
1478
|
+
remaining.push(f);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
const obsolete = baseline.entries.filter((entry) => (budget.get(fingerprint(entry)) ?? 0) > 0).sort((a, b) => fingerprint(a).localeCompare(fingerprint(b)));
|
|
1482
|
+
return { remaining, suppressed, obsolete };
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1301
1485
|
// ../check/dist/ai.js
|
|
1302
1486
|
async function analyzeWithAi(findings, context) {
|
|
1303
1487
|
const apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
@@ -1356,6 +1540,11 @@ export {
|
|
|
1356
1540
|
checkArtifacts,
|
|
1357
1541
|
detectFramework,
|
|
1358
1542
|
runCheck,
|
|
1543
|
+
fingerprint,
|
|
1544
|
+
createBaseline,
|
|
1545
|
+
serializeBaseline,
|
|
1546
|
+
parseBaseline,
|
|
1547
|
+
applyBaseline,
|
|
1359
1548
|
analyzeWithAi
|
|
1360
1549
|
};
|
|
1361
|
-
//# sourceMappingURL=chunk-
|
|
1550
|
+
//# sourceMappingURL=chunk-2UUQJ2ER.js.map
|