@feigi/fleet-ctl 3.120.0 → 3.122.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/compute-board.mjs +2 -1
- package/scripts/fleet-event.mjs +39 -19
- package/scripts/ledger-grammar.mjs +18 -9
- package/scripts/pull-attribution.mjs +7 -4
- package/scripts/pull.mjs +46 -31
- package/scripts/slice-fill.mjs +114 -0
- package/scripts/ticket-router.mjs +59 -10
- package/skills/run-team/references/pull.md +1 -1
package/package.json
CHANGED
|
@@ -371,11 +371,12 @@ function reasonWords(r, table) {
|
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
// The Stratum and the numbers that set it.
|
|
374
|
+
// The Stratum and the numbers that set it: a Slice's parent sets it, ahead of the brief's numbers.
|
|
375
375
|
function stratumWords(r) {
|
|
376
376
|
if (r.sized !== null) return `${r.stratum}: sized ${r.sized}`;
|
|
377
377
|
if (r.brief === null) return `${r.stratum}: no brief read`;
|
|
378
378
|
if (r.reason === "no-sizing") return `${r.stratum}: no sizing`;
|
|
379
|
+
if (r.parent !== null) return `${r.stratum}: Slice of #${r.parent}`;
|
|
379
380
|
const past = (n, at) => `${n > at ? "past" : "not past"} ${grouped(at)}`;
|
|
380
381
|
return `${r.stratum}: ${grouped(r.brief)} chars (${past(r.brief, HEAVY_BRIEF_CHARS)}), ${r.criteria} criteria (${past(r.criteria, HEAVY_CRITERIA)})`;
|
|
381
382
|
}
|
package/scripts/fleet-event.mjs
CHANGED
|
@@ -168,6 +168,10 @@
|
|
|
168
168
|
// `NEED <what> …` line, at the left margin, for the controller to make by
|
|
169
169
|
// hand.
|
|
170
170
|
//
|
|
171
|
+
// The labels this script compares and writes are the Label map's strings
|
|
172
|
+
// (label-map.mjs), read once at the command's entry; the label names in this
|
|
173
|
+
// header are Label roles, and the map's string stands where it says one.
|
|
174
|
+
//
|
|
171
175
|
// Exit: 0 every write made and the tick exited 0. 2 a usage error, refused
|
|
172
176
|
// before anything is written or ticked: an unknown kind or flag, a `--reason`
|
|
173
177
|
// that is empty or beside any kind but `drain` and `undrain`, a `--session`
|
|
@@ -175,7 +179,8 @@
|
|
|
175
179
|
// a name that is no ledger member, no session directory, a session directory
|
|
176
180
|
// that cannot be listed, a heartbeat file that cannot be used), a member of
|
|
177
181
|
// the wrong family, a review path outside the PR's partition or a file that
|
|
178
|
-
// is no review result, a ledger or phase-0 receipt that cannot be read
|
|
182
|
+
// is no review result, a ledger or phase-0 receipt that cannot be read, no
|
|
183
|
+
// valid Label map (the message names `label-map.mjs ensure`). A
|
|
179
184
|
// ledger write's own refusal — `settle`'s 3 (the report's claim and the world
|
|
180
185
|
// disagree) or 2, `token`'s or `review`'s 2 — passes its exit and message
|
|
181
186
|
// through, as do `closeout.mjs begin`'s and `reopen`'s 2 or 3 and the
|
|
@@ -194,6 +199,7 @@ import { makeDie, defineFlags, isDigits, writeAll } from "./arg.mjs";
|
|
|
194
199
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
195
200
|
import { gitEnv } from "./git-env.mjs";
|
|
196
201
|
import { isCLI } from "./is-cli.mjs";
|
|
202
|
+
import { LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
|
|
197
203
|
import { BRIEFS, REVIEW, REVIEWED, REVIEWER, dispositionsToken, memberTokens, nextReviewerName, parseDispatchedEntry, parseMember, parseToken, readRetired, rowNums } from "./ledger-grammar.mjs";
|
|
198
204
|
import { NO_TRANSCRIPT_AFTER_DEFAULT, PARKS, controllerState, foldLedger, parkedToken } from "./fleet-tick.mjs";
|
|
199
205
|
import { phase0Gate, readRunReceipt, tickCaps } from "./phase0-receipt.mjs";
|
|
@@ -206,7 +212,6 @@ const SCRIPTS = dirname(fileURLToPath(import.meta.url));
|
|
|
206
212
|
const MAX_BUFFER = 64 * 1024 * 1024;
|
|
207
213
|
const GH_TIMEOUT_MS = 60_000;
|
|
208
214
|
const CHILD_TIMEOUT_MS = 300_000;
|
|
209
|
-
const READY = "ready-to-merge";
|
|
210
215
|
|
|
211
216
|
const KINDS = {
|
|
212
217
|
"impl-report": { args: ["<member>"], family: "impl" },
|
|
@@ -227,14 +232,16 @@ const FLAGS = { "in-flight": "value", reason: "value", session: "value" };
|
|
|
227
232
|
const USAGE = `usage: ${NAME}.mjs <kind> <args> [--in-flight <n>] — kinds: `
|
|
228
233
|
+ Object.entries(KINDS).map(([k, { args, flag }]) => [k, ...args, ...(flag ? [flag] : [])].join(" ")).join(", ");
|
|
229
234
|
|
|
230
|
-
// The
|
|
231
|
-
//
|
|
232
|
-
//
|
|
235
|
+
// The Label role each `bailCause` demotes to, and the relabel template's kind;
|
|
236
|
+
// the tracker's string for the role is the map's, resolved where the label is
|
|
237
|
+
// written. `fixed` takes no role: it closes the ticket once `verify-sha.sh`
|
|
238
|
+
// finds the commit on origin/main, and demotes to `needs-triage` when it does
|
|
239
|
+
// not.
|
|
233
240
|
export const BAILS = {
|
|
234
|
-
undecided: {
|
|
235
|
-
fork: {
|
|
236
|
-
hands: {
|
|
237
|
-
covered: {
|
|
241
|
+
undecided: { role: "needs-triage", kind: "needs-triage", flag: "line" },
|
|
242
|
+
fork: { role: "ready-for-human", kind: "fork", flag: "options" },
|
|
243
|
+
hands: { role: "ready-for-human", kind: "hands" },
|
|
244
|
+
covered: { role: "ready-for-human", kind: "covered", flag: "detail" },
|
|
238
245
|
fixed: { kind: "fixed", flag: "detail" },
|
|
239
246
|
};
|
|
240
247
|
// The commit a `fixed` bail's detail opens with.
|
|
@@ -415,7 +422,8 @@ function relabelArgs(cause, detail) {
|
|
|
415
422
|
}
|
|
416
423
|
|
|
417
424
|
// The comment `dispatch-prompt.mjs render relabel` renders for a bail, or null
|
|
418
|
-
// when there is none (the NEED, named `what`, is printed here).
|
|
425
|
+
// when there is none (the NEED, named `what`, is printed here). The template
|
|
426
|
+
// names the role `ready-for-agent`; the comment filed names the map's string.
|
|
419
427
|
function rendered(ev, ticket, cause, detail, what) {
|
|
420
428
|
const relabel = relabelArgs(cause, detail);
|
|
421
429
|
if (relabel.why !== undefined) {
|
|
@@ -427,18 +435,23 @@ function rendered(ev, ticket, cause, detail, what) {
|
|
|
427
435
|
ev.need(`${what} #${ticket} — dispatch-prompt.mjs render relabel refused: ${said(r)}`);
|
|
428
436
|
return null;
|
|
429
437
|
}
|
|
430
|
-
return r.stdout;
|
|
438
|
+
return r.stdout.replaceAll("`ready-for-agent`", `\`${ev.labels["ready-for-agent"]}\``);
|
|
431
439
|
}
|
|
432
440
|
|
|
441
|
+
// The map's strings for the labels a pulled ticket carries, which a demotion
|
|
442
|
+
// or a close takes off.
|
|
443
|
+
const pulledLabels = (ev) => [ev.labels["ready-for-agent"], ev.labels["in-progress"]];
|
|
444
|
+
|
|
433
445
|
// Moves #ticket to `label`, then posts the comment `body()` returns, if any.
|
|
434
446
|
// False when the move could not be made, so nothing after it may run.
|
|
435
447
|
function demote(ev, ticket, label, cause, body) {
|
|
436
448
|
const seen = ev.comments("issue", ticket, `relabel #${ticket} ${label}`);
|
|
437
449
|
if (seen === null) return false;
|
|
438
|
-
|
|
450
|
+
const pulled = pulledLabels(ev);
|
|
451
|
+
if (seen.labels.includes(label) && !pulled.some((l) => seen.labels.includes(l))) {
|
|
439
452
|
ev.note(`#${ticket} already ${label}`);
|
|
440
453
|
} else {
|
|
441
|
-
const e = gh(["issue", "edit", String(ticket),
|
|
454
|
+
const e = gh(["issue", "edit", String(ticket), ...pulled.flatMap((l) => ["--remove-label", l]), "--add-label", label]);
|
|
442
455
|
if (e.status !== 0) {
|
|
443
456
|
ev.need(`relabel #${ticket} ${label} — gh issue edit failed: ${said(e)}`);
|
|
444
457
|
return false;
|
|
@@ -461,7 +474,7 @@ function fixed(ev, ticket, detail) {
|
|
|
461
474
|
}
|
|
462
475
|
const v = run("sh", [join(SCRIPTS, "verify-sha.sh"), "main", sha]);
|
|
463
476
|
if (v.status === 1) {
|
|
464
|
-
return demote(ev, ticket, "needs-triage", "fixed", () => `*Relabelled by the fleet controller.* Pulled for implementation and returned as already fixed by ${sha}: ${sha} not on origin/main.`);
|
|
477
|
+
return demote(ev, ticket, ev.labels["needs-triage"], "fixed", () => `*Relabelled by the fleet controller.* Pulled for implementation and returned as already fixed by ${sha}: ${sha} not on origin/main.`);
|
|
465
478
|
}
|
|
466
479
|
if (v.status !== 0) {
|
|
467
480
|
ev.need(`close #${ticket} — verify-sha.sh main ${sha} could not answer (${v.how}): ${said(v)}`);
|
|
@@ -482,7 +495,7 @@ function fixed(ev, ticket, detail) {
|
|
|
482
495
|
}
|
|
483
496
|
ev.note(`closed #${ticket}: fixed by ${sha}`);
|
|
484
497
|
}
|
|
485
|
-
const stale =
|
|
498
|
+
const stale = pulledLabels(ev).filter((l) => seen.labels.includes(l));
|
|
486
499
|
if (stale.length > 0) {
|
|
487
500
|
const e = gh(["issue", "edit", String(ticket), ...stale.flatMap((l) => ["--remove-label", l])]);
|
|
488
501
|
if (e.status !== 0) ev.need(`unlabel #${ticket} ${stale.join(" ")} — gh issue edit failed: ${said(e)}`);
|
|
@@ -501,7 +514,7 @@ function bailed(ev, member) {
|
|
|
501
514
|
const detail = read.report.bailDetail;
|
|
502
515
|
const moved = cause === "fixed"
|
|
503
516
|
? fixed(ev, ticket, detail)
|
|
504
|
-
: demote(ev, ticket, BAILS[cause].
|
|
517
|
+
: demote(ev, ticket, ev.labels[BAILS[cause].role], cause, () => rendered(ev, ticket, cause, detail, "relabel-comment"));
|
|
505
518
|
if (!moved) return;
|
|
506
519
|
const release = run("sh", [join(SCRIPTS, "release-ticket.sh"), String(ticket), `impl-${ticket}`, "implementer", "--apply"]);
|
|
507
520
|
if (release.status === 0) ev.note(`released #${ticket}`);
|
|
@@ -616,7 +629,7 @@ function finisherReport(ev, member) {
|
|
|
616
629
|
}
|
|
617
630
|
// The escalation is for a repair finisher that claims the label and reads
|
|
618
631
|
// back none; a halt says why in its own comment above.
|
|
619
|
-
if (self.retry === null || report?.outcome !== "labelled" || report.labelsReadBack.includes(
|
|
632
|
+
if (self.retry === null || report?.outcome !== "labelled" || report.labelsReadBack.includes(ev.labels["ready-to-merge"])) return;
|
|
620
633
|
const earlier = ledgerMembers(ev.ledger)
|
|
621
634
|
.filter((t) => t.family === "finisher-pr" && t.number === pr && (t.retry ?? "") < self.retry)
|
|
622
635
|
.sort((a, b) => (a.retry ?? "").localeCompare(b.retry ?? "")).at(-1)?.name;
|
|
@@ -625,7 +638,7 @@ function finisherReport(ev, member) {
|
|
|
625
638
|
const prior = ev.report(earlier);
|
|
626
639
|
before = prior.state === "ok" ? `${earlier} read back: ${listed(prior.report.labelsReadBack)}` : `${earlier}'s report ${prior.path} is ${prior.state}`;
|
|
627
640
|
}
|
|
628
|
-
const body = `**${member}, a repair finisher, read back no \`${
|
|
641
|
+
const body = `**${member}, a repair finisher, read back no \`${ev.labels["ready-to-merge"]}\` on PR #${pr}.**\n\n`
|
|
629
642
|
+ `- ${member} read back: ${listed(report.labelsReadBack)}\n- ${before}`;
|
|
630
643
|
const seen = ev.comments("pr", pr, `escalation-comment PR #${pr}`);
|
|
631
644
|
if (seen !== null) ev.comment("pr", pr, body, seen, "escalation comment");
|
|
@@ -977,7 +990,14 @@ function main() {
|
|
|
977
990
|
const caps = tickCaps(fleetDir);
|
|
978
991
|
if (caps.error) die(`${caps.error} — nothing written`);
|
|
979
992
|
const tickArgs = ["--apply", ...(inFlight === null ? caps.args : ["--in-flight", inFlight]), ...(kind === "heartbeat" ? ["--fold-unchanged"] : [])];
|
|
980
|
-
|
|
993
|
+
let labels;
|
|
994
|
+
try {
|
|
995
|
+
labels = readLabelMap();
|
|
996
|
+
} catch (e) {
|
|
997
|
+
if (!(e instanceof LabelMapUnreadable)) throw e;
|
|
998
|
+
die(`${e.message} — nothing written`);
|
|
999
|
+
}
|
|
1000
|
+
const ev = new Event({ fleetDir, scratch, labels, ledger: readLedger() });
|
|
981
1001
|
if (kind === "impl-report") implReport(ev, args[0]);
|
|
982
1002
|
else if (kind === "fix-report") fixReport(ev, args[0]);
|
|
983
1003
|
else if (kind === "finisher-report") finisherReport(ev, args[0]);
|
|
@@ -817,10 +817,12 @@ export function drawCell({ session, ticket, policyCell, cells }) {
|
|
|
817
817
|
// POLICY the policy row's Cell CELL the Pull's Cell
|
|
818
818
|
// DRAW k/K of the draw BY burn-in | every-5th
|
|
819
819
|
// STRATUM light | heavy | unknown BRIEF the brief's chars
|
|
820
|
-
// CRITERIA the criteria count
|
|
821
|
-
// OBJECTIVE cost | speed
|
|
822
|
-
// REASON the first thing that went wrong
|
|
823
|
-
// DRAW and BY are `-` together (no draw); so are BRIEF and CRITERIA (no issue
|
|
820
|
+
// CRITERIA the criteria count PARENT a Slice's parent issue
|
|
821
|
+
// SIZED arm B's sizing label OBJECTIVE cost | speed
|
|
822
|
+
// TRIPPED the guard's tripped Cells REASON the first thing that went wrong
|
|
823
|
+
// DRAW and BY are `-` together (no draw); so are BRIEF and CRITERIA (no issue
|
|
824
|
+
// read), and PARENT is `-` with them. A line written before PARENT was a part
|
|
825
|
+
// carries none, and reads as `PARENT=-`.
|
|
824
826
|
export const STRATA = Object.freeze(["light", "heavy", "unknown"]);
|
|
825
827
|
// What a run asks the router to minimise. phase0.mjs records the run's in its
|
|
826
828
|
// receipt, and every Routing names the one it routed by.
|
|
@@ -828,19 +830,24 @@ export const OBJECTIVES = Object.freeze(["cost", "speed"]);
|
|
|
828
830
|
const DRAWN_BY = Object.freeze(["burn-in", "every-5th"]);
|
|
829
831
|
export const ROUTING_REASONS = Object.freeze(["ok", "no-issue-json", "no-sizing", "guard-missing", "guard-tripped", "table-cell-tripped"]);
|
|
830
832
|
const SIZINGS = Object.freeze(["light", "heavy"]);
|
|
831
|
-
const ROUTING_KEYS = Object.freeze(["POLICY", "CELL", "DRAW", "BY", "STRATUM", "BRIEF", "CRITERIA", "SIZED", "OBJECTIVE", "TRIPPED", "REASON"]);
|
|
833
|
+
const ROUTING_KEYS = Object.freeze(["POLICY", "CELL", "DRAW", "BY", "STRATUM", "BRIEF", "CRITERIA", "PARENT", "SIZED", "OBJECTIVE", "TRIPPED", "REASON"]);
|
|
834
|
+
const PARENT_AT = ROUTING_KEYS.indexOf("PARENT");
|
|
835
|
+
const ISSUE = /^[1-9][0-9]*$/;
|
|
832
836
|
const COUNT = /^(?:0|[1-9][0-9]*)$/;
|
|
833
837
|
const DRAW = /^([1-9][0-9]*)\/([1-9][0-9]*)$/;
|
|
834
838
|
|
|
835
839
|
/**
|
|
836
840
|
* A Routing line read into its parts, or null when it is not one.
|
|
837
841
|
* @returns {null | { policy: string, cell: string, draw: null | { k: number, K: number }, by: null | string,
|
|
838
|
-
* stratum: string, brief: null | number, criteria: null | number,
|
|
839
|
-
* tripped: string[], reason: string }}
|
|
842
|
+
* stratum: string, brief: null | number, criteria: null | number, parent: null | number, sized: null | string,
|
|
843
|
+
* objective: string, tripped: string[], reason: string }}
|
|
840
844
|
*/
|
|
841
845
|
export function parseRouting(line) {
|
|
842
846
|
if (typeof line !== "string") return null;
|
|
843
847
|
const words = line.split(" ");
|
|
848
|
+
// A line written before PARENT was a part is one word short; one that holds
|
|
849
|
+
// PARENT= and lacks another key instead fails the per-key check.
|
|
850
|
+
if (words.length === ROUTING_KEYS.length - 1) words.splice(PARENT_AT, 0, "PARENT=-");
|
|
844
851
|
if (words.length !== ROUTING_KEYS.length) return null;
|
|
845
852
|
const v = {};
|
|
846
853
|
for (const [i, key] of ROUTING_KEYS.entries()) {
|
|
@@ -859,6 +866,7 @@ export function parseRouting(line) {
|
|
|
859
866
|
stratum: STRATA.includes(v.STRATUM) ? v.STRATUM : undefined,
|
|
860
867
|
brief: count(v.BRIEF),
|
|
861
868
|
criteria: count(v.CRITERIA),
|
|
869
|
+
parent: v.PARENT === "-" ? null : ISSUE.test(v.PARENT) && Number.isSafeInteger(Number(v.PARENT)) ? Number(v.PARENT) : undefined,
|
|
862
870
|
sized: opt(v.SIZED, (x) => SIZINGS.includes(x)),
|
|
863
871
|
objective: OBJECTIVES.includes(v.OBJECTIVE) ? v.OBJECTIVE : undefined,
|
|
864
872
|
tripped: tripped.every((c) => CELL.test(c)) ? tripped : undefined,
|
|
@@ -867,15 +875,16 @@ export function parseRouting(line) {
|
|
|
867
875
|
if (Object.values(r).includes(undefined)) return null;
|
|
868
876
|
if (r.draw !== null && r.draw.k > r.draw.K) return null;
|
|
869
877
|
if ((r.draw === null) !== (r.by === null) || (r.brief === null) !== (r.criteria === null)) return null;
|
|
878
|
+
if (r.parent !== null && r.brief === null) return null;
|
|
870
879
|
return r;
|
|
871
880
|
}
|
|
872
881
|
|
|
873
882
|
/** The Routing line for parsed parts; throws on parts no Routing line can carry, so nothing writes one parseRouting refuses. */
|
|
874
|
-
export function formatRouting({ policy, cell, draw, by, stratum, brief, criteria, sized, objective, tripped, reason }) {
|
|
883
|
+
export function formatRouting({ policy, cell, draw, by, stratum, brief, criteria, parent, sized, objective, tripped, reason }) {
|
|
875
884
|
const none = (x) => (x === null ? "-" : String(x));
|
|
876
885
|
const line = [
|
|
877
886
|
`POLICY=${policy}`, `CELL=${cell}`, `DRAW=${draw === null ? "-" : `${draw.k}/${draw.K}`}`, `BY=${none(by)}`,
|
|
878
|
-
`STRATUM=${stratum}`, `BRIEF=${none(brief)}`, `CRITERIA=${none(criteria)}`, `SIZED=${none(sized)}`,
|
|
887
|
+
`STRATUM=${stratum}`, `BRIEF=${none(brief)}`, `CRITERIA=${none(criteria)}`, `PARENT=${none(parent)}`, `SIZED=${none(sized)}`,
|
|
879
888
|
`OBJECTIVE=${objective}`, `TRIPPED=${tripped.length === 0 ? "-" : tripped.join(",")}`, `REASON=${reason}`,
|
|
880
889
|
].join(" ");
|
|
881
890
|
if (parseRouting(line) === null) throw new Error(`not a Routing: ${line}`);
|
|
@@ -89,14 +89,16 @@ import { parseMemberName } from "./member-record.mjs";
|
|
|
89
89
|
import { isImplementer } from "./member-outcomes.mjs";
|
|
90
90
|
import { DATE, isDerivedNote, rulingFor, rulingsByTicket } from "./tier-outcomes.mjs";
|
|
91
91
|
|
|
92
|
-
// The ticket-features row, one per Pull, in this order. `objective`
|
|
93
|
-
// and
|
|
92
|
+
// The ticket-features row, one per Pull, in this order. `objective` and
|
|
93
|
+
// `parent` came last and are optional on read: a file whose header lacks
|
|
94
|
+
// either reads it blank. `parent` is a Slice's parent issue number, blank for
|
|
95
|
+
// a ticket that is no Slice (ticket-router.mjs's sliceParent).
|
|
94
96
|
export const FEATURE_COLUMNS = Object.freeze([
|
|
95
97
|
"run_date", "session", "agent", "ticket", "policy_cell", "chosen_cell", "exploration_draw",
|
|
96
98
|
"sizing_src", "sizing_pre", "router_usd", "brief_chars", "criteria", "comments", "age_days",
|
|
97
|
-
"paths", "test_paths", "xrefs", "kind", "objective",
|
|
99
|
+
"paths", "test_paths", "xrefs", "kind", "objective", "parent",
|
|
98
100
|
]);
|
|
99
|
-
const OPTIONAL_COLUMNS = new Set(["objective"]);
|
|
101
|
+
export const OPTIONAL_COLUMNS = new Set(["objective", "parent"]);
|
|
100
102
|
|
|
101
103
|
// The quality floor's margin, in points of fail rate.
|
|
102
104
|
export const TRIP_POINTS = 15;
|
|
@@ -170,6 +172,7 @@ export function parseFeatures(text) {
|
|
|
170
172
|
const row = Object.fromEntries(header.map((c, j) => [c, cells[j]]));
|
|
171
173
|
for (const c of OPTIONAL_COLUMNS) row[c] ??= "";
|
|
172
174
|
if (!isDigits(row.ticket)) throw new Error(`ticket-features.tsv row ${i + 1}: ticket ${JSON.stringify(row.ticket)} is not a number`);
|
|
175
|
+
if (row.parent !== "" && !isDigits(row.parent)) throw new Error(`ticket-features.tsv row ${i + 1}: parent ${JSON.stringify(row.parent)} is not blank or a number`);
|
|
173
176
|
if (!CELL.test(row.chosen_cell)) throw new Error(`ticket-features.tsv row ${i + 1}: chosen_cell ${JSON.stringify(row.chosen_cell)} is not a cell`);
|
|
174
177
|
return row;
|
|
175
178
|
});
|
package/scripts/pull.mjs
CHANGED
|
@@ -24,17 +24,19 @@
|
|
|
24
24
|
// a Pull for a ticket whose ledger row is an exclusion naming no premise,
|
|
25
25
|
// or one whose premise still stands, is this exit as well.
|
|
26
26
|
// 2 could not look, named on stderr: a probe that did not answer, a write
|
|
27
|
-
// that failed, a router that refused
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
27
|
+
// that failed, a router that refused, or no valid Label map (the message
|
|
28
|
+
// names `label-map.mjs ensure`; the labels the Pull compares, writes and
|
|
29
|
+
// names in its comments are the map's strings, read once at the command's
|
|
30
|
+
// entry). `next --head <N>` runs a step that failed again; when the failure
|
|
31
|
+
// came from applying an answer, the question stands and the answer is given
|
|
32
|
+
// again. A router that refused has its claim released and the Pull is over,
|
|
33
|
+
// `next --head <N>` starting the ticket over; one whose claim could not be
|
|
34
|
+
// released leaves the Pull at the route step with the claim standing, and
|
|
35
|
+
// `next` routes again. An exclusion premise `gh` could not read is exit 2
|
|
36
|
+
// when no other entry is left, and always exit 2 when `next --head <N>`
|
|
37
|
+
// starts a Pull for the ticket that holds it, the exclusion standing and no
|
|
38
|
+
// record written. An unknown flag is exit 2 as well, as for every script
|
|
39
|
+
// that holds a command line of its own.
|
|
38
40
|
// 3 usage: any other mistake in the command line, or an answer the pending
|
|
39
41
|
// question does not take. Nothing is recorded.
|
|
40
42
|
// 10 a question is pending: its `QUESTION <qid>:` block, with the tokens it
|
|
@@ -136,6 +138,7 @@ import { isDigits, makeDie } from "./arg.mjs";
|
|
|
136
138
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
137
139
|
import { gitEnv } from "./git-env.mjs";
|
|
138
140
|
import { isCLI } from "./is-cli.mjs";
|
|
141
|
+
import { LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
|
|
139
142
|
import { EXCLUDED_REASON, POLICY_CELL, memberTokens, parseRouting, premisesOf, pullEnded, tierValues } from "./ledger-grammar.mjs";
|
|
140
143
|
import { sessionFromReceipt } from "./phase0-receipt.mjs";
|
|
141
144
|
import { briefPaths, briefText, defang, outOfScope, strandedRuling, ticketText } from "./ticket-text.mjs";
|
|
@@ -155,10 +158,6 @@ const EXPLORE_EVERY = 5;
|
|
|
155
158
|
// The states that lift an exclusion's premise.
|
|
156
159
|
const LIFTED = new Set(["MERGED", "CLOSED"]);
|
|
157
160
|
|
|
158
|
-
const READY = "ready-for-agent";
|
|
159
|
-
const TRIAGE = "needs-triage";
|
|
160
|
-
const HUMAN = "ready-for-human";
|
|
161
|
-
|
|
162
161
|
const USAGE = `usage: ${NAME}.mjs next [--head <N>] | ${NAME}.mjs answer <N> <qid> <token> [--path <p>] [--] [<text>…]`;
|
|
163
162
|
|
|
164
163
|
// ── the comments the script posts ────────────────────────────────────────────
|
|
@@ -181,28 +180,31 @@ function handsParts(text) {
|
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
/**
|
|
184
|
-
* The comment, and the label that replaces `ready-for-agent
|
|
185
|
-
* other than `decided` — or, for `stranded-ruling`, for a ruling or
|
|
186
|
-
* comment newer than the brief, `text` naming its heading line and its
|
|
183
|
+
* The comment, and the label that replaces the `ready-for-agent` label, for a
|
|
184
|
+
* Q2 answer other than `decided` — or, for `stranded-ruling`, for a ruling or
|
|
185
|
+
* triage comment newer than the brief, `text` naming its heading line and its
|
|
186
|
+
* URL. `labels` is the Label map (role -> the tracker's string): the label
|
|
187
|
+
* returned and the labels the comment names are its strings.
|
|
187
188
|
*/
|
|
188
|
-
export function relabel(token, text) {
|
|
189
|
+
export function relabel(token, text, labels) {
|
|
190
|
+
const { "ready-for-agent": ready, "ready-for-human": human } = labels;
|
|
189
191
|
if (token === "stranded-ruling") {
|
|
190
192
|
return {
|
|
191
|
-
label:
|
|
192
|
-
comment: `${RELABELLED} a ruling or triage comment is newer than the brief, and the Pull does not read it: ${text}. To make it the brief, rename its heading to \`## Agent Brief — ruling\` and drop anything that is not decided scope, or delete it; then restore \`${
|
|
193
|
+
label: human,
|
|
194
|
+
comment: `${RELABELLED} a ruling or triage comment is newer than the brief, and the Pull does not read it: ${text}. To make it the brief, rename its heading to \`## Agent Brief — ruling\` and drop anything that is not decided scope, or delete it; then restore \`${ready}\`.`,
|
|
193
195
|
};
|
|
194
196
|
}
|
|
195
197
|
if (token === "needs-triage") {
|
|
196
198
|
return {
|
|
197
|
-
label:
|
|
198
|
-
comment: `${RELABELLED} the brief does not decide what to build. Missing decision: ${text}. Returning to /triage; \`${
|
|
199
|
+
label: labels["needs-triage"],
|
|
200
|
+
comment: `${RELABELLED} the brief does not decide what to build. Missing decision: ${text}. Returning to /triage; \`${ready}\` restored once decided.`,
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
203
|
if (token === "ready-for-human-fork") {
|
|
202
|
-
return { label:
|
|
204
|
+
return { label: human, comment: `${RELABELLED} the brief leaves a decision open. Open fork: ${text}.` };
|
|
203
205
|
}
|
|
204
206
|
const { cause, line } = handsParts(text);
|
|
205
|
-
return { label:
|
|
207
|
+
return { label: human, comment: `${RELABELLED} needs human hands — ${HANDS[cause]}: ${line}.` };
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
/** The comment a `yes` to Q1b closes the issue with. */
|
|
@@ -809,7 +811,7 @@ class Pull {
|
|
|
809
811
|
} catch (e) {
|
|
810
812
|
return this.stop(`cannot write ${this.p.issue}: ${e.message}`);
|
|
811
813
|
}
|
|
812
|
-
if (!issue.labels.some((l) => l?.name ===
|
|
814
|
+
if (!issue.labels.some((l) => l?.name === this.p.labels["ready-for-agent"])) return this.leave("relabelled elsewhere");
|
|
813
815
|
const stranded = strandedRuling(issue);
|
|
814
816
|
if (stranded !== null) {
|
|
815
817
|
if (typeof stranded.url !== "string") return this.stop(`gh issue view printed a ruling comment with no url: "${stranded.heading}"`);
|
|
@@ -1100,17 +1102,20 @@ class Pull {
|
|
|
1100
1102
|
|
|
1101
1103
|
// Posts the cause's comment and swaps `ready-for-agent` for its label. One
|
|
1102
1104
|
// comment per cause: an edit that failed after its comment landed is run
|
|
1103
|
-
// again without a second comment.
|
|
1105
|
+
// again without a second comment. The cause is the token and its text, never
|
|
1106
|
+
// the comment, whose wording takes the Label map's strings and so moves with
|
|
1107
|
+
// the map between the failed edit and the retry.
|
|
1104
1108
|
relabelled(token, text) {
|
|
1105
1109
|
const { st } = this;
|
|
1106
|
-
const { label, comment } = relabel(token, text);
|
|
1107
|
-
|
|
1110
|
+
const { label, comment } = relabel(token, text, this.p.labels);
|
|
1111
|
+
const cause = JSON.stringify([token, text]);
|
|
1112
|
+
if (st.commented !== cause) {
|
|
1108
1113
|
const c = this.gh("relabel", ["issue", "comment", String(st.ticket), "--body", comment]);
|
|
1109
1114
|
if (c.status !== 0) return this.stop(withText(`gh issue comment failed (${c.how})`, c));
|
|
1110
|
-
st.commented =
|
|
1115
|
+
st.commented = cause;
|
|
1111
1116
|
this.save();
|
|
1112
1117
|
}
|
|
1113
|
-
const e = this.gh("relabel", ["issue", "edit", String(st.ticket), "--remove-label",
|
|
1118
|
+
const e = this.gh("relabel", ["issue", "edit", String(st.ticket), "--remove-label", this.p.labels["ready-for-agent"], "--add-label", label]);
|
|
1114
1119
|
if (e.status !== 0) return this.stop(withText(`gh issue edit failed (${e.how}) — the comment is posted`, e));
|
|
1115
1120
|
return this.leave(`relabelled ${label}: ${token}`);
|
|
1116
1121
|
}
|
|
@@ -1257,11 +1262,21 @@ function setup() {
|
|
|
1257
1262
|
}
|
|
1258
1263
|
const root = spawn(process.execPath, [join(SCRIPTS, "scratch-root.mjs")], { cwd });
|
|
1259
1264
|
if (root.status !== 0) throw new Refusal(withText(`scratch-root.mjs ${root.how}`, root));
|
|
1265
|
+
// The Label map, read once here: every label the Pull compares, writes or names in a comment is its string. No
|
|
1266
|
+
// valid map is exit 2, the reader's message naming `label-map.mjs ensure`; never the exit that reads as "left".
|
|
1267
|
+
let labels;
|
|
1268
|
+
try {
|
|
1269
|
+
labels = readLabelMap({ cwd });
|
|
1270
|
+
} catch (e) {
|
|
1271
|
+
if (!(e instanceof LabelMapUnreadable)) throw e;
|
|
1272
|
+
throw new Refusal(e.message);
|
|
1273
|
+
}
|
|
1260
1274
|
const scratch = root.stdout;
|
|
1261
1275
|
const dir = (n) => join(scratch, `impl-${n}`);
|
|
1262
1276
|
return {
|
|
1263
1277
|
cwd,
|
|
1264
1278
|
scratch,
|
|
1279
|
+
labels,
|
|
1265
1280
|
shortlist: join(fleetDir, "shortlist.json"),
|
|
1266
1281
|
guard: join(fleetDir, "cost-guard.json"),
|
|
1267
1282
|
statePath: (n) => join(dir(n), STATE),
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Fills the `parent` column of a ticket-features corpus from each ticket's
|
|
3
|
+
// issue body, so the Router's fit reads every Slice as a Slice.
|
|
4
|
+
//
|
|
5
|
+
// slice-fill.mjs [--features <tsv>]
|
|
6
|
+
//
|
|
7
|
+
// `--features` is the corpus, `docs/metrics/ticket-features.tsv` under the cwd
|
|
8
|
+
// when omitted; `gh` reads the issues of the repository the cwd is in. A
|
|
9
|
+
// corpus whose header lacks `parent` gains it, blank on every row. Then every
|
|
10
|
+
// row whose ticket is a Slice (ticket-router.mjs's sliceParent, off the
|
|
11
|
+
// issue's current body) gets its parent's number, and nothing else changes: a
|
|
12
|
+
// row whose ticket is no Slice keeps its `parent` as it is, and a run over a
|
|
13
|
+
// filled corpus writes nothing. So it is safe to run again, and it is what
|
|
14
|
+
// sets `parent` on rows a run drained from a plugin that wrote no `parent`.
|
|
15
|
+
//
|
|
16
|
+
// Prints one line naming how many rows it set. Exit 0 when every ticket's
|
|
17
|
+
// issue was read; 1 when some could not be — their rows are left as they
|
|
18
|
+
// were, each named on stderr, and the rest are written; 2 on a usage error, a
|
|
19
|
+
// corpus that does not parse, or a corpus that cannot be written, which
|
|
20
|
+
// writes nothing.
|
|
21
|
+
|
|
22
|
+
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { resolve } from "node:path";
|
|
24
|
+
import { makeDie, defineFlags } from "./arg.mjs";
|
|
25
|
+
import { ghAliasedRead } from "./gh-aliased-read.mjs";
|
|
26
|
+
import { isCLI } from "./is-cli.mjs";
|
|
27
|
+
import { parseFeatures } from "./pull-attribution.mjs";
|
|
28
|
+
import { sliceParent } from "./ticket-router.mjs";
|
|
29
|
+
|
|
30
|
+
const NAME = "slice-fill";
|
|
31
|
+
const DEFAULT_FEATURES = "docs/metrics/ticket-features.tsv";
|
|
32
|
+
const GH_TIMEOUT_MS = 120_000;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `text`, a ticket-features corpus, with `parent` set on every row whose
|
|
36
|
+
* ticket `parents` maps to a parent number: `parents` maps a ticket (as a
|
|
37
|
+
* string) to its parent's number, or to "" for a ticket that is no Slice. A
|
|
38
|
+
* ticket it leaves out keeps its rows as they are. A header without `parent`
|
|
39
|
+
* gains it, blank on every row. Comment lines, row order and every other cell
|
|
40
|
+
* are kept byte for byte. Throws on a corpus parseFeatures refuses.
|
|
41
|
+
* @returns {{ text: string, set: number, widened: boolean }}
|
|
42
|
+
*/
|
|
43
|
+
export function fillParent(text, parents) {
|
|
44
|
+
parseFeatures(text);
|
|
45
|
+
const lines = String(text).split("\n");
|
|
46
|
+
let ticketAt = -1;
|
|
47
|
+
let at = -1;
|
|
48
|
+
let set = 0;
|
|
49
|
+
let widened = false;
|
|
50
|
+
const out = lines.map((l) => {
|
|
51
|
+
if (!l.trim() || l.startsWith("#")) return l;
|
|
52
|
+
if (at === -1) {
|
|
53
|
+
const header = l.split("\t");
|
|
54
|
+
ticketAt = header.indexOf("ticket");
|
|
55
|
+
at = header.indexOf("parent");
|
|
56
|
+
if (at !== -1) return l;
|
|
57
|
+
widened = true;
|
|
58
|
+
at = header.length;
|
|
59
|
+
return `${l}\tparent`;
|
|
60
|
+
}
|
|
61
|
+
const cells = l.split("\t");
|
|
62
|
+
if (widened) cells.push("");
|
|
63
|
+
const parent = parents.get(cells[ticketAt]) ?? "";
|
|
64
|
+
if (parent !== "" && cells[at] !== parent) {
|
|
65
|
+
cells[at] = parent;
|
|
66
|
+
set += 1;
|
|
67
|
+
}
|
|
68
|
+
return cells.join("\t");
|
|
69
|
+
});
|
|
70
|
+
return { text: out.join("\n"), set, widened };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function main() {
|
|
74
|
+
const die = makeDie(NAME);
|
|
75
|
+
const F = defineFlags(die, { flags: { features: "value" } });
|
|
76
|
+
F.sweep();
|
|
77
|
+
F.stray();
|
|
78
|
+
const file = resolve(F.arg("features") ?? DEFAULT_FEATURES);
|
|
79
|
+
let text;
|
|
80
|
+
let tickets;
|
|
81
|
+
try {
|
|
82
|
+
text = readFileSync(file, "utf8");
|
|
83
|
+
tickets = [...new Set(parseFeatures(text).map((r) => Number(r.ticket)))];
|
|
84
|
+
} catch (e) {
|
|
85
|
+
die(`${file}: ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
const parents = new Map();
|
|
88
|
+
let missed = 0;
|
|
89
|
+
for (const [n, got] of ghAliasedRead(tickets, { field: "issue", selection: "{body}", timeoutMs: GH_TIMEOUT_MS })) {
|
|
90
|
+
if (typeof got.node?.body === "string") {
|
|
91
|
+
parents.set(String(n), sliceParent(got.node.body));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
missed += 1;
|
|
95
|
+
process.stderr.write(`${NAME}: issue #${n} ${got.notFound ? "not found" : `unreadable (${got.unreachable ?? "no body"})`} — its rows are left as they were\n`);
|
|
96
|
+
}
|
|
97
|
+
const filled = fillParent(text, parents);
|
|
98
|
+
if (filled.text !== text) {
|
|
99
|
+
try {
|
|
100
|
+
writeFileSync(`${file}.tmp`, filled.text);
|
|
101
|
+
renameSync(`${file}.tmp`, file);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
// A .tmp the rename left behind goes too; one that cannot be removed is
|
|
104
|
+
// overwritten by the next run, and the die message names the failure.
|
|
105
|
+
try { rmSync(`${file}.tmp`, { force: true }); } catch {}
|
|
106
|
+
die(`${file}: cannot write: ${e.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const slices = [...parents.values()].filter((p) => p !== "").length;
|
|
110
|
+
process.stdout.write(`${NAME}: ${file}: parent set on ${filled.set} row${filled.set === 1 ? "" : "s"}${filled.widened ? ", parent column added" : ""}; ${slices} of ${parents.size} ticket${parents.size === 1 ? "" : "s"} read are Slices\n`);
|
|
111
|
+
if (missed > 0) process.exitCode = 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (isCLI(import.meta.url)) main();
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// [--chain-head] [--pending <tsv>]
|
|
10
10
|
// Prints one line, the Pull's Routing (ledger-grammar.mjs owns its
|
|
11
11
|
// grammar): `POLICY=<cell> CELL=<cell> DRAW=<k/K|-> BY=<burn-in|every-5th|->
|
|
12
|
-
// STRATUM=<light|heavy|unknown> BRIEF=<chars|-> CRITERIA=<n|->
|
|
12
|
+
// STRATUM=<light|heavy|unknown> BRIEF=<chars|-> CRITERIA=<n|-> PARENT=<N|->
|
|
13
13
|
// SIZED=<light|heavy|-> OBJECTIVE=<cost|speed> TRIPPED=<cell,…|->
|
|
14
14
|
// REASON=<reason>`,
|
|
15
15
|
// routing by the objective's row set, and appends the Pull's
|
|
@@ -55,7 +55,7 @@ import { CELL, OBJECTIVES, POLICY_CELL, STRATA, drawCell, formatRouting, parseMe
|
|
|
55
55
|
import { objectiveFromReceipt, sessionFromReceipt } from "./phase0-receipt.mjs";
|
|
56
56
|
import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
|
|
57
57
|
import {
|
|
58
|
-
AttributionError, FEATURE_COLUMNS, TRIP_POINTS, attribute, bootUnit, bootstrapDiffCI, generations, parseFeatures, tally, underFloor,
|
|
58
|
+
AttributionError, FEATURE_COLUMNS, OPTIONAL_COLUMNS, TRIP_POINTS, attribute, bootUnit, bootstrapDiffCI, generations, parseFeatures, tally, underFloor,
|
|
59
59
|
} from "./pull-attribution.mjs";
|
|
60
60
|
import { RulingError, parseTierOutcomes } from "./tier-outcomes.mjs";
|
|
61
61
|
import { briefPaths, briefText } from "./ticket-text.mjs";
|
|
@@ -83,6 +83,32 @@ const DAY_MS = 86_400_000;
|
|
|
83
83
|
// metrics — every one free, deterministic and known before dispatch
|
|
84
84
|
// ---------------------------------------------------------------------------
|
|
85
85
|
|
|
86
|
+
// A Slice names its parent at the top of its issue body: `Spec: #<N>` at the
|
|
87
|
+
// start of the first non-blank line, or a `## Parent` section the body opens
|
|
88
|
+
// with, whose first issue named (`#<N>` or an issue URL) is the parent.
|
|
89
|
+
const SPEC_LINE = /^Spec: #([1-9][0-9]*)(?![0-9])/;
|
|
90
|
+
const PARENT_HEADING = /^##\s+Parent\s*$/;
|
|
91
|
+
const HEADING = /^#{1,6}\s/;
|
|
92
|
+
const ISSUE_REF = /(?:^|[^\w/&])#([1-9][0-9]*)(?![0-9])|https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/issues\/([1-9][0-9]*)(?![0-9])/;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A Slice's parent issue number off its issue body, as a string, or "" when
|
|
96
|
+
* the body makes no Slice. The body alone decides: a later `## Agent Brief`
|
|
97
|
+
* comment leaves a Slice a Slice. `Spec #<N>` with no colon, a `## Parent`
|
|
98
|
+
* section naming no issue and a `Part of #<N>` line make none.
|
|
99
|
+
*/
|
|
100
|
+
export function sliceParent(body) {
|
|
101
|
+
const lines = String(body ?? "").split(/\r?\n/);
|
|
102
|
+
const at = lines.findIndex((l) => l.trim() !== "");
|
|
103
|
+
if (at === -1) return "";
|
|
104
|
+
const spec = SPEC_LINE.exec(lines[at]);
|
|
105
|
+
if (spec !== null) return spec[1];
|
|
106
|
+
if (!PARENT_HEADING.test(lines[at])) return "";
|
|
107
|
+
const end = lines.findIndex((l, i) => i > at && HEADING.test(l));
|
|
108
|
+
const ref = ISSUE_REF.exec(lines.slice(at + 1, end === -1 ? undefined : end).join("\n"));
|
|
109
|
+
return ref === null ? "" : ref[1] ?? ref[2];
|
|
110
|
+
}
|
|
111
|
+
|
|
86
112
|
/** The metric columns for a parsed `gh issue view --json title,body,comments,labels,createdAt`, or null when it is not one. */
|
|
87
113
|
export function issueMetrics(issue, now = Date.now()) {
|
|
88
114
|
if (issue === null || typeof issue !== "object" || Array.isArray(issue) || typeof issue.body !== "string") return null;
|
|
@@ -100,12 +126,19 @@ export function issueMetrics(issue, now = Date.now()) {
|
|
|
100
126
|
test_paths: String(paths.filter((p) => /\.test\.|(^|\/)tests?\//.test(p)).length),
|
|
101
127
|
xrefs: String(new Set([...brief.matchAll(/#(\d+)/g)].map((m) => m[1])).size),
|
|
102
128
|
kind,
|
|
129
|
+
parent: sliceParent(issue.body),
|
|
103
130
|
};
|
|
104
131
|
}
|
|
105
132
|
|
|
106
|
-
/**
|
|
107
|
-
|
|
133
|
+
/**
|
|
134
|
+
* The `rule` classifier, over a row's metric columns: blank metrics are
|
|
135
|
+
* `unknown`, a Slice (a row with a `parent`) is `heavy`, and any other row is
|
|
136
|
+
* `heavy` past the brief length or the criteria count. A Slice whose metrics
|
|
137
|
+
* are blank stays `unknown`, as it was routed: its issue was not read then.
|
|
138
|
+
*/
|
|
139
|
+
export function ruleStratum({ brief_chars, criteria, parent }) {
|
|
108
140
|
if (brief_chars === "" || brief_chars === undefined || criteria === "" || criteria === undefined) return "unknown";
|
|
141
|
+
if (parent) return "heavy";
|
|
109
142
|
return Number(brief_chars) > HEAVY_BRIEF_CHARS || Number(criteria) > HEAVY_CRITERIA ? "heavy" : "light";
|
|
110
143
|
}
|
|
111
144
|
|
|
@@ -219,7 +252,7 @@ export function route({ session, ticket, arm, implRow, chainHead = false, issue,
|
|
|
219
252
|
|
|
220
253
|
const metrics = issueMetrics(issue, now);
|
|
221
254
|
if (metrics === null) degrade("no-issue-json");
|
|
222
|
-
const blank = Object.fromEntries(["brief_chars", "criteria", "comments", "age_days", "paths", "test_paths", "xrefs", "kind"].map((c) => [c, ""]));
|
|
255
|
+
const blank = Object.fromEntries(["brief_chars", "criteria", "comments", "age_days", "paths", "test_paths", "xrefs", "kind", "parent"].map((c) => [c, ""]));
|
|
223
256
|
const m = metrics ?? blank;
|
|
224
257
|
const ruleS = ruleStratum(m);
|
|
225
258
|
|
|
@@ -284,13 +317,16 @@ export function route({ session, ticket, arm, implRow, chainHead = false, issue,
|
|
|
284
317
|
const line = formatRouting({
|
|
285
318
|
policy, cell, draw, by, stratum,
|
|
286
319
|
brief: metrics === null ? null : Number(metrics.brief_chars), criteria: metrics === null ? null : Number(metrics.criteria),
|
|
320
|
+
parent: m.parent === "" ? null : Number(m.parent),
|
|
287
321
|
sized: sizingPre === "" ? null : sizingPre, objective, tripped: guard?.tripped ?? [], reason,
|
|
288
322
|
});
|
|
289
323
|
return { line, row };
|
|
290
324
|
}
|
|
291
325
|
|
|
292
|
-
|
|
293
|
-
|
|
326
|
+
// `columns` is the header of the file the row joins: a pending file a run
|
|
327
|
+
// began before a column was added keeps its own width.
|
|
328
|
+
export function formatFeatureRow(row, columns = FEATURE_COLUMNS) {
|
|
329
|
+
return columns.map((c) => String(row[c] ?? "").replace(/[\t\r\n]/g, " ")).join("\t");
|
|
294
330
|
}
|
|
295
331
|
|
|
296
332
|
// ---------------------------------------------------------------------------
|
|
@@ -686,11 +722,24 @@ function main() {
|
|
|
686
722
|
// The header decision and the append are not atomic and take no lock. That is
|
|
687
723
|
// safe only while the run's controller is the only process that routes or
|
|
688
724
|
// drains on a checkout, doing both serially: one controller per checkout is
|
|
689
|
-
// the rule, and neither this append nor the drain checks it.
|
|
725
|
+
// the rule, and neither this append nor the drain checks it. A pending file
|
|
726
|
+
// already begun keeps its header's columns, so a plugin updated mid-run
|
|
727
|
+
// never appends a row wider or narrower than the file. A first line that is
|
|
728
|
+
// no features header — a required column missing, or a name no features
|
|
729
|
+
// file carries — is refused, not appended against.
|
|
690
730
|
try {
|
|
691
731
|
mkdirSync(dirname(pending), { recursive: true });
|
|
692
|
-
const
|
|
693
|
-
|
|
732
|
+
const had = statSync(pending, { throwIfNoEntry: false })?.size > 0 ? readFileSync(pending, "utf8").split("\n", 1)[0].split("\t") : null;
|
|
733
|
+
if (had !== null) {
|
|
734
|
+
const missing = FEATURE_COLUMNS.filter((c) => !had.includes(c) && !OPTIONAL_COLUMNS.has(c));
|
|
735
|
+
const unknown = had.filter((c) => !FEATURE_COLUMNS.includes(c));
|
|
736
|
+
if (missing.length || unknown.length) {
|
|
737
|
+
const why = [missing.length ? `lacks ${missing.join(", ")}` : "", unknown.length ? `names ${unknown.map((c) => JSON.stringify(c)).join(", ")}` : ""];
|
|
738
|
+
throw new Error(`its first line is no ticket-features header: it ${why.filter(Boolean).join(" and ")}`);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const header = had === null ? `${FEATURE_COLUMNS.join("\t")}\n` : "";
|
|
742
|
+
appendFileSync(pending, `${header}${formatFeatureRow(row, had ?? FEATURE_COLUMNS)}\n`);
|
|
694
743
|
} catch (e) {
|
|
695
744
|
process.stderr.write(`${NAME}: WARNING could not append to ${pending}: ${e.message} — this Pull's ticket-features row is not recorded\n`);
|
|
696
745
|
}
|
|
@@ -251,7 +251,7 @@ terminating in exactly one dispatch or an empty shortlist:
|
|
|
251
251
|
7. **Route, row, then dispatch** — `~/.fleet/bin/fleet-run ticket-router.mjs route
|
|
252
252
|
--session <session> --ticket <N> --arm <A|B> --impl-row <k>[ --chain-head] --issue
|
|
253
253
|
<scratch>/impl-<N>/issue.json --guard .fleet/cost-guard.json` prints the Pull's
|
|
254
|
-
Routing, `POLICY=… CELL=… DRAW=… BY=… STRATUM=… BRIEF=… CRITERIA=… SIZED=… OBJECTIVE=… TRIPPED=… REASON=…`
|
|
254
|
+
Routing, `POLICY=… CELL=… DRAW=… BY=… STRATUM=… BRIEF=… CRITERIA=… PARENT=… SIZED=… OBJECTIVE=… TRIPPED=… REASON=…`
|
|
255
255
|
(the router's arguments paragraph below the list says what each argument is);
|
|
256
256
|
then `ledger.mjs row <N> "impl-<N>[ · tier=<CELL>]" --routing "<that line>"`,
|
|
257
257
|
`tier=<CELL>` exactly when `DRAW` is not `-`, which writes the row and files
|