rungate 0.8.2 → 0.8.4
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/bin/rungate.ts +11 -6
- package/config/prove-evidence.schema.json +21 -3
- package/gates/.gate-salt +1 -1
- package/gates/gate-executor.ts +153 -1
- package/gates/prove.test.ts +12 -6
- package/gates/schema.ts +69 -6
- package/gates/workflow.test.ts +12 -5
- package/hooks/BunTestPathGuard.hook.ts +106 -0
- package/hooks/DocHygiene.hook.ts +2 -1
- package/hooks/GateResultProtection.hook.ts +28 -7
- package/hooks/HookCurrency.hook.ts +48 -1
- package/hooks/TopLevelCdGuard.hook.ts +38 -6
- package/hooks/VerifyPhaseLock.hook.ts +25 -8
- package/hooks/WorkflowStateGuard.hook.ts +24 -7
- package/lib/ai-review-jury.ts +725 -0
- package/lib/ai-review-rounds.ts +791 -4
- package/lib/ai-review-unmeasured.ts +361 -0
- package/lib/bash-write-guard.ts +1235 -102
- package/lib/bun-test-paths.ts +253 -0
- package/lib/cli-commands.ts +252 -11
- package/lib/closing-reference-audit.ts +163 -0
- package/lib/conformity.ts +17 -1
- package/lib/create-sc.ts +45 -12
- package/lib/derived-spec.ts +206 -0
- package/lib/file-claims.ts +335 -0
- package/lib/finding-arbiter.ts +502 -28
- package/lib/finding-jury.ts +61 -5
- package/lib/finding-pr-routing.ts +333 -0
- package/lib/frontmatter.ts +16 -0
- package/lib/gate-check-audit.ts +646 -0
- package/lib/generators/agents-md.ts +29 -0
- package/lib/github.ts +112 -7
- package/lib/hook-tree-currency.ts +494 -0
- package/lib/issue-closure-audit.ts +161 -14
- package/lib/issue-create-override.ts +53 -3
- package/lib/issue-filing-gate.ts +1073 -76
- package/lib/local-review-rounds.ts +523 -0
- package/lib/organize.ts +21 -1
- package/lib/project-state-shape.ts +56 -5
- package/lib/release-preflight.ts +90 -1
- package/lib/repo-path.ts +94 -0
- package/lib/report-provenance.ts +218 -3
- package/lib/risk-tier.ts +302 -0
- package/lib/rounds-to-pass.ts +274 -0
- package/lib/rule-row-drift.ts +199 -0
- package/lib/sc-claim-forms.ts +33 -5
- package/lib/sc-guard.ts +11 -1
- package/lib/sc-id-cross-tree.ts +17 -2
- package/lib/sc-ids.ts +71 -6
- package/lib/sc-reservations.ts +158 -14
- package/lib/scaffold/ai-review-findings.ts +1369 -27
- package/lib/scaffold/ai-review-step.ts +4095 -119
- package/lib/scaffold/ai-review-unmeasured-workflow.ts +243 -0
- package/lib/scaffold/owned-files.ts +14 -0
- package/lib/scaffold/steps.ts +100 -9
- package/lib/scratch-roots.ts +93 -3
- package/lib/spec-updater.ts +22 -2
- package/lib/spec-write-ast.ts +728 -0
- package/lib/spec-write-sweep.ts +470 -0
- package/lib/test-suite-lock.ts +127 -13
- package/lib/ts-ast.ts +26 -0
- package/lib/validators/spec-validators.ts +36 -7
- package/lib/write-spec.ts +138 -0
- package/package.json +2 -1
- package/scripts/ai-review-findings.ts +41 -1
- package/scripts/arbitrate-finding.ts +330 -12
- package/scripts/audit-specs.ts +225 -24
- package/scripts/convert-spec.ts +7 -2
- package/scripts/create-sc.ts +14 -2
- package/scripts/create-spec.ts +5 -2
- package/scripts/detect-sc-drift.ts +10 -2
- package/scripts/record-ai-review-unmeasured.ts +370 -0
- package/scripts/split-spec.ts +17 -4
- package/scripts/sync-sc-status.ts +14 -2
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Record WHICH kind of unmeasured each UNMEASURED review round was (#1486).
|
|
4
|
+
*
|
|
5
|
+
* ```
|
|
6
|
+
* bun scripts/record-ai-review-unmeasured.ts --repo owner/name --limit 45
|
|
7
|
+
* bun scripts/record-ai-review-unmeasured.ts --repo owner/name --pr 1486 --write
|
|
8
|
+
* bun scripts/record-ai-review-unmeasured.ts --repo owner/name --head-sha <sha> --write
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Reads each pull request's AI-review ledger comment, and for every round it
|
|
12
|
+
* holds that recorded `findings: null`, fetches that round's FULL job log and
|
|
13
|
+
* asks `classifyUnmeasuredRound` which state it was in. Prints the split.
|
|
14
|
+
* With `--write`, splices the readings back into the ledger comment.
|
|
15
|
+
*
|
|
16
|
+
* ## Why this is a script and not a step in the ai-review job
|
|
17
|
+
*
|
|
18
|
+
* The obvious place is the persist step, which writes the round. It cannot
|
|
19
|
+
* reach the evidence: a later step cannot read an earlier step's stdout
|
|
20
|
+
* (`AI_REVIEW_APP_INSTALL_CAUSE`, #803), the Actions log endpoint does not
|
|
21
|
+
* serve a job that is still running, and `test/ai-review-payload-reading.test.ts`
|
|
22
|
+
* AC-6 forbids the action's skip prose anywhere in the generated script. So
|
|
23
|
+
* the reading is only available from outside the run, after it ends.
|
|
24
|
+
*
|
|
25
|
+
* **And the logs expire.** That was the whole urgency of #1486: each day a
|
|
26
|
+
* round goes unclassified, another population becomes permanently
|
|
27
|
+
* unmeasurable.
|
|
28
|
+
*
|
|
29
|
+
* ## What runs it now, and what `--head-sha` is for
|
|
30
|
+
*
|
|
31
|
+
* #1488. `lib/scaffold/ai-review-unmeasured-workflow.ts` generates a second
|
|
32
|
+
* workflow, triggered on `workflow_run: completed` for the AI review
|
|
33
|
+
* workflow. That event fires after the job ends, which is the first moment
|
|
34
|
+
* the log is served, and it hands this script the finished run's head sha.
|
|
35
|
+
*
|
|
36
|
+
* Running it by hand over a window still works and is still worth doing for
|
|
37
|
+
* rounds written before the workflow existed — their logs are the ones with
|
|
38
|
+
* a deadline.
|
|
39
|
+
*
|
|
40
|
+
* ## It is a recorder, and it refuses rather than guesses
|
|
41
|
+
*
|
|
42
|
+
* - the FULL log, never `--log-failed`. The skip line is emitted by a step
|
|
43
|
+
* that SUCCEEDS, so `--log-failed` returns 0 bytes on a declined run —
|
|
44
|
+
* measured on run 40047304108. Never the clock either: #1485 has
|
|
45
|
+
* no-payload runs at 4m11s–5m35s and a real review at 2m16s.
|
|
46
|
+
* - a log it could not fetch is recorded as `log_unreadable` by name. It is
|
|
47
|
+
* not "no skip line found", which is the conflation the issue exists to
|
|
48
|
+
* fix, one level down.
|
|
49
|
+
* - a ledger `readLedger` refuses is SKIPPED, never rewritten. Replacing a
|
|
50
|
+
* ledger holding seven rounds with one holding this pass is the worst
|
|
51
|
+
* thing this can do and is invisible afterwards.
|
|
52
|
+
* - the spliced body is read back through the real `readLedger` and the
|
|
53
|
+
* rounds compared before anything is sent. `replaceLedgerJsonBlock` finds
|
|
54
|
+
* the fence itself and is therefore a second reader of those bytes; this
|
|
55
|
+
* read-back is what closes it.
|
|
56
|
+
* - a round that already carries a reading is left alone and costs no
|
|
57
|
+
* fetch, so a later expiry can never overwrite a reading taken while the
|
|
58
|
+
* log still existed.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
import { spawnSync } from "node:child_process";
|
|
62
|
+
|
|
63
|
+
import {
|
|
64
|
+
AI_REVIEW_JOB_LOG_READ,
|
|
65
|
+
AI_REVIEW_JOB_LOG_UNREADABLE,
|
|
66
|
+
AI_REVIEW_UNMEASURED_NOT_RECORDED,
|
|
67
|
+
annotateUnmeasuredRounds,
|
|
68
|
+
readRecordedUnmeasuredState,
|
|
69
|
+
replaceLedgerJsonBlock,
|
|
70
|
+
type JobLogReading,
|
|
71
|
+
} from "../lib/ai-review-unmeasured.ts";
|
|
72
|
+
import {
|
|
73
|
+
AI_REVIEW_LEDGER_ABSENT,
|
|
74
|
+
AI_REVIEW_LEDGER_READ,
|
|
75
|
+
AI_REVIEW_LEDGER_ROUNDS_KEY,
|
|
76
|
+
ledgerUnreadable,
|
|
77
|
+
readLedger,
|
|
78
|
+
selectLedgerComment,
|
|
79
|
+
type LedgerCandidate,
|
|
80
|
+
type LedgerSelection,
|
|
81
|
+
} from "../lib/ai-review-rounds.ts";
|
|
82
|
+
|
|
83
|
+
/** One exported exit code, so there is a single refusal path to mutate. */
|
|
84
|
+
export const RECORD_UNMEASURED_FAILED = 1;
|
|
85
|
+
|
|
86
|
+
interface Args {
|
|
87
|
+
repo: string;
|
|
88
|
+
prs: number[];
|
|
89
|
+
limit: number;
|
|
90
|
+
write: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the pull requests from a COMMIT rather than naming them (#1488).
|
|
93
|
+
*
|
|
94
|
+
* What the `workflow_run: completed` job knows about the run that just
|
|
95
|
+
* finished is its head sha. It also has `workflow_run.pull_requests`, and
|
|
96
|
+
* that field is the wrong reading: GitHub leaves it EMPTY for a pull
|
|
97
|
+
* request opened from a fork, so a workflow built on it would classify the
|
|
98
|
+
* rounds it could see and skip the ones it could not, silently — the same
|
|
99
|
+
* shape as the conflation this whole feature exists to undo.
|
|
100
|
+
*/
|
|
101
|
+
headSha: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseArgs(argv: readonly string[]): Args | { error: string } {
|
|
105
|
+
const out: Args = { repo: "", prs: [], limit: 45, write: false, headSha: "" };
|
|
106
|
+
for (let i = 0; i < argv.length; i++) {
|
|
107
|
+
const a = argv[i];
|
|
108
|
+
if (a === "--write") out.write = true;
|
|
109
|
+
else if (a === "--repo") out.repo = argv[++i] ?? "";
|
|
110
|
+
else if (a === "--head-sha") {
|
|
111
|
+
const sha = argv[++i] ?? "";
|
|
112
|
+
// Validated, because it reaches an API path. A sha that is not one is
|
|
113
|
+
// refused by name rather than sent and allowed to 404 — a 404 and an
|
|
114
|
+
// empty pull-request list are the two readings this must keep apart.
|
|
115
|
+
if (!/^[0-9a-f]{7,40}$/.test(sha)) {
|
|
116
|
+
return { error: `--head-sha needs a commit sha, got ${JSON.stringify(sha)}` };
|
|
117
|
+
}
|
|
118
|
+
out.headSha = sha;
|
|
119
|
+
} else if (a === "--pr") {
|
|
120
|
+
const n = Number.parseInt(argv[++i] ?? "", 10);
|
|
121
|
+
if (!Number.isSafeInteger(n) || n < 1) return { error: `--pr needs a number, got ${argv[i]}` };
|
|
122
|
+
out.prs.push(n);
|
|
123
|
+
} else if (a === "--limit") {
|
|
124
|
+
const n = Number.parseInt(argv[++i] ?? "", 10);
|
|
125
|
+
if (!Number.isSafeInteger(n) || n < 1) return { error: `--limit needs a number` };
|
|
126
|
+
out.limit = n;
|
|
127
|
+
} else return { error: `unknown argument ${a}` };
|
|
128
|
+
}
|
|
129
|
+
if (!out.repo) return { error: "--repo owner/name is required" };
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function gh(args: string[], maxBuffer = 256 * 1024 * 1024) {
|
|
134
|
+
return spawnSync("gh", args, { encoding: "utf8", maxBuffer });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The pull requests to walk: the ones named, the ones carrying a commit, else
|
|
139
|
+
* the most recent `limit`.
|
|
140
|
+
*
|
|
141
|
+
* The `--head-sha` branch is what the `workflow_run: completed` workflow uses
|
|
142
|
+
* (#1488), and its two zero-length answers are different facts kept apart:
|
|
143
|
+
*
|
|
144
|
+
* - `gh` exited non-zero — the reading could not be taken. An ERROR, so the
|
|
145
|
+
* job goes red rather than reporting a clean pass over nothing.
|
|
146
|
+
* - `gh` exited zero and listed nothing — the commit is genuinely on no open
|
|
147
|
+
* pull request, which is every `merge_group` run and every push to the
|
|
148
|
+
* default branch. An empty list, and the caller's `TOTAL` says so.
|
|
149
|
+
*/
|
|
150
|
+
function resolvePullRequests(args: Args): number[] | { error: string } {
|
|
151
|
+
if (args.prs.length > 0) return args.prs;
|
|
152
|
+
if (args.headSha) {
|
|
153
|
+
const r = gh([
|
|
154
|
+
"api", `repos/${args.repo}/commits/${args.headSha}/pulls`, "-q", ".[].number",
|
|
155
|
+
]);
|
|
156
|
+
if (r.status !== 0) {
|
|
157
|
+
return {
|
|
158
|
+
error:
|
|
159
|
+
`gh api repos/${args.repo}/commits/${args.headSha}/pulls exited ${r.status}: ` +
|
|
160
|
+
`${(r.stderr ?? "").trim().slice(0, 300)} — UNMEASURED, not "no pull request"`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return (r.stdout ?? "").split("\n").map(s => s.trim()).filter(Boolean).map(Number);
|
|
164
|
+
}
|
|
165
|
+
const r = gh([
|
|
166
|
+
"pr", "list", "--repo", args.repo, "--state", "all",
|
|
167
|
+
"--limit", String(args.limit), "--json", "number", "-q", ".[].number",
|
|
168
|
+
]);
|
|
169
|
+
if (r.status !== 0) return { error: `gh pr list failed: ${(r.stderr ?? "").trim()}` };
|
|
170
|
+
return (r.stdout ?? "").split("\n").map(s => s.trim()).filter(Boolean).map(Number);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Which comment on a pull request is the ledger, or why that is not knowable.
|
|
175
|
+
*
|
|
176
|
+
* **The AUTHOR is read, and the whole list is walked before anything is
|
|
177
|
+
* chosen.** This used to select on the marker alone and return the first hit
|
|
178
|
+
* — and the marker is a quotable string, so on #1319 and #1386 TWO comments
|
|
179
|
+
* carry it: the ledger, and a `type: "User"` comment that quotes it while
|
|
180
|
+
* discussing it (measured against the live API, #1412). It took the right
|
|
181
|
+
* one on both, by the API's oldest-first ordering and not by any clause,
|
|
182
|
+
* and then PATCHed it. `selectLedgerComment` holds the decision now: this
|
|
183
|
+
* function's job is to produce candidates and to keep a failed read from
|
|
184
|
+
* reading as an absent ledger.
|
|
185
|
+
*/
|
|
186
|
+
function ledgerComment(repo: string, pr: number): LedgerSelection {
|
|
187
|
+
const r = gh([
|
|
188
|
+
"api", "--paginate", `repos/${repo}/issues/${pr}/comments`,
|
|
189
|
+
// `? // null` on both author fields, not a bare `.user.login`. A
|
|
190
|
+
// comment whose author block is absent would make jq error and take the
|
|
191
|
+
// WHOLE pull request to UNREADABLE; it is simply not a candidate, and
|
|
192
|
+
// over-refusing on one unrelated comment is its own silent cost.
|
|
193
|
+
"-q",
|
|
194
|
+
".[] | select(.body != null) | {id, body, login: (.user.login? // null), type: (.user.type? // null)} | @json",
|
|
195
|
+
]);
|
|
196
|
+
if (r.status !== 0) {
|
|
197
|
+
// NOT absent. A list this script could not read is not a pull request
|
|
198
|
+
// with no ledger on it, and the destructive branch downstream is the one
|
|
199
|
+
// that writes when it believes there is nothing there.
|
|
200
|
+
return ledgerUnreadable(
|
|
201
|
+
`gh api repos/${repo}/issues/${pr}/comments exited ${r.status}: ` +
|
|
202
|
+
`${(r.stderr ?? "").trim().slice(0, 300)}`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
// `@json` through `gh -q` prints the object's JSON text RAW, one per line,
|
|
206
|
+
// so ONE parse. The first draft parsed twice, every line threw, the throw
|
|
207
|
+
// was swallowed, and six pull requests that all have a ledger reported
|
|
208
|
+
// "no ledger comment" — the fail-open shape this repository's own rules
|
|
209
|
+
// open with. A line that will not parse is now counted and named.
|
|
210
|
+
let unparseable = 0;
|
|
211
|
+
const candidates: LedgerCandidate[] = [];
|
|
212
|
+
for (const line of (r.stdout ?? "").split("\n")) {
|
|
213
|
+
if (!line.trim()) continue;
|
|
214
|
+
try {
|
|
215
|
+
candidates.push(JSON.parse(line) as LedgerCandidate);
|
|
216
|
+
} catch {
|
|
217
|
+
unparseable++;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const selection = selectLedgerComment(candidates);
|
|
221
|
+
if (unparseable > 0 && selection.status === AI_REVIEW_LEDGER_ABSENT) {
|
|
222
|
+
// A partial list that held no ledger is not a list that held no ledger.
|
|
223
|
+
return ledgerUnreadable(
|
|
224
|
+
`${unparseable} comment line(s) could not be parsed and no ledger was found in ` +
|
|
225
|
+
"the ones that could, so this pull request's reading is incomplete",
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return selection;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The FULL log for the run a round recorded.
|
|
233
|
+
*
|
|
234
|
+
* `--log`, with the attempt the round recorded. Every failure is an
|
|
235
|
+
* UNREADABLE reading carrying its reason, never an empty string: an empty log
|
|
236
|
+
* is a perfectly good log of a run that was declined.
|
|
237
|
+
*/
|
|
238
|
+
function fetchJobLog(repo: string, run: unknown, attempt: unknown): JobLogReading {
|
|
239
|
+
if (typeof run !== "string" || !/^[0-9]+$/.test(run)) {
|
|
240
|
+
return {
|
|
241
|
+
status: AI_REVIEW_JOB_LOG_UNREADABLE,
|
|
242
|
+
reason: `the round recorded ${JSON.stringify(run)} as its run id, which is not one`,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const args = ["run", "view", run, "--repo", repo, "--log"];
|
|
246
|
+
if (typeof attempt === "string" && /^[0-9]+$/.test(attempt)) args.push("--attempt", attempt);
|
|
247
|
+
const r = gh(args);
|
|
248
|
+
if (r.status !== 0) {
|
|
249
|
+
return {
|
|
250
|
+
status: AI_REVIEW_JOB_LOG_UNREADABLE,
|
|
251
|
+
reason: `gh run view ${run} --log exited ${r.status}: ${(r.stderr ?? "").trim().slice(0, 300)}`,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (typeof r.stdout !== "string") {
|
|
255
|
+
return { status: AI_REVIEW_JOB_LOG_UNREADABLE, reason: `gh run view ${run} wrote nothing` };
|
|
256
|
+
}
|
|
257
|
+
return { status: AI_REVIEW_JOB_LOG_READ, text: r.stdout };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function main(argv: readonly string[]): number {
|
|
261
|
+
const parsed = parseArgs(argv);
|
|
262
|
+
if ("error" in parsed) {
|
|
263
|
+
console.error(`record-ai-review-unmeasured: ${parsed.error}`);
|
|
264
|
+
return RECORD_UNMEASURED_FAILED;
|
|
265
|
+
}
|
|
266
|
+
const prs = resolvePullRequests(parsed);
|
|
267
|
+
if ("error" in prs) {
|
|
268
|
+
console.error(`record-ai-review-unmeasured: ${prs.error}`);
|
|
269
|
+
return RECORD_UNMEASURED_FAILED;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const totals: Record<string, number> = {};
|
|
273
|
+
let skipped = 0;
|
|
274
|
+
|
|
275
|
+
// Named, because `TOTAL: nothing unmeasured` over zero pull requests and
|
|
276
|
+
// the same line over forty is the one sentence this script must never let
|
|
277
|
+
// a reader confuse. A `--head-sha` on no pull request is the ordinary
|
|
278
|
+
// merge-group and push case, not a fault.
|
|
279
|
+
if (parsed.headSha && prs.length === 0) {
|
|
280
|
+
console.log(`${parsed.headSha}: on no pull request — nothing to classify`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
for (const pr of prs) {
|
|
284
|
+
const selected = ledgerComment(parsed.repo, pr);
|
|
285
|
+
if (selected.status === AI_REVIEW_LEDGER_ABSENT) {
|
|
286
|
+
console.log(`#${pr}: no ledger comment`);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (selected.status !== AI_REVIEW_LEDGER_READ) {
|
|
290
|
+
// AMBIGUOUS or UNFETCHED. Counted as refused rather than skipped
|
|
291
|
+
// silently: this is the branch where a wrong comment would have been
|
|
292
|
+
// read, annotated and PATCHed, and nothing afterwards could say so.
|
|
293
|
+
console.log(`#${pr}: ledger SKIPPED (${selected.status}) — ${selected.reason}`);
|
|
294
|
+
skipped++;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const comment = selected.comment;
|
|
298
|
+
const reading = readLedger(comment.body);
|
|
299
|
+
if (reading.status !== AI_REVIEW_LEDGER_READ) {
|
|
300
|
+
// REFUSED, and named. Writing here is the destructive case.
|
|
301
|
+
console.log(`#${pr}: ledger SKIPPED (${reading.status})`);
|
|
302
|
+
skipped++;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const doc = JSON.parse(
|
|
307
|
+
comment.body.slice(
|
|
308
|
+
comment.body.indexOf("\n", comment.body.indexOf("```json")) + 1,
|
|
309
|
+
comment.body.indexOf("\n```", comment.body.indexOf("```json")),
|
|
310
|
+
),
|
|
311
|
+
) as unknown;
|
|
312
|
+
const rawRounds = Array.isArray(doc)
|
|
313
|
+
? doc
|
|
314
|
+
: ((doc as Record<string, unknown>)[AI_REVIEW_LEDGER_ROUNDS_KEY] as unknown[]);
|
|
315
|
+
|
|
316
|
+
const out = annotateUnmeasuredRounds(rawRounds, round =>
|
|
317
|
+
fetchJobLog(parsed.repo, round.run, round.attempt),
|
|
318
|
+
);
|
|
319
|
+
for (const [state, n] of Object.entries(out.counts)) totals[state] = (totals[state] ?? 0) + n;
|
|
320
|
+
|
|
321
|
+
const already = rawRounds.filter(
|
|
322
|
+
r => readRecordedUnmeasuredState(r) !== AI_REVIEW_UNMEASURED_NOT_RECORDED,
|
|
323
|
+
).length;
|
|
324
|
+
const split = Object.entries(out.counts).map(([k, v]) => `${k} ${v}`).join(", ") || "none";
|
|
325
|
+
console.log(
|
|
326
|
+
`#${pr}: ${rawRounds.length} round(s), ${out.recorded} newly classified, ` +
|
|
327
|
+
`${already} already recorded — ${split}`,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
if (!parsed.write || out.recorded === 0) continue;
|
|
331
|
+
|
|
332
|
+
const nextDoc = Array.isArray(doc) ? out.rounds : { ...(doc as object), rounds: out.rounds };
|
|
333
|
+
const nextBody = replaceLedgerJsonBlock(comment.body, nextDoc);
|
|
334
|
+
if (nextBody === null) {
|
|
335
|
+
console.error(`#${pr}: REFUSED to write — the fenced block could not be located`);
|
|
336
|
+
skipped++;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
// READ BACK BEFORE SENDING. `replaceLedgerJsonBlock` locates the fence
|
|
340
|
+
// itself; this is the real reader agreeing that what it produced is a
|
|
341
|
+
// ledger with the same rounds in it.
|
|
342
|
+
const verify = readLedger(nextBody);
|
|
343
|
+
if (
|
|
344
|
+
verify.status !== AI_REVIEW_LEDGER_READ ||
|
|
345
|
+
verify.rounds.length !== reading.rounds.length ||
|
|
346
|
+
verify.rounds.some((r, i) => r.measured !== reading.rounds[i].measured)
|
|
347
|
+
) {
|
|
348
|
+
console.error(`#${pr}: REFUSED to write — the rewritten body does not read back`);
|
|
349
|
+
skipped++;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const patch = spawnSync(
|
|
354
|
+
"gh",
|
|
355
|
+
["api", "--method", "PATCH", `repos/${parsed.repo}/issues/comments/${comment.id}`,
|
|
356
|
+
"-f", `body=${nextBody}`],
|
|
357
|
+
{ encoding: "utf8" },
|
|
358
|
+
);
|
|
359
|
+
if (patch.status !== 0) {
|
|
360
|
+
console.error(`#${pr}: PATCH failed: ${(patch.stderr ?? "").trim()}`);
|
|
361
|
+
skipped++;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const summary = Object.entries(totals).sort().map(([k, v]) => `${k} ${v}`).join(", ");
|
|
366
|
+
console.log(`\nTOTAL: ${summary || "nothing unmeasured"}${skipped ? ` (${skipped} refused)` : ""}`);
|
|
367
|
+
return skipped > 0 ? RECORD_UNMEASURED_FAILED : 0;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (import.meta.main) process.exit(main(process.argv.slice(2)));
|
package/scripts/split-spec.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import { readFileSync,
|
|
3
|
+
import { readFileSync, mkdirSync } from "fs";
|
|
4
4
|
import { join, dirname } from "path";
|
|
5
5
|
import { localCalendarDay } from "../lib/local-calendar-day";
|
|
6
|
+
import { skipLine } from "../lib/derived-spec";
|
|
7
|
+
import { maySpecBeWritten, writeSpec } from "../lib/write-spec";
|
|
6
8
|
|
|
7
9
|
export interface SplitBoundary {
|
|
8
10
|
heading: string;
|
|
@@ -258,6 +260,17 @@ if (import.meta.main) {
|
|
|
258
260
|
const specPath = args[0];
|
|
259
261
|
const content = readFileSync(specPath, "utf-8");
|
|
260
262
|
|
|
263
|
+
// #1286: asked before ANYTHING is written, not beside the overwrite at the
|
|
264
|
+
// end. Splitting replaces the original with a redirect stub, so a spec a
|
|
265
|
+
// generator owns would lose its entire body to a stub the generator then
|
|
266
|
+
// overwrites — and refusing after the split files are on disk leaves the
|
|
267
|
+
// tree half-migrated.
|
|
268
|
+
const early = maySpecBeWritten(content);
|
|
269
|
+
if (!early.allowed) {
|
|
270
|
+
console.error(skipLine(specPath, early.reading));
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
|
|
261
274
|
// Check if split needed
|
|
262
275
|
if (!shouldSplit(content)) {
|
|
263
276
|
console.log("File does not need splitting (< 500 lines or already split)");
|
|
@@ -295,19 +308,19 @@ if (import.meta.main) {
|
|
|
295
308
|
// Write split files
|
|
296
309
|
for (const file of splitFiles) {
|
|
297
310
|
const filePath = join(splitDir, file.filename);
|
|
298
|
-
|
|
311
|
+
writeSpec(filePath, file.content);
|
|
299
312
|
console.log(`Created: ${filePath} (${file.lineCount} lines)`);
|
|
300
313
|
}
|
|
301
314
|
|
|
302
315
|
// Write INDEX.md
|
|
303
316
|
const indexContent = generateIndex(splitFiles, originalGoverns);
|
|
304
317
|
const indexPath = join(splitDir, "INDEX.md");
|
|
305
|
-
|
|
318
|
+
writeSpec(indexPath, indexContent);
|
|
306
319
|
console.log(`Created: ${indexPath}`);
|
|
307
320
|
|
|
308
321
|
// Replace original with redirect
|
|
309
322
|
const redirectContent = generateRedirect(specPath, splitDir, splitFiles);
|
|
310
|
-
|
|
323
|
+
writeSpec(specPath, redirectContent);
|
|
311
324
|
console.log(`Updated: ${specPath} (now a redirect)`);
|
|
312
325
|
|
|
313
326
|
console.log(
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* bun scripts/sync-sc-status.ts --report # Output per-spec coverage report
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { existsSync, readFileSync,
|
|
17
|
+
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
18
18
|
|
|
19
19
|
import { walkTestFiles } from "../lib/walk-test-files";
|
|
20
20
|
import { commentMask, enclosingComment, stripJsComments } from "../lib/strip-js-comments";
|
|
@@ -23,6 +23,8 @@ import { join } from "path";
|
|
|
23
23
|
import { execSync } from "child_process";
|
|
24
24
|
import { matchPattern, isBehavioralSC, type ParsedSC } from "../lib/conformity";
|
|
25
25
|
import { behavioralCachePath, readFreshCache } from "../lib/behavioral-cache";
|
|
26
|
+
import { skipLine } from "../lib/derived-spec";
|
|
27
|
+
import { maySpecBeWritten, writeSpec } from "../lib/write-spec";
|
|
26
28
|
import { detectDrift } from "./detect-sc-drift";
|
|
27
29
|
import {
|
|
28
30
|
ambiguityOf,
|
|
@@ -684,6 +686,16 @@ export function flipCheckboxes(specFile: string, scIds: string[], specsDir?: str
|
|
|
684
686
|
const dir = specsDir || SPECS_DIR;
|
|
685
687
|
const filePath = join(dir, specFile);
|
|
686
688
|
let content = readFileSync(filePath, "utf-8");
|
|
689
|
+
|
|
690
|
+
// #1286: ticking a checkbox is an in-place edit like any other. A spec a
|
|
691
|
+
// generator owns gets its ticks from the generator, and flipping one here
|
|
692
|
+
// is discarded at the next regeneration after breaking whatever pins it.
|
|
693
|
+
const early = maySpecBeWritten(content);
|
|
694
|
+
if (!early.allowed) {
|
|
695
|
+
console.warn(skipLine(specFile, early.reading));
|
|
696
|
+
return 0;
|
|
697
|
+
}
|
|
698
|
+
|
|
687
699
|
let flipped = 0;
|
|
688
700
|
|
|
689
701
|
for (const id of scIds) {
|
|
@@ -697,7 +709,7 @@ export function flipCheckboxes(specFile: string, scIds: string[], specsDir?: str
|
|
|
697
709
|
// Write unless dry-run: use explicit isDryRun param if provided, else module-level flag
|
|
698
710
|
const shouldSkipWrite = isDryRun !== undefined ? isDryRun : dryRun;
|
|
699
711
|
if (flipped > 0 && !shouldSkipWrite) {
|
|
700
|
-
|
|
712
|
+
writeSpec(filePath, content, { label: specFile });
|
|
701
713
|
}
|
|
702
714
|
return flipped;
|
|
703
715
|
}
|