diff --git a/.claude/skills/pm-dispatch/references/l1-review-checklist.md b/.claude/skills/pm-dispatch/references/l1-review-checklist.md index c58f7e39d4c..2b057e54168 100644 --- a/.claude/skills/pm-dispatch/references/l1-review-checklist.md +++ b/.claude/skills/pm-dispatch/references/l1-review-checklist.md @@ -1,8 +1,14 @@ # L1 审核清单细则 -见 execution-duties.md 〈L1 审核〉;本文逐项展开每份 dev 报告的 L1 判据。 +见 execution-duties.md 〈L1 审核〉;本文展开其判据,机械项现读 `l1-face.mjs --pr N`。 -## PR 形态与卡片关系(机械项现读 `l1-face.mjs --pr N`) +- 判决评论照下块,REWORK/REJECT 同形;⛔ 无他拼法。 +``` +## 席位核对 +**ACCEPT** · head `SHA8` · read YYYY-MM-DDThh:mmZ +``` + +## PR 形态与卡片关系 - PR 存在、是 draft、目标 `main`,正文首行引用卡片。 - `Fixes #` 仅当合并应当关卡;只落地了可实施的一半 ⇒ 必须 `Part of #`。 @@ -12,7 +18,7 @@ - `Part of` 收口的卡不会自动关,`pm:dispatched` 必须手工摘,动作要件见落地细则 B。 - ACCEPT 那一刻记进落地待办,⛔ 不留给下次巡检。 -## 范围与 changeset(机械项现读 `l1-face.mjs --pr N`) +## 范围与 changeset - 无 `content/docs/releases/` 改动、用户可见改动有 changeset、无卡外或超 `Scope-review:` 的文件。 - 种类非 `none` 或带 `(narrowing)`:`Skills-docs:` 行在且属实;`follow-up owed` 立卡改 `#N`;缺 ⇒ REWORK。 @@ -34,10 +40,10 @@ - 移动/拆分重构净增远超纯移动:逐文件点清多出各块用途,记进 ACCEPT 评论;点不清判 REWORK。 - 非测试源文件已超 2,000 行又净增 >300 行:ACCEPT 点名为何进不了新模块,无理由 ⇒ REWORK。 -## 测试与门禁证据(机械项现读 `l1-face.mjs --pr N`) +## 测试与门禁证据 - 测试证据要有真实命令与通过输出,⛔ 不接受一句 tests pass。 -- 测量类交付先看阳性对照:对照本身失败 ⇒ 该读数记 INCONCLUSIVE,⛔ 不入账。 +- 测量类交付先看阳性对照:对照失败 ⇒ 该读数记 INCONCLUSIVE,⛔ 不入账。 - L1 审核项证据已销毁(评论、卡或 PR 答 404)⇒ 记 NOT MEASURED 并写因,⛔ 不记通过或无旗。 - 引 entry `.d.ts` 逐字节相同的读数必须同块带阳性对照,它只判名字集。 - 对 barrel 已转发符号的形状恒无效:`export *` 与 `export type { X } from` 都不复述形状。 @@ -76,6 +82,6 @@ - 判据是它报的证据面(搜了什么、找到什么)加 PM 自己在 `origin/main` 上的复核。 - 验收判据本身也可被证伪:dev 用测量推翻字面判据、换上更强的不变量门禁照 ACCEPT。 - 但推翻过程必须写在 PR 正文并附 main 语料上的实测信噪比,否则按 REWORK 要证据。 -- `+0/-0` 先疑 NUL,以 blob 定论,现读 `l1-face.mjs --pr N`;要求源侧写转义序列。 +- `+0/-0` 先疑 NUL,以 blob 定论;要求源侧写转义序列。 - 以死代码或不可达为由的删除,PM 先在 `origin/main` 用带引号精确名核引用面,再 ACCEPT。 - 卡的交付物含系统性 sweep 时,ACCEPT 评论把范围外产出成组列出并写明 sweep 判据。 diff --git a/package.json b/package.json index 63b028a864f..66eaab99179 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "check:declared-population-live": "node scripts/check-declared-population-live.mjs --self-test && node scripts/check-declared-population-live.mjs", "check:pm-half-states": "node scripts/pm/check-half-states.mjs --self-test", "check:issue-citations": "node scripts/check-issue-citations.mjs --self-test", - "check:pm-record-recognisers": "node scripts/pm/record-recognisers.mjs --self-test && node scripts/pm/check-owed-reviews.mjs --self-test && node scripts/pm/mailbox-open.mjs --self-test && node scripts/pm/fleet-roster.mjs --self-test", + "check:pm-record-recognisers": "node scripts/pm/record-recognisers.mjs --self-test && node scripts/pm/check-owed-reviews.mjs --self-test && node scripts/pm/mailbox-open.mjs --self-test && node scripts/pm/fleet-roster.mjs --self-test && node scripts/pm/seat-record.mjs --self-test", "check:pm-prior-rulings": "node scripts/pm/check-prior-rulings.mjs --self-test && node scripts/pm/card-pick.mjs --self-test && node scripts/pm/round-open.mjs --self-test", "check:pm-write-pace": "node scripts/pm/write-pace.mjs --self-test", "check:pm-fleet-token": "node scripts/pm/fleet-token.mjs --self-test", diff --git a/scripts/pm/seat-record.mjs b/scripts/pm/seat-record.mjs index 632783c00ec..205471ce62f 100644 --- a/scripts/pm/seat-record.mjs +++ b/scripts/pm/seat-record.mjs @@ -33,9 +33,42 @@ * `ACCEPT` is the only verdict that lets a pull land; `REWORK` and `REJECT` * never do, and a record whose verdict cannot be read carries `null`. * - * ⛔ No network, no I/O, no imports: a body in, a reading out. + * ## The record, as it is WRITTEN: the one template, and its pin + * + * Reading is wide on purpose; writing is not. Two more readers find a verdict + * through a LINE marker and nothing else: H48 through `ACCEPT_VERDICT_MARKER` + * (`**ACCEPT**` opening a line), and H44 through `H44_VERDICT_MARKER`. Both + * live in `check-half-states.mjs`, and the repair direction their headers name + * is the WRITE side. The inline heading above reads as a record here and as + * no verdict at all to H48, so a record written that way is an ACCEPT the + * patrol never sees. + * + * So the seat writes every verdict comment, ACCEPT, REWORK and REJECT alike, + * from the ONE template in `references/l1-review-checklist.md`: the heading + * with no verdict word on it, then the verdict line as the first line under + * it, `**ACCEPT** · head … · read …`, carrying the tip AND the UTC stamp a + * seat text owes (`reading-discipline.md`). `--self-test` reads that template + * out of the checklist, renders it for each verdict word and pins every + * rendering against this file's reading and against the markers it IMPORTS + * from `check-half-states.mjs`, and asks H44's own predicate + * (`h44UntimestampedReading`, imported too) whether the filled line is a + * reading with no time. ⛔ A marker is never re-spelled here: each verdict + * is held to the ACCEPT marker with its word swapped, derived from the + * imported source, and to the marker that file exports under + * `_VERDICT_MARKER` wherever it exports one (REWORK, beside ACCEPT; + * REJECT has none, and H48 does not read it). + * + * ⛔ No network, no I/O, one import (the entry predicate): a body in, a + * reading out. Only `--self-test` reads a file and loads + * `check-half-states.mjs`, lazily, from inside the run: that file imports + * this one, so a static import back would be a cycle, and the dispatch below + * never awaits at module scope, so the lazy load finds this module settled + * (a top-level await here would deadlock it; `check-half-states.mjs` measures + * that shape). */ +import { isEntrypoint } from '../invoked-as.mjs'; + /** * The seat's record, as a heading line — line-anchored, an optional leading * blockquote, no `g` flag (so two reads of one body agree). A `###` @@ -77,3 +110,214 @@ export function seatRecordOf(body) { export function seatRecordAccepts(body) { return seatRecordOf(body)?.verdict === 'ACCEPT'; } + +// --------------------------------------------------------------------------- +// --self-test: the written template, pinned against every reader +// --------------------------------------------------------------------------- + +/** The file the seat writes its verdict comments from, relative to the repo root. */ +const TEMPLATE_PATH = '.claude/skills/pm-dispatch/references/l1-review-checklist.md'; + +/** + * Every fenced block of a markdown text whose lines carry a record heading: + * the template candidates. `[]` for none; more than one is the caller's + * refusal, never a choice made here. Pure. + */ +function templateBlocks(text) { + const blocks = []; + let open = null; + for (const line of String(text ?? '').split(/\r?\n/)) { + if (/^[ \t]*(?:`{3,}|~{3,})/.test(line)) { + if (open === null) open = []; + else { + if (open.some((l) => SEAT_RECORD_MARKER.test(l))) blocks.push(open.join('\n')); + open = null; + } + continue; + } + if (open !== null) open.push(line); + } + return blocks; +} + +/** The template's verdict slot: the one `ACCEPT` it carries, swapped for `verdict`. */ +const renderTemplate = (block, verdict) => block.replace(/\bACCEPT\b/g, verdict); + +/** + * The template's two reading slots, and what a seat fills them with: the head + * tip (a hex short sha, the `tree` reading H44 looks for) and the UTC stamp + * (`reading-discipline.md` spells it `YYYY-MM-DDThh:mmZ`). + */ +const SHA_SLOT = 'SHA8'; +const STAMP_SLOT = 'YYYY-MM-DDThh:mmZ'; +const fillSlots = (text) => text.replace(SHA_SLOT, '0123abcd').replace(STAMP_SLOT, '2026-12-04T10:20Z'); + +/** The rendering with the ` · ` segment that carries the stamp slot cut: the stampless control. Pure. */ +const withoutStamp = (text) => text.split('\n').map((line) => line.split(' · ').filter((seg) => !seg.includes(STAMP_SLOT)).join(' · ')).join('\n'); + +/** + * Why `body` is NOT a canonical `verdict` comment: `[]` when it is. `markers` + * holds the line markers this verdict must meet (`accept`, `perVerdict`, + * `anyVerdict`). The canonical shape: a record heading carrying no verdict + * word, its first non-blank line under it met by every line marker, the + * record reading `verdict`, and, for REWORK and REJECT, no ACCEPT anywhere + * H48 would see one. Pure. + */ +function canonicalVerdictProblems(body, verdict, markers) { + const text = String(body ?? ''); + const problems = []; + const lines = text.split(/\r?\n/); + const at = lines.findIndex((line) => SEAT_RECORD_MARKER.test(line)); + if (at === -1) return ['no `## 席位核对` heading opens a line']; + // Any verdict word on the heading, not only one the inline arm reads (`— L1 REWORK @` is none). + if (new RegExp(`\\b(?:${VERDICT_WORD})\\b`).test(lines[at])) problems.push('the heading itself carries a verdict word'); + const first = lines.slice(at + 1).find((line) => line.trim() !== ''); + if (first === undefined) problems.push('no line under the heading'); + else { + for (const marker of markers.perVerdict) { + if (!marker.test(first)) problems.push(`the first line under the heading misses ${marker}`); + } + if (!markers.anyVerdict.test(first)) problems.push('the first line under the heading misses `H44_VERDICT_MARKER`'); + } + const read = seatRecordOf(text)?.verdict ?? null; + if (read !== verdict) problems.push(`the record reads ${read} here, not ${verdict}`); + if (verdict !== 'ACCEPT' && markers.accept.test(text)) problems.push('H48 would read this as an ACCEPT'); + return problems; +} + +/** + * The battery roster and its floor (AGENTS.md, Writing a `--self-test`): the + * NAMES are pinned, each with its minimum case count, and the roster's own + * size beside it, so a battery deleted or emptied reds by name. + */ +const SELF_TEST_BATTERIES = Object.freeze({ + 'the imported markers: present, and the ACCEPT word derivable': 3, + 'the template: one block in the checklist, one verdict slot': 3, + 'every verdict rendered from the template reads canonically': 3, + 'a REWORK or REJECT rendering never reads as ACCEPT': 2, + 'the filled verdict line carries a stamp H44 accepts': 8, + 'the live free-form spellings are refused, each for its named problem': 7, +}); +const SELF_TEST_BATTERY_FLOOR = 6; + +// Set as the self-test's last statement, after its verdict prints; the +// dispatch refuses a run that returned without it (AGENTS.md: the handshake). +let selfTestReachedVerdict = false; + +async function selfTest() { + const seen = new Map(); + let current = null; + let failed = 0; + const battery = (name) => { current = name; seen.set(name, seen.get(name) ?? 0); }; + const t = (label, actual, expected) => { + seen.set(current, (seen.get(current) ?? 0) + 1); + const ok = JSON.stringify(actual) === JSON.stringify(expected); + if (!ok) { + failed += 1; + console.error(` ✗ [${current}] ${label}\n expected ${JSON.stringify(expected)}\n actual ${JSON.stringify(actual)}`); + } + }; + + const halfStates = await import('./check-half-states.mjs'); + const { readFileSync } = await import('node:fs'); + const { ACCEPT_VERDICT_MARKER: accept, H44_VERDICT_MARKER: anyVerdict, h44UntimestampedReading: untimestamped } = halfStates; + + battery('the imported markers: present, and the ACCEPT word derivable'); + t('`ACCEPT_VERDICT_MARKER` is a RegExp exported by check-half-states.mjs', accept instanceof RegExp, true); + t('`H44_VERDICT_MARKER` is a RegExp exported by check-half-states.mjs', anyVerdict instanceof RegExp, true); + t('the ACCEPT marker spells its word exactly once, so a swap derives the others', (String(accept?.source).match(/ACCEPT/g) ?? []).length, 1); + if (!(accept instanceof RegExp) || !(anyVerdict instanceof RegExp)) { + console.error('\n✗ seat-record self-test: the markers did not import; nothing below can be judged.'); + process.exitCode = 1; + return; + } + const markersFor = (verdict) => { + const derived = verdict === 'ACCEPT' ? accept : new RegExp(accept.source.replace('ACCEPT', verdict), accept.flags); + const exported = halfStates[`${verdict}_VERDICT_MARKER`]; + return { accept, anyVerdict, perVerdict: exported instanceof RegExp && verdict !== 'ACCEPT' ? [derived, exported] : [derived] }; + }; + + battery('the template: one block in the checklist, one verdict slot'); + const checklist = readFileSync(new URL(`../../${TEMPLATE_PATH}`, import.meta.url), 'utf8'); + const blocks = templateBlocks(checklist); + t(`${TEMPLATE_PATH} carries exactly one fenced block with a record heading`, blocks.length, 1); + const template = blocks[0] ?? ''; + t('the block carries exactly one verdict slot (`ACCEPT`)', (template.match(/\bACCEPT\b/g) ?? []).length, 1); + t('the extractor is capable of failing: a text with no template, and one with two', [templateBlocks('# x\n\n```\nplain\n```\n').length, templateBlocks(`\`\`\`\n${template}\n\`\`\`\n\`\`\`\n${template}\n\`\`\``).length], [0, 2]); + + battery('every verdict rendered from the template reads canonically'); + for (const verdict of SEAT_RECORD_VERDICTS) { + t(`${verdict}: the rendered template is canonical`, canonicalVerdictProblems(renderTemplate(template, verdict), verdict, markersFor(verdict)), []); + } + + battery('a REWORK or REJECT rendering never reads as ACCEPT'); + for (const verdict of SEAT_RECORD_VERDICTS.filter((v) => v !== 'ACCEPT')) { + const rendered = renderTemplate(template, verdict); + t(`${verdict}: H48's ACCEPT marker does not match, and this file's reading does not accept`, [accept.test(rendered), seatRecordAccepts(rendered)], [false, false]); + } + + battery('the filled verdict line carries a stamp H44 accepts'); + t('`h44UntimestampedReading` is a function exported by check-half-states.mjs', typeof untimestamped, 'function'); + t(`the template carries exactly one \`${SHA_SLOT}\` slot and one \`${STAMP_SLOT}\` slot`, [template.split(SHA_SLOT).length - 1, template.split(STAMP_SLOT).length - 1], [1, 1]); + for (const verdict of SEAT_RECORD_VERDICTS) { + const rendered = renderTemplate(template, verdict); + t(`${verdict}: the filled rendering is no untimestamped reading`, untimestamped(fillSlots(rendered)), null); + // The control: the same line with its stamp segment cut is the form H44 calls malformed. + t(`${verdict}: control — the stampless rendering is a hit on its tip`, untimestamped(fillSlots(withoutStamp(rendered)))?.kind ?? null, 'tree'); + } + + battery('the live free-form spellings are refused, each for its named problem'); + const refusedFor = (body, verdict, problem) => canonicalVerdictProblems(body, verdict, markersFor(verdict)).includes(problem); + const noHeading = 'no `## 席位核对` heading opens a line'; + const onHeading = 'the heading itself carries a verdict word'; + const missLine = (verdict) => `the first line under the heading misses ${markersFor(verdict).perVerdict[0]}`; + t('`L1-a verdict: **REWORK** at head` — no heading, the word not at line start', refusedFor('L1-a verdict: **REWORK** at head `0123abcd`', 'REWORK', noHeading), true); + t('`**Verdict: REWORK.**` — the bold opens on another word', refusedFor('## 席位核对\n\n**Verdict: REWORK.**', 'REWORK', missLine('REWORK')), true); + t('`## 席位核对 — L1 REWORK @` — the verdict on the heading', refusedFor('## 席位核对 — L1 REWORK @ `0123abcd`\n\n1. 范围 ✓', 'REWORK', onHeading), true); + t('`## 席位核对 — ACCEPT · …` — the inline heading H48 never sees', refusedFor('## 席位核对 — ACCEPT · domain:skills#2\n\n1. 范围 ✓', 'ACCEPT', missLine('ACCEPT')), true); + t('`**Accept**` — a lowercase verdict is malformed', refusedFor('## 席位核对\n**Accept** · head `0123abcd`', 'ACCEPT', missLine('ACCEPT')), true); + t('the verdict line below a checklist line — not the first line under the heading', refusedFor('## 席位核对\n1. 范围 ✓\n**ACCEPT** · head `0123abcd`', 'ACCEPT', missLine('ACCEPT')), true); + t('`**L1-a · ACCEPT · #N @ …**` — the live bold line, no heading over it', refusedFor('**L1-a · ACCEPT · #39606 @ `428eb43d50` · Area: ot-build · read 2026-12-04T10:20Z**', 'ACCEPT', noHeading), true); + + const declared = Object.keys(SELF_TEST_BATTERIES); + const floor = []; + if (declared.length < SELF_TEST_BATTERY_FLOOR) floor.push(`the roster declares ${declared.length} batteries, below its pinned ${SELF_TEST_BATTERY_FLOOR}`); + for (const name of seen.keys()) if (!declared.includes(name)) floor.push(`battery "${name}" ran but is not declared`); + for (const name of declared) { + const n = seen.get(name) ?? 0; + if (n < SELF_TEST_BATTERIES[name]) floor.push(n === 0 ? `battery "${name}" DID NOT RUN` : `battery "${name}" ran ${n} case(s), below its floor of ${SELF_TEST_BATTERIES[name]}`); + } + for (const message of floor) console.error(`✗ self-test floor: ${message}`); + failed += floor.length; + + const total = [...seen.values()].reduce((a, b) => a + b, 0); + if (failed > 0) { + console.error(`\n✗ seat-record self-test: ${failed} failure(s) (cases and floor).`); + process.exitCode = 1; + return; + } + const own = SEAT_RECORD_VERDICTS.filter((v) => halfStates[`${v}_VERDICT_MARKER`] instanceof RegExp); + console.log(`✓ seat-record self-test: ${total} cases across ${declared.length} batteries pass (verdicts with an exported marker of their own: ${own.join(', ') || 'none'}).`); + selfTestReachedVerdict = true; +} + +if (isEntrypoint(import.meta.url)) { + if (process.argv.includes('--self-test')) { + // ⛔ Never `await` here: a top-level await keeps this module unsettled, and the + // self-test's lazy load of check-half-states.mjs (which imports this file) deadlocks. + selfTest().then( + () => { + if (selfTestReachedVerdict || process.exitCode) return; + console.error('\n✗ seat-record self-test: selfTest() returned without reaching its verdict — a run that never finished is not a pass.'); + process.exitCode = 1; + }, + (err) => { + console.error(`\n✗ seat-record self-test threw: ${err?.stack ?? err}`); + process.exitCode = 1; + }, + ); + } else { + console.error('usage: node scripts/pm/seat-record.mjs --self-test (a library otherwise; import it)'); + process.exitCode = 2; + } +}