Skip to content

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.

fix(core): finish setup after authenticated view reuse [N26,N32]

Corey Olson7bd433e121d0
diff --git a/src/cli.js b/src/cli.js
index 2dd46e4f..3b6f7737 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1062,16 +1062,18 @@ function setupIdentity(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. */
+/** Read the view's typed fresh-bind or authenticated-reuse 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
+ const observedAt = receipt?.type === 'pullboard.view.bound' ? receipt.boundAt
+ : receipt?.type === 'pullboard.view.reused' ? receipt.openedAt : null;
+ return 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);
+ && Number.isFinite(Date.parse(observedAt))
+ && Date.parse(observedAt) >= Date.parse(identity.setupStartedAt);
}
/** Atomically record a successful real view bind, scoped to this board's current setup. */
@@ -1084,6 +1086,17 @@ function recordViewBind(ctx, board, boundAt) {
renameSync(temporary, file);
}
+/** Record this board's authenticated reuse without claiming that its existing listener bound again. */
+function recordViewReuse(ctx, board, view) {
+ const file = join(ctx.info.commonDir, 'pullboard', 'view-bind.json');
+ const temporary = file + '.' + randomUUID() + '.tmp';
+ const receipt = { type: 'pullboard.view.reused', version: 1, ...setupIdentity(board),
+ openedAt: new Date().toISOString(), boundAt: view.boundAt, port: view.port, pid: view.pid };
+ 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;
@@ -1110,7 +1123,7 @@ function boardSetup(ctx, card) {
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,
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.' },
+ 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 or authenticated reuse for this board.' },
];
const current = steps.find(step => !step.done);
return current ? { step: current.number, total: 5, ...current, steps } : null;
@@ -1274,8 +1287,9 @@ async function viewHere(io, values) {
}
const port = values.port === undefined ? 4890 : 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');
+ let info;
try {
- const info = repoInfo(io.cwd);
+ info = repoInfo(io.cwd);
if (info.isMain && existsSync(join(info.root, CONFIG_FILE))) await registerProjectAndLink(info.root, new Date(), loadConfig(info.root), io);
} catch (error) {
if (!(error instanceof Refused)) throw error;
@@ -1285,6 +1299,10 @@ async function viewHere(io, values) {
if (!internalForeground) {
const existing = port ? await runningView(port) : null;
if (existing) {
+ if (info && existsSync(join(info.root, CONFIG_FILE))) {
+ const ctx = context(io);
+ withBoard(ctx, board => recordViewReuse(ctx, board, existing));
+ }
reportView(io, { ...existing, reused: true });
return 0;
}
diff --git a/test/resume-flow.test.js b/test/resume-flow.test.js
index cb3e9833..900c6154 100644
--- a/test/resume-flow.test.js
+++ b/test/resume-flow.test.js
@@ -1,6 +1,6 @@
/** Coordinator flow alerts reuse the real Git/SQLite statistics and documented thresholds [N32,R1,R2]. */
import assert from 'node:assert/strict';
-import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
+import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
@@ -10,6 +10,7 @@ import { spawn } from 'node:child_process';
import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
import { proofStats } from '../src/stats.js';
import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { takeDefaultViewPort } from './view-port-fixture.js';
const PRIVATE_CHANGELOG = `# Changelog\n\n## [0.8.7] - 2026-10-12\n\n### A new session\n\nThe latest headline paragraph.\n\n### Added\n\n- The detailed release list is not part of the resume.\n\n## [0.8.6] - 2026-10-11\n\n### See the flow\n\nThe middle headline paragraph.\n\n### Fixed\n\n- A detailed fix.\n\n## [0.8.5] - 2026-10-10\n\n### A prettier board\n\nThe previous release.\n`;
const LONG_CHANGELOG = `# Changelog\n\n## [0.8.9] - 2026-10-14\n\n### Nine\n\nNine paragraph.\n\n## [0.8.8] - 2026-10-13\n\n### Eight\n\nEight paragraph.\n\n## [0.8.7] - 2026-10-12\n\n### Seven\n\nSeven paragraph.\n\n## [0.8.6] - 2026-10-11\n\n### Six\n\nSix paragraph.\n\n## [0.8.5] - 2026-10-10\n\n### Five\n\nFive paragraph.\n\n## [0.8.4] - 2026-10-09\n\n### Added\n\nThis category heading is not a release headline.\n`;
@@ -324,6 +325,80 @@ function assertViewReceipt(box) {
writeFileSync(receiptPath, receiptBytes);
}
+test('a reused authenticated view completes setup for its new board [N26,N32]', async t => {
+ const firstBoard = releaseFixture(t);
+ const secondBoard = releaseFixture(t);
+ const refusedBoard = releaseFixture(t);
+ const lease = await takeDefaultViewPort(firstBoard.root);
+ t.after(() => lease.release());
+ for (const box of [firstBoard, secondBoard, refusedBoard]) {
+ box.env.PULLBOARD_HOME = firstBoard.env.PULLBOARD_HOME;
+ box.env.PULLBOARD_MACHINE_HOME = firstBoard.env.PULLBOARD_MACHINE_HOME;
+ delete box.env.PULLBOARD_VIEW_FOREGROUND;
+ const file = join(box.repo, 'pullboard.json');
+ const config = JSON.parse(readFileSync(file, 'utf8'));
+ config.gate = 'true';
+ config.lanes = { app: { owns: ['app/'] } };
+ writeFileSync(file, JSON.stringify(config));
+ const added = box.run(box.repo, 'add', 'app', 'First setup item', '--specs', 'N19', '--criterion', 'The fixture has work.');
+ assert.equal(added.status, 0, added.failure || added.stderr || added.stdout);
+ assert.equal(JSON.parse(box.run(box.repo, 'resume', '--json').stdout).setup?.step, 5);
+ }
+ const child = spawn(process.execPath, [join(firstBoard.root, 'cli/bin/pullboard.js'), 'view', '--no-open', '--json'],
+ { cwd: firstBoard.repo, env: { ...firstBoard.env, PULLBOARD_VIEW_FOREGROUND: '1' }, stdio: ['ignore', 'pipe', 'pipe'] });
+ const closed = new Promise(resolve => child.once('close', resolve));
+ t.after(async () => {
+ if (child.exitCode === null && child.signalCode === null) child.kill('SIGTERM');
+ await closed;
+ });
+ const first = await new Promise((resolve, reject) => {
+ let output = '', errors = '';
+ child.once('error', reject);
+ child.once('close', code => reject(new Error(`owned view exited ${code}: ${errors}`)));
+ child.stderr.on('data', bytes => { errors += bytes; });
+ child.stdout.on('data', bytes => {
+ output += bytes;
+ try { resolve(JSON.parse(output)); } catch { /* Wait for the complete ready document. */ }
+ });
+ });
+ assert.equal(first.port, 4890);
+ assert.equal(JSON.parse(firstBoard.run(firstBoard.repo, 'resume', '--json').stdout).setup, null);
+ const reused = secondBoard.run(secondBoard.repo, 'view', '--no-open', '--json');
+ assert.equal(reused.status, 0, reused.failure || reused.stderr || reused.stdout);
+ const second = JSON.parse(reused.stdout);
+ assert.equal(second.reused, true);
+ assert.equal(second.url, first.url);
+ assert.equal(JSON.parse(secondBoard.run(secondBoard.repo, 'resume', '--json').stdout).setup, null,
+ 'the exact offered view command completes setup on the second board');
+ const receiptPath = join(secondBoard.repo, '.git/pullboard/view-bind.json');
+ const bytes = readFileSync(receiptPath);
+ const receipt = JSON.parse(bytes);
+ assert.equal(receipt.type, 'pullboard.view.reused');
+ assert.equal(receipt.boundAt, first.boundAt, 'reuse retains the original bind time');
+ assert.equal(receipt.pid, first.pid);
+ assert.equal(receipt.port, first.port);
+ assert.equal(statSync(receiptPath).mode & 0o077, 0);
+ assert.equal(Object.hasOwn(receipt, 'url'), false, 'the setup receipt never copies the session secret');
+ for (const invalid of [{ ...receipt, boardId: 'another-board' },
+ { ...receipt, setupStartedAt: '2000-01-01T00:00:00.000Z' },
+ { ...receipt, openedAt: '2000-01-01T00:00:00.000Z' }]) {
+ writeFileSync(receiptPath, JSON.stringify(invalid));
+ assert.equal(JSON.parse(secondBoard.run(secondBoard.repo, 'resume', '--json').stdout).setup?.step, 5,
+ 'another board or an observation before this setup cannot complete it');
+ }
+ writeFileSync(receiptPath, bytes);
+ const sessionPath = join(firstBoard.env.PULLBOARD_HOME, 'view-4890.json');
+ const sessionBytes = readFileSync(sessionPath);
+ try {
+ writeFileSync(sessionPath, JSON.stringify({ ...JSON.parse(sessionBytes), secret: 'not-the-listener-secret' }));
+ const refused = refusedBoard.run(refusedBoard.repo, 'view', '--no-open', '--json');
+ assert.equal(refused.status, 1, refused.failure || refused.stderr || refused.stdout);
+ assert.equal(JSON.parse(refused.stdout).error.code, 'PORT_BUSY');
+ assert.equal(JSON.parse(refusedBoard.run(refusedBoard.repo, 'resume', '--json').stdout).setup?.step, 5,
+ 'an unauthenticated listener cannot complete setup');
+ } finally { writeFileSync(sessionPath, sessionBytes); }
+});
+
/** 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. */