diff --git a/.claude/skills/pm-dispatch/references/coordinator.md b/.claude/skills/pm-dispatch/references/coordinator.md index e07a0f7635f..4936fd0277d 100644 --- a/.claude/skills/pm-dispatch/references/coordinator.md +++ b/.claude/skills/pm-dispatch/references/coordinator.md @@ -15,6 +15,7 @@ ## 二、跨车道取卡(coordinator 每次唤醒读) - 取卡面 = 各车道 open 卡:p0/p1 先,再点名 area 或子专题的下一张;判据照 `execution-duties.md`。 +- 维护者只说改级 ⇒ 只落级,评论照 `filing-gate.md` 引原话;⛔ 不借此开线程,照取卡全序。 - 每张卡交其车道的席位线程;车道无席位线程而座位贴空着 ⇒ 先开席位线程再交卡。 - 维护者 ⛔ 不逐卡点名车道:车道读卡的 `domain:*`;S/M 分流见 `dispatch-runbook.md` 卡线程节。 @@ -24,6 +25,7 @@ - 席位攒批交候选,一线程一行:卡/PR、标题、级别、effort、汇报区、要读文件、续做分支。 - 派发令全文随行;⛔ 不等自己的槽位;区与卡线程 ⛔ 不直找 coordinator,经席位。 - coordinator 一批开完、一次回全部 id:p0/p1 先,余照点名次序;满即排队,交回或合入即释放。 +- 有空槽即开;先后只认卡上 `Blocked-by:` 与席位串行队,⛔ 不自排、不逐张等。 - 槽位只算在建的线程:等人(授权批准、决策卡)或等席位 L1/L2 审核的卡线程不占槽。 - S 卡的席内子代理只计该席 `batch`,不计本上限。 diff --git a/.claude/skills/pm-dispatch/references/filing-gate.md b/.claude/skills/pm-dispatch/references/filing-gate.md index 35fea6d29c2..0088e86ce3f 100644 --- a/.claude/skills/pm-dispatch/references/filing-gate.md +++ b/.claude/skills/pm-dispatch/references/filing-gate.md @@ -32,6 +32,7 @@ - 车队立的卡(席位、代立发现、清单、分诊)建卡带 area、type、级与正文定级行,缺一拒收。 - 维护者或外部人立的卡由分诊首触补齐 area 与 type;人定的级 ⛔ 不改,分诊与各席同此。 - 改级前读现级末次 `labeled` 事件:带 `performed_via_github_app` 或 bot actor 才算车队,余人定。 +- 代维护者落的级:同笔评论行首 `Ruling-ref: priority:pN` 引原话才算人定;⛔ 不凭 bot 判车队。 - 对人定的级有异议 ⇒ 只在卡上评论一行理由;级与卡的状态 ⛔ 不动。 - 业务理由:谁受益、什么场景、不做会怎样;③ 以原话代,④ 承父单;分诊 ⛔ 不代写。 - 清楚且合北极星方向 ⇒ 照常定级入队;与「What gets built」不符或无受益者 = 站不住。 diff --git a/scripts/pm/check-skill-line-ratchet.mjs b/scripts/pm/check-skill-line-ratchet.mjs index cbabe141293..01f7f7effc9 100644 --- a/scripts/pm/check-skill-line-ratchet.mjs +++ b/scripts/pm/check-skill-line-ratchet.mjs @@ -1442,7 +1442,14 @@ export const CEILINGS = new Map([ // It is beside seat-lifecycle.md because the coordinator is not a // `domain:*` seat. A NEW file, so this is not a raise and funds nothing — // set at the landed line count, headroom 0, same convention as above. - ['.claude/skills/pm-dispatch/references/coordinator.md', 49], + // 49 → 51: an ordinary ruled raise. The ruling of record is the maintainer's + // 2026-11-19 word, verbatim: 「同意」 on the coordinator's three dispatch rules, + // 「用 fable先评审你这个意见」, then his decision-card choice 「加两行,并修代改级漏洞」; + // quoted in the body of the card it ordered, claim comment 7000373266. Two + // lines: open whenever a slot is free, ordering only by `Blocked-by:` and the + // seat's serial queue; a grade-only word writes the grade and opens nothing. + // Measured delta +2. Landed count, headroom 0. + ['.claude/skills/pm-dispatch/references/coordinator.md', 51], // The external-text reference (whose text instructs, whose is data) and the // fork-PR flow it amends. Both are NEW to this map, so neither is a raise — // set at the landed line count, headroom 0, same convention as above. @@ -1652,7 +1659,11 @@ export const CEILINGS = new Map([ // area's loose-ends card, and the dedupe search before a review files. The // quota line (one card per defect) is untouched. Measured delta +3. // Not a CROSS_FILE_MOVES destination. Landed count, headroom 0. - ['.claude/skills/pm-dispatch/references/filing-gate.md', 82], + // 82 → 83: an ordinary ruled raise by the same ruling of record as + // coordinator.md's 51 (claim comment 7000373266): a grade the fleet wrote on + // the maintainer's word, its comment opening `Ruling-ref: priority:pN`, reads + // as his. Measured delta +1. Landed count, headroom 0. + ['.claude/skills/pm-dispatch/references/filing-gate.md', 83], // The project layer above the seats (maintainer's word: ONE project form, the // instruction line 「pm-dispatch <席位…>」 is the summon, seats are read from the // seat posts' 🟢 line, takeover never waits for a walled account, mailbox PRs, diff --git a/scripts/pm/label-write.mjs b/scripts/pm/label-write.mjs index 7c2c6ded3da..2673d475c39 100644 --- a/scripts/pm/label-write.mjs +++ b/scripts/pm/label-write.mjs @@ -343,6 +343,21 @@ * leave one line with the reason on the card as a comment, and nothing else: * the grade and the card's state stay. ⛔ This is the seat's label door and claims nothing about the * others: a write that reaches the board another way is not judged here. + * + * A grade the fleet wrote ON the maintainer's word is his too (`filing-gate.md`: 「代维护者落的级 … 才算人定」): + * the bot actor says who typed it, not whose grade it is. Such a write folds a comment whose line opens + * `Ruling-ref: priority:pN` — the grade it writes — before his words (`GRADE_RULING_MARK`), so a fleet-set grade whose + * `labeled` event has, within `RULING_COMMENT_WINDOW_MS` of it, a FLEET comment (the same allow-list as the event) + * with a line opening `Ruling-ref:` and that same grade is refused like a hand. Any other `Ruling-ref:` is not a + * grade he named and reads as nothing here: a lane seat's self-triage record citing the standing exception + * (`triage-duties.md`), a claim or dispatch citing a ruling comment id (`dispatch-runbook.md`), a line naming + * another grade, or one a person typed — so triage's 改判 of a self-triaged grade still lands. The marker is read + * past backticks and a quote set tight after the grade. The write agrees with that read: a folded `Ruling-ref:` lets a + * grade change past a person's (or his) grade only when it names every grade the write sets; one that names none is + * asked as if absent — refused there with the exact line to write, and over a grade the fleet may change anyway + * passed with a step ② line saying the new grade will read as the fleet's own. That costs one + * comments read (from the oldest fleet grade event minus the window), only when a carried grade reads as the fleet's; + * a read that does not answer is refused, never passed — the same rule as an unread events list. */ import process from 'node:process'; @@ -602,6 +617,10 @@ export const GRADE_LABEL_PREFIX = 'priority:'; export const RULING_REF_KEY = 'Ruling-ref:'; /** The grade read walks at most this many pages of a card's events (100 a page); a card with more is an incomplete read. */ export const GRADE_EVENT_PAGE_CAP = 10; +/** A grade-ruling comment this close to a fleet `labeled` event is the write's own fold: the grade is the maintainer's (header). */ +export const RULING_COMMENT_WINDOW_MS = 120_000; +/** The marker `filing-gate.md` spells for a grade written on the maintainer's word: the key, then the grade it writes (header). */ +export const GRADE_RULING_MARK = `${RULING_REF_KEY} ${GRADE_LABEL_PREFIX}pN`; const gradeKeys = (labels) => dedupe((labels ?? []).map(labelKey).filter((l) => typeof l === 'string' && l.startsWith(GRADE_LABEL_PREFIX))).sort(); @@ -621,20 +640,54 @@ export function hasRulingRef(text) { return String(text ?? '').split(/\r?\n/u).some((line) => line.startsWith(RULING_REF_KEY) && line.slice(RULING_REF_KEY.length).trim() !== ''); } +/** The newest `labeled` event of one grade, or undefined. */ +const newestGradeEvent = (events, grade) => events.filter((e) => e?.event === 'labeled' && labelKey(e?.label?.name) === grade).at(-1); + +/** The grade a `Ruling-ref:` line opens with — backticks, quotes and a quote set tight after it tolerated — or undefined. */ +const GRADE_AT_LINE_START = new RegExp(`^[\\s\`'"*]*(${GRADE_LABEL_PREFIX}[A-Za-z0-9_-]+)`, 'iu'); + +/** A line opening `Ruling-ref:` whose first cited word is `grade` (`GRADE_RULING_MARK`): his ruling on THAT grade, not any ruling. */ +export function hasGradeRuling(text, grade) { + return String(text ?? '').split(/\r?\n/u).some((line) => line.startsWith(RULING_REF_KEY) && labelKey(line.slice(RULING_REF_KEY.length).match(GRADE_AT_LINE_START)?.[1]) === grade); +} + +/** The fleet's comment, within the window of a fleet label event, naming that event's grade after `Ruling-ref:`: the fold of a write on the maintainer's word. */ +export function rulingCommentNear(event, comments = []) { + const at = Date.parse(event?.created_at ?? ''); + const grade = labelKey(event?.label?.name); + if (!Number.isFinite(at) || typeof grade !== 'string') return undefined; + return (comments ?? []).find( + (c) => isFleetLabelEvent({ performed_via_github_app: c?.performed_via_github_app, actor: c?.user }) && Math.abs(Date.parse(c?.created_at ?? '') - at) <= RULING_COMMENT_WINDOW_MS && hasGradeRuling(c?.body, grade), + ); +} + +/** Where a fleet-set grade's ruling comments are read from: the oldest fleet event among the grades, minus the window; or null. */ +export function rulingCommentsSince({ grades = [], events = null } = {}) { + if (!Array.isArray(events)) return null; + const times = grades + .map((g) => newestGradeEvent(events, g)) + .filter((e) => e && isFleetLabelEvent(e)) + .map((e) => Date.parse(e.created_at ?? '')) + .filter(Number.isFinite); + return times.length ? new Date(Math.min(...times) - RULING_COMMENT_WINDOW_MS).toISOString() : null; +} + /** * The hand-set grade (header), asked of the grades ONE write changes. Returns the refusal sentence, or null. * * grades `gradesChanged`'s answer — the carried `priority:*` labels, as `labelKey` spells them. * events the card's issue events, oldest first as the platform lists them; null when the read did not answer or * ran past `GRADE_EVENT_PAGE_CAP`. Only `labeled` events are read (header: why not `unlabeled`). + * comments the card's comments around the fleet-set grades' events (`rulingCommentsSince`); null when that read did + * not answer. A fleet event with the fleet's `Ruling-ref: ` comment beside it is his grade (header). * rulingRef the folded comment carries a `Ruling-ref:` line — the maintainer's ruling, cited; nothing is refused. */ -export function refuseHandSetGrade({ grades = [], events = null, rulingRef = false, ref = 'the card' } = {}) { +export function refuseHandSetGrade({ grades = [], events = null, comments = [], rulingRef = false, ref = 'the card' } = {}) { if (grades.length === 0 || rulingRef) return null; const rule = `${HAND_SET_RULE_PATH}: 「${HAND_SET_RULE}」`; const exits = 'A grade a person set stays. To disagree, leave one line with the reason on the card as a comment, and nothing else: the grade ' + - `and the card's state stay as they are; where the maintainer has already ruled, fold the comment into this write (\`--comment-file\`) with a \`${RULING_REF_KEY}\` line citing his words.`; + `and the card's state stay as they are; where the maintainer has already ruled, fold the comment into this write (\`--comment-file\`) with a line opening \`${GRADE_RULING_MARK}\` — the grade it writes — then his words.`; if (!Array.isArray(events)) { return ( `the write changes the grade of ${ref} and the card's label events could not be read in full (${GRADE_EVENT_PAGE_CAP} pages at most), so ` + @@ -643,8 +696,17 @@ export function refuseHandSetGrade({ grades = [], events = null, rulingRef = fal } const byHand = []; for (const grade of grades) { - const set = events.filter((e) => e?.event === 'labeled' && labelKey(e?.label?.name) === grade).at(-1); - if (set && isFleetLabelEvent(set)) continue; + const set = newestGradeEvent(events, grade); + if (set && isFleetLabelEvent(set)) { + if (!Array.isArray(comments)) { + byHand.push(`\`${grade}\` (set by the fleet at ${set.created_at ?? 'an unread time'}, and the comments beside it could not be read, so nothing shows it was not written on the maintainer's word)`); + continue; + } + const ruling = rulingCommentNear(set, comments); + if (!ruling) continue; + byHand.push(`\`${grade}\` (set by the fleet at ${set.created_at} on the maintainer's word: the fleet's comment ${ruling.id ?? 'unread'} beside it opens a line \`${RULING_REF_KEY} ${grade}\`)`); + continue; + } byHand.push( set ? `\`${grade}\` (set by \`${set.actor?.login ?? 'an unread actor'}\` at ${set.created_at ?? 'an unread time'}: actor type ${set.actor?.type ?? 'unread'}, no \`performed_via_github_app\`)` @@ -652,7 +714,28 @@ export function refuseHandSetGrade({ grades = [], events = null, rulingRef = fal ); } if (byHand.length === 0) return null; - return `the write changes the grade of ${ref}, and ${byHand.join(' and ')} is not the fleet's label event — ${rule}. ${exits}`; + return `the write changes the grade of ${ref}, and ${byHand.join(' and ')} is not the fleet's own grade — ${rule}. ${exits}`; +} + +/** The hand-set refusal for a write whose folded `Ruling-ref:` would have let it through but names no grade it writes, with the exact fix. */ +export function unnamedGradeRuling(handSet, written = []) { + const fix = written.length ? written.map((g) => `\`${RULING_REF_KEY} ${g} 「his words」\``).join(' and ') : `a \`${RULING_REF_KEY}\` line`; + return ( + `${handSet.replace(/ — .*$/su, '')}. The folded \`${RULING_REF_KEY}\` would let it through, so this is a grade written on the maintainer's word — and its line names no grade ` + + `this write sets, so the new grade would read as the fleet's own and be changed again (${HAND_SET_RULE_PATH}: 「行首 \`${GRADE_RULING_MARK}\` 引原话才算人定」). Open the line ${fix} and send again.` + ); +} + +/** The card's comments since `since`, for the ruling read beside a fleet-set grade; null on any unanswered page or past the cap. */ +async function readRulingComments({ doCall, base, since }) { + const all = []; + for (let page = 1; page <= GRADE_EVENT_PAGE_CAP; page += 1) { + const r = await doCall('comments-list', `${base}/comments?since=${encodeURIComponent(since)}&per_page=100&page=${page}`, {}); + if (r.verdict !== 'ok' || !Array.isArray(r.json)) return null; + all.push(...r.json); + if (r.json.length < 100) return all; + } + return null; } /** The card's issue events for the grade read, or null when a page did not answer or the cap was reached with more to come. */ @@ -1325,13 +1408,22 @@ export async function runLabelWrite(options, deps = {}) { folded = ''; // an unreadable comment file cites nothing here; the fold below reports the file itself } const rulingRef = hasRulingRef(folded); - const handSet = refuseHandSetGrade({ grades, events: rulingRef ? [] : await readLabelEvents({ doCall, base }), rulingRef, ref: `${repo}#${issue}` }); + // The write and the read agree (header): a fold that names every grade it writes is read later as his; any other + // `Ruling-ref:` is asked as if it were absent, and may pass only where the fleet may change the grade anyway. + const written = gradeKeys(labels.target).filter((g) => !gradeKeys(currentLabels).includes(g)); + const named = rulingRef && written.every((g) => hasGradeRuling(folded, g)); + const events = named ? [] : await readLabelEvents({ doCall, base }); + const since = named ? null : rulingCommentsSince({ grades, events }); + const comments = since ? await readRulingComments({ doCall, base, since }) : []; + const handSet = refuseHandSetGrade({ grades, events, comments, rulingRef: named, ref: `${repo}#${issue}` }); if (handSet) { - record(`[${stamp()}] ② REFUSED — ${handSet}`); + const refusal = rulingRef ? unnamedGradeRuling(handSet, written) : handSet; + record(`[${stamp()}] ② REFUSED — ${refusal}`); record(`[${stamp()}] ⛔ NOTHING WAS WRITTEN.`); - return result(EXIT_USAGE, { stoppedAt: 2, refusal: handSet }); + return result(EXIT_USAGE, { stoppedAt: 2, refusal }); } - record(`[${stamp()}] ② grade — ${render(grades)} ${rulingRef ? `changes under the comment's \`${RULING_REF_KEY}\` line` : "was set by the fleet (its newest `labeled` event carries an app or a bot actor)"}.`); + if (named) record(`[${stamp()}] ② grade — ${render(grades)} changes under the comment's \`${RULING_REF_KEY}\` line, which names ${render(written) || 'no new grade'}: from here it reads as the maintainer's (${HAND_SET_RULE_PATH}).`); + else record(`[${stamp()}] ② grade — ${render(grades)} was set by the fleet (its newest \`labeled\` event carries an app or a bot actor)${rulingRef ? `; the comment's \`${RULING_REF_KEY}\` line names no grade this write sets, so ${render(written)} will read as the fleet's own — a grade on the maintainer's word opens it ${written.map((g) => `\`${RULING_REF_KEY} ${g}\``).join(' / ')}` : ''}.`); } // ── `--comment-file`: the comment (and `--land`) folded into this ONE stroke, RELAY-ONLY (header) ── @@ -2547,7 +2639,7 @@ const REAL_TRANSPORT_BATTERY = "the real transport: a comment-bearing stroke (a const KIND_BATTERY = 'the kind rule: no pm state added to a pull request, no `pm:awaiting-merge` added to an issue, a removal never refused, an unreadable kind refused — on both write paths, before the transport'; const LAND_DOGFOOD_BATTERY = "the --land dogfood gate: a `!` title or a `(narrowing)` arm lands only on a trusted newest os-dev-report whose dogfood_battery names the head or a first-parent ancestor reached over merges of the base alone; every NOT MEASURED refuses before any send; an unmarked pull is not judged"; const STATELESS_BATTERY = 'the stateless write: an OPEN card never loses its last pm state unless the same write adds a state or needs-user-decision or closes it, a parked card never keeps an assignee a state or assignee move left there, a release stays legal — before the transport, zero writes'; -const HAND_SET_BATTERY = "the hand-set grade: a `priority:*` whose newest `labeled` event is not the fleet's (no app, no bot actor) is never changed — refused at step ② with zero writes unless the folded comment cites a `Ruling-ref:`"; +const HAND_SET_BATTERY = "the hand-set grade: a `priority:*` whose newest `labeled` event is not the fleet's (no app, no bot actor), or is the fleet's with its own `Ruling-ref: ` fold beside it, is never changed — refused at step ② with zero writes unless the folded comment's `Ruling-ref:` names the grade it writes"; const SELF_TEST_BATTERIES = Object.freeze({ 'the re-exec guard: the name this tool sets, and the patrol name that must not silence it': 11, 'the arithmetic: union, difference, and the two idempotent no-ops': 12, @@ -2566,7 +2658,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ [REAL_TRANSPORT_BATTERY]: 5, [STATELESS_BATTERY]: 19, [LAND_DOGFOOD_BATTERY]: 50, - [HAND_SET_BATTERY]: 23, + [HAND_SET_BATTERY]: 42, }); const SELF_TEST_BATTERY_FLOOR = 18; const UNATTRIBUTED_BATTERY = '(unattributed)'; @@ -3143,6 +3235,23 @@ export async function selfTest() { t('⭐ an events read that did not answer is refused too, never passed', String(hs(null)).includes('could not be read in full')); t('a `Ruling-ref:` line passes it, and the key must open a line and cite something', [hs([HAND], { rulingRef: true }), hasRulingRef('seat sig\nRuling-ref: 6982855148 「改回去」'), hasRulingRef('see Ruling-ref: x'), hasRulingRef('Ruling-ref: ')], [null, true, false, false]); t('two carried grades are each asked: one by hand refuses the write', typeof refuseHandSetGrade({ grades: ['priority:p1', 'priority:p2'], events: [RELAY, labeled('priority:p2', 'hotlong', 'User')] }), 'string'); + const FLEET_USER = { login: RELAY_COMMENT_AUTHOR, type: 'Bot' }; + const ruled = (at, body = 'Grade on the maintainer\'s word.\nRuling-ref: priority:p1 project thread 「改到 p1」', user = FLEET_USER) => ({ id: 41, body, user, created_at: at }); + const onWord = hs([RELAY], { comments: [ruled('2026-11-18T10:00:20Z')] }); + t('⭐ a grade the fleet set ON the maintainer\'s word — its fold `Ruling-ref: priority:p1` beside the event — is his: REFUSED, naming the comment and the line', typeof onWord === 'string' && ['`priority:p1`', 'comment 41', `\`${RULING_REF_KEY} priority:p1\``, HAND_SET_RULE].every((s) => onWord.includes(s)), true, onWord); + const BESIDE = '2026-11-18T10:00:20Z'; + const SELF_TRIAGE = 'Self-triage: p1 — blocks our in-flight claim, failing run named.\nRuling-ref: 「车道席自分诊 … 方可首触定 p1/p2」'; + t('⭐ a self-triage record beside a fleet grade cites the standing exception, not a grade he named: passes, so triage\'s 改判 lands', hs([RELAY], { comments: [ruled(BESIDE, SELF_TRIAGE)] }), null); + t('⭐ …and so does a claim or dispatch citing a ruling comment id (`Ruling-ref: `)', hs([RELAY], { comments: [ruled(BESIDE, 'Claim: seat 5\nRuling-ref: 7000373266')] }), null); + t('…a `Ruling-ref:` naming ANOTHER grade, or naming this one only after other words, is not this grade\'s ruling', [hs([RELAY], { comments: [ruled(BESIDE, 'Ruling-ref: priority:p2 「改到 p2」')] }), hs([RELAY], { comments: [ruled(BESIDE, 'Ruling-ref: 「改到 p1」 priority:p1')] })], [null, null]); + t('…the same line typed by a PERSON is not the fleet\'s fold: passes; through an app it is the fleet\'s, and the label is matched as GitHub does', [hs([RELAY], { comments: [ruled(BESIDE, undefined, { login: 'os-warren', type: 'User' })] }), typeof hs([RELAY], { comments: [{ ...ruled(BESIDE, 'Ruling-ref: Priority:P1 「改到 p1」', { login: 'os-warren', type: 'User' }), performed_via_github_app: { slug: 'claude' } }] })], [null, 'string']); + t('the marker is read past backticks and a quote set tight after it: `Ruling-ref: `priority:p1`` and `Ruling-ref: priority:p1「…」` beside a fleet grade are his', [hs([RELAY], { comments: [ruled(BESIDE, 'Ruling-ref: `priority:p1` 「改到 p1」')] }), hs([RELAY], { comments: [ruled(BESIDE, 'Ruling-ref: priority:p1「改到 p1」')] })].map((r) => typeof r), ['string', 'string']); + t('↔ the rule names the marker this check reads: filing-gate.md spells `Ruling-ref: priority:pN`, and coordinator.md\'s grade-only word points there', [readFileSync(new URL(HAND_SET_RULE_PATH, REPO_ROOT), 'utf8').includes(`行首 \`${GRADE_RULING_MARK}\` 引原话才算人定`), readFileSync(new URL('.claude/skills/pm-dispatch/references/coordinator.md', REPO_ROOT), 'utf8').includes('只落级,评论照 `filing-gate.md`')], [true, true]); + t('…the window is both sides of the event, and only that window', [hs([RELAY], { comments: [ruled('2026-11-18T09:58:30Z')] }) === null, hs([RELAY], { comments: [ruled('2026-11-18T10:05:00Z')] }), hs([RELAY], { comments: [ruled('2026-11-18T09:50:00Z')] })], [false, null, null]); + t('…a comment beside it WITHOUT a `Ruling-ref:` line is a plain fleet grade: passes', hs([RELAY], { comments: [ruled('2026-11-18T10:00:20Z', 'Triage audit: p2 by the grading table.')] }), null); + t('⭐ …a comments read that did not answer, beside a fleet grade, is refused — never passed', String(hs([RELAY], { comments: null })).includes('could not be read')); + t('…a person\'s grade needs no comments read at all: refused with comments unread', typeof hs([HAND], { comments: null }), 'string'); + t('the comments read starts at the oldest fleet grade event minus the window, and is skipped for a hand or unread events', [rulingCommentsSince({ grades: ['priority:p1'], events: [RELAY] }), rulingCommentsSince({ grades: ['priority:p1'], events: [HAND] }), rulingCommentsSince({ grades: ['priority:p1'], events: null })], ['2026-11-18T09:58:00.000Z', null, null]); const REGRADE = ['--repo', 'o/r', '--issue', '7', '--add', 'priority:p3', '--remove', 'priority:p1']; const CARD = { labels: ['pm:queue', 'priority:p1'] }; @@ -3156,6 +3265,23 @@ export async function selfTest() { const long = Array.from({ length: 100 }, () => labeled('pm:queue', RELAY_COMMENT_AUTHOR, 'Bot')); const paged = await driveOffline(REGRADE, { ...CARD, events: [RELAY, ...long, HAND] }); t('⭐ the newest event is found on a later page: 101 events before it, two reads, refused', [paged.exit, paged.fake.calls.filter((c) => c.op === 'events-list').length], [EXIT_USAGE, 2]); + const onWordE2E = await driveOffline(REGRADE, { ...CARD, events: [RELAY], comments: [ruled('2026-11-18T10:00:20Z')] }); + t('⭐ end to end: regrading a grade the fleet wrote on the maintainer\'s word is exit 2 at step ② with ZERO writes, after one comments read', [onWordE2E.exit, onWordE2E.res.stoppedAt, writes(onWordE2E), onWordE2E.fake.calls.filter((c) => c.op === 'comments-list').length], [EXIT_USAGE, 2, 0, 1], onWordE2E.text); + t('…and the maintainer can still regrade it: a folded `Ruling-ref:` passes over a ruled grade', hs([RELAY], { comments: [ruled('2026-11-18T10:00:20Z')], rulingRef: true }), null); + const triaged = await driveOffline(REGRADE, { ...CARD, events: [RELAY], comments: [ruled('2026-11-18T10:00:20Z', SELF_TRIAGE)] }); + t('⭐ end to end: triage\'s 改判 of a self-triaged grade — its record\'s `Ruling-ref:` beside the event — lands and reads back, after one comments read', [triaged.exit, triaged.fake.board.labels, triaged.fake.calls.filter((c) => c.op === 'comments-list').length], [EXIT_OK, ['pm:queue', 'priority:p3'], 1], triaged.text); + const FOLD_FILE = '/tmp/self-test/regrade.md'; + const foldRegrade = (line, board) => driveOffline([...REGRADE, '--comment-file', FOLD_FILE], board, { files: { [FOLD_FILE]: `seat sig\nRegrade on the maintainer's word.\n${line}` } }); + const unnamed = await foldRegrade('Ruling-ref: 6982855148 「改回去」', { ...CARD, events: [HAND] }); + t('⭐ the write agrees with the read: a folded `Ruling-ref:` naming no grade it writes is NOT let past a person\'s grade — exit 2 at step ②, zero writes, the exact line to write named', [unnamed.exit, unnamed.res.stoppedAt, writes(unnamed), String(unnamed.res.refusal).includes('`Ruling-ref: priority:p3 「his words」`'), String(unnamed.res.refusal).includes(GRADE_RULING_MARK)], [EXIT_USAGE, 2, 0, true, true], unnamed.text); + const passedTwo = (r) => r.text.includes('② grade — `priority:p1` changes under the comment\'s `Ruling-ref:` line, which names `priority:p3`'); + const ticked = await foldRegrade('Ruling-ref: `priority:p3` 「改到 p3」', { ...CARD, events: [HAND] }); + const tight = await foldRegrade('Ruling-ref: priority:p3「改到 p3」', { ...CARD, events: [HAND] }); + t('…the grade in backticks, or set tight against his words, names it: past step ② with no events read, and said so', [passedTwo(ticked), passedTwo(tight), ticked.fake.calls.filter((c) => c.op === 'events-list').length], [true, true, 0], ticked.text); + const plainFleet = await foldRegrade('Ruling-ref: 「车道席自分诊 … 方可首触定 p1/p2」', CARD); + t('…over a grade the fleet may change anyway, an unnamed `Ruling-ref:` passes step ②, saying the new grade will read as the fleet\'s own and the line that would make it his', [plainFleet.text.includes('② REFUSED'), plainFleet.text.includes("will read as the fleet's own"), plainFleet.text.includes('`Ruling-ref: priority:p3`')], [false, true, true], plainFleet.text); + const deadComments = await driveOffline(REGRADE, { ...CARD, events: [RELAY], hooks: { 'comments-list': [{ status: 502 }] } }); + t('a comments read answered 502 beside a fleet grade is exit 2 with zero writes', [deadComments.exit, writes(deadComments)], [EXIT_USAGE, 0]); const dead = await driveOffline(REGRADE, { ...CARD, hooks: { 'events-list': [{ status: 502 }] } }); t('an events read answered 502 is exit 2 with zero writes — never a guess', [dead.exit, writes(dead)], [EXIT_USAGE, 0]); const relayRoute = { requested: 'dispatch', transport: 'dispatch', reason: 'self-test: relay', error: null, session: 'session_01ABCDEFGHJKMNPQRSTVWXYZ' };