Skip to content

Commit 2e75b19

Browse files
committed
fix(pm): the Head-sha reader opens scope only on an unquoted heading, refuses code-indented lines, and closes a fence only on its own character and length
Contract-review should-fixes 1–3 on the first head of this branch: - A blockquoted `## Contract review` opens no head scope. A fully quoted signed record followed by a plain prose line opening `Head-sha:` read the plain line as the head, under the quoted signature; the locator still sees such a comment as a record (the marker keeps its `>` tolerance), and it now names no head. - `CONTRACT_REVIEW_HEAD_SHA_LINE` allows at most three spaces of indent (CommonMark's limit before an indented code block) and no tab, so a `Head-sha:` line rendered as code is skipped above the record's own line and names nothing alone. - `FENCE_LINE` captures the fence run; a fence closes only on the same character with a run at least as long, so a nested or mismatched fence keeps its content fenced. Pins for each shape in the H51 battery, the locator battery (floor 13 to 14; the blockquoted-heading pin flips to ABSENT with its reason) and the post-stamped record battery (floor 17 to 18). Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4czYNVYrGQqbs51hpvv
1 parent fd3f1f3 commit 2e75b19

3 files changed

Lines changed: 51 additions & 24 deletions

File tree

‎scripts/pm/check-half-states.mjs‎

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12649,10 +12649,13 @@ export const H51_SHA_SPAN = /`([0-9a-fA-F]{7,40})`/g;
1264912649
* record itself, but this line decides WHICH HEAD a PASS clears, and a quoted
1265012650
* or bulleted `Head-sha:` line is one the author CITED rather than wrote (a
1265112651
* review quoting the seat's hand-off, a record quoting an earlier record), so
12652-
* a reader that took it read a quoted sha as reviewed. `contractReviewHeadSha`
12652+
* a reader that took it read a quoted sha as reviewed. The key may be indented
12653+
* by at most three spaces, CommonMark's limit before a line becomes an
12654+
* INDENTED CODE BLOCK: four spaces or a tab render the line as code, which is
12655+
* a quotation too, so the regex refuses them. `contractReviewHeadSha`
1265312656
* adds the two positional rules a single-line regex cannot carry: the line
12654-
* sits BELOW the record's own `## Contract review` heading and outside any
12655-
* fenced code block. The VALUE is a hex code span of
12657+
* sits BELOW the record's own UNQUOTED `## Contract review` heading and
12658+
* outside any fenced code block. The VALUE is a hex code span of
1265612659
* its OWN — the shape `--template` prints — and it is the FIRST thing after the
1265712660
* colon (spaces and bold may precede it, ⛔ nothing else); what follows the span
1265812661
* on that line is prose and decides nothing. A key folded into the span with
@@ -12666,17 +12669,19 @@ export const H51_SHA_SPAN = /`([0-9a-fA-F]{7,40})`/g;
1266612669
* cannot read BEFORE the write.
1266712670
*/
1266812671
export const CONTRACT_REVIEW_HEAD_SHA_LINE = new RegExp(
12669-
`^[ \\t]*(?:\\*\\*)?\`?Head-sha\`?(?:\\*\\*)?[ \\t]*:(?:[ \\t]|\\*\\*)*${H51_SHA_SPAN.source}`,
12672+
`^[ ]{0,3}(?:\\*\\*)?\`?Head-sha\`?(?:\\*\\*)?[ \\t]*:(?:[ \\t]|\\*\\*)*${H51_SHA_SPAN.source}`,
1267012673
);
1267112674

1267212675
/**
12673-
* A fenced-code boundary, as CommonMark opens and closes one: three or more
12674-
* backticks or tildes at the line start (up to three spaces of indent).
12675-
* One toggle for both fence characters — the reader needs "inside a fence or
12676-
* not", never which fence; an unclosed fence runs to the end of the body, as
12677-
* it renders.
12676+
* A fence line, as CommonMark spells one: three or more backticks or tildes at
12677+
* the line start (up to three spaces of indent). The run is captured because a
12678+
* fence CLOSES only on the same character with a run at least as long as the
12679+
* one that opened it: a shorter run, or the other character, is content of the
12680+
* open fence (a nested ``` inside a ```` block, a ~~~ inside a ``` block), and
12681+
* reading past either would read fenced content as the record's line. An
12682+
* unclosed fence runs to the end of the body, as it renders.
1267812683
*/
12679-
const FENCE_LINE = /^[ ]{0,3}(?:`{3,}|~{3,})/;
12684+
const FENCE_LINE = /^[ ]{0,3}(`{3,}|~{3,})/;
1268012685

1268112686
/**
1268212687
* The head a contract-review record names — the span on the first `Head-sha:`
@@ -12690,11 +12695,16 @@ const FENCE_LINE = /^[ ]{0,3}(?:`{3,}|~{3,})/;
1269012695
* ABOVE the record's own line — read as the head, so the record was found at
1269112696
* the cited head and absent at the real one. None is prose to a first-line
1269212697
* reader, and all four shapes are what a quotation looks like. So: lines
12693-
* before the first heading-marker line are skipped (the heading is read with
12694-
* `CONTRACT_REVIEW_HEADING_MARKER`, blockquoted heading included, exactly as
12695-
* the locator finds the record); a fenced line is skipped, fence boundaries
12696-
* included; and `CONTRACT_REVIEW_HEAD_SHA_LINE` itself refuses the blockquote
12697-
* and the bullet. Among the lines that remain, the FIRST wins, as
12698+
* before the first UNQUOTED heading-marker line are skipped — the heading is
12699+
* read with `CONTRACT_REVIEW_HEADING_MARKER`, but a blockquoted heading opens
12700+
* nothing here, because a fully quoted record (heading, head line and
12701+
* signature all under `>`) followed by a plain line opening `Head-sha:` would
12702+
* otherwise hand the quoted record's signature to the plain line's head; the
12703+
* locator still finds such a comment as a record, and it then names no head.
12704+
* A fenced line is skipped, fence boundaries included, with the fence closed
12705+
* only by its own character and length (`FENCE_LINE`); and
12706+
* `CONTRACT_REVIEW_HEAD_SHA_LINE` itself refuses the blockquote, the bullet
12707+
* and an indented-code line. Among the lines that remain, the FIRST wins, as
1269812708
* `readServedTier` reads its key: a record is one comment and names one head,
1269912709
* and a later `Head-sha:` line (a quoted record, say) is prose to this reader.
1270012710
* Measured on the 709 records with a line-initial heading posted to this
@@ -12709,16 +12719,18 @@ const FENCE_LINE = /^[ ]{0,3}(?:`{3,}|~{3,})/;
1270912719
* record: a body carrying a `Head-sha` key that reads `null` here is refused.
1271012720
*/
1271112721
export function contractReviewHeadSha(body) {
12712-
let fenced = false;
12722+
let fence = null; // the OPEN fence — its character and run length — or null outside one
1271312723
let belowHeading = false;
1271412724
for (const line of String(body ?? '').split(/\r?\n/)) {
12715-
if (FENCE_LINE.test(line)) {
12716-
fenced = !fenced;
12725+
const f = FENCE_LINE.exec(line);
12726+
if (f !== null) {
12727+
if (fence === null) fence = { ch: f[1][0], len: f[1].length };
12728+
else if (f[1][0] === fence.ch && f[1].length >= fence.len) fence = null;
1271712729
continue;
1271812730
}
12719-
if (fenced) continue;
12731+
if (fence !== null) continue;
1272012732
if (!belowHeading) {
12721-
belowHeading = CONTRACT_REVIEW_HEADING_MARKER.test(line);
12733+
belowHeading = CONTRACT_REVIEW_HEADING_MARKER.test(line) && !/^\s*>/.test(line);
1272212734
continue;
1272312735
}
1272412736
const m = CONTRACT_REVIEW_HEAD_SHA_LINE.exec(line);
@@ -33504,7 +33516,17 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading.
3350433516
t('⛔ record reader: a delta record on head A whose PROSE names head B is NO review of B', latestContractReviewOnHead([cm51(1, DELTA51, T51)], HEAD51), null);
3350533517
t('⭐ record reader: …and IS the review of A — the `Head-sha:` line alone decides', latestContractReviewOnHead([cm51(1, DELTA51, T51)], OLDHEAD51)?.sha, OLDHEAD51);
3350633518
const UNDER51 = (...lines) => ['## Contract review', ...lines].join('\n');
33507-
t('record reader: `contractReviewHeadSha` reads the line\'s span — the first line BELOW the heading wins; bold or backticks on the key, a trailing span and a blockquoted heading are tolerated', [contractReviewHeadSha(DELTA51), contractReviewHeadSha(UNDER51(`**Head-sha:** \`${HEAD51}\` (moved to \`${OLDHEAD51}\`)`, `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51(`\`Head-sha\`: \`${HEAD51}\``)), contractReviewHeadSha(`> ## Contract review\nHead-sha: \`${HEAD51}\``)].join(), [OLDHEAD51, HEAD51, HEAD51, HEAD51].join());
33519+
t('record reader: `contractReviewHeadSha` reads the line\'s span — the first line BELOW the heading wins; bold or backticks on the key, a trailing span and up to three spaces of indent are tolerated', [contractReviewHeadSha(DELTA51), contractReviewHeadSha(UNDER51(`**Head-sha:** \`${HEAD51}\` (moved to \`${OLDHEAD51}\`)`, `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51(`\`Head-sha\`: \`${HEAD51}\``)), contractReviewHeadSha(UNDER51(` Head-sha: \`${HEAD51}\``))].join(), [OLDHEAD51, HEAD51, HEAD51, HEAD51].join());
33520+
// ⛔ A BLOCKQUOTED heading opens no scope: a fully quoted signed record followed by a plain prose line opening
33521+
// `Head-sha:` would otherwise lend the quoted signature to the plain line's head (the locator still sees a record here,
33522+
// through the marker's `>` tolerance — it then names no head). Measured live: 0 of 709 records quote their heading.
33523+
const QUOTED_RECORD51 = `> ## Contract review\n> Head-sha: \`${OLDHEAD51}\`\n> Reviewed-by: \`session_01SEAT\`\n> **VERDICT: PASS**\n\nHead-sha: \`${HEAD51}\` is the head the PR has since moved to.`;
33524+
t('⛔ record reader: a QUOTED record followed by a plain line opening `Head-sha:` names no head — a blockquoted heading opens no scope, and nor does a quoted heading alone', [contractReviewHeadSha(QUOTED_RECORD51), contractReviewHeadSha(`> ## Contract review\nHead-sha: \`${HEAD51}\``), latestContractReviewOnHead([cm51(1, QUOTED_RECORD51, T51)], HEAD51)].join('|'), '||');
33525+
// ⛔ An INDENTED CODE BLOCK (four spaces or a tab) is a quotation too: skipped above the record's own line, nothing alone.
33526+
t('⛔ record reader: a `Head-sha:` line indented as CODE — four spaces or a tab — above the record\'s own is skipped, and alone names no head', [contractReviewHeadSha(UNDER51(` Head-sha: \`${HEAD51}\``, `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51(`\tHead-sha: \`${HEAD51}\``, `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51(` Head-sha: \`${HEAD51}\``)), contractReviewHeadSha(UNDER51(`\tHead-sha: \`${HEAD51}\``))].join('|'), [OLDHEAD51, OLDHEAD51, '', ''].join('|'));
33527+
// ⛔ A fence closes only on its OWN character and a run at least as long: a nested ``` inside ````, a ~~~ inside ```,
33528+
// are content, and a `Head-sha:` line between them stays fenced; a longer closing run closes; a never-closed one runs out.
33529+
t('⛔ record reader: a nested or mismatched fence does not close the open one — the `Head-sha:` line inside stays fenced; a longer run closes; an unmatched run leaves it open to the end', [contractReviewHeadSha(UNDER51('````', '```', `Head-sha: \`${HEAD51}\``, '```', '````', `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51('```', '~~~', `Head-sha: \`${HEAD51}\``, '```', `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51('```', `Head-sha: \`${HEAD51}\``, '`````', `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51('```', '~~~', `Head-sha: \`${HEAD51}\``, '~~~', `Head-sha: \`${OLDHEAD51}\``))].join('|'), [OLDHEAD51, OLDHEAD51, OLDHEAD51, ''].join('|'));
3350833530
t('⛔ record reader: the key folded INTO the span, a bare hex value, a lowercase key and a sub-floor span name no head', [contractReviewHeadSha(UNDER51(`\`Head-sha: ${HEAD51}\``)), contractReviewHeadSha(UNDER51(`Head-sha: ${HEAD51}`)), contractReviewHeadSha(UNDER51(`head-sha: \`${HEAD51}\``)), contractReviewHeadSha(UNDER51('Head-sha: `ba3d95`'))].join('|'), '|||');
3350933531
// ⛔ The shapes the review of the line-form reader probed (2026-10-30): a `Head-sha:` line naming ANOTHER head above the
3351033532
// record's own — placed before the heading, blockquoted, bulleted or fenced. Each is a citation, not the record's line,

‎scripts/pm/post-stamped.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
40874087
'the two positions: a declaration renders as bare digits, and the patrol reads digits': 24,
40884088
'the shared rule: this tool and H56 cannot come to disagree': 6,
40894089
'the keyed lines: a claim\'s exact-value fields, judged by the readers that own them': 30,
4090-
'the record line: a `## Contract review` record\'s `Head-sha:` and `Local-runs:` lines, judged when present — an absent line is not re-judged': 17,
4090+
'the record line: a `## Contract review` record\'s `Head-sha:` and `Local-runs:` lines, judged when present — an absent line is not re-judged': 18,
40914091
'the vacant body: a VACANT seat post\'s ledger holds pointers, never obligations': 27,
40924092
'the decision facets: a decision analysis carries its marker, and a delta, a record or a quotation is not one': 22,
40934093
'the relay transport: the same act as one op, the comment found on the board, the exit register kept apart': 13,
@@ -5318,6 +5318,7 @@ export function selfTest() {
53185318
t('⛔ the key folded INTO the span, a bare hex value and a lowercase key are refused — each names no head to every reader', rkeys(SHA_WITH([`\`Head-sha: ${SHA_HEAD}\``])) === 'Head-sha' && rkeys(SHA_WITH([`Head-sha: ${SHA_HEAD}`])) === 'Head-sha' && rkeys(SHA_WITH([`head-sha: \`${SHA_HEAD}\``])) === 'Head-sha');
53195319
t('⭐ a quoted line ABOVE the record\'s own passes — the reader skips the quotation and reads the line below it', rkeys(SHA_WITH([`> Head-sha: \`${'f'.repeat(40)}\``, `Head-sha: \`${SHA_HEAD}\``])) === '');
53205320
t('⛔ ABSENT is NOT re-judged for this key either: a record with no `Head-sha` key at all passes untouched — the retired-dialect records carry none', rkeys(SHA_WITH([])) === '');
5321+
t('⛔ a fully QUOTED record, and a code-indented (four spaces or tab) line alone, are refused — a quoted heading opens no scope and an indented line is code', rkeys(SHA_WITH([`Head-sha: \`${SHA_HEAD}\``]).split('\n').map((l) => `> ${l}`).join('\n')) === 'Head-sha' && rkeys(SHA_WITH([` Head-sha: \`${SHA_HEAD}\``])) === 'Head-sha' && rkeys(SHA_WITH([`\tHead-sha: \`${SHA_HEAD}\``])) === 'Head-sha');
53215322
t('both lines unreadable ⇒ both rows, `Head-sha` first', rkeys(SHA_WITH([`> Head-sha: \`${SHA_HEAD}\``], 'Local-runs: probe')) === 'Head-sha,Local-runs');
53225323
t('the `Head-sha` refusal prints the spelling that reads, names the owner, and quotes the offending line', (() => { const rows = recordKeyedLineRefusals(SHA_WITH([`> Head-sha: \`${SHA_HEAD}\``])); const text = recordLineRefusalText(rows); return text.includes(RECORD_KEY_SPELLINGS['Head-sha']) && text.includes('contractReviewHeadSha') && rows[0].line.includes('> Head-sha'); })());
53235324
t('⛔ NOT a record: a claim or a report carrying a quoted `Head-sha:` line is untouched — the reader runs on the record\'s heading only', rkeys(`Claim: x\n> Head-sha: \`${SHA_HEAD}\``) === '' && rkeys(`os-dev-report\n\n> Head-sha: \`${SHA_HEAD}\``) === '');

‎scripts/pm/record-recognisers.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ export function locateReviewOfRecord(pair, carriedHead = null) {
20702070
// stopped registering.
20712071
const SELF_TEST_BATTERIES = Object.freeze({
20722072
'the locator: the newest `## Contract review` on this head, on EITHER thread (#17302)': 19,
2073-
'#18141 · #27979: the head sha sits in a span of ITS OWN on the `Head-sha:` line — the key-in-span spelling and a span in the prose name no head': 13,
2073+
'#18141 · #27979: the head sha sits in a span of ITS OWN on the `Head-sha:` line — the key-in-span spelling and a span in the prose name no head': 14,
20742074
'the `Served-tier:` reading — the tier that SERVED the record (#17915 · #18060 · #18174)': 27,
20752075
'⭐ the 2026-09-20 ruling: a pure-regeneration head move KEEPS the record, decided on the COMMITTED trees': 22,
20762076
'#18042: the copyable record TEMPLATE — the one machine-read artefact with nothing to copy': 29,
@@ -2185,7 +2185,7 @@ export async function selfTest() {
21852185
`**Director seat adoption record** — the verdict on \`${HEAD_9AF9}\` below is adopted verbatim.\n\n---\n\n## Contract review\n\n- **Reviewed-by:** \`${RECORD_SESSION}\``,
21862186
].map((body, i) => ({ id: 3310 + i, created_at: '2026-09-01T08:52:00Z', body }));
21872187
t('⛔ the RETIRED dialects — the head in the heading (two spellings), on the first body line, in the adoption sentence — read ABSENT: a record names its head on the `Head-sha:` line or not at all', LEGACY.every((row) => locateReviewOfRecord(pairOf({ prComments: [row] })).state === 'absent'));
2188-
t('a blockquoted heading still reads — H51 tolerates the `>` a seat writes without meaning it', locateReviewOfRecord(pairOf({ prComments: [{ ...RECORD_ON_9AF9, body: RECORD_ON_9AF9.body.replace(/^## /, '> ## ') }] })).state === 'found');
2188+
t('⛔ #28024: a blockquoted heading is still the record MARKER (H51 tolerates the `>`), but it opens no head scope — the record names no head and reads ABSENT', locateReviewOfRecord(pairOf({ prComments: [{ ...RECORD_ON_9AF9, body: RECORD_ON_9AF9.body.replace(/^## /, '> ## ') }] })).state === 'absent');
21892189
t('⛔ a `###` sub-heading is not the marker', locateReviewOfRecord(pairOf({ prComments: [{ ...RECORD_ON_9AF9, body: RECORD_ON_9AF9.body.replace(/^## /, '### ') }] })).state === 'absent');
21902190
t('⛔ the heading mentioned inside a paragraph is not the marker', locateReviewOfRecord(pairOf({ prComments: [{ ...RECORD_ON_9AF9, body: RECORD_ON_9AF9.body.replace(/^## /, 'see the ## ') }] })).state === 'absent');
21912191
const DEV_REPORT = { id: 3303, created_at: '2026-09-01T08:40:00Z', body: `os-dev-report\n\n\`\`\`json\n{ "issue": 13657, "pr": "https://github.com/o/r/pull/13864", "summary": "landed at \`${HEAD_9AF9}\`" }\n\`\`\`` };
@@ -2241,6 +2241,10 @@ export async function selfTest() {
22412241
t('⛔ #28024: a blockquoted, bulleted or fenced `Head-sha:` line ABOVE the record\'s own is ABSENT for the head it names — on the PR thread and on the card alike', CITED_LEADS.every((lead) => locateReviewOfRecord(pairOf({ headSha: DELTA_B, prComments: [QUOTED_ABOVE(lead)] })).state === 'absent' && locateReviewOfRecord(pairOf({ headSha: DELTA_B, cardComments: [QUOTED_ABOVE(lead)] })).state === 'absent'));
22422242
t('⭐ #28024: …and each record is FOUND for the head its OWN line names, with that line\'s full sha', CITED_LEADS.every((lead) => { const r = locateReviewOfRecord(pairOf({ headSha: DELTA_A, prComments: [QUOTED_ABOVE(lead)] })); return r.state === 'found' && r.sha === DELTA_A && r.id === 6516042955; }));
22432243
const PRE_HEADING = { ...QUOTED_ABOVE([]), body: `Head-sha: \`${DELTA_B}\`\n\n${QUOTED_ABOVE([]).body}` };
2244+
// ⛔ A fully QUOTED signed record followed by a plain prose line opening `Head-sha:`: the quoted heading opens no scope,
2245+
// so the plain line is not read against the quoted signature — absent for B, and absent for A (the quoted line is quoted).
2246+
const QUOTED_RECORD = { id: 6516042956, created_at: '2026-10-30T05:53:38Z', body: QUOTED_ABOVE([]).body.split('\n').map((l) => `> ${l}`).join('\n') + `\n\nHead-sha: \`${DELTA_B}\` is the head the PR has since moved to.` };
2247+
t('⛔ #28024: a QUOTED record followed by a plain `Head-sha:` prose line is ABSENT for both heads — a blockquoted heading opens no scope', locateReviewOfRecord(pairOf({ headSha: DELTA_B, prComments: [QUOTED_RECORD] })).state === 'absent' && locateReviewOfRecord(pairOf({ headSha: DELTA_A, prComments: [QUOTED_RECORD] })).state === 'absent');
22442248
t('⛔ #28024: a `Head-sha:` line BEFORE the `## Contract review` heading is not the record\'s — absent for the head it names, found for the one below the heading', locateReviewOfRecord(pairOf({ headSha: DELTA_B, prComments: [PRE_HEADING] })).state === 'absent' && locateReviewOfRecord(pairOf({ headSha: DELTA_A, prComments: [PRE_HEADING] })).state === 'found');
22452249
t('⭐ a correct record beside a refused one is FOUND, in either arrival order', locateReviewOfRecord(pairOf({ prComments: [KEYED_ROW, NEWER_RECORD] })).state === 'found' && locateReviewOfRecord(pairOf({ prComments: [RECORD(HEAD_9AF9, undefined, '2026-09-01T08:45:00Z', 3404), KEYED_ROW] })).state === 'found');
22462250
t('…and the locator chooses the CORRECT one — a refused spelling is never chosen over it, and never chosen at all', locateReviewOfRecord(pairOf({ prComments: [KEYED_ROW, NEWER_RECORD] })).id === 3403 && locateReviewOfRecord(pairOf({ prComments: [RECORD(HEAD_9AF9, undefined, '2026-09-01T08:45:00Z', 3404), KEYED_ROW] })).id === 3404);

0 commit comments

Comments
 (0)