Skip to content

Commit 87f02db

Browse files
committed
feat(pm): key the mailbox by seat — mailbox-open opens one per seat, fleet-roster reads it per seat row
One account routinely holds several seats, and a PR's events reach one subscribed session at a time, so a mailbox keyed by login wakes one of that account's seats and the others never hear. mailbox-open.mjs: `--seat LANE#N` is required to open. The branch is `mailbox/<login>/<seat-slug>`, the body opens `Mailbox-of: <seat> · <login>`, and step ① refuses a second open mailbox for the same SEAT, whichever login holds it; a second seat under one login opens freely. A legacy per-login mailbox blocks nothing and is named so the account closes it. The header's "a login holds one seat" argument is rewritten, not patched. `--close`, the labels, the ledger exclusion and the `--head` cloud path are unchanged. fleet-roster.mjs: `mailboxLogin` gives way to the opener's `mailboxOwner`, read per seat row. A legacy per-login mailbox, or a seat no post carries, is flagged under the table, never attributed to the login's seats. This also aligns the reader with the writer: the opener wrote `To: <login>` while the roster read `Mailbox-of:`, so every `--head` mailbox was invisible to the mailbox column. Claude-Session: https://claude.ai/code/session_016WV4d1d1pooSGzvbJymLKy Co-authored-by: Claude <noreply@anthropic.com>
1 parent ddab8b9 commit 87f02db

3 files changed

Lines changed: 273 additions & 111 deletions

File tree

‎scripts/pm/fleet-roster.fixture.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
],
2424
"pulls": [
2525
{ "number": 25427, "state": "open", "head": { "ref": "claude/project-thread-aaaa" }, "body": "Fixes #25412", "labels": [] },
26-
{ "number": 25392, "state": "open", "head": { "ref": "claude/project-thread-bbbb" }, "body": "Mailbox-of: os-elon-musk\n\nFixes #25416", "labels": [{ "name": "pm:mailbox" }, { "name": "skip-changeset" }] },
26+
{ "number": 25392, "state": "open", "head": { "ref": "claude/project-thread-bbbb" }, "body": "Mailbox-of: domain:devx#1 · os-elon-musk\n\nFixes #25416", "labels": [{ "name": "pm:mailbox" }, { "name": "skip-changeset" }] },
27+
{ "number": 25393, "state": "open", "head": { "ref": "mailbox/os-elon-musk/skills-2" }, "body": "Mailbox-of: domain:skills#2 · os-elon-musk\n\nThe mailbox of the seat `domain:skills#2`", "labels": [{ "name": "pm:mailbox" }, { "name": "pinned" }] },
28+
{ "number": 25394, "state": "open", "head": { "ref": "mailbox/os-sales/devx-2" }, "body": "", "labels": [{ "name": "pm:mailbox" }] },
29+
{ "number": 25395, "state": "open", "head": { "ref": "claude/project-thread-eeee" }, "body": "To: os-sales\n\nThe mailbox of the seat held by `os-sales`", "labels": [{ "name": "pm:mailbox" }, { "name": "pinned" }] },
30+
{ "number": 25396, "state": "open", "head": { "ref": "claude/project-thread-ffff" }, "body": "Mailbox-of: domain:spec#5 · os-tesla", "labels": [{ "name": "pm:mailbox" }] },
2731
{ "number": 25433, "state": "open", "head": { "ref": "claude/project-thread-cccc" }, "body": "Fixes #25417", "labels": [] }
2832
],
2933
"comments": {

‎scripts/pm/fleet-roster.mjs‎

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@
5252
* last activity the newest `updated_at` of the post and its in-flight
5353
* cards. A seated seat older than `STALE_HOURS` with no
5454
* wall note is flagged 「疑似撞墙」.
55-
* mailbox open `pm:mailbox` pulls of the seat's account, by head
56-
* `mailbox/<login>` or the body's `Mailbox-of: <login>`.
55+
* mailbox open `pm:mailbox` pulls of the SEAT, whichever account
56+
* holds it: the seat on the body's first line
57+
* `Mailbox-of: <seat> · <login>`, or the head
58+
* `mailbox/<login>/<seat-slug>` (`mailboxOwner`, the
59+
* opener's one reading). A legacy per-login mailbox names
60+
* no seat, and an account holds several seats, so which of
61+
* them reads it cannot be told: it is listed under the
62+
* table as assigned to no seat, ⛔ never shown on the
63+
* login's rows. So is a per-seat one whose seat no post
64+
* carries.
5765
*
5866
* The footer names the generation time and every read made, so a reader can
5967
* re-run each one.
@@ -88,10 +96,11 @@ import { fileURLToPath } from 'node:url';
8896
import { isEntrypoint } from '../invoked-as.mjs';
8997
import { validateStroke } from './fleet-write/validate.mjs';
9098
import { ghApi, PER_PAGE, readAllPages } from './gh-pages.mjs';
91-
// The mailbox label, its ledger exclusion and its branch prefix have ONE owner,
92-
// the mailbox opener (#25417); this file reads them, never re-spells them.
99+
// The mailbox label, its ledger exclusion, its branch prefix and the reading of
100+
// whose mailbox a pull is have ONE owner, the mailbox opener (#25417, keyed by
101+
// seat since #27637); this file reads them, never re-spells them.
93102
import * as mailboxOpen from './mailbox-open.mjs';
94-
import { LEDGER_EXCLUSION, MAILBOX_BRANCH_PREFIX, MAILBOX_LABEL } from './mailbox-open.mjs';
103+
import { LEDGER_EXCLUSION, MAILBOX_BRANCH_PREFIX, MAILBOX_LABEL, mailboxOwner, seatKey } from './mailbox-open.mjs';
95104
// The seat record's heading and verdict have ONE reading, shared with H69 in
96105
// check-half-states; this file asks it, never re-spells the heading.
97106
import * as seatRecord from './seat-record.mjs';
@@ -232,12 +241,30 @@ export function hasLandingVerdict(comments) {
232241
});
233242
}
234243

235-
/** The login whose mailbox a `pm:mailbox` pull is, or null. Pure. */
236-
export function mailboxLogin(pr) {
237-
if (!labelNames(pr).includes(MAILBOX_LABEL)) return null;
238-
const ref = String(pr?.head?.ref ?? '');
239-
if (ref.startsWith(MAILBOX_BRANCH_PREFIX)) return ref.slice(MAILBOX_BRANCH_PREFIX.length);
240-
return /^Mailbox-of: (\S+)/m.exec(String(pr?.body ?? ''))?.[1] ?? null;
244+
/** A seat row's mailbox slug — its `LANE#N` as the opener spells it in a ref — or null. Pure. */
245+
const seatSlugOf = (row) => seatKey(`${row.lane}#${row.seat}`)?.slug ?? null;
246+
247+
/** Every open `pm:mailbox` pull in the snapshot, with whose it is (`mailboxOwner`), ordered by ref. Pure. */
248+
export function readMailboxes(snapshot) {
249+
const out = [];
250+
for (const repo of Object.keys(snapshot?.repos ?? {}).sort()) {
251+
for (const pr of snapshot.repos[repo]?.pulls ?? []) {
252+
const owner = pr?.state === 'closed' ? null : mailboxOwner(pr);
253+
if (owner !== null) out.push({ ref: ref(repo, pr.number), ...owner });
254+
}
255+
}
256+
return out.sort((a, b) => byRef(a.ref, b.ref));
257+
}
258+
259+
/**
260+
* The mailboxes no seat row reads — flagged under the table, ⛔ never attributed: a legacy per-login mailbox
261+
* (it names no seat, and its login holds several), or a per-seat one whose seat no seat post carries. Pure.
262+
*/
263+
export function unassignedMailboxes(snapshot, rows) {
264+
const read = new Set(rows.map(seatSlugOf).filter(Boolean));
265+
return readMailboxes(snapshot)
266+
.filter((m) => m.slug === null || !read.has(m.slug))
267+
.map((m) => ({ ...m, why: m.slug === null ? 'legacy per-login, names no seat' : 'no seat post carries this seat' }));
241268
}
242269

243270
const cardLaneMatch = (card, row) => {
@@ -275,16 +302,12 @@ export function buildRows(snapshot, { now }) {
275302
rows.sort((a, b) => (a.repo !== b.repo ? (a.repo < b.repo ? -1 : 1) : a.lane !== b.lane ? (a.lane < b.lane ? -1 : 1) : a.seat !== b.seat ? a.seat - b.seat : a.post - b.post));
276303

277304
const landing = new Map(); // card key → [pull refs]
278-
const mailboxes = [];
279305
for (const { repo, pr, comments } of pulls) {
280-
const owner = mailboxLogin(pr);
281-
if (owner !== null) {
282-
mailboxes.push({ login: lc(owner), ref: ref(repo, pr.number) });
283-
continue;
284-
}
285-
if (labelNames(pr).includes(MAILBOX_LABEL) || !String(pr?.head?.ref ?? '').startsWith(CARD_BRANCH_PREFIX) || !hasLandingVerdict(comments)) continue;
306+
// Every `pm:mailbox` pull is a mailbox, whosever it reads as, and ⛔ never counts as landing.
307+
if (mailboxOwner(pr) !== null || !String(pr?.head?.ref ?? '').startsWith(CARD_BRANCH_PREFIX) || !hasLandingVerdict(comments)) continue;
286308
for (const k of closingRefs(pr.body, repo)) landing.set(k, [...(landing.get(k) ?? []), ref(repo, pr.number)]);
287309
}
310+
const mailboxes = readMailboxes(snapshot);
288311

289312
const out = rows.map((row) => {
290313
const acct = lc(row.account);
@@ -304,7 +327,8 @@ export function buildRows(snapshot, { now }) {
304327
awaitingLanding: awaitingLanding.sort(byRef),
305328
lastActivity,
306329
suspectedWall: row.status === 'seated' && row.wallNote === null && ageHours !== null && ageHours > STALE_HOURS,
307-
mailbox: row.account ? mailboxes.filter((m) => m.login === acct).map((m) => m.ref).sort(byRef) : [],
330+
// Per seat, never per account: one account holds several seats, and each seat opens its own.
331+
mailbox: mailboxes.filter((m) => m.slug !== null && m.slug === seatSlugOf(row)).map((m) => m.ref),
308332
};
309333
});
310334

@@ -341,8 +365,8 @@ export function readsFor(repos) {
341365
]);
342366
}
343367

344-
/** The roster body, markdown. Pure. */
345-
export function renderBody(rows, { now, repos, session = null }) {
368+
/** The roster body, markdown; `unassigned` is `unassignedMailboxes`' list. Pure. */
369+
export function renderBody(rows, { now, repos, session = null, unassigned = [] }) {
346370
const lines = [
347371
ROSTER_MARKER,
348372
'# 车队总表 — fleet roster',
@@ -365,6 +389,9 @@ export function renderBody(rows, { now, repos, session = null }) {
365389
lines.push(
366390
'',
367391
`${rows.length} seat posts · ${seated.length} seated · ${rows.filter((r) => r.suspectedWall).length} ${SUSPECTED_WALL} (seated, no \`Wall:\` line, last activity older than ${STALE_HOURS} h).`,
392+
...(unassigned.length
393+
? ['', `⚠️ ${unassigned.length} mailbox PR(s) on no seat row — never attributed to an account's seats; close a legacy one and open one per seat: ${unassigned.map((m) => `${shortRef(m.ref)} (${[m.seat ?? m.slug, m.login].filter(Boolean).join(' · ') || 'no owner'}: ${m.why})`).join(' · ')}.`]
394+
: []),
368395
'',
369396
`Generated ${now} by \`node scripts/pm/fleet-roster.mjs --repos ${repos.join(',')}\` from:`,
370397
...readsFor(repos).map((q) => `- \`${q}\``),
@@ -424,7 +451,7 @@ function readLive(repos) {
424451
const dispatched = new Set(Object.entries(snapshot.repos).flatMap(([repo, s]) => s.dispatched.map((i) => `${repo}#${i.number}`)));
425452
for (const [repo, s] of Object.entries(snapshot.repos)) {
426453
for (const p of s.pulls) {
427-
if (mailboxLogin(p) !== null || labelNames(p).includes(MAILBOX_LABEL) || !String(p.head?.ref ?? '').startsWith(CARD_BRANCH_PREFIX)) continue;
454+
if (mailboxOwner(p) !== null || !String(p.head?.ref ?? '').startsWith(CARD_BRANCH_PREFIX)) continue;
428455
if (!closingRefs(p.body, repo).some((k) => dispatched.has(k))) continue;
429456
s.comments[String(p.number)] = need(`/repos/${repo}/issues/${p.number}/comments?per_page=100`);
430457
}
@@ -478,12 +505,13 @@ export async function main(argv, { env = process.env } = {}) {
478505
}
479506
const now = new Date(opts.now ?? snapshot.now ?? Date.now()).toISOString().replace(/\.\d{3}Z$/, 'Z');
480507
const rows = buildRows(snapshot, { now });
508+
const unassigned = unassignedMailboxes(snapshot, rows);
481509
if (opts.json) {
482-
console.log(JSON.stringify({ now, repos, rows }, null, 2));
510+
console.log(JSON.stringify({ now, repos, rows, unassignedMailboxes: unassigned }, null, 2));
483511
return EXIT_OK;
484512
}
485513
const session = env.OS_FLEET_SESSION || env.CLAUDE_CODE_REMOTE_SESSION_ID || null;
486-
const body = renderBody(rows, { now, repos, session });
514+
const body = renderBody(rows, { now, repos, session, unassigned });
487515
if (opts.write === null) {
488516
console.log(body);
489517
return EXIT_OK;
@@ -523,10 +551,10 @@ const SELF_TEST_BATTERIES = Object.freeze({
523551
'arguments: modes and every refusal': 9,
524552
'seat titles: lane, seat, repo, status, account, project': 13,
525553
'wall notes, closing refs, verdicts and mailboxes': 13,
526-
'the fixture snapshot: rows for the three repos': 15,
527-
'the rendered body: marker, columns, footer, determinism': 8,
554+
'the fixture snapshot: rows for the three repos': 17,
555+
'the rendered body: marker, columns, footer, determinism': 9,
528556
'refusing to overwrite what is not the roster': 6,
529-
'the CLI: fixture runs offline, usage errors are exit 2': 5,
557+
'the CLI: fixture runs offline, usage errors are exit 2': 6,
530558
'paging: a three-page read through the loop equals the slurped array': 4,
531559
});
532560
const SELF_TEST_BATTERY_FLOOR = 8;
@@ -601,7 +629,7 @@ async function selfTest() {
601629
t('⛔ an ACCEPT line ABOVE the heading is not the record\'s verdict', hasLandingVerdict([{ body: 'ACCEPT\n\n## 席位核对\n\nREWORK · rework' }]), false);
602630
t('the heading is H69\'s marker, imported not re-spelled: the three measured bodies read record alike', ['## 席位核对\n\n**ACCEPT** · x', '## 席位核对 — ACCEPT · x', '## Contract review\n\n**VERDICT: PASS**'].map((b) => `${seatRecord.SEAT_RECORD_MARKER.test(b)}/${hasLandingVerdict([{ body: b }])}`), ['true/true', 'true/true', 'false/true']);
603631
t('the mailbox constants are the opener\'s own, imported not re-spelled', [MAILBOX_LABEL, LEDGER_EXCLUSION, MAILBOX_BRANCH_PREFIX], [mailboxOpen.MAILBOX_LABEL, mailboxOpen.LEDGER_EXCLUSION, mailboxOpen.MAILBOX_BRANCH_PREFIX]);
604-
t('a mailbox is read by head, then by body line; no label ⇒ none', [mailboxLogin({ labels: ['pm:mailbox'], head: { ref: 'mailbox/os-bill' } }), mailboxLogin({ labels: ['pm:mailbox'], head: { ref: 'claude/x' }, body: 'Mailbox-of: os-sales\n' }), mailboxLogin({ labels: [], head: { ref: 'mailbox/os-bill' } })], ['os-bill', 'os-sales', null]);
632+
t('whose mailbox a pull is, and a seat row\'s slug, are the opener\'s own readings — imported, not re-spelled', [mailboxOwner === mailboxOpen.mailboxOwner, seatKey === mailboxOpen.seatKey, seatSlugOf({ lane: 'domain:ui', seat: 4 }), seatSlugOf({ lane: 'triage', seat: 1 })], [true, true, 'ui-4', 'triage-1']);
605633

606634
battery('the fixture snapshot: rows for the three repos');
607635
const fixture = JSON.parse(readFileSync(FIXTURE_PATH, 'utf8'));
@@ -628,7 +656,10 @@ async function selfTest() {
628656
t('a PR with no verdict does not count', row(1353, 'objectstack-ai/hotcrm').awaitingLanding, []);
629657
t('an unassigned ruling sits on the lane’s lowest seated seat', [row(6023).awaitingRuling, row(20163).awaitingRuling], [[{ repo: 'objectstack-ai/objectstack', number: 25373 }], []]);
630658
t('a ruling assigned to seat 2’s account sits on seat 2', row(19287).awaitingRuling, [{ repo: 'objectstack-ai/objectstack', number: 25344 }]);
631-
t('the mailbox column is the account’s pm:mailbox PR', [row(6023).mailbox, row(20163).mailbox], [[{ repo: 'objectstack-ai/objectstack', number: 25392 }], []]);
659+
const os = (number) => ({ repo: 'objectstack-ai/objectstack', number });
660+
t('⭐ the mailbox column is the SEAT\'s pm:mailbox PR — by body line on a --head branch, by head slug, by both', [row(6023).mailbox, row(19287).mailbox, row(20163).mailbox], [[os(25392)], [os(25393)], [os(25394)]]);
661+
t('⛔ one login on three seats: each seat shows only its own mailbox, and a seat that opened none shows none', [row(6023).mailbox.length, row(19287).mailbox.length, row(1353, 'objectstack-ai/hotcrm').mailbox], [1, 1, []]);
662+
t('⛔ a legacy per-login mailbox and a seat no post carries sit on no row — flagged, never attributed to the login\'s seats', [unassignedMailboxes(fixture, rows).map((m) => [m.ref.number, m.seat, m.login, m.why]), [row(5560, 'objectstack-ai/objectui').mailbox, row(10243, 'objectstack-ai/objectui').mailbox]], [[[25395, null, 'os-sales', 'legacy per-login, names no seat'], [25396, 'domain:spec#5', 'os-tesla', 'no seat post carries this seat']], [[], []]]);
632663
t('stale and no wall note ⇒ 疑似撞墙; a wall note silences it; vacant never', [row(20163).suspectedWall, row(5560, 'objectstack-ai/objectui').suspectedWall, row(5560, 'objectstack-ai/objectui').wallNote, row(7623).suspectedWall], [true, false, 'limit reached, resets at 15:00Z', false]);
633664
t('last activity is the newest of post and in-flight cards', row(6023).lastActivity, '2026-10-23T13:28:00Z');
634665
t('one account on two seats of a lane: cards on the lowest seat, the other reads = seat 1', [row(5560, 'objectstack-ai/objectui').inFlight.length, row(10243, 'objectstack-ai/objectui').sharesWith, row(10243, 'objectstack-ai/objectui').inFlight, row(10243, 'objectstack-ai/objectui').suspectedWall], [1, 1, [], true]);
@@ -641,6 +672,10 @@ async function selfTest() {
641672
t('the footer names the generation time and each read', [body.includes(`Generated ${fixture.now}`), body.includes('`GET /repos/objectstack-ai/hotcrm/issues?state=open&labels=pm:seat`')], [true, true]);
642673
t('the suspected wall is spelled in the row', body.includes(`⚠️ ${SUSPECTED_WALL}`), true);
643674
t('a shared seat reads = seat N in the in-flight cell', body.includes('| = seat 1 |'), true);
675+
t('the mailboxes on no seat row are flagged under the table, each with its owner and why', (() => {
676+
const flagged = renderBody(rows, { now: fixture.now, repos: Object.keys(fixture.repos).sort(), unassigned: unassignedMailboxes(fixture, rows) });
677+
return [flagged.includes('⚠️ 2 mailbox PR(s) on no seat row'), flagged.includes('objectstack#25395 (os-sales: legacy per-login, names no seat)'), flagged.includes('objectstack#25396 (domain:spec#5 · os-tesla: no seat post carries this seat)'), body.includes('on no seat row')];
678+
})(), [true, true, true, false]);
644679
t('the attribution footer closes the body', body.endsWith('\n\n---\n_Generated by [Claude Code](https://claude.ai/code/session_01ABC)_'), true);
645680
const shuffled = { ...fixture, repos: Object.fromEntries(Object.entries(fixture.repos).reverse().map(([k, v]) => [k, { ...v, seats: [...v.seats].reverse() }])) };
646681
t('the same facts in another read order render the same body', renderBody(buildRows(shuffled, { now: fixture.now }), { now: fixture.now, repos: Object.keys(fixture.repos).sort() }), renderBody(rows, { now: fixture.now, repos: Object.keys(fixture.repos).sort() }));
@@ -683,6 +718,7 @@ async function selfTest() {
683718
} catch {}
684719
t('--fixture --json exits 0 with no gh on PATH (nothing reached for)', jsonRun.status, EXIT_OK);
685720
t('the printed rows are the built rows', parsed?.rows?.length, rows.length);
721+
t('the printed JSON carries the mailboxes on no seat row', parsed?.unassignedMailboxes?.map((m) => m.ref.number), [25395, 25396]);
686722
t('--fixture prints the markdown table', cli(['--fixture', FIXTURE_PATH]).stdout.split('\n')[0], ROSTER_MARKER);
687723
t('a usage error is exit 2', cli(['--write', 'x']).status, EXIT_USAGE);
688724
t('a missing fixture is exit 3', cli(['--fixture', join(PM_DIR, 'no-such-fixture.json')]).status, EXIT_PREREQUISITE);

0 commit comments

Comments
 (0)