Skip to content

Commit f619d31

Browse files
committed
fix(pm): the record reader closes a fence only on a bare run and opens its scope only on an unindented heading; the writer refuses on a key LINE and names the two new causes
`contractReviewHeadSha` (check-half-states.mjs) closed a fence on any run of the opening character, so a closing line with trailing text — fence content to CommonMark — ended the fence and a `Head-sha:` line after it was read. It also opened its heading scope on a `## Contract review` heading indented four spaces or a tab, an indented code block to the renderer, while holding the key line itself to three spaces. Both read the same as base and appear in 0 of 713 live records; both are now closed, each pinned and ablated once. `FENCE_CLOSE_LINE` admits whitespace only after the run; the scope opens on `^[ ]{0,3}#` and the shared marker keeps its tolerance for the locator. `post-stamped.mjs` tested the `Head-sha` key ANYWHERE in a record-shaped comment, so one that quoted a record heading and named the key mid-sentence was refused at write time. `HEAD_SHA_KEY_LINE` now asks for a line opening on the key, however decorated (indent, blockquotes, a bullet or a list number, bold, backticks), so every refused shape #28042 pinned stays refused and the prose mention is not. The refusal's `why` and `RECORD_KEY_SPELLINGS['Head-sha']` name the code-indented line and the line under a quoted or code-indented heading. No new refusal class, no new gate. `contract-review.md:33` now says the `Head-sha:` line sits 题头之下, at 120 bytes and line-neutral; the `--template` note says the same in English. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4czoR81DDKSnGWnBYqA
1 parent 549203d commit f619d31

4 files changed

Lines changed: 56 additions & 25 deletions

File tree

‎.claude/skills/pm-dispatch/references/contract-review.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- 新 head 即清;点名现 head 时 (b) 不起;条件满足由持有车道挂等复核标记或落交接行。
3131
- 逾 24 小时条件未满的 hold 列入分诊轮次记录(`check-owed-reviews.mjs` 标出)。
3232
- 复核记录 = 一条评论落 PR 或卡,席内与子代理同形;散文、dev 自评、`os-dev-report` 恒不算。
33-
- 同形 = `## Contract review` 题头、`Head-sha:` 行独占码段、①②③ 逐项、独立性对、PASS/FAIL。
33+
- 同形 = `## Contract review` 题头之下 `Head-sha:` 行独占码段、①②③逐项、独立性对、PASS/FAIL。
3434
- 同形含首行 `Served-tier:`:值写该面所定档的常量名 `CONTRACT_REVIEW_TIER` 或 `TIER_DEFAULT`;
3535
无此行不成裁决;模板 `node scripts/pm/record-recognisers.mjs --template`,申报面加 `--face declaration`。
3636
- 同形带 `Local-runs:` 行:`none` 或 `probe — REASON` 具名唯一探针;有行必校,缺行旧记录不改判。

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12687,8 +12687,16 @@ export const CONTRACT_REVIEW_HEAD_SHA_LINE = new RegExp(
1268712687
* open fence (a nested ``` inside a ```` block, a ~~~ inside a ``` block), and
1268812688
* reading past either would read fenced content as the record's line. An
1268912689
* unclosed fence runs to the end of the body, as it renders.
12690+
*
12691+
* An OPENING fence may carry an info string after the run (```md); a CLOSING
12692+
* fence may not — a run followed by anything but whitespace is content of the
12693+
* open fence, not its close (`FENCE_CLOSE_LINE`), as CommonMark renders it.
12694+
* Measured in the delta review of the fence-tracking reader (2026-10-30): a
12695+
* ``` followed by prose closed the fence here while the renderer kept it open,
12696+
* so a `Head-sha:` line after it was read; 0 of 713 live records carry one.
1269012697
*/
1269112698
const FENCE_LINE = /^[ ]{0,3}(`{3,}|~{3,})/;
12699+
const FENCE_CLOSE_LINE = /^[ ]{0,3}(`{3,}|~{3,})[ \t]*$/;
1269212700

1269312701
/**
1269412702
* The head a contract-review record names — the span on the first `Head-sha:`
@@ -12702,14 +12710,17 @@ const FENCE_LINE = /^[ ]{0,3}(`{3,}|~{3,})/;
1270212710
* ABOVE the record's own line — read as the head, so the record was found at
1270312711
* the cited head and absent at the real one. None is prose to a first-line
1270412712
* reader, and all four shapes are what a quotation looks like. So: lines
12705-
* before the first UNQUOTED heading-marker line are skipped — the heading is
12706-
* read with `CONTRACT_REVIEW_HEADING_MARKER`, but a blockquoted heading opens
12707-
* nothing here, because a fully quoted record (heading, head line and
12708-
* signature all under `>`) followed by a plain line opening `Head-sha:` would
12709-
* otherwise hand the quoted record's signature to the plain line's head; the
12710-
* locator still finds such a comment as a record, and it then names no head.
12711-
* A fenced line is skipped, fence boundaries included, with the fence closed
12712-
* only by its own character and length (`FENCE_LINE`); and
12713+
* before the first UNQUOTED, UNINDENTED heading-marker line are skipped — the
12714+
* heading is read with `CONTRACT_REVIEW_HEADING_MARKER`, but a blockquoted
12715+
* heading opens nothing here, because a fully quoted record (heading, head
12716+
* line and signature all under `>`) followed by a plain line opening
12717+
* `Head-sha:` would otherwise hand the quoted record's signature to the plain
12718+
* line's head; nor does a heading indented four spaces or a tab, which is an
12719+
* indented code block to the renderer, held to the same three-space bound as
12720+
* the key line itself; the locator still finds such a comment as a record,
12721+
* and it then names no head. A fenced line is skipped, fence boundaries
12722+
* included, with the fence closed only by its own character and length on a
12723+
* line of its own (`FENCE_LINE`, `FENCE_CLOSE_LINE`); and
1271312724
* `CONTRACT_REVIEW_HEAD_SHA_LINE` itself refuses the blockquote, the bullet
1271412725
* and an indented-code line. Among the lines that remain, the FIRST wins, as
1271512726
* `readServedTier` reads its key: a record is one comment and names one head,
@@ -12729,15 +12740,18 @@ export function contractReviewHeadSha(body) {
1272912740
let fence = null; // the OPEN fence — its character and run length — or null outside one
1273012741
let belowHeading = false;
1273112742
for (const line of String(body ?? '').split(/\r?\n/)) {
12743+
if (fence !== null) {
12744+
const c = FENCE_CLOSE_LINE.exec(line);
12745+
if (c !== null && c[1][0] === fence.ch && c[1].length >= fence.len) fence = null;
12746+
continue;
12747+
}
1273212748
const f = FENCE_LINE.exec(line);
1273312749
if (f !== null) {
12734-
if (fence === null) fence = { ch: f[1][0], len: f[1].length };
12735-
else if (f[1][0] === fence.ch && f[1].length >= fence.len) fence = null;
12750+
fence = { ch: f[1][0], len: f[1].length };
1273612751
continue;
1273712752
}
12738-
if (fence !== null) continue;
1273912753
if (!belowHeading) {
12740-
belowHeading = CONTRACT_REVIEW_HEADING_MARKER.test(line) && !/^\s*>/.test(line);
12754+
belowHeading = CONTRACT_REVIEW_HEADING_MARKER.test(line) && /^[ ]{0,3}#/.test(line);
1274112755
continue;
1274212756
}
1274312757
const m = CONTRACT_REVIEW_HEAD_SHA_LINE.exec(line);
@@ -33545,6 +33559,12 @@ Doubles as the fire's **write self-check** (step 0). \`201\` is not the reading.
3354533559
// ⛔ A fence closes only on its OWN character and a run at least as long: a nested ``` inside ````, a ~~~ inside ```,
3354633560
// are content, and a `Head-sha:` line between them stays fenced; a longer closing run closes; a never-closed one runs out.
3354733561
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('|'));
33562+
// ⛔ A closing run with TRAILING TEXT is fence content, not a close (CommonMark): the fence stays open past it, so a
33563+
// `Head-sha:` line after such a line is still fenced; a bare run later closes it; whitespace after the run still closes.
33564+
t('⛔ record reader: a fence is closed only by a run on a line of its OWN — a run with trailing text is content, so the line after it stays fenced; a bare run later closes; trailing whitespace still closes', [contractReviewHeadSha(UNDER51('```', '``` not a close', `Head-sha: \`${HEAD51}\``)), contractReviewHeadSha(UNDER51('```', '``` not a close', `Head-sha: \`${HEAD51}\``, '```', `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51('~~~', '~~~ tail', `Head-sha: \`${HEAD51}\``, '~~~', `Head-sha: \`${OLDHEAD51}\``)), contractReviewHeadSha(UNDER51('```md', `Head-sha: \`${HEAD51}\``, '``` ', `Head-sha: \`${OLDHEAD51}\``))].join('|'), ['', OLDHEAD51, OLDHEAD51, OLDHEAD51].join('|'));
33565+
// ⛔ A heading indented as CODE (four spaces or a tab) opens no scope — the same three-space bound the key line is held
33566+
// to — while one indented up to three spaces does; the marker itself keeps its tolerance for the locator.
33567+
t('⛔ record reader: a `## Contract review` heading indented four spaces or a tab opens no scope, one indented three does; the marker still finds the indented one', [contractReviewHeadSha([' ## Contract review', `Head-sha: \`${HEAD51}\``].join('\n')), contractReviewHeadSha(['\t## Contract review', `Head-sha: \`${HEAD51}\``].join('\n')), contractReviewHeadSha([' ## Contract review', `Head-sha: \`${HEAD51}\``].join('\n')), latestContractReviewOnHead([cm51(1, [' ## Contract review', `Head-sha: \`${HEAD51}\``].join('\n'), T51)], HEAD51), CONTRACT_REVIEW_HEADING_MARKER.test(' ## Contract review')].join('|'), ['', '', HEAD51, '', 'true'].join('|'));
3354833568
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('|'), '|||');
3354933569
// ⛔ The shapes the review of the line-form reader probed (2026-10-30): a `Head-sha:` line naming ANOTHER head above the
3355033570
// 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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,17 +2060,20 @@ export function keyedLineRefusalText(rows) {
20602060

20612061
/** What the record's owner accepts, printed BY the refusal so the fix is one line away. */
20622062
export const RECORD_KEY_SPELLINGS = Object.freeze({
2063-
'Head-sha': '`Head-sha: ` then the reviewed head as 7 to 40 hex in a code span of its OWN, at the START of a line BELOW the `## Contract review` heading — not blockquoted, not bulleted, not inside a fence, not before the heading; the first such line is the head the record names, and a record written before the line existed may omit it',
2063+
'Head-sha': '`Head-sha: ` then the reviewed head as 7 to 40 hex in a code span of its OWN, at the START of a line (up to three spaces of indent) BELOW an unquoted, unindented `## Contract review` heading — not blockquoted, not bulleted, not inside a fence, not indented as code (four spaces or a tab), not before the heading, not under a quoted or code-indented heading; the first such line is the head the record names, and a record written before the line existed may omit it',
20642064
'Local-runs': '`Local-runs: none` at the START of a line, or `Local-runs: probe — REASON` naming the ONE local run the read-only rule was broken for and why; a record written before the line existed may omit it',
20652065
});
20662066

2067-
/** PRESENCE only, case-blind: a `Head-sha` key anywhere in the body, however decorated or placed. Consulted solely to
2068-
* tell "the author wrote the key and the reader cannot read it" (refused) from "no key at all" (not re-judged). */
2069-
const HEAD_SHA_KEY_ANYWHERE = /head-sha[ \t`*]*:/i;
2067+
/** PRESENCE only, case-blind: a `Head-sha` key opening a LINE, however decorated or placed — any indent, blockquote
2068+
* markers, a bullet or a list number, bold or backticks around the key — so a decorated, fenced, code-indented or
2069+
* pre-heading key line still counts as written. Consulted solely to tell "the author wrote the key and the reader
2070+
* cannot read it" (refused) from "no key at all" (not re-judged). ⛔ Not mid-sentence: a comment that quotes a record's
2071+
* heading and then names the key in prose wrote no key line, and was refused for it until 2026-10-30 (loudness only). */
2072+
const HEAD_SHA_KEY_LINE = /^[ \t]*(?:>[ \t]*)*(?:(?:[-*+]|\d+[.)])[ \t]+)?[`*]*head-sha[ \t`*]*:/im;
20702073

20712074
/** The first line carrying a `Head-sha` key, however spelled — a LOCATOR for the writer's eye, ⛔ never the judgement. */
20722075
function headShaKeyLine(text) {
2073-
const hit = text.split(/\r?\n/).find((line) => HEAD_SHA_KEY_ANYWHERE.test(line));
2076+
const hit = text.split(/\r?\n/).find((line) => HEAD_SHA_KEY_LINE.test(line));
20742077
return hit === undefined ? '(no single line carries the key)' : offendingSpan(hit.trim(), 160);
20752078
}
20762079

@@ -2081,7 +2084,8 @@ function headShaKeyLine(text) {
20812084
* verdict over a line nobody had been asked to write. Scoped by the record's own heading marker, on `--comment`
20822085
* alone — a record IS a comment.
20832086
* Head-sha `contractReviewHeadSha` (`check-half-states.mjs`) is the ONE reader every guard reaches the record's head
2084-
* through: the first plain `Head-sha:` line below the heading, outside any blockquote, bullet or fence. A
2087+
* through: the first plain `Head-sha:` line below an unquoted, unindented heading, outside any blockquote,
2088+
* bullet, fence or indented code. A
20852089
* body that carries the key somewhere and reads `null` there would be filed by every reader as a review of
20862090
* NO head — absent on the owed list, refused at the queue — so it is refused here, before the write. The
20872091
* template's null-oid placeholder reads as a head (it is 40 hex) and is not this row's: C6 refuses it.
@@ -2093,8 +2097,8 @@ export function recordKeyedLineRefusals(body) {
20932097
const text = String(body ?? '');
20942098
if (!CONTRACT_REVIEW_HEADING_MARKER.test(text)) return [];
20952099
const rows = [];
2096-
if (HEAD_SHA_KEY_ANYWHERE.test(text) && contractReviewHeadSha(text) === null)
2097-
rows.push({ key: 'Head-sha', line: headShaKeyLine(text), why: '`contractReviewHeadSha` reads NO head here — a `Head-sha` key is present, but no line below the `## Contract review` heading carries it plainly with a hex span of its own (a blockquoted, bulleted, fenced or pre-heading line, the key folded into the span, a bare hex value, a lowercase key and a sub-floor span all read as nothing). Every reader would file this record as a review of NO head.' });
2100+
if (HEAD_SHA_KEY_LINE.test(text) && contractReviewHeadSha(text) === null)
2101+
rows.push({ key: 'Head-sha', line: headShaKeyLine(text), why: '`contractReviewHeadSha` reads NO head here — a `Head-sha` key opens a line, but no line below an unquoted, unindented `## Contract review` heading carries it plainly with a hex span of its own (a blockquoted, bulleted, fenced or pre-heading line, a code-indented line — four spaces or a tab — a line under a quoted or code-indented heading, the key folded into the span, a bare hex value, a lowercase key and a sub-floor span all read as nothing). Every reader would file this record as a review of NO head.' });
20982102
const runs = readLocalRuns(text);
20992103
if (!localRunsStand(runs))
21002104
rows.push({ key: 'Local-runs', line: runs.line, why: '`readLocalRuns` reads the line and cannot grade its value — `none` and `probe — REASON` are the closed set, and a probe with no reason names no deviation.' });
@@ -5319,6 +5323,12 @@ export function selfTest() {
53195323
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}\``])) === '');
53205324
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([])) === '');
53215325
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');
5326+
// ⛔ PRESENCE is a key LINE, however decorated, ⛔ never a mid-sentence mention: a record-shaped comment that names the key
5327+
// in prose wrote no line and is untouched; a key under a code-indented heading, or opening a numbered, doubly quoted
5328+
// or `+`-bulleted line, is a written line the reader refuses, and is refused here.
5329+
t('⭐ NOT a key line: a record-shaped comment that names `Head-sha:` mid-sentence, with no line opening on the key, is untouched — presence is a key LINE', rkeys('## Contract review\n\nThe seat\'s own record carries its Head-sha: line plainly, below the heading; see `Head-sha:` in the template.') === '' && rkeys(`> ## Contract review\n\nquoted above; the record\'s Head-sha: line is \`${SHA_HEAD}\` there`) === '');
5330+
t('⛔ …while a decorated key LINE still counts as written and is refused when the reader names no head: numbered, doubly quoted, `+`-bulleted, and one under a CODE-INDENTED heading', rkeys(SHA_WITH([`1. Head-sha: \`${SHA_HEAD}\``])) === 'Head-sha' && rkeys(SHA_WITH([`> > **Head-sha:** \`${SHA_HEAD}\``])) === 'Head-sha' && rkeys(SHA_WITH([`+ Head-sha: \`${SHA_HEAD}\``])) === 'Head-sha' && rkeys(` ## Contract review\nHead-sha: \`${SHA_HEAD}\``) === 'Head-sha');
5331+
t('the `Head-sha` refusal and the printed spelling NAME the two causes the reader added — a code-indented line and a line under a quoted or code-indented heading', (() => { const text = recordLineRefusalText(recordKeyedLineRefusals(SHA_WITH([`\tHead-sha: \`${SHA_HEAD}\``]))); const rule = RECORD_KEY_SPELLINGS['Head-sha']; return text.includes('a code-indented line — four spaces or a tab') && text.includes('a line under a quoted or code-indented heading') && rule.includes('not indented as code (four spaces or a tab)') && rule.includes('not under a quoted or code-indented heading') && rule.includes('BELOW an unquoted, unindented'); })());
53225332
t('both lines unreadable ⇒ both rows, `Head-sha` first', rkeys(SHA_WITH([`> Head-sha: \`${SHA_HEAD}\``], 'Local-runs: probe')) === 'Head-sha,Local-runs');
53235333
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'); })());
53245334
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,11 @@ export function contractReviewTemplateLines(values = {}) {
17201720
` the review owed by the \`Clause-②: yes\` line alone ⇒ ${TIER_DEFAULT_NAME} (--face declaration).`,
17211721
faceLine,
17221722
' An at-tier/total stamp control may precede it — 75/75, then the constant.',
1723-
' · Head-sha the head you reviewed, 7 to 40 hex in a span of ITS OWN, on THIS line: it is',
1724-
' the only place the head is read, so a sha in the heading or in the prose names',
1725-
' nothing; a span holding the key as well is not a sha, and the record then names',
1726-
' no head.',
1723+
' · Head-sha the head you reviewed, 7 to 40 hex in a span of ITS OWN, on THIS line, plain and',
1724+
' BELOW the heading: it is the only place the head is read, so a sha in the heading',
1725+
' or in the prose names nothing; a span holding the key as well is not a sha, and a',
1726+
' quoted, bulleted, fenced, code-indented or pre-heading line is prose — the record',
1727+
' then names no head.',
17271728
' · Local-runs `none` — the read-only shape held (the diff, the card and the head\'s check-runs;',
17281729
' nothing built, run or re-run locally); or `probe — REASON`, naming the ONE local run',
17291730
' the rule was broken for. A record without the line predates it and is not re-judged;',

0 commit comments

Comments
 (0)