@feigi/fleet-ctl 0.0.0 → 3.16.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.
Files changed (152) hide show
  1. package/agents/{fleet-implementer.agent.md → fleet-implementer-slow-high.agent.md} +23 -2
  2. package/agents/fleet-implementer-slow-medium.agent.md +231 -0
  3. package/agents/fleet-implementer-smol-high.agent.md +231 -0
  4. package/agents/{fleet-implementer-alt.agent.md → fleet-implementer-task-high.agent.md} +23 -2
  5. package/agents/fleet-implementer-task-max.agent.md +231 -0
  6. package/agents/fleet-review-comments.agent.md +4 -2
  7. package/agents/fleet-review-correctness.agent.md +2 -1
  8. package/agents/fleet-review-runner.agent.md +14 -10
  9. package/agents/fleet-review-silent-failure.agent.md +4 -3
  10. package/agents/fleet-review-simplify.agent.md +2 -1
  11. package/agents/fleet-review-snapshot.agent.md +2 -1
  12. package/agents/fleet-review-test-run.agent.md +29 -0
  13. package/agents/fleet-review-tests.agent.md +10 -5
  14. package/agents/fleet-review-types.agent.md +4 -2
  15. package/agents/fleet-review-verifier.agent.md +4 -3
  16. package/commands/review-and-fix.md +7 -6
  17. package/commands/run-merge-bot.md +14 -4
  18. package/package.json +4 -2
  19. package/scripts/agent-test.test.mjs +36 -32
  20. package/scripts/ambient-git-vars-mjs-prose.test.mjs +23 -13
  21. package/scripts/apply-ruleset.test.mjs +4 -3
  22. package/scripts/arg-header-probes-prose.test.mjs +1 -0
  23. package/scripts/arg.test.mjs +18 -18
  24. package/scripts/board-cli.test.mjs +18 -21
  25. package/scripts/board-identity.test.mjs +9 -9
  26. package/scripts/board-liveness-banner.test.mjs +6 -6
  27. package/scripts/board-prev-shape.test.mjs +12 -13
  28. package/scripts/board-tryparse-null.test.mjs +7 -7
  29. package/scripts/board.mjs +4 -7
  30. package/scripts/board.test.mjs +57 -61
  31. package/scripts/candidates.test.mjs +228 -17
  32. package/scripts/ci-completes-premise-prose.test.mjs +1 -1
  33. package/scripts/ci-state-prose.test.mjs +2 -2
  34. package/scripts/ci-state.mjs +389 -187
  35. package/scripts/ci-state.test.mjs +458 -165
  36. package/scripts/claim-lifecycle.test.mjs +2 -1
  37. package/scripts/claim-ticket.test.mjs +35 -34
  38. package/scripts/closing-keyword-prose.test.mjs +1 -1
  39. package/scripts/cockpit-tick-nonblocking.test.mjs +8 -8
  40. package/scripts/compute-board.mjs +13 -3
  41. package/scripts/compute-board.test.mjs +64 -1
  42. package/scripts/compute-spend.mjs +46 -8
  43. package/scripts/compute-spend.test.mjs +64 -10
  44. package/scripts/cross-repo-citation-prose.test.mjs +18 -19
  45. package/scripts/delete-merged-branch.sh +218 -0
  46. package/scripts/delete-merged-branch.test.mjs +576 -0
  47. package/scripts/derive-testcmd.sh +18 -7
  48. package/scripts/derive-testcmd.test.mjs +9 -8
  49. package/scripts/diff-stats.mjs +2 -2
  50. package/scripts/diff-stats.test.mjs +7 -11
  51. package/scripts/dispatch-block-golden-prose.test.mjs +111 -6
  52. package/scripts/dispatch-block-pins-prose.test.mjs +5 -5
  53. package/scripts/dispositions-check.mjs +507 -0
  54. package/scripts/dispositions-check.test.mjs +843 -0
  55. package/scripts/dispositions-gate-prose.test.mjs +114 -0
  56. package/scripts/drop-merged-label.test.mjs +3 -4
  57. package/scripts/exec-stub.mjs +93 -0
  58. package/scripts/exec-stub.test.mjs +69 -0
  59. package/scripts/filing-bar-seat-prose.test.mjs +1 -1
  60. package/scripts/finisher-test-verdict-prose.test.mjs +102 -0
  61. package/scripts/fix-applier-correction-rules-prose.test.mjs +11 -10
  62. package/scripts/fleet-bootstrap +5 -20
  63. package/scripts/fleet-bootstrap.test.mjs +75 -0
  64. package/scripts/fleet-heartbeat.mjs +2 -2
  65. package/scripts/fleet-provenance +15 -24
  66. package/scripts/fleet-provenance.test.mjs +86 -12
  67. package/scripts/fleet-run.test.mjs +5 -5
  68. package/scripts/fleet-state.mjs +33 -11
  69. package/scripts/fleet-state.test.mjs +90 -3
  70. package/scripts/fleet-tick.mjs +346 -70
  71. package/scripts/fleet-tick.test.mjs +566 -16
  72. package/scripts/force-with-lease-reason-prose.test.mjs +1 -1
  73. package/scripts/frontmatter-check.mjs +3 -2
  74. package/scripts/frontmatter-check.test.mjs +6 -6
  75. package/scripts/immutable-body-claim-prose.test.mjs +53 -262
  76. package/scripts/implementer-model-tier.test.mjs +98 -506
  77. package/scripts/inflight.test.mjs +18 -127
  78. package/scripts/is-cli.mjs +26 -0
  79. package/scripts/is-cli.test.mjs +99 -0
  80. package/scripts/json.test.mjs +3 -3
  81. package/scripts/ledger-dispatch.test.mjs +368 -7
  82. package/scripts/ledger-grammar.mjs +85 -1
  83. package/scripts/ledger-grammar.test.mjs +86 -1
  84. package/scripts/ledger-read-require-file.test.mjs +7 -7
  85. package/scripts/ledger-rotate.test.mjs +142 -0
  86. package/scripts/ledger.mjs +181 -17
  87. package/scripts/ledger.test.mjs +12 -130
  88. package/scripts/main-checkout.mjs +312 -0
  89. package/scripts/main-checkout.test.mjs +332 -0
  90. package/scripts/member-outcomes-header.test.mjs +3 -3
  91. package/scripts/member-outcomes.mjs +4 -5
  92. package/scripts/member-outcomes.test.mjs +92 -18
  93. package/scripts/member-prompt-prose.test.mjs +17 -13
  94. package/scripts/member-record.mjs +8 -3
  95. package/scripts/member-record.test.mjs +5 -5
  96. package/scripts/member-write-guard.mjs +5 -5
  97. package/scripts/member-write-guard.test.mjs +6 -3
  98. package/scripts/no-undo-audit.sh +24 -21
  99. package/scripts/no-undo-audit.test.mjs +9 -13
  100. package/scripts/pointer-target-prose.test.mjs +1 -1
  101. package/scripts/pr-overlap.test.mjs +6 -9
  102. package/scripts/prompt-renderer.mjs +10 -9
  103. package/scripts/prose-pin.mjs +10 -11
  104. package/scripts/prove-merge.test.mjs +3 -3
  105. package/scripts/quiet-payload-prose.test.mjs +1 -1
  106. package/scripts/reap.test.mjs +3 -4
  107. package/scripts/release-label-split-prose.test.mjs +17 -2
  108. package/scripts/release-ticket.test.mjs +35 -44
  109. package/scripts/review-core-cwd-isolation.test.mjs +7 -6
  110. package/scripts/review-core-reads.test.mjs +1 -1
  111. package/scripts/review-core-scratch-refusal.test.mjs +64 -0
  112. package/scripts/review-core-shared-test-run.test.mjs +238 -0
  113. package/scripts/review-core-snapshot-path.test.mjs +59 -12
  114. package/scripts/review-core-specialist-scratch.test.mjs +12 -10
  115. package/scripts/review-core-testcmd.test.mjs +76 -45
  116. package/scripts/review-core-unrun.test.mjs +154 -168
  117. package/scripts/review-core.mjs +250 -56
  118. package/scripts/review-eval.mjs +11 -4
  119. package/scripts/review-host-fixture.mjs +12 -3
  120. package/scripts/review-in-run-retry.test.mjs +27 -3
  121. package/scripts/review-runner-spawns.test.mjs +5 -3
  122. package/scripts/review-runner.test.mjs +14 -3
  123. package/scripts/review-tier-audit.test.mjs +1 -1
  124. package/scripts/run-merge-bot-prose.test.mjs +29 -6
  125. package/scripts/scratch-partition-invariant-prose.test.mjs +1 -1
  126. package/scripts/section-between-guard-prose.test.mjs +4 -3
  127. package/scripts/select-dimensions.test.mjs +1 -1
  128. package/scripts/shell-traps-prose.test.mjs +6 -9
  129. package/scripts/shortlist.mjs +4 -1
  130. package/scripts/shortlist.test.mjs +30 -16
  131. package/scripts/snapshot-repo.test.mjs +177 -4
  132. package/scripts/stash-prohibition-prose.test.mjs +1 -1
  133. package/scripts/temp-dir.mjs +47 -0
  134. package/scripts/tier-check.mjs +95 -28
  135. package/scripts/tier-check.test.mjs +131 -29
  136. package/scripts/tier-outcomes-header.test.mjs +11 -54
  137. package/scripts/tier-outcomes.mjs +34 -12
  138. package/scripts/tier-outcomes.test.mjs +157 -4
  139. package/scripts/tier-roles.mjs +118 -29
  140. package/scripts/tier-roles.test.mjs +226 -61
  141. package/scripts/tracker-block-copy-prose.test.mjs +3 -3
  142. package/scripts/verify-sha.test.mjs +4 -5
  143. package/scripts/watcher-degraded-block.test.mjs +5 -8
  144. package/scripts/within-run-pair-prose.test.mjs +43 -75
  145. package/scripts/worktree-audit.test.mjs +2 -1
  146. package/skills/next-ticket/SKILL.md +2 -2
  147. package/skills/run-team/SKILL.md +433 -303
  148. package/skills/run-team/references/ci-and-staleness.md +7 -6
  149. package/skills/run-team/references/correction-tickets.md +3 -3
  150. package/skills/run-team/references/isolation.md +1 -1
  151. package/skills/sizing-a-ticket/SKILL.md +8 -8
  152. package/scripts/tier-guard-gate-prose.test.mjs +0 -216
@@ -57,7 +57,7 @@ function fixture(t, body = null) {
57
57
  test("dispatch appends a live member row and records the dispatch in ## Dispatched", (t) => {
58
58
  const { ok, read, bytes } = fixture(t);
59
59
  assert.deepEqual(ok("dispatch", "412", "impl-412"), {
60
- member: "impl-412", ticket: "#412", line: "#412 impl-412", created: true, total: 1,
60
+ member: "impl-412", agent: "fleet-implementer-slow-high", ticket: "#412", line: "#412 impl-412", created: true, total: 1,
61
61
  });
62
62
  const l = read();
63
63
  assert.deepEqual(l.rows, ["#412 impl-412"]);
@@ -73,7 +73,7 @@ test("dispatch keeps an existing row's text, appending the token only where it i
73
73
  ok("row", "412", "impl-412 · class=routine");
74
74
  ok("row", "415", "claimed · class=correction");
75
75
  assert.deepEqual(ok("dispatch", "412", "impl-412"), {
76
- member: "impl-412", ticket: "#412", line: "#412 impl-412 · class=routine", created: false, total: 1,
76
+ member: "impl-412", agent: "fleet-implementer-slow-high", ticket: "#412", line: "#412 impl-412 · class=routine", created: false, total: 1,
77
77
  });
78
78
  assert.equal(ok("dispatch", "#415", "impl-415").line, "#415 claimed · class=correction · impl-415");
79
79
  assert.deepEqual(read().dispatched, ["impl-412", "impl-415"]);
@@ -85,7 +85,7 @@ test("a PR-bound member lands on the row carrying its PR, named by PR or by tick
85
85
  ok("settle", "impl-324", "PR#346");
86
86
  // By the PR number: found through the implementer's own settled token.
87
87
  assert.deepEqual(ok("dispatch", "346", "fix-pr-346"), {
88
- member: "fix-pr-346", ticket: "#324", line: "#324 impl-324=PR#346 · fix-pr-346", created: false, total: 2,
88
+ member: "fix-pr-346", agent: null, ticket: "#324", line: "#324 impl-324=PR#346 · fix-pr-346", created: false, total: 2,
89
89
  });
90
90
  // By the ticket number whose row carries that PR.
91
91
  assert.equal(ok("dispatch", "324", "finisher-pr-346").line, "#324 impl-324=PR#346 · fix-pr-346 · finisher-pr-346");
@@ -94,7 +94,7 @@ test("a PR-bound member lands on the row carrying its PR, named by PR or by tick
94
94
  assert.equal(ok("dispatch", "350", "fix-pr-350").ticket, "#330");
95
95
  // A PR no row carries gets a row of its own.
96
96
  assert.deepEqual(ok("dispatch", "777", "fix-pr-777"), {
97
- member: "fix-pr-777", ticket: "#777", line: "#777 fix-pr-777", created: true, total: 5,
97
+ member: "fix-pr-777", agent: null, ticket: "#777", line: "#777 fix-pr-777", created: true, total: 5,
98
98
  });
99
99
  assert.equal(read().rows.length, 3);
100
100
  });
@@ -132,7 +132,7 @@ test("a member is dispatched once; its replacement takes a name of its own", (t)
132
132
 
133
133
  test("merge-bot-<n> counts the ## Dispatched merge-bot entries, and a new ledger starts again at 1", (t) => {
134
134
  const { ok, read, refused } = fixture(t);
135
- assert.deepEqual(ok("dispatch", "merge-bot"), { member: "merge-bot-1", ticket: null, line: null, created: false, total: 1 });
135
+ assert.deepEqual(ok("dispatch", "merge-bot"), { member: "merge-bot-1", agent: "fleet-merge-bot", ticket: null, line: null, created: false, total: 1 });
136
136
  ok("dispatch", "412", "impl-412");
137
137
  ok("settle", "merge-bot-1", "done");
138
138
  // A settled bot still counts: its replacement gets a new n.
@@ -149,6 +149,135 @@ test("merge-bot-<n> counts the ## Dispatched merge-bot entries, and a new ledger
149
149
  assert.equal(fresh.ok("dispatch", "merge-bot").member, "merge-bot-1");
150
150
  });
151
151
 
152
+ // #2208: the controller names the `task` call's `agent` off this output, not
153
+ // off prose a compaction drops — so every family's definition is printed, and
154
+ // an implementer's follows its row's `tier=` the way tier-check.mjs reads it:
155
+ // none is the policy cell, `slow-high`.
156
+ test("dispatch prints the agent definition the call names: the row's tier for an implementer, fixed for finisher and merge bot, null for a review fix-applier", (t) => {
157
+ const { ok } = fixture(t);
158
+ assert.equal(ok("dispatch", "7", "impl-7").agent, "fleet-implementer-slow-high");
159
+ ok("row", "8", "impl-8 · class=routine · tier=task-high");
160
+ assert.equal(ok("dispatch", "8", "impl-8").agent, "fleet-implementer-task-high");
161
+ // A replacement inherits the row's tier, because it reads the same row.
162
+ ok("settle", "impl-8", "killed");
163
+ assert.equal(ok("dispatch", "8", "impl-8-b").agent, "fleet-implementer-task-high");
164
+ // Neither verdict token is a `tier=` token.
165
+ ok("row", "10", "impl-10 · tier-ok=impl-10:fleet-implementer-task-high · tier-mismatch=impl-10:fleet-implementer-task-high");
166
+ assert.equal(ok("dispatch", "10", "impl-10").agent, "fleet-implementer-slow-high");
167
+ ok("settle", "impl-7", "PR#70");
168
+ assert.equal(ok("dispatch", "70", "finisher-pr-70").agent, "fleet-finisher");
169
+ assert.equal(ok("dispatch", "70", "fix-pr-70").agent, null);
170
+ assert.equal(ok("dispatch", "merge-bot").agent, "fleet-merge-bot");
171
+ });
172
+
173
+ // A `tier=` of the right shape whose definition has no file is refused the
174
+ // same way: a `task` call naming it cannot resolve. Two of those: a cell
175
+ // outside the shipped grid (`smol-max` — haiku has no `max`), and the
176
+ // pre-cell `alt` whose definition #2129 deleted.
177
+ test("dispatch refuses an implementer whose row names no single definition, or one with no file, before marking it live", (t) => {
178
+ const { ok, read, refused } = fixture(t);
179
+ ok("row", "7", "class=routine · tier=alt · tier=slow-high");
180
+ refused(["dispatch", "7", "impl-7"], /impl-7: row carries conflicting tier= tokens \(tier=alt, tier=slow-high\) — fix the row with `ledger\.mjs row` — not dispatching impl-7/);
181
+ ok("row", "8", "class=routine · tier=../../etc");
182
+ refused(["dispatch", "8", "impl-8"], /impl-8: tier=\.\.\/\.\.\/etc is not a definition suffix — expected \[a-z0-9\] words joined by '-' — fix the row with `ledger\.mjs row` — not dispatching impl-8/);
183
+ ok("row", "9", "class=routine · tier=");
184
+ refused(["dispatch", "9", "impl-9"], /impl-9: tier= is not a definition suffix/);
185
+ ok("row", "10", "class=routine · tier=smol-max");
186
+ refused(["dispatch", "10", "impl-10"], /impl-10: row #10's tier= names fleet-implementer-smol-max, which has no agents\/fleet-implementer-smol-max\.agent\.md — fix the row with `ledger\.mjs row` — not dispatching impl-10/);
187
+ ok("row", "11", "class=routine · tier=alt");
188
+ refused(["dispatch", "11", "impl-11"], /impl-11: row #11's tier= names fleet-implementer-alt, which has no agents\/fleet-implementer-alt\.agent\.md/);
189
+ assert.deepEqual(read().dispatched, []);
190
+ });
191
+
192
+ // The refusal is about the implementer's own definition: a member whose
193
+ // definition does not come off `tier=` must still be dispatchable on such a
194
+ // row, or one bad token would strand the PR's finisher and fix-applier.
195
+ test("a malformed tier= on a row does not refuse a member whose definition ignores it", (t) => {
196
+ const { ok } = fixture(t);
197
+ ok("row", "7", "impl-7=PR#70 · tier=alt · tier=slow-high");
198
+ assert.equal(ok("dispatch", "70", "fix-pr-70").agent, null);
199
+ assert.equal(ok("dispatch", "7", "finisher-pr-70").agent, "fleet-finisher");
200
+ });
201
+
202
+ // #2299: a fix-applier dispatched on merge-bot's conflict hold is a
203
+ // `fleet-implementer-slow-high` (the policy cell) whatever the row's tier,
204
+ // named off `dispatch`'s output like every other member. A review
205
+ // fix-applier stays a generic `task` — including on a row whose hold a
206
+ // fix-applier has already cleared.
207
+ test("dispatch names a fix-applier on an unresolved conflict hold of its own PR the policy cell's implementer, whatever the row's tier or the hold's spelling", (t) => {
208
+ const { ok } = fixture(t);
209
+ ok("row", "20", "impl-20=PR#21 · conflict-hold:#21");
210
+ assert.equal(ok("dispatch", "21", "fix-pr-21").agent, "fleet-implementer-slow-high");
211
+ // A failed one leaves the hold unresolved, so its replacement is one too.
212
+ ok("settle", "fix-pr-21", "failed");
213
+ assert.equal(ok("dispatch", "21", "fix-pr-21-b").agent, "fleet-implementer-slow-high");
214
+
215
+ // `tier=` is not consulted — conflicting values neither change nor refuse it.
216
+ ok("row", "50", "impl-50=PR#51 · tier=task-high · conflict-hold:#51");
217
+ assert.equal(ok("dispatch", "51", "fix-pr-51").agent, "fleet-implementer-slow-high");
218
+ ok("row", "60", "impl-60=PR#61 · tier=alt · tier=slow-high · conflict-hold:#61");
219
+ assert.equal(ok("dispatch", "61", "fix-pr-61").agent, "fleet-implementer-slow-high");
220
+
221
+ // The hold's other spelling the tick reads (fleet-tick.mjs's CONFLICT_HOLD).
222
+ ok("row", "70", "impl-70=PR#71 · conflict-hold-71");
223
+ assert.equal(ok("dispatch", "71", "fix-pr-71").agent, "fleet-implementer-slow-high");
224
+ });
225
+
226
+ test("dispatch names a review fix-applier null, including after a hold a fix-applier settled, until a fresh hold", (t) => {
227
+ const { ok } = fixture(t);
228
+ ok("row", "30", "impl-30=PR#31");
229
+ assert.equal(ok("dispatch", "31", "fix-pr-31").agent, null);
230
+
231
+ // A hold a fix-applier settled `applied:`/`no-op` after is cleared: the
232
+ // row's next fix-applier works a review's survivors.
233
+ ok("row", "80", "impl-80=PR#81 · conflict-hold:#81 · fix-pr-81=applied:def5678 · reviewed=abc1234:1/0/0");
234
+ assert.equal(ok("dispatch", "81", "fix-pr-81-b").agent, null);
235
+ ok("row", "90", "impl-90=PR#91 · conflict-hold:#91 · fix-pr-91=no-op");
236
+ assert.equal(ok("dispatch", "91", "fix-pr-91-b").agent, null);
237
+ // ...until a fresh hold after that settle.
238
+ ok("row", "100", "impl-100=PR#101 · fix-pr-101=applied:73b356de · conflict-hold:#101");
239
+ assert.equal(ok("dispatch", "101", "fix-pr-101-b").agent, "fleet-implementer-slow-high");
240
+ });
241
+
242
+ // The hold is the tick's reading, so a ledger the tick refuses — here a hold
243
+ // recorded on another PR's row — names no definition: dispatch refuses before
244
+ // the member is live, rather than reading one row the tick would throw on.
245
+ test("dispatch refuses a fix-applier on a ledger the tick refuses, before marking it live", (t) => {
246
+ const { ok, read, refused } = fixture(t);
247
+ ok("row", "40", "impl-40=PR#41 · conflict-hold:#42");
248
+ refused(["dispatch", "41", "fix-pr-41"], /'conflict-hold:#42' names PR #42, but this row is PR #41's .* — fleet-tick\.mjs refuses this ledger, so fix-pr-41's definition cannot be read off it/);
249
+ assert.deepEqual(read().dispatched, []);
250
+ // A finisher's dispositions gate reads the same fold, so it is refused too,
251
+ // naming the ledger as the cause rather than reading an unreadable verdict.
252
+ refused(["dispatch", "41", "finisher-pr-41"], /— fleet-tick\.mjs refuses this ledger, so finisher-pr-41's dispositions verdict cannot be read off it/);
253
+ assert.deepEqual(read().dispatched, []);
254
+ });
255
+
256
+ // A PR's tokens can sit on two rows — its ticket's, and a `#<pr>` row `row`
257
+ // keyed by the PR's own number (#2283). The tick folds both into one state per
258
+ // PR; dispatch must name the fix-applier off that same state, so the two
259
+ // readers agree whichever row carries the hold or the settle that clears it.
260
+ test("dispatch reads a fix-applier's conflict hold off the PR's merged state, agreeing with the tick", (t) => {
261
+ const { ok, read } = fixture(t);
262
+ const agrees = (key, member, expected) => {
263
+ const l = read();
264
+ const tickHeld = deriveRun({ rows: l.rows, dispatched: l.dispatched, drain: null }, []).conflictHeld.includes(Number(key));
265
+ const { agent } = ok("dispatch", key, member);
266
+ assert.equal(agent, expected, `${member} on ${JSON.stringify(l.rows)}`);
267
+ assert.equal(agent, tickHeld ? "fleet-implementer-slow-high" : null, `${member}: dispatch and the tick disagree`);
268
+ };
269
+
270
+ // The hold on the PR's own row, the ticket row first and holding none.
271
+ ok("row", "20", "impl-20=PR#21");
272
+ ok("row", "21", "conflict-hold:#21");
273
+ agrees("21", "fix-pr-21", "fleet-implementer-slow-high");
274
+
275
+ // The hold on the ticket row, cleared by a settle on the PR's own row.
276
+ ok("row", "30", "impl-30=PR#31 · conflict-hold:#31");
277
+ ok("row", "31", "fix-pr-31=applied:abc1234 · reviewed=def5678:2/0/0");
278
+ agrees("31", "fix-pr-31-b", null);
279
+ });
280
+
152
281
  test("settle rewrites the member's token in its row and in ## Dispatched, and nothing else", (t) => {
153
282
  const { ok, read } = fixture(t);
154
283
  ok("row", "412", "impl-412 · class=routine · ports=16412");
@@ -265,12 +394,57 @@ test("row still writes well-formed member tokens and non-member keys", (t) => {
265
394
  assert.deepEqual(read().rows, rows.map(([n, text]) => `#${n} ${text}`));
266
395
  });
267
396
 
397
+ // #2331: `label-off=<attempt>` marks the controller's own removal of
398
+ // `ready-to-merge`, so the tick does not read it as a finisher's miss. One
399
+ // naming no finisher this run ever had would hide a real miss behind a record
400
+ // of nothing, so `row` refuses it — locally, off `## Dispatched` and the rows'
401
+ // member tokens, the same two places dispatch's live-sibling check reads.
402
+ test("row refuses a label-off naming no finisher this run has, writing nothing", (t) => {
403
+ const { ok, read, refused } = fixture(t);
404
+ ok("dispatch", "10", "impl-10");
405
+ ok("settle", "impl-10", "PR#40");
406
+ ok("dispatch", "40", "finisher-pr-40");
407
+ const before = read().rows;
408
+ for (const [tok, why] of [
409
+ ["label-off=finisher-pr-40-b", /'label-off=finisher-pr-40-b' names no finisher-pr member/], // never dispatched
410
+ ["label-off=finisher-pr-41", /'label-off=finisher-pr-41'/], // another PR's, never dispatched
411
+ ["label-off=impl-10", /'label-off=impl-10' names no finisher-pr member/], // a member, not a finisher
412
+ ["label-off=finisher-pr-40=labelled", /'label-off=finisher-pr-40=labelled'/], // a token, not a name
413
+ ["label-off=", /'label-off='/],
414
+ ]) {
415
+ refused(["row", "10", `impl-10=PR#40 → PR#40 · finisher-pr-40 ${tok}`], why);
416
+ }
417
+ // The new line's own copy of a name does not vouch for it.
418
+ refused(["row", "10", "impl-10=PR#40 → PR#40 · finisher-pr-40-c=labelled label-off=finisher-pr-40-c"], /'label-off=finisher-pr-40-c'/);
419
+ assert.deepEqual(read().rows, before);
420
+ });
421
+
422
+ test("row accepts a label-off naming a finisher in ## Dispatched or on any row, settled or live", (t) => {
423
+ const { ok, read } = fixture(t);
424
+ ok("dispatch", "10", "impl-10");
425
+ ok("settle", "impl-10", "PR#40");
426
+ ok("dispatch", "40", "finisher-pr-40");
427
+ ok("settle", "finisher-pr-40", "labelled");
428
+ // Only in `## Dispatched`: a whole-line rewrite dropped the settled token
429
+ // from the row first, so no row names the attempt any more.
430
+ ok("row", "10", "impl-10=PR#40 → PR#40");
431
+ ok("row", "10", "impl-10=PR#40 → PR#40 label-off=finisher-pr-40");
432
+ // Only on a row — a token `row` wrote never enters `## Dispatched`.
433
+ ok("row", "50", "finisher-pr-50");
434
+ ok("row", "50", "finisher-pr-50 label-off=finisher-pr-50");
435
+ assert.deepEqual(read().rows, [
436
+ "#10 impl-10=PR#40 → PR#40 label-off=finisher-pr-40",
437
+ "#50 finisher-pr-50 label-off=finisher-pr-50",
438
+ ]);
439
+ assert.deepEqual(read().dispatched, ["impl-10=PR#40", "finisher-pr-40=labelled"]);
440
+ });
441
+
268
442
  // #1876: the tick owes an open PR a review while its implementer is still
269
443
  // live, so a PR-bound member can be dispatched before `settle impl-N=PR#M`
270
444
  // names the PR on the ticket row. dispatch's fallback then keys a row of its
271
445
  // own to the PR — truthful until the settle, when two rows would name one PR:
272
- // the cockpit drew two REVIEW cards and the tick's first-row-wins `byPr` lost
273
- // the live review. The settle folds the PR-keyed row into the ticket row.
446
+ // the cockpit drew two REVIEW cards and the tick's `byPr`, first-row-wins until
447
+ // #2283, lost the live review. The settle folds the PR-keyed row into the ticket row.
274
448
  test("settle impl-N=PR#M folds the PR-keyed row a pre-settle dispatch created into the ticket row", (t) => {
275
449
  const { ok, read } = fixture(t);
276
450
  ok("dispatch", "1300", "impl-1300");
@@ -331,6 +505,27 @@ test("a conflict hold written by row is cleared by a later dispatch + settle, in
331
505
  assert.deepEqual([tick().fixDue, tick().mergeHeld], [[], 0]);
332
506
  });
333
507
 
508
+ // #2328: the conflict fix-applier rebases without the review file, so once it
509
+ // lands the PR's unanswered survivors come back due — and `dispatch` names
510
+ // their fix-applier a review one, off the same tick state.
511
+ test("a review's survivors outlive a conflict fix-applier's settle: the next fix-applier is a review one", (t) => {
512
+ const { ok, read } = fixture(t);
513
+ ok("row", "20", "impl-20=PR#21 · reviewed=abc1234:2/0/0 · conflict-hold:#21");
514
+ const tick = () => {
515
+ const l = read();
516
+ return deriveRun({ rows: l.rows, dispatched: l.dispatched, drain: null },
517
+ [{ number: 21, labels: [], closingIssuesReferences: [{ number: 20 }] }]);
518
+ };
519
+ assert.deepEqual([tick().fixDue, tick().conflictHeld], [[21], [21]]);
520
+ assert.equal(ok("dispatch", "21", "fix-pr-21").agent, "fleet-implementer-slow-high");
521
+ assert.deepEqual(tick().fixDue, [], "one fix-applier at a time");
522
+ ok("settle", "fix-pr-21", "applied:def5678");
523
+ assert.deepEqual([tick().fixDue, tick().conflictHeld], [[21], []], "the survivors it never read are due again");
524
+ assert.equal(ok("dispatch", "21", "fix-pr-21-b").agent, null);
525
+ ok("settle", "fix-pr-21-b", "applied:0123abc");
526
+ assert.deepEqual(tick().fixDue, []);
527
+ });
528
+
334
529
  test("the fold takes the PR row's settled tokens in order, under the two-argument spelling, wherever the PR row sits", (t) => {
335
530
  const { ok, read } = fixture(t);
336
531
  // The PR's row comes first here, and a third row follows the ticket's.
@@ -514,3 +709,169 @@ test("a ledger carrying two `## Drain` entries refuses to load rather than silen
514
709
  const { refused } = fixture(t, body);
515
710
  refused(["read"], /has 2 `## Drain` entries — one marker per run/);
516
711
  });
712
+
713
+ // The dispositions gate. A finisher labels a PR `ready-to-merge`, so it is
714
+ // recorded only once the PR's current dispositions verdict is ok: among the
715
+ // `dispositions-*=fix-pr-<M>[-x]:<head>` tokens whose head prefix-matches the
716
+ // latest `reviewed=<head>`, the one from the highest-suffixed fix-applier.
717
+ // A refusal is exit 2 and writes nothing — the `refused` helper checks both.
718
+ const GATE_HEAD = `${"abc1234".repeat(5)}abcde`;
719
+ const OTHER_HEAD = `${"def5678".repeat(5)}defab`;
720
+ const gateRow = (counts, ...tokens) =>
721
+ ["impl-10=PR#40 → PR#40", `reviewed=${GATE_HEAD.slice(0, 7)}:${counts}`, "fix-pr-40=applied:def5678", ...tokens].join(" · ");
722
+
723
+ test("a finisher is refused on a dispositions mismatch and recorded on a dispositions ok", (t) => {
724
+ const { ok, read, refused } = fixture(t);
725
+ ok("row", "10", gateRow("1/0/0", `dispositions-mismatch=fix-pr-40:${GATE_HEAD}`));
726
+ refused(["dispatch", "40", "finisher-pr-40"],
727
+ /finisher-pr-40: dispositions mismatch — fix-pr-40's disposition record .*dispositions-check\.mjs/);
728
+ assert.deepEqual(read().dispatched, []);
729
+
730
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${GATE_HEAD}`));
731
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
732
+ assert.deepEqual(read().dispatched, ["finisher-pr-40"]);
733
+ });
734
+
735
+ test("a finisher is refused as unchecked while no verdict answers the latest review's head", (t) => {
736
+ const { ok, refused } = fixture(t);
737
+ const unchecked = /finisher-pr-40: dispositions unchecked — no dispositions-ok=\/dispositions-mismatch=\/dispositions-escalate= token .* run dispositions-check\.mjs --member fix-pr-40/;
738
+ // No token at all.
739
+ ok("row", "10", gateRow("1/0/0"));
740
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
741
+ // An unverified finding alone puts the PR under the gate too.
742
+ ok("row", "10", gateRow("0/2/1"));
743
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
744
+ // An ok answering another head satisfies nothing, wherever it sits on the row.
745
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${OTHER_HEAD}`));
746
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
747
+ ok("row", "10", `impl-10=PR#40 → PR#40 · dispositions-ok=fix-pr-40:${OTHER_HEAD} · reviewed=${GATE_HEAD}:1/0/0`);
748
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
749
+ // An earlier review's ok, answered before a later review returned, does not
750
+ // carry over to the later one.
751
+ ok("row", "10", `impl-10=PR#40 → PR#40 · reviewed=${OTHER_HEAD}:1/0/0 · dispositions-ok=fix-pr-40:${OTHER_HEAD} · reviewed=${GATE_HEAD}:1/0/0`);
752
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
753
+ // Another PR's fix-applier's verdict is no answer for this PR.
754
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-41:${GATE_HEAD}`));
755
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
756
+ });
757
+
758
+ test("a PR whose latest review counts no survived and no unverified finding dispatches a finisher with no verdict", (t) => {
759
+ const { ok, read } = fixture(t);
760
+ ok("row", "10", `impl-10=PR#40 → PR#40 · reviewed=${GATE_HEAD}:0/3/0`);
761
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
762
+ // A PR never reviewed is outside the gate as well: no review file, no record.
763
+ ok("row", "11", "impl-11=PR#41 → PR#41");
764
+ assert.equal(ok("dispatch", "41", "finisher-pr-41").agent, "fleet-finisher");
765
+ assert.deepEqual(read().dispatched, ["finisher-pr-40", "finisher-pr-41"]);
766
+ });
767
+
768
+ test("the current verdict is the highest-suffixed fix-applier's, in either text order", (t) => {
769
+ const { ok, read, refused } = fixture(t);
770
+ const a = `dispositions-mismatch=fix-pr-40:${GATE_HEAD}`;
771
+ const b = `dispositions-ok=fix-pr-40-b:${GATE_HEAD}`;
772
+ for (const [i, tokens] of [[a, b], [b, a]].entries()) {
773
+ ok("row", "10", gateRow("1/0/0", ...tokens));
774
+ assert.equal(ok("dispatch", "40", `finisher-pr-40${i === 0 ? "" : "-b"}`).agent, "fleet-finisher");
775
+ ok("settle", `finisher-pr-40${i === 0 ? "" : "-b"}`, "failed");
776
+ }
777
+ // Swapped between the two members, the -b's mismatch is current.
778
+ const swapped = [`dispositions-ok=fix-pr-40:${GATE_HEAD}`, `dispositions-mismatch=fix-pr-40-b:${GATE_HEAD}`];
779
+ for (const tokens of [swapped, [...swapped].reverse()]) {
780
+ ok("row", "10", gateRow("1/0/0", ...tokens));
781
+ refused(["dispatch", "40", "finisher-pr-40-c"], /finisher-pr-40-c: dispositions mismatch — fix-pr-40-b's disposition record/);
782
+ }
783
+ assert.deepEqual(read().dispatched, ["finisher-pr-40=failed", "finisher-pr-40-b=failed"]);
784
+ });
785
+
786
+ test("a later fix-applier that writes no verdict neither satisfies nor resets the gate", (t) => {
787
+ const { ok, refused } = fixture(t);
788
+ // A conflict-hold fix-applier after the review one: no review file, no token.
789
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${GATE_HEAD}`, "conflict-hold:#40", "fix-pr-40-b=no-op"));
790
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
791
+ ok("row", "11", ["impl-11=PR#41 → PR#41", `reviewed=${GATE_HEAD}:1/0/0`, "fix-pr-41=applied:def5678",
792
+ `dispositions-mismatch=fix-pr-41:${GATE_HEAD}`, "conflict-hold:#41", "fix-pr-41-b=no-op"].join(" · "));
793
+ refused(["dispatch", "41", "finisher-pr-41"], /finisher-pr-41: dispositions mismatch — fix-pr-41's/);
794
+ });
795
+
796
+ test("a finisher is refused on a dispositions escalate, naming it, and nothing retries it", (t) => {
797
+ const { ok, read, refused } = fixture(t);
798
+ ok("row", "10", gateRow("1/0/0", `dispositions-escalate=fix-pr-40:${GATE_HEAD}`));
799
+ refused(["dispatch", "40", "finisher-pr-40"],
800
+ /finisher-pr-40: dispositions escalate — fix-pr-40 deferred .*dispositions-check\.mjs --member fix-pr-40/);
801
+ assert.deepEqual(read().dispatched, []);
802
+ const l = read();
803
+ const run = deriveRun({ rows: l.rows, dispatched: l.dispatched, drain: null },
804
+ [{ number: 40, labels: [], closingIssuesReferences: [{ number: 10 }] }]);
805
+ assert.deepEqual(run.fixDue, [], "an escalation never returns the PR to fixDue");
806
+ assert.deepEqual(run.reviewed.find((r) => r.pr === 40).dispositions, { verdict: "escalate", member: "fix-pr-40" });
807
+ });
808
+
809
+ test("an escalate is the current verdict only until a higher-suffixed fix-applier's own verdict answers the head, and outranks a mismatch of the same member", (t) => {
810
+ const { ok, refused } = fixture(t);
811
+ const esc = `dispositions-escalate=fix-pr-40:${GATE_HEAD}`;
812
+ const okB = `dispositions-ok=fix-pr-40-b:${GATE_HEAD}`;
813
+ for (const [i, tokens] of [[esc, okB], [okB, esc]].entries()) {
814
+ ok("row", "10", gateRow("1/0/0", ...tokens));
815
+ assert.equal(ok("dispatch", "40", `finisher-pr-40${i === 0 ? "" : "-b"}`).agent, "fleet-finisher");
816
+ ok("settle", `finisher-pr-40${i === 0 ? "" : "-b"}`, "failed");
817
+ }
818
+ const swapped = [`dispositions-ok=fix-pr-40:${GATE_HEAD}`, `dispositions-escalate=fix-pr-40-b:${GATE_HEAD}`];
819
+ for (const tokens of [swapped, [...swapped].reverse()]) {
820
+ ok("row", "10", gateRow("1/0/0", ...tokens));
821
+ refused(["dispatch", "40", "finisher-pr-40-c"], /finisher-pr-40-c: dispositions escalate — fix-pr-40-b deferred/);
822
+ }
823
+ ok("row", "10", gateRow("1/0/0", `dispositions-mismatch=fix-pr-40:${GATE_HEAD}`, esc));
824
+ refused(["dispatch", "40", "finisher-pr-40-c"], /dispositions escalate/);
825
+ });
826
+
827
+ test("one fix-applier carrying both verdicts for the same head reads as a mismatch", (t) => {
828
+ const { ok, refused } = fixture(t);
829
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${GATE_HEAD}`, `dispositions-mismatch=fix-pr-40:${GATE_HEAD}`));
830
+ refused(["dispatch", "40", "finisher-pr-40"], /dispositions mismatch/);
831
+ });
832
+
833
+ test("only a fix-applier's well-formed verdict answers the gate: another family's, a short head's or a non-verdict's never does", (t) => {
834
+ const { ok, read, refused } = fixture(t);
835
+ const unchecked = /finisher-pr-40: dispositions unchecked/;
836
+ for (const token of [
837
+ `dispositions-ok=finisher-pr-40:${GATE_HEAD}`, // a finisher writes no disposition record
838
+ `dispositions-ok=impl-10:${GATE_HEAD}`,
839
+ "dispositions-ok=fix-pr-40:abc", // 3 hex: below the 7-hex floor, matches every head starting abc
840
+ `dispositions-maybe=fix-pr-40:${GATE_HEAD}`,
841
+ ]) {
842
+ ok("row", "10", gateRow("1/0/0", token));
843
+ refused(["dispatch", "40", "finisher-pr-40"], unchecked);
844
+ }
845
+ // Case is not a verdict's meaning: an upper-case head and verdict still answer.
846
+ ok("row", "10", gateRow("1/0/0", `DISPOSITIONS-OK=fix-pr-40:${GATE_HEAD.toUpperCase()}`));
847
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
848
+ assert.deepEqual(read().dispatched, ["finisher-pr-40"]);
849
+ });
850
+
851
+ test("a verdict's head and the review's match as prefixes in either direction", (t) => {
852
+ const { ok, refused } = fixture(t);
853
+ // A 7-hex verdict head answers a 40-hex `reviewed=` head …
854
+ ok("row", "10", ["impl-10=PR#40 → PR#40", `reviewed=${GATE_HEAD}:1/0/0`, "fix-pr-40=applied:def5678",
855
+ `dispositions-ok=fix-pr-40:${GATE_HEAD.slice(0, 7)}`].join(" · "));
856
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
857
+ // … and a 7-hex one that is not its prefix does not.
858
+ ok("row", "11", ["impl-11=PR#41 → PR#41", `reviewed=${GATE_HEAD}:1/0/0`, "fix-pr-41=applied:def5678",
859
+ `dispositions-ok=fix-pr-41:${OTHER_HEAD.slice(0, 7)}`].join(" · "));
860
+ refused(["dispatch", "41", "finisher-pr-41"], /finisher-pr-41: dispositions unchecked/);
861
+ });
862
+
863
+ test("a finisher is refused while a fix-applier on the PR is live, even with an earlier ok answering the same head", (t) => {
864
+ const { ok, read, refused } = fixture(t);
865
+ // A re-review at the same head: fix-pr-40 answered the first round, and
866
+ // fix-pr-40-b, answering the second, is still working.
867
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${GATE_HEAD}`, `reviewed=${GATE_HEAD.slice(0, 7)}:3/0/2`, "fix-pr-40-b"));
868
+ refused(["dispatch", "40", "finisher-pr-40"], /finisher-pr-40: fix-pr-40-b still live on PR #40 — .*settle it, run dispositions-check\.mjs for it/);
869
+ // A PR outside the verdict gate is still held while its fix-applier works.
870
+ ok("row", "11", `impl-11=PR#41 → PR#41 · reviewed=${GATE_HEAD}:0/1/0 · fix-pr-41`);
871
+ refused(["dispatch", "41", "finisher-pr-41"], /finisher-pr-41: fix-pr-41 still live on PR #41/);
872
+ // Settled with its own verdict written, the -b's answer is the current one.
873
+ ok("row", "10", gateRow("1/0/0", `dispositions-ok=fix-pr-40:${GATE_HEAD}`, `reviewed=${GATE_HEAD.slice(0, 7)}:3/0/2`,
874
+ "fix-pr-40-b=applied:fedcba9", `dispositions-ok=fix-pr-40-b:${GATE_HEAD}`));
875
+ assert.equal(ok("dispatch", "40", "finisher-pr-40").agent, "fleet-finisher");
876
+ assert.deepEqual(read().dispatched, ["finisher-pr-40"]);
877
+ });
@@ -16,6 +16,8 @@
16
16
  // `review=`/`reviewed=` pair, the `→ PR#M` arrow) is not a member and is left
17
17
  // alone.
18
18
 
19
+ import { createHash } from "node:crypto";
20
+
19
21
  // The outcome vocabulary, verbatim from the spec. A word is matched exactly,
20
22
  // except the three that carry a value, which match OUTCOME_PATTERNS below.
21
23
  const FAMILIES = {
@@ -24,6 +26,9 @@ const FAMILIES = {
24
26
  "finisher-pr": { label: "finisher-pr-M", bound: "pr", outcomes: ["labelled", "failed", "killed", "halted:<cause>"] },
25
27
  "merge-bot": { label: "merge-bot-n", bound: null, outcomes: ["done", "killed"] },
26
28
  };
29
+ // Every family parseMember can yield: MEMBER below is built from this list,
30
+ // so every family it matches has an entry here by construction.
31
+ export const MEMBER_FAMILIES = Object.freeze(Object.keys(FAMILIES));
27
32
  // A finisher halt's causes (#2083): the finisher worked correctly and refused
28
33
  // to label, which `failed` (it crashed or gave up) does not say. `unreadable`,
29
34
  // `missing` and `absent` are duty 1's audit-read halts (#1106).
@@ -39,7 +44,7 @@ const OUTCOME_PATTERNS = {
39
44
  // suffix (`impl-<N>-b` — member-record.mjs has -b, -c and -d observed);
40
45
  // merge bots take none, because a replacement for a dead bot gets a new n.
41
46
  // Attempts on one number order by it: no suffix first, then by letter.
42
- const MEMBER = /^(impl|fix-pr|finisher-pr|merge-bot)-([1-9][0-9]*)(-[a-z])?$/;
47
+ const MEMBER = new RegExp(`^(${MEMBER_FAMILIES.join("|")})-([1-9][0-9]*)(-[a-z])?$`);
43
48
 
44
49
  /** `{name, family, number, retry, bound}` for a member name, else null.
45
50
  * `retry` is the suffix letter (`"b"` for `impl-412-b`), null for none.
@@ -83,3 +88,82 @@ export function memberTokens(text) {
83
88
  export function nextMergeBot(dispatched) {
84
89
  return `merge-bot-${dispatched.map(parseToken).filter((t) => t?.family === "merge-bot").length + 1}`;
85
90
  }
91
+
92
+ // #2030: an implementer cell is `<role>-<level>` — an omp role and a thinking
93
+ // level — and each cell is one definition, `fleet-implementer-<cell>`, whose
94
+ // `model:` is `@<role>:<level>` (spec 2026-09-28 § 2). Nothing is named
95
+ // `fleet-implementer` alone, so CELL_DEF is the whole implementer family:
96
+ // derived from CELL rather than spelled twice, so a level added to one cannot
97
+ // be missing from the other.
98
+ export const CELL = /^(slow|task|smol)-(minimal|low|medium|high|xhigh|max)$/;
99
+ export const CELL_DEF = new RegExp(`^fleet-implementer-${CELL.source.slice(1)}`);
100
+
101
+ // The cell a row with no `tier=` runs at: `policy_cell`, `slow-high` on every
102
+ // Pull until the router (spec § 4) picks one per stratum.
103
+ const POLICY_CELL = "slow-high";
104
+
105
+ // The Exploration Pull's draw (spec § 2): uniform over every cell but
106
+ // `policyCell`, keyed off the row's own `session` and `ticket`, so the draw
107
+ // is reproducible from the row and a re-dispatch of the same ticket in the
108
+ // same session lands on the same cell. No RNG and no seed token. `k` is the
109
+ // 1-based index into the sorted remainder, `K` its size; with every
110
+ // non-default cell withdrawn (`K === 0`) the Pull runs at `policyCell` and
111
+ // `k`/`K` are 0 — the caller writes no draw column then, and there is no
112
+ // `% 0` to take.
113
+ /** @returns {{cell: string|null, k: number, K: number}} */
114
+ export function drawCell({ session, ticket, policyCell, cells }) {
115
+ const E = cells.filter((c) => c !== policyCell).sort();
116
+ const K = E.length;
117
+ if (K === 0) return { cell: policyCell, k: 0, K: 0 };
118
+ const k = 1 + (parseInt(createHash("sha256").update(`${session}\t${ticket}`).digest("hex").slice(0, 8), 16) % K);
119
+ return { cell: E[k - 1], k, K };
120
+ }
121
+
122
+ // #1398: the definition an implementer should run under, off its ticket
123
+ // row's `tier=` token — none means `fleet-implementer-<POLICY_CELL>`,
124
+ // `tier=<x>` means `fleet-implementer-<x>`. The value becomes a file
125
+ // name under `agents/`, so it is held to `[a-z0-9]` words joined by `-`
126
+ // rather than joined into a path as written, and two different `tier=`
127
+ // values on one row name no single definition — refused, never resolved by
128
+ // position. A value with no definition behind it (the retired `tier=alt`) is
129
+ // `ledger.mjs dispatch`'s to refuse: it checks the file exists.
130
+ //
131
+ // Here, not in tier-check.mjs, because two readers must agree on it (#2208):
132
+ // `ledger.mjs dispatch` prints the definition before the call, and
133
+ // tier-check.mjs judges the member against it after. Two copies could name
134
+ // different definitions for one row and fail a dispatch made exactly as
135
+ // printed.
136
+ const TIER_SUFFIX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
137
+ export function expectedDefinition(rowText) {
138
+ const values = [...new Set(String(rowText ?? "").split(/\s+/)
139
+ .filter((t) => t.startsWith("tier=")).map((t) => t.slice("tier=".length)))];
140
+ if (values.length === 0) return `fleet-implementer-${POLICY_CELL}`;
141
+ if (values.length > 1) throw new Error(`row carries conflicting tier= tokens (${values.map((v) => `tier=${v}`).join(", ")}) — fix the row with \`ledger.mjs row\``);
142
+ if (!TIER_SUFFIX.test(values[0])) throw new Error(`tier=${values[0]} is not a definition suffix — expected [a-z0-9] words joined by '-' — fix the row with \`ledger.mjs row\``);
143
+ return `fleet-implementer-${values[0]}`;
144
+ }
145
+
146
+ // The agent definition a member is dispatched as (#2208), for a parsed member
147
+ // and the text of the row it works: `ledger.mjs dispatch` prints it so the
148
+ // `task` call that follows names it off a script's output, not off prose a
149
+ // compaction drops. A fix-applier on an unresolved conflict hold of its own PR
150
+ // is a `fleet-implementer-<POLICY_CELL>` whatever the row's `tier=` (#2299) —
151
+ // it rebases the PR, it does not work a ticket at a tier. Any other fix-applier is a review
152
+ // one and gets null: a generic `task` by design. Whether the hold is
153
+ // unresolved is `conflictHeld`, the caller's to supply from fleet-tick.mjs's
154
+ // deriveRun() — the reading the tick holds the merge on, which folds every
155
+ // row of the PR, never one row's text alone. Throws whatever
156
+ // expectedDefinition throws, and on a family this switch has no case for
157
+ // (#2330): null is the review fix-applier's deliberate answer, so a
158
+ // `default: return null` would print a new family as a generic `task`
159
+ // without anyone having decided it is one.
160
+ /** @returns {string|null} the definition name; null only for a review fix-applier. */
161
+ export function agentDefinition(member, rowText, conflictHeld = false) {
162
+ switch (member.family) {
163
+ case "impl": return expectedDefinition(rowText);
164
+ case "fix-pr": return conflictHeld ? `fleet-implementer-${POLICY_CELL}` : null;
165
+ case "finisher-pr": return "fleet-finisher";
166
+ case "merge-bot": return "fleet-merge-bot";
167
+ default: throw new Error(`agentDefinition has no case for member family '${member.family}' (${member.name}) — add one to ledger-grammar.mjs`);
168
+ }
169
+ }