From 8d4cf1cc86f8e025ea70bd3d4b708779df5fc2d2 Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Sun, 15 Nov 2026 14:59:18 -0600 Subject: [PATCH 1/5] Bench: pick Ship all's cards and read the steward's check The logic under the steward digest's Ship all (design: Desktop/Buzz/ steward-digest-ship-all-design-2026-11-15.md, Russell's answers of 15 Nov 2026). shipAllPick takes the waiting hold and stack cards by the same rules as the kit's lane/shipall.mjs (steward, pending, current, posted, unanswered, no reply, Ship it recommended, an action bound to its id; two cards on one PR are both left out) and says why each other one is left out. A title without K1's anchored "waits for your tap:" reads as read first (lane:hold, money, sign-in or database), so a card from before K1 fails safe. readShipAllCheck parses the kit's status item steward/ship-all-check line by line: the clear cards in the order Ship all taps them, the held cards with the kit's reason, and the button-level whys. Any other line, a line out of order, or a card both clear and held makes it unreadable. The check item no longer shows under Where things stand on the Bench screen; the digest's bar speaks for it. Stack: this is the bottom of four (gate and run, the digest card's bar, Give me details). Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- .../features/bench/lib/benchScreen.test.mjs | 1 + desktop/src/features/bench/lib/benchScreen.ts | 3 + .../bench/lib/benchShipAll.test-support.mjs | 117 +++++++++ .../features/bench/lib/benchShipAll.test.mjs | 92 +++++++ .../src/features/bench/lib/benchShipAll.ts | 224 ++++++++++++++++++ 5 files changed, 437 insertions(+) create mode 100644 desktop/src/features/bench/lib/benchShipAll.test-support.mjs create mode 100644 desktop/src/features/bench/lib/benchShipAll.test.mjs create mode 100644 desktop/src/features/bench/lib/benchShipAll.ts diff --git a/desktop/src/features/bench/lib/benchScreen.test.mjs b/desktop/src/features/bench/lib/benchScreen.test.mjs index 49784f74c2e..5e9ca32b897 100644 --- a/desktop/src/features/bench/lib/benchScreen.test.mjs +++ b/desktop/src/features/bench/lib/benchScreen.test.mjs @@ -65,6 +65,7 @@ test("sections: each item lands in exactly one section, like the board", () => { card("w/status", { kind: "status", options: [], state: "done" }), card("w/stale", { validity: "suspected-stale" }), card("w/gone", { kind: "status", validity: "superseded" }), + card("steward/ship-all-check", { kind: "status", options: [] }), ]), ); assert.deepEqual(ids(sections.needsYou), ["w/open"]); diff --git a/desktop/src/features/bench/lib/benchScreen.ts b/desktop/src/features/bench/lib/benchScreen.ts index 59f1b6c04f1..94075213678 100644 --- a/desktop/src/features/bench/lib/benchScreen.ts +++ b/desktop/src/features/bench/lib/benchScreen.ts @@ -13,6 +13,7 @@ import { benchCreatedSeconds, enabledBenchSnapshot, } from "@/features/bench/lib/benchCards"; +import { SHIP_ALL_CHECK_ID } from "@/features/bench/lib/benchShipAll"; import { normalizePubkey } from "@/shared/lib/pubkey"; export type BenchSections = { @@ -127,6 +128,8 @@ export function benchSections( viewer === undefined || (owner !== null && normalizePubkey(viewer) === normalizePubkey(owner)); for (const card of snapshot.items) { + // Machine lines for Ship all: the digest's bar speaks for it. + if (card.id === SHIP_ALL_CHECK_ID) continue; if (card.validity !== "current") { sections.retiring += 1; } else if (card.kind === "pending") { diff --git a/desktop/src/features/bench/lib/benchShipAll.test-support.mjs b/desktop/src/features/bench/lib/benchShipAll.test-support.mjs new file mode 100644 index 00000000000..24b150cdc33 --- /dev/null +++ b/desktop/src/features/bench/lib/benchShipAll.test-support.mjs @@ -0,0 +1,117 @@ +/** Steward cards and the kit's Ship all check as a Bench snapshot shows them. */ + +export const RESET = "QuicksilverSlick/Metabolic-reset"; +export const ANSWER = { + option: 0, + answeredAt: 1, + by: "", + byName: null, + byOwner: true, + source: "tap", +}; +export const REPLY = { + eventId: "r", + by: "", + byName: null, + role: null, + at: 1, + hhmm: "", +}; +const OPTIONS = ["Ship it", "Send it back", "Keep holding"]; +const BASE = "b".repeat(40); + +export function stewardItem(id, overrides = {}) { + return { + id, + writer: "steward", + kind: "pending", + title: id, + body: "", + area: "28-day-reset", + severity: "attention", + options: OPTIONS, + state: null, + decidedBy: null, + deadline: null, + links: [], + order: 0, + validity: "current", + cardEventId: "e".repeat(64), + answer: null, + recorded: null, + updatedAt: "2026-11-15T18:00:00Z", + channelId: null, + project: null, + scoped: false, + needs: "you", + answerers: [], + ownerName: null, + recommend: 1, + recommender: null, + reply: null, + request: null, + plain: { risk: "medium", undo: "easy" }, + ...overrides, + }; +} + +/** A reset hold card as the kit raises it; `sha` seeds its head commit. */ +export function hold(pr, { sha = "a", readFirst = false, ...overrides } = {}) { + const head = sha.repeat(40); + const wait = readFirst ? "waits for you, read first" : "waits for your tap"; + return stewardItem( + `steward/hold-reset-${pr}-${head.slice(0, 12)}-${BASE.slice(0, 12)}`, + { + title: `reset PR ${pr} ${wait}: Change ${pr}`, + action: `Ship pull request ${pr} of ${RESET} at commit ${head} on top of main at commit ${BASE}`, + cardEventId: String(pr).padStart(64, "e"), + ...overrides, + }, + ); +} + +export function stack(prs, { digest = "c".repeat(64), ...overrides } = {}) { + const span = `${prs[0]}-${prs.at(-1)}`; + return stewardItem(`steward/stack-reset-${span}-${digest.slice(0, 12)}`, { + title: `reset stack ${span} waits for your tap: ${prs.length} pull requests`, + action: `Ship as one stack the pull requests ${prs.join(", ")} of ${RESET}, list ${digest}`, + ...overrides, + }); +} + +/** + * The kit's check item; `listed` as [card, on the digest button too?], the + * clear ones; `held` as [card, why]. + */ +export function shipAllCheck( + listed, + { + at = Date.now(), + digest = "clear", + details = "clear", + held = [], + whys = [], + } = {}, +) { + const iso = (ms) => new Date(ms).toISOString(); + return stewardItem("steward/ship-all-check", { + kind: "status", + state: "active", + options: [], + recommend: null, + cardEventId: null, + title: "Ship all check", + body: [ + "Ship all check v1: the steward's check for the desktop's Ship all buttons. It ships nothing.", + `checked: ${iso(at)}`, + `next: ${iso(at + 15 * 60_000)}`, + `digest: ${digest}`, + `details: ${details}`, + ...listed.map( + ([c, both]) => `card: ${c.id} ${both ? "digest " : ""}details`, + ), + ...held.map(([c, why]) => `held: ${c.id} ${why}`), + ...whys, + ].join("\n"), + }); +} diff --git a/desktop/src/features/bench/lib/benchShipAll.test.mjs b/desktop/src/features/bench/lib/benchShipAll.test.mjs new file mode 100644 index 00000000000..dbcb2c0cb71 --- /dev/null +++ b/desktop/src/features/bench/lib/benchShipAll.test.mjs @@ -0,0 +1,92 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { readShipAllCheck, shipAllPick } from "./benchShipAll.ts"; +import { + ANSWER, + REPLY, + RESET, + hold, + shipAllCheck, + stack, + stewardItem, +} from "./benchShipAll.test-support.mjs"; + +const ids = (cards) => cards.map((c) => c.card.id); +const pr = (card) => card.id.split("-")[2]; + +test("candidates follow the kit's rules; the rest are left out with why", () => { + const head = (c) => + `${c.repeat(40)} on top of main at commit ${"b".repeat(40)}`; + const items = [ + hold(901), + hold(902, { reply: REPLY }), + hold(903, { cardEventId: null, waitsFor: "slot" }), + hold(904, { answer: ANSWER }), + hold(905, { options: ["Merge it", "Hold"] }), + hold(906, { + action: `Ship pull request 906 of ${RESET} at commit ${head("f")}`, + }), + hold(907, { + action: `Ship pull request 907 of QuicksilverSlick/buzz at commit ${head("a")}`, + }), + hold(908, { writer: "claude" }), + hold(909, { validity: "superseded" }), + stack([3, 4]), + stack([3, 4], { digest: "d".repeat(64) }), // a second card for PR 3 + stewardItem("steward/stop-reset-1", { options: ["Stop this line"] }), + ]; + const { candidates, left } = shipAllPick({ items }); + assert.deepEqual(ids(candidates), [items[0].id]); + assert.deepEqual( + left.map((l) => [pr(l.card), l.reason.split(/[:(]/)[0]]), + [ + ["902", "You wrote on its card"], + ["903", "Not on the Bench yet "], + ["905", "Its card does not name the commits Ship all checks"], + ["906", "Its card does not name the commits Ship all checks"], + ["907", "Its card does not name the commits Ship all checks"], + ["3", "Two open cards for reset pull request 3"], + ["3", "Two open cards for reset pull request 3"], + ], + ); +}); + +test("read first is any title without K1's anchored marker", () => { + const titles = [ + "reset PR 1 waits for your tap: A", + "reset PR 1 waits for you, read first: A", + "reset PR 1 waits for you: a card from before K1", + "reset PR 1 waits for you, read first: x waits for your tap: y", + "Fix: reset PR 1 waits for your tap: hostile", + ]; + const read = titles.map( + (title) => + shipAllPick({ items: [hold(1, { title })] }).candidates[0].readFirst, + ); + assert.deepEqual(read, [false, true, true, true, true]); +}); + +test("the check parses line by line; any other line is unreadable", () => { + const a = hold(901); + const b = hold(902, { sha: "c" }); + const item = shipAllCheck([[a, true]], { + held: [[b, "reset PR 902 has red CI."]], + whys: ["why details: x"], + }); + const parsed = readShipAllCheck({ items: [item] }); + assert.deepEqual(parsed.cards, [{ id: a.id, digest: true }]); + assert.deepEqual([...parsed.held], [[b.id, "reset PR 902 has red CI."]]); + assert.deepEqual(parsed.whys, { digest: [], details: ["x"] }); + const read = (body) => readShipAllCheck({ items: [{ ...item, body }] }); + assert.equal(read(item.body.replace("v1", "v2")), "unreadable"); + assert.equal(read(`${item.body}\nship: all`), "unreadable"); + assert.equal(read(`${item.body}\ncard: ${a.id} details`), "unreadable"); + assert.equal(read(`${item.body}\nwhy digest: late`), "unreadable"); + assert.equal(read(`${item.body}\nheld: ${b.id} late`), "unreadable"); + const twice = shipAllCheck([[a, true]], { held: [[a, "x"]] }); + assert.equal(read(twice.body), "unreadable", "clear and held at once"); + assert.equal(readShipAllCheck({ items: [] }), "missing"); + const foreign = { ...item, writer: "claude" }; + assert.equal(readShipAllCheck({ items: [foreign] }), "missing"); +}); diff --git a/desktop/src/features/bench/lib/benchShipAll.ts b/desktop/src/features/bench/lib/benchShipAll.ts new file mode 100644 index 00000000000..ee694b1997b --- /dev/null +++ b/desktop/src/features/bench/lib/benchShipAll.ts @@ -0,0 +1,224 @@ +/** + * Ship all on the steward's digest (Desktop/Buzz/steward-digest-ship-all-design- + * 2026-11-15.md, Russell's answers of 15 Nov 2026). Ship all taps each waiting + * hold or stack card's own Ship it, one `bench_answer` at a time, so the kit + * verifies every tap alone as today. It taps only the cards that both this + * picks (the same rules as the kit's lane/shipall.mjs) and the steward's + * fresh check (`steward/ship-all-check`, a status item the kit drops each + * tick) lists as clear, card by card; every other waiting card says why. + */ + +import type { BenchCard, BenchSnapshot } from "@/features/bench/lib/benchCards"; + +export type ShipAllButton = "digest" | "details"; + +/** The kit's digestCard ids: the morning's, then a daytime `-2` or `-3`. */ +const DIGEST_ID = /^steward\/digest-\d{4}-\d{2}-\d{2}(?:-\d{1,2})?$/; +const HOLD_ID = + /^steward\/hold-(reset|talos|buzz)-(\d{1,7})-([0-9a-f]{12})-([0-9a-f]{12})$/; +const STACK_ID = + /^steward\/stack-(reset|talos|buzz)-(\d{1,7})-(\d{1,7})-([0-9a-f]{12})$/; +const SHIP_ACTION = + /^Ship pull request (\d{1,7}) of ([A-Za-z0-9-]+\/[A-Za-z0-9.-]+) at commit ([0-9a-f]{40}) on top of [A-Za-z0-9./-]{1,80} at commit ([0-9a-f]{40})$/; +const STACK_ACTION = + /^Ship as one stack the pull requests (\d{1,7}(?:, \d{1,7}){0,4}) of ([A-Za-z0-9-]+\/[A-Za-z0-9.-]+), list ([0-9a-f]{64})$/; +/** K1's marker: any other title reads as read first (lane:hold, money, sign-in or database). */ +const TAP_TITLE = + /^(buzz|reset|talos) (hotfix )?(PR \d{1,7}|stack \d{1,7}-\d{1,7}) waits for your tap: /; +/** lane/repos.json: the repo an action names, by its short name. */ +const REPO_SHORT: Record = { + "QuicksilverSlick/Metabolic-reset": "reset", + "QuicksilverSlick/dreamforge-talos": "talos", + "QuicksilverSlick/buzz": "buzz", +}; +const SHIP_LABEL = "Ship it"; + +export const SHIP_ALL_CHECK_ID = "steward/ship-all-check"; +const CHECK_HEAD = + "Ship all check v1: the steward's check for the desktop's Ship all buttons. It ships nothing."; +const ISO = "(\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d\\.\\d{3}Z)"; +const CHECKED = new RegExp(`^checked: ${ISO}$`); +const NEXT = new RegExp(`^next: ${ISO}$`); +const CARD_LINE = + /^card: (steward\/(?:hold|stack)-[a-z0-9-]{1,64}) (digest details|details)$/; +const HELD_LINE = + /^held: (steward\/(?:hold|stack)-[a-z0-9-]{1,64}) (.{1,200})$/; + +export function isStewardDigest(card: BenchCard): boolean { + return ( + card.writer === "steward" && + card.kind === "pending" && + !card.request && + DIGEST_ID.test(card.id) + ); +} + +/** A card Ship all can tap; `prs` as "reset 906", one per PR it ships. */ +export type ShipAllCard = { + card: BenchCard; + prs: string[]; + readFirst: boolean; +}; +export type ShipAllLeftOut = { + card: BenchCard; + reason: string; + /** The steward's check reads it as read first now (a lane:hold added later). */ + readFirst?: boolean; +}; + +/** The PRs a card's id and action agree on, or null when they don't. */ +function boundPrs(card: BenchCard): string[] | null { + const hold = HOLD_ID.exec(card.id); + if (hold) { + const a = SHIP_ACTION.exec(card.action ?? ""); + const ok = + a && + REPO_SHORT[a[2]] === hold[1] && + a[1] === hold[2] && + a[3].startsWith(hold[3]) && + a[4].startsWith(hold[4]); + return ok ? [`${hold[1]} ${hold[2]}`] : null; + } + const stack = STACK_ID.exec(card.id); + const a = STACK_ACTION.exec(card.action ?? ""); + if (!stack || !a) return null; + const prs = a[1].split(", "); + const ok = + REPO_SHORT[a[2]] === stack[1] && + prs[0] === stack[2] && + prs.at(-1) === stack[3] && + a[3].startsWith(stack[4]); + return ok ? prs.map((n) => `${stack[1]} ${n}`) : null; +} + +/** + * Every hold or stack card waiting on the owner's tap, split into what Ship + * all can tap (the kit's candidates) and what it leaves out, with why. + */ +export function shipAllPick(snapshot: Pick): { + candidates: ShipAllCard[]; + left: ShipAllLeftOut[]; +} { + const picked: ShipAllCard[] = []; + const left: ShipAllLeftOut[] = []; + for (const card of snapshot.items) { + const waiting = + card.writer === "steward" && + card.kind === "pending" && + card.validity === "current" && + !card.request && + !card.answer && + /^steward\/(?:hold|stack)-/.test(card.id); + if (!waiting) continue; + const prs = boundPrs(card); + const out = (reason: string) => left.push({ card, reason }); + if (card.reply) out("You wrote on its card: answer it there."); + else if (!card.cardEventId) { + out( + card.waitsFor === "slot" + ? "Not on the Bench yet (it waits for a card slot). It posts as answered cards free their slots, about 15 minutes after each answer." + : "Not on the Bench yet: answer it on its card once it posts.", + ); + } else if ( + !prs || + card.recommend === null || + card.options[card.recommend - 1] !== SHIP_LABEL + ) { + out( + "Its card does not name the commits Ship all checks: answer it on its card.", + ); + } else { + picked.push({ card, prs, readFirst: !TAP_TITLE.test(card.title) }); + } + } + // Two cards naming one PR: one is being replaced, so neither is tapped. + const count = new Map(); + for (const pr of picked.flatMap((c) => c.prs)) { + count.set(pr, (count.get(pr) ?? 0) + 1); + } + const candidates: ShipAllCard[] = []; + for (const c of picked) { + const twice = c.prs.find((pr) => count.get(pr) !== 1); + if (!twice) candidates.push(c); + else { + const [repo, n] = twice.split(" "); + left.push({ + card: c.card, + reason: `Two open cards for ${repo} pull request ${n}: the steward closes one at its next tick.`, + }); + } + } + return { candidates, left }; +} + +export type ShipAllCheck = { + checked: number; + next: number; + clear: Record; + /** The clear cards, in the order Ship all taps them; `digest`: on the digest card's too. */ + cards: Array<{ id: string; digest: boolean }>; + /** Each card the steward keeps off Ship all this tick, with why. */ + held: Map; + whys: Record; +}; + +/** + * The steward's check, line by line in the kit's order (README, Ship all's + * check); any other line makes it unreadable. "missing" when the snapshot + * holds no such item from the steward. + */ +export function readShipAllCheck( + snapshot: Pick, +): ShipAllCheck | "missing" | "unreadable" { + const item = snapshot.items.find( + (i) => + i.id === SHIP_ALL_CHECK_ID && + i.writer === "steward" && + i.kind === "status", + ); + if (!item) return "missing"; + const lines = item.body.split("\n"); + const checked = CHECKED.exec(lines[1] ?? "")?.[1]; + const next = NEXT.exec(lines[2] ?? "")?.[1]; + const digest = /^digest: (clear|not clear)$/.exec(lines[3] ?? "")?.[1]; + const details = /^details: (clear|not clear)$/.exec(lines[4] ?? "")?.[1]; + if (lines[0] !== CHECK_HEAD || !checked || !next || !digest || !details) { + return "unreadable"; + } + const check: ShipAllCheck = { + checked: Date.parse(checked), + next: Date.parse(next), + clear: { digest: digest === "clear", details: details === "clear" }, + cards: [], + held: new Map(), + whys: { digest: [], details: [] }, + }; + // Sections in order: cards, held, then the digest's whys, then the details'. + let section = 0; + for (const line of lines.slice(5)) { + const card = CARD_LINE.exec(line); + const held = HELD_LINE.exec(line); + const why = /^why (digest|details): (.{1,200})$/.exec(line); + const at = card ? 0 : held ? 1 : why?.[1] === "digest" ? 2 : why ? 3 : -1; + if (at < section) return "unreadable"; + section = at; + if (card) check.cards.push({ id: card[1], digest: card[2] !== "details" }); + else if (held) check.held.set(held[1], held[2]); + else if (why) check.whys[why[1] as ShipAllButton].push(why[2]); + } + const ids = new Set(check.cards.map((c) => c.id)); + const named = ids.size + check.held.size; + for (const id of check.held.keys()) ids.add(id); + if (ids.size !== named || !Number.isFinite(check.checked)) { + return "unreadable"; + } + return Number.isFinite(check.next) ? check : "unreadable"; +} + +const HHMM = new Intl.DateTimeFormat("en-US", { + hour: "numeric", + minute: "2-digit", +}); +export function formatShipAllTime(ms: number): string { + return HHMM.format(new Date(ms)); +} From 01b05a44c8b83696af693a38102c53c24a450ce4 Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Sun, 15 Nov 2026 14:59:42 -0600 Subject: [PATCH 2/5] Bench: Ship all's gate and run: tap what the steward's check clears, one card at a time shipAllGate says what one button taps now: the cards that both wait on the owner's tap and are listed clear for that button by a readable steward check at most 25 minutes old (one slow tick does not turn it off), in the check's order (repo by repo, a card on another card's PR after it, stacks first, then oldest). A card answered by hand since the check just drops out; one the check holds, or has not seen yet, is left out with why, so one blocked card never turns Ship all off for the rest. A missing, unreadable or stale check says that each card's own Ship it still works and where to look. runShipAll taps each card with the same bench_answer call its own Ship it sends. Before each tap it reads the Bench again (shipAllStillOk) and stops if that card no longer waits or is no longer clear, so an answer or reply he gave meanwhile is never overwritten with Ship it. It waits for each card's Recorded line before the next and stops at the first failure; a tap not recorded after 15 s says its Ship it was sent and may still record. Stack: on feat/bench-ship-all. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- .../features/bench/lib/benchShipAll.test.mjs | 261 +++++++++++++++++- .../src/features/bench/lib/benchShipAll.ts | 228 ++++++++++++++- 2 files changed, 487 insertions(+), 2 deletions(-) diff --git a/desktop/src/features/bench/lib/benchShipAll.test.mjs b/desktop/src/features/bench/lib/benchShipAll.test.mjs index dbcb2c0cb71..829a5a6e1ad 100644 --- a/desktop/src/features/bench/lib/benchShipAll.test.mjs +++ b/desktop/src/features/bench/lib/benchShipAll.test.mjs @@ -1,7 +1,15 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { readShipAllCheck, shipAllPick } from "./benchShipAll.ts"; +import { + formatShipAllTime, + readShipAllCheck, + runShipAll, + shipAllGate, + shipAllPick, + shipAllRecorded, + shipAllTaps, +} from "./benchShipAll.ts"; import { ANSWER, REPLY, @@ -90,3 +98,254 @@ test("the check parses line by line; any other line is unreadable", () => { const foreign = { ...item, writer: "claude" }; assert.equal(readShipAllCheck({ items: [foreign] }), "missing"); }); + +test("a button taps the cards both lists name, in the check's order, while the check is fresh", () => { + const now = Date.parse("2026-11-15T18:30:00.000Z"); + const a = hold(901, { updatedAt: "2026-11-15T18:00:00Z" }); + const b = hold(902, { updatedAt: "2026-11-15T17:00:00Z", sha: "c" }); + const both = [ + [a, true], + [b, true], + ]; + const gate = (check, items = [a, b]) => + shipAllGate( + { items: [...items, ...(check ? [check] : [])] }, + "digest", + now, + ); + const open = gate(shipAllCheck(both, { at: now - 60_000 })); + assert.equal(open.enabled, true); + assert.deepEqual(ids(open.cards), [a.id, b.id], "the steward's order"); + assert.equal( + gate(shipAllCheck(both, { at: now - 24 * 60_000 })).enabled, + true, + "one slow tick does not turn it off", + ); + + const reason = (check) => gate(check).reasons.join(" "); + assert.match( + reason(null), + /check is not on the Bench yet.*own Ship it still works/, + ); + assert.match( + reason({ ...shipAllCheck(both), body: "x" }), + /could not be read\. Each card's own Ship it still works\. .*see #steward/, + ); + const stale = shipAllCheck(both, { at: now - 26 * 60_000 }); + assert.match( + reason(stale), + /last check \(.*\) is too old to trust\. .*tick may be failing/, + ); + assert.deepEqual( + ids(gate(stale).cards), + [b.id, a.id], + "what it would tap, oldest first", + ); + assert.equal( + gate(shipAllCheck(both, { at: now + 3 * 60_000 })).enabled, + false, + ); + + // Answered by hand since the check: it just drops out. + const answered = gate(shipAllCheck(both, { at: now - 60_000 }), [ + a, + { ...b, answer: ANSWER }, + ]); + assert.deepEqual([answered.enabled, ids(answered.cards)], [true, [a.id]]); + // PR 902 moved to a new commit: the check has not seen its new card yet. + const moved = gate( + shipAllCheck([both[0], [hold(902, { sha: "d" }), true]], { + at: now - 60_000, + }), + ); + assert.deepEqual([moved.enabled, ids(moved.cards)], [true, [a.id]]); + assert.deepEqual( + moved.left.map((l) => [l.card.id, l.reason]), + [[b.id, "New since the steward's check at 6:29 PM."]].map(([id, r]) => [ + id, + r.replace("6:29 PM", formatShipAllTime(now - 60_000)), + ]), + ); + assert.match(moved.recheck, /^It checks again by /); +}); + +test("a card the check holds is left out with its reason; with none clear the button says each", () => { + const now = Date.now(); + const a = hold(901); + const b = hold(902, { sha: "c" }); + const why = (n) => + `reset PR ${n} conflicts with main at bbbbbbbbbbbb (2 files): the fix is a new commit.`; + const one = shipAllGate( + { items: [a, b, shipAllCheck([[a, true]], { held: [[b, why(902)]] })] }, + "digest", + now, + ); + assert.deepEqual([one.enabled, ids(one.cards)], [true, [a.id]]); + assert.deepEqual( + one.left.map((l) => l.reason), + [why(902)], + ); + const none = shipAllGate( + { + items: [ + a, + b, + shipAllCheck([], { + digest: "not clear", + held: [ + [a, why(901)], + [b, why(902)], + ], + whys: ["why digest: Every card for this button is held this tick."], + }), + ], + }, + "digest", + now, + ); + assert.equal(none.enabled, false); + assert.deepEqual(none.cards, []); + assert.deepEqual(none.reasons.slice(0, 2), [why(901), why(902)]); + assert.match(none.reasons[2], /^It checks again by /); + // Too many to list: the kit names no card and says so. + const over = + "40 cards wait, more than one check can list: tap them on their cards until fewer wait."; + const many = shipAllGate( + { + items: [ + a, + shipAllCheck([], { + digest: "not clear", + whys: [`why digest: ${over}`], + }), + ], + }, + "digest", + now, + ); + assert.deepEqual( + many.left.map((l) => l.reason), + [over], + ); +}); + +test("the digest button skips read-first cards; Give me details holds them", () => { + const now = Date.now(); + const a = hold(901); + const r = hold(902, { readFirst: true, sha: "c" }); + const items = [ + a, + r, + shipAllCheck([ + [r, false], + [a, true], + ]), + ]; + assert.deepEqual(ids(shipAllGate({ items }, "digest", now).cards), [a.id]); + const details = shipAllGate({ items }, "details", now); + assert.equal(details.enabled, true); + assert.deepEqual(ids(details.cards), [r.id, a.id]); + const held = shipAllGate( + { items: [r, shipAllCheck([[r, false]])] }, + "digest", + now, + ); + assert.match( + held.reasons[0], + /Every waiting card is read first \(lane:hold, money, sign-in or database\)/, + ); + const none = shipAllGate({ items: [] }, "details", now); + assert.match(none.reasons[0], /Nothing for this button waits/); + // lane:hold added after its card: the title still says tap, the check says details only. + const late = shipAllGate( + { items: [a, shipAllCheck([[a, false]])] }, + "digest", + now, + ); + assert.equal(late.enabled, false); + assert.deepEqual( + late.left.map((l) => [l.readFirst, l.reason]), + [ + [ + true, + "It is read first now (lane:hold was added after its card): ship it from Give me details.", + ], + ], + ); +}); + +test("the run taps in order, waits for each Recorded line, stops at a failure", async () => { + const cards = [hold(1), stack([2, 3]), hold(4, { sha: "d" })]; + const taps = shipAllTaps(cards.map((card) => ({ card }))); + assert.deepEqual(taps[0], { + itemId: cards[0].id, + cardEventId: cards[0].cardEventId, + option: 0, + title: cards[0].title, + }); + const log = []; + let answered = null; + const deps = (fail) => ({ + answer: async (t) => { + log.push(`tap ${t.itemId.split("-")[2]}`); + if (t.itemId === fail) throw new Error("This card changed - look again"); + }, + stillOk: async (t) => t.itemId !== answered, + // Recorded on the second read of each card. + isRecorded: async (t) => { + const read = `read ${t.itemId.split("-")[2]}`; + log.push(read); + return log.filter((line) => line === read).length > 1; + }, + onStep: () => {}, + sleep: async () => {}, + }); + assert.deepEqual(await runShipAll(taps, deps()), { + recorded: 3, + error: null, + }); + assert.deepEqual( + log.join(), + "tap 1,read 1,read 1,tap 2,read 2,read 2,tap 4,read 4,read 4", + ); + + log.length = 0; + const failed = await runShipAll(taps, deps(cards[1].id)); + assert.equal(failed.recorded, 1); + assert.match(failed.error, /couldn't save: This card changed/); + assert.deepEqual(log.join(), "tap 1,read 1,read 1,tap 2", "nothing after it"); + + const never = { ...deps(), isRecorded: async () => false, timeoutMs: 3_000 }; + const timedOut = await runShipAll(taps, never); + assert.equal(timedOut.recorded, 0); + assert.match( + timedOut.error, + /its Ship it was sent, but the Bench has not recorded it after 3 s\. It may still record: check its card/, + ); + + // He answered the second card meanwhile: it is never tapped, and nothing after it. + log.length = 0; + answered = cards[1].id; + const stopped = await runShipAll(taps, deps()); + assert.equal(stopped.recorded, 1); + assert.match( + stopped.error, + /: not tapped\. You answered or wrote on it meanwhile/, + ); + assert.deepEqual(log.join(), "tap 1,read 1,read 1"); +}); + +test("Recorded means the owner's Ship it on the card he was shown", () => { + const card = hold(1); + const [tap] = shipAllTaps([{ card }]); + const shows = (over) => + shipAllRecorded({ items: [{ ...card, ...over }] }, tap); + assert.equal(shows({}), false); + assert.equal(shows({ recorded: 0, answer: ANSWER }), true); + assert.equal( + shows({ recorded: 0, answer: { ...ANSWER, byOwner: false } }), + false, + ); + assert.equal(shows({ recorded: 0, cardEventId: "f".repeat(64) }), false); + assert.equal(shipAllRecorded(null, tap), false); +}); diff --git a/desktop/src/features/bench/lib/benchShipAll.ts b/desktop/src/features/bench/lib/benchShipAll.ts index ee694b1997b..1b46a3ff1c3 100644 --- a/desktop/src/features/bench/lib/benchShipAll.ts +++ b/desktop/src/features/bench/lib/benchShipAll.ts @@ -8,7 +8,11 @@ * tick) lists as clear, card by card; every other waiting card says why. */ -import type { BenchCard, BenchSnapshot } from "@/features/bench/lib/benchCards"; +import { + type BenchCard, + type BenchSnapshot, + benchCreatedSeconds, +} from "@/features/bench/lib/benchCards"; export type ShipAllButton = "digest" | "details"; @@ -43,6 +47,10 @@ const CARD_LINE = /^card: (steward\/(?:hold|stack)-[a-z0-9-]{1,64}) (digest details|details)$/; const HELD_LINE = /^held: (steward\/(?:hold|stack)-[a-z0-9-]{1,64}) (.{1,200})$/; +const OVER = / cards wait, more than one check can list: /; +/** Under two ticks: one slow tick (232 s, 15 Nov) must not turn it off. */ +const STALE_MS = 25 * 60_000; +const FUTURE_MS = 2 * 60_000; export function isStewardDigest(card: BenchCard): boolean { return ( @@ -222,3 +230,221 @@ const HHMM = new Intl.DateTimeFormat("en-US", { export function formatShipAllTime(ms: number): string { return HHMM.format(new Date(ms)); } + +export type ShipAllGate = { + /** What this button taps, in the steward's order; while the check can't be used, what it would. */ + cards: ShipAllCard[]; + enabled: boolean; + /** Why it is off, and when that clears; empty when enabled. */ + reasons: string[]; + /** This button's other waiting cards, each with why it is not tapped. */ + left: ShipAllLeftOut[]; + /** When the steward checks again, once its check is in use. */ + recheck: string; +}; + +/** + * What one button taps now: the cards both picked here and listed clear for + * it by a readable steward check at most 25 minutes old (their ids hold + * their commits), in the check's order. A card answered since the check just + * drops out; one the check holds, or has not seen yet, is left out with why. + */ +export function shipAllGate( + snapshot: Pick, + button: ShipAllButton, + now: number, +): ShipAllGate { + const { candidates } = shipAllPick(snapshot); + const mine = candidates + .filter((c) => button === "details" || !c.readFirst) + .sort( + (a, b) => + (benchCreatedSeconds(a.card) ?? 0) - (benchCreatedSeconds(b.card) ?? 0), + ); + const off = (reason: string) => ({ + cards: mine, + enabled: false, + reasons: [reason], + left: [], + recheck: "", + }); + if (mine.length === 0) { + return off( + candidates.length > 0 + ? "Every waiting card is read first (lane:hold, money, sign-in or database): open Give me details to read and ship them there." + : "Nothing for this button waits on your tap.", + ); + } + const check = readShipAllCheck(snapshot); + const still = "Each card's own Ship it still works."; + if (check === "missing") { + return off( + `The steward's check is not on the Bench yet: it checks every 15 minutes. ${still}`, + ); + } + if (check === "unreadable") { + return off( + `The steward's check could not be read. ${still} It checks every 15 minutes; if this stays, see #steward.`, + ); + } + const at = formatShipAllTime(check.checked); + if (now - check.checked > STALE_MS || check.checked - now > FUTURE_MS) { + return off( + `The steward's last check (${at}) is too old to trust. It checks every 15 minutes; if this stays, the tick may be failing (see #steward). ${still}`, + ); + } + const recheck = + check.next > now + ? `It checks again by ${formatShipAllTime(check.next)}.` + : "It checks again at its next tick."; + const cards = check.cards + .filter((l) => button === "details" || l.digest) + .flatMap((l) => mine.filter((c) => c.card.id === l.id)); + const left = mine + .filter((c) => !cards.includes(c)) + .map(({ card }): ShipAllLeftOut => { + const held = check.held.get(card.id); + if (held) return { card, reason: held }; + if (check.cards.some((l) => l.id === card.id)) { + return { + card, + reason: + "It is read first now (lane:hold was added after its card): ship it from Give me details.", + readFirst: true, + }; + } + // The kit's one way to name no card while some wait: too many to list. + const over = check.whys[button].find((w) => OVER.test(w)); + return { + card, + reason: over ?? `New since the steward's check at ${at}.`, + }; + }); + if (cards.length === 0) { + const shown = left.slice(0, 3).map((l) => l.reason); + const more = left.length - shown.length; + return { + cards, + enabled: false, + reasons: [...shown, ...(more > 0 ? [`And ${more} more.`] : []), recheck], + left, + recheck, + }; + } + return { cards, enabled: true, reasons: [], left, recheck }; +} + +export type ShipAllTap = { + itemId: string; + cardEventId: string; + /** 0-based: the card's recommended Ship it. */ + option: number; + title: string; +}; + +export function shipAllTaps(cards: readonly ShipAllCard[]): ShipAllTap[] { + return cards.map(({ card }) => ({ + itemId: card.id, + cardEventId: card.cardEventId ?? "", + option: (card.recommend ?? 1) - 1, + title: card.title, + })); +} + +/** + * Taps each card in order with `answer` (bench_answer), then waits for its + * Recorded line before the next; the first failure stops the run, so no + * card goes before one under it. `stillOk` reads the Bench again before each + * tap, so an answer or reply he gave meanwhile, or a new check that holds + * the card, is never overwritten with Ship it. + */ +export async function runShipAll( + taps: readonly ShipAllTap[], + { + answer, + stillOk, + isRecorded, + onStep, + sleep, + pollMs = 1_000, + timeoutMs = 15_000, + }: { + answer: (tap: ShipAllTap) => Promise; + stillOk: (tap: ShipAllTap) => Promise; + isRecorded: (tap: ShipAllTap) => Promise; + onStep: (index: number) => void; + sleep: (ms: number) => Promise; + pollMs?: number; + timeoutMs?: number; + }, +): Promise<{ recorded: number; error: string | null }> { + for (const [i, tap] of taps.entries()) { + onStep(i); + if (!(await stillOk(tap).catch(() => false))) { + return { + recorded: i, + error: `${tap.title}: not tapped. You answered or wrote on it meanwhile, or the steward's check no longer clears it.`, + }; + } + try { + await answer(tap); + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + return { recorded: i, error: `${tap.title}: couldn't save: ${message}` }; + } + for (let polls = 0; !(await isRecorded(tap).catch(() => false)); polls++) { + if (polls * pollMs >= timeoutMs) { + return { + recorded: i, + error: `${tap.title}: its Ship it was sent, but the Bench has not recorded it after ${timeoutMs / 1_000} s. It may still record: check its card, and click its Ship it to take it back.`, + }; + } + await sleep(pollMs); + } + } + return { recorded: taps.length, error: null }; +} + +/** Whether a fresh snapshot still has this card waiting and clear on this button. */ +export function shipAllStillOk( + snapshot: Pick | null, + tap: ShipAllTap, + button: ShipAllButton, + now: number, +): boolean { + const gate = snapshot && shipAllGate(snapshot, button, now); + return ( + !!gate?.enabled && + gate.cards.some( + (c) => c.card.id === tap.itemId && c.card.cardEventId === tap.cardEventId, + ) + ); +} + +/** Whether a fresh snapshot shows the owner's Ship it recorded on the card. */ +export function shipAllRecorded( + snapshot: Pick | null, + tap: ShipAllTap, +): boolean { + const card = snapshot?.items.find((i) => i.id === tap.itemId); + return ( + card?.cardEventId === tap.cardEventId && + card.recorded === tap.option && + (card.answer?.byOwner ?? true) + ); +} + +/** The titles of the steward's trains still on their way to live. */ +export function shipAllTrains( + snapshot: Pick, +): string[] { + return snapshot.items + .filter( + (i) => + i.writer === "steward" && + /^steward\/(?:reset|talos|buzz)-train$/.test(i.id) && + i.validity === "current" && + !i.title.endsWith(": live"), + ) + .map((i) => i.title); +} From 6fed5fce3cda81e1a2d616a09b4b09fbecfab7e0 Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Sun, 15 Nov 2026 14:59:50 -0600 Subject: [PATCH 3/5] Bench: Ship all on the steward digest card The steward digest card gets Ship all N (its cards that are not read first) and Give me details, which opens the digest's thread the way Open thread does, so it works from the Inbox too. Got it stays the digest's only option. Ship all is on while the steward's check clears at least one of its cards; otherwise it is off and says why and when the steward checks again. The bar says how many more are read first (lane:hold, money, sign-in or database) and how many can't go now. Ship all asks once, "Ship these N?", naming each card with its risk and undo. Yes taps each card's own Ship it in the steward's order, reading the Bench again before each, and waits for its Recorded line. The first failure stops the run and names the card; the result is also a toast, so a digest replaced mid-run cannot hide it. After the taps it says what happens next: the 2-minute settle, the 15-minute tick, the trains and the trains now. With no digest open (the day's three are out, or it closed), the owner gets the same Ship all above Needs you on the Bench screen. Stack: on feat/bench-ship-all-gate. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- .../src/features/bench/ui/BenchCard.test.mjs | 207 ++++++++++++- desktop/src/features/bench/ui/BenchCard.tsx | 5 + .../features/bench/ui/BenchScreen.test.mjs | 32 ++ desktop/src/features/bench/ui/BenchScreen.tsx | 15 + .../src/features/bench/ui/BenchShipAll.tsx | 276 ++++++++++++++++++ desktop/src/features/bench/useBenchCards.ts | 9 + 6 files changed, 541 insertions(+), 3 deletions(-) create mode 100644 desktop/src/features/bench/ui/BenchShipAll.tsx diff --git a/desktop/src/features/bench/ui/BenchCard.test.mjs b/desktop/src/features/bench/ui/BenchCard.test.mjs index 9afcec4cd23..613a15bee04 100644 --- a/desktop/src/features/bench/ui/BenchCard.test.mjs +++ b/desktop/src/features/bench/ui/BenchCard.test.mjs @@ -24,6 +24,12 @@ import { after, afterEach, before, test } from "node:test"; import { JSDOM } from "jsdom"; +import { + ANSWER, + hold, + shipAllCheck, +} from "../lib/benchShipAll.test-support.mjs"; + const dom = new JSDOM("", { url: "http://localhost", }); @@ -42,6 +48,11 @@ let createElement; let QueryClient; let QueryClientProvider; let TooltipProvider; +let RouterContextProvider; +let createMemoryHistory; +let createRootRoute; +let createRouter; +let router; let BenchCard; let clearBenchWhys; let formatBenchCreated; @@ -94,10 +105,19 @@ function wrap(element) { }, }); clients.push(client); + // Only the router context useAppNavigation reads (Give me details). + router = createRouter({ + routeTree: createRootRoute(), + history: createMemoryHistory({ initialEntries: ["/"] }), + }); return createElement( - QueryClientProvider, - { client }, - createElement(TooltipProvider, null, element), + RouterContextProvider, + { router }, + createElement( + QueryClientProvider, + { client }, + createElement(TooltipProvider, null, element), + ), ); } @@ -128,6 +148,7 @@ before(async () => { Object.assign(globalThis, { document: dom.window.document, window: dom.window, + self: dom.window, IS_REACT_ACT_ENVIRONMENT: true, }); for (const key of Object.getOwnPropertyNames(dom.window)) { @@ -177,6 +198,12 @@ before(async () => { "@tanstack/react-query" )); ({ TooltipProvider } = await import("@/shared/ui/tooltip")); + ({ + RouterContextProvider, + createMemoryHistory, + createRootRoute, + createRouter, + } = await import("@tanstack/react-router")); ({ BenchCard } = await import("./BenchCard.tsx")); ({ clearBenchWhys } = await import("./BenchWhyBox.tsx")); ({ formatBenchCreated } = await import("../lib/benchCards.ts")); @@ -1332,3 +1359,177 @@ test("Why? on a steward card says the reason goes on the PR, and public unless t "Posted as a reply on this card; no agent is told for dreamforge. Send opens once the card records your tap.", ); }); + +// Ship all on the steward's digest (benchShipAll.ts): the bar, the confirm +// and the taps in the steward's order. +const DIGEST = card({ + id: "steward/digest-2026-11-15", + writer: "steward", + title: "Steward digest 2026-11-15: 2 taps would free 2 pull requests", + options: ["Got it"], +}); + +/** Serves the snapshot; a bench_answer records on it, as the Bench would. */ +function serveBench(items, { fail = null, onAnswer = () => {} } = {}) { + const snapshot = { + enabled: true, + channelId: CHANNEL, + writerPubkey: WRITER, + ownerPubkey: OWNER, + lastError: null, + lastTick: new Date().toISOString(), + items, + }; + ipcHandlers.set("bench_cards", async () => structuredClone(snapshot)); + ipcHandlers.set("bench_answer", async ({ itemId, option }) => { + if (itemId === fail) throw new Error("boom"); + const item = snapshot.items.find((i) => i.id === itemId); + Object.assign(item, { recorded: option, answer: ANSWER }); + onAnswer(snapshot.items); + return null; + }); +} + +const shipAll = () => screen.getByRole("button", { name: /^Ship all \d/ }); +const click = (name) => + act(async () => fireEvent.click(screen.getByRole("button", { name }))); + +async function renderDigest() { + await act(async () => { + render(wrap(benchCard({ card: DIGEST, onOther: () => {} }))); + }); +} + +test("the digest shows Ship all and Give me details; a stale check says why", async () => { + const a = hold(901); + const at = Date.now() - 26 * 60_000; + serveBench([DIGEST, a, shipAllCheck([[a, true]], { at })]); + await renderDigest(); + await waitFor(() => assert.equal(shipAll().textContent, "Ship all 1")); + assert.equal(shipAll().disabled, true); + assert.match( + screen.getByTestId("bench-ship-all-reason").textContent, + /^The steward's last check \(.*\) is too old to trust\. It checks every 15 minutes; if this stays, the tick may be failing \(see #steward\)\. Each card's own Ship it still works\.$/, + ); + // Give me details opens the digest's thread, from the Inbox too. + await click("Give me details"); + await waitFor(() => + assert.equal(router.history.location.pathname, `/channels/${CHANNEL}`), + ); + assert.match( + decodeURIComponent(router.history.location.search), + new RegExp(`^\\?messageId="?${DIGEST.cardEventId}"?$`), + ); + assert.ok(optionButton("1. Got it"), "Got it stays the only option"); +}); + +test("Ship all asks once naming each card; Yes taps in the steward's order", async () => { + const a = hold(901, { updatedAt: "2026-11-15T10:00:00Z" }); + const b = hold(902, { updatedAt: "2026-11-15T11:00:00Z", sha: "c" }); + const held = hold(903, { readFirst: true, sha: "d" }); + const listed = [ + [b, true], + [held, false], + [a, true], + ]; + serveBench([DIGEST, a, b, held, shipAllCheck(listed)]); + await renderDigest(); + await waitFor(() => assert.equal(shipAll().disabled, false)); + assert.equal(shipAll().textContent, "Ship all 2", "not the read-first card"); + assert.ok( + screen.getByText( + /^1 more is read first \(lane:hold, money, sign-in or database\), so it ships from Give me details\.$/, + ), + ); + + await act(async () => fireEvent.click(shipAll())); + const confirm = screen.getByTestId("bench-ship-all-confirm"); + assert.match(confirm.textContent, /^Ship these 2\?/); + assert.deepEqual( + [...confirm.querySelectorAll("li")].map((li) => li.textContent), + [b, a].map((c) => `${c.title} · risk medium, undo easy`), + ); + await click("Cancel"); + assert.equal(screen.queryByTestId("bench-ship-all-confirm"), null); + assert.deepEqual(answerCalls(), []); + + await act(async () => fireEvent.click(shipAll())); + await click("Yes, ship 2"); + await waitFor(() => screen.getByText(/^Recorded Ship it on 2 cards at /)); + assert.deepEqual( + answerCalls(), + [b, a].map((c) => ({ + itemId: c.id, + cardEventId: c.cardEventId, + option: 0, + })), + ); + assert.ok(screen.getByText(/To take one back, click its Ship it again\./)); +}); + +test("Ship all stops at the first failure and names the card", async () => { + const a = hold(901); + const b = hold(902, { sha: "c" }); + const listed = [ + [a, true], + [b, true], + ]; + serveBench([DIGEST, a, b, shipAllCheck(listed)], { fail: a.id }); + await renderDigest(); + await waitFor(() => assert.equal(shipAll().disabled, false)); + await act(async () => fireEvent.click(shipAll())); + await click("Yes, ship 2"); + await waitFor(() => screen.getByRole("alert")); + assert.equal( + screen.getByRole("alert").textContent, + `Stopped at 1 of 2: ${a.title}: couldn't save: boom The rest were not tapped.`, + ); + assert.equal(answerCalls().length, 1); +}); + +test("Ship all reads the Bench again before each tap: a card he answered meanwhile is not overwritten", async () => { + const a = hold(901); + const b = hold(902, { sha: "c" }); + const listed = [ + [a, true], + [b, true], + ]; + // While 901 records, he clicks Keep holding on 902 (or taps it on the phone). + const keep = (items) => + Object.assign( + items.find((i) => i.id === b.id), + { recorded: 2, answer: { ...ANSWER, option: 2 } }, + ); + serveBench([DIGEST, a, b, shipAllCheck(listed)], { onAnswer: keep }); + await renderDigest(); + await waitFor(() => assert.equal(shipAll().disabled, false)); + await act(async () => fireEvent.click(shipAll())); + await click("Yes, ship 2"); + await waitFor(() => screen.getByRole("alert")); + assert.equal( + screen.getByRole("alert").textContent, + `Stopped at 2 of 2: ${b.title}: not tapped. You answered or wrote on it meanwhile, or the steward's check no longer clears it.`, + ); + assert.deepEqual( + answerCalls().map((c) => c.itemId), + [a.id], + ); +}); + +test("a conflict the check names keeps Ship all off; other cards have none", async () => { + const a = hold(901); + const why = "reset PR 901 conflicts with main at cccccccccccc (2 files)."; + serveBench([ + DIGEST, + a, + shipAllCheck([], { digest: "not clear", held: [[a, why]] }), + ]); + await act(async () => { + render(wrap(benchCard({ card: DIGEST }))); + render(wrap(benchCard({ card: a }))); + }); + await waitFor(() => screen.getByTestId("bench-ship-all-reason")); + const reason = screen.getByTestId("bench-ship-all-reason").textContent; + assert.ok(reason.startsWith(`${why} It checks again by `), reason); + assert.equal(screen.getAllByRole("button", { name: /^Ship all/ }).length, 1); +}); diff --git a/desktop/src/features/bench/ui/BenchCard.tsx b/desktop/src/features/bench/ui/BenchCard.tsx index 01b8be12bbf..ff5fd04d2f2 100644 --- a/desktop/src/features/bench/ui/BenchCard.tsx +++ b/desktop/src/features/bench/ui/BenchCard.tsx @@ -35,10 +35,12 @@ import { benchCardMeta, benchPostCard, } from "@/features/bench/lib/benchCardLayout"; +import { isStewardDigest } from "@/features/bench/lib/benchShipAll"; import { BenchCardBlocks, BenchCardDetails, } from "@/features/bench/ui/BenchCardFields"; +import { BenchShipAllBar } from "@/features/bench/ui/BenchShipAll"; import { BenchWhyBox, benchWhyAfterClick, @@ -303,6 +305,9 @@ function BenchQuestionCard({ ) : null} + {interactive && isStewardDigest(card) ? ( + + ) : null}
{saving ? (

Saving...

diff --git a/desktop/src/features/bench/ui/BenchScreen.test.mjs b/desktop/src/features/bench/ui/BenchScreen.test.mjs index 5881ee2d25a..015c058b716 100644 --- a/desktop/src/features/bench/ui/BenchScreen.test.mjs +++ b/desktop/src/features/bench/ui/BenchScreen.test.mjs @@ -19,6 +19,8 @@ import { after, afterEach, before, test } from "node:test"; import { JSDOM } from "jsdom"; +import { hold, shipAllCheck } from "../lib/benchShipAll.test-support.mjs"; + const dom = new JSDOM("", { url: "http://localhost", }); @@ -393,6 +395,36 @@ test("screen: only the owner's identity gets live buttons", async () => { assert.equal(answerCalls().length, 0); }); +test("screen: with no digest open, the owner gets the digest's Ship all above Needs you", async () => { + const a = hold(901); + const check = shipAllCheck([[a, true]]); + const show = async (items, viewer = OWNER) => { + cleanup(); + serveIdentity(viewer); + serveSnapshot(snapshot(items)); + await act(async () => { + render(wrap(createElement(BenchScreen))); + }); + await waitFor(() => screen.getByText(a.title)); + return screen.queryAllByRole("button", { name: /^Ship all/ }); + }; + const [bar] = await show([a, check]); + await waitFor(() => assert.equal(bar.disabled, false)); + assert.equal(bar.textContent, "Ship all 1"); + assert.equal( + screen.queryByText("Ship all check"), + null, + "the check stays off the screen", + ); + // A digest is open: its own card carries Ship all, so the screen adds none. + const digest = card("steward/digest-2026-11-15", { + writer: "steward", + options: ["Got it"], + }); + assert.equal((await show([a, digest, check])).length, 1); + assert.equal((await show([a, check], STRANGER)).length, 0); +}); + test("screen: disabled, unreadable and not-yet-ticked Benches say so", async () => { serveIdentity(OWNER); serveSnapshot({ enabled: false }); diff --git a/desktop/src/features/bench/ui/BenchScreen.tsx b/desktop/src/features/bench/ui/BenchScreen.tsx index f55649fb844..4aa25104a99 100644 --- a/desktop/src/features/bench/ui/BenchScreen.tsx +++ b/desktop/src/features/bench/ui/BenchScreen.tsx @@ -4,6 +4,7 @@ import { useAppNavigation } from "@/app/navigation/useAppNavigation"; import { useViewerAgentPubkeys } from "@/features/agents/useKnownAgentPubkeys"; import { type BenchCard as BenchCardData, + benchCardMode, benchQueuedLine, benchSearch, } from "@/features/bench/lib/benchCards"; @@ -12,6 +13,10 @@ import { benchLastTickSeconds, benchSections, } from "@/features/bench/lib/benchScreen"; +import { + isStewardDigest, + shipAllPick, +} from "@/features/bench/lib/benchShipAll"; import { type BenchTab, benchTabs, @@ -25,6 +30,7 @@ import { workbenches, } from "@/features/bench/lib/workbenches"; import { BenchCard } from "@/features/bench/ui/BenchCard"; +import { BenchShipAllBar } from "@/features/bench/ui/BenchShipAll"; import { ColorKeyButton } from "@/features/color-key/ui/ColorKey"; import { useBenchCards } from "@/features/bench/useBenchCards"; import { useProjectsQuery } from "@/features/projects/hooks"; @@ -345,6 +351,15 @@ export function BenchScreen({ focusCardId }: { focusCardId?: string } = {}) { type="search" value={query} /> + {/* The digest's Ship all, while no digest is open (the day's 3 are out, or it closed). */} + {!snapshot.items.some(isStewardDigest) && + shipAllPick(snapshot).candidates.some( + (c) => + benchCardMode(c.card, snapshot.ownerPubkey, viewerPubkey) + .interactive, + ) ? ( + + ) : null} {SECTIONS.map((section) => ( r.label !== "Reach") + .map((r) => `${r.label.toLowerCase()} ${r.text.toLowerCase()}`); + return parts.length > 0 ? parts.join(", ") : "risk and undo not stated"; +} + +/** Give me details: opens the digest's thread, as a card's Open thread does. */ +function BenchShipAllDetailsButton({ + digest, + channelId, +}: { + digest: BenchCard; + channelId: string | null; +}) { + const { goChannel } = useAppNavigation(); + const channel = digest.channelId ?? channelId; + const messageId = digest.cardEventId; + if (!channel || !messageId) { + return ( + + Give me details opens once the digest is on the Bench. + + ); + } + return ( + + ); +} + +/** + * Ship all for one button: the digest card's (no read-first card) or Give me + * details' (every waiting card). It taps the cards the steward's check + * clears; otherwise it is off and says why and when that re-checks. Yes taps + * each card's own Ship it in the steward's order, reading the Bench again + * before each, and waits for its Recorded line before the next. + */ +export function BenchShipAllBar({ + button, + digest, +}: { + button: ShipAllButton; + /** The digest card, for its Give me details. */ + digest?: BenchCard; +}) { + const snapshot = useBenchSnapshot(); + const now = useNow(15_000); + const queryClient = useQueryClient(); + const { mutateAsync: answer } = useBenchAnswer(); + const [run, setRun] = React.useState({ phase: "idle" }); + const reasonId = React.useId(); + if (!snapshot) return null; + const gate = shipAllGate(snapshot, button, now); + const { candidates, left } = shipAllPick(snapshot); + // With none on this button, its reason already says they are all read first. + const later = gate.left.filter((l) => l.readFirst).length; + const readFirst = + button === "digest" && gate.cards.length > 0 + ? candidates.filter((c) => c.readFirst).length + later + : 0; + // While it is off, its reasons already name this button's own cards. + const others = left.length + (gate.enabled ? gate.left.length - later : 0); + + const ship = async (confirmed: ShipAllCard[]) => { + if (running) { + setRun({ + phase: "done", + recorded: 0, + at: Date.now(), + error: "Another Ship all is running: wait for it to finish.", + }); + return; + } + running = true; + const taps = shipAllTaps(confirmed); + setRun({ phase: "running", total: taps.length, step: 0 }); + try { + const result = await runShipAll(taps, { + answer, + // Only what he was shown, and only while each is still waiting and clear. + stillOk: async (tap) => + shipAllStillOk( + await readBenchSnapshot(queryClient), + tap, + button, + Date.now(), + ), + isRecorded: async (tap) => + shipAllRecorded(await readBenchSnapshot(queryClient), tap), + onStep: (step) => + setRun({ phase: "running", total: taps.length, step }), + sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)), + }); + const { recorded, error } = result; + const rest = + recorded + 1 < taps.length ? " The rest were not tapped." : ""; + const message = + error && + `Stopped at ${recorded + 1} of ${taps.length}: ${error}${rest}`; + setRun({ phase: "done", recorded, at: Date.now(), error: message }); + // Also outside this bar, which a new digest can replace mid-run. + if (message) toast.error(message); + else toast.success(`Recorded Ship it on ${recorded} of ${taps.length}.`); + } finally { + running = false; + } + }; + + const busy = run.phase === "confirm" || run.phase === "running"; + const trains = shipAllTrains(snapshot); + return ( +
+
+ + {digest ? ( + + ) : null} +
+ {gate.enabled ? null : ( +

+ {gate.reasons.join(" ")} +

+ )} + {readFirst > 0 ? ( +

+ {readFirst === 1 ? "1 more is" : `${readFirst} more are`} read first + (lane:hold, money, sign-in or database), so{" "} + {readFirst === 1 ? "it ships" : "they ship"} from Give me details. +

+ ) : null} + {button === "digest" && others > 0 ? ( +

+ {others} more can't go on Ship all now: Give me details says why. +

+ ) : null} + {run.phase === "confirm" ? ( +
+ + Ship these {run.cards.length}? + +
    + {run.cards.map((c) => ( +
  1. + {c.card.title} · {riskUndo(c.card)} + {c.readFirst ? " · read first" : ""} +
  2. + ))} +
+

+ One tap each, in this order, at the commit each card shows. A stack + ships bottom first. +

+
+ + +
+
+ ) : null} +
+ {run.phase === "running" ? ( +

+ Recording {run.step + 1} of {run.total}... +

+ ) : null} + {run.phase === "done" && run.recorded > 0 ? ( +
+

+ Recorded Ship it on {run.recorded}{" "} + {run.recorded === 1 ? "card" : "cards"} at{" "} + {formatShipAllTime(run.at)}. +

+ {AFTER_TAPS.map((line) => ( +

{line}

+ ))} +

Trains now: {trains.length ? trains.join("; ") : "none"}.

+
+ ) : null} + {run.phase === "done" && run.error ? ( +

+ {run.error} +

+ ) : null} +
+
+ ); +} diff --git a/desktop/src/features/bench/useBenchCards.ts b/desktop/src/features/bench/useBenchCards.ts index 225187b1960..257082f96ca 100644 --- a/desktop/src/features/bench/useBenchCards.ts +++ b/desktop/src/features/bench/useBenchCards.ts @@ -113,6 +113,15 @@ export function useBenchAnswer() { }); } +/** A snapshot read now, through the shared cache: Ship all's Recorded wait. */ +export async function readBenchSnapshot( + queryClient: QueryClient, +): Promise { + return enabledBenchSnapshot( + await queryClient.fetchQuery({ ...benchCardsQueryOptions, staleTime: 0 }), + ); +} + export type BenchReplyInput = { itemId: string; /** The card the owner saw: the Bench refuses a reply on any other. */ From b806da31f60a82ffe9e4a191dc9a8d1dba85a94f Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Sun, 15 Nov 2026 14:59:57 -0600 Subject: [PATCH 4/5] Bench: Give me details lists every card waiting on a tap Opening the steward digest's thread now shows, under the digest, every hold and stack card Ship all would tap, in full (What changes, Risk and Undo, the commits, the PR link), each with its own Ship it, Send it back and Keep holding, then the Ship all bar below the last of them. That Ship all includes the read-first cards, since each is shown in full above it, and uses the same check, confirm and one-tap-at-a-time run as the digest card's. A sticky header keeps the count and says where the button is. Below, Not in Ship all lists each other waiting card in full with its reason: held by the steward's check, new since the check, a reply, not posted yet, two cards on one PR, or no bound commits; and when the steward checks again. The thread head shows no second Ship all. The last line says typing in the thread ships nothing. Any other thread renders as before. Stack: on feat/bench-ship-all-digest. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- .../src/features/bench/ui/BenchCard.test.mjs | 65 +++++++++++- desktop/src/features/bench/ui/BenchCard.tsx | 3 +- .../features/bench/ui/BenchShipAllDetails.tsx | 99 +++++++++++++++++++ .../messages/ui/MessageThreadPanel.tsx | 6 ++ 4 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 desktop/src/features/bench/ui/BenchShipAllDetails.tsx diff --git a/desktop/src/features/bench/ui/BenchCard.test.mjs b/desktop/src/features/bench/ui/BenchCard.test.mjs index 613a15bee04..f0e606d6e03 100644 --- a/desktop/src/features/bench/ui/BenchCard.test.mjs +++ b/desktop/src/features/bench/ui/BenchCard.test.mjs @@ -26,6 +26,7 @@ import { JSDOM } from "jsdom"; import { ANSWER, + REPLY, hold, shipAllCheck, } from "../lib/benchShipAll.test-support.mjs"; @@ -54,6 +55,7 @@ let createRootRoute; let createRouter; let router; let BenchCard; +let BenchShipAllDetails; let clearBenchWhys; let formatBenchCreated; let useBenchCardForMessage; @@ -205,6 +207,7 @@ before(async () => { createRouter, } = await import("@tanstack/react-router")); ({ BenchCard } = await import("./BenchCard.tsx")); + ({ BenchShipAllDetails } = await import("./BenchShipAllDetails.tsx")); ({ clearBenchWhys } = await import("./BenchWhyBox.tsx")); ({ formatBenchCreated } = await import("../lib/benchCards.ts")); ({ useBenchCardForMessage } = await import("../useBenchCards.ts")); @@ -1360,8 +1363,8 @@ test("Why? on a steward card says the reason goes on the PR, and public unless t ); }); -// Ship all on the steward's digest (benchShipAll.ts): the bar, the confirm -// and the taps in the steward's order. +// Ship all on the steward's digest (benchShipAll.ts): the bar, the confirm, +// the taps in the steward's order, and Give me details' thread block. const DIGEST = card({ id: "steward/digest-2026-11-15", writer: "steward", @@ -1525,7 +1528,7 @@ test("a conflict the check names keeps Ship all off; other cards have none", asy shipAllCheck([], { digest: "not clear", held: [[a, why]] }), ]); await act(async () => { - render(wrap(benchCard({ card: DIGEST }))); + render(wrap(benchCard({ card: DIGEST, onOther: () => {} }))); render(wrap(benchCard({ card: a }))); }); await waitFor(() => screen.getByTestId("bench-ship-all-reason")); @@ -1533,3 +1536,59 @@ test("a conflict the check names keeps Ship all off; other cards have none", asy assert.ok(reason.startsWith(`${why} It checks again by `), reason); assert.equal(screen.getAllByRole("button", { name: /^Ship all/ }).length, 1); }); + +test("Give me details shows every waiting card, read first included, the bar below them, and what is left out", async () => { + const a = hold(901); + const held = hold(903, { readFirst: true, sha: "c" }); + const replied = hold(904, { reply: REPLY, sha: "d" }); + const red = hold(905, { sha: "f" }); + const listed = [ + [held, false], + [a, true], + ]; + const why = "reset PR 905 has red CI on the commit its card names."; + serveBench([ + DIGEST, + a, + held, + replied, + red, + shipAllCheck(listed, { held: [[red, why]] }), + ]); + const message = { + id: DIGEST.cardEventId, + kind: 9, + signerPubkey: WRITER, + tags: [], + }; + const props = { channelId: CHANNEL, message, viewerPubkey: OWNER }; + // The thread head (no Open thread) and the block under it: one Ship all. + await act(async () => { + render(wrap(benchCard({ card: DIGEST }))); + render(wrap(createElement(BenchShipAllDetails, props))); + }); + await waitFor(() => screen.getByText("Waiting on your tap (4)")); + await waitFor(() => assert.equal(shipAll().disabled, false)); + assert.equal(shipAll().textContent, "Ship all 2"); + const block = screen.getByTestId("bench-ship-all-thread"); + const cards = [...block.querySelectorAll("[data-testid='bench-card']")]; + const titles = cards.map( + (c) => c.querySelector("p.font-semibold").textContent, + ); + assert.deepEqual(titles, [held.title, a.title, red.title, replied.title]); + // Below the last card it ships, above what it leaves out. + const bar = screen.getByTestId("bench-ship-all-details"); + const after = (x, y) => + Boolean( + x.compareDocumentPosition(y) & + dom.window.Node.DOCUMENT_POSITION_FOLLOWING, + ); + assert.ok(after(cards[1], bar) && after(bar, cards[2])); + assert.deepEqual( + screen + .getAllByTestId("bench-ship-all-left-reason") + .map((p) => p.textContent), + [why, "You wrote on its card: answer it there."], + ); + assert.ok(screen.getByText(/^Typing in this thread ships nothing/)); +}); diff --git a/desktop/src/features/bench/ui/BenchCard.tsx b/desktop/src/features/bench/ui/BenchCard.tsx index ff5fd04d2f2..67de7b478b4 100644 --- a/desktop/src/features/bench/ui/BenchCard.tsx +++ b/desktop/src/features/bench/ui/BenchCard.tsx @@ -305,7 +305,8 @@ function BenchQuestionCard({ ) : null} - {interactive && isStewardDigest(card) ? ( + {/* The thread head has Give me details' own bar below it instead. */} + {interactive && isStewardDigest(card) && onOther ? ( ) : null}
diff --git a/desktop/src/features/bench/ui/BenchShipAllDetails.tsx b/desktop/src/features/bench/ui/BenchShipAllDetails.tsx new file mode 100644 index 00000000000..edd250491c9 --- /dev/null +++ b/desktop/src/features/bench/ui/BenchShipAllDetails.tsx @@ -0,0 +1,99 @@ +import type { BenchCard as BenchCardData } from "@/features/bench/lib/benchCards"; +import { benchCardMode } from "@/features/bench/lib/benchCards"; +import { + isStewardDigest, + shipAllGate, + shipAllPick, +} from "@/features/bench/lib/benchShipAll"; +import { BenchCard } from "@/features/bench/ui/BenchCard"; +import { BenchShipAllBar } from "@/features/bench/ui/BenchShipAll"; +import { + useBenchCardForMessage, + useBenchSnapshot, +} from "@/features/bench/useBenchCards"; +import type { TimelineMessage } from "@/features/messages/types"; + +/** + * Give me details: under the steward's digest at the head of its thread, + * every card Ship all would tap in full, each with its own buttons, then the + * Ship all bar below the last of them. That Ship all includes read-first + * cards, since each is shown here above it. Then what Ship all leaves out, + * and why. Renders nothing for any other thread. + */ +export function BenchShipAllDetails({ + channelId, + message, + viewerPubkey, +}: { + channelId: string | null; + message: TimelineMessage; + viewerPubkey?: string; +}) { + const match = useBenchCardForMessage({ ...message, channelId }); + const snapshot = useBenchSnapshot(); + if (!match || match.retired || !snapshot || !isStewardDigest(match.card)) { + return null; + } + const { ownerPubkey, maxCards } = snapshot; + if (!benchCardMode(match.card, ownerPubkey, viewerPubkey).interactive) { + return null; + } + const gate = shipAllGate(snapshot, "details", Date.now()); + const left = [...gate.left, ...shipAllPick(snapshot).left]; + const show = (card: BenchCardData) => ( + + ); + return ( +
+
+

+ Waiting on your tap ({gate.cards.length + left.length}) +

+

+ Ship all is below the last card it ships, so you pass each one first. +

+
+
    + {gate.cards.map(({ card }) => ( +
  • {show(card)}
  • + ))} +
+ + {left.length > 0 ? ( +
+

+ Not in Ship all +

+

+ Each says why it is left out. {gate.recheck} +

+
    + {left.map(({ card, reason }) => ( +
  • +

    + {reason} +

    + {show(card)} +
  • + ))} +
+
+ ) : null} +

+ Typing in this thread ships nothing: the steward acts only on taps. +

+
+ ); +} diff --git a/desktop/src/features/messages/ui/MessageThreadPanel.tsx b/desktop/src/features/messages/ui/MessageThreadPanel.tsx index 2448cd6f979..0f6912d4a1c 100644 --- a/desktop/src/features/messages/ui/MessageThreadPanel.tsx +++ b/desktop/src/features/messages/ui/MessageThreadPanel.tsx @@ -1,6 +1,7 @@ import * as React from "react"; import { ArrowDown } from "lucide-react"; +import { BenchShipAllDetails } from "@/features/bench/ui/BenchShipAllDetails"; import { HuddleTranscriptIntro } from "@/features/huddle/components/HuddleTranscriptIntro"; import { buildThreadSummaryFromVisibleEntries, @@ -597,6 +598,11 @@ export function MessageThreadPanel({ )} />
+
)} From 23c627f8260ae98d23365abab58231831320d9be Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Wed, 18 Nov 2026 15:51:32 -0600 Subject: [PATCH 5/5] chore(mobile): remove the one-time compose_bar size ceiling #155 (the Block catch-up) needed a one-time ceiling of 1202 lines for lib/features/channels/compose_bar, because CI compared Block's whole catch-up against a far-behind fork main. #155 is on main now (train #172), so the base holds the over-limit file and the normal hold-or-shrink rule covers it. This reverts 21bbc1c6f. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- mobile/scripts/file-size-policy.mjs | 10 ---------- scripts/check-file-sizes-core.test.mjs | 8 +------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/mobile/scripts/file-size-policy.mjs b/mobile/scripts/file-size-policy.mjs index 19f279d4402..2d05dfb4be5 100644 --- a/mobile/scripts/file-size-policy.mjs +++ b/mobile/scripts/file-size-policy.mjs @@ -1,14 +1,4 @@ export const rules = [ - // Fork only (QuicksilverSlick/buzz #155): Block's compose bar arrives at 1202 - // lines in one catch-up merge. Block's own ratchet allows it because Block's - // base was already over the limit; ours was 1120, so the merge reads as growth. - // shortcut: one-time ceiling for a Block-owned folder; remove it once #155 is - // on main (the base is then over the limit, so hold-or-shrink applies anyway). - { - root: "lib/features/channels/compose_bar", - extensions: new Set([".dart"]), - maxLines: 1202, - }, { root: "lib", extensions: new Set([".dart"]), diff --git a/scripts/check-file-sizes-core.test.mjs b/scripts/check-file-sizes-core.test.mjs index 6935d203168..905a2cea2c9 100644 --- a/scripts/check-file-sizes-core.test.mjs +++ b/scripts/check-file-sizes-core.test.mjs @@ -230,13 +230,7 @@ test("surface entrypoints expose the exact ordered production policies", () => { ["src/shared/styles", [".css"], 1200], ], ], - [ - mobilePolicy, - [ - ["lib/features/channels/compose_bar", [".dart"], 1202], - ["lib", [".dart"], 1200], - ], - ], + [mobilePolicy, [["lib", [".dart"], 1200]]], [ webPolicy, [