From fd329e536cf0634fe25d141b1cfc032fd3e755b0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 23:00:24 +0000 Subject: [PATCH 01/10] pm: land low-risk skills wording on the seat's review (Tier S arm on the catalog rows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The skills-catalog and ui-skills-catalog register rows keep tier H for every path-only reader and carry a low-risk reading: a diff whose only governed paths are catalog paths, whose other paths are changesets or docs prose, whose body declares a bare `Clause-②: no` and which carries no `security` label reads Tier S. The queue guard reads it on the merge_group leg off the pull object it already fetches, over every commit of the PR; `--pr` reads it off the same GET. Everything else, and any unread input, stays Tier H. docs/adr stays Tier H. AGENTS.md Prime Directive 14 and the pm-dispatch landing lines name the arm. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- .claude/skills/pm-dispatch/SKILL.md | 4 +- .../pm-dispatch/references/lanes/skills.md | 2 +- AGENTS.md | 24 +- scripts/pm/check-governed-merges.mjs | 254 +++++++++++++++++- scripts/pm/check-governed-queue-guard.mjs | 111 +++++++- 5 files changed, 361 insertions(+), 34 deletions(-) diff --git a/.claude/skills/pm-dispatch/SKILL.md b/.claude/skills/pm-dispatch/SKILL.md index 90437f09b37..d0afa425b0a 100644 --- a/.claude/skills/pm-dispatch/SKILL.md +++ b/.claude/skills/pm-dispatch/SKILL.md @@ -183,7 +183,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报 - governed 面(定 Tier,非车道):`docs/adr/**`+`.claude/**`+`skills/**`+`docs/NORTH-STAR.md`+`.github/workflows/**`。 - governed 面同含 `AGENTS.md`+`CLAUDE.md`;`GOVERNED_REPOS` 同治理、行可限仓,执行席恒随落地仓车道。 - 另含 `ui/docs/adr/**`+`ui/.claude/**`+`ui/skills/**`+`ui/AGENTS.md`+`ui/CLAUDE.md`+`ui/.github/workflows/**`。 -- 路径面命中 Tier H ⇒ ACCEPT 换终局四件套,混合 diff ⛔ 不按比例判;要拆让 dev 单独开 PR。 +- 定档 Tier H ⇒ ACCEPT 换终局四件套,混合 diff ⛔ 不按比例判;要拆让 dev 单独开 PR。 - 改动 >3000 行(含生成物)同换终局四件套含③请审,⛔ 无 Tier S 例外;读数=PR additions+deletions。 - ① 席位记录落 PR 先于 `pr_ready`/入队且钉 head:速读六行+席位意见,其下 `## 席位核对`。 - ② PR 悬着等人批,同笔挂 `pm:awaiting-merge`;人工直合即审核记录,授权批准 ⇒ 席位落地。 @@ -200,7 +200,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报 - ④ 轮报单列 awaiting a human merge 并现读请审人;⛔ 未请审不在 chat 报「等你批」,先补请。 - skills 车道自有 PR:纯代码面如 `scripts/pm/` 由本席自读(清单不减)后落地。 - 受管面两层:Tier S = `.claude/**`+下行 S 面,余皆 Tier H 等人批;S 经达档 PASS 后 ready → 入队。 -- 本仓 `.github/workflows/**` 由 `readWorkflowDiff` 定档:发布路径、C2 触发、拒读或未读 ⇒ H,余 S。 +- 本仓 `.github/workflows/**` 由 `readWorkflowDiff`、技能措辞由 `lowRiskArmVerdict` 定档,未读 ⇒ H。 - 入队资格:每 check 绿或预期 skip,⛔ 非必查子集;名单 check-expected-skips.mjs 只判 objectstack。 - 非必查红是真缺陷或坏门,归 PM 入队前处置;第三种按设计而红,三条全立才可带红入队: - 源码自述 pushed 分支上按设计而红、不跑 `merge_group`、PR 评论记明门与因,缺一即否。 diff --git a/.claude/skills/pm-dispatch/references/lanes/skills.md b/.claude/skills/pm-dispatch/references/lanes/skills.md index b8e0e942763..f6a9ab43eba 100644 --- a/.claude/skills/pm-dispatch/references/lanes/skills.md +++ b/.claude/skills/pm-dispatch/references/lanes/skills.md @@ -21,7 +21,7 @@ ## 常设承诺 - 四维分析先于派发与复核。 -- Tier H 受管 PR 恒 draft 等维护者的字;flip 或 arm 前跑 `check-governed-merges --test` 带路径。 +- Tier H 受管 PR 恒 draft 等维护者的字;flip 或 arm 前跑 `check-governed-merges --pr N` 定档。 - 档位从 `--tier` 推导引用;pm-dispatch 根恒契约复审档;条款②闸门照现行。 - 棘轮逐行付账,⛔ re-wrap 筹行;砍点逐条核幸存,被砍内容若在别处无家,砍掉就是丢规则。 - 「Instruments serve the fleet」答不出的 finding ⇒ 建议 p3 或不做,⛔ 不自入队;定级归分诊。 diff --git a/AGENTS.md b/AGENTS.md index 06e3e9b81d4..bcccfd829f3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -273,7 +273,7 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas. seat merges, queues, or arms auto-merge on a PR whose diff touches one.** The governed surfaces are `docs/adr/**`, `docs/NORTH-STAR.md`, `.claude/**` (agents, hooks and settings — not only skills), `skills/**`, `AGENTS.md`, `CLAUDE.md` and `.github/workflows/**`, and under `ui/` `ui/docs/adr/**`, `ui/.claude/**`, `ui/skills/**`, - `ui/AGENTS.md`, `ui/CLAUDE.md` and `ui/.github/workflows/**`, all Tier H. The register is `GOVERNED_SURFACES` in + `ui/AGENTS.md`, `ui/CLAUDE.md` and `ui/.github/workflows/**`. The register is `GOVERNED_SURFACES` in `scripts/pm/check-governed-merges.mjs`, each row carrying its tier; adding a surface is an edit *there*, never here, and `pnpm check:pm-governed-prose` reds per-PR when this paragraph names fewer surfaces than the register — or more. A fork PR (head repo ≠ base repo) is a proposal, never a delivery, whatever its paths: no AI seat readies, @@ -284,17 +284,17 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas. auto-merge, ⛔ never flip it out of draft to make any of those possible — judged on the PR's **file list**, not its description; a **mixed diff is not a proportion question**, one path hit is enough; to land the rest, split off the governed files. **The landing is tiered by the register; one Tier H path makes the whole PR Tier H.** **Tier H** - (人合: every register row except `.claude/**` and Tier S workflow edits): those four lift only for an - authorized APPROVED review by an account in `GOVERNED_APPROVERS`, on ANY commit and not dismissed; that word is - spent once per PR — the OWNING seat then lands it, later pushes included; the click stays the maintainer's. - **Tier S** (席内达档复核落地: objectstack workflow edits `readWorkflowDiff` reads as Tier S, and all of - `.claude/**`): those four lift once the PR thread or its card carries a `## Contract review` record for the PR's - current head with `Served-tier: CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning - seat then lands it through the queue; the post-merge audit is the compensating control. A PR whose only governed - paths are register rows the queue leg regenerates byte-exact clears with zero approvals — an uncertified - recompute, drift or a hand-authored sibling keeps it governed. ⛔ **No agent seat submits an approving review on a - governed-surface PR, under any account** — an authorized account is agent-operated too; "CI is green" carries no - information about a governance change. An authorized account's enqueue is a review record too: ⛔ never a seat's. + (人合: every register row outside Tier S): those four lift only for an authorized APPROVED review by an account in + `GOVERNED_APPROVERS`, on ANY commit and not dismissed; that word is spent once per PR — the OWNING seat then lands + it, later pushes included; the click stays the maintainer's. **Tier S** (席内达档复核落地: `.claude/**`, and + objectstack workflow edits (`readWorkflowDiff`) and skills wording (`lowRiskArmVerdict`) read as S): those four lift + once the PR thread or its card carries a `## Contract review` record for the PR's current head with `Served-tier: + CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning seat then lands it through the + queue; the post-merge audit is the compensating control. A PR whose only governed paths are register rows the queue + leg regenerates byte-exact clears with zero approvals — an uncertified recompute, drift or a hand-authored sibling + keeps it governed. ⛔ **No agent seat submits an approving review on a governed-surface PR, under any account** — + an authorized account is agent-operated too; "CI is green" carries no information about a governance change. An + authorized account's enqueue is a review record too: ⛔ never a seat's. **Already armed or queued when you read this?** Disable auto-merge AND convert it back to **draft**, which disarms an unqueued PR; no seat act, those two included, is measured to dequeue one (`platform-readings.md`, queue diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 0829fdebf12..51221950696 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -421,7 +421,8 @@ * them. What moved is the LANDING each row waits for, carried as `tier` on the * row and derived per PR by `governedTierFor`: * - * H 人合 — every register row except objectstack's `.claude/**` (today: `docs/adr/**`, + * H 人合 — every register row except objectstack's `.claude/**`, and the split + * rows where their reading says S (today: `docs/adr/**`, * `docs/NORTH-STAR.md`, `skills/**`, `AGENTS.md`, `CLAUDE.md`, and since * the B2 ruling of 2026-10-13 the `workflows` row, `.github/workflows/**`, * scoped to objectstack, objectui and cloud — in objectstack split by @@ -455,7 +456,9 @@ * auto-mode classifier still refuses AI writes to it, so the maintainer's hand * stays its writer and the tier removes only the approval click. * - * Published `skills/**` stays Tier H: the seat did not propose moving it. + * Published `skills/**` stays a Tier H ROW: the 2026-09-18 seat did not propose + * moving it, and no row moved since. What moved on 2026-11-14 is a READING on + * the two catalog rows (section "The low-risk skills arm" below). * `check-governed-queue-guard.mjs` reads `tier` and `governedTierFor` from HERE * (a module-scope import; the cycle that forces its mirrors is with * `check-half-states.mjs`, not with this file), so there is ONE register and one @@ -463,6 +466,46 @@ * the instruction prose names — the tier is an attribute the prose states in * words, which that gate deliberately does not parse. * + * ## The low-risk skills arm (#33501, maintainer ruling 2026-11-14) + * + * The maintainer, verbatim 「同意 把低风险的 Tier H 放权给座位」, then 「把低风险的 + * Tier H 放权给座位,立 p1 卡优化」, agreeing to the scope the coordinator put to + * him: pure docs, ADR annotations or notes, and skills wording land on the + * seat's own contract review; anything touching a contract (spec or published + * types, Clause ②, narrowing) or security stays with him. + * + * Modelled as the workflows split is: the `skills-catalog` and + * `ui-skills-catalog` rows KEEP `tier: H` — every path-only reader (`--test`, + * `--branch`, the CODEOWNERS mirror, the prose gate, the relay's review plan) + * answers exactly as before, and the approvers are still summoned — and carry + * `lowRisk`, scoped to objectstack. A READING of the pull request + * (`lowRiskArmVerdict`: every changed path, the body, the label names) moves + * them to Tier S only when ALL hold: + * + * - every governed path lies under a catalog row — `.claude/**`, a workflow, + * `AGENTS.md`, an ADR or any other row beside it is H; + * - every changed path lies under a hit catalog row or `LOW_RISK_RIDER_PREFIXES` + * (`.changeset/`, `docs/`, `content/docs/`) — an ALLOWLIST, so `packages/**`, + * `ui/packages/**`, a gate script, a ratchet ceiling or a lockfile is H; + * - the body declares `Clause-②: no` with no arm (`readClause2Line`, the one + * reader) — `yes`, `(narrowing)`, malformed or absent is H; + * - the labels were read and none is `security`. + * + * Then the landing is Tier S's: a `## Contract review` record for the current + * head at `CONTRACT_REVIEW_TIER` (the record recognisers' `rules` face — no + * lower tier stands on a governed path) and every check green; the owning seat + * enqueues. ⛔ Fail closed: no reading or an unmeasured one is H. `--pr` reads + * it off the same pull object and file walk; the queue guard's `merge_group` leg + * off the pull it already reads, over every commit of the PR in the group. + * + * NOT moved: `docs/adr/**` stays Tier H. The ruling names ADR notes, but a path + * cannot tell a note from a changed decision, and no mechanical reading was + * ruled; the seat carries that question. Ungoverned `docs/**` and + * `content/docs/**` prose needs nothing — it was never on the register. The + * post-merge sweep still lists every catalog merge (membership did not move), + * so a seat-landed low-risk merge is on the same audit list as a `.claude/**` + * one, where a merge without its PASS record is the finding. + * * ## The workflows row's split (#31538, ruling record 6722205630, letter C) * * In objectstack the `workflows` row's tier is read off the DIFF, not the @@ -1037,6 +1080,7 @@ import { tmpdir } from 'node:os'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { historyHorizon } from './git-history.mjs'; +import { readClause2Line } from './clause2-line.mjs'; import { EXIT_PREREQUISITE_NOT_MET, INSTALL_FIX, reportPrerequisiteNotMet } from '../import-prerequisite.mjs'; import { isEntrypoint } from '../invoked-as.mjs'; @@ -1093,12 +1137,14 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the per-row repository scope (ruled B2, 2026-10-13)': 20, 'the nested `ui/` workspace rows, on the register (#25712)': 16, '⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75, + '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 24, }); // DELETING an entry silences that battery's floor exactly as effectively as // zeroing it, so the roster's own size is pinned too. Raised 35 → 36 with the // workflows split battery (ruling record 6722205630): one battery, one row. -const SELF_TEST_BATTERY_FLOOR = 36; +// Raised 36 → 37 with the low-risk skills arm battery (#33501). +const SELF_TEST_BATTERY_FLOOR = 37; // The key an assertion is filed under when no battery is open. It is not a // declared battery, so it reds by the same set difference rather than silently @@ -1260,14 +1306,14 @@ export const WORKFLOWS_PREFIX = '.github/workflows/'; export const GOVERNED_SURFACES = Object.freeze([ Object.freeze({ id: 'adr', prefix: 'docs/adr/', glob: 'docs/adr/**', tier: GOVERNED_TIER_H, what: 'architecture decision records' }), Object.freeze({ id: 'claude-tree', prefix: '.claude/', glob: '.claude/**', tier: GOVERNED_TIER_S, tierRepos: Object.freeze(['objectstack']), what: 'the agent instruction tree (skills, agents, hooks, settings)' }), - Object.freeze({ id: 'skills-catalog', prefix: 'skills/', glob: 'skills/**', tier: GOVERNED_TIER_H, what: 'the published skills catalog' }), + Object.freeze({ id: 'skills-catalog', prefix: 'skills/', glob: 'skills/**', tier: GOVERNED_TIER_H, lowRisk: Object.freeze({ repos: Object.freeze(['objectstack']) }), what: 'the published skills catalog' }), Object.freeze({ id: 'agents-md', exact: 'AGENTS.md', glob: 'AGENTS.md', tier: GOVERNED_TIER_H, what: 'the repo-root agent instruction file' }), Object.freeze({ id: 'claude-md', exact: 'CLAUDE.md', glob: 'CLAUDE.md', tier: GOVERNED_TIER_H, what: 'the repo-root Claude instruction file' }), Object.freeze({ id: 'north-star', exact: 'docs/NORTH-STAR.md', glob: 'docs/NORTH-STAR.md', tier: GOVERNED_TIER_H, what: "the maintainer's North Star — the law above AGENTS.md" }), Object.freeze({ id: 'workflows', prefix: '.github/workflows/', glob: '.github/workflows/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack', 'objectui', 'cloud']), split: Object.freeze({ repos: Object.freeze(['objectstack']), reader: 'readWorkflowDiff' }), what: 'CI, deploy and release workflows: what runs on every push, what deploys, what gates the queue' }), Object.freeze({ id: 'ui-adr', prefix: 'ui/docs/adr/', glob: 'ui/docs/adr/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's architecture decision records" }), Object.freeze({ id: 'ui-claude-tree', prefix: 'ui/.claude/', glob: 'ui/.claude/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's agent instruction tree" }), - Object.freeze({ id: 'ui-skills-catalog', prefix: 'ui/skills/', glob: 'ui/skills/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's published skills catalog" }), + Object.freeze({ id: 'ui-skills-catalog', prefix: 'ui/skills/', glob: 'ui/skills/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), lowRisk: Object.freeze({ repos: Object.freeze(['objectstack']) }), what: "the ui workspace's published skills catalog" }), Object.freeze({ id: 'ui-agents-md', exact: 'ui/AGENTS.md', glob: 'ui/AGENTS.md', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's agent instruction file" }), Object.freeze({ id: 'ui-claude-md', exact: 'ui/CLAUDE.md', glob: 'ui/CLAUDE.md', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's Claude instruction file" }), Object.freeze({ id: 'ui-workflows', prefix: 'ui/.github/workflows/', glob: 'ui/.github/workflows/**', tier: GOVERNED_TIER_H, repos: Object.freeze(['objectstack']), what: "the ui workspace's workflow files" }), @@ -1601,9 +1647,9 @@ export function landingTierOf(matched) { * list answers `H` (see `landingTierOf`). `repo` is required, as for * `governedPathsIn`: the rows consulted are the ones that govern it. */ -export function governedTierFor(paths, repo, register = GOVERNED_SURFACES, workflowDiff = null) { +export function governedTierFor(paths, repo, register = GOVERNED_SURFACES, workflowDiff = null, lowRisk = null) { const id = assertGovernedRepo(repo, 'governedTierFor'); - return landingTierOf(applyWorkflowSplit(governedPathsIn(paths, id, register), id, workflowDiff)); + return landingTierOf(applyLowRiskArm(applyWorkflowSplit(governedPathsIn(paths, id, register), id, workflowDiff), id, lowRisk)); } // ── the `workflows` row's content-aware tier (ruling record 6722205630, letter C) ── @@ -2172,6 +2218,109 @@ export function renderWorkflowSplitLines(matched) { .join(''); } +// ── the low-risk skills arm (maintainer ruling 2026-11-14, card #33501) ───── + +/** + * Where the arm is ruled (header section "The low-risk skills arm"), printed on + * every reading so a queue log names what moved a skills PR to Tier S. + */ +export const LOW_RISK_ARM_RULING = 'maintainer ruling 2026-11-14 on #33501, 「同意 把低风险的 Tier H 放权给座位」'; + +/** + * The ungoverned paths a low-risk PR may carry BESIDE its low-risk rows: + * prose the register does not govern and the changeset the published catalog + * owes. ⭐ An ALLOWLIST, never a denylist of published trees: a path outside + * it — `packages/**`, `ui/packages/**`, a gate script, a ratchet ceiling, a + * lockfile — keeps the PR Tier H however harmless it reads, because the + * ruling's arm is wording and a denylist fails open on the next published tree. + * `docs/` holds `docs/adr/**` and `docs/NORTH-STAR.md`; those are register + * rows outside the arm, so they keep the PR Tier H by the governed-rows rule. + */ +export const LOW_RISK_RIDER_PREFIXES = Object.freeze(['.changeset/', 'docs/', 'content/docs/']); + +/** Does this matched row carry the arm in `repo`? */ +function lowRiskArmIn(surface, repo) { + return Boolean(surface?.lowRisk) && Array.isArray(surface.lowRisk.repos) && surface.lowRisk.repos.includes(repo); +} + +/** + * The arm's verdict over one matched slice, from a READING of the pull request: + * `{ measured: true, paths, body, labels }` — every changed path (ungoverned + * ones included), the PR body (where its `Clause-②:` line is written) and its + * label names. Pure. + * + * Tier S only when ALL of these hold, each a reason when it does not: + * - every governed row hit is a low-risk row (a `.claude/**`, workflow or + * any Tier H row beside it is H — the card's "no other governed path"); + * - every changed path lies under a hit low-risk row or `LOW_RISK_RIDER_PREFIXES`; + * - the reading's path list holds every governed file of the slice; + * - the body declares `Clause-②: no` with NO arm (`readClause2Line`, the + * fleet's one reader; `no (narrowing)`, `yes`, malformed or absent is H); + * - the labels were read and none is `security`. + * ⛔ Fail closed: no reading, or one not measured, is Tier H with its reason. + */ +export function lowRiskArmVerdict(matched, repo, reading = null) { + const rows = (Array.isArray(matched) ? matched : []).filter(Boolean); + if (!reading || reading.measured !== true) { + return { + tier: GOVERNED_TIER_H, + measured: false, + reason: reading?.reason ?? 'no reading of the pull request was handed in — a path list alone cannot say what its body declares or which labels it carries', + reasons: [], + }; + } + const reasons = []; + const armRows = rows.filter((s) => lowRiskArmIn(s, repo)); + const outside = rows.filter((s) => !lowRiskArmIn(s, repo)); + if (armRows.length === 0) reasons.push('no low-risk row was hit'); + if (outside.length > 0) reasons.push(`a governed path outside the arm: ${outside.map((s) => `\`${s.glob}\``).join(', ')}`); + const paths = (Array.isArray(reading.paths) ? reading.paths : []).filter((p) => typeof p === 'string' && p !== ''); + if (paths.length === 0) reasons.push('the reading carries no path list'); + const allowed = [...armRows.map((s) => s.prefix).filter(Boolean), ...LOW_RISK_RIDER_PREFIXES]; + const stray = paths.filter((p) => !allowed.some((prefix) => p.startsWith(prefix))); + if (stray.length > 0) reasons.push(`a path outside skills wording and prose: ${stray.slice(0, 4).join(', ')}${stray.length > 4 ? ` (+${stray.length - 4} more)` : ''}`); + const listed = new Set(paths); + const unlisted = rows.flatMap((s) => s.files ?? []).filter((f) => !listed.has(f)); + if (paths.length > 0 && unlisted.length > 0) reasons.push(`the reading's path list does not hold ${unlisted.slice(0, 2).join(', ')}`); + const clause2 = readClause2Line(reading.body); + if (clause2 === null) reasons.push('the PR body carries no `Clause-②:` line'); + else if (clause2.kind !== 'declared') reasons.push(`the PR body's \`Clause-②:\` line does not read (${clause2.line})`); + else if (clause2.value !== 'no' || clause2.arm !== null) reasons.push(`the PR body declares \`Clause-②: ${clause2.value}${clause2.arm ? ` (${clause2.arm})` : ''}\`, which stays with the maintainer`); + if (!Array.isArray(reading.labels)) reasons.push('the labels were not read'); + else if (reading.labels.some((l) => String(l ?? '').toLowerCase() === 'security')) reasons.push('the PR carries the `security` label'); + return { tier: reasons.length === 0 ? GOVERNED_TIER_S : GOVERNED_TIER_H, measured: true, reason: null, reasons }; +} + +/** + * The matched slice with every low-risk row's tier read off the pull request, + * in `repo`. A slice with no low-risk row in `repo` is returned AS IS — every + * reading without a skills hit is byte-identical to before. Run AFTER the + * workflow split, so a split workflow row beside a skills path is a governed + * row outside the arm. Pure. + */ +export function applyLowRiskArm(matched, repo, reading = null) { + const list = Array.isArray(matched) ? matched : []; + if (!list.some((s) => lowRiskArmIn(s, repo))) return list; + const lowRiskVerdict = lowRiskArmVerdict(list, repo, reading); + return list.map((s) => (lowRiskArmIn(s, repo) ? Object.freeze({ ...s, tier: lowRiskVerdict.tier, lowRiskVerdict }) : s)); +} + +/** The arm's words under a verdict, once, or '' when no low-risk row was hit. Pure. */ +export function renderLowRiskLines(matched) { + const v = (Array.isArray(matched) ? matched : []).find((s) => s?.lowRiskVerdict)?.lowRiskVerdict; + if (!v) return ''; + if (!v.measured) { + return ( + ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): NOT MEASURED — ${v.reason}.\n` + + ' Tier H, fail closed. `--pr ` reads the body and the labels; the queue guard reads them on the queue leg.\n' + ); + } + if (v.tier === GOVERNED_TIER_S) { + return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, \`Clause-②: no\`, no \`security\` label.\n`; + } + return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier H —\n${v.reasons.map((r) => ` - ${r}\n`).join('')}`; +} + /** `owner/name` out of any git remote spelling, or null. Pure. */ export function slugFromRemote(url) { const m = /(?:github\.com[:/])([\w.-]+\/[\w.-]+?)(?:\.git)?\/*\s*$/.exec(String(url ?? '')); @@ -2315,11 +2464,12 @@ export function classifyCommit({ sha, date, subject }, changedPaths, repo, size * it names which one, and the verdict carries it (`repo`, and * `surfacesChecked` counts the rows that govern it, not the whole table). */ -export function testVerdict(paths, { repo, size = null, fork = null, checks = null, approval = null, workflowDiff = null } = {}) { +export function testVerdict(paths, { repo, size = null, fork = null, checks = null, approval = null, workflowDiff = null, lowRisk = null } = {}) { assertGovernedRepo(repo, 'testVerdict'); const list = (Array.isArray(paths) ? paths : []).filter((p) => typeof p === 'string' && p !== ''); // The `workflows` row's tier is read off the diff where a reading was handed in (the split): H otherwise. - const matched = applyWorkflowSplit(governedPathsIn(list, repo), repo, workflowDiff); + // The low-risk skills rows' tier is read off the pull request's body, labels and whole path list: H otherwise. + const matched = applyLowRiskArm(applyWorkflowSplit(governedPathsIn(list, repo), repo, workflowDiff), repo, lowRisk); const hit = new Set(matched.flatMap((s) => s.files)); const sized = sizeVerdict(size, approval); const forked = fork && typeof fork === 'object' ? fork : forkVerdict(null); // the FORK limb, or NOT MEASURED @@ -2522,6 +2672,7 @@ export function renderTestVerdict(verdict) { ` one Tier H path among the hits and the whole PR would be Tier H.\n` + `${lines.join('\n')}${clear}\n` + renderWorkflowSplitLines(verdict.matched) + + renderLowRiskLines(verdict.matched) + `${intake}${renderSizeLines(size)}` + renderExceptionLines(verdict) ); @@ -2534,6 +2685,7 @@ export function renderTestVerdict(verdict) { ` ⚖️ landing tier: H(人合) — ${GOVERNED_TIERS[GOVERNED_TIER_H].landing}.\n` + `${lines.join('\n')}${clear}\n` + renderWorkflowSplitLines(verdict.matched) + + renderLowRiskLines(verdict.matched) + `${intake}${renderSizeLines(size)}` + renderExceptionLines(verdict) ); @@ -3903,6 +4055,8 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = size, fork, checks, + // The low-risk skills arm's reading (#33501), off the SAME pull object and file walk — no read of its own. + lowRisk: pullLowRiskReading(head, paths), derivation: { kind: 'pull', slug, @@ -3920,6 +4074,17 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = }; } +/** + * The low-risk skills arm's reading off a PR object and its WHOLE changed-path + * list (`lowRiskArmVerdict`). Pure. Labels the object does not carry as a list + * read `null`, which the arm reads as H; a body that is not a string reads as + * an empty body, which declares nothing and is H too. + */ +export function pullLowRiskReading(head, paths) { + const labels = Array.isArray(head?.labels) ? head.labels.map((l) => (typeof l === 'string' ? l : String(l?.name ?? ''))) : null; + return { measured: true, reason: null, paths: Array.isArray(paths) ? [...paths] : [], body: typeof head?.body === 'string' ? head.body : '', labels }; +} + /** * The `additions` / `deletions` pair off a PR object, or null when the object * does not carry both as non-negative integers. Pure; null is the caller's @@ -4262,8 +4427,8 @@ function rootFromArgs(args) { * leave two readings of the same register in circulation, which is the shape * the card is about. `--self-test` pins the identity end to end. */ -async function emitVerdict(paths, args, derivation = null, size = null, intake = null, repo = undefined, workflowDiff = null) { - let verdict = testVerdict(paths, { repo, size, ...(intake ?? {}), workflowDiff }); +async function emitVerdict(paths, args, derivation = null, size = null, intake = null, repo = undefined, workflowDiff = null, lowRisk = null) { + let verdict = testVerdict(paths, { repo, size, ...(intake ?? {}), workflowDiff, lowRisk }); // The provenance-aware exceptions (#9866 + #11705): recompute only when a // registered path is actually among the hits, so every other run stays the // zero-git, zero-cost read it always was. The driver applies each row's @@ -4519,7 +4684,7 @@ async function runPullMode(args) { const workflowDiff = derived.paths.some((p) => p.startsWith(WORKFLOWS_PREFIX)) ? pullWorkflowDiff({ derivation: derived.derivation, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv), git: (argv) => git(root, argv) }) : null; - return await emitVerdict(derived.paths, args, derived.derivation, derived.size, { fork: derived.fork, checks: derived.checks }, repo, workflowDiff); + return await emitVerdict(derived.paths, args, derived.derivation, derived.size, { fork: derived.fork, checks: derived.checks }, repo, workflowDiff, derived.lowRisk ?? null); } /** @@ -5387,6 +5552,70 @@ async function selfTest() { assert('--pr-reads-the-split-only-from-a-checkout-holding-both-commits-else-UNMEASURED', pr().measured === false && /not in this checkout/.test(pr().reason) && pr({ sameCheckout: false }).measured === false && pr({ derivation: { pull: 7 } }).measured === false, JSON.stringify([pr().reason, pr({ sameCheckout: false }).reason])); } + battery('⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)'); + { + const REPO = 'objectstack'; + const SK = 'skills/objectstack-data/SKILL.md'; + const UISK = 'ui/skills/objectui-views/SKILL.md'; + const CS = '.changeset/33501-skills-wording.md'; + const read = (paths, over = {}) => ({ measured: true, reason: null, paths, body: 'Fixes #1\n\nClause-②: no\nMetadata-protocol: none\n', labels: [], ...over }); + const tier = (paths, reading, repo = REPO) => governedTierFor(paths, repo, GOVERNED_SURFACES, null, reading); + const reasons = (paths, reading) => lowRiskArmVerdict(governedPathsIn(paths, REPO), REPO, reading).reasons.join(' | '); + + // The register: the two catalog rows carry the arm, scoped to objectstack; the row tier stays H for every path-only reader. + const armRows = GOVERNED_SURFACES.filter((s) => s.lowRisk); + assert('the-arm-rides-exactly-the-two-catalog-rows-scoped-to-objectstack-and-both-keep-row-tier-H', + armRows.map((s) => s.id).join() === 'skills-catalog,ui-skills-catalog' && armRows.every((s) => s.tier === GOVERNED_TIER_H && Object.isFrozen(s.lowRisk) && s.lowRisk.repos.join() === REPO), JSON.stringify(armRows.map((s) => [s.id, s.tier, s.lowRisk]))); + assert('the-rider-allowlist-is-changesets-and-ungoverned-prose-only', LOW_RISK_RIDER_PREFIXES.join() === '.changeset/,docs/,content/docs/' && Object.isFrozen(LOW_RISK_RIDER_PREFIXES)); + + // ⛔ Fail closed: no reading, or an unmeasured one, is H — the path-only readers (`--test`, `--branch`, CODEOWNERS, the prose gate) answer as before. + assert('⛔ no-reading-is-Tier-H-and-says-NOT-MEASURED', tier([SK], null) === GOVERNED_TIER_H && governedTierFor([SK], REPO) === GOVERNED_TIER_H && testVerdict([SK], { repo: REPO }).tier === GOVERNED_TIER_H && /low-risk skills arm .*NOT MEASURED/.test(renderTestVerdict(testVerdict([SK], { repo: REPO })))); + assert('⛔ an-unmeasured-reading-is-Tier-H-with-its-own-reason', tier([SK], { measured: false, reason: 'the pull could not be read' }) === GOVERNED_TIER_H && /the pull could not be read/.test(renderTestVerdict(testVerdict([SK], { repo: REPO, lowRisk: { measured: false, reason: 'the pull could not be read' } })))); + + // ⭐ The arm: pure skills wording, with its changeset and prose riders, on `Clause-②: no` and no security label. + assert('⭐ a-pure-skills-diff-on-Clause-2-no-is-Tier-S', tier([SK], read([SK])) === GOVERNED_TIER_S && testVerdict([SK], { repo: REPO, lowRisk: read([SK]) }).tier === GOVERNED_TIER_S); + assert('⭐ with-its-changeset-and-docs-prose-riders-it-stays-Tier-S', tier([SK, CS, 'content/docs/guides/x.mdx', 'docs/agents/x.md'], read([SK, CS, 'content/docs/guides/x.mdx', 'docs/agents/x.md'])) === GOVERNED_TIER_S); + assert('a-ui-skills-diff-and-both-catalogs-together-are-Tier-S', tier([UISK], read([UISK])) === GOVERNED_TIER_S && tier([SK, UISK, CS], read([SK, UISK, CS])) === GOVERNED_TIER_S); + assert('the-words-name-the-arm-and-the-Tier-S-landing', (() => { const t = renderTestVerdict(testVerdict([SK], { repo: REPO, lowRisk: read([SK]) })); return /Tier S\(席内达档复核落地\)/.test(t) && /low-risk skills arm .*Tier S/.test(t) && t.includes(LOW_RISK_ARM_RULING); })()); + + // ⛔ Published source or any path outside the allowlist: H. + assert('⛔ skills-plus-packages-spec-stays-H', tier([SK, 'packages/spec/src/data/field.zod.ts'], read([SK, 'packages/spec/src/data/field.zod.ts'])) === GOVERNED_TIER_H && /outside skills wording and prose: packages\/spec/.test(reasons([SK, 'packages/spec/src/data/field.zod.ts'], read([SK, 'packages/spec/src/data/field.zod.ts'])))); + assert('⛔ skills-plus-ui-packages-stays-H', tier([UISK, 'ui/packages/react/src/x.tsx'], read([UISK, 'ui/packages/react/src/x.tsx'])) === GOVERNED_TIER_H); + assert('⛔ skills-plus-a-gate-script-or-a-lockfile-stays-H-the-list-is-an-allowlist', tier([SK, 'scripts/check-skills-token-ratchet.mjs'], read([SK, 'scripts/check-skills-token-ratchet.mjs'])) === GOVERNED_TIER_H && tier([SK, 'pnpm-lock.yaml'], read([SK, 'pnpm-lock.yaml'])) === GOVERNED_TIER_H); + assert('⛔ a-reading-whose-path-list-misses-a-governed-file-or-is-empty-is-H', tier([SK, UISK], read([SK])) === GOVERNED_TIER_H && tier([SK], read([])) === GOVERNED_TIER_H); + + // ⛔ Any other governed row beside it: H, Tier S rows included (the card's "no other governed path"). + assert('⛔ skills-beside-AGENTS-md-an-ADR-or-NORTH-STAR-is-H', [['AGENTS.md'], ['docs/adr/0001-x.md'], ['docs/NORTH-STAR.md']].every(([p]) => tier([SK, p], read([SK, p])) === GOVERNED_TIER_H)); + assert('⛔ skills-beside-a-Tier-S-claude-path-is-H-too', tier([SK, '.claude/agents/os-dev.md'], read([SK, '.claude/agents/os-dev.md'])) === GOVERNED_TIER_H && /outside the arm: `\.claude\/\*\*`/.test(reasons([SK, '.claude/agents/os-dev.md'], read([SK, '.claude/agents/os-dev.md'])))); + + // ⛔ The declaration: only a bare `Clause-②: no` lands on the seat. + const body = (line) => read([SK], { body: `Fixes #1\n\n${line}\n` }); + assert('⛔ Clause-2-yes-or-no-narrowing-or-yes-widening-is-H', ['Clause-②: yes', 'Clause-②: no (narrowing)', 'Clause-②: yes (widening)', 'Clause-②: yes (narrowing)'].every((l) => tier([SK], body(l)) === GOVERNED_TIER_H)); + assert('⛔ a-malformed-absent-or-near-miss-Clause-2-line-is-H', ['Clause-②: maybe', 'no declaration here', 'Clause 2: no', '`Clause-②:` no', ''].every((l) => tier([SK], body(l)) === GOVERNED_TIER_H) && tier([SK], read([SK], { body: null })) === GOVERNED_TIER_H); + assert('a-decorated-Clause-2-no-line-reads-as-the-one-reader-reads-it', tier([SK], body('- `Clause-②`: no')) === GOVERNED_TIER_S && tier([SK], body('- **Clause-②:** no')) === GOVERNED_TIER_S); + + // ⛔ Security: the label keeps it with the maintainer; labels not read is H. + assert('⛔ a-security-label-in-any-case-is-H', tier([SK], read([SK], { labels: ['security'] })) === GOVERNED_TIER_H && tier([SK], read([SK], { labels: ['docs', 'Security'] })) === GOVERNED_TIER_H); + assert('⛔ labels-not-read-is-H', tier([SK], read([SK], { labels: null })) === GOVERNED_TIER_H && tier([SK], read([SK], { labels: undefined })) === GOVERNED_TIER_H); + + // The scope: the arm moves nothing outside objectstack, and nothing without a catalog hit. + assert('the-same-S-reading-moves-nothing-in-objectui-cloud-or-hotcrm', ['objectui', 'cloud', 'hotcrm'].every((r) => tier([SK], read([SK]), r) === GOVERNED_TIER_H)); + assert('a-slice-with-no-catalog-row-is-returned-as-is-byte-identical', (() => { const m = governedPathsIn(['AGENTS.md', '.claude/x.md'], REPO); return applyLowRiskArm(m, REPO, read(['AGENTS.md', '.claude/x.md'])) === m && renderLowRiskLines(m) === ''; })() && tier(['.claude/agents/os-dev.md'], read(['.claude/agents/os-dev.md'])) === GOVERNED_TIER_S); + + // The H words name every reason; `--pr` reads the arm off the SAME pull object and file walk. + assert('the-H-words-list-each-reason', (() => { const t = renderTestVerdict(testVerdict([SK, 'packages/core/src/x.ts'], { repo: REPO, lowRisk: read([SK, 'packages/core/src/x.ts'], { labels: ['security'] }) })); return /low-risk skills arm .*Tier H/.test(t) && /packages\/core/.test(t) && /`security` label/.test(t) && /landing tier: H/.test(t); })()); + const fromPull = pullLowRiskReading({ body: 'Clause-②: no', labels: [{ name: 'skip-changeset' }, { name: 'security' }] }, [SK]); + assert('pullLowRiskReading-takes-body-label-names-and-the-whole-path-list', fromPull.measured === true && fromPull.body === 'Clause-②: no' && fromPull.labels.join() === 'skip-changeset,security' && fromPull.paths.join() === SK && pullLowRiskReading({}, [SK]).labels === null && pullLowRiskReading({ body: 7, labels: [] }, [SK]).body === '', JSON.stringify(fromPull)); + { + const respond = (b) => ({ ok: true, status: 200, headers: { get: () => null }, json: async () => b }); + const walked = await fetchPullFiles({ + apiUrl: 'https://api', slug: 'o/r', pull: 2, channels: [{ id: 'fixture', name: 'fixture channel', headers: {} }], + fetchImpl: async (url) => (/\/files/.test(url) ? respond([{ filename: SK }, { filename: CS }]) : respond({ changed_files: 2, additions: 3, deletions: 1, body: 'Clause-②: no', labels: [{ name: 'docs' }] })), + }); + assert('⭐ --pr-carries-the-arm-reading-off-the-same-GET-and-file-walk-and-it-answers-Tier-S', walked.ok === true && walked.lowRisk?.measured === true && walked.lowRisk.paths.join() === `${SK},${CS}` && tier(walked.paths, walked.lowRisk) === GOVERNED_TIER_S, JSON.stringify(walked.lowRisk ?? walked.reason)); + } + } + battery('the nested `ui/` workspace rows, on the register (#25712)'); const UI_ROWS = GOVERNED_SURFACES.filter((s) => s.id.startsWith('ui-')); const ROOT_ROWS = Object.freeze(GOVERNED_SURFACES.filter((s) => !s.id.startsWith('ui-'))); @@ -6717,6 +6946,7 @@ async function selfTest() { const moduleGraph = [ 'scripts/pm/check-governed-merges.mjs', 'scripts/pm/git-history.mjs', + 'scripts/pm/clause2-line.mjs', 'scripts/import-prerequisite.mjs', 'scripts/cli-build-prerequisite.mjs', 'scripts/invoked-as.mjs', diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index 4fb4781739e..b67018bcb58 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -341,6 +341,15 @@ * `merge_group`, the merge base on `pull_request` — to the register's * `applyWorkflowSplit`, and a commit it could not read stays Tier H. * + * ⚖️ The two skills catalog rows are read off the PULL REQUEST (maintainer + * ruling 2026-11-14 on #33501, the register's "The low-risk skills arm"): + * `decomposeGovernedWork` keeps every path of every attributed commit + * (`allPaths`, ungoverned commits of the same PR included) and reads the arm + * NOT MEASURED, so the `pull_request` leg says Tier H; the `merge_group` leg's + * `readLowRiskTier` re-reads the tier with the body and label names of the pull + * object it already fetched for the head — no read of its own — through the + * register's `governedTierFor`. An unread pull stays Tier H. + * * ⭐ THE TWO CARRIERS ARE ONE DELIVERY, and the location is the governed text's * to decide rather than this file's — quoted, untranslated, because it IS the * criterion: 「复核记录 = 一条评论落 PR 或卡」 @@ -577,9 +586,11 @@ import { GOVERNED_TIER_H, GOVERNED_TIER_S, HUMAN_MERGE_LINE_THRESHOLD, + LOW_RISK_ARM_RULING, SELF_REPO_ID, WORKFLOWS_PREFIX, applyGeneratedExceptions, + applyLowRiskArm, applyWorkflowSplit, assertGovernedRepo, generatedExceptionFor, @@ -594,6 +605,7 @@ import { recomputeProvenanceFor, readWorkflowDiff, renderLiftApprovals, + renderLowRiskLines, renderWorkflowSplitLines, repoIdForSlug, testVerdict, @@ -647,6 +659,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 16, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -659,7 +672,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ // Raised 27 → 28 with the ENQUEUE leg battery (maintainer ruling 2026-10-26): one battery, one row. // Raised 28 → 29 with the cheap early-warning leg battery: one battery, one row. // Raised 29 → 30 with the workflows split battery (ruling record 6722205630): one battery, one row. -const SELF_TEST_BATTERY_FLOOR = 30; +// Raised 30 → 31 with the low-risk skills arm battery (#33501): one battery, one row. +const SELF_TEST_BATTERY_FLOOR = 31; // The key an assertion is filed under when no battery is open. It is not a // declared battery, so it reds by the same set difference rather than silently @@ -1145,6 +1159,17 @@ export function decomposeGovernedWork(rows, repo) { assertGovernedRepo(repo, 'decomposeGovernedWork'); const byPull = new Map(); const unattributed = []; + // ⭐ EVERY path of every attributed row, governed or not, per PR — the low-risk + // skills arm's allowlist reads the whole diff (#33501). Collected BEFORE the + // governed filter below drops a row, so an ungoverned commit of the same PR + // (a `packages/**` edit in a commit of its own) still counts against the arm. + const allByPull = new Map(); + for (const row of Array.isArray(rows) ? rows : []) { + if (typeof row?.pr !== 'number' || !Number.isInteger(row.pr) || row.pr <= 0) continue; + const all = allByPull.get(row.pr) ?? new Set(); + for (const p of Array.isArray(row.paths) ? row.paths : []) if (typeof p === 'string' && p !== '') all.add(p); + allByPull.set(row.pr, all); + } for (const row of Array.isArray(rows) ? rows : []) { const surfaces = governedPathsIn(row?.paths ?? [], repo); if (surfaces.length === 0) continue; @@ -1171,12 +1196,17 @@ export function decomposeGovernedWork(rows, repo) { // SAME governed path list the verdict is judged on — never from the raw // diff, which carries files the register does not govern at all — and, // for the `workflows` row, from the reading of its diff (the split). + // The low-risk skills arm (#33501) needs the PR body and labels, which no + // row carries: here it is NOT MEASURED, so a catalog path is Tier H; the + // queue leg re-reads the tier with `readLowRiskTier` once the pull is read. return { pr: entry.pr, shas: entry.shas, paths, - surfaces: applyWorkflowSplit(governedPathsIn(paths, repo), repo, workflowDiff), - tier: governedTierFor(paths, repo, GOVERNED_SURFACES, workflowDiff), + allPaths: [...(allByPull.get(entry.pr) ?? entry.paths)], + workflowDiff, + surfaces: applyLowRiskArm(applyWorkflowSplit(governedPathsIn(paths, repo), repo, workflowDiff), repo, null), + tier: governedTierFor(paths, repo, GOVERNED_SURFACES, workflowDiff, null), }; }) .sort((a, b) => a.pr - b.pr); @@ -1545,6 +1575,7 @@ export function renderGuardVerdict(verdict) { lines.push('', ` #${entry.pr} — governed:`); lines.push(...surfaceLines(entry)); lines.push(...renderWorkflowSplitLines(entry.surfaces).split('\n').filter((l) => l !== '').map((l) => ` ${l}`)); + lines.push(...renderLowRiskLines(entry.surfaces).split('\n').filter((l) => l !== '').map((l) => ` ${l}`)); // The pre-#19133 `pull_request` byte-identity constraint (2026-08-27) is // superseded by that ruling's own requirement: the early warning names the // tier and what it waits for. @@ -1854,6 +1885,25 @@ export function renderGuardVerdict(verdict) { return lines.join('\n'); } +/** + * Re-read one governed entry's tier with the low-risk skills arm's reading + * (#33501): `paths` = every path of the PR's commits (`allPaths`), the body and + * labels off the pull object the queue leg read. An entry with no catalog row + * is left untouched; `pull` null (its read failed) is an UNMEASURED reading, so + * the entry stays Tier H with the reason printed. ⛔ The tier comes from the + * register's own `governedTierFor` and `applyLowRiskArm` — no second predicate + * here. Mutates `entry` (its `surfaces` and `tier`); returns it. + */ +export function readLowRiskTier(entry, repo, pull) { + if (!entry || !(entry.surfaces ?? []).some((s) => s?.lowRiskVerdict)) return entry; + const reading = pull + ? { measured: true, reason: null, paths: entry.allPaths ?? entry.paths, body: String(pull.body ?? ''), labels: Array.isArray(pull.labels) ? pull.labels : null } + : { measured: false, reason: 'its pull request could not be read, so its body and labels are unknown' }; + entry.surfaces = applyLowRiskArm(applyWorkflowSplit(governedPathsIn(entry.paths, repo), repo, entry.workflowDiff ?? null), repo, reading); + entry.tier = governedTierFor(entry.paths, repo, GOVERNED_SURFACES, entry.workflowDiff ?? null, reading); + return entry; +} + /** * The orchestrator, with its one IO dependency injected. * @@ -1898,7 +1948,7 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet // head read was not already making. const pull = await fetchPull(entry.pr); headSha = pull?.sha ?? null; - pulls.set(entry.pr, { number: entry.pr, body: pull?.body ?? '', head: { ref: pull?.headRef ?? '' } }); + pulls.set(entry.pr, { number: entry.pr, body: pull?.body ?? '', labels: Array.isArray(pull?.labels) ? pull.labels : null, head: { ref: pull?.headRef ?? '' } }); } catch (error) { headNotes.push( ` ℹ️ #${entry.pr}: the PR head could not be read (${String(error?.message ?? error).split('\n')[0]}) — ` + @@ -1946,6 +1996,10 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet // take a pass away), and it is FREE on every merge group that does not need // it — no thread is read, and the recognisers are not even loaded. if (event === EVENT_MERGE_GROUP) { + // ⭐ The low-risk skills arm (#33501) FIRST: a catalog entry's tier is read + // off the pull object this leg already holds — body, labels — and the whole + // path list of its commits. An unread pull is NOT MEASURED: Tier H. + for (const entry of governed) readLowRiskTier(entry, repo, pulls.get(entry.pr) ?? null); let recognisers = null; for (const entry of governed) { if (entry.tier !== TIER_S) continue; @@ -2721,6 +2775,8 @@ export function makePullReader({ apiUrl, slug, token, fetchImpl = fetch }) { return { sha, body: String(row?.body ?? ''), + // The label NAMES (#33501): the low-risk skills arm reads `security` off them. Not a list ⇒ null ⇒ Tier H. + labels: Array.isArray(row?.labels) ? row.labels.map((l) => String(l?.name ?? '')) : null, headRef: String(row?.head?.ref ?? ''), size: pair === null ? null : { ...pair, source: `GET /repos/${slug}/pulls/${pull}` }, }; @@ -3067,7 +3123,7 @@ export async function selfTest() { // SIZE leg judges (#19036) — `null` unless a fixture hands one in, exactly // as the reader answers a pull object without the pair. Spelled once, so a // fixture can never disagree with `makePullReader` about what a pull row is. - const pull = (sha = HEAD, { body = '', headRef = '', size = null } = {}) => ({ sha, body, headRef, size }); + const pull = (sha = HEAD, { body = '', headRef = '', size = null, labels = [] } = {}) => ({ sha, body, headRef, size, labels }); const authorizedPass = (login = GOVERNED_APPROVERS[0]) => authorizedApprovalVerdict([approvedAt(login, HEAD)], HEAD); // The same authorized approval, on a commit that is no longer the head. Under // the retired sha pin this exact fixture was the REFUSAL case. @@ -4771,15 +4827,17 @@ export async function selfTest() { runGit = null, baseRef = null, workflowDiff = null, + labels = [], + extraRows = [], } = {}) => { tierApiCalls = 0; tierThreadsRead = []; return runGuard({ repo: REPO, event, - rows: [{ ...row(pr, files, 'c'.repeat(40), `x (#${pr})`), ...(workflowDiff ? { workflowDiff } : {}) }], + rows: [{ ...row(pr, files, 'c'.repeat(40), `x (#${pr})`), ...(workflowDiff ? { workflowDiff } : {}) }, ...extraRows], fetchReviews: async () => { tierApiCalls += 1; return reviews; }, - fetchPull: async () => { tierApiCalls += 1; if (headThrows) throw new Error('head unreadable'); return pull(head, { body: prBody, headRef: branch }); }, + fetchPull: async () => { tierApiCalls += 1; if (headThrows) throw new Error('head unreadable'); return pull(head, { body: prBody, headRef: branch, labels }); }, fetchComments: async (n) => { tierApiCalls += 1; tierThreadsRead.push(n); @@ -5549,6 +5607,45 @@ export async function selfTest() { assert('no-rows-attach-nothing', attachWorkflowReadings(undefined, { event: EVENT_MERGE_GROUP, mergeBase: M, runGit: fakeGit([]) }).length === 0); } + battery('⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)'); + { + const SK = 'skills/objectstack-data/SKILL.md'; + const CS = '.changeset/33501-skills-wording.md'; + const LOW = `Fixes #${REF_CARD}\n\nClause-②: no\nMetadata-protocol: none\n`; + // The decomposition: a catalog entry is NOT MEASURED there (no row carries a body), and it keeps EVERY path of the PR. + const split = decomposeGovernedWork([row(33501, [SK, CS, 'packages/spec/src/a.zod.ts'])], REPO).governed[0]; + assert('the-decomposition-reads-a-catalog-entry-Tier-H-NOT-MEASURED-and-keeps-every-path', split.tier === TIER_H && split.surfaces[0].lowRiskVerdict?.measured === false && split.allPaths.join() === `${SK},${CS},packages/spec/src/a.zod.ts` && split.paths.join() === SK, JSON.stringify(split)); + const twoCommits = decomposeGovernedWork([row(9, [SK], '1'.repeat(40)), row(9, ['packages/core/src/x.ts'], '2'.repeat(40))], REPO).governed[0]; + assert('⛔ an-ungoverned-commit-of-the-same-PR-still-counts-its-published-path-is-in-allPaths', twoCommits.allPaths.includes('packages/core/src/x.ts') && readLowRiskTier(twoCommits, REPO, { body: LOW, labels: [] }).tier === TIER_H, JSON.stringify(twoCommits.allPaths)); + const untouched = decomposeGovernedWork([row(9, ['AGENTS.md'])], REPO).governed[0]; + assert('readLowRiskTier-leaves-an-entry-with-no-catalog-row-as-it-was', readLowRiskTier(untouched, REPO, null) === untouched && untouched.tier === TIER_H && !untouched.surfaces.some((s) => s.lowRiskVerdict)); + + // ⭐ End to end on the queue leg: pure skills wording + changeset, `Clause-②: no`, a same-head record ⇒ the seat's enqueue clears. + const pass = await tierRun({ files: [SK, CS], prBody: LOW, comments: [recordComment()] }); + assert('⭐ a-pure-skills-PR-on-Clause-2-no-with-a-same-head-record-CLEARS-with-zero-approvals', pass.exitCode === EXIT_CLEAR && pass.conclusion === 'cleared' && pass.entries[0].tier === TIER_S && pass.entries[0].record.state === 'stands', JSON.stringify(pass.entries[0])); + assert('and-the-words-name-the-arm-and-its-ruling', /low-risk skills arm .*Tier S/.test(renderGuardVerdict(pass)) && renderGuardVerdict(pass).includes(LOW_RISK_ARM_RULING), renderGuardVerdict(pass)); + const noRecord = await tierRun({ files: [SK], prBody: LOW, comments: [] }); + assert('⛔ CONTROL: the-same-skills-PR-with-NO-record-is-REFUSED-Tier-S-without-its-record', noRecord.exitCode === EXIT_REFUSED_UNAPPROVED && noRecord.entries[0].tier === TIER_S && noRecord.entries[0].record.state === 'absent'); + const old = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment({ sha: REF_OLD.slice(0, 12) })] }); + assert('⛔ a-record-on-an-OLDER-head-is-REFUSED', old.exitCode === EXIT_REFUSED_UNAPPROVED && old.entries[0].record.state === 'absent'); + + // ⛔ Each H case, each WITH a valid record: the record leg is never consulted, the entry needs the maintainer. + const hCase = async (over) => { const v = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment()], ...over }); return [v.exitCode, v.entries[0].tier, v.entries[0].record === undefined]; }; + const H = [EXIT_REFUSED_UNAPPROVED, TIER_H, true]; + assert('⛔ skills-plus-packages-spec-stays-H', JSON.stringify(await hCase({ files: [SK, 'packages/spec/src/data/field.zod.ts'] })) === JSON.stringify(H)); + assert('⛔ skills-with-Clause-2-yes-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: yes\n` })) === JSON.stringify(H)); + assert('⛔ skills-with-Clause-2-no-narrowing-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: no (narrowing)\n` })) === JSON.stringify(H)); + assert('⛔ skills-with-NO-Clause-2-line-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}` })) === JSON.stringify(H)); + assert('⛔ skills-with-the-security-label-stays-H', JSON.stringify(await hCase({ labels: ['security'] })) === JSON.stringify(H)); + assert('⛔ skills-beside-AGENTS-md-stays-H', JSON.stringify(await hCase({ files: [SK, 'AGENTS.md'] })) === JSON.stringify(H)); + assert('⛔ a-pull-the-leg-could-not-read-is-NOT-MEASURED-and-H', await (async () => { const v = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment()], headThrows: true }); return v.exitCode === EXIT_REFUSED_UNAPPROVED && v.entries[0].tier === TIER_H && v.entries[0].surfaces[0].lowRiskVerdict?.measured === false; })()); + assert('⛔ a-published-path-in-ANOTHER-commit-of-the-same-PR-in-the-group-stays-H', JSON.stringify(await hCase({ extraRows: [row(70, ['ui/packages/react/src/x.tsx'], 'd'.repeat(40), 'y (#70)')] })) === JSON.stringify(H)); + + // The pull_request leg reads no body: the early warning says Tier H, NOT MEASURED, and that the queue leg reads it. + const early = await tierRun({ files: [SK], prBody: LOW, event: EVENT_PULL_REQUEST }); + assert('the-pull_request-leg-names-the-arm-NOT-MEASURED-and-never-reddens', early.entries[0].tier === TIER_H && /low-risk skills arm .*NOT MEASURED/.test(renderGuardVerdict(early)) && /queue guard reads them on the queue leg/.test(renderGuardVerdict(early)), renderGuardVerdict(early)); + } + // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── // // Evaluated after every battery has had its chance and BEFORE the verdict, so From a35085bf3f6c7e558060e0c63fabae25df6a66dd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 23:28:08 +0000 Subject: [PATCH 02/10] pm: spell the low-risk rider allowlist as path shapes, not a bare docs root Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- scripts/pm/check-governed-merges.mjs | 35 +++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 51221950696..9410283e0d9 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -484,9 +484,10 @@ * * - every governed path lies under a catalog row — `.claude/**`, a workflow, * `AGENTS.md`, an ADR or any other row beside it is H; - * - every changed path lies under a hit catalog row or `LOW_RISK_RIDER_PREFIXES` - * (`.changeset/`, `docs/`, `content/docs/`) — an ALLOWLIST, so `packages/**`, - * `ui/packages/**`, a gate script, a ratchet ceiling or a lockfile is H; + * - every changed path lies under a hit catalog row or matches + * `LOW_RISK_RIDER_PATTERNS` (a changeset, Markdown prose under the docs + * trees) — an ALLOWLIST, so `packages/**`, `ui/packages/**`, a gate script, + * a ratchet ceiling or a lockfile is H; * - the body declares `Clause-②: no` with no arm (`readClause2Line`, the one * reader) — `yes`, `(narrowing)`, malformed or absent is H; * - the labels were read and none is `security`. @@ -2227,16 +2228,17 @@ export function renderWorkflowSplitLines(matched) { export const LOW_RISK_ARM_RULING = 'maintainer ruling 2026-11-14 on #33501, 「同意 把低风险的 Tier H 放权给座位」'; /** - * The ungoverned paths a low-risk PR may carry BESIDE its low-risk rows: - * prose the register does not govern and the changeset the published catalog - * owes. ⭐ An ALLOWLIST, never a denylist of published trees: a path outside - * it — `packages/**`, `ui/packages/**`, a gate script, a ratchet ceiling, a - * lockfile — keeps the PR Tier H however harmless it reads, because the - * ruling's arm is wording and a denylist fails open on the next published tree. - * `docs/` holds `docs/adr/**` and `docs/NORTH-STAR.md`; those are register - * rows outside the arm, so they keep the PR Tier H by the governed-rows rule. + * The ungoverned paths a low-risk PR may carry BESIDE its low-risk rows: a + * changeset (the one the published catalog owes) and Markdown prose under the + * docs trees the register does not govern. ⭐ An ALLOWLIST of path SHAPES, never + * a denylist of published trees: anything else — `packages/**`, + * `ui/packages/**`, a gate script, a ratchet ceiling, a lockfile, a non-prose + * file under a docs tree — keeps the PR Tier H however harmless it reads, + * because the ruling's arm is wording and a denylist fails open on the next + * published tree. `docs/adr/**` and `docs/NORTH-STAR.md` match the prose shape + * but are register rows outside the arm, so the governed-rows rule keeps them H. */ -export const LOW_RISK_RIDER_PREFIXES = Object.freeze(['.changeset/', 'docs/', 'content/docs/']); +export const LOW_RISK_RIDER_PATTERNS = Object.freeze([/^\.changeset\/[^/]+\.md$/, /^(?:content\/)?docs\/.+\.mdx?$/]); /** Does this matched row carry the arm in `repo`? */ function lowRiskArmIn(surface, repo) { @@ -2252,7 +2254,7 @@ function lowRiskArmIn(surface, repo) { * Tier S only when ALL of these hold, each a reason when it does not: * - every governed row hit is a low-risk row (a `.claude/**`, workflow or * any Tier H row beside it is H — the card's "no other governed path"); - * - every changed path lies under a hit low-risk row or `LOW_RISK_RIDER_PREFIXES`; + * - every changed path lies under a hit low-risk row or matches `LOW_RISK_RIDER_PATTERNS`; * - the reading's path list holds every governed file of the slice; * - the body declares `Clause-②: no` with NO arm (`readClause2Line`, the * fleet's one reader; `no (narrowing)`, `yes`, malformed or absent is H); @@ -2276,8 +2278,8 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { if (outside.length > 0) reasons.push(`a governed path outside the arm: ${outside.map((s) => `\`${s.glob}\``).join(', ')}`); const paths = (Array.isArray(reading.paths) ? reading.paths : []).filter((p) => typeof p === 'string' && p !== ''); if (paths.length === 0) reasons.push('the reading carries no path list'); - const allowed = [...armRows.map((s) => s.prefix).filter(Boolean), ...LOW_RISK_RIDER_PREFIXES]; - const stray = paths.filter((p) => !allowed.some((prefix) => p.startsWith(prefix))); + const armPrefixes = armRows.map((s) => s.prefix).filter(Boolean); + const stray = paths.filter((p) => !armPrefixes.some((prefix) => p.startsWith(prefix)) && !LOW_RISK_RIDER_PATTERNS.some((re) => re.test(p))); if (stray.length > 0) reasons.push(`a path outside skills wording and prose: ${stray.slice(0, 4).join(', ')}${stray.length > 4 ? ` (+${stray.length - 4} more)` : ''}`); const listed = new Set(paths); const unlisted = rows.flatMap((s) => s.files ?? []).filter((f) => !listed.has(f)); @@ -5566,7 +5568,8 @@ async function selfTest() { const armRows = GOVERNED_SURFACES.filter((s) => s.lowRisk); assert('the-arm-rides-exactly-the-two-catalog-rows-scoped-to-objectstack-and-both-keep-row-tier-H', armRows.map((s) => s.id).join() === 'skills-catalog,ui-skills-catalog' && armRows.every((s) => s.tier === GOVERNED_TIER_H && Object.isFrozen(s.lowRisk) && s.lowRisk.repos.join() === REPO), JSON.stringify(armRows.map((s) => [s.id, s.tier, s.lowRisk]))); - assert('the-rider-allowlist-is-changesets-and-ungoverned-prose-only', LOW_RISK_RIDER_PREFIXES.join() === '.changeset/,docs/,content/docs/' && Object.isFrozen(LOW_RISK_RIDER_PREFIXES)); + const rider = (p) => LOW_RISK_RIDER_PATTERNS.some((re) => re.test(p)); + assert('the-rider-allowlist-is-changesets-and-Markdown-prose-under-the-docs-trees-only', Object.isFrozen(LOW_RISK_RIDER_PATTERNS) && [CS, 'docs/agents/x.md', 'content/docs/guides/x.mdx'].every(rider) && !['.changeset/config.json', 'docs/x.ts', 'content/docs/x.json', 'content/x.md', 'packages/docs/x.md', '.changeset/a/b.md'].some(rider)); // ⛔ Fail closed: no reading, or an unmeasured one, is H — the path-only readers (`--test`, `--branch`, CODEOWNERS, the prose gate) answer as before. assert('⛔ no-reading-is-Tier-H-and-says-NOT-MEASURED', tier([SK], null) === GOVERNED_TIER_H && governedTierFor([SK], REPO) === GOVERNED_TIER_H && testVerdict([SK], { repo: REPO }).tier === GOVERNED_TIER_H && /low-risk skills arm .*NOT MEASURED/.test(renderTestVerdict(testVerdict([SK], { repo: REPO })))); From 4a459236f421a0add59431b816de104de054eb89 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 00:12:20 +0000 Subject: [PATCH 03/10] pm: the low-risk skills arm reads changesets, the timeline, the fork and a PASS record MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arm now holds a skills PR at Tier H unless its body carries exactly one bare `Clause-②: no` and `Metadata-protocol: none`, every changeset read at the head releases only `'@objectstack/skills': patch` with the same two lines, the timeline never removed a `security` label, the head is no fork, and every file under a catalog row is Markdown or an `evals/*.json`. At the queue the arm clears only on a same-head record that reads PASS, read with the fleet's verdict reader (re-exported by the recognisers). SKILL.md names the workflow Tier H triggers again. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- .claude/skills/pm-dispatch/SKILL.md | 2 +- scripts/pm/check-governed-merges.mjs | 335 +++++++++++++++++++--- scripts/pm/check-governed-queue-guard.mjs | 236 ++++++++++++--- scripts/pm/record-recognisers.mjs | 4 + 4 files changed, 486 insertions(+), 91 deletions(-) diff --git a/.claude/skills/pm-dispatch/SKILL.md b/.claude/skills/pm-dispatch/SKILL.md index d0afa425b0a..66ffa4c70b2 100644 --- a/.claude/skills/pm-dispatch/SKILL.md +++ b/.claude/skills/pm-dispatch/SKILL.md @@ -200,7 +200,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报 - ④ 轮报单列 awaiting a human merge 并现读请审人;⛔ 未请审不在 chat 报「等你批」,先补请。 - skills 车道自有 PR:纯代码面如 `scripts/pm/` 由本席自读(清单不减)后落地。 - 受管面两层:Tier S = `.claude/**`+下行 S 面,余皆 Tier H 等人批;S 经达档 PASS 后 ready → 入队。 -- 本仓 `.github/workflows/**` 由 `readWorkflowDiff`、技能措辞由 `lowRiskArmVerdict` 定档,未读 ⇒ H。 +- 本仓 `.github/workflows/**` 读 `readWorkflowDiff`(发布面/C2/拒读⇒H),技能 `lowRiskArmVerdict`,未读⇒H。 - 入队资格:每 check 绿或预期 skip,⛔ 非必查子集;名单 check-expected-skips.mjs 只判 objectstack。 - 非必查红是真缺陷或坏门,归 PM 入队前处置;第三种按设计而红,三条全立才可带红入队: - 源码自述 pushed 分支上按设计而红、不跑 `merge_group`、PR 评论记明门与因,缺一即否。 diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 9410283e0d9..0fe5a72a694 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -479,23 +479,32 @@ * `--branch`, the CODEOWNERS mirror, the prose gate, the relay's review plan) * answers exactly as before, and the approvers are still summoned — and carry * `lowRisk`, scoped to objectstack. A READING of the pull request - * (`lowRiskArmVerdict`: every changed path, the body, the label names) moves - * them to Tier S only when ALL hold: + * (`lowRiskArmVerdict`: every changed path, the body, the label names, the + * timeline, the fork predicate and the changesets read at the head) moves them + * to Tier S only when ALL hold (the last five tightened by contract review + * 6886243839): * * - every governed path lies under a catalog row — `.claude/**`, a workflow, * `AGENTS.md`, an ADR or any other row beside it is H; * - every changed path lies under a hit catalog row or matches * `LOW_RISK_RIDER_PATTERNS` (a changeset, Markdown prose under the docs * trees) — an ALLOWLIST, so `packages/**`, `ui/packages/**`, a gate script, - * a ratchet ceiling or a lockfile is H; - * - the body declares `Clause-②: no` with no arm (`readClause2Line`, the one - * reader) — `yes`, `(narrowing)`, malformed or absent is H; - * - the labels were read and none is `security`. + * a ratchet ceiling or a lockfile is H — and under a catalog row only + * Markdown and `evals/*.json` (`LOW_RISK_ARM_FILE_PATTERNS`); + * - the body carries exactly ONE bare `Clause-②: no` and ONE bare + * `Metadata-protocol: none` (`readBareDeclaration`, the fleet's readers run + * per line): `yes`, an arm, trailing words, a second declaration, or the + * line quoted or fenced is H; + * - at least one changeset, each read at the head, releasing nothing but + * `'@objectstack/skills': patch` and carrying the same two bare lines; + * - the labels were read and none is `security`, and the timeline was read and + * never removed one; + * - the head lives in the base repository (`forkVerdict`). * * Then the landing is Tier S's: a `## Contract review` record for the current * head at `CONTRACT_REVIEW_TIER` (the record recognisers' `rules` face — no - * lower tier stands on a governed path) and every check green; the owning seat - * enqueues. ⛔ Fail closed: no reading or an unmeasured one is H. `--pr` reads + * lower tier stands on a governed path) that READS PASS — the queue guard reads + * the verdict for this arm — and every check green; the owning seat enqueues. ⛔ Fail closed: no reading or an unmeasured one is H. `--pr` reads * it off the same pull object and file walk; the queue guard's `merge_group` leg * off the pull it already reads, over every commit of the PR in the group. * @@ -1081,7 +1090,7 @@ import { tmpdir } from 'node:os'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { historyHorizon } from './git-history.mjs'; -import { readClause2Line } from './clause2-line.mjs'; +import { quoteLine, readClause2Line, readMetadataProtocolLine } from './clause2-line.mjs'; import { EXIT_PREREQUISITE_NOT_MET, INSTALL_FIX, reportPrerequisiteNotMet } from '../import-prerequisite.mjs'; import { isEntrypoint } from '../invoked-as.mjs'; @@ -1138,7 +1147,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the per-row repository scope (ruled B2, 2026-10-13)': 20, 'the nested `ui/` workspace rows, on the register (#25712)': 16, '⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75, - '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 24, + '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 54, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -2245,20 +2254,91 @@ function lowRiskArmIn(surface, repo) { return Boolean(surface?.lowRisk) && Array.isArray(surface.lowRisk.repos) && surface.lowRisk.repos.includes(repo); } +/** + * The file SHAPES a low-risk row may change (contract review 6886243839, S4): skill + * wording and its evals, nothing else. A script, a JSON or YAML outside an + * `evals/` folder, an image or any other file under `skills/**` keeps the PR H. + */ +export const LOW_RISK_ARM_FILE_PATTERNS = Object.freeze([/\.md$/, /(?:^|\/)evals\/[^/]+\.json$/]); + +/** A changeset path, as the rider allowlist spells it. */ +export const LOW_RISK_CHANGESET_PATH = /^\.changeset\/[^/]+\.md$/; + +/** The ONE frontmatter line a low-risk changeset may carry (none is allowed too): the catalog, at patch. */ +export const LOW_RISK_CHANGESET_RELEASE = /^(['"])@objectstack\/skills\1[ \t]*:[ \t]*patch[ \t]*$/; + +/** + * The ONE bare declaration of `key` in `text`, read with the fleet's reader LINE + * BY LINE (never a second parser), or the reason it is not there. Pure. + * + * Every line the reader reads as `declared` or `malformed` is a declaration + * line, fenced and quoted ones included. Exactly ONE must exist, outside any + * ``` or ~~~ fence and any `>` quote, and with its list bullet, bold and + * backticks stripped it must read EXACTLY `: `. So a second + * declaration (a quoted `no` before a real `yes`), trailing words (`no — but`) + * and an arm (`no (narrowing)`) are each a reason, and the arm reads them as H. + */ +export function readBareDeclaration(text, reader, key, value) { + const hits = []; + let fence = null; + for (const line of String(text ?? '').split(/\r?\n/)) { + const read = reader(line); + if (read && (read.kind === 'declared' || read.kind === 'malformed')) hits.push({ line, fenced: fence !== null }); + const marker = /^[ \t]*(?:>[ \t]*)*(`{3,}|~{3,})/.exec(line); + if (marker) fence = fence === null ? marker[1][0] : marker[1][0] === fence ? null : fence; + } + const want = `${key}: ${value}`; + if (hits.length === 0) return { ok: false, reason: `no \`${key}:\` line` }; + if (hits.length > 1) return { ok: false, reason: `${hits.length} \`${key}:\` lines, where exactly one bare \`${want}\` is read` }; + const [{ line, fenced }] = hits; + if (fenced) return { ok: false, reason: `its one \`${key}:\` line sits inside a code fence` }; + if (/^[ \t]*>/.test(line)) return { ok: false, reason: `its one \`${key}:\` line is a quote (${quoteLine(line)})` }; + const bare = line.replace(/^[ \t]*(?:[-*][ \t]+)?/, '').replace(/\*\*|`/g, '').replace(/[ \t]+/g, ' ').trim(); + if (bare !== want) return { ok: false, reason: `its \`${key}:\` line reads ${quoteLine(line)}, not exactly \`${want}\`` }; + return { ok: true, reason: null }; +} + +/** + * Why one changeset read at the head keeps the arm H, or [] (M1). Pure. Its + * frontmatter may release `'@objectstack/skills': patch` and nothing else, and + * its body carries one bare `Clause-②: no` and one bare `Metadata-protocol: none`. + */ +export function lowRiskChangesetReasons(file) { + const path = String(file?.path ?? '(unnamed)'); + if (typeof file?.text !== 'string') return [`\`${path}\` was not read at the head`]; + const lines = file.text.replace(/^\uFEFF/, '').split(/\r?\n/); + const close = lines.findIndex((l, i) => i > 0 && l.trim() === '---'); + if (lines[0]?.trim() !== '---' || close < 0) return [`\`${path}\` carries no frontmatter block`]; + const reasons = []; + const releases = lines.slice(1, close).filter((l) => l.trim() !== '' && !LOW_RISK_CHANGESET_RELEASE.test(l.trim())); + if (releases.length > 0) reasons.push(`\`${path}\` releases ${releases.slice(0, 2).map((l) => quoteLine(l.trim(), 60)).join(', ')}; the arm allows only \`'@objectstack/skills': patch\``); + const body = lines.slice(close + 1).join('\n'); + for (const [reader, key, value] of [[readClause2Line, 'Clause-②', 'no'], [readMetadataProtocolLine, 'Metadata-protocol', 'none']]) { + const read = readBareDeclaration(body, reader, key, value); + if (!read.ok) reasons.push(`\`${path}\`: ${read.reason}`); + } + return reasons; +} + /** * The arm's verdict over one matched slice, from a READING of the pull request: - * `{ measured: true, paths, body, labels }` — every changed path (ungoverned - * ones included), the PR body (where its `Clause-②:` line is written) and its - * label names. Pure. + * `{ measured: true, paths, body, labels, timeline, fork, changesets }` — every + * changed path (ungoverned ones included), the PR body, its label names, its + * timeline events, `forkVerdict` of the pull object and the changesets read at + * the head (`{ measured, reason, files: [{ path, text }] }`). Pure. * * Tier S only when ALL of these hold, each a reason when it does not: * - every governed row hit is a low-risk row (a `.claude/**`, workflow or * any Tier H row beside it is H — the card's "no other governed path"); - * - every changed path lies under a hit low-risk row or matches `LOW_RISK_RIDER_PATTERNS`; + * - every changed path lies under a hit low-risk row or matches `LOW_RISK_RIDER_PATTERNS`, + * and every path under a low-risk row matches `LOW_RISK_ARM_FILE_PATTERNS`; * - the reading's path list holds every governed file of the slice; - * - the body declares `Clause-②: no` with NO arm (`readClause2Line`, the - * fleet's one reader; `no (narrowing)`, `yes`, malformed or absent is H); - * - the labels were read and none is `security`. + * - the body carries one bare `Clause-②: no` and one bare `Metadata-protocol: none` + * (`readBareDeclaration` over the fleet's readers); + * - at least one changeset, every one read at the head and clean (`lowRiskChangesetReasons`); + * - the labels were read and none is `security`, and the timeline was read and + * never removed a `security` label; + * - the head lives in the base repository (no fork). * ⛔ Fail closed: no reading, or one not measured, is Tier H with its reason. */ export function lowRiskArmVerdict(matched, repo, reading = null) { @@ -2272,6 +2352,7 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { }; } const reasons = []; + const more = (list, n) => `${list.slice(0, n).join(', ')}${list.length > n ? ` (+${list.length - n} more)` : ''}`; const armRows = rows.filter((s) => lowRiskArmIn(s, repo)); const outside = rows.filter((s) => !lowRiskArmIn(s, repo)); if (armRows.length === 0) reasons.push('no low-risk row was hit'); @@ -2279,17 +2360,37 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { const paths = (Array.isArray(reading.paths) ? reading.paths : []).filter((p) => typeof p === 'string' && p !== ''); if (paths.length === 0) reasons.push('the reading carries no path list'); const armPrefixes = armRows.map((s) => s.prefix).filter(Boolean); - const stray = paths.filter((p) => !armPrefixes.some((prefix) => p.startsWith(prefix)) && !LOW_RISK_RIDER_PATTERNS.some((re) => re.test(p))); - if (stray.length > 0) reasons.push(`a path outside skills wording and prose: ${stray.slice(0, 4).join(', ')}${stray.length > 4 ? ` (+${stray.length - 4} more)` : ''}`); + const underArm = (p) => armPrefixes.some((prefix) => p.startsWith(prefix)); + const stray = paths.filter((p) => !underArm(p) && !LOW_RISK_RIDER_PATTERNS.some((re) => re.test(p))); + if (stray.length > 0) reasons.push(`a path outside skills wording and prose: ${more(stray, 4)}`); + const odd = paths.filter((p) => underArm(p) && !LOW_RISK_ARM_FILE_PATTERNS.some((re) => re.test(p))); + if (odd.length > 0) reasons.push(`a skills file that is neither Markdown nor an \`evals/*.json\`: ${more(odd, 4)}`); const listed = new Set(paths); const unlisted = rows.flatMap((s) => s.files ?? []).filter((f) => !listed.has(f)); if (paths.length > 0 && unlisted.length > 0) reasons.push(`the reading's path list does not hold ${unlisted.slice(0, 2).join(', ')}`); - const clause2 = readClause2Line(reading.body); - if (clause2 === null) reasons.push('the PR body carries no `Clause-②:` line'); - else if (clause2.kind !== 'declared') reasons.push(`the PR body's \`Clause-②:\` line does not read (${clause2.line})`); - else if (clause2.value !== 'no' || clause2.arm !== null) reasons.push(`the PR body declares \`Clause-②: ${clause2.value}${clause2.arm ? ` (${clause2.arm})` : ''}\`, which stays with the maintainer`); + for (const [reader, key, value] of [[readClause2Line, 'Clause-②', 'no'], [readMetadataProtocolLine, 'Metadata-protocol', 'none']]) { + const read = readBareDeclaration(reading.body, reader, key, value); + if (!read.ok) reasons.push(`the PR body: ${read.reason}`); + } + const changesetPaths = paths.filter((p) => LOW_RISK_CHANGESET_PATH.test(p)); + const changesets = reading.changesets; + if (changesetPaths.length === 0) reasons.push('the PR carries no changeset'); + else if (!changesets || changesets.measured !== true) reasons.push(`its changesets were not read at the head (${changesets?.reason ?? 'no reading'})`); + else { + const files = Array.isArray(changesets.files) ? changesets.files : []; + for (const path of changesetPaths) { + const read = files.filter((f) => f?.path === path); + for (const r of read.length > 0 ? read : [{ path, text: null }]) reasons.push(...lowRiskChangesetReasons(r)); + } + } if (!Array.isArray(reading.labels)) reasons.push('the labels were not read'); else if (reading.labels.some((l) => String(l ?? '').toLowerCase() === 'security')) reasons.push('the PR carries the `security` label'); + const timeline = reading.timeline; + if (!timeline || timeline.measured !== true || !Array.isArray(timeline.events)) reasons.push(`its timeline was not read (${timeline?.reason ?? 'no reading'}), so a removed \`security\` label cannot be ruled out`); + else if (timeline.events.some((e) => e?.event === 'unlabeled' && String(e?.label?.name ?? '').toLowerCase() === 'security')) reasons.push('its timeline shows the `security` label removed'); + const fork = reading.fork; + if (!fork || fork.measured !== true) reasons.push('its head repository was not read, so a fork cannot be ruled out'); + else if (fork.isFork === true) reasons.push(`its head lives in a fork (${fork.headRepo ?? 'a deleted repository'})`); return { tier: reasons.length === 0 ? GOVERNED_TIER_S : GOVERNED_TIER_H, measured: true, reason: null, reasons }; } @@ -2314,11 +2415,11 @@ export function renderLowRiskLines(matched) { if (!v.measured) { return ( ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): NOT MEASURED — ${v.reason}.\n` + - ' Tier H, fail closed. `--pr ` reads the body and the labels; the queue guard reads them on the queue leg.\n' + ' Tier H, fail closed. `--pr ` on a checkout holding the head reads the PR; the queue guard reads it on the queue leg.\n' ); } if (v.tier === GOVERNED_TIER_S) { - return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, \`Clause-②: no\`, no \`security\` label.\n`; + return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, one bare \`Clause-②: no\` and \`Metadata-protocol: none\`, clean changesets, no \`security\` label ever, no fork.\n`; } return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier H —\n${v.reasons.map((r) => ` - ${r}\n`).join('')}`; } @@ -4057,8 +4158,11 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = size, fork, checks, - // The low-risk skills arm's reading (#33501), off the SAME pull object and file walk — no read of its own. - lowRisk: pullLowRiskReading(head, paths), + // The low-risk skills arm's reading (#33501), off the SAME pull object and file walk, plus the timeline + // over the same channel — read only when a path sits under an arm row, so no other `--pr` pays for it. + lowRisk: pullLowRiskReading(head, paths, { + timeline: lowRiskRowHit(paths) ? await fetchTimelineOver({ fetchImpl, url: `${apiUrl}/repos/${slug}/issues/${pull}/timeline`, channel: chosen, pageCap }) : null, + }), derivation: { kind: 'pull', slug, @@ -4080,11 +4184,68 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = * The low-risk skills arm's reading off a PR object and its WHOLE changed-path * list (`lowRiskArmVerdict`). Pure. Labels the object does not carry as a list * read `null`, which the arm reads as H; a body that is not a string reads as - * an empty body, which declares nothing and is H too. + * an empty body, which declares nothing and is H too. The fork predicate is + * read off the same object; the timeline and the changesets arrive as their own + * readings, and one not handed in is NOT MEASURED, so H. */ -export function pullLowRiskReading(head, paths) { +export function pullLowRiskReading(head, paths, { timeline = null, changesets = null } = {}) { const labels = Array.isArray(head?.labels) ? head.labels.map((l) => (typeof l === 'string' ? l : String(l?.name ?? ''))) : null; - return { measured: true, reason: null, paths: Array.isArray(paths) ? [...paths] : [], body: typeof head?.body === 'string' ? head.body : '', labels }; + return { + measured: true, + reason: null, + paths: Array.isArray(paths) ? [...paths] : [], + body: typeof head?.body === 'string' ? head.body : '', + labels, + fork: forkVerdict(head), + timeline: timeline ?? { measured: false, reason: 'the timeline was not read', events: null }, + changesets: changesets ?? { measured: false, reason: 'the changesets were not read at the head', files: [] }, + }; +} + +/** Does any of these paths sit under a register row that carries the low-risk arm? Pure. */ +export function lowRiskRowHit(paths) { + const list = Array.isArray(paths) ? paths : []; + return GOVERNED_SURFACES.some((s) => s.lowRisk && list.some((p) => typeof p === 'string' && p.startsWith(s.prefix))); +} + +/** + * The PR's issue timeline over the channel that read the PR, every page or NOT + * MEASURED: the event the arm looks for (a removed `security` label) can sit on + * any page, so a cut list is no reading. + */ +export async function fetchTimelineOver({ fetchImpl, url, channel, pageCap = PULL_FILES_PAGE_CAP }) { + const events = []; + let pages = 0; + let next = `${url}?per_page=100`; + while (next && pages < pageCap) { + const read = await fetchJsonOver(fetchImpl, next, channel); + if (!read.ok) return { measured: false, reason: `page ${pages + 1} of the timeline did not read — ${read.reason}`, events: null }; + if (!Array.isArray(read.body)) return { measured: false, reason: `page ${pages + 1} of the timeline answered no list`, events: null }; + events.push(...read.body); + pages += 1; + next = linkNext(read.link); + } + if (next) return { measured: false, reason: `the timeline runs past ${pageCap} page(s)`, events: null }; + return { measured: true, reason: null, events }; +} + +/** + * `--pr`'s changeset reading for the arm: each `.changeset/*.md` the PR changes, + * read at the PR's own head from THIS checkout. Anything short of that is NOT + * MEASURED (Tier H) naming the fetch that cures it. A path that does not read at + * the head (a deleted changeset) is carried with no text, which the arm reads as H. + */ +export function pullChangesetReading({ derivation, paths, sameCheckout, run }) { + const unmeasured = (reason) => ({ measured: false, reason, files: [] }); + const headSha = derivation?.headSha; + if (!sameCheckout) return unmeasured('the PR is not in the repository this checkout holds, so its head cannot be read here'); + if (!isObjectId(headSha)) return unmeasured('the PR object named no head commit'); + if (!run(['cat-file', '-e', `${headSha}^{commit}`]).ok) return unmeasured(`${headSha.slice(0, 10)} is not in this checkout — \`git fetch origin pull/${derivation.pull}/head\``); + const files = (Array.isArray(paths) ? paths : []).filter((p) => LOW_RISK_CHANGESET_PATH.test(p)).map((path) => { + const read = run(['show', `${headSha}:${path}`]); + return { path, text: read.ok ? read.out : null }; + }); + return { measured: true, reason: null, files }; } /** @@ -4686,7 +4847,11 @@ async function runPullMode(args) { const workflowDiff = derived.paths.some((p) => p.startsWith(WORKFLOWS_PREFIX)) ? pullWorkflowDiff({ derivation: derived.derivation, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv), git: (argv) => git(root, argv) }) : null; - return await emitVerdict(derived.paths, args, derived.derivation, derived.size, { fork: derived.fork, checks: derived.checks }, repo, workflowDiff, derived.lowRisk ?? null); + // The arm's changesets, read at the PR's head from this checkout, as the workflow split reads its trees. + const lowRisk = derived.lowRisk && lowRiskRowHit(derived.paths) + ? { ...derived.lowRisk, changesets: pullChangesetReading({ derivation: derived.derivation, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv) }) } + : derived.lowRisk ?? null; + return await emitVerdict(derived.paths, args, derived.derivation, derived.size, { fork: derived.fork, checks: derived.checks }, repo, workflowDiff, lowRisk); } /** @@ -5560,7 +5725,15 @@ async function selfTest() { const SK = 'skills/objectstack-data/SKILL.md'; const UISK = 'ui/skills/objectui-views/SKILL.md'; const CS = '.changeset/33501-skills-wording.md'; - const read = (paths, over = {}) => ({ measured: true, reason: null, paths, body: 'Fixes #1\n\nClause-②: no\nMetadata-protocol: none\n', labels: [], ...over }); + const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; + const csFiles = (paths, text = CS_TEXT) => paths.filter((p) => LOW_RISK_CHANGESET_PATH.test(p)).map((path) => ({ path, text })); + const read = (paths, over = {}) => ({ + measured: true, reason: null, paths, body: 'Fixes #1\n\nClause-②: no\nMetadata-protocol: none\n', labels: [], + timeline: { measured: true, reason: null, events: [] }, + fork: { measured: true, isFork: false, headRepo: 'o/r', baseRepo: 'o/r' }, + changesets: { measured: true, reason: null, files: csFiles(paths) }, + ...over, + }); const tier = (paths, reading, repo = REPO) => governedTierFor(paths, repo, GOVERNED_SURFACES, null, reading); const reasons = (paths, reading) => lowRiskArmVerdict(governedPathsIn(paths, REPO), REPO, reading).reasons.join(' | '); @@ -5576,10 +5749,10 @@ async function selfTest() { assert('⛔ an-unmeasured-reading-is-Tier-H-with-its-own-reason', tier([SK], { measured: false, reason: 'the pull could not be read' }) === GOVERNED_TIER_H && /the pull could not be read/.test(renderTestVerdict(testVerdict([SK], { repo: REPO, lowRisk: { measured: false, reason: 'the pull could not be read' } })))); // ⭐ The arm: pure skills wording, with its changeset and prose riders, on `Clause-②: no` and no security label. - assert('⭐ a-pure-skills-diff-on-Clause-2-no-is-Tier-S', tier([SK], read([SK])) === GOVERNED_TIER_S && testVerdict([SK], { repo: REPO, lowRisk: read([SK]) }).tier === GOVERNED_TIER_S); + assert('⭐ a-pure-skills-diff-with-its-changeset-on-Clause-2-no-is-Tier-S', tier([SK, CS], read([SK, CS])) === GOVERNED_TIER_S && testVerdict([SK, CS], { repo: REPO, lowRisk: read([SK, CS]) }).tier === GOVERNED_TIER_S, reasons([SK, CS], read([SK, CS]))); assert('⭐ with-its-changeset-and-docs-prose-riders-it-stays-Tier-S', tier([SK, CS, 'content/docs/guides/x.mdx', 'docs/agents/x.md'], read([SK, CS, 'content/docs/guides/x.mdx', 'docs/agents/x.md'])) === GOVERNED_TIER_S); - assert('a-ui-skills-diff-and-both-catalogs-together-are-Tier-S', tier([UISK], read([UISK])) === GOVERNED_TIER_S && tier([SK, UISK, CS], read([SK, UISK, CS])) === GOVERNED_TIER_S); - assert('the-words-name-the-arm-and-the-Tier-S-landing', (() => { const t = renderTestVerdict(testVerdict([SK], { repo: REPO, lowRisk: read([SK]) })); return /Tier S\(席内达档复核落地\)/.test(t) && /low-risk skills arm .*Tier S/.test(t) && t.includes(LOW_RISK_ARM_RULING); })()); + assert('a-ui-skills-diff-and-both-catalogs-together-are-Tier-S', tier([UISK, CS], read([UISK, CS])) === GOVERNED_TIER_S && tier([SK, UISK, CS], read([SK, UISK, CS])) === GOVERNED_TIER_S); + assert('the-words-name-the-arm-and-the-Tier-S-landing', (() => { const t = renderTestVerdict(testVerdict([SK, CS], { repo: REPO, lowRisk: read([SK, CS]) })); return /Tier S\(席内达档复核落地\)/.test(t) && /low-risk skills arm .*Tier S/.test(t) && t.includes(LOW_RISK_ARM_RULING); })()); // ⛔ Published source or any path outside the allowlist: H. assert('⛔ skills-plus-packages-spec-stays-H', tier([SK, 'packages/spec/src/data/field.zod.ts'], read([SK, 'packages/spec/src/data/field.zod.ts'])) === GOVERNED_TIER_H && /outside skills wording and prose: packages\/spec/.test(reasons([SK, 'packages/spec/src/data/field.zod.ts'], read([SK, 'packages/spec/src/data/field.zod.ts'])))); @@ -5592,31 +5765,99 @@ async function selfTest() { assert('⛔ skills-beside-a-Tier-S-claude-path-is-H-too', tier([SK, '.claude/agents/os-dev.md'], read([SK, '.claude/agents/os-dev.md'])) === GOVERNED_TIER_H && /outside the arm: `\.claude\/\*\*`/.test(reasons([SK, '.claude/agents/os-dev.md'], read([SK, '.claude/agents/os-dev.md'])))); // ⛔ The declaration: only a bare `Clause-②: no` lands on the seat. - const body = (line) => read([SK], { body: `Fixes #1\n\n${line}\n` }); - assert('⛔ Clause-2-yes-or-no-narrowing-or-yes-widening-is-H', ['Clause-②: yes', 'Clause-②: no (narrowing)', 'Clause-②: yes (widening)', 'Clause-②: yes (narrowing)'].every((l) => tier([SK], body(l)) === GOVERNED_TIER_H)); - assert('⛔ a-malformed-absent-or-near-miss-Clause-2-line-is-H', ['Clause-②: maybe', 'no declaration here', 'Clause 2: no', '`Clause-②:` no', ''].every((l) => tier([SK], body(l)) === GOVERNED_TIER_H) && tier([SK], read([SK], { body: null })) === GOVERNED_TIER_H); - assert('a-decorated-Clause-2-no-line-reads-as-the-one-reader-reads-it', tier([SK], body('- `Clause-②`: no')) === GOVERNED_TIER_S && tier([SK], body('- **Clause-②:** no')) === GOVERNED_TIER_S); + const body = (line) => read([SK, CS], { body: `Fixes #1\n\n${line}\nMetadata-protocol: none\n` }); + assert('⛔ Clause-2-yes-or-no-narrowing-or-yes-widening-is-H', ['Clause-②: yes', 'Clause-②: no (narrowing)', 'Clause-②: yes (widening)', 'Clause-②: yes (narrowing)'].every((l) => tier([SK, CS], body(l)) === GOVERNED_TIER_H)); + assert('⛔ a-malformed-absent-or-near-miss-Clause-2-line-is-H', ['Clause-②: maybe', 'no declaration here', 'Clause 2: no', '`Clause-②:` no', ''].every((l) => tier([SK, CS], body(l)) === GOVERNED_TIER_H) && tier([SK, CS], read([SK, CS], { body: null })) === GOVERNED_TIER_H); + assert('a-decorated-Clause-2-no-line-reads-as-the-one-reader-reads-it', tier([SK, CS], body('- `Clause-②`: no')) === GOVERNED_TIER_S && tier([SK, CS], body('- **Clause-②:** no')) === GOVERNED_TIER_S && tier([SK, CS], body('Clause-②: no')) === GOVERNED_TIER_S); // ⛔ Security: the label keeps it with the maintainer; labels not read is H. - assert('⛔ a-security-label-in-any-case-is-H', tier([SK], read([SK], { labels: ['security'] })) === GOVERNED_TIER_H && tier([SK], read([SK], { labels: ['docs', 'Security'] })) === GOVERNED_TIER_H); - assert('⛔ labels-not-read-is-H', tier([SK], read([SK], { labels: null })) === GOVERNED_TIER_H && tier([SK], read([SK], { labels: undefined })) === GOVERNED_TIER_H); + assert('⛔ a-security-label-in-any-case-is-H', tier([SK, CS], read([SK, CS], { labels: ['security'] })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { labels: ['docs', 'Security'] })) === GOVERNED_TIER_H); + assert('⛔ labels-not-read-is-H', tier([SK, CS], read([SK, CS], { labels: null })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { labels: undefined })) === GOVERNED_TIER_H); // The scope: the arm moves nothing outside objectstack, and nothing without a catalog hit. - assert('the-same-S-reading-moves-nothing-in-objectui-cloud-or-hotcrm', ['objectui', 'cloud', 'hotcrm'].every((r) => tier([SK], read([SK]), r) === GOVERNED_TIER_H)); + assert('the-same-S-reading-moves-nothing-in-objectui-cloud-or-hotcrm', tier([SK, CS], read([SK, CS])) === GOVERNED_TIER_S && ['objectui', 'cloud', 'hotcrm'].every((r) => tier([SK, CS], read([SK, CS]), r) === GOVERNED_TIER_H)); assert('a-slice-with-no-catalog-row-is-returned-as-is-byte-identical', (() => { const m = governedPathsIn(['AGENTS.md', '.claude/x.md'], REPO); return applyLowRiskArm(m, REPO, read(['AGENTS.md', '.claude/x.md'])) === m && renderLowRiskLines(m) === ''; })() && tier(['.claude/agents/os-dev.md'], read(['.claude/agents/os-dev.md'])) === GOVERNED_TIER_S); // The H words name every reason; `--pr` reads the arm off the SAME pull object and file walk. assert('the-H-words-list-each-reason', (() => { const t = renderTestVerdict(testVerdict([SK, 'packages/core/src/x.ts'], { repo: REPO, lowRisk: read([SK, 'packages/core/src/x.ts'], { labels: ['security'] }) })); return /low-risk skills arm .*Tier H/.test(t) && /packages\/core/.test(t) && /`security` label/.test(t) && /landing tier: H/.test(t); })()); - const fromPull = pullLowRiskReading({ body: 'Clause-②: no', labels: [{ name: 'skip-changeset' }, { name: 'security' }] }, [SK]); - assert('pullLowRiskReading-takes-body-label-names-and-the-whole-path-list', fromPull.measured === true && fromPull.body === 'Clause-②: no' && fromPull.labels.join() === 'skip-changeset,security' && fromPull.paths.join() === SK && pullLowRiskReading({}, [SK]).labels === null && pullLowRiskReading({ body: 7, labels: [] }, [SK]).body === '', JSON.stringify(fromPull)); + const SAME = { head: { repo: { full_name: 'o/r' } }, base: { repo: { full_name: 'o/r' } } }; + const fromPull = pullLowRiskReading({ ...SAME, body: 'Clause-②: no', labels: [{ name: 'skip-changeset' }, { name: 'security' }] }, [SK]); + assert('pullLowRiskReading-takes-body-label-names-the-whole-path-list-and-the-fork-predicate', fromPull.measured === true && fromPull.body === 'Clause-②: no' && fromPull.labels.join() === 'skip-changeset,security' && fromPull.paths.join() === SK && fromPull.fork.measured === true && fromPull.fork.isFork === false && pullLowRiskReading({}, [SK]).labels === null && pullLowRiskReading({ body: 7, labels: [] }, [SK]).body === '', JSON.stringify(fromPull)); + assert('⛔ pullLowRiskReading-without-a-timeline-or-changesets-handed-in-reads-both-NOT-MEASURED-so-H', fromPull.timeline.measured === false && fromPull.changesets.measured === false && tier([SK, CS], pullLowRiskReading({ ...SAME, body: 'Clause-②: no\nMetadata-protocol: none', labels: [] }, [SK, CS])) === GOVERNED_TIER_H); { const respond = (b) => ({ ok: true, status: 200, headers: { get: () => null }, json: async () => b }); - const walked = await fetchPullFiles({ + const urls = []; + const walk = (paths, timeline) => fetchPullFiles({ apiUrl: 'https://api', slug: 'o/r', pull: 2, channels: [{ id: 'fixture', name: 'fixture channel', headers: {} }], - fetchImpl: async (url) => (/\/files/.test(url) ? respond([{ filename: SK }, { filename: CS }]) : respond({ changed_files: 2, additions: 3, deletions: 1, body: 'Clause-②: no', labels: [{ name: 'docs' }] })), + fetchImpl: async (url) => { + urls.push(url); + if (/\/files/.test(url)) return respond(paths.map((filename) => ({ filename }))); + if (/\/timeline/.test(url)) return timeline === 'fail' ? { ok: false, status: 403, headers: { get: () => null }, json: async () => ({}) } : respond(timeline); + return respond({ ...SAME, changed_files: paths.length, additions: 3, deletions: 1, body: 'Clause-②: no\nMetadata-protocol: none', labels: [{ name: 'docs' }] }); + }, }); - assert('⭐ --pr-carries-the-arm-reading-off-the-same-GET-and-file-walk-and-it-answers-Tier-S', walked.ok === true && walked.lowRisk?.measured === true && walked.lowRisk.paths.join() === `${SK},${CS}` && tier(walked.paths, walked.lowRisk) === GOVERNED_TIER_S, JSON.stringify(walked.lowRisk ?? walked.reason)); + const walked = await walk([SK, CS], []); + const withCs = (r) => ({ ...r, changesets: { measured: true, reason: null, files: csFiles([SK, CS]) } }); + assert('⭐ --pr-carries-the-arm-reading-off-the-same-GET-file-walk-and-timeline-and-with-its-changesets-read-it-answers-Tier-S', walked.ok === true && walked.lowRisk?.measured === true && walked.lowRisk.paths.join() === `${SK},${CS}` && walked.lowRisk.timeline.measured === true && urls.some((u) => /\/issues\/2\/timeline\?per_page=100$/.test(u)) && tier(walked.paths, withCs(walked.lowRisk)) === GOVERNED_TIER_S, JSON.stringify(walked.lowRisk ?? walked.reason)); + const removed = await walk([SK, CS], [{ event: 'labeled', label: { name: 'security' } }, { event: 'unlabeled', label: { name: 'security' } }]); + assert('⛔ S1-a-security-label-REMOVED-in-the-timeline-the-pull-object-no-longer-shows-is-H', tier(removed.paths, withCs(removed.lowRisk)) === GOVERNED_TIER_H && /`security` label removed/.test(lowRiskArmVerdict(governedPathsIn(removed.paths, REPO), REPO, withCs(removed.lowRisk)).reasons.join())); + const blind = await walk([SK, CS], 'fail'); + assert('⛔ S1-a-timeline-that-does-not-read-is-NOT-MEASURED-so-H', blind.ok === true && blind.lowRisk.timeline.measured === false && tier(blind.paths, withCs(blind.lowRisk)) === GOVERNED_TIER_H); + urls.length = 0; + await walk(['packages/core/src/x.ts'], []); + assert('a-PR-with-no-arm-row-hit-spends-no-timeline-read', urls.length > 0 && !urls.some((u) => /\/timeline/.test(u)), urls.join()); } + + // ⛔ M1: the changesets, read at the head — the catalog at patch only, each with a bare `Clause-②: no` and `Metadata-protocol: none`. + const cs = (text, paths = [SK, CS]) => read(paths, { changesets: { measured: true, reason: null, files: csFiles(paths, text) } }); + const CS_BODY = '\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n'; + assert('⛔ M1-a-PR-with-no-changeset-is-H', tier([SK], read([SK])) === GOVERNED_TIER_H && /no changeset/.test(reasons([SK], read([SK])))); + assert('⛔ M1-changesets-not-read-at-the-head-are-H-with-their-reason', tier([SK, CS], read([SK, CS], { changesets: { measured: false, reason: 'not in this checkout', files: [] } })) === GOVERNED_TIER_H && /not in this checkout/.test(reasons([SK, CS], read([SK, CS], { changesets: { measured: false, reason: 'not in this checkout', files: [] } }))) && tier([SK, CS], read([SK, CS], { changesets: undefined })) === GOVERNED_TIER_H); + assert('⛔ M1-a-changeset-releasing-any-other-package-or-the-catalog-above-patch-is-H', + [`---\n'@objectstack/spec': patch\n---${CS_BODY}`, `---\n'@objectstack/skills': minor\n---${CS_BODY}`, `---\n'@objectstack/skills': patch\n'@objectstack/core': patch\n---${CS_BODY}`, `---\n'@objectstack/skills': major\n---${CS_BODY}`].every((t) => tier([SK, CS], cs(t)) === GOVERNED_TIER_H) && /releases/.test(reasons([SK, CS], cs(`---\n'@objectstack/spec': patch\n---${CS_BODY}`)))); + assert('M1-the-catalog-at-patch-in-either-quote-or-an-empty-frontmatter-is-S', [`---\n"@objectstack/skills": patch\n---${CS_BODY}`, `---\n---${CS_BODY}`, `---\n'@objectstack/skills': patch \n---${CS_BODY}`].every((t) => tier([SK, CS], cs(t)) === GOVERNED_TIER_S)); + assert('⛔ M1-a-changeset-without-a-bare-Clause-2-no-or-Metadata-protocol-none-is-H', + [`---\n'@objectstack/skills': patch\n---\n\nx\n\nMetadata-protocol: none\n`, `---\n'@objectstack/skills': patch\n---\n\nx\n\nClause-②: no\n`, `---\n'@objectstack/skills': patch\n---\n\nClause-②: no\nMetadata-protocol: added\n`, `---\n'@objectstack/skills': patch\n---\n\nClause-②: no (narrowing)\nMetadata-protocol: none\n`, `---\n'@objectstack/skills': patch\n---\n\nClause-②: no, wording\nMetadata-protocol: none\n`].every((t) => tier([SK, CS], cs(t)) === GOVERNED_TIER_H)); + assert('⛔ M1-a-changeset-with-no-frontmatter-or-that-did-not-read-at-the-head-is-H', tier([SK, CS], cs(`'@objectstack/skills': patch${CS_BODY}`)) === GOVERNED_TIER_H && tier([SK, CS], cs(null)) === GOVERNED_TIER_H && /was not read at the head/.test(reasons([SK, CS], cs(null)))); + assert('⛔ M1-a-changed-changeset-the-reading-holds-no-file-for-is-H', tier([SK, CS, '.changeset/other.md'], read([SK, CS, '.changeset/other.md'], { changesets: { measured: true, reason: null, files: csFiles([SK, CS]) } })) === GOVERNED_TIER_H); + assert('⛔ M1-the-PR-body-needs-a-bare-Metadata-protocol-none-too', ['Clause-②: no\n', 'Clause-②: no\nMetadata-protocol: semantic\n', 'Clause-②: no\nMetadata-protocol: none (wording)\n'].every((b) => tier([SK, CS], read([SK, CS], { body: b })) === GOVERNED_TIER_H) && /Metadata-protocol/.test(reasons([SK, CS], read([SK, CS], { body: 'Clause-②: no\n' })))); + assert('lowRiskChangesetReasons-is-empty-for-the-clean-changeset-and-names-the-file-otherwise', lowRiskChangesetReasons({ path: CS, text: CS_TEXT }).length === 0 && lowRiskChangesetReasons({ path: CS, text: `---\n---\n` }).every((r) => r.includes(CS)) && lowRiskChangesetReasons({ path: CS, text: `---\n---\n` }).length === 2); + + // ⛔ S2: exactly ONE bare `Clause-②: no` — trailing words, a second declaration, a quoted or fenced `no` are each H. + const bodyOf = (text) => read([SK, CS], { body: `${text}\nMetadata-protocol: none\n` }); + assert('⛔ S2-trailing-text-after-no-is-H', ['Clause-②: no — wording only', 'Clause-②: no, see below', 'Clause-②: no.'].every((l) => tier([SK, CS], bodyOf(l)) === GOVERNED_TIER_H)); + assert('⛔ S2-two-declarations-are-H-even-two-of-no', tier([SK, CS], bodyOf('Clause-②: no\nClause-②: no')) === GOVERNED_TIER_H && /2 `Clause-②:` lines/.test(reasons([SK, CS], bodyOf('Clause-②: no\nClause-②: no')))); + assert('⛔ S2-a-QUOTED-no-before-a-real-yes-is-H', tier([SK, CS], bodyOf('> Clause-②: no\n\nClause-②: yes')) === GOVERNED_TIER_H); + assert('⛔ S2-a-FENCED-no-before-a-real-yes-is-H-backtick-and-tilde', tier([SK, CS], bodyOf('```\nClause-②: no\n```\nClause-②: yes')) === GOVERNED_TIER_H && tier([SK, CS], bodyOf('~~~md\nClause-②: no\n~~~\nClause-②: yes (widening)')) === GOVERNED_TIER_H); + assert('⛔ S2-a-lone-fenced-or-quoted-no-is-H', tier([SK, CS], bodyOf('```\nClause-②: no\n```')) === GOVERNED_TIER_H && tier([SK, CS], bodyOf('> Clause-②: no')) === GOVERNED_TIER_H && /code fence/.test(reasons([SK, CS], bodyOf('```\nClause-②: no\n```'))) && /a quote/.test(reasons([SK, CS], bodyOf('> Clause-②: no')))); + assert('S2-a-fence-that-closed-before-the-real-line-leaves-it-bare', tier([SK, CS], bodyOf('```js\nconst x = 1;\n```\nClause-②: no')) === GOVERNED_TIER_S); + assert('readBareDeclaration-runs-the-one-reader-per-line', readBareDeclaration('a\nClause-②: no\nb', readClause2Line, 'Clause-②', 'no').ok === true && readBareDeclaration('Metadata-protocol: none', readMetadataProtocolLine, 'Metadata-protocol', 'none').ok === true && readBareDeclaration('Clause-②: maybe', readClause2Line, 'Clause-②', 'no').ok === false); + + // ⛔ S1: a `security` label removed before the queue read; the timeline unread. + const tl = (events) => read([SK, CS], { timeline: { measured: true, reason: null, events } }); + assert('⛔ S1-any-unlabeled-security-event-is-H-in-any-case', tier([SK, CS], tl([{ event: 'unlabeled', label: { name: 'security' } }])) === GOVERNED_TIER_H && tier([SK, CS], tl([{ event: 'unlabeled', label: { name: 'Security' } }])) === GOVERNED_TIER_H); + assert('S1-another-label-removed-or-security-on-another-event-stays-S', tier([SK, CS], tl([{ event: 'unlabeled', label: { name: 'docs' } }, { event: 'commented', label: { name: 'security' } }])) === GOVERNED_TIER_S); + assert('⛔ S1-a-timeline-not-read-or-not-a-list-is-H', tier([SK, CS], read([SK, CS], { timeline: { measured: false, reason: 'HTTP 403', events: null } })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { timeline: { measured: true, reason: null, events: null } })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { timeline: undefined })) === GOVERNED_TIER_H); + + // ⛔ S3: a fork head, or a head repository not read. + assert('⛔ S3-a-fork-PR-is-H', tier([SK, CS], read([SK, CS], { fork: { measured: true, isFork: true, headRepo: 'someone/fork', baseRepo: 'o/r' } })) === GOVERNED_TIER_H && /fork \(someone\/fork\)/.test(reasons([SK, CS], read([SK, CS], { fork: { measured: true, isFork: true, headRepo: 'someone/fork', baseRepo: 'o/r' } })))); + assert('⛔ S3-a-deleted-head-repo-or-an-unread-fork-predicate-is-H', tier([SK, CS], read([SK, CS], { fork: forkVerdict({ head: { repo: null }, base: { repo: { full_name: 'o/r' } } }) })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { fork: forkVerdict({}) })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { fork: undefined })) === GOVERNED_TIER_H); + + // ⛔ S4: under the catalog rows only Markdown and `evals/*.json`. + assert('S4-skill-Markdown-and-an-evals-json-are-S', tier([SK, 'skills/objectstack-data/evals/evals.json', CS], read([SK, 'skills/objectstack-data/evals/evals.json', CS])) === GOVERNED_TIER_S && tier(['ui/skills/x/evals/a.json', CS], read(['ui/skills/x/evals/a.json', CS])) === GOVERNED_TIER_S); + assert('⛔ S4-any-other-file-under-the-catalog-is-H', ['skills/objectstack-data/hook.js', 'skills/objectstack-data/data.json', 'skills/objectstack-data/evals/sub/a.json', 'skills/objectstack-data/evals/a.yaml', 'skills/objectstack-data/logo.png', 'ui/skills/x/run.sh'].every((p) => tier([p, CS], read([p, CS])) === GOVERNED_TIER_H) && /neither Markdown nor/.test(reasons(['skills/x/hook.js', CS], read(['skills/x/hook.js', CS])))); + assert('LOW_RISK_ARM_FILE_PATTERNS-are-frozen-and-two', Object.isFrozen(LOW_RISK_ARM_FILE_PATTERNS) && LOW_RISK_ARM_FILE_PATTERNS.length === 2); + assert('pullChangesetReading-reads-each-changeset-at-the-head-or-is-NOT-MEASURED', (() => { + const H = 'a'.repeat(40); + const run = (argv) => (argv[0] === 'cat-file' ? { ok: true, out: '' } : argv[1] === `${H}:${CS}` ? { ok: true, out: CS_TEXT } : { ok: false, out: '' }); + const ok = pullChangesetReading({ derivation: { headSha: H, pull: 2 }, paths: [SK, CS, '.changeset/gone.md'], sameCheckout: true, run }); + const away = pullChangesetReading({ derivation: { headSha: H, pull: 2 }, paths: [CS], sameCheckout: true, run: () => ({ ok: false, out: '' }) }); + return ok.measured === true && ok.files.length === 2 && ok.files[0].text === CS_TEXT && ok.files[1].text === null && + away.measured === false && /git fetch origin pull\/2\/head/.test(away.reason) && + pullChangesetReading({ derivation: { headSha: H, pull: 2 }, paths: [CS], sameCheckout: false, run }).measured === false && + pullChangesetReading({ derivation: { headSha: null, pull: 2 }, paths: [CS], sameCheckout: true, run }).measured === false; + })()); + assert('lowRiskRowHit-reads-the-arm-rows-only', lowRiskRowHit([SK]) && lowRiskRowHit(['x', UISK]) && !lowRiskRowHit(['.claude/x.md', 'packages/a.ts', 'docs/adr/1.md']) && !lowRiskRowHit(null)); } battery('the nested `ui/` workspace rows, on the register (#25712)'); diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index b67018bcb58..ede38697917 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -346,9 +346,13 @@ * `decomposeGovernedWork` keeps every path of every attributed commit * (`allPaths`, ungoverned commits of the same PR included) and reads the arm * NOT MEASURED, so the `pull_request` leg says Tier H; the `merge_group` leg's - * `readLowRiskTier` re-reads the tier with the body and label names of the pull - * object it already fetched for the head — no read of its own — through the - * register's `governedTierFor`. An unread pull stays Tier H. + * `readLowRiskTier` re-reads the tier with the body, label names and fork + * predicate of the pull object it already fetched for the head, the timeline the + * enqueue leg already read, and each changeset at the commit that touched it + * (`git show`) — through the register's `governedTierFor`. An unread pull, + * timeline or changeset stays Tier H. An entry the arm puts at Tier S clears on + * a same-head record that READS PASS (`lowRiskRecordVerdict`, the fleet's + * `contractReviewVerdictOf`); the other Tier S legs still read no verdict. * * ⭐ THE TWO CARRIERS ARE ONE DELIVERY, and the location is the governed text's * to decide rather than this file's — quoted, untranslated, because it IS the @@ -587,6 +591,7 @@ import { GOVERNED_TIER_S, HUMAN_MERGE_LINE_THRESHOLD, LOW_RISK_ARM_RULING, + LOW_RISK_CHANGESET_PATH, SELF_REPO_ID, WORKFLOWS_PREFIX, applyGeneratedExceptions, @@ -601,6 +606,7 @@ import { landsByHumanMerge, mergeWorkflowReadings, pullNumberFromSubject, + forkVerdict, pullSizeFrom, recomputeProvenanceFor, readWorkflowDiff, @@ -659,7 +665,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 16, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 38, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -922,6 +928,8 @@ export async function loadRecordRecognisers(load = (specifier) => import(specifi reviewFace: tier?.reviewFace, threads: tier?.REVIEW_OF_RECORD_THREADS, location: tier?.REVIEW_OF_RECORD_LOCATION, + // Read by the low-risk skills arm alone (#33501); absent, that arm refuses and nothing else changes. + verdictOf: tier?.contractReviewVerdictOf, }; const missing = [ ...['locate', 'deliveredCard', 'servedTierStands', 'isModelIdentifierToken', 'reviewFace'].filter((key) => typeof found[key] !== 'function'), @@ -1164,11 +1172,20 @@ export function decomposeGovernedWork(rows, repo) { // governed filter below drops a row, so an ungoverned commit of the same PR // (a `packages/**` edit in a commit of its own) still counts against the arm. const allByPull = new Map(); + // ⭐ And every changeset each commit of the PR touches, with the commit it is read at (contract review + // 6886243839, M1): the arm reads each one's committed text, so a changeset in an ungoverned commit counts too. + const changesetsByPull = new Map(); for (const row of Array.isArray(rows) ? rows : []) { if (typeof row?.pr !== 'number' || !Number.isInteger(row.pr) || row.pr <= 0) continue; const all = allByPull.get(row.pr) ?? new Set(); - for (const p of Array.isArray(row.paths) ? row.paths : []) if (typeof p === 'string' && p !== '') all.add(p); + const refs = changesetsByPull.get(row.pr) ?? []; + for (const p of Array.isArray(row.paths) ? row.paths : []) { + if (typeof p !== 'string' || p === '') continue; + all.add(p); + if (LOW_RISK_CHANGESET_PATH.test(p)) refs.push({ sha: row.sha ?? null, path: p }); + } allByPull.set(row.pr, all); + changesetsByPull.set(row.pr, refs); } for (const row of Array.isArray(rows) ? rows : []) { const surfaces = governedPathsIn(row?.paths ?? [], repo); @@ -1204,6 +1221,7 @@ export function decomposeGovernedWork(rows, repo) { shas: entry.shas, paths, allPaths: [...(allByPull.get(entry.pr) ?? entry.paths)], + changesetRefs: changesetsByPull.get(entry.pr) ?? [], workflowDiff, surfaces: applyLowRiskArm(applyWorkflowSplit(governedPathsIn(paths, repo), repo, workflowDiff), repo, null), tier: governedTierFor(paths, repo, GOVERNED_SURFACES, workflowDiff, null), @@ -1623,8 +1641,12 @@ export function renderGuardVerdict(verdict) { ' ⛔ never on the `Regen-provenance:` line being present (maintainer 2026-09-20; prose arm: 6159870311).', ] : []), - ' ⚠️ EXISTENCE and PROVENANCE, never the verdict: whether that record reads PASS is precondition ①', - ' of the landing check and stays human. This leg measures what produced it, not what it concluded.', + ...(entry.record.verdict === 'PASS' + ? [' ⚖️ the low-risk skills arm lands on a record that READS PASS, and this one does (#33501).'] + : [ + ' ⚠️ EXISTENCE and PROVENANCE, never the verdict: whether that record reads PASS is precondition ①', + ' of the landing check and stays human. This leg measures what produced it, not what it concluded.', + ]), ); } else if (entry.approval.state === 'unreadable') { lines.push(` ⛔ the review list could NOT be read — ${entry.approval.reason}`); @@ -1660,6 +1682,12 @@ export function renderGuardVerdict(verdict) { ] : entry.record.state === 'unreadable' ? [` ⛔ the review of record could NOT be read — ${entry.record.reason}`] + : entry.record.state === 'not-pass' + ? [ + ` ⛔ the \`## Contract review\` comment on this head (comment ${entry.record.id ?? '(no readable id)'}, ` + + `${entry.record.at ?? 'undated'}) does not read PASS: ${entry.record.verdictReason}.`, + ' The low-risk skills arm lands on a PASS record only (#33501); a FAIL owes a patch and a new review.', + ] : entry.record.state === 'unsigned' ? [ ` ⛔ a \`## Contract review\` comment names this head (comment ${entry.record.id ?? '(no readable id)'}, ` + @@ -1887,23 +1915,75 @@ export function renderGuardVerdict(verdict) { /** * Re-read one governed entry's tier with the low-risk skills arm's reading - * (#33501): `paths` = every path of the PR's commits (`allPaths`), the body and - * labels off the pull object the queue leg read. An entry with no catalog row - * is left untouched; `pull` null (its read failed) is an UNMEASURED reading, so - * the entry stays Tier H with the reason printed. ⛔ The tier comes from the - * register's own `governedTierFor` and `applyLowRiskArm` — no second predicate - * here. Mutates `entry` (its `surfaces` and `tier`); returns it. + * (#33501): `paths` = every path of the PR's commits (`allPaths`); the body, + * labels and fork predicate off the pull object the queue leg read; the timeline + * the enqueue leg read (`timeline`: `{ measured, reason, events }`); and each + * changeset at the commit that touched it, read with `runGit` (contract review + * 6886243839). An entry with no catalog row is left untouched; `pull` null (its + * read failed) is an UNMEASURED reading, so the entry stays Tier H with the + * reason printed, and so is a missing timeline, fork reading or git reader. + * ⛔ The tier comes from the register's own `governedTierFor` and + * `applyLowRiskArm` — no second predicate here. Mutates `entry` (its `surfaces` + * and `tier`); returns it. */ -export function readLowRiskTier(entry, repo, pull) { +export function readLowRiskTier(entry, repo, pull, { timeline = null, runGit = null } = {}) { if (!entry || !(entry.surfaces ?? []).some((s) => s?.lowRiskVerdict)) return entry; + const refs = Array.isArray(entry.changesetRefs) ? entry.changesetRefs : []; + const changesets = typeof runGit !== 'function' + ? { measured: false, reason: 'no git reader was handed to the queue leg', files: [] } + : { + measured: true, + reason: null, + files: refs.map(({ sha, path }) => { + if (!sha) return { path, text: null }; + try { + return { path, text: String(runGit(['show', `${sha}:${path}`])) }; + } catch { + return { path, text: null }; + } + }), + }; const reading = pull - ? { measured: true, reason: null, paths: entry.allPaths ?? entry.paths, body: String(pull.body ?? ''), labels: Array.isArray(pull.labels) ? pull.labels : null } + ? { + measured: true, + reason: null, + paths: entry.allPaths ?? entry.paths, + body: String(pull.body ?? ''), + labels: Array.isArray(pull.labels) ? pull.labels : null, + fork: pull.fork ?? null, + timeline: timeline ?? { measured: false, reason: 'the timeline was not read', events: null }, + changesets, + } : { measured: false, reason: 'its pull request could not be read, so its body and labels are unknown' }; entry.surfaces = applyLowRiskArm(applyWorkflowSplit(governedPathsIn(entry.paths, repo), repo, entry.workflowDiff ?? null), repo, reading); entry.tier = governedTierFor(entry.paths, repo, GOVERNED_SURFACES, entry.workflowDiff ?? null, reading); return entry; } +/** Did the low-risk skills arm put this entry at Tier S? */ +export function landsOnLowRiskArm(entry) { + return entry?.tier === TIER_S && (entry.surfaces ?? []).some((s) => s?.lowRiskVerdict?.tier === TIER_S); +} + +/** + * The record leg's verdict for an entry the low-risk arm put at Tier S: a + * record that STANDS must also READ PASS (contract review 6886243839), read off + * the same comment the locator chose, with the fleet's verdict reader + * (`contractReviewVerdictOf`, re-exported by the recognisers). Anything else — + * FAIL, no verdict word, the comment not among the rows, no reader loaded — is + * `not-pass`, a refusal. Every other entry's record is returned as it was (the + * other Tier S legs read no verdict; card #33541). Pure. + */ +export function lowRiskRecordVerdict(record, pair, recognisers) { + if (record?.state !== 'stands') return record; + if (typeof recognisers?.verdictOf !== 'function') return { ...record, state: 'not-pass', verdict: null, verdictReason: 'the contract-review verdict reader was not loaded' }; + const rows = (recognisers.threads ?? []).flatMap((thread) => (Array.isArray(pair?.[thread.rows]) ? pair[thread.rows] : [])); + const comment = record.id === null || record.id === undefined ? null : rows.find((r) => r?.id === record.id) ?? null; + if (comment === null) return { ...record, state: 'not-pass', verdict: null, verdictReason: 'the record comment was not among the rows read, so its verdict is unknown' }; + const verdict = recognisers.verdictOf(comment.body); + return verdict === 'PASS' ? { ...record, verdict } : { ...record, state: 'not-pass', verdict, verdictReason: verdict === null ? 'it states no verdict' : `it reads ${verdict}` }; +} + /** * The orchestrator, with its one IO dependency injected. * @@ -1928,6 +2008,7 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet const records = new Map(); const heads = new Map(); const pulls = new Map(); + const timelines = new Map(); const headNotes = []; let apiCalls = 0; for (const entry of governed) { @@ -1948,7 +2029,7 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet // head read was not already making. const pull = await fetchPull(entry.pr); headSha = pull?.sha ?? null; - pulls.set(entry.pr, { number: entry.pr, body: pull?.body ?? '', labels: Array.isArray(pull?.labels) ? pull.labels : null, head: { ref: pull?.headRef ?? '' } }); + pulls.set(entry.pr, { number: entry.pr, body: pull?.body ?? '', labels: Array.isArray(pull?.labels) ? pull.labels : null, fork: pull?.fork ?? null, head: { ref: pull?.headRef ?? '' } }); } catch (error) { headNotes.push( ` ℹ️ #${entry.pr}: the PR head could not be read (${String(error?.message ?? error).split('\n')[0]}) — ` + @@ -1978,12 +2059,18 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet if (event === EVENT_MERGE_GROUP && approvals.get(entry.pr)?.state !== 'approved') { if (typeof fetchTimeline !== 'function') { enqueues.set(entry.pr, undeterminedEnqueue('no timeline reader was supplied to the queue leg')); + timelines.set(entry.pr, { measured: false, reason: 'no timeline reader was supplied to the queue leg', events: null }); } else { try { apiCalls += 1; - enqueues.set(entry.pr, authorizedEnqueueVerdict(enqueuerFromTimeline(await fetchTimeline(entry.pr)))); + const events = await fetchTimeline(entry.pr); + // ⭐ Kept for the low-risk skills arm (S1): a removed `security` label is on this same timeline. + timelines.set(entry.pr, Array.isArray(events) ? { measured: true, reason: null, events } : { measured: false, reason: 'the timeline answered no list', events: null }); + enqueues.set(entry.pr, authorizedEnqueueVerdict(enqueuerFromTimeline(events))); } catch (error) { - enqueues.set(entry.pr, undeterminedEnqueue(`the timeline could not be read (${String(error?.message ?? error).split('\n')[0]})`)); + const why = `the timeline could not be read (${String(error?.message ?? error).split('\n')[0]})`; + timelines.set(entry.pr, { measured: false, reason: why, events: null }); + enqueues.set(entry.pr, undeterminedEnqueue(why)); } } } @@ -1997,9 +2084,10 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet // it — no thread is read, and the recognisers are not even loaded. if (event === EVENT_MERGE_GROUP) { // ⭐ The low-risk skills arm (#33501) FIRST: a catalog entry's tier is read - // off the pull object this leg already holds — body, labels — and the whole + // off the pull object this leg already holds — body, labels, fork — the + // timeline the enqueue leg read, the changesets at their commits and the whole // path list of its commits. An unread pull is NOT MEASURED: Tier H. - for (const entry of governed) readLowRiskTier(entry, repo, pulls.get(entry.pr) ?? null); + for (const entry of governed) readLowRiskTier(entry, repo, pulls.get(entry.pr) ?? null, { timeline: timelines.get(entry.pr) ?? null, runGit }); let recognisers = null; for (const entry of governed) { if (entry.tier !== TIER_S) continue; @@ -2061,7 +2149,9 @@ export async function runGuard({ event, repo, rows, fetchReviews, fetchPull, fet records.set(entry.pr, { state: 'unreadable', reason: unreadable, cardNote }); continue; } - records.set(entry.pr, recordVerdict({ pair, recognisers, cardNote })); + const record = recordVerdict({ pair, recognisers, cardNote }); + // ⭐ The low-risk arm lands on a record that READS PASS, never on one that merely exists. + records.set(entry.pr, landsOnLowRiskArm(entry) ? lowRiskRecordVerdict(record, pair, recognisers) : record); } } return guardVerdict({ event, repo, governed, unattributed, approvals, enqueues, records, apiCalls, headNotes, lifted }); @@ -2777,6 +2867,8 @@ export function makePullReader({ apiUrl, slug, token, fetchImpl = fetch }) { body: String(row?.body ?? ''), // The label NAMES (#33501): the low-risk skills arm reads `security` off them. Not a list ⇒ null ⇒ Tier H. labels: Array.isArray(row?.labels) ? row.labels.map((l) => String(l?.name ?? '')) : null, + // The FORK predicate off the same object (#33501, S3): a fork head keeps a skills PR Tier H. + fork: forkVerdict(row), headRef: String(row?.head?.ref ?? ''), size: pair === null ? null : { ...pair, source: `GET /repos/${slug}/pulls/${pull}` }, }; @@ -3123,7 +3215,8 @@ export async function selfTest() { // SIZE leg judges (#19036) — `null` unless a fixture hands one in, exactly // as the reader answers a pull object without the pair. Spelled once, so a // fixture can never disagree with `makePullReader` about what a pull row is. - const pull = (sha = HEAD, { body = '', headRef = '', size = null, labels = [] } = {}) => ({ sha, body, headRef, size, labels }); + const SAME_REPO = Object.freeze({ measured: true, isFork: false, headRepo: 'o/r', baseRepo: 'o/r' }); + const pull = (sha = HEAD, { body = '', headRef = '', size = null, labels = [], fork = SAME_REPO } = {}) => ({ sha, body, headRef, size, labels, fork }); const authorizedPass = (login = GOVERNED_APPROVERS[0]) => authorizedApprovalVerdict([approvedAt(login, HEAD)], HEAD); // The same authorized approval, on a commit that is no longer the head. Under // the retired sha pin this exact fixture was the REFUSAL case. @@ -4829,6 +4922,8 @@ export async function selfTest() { workflowDiff = null, labels = [], extraRows = [], + timeline = null, + fork = SAME_REPO, } = {}) => { tierApiCalls = 0; tierThreadsRead = []; @@ -4837,7 +4932,8 @@ export async function selfTest() { event, rows: [{ ...row(pr, files, 'c'.repeat(40), `x (#${pr})`), ...(workflowDiff ? { workflowDiff } : {}) }, ...extraRows], fetchReviews: async () => { tierApiCalls += 1; return reviews; }, - fetchPull: async () => { tierApiCalls += 1; if (headThrows) throw new Error('head unreadable'); return pull(head, { body: prBody, headRef: branch, labels }); }, + fetchPull: async () => { tierApiCalls += 1; if (headThrows) throw new Error('head unreadable'); return pull(head, { body: prBody, headRef: branch, labels, fork }); }, + ...(timeline === null ? {} : { fetchTimeline: async () => { if (timeline === 'throw') throw new Error('HTTP 403'); return timeline; } }), fetchComments: async (n) => { tierApiCalls += 1; tierThreadsRead.push(n); @@ -5612,38 +5708,92 @@ export async function selfTest() { const SK = 'skills/objectstack-data/SKILL.md'; const CS = '.changeset/33501-skills-wording.md'; const LOW = `Fixes #${REF_CARD}\n\nClause-②: no\nMetadata-protocol: none\n`; + const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; + // The committed changeset text, by `git show :`; any other read throws, as git does. + const csGit = (text = CS_TEXT) => (args) => { + if (args[0] === 'show' && /^[0-9a-f]{40}:\.changeset\//.test(args[1]) && text !== null) return text; + throw new Error(`fatal: path not in tree (${args.join(' ')})`); + }; + const arm = { files: [SK, CS], prBody: LOW, comments: [recordComment()], timeline: [], runGit: csGit() }; // The decomposition: a catalog entry is NOT MEASURED there (no row carries a body), and it keeps EVERY path of the PR. const split = decomposeGovernedWork([row(33501, [SK, CS, 'packages/spec/src/a.zod.ts'])], REPO).governed[0]; assert('the-decomposition-reads-a-catalog-entry-Tier-H-NOT-MEASURED-and-keeps-every-path', split.tier === TIER_H && split.surfaces[0].lowRiskVerdict?.measured === false && split.allPaths.join() === `${SK},${CS},packages/spec/src/a.zod.ts` && split.paths.join() === SK, JSON.stringify(split)); + assert('M1-the-decomposition-keeps-each-changeset-with-the-commit-it-is-read-at-ungoverned-commits-included', (() => { const e = decomposeGovernedWork([row(9, [SK], '1'.repeat(40)), row(9, [CS, 'docs/x.md'], '2'.repeat(40))], REPO).governed[0]; return e.changesetRefs.length === 1 && e.changesetRefs[0].sha === '2'.repeat(40) && e.changesetRefs[0].path === CS; })()); const twoCommits = decomposeGovernedWork([row(9, [SK], '1'.repeat(40)), row(9, ['packages/core/src/x.ts'], '2'.repeat(40))], REPO).governed[0]; - assert('⛔ an-ungoverned-commit-of-the-same-PR-still-counts-its-published-path-is-in-allPaths', twoCommits.allPaths.includes('packages/core/src/x.ts') && readLowRiskTier(twoCommits, REPO, { body: LOW, labels: [] }).tier === TIER_H, JSON.stringify(twoCommits.allPaths)); + assert('⛔ an-ungoverned-commit-of-the-same-PR-still-counts-its-published-path-is-in-allPaths', twoCommits.allPaths.includes('packages/core/src/x.ts') && readLowRiskTier(twoCommits, REPO, { body: LOW, labels: [], fork: SAME_REPO }, { timeline: { measured: true, reason: null, events: [] }, runGit: csGit() }).tier === TIER_H, JSON.stringify(twoCommits.allPaths)); const untouched = decomposeGovernedWork([row(9, ['AGENTS.md'])], REPO).governed[0]; assert('readLowRiskTier-leaves-an-entry-with-no-catalog-row-as-it-was', readLowRiskTier(untouched, REPO, null) === untouched && untouched.tier === TIER_H && !untouched.surfaces.some((s) => s.lowRiskVerdict)); - // ⭐ End to end on the queue leg: pure skills wording + changeset, `Clause-②: no`, a same-head record ⇒ the seat's enqueue clears. - const pass = await tierRun({ files: [SK, CS], prBody: LOW, comments: [recordComment()] }); - assert('⭐ a-pure-skills-PR-on-Clause-2-no-with-a-same-head-record-CLEARS-with-zero-approvals', pass.exitCode === EXIT_CLEAR && pass.conclusion === 'cleared' && pass.entries[0].tier === TIER_S && pass.entries[0].record.state === 'stands', JSON.stringify(pass.entries[0])); - assert('and-the-words-name-the-arm-and-its-ruling', /low-risk skills arm .*Tier S/.test(renderGuardVerdict(pass)) && renderGuardVerdict(pass).includes(LOW_RISK_ARM_RULING), renderGuardVerdict(pass)); - const noRecord = await tierRun({ files: [SK], prBody: LOW, comments: [] }); + // ⭐ End to end on the queue leg: pure skills wording + clean changeset, one bare `Clause-②: no`, a same-head PASS record ⇒ the seat's enqueue clears. + const pass = await tierRun(arm); + assert('⭐ a-pure-skills-PR-on-Clause-2-no-with-a-same-head-PASS-record-CLEARS-with-zero-approvals', pass.exitCode === EXIT_CLEAR && pass.conclusion === 'cleared' && pass.entries[0].tier === TIER_S && pass.entries[0].record.state === 'stands' && pass.entries[0].record.verdict === 'PASS', JSON.stringify(pass.entries[0])); + assert('and-the-words-name-the-arm-its-ruling-and-the-PASS-it-read', /low-risk skills arm .*Tier S/.test(renderGuardVerdict(pass)) && renderGuardVerdict(pass).includes(LOW_RISK_ARM_RULING) && /READS PASS, and this one does/.test(renderGuardVerdict(pass)), renderGuardVerdict(pass)); + const noRecord = await tierRun({ ...arm, comments: [] }); assert('⛔ CONTROL: the-same-skills-PR-with-NO-record-is-REFUSED-Tier-S-without-its-record', noRecord.exitCode === EXIT_REFUSED_UNAPPROVED && noRecord.entries[0].tier === TIER_S && noRecord.entries[0].record.state === 'absent'); - const old = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment({ sha: REF_OLD.slice(0, 12) })] }); + const old = await tierRun({ ...arm, comments: [recordComment({ sha: REF_OLD.slice(0, 12) })] }); assert('⛔ a-record-on-an-OLDER-head-is-REFUSED', old.exitCode === EXIT_REFUSED_UNAPPROVED && old.entries[0].record.state === 'absent'); - // ⛔ Each H case, each WITH a valid record: the record leg is never consulted, the entry needs the maintainer. - const hCase = async (over) => { const v = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment()], ...over }); return [v.exitCode, v.entries[0].tier, v.entries[0].record === undefined]; }; - const H = [EXIT_REFUSED_UNAPPROVED, TIER_H, true]; - assert('⛔ skills-plus-packages-spec-stays-H', JSON.stringify(await hCase({ files: [SK, 'packages/spec/src/data/field.zod.ts'] })) === JSON.stringify(H)); - assert('⛔ skills-with-Clause-2-yes-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: yes\n` })) === JSON.stringify(H)); - assert('⛔ skills-with-Clause-2-no-narrowing-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: no (narrowing)\n` })) === JSON.stringify(H)); - assert('⛔ skills-with-NO-Clause-2-line-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}` })) === JSON.stringify(H)); - assert('⛔ skills-with-the-security-label-stays-H', JSON.stringify(await hCase({ labels: ['security'] })) === JSON.stringify(H)); - assert('⛔ skills-beside-AGENTS-md-stays-H', JSON.stringify(await hCase({ files: [SK, 'AGENTS.md'] })) === JSON.stringify(H)); - assert('⛔ a-pull-the-leg-could-not-read-is-NOT-MEASURED-and-H', await (async () => { const v = await tierRun({ files: [SK], prBody: LOW, comments: [recordComment()], headThrows: true }); return v.exitCode === EXIT_REFUSED_UNAPPROVED && v.entries[0].tier === TIER_H && v.entries[0].surfaces[0].lowRiskVerdict?.measured === false; })()); - assert('⛔ a-published-path-in-ANOTHER-commit-of-the-same-PR-in-the-group-stays-H', JSON.stringify(await hCase({ extraRows: [row(70, ['ui/packages/react/src/x.tsx'], 'd'.repeat(40), 'y (#70)')] })) === JSON.stringify(H)); + // ⛔ The verdict: the arm lands on a record that READS PASS, never on one that merely exists. + const failRecord = await tierRun({ ...arm, comments: [recordComment({ verdictWord: '**VERDICT: FAIL**' })] }); + assert('⛔ a-same-head-FAIL-record-is-REFUSED-on-the-arm', failRecord.exitCode === EXIT_REFUSED_UNAPPROVED && failRecord.entries[0].tier === TIER_S && failRecord.entries[0].record.state === 'not-pass' && failRecord.entries[0].record.verdict === 'FAIL' && /does not read PASS: it reads FAIL/.test(renderGuardVerdict(failRecord)), renderGuardVerdict(failRecord)); + const wordless = await tierRun({ ...arm, comments: [recordComment({ verdictWord: 'pending' })] }); + assert('⛔ a-same-head-record-with-NO-verdict-word-is-REFUSED-on-the-arm', wordless.exitCode === EXIT_REFUSED_UNAPPROVED && wordless.entries[0].record.state === 'not-pass' && /states no verdict/.test(renderGuardVerdict(wordless))); + const explicitPass = await tierRun({ ...arm, comments: [recordComment({ verdictWord: '**VERDICT: PASS**' })] }); + assert('the-template-VERDICT-PASS-line-clears-the-arm', explicitPass.exitCode === EXIT_CLEAR && explicitPass.entries[0].record.verdict === 'PASS'); + const newestFail = await tierRun({ ...arm, comments: [recordComment({ id: 901, at: '2026-09-13T12:00:00Z' }), recordComment({ id: 902, at: '2026-09-13T14:00:00Z', verdictWord: '**VERDICT: FAIL**' })] }); + assert('⛔ the-NEWEST-same-head-record-is-the-one-whose-verdict-is-read-an-older-PASS-does-not-clear-a-newer-FAIL', newestFail.exitCode === EXIT_REFUSED_UNAPPROVED && newestFail.entries[0].record.id === 902 && newestFail.entries[0].record.state === 'not-pass'); + const noReader = await tierRun({ ...arm, recognisers: { ...live, verdictOf: undefined } }); + assert('⛔ a-recogniser-set-without-the-verdict-reader-REFUSES-the-arm-fail-closed', noReader.exitCode === EXIT_REFUSED_UNAPPROVED && noReader.entries[0].record.state === 'not-pass' && /verdict reader was not loaded/.test(renderGuardVerdict(noReader))); + assert('the-live-loader-reaches-the-fleet-verdict-reader', typeof live.verdictOf === 'function' && live.verdictOf('## Contract review\n\n**VERDICT: FAIL**') === 'FAIL'); + assert('lowRiskRecordVerdict-passes-a-non-standing-record-through-and-reads-the-chosen-comment', (() => { + const absent = { state: 'absent' }; + const pair = { prComments: [{ id: 5, body: '## Contract review\n\n**VERDICT: PASS**' }], cardComments: [] }; + return lowRiskRecordVerdict(absent, pair, live) === absent && lowRiskRecordVerdict({ state: 'stands', id: 5 }, pair, live).verdict === 'PASS' && lowRiskRecordVerdict({ state: 'stands', id: 6 }, pair, live).state === 'not-pass' && lowRiskRecordVerdict({ state: 'stands', id: null }, pair, live).state === 'not-pass'; + })()); + const nonArmFail = await tierRun({ comments: [recordComment({ verdictWord: '**VERDICT: FAIL**' })] }); + assert('the-other-Tier-S-legs-are-unchanged-here-a-FAIL-record-still-stands-for-them-follow-up-33541', nonArmFail.entries[0].record.state === 'stands' && nonArmFail.entries[0].record.verdict === undefined); + + // ⛔ Each H case, each WITH a valid PASS record: the record leg is never consulted, the entry needs the maintainer. + const hCase = async (over) => { const v = await tierRun({ ...arm, ...over }); return [v.exitCode, v.entries[0].tier, v.entries[0].record === undefined]; }; + const H = JSON.stringify([EXIT_REFUSED_UNAPPROVED, TIER_H, true]); + assert('⛔ skills-plus-packages-spec-stays-H', JSON.stringify(await hCase({ files: [SK, CS, 'packages/spec/src/data/field.zod.ts'] })) === H); + assert('⛔ skills-with-Clause-2-yes-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: yes\nMetadata-protocol: none\n` })) === H); + assert('⛔ skills-with-Clause-2-no-narrowing-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: no (narrowing)\nMetadata-protocol: none\n` })) === H); + assert('⛔ skills-with-NO-Clause-2-line-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nMetadata-protocol: none\n` })) === H); + assert('⛔ skills-with-the-security-label-stays-H', JSON.stringify(await hCase({ labels: ['security'] })) === H); + assert('⛔ skills-beside-AGENTS-md-stays-H', JSON.stringify(await hCase({ files: [SK, CS, 'AGENTS.md'] })) === H); + assert('⛔ a-pull-the-leg-could-not-read-is-NOT-MEASURED-and-H', await (async () => { const v = await tierRun({ ...arm, headThrows: true }); return v.exitCode === EXIT_REFUSED_UNAPPROVED && v.entries[0].tier === TIER_H && v.entries[0].surfaces[0].lowRiskVerdict?.measured === false; })()); + assert('⛔ a-published-path-in-ANOTHER-commit-of-the-same-PR-in-the-group-stays-H', JSON.stringify(await hCase({ extraRows: [row(70, ['ui/packages/react/src/x.tsx'], 'd'.repeat(40), 'y (#70)')] })) === H); + + // ⛔ M1 at the queue: the changesets read at their commits, and the body's `Metadata-protocol: none`. + assert('⛔ M1-no-changeset-stays-H', JSON.stringify(await hCase({ files: [SK] })) === H); + assert('⛔ M1-a-changeset-releasing-another-package-stays-H', JSON.stringify(await hCase({ runGit: csGit("---\n'@objectstack/skills': patch\n'@objectstack/spec': minor\n---\n\nClause-②: no\nMetadata-protocol: none\n") })) === H); + assert('⛔ M1-a-changeset-without-its-declarations-stays-H', JSON.stringify(await hCase({ runGit: csGit("---\n'@objectstack/skills': patch\n---\n\nwording\n") })) === H); + assert('⛔ M1-a-changeset-git-cannot-show-at-its-commit-stays-H', JSON.stringify(await hCase({ runGit: csGit(null) })) === H); + assert('⛔ M1-no-git-reader-on-the-leg-stays-H', JSON.stringify(await hCase({ runGit: null })) === H); + assert('⛔ M1-a-changeset-in-ANOTHER-commit-of-the-PR-is-read-too', JSON.stringify(await hCase({ files: [SK, CS], extraRows: [row(70, ['.changeset/second.md'], 'e'.repeat(40), 'y (#70)')], runGit: (args) => (args[1].endsWith('second.md') ? "---\n'@objectstack/core': patch\n---\n\nClause-②: no\nMetadata-protocol: none\n" : CS_TEXT) })) === H); + assert('⛔ M1-a-body-without-Metadata-protocol-none-stays-H', JSON.stringify(await hCase({ prBody: `Fixes #${REF_CARD}\n\nClause-②: no\n` })) === H); + + // ⛔ S1: a removed `security` label on the timeline the enqueue leg read; an unread timeline. + assert('⛔ S1-a-security-label-removed-on-the-timeline-stays-H', JSON.stringify(await hCase({ timeline: [{ event: 'labeled', label: { name: 'security' } }, { event: 'unlabeled', label: { name: 'security' } }] })) === H); + assert('⛔ S1-a-timeline-that-threw-or-was-never-read-stays-H', JSON.stringify(await hCase({ timeline: 'throw' })) === H && JSON.stringify(await hCase({ timeline: null })) === H); + // ⛔ S2: exactly one bare `Clause-②: no`. + assert('⛔ S2-trailing-text-two-lines-or-a-quoted-no-before-a-real-yes-stays-H', JSON.stringify(await hCase({ prBody: `Clause-②: no — wording\nMetadata-protocol: none\n` })) === H && JSON.stringify(await hCase({ prBody: `Clause-②: no\nClause-②: no\nMetadata-protocol: none\n` })) === H && JSON.stringify(await hCase({ prBody: `> Clause-②: no\n\nClause-②: yes\nMetadata-protocol: none\n` })) === H && JSON.stringify(await hCase({ prBody: '```\nClause-②: no\n```\nClause-②: yes\nMetadata-protocol: none\n' })) === H); + // ⛔ S3: a fork head. + assert('⛔ S3-a-fork-head-or-an-unread-fork-predicate-stays-H', JSON.stringify(await hCase({ fork: { measured: true, isFork: true, headRepo: 'x/fork', baseRepo: 'o/r' } })) === H && JSON.stringify(await hCase({ fork: null })) === H); + assert('S3-makePullReader-carries-the-fork-predicate-off-the-same-GET', await (async () => { + const respond = (b) => async () => ({ ok: true, status: 200, json: async () => b }); + const args = { apiUrl: 'https://api', slug: 'o/r', token: 't' }; + const same = await makePullReader({ ...args, fetchImpl: respond({ head: { sha: HEAD, repo: { full_name: 'o/r' } }, base: { repo: { full_name: 'o/r' } } }) })(7); + const forked = await makePullReader({ ...args, fetchImpl: respond({ head: { sha: HEAD, repo: null }, base: { repo: { full_name: 'o/r' } } }) })(7); + return same.fork.measured === true && same.fork.isFork === false && forked.fork.isFork === true; + })()); + // ⛔ S4: under the catalog only Markdown and `evals/*.json`. + assert('⛔ S4-a-script-under-skills-stays-H-an-evals-json-does-not', JSON.stringify(await hCase({ files: [SK, CS, 'skills/objectstack-data/hook.mjs'] })) === H && (await tierRun({ ...arm, files: [SK, CS, 'skills/objectstack-data/evals/evals.json'] })).exitCode === EXIT_CLEAR); // The pull_request leg reads no body: the early warning says Tier H, NOT MEASURED, and that the queue leg reads it. - const early = await tierRun({ files: [SK], prBody: LOW, event: EVENT_PULL_REQUEST }); - assert('the-pull_request-leg-names-the-arm-NOT-MEASURED-and-never-reddens', early.entries[0].tier === TIER_H && /low-risk skills arm .*NOT MEASURED/.test(renderGuardVerdict(early)) && /queue guard reads them on the queue leg/.test(renderGuardVerdict(early)), renderGuardVerdict(early)); + const early = await tierRun({ ...arm, event: EVENT_PULL_REQUEST }); + assert('the-pull_request-leg-names-the-arm-NOT-MEASURED-and-never-reddens', early.entries[0].tier === TIER_H && /low-risk skills arm .*NOT MEASURED/.test(renderGuardVerdict(early)) && /queue guard reads it on the queue leg/.test(renderGuardVerdict(early)), renderGuardVerdict(early)); } // ── The floor: every declared battery RAN, and ran its cases (#13489) ──── diff --git a/scripts/pm/record-recognisers.mjs b/scripts/pm/record-recognisers.mjs index f1d96351183..948032c0f3b 100644 --- a/scripts/pm/record-recognisers.mjs +++ b/scripts/pm/record-recognisers.mjs @@ -87,6 +87,7 @@ import { branchNameTarget, closingKeywordTargets, contractReviewHeadMatch, + contractReviewVerdictOf, deliveryEvidence, deliveryEvidenceNote, latestMarkedComment, @@ -95,6 +96,9 @@ import { SEAT_SIGNATURE_SESSION_SOURCE, stripSignatureLine, } from './check-half-states.mjs'; +// The fleet's one verdict reader, re-exported so the queue guard's lazy loader reaches it (the +// low-risk skills arm lands on a record that reads PASS, #33501). ⛔ Never a second parser. +export { contractReviewVerdictOf }; // The tier `isModelIdentifierToken` refuses by VALUE. IMPORTED, never restated: // `dispatch-gates.mjs` is the one line in `scripts/pm/**` where the model id is // spelled as a value, and a second value site here is the drift that let a From 98d301976e04e0619557a292c90304ae1c627e1c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 00:48:19 +0000 Subject: [PATCH 04/10] pm: a carried record clears the low-risk arm only when no changeset or catalog path moved The regeneration and prose-only carry admits `.changeset/**` and catalog prose such as a skill's CHANGELOG.md, yet those are what the arm reads its tier from. For an arm entry, a record carried from an older head now stands only when the hops (diffed with the leg's git reader) moved no changeset and no path under a catalog row; an unreadable diff refuses. PD 14 and SKILL.md say the skills arm is exclusive (skills-only wording), and the code comments drop the off-tier review citation. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- .claude/skills/pm-dispatch/SKILL.md | 2 +- AGENTS.md | 16 +++---- scripts/pm/check-governed-merges.mjs | 5 +- scripts/pm/check-governed-queue-guard.mjs | 56 +++++++++++++++++++---- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/.claude/skills/pm-dispatch/SKILL.md b/.claude/skills/pm-dispatch/SKILL.md index 66ffa4c70b2..9ea7ba4e477 100644 --- a/.claude/skills/pm-dispatch/SKILL.md +++ b/.claude/skills/pm-dispatch/SKILL.md @@ -199,7 +199,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报 - 速读「需要你做的」求批点名 PASS 评论 id+`Head-sha`;无 PASS ⇒ 写 contract review owed 不求批。 - ④ 轮报单列 awaiting a human merge 并现读请审人;⛔ 未请审不在 chat 报「等你批」,先补请。 - skills 车道自有 PR:纯代码面如 `scripts/pm/` 由本席自读(清单不减)后落地。 -- 受管面两层:Tier S = `.claude/**`+下行 S 面,余皆 Tier H 等人批;S 经达档 PASS 后 ready → 入队。 +- 受管面两层:Tier S = `.claude/**`+下行 S 面(技能独占),余皆 Tier H;S 经达档 PASS 后 ready→入队。 - 本仓 `.github/workflows/**` 读 `readWorkflowDiff`(发布面/C2/拒读⇒H),技能 `lowRiskArmVerdict`,未读⇒H。 - 入队资格:每 check 绿或预期 skip,⛔ 非必查子集;名单 check-expected-skips.mjs 只判 objectstack。 - 非必查红是真缺陷或坏门,归 PM 入队前处置;第三种按设计而红,三条全立才可带红入队: diff --git a/AGENTS.md b/AGENTS.md index bcccfd829f3..777ce3b53ec 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -287,14 +287,14 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas. (人合: every register row outside Tier S): those four lift only for an authorized APPROVED review by an account in `GOVERNED_APPROVERS`, on ANY commit and not dismissed; that word is spent once per PR — the OWNING seat then lands it, later pushes included; the click stays the maintainer's. **Tier S** (席内达档复核落地: `.claude/**`, and - objectstack workflow edits (`readWorkflowDiff`) and skills wording (`lowRiskArmVerdict`) read as S): those four lift - once the PR thread or its card carries a `## Contract review` record for the PR's current head with `Served-tier: - CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning seat then lands it through the - queue; the post-merge audit is the compensating control. A PR whose only governed paths are register rows the queue - leg regenerates byte-exact clears with zero approvals — an uncertified recompute, drift or a hand-authored sibling - keeps it governed. ⛔ **No agent seat submits an approving review on a governed-surface PR, under any account** — - an authorized account is agent-operated too; "CI is green" carries no information about a governance change. An - authorized account's enqueue is a review record too: ⛔ never a seat's. + objectstack workflow edits (`readWorkflowDiff`) and skills-only wording (`lowRiskArmVerdict`) read as S): those four + lift once the PR thread or its card carries a `## Contract review` record for the PR's current head with + `Served-tier: CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning seat then lands it + through the queue; the post-merge audit is the compensating control. A PR whose only governed paths are register + rows the queue leg regenerates byte-exact clears with zero approvals — an uncertified recompute, drift or a + hand-authored sibling keeps it governed. ⛔ **No agent seat submits an approving review on a governed-surface PR, + under any account** — an authorized account is agent-operated too; "CI is green" carries no information about a + governance change. An authorized account's enqueue is a review record too: ⛔ never a seat's. **Already armed or queued when you read this?** Disable auto-merge AND convert it back to **draft**, which disarms an unqueued PR; no seat act, those two included, is measured to dequeue one (`platform-readings.md`, queue diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 0fe5a72a694..e3cff8988a2 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -481,8 +481,7 @@ * `lowRisk`, scoped to objectstack. A READING of the pull request * (`lowRiskArmVerdict`: every changed path, the body, the label names, the * timeline, the fork predicate and the changesets read at the head) moves them - * to Tier S only when ALL hold (the last five tightened by contract review - * 6886243839): + * to Tier S only when ALL hold: * * - every governed path lies under a catalog row — `.claude/**`, a workflow, * `AGENTS.md`, an ADR or any other row beside it is H; @@ -2255,7 +2254,7 @@ function lowRiskArmIn(surface, repo) { } /** - * The file SHAPES a low-risk row may change (contract review 6886243839, S4): skill + * The file SHAPES a low-risk row may change: skill * wording and its evals, nothing else. A script, a JSON or YAML outside an * `evals/` folder, an image or any other file under `skills/**` keeps the PR H. */ diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index ede38697917..bede39cda04 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -352,7 +352,9 @@ * (`git show`) — through the register's `governedTierFor`. An unread pull, * timeline or changeset stays Tier H. An entry the arm puts at Tier S clears on * a same-head record that READS PASS (`lowRiskRecordVerdict`, the fleet's - * `contractReviewVerdictOf`); the other Tier S legs still read no verdict. + * `contractReviewVerdictOf`), and a record carried from an older head stands for it + * only when the hops moved no changeset and no catalog path; the other Tier S + * legs still read no verdict. * * ⭐ THE TWO CARRIERS ARE ONE DELIVERY, and the location is the governed text's * to decide rather than this file's — quoted, untranslated, because it IS the @@ -665,7 +667,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 38, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 42, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -1172,8 +1174,8 @@ export function decomposeGovernedWork(rows, repo) { // governed filter below drops a row, so an ungoverned commit of the same PR // (a `packages/**` edit in a commit of its own) still counts against the arm. const allByPull = new Map(); - // ⭐ And every changeset each commit of the PR touches, with the commit it is read at (contract review - // 6886243839, M1): the arm reads each one's committed text, so a changeset in an ungoverned commit counts too. + // ⭐ And every changeset each commit of the PR touches, with the commit it is read at: the arm reads each + // one's committed text, so a changeset in an ungoverned commit counts too. const changesetsByPull = new Map(); for (const row of Array.isArray(rows) ? rows : []) { if (typeof row?.pr !== 'number' || !Number.isInteger(row.pr) || row.pr <= 0) continue; @@ -1918,8 +1920,7 @@ export function renderGuardVerdict(verdict) { * (#33501): `paths` = every path of the PR's commits (`allPaths`); the body, * labels and fork predicate off the pull object the queue leg read; the timeline * the enqueue leg read (`timeline`: `{ measured, reason, events }`); and each - * changeset at the commit that touched it, read with `runGit` (contract review - * 6886243839). An entry with no catalog row is left untouched; `pull` null (its + * changeset at the commit that touched it, read with `runGit`. An entry with no catalog row is left untouched; `pull` null (its * read failed) is an UNMEASURED reading, so the entry stays Tier H with the * reason printed, and so is a missing timeline, fork reading or git reader. * ⛔ The tier comes from the register's own `governedTierFor` and @@ -1967,15 +1968,36 @@ export function landsOnLowRiskArm(entry) { /** * The record leg's verdict for an entry the low-risk arm put at Tier S: a - * record that STANDS must also READ PASS (contract review 6886243839), read off + * record that STANDS must also READ PASS, read off * the same comment the locator chose, with the fleet's verdict reader * (`contractReviewVerdictOf`, re-exported by the recognisers). Anything else — * FAIL, no verdict word, the comment not among the rows, no reader loaded — is * `not-pass`, a refusal. Every other entry's record is returned as it was (the - * other Tier S legs read no verdict; card #33541). Pure. + * other Tier S legs read no verdict; card #33541). + * + * ⛔ A record CARRIED from an older head (the regeneration and prose-only hops) + * stands for this arm only when nothing it reads moved after the PASS: the hops + * (`git diff -z --name-only `, through `pair.runGit`) + * may touch no `.changeset/` path and no path under a catalog row. A changeset, + * the body's partner, and catalog text such as a skill's `CHANGELOG.md` are + * prose faces the carry admits, yet they are exactly what the arm's tier was + * read from. A diff that cannot be read refuses too. Pure but for `runGit`. */ export function lowRiskRecordVerdict(record, pair, recognisers) { if (record?.state !== 'stands') return record; + if (record.carriedFrom) { + const refuse = (why) => ({ ...record, state: 'not-pass', verdict: null, verdictReason: why }); + if (typeof pair?.runGit !== 'function' || !pair?.headSha) return refuse(`it was carried from \`${String(record.carriedFrom).slice(0, 12)}\` and this leg could not diff the hops`); + let moved; + try { + moved = String(pair.runGit(['diff', '-z', '--name-only', record.carriedFrom, pair.headSha])).split('\0').filter(Boolean); + } catch (error) { + return refuse(`it was carried from \`${String(record.carriedFrom).slice(0, 12)}\` and the hops could not be diffed (${String(error?.message ?? error).split('\n')[0]})`); + } + const catalog = GOVERNED_SURFACES.filter((s) => s.lowRisk && s.prefix).map((s) => s.prefix); + const touched = moved.filter((p) => p.startsWith('.changeset/') || catalog.some((prefix) => p.startsWith(prefix))); + if (touched.length > 0) return refuse(`it was carried from \`${String(record.carriedFrom).slice(0, 12)}\` over hops that moved ${touched.slice(0, 3).join(', ')}${touched.length > 3 ? ` (+${touched.length - 3} more)` : ''}, which the arm reads, after the review`); + } if (typeof recognisers?.verdictOf !== 'function') return { ...record, state: 'not-pass', verdict: null, verdictReason: 'the contract-review verdict reader was not loaded' }; const rows = (recognisers.threads ?? []).flatMap((thread) => (Array.isArray(pair?.[thread.rows]) ? pair[thread.rows] : [])); const comment = record.id === null || record.id === undefined ? null : rows.find((r) => r?.id === record.id) ?? null; @@ -5750,6 +5772,24 @@ export async function selfTest() { const pair = { prComments: [{ id: 5, body: '## Contract review\n\n**VERDICT: PASS**' }], cardComments: [] }; return lowRiskRecordVerdict(absent, pair, live) === absent && lowRiskRecordVerdict({ state: 'stands', id: 5 }, pair, live).verdict === 'PASS' && lowRiskRecordVerdict({ state: 'stands', id: 6 }, pair, live).state === 'not-pass' && lowRiskRecordVerdict({ state: 'stands', id: null }, pair, live).state === 'not-pass'; })()); + // ⛔ A record CARRIED over prose-only hops stands for the arm only when the hops moved no changeset and no catalog path. + const armCarry = (moved) => { + const tree = qgit({ moved, attrs: '', own: { [REF_HEAD]: moved } }); + return (args) => (args[0] === 'show' ? CS_TEXT : tree(args)); + }; + const carriedDocs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry('content/docs/guides/x.mdx\0'), baseRef: QBASE }); + assert('SF1-CONTROL-a-PASS-record-carried-over-a-docs-only-hop-still-clears-the-arm', carriedDocs.exitCode === EXIT_CLEAR && carriedDocs.entries[0].record.carriedHops === 1 && carriedDocs.entries[0].record.verdict === 'PASS', JSON.stringify(carriedDocs.entries[0].record)); + const carriedCs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry(`${CS}\0`), baseRef: QBASE }); + assert('⛔ SF1-a-record-carried-over-a-hop-that-rewrote-the-CHANGESET-is-refused-on-the-arm', carriedCs.exitCode === EXIT_REFUSED_UNAPPROVED && carriedCs.entries[0].record.state === 'not-pass' && /over hops that moved \.changeset\/33501-skills-wording\.md/.test(renderGuardVerdict(carriedCs)), JSON.stringify(carriedCs.entries[0].record)); + const carriedLog = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry('skills/objectstack-data/CHANGELOG.md\0'), baseRef: QBASE }); + assert('⛔ SF1-a-record-carried-over-a-hop-that-moved-CATALOG-text-a-skill-CHANGELOG-is-refused-on-the-arm', carriedLog.exitCode === EXIT_REFUSED_UNAPPROVED && carriedLog.entries[0].record.state === 'not-pass' && /skills\/objectstack-data\/CHANGELOG\.md/.test(renderGuardVerdict(carriedLog)), JSON.stringify(carriedLog.entries[0].record)); + assert('⛔ SF1-a-carried-record-whose-hops-cannot-be-diffed-or-with-no-git-reader-is-refused', (() => { + const carriedRec = { state: 'stands', id: 5, carriedFrom: REF_OLD, carriedHops: 1 }; + const rows = { prComments: [{ id: 5, body: '## Contract review\n\n**VERDICT: PASS**' }], cardComments: [], headSha: REF_HEAD }; + return lowRiskRecordVerdict(carriedRec, { ...rows, runGit: () => { throw new Error('fatal: bad object'); } }, live).state === 'not-pass' && + lowRiskRecordVerdict(carriedRec, rows, live).state === 'not-pass' && + lowRiskRecordVerdict(carriedRec, { ...rows, runGit: () => 'docs/x.md\0' }, live).verdict === 'PASS'; + })()); const nonArmFail = await tierRun({ comments: [recordComment({ verdictWord: '**VERDICT: FAIL**' })] }); assert('the-other-Tier-S-legs-are-unchanged-here-a-FAIL-record-still-stands-for-them-follow-up-33541', nonArmFail.entries[0].record.state === 'stands' && nonArmFail.entries[0].record.verdict === undefined); From 6e6e3fe2b6276a31d6f4dacae02f89c52135b587 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 01:17:52 +0000 Subject: [PATCH 05/10] pm: the low-risk arm's carry check lists a rename by both paths `git diff --name-only` names a rename by its destination alone, so a hop that moved a skill out of the catalog into the docs tree cleared on a carried record. The check now diffs with `--no-renames`; the self-test pins the argument and runs the rename on a real repository. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- scripts/pm/check-governed-queue-guard.mjs | 61 ++++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index bede39cda04..231f5e002d0 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -582,7 +582,8 @@ */ import { execFileSync } from 'node:child_process'; -import { appendFileSync, readFileSync } from 'node:fs'; +import { appendFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { @@ -667,7 +668,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 42, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 44, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -1174,8 +1175,8 @@ export function decomposeGovernedWork(rows, repo) { // governed filter below drops a row, so an ungoverned commit of the same PR // (a `packages/**` edit in a commit of its own) still counts against the arm. const allByPull = new Map(); - // ⭐ And every changeset each commit of the PR touches, with the commit it is read at: the arm reads each - // one's committed text, so a changeset in an ungoverned commit counts too. + // ⭐ And every changeset each commit of the PR touches, with the commit it is read at: the arm reads + // each one's committed text, so a changeset in an ungoverned commit counts too. const changesetsByPull = new Map(); for (const row of Array.isArray(rows) ? rows : []) { if (typeof row?.pr !== 'number' || !Number.isInteger(row.pr) || row.pr <= 0) continue; @@ -1920,9 +1921,10 @@ export function renderGuardVerdict(verdict) { * (#33501): `paths` = every path of the PR's commits (`allPaths`); the body, * labels and fork predicate off the pull object the queue leg read; the timeline * the enqueue leg read (`timeline`: `{ measured, reason, events }`); and each - * changeset at the commit that touched it, read with `runGit`. An entry with no catalog row is left untouched; `pull` null (its - * read failed) is an UNMEASURED reading, so the entry stays Tier H with the - * reason printed, and so is a missing timeline, fork reading or git reader. + * changeset at the commit that touched it, read with `runGit`. An entry with no + * catalog row is left untouched; `pull` null (its read failed) is an UNMEASURED + * reading, so the entry stays Tier H with the reason printed, and so is a + * missing timeline, fork reading or git reader. * ⛔ The tier comes from the register's own `governedTierFor` and * `applyLowRiskArm` — no second predicate here. Mutates `entry` (its `surfaces` * and `tier`); returns it. @@ -1968,16 +1970,17 @@ export function landsOnLowRiskArm(entry) { /** * The record leg's verdict for an entry the low-risk arm put at Tier S: a - * record that STANDS must also READ PASS, read off - * the same comment the locator chose, with the fleet's verdict reader - * (`contractReviewVerdictOf`, re-exported by the recognisers). Anything else — + * record that STANDS must also READ PASS, read off the same comment the locator + * chose, with the fleet's verdict reader (`contractReviewVerdictOf`, re-exported + * by the recognisers). Anything else — * FAIL, no verdict word, the comment not among the rows, no reader loaded — is * `not-pass`, a refusal. Every other entry's record is returned as it was (the * other Tier S legs read no verdict; card #33541). * * ⛔ A record CARRIED from an older head (the regeneration and prose-only hops) * stands for this arm only when nothing it reads moved after the PASS: the hops - * (`git diff -z --name-only `, through `pair.runGit`) + * (`git diff -z --name-only --no-renames `, through + * `pair.runGit`: a rename lists BOTH paths, so a skill moved out of the catalog counts) * may touch no `.changeset/` path and no path under a catalog row. A changeset, * the body's partner, and catalog text such as a skill's `CHANGELOG.md` are * prose faces the carry admits, yet they are exactly what the arm's tier was @@ -1990,7 +1993,7 @@ export function lowRiskRecordVerdict(record, pair, recognisers) { if (typeof pair?.runGit !== 'function' || !pair?.headSha) return refuse(`it was carried from \`${String(record.carriedFrom).slice(0, 12)}\` and this leg could not diff the hops`); let moved; try { - moved = String(pair.runGit(['diff', '-z', '--name-only', record.carriedFrom, pair.headSha])).split('\0').filter(Boolean); + moved = String(pair.runGit(['diff', '-z', '--name-only', '--no-renames', record.carriedFrom, pair.headSha])).split('\0').filter(Boolean); } catch (error) { return refuse(`it was carried from \`${String(record.carriedFrom).slice(0, 12)}\` and the hops could not be diffed (${String(error?.message ?? error).split('\n')[0]})`); } @@ -5775,8 +5778,13 @@ export async function selfTest() { // ⛔ A record CARRIED over prose-only hops stands for the arm only when the hops moved no changeset and no catalog path. const armCarry = (moved) => { const tree = qgit({ moved, attrs: '', own: { [REF_HEAD]: moved } }); - return (args) => (args[0] === 'show' ? CS_TEXT : tree(args)); + return (args) => { + if (args[0] === 'show') return CS_TEXT; + if (args.includes('--no-renames')) armDiffArgs.push(args.join(' ')); + return tree(args.filter((a) => a !== '--no-renames')); + }; }; + const armDiffArgs = []; const carriedDocs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry('content/docs/guides/x.mdx\0'), baseRef: QBASE }); assert('SF1-CONTROL-a-PASS-record-carried-over-a-docs-only-hop-still-clears-the-arm', carriedDocs.exitCode === EXIT_CLEAR && carriedDocs.entries[0].record.carriedHops === 1 && carriedDocs.entries[0].record.verdict === 'PASS', JSON.stringify(carriedDocs.entries[0].record)); const carriedCs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry(`${CS}\0`), baseRef: QBASE }); @@ -5790,6 +5798,33 @@ export async function selfTest() { lowRiskRecordVerdict(carriedRec, rows, live).state === 'not-pass' && lowRiskRecordVerdict(carriedRec, { ...rows, runGit: () => 'docs/x.md\0' }, live).verdict === 'PASS'; })()); + assert('⛔ SF2-the-carry-check-diffs-with-no-renames-so-a-rename-lists-both-paths', armDiffArgs.length > 0 && armDiffArgs.every((a) => a === `diff -z --name-only --no-renames ${REF_OLD} ${REF_HEAD}`), JSON.stringify(armDiffArgs)); + assert('⛔ SF2-on-REAL-git-a-skill-renamed-out-of-the-catalog-into-docs-refuses-the-carried-record', (() => { + const dir = mkdtempSync(join(tmpdir(), 'lowrisk-rename-')); + try { + const g = (args) => execFileSync('git', args, { cwd: dir, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }); + g(['init', '-q']); + g(['config', 'user.email', 'selftest@example.invalid']); + g(['config', 'user.name', 'selftest']); + mkdirSync(join(dir, 'skills/a/rules'), { recursive: true }); + writeFileSync(join(dir, 'skills/a/rules/security.md'), 'Never echo a token back.\n'.repeat(20)); + g(['add', '-A']); + g(['commit', '-q', '-m', 'a']); + const from = g(['rev-parse', 'HEAD']).trim(); + mkdirSync(join(dir, 'content/docs'), { recursive: true }); + g(['mv', 'skills/a/rules/security.md', 'content/docs/security.md']); + g(['commit', '-q', '-m', 'b']); + const to = g(['rev-parse', 'HEAD']).trim(); + const renamesOn = g(['-c', 'diff.renames=true', 'diff', '-z', '--name-only', from, to]).split('\0').filter(Boolean); + const rec = { state: 'stands', id: 5, carriedFrom: from, carriedHops: 1 }; + const rows = { prComments: [{ id: 5, body: '## Contract review\n\n**VERDICT: PASS**' }], cardComments: [], headSha: to, runGit: g }; + const v = lowRiskRecordVerdict(rec, rows, live); + // The plain diff names the destination alone (the blind spot); the check names the catalog path. + return renamesOn.join() === 'content/docs/security.md' && v.state === 'not-pass' && /skills\/a\/rules\/security\.md/.test(v.verdictReason); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + })()); const nonArmFail = await tierRun({ comments: [recordComment({ verdictWord: '**VERDICT: FAIL**' })] }); assert('the-other-Tier-S-legs-are-unchanged-here-a-FAIL-record-still-stands-for-them-follow-up-33541', nonArmFail.entries[0].record.state === 'stands' && nonArmFail.entries[0].record.verdict === undefined); From 01d718f9051c8c74eb8d7c17e5343a716f98f418 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 01:42:55 +0000 Subject: [PATCH 06/10] pm: the low-risk arm's real-git rename case spawns git detached from the caller's GIT_ env The temporary-repository case now runs every git call with `gitFreeEnv()` and `-c commit.gpgsign=false`, as the sibling fixtures do, so an inherited GIT_DIR or GIT_INDEX_FILE never reaches the real checkout. Docblock lines rewrapped. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- scripts/pm/check-governed-merges.mjs | 11 ++++++----- scripts/pm/check-governed-queue-guard.mjs | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index e3cff8988a2..48195da464d 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -503,8 +503,9 @@ * Then the landing is Tier S's: a `## Contract review` record for the current * head at `CONTRACT_REVIEW_TIER` (the record recognisers' `rules` face — no * lower tier stands on a governed path) that READS PASS — the queue guard reads - * the verdict for this arm — and every check green; the owning seat enqueues. ⛔ Fail closed: no reading or an unmeasured one is H. `--pr` reads - * it off the same pull object and file walk; the queue guard's `merge_group` leg + * the verdict for this arm — and every check green; the owning seat enqueues. + * ⛔ Fail closed: no reading or an unmeasured one is H. `--pr` reads it off the + * same pull object and file walk; the queue guard's `merge_group` leg * off the pull it already reads, over every commit of the PR in the group. * * NOT moved: `docs/adr/**` stays Tier H. The ruling names ADR notes, but a path @@ -2254,9 +2255,9 @@ function lowRiskArmIn(surface, repo) { } /** - * The file SHAPES a low-risk row may change: skill - * wording and its evals, nothing else. A script, a JSON or YAML outside an - * `evals/` folder, an image or any other file under `skills/**` keeps the PR H. + * The file SHAPES a low-risk row may change: skill wording and its evals, + * nothing else. A script, a JSON or YAML outside an `evals/` folder, an image or + * any other file under `skills/**` keeps the PR H. */ export const LOW_RISK_ARM_FILE_PATTERNS = Object.freeze([/\.md$/, /(?:^|\/)evals\/[^/]+\.json$/]); diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index 231f5e002d0..3c2b663cbb0 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -619,6 +619,7 @@ import { repoIdForSlug, testVerdict, } from './check-governed-merges.mjs'; +import { gitFreeEnv } from '../git-env.mjs'; import { isEntrypoint } from '../invoked-as.mjs'; // ── The self-test's own battery roster and floor (#13489) ────────────────── @@ -1979,8 +1980,9 @@ export function landsOnLowRiskArm(entry) { * * ⛔ A record CARRIED from an older head (the regeneration and prose-only hops) * stands for this arm only when nothing it reads moved after the PASS: the hops - * (`git diff -z --name-only --no-renames `, through - * `pair.runGit`: a rename lists BOTH paths, so a skill moved out of the catalog counts) + * (`git diff -z --name-only --no-renames ` through + * `pair.runGit`; a rename lists BOTH paths, so a skill moved out of the catalog + * counts) * may touch no `.changeset/` path and no path under a catalog row. A changeset, * the body's partner, and catalog text such as a skill's `CHANGELOG.md` are * prose faces the carry admits, yet they are exactly what the arm's tier was @@ -5776,6 +5778,7 @@ export async function selfTest() { return lowRiskRecordVerdict(absent, pair, live) === absent && lowRiskRecordVerdict({ state: 'stands', id: 5 }, pair, live).verdict === 'PASS' && lowRiskRecordVerdict({ state: 'stands', id: 6 }, pair, live).state === 'not-pass' && lowRiskRecordVerdict({ state: 'stands', id: null }, pair, live).state === 'not-pass'; })()); // ⛔ A record CARRIED over prose-only hops stands for the arm only when the hops moved no changeset and no catalog path. + const armDiffArgs = []; const armCarry = (moved) => { const tree = qgit({ moved, attrs: '', own: { [REF_HEAD]: moved } }); return (args) => { @@ -5784,7 +5787,6 @@ export async function selfTest() { return tree(args.filter((a) => a !== '--no-renames')); }; }; - const armDiffArgs = []; const carriedDocs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry('content/docs/guides/x.mdx\0'), baseRef: QBASE }); assert('SF1-CONTROL-a-PASS-record-carried-over-a-docs-only-hop-still-clears-the-arm', carriedDocs.exitCode === EXIT_CLEAR && carriedDocs.entries[0].record.carriedHops === 1 && carriedDocs.entries[0].record.verdict === 'PASS', JSON.stringify(carriedDocs.entries[0].record)); const carriedCs = await tierRun({ ...arm, comments: onOldHead, runGit: armCarry(`${CS}\0`), baseRef: QBASE }); @@ -5802,10 +5804,15 @@ export async function selfTest() { assert('⛔ SF2-on-REAL-git-a-skill-renamed-out-of-the-catalog-into-docs-refuses-the-carried-record', (() => { const dir = mkdtempSync(join(tmpdir(), 'lowrisk-rename-')); try { - const g = (args) => execFileSync('git', args, { cwd: dir, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }); + // `gitFreeEnv` (GIT_ENV_ISOLATION_RULE): an inherited GIT_DIR or GIT_INDEX_FILE never reaches the real checkout. + const g = (args) => + execFileSync('git', ['-c', 'user.email=t@t.invalid', '-c', 'user.name=t', '-c', 'init.defaultBranch=main', '-c', 'commit.gpgsign=false', ...args], { + cwd: dir, + encoding: 'utf8', + env: gitFreeEnv(), + stdio: ['ignore', 'pipe', 'pipe'], + }); g(['init', '-q']); - g(['config', 'user.email', 'selftest@example.invalid']); - g(['config', 'user.name', 'selftest']); mkdirSync(join(dir, 'skills/a/rules'), { recursive: true }); writeFileSync(join(dir, 'skills/a/rules/security.md'), 'Never echo a token back.\n'.repeat(20)); g(['add', '-A']); From 0d879ae4ecf1532f30a6f02046b7538626d2d912 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:17:05 +0000 Subject: [PATCH 07/10] pm: the low-risk arm reads the security name of a catalog path as well as the label A changed path under a catalog row whose name below the row (any segment, any case) says security, auth or permission keeps the PR Tier H, with or without the `security` label; a rename reads as both of its paths. PD 14 names the contract reviewer's duty to label security teaching the name test cannot see. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- AGENTS.md | 20 +++++++------- scripts/pm/check-governed-merges.mjs | 33 ++++++++++++++++++++--- scripts/pm/check-governed-queue-guard.mjs | 22 ++++++++++++--- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 777ce3b53ec..d9574ebdd3e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -284,17 +284,17 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas. auto-merge, ⛔ never flip it out of draft to make any of those possible — judged on the PR's **file list**, not its description; a **mixed diff is not a proportion question**, one path hit is enough; to land the rest, split off the governed files. **The landing is tiered by the register; one Tier H path makes the whole PR Tier H.** **Tier H** - (人合: every register row outside Tier S): those four lift only for an authorized APPROVED review by an account in + (人合: every row outside Tier S): those four lift only for an authorized APPROVED review by an account in `GOVERNED_APPROVERS`, on ANY commit and not dismissed; that word is spent once per PR — the OWNING seat then lands - it, later pushes included; the click stays the maintainer's. **Tier S** (席内达档复核落地: `.claude/**`, and - objectstack workflow edits (`readWorkflowDiff`) and skills-only wording (`lowRiskArmVerdict`) read as S): those four - lift once the PR thread or its card carries a `## Contract review` record for the PR's current head with - `Served-tier: CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning seat then lands it - through the queue; the post-merge audit is the compensating control. A PR whose only governed paths are register - rows the queue leg regenerates byte-exact clears with zero approvals — an uncertified recompute, drift or a - hand-authored sibling keeps it governed. ⛔ **No agent seat submits an approving review on a governed-surface PR, - under any account** — an authorized account is agent-operated too; "CI is green" carries no information about a - governance change. An authorized account's enqueue is a review record too: ⛔ never a seat's. + it, later pushes included; the click stays the maintainer's. **Tier S** (席内达档复核落地: `.claude/**`, + objectstack workflow edits (`readWorkflowDiff`) and skills-only wording (`lowRiskArmVerdict`; the reviewer labels + unnamed security teaching) read as S): those four lift once the PR thread or its card carries a `## Contract review` + record for the PR's current head with `Served-tier: CONTRACT_REVIEW_TIER` and a PASS verdict and every check is + green — the owning seat lands it through the queue; the post-merge audit is the compensating control. A PR whose + only governed paths are register rows the queue leg regenerates byte-exact clears with zero approvals — an + uncertified recompute, drift or a hand-authored sibling keeps it governed. ⛔ **No agent seat submits an approving + review on a governed-surface PR, under any account** — an authorized account is agent-operated too; "CI is green" + says nothing about a governance change. An authorized account's enqueue is a review record too: ⛔ never a seat's. **Already armed or queued when you read this?** Disable auto-merge AND convert it back to **draft**, which disarms an unqueued PR; no seat act, those two included, is measured to dequeue one (`platform-readings.md`, queue diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 48195da464d..2dbf7de11a7 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -497,7 +497,10 @@ * - at least one changeset, each read at the head, releasing nothing but * `'@objectstack/skills': patch` and carrying the same two bare lines; * - the labels were read and none is `security`, and the timeline was read and - * never removed one; + * never removed one; and no catalog path names security, auth or permission + * (`LOW_RISK_SECURITY_NAME`, any segment below the row, any case) — the label + * OR the name sends the PR to H; security teaching the name cannot see is the + * contract reviewer's to label `security`; * - the head lives in the base repository (`forkVerdict`). * * Then the landing is Tier S's: a `## Contract review` record for the current @@ -1147,7 +1150,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the per-row repository scope (ruled B2, 2026-10-13)': 20, 'the nested `ui/` workspace rows, on the register (#25712)': 16, '⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75, - '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 54, + '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 61, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -2261,6 +2264,16 @@ function lowRiskArmIn(surface, repo) { */ export const LOW_RISK_ARM_FILE_PATTERNS = Object.freeze([/\.md$/, /(?:^|\/)evals\/[^/]+\.json$/]); +/** + * The security NAME test (maintainer ruling on the security-scope card, 「标签和路径都读」): + * a changed path under a catalog row whose name below the row — any segment, so a + * skill FOLDER named for it counts as well as a file — says security, auth or + * permission (any case) keeps the PR H, with or without the label. A segment + * rather than the basename alone, because a security skill's entry file is + * `SKILL.md`. Teaching the name cannot see is the contract reviewer's to label. + */ +export const LOW_RISK_SECURITY_NAME = /security|auth|permission/i; + /** A changeset path, as the rider allowlist spells it. */ export const LOW_RISK_CHANGESET_PATH = /^\.changeset\/[^/]+\.md$/; @@ -2365,6 +2378,11 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { if (stray.length > 0) reasons.push(`a path outside skills wording and prose: ${more(stray, 4)}`); const odd = paths.filter((p) => underArm(p) && !LOW_RISK_ARM_FILE_PATTERNS.some((re) => re.test(p))); if (odd.length > 0) reasons.push(`a skills file that is neither Markdown nor an \`evals/*.json\`: ${more(odd, 4)}`); + const securityNamed = paths.filter((p) => { + const prefix = armPrefixes.find((pre) => p.startsWith(pre)); + return prefix !== undefined && LOW_RISK_SECURITY_NAME.test(p.slice(prefix.length)); + }); + if (securityNamed.length > 0) reasons.push(`a catalog path that names security, auth or permission: ${more(securityNamed, 4)}`); const listed = new Set(paths); const unlisted = rows.flatMap((s) => s.files ?? []).filter((f) => !listed.has(f)); if (paths.length > 0 && unlisted.length > 0) reasons.push(`the reading's path list does not hold ${unlisted.slice(0, 2).join(', ')}`); @@ -2419,7 +2437,7 @@ export function renderLowRiskLines(matched) { ); } if (v.tier === GOVERNED_TIER_S) { - return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, one bare \`Clause-②: no\` and \`Metadata-protocol: none\`, clean changesets, no \`security\` label ever, no fork.\n`; + return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, one bare \`Clause-②: no\` and \`Metadata-protocol: none\`, clean changesets, no \`security\` label ever and no catalog path named for it, no fork.\n`; } return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier H —\n${v.reasons.map((r) => ` - ${r}\n`).join('')}`; } @@ -5846,6 +5864,15 @@ async function selfTest() { // ⛔ S4: under the catalog rows only Markdown and `evals/*.json`. assert('S4-skill-Markdown-and-an-evals-json-are-S', tier([SK, 'skills/objectstack-data/evals/evals.json', CS], read([SK, 'skills/objectstack-data/evals/evals.json', CS])) === GOVERNED_TIER_S && tier(['ui/skills/x/evals/a.json', CS], read(['ui/skills/x/evals/a.json', CS])) === GOVERNED_TIER_S); assert('⛔ S4-any-other-file-under-the-catalog-is-H', ['skills/objectstack-data/hook.js', 'skills/objectstack-data/data.json', 'skills/objectstack-data/evals/sub/a.json', 'skills/objectstack-data/evals/a.yaml', 'skills/objectstack-data/logo.png', 'ui/skills/x/run.sh'].every((p) => tier([p, CS], read([p, CS])) === GOVERNED_TIER_H) && /neither Markdown nor/.test(reasons(['skills/x/hook.js', CS], read(['skills/x/hook.js', CS])))); + // ⛔ The security NAME test: the label OR the path sends the PR to H (ruling 「标签和路径都读」). + const SEC_MAIN = ['skills/objectstack-api/evals/endpoints-auth-routes.json', 'skills/objectstack-data/evals/hooks-security-seeds-datasources.json', 'skills/objectstack-data/rules/security.md', 'skills/objectui/evals/auth-permissions.json', 'skills/objectui/guides/auth-permissions.md']; + assert('⛔ SEC-a-security-named-Markdown-file-is-H-and-the-reason-names-it', tier(['skills/objectstack-data/rules/security.md', CS], read(['skills/objectstack-data/rules/security.md', CS])) === GOVERNED_TIER_H && /names security, auth or permission: skills\/objectstack-data\/rules\/security\.md/.test(reasons(['skills/objectstack-data/rules/security.md', CS], read(['skills/objectstack-data/rules/security.md', CS])))); + assert('⛔ SEC-an-auth-named-evals-json-is-H', tier(['skills/objectstack-api/evals/endpoints-auth-routes.json', CS], read(['skills/objectstack-api/evals/endpoints-auth-routes.json', CS])) === GOVERNED_TIER_H); + assert('⛔ SEC-each-of-the-five-matching-files-on-main-is-H-ui-catalog-and-any-case-too', SEC_MAIN.every((p) => tier([p, CS], read([p, CS])) === GOVERNED_TIER_H) && tier(['ui/skills/x/guides/Permissions.md', CS], read(['ui/skills/x/guides/Permissions.md', CS])) === GOVERNED_TIER_H && tier(['skills/x/rules/SECURITY.md', CS], read(['skills/x/rules/SECURITY.md', CS])) === GOVERNED_TIER_H); + assert('⛔ SEC-a-skill-FOLDER-named-for-it-is-H-though-its-file-is-SKILL-md', tier(['skills/objectstack-security/SKILL.md', CS], read(['skills/objectstack-security/SKILL.md', CS])) === GOVERNED_TIER_H); + assert('⛔ SEC-a-rename-INTO-a-security-name-is-H-both-paths-are-read', tier(['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS], read(['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS])) === GOVERNED_TIER_H); + assert('⛔ SEC-a-rename-OUT-OF-a-security-name-is-H-both-paths-are-read', tier(['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS], read(['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS])) === GOVERNED_TIER_H); + assert('SEC-CONTROL-the-name-test-reads-below-the-catalog-row-only-a-security-word-in-a-rider-path-stays-S', tier([SK, CS, 'docs/agents/security-notes.md'], read([SK, CS, 'docs/agents/security-notes.md'])) === GOVERNED_TIER_S && tier(['skills/objectstack-data/rules/hooks.md', CS], read(['skills/objectstack-data/rules/hooks.md', CS])) === GOVERNED_TIER_S); assert('LOW_RISK_ARM_FILE_PATTERNS-are-frozen-and-two', Object.isFrozen(LOW_RISK_ARM_FILE_PATTERNS) && LOW_RISK_ARM_FILE_PATTERNS.length === 2); assert('pullChangesetReading-reads-each-changeset-at-the-head-or-is-NOT-MEASURED', (() => { const H = 'a'.repeat(40); diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index 3c2b663cbb0..c216aa93d8a 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -601,15 +601,16 @@ import { applyLowRiskArm, applyWorkflowSplit, assertGovernedRepo, + forkVerdict, generatedExceptionFor, governedPathsIn, governedSurfacesFor, governedTierFor, groupHitsByException, landsByHumanMerge, + lowRiskArmVerdict, mergeWorkflowReadings, pullNumberFromSubject, - forkVerdict, pullSizeFrom, recomputeProvenanceFor, readWorkflowDiff, @@ -669,7 +670,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 44, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 46, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -5815,6 +5816,7 @@ export async function selfTest() { g(['init', '-q']); mkdirSync(join(dir, 'skills/a/rules'), { recursive: true }); writeFileSync(join(dir, 'skills/a/rules/security.md'), 'Never echo a token back.\n'.repeat(20)); + writeFileSync(join(dir, 'skills/a/rules/guide.md'), 'Grant the narrowest set.\n'.repeat(20)); g(['add', '-A']); g(['commit', '-q', '-m', 'a']); const from = g(['rev-parse', 'HEAD']).trim(); @@ -5826,8 +5828,19 @@ export async function selfTest() { const rec = { state: 'stands', id: 5, carriedFrom: from, carriedHops: 1 }; const rows = { prComments: [{ id: 5, body: '## Contract review\n\n**VERDICT: PASS**' }], cardComments: [], headSha: to, runGit: g }; const v = lowRiskRecordVerdict(rec, rows, live); + // ⭐ And a rename INTO a security name inside the catalog: `--no-renames` lists BOTH sides, so the + // carry check names both and the arm's own name test reads the new name (ruling 「标签和路径都读」). + g(['mv', 'skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md']); + g(['commit', '-q', '-m', 'c']); + const to2 = g(['rev-parse', 'HEAD']).trim(); + const into = lowRiskRecordVerdict({ ...rec, carriedFrom: to }, { ...rows, headSha: to2 }, live); + const bothSides = g(['diff', '-z', '--name-only', '--no-renames', to, to2]).split('\0').filter(Boolean).sort(); + const intoTier = lowRiskArmVerdict(governedPathsIn(bothSides, REPO), REPO, { measured: true, reason: null, paths: [...bothSides, CS], body: LOW, labels: [], timeline: { measured: true, reason: null, events: [] }, fork: SAME_REPO, changesets: { measured: true, reason: null, files: [{ path: CS, text: CS_TEXT }] } }); // The plain diff names the destination alone (the blind spot); the check names the catalog path. - return renamesOn.join() === 'content/docs/security.md' && v.state === 'not-pass' && /skills\/a\/rules\/security\.md/.test(v.verdictReason); + return renamesOn.join() === 'content/docs/security.md' && v.state === 'not-pass' && /skills\/a\/rules\/security\.md/.test(v.verdictReason) && + bothSides.join() === 'skills/a/rules/guide.md,skills/a/rules/permission-guide.md' && into.state === 'not-pass' && + /guide\.md/.test(into.verdictReason) && /permission-guide\.md/.test(into.verdictReason) && + intoTier.tier === TIER_H && intoTier.reasons.some((r) => /names security, auth or permission: skills\/a\/rules\/permission-guide\.md/.test(r)); } finally { rmSync(dir, { recursive: true, force: true }); } @@ -5870,6 +5883,9 @@ export async function selfTest() { const forked = await makePullReader({ ...args, fetchImpl: respond({ head: { sha: HEAD, repo: null }, base: { repo: { full_name: 'o/r' } } }) })(7); return same.fork.measured === true && same.fork.isFork === false && forked.fork.isFork === true; })()); + // ⛔ The security NAME test at the queue (ruling 「标签和路径都读」): the label OR the path; a rename read as both paths. + assert('⛔ SEC-a-security-named-skill-file-stays-H-with-a-PASS-record-and-no-label', JSON.stringify(await hCase({ files: ['skills/objectstack-data/rules/security.md', CS] })) === H); + assert('⛔ SEC-a-rename-into-or-out-of-a-security-name-in-one-commit-stays-H', JSON.stringify(await hCase({ files: ['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS] })) === H && JSON.stringify(await hCase({ files: ['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS] })) === H); // ⛔ S4: under the catalog only Markdown and `evals/*.json`. assert('⛔ S4-a-script-under-skills-stays-H-an-evals-json-does-not', JSON.stringify(await hCase({ files: [SK, CS, 'skills/objectstack-data/hook.mjs'] })) === H && (await tierRun({ ...arm, files: [SK, CS, 'skills/objectstack-data/evals/evals.json'] })).exitCode === EXIT_CLEAR); From 1ef6b18201f1a016e42212350ee36f5eb2077729 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:22:46 +0000 Subject: [PATCH 08/10] pm: only a modified regular catalog file is wording on the low-risk arm Adding, deleting or renaming a skill or an eval changes what the catalog teaches, so a catalog path whose status is not `modified`, whose mode is not a regular file (a symlink or submodule), or whose status was not read keeps the PR Tier H. `--pr` reads the status off the API's file walk and the mode at the head from the checkout; the queue leg reads both with `diff-tree --raw --no-renames` on each governed commit. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- scripts/pm/check-governed-merges.mjs | 115 ++++++++++++++++++++-- scripts/pm/check-governed-queue-guard.mjs | 63 +++++++++++- 2 files changed, 169 insertions(+), 9 deletions(-) diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 2dbf7de11a7..4b5b107a324 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -501,7 +501,9 @@ * (`LOW_RISK_SECURITY_NAME`, any segment below the row, any case) — the label * OR the name sends the PR to H; security teaching the name cannot see is the * contract reviewer's to label `security`; - * - the head lives in the base repository (`forkVerdict`). + * - the head lives in the base repository (`forkVerdict`); + * - every catalog path is a MODIFIED regular file — an added, deleted or renamed + * skill or eval, a symlink or a status not read is H (`catalogFiles`). * * Then the landing is Tier S's: a `## Contract review` record for the current * head at `CONTRACT_REVIEW_TIER` (the record recognisers' `rules` face — no @@ -1150,7 +1152,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the per-row repository scope (ruled B2, 2026-10-13)': 20, 'the nested `ui/` workspace rows, on the register (#25712)': 16, '⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75, - '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 61, + '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 70, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -2274,6 +2276,12 @@ export const LOW_RISK_ARM_FILE_PATTERNS = Object.freeze([/\.md$/, /(?:^|\/)evals */ export const LOW_RISK_SECURITY_NAME = /security|auth|permission/i; +/** + * The file modes a catalog path may carry: a regular file. A symlink (`120000`) + * or a submodule (`160000`) under a catalog row keeps the PR H. + */ +export const LOW_RISK_REGULAR_MODES = Object.freeze(['100644', '100755']); + /** A changeset path, as the rider allowlist spells it. */ export const LOW_RISK_CHANGESET_PATH = /^\.changeset\/[^/]+\.md$/; @@ -2383,6 +2391,31 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { return prefix !== undefined && LOW_RISK_SECURITY_NAME.test(p.slice(prefix.length)); }); if (securityNamed.length > 0) reasons.push(`a catalog path that names security, auth or permission: ${more(securityNamed, 4)}`); + // ⭐ Only a MODIFIED regular catalog file is wording: adding, deleting or renaming a skill or an eval + // changes what the catalog teaches, not how it words it. Status and mode come from `catalogFiles` + // (`{ measured, reason, files: [{ path, status, mode }] }`), one row per commit that touched the path. + const armPaths = paths.filter(underArm); + if (armPaths.length > 0) { + const catalog = reading.catalogFiles; + if (!catalog || catalog.measured !== true || !Array.isArray(catalog.files)) { + reasons.push(`the status and mode of its catalog files were not read (${catalog?.reason ?? 'no reading'})`); + } else { + const unread = []; + const notModified = new Set(); + const notRegular = new Set(); + for (const p of armPaths) { + const rows = catalog.files.filter((f) => f?.path === p); + if (rows.length === 0) unread.push(p); + for (const r of rows) { + if (r?.status !== 'modified') notModified.add(`${p} (${r?.status || 'no status'})`); + else if (!LOW_RISK_REGULAR_MODES.includes(String(r?.mode ?? ''))) notRegular.add(`${p} (${r?.mode ?? 'mode not read'})`); + } + } + if (unread.length > 0) reasons.push(`no status was read for ${more(unread, 4)}`); + if (notModified.size > 0) reasons.push(`a catalog file added, deleted or renamed rather than modified: ${more([...notModified], 4)}`); + if (notRegular.size > 0) reasons.push(`a catalog path that is not a regular file: ${more([...notRegular], 4)}`); + } + } const listed = new Set(paths); const unlisted = rows.flatMap((s) => s.files ?? []).filter((f) => !listed.has(f)); if (paths.length > 0 && unlisted.length > 0) reasons.push(`the reading's path list does not hold ${unlisted.slice(0, 2).join(', ')}`); @@ -2437,7 +2470,7 @@ export function renderLowRiskLines(matched) { ); } if (v.tier === GOVERNED_TIER_S) { - return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — skills wording and prose only, one bare \`Clause-②: no\` and \`Metadata-protocol: none\`, clean changesets, no \`security\` label ever and no catalog path named for it, no fork.\n`; + return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier S — modified skill files and prose only, one bare \`Clause-②: no\` and \`Metadata-protocol: none\`, clean changesets, no \`security\` label ever and no catalog path named for it, no fork.\n`; } return ` ⚖️ low-risk skills arm (${LOW_RISK_ARM_RULING}): Tier H —\n${v.reasons.map((r) => ` - ${r}\n`).join('')}`; } @@ -4171,6 +4204,8 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = } const { paths, renames, entries } = pullPathsFrom(files); return { + // Each file's status (#33501's arm: only a MODIFIED catalog file is wording); `--pr` adds the modes. + catalogStatuses: pullCatalogStatuses(files), ok: true, paths, size, @@ -4206,7 +4241,7 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = * read off the same object; the timeline and the changesets arrive as their own * readings, and one not handed in is NOT MEASURED, so H. */ -export function pullLowRiskReading(head, paths, { timeline = null, changesets = null } = {}) { +export function pullLowRiskReading(head, paths, { timeline = null, changesets = null, catalogFiles = null } = {}) { const labels = Array.isArray(head?.labels) ? head.labels.map((l) => (typeof l === 'string' ? l : String(l?.name ?? ''))) : null; return { measured: true, @@ -4217,9 +4252,47 @@ export function pullLowRiskReading(head, paths, { timeline = null, changesets = fork: forkVerdict(head), timeline: timeline ?? { measured: false, reason: 'the timeline was not read', events: null }, changesets: changesets ?? { measured: false, reason: 'the changesets were not read at the head', files: [] }, + catalogFiles: catalogFiles ?? { measured: false, reason: 'the status and mode of the changed files were not read', files: [] }, }; } +/** + * Each changed file's STATUS off the API's file walk (`added`, `removed`, + * `modified`, `renamed`, ...), a rename's old name carried as `renamed` too. + * Pure; the mode is not on the API row, so `pullCatalogReading` reads it. + */ +export function pullCatalogStatuses(files) { + const out = []; + for (const file of Array.isArray(files) ? files : []) { + const status = typeof file?.status === 'string' ? file.status : ''; + if (typeof file?.filename === 'string' && file.filename !== '') out.push({ path: file.filename, status }); + if (typeof file?.previous_filename === 'string' && file.previous_filename !== '') out.push({ path: file.previous_filename, status: 'renamed' }); + } + return out; +} + +/** + * `--pr`'s status-and-mode reading for the arm: the API's status per path, and + * the mode of each modified catalog path at the PR's head from THIS checkout + * (`git ls-tree`). No statuses, or a head not here, is NOT MEASURED (Tier H). + */ +export function pullCatalogReading({ derivation, statuses, paths, sameCheckout, run }) { + const unmeasured = (reason) => ({ measured: false, reason, files: [] }); + if (!Array.isArray(statuses)) return unmeasured('the file walk carried no status per file'); + const headSha = derivation?.headSha; + if (!sameCheckout) return unmeasured('the PR is not in the repository this checkout holds, so its file modes cannot be read here'); + if (!isObjectId(headSha)) return unmeasured('the PR object named no head commit'); + if (!run(['cat-file', '-e', `${headSha}^{commit}`]).ok) return unmeasured(`${headSha.slice(0, 10)} is not in this checkout — \`git fetch origin pull/${derivation.pull}/head\``); + const wanted = new Set((Array.isArray(paths) ? paths : []).filter((p) => GOVERNED_SURFACES.some((s) => s.lowRisk && p.startsWith(s.prefix)))); + const files = statuses.filter((f) => wanted.has(f.path)).map((f) => { + if (f.status !== 'modified') return { ...f, mode: null }; + const tree = run(['ls-tree', headSha, '--', f.path]); + const mode = tree.ok ? (/^(\d{6}) /.exec(tree.out)?.[1] ?? null) : null; + return { ...f, mode }; + }); + return { measured: true, reason: null, files }; +} + /** Does any of these paths sit under a register row that carries the low-risk arm? Pure. */ export function lowRiskRowHit(paths) { const list = Array.isArray(paths) ? paths : []; @@ -4867,7 +4940,11 @@ async function runPullMode(args) { : null; // The arm's changesets, read at the PR's head from this checkout, as the workflow split reads its trees. const lowRisk = derived.lowRisk && lowRiskRowHit(derived.paths) - ? { ...derived.lowRisk, changesets: pullChangesetReading({ derivation: derived.derivation, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv) }) } + ? { + ...derived.lowRisk, + changesets: pullChangesetReading({ derivation: derived.derivation, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv) }), + catalogFiles: pullCatalogReading({ derivation: derived.derivation, statuses: derived.catalogStatuses, paths: derived.paths, sameCheckout: target.slug === selfSlug, run: (argv) => tryGit(root, argv) }), + } : derived.lowRisk ?? null; return await emitVerdict(derived.paths, args, derived.derivation, derived.size, { fork: derived.fork, checks: derived.checks }, repo, workflowDiff, lowRisk); } @@ -5744,12 +5821,15 @@ async function selfTest() { const UISK = 'ui/skills/objectui-views/SKILL.md'; const CS = '.changeset/33501-skills-wording.md'; const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; + // Every catalog path a MODIFIED regular file — the shape a wording PR has. + const catFiles = (paths, status = 'modified', mode = '100644') => paths.filter((p) => /^(?:ui\/)?skills\//.test(p)).map((path) => ({ path, status, mode })); const csFiles = (paths, text = CS_TEXT) => paths.filter((p) => LOW_RISK_CHANGESET_PATH.test(p)).map((path) => ({ path, text })); const read = (paths, over = {}) => ({ measured: true, reason: null, paths, body: 'Fixes #1\n\nClause-②: no\nMetadata-protocol: none\n', labels: [], timeline: { measured: true, reason: null, events: [] }, fork: { measured: true, isFork: false, headRepo: 'o/r', baseRepo: 'o/r' }, changesets: { measured: true, reason: null, files: csFiles(paths) }, + catalogFiles: { measured: true, reason: null, files: catFiles(paths) }, ...over, }); const tier = (paths, reading, repo = REPO) => governedTierFor(paths, repo, GOVERNED_SURFACES, null, reading); @@ -5815,7 +5895,7 @@ async function selfTest() { }, }); const walked = await walk([SK, CS], []); - const withCs = (r) => ({ ...r, changesets: { measured: true, reason: null, files: csFiles([SK, CS]) } }); + const withCs = (r) => ({ ...r, changesets: { measured: true, reason: null, files: csFiles([SK, CS]) }, catalogFiles: { measured: true, reason: null, files: catFiles([SK]) } }); assert('⭐ --pr-carries-the-arm-reading-off-the-same-GET-file-walk-and-timeline-and-with-its-changesets-read-it-answers-Tier-S', walked.ok === true && walked.lowRisk?.measured === true && walked.lowRisk.paths.join() === `${SK},${CS}` && walked.lowRisk.timeline.measured === true && urls.some((u) => /\/issues\/2\/timeline\?per_page=100$/.test(u)) && tier(walked.paths, withCs(walked.lowRisk)) === GOVERNED_TIER_S, JSON.stringify(walked.lowRisk ?? walked.reason)); const removed = await walk([SK, CS], [{ event: 'labeled', label: { name: 'security' } }, { event: 'unlabeled', label: { name: 'security' } }]); assert('⛔ S1-a-security-label-REMOVED-in-the-timeline-the-pull-object-no-longer-shows-is-H', tier(removed.paths, withCs(removed.lowRisk)) === GOVERNED_TIER_H && /`security` label removed/.test(lowRiskArmVerdict(governedPathsIn(removed.paths, REPO), REPO, withCs(removed.lowRisk)).reasons.join())); @@ -5873,6 +5953,29 @@ async function selfTest() { assert('⛔ SEC-a-rename-INTO-a-security-name-is-H-both-paths-are-read', tier(['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS], read(['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS])) === GOVERNED_TIER_H); assert('⛔ SEC-a-rename-OUT-OF-a-security-name-is-H-both-paths-are-read', tier(['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS], read(['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS])) === GOVERNED_TIER_H); assert('SEC-CONTROL-the-name-test-reads-below-the-catalog-row-only-a-security-word-in-a-rider-path-stays-S', tier([SK, CS, 'docs/agents/security-notes.md'], read([SK, CS, 'docs/agents/security-notes.md'])) === GOVERNED_TIER_S && tier(['skills/objectstack-data/rules/hooks.md', CS], read(['skills/objectstack-data/rules/hooks.md', CS])) === GOVERNED_TIER_S); + // ⛔ Only a MODIFIED regular catalog file is wording: add, delete, rename, a symlink, or no status is H. + const cat = (paths, files) => read(paths, { catalogFiles: { measured: true, reason: null, files } }); + assert('⛔ STATUS-adding-a-new-skill-file-is-H', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'added', mode: '100644' }])) === GOVERNED_TIER_H && /added, deleted or renamed rather than modified: skills\/objectstack-data\/SKILL\.md \(added\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'added', mode: '100644' }])))); + assert('⛔ STATUS-deleting-a-skill-is-H-on-either-spelling', ['removed', 'deleted'].every((st) => tier([SK, CS], cat([SK, CS], [{ path: SK, status: st, mode: null }])) === GOVERNED_TIER_H)); + assert('⛔ STATUS-a-rename-inside-the-catalog-is-H-both-sides', tier(['skills/a/x.md', 'skills/a/y.md', CS], cat(['skills/a/x.md', 'skills/a/y.md', CS], [{ path: 'skills/a/y.md', status: 'renamed', mode: '100644' }, { path: 'skills/a/x.md', status: 'renamed', mode: null }])) === GOVERNED_TIER_H); + assert('⛔ STATUS-an-eval-added-in-one-commit-and-modified-in-the-next-is-H', tier(['skills/a/evals/e.json', CS], cat(['skills/a/evals/e.json', CS], [{ path: 'skills/a/evals/e.json', status: 'added', mode: '100644' }, { path: 'skills/a/evals/e.json', status: 'modified', mode: '100644' }])) === GOVERNED_TIER_H); + assert('⛔ STATUS-a-symlink-or-a-mode-not-read-is-H-an-executable-regular-file-is-not', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '120000' }])) === GOVERNED_TIER_H && /not a regular file: skills\/objectstack-data\/SKILL\.md \(120000\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '120000' }]))) && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: null }])) === GOVERNED_TIER_H && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '100755' }])) === GOVERNED_TIER_S); + assert('⛔ STATUS-a-catalog-path-with-no-status-row-or-no-status-reading-is-H', tier([SK, CS], cat([SK, CS], [])) === GOVERNED_TIER_H && /no status was read for/.test(reasons([SK, CS], cat([SK, CS], []))) && tier([SK, CS], read([SK, CS], { catalogFiles: { measured: false, reason: 'not here', files: [] } })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { catalogFiles: undefined })) === GOVERNED_TIER_H && tier([SK, CS], cat([SK, CS], [{ path: SK, status: '', mode: '100644' }])) === GOVERNED_TIER_H); + assert('STATUS-a-changeset-or-docs-rider-ADDED-beside-a-modified-skill-stays-S-the-status-test-reads-catalog-paths-only', tier([SK, CS, 'docs/agents/new.md'], read([SK, CS, 'docs/agents/new.md'])) === GOVERNED_TIER_S); + assert('pullCatalogStatuses-reads-each-status-and-a-renames-old-name', (() => { + const st = pullCatalogStatuses([{ filename: 'a.md', status: 'modified' }, { filename: 'b.md', status: 'renamed', previous_filename: 'c.md' }, { filename: 'd.md' }]); + return JSON.stringify(st) === JSON.stringify([{ path: 'a.md', status: 'modified' }, { path: 'b.md', status: 'renamed' }, { path: 'c.md', status: 'renamed' }, { path: 'd.md', status: '' }]); + })()); + assert('pullCatalogReading-reads-the-mode-of-each-modified-catalog-file-at-the-head-or-is-NOT-MEASURED', (() => { + const Hd = 'a'.repeat(40); + const run = (argv) => (argv[0] === 'cat-file' ? { ok: true, out: '' } : argv[0] === 'ls-tree' ? { ok: true, out: `${argv[3] === SK ? '120000' : '100644'} blob ${'f'.repeat(40)}\t${argv[3]}` } : { ok: false, out: '' }); + const statuses = [{ path: SK, status: 'modified' }, { path: UISK, status: 'modified' }, { path: 'skills/a/new.md', status: 'added' }, { path: CS, status: 'added' }]; + const r = pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK, UISK, 'skills/a/new.md', CS], sameCheckout: true, run }); + return r.measured === true && r.files.length === 3 && r.files[0].mode === '120000' && r.files[1].mode === '100644' && r.files[2].mode === null && + pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: false, run }).measured === false && + pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses: null, paths: [SK], sameCheckout: true, run }).measured === false && + pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: true, run: () => ({ ok: false, out: '' }) }).measured === false; + })()); assert('LOW_RISK_ARM_FILE_PATTERNS-are-frozen-and-two', Object.isFrozen(LOW_RISK_ARM_FILE_PATTERNS) && LOW_RISK_ARM_FILE_PATTERNS.length === 2); assert('pullChangesetReading-reads-each-changeset-at-the-head-or-is-NOT-MEASURED', (() => { const H = 'a'.repeat(40); diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index c216aa93d8a..c40c18374a9 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -349,7 +349,9 @@ * `readLowRiskTier` re-reads the tier with the body, label names and fork * predicate of the pull object it already fetched for the head, the timeline the * enqueue leg already read, and each changeset at the commit that touched it - * (`git show`) — through the register's `governedTierFor`. An unread pull, + * (`git show`), and each governed commit's status and mode per path + * (`catalogFilesOf`, `diff-tree --raw --no-renames`) — through the register's + * `governedTierFor`. An unread pull, * timeline or changeset stays Tier H. An entry the arm puts at Tier S clears on * a same-head record that READS PASS (`lowRiskRecordVerdict`, the fleet's * `contractReviewVerdictOf`), and a record carried from an older head stands for it @@ -670,7 +672,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 46, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 52, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -1952,6 +1954,7 @@ export function readLowRiskTier(entry, repo, pull, { timeline = null, runGit = n ? { measured: true, reason: null, + catalogFiles: catalogFilesOf(entry, runGit), paths: entry.allPaths ?? entry.paths, body: String(pull.body ?? ''), labels: Array.isArray(pull.labels) ? pull.labels : null, @@ -1965,6 +1968,38 @@ export function readLowRiskTier(entry, repo, pull, { timeline = null, runGit = n return entry; } +/** `git diff-tree --raw` status letters, spelled as the arm reads them. */ +const RAW_STATUS = Object.freeze({ M: 'modified', A: 'added', D: 'deleted', T: 'type-changed', R: 'renamed', C: 'copied' }); + +/** + * The status and mode of every path each governed commit of the entry touched, + * read with `git diff-tree -r --raw -z --no-renames` against the commit's first + * parent (the same comparison `enumerateRows` lists the paths from). One row per + * commit per path, so an add in one commit and an edit in the next reads `added`. + * No git reader, a commit with no sha, or a read that throws is NOT MEASURED. + */ +export function catalogFilesOf(entry, runGit) { + if (typeof runGit !== 'function') return { measured: false, reason: 'no git reader was handed to the queue leg', files: [] }; + const shas = Array.isArray(entry?.shas) ? entry.shas : []; + if (shas.length === 0) return { measured: false, reason: 'the entry names no commit to read the status from', files: [] }; + const files = []; + for (const sha of shas) { + let out; + try { + out = String(runGit(['diff-tree', '-r', '--no-commit-id', '--no-renames', '--raw', '-z', '-m', '--first-parent', sha])); + } catch (error) { + return { measured: false, reason: `the status of ${String(sha).slice(0, 12)} could not be read (${String(error?.message ?? error).split('\n')[0]})`, files: [] }; + } + const tokens = out.split('\0'); + for (let i = 0; i + 1 < tokens.length; i += 2) { + const meta = /^:(\d{6}) (\d{6}) [0-9a-f]+ [0-9a-f]+ ([A-Z])/.exec(tokens[i].trim()); + if (!meta || tokens[i + 1] === '') continue; + files.push({ path: tokens[i + 1], status: RAW_STATUS[meta[3]] ?? meta[3], mode: meta[2] }); + } + } + return { measured: true, reason: null, files }; +} + /** Did the low-risk skills arm put this entry at Tier S? */ export function landsOnLowRiskArm(entry) { return entry?.tier === TIER_S && (entry.surfaces ?? []).some((s) => s?.lowRiskVerdict?.tier === TIER_S); @@ -5738,8 +5773,15 @@ export async function selfTest() { const LOW = `Fixes #${REF_CARD}\n\nClause-②: no\nMetadata-protocol: none\n`; const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; // The committed changeset text, by `git show :`; any other read throws, as git does. - const csGit = (text = CS_TEXT) => (args) => { + // `diff-tree --raw -z` rows: every path the fixtures touch, a MODIFIED regular file unless a case says otherwise. + const rawOf = (rows) => rows.map(([st, mode, p]) => `:100644 ${mode} ${'1'.repeat(40)} ${'2'.repeat(40)} ${st}\0${p}\0`).join(''); + const MODIFIED = rawOf([SK, 'skills/objectstack-data/evals/evals.json', 'skills/objectstack-data/rules/security.md', 'skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', 'skills/a/rules/security.md', 'skills/objectstack-data/hook.mjs'].map((p) => ['M', '100644', p]).concat([['A', '100644', CS]])); + const csGit = (text = CS_TEXT, raw = MODIFIED) => (args) => { if (args[0] === 'show' && /^[0-9a-f]{40}:\.changeset\//.test(args[1]) && text !== null) return text; + if (args[0] === 'diff-tree' && args.includes('--raw')) { + if (raw === null) throw new Error('fatal: bad object'); + return raw; + } throw new Error(`fatal: path not in tree (${args.join(' ')})`); }; const arm = { files: [SK, CS], prBody: LOW, comments: [recordComment()], timeline: [], runGit: csGit() }; @@ -5784,6 +5826,7 @@ export async function selfTest() { const tree = qgit({ moved, attrs: '', own: { [REF_HEAD]: moved } }); return (args) => { if (args[0] === 'show') return CS_TEXT; + if (args[0] === 'diff-tree' && args.includes('--raw')) return MODIFIED; if (args.includes('--no-renames')) armDiffArgs.push(args.join(' ')); return tree(args.filter((a) => a !== '--no-renames')); }; @@ -5886,6 +5929,20 @@ export async function selfTest() { // ⛔ The security NAME test at the queue (ruling 「标签和路径都读」): the label OR the path; a rename read as both paths. assert('⛔ SEC-a-security-named-skill-file-stays-H-with-a-PASS-record-and-no-label', JSON.stringify(await hCase({ files: ['skills/objectstack-data/rules/security.md', CS] })) === H); assert('⛔ SEC-a-rename-into-or-out-of-a-security-name-in-one-commit-stays-H', JSON.stringify(await hCase({ files: ['skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', CS] })) === H && JSON.stringify(await hCase({ files: ['skills/a/rules/security.md', 'skills/a/rules/guide.md', CS] })) === H); + // ⛔ Only a MODIFIED regular catalog file is wording (read off `diff-tree --raw` on each governed commit). + assert('⛔ STATUS-a-skill-ADDED-in-the-group-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['A', '100644', SK], ['A', '100644', CS]])) })) === H); + assert('⛔ STATUS-a-skill-DELETED-in-the-group-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['D', '000000', SK], ['A', '100644', CS]])) })) === H); + assert('⛔ STATUS-a-rename-read-as-delete-plus-add-under-no-renames-stays-H', JSON.stringify(await hCase({ files: ['skills/a/rules/guide.md', 'skills/a/rules/howto.md', CS], runGit: csGit(CS_TEXT, rawOf([['D', '000000', 'skills/a/rules/guide.md'], ['A', '100644', 'skills/a/rules/howto.md'], ['A', '100644', CS]])) })) === H); + assert('⛔ STATUS-a-SYMLINK-under-the-catalog-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['M', '120000', SK], ['A', '100644', CS]])) })) === H); + assert('⛔ STATUS-a-status-read-that-throws-or-misses-the-path-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, null) })) === H && JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['A', '100644', CS]])) })) === H); + assert('catalogFilesOf-reads-status-and-mode-per-commit-and-fails-closed', (() => { + const e = { shas: ['a'.repeat(40), 'b'.repeat(40)] }; + const per = { ['a'.repeat(40)]: rawOf([['A', '100644', SK]]), ['b'.repeat(40)]: rawOf([['M', '100644', SK]]) }; + const r = catalogFilesOf(e, (args) => per[args[args.length - 1]]); + return r.measured === true && r.files.map((f) => `${f.status}:${f.mode}`).join() === 'added:100644,modified:100644' && + catalogFilesOf(e, null).measured === false && catalogFilesOf({ shas: [] }, () => '').measured === false && + catalogFilesOf(e, () => { throw new Error('x'); }).measured === false; + })()); // ⛔ S4: under the catalog only Markdown and `evals/*.json`. assert('⛔ S4-a-script-under-skills-stays-H-an-evals-json-does-not', JSON.stringify(await hCase({ files: [SK, CS, 'skills/objectstack-data/hook.mjs'] })) === H && (await tierRun({ ...arm, files: [SK, CS, 'skills/objectstack-data/evals/evals.json'] })).exitCode === EXIT_CLEAR); From 0fbe225c75736f9fd9dc29a7b645f44241d82841 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 03:03:39 +0000 Subject: [PATCH 09/10] pm: the low-risk arm reads both modes, and the brief hands the reviewer the security label duty The `--pr` leg now reads each modified catalog file's mode at the merge base as well as at the head, and the queue leg carries the raw line's old mode: a symlink replaced by a regular file, or any other mode change, reads Tier H. A copy's source is carried as `copied source`, never `renamed`. The reviewer brief over a low-risk skills path names the duty to add the `security` label for teaching the path name does not show. The arm's and the queue leg's docblocks now list every condition the code enforces. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- scripts/pm/check-governed-merges.mjs | 104 +++++++++++++++------- scripts/pm/check-governed-queue-guard.mjs | 36 +++++--- scripts/pm/record-recognisers.mjs | 17 +++- 3 files changed, 113 insertions(+), 44 deletions(-) diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 4b5b107a324..2ba17238730 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -502,8 +502,9 @@ * OR the name sends the PR to H; security teaching the name cannot see is the * contract reviewer's to label `security`; * - the head lives in the base repository (`forkVerdict`); - * - every catalog path is a MODIFIED regular file — an added, deleted or renamed - * skill or eval, a symlink or a status not read is H (`catalogFiles`). + * - every catalog path is a MODIFIED regular file with the same mode at both ends + * — an added, deleted, renamed or copied skill or eval, a symlink, a mode change + * or a status not read is H (`catalogFiles`). * * Then the landing is Tier S's: a `## Contract review` record for the current * head at `CONTRACT_REVIEW_TIER` (the record recognisers' `rules` face — no @@ -1152,7 +1153,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the per-row repository scope (ruled B2, 2026-10-13)': 20, 'the nested `ui/` workspace rows, on the register (#25712)': 16, '⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 75, - '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 70, + '⚖️ the low-risk skills arm: skills wording on Clause-② no lands Tier S, everything else stays H (#33501)': 74, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -2343,10 +2344,12 @@ export function lowRiskChangesetReasons(file) { /** * The arm's verdict over one matched slice, from a READING of the pull request: - * `{ measured: true, paths, body, labels, timeline, fork, changesets }` — every - * changed path (ungoverned ones included), the PR body, its label names, its - * timeline events, `forkVerdict` of the pull object and the changesets read at - * the head (`{ measured, reason, files: [{ path, text }] }`). Pure. + * `{ measured: true, paths, body, labels, timeline, fork, changesets, catalogFiles }` + * — every changed path (ungoverned ones included), the PR body, its label names, + * its timeline events, `forkVerdict` of the pull object, the changesets read at + * the head (`{ measured, reason, files: [{ path, text }] }`) and the status and + * modes of each catalog file (`{ measured, reason, files: [{ path, status, + * oldMode, mode }] }`, one row per commit that touched it). Pure. * * Tier S only when ALL of these hold, each a reason when it does not: * - every governed row hit is a low-risk row (a `.claude/**`, workflow or @@ -2357,6 +2360,11 @@ export function lowRiskChangesetReasons(file) { * - the body carries one bare `Clause-②: no` and one bare `Metadata-protocol: none` * (`readBareDeclaration` over the fleet's readers); * - at least one changeset, every one read at the head and clean (`lowRiskChangesetReasons`); + * - no path below a low-risk row names security, auth or permission + * (`LOW_RISK_SECURITY_NAME`, any segment, any case; ruling B on card #33501); + * - every catalog path's every status row reads `modified`, with a regular mode + * (`LOW_RISK_REGULAR_MODES`) at both ends and the same mode at both ends — an + * add, delete, rename, copy, symlink, mode change or unread row is H (ruling A); * - the labels were read and none is `security`, and the timeline was read and * never removed a `security` label; * - the head lives in the base repository (no fork). @@ -2393,7 +2401,9 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { if (securityNamed.length > 0) reasons.push(`a catalog path that names security, auth or permission: ${more(securityNamed, 4)}`); // ⭐ Only a MODIFIED regular catalog file is wording: adding, deleting or renaming a skill or an eval // changes what the catalog teaches, not how it words it. Status and mode come from `catalogFiles` - // (`{ measured, reason, files: [{ path, status, mode }] }`), one row per commit that touched the path. + // (`{ measured, reason, files: [{ path, status, oldMode, mode }] }`), one row per commit that touched + // the path. Both ends are read: a symlink turned regular file can be called `modified`, so a regular + // mode at the head alone proves nothing, and any change of mode is H. const armPaths = paths.filter(underArm); if (armPaths.length > 0) { const catalog = reading.catalogFiles; @@ -2403,17 +2413,20 @@ export function lowRiskArmVerdict(matched, repo, reading = null) { const unread = []; const notModified = new Set(); const notRegular = new Set(); + const modeChanged = new Set(); for (const p of armPaths) { const rows = catalog.files.filter((f) => f?.path === p); if (rows.length === 0) unread.push(p); for (const r of rows) { if (r?.status !== 'modified') notModified.add(`${p} (${r?.status || 'no status'})`); - else if (!LOW_RISK_REGULAR_MODES.includes(String(r?.mode ?? ''))) notRegular.add(`${p} (${r?.mode ?? 'mode not read'})`); + else if (![r?.oldMode, r?.mode].every((m) => LOW_RISK_REGULAR_MODES.includes(String(m ?? '')))) notRegular.add(`${p} (${r?.oldMode ?? 'base mode not read'} to ${r?.mode ?? 'head mode not read'})`); + else if (r.oldMode !== r.mode) modeChanged.add(`${p} (${r.oldMode} to ${r.mode})`); } } if (unread.length > 0) reasons.push(`no status was read for ${more(unread, 4)}`); if (notModified.size > 0) reasons.push(`a catalog file added, deleted or renamed rather than modified: ${more([...notModified], 4)}`); - if (notRegular.size > 0) reasons.push(`a catalog path that is not a regular file: ${more([...notRegular], 4)}`); + if (notRegular.size > 0) reasons.push(`a catalog path that is not a regular file at both ends: ${more([...notRegular], 4)}`); + if (modeChanged.size > 0) reasons.push(`a catalog file whose mode changed: ${more([...modeChanged], 4)}`); } } const listed = new Set(paths); @@ -4258,37 +4271,47 @@ export function pullLowRiskReading(head, paths, { timeline = null, changesets = /** * Each changed file's STATUS off the API's file walk (`added`, `removed`, - * `modified`, `renamed`, ...), a rename's old name carried as `renamed` too. - * Pure; the mode is not on the API row, so `pullCatalogReading` reads it. + * `modified`, `renamed`, ...). A rename's old name is carried as `renamed`; + * any other row's `previous_filename` (a copy's source) as ` source`, + * never `modified`, so it reads H. Pure; the modes are not on the API row, so + * `pullCatalogReading` reads them. */ export function pullCatalogStatuses(files) { const out = []; for (const file of Array.isArray(files) ? files : []) { const status = typeof file?.status === 'string' ? file.status : ''; if (typeof file?.filename === 'string' && file.filename !== '') out.push({ path: file.filename, status }); - if (typeof file?.previous_filename === 'string' && file.previous_filename !== '') out.push({ path: file.previous_filename, status: 'renamed' }); + if (typeof file?.previous_filename === 'string' && file.previous_filename !== '') out.push({ path: file.previous_filename, status: status === 'renamed' ? 'renamed' : `${status || 'unread'} source` }); } return out; } /** * `--pr`'s status-and-mode reading for the arm: the API's status per path, and - * the mode of each modified catalog path at the PR's head from THIS checkout - * (`git ls-tree`). No statuses, or a head not here, is NOT MEASURED (Tier H). + * the mode of each modified catalog path at the merge base (`oldMode`) and at + * the PR's head (`mode`) from THIS checkout (`git ls-tree`) — the API's status + * alone cannot tell a symlink replaced by a regular file from an edit. No + * statuses, a head or base not here, or no merge base is NOT MEASURED (Tier H). */ export function pullCatalogReading({ derivation, statuses, paths, sameCheckout, run }) { const unmeasured = (reason) => ({ measured: false, reason, files: [] }); if (!Array.isArray(statuses)) return unmeasured('the file walk carried no status per file'); const headSha = derivation?.headSha; + const baseSha = derivation?.baseSha; if (!sameCheckout) return unmeasured('the PR is not in the repository this checkout holds, so its file modes cannot be read here'); - if (!isObjectId(headSha)) return unmeasured('the PR object named no head commit'); - if (!run(['cat-file', '-e', `${headSha}^{commit}`]).ok) return unmeasured(`${headSha.slice(0, 10)} is not in this checkout — \`git fetch origin pull/${derivation.pull}/head\``); + if (!isObjectId(headSha) || !isObjectId(baseSha)) return unmeasured('the PR object named no head or base commit'); + const missing = [headSha, baseSha].filter((sha) => !run(['cat-file', '-e', `${sha}^{commit}`]).ok); + if (missing.length > 0) return unmeasured(`${missing.map((sha) => sha.slice(0, 10)).join(' and ')} not in this checkout — \`git fetch origin pull/${derivation.pull}/head main\``); + const mergeBase = run(['merge-base', baseSha, headSha]); + if (!mergeBase.ok || !isObjectId(mergeBase.out)) return unmeasured('no merge base of the PR head and its base could be computed here (a shallow clone?)'); + const modeAt = (sha, path) => { + const tree = run(['ls-tree', sha, '--', path]); + return tree.ok ? (/^(\d{6}) /.exec(tree.out)?.[1] ?? null) : null; + }; const wanted = new Set((Array.isArray(paths) ? paths : []).filter((p) => GOVERNED_SURFACES.some((s) => s.lowRisk && p.startsWith(s.prefix)))); const files = statuses.filter((f) => wanted.has(f.path)).map((f) => { - if (f.status !== 'modified') return { ...f, mode: null }; - const tree = run(['ls-tree', headSha, '--', f.path]); - const mode = tree.ok ? (/^(\d{6}) /.exec(tree.out)?.[1] ?? null) : null; - return { ...f, mode }; + if (f.status !== 'modified') return { ...f, oldMode: null, mode: null }; + return { ...f, oldMode: modeAt(mergeBase.out, f.path), mode: modeAt(headSha, f.path) }; }); return { measured: true, reason: null, files }; } @@ -5822,7 +5845,7 @@ async function selfTest() { const CS = '.changeset/33501-skills-wording.md'; const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; // Every catalog path a MODIFIED regular file — the shape a wording PR has. - const catFiles = (paths, status = 'modified', mode = '100644') => paths.filter((p) => /^(?:ui\/)?skills\//.test(p)).map((path) => ({ path, status, mode })); + const catFiles = (paths, status = 'modified', mode = '100644') => paths.filter((p) => /^(?:ui\/)?skills\//.test(p)).map((path) => ({ path, status, oldMode: mode, mode })); const csFiles = (paths, text = CS_TEXT) => paths.filter((p) => LOW_RISK_CHANGESET_PATH.test(p)).map((path) => ({ path, text })); const read = (paths, over = {}) => ({ measured: true, reason: null, paths, body: 'Fixes #1\n\nClause-②: no\nMetadata-protocol: none\n', labels: [], @@ -5959,22 +5982,43 @@ async function selfTest() { assert('⛔ STATUS-deleting-a-skill-is-H-on-either-spelling', ['removed', 'deleted'].every((st) => tier([SK, CS], cat([SK, CS], [{ path: SK, status: st, mode: null }])) === GOVERNED_TIER_H)); assert('⛔ STATUS-a-rename-inside-the-catalog-is-H-both-sides', tier(['skills/a/x.md', 'skills/a/y.md', CS], cat(['skills/a/x.md', 'skills/a/y.md', CS], [{ path: 'skills/a/y.md', status: 'renamed', mode: '100644' }, { path: 'skills/a/x.md', status: 'renamed', mode: null }])) === GOVERNED_TIER_H); assert('⛔ STATUS-an-eval-added-in-one-commit-and-modified-in-the-next-is-H', tier(['skills/a/evals/e.json', CS], cat(['skills/a/evals/e.json', CS], [{ path: 'skills/a/evals/e.json', status: 'added', mode: '100644' }, { path: 'skills/a/evals/e.json', status: 'modified', mode: '100644' }])) === GOVERNED_TIER_H); - assert('⛔ STATUS-a-symlink-or-a-mode-not-read-is-H-an-executable-regular-file-is-not', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '120000' }])) === GOVERNED_TIER_H && /not a regular file: skills\/objectstack-data\/SKILL\.md \(120000\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '120000' }]))) && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: null }])) === GOVERNED_TIER_H && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '100755' }])) === GOVERNED_TIER_S); + assert('⛔ STATUS-a-symlink-or-a-mode-not-read-is-H-an-executable-regular-file-is-not', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '120000', mode: '120000' }])) === GOVERNED_TIER_H && /not a regular file at both ends: skills\/objectstack-data\/SKILL\.md \(120000 to 120000\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '120000', mode: '120000' }]))) && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '100644', mode: null }])) === GOVERNED_TIER_H && tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '100755', mode: '100755' }])) === GOVERNED_TIER_S); + // ⛔ N10 (record 6888217778): the API can call a symlink replaced by a regular file `modified`, so the + // BASE mode is read too, and any change of mode is H — a regular mode at the head alone proves nothing. + assert('⛔ MODE-a-symlink-turned-regular-file-called-modified-is-H-on-its-base-mode', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '120000', mode: '100644' }])) === GOVERNED_TIER_H && /not a regular file at both ends: skills\/objectstack-data\/SKILL\.md \(120000 to 100644\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', oldMode: '120000', mode: '100644' }])))); + assert('⛔ MODE-a-regular-file-made-executable-or-back-is-H-any-mode-change-is', ['100644', '100755'].every((from) => { const to = from === '100644' ? '100755' : '100644'; const c = cat([SK, CS], [{ path: SK, status: 'modified', oldMode: from, mode: to }]); return tier([SK, CS], c) === GOVERNED_TIER_H && new RegExp(`mode changed: skills/objectstack-data/SKILL\\.md \\(${from} to ${to}\\)`).test(reasons([SK, CS], c)); })); + assert('⛔ MODE-a-base-mode-not-read-is-H-the-head-mode-alone-never-reads-S', tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '100644' }])) === GOVERNED_TIER_H && /\(base mode not read to 100644\)/.test(reasons([SK, CS], cat([SK, CS], [{ path: SK, status: 'modified', mode: '100644' }])))); assert('⛔ STATUS-a-catalog-path-with-no-status-row-or-no-status-reading-is-H', tier([SK, CS], cat([SK, CS], [])) === GOVERNED_TIER_H && /no status was read for/.test(reasons([SK, CS], cat([SK, CS], []))) && tier([SK, CS], read([SK, CS], { catalogFiles: { measured: false, reason: 'not here', files: [] } })) === GOVERNED_TIER_H && tier([SK, CS], read([SK, CS], { catalogFiles: undefined })) === GOVERNED_TIER_H && tier([SK, CS], cat([SK, CS], [{ path: SK, status: '', mode: '100644' }])) === GOVERNED_TIER_H); assert('STATUS-a-changeset-or-docs-rider-ADDED-beside-a-modified-skill-stays-S-the-status-test-reads-catalog-paths-only', tier([SK, CS, 'docs/agents/new.md'], read([SK, CS, 'docs/agents/new.md'])) === GOVERNED_TIER_S); assert('pullCatalogStatuses-reads-each-status-and-a-renames-old-name', (() => { const st = pullCatalogStatuses([{ filename: 'a.md', status: 'modified' }, { filename: 'b.md', status: 'renamed', previous_filename: 'c.md' }, { filename: 'd.md' }]); return JSON.stringify(st) === JSON.stringify([{ path: 'a.md', status: 'modified' }, { path: 'b.md', status: 'renamed' }, { path: 'c.md', status: 'renamed' }, { path: 'd.md', status: '' }]); })()); - assert('pullCatalogReading-reads-the-mode-of-each-modified-catalog-file-at-the-head-or-is-NOT-MEASURED', (() => { + // N10: a copy's source is not renamed — it is carried as `copied source`, never `modified`, so still H. + assert('⛔ pullCatalogStatuses-carries-a-copys-source-as-copied-source-never-renamed-or-modified-and-it-reads-H', (() => { + const st = pullCatalogStatuses([{ filename: 'skills/a/new.md', status: 'copied', previous_filename: SK }, { filename: 'e.md', status: 'modified', previous_filename: 'f.md' }]); + return JSON.stringify(st) === JSON.stringify([{ path: 'skills/a/new.md', status: 'copied' }, { path: SK, status: 'copied source' }, { path: 'e.md', status: 'modified' }, { path: 'f.md', status: 'modified source' }]) && + tier([SK, CS], cat([SK, CS], [{ path: SK, status: 'copied source', oldMode: '100644', mode: '100644' }])) === GOVERNED_TIER_H; + })()); + assert('pullCatalogReading-reads-the-mode-of-each-modified-catalog-file-at-the-merge-base-and-the-head-or-is-NOT-MEASURED', (() => { const Hd = 'a'.repeat(40); - const run = (argv) => (argv[0] === 'cat-file' ? { ok: true, out: '' } : argv[0] === 'ls-tree' ? { ok: true, out: `${argv[3] === SK ? '120000' : '100644'} blob ${'f'.repeat(40)}\t${argv[3]}` } : { ok: false, out: '' }); + const Bs = 'b'.repeat(40); + const Mb = 'c'.repeat(40); + // SK was a symlink at the merge base and is a regular file at the head: the API calls it `modified`. + const modeOf = (sha, p) => (p === SK ? (sha === Mb ? '120000' : '100644') : '100644'); + const run = (argv) => (argv[0] === 'cat-file' ? { ok: true, out: '' } : argv[0] === 'merge-base' ? { ok: true, out: Mb } : argv[0] === 'ls-tree' ? { ok: true, out: `${modeOf(argv[1], argv[3])} blob ${'f'.repeat(40)}\t${argv[3]}` } : { ok: false, out: '' }); const statuses = [{ path: SK, status: 'modified' }, { path: UISK, status: 'modified' }, { path: 'skills/a/new.md', status: 'added' }, { path: CS, status: 'added' }]; - const r = pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK, UISK, 'skills/a/new.md', CS], sameCheckout: true, run }); - return r.measured === true && r.files.length === 3 && r.files[0].mode === '120000' && r.files[1].mode === '100644' && r.files[2].mode === null && - pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: false, run }).measured === false && - pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses: null, paths: [SK], sameCheckout: true, run }).measured === false && - pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: true, run: () => ({ ok: false, out: '' }) }).measured === false; + const derivation = { headSha: Hd, baseSha: Bs, pull: 2 }; + const r = pullCatalogReading({ derivation, statuses, paths: [SK, UISK, 'skills/a/new.md', CS], sameCheckout: true, run }); + const noBase = pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: true, run: (argv) => (argv[0] === 'cat-file' && argv[2] === `${Bs}^{commit}` ? { ok: false, out: '' } : run(argv)) }); + return r.measured === true && r.files.length === 3 && r.files[0].oldMode === '120000' && r.files[0].mode === '100644' && r.files[1].oldMode === '100644' && r.files[1].mode === '100644' && r.files[2].mode === null && r.files[2].oldMode === null && + tier([SK, CS], read([SK, CS], { catalogFiles: pullCatalogReading({ derivation, statuses, paths: [SK, CS], sameCheckout: true, run }) })) === GOVERNED_TIER_H && + noBase.measured === false && /bbbbbbbbbb not in this checkout/.test(noBase.reason) && + pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: true, run }).measured === false && + pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: true, run: (argv) => (argv[0] === 'merge-base' ? { ok: false, out: '' } : run(argv)) }).measured === false && + pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: false, run }).measured === false && + pullCatalogReading({ derivation, statuses: null, paths: [SK], sameCheckout: true, run }).measured === false && + pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: true, run: () => ({ ok: false, out: '' }) }).measured === false; })()); assert('LOW_RISK_ARM_FILE_PATTERNS-are-frozen-and-two', Object.isFrozen(LOW_RISK_ARM_FILE_PATTERNS) && LOW_RISK_ARM_FILE_PATTERNS.length === 2); assert('pullChangesetReading-reads-each-changeset-at-the-head-or-is-NOT-MEASURED', (() => { diff --git a/scripts/pm/check-governed-queue-guard.mjs b/scripts/pm/check-governed-queue-guard.mjs index c40c18374a9..d024a0a2957 100644 --- a/scripts/pm/check-governed-queue-guard.mjs +++ b/scripts/pm/check-governed-queue-guard.mjs @@ -672,7 +672,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ '⭐ the 2026-10-26 ENQUEUE leg: an authorized enqueuer is the human review': 28, '⭐ the cheap early-warning leg: commits and trees, toolchain on demand': 20, '⭐ the workflows split at the queue (ruling record 6722205630)': 30, - '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 52, + '⚖️ the low-risk skills arm at the queue: body, labels and every path, read off the pull this leg holds (#33501)': 54, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -1924,11 +1924,17 @@ export function renderGuardVerdict(verdict) { * Re-read one governed entry's tier with the low-risk skills arm's reading * (#33501): `paths` = every path of the PR's commits (`allPaths`); the body, * labels and fork predicate off the pull object the queue leg read; the timeline - * the enqueue leg read (`timeline`: `{ measured, reason, events }`); and each - * changeset at the commit that touched it, read with `runGit`. An entry with no - * catalog row is left untouched; `pull` null (its read failed) is an UNMEASURED - * reading, so the entry stays Tier H with the reason printed, and so is a - * missing timeline, fork reading or git reader. + * the enqueue leg read (`timeline`: `{ measured, reason, events }`); each + * changeset at the commit that touched it, read with `runGit`; and the status + * and both modes of every path of every governed commit (`catalogFilesOf`). + * `lowRiskArmVerdict` then holds all of its conditions: catalog rows only, an + * allowlisted path list, the bare declarations in the body and in clean + * changesets, no `security` label now or removed, no catalog path named for + * security, auth or permission, every catalog file a modified regular file with + * its mode unchanged, and no fork. An entry with no catalog row is left + * untouched; `pull` null (its read failed) is an UNMEASURED reading, so the + * entry stays Tier H with the reason printed, and so is a missing timeline, + * fork reading, status reading or git reader. * ⛔ The tier comes from the register's own `governedTierFor` and * `applyLowRiskArm` — no second predicate here. Mutates `entry` (its `surfaces` * and `tier`); returns it. @@ -1972,10 +1978,12 @@ export function readLowRiskTier(entry, repo, pull, { timeline = null, runGit = n const RAW_STATUS = Object.freeze({ M: 'modified', A: 'added', D: 'deleted', T: 'type-changed', R: 'renamed', C: 'copied' }); /** - * The status and mode of every path each governed commit of the entry touched, - * read with `git diff-tree -r --raw -z --no-renames` against the commit's first - * parent (the same comparison `enumerateRows` lists the paths from). One row per - * commit per path, so an add in one commit and an edit in the next reads `added`. + * The status and both modes of every path each governed commit of the entry + * touched, read with `git diff-tree -r --raw -z --no-renames` against the + * commit's first parent (the same comparison `enumerateRows` lists the paths + * from): `{ path, status, oldMode, mode }`, the raw line's two modes, so a mode + * change reads H in the arm. One row per commit per path, so an add in one + * commit and an edit in the next reads `added`. * No git reader, a commit with no sha, or a read that throws is NOT MEASURED. */ export function catalogFilesOf(entry, runGit) { @@ -1994,7 +2002,7 @@ export function catalogFilesOf(entry, runGit) { for (let i = 0; i + 1 < tokens.length; i += 2) { const meta = /^:(\d{6}) (\d{6}) [0-9a-f]+ [0-9a-f]+ ([A-Z])/.exec(tokens[i].trim()); if (!meta || tokens[i + 1] === '') continue; - files.push({ path: tokens[i + 1], status: RAW_STATUS[meta[3]] ?? meta[3], mode: meta[2] }); + files.push({ path: tokens[i + 1], status: RAW_STATUS[meta[3]] ?? meta[3], oldMode: meta[1], mode: meta[2] }); } } return { measured: true, reason: null, files }; @@ -5774,7 +5782,7 @@ export async function selfTest() { const CS_TEXT = "---\n'@objectstack/skills': patch\n---\n\nskills: wording\n\nClause-②: no\nMetadata-protocol: none\n"; // The committed changeset text, by `git show :`; any other read throws, as git does. // `diff-tree --raw -z` rows: every path the fixtures touch, a MODIFIED regular file unless a case says otherwise. - const rawOf = (rows) => rows.map(([st, mode, p]) => `:100644 ${mode} ${'1'.repeat(40)} ${'2'.repeat(40)} ${st}\0${p}\0`).join(''); + const rawOf = (rows) => rows.map(([st, mode, p, oldMode = '100644']) => `:${oldMode} ${mode} ${'1'.repeat(40)} ${'2'.repeat(40)} ${st}\0${p}\0`).join(''); const MODIFIED = rawOf([SK, 'skills/objectstack-data/evals/evals.json', 'skills/objectstack-data/rules/security.md', 'skills/a/rules/guide.md', 'skills/a/rules/permission-guide.md', 'skills/a/rules/security.md', 'skills/objectstack-data/hook.mjs'].map((p) => ['M', '100644', p]).concat([['A', '100644', CS]])); const csGit = (text = CS_TEXT, raw = MODIFIED) => (args) => { if (args[0] === 'show' && /^[0-9a-f]{40}:\.changeset\//.test(args[1]) && text !== null) return text; @@ -5934,6 +5942,10 @@ export async function selfTest() { assert('⛔ STATUS-a-skill-DELETED-in-the-group-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['D', '000000', SK], ['A', '100644', CS]])) })) === H); assert('⛔ STATUS-a-rename-read-as-delete-plus-add-under-no-renames-stays-H', JSON.stringify(await hCase({ files: ['skills/a/rules/guide.md', 'skills/a/rules/howto.md', CS], runGit: csGit(CS_TEXT, rawOf([['D', '000000', 'skills/a/rules/guide.md'], ['A', '100644', 'skills/a/rules/howto.md'], ['A', '100644', CS]])) })) === H); assert('⛔ STATUS-a-SYMLINK-under-the-catalog-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['M', '120000', SK], ['A', '100644', CS]])) })) === H); + // N10 (record 6888217778): the raw line's OLD mode is read too — a symlink turned regular file, however its + // status letter reads, and a regular file made executable both change the mode, and any mode change is H. + assert('⛔ MODE-a-symlink-turned-regular-file-stays-H-on-its-old-mode-as-M-or-as-T', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['M', '100644', SK, '120000'], ['A', '100644', CS]])) })) === H && JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['T', '100644', SK, '120000'], ['A', '100644', CS]])) })) === H); + assert('⛔ MODE-a-regular-file-made-executable-stays-H-and-catalogFilesOf-carries-both-modes', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['M', '100755', SK], ['A', '100644', CS]])) })) === H && JSON.stringify(catalogFilesOf({ shas: ['a'.repeat(40)] }, csGit(CS_TEXT, rawOf([['M', '100755', SK]]))).files) === JSON.stringify([{ path: SK, status: 'modified', oldMode: '100644', mode: '100755' }])); assert('⛔ STATUS-a-status-read-that-throws-or-misses-the-path-stays-H', JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, null) })) === H && JSON.stringify(await hCase({ runGit: csGit(CS_TEXT, rawOf([['A', '100644', CS]])) })) === H); assert('catalogFilesOf-reads-status-and-mode-per-commit-and-fails-closed', (() => { const e = { shas: ['a'.repeat(40), 'b'.repeat(40)] }; diff --git a/scripts/pm/record-recognisers.mjs b/scripts/pm/record-recognisers.mjs index 948032c0f3b..3bbb6f8334f 100644 --- a/scripts/pm/record-recognisers.mjs +++ b/scripts/pm/record-recognisers.mjs @@ -118,7 +118,7 @@ import { // The governed-rules face is the governed register itself — the same function the queue guard // classifies a merge group's paths with. `dispatch-gates.mjs` already imports this module at module // scope, so the edge adds no new module to this file's graph and no cycle. -import { SELF_REPO_ID, governedPathsIn } from './check-governed-merges.mjs'; +import { SELF_REPO_ID, governedPathsIn, lowRiskRowHit } from './check-governed-merges.mjs'; // How an unreadable `Served-tier:` line is quoted back — the declaration // line's own quoting helper, one spelling for both. The narrowing face is read // with the fleet's ONE reader of that line, imported, ⛔ never a second parser. @@ -2169,6 +2169,13 @@ export function contractReviewBriefLines(values = {}) { ] : []), '', ]; + // A `hits` path on the low-risk skills arm lands on this record alone (#33501, ruling B): the arm reads + // the `security` label and the path's name, so teaching the name does not show is the reviewer's to label. + const lowRiskLines = scopeHits !== undefined && lowRiskRowHit(scopeHits) ? [ + 'Security — a `hits` path sits on the low-risk skills arm: the contract reviewer adds the `security` label', + " when the change teaches security, auth or permission behaviour the path name doesn't show, and the record says so.", + '', + ] : []; return [ 'record-recognisers --brief-template — the brief a seat hands its contract reviewer, copyable. The', "read-only shape is built in: keep every ⛔ line, they are the review's shape and not advice to it.", @@ -2189,6 +2196,7 @@ export function contractReviewBriefLines(values = {}) { "⛔ Not the dispatch order, ⛔ not the dispatching seat's own conclusions — this brief is adversarial by design.", '', ...scopeLines, + ...lowRiskLines, '⛔ READ-ONLY. No worktree, no checkout, no build, no test run, no gate re-run, no ablation: the check-runs', ' on the head already answered every derived gate family, and a local run costs more than it returns.', " If ONE probe is unavoidable, the record's `Local-runs:` line says `probe — REASON`; otherwise `none`.", @@ -2368,7 +2376,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the reviewer BRIEF template — the read-only shape a hand-written brief dropped, built in and printed': 23, '⭐ B′ with C: the review tier FOLLOWS THE FACE that made it owed — exact, never a floor': 23, '⭐ B′ with C: a PROSE-ONLY head move keeps the record, decided on the COMMITTED trees like a regeneration': 6, - '⭐ letter C: the at-tier review of a mixed diff is SCOPED — `hits` plus what they claim, on the `Scope:` line': 19, + '⭐ letter C: the at-tier review of a mixed diff is SCOPED — `hits` plus what they claim, on the `Scope:` line': 21, '⭐ letter B: a declared NARROWING is a face of its own at CONTRACT_REVIEW_TIER — keyed on the `Clause-②:` line, exact': 17, '⭐ the `Contract-review-handoff:` line — names the current head ⇒ the named review or sibling seat\'s review; head moved ⇒ stale; absent ⇒ the seat\'s own; `triage` unreadable': 17, // Raised 27 → 40 with the scenario table's seven admitted keys and the `seat-online` patrol field: one pin @@ -2674,6 +2682,11 @@ export async function selfTest() { t('⛔ the declaration-face brief states none', !says(contractReviewBriefLines({ face: 'declaration' }).join('\n'), '`Scope:` line')); t('⭐ the brief over `paths` names the hits and hands the reviewer `--template --paths` over THEM — which reads back the same face and floor', (() => { const b = contractReviewBriefLines({ paths: MIXED }).join('\n'); const hits = reviewScopeHits(MIXED); return says(b, `file list: ${hits.join(', ')};`) && says(b, `--template --paths ${hits.join(' ')}\``) && fenced(contractReviewTemplateLines({ paths: hits })) === fenced(contractReviewTemplateLines({ paths: MIXED })); })()); t('…and over a declaration-only list it hands `--face declaration`, as the face table would', says(contractReviewBriefLines({ paths: DECL_PATHS }).join('\n'), '--template --face declaration`') && contractReviewBriefLines({ paths: DECL_PATHS }).join('\n') === contractReviewBriefLines({ face: 'declaration' }).join('\n')); + // #33501 ruling B: the low-risk arm reads the `security` label and the path's name, so the brief over a + // catalog path hands the reviewer the label duty for teaching the name does not show. + const SECURITY_DUTY = 'the contract reviewer adds the `security` label'; + t('⭐ the brief over a low-risk skills path hands the reviewer the `security` label duty, on either catalog row and through the CLI', (() => { const own = ['skills/objectstack-data/SKILL.md', 'ui/skills/objectui-forms/SKILL.md']; return own.every((p) => says(contractReviewBriefLines({ paths: [p, ...DECL_PATHS] }).join('\n'), SECURITY_DUTY)) && says(faceCli(['--brief-template', '--paths', own[0]]).stdout, "behaviour the path name doesn't show, and the record says so"); })()); + t('⛔ …and no other brief carries it — a mixed list off the arm, the declaration face, the default brief', [contractReviewBriefLines({ paths: MIXED }), contractReviewBriefLines({ face: 'declaration' }), contractReviewBriefLines(), contractReviewBriefLines({ face: 'narrowing' })].every((b) => !says(b.join('\n'), SECURITY_DUTY))); t('⭐ `--template --paths` and `--brief-template --paths` print exactly the function output and exit 0', (() => { const a = faceCli(['--template', '--paths', ...MIXED]); const b = faceCli(['--brief-template', '--paths', ...MIXED]); return a.status === 0 && a.stdout === `${contractReviewTemplateLines({ paths: MIXED }).join('\n')}\n` && b.status === 0 && b.stdout === `${contractReviewBriefLines({ paths: MIXED }).join('\n')}\n`; })()); t('⛔ `--paths` naming no path, or beside `--face` in either order, is REFUSED with the usage, exit 1', [['--template', '--paths'], ['--template', '--paths', RULES_PATH, '--face', 'rules'], ['--brief-template', '--face', 'rules', '--paths', RULES_PATH], ['--template', '--paths', '']].every((args) => { const r = faceCli(args); return r.status === 1 && says(r.stderr, 'usage:'); })); t('…and the usage names the flag, the face it reads and the line it fills', ['--paths PATH...', '`reviewFace`', '`Scope:`'].every((s) => usageLines().join('\n').includes(s))); From 9eafdc7cb0f493f174af8c28a92bddd370e1e99a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 03:31:23 +0000 Subject: [PATCH 10/10] pm: the bare reviewer brief carries the security duty, the seat adds the label, and the fetch hint names the base ref The reviewer brief built without `--paths` (the spelling the skill teaches) now prints the security duty in a conditional form, so a skills PR's brief never drops it. An isolated reviewer cannot label, so the line says the record flags the teaching and the seat adopting it adds the `security` label; PD 14 and the register's comments say the same. The NOT MEASURED fetch hint names the PR's own base ref, or its sha, never an assumed `main`. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5pF46HJnpBrhgVWtwV --- AGENTS.md | 2 +- scripts/pm/check-governed-merges.mjs | 31 ++++++++++++++++++++++------ scripts/pm/record-recognisers.mjs | 26 ++++++++++++++++------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d9574ebdd3e..3362b82af11 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -287,7 +287,7 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas. (人合: every row outside Tier S): those four lift only for an authorized APPROVED review by an account in `GOVERNED_APPROVERS`, on ANY commit and not dismissed; that word is spent once per PR — the OWNING seat then lands it, later pushes included; the click stays the maintainer's. **Tier S** (席内达档复核落地: `.claude/**`, - objectstack workflow edits (`readWorkflowDiff`) and skills-only wording (`lowRiskArmVerdict`; the reviewer labels + objectstack workflow edits (`readWorkflowDiff`) and skills-only wording (`lowRiskArmVerdict`; the seat labels unnamed security teaching) read as S): those four lift once the PR thread or its card carries a `## Contract review` record for the PR's current head with `Served-tier: CONTRACT_REVIEW_TIER` and a PASS verdict and every check is green — the owning seat lands it through the queue; the post-merge audit is the compensating control. A PR whose diff --git a/scripts/pm/check-governed-merges.mjs b/scripts/pm/check-governed-merges.mjs index 2ba17238730..6fbe8e16915 100644 --- a/scripts/pm/check-governed-merges.mjs +++ b/scripts/pm/check-governed-merges.mjs @@ -499,8 +499,9 @@ * - the labels were read and none is `security`, and the timeline was read and * never removed one; and no catalog path names security, auth or permission * (`LOW_RISK_SECURITY_NAME`, any segment below the row, any case) — the label - * OR the name sends the PR to H; security teaching the name cannot see is the - * contract reviewer's to label `security`; + * OR the name sends the PR to H; security teaching the name cannot see is + * flagged in the contract review's record and labelled `security` by the + * seat adopting it (the reviewer brief says so); * - the head lives in the base repository (`forkVerdict`); * - every catalog path is a MODIFIED regular file with the same mode at both ends * — an added, deleted, renamed or copied skill or eval, a symlink, a mode change @@ -2273,7 +2274,8 @@ export const LOW_RISK_ARM_FILE_PATTERNS = Object.freeze([/\.md$/, /(?:^|\/)evals * skill FOLDER named for it counts as well as a file — says security, auth or * permission (any case) keeps the PR H, with or without the label. A segment * rather than the basename alone, because a security skill's entry file is - * `SKILL.md`. Teaching the name cannot see is the contract reviewer's to label. + * `SKILL.md`. Teaching the name cannot see is flagged in the review's record and + * labelled by the seat adopting it. */ export const LOW_RISK_SECURITY_NAME = /security|auth|permission/i; @@ -4235,6 +4237,7 @@ export async function fetchPullFiles({ apiUrl, slug, pull, channels, fetchImpl = pull, headSha: sha, baseSha: typeof head?.base?.sha === 'string' ? head.base.sha : null, + baseRef: typeof head?.base?.ref === 'string' && head.base.ref !== '' ? head.base.ref : null, endpoint: `/repos/${slug}/pulls/${pull}/files`, channel: chosen.id, pages, @@ -4301,7 +4304,7 @@ export function pullCatalogReading({ derivation, statuses, paths, sameCheckout, if (!sameCheckout) return unmeasured('the PR is not in the repository this checkout holds, so its file modes cannot be read here'); if (!isObjectId(headSha) || !isObjectId(baseSha)) return unmeasured('the PR object named no head or base commit'); const missing = [headSha, baseSha].filter((sha) => !run(['cat-file', '-e', `${sha}^{commit}`]).ok); - if (missing.length > 0) return unmeasured(`${missing.map((sha) => sha.slice(0, 10)).join(' and ')} not in this checkout — \`git fetch origin pull/${derivation.pull}/head main\``); + if (missing.length > 0) return unmeasured(`${missing.map((sha) => sha.slice(0, 10)).join(' and ')} not in this checkout — ${pullFetchHint(derivation, missing)}`); const mergeBase = run(['merge-base', baseSha, headSha]); if (!mergeBase.ok || !isObjectId(mergeBase.out)) return unmeasured('no merge base of the PR head and its base could be computed here (a shallow clone?)'); const modeAt = (sha, path) => { @@ -4316,6 +4319,21 @@ export function pullCatalogReading({ derivation, statuses, paths, sameCheckout, return { measured: true, reason: null, files }; } +/** + * The fetch that brings a PR's missing commits into this checkout: the head by + * `pull/N/head`, the base by the PR's own base ref — never an assumed `main`, + * since a PR can target any branch — or by its sha when the ref was not read. + * Pure. + */ +export function pullFetchHint(derivation, missing) { + const want = new Set(Array.isArray(missing) ? missing : []); + const refs = [ + want.has(derivation?.headSha) ? `pull/${derivation?.pull}/head` : null, + want.has(derivation?.baseSha) ? (derivation?.baseRef ?? derivation?.baseSha) : null, + ].filter(Boolean); + return `\`git fetch origin ${refs.join(' ')}\``; +} + /** Does any of these paths sit under a register row that carries the low-risk arm? Pure. */ export function lowRiskRowHit(paths) { const list = Array.isArray(paths) ? paths : []; @@ -4900,7 +4918,7 @@ export function pullWorkflowDiff({ derivation, paths, sameCheckout, run, git: re if (!sameCheckout) return unmeasured('the PR is not in the repository this checkout holds, so its commits cannot be read here'); if (!isObjectId(headSha) || !isObjectId(baseSha)) return unmeasured('the PR object named no head or base commit'); const missing = [headSha, baseSha].filter((sha) => !run(['cat-file', '-e', `${sha}^{commit}`]).ok); - if (missing.length > 0) return unmeasured(`${missing.map((sha) => sha.slice(0, 10)).join(' and ')} not in this checkout — \`git fetch origin pull/${derivation.pull}/head main\``); + if (missing.length > 0) return unmeasured(`${missing.map((sha) => sha.slice(0, 10)).join(' and ')} not in this checkout — ${pullFetchHint(derivation, missing)}`); const mergeBase = run(['merge-base', baseSha, headSha]); if (!mergeBase.ok || !isObjectId(mergeBase.out)) return unmeasured('no merge base of the PR head and its base could be computed here (a shallow clone?)'); return readWorkflowDiff({ paths, base: mergeBase.out, head: headSha, git: readGit }); @@ -6013,7 +6031,8 @@ async function selfTest() { const noBase = pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: true, run: (argv) => (argv[0] === 'cat-file' && argv[2] === `${Bs}^{commit}` ? { ok: false, out: '' } : run(argv)) }); return r.measured === true && r.files.length === 3 && r.files[0].oldMode === '120000' && r.files[0].mode === '100644' && r.files[1].oldMode === '100644' && r.files[1].mode === '100644' && r.files[2].mode === null && r.files[2].oldMode === null && tier([SK, CS], read([SK, CS], { catalogFiles: pullCatalogReading({ derivation, statuses, paths: [SK, CS], sameCheckout: true, run }) })) === GOVERNED_TIER_H && - noBase.measured === false && /bbbbbbbbbb not in this checkout/.test(noBase.reason) && + noBase.measured === false && /bbbbbbbbbb not in this checkout — `git fetch origin bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`$/.test(noBase.reason) && + pullCatalogReading({ derivation: { ...derivation, baseRef: 'release/v4' }, statuses, paths: [SK], sameCheckout: true, run: () => ({ ok: false, out: '' }) }).reason.endsWith('`git fetch origin pull/2/head release/v4`') && pullCatalogReading({ derivation: { headSha: Hd, pull: 2 }, statuses, paths: [SK], sameCheckout: true, run }).measured === false && pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: true, run: (argv) => (argv[0] === 'merge-base' ? { ok: false, out: '' } : run(argv)) }).measured === false && pullCatalogReading({ derivation, statuses, paths: [SK], sameCheckout: false, run }).measured === false && diff --git a/scripts/pm/record-recognisers.mjs b/scripts/pm/record-recognisers.mjs index 3bbb6f8334f..7b59b679077 100644 --- a/scripts/pm/record-recognisers.mjs +++ b/scripts/pm/record-recognisers.mjs @@ -2170,10 +2170,18 @@ export function contractReviewBriefLines(values = {}) { '', ]; // A `hits` path on the low-risk skills arm lands on this record alone (#33501, ruling B): the arm reads - // the `security` label and the path's name, so teaching the name does not show is the reviewer's to label. - const lowRiskLines = scopeHits !== undefined && lowRiskRowHit(scopeHits) ? [ - 'Security — a `hits` path sits on the low-risk skills arm: the contract reviewer adds the `security` label', - " when the change teaches security, auth or permission behaviour the path name doesn't show, and the record says so.", + // the `security` label and the path's name, so teaching the name does not show must be flagged here. An + // isolated reviewer cannot label, so the record says so and the adopting seat adds the label. With no + // `--paths` the brief cannot know the hits, and the skill teaches the bare `--brief-template`, so every + // at-tier brief over unknown paths carries the duty in its conditional form. + const securityDuty = " behaviour the path name doesn't show, the record says so and the seat adopting the record adds the `security` label."; + const lowRiskLines = scopeHits !== undefined ? (lowRiskRowHit(scopeHits) ? [ + 'Security — a `hits` path sits on the low-risk skills arm: when the change teaches security, auth or permission', + securityDuty, + '', + ] : []) : atTier && face?.id !== 'narrowing' ? [ + 'Security — if a `hits` path is under `skills/**` or `ui/skills/**` and the change teaches security, auth or permission', + securityDuty, '', ] : []; return [ @@ -2376,7 +2384,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'the reviewer BRIEF template — the read-only shape a hand-written brief dropped, built in and printed': 23, '⭐ B′ with C: the review tier FOLLOWS THE FACE that made it owed — exact, never a floor': 23, '⭐ B′ with C: a PROSE-ONLY head move keeps the record, decided on the COMMITTED trees like a regeneration': 6, - '⭐ letter C: the at-tier review of a mixed diff is SCOPED — `hits` plus what they claim, on the `Scope:` line': 21, + '⭐ letter C: the at-tier review of a mixed diff is SCOPED — `hits` plus what they claim, on the `Scope:` line': 22, '⭐ letter B: a declared NARROWING is a face of its own at CONTRACT_REVIEW_TIER — keyed on the `Clause-②:` line, exact': 17, '⭐ the `Contract-review-handoff:` line — names the current head ⇒ the named review or sibling seat\'s review; head moved ⇒ stale; absent ⇒ the seat\'s own; `triage` unreadable': 17, // Raised 27 → 40 with the scenario table's seven admitted keys and the `seat-online` patrol field: one pin @@ -2684,9 +2692,11 @@ export async function selfTest() { t('…and over a declaration-only list it hands `--face declaration`, as the face table would', says(contractReviewBriefLines({ paths: DECL_PATHS }).join('\n'), '--template --face declaration`') && contractReviewBriefLines({ paths: DECL_PATHS }).join('\n') === contractReviewBriefLines({ face: 'declaration' }).join('\n')); // #33501 ruling B: the low-risk arm reads the `security` label and the path's name, so the brief over a // catalog path hands the reviewer the label duty for teaching the name does not show. - const SECURITY_DUTY = 'the contract reviewer adds the `security` label'; - t('⭐ the brief over a low-risk skills path hands the reviewer the `security` label duty, on either catalog row and through the CLI', (() => { const own = ['skills/objectstack-data/SKILL.md', 'ui/skills/objectui-forms/SKILL.md']; return own.every((p) => says(contractReviewBriefLines({ paths: [p, ...DECL_PATHS] }).join('\n'), SECURITY_DUTY)) && says(faceCli(['--brief-template', '--paths', own[0]]).stdout, "behaviour the path name doesn't show, and the record says so"); })()); - t('⛔ …and no other brief carries it — a mixed list off the arm, the declaration face, the default brief', [contractReviewBriefLines({ paths: MIXED }), contractReviewBriefLines({ face: 'declaration' }), contractReviewBriefLines(), contractReviewBriefLines({ face: 'narrowing' })].every((b) => !says(b.join('\n'), SECURITY_DUTY))); + const SECURITY_DUTY = 'the seat adopting the record adds the `security` label'; + const SECURITY_IF = 'if a `hits` path is under `skills/**` or `ui/skills/**`'; + t('⭐ the brief over a low-risk skills path hands the `security` label duty, unconditionally, on either catalog row and through the CLI — the record says so, the adopting seat labels', (() => { const own = ['skills/objectstack-data/SKILL.md', 'ui/skills/objectui-forms/SKILL.md']; return own.every((p) => { const b = contractReviewBriefLines({ paths: [p, ...DECL_PATHS] }).join('\n'); return says(b, SECURITY_DUTY) && says(b, 'sits on the low-risk skills arm') && !says(b, SECURITY_IF); }) && says(faceCli(['--brief-template', '--paths', own[0]]).stdout, "behaviour the path name doesn't show, the record says so") && !says(contractReviewBriefLines({ paths: [own[0]] }).join('\n'), 'reviewer adds'); })()); + t('⭐ SF5: the bare `--brief-template` and `--face rules` brief — the spelling the skill teaches — carry the duty in its CONDITIONAL form', (() => { const forms = [contractReviewBriefLines(), contractReviewBriefLines({ face: 'rules' }), contractReviewBriefLines({ face: 'schema' })].map((b) => b.join('\n')); return forms.every((b) => says(b, SECURITY_IF) && says(b, SECURITY_DUTY)) && says(faceCli(['--brief-template']).stdout, SECURITY_IF) && says(faceCli(['--brief-template', '--face', 'rules']).stdout, SECURITY_IF); })()); + t('⛔ …and a brief whose `hits` are known and off the arm carries none, nor does the declaration or the narrowing face', [contractReviewBriefLines({ paths: MIXED }), contractReviewBriefLines({ face: 'declaration' }), contractReviewBriefLines({ face: 'narrowing' })].every((b) => !says(b.join('\n'), SECURITY_DUTY))); t('⭐ `--template --paths` and `--brief-template --paths` print exactly the function output and exit 0', (() => { const a = faceCli(['--template', '--paths', ...MIXED]); const b = faceCli(['--brief-template', '--paths', ...MIXED]); return a.status === 0 && a.stdout === `${contractReviewTemplateLines({ paths: MIXED }).join('\n')}\n` && b.status === 0 && b.stdout === `${contractReviewBriefLines({ paths: MIXED }).join('\n')}\n`; })()); t('⛔ `--paths` naming no path, or beside `--face` in either order, is REFUSED with the usage, exit 1', [['--template', '--paths'], ['--template', '--paths', RULES_PATH, '--face', 'rules'], ['--brief-template', '--face', 'rules', '--paths', RULES_PATH], ['--template', '--paths', '']].every((args) => { const r = faceCli(args); return r.status === 1 && says(r.stderr, 'usage:'); })); t('…and the usage names the flag, the face it reads and the line it fills', ['--paths PATH...', '`reviewFace`', '`Scope:`'].every((s) => usageLines().join('\n').includes(s)));