rungate 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/bin/rungate.ts +70 -0
  2. package/lib/aes-calculator.ts +66 -0
  3. package/lib/agent-audit.ts +139 -0
  4. package/lib/agent-brief-validation.ts +359 -0
  5. package/lib/agents-md-refs.ts +90 -0
  6. package/lib/bash-file-read.ts +197 -0
  7. package/lib/behavioral-cache.ts +78 -0
  8. package/lib/branch-cleanup.ts +234 -0
  9. package/lib/brief-context-parser.ts +35 -0
  10. package/lib/canary.ts +117 -0
  11. package/lib/check-registry.ts +226 -0
  12. package/lib/ci-checkout.ts +400 -0
  13. package/lib/cli-commands.ts +137 -0
  14. package/lib/compliance-backfill.ts +220 -0
  15. package/lib/compliance-report.ts +504 -0
  16. package/lib/compliance.ts +361 -0
  17. package/lib/config-loader.ts +255 -0
  18. package/lib/conformity.ts +1818 -131
  19. package/lib/container-provenance.ts +230 -0
  20. package/lib/create-brief.ts +150 -0
  21. package/lib/create-sc.ts +272 -0
  22. package/lib/deep-merge.ts +69 -0
  23. package/lib/dev-liveness.ts +214 -0
  24. package/lib/directive-extractor.ts +210 -0
  25. package/lib/distribution-standing.ts +113 -0
  26. package/lib/doc-hygiene.ts +238 -0
  27. package/lib/eval-criteria.ts +6 -0
  28. package/lib/evidence-portability.ts +123 -0
  29. package/lib/evidence-prevalidator.ts +390 -0
  30. package/lib/evidence-required.ts +150 -0
  31. package/lib/evidence-satisfiability.ts +288 -0
  32. package/lib/frontmatter.ts +163 -0
  33. package/lib/gap-scanner.ts +348 -0
  34. package/lib/gate-enforcement.ts +366 -0
  35. package/lib/generators/agent-briefs.ts +136 -0
  36. package/lib/generators/agents-md.ts +506 -0
  37. package/lib/generators/code-map.ts +60 -0
  38. package/lib/generators/types.ts +184 -0
  39. package/lib/git-ref-normalizer.ts +107 -0
  40. package/lib/github.ts +539 -0
  41. package/lib/harness-identity.ts +63 -0
  42. package/lib/hill-climb.ts +164 -0
  43. package/lib/instruction-effectiveness.ts +131 -0
  44. package/lib/issue-closure-audit.ts +225 -0
  45. package/lib/issue-create-override.ts +343 -0
  46. package/lib/js-top-level-code.ts +250 -0
  47. package/lib/liveness-contradiction.ts +149 -0
  48. package/lib/organize.ts +505 -0
  49. package/lib/paths.ts +197 -6
  50. package/lib/post-fix-verify.ts +157 -0
  51. package/lib/prior-branch.ts +489 -0
  52. package/lib/project-state-shape.ts +166 -0
  53. package/lib/promote-outputs.ts +156 -0
  54. package/lib/prove-label-gate.ts +35 -0
  55. package/lib/reachability.ts +302 -0
  56. package/lib/release-preflight.ts +186 -0
  57. package/lib/rule-health-pipeline.ts +264 -0
  58. package/lib/rule-health-trend.ts +161 -0
  59. package/lib/rule-provenance.ts +149 -0
  60. package/lib/rule-registry.ts +128 -0
  61. package/lib/rungate-schema.ts +114 -4
  62. package/lib/sc-claim-forms.ts +179 -0
  63. package/lib/sc-cover.ts +150 -0
  64. package/lib/sc-guard.ts +157 -0
  65. package/lib/sc-ids.ts +344 -0
  66. package/lib/scaffold/defaults.ts +165 -0
  67. package/lib/scaffold/managed-workflow.ts +370 -0
  68. package/lib/scaffold/owned-files.ts +265 -0
  69. package/lib/scaffold/steps.ts +2680 -0
  70. package/lib/scanner.ts +701 -0
  71. package/lib/screenshot-upload.ts +73 -0
  72. package/lib/secret-patterns.ts +112 -0
  73. package/lib/security-verdict.ts +616 -0
  74. package/lib/signal-phrases.ts +1 -0
  75. package/lib/spec-change-conformity.ts +80 -0
  76. package/lib/spec-files.ts +62 -0
  77. package/lib/spec-registry.ts +133 -0
  78. package/lib/spec-updater.ts +96 -0
  79. package/lib/stale-cleanup.ts +224 -0
  80. package/lib/stale-issue-scanner.ts +36 -0
  81. package/lib/strip-js-comments.ts +269 -0
  82. package/lib/suite-measurement.ts +228 -0
  83. package/lib/task-completion-checks.ts +177 -0
  84. package/lib/test-suite-lock.ts +1136 -0
  85. package/lib/transcript-checker.ts +1140 -0
  86. package/lib/validators/spec-validators.ts +171 -0
  87. package/lib/verdict-capture.ts +73 -0
  88. package/lib/verified-push.ts +358 -0
  89. package/lib/workflow-security.ts +174 -0
  90. package/lib/worktree-cleanup.ts +250 -0
  91. package/lib/worktree-collect.ts +283 -0
  92. package/lib/worktree-isolation.ts +82 -0
  93. package/package.json +24 -2
  94. package/prompts/ac-adversary.md +14 -2
  95. package/prompts/aditi.md +5 -0
  96. package/prompts/blast-radius.md +5 -0
  97. package/prompts/container-verify.md +5 -0
  98. package/prompts/discovery.md +4 -0
  99. package/prompts/environment.md +5 -0
  100. package/prompts/evidence-hierarchy.md +5 -0
  101. package/prompts/evidence-validator.md +11 -0
  102. package/prompts/marcus.md +5 -0
  103. package/prompts/prevention.md +5 -0
  104. package/prompts/prove-reproducer.md +12 -0
  105. package/prompts/quinn-decision-tree.md +5 -0
  106. package/prompts/quinn-ui-brief.md +5 -0
  107. package/prompts/quinn.md +5 -0
  108. package/prompts/rca.md +5 -0
  109. package/prompts/read-before-write.md +4 -0
  110. package/prompts/regression.md +5 -0
  111. package/prompts/serena.md +5 -0
  112. package/scripts/audit-specs.ts +464 -0
  113. package/scripts/convert-spec.ts +293 -0
  114. package/scripts/create-sc.ts +92 -0
  115. package/scripts/create-spec.ts +166 -0
  116. package/scripts/extract-constraints.ts +4 -3
  117. package/scripts/generate-code-map.ts +1 -1
  118. package/scripts/scaffold-project.ts +138 -1426
  119. package/scripts/sync-spec-tests.ts +211 -126
@@ -13,15 +13,79 @@
13
13
  * Lines containing `Quinn` + action verb → assert Quinn integration
14
14
  */
15
15
 
16
- import { readFileSync, writeFileSync, readdirSync } from "fs";
16
+ import { existsSync, readFileSync, writeFileSync, readdirSync } from "fs";
17
+ import { collectSpecFiles } from "../lib/spec-files";
17
18
  import { resolve, join } from "path";
19
+ import { harnessRootFor } from "../lib/paths";
18
20
 
19
- const HOME = process.env.HOME || "";
20
- const HARNESS_ROOT = process.env.HARNESS_ROOT || join(HOME, ".claude");
21
- const SPECS_DIR = resolve(HARNESS_ROOT, "PAI/Specs");
22
- const SHIP_PATH = resolve(HARNESS_ROOT, "workflows/ship.js");
23
- const PROVE_PATH = resolve(HARNESS_ROOT, "workflows/prove.js");
24
- const OUTPUT_PATH = resolve(HARNESS_ROOT, "test/spec-compliance-auto.test.ts");
21
+ /**
22
+ * Where this script reads specs and writes tests (#141).
23
+ *
24
+ * It used to compute these itself:
25
+ *
26
+ * const HARNESS_ROOT = process.env.HARNESS_ROOT || join(HOME, ".claude");
27
+ * const SPECS_DIR = resolve(HARNESS_ROOT, "PAI/Specs");
28
+ * const OUTPUT_PATH = resolve(HARNESS_ROOT, "test/spec-compliance-auto.test.ts");
29
+ *
30
+ * `HARNESS_ROOT` is never exported — no profile, CI file, hook or skill sets
31
+ * it; it is only ever passed as a workflow argument. So the default applied,
32
+ * and the generator read `~/.claude/PAI/Specs` and wrote
33
+ * `~/.claude/test/spec-compliance-auto.test.ts`, while `lib/paths.ts`
34
+ * `harnessRoot()` resolved to this checkout. Two functions, one concept, two
35
+ * answers — and both directories exist, so nothing ever errored.
36
+ *
37
+ * The cost: `specs/` holds 30 spec files and this generator had never read
38
+ * one of them. "SCs without tests are wishes" is the project's own rule, and
39
+ * the mechanism meant to enforce it wrote its output where the suite does not
40
+ * look and reported success. `gates/gate-executor.ts` runs it on every gate.
41
+ *
42
+ * Pure in `root` so the resolution is testable without a filesystem, which is
43
+ * the shape the issue asked for.
44
+ */
45
+ export interface SyncPaths {
46
+ specsDir: string;
47
+ shipPath: string;
48
+ provePath: string;
49
+ outputPath: string;
50
+ }
51
+
52
+ export function resolveSyncPaths(root: string): SyncPaths {
53
+ return {
54
+ specsDir: resolve(root, "specs"),
55
+ shipPath: resolve(root, "workflows/ship.js"),
56
+ provePath: resolve(root, "workflows/prove.js"),
57
+ outputPath: resolve(root, "test/spec-compliance-auto.test.ts"),
58
+ };
59
+ }
60
+
61
+ /**
62
+ * The tree this script WRITES to, stated rather than inherited (#190).
63
+ *
64
+ * It was `const ROOT = harnessRoot()` at module scope, which made the
65
+ * destination of a write depend on two things the caller never said: the
66
+ * `HARNESS_ROOT` environment variable, and which checkout happened to load
67
+ * `lib/paths.ts`. `gates/gate-executor.ts` runs this on every scope gate, so a
68
+ * gate whose root was resolved elsewhere regenerated a DIFFERENT checkout's
69
+ * `test/spec-compliance-auto.test.ts` and left its own stale — silently, since
70
+ * both files exist and both are real.
71
+ *
72
+ * Resolution order:
73
+ *
74
+ * 1. `argv[2]`, when a caller names the tree it means.
75
+ * 2. Otherwise the checkout this script file lives in.
76
+ *
77
+ * `bun <checkout>/scripts/sync-spec-tests.ts` therefore writes into
78
+ * `<checkout>`, whatever the cwd and whatever the environment says. Deliberately
79
+ * NOT `harnessRoot()`: a writer that can be aimed by an env var is how #141
80
+ * happened, and `HARNESS_ROOT` is set by the ship workflow for reasons that
81
+ * have nothing to do with where generated tests belong.
82
+ */
83
+ export function syncRoot(argv: string[] = process.argv): string {
84
+ const arg = argv[2];
85
+ // `join(dir, "..")` because this file sits in `scripts/`; `harnessRootFor`
86
+ // resolves and validates the path it is handed, it does not search upward.
87
+ return arg ? harnessRootFor(arg) : harnessRootFor(join(import.meta.dir, ".."));
88
+ }
25
89
 
26
90
  function parseTestable(content: string): boolean | null {
27
91
  const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
@@ -31,13 +95,36 @@ function parseTestable(content: string): boolean | null {
31
95
  return testableMatch[1] === "true";
32
96
  }
33
97
 
34
- function discoverTestableSpecs(): { path: string; name: string }[] {
35
- const files = readdirSync(SPECS_DIR).filter(f => f.endsWith(".md"));
98
+ /**
99
+ * Whether a spec makes claims about THIS harness's own workflows (#225).
100
+ *
101
+ * Every claim this script extracts is asserted against `workflows/ship.js` or
102
+ * `workflows/prove.js`, so it only means anything for a spec describing the
103
+ * harness. `specs/bootstrap-data-flow/template-architecture.md` describes what
104
+ * a SCAFFOLDED CONSUMER's files look like, and its `make dev-all` /
105
+ * `make test-rebuild` / `make prove-up` are examples of a consumer Makefile —
106
+ * turning them into "rungate's ship.js must contain this string" is a false
107
+ * assertion about a different project.
108
+ *
109
+ * This was always true; it only started firing when #225 made the collectors
110
+ * recursive and the consumer-facing specs became visible for the first time.
111
+ * The opt-out is frontmatter rather than a path rule so it stays explicit and
112
+ * reviewable, and so making a spec visible to the conformity engine and making
113
+ * it a source of harness claims remain two separate decisions.
114
+ */
115
+ function parseWorkflowClaims(content: string): boolean {
116
+ const fm = content.match(/^---\n([\s\S]*?)\n---/);
117
+ if (!fm) return true;
118
+ return !/^workflow-claims:\s*false\s*$/m.test(fm[1]);
119
+ }
120
+
121
+ function discoverTestableSpecs(specsDir: string): { path: string; name: string }[] {
122
+ const files = collectSpecFiles(specsDir); // #225 — subdirectories too
36
123
  const testable: { path: string; name: string }[] = [];
37
124
  for (const f of files) {
38
- const fullPath = join(SPECS_DIR, f);
125
+ const fullPath = join(specsDir, f);
39
126
  const content = readFileSync(fullPath, "utf-8");
40
- if (parseTestable(content) === true) {
127
+ if (parseTestable(content) === true && parseWorkflowClaims(content)) {
41
128
  testable.push({ path: fullPath, name: f });
42
129
  }
43
130
  }
@@ -54,116 +141,93 @@ interface Claim {
54
141
  context: string;
55
142
  }
56
143
 
57
- function extractClaims(spec: string): Claim[] {
58
- const claims: Claim[] = [];
59
- const lines = spec.split("\n");
60
- let claimCounter = 0;
61
-
62
- for (let i = 0; i < lines.length; i++) {
63
- const line = lines[i];
64
- const lineNum = i + 1;
65
-
66
- // Make commands: make test-up, make prove-up, make test-rebuild, make rebuild
67
- const makeMatch = line.match(/`(make\s+[\w-]+)`/);
68
- if (makeMatch) {
69
- const cmd = makeMatch[1];
70
- // Determine target based on section context and command name
71
- const isProveSection = lines.slice(Math.max(0, i - 30), i).some(l => /Step 4.*PROVE|PROVE.*post-merge|Layer 3.*Prove/i.test(l));
72
- const isReleaseSection = lines.slice(Math.max(0, i - 20), i).some(l => /Step 5.*RELEASE|RELEASE/i.test(l));
73
- // Skip release commands — they belong to release skill, not ship/prove
74
- if (isReleaseSection) continue;
75
- const target = isProveSection || cmd.includes("prove") ? "prove" : "ship";
76
- // For ship, test-up may have been upgraded to test-rebuild — check for either
77
- const searchTerm = cmd.replace("make ", "");
78
- claims.push({
79
- id: `AUTO-MAKE-${++claimCounter}`,
80
- spec_line: lineNum,
81
- claim: `Spec requires make ${searchTerm}`,
82
- target,
83
- assertion_type: "contains",
84
- search_term: searchTerm,
85
- context: line.trim().slice(0, 100),
86
- });
87
- }
88
-
89
- // GATE markers
90
- if (line.includes("**GATE:") || line.includes("**Gate:**")) {
91
- const gateText = line.replace(/\*\*/g, "").replace("GATE:", "").replace("Gate:", "").trim();
92
- const target = line.toLowerCase().includes("prove") ? "prove" : "ship";
93
- claims.push({
94
- id: `AUTO-GATE-${++claimCounter}`,
95
- spec_line: lineNum,
96
- claim: `Gate: ${gateText.slice(0, 80)}`,
97
- target,
98
- assertion_type: "contains",
99
- search_term: gateText.includes("Quinn") ? "quinn" : gateText.includes("Ship gate") ? "ship" : "gate",
100
- context: line.trim().slice(0, 100),
101
- });
102
- }
103
-
104
- // Port references in context of specific tools
105
- const portMatch = line.match(/:(\d{4})\b/);
106
- if (portMatch) {
107
- const port = portMatch[1];
108
- if (["7776", "7777", "7778", "5173"].includes(port)) {
109
- // Determine which file should reference this port
110
- const isProveSection = lines.slice(Math.max(0, i - 20), i).some(l => /Step 4.*PROVE|PROVE.*post-merge/i.test(l));
111
- const target = isProveSection ? "prove" : "ship";
112
- claims.push({
113
- id: `AUTO-PORT-${++claimCounter}`,
114
- spec_line: lineNum,
115
- claim: `Port ${port} referenced in ${isProveSection ? "PROVE" : "SHIP"} context`,
116
- target,
117
- assertion_type: "port",
118
- search_term: port,
119
- context: line.trim().slice(0, 100),
120
- });
121
- }
122
- }
123
-
124
- // Quinn + action verb patterns
125
- const quinnMatch = line.match(/Quinn\s+(validates|captures|tests|navigates|compares|verifies)/i);
126
- if (quinnMatch) {
127
- const action = quinnMatch[1].toLowerCase();
128
- const isProveSection = lines.slice(Math.max(0, i - 20), i).some(l => /Step 4.*PROVE|PROVE.*post-merge/i.test(l));
129
- const target = isProveSection ? "prove" : "ship";
130
- claims.push({
131
- id: `AUTO-QUINN-${++claimCounter}`,
132
- spec_line: lineNum,
133
- claim: `Quinn ${action} in ${isProveSection ? "PROVE" : "SHIP"}`,
134
- target,
135
- assertion_type: "contains",
136
- search_term: "quinn",
137
- context: line.trim().slice(0, 100),
138
- });
139
- }
140
- }
141
-
142
- // Deduplicate by search_term + target
143
- const seen = new Set<string>();
144
- return claims.filter(c => {
145
- const key = `${c.target}:${c.assertion_type}:${c.search_term}`;
146
- if (seen.has(key)) return false;
147
- seen.add(key);
148
- return true;
149
- });
144
+ /**
145
+ * #277/#343 — this emitted twelve assertions, every one of which was a bare
146
+ * substring presence check against a 4,000-line workflow file.
147
+ *
148
+ * Four claim shapes were extracted from spec prose — \`make x\`, \`**GATE:**\`,
149
+ * a port number, and "Quinn <verb>" — and each became
150
+ * \`expect(SHIP_JS.toLowerCase()).toContain(<search_term>)\` where the search
151
+ * term was a generic word lifted out of the sentence. Counted in ship.js:
152
+ *
153
+ * "gate" 196 occurrences
154
+ * "ship" 264
155
+ * "quinn" 94
156
+ * "rebuild" 17
157
+ * "x" 563 <- from the literal spec phrase \`make x\`
158
+ *
159
+ * None of them could fail. Not "unlikely to fail" — the terms are structural
160
+ * vocabulary of the file being searched, so the assertions were true before
161
+ * the spec sentence existed and would stay true if the behaviour were
162
+ * deleted. Twelve named checks, zero measurement, counted in the suite total
163
+ * and in every compliance report.
164
+ *
165
+ * Found because an SC line added in #343 — about REMOVING a hardcoded
166
+ * \`make rebuild\` — matched the \`make x\` shape and generated a thirteenth
167
+ * test asserting ship.js contains "rebuild". A spec sentence describing the
168
+ * deletion of a thing generated a test demanding its presence.
169
+ *
170
+ * Removed rather than weakened, which is what #315 did with
171
+ * \`evidence-target-valid\` for the same reason: a name in a report with
172
+ * nothing behind it is worse than an absence, because the absence is visible.
173
+ * Rebuilding spec-claim extraction with assertions that can fail is real
174
+ * work with a real design question behind it — what IS the checkable content
175
+ * of "Spec requires make rebuild"? — and it is not done by keeping these.
176
+ *
177
+ * \`test/spec-compliance-config.test.ts\` holds the hand-written checks that
178
+ * used to live in the generated file and are genuinely load-bearing.
179
+ */
180
+ function extractClaims(_spec: string): Claim[] {
181
+ return [];
150
182
  }
151
183
 
152
184
  function generateTest(claims: Claim[]): string {
185
+ // No claims means no file worth importing: the header alone would read
186
+ // `workflows/ship.js` at module scope to populate two constants nothing
187
+ // uses, so a missing workflow file would fail a suite that asserts nothing.
188
+ if (claims.length === 0) {
189
+ return [
190
+ `// AUTO-GENERATED by scripts/sync-spec-tests.ts — do not edit manually`,
191
+ `// Regenerate: bun scripts/sync-spec-tests.ts`,
192
+ ``,
193
+ `// No generated claims. extractClaims returns nothing on purpose — see the`,
194
+ `// docblock above it in scripts/sync-spec-tests.ts. The twelve assertions`,
195
+ `// this file used to hold were bare substring checks for words like "gate"`,
196
+ `// and "ship" against a file containing them 196 and 264 times.`,
197
+ `//`,
198
+ `// Hand-written spec-compliance checks live in`,
199
+ `// test/spec-compliance-config.test.ts and test/spec-compliance.test.ts.`,
200
+ ``,
201
+ ].join("\n");
202
+ }
203
+
153
204
  const shipClaims = claims.filter(c => c.target === "ship" || c.target === "both");
154
205
  const proveClaims = claims.filter(c => c.target === "prove" || c.target === "both");
155
206
 
156
207
  const lines: string[] = [
157
208
  `// AUTO-GENERATED by scripts/sync-spec-tests.ts — do not edit manually`,
158
209
  `// Regenerate: bun scripts/sync-spec-tests.ts`,
159
- `// Source: PAI/specs/HARNESS-SKILL-CHAIN.md`,
210
+ `// Source: specs/ (every spec with testable: true)`,
160
211
  `// Generated: ${new Date().toISOString().split("T")[0]}`,
161
212
  ``,
162
213
  `import { test, expect, describe } from "bun:test";`,
163
214
  `import { readFileSync } from "fs";`,
215
+ `import { join } from "path";`,
216
+ `import { harnessRootFor } from "../lib/paths";`,
164
217
  ``,
165
- `const SHIP_JS = readFileSync("${SHIP_PATH}", "utf-8");`,
166
- `const PROVE_JS = readFileSync("${PROVE_PATH}", "utf-8");`,
218
+ `// Resolved at run time, not baked in: an absolute path written by whoever`,
219
+ `// last ran the generator makes the file unrunnable anywhere else, CI`,
220
+ `// included.`,
221
+ `//`,
222
+ `// Resolved from THIS file's own location, not from the implicit`,
223
+ `// module-relative root (#190). These cases grade workflows/ship.js, and`,
224
+ `// the implicit root honours HARNESS_ROOT — so a run with it set read a`,
225
+ `// different checkout's ship.js than the one this file was generated`,
226
+ `// from. A generated test grading a tree it does not belong to reports`,
227
+ `// failures that exist in nobody's checkout.`,
228
+ `const HR = harnessRootFor(join(import.meta.dir, ".."));`,
229
+ `const SHIP_JS = readFileSync(join(HR, "workflows/ship.js"), "utf-8");`,
230
+ `const PROVE_JS = readFileSync(join(HR, "workflows/prove.js"), "utf-8");`,
167
231
  ``,
168
232
  ];
169
233
 
@@ -209,28 +273,49 @@ function generateTest(claims: Claim[]): string {
209
273
  return lines.join("\n") + "\n";
210
274
  }
211
275
 
212
- // Main — glob scan all testable specs
213
- const testableSpecs = discoverTestableSpecs();
214
- const allFiles = readdirSync(SPECS_DIR).filter(f => f.endsWith(".md"));
276
+ // Main — glob scan all testable specs.
277
+ //
278
+ // Behind `import.meta.main` so importing this module for its pure path
279
+ // helpers does not rewrite a test file as a side effect of the import. The
280
+ // test that covers resolveSyncPaths does exactly that import, and without
281
+ // this guard it regenerated the suite's own source mid-run.
282
+ export function main(root: string) {
283
+ const { specsDir: SPECS_DIR, outputPath: OUTPUT_PATH } = resolveSyncPaths(root);
284
+
285
+ // Fail loudly on a missing spec directory. The previous version could not:
286
+ // `~/.claude/PAI/Specs` happened to exist, so reading the wrong tree looked
287
+ // exactly like reading the right one.
288
+ if (!existsSync(SPECS_DIR)) {
289
+ console.error(
290
+ `sync-spec-tests: no spec directory at ${SPECS_DIR}\n` +
291
+ ` (harness root given as ${root} — pass the root as argv[2] if that is wrong)`,
292
+ );
293
+ process.exit(1);
294
+ }
215
295
 
216
- console.log(`Spec discovery: ${allFiles.length} specs scanned, ${testableSpecs.length} testable`);
296
+ const testableSpecs = discoverTestableSpecs(SPECS_DIR);
297
+ const allFiles = collectSpecFiles(SPECS_DIR); // #225 — subdirectories too
217
298
 
218
- let allClaims: Claim[] = [];
219
- for (const spec of testableSpecs) {
220
- const content = readFileSync(spec.path, "utf-8");
221
- const claims = extractClaims(content);
222
- allClaims = allClaims.concat(claims);
223
- console.log(` ${spec.name}: ${claims.length} claims`);
224
- }
299
+ console.log(`Spec discovery: ${allFiles.length} specs scanned, ${testableSpecs.length} testable`);
300
+
301
+ let allClaims: Claim[] = [];
302
+ for (const spec of testableSpecs) {
303
+ const content = readFileSync(spec.path, "utf-8");
304
+ const claims = extractClaims(content);
305
+ allClaims = allClaims.concat(claims);
306
+ console.log(` ${spec.name}: ${claims.length} claims`);
307
+ }
225
308
 
226
- const testContent = generateTest(allClaims);
227
- writeFileSync(OUTPUT_PATH, testContent);
309
+ writeFileSync(OUTPUT_PATH, generateTest(allClaims));
228
310
 
229
- console.log(`\nTotal: ${allClaims.length} claims extracted`);
230
- console.log(` ship.js: ${allClaims.filter(c => c.target === "ship").length}`);
231
- console.log(` prove.js: ${allClaims.filter(c => c.target === "prove").length}`);
232
- console.log(`Written to: ${OUTPUT_PATH}`);
311
+ console.log(`\nTotal: ${allClaims.length} claims extracted`);
312
+ console.log(` ship.js: ${allClaims.filter(c => c.target === "ship").length}`);
313
+ console.log(` prove.js: ${allClaims.filter(c => c.target === "prove").length}`);
314
+ console.log(`Written to: ${OUTPUT_PATH}`);
233
315
 
234
- for (const c of allClaims) {
235
- console.log(` ${c.id} [${c.target}] L${c.spec_line}: ${c.claim}`);
316
+ for (const c of allClaims) {
317
+ console.log(` ${c.id} [${c.target}] L${c.spec_line}: ${c.claim}`);
318
+ }
236
319
  }
320
+
321
+ if (import.meta.main) main(syncRoot());