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
fix(docs): keep README capture view owned [I11,I13]
Corey Olson93a8393706c7
diff --git a/docs/shots/demo.mjs b/docs/shots/demo.mjsindex 1ecd0fc3..76d3b6c5 100644--- a/docs/shots/demo.mjs+++ b/docs/shots/demo.mjs@@ -4,6 +4,7 @@* The disposable repo and private PULLBOARD_HOME keep personal projects and shouts out of the art.*/import { spawn, spawnSync } from 'node:child_process';+import { readlinkSync } from 'node:fs';import { mkdtemp, mkdir, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';@@ -11,6 +12,7 @@ import { fileURLToPath } from 'node:url';import { browser, waitForDemoBoard } from './capture-browser.mjs';import { FIXED_TIME, isolatedEnv } from './demo-env.mjs';import { renderTour } from './tour-renderer.mjs';+import { AGENT_SHELL_MARKERS } from '../../src/person.js';const ROOT = resolve(fileURLToPath(new URL('../..', import.meta.url)));const BIN = join(ROOT, 'bin', 'pullboard.js');@@ -38,6 +40,87 @@ async function stop(child) {await new Promise((resolveStop) => child.once('close', resolveStop));}+/** Read one process identity without capturing its environment or application data. */+function processIdentity(pid) {+ if (!Number.isInteger(pid) || pid < 1) return null;+ const result = spawnSync('ps', ['-ww', '-p', String(pid), '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'lstart=', '-o', 'command='], { encoding: 'utf8' });+ if (result.status !== 0) return null;+ const fields = result.stdout.trim().split(/\s+/);+ if (fields.length < 9 || Number(fields[0]) !== pid) return null;+ const identity = { pid, ppid: Number(fields[1]), pgid: Number(fields[2]), birth: fields.slice(3, 8).join(' '), command: fields.slice(8).join(' ') };+ if (process.platform === 'linux') {+ try { identity.cwd = readlinkSync(`/proc/${pid}/cwd`); } catch { identity.cwd = null; }+ } else if (process.platform === 'darwin') {+ const cwd = spawnSync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'], { encoding: 'utf8' });+ identity.cwd = cwd.status === 0 ? cwd.stdout.split(/\r?\n/).find((line) => line.startsWith('n'))?.slice(1) ?? null : null;+ } else identity.cwd = null;+ return identity;+}++/** List fixture-owned command lines while the temporary directory still exists. */+function fixtureProcessIdentities(directory, knownViewPid) {+ const result = spawnSync('ps', ['-ww', '-A', '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'lstart=', '-o', 'command='], { encoding: 'utf8' });+ if (result.status !== 0) throw new Error(`could not inspect processes for the README capture (ps status ${result.status})`);+ return result.stdout.split(/\r?\n/).flatMap((line) => {+ const fields = line.trim().split(/\s+/);+ const pid = Number(fields[0]);+ if (!Number.isInteger(pid) || pid < 1 || pid === process.pid || fields.length < 9) return [];+ const identity = { pid, ppid: Number(fields[1]), pgid: Number(fields[2]), birth: fields.slice(3, 8).join(' '), command: fields.slice(8).join(' ') };+ if (!identity.command.includes(directory) && identity.pid !== knownViewPid) return [];+ return [{ ...identity, cwd: processIdentity(identity.pid)?.cwd ?? null }];+ });+}++/** In the opt-in test receipt only, stop the one exact view PID this capture reported. */+async function stopObservedView(observation) {+ const record = observation.viewBeforeStop;+ const current = processIdentity(observation.viewPid);+ const cleanup = { attempted: false, pid: observation.viewPid ?? null, signal: null, exited: current === null, refused: null };+ if (!current) return cleanup;+ if (!record || current.birth !== record.birth || current.command !== record.command+ || !current.command.includes(observation.entrypoint)+ || !/\bview\s+--no-open\s+--port\s+0(?:\s|$)/.test(current.command)+ || current.cwd !== record.cwd || record.cwd !== observation.repo) {+ cleanup.refused = 'the live PID did not match the recorded fixture view identity';+ cleanup.exited = false;+ return cleanup;+ }+ cleanup.attempted = true;+ cleanup.signal = 'SIGTERM';+ try { process.kill(current.pid, 'SIGTERM'); }+ catch (error) { cleanup.refused = `${error.code ?? error.name}: could not signal recorded view PID`; cleanup.exited = false; return cleanup; }+ const deadline = Date.now() + 5_000;+ let stillLive = processIdentity(current.pid);+ while (stillLive && Date.now() < deadline) {+ if (stillLive.birth !== record.birth || stillLive.command !== record.command) {+ cleanup.refused = 'the PID identity changed during bounded cleanup';+ cleanup.exited = false;+ return cleanup;+ }+ await new Promise((resolveDelay) => setTimeout(resolveDelay, 50));+ stillLive = processIdentity(current.pid);+ }+ cleanup.exited = stillLive === null;+ if (!cleanup.exited) cleanup.refused = 'the exact view PID remained after bounded SIGTERM cleanup';+ return cleanup;+}++/** Record all fixture processes and the exact view identity before the ordinary stop. */+function recordBeforeViewStop(observation) {+ if (!observation || observation.fixtureProcessesBeforeStop) return;+ observation.viewBeforeStop = processIdentity(observation.viewPid);+ observation.fixtureProcessesBeforeStop = fixtureProcessIdentities(observation.demoDirectory, observation.viewPid);+}++/** Record ordinary-stop survivors, apply only the owned test cleanup, then rescan. */+async function recordAfterViewStop(observation) {+ if (!observation || observation.fixtureProcessesAfterStop) return;+ observation.viewAfterStop = processIdentity(observation.viewPid);+ observation.fixtureProcessesAfterStop = fixtureProcessIdentities(observation.demoDirectory, observation.viewPid);+ observation.testCleanup = await stopObservedView(observation);+ observation.fixtureProcessesAfterTestCleanup = fixtureProcessIdentities(observation.demoDirectory, observation.viewPid);+}+/** Export the board, then replace its random storage id with a stable public snapshot id. */async function exportBoard(repo, env) {await rm(DEMO_OUTPUT, { recursive: true, force: true });@@ -169,6 +252,19 @@ else {const base = await realpath(await mkdtemp(join(tmpdir(), 'pullboard-readme-demo-')));let view;let server;+ const observationPath = process.env.PULLBOARD_README_CAPTURE_OBSERVATION_PATH;+ const requestedForeground = process.env.PULLBOARD_README_CAPTURE_FOREGROUND === '1';+ const observation = observationPath ? {+ arm: requestedForeground ? 'foreground-control' : 'unchanged-default',+ startedAt: new Date().toISOString(),+ demoDirectory: base,+ repo: join(base, 'demo-board'),+ entrypoint: BIN,+ sourceEnv: {+ aiAgentPresent: process.env.AI_AGENT !== undefined,+ requestedForeground,+ },+ } : null;try {const clockShim = join(base, 'fixed-clock.mjs');await writeFile(clockShim, `const NativeDate = Date;\nconst fixed = NativeDate.parse(process.env.PULLBOARD_DEMO_NOW || ${JSON.stringify(FIXED_TIME)});\nclass FixedDate extends NativeDate { constructor(...args) { super(...(args.length ? args : [fixed])); } static now() { return fixed; } }\nglobalThis.Date = FixedDate;\n`);@@ -179,14 +275,49 @@ else {const repo = await buildBoard(base, env);await exportBoard(repo, env);if (!boardOnly) {- server = spawn(process.execPath, [BIN, 'view', '--no-open', '--port', '0'], { cwd: repo, env, stdio: ['ignore', 'pipe', 'ignore'] });+ const viewEnv = { ...env };+ delete viewEnv.PULLBOARD_README_CAPTURE_FOREGROUND;+ delete viewEnv.PULLBOARD_README_CAPTURE_OBSERVATION_PATH;+ delete viewEnv.PULLBOARD_README_CAPTURE_EVIDENCE_DIR;+ viewEnv.PULLBOARD_VIEW_FOREGROUND = '1';+ server = spawn(process.execPath, [BIN, 'view', '--no-open', '--port', '0'], { cwd: repo, env: viewEnv, stdio: ['ignore', 'pipe', 'ignore'] });+ if (observation) {+ observation.viewLaunch = {+ directPid: server.pid,+ cwd: repo,+ stdoutIsTTY: Boolean(server.stdout?.isTTY),+ foregroundEnv: viewEnv.PULLBOARD_VIEW_FOREGROUND === '1',+ aiAgentPresent: viewEnv.AI_AGENT !== undefined,+ agentMarkersPresent: AGENT_SHELL_MARKERS.some((name) => viewEnv[name] !== undefined),+ };+ }const url = await new Promise((resolveUrl, reject) => {let output = '';+ let pageUrl;const timer = setTimeout(() => reject(new Error('The demo view did not start')), 10000);+ const resolveWhenReady = () => {+ if (pageUrl && (!observation || observation.viewPid)) {+ if (observation) observation.viewOutput = output.replace(/(https?:\/\/[^\s?#]+)\?[^\s#]*/g, '$1?[redacted]');+ clearTimeout(timer);+ resolveUrl(pageUrl);+ }+ };server.stdout.setEncoding('utf8');- server.stdout.on('data', (chunk) => { output += chunk; const match = /Pullboard view: (http:\/\/[^\s]+)/.exec(output); if (match) { clearTimeout(timer); resolveUrl(match[1]); } });+ server.stdout.on('data', (chunk) => {+ output += chunk;+ const match = /Pullboard view: (http:\/\/[^\s]+)/.exec(output);+ const pid = /To stop it: (?:kill|taskkill \/PID) (\d+)/.exec(output);+ if (pid && observation) observation.viewPid = Number(pid[1]);+ if (match) pageUrl = match[1];+ resolveWhenReady();+ });server.once('close', () => { clearTimeout(timer); reject(new Error('The demo view stopped before it opened')); });});+ if (observation) {+ observation.viewLaunch.actualViewPid = observation.viewPid ?? null;+ observation.viewLaunch.branch = observation.viewPid === server.pid ? 'foreground' : observation.viewPid ? 'background' : 'unknown';+ observation.viewLaunch.reportedIdentity = processIdentity(observation.viewPid);+ }view = await browser(chrome, join(base, 'chrome-profile'), url);await waitForDemoBoard(view, repo);await view.viewport(1440, 900);@@ -207,13 +338,32 @@ else {await view.evaluate('document.fonts.ready.then(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))))');await view.screenshot(join(OUTPUT, 'shouts.png'));await view.close(); view = null;+ recordBeforeViewStop(observation);await stop(server); server = null;+ await recordAfterViewStop(observation);if (!screenshotsOnly) await recordTour(env);+ if (observation) observation.outcome = 'completed';}}} finally {- if (view) await view.close();- if (server) await stop(server);+ const teardownErrors = [];+ if (view) {+ try { await view.close(); } catch (error) { teardownErrors.push(`${error.name}: browser close failed`); }+ view = null;+ }+ try { recordBeforeViewStop(observation); } catch (error) { teardownErrors.push(`${error.name}: pre-stop process snapshot failed`); }+ if (server) {+ try { await stop(server); } catch (error) { teardownErrors.push(`${error.name}: view launcher stop failed`); }+ server = null;+ }+ try { await recordAfterViewStop(observation); } catch (error) { teardownErrors.push(`${error.name}: post-stop process snapshot failed`); }+ if (observation) {+ observation.teardownErrors = teardownErrors;+ observation.finishedAt = new Date().toISOString();+ try { await writeFile(observationPath, `${JSON.stringify(observation, null, 2)}\n`, { mode: 0o600 }); }+ catch (error) { teardownErrors.push(`${error.name}: observation receipt write failed`); }+ }+ if (teardownErrors.length) process.exitCode = 1;await rm(base, { recursive: true, force: true });}}diff --git a/docs/shots/shots.test.js b/docs/shots/shots.test.jsindex d8ecac5e..e13354f1 100644--- a/docs/shots/shots.test.js+++ b/docs/shots/shots.test.js@@ -102,10 +102,20 @@ test('the demo board declares every agent\'s model [I11,I13]', () => {}});-test('the README capture runs end to end [I11,I13]', { timeout: 240_000 }, () => { // budget: outer ceiling gives the bounded capture process 30s to clean up.- const fixture = mkdtempSync(join(tmpdir(), 'pullboard-readme-capture-'));+test('the README capture leaves no view running [I11,I13]', { timeout: 240_000 }, () => {+ const source = fileURLToPath(ROOT);+ const images = ['desktop.png', 'phone.png', 'shouts.png'];+ const chrome = process.env.PULLBOARD_CHROME || [+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',+ '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',+ ].find((candidate) => { try { return spawnSync(candidate, ['--version'], { stdio: 'ignore' }).status === 0; } catch { return false; } });+ assert.ok(chrome, 'the README capture requires installed headless Chrome');+ const foregroundControl = process.env.PULLBOARD_README_CAPTURE_FOREGROUND === '1';+ const arm = foregroundControl ? 'foreground-control' : 'unchanged-default';+ const evidenceDirectory = process.env.PULLBOARD_README_CAPTURE_EVIDENCE_DIR;+ if (evidenceDirectory) mkdirSync(evidenceDirectory, { recursive: true, mode: 0o700 });+ const fixture = mkdtempSync(join(tmpdir(), `pullboard-readme-capture-${arm}-`));try {- const source = fileURLToPath(ROOT);const root = join(fixture, 'repo');mkdirSync(root);for (const directory of ['bin', 'src', 'skills', 'docs/shots']) {@@ -120,27 +130,59 @@ test('the README capture runs end to end [I11,I13]', { timeout: 240_000 }, () =>const pullboard = join(shims, 'pullboard');writeFileSync(pullboard, `#!/bin/sh\nexec "${process.execPath}" "${join(root, 'bin/pullboard.js')}" "$@"\n`);chmodSync(pullboard, 0o755);- const images = ['desktop.png', 'phone.png', 'shouts.png'];for (const image of images) rmSync(join(root, 'docs/shots', image), { force: true });- const chrome = process.env.PULLBOARD_CHROME || [- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',- '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',- ].find((candidate) => { try { return spawnSync(candidate, ['--version'], { stdio: 'ignore' }).status === 0; } catch { return false; } });- assert.ok(chrome, 'the README capture requires installed headless Chrome');+ const observationPath = join(fixture, 'capture-observation.json');+ const env = {+ ...process.env,+ PATH: [shims, process.env.PATH].filter(Boolean).join(delimiter),+ PULLBOARD_CHROME: chrome,+ PULLBOARD_README_CAPTURE_OBSERVATION_PATH: observationPath,+ TMPDIR: fixture,+ TMP: fixture,+ TEMP: fixture,+ HOME: join(fixture, 'home'),+ PULLBOARD_HOME: join(fixture, 'home'),+ PULLBOARD_MACHINE_HOME: join(fixture, 'home'),+ };+ delete env.PULLBOARD_VIEW_FOREGROUND;+ if (!foregroundControl) delete env.PULLBOARD_README_CAPTURE_FOREGROUND;const result = spawnSync(process.execPath, [join(root, 'docs/shots/demo.mjs'), '--screenshots-only'], {cwd: root,- env: { ...process.env, PATH: [shims, process.env.PATH].filter(Boolean).join(delimiter), PULLBOARD_CHROME: chrome, HOME: join(fixture, 'home'), PULLBOARD_HOME: join(fixture, 'home'), PULLBOARD_MACHINE_HOME: join(fixture, 'home') },+ env,encoding: 'utf8',- timeout: 210_000, // budget: isolated board build, export and three Chrome captures; 30s remains for cleanup.+ timeout: 210_000,});- assert.equal(result.status, 0, `the isolated README capture completes in headless Chrome: ${result.stderr}\n${result.stdout}`);+ const observation = existsSync(observationPath) ? JSON.parse(readFileSync(observationPath, 'utf8')) : null;+ const outcome = {+ arm,+ runtime: process.version,+ platform: process.platform,+ status: result.status,+ signal: result.signal,+ stdout: result.stdout,+ stderr: result.stderr,+ observation,+ };+ if (evidenceDirectory) writeFileSync(join(evidenceDirectory, `${arm}.json`), `${JSON.stringify(outcome, null, 2)}\n`, { mode: 0o600 });+ assert.equal(result.status, 0, `${arm}: the isolated README capture completes in headless Chrome: ${result.stderr}\n${result.stdout}`);for (const image of images) {- assert.ok(existsSync(join(root, 'docs/shots', image)), `${image} was captured`);+ assert.ok(existsSync(join(root, 'docs/shots', image)), `${arm}: ${image} was captured`);const bytes = readFileSync(join(root, 'docs/shots', image));- assert.ok(bytes.length > 8, `${image} was captured`);- assert.deepEqual([...bytes.subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10], `${image} is a PNG screenshot`);+ assert.ok(bytes.length > 8, `${arm}: ${image} was captured`);+ assert.deepEqual([...bytes.subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10], `${arm}: ${image} is a PNG screenshot`);}- assert.ok(statSync(join(root, 'docs/demo/index.html')).size > 0, 'the demo export was rebuilt');+ assert.ok(statSync(join(root, 'docs/demo/index.html')).size > 0, `${arm}: the demo export was rebuilt`);+ assert.ok(observation, `${arm}: the capture process identity receipt was written`);+ assert.equal(observation.viewLaunch.stdoutIsTTY, false, `${arm}: the nested view stdout is piped`);+ assert.equal(observation.viewLaunch.aiAgentPresent, false, `${arm}: the nested view has no AI_AGENT marker`);+ assert.equal(observation.viewLaunch.agentMarkersPresent, false, `${arm}: the nested view has no agent shell markers`);+ assert.notEqual(observation.viewLaunch.branch, 'unknown', `${arm}: the foreground/background branch is observed`);+ if (foregroundControl) assert.equal(observation.viewLaunch.branch, 'foreground', 'the fixture-only foreground control selects the foreground server');+ assert.equal(observation.viewAfterStop, null, `${arm}: the view PID is gone after the ordinary capture cleanup`);+ assert.deepEqual(observation.fixtureProcessesAfterStop, [], `${arm}: no process from the fixture survives capture cleanup`);+ assert.equal(observation.testCleanup.exited, true, `${arm}: the test-only exact-PID cleanup completed`);+ assert.deepEqual(observation.fixtureProcessesAfterTestCleanup, [], `${arm}: test cleanup leaves no fixture process behind`);+ assert.deepEqual(observation.teardownErrors, [], `${arm}: capture teardown completed without errors`);} finally {rmSync(fixture, { recursive: true, force: true });}