diff --git a/CHANGELOG.md b/CHANGELOG.md index 89354071..0ed38043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ 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.119 + +#### Fixed + +- ISS-15030: `cloud-worker.mjs check` no longer fails lane-tools only because the last capability proof is older than 30 minutes. A stale proof that measured every tool present asks only for a fresh capability run. The setup script is printed only when a tool was measured missing or there was never a proof. +- The environment-setup row passes after a run that succeeded, and the api row names the error a failed `claude -p` reports instead of "result success". +- A cloud-capabilities validate request without `repository` takes it from the worktree's origin. +- A new chrome-account row says a script cannot verify the Chrome and Claude in Chrome extension account, and names the manual check. +- The merge guard reads a pull request's full paginated file list when GitHub's view stops at 100 files. Only a failed listing is treated as changing UI. +- The fleet launch guard lets a fleet chat start read-only and operational workers. A plain code-writing worker starts only when the program's rulings.md quotes an operator ruling naming each of its tickets. The brief declares `Worker role:` and `Tickets:`; a brief with no role is a writer. +- Across all plugin Markdown, including eval prompts and graders, the release is about 0 words longer than v1.1.118. The count covers the source files in `plugins/vibe` and excludes the generated ClosedLoop edition. + ### vibe v1.1.118 #### Added diff --git a/plugins/vibe-closedloop/.claude-plugin/plugin.json b/plugins/vibe-closedloop/.claude-plugin/plugin.json index b0c614c5..be87bfd2 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.118", + "version": "1.1.119", "dependencies": [ "closedloop-core", "vibe-core" diff --git a/plugins/vibe-closedloop/.codex-plugin/plugin.json b/plugins/vibe-closedloop/.codex-plugin/plugin.json index d53fb815..434c4a81 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.118", + "version": "1.1.119", "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 6b3103b1..6b7da1ab 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.118` contains 17 skills and 17 agents, and no hook manifest: the +Version `1.1.119` 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/agent-guard.mjs b/plugins/vibe-closedloop/hooks/agent-guard.mjs index f2a203c3..85c59b80 100644 --- a/plugins/vibe-closedloop/hooks/agent-guard.mjs +++ b/plugins/vibe-closedloop/hooks/agent-guard.mjs @@ -11,6 +11,9 @@ import { vibeSkillOf } from "../shared/plugin-roots.mjs"; import { vibeScriptPath, vibeSkill } from "../shared/vibe-install.mjs"; import { briefProviderProblem } from "../lib/vibe/scripts/provider-brief.mjs"; import { recordedBinding } from "../lib/vibe/scripts/provider.mjs"; +import { chatProgramDir, defaultHome } from "../lib/fleet-orchestrator/scripts/fleet-home.mjs"; +import { validChat } from "../lib/fleet-orchestrator/scripts/chat-binding.mjs"; +import { operatorTicketRuling } from "../skills/handoff/scripts/rulings-check.mjs"; // Roles are agent names qualified by either vibe plugin. const VIBE_WORKER = /^vibe-[a-z0-9-]+-worker$/; @@ -41,19 +44,53 @@ function rawCodexLaunch(words) { return ["exec", "e", "review"].includes(words[i]); } -/** Fleet-only launch policy. Managed launchers start their child internally and never issue a raw parent tool call. */ -export function fleetLaunchGuard(event, home) { +/** + * Fleet-only launch policy. Managed launchers start their child internally and never issue a raw parent tool call. A + * native Agent brief declares `Worker role: read-only | operational | writer` and `Tickets: `; a brief with no + * role is a writer. A writer that is neither a vibe start nor a helper needs a quoted operator ruling naming each of its + * tickets in the program's rulings.md (operator ruling 2026-12-02). + */ +export function fleetLaunchGuard(event, home, env = process.env) { const input = event?.tool_input; const native = event.tool_name === "Agent"; + const prompt = String(input?.prompt ?? ""); + const lines = prompt.split("\n"); const candidate = native - ? !/^(?:\$vibe\b|\/(?:vibe|vibe-generic):vibe\b)/.test(input?.prompt?.trim() ?? "") + ? !/^(?:\$vibe\b|\/(?:vibe|vibe-generic):vibe\b)/.test(prompt.trim()) && !["Ticket writer:", "Helper branch and worktree:", "Exclusive file allowlist:", "Assignment:", "Test authority:", "Return:"] - .every(field => String(input?.prompt ?? "").split("\n").some(line => line.startsWith(field) && line.slice(field.length).trim())) + .every(field => lines.some(line => line.startsWith(field) && line.slice(field.length).trim())) : typeof input?.command === "string"; if (!candidate || conversationSkill(event, home) !== "fleet-orchestrator") return null; - if (!native && !commandCalls(input.command, eventCwd(event)).some(({ words, value }) => rawCodexLaunch(words.map(word => value(word) ?? word)))) return null; - return deny("Fleet ticket analysis uses dist/claude-worker.mjs with vibe-requirements-worker in sessionless startup mode. " - + "Use dist/codex-reviewer.mjs for review, dist/codex-reviewer.mjs run --role visual-qa-critic --agent-definition for visual QA, or fleet.sh session turn for assigned worker work."); + if (native) { + const problem = plainWriterProblem(lines, event, env); + return problem ? deny(`${problem} ${FLEET_ROUTES}`) : null; + } + if (!commandCalls(input.command, eventCwd(event)).some(({ words, value }) => rawCodexLaunch(words.map(word => value(word) ?? word)))) return null; + return deny(FLEET_ROUTES); +} + +const FLEET_ROUTES = "Fleet ticket analysis uses dist/claude-worker.mjs with vibe-requirements-worker in sessionless startup mode. " + + "Use dist/codex-reviewer.mjs for review, dist/codex-reviewer.mjs run --role visual-qa-critic --agent-definition for visual QA, or fleet.sh session turn for assigned worker work."; +const NON_WRITER_ROLES = new Set(["read-only", "operational"]); + +/** Why a fleet chat may not launch this brief as a plain worker, or null: decided from its declared lines only. */ +function plainWriterProblem(lines, event, env) { + const declared = (field) => lines.find((line) => line.startsWith(field))?.slice(field.length).trim() ?? ""; + if (NON_WRITER_ROLES.has(declared("Worker role:").toLowerCase())) return null; + const tickets = declared("Tickets:").split(/[\s,]+/).filter(Boolean); + const declare = "Declare `Worker role: read-only` or `Worker role: operational` for a worker that writes no code."; + if (tickets.length === 0) { + return `A worker brief with no read-only or operational role is a writer, and a writer names its tickets on a \`Tickets: \` line. ${declare}`; + } + let rulings = ""; + try { + const chat = validChat(event?.session_id); + rulings = readFileSync(path.join(chatProgramDir(defaultHome(env, chat), chat, env).dir, "rulings.md"), "utf8"); + } catch { /* No program or no rulings file: no ticket has a ruling. */ } + const missing = tickets.filter((ticket) => !operatorTicketRuling(rulings, ticket)); + if (missing.length === 0) return null; + return `A plain worker that writes code for ${missing.join(", ")} outside vibe needs the operator's ruling naming that ticket in the program's rulings.md, ` + + `quoted with its source: \`- Ruling YYYY-MM-DD (operator message: ): "" \`. ${declare}`; } /** The refusal for a direct internal vibe-worker launch, or null. */ diff --git a/plugins/vibe-closedloop/hooks/merge-guard.mjs b/plugins/vibe-closedloop/hooks/merge-guard.mjs index ccf78b34..d5e40446 100644 --- a/plugins/vibe-closedloop/hooks/merge-guard.mjs +++ b/plugins/vibe-closedloop/hooks/merge-guard.mjs @@ -104,7 +104,7 @@ export function mergeProblem(command, gh, { cwd, environment = process.env, bind /** * Why `call` would merge a pull request that changes the repository's UI paths without visual QA findings for its - * current head, or null. A file list GitHub cut short is treated as changing UI. + * current head, or null. A file list that stays short after reading every page is treated as changing UI. */ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRemote) { const { checkout, unresolved, remote } = headBranchCheckout(call, headBranch, environment); @@ -119,8 +119,13 @@ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRe try { view = capturedJson(gh(args, { cwd: call.cwd })); } catch (error) { return `${name} refused: visual QA cannot be checked because gh could not list the pull request's files (${String(error?.message ?? error).split("\n")[0]}); rerun when gh can answer`; } const { files, changedFiles, headRefOid, body } = view ?? {}; - const paths = Array.isArray(files) ? files.map((file) => file?.path).filter((file) => typeof file === "string") : []; - const complete = Array.isArray(files) && Number.isInteger(changedFiles) && paths.length >= changedFiles; + let paths = Array.isArray(files) ? files.map((file) => file?.path).filter((file) => typeof file === "string") : []; + let complete = Array.isArray(files) && Number.isInteger(changedFiles) && paths.length >= changedFiles; + // gh pr view lists at most 100 files; a larger pull request is read page by page before it is judged. + if (!complete && Number.isInteger(changedFiles)) { + const listed = pagedFiles(call, gh, changedFiles); + if (listed) [paths, complete] = [listed, true]; + } let gateWitness = checkout ? () => readFileSync(gatePath(checkout), "utf8") : null; let expected = checkout ? undefined : null; if (remote) { @@ -155,6 +160,20 @@ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRe return null; } +/** Every changed file of the pull request from the paginated files API, or null when that listing fails or comes up short. */ +function pagedFiles(call, gh, changedFiles) { + try { + const { url } = capturedJson(gh(["pr", "view", ...(call.target ? [call.target] : []), ...(call.repo ? ["-R", call.repo] : []), "--json", "url"], { cwd: call.cwd })) ?? {}; + const pr = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)$/.exec(url ?? ""); + if (!pr) return null; + const listed = String(gh(["api", "--paginate", `repos/${pr[1]}/${pr[2]}/pulls/${pr[3]}/files`, "--jq", ".[].filename"], { cwd: call.cwd })) + .split("\n").filter(Boolean); + return listed.length >= changedFiles ? listed : null; + } catch { + return null; + } +} + /** Whichever of the session's binding and the head's recorded one declare UI paths, or the refusal when either cannot be read. */ function declaringSides(name, binding, recorded) { try { return { declaring: [binding, recorded()].filter(declaresUiPaths) }; } catch (error) { diff --git a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs index 579d3a89..edac0ad2 100644 --- a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs +++ b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs @@ -18,7 +18,7 @@ import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import os from "node:os"; import { fileURLToPath } from "node:url"; -import { measuredSetupTools } from "./cloud-validation-environment.mjs"; +import { lastSetupMeasurement } from "./cloud-validation-environment.mjs"; import { cloudRecipe } from "./cloud-validation-recipes.mjs"; import { parseConfig } from "../../codex-fleet-monitor/scripts/work-dir.mjs"; import { defaultHome } from "../../fleet-orchestrator/scripts/fleet-home.mjs"; @@ -52,6 +52,8 @@ export function cloudSetupScript({ recipe = cloudRecipe, root = VIBE_ROOT } = {} export const CLAUDE_ENV_VAR = "VIBE_CLOUD_CLAUDE_ENV"; export const CLAUDE_ENV_CONFIG_KEY = "CLOUD_CLAUDE_ENV"; +// No script can read which Claude account Chrome or its extension is signed in to (extension storage and encrypted cookies). +const CHROME_ACCOUNT = "cannot verify by script which Claude account Chrome and the Claude in Chrome extension are signed in to. Check by hand on each machine that launches cloud workers: Chrome is signed in to the same account on every such machine, and claude.ai in Chrome and the Claude in Chrome extension both show the Claude account that `claude auth status` shows."; const NOTHING_RECORDED = "no vibe cloud worker routine is recorded on this machine yet; the first cloud run creates it"; export const CloudSetupError = Object.freeze({ EnvMissing: "CLOUD_ENV_MISSING", @@ -180,6 +182,9 @@ function environmentSetupCheck(routine) { if (!last) return { check: "environment-setup", ok: null, detail: "not exercised: the recorded routine has no run yet, so check did not run the environment setup script" }; const status = String(last.status ?? "").toLowerCase(); + // A run that finished got past the environment setup, which archives the session when it fails. + if (status.includes("succeed")) return { check: "environment-setup", ok: true, + detail: `the last run finished with status ${last.status}, so the environment setup script completed` }; const turns = last.turn_count ?? last.turns_count ?? last.num_turns; if (status.includes("archiv") && (!Number.isInteger(turns) || turns === 0)) { return { check: "environment-setup", ok: false, code: "CLOUD_ENV_SETUP_FAILED", @@ -193,9 +198,9 @@ function environmentSetupCheck(routine) { /** * The setup check: environment configured, the account pin, API reachable, the environment this machine's standing - * routine (`standing`, from the routine ledger) runs in, the GitHub connection, and the lane tools (zsh, uv, Python - * 3.13, Node 24, pnpm and Chromium headless shell 1254) a current measured run on this account and environment - * verified; `pending` is the routine-removal line when routines vibe created are still recorded for removal. + * routine (`standing`, from the routine ledger) runs in, the GitHub connection, the lane tools the setup script installs + * as the last measured run on this account and environment found them, and the Chrome account check this script + * cannot make; `pending` is the routine-removal line when routines vibe created are still recorded for removal. */ export function checkCloudSetup(request, { remote, env = process.env, home = os.homedir(), standing = null, pending = null, ledgerProblem = null, githubTokenMissingAt = null, account, environmentPin = null } = {}) { const checks = []; @@ -249,14 +254,32 @@ export function checkCloudSetup(request, { remote, env = process.env, home = os. detail: `The routine API reported github_token_missing${refusedAt ? ` on ${refusedAt}` : ""}. ${CONNECT_GITHUB}` } : { check: "github", ok: null, detail: "No GitHub connection refusal is recorded. This read-only check does not create a task to test repository access." }); const ownsEnvironment = checks.some((row) => row.check === "environment-use" && row.ok === true); - const observed = ownsEnvironment && !accountProblem && account?.uuid && environment - ? measuredSetupTools(home, environmentPin, account.uuid, environment.id) : null; - const setup = cloudSetupScript(); - const missing = setup.checks.filter((key) => observed?.[key] !== true); - checks.push(missing.length ? { check: "lane-tools", ok: false, code: "CLOUD_SETUP_UNVERIFIED", - detail: `Missing current account/environment measurements for ${missing.join(", ")}. At https://claude.ai/code open the environment selector, select the cloud environment's settings (or New environment), paste the setup script below (from ${setup.file}) into Setup script and save. Set CLOUD_CLAUDE_ENV= in ${path.join(defaultHome(env), "config.env")}. Re-pin with cloud-worker.mjs pin, run the cloud-capabilities lane on a pushed tooling head, then run check.`, - setupScript: setup.text } - : { check: "lane-tools", ok: true, detail: `A current measured run on this account and environment verified ${setup.checks.map((key) => MEASURED_NAMES[key]).join(", ")}.` }); + const measured = ownsEnvironment && !accountProblem && account?.uuid && environment + ? lastSetupMeasurement(home, environmentPin, account.uuid, environment.id) : null; + checks.push(laneToolsCheck(measured, cloudSetupScript(), env)); + checks.push({ check: "chrome-account", ok: null, detail: CHROME_ACCOUNT }); if (pending) checks.push({ check: "routine-removal", ok: null, detail: pending }); return { ok: checks.every((entry) => entry.ok !== false), environment, checks }; } + +/** + * The lane-tools row. Paste advice only when a tool was measured false or this account and environment were never + * measured; a proof older than admission allows that measured every tool true needs only a fresh capability run. + */ +function laneToolsCheck(measured, setup, env) { + const names = (keys) => keys.map((key) => MEASURED_NAMES[key]).join(", "); + const failed = setup.checks.filter((key) => measured?.checks[key] === false); + if (!measured || failed.length) { + const what = failed.length ? `The last capability run on this account and environment measured ${names(failed)} missing.` + : `Missing current account/environment measurements for ${setup.checks.join(", ")}.`; + return { check: "lane-tools", ok: false, code: "CLOUD_SETUP_UNVERIFIED", + detail: `${what} At https://claude.ai/code open the environment selector, select the cloud environment's settings (or New environment), paste the setup script below (from ${setup.file}) into Setup script and save. Set CLOUD_CLAUDE_ENV= in ${path.join(defaultHome(env), "config.env")}. Re-pin with cloud-worker.mjs pin, run the cloud-capabilities lane on a pushed tooling head, then run check.`, + setupScript: setup.text }; + } + const unmeasured = setup.checks.filter((key) => measured.checks[key] !== true); + if (!measured.fresh || unmeasured.length) { + const seen = setup.checks.filter((key) => measured.checks[key] === true); + return { check: "lane-tools", ok: null, detail: `The last capability run on this account and environment (${new Date(measured.at).toISOString()}) measured ${seen.length ? names(seen) : "none of the setup's tools"} present${unmeasured.length ? ` and did not measure ${names(unmeasured)}` : ""}. It needs a fresh capability run before capability lanes: run the cloud-capabilities lane on a pushed tooling head, then run check.` }; + } + return { check: "lane-tools", ok: true, detail: `A current measured run on this account and environment verified ${names(setup.checks)}.` }; +} diff --git a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-validation-environment.mjs b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-validation-environment.mjs index b3b6d555..d3c05398 100644 --- a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-validation-environment.mjs +++ b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-validation-environment.mjs @@ -44,21 +44,25 @@ function validTool(tool) { !tool.ref.includes("..") && !tool.ref.includes("//") && !tool.ref.endsWith(".lock"); } -function matchingProof(home, pin, tool, now) { +function matchingProof(home, pin, tool, now, maxAge = PROOF_MAX_MS) { const file = proofPath(home, pin); if (!existsSync(file)) return null; let record; try { record = regularJson(file); } catch { return null; } if (record?.schema !== PROOF_SCHEMA || record.environmentId !== pin.environmentId || record.accountUuid !== pin.accountUuid || !validTool(record.tool) || (tool && (record.tool.commit !== tool.commit || record.tool.ref !== tool.ref)) || typeof record.sessionId !== "string" || !record.sessionId || - !Number.isFinite(record.at) || record.at > now || now - record.at > PROOF_MAX_MS) return null; + !Number.isFinite(record.at) || record.at > now || now - record.at > maxAge) return null; return record; } -/** Read a fresh capability measurement for this exact environment and signed-in account. */ -export function measuredSetupTools(home, pin, accountUuid, environmentId, now = Date.now()) { +/** + * The last capability measurement for this exact environment and signed-in account at any age, and whether it is still + * fresh enough for admission. Only admission needs a fresh one; a stale one still shows which tools the setup installed. + */ +export function lastSetupMeasurement(home, pin, accountUuid, environmentId, now = Date.now()) { if (!pin || pin.environmentId !== environmentId || pin.accountUuid !== accountUuid) return null; - return matchingProof(home, pin, null, now)?.checks ?? null; + const proof = matchingProof(home, pin, null, now, Infinity); + return proof ? { checks: proof.checks ?? {}, at: proof.at, fresh: now - proof.at <= PROOF_MAX_MS } : null; } function laneCommands(lane) { diff --git a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-worker.mjs b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-worker.mjs index 95a45ff1..b2220823 100644 --- a/plugins/vibe-closedloop/lib/vibe/scripts/cloud-worker.mjs +++ b/plugins/vibe-closedloop/lib/vibe/scripts/cloud-worker.mjs @@ -266,7 +266,11 @@ function toolResultText(body, structured) { function triggerDiagnostic(result, terminal, last) { const clean = (value) => redactedLine(value).slice(0, 400); const errors = Array.isArray(terminal?.errors) ? terminal.errors.slice(0, 3).map((error) => clean(error?.message ?? error)).filter(Boolean) : []; - const end = [clean(terminal?.subtype), ...errors].filter(Boolean).join(": "); + // A failed `claude -p` (an OAuth refresh that failed over ssh) can end with subtype "success" and the cause in `result`. + const failed = terminal?.is_error === true || (Number.isInteger(result.status) && result.status !== 0); + const cause = failed && typeof terminal?.result === "string" ? clean(terminal.result) : ""; + const subtype = clean(terminal?.subtype); + const end = [cause && subtype === "success" ? "" : subtype, cause, ...errors].filter(Boolean).join(": "); const tool = clean(last?.raw); const stderr = clean(result.stderr); const spawn = clean(result.error?.message); @@ -546,6 +550,11 @@ export function verifyRepository(worktree, repository) { return resolveRepository(repository, origin); } +/** The request with its repository filled from the worktree's origin when it names none (the field is optional). */ +function withRepository(request) { + return request.repository === undefined ? { ...request, repository: verifyRepository(request.worktree) } : request; +} + /** A request's resolved repository; every cloud call runs after verifyRepository named it. */ function requireRepository(request) { if (!request.repository) throw new Error("the cloud repository was not resolved from the request or the worktree's origin"); @@ -609,7 +618,7 @@ export async function abandonValidation(request, { confirm = false, home = os.ho validateValidationRequest(request); const key = sha256(JSON.stringify(request)), base = validationReceiptPath(request, key); const file = request.lanes?.some(lane => lane.name === "cloud-capabilities") - ? boundProbeReceipt(base, validationLanes(request).lanes, readLedger(home), resolveClaudeEnvironment(request)) : base; + ? boundProbeReceipt(base, validationLanes(withRepository(request)).lanes, readLedger(home), resolveClaudeEnvironment(request)) : base; const receipt = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : null; const abandoned = receipt && (TERMINAL.has(receipt.status) ? receipt : { ...receipt, status: "abandoned", finishedAt: new Date().toISOString() }); const result = await releaseValidationReservation({ home, key, confirm, unconfirmed: (plan) => unconfirmed("abandon", plan), markRun: (runId) => markRun(home, runId, "abandoned", DEFAULT_WALL_MS), @@ -773,7 +782,7 @@ export function validateValidationRequest(request) { if (Object.hasOwn(request, "env") || Object.hasOwn(request, "envValues")) throw new Error("caller test environment values are refused"); if (!Array.isArray(request.lanes) || request.lanes.length === 0) throw new Error("at least one lane is required"); if (new Set(request.lanes.map((lane) => lane.name)).size !== request.lanes.length) throw new Error("lane names must be unique"); - validationLanes(request); + validationLanes(withRepository(request)); if (request.resultArtifact !== undefined) { const artifact = request.resultArtifact; if (!artifact || typeof artifact !== "object" || typeof artifact.path !== "string" @@ -790,8 +799,9 @@ export function validateValidationRequest(request) { } /** The validation-only brief: exact checkout, install, lanes, no changes, one bound result line. */ -export function validationBrief(request, managedHost = null, provedBranch = null, requestKey = sha256(JSON.stringify(request))) { - validateValidationRequest(request); +export function validationBrief(raw, managedHost = null, provedBranch = null, requestKey = sha256(JSON.stringify(raw))) { + validateValidationRequest(raw); + const request = withRepository(raw); const resolved = validationLanes(request); const artifact = request.resultArtifact; const branch = provedBranch ?? request.branch; diff --git a/plugins/vibe-closedloop/skills/handoff/scripts/rulings-check.mjs b/plugins/vibe-closedloop/skills/handoff/scripts/rulings-check.mjs index 96649fdf..31063deb 100644 --- a/plugins/vibe-closedloop/skills/handoff/scripts/rulings-check.mjs +++ b/plugins/vibe-closedloop/skills/handoff/scripts/rulings-check.mjs @@ -244,6 +244,18 @@ export function separationRuling(program, reason, tickets) { return null; } +/** + * The program's quoted operator ruling, with its source, whose decision names `ticket` by its whole id, or null. A ruling + * copied from a ticket (`ticket:` channel) or one with no quoted words is never the operator's authority for a worker. + */ +export function operatorTicketRuling(program, ticket) { + for (const match of String(program ?? "").matchAll(PROGRAM_RULING)) { + const [, date, channel, source, decision] = match; + if (channel !== "ticket" && /"[^"\n]+"|“[^”\n]+”/u.test(decision) && rulingNamesScope(decision, [ticket], { exact: true })) return { date, channel, source, decision }; + } + return null; +} + /** A dated operator ruling line: its channel, its optional source after a colon, and its decision. */ const OPERATOR_RULING = /^\s*[-*]\s*Ruling\s+(\d{4}-\d{2}-\d{2})\s+\((operator message|AskUserQuestion)(?::\s*([^)]*?))?\s*\):\s*(\S.*)$/; const LOCATOR_CHANNELS = new Set(["chat", "slack", "dm", "email", "call", "meeting"]); diff --git a/plugins/vibe/.claude-plugin/plugin.json b/plugins/vibe/.claude-plugin/plugin.json index 930939fe..fe122a14 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.118", + "version": "1.1.119", "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 59bf8267..deb261a4 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.118", + "version": "1.1.119", "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 df8e9bd0..43a58196 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.118` contains 17 skills and 17 agents, and no hook manifest: the +Version `1.1.119` 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/agent-guard.mjs b/plugins/vibe/hooks/agent-guard.mjs index f2a203c3..85c59b80 100644 --- a/plugins/vibe/hooks/agent-guard.mjs +++ b/plugins/vibe/hooks/agent-guard.mjs @@ -11,6 +11,9 @@ import { vibeSkillOf } from "../shared/plugin-roots.mjs"; import { vibeScriptPath, vibeSkill } from "../shared/vibe-install.mjs"; import { briefProviderProblem } from "../lib/vibe/scripts/provider-brief.mjs"; import { recordedBinding } from "../lib/vibe/scripts/provider.mjs"; +import { chatProgramDir, defaultHome } from "../lib/fleet-orchestrator/scripts/fleet-home.mjs"; +import { validChat } from "../lib/fleet-orchestrator/scripts/chat-binding.mjs"; +import { operatorTicketRuling } from "../skills/handoff/scripts/rulings-check.mjs"; // Roles are agent names qualified by either vibe plugin. const VIBE_WORKER = /^vibe-[a-z0-9-]+-worker$/; @@ -41,19 +44,53 @@ function rawCodexLaunch(words) { return ["exec", "e", "review"].includes(words[i]); } -/** Fleet-only launch policy. Managed launchers start their child internally and never issue a raw parent tool call. */ -export function fleetLaunchGuard(event, home) { +/** + * Fleet-only launch policy. Managed launchers start their child internally and never issue a raw parent tool call. A + * native Agent brief declares `Worker role: read-only | operational | writer` and `Tickets: `; a brief with no + * role is a writer. A writer that is neither a vibe start nor a helper needs a quoted operator ruling naming each of its + * tickets in the program's rulings.md (operator ruling 2026-12-02). + */ +export function fleetLaunchGuard(event, home, env = process.env) { const input = event?.tool_input; const native = event.tool_name === "Agent"; + const prompt = String(input?.prompt ?? ""); + const lines = prompt.split("\n"); const candidate = native - ? !/^(?:\$vibe\b|\/(?:vibe|vibe-generic):vibe\b)/.test(input?.prompt?.trim() ?? "") + ? !/^(?:\$vibe\b|\/(?:vibe|vibe-generic):vibe\b)/.test(prompt.trim()) && !["Ticket writer:", "Helper branch and worktree:", "Exclusive file allowlist:", "Assignment:", "Test authority:", "Return:"] - .every(field => String(input?.prompt ?? "").split("\n").some(line => line.startsWith(field) && line.slice(field.length).trim())) + .every(field => lines.some(line => line.startsWith(field) && line.slice(field.length).trim())) : typeof input?.command === "string"; if (!candidate || conversationSkill(event, home) !== "fleet-orchestrator") return null; - if (!native && !commandCalls(input.command, eventCwd(event)).some(({ words, value }) => rawCodexLaunch(words.map(word => value(word) ?? word)))) return null; - return deny("Fleet ticket analysis uses dist/claude-worker.mjs with vibe-requirements-worker in sessionless startup mode. " - + "Use dist/codex-reviewer.mjs for review, dist/codex-reviewer.mjs run --role visual-qa-critic --agent-definition for visual QA, or fleet.sh session turn for assigned worker work."); + if (native) { + const problem = plainWriterProblem(lines, event, env); + return problem ? deny(`${problem} ${FLEET_ROUTES}`) : null; + } + if (!commandCalls(input.command, eventCwd(event)).some(({ words, value }) => rawCodexLaunch(words.map(word => value(word) ?? word)))) return null; + return deny(FLEET_ROUTES); +} + +const FLEET_ROUTES = "Fleet ticket analysis uses dist/claude-worker.mjs with vibe-requirements-worker in sessionless startup mode. " + + "Use dist/codex-reviewer.mjs for review, dist/codex-reviewer.mjs run --role visual-qa-critic --agent-definition for visual QA, or fleet.sh session turn for assigned worker work."; +const NON_WRITER_ROLES = new Set(["read-only", "operational"]); + +/** Why a fleet chat may not launch this brief as a plain worker, or null: decided from its declared lines only. */ +function plainWriterProblem(lines, event, env) { + const declared = (field) => lines.find((line) => line.startsWith(field))?.slice(field.length).trim() ?? ""; + if (NON_WRITER_ROLES.has(declared("Worker role:").toLowerCase())) return null; + const tickets = declared("Tickets:").split(/[\s,]+/).filter(Boolean); + const declare = "Declare `Worker role: read-only` or `Worker role: operational` for a worker that writes no code."; + if (tickets.length === 0) { + return `A worker brief with no read-only or operational role is a writer, and a writer names its tickets on a \`Tickets: \` line. ${declare}`; + } + let rulings = ""; + try { + const chat = validChat(event?.session_id); + rulings = readFileSync(path.join(chatProgramDir(defaultHome(env, chat), chat, env).dir, "rulings.md"), "utf8"); + } catch { /* No program or no rulings file: no ticket has a ruling. */ } + const missing = tickets.filter((ticket) => !operatorTicketRuling(rulings, ticket)); + if (missing.length === 0) return null; + return `A plain worker that writes code for ${missing.join(", ")} outside vibe needs the operator's ruling naming that ticket in the program's rulings.md, ` + + `quoted with its source: \`- Ruling YYYY-MM-DD (operator message: ): "" \`. ${declare}`; } /** The refusal for a direct internal vibe-worker launch, or null. */ diff --git a/plugins/vibe/hooks/agent-guard.test.mjs b/plugins/vibe/hooks/agent-guard.test.mjs index 19f7b1f5..3d152b2e 100644 --- a/plugins/vibe/hooks/agent-guard.test.mjs +++ b/plugins/vibe/hooks/agent-guard.test.mjs @@ -5,7 +5,7 @@ import os from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; -import { agentGuard, agentLaunchProblem, paneLaunchProblem, writerBindingProblem } from "./agent-guard.mjs"; +import { agentGuard, agentLaunchProblem, fleetLaunchGuard, paneLaunchProblem, writerBindingProblem } from "./agent-guard.mjs"; import { PRE_TOOL_USE_ROUTES } from "./pre-tool-use.mjs"; import { vibeRoot } from "../shared/vibe-install.mjs"; import { activatedChat } from "./activation-test-support.mjs"; @@ -148,3 +148,55 @@ test("a named launch into a terminal pane is refused when its name can push the assert.match(problem("audit-1114-mesh", { TMUX: "/tmp/tmux,1,0" }) ?? "", /never starts/); assert.equal(problem("audit-1114-mesh", {}), null, "automatic mode outside tmux and iTerm stays in process"); }); + +test("ISS-15030 AC-8 a fleet chat launches read-only and operational workers, and a plain writer only with a quoted operator ruling naming its ticket", (t) => { + const root = mkdtempSync(path.join(os.tmpdir(), "fleet-launch-guard-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const fleetHome = path.join(root, "fleet"); + mkdirSync(path.join(fleetHome, "programs", "bugs"), { recursive: true }); + writeFileSync(path.join(fleetHome, "current"), "bugs\n"); + const rulings = path.join(fleetHome, "programs", "bugs", "rulings.md"); + const transcript = path.join(root, "transcript.jsonl"); + writeFileSync(transcript, JSON.stringify({ type: "user", message: { content: "Base directory for this skill: /cache/vibe/1.1.119/skills/fleet-orchestrator" } }) + "\n"); + const env = { FLEET_HOME: fleetHome, HOME: root }; + const launch = (prompt) => fleetLaunchGuard({ tool_name: "Agent", session_id: "chat-fixture", transcript_path: transcript, cwd: root, + tool_input: { subagent_type: "general-purpose", prompt } }, root, env); + const denied = (result) => result?.decision === "deny"; + writeFileSync(rulings, [ + "# Rulings", + "- Ruling 2026-12-02 (operator message: chat 3:20 PM): \"yes, plain workers for the next two PRs\" ISS-15030 is finished outside vibe.", + "- Ruling 2026-12-02 (ticket: ISS-15022): \"plain worker\" ISS-15022 copied from the ticket, not the operator.", + ].join("\n") + "\n"); + + assert.equal(launch("Worker role: read-only\nRun the node test lane on laptop 2 and report."), null, "a read-only lane worker passes"); + assert.equal(launch("Worker role: operational\nClean up the stale worktrees."), null, "an operational worker passes"); + assert.equal(launch("Worker role: writer\nTickets: ISS-15030\nFix the cloud check."), null, "a plain writer with a matching ruling passes"); + const without = launch("Worker role: writer\nTickets: ISS-15031\nFix the next thing."); + assert.ok(denied(without), "a plain writer without a ruling is refused"); + assert.match(without.reason, /rulings\.md/); + assert.match(without.reason, /ISS-15031/); + assert.ok(denied(launch("Worker role: writer\nTickets: ISS-15022\nFix it.")), "a ruling copied from a ticket is not the operator's"); + assert.ok(denied(launch("Worker role: writer\nTickets: ISS-15030, ISS-15031\nFix both.")), "every ticket needs its ruling"); + assert.ok(denied(launch("Worker role: writer\nFix the cloud check for ISS-15030.")), "a writer names its tickets on a Tickets line, never in free text"); + assert.ok(denied(launch("Tickets: ISS-15031\nThis is read-only research, it writes no code.")), "a brief with no declared role is a writer"); + assert.equal(launch("Tickets: ISS-15030\nFix the cloud check."), null, "a brief with no declared role and a matching ruling passes as a writer"); + + assert.equal(launch("/vibe:vibe ISS-15031"), null, "a vibe session start keeps passing"); + const helper = ["Ticket writer: w1", "Helper branch and worktree: h/1 at /tmp/h1", "Exclusive file allowlist: a.mjs", "Assignment: fix a", + "Test authority: focused", "Return: summary"].join("\n"); + assert.equal(launch(helper), null, "a helper brief keeps passing"); + // Through the hook entry, which calls the guard with the event alone and the process environment. + const hook = (prompt) => spawnSync(process.execPath, [GUARD], { encoding: "utf8", env: { ...process.env, ...env }, + input: JSON.stringify({ hook_event_name: "PreToolUse", tool_name: "Agent", session_id: "chat-fixture", transcript_path: transcript, cwd: root, + tool_input: { subagent_type: "general-purpose", prompt } }) }); + assert.equal(hook("Worker role: writer\nTickets: ISS-15030\nFix the cloud check.").stdout, "", "the hook lets a ruled writer start"); + assert.match(JSON.parse(hook("Worker role: writer\nTickets: ISS-15031\nFix it.").stdout).hookSpecificOutput.permissionDecisionReason, /ISS-15031 outside vibe/, + "the hook refuses a writer without a ruling"); + rmSync(rulings); + assert.ok(denied(launch("Worker role: writer\nTickets: ISS-15030\nFix the cloud check.")), "with no rulings.md no writer has a ruling"); + assert.equal(launch("Worker role: read-only\nRead the logs."), null, "a read-only worker needs no rulings.md"); + + const outside = fleetLaunchGuard({ tool_name: "Agent", session_id: "chat-fixture", transcript_path: path.join(root, "none.jsonl"), cwd: root, + tool_input: { subagent_type: "general-purpose", prompt: "Worker role: writer\nTickets: ISS-15031" } }, root, env); + assert.equal(outside, null, "outside a fleet-orchestrator chat the guard does nothing"); +}); diff --git a/plugins/vibe/hooks/merge-guard.mjs b/plugins/vibe/hooks/merge-guard.mjs index ccf78b34..d5e40446 100644 --- a/plugins/vibe/hooks/merge-guard.mjs +++ b/plugins/vibe/hooks/merge-guard.mjs @@ -104,7 +104,7 @@ export function mergeProblem(command, gh, { cwd, environment = process.env, bind /** * Why `call` would merge a pull request that changes the repository's UI paths without visual QA findings for its - * current head, or null. A file list GitHub cut short is treated as changing UI. + * current head, or null. A file list that stays short after reading every page is treated as changing UI. */ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRemote) { const { checkout, unresolved, remote } = headBranchCheckout(call, headBranch, environment); @@ -119,8 +119,13 @@ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRe try { view = capturedJson(gh(args, { cwd: call.cwd })); } catch (error) { return `${name} refused: visual QA cannot be checked because gh could not list the pull request's files (${String(error?.message ?? error).split("\n")[0]}); rerun when gh can answer`; } const { files, changedFiles, headRefOid, body } = view ?? {}; - const paths = Array.isArray(files) ? files.map((file) => file?.path).filter((file) => typeof file === "string") : []; - const complete = Array.isArray(files) && Number.isInteger(changedFiles) && paths.length >= changedFiles; + let paths = Array.isArray(files) ? files.map((file) => file?.path).filter((file) => typeof file === "string") : []; + let complete = Array.isArray(files) && Number.isInteger(changedFiles) && paths.length >= changedFiles; + // gh pr view lists at most 100 files; a larger pull request is read page by page before it is judged. + if (!complete && Number.isInteger(changedFiles)) { + const listed = pagedFiles(call, gh, changedFiles); + if (listed) [paths, complete] = [listed, true]; + } let gateWitness = checkout ? () => readFileSync(gatePath(checkout), "utf8") : null; let expected = checkout ? undefined : null; if (remote) { @@ -155,6 +160,20 @@ function mergeVisualQaProblem(call, gh, binding, headBranch, environment, readRe return null; } +/** Every changed file of the pull request from the paginated files API, or null when that listing fails or comes up short. */ +function pagedFiles(call, gh, changedFiles) { + try { + const { url } = capturedJson(gh(["pr", "view", ...(call.target ? [call.target] : []), ...(call.repo ? ["-R", call.repo] : []), "--json", "url"], { cwd: call.cwd })) ?? {}; + const pr = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)$/.exec(url ?? ""); + if (!pr) return null; + const listed = String(gh(["api", "--paginate", `repos/${pr[1]}/${pr[2]}/pulls/${pr[3]}/files`, "--jq", ".[].filename"], { cwd: call.cwd })) + .split("\n").filter(Boolean); + return listed.length >= changedFiles ? listed : null; + } catch { + return null; + } +} + /** Whichever of the session's binding and the head's recorded one declare UI paths, or the refusal when either cannot be read. */ function declaringSides(name, binding, recorded) { try { return { declaring: [binding, recorded()].filter(declaresUiPaths) }; } catch (error) { diff --git a/plugins/vibe/hooks/merge-guard.test.mjs b/plugins/vibe/hooks/merge-guard.test.mjs index 5058628e..3ba2cc6f 100644 --- a/plugins/vibe/hooks/merge-guard.test.mjs +++ b/plugins/vibe/hooks/merge-guard.test.mjs @@ -314,3 +314,35 @@ echo '{"author":{"login":"operator"},"headRefName":"vibe/ui"}' assert.equal(output.permissionDecision, "deny"); assert.match(output.permissionDecisionReason, /visual QA is required/); }); + +test("ISS-15030 AC-7 a pull request over GitHub's 100-file view is judged on its full paginated file list", (t) => { + const { worktree, binding } = uiBinding(t); + const head = "c".repeat(40); + const docs = Array.from({ length: 101 }, (_, index) => `docs/page-${index}.md`); + const prs = { 454: docs, 455: [...docs.slice(0, 100), "apps/app/header.tsx"] }; + const calls = []; + const gh = (args, { paginationFails = false } = {}) => { + calls.push(args.join(" ")); + if (args[0] === "api" && args[1] === "user") return "operator\n"; + if (args[0] === "api") { + const number = /^repos\/acme\/app\/pulls\/(\d+)\/files$/.exec(args[2])?.[1]; + assert.ok(args.includes("--paginate"), "every page is read"); + if (paginationFails || !number) throw new Error("HTTP 502"); + return prs[number].join("\n") + "\n"; + } + if (args.includes("files,changedFiles,headRefOid,body")) { + // gh pr view lists at most 100 files. + return JSON.stringify({ files: prs[args[2]].slice(0, 100).map((file) => ({ path: file })), changedFiles: prs[args[2]].length, headRefOid: head, body: "" }); + } + if (args.includes("url")) return JSON.stringify({ url: `https://github.com/acme/app/pull/${args[2]}` }); + return JSON.stringify({ author: { login: "operator" }, headRefName: "vibe/ui" }); + }; + const problem = (command, options) => mergeProblem(command, (args) => gh(args, options), { cwd: worktree, environment: {}, binding }); + assert.equal(problem("gh pr merge 454 --squash --auto"), null, "101 non-UI files merge without visual QA"); + assert.ok(calls.includes("api --paginate repos/acme/app/pulls/454/files --jq .[].filename")); + const ui = problem("gh pr merge 455 --squash --auto") ?? ""; + assert.match(ui, /visual QA is required \(1 changed file\(s\)[^)]*apps\/app\/header\.tsx\)/, "the 101st file is UI"); + assert.doesNotMatch(ui, /listed only part/); + assert.match(problem("gh pr merge 454 --squash --auto", { paginationFails: true }) ?? "", /listed only part of its changed files/, + "a failed pagination is still treated as partial"); +}); diff --git a/plugins/vibe/lib/vibe/scripts/cloud-capability-probe.test.mjs b/plugins/vibe/lib/vibe/scripts/cloud-capability-probe.test.mjs index aa6df77e..89833e87 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-capability-probe.test.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-capability-probe.test.mjs @@ -423,3 +423,30 @@ test("ISS-14874 a megabyte of one repeated text is redacted, and the credential assert.ok(redactUserinfo(text) === `${filler}\nPASSWORD=s3cret https://@proxy.internal`, form); } }); + +test("ISS-15030 AC-3 a cloud-capabilities validate request without repository takes it from the worktree's origin", async (t) => { + const { validateValidationRequest, validationBrief } = await import("./cloud-worker.mjs"); + const { git, makeCheckout } = await import("../../../skills/vibe/scripts/test-fixtures.mjs"); + const f = makeHome("probe-origin-repository-"); + t.after(f.cleanup); + const { repository, ...base } = canonicalRequest(); + const worktree = path.join(f.root, "checkout"), probe = CLOUD_CAPABILITIES_COMMAND.slice(5); + // `git remote get-url` applies the fixture's insteadOf, so drop it: these checks read only local objects. + const checkout = (dir, remoteUrl) => { + const { origin } = makeCheckout({ ...f, checkout: dir, remoteUrl, files: { [probe]: "export {};", [probe.replace("probe.mjs", "electron.cjs")]: "" } }); + git(dir, ["config", "--remove-section", `url.${origin}`], f.home); + }; + checkout(worktree, "https://github.com/" + repository); + const request = { ...base, provider: "claude", model: "claude-sonnet-5-5", commit: git(worktree, ["rev-parse", "HEAD"], f.home), worktree, branch: "main" }; + assert.equal(Object.hasOwn(request, "repository"), false); + assert.doesNotThrow(() => validateValidationRequest(request), "the header says repository is optional"); + assert.match(validationBrief(request), /cloud-capability-probe\.mjs/); + const { abandonValidation } = await import("./cloud-worker.mjs"); + // Abandoning the same request resolves its repository the same way and reaches the pin check, not the lane refusal. + await assert.rejects(abandonValidation({ ...request, claudeEnvironment: "env_01Fixture" }, { home: f.home, remote: () => { throw new Error("no remote call expected"); } }), + /requires a verified account and environment pin/); + const other = path.join(f.root, "other"); + checkout(other, "https://github.com/example-org/other-repo"); + assert.throws(() => validateValidationRequest({ ...request, worktree: other, commit: git(other, ["rev-parse", "HEAD"], f.home) }), + /CLOUD_CAPABILITY_UNAVAILABLE/, "an origin that is not the tooling repository is still refused"); +}); diff --git a/plugins/vibe/lib/vibe/scripts/cloud-check-rows.test.mjs b/plugins/vibe/lib/vibe/scripts/cloud-check-rows.test.mjs new file mode 100644 index 00000000..8ea661e1 --- /dev/null +++ b/plugins/vibe/lib/vibe/scripts/cloud-check-rows.test.mjs @@ -0,0 +1,104 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { checkCloudSetup, cloudSetupScript } from "./cloud-environment.mjs"; +// The ClosedLoop build, whose recipe names its own setup script. +import { checkCloudSetup as providerCheckSetup, cloudSetupScript as providerSetup } from "../../../../vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs"; +import { remoteTrigger } from "./cloud-worker.mjs"; +import { confirmCloudEnvironment } from "./cloud-validation-environment.mjs"; +import { makeHome } from "../../../../vibe/skills/vibe/scripts/test-fixtures.mjs"; + +const PIN = { accountUuid: "a0a01111-1111-4111-a111-111111111111", environmentId: "env_Fixture" }; +const TOOL = { commit: "a".repeat(40), ref: "refs/heads/proof" }; +const STALE = 31 * 60_000; +const FRESH_RUN = /needs a fresh capability run before capability lanes/; +const owning = () => ({ data: [{ id: "standing", job_config: { ccr: { environment_id: PIN.environmentId } } }] }); +const row = (result, name) => result.checks.find((entry) => entry.check === name); + +function proofFixture(t, check, setup) { + const f = makeHome("vibe-cloud-rows-"); + t.after(f.cleanup); + const allTrue = { workspace: true, nonRoot: true, ports: true, chromium: true, gitUtc: true, ...Object.fromEntries(setup.checks.map((key) => [key, true])) }; + const record = (flags, at = Date.now()) => confirmCloudEnvironment({ home: f.home, pin: PIN, environmentId: PIN.environmentId, + tool: TOOL, sessionId: "session-fixture", completed: true, now: at, outcome: { name: "cloud-capabilities", exitCode: 0, + stdoutTail: "CLOUD_HOST_RUNTIME " + JSON.stringify({ commit: TOOL.commit, checks: flags }) } }); + const run = () => check({ claudeEnvironment: PIN.environmentId }, { home: f.home, account: { uuid: PIN.accountUuid }, environmentPin: PIN, remote: owning }); + return { allTrue, record, run }; +} + +for (const [edition, check, setupOf] of [["generic", checkCloudSetup, cloudSetupScript], ["provider", providerCheckSetup, providerSetup]]) { + test(`ISS-15030 AC-1 AC-2 (${edition}) lane-tools fails only for a tool measured false or no proof, and prints this edition's script`, (t) => { + const setup = setupOf(); + const { allTrue, record, run } = proofFixture(t, check, setup); + + const never = row(run(), "lane-tools"); + assert.equal(never.ok, false, "there was never a proof"); + assert.equal(never.setupScript, setup.text, "the advice prints the script cloudSetupScript returns for this edition"); + + record(allTrue); + const fresh = run(); + assert.equal(row(fresh, "lane-tools").ok, true, "a fresh all-true proof passes"); + assert.equal(row(fresh, "lane-tools").setupScript, undefined); + + record(allTrue, Date.now() - STALE); + const stale = run(); + const staleRow = row(stale, "lane-tools"); + assert.notEqual(staleRow.ok, false, "a stale proof that measured every tool true does not fail lane-tools"); + assert.equal(stale.ok, true); + assert.match(staleRow.detail, FRESH_RUN); + assert.equal(staleRow.setupScript, undefined, "no setup script to paste"); + assert.doesNotMatch(staleRow.detail, /paste|Setup script/i); + + const [first] = setup.checks; + for (const at of [Date.now(), Date.now() - STALE]) { + record({ ...allTrue, [first]: false }, at); + const missing = row(run(), "lane-tools"); + assert.equal(missing.ok, false, "a tool measured false fails, fresh or stale"); + assert.equal(missing.setupScript, setup.text); + assert.match(missing.detail, /Setup script/); + } + }); +} + +test("ISS-15030 AC-2 the generic edition's script differs from the provider's, so each edition's advice is its own", () => { + assert.notEqual(cloudSetupScript().text, providerSetup().text); + assert.match(providerSetup().file, /cloud-env-setup-closedloop\.md$/); +}); + +// The stream shape is inferred from the reported message ("RemoteTrigger get failed: result success"); no failing stream was captured. +test("ISS-15030 AC-4 the api row names the claude -p failure, never a bare \"result success\"", () => { + for (const [status, isError] of [[1, true], [1, false], [0, true]]) { + const failing = () => ({ status, stderr: "", stdout: [ + JSON.stringify({ type: "system", subtype: "init" }), + JSON.stringify({ type: "result", subtype: "success", is_error: isError, result: "OAuth session expired and could not be refreshed. Please run /login." }), + ].join("\n") }); + const remote = (action, payload) => remoteTrigger(action, payload, { run: failing }); + assert.throws(() => remote("get", { trigger_id: "standing" }), /OAuth session expired and could not be refreshed/); + const api = row(checkCloudSetup({ claudeEnvironment: PIN.environmentId }, { remote, standing: { id: "standing" } }), "api"); + assert.equal(api.ok, false); + assert.match(api.detail, /OAuth session expired and could not be refreshed/, `exit ${status}, is_error ${isError}`); + assert.doesNotMatch(api.detail, /result success\b(?!:)/); + } +}); + +test("ISS-15030 AC-5 environment-setup passes after a completed run in that environment", () => { + const setupRow = (last) => row(checkCloudSetup({ claudeEnvironment: PIN.environmentId }, { standing: { id: "standing" }, + remote: () => ({ trigger: { id: "standing", job_config: { ccr: { environment_id: PIN.environmentId } }, last_run: last } }) }), "environment-setup"); + const done = setupRow({ status: "ROUTINE_RUN_STATUS_SUCCEEDED" }); + assert.equal(done.ok, true); + assert.doesNotMatch(done.detail, /not exercised/); + assert.equal(setupRow({ status: "ROUTINE_RUN_STATUS_RUNNING" }).ok, null, "a run still going proves nothing yet"); + assert.equal(setupRow({ status: "ROUTINE_RUN_STATUS_ARCHIVED", turn_count: 0 }).ok, false, "an archived run with no turn still fails"); +}); + +test("ISS-15030 AC-6 one named row says the Chrome and extension account cannot be verified by a script and names the manual check", () => { + for (const account of [{ uuid: PIN.accountUuid }, { error: Object.assign(new Error("CLOUD_ACCOUNT_UNVERIFIED: x"), { code: "CLOUD_ACCOUNT_UNVERIFIED" }) }, undefined]) { + const result = checkCloudSetup({ claudeEnvironment: PIN.environmentId }, { remote: owning, account, environmentPin: PIN }); + const rows = result.checks.filter((entry) => entry.check === "chrome-account"); + assert.equal(rows.length, 1); + assert.equal(rows[0].ok, null, "unverified, never a pass"); + assert.match(rows[0].detail, /cannot verify/); + assert.match(rows[0].detail, /Claude in Chrome extension/); + assert.match(rows[0].detail, /claude auth status/); + assert.match(rows[0].detail, /each machine that launches cloud workers/); + } +}); diff --git a/plugins/vibe/lib/vibe/scripts/cloud-environment.mjs b/plugins/vibe/lib/vibe/scripts/cloud-environment.mjs index 579d3a89..edac0ad2 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-environment.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-environment.mjs @@ -18,7 +18,7 @@ import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import os from "node:os"; import { fileURLToPath } from "node:url"; -import { measuredSetupTools } from "./cloud-validation-environment.mjs"; +import { lastSetupMeasurement } from "./cloud-validation-environment.mjs"; import { cloudRecipe } from "./cloud-validation-recipes.mjs"; import { parseConfig } from "../../codex-fleet-monitor/scripts/work-dir.mjs"; import { defaultHome } from "../../fleet-orchestrator/scripts/fleet-home.mjs"; @@ -52,6 +52,8 @@ export function cloudSetupScript({ recipe = cloudRecipe, root = VIBE_ROOT } = {} export const CLAUDE_ENV_VAR = "VIBE_CLOUD_CLAUDE_ENV"; export const CLAUDE_ENV_CONFIG_KEY = "CLOUD_CLAUDE_ENV"; +// No script can read which Claude account Chrome or its extension is signed in to (extension storage and encrypted cookies). +const CHROME_ACCOUNT = "cannot verify by script which Claude account Chrome and the Claude in Chrome extension are signed in to. Check by hand on each machine that launches cloud workers: Chrome is signed in to the same account on every such machine, and claude.ai in Chrome and the Claude in Chrome extension both show the Claude account that `claude auth status` shows."; const NOTHING_RECORDED = "no vibe cloud worker routine is recorded on this machine yet; the first cloud run creates it"; export const CloudSetupError = Object.freeze({ EnvMissing: "CLOUD_ENV_MISSING", @@ -180,6 +182,9 @@ function environmentSetupCheck(routine) { if (!last) return { check: "environment-setup", ok: null, detail: "not exercised: the recorded routine has no run yet, so check did not run the environment setup script" }; const status = String(last.status ?? "").toLowerCase(); + // A run that finished got past the environment setup, which archives the session when it fails. + if (status.includes("succeed")) return { check: "environment-setup", ok: true, + detail: `the last run finished with status ${last.status}, so the environment setup script completed` }; const turns = last.turn_count ?? last.turns_count ?? last.num_turns; if (status.includes("archiv") && (!Number.isInteger(turns) || turns === 0)) { return { check: "environment-setup", ok: false, code: "CLOUD_ENV_SETUP_FAILED", @@ -193,9 +198,9 @@ function environmentSetupCheck(routine) { /** * The setup check: environment configured, the account pin, API reachable, the environment this machine's standing - * routine (`standing`, from the routine ledger) runs in, the GitHub connection, and the lane tools (zsh, uv, Python - * 3.13, Node 24, pnpm and Chromium headless shell 1254) a current measured run on this account and environment - * verified; `pending` is the routine-removal line when routines vibe created are still recorded for removal. + * routine (`standing`, from the routine ledger) runs in, the GitHub connection, the lane tools the setup script installs + * as the last measured run on this account and environment found them, and the Chrome account check this script + * cannot make; `pending` is the routine-removal line when routines vibe created are still recorded for removal. */ export function checkCloudSetup(request, { remote, env = process.env, home = os.homedir(), standing = null, pending = null, ledgerProblem = null, githubTokenMissingAt = null, account, environmentPin = null } = {}) { const checks = []; @@ -249,14 +254,32 @@ export function checkCloudSetup(request, { remote, env = process.env, home = os. detail: `The routine API reported github_token_missing${refusedAt ? ` on ${refusedAt}` : ""}. ${CONNECT_GITHUB}` } : { check: "github", ok: null, detail: "No GitHub connection refusal is recorded. This read-only check does not create a task to test repository access." }); const ownsEnvironment = checks.some((row) => row.check === "environment-use" && row.ok === true); - const observed = ownsEnvironment && !accountProblem && account?.uuid && environment - ? measuredSetupTools(home, environmentPin, account.uuid, environment.id) : null; - const setup = cloudSetupScript(); - const missing = setup.checks.filter((key) => observed?.[key] !== true); - checks.push(missing.length ? { check: "lane-tools", ok: false, code: "CLOUD_SETUP_UNVERIFIED", - detail: `Missing current account/environment measurements for ${missing.join(", ")}. At https://claude.ai/code open the environment selector, select the cloud environment's settings (or New environment), paste the setup script below (from ${setup.file}) into Setup script and save. Set CLOUD_CLAUDE_ENV= in ${path.join(defaultHome(env), "config.env")}. Re-pin with cloud-worker.mjs pin, run the cloud-capabilities lane on a pushed tooling head, then run check.`, - setupScript: setup.text } - : { check: "lane-tools", ok: true, detail: `A current measured run on this account and environment verified ${setup.checks.map((key) => MEASURED_NAMES[key]).join(", ")}.` }); + const measured = ownsEnvironment && !accountProblem && account?.uuid && environment + ? lastSetupMeasurement(home, environmentPin, account.uuid, environment.id) : null; + checks.push(laneToolsCheck(measured, cloudSetupScript(), env)); + checks.push({ check: "chrome-account", ok: null, detail: CHROME_ACCOUNT }); if (pending) checks.push({ check: "routine-removal", ok: null, detail: pending }); return { ok: checks.every((entry) => entry.ok !== false), environment, checks }; } + +/** + * The lane-tools row. Paste advice only when a tool was measured false or this account and environment were never + * measured; a proof older than admission allows that measured every tool true needs only a fresh capability run. + */ +function laneToolsCheck(measured, setup, env) { + const names = (keys) => keys.map((key) => MEASURED_NAMES[key]).join(", "); + const failed = setup.checks.filter((key) => measured?.checks[key] === false); + if (!measured || failed.length) { + const what = failed.length ? `The last capability run on this account and environment measured ${names(failed)} missing.` + : `Missing current account/environment measurements for ${setup.checks.join(", ")}.`; + return { check: "lane-tools", ok: false, code: "CLOUD_SETUP_UNVERIFIED", + detail: `${what} At https://claude.ai/code open the environment selector, select the cloud environment's settings (or New environment), paste the setup script below (from ${setup.file}) into Setup script and save. Set CLOUD_CLAUDE_ENV= in ${path.join(defaultHome(env), "config.env")}. Re-pin with cloud-worker.mjs pin, run the cloud-capabilities lane on a pushed tooling head, then run check.`, + setupScript: setup.text }; + } + const unmeasured = setup.checks.filter((key) => measured.checks[key] !== true); + if (!measured.fresh || unmeasured.length) { + const seen = setup.checks.filter((key) => measured.checks[key] === true); + return { check: "lane-tools", ok: null, detail: `The last capability run on this account and environment (${new Date(measured.at).toISOString()}) measured ${seen.length ? names(seen) : "none of the setup's tools"} present${unmeasured.length ? ` and did not measure ${names(unmeasured)}` : ""}. It needs a fresh capability run before capability lanes: run the cloud-capabilities lane on a pushed tooling head, then run check.` }; + } + return { check: "lane-tools", ok: true, detail: `A current measured run on this account and environment verified ${names(setup.checks)}.` }; +} diff --git a/plugins/vibe/lib/vibe/scripts/cloud-environment.test.mjs b/plugins/vibe/lib/vibe/scripts/cloud-environment.test.mjs index 15ffb6e4..01b726f6 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-environment.test.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-environment.test.mjs @@ -131,7 +131,7 @@ test('the setup check reports each environment and API result with its fix, and const gone = { get: () => { throw httpError(404); }, list: () => used }; const ok = checkCloudSetup({ claudeEnvironment: REQUEST_ENV }, { remote: fakeRemote(recorded).remote, standing, env: { FLEET_HOME: fleetHome(t) } }); assert.equal(ok.ok, false, "an account-free routine read cannot prove the lane tools"); - assert.deepEqual(ok.checks.map(({ check, ok: passed }) => [check, passed]), [['environment', true], ['api', true], ['environment-setup', null], ['environment-use', true], ['github', null], ['lane-tools', false]]); + assert.deepEqual(ok.checks.map(({ check, ok: passed }) => [check, passed]), [['environment', true], ['api', true], ['environment-setup', null], ['environment-use', true], ['github', null], ['lane-tools', false], ['chrome-account', null]]); assert.match(ok.checks[2].detail, /not exercised.*did not run the environment setup script/); assert.match(ok.checks[3].detail, /routine trig_a on this account runs in env_01FromRequest/); assert.match(ok.checks[4].detail, /No GitHub connection refusal is recorded.*read-only check/); diff --git a/plugins/vibe/lib/vibe/scripts/cloud-setup-proof.test.mjs b/plugins/vibe/lib/vibe/scripts/cloud-setup-proof.test.mjs index 442a4105..81bea642 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-setup-proof.test.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-setup-proof.test.mjs @@ -7,7 +7,7 @@ import { checkCloudSetup, cloudSetupScript } from "./cloud-environment.mjs"; // The ClosedLoop build's own setup script, which carries the repository tools vibe's generic template leaves out. import { checkCloudSetup as providerCheckSetup, cloudSetupScript as providerSetup } from "../../../../vibe-closedloop/lib/vibe/scripts/cloud-environment.mjs"; import { CLOUD_CAPABILITIES_COMMAND } from "./cloud-check-command.mjs"; -import { confirmCloudEnvironment, recordRuntimeFromValidation, measuredSetupTools } from "./cloud-validation-environment.mjs"; +import { confirmCloudEnvironment, recordRuntimeFromValidation, lastSetupMeasurement } from "./cloud-validation-environment.mjs"; import { PACKAGE_REPAIR, repairHostPackages } from "./cloud-validation-host.mjs"; import { makeHome } from "../../../../vibe/skills/vibe/scripts/test-fixtures.mjs"; @@ -50,7 +50,13 @@ test("AC-102 check requires current measured account, environment and every chec assert.equal(providerCheck().ok, true); record({ ...own, chromium1254: false }); assert.equal(providerCheck().ok, false, "a previous browser revision cannot satisfy the canonical setup"); + // ISS-15030 AC-1 (operator ruling): a stale proof whose tools were all measured present no longer fails lane-tools or + // asks for the setup script; it asks only for a fresh capability run. A stale proof with a tool measured false still refuses. record(checks, Date.now() - 31 * 60_000); + const stale = check().checks.find((entry) => entry.check === "lane-tools"); + assert.equal(stale.ok, null); + assert.match(stale.detail, /needs a fresh capability run before capability lanes/); + record({ ...checks, [setup.checks[0]]: false }, Date.now() - 31 * 60_000); refused(check()); }); @@ -137,7 +143,7 @@ test("AC-102 completion cannot rebind an unpinned, repinned or old run", (t) => const commit = "a".repeat(40); const outcome = { name: "cloud-capabilities", exitCode: 0, stdoutTail: "CLOUD_HOST_RUNTIME " + JSON.stringify({ commit, checks }) }; const run = { runId: "run", routineId: "routine", sessionId: "session", startedAt: new Date().toISOString() }; - const measured = () => measuredSetupTools(f.home, pin, pin.accountUuid, pin.environmentId)?.node24; + const measured = () => { const last = lastSetupMeasurement(f.home, pin, pin.accountUuid, pin.environmentId); return last?.fresh ? last.checks.node24 : undefined; }; const canonical = [{name:outcome.name,command:CLOUD_CAPABILITIES_COMMAND,capabilityProbe:true}]; const capture = (fields, lanes=canonical) => recordRuntimeFromValidation({ lanes, home: f.home, branch: "main", currentAccount: () => pin.accountUuid, ledger: () => ({ environmentPin: pin, runs: [{ ...run, ...fields }] }) }, { commit, lanes: [outcome] }, diff --git a/plugins/vibe/lib/vibe/scripts/cloud-validation-environment.mjs b/plugins/vibe/lib/vibe/scripts/cloud-validation-environment.mjs index b3b6d555..d3c05398 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-validation-environment.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-validation-environment.mjs @@ -44,21 +44,25 @@ function validTool(tool) { !tool.ref.includes("..") && !tool.ref.includes("//") && !tool.ref.endsWith(".lock"); } -function matchingProof(home, pin, tool, now) { +function matchingProof(home, pin, tool, now, maxAge = PROOF_MAX_MS) { const file = proofPath(home, pin); if (!existsSync(file)) return null; let record; try { record = regularJson(file); } catch { return null; } if (record?.schema !== PROOF_SCHEMA || record.environmentId !== pin.environmentId || record.accountUuid !== pin.accountUuid || !validTool(record.tool) || (tool && (record.tool.commit !== tool.commit || record.tool.ref !== tool.ref)) || typeof record.sessionId !== "string" || !record.sessionId || - !Number.isFinite(record.at) || record.at > now || now - record.at > PROOF_MAX_MS) return null; + !Number.isFinite(record.at) || record.at > now || now - record.at > maxAge) return null; return record; } -/** Read a fresh capability measurement for this exact environment and signed-in account. */ -export function measuredSetupTools(home, pin, accountUuid, environmentId, now = Date.now()) { +/** + * The last capability measurement for this exact environment and signed-in account at any age, and whether it is still + * fresh enough for admission. Only admission needs a fresh one; a stale one still shows which tools the setup installed. + */ +export function lastSetupMeasurement(home, pin, accountUuid, environmentId, now = Date.now()) { if (!pin || pin.environmentId !== environmentId || pin.accountUuid !== accountUuid) return null; - return matchingProof(home, pin, null, now)?.checks ?? null; + const proof = matchingProof(home, pin, null, now, Infinity); + return proof ? { checks: proof.checks ?? {}, at: proof.at, fresh: now - proof.at <= PROOF_MAX_MS } : null; } function laneCommands(lane) { diff --git a/plugins/vibe/lib/vibe/scripts/cloud-validation-recovery.test.mjs b/plugins/vibe/lib/vibe/scripts/cloud-validation-recovery.test.mjs index d5c96f36..d9e11b29 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-validation-recovery.test.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-validation-recovery.test.mjs @@ -3,7 +3,7 @@ import path from "node:path"; import test from "node:test"; import { makeHome } from "../../../../vibe/skills/vibe/scripts/test-fixtures.mjs"; import { recordEnvironmentPin, readLedger, runOnStanding } from "./cloud-routines.mjs"; -import { executeCloudValidation, measuredSetupTools, recordRuntimeFromValidation } from "./cloud-validation-environment.mjs"; +import { executeCloudValidation, lastSetupMeasurement, recordRuntimeFromValidation } from "./cloud-validation-environment.mjs"; import { CLOUD_CAPABILITIES_COMMAND } from "./cloud-check-command.mjs"; import { remoteTrigger } from "./cloud-worker.mjs"; import { regularJson, writeAtomic } from "./owned-state.mjs"; @@ -53,7 +53,8 @@ for(const variant of ["nonzero CLI","trailing frame"]) test("uncertain provider await f.run({start,remote}); assert.equal(starts,1); assert.equal(f.ledger().runs.filter(r=>r.accountUuid===accountUuid && r.environmentId===environmentId && r.runId==="run").length,1); - assert.equal(measuredSetupTools(f.home,pin,accountUuid,environmentId)?.node24,true); + const last = lastSetupMeasurement(f.home,pin,accountUuid,environmentId); + assert.equal(last?.fresh && last.checks.node24,true); }); test("expired completed capability request runs afresh while an in-flight receipt resumes",async t=>{ diff --git a/plugins/vibe/lib/vibe/scripts/cloud-worker.mjs b/plugins/vibe/lib/vibe/scripts/cloud-worker.mjs index 95a45ff1..b2220823 100644 --- a/plugins/vibe/lib/vibe/scripts/cloud-worker.mjs +++ b/plugins/vibe/lib/vibe/scripts/cloud-worker.mjs @@ -266,7 +266,11 @@ function toolResultText(body, structured) { function triggerDiagnostic(result, terminal, last) { const clean = (value) => redactedLine(value).slice(0, 400); const errors = Array.isArray(terminal?.errors) ? terminal.errors.slice(0, 3).map((error) => clean(error?.message ?? error)).filter(Boolean) : []; - const end = [clean(terminal?.subtype), ...errors].filter(Boolean).join(": "); + // A failed `claude -p` (an OAuth refresh that failed over ssh) can end with subtype "success" and the cause in `result`. + const failed = terminal?.is_error === true || (Number.isInteger(result.status) && result.status !== 0); + const cause = failed && typeof terminal?.result === "string" ? clean(terminal.result) : ""; + const subtype = clean(terminal?.subtype); + const end = [cause && subtype === "success" ? "" : subtype, cause, ...errors].filter(Boolean).join(": "); const tool = clean(last?.raw); const stderr = clean(result.stderr); const spawn = clean(result.error?.message); @@ -546,6 +550,11 @@ export function verifyRepository(worktree, repository) { return resolveRepository(repository, origin); } +/** The request with its repository filled from the worktree's origin when it names none (the field is optional). */ +function withRepository(request) { + return request.repository === undefined ? { ...request, repository: verifyRepository(request.worktree) } : request; +} + /** A request's resolved repository; every cloud call runs after verifyRepository named it. */ function requireRepository(request) { if (!request.repository) throw new Error("the cloud repository was not resolved from the request or the worktree's origin"); @@ -609,7 +618,7 @@ export async function abandonValidation(request, { confirm = false, home = os.ho validateValidationRequest(request); const key = sha256(JSON.stringify(request)), base = validationReceiptPath(request, key); const file = request.lanes?.some(lane => lane.name === "cloud-capabilities") - ? boundProbeReceipt(base, validationLanes(request).lanes, readLedger(home), resolveClaudeEnvironment(request)) : base; + ? boundProbeReceipt(base, validationLanes(withRepository(request)).lanes, readLedger(home), resolveClaudeEnvironment(request)) : base; const receipt = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : null; const abandoned = receipt && (TERMINAL.has(receipt.status) ? receipt : { ...receipt, status: "abandoned", finishedAt: new Date().toISOString() }); const result = await releaseValidationReservation({ home, key, confirm, unconfirmed: (plan) => unconfirmed("abandon", plan), markRun: (runId) => markRun(home, runId, "abandoned", DEFAULT_WALL_MS), @@ -773,7 +782,7 @@ export function validateValidationRequest(request) { if (Object.hasOwn(request, "env") || Object.hasOwn(request, "envValues")) throw new Error("caller test environment values are refused"); if (!Array.isArray(request.lanes) || request.lanes.length === 0) throw new Error("at least one lane is required"); if (new Set(request.lanes.map((lane) => lane.name)).size !== request.lanes.length) throw new Error("lane names must be unique"); - validationLanes(request); + validationLanes(withRepository(request)); if (request.resultArtifact !== undefined) { const artifact = request.resultArtifact; if (!artifact || typeof artifact !== "object" || typeof artifact.path !== "string" @@ -790,8 +799,9 @@ export function validateValidationRequest(request) { } /** The validation-only brief: exact checkout, install, lanes, no changes, one bound result line. */ -export function validationBrief(request, managedHost = null, provedBranch = null, requestKey = sha256(JSON.stringify(request))) { - validateValidationRequest(request); +export function validationBrief(raw, managedHost = null, provedBranch = null, requestKey = sha256(JSON.stringify(raw))) { + validateValidationRequest(raw); + const request = withRepository(raw); const resolved = validationLanes(request); const artifact = request.resultArtifact; const branch = provedBranch ?? request.branch; diff --git a/plugins/vibe/skills/handoff/scripts/rulings-check.mjs b/plugins/vibe/skills/handoff/scripts/rulings-check.mjs index 96649fdf..31063deb 100644 --- a/plugins/vibe/skills/handoff/scripts/rulings-check.mjs +++ b/plugins/vibe/skills/handoff/scripts/rulings-check.mjs @@ -244,6 +244,18 @@ export function separationRuling(program, reason, tickets) { return null; } +/** + * The program's quoted operator ruling, with its source, whose decision names `ticket` by its whole id, or null. A ruling + * copied from a ticket (`ticket:` channel) or one with no quoted words is never the operator's authority for a worker. + */ +export function operatorTicketRuling(program, ticket) { + for (const match of String(program ?? "").matchAll(PROGRAM_RULING)) { + const [, date, channel, source, decision] = match; + if (channel !== "ticket" && /"[^"\n]+"|“[^”\n]+”/u.test(decision) && rulingNamesScope(decision, [ticket], { exact: true })) return { date, channel, source, decision }; + } + return null; +} + /** A dated operator ruling line: its channel, its optional source after a colon, and its decision. */ const OPERATOR_RULING = /^\s*[-*]\s*Ruling\s+(\d{4}-\d{2}-\d{2})\s+\((operator message|AskUserQuestion)(?::\s*([^)]*?))?\s*\):\s*(\S.*)$/; const LOCATOR_CHANNELS = new Set(["chat", "slack", "dm", "email", "call", "meeting"]); 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 c0f96470..f0d4345c 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.118" + assert claude["version"] == codex["version"] == "1.1.119" 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 1615cd76..9c272536 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.118", manifest - assert "Version `1.1.118`" in skill_split.read(PLUGIN_ROOT / "README.md") + assert json.loads(skill_split.read(PLUGIN_ROOT / manifest / "plugin.json"))["version"] == "1.1.119", manifest + assert "Version `1.1.119`" in skill_split.read(PLUGIN_ROOT / "README.md") changelog = skill_split.read(PLUGIN_ROOT.parents[1] / "CHANGELOG.md") assert "### vibe v1.1.76" in changelog assert "### vibe v1.1.61" in changelog