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.

feat(resume): walk new boards through setup [N32,N19]

Corey Olson780e13cf8047
diff --git a/src/cli.js b/src/cli.js
index cd291221..e51bcc7c 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, readFileSync, writeFileSync } from 'node:fs';
+import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, 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';
@@ -30,7 +30,7 @@ import {
pushesTrunk,
unwiredHookProblems,
} from './hooks.js';
-import { initRepo } from './init.js';
+import { detectGate, initRepo } from './init.js';
import { lifecycleMarkdown } from './machine.js';
import { HELP, VERSION } from './help.js';
export { HELP, VERSION };
@@ -1042,6 +1042,36 @@ function resumeReleaseNotes(info) {
return releases.length ? { releases: releases.slice(0, 3), omitted: Math.max(0, releases.length - 3), notes: 'CHANGELOG.md' } : null;
}
+/** 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;
+ const approved = rows.filter(row => row.status === 'approved');
+ const lanes = laneNames(ctx.config).filter(lane => !['review', COORDINATOR].includes(lane));
+ const folders = readdirSync(ctx.info.root, { withFileTypes: true })
+ .filter(entry => entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules')
+ .map(entry => entry.name).sort();
+ const lane = lanes[0] ?? folders[0] ?? 'app';
+ /** Quote the exact suggested command safely for a shell. */
+ 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 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.' },
+ { 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' },
+ ];
+ const current = steps.find(step => !step.done);
+ return current ? { step: current.number, total: 5, ...current, steps } : null;
+}
+
/**
* `pullboard resume` (N19): one short card that puts an agent back to work after a fresh start,
* a restart or a compaction, from the board rather than from a summary.
@@ -1078,6 +1108,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.'),
};
});
card.relayProblems = unlinkedRelayProjects();
@@ -1102,6 +1133,13 @@ function resumeHere(io) {
for (const problem of card.hookProblems) say(`${problem.message}; ${problem.next}`);
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
say(`resume: ${me.displayName}${me.family ? ` [family ${me.family}]` : ''}, ${me.lane} lane${isMain ? ', the main checkout' : ''}, at ${root}`);
+ card.setup = boardSetup(ctx, card);
+ if (card.setup) {
+ say(`Setting up: step ${card.setup.step} of 5`);
+ say(card.setup.question);
+ say(`Record the answer: ${card.setup.command}`);
+ if (card.setup.afterAnswer) say(card.setup.afterAnswer);
+ }
const dirty = dirtyFiles(root).length;
if (!isMain) {
const branch = tryGit(root, ['rev-parse', '--abbrev-ref', 'HEAD']).stdout || 'HEAD';
@@ -1166,6 +1204,7 @@ function resumeHere(io) {
else if (inLane.length) next = `pullboard next --wait 9 (minutes); ${inLane.length} in your lane ${inLane.length === 1 ? 'waits' : 'wait'} on other work`;
else if (card.awaiting.length) next = 'pullboard next --wait 9 (minutes); a rejected item comes back to your lane';
else next = 'nothing open in your lane; pullboard next --verify names work you can check';
+ if (card.setup) next = card.setup.command;
io.result?.({ ...card, root, dirty, next });
say(`next: ${next}`);
const flowAlert = isMain ? flowAlertLine(card.flow) : null;
@@ -1198,6 +1237,19 @@ 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.
+ 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) }]);
+ }
+ });
+ } catch (error) {
+ await view.close();
+ throw error;
+ }
io.result?.({ url: view.url, port: view.port });
io.say(`Pullboard view: ${view.url}`);
io.say('Only this machine can reach it, and only with that link. Ctrl-C stops it.');
diff --git a/test/resume-flow.test.js b/test/resume-flow.test.js
index 34dd42a1..818e98c9 100644
--- a/test/resume-flow.test.js
+++ b/test/resume-flow.test.js
@@ -6,6 +6,8 @@ import { join } from 'node:path';
import { test } from 'node:test';
import * as store from '../src/board.js';
import { main } from '../src/cli.js';
+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';
@@ -13,14 +15,14 @@ const PRIVATE_CHANGELOG = `# Changelog\n\n## [0.8.7] - 2026-10-12\n\n### A new s
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`;
/** Build an isolated copy of the production CLI at a chosen release version. */
-function releaseFixture(t, { previous = null, version = '0.8.7', changelog = PRIVATE_CHANGELOG } = {}) {
+function releaseFixture(t, { previous = null, version = '0.8.7', changelog = PRIVATE_CHANGELOG, freshSetup = false } = {}) {
const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-resume-release-')));
t.after(() => rmSync(root, { recursive: true, force: true }));
const cli = join(root, 'cli');
const repo = join(root, 'repo');
mkdirSync(cli);
mkdirSync(repo);
- writeFileSync(join(repo, 'SPEC.md'), '# Release fixture\n\n## N · Resume\n- N19 [approved, must] Resume announces released headlines once per checkout. | gate: review\n');
+ if (!freshSetup) writeFileSync(join(repo, 'SPEC.md'), '# Release fixture\n\n## N · Resume\n- N19 [approved, must] Resume announces released headlines once per checkout. | gate: review\n');
cpSync(join(import.meta.dirname, '../src'), join(cli, 'src'), { recursive: true });
cpSync(join(import.meta.dirname, '../bin'), join(cli, 'bin'), { recursive: true });
cpSync(join(import.meta.dirname, '../skills'), join(cli, 'skills'), { recursive: true });
@@ -32,6 +34,7 @@ function releaseFixture(t, { previous = null, version = '0.8.7', changelog = PRI
GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'Fixture',
GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'Fixture', GIT_COMMITTER_EMAIL: '[email protected]' };
delete env.PULLBOARD_RELAY_TOKEN;
+ for (const name of [...AGENT_SHELL_MARKERS, ...SSH_SHELL_MARKERS]) delete env[name];
runFixtureGit(['init', '-q', '-b', 'main'], { cwd: repo, env });
/** Run the copied production CLI in the selected real checkout. */
const run = (cwd, ...args) => runFixtureChild(process.execPath, [join(cli, 'bin/pullboard.js'), ...args], { cwd, env, encoding: 'utf8' });
@@ -278,3 +281,86 @@ test('coordinator resume finds the oldest unreserved item behind an older live r
alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 3 h 1 min (> 3 h 0 min); bottleneck: not measured yet');
assert.deepEqual(box.stats().flow.unreviewed, { size: 1, oldest: { id: 2, since: '2026-10-10T05:19:00.000Z', ageMinutes: 181 } });
});
+
+/** Execute the exact record-answer command offered by resume inside its private repository. */
+function recordSetupAnswer(box, command) {
+ const result = runFixtureChild('sh', ['-c', command], { cwd: box.repo, env: box.env, encoding: 'utf8' });
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+}
+
+/** 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'] });
+ let output = '', errors = '';
+ const closed = new Promise(resolve => child.once('close', (code, signal) => resolve({ code, signal })));
+ try {
+ await new Promise((resolve, reject) => {
+ child.once('error', reject);
+ child.once('close', () => reject(new Error(errors || output || 'view closed before ready')));
+ child.stderr.on('data', bytes => { errors += bytes; });
+ child.stdout.on('data', bytes => { output += bytes; if (output.includes('Pullboard view: http://')) resolve(); });
+ });
+ assert.match(output, /Pullboard view: http:\/\/127\.0\.0\.1:/u);
+ } finally {
+ child.kill('SIGTERM');
+ await closed;
+ }
+}
+
+/** 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. */
+ function step(number) {
+ const text = box.run(box.repo, 'resume');
+ assert.equal(text.status, 0, text.failure || text.stderr);
+ assert.match(text.stdout, new RegExp(`Setting up: step ${number} of 5`));
+ const json = box.run(box.repo, 'resume', '--json');
+ assert.equal(json.status, 0, json.failure || json.stderr);
+ const setup = JSON.parse(json.stdout).setup;
+ assert.equal(setup.step, number);
+ assert.equal(setup.total, 5);
+ assert.ok(setup.question.startsWith('Ask the person:'));
+ assert.ok(text.stdout.includes(setup.command));
+ observe(number, setup);
+ return setup;
+ }
+ recordSetupAnswer(box, step(1).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']]) {
+ const result = box.run(box.repo, ...args);
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ }
+ recordSetupAnswer(box, step(2).command);
+ writeFileSync(join(box.repo, 'package.json'), JSON.stringify({ scripts: { test: 'node -e ""' } }));
+ const gate = step(3);
+ assert.match(gate.question, /Suggested: npm test/u);
+ recordSetupAnswer(box, gate.command);
+ recordSetupAnswer(box, step(4).command);
+ assert.equal(step(5).command, 'pullboard view');
+ await openSetupView(box);
+}
+
+test('resume walks a new board through setup one step at a time [N32,N19]', async t => {
+ const box = releaseFixture(t, { freshSetup: true });
+ mkdirSync(join(box.repo, 'app'));
+ const seen = [];
+ await finishSetup(box, (number, setup) => {
+ seen.push(number);
+ if (number === 2) assert.match(setup.question, /Suggested folders: app/u);
+ });
+ assert.deepEqual(seen, [1, 2, 3, 4, 5]);
+ const result = box.run(box.repo, 'resume', '--json');
+ assert.equal(result.status, 0, result.failure || result.stderr);
+ assert.equal(JSON.parse(result.stdout).setup, null, 'actual successful view bind completes the board setup');
+});
+
+test("a set-up board's resume prints no setup steps [N32,N19]", async t => {
+ const box = releaseFixture(t, { freshSetup: true });
+ await finishSetup(box);
+ const result = box.run(box.repo, 'resume');
+ assert.equal(result.status, 0, result.failure || result.stderr);
+ assert.doesNotMatch(result.stdout, /Setting up: step/u);
+ const json = box.run(box.repo, 'resume', '--json');
+ assert.equal(JSON.parse(json.stdout).setup, null);
+});