Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .claude/skills/pm-dispatch/references/decision-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
- 问题写客户看到的症状、谁碰到、多频繁;选项句写选了客户看到什么、约几个 PR。
- ⛔ 速读不写代码名、文件路径、命令、裁决字母、裸卡号;点到的卡配一句中文说明。
- 四轴、四棱块、自检行、置信缺口、工作量先例归英文分析段,⛔ 不删。
- 英文段首两行 `Served-tier: <CONTRACT_REVIEW_TIER | TIER_DEFAULT>`、`Analysed-by: <session>`(执笔会话或子代理),⛔ 不写模型 id;标 `CONTRACT_REVIEW_TIER` 须执笔转录过 `verify-review-tier.mjs`(评论、新卡、新引入该行的正文刷新经 `--tier-evidence=` 写入即判)。
- 英文段首两行 `Served-tier: <CONTRACT_REVIEW_TIER | TIER_DEFAULT>`、`Analysed-by: <session>`(执笔会话;子代理执笔写派它并贴出的会话,同 `Reviewed-by:`),值恰一 token,⛔ 不写散文、模型 id;标 `CONTRACT_REVIEW_TIER` 须执笔转录过 `verify-review-tier.mjs`(评论、新卡、新引入该行的正文刷新经 `--tier-evidence=` 写入即判),拒即子代理达档重跑 ⛔ 不改档名。
- 呈维护者前读该行(`check-owed-reviews.mjs --decisions` 逐卡列):缺或未达档 ⇒ 达档重跑,贴带两行的 delta 评论(逐棱同异)再呈;⛔ 永不呈读不出档的分析。
- 达档且仍现行(载行后无裁决、正文未改)⇒ 照原样呈,只跑前提 re-check,⛔ 不重跑;前提已变 ⇒ 达档重跑。
- 最新一份分析为准:读最新带两行者,其后无行的分析读作缺行;推荐变了同笔改速读,先刷正文、隔分钟再贴 delta(同分钟读 stale)。

分析段骨架:背景 / Governing text(引文 + grep,或 none found + 检索式)/ 协议声明、是否改协议 /
带 re-check 命令的前提 / 具体问题 / 选项 / 推荐 / 相关单与 PR。正文六项:
Expand Down
54 changes: 43 additions & 11 deletions scripts/pm/check-owed-reviews.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@
* the NEWEST text on the card that carries a line of the pair — the body, or a comment (a delta
* re-analysis is newer than the body it re-runs): `at-tier`, `below-tier`, `unreadable`, `missing`
* (no line anywhere; the row says whether the card carries an analysis at all), or `unjudged` (the
* thread could not be read). Read through the queue guard's author binding, as records are: a body
* thread could not be read). ⛔ The newest ANALYSIS governs, not the newest line: an analysis posted
* after the carrier with no line of the pair reads `missing` (it names the analysis it supersedes and
* the line it leaves unread), never the older line it was written to replace. Read through the queue guard's author binding, as records are: a body
* or comment by any other author is never the carrier, and the drops are counted on the row.
* carrier the comment id that carries the line, or `body`.
* current whether the analysis is still the card's question: `stale` when a ruling comment
* (`classifyRulingComment`, the prior-rulings reader's three measured shapes) follows the carrier,
* (`classifyRulingComment`, the prior-rulings reader's three measured shapes, or a comment whose first
* content line is `Ruling-ref:` — the maintainer ruling a seat records on the card, a grade ruling
* included: the safe direction) follows the carrier,
* when the body carries a `Ruled:` record (`ruledRecords`) at or after it, or, for a comment
* carrier, when the body's newest protocol stamp (`lastWriteStamp`) is at or after its minute — a
* body written since. ⚠️ A body edit that writes no stamp is NOT seen: the REST issue carries no
Expand All @@ -137,7 +141,7 @@ import process from 'node:process';

import { isEntrypoint } from '../invoked-as.mjs';
import { cardIntakeKeys, CONTRACT_REVIEW_HEADING_MARKER, contractReviewVerdictLines, DECISION_INBOX_LABEL, latestMarkedComment, readSignatureLine, ruledRecords, seatNameId, seatIntakeKeys, signedSeatId, withSeatNumbers } from './check-half-states.mjs';
import { classifyRulingComment } from './check-prior-rulings.mjs';
import { classifyRulingComment, firstContentLine } from './check-prior-rulings.mjs';
import { lastWriteStamp } from './post-stamped.mjs';
import { repoIdForSlug } from './check-governed-merges.mjs';
import { GOVERNED_APPROVERS, NARROWING_FACE_LINE, narrowingDeclarationsIn, recordAuthorTrusted, recordTrustedAuthors } from './check-governed-queue-guard.mjs';
Expand Down Expand Up @@ -572,6 +576,16 @@ const createdMs = (row) => {
const byThreadOrder = (a, b) => createdMs(a) - createdMs(b) || Number(a?.id) - Number(b?.id);
const minuteFloor = (ms) => Math.floor(ms / 60000) * 60000;

/**
* A comment that records a maintainer ruling on its first content line, `Ruling-ref: …` (a grade set on a decision
* card, a ruling quoted where a seat executes it). ⛔ Read on the first content line only, after the signature line
* (`firstContentLine`): a claim or a triage audit carrying a `Ruling-ref:` line further down cites a ruling, and is
* not one. Local to this reader: the prior-rulings reader keeps its three shapes.
*/
export function isRulingRefComment(body) {
return /^Ruling-ref\s*[::]/.test(firstContentLine(body));
}

/**
* Whether the analysis on `carrier` is still the card's question — the reasons it is not, empty when it is. Pure.
* The bound (an unstamped body edit is unseen) is the header's.
Expand All @@ -580,8 +594,8 @@ export function decisionCurrency(card, comments, carrier) {
const reasons = [];
const at = carrier.where === 'body' ? Number.NEGATIVE_INFINITY : createdMs(carrier.row);
const after = carrier.where === 'body' ? comments : comments.filter((c) => byThreadOrder(c, carrier.row) > 0);
const ruling = after.find((c) => classifyRulingComment(c?.body) !== null);
if (ruling) reasons.push(`ruling comment ${ruling.id ?? '?'} after it`);
const ruling = after.find((c) => classifyRulingComment(c?.body) !== null || isRulingRefComment(c?.body));
if (ruling) reasons.push(`ruling comment ${ruling.id ?? '?'} after it${isRulingRefComment(ruling.body) ? ' (`Ruling-ref:`)' : ''}`);
const ruled = ruledRecords(card?.body ?? '').find((r) => r.at === null || r.at >= minuteFloor(at));
if (ruled) reasons.push(`body \`Ruled: ${ruled.id}\`${ruled.at === null ? ' (unstamped)' : ''} at or after it`);
if (carrier.where === 'comment') {
Expand All @@ -597,14 +611,18 @@ export function decisionCurrency(card, comments, carrier) {
*/
export function decisionAnalysisRow(card, comments, trusted = RECORD_AUTHORS) {
const base = { card: card?.number ?? null, title: String(card?.title ?? '') };
if (!Array.isArray(comments)) return { ...base, state: 'unjudged', analysis: null, carrier: null, analysedBy: null, current: null, act: DECISION_ACT_RERUN, ignored: 0, bodyRead: false };
if (!Array.isArray(comments)) return { ...base, state: 'unjudged', analysis: null, carrier: null, uncarried: null, analysedBy: null, current: null, act: DECISION_ACT_RERUN, ignored: 0, bodyRead: false };
const kept = comments.filter((c) => recordAuthorTrusted(c, trusted)).sort(byThreadOrder);
const bodyRead = recordAuthorTrusted(card, trusted);
const texts = [
...(bodyRead ? [{ where: 'body', id: null, row: card, reading: readDecisionAnalysisTier(card.body) }] : []),
...kept.map((c) => ({ where: 'comment', id: c.id ?? null, row: c, reading: readDecisionAnalysisTier(c.body) })),
];
const carrier = [...texts].reverse().find((x) => x.reading.carriesLine) ?? null;
// The newest ANALYSIS governs: one with no line of the pair supersedes an older carrier and reads `missing`.
const newest = [...texts].reverse().find((x) => x.reading.analysis) ?? null;
const older = [...texts].reverse().find((x) => x.reading.carriesLine) ?? null;
const carrier = newest?.reading.carriesLine ? newest : null; // a line rides only on an analysis, so no analysis ⇒ no line
const uncarried = carrier === null && newest !== null && older !== null ? { where: newest.where, id: newest.id, supersedes: older.where === 'body' ? 'body' : older.id } : null;
const state = carrier === null ? 'missing' : carrier.reading.state;
const current = carrier === null ? null : decisionCurrency(card, kept, carrier);
const by = carrier?.reading.analysedBy;
Expand All @@ -613,6 +631,7 @@ export function decisionAnalysisRow(card, comments, trusted = RECORD_AUTHORS) {
state,
analysis: texts.some((x) => x.reading.analysis),
carrier: carrier === null ? null : { where: carrier.where, id: carrier.id, at: carrier.row?.created_at ?? null },
uncarried,
analysedBy: by === undefined ? null : by.state === 'read' ? by.value : by.state,
current,
act: state === 'at-tier' && current?.state === 'current' ? DECISION_ACT_PRESENT : DECISION_ACT_RERUN,
Expand All @@ -633,6 +652,7 @@ export function renderDecisionRow(row) {
const where = row.carrier === null ? null : row.carrier.where === 'body' ? 'line in the body' : `line on comment ${row.carrier.id}`;
const parts = [`#${row.card} ${row.state}`];
if (row.state === 'unjudged') parts.push('thread not read');
else if (row.uncarried) parts.push(`newer analysis ${row.uncarried.where === 'body' ? 'in the body' : `on comment ${row.uncarried.id}`} carries no Served-tier / Analysed-by line (supersedes the line ${row.uncarried.supersedes === 'body' ? 'in the body' : `on comment ${row.uncarried.supersedes}`})`);
else if (row.carrier === null) parts.push(row.analysis ? 'analysis carries no Served-tier / Analysed-by line' : 'no analysis found on the card');
else parts.push(`${where} (Analysed-by ${row.analysedBy})`, row.current.state === 'current' ? 'current' : `stale: ${row.current.reasons.join('; ')}`);
const dropped = row.ignored > 0 || (row.bodyRead === false && row.state !== 'unjudged') ? ` (${row.bodyRead ? '' : 'body by an untrusted author not read; '}${row.ignored} comment(s) by an untrusted author not read)` : '';
Expand All @@ -644,7 +664,7 @@ export function renderDecisionReport(rows, { repo, now, gaps }) {
const n = (pred) => rows.filter(pred).length;
const present = n((r) => r.act === DECISION_ACT_PRESENT);
const lines = [
`check-owed-reviews --decisions — ${repo}, ${new Date(now).toISOString().replace(/:\d\d\.\d{3}Z$/, 'Z')}: ${rows.length} open \`${DECISION_INBOX_LABEL}\` card(s); `
`check-owed-reviews --decisions — ${repo}, ${new Date(now).toISOString().replace(/:\d\d\.\d{3}Z$/, 'Z')}: ${rows.length} open \`${DECISION_INBOX_LABEL}\` card(s), this repository only (another repository's box: --repo OWNER/NAME); `
+ `${present} at tier and current (${DECISION_ACT_PRESENT}), ${rows.length - present} to re-run at tier — `
+ `${n((r) => r.state === 'at-tier') - present} at tier but stale, ${n((r) => r.state === 'below-tier')} below tier, ${n((r) => r.state === 'missing')} missing, ${n((r) => r.state === 'unreadable')} unreadable, ${n((r) => r.state === 'unjudged')} unjudged.`,
'',
Expand All @@ -653,7 +673,7 @@ export function renderDecisionReport(rows, { repo, now, gaps }) {
if (gaps.length > 0) lines.push('', `⚠️ sweep INCOMPLETE — ${gaps.length} read(s) failed; the rows above are not the whole answer:`, ...gaps.map((g) => ` - ${g}`));
lines.push(
'',
'`current` reads ruling comments, `Ruled:` records and the body\'s newest stamp; a body edit that writes no stamp is not seen (REST carries no body-edit time) — the premise re-check covers it.',
'`current` reads ruling comments (a first-line `Ruling-ref:` too), `Ruled:` records and the body\'s newest stamp; a body edit that writes no stamp is not seen (REST carries no body-edit time) — the premise re-check covers it.',
'Report-only: exit 0, nothing written. The rule is `references/decision-analysis.md` 〈落卡分析模板〉.',
);
return lines;
Expand Down Expand Up @@ -807,7 +827,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
'the report: one line per owing PR, TAKE first, exit 0': 5,
'the hold: a live hold on this head holds (b) alone, (a) and (c) still fire; a new head clears it; at 24 hours it is listed, still WAIT': 14,
// The decision box (`--decisions`): the analysis tier read by the record's own parser, its carrier, its currency.
'the decision box: each open needs-user-decision card\'s analysis tier on its newest carrier — at tier, below, missing, unjudged — whether it is still current, and what the seat does with it': 16,
'the decision box: each open needs-user-decision card\'s analysis tier on its newest carrier — at tier, below, missing, unjudged — whether it is still current, and what the seat does with it': 22,
});
const SELF_TEST_BATTERY_FLOOR = 10;
const UNATTRIBUTED_BATTERY = '(no battery open)';
Expand Down Expand Up @@ -1074,6 +1094,17 @@ export function selfTest() {
t('⭐ MISSING — an analysis with no line ⇒ re-run, and the row says the card does carry an analysis', r4.state === 'missing' && r4.carrier === null && r4.analysis === true && r4.act === DECISION_ACT_RERUN && renderDecisionRow(r4).includes('analysis carries no Served-tier'));
t('…and a card with no analysis at all says so', renderDecisionRow(decisionAnalysisRow(card({ body: `${DSIG}\nA plain question.` }), [])).includes('no analysis found on the card'));
t('⭐ the NEWEST carrier governs, both ways — an at-tier body under a TIER_DEFAULT delta is below tier, and the reverse is at tier', decisionAnalysisRow(card({ body: analysisBody(AT) }), [delta(7301, '2026-11-30T09:00:00Z', 'TIER_DEFAULT')]).state === 'below-tier' && decisionAnalysisRow(card({ body: analysisBody('TIER_DEFAULT') }), [delta(7301, '2026-11-30T09:00:00Z')]).state === 'at-tier');
// A later analysis with no line of the pair supersedes the older carrier (#38874 N-a): the newest ANALYSIS governs.
const bare = (id, at) => cmt(id, at, `${DSIG}\n## Re-analysis\n\nos-decision-facets\n- ① 项目长远合理性:changed.\n\nThis seat now recommends **B**.`);
const r5 = decisionAnalysisRow(card(), [delta(7301, '2026-11-30T09:00:00Z'), bare(7303, '2026-11-30T11:00:00Z')]);
t('⛔ a NEWER analysis with no line supersedes the at-tier carrier ⇒ missing, re-run; the row names both comments', r5.state === 'missing' && r5.carrier === null && r5.act === DECISION_ACT_RERUN && r5.uncarried?.id === 7303 && r5.uncarried?.supersedes === 7301 && renderDecisionRow(r5).includes('newer analysis on comment 7303') && renderDecisionRow(r5).includes('line on comment 7301'), JSON.stringify(r5));
t('…while a newer comment that is no analysis (a plain note) leaves the carrier governing', decisionAnalysisRow(card(), [delta(7301, '2026-11-30T09:00:00Z'), cmt(7304, '2026-11-30T11:00:00Z', `${DSIG}\nPremise re-checked: holds.`)]).act === DECISION_ACT_PRESENT);
// A maintainer ruling recorded on its first content line as `Ruling-ref:` (#38874 N-b, e.g. a grade ruling).
const ref = (id, at, first) => cmt(id, at, `${DSIG}\n\n${first}\nQuestion, verbatim: 「x」`);
t('⛔ a comment whose FIRST content line is `Ruling-ref:` after the carrier is a ruling ⇒ stale, and the reason says so', (() => { const r = decisionAnalysisRow(card(), [delta(7301, '2026-11-30T09:00:00Z'), ref(7305, '2026-11-30T10:00:00Z', 'Ruling-ref: priority:p2 · 2026-11-30T09:59Z · a grade set by the maintainer.')]); return r.current.state === 'stale' && r.current.reasons[0].includes('7305') && r.current.reasons[0].includes('Ruling-ref') && r.act === DECISION_ACT_RERUN; })());
t('…while a claim that CITES a ruling on a later line is not one ⇒ still current', decisionAnalysisRow(card(), [delta(7301, '2026-11-30T09:00:00Z'), ref(7306, '2026-11-30T10:00:00Z', 'Claim: PM loop round 4\nRuling-ref: 7300000001')]).current.state === 'current' && isRulingRefComment(`${DSIG}\n**Ruling-ref:** 7303021478`) && !isRulingRefComment('Claim: x\nRuling-ref: 1'));
// The refresh order the rule states (#38874 N-c): body first, the delta in a LATER minute; the same minute reads stale.
t('⭐ body refreshed first, delta posted in a later minute ⇒ current; the same minute ⇒ stale (stamps read to the minute, the safe direction)', decisionAnalysisRow(card({ body: analysisBody(null, 'Refreshed 2026-11-30T09:00Z.') }), [delta(7301, '2026-11-30T09:01:10Z')]).current.state === 'current' && decisionAnalysisRow(card({ body: analysisBody(null, 'Refreshed 2026-11-30T09:01Z.') }), [delta(7301, '2026-11-30T09:01:50Z')]).current.state === 'stale');
t('⛔ the author binding: an at-tier delta by an untrusted author is never the carrier, and the drop is counted and printed', (() => { const r = decisionAnalysisRow(card(), [delta(7301, '2026-11-30T09:00:00Z')].map((c) => ({ ...c, user: { login: 'drive-by' } }))); return r.state === 'missing' && r.ignored === 1 && renderDecisionRow(r).includes('1 comment(s) by an untrusted author not read'); })());
t('⛔ …and a body by an untrusted author is not read either', (() => { const r = decisionAnalysisRow(card({ body: analysisBody(AT), user: { login: 'drive-by' } }), []); return r.state === 'missing' && r.bodyRead === false && renderDecisionRow(r).includes('body by an untrusted author not read'); })());
t('⛔ a `## Contract review` record on the card is not an analysis\'s carrier', decisionAnalysisRow(card(), [recordRow(HEAD)]).state === 'missing');
Expand All @@ -1087,6 +1118,7 @@ export function selfTest() {
};
const out = [];
const code = main(['--decisions', '--now', '2026-12-01T00:00:00Z'], { get: boxGet, log: (l) => out.push(l) });
t('the report states its SCOPE — one repository, and how to read another (#38874 N-f)', renderDecisionReport([], { repo: 'objectstack-ai/objectstack', now: Date.parse('2026-12-01T00:00:00Z'), gaps: [] })[0].includes('this repository only'));
t('the live read: the label listing through the one reader, a PR dropped, a failed thread a GAP and its card unjudged, exit 0', code === EXIT_OK && boxPaths[0].includes(`labels=${encodeURIComponent(DECISION_INBOX_LABEL)}`) && boxPaths[0].includes('state=open') && out.some((l) => l.startsWith('#38700 unjudged')) && out.some((l) => l.includes('sweep INCOMPLETE')) && !out.some((l) => l.startsWith('#1 ')), out.join(' | '));
t('the report: re-run rows first, the present row last, and the bound on body edits printed', (() => { const i = out.findIndex((l) => l.startsWith('#38700')); const j = out.findIndex((l) => l.startsWith('#38624')); return i > 0 && j > i && out[j].endsWith('A decision') && out[j].includes(DECISION_ACT_PRESENT) && out.some((l) => l.includes('a body edit that writes no stamp is not seen')); })(), out.join(' | '));
}
Expand All @@ -1112,7 +1144,7 @@ export function selfTest() {
+ 'the (a) / (b) / (c) triggers and the taker — the seat a hand-off names, an L2 seat on the delta of its own record, else the lane seat, never triage; claims holding and lapsing, the earliest live claim holding; the two live drafts as TAKE; '
+ 'every read through one reader with failures as gaps; the report, exit 0; a lane\'s live hold holding (b) alone, '
+ 'cleared by a new head, an unreadable hold line voiding nothing and printed, listed at 24 hours and still WAIT; '
+ 'the decision box — each analysis\'s tier on its newest trusted carrier, at tier, below, missing or unjudged, stale after a ruling or a body written since, and present-as-it-stands only at tier and current).',
+ 'the decision box — each analysis\'s tier on its newest trusted carrier, at tier, below, missing or unjudged, a newer analysis with no line reading missing, stale after a ruling (a first-line `Ruling-ref:` too) or a body written since, and present-as-it-stands only at tier and current).',
);
selfTestReachedVerdict = true;
return 0;
Expand Down
Loading
Loading