@feigi/fleet-ctl 3.66.2 → 3.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/claim-ticket.sh +1 -1
- package/scripts/fleet-event.mjs +147 -15
- package/scripts/fleet-heartbeat.mjs +2 -2
- package/scripts/fleet-tick.mjs +104 -10
- package/skills/run-team/SKILL.md +148 -515
- package/skills/run-team/references/isolation.md +104 -1
- package/skills/run-team/references/phase-0.md +1 -1
- package/skills/run-team/references/pull.md +346 -0
package/package.json
CHANGED
package/scripts/claim-ticket.sh
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#
|
|
7
7
|
# The claim is branch `<type>/<issue>-<slug>` and worktree
|
|
8
8
|
# `.worktrees/<issue>-<slug>`. The fleet always calls it as
|
|
9
|
-
# `claim-ticket.sh <N> impl-<N> implementer` (run-team
|
|
9
|
+
# `claim-ticket.sh <N> impl-<N> implementer` (run-team references/pull.md, **Claiming**),
|
|
10
10
|
# giving `implementer/<N>-impl-<N>` and `.worktrees/<N>-impl-<N>`, and releases
|
|
11
11
|
# with the same pair through release-ticket.sh. <slug> and <type> are
|
|
12
12
|
# free text — neither derived nor validated here — so a caller outside the fleet
|
package/scripts/fleet-event.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// A
|
|
3
|
-
// the tick.
|
|
2
|
+
// A wake recorded as one command: the writes it owes, then the tick.
|
|
4
3
|
//
|
|
5
4
|
// fleet-event.mjs <kind> <args> [--in-flight <n>]
|
|
5
|
+
// fleet-event.mjs drain --reason "<reason>" [--in-flight <n>]
|
|
6
6
|
//
|
|
7
7
|
// Reached through the Resolver and run from the main checkout. Every kind
|
|
8
8
|
// performs its writes, then runs `fleet-tick.mjs --apply` with the In-flight
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// settled, under any outcome, is not settled again.
|
|
19
19
|
//
|
|
20
20
|
// impl-report <impl-N[-x]>
|
|
21
|
-
// `ledger.mjs settle <member> --from-report
|
|
21
|
+
// `ledger.mjs settle <member> --from-report`, which runs `verify-sha.sh` and reads the PR itself. Settled `bailed`: the
|
|
22
22
|
// report's `bailCause` names the label (undecided `needs-triage`, fork
|
|
23
23
|
// and hands `ready-for-human`), then:
|
|
24
24
|
// `gh issue edit <N> --remove-label ready-for-agent --remove-label
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
// It runs on a second run too: it measures the claim again and
|
|
36
36
|
// writes nothing when nothing is left to release. A refusal prints
|
|
37
37
|
// `NEED hand-release #<N> <blocker>` and is never forced.
|
|
38
|
+
// Dropping `in-progress` is the load-bearing half: phase 1 applied it and `candidates.mjs` excludes it, so leaving it makes the ticket invisible to the controller's scans and the maintainer's. It does not loop; it disappears.
|
|
39
|
+
// `reap.sh` declines a claim that never became a PR, so the release of a bailed claim is `release-ticket.sh`'s.
|
|
38
40
|
// fix-report <fix-pr-M[-x]>
|
|
39
41
|
// `settle --from-report`, which records the filings and rulings the
|
|
40
42
|
// report carries. Settled `applied:`/`no-op`, on a PR whose rows carry
|
|
@@ -54,11 +56,15 @@
|
|
|
54
56
|
// whether or not its settle was accepted, since the settle refuses
|
|
55
57
|
// exactly that read-back. Either comment is skipped when the PR already
|
|
56
58
|
// carries it.
|
|
59
|
+
// A settle that refuses on `ready-to-merge` — missing from the PR or from the read-back — is the case the tick's `DISPATCH finisher PR#<M>` catches next: settle it `ledger.mjs settle finisher-pr-<M>=labelled` as reported, and `ledger.mjs filed <N> "<subject>"` for each `unrecorded` entry.
|
|
57
60
|
// merge-bot-report <merge-bot-n>
|
|
58
61
|
// `ledger.mjs token <pr> held-behind:#<behind>` for each `held[]` entry
|
|
59
62
|
// of the report the PR's rows do not already carry, then `settle
|
|
60
63
|
// --from-report`. The reap and the reclaim run under the tick's
|
|
61
64
|
// `--apply`.
|
|
65
|
+
// The verdict moves no label and leaves nothing in the repo, so the row is the only place the tick can read a `held-behind` from.
|
|
66
|
+
// The reap and the reclaim run once for every merge bot settled `done`, always, even when the pass merged nothing, and again on the next tick after an `APPLY FAILED` line, and on every tick while this run has no controller record to remember the pass by.
|
|
67
|
+
// The bot may also have written `conflict-hold:#<pr>` onto a held PR's own row earlier in the same pass, before reporting: a token the bot wrote in that pass, never one `reap.sh` writes.
|
|
62
68
|
// review-result <pr> <path>
|
|
63
69
|
// The review result file at `<path>`, which must be
|
|
64
70
|
// `<scratch>/pr<pr>/<run>/<file>`, `<run>` a review run root
|
|
@@ -66,24 +72,68 @@
|
|
|
66
72
|
// `counts` make `ledger.mjs review <pr>
|
|
67
73
|
// reviewed=<head>:<survived>/<refuted>/<unverified>:<run>`, skipped when
|
|
68
74
|
// the PR's rows already carry that token.
|
|
75
|
+
// The result file is `<scratch>/pr<pr>/<run>/review.json`, `<run>` the review's own `run-XXXXXXXX` run root.
|
|
69
76
|
// review-failed <pr> <launch>
|
|
70
77
|
// `ledger.mjs review <pr> review=<launch>=failed`, `<launch>` as the
|
|
71
78
|
// PR's row spells it after `review=` (`member:<runner>` or
|
|
72
79
|
// `wf:<runId>`), skipped when the rows already carry it; the summary
|
|
73
80
|
// names the runner the PR's next launch takes, as `review` reports it.
|
|
81
|
+
// ci <pr>
|
|
82
|
+
// `ci-state.mjs --pr <pr>`, never `--quiet`, then `ledger.mjs token <pr>
|
|
83
|
+
// ci=<run-id>:<attempt>:<conclusion>` on the PR's row, `<conclusion>`
|
|
84
|
+
// `-` when ci-state reports it as `""` or null (an in-progress run),
|
|
85
|
+
// skipped when the PR's rows already carry that token. The payload is
|
|
86
|
+
// the verdict, never the exit code: not-green exits 1 and is an
|
|
87
|
+
// ordinary state. A payload with no `verdict`, or `verdict:
|
|
88
|
+
// rate-limited`, prints `WATCHER DEGRADED: no usable ci-state reading
|
|
89
|
+
// for #<pr> — silence is NOT green` and writes nothing; a payload that
|
|
90
|
+
// binds no run (`no-ci`) writes nothing either.
|
|
91
|
+
// `token` appends the key to the PR's row and keeps every token already on it, where `row` would replace the whole line.
|
|
92
|
+
// That key cannot be reconstructed once the head is superseded, so a controller holding only the colour cannot later tell an edge it has already spent from one that never fired.
|
|
93
|
+
// label <pr>
|
|
94
|
+
// No write: a `ready-to-merge` label was seen, and the tick is the whole
|
|
95
|
+
// of the event.
|
|
96
|
+
// conflict <pr>
|
|
97
|
+
// The tick's `CONFLICT` line for the PR, recorded: `ledger.mjs token
|
|
98
|
+
// <pr> conflict-hold:#<pr>`, no note beside it (`token` refuses any
|
|
99
|
+
// `conflict-hold` word that is not `conflict-hold:#<number>`, spelled
|
|
100
|
+
// with `:` or `-`). `token` appends the hold and keeps every token the row already carries, where `row` would replace the whole line.
|
|
101
|
+
// Refused, nothing written, exit 2, when the PR's row already carries a
|
|
102
|
+
// hold no fix-applier has answered (the tick's own reading of the row),
|
|
103
|
+
// or both spellings. A row whose one hold a fix-applier answered takes
|
|
104
|
+
// the other spelling, `conflict-hold-#<pr>`: `token` writes no word the
|
|
105
|
+
// row already carries, and the tick reads a fresh hold after an answer
|
|
106
|
+
// as unresolved.
|
|
107
|
+
// heartbeat
|
|
108
|
+
// No write: the tick runs with `--fold-unchanged`, which prints one line
|
|
109
|
+
// instead of the rows when the tick asks for nothing and says what the
|
|
110
|
+
// last one said. The hold itself stays `fleet-heartbeat.mjs`, whose
|
|
111
|
+
// interval-elapsed line names this command.
|
|
112
|
+
// drain --reason "<reason>"
|
|
113
|
+
// `closeout.mjs begin --reason "<reason>"`, its output printed as it
|
|
114
|
+
// stands, then the tick.
|
|
115
|
+
// `closeout.mjs begin` drains (`ledger.mjs drain`), then releases every claim that never became a PR and settles each `impl-<N>=released`. Nothing else in the loop fires for those claims.
|
|
116
|
+
// `begin` answers a second drain with the standing marker, so a second
|
|
117
|
+
// run releases what is left and writes nothing else. Its exit 4 (a
|
|
118
|
+
// `NEED hand-release #<N> <blocker>` line) is this script's exit 4; its
|
|
119
|
+
// exit 2 or 3 is passed through. The rest of the end of a run,
|
|
120
|
+
// `closeout.mjs finish` last, is the controller's.
|
|
74
121
|
//
|
|
75
122
|
// A write this script cannot make, and does not refuse, is printed as a
|
|
76
123
|
// `NEED <what> …` line, at the left margin, for the controller to make by
|
|
77
124
|
// hand.
|
|
78
125
|
//
|
|
79
126
|
// Exit: 0 every write made and the tick exited 0. 2 a usage error, refused
|
|
80
|
-
// before anything is written or ticked: an unknown kind or flag, a
|
|
127
|
+
// before anything is written or ticked: an unknown kind or flag, a `--reason`
|
|
128
|
+
// that is empty or beside any kind but `drain`, a member of
|
|
81
129
|
// the wrong family, a review path outside the PR's partition or a file that
|
|
82
130
|
// is no review result, a ledger or phase-0 receipt that cannot be read. A
|
|
83
131
|
// ledger write's own refusal — `settle`'s 3 (the report's claim and the world
|
|
84
132
|
// disagree) or 2, `token`'s or `review`'s 2 — passes its exit and message
|
|
85
|
-
// through,
|
|
86
|
-
//
|
|
133
|
+
// through, as does `closeout.mjs begin`'s 2 or 3 and the refusal of a second
|
|
134
|
+
// conflict hold (2), and the tick still runs so the controller sees the rows.
|
|
135
|
+
// Else the tick's own exit when it is not 0. Else 4 when a NEED line was
|
|
136
|
+
// printed, `begin`'s own exit 4 included.
|
|
87
137
|
//
|
|
88
138
|
// Zero deps: node builtins and sibling scripts only.
|
|
89
139
|
|
|
@@ -96,7 +146,7 @@ import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
|
96
146
|
import { gitEnv } from "./git-env.mjs";
|
|
97
147
|
import { isCLI } from "./is-cli.mjs";
|
|
98
148
|
import { BRIEFS, REVIEW, REVIEWED, memberTokens, nextReviewerName, parseDispatchedEntry, parseMember, parseToken, rowNums } from "./ledger-grammar.mjs";
|
|
99
|
-
import { dispositionsToken } from "./fleet-tick.mjs";
|
|
149
|
+
import { dispositionsToken, foldLedger } from "./fleet-tick.mjs";
|
|
100
150
|
import { readRunReceipt, tickCaps } from "./phase0-receipt.mjs";
|
|
101
151
|
import { defaultScratch, readReportIn, reportsDir } from "./report-files.mjs";
|
|
102
152
|
|
|
@@ -113,12 +163,17 @@ const KINDS = {
|
|
|
113
163
|
"fix-report": { args: ["<member>"], family: "fix-pr" },
|
|
114
164
|
"finisher-report": { args: ["<member>"], family: "finisher-pr" },
|
|
115
165
|
"merge-bot-report": { args: ["<member>"], family: "merge-bot" },
|
|
116
|
-
"review-result": { args: ["<pr>", "<path>"] },
|
|
117
|
-
"review-failed": { args: ["<pr>", "<launch>"] },
|
|
166
|
+
"review-result": { args: ["<pr>", "<path>"], pr: true },
|
|
167
|
+
"review-failed": { args: ["<pr>", "<launch>"], pr: true },
|
|
168
|
+
ci: { args: ["<pr>"], pr: true },
|
|
169
|
+
label: { args: ["<pr>"], pr: true },
|
|
170
|
+
conflict: { args: ["<pr>"], pr: true },
|
|
171
|
+
heartbeat: { args: [] },
|
|
172
|
+
drain: { args: [], flag: "--reason \"<reason>\"" },
|
|
118
173
|
};
|
|
119
|
-
const FLAGS = { "in-flight": "value" };
|
|
174
|
+
const FLAGS = { "in-flight": "value", reason: "value" };
|
|
120
175
|
const USAGE = `usage: ${NAME}.mjs <kind> <args> [--in-flight <n>] — kinds: `
|
|
121
|
-
+ Object.entries(KINDS).map(([k, { args }]) =>
|
|
176
|
+
+ Object.entries(KINDS).map(([k, { args, flag }]) => [k, ...args, ...(flag ? [flag] : [])].join(" ")).join(", ");
|
|
122
177
|
|
|
123
178
|
// The label each `bailCause` demotes to, and the relabel template's kind.
|
|
124
179
|
const BAILS = {
|
|
@@ -501,6 +556,74 @@ function reviewFailed(ev, pr, launch) {
|
|
|
501
556
|
: next === null ? "no free runner name left" : `next free runner ${next}`);
|
|
502
557
|
}
|
|
503
558
|
|
|
559
|
+
// The line the CI watcher prints for a PR whose ci-state reading it cannot use.
|
|
560
|
+
const degraded = (pr) => `WATCHER DEGRADED: no usable ci-state reading for #${pr} — silence is NOT green`;
|
|
561
|
+
|
|
562
|
+
function ci(ev, pr) {
|
|
563
|
+
const r = node("ci-state.mjs", ["--pr", String(pr)]);
|
|
564
|
+
let payload = null;
|
|
565
|
+
try {
|
|
566
|
+
payload = JSON.parse(r.stdout);
|
|
567
|
+
} catch {
|
|
568
|
+
// No payload is a reading that cannot be used, judged below.
|
|
569
|
+
}
|
|
570
|
+
// The payload is the verdict, never the exit: not-green exits 1 and is an
|
|
571
|
+
// ordinary state.
|
|
572
|
+
const verdict = payload?.verdict;
|
|
573
|
+
if (typeof verdict !== "string" || verdict === "" || verdict === "rate-limited") {
|
|
574
|
+
ev.print(degraded(pr));
|
|
575
|
+
ev.note(`#${pr} ci: no usable ci-state reading, nothing written`);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const { runId, attempt, conclusion } = payload;
|
|
579
|
+
if (!isDigits(String(runId)) || !isDigits(String(attempt))) {
|
|
580
|
+
ev.note(`#${pr} ci: verdict ${verdict} binds no run, nothing to record`);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
// `""` is an in-progress run, which `//` would pass through as a conclusion.
|
|
584
|
+
const tok = `ci=${runId}:${attempt}:${conclusion === null || conclusion === undefined || conclusion === "" ? "-" : conclusion}`;
|
|
585
|
+
if (prWords(ev.ledger, pr).includes(tok)) {
|
|
586
|
+
ev.note(`#${pr} already ${tok}`);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const w = node("ledger.mjs", ["token", String(pr), tok]);
|
|
590
|
+
if (w.status === 0) ev.note(`#${pr} ${tok}`);
|
|
591
|
+
else ev.refuse(`token #${pr} ${tok}`, w);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// A second hold on a row that already answered one is the same word spelled
|
|
595
|
+
// the other way the tick reads, because `token` writes no word a row carries.
|
|
596
|
+
const HOLD_SPELLINGS = (pr) => [`conflict-hold:#${pr}`, `conflict-hold-#${pr}`];
|
|
597
|
+
|
|
598
|
+
function conflict(ev, pr) {
|
|
599
|
+
const open = foldLedger(ev.ledger, new Set(), { lenient: true }).byPr.get(pr)?.conflictOpen === true;
|
|
600
|
+
const words = prWords(ev.ledger, pr);
|
|
601
|
+
const tok = HOLD_SPELLINGS(pr).find((t) => !words.includes(t));
|
|
602
|
+
if (open || tok === undefined) {
|
|
603
|
+
const why = open ? "an unresolved conflict hold" : "every spelling of a conflict hold the tick reads";
|
|
604
|
+
writeAll(2, `${NAME}: conflict: PR #${pr}'s row already carries ${why} — nothing written\n`);
|
|
605
|
+
if (ev.refused === null) ev.refused = 2;
|
|
606
|
+
ev.note(`#${pr} conflict hold refused (row already holds)`);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const w = node("ledger.mjs", ["token", String(pr), tok]);
|
|
610
|
+
if (w.status === 0) ev.note(`#${pr} ${tok}`);
|
|
611
|
+
else ev.refuse(`token #${pr} ${tok}`, w);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function drain(ev, reason) {
|
|
615
|
+
const r = node("closeout.mjs", ["begin", "--reason", reason]);
|
|
616
|
+
ev.print(r.stdout);
|
|
617
|
+
if (r.status === 0) {
|
|
618
|
+
ev.note("drain begun");
|
|
619
|
+
} else if (r.status === 4) {
|
|
620
|
+
ev.needs += 1;
|
|
621
|
+
ev.note("drain begun, a claim to hand-release");
|
|
622
|
+
} else {
|
|
623
|
+
ev.refuse("closeout begin", r);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
504
627
|
// ── main ────────────────────────────────────────────────────────────────────
|
|
505
628
|
|
|
506
629
|
function boundArg(F, name) {
|
|
@@ -530,13 +653,19 @@ function main() {
|
|
|
530
653
|
const [kind, ...args] = positionals();
|
|
531
654
|
if (!Object.hasOwn(KINDS, kind ?? "")) die(kind === undefined ? USAGE : `unknown kind '${kind}' — ${USAGE}`);
|
|
532
655
|
const spec = KINDS[kind];
|
|
533
|
-
if (args.length !== spec.args.length) die(`${kind} takes ${spec.args.join(" ")} — ${USAGE}`);
|
|
656
|
+
if (args.length !== spec.args.length) die(`${kind} takes ${spec.args.join(" ") || "no arguments"} — ${USAGE}`);
|
|
534
657
|
const inFlight = boundArg(F, "in-flight");
|
|
658
|
+
const reason = F.arg("reason");
|
|
659
|
+
if (kind === "drain") {
|
|
660
|
+
if (reason === null) die("drain takes --reason \"<reason>\"");
|
|
661
|
+
} else if (reason !== null) {
|
|
662
|
+
die(`--reason belongs to drain, not ${kind}`);
|
|
663
|
+
}
|
|
535
664
|
let pr = null;
|
|
536
665
|
if (spec.family !== undefined) {
|
|
537
666
|
const m = parseMember(args[0]);
|
|
538
667
|
if (m === null || m.family !== spec.family) die(`${kind} takes a member of the ${spec.family} family, not '${args[0]}'`);
|
|
539
|
-
} else {
|
|
668
|
+
} else if (spec.pr) {
|
|
540
669
|
const digits = args[0].replace(/^#/, "");
|
|
541
670
|
if (!isDigits(digits) || Number(digits) < 1) die(`${kind}: '${args[0]}' is not a PR number`);
|
|
542
671
|
pr = Number(digits);
|
|
@@ -555,7 +684,7 @@ function main() {
|
|
|
555
684
|
}
|
|
556
685
|
const caps = tickCaps(fleetDir);
|
|
557
686
|
if (caps.error) die(`${caps.error} — nothing written`);
|
|
558
|
-
const tickArgs = ["--apply", ...(inFlight === null ? caps.args : ["--in-flight", inFlight])];
|
|
687
|
+
const tickArgs = ["--apply", ...(inFlight === null ? caps.args : ["--in-flight", inFlight]), ...(kind === "heartbeat" ? ["--fold-unchanged"] : [])];
|
|
559
688
|
|
|
560
689
|
const ev = new Event({ fleetDir, scratch, ledger: readLedger() });
|
|
561
690
|
if (kind === "impl-report") implReport(ev, args[0]);
|
|
@@ -563,7 +692,10 @@ function main() {
|
|
|
563
692
|
else if (kind === "finisher-report") finisherReport(ev, args[0]);
|
|
564
693
|
else if (kind === "merge-bot-report") mergeBotReport(ev, args[0]);
|
|
565
694
|
else if (kind === "review-result") reviewResult(ev, pr, args[1]);
|
|
566
|
-
else reviewFailed(ev, pr, args[1]);
|
|
695
|
+
else if (kind === "review-failed") reviewFailed(ev, pr, args[1]);
|
|
696
|
+
else if (kind === "ci") ci(ev, pr);
|
|
697
|
+
else if (kind === "conflict") conflict(ev, pr);
|
|
698
|
+
else if (kind === "drain") drain(ev, reason);
|
|
567
699
|
|
|
568
700
|
writeAll(1, `${[...ev.lines, `event: ${kind}: ${ev.summary.join("; ") || "nothing to record"}`].join("\n")}\n`);
|
|
569
701
|
const tick = spawnSync(process.execPath, [join(SCRIPTS, "fleet-tick.mjs"), ...tickArgs], { stdio: ["ignore", "inherit", "inherit"], env: gitEnv() });
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
// script never reads or reports fleet state: counts captured before a
|
|
33
33
|
// twenty-minute hold and printed after it are a stale verdict, and a stale
|
|
34
34
|
// verdict is how a reconcile prints an ACTION nobody can take. The controller
|
|
35
|
-
// runs fleet-
|
|
35
|
+
// runs `fleet-event.mjs heartbeat` itself at wake time, which ticks and so reads the run as it stands then.
|
|
36
36
|
// It also makes a late hold harmless: if a member reports at minute two and
|
|
37
37
|
// the controller acts, the hold that fires afterwards is a free extra tick.
|
|
38
38
|
//
|
|
@@ -277,7 +277,7 @@ function main() {
|
|
|
277
277
|
// on every hold until the file is repaired.
|
|
278
278
|
const skippedNote = now.degraded ? " — the heartbeat file is degraded and was left as it is, so interval progress is not kept and every hold fires" : "";
|
|
279
279
|
console.log(done
|
|
280
|
-
? `heartbeat: held ${held}s, ${target}s interval elapsed (quiet=${state.quiet}) → run fleet-
|
|
280
|
+
? `heartbeat: held ${held}s, ${target}s interval elapsed (quiet=${state.quiet}) → run fleet-event.mjs heartbeat${skippedNote}`
|
|
281
281
|
: `heartbeat: held ${held}s, ${target - elapsed}s of ${target}s remain (quiet=${state.quiet}) → re-issue this command now, do not end your turn`);
|
|
282
282
|
}
|
|
283
283
|
|
package/scripts/fleet-tick.mjs
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
//
|
|
10
10
|
// So compute the deficit instead of remembering it. Every wake ends in one
|
|
11
11
|
// invocation (record, tick, act, beat), and each prints
|
|
12
|
-
// actual/target and a named ACTION per role — `PULL #<n>
|
|
12
|
+
// actual/target and a named ACTION per role — `PULL #<n> — pull.mjs next --head
|
|
13
|
+
// <n>`, one row per head, `DISPATCH
|
|
13
14
|
// fix-pr PR#<pr>`, `DISPATCH review PR#<pr>`, `DISPATCH merge-bot`, `HOLD (…)`,
|
|
14
15
|
// `REFRESHED shortlist: …` — with run-team's guards applied in code rather than
|
|
15
16
|
// recalled from its table. You cannot forget what a script prints at you. A
|
|
@@ -101,6 +102,18 @@
|
|
|
101
102
|
// CHECK-LIVENESS: the tick settles nothing. A review runner has no
|
|
102
103
|
// report schema and files none, so no `review=` token is looked
|
|
103
104
|
// up; a member with no schema is never checked against one.
|
|
105
|
+
// pulls `<scratch>/impl-<N>/pull.json`, pull.mjs's record of a Pull, for
|
|
106
|
+
// every head on the shortlist, `<scratch>` as for the report
|
|
107
|
+
// files. A question standing prints `PULL #<N> (Q<n> pending —
|
|
108
|
+
// pull.mjs answer <N> <qid> …)` in place of the fresh row, with
|
|
109
|
+
// ` (stale)` once the file is older than `--pull-stale-minutes`; a
|
|
110
|
+
// Pull that dispatched with the head still holding no `impl-` row
|
|
111
|
+
// prints `(dispatched, row missing — ledger.mjs row …)`. A Pull
|
|
112
|
+
// that ended in this run's session (the ticket left, or its claim
|
|
113
|
+
// was released) names no row: `pull.mjs next` skips it, `next
|
|
114
|
+
// --head` would start the ticket over, so the next head fills the
|
|
115
|
+
// slot. A record from another phase-0 session, or one unreadable
|
|
116
|
+
// or absent, is the fresh row: `pull.mjs next` starts or resumes it.
|
|
104
117
|
// session The listing of the session directory omp writes one
|
|
105
118
|
// `<member>.jsonl` transcript into per dispatched member: this
|
|
106
119
|
// run's phase-0 receipt's `session`, else `--session`; with
|
|
@@ -131,7 +144,7 @@ export function reconcile(s) {
|
|
|
131
144
|
// dispatch — so they stand outside the dispatch hold: the fix-applier a
|
|
132
145
|
// conflict hold leads to obeys the hold through its own role's row.
|
|
133
146
|
return [
|
|
134
|
-
...dispatchHold(s, [implementers(s), ...rev.rows]),
|
|
147
|
+
...dispatchHold(s, [...implementers(s), ...rev.rows]),
|
|
135
148
|
...rev.conflictRows,
|
|
136
149
|
...dispatchHold(s, [mergeBot(s)]),
|
|
137
150
|
...shortlistRows(s),
|
|
@@ -221,12 +234,59 @@ function specsDropped(dropped) {
|
|
|
221
234
|
return `specs-dropped=${[...by].map(([reason, ns]) => `${ns.join(" ")} (${reason})`).join(", ")}`;
|
|
222
235
|
}
|
|
223
236
|
|
|
237
|
+
// The question numbers SKILL.md's phase 1 gives pull.mjs's questions. The row
|
|
238
|
+
// names the number and the command names the qid, which is what `pull.mjs
|
|
239
|
+
// answer` takes; a qid with no number here is named by itself.
|
|
240
|
+
const QUESTION_NUMBERS = { staleness: "Q1", close: "Q1b", decided: "Q2", collision: "Q3" };
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Where a head's Pull stands, off its `pull.json` record as parsed, for the
|
|
244
|
+
* PULL row: `{kind: "pending", qid, stale}`, `{kind: "dispatched", text}` with
|
|
245
|
+
* the text the Pull's own `ledger.mjs row` wrote (null when it recorded none),
|
|
246
|
+
* `{kind: "ended"}` for a Pull that left or was released, or null for the
|
|
247
|
+
* fresh row. `since` is the file's mtime and `session` this run's phase-0
|
|
248
|
+
* session, null when the receipt names none.
|
|
249
|
+
*/
|
|
250
|
+
export function pullOf(record, { session, since, now, staleMinutes }) {
|
|
251
|
+
if (record === null || typeof record !== "object" || Array.isArray(record)) return null;
|
|
252
|
+
// pull.mjs ends a record from another phase-0 session whatever it says, and
|
|
253
|
+
// starts the ticket afresh.
|
|
254
|
+
if (session !== null && record.session !== session) return null;
|
|
255
|
+
// pull.mjs's `next` skips a Pull that ended in this run, and `next --head`
|
|
256
|
+
// would start the ticket over: the head is no one for a PULL row to name.
|
|
257
|
+
if (record.status === "left" || record.status === "released") return { kind: "ended" };
|
|
258
|
+
if (record.status === "running" && typeof record.pending?.qid === "string") {
|
|
259
|
+
return { kind: "pending", qid: record.pending.qid, stale: now - since > staleMinutes * 60_000 };
|
|
260
|
+
}
|
|
261
|
+
if (record.status === "dispatched") {
|
|
262
|
+
const row = Array.isArray(record.commands)
|
|
263
|
+
? record.commands.findLast((c) => c?.step === "row" && c.exit === 0 && Array.isArray(c.cmd))
|
|
264
|
+
: undefined;
|
|
265
|
+
return { kind: "dispatched", text: typeof row?.cmd[3] === "string" ? row.cmd[3] : null };
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// A head's PULL action. A question standing is a Pull in progress: the fresh
|
|
271
|
+
// row there would ask it twice. A dispatched Pull whose head still holds no
|
|
272
|
+
// `impl-` row should not occur, and must not read as a fresh Pull either.
|
|
273
|
+
function pullAction(n, p) {
|
|
274
|
+
if (p?.kind === "pending") {
|
|
275
|
+
return `PULL #${n} (${QUESTION_NUMBERS[p.qid] ?? p.qid} pending — pull.mjs answer ${n} ${p.qid} …)${p.stale ? " (stale)" : ""}`;
|
|
276
|
+
}
|
|
277
|
+
if (p?.kind === "dispatched") return `PULL #${n} (dispatched, row missing — ledger.mjs row ${n} ${p.text === null ? "…" : JSON.stringify(p.text)})`;
|
|
278
|
+
return `PULL #${n} — pull.mjs next --head ${n}`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// The implementer rows: one per head a free slot Pulls, else the one row
|
|
282
|
+
// saying why none is pulled.
|
|
224
283
|
function implementers(s) {
|
|
225
284
|
const dropped = specsDropped(s.dropped);
|
|
226
|
-
const
|
|
285
|
+
const one = mkRow("implementers", s.inFlight, s.bound,
|
|
227
286
|
`implementers=${s.inFlightImpl} prs=${s.inFlightPrs} unclaimed=${s.heads.length} supply=${s.supply ?? "?"}`
|
|
228
287
|
+ (s.shortlistStatus === "ok" ? "" : ` shortlist=${s.shortlistStatus}`)
|
|
229
288
|
+ (dropped ? ` ${dropped}` : ""));
|
|
289
|
+
const row = (...a) => [one(...a)];
|
|
230
290
|
|
|
231
291
|
// Drain stops supply and nothing else. Read from the file, so
|
|
232
292
|
// a replacement controller that never saw the drain is held by it too.
|
|
@@ -263,9 +323,12 @@ function implementers(s) {
|
|
|
263
323
|
return s.owedCounted.length ? row(hold, { acts: true, extra: replaceStep(s.owedCounted, s.implNames) }) : row(hold);
|
|
264
324
|
}
|
|
265
325
|
|
|
266
|
-
|
|
326
|
+
// A head whose Pull ended in this run takes no slot: the next head does.
|
|
327
|
+
const pullable = s.heads.filter((n) => s.pulls?.get(n)?.kind !== "ended");
|
|
328
|
+
if (pullable.length) return pullable.slice(0, s.bound - s.inFlight).map((n) => one(pullAction(n, s.pulls?.get(n)), { acts: true }));
|
|
267
329
|
|
|
268
|
-
// Nothing
|
|
330
|
+
// Nothing to Pull even after a refresh: no unclaimed head, or only heads
|
|
331
|
+
// whose Pull ended in this run, which `pull.mjs next` skips. `SUGGEST /triage` asks a
|
|
269
332
|
// MAINTAINER to tick tickets, and on the unattended night the heartbeat
|
|
270
333
|
// exists for there is nobody to ask — so it prints (the fold shows it once)
|
|
271
334
|
// but is not actionable, or it would pin the interval at the base all night.
|
|
@@ -1378,6 +1441,9 @@ const OPTIONS = {
|
|
|
1378
1441
|
// Minutes a live member token may go with no transcript in the session
|
|
1379
1442
|
// directory before NO-TRANSCRIPT names it.
|
|
1380
1443
|
"no-transcript-after": { type: "string", default: "5" },
|
|
1444
|
+
// Minutes a Pull's question may stand, its `pull.json` unwritten, before the
|
|
1445
|
+
// PULL row naming it says `(stale)`.
|
|
1446
|
+
"pull-stale-minutes": { type: "string", default: "120" },
|
|
1381
1447
|
// Minutes a live token of each family may run before CHECK-LIVENESS names it.
|
|
1382
1448
|
...Object.fromEntries(Object.entries(LIVENESS_FLAGS).map(([family, flag]) => [flag, { type: "string", default: String(LIVENESS_DEFAULTS[family]) }])),
|
|
1383
1449
|
};
|
|
@@ -1408,7 +1474,7 @@ function options() {
|
|
|
1408
1474
|
return {
|
|
1409
1475
|
bound: positive("in-flight"),
|
|
1410
1476
|
fold: values["fold-unchanged"], apply: values.apply, state: values.state || statePath(NAME), scratch: values.scratch,
|
|
1411
|
-
session: values.session || null, noTranscriptAfter: positive("no-transcript-after"),
|
|
1477
|
+
session: values.session || null, noTranscriptAfter: positive("no-transcript-after"), pullStaleMinutes: positive("pull-stale-minutes"),
|
|
1412
1478
|
liveness: Object.fromEntries(Object.entries(LIVENESS_FLAGS).map(([family, flag]) => [family, positive(flag)])),
|
|
1413
1479
|
};
|
|
1414
1480
|
}
|
|
@@ -1850,8 +1916,28 @@ function listTranscripts(session, { missingIsEmpty }) {
|
|
|
1850
1916
|
}
|
|
1851
1917
|
}
|
|
1852
1918
|
|
|
1919
|
+
// Where each head's Pull stands, as pullOf() reads its record, for the heads
|
|
1920
|
+
// with one. A record that is not there, or cannot be read or parsed, is the
|
|
1921
|
+
// fresh row: `pull.mjs next` names one it cannot use, in its own words.
|
|
1922
|
+
function readPulls(scratch, heads, { session, now, staleMinutes }) {
|
|
1923
|
+
const out = new Map();
|
|
1924
|
+
for (const n of heads) {
|
|
1925
|
+
const path = join(scratch, `impl-${n}`, "pull.json");
|
|
1926
|
+
let since, record;
|
|
1927
|
+
try {
|
|
1928
|
+
since = statSync(path).mtimeMs;
|
|
1929
|
+
record = JSON.parse(readFileSync(path, "utf8"));
|
|
1930
|
+
} catch {
|
|
1931
|
+
continue;
|
|
1932
|
+
}
|
|
1933
|
+
const p = pullOf(record, { session, since, now, staleMinutes });
|
|
1934
|
+
if (p !== null) out.set(n, p);
|
|
1935
|
+
}
|
|
1936
|
+
return out;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1853
1939
|
function main() {
|
|
1854
|
-
const { fold, apply, state: path, liveness, scratch: scratchFlag, session: sessionFlag, noTranscriptAfter, ...caps } = options();
|
|
1940
|
+
const { fold, apply, state: path, liveness, scratch: scratchFlag, session: sessionFlag, noTranscriptAfter, pullStaleMinutes, ...caps } = options();
|
|
1855
1941
|
const listPath = shortlistPath();
|
|
1856
1942
|
const current = readShortlist(listPath);
|
|
1857
1943
|
// Beside the shortlist, off the same git probe rather than a second one.
|
|
@@ -1972,15 +2058,23 @@ function main() {
|
|
|
1972
2058
|
}
|
|
1973
2059
|
}
|
|
1974
2060
|
|
|
2061
|
+
// The scratch root of the report files and the Pull records alike.
|
|
2062
|
+
const scratch = reportsScratch(receipt, scratchFlag);
|
|
2063
|
+
if (scratch === null) console.error(`${NAME}: report files and Pull records not checked — no scratch in the phase-0 receipt and no --scratch`);
|
|
2064
|
+
// Each head's Pull record read, not only the heads a free slot names: a head
|
|
2065
|
+
// whose Pull ended gives its slot to the next, so the heads past the slots
|
|
2066
|
+
// can fill one. The session it is judged against is the receipt's, as
|
|
2067
|
+
// pull.mjs judges it.
|
|
2068
|
+
const runSession = receipt.read.state === "ok" && receipt.read.receipt.session !== "" ? receipt.read.receipt.session : null;
|
|
2069
|
+
const pulls = scratch === null ? new Map()
|
|
2070
|
+
: readPulls(scratch.root, heads, { session: runSession, now: Date.now(), staleMinutes: pullStaleMinutes });
|
|
1975
2071
|
const rows = reconcile({
|
|
1976
|
-
...caps, ...run, heads, supply, dropped, shortlistStatus: current.status, refresh: fresh, mainCheckout, phase0, router,
|
|
2072
|
+
...caps, ...run, heads, supply, dropped, shortlistStatus: current.status, refresh: fresh, mainCheckout, phase0, router, pulls,
|
|
1977
2073
|
});
|
|
1978
2074
|
const said = describe(mainCheckout, run.live);
|
|
1979
2075
|
// The report files of the live members, read before the state file for the
|
|
1980
2076
|
// reason given below. A member's report on disk is the outcome its message
|
|
1981
2077
|
// was to carry, whether or not that message arrived.
|
|
1982
|
-
const scratch = reportsScratch(receipt, scratchFlag);
|
|
1983
|
-
if (scratch === null) console.error(`${NAME}: report files not checked — no scratch in the phase-0 receipt and no --scratch`);
|
|
1984
2078
|
const reports = scratch === null ? new Map() : readReports(scratch.root, run.reporters);
|
|
1985
2079
|
// Re-read rather than reusing priorState: this must be the freshest
|
|
1986
2080
|
// snapshot, or this tick reverts whatever the heartbeat wrote while the
|