From 237ed1895a955161829ebb7bc86095fa5183df3a Mon Sep 17 00:00:00 2001 From: Daniel Ochoa Date: Thu, 3 Dec 2026 15:42:29 -0600 Subject: [PATCH 1/2] ISS-15124: Ask the user before opening a PR with unrun CI checks; ISS-15125: Apply the proof cutoff to decision-table mutants --- CHANGELOG.md | 11 ++ .../.claude-plugin/plugin.json | 2 +- .../vibe-closedloop/.codex-plugin/plugin.json | 2 +- plugins/vibe-closedloop/README.md | 2 +- .../vibe-closedloop/hooks/pr-create-guard.mjs | 49 +++++--- .../hooks/skill-transcript.mjs | 21 ++++ .../lib/handoff/scripts/full-ci-check.mjs | 34 ++++-- .../lib/handoff/scripts/proof-receipts.mjs | 44 +++++-- .../lib/handoff/scripts/proof-scope.mjs | 2 +- .../lib/handoff/scripts/refusing-checks.mjs | 16 ++- .../skills/fleet-orchestrator/SKILL.md | 2 + plugins/vibe-closedloop/skills/vibe/SKILL.md | 9 +- .../skills/vibe/scripts/pre-pr-lanes.mjs | 12 +- .../skills/vibe/scripts/session-questions.mjs | 98 +++++++++++++-- plugins/vibe/.claude-plugin/plugin.json | 2 +- plugins/vibe/.codex-plugin/plugin.json | 2 +- plugins/vibe/README.md | 2 +- plugins/vibe/hooks/pr-create-full-ci.test.mjs | 114 ++++++++++++++++-- plugins/vibe/hooks/pr-create-guard.mjs | 49 +++++--- plugins/vibe/hooks/skill-transcript.mjs | 21 ++++ .../lib/handoff/scripts/full-ci-check.mjs | 34 ++++-- .../lib/handoff/scripts/proof-receipts.mjs | 44 +++++-- .../vibe/lib/handoff/scripts/proof-scope.mjs | 2 +- .../lib/handoff/scripts/proof-scope.test.mjs | 20 +++ .../lib/handoff/scripts/refusing-checks.mjs | 16 ++- .../handoff/scripts/refusing-checks.test.mjs | 2 +- .../vibe/skills/fleet-orchestrator/SKILL.md | 2 + .../scripts/board-push-proof.test.mjs | 4 +- plugins/vibe/skills/vibe/SKILL.md | 9 +- .../vibe/skills/vibe/scripts/pre-pr-lanes.mjs | 12 +- .../skills/vibe/scripts/session-questions.mjs | 98 +++++++++++++-- .../python/test_pr_takeover_skill_contract.py | 2 +- .../python/test_vibe_ws8_load_contract.py | 4 +- 33 files changed, 600 insertions(+), 143 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4b3a69..138fef18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to the claude-plugins project will be documented in this fil The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Entries are listed newest-first; each plugin section is treated as released when merged to `main`. +### vibe v1.1.124 + +#### Changed + +- When CI jobs or package checks lack results, opening a pull request asks the user whether to run them or proceed without them for that head (ISS-15124). + +#### Fixed + +- Push-check applies the December 1 mutation-proof cutoff to missing decision-table inventory runs (ISS-15125). +- Across all plugin Markdown, including eval prompts and graders, the release is about 80 words longer than v1.1.123. The count covers the source files in `plugins/vibe` and excludes the generated ClosedLoop edition. + ### vibe v1.1.123 #### Fixed diff --git a/plugins/vibe-closedloop/.claude-plugin/plugin.json b/plugins/vibe-closedloop/.claude-plugin/plugin.json index 0fe9fdc7..611fe389 100644 --- a/plugins/vibe-closedloop/.claude-plugin/plugin.json +++ b/plugins/vibe-closedloop/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "vibe", "description": "Vibe sessions, handoff, seed refresh, and ClosedLoop ticket workflows", - "version": "1.1.123", + "version": "1.1.124", "dependencies": [ "closedloop-core", "vibe-core" diff --git a/plugins/vibe-closedloop/.codex-plugin/plugin.json b/plugins/vibe-closedloop/.codex-plugin/plugin.json index dee584c5..8e44ca4a 100644 --- a/plugins/vibe-closedloop/.codex-plugin/plugin.json +++ b/plugins/vibe-closedloop/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "vibe", - "version": "1.1.123", + "version": "1.1.124", "description": "Vibe sessions, handoff, seed refresh, and ClosedLoop ticket workflows", "author": { "name": "ClosedLoop", diff --git a/plugins/vibe-closedloop/README.md b/plugins/vibe-closedloop/README.md index a2437db6..c140791d 100644 --- a/plugins/vibe-closedloop/README.md +++ b/plugins/vibe-closedloop/README.md @@ -314,7 +314,7 @@ Run the matching Codex suite from the repository root with ### Runtime files -Version `1.1.123` contains 17 skills and 17 agents, and no hook manifest: the +Version `1.1.124` contains 17 skills and 17 agents, and no hook manifest: the `vibe-core` plugin, which vibe declares as a dependency, registers the hooks and runs `hooks/runtime.mjs` from the vibe a session uses. Skill commands forward to guards in `hooks/` and runtime modules in `lib/`. The package has no standalone commands, root shell scripts or production Python tools. Tests sit beside their owners; Python contract helpers and the generic scan live in `tools/python/`. diff --git a/plugins/vibe-closedloop/hooks/pr-create-guard.mjs b/plugins/vibe-closedloop/hooks/pr-create-guard.mjs index b62bc33b..0bc23b03 100644 --- a/plugins/vibe-closedloop/hooks/pr-create-guard.mjs +++ b/plugins/vibe-closedloop/hooks/pr-create-guard.mjs @@ -9,8 +9,8 @@ // unrelated tool false positives. A call that overrides head ownership or the // session record has no gate witness, so it names its findings inline, as // merge-guard.mjs reads them: `VISUAL_QA_FINDINGS= gh pr create ...`. -// Any head in scope, vibe or not, also needs every declared CI workflow job run in full on it (full-ci-check.mjs), and -// a change to a registered refusing check needs that check replayed against real work (refusing-check-replay.mjs). +// Any new PR in scope needs whole-lane results or the user's decision for that head. A change to a registered refusing +// check needs that check replayed against real work (refusing-check-replay.mjs). import { execFileSync } from "node:child_process"; import { existsSync, lstatSync, readFileSync } from "node:fs"; import path from "node:path"; @@ -23,15 +23,17 @@ import { githubRepository } from "../lib/vibe/scripts/github-remote.mjs"; import { upstreamBranchName } from "../lib/vibe/scripts/upstream-branch.mjs"; import { isProviderBroken, recordedBinding } from "../lib/vibe/scripts/provider.mjs"; import { assertIsolatedTestRead } from "../lib/vibe/scripts/test-state-isolation.mjs"; -import { conversationSkill } from "./hook-session-scope.mjs"; +import { conversationSkill, hookRuntime } from "./hook-session-scope.mjs"; import { changedPaths, declaresUiPaths, visualQaFindingsProblems, visualQaRequired, VISUAL_QA_STEP } from "../lib/vibe/scripts/required-visual-qa.mjs"; import { deliveryPlacementProblem, deliveryRepository, fleetRowHasPullRequest } from "../lib/fleet-orchestrator/scripts/delivery-placement.mjs"; import { validChat } from "../lib/fleet-orchestrator/scripts/chat-binding.mjs"; import os from "node:os"; import { BodyFileError, OVERRIDE_CHECKS, overriddenChecks, readPrBodyFile } from "../lib/handoff/scripts/gate-override.mjs"; -import { declaresPackageLanes, declaredWorkflowLanes, fullCiProblem } from "../lib/handoff/scripts/full-ci-check.mjs"; +import { declaresPackageLanes, declaredWorkflowLanes, prCiLaneStatus } from "../lib/handoff/scripts/full-ci-check.mjs"; import { refusalReplayProblem } from "../lib/handoff/scripts/refusing-check-replay.mjs"; import { e2eGateProblems } from "../lib/handoff/scripts/e2e-gate-check.mjs"; +import { prLaneLocalLimitation } from "../skills/vibe/scripts/pre-pr-lanes.mjs"; +import { prCiDecision } from "../skills/vibe/scripts/session-questions.mjs"; const VIBE_BRANCH = "vibe/"; const overrideHint = (check) => `if every real check and review passed and known Vibe gate bugs are the only blocker (operator ruling 2026-11-08), add \`Vibe gate override: [, ...]: ${check}: \` naming each bug ticket and the check it overrides to the PR body file`; @@ -303,34 +305,45 @@ function prVisualQaProblem({ cwd, head = null, base, binding, witnessWorktree = } /** - * Why the PR head may not be raised yet, or null: a declared CI workflow job not run on it in full (full-ci-check.mjs), - * a required e2e spec with no run receipt (e2e-gate-check.mjs), or a changed refusing check not replayed against real - * work (refusing-check-replay.mjs). It applies to every head in scope, vibe or not, since push-check leaves a row with - * no pull request to this gate (full-ci-check.mjs cites the rulings); the records are read from the worktree whose HEAD - * is the PR head, else the command worktree. + * The new-PR lane decision, E2E witness and replay checks. Every head in scope reaches this gate. Records come from + * the worktree whose HEAD is the PR head, or the command worktree when no checkout has that head. */ -function prReadinessProblem(call, target, binding) { +function prReadinessProblem(call, target, binding, event, home) { let headCommit; try { headCommit = git(call.cwd, ["rev-parse", "--verify", `${call.head ? prHeadRef(call.cwd, call.head) : "HEAD"}^{commit}`]); } catch { try { return declaresPackageLanes(call.cwd, "HEAD") || declaredWorkflowLanes(call.cwd, "HEAD") - ? "the PR head cannot be read to check its test lanes" : null; + ? refuse("the PR head cannot be read to check its test lanes") : null; } catch { return null; } } const worktree = git(call.cwd, ["worktree", "list", "--porcelain"]).split(/\n\s*\n/) .find((entry) => entry.split("\n").includes(`HEAD ${headCommit}`))?.match(/^worktree (.+)$/m)?.[1] ?? target?.cwd ?? call.cwd; try { + const { problem, missing } = prCiLaneStatus(worktree, headCommit); + if (problem) return refuse(problem); + if (missing.length) { + const { choice, question, transcriptUnavailable } = prCiDecision({ worktree, head: headCommit, lanes: missing, home, + chat: validChat(event.session_id), transcript: event.transcript_path, runtime: hookRuntime(event), + localLimitation: (lane) => prLaneLocalLimitation(lane, worktree) }); + if (choice !== "open") { + const lanes = missing.map(({ kind, name, command }) => kind === "package" ? command : name).join(", "); + let next = "Wait for the user's recorded reply."; + if (choice === "run") next = "The user chose to run the missing checks."; + if (transcriptUnavailable) next = "Retry from the chat with a readable transcript to record the user's choice."; + const result = refuse(`CI decision required for ${headCommit.slice(0, 12)}. Missing witnessed checks: ${lanes}. ${next} Use full-ci-check.mjs report for the run commands.`); + return question ? { ...result, systemMessage: question } : result; + } + } const bodyText = () => call.bodyFile ? readPrBodyFile(call.bodyFile) : ""; const base = () => resolvePrBase(call.cwd, call.base).oid; - const e2e = () => e2eGateProblems(worktree, { base, head: headCommit, bodyText, binding }); - return fullCiProblem(worktree, headCommit, { bodyText, binding }) - ?? (e2e().join("; ") || null) + const outstanding = (e2eGateProblems(worktree, { base, head: headCommit, bodyText, binding }).join("; ") || null) ?? refusalReplayProblem(worktree, { base, head: headCommit, bodyText, binding }); + return outstanding ? refuse(outstanding) : null; } catch (error) { - if (error instanceof BodyFileError) return error.message; - return `the PR head's CI workflow runs, e2e runs and refusing-check replays could not be checked: ${error.message}`; + if (error instanceof BodyFileError) return refuse(error.message); + return refuse(`the PR head's CI workflow runs, e2e runs and refusing-check replays could not be checked: ${error.message}`); } } @@ -392,9 +405,9 @@ export function prCreateGuard(event, home = os.homedir()) { const chat = validChat(event?.session_id); const creatingPullRequest = !fleetRowHasPullRequest({ cwd: target?.cwd ?? call.cwd, branch: call.head, chat }); const readiness = creatingPullRequest - ? prReadinessProblem(call, target, recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home })) + ? prReadinessProblem(call, target, recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home }), event, home) : null; - if (readiness) return refuse(readiness); + if (readiness) return readiness; if (target?.nonVibe) continue; let covered; try { covered = overriddenChecks(call.bodyFile ? readPrBodyFile(call.bodyFile) : "", recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home })); } diff --git a/plugins/vibe-closedloop/hooks/skill-transcript.mjs b/plugins/vibe-closedloop/hooks/skill-transcript.mjs index bc6469a4..a823d831 100644 --- a/plugins/vibe-closedloop/hooks/skill-transcript.mjs +++ b/plugins/vibe-closedloop/hooks/skill-transcript.mjs @@ -94,6 +94,27 @@ export function* transcriptLines(file, position) { } } +/** Main-chat text replies after a hook asked a question. Exclude assistant text, tool results and injected context. */ +export function* userReplies(file, position, chat, runtime) { + for (const line of transcriptLines(file, position)) { + let row; + try { row = JSON.parse(line); } catch { continue; } + if (runtime === "codex") { + if (row?.type === "event_msg" && row.payload?.type === "user_message" && typeof row.payload.message === "string") { + yield row.payload.message.trim(); + } + continue; + } + if (row?.sessionId !== chat || row.type !== "user" || row.isSidechain === true || row.isMeta === true || + row.toolUseResult !== undefined || row.message?.role !== "user") continue; + const { content } = row.message; + if (typeof content === "string") yield content.trim(); + else if (Array.isArray(content) && content.length === 1 && content[0]?.type === "text" && typeof content[0].text === "string") { + yield content[0].text.trim(); + } + } +} + function readRange(fd, position, length) { const buffer = Buffer.alloc(length); let read = 0; diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/full-ci-check.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/full-ci-check.mjs index 29082e9e..88328abf 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/full-ci-check.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/full-ci-check.mjs @@ -1,4 +1,4 @@ -// A new pull request needs a head that contains fetched origin/main and records from that head for the whole lanes. +// Surface the whole lanes owed for a pull request head containing fetched origin/main. // Workflow repositories declare their jobs in vibe-handoff-paths.json. pnpm/Turbo workspaces declare package tests // and compatibility scripts in their manifests. Focused tests remain useful for development and push checks warn. // @@ -160,13 +160,28 @@ export function unrunCiLanes(worktree, head, { exactCommit = false, declared = d && record.targeted === undefined && record.source?.treeSha256 === tree && !witnessProblem(record))); } -/** Why `head` may not be raised as a pull request yet, or null. `bodyText` may be a function, read only when a job is unrun. */ -export function fullCiProblem(worktree, head, { bodyText = "", binding = null } = {}) { +function workflowLaneStatus(worktree, head) { const declared = declaredWorkflowLanes(worktree, head); const main = declared ? fetchedMain(worktree) : null; - const mainNotice = mainAncestryNotice(worktree, head, main); - if (mainNotice) return mainNotice; - const unrun = unrunCiLanes(worktree, head, { exactCommit: Boolean(main), declared }); + const problem = mainAncestryNotice(worktree, head, main); + return { declared, problem, missing: problem ? [] : unrunCiLanes(worktree, head, { exactCommit: Boolean(main), declared }) }; +} + +/** The CI and package lanes for the new-PR decision. Only missing witnesses are waivable. */ +export function prCiLaneStatus(worktree, head) { + const workflow = workflowLaneStatus(worktree, head); + const packages = packageLaneStatus(worktree, head); + return { + problem: workflow.problem ?? packages?.problem, + missing: [...workflow.missing.map((lane) => ({ ...lane, kind: "workflow" })), + ...(packages?.missing ?? []).map((lane) => ({ ...lane, kind: "package" }))], + }; +} + +/** The existing push-check advisory. `bodyText` may be a function, read only when a workflow job is unrun. */ +export function fullCiProblem(worktree, head, { bodyText = "", binding = null } = {}) { + const { problem, missing: unrun } = workflowLaneStatus(worktree, head); + if (problem) return problem; if (!unrun.length || quotedRulingOverride(typeof bodyText === "function" ? bodyText() : bodyText, binding, CI_LANES_OVERRIDE)) { return packageLaneNotice(worktree, head); } @@ -192,10 +207,8 @@ function main(argv) { const head = git(values.worktree, ["rev-parse", "HEAD"]).trim(); const packages = packageLaneStatus(values.worktree, head); if (packages?.problem) throw new Error(packages.problem); - const declared = declaredWorkflowLanes(values.worktree, head); - const main = declared ? fetchedMain(values.worktree) : null; - const mainNotice = mainAncestryNotice(values.worktree, head, main); - if (mainNotice) throw new Error(mainNotice); + const { declared, problem, missing: unrun } = workflowLaneStatus(values.worktree, head); + if (problem) throw new Error(problem); if (packages?.lanes.length) { const file = path.join(git(values.worktree, ["rev-parse", "--absolute-git-dir"]).trim(), "vibe-package-lane-report.txt"); writeFileSync(file, packages.lanes.map(({ command }) => ` ${command}\n`).join("")); @@ -204,7 +217,6 @@ function main(argv) { } if (!declared && packages) return packages.missing.length ? 1 : 0; process.stdout.write(`REPORT ${writeWorkflowLaneReport(values.worktree, head)}\n`); - const unrun = unrunCiLanes(values.worktree, head, { exactCommit: Boolean(main), declared }); for (const { name } of unrun) process.stdout.write(`UNRUN ${name}\n`); return unrun.length || packages?.missing.length ? 1 : 0; } diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs index b4f1161d..584d6ca4 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs @@ -566,9 +566,9 @@ function integritySubstitute(worktree, head, changed, runs, current) { }); } -function testProofProblems(worktree, base, head, receipt, current, runs, view, accepted) { +function testProofProblems(worktree, base, head, receipt, current, runs, view, snapshots) { const changed = changedTests(worktree, base, head); - const exempt = proofExemptions(worktree, { snapshots: acceptedSnapshots(worktree, { comparisonBase: base, head, ...accepted }), head, tests: changed }); + const exempt = proofExemptions(worktree, { snapshots, head, tests: changed }); const substitutes = integritySubstitute(worktree, head, changed, runs, current); const holds = (proof) => stillHolds(proof, view) && proof.mutatedExit !== 0 && proof.restoredPass === true; const authored = (proof) => proof.authoring?.requestId && GRANTS.has(proof.authoring.grant); @@ -645,8 +645,26 @@ export function writeMutantInventory(worktree) { return { table, rows: rows.map(({ path: file, case: name, mutation, outcome }) => ({ path: file, case: name, mutation, outcome })) }; } -/** The decision table's `## Mutant Inventory` against the latest logged run of each mutant that still holds: same mutants, same outcomes. */ -function mutantInventoryProblems(worktree, receipt, view) { +/** Scope missing inventory runs by the ruling only. A push alone cannot excuse a post-ruling inventory entry. */ +function legacyInventoryCases(worktree, head, snapshots, missing) { + if (!snapshots.length || !missing.length) return () => false; + const sources = new Map(); + for (const file of new Set(missing.map((row) => row.path))) { + if (!isCollectedTestFile(file)) continue; + try { sources.set(file, sourceBytes(worktree, head, repoPath(file, "test path")).toString("utf8")); } + catch { /* An unreadable test cannot establish a cutoff exemption. */ } + } + const tests = [...sources.keys()].map((file) => ({ file })); + const exempt = proofExemptions(worktree, { snapshots, head, tests }); + return ({ path: file, case: name }) => { + const source = sources.get(file); + if (source === undefined || exempt.testCase(file, source, name) !== ProofExemption.Ruling) return false; + return caseText(file, source, name) !== null; + }; +} + +/** Compare the table with the latest runs that still hold, preserving checks on logged outcomes. */ +function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshots }) { let rows = null; try { const table = sessionDecisionTable(realpathSync(worktree)); @@ -660,9 +678,12 @@ function mutantInventoryProblems(worktree, receipt, view) { } const key = (entry) => JSON.stringify([entry.path, entry.case, entry.mutation]); const listed = new Set(rows.map(key)); + const grandfathered = legacyInventoryCases(worktree, head, rulingSnapshots, rows.filter((row) => !runs.has(key(row)))); for (const row of rows) { const run = runs.get(key(row)); - if (!run) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + if (!run) { + if (!grandfathered(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + } else if (run.outcome !== row.outcome) problems.push(`the decision table says "${row.mutation}" for ${row.path} case "${row.case}" was ${row.outcome}; the mutation log shows ${run.outcome}`); } for (const [name, run] of runs) { @@ -696,10 +717,10 @@ const quotedIn = (entry) => entry.in ?? "ticket"; * mutation proof. Diff-scoped checks start at the common ancestor with the base * branch. With `head` the committed tree is checked (fleet push-check); * otherwise the worktree's current source is checked. `accepted` names the heads - * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs); - * only push-check passes a pushed head. + * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs). + * Only push-check passes a pushed head and uses the ruling cutoff for missing inventory runs. */ -export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {} } = {}) { +export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {}, pushCheck = false } = {}) { const record = readSessionRecord(worktree); const problems = flagKeyProblems(record).map((problem) => `flag keys: ${problem}`); const ticket = sessionLiveTicket(record ?? {}); @@ -719,7 +740,10 @@ export function proofGateProblems(worktree, { base, head, bodyText = "", ticketT problems.push(...commandProblems(receipt, [...found(operatorCommands(bodyText), "body"), ...found(operatorCommands(ticketText), "ticket"), ...runbookCommands(worktree, comparisonBase, fullHead)], current, ticket)); const view = sourceView(worktree, fullHead, current); - problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, accepted), ...mutantInventoryProblems(worktree, receipt, view)); + const snapshots = acceptedSnapshots(worktree, { comparisonBase, head: fullHead, ...accepted }); + const rulingSnapshots = pushCheck ? snapshots.filter(({ exemption }) => exemption === ProofExemption.Ruling) : []; + problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, snapshots), + ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, rulingSnapshots })); return problems; } @@ -760,7 +784,7 @@ export function pushReadyProofProblems(worktree, { base, head, bodyFile, witness const ticketFile = evidence.ticket?.path && existsSync(evidence.ticket.path) ? evidence.ticket.path : null; return proofGateProblems(worktree, { base, head, bodyText: read(bodyFile ?? evidence.body?.path), ticketText: proofTicketText(ticketFile, (evidence.members ?? []).map((saved) => saved.path)), runs: JSON.parse(read(evidence.runs?.path) || "{}"), - accepted: { pushed, passed: passedGateHeads(worktree) } }); + accepted: { pushed, passed: passedGateHeads(worktree) }, pushCheck: true }); } /** The last head that passed the handoff gate, as a list for `accepted.passed`; empty when none is recorded. */ diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs index 0df3281d..cdcb99ad 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs @@ -68,7 +68,7 @@ export function proofExemptions(worktree, { snapshots, head, tests }) { const tracked = tests.filter((entry) => !entry.untracked).map((entry) => entry.file); const since = snapshots.map(({ exemption, tree }) => { const diff = tracked.length ? execFileSync("git", ["-C", worktree, "diff", "-U0", "--no-renames", "--no-color", "--no-ext-diff", "--src-prefix=a/", "--dst-prefix=b/", - tree, ...(head ? [head] : []), "--", ...tracked], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 }) : ""; + tree, ...(head ? [head] : []), "--", ...tracked.map((file) => `:(literal)${file}`)], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 }) : ""; return { exemption, lines: addedLineNumbers(diff) }; }); const untracked = new Set(tests.filter((entry) => entry.untracked).map((entry) => entry.file)); diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/refusing-checks.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/refusing-checks.mjs index 81f768cd..a0945947 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/refusing-checks.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/refusing-checks.mjs @@ -11,7 +11,7 @@ // replay and move it to REFUSING_CHECKS, never add one. import { e2eGateProblems } from "./e2e-gate-check.mjs"; -import { fullCiProblem } from "./full-ci-check.mjs"; +import { prCiLaneStatus } from "./full-ci-check.mjs"; import { proofGateProblems, pushReadyProofProblems } from "./proof-receipts.mjs"; import { refusalReplayProblem } from "./refusing-check-replay.mjs"; @@ -38,15 +38,19 @@ export const REFUSING_CHECKS = Object.freeze({ e2eGateProblems: { files: E2E_FILES, gates: ["PR create"], replay: ({ worktree, base, head, pushed, passed, bodyText, binding }) => alreadyAccepted(head, pushed, passed) ? [] : e2eGateProblems(worktree, { base, head, bodyText, binding }) }, - fullCiProblem: { files: [`${HANDOFF}/full-ci-check.mjs`, ...LANE_RECORDERS, PR_CREATE], gates: ["PR create"], - replay: ({ worktree, head, pushed, passed, bodyText, binding }) => alreadyAccepted(head, pushed, passed) - ? [] : [fullCiProblem(worktree, head, { bodyText, binding })].filter(Boolean) }, + prReadinessProblem: { files: [`${HANDOFF}/full-ci-check.mjs`, ...LANE_RECORDERS, PR_CREATE, + `${LANE_SCRIPTS}/session-questions.mjs`, "plugins/vibe/hooks/skill-transcript.mjs"], gates: ["PR create"], + replay: ({ worktree, head, pushed, passed }) => { + if (alreadyAccepted(head, pushed, passed)) return []; + const { problem, missing } = prCiLaneStatus(worktree, head); + if (problem) return [problem]; + return missing.length ? [`CI decision required. Missing witnessed checks: ${missing.map(({ name }) => name).join(", ")}`] : []; + } }, refusalReplayProblem: { files: [`${HANDOFF}/refusing-check-replay.mjs`, `${HANDOFF}/refusing-checks.mjs`], gates: ["PR create"], replay: ({ worktree, base, head, bodyText, binding }) => [refusalReplayProblem(worktree, { base, head, bodyText, binding })].filter(Boolean) }, "PROOF-MISSING": { via: "pushReadyProofProblems" }, "E2E-NOT-RUN": { via: "e2eGateProblems" }, - "CI-NOT-RUN": { via: "fullCiProblem" }, - prReadinessProblem: { via: "fullCiProblem" }, + "CI-NOT-RUN": { via: "prReadinessProblem" }, }); /** Refusing checks that predate the registry and have no replay (shrink-only). */ diff --git a/plugins/vibe-closedloop/skills/fleet-orchestrator/SKILL.md b/plugins/vibe-closedloop/skills/fleet-orchestrator/SKILL.md index f9c0fa31..462bce77 100644 --- a/plugins/vibe-closedloop/skills/fleet-orchestrator/SKILL.md +++ b/plugins/vibe-closedloop/skills/fleet-orchestrator/SKILL.md @@ -14,6 +14,8 @@ Finish the [product-question research order](../vibe/references/quality-loop.md# Before **every operator question**, in chat or through a tool, run `session-questions.mjs ask --product --code-evidence :`. Send its exact path-free question only on `ask: true`. Keep `checked in code: :` private. Apply cited rulings; to reopen one, put the uncovered fact in the question and `--new-fact`. Outside a session pass the latest full tracker response with `--ticket-record`. Bring conflicting human sources to the operator with a recommendation. Record the answer and source as `- Ruling (): ` in the resume log, on the ticket with amended criteria, and on the relevant thread. Technical and test-evidence decisions are `(orchestrator)`; put remaining engineer-only checks in the PR’s Engineering review. + The PR-create hook records its own question about unwitnessed CI or package checks. The person's chat reply decides whether to run them or open that head without the listed results. + Route analysis through `dist/claude-worker.mjs` with `vibe-requirements-worker` and sessionless startup. Verify saved results with `node dist/claude-worker.mjs check-analysis < result.json`; replace refused results. Route reviews and visual QA through `dist/codex-reviewer.mjs`, assigned work through fleet writer turns. Before recording a sequencing ruling, run `node ../handoff/scripts/rulings-check.mjs --sequencing --pr-tickets `, resolve every pull request number to its ticket, and report every reference that cannot be resolved. For each resolved dependency, call `create-artifact-link` with `BLOCKS` from the prerequisite ticket to the waiting ticket and list the links to confirm them. Normalize that receipt as blocker-to-blocked link JSON, then run `node ../handoff/scripts/rulings-check.mjs --record-sequencing --program /rulings.md --pr-tickets --links `. This command is the only sequencing-ruling writer: it refuses a missing link and appends only after every receipt matches. A direction authored by the orchestrator stays operational text marked `(orchestrator)` and never enters `rulings.md`; only quoted operator words with their source use this path. diff --git a/plugins/vibe-closedloop/skills/vibe/SKILL.md b/plugins/vibe-closedloop/skills/vibe/SKILL.md index 81b2abbf..d9cb4f46 100644 --- a/plugins/vibe-closedloop/skills/vibe/SKILL.md +++ b/plugins/vibe-closedloop/skills/vibe/SKILL.md @@ -873,13 +873,18 @@ Local Storybook remains available and product design approvals stay intact. No question reaches the person twice. Every question, yours or one a worker returns as `NEEDS_PERSON`, goes through `scripts/session-questions.mjs`, except the startup version question, which runs once per conversation -(section 1, "Plugin version"): +(section 1, "Plugin version"). + +For a new pull request with unwitnessed CI or package checks, the PR-create +hook records the question itself. Wait for the person's chat reply, or act +on their choice to run the checks. The hook records and verifies the reply +for that head. Ask once and use the reply format shown by the hook. 1. Before asking, run `node scripts/session-questions.mjs ask --key --question "" --default "" --deadline-minutes [--worktree ""]` and end the message with the `ifNoAnswer` line it returns (at most 30 minutes); past it, go ahead on - the default and say so. A question never holds a pull request: ship what + the default and say so. For other questions, ship what is done, arm auto-merge and put the answer-dependent part in a follow-up. For a product question, also pass `--product --code-evidence ""`; the command refuses it diff --git a/plugins/vibe-closedloop/skills/vibe/scripts/pre-pr-lanes.mjs b/plugins/vibe-closedloop/skills/vibe/scripts/pre-pr-lanes.mjs index 754c9260..c0236866 100644 --- a/plugins/vibe-closedloop/skills/vibe/scripts/pre-pr-lanes.mjs +++ b/plugins/vibe-closedloop/skills/vibe/scripts/pre-pr-lanes.mjs @@ -192,6 +192,14 @@ function commandOnPath(tool) { return spawnSync("sh", ["-c", `command -v ${tool}`], { stdio: "ignore" }).status === 0; } +/** Known host blockers for the whole lanes offered by the new-PR question. No lane is started. */ +export function prLaneLocalLimitation(lane, worktree) { + if (lane.kind === "workflow") return "use the CI runner or remote workflow replay"; + if (fleetHeavyPolicy(process.env, undefined, worktree).barred) return "use a machine that can run heavy checks"; + if (!commandOnPath("pnpm")) return "pnpm is unavailable"; + return null; +} + /** Whether this machine has the staging e2e identities the web e2e lane signs in and tears down as. */ export function hasStagingE2eIdentity(worktree, env = process.env, identity = stagingIdentity()) { if (!identity) { @@ -820,7 +828,7 @@ async function main(argv) { } values.fleetReceipt = fleetReceipt; if (result === "pass" && wholePackage && !witnessed) { - process.stderr.write("CI-NOT-RUN: this full package lane needs a run witness at PR create. Use witness on the runner and record its evidence.\n"); + process.stderr.write("CI-NOT-RUN: this full package lane has no witness for the new-PR decision. Use witness on the runner and record its evidence.\n"); } } const cacheKey = source.diffSha256 === createHash("sha256").digest("hex") ? laneKeyFor(values.worktree, { command: values.command, base: values.base, config: values.config }) : null; @@ -920,7 +928,7 @@ async function main(argv) { for (const line of hints.full) process.stdout.write(`${line}\n`); if (hints.targetable.length > 0) process.stdout.write(`TARGETED-E2E: this repository allows a targeted E2E lane in place of the full one for ${hints.targetable.join(", ")}; ${TARGETED_RECORD}\n`); } - // An impact report can still drive focused work. The new whole-package policy applies at PR create. + // An impact report can still drive focused work. Whole package lanes are considered at PR creation. try { const notice = packageLaneNotice(values.worktree, head); if (notice) process.stdout.write(`CI-NOT-RUN ${notice}\n`); diff --git a/plugins/vibe-closedloop/skills/vibe/scripts/session-questions.mjs b/plugins/vibe-closedloop/skills/vibe/scripts/session-questions.mjs index 3aa55ab6..81c71e99 100644 --- a/plugins/vibe-closedloop/skills/vibe/scripts/session-questions.mjs +++ b/plugins/vibe-closedloop/skills/vibe/scripts/session-questions.mjs @@ -15,6 +15,7 @@ // With --worktree the questions live on that session's private record. Before // the session exists they live in ~/.codex/vibe/startup-questions.json, which // `reset` clears and `vibe-sessions.mjs new` moves onto the new session. +// Plain fleet PR decisions stay with their recorded chat and checkout. // // `ask` answers whether to ask: {"ask":true} only for a key never asked. A key // already asked returns {"ask":false} with its pending question or its answer, @@ -34,10 +35,12 @@ // is at most 30 minutes, and a question never holds a pull request: the // writer ships what is done, arms auto-merge and puts the answer-dependent // part in a follow-up (operator ruling, 2026-10-22), so `ask` refuses one -// that says it holds a merge, a push or the PR. +// that says it holds a merge, a push or the PR. The PR-create hook records +// its required CI decision directly and verifies the user's chat reply. // Every command prints one JSON object; errors print {"ok":false,"error":...}. -import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { createHash } from "node:crypto"; +import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { parseArgs } from "node:util"; @@ -47,6 +50,7 @@ import { boundProgramRulings, currentTrackerBody } from "../../handoff/scripts/r import { questionRulings } from "../../handoff/scripts/rulings-check.mjs"; import { waitsForPerson } from "./question-wait-policy.mjs"; import { sessionPlanEvidencePaths } from "./session-plan.mjs"; +import { transcriptPosition, userReplies } from "../../../hooks/skill-transcript.mjs"; export { waitsForPerson }; @@ -61,6 +65,7 @@ const IN_SCOPE_WORK = /\b(?:tests?|fixtures?|specs?|snapshots?|merge (?:main|the const HUMAN_ONLY = /\b(?:flags?|feature flag|switch(?:es)?|toggles?|credentials?|password|token|sign(?:ed)?[ -]?in|log ?in|delete|discard|destroy|drop|force|wording|copy|say|says|label|product|skip|narrow|defer|exclude|descope|obsolete|out of scope)\b/i; const MAX_DEADLINE_MINUTES = 30; const HOLDS_PR = /\b(?:hold(?:s|ing)?|block(?:s|ing)?|paus(?:e|es|ing)|park(?:ed|ing)?)\b[^.?!\n]{0,40}\b(?:auto-?merge|merge|pr|pull request|push)\b|\b(?:auto-?merge|merge|pr|pull request|push)\b[^.?!\n]{0,20}\b(?:on hold|held|until you answer|pending your answer)\b/i; +const PR_CI_QUESTION = "Should I run the missing checks or open the pull request without these results?"; /** In-scope engineering work asked as permission; it never waits for the person. */ export function asksLeaveForInScopeWork(question) { @@ -78,7 +83,7 @@ export function startupFile(home = os.homedir()) { } /** Records a question once; a repeated key returns the existing entry instead. */ -export function askQuestion(questions, { key, question, product = false, codeEvidence, fallback, deadlineMinutes, newFact, rulings, ticketRecord, chat, now = new Date().toISOString() }) { +export function askQuestion(questions, { key, question, product = false, codeEvidence, fallback, deadlineMinutes, newFact, rulings, ticketRecord, chat, prCi, now = new Date().toISOString() }) { requireKey(key); requireText("--question", question); if (asksLeaveForInScopeWork(question)) { @@ -94,7 +99,7 @@ export function askQuestion(questions, { key, question, product = false, codeEvi if (existing) { return { questions, result: { ask: false, ...existing } }; } - const waits = waitsForPerson(question); + const waits = Boolean(prCi) || waitsForPerson(question); const minutes = Number(deadlineMinutes); if (!waits && (!fallback?.trim() || !Number.isInteger(minutes) || minutes < 1 || minutes > MAX_DEADLINE_MINUTES)) { throw new Error(`a question carries --default and --deadline-minutes <1 to ${MAX_DEADLINE_MINUTES}>; only a flag, copy, destructive, credential or scope-narrowing question waits for the person with no deadline`); @@ -102,7 +107,7 @@ export function askQuestion(questions, { key, question, product = false, codeEvi const deadlineAt = waits ? null : new Date(Date.parse(now) + minutes * 60_000).toISOString(); const entry = { key, question, ...(product ? { product: true, codeEvidence } : {}), - ...(newFact ? { newFact, rulings } : {}), ...(ticketRecord ? { ticketRecord } : {}), ...(chat ? { chat } : {}), + ...(newFact ? { newFact, rulings } : {}), ...(ticketRecord ? { ticketRecord } : {}), ...(chat ? { chat } : {}), ...(prCi ? { prCi } : {}), ...(waits ? { waitsForPerson: true } : { default: fallback.trim(), deadlineAt, ifNoAnswer: ifNoAnswerLine(deadlineAt, fallback.trim()) }), askedAt: now, answer: null, answeredAt: null, }; @@ -121,9 +126,71 @@ export function answerQuestion(questions, { key, answer, now = new Date().toISOS return { questions: questions.map((entry) => (entry.key === key ? updated : entry)), result: updated }; } +/** Record a PR's required decision with the usual question ledger. The hook's transcript is the authority for replies. */ +export function prCiDecision({ worktree, head, lanes, chat, transcript, runtime, localLimitation, home }) { + const root = realpathSync(worktree); + const scope = lanes.map(({ kind, name, command }) => ({ + kind, name, fingerprint: createHash("sha256").update(command).digest("hex"), + })); + const keyFor = (checks) => "pr-ci:" + createHash("sha256").update(JSON.stringify([chat, root, head, checks])).digest("hex").slice(0, 20); + const choiceText = (key) => ({ + run: `Run the missing checks ${key.slice("pr-ci:".length)}`, + open: `Open without these results ${key.slice("pr-ci:".length)}`, + }); + const copy = ({ run, open }) => [ + "This pull request is missing results for the following checks:", + "", + ...lanes.map((lane) => { + const limitation = localLimitation(lane); + return `- ${lane.name}${limitation ? ` (can’t run on this machine, ${limitation})` : ""}`; + }), + "", + PR_CI_QUESTION, + `Reply with “${run}” or “${open}”.`, + ].join("\n"); + const position = transcriptPosition(transcript); + const key = keyFor(scope); + if (!chat || !position) return { choice: null, transcriptUnavailable: true }; + // Plain fleet worktrees use the existing startup record, scoped by chat and worktree in the key. + const owner = readSessionRecord(worktree) ? worktree : null; + const questions = load(owner, home); + const [device, inode, length] = position.split("-"); + const existing = questions.findLast((entry) => { + const saved = entry.prCi; + if (entry.chat !== chat || saved?.head !== head || !Array.isArray(saved.lanes) + || entry.key !== keyFor(saved.lanes)) return false; + const [savedDevice, savedInode, start] = /^(\d+)-(\d+)-(\d+)$/.exec(saved.position ?? "")?.slice(1) ?? []; + if (savedDevice !== device || savedInode !== inode || Number(start) > Number(length)) return false; + // Passing a check after asking does not invalidate the decision for the others. + return scope.every(({ kind, name, fingerprint }) => saved.lanes.some((lane) => + lane.kind === kind && lane.name === name && lane.fingerprint === fingerprint)); + }); + if (!existing) { + const result = askQuestion(questions.filter((entry) => entry.key !== key), { + key, question: PR_CI_QUESTION, chat, prCi: { head, lanes: scope, position }, + }); + const question = copy(choiceText(key)); + store(owner, home, result.questions); + return { choice: null, question }; + } + const { run, open } = choiceText(existing.key); + let answer = null; + for (const reply of userReplies(transcript, existing.prCi.position, chat, runtime)) { + if (reply === run || reply === open) answer = reply; + } + if (!answer) return { choice: null }; + if (existing.answer !== answer || !existing.prCi.confirmedInTranscript) { + const updated = answerQuestion(questions, { key: existing.key, answer }); + updated.result.prCi = { ...existing.prCi, confirmedInTranscript: true }; + store(owner, home, updated.questions); + } + return { choice: answer === open ? "open" : "run" }; +} + /** Moves startup questions onto a new session record and clears the startup file. */ export function adoptStartupQuestions(worktree, home = os.homedir()) { - const startup = readStartup(home); + const saved = readStartup(home); + const startup = saved.filter((entry) => !entry.prCi); if (!startup.length) { return []; } @@ -138,7 +205,7 @@ export function adoptStartupQuestions(worktree, home = os.homedir()) { } } writeSessionRecord(worktree, { ...record, questions: merged }); - rmSync(startupFile(home), { force: true }); + clearStartupQuestions(home, saved); return merged; } @@ -154,7 +221,16 @@ function readStartup(home) { function writeStartup(home, questions) { const file = startupFile(home); mkdirSync(path.dirname(file), { recursive: true }); - writeFileSync(file, `${JSON.stringify({ questions }, null, 2)}\n`, { mode: 0o600 }); + const temporary = `${file}.${process.pid}.tmp`; + writeFileSync(temporary, `${JSON.stringify({ questions }, null, 2)}\n`, { mode: 0o600 }); + renameSync(temporary, file); +} + +/** Startup resets and adoption leave other chats' head-bound PR decisions available. */ +function clearStartupQuestions(home, questions) { + const decisions = questions.filter((entry) => entry.prCi); + if (decisions.length) writeStartup(home, decisions); + else rmSync(startupFile(home), { force: true }); } function load(worktree, home) { @@ -234,7 +310,7 @@ function run(argv, home = os.homedir()) { if (worktree) { throw new Error("reset clears only the questions kept before a session exists; it takes no --worktree."); } - rmSync(startupFile(home), { force: true }); + clearStartupQuestions(home, readStartup(home)); return { questions: [] }; case "ask": { requireText("--question", values.question); @@ -253,7 +329,9 @@ function run(argv, home = os.homedir()) { return result; } case "answer": { - const { questions, result } = answerQuestion(load(worktree, home), { key: values.key, answer: values.answer }); + const saved = load(worktree, home); + if (saved.some((entry) => entry.key === values.key && entry.prCi)) throw new Error("The new-PR decision is recorded from the user's chat reply."); + const { questions, result } = answerQuestion(saved, { key: values.key, answer: values.answer }); store(worktree, home, questions); return result; } diff --git a/plugins/vibe/.claude-plugin/plugin.json b/plugins/vibe/.claude-plugin/plugin.json index 92e54204..f9ac683e 100644 --- a/plugins/vibe/.claude-plugin/plugin.json +++ b/plugins/vibe/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "vibe-generic", "description": "Vibe sessions and handoff in any git repository, with fleet orchestration, seed refresh and ticket workflows", - "version": "1.1.123", + "version": "1.1.124", "dependencies": ["closedloop-core", "vibe-core"], "author": {"name": "ClosedLoop", "email": "support@closedloop.ai"} } diff --git a/plugins/vibe/.codex-plugin/plugin.json b/plugins/vibe/.codex-plugin/plugin.json index 879f8974..81da2067 100644 --- a/plugins/vibe/.codex-plugin/plugin.json +++ b/plugins/vibe/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "vibe-generic", - "version": "1.1.123", + "version": "1.1.124", "description": "Vibe sessions and handoff in any git repository, with fleet orchestration, seed refresh and ticket workflows", "author": {"name": "ClosedLoop", "email": "support@closedloop.ai"}, "homepage": "https://github.com/closedloop-ai/claude-plugins", diff --git a/plugins/vibe/README.md b/plugins/vibe/README.md index 0d0bacd3..ec4e6bb8 100644 --- a/plugins/vibe/README.md +++ b/plugins/vibe/README.md @@ -337,7 +337,7 @@ Run the matching Codex suite from the repository root with ### Runtime files -Version `1.1.123` contains 17 skills and 17 agents, and no hook manifest: the +Version `1.1.124` contains 17 skills and 17 agents, and no hook manifest: the `vibe-core` plugin, which vibe declares as a dependency, registers the hooks and runs `hooks/runtime.mjs` from the vibe a session uses. Skill commands forward to guards in `hooks/` and runtime modules in `lib/`. The package has no standalone commands, root shell scripts or production Python tools. Tests sit beside their owners; Python contract helpers and the generic scan live in `tools/python/`. diff --git a/plugins/vibe/hooks/pr-create-full-ci.test.mjs b/plugins/vibe/hooks/pr-create-full-ci.test.mjs index dbb01c3a..0f4fe53c 100644 --- a/plugins/vibe/hooks/pr-create-full-ci.test.mjs +++ b/plugins/vibe/hooks/pr-create-full-ci.test.mjs @@ -1,7 +1,7 @@ -// PR create refuses any head in scope, vibe or not, until every declared CI workflow job ran on it in full (full-ci-check.mjs). +// A new PR in scope needs witnessed checks or a user decision for that head. import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; -import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; @@ -11,11 +11,87 @@ import { recordHookSkill } from "./hook-session-scope.mjs"; import { ciRepository, recordLanes } from "../lib/handoff/scripts/full-ci-fixture.mjs"; import { passingPnpmPath } from "../skills/vibe/scripts/test-fixtures.mjs"; import { REFUSING_CHECKS } from "../lib/handoff/scripts/refusing-checks.mjs"; +import { answerQuestion, startupFile } from "../skills/vibe/scripts/session-questions.mjs"; const FULL_CI = fileURLToPath(new URL("../lib/handoff/scripts/full-ci-check.mjs", import.meta.url)); const LANES = fileURLToPath(new URL("../skills/vibe/scripts/pre-pr-lanes.mjs", import.meta.url)); +const QUESTIONS = fileURLToPath(new URL("../skills/vibe/scripts/session-questions.mjs", import.meta.url)); -test("class B: a plain worker's PR from a fleet conversation is refused until every CI job ran in full on its head", (t) => { +function ciQuestion(t, { codex = false } = {}) { + const home = mkdtempSync(path.join(tmpdir(), "pr-ci-question-home-")); + t.after(() => rmSync(home, { recursive: true, force: true })); + const chat = "ci-question"; + recordHookSkill(chat, "vibe:fleet-orchestrator", home); + const r = ciRepository(t); + const transcript = path.join(home, "session.jsonl"); + writeFileSync(transcript, codex ? JSON.stringify({ type: "session_meta", payload: { id: chat } }) + "\n" : ""); + const body = path.join(home, "body.md"); + writeFileSync(body, 'Vibe gate override: #12: ci lanes: "open without checks"\n'); + const create = () => prCreateGuard({ cwd: r.worktree, session_id: chat, transcript_path: transcript, + ...(codex ? { model: "test" } : {}), tool_input: { command: `gh pr create --base main --body-file ${body}` } }, home); + const addTurn = (answer, role = "user") => appendFileSync(transcript, JSON.stringify(codex + ? { type: "event_msg", payload: { type: role === "user" ? "user_message" : "agent_message", message: answer } } + : { sessionId: chat, type: role, message: { role, content: answer } }) + "\n"); + const decisionRecord = () => JSON.parse(readFileSync(startupFile(home), "utf8")); + return { ...r, home, create, addTurn, decisionRecord }; +} + +const openReply = (result) => { + const message = result.systemMessage ?? ""; + const reply = /Open without these results [0-9a-f]+/.exec(message)?.[0]; + assert.ok(reply, message || result.reason); + return reply; +}; + +test("an unwitnessed new PR asks once, lists jobs and limitations, and opens only after the user answers on this head", (t) => { + const r = ciQuestion(t); + const pending = r.create(); + assert.equal(pending?.decision, "deny", "a quoted override in the PR body cannot waive the question"); + assert.match(pending.systemMessage ?? "", /plugin-version-bump \(can’t run on this machine/); + assert.match(pending.systemMessage ?? "", /node-tests \(can’t run on this machine/); + const answer = openReply(pending); + assert.equal(r.create()?.systemMessage, undefined, "the pending question is not shown twice"); + const { questions } = r.decisionRecord(); + assert.equal(questions.length, 1); + const { questions: forged } = answerQuestion(questions, { key: questions[0].key, answer }); + writeFileSync(startupFile(r.home), JSON.stringify({ questions: forged })); + r.addTurn(answer, "assistant"); + assert.equal(r.create()?.decision, "deny", "the record and assistant text do not prove a user response"); + r.addTurn(answer); + assert.equal(r.create(), null); + const [decision] = r.decisionRecord().questions; + assert.equal(decision.answer, answer); + assert.equal(decision.prCi.head, r.head); + assert.deepEqual(decision.prCi.lanes.map(({ name }) => name), ["plugin-version-bump", "node-tests"]); + const reset = spawnSync(process.execPath, [QUESTIONS, "reset"], { encoding: "utf8", env: { ...process.env, HOME: r.home } }); + assert.equal(reset.status, 0, reset.stderr); + assert.equal(r.create(), null, "the user's recorded answer applies to retries of this head"); + r.record([r.lanes[0].command]); + assert.equal(r.create(), null, "the waiver still covers the remaining check after one runs"); + r.git("commit", "--allow-empty", "-qm", "later head"); + const stale = r.create(); + assert.equal(stale?.decision, "deny"); + assert.notEqual(openReply(stale), answer); +}); + +test("Codex's user-message event can answer to open or to run the missing checks", (t) => { + const r = ciQuestion(t, { codex: true }); + const open = openReply(r.create()); + r.addTurn(open.replace("Open without these results", "Run the missing checks")); + assert.equal(r.create()?.decision, "deny"); + assert.match(r.decisionRecord().questions[0].answer, /^Run the missing checks /); + r.addTurn(open); + assert.equal(r.create(), null); +}); + +test("a fully witnessed PR does not ask or create a question record", (t) => { + const r = ciQuestion(t); + r.record(r.lanes.map(({ command }) => command)); + assert.equal(r.create(), null); + assert.equal(existsSync(startupFile(r.home)), false); +}); + +test("class B: a plain worker's PR in a fleet conversation asks for a decision until every job ran on its head", (t) => { const home = mkdtempSync(path.join(tmpdir(), "pr-full-ci-home-")); t.after(() => rmSync(home, { recursive: true, force: true })); recordHookSkill("fleet-ci", "vibe:fleet-orchestrator", home); @@ -26,7 +102,9 @@ test("class B: a plain worker's PR from a fleet conversation is refused until ev r.record(["node --test plugins/vibe/lib/vibe/scripts/cloud-worker.test.mjs"]); const refused = create(`gh pr create --base main --body-file ${body}`); assert.equal(refused?.decision, "deny"); - assert.match(refused.reason, /gh pr create refused: every CI workflow job runs in full on the exact head before a pull request, and 2 have no witnessed passing run of [0-9a-f]{12}: plugin-version-bump, node-tests/); + assert.match(refused.reason, /CI decision required for [0-9a-f]{12}\. Missing witnessed checks: plugin-version-bump, node-tests/); + assert.match(refused.reason, /readable transcript/); + assert.equal(refused.systemMessage, undefined, "a host without proof of user replies cannot offer a waiver"); assert.match(create(`gh pr create --base main --head feat/cloud-scale --body-file ${body}`)?.reason ?? "", /plugin-version-bump, node-tests/, "a named head reads the same records"); assert.equal(prCreateGuard({ cwd: r.worktree, session_id: "unscoped", transcript_path: null, tool_input: { command: "gh pr create --fill" } }, home), null, "a conversation with no vibe skill is not in the guard's scope"); @@ -34,11 +112,11 @@ test("class B: a plain worker's PR from a fleet conversation is refused until ev assert.equal(create(`gh pr create --base main --body-file ${body}`), null, "every job ran on the head's tree"); }); -function packagePr(t) { +function packagePr(t, { declared = false } = {}) { const home = mkdtempSync(path.join(tmpdir(), "pr-package-lanes-home-")); t.after(() => rmSync(home, { recursive: true, force: true })); recordHookSkill("fleet-lanes", "vibe:fleet-orchestrator", home); - const r = ciRepository(t, { declared: false }); + const r = ciRepository(t, { declared }); mkdirSync(path.join(r.worktree, "apps/api"), { recursive: true }); writeFileSync(path.join(r.worktree, "pnpm-workspace.yaml"), "packages:\n - 'apps/*'\n"); writeFileSync(path.join(r.worktree, "turbo.json"), '{"tasks":{"test":{}}}\n'); @@ -54,7 +132,11 @@ function packagePr(t) { r.git("commit", "-qm", "change API"); const head = () => r.git("rev-parse", "HEAD"); const record = (commands, extra) => recordLanes(r.worktree, head(), commands, extra); - const guard = (command) => prCreateGuard({ cwd: r.worktree, session_id: "fleet-lanes", transcript_path: null, + const transcript = path.join(home, "session.jsonl"); + writeFileSync(transcript, ""); + const addReply = (content) => appendFileSync(transcript, JSON.stringify({ sessionId: "fleet-lanes", + type: "user", message: { role: "user", content } }) + "\n"); + const guard = (command) => prCreateGuard({ cwd: r.worktree, session_id: "fleet-lanes", transcript_path: transcript, tool_input: { command } }, home); const env = { ...process.env, HOME: home, PATH: passingPnpmPath(home), CLAUDE_CODE_SESSION_ID: "", CODEX_THREAD_ID: "" }; const run = (script, ...args) => spawnSync(process.execPath, [script, ...args, "--worktree", r.worktree], { encoding: "utf8", env }); @@ -67,12 +149,22 @@ function packagePr(t) { assert.equal(result.status, 0, result.stderr + result.stdout); } }; - return { ...r, base, head, record, guard, run, runWhole }; + return { ...r, base, head, record, guard, run, runWhole, addReply }; } const FULL_TEST = "pnpm turbo run test --filter=api --force"; const COMPATIBILITY = "pnpm --filter=api test:compatibility"; +test("one decision lists and can waive both workflow jobs and package lanes when a repository declares both", (t) => { + const r = packagePr(t, { declared: true }); + const pending = r.guard("gh pr create --fill"); + for (const name of ["plugin-version-bump", "node-tests", "api#test", "api#test:compatibility"]) { + assert.ok(pending.systemMessage.split("\n").some((line) => line === `- ${name}` || line.startsWith(`- ${name} (`)), name); + } + r.addReply(openReply(pending)); + assert.equal(r.guard("gh pr create --fill"), null); +}); + test("a new PR needs the full Turbo task and compatibility command for a touched package", (t) => { const r = packagePr(t); r.record(["pnpm --filter api exec vitest run changed.test.ts"]); @@ -115,12 +207,12 @@ test("in-flight lane checks warn without changing the focused check verdict", (t assert.equal(check.status, 0, check.stderr + check.stdout); assert.match(check.stdout, /^CI-NOT-RUN .*needs witnessed whole package lanes:/m); const input = { worktree: r.worktree, head: r.head() }; - assert.deepEqual(REFUSING_CHECKS.fullCiProblem.replay({ ...input, pushed: [r.head()] }), []); - assert.match(REFUSING_CHECKS.fullCiProblem.replay(input)[0], /needs witnessed whole package lanes/); + assert.deepEqual(REFUSING_CHECKS.prReadinessProblem.replay({ ...input, pushed: [r.head()] }), []); + assert.match(REFUSING_CHECKS.prReadinessProblem.replay(input)[0], /CI decision required.*api#test, api#test:compatibility/); }); test("a fetched remote-only head cannot bypass new-PR checks from a plain fleet checkout", (t) => { const r = packagePr(t); r.git("update-ref", "refs/remotes/origin/remote-only-topic", r.head()); - assert.match(r.guard("gh pr create --head remote-only-topic --fill")?.reason ?? "", /needs witnessed whole package lanes/); + assert.match(r.guard("gh pr create --head remote-only-topic --fill")?.reason ?? "", /CI decision required.*pnpm turbo run test --filter=api/); }); diff --git a/plugins/vibe/hooks/pr-create-guard.mjs b/plugins/vibe/hooks/pr-create-guard.mjs index b62bc33b..0bc23b03 100644 --- a/plugins/vibe/hooks/pr-create-guard.mjs +++ b/plugins/vibe/hooks/pr-create-guard.mjs @@ -9,8 +9,8 @@ // unrelated tool false positives. A call that overrides head ownership or the // session record has no gate witness, so it names its findings inline, as // merge-guard.mjs reads them: `VISUAL_QA_FINDINGS= gh pr create ...`. -// Any head in scope, vibe or not, also needs every declared CI workflow job run in full on it (full-ci-check.mjs), and -// a change to a registered refusing check needs that check replayed against real work (refusing-check-replay.mjs). +// Any new PR in scope needs whole-lane results or the user's decision for that head. A change to a registered refusing +// check needs that check replayed against real work (refusing-check-replay.mjs). import { execFileSync } from "node:child_process"; import { existsSync, lstatSync, readFileSync } from "node:fs"; import path from "node:path"; @@ -23,15 +23,17 @@ import { githubRepository } from "../lib/vibe/scripts/github-remote.mjs"; import { upstreamBranchName } from "../lib/vibe/scripts/upstream-branch.mjs"; import { isProviderBroken, recordedBinding } from "../lib/vibe/scripts/provider.mjs"; import { assertIsolatedTestRead } from "../lib/vibe/scripts/test-state-isolation.mjs"; -import { conversationSkill } from "./hook-session-scope.mjs"; +import { conversationSkill, hookRuntime } from "./hook-session-scope.mjs"; import { changedPaths, declaresUiPaths, visualQaFindingsProblems, visualQaRequired, VISUAL_QA_STEP } from "../lib/vibe/scripts/required-visual-qa.mjs"; import { deliveryPlacementProblem, deliveryRepository, fleetRowHasPullRequest } from "../lib/fleet-orchestrator/scripts/delivery-placement.mjs"; import { validChat } from "../lib/fleet-orchestrator/scripts/chat-binding.mjs"; import os from "node:os"; import { BodyFileError, OVERRIDE_CHECKS, overriddenChecks, readPrBodyFile } from "../lib/handoff/scripts/gate-override.mjs"; -import { declaresPackageLanes, declaredWorkflowLanes, fullCiProblem } from "../lib/handoff/scripts/full-ci-check.mjs"; +import { declaresPackageLanes, declaredWorkflowLanes, prCiLaneStatus } from "../lib/handoff/scripts/full-ci-check.mjs"; import { refusalReplayProblem } from "../lib/handoff/scripts/refusing-check-replay.mjs"; import { e2eGateProblems } from "../lib/handoff/scripts/e2e-gate-check.mjs"; +import { prLaneLocalLimitation } from "../skills/vibe/scripts/pre-pr-lanes.mjs"; +import { prCiDecision } from "../skills/vibe/scripts/session-questions.mjs"; const VIBE_BRANCH = "vibe/"; const overrideHint = (check) => `if every real check and review passed and known Vibe gate bugs are the only blocker (operator ruling 2026-11-08), add \`Vibe gate override: [, ...]: ${check}: \` naming each bug ticket and the check it overrides to the PR body file`; @@ -303,34 +305,45 @@ function prVisualQaProblem({ cwd, head = null, base, binding, witnessWorktree = } /** - * Why the PR head may not be raised yet, or null: a declared CI workflow job not run on it in full (full-ci-check.mjs), - * a required e2e spec with no run receipt (e2e-gate-check.mjs), or a changed refusing check not replayed against real - * work (refusing-check-replay.mjs). It applies to every head in scope, vibe or not, since push-check leaves a row with - * no pull request to this gate (full-ci-check.mjs cites the rulings); the records are read from the worktree whose HEAD - * is the PR head, else the command worktree. + * The new-PR lane decision, E2E witness and replay checks. Every head in scope reaches this gate. Records come from + * the worktree whose HEAD is the PR head, or the command worktree when no checkout has that head. */ -function prReadinessProblem(call, target, binding) { +function prReadinessProblem(call, target, binding, event, home) { let headCommit; try { headCommit = git(call.cwd, ["rev-parse", "--verify", `${call.head ? prHeadRef(call.cwd, call.head) : "HEAD"}^{commit}`]); } catch { try { return declaresPackageLanes(call.cwd, "HEAD") || declaredWorkflowLanes(call.cwd, "HEAD") - ? "the PR head cannot be read to check its test lanes" : null; + ? refuse("the PR head cannot be read to check its test lanes") : null; } catch { return null; } } const worktree = git(call.cwd, ["worktree", "list", "--porcelain"]).split(/\n\s*\n/) .find((entry) => entry.split("\n").includes(`HEAD ${headCommit}`))?.match(/^worktree (.+)$/m)?.[1] ?? target?.cwd ?? call.cwd; try { + const { problem, missing } = prCiLaneStatus(worktree, headCommit); + if (problem) return refuse(problem); + if (missing.length) { + const { choice, question, transcriptUnavailable } = prCiDecision({ worktree, head: headCommit, lanes: missing, home, + chat: validChat(event.session_id), transcript: event.transcript_path, runtime: hookRuntime(event), + localLimitation: (lane) => prLaneLocalLimitation(lane, worktree) }); + if (choice !== "open") { + const lanes = missing.map(({ kind, name, command }) => kind === "package" ? command : name).join(", "); + let next = "Wait for the user's recorded reply."; + if (choice === "run") next = "The user chose to run the missing checks."; + if (transcriptUnavailable) next = "Retry from the chat with a readable transcript to record the user's choice."; + const result = refuse(`CI decision required for ${headCommit.slice(0, 12)}. Missing witnessed checks: ${lanes}. ${next} Use full-ci-check.mjs report for the run commands.`); + return question ? { ...result, systemMessage: question } : result; + } + } const bodyText = () => call.bodyFile ? readPrBodyFile(call.bodyFile) : ""; const base = () => resolvePrBase(call.cwd, call.base).oid; - const e2e = () => e2eGateProblems(worktree, { base, head: headCommit, bodyText, binding }); - return fullCiProblem(worktree, headCommit, { bodyText, binding }) - ?? (e2e().join("; ") || null) + const outstanding = (e2eGateProblems(worktree, { base, head: headCommit, bodyText, binding }).join("; ") || null) ?? refusalReplayProblem(worktree, { base, head: headCommit, bodyText, binding }); + return outstanding ? refuse(outstanding) : null; } catch (error) { - if (error instanceof BodyFileError) return error.message; - return `the PR head's CI workflow runs, e2e runs and refusing-check replays could not be checked: ${error.message}`; + if (error instanceof BodyFileError) return refuse(error.message); + return refuse(`the PR head's CI workflow runs, e2e runs and refusing-check replays could not be checked: ${error.message}`); } } @@ -392,9 +405,9 @@ export function prCreateGuard(event, home = os.homedir()) { const chat = validChat(event?.session_id); const creatingPullRequest = !fleetRowHasPullRequest({ cwd: target?.cwd ?? call.cwd, branch: call.head, chat }); const readiness = creatingPullRequest - ? prReadinessProblem(call, target, recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home })) + ? prReadinessProblem(call, target, recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home }), event, home) : null; - if (readiness) return refuse(readiness); + if (readiness) return readiness; if (target?.nonVibe) continue; let covered; try { covered = overriddenChecks(call.bodyFile ? readPrBodyFile(call.bodyFile) : "", recordedBinding({ worktree: call.cwd, conversation: event?.session_id ?? null, home })); } diff --git a/plugins/vibe/hooks/skill-transcript.mjs b/plugins/vibe/hooks/skill-transcript.mjs index bc6469a4..a823d831 100644 --- a/plugins/vibe/hooks/skill-transcript.mjs +++ b/plugins/vibe/hooks/skill-transcript.mjs @@ -94,6 +94,27 @@ export function* transcriptLines(file, position) { } } +/** Main-chat text replies after a hook asked a question. Exclude assistant text, tool results and injected context. */ +export function* userReplies(file, position, chat, runtime) { + for (const line of transcriptLines(file, position)) { + let row; + try { row = JSON.parse(line); } catch { continue; } + if (runtime === "codex") { + if (row?.type === "event_msg" && row.payload?.type === "user_message" && typeof row.payload.message === "string") { + yield row.payload.message.trim(); + } + continue; + } + if (row?.sessionId !== chat || row.type !== "user" || row.isSidechain === true || row.isMeta === true || + row.toolUseResult !== undefined || row.message?.role !== "user") continue; + const { content } = row.message; + if (typeof content === "string") yield content.trim(); + else if (Array.isArray(content) && content.length === 1 && content[0]?.type === "text" && typeof content[0].text === "string") { + yield content[0].text.trim(); + } + } +} + function readRange(fd, position, length) { const buffer = Buffer.alloc(length); let read = 0; diff --git a/plugins/vibe/lib/handoff/scripts/full-ci-check.mjs b/plugins/vibe/lib/handoff/scripts/full-ci-check.mjs index 29082e9e..88328abf 100644 --- a/plugins/vibe/lib/handoff/scripts/full-ci-check.mjs +++ b/plugins/vibe/lib/handoff/scripts/full-ci-check.mjs @@ -1,4 +1,4 @@ -// A new pull request needs a head that contains fetched origin/main and records from that head for the whole lanes. +// Surface the whole lanes owed for a pull request head containing fetched origin/main. // Workflow repositories declare their jobs in vibe-handoff-paths.json. pnpm/Turbo workspaces declare package tests // and compatibility scripts in their manifests. Focused tests remain useful for development and push checks warn. // @@ -160,13 +160,28 @@ export function unrunCiLanes(worktree, head, { exactCommit = false, declared = d && record.targeted === undefined && record.source?.treeSha256 === tree && !witnessProblem(record))); } -/** Why `head` may not be raised as a pull request yet, or null. `bodyText` may be a function, read only when a job is unrun. */ -export function fullCiProblem(worktree, head, { bodyText = "", binding = null } = {}) { +function workflowLaneStatus(worktree, head) { const declared = declaredWorkflowLanes(worktree, head); const main = declared ? fetchedMain(worktree) : null; - const mainNotice = mainAncestryNotice(worktree, head, main); - if (mainNotice) return mainNotice; - const unrun = unrunCiLanes(worktree, head, { exactCommit: Boolean(main), declared }); + const problem = mainAncestryNotice(worktree, head, main); + return { declared, problem, missing: problem ? [] : unrunCiLanes(worktree, head, { exactCommit: Boolean(main), declared }) }; +} + +/** The CI and package lanes for the new-PR decision. Only missing witnesses are waivable. */ +export function prCiLaneStatus(worktree, head) { + const workflow = workflowLaneStatus(worktree, head); + const packages = packageLaneStatus(worktree, head); + return { + problem: workflow.problem ?? packages?.problem, + missing: [...workflow.missing.map((lane) => ({ ...lane, kind: "workflow" })), + ...(packages?.missing ?? []).map((lane) => ({ ...lane, kind: "package" }))], + }; +} + +/** The existing push-check advisory. `bodyText` may be a function, read only when a workflow job is unrun. */ +export function fullCiProblem(worktree, head, { bodyText = "", binding = null } = {}) { + const { problem, missing: unrun } = workflowLaneStatus(worktree, head); + if (problem) return problem; if (!unrun.length || quotedRulingOverride(typeof bodyText === "function" ? bodyText() : bodyText, binding, CI_LANES_OVERRIDE)) { return packageLaneNotice(worktree, head); } @@ -192,10 +207,8 @@ function main(argv) { const head = git(values.worktree, ["rev-parse", "HEAD"]).trim(); const packages = packageLaneStatus(values.worktree, head); if (packages?.problem) throw new Error(packages.problem); - const declared = declaredWorkflowLanes(values.worktree, head); - const main = declared ? fetchedMain(values.worktree) : null; - const mainNotice = mainAncestryNotice(values.worktree, head, main); - if (mainNotice) throw new Error(mainNotice); + const { declared, problem, missing: unrun } = workflowLaneStatus(values.worktree, head); + if (problem) throw new Error(problem); if (packages?.lanes.length) { const file = path.join(git(values.worktree, ["rev-parse", "--absolute-git-dir"]).trim(), "vibe-package-lane-report.txt"); writeFileSync(file, packages.lanes.map(({ command }) => ` ${command}\n`).join("")); @@ -204,7 +217,6 @@ function main(argv) { } if (!declared && packages) return packages.missing.length ? 1 : 0; process.stdout.write(`REPORT ${writeWorkflowLaneReport(values.worktree, head)}\n`); - const unrun = unrunCiLanes(values.worktree, head, { exactCommit: Boolean(main), declared }); for (const { name } of unrun) process.stdout.write(`UNRUN ${name}\n`); return unrun.length || packages?.missing.length ? 1 : 0; } diff --git a/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs b/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs index b4f1161d..584d6ca4 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs @@ -566,9 +566,9 @@ function integritySubstitute(worktree, head, changed, runs, current) { }); } -function testProofProblems(worktree, base, head, receipt, current, runs, view, accepted) { +function testProofProblems(worktree, base, head, receipt, current, runs, view, snapshots) { const changed = changedTests(worktree, base, head); - const exempt = proofExemptions(worktree, { snapshots: acceptedSnapshots(worktree, { comparisonBase: base, head, ...accepted }), head, tests: changed }); + const exempt = proofExemptions(worktree, { snapshots, head, tests: changed }); const substitutes = integritySubstitute(worktree, head, changed, runs, current); const holds = (proof) => stillHolds(proof, view) && proof.mutatedExit !== 0 && proof.restoredPass === true; const authored = (proof) => proof.authoring?.requestId && GRANTS.has(proof.authoring.grant); @@ -645,8 +645,26 @@ export function writeMutantInventory(worktree) { return { table, rows: rows.map(({ path: file, case: name, mutation, outcome }) => ({ path: file, case: name, mutation, outcome })) }; } -/** The decision table's `## Mutant Inventory` against the latest logged run of each mutant that still holds: same mutants, same outcomes. */ -function mutantInventoryProblems(worktree, receipt, view) { +/** Scope missing inventory runs by the ruling only. A push alone cannot excuse a post-ruling inventory entry. */ +function legacyInventoryCases(worktree, head, snapshots, missing) { + if (!snapshots.length || !missing.length) return () => false; + const sources = new Map(); + for (const file of new Set(missing.map((row) => row.path))) { + if (!isCollectedTestFile(file)) continue; + try { sources.set(file, sourceBytes(worktree, head, repoPath(file, "test path")).toString("utf8")); } + catch { /* An unreadable test cannot establish a cutoff exemption. */ } + } + const tests = [...sources.keys()].map((file) => ({ file })); + const exempt = proofExemptions(worktree, { snapshots, head, tests }); + return ({ path: file, case: name }) => { + const source = sources.get(file); + if (source === undefined || exempt.testCase(file, source, name) !== ProofExemption.Ruling) return false; + return caseText(file, source, name) !== null; + }; +} + +/** Compare the table with the latest runs that still hold, preserving checks on logged outcomes. */ +function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshots }) { let rows = null; try { const table = sessionDecisionTable(realpathSync(worktree)); @@ -660,9 +678,12 @@ function mutantInventoryProblems(worktree, receipt, view) { } const key = (entry) => JSON.stringify([entry.path, entry.case, entry.mutation]); const listed = new Set(rows.map(key)); + const grandfathered = legacyInventoryCases(worktree, head, rulingSnapshots, rows.filter((row) => !runs.has(key(row)))); for (const row of rows) { const run = runs.get(key(row)); - if (!run) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + if (!run) { + if (!grandfathered(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + } else if (run.outcome !== row.outcome) problems.push(`the decision table says "${row.mutation}" for ${row.path} case "${row.case}" was ${row.outcome}; the mutation log shows ${run.outcome}`); } for (const [name, run] of runs) { @@ -696,10 +717,10 @@ const quotedIn = (entry) => entry.in ?? "ticket"; * mutation proof. Diff-scoped checks start at the common ancestor with the base * branch. With `head` the committed tree is checked (fleet push-check); * otherwise the worktree's current source is checked. `accepted` names the heads - * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs); - * only push-check passes a pushed head. + * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs). + * Only push-check passes a pushed head and uses the ruling cutoff for missing inventory runs. */ -export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {} } = {}) { +export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {}, pushCheck = false } = {}) { const record = readSessionRecord(worktree); const problems = flagKeyProblems(record).map((problem) => `flag keys: ${problem}`); const ticket = sessionLiveTicket(record ?? {}); @@ -719,7 +740,10 @@ export function proofGateProblems(worktree, { base, head, bodyText = "", ticketT problems.push(...commandProblems(receipt, [...found(operatorCommands(bodyText), "body"), ...found(operatorCommands(ticketText), "ticket"), ...runbookCommands(worktree, comparisonBase, fullHead)], current, ticket)); const view = sourceView(worktree, fullHead, current); - problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, accepted), ...mutantInventoryProblems(worktree, receipt, view)); + const snapshots = acceptedSnapshots(worktree, { comparisonBase, head: fullHead, ...accepted }); + const rulingSnapshots = pushCheck ? snapshots.filter(({ exemption }) => exemption === ProofExemption.Ruling) : []; + problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, snapshots), + ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, rulingSnapshots })); return problems; } @@ -760,7 +784,7 @@ export function pushReadyProofProblems(worktree, { base, head, bodyFile, witness const ticketFile = evidence.ticket?.path && existsSync(evidence.ticket.path) ? evidence.ticket.path : null; return proofGateProblems(worktree, { base, head, bodyText: read(bodyFile ?? evidence.body?.path), ticketText: proofTicketText(ticketFile, (evidence.members ?? []).map((saved) => saved.path)), runs: JSON.parse(read(evidence.runs?.path) || "{}"), - accepted: { pushed, passed: passedGateHeads(worktree) } }); + accepted: { pushed, passed: passedGateHeads(worktree) }, pushCheck: true }); } /** The last head that passed the handoff gate, as a list for `accepted.passed`; empty when none is recorded. */ diff --git a/plugins/vibe/lib/handoff/scripts/proof-scope.mjs b/plugins/vibe/lib/handoff/scripts/proof-scope.mjs index 0df3281d..cdcb99ad 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-scope.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-scope.mjs @@ -68,7 +68,7 @@ export function proofExemptions(worktree, { snapshots, head, tests }) { const tracked = tests.filter((entry) => !entry.untracked).map((entry) => entry.file); const since = snapshots.map(({ exemption, tree }) => { const diff = tracked.length ? execFileSync("git", ["-C", worktree, "diff", "-U0", "--no-renames", "--no-color", "--no-ext-diff", "--src-prefix=a/", "--dst-prefix=b/", - tree, ...(head ? [head] : []), "--", ...tracked], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 }) : ""; + tree, ...(head ? [head] : []), "--", ...tracked.map((file) => `:(literal)${file}`)], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 }) : ""; return { exemption, lines: addedLineNumbers(diff) }; }); const untracked = new Set(tests.filter((entry) => entry.untracked).map((entry) => entry.file)); diff --git a/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs b/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs index 7062380a..1db259bb 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs @@ -7,6 +7,7 @@ import test from "node:test"; import { passedGateHeads, proofGateProblems, pushReadyProofProblems, readProofReceipt, recordGatePass, recordMutationProof } from "./proof-receipts.mjs"; import { dayFromRuling, LONG_LIVED_SHAPE, longLivedBranch } from "./long-lived-branch-fixture.mjs"; import { sourceIdentity } from "../../vibe/scripts/tested-head.mjs"; +import { sessionDecisionTable } from "../../vibe/scripts/session-artifact-paths.mjs"; const NO_PROOF = /has no mutation proof/; const BEFORE = dayFromRuling(-3); @@ -59,6 +60,25 @@ test("AC-1 a line deleted after the ruling inside a case committed before it bri assert.deepEqual(cases(gate(r, { head })), ["old one"]); }); +test("push-check only asks for missing inventory runs for cases added or edited after the ruling", (t) => { + const r = repo(t); + const original = [["old unchanged", " assert.equal(add(1, 2), 3);"], ["old edited", " assert.equal(add(2, 2), 4);"]]; + r.write("src/add.test.mjs", testFile(original)); + r.commit("old cases", BEFORE); + r.write("src/add.test.mjs", testFile([original[0], ["old edited", " assert.equal(add(2, 3), 5);"], + ["added later", " assert.equal(add(0, 0), 0);"]])); + const head = r.commit("edit and add cases", AFTER); + const table = sessionDecisionTable(r.worktree); + mkdirSync(path.dirname(table), { recursive: true }); + const names = ["old unchanged", "old edited", "added later", "invalid case name"]; + writeFileSync(table, "## Mutant Inventory\n\n| Test file | Case | Mutation | Outcome |\n| --- | --- | --- | --- |\n" + + names.map((name) => `| src/add.test.mjs | ${name} | change add | killed |\n`).join("")); + const fromInventory = (problems) => cases(problems.filter((problem) => problem.includes("mutant inventory lists"))); + assert.deepEqual(fromInventory(pushReadyProofProblems(r.worktree, { base: r.main, head, pushed: [head] })), + ["added later", "invalid case name", "old edited"]); + assert.deepEqual(fromInventory(gate(r, { head })), [...names].sort(), "handoff keeps its inventory check"); +}); + test("AC-2 a long-lived branch with many inherited cases, a main sync and one new case gets exactly one refusal", (t) => { const shape = LONG_LIVED_SHAPE; const f = longLivedBranch(t); diff --git a/plugins/vibe/lib/handoff/scripts/refusing-checks.mjs b/plugins/vibe/lib/handoff/scripts/refusing-checks.mjs index 81f768cd..a0945947 100644 --- a/plugins/vibe/lib/handoff/scripts/refusing-checks.mjs +++ b/plugins/vibe/lib/handoff/scripts/refusing-checks.mjs @@ -11,7 +11,7 @@ // replay and move it to REFUSING_CHECKS, never add one. import { e2eGateProblems } from "./e2e-gate-check.mjs"; -import { fullCiProblem } from "./full-ci-check.mjs"; +import { prCiLaneStatus } from "./full-ci-check.mjs"; import { proofGateProblems, pushReadyProofProblems } from "./proof-receipts.mjs"; import { refusalReplayProblem } from "./refusing-check-replay.mjs"; @@ -38,15 +38,19 @@ export const REFUSING_CHECKS = Object.freeze({ e2eGateProblems: { files: E2E_FILES, gates: ["PR create"], replay: ({ worktree, base, head, pushed, passed, bodyText, binding }) => alreadyAccepted(head, pushed, passed) ? [] : e2eGateProblems(worktree, { base, head, bodyText, binding }) }, - fullCiProblem: { files: [`${HANDOFF}/full-ci-check.mjs`, ...LANE_RECORDERS, PR_CREATE], gates: ["PR create"], - replay: ({ worktree, head, pushed, passed, bodyText, binding }) => alreadyAccepted(head, pushed, passed) - ? [] : [fullCiProblem(worktree, head, { bodyText, binding })].filter(Boolean) }, + prReadinessProblem: { files: [`${HANDOFF}/full-ci-check.mjs`, ...LANE_RECORDERS, PR_CREATE, + `${LANE_SCRIPTS}/session-questions.mjs`, "plugins/vibe/hooks/skill-transcript.mjs"], gates: ["PR create"], + replay: ({ worktree, head, pushed, passed }) => { + if (alreadyAccepted(head, pushed, passed)) return []; + const { problem, missing } = prCiLaneStatus(worktree, head); + if (problem) return [problem]; + return missing.length ? [`CI decision required. Missing witnessed checks: ${missing.map(({ name }) => name).join(", ")}`] : []; + } }, refusalReplayProblem: { files: [`${HANDOFF}/refusing-check-replay.mjs`, `${HANDOFF}/refusing-checks.mjs`], gates: ["PR create"], replay: ({ worktree, base, head, bodyText, binding }) => [refusalReplayProblem(worktree, { base, head, bodyText, binding })].filter(Boolean) }, "PROOF-MISSING": { via: "pushReadyProofProblems" }, "E2E-NOT-RUN": { via: "e2eGateProblems" }, - "CI-NOT-RUN": { via: "fullCiProblem" }, - prReadinessProblem: { via: "fullCiProblem" }, + "CI-NOT-RUN": { via: "prReadinessProblem" }, }); /** Refusing checks that predate the registry and have no replay (shrink-only). */ diff --git a/plugins/vibe/lib/handoff/scripts/refusing-checks.test.mjs b/plugins/vibe/lib/handoff/scripts/refusing-checks.test.mjs index de6dd2a1..ac501399 100644 --- a/plugins/vibe/lib/handoff/scripts/refusing-checks.test.mjs +++ b/plugins/vibe/lib/handoff/scripts/refusing-checks.test.mjs @@ -35,7 +35,7 @@ test("class A: every refusal producer the gates call or print is registered, and test("class A: a change to a replayed check's source names that check", () => { assert.deepEqual(replayedChecksTouched(["plugins/vibe/lib/handoff/scripts/proof-scope.mjs", "README.md"]), ["proofGateProblems", "pushReadyProofProblems"]); - assert.deepEqual(replayedChecksTouched(["plugins/vibe/lib/handoff/scripts/full-ci-check.mjs"]), ["fullCiProblem"]); + assert.deepEqual(replayedChecksTouched(["plugins/vibe/lib/handoff/scripts/full-ci-check.mjs"]), ["prReadinessProblem"]); assert.deepEqual(replayedChecksTouched(["plugins/vibe/README.md"]), []); }); diff --git a/plugins/vibe/skills/fleet-orchestrator/SKILL.md b/plugins/vibe/skills/fleet-orchestrator/SKILL.md index d025aefa..d5541716 100644 --- a/plugins/vibe/skills/fleet-orchestrator/SKILL.md +++ b/plugins/vibe/skills/fleet-orchestrator/SKILL.md @@ -18,6 +18,8 @@ Finish the [product-question research order](../vibe/references/quality-loop.md# Before **every operator question**, in chat or through a tool, run `session-questions.mjs ask --product --code-evidence :`. Send its exact path-free question only on `ask: true`. Keep `checked in code: :` private. Apply cited rulings; to reopen one, put the uncovered fact in the question and `--new-fact`. Outside a session pass the latest full tracker response with `--ticket-record`. Bring conflicting human sources to the operator with a recommendation. Record the answer and source as `- Ruling (): ` in the resume log, on the ticket with amended criteria, and on the relevant thread. Technical and test-evidence decisions are `(orchestrator)`; put remaining engineer-only checks in the PR’s Engineering review. + The PR-create hook records its own question about unwitnessed CI or package checks. The person's chat reply decides whether to run them or open that head without the listed results. + Route analysis through `dist/claude-worker.mjs` with `vibe-requirements-worker` and sessionless startup. Verify saved results with `node dist/claude-worker.mjs check-analysis < result.json`; replace refused results. Route reviews and visual QA through `dist/codex-reviewer.mjs`, assigned work through fleet writer turns. diff --git a/plugins/vibe/skills/fleet-orchestrator/scripts/board-push-proof.test.mjs b/plugins/vibe/skills/fleet-orchestrator/scripts/board-push-proof.test.mjs index e30628d7..61ec0d94 100644 --- a/plugins/vibe/skills/fleet-orchestrator/scripts/board-push-proof.test.mjs +++ b/plugins/vibe/skills/fleet-orchestrator/scripts/board-push-proof.test.mjs @@ -206,7 +206,7 @@ test('AC-9 a row refused for an unreadable kind is checked once re-registered wi } }); -test('class B a row with no pull request passes push-check on focused runs, and PR create refuses it until every CI job ran in full', t => { +test('class B a row with no pull request passes push-check on focused runs, and PR create asks for a CI decision', t => { const { dir, run } = program(t, ['ISS-1']); const r = ciRepository(t, { worktree: path.join(dir, 'ci-wt') }); r.git('update-ref', 'refs/remotes/origin/main', r.git('rev-parse', 'main')); @@ -220,7 +220,7 @@ test('class B a row with no pull request passes push-check on focused runs, and assert.doesNotMatch(pushed.stdout, /CI-NOT-RUN/); const home = hookHome(t, 'fleet-no-pr'); const create = () => prCreateGuard({ cwd: r.worktree, session_id: 'fleet-no-pr', transcript_path: null, tool_input: { command: 'gh pr create --base main --fill' } }, home); - assert.match(create()?.reason ?? '', /every CI workflow job runs in full on the exact head before a pull request, and 2 have no witnessed passing run of [0-9a-f]{12}: plugin-version-bump, node-tests/); + assert.match(create()?.reason ?? '', /CI decision required for [0-9a-f]{12}\. Missing witnessed checks: plugin-version-bump, node-tests/); r.record(r.lanes.map(({ command }) => command)); assert.equal(create(), null); }); diff --git a/plugins/vibe/skills/vibe/SKILL.md b/plugins/vibe/skills/vibe/SKILL.md index 4a7811fc..ee5643a0 100644 --- a/plugins/vibe/skills/vibe/SKILL.md +++ b/plugins/vibe/skills/vibe/SKILL.md @@ -882,13 +882,18 @@ Local Storybook remains available and product design approvals stay intact. No question reaches the person twice. Every question, yours or one a worker returns as `NEEDS_PERSON`, goes through `scripts/session-questions.mjs`, except the startup version question, which runs once per conversation -(section 1, "Plugin version"): +(section 1, "Plugin version"). + +For a new pull request with unwitnessed CI or package checks, the PR-create +hook records the question itself. Wait for the person's chat reply, or act +on their choice to run the checks. The hook records and verifies the reply +for that head. Ask once and use the reply format shown by the hook. 1. Before asking, run `node scripts/session-questions.mjs ask --key --question "" --default "" --deadline-minutes [--worktree ""]` and end the message with the `ifNoAnswer` line it returns (at most 30 minutes); past it, go ahead on - the default and say so. A question never holds a pull request: ship what + the default and say so. For other questions, ship what is done, arm auto-merge and put the answer-dependent part in a follow-up. For a product question, also pass `--product --code-evidence ""`; the command refuses it diff --git a/plugins/vibe/skills/vibe/scripts/pre-pr-lanes.mjs b/plugins/vibe/skills/vibe/scripts/pre-pr-lanes.mjs index 754c9260..c0236866 100644 --- a/plugins/vibe/skills/vibe/scripts/pre-pr-lanes.mjs +++ b/plugins/vibe/skills/vibe/scripts/pre-pr-lanes.mjs @@ -192,6 +192,14 @@ function commandOnPath(tool) { return spawnSync("sh", ["-c", `command -v ${tool}`], { stdio: "ignore" }).status === 0; } +/** Known host blockers for the whole lanes offered by the new-PR question. No lane is started. */ +export function prLaneLocalLimitation(lane, worktree) { + if (lane.kind === "workflow") return "use the CI runner or remote workflow replay"; + if (fleetHeavyPolicy(process.env, undefined, worktree).barred) return "use a machine that can run heavy checks"; + if (!commandOnPath("pnpm")) return "pnpm is unavailable"; + return null; +} + /** Whether this machine has the staging e2e identities the web e2e lane signs in and tears down as. */ export function hasStagingE2eIdentity(worktree, env = process.env, identity = stagingIdentity()) { if (!identity) { @@ -820,7 +828,7 @@ async function main(argv) { } values.fleetReceipt = fleetReceipt; if (result === "pass" && wholePackage && !witnessed) { - process.stderr.write("CI-NOT-RUN: this full package lane needs a run witness at PR create. Use witness on the runner and record its evidence.\n"); + process.stderr.write("CI-NOT-RUN: this full package lane has no witness for the new-PR decision. Use witness on the runner and record its evidence.\n"); } } const cacheKey = source.diffSha256 === createHash("sha256").digest("hex") ? laneKeyFor(values.worktree, { command: values.command, base: values.base, config: values.config }) : null; @@ -920,7 +928,7 @@ async function main(argv) { for (const line of hints.full) process.stdout.write(`${line}\n`); if (hints.targetable.length > 0) process.stdout.write(`TARGETED-E2E: this repository allows a targeted E2E lane in place of the full one for ${hints.targetable.join(", ")}; ${TARGETED_RECORD}\n`); } - // An impact report can still drive focused work. The new whole-package policy applies at PR create. + // An impact report can still drive focused work. Whole package lanes are considered at PR creation. try { const notice = packageLaneNotice(values.worktree, head); if (notice) process.stdout.write(`CI-NOT-RUN ${notice}\n`); diff --git a/plugins/vibe/skills/vibe/scripts/session-questions.mjs b/plugins/vibe/skills/vibe/scripts/session-questions.mjs index 3aa55ab6..81c71e99 100644 --- a/plugins/vibe/skills/vibe/scripts/session-questions.mjs +++ b/plugins/vibe/skills/vibe/scripts/session-questions.mjs @@ -15,6 +15,7 @@ // With --worktree the questions live on that session's private record. Before // the session exists they live in ~/.codex/vibe/startup-questions.json, which // `reset` clears and `vibe-sessions.mjs new` moves onto the new session. +// Plain fleet PR decisions stay with their recorded chat and checkout. // // `ask` answers whether to ask: {"ask":true} only for a key never asked. A key // already asked returns {"ask":false} with its pending question or its answer, @@ -34,10 +35,12 @@ // is at most 30 minutes, and a question never holds a pull request: the // writer ships what is done, arms auto-merge and puts the answer-dependent // part in a follow-up (operator ruling, 2026-10-22), so `ask` refuses one -// that says it holds a merge, a push or the PR. +// that says it holds a merge, a push or the PR. The PR-create hook records +// its required CI decision directly and verifies the user's chat reply. // Every command prints one JSON object; errors print {"ok":false,"error":...}. -import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { createHash } from "node:crypto"; +import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { parseArgs } from "node:util"; @@ -47,6 +50,7 @@ import { boundProgramRulings, currentTrackerBody } from "../../handoff/scripts/r import { questionRulings } from "../../handoff/scripts/rulings-check.mjs"; import { waitsForPerson } from "./question-wait-policy.mjs"; import { sessionPlanEvidencePaths } from "./session-plan.mjs"; +import { transcriptPosition, userReplies } from "../../../hooks/skill-transcript.mjs"; export { waitsForPerson }; @@ -61,6 +65,7 @@ const IN_SCOPE_WORK = /\b(?:tests?|fixtures?|specs?|snapshots?|merge (?:main|the const HUMAN_ONLY = /\b(?:flags?|feature flag|switch(?:es)?|toggles?|credentials?|password|token|sign(?:ed)?[ -]?in|log ?in|delete|discard|destroy|drop|force|wording|copy|say|says|label|product|skip|narrow|defer|exclude|descope|obsolete|out of scope)\b/i; const MAX_DEADLINE_MINUTES = 30; const HOLDS_PR = /\b(?:hold(?:s|ing)?|block(?:s|ing)?|paus(?:e|es|ing)|park(?:ed|ing)?)\b[^.?!\n]{0,40}\b(?:auto-?merge|merge|pr|pull request|push)\b|\b(?:auto-?merge|merge|pr|pull request|push)\b[^.?!\n]{0,20}\b(?:on hold|held|until you answer|pending your answer)\b/i; +const PR_CI_QUESTION = "Should I run the missing checks or open the pull request without these results?"; /** In-scope engineering work asked as permission; it never waits for the person. */ export function asksLeaveForInScopeWork(question) { @@ -78,7 +83,7 @@ export function startupFile(home = os.homedir()) { } /** Records a question once; a repeated key returns the existing entry instead. */ -export function askQuestion(questions, { key, question, product = false, codeEvidence, fallback, deadlineMinutes, newFact, rulings, ticketRecord, chat, now = new Date().toISOString() }) { +export function askQuestion(questions, { key, question, product = false, codeEvidence, fallback, deadlineMinutes, newFact, rulings, ticketRecord, chat, prCi, now = new Date().toISOString() }) { requireKey(key); requireText("--question", question); if (asksLeaveForInScopeWork(question)) { @@ -94,7 +99,7 @@ export function askQuestion(questions, { key, question, product = false, codeEvi if (existing) { return { questions, result: { ask: false, ...existing } }; } - const waits = waitsForPerson(question); + const waits = Boolean(prCi) || waitsForPerson(question); const minutes = Number(deadlineMinutes); if (!waits && (!fallback?.trim() || !Number.isInteger(minutes) || minutes < 1 || minutes > MAX_DEADLINE_MINUTES)) { throw new Error(`a question carries --default and --deadline-minutes <1 to ${MAX_DEADLINE_MINUTES}>; only a flag, copy, destructive, credential or scope-narrowing question waits for the person with no deadline`); @@ -102,7 +107,7 @@ export function askQuestion(questions, { key, question, product = false, codeEvi const deadlineAt = waits ? null : new Date(Date.parse(now) + minutes * 60_000).toISOString(); const entry = { key, question, ...(product ? { product: true, codeEvidence } : {}), - ...(newFact ? { newFact, rulings } : {}), ...(ticketRecord ? { ticketRecord } : {}), ...(chat ? { chat } : {}), + ...(newFact ? { newFact, rulings } : {}), ...(ticketRecord ? { ticketRecord } : {}), ...(chat ? { chat } : {}), ...(prCi ? { prCi } : {}), ...(waits ? { waitsForPerson: true } : { default: fallback.trim(), deadlineAt, ifNoAnswer: ifNoAnswerLine(deadlineAt, fallback.trim()) }), askedAt: now, answer: null, answeredAt: null, }; @@ -121,9 +126,71 @@ export function answerQuestion(questions, { key, answer, now = new Date().toISOS return { questions: questions.map((entry) => (entry.key === key ? updated : entry)), result: updated }; } +/** Record a PR's required decision with the usual question ledger. The hook's transcript is the authority for replies. */ +export function prCiDecision({ worktree, head, lanes, chat, transcript, runtime, localLimitation, home }) { + const root = realpathSync(worktree); + const scope = lanes.map(({ kind, name, command }) => ({ + kind, name, fingerprint: createHash("sha256").update(command).digest("hex"), + })); + const keyFor = (checks) => "pr-ci:" + createHash("sha256").update(JSON.stringify([chat, root, head, checks])).digest("hex").slice(0, 20); + const choiceText = (key) => ({ + run: `Run the missing checks ${key.slice("pr-ci:".length)}`, + open: `Open without these results ${key.slice("pr-ci:".length)}`, + }); + const copy = ({ run, open }) => [ + "This pull request is missing results for the following checks:", + "", + ...lanes.map((lane) => { + const limitation = localLimitation(lane); + return `- ${lane.name}${limitation ? ` (can’t run on this machine, ${limitation})` : ""}`; + }), + "", + PR_CI_QUESTION, + `Reply with “${run}” or “${open}”.`, + ].join("\n"); + const position = transcriptPosition(transcript); + const key = keyFor(scope); + if (!chat || !position) return { choice: null, transcriptUnavailable: true }; + // Plain fleet worktrees use the existing startup record, scoped by chat and worktree in the key. + const owner = readSessionRecord(worktree) ? worktree : null; + const questions = load(owner, home); + const [device, inode, length] = position.split("-"); + const existing = questions.findLast((entry) => { + const saved = entry.prCi; + if (entry.chat !== chat || saved?.head !== head || !Array.isArray(saved.lanes) + || entry.key !== keyFor(saved.lanes)) return false; + const [savedDevice, savedInode, start] = /^(\d+)-(\d+)-(\d+)$/.exec(saved.position ?? "")?.slice(1) ?? []; + if (savedDevice !== device || savedInode !== inode || Number(start) > Number(length)) return false; + // Passing a check after asking does not invalidate the decision for the others. + return scope.every(({ kind, name, fingerprint }) => saved.lanes.some((lane) => + lane.kind === kind && lane.name === name && lane.fingerprint === fingerprint)); + }); + if (!existing) { + const result = askQuestion(questions.filter((entry) => entry.key !== key), { + key, question: PR_CI_QUESTION, chat, prCi: { head, lanes: scope, position }, + }); + const question = copy(choiceText(key)); + store(owner, home, result.questions); + return { choice: null, question }; + } + const { run, open } = choiceText(existing.key); + let answer = null; + for (const reply of userReplies(transcript, existing.prCi.position, chat, runtime)) { + if (reply === run || reply === open) answer = reply; + } + if (!answer) return { choice: null }; + if (existing.answer !== answer || !existing.prCi.confirmedInTranscript) { + const updated = answerQuestion(questions, { key: existing.key, answer }); + updated.result.prCi = { ...existing.prCi, confirmedInTranscript: true }; + store(owner, home, updated.questions); + } + return { choice: answer === open ? "open" : "run" }; +} + /** Moves startup questions onto a new session record and clears the startup file. */ export function adoptStartupQuestions(worktree, home = os.homedir()) { - const startup = readStartup(home); + const saved = readStartup(home); + const startup = saved.filter((entry) => !entry.prCi); if (!startup.length) { return []; } @@ -138,7 +205,7 @@ export function adoptStartupQuestions(worktree, home = os.homedir()) { } } writeSessionRecord(worktree, { ...record, questions: merged }); - rmSync(startupFile(home), { force: true }); + clearStartupQuestions(home, saved); return merged; } @@ -154,7 +221,16 @@ function readStartup(home) { function writeStartup(home, questions) { const file = startupFile(home); mkdirSync(path.dirname(file), { recursive: true }); - writeFileSync(file, `${JSON.stringify({ questions }, null, 2)}\n`, { mode: 0o600 }); + const temporary = `${file}.${process.pid}.tmp`; + writeFileSync(temporary, `${JSON.stringify({ questions }, null, 2)}\n`, { mode: 0o600 }); + renameSync(temporary, file); +} + +/** Startup resets and adoption leave other chats' head-bound PR decisions available. */ +function clearStartupQuestions(home, questions) { + const decisions = questions.filter((entry) => entry.prCi); + if (decisions.length) writeStartup(home, decisions); + else rmSync(startupFile(home), { force: true }); } function load(worktree, home) { @@ -234,7 +310,7 @@ function run(argv, home = os.homedir()) { if (worktree) { throw new Error("reset clears only the questions kept before a session exists; it takes no --worktree."); } - rmSync(startupFile(home), { force: true }); + clearStartupQuestions(home, readStartup(home)); return { questions: [] }; case "ask": { requireText("--question", values.question); @@ -253,7 +329,9 @@ function run(argv, home = os.homedir()) { return result; } case "answer": { - const { questions, result } = answerQuestion(load(worktree, home), { key: values.key, answer: values.answer }); + const saved = load(worktree, home); + if (saved.some((entry) => entry.key === values.key && entry.prCi)) throw new Error("The new-PR decision is recorded from the user's chat reply."); + const { questions, result } = answerQuestion(saved, { key: values.key, answer: values.answer }); store(worktree, home, questions); return result; } diff --git a/plugins/vibe/tools/python/test_pr_takeover_skill_contract.py b/plugins/vibe/tools/python/test_pr_takeover_skill_contract.py index 8e411d5e..4c2235ba 100644 --- a/plugins/vibe/tools/python/test_pr_takeover_skill_contract.py +++ b/plugins/vibe/tools/python/test_pr_takeover_skill_contract.py @@ -25,7 +25,7 @@ def _section(text: str, heading: str) -> str: def test_both_manifests_publish_the_same_new_skill_version() -> None: claude = json.loads(skill_split.read(PLUGIN / ".claude-plugin" / "plugin.json")) codex = json.loads(skill_split.read(PLUGIN / ".codex-plugin" / "plugin.json")) - assert claude["version"] == codex["version"] == "1.1.123" + assert claude["version"] == codex["version"] == "1.1.124" assert codex["skills"] == "./skills/" assert skill_split.read(SKILL).startswith("---\nname: pr-takeover\n") diff --git a/plugins/vibe/tools/python/test_vibe_ws8_load_contract.py b/plugins/vibe/tools/python/test_vibe_ws8_load_contract.py index 245abc08..db0dccce 100644 --- a/plugins/vibe/tools/python/test_vibe_ws8_load_contract.py +++ b/plugins/vibe/tools/python/test_vibe_ws8_load_contract.py @@ -150,8 +150,8 @@ def test_the_flags_the_skill_uses_exist_in_verify_run_and_the_worker_can_join() def test_current_version_and_prior_release_notes() -> None: for manifest in (".claude-plugin", ".codex-plugin"): - assert json.loads(skill_split.read(PLUGIN_ROOT / manifest / "plugin.json"))["version"] == "1.1.123", manifest - assert "Version `1.1.123`" in skill_split.read(PLUGIN_ROOT / "README.md") + assert json.loads(skill_split.read(PLUGIN_ROOT / manifest / "plugin.json"))["version"] == "1.1.124", manifest + assert "Version `1.1.124`" in skill_split.read(PLUGIN_ROOT / "README.md") changelog = skill_split.read(PLUGIN_ROOT.parents[1] / "CHANGELOG.md") assert "### vibe v1.1.121" in changelog assert "### vibe v1.1.76" in changelog From 6a79eb7da2209a5c86688487caa9f9690d6f18a7 Mon Sep 17 00:00:00 2001 From: Daniel Ochoa Date: Thu, 3 Dec 2026 16:25:10 -0600 Subject: [PATCH 2/2] ISS-15125: Count only the branch's own test changes for the proof cutoff; pin the narrowed question rule --- CHANGELOG.md | 4 +- .../lib/handoff/scripts/proof-receipts.mjs | 22 +++---- .../lib/handoff/scripts/proof-scope.mjs | 36 +++++++---- plugins/vibe-closedloop/skills/vibe/SKILL.md | 2 + plugins/vibe/hooks/pr-create-full-ci.test.mjs | 12 +++- .../lib/handoff/scripts/proof-receipts.mjs | 22 +++---- .../vibe/lib/handoff/scripts/proof-scope.mjs | 36 +++++++---- .../lib/handoff/scripts/proof-scope.test.mjs | 61 ++++++++++++++++++- plugins/vibe/skills/vibe/SKILL.md | 2 + .../python/test_vibe_1076_lessons_contract.py | 3 +- 10 files changed, 149 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 138fef18..137f992d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). #### Fixed -- Push-check applies the December 1 mutation-proof cutoff to missing decision-table inventory runs (ISS-15125). -- Across all plugin Markdown, including eval prompts and graders, the release is about 80 words longer than v1.1.123. The count covers the source files in `plugins/vibe` and excludes the generated ClosedLoop edition. +- Push-check, handoff, and PR creation apply the December 1 mutation-proof cutoff to missing decision-table inventory runs. Test changes inherited from main do not count as branch edits (ISS-15125). +- Across all plugin Markdown, including eval prompts and graders, the release is about 97 words longer than v1.1.123. The count covers the source files in `plugins/vibe` and excludes the generated ClosedLoop edition. ### vibe v1.1.123 diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs index 584d6ca4..9954bb04 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/proof-receipts.mjs @@ -51,7 +51,7 @@ import { isCollectedTestFile, isTestFile } from "../../../skills/vibe/scripts/te import { flagKeyProblems } from "../../../skills/vibe/scripts/flag-keys.mjs"; import { testIntegrityCandidates, testIntegrityProblems } from "../../../skills/handoff/scripts/test-integrity.mjs"; import { isEntryPoint } from "../../../shared/plugin-roots.mjs"; -import { acceptedSnapshots, ProofExemption, proofExemptions, skipsCase } from "./proof-scope.mjs"; +import { acceptedSnapshots, outsideCutoff, ProofExemption, proofExemptions, skipsCase } from "./proof-scope.mjs"; const RECEIPT_FILE = "vibe-proof-receipt.json"; const KINDS = new Set(["bug-fix", "feature"]); @@ -646,7 +646,7 @@ export function writeMutantInventory(worktree) { } /** Scope missing inventory runs by the ruling only. A push alone cannot excuse a post-ruling inventory entry. */ -function legacyInventoryCases(worktree, head, snapshots, missing) { +function cutoffInventoryCases(worktree, head, snapshots, missing) { if (!snapshots.length || !missing.length) return () => false; const sources = new Map(); for (const file of new Set(missing.map((row) => row.path))) { @@ -658,13 +658,13 @@ function legacyInventoryCases(worktree, head, snapshots, missing) { const exempt = proofExemptions(worktree, { snapshots, head, tests }); return ({ path: file, case: name }) => { const source = sources.get(file); - if (source === undefined || exempt.testCase(file, source, name) !== ProofExemption.Ruling) return false; + if (source === undefined || !outsideCutoff(exempt.testCase(file, source, name))) return false; return caseText(file, source, name) !== null; }; } /** Compare the table with the latest runs that still hold, preserving checks on logged outcomes. */ -function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshots }) { +function mutantInventoryProblems(worktree, receipt, view, { head, cutoffSnapshots }) { let rows = null; try { const table = sessionDecisionTable(realpathSync(worktree)); @@ -678,11 +678,11 @@ function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshot } const key = (entry) => JSON.stringify([entry.path, entry.case, entry.mutation]); const listed = new Set(rows.map(key)); - const grandfathered = legacyInventoryCases(worktree, head, rulingSnapshots, rows.filter((row) => !runs.has(key(row)))); + const outsideScope = cutoffInventoryCases(worktree, head, cutoffSnapshots, rows.filter((row) => !runs.has(key(row)))); for (const row of rows) { const run = runs.get(key(row)); if (!run) { - if (!grandfathered(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + if (!outsideScope(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); } else if (run.outcome !== row.outcome) problems.push(`the decision table says "${row.mutation}" for ${row.path} case "${row.case}" was ${row.outcome}; the mutation log shows ${run.outcome}`); } @@ -718,9 +718,9 @@ const quotedIn = (entry) => entry.in ?? "ticket"; * branch. With `head` the committed tree is checked (fleet push-check); * otherwise the worktree's current source is checked. `accepted` names the heads * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs). - * Only push-check passes a pushed head and uses the ruling cutoff for missing inventory runs. + * Only push-check passes a pushed head. Every path uses the ruling cutoff for missing inventory runs. */ -export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {}, pushCheck = false } = {}) { +export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {} } = {}) { const record = readSessionRecord(worktree); const problems = flagKeyProblems(record).map((problem) => `flag keys: ${problem}`); const ticket = sessionLiveTicket(record ?? {}); @@ -741,9 +741,9 @@ export function proofGateProblems(worktree, { base, head, bodyText = "", ticketT ...runbookCommands(worktree, comparisonBase, fullHead)], current, ticket)); const view = sourceView(worktree, fullHead, current); const snapshots = acceptedSnapshots(worktree, { comparisonBase, head: fullHead, ...accepted }); - const rulingSnapshots = pushCheck ? snapshots.filter(({ exemption }) => exemption === ProofExemption.Ruling) : []; + const cutoffSnapshots = snapshots.filter(({ exemption }) => outsideCutoff(exemption)); problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, snapshots), - ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, rulingSnapshots })); + ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, cutoffSnapshots })); return problems; } @@ -784,7 +784,7 @@ export function pushReadyProofProblems(worktree, { base, head, bodyFile, witness const ticketFile = evidence.ticket?.path && existsSync(evidence.ticket.path) ? evidence.ticket.path : null; return proofGateProblems(worktree, { base, head, bodyText: read(bodyFile ?? evidence.body?.path), ticketText: proofTicketText(ticketFile, (evidence.members ?? []).map((saved) => saved.path)), runs: JSON.parse(read(evidence.runs?.path) || "{}"), - accepted: { pushed, passed: passedGateHeads(worktree) }, pushCheck: true }); + accepted: { pushed, passed: passedGateHeads(worktree) } }); } /** The last head that passed the handoff gate, as a list for `accepted.passed`; empty when none is recorded. */ diff --git a/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs b/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs index cdcb99ad..8e5dd9f9 100644 --- a/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs +++ b/plugins/vibe-closedloop/lib/handoff/scripts/proof-scope.mjs @@ -1,14 +1,15 @@ // Which changed test cases the mutation-proof gate asks about. The gate diffs a branch against its merge base, so a // long-lived branch built before the mutation-proof ruling (operator ruling, 2026-12-01) was refused for every test it // ever changed. The scope rule (operator rulings, 2026-12-02): -// - A case whose text at the checked source equals its text at the branch's last commit before the 2026-12-01 ruling -// (first-parent, by committer time) is never asked about, even when an old proof of it expired. +// - A case unchanged from the branch's last commit before the 2026-12-01 ruling (first-parent, by committer time), +// after syncing it with the main the branch actually merged, is never asked about, even if its old proof expired. +// - A case unchanged from the merged main also needs no proof, including a case taken verbatim in a conflict resolution. // - At push-check only, a case unchanged since the upstream head (the last pushed head) is not asked about. The handoff // gate and PR create do not count a pushed head: a redeploy push never passed the gate. // - At all three, a case unchanged since the last head that passed the handoff gate is asked about only when its // recorded mutation proof no longer holds (its test or the code it tests changed), as the 2026-12-01 ruling says. // A case is unchanged since a snapshot when no line inside it was added or deleted between the snapshot, merged with the -// comparison base the way a sync with main merges it, and the checked source. A deletion inside an old case brings it +// corresponding base the way a sync with main merges it, and the checked source. A deletion inside an old case brings it // back into scope; what a sync with main brought into a branch's old case does not. import { execFileSync, spawnSync } from "node:child_process"; @@ -17,18 +18,20 @@ import { addedLineNumbers, changedTestCases } from "./proof-parsers.mjs"; /** The 2026-12-01 mutation-proof ruling, about 12:55 PM CST. */ export const MUTATION_RULING_AT = "2026-12-01T18:55:00Z"; -/** Why a changed case is out of the gate's scope. Ruling and Pushed skip it; Passed still asks about an expired proof. */ -export const ProofExemption = Object.freeze({ Ruling: "ruling", Pushed: "pushed", Passed: "passed" }); +/** Why a case needs no new proof. Passed still asks about an expired proof. */ +export const ProofExemption = Object.freeze({ Ruling: "ruling", Main: "main", Pushed: "pushed", Passed: "passed" }); -const STRENGTH = Object.freeze({ [ProofExemption.Ruling]: 2, [ProofExemption.Pushed]: 2, [ProofExemption.Passed]: 1 }); +const STRENGTH = Object.freeze({ [ProofExemption.Ruling]: 2, [ProofExemption.Main]: 2, [ProofExemption.Pushed]: 2, [ProofExemption.Passed]: 1 }); + +/** Whether the case has no branch change since the ruling, independent of prior proof or push evidence. */ +export const outsideCutoff = (exemption) => exemption === ProofExemption.Ruling || exemption === ProofExemption.Main; /** Whether an exemption skips the case outright, with no question about an expired proof. */ -export const skipsCase = (exemption) => exemption === ProofExemption.Ruling || exemption === ProofExemption.Pushed; +export const skipsCase = (exemption) => outsideCutoff(exemption) || exemption === ProofExemption.Pushed; /** - * The commits whose cases the gate already accepted, each with its exemption: the branch's last commit before the ruling - * and each given pushed or passed head. A snapshot inside the comparison base adds nothing and is dropped, and so is a - * head this repository cannot resolve. + * Snapshots for the cutoff and each pushed or passed head. Keep the main and ruling trees even when they are in the + * base: inventory rows can name cases outside the changed-test scan. Pushed and passed heads in the base add nothing. */ export function acceptedSnapshots(worktree, { comparisonBase, head, pushed = [], passed = [] }) { const git = (...args) => execFileSync("git", ["-C", worktree, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim(); @@ -40,9 +43,20 @@ export function acceptedSnapshots(worktree, { comparisonBase, head, pushed = [], try { git("merge-base", "--is-ancestor", sha, comparisonBase); return; } catch { /* Not inside the base: it counts. */ } snapshots.push({ exemption, sha, tree: syncedTree(worktree, sha, comparisonBase) }); }; + // A board row can pin an older base, or a PR can target a stack parent. Only use main commits in the checked head. + let mergedMain = ""; + try { mergedMain = git("merge-base", "--", head ?? "HEAD", "refs/remotes/origin/main"); } catch { /* No shared fetched main. */ } + if (mergedMain) snapshots.push({ exemption: ProofExemption.Main, sha: mergedMain, tree: mergedMain }); let ruling = ""; try { ruling = git("rev-list", "-1", "--first-parent", `--before=${MUTATION_RULING_AT}`, head ?? "HEAD"); } catch { /* No such commit. */ } - add(ProofExemption.Ruling, ruling); + if (ruling) { + let rulingBase = comparisonBase; + if (mergedMain && mergedMain !== comparisonBase) { + try { git("merge-base", "--is-ancestor", mergedMain, comparisonBase); } + catch { rulingBase = mergedMain; } + } + snapshots.push({ exemption: ProofExemption.Ruling, sha: ruling, tree: syncedTree(worktree, ruling, rulingBase) }); + } for (const ref of pushed) add(ProofExemption.Pushed, ref); for (const ref of passed) add(ProofExemption.Passed, ref); return snapshots; diff --git a/plugins/vibe-closedloop/skills/vibe/SKILL.md b/plugins/vibe-closedloop/skills/vibe/SKILL.md index d9cb4f46..7f1556d1 100644 --- a/plugins/vibe-closedloop/skills/vibe/SKILL.md +++ b/plugins/vibe-closedloop/skills/vibe/SKILL.md @@ -879,6 +879,8 @@ For a new pull request with unwitnessed CI or package checks, the PR-create hook records the question itself. Wait for the person's chat reply, or act on their choice to run the checks. The hook records and verifies the reply for that head. Ask once and use the reply format shown by the hook. +The CI decision holds creation of the new pull request. Other questions +never hold a pull request. 1. Before asking, run `node scripts/session-questions.mjs ask --key --question "" --default "" diff --git a/plugins/vibe/hooks/pr-create-full-ci.test.mjs b/plugins/vibe/hooks/pr-create-full-ci.test.mjs index 0f4fe53c..a15f23e5 100644 --- a/plugins/vibe/hooks/pr-create-full-ci.test.mjs +++ b/plugins/vibe/hooks/pr-create-full-ci.test.mjs @@ -47,9 +47,17 @@ test("an unwitnessed new PR asks once, lists jobs and limitations, and opens onl const r = ciQuestion(t); const pending = r.create(); assert.equal(pending?.decision, "deny", "a quoted override in the PR body cannot waive the question"); - assert.match(pending.systemMessage ?? "", /plugin-version-bump \(can’t run on this machine/); - assert.match(pending.systemMessage ?? "", /node-tests \(can’t run on this machine/); const answer = openReply(pending); + const code = answer.split(" ").at(-1); + assert.equal(pending.systemMessage, [ + "This pull request is missing results for the following checks:", + "", + "- plugin-version-bump (can’t run on this machine, use the CI runner or remote workflow replay)", + "- node-tests (can’t run on this machine, use the CI runner or remote workflow replay)", + "", + "Should I run the missing checks or open the pull request without these results?", + `Reply with “Run the missing checks ${code}” or “Open without these results ${code}”.`, + ].join("\n")); assert.equal(r.create()?.systemMessage, undefined, "the pending question is not shown twice"); const { questions } = r.decisionRecord(); assert.equal(questions.length, 1); diff --git a/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs b/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs index 584d6ca4..9954bb04 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-receipts.mjs @@ -51,7 +51,7 @@ import { isCollectedTestFile, isTestFile } from "../../../skills/vibe/scripts/te import { flagKeyProblems } from "../../../skills/vibe/scripts/flag-keys.mjs"; import { testIntegrityCandidates, testIntegrityProblems } from "../../../skills/handoff/scripts/test-integrity.mjs"; import { isEntryPoint } from "../../../shared/plugin-roots.mjs"; -import { acceptedSnapshots, ProofExemption, proofExemptions, skipsCase } from "./proof-scope.mjs"; +import { acceptedSnapshots, outsideCutoff, ProofExemption, proofExemptions, skipsCase } from "./proof-scope.mjs"; const RECEIPT_FILE = "vibe-proof-receipt.json"; const KINDS = new Set(["bug-fix", "feature"]); @@ -646,7 +646,7 @@ export function writeMutantInventory(worktree) { } /** Scope missing inventory runs by the ruling only. A push alone cannot excuse a post-ruling inventory entry. */ -function legacyInventoryCases(worktree, head, snapshots, missing) { +function cutoffInventoryCases(worktree, head, snapshots, missing) { if (!snapshots.length || !missing.length) return () => false; const sources = new Map(); for (const file of new Set(missing.map((row) => row.path))) { @@ -658,13 +658,13 @@ function legacyInventoryCases(worktree, head, snapshots, missing) { const exempt = proofExemptions(worktree, { snapshots, head, tests }); return ({ path: file, case: name }) => { const source = sources.get(file); - if (source === undefined || exempt.testCase(file, source, name) !== ProofExemption.Ruling) return false; + if (source === undefined || !outsideCutoff(exempt.testCase(file, source, name))) return false; return caseText(file, source, name) !== null; }; } /** Compare the table with the latest runs that still hold, preserving checks on logged outcomes. */ -function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshots }) { +function mutantInventoryProblems(worktree, receipt, view, { head, cutoffSnapshots }) { let rows = null; try { const table = sessionDecisionTable(realpathSync(worktree)); @@ -678,11 +678,11 @@ function mutantInventoryProblems(worktree, receipt, view, { head, rulingSnapshot } const key = (entry) => JSON.stringify([entry.path, entry.case, entry.mutation]); const listed = new Set(rows.map(key)); - const grandfathered = legacyInventoryCases(worktree, head, rulingSnapshots, rows.filter((row) => !runs.has(key(row)))); + const outsideScope = cutoffInventoryCases(worktree, head, cutoffSnapshots, rows.filter((row) => !runs.has(key(row)))); for (const row of rows) { const run = runs.get(key(row)); if (!run) { - if (!grandfathered(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); + if (!outsideScope(row)) problems.push(`the decision table's mutant inventory lists "${row.mutation}" for ${row.path} case "${row.case}", for which the mutation log has no run that still holds`); } else if (run.outcome !== row.outcome) problems.push(`the decision table says "${row.mutation}" for ${row.path} case "${row.case}" was ${row.outcome}; the mutation log shows ${run.outcome}`); } @@ -718,9 +718,9 @@ const quotedIn = (entry) => entry.in ?? "ticket"; * branch. With `head` the committed tree is checked (fleet push-check); * otherwise the worktree's current source is checked. `accepted` names the heads * whose cases the gate already accepted ({ pushed, passed }: proof-scope.mjs). - * Only push-check passes a pushed head and uses the ruling cutoff for missing inventory runs. + * Only push-check passes a pushed head. Every path uses the ruling cutoff for missing inventory runs. */ -export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {}, pushCheck = false } = {}) { +export function proofGateProblems(worktree, { base, head, bodyText = "", ticketText: suppliedTicket, runs = {}, accepted = {} } = {}) { const record = readSessionRecord(worktree); const problems = flagKeyProblems(record).map((problem) => `flag keys: ${problem}`); const ticket = sessionLiveTicket(record ?? {}); @@ -741,9 +741,9 @@ export function proofGateProblems(worktree, { base, head, bodyText = "", ticketT ...runbookCommands(worktree, comparisonBase, fullHead)], current, ticket)); const view = sourceView(worktree, fullHead, current); const snapshots = acceptedSnapshots(worktree, { comparisonBase, head: fullHead, ...accepted }); - const rulingSnapshots = pushCheck ? snapshots.filter(({ exemption }) => exemption === ProofExemption.Ruling) : []; + const cutoffSnapshots = snapshots.filter(({ exemption }) => outsideCutoff(exemption)); problems.push(...testProofProblems(worktree, comparisonBase, fullHead, receipt, current, runs, view, snapshots), - ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, rulingSnapshots })); + ...mutantInventoryProblems(worktree, receipt, view, { head: fullHead, cutoffSnapshots })); return problems; } @@ -784,7 +784,7 @@ export function pushReadyProofProblems(worktree, { base, head, bodyFile, witness const ticketFile = evidence.ticket?.path && existsSync(evidence.ticket.path) ? evidence.ticket.path : null; return proofGateProblems(worktree, { base, head, bodyText: read(bodyFile ?? evidence.body?.path), ticketText: proofTicketText(ticketFile, (evidence.members ?? []).map((saved) => saved.path)), runs: JSON.parse(read(evidence.runs?.path) || "{}"), - accepted: { pushed, passed: passedGateHeads(worktree) }, pushCheck: true }); + accepted: { pushed, passed: passedGateHeads(worktree) } }); } /** The last head that passed the handoff gate, as a list for `accepted.passed`; empty when none is recorded. */ diff --git a/plugins/vibe/lib/handoff/scripts/proof-scope.mjs b/plugins/vibe/lib/handoff/scripts/proof-scope.mjs index cdcb99ad..8e5dd9f9 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-scope.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-scope.mjs @@ -1,14 +1,15 @@ // Which changed test cases the mutation-proof gate asks about. The gate diffs a branch against its merge base, so a // long-lived branch built before the mutation-proof ruling (operator ruling, 2026-12-01) was refused for every test it // ever changed. The scope rule (operator rulings, 2026-12-02): -// - A case whose text at the checked source equals its text at the branch's last commit before the 2026-12-01 ruling -// (first-parent, by committer time) is never asked about, even when an old proof of it expired. +// - A case unchanged from the branch's last commit before the 2026-12-01 ruling (first-parent, by committer time), +// after syncing it with the main the branch actually merged, is never asked about, even if its old proof expired. +// - A case unchanged from the merged main also needs no proof, including a case taken verbatim in a conflict resolution. // - At push-check only, a case unchanged since the upstream head (the last pushed head) is not asked about. The handoff // gate and PR create do not count a pushed head: a redeploy push never passed the gate. // - At all three, a case unchanged since the last head that passed the handoff gate is asked about only when its // recorded mutation proof no longer holds (its test or the code it tests changed), as the 2026-12-01 ruling says. // A case is unchanged since a snapshot when no line inside it was added or deleted between the snapshot, merged with the -// comparison base the way a sync with main merges it, and the checked source. A deletion inside an old case brings it +// corresponding base the way a sync with main merges it, and the checked source. A deletion inside an old case brings it // back into scope; what a sync with main brought into a branch's old case does not. import { execFileSync, spawnSync } from "node:child_process"; @@ -17,18 +18,20 @@ import { addedLineNumbers, changedTestCases } from "./proof-parsers.mjs"; /** The 2026-12-01 mutation-proof ruling, about 12:55 PM CST. */ export const MUTATION_RULING_AT = "2026-12-01T18:55:00Z"; -/** Why a changed case is out of the gate's scope. Ruling and Pushed skip it; Passed still asks about an expired proof. */ -export const ProofExemption = Object.freeze({ Ruling: "ruling", Pushed: "pushed", Passed: "passed" }); +/** Why a case needs no new proof. Passed still asks about an expired proof. */ +export const ProofExemption = Object.freeze({ Ruling: "ruling", Main: "main", Pushed: "pushed", Passed: "passed" }); -const STRENGTH = Object.freeze({ [ProofExemption.Ruling]: 2, [ProofExemption.Pushed]: 2, [ProofExemption.Passed]: 1 }); +const STRENGTH = Object.freeze({ [ProofExemption.Ruling]: 2, [ProofExemption.Main]: 2, [ProofExemption.Pushed]: 2, [ProofExemption.Passed]: 1 }); + +/** Whether the case has no branch change since the ruling, independent of prior proof or push evidence. */ +export const outsideCutoff = (exemption) => exemption === ProofExemption.Ruling || exemption === ProofExemption.Main; /** Whether an exemption skips the case outright, with no question about an expired proof. */ -export const skipsCase = (exemption) => exemption === ProofExemption.Ruling || exemption === ProofExemption.Pushed; +export const skipsCase = (exemption) => outsideCutoff(exemption) || exemption === ProofExemption.Pushed; /** - * The commits whose cases the gate already accepted, each with its exemption: the branch's last commit before the ruling - * and each given pushed or passed head. A snapshot inside the comparison base adds nothing and is dropped, and so is a - * head this repository cannot resolve. + * Snapshots for the cutoff and each pushed or passed head. Keep the main and ruling trees even when they are in the + * base: inventory rows can name cases outside the changed-test scan. Pushed and passed heads in the base add nothing. */ export function acceptedSnapshots(worktree, { comparisonBase, head, pushed = [], passed = [] }) { const git = (...args) => execFileSync("git", ["-C", worktree, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim(); @@ -40,9 +43,20 @@ export function acceptedSnapshots(worktree, { comparisonBase, head, pushed = [], try { git("merge-base", "--is-ancestor", sha, comparisonBase); return; } catch { /* Not inside the base: it counts. */ } snapshots.push({ exemption, sha, tree: syncedTree(worktree, sha, comparisonBase) }); }; + // A board row can pin an older base, or a PR can target a stack parent. Only use main commits in the checked head. + let mergedMain = ""; + try { mergedMain = git("merge-base", "--", head ?? "HEAD", "refs/remotes/origin/main"); } catch { /* No shared fetched main. */ } + if (mergedMain) snapshots.push({ exemption: ProofExemption.Main, sha: mergedMain, tree: mergedMain }); let ruling = ""; try { ruling = git("rev-list", "-1", "--first-parent", `--before=${MUTATION_RULING_AT}`, head ?? "HEAD"); } catch { /* No such commit. */ } - add(ProofExemption.Ruling, ruling); + if (ruling) { + let rulingBase = comparisonBase; + if (mergedMain && mergedMain !== comparisonBase) { + try { git("merge-base", "--is-ancestor", mergedMain, comparisonBase); } + catch { rulingBase = mergedMain; } + } + snapshots.push({ exemption: ProofExemption.Ruling, sha: ruling, tree: syncedTree(worktree, ruling, rulingBase) }); + } for (const ref of pushed) add(ProofExemption.Pushed, ref); for (const ref of passed) add(ProofExemption.Passed, ref); return snapshots; diff --git a/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs b/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs index 1db259bb..53e0b24a 100644 --- a/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs +++ b/plugins/vibe/lib/handoff/scripts/proof-scope.test.mjs @@ -4,6 +4,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "nod import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; +import { pushProofLines } from "../../../skills/fleet-orchestrator/scripts/push-proof.mjs"; import { passedGateHeads, proofGateProblems, pushReadyProofProblems, readProofReceipt, recordGatePass, recordMutationProof } from "./proof-receipts.mjs"; import { dayFromRuling, LONG_LIVED_SHAPE, longLivedBranch } from "./long-lived-branch-fixture.mjs"; import { sourceIdentity } from "../../vibe/scripts/tested-head.mjs"; @@ -60,7 +61,7 @@ test("AC-1 a line deleted after the ruling inside a case committed before it bri assert.deepEqual(cases(gate(r, { head })), ["old one"]); }); -test("push-check only asks for missing inventory runs for cases added or edited after the ruling", (t) => { +test("missing inventory runs are required only for cases added or edited after the ruling", (t) => { const r = repo(t); const original = [["old unchanged", " assert.equal(add(1, 2), 3);"], ["old edited", " assert.equal(add(2, 2), 4);"]]; r.write("src/add.test.mjs", testFile(original)); @@ -76,7 +77,63 @@ test("push-check only asks for missing inventory runs for cases added or edited const fromInventory = (problems) => cases(problems.filter((problem) => problem.includes("mutant inventory lists"))); assert.deepEqual(fromInventory(pushReadyProofProblems(r.worktree, { base: r.main, head, pushed: [head] })), ["added later", "invalid case name", "old edited"]); - assert.deepEqual(fromInventory(gate(r, { head })), [...names].sort(), "handoff keeps its inventory check"); + assert.deepEqual(fromInventory(gate(r)), ["added later", "invalid case name", "old edited"], "handoff and PR create"); +}); + +test("a main merge alone does not reopen a pre-cutoff case, but a branch edit does", (t) => { + const r = repo(t); + const file = "src/add.test.mjs"; + const name = "pre-cutoff case"; + const writeCase = (body) => r.write(file, testFile([[name, body]])); + r.git(["checkout", "-q", "main"]); + writeCase(" assert.equal(add(1, 2), 3);"); + const pinned = r.commit("pre-existing test", BEFORE); + r.git(["checkout", "-q", "vibe/scope"]); + r.git(["merge", "-q", "--ff-only", "main"]); + r.write("src/branch.mjs", "export const branch = true;\n"); + r.commit("unrelated branch work", BEFORE); + const fork = r.git(["rev-parse", "HEAD"]); + r.git(["checkout", "-q", "main"]); + writeCase(" assert.equal(add(2, 3), 5);"); + const mergedMain = r.commit("main edits the test after the ruling", AFTER); + // A newer unmerged edit must not replace the actual merge parent as the comparison snapshot. + writeCase(" assert.equal(add(8, 9), 17);"); + r.commit("main advances again", dayFromRuling(2)); + r.git(["update-ref", "refs/remotes/origin/main", "main"]); + r.git(["checkout", "-q", "vibe/scope"]); + r.git(["merge", "-q", "--no-edit", mergedMain], dayFromRuling(3)); + const table = sessionDecisionTable(r.worktree); + mkdirSync(path.dirname(table), { recursive: true }); + writeFileSync(table, `## Mutant Inventory\n\n| Test file | Case | Mutation | Outcome |\n| --- | --- | --- | --- |\n| ${file} | ${name} | change add | killed |\n`); + + const check = (head) => [ + pushReadyProofProblems(r.worktree, { base: pinned, head }), + gate(r, { base: pinned }), + gate(r, { base: mergedMain }), + ]; + const board = (head) => pushProofLines("w", { worktree: r.worktree, branch: "vibe/scope" }, + { head, trustedBase: () => pinned, published: () => null }).refuse; + const merged = r.git(["rev-parse", "HEAD"]); + assert.deepEqual(check(merged), [[], [], []]); + assert.deepEqual(board(merged), []); + + writeCase(" assert.equal(add(3, 4), 7);"); + const edited = r.commit("branch edits the same case", dayFromRuling(4)); + for (const problems of check(edited)) { + assert.equal(problems.length, 2); + assert.match(problems[0], NO_PROOF); + assert.match(problems[1], /mutant inventory lists/); + assert.deepEqual(cases(problems).filter((caseName) => caseName === name), [name, name]); + } + assert.equal(board(edited).filter((line) => line.startsWith("PROOF-MISSING")).length, 2); + + r.git(["checkout", "-q", "-b", "vibe/resolve", fork]); + writeCase(" assert.equal(add(6, 7), 13);"); + r.commit("branch edits the assertion before the ruling", BEFORE); + assert.throws(() => r.git(["merge", "-q", "--no-edit", mergedMain], dayFromRuling(3)), /Command failed/); + writeCase(" assert.equal(add(2, 3), 5);"); + const resolved = r.commit("resolve the merge by accepting main's version of the case", dayFromRuling(3)); + assert.deepEqual(check(resolved), [[], [], []]); }); test("AC-2 a long-lived branch with many inherited cases, a main sync and one new case gets exactly one refusal", (t) => { diff --git a/plugins/vibe/skills/vibe/SKILL.md b/plugins/vibe/skills/vibe/SKILL.md index ee5643a0..06d521c1 100644 --- a/plugins/vibe/skills/vibe/SKILL.md +++ b/plugins/vibe/skills/vibe/SKILL.md @@ -888,6 +888,8 @@ For a new pull request with unwitnessed CI or package checks, the PR-create hook records the question itself. Wait for the person's chat reply, or act on their choice to run the checks. The hook records and verifies the reply for that head. Ask once and use the reply format shown by the hook. +The CI decision holds creation of the new pull request. Other questions +never hold a pull request. 1. Before asking, run `node scripts/session-questions.mjs ask --key --question "" --default "" diff --git a/plugins/vibe/tools/python/test_vibe_1076_lessons_contract.py b/plugins/vibe/tools/python/test_vibe_1076_lessons_contract.py index 96dd3555..543c8195 100644 --- a/plugins/vibe/tools/python/test_vibe_1076_lessons_contract.py +++ b/plugins/vibe/tools/python/test_vibe_1076_lessons_contract.py @@ -84,7 +84,8 @@ def test_stale_prs_and_unanswered_questions_are_flagged_and_answered() -> None: assert "On `STALE-PR`" in fleet and "ask the owning writer for an ETA, unblock it, or reassign it" in fleet assert "no push for 45 minutes" in fleet assert "cadence never authorizes checkpoint commits" in fleet - assert "A question never holds a pull request" in _text(VIBE / "SKILL.md") + vibe = " ".join(_text(VIBE / "SKILL.md").split()) + assert "The CI decision holds creation of the new pull request. Other questions never hold a pull request." in vibe assert "board.mjs question" in _text(FLEET / "references" / "templates.md")