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(init): ignore internal agent worktrees idempotently [I1,I16]

Corey Olson1fdae4588deb
diff --git a/src/hooks.js b/src/hooks.js
index 3fab8157..4cdcf8e6 100644
--- a/src/hooks.js
+++ b/src/hooks.js
@@ -4,7 +4,7 @@
* Each check returns its problems; an empty list lets git go on.
*/
import { spawnSync } from 'node:child_process';
-import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { git, gitChildEnv, mainCheckout, tryGit } from './git.js';
import { Refused } from './refused.js';
@@ -384,7 +384,16 @@ export function installHooks(root, onWrite = () => {}) {
);
continue;
}
- writeFileSync(file, hookScript(hook));
+ const script = hookScript(hook);
+ if (existing === script) {
+ if ((statSync(file).mode & 0o777) !== 0o755) {
+ chmodSync(file, 0o755);
+ onWrite(`${HOOKS_DIR}/${hook}`);
+ notes.push(`restored executable mode for ${HOOKS_DIR}/${hook}`);
+ } else notes.push(`kept ${HOOKS_DIR}/${hook}`);
+ continue;
+ }
+ writeFileSync(file, script);
chmodSync(file, 0o755);
onWrite(`${HOOKS_DIR}/${hook}`);
notes.push(`wrote ${HOOKS_DIR}/${hook}`);
@@ -392,6 +401,8 @@ export function installHooks(root, onWrite = () => {}) {
const current = tryGit(root, ['config', '--get', 'core.hooksPath']).stdout;
if (current && current !== HOOKS_DIR) {
notes.push(`core.hooksPath is ${current}; left as is. Call pullboard hook <name> from those hooks`);
+ } else if (current === HOOKS_DIR) {
+ notes.push(`kept core.hooksPath at ${HOOKS_DIR}`);
} else {
git(root, ['config', 'core.hooksPath', HOOKS_DIR]);
notes.push(`set core.hooksPath to ${HOOKS_DIR}`);
diff --git a/src/init.js b/src/init.js
index 890a4348..e543ac39 100644
--- a/src/init.js
+++ b/src/init.js
@@ -87,6 +87,18 @@ function writeNew(file, text, name, onWrite) {
return `wrote ${name}`;
}
+/** Ignore Claude's nested agent worktrees, preserving existing ignore bytes and second-run idempotence. */
+function ignoreAgentWorktrees(root, onWrite) {
+ const file = join(root, '.gitignore');
+ const pattern = '.claude/worktrees/';
+ const existing = existsSync(file);
+ const previous = existing ? readFileSync(file, 'utf8') : '';
+ if (previous.split(/\r?\n/u).includes(pattern)) return 'kept .gitignore (already ignores .claude/worktrees/)';
+ appendFileSync(file, (previous && !previous.endsWith('\n') ? '\n' : '') + pattern + '\n');
+ onWrite('.gitignore');
+ return existing ? 'added .claude/worktrees/ to .gitignore' : 'wrote .gitignore (ignores .claude/worktrees/)';
+}
+
/**
* Put the agent instructions in AGENTS.md, appending pullboard's block to a file the repo already
* has, and point CLAUDE.md at AGENTS.md so Claude Code reads the same rules.
@@ -192,6 +204,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard }) {
writeNew(join(root, CONFIG_FILE), configTemplate(gate, detectFixers(root)), CONFIG_FILE, onWrite),
writeNew(join(root, 'SPEC.md'), specTemplate(basename(root), gate), 'SPEC.md', onWrite),
writeNew(join(root, 'PRACTICE.md'), practiceTemplate(), 'PRACTICE.md', onWrite),
+ ignoreAgentWorktrees(root, onWrite),
...writeAgentDocs(root, onWrite),
...installHooks(root, onWrite),
...installSkills(root, onWrite),
diff --git a/test/init-ignore.test.js b/test/init-ignore.test.js
new file mode 100644
index 00000000..6f1c81a4
--- /dev/null
+++ b/test/init-ignore.test.js
@@ -0,0 +1,89 @@
+/** Setup preserves local ignore rules and excludes real nested agent worktrees [I1,I2,I16]. */
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+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';
+
+/** Create a private Git repo whose installed hooks invoke this candidate CLI only. */
+function fixture(t, ignore) {
+ const directory = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-init-ignore-')));
+ t.after(() => rmSync(directory, { recursive: true, force: true }));
+ const root = join(directory, 'repo'); const bin = join(directory, 'bin');
+ mkdirSync(root); mkdirSync(bin);
+ const cliPath = resolve(import.meta.dirname, '../bin/pullboard.js');
+ writeFileSync(join(bin, 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${cliPath}" "$@"\n`);
+ chmodSync(join(bin, 'pullboard'), 0o755);
+ const env = { ...process.env, HOME: join(directory, 'home'), PULLBOARD_HOME: join(directory, 'board-home'), PULLBOARD_MACHINE_HOME: join(directory, 'machine-home'), PATH: bin + ':' + process.env.PATH };
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
+ delete env.PULLBOARD_RELAY_TOKEN;
+ Object.assign(env, { GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'Init Fixture', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'Init Fixture', GIT_COMMITTER_EMAIL: '[email protected]' });
+ /** Run actual Git and its installed hooks, requiring success. */
+ function git(...args) {
+ const result = spawnSync('git', args, { cwd: root, env, encoding: 'utf8' });
+ assert.equal(result.status, 0, result.stderr);
+ return result.stdout;
+ }
+ /** Invoke the real command and retain its typed result, including refusals. */
+ function cli(...args) {
+ const result = spawnSync(process.execPath, [cliPath, ...args, '--json'], { cwd: root, env, encoding: 'utf8' });
+ return { code: result.status, document: JSON.parse(result.stdout), stderr: result.stderr };
+ }
+ 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 };
+}
+
+test('init appends only the agent-worktree ignore rule and the second init writes nothing [I1,I2,I16]', t => {
+ for (const previous of [undefined, '', '# existing rules\r\nnode_modules/\r\n!keep-this', '.claude/worktrees/\n# already configured\n']) {
+ const box = fixture(t, previous);
+ const first = box.cli('init');
+ assert.equal(first.code, 0, JSON.stringify(first.document));
+ const file = join(box.root, '.gitignore');
+ const expected = previous?.split(/\r?\n/u).includes('.claude/worktrees/') ? previous : (previous ?? '') + (previous && !previous.endsWith('\n') ? '\n' : '') + '.claude/worktrees/\n';
+ assert.equal(readFileSync(file, 'utf8'), expected, 'every previous byte stays intact');
+ assert.ok(first.document.notes.some(note => note.includes('.gitignore')));
+ const setupFiles = ['.gitignore', '.git/config', 'AGENTS.md', '.githooks/pre-commit', '.githooks/commit-msg', '.githooks/pre-push'];
+ const before = setupFiles.map(name => statSync(join(box.root, name), { bigint: true }).mtimeNs);
+ const second = box.cli('init');
+ assert.equal(second.code, 0, second.stderr);
+ assert.equal(readFileSync(file, 'utf8'), expected);
+ assert.deepEqual(setupFiles.map(name => statSync(join(box.root, name), { bigint: true }).mtimeNs), before, 'setup files and hook configuration are never rewritten');
+ assert.ok(second.document.notes.includes('kept .gitignore (already ignores .claude/worktrees/)'));
+ assert.equal(second.document.notes.some(note => note.startsWith('git add ')), false, 'a second init writes no setup files: ' + JSON.stringify(second.document.notes));
+ }
+});
+
+test('idempotent setup still restores executable mode on its own managed hooks [I1,I2]', t => {
+ const box = fixture(t);
+ assert.equal(box.cli('init').code, 0);
+ const hook = join(box.root, '.githooks/pre-commit');
+ const source = readFileSync(hook, 'utf8');
+ chmodSync(hook, 0o644);
+ const repaired = box.cli('init');
+ assert.equal(repaired.code, 0);
+ assert.equal(statSync(hook).mode & 0o777, 0o755);
+ assert.equal(readFileSync(hook, 'utf8'), source);
+ assert.ok(repaired.document.notes.includes('restored executable mode for .githooks/pre-commit'));
+});
+
+test('a real worktree under .claude/worktrees leaves status clean and coordinator submit succeeds [I1,I16]', t => {
+ const box = fixture(t);
+ assert.equal(box.cli('init').code, 0);
+ box.git('add', '-A'); box.git('commit', '-q', '-m', 'chore: initialize isolated board');
+ const added = box.cli('add', 'coordinator', 'Proof with a nested agent worktree', '--criterion', 'the clean coordinator can submit');
+ assert.equal(added.code, 0);
+ const id = String(added.document.item.item_id);
+ assert.equal(box.cli('claim', id).code, 0);
+ mkdirSync(join(box.root, 'docs'));
+ writeFileSync(join(box.root, 'docs/proof.txt'), 'actual coordinator work\n');
+ box.git('add', 'docs/proof.txt'); box.git('commit', '-q', '-m', 'chore: add the coordinator proof');
+ box.git('worktree', 'add', '-q', '-b', 'agent/scratch', '.claude/worktrees/scratch', 'HEAD');
+ assert.equal(box.git('status', '--porcelain'), '', 'the real nested checkout adds no untracked paths');
+ const submitted = box.cli('submit', id);
+ assert.equal(submitted.code, 0, JSON.stringify(submitted.document));
+ assert.equal(submitted.document.id, Number(id));
+ assert.equal(submitted.document.gate.green, true);
+});