cyber-sdd 0.7.0 → 0.7.2

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 (150) hide show
  1. package/.claude-plugin/plugin.json +1 -2
  2. package/.codex-plugin/plugin.json +1 -2
  3. package/CHANGELOG.md +320 -0
  4. package/agents/sdd-scanner.md +1 -1
  5. package/package.json +11 -12
  6. package/plugin.json +55 -0
  7. package/skills/align-spec/SKILL.md +1 -1
  8. package/skills/align-spec/scripts/align-spec.mjs +6755 -12
  9. package/skills/blast-estimate/README.md +3 -3
  10. package/skills/blast-estimate/scripts/blast-estimate.mjs +601 -12
  11. package/skills/check-field-mandates/scripts/check-field-mandates.mjs +253 -12
  12. package/skills/check-partition-quality/scripts/check-partition-quality.mjs +235 -12
  13. package/skills/check-plan-safety/SKILL.md +2 -3
  14. package/skills/check-plan-safety/scripts/check-plan-safety.mjs +109 -12
  15. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mjs +250 -12
  16. package/skills/check-project-specs/SKILL.md +1 -1
  17. package/skills/check-project-specs/scripts/check-project-specs.mjs +593 -12
  18. package/skills/check-retired-terms/SKILL.md +2 -3
  19. package/skills/check-retired-terms/scripts/check-retired-terms.mjs +186 -12
  20. package/skills/check-scenario-overlap/SKILL.md +1 -2
  21. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.mjs +177 -12
  22. package/skills/check-spec-references/SKILL.md +2 -2
  23. package/skills/check-spec-references/scripts/check-spec-references.mjs +287 -12
  24. package/skills/check-spec-structure/SKILL.md +1 -2
  25. package/skills/check-spec-structure/scripts/check-spec-structure.mjs +243 -12
  26. package/skills/collision-ladder/README.md +2 -2
  27. package/skills/collision-ladder/scripts/collision-ladder.mjs +7047 -12
  28. package/skills/combat-log-governance/SKILL.md +1 -1
  29. package/skills/concept-index/SKILL.md +1 -1
  30. package/skills/concept-index/scripts/concept-index.mjs +183 -12
  31. package/skills/discover-plans/README.md +3 -3
  32. package/skills/discover-plans/SKILL.md +1 -1
  33. package/skills/discover-plans/scripts/discover-plans.mjs +137 -12
  34. package/skills/discover-specs/README.md +3 -3
  35. package/skills/discover-specs/SKILL.md +1 -1
  36. package/skills/discover-specs/scripts/discover-specs.mjs +321 -12
  37. package/skills/doctrine-loop/SKILL.md +1 -1
  38. package/skills/gate-validation-governance/SKILL.md +1 -1
  39. package/skills/init/README.md +2 -2
  40. package/skills/init/scripts/wire-statusline.mjs +168 -12
  41. package/skills/manage-ignore/README.md +3 -3
  42. package/skills/manage-ignore/SKILL.md +1 -2
  43. package/skills/manage-ignore/scripts/manage-ignore.mjs +285 -12
  44. package/skills/manage-scenario-bridge/README.md +3 -3
  45. package/skills/manage-scenario-bridge/SKILL.md +1 -1
  46. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mjs +239 -12
  47. package/skills/manage-spec-anchors/README.md +3 -3
  48. package/skills/manage-spec-anchors/SKILL.md +1 -1
  49. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mjs +310 -12
  50. package/skills/mission-graph/README.md +2 -2
  51. package/skills/mission-graph/SKILL.md +1 -1
  52. package/skills/mission-graph/scripts/mission-graph.mjs +1040 -12
  53. package/skills/pause-mission/SKILL.md +1 -1
  54. package/skills/place-node/SKILL.md +2 -2
  55. package/skills/place-node/scripts/place-node.mjs +117 -12
  56. package/skills/plan-retirement/README.md +2 -2
  57. package/skills/plan-retirement/scripts/retire-plans.mjs +123 -12
  58. package/skills/resolve-governances/README.md +3 -3
  59. package/skills/resolve-governances/SKILL.md +1 -1
  60. package/skills/resolve-governances/scripts/resolve-governances.mjs +352 -12
  61. package/skills/resolve-tracking/SKILL.md +1 -1
  62. package/skills/resolve-tracking/scripts/resolve-tracking.mjs +152 -12
  63. package/skills/scaffold-project-spec/SKILL.md +1 -1
  64. package/skills/spec-gate/README.md +12 -9
  65. package/skills/spec-gate/SKILL.md +2 -2
  66. package/skills/spec-gate/scripts/check-spec-state.mjs +422 -12
  67. package/skills/spec-gate/scripts/check-suite.mjs +6500 -12
  68. package/skills/spec-gate/scripts/classify-edit-class.mjs +6579 -12
  69. package/skills/spec-producer-governance/SKILL.md +2 -2
  70. package/skills/start-mission/SKILL.md +1 -1
  71. package/skills/suite-format-governance/README.md +1 -1
  72. package/skills/suite-format-governance/SKILL.md +1 -1
  73. package/skills/touch-set-correction/README.md +5 -5
  74. package/skills/touch-set-correction/SKILL.md +1 -1
  75. package/skills/touch-set-correction/scripts/touch-set-correction.mjs +6663 -12
  76. package/skills/verify-scenarios/README.md +6 -6
  77. package/skills/verify-scenarios/scripts/verify-scenarios.mjs +6539 -12
  78. package/.plugin/pins.json +0 -3
  79. package/.plugin/plugin.json +0 -19
  80. package/dist/align-spec/scripts/align-spec.js +0 -102
  81. package/dist/check-project-specs/scripts/check-project-specs.js +0 -312
  82. package/dist/check-scenario-overlap/scripts/check-scenario-overlap.js +0 -175
  83. package/dist/check-spec-references/scripts/check-spec-references.js +0 -285
  84. package/dist/check-spec-structure/scripts/check-spec-structure.js +0 -241
  85. package/dist/concept-index/scripts/concept-index.js +0 -181
  86. package/dist/discover-specs/scripts/discover-specs.js +0 -318
  87. package/dist/spec-gate/scripts/check-spec-state.js +0 -420
  88. package/dist/spec-gate/scripts/check-suite.js +0 -317
  89. package/dist/spec-gate/scripts/classify-edit-class.js +0 -263
  90. package/dist/spec-gate/vendor/gherkin-cli.js +0 -6369
  91. package/skills/align-spec/scripts/align-spec.bundle.mjs +0 -6753
  92. package/skills/align-spec/scripts/align-spec.mts +0 -188
  93. package/skills/blast-estimate/scripts/blast-estimate.bundle.mjs +0 -593
  94. package/skills/blast-estimate/scripts/blast-estimate.mts +0 -586
  95. package/skills/check-field-mandates/scripts/check-field-mandates.bundle.mjs +0 -251
  96. package/skills/check-field-mandates/scripts/check-field-mandates.mts +0 -337
  97. package/skills/check-partition-quality/scripts/check-partition-quality.bundle.mjs +0 -233
  98. package/skills/check-partition-quality/scripts/check-partition-quality.mts +0 -338
  99. package/skills/check-plan-safety/scripts/check-plan-safety.bundle.mjs +0 -107
  100. package/skills/check-plan-safety/scripts/check-plan-safety.mts +0 -148
  101. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.bundle.mjs +0 -248
  102. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mts +0 -303
  103. package/skills/check-project-specs/scripts/check-project-specs.bundle.mjs +0 -584
  104. package/skills/check-project-specs/scripts/check-project-specs.mts +0 -370
  105. package/skills/check-retired-terms/scripts/check-retired-terms.bundle.mjs +0 -184
  106. package/skills/check-retired-terms/scripts/check-retired-terms.mts +0 -293
  107. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.bundle.mjs +0 -175
  108. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.mts +0 -250
  109. package/skills/check-spec-references/scripts/check-spec-references.bundle.mjs +0 -285
  110. package/skills/check-spec-references/scripts/check-spec-references.mts +0 -422
  111. package/skills/check-spec-structure/scripts/check-spec-structure.bundle.mjs +0 -241
  112. package/skills/check-spec-structure/scripts/check-spec-structure.mts +0 -347
  113. package/skills/collision-ladder/scripts/collision-ladder.bundle.mjs +0 -7041
  114. package/skills/collision-ladder/scripts/collision-ladder.mts +0 -662
  115. package/skills/concept-index/scripts/concept-index.bundle.mjs +0 -181
  116. package/skills/concept-index/scripts/concept-index.mts +0 -246
  117. package/skills/discover-plans/scripts/discover-plans.bundle.mjs +0 -135
  118. package/skills/discover-plans/scripts/discover-plans.mts +0 -215
  119. package/skills/discover-specs/scripts/discover-specs.bundle.mjs +0 -319
  120. package/skills/discover-specs/scripts/discover-specs.mts +0 -420
  121. package/skills/init/scripts/wire-statusline.bundle.mjs +0 -166
  122. package/skills/init/scripts/wire-statusline.mts +0 -279
  123. package/skills/manage-ignore/scripts/manage-ignore.bundle.mjs +0 -244
  124. package/skills/manage-ignore/scripts/manage-ignore.mts +0 -297
  125. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.bundle.mjs +0 -237
  126. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mts +0 -159
  127. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.bundle.mjs +0 -308
  128. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mts +0 -331
  129. package/skills/mission-graph/scripts/mission-graph.bundle.mjs +0 -1038
  130. package/skills/mission-graph/scripts/mission-graph.mts +0 -1333
  131. package/skills/place-node/scripts/place-node.bundle.mjs +0 -115
  132. package/skills/place-node/scripts/place-node.mts +0 -158
  133. package/skills/plan-retirement/scripts/retire-plans.bundle.mjs +0 -121
  134. package/skills/plan-retirement/scripts/retire-plans.mts +0 -205
  135. package/skills/resolve-governances/scripts/resolve-governances.bundle.mjs +0 -350
  136. package/skills/resolve-governances/scripts/resolve-governances.mts +0 -518
  137. package/skills/resolve-tracking/scripts/resolve-tracking.bundle.mjs +0 -150
  138. package/skills/resolve-tracking/scripts/resolve-tracking.mts +0 -214
  139. package/skills/spec-gate/scripts/check-spec-state.bundle.mjs +0 -420
  140. package/skills/spec-gate/scripts/check-spec-state.mts +0 -637
  141. package/skills/spec-gate/scripts/check-suite.bundle.mjs +0 -6498
  142. package/skills/spec-gate/scripts/check-suite.mts +0 -538
  143. package/skills/spec-gate/scripts/classify-edit-class.bundle.mjs +0 -6577
  144. package/skills/spec-gate/scripts/classify-edit-class.mts +0 -414
  145. package/skills/spec-gate/vendor/gherkin-cli.d.mts +0 -2
  146. package/skills/spec-gate/vendor/gherkin-cli.mjs +0 -6545
  147. package/skills/touch-set-correction/scripts/touch-set-correction.bundle.mjs +0 -6655
  148. package/skills/touch-set-correction/scripts/touch-set-correction.mts +0 -429
  149. package/skills/verify-scenarios/scripts/verify-scenarios.bundle.mjs +0 -6537
  150. package/skills/verify-scenarios/scripts/verify-scenarios.mts +0 -470
@@ -1,584 +0,0 @@
1
- #!/usr/bin/env node
2
- import { execFileSync } from "node:child_process";
3
- import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
4
- import { dirname, join, relative, resolve } from "node:path";
5
- import { fileURLToPath, pathToFileURL } from "node:url";
6
- //#region skills/discover-specs/scripts/discover-specs.mts
7
- const LIFECYCLE_STATUSES = /* @__PURE__ */ new Set([
8
- "draft",
9
- "approved",
10
- "implemented",
11
- "deprecated"
12
- ]);
13
- const ROOT_PROJECT_NAME = "repo";
14
- const SKIP_DIRS = /* @__PURE__ */ new Set([
15
- "node_modules",
16
- ".git",
17
- "dist",
18
- ".turbo",
19
- ".next",
20
- "coverage"
21
- ]);
22
- /**
23
- * A directory that is itself a checkout is a DIFFERENT repository's tree, not part of this corpus.
24
- *
25
- * A name blocklist cannot express this: it can only say "this is called X", never "this is a
26
- * boundary". `SKIP_DIRS` already holds `.git`, so the walk skipped the METADATA directory while
27
- * descending straight into the checkout that directory marks — one level off from where the guard
28
- * was needed. Agent-harness worktree isolation checks this repo out inside itself, and the scan then
29
- * found the whole corpus once per worktree: 38 spec files where 10 exist, and every corpus-wide
30
- * guard silently auditing a tree nobody has.
31
- *
32
- * `.git` is a DIRECTORY in a clone and a FILE in a worktree or submodule, so both forms count.
33
- */
34
- function isNestedCheckout(abs) {
35
- return existsSync(join(abs, ".git"));
36
- }
37
- const ANCHORS_CONFIG = ".agents/sdd/spec-anchors.toml";
38
- function parseFrontmatter(text) {
39
- const m = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(text);
40
- if (!m) return null;
41
- const fm = { approval: {} };
42
- let gate = null;
43
- for (const raw of m[1].split("\n")) {
44
- const line = raw.replace(/\r$/, "");
45
- if (line.trim() === "" || line.trim().startsWith("#")) continue;
46
- const indent = line.length - line.trimStart().length;
47
- const [key, ...rest] = line.trim().split(":");
48
- const value = rest.join(":").trim();
49
- if (indent === 0) {
50
- gate = null;
51
- if (key === "status") fm.status = unquote(value);
52
- else if (key === "project-path") fm.projectPath = unquote(value);
53
- else if (key === "name") fm.name = unquote(value);
54
- else if (key === "approval") gate = null;
55
- } else if (indent === 2 && value === "" && insideApproval(m[1], line)) gate = key;
56
- else if (indent >= 4 && key === "verdict" && gate) fm.approval[gate] = unquote(value);
57
- }
58
- return fm;
59
- }
60
- function insideApproval(block, line) {
61
- const lines = block.split("\n");
62
- const idx = lines.indexOf(line);
63
- for (let i = idx - 1; i >= 0; i--) {
64
- const l = lines[i].replace(/\r$/, "");
65
- if (l.trim() === "" || l.trim().startsWith("#")) continue;
66
- if (l.length - l.trimStart().length === 0) return l.trim().replace(/:.*$/, "") === "approval";
67
- }
68
- return false;
69
- }
70
- function unquote(v) {
71
- return v.replace(/^["']|["']$/g, "");
72
- }
73
- function classifyLocation(relPath) {
74
- const p = relPath.replace(/\\/g, "/");
75
- if (p === ".agents/spec/spec.md") return {
76
- pattern: "root-single",
77
- locationDir: ""
78
- };
79
- const multi = /^\.agents\/specs\/([^/]+)\/spec\.md$/.exec(p);
80
- if (multi) return {
81
- pattern: "root-multi",
82
- locationDir: multi[1]
83
- };
84
- const nested = /^(.+)\/\.agents\/spec\/spec\.md$/.exec(p);
85
- if (nested) return {
86
- pattern: "nested",
87
- locationDir: nested[1]
88
- };
89
- return null;
90
- }
91
- function deriveName(loc, fm) {
92
- if (fm.name) return {
93
- name: fm.name,
94
- nameSource: "declared"
95
- };
96
- if (loc.pattern === "root-single") return {
97
- name: ROOT_PROJECT_NAME,
98
- nameSource: "derived"
99
- };
100
- if (loc.pattern === "root-multi") return {
101
- name: loc.locationDir,
102
- nameSource: "derived"
103
- };
104
- if (loc.pattern === "extra" && loc.capturedName) return {
105
- name: loc.capturedName,
106
- nameSource: "derived"
107
- };
108
- return {
109
- name: loc.locationDir.split("/").pop() ?? loc.locationDir,
110
- nameSource: "guessed"
111
- };
112
- }
113
- function discoverSpecFiles(root) {
114
- const found = [];
115
- const walk = (relDir) => {
116
- let entries;
117
- try {
118
- entries = readdirSync(join(root, relDir), { withFileTypes: true });
119
- } catch {
120
- return;
121
- }
122
- for (const e of entries) {
123
- if (!e.isDirectory() || SKIP_DIRS.has(e.name)) continue;
124
- const childRel = relDir ? `${relDir}/${e.name}` : e.name;
125
- if (isNestedCheckout(join(root, childRel))) continue;
126
- if (e.name === ".agents") {
127
- probeAgents(root, childRel, found);
128
- continue;
129
- }
130
- walk(childRel);
131
- }
132
- };
133
- walk("");
134
- return found;
135
- }
136
- function probeAgents(root, agentsRel, found) {
137
- const single = `${agentsRel}/spec/spec.md`;
138
- if (existsSync(join(root, single))) found.push(single);
139
- if (agentsRel === ".agents") {
140
- const specsDir = join(root, ".agents", "specs");
141
- let projects;
142
- try {
143
- projects = readdirSync(specsDir, { withFileTypes: true });
144
- } catch {
145
- projects = [];
146
- }
147
- for (const p of projects) {
148
- if (!p.isDirectory()) continue;
149
- const rel = `.agents/specs/${p.name}/spec.md`;
150
- if (existsSync(join(root, rel))) found.push(rel);
151
- }
152
- }
153
- }
154
- function parseAnchorsToml(text) {
155
- const m = /(^|\n)\s*anchors\s*=\s*\[([\s\S]*?)\]/.exec(text);
156
- if (!m) return [];
157
- const out = [];
158
- for (const q of m[2].matchAll(/"([^"]*)"|'([^']*)'/g)) out.push((q[1] ?? q[2]).trim());
159
- return out.filter((s) => s !== "");
160
- }
161
- function readAnchors(root) {
162
- const file = join(root, ANCHORS_CONFIG);
163
- if (!existsSync(file)) return [];
164
- try {
165
- return parseAnchorsToml(readFileSync(file, "utf8"));
166
- } catch {
167
- process.stderr.write(`discover-specs: ignoring unreadable ${ANCHORS_CONFIG}\n`);
168
- return [];
169
- }
170
- }
171
- function collectDescendants(root, startDir) {
172
- const out = [startDir];
173
- let entries;
174
- try {
175
- entries = readdirSync(join(root, startDir), { withFileTypes: true });
176
- } catch {
177
- return out;
178
- }
179
- for (const e of entries) {
180
- if (!e.isDirectory() || SKIP_DIRS.has(e.name)) continue;
181
- const childRel = startDir ? `${startDir}/${e.name}` : e.name;
182
- if (isNestedCheckout(join(root, childRel))) continue;
183
- out.push(...collectDescendants(root, childRel));
184
- }
185
- return out;
186
- }
187
- function expandAnchor(root, pattern) {
188
- const segs = pattern.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
189
- let frontier = [{ dir: "" }];
190
- for (const seg of segs) {
191
- const next = [];
192
- if (seg === "**") {
193
- for (const node of frontier) for (const dir of collectDescendants(root, node.dir)) next.push({
194
- dir,
195
- capturedName: node.capturedName
196
- });
197
- frontier = next;
198
- continue;
199
- }
200
- const isGlob = seg === "*" || seg === "<project>";
201
- for (const node of frontier) if (isGlob) {
202
- let entries;
203
- try {
204
- entries = readdirSync(join(root, node.dir), { withFileTypes: true });
205
- } catch {
206
- continue;
207
- }
208
- for (const e of entries) {
209
- if (!e.isDirectory() || SKIP_DIRS.has(e.name)) continue;
210
- const childRel = node.dir ? `${node.dir}/${e.name}` : e.name;
211
- if (isNestedCheckout(join(root, childRel))) continue;
212
- next.push({
213
- dir: childRel,
214
- capturedName: seg === "<project>" ? e.name : node.capturedName
215
- });
216
- }
217
- } else next.push({
218
- dir: node.dir ? `${node.dir}/${seg}` : seg,
219
- capturedName: node.capturedName
220
- });
221
- frontier = next;
222
- }
223
- const out = [];
224
- for (const node of frontier) {
225
- const rel = node.dir ? `${node.dir}/spec.md` : "spec.md";
226
- if (existsSync(join(root, rel))) out.push({
227
- rel,
228
- capturedName: node.capturedName
229
- });
230
- }
231
- return out;
232
- }
233
- function recordFor(root, rel, loc) {
234
- let fm;
235
- try {
236
- fm = parseFrontmatter(readFileSync(join(root, rel), "utf8"));
237
- } catch {
238
- return null;
239
- }
240
- if (!fm?.status || !LIFECYCLE_STATUSES.has(fm.status)) return null;
241
- const { name, nameSource } = deriveName(loc, fm);
242
- return {
243
- path: rel.replace(/\/spec\.md$/, ""),
244
- name,
245
- nameSource,
246
- status: fm.status,
247
- projectPath: fm.projectPath ?? "",
248
- approvals: Object.entries(fm.approval).map(([gate, verdict]) => `${gate}:${verdict}`).join(";")
249
- };
250
- }
251
- function collectSpecs(root) {
252
- const out = [];
253
- const seen = /* @__PURE__ */ new Set();
254
- for (const rel of discoverSpecFiles(root)) {
255
- const loc = classifyLocation(rel);
256
- if (!loc) continue;
257
- const rec = recordFor(root, rel, loc);
258
- if (rec) {
259
- out.push(rec);
260
- seen.add(rel);
261
- }
262
- }
263
- for (const pattern of readAnchors(root)) for (const { rel, capturedName } of expandAnchor(root, pattern)) {
264
- if (seen.has(rel)) continue;
265
- const rec = recordFor(root, rel, {
266
- pattern: "extra",
267
- locationDir: rel.replace(/\/spec\.md$/, ""),
268
- capturedName
269
- });
270
- if (rec) {
271
- out.push(rec);
272
- seen.add(rel);
273
- }
274
- }
275
- return out.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
276
- }
277
- if (process.argv[1] && false);
278
- //#endregion
279
- //#region skills/check-project-specs/scripts/check-project-specs.mts
280
- const HERE = fileURLToPath(import.meta.url);
281
- const ENGINES = [
282
- {
283
- name: "check-spec-state",
284
- script: "spec-gate/scripts/check-spec-state.mts",
285
- args: (d) => ["--root", d]
286
- },
287
- {
288
- name: "check-suite",
289
- script: "spec-gate/scripts/check-suite.mts",
290
- args: (d) => ["--root", d]
291
- },
292
- {
293
- name: "concept-index",
294
- script: "concept-index/scripts/concept-index.mts",
295
- args: (d) => [
296
- "--spec-dir",
297
- d,
298
- "--check"
299
- ]
300
- },
301
- {
302
- name: "check-spec-structure",
303
- script: "check-spec-structure/scripts/check-spec-structure.mts",
304
- args: (d) => [
305
- "--spec-dir",
306
- d,
307
- "--check"
308
- ]
309
- },
310
- {
311
- name: "align-spec",
312
- script: "align-spec/scripts/align-spec.mts",
313
- args: (d) => [
314
- "--spec-dir",
315
- d,
316
- "--check"
317
- ]
318
- },
319
- {
320
- name: "check-spec-references",
321
- script: "check-spec-references/scripts/check-spec-references.mts",
322
- args: (d) => ["--spec-dir", d]
323
- },
324
- {
325
- name: "check-scenario-overlap",
326
- script: "check-scenario-overlap/scripts/check-scenario-overlap.mts",
327
- args: (d) => [
328
- "--spec-dir",
329
- d,
330
- "--check"
331
- ]
332
- }
333
- ];
334
- /**
335
- * Where an engine runs from. The .mts source runs its siblings in the skills tree; the
336
- * published bin runs from dist/, which mirrors that tree compiled to .js (tsdown.config.ts)
337
- * — Node will not strip types under node_modules, so the bin must never reach back into
338
- * the .mts tree.
339
- */
340
- function enginePath(e, here = HERE) {
341
- const skillsDir = resolve(dirname(here), "../..");
342
- if (here.endsWith(".bundle.mjs")) return join(skillsDir, e.script.replace(/\.mts$/, ".bundle.mjs"));
343
- return join(skillsDir, here.endsWith(".mts") ? e.script : e.script.replace(/\.mts$/, ".js"));
344
- }
345
- /** Walk up from `start` for the workspace marker. Returns '' when not found. */
346
- function findRepoRoot(start) {
347
- let dir = resolve(start);
348
- for (;;) {
349
- if (existsSync(join(dir, "pnpm-workspace.yaml"))) return dir;
350
- const up = dirname(dir);
351
- if (up === dir) return "";
352
- dir = up;
353
- }
354
- }
355
- /**
356
- * Find the spec whose `project-path` names `projectRel` (a repo-relative dir).
357
- * A project with no spec is `none` — not an error: the script is uniform across
358
- * every workspace member, and some members are governed by no spec.
359
- */
360
- function resolveSpecFor(specs, projectRel) {
361
- const hits = specs.filter((s) => s.projectPath !== "" && s.projectPath === projectRel);
362
- if (hits.length === 0) return { kind: "none" };
363
- if (hits.length > 1) return {
364
- kind: "ambiguous",
365
- specs: hits
366
- };
367
- return {
368
- kind: "resolved",
369
- spec: hits[0]
370
- };
371
- }
372
- /**
373
- * Every spec must be reachable from a project that actually checks it. Without
374
- * this, a spec silently goes unchecked the moment its project drops the script —
375
- * which is exactly how the corpus ended up with one audited project out of ten.
376
- *
377
- * `specFiles` are the spec.md paths found at the recognized locations *before*
378
- * the lifecycle-status filter; `specs` are the ones that survived it. A file in
379
- * the first set and not the second is a spec whose status is not in the enum:
380
- * discovery drops it, so every engine silently skips it and it is checked by
381
- * nothing. That is a gap to escalate, not to exempt.
382
- */
383
- function findCoverageGaps(root, specFiles, specs, readPkg) {
384
- const gaps = [];
385
- const recognized = new Set(specs.map((s) => s.path === "" ? "spec.md" : `${s.path}/spec.md`));
386
- for (const f of specFiles) if (!recognized.has(f)) gaps.push({
387
- spec: f,
388
- projectPath: "",
389
- reason: "unrecognized"
390
- });
391
- for (const s of specs) {
392
- if (s.projectPath === "") {
393
- gaps.push({
394
- spec: s.path,
395
- projectPath: "",
396
- reason: "no-project-path"
397
- });
398
- continue;
399
- }
400
- const pkg = readPkg(join(root, s.projectPath, "package.json"));
401
- if (!pkg) {
402
- gaps.push({
403
- spec: s.path,
404
- projectPath: s.projectPath,
405
- reason: "no-manifest"
406
- });
407
- continue;
408
- }
409
- if (!pkg.scripts?.["check:spec"]) gaps.push({
410
- spec: s.path,
411
- projectPath: s.projectPath,
412
- reason: "no-check-script"
413
- });
414
- }
415
- return gaps;
416
- }
417
- /**
418
- * A spec.md sitting at a recognized location that discovery DROPPED (its status is not
419
- * in the lifecycle enum) and that belongs to `projectRel` — by the `project-path` it
420
- * declares, or by sitting inside the project (`<project>/.agents/spec/spec.md`, which
421
- * survives frontmatter corruption because it is location-derived).
422
- *
423
- * Without this, a per-project run resolves such a spec to `none` and prints "no spec
424
- * governs <project> — skipped" with exit 0: a status typo silently exempts the whole
425
- * project from every engine. A spec that exists but cannot be classified is escalated,
426
- * not exempted — the same call the corpus scope’s coverage guard makes.
427
- */
428
- function findDroppedSpecFor(specFiles, specs, projectRel, readText) {
429
- const recognized = new Set(specs.map((s) => s.path === "" ? "spec.md" : `${s.path}/spec.md`));
430
- const out = [];
431
- for (const f of specFiles) {
432
- if (recognized.has(f)) continue;
433
- const text = readText(f);
434
- const fm = text === null ? null : parseFrontmatter(text);
435
- const dir = f.replace(/(^|\/)spec\.md$/, "");
436
- const nested = /^(.+)\/\.agents\/spec$/.exec(dir)?.[1] ?? "";
437
- if (fm?.projectPath === projectRel || nested === projectRel) out.push({
438
- file: f,
439
- status: fm?.status ?? ""
440
- });
441
- }
442
- return out;
443
- }
444
- const REASON_TEXT = {
445
- unrecognized: "sits at a spec location but its status is not in the lifecycle enum, so discovery drops it and nothing checks it",
446
- "no-project-path": "declares no project-path, so no project can be resolved to check it",
447
- "no-manifest": "names a project with no package.json, so it is not a workspace member",
448
- "no-check-script": "names a project that defines no `check:spec` script"
449
- };
450
- /** Read a file, or null when it cannot be read. */
451
- function readTextOrNull(path) {
452
- try {
453
- return readFileSync(path, "utf8");
454
- } catch {
455
- return null;
456
- }
457
- }
458
- /**
459
- * Run the whole engine set against one project-spec dir. Every engine runs even
460
- * after one fails: a run that stops at the first failure reports one defect per
461
- * invocation, and the corpus scope exists to report the tree's defects in one go.
462
- */
463
- function runEngines(repoRoot, specDir) {
464
- let failed = 0;
465
- for (const e of ENGINES) try {
466
- execFileSync("node", [enginePath(e), ...e.args(specDir)], {
467
- cwd: repoRoot,
468
- stdio: "inherit"
469
- });
470
- process.stdout.write(` ok ${e.name}\n`);
471
- } catch {
472
- process.stderr.write(` FAIL ${e.name}\n`);
473
- failed++;
474
- }
475
- return failed;
476
- }
477
- function checkCoverage(root) {
478
- const gaps = findCoverageGaps(root, discoverSpecFiles(root), collectSpecs(root), (p) => {
479
- try {
480
- return JSON.parse(readFileSync(p, "utf8"));
481
- } catch {
482
- return null;
483
- }
484
- });
485
- if (gaps.length === 0) {
486
- process.stdout.write("check-project-specs: every spec is checked by its project\n");
487
- return 0;
488
- }
489
- for (const g of gaps) process.stderr.write(` ${g.spec} — ${REASON_TEXT[g.reason]}\n`);
490
- process.stderr.write(`check-project-specs: ${gaps.length} spec(s) no project checks\n`);
491
- return 1;
492
- }
493
- /** The flags the harness defines. Anything else is an error, never a default. */
494
- const KNOWN_FLAGS = ["--corpus", "--project"];
495
- /**
496
- * The scope is chosen by a flag, so an unrecognized one must not fall through to a
497
- * default. It used to: project scope at a repo root resolves no governing spec and
498
- * exits 0, so a misspelled or retired flag reported success having checked nothing.
499
- * That is how `--check-coverage` guarded commits and CI while running no engine.
500
- */
501
- function unknownFlags(argv) {
502
- const out = [];
503
- for (let i = 0; i < argv.length; i++) {
504
- const a = argv[i];
505
- if (!a.startsWith("-")) continue;
506
- if (a === "--project") {
507
- i++;
508
- continue;
509
- }
510
- if (!KNOWN_FLAGS.includes(a)) out.push(a);
511
- }
512
- return out;
513
- }
514
- function main(argv) {
515
- const unknown = unknownFlags(argv);
516
- if (unknown.length) {
517
- process.stderr.write(`check-project-specs: unrecognized flag(s) ${unknown.join(", ")} — the scope is ${KNOWN_FLAGS.join(" | ")} (or none, meaning the cwd's project)\n`);
518
- return 1;
519
- }
520
- if (argv.includes("--corpus") && argv.includes("--project")) {
521
- process.stderr.write("check-project-specs: --corpus and --project name contradictory scopes — pass one\n");
522
- return 1;
523
- }
524
- if (argv.includes("--corpus")) return checkCorpus();
525
- return checkProject(argv);
526
- }
527
- /**
528
- * Corpus scope — the commit floor. Total by definition: every project-spec the
529
- * corpus holds is checked, and a spec that cannot be classified fails rather than
530
- * being skipped.
531
- *
532
- * It runs BOTH sub-checks because neither subsumes the other. The sweep iterates
533
- * the specs discovery *recognizes*, so a spec whose lifecycle `status` is a typo is
534
- * invisible to it — and would report clean. The coverage guard sees that file on
535
- * disk and escalates it, but says nothing about whether the engines pass. Run either
536
- * alone and a whole project-spec leaves the floor silently.
537
- */
538
- function checkCorpus() {
539
- const root = findRepoRoot(process.cwd());
540
- if (!root) {
541
- process.stderr.write("check-project-specs: no pnpm-workspace.yaml found above the cwd\n");
542
- return 1;
543
- }
544
- let failed = checkCoverage(root) === 0 ? 0 : 1;
545
- const specs = collectSpecs(root);
546
- if (specs.length === 0) {
547
- process.stdout.write("check-project-specs: the corpus holds no project-spec\n");
548
- return failed;
549
- }
550
- for (const s of specs) {
551
- process.stdout.write(`check-project-specs: ${s.path}\n`);
552
- if (runEngines(root, join(root, s.path)) > 0) failed = 1;
553
- }
554
- return failed;
555
- }
556
- function checkProject(argv) {
557
- const projectArg = argv.includes("--project") ? argv[argv.indexOf("--project") + 1] : void 0;
558
- const projectDir = resolve(projectArg ?? process.cwd());
559
- const repoRoot = findRepoRoot(projectDir);
560
- if (!repoRoot) {
561
- process.stderr.write(`check-project-specs: no pnpm-workspace.yaml found above ${projectDir}\n`);
562
- return 1;
563
- }
564
- const projectRel = relative(repoRoot, projectDir) || ".";
565
- const specs = collectSpecs(repoRoot);
566
- const res = resolveSpecFor(specs, projectRel);
567
- if (res.kind === "none") {
568
- const dropped = findDroppedSpecFor(discoverSpecFiles(repoRoot), specs, projectRel, (rel) => readTextOrNull(join(repoRoot, rel)));
569
- for (const d of dropped) process.stderr.write(`check-project-specs: \`${d.file}\` sits at a spec location and governs \`${projectRel}\` but ` + (d.status === "" ? "declares no lifecycle status" : `its status \`${d.status}\` is not in the lifecycle enum`) + " (draft | approved | implemented | deprecated) — discovery drops it, so it is checked by nothing\n");
570
- if (dropped.length) return 1;
571
- process.stdout.write(`check-project-specs: no spec governs \`${projectRel}\` — skipped\n`);
572
- return 0;
573
- }
574
- if (res.kind === "ambiguous") {
575
- process.stderr.write(`check-project-specs: \`${projectRel}\` is claimed by ${res.specs.length} specs (${res.specs.map((s) => s.path).join(", ")}) — a project has exactly one spec\n`);
576
- return 1;
577
- }
578
- const specDir = join(repoRoot, res.spec.path);
579
- process.stdout.write(`check-project-specs: ${projectRel} -> ${res.spec.path}\n`);
580
- return runEngines(repoRoot, specDir) === 0 ? 0 : 1;
581
- }
582
- if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) process.exit(main(process.argv.slice(2)));
583
- //#endregion
584
- export { ENGINES, KNOWN_FLAGS, enginePath, findCoverageGaps, findDroppedSpecFor, findRepoRoot, main, resolveSpecFor, unknownFlags };