diff --git a/.claude/skills/pm-dispatch/SKILL.md b/.claude/skills/pm-dispatch/SKILL.md index 1449bf4de75..d2653ec10f3 100644 --- a/.claude/skills/pm-dispatch/SKILL.md +++ b/.claude/skills/pm-dispatch/SKILL.md @@ -289,7 +289,6 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → L1 审核 → - 终报 JSON 形状住 `.claude/agents/os-dev.md`,⛔ 不抄第二份;`needs_decision` 时 `open_questions` 非空。 - `premise_still_valid: false` + `pr: null` 是合法终报,当再分诊输入作 L1 审核,永不当失败派发。 -- `out_of_scope_findings` 每条 `class: a|b|c`+`reach:`+证据,或 `carrier:`(承接者);皆无 ⇒ Acceptance notes。 - dev 不立卡;ACCEPT 逐条一行 `filed #N`/`Acceptance notes`/`dropped — 因`;三类由席位立在修复仓。 - 席位读 PR `## Acceptance notes`,实属三类的经立卡门补立、归挂;门外已立卡关 not planned。 - 同族发现并入收口卡(一卡覆盖全族位置,带枚举钉子),⛔ 不开单点卡;无则第二次即开。 @@ -312,6 +311,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → L1 审核 → ```text Claim: PM loop round N Session: `session_` +Thread session: `session_` (mode:thread only: the card thread's own session, which knocks the seat mailbox as its delegate; nothing after the id; omit otherwise) Account: `` (the seat's linked user as `GET /user` answers it; always the card's assignee) Branch: `claude/issue--` Worktree: `-issue-` diff --git a/scripts/pm/check-half-states.mjs b/scripts/pm/check-half-states.mjs index 50315415a0b..c519d37d857 100644 --- a/scripts/pm/check-half-states.mjs +++ b/scripts/pm/check-half-states.mjs @@ -15988,11 +15988,28 @@ export function h71UnclaimedOnDutyLane(issue, onDutyLanes, nowMs = Date.now()) { // `knockSignature`): a knock whose signed session the seat it names does not list // reads `unlisted`, and the seat the mailbox serves ⛔ does not act on it // (`untrusted-text.md`). Without this row nobody was told one arrived. The sweep -// builds the roster ONCE, from the two listings it already holds — the open -// `pm:seat` posts (`SEEN_LABEL_PAGES`) and the open pulls (H7's) — and hands it -// to the same `mailboxEvents` call: ⛔ no second signature or roster parser here. -// A roster that cannot be read — a listing truncated at the page ceiling, which -// would make a seat whose post sat on an unread page look unlisted — makes every +// builds the roster ONCE, from the listings it already holds — the open +// `pm:seat` posts (`SEEN_LABEL_PAGES`), the open pulls (H7's) and the open +// `pm:dispatched` cards' threads in `commentCache` (a card thread its seat's open +// claim names knocks as that seat's delegate) — and hands it to the same +// `mailboxEvents` call: ⛔ no second signature or roster parser here, and the +// claim join buys NOTHING (`commentCache.get`, never a fetch). +// +// WHERE in the sweep, and why: the row runs AFTER the dispatch-liveness loop +// (H50's completing walk), not beside the PR listing. Before that loop two +// populations of open `pm:dispatched` cards have no whole thread in the cache: +// (1) a card with no assignee — H2 reads only assigned cards, so nothing is +// cached for it yet — and (2) a card whose first page came back full — whole only +// once H50's walk completes it. H50 walks EVERY open `pm:dispatched` card, first +// page included, so after it both populations are held, at no request beyond the +// ones H50 already makes. What stays unheld is H50's own residue: a walk still +// full at `H50_COMMENT_PAGE_CEILING` or one whose page failed. While such a card +// is open the signature half stays UNJUDGED, every sweep, and the summary names +// the card numbers so a seat can find them. +// +// A roster that cannot be read — a listing truncated at the page ceiling, or a +// claimed card's thread not held whole, which would make a seat whose post sat +// on an unread page, or its card thread, look unlisted — makes every // knock read `unlisted` by the reader's fail-closed rule; this row reads that as // UNJUDGED, lists nothing, and the summary says NOT MEASURED. A `listed` knock is // a consistency reading inside the fleet's trust root, never proof of who rang, @@ -16069,31 +16086,64 @@ export function h72OffTableMailboxLines(reading, nowMs = Date.now()) { ); } -/** The open listing names `noteOpenListing` records for the two listings the H72 roster is read from. */ -export const H72_ROSTER_LISTINGS = Object.freeze({ posts: 'listIssues(pm:seat)', mailboxes: 'listOpenPullRequests' }); +/** The open listing names `noteOpenListing` records for the listings the H72 roster is read from. */ +export const H72_ROSTER_LISTINGS = Object.freeze({ posts: 'listIssues(pm:seat)', mailboxes: 'listOpenPullRequests', claims: 'listIssues(pm:dispatched)' }); /** - * The two listings the sweep hands `seatSessionRoster` (record-recognisers.mjs): the open `pm:seat` posts and the open - * pulls it already holds. Either one is `null` — which the roster reads as `unreadable`, never as an empty listing — + * The listings the sweep hands `seatSessionRoster` (record-recognisers.mjs): first the open `pm:seat` posts and the + * open pulls it already holds. Either one is `null` — which the roster reads as `unreadable`, never as an empty listing — * when the sweep's open listing of it was truncated at the page ceiling (`stats.openListingsTruncated`), or is not an * array. A partial roster would read a knock from a seat whose post sat on an unread page as `unlisted`: a finding * made up from a page nobody read. So it fails to UNJUDGED, never to a smaller roster. Pure. * + * The third listing is the open `pm:dispatched` cards, each with its WHOLE thread (`{ card, rows }`): the roster + * lists the card thread a seat's open claim names (record-recognisers.mjs `claimThreadSession`). The threads are + * the ones the sweep already holds; ⛔ a card whose thread is missing or not whole (`complete` not true — a first + * page that came back full may hide the newest claim) makes `claims` null, and so does a truncated + * `pm:dispatched` listing: a card thread nobody read would read its delegate's knock `unlisted`. `unheld` names + * the numbers of the open `pm:dispatched` cards whose thread is not held whole, so the summary can name them (it is + * not a listing; the roster does not read it). Pure. + * * @param {object[]} issues — the open issue rows the sweep listed (every label page; `pm:seat` rows are kept). * @param {object[]} pulls — the open pull rows the sweep listed. * @param {string[]} [truncated] — the listing names `noteOpenListing` recorded as truncated. + * @param {Map} [threads] — the comment threads the sweep holds, by card. */ -export function h72RosterListings(issues, pulls, truncated = []) { +export function h72RosterListings(issues, pulls, truncated = [], threads = new Map()) { const cut = new Set(Array.isArray(truncated) ? truncated : []); + const held = (issue) => { + const thread = threads instanceof Map ? threads.get(issue.number) : undefined; + return thread?.complete === true && Array.isArray(thread.rows) ? { card: issue, rows: thread.rows } : null; + }; + const dispatched = Array.isArray(issues) + ? issues.filter((issue) => issue && issue.state === 'open' && labelNames(issue).includes('pm:dispatched')) + : null; + const claims = dispatched === null || cut.has(H72_ROSTER_LISTINGS.claims) ? null : dispatched.map(held); return { posts: !Array.isArray(issues) || cut.has(H72_ROSTER_LISTINGS.posts) ? null : issues.filter((issue) => labelNames(issue ?? {}).includes('pm:seat')), mailboxes: !Array.isArray(pulls) || cut.has(H72_ROSTER_LISTINGS.mailboxes) ? null : pulls, + claims: claims === null || claims.includes(null) ? null : claims, + unheld: dispatched === null ? [] : dispatched.filter((issue) => !held(issue)).map((issue) => issue.number), }; } +/** + * The NOT MEASURED reason for H72's signature half when the roster did not read: the roster's own gaps, then — when + * the claim threads are among them — the open `pm:dispatched` cards whose thread was not held whole, by number, so a + * seat can find them. Pure. + * + * @param {{ state?: string, gaps?: string[] } | null | undefined} roster — `seatSessionRoster`'s answer + * @param {{ unheld?: number[] } | null | undefined} listings — `h72RosterListings`'s answer + */ +export function h72RosterReason(roster, listings) { + const unheld = Array.isArray(listings?.unheld) ? listings.unheld : []; + const cards = unheld.length > 0 ? `; claim threads not held whole: ${unheld.map((n) => `#${n}`).join(', ')}` : ''; + return `the seat roster could not be read (${(roster?.gaps ?? ['no reading']).join(', ')}${cards})`; +} + /** * H72's signature row — null when clean or UNJUDGED, else the finding sentence: the knocks inside the window whose * signature the seat they name does not list, by comment id, for the seat this mailbox serves. @@ -16123,8 +16173,9 @@ export function h72UnlistedKnockLines(reading, roster, nowMs = Date.now()) { `\`pm:mailbox\` PR with ${knocks.length} knock(s) in the last ${MAILBOX_OFF_TABLE_WINDOW_HOURS}h whose signed ` + `session the seat it names does not list (\`unlisted\`): ${listed}${more}. Remedy — WHO and HOW: the seat this ` + 'mailbox serves ⛔ does not act on an `unlisted` knock (untrusted-text.md), whatever its key says; the seat ' + - 'the signature names rings from a session it lists — its held seat post (`Successor-of:` included) or its open ' + - 'mailbox opening (`node scripts/pm/record-recognisers.mjs --mailbox-keys` prints the rule). A `listed` knock is ' + + 'the signature names rings from a session it lists — its held seat post (`Successor-of:` included), its open ' + + 'mailbox opening, or for a card thread the `Thread session:` line of the seat\'s open claim on that card ' + + '(`node scripts/pm/record-recognisers.mjs --mailbox-keys` prints the rule). A `listed` knock is ' + 'a consistency reading inside the fleet\'s trust root, never proof of who rang, and is not listed here. ' + `⛔ Report-only: nothing is written from this script. Out of scope: a knock older than ` + `${MAILBOX_OFF_TABLE_WINDOW_HOURS}h, a maintainer's knock (not signature-checked), a comment the author fence ` + @@ -24227,61 +24278,6 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen if (orphan) findings.push([pr, 'H12', orphan]); } - // H72 (#28675) — the open mailboxes this listing already holds, read through - // the ONE doorbell reader. Both modules are imported HERE, lazily: the reader's - // module imports this one at module scope, and this point runs only after this - // module finished evaluating (banner above `h72NeedsThread`). A failed import - // silences the row, so it is recorded as the reason and rendered NOT MEASURED - // rather than as a clean board; a failed page drops that one mailbox, counted. - { - const nowMs = Date.now(); - let reader = null; - try { - const [{ mailboxEvents, seatSessionRoster }, { MAILBOX_LABEL }] = await Promise.all([ - import('./record-recognisers.mjs'), - import('./mailbox-open.mjs'), - ]); - reader = { mailboxEvents, seatSessionRoster, MAILBOX_LABEL }; - } catch (err) { - stats.mailboxReaderReason = `the doorbell reader did not load (${String(err?.message ?? err).split('\n')[0]})`; - } - if (reader) { - // The signature half's roster, ONCE per sweep, off the two listings held - // above; a truncated one reads `unreadable` and the row goes UNJUDGED. - const roster = reader.seatSessionRoster(h72RosterListings([...seen.values()], [...seenPrs.values()], stats.openListingsTruncated)); - if (roster?.state !== 'read') stats.mailboxRosterReason = `the seat roster could not be read (${(roster?.gaps ?? ['no reading']).join(', ')})`; - const since = new Date(nowMs - MAILBOX_OFF_TABLE_WINDOW_HOURS * 3_600_000).toISOString(); - for (const pr of seenPrs.values()) { - if (!h72NeedsThread(pr, reader.MAILBOX_LABEL, nowMs)) continue; - stats.mailboxCandidates = (stats.mailboxCandidates ?? 0) + 1; - // Every page of the window, oldest first as GitHub serves them, so the - // NEWEST bells are never the ones a single page leaves out. A window that - // outruns the ceiling is UNJUDGED, not judged on its oldest pages. - const rows = []; - let complete = false; - try { - for (let page = 1; page <= H72_COMMENT_PAGE_CEILING; page++) { - const batch = await rest(`/repos/${OWNER_REPO}/issues/${pr.number}/comments?since=${encodeURIComponent(since)}&per_page=100&page=${page}`); - rows.push(...(Array.isArray(batch) ? batch : [])); - if (!Array.isArray(batch) || batch.length < 100) { - complete = true; - break; - } - } - } catch { - continue; - } - if (!complete) continue; - stats.mailboxRead = (stats.mailboxRead ?? 0) + 1; - const reading = reader.mailboxEvents(rows, roster); - const offTable = h72OffTableMailboxLines(reading, nowMs); - if (offTable) findings.push([pr, 'H72', offTable]); - const unlisted = h72UnlistedKnockLines(reading, roster, nowMs); - if (unlisted) findings.push([pr, 'H72', unlisted]); - } - } - } - // H76 — an open PR with no assignee, off the listing above, free. The mailbox // label is imported LAZILY for H72's reason (banner above `h72NeedsThread`); // a failed import leaves it unread, and every unowned PR then fires UNJUDGED. @@ -24785,6 +24781,73 @@ async function sweepInto(findings, seen, seenPrs, seenMerged, seenUnscoped, seen stats.dispatchRefTargets = refCache.size; stats.dispatchRefRead = [...refCache.values()].filter((r) => r.state !== 'unreadable').length; + // H72 (#28675) — the open mailboxes the PR listing above holds, read through + // the ONE doorbell reader. Placed HERE, after the dispatch-liveness loop, so + // every open `pm:dispatched` card's thread is in `commentCache` and walked + // (banner above `h72RosterListings`). Both modules are imported HERE, lazily: the reader's + // module imports this one at module scope, and this point runs only after this + // module finished evaluating (banner above `h72NeedsThread`). A failed import + // silences the row, so it is recorded as the reason and rendered NOT MEASURED + // rather than as a clean board; a failed page drops that one mailbox, counted. + { + const nowMs = Date.now(); + let reader = null; + try { + const [{ mailboxEvents, seatSessionRoster }, { MAILBOX_LABEL }] = await Promise.all([ + import('./record-recognisers.mjs'), + import('./mailbox-open.mjs'), + ]); + reader = { mailboxEvents, seatSessionRoster, MAILBOX_LABEL }; + } catch (err) { + stats.mailboxReaderReason = `the doorbell reader did not load (${String(err?.message ?? err).split('\n')[0]})`; + } + if (reader) { + // The signature half's roster, ONCE per sweep, off the listings held above + // and the claimed cards' threads H50's walk left in `commentCache` — + // `.get`, ⛔ never a fetch. A thread is whole only when its walk says so; a + // truncated listing or a thread not held whole reads `unreadable`, the row + // goes UNJUDGED and the reason names the cards. + const claimThreads = new Map(); + for (const issue of seen.values()) { + if (!labelNames(issue).includes('pm:dispatched')) continue; + const rows = commentCache.get(issue.number); + claimThreads.set(issue.number, { rows, complete: Array.isArray(rows) && threadWalks.get(issue.number)?.complete === true }); + } + const listings = h72RosterListings([...seen.values()], [...seenPrs.values()], stats.openListingsTruncated, claimThreads); + const roster = reader.seatSessionRoster(listings); + if (roster?.state !== 'read') stats.mailboxRosterReason = h72RosterReason(roster, listings); + const since = new Date(nowMs - MAILBOX_OFF_TABLE_WINDOW_HOURS * 3_600_000).toISOString(); + for (const pr of seenPrs.values()) { + if (!h72NeedsThread(pr, reader.MAILBOX_LABEL, nowMs)) continue; + stats.mailboxCandidates = (stats.mailboxCandidates ?? 0) + 1; + // Every page of the window, oldest first as GitHub serves them, so the + // NEWEST bells are never the ones a single page leaves out. A window that + // outruns the ceiling is UNJUDGED, not judged on its oldest pages. + const rows = []; + let complete = false; + try { + for (let page = 1; page <= H72_COMMENT_PAGE_CEILING; page++) { + const batch = await rest(`/repos/${OWNER_REPO}/issues/${pr.number}/comments?since=${encodeURIComponent(since)}&per_page=100&page=${page}`); + rows.push(...(Array.isArray(batch) ? batch : [])); + if (!Array.isArray(batch) || batch.length < 100) { + complete = true; + break; + } + } + } catch { + continue; + } + if (!complete) continue; + stats.mailboxRead = (stats.mailboxRead ?? 0) + 1; + const reading = reader.mailboxEvents(rows, roster); + const offTable = h72OffTableMailboxLines(reading, nowMs); + if (offTable) findings.push([pr, 'H72', offTable]); + const unlisted = h72UnlistedKnockLines(reading, roster, nowMs); + if (unlisted) findings.push([pr, 'H72', unlisted]); + } + } + } + // H37 (#12629) — the family-dispatch join, in two rounds (banner at the // predicate). Placed HERE, after the dispatch-liveness loop, because round 1 // is exactly that loop's leftovers: `commentCache` now holds a thread for @@ -25824,8 +25887,11 @@ export const SELF_TEST_BATTERIES = Object.freeze({ // because this self-test cannot import that module (H62's banner). RAISED 20 → 33 // with the signature half (#34013): its predicate both ways, the unjudged roster, // the window, the cap, the text, the roster listings and their truncation names, - // the wiring and the summary clause. - 'H72 mailbox off-table bells': 33, + // the wiring and the summary clause. RAISED 33 → 37 with the claim listing + // (#34013 remainder 2): the listing, its unread and truncated cases, its + // truncation name and the cache-only wiring. RAISED 37 → 39 with review fix r1: + // the row's place after the dispatch-liveness loop and the unheld cards named. + 'H72 mailbox off-table bells': 39, // Registered with the unowned-PR row, pin just under the count: the firing, the assignee/mailbox/closed // exemptions, the unread-label UNJUDGED leg, the text, the band and the wiring. 'H76 unowned open PR': 11, @@ -29196,7 +29262,17 @@ async function selfTest() { b(BATTERY28675, '⭐ H72 roster listings: the open `pm:seat` rows and the open pulls the sweep holds, other cards dropped', (() => { const seat = { number: 1, labels: [{ name: 'pm:seat' }] }; const card = { number: 2, labels: [{ name: 'pm:queue' }] }; const pull = { number: 3 }; const l = h72RosterListings([seat, card, null], [pull]); return l.posts.length === 1 && l.posts[0] === seat && l.mailboxes.length === 1 && l.mailboxes[0] === pull; })(), true); b(BATTERY28675, '⛔ H72 roster listings: a listing truncated at the page ceiling, or not an array, hands the roster NULL — read as unreadable, never as a smaller roster', (() => { const both = h72RosterListings([], [], [H72_ROSTER_LISTINGS.posts, H72_ROSTER_LISTINGS.mailboxes]); const other = h72RosterListings([], [], ['listIssues(pm:queue)']); const bad = h72RosterListings(undefined, 'x'); return both.posts === null && both.mailboxes === null && Array.isArray(other.posts) && Array.isArray(other.mailboxes) && bad.posts === null && bad.mailboxes === null; })(), true); b(BATTERY28675, '⭐ H72 roster listings: the truncation names are the ones the two listings record — `listIssues(pm:seat)` off a label page this sweep lists, `listOpenPullRequests` off the pulls', (() => { const src = SRC72; return SRC72.length > 0 && SEEN_LABEL_PAGES.includes('pm:seat') && src.includes('noteOpenListing(stats, `listIssues(${label})`') && src.includes(`noteOpenListing(stats, '${H72_ROSTER_LISTINGS.mailboxes}'`) && H72_ROSTER_LISTINGS.posts === 'listIssues(pm:seat)'; })(), true); - b(BATTERY28675, '⭐ H72 wiring: the sweep reads the roster ONCE through the reader\'s `seatSessionRoster`, hands it to the same `mailboxEvents` call both rows judge, and parses no signature or roster of its own', (() => { const src = SRC72; return SRC72.length > 0 && src.includes('reader.seatSessionRoster(h72RosterListings([...seen.values()], [...seenPrs.values()], stats.openListingsTruncated))') && src.includes('const reading = reader.mailboxEvents(rows, roster);') && src.includes('h72OffTableMailboxLines(reading, nowMs)') && src.includes('h72UnlistedKnockLines(reading, roster, nowMs)') && !/function (?:seatSessionRoster|knockSignature|readMailboxComment)\b/u.test(src); })(), true); + // -- the claim listing (#34013 remainder 2): the open `pm:dispatched` cards with the WHOLE thread the sweep holds; + // the real reader's join of them is pinned in record-recognisers.mjs's card-thread delegate battery. ---- + const CARD72 = (number, o = {}) => ({ number, state: 'open', labels: [{ name: 'pm:dispatched' }], ...o }); + const HELD72 = (...pairs) => new Map(pairs.map(([n, complete = true]) => [n, { rows: [{ id: n, body: 'Claim: x' }], complete }])); + b(BATTERY28675, '⭐ H72 claim listing: each open `pm:dispatched` card with the whole thread the sweep holds, as `{ card, rows }` — other labels and a closed row dropped', (() => { const a = CARD72(1); const l = h72RosterListings([a, { number: 2, state: 'open', labels: [{ name: 'pm:queue' }] }, CARD72(3, { state: 'closed' }), null], [], [], HELD72([1])); return Array.isArray(l.claims) && l.claims.length === 1 && l.claims[0].card === a && l.claims[0].rows[0].id === 1; })(), true); + b(BATTERY28675, '⛔ H72 claim listing: a card whose thread is missing or NOT whole, a truncated `pm:dispatched` listing, or no issue array hands the roster NULL — unread, never a smaller roster', (() => { const cards = [CARD72(1), CARD72(2)]; return [h72RosterListings(cards, [], [], HELD72([1])).claims, h72RosterListings(cards, [], [], HELD72([1], [2, false])).claims, h72RosterListings(cards, [], [H72_ROSTER_LISTINGS.claims], HELD72([1], [2])).claims, h72RosterListings(undefined, []).claims, h72RosterListings(cards, []).claims].every((c) => c === null) && Array.isArray(h72RosterListings(cards, [], [], HELD72([1], [2])).claims) && JSON.stringify(h72RosterListings([], []).claims) === "[]"; })(), true); + b(BATTERY28675, '⭐ H72 claim listing: the truncation name is the one the `pm:dispatched` label page records, a page this sweep lists', SEEN_LABEL_PAGES.includes('pm:dispatched') && H72_ROSTER_LISTINGS.claims === 'listIssues(pm:dispatched)' && SRC72.includes('noteOpenListing(stats, `listIssues(${label})`'), true); + b(BATTERY28675, '⭐ H72 claim wiring: the threads come out of `commentCache` — `.get`, never a fetch — and a thread is whole only when H50\'s walk says so', (() => { const at = SRC72.indexOf('const claimThreads = new Map();'); const block = at < 0 ? '' : SRC72.slice(at, SRC72.indexOf('const roster = reader.seatSessionRoster(', at)); return block.includes('commentCache.get(issue.number)') && block.includes('threadWalks.get(issue.number)?.complete === true') && !block.includes('H50_COMMENTS_PAGE_SIZE') && !/\brest\(|commentRowsFor|completeCardThread|commentCache\.set/u.test(block); })(), true); + b(BATTERY28675, '⭐ H72 runs AFTER the dispatch-liveness loop: the claim join comes after H50\'s walk of every open `pm:dispatched` card, so an unassigned card and a full first page are held by then — at no request of its own', (() => { const walk = SRC72.indexOf('const walk = await completeCardThread(issue);'); const join = SRC72.indexOf('const claimThreads = new Map();'); const mailboxes = SRC72.indexOf('if (!h72NeedsThread(pr, reader.MAILBOX_LABEL, nowMs)) continue;'); return walk > 0 && join > walk && mailboxes > join; })(), true); + b(BATTERY28675, '⭐ H72 unheld cards: the listing names each open `pm:dispatched` card whose thread is not held whole, and the NOT MEASURED reason names them by number', (() => { const l = h72RosterListings([CARD72(7), CARD72(8), CARD72(9)], [], [], HELD72([7], [8, false])); const why = h72RosterReason({ state: 'unreadable', gaps: ['the open `pm:dispatched` claim threads'] }, l); return l.claims === null && JSON.stringify(l.unheld) === '[8,9]' && why === 'the seat roster could not be read (the open `pm:dispatched` claim threads; claim threads not held whole: #8, #9)' && JSON.stringify(h72RosterListings([CARD72(7)], [], [], HELD72([7])).unheld) === '[]' && h72RosterReason({ state: 'unreadable', gaps: ['x'] }, { unheld: [] }) === 'the seat roster could not be read (x)' && SRC72.includes('stats.mailboxRosterReason = h72RosterReason(roster, listings);'); })(), true); + b(BATTERY28675, '⭐ H72 wiring: the sweep reads the roster ONCE through the reader\'s `seatSessionRoster`, hands it to the same `mailboxEvents` call both rows judge, and parses no signature or roster of its own', (() => { const src = SRC72; return SRC72.length > 0 && src.includes('const listings = h72RosterListings([...seen.values()], [...seenPrs.values()], stats.openListingsTruncated, claimThreads);') && src.includes('const roster = reader.seatSessionRoster(listings);') && src.includes('const reading = reader.mailboxEvents(rows, roster);') && src.includes('h72OffTableMailboxLines(reading, nowMs)') && src.includes('h72UnlistedKnockLines(reading, roster, nowMs)') && !/function (?:seatSessionRoster|knockSignature|readMailboxComment)\b/u.test(src); })(), true); b(BATTERY28675, '⛔ H72 summary: a roster that was not read renders NOT MEASURED for the signature half, a read one says it buys no fetch — and the key rides the forwarding contract', (() => { const no = saidBy('h72Mailbox', summaryLine({ mailboxRead: 1, mailboxCandidates: 1, mailboxRosterReason: 'the seat roster could not be read (x)' }, 0)); const yes = saidBy('h72Mailbox', summaryLine({ mailboxRead: 1, mailboxCandidates: 1 }, 0)); return no.includes('Unlisted knock signatures: NOT MEASURED — the seat roster could not be read (x)') && yes.includes('Unlisted knock signatures: judged on the same pages') && SWEEP_COUNT_KEYS.includes('mailboxRosterReason'); })(), true); b(BATTERY28675, '⭐ H72: the sweep takes the ONE reader and the opener\'s label LAZILY — `mailboxEvents` from record-recognisers.mjs, MAILBOX_LABEL from mailbox-open.mjs — and spells no doorbell key of its own', (() => { const src = readFileSync(fileURLToPath(import.meta.url), 'utf8'); return src.includes("import('./record-recognisers.mjs')") && src.includes("import('./mailbox-open.mjs')") && !/^import [^\n]*from '\.\/(?:record-recognisers|mailbox-open)\.mjs'/mu.test(src) && !src.includes(['MAILBOX_KEYS', '='].join(' ')); })(), true); b(BATTERY28675, 'floor: this battery is DECLARED on the roster, with a positive pin', Object.prototype.hasOwnProperty.call(SELF_TEST_BATTERIES, BATTERY28675) && SELF_TEST_BATTERIES[BATTERY28675] > 0, true); diff --git a/scripts/pm/dispatch-gates.data.mjs b/scripts/pm/dispatch-gates.data.mjs index b11e8055298..d882120ab72 100644 --- a/scripts/pm/dispatch-gates.data.mjs +++ b/scripts/pm/dispatch-gates.data.mjs @@ -513,6 +513,13 @@ export const COMPOUND_ANCHOR_LEDGER = [ * in the rule text — the same population claim, on a second governed file. The * one `self-test-reads` line names both paths, so a card touching either file * derives `check:pm-record-recognisers`. + * + * ## The seventh row: the claim template's `Thread session:` pin + * + * The same self-test reads pm-dispatch `SKILL.md` to pin the claim template's + * one `Thread session:` line against the reader that lists a card thread on + * its seat's roster — the same population claim, on a third governed file, + * named on the same `self-test-reads` line. */ export const GOVERNED_READ_FLOOR = Object.freeze([ Object.freeze({ script: 'scripts/check-commit-card-trailers.mjs', file: '.claude/agents/os-dev.md', declared: false }), @@ -541,6 +548,11 @@ export const GOVERNED_READ_FLOOR = Object.freeze([ file: '.claude/skills/pm-dispatch/references/contract-review.md', declared: true, }), + Object.freeze({ + script: 'scripts/pm/record-recognisers.mjs', + file: '.claude/skills/pm-dispatch/SKILL.md', + declared: true, + }), ]); /** diff --git a/scripts/pm/record-recognisers.mjs b/scripts/pm/record-recognisers.mjs index 13377cfee43..41ab9301da1 100644 --- a/scripts/pm/record-recognisers.mjs +++ b/scripts/pm/record-recognisers.mjs @@ -33,7 +33,7 @@ * isOutsideReviewSurface the prose faces a head may move on and keep its record * contractReviewTemplateLines / contractReviewRecordLines what `--template` prints * contractReviewBriefLines what `--brief-template` prints — the brief a seat hands its reviewer - * readMailboxLine / mailboxEvents / MAILBOX_KEYS the mailbox DOORBELL — `To: `, then one key of the table a `pm:mailbox` comment may carry, read; anything else refused; `mailboxKeyLines` is what `--mailbox-keys` prints; `readMailboxComment` / `MAILBOX_KNOCK_AUTHORS` its AUTHOR fence — a knock counts only from the relay or a `GOVERNED_APPROVERS` account, any other author ignored and its body never read; `seatSessionRoster` / `knockSignature` its SIGNATURE LISTING — a relay knock whose signed session the seat it names does not list reads `unlisted` (`unverified seat signature`), never acted on; `listed` is a consistency check inside the fleet's trust root, ⛔ never proof of who rang (a copied signature line reads `listed`) + * readMailboxLine / mailboxEvents / MAILBOX_KEYS the mailbox DOORBELL — `To: `, then one key of the table a `pm:mailbox` comment may carry, read; anything else refused; `mailboxKeyLines` is what `--mailbox-keys` prints; `readMailboxComment` / `MAILBOX_KNOCK_AUTHORS` its AUTHOR fence — a knock counts only from the relay or a `GOVERNED_APPROVERS` account, any other author ignored and its body never read; `seatSessionRoster` / `knockSignature` its SIGNATURE LISTING — a relay knock whose signed session the seat it names does not list reads `unlisted` (`unverified seat signature`), never acted on; `listed` is a consistency check inside the fleet's trust root, ⛔ never proof of who rang (a copied signature line reads `listed`); `claimThreadSession` the claim's `Thread session:` line, ONE spelling — the card thread an open card's newest, unreleased claim names joins the roster of the seat that claim is signed by, as its delegate — a claim row read only from the knock's own authors (`MAILBOX_KNOCK_AUTHORS`) * * Every definition below was MOVED, names unchanged, out of * `check-clause2-carriers.mjs` at the ruling's last step, which deleted the @@ -74,7 +74,7 @@ // row is `GOVERNED_READ_FLOOR` in `dispatch-gates.data.mjs`). The derivation // grades it against the read the self-test really performs, so it cannot be // satisfied by deleting either half. -// dispatch-gates: self-test-reads .claude/skills/pm-dispatch/references/project-forms.md .claude/skills/pm-dispatch/references/contract-review.md -- the mailbox doorbell battery pins the key table both ways against project-forms.md's 〈信箱 PR〉 section (every key named there, no other key named there), the claim-line battery pins the `Contract-review-claim:` template and its lapse hours in contract-review.md, and the hold-line battery pins the `Contract-review-hold:` template and its listing hours there, so a change to any of those spellings is judged here +// dispatch-gates: self-test-reads .claude/skills/pm-dispatch/references/project-forms.md .claude/skills/pm-dispatch/references/contract-review.md .claude/skills/pm-dispatch/SKILL.md -- the mailbox doorbell battery pins the key table both ways against project-forms.md's 〈信箱 PR〉 section (every key named there, no other key named there), the claim-line battery pins the `Contract-review-claim:` template and its lapse hours in contract-review.md, the hold-line battery pins the `Contract-review-hold:` template and its listing hours there, and the card-thread delegate battery pins the claim template's one `Thread session:` line in SKILL.md 〈模板与表〉 against `claimThreadSession`, so a change to any of those spellings is judged here import process from 'node:process'; import { execFileSync, spawnSync } from 'node:child_process'; @@ -85,6 +85,7 @@ import { fileURLToPath } from 'node:url'; import { gitFreeEnv } from '../git-env.mjs'; import { isEntrypoint } from '../invoked-as.mjs'; import { + CLAIM_COMMENT_MARKER, CONTRACT_REVIEW_HEADING_MARKER, CONTRACT_REVIEW_SECURITY_TOUCHING_KEY, CONTRACT_REVIEW_SECURITY_TOUCHING_VALUES, @@ -102,9 +103,12 @@ import { labelNames, readSignatureLine, refsTargets, + RELEASE_COMMENT_MARKER, + releaseAnswersClaim, SEAT_SIGNATURE_SESSION_SOURCE, seatOnDuty, stripSignatureLine, + yieldedClaimIndexes, } from './check-half-states.mjs'; // The fleet's one verdict reader, in its counting form, re-exported so the queue guard's lazy loader // reaches it: every Tier S entry lands on a record with exactly one `VERDICT:` line reading PASS @@ -1770,11 +1774,81 @@ function mailboxOpeningSession(body) { return MAILBOX_OPENING_FOOTER.exec(lines.at(-1) ?? '')?.[1] ?? null; } +/** The claim template's `Thread session:` line (pm-dispatch SKILL.md 〈模板与表〉), its ONE spelling: one backticked id, nothing after it. */ +const CLAIM_THREAD_SESSION_LINE = new RegExp(`^Thread session: \`(${SEAT_SIGNATURE_SESSION_SOURCE})\`[ \\t]*$`, 'u'); +/** Any line that reads as that key, however decorated — what makes a second or a misspelt `Thread session:` line count. */ +const CLAIM_THREAD_SESSION_KEY = /^[ \t]*(?:[-*+][ \t]+)?>?[ \t]*(?:\*\*)?`?thread[ _-]?session`?(?:\*\*)?[ \t]*[::]/iu; + +/** + * The card thread a `Claim:` names on its `Thread session:` line — the session that implements the card in + * `mode:thread` and knocks the seat's mailbox as the seat's DELEGATE — or null. ONE key, ONE spelling, the + * template's: the line starts the line, the value is one backticked session id (`SEAT_SIGNATURE_SESSION_SOURCE`, + * the signature's own session shape), and nothing follows it. ⛔ Everything else reads null, never a guess: a + * bare or decorated key, a value with prose around it, a session written in prose on the `Session:` line (the + * first session there is `claimSessionId`'s, another reader's question), no key at all, and TWO lines that read as + * the key — one claim naming two threads cannot say which one knocks. A null adds nothing to the roster and never + * fails it. Pure. + * + * @param {string} body — a claim comment's body + * @returns {string | null} + */ +export function claimThreadSession(body) { + const keyed = String(body ?? '').split(/\r?\n/).filter((line) => CLAIM_THREAD_SESSION_KEY.test(line)); + if (keyed.length !== 1) return null; + return CLAIM_THREAD_SESSION_LINE.exec(keyed[0])?.[1] ?? null; +} + +/** + * The card-thread delegate one OPEN card's thread lists, or null: `{ seat, session, where }` when the thread's + * NEWEST claim (`latestMarkedComment` over `CLAIM_COMMENT_MARKER`, the recency rule every claim reader shares; + * a claim its own session yielded, `yieldedClaimIndexes`, is not a claim) is signed by a seat + * (`readSignatureLine`, `seatKey`) and names its card thread (`claimThreadSession`), and no `Release:` answers it + * (`releaseAnswersClaim`). So a released claim, a claim a newer one superseded — another seat's included — and a + * closed card list nobody. + * + * ⛔ AUTHOR RULE FIRST: only the rows whose author the knock's own fence trusts (`MAILBOX_KNOCK_AUTHORS`, read + * with `recordAuthorTrusted` as `readMailboxComment` reads it — ⛔ no second author list) are read at all. A row + * that names no author, or one outside that rule, is not the fleet's word: it lists nobody, and it neither + * supersedes, yields nor releases a claim — the claim, yield and release readers run on the fenced rows only. + * + * What it does NOT do, as intended: + * - the signer's session is not compared: the claim's signature names the seat, and its session is not checked + * against what that seat lists elsewhere; + * - a claim does not lapse by age: it lists until it is released, superseded or its card closes (a stale claim + * is the claim-liveness rows' finding, not this roster's); + * - a card closed and REOPENED with its newest claim never released lists that claim's thread again — the card + * is open and the claim is still its newest, the reading every claim reader shares; + * - the seat's post is not consulted: a seat whose post is no longer held keeps its open claims' threads listed + * until each claim is released or superseded — the claim, not the post, is the record of whom it dispatched. + * Pure. + */ +function claimDelegate(card, rows) { + if (!card || card.state !== 'open' || card.pull_request) return null; + rows = rows.filter((row) => recordAuthorTrusted(row, MAILBOX_KNOCK_AUTHORS)); + const yielded = yieldedClaimIndexes(rows); + const live = rows.map((row, index) => ({ row, index })).filter(({ index }) => !yielded.has(index)); + const newest = latestMarkedComment(live.map(({ row }) => row), CLAIM_COMMENT_MARKER); + if (!newest) return null; + const { row, index } = live[newest.index]; + if (releaseAnswersClaim(latestMarkedComment(rows, RELEASE_COMMENT_MARKER), { ...newest, index })) return null; + const signed = readSignatureLine(row?.body); + const seat = signed ? seatKey(`${signed.lane}#${signed.seat}`) : null; + const session = claimThreadSession(row?.body); + if (!seat || !session) return null; + return { seat: seat.key, session, where: `claim on #${card.number} (comment ${row?.id ?? '?'}) Thread session` }; +} + /** - * The sessions each seat LISTS — the roster a knock's signature line is compared with. Read off the two records a - * seat keeps of who sits it (`seat-post-protocol.md`; `project-forms.md` 〈信箱 PR〉), both bodies only the relay - * writes — so any fleet session can write them too, and their authors are not read: the roster is the fleet's own - * word about itself, the trust root a `listed` reading stands inside (`readMailboxComment`, ⛔ never proof): + * The sessions each seat LISTS — the roster a knock's signature line is compared with. Read off the records a + * seat keeps of who sits it (`seat-post-protocol.md`; `project-forms.md` 〈信箱 PR〉) and of whom it dispatched. The + * roster is the fleet's own word about itself, the trust root a `listed` reading stands inside + * (`readMailboxComment`, ⛔ never proof), and each source holds to it its own way: + * + * - a seat post and a mailbox opening are BODIES only the relay writes, so any fleet session can write them too, + * and their authors are not read; + * - a claim is a COMMENT on a card, which any author can post, so its rows' authors ARE read: only a row whose + * author the knock's own fence trusts (`MAILBOX_KNOCK_AUTHORS`) counts, and any other row — no author, or one + * outside the rule — lists nobody and neither supersedes nor releases a claim (`claimDelegate`). * * a seat post an open `pm:seat` issue whose title is 🟢 (`seatOnDuty` — a vacant or paused post lists nobody) * lists, for the seat its FIRST-LINE signature names (`readSignatureLine`, the one reader), that @@ -1785,18 +1859,25 @@ function mailboxOpeningSession(body) { * a mailbox an open `pm:mailbox` pull whose body names its seat (`mailboxOwner`, the opener's own reading) * opening lists the session its footer names — the session that opened it at seating. So a successor's * session the post lists reads `listed` on a mailbox its predecessor opened, and the reverse. - * - * ⛔ Fail closed: either listing not an array reads `{ state: 'unreadable', gaps }`, never an empty roster, and a - * row lists only when its `state` reads `open` — a closed row, or one with no `state` at all, lists nobody. + * a claim `{ card, rows }`, an open card and its WHOLE comment thread: the card thread its newest claim + * names (`claimDelegate`), for the seat that claim's own signature names — the session that knocks + * as that seat's delegate, listed only while the claim is open: released, superseded or closed, + * it drops. `claims` omitted lists no card thread (they read `unlisted`, as before). + * + * ⛔ Fail closed: any listing that is not an array — `claims` handed in as anything but an array or omitted, or + * one of its threads not an array — reads `{ state: 'unreadable', gaps }`, never a smaller roster, and a row + * lists only when its `state` reads `open` — a closed row, or one with no `state` at all, lists nobody. * Rows in, `{ state: 'read', seats }` out — `seats` a Map from a seat's canonical key (`seatKey`) to a Map of each * session it lists to where it is listed. Pure. * - * @param {{ posts?: object[], mailboxes?: object[] }} listings — the open `pm:seat` issues and the open pulls + * @param {{ posts?: object[], mailboxes?: object[], claims?: { card: object, rows: object[] }[] }} listings — the + * open `pm:seat` issues, the open pulls, and the open claimed cards with their whole threads */ -export function seatSessionRoster({ posts, mailboxes } = {}) { +export function seatSessionRoster({ posts, mailboxes, claims = [] } = {}) { const gaps = []; if (!Array.isArray(posts)) gaps.push('the open `pm:seat` posts'); if (!Array.isArray(mailboxes)) gaps.push('the open `pm:mailbox` pulls'); + if (!Array.isArray(claims) || claims.some((entry) => !Array.isArray(entry?.rows))) gaps.push('the open `pm:dispatched` claim threads'); if (gaps.length > 0) return { state: 'unreadable', gaps }; const seats = new Map(); const list = (seat, session, where) => { @@ -1820,6 +1901,10 @@ export function seatSessionRoster({ posts, mailboxes } = {}) { const session = seat ? mailboxOpeningSession(pr.body) : null; if (session) list(seat, session, `mailbox opening #${pr.number}`); } + for (const { card, rows } of claims) { + const delegate = claimDelegate(card, rows); + if (delegate) list(delegate.seat, delegate.session, delegate.where); + } return { state: 'read', seats }; } @@ -1843,7 +1928,7 @@ export function knockSignature(body, roster) { const seat = seatKey(`${signed.lane}#${signed.seat}`)?.key ?? null; if (!seat) return unlisted(`\`${signed.lane}#${signed.seat}\` names no seat a mailbox serves`); const listed = roster.seats.get(seat); - if (!listed || listed.size === 0) return unlisted(`${seat} lists no session (no held seat post signed by it, no open mailbox opening)`); + if (!listed || listed.size === 0) return unlisted(`${seat} lists no session (no held seat post signed by it, no open mailbox opening, no open claim naming its card thread)`); if (!listed.has(signed.session)) return unlisted(`${signed.session} is not a session ${seat} lists`); const also = [...roster.seats].filter(([other, sessions]) => other !== seat && sessions.has(signed.session)).map(([other]) => other); if (also.length > 0) return unlisted(`${signed.session} is listed by ${also.join(', ')} too, so it cannot say which seat rang`); @@ -1860,7 +1945,7 @@ export function mailboxKeyLines() { `Mailbox doorbell — the comment's first line is \`To: \` (LANE#N), the next is ONE of these ${MAILBOX_KEYS.length} keys:`, `one event, one line of at most ${MAILBOX_LINE_MAX_BYTES} bytes, keys and numbers only; anything else is a half-state.`, `A knock counts only from ${MAILBOX_KNOCK_AUTHORS.join(', ')}; any other author is ${MAILBOX_IGNORED_AUTHOR.replace(/^ignored: /, 'ignored — ')}, its body never read.`, - `A relay knock opens with its seat signature (LANE#N · ACCOUNT · SESSION), from a session that seat lists — its held seat post (Successor-of: included) or its open mailbox opening; any other is ${MAILBOX_UNVERIFIED_SIGNATURE}, not acted on. Listed is consistency, not proof: a copied signature line also reads listed.`, + `A relay knock opens with its seat signature (LANE#N · ACCOUNT · SESSION), from a session that seat lists — its held seat post (Successor-of: included), its open mailbox opening, or the Thread session: line of its open claim on a card (a card thread, as the seat's delegate; a claim counts only from an author the knock fence trusts); any other is ${MAILBOX_UNVERIFIED_SIGNATURE}, not acted on. Listed is consistency, not proof: a copied signature line also reads listed.`, '', ...MAILBOX_KEYS.flatMap((k) => [k.template, ` ${k.from} → ${k.to}; ${k.when}`]), '', @@ -2722,6 +2807,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the mailbox doorbell: `To: `, then one key of the table read — seat, kind, numbers, sha, login, time — and anything else refused': 51, // The knock signature listing (#34013): a relay knock its named seat does not list is never acted on. '⭐ the knock signature listing: a relay knock the seat it names does not list reads `unverified seat signature` — and a listed one is consistency, never proof': 18, + // The card-thread delegate (#34013 remainder 2): a claim's `Thread session:` line, one spelling, joins its signing seat's roster. + '⭐ the card-thread delegate: the session an open claim names on its `Thread session:` line joins the roster of the seat that signed it — one spelling, dropped when released, superseded or closed': 17, '⭐ the signature line: the reader reads LANE#N · ACCOUNT · SESSION exactly, and one leading signature changes no first-line reading': 22, '⭐ the `Contract-review-claim:` line — session, FULL head, time; lapses on a moved head or after two hours; the earliest live claim holds': 24, '⭐ the `Contract-review-hold:` line — session, head, reason, until; a new head clears it; at 24 hours it reads overdue and still holds': 23, @@ -2748,7 +2835,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ // Raised 15 → 16 with the claim-line battery (the maintainer's one-claim-per-head rule): one battery, one row. // Raised 16 → 17 with the hold-line battery (the maintainer's lane-hold rule): one battery, one row. // Raised 17 → 18 with the knock-signature battery (#33789 item 3, split to #34013): one battery, one row. -const SELF_TEST_BATTERY_FLOOR = 18; +// Raised 18 → 19 with the card-thread delegate battery (#34013 remainder 2): one battery, one row. +const SELF_TEST_BATTERY_FLOOR = 19; // The key an assertion is filed under when no battery is open. It is not a // declared battery, so it reds by the same set difference rather than silently @@ -3485,7 +3573,7 @@ export async function selfTest() { t('⛔ ANOTHER seat\'s session signing as this seat is unlisted and NOT consistent — seat 2 ringing as seat 1, though its own post names seat 1\'s session in prose — while its vocabulary reading still reads', (() => { const r = read(KNOCK('domain:skills#1', S2)); return r.state === 'read' && r.consistent === false && r.signature.state === 'unlisted' && r.signature.reason.startsWith(MAILBOX_UNVERIFIED_SIGNATURE) && r.signature.reason.includes(`${S2} is not a session domain:skills#1 lists`) && read(KNOCK('domain:skills#2', S1)).signature.state === 'unlisted'; })()); t('⛔ a session no seat lists — a card thread ringing under its seat\'s signature — is unlisted', why(KNOCK('domain:skills#1', STRAY)).includes(`${STRAY} is not a session domain:skills#1 lists`)); t('⛔ a knock with NO signature line is unlisted — `To:` first, or the signature below the key line', [why(DB_ROW(MSG('Notify: landed · #28562'))), why(DB_ROW(`${MSG('Notify: landed · #28562')}\n${SIG('domain:skills#1', S1)}`))].every((w) => w === `${MAILBOX_UNVERIFIED_SIGNATURE} — the knock opens with no seat signature line`)); - t('⛔ a vacant or paused post lists NOBODY — its last session signing as it reads `lists no session` — and so does a seat with neither a post nor an opening', SAME([why(KNOCK('domain:skills#3', S3)), why(KNOCK('domain:ui#9', S3)), seatSessionRoster({ posts: [POST(29747, '[PM seat] domain:skills · seat 3 — ⏸️ paused', `${SIG('domain:skills#3', S3)}\n`)], mailboxes: [] }).seats.size].join('|'), `${MAILBOX_UNVERIFIED_SIGNATURE} — domain:skills#3 lists no session (no held seat post signed by it, no open mailbox opening)|${MAILBOX_UNVERIFIED_SIGNATURE} — domain:ui#9 lists no session (no held seat post signed by it, no open mailbox opening)|0`)); + t('⛔ a vacant or paused post lists NOBODY — its last session signing as it reads `lists no session` — and so does a seat with neither a post nor an opening', SAME([why(KNOCK('domain:skills#3', S3)), why(KNOCK('domain:ui#9', S3)), seatSessionRoster({ posts: [POST(29747, '[PM seat] domain:skills · seat 3 — ⏸️ paused', `${SIG('domain:skills#3', S3)}\n`)], mailboxes: [] }).seats.size].join('|'), `${MAILBOX_UNVERIFIED_SIGNATURE} — domain:skills#3 lists no session (no held seat post signed by it, no open mailbox opening, no open claim naming its card thread)|${MAILBOX_UNVERIFIED_SIGNATURE} — domain:ui#9 lists no session (no held seat post signed by it, no open mailbox opening, no open claim naming its card thread)|0`)); t('⛔ FAIL CLOSED with no roster: none handed in, an unreadable one (either listing not an array) and a malformed one all read unlisted — never an empty roster, never a pass', SAME([readMailboxComment(KNOCK('domain:skills#1', S1)).signature.reason, read(KNOCK('domain:skills#1', S1), seatSessionRoster({ posts: null, mailboxes })).signature.reason, read(KNOCK('domain:skills#1', S1), seatSessionRoster({ posts })).signature.reason, read(KNOCK('domain:skills#1', S1), { state: 'read', seats: {} }).signature.state, seatSessionRoster().state], [`${MAILBOX_UNVERIFIED_SIGNATURE} — no seat roster was read (none was handed in)`, `${MAILBOX_UNVERIFIED_SIGNATURE} — no seat roster was read (the open \`pm:seat\` posts)`, `${MAILBOX_UNVERIFIED_SIGNATURE} — no seat roster was read (the open \`pm:mailbox\` pulls)`, 'unlisted', 'unreadable'])); t('⛔ a session TWO seats list cannot say which rang — unlisted for each of them', (() => { const r = seatSessionRoster({ posts, mailboxes: [...mailboxes, MAILBOX(33921, 'domain:skills#2', S1)] }); return why(KNOCK('domain:skills#1', S1), r).includes(`${S1} is listed by domain:skills#2 too`) && why(KNOCK('domain:skills#2', S1), r).includes(`${S1} is listed by domain:skills#1 too`) && read(KNOCK('domain:skills#2', S2), r).signature.state === 'listed'; })()); t('⛔ what lists nothing: a post with no signature line, one not labelled `pm:seat`, a closed post, a pull row, a closed or seat-less mailbox, an opening with the bare footer — and a signature naming no seat a mailbox serves', (() => { const r = seatSessionRoster({ posts: [POST(1, '[PM seat] domain:ui — 🟢 os-pm', `## Current PM\n\n\`${STRAY}\``), POST(2, '[PM seat] domain:ui · seat 2 — 🟢 os-pm', SIG('domain:ui#2', STRAY), { labels: [] }), POST(3, '[PM seat] domain:ui · seat 3 — 🟢 os-pm', SIG('domain:ui#3', STRAY), { state: 'closed' }), POST(4, '[PM seat] domain:ui · seat 4 — 🟢 os-pm', SIG('domain:ui#4', STRAY), { pull_request: {} })], mailboxes: [MAILBOX(5, 'domain:ui#5', STRAY, { state: 'closed' }), MAILBOX(6, 'domain:ui#6', STRAY, { body: 'To: os-pm\n\nlegacy' }), MAILBOX(7, 'domain:ui#7', null)] }); return r.state === 'read' && r.seats.size === 0 && why(KNOCK('coordinator#1', S1)) === `${MAILBOX_UNVERIFIED_SIGNATURE} — \`coordinator#1\` names no seat a mailbox serves`; })()); @@ -3503,6 +3591,54 @@ export async function selfTest() { const ROWS_H72 = [{ ...KNOCK('domain:skills#1', S1), id: 8201 }, { ...KNOCK('domain:skills#1', STRAY), id: 8202 }, DB_ROW(DB.ut, 8203, '2026-10-28T07:00:00Z', GOVERNED_APPROVERS[0]), DB_ROW(DRIVE_BY, 8204, '2026-10-28T07:00:00Z', 'drive-by-commenter')]; t('⭐ H72 lists the REAL reader\'s `unlisted` knock for the seat the mailbox serves — by comment id, naming the stray session — and not the listed knock, the maintainer\'s or the drive-by', await (async () => { const hs = await import('./check-half-states.mjs'); const r = seatSessionRoster(hs.h72RosterListings([...posts, { number: 1, state: 'open', labels: [{ name: 'pm:queue' }] }], [...mailboxes, { number: 2, state: 'open', labels: [] }])); const row = String(hs.h72UnlistedKnockLines(mailboxEvents(ROWS_H72, r), r, NOW_H72) ?? ''); return r.state === 'read' && row.includes('1 knock(s)') && row.includes('comment 8202') && row.includes(`${STRAY} is not a session domain:skills#1 lists`) && !['comment 8201', 'comment 8203', 'comment 8204'].some((c) => row.includes(c)); })()); t('⛔ …and a TRUNCATED `pm:seat` listing makes the real roster unreadable, so the reader reads every relay knock `unlisted` (fail closed) while H72 lists NONE of them — unjudged, never a finding against a roster nobody read', await (async () => { const hs = await import('./check-half-states.mjs'); const r = seatSessionRoster(hs.h72RosterListings(posts, mailboxes, [hs.H72_ROSTER_LISTINGS.posts])); const reading = mailboxEvents(ROWS_H72, r); return r.state === 'unreadable' && SAME(reading.unlisted, [8201, 8202]) && hs.h72UnlistedKnockLines(reading, r, NOW_H72) === null; })()); + + // -- the card-thread delegate (#34013 remainder 2, seat ruling: option A) ------------------------------------ + // + // A card thread knocks its seat's mailbox as the seat's DELEGATE, so the seat's roster lists the session its + // open claim names on the template's ONE `Thread session:` spelling — only while that claim is the card's + // newest, unreleased claim on an open card, and only for the seat the claim's own signature names. + battery('⭐ the card-thread delegate: the session an open claim names on its `Thread session:` line joins the roster of the seat that signed it — one spelling, dropped when released, superseded or closed'); + { + const T = 'session_01CardThreadDelegateGggg'; + const T2 = 'session_01CardThreadSecondHhhhhh'; + const S_UI = 'session_01UiSeatTwoIiiiiiiiiiiii'; + const CARD = (number, o = {}) => ({ number, state: 'open', labels: [{ name: 'pm:dispatched' }], ...o }); + const CLAIM = (id, at, seat, seatSession, lines, signed = true) => ({ id, created_at: at, user: { login: RELAY_COMMENT_AUTHOR }, body: `${signed ? `${SIG(seat, seatSession)}\n\n` : ''}Claim: PM loop round 1\n${lines.join('\n')}\nAccount: \`os-pm\`\nBranch: \`claude/project-thread-x\`\nSeat: \`${seat}\`\n` }); + const OWN = (thread) => [`Session: \`${S2}\``, thread]; + const TEMPLATE = `Thread session: \`${T}\``; + const R = (claims, more = {}) => seatSessionRoster({ posts, mailboxes, claims, ...more }); + const ONE = (rows, card = CARD(34013)) => R([{ card, rows }]); + const DELEGATE = (r, seat = 'domain:skills#2', session = T) => read(KNOCK(seat, session), r).signature; + const BASE = [CLAIM(1, '2026-11-16T03:16:00Z', 'domain:skills#2', S2, OWN(TEMPLATE))]; + t('⭐ the template\'s spelling, with a real id, reads its session — the key starting the line, the backticked id, nothing after it but blanks', claimThreadSession(TEMPLATE) === T && claimThreadSession(`${TEMPLATE} `) === T && claimThreadSession(`Claim: x\r\n${TEMPLATE}\r\nSeat: y`) === T); + t('⭐ the GOVERNED template (pm-dispatch SKILL.md 〈模板与表〉) carries exactly ONE line that reads as the key, the backticked placeholder directly after it, its note saying nothing follows the id — and that spelling with a real id is the one the reader reads', (() => { const skill = readFileSync(new URL('../../.claude/skills/pm-dispatch/SKILL.md', import.meta.url), 'utf8'); const keyed = skill.split(/\r?\n/).filter((line) => CLAIM_THREAD_SESSION_KEY.test(line)); const head = 'Thread session: `session_`'; return keyed.length === 1 && keyed[0].startsWith(`${head} (`) && keyed[0].includes('nothing after the id') && claimThreadSession(head.replace('session_', T)) === T && claimThreadSession(keyed[0].replace('session_', T)) === null; })()); + t('⭐ the template spelling JOINS the roster: the card thread ringing under its seat\'s signature reads `listed`, via the claim it was named on', (() => { const s = DELEGATE(ONE(BASE)); return s.state === 'listed' && s.seat === 'domain:skills#2' && s.session === T && s.via === 'claim on #34013 (comment 1) Thread session'; })()); + const OTHER = { + 'a bare id': [`Session: \`${S2}\``, `Thread session: ${T}`], + 'a list bullet': [`Session: \`${S2}\``, `- Thread session: \`${T}\``], + 'a bold key': [`Session: \`${S2}\``, `**Thread session:** \`${T}\``], + 'a prose tail': [`Session: \`${S2}\``, `Thread session: \`${T}\` (card thread, dev)`], + 'a hyphenated key': [`Session: \`${S2}\``, `Thread-session: \`${T}\``], + 'the session in prose on the `Session:` line': [`Session: \`${T}\` (card thread, dev) · seat \`${S2}\``], + 'no session at all': [`Session: a card thread opened under seat \`${S2}\``], + 'two key lines': [`Session: \`${S2}\``, TEMPLATE, `Thread session: \`${T2}\``], + 'the template placeholder': [`Session: \`${S2}\``, 'Thread session: `session_` (mode:thread only)'], + }; + t('⛔ every OTHER spelling reads null — a bare id, a bullet, a bold key, a prose tail, a hyphenated key, the measured prose on the `Session:` line, no session, two key lines, the template\'s placeholder', Object.values(OTHER).every((lines) => claimThreadSession(CLAIM(1, 'x', 'domain:skills#2', S2, lines).body) === null)); + t('⛔ …and each joins NOTHING: the thread\'s knock reads unlisted, never a guess at a session in prose', Object.values(OTHER).every((lines) => { const r = ONE([CLAIM(1, '2026-11-16T03:16:00Z', 'domain:skills#2', S2, lines)]); return r.state === 'read' && DELEGATE(r).state === 'unlisted' && DELEGATE(r, 'domain:skills#2', T2).state === 'unlisted' && DELEGATE(r, 'domain:skills#2', S2).state === 'listed'; })); + t('⛔ a RELEASED claim drops its thread — and a release OLDER than a fresh claim does not', (() => { const rel = { id: 2, created_at: '2026-11-16T04:00:00Z', user: { login: RELAY_COMMENT_AUTHOR }, body: `${SIG('domain:skills#2', S2)}\n\nRelease: \`${S2}\` · premise moved · back to pm:queue` }; return DELEGATE(ONE([...BASE, rel])).state === 'unlisted' && DELEGATE(ONE([{ ...rel, created_at: '2026-11-16T03:00:00Z' }, ...BASE])).state === 'listed'; })()); + t('⛔ a SUPERSEDED claim drops its thread — a newer claim by another seat lists ITS thread for ITS seat, a newer claim by the same seat lists only the newer thread', (() => { const ui = ONE([...BASE, CLAIM(3, '2026-11-16T05:00:00Z', 'domain:ui#2', S_UI, [`Session: \`${S_UI}\``, `Thread session: \`${T2}\``])]); const same = ONE([...BASE, CLAIM(3, '2026-11-16T05:00:00Z', 'domain:skills#2', S2, OWN(`Thread session: \`${T2}\``))]); return DELEGATE(ui).state === 'unlisted' && DELEGATE(ui, 'domain:ui#2', T2).state === 'listed' && DELEGATE(same).state === 'unlisted' && DELEGATE(same, 'domain:skills#2', T2).state === 'listed'; })()); + t('⛔ a CLOSED card drops its thread — and so does a pull row', DELEGATE(ONE(BASE, CARD(34013, { state: 'closed' }))).state === 'unlisted' && DELEGATE(ONE(BASE, CARD(34013, { pull_request: {} }))).state === 'unlisted'); + t('⭐ a claim its OWN session yielded is no claim: the race loser\'s newer claim lists nothing and the winner\'s older claim still lists its thread', (() => { const lose = CLAIM(3, '2026-11-16T05:00:00Z', 'domain:ui#2', S_UI, [`Session: \`${S_UI}\``, `Thread session: \`${T2}\``]); const yieldRow = { id: 4, created_at: '2026-11-16T05:01:00Z', user: { login: RELAY_COMMENT_AUTHOR }, body: `${SIG('domain:ui#2', S_UI)}\n\nalready claimed — yielding \`${S_UI}\`` }; const r = ONE([...BASE, lose, yieldRow]); return DELEGATE(r).state === 'listed' && DELEGATE(r, 'domain:ui#2', T2).state === 'unlisted'; })()); + t('⛔ a claim signed by ANOTHER seat adds nothing to this one: ui#2\'s thread knocking as skills#2 is unlisted, as ui#2 listed — and a claim with no signature line lists nobody', (() => { const r = ONE([CLAIM(1, '2026-11-16T03:16:00Z', 'domain:ui#2', S_UI, [`Session: \`${S_UI}\``, TEMPLATE])]); const bare = ONE([CLAIM(1, '2026-11-16T03:16:00Z', 'domain:skills#2', S2, OWN(TEMPLATE), false)]); return why(KNOCK('domain:skills#2', T), r).includes(`${T} is not a session domain:skills#2 lists`) && DELEGATE(r, 'domain:ui#2', T).state === 'listed' && DELEGATE(bare).state === 'unlisted' && [...bare.seats.values()].every((m) => !m.has(T)); })()); + t('⭐ AUTHOR RULE: a claim the relay posted lists its thread, and so does one a `GOVERNED_APPROVERS` account posted — the knock fence\'s own authors, ⛔ no second list', DELEGATE(ONE(BASE)).state === 'listed' && DELEGATE(ONE([{ ...BASE[0], user: { login: GOVERNED_APPROVERS[0] } }])).state === 'listed'); + t('⛔ AUTHOR RULE: a claim posted by any OTHER author, or naming no author at all, lists nobody — whatever its signature and `Thread session:` line say', [{ login: 'drive-by' }, {}, undefined, { login: '' }].every((user) => { const r = ONE([{ ...BASE[0], user }]); return r.state === 'read' && DELEGATE(r).state === 'unlisted' && [...r.seats.values()].every((m) => !m.has(T)); })); + t('⛔ AUTHOR RULE: a row outside it neither SUPERSEDES nor RELEASES nor YIELDS — a newer drive-by claim naming another thread lists nothing and the relay claim still lists; a drive-by `Release:` or yield leaves it listed', (() => { const by = { login: 'drive-by' }; const newer = ONE([...BASE, { ...CLAIM(3, '2026-11-16T05:00:00Z', 'domain:skills#2', S2, OWN(`Thread session: \`${T2}\``)), user: by }]); const rel = ONE([...BASE, { id: 2, created_at: '2026-11-16T04:00:00Z', user: by, body: `${SIG('domain:skills#2', S2)}\n\nRelease: \`${S2}\` · premise moved · back to pm:queue` }]); const yieldRow = ONE([...BASE, { id: 4, created_at: '2026-11-16T05:01:00Z', user: by, body: `${SIG('domain:skills#2', S2)}\n\nalready claimed — yielding \`${S2}\`` }]); return DELEGATE(newer).state === 'listed' && DELEGATE(newer, 'domain:skills#2', T2).state === 'unlisted' && DELEGATE(rel).state === 'listed' && DELEGATE(yieldRow).state === 'listed'; })()); + t('⛔ FAIL CLOSED: claims that are not an array, or a thread that is not one, read the roster UNREADABLE, naming the claim threads — and omitting `claims` lists no card thread, as before', (() => { const gap = 'the open `pm:dispatched` claim threads'; const a = R(null); const b = R([{ card: CARD(1), rows: null }]); const c = seatSessionRoster({ posts, mailboxes }); return a.state === 'unreadable' && a.gaps.includes(gap) && b.state === 'unreadable' && b.gaps.includes(gap) && c.state === 'read' && DELEGATE(c).state === 'unlisted'; })()); + t('⛔ one thread on TWO seats\' claims cannot say which rang — unlisted for each', (() => { const r = R([{ card: CARD(1), rows: BASE }, { card: CARD(2), rows: [CLAIM(5, '2026-11-16T03:16:00Z', 'domain:ui#2', S_UI, [`Session: \`${S_UI}\``, TEMPLATE])] }]); return why(KNOCK('domain:skills#2', T), r).includes(`${T} is listed by domain:ui#2 too`) && DELEGATE(r, 'domain:ui#2', T).state === 'unlisted'; })()); + t('⭐ H72 end to end: the claimed card\'s WHOLE thread the sweep holds joins the REAL roster — the delegate\'s knock is not listed, a stray beside it is', await (async () => { const hs = await import('./check-half-states.mjs'); const r = seatSessionRoster(hs.h72RosterListings([...posts, CARD(34013)], mailboxes, [], new Map([[34013, { rows: BASE, complete: true }]]))); const rows = [{ ...KNOCK('domain:skills#2', T), id: 8301 }, { ...KNOCK('domain:skills#2', STRAY), id: 8302 }]; const row = String(hs.h72UnlistedKnockLines(mailboxEvents(rows, r), r, NOW_H72) ?? ''); return r.state === 'read' && row.includes('1 knock(s)') && row.includes('comment 8302') && !row.includes('comment 8301'); })()); + t('⛔ …and a claimed card whose thread is NOT held whole makes that roster unreadable, so H72 lists nothing — unjudged, never the delegate accused', await (async () => { const hs = await import('./check-half-states.mjs'); const r = seatSessionRoster(hs.h72RosterListings([...posts, CARD(34013)], mailboxes, [], new Map([[34013, { rows: BASE, complete: false }]]))); const reading = mailboxEvents([{ ...KNOCK('domain:skills#2', T), id: 8301 }], r); return r.state === 'unreadable' && SAME(reading.unlisted, [8301]) && hs.h72UnlistedKnockLines(reading, r, NOW_H72) === null; })()); + } } // -- the signature line (#27113) ---------------------------------------------- @@ -3862,7 +3998,7 @@ export async function selfTest() { + 'locator and printed by `--template`; the `Local-runs:` reading — none, one named probe, absent not re-judged, ' + 'unreadable refused; the reviewer brief printed by `--brief-template` with its read-only shape; the mailbox ' + 'doorbell — `To: ` then each of the table\'s keys read, the table named both ways in the protocol text and printed by `--mailbox-keys`, and a key with no `To:`, a `To:` naming a login, free text, an acknowledgement, ' - + 'a key outside the table, a second line and an over-long line refused; the knock signature listing — `listed` only for a session the seat it names lists on its held post (`Successor-of:` included) or its open mailbox opening, a copied signature line `listed` too (consistency, never proof), a maintainer\'s knock exempt, everything else `unverified seat signature` and failing closed; the review claim line — read signed and unsigned, ' + + 'a key outside the table, a second line and an over-long line refused; the knock signature listing — `listed` only for a session the seat it names lists on its held post (`Successor-of:` included), its open mailbox opening or its open newest claim\'s `Thread session:` line (one spelling; released, superseded and closed claims drop), a copied signature line `listed` too (consistency, never proof), a maintainer\'s knock exempt, everything else `unverified seat signature` and failing closed; the review claim line — read signed and unsigned, ' + 'spelled verbatim in the rule text, lapsing on a moved head or after two hours, the earliest live claim holding; the review hold ' + 'line — read signed and unsigned, spelled verbatim in the rule text, per head and cleared only by a new head, an unreadable ' + 'line listed and voiding nothing, its 24-hour age a reading '