Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
Merge commit '47c40ac06691bb0ce60bbeda86444a2c7656252f' into HEAD
Corey Olsonf37cc9665dc1
diff --cc src/gate.jsindex d605a9a3,2be010ce..0dcf3345--- a/src/gate.js+++ b/src/gate.js@@@ -6,10 -6,9 +6,10 @@@*/import { spawn, spawnSync } from 'node:child_process';import { randomUUID } from 'node:crypto';- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';- import { dirname, isAbsolute, join, relative, sep } from 'node:path';-import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';-import { dirname, isAbsolute, join, relative, resolve } from 'node:path';++import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';++import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';import { availableParallelism } from 'node:os';+import { fileURLToPath } from 'node:url';import { gitChildEnv, gitPath, headTree, invalidateGitFacts, isClean, untracked } from './git.js';import { secretsIn } from './hooks.js';import { Refused } from './refused.js';@@@ -149,7 -147,147 +149,148 @@@ export function runShell(root, command// Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.const result = spawnSync(`${prefix}(\n${command}\n) 2>&1`, options);invalidateGitFacts();- return { isGreen: result.status === 0, output: `${result.stdout ?? ''}${result.stderr ?? ''}`, seconds: Math.round((Date.now() - started) / 1000) };+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;+ return { isGreen: result.status === 0, output, seconds: Math.round((Date.now() - started) / 1000),+ sandboxBlocked: result.status === 0 ? null : sandboxBlockedOperation(root, output) };+ }++ /** Resolve existing path prefixes so a symlink cannot hide an outside-worktree operation. */+ function diagnosticPath(path) {+ let current = resolve(path);+ const missing = [];+ for (;;) {+ try { return resolve(realpathSync(current), ...missing); }+ catch (error) {+ if (!['ENOENT', 'ENOTDIR'].includes(error.code)) return null;+ const parent = dirname(current);+ if (parent === current) return null;+ missing.unshift(relative(parent, current));+ current = parent;+ }+ }+ }++ /** Describe one OS permission message, resolving file targets against the command's worktree. */-function permissionOperation(root, message) {++function permissionOperation(root, message, { includeFilePaths = true } = {}) {+ const network = /^(listen|bind) (EPERM|EACCES)\b/u.exec(message);+ if (network) return { code: network[2], syscall: network[1], operation: `${network[1]} (${network[2]})` };++ if (!includeFilePaths) return null;+ const file = /^(EPERM|EACCES): [^\n]*?, (open|mkdir|read|write|rename|unlink|scandir|access) (['"])([^\n]+?)\3(?= -> |$)/u.exec(message);+ const python = /^PermissionError: \[Errno (?:1|13)\] [^\n]*?: ['"]([^'"\n]+)['"]/u.exec(message);+ if (!file && !python) return null;+ const path = diagnosticPath(resolve(root, file ? file[4] : python[1]));+ const tree = diagnosticPath(root);+ if (!path || !tree) return null;+ const within = relative(tree, path);+ if (within !== '..' && !within.startsWith('../') && !isAbsolute(within)) return null;+ const code = file ? file[1] : 'EACCES';+ return { code, path, syscall: file ? file[2] : null,+ operation: `${file ? file[2] : 'file access'} ${JSON.stringify(path)} (${code})` };+ }++ /** Decode the single-line quoted YAML scalars emitted by Node's TAP reporter. */+ function tapScalar(value) {+ if (value.startsWith('"')) {+ try { return JSON.parse(value); } catch { return null; }+ }+ if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/gu, "'");+ return /^[A-Z_]+$/u.test(value) ? value : null;+ }++ /** Scan complete lines with bounded TAP state so assertion messages cannot impersonate OS codes. */-export function sandboxBlockedScanner(root) {++export function sandboxBlockedScanner(root, { includeFilePaths = true } = {}) {+ let failureIndent = null;+ let fieldIndent = null;+ let permission = null;+ let code = null;+ let comment = null;+ let startup = null;+ let failureMessage = null;+ let failureType = false;+ let exitCode = null;+ /** Retain one pending fatal diagnostic and the current failed TAP record. */+ return (raw) => {+ const line = raw.trim().replace(/^#\s*/u, '');+ const indent = raw.length - raw.trimStart().length;+ // Node's TAP reporter prints test-console output as comments and assertion details+ // as indented YAML. Neither is a standalone gate diagnostic, even when it contains+ // text that looks exactly like an operating-system denial.+ if (indent === 0 && !raw.startsWith('#') && /^(?:Error: |PermissionError: )/u.test(line)) {- const direct = permissionOperation(root, line.replace(/^Error: /u, ''));++ const direct = permissionOperation(root, line.replace(/^Error: /u, ''), { includeFilePaths });+ if (direct) return direct.operation;+ }+ if (/^TAP version \d+$/u.test(raw)) {+ comment = null; startup = null;+ failureIndent = null; fieldIndent = null; permission = null; code = null;+ failureMessage = null; failureType = false; exitCode = null;+ }+ // Uncaught module-load errors are comments too. Keep their complete Node fatal+ // diagnostic pending; it is evidence only if the following file record failed+ // to start. A test logging a caught error and then asserting is not that record.+ if (indent === 0 && raw.startsWith('#')) {+ if (line.startsWith('Error: ')) {- const operation = permissionOperation(root, line.slice('Error: '.length));++ const operation = permissionOperation(root, line.slice('Error: '.length), { includeFilePaths });+ comment = operation ? { operation, code: null, syscall: null, path: null, closed: false, fatal: false } : null;+ } else if (comment) {+ const field = /^(code|syscall|path): (.*)$/u.exec(line);+ if (field) comment[field[1]] = tapScalar(field[2].replace(/,$/u, ''));+ else if (line === '}') comment.closed = true;+ else if (/^Node\.js v\d+\./u.test(line)) comment.fatal = true;+ else if (line && !/^at |^errno: |^address: |^port: /u.test(line)+ && !(comment.closed && comment.fatal && line.startsWith('Subtest: '))) comment = null;+ }+ }+ if (/^(?:not )?ok \d+\b/u.test(line)) {+ failureIndent = /^not ok /u.test(line) ? indent : null;+ const operation = comment?.operation;+ startup = failureIndent !== null && comment?.closed && comment.fatal+ && comment.code === operation.code && comment.syscall === operation.syscall+ && (!operation.path || (typeof comment.path === 'string'+ && diagnosticPath(resolve(root, comment.path)) === operation.path)) ? operation : null;+ comment = null;+ fieldIndent = null; permission = null; code = null;+ failureMessage = null; failureType = false; exitCode = null;+ } else if (line === '---' && failureIndent !== null && indent === failureIndent + 2) {+ fieldIndent = indent;+ } else if (line === '...' && indent === fieldIndent) {+ failureIndent = null; fieldIndent = null; permission = null; code = null;+ startup = null; comment = null;+ failureMessage = null; failureType = false; exitCode = null;+ } else if (fieldIndent !== null && indent === fieldIndent) {+ const field = /^(error|code|failureType|exitCode): (.*)$/u.exec(line);+ if (field) {+ const value = tapScalar(field[2]);+ if (field[1] === 'error') {+ failureMessage = value;- permission = typeof value === 'string' ? permissionOperation(root, value) : null;++ permission = typeof value === 'string' ? permissionOperation(root, value, { includeFilePaths }) : null;+ } else if (field[1] === 'code') {+ code = value;+ if (code !== 'ERR_TEST_FAILURE') startup = null;+ } else if (field[1] === 'failureType') failureType = value === 'testCodeFailure' || field[2] === 'testCodeFailure';+ else exitCode = /^[1-9]\d*$/u.test(field[2]) && Number.isSafeInteger(Number(field[2])) ? Number(field[2]) : null;+ if (permission && permission.code === code) return permission.operation;+ if (startup && code === 'ERR_TEST_FAILURE' && failureMessage === 'test failed'+ && failureType && exitCode !== null) return startup.operation;+ }+ }+ return null;+ };+ }++ /** Recognize concrete OS permission diagnostics, keeping ordinary assertion failures ordinary. */-export function sandboxBlockedOperation(root, output) {- const scan = sandboxBlockedScanner(root);++export function sandboxBlockedOperation(root, output, options) {++ const scan = sandboxBlockedScanner(root, options);+ for (const line of output.split('\n')) {+ const operation = scan(line);+ if (operation) return operation;+ }+ return null;+ }++ /** Refuse an environment-blocked proof after its ordinary raw logs and timings are persisted. */+ export function refuseSandboxBlocked(run) {+ if (run.sandboxBlocked) throw new Refused('SANDBOX_BLOCKED',+ `The environment refused ${run.sandboxBlocked}. Ask the person to allow this operation, or run the gate outside the sandbox; keep the tests unchanged.`);}/** Replace a possible secret-bearing line before persisting a direct item-check log. */@@@ -174,17 -312,16 +315,22 @@@ export function runProfiledShell(root,const logPath = persistLog ? join(directory, `${artifactPrefix}-${id}.log`) : null;const started = Date.now();const inherited = {- ...(gateLease ? gateSlotEnvironment(gateLease) : gateSlotHeld ? { [GATE_SLOT_HELD_ENV]: '1' } : {}),+ ...(gateLease && !gateLease.runner ? gateSlotEnvironment(gateLease) : gateSlotHeld ? { [GATE_SLOT_HELD_ENV]: '1' } : {}),[LANDING_RUN_ENV]: landing ? '1' : '0',};- const run = runShell(root, command, { pipefail, env: inherited });+ const run = gateLease?.runner ? runOnRunner(root, command, { runner: gateLease.runner, source: gateLease.source,+ browser: gateLease.browser, pipefail, metadata: { ...(gateLease.runMetadata ?? {}), landing } }) : runShell(root, command, { pipefail, env: inherited });++ const sandboxBlocked = run.isGreen ? null : run.sandboxBlocked ?? (run.executionRunner++ // The controller cannot realpath remote files; retain the network denial signal without treating remote paths as local paths.++ ? sandboxBlockedOperation(root, run.output, { includeFilePaths: false })++ : sandboxBlockedOperation(root, run.output));++ const profiledRun = { ...run, sandboxBlocked };const profile = writeTimingProfile(profilePath, {- ...runTiming(run, command),- ...timingFromOutput(run.output, timingRunner(command)),++ ...runTiming(profiledRun, command),waitMs: Math.max(0, Math.round(waitMs)), wallMs: Math.max(0, Date.now() - started),});if (logPath) writeFileSync(logPath, safeLog(run.output), { mode: 0o600 });-- return { ...run, profile, profilePath, logPath };++ return { ...profiledRun, profile, profilePath, logPath };}/** Run an independent focused comparison without blocking other holders of the machine pool.@@@ -195,14 -332,6 +341,16 @@@*/export async function runProfiledShellAsync(root, command, { waitMs = 0, gateSlotHeld = false, gateLease, landing = false } = {}) {const started = Date.now();+ if (gateLease?.runner) {+ const run = await runOnRunnerAsync(root, command, { runner: gateLease.runner, source: gateLease.source,+ browser: gateLease.browser, metadata: { ...(gateLease.runMetadata ?? {}), landing } });+ const wallMs = Math.max(0, Date.now() - started);+ const profilePath = join(dirname(gitPath(root, LOG)), `pullboard-gate-${randomUUID()}.profile.json`);++ const sandboxBlocked = run.isGreen ? null : run.sandboxBlocked++ ?? sandboxBlockedOperation(root, run.output, { includeFilePaths: false });+ const profile = writeTimingProfile(profilePath, { ...runTiming(run, command), waitMs, wallMs });- return { ...run, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };++ return { ...run, sandboxBlocked, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };+ }const inherited = {...(gateLease ? gateSlotEnvironment(gateLease) : gateSlotHeld ? { [GATE_SLOT_HELD_ENV]: '1' } : {}),[LANDING_RUN_ENV]: landing ? '1' : '0',@@@ -230,29 -359,9 +378,29 @@@const profilePath = join(dirname(gitPath(root, LOG)), `pullboard-gate-${randomUUID()}.profile.json`);const profile = writeTimingProfile(profilePath, { ...timingFromOutput(output, timingRunner(command)),waitMs: Math.max(0, Math.round(waitMs)), wallMs });- return { isGreen: status === 0 && !overflow && !failure, output, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };+ return { isGreen: status === 0 && !overflow && !failure, sandboxBlocked: status === 0 ? null : sandboxBlockedOperation(root, output), output, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };}+/** Keep raw remote TAP intact while resolving its measured filenames against the local source. */+function runTiming(run, command) {+ const profile = timingFromOutput(run.output, timingRunner(command));+ if (!run.executionRunner) return profile;+ /** Relocate only paths inside the actual remote checkout, never a foreign absolute path. */+ const localPath = path => {+ if (typeof path !== 'string') return path;+ const original = path;+ if (path.startsWith('file:')) {+ try { path = fileURLToPath(path); } catch { return original; }+ }+ if (!isAbsolute(path)) return original;+ const suffix = relative(run.executionRoot, path);+ return suffix && suffix !== '..' && !suffix.startsWith(`..${sep}`) && !isAbsolute(suffix) ? suffix : original;+ };+ return { ...profile, executionRunner: run.executionRunner, executionSource: run.executionSource,+ files: (profile.files ?? []).map(file => ({ ...file, path: localPath(file.path) })),+ tests: (profile.tests ?? []).map(test => ({ ...test, file: localPath(test.file) })) };+}+/** Persist one sanitized timing profile as a private artifact.* @param {string} path* @param {{ files?: Array<object>, tests?: Array<object>, [key: string]: any }} profile@@@ -452,10 -529,9 +602,11 @@@ export async function runSubmitGate(roorunner: [...new Set(profiles.map(value => value.runner))].join(', '),format: [...new Set(profiles.map(value => value.format))].join('+'),unavailable: profiles.some(value => value.unavailable) ? 'per-test timing unavailable: output was not TAP or JUnit (one or more phases)' : null,+ ...(lease.runner ? { executionRunner: lease.runner.host,+ executionSource: profiles.find(value => value.executionSource)?.executionSource } : {}),});+ refuseSandboxBlocked(proof);- return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, deferred, deferFullFallback, check: receipt,+ return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, ...(deferred ? { files: proofFiles, submitInvariants: invariants } : {}), deferred, deferFullFallback, check: receipt,profile, profilePath, proofProfilePath: proof.profilePath, proofLog: proof.log };};if (!criterion.isGreen) {diff --cc test/machine.test.jsindex 985d8fc1,c1a3cce3..fd0f0fca--- a/test/machine.test.js+++ b/test/machine.test.js@@@ -27,7 -27,7 +27,8 @@@ const NOT_MOVES =ALREADY_JOINED: 'registering who is asking, before any move',BAD_ROUTE: 'registering who is asking, before any move',ONE_COORDINATOR: 'registering who is asking, before any move',+ MACHINE_HOME_NOT_WRITABLE: 'machine-wide storage must be writable before a command runs',+ SANDBOX_BLOCKED: 'the command environment must allow the gate or check operation',BAD_MACHINE_SETTINGS: 'machine-wide settings checked before a command runs',BAD_GATE_SLOTS: 'machine-wide gate capacity checked before a command runs',BAD_BROWSER_SLOTS: 'machine-wide browser capacity checked before a command runs',