@kirill.konshin/lint 0.6.0 → 0.6.1

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 (51) hide show
  1. package/README.md +7 -7
  2. package/dist/lib.js +2 -1
  3. package/package.json +4 -6
  4. package/skills/spec-steward/SKILL.md +2 -2
  5. package/skills/spec-steward/references/contract.md +7 -7
  6. package/skills/spec-tools/SKILL.md +3 -1
  7. package/skills/spec-tools/references/contract.md +1 -1
  8. package/skills/spec-tools/references/gitlab.md +20 -22
  9. package/skills/spec-tools/scripts/cli.js +8129 -0
  10. package/skills/spec-verify/SKILL.md +2 -2
  11. package/skills/spec-steward/scripts/lib/align.mjs +0 -127
  12. package/skills/spec-steward/scripts/lib/checks.mjs +0 -589
  13. package/skills/spec-steward/scripts/lib/citations.mjs +0 -156
  14. package/skills/spec-steward/scripts/lib/corpus.mjs +0 -256
  15. package/skills/spec-steward/scripts/lib/coverage.mjs +0 -123
  16. package/skills/spec-steward/scripts/lib/evidence.mjs +0 -189
  17. package/skills/spec-steward/scripts/lib/git.mjs +0 -138
  18. package/skills/spec-steward/scripts/lib/review.mjs +0 -347
  19. package/skills/spec-steward/scripts/lib/scan.mjs +0 -364
  20. package/skills/spec-steward/scripts/lib/util.mjs +0 -161
  21. package/skills/spec-steward/scripts/lib/wire.mjs +0 -333
  22. package/skills/spec-steward/scripts/steward.mjs +0 -289
  23. package/spec-tools/dist/audit-DkZZulq6.mjs +0 -130
  24. package/spec-tools/dist/auditChanged-CNGjlake.mjs +0 -1
  25. package/spec-tools/dist/auditChanged-CZCvMgyZ.mjs +0 -618
  26. package/spec-tools/dist/auditReport-xgq4wK2i.mjs +0 -458
  27. package/spec-tools/dist/auditScope-CBuBtfPG.mjs +0 -104
  28. package/spec-tools/dist/changeGates-DdeQKfle.mjs +0 -333
  29. package/spec-tools/dist/changeGates-uy4Ti8rK.mjs +0 -1
  30. package/spec-tools/dist/ci-BUewHJS3.mjs +0 -143
  31. package/spec-tools/dist/ci-CFBzn8Of.mjs +0 -1
  32. package/spec-tools/dist/cli.mjs +0 -93
  33. package/spec-tools/dist/comment-szasMMg2.mjs +0 -57
  34. package/spec-tools/dist/files-Bppsb34B.mjs +0 -1
  35. package/spec-tools/dist/files-QlzY687_.mjs +0 -38
  36. package/spec-tools/dist/html-BMTkpbUN.mjs +0 -1766
  37. package/spec-tools/dist/jsonrepair-Dlm5dEen.mjs +0 -742
  38. package/spec-tools/dist/repo-CjIoUPYl.mjs +0 -16
  39. package/spec-tools/dist/repo-DUcnJw3c.mjs +0 -1
  40. package/spec-tools/dist/run-BElA9du3.mjs +0 -67
  41. package/spec-tools/dist/specDiff-8G56jMYn.mjs +0 -123
  42. package/spec-tools/dist/steward-DeieyOcj.mjs +0 -34
  43. package/spec-tools/dist/stewardAudit-BRMM0lrD.mjs +0 -1
  44. package/spec-tools/dist/stewardAudit-v0vOMfLN.mjs +0 -271
  45. package/spec-tools/dist/tier-Cn0P7juM.mjs +0 -1
  46. package/spec-tools/dist/tier-c3s_mA_I.mjs +0 -65
  47. package/spec-tools/dist/util-wnxhsnWO.mjs +0 -49
  48. package/spec-tools/dist/verdict-BFfN9PO8.mjs +0 -58
  49. package/spec-tools/dist/workers-BcIgckeq.mjs +0 -417
  50. package/spec-tools/dist/workflowEvidence-DyBj8EdG.mjs +0 -1
  51. package/spec-tools/dist/workflowEvidence-oui6ghPI.mjs +0 -78
@@ -1,458 +0,0 @@
1
- import { c as SCOPE_JSON, i as FINDINGS_DIR, l as UNITS_FILE, o as REPORT_FILE, s as REPORT_JSON, u as VERIFIED_MARKER } from "./files-QlzY687_.mjs";
2
- import { n as root } from "./repo-CjIoUPYl.mjs";
3
- import { t as jsonrepair } from "./jsonrepair-Dlm5dEen.mjs";
4
- import { execFileSync } from "node:child_process";
5
- import * as fs from "node:fs";
6
- import * as path from "node:path";
7
- //#region spec-tools/src/auditReport.ts
8
- /**
9
- * The specification audit's report, merged mechanically from what each worker judged. A worker
10
- * writes its part's findings as JSON; nothing here judges again. What this does is what needs no
11
- * judgment: every ERROR's quotes are looked up at their `file:line` in the audited commit — `HEAD`,
12
- * which no worker can edit, or the working tree with `--worktree` when the working tree is what
13
- * `spec-tools audit --here` audits — and a finding whose quotes are not there is WARN; kinds are tiered
14
- * by the contract's list, and a finding against an ⚠️ Advisory requirement is at most WARN;
15
- * coverage is the weakest part's; the verdict follows from those; and the Markdown CI and the reader
16
- * consume is rendered from it. The JSON files stay beside the report for debugging.
17
- * Usage: spec-tools report [--gate] [--worktree]
18
- */
19
- /** One merge of a run, as it stood after the pass before it: `audit-parts/findings/merge-<n>.json`. */
20
- const MERGE_FILE = /^merge-\d+\.json$/;
21
- /** One verifier's answer over one ERROR: `audit-parts/findings/verdict-<k>.json`. */
22
- const VERDICT_FILE = /^verdict-(\d+)\.json$/;
23
- const ERROR_CLASS = [
24
- "code-mismatch",
25
- "conflict",
26
- "undeclared-gap"
27
- ];
28
- const INFO_CLASS = ["spec-dup", "untested"];
29
- /** The checks every reader runs over every requirement of its part — the `spec-verify` skill's numbering. */
30
- const CHECKS = {
31
- "1": "Gap honesty",
32
- "2": "Contradictory rules",
33
- "3": "A rule redundant with, or substantially overlapping, another",
34
- "4": "A rule that no longer matches the implementation or architecture",
35
- "5": "A rule whose tests satisfy the wording while failing to protect the intent"
36
- };
37
- /** The status a coverage entry states, and its note; anything unreadable ran nothing. */
38
- function coverageEntry(value) {
39
- const m = typeof value === "string" ? /^\s*(full|sampled|not-run)\b[\s:—-]*(.*)$/s.exec(value) : null;
40
- if (!m) return {
41
- status: "not-run",
42
- note: value === void 0 ? void 0 : `unreadable coverage entry ${JSON.stringify(value)}`
43
- };
44
- return {
45
- status: m[1],
46
- note: m[2]?.trim() || void 0
47
- };
48
- }
49
- const normalize = (s) => s.replace(/\s+/g, " ").trim();
50
- /**
51
- * Whether the quote is really at its line: the normalized quote appears in the normalized text of the
52
- * lines starting at the cited line or one above and running one line past what the quote spans — so a
53
- * fragment may run onto the next line and a worker copying from a numbered excerpt may be one line
54
- * out, never more.
55
- */
56
- function quoteFound(quote, lines) {
57
- if (!lines) return false;
58
- const wanted = normalize(quote.text);
59
- if (wanted === "") return false;
60
- const span = quote.text.split("\n").length + 1;
61
- for (const start of [quote.line - 1, quote.line - 2]) {
62
- if (start < 0 || start >= lines.length) continue;
63
- if (normalize(lines.slice(start, start + span).join(" ")).includes(wanted)) return true;
64
- }
65
- return false;
66
- }
67
- /** The audit's own artifacts are not evidence: a quote must come from a specification or a source. */
68
- const isGenerated = (file) => file.startsWith(`audit-parts/`) || /^(spec-verify|spec-review|spec-coverage|audit-scope)\.(md|json)$/.test(file);
69
- /** Files as a commit carries them: `git show <ref>:<file>` — what no worker's edit of the tree can reach. */
70
- const gitReader = (ref, cwd = root()) => (file) => {
71
- try {
72
- return execFileSync("git", ["show", `${ref}:${file}`], {
73
- cwd,
74
- encoding: "utf8",
75
- maxBuffer: 67108864,
76
- stdio: [
77
- "ignore",
78
- "pipe",
79
- "ignore"
80
- ]
81
- }).split("\n");
82
- } catch {
83
- return;
84
- }
85
- };
86
- /** The audited commit: `HEAD`, the tree CI checked out and `spec-tools audit`'s detached worktree. */
87
- const commitReader = gitReader("HEAD");
88
- /** A file as the working tree carries it — the audited tree of `spec-tools audit --here` alone. */
89
- const worktreeReader = (file) => {
90
- try {
91
- return fs.readFileSync(path.join(root(), file), "utf8").split("\n");
92
- } catch {
93
- return;
94
- }
95
- };
96
- /**
97
- * The tier a finding earns: INFO-class kinds are INFO however the worker graded them; an ERROR-class
98
- * kind is ERROR only when the worker claimed it and at least two of its quotes — both sides — are
99
- * found at their lines, and WARN otherwise, saying why; and a finding against an ⚠️ Advisory
100
- * requirement is at most WARN. A kind the contract does not name is recorded as INFO with the
101
- * note, never invented into a failure.
102
- */
103
- function grade(finding, part, read, advisory) {
104
- const graded = gradeKind(finding, part, read);
105
- if (graded.tier !== "ERROR" || !advisory?.has(unitOf(finding.where))) return graded;
106
- return {
107
- ...graded,
108
- tier: "WARN",
109
- regraded: "the requirement is ⚠️ Advisory: a finding against it is at most WARN"
110
- };
111
- }
112
- function gradeKind(finding, part, read) {
113
- const kind = finding.kind;
114
- if (INFO_CLASS.includes(kind)) return {
115
- ...finding,
116
- tier: "INFO",
117
- part,
118
- regraded: finding.tier === "INFO" ? void 0 : `${kind} is INFO-class`
119
- };
120
- if (!ERROR_CLASS.includes(kind)) return {
121
- ...finding,
122
- tier: "INFO",
123
- part,
124
- regraded: `kind \`${kind}\` is not in the contract's list`
125
- };
126
- if (finding.tier !== "ERROR") return {
127
- ...finding,
128
- tier: "WARN",
129
- part,
130
- regraded: finding.tier === "WARN" ? void 0 : "ERROR-class kinds are WARN at least"
131
- };
132
- const quotes = (finding.quotes ?? []).filter((q) => !isGenerated(q.file));
133
- const missing = quotes.filter((q) => !quoteFound(q, read(q.file)));
134
- if (quotes.length < 2) return {
135
- ...finding,
136
- tier: "WARN",
137
- part,
138
- regraded: "ERROR needs both sides quoted from the sources; fewer than two such quotes"
139
- };
140
- if (missing.length > 0) return {
141
- ...finding,
142
- tier: "WARN",
143
- part,
144
- regraded: `re-proof failed: not found at ${missing.map((q) => `\`${q.file}:${q.line}\``).join(", ")}`
145
- };
146
- return {
147
- ...finding,
148
- tier: "ERROR",
149
- part
150
- };
151
- }
152
- const rank = {
153
- full: 0,
154
- sampled: 1,
155
- "not-run": 2
156
- };
157
- /**
158
- * A part's coverage of a check is the best any of its readers achieved — two readers judge the same
159
- * evidence independently, so the part is covered when either judged it all. A part none of whose
160
- * readers reported ran nothing.
161
- */
162
- function partCoverage(readers, check) {
163
- const present = readers.filter((r) => r !== void 0);
164
- if (present.length === 0) return {
165
- status: "not-run",
166
- note: "no findings file"
167
- };
168
- return present.map((r) => coverageEntry(r.coverage?.[check])).reduce((best, e) => rank[e.status] < rank[best.status] ? e : best);
169
- }
170
- /**
171
- * The requirements of a part no reader listed as judged. A reader's claim of full coverage is only as
172
- * good as its judged list: a requirement absent from every reader's list was not judged, whatever the
173
- * coverage string says, and a reader with no judged list judged nothing that can be shown.
174
- */
175
- function unjudged(readers, expected) {
176
- const judged = new Set(readers.flatMap((r) => r?.judged ?? []));
177
- return expected.filter((id) => !judged.has(id));
178
- }
179
- /**
180
- * The audit's coverage per check is its weakest part's. Every part owns every check, and every check runs
181
- * requirement by requirement, so each is also bounded by the readers' judged lists.
182
- */
183
- function mergeCoverage(parts, expected) {
184
- const merged = Object.fromEntries(Object.keys(CHECKS).map((c) => [c, {
185
- status: "full",
186
- parts: [],
187
- notes: []
188
- }]));
189
- for (const [n, readers] of [...parts].sort(([a], [b]) => a - b)) {
190
- const ids = expected?.get(n) ?? [];
191
- const missed = ids.length ? unjudged(readers, ids) : [];
192
- for (const check of Object.keys(CHECKS)) {
193
- let entry = partCoverage(readers, check);
194
- if (missed.length && entry.status === "full") {
195
- const shown = missed.slice(0, 5).map((id) => `\`${id}\``).join(", ");
196
- entry = {
197
- status: "sampled",
198
- note: `judged list names ${ids.length - missed.length} of ${ids.length} requirements; not judged: ${shown}${missed.length > 5 ? ` and ${missed.length - 5} more` : ""}`
199
- };
200
- }
201
- const slot = merged[check];
202
- if (entry.status !== "full") {
203
- slot.parts.push(n);
204
- if (entry.note) slot.notes.push(`part ${n}: ${entry.note}`);
205
- }
206
- if (rank[entry.status] > rank[slot.status]) slot.status = entry.status;
207
- }
208
- }
209
- return merged;
210
- }
211
- function shortList(parts, expected) {
212
- const out = [];
213
- for (const [n, readers] of [...parts].sort(([a], [b]) => a - b)) {
214
- const ids = expected.get(n) ?? [];
215
- const requirementIds = ids.length ? unjudged(readers, ids) : [];
216
- const checks = {};
217
- for (const check of Object.keys(CHECKS)) {
218
- const entry = partCoverage(readers, check);
219
- if (entry.status !== "full") checks[check] = `${entry.status}${entry.note ? `: ${entry.note}` : ""}`;
220
- }
221
- if (requirementIds.length || Object.keys(checks).length) out.push({
222
- part: n,
223
- requirementIds,
224
- checks
225
- });
226
- }
227
- return out;
228
- }
229
- /**
230
- * The findings files a part has: the ones the scope lists, then any further `part-<n>-<reader>.json`
231
- * present — a completion worker writes the part's next reader number, and the merge reads it the
232
- * way it reads a second independent reader.
233
- */
234
- function readerFiles(listed, present, part) {
235
- const own = new RegExp(`(^|/)part-${part}-\\d+\\.json$`);
236
- const extra = present.filter((f) => own.test(f) && !listed.includes(f)).sort();
237
- return [...listed, ...extra];
238
- }
239
- const tierRank = {
240
- ERROR: 0,
241
- WARN: 1,
242
- INFO: 2
243
- };
244
- /**
245
- * Two readers of one part report the same defect in their own words; it is one finding. Two
246
- * findings are the same when they share a kind and a quoted `file:line`, or a kind and a `where`;
247
- * the better-proved twin stands.
248
- */
249
- function dedupe(findings) {
250
- const kept = [];
251
- const sameQuote = (a, b) => (a.quotes ?? []).some((q) => (b.quotes ?? []).some((p) => p.file === q.file && p.line === q.line));
252
- for (const f of findings) {
253
- const at = kept.findIndex((k) => k.kind === f.kind && (normalize(k.where) === normalize(f.where) || sameQuote(k, f)));
254
- if (at === -1) kept.push(f);
255
- else if (tierRank[f.tier] < tierRank[kept[at].tier]) kept[at] = f;
256
- }
257
- return kept;
258
- }
259
- /**
260
- * The verification pass's answers, applied. An ERROR the workers demonstrated is put to one more reader
261
- * over that finding alone, which confirms it only when the divergence is real and critical — an obvious
262
- * code defect, or a statement that would steer an agent wrongly — and otherwise lowers it to WARN with
263
- * its reason. One the pass never reached (no verdict written although the pass ran) stands on its quotes
264
- * and says so; without the pass, nothing changes. WARN and INFO are never touched. A verdict answers the ERROR
265
- * at its position: `verdict-<k>.json` is the k-th ERROR of the merge the verification pass started from, and the
266
- * merge after it, over the same findings files, lists the same ERRORs in the same order.
267
- */
268
- function applyVerdicts(findings, verdicts, ran) {
269
- let k = 0;
270
- return findings.map((f) => {
271
- if (f.tier !== "ERROR") return f;
272
- const v = verdicts.get(++k);
273
- if (!v) return ran ? {
274
- ...f,
275
- verified: "unverified — the verifier wrote no verdict; the finding stands on its quotes"
276
- } : f;
277
- return v.verdict === "confirmed" ? {
278
- ...f,
279
- verified: `confirmed — ${v.reason}`
280
- } : {
281
- ...f,
282
- tier: "WARN",
283
- verified: `not confirmed — ${v.reason}`
284
- };
285
- });
286
- }
287
- /** Every verdict file the verification pass wrote, by the ERROR's position; one that does not parse is reported and skipped. */
288
- function readVerdicts(problems) {
289
- const dir = path.join(root(), FINDINGS_DIR);
290
- const out = /* @__PURE__ */ new Map();
291
- if (!fs.existsSync(dir)) return out;
292
- for (const name of fs.readdirSync(dir).sort()) {
293
- const k = VERDICT_FILE.exec(name)?.[1];
294
- if (!k) continue;
295
- try {
296
- const v = JSON.parse(jsonrepair(fs.readFileSync(path.join(dir, name), "utf8")));
297
- if (v.verdict !== "confirmed" && v.verdict !== "warn") throw new Error("missing `verdict`");
298
- out.set(Number(k), v);
299
- } catch (error) {
300
- problems.push(`\`${FINDINGS_DIR}/${name}\` is not a valid verdict: ${error.message} — its ERROR stands on its quotes.`);
301
- }
302
- }
303
- return out;
304
- }
305
- function verdict(findings, coverage) {
306
- const errors = findings.filter((f) => f.tier === "ERROR").length;
307
- const warnings = findings.filter((f) => f.tier === "WARN").length;
308
- const incomplete = Object.values(coverage).some((c) => c.status !== "full");
309
- const state = errors > 0 ? "FAIL" : incomplete ? "INCOMPLETE" : "PASS";
310
- return {
311
- state,
312
- errors,
313
- warnings,
314
- line: `${state} (${errors} errors, ${warnings} warnings)`
315
- };
316
- }
317
- /**
318
- * The exit code a verdict earns when the report gates a run: 0 on PASS, 1 on FAIL, 3 on INCOMPLETE — an
319
- * allowed failure, so the job is marked failed and the pipeline continues.
320
- */
321
- const exitCodeFor = (state) => state === "FAIL" ? 1 : state === "INCOMPLETE" ? 3 : 0;
322
- /** The unit a finding is about: the requirement id its `where` opens with. */
323
- const unitOf = (where) => where.split(" ")[0];
324
- /** A finding's first sentence, which is all the developer's report shows of its detail. */
325
- const firstSentence = (text) => {
326
- const flat = normalize(text);
327
- const end = flat.search(/[.!?](\s|$)/);
328
- return end === -1 ? flat : flat.slice(0, end + 1);
329
- };
330
- /** One ERROR or WARN as the developer reads it: kind, place, requirement, what drifted, why it was regraded, the verifier's word. */
331
- const findingLine = (f) => {
332
- const [requirement, at] = f.where.split(" / ");
333
- const place = at ?? (f.quotes?.[0] ? `${f.quotes[0].file}:${f.quotes[0].line}` : void 0);
334
- return [
335
- `- \`${f.kind}\``,
336
- place ? ` \`${place}\`` : "",
337
- ` — \`${requirement}\``,
338
- ` — ${firstSentence(f.detail)}`,
339
- f.regraded ? ` — _${f.regraded}_` : "",
340
- f.verified ? ` — _${f.verified}_` : ""
341
- ].join("");
342
- };
343
- /**
344
- * The developer's report: the verdict, what errored and what drifted — one line each — the INFO findings as counts,
345
- * and the checks that fell short. Quotes, full details and INFO findings are in `spec-verify.json`.
346
- */
347
- function render(scopeHeader, findings, coverage, problems) {
348
- const out = [
349
- verdict(findings, coverage).line,
350
- "",
351
- ...scopeHeader,
352
- ""
353
- ];
354
- if (problems.length) out.push("## Problems with the workers' output", "", ...problems.map((p) => `- ${p}`), "");
355
- for (const [tier, title] of [["ERROR", "Errors — demonstrated and confirmed"], ["WARN", "Warnings — suspected, or not confirmed"]]) {
356
- const items = findings.filter((f) => f.tier === tier).sort((a, b) => a.kind.localeCompare(b.kind) || a.where.localeCompare(b.where));
357
- if (items.length) out.push(`## ${title}`, "", ...items.map(findingLine), "");
358
- }
359
- const info = /* @__PURE__ */ new Map();
360
- for (const f of findings) if (f.tier === "INFO") info.set(f.kind, (info.get(f.kind) ?? 0) + 1);
361
- if (info.size) out.push("## Info", "", ...[...info].sort().map(([k, n]) => `- \`${k}\`: ${n}`), "");
362
- const short = Object.entries(CHECKS).filter(([c]) => coverage[c].status !== "full");
363
- if (short.length) {
364
- out.push("## Coverage short", "");
365
- for (const [c, name] of short) {
366
- const m = coverage[c];
367
- out.push(`- ${c}. ${name}: ${m.status} — parts ${m.parts.join(", ")}${m.notes.length ? ` — ${m.notes.join("; ")}` : ""}`);
368
- }
369
- out.push("");
370
- }
371
- return out.join("\n");
372
- }
373
- /** The report's first lines after the verdict: the scope. */
374
- function scopeHeader(scope) {
375
- if (scope.scope === "affected") return [
376
- "SCOPE affected",
377
- "",
378
- scope.parts.length === 0 ? `The affected set against \`${scope.base ?? "?"}\` is empty — nothing to judge.` : `The affected set against \`${scope.base ?? "?"}\`: ${(scope.capabilities ?? []).length} capabilities in ${scope.parts.length} parts.`
379
- ];
380
- return [
381
- "SCOPE all",
382
- "",
383
- `Every capability under \`openspec/specs/\`, in ${scope.parts.length} parts.`
384
- ];
385
- }
386
- function main(read = commitReader) {
387
- const scopePath = path.join(root(), SCOPE_JSON);
388
- const unitsPath = path.join(root(), UNITS_FILE);
389
- const units = fs.existsSync(unitsPath) ? JSON.parse(fs.readFileSync(unitsPath, "utf8")) : {};
390
- const advisory = new Set(Object.entries(units).flatMap(([id, u]) => u.advisory ? [id] : []));
391
- const scope = fs.existsSync(scopePath) ? JSON.parse(fs.readFileSync(scopePath, "utf8")) : void 0;
392
- const problems = [];
393
- if (!scope) problems.push(`\`${SCOPE_JSON}\` is missing — run \`spec-tools scope\` first; one part assumed.`);
394
- const header = scope ? scopeHeader(scope) : ["SCOPE unknown"];
395
- const expected = scope ? scope.parts.length : 1;
396
- const parts = /* @__PURE__ */ new Map();
397
- const readers = scope?.readers ?? 1;
398
- const readPart = (files, n) => files.map((rel, index) => {
399
- const file = path.join(root(), rel);
400
- if (!fs.existsSync(file)) {
401
- problems.push(`\`${rel}\` was not written — reader ${index + 1} of part ${n} counts as not run.`);
402
- return;
403
- }
404
- try {
405
- const text = fs.readFileSync(file, "utf8");
406
- let parsed;
407
- try {
408
- parsed = JSON.parse(text);
409
- } catch (error) {
410
- parsed = JSON.parse(jsonrepair(text));
411
- problems.push(`\`${rel}\` needed a syntax repair (${error.message}); its content was kept as written.`);
412
- }
413
- if (!Array.isArray(parsed.findings) || typeof parsed.coverage !== "object") throw new Error("missing `findings` or `coverage`");
414
- return {
415
- ...parsed,
416
- part: n,
417
- capabilities: parsed.capabilities ?? []
418
- };
419
- } catch (error) {
420
- problems.push(`\`${rel}\` is not valid: ${error.message} — reader ${index + 1} of part ${n} counts as not run.`);
421
- return;
422
- }
423
- });
424
- const defaults = (n) => Array.from({ length: readers }, (_, r) => `${FINDINGS_DIR}/part-${n}-${r + 1}.json`);
425
- const dir = path.join(root(), FINDINGS_DIR);
426
- const present = fs.existsSync(dir) ? fs.readdirSync(dir).map((f) => `${FINDINGS_DIR}/${f}`) : [];
427
- for (let n = 1; n <= expected; n++) parts.set(n, readPart(readerFiles(scope?.parts[n - 1]?.findings ?? defaults(n), present, n), n));
428
- const findings = applyVerdicts(dedupe([...parts.values()].flatMap((readers) => readers.flatMap((p, index) => p ? p.findings.map((f) => ({
429
- ...grade(f, p.part, read, advisory),
430
- reader: index + 1
431
- })) : []))), readVerdicts(problems), fs.existsSync(path.join(root(), VERIFIED_MARKER)));
432
- const expectedIds = new Map((scope?.parts ?? []).map((p) => [p.part, p.requirementIds ?? []]));
433
- const coverage = mergeCoverage(parts, expectedIds);
434
- const report = render(header, findings, coverage, problems);
435
- fs.writeFileSync(path.join(root(), REPORT_FILE), report);
436
- const v = verdict(findings, coverage);
437
- const json = JSON.stringify({
438
- verdict: v.line,
439
- state: v.state,
440
- errors: v.errors,
441
- warnings: v.warnings,
442
- findings,
443
- short: shortList(parts, expectedIds)
444
- }, null, 2) + "\n";
445
- fs.writeFileSync(path.join(root(), REPORT_JSON), json);
446
- fs.mkdirSync(dir, { recursive: true });
447
- const merges = fs.readdirSync(dir).filter((f) => MERGE_FILE.test(f)).length;
448
- fs.writeFileSync(path.join(dir, `merge-${merges + 1}.json`), json);
449
- return report;
450
- }
451
- /** `spec-tools report [--gate] [--worktree]`: the merge, its verdict line, and with `--gate` the verdict's exit code. */
452
- function cli(argv) {
453
- const line = main(argv.includes("--worktree") ? worktreeReader : commitReader).split("\n")[0];
454
- process.stdout.write(line + "\n");
455
- return argv.includes("--gate") ? exitCodeFor(line.split(" ")[0]) : 0;
456
- }
457
- //#endregion
458
- export { cli, commitReader, worktreeReader };
@@ -1,104 +0,0 @@
1
- import { a as PARTS_DIR, d as findingsFile, t as AUDIT_FILES } from "./files-QlzY687_.mjs";
2
- import { n as root } from "./repo-CjIoUPYl.mjs";
3
- import { d as requirementsOf, f as writeParts, l as PART_BYTES, n as affectedScope, u as loadEvidence } from "./auditChanged-CZCvMgyZ.mjs";
4
- import { a as mergeRequest, r as isNightly, t as diffBase } from "./ci-BUewHJS3.mjs";
5
- import { o as sweepUnits } from "./stewardAudit-v0vOMfLN.mjs";
6
- import * as fs from "node:fs";
7
- import * as path from "node:path";
8
- //#region spec-tools/src/auditScope.ts
9
- /**
10
- * Which scope a run audits: the tier script's decision when it made one, else the corpus on the nightly
11
- * and wherever there is no merge-request target, and the request's affected set otherwise.
12
- */
13
- function modeFor(env = process.env) {
14
- if (env.AUDIT_SCOPE === "affected") return "affected";
15
- if (env.AUDIT_SCOPE === "corpus") return "all";
16
- if (isNightly(env)) return "all";
17
- return mergeRequest(env)?.target ? "affected" : "all";
18
- }
19
- /**
20
- * What judging one requirement costs a worker, in bytes of evidence: a part of 36 requirements finished
21
- * minutes after one of 13 at the same size, so the partition places the heaviest first by both. About two
22
- * kilobytes each.
23
- */
24
- const REQUIREMENT_BYTES = 2048;
25
- const findingsFiles = (part, audit) => Array.from({ length: 1 }, (_, r) => findingsFile(part, r + 1, audit));
26
- /** An evidence file's load on a worker: its evidence, plus the requirements it must walk one by one. */
27
- const load = (w) => w.bytes + w.requirements * REQUIREMENT_BYTES;
28
- /**
29
- * The partition the audit starts from — decided here so the orchestrator opens nothing before its
30
- * workers run. Evidence files are placed heaviest first, by evidence and requirements, each into the first
31
- * part it fits in under `PART_BYTES` — no part is larger than one reader holds unless one file alone is,
32
- * and the evidence alone decides how many parts there are; a scope one reader holds is a single part, and
33
- * nothing in scope is none. A function of the files alone, in whatever order they come: the parts are
34
- * numbered in the order they open, heaviest first, so dealing them out in turn spreads the load evenly.
35
- */
36
- function partition(files, audit = "spec-verify") {
37
- const order = [...files].sort((x, y) => load(y) - load(x) || (x.file < y.file ? -1 : x.file > y.file ? 1 : 0));
38
- const bins = [];
39
- const bytesOf = (bin) => bin.reduce((sum, f) => sum + f.bytes, 0);
40
- for (const f of order) {
41
- const bin = bins.find((b) => bytesOf(b) + f.bytes <= PART_BYTES);
42
- if (bin) bin.push(f);
43
- else bins.push([f]);
44
- }
45
- return bins.map((bin, index) => ({
46
- part: index + 1,
47
- capabilities: [...new Set(bin.map((f) => f.capability))],
48
- files: bin.map((f) => f.file),
49
- findings: findingsFiles(index + 1, audit),
50
- requirementIds: bin.flatMap((f) => f.requirementIds),
51
- bytes: bytesOf(bin),
52
- requirements: bin.reduce((sum, f) => sum + f.requirements, 0)
53
- }));
54
- }
55
- const kb = (bytes) => `${Math.max(1, Math.round(bytes / 1024))} KB`;
56
- function renderScope(parts, kind = "all", detail) {
57
- const lines = [
58
- `SCOPE ${kind}`,
59
- "",
60
- kind === "all" ? "Every capability under `openspec/specs/`: a change can break a rule in a capability it never touched or cited." : detail ?? "The affected set.",
61
- "",
62
- "## Parts",
63
- "",
64
- `Every part's worker judges its evidence files under \`${PARTS_DIR}/\` — a capability whole, or a capability cut between its requirements — for every check: the specification against itself (2, 3) and the code against it (1, 4, 5).`,
65
- ""
66
- ];
67
- lines.push(`1 independent readers per part, each writing its own findings file; the merge unions what they found.`, "");
68
- if (parts.length === 0) lines.push("Nothing in scope: the request touches no requirement, no delta, no bound test and no source where a requirement names a term — there is nothing to judge, and the verdict is PASS.");
69
- else if (parts.length === 1) lines.push(`One part, ${parts[0].requirements} requirements (${kb(parts[0].bytes)}).`);
70
- else {
71
- lines.push(`${parts.length} parts, 1 workers each, dealt out in turn to the reading jobs:`, "");
72
- parts.forEach((part) => lines.push(`- Part ${part.part} (${part.requirements} requirements, ${kb(part.bytes)}): ${part.files.map((f) => `\`${f.slice(PARTS_DIR.length + 1)}\``).join(", ")}`));
73
- }
74
- return lines.join("\n") + "\n";
75
- }
76
- /**
77
- * The scope of one audit. spec-verify's parts are capabilities; spec-steward's are the same parts plus its sweeps, each a
78
- * unit of its own after the last part.
79
- */
80
- function main(env = process.env, audit = "spec-verify") {
81
- const kind = modeFor(env);
82
- const model = loadEvidence();
83
- const all = requirementsOf(model);
84
- const affected = kind === "affected" ? affectedScope(diffBase(env), all) : void 0;
85
- const corpus = [...new Set(all.map((r) => r.capability))].sort();
86
- const capabilityParts = partition(writeParts(affected ? affected.capabilities : corpus, all), audit);
87
- const parts = audit === "spec-steward" ? [...capabilityParts, ...sweepUnits(model, capabilityParts.length)] : capabilityParts;
88
- const report = renderScope(parts, kind, affected ? `The affected set against \`${affected.base}\`: ${affected.requirements.length} requirements in ${affected.capabilities.length} capabilities — the ones the diff changed or a touched delta names, the ones whose bound tests or own terms the changed files contain, the ones the changed code cites, and the requirements related to these — with cross-capability checks against the corpus the evidence quotes.` : void 0);
89
- const json = {
90
- scope: kind,
91
- ...affected ? {
92
- base: affected.base,
93
- capabilities: affected.capabilities
94
- } : {},
95
- readers: 1,
96
- parts
97
- };
98
- const file = path.join(root(), AUDIT_FILES[audit].scope);
99
- fs.mkdirSync(path.dirname(file), { recursive: true });
100
- fs.writeFileSync(file, JSON.stringify(json, null, 2) + "\n");
101
- return report;
102
- }
103
- //#endregion
104
- export { main };