@feigi/fleet-ctl 3.30.0 → 3.30.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.30.0",
3
+ "version": "3.30.2",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  // fleet-tick.mjs's I/O and main() never run here, main() being guarded on
26
26
  // argv[1].
27
27
  import { assessBeat, isStalled, stallReport } from "./fleet-state.mjs";
28
- import { parseToken, rowPr, HALT_CAUSES } from "./ledger-grammar.mjs";
28
+ import { parseToken, rowPr, premisesOf, HALT_CAUSES } from "./ledger-grammar.mjs";
29
29
  import { REVIEWED, latestFinisherAttempts } from "./fleet-tick.mjs";
30
30
 
31
31
  // A ledger row is freeform, controller-authored text. Two example shapes:
@@ -95,11 +95,9 @@ import { REVIEWED, latestFinisherAttempts } from "./fleet-tick.mjs";
95
95
  // it to agree with.
96
96
  //
97
97
  // `#N excluded · behind-pr:#M` / `behind-issue:#M` is an Exclusion — pool
98
- // supply, not a claim — spelled exactly as shortlist.mjs and fleet-tick.mjs
99
- // spell it. `#M` is an issue or PR number, or the branch name recorded before
100
- // that PR existed.
101
- const EXCLUDED_ROW = /^#[0-9]+[ \t]+excluded(?=[ \t]|$)([\s\S]*)$/;
102
- const PREMISE = /\bbehind-(pr|issue):#?([^\s,;]+)/g;
98
+ // supply, not a claim — read through ledger-grammar.mjs's premisesOf(), the
99
+ // reading shortlist.mjs and fleet-tick.mjs use too.
100
+ //
103
101
  // Captures the matched kind, so parseRow tells a Workflow from a runner by
104
102
  // that capture instead of a second scan; see the review notes above for
105
103
  // what each kind means and how `=failed` settles it.
@@ -135,7 +133,7 @@ export function parseRow(row) {
135
133
  for (const t of ["KILLED", "BLOCKED", "SHA-OFF-BRANCH"]) {
136
134
  if (new RegExp(`\\b${t}\\b`).test(row)) causes.push(t.toLowerCase());
137
135
  }
138
- const ex = EXCLUDED_ROW.exec(row);
136
+ const excluded = premisesOf(row);
139
137
 
140
138
  // `live` holds live entries in row order, each one of two kinds: a
141
139
  // ledger-grammar member (`kind: "member"`, its parsed token as `token`) or
@@ -217,7 +215,7 @@ export function parseRow(row) {
217
215
  // module's extra gate exists so an ordinary unclaimed ticket never
218
216
  // borrows its own number as a phantom PR. An Exclusion is supply and
219
217
  // never takes a PR, whatever text it carries.
220
- if (!anyImpl && !ex) {
218
+ if (!anyImpl && excluded === null) {
221
219
  const own = rowPr(row);
222
220
  if (own !== null) pr = own;
223
221
  else if ((prMember || review || reviewed) && row.split(/\s/)[0] === issueM[0]) pr = Number(issueM[1]);
@@ -228,7 +226,7 @@ export function parseRow(row) {
228
226
  }
229
227
  return {
230
228
  issue: Number(issueM[1]),
231
- excluded: ex ? [...ex[1].matchAll(PREMISE)].map(([, kind, target]) => ({ kind, target })) : null,
229
+ excluded,
232
230
  impl: lastImpl?.name ?? null,
233
231
  implOutcome,
234
232
  finisherOutcome: lastFinisher ? (finisherOutcomes.get(lastFinisher.name) ?? null) : null,
@@ -59,7 +59,7 @@
59
59
  // the ledger; main() does the I/O. Split so the guard table and the reading are
60
60
  // both unit-testable without a network.
61
61
 
62
- import { parseMember, parseToken, rowPr } from "./ledger-grammar.mjs";
62
+ import { parseMember, parseToken, rowPr, premisesOf } from "./ledger-grammar.mjs";
63
63
 
64
64
  // Every role's TARGET is its configured cap. Availability of work belongs in
65
65
  // the ACTION, not the target: a reviewer target that shrank to the backlog
@@ -340,9 +340,6 @@ export function actionable(rows) {
340
340
 
341
341
  export class LedgerError extends Error {}
342
342
 
343
- // shortlist.mjs's own spelling of an Exclusion row and its premises.
344
- const EXCLUDED_ROW = /^#[0-9]+[ \t]+excluded(?=[ \t]|$)([\s\S]*)$/;
345
- const PREMISE = /\bbehind-(pr|issue):#?([^\s,;]+)/g;
346
343
  // `review=wf:<runId>` | `review=member:review-pr-<n>` |
347
344
  // `review=fallback:review-pr-<n>[-b]`, settled dead as `…=failed`; the result
348
345
  // is `reviewed=<head>:<survived>/<refuted>/<unverified>`.
@@ -691,9 +688,8 @@ export function deriveRun({ rows, dispatched, drain }, prs, closed = new Set(),
691
688
  if (d && d.member.number === pr) st.dispositions.push(d);
692
689
  }
693
690
  }
694
- const ex = EXCLUDED_ROW.exec(text);
695
- if (ex && keyNum !== null) {
696
- const premises = [...ex[1].matchAll(PREMISE)].map(([, kind, target]) => ({ kind, target }));
691
+ const premises = premisesOf(text);
692
+ if (premises !== null) {
697
693
  // An `excluded` row claims its ticket only while its
698
694
  // premise still holds. Lifted here only when EVERY premise is a
699
695
  // verifiable, now-closed `behind-pr:#M` — the same rule a
@@ -1,13 +1,15 @@
1
- // The run ledger's member grammar: a member's token is `<member>` while it is live and
1
+ // The run ledger's grammar: its sections on disk, a row's Exclusion and its
2
+ // PR, and its members. A member's token is `<member>` while it is live and
2
3
  // `<member>=<outcome>` once settled. `ledger.mjs dispatch` writes the bare
3
4
  // token and `ledger.mjs settle` rewrites it, so a reader derives every
4
5
  // liveness count from the ledger file alone instead of from the controller's
5
6
  // memory of what it dispatched.
6
7
  //
7
8
  // A module of its own, not a function inside ledger.mjs, because ledger.mjs is
8
- // a CLI that parses argv and exits on import — and `fleet-tick.mjs` is to read
9
- // this same grammar. A second copy of it there would be two readings
10
- // of which members are live, free to drift apart.
9
+ // a CLI that parses argv and exits on import — and `fleet-tick.mjs`,
10
+ // `compute-board.mjs` and `shortlist.mjs` read this same grammar. A second
11
+ // copy of it in any of them would be two readings of one row, free to drift
12
+ // apart.
11
13
  //
12
14
  // Rows stay freeform text. Only a token whose name part is a member name is
13
15
  // claimed here; everything else a row carries (`class=routine`, `ports=`,
@@ -103,6 +105,49 @@ export function rowPr(text) {
103
105
  return m ? Number(m[1]) : null;
104
106
  }
105
107
 
108
+ // A ticket row is `#N <text>`; it is an Exclusion when `excluded` is the
109
+ // text's first word — `impl-N · … excluded …` is a row about something else.
110
+ // `#N excluded · behind-pr:#M` / `behind-issue:#M`: `#M` is an issue or PR
111
+ // number, or the branch name recorded before that PR existed.
112
+ const EXCLUDED_ROW = /^#[0-9]+[ \t]+excluded(?=[ \t]|$)([\s\S]*)$/;
113
+ const PREMISE = /\bbehind-(pr|issue):#?([^\s,;]+)/g;
114
+
115
+ /** The `{kind, target}` premises an Exclusion row names, in row order and
116
+ * possibly none, or null for any other row. */
117
+ export function premisesOf(row) {
118
+ const m = EXCLUDED_ROW.exec(row);
119
+ if (!m) return null;
120
+ return [...m[1].matchAll(PREMISE)].map(([, kind, target]) => ({ kind, target }));
121
+ }
122
+
123
+ export const ROWS = "## Rows";
124
+ export const DISPATCHED = "## Dispatched";
125
+ export const FILED = "## Filed";
126
+ export const RULED = "## Ruled";
127
+ export const DRAIN = "## Drain";
128
+
129
+ // What a section header looks like on disk, defined once because a second
130
+ // copy drifts: ledger.mjs slices sections with it, and sets its readability
131
+ // flag from it. Anchored to a real line start (or string start), not
132
+ // a bare substring search — otherwise an escaped entry that merely CONTAINS
133
+ // the text "## Filed" (never a physical line, just a run of characters inside
134
+ // a one-line entry) is found by indexOf() before the genuine header and the
135
+ // whole section is sliced from the wrong offset.
136
+ export const headerRe = (name) => new RegExp(`(^|\\n)${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\n|$)`);
137
+
138
+ // One entry is always exactly one physical line on disk. Escape backslash
139
+ // first, then newline, so a `\` in entry text can never be mistaken for the
140
+ // start of an escape sequence introduced by this encoding. Without this, an
141
+ // entry containing a real newline — or a line that happens to look like
142
+ // `## Filed` or `- #<issue> ...` — gets misparsed on reload: real records
143
+ // silently drop, or phantom ones get injected.
144
+ export function escapeText(s) {
145
+ return s.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
146
+ }
147
+ export function unescapeText(s) {
148
+ return s.replace(/\\(\\|n)/g, (_, c) => (c === "n" ? "\n" : "\\"));
149
+ }
150
+
106
151
  /** The name the next merge bot takes: 1 + the `merge-bot-` entries in
107
152
  * `## Dispatched`, settled ones included. One ledger per run, so n restarts
108
153
  * at 1 with every run. */
@@ -35,7 +35,7 @@ import { fileURLToPath } from "node:url";
35
35
  import { spawnSync, execFileSync } from "node:child_process";
36
36
  import { makeDie, isFlagLike, hasEqualsForm, isDigits } from "./arg.mjs";
37
37
  import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
38
- import { parseMember, parseToken, memberTokens, nextMergeBot, agentDefinition, CELL, tierValues, rowPr } from "./ledger-grammar.mjs";
38
+ import { parseMember, parseToken, memberTokens, nextMergeBot, agentDefinition, CELL, tierValues, rowPr, ROWS, DISPATCHED, FILED, RULED, DRAIN, headerRe, escapeText, unescapeText } from "./ledger-grammar.mjs";
39
39
  import { deriveRun, LedgerError, labelOffMember } from "./fleet-tick.mjs";
40
40
  import { stateFileIn, readState, assessBeat, stallsAt } from "./fleet-state.mjs";
41
41
 
@@ -225,34 +225,6 @@ if (requireFileIdx !== -1) argv.splice(requireFileIdx, 1);
225
225
  const [cmd, ...rest] = argv;
226
226
  if (!cmd) die("usage: ledger.mjs [--file <path>] [--require-file] row|filed|ruled|check|read|dispatch|settle|drain|rotate [args]");
227
227
 
228
- const ROWS = "## Rows";
229
- const DISPATCHED = "## Dispatched";
230
- const FILED = "## Filed";
231
- const RULED = "## Ruled";
232
- const DRAIN = "## Drain";
233
-
234
- // What a section header looks like on disk, defined once because a second
235
- // copy drifts: the parser slices sections with it, and the readability flag
236
- // below is set from it. Anchored to a real line start (or string start), not
237
- // a bare substring search — otherwise an escaped entry that merely CONTAINS
238
- // the text "## Filed" (never a physical line, just a run of characters inside
239
- // a one-line entry) is found by indexOf() before the genuine header and the
240
- // whole section is sliced from the wrong offset.
241
- const headerRe = (name) => new RegExp(`(^|\\n)${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\n|$)`);
242
-
243
- // One entry is always exactly one physical line on disk. Escape backslash
244
- // first, then newline, so a `\` in entry text can never be mistaken for the
245
- // start of an escape sequence introduced by this encoding. Without this, an
246
- // entry containing a real newline — or a line that happens to look like
247
- // `## Filed` or `- #<issue> ...` — gets misparsed on reload: real records
248
- // silently drop, or phantom ones get injected.
249
- function escapeText(s) {
250
- return s.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
251
- }
252
- function unescapeText(s) {
253
- return s.replace(/\\(\\|n)/g, (_, c) => (c === "n" ? "\n" : "\\"));
254
- }
255
-
256
228
  // A `--`-prefixed token in `check`'s free-text tail used to fold
257
229
  // straight into the duplicate-filing subject, so a misspelled flag searched
258
230
  // for a DIFFERENT subject and read "safe to file" where the correct spelling
package/scripts/reap.sh CHANGED
@@ -312,22 +312,18 @@ removed=""
312
312
  # a substitution that failed would contribute an empty string and splice
313
313
  # `{"branch":,…}` — malformed JSON — with nothing to notice it.
314
314
  #
315
- # Five interpolations converge on this function: the branch name, `dirty
316
- # worktree $wt`, `ignored files present in $wt: $ignored`, `cherry probe
317
- # failed …: $cherry` (arbitrary git stderr) — the first four via `keep`, whose
318
- # own `jfield "$1"` / `jfield "$2"` every `keep` call carrying one of them
319
- # reaches — and the `reaped` accumulator, which calls `jfield`
320
- # directly and never routes through `keep` at all. The branch name is the
321
- # demonstrated trigger — `git branch 'has"quote'` is a legal refname — and raw
322
- # it emitted a payload no parser accepts at exit 0, while the branch was
323
- # correctly kept. The stderr lines stay raw: they are prose for an
324
- # operator, not JSON.
325
- #
326
- # A sixth joined the five above later: grep's own stderr, `$gq_err`,
327
- # surfaced through `gp_why "$gq_err"` in `keep`'s message at the cherry
328
- # checks and the registry re-reads —
329
- # arbitrary text on the same footing as `$cherry`, routed through the same
330
- # jfield/jstr escaping the paragraph above already covers.
315
+ # Arbitrary text reaches this function by many routes, and what follows names
316
+ # the kinds of it, not every caller: branch names; worktree paths; git's own
317
+ # stderr, surfaced through `gp_why` with no argument, which reads `$gp_err`;
318
+ # grep's own stderr, through `gp_why "$gq_err"`; the error text of `git
319
+ # worktree remove`, `git update-ref` and `git config --remove-section`; and
320
+ # scan output such as `$cherry` and the `$ignored` listing. Most of it arrives
321
+ # inside a `keep` message, through `keep`'s own `jfield "$1"` / `jfield "$2"`;
322
+ # the `reaped`, `removed` and `warnings` accumulators call `jfield` directly
323
+ # and never route through `keep` at all. The branch name is the demonstrated
324
+ # trigger — `git branch 'has"quote'` is a legal refname — and raw it emitted a
325
+ # payload no parser accepts at exit 0, while the branch was correctly kept.
326
+ # The stderr lines stay raw: they are prose for an operator, not JSON.
331
327
  jfield() {
332
328
  if jf=$(jstr "$1"); then
333
329
  printf '"%s"' "$jf"
@@ -67,6 +67,7 @@ import { fileURLToPath } from "node:url";
67
67
  import { makeDie, writeAll, isDigits } from "./arg.mjs";
68
68
  import { gitEnv } from "./git-env.mjs";
69
69
  import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
70
+ import { premisesOf } from "./ledger-grammar.mjs";
70
71
 
71
72
  const NAME = "shortlist";
72
73
  const die = makeDie(NAME);
@@ -196,17 +197,6 @@ function ledgerRows() {
196
197
  return data.rows;
197
198
  }
198
199
 
199
- // A ticket row is `#N <text>`; it is an exclusion when `excluded` is the text's
200
- // first word — `impl-N · … excluded …` is a row about something else. Answers
201
- // the premises the row names, possibly none, or null for any other row.
202
- const EXCLUDED_ROW = /^#[0-9]+[ \t]+excluded(?=[ \t]|$)([\s\S]*)$/;
203
- const PREMISE = /\bbehind-(pr|issue):#?([^\s,;]+)/g;
204
- function premisesOf(row) {
205
- const m = EXCLUDED_ROW.exec(row);
206
- if (!m) return null;
207
- return [...m[1].matchAll(PREMISE)].map(([, kind, target]) => ({ kind, target }));
208
- }
209
-
210
200
  // gh takes a `-`-led argument as a flag, and `gh issue view` takes a number.
211
201
  const askable = ({ kind, target }) => !target.startsWith("-") && (kind === "pr" || isDigits(target));
212
202
  const premiseKey = ({ kind, target }) => `${kind} ${target}`;