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
feat(init): confirm setup files with one action [I1,I2]
Corey Olsonfd5176914e6a
diff --git a/src/cli.js b/src/cli.jsindex 6ba39bf2..0d3ac784 100644--- a/src/cli.js+++ b/src/cli.js@@ -141,6 +141,12 @@ import {starterLane,starterLaneNotes,} from './init.js';+import {+ beginInitCommit,+ finishInitCommit,+ reportInitSetup,+ SETUP_COMMIT_LATER,+} from './init-finish.js';import { lifecycleMarkdown } from './machine.js';import {buildHelp,@@ -219,8 +225,6 @@ import {import {blueprintStarterNote,combinedSummary,- initBlueprintLines,- initBlueprintResult,installedBlueprints,landEach,readBlueprints,@@ -251,10 +255,7 @@ import {startCheckBaseline,} from './check-baseline-worker.js';import {- alreadyAddedLine,- initWaitingRows,startersCommand,- waitingRowLines,} from './blueprint-report.js';import {compareMainFailures,@@ -2019,8 +2020,10 @@ function setupCommands(io, { first, second, rest = [], values }) {const linked = relayLinked(info.root);const ctx = linked && model !== undefined ? context(io) : null;if (model !== undefined && linked) refuseRemoteCoordinatorModel(ctx, 'init');+ const setupPlan = beginInitCommit(info);const notes = initRepo({info,+ onWritten: setupPlan.written,model,permissions: !values['no-permissions'],openBoardHere: () => store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), io.clock, { isMain: codeIsFromMain() }),@@ -2044,20 +2047,9 @@ function setupCommands(io, { first, second, rest = [], values }) {]));// Keep blueprint initialization and the person's unwritten lane proposals in the same result.const landed = await landEach(blueprints, ({ reference, blueprint }, drafted) => addBlueprintHere(io, reference, { report: false, blueprint, drafted }));- // Every row that waits for the person once, the blueprints' new rows and the doctrine's pending rows alike (#734).- const fresh = landed.filter((added) => !added.marked);- const waiting = landed.length ? initWaitingRows(info.root, { rows: fresh.flatMap((added) => added.rows) }) : [];- const blueprintResult = (added) => ({ ...initBlueprintResult(added), marked: added.marked, waitingRows: waiting });- const result = { root: info.root, notes, proposedLanes: proposeLanes(info.root),- ...(landed.length ? { blueprint: blueprintResult(landed[0]), blueprints: landed.map(blueprintResult) } : {}) };- io.result?.(result);- const staging = notes.at(-1)?.startsWith('git add -f -- ') ? notes.at(-1) : null;- (staging ? notes.slice(0, -1) : notes).forEach((note) => io.say(note));- for (const added of landed) {- if (added.marked) io.say(alreadyAddedLine(added.blueprint));- else initBlueprintLines(added, askedLaneNotes(added.items, loadConfig(info.root))).forEach((line) => io.say(line));- }- if (fresh.length) waitingRowLines(waiting).forEach((line) => io.say(line));+ const setupCommit = await finishInitCommit(setupPlan, { io, yes: values.yes, landed, permissions: !values['no-permissions'] });+ const { result } = reportInitSetup(io, info, notes, landed);+ result.setupCommit = setupCommit;if (await registerProjectAndLink(info.root, new Date(), loadConfig(info.root), io)) io.say('registered this project on this machine, so pullboard view lists it');// Once registered, a background view lists this board for pullboard.dev [H5,N26].const view = await keepViewRunning();@@ -2067,9 +2059,11 @@ function setupCommands(io, { first, second, rest = [], values }) {io.say(agentSessionDigest()? 'Next: run pullboard resume now to continue setup in this session; the new skills load next session, and setup does not need them.': 'Next: ask your agent to set up Pullboard here; in Claude Code, start a new session first so it loads the Pullboard skills.');- // The offer comes before the staging line, which stays init's last line [I1,I2].+ // Sharing remains a separate choice; --yes confirms only the setup commit.const code = await offerRelayAtInit(info.root, io);- if (staging) io.say(`To commit Pullboard's files: ${staging}`);+ if (setupCommit.skipped.length) io.say(`Your earlier changes remain uncommitted: ${setupCommit.skipped.join(', ')}.`);+ if (setupCommit.state === 'pending') io.say(SETUP_COMMIT_LATER);+ if (setupCommit.state === 'committed') io.say(`Committed ${setupCommit.skipped.length ? 'only unchanged Pullboard files' : 'Pullboard setup'} at ${setupCommit.commit.slice(0, 12)}.`);return code;},lane: () => {diff --git a/src/help.js b/src/help.jsindex 7b8ac7e4..e4af33d2 100644--- a/src/help.js+++ b/src/help.js@@ -10,7 +10,7 @@ Nothing ships until a second agent verifies it.Set uppullboard tour see it work: a reject and its rework, scripted, in thirty seconds- pullboard init [--model <name>] [--blueprint <name or file>]... [--no-permissions] config, SPEC.md, agent instructions, git hooks, board and project agent rules; optional coordinator model+ pullboard init [--model <name>] [--blueprint <name or file>]... [--no-permissions] [--yes] setup and project rules; --yes commits only setup's own files with your Git identitypullboard worktree <lane> --model <name> [--route light] [--family <name>] make and join a worktree for a new agentpullboard.json worktrees: inside or beside; init defaults to insidepullboard join <lane> --model <name> [--route light] [--family <name>] register this worktree as an agentdiff --git a/src/init-finish.js b/src/init-finish.jsnew file mode 100644index 00000000..73efafc5--- /dev/null+++ b/src/init-finish.js@@ -0,0 +1,166 @@+/** Complete setup with only its own writes, keeping the user's index and identity [I1,I2]. */+import {+ createHash,+ randomUUID,+} from 'node:crypto';+import { spawnSync } from 'node:child_process';+import {+ lstatSync,+ mkdirSync,+ readFileSync,+ realpathSync,+ renameSync,+ writeFileSync,+} from 'node:fs';+import {+ dirname,+ isAbsolute,+ join,+ relative,+ resolve,+ sep,+} from 'node:path';+import { createInterface } from 'node:readline';+import {+ git,+ tryGit,+} from './git.js';+import { loadConfig } from './config.js';+import {+ alreadyAddedLine,+ initWaitingRows,+ waitingRowLines,+} from './blueprint-report.js';+import {+ initBlueprintLines,+ initBlueprintResult,+} from './blueprint-set.js';+import {+ askedLaneNotes,+ proposeLanes,+ refreshInitPermissions,+ relayOfferAtInit,+} from './init.js';+import { Refused } from './refused.js';++export const SETUP_COMMIT_QUESTION = 'Commit Pullboard setup now? [Y/n] ';+export const SETUP_COMMIT_LATER = "To commit Pullboard's files: pullboard init --yes";++/** Hash regular files only, refusing paths outside the repository and symlink targets. */+function setupFile(root, name) {+ if (typeof name !== 'string' || isAbsolute(name) || name.includes('\0')) return null;+ const path = resolve(root, name), inside = relative(root, path);+ if (!inside || inside === '..' || inside.startsWith('..' + sep)) return null;+ try {+ if (!lstatSync(path).isFile()) return null;+ const physical = relative(root, realpathSync(path));+ if (physical === '..' || physical.startsWith('..' + sep)) return null;+ return createHash('sha256').update(readFileSync(path)).digest('hex');+ } catch (error) { if (error.code === 'ENOENT') return null; throw error; }+}++/** Capture existing edits before init writes, and retain only unchanged previous setup receipts. */+export function beginInitCommit(info) {+ const status = spawnSync('git', ['--no-replace-objects', 'status', '--porcelain=v1', '-z', '--untracked-files=all', '--ignored=matching'],+ { cwd: info.root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });+ if (status.status !== 0) throw new Refused('NOT_COMMITTED', 'Git could not read the existing changes; fix Git before running pullboard init again');+ const entries = status.stdout.split('\0'), blocked = new Set();+ for (let index = 0; index < entries.length; index++) {+ const entry = entries[index];+ if (!entry) continue;+ blocked.add(entry.slice(3));+ if (/[RC]/u.test(entry.slice(0, 2))) blocked.add(entries[++index]);+ }+ const file = join(info.commonDir, 'pullboard', 'setup-written-files.json');+ let previous = {};+ try {+ const saved = JSON.parse(readFileSync(file, 'utf8'));+ if (saved.version === 1 && saved.root === info.root && saved.files && typeof saved.files === 'object') previous = saved.files;+ } catch (error) { if (error.code !== 'ENOENT' && !(error instanceof SyntaxError)) throw error; }+ const files = new Map(), skipped = new Set();+ for (const [name, hash] of Object.entries(previous)) {+ const actual = setupFile(info.root, name);+ if (hash && actual === hash) files.set(name, hash);+ else if (actual) skipped.add(name);+ }+ const owned = new Set(files.keys());+ /** Retain the exact bytes init wrote, without adopting a file that already held user edits. */+ function written(name) {+ if (typeof name !== 'string') return;+ if (!owned.has(name) && [...blocked].some(path => path === name || (path?.endsWith('/') && name.startsWith(path)))) { skipped.add(name); return; }+ const hash = setupFile(info.root, name);+ if (hash) { owned.add(name); files.set(name, hash); }+ }+ return { info, file, files, written, skipped };+}++/** Ask once; closing stdin is a decline, while Enter accepts the displayed file list. */+function askCommit(io) {+ return new Promise(resolveAnswer => {+ const reader = createInterface({ input: io.stdin, output: io.stdout, terminal: false });+ let answer = null;+ reader.once('line', line => { answer = line; reader.close(); });+ reader.once('close', () => { io.stdin.pause?.(); resolveAnswer(answer); });+ io.stdout.write(SETUP_COMMIT_QUESTION);+ });+}++/** Confirm and commit exact setup paths through ordinary hooks, never unrelated staged files. */+export async function finishInitCommit(plan, { io, yes, landed, permissions }) {+ const { info, files } = plan;+ if (landed.some(added => !added.marked)) {+ const config = loadConfig(info.root);+ for (const name of ['pullboard.json', config.spec, config.practice]) plan.written(name);+ if (permissions) refreshInitPermissions(info.root, plan.written);+ }+ const retained = [...files].filter(([name, hash]) => setupFile(info.root, name) === hash);+ mkdirSync(dirname(plan.file), { recursive: true });+ const temporary = plan.file + '.' + randomUUID();+ writeFileSync(temporary, JSON.stringify({ version: 1, root: info.root, files: Object.fromEntries(retained) }) + '\n', { mode: 0o600 });+ renameSync(temporary, plan.file);+ const head = tryGit(info.root, ['rev-parse', '--verify', 'HEAD']);+ const changed = retained.filter(([name]) => head.status !== 0+ || tryGit(info.root, ['diff', '--quiet', 'HEAD', '--', `:(literal)${name}`]).status !== 0+ || !tryGit(info.root, ['ls-tree', 'HEAD', '--', `:(literal)${name}`]).stdout);+ if (!changed.length) return { state: 'unchanged', files: [], skipped: [...plan.skipped] };+ const paths = changed.map(([name]) => name);+ let accepted = Boolean(yes);+ if (!accepted && !io.json && relayOfferAtInit({ enabled: true, shared: false, stdin: io.stdin, stdout: io.stdout }) === 'ask') {+ io.say('Pullboard setup files: ' + paths.join(', '));+ const answer = await askCommit(io);+ accepted = answer !== null && ['', 'y', 'yes'].includes(answer.trim().toLowerCase());+ }+ if (!accepted) return { state: 'pending', files: paths, skipped: [...plan.skipped] };+ if (changed.some(([name, hash]) => setupFile(info.root, name) !== hash)) {+ throw new Refused('NOT_COMMITTED', 'a setup file changed while confirmation was open; review the change and run pullboard init --yes again');+ }+ try {+ git(info.root, ['add', '-f', '--', ...paths.map(name => `:(literal)${name}`)]);+ git(info.root, ['commit', '--only', '-q', '-m', 'chore: set up Pullboard', '--', ...paths.map(name => `:(literal)${name}`)]);+ } catch (error) {+ // Every selected path was clean or absent before init; restore only those index entries.+ if (head.status === 0) tryGit(info.root, ['reset', '-q', head.stdout, '--', ...paths.map(name => `:(literal)${name}`)]);+ else tryGit(info.root, ['rm', '--cached', '-q', '--ignore-unmatch', '--', ...paths.map(name => `:(literal)${name}`)]);+ throw new Refused('NOT_COMMITTED', `Git did not commit Pullboard setup: ${String(error.stderr ?? error.message).trim()}; fix the reported identity or hook problem, then run pullboard init --yes`, 'fix the Git error above, then run pullboard init --yes');+ }+ return { state: 'committed', files: paths, skipped: [...plan.skipped], commit: git(info.root, ['rev-parse', 'HEAD']) };+}++/** Report setup and blueprint notes together, keeping the CLI command itself bounded. */+export function reportInitSetup(io, info, notes, landed) {+ const fresh = landed.filter(added => !added.marked);+ const waiting = landed.length ? initWaitingRows(info.root, { rows: fresh.flatMap(added => added.rows) }) : [];+ /** Give each blueprint the same complete list of still-undecided rows. */+ const blueprintResult = added => ({ ...initBlueprintResult(added), marked: added.marked, waitingRows: waiting });+ const result = { root: info.root, notes, proposedLanes: proposeLanes(info.root),+ ...(landed.length ? { blueprint: blueprintResult(landed[0]), blueprints: landed.map(blueprintResult) } : {}) };+ io.result?.(result);+ const staging = notes.at(-1)?.startsWith('git add -f -- ') ? notes.at(-1) : null;+ (staging ? notes.slice(0, -1) : notes).forEach(note => io.say(note));+ for (const added of landed) {+ if (added.marked) io.say(alreadyAddedLine(added.blueprint));+ else initBlueprintLines(added, askedLaneNotes(added.items, loadConfig(info.root))).forEach(line => io.say(line));+ }+ if (fresh.length) waitingRowLines(waiting).forEach(line => io.say(line));+ return { result, staging };+}diff --git a/src/init.js b/src/init.jsindex 72f61545..0e131759 100644--- a/src/init.js+++ b/src/init.js@@ -569,10 +569,10 @@ function writeCodexLoopRules(root, gate, onWrite) {/*** Set the repo up. Must run in the main checkout, which becomes the coordinator.*- * @param {{ info: { root: string, isMain: boolean }, openBoardHere: () => any, register: Function, closeBoard: Function, model?: string, permissions?: boolean }} context+ * @param {{ info: { root: string, isMain: boolean }, openBoardHere: () => any, register: Function, closeBoard: Function, model?: string, permissions?: boolean, onWritten?: (path: string) => void }} context* @returns {string[]} What happened, one line each.*/-export function initRepo({ info, openBoardHere, register, closeBoard, model, permissions = true }) {+export function initRepo({ info, openBoardHere, register, closeBoard, model, permissions = true, onWritten }) {if (!info.isMain) {throw new Refused('NOT_MAIN', 'run init in the main checkout; worktrees join a lane instead');}@@ -583,7 +583,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model, perconst configured = configuredGate(root);const written = [];/** Record only paths setup actually writes; unrelated files never enter its staging command. */- const onWrite = (path) => { if (!written.includes(path)) written.push(path); };+ const onWrite = (path) => { if (!written.includes(path)) written.push(path); onWritten?.(path); };const notes = [writeNew(join(root, CONFIG_FILE), configTemplate(gate, detectFixers(root)), CONFIG_FILE, onWrite),writeNew(join(root, 'SPEC.md'), specTemplate(basename(root), gate), 'SPEC.md', onWrite),@@ -626,6 +626,12 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model, per/** The one command that shares every board on this computer with the phone and pullboard.dev. */export const RELAY_ON_ALL = 'pullboard relay on --all';+/** Refresh only managed permission files after a blueprint supplies the final gate command. */+export function refreshInitPermissions(root, onWritten) {+ const gate = configuredGate(root) || detectGate(root);+ return [writeClaudeLoopPermissions(root, gate, onWritten), writeCodexLoopRules(root, gate, onWritten)];+}+/** The question init asks a person at the end of setup; Enter means yes. */export const RELAY_OFFER_QUESTION = 'See this board on your phone and pullboard.dev? Sign in with GitHub [Y/n] ';diff --git a/test/init-ignore.test.js b/test/init-ignore.test.jsindex 008fe0a0..69092d17 100644--- a/test/init-ignore.test.js+++ b/test/init-ignore.test.js@@ -39,9 +39,79 @@ function fixture(t, ignore) {git('init', '-q', '-b', 'main');writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ gate: 'true', lanes: { web: { owns: ['web/'], specs: [] } } }));if (ignore !== undefined) writeFileSync(join(root, '.gitignore'), ignore);- return { root, git, cli, output };+ return { root, git, cli, output, env };}+test('init commits its setup files before the first worktree [I1,I2]', t => {+ const box = fixture(t);+ rmSync(join(box.root, 'pullboard.json'));+ for (const key of ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL']) delete box.env[key];+ box.git('config', 'user.name', 'Repository Owner');+ box.git('config', 'user.email', '[email protected]');+ writeFileSync(join(box.root, 'README.md'), '# Existing repository\n');+ box.git('add', 'README.md');+ box.git('commit', '-q', '-m', 'chore: create the repository');+ const original = box.git('rev-parse', 'HEAD');+ writeFileSync(join(box.root, 'README.md'), '# Existing repository\nA separate staged change.\n');+ box.git('add', 'README.md');+ writeFileSync(join(box.root, 'unrelated.txt'), 'A local note, outside setup.\n');+ const staged = box.git('diff', '--cached', '--binary');+ const initialized = box.cli('init', '--blueprint', 'web-app', '--yes');+ assert.equal(initialized.code, 0, initialized.stderr);+ const setup = box.git('rev-parse', 'HEAD');+ assert.notEqual(setup, original, 'the single confirmation commits setup before an agent opens its worktree');+ assert.equal(box.git('show', 'HEAD:README.md'), '# Existing repository', 'the commit excludes the staged user change');+ assert.equal(box.git('diff', '--cached', '--binary'), staged, 'the existing index stays exactly as the user left it');+ assert.equal(readFileSync(join(box.root, 'unrelated.txt'), 'utf8'), 'A local note, outside setup.\n');+ assert.doesNotMatch(box.git('ls-tree', '-r', '--name-only', 'HEAD'), /^unrelated\.txt$/mu);+ assert.equal(box.git('log', '-1', '--format=%an <%ae>'), 'Repository Owner <[email protected]>');+ assert.equal(box.git('show', 'HEAD:SPEC.md'), readFileSync(join(box.root, 'SPEC.md'), 'utf8').trimEnd(),+ 'the setup commit includes the blueprint rows written after the initial setup files');+ const joined = box.cli('worktree', 'review', '--model', 'Setup fixture');+ assert.equal(joined.code, 0, joined.stderr);+ assert.equal(box.git('-C', joined.document.path, 'rev-parse', 'HEAD'), setup);+ const again = box.cli('init', '--yes');+ assert.equal(again.code, 0, again.stderr);+ assert.equal(box.git('rev-parse', 'HEAD'), setup, 'repeating init never creates an empty setup commit');+ assert.equal(box.git('diff', '--cached', '--binary'), staged);+});++test('setup confirmation keeps the index when Git identity is missing and retries after repair [I1,I2]', t => {+ const box = fixture(t);+ rmSync(join(box.root, 'pullboard.json'));+ for (const key of ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL']) delete box.env[key];+ writeFileSync(join(box.root, 'README.md'), '# User staging\n');+ box.git('add', 'README.md');+ const staged = box.git('diff', '--cached', '--binary');+ const failed = box.cli('init', '--yes');+ assert.equal(failed.code, 1);+ assert.equal(failed.document.error.code, 'NOT_COMMITTED');+ assert.match(failed.document.error.next, /pullboard init --yes/u);+ assert.equal(box.git('diff', '--cached', '--binary'), staged, 'a refused commit leaves the existing index alone');+ box.git('config', 'user.name', 'Repaired Owner');+ box.git('config', 'user.email', '[email protected]');+ const repaired = box.cli('init', '--yes');+ assert.equal(repaired.code, 0, repaired.stderr);+ assert.equal(box.git('diff', '--cached', '--binary'), staged, 'the first setup commit also leaves user staging alone');+ assert.equal(box.git('log', '-1', '--format=%an <%ae>'), 'Repaired Owner <[email protected]>');+ assert.doesNotMatch(box.git('ls-tree', '-r', '--name-only', 'HEAD'), /^README\.md$/mu);+ assert.equal(box.cli('worktree', 'review', '--model', 'Repaired fixture').code, 0);+});++test('setup confirmation does not adopt a later user edit to a generated file [I1,I2]', t => {+ const box = fixture(t);+ rmSync(join(box.root, 'pullboard.json'));+ assert.equal(box.cli('init').code, 0);+ const file = join(box.root, 'SPEC.md');+ const edited = readFileSync(file, 'utf8') + '\nA later user note.\n';+ writeFileSync(file, edited);+ const confirmed = box.cli('init', '--yes');+ assert.equal(confirmed.code, 0, confirmed.stderr);+ assert.equal(readFileSync(file, 'utf8'), edited);+ assert.doesNotMatch(box.git('ls-tree', '-r', '--name-only', 'HEAD'), /^SPEC\.md$/mu,+ 'the unchanged-write receipt cannot authorize a later user edit');+});+test('a fresh init tells the person and the agent how to start [I9,I1]', t => {const box = fixture(t);rmSync(join(box.root, 'pullboard.json'));@@ -52,7 +122,7 @@ test('a fresh init tells the person and the agent how to start [I9,I1]', t => {assert.match(initialized.stdout, /new agent worktrees go in \.claude\/worktrees; dot-scanner tools such as eslint \. should ignore \.claude\/worktrees; set "worktrees": "beside" in pullboard\.json to use sibling folders/u,'init prints one-line location, scanner-ignore and switch guidance');assert.match(initialized.stdout, /^Next: ask your agent to set up Pullboard here; in Claude Code, start a new session first so it loads the Pullboard skills\.$/mu, 'init gives one setup instruction and preserves Claude Code skill loading');- assert.match(initialized.stdout, /git add -f --/u, 'the init output keeps its staging instruction');+ assert.match(initialized.stdout, /To commit Pullboard's files: pullboard init --yes/u, 'init gives one setup-only confirmation command');const agents = readFileSync(join(box.root, 'AGENTS.md'), 'utf8');const section = agents.slice(agents.indexOf('## A new board'), agents.indexOf('## Working here: pullboard'));diff --git a/test/init-relay-offer.test.js b/test/init-relay-offer.test.jsindex ffa49a7a..78cb36a9 100644--- a/test/init-relay-offer.test.js+++ b/test/init-relay-offer.test.js@@ -4,6 +4,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { test } from 'node:test';import { acceptsRelayOffer, RELAY_LATER, RELAY_OFFER_QUESTION, RELAY_ON_ALL } from '../src/init.js';+import { SETUP_COMMIT_LATER, SETUP_COMMIT_QUESTION } from '../src/init-finish.js';import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';import { runFixtureChild, safeFixtureDiagnostic, startFixtureChild } from './fixture-child.js';import { relayClientFixture } from './relay-client-fixture.js';@@ -44,7 +45,7 @@ function safeTail(output, env) {* @param {{ when: string, send: string }[]} keys - Keys to type once each text appears, in order.* @returns {Promise<{ code: number | null, output: string, asked: boolean }>}*/-function initInTerminal(t, cwd, env, keys = []) {+function initInTerminal(t, cwd, env, keys = [], setupAnswer = 'n\n') {// The shell keeps a trap on SIGINT so Ctrl-C reaches init and still leaves the shell to print// init's exit code; dash, Linux's sh, would otherwise die with it. Init itself gets the default.const inner = `trap : INT; ${shellWord(process.execPath)} ${shellWord(CLI)} init; echo "pty-exit:$?"`;@@ -56,10 +57,15 @@ function initInTerminal(t, cwd, env, keys = []) {let output = '';let typed = 0;let closedKeyboard = false;+ let answeredSetup = false;/** Close the keyboard once; the terminal then reads end of input. */const closeKeyboard = () => { if (!closedKeyboard) { closedKeyboard = true; child.stdin.end(); } };child.stdout.setEncoding('utf8').on('data', (part) => {output += part;+ if (!answeredSetup && output.includes(SETUP_COMMIT_QUESTION.trim())) {+ answeredSetup = true;+ child.stdin.write(setupAnswer);+ }while (typed < keys.length && output.includes(keys[typed].when)) child.stdin.write(keys[typed++].send);// A question nobody planned to answer gets end of input, so a wrong ask fails instead of hanging.if (output.includes(QUESTION) && !keys.some((key) => key.when === QUESTION)) closeKeyboard();@@ -153,11 +159,29 @@ test('a person at init shares with one Enter [H5,H17,B26]', { timeout: 240_000 }assert.equal(run.asked, true, 'a person at a terminal is asked');assert.equal(run.output.split(QUESTION).length - 1, 1, 'the question is asked once');assert.ok(run.output.split(QUESTION)[1].includes(RELAY_LATER), 'n prints the command for later');- assert.ok(lastInitLine(run.output).startsWith("To commit Pullboard's files: git add -f -- "), 'the staging line stays last');+ assert.equal(lastInitLine(run.output), SETUP_COMMIT_LATER, 'the one setup confirmation command stays last');assert.equal(signIns(box), before, 'n starts no sign-in');assert.equal(linked(root), false, 'n links nothing');});+ await t.test('Enter commits setup while sharing remains a separate choice [I1,I2,H5]', async () => {+ const before = signIns(box);+ const root = freshRepository(box, 'setup-commit-enter');+ const bin = join(root, 'fixture-bin');+ mkdirSync(bin);+ writeFileSync(join(bin, 'pullboard'), `#!/bin/sh\nexec ${shellWord(process.execPath)} ${shellWord(CLI)} "$@"\n`, { mode: 0o700 });+ const terminal = { ...person, PATH: bin + ':' + person.PATH };+ const run = await initInTerminal(t, root, terminal, [{ when: QUESTION, send: 'n\r' }], '\r');+ assert.equal(run.code, 0, safeTail(run.output, person));+ assert.equal(run.output.split(SETUP_COMMIT_QUESTION.trim()).length - 1, 1, 'the setup question appears once');+ assert.match(run.output, /Committed Pullboard setup at [a-f0-9]+/u);+ assert.equal(signIns(box), before, 'setup consent never starts sharing');+ const joined = runFixtureChild(process.execPath, [CLI, 'worktree', 'review', '--model', 'Enter fixture', '--json'],+ { cwd: root, env: terminal, encoding: 'utf8' });+ assert.equal(joined.status, 0, joined.context);+ assert.equal(JSON.parse(joined.stdout).lane, 'review', 'a worktree can join immediately after the one Enter');+ });+await t.test('Enter signs in, shares every board on this computer and prints the QR [H5,H17]', async () => {const before = signIns(box);const root = freshRepository(box, 'answered-enter');@@ -174,7 +198,7 @@ test('a person at init shares with one Enter [H5,H17,B26]', { timeout: 240_000 }assert.match(after, /Pair your phone once: \S+#device=/u, 'the pairing link is printed');assert.ok(after.includes('\x1b[30;47m') && after.includes('█'), 'the QR is printed');assert.equal(after.includes(RELAY_LATER), false, 'a yes is not told to run the command later');- assert.ok(lastInitLine(run.output).startsWith("To commit Pullboard's files: git add -f -- "), 'the staging line stays last');+ assert.equal(lastInitLine(run.output), SETUP_COMMIT_LATER, 'the one setup confirmation command stays last');assert.deepEqual(['', 'y', 'Y', 'yes', ' y '].map(acceptsRelayOffer), [true, true, true, true, true], 'Enter or y is yes');assert.deepEqual(['n', 'no', 'later', null].map(acceptsRelayOffer), [false, false, false, false], 'anything else, or a closed terminal, is no');});diff --git a/test/newcomer.test.js b/test/newcomer.test.jsindex a71bdf1b..6c7eeda4 100644--- a/test/newcomer.test.js+++ b/test/newcomer.test.js@@ -22,8 +22,14 @@ function project(t) {return { root, env, git, run };}-test('init ends with a working staging line for exactly its own writes [I1,I2,D1,D2]', (t) => {+test('init ends with one confirmation command for its own writes [I1,I2,D1,D2]', (t) => {const box = project(t);+ box.git('config', 'user.name', 'Newcomer Fixture');+ box.git('config', 'user.email', '[email protected]');+ const bin = join(box.root, 'fixture-bin');+ mkdirSync(bin);+ symlinkSync(BIN, join(bin, 'pullboard'));+ box.env.PATH = bin + ':' + process.env.PATH;writeFileSync(join(box.root, '.env.local'), 'LOCAL=1\n');writeFileSync(join(box.root, 'notes.txt'), 'keep this out of the initial commit\n');writeFileSync(join(box.root, '.gitignore'), '.claude/\n');@@ -39,28 +45,23 @@ test('init ends with a working staging line for exactly its own writes [I1,I2,D1const label = "To commit Pullboard's files: ";assert.ok(stagingLine.startsWith(label), `expected the final line to start with ${label}`);const command = stagingLine.slice(label.length);- assert.match(command, /^git add -f -- /);+ assert.equal(command, 'pullboard init --yes');const staged = spawnSync('sh', ['-c', command], { cwd: box.root, env: box.env, encoding: 'utf8' });assert.equal(staged.status, 0, staged.stderr);- assert.deepEqual(box.git('diff', '--cached', '--name-only').split('\n'), [- '.claude/settings.json',- '.claude/skills/pullboard-decompose/SKILL.md',- '.claude/skills/pullboard-plan/SKILL.md',- '.claude/skills/pullboard-signoff/SKILL.md',- '.claude/skills/pullboard-spec-review/SKILL.md',- '.claude/skills/pullboard-verify/SKILL.md',- '.codex/rules/pullboard.rules',- '.githooks/commit-msg', '.githooks/pre-merge-commit', '.githooks/pre-push',- '.gitignore',- 'AGENTS.md', 'DOCTRINE.md', 'SPEC.md', 'pullboard.json',- ]);+ const committed = box.git('ls-tree', '-r', '--name-only', 'HEAD').split('\n');+ for (const file of ['pullboard.json', 'SPEC.md', 'DOCTRINE.md', '.githooks/commit-msg']) assert.ok(committed.includes(file), file);+ for (const file of ['.env.local', 'notes.txt', '.githooks/pre-commit', '.claude/skills/pullboard-run/SKILL.md', 'fixture-bin/pullboard']) {+ assert.equal(committed.includes(file), false, `setup never commits the existing ${file}`);+ }+ assert.equal(box.git('diff', '--cached', '--name-only'), '', 'the setup-only commit leaves no extra staging behind');assert.equal(readFileSync(join(box.root, '.env.local'), 'utf8'), 'LOCAL=1\n');assert.equal(readFileSync(join(box.root, '.githooks', 'pre-commit'), 'utf8'), '#!/bin/sh\n# My hook\n');- box.git('reset', '-q');+ const head = box.git('rev-parse', 'HEAD');const rerun = box.run('init');assert.equal(rerun.status, 0, rerun.stderr);const secondStage = rerun.stdout.trimEnd().split('\n').at(-1);- assert.doesNotMatch(secondStage, /^git add -f -- /, 'idempotent setup writes and stages nothing on its second run');+ assert.doesNotMatch(secondStage, /pullboard init --yes/u, 'committed setup needs no second confirmation');+ assert.equal(box.git('rev-parse', 'HEAD'), head);assert.equal(box.git('diff', '--cached', '--name-only'), '');});