@feigi/fleet-ctl 3.142.0 → 3.143.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/package.json +1 -1
- package/scripts/closeout.mjs +136 -56
- package/scripts/finisher-scope.mjs +12 -1
- package/scripts/main-checkout.mjs +19 -10
- package/scripts/phase0-receipt.mjs +1 -1
- package/scripts/phase0.mjs +85 -7
- package/scripts/reap.sh +162 -14
- package/scripts/reclaim-scratch.mjs +45 -4
- package/scripts/release-ticket.sh +3 -2
- package/scripts/run-records.mjs +251 -0
- package/skills/run-team/references/close-out.md +31 -2
- package/skills/run-team/references/finisher.md +1 -1
- package/skills/run-team/references/phase-0.md +30 -2
- package/skills/run-team/references/reaping.md +3 -2
package/package.json
CHANGED
package/scripts/closeout.mjs
CHANGED
|
@@ -38,13 +38,31 @@
|
|
|
38
38
|
// The verdicts come from `tier-outcomes.mjs append`, which
|
|
39
39
|
// works them out from the Charges; this script never writes one.
|
|
40
40
|
// metrics `metrics-refresh.mjs`. Any non-zero exit is a failed step.
|
|
41
|
+
// gather run-records.mjs's gather(): every run archive `ledger.mjs
|
|
42
|
+
// rotate` left in `.fleet/` (`ledger.<stamp>.md`,
|
|
43
|
+
// `phase0.<stamp>.json`, `closeout.<stamp>.json`) into
|
|
44
|
+
// `docs/metrics/runs/<stamp>/` with its `plugin-version`, and
|
|
45
|
+
// every review's `review.json` and Charges file under the
|
|
46
|
+
// scratch root into `docs/metrics/reviews/<pr>/<run>/`. The
|
|
47
|
+
// phase-0 receipt's `recipe` step output is withheld, since
|
|
48
|
+
// a Recipe command can carry an environment assignment. A
|
|
49
|
+
// run's own archives exist only once the next run has
|
|
50
|
+
// rotated, so this commits the runs before it; a file main
|
|
51
|
+
// already holds comes back byte for byte and adds nothing.
|
|
52
|
+
// A directory it cannot list or a file it cannot copy fails
|
|
53
|
+
// the step.
|
|
41
54
|
// commit-and-pr `git switch -c <branch>` (`--branch`, default
|
|
42
55
|
// `chore/run-artifacts-<UTC date>`, suffixed `b`, `c`… while
|
|
43
|
-
// that name exists locally or on origin),
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
56
|
+
// that name exists locally or on origin), `git add` the
|
|
57
|
+
// new and changed files under `docs/metrics/runs/` and
|
|
58
|
+
// `docs/metrics/reviews/` that isRunRecord() allows, commit
|
|
59
|
+
// exactly those and the three `docs/metrics/*.tsv` files,
|
|
60
|
+
// `git fetch origin`, `git rebase origin/main`, push `-u`
|
|
61
|
+
// with a lease, `gh pr
|
|
62
|
+
// create --label patch` with a body naming the reason, the
|
|
63
|
+
// rows each file gained and lost and the record files
|
|
64
|
+
// added, `git switch main`. A file there that isRunRecord()
|
|
65
|
+
// does not allow is never staged; the output names it. The
|
|
48
66
|
// rebase is three-way, so rows `main` gained during the run
|
|
49
67
|
// stay; one that conflicts or that git refuses is aborted, the
|
|
50
68
|
// branch is pushed as it was, and the PR is opened all the
|
|
@@ -146,13 +164,14 @@ import { homedir } from "node:os";
|
|
|
146
164
|
import { dirname, join } from "node:path";
|
|
147
165
|
import { fileURLToPath } from "node:url";
|
|
148
166
|
import { makeDie, defineFlags } from "./arg.mjs";
|
|
149
|
-
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
167
|
+
import { FleetDirUnresolvable, fleetFile, scratchRoot } from "./fleet-dir.mjs";
|
|
150
168
|
import { inertVerdict } from "./finisher-scope.mjs";
|
|
151
169
|
import { gitEnv } from "./git-env.mjs";
|
|
152
170
|
import { isCLI } from "./is-cli.mjs";
|
|
153
171
|
import { CLOSEOUT_RECEIPT, RECEIPT, RECEIPT_HELD, memberTokens, rowPr, isOmpSessionDirName } from "./ledger-grammar.mjs";
|
|
154
172
|
import { encodeProjectDir } from "./member-record.mjs";
|
|
155
173
|
import { tickCaps } from "./phase0-receipt.mjs";
|
|
174
|
+
import { RECORD_DIRS, gather, recordChanges, refusedLine } from "./run-records.mjs";
|
|
156
175
|
|
|
157
176
|
const NAME = "closeout";
|
|
158
177
|
const SCRIPTS = dirname(fileURLToPath(import.meta.url));
|
|
@@ -334,12 +353,31 @@ function stepMetrics({ cwd }) {
|
|
|
334
353
|
return r.status === 0 ? ok(r.stdout) : failed(`metrics-refresh.mjs failed: ${detail(r)}`);
|
|
335
354
|
}
|
|
336
355
|
|
|
337
|
-
//
|
|
356
|
+
// Copies the run archives and the review evidence into the checkout, for the
|
|
357
|
+
// commit step to stage.
|
|
358
|
+
function stepGather({ fleetDir }) {
|
|
359
|
+
const wt = workTree();
|
|
360
|
+
if (wt.error) return failed(wt.error);
|
|
361
|
+
let scratch;
|
|
362
|
+
try {
|
|
363
|
+
scratch = scratchRoot({ cwd: wt.cwd });
|
|
364
|
+
} catch (e) {
|
|
365
|
+
if (!(e instanceof FleetDirUnresolvable)) throw e;
|
|
366
|
+
return failed(`cannot name the scratch root: ${e.message}`);
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
return ok(gather({ cwd: wt.cwd, fleetDir, scratch }).join("\n"));
|
|
370
|
+
} catch (e) {
|
|
371
|
+
return failed(`gather failed: ${e.message}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// A name for the branch: `--branch` as given, else `stem` and the UTC date,
|
|
338
376
|
// lettered while the name is taken. A probe that fails to answer is no answer
|
|
339
377
|
// at all, never "not taken".
|
|
340
|
-
function pickBranch(git, given) {
|
|
378
|
+
function pickBranch(git, given, stem) {
|
|
341
379
|
if (given !== null) return { name: given };
|
|
342
|
-
const base =
|
|
380
|
+
const base = `${stem}${new Date().toISOString().slice(0, 10).replaceAll("-", "")}`;
|
|
343
381
|
for (const suffix of ["", ..."bcdefghijklmnopqrstuvwxyz"]) {
|
|
344
382
|
const name = base + suffix;
|
|
345
383
|
const local = git(["show-ref", "--verify", "--quiet", `refs/heads/${name}`]);
|
|
@@ -351,11 +389,22 @@ function pickBranch(git, given) {
|
|
|
351
389
|
return { error: `every lettered ${base} name is taken` };
|
|
352
390
|
}
|
|
353
391
|
|
|
354
|
-
// The rows each metrics file gained and lost on the branch, one TSV line a
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
392
|
+
// The rows each metrics file gained and lost on the branch, one TSV line a
|
|
393
|
+
// row, then the record files it adds under each of RECORD_DIRS.
|
|
394
|
+
function rowCounts(git, tsvs) {
|
|
395
|
+
const lines = [];
|
|
396
|
+
if (tsvs.length > 0) {
|
|
397
|
+
const r = git(["diff", "--numstat", "origin/main...HEAD", "--", ...tsvs]);
|
|
398
|
+
if (r.status !== 0) return { error: `git diff --numstat failed: ${detail(r)}` };
|
|
399
|
+
lines.push(...r.stdout.split("\n").filter(Boolean).map((l) => l.split("\t")).map(([added, removed, file]) => `- ${file}: +${added} -${removed}`));
|
|
400
|
+
}
|
|
401
|
+
for (const dir of RECORD_DIRS) {
|
|
402
|
+
const r = git(["diff", "--name-only", "--diff-filter=A", "origin/main...HEAD", "--", dir]);
|
|
403
|
+
if (r.status !== 0) return { error: `git diff --name-only -- ${dir} failed: ${detail(r)}` };
|
|
404
|
+
const added = r.stdout.split("\n").filter(Boolean).length;
|
|
405
|
+
if (added > 0) lines.push(`- ${dir}/: ${added} file(s) added`);
|
|
406
|
+
}
|
|
407
|
+
return { lines };
|
|
359
408
|
}
|
|
360
409
|
|
|
361
410
|
// Replays the branch's commit onto the `origin/main` just fetched, three-way,
|
|
@@ -385,42 +434,57 @@ function rebaseOntoMain(git) {
|
|
|
385
434
|
return { leftOpen: `rebase refused: ${refused}` };
|
|
386
435
|
}
|
|
387
436
|
|
|
388
|
-
// Everything the
|
|
389
|
-
// caller switches back to main whatever this returns.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
437
|
+
// Everything the commit flow does while the checkout is on its branch; the
|
|
438
|
+
// caller switches back to main whatever this returns or throws. `tsvs` are
|
|
439
|
+
// the metrics files the commit carries beside the record files; `rebase`
|
|
440
|
+
// false skips the fetch and the replay, for a caller whose branch was cut from
|
|
441
|
+
// an `origin/main` it has just fetched and whose work tree may hold changes
|
|
442
|
+
// the commit leaves out.
|
|
443
|
+
function onBranch({ git, cwd, title, tsvs, rebase, state, save }) {
|
|
444
|
+
const records = recordChanges(git, cwd);
|
|
445
|
+
if (records.error) return failed(records.error);
|
|
446
|
+
const refusedLines = records.refused.map(refusedLine);
|
|
447
|
+
const fail = (line) => failed([...refusedLines, line].join("\n"));
|
|
448
|
+
if (records.allowed.length > 0) {
|
|
449
|
+
const add = git(["add", "--", ...records.allowed]);
|
|
450
|
+
if (add.status !== 0) return fail(`git add failed: ${detail(add)}`);
|
|
451
|
+
}
|
|
452
|
+
const paths = [...tsvs, ...records.allowed];
|
|
453
|
+
if (paths.length > 0) {
|
|
454
|
+
const dirty = git(["status", "--porcelain", "--", ...paths]);
|
|
455
|
+
if (dirty.status !== 0) return fail(`git status failed: ${detail(dirty)}`);
|
|
456
|
+
if (dirty.stdout !== "") {
|
|
457
|
+
const commit = git(["commit", "-m", title, "--", ...paths]);
|
|
458
|
+
if (commit.status !== 0) return fail(`git commit failed: ${detail(commit)}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const rebased = rebase ? rebaseOntoMain(git) : { leftOpen: null };
|
|
462
|
+
if (rebased.error) return fail(rebased.error);
|
|
399
463
|
const ahead = git(["rev-list", "--count", "origin/main..HEAD"]);
|
|
400
|
-
if (ahead.status !== 0) return
|
|
401
|
-
if (ahead.stdout === "0") return
|
|
464
|
+
if (ahead.status !== 0) return fail(`git rev-list --count origin/main..HEAD failed: ${detail(ahead)}`);
|
|
465
|
+
if (ahead.stdout === "0") return fail(`nothing to commit: ${[...tsvs, ...RECORD_DIRS].join(", ")} are unchanged`);
|
|
402
466
|
const head = git(["rev-parse", "HEAD"]);
|
|
403
|
-
if (head.status !== 0) return
|
|
467
|
+
if (head.status !== 0) return fail(`git rev-parse HEAD failed: ${detail(head)}`);
|
|
404
468
|
|
|
405
469
|
// The lease is the head this step last pushed, never what the fetch above
|
|
406
470
|
// just read: an empty one expects the branch absent from origin.
|
|
407
|
-
const lease = `--force-with-lease=refs/heads/${
|
|
408
|
-
const push = git(["push", "-u", lease, "origin",
|
|
409
|
-
if (push.status !== 0) return
|
|
410
|
-
|
|
411
|
-
|
|
471
|
+
const lease = `--force-with-lease=refs/heads/${state.branch}:${state.pin ?? ""}`;
|
|
472
|
+
const push = git(["push", "-u", lease, "origin", state.branch], NETWORK_TIMEOUT_MS);
|
|
473
|
+
if (push.status !== 0) return fail(`git push failed: ${detail(push)}`);
|
|
474
|
+
state.pin = head.stdout;
|
|
475
|
+
state.rebase = rebased.leftOpen;
|
|
412
476
|
save();
|
|
413
|
-
const lines = [`pushed ${
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
const counts = rowCounts(git);
|
|
417
|
-
if (counts.error) return
|
|
418
|
-
const body =
|
|
419
|
-
const pr = run("gh", ["pr", "create", "--head",
|
|
420
|
-
if (pr.status !== 0) return
|
|
421
|
-
|
|
477
|
+
const lines = [...refusedLines, `pushed ${state.pin}`, ...(rebased.leftOpen === null ? [] : [rebased.leftOpen])];
|
|
478
|
+
|
|
479
|
+
if (state.pr !== null) return ok([...lines, `PR ${state.pr} already opened for ${state.branch}`].join("\n"));
|
|
480
|
+
const counts = rowCounts(git, tsvs);
|
|
481
|
+
if (counts.error) return fail(counts.error);
|
|
482
|
+
const body = `${title}\n\nRows changed:\n${counts.lines.join("\n")}\n`;
|
|
483
|
+
const pr = run("gh", ["pr", "create", "--head", state.branch, "--title", title, "--label", "patch", "--body", body], { cwd, env: { GH_REPO: "" }, timeoutMs: NETWORK_TIMEOUT_MS });
|
|
484
|
+
if (pr.status !== 0) return fail(`gh pr create failed: ${detail(pr)}`);
|
|
485
|
+
state.pr = pr.stdout.split("\n").at(-1);
|
|
422
486
|
save();
|
|
423
|
-
return ok([...lines, `PR ${
|
|
487
|
+
return ok([...lines, `PR ${state.pr} opened on ${state.branch}`].join("\n"));
|
|
424
488
|
}
|
|
425
489
|
|
|
426
490
|
// The work tree the command runs in, as `{ cwd }`, or `{ error }`.
|
|
@@ -429,29 +493,44 @@ function workTree() {
|
|
|
429
493
|
return top.status === 0 ? { cwd: top.stdout } : { error: `not inside a git work tree: ${detail(top)}` };
|
|
430
494
|
}
|
|
431
495
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
496
|
+
/**
|
|
497
|
+
* The commit flow the Close-out PR and phase 0's catch-up share, run in the
|
|
498
|
+
* checkout at `cwd`: switch to `state.branch`, or cut one (`given`, else
|
|
499
|
+
* pickBranch() over `stem`) when it is null, stage and commit the allowed
|
|
500
|
+
* record files and `tsvs` under `title`, rebase when `rebase` is true, push
|
|
501
|
+
* with a lease, open the PR, and switch back to main, a throw on the branch
|
|
502
|
+
* included. `state` carries `{branch, pr, pin, rebase}` across calls and
|
|
503
|
+
* `save()` records it. The result is a step's `{status, output}`.
|
|
504
|
+
*/
|
|
505
|
+
export function commitAndPr({ cwd, given = null, stem, title, tsvs, rebase, state, save }) {
|
|
436
506
|
const git = (args, timeoutMs) => run("git", args, { cwd, timeoutMs });
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const picked = pickBranch(git, branch);
|
|
507
|
+
if (state.branch === null) {
|
|
508
|
+
const picked = pickBranch(git, given, stem);
|
|
440
509
|
if (picked.error) return failed(picked.error);
|
|
441
510
|
const made = git(["switch", "-c", picked.name]);
|
|
442
511
|
if (made.status !== 0) return failed(`git switch -c ${picked.name} failed: ${detail(made)}`);
|
|
443
|
-
|
|
512
|
+
state.branch = picked.name;
|
|
444
513
|
save();
|
|
445
514
|
} else {
|
|
446
|
-
const back = git(["switch",
|
|
447
|
-
if (back.status !== 0) return failed(`git switch ${
|
|
515
|
+
const back = git(["switch", state.branch]);
|
|
516
|
+
if (back.status !== 0) return failed(`git switch ${state.branch} failed: ${detail(back)}`);
|
|
517
|
+
}
|
|
518
|
+
let result = null;
|
|
519
|
+
try {
|
|
520
|
+
result = onBranch({ git, cwd, title, tsvs, rebase, state, save });
|
|
521
|
+
} finally {
|
|
522
|
+
const main = git(["switch", "main"]);
|
|
523
|
+
if (main.status !== 0 && result !== null) result = failed([result.status === "ok" ? null : result.output, `git switch main failed: ${detail(main)}`].filter(Boolean).join("\n"));
|
|
448
524
|
}
|
|
449
|
-
const result = onBranch({ git, cwd, reason, receipt, save });
|
|
450
|
-
const main = git(["switch", "main"]);
|
|
451
|
-
if (main.status !== 0) return failed([result.status === "ok" ? null : result.output, `git switch main failed: ${detail(main)}`].filter(Boolean).join("\n"));
|
|
452
525
|
return result;
|
|
453
526
|
}
|
|
454
527
|
|
|
528
|
+
function stepCommitAndPR({ reason, branch, receipt, save }) {
|
|
529
|
+
const wt = workTree();
|
|
530
|
+
if (wt.error) return failed(wt.error);
|
|
531
|
+
return commitAndPr({ cwd: wt.cwd, given: branch, stem: "chore/run-artifacts-", title: `Closeout: ${reason}`, tsvs: METRICS, rebase: true, state: receipt, save });
|
|
532
|
+
}
|
|
533
|
+
|
|
455
534
|
// The receipt `phase0.mjs` resumes would otherwise outlive the run it describes.
|
|
456
535
|
// It is set aside under the name `phase0.mjs` holds a previous run's receipt
|
|
457
536
|
// under, which the next run's rotation restores and archives with the ledger.
|
|
@@ -619,6 +698,7 @@ const FINISH = {
|
|
|
619
698
|
scrape: stepScrape,
|
|
620
699
|
"tier-outcomes": stepTierOutcomes,
|
|
621
700
|
metrics: stepMetrics,
|
|
701
|
+
gather: stepGather,
|
|
622
702
|
"commit-and-pr": stepCommitAndPR,
|
|
623
703
|
"phase0-receipt": stepPhase0Receipt,
|
|
624
704
|
"heartbeat-stop": stepHeartbeatStop,
|
|
@@ -30,7 +30,11 @@
|
|
|
30
30
|
// CLAUDE.md or GEMINI.md, at any depth. A file directly in the root
|
|
31
31
|
// .out-of-scope/, spelled exactly so, is exempt from the dot rule
|
|
32
32
|
// alone
|
|
33
|
-
// data one of the METRICS paths closeout.mjs names,
|
|
33
|
+
// data one of the METRICS paths closeout.mjs names, or a run record or
|
|
34
|
+
// review evidence file run-records.mjs's isRunRecord() accepts — a
|
|
35
|
+
// path of the allowlisted shape under docs/metrics/runs/ or
|
|
36
|
+
// docs/metrics/reviews/ — that is also outside the prompt surface,
|
|
37
|
+
// and no other file
|
|
34
38
|
//
|
|
35
39
|
// Stdout is one JSON line:
|
|
36
40
|
//
|
|
@@ -60,6 +64,7 @@ import { statSync } from "node:fs";
|
|
|
60
64
|
import { isAbsolute, resolve } from "node:path";
|
|
61
65
|
import { makeDie, defineFlags, writeAll } from "./arg.mjs";
|
|
62
66
|
import { METRICS } from "./closeout.mjs";
|
|
67
|
+
import { isRunRecord } from "./run-records.mjs";
|
|
63
68
|
import { isDocs, isMarkdown, isTestDir } from "./diff-stats.mjs";
|
|
64
69
|
import { gitEnv } from "./git-env.mjs";
|
|
65
70
|
import { isCLI } from "./is-cli.mjs";
|
|
@@ -136,6 +141,12 @@ export function classifyEntry(path, status, oldMode, newMode) {
|
|
|
136
141
|
const mode = modeProblem(status, oldMode, newMode);
|
|
137
142
|
if (mode !== null) return { class: null, why: mode };
|
|
138
143
|
if (METRICS.includes(path)) return { class: "data", why: "run metrics file" };
|
|
144
|
+
if (isRunRecord(path)) {
|
|
145
|
+
// No name isRunRecord() accepts is on the prompt surface today; the check
|
|
146
|
+
// stays so a record still has to pass it should either rule ever widen.
|
|
147
|
+
const surface = promptSurface(path);
|
|
148
|
+
return surface === null ? { class: "data", why: "run record or review evidence file" } : { class: null, why: surface };
|
|
149
|
+
}
|
|
139
150
|
if (isTestDir(path)) return { class: null, why: "under a test directory" };
|
|
140
151
|
if (!isMarkdown(path)) return { class: null, why: isDocs(path) ? "docs, but not .md or .markdown" : "not prose or data" };
|
|
141
152
|
const surface = promptSurface(path);
|
|
@@ -56,10 +56,17 @@
|
|
|
56
56
|
// Compared like any other path, the first append would hold every
|
|
57
57
|
// dispatching row for the rest of the run, and clearing it with `--record`
|
|
58
58
|
// after every ruling would certify whatever stray write landed beside it.
|
|
59
|
-
// So `snapshot()` leaves
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
59
|
+
// So `snapshot()` leaves those three paths out, for the reason instruments.sh
|
|
60
|
+
// leaves `docs/metrics/` out of its pin.
|
|
61
|
+
// The same holds for the run records and review evidence the close-out and
|
|
62
|
+
// phase 0's catch-up copy into `docs/metrics/runs/` and `docs/metrics/reviews/`
|
|
63
|
+
// and commit on a branch, which appear in the work tree and leave it again
|
|
64
|
+
// when the checkout switches back to main: a path run-records.mjs's
|
|
65
|
+
// isRunRecord() allows is left out too, while it is the regular file with no
|
|
66
|
+
// executable bit a commit carries. A symlink or an executable there, which
|
|
67
|
+
// the commit refuses, is still audited. Named files and one allowlisted shape,
|
|
68
|
+
// not the directory: anything else under `docs/metrics/` is still a stray
|
|
69
|
+
// write. The price: a member's leaked write to one of those paths goes unseen.
|
|
63
70
|
//
|
|
64
71
|
// FOUR ANSWERS, worktree-audit.sh's three plus the baseline's own refusal:
|
|
65
72
|
// clean — the porcelain entries and hashes equal the baseline's, and HEAD
|
|
@@ -124,10 +131,12 @@ import { join } from "node:path";
|
|
|
124
131
|
import { isCLI } from "./is-cli.mjs";
|
|
125
132
|
import { makeDie, defineFlags } from "./arg.mjs";
|
|
126
133
|
import { gitEnv, mainCheckoutDirFromGitCommonDir } from "./git-env.mjs";
|
|
134
|
+
import { isPlainFile, isRunRecord } from "./run-records.mjs";
|
|
127
135
|
|
|
128
136
|
export const BASELINE_FILE = "main-checkout.sha";
|
|
129
137
|
export const RECORD_COMMAND = "~/.omp/plugins/node_modules/@feigi/fleet-ctl/scripts/fleet-run main-checkout.mjs --record";
|
|
130
|
-
const
|
|
138
|
+
const RUN_METRICS = new Set(["docs/metrics/tier-outcomes.tsv", "docs/metrics/member-outcomes.tsv", "docs/metrics/ticket-features.tsv"]);
|
|
139
|
+
const isRunBookkeeping = (root, rel) => RUN_METRICS.has(rel) || (isRunRecord(rel) && isPlainFile(join(root, rel)));
|
|
131
140
|
// Any change to an entry's hash or to a line's format bumps VERSION: a
|
|
132
141
|
// baseline an older plugin wrote then reads `outdated` (re-record) and one a
|
|
133
142
|
// newer plugin wrote reads `newer`, never as a baseline this code wrote.
|
|
@@ -209,11 +218,11 @@ const sha = (buf) => createHash("sha256").update(buf).digest("hex");
|
|
|
209
218
|
// the hash where its status line would not — folded with its HEAD, so a
|
|
210
219
|
// commit in it moves the hash too. A commitless repository's HEAD is the
|
|
211
220
|
// branch it names. Nothing is left out: the run's bookkeeping is
|
|
212
|
-
// `
|
|
221
|
+
// `isRunBookkeeping`, the main checkout's paths, not a nested
|
|
213
222
|
// repository's. Any git that fails throws: `unknown`, never a hash that reads
|
|
214
223
|
// clean.
|
|
215
224
|
function nestedHash(abs, env) {
|
|
216
|
-
const now = entriesAt(abs, env,
|
|
225
|
+
const now = entriesAt(abs, env, () => false);
|
|
217
226
|
if (!now.ok) throw new Error(now.why);
|
|
218
227
|
let head = git("git rev-parse HEAD", ["rev-parse", "-q", "--verify", "HEAD^{commit}"], abs, env);
|
|
219
228
|
if (!head.ok) {
|
|
@@ -241,10 +250,10 @@ function nestedHash(abs, env) {
|
|
|
241
250
|
* `--no-renames` so every entry names exactly one path.
|
|
242
251
|
*/
|
|
243
252
|
export function snapshot(root, env = process.env) {
|
|
244
|
-
return entriesAt(root, env,
|
|
253
|
+
return entriesAt(root, env, (rel) => isRunBookkeeping(root, rel));
|
|
245
254
|
}
|
|
246
255
|
|
|
247
|
-
// `snapshot` of the repository at `root`, leaving out
|
|
256
|
+
// `snapshot` of the repository at `root`, leaving out each path `skip` accepts.
|
|
248
257
|
function entriesAt(root, env, skip) {
|
|
249
258
|
const r = git("git status --porcelain -uall", ["--no-optional-locks", "status", "--porcelain", "-uall", "-z", "--no-renames"], root, env);
|
|
250
259
|
if (!r.ok) return r;
|
|
@@ -253,8 +262,8 @@ function entriesAt(root, env, skip) {
|
|
|
253
262
|
if (!line) continue;
|
|
254
263
|
if (line.length < 4 || line[2] !== " ") return { ok: false, why: `git status printed an entry it does not document: ${JSON.stringify(line)}` };
|
|
255
264
|
const rel = line.slice(3);
|
|
256
|
-
if (skip.has(rel)) continue;
|
|
257
265
|
try {
|
|
266
|
+
if (skip(rel)) continue;
|
|
258
267
|
entries.set(line, hashPath(root, rel, env));
|
|
259
268
|
} catch (e) {
|
|
260
269
|
return { ok: false, why: `cannot hash ${rel}: ${e?.code ?? e?.message ?? e}` };
|
|
@@ -20,7 +20,7 @@ const isRecord = (x) => x !== null && typeof x === "object" && !Array.isArray(x)
|
|
|
20
20
|
// by a finished phase 0.
|
|
21
21
|
export const STEP_NAMES = Object.freeze([
|
|
22
22
|
"alarm", "branch", "fast-forward", "pin", "baseline", "labels", "preflight", "ruleset", "tier-roles", "metrics",
|
|
23
|
-
"cockpit", "rotate", "reclaim", "evict", "recipe", "fold-in", "stranded", "shortlist",
|
|
23
|
+
"cockpit", "rotate", "catch-up", "reclaim", "evict", "recipe", "fold-in", "stranded", "shortlist",
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
26
|
// The statuses a step can end in that let the run go on: `ok`, and the two
|
package/scripts/phase0.mjs
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
// worktree refuses: the checks below judge the checkout the controller reads
|
|
19
19
|
// its rules from). The steps, each a named entry in the receipt, run in
|
|
20
20
|
// this order because the order is the point — the pin is recorded after the
|
|
21
|
-
// fast-forward, the rotation comes before the fold-in, the
|
|
22
|
-
//
|
|
23
|
-
// Pull is routed:
|
|
21
|
+
// fast-forward, the rotation comes before the fold-in, the catch-up straight
|
|
22
|
+
// after the rotation and the scratch reclaim straight after the catch-up, the
|
|
23
|
+
// metrics refresh before the first Pull is routed:
|
|
24
24
|
//
|
|
25
25
|
// alarm `~/.fleet/alarm/<pid>.json` names this omp's pid and start time
|
|
26
26
|
// and this `.fleet/`. Missing, malformed or mismatched, or no omp
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
// pin `instruments.sh --pin`, which certifies the Install root; the
|
|
39
39
|
// ok line names its kind, root and version. A linked
|
|
40
40
|
// checkout refuses: a fleet run executes an installed package.
|
|
41
|
+
// The `version=` line the pin writes to
|
|
42
|
+
// `.fleet/instruments.sha` is the receipt's `pluginVersion`.
|
|
41
43
|
// baseline `main-checkout.mjs --record`; its refusals fail the step.
|
|
42
44
|
// labels `label-map.mjs ensure`, the Label map derivation step. Exit 0
|
|
43
45
|
// is ok, its output the map ensure printed. Exit 3 is pending,
|
|
@@ -65,6 +67,25 @@
|
|
|
65
67
|
// cockpit `board.mjs serve --open` launched detached, `--spend-dir`
|
|
66
68
|
// passed through. Recorded; never fails the run.
|
|
67
69
|
// rotate `ledger.mjs rotate`. Exit 2 is a refusal and fails the step.
|
|
70
|
+
// catch-up run-records.mjs's gather() copies every run archive in
|
|
71
|
+
// `.fleet/` (the previous run's, which the rotation has just
|
|
72
|
+
// filed, and any earlier one) and every review evidence file
|
|
73
|
+
// under the scratch root into `docs/metrics/runs/` and
|
|
74
|
+
// `docs/metrics/reviews/`; when that leaves main lacking a
|
|
75
|
+
// record of a run that never closed out — no
|
|
76
|
+
// `closeout.<stamp>.json` beside its ledger archive —
|
|
77
|
+
// closeout.mjs's commitAndPr() commits every file main lacks
|
|
78
|
+
// alone on `chore/run-records-<UTC date>` (lettered while
|
|
79
|
+
// taken), pushes it and opens a PR, then switches back to
|
|
80
|
+
// main. A run that closed out leaves its records to this
|
|
81
|
+
// run's close-out, which gathers them again, so the catch-up
|
|
82
|
+
// opens no second PR carrying the same files. Before the
|
|
83
|
+
// reclaim, so a close-out that never ran loses nothing: the
|
|
84
|
+
// reclaim keeps a merged PR's evidence until main holds it.
|
|
85
|
+
// Recorded, and never fails the run but for a checkout it
|
|
86
|
+
// could not switch back to main; what it could not commit,
|
|
87
|
+
// the close-out gathers again, and its output says how far
|
|
88
|
+
// a failed commit got — a branch pushed with no PR included.
|
|
68
89
|
// reclaim `reclaim-scratch.mjs --root <scratch> --after-rotate --apply`,
|
|
69
90
|
// then `reclaim-scratch.mjs --siblings --root <scratch> --apply`
|
|
70
91
|
// for the other keys under the scratch parent, which runs
|
|
@@ -102,7 +123,7 @@
|
|
|
102
123
|
// THE RECEIPT is `.fleet/phase0.json` (resolved through fleet-dir.mjs, so a
|
|
103
124
|
// worktree and the main checkout name one file):
|
|
104
125
|
//
|
|
105
|
-
// { run, session, scratch, inFlight, objective,
|
|
126
|
+
// { run, session, scratch, inFlight, objective, pluginVersion,
|
|
106
127
|
// steps: { <name>: { status, at, output } } }
|
|
107
128
|
//
|
|
108
129
|
// `status` is ok, pending, failed, drift or unanswered; `at` an ISO time;
|
|
@@ -119,6 +140,8 @@
|
|
|
119
140
|
// default when it records none — and a resume whose `--objective` names the
|
|
120
141
|
// other one exits 2 naming both, leaving the receipt as it was. A resumed
|
|
121
142
|
// receipt recording a value that is not an Objective exits 3 naming it.
|
|
143
|
+
// `pluginVersion` is the version the pin recorded, null when it recorded
|
|
144
|
+
// none; a resumed receipt keeps it.
|
|
122
145
|
//
|
|
123
146
|
// RESUMABLE. A re-run reads the receipt. It continues it — skipping every `ok`
|
|
124
147
|
// step but `alarm` and re-running the rest — only when its `run` equals the
|
|
@@ -173,6 +196,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
173
196
|
import { fileURLToPath } from "node:url";
|
|
174
197
|
import { makeDie, defineFlags, isDigits } from "./arg.mjs";
|
|
175
198
|
import { alarmFile } from "./controller-alarm.mjs";
|
|
199
|
+
import { commitAndPr } from "./closeout.mjs";
|
|
176
200
|
import { ownClosingIssues } from "./closing-refs.mjs";
|
|
177
201
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
178
202
|
import { readState, stateFileIn } from "./fleet-state.mjs";
|
|
@@ -183,6 +207,7 @@ import { OBJECTIVES, RECEIPT, RECEIPT_HELD, archiveStamp, receiptArchiveName, ro
|
|
|
183
207
|
import { ancestry, controllerOf, processSource, ProcUnreadable } from "./proc.mjs";
|
|
184
208
|
import { IN_FLIGHT_DEFAULT, OBJECTIVE_DEFAULT } from "./phase0-receipt.mjs";
|
|
185
209
|
import { readRecipe } from "./recipe-read.mjs";
|
|
210
|
+
import { gather, recordChanges, refusedLine, unclosedRecords } from "./run-records.mjs";
|
|
186
211
|
|
|
187
212
|
const NAME = "phase0";
|
|
188
213
|
const SCRIPTS = dirname(fileURLToPath(import.meta.url));
|
|
@@ -249,14 +274,28 @@ function fastForward({ cwd }) {
|
|
|
249
274
|
return ok(`fast-forwarded ${behind} commits to origin/main`);
|
|
250
275
|
}
|
|
251
276
|
|
|
252
|
-
function pin({ cwd }) {
|
|
277
|
+
function pin({ cwd, fleetDir, receipt }) {
|
|
253
278
|
const r = sh("instruments.sh", ["--pin"], { cwd });
|
|
254
279
|
if (r.status !== 0) return refusal("instruments.sh --pin failed:", r);
|
|
280
|
+
receipt.pluginVersion = pinnedVersion(fleetDir);
|
|
255
281
|
// `instruments: pinned <digest> over <kind> <root> (version <v>)`
|
|
256
282
|
const m = /^instruments: pinned [0-9a-f]+ over (.+)$/m.exec(r.stderr);
|
|
257
283
|
return ok(`instruments pinned: ${m ? m[1] : r.stderr || "?"}`);
|
|
258
284
|
}
|
|
259
285
|
|
|
286
|
+
// The `version=` line of the pin `instruments.sh --pin` just wrote, or null
|
|
287
|
+
// when it wrote none or the file cannot be read.
|
|
288
|
+
function pinnedVersion(fleetDir) {
|
|
289
|
+
let text;
|
|
290
|
+
try {
|
|
291
|
+
text = readFileSync(join(fleetDir, "instruments.sha"), "utf8");
|
|
292
|
+
} catch {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
const m = /^version=(\S+)$/m.exec(text);
|
|
296
|
+
return m === null ? null : m[1];
|
|
297
|
+
}
|
|
298
|
+
|
|
260
299
|
function baseline({ cwd }) {
|
|
261
300
|
const r = node("main-checkout.mjs", ["--record"], { cwd });
|
|
262
301
|
if (r.status !== 0) return refusal("main-checkout.mjs --record refused:", r);
|
|
@@ -352,6 +391,44 @@ function rotate(ctx) {
|
|
|
352
391
|
return ok([head, ...lines(r.stderr).map((l) => l.trim())].join("\n"));
|
|
353
392
|
}
|
|
354
393
|
|
|
394
|
+
// The previous runs' archives and the review evidence in scratch, committed on
|
|
395
|
+
// a branch of their own when main lacks a record of a run that never closed
|
|
396
|
+
// out. A run that closed out leaves its records to the next close-out, this
|
|
397
|
+
// run's, which gathers everything again, so committing them here too would
|
|
398
|
+
// open a second PR carrying the same files. The work tree may hold the metrics
|
|
399
|
+
// refresh's rows, which the commit leaves out, so the branch is cut from the
|
|
400
|
+
// main the fast-forward just brought level and is not rebased.
|
|
401
|
+
function catchUp({ cwd, fleetDir, scratch }) {
|
|
402
|
+
let gathered;
|
|
403
|
+
try {
|
|
404
|
+
gathered = gather({ cwd, fleetDir, scratch });
|
|
405
|
+
} catch (e) {
|
|
406
|
+
return ok(`not gathered: ${e.message} — the close-out gathers them`);
|
|
407
|
+
}
|
|
408
|
+
const git = (args, timeoutMs) => run("git", args, { cwd, timeoutMs });
|
|
409
|
+
const records = recordChanges(git, cwd);
|
|
410
|
+
if (records.error) return ok([...gathered, `not committed: ${records.error} — the close-out commits them`].join("\n"));
|
|
411
|
+
const refused = records.refused.map(refusedLine);
|
|
412
|
+
if (records.allowed.length === 0) {
|
|
413
|
+
return ok([...gathered, ...refused, "nothing to catch up: main holds every run record and review evidence file"].join("\n"));
|
|
414
|
+
}
|
|
415
|
+
if (unclosedRecords(fleetDir, records.allowed).length === 0) {
|
|
416
|
+
return ok([...gathered, ...refused, "nothing to catch up: every run whose records main lacks closed out, so this run's close-out commits them"].join("\n"));
|
|
417
|
+
}
|
|
418
|
+
const state = { branch: null, pr: null, pin: null, rebase: null };
|
|
419
|
+
const result = commitAndPr({ cwd, stem: "chore/run-records-", title: "Run records: phase 0 catch-up", tsvs: [], rebase: false, state, save: () => {} });
|
|
420
|
+
if (result.status === "ok") return ok([...gathered, result.output].join("\n"));
|
|
421
|
+
const head = git(["symbolic-ref", "-q", "HEAD"]);
|
|
422
|
+
if (head.status === 0 && head.stdout === "refs/heads/main") {
|
|
423
|
+
// How far the flow got before it failed, from what it recorded on the way.
|
|
424
|
+
const left = state.pin !== null
|
|
425
|
+
? `pushed ${state.branch} at ${state.pin}, but no PR is open for it`
|
|
426
|
+
: state.branch !== null ? `not pushed; whatever was committed stays on the local branch ${state.branch}` : "not committed";
|
|
427
|
+
return ok([...gathered, `${left}: ${result.output} — the close-out commits them`].join("\n"));
|
|
428
|
+
}
|
|
429
|
+
return failed([...gathered, result.output, "the checkout is not back on main — switch it to main before the run goes on"].join("\n"));
|
|
430
|
+
}
|
|
431
|
+
|
|
355
432
|
function reclaim({ cwd, scratch }) {
|
|
356
433
|
const live = node("reclaim-scratch.mjs", ["--root", scratch, "--after-rotate", "--apply"], { cwd });
|
|
357
434
|
// The sibling pass runs whatever the live sweep answered: a failure there is recorded beside it, never a reason to skip it.
|
|
@@ -549,7 +626,7 @@ function alarm({ fleetDir }) {
|
|
|
549
626
|
const STEPS = {
|
|
550
627
|
"alarm": alarm, "branch": branch, "fast-forward": fastForward, "pin": pin, "baseline": baseline, "labels": labels,
|
|
551
628
|
"preflight": preflight, "ruleset": ruleset, "tier-roles": tierRoles, "metrics": metrics, "cockpit": cockpit, "rotate": rotate,
|
|
552
|
-
"reclaim": reclaim, "evict": evict, "recipe": recipe, "fold-in": foldIn, "stranded": stranded, "shortlist": shortlist,
|
|
629
|
+
"catch-up": catchUp, "reclaim": reclaim, "evict": evict, "recipe": recipe, "fold-in": foldIn, "stranded": stranded, "shortlist": shortlist,
|
|
553
630
|
};
|
|
554
631
|
|
|
555
632
|
const STEP_NAMES = Object.keys(STEPS);
|
|
@@ -705,7 +782,8 @@ function main() {
|
|
|
705
782
|
renameSync(receiptPath, held);
|
|
706
783
|
}
|
|
707
784
|
|
|
708
|
-
const
|
|
785
|
+
const pluginVersion = resumed && typeof previous.pluginVersion === "string" ? previous.pluginVersion : null;
|
|
786
|
+
const receipt = { run: resumed ? previous.run : null, session, scratch, inFlight, objective, pluginVersion, steps: {} };
|
|
709
787
|
for (const name of STEP_NAMES) {
|
|
710
788
|
// `alarm` checks the omp running this invocation, so its `ok` is never carried.
|
|
711
789
|
const was = resumed && name !== "alarm" ? previous.steps[name] : undefined;
|