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(cli): wait for setup approvals in resume [I1,I2]

Corey Olsone132f04db2a4
diff --git a/src/cli.js b/src/cli.js
index 86c88f4e..e692c965 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1123,22 +1123,49 @@ function recordViewReuse(ctx, board, view) {
renameSync(temporary, file);
}
+/** Read a typed setup receipt only for this board's current coordinator enrollment. */
+function setupReceiptMatches(ctx, identity, state) {
+ let receipt;
+ try { receipt = JSON.parse(readFileSync(join(ctx.info.commonDir, 'pullboard', `setup-${state}.json`), 'utf8')); }
+ catch (error) { if (error.code === 'ENOENT' || error instanceof SyntaxError) return false; throw error; }
+ return receipt?.type === `pullboard.setup.${state === 'complete' ? 'completed' : state}` && receipt.version === 1
+ && receipt.boardId === identity.boardId && receipt.setupStartedAt === identity.setupStartedAt;
+}
+
+/** Atomically record a setup transition, scoped to this board enrollment. */
+function recordSetupState(ctx, identity, state) {
+ const file = join(ctx.info.commonDir, 'pullboard', `setup-${state}.json`);
+ const temporary = file + '.' + randomUUID() + '.tmp';
+ mkdirSync(dirname(file), { recursive: true });
+ writeFileSync(temporary, JSON.stringify({ type: `pullboard.setup.${state === 'complete' ? 'completed' : state}`, version: 1, ...identity }) + '\n', { mode: 0o600 });
+ renameSync(temporary, file);
+}
+
/** Derive the next setup question from the real requirements, config, items and view receipt. */
-function boardSetup(ctx, card) {
+function boardSetup(ctx, card, identity) {
const rows = loadSpec(ctx.info.root, ctx.config).rows;
const approved = rows.filter(row => row.status === 'approved');
+ const drafted = rows.filter(row => row.status === 'draft' || row.status === 'pending');
+ const recordedComplete = setupReceiptMatches(ctx, identity, 'complete');
+ const started = setupReceiptMatches(ctx, identity, 'started');
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';
+ // Older installations had no setup marker. Preserve their completed five-step state on upgrade.
+ const legacyUnmarked = !existsSync(join(ctx.info.commonDir, 'pullboard', 'setup-started.json'))
+ && !existsSync(join(ctx.info.commonDir, 'pullboard', 'setup-complete.json'));
+ const legacyComplete = legacyUnmarked && approved.length > 0 && lanes.length > 0
+ && Boolean(ctx.config.gate?.trim()) && card.all.length > 0 && card.viewOpened;
+ const completed = recordedComplete || legacyComplete;
const detectedGate = detectGate(ctx.info.root);
/** 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, then ask the person to approve them.',
+ { number: 1, done: approved.length > 0 && (!drafted.length || completed), question: 'Ask the person: what are we building, and who will use it? Draft a few requirements, then ask the person to approve them.',
command: 'pullboard spec draft "<text>"',
afterAnswer: 'Record each answer with pullboard spec draft "<text>"; the person approves the returned ids in Pullboard View or runs pullboard spec approve <ids> 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)'}.`,
@@ -1155,6 +1182,19 @@ function boardSetup(ctx, card) {
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);
+ if (!current && !recordedComplete) recordSetupState(ctx, identity, 'complete');
+ else if (current && !completed && !started) recordSetupState(ctx, identity, 'started');
+ if (current?.number === 1 && drafted.length) {
+ const rowIds = drafted.map(row => row.id);
+ const names = rowIds.join(', ');
+ const command = `pullboard spec show ${rowIds[0]}`;
+ return { step: 1, total: 5, ...current, steps, waitingOn: 'person-approval', rowIds,
+ question: `Waiting for the person to approve ${names}.`, command,
+ personCommand: `pullboard spec approve ${rowIds.join(',')}`,
+ afterAnswer: 'The person approves these rows in Pullboard View or their own terminal; then the coordinator runs pullboard spec apply.',
+ meanwhile: 'While waiting, the agent may review independent approved work or prepare questions for the person.',
+ agentNext: `wait for the person to approve ${names}; meanwhile ${command}` };
+ }
return current ? { step: current.number, total: 5, ...current, steps } : null;
}
@@ -1168,7 +1208,9 @@ function boardSetup(ctx, card) {
function resumeHere(io) {
const ctx = context(io);
const { root, isMain } = ctx.info;
+ let setupScope;
const card = withBoard(ctx, (board) => {
+ setupScope = setupIdentity(board);
const me = whoAmI(ctx, board);
const all = store.listItems(board, { all: true });
const toMerge = all.filter((item) => item.item_status === 'verified' && !item.item_merged_commit);
@@ -1219,12 +1261,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);
+ card.setup = boardSetup(ctx, card, setupScope);
if (card.setup) {
say(`Setting up: step ${card.setup.step} of 5`);
say(card.setup.question);
- say(`Record the answer: ${card.setup.command}`);
+ say(card.setup.personCommand ? `For the person: ${card.setup.personCommand}` : `Record the answer: ${card.setup.command}`);
if (card.setup.afterAnswer) say(card.setup.afterAnswer);
+ if (card.setup.meanwhile) say(card.setup.meanwhile);
}
const dirty = dirtyFiles(root).length;
if (!isMain) {
@@ -1290,7 +1333,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;
+ if (card.setup) next = card.setup.agentNext ?? card.setup.command;
io.result?.({ ...card, root, dirty, next });
say(`next: ${next}`);
const flowAlert = isMain ? flowAlertLine(card.flow) : null;
@@ -1492,7 +1535,12 @@ function setupCommands(io, { first, values }) {
openBoardHere: () => store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), io.clock, { isMain: codeIsFromMain() }),
/** Keep a linked coordinator's canonical identity without writing a clone-local path. */
register: (board, options) => {
- if (!linked) return store.register(board, options);
+ if (!linked) {
+ const existing = board.db.prepare('SELECT 1 FROM agent WHERE agent_id=?').get(COORDINATOR);
+ const registered = store.register(board, options);
+ if (!existing) recordSetupState({ info }, setupIdentity(board), 'started');
+ return registered;
+ }
if (!board.db.prepare('SELECT 1 FROM agent WHERE agent_id=?').get(COORDINATOR)) {
throw new Refused('NO_AGENT', 'the linked snapshot has no coordinator; restore a consistent relay snapshot before initializing');
}
diff --git a/test/resume-flow.test.js b/test/resume-flow.test.js
index d7ca4bdc..efe9b9ad 100644
--- a/test/resume-flow.test.js
+++ b/test/resume-flow.test.js
@@ -308,7 +308,8 @@ test('spec draft adds draft rows and resume names them [N32]', t => {
const next = JSON.parse(box.run(box.repo, 'resume', '--json').stdout);
assert.equal(next.setup.step, 1);
- assert.match(next.setup.command, /^pullboard spec draft/u);
+ assert.match(next.setup.question, /waiting.*person.*approv/iu);
+ assert.deepEqual(next.setup.rowIds, ['G1', 'G2']);
const custom = releaseFixture(t, { freshSetup: true });
const customSpec = [
@@ -329,6 +330,58 @@ test('spec draft adds draft rows and resume names them [N32]', t => {
'draft preserves every existing status row and inserts in the first section');
});
+test("resume says setup waits on the person's approval [I1,I2]", async t => {
+ const box = releaseFixture(t, { freshSetup: true });
+ box.env.AI_AGENT = 'fixture-agent';
+ const drafted = [
+ box.run(box.repo, 'spec', 'draft', 'The person can choose a project name.', '--json'),
+ box.run(box.repo, 'spec', 'draft', 'The person can choose a project color.', '--json'),
+ ];
+ for (const result of drafted) assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ const ids = drafted.map(result => JSON.parse(result.stdout).id);
+ assert.deepEqual(ids, ['G1', 'G2']);
+
+ const waiting = box.run(box.repo, 'resume');
+ assert.equal(waiting.status, 0, waiting.failure || waiting.stderr || waiting.stdout);
+ assert.match(waiting.stdout, /waiting.*person.*approv/iu, 'setup waits for the person after the rows are drafted');
+ for (const id of ids) assert.match(waiting.stdout, new RegExp(`\\b${id}\\b`, 'u'));
+ assert.match(waiting.stdout, /agent[^\n]*may[^\n]*review[^\n]*independent approved work/iu,
+ 'resume names permissible independent work while approval is pending');
+ assert.doesNotMatch(waiting.stdout, /^next: .*spec (?:draft|approve)/mu,
+ 'the agent is not told to draft again or perform the person-only approval');
+ const waitingJson = box.run(box.repo, 'resume', '--json');
+ assert.equal(waitingJson.status, 0, waitingJson.failure || waitingJson.stderr || waitingJson.stdout);
+ const card = JSON.parse(waitingJson.stdout);
+ assert.equal(card.setup?.step, 1);
+ assert.equal(card.setup.waitingOn, 'person-approval');
+ assert.deepEqual(card.setup.rowIds, ids);
+ assert.match(card.next, /^wait for the person to approve G1, G2; meanwhile pullboard spec show G1$/u);
+
+ // Opening the real view to approve these rows cannot stand in for completing setup.
+ await openSetupView(box);
+
+ delete box.env.AI_AGENT;
+ const approval = box.run(box.repo, 'spec', 'approve', ids[0]);
+ assert.equal(approval.status, 0, approval.failure || approval.stderr || approval.stdout);
+ const applied = box.run(box.repo, 'spec', 'apply');
+ assert.equal(applied.status, 0, applied.failure || applied.stderr || applied.stdout);
+ const partial = box.run(box.repo, 'resume', '--json');
+ assert.equal(partial.status, 0, partial.failure || partial.stderr || partial.stdout);
+ const pending = JSON.parse(partial.stdout);
+ assert.equal(pending.setup?.step, 1, 'one approved row does not stand in for the remaining setup draft');
+ assert.deepEqual(pending.setup.rowIds, [ids[1]]);
+ assert.match(pending.setup.question, /Waiting for the person to approve G2/u);
+ const finalApproval = box.run(box.repo, 'spec', 'approve', ids[1]);
+ assert.equal(finalApproval.status, 0, finalApproval.failure || finalApproval.stderr || finalApproval.stdout);
+ const finalApply = box.run(box.repo, 'spec', 'apply');
+ assert.equal(finalApply.status, 0, finalApply.failure || finalApply.stderr || finalApply.stdout);
+ const resumed = box.run(box.repo, 'resume', '--json');
+ assert.equal(resumed.status, 0, resumed.failure || resumed.stderr || resumed.stdout);
+ const next = JSON.parse(resumed.stdout);
+ assert.equal(next.setup?.step, 2, 'person approval advances setup to its next unanswered step');
+ assert.equal(next.setup.waitingOn, undefined);
+});
+
test('coordinator resume finds the oldest unreserved item behind an older live review [N32,R1,R2]', async t => {
const box = fixture(t, { age: 190, otherAge: 181, reservation: 'live' });
alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 3 h 1 min (> 3 h 0 min); bottleneck: not measured yet');
@@ -530,4 +583,76 @@ test("a set-up board's resume prints no setup steps [N32,N19]", async t => {
assert.doesNotMatch(result.stdout, /Setting up: step/u);
const json = box.run(box.repo, 'resume', '--json');
assert.equal(JSON.parse(json.stdout).setup, null);
+ const proposed = box.run(box.repo, 'spec', 'draft', 'A later proposal for the person', '--json');
+ assert.equal(proposed.status, 0, proposed.failure || proposed.stderr || proposed.stdout);
+ const later = box.run(box.repo, 'resume', '--json');
+ assert.equal(later.status, 0, later.failure || later.stderr || later.stdout);
+ assert.equal(JSON.parse(later.stdout).setup, null, 'a later proposal does not reopen completed setup');
+});
+
+
+test('a new preconfigured board waits for every initial approval [I1,I2]', async t => {
+ const box = releaseFixture(t, { freshSetup: true });
+ const marker = join(box.repo, '.git/pullboard/setup-started.json');
+ const started = JSON.parse(readFileSync(marker, 'utf8'));
+ assert.equal(started.type, 'pullboard.setup.started');
+ assert.equal(started.version, 1);
+ assert.equal(statSync(marker).mode & 0o077, 0);
+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));
+ try {
+ assert.equal(started.boardId, store.boardId(board));
+ assert.equal(started.setupStartedAt, store.listAgents(board).find(agent => agent.agent_id === 'coordinator').agent_created_at);
+ } finally { store.closeBoard(board); }
+ const configPath = join(box.repo, 'pullboard.json');
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
+ writeFileSync(configPath, JSON.stringify({ ...config, gate: 'true', lanes: { app: { owns: ['app/'] } } }));
+ for (const text of ['The person chooses the name.', 'The person chooses the color.']) {
+ const draft = box.run(box.repo, 'spec', 'draft', text);
+ assert.equal(draft.status, 0, draft.failure || draft.stderr || draft.stdout);
+ }
+ for (const args of [['spec', 'approve', 'G1'], ['spec', 'apply'],
+ ['add', 'app', 'First setup item', '--specs', 'G1', '--criterion', 'The fixture has work.']]) {
+ const result = box.run(box.repo, ...args);
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ }
+ await openSetupView(box);
+ const result = box.run(box.repo, 'resume', '--json');
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ const setup = JSON.parse(result.stdout).setup;
+ assert.equal(setup?.step, 1, 'an early view and preconfigured answers cannot bypass the remaining initial approval');
+ assert.deepEqual(setup.rowIds, ['G2']);
+ const startedBytes = readFileSync(marker);
+ for (const invalid of ['{', JSON.stringify({ ...started, boardId: 'another-board' }),
+ JSON.stringify({ ...started, setupStartedAt: '2000-01-01T00:00:00.000Z' })]) {
+ writeFileSync(marker, invalid);
+ const resumed = box.run(box.repo, 'resume', '--json');
+ assert.equal(resumed.status, 0, resumed.failure || resumed.stderr || resumed.stdout);
+ assert.deepEqual(JSON.parse(resumed.stdout).setup?.rowIds, ['G2'],
+ 'an invalid progress receipt is not evidence of a completed legacy setup');
+ }
+ writeFileSync(marker, startedBytes);
+});
+
+test('an upgraded configured board stays set up before its first resume [I1,I2]', async t => {
+ const box = releaseFixture(t, { freshSetup: true });
+ await finishSetup(box);
+ // Legacy installations have these actual completed setup facts, but neither new lifecycle receipt.
+ const stateDirectory = join(box.repo, '.git/pullboard');
+ for (const name of ['setup-started.json', 'setup-complete.json']) rmSync(join(stateDirectory, name), { force: true });
+ const reinitialized = box.run(box.repo, 'init');
+ assert.equal(reinitialized.status, 0, reinitialized.failure || reinitialized.stderr || reinitialized.stdout);
+ assert.throws(() => readFileSync(join(stateDirectory, 'setup-started.json')), { code: 'ENOENT' },
+ 'idempotent init does not classify an existing coordinator as a new enrollment');
+ const proposed = box.run(box.repo, 'spec', 'draft', 'A proposal drafted before the first upgraded resume', '--json');
+ assert.equal(proposed.status, 0, proposed.failure || proposed.stderr || proposed.stdout);
+ const result = box.run(box.repo, 'resume', '--json');
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ assert.equal(JSON.parse(result.stdout).setup, null, 'a later draft does not reopen a legacy completed setup');
+ const complete = JSON.parse(readFileSync(join(stateDirectory, 'setup-complete.json'), 'utf8'));
+ const view = JSON.parse(readFileSync(join(stateDirectory, 'view-bind.json'), 'utf8'));
+ assert.equal(complete.type, 'pullboard.setup.completed');
+ assert.equal(complete.version, 1);
+ assert.equal(complete.boardId, view.boardId);
+ assert.equal(complete.setupStartedAt, view.setupStartedAt);
+ assert.equal(statSync(join(stateDirectory, 'setup-complete.json')).mode & 0o077, 0);
});