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): keep setup index edits and repository identity [I1,I2]

Corey Olsondf7cb1bc6222
diff --git a/src/init-finish.js b/src/init-finish.js
index 2ca31196..2efa5a62 100644
--- a/src/init-finish.js
+++ b/src/init-finish.js
@@ -106,14 +106,17 @@ export function beginInitCommit(info) {
else if (actual) skipped.add(name);
}
const owned = new Set(files.keys());
+ const initialIndex = new Map();
/** 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; }
+ if (!initialIndex.has(name)) initialIndex.set(name, tryGit(info.root, ['ls-files', '--stage', '-z', '--', `:(literal)${name}`]).stdout);
const hash = setupFile(info.root, name);
if (hash) { owned.add(name); files.set(name, hash); }
}
- return { info, file, files, written, skipped };
+ for (const name of files.keys()) if (!initialIndex.has(name)) initialIndex.set(name, tryGit(info.root, ['ls-files', '--stage', '-z', '--', `:(literal)${name}`]).stdout);
+ return { info, file, files, written, skipped, initialIndex };
}
/** Ask once; closing stdin is a decline, while Enter accepts the displayed file list. */
@@ -159,9 +162,17 @@ export async function finishInitCommit(plan, { io, yes, landed, permissions }) {
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');
}
+ if (changed.some(([name, hash]) => {
+ const index = tryGit(info.root, ['ls-files', '--stage', '-z', '--', `:(literal)${name}`]);
+ return index.status !== 0 || (index.stdout !== plan.initialIndex.get(name) && indexedSetupFile(info.root, name) !== hash);
+ })) {
+ throw new Refused('NOT_COMMITTED', 'a setup file was staged differently while confirmation was open; your index is unchanged; review it, then 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}`)]);
+ const identity = { ...process.env };
+ for (const name of ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL', 'EMAIL']) delete identity[name];
+ git(info.root, ['commit', '--only', '-q', '-m', 'chore: set up Pullboard', '--', ...paths.map(name => `:(literal)${name}`)], { env: identity });
} 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}`)]);
diff --git a/test/init-ignore.test.js b/test/init-ignore.test.js
index ad9c09a7..01d08ddd 100644
--- a/test/init-ignore.test.js
+++ b/test/init-ignore.test.js
@@ -1,11 +1,13 @@
/** Setup preserves local ignore rules and excludes real nested agent worktrees [I1,I2,I16]. */
import assert from 'node:assert/strict';
-import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { runFixtureChild, runFixtureGit, startFixtureChild } from './fixture-child.js';
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { test } from 'node:test';
-import { AGENT_SHELL_MARKERS } from '../src/person.js';
+import { SETUP_COMMIT_QUESTION } from '../src/init-finish.js';
+import { RELAY_OFFER_QUESTION } from '../src/init.js';
+import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
/** Create a private Git repo whose installed hooks invoke this candidate CLI only. */
function fixture(t, ignore) {
@@ -37,6 +39,7 @@ function fixture(t, ignore) {
return { code: result.status, stdout: result.stdout, stderr: result.failure ?? result.stderr, failure: result.failure };
}
git('init', '-q', '-b', 'main');
+ git('config', 'user.name', 'Init Fixture'); git('config', 'user.email', '[email protected]');
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, env };
@@ -80,6 +83,7 @@ test('setup confirmation keeps the index when Git identity is missing and retrie
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', '--unset', 'user.name'); box.git('config', '--unset', 'user.email');
writeFileSync(join(box.root, 'README.md'), '# User staging\n');
box.git('add', 'README.md');
const staged = box.git('diff', '--cached', '--binary');
@@ -145,6 +149,67 @@ test('setup confirmation preserves a different version staged from its saved wor
assert.equal(readFileSync(file, 'utf8'), original, 'the working version remains exact too');
});
+/** Run a real terminal confirmation, staging the caller's change only after the question appears. */
+async function confirmSetupAfter(t, box, beforeEnter) {
+ const env = { ...box.env, SHELL: '/bin/sh', PULLBOARD_VIEW_BACKGROUND: '0' };
+ for (const marker of [...AGENT_SHELL_MARKERS, ...SSH_SHELL_MARKERS, 'CI']) delete env[marker];
+ const word = value => "'" + value.replaceAll("'", "'\\''") + "'";
+ const cli = resolve(import.meta.dirname, '../bin/pullboard.js');
+ const inner = `${word(process.execPath)} ${word(cli)} init; echo "pty-exit:$?"`;
+ const script = process.platform === 'darwin' ? ['-q', '/dev/null', '/bin/sh', '-c', inner] : ['-qec', inner, '/dev/null'];
+ const child = startFixtureChild('/bin/sh', ['-c', '/bin/cat | /usr/bin/script "$@"', 'sh', ...script],
+ { cwd: box.root, env, stdio: ['pipe', 'pipe', 'pipe'] });
+ t.after(() => { if (child.exitCode === null && child.signalCode === null) child.kill('SIGTERM'); });
+ let output = '', entered = false, closed = false;
+ child.stdout.setEncoding('utf8').on('data', part => {
+ output += part;
+ if (!entered && output.includes(SETUP_COMMIT_QUESTION.trim())) {
+ entered = true; beforeEnter(); child.stdin.write('\r');
+ }
+ if (!closed && (output.includes(RELAY_OFFER_QUESTION.trim()) || /pty-exit:\d+/u.test(output))) {
+ closed = true; child.stdin.end();
+ }
+ });
+ await new Promise((resolveRun, reject) => { child.once('error', reject); child.once('close', resolveRun); });
+ return { entered, output, code: Number(/pty-exit:(\d+)/u.exec(output)?.[1]) };
+}
+
+test('setup confirmation preserves an index-only edit made while the prompt is open [I1,I2]', { timeout: 30_000 }, async t => {
+ const box = fixture(t);
+ rmSync(join(box.root, 'pullboard.json'));
+ writeFileSync(join(box.root, 'README.md'), '# Existing repository\n');
+ box.git('add', 'README.md'); box.git('commit', '-q', '-m', 'chore: initial repository');
+ assert.equal(box.output('init').code, 0);
+ const head = box.git('rev-parse', 'HEAD'), file = join(box.root, 'SPEC.md');
+ const original = readFileSync(file, 'utf8'), staged = original + '\nA note staged during confirmation.\n';
+ let before;
+ const confirmed = await confirmSetupAfter(t, box, () => {
+ writeFileSync(file, staged); box.git('add', 'SPEC.md'); writeFileSync(file, original);
+ before = box.git('diff', '--cached', '--binary');
+ });
+ assert.equal(confirmed.entered, true, 'the actual human question appeared before the index changed');
+ assert.equal(box.git('show', ':SPEC.md'), staged.trimEnd(), 'the new index-only version survives Enter');
+ assert.equal(box.git('diff', '--cached', '--binary'), before, 'the whole staged patch remains exact');
+ assert.equal(readFileSync(file, 'utf8'), original, 'the working version remains exact too');
+ assert.equal(box.git('rev-parse', 'HEAD'), head, 'a stale confirmation commits nothing');
+ assert.equal(confirmed.code, 1, confirmed.output);
+ assert.match(confirmed.output, /\[NOT_COMMITTED\].*staged differently while confirmation was open/u);
+});
+
+test('setup commits use repository identity despite inherited agent identity [I1,I2]', t => {
+ const box = fixture(t);
+ rmSync(join(box.root, 'pullboard.json'));
+ box.git('config', 'user.name', 'Repository Owner'); box.git('config', 'user.email', '[email protected]');
+ Object.assign(box.env, { GIT_AUTHOR_NAME: 'Inherited Agent', GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Inherited Agent', GIT_COMMITTER_EMAIL: '[email protected]', EMAIL: '[email protected]' });
+ const configured = box.git('config', '--local', '--get-regexp', '^user\\.');
+ const initialized = box.cli('init', '--yes');
+ assert.equal(initialized.code, 0, initialized.stderr);
+ assert.equal(box.git('log', '-1', '--format=%an <%ae> / %cn <%ce>'),
+ 'Repository Owner <[email protected]> / Repository Owner <[email protected]>', 'both identities come from this repository');
+ assert.equal(box.git('config', '--local', '--get-regexp', '^user\\.'), configured, 'setup never changes repository identity settings');
+});
+
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'));
diff --git a/test/init-relay-offer.test.js b/test/init-relay-offer.test.js
index 78cb36a9..50a41b61 100644
--- a/test/init-relay-offer.test.js
+++ b/test/init-relay-offer.test.js
@@ -90,7 +90,7 @@ function initWithoutTerminal(cwd, env) {
function freshRepository(box, name) {
const root = join(dirname(box.root), name);
mkdirSync(root);
- for (const args of [['init', '-q', '-b', 'main'], ['-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-q', '-m', 'fixture base'],
+ for (const args of [['init', '-q', '-b', 'main'], ['config', 'user.name', 'Relay Fixture'], ['config', 'user.email', '[email protected]'], ['-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-q', '-m', 'fixture base'],
['remote', 'add', 'origin', '[email protected]:fixture/repository.git']]) {
assert.equal(runFixtureChild('git', args, { cwd: root, env: box.env, encoding: 'utf8' }).status, 0);
}