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(resume): require the view’s scoped setup receipt [N32,N19]
Corey Olson1934b24bbd2f
diff --git a/src/cli.js b/src/cli.jsindex e51bcc7c..10b0fda2 100644--- a/src/cli.js+++ b/src/cli.js@@ -4,7 +4,7 @@*/import { createHash, randomUUID } from 'node:crypto';import { spawn, spawnSync } from 'node:child_process';-import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';+import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';import { loadavg } from 'node:os';import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';import { performance } from 'node:perf_hooks';@@ -1042,6 +1042,34 @@ function resumeReleaseNotes(info) {return releases.length ? { releases: releases.slice(0, 3), omitted: Math.max(0, releases.length - 3), notes: 'CHANGELOG.md' } : null;}+/** Identify setup from this board's coordinator enrollment, independently of agent flags. */+function setupIdentity(board) {+ return { boardId: store.boardId(board),+ setupStartedAt: store.listAgents(board).find(agent => agent.agent_id === COORDINATOR)?.agent_created_at };+}++/** Read only the view's typed successful-bind receipt for this board and setup. */+function viewSetupComplete(ctx, board) {+ let receipt;+ try { receipt = JSON.parse(readFileSync(join(ctx.info.commonDir, 'pullboard', 'view-bind.json'), 'utf8')); }+ catch (error) { if (error.code === 'ENOENT' || error instanceof SyntaxError) return false; throw error; }+ const identity = setupIdentity(board);+ return receipt?.type === 'pullboard.view.bound' && receipt.version === 1+ && receipt.boardId === identity.boardId && receipt.setupStartedAt === identity.setupStartedAt+ && Number.isFinite(Date.parse(receipt.boundAt))+ && Date.parse(receipt.boundAt) >= Date.parse(identity.setupStartedAt);+}++/** Atomically record a successful real view bind, scoped to this board's current setup. */+function recordViewBind(ctx, board) {+ const file = join(ctx.info.commonDir, 'pullboard', 'view-bind.json');+ const temporary = file + '.' + randomUUID() + '.tmp';+ const receipt = { type: 'pullboard.view.bound', version: 1, ...setupIdentity(board), boundAt: new Date().toISOString() };+ mkdirSync(dirname(file), { recursive: true });+ writeFileSync(temporary, JSON.stringify(receipt) + '\n', { mode: 0o600 });+ renameSync(temporary, file);+}+/** Derive the next setup question from the real requirements, config, items and view receipt. */function boardSetup(ctx, card) {const rows = loadSpec(ctx.info.root, ctx.config).rows;@@ -1055,18 +1083,20 @@ function boardSetup(ctx, card) {const quote = value => "'" + String(value).replaceAll("'", "'\\''") + "'";/** Preserve all existing configuration when recording one setup answer. */const configure = patch => `node -e ${quote(`const fs=require('node:fs');const p='pullboard.json';const c=JSON.parse(fs.readFileSync(p,'utf8'));${patch};fs.writeFileSync(p,JSON.stringify(c,null,2)+${JSON.stringify('\n')})`)}`;+ const proposedIds = rows.length ? rows.map(row => row.id).join(',') : 'G1,G2';const steps = [{ number: 1, done: approved.length > 0, question: 'Ask the person: what are we building, and who will use it? Draft a few requirements as pending, then ask the person to approve them.',- command: `node -e ${quote(`require('node:fs').appendFileSync(${JSON.stringify(ctx.config.spec)},${JSON.stringify('\n- G1 [pending, must] Describe the first thing the person wants. | gate: review\n')})`)}`,- afterAnswer: 'Replace the proposed text with the person’s answer; the person runs pullboard spec approve G1, then the agent runs pullboard spec apply.' },+ command: rows.length ? `pullboard spec show ${quote(rows[0].id)}` : `node -e ${quote(`require('node:fs').appendFileSync(${JSON.stringify(ctx.config.spec)},${JSON.stringify('\n- G1 [pending, must] Describe the first thing the person wants. | gate: review\n- G2 [pending, must] Describe how the person will know it works. | gate: review\n')})`)}`,+ afterAnswer: `Replace the proposed text with the person’s answer; the person approves ${proposedIds} in Pullboard View or runs pullboard spec approve ${proposedIds} in their own terminal; then the coordinator runs pullboard spec apply.` },{ number: 2, done: lanes.length > 0, question: `Ask the person: how should we divide the work? Suggested folders: ${folders.join(', ') || 'app/ (create it for the app)'}.`,command: configure(`c.lanes[${JSON.stringify(lane)}]={owns:[${JSON.stringify(lane + '/')}]}`) },{ number: 3, done: Boolean(ctx.config.gate?.trim()), question: `Ask the person: which command proves the build works? Suggested: ${detectGate(ctx.info.root) || 'choose the repo’s test command'}.`,command: configure(`c.gate=${JSON.stringify(detectGate(ctx.info.root) || '<test command>')}`) },{ number: 4, done: card.all.length > 0, question: 'Ask the person: what is the first small piece we should build?',command: `pullboard add ${quote(lane)} 'First small piece' --specs ${quote(approved[0]?.id ?? 'G1')} --criterion 'Describe what the person will be able to do'` },- { number: 5, done: card.viewOpened || card.agents.some(agent => !['coordinator', 'review'].includes(agent.agent_lane)),- question: 'Ask the person: shall we open the board so you can follow the work?', command: 'pullboard view' },+ { number: 5, done: card.viewOpened,+ question: 'Ask the person: shall we open the board so you can follow the work?', command: 'pullboard view',+ afterAnswer: 'Run this in the person’s own terminal, or start it in the background as the agent so setup can continue. The view records its successful bind for this board.' },];const current = steps.find(step => !step.done);return current ? { step: current.number, total: 5, ...current, steps } : null;@@ -1108,7 +1138,7 @@ function resumeHere(io) {unread: store.unreadCount(board, me.id),newest: store.peekShouts(board, me.id, 1),agents: store.listAgents(board),- viewOpened: store.allShouts(board).some(shout => shout.shout_text === 'Opened Pullboard view for this board.'),+ viewOpened: viewSetupComplete(ctx, board),};});card.relayProblems = unlinkedRelayProjects();@@ -1237,15 +1267,15 @@ async function viewHere(io, values) {const port = values.port === undefined ? 0 : Number(values.port);if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Refused('USAGE', '--port is a number from 0 to 65535; 0 picks a free one');const view = await serveView({ port, isMain: codeIsFromMain() });- // Record the actual successful server bind, rather than an agent-controlled setup flag.+ // Only an actual bind writes this typed receipt; ordinary shouts cannot complete setup.try {- const ctx = existsSync(join(io.cwd, CONFIG_FILE)) ? context(io) : null;- if (ctx?.info.isMain) await withBoard(ctx, async board => {- if (!store.allShouts(board).some(shout => shout.shout_text === 'Opened Pullboard view for this board.')) {- await ordered(ctx, board, 'shout', [{ from: COORDINATOR, to: 'all',- text: 'Opened Pullboard view for this board.', lanes: laneNames(ctx.config) }]);- }- });+ let info;+ try { info = repoInfo(io.cwd); }+ catch (error) { if (!(error instanceof Refused)) throw error; }+ if (info && existsSync(join(info.root, CONFIG_FILE))) {+ const ctx = context(io);+ withBoard(ctx, board => recordViewBind(ctx, board));+ }} catch (error) {await view.close();throw error;diff --git a/test/e2e-cli.test.js b/test/e2e-cli.test.jsindex ea77cf70..dc459bbd 100644--- a/test/e2e-cli.test.js+++ b/test/e2e-cli.test.js@@ -345,8 +345,11 @@ test('output into a reader that stops early ends quietly [N24]', async () => {assert.equal(code, 0);});-test('every wait pullboard suggests names its unit and fits one ten-minute tool call [N25]', () => {+test('every wait pullboard suggests names its unit and fits one ten-minute tool call [N25]', async () => {const box = project();+ box.env.PULLBOARD_VIEW_FOREGROUND = '1';+ const view = await e2e.startView(box, box.repo);+ await view.stop();box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1');box.run(box.repo, 'add', 'web', 'Second', '--specs', 'G1', '--after', '1');box.run(box.web, 'claim', '1');diff --git a/test/e2e-runner.test.js b/test/e2e-runner.test.jsindex 2abb3368..1e77a98f 100644--- a/test/e2e-runner.test.js+++ b/test/e2e-runner.test.js@@ -229,8 +229,11 @@ test('pre-commit runs the fixers on fully staged files and restages them; partlyassert.equal(committedText('docs/e.js'), 'const e = 1; \n');});-test('resume puts an agent back to work from the board: its claim, its branch, what came back, the next step [N19]', () => {+test('resume puts an agent back to work from the board: its claim, its branch, what came back, the next step [N19]', async () => {const box = project();+ box.env.PULLBOARD_VIEW_FOREGROUND = '1';+ const view = await e2e.startView(box, box.repo);+ await view.stop();box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1', '--brief', 'Files: web/page.html');const fresh = box.run(box.web, 'resume');assert.equal(fresh.code, 0, fresh.err);diff --git a/test/e2e.test.js b/test/e2e.test.jsindex 8d24f350..0193e402 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -112,7 +112,7 @@ test("init's spec has its sections and no rows, and the README's example fits unassert.match(check.out, new RegExp(`SPEC.md: ${rows.length} rows, 0 errors`));});-test("the coordinator's resume names its next step from the spec and the board, stage by stage [N32, I9]", () => {+test("the coordinator's resume names its next step from the spec and the board, stage by stage [N32, I9]", async () => {const next = (box, cwd) => /^next: (.*)$/m.exec(box.run(cwd, 'resume').out)?.[1] ?? '';const fresh = sandbox();const repo = join(fresh.dir, 'fresh');@@ -120,17 +120,28 @@ test("the coordinator's resume names its next step from the spec and the board,fresh.git(repo, 'init', '-q', '-b', 'main');const initialized = fresh.run(repo, 'init');assert.match(initialized.out, /with an agent: start a new Claude Code session here, which loads the pullboard skills, then tell it what to build/, 'init tells an agent to start a new session [I9]');- assert.match(next(fresh, repo), /^turn what the person wants into spec rows with them: the pullboard-decompose skill/);+ const firstSetup = JSON.parse(fresh.run(repo, 'resume', '--json').out).setup;+ assert.equal(firstSetup?.step, 1, 'a new board starts by asking what the person wants');+ assert.equal(next(fresh, repo), firstSetup.command);assert.equal(fresh.run(repo, 'add', 'coordinator', 'Tidy the readme').code, 0);assert.equal(fresh.run(repo, 'claim', '1').code, 0);- assert.match(next(fresh, repo), /^turn what the person wants into spec rows with them/, "the coordinator's own claim does not jump the spec");+ assert.equal(JSON.parse(fresh.run(repo, 'resume', '--json').out).setup.step, 1, "the coordinator's own claim does not jump the spec");writeFileSync(join(repo, 'SPEC.md'), '# Fresh\n\n## G · Goals\n- G1 [draft, must] It works. | gate: test\n');- assert.match(next(fresh, repo), /^the person approves rows in SPEC.md; then plan them/, 'nor the approval');+ assert.equal(JSON.parse(fresh.run(repo, 'resume', '--json').out).setup.step, 1, 'nor the approval');writeFileSync(join(repo, 'SPEC.md'), '# Fresh\n\n## G · Goals\n- G1 [approved, must] It works. | gate: test\n');- assert.match(next(fresh, repo), /^build #1, commit, then pullboard submit 1/, 'then it comes first');+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(CONFIG));+ fresh.env.PULLBOARD_VIEW_FOREGROUND = '1';+ const freshView = await startView(fresh, repo);+ await freshView.stop();+ assert.match(next(fresh, repo), /^build #1, commit, then pullboard submit 1/, 'after setup the coordinator’s claim comes first');const box = project();- assert.match(next(box, box.repo), /^plan the approved rows no item cites \(G1, G2\): the pullboard-plan skill/);+ box.env.PULLBOARD_VIEW_FOREGROUND = '1';+ const view = await startView(box, box.repo);+ await view.stop();+ const firstItem = JSON.parse(box.run(box.repo, 'resume', '--json').out).setup;+ assert.equal(firstItem?.step, 4, 'setup asks for the first small piece before planning the remaining rows');+ assert.equal(next(box, box.repo), firstItem.command);box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1');assert.match(next(box, box.repo), /^start a builder for each lane with open items \(web\): pullboard worktree <lane>/);assert.equal(box.run(box.web, 'claim', '1').code, 0);diff --git a/test/resume-flow.test.js b/test/resume-flow.test.jsindex 818e98c9..71cf108b 100644--- a/test/resume-flow.test.js+++ b/test/resume-flow.test.js@@ -291,7 +291,7 @@ function recordSetupAnswer(box, command) {/** Open the real local view and wait for its ready line before stopping its owned child. */async function openSetupView(box) {const child = spawn(process.execPath, [join(box.root, 'cli/bin/pullboard.js'), 'view', '--no-open'],- { cwd: box.repo, env: box.env, stdio: ['ignore', 'pipe', 'pipe'] });+ { cwd: box.repo, env: { ...box.env, PULLBOARD_VIEW_FOREGROUND: '1' }, stdio: ['ignore', 'pipe', 'pipe'] });let output = '', errors = '';const closed = new Promise(resolve => child.once('close', (code, signal) => resolve({ code, signal })));try {@@ -308,6 +308,22 @@ async function openSetupView(box) {}}+/** Reject stale or foreign receipt data while preserving the view's exact successful receipt. */+function assertViewReceipt(box) {+ const receiptPath = join(box.repo, '.git/pullboard/view-bind.json');+ const receiptBytes = readFileSync(receiptPath);+ const receipt = JSON.parse(receiptBytes);+ assert.equal(receipt.type, 'pullboard.view.bound');+ for (const invalid of [{ ...receipt, boardId: 'another-board' },+ { ...receipt, setupStartedAt: '2000-01-01T00:00:00.000Z' },+ { ...receipt, boundAt: '2000-01-01T00:00:00.000Z' }]) {+ writeFileSync(receiptPath, JSON.stringify(invalid));+ assert.equal(JSON.parse(box.run(box.repo, 'resume', '--json').stdout).setup?.step, 5,+ 'a receipt for another board or before this setup cannot complete it');+ }+ writeFileSync(receiptPath, receiptBytes);+}+/** Drive the same actual commands a newcomer receives, with a private fixture person approval. */async function finishSetup(box, observe = () => {}) {/** Assert the next setup block in both the actual text and JSON CLI output. */@@ -325,9 +341,12 @@ async function finishSetup(box, observe = () => {}) {observe(number, setup);return setup;}- recordSetupAnswer(box, step(1).command);+ const requirements = step(1);+ assert.match(requirements.afterAnswer, /person approves G1,G2 in Pullboard View or runs pullboard spec approve G1,G2 in their own terminal/u);+ assert.match(requirements.afterAnswer, /coordinator runs pullboard spec apply/u);+ recordSetupAnswer(box, requirements.command);// The person decision is recorded through the real CLI in a synthetic, private person environment.- for (const args of [['spec', 'approve', 'G1'], ['spec', 'apply']]) {+ for (const args of [['spec', 'approve', 'G1,G2'], ['spec', 'apply']]) {const result = box.run(box.repo, ...args);assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);}@@ -337,8 +356,21 @@ async function finishSetup(box, observe = () => {}) {assert.match(gate.question, /Suggested: npm test/u);recordSetupAnswer(box, gate.command);recordSetupAnswer(box, step(4).command);- assert.equal(step(5).command, 'pullboard view');+ const view = step(5);+ assert.equal(view.command, 'pullboard view');+ assert.match(view.afterAnswer, /person’s own terminal, or start it in the background as the agent/u);+ box.git(box.repo, 'add', '-A');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: set up private fixture');+ const builder = box.run(box.repo, 'worktree', 'app', '--model', 'Fixture');+ assert.equal(builder.status, 0, builder.failure || builder.stderr);+ const stillWaiting = JSON.parse(box.run(box.repo, 'resume', '--json').stdout);+ assert.equal(stillWaiting.setup?.step, 5, 'registering a builder does not stand in for the view’s own bind receipt');+ const shouted = box.run(box.repo, 'shout', 'all', 'Opened Pullboard view for this board.');+ assert.equal(shouted.status, 0, shouted.failure || shouted.stderr);+ assert.equal(JSON.parse(box.run(box.repo, 'resume', '--json').stdout).setup?.step, 5,+ 'an ordinary same-text shout cannot impersonate a successful view bind');await openSetupView(box);+ assertViewReceipt(box);}test('resume walks a new board through setup one step at a time [N32,N19]', async t => {