@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.
- package/README.md +7 -7
- package/dist/lib.js +2 -1
- package/package.json +4 -6
- package/skills/spec-steward/SKILL.md +2 -2
- package/skills/spec-steward/references/contract.md +7 -7
- package/skills/spec-tools/SKILL.md +3 -1
- package/skills/spec-tools/references/contract.md +1 -1
- package/skills/spec-tools/references/gitlab.md +20 -22
- package/skills/spec-tools/scripts/cli.js +8129 -0
- package/skills/spec-verify/SKILL.md +2 -2
- package/skills/spec-steward/scripts/lib/align.mjs +0 -127
- package/skills/spec-steward/scripts/lib/checks.mjs +0 -589
- package/skills/spec-steward/scripts/lib/citations.mjs +0 -156
- package/skills/spec-steward/scripts/lib/corpus.mjs +0 -256
- package/skills/spec-steward/scripts/lib/coverage.mjs +0 -123
- package/skills/spec-steward/scripts/lib/evidence.mjs +0 -189
- package/skills/spec-steward/scripts/lib/git.mjs +0 -138
- package/skills/spec-steward/scripts/lib/review.mjs +0 -347
- package/skills/spec-steward/scripts/lib/scan.mjs +0 -364
- package/skills/spec-steward/scripts/lib/util.mjs +0 -161
- package/skills/spec-steward/scripts/lib/wire.mjs +0 -333
- package/skills/spec-steward/scripts/steward.mjs +0 -289
- package/spec-tools/dist/audit-DkZZulq6.mjs +0 -130
- package/spec-tools/dist/auditChanged-CNGjlake.mjs +0 -1
- package/spec-tools/dist/auditChanged-CZCvMgyZ.mjs +0 -618
- package/spec-tools/dist/auditReport-xgq4wK2i.mjs +0 -458
- package/spec-tools/dist/auditScope-CBuBtfPG.mjs +0 -104
- package/spec-tools/dist/changeGates-DdeQKfle.mjs +0 -333
- package/spec-tools/dist/changeGates-uy4Ti8rK.mjs +0 -1
- package/spec-tools/dist/ci-BUewHJS3.mjs +0 -143
- package/spec-tools/dist/ci-CFBzn8Of.mjs +0 -1
- package/spec-tools/dist/cli.mjs +0 -93
- package/spec-tools/dist/comment-szasMMg2.mjs +0 -57
- package/spec-tools/dist/files-Bppsb34B.mjs +0 -1
- package/spec-tools/dist/files-QlzY687_.mjs +0 -38
- package/spec-tools/dist/html-BMTkpbUN.mjs +0 -1766
- package/spec-tools/dist/jsonrepair-Dlm5dEen.mjs +0 -742
- package/spec-tools/dist/repo-CjIoUPYl.mjs +0 -16
- package/spec-tools/dist/repo-DUcnJw3c.mjs +0 -1
- package/spec-tools/dist/run-BElA9du3.mjs +0 -67
- package/spec-tools/dist/specDiff-8G56jMYn.mjs +0 -123
- package/spec-tools/dist/steward-DeieyOcj.mjs +0 -34
- package/spec-tools/dist/stewardAudit-BRMM0lrD.mjs +0 -1
- package/spec-tools/dist/stewardAudit-v0vOMfLN.mjs +0 -271
- package/spec-tools/dist/tier-Cn0P7juM.mjs +0 -1
- package/spec-tools/dist/tier-c3s_mA_I.mjs +0 -65
- package/spec-tools/dist/util-wnxhsnWO.mjs +0 -49
- package/spec-tools/dist/verdict-BFfN9PO8.mjs +0 -58
- package/spec-tools/dist/workers-BcIgckeq.mjs +0 -417
- package/spec-tools/dist/workflowEvidence-DyBj8EdG.mjs +0 -1
- package/spec-tools/dist/workflowEvidence-oui6ghPI.mjs +0 -78
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
//#region spec-tools/src/verdict.ts
|
|
3
|
-
/**
|
|
4
|
-
* The verdict gate of an AI review. A headless `claude --print` exits 0 whether the review passed or found violations,
|
|
5
|
-
* so the report's own verdict is the only signal that the REVIEW passed — without this a review job is a publisher, not
|
|
6
|
-
* a gate. A Markdown report carries its verdict on its first line; a JSON report (`spec-verify.json`) as `.verdict`.
|
|
7
|
-
*
|
|
8
|
-
* A skill that prints its report and also writes it occasionally finishes the report in the conversation and skips
|
|
9
|
-
* the write. The printed report is the same content by the skill's own contract, so when the file is missing but the
|
|
10
|
-
* job log carries a graded verdict, the log IS the report: it is kept under the expected name with the verdict on the
|
|
11
|
-
* first line, and gated as usual. A log with no verdict at all fails — that review did not complete.
|
|
12
|
-
*
|
|
13
|
-
* Exit codes: 0 PASS; 1 FAIL on a gating run, or no verdict; 77 FAIL on an advisory run (the job fails, a pipeline that
|
|
14
|
-
* allows 77 continues); 3 INCOMPLETE — no ERROR stands but a check was sampled or skipped, so the review cannot say what
|
|
15
|
-
* it covered. Which runs gate is the run class's (`tier.ts`): `AUDIT_GATING`, or `--advisory`.
|
|
16
|
-
*/
|
|
17
|
-
const VERDICT_LINE = /(PASS|FAIL|INCOMPLETE) \(\d+ errors?, \d+ warnings?\)/;
|
|
18
|
-
const STATE = /^(PASS|FAIL|INCOMPLETE)\S*/m;
|
|
19
|
-
/** The verdict a report states, or null when it states none. */
|
|
20
|
-
function verdictOf(file, text) {
|
|
21
|
-
if (file.endsWith(".json")) {
|
|
22
|
-
const verdict = JSON.parse(text).verdict;
|
|
23
|
-
return typeof verdict === "string" ? STATE.exec(verdict)?.[0] ?? null : null;
|
|
24
|
-
}
|
|
25
|
-
return STATE.exec(text)?.[0] ?? null;
|
|
26
|
-
}
|
|
27
|
-
/** The exit code a verdict carries. */
|
|
28
|
-
function exitFor(verdict, advisory) {
|
|
29
|
-
if (verdict?.startsWith("PASS")) return 0;
|
|
30
|
-
if (verdict?.startsWith("INCOMPLETE")) return 3;
|
|
31
|
-
if (verdict?.startsWith("FAIL")) return advisory ? 77 : 1;
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
34
|
-
/** `spec-tools verdict <report> [--log <job log>] [--advisory]`. */
|
|
35
|
-
function gate(file, log, advisory) {
|
|
36
|
-
if (!fs.existsSync(file)) {
|
|
37
|
-
const recovered = fs.existsSync(log) ? VERDICT_LINE.exec(fs.readFileSync(log, "utf8"))?.[0] : void 0;
|
|
38
|
-
if (!recovered) {
|
|
39
|
-
console.error(`ERROR: ${file} was not written and ${log} carries no verdict — the review did not complete.`);
|
|
40
|
-
return 1;
|
|
41
|
-
}
|
|
42
|
-
console.warn(`WARNING: ${file} was not written by the skill; recovering the report from ${log}.`);
|
|
43
|
-
fs.writeFileSync(file, `${recovered}\n\n_Recovered from the streamed result: the skill printed its report but skipped the write._\n\n${fs.readFileSync(log, "utf8")}`);
|
|
44
|
-
}
|
|
45
|
-
const verdict = verdictOf(file, fs.readFileSync(file, "utf8"));
|
|
46
|
-
if (!verdict) {
|
|
47
|
-
console.error(`ERROR: no verdict line (PASS / FAIL / INCOMPLETE) found in ${file}.`);
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
console.log(`verdict: ${verdict}`);
|
|
51
|
-
const code = exitFor(verdict, advisory);
|
|
52
|
-
if (code === 77) console.error(`ERROR findings in ${file}; an advisory run: the job fails, the pipeline continues.`);
|
|
53
|
-
else if (code === 1) console.error(`ERROR findings in ${file} — see it in this job's artifacts.`);
|
|
54
|
-
else if (code === 3) console.error(`INCOMPLETE: the review did not cover its whole scope — see the coverage in ${file}.`);
|
|
55
|
-
return code;
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
export { gate };
|
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
import { d as findingsFile, t as AUDIT_FILES } from "./files-QlzY687_.mjs";
|
|
2
|
-
import { n as root, t as git } from "./repo-CjIoUPYl.mjs";
|
|
3
|
-
import { s as shard } from "./ci-BUewHJS3.mjs";
|
|
4
|
-
import { n as briefComplete$1, r as briefVerify$1, t as brief$1 } from "./stewardAudit-v0vOMfLN.mjs";
|
|
5
|
-
import { i as EXPENSIVE_MODEL, n as CHEAP_MODEL, t as CHEAP_EFFORT } from "./tier-c3s_mA_I.mjs";
|
|
6
|
-
import { spawn } from "node:child_process";
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
//#region spec-tools/src/workers.ts
|
|
11
|
-
/**
|
|
12
|
-
* The specification audit's fan-out, deterministic: headless `claude --print` workers started from here — no
|
|
13
|
-
* orchestrating model decides when or whether the next worker starts. Each worker loads the `spec-verify` skill for its
|
|
14
|
-
* contract — the five checks, the grading, the findings file — and writes its own findings file; `spec-tools report`
|
|
15
|
-
* merges after every pass. CI's reading jobs and judge job, and `spec-tools audit`, run the passes in this order:
|
|
16
|
-
*
|
|
17
|
-
* 1. reading One worker per part of `audit-scope.json`, judging every check over every requirement of its part.
|
|
18
|
-
* In a parallel job (`ci.ts` `shard`) only the job's share: part p goes to job ((p - 1) mod total) + 1,
|
|
19
|
-
* so each job works its share out from the scope alone. Then, in the judge, the merge.
|
|
20
|
-
* 2. complete One worker per part the merge left short — the `short` list of `spec-verify.json` — over exactly
|
|
21
|
-
* those items, writing the part's next reader file. Nothing already judged is judged twice.
|
|
22
|
-
* 3. verify One verifier per ERROR the merge left standing, over that finding alone, confirming it only when
|
|
23
|
-
* the divergence is real and critical and lowering it to WARN with its reason otherwise, on
|
|
24
|
-
* AUDIT_MODEL_VERIFY. Then the last merge, whose verdict gates.
|
|
25
|
-
*
|
|
26
|
-
* A worker writes its findings file and nothing else. Every pass compares the tree it leaves with the tree it found —
|
|
27
|
-
* each changed or untracked file with its content's hash — and fails, exit 1, naming the paths, when anything changed
|
|
28
|
-
* outside the audit's own outputs (`audit-parts/`, `spec-verify.*`, CI's `job-log-*`).
|
|
29
|
-
*
|
|
30
|
-
* Models, efforts and gating are the run class's (`tier.ts`); how many parts there are is the evidence's
|
|
31
|
-
* (`auditScope.ts`), and how many run at once is memory's, below.
|
|
32
|
-
*/
|
|
33
|
-
/** The tools a worker may use; every other command is denied in a headless run and only costs a turn. */
|
|
34
|
-
const TOOLS = "Skill,Bash(git:git diff*|git log*|git show*),Read,Glob,Grep,Write,Edit";
|
|
35
|
-
/** A corpus-quality worker reads and writes its findings file; it never edits one. */
|
|
36
|
-
const STEWARD_TOOLS = "Skill,Bash(git:git diff*|git log*|git show*),Read,Glob,Grep,Write";
|
|
37
|
-
/**
|
|
38
|
-
* Each headless worker is a node process of about 500 MB resident — 590 MB at the most, measured over 24 cheap-tier
|
|
39
|
-
* workers — so in a container the count follows the cgroup memory limit at 600 MB per worker (at least two).
|
|
40
|
-
*/
|
|
41
|
-
const PER_WORKER_BYTES = 629145600;
|
|
42
|
-
/** What a pass may leave behind besides nothing. */
|
|
43
|
-
const OUTPUTS = /^(audit-parts\/|spec-verify\.|job-log-)/;
|
|
44
|
-
/** How many workers run at once: memory's bound in a container, capped by AUDIT_WORKERS; else AUDIT_WORKERS, else all. */
|
|
45
|
-
function concurrency(env, memoryLimit = cgroupLimit()) {
|
|
46
|
-
const asked = Number(env.AUDIT_WORKERS) || 0;
|
|
47
|
-
if (memoryLimit === null) return asked;
|
|
48
|
-
const bound = Math.max(2, Math.floor(memoryLimit / PER_WORKER_BYTES));
|
|
49
|
-
return asked > 0 ? Math.min(asked, bound) : bound;
|
|
50
|
-
}
|
|
51
|
-
function cgroupLimit() {
|
|
52
|
-
for (const file of ["/sys/fs/cgroup/memory.max", "/sys/fs/cgroup/memory/memory.limit_in_bytes"]) {
|
|
53
|
-
let value;
|
|
54
|
-
try {
|
|
55
|
-
value = fs.readFileSync(file, "utf8").trim();
|
|
56
|
-
} catch {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (value === "max") return null;
|
|
60
|
-
const bytes = Number(value);
|
|
61
|
-
if (Number.isFinite(bytes) && bytes < 0x38d7ea4c68000) return bytes;
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
/** The parts dealt to job `index` of `total` in turn. */
|
|
66
|
-
const shareOf = (parts, { index, total }) => parts.filter((p) => (p.part - 1) % total === index - 1);
|
|
67
|
-
/** The tree as git sees it beyond HEAD: every changed or untracked file with its content's hash. */
|
|
68
|
-
function treeState(cwd) {
|
|
69
|
-
const state = /* @__PURE__ */ new Map();
|
|
70
|
-
for (const file of git([
|
|
71
|
-
"ls-files",
|
|
72
|
-
"--modified",
|
|
73
|
-
"--others",
|
|
74
|
-
"--exclude-standard",
|
|
75
|
-
"-z"
|
|
76
|
-
], cwd).split("\0")) {
|
|
77
|
-
if (!file) continue;
|
|
78
|
-
const full = path.join(cwd, file);
|
|
79
|
-
const stat = fs.lstatSync(full, { throwIfNoEntry: false });
|
|
80
|
-
state.set(file, !stat ? "deleted" : stat.isFile() ? git([
|
|
81
|
-
"hash-object",
|
|
82
|
-
"--no-filters",
|
|
83
|
-
"--",
|
|
84
|
-
file
|
|
85
|
-
], cwd).trim() : "other");
|
|
86
|
-
}
|
|
87
|
-
return state;
|
|
88
|
-
}
|
|
89
|
-
/** The paths whose state differs between two snapshots, the audit's own outputs aside. */
|
|
90
|
-
function treeChanges(before, after) {
|
|
91
|
-
return [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].filter((p) => before.get(p) !== after.get(p) && !OUTPUTS.test(p)).sort();
|
|
92
|
-
}
|
|
93
|
-
const TOOL_RULE = "Tool rule: only Skill, Read, Glob, Grep, Write, Edit and the git commands — no ls/cat/find, no shell validation of your JSON; other commands are denied here and only cost a turn.";
|
|
94
|
-
/** The shipped skill, two levels above this module in the source and in the build alike. */
|
|
95
|
-
const SKILL = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../skills/spec-verify/SKILL.md");
|
|
96
|
-
/** Loading the skill: by name where the repository links it, else from the package — a job with no install links none. */
|
|
97
|
-
const loadSkill = (repo) => `First, load the skill instructions: use the Skill tool with skill "spec-verify" (or Read ${path.relative(repo, SKILL)} if that fails) to get the checks, the grading contract, the findings-file contract and the tool rules. Follow them exactly.`;
|
|
98
|
-
/** The reading brief: one part, every check over every requirement of it. */
|
|
99
|
-
const brief = (p, repo) => `You are a worker for the spec-verify audit skill in repo ${repo}.
|
|
100
|
-
|
|
101
|
-
${loadSkill(repo)}
|
|
102
|
-
|
|
103
|
-
Your assignment:
|
|
104
|
-
- part: ${p.part}
|
|
105
|
-
- reader: 1
|
|
106
|
-
- capabilities: ${p.capabilities.join(", ")}
|
|
107
|
-
- findings file to write (Write tool, overwrite, nothing else): ${p.findings[0]}
|
|
108
|
-
- evidence files to read in full: ${p.files.join(", ")}
|
|
109
|
-
- requirementIds (your judged list must cover exactly these):
|
|
110
|
-
${p.requirementIds.join("\n")}
|
|
111
|
-
|
|
112
|
-
Judge checks 1–5 over every requirement, every bound test, every listed term occurrence and every listed related pair. Complete this assigned evidence: read any named source window before judging and list every requirement id in your judged list. An uncertain conclusion is a WARN finding, not sampled coverage; use \`sampled\` only if an assigned source remains genuinely unavailable after reading it. A test that proves less than its rule is an \`untested\` finding with check 5 still full — a coverage note names what you did not read, never what a test did not assert. ${TOOL_RULE} Write the findings file exactly at the path above, then return one line: the path and your counts per tier.
|
|
113
|
-
`;
|
|
114
|
-
/**
|
|
115
|
-
* The completion brief: the same contract, over exactly what the first pass left. A check the first pass left short is
|
|
116
|
-
* judged over the requirements its note names, or over the whole part when it names none; a requirement no judged
|
|
117
|
-
* list names is judged for checks 1–5.
|
|
118
|
-
*/
|
|
119
|
-
const briefComplete = (p, short, reader, file, repo) => {
|
|
120
|
-
const ids = short.requirementIds.length ? short.requirementIds.join("\n") : "(none)";
|
|
121
|
-
const checks = Object.entries(short.checks);
|
|
122
|
-
return `You are a completion worker for the spec-verify audit skill in repo ${repo}. The first pass over part ${p.part} was left short; judge exactly what it left, and nothing else — every other requirement and check of this part is already judged.
|
|
123
|
-
|
|
124
|
-
${loadSkill(repo)}
|
|
125
|
-
|
|
126
|
-
Your assignment:
|
|
127
|
-
- part: ${p.part}
|
|
128
|
-
- reader: ${reader}
|
|
129
|
-
- capabilities: ${p.capabilities.join(", ")}
|
|
130
|
-
- findings file to write (Write tool, overwrite, nothing else): ${file}
|
|
131
|
-
- evidence files (read the requirement blocks you judge in full, with their bound tests, term occurrences and related lists): ${p.files.join(", ")}
|
|
132
|
-
- requirements the first pass did not judge — judge checks 1–5 over each:
|
|
133
|
-
${ids}
|
|
134
|
-
- checks the first pass left short, with its own note — judge each in full over the requirements the note names, or over every requirement of the part when it names none:
|
|
135
|
-
${checks.length ? checks.map(([check, note]) => ` ${check}: ${note}`).join("\n") : " (none)"}
|
|
136
|
-
|
|
137
|
-
Your findings file has the usual shape. Its coverage object names exactly the checks this brief names — each "full" when you judged every item named for it, otherwise "sampled: <what was skipped>" — and its judged list names exactly the requirement ids you judged here. This completion pass must close the named shortfall: read any required source window and record uncertainty as a WARN finding, not sampled coverage. A shortfall that is really a judgment about a test — it covers less than its rule — is closed by writing that judgment as an \`untested\` finding and marking the check full. Use \`sampled\` only if an assigned source remains genuinely unavailable after reading it. ${TOOL_RULE} Write the findings file exactly at the path above, then return one line: the path and your counts per tier.
|
|
138
|
-
`;
|
|
139
|
-
};
|
|
140
|
-
/** The verifier's brief: one finding, one question, no skill to load — the contract is here in full. */
|
|
141
|
-
const briefVerify = (f, p, file, repo) => {
|
|
142
|
-
const { kind, where, detail, quotes } = f;
|
|
143
|
-
return `You are the verifier for ONE finding of the spec-verify audit in repo ${repo}. A worker graded it ERROR, and its quotes were found at their lines mechanically. Your job is to decide whether it should stop the build.
|
|
144
|
-
|
|
145
|
-
The finding:
|
|
146
|
-
${JSON.stringify({
|
|
147
|
-
kind,
|
|
148
|
-
where,
|
|
149
|
-
detail,
|
|
150
|
-
quotes
|
|
151
|
-
}, null, 2)}
|
|
152
|
-
|
|
153
|
-
Read, with the Read and Grep tools only: the requirement's block in the part's evidence files (${p?.files.join(", ") ?? "audit-parts/"} — Grep the slug from "where"), both quoted sources at and around the quoted lines, and enough of the surrounding code to know what it does. Do not shell out (no ls/cat/find); other commands are denied and only cost a turn.
|
|
154
|
-
|
|
155
|
-
Confirm the ERROR only when ALL of these hold:
|
|
156
|
-
1. The quotes are genuine and say what the finding claims.
|
|
157
|
-
2. The requirement and the code genuinely diverge — not a vague requirement read narrowly, not an ambiguity the surrounding code resolves, not behaviour implemented elsewhere that the finding did not look at.
|
|
158
|
-
3. The divergence is critical: an obvious code defect — the code does something different from what the requirement mandates in a way a caller, a test or an operator would observe — or a statement that would steer an agent wrongly (a prompt, a tool description, a workflow rule the agents follow).
|
|
159
|
-
|
|
160
|
-
Otherwise the finding is WARN. A citation or a comment is never evidence either way: judge the requirement and the code. Write exactly this JSON with the Write tool to ${file} and nothing else:
|
|
161
|
-
{"verdict": "confirmed" | "warn", "reason": "<one sentence: for confirmed, the observable consequence; for warn, which of the three conditions fails and why>"}
|
|
162
|
-
Then return one line: the path and the verdict.
|
|
163
|
-
`;
|
|
164
|
-
};
|
|
165
|
-
/** `20m`, `90s`, `1h` or bare seconds, in milliseconds. */
|
|
166
|
-
function duration(text) {
|
|
167
|
-
const m = /^(\d+(?:\.\d+)?)([smh]?)$/.exec(text.trim());
|
|
168
|
-
if (!m) throw new Error(`bad duration: ${text}`);
|
|
169
|
-
return Number(m[1]) * {
|
|
170
|
-
"": 1e3,
|
|
171
|
-
s: 1e3,
|
|
172
|
-
m: 6e4,
|
|
173
|
-
h: 36e5
|
|
174
|
-
}[m[2]];
|
|
175
|
-
}
|
|
176
|
-
/** The last `result` event of a worker's stream, or undefined when it wrote none. */
|
|
177
|
-
function resultOf(jsonl) {
|
|
178
|
-
if (!fs.existsSync(jsonl)) return void 0;
|
|
179
|
-
let result;
|
|
180
|
-
for (const line of fs.readFileSync(jsonl, "utf8").split("\n")) try {
|
|
181
|
-
const event = JSON.parse(line);
|
|
182
|
-
if (event.type === "result") result = event;
|
|
183
|
-
} catch {}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
const KINDS = {
|
|
187
|
-
"spec-verify": {
|
|
188
|
-
files: AUDIT_FILES["spec-verify"],
|
|
189
|
-
tools: TOOLS,
|
|
190
|
-
model: CHEAP_MODEL,
|
|
191
|
-
effort: CHEAP_EFFORT,
|
|
192
|
-
brief,
|
|
193
|
-
briefComplete,
|
|
194
|
-
targets: (data, partOf) => data.findings.filter((f) => f.tier === "ERROR").map((f) => ({
|
|
195
|
-
label: f.where,
|
|
196
|
-
brief: (file, repo) => briefVerify(f, partOf(f.part ?? 1), file, repo)
|
|
197
|
-
})),
|
|
198
|
-
none: "no ERROR stands"
|
|
199
|
-
},
|
|
200
|
-
"spec-steward": {
|
|
201
|
-
files: AUDIT_FILES["spec-steward"],
|
|
202
|
-
tools: STEWARD_TOOLS,
|
|
203
|
-
model: EXPENSIVE_MODEL,
|
|
204
|
-
effort: "high",
|
|
205
|
-
brief: brief$1,
|
|
206
|
-
briefComplete: briefComplete$1,
|
|
207
|
-
targets: (data) => data.candidates.map((c) => ({
|
|
208
|
-
label: `${c.file}:${c.line}`,
|
|
209
|
-
brief: (file, repo) => briefVerify$1(c, file, repo)
|
|
210
|
-
})),
|
|
211
|
-
none: "no finding stands"
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* One headless worker under its time budget. A worker that never returns must not hold the whole job to its timeout:
|
|
216
|
-
* past the budget it is killed and writes no findings file; the merge lists its part as short, and the completion pass
|
|
217
|
-
* judges it once. A finished worker keeps its result event alone (duration, turns, cost, usage); a failed one keeps its
|
|
218
|
-
* whole stream, and its own reason — e.g. an API usage-limit error — is echoed next to the exit status.
|
|
219
|
-
*/
|
|
220
|
-
async function runClaude(run, wrote, budget, env, cwd) {
|
|
221
|
-
const jsonl = path.join(cwd, run.dir, `${run.log}.jsonl`);
|
|
222
|
-
const err = path.join(cwd, run.dir, `${run.log}.err`);
|
|
223
|
-
const args = [
|
|
224
|
-
"--print",
|
|
225
|
-
run.prompt,
|
|
226
|
-
"--model",
|
|
227
|
-
run.model,
|
|
228
|
-
"--effort",
|
|
229
|
-
run.effort,
|
|
230
|
-
"--permission-mode",
|
|
231
|
-
"default"
|
|
232
|
-
];
|
|
233
|
-
args.push("--output-format", "stream-json", "--verbose", "--allowedTools", run.tools);
|
|
234
|
-
const out = fs.openSync(jsonl, "w");
|
|
235
|
-
const errOut = fs.openSync(err, "w");
|
|
236
|
-
const child = spawn("claude", args, {
|
|
237
|
-
cwd,
|
|
238
|
-
env,
|
|
239
|
-
stdio: [
|
|
240
|
-
"ignore",
|
|
241
|
-
out,
|
|
242
|
-
errOut
|
|
243
|
-
]
|
|
244
|
-
});
|
|
245
|
-
let killed = false;
|
|
246
|
-
const timer = setTimeout(() => {
|
|
247
|
-
killed = true;
|
|
248
|
-
child.kill("SIGTERM");
|
|
249
|
-
}, budget);
|
|
250
|
-
const code = await new Promise((resolve) => {
|
|
251
|
-
child.on("error", () => resolve(127));
|
|
252
|
-
child.on("close", (c) => resolve(c ?? 1));
|
|
253
|
-
});
|
|
254
|
-
clearTimeout(timer);
|
|
255
|
-
fs.closeSync(out);
|
|
256
|
-
fs.closeSync(errOut);
|
|
257
|
-
if (killed) return `killed after ${Math.round(budget / 6e4)}m`;
|
|
258
|
-
if (code !== 0) {
|
|
259
|
-
const why = String(resultOf(jsonl)?.result ?? "").slice(0, 200);
|
|
260
|
-
return `exit ${code}${why ? ` (${why})` : ""}`;
|
|
261
|
-
}
|
|
262
|
-
if (wrote()) {
|
|
263
|
-
const r = resultOf(jsonl);
|
|
264
|
-
const kept = r && {
|
|
265
|
-
subtype: r.subtype,
|
|
266
|
-
is_error: r.is_error,
|
|
267
|
-
duration_ms: r.duration_ms,
|
|
268
|
-
num_turns: r.num_turns,
|
|
269
|
-
total_cost_usd: r.total_cost_usd,
|
|
270
|
-
usage: r.usage
|
|
271
|
-
};
|
|
272
|
-
fs.writeFileSync(jsonl.replace(/\.jsonl$/, ".result.json"), kept ? JSON.stringify(kept) + "\n" : "");
|
|
273
|
-
fs.rmSync(jsonl);
|
|
274
|
-
if (fs.statSync(err).size === 0) fs.rmSync(err);
|
|
275
|
-
}
|
|
276
|
-
return "ok";
|
|
277
|
-
}
|
|
278
|
-
/** Run tasks with at most `limit` at once (0: all at once). */
|
|
279
|
-
async function pool(tasks, limit) {
|
|
280
|
-
const queue = [...tasks];
|
|
281
|
-
const lanes = Array.from({ length: limit > 0 ? Math.min(limit, queue.length) : queue.length }, async () => {
|
|
282
|
-
for (let task = queue.shift(); task; task = queue.shift()) await task();
|
|
283
|
-
});
|
|
284
|
-
await Promise.all(lanes);
|
|
285
|
-
}
|
|
286
|
-
const clock = () => (/* @__PURE__ */ new Date()).toTimeString().slice(0, 8);
|
|
287
|
-
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
288
|
-
/** One pass of the audit's workers; the exit code: 0 done, 1 the tree changed, 2 an input is missing. */
|
|
289
|
-
async function workers(pass, { audit = "spec-verify", context, env = process.env, cwd = root(), log = console.log } = {}) {
|
|
290
|
-
const withContext = (prompt) => context?.trim() ? `${prompt}\nRun context — facts established and decisions the owner has already made. Judge with them; a finding or a verdict that would reverse one says so:\n${context.trim()}\n` : prompt;
|
|
291
|
-
const kind = KINDS[audit];
|
|
292
|
-
const { files } = kind;
|
|
293
|
-
const flag = audit === "spec-verify" ? "" : ` --audit ${audit}`;
|
|
294
|
-
const fail = (message) => {
|
|
295
|
-
console.error(`spec-tools workers: ${message}`);
|
|
296
|
-
return 2;
|
|
297
|
-
};
|
|
298
|
-
const scopePath = path.join(cwd, files.scope);
|
|
299
|
-
if (!fs.existsSync(scopePath)) return fail(`${files.scope} is missing — run spec-tools scope${flag} first`);
|
|
300
|
-
const scope = readJson(scopePath);
|
|
301
|
-
const model = env.AUDIT_MODEL || kind.model;
|
|
302
|
-
const effort = env.AUDIT_EFFORT || kind.effort;
|
|
303
|
-
const budget = duration(env.AUDIT_WORKER_TIMEOUT || "20m");
|
|
304
|
-
const limit = concurrency(env);
|
|
305
|
-
const findings = path.join(cwd, files.findings);
|
|
306
|
-
fs.mkdirSync(findings, { recursive: true });
|
|
307
|
-
const before = treeState(cwd);
|
|
308
|
-
const partOf = (n) => scope.parts.find((p) => p.part === n);
|
|
309
|
-
const repo = cwd;
|
|
310
|
-
const work = async (p, short) => {
|
|
311
|
-
const reader = short ? fs.readdirSync(findings).filter((f) => new RegExp(`^part-${p.part}-\\d+\\.json$`).test(f)).length + 1 : 1;
|
|
312
|
-
const file = short ? findingsFile(p.part, reader, audit) : p.findings[0];
|
|
313
|
-
const prompt = withContext(short ? kind.briefComplete(p, short, reader, file, repo) : kind.brief(p, repo));
|
|
314
|
-
const started = Date.now();
|
|
315
|
-
log(`[${clock()}] worker ${p.part} started — ${short ? `completion, reader ${reader}, ` : ""}${model}`);
|
|
316
|
-
const logName = short ? `worker-${p.part}-${reader}` : `worker-${p.part}`;
|
|
317
|
-
const full = path.join(cwd, file);
|
|
318
|
-
const status = await runClaude({
|
|
319
|
-
prompt,
|
|
320
|
-
model,
|
|
321
|
-
effort,
|
|
322
|
-
log: logName,
|
|
323
|
-
dir: files.findings,
|
|
324
|
-
tools: kind.tools
|
|
325
|
-
}, () => fs.existsSync(full), budget, env, cwd);
|
|
326
|
-
let wrote = "no findings file";
|
|
327
|
-
if (fs.existsSync(full)) try {
|
|
328
|
-
const json = readJson(full);
|
|
329
|
-
wrote = `${json.findings?.length ?? 0} findings, judged ${json.judged?.length ?? 0}`;
|
|
330
|
-
} catch {
|
|
331
|
-
wrote = "unparseable findings file";
|
|
332
|
-
}
|
|
333
|
-
log(`[${clock()}] worker ${p.part} finished in ${Math.round((Date.now() - started) / 1e3)}s — ${status} — ${wrote}`);
|
|
334
|
-
};
|
|
335
|
-
const verify = async (target, k) => {
|
|
336
|
-
const file = `${files.findings}/verdict-${k}.json`;
|
|
337
|
-
const full = path.join(cwd, file);
|
|
338
|
-
const started = Date.now();
|
|
339
|
-
log(`[${clock()}] verifier ${k} started — ${target.label}`);
|
|
340
|
-
const status = await runClaude({
|
|
341
|
-
prompt: withContext(target.brief(file, repo)),
|
|
342
|
-
model: env.AUDIT_MODEL_VERIFY || model,
|
|
343
|
-
effort: env.AUDIT_EFFORT_VERIFY || effort,
|
|
344
|
-
log: `verifier-${k}`,
|
|
345
|
-
dir: files.findings,
|
|
346
|
-
tools: kind.tools
|
|
347
|
-
}, () => fs.existsSync(full), budget, env, cwd);
|
|
348
|
-
let wrote = "no verdict file";
|
|
349
|
-
if (fs.existsSync(full)) try {
|
|
350
|
-
const v = readJson(full);
|
|
351
|
-
wrote = `${v.verdict} — ${v.reason}`;
|
|
352
|
-
} catch {
|
|
353
|
-
wrote = "unparseable verdict file";
|
|
354
|
-
}
|
|
355
|
-
log(`[${clock()}] verifier ${k} finished in ${Math.round((Date.now() - started) / 1e3)}s — ${status} — ${wrote}`);
|
|
356
|
-
};
|
|
357
|
-
const unchanged = () => {
|
|
358
|
-
const changed = treeChanges(before, treeState(cwd));
|
|
359
|
-
if (!changed.length) return 0;
|
|
360
|
-
console.error("spec-tools workers: the pass changed files outside the audit's outputs (a worker writes only its findings):");
|
|
361
|
-
for (const p of changed) console.error(` ${p}`);
|
|
362
|
-
return 1;
|
|
363
|
-
};
|
|
364
|
-
if (pass === "verify" || pass === "complete") {
|
|
365
|
-
const reportPath = path.join(cwd, files.data);
|
|
366
|
-
if (!fs.existsSync(reportPath)) return fail(`${files.data} is missing — run spec-tools report${flag} first`);
|
|
367
|
-
const report = readJson(reportPath);
|
|
368
|
-
if (pass === "verify") {
|
|
369
|
-
for (const f of fs.readdirSync(findings)) if (/^(verdict-.*\.json|verifier-.*\.(jsonl|err|result\.json))$/.test(f)) fs.rmSync(path.join(findings, f));
|
|
370
|
-
fs.writeFileSync(path.join(cwd, files.verified), "");
|
|
371
|
-
const targets = kind.targets(report, partOf);
|
|
372
|
-
if (!targets.length) {
|
|
373
|
-
log(`spec-tools workers: nothing to verify — ${kind.none}`);
|
|
374
|
-
return 0;
|
|
375
|
-
}
|
|
376
|
-
log(`spec-tools workers: verification pass over ${targets.length} finding(s), model ${env.AUDIT_MODEL_VERIFY || model} effort ${env.AUDIT_EFFORT_VERIFY || effort}`);
|
|
377
|
-
await pool(targets.map((t, i) => () => verify(t, i + 1)), limit);
|
|
378
|
-
const code = unchanged();
|
|
379
|
-
if (code === 0) log("spec-tools workers: verification done");
|
|
380
|
-
return code;
|
|
381
|
-
}
|
|
382
|
-
if (!report.short.length) {
|
|
383
|
-
log("spec-tools workers: nothing to complete — every part is covered");
|
|
384
|
-
return 0;
|
|
385
|
-
}
|
|
386
|
-
log(`spec-tools workers: completion pass over ${report.short.length} short part(s), model ${model} effort ${effort}`);
|
|
387
|
-
await pool(report.short.flatMap((s) => {
|
|
388
|
-
const p = partOf(s.part);
|
|
389
|
-
return p ? [() => work(p, s)] : [];
|
|
390
|
-
}), limit);
|
|
391
|
-
const code = unchanged();
|
|
392
|
-
if (code === 0) log("spec-tools workers: completion done");
|
|
393
|
-
return code;
|
|
394
|
-
}
|
|
395
|
-
const job = shard(env);
|
|
396
|
-
const share = shareOf(scope.parts, job);
|
|
397
|
-
const of = job.total > 1 ? ` — job ${job.index} of ${job.total}, its share of ${scope.parts.length}` : "";
|
|
398
|
-
const mine = new Set(share.map((p) => p.part));
|
|
399
|
-
for (const f of fs.readdirSync(findings)) {
|
|
400
|
-
const part = /^(?:part|worker)-(\d+)[-.]/.exec(f);
|
|
401
|
-
if (job.total > 1 ? part !== null && mine.has(Number(part[1])) : part !== null || /^(verdict-.*\.json|merge-.*\.json)$/.test(f)) fs.rmSync(path.join(findings, f));
|
|
402
|
-
}
|
|
403
|
-
if (job.total === 1) fs.rmSync(path.join(cwd, files.verified), { force: true });
|
|
404
|
-
if (!share.length) {
|
|
405
|
-
log(`spec-tools workers: no part to read${of}`);
|
|
406
|
-
return unchanged();
|
|
407
|
-
}
|
|
408
|
-
log(`spec-tools workers: ${share.length} parts${of}, model ${model} effort ${effort}, ${limit === 0 ? "all at once" : `${limit} at a time`}`);
|
|
409
|
-
await pool(share.map((p) => () => work(p)), limit);
|
|
410
|
-
const missing = share.map((p) => p.findings[0]).filter((f) => !fs.existsSync(path.join(cwd, f)));
|
|
411
|
-
if (missing.length) log(`spec-tools workers: findings files not written (the completion pass judges those parts):\n${missing.join("\n")}`);
|
|
412
|
-
const code = unchanged();
|
|
413
|
-
if (code === 0) log("spec-tools workers: done");
|
|
414
|
-
return code;
|
|
415
|
-
}
|
|
416
|
-
//#endregion
|
|
417
|
-
export { workers };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { n as cli } from "./workflowEvidence-oui6ghPI.mjs";
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { n as gateBase } from "./ci-BUewHJS3.mjs";
|
|
2
|
-
import { f as syncedUnarchivedChanges, n as deltaFilesInOpenChanges, p as touchedOpenChanges } from "./changeGates-DdeQKfle.mjs";
|
|
3
|
-
//#region spec-tools/src/workflowEvidence.ts
|
|
4
|
-
/**
|
|
5
|
-
* Is this merge request finished? The one gate whose red says "not yet". A change that takes the
|
|
6
|
-
* delta flow is finished inside its merge request — archived, its deltas folded into the standing
|
|
7
|
-
* specifications, its folder moved — and never merges half-done: deltas left open drift from the
|
|
8
|
-
* specifications the longer they sit, which is how two changes reached `main` with their code
|
|
9
|
-
* merged and their deltas never folded. The diff cannot see either state; the tree can:
|
|
10
|
-
*
|
|
11
|
-
* - an open change still carrying delta files, synced or not (`deltaFilesInOpenChanges`);
|
|
12
|
-
* - an open change whose deltas are already live in `openspec/specs/` — synced but not archived
|
|
13
|
-
* (`syncedUnarchivedChanges`) — which an emptied `specs/` folder would otherwise hide.
|
|
14
|
-
*
|
|
15
|
-
* A direct edit of `openspec/specs/` is not this gate's business: it needs no archive and is
|
|
16
|
-
* reviewed as the merge request's diff, which `spec-tools diff` renders by requirement.
|
|
17
|
-
*
|
|
18
|
-
* Both live here and not in the corpus gates, so a branch mid-delta-flow reads red on exactly this gate
|
|
19
|
-
* and green on everything else — the audits included, which depend on no gate.
|
|
20
|
-
*
|
|
21
|
-
* With `--classify` it answers the audit's run-class question instead (`spec-tools tier`): which kind of open
|
|
22
|
-
* change the branch touches against its base — `deltas` (one carrying deltas, or synced but not archived),
|
|
23
|
-
* `skip-specs` (one carrying none) or `none` — printed as the last line.
|
|
24
|
-
*
|
|
25
|
-
* Usage: `spec-tools evidence` | `spec-tools evidence --classify`
|
|
26
|
-
*/
|
|
27
|
-
/** The gate's decision, kept pure so it can be tested without a repository. */
|
|
28
|
-
function workflowEvidence(input) {
|
|
29
|
-
const errors = [];
|
|
30
|
-
if (input.openDeltas.length > 0) errors.push("ERROR: an open change still carries delta files:", ...input.openDeltas.map((line) => ` ${line}`), "", "A change with deltas is finished inside its merge request: archive it (/opsx:archive) before it merges.", "A parked proposal is skip_specs and carries no delta; a small change edits openspec/specs/ directly.");
|
|
31
|
-
if (input.syncedUnarchived.length > 0) {
|
|
32
|
-
if (errors.length > 0) errors.push("");
|
|
33
|
-
errors.push("ERROR: an open change already has its deltas live in openspec/specs/ (synced but not archived):", ...input.syncedUnarchived.map((line) => ` ${line}`), "", "This branch is unfinished: archive the change (/opsx:archive) before it merges.");
|
|
34
|
-
}
|
|
35
|
-
return errors.length === 0 ? null : [
|
|
36
|
-
...errors,
|
|
37
|
-
"",
|
|
38
|
-
"See AGENTS.md, \"Making a change\"."
|
|
39
|
-
].join("\n");
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The kind of open change a branch touches: `deltas` when one of them carries deltas or is synced but not archived —
|
|
43
|
-
* the merge this gate blocks — `skip-specs` when it touches open changes carrying none, `none` when it touches none.
|
|
44
|
-
*/
|
|
45
|
-
function classify(touched, input) {
|
|
46
|
-
const name = (line) => line.split(" — ")[0];
|
|
47
|
-
const withDeltas = new Set([...input.openDeltas, ...input.syncedUnarchived].map(name));
|
|
48
|
-
if (touched.some((change) => withDeltas.has(change))) return "deltas";
|
|
49
|
-
return touched.length > 0 ? "skip-specs" : "none";
|
|
50
|
-
}
|
|
51
|
-
/** `spec-tools evidence [--classify]`: the workflow-evidence gate, or with `--classify` the open changes a branch touches. */
|
|
52
|
-
function cli(argv) {
|
|
53
|
-
const openDeltas = deltaFilesInOpenChanges();
|
|
54
|
-
const syncedUnarchived = syncedUnarchivedChanges();
|
|
55
|
-
if (argv.includes("--classify")) {
|
|
56
|
-
const base = gateBase();
|
|
57
|
-
const touched = base === null ? [] : touchedOpenChanges(base);
|
|
58
|
-
console.log(`open changes this branch touches against ${base ?? "no base"}: ${touched.join(", ") || "none"}`);
|
|
59
|
-
console.log(classify(touched, {
|
|
60
|
-
openDeltas,
|
|
61
|
-
syncedUnarchived
|
|
62
|
-
}));
|
|
63
|
-
return 0;
|
|
64
|
-
}
|
|
65
|
-
console.log(`open changes carrying deltas: ${openDeltas.length}, open changes already synced: ${syncedUnarchived.length}`);
|
|
66
|
-
const violation = workflowEvidence({
|
|
67
|
-
openDeltas,
|
|
68
|
-
syncedUnarchived
|
|
69
|
-
});
|
|
70
|
-
if (violation) {
|
|
71
|
-
console.error(violation);
|
|
72
|
-
return 1;
|
|
73
|
-
}
|
|
74
|
-
console.log("PASS — no open change carries deltas, and none is synced but unarchived");
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
export { cli as n, workflowEvidence as r, classify as t };
|