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(worktree): configure agent worktree location [I1,I2]
Corey Olson4368fafba6aa
diff --git a/docs/api.md b/docs/api.mdindex dbafe4db..6dea32bb 100644--- a/docs/api.md+++ b/docs/api.md@@ -51,7 +51,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec| `join` | `version:number`, `agent:string`, `lane:string`, `route:string`, `path:string`, `model:string`, `displayName:string` || `takeover` | `version:number`, `agent:string`, `path:string` || `worktree` | `version:number`, `agent:string`, `lane:string`, `route:string`, `path:string`, `branch:string`, `prompt:string`, `model:string`, `displayName:string` |-| `resume` | `version:number`, `me:object`, `all:array`, `requests:array`, `holding:array`, `sentBack:array`, `awaiting:array`, `toVerify:array`, `toMerge:array`, `open:array`, `stale:array`, `holds:array`, `unread:number`, `newest:array`, `root:string`, `dirty:number`, `next:string` |+| `resume` | `version:number`, `me:object`, `all:array`, `requests:array`, `holding:array`, `sentBack:array`, `awaiting:array`, `toVerify:array`, `toMerge:array`, `open:array`, `stale:array`, `holds:array`, `unread:number`, `newest:array`, `root:string`, `newWorktreeLocation:string`, `dirty:number`, `next:string` || `whoami` | `version:number`, `id:string`, `lane:string`, `path:string`, `model:string`, `displayName:string` || `lanes` | `version:number`, `lanes:object`, `shared:array`, `coordinator:string` || `resources` | `version:number`, `resources:array` |diff --git a/docs/formats.md b/docs/formats.mdindex 53745ece..8ce32cd8 100644--- a/docs/formats.md+++ b/docs/formats.md@@ -357,6 +357,8 @@ Migration preserves event rows and adds only schema objects that are missing.`pullboard.json` may set `affectedTests` to a command prefix that runs selected test files. When it is absent, `submit` runs the configured `gate` in full. When present and the import graph can safely select a subset, Pullboard appends the selected file paths to this prefix; an uncertain selection still runs the full gate. For example, this repository opts in with `"affectedTests": "node bin/run-tests.js"`. Projects using another test framework can leave the setting out and keep their configured gate, such as `npm test`.+`pullboard.json` may set `worktrees` to `"inside"` or `"beside"`. Fresh `pullboard init` writes `"inside"`, placing new agent worktrees under `.claude/worktrees/<lane>-N`; it also adds `.claude/worktrees/` to `.gitignore` and prints guidance for dot-scanner ignore rules. An omitted setting defaults to `"beside"` to preserve existing sibling paths (`../<repo>-<lane>-N`). `pullboard resume` and `pullboard help worktree` show the active location from the primary checkout's config.+<!-- pass-rule:start -->The `pass` event is emitted by `passDecision` only for the coordinator; another agent receives `COORDINATOR_ONLY`. Its event actor is the coordinator. The person receives the passed decision, while the event table records who performed the pass.<!-- pass-rule:end -->diff --git a/src/cli.js b/src/cli.jsindex bb55b3c2..47520905 100644--- a/src/cli.js+++ b/src/cli.js@@ -1237,6 +1237,8 @@ function boardSetup(ctx, card, identity) {function resumeHere(io) {const ctx = context(io);const { root, isMain } = ctx.info;+ const mainRoot = primaryCheckoutRoot(ctx.info);+ const worktreeConfig = mainRoot ? (isMain ? ctx.config : loadConfig(mainRoot)) : null;let setupScope;const card = withBoard(ctx, (board) => {setupScope = setupIdentity(board);@@ -1270,6 +1272,9 @@ function resumeHere(io) {});card.relayProblems = unlinkedRelayProjects();card.hookProblems = unwiredHookProblems(root);+ card.newWorktreeLocation = mainRoot+ ? worktreeLocation(mainRoot, worktreeConfig)+ : unavailableWorktreeLocation();const { me } = card;const name = (id) => agentDisplayName(card.agents, ctx.config, id);card.stale = staleFrozenItems(card.all, loadSpec(root, ctx.config).rows, ctx.doctrine.rows).map((item) => ({ ...item, ...staleItemFinding(item) }));@@ -1290,6 +1295,7 @@ 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}`);+ say(`New agent worktrees: ${card.newWorktreeLocation}`);card.setup = boardSetup(ctx, card, setupScope);if (card.setup) {say(`Setting up: step ${card.setup.step} of 5`);@@ -1681,12 +1687,17 @@ async function worktreeFor(io, lane, route, family = null, model) {throw new Refused('BAD_ROUTE', `route "${route}" is strong (needs a frontier model) or light (any model can build it from the brief)`);}model = requiredModel(model, process.env, `worktree ${shellWord(lane)}${route === 'strong' ? '' : ` --route ${shellWord(route)}`}${family ? ` --family ${shellWord(family)}` : ''}`);- const mainRoot = resolve(ctx.info.commonDir, '..');- refuseUncommittedSetup(mainRoot, ctx.config);- const pathFor = (n) => join(dirname(mainRoot), `${basename(mainRoot)}-${lane}-${n}`);+ const mainRoot = primaryCheckoutRoot(ctx.info);+ if (!mainRoot) throw new Refused('NO_POLICY', 'the primary checkout cannot be proven from Git metadata or the read-only project registry; restore the registry and retry');+ const mainConfig = loadConfig(mainRoot);+ refuseUncommittedSetup(mainRoot, mainConfig);+ const pathFor = (n) => mainConfig.worktrees === 'inside'+ ? join(mainRoot, '.claude', 'worktrees', `${lane}-${n}`)+ : join(dirname(mainRoot), `${basename(mainRoot)}-${lane}-${n}`);const isTaken = (n) => existsSync(pathFor(n)) || tryGit(mainRoot, ['rev-parse', '--verify', '--quiet', `refs/heads/${lane}/${n}`]).status === 0;let n = 1;while (isTaken(n)) n += 1;+ mkdirSync(dirname(pathFor(n)), { recursive: true });git(mainRoot, ['worktree', 'add', '-q', '-b', `${lane}/${n}`, pathFor(n), git(mainRoot, ['rev-parse', 'HEAD'])]);const root = git(pathFor(n), ['rev-parse', '--show-toplevel']);let id;@@ -1720,6 +1731,18 @@ async function worktreeFor(io, lane, route, family = null, model) {return 0;}+/** Describe the active configured location for new agent worktrees. */+function worktreeLocation(mainRoot, config) {+ return config.worktrees === 'inside'+ ? join(mainRoot, '.claude', 'worktrees', '<lane>-N')+ : join(dirname(mainRoot), `${basename(mainRoot)}-<lane>-N`);+}++/** Explain how to recover the configured location when the primary checkout cannot be proven. */+function unavailableWorktreeLocation() {+ return 'unavailable; run pullboard resume from the main checkout to see the configured location';+}+/*** The files a new worktree takes from the main checkout's last commit and works by: the config, the* spec, the practice file, the rules its opening lines name, and the hooks, when git looks for them@@ -3356,7 +3379,22 @@ async function runCommand(argv, io) {}const help = selectedHelp(command, first, second, rest, values);if (help) {- if (help.text) return printHelp(io, help.text);+ if (help.text) {+ let text = help.text;+ if (help.name === 'worktree') {+ try {+ const ctx = context(io);+ const mainRoot = primaryCheckoutRoot(ctx.info);+ const worktreeConfig = mainRoot ? (ctx.info.isMain ? ctx.config : loadConfig(mainRoot)) : null;+ text += `\nActive worktree location: ${mainRoot+ ? worktreeLocation(mainRoot, worktreeConfig)+ : unavailableWorktreeLocation()}.`;+ } catch (error) {+ if (!(error instanceof Refused)) throw error;+ }+ }+ return printHelp(io, text);+ }return unknownCommand(io, help.name);}const args = { first, second, rest, values };diff --git a/src/config.js b/src/config.jsindex f06fe763..c2d2ff8d 100644--- a/src/config.js+++ b/src/config.js@@ -43,6 +43,7 @@ export function defaults() {gate: '',lease: '2h',reviewLease: '30m',+ worktrees: 'beside',verify: { policy: 'any', family: 'off', reviewRatio: 3 },agents: { names: 'suffix' },check: { install: '', timeout: '5m' },@@ -158,6 +159,7 @@ export function configProblems(config) {if (typeof config.spec !== 'string' || !config.spec) problems.push('"spec" names a file');if (typeof config.practice !== 'string' || !config.practice) problems.push('"practice" names the doctrine file');if (typeof config.gate !== 'string') problems.push('"gate" is a shell command, like "npm test"');+ if (!['inside', 'beside'].includes(config.worktrees)) problems.push('"worktrees" is "inside" or "beside"');if (config.submitGate !== undefined && config.submitGate !== 'landing') {problems.push('"submitGate" is "landing" when the full suite should be deferred until landing');}diff --git a/src/help.js b/src/help.jsindex d2485849..5e309850 100644--- a/src/help.js+++ b/src/help.js@@ -12,6 +12,7 @@ Set uppullboard tour see it work: a reject and its rework, scripted, in thirty secondspullboard init [--model <name>] config, SPEC.md, agent instructions, git hooks, board; optional coordinator modelpullboard worktree <lane> --model <name> [--route light] [--family <name>] make and join a worktree for a new agent+ pullboard.json worktrees: inside or beside; init defaults to insidepullboard join <lane> --model <name> [--route light] [--family <name>] register this worktree as an agentA model is required (or set PULLBOARD_MODEL); family is a separate declarationpullboard join coordinator --model <name> declare the main checkout's coordinator modeldiff --git a/src/init.js b/src/init.jsindex 8a5b1567..c5a522ba 100644--- a/src/init.js+++ b/src/init.js@@ -196,6 +196,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {throw new Refused('NOT_MAIN', 'run init in the main checkout; worktrees join a lane instead');}const { root } = info;+ const worktreeMode = existsSync(join(root, CONFIG_FILE)) ? loadConfig(root).worktrees : 'inside';const doctrine = existsSync(join(root, CONFIG_FILE)) ? loadConfig(root).practice : doctrineFile(root);const gate = detectGate(root);const written = [];@@ -206,6 +207,9 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {writeNew(join(root, 'SPEC.md'), specTemplate(basename(root), gate), 'SPEC.md', onWrite),writeNew(join(root, doctrine), practiceTemplate(), doctrine, onWrite),ignoreAgentWorktrees(root, onWrite),+ worktreeMode === 'inside'+ ? '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'+ : 'new agent worktrees go beside this repository as <repo>-<lane>-N; set "worktrees": "inside" in pullboard.json to nest them under .claude/worktrees (dot-scanner tools such as eslint . should ignore that path)',...writeAgentDocs(root, onWrite),...installHooks(root, onWrite),...installSkills(root, onWrite),diff --git a/src/json.js b/src/json.jsindex cb556f2c..6077e520 100644--- a/src/json.js+++ b/src/json.js@@ -16,7 +16,7 @@ export const JSON_SHAPES = {join: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string', model: 'string', displayName: 'string' }),takeover: shape({ agent: 'string', path: 'string' }),worktree: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string', branch: 'string', prompt: 'string', model: 'string', displayName: 'string' }),- resume: shape({ me: 'object', all: 'array', requests: 'array', holding: 'array', sentBack: 'array', awaiting: 'array', toVerify: 'array', toMerge: 'array', open: 'array', stale: 'array', holds: 'array', unread: 'number', newest: 'array', root: 'string', dirty: 'number', next: 'string' }),+ resume: shape({ me: 'object', all: 'array', requests: 'array', holding: 'array', sentBack: 'array', awaiting: 'array', toVerify: 'array', toMerge: 'array', open: 'array', stale: 'array', holds: 'array', unread: 'number', newest: 'array', root: 'string', newWorktreeLocation: 'string', dirty: 'number', next: 'string' }),whoami: shape({ id: 'string', lane: 'string', path: 'string', model: 'string', displayName: 'string' }),lanes: shape({ lanes: 'object', shared: 'array', coordinator: 'string' }),resources: shape({ resources: 'array' }),diff --git a/src/templates.js b/src/templates.jsindex 4ca3e3fe..fa2c4e5c 100644--- a/src/templates.js+++ b/src/templates.js@@ -21,6 +21,7 @@ export function configTemplate(gate, fix = []) {...(fix.length ? { fix } : {}),spec: 'SPEC.md',practice: DOCTRINE_FILE,+ worktrees: 'inside',verify: { policy: 'any', family: 'off' },agents: { names: 'suffix' },lease: '2h',diff --git a/test/init-ignore.test.js b/test/init-ignore.test.jsindex 1f19b5c0..5384fd48 100644--- a/test/init-ignore.test.js+++ b/test/init-ignore.test.js@@ -47,6 +47,10 @@ test('a fresh init tells the person and the agent how to start [I9,I1]', t => {rmSync(join(box.root, 'pullboard.json'));const initialized = box.output('init');assert.equal(initialized.code, 0, initialized.stderr);+ assert.equal(JSON.parse(readFileSync(join(box.root, 'pullboard.json'), 'utf8')).worktrees, 'inside',+ 'fresh init opts into worktrees inside the repository');+ 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');diff --git a/test/worktree-start.test.js b/test/worktree-start.test.jsindex 6a7b83fa..57c0c263 100644--- a/test/worktree-start.test.js+++ b/test/worktree-start.test.js@@ -1,9 +1,11 @@/** A fresh main checkout uses its declared model for an agent worktree [I1,I2]. */import assert from 'node:assert/strict';-import { join, resolve } from 'node:path';+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { basename, dirname, join, resolve } from 'node:path';import { after, test } from 'node:test';import { createE2eHelpers } from './e2e-helpers.js';import { runFixtureChild } from './fixture-child.js';+import { configProblems, defaults } from '../src/config.js';const e2e = createE2eHelpers();after(e2e.cleanup);@@ -69,3 +71,125 @@ test("the README's worktree command works in a fresh repo [I1,I2]", () => {assert.equal(JSON.parse(missingJoinJson.out).error.next,'run pullboard join api --model "<model name>"');});++test('a new worktree is created inside the repository [I1,I2]', () => {+ for (const mode of ['inside', 'beside', undefined]) {+ const box = sandbox();+ const { repo, web } = project('true', box);+ const configPath = join(repo, 'pullboard.json');+ const originalConfigText = readFileSync(configPath, 'utf8');+ const config = JSON.parse(originalConfigText);+ if (mode === undefined) delete config.worktrees;+ else config.worktrees = mode;+ const configText = `${JSON.stringify(config, null, 2)}\n`;+ if (configText !== originalConfigText) {+ writeFileSync(configPath, configText);+ box.git(repo, 'add', 'pullboard.json');+ box.git(repo, 'commit', '-q', '-m', 'chore: configure agent worktree location');+ }++ // Leave the sibling on its older config to prove placement follows the current main checkout.+ box.env.PULLBOARD_MODEL = 'Worktree Location Model';+ const made = box.run(web, 'worktree', 'api', '--json');+ assert.equal(made.code, 0, made.err || made.out);+ const result = JSON.parse(made.out);+ const expected = mode === 'inside'+ ? join(repo, '.claude', 'worktrees', 'api-1')+ : join(dirname(repo), `${basename(repo)}-api-1`);+ assert.equal(resolve(result.path), resolve(expected), `${mode ?? 'omitted'} keeps its specified location`);+ assert.equal(box.git(repo, 'status', '--porcelain'), '', 'the nested worktree stays ignored by the main checkout');+ assert.equal(box.run(web, 'whoami', '--json').code, 0, 'the existing sibling remains usable');+ const newIdentity = box.run(result.path, 'whoami', '--json');+ assert.equal(newIdentity.code, 0, newIdentity.err || newIdentity.out);+ assert.equal(JSON.parse(newIdentity.out).lane, 'api');+ assert.ok(existsSync(join(result.path, '.githooks', 'pre-commit')), 'the new worktree has its commit hook');+ const resumed = box.run(web, 'resume');+ assert.equal(resumed.code, 0, resumed.err);+ assert.match(resumed.out, mode === 'inside'+ ? /New agent worktrees: .*\.claude\/worktrees\/<lane>-N/u+ : /New agent worktrees: .*repo-<lane>-N/u);+ const resumedJson = box.run(web, 'resume', '--json');+ assert.equal(JSON.parse(resumedJson.out).newWorktreeLocation, mode === 'inside'+ ? join(repo, '.claude', 'worktrees', '<lane>-N')+ : join(dirname(repo), `${basename(repo)}-<lane>-N`));+ assert.match(box.run(web, 'help', 'worktree').out, mode === 'inside'+ ? /Active worktree location: .*\.claude\/worktrees\/<lane>-N/u+ : /Active worktree location: .*repo-<lane>-N/u);+ }++ assert.deepEqual(configProblems({ ...defaults(), worktrees: 'inside' }), []);+ assert.deepEqual(configProblems({ ...defaults(), worktrees: 'beside' }), []);+ assert.ok(configProblems({ ...defaults(), worktrees: 'somewhere' }).some(problem => problem.includes('"worktrees"')));++ const box = sandbox();+ const repo = join(box.dir, 'separate-main');+ const gitDir = join(box.dir, 'separate-git-dir');+ mkdirSync(repo);+ box.git(repo, 'init', '-q', '-b', 'main', '--separate-git-dir', gitDir);+ assert.equal(box.run(repo, 'init').code, 0);+ const configPath = join(repo, 'pullboard.json');+ const config = JSON.parse(readFileSync(configPath, 'utf8'));+ config.lanes = { web: { owns: ['web/'], specs: [] }, api: { owns: ['api/'], specs: [] } };+ config.worktrees = 'inside';+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: configure separate git dir fixture');+ box.env.PULLBOARD_MODEL = 'Separate Git Dir Model';+ const made = box.run(repo, 'worktree', 'web', '--json');+ assert.equal(made.code, 0, made.err || made.out);+ const linkedPath = JSON.parse(made.out).path;+ assert.equal(resolve(linkedPath), resolve(repo, '.claude', 'worktrees', 'web-1'));+ const nestedMade = box.run(linkedPath, 'worktree', 'api', '--json');+ assert.equal(nestedMade.code, 0, nestedMade.err || nestedMade.out);+ assert.equal(resolve(JSON.parse(nestedMade.out).path), resolve(repo, '.claude', 'worktrees', 'api-1'),+ 'a linked checkout with a separate git dir resolves its registered main root');+ const registryPath = join(box.env.PULLBOARD_HOME, 'projects.json');+ const registryBytes = readFileSync(registryPath);+ const linkedResume = box.run(linkedPath, 'resume');+ assert.match(linkedResume.out, /New agent worktrees: .*\.claude\/worktrees\/<lane>-N/u);+ assert.deepEqual(readFileSync(registryPath), registryBytes, 'resume reads the registry without refreshing it');+ const linkedHelp = box.run(linkedPath, 'help', 'worktree');+ assert.match(linkedHelp.out, /Active worktree location: .*\.claude\/worktrees\/<lane>-N/u);+ assert.deepEqual(readFileSync(registryPath), registryBytes, 'help reads the registry without refreshing it');++ rmSync(registryPath);+ const missingRegistry = box.run(linkedPath, 'worktree', 'api', '--json');+ assert.notEqual(missingRegistry.code, 0);+ assert.equal(JSON.parse(missingRegistry.out).error.code, 'NO_POLICY', 'an unprovable primary root fails closed');+ assert.equal(existsSync(join(repo, '.claude', 'worktrees', 'api-2')), false, 'missing registry creates no worktree');+ assert.notEqual(box.tryGit(repo, 'show-ref', '--verify', '--quiet', 'refs/heads/api/2').status, 0,+ 'missing registry creates no branch');+ const missingResume = box.run(linkedPath, 'resume', '--json');+ assert.equal(missingResume.code, 0, missingResume.err || missingResume.out);+ assert.match(JSON.parse(missingResume.out).newWorktreeLocation, /^unavailable; run pullboard resume from the main checkout/u);+ assert.match(box.run(linkedPath, 'help', 'worktree').out,+ /Active worktree location: unavailable; run pullboard resume from the main checkout/u,+ 'help remains usable when the primary root is unprovable');+ assert.equal(existsSync(registryPath), false, 'read-only help and resume do not recreate a missing registry');++ writeFileSync(registryPath, registryBytes);+ writeFileSync(registryPath, '{not valid JSON');+ const malformedRegistry = box.run(linkedPath, 'worktree', 'web', '--json');+ assert.notEqual(malformedRegistry.code, 0);+ assert.equal(JSON.parse(malformedRegistry.out).error.code, 'NO_POLICY', 'a malformed registry cannot authorize a guessed sibling');+ assert.equal(existsSync(join(repo, '.claude', 'worktrees', 'web-2')), false, 'malformed registry creates no worktree');+ assert.notEqual(box.tryGit(repo, 'show-ref', '--verify', '--quiet', 'refs/heads/web/2').status, 0,+ 'malformed registry creates no branch');+ const malformedBytes = readFileSync(registryPath);+ const malformedResume = box.run(linkedPath, 'resume', '--json');+ assert.equal(malformedResume.code, 0, malformedResume.err || malformedResume.out);+ assert.match(JSON.parse(malformedResume.out).newWorktreeLocation, /^unavailable; run pullboard resume from the main checkout/u);+ assert.match(box.run(linkedPath, 'help', 'worktree').out,+ /Active worktree location: unavailable; run pullboard resume from the main checkout/u,+ 'help remains usable with a malformed registry');+ assert.deepEqual(readFileSync(registryPath), malformedBytes, 'read-only help and resume preserve malformed registry bytes');++ writeFileSync(registryPath, `${JSON.stringify({ projects: [] }, null, 2)}\n`);+ const emptyRegistry = box.run(linkedPath, 'worktree', 'api', '--json');+ assert.notEqual(emptyRegistry.code, 0);+ assert.equal(JSON.parse(emptyRegistry.out).error.code, 'NO_POLICY', 'a valid but unrelated registry is unprovable');+ assert.equal(existsSync(join(repo, '.claude', 'worktrees', 'api-2')), false, 'unrelated registry creates no worktree');+ assert.notEqual(box.tryGit(repo, 'show-ref', '--verify', '--quiet', 'refs/heads/api/2').status, 0,+ 'unrelated registry creates no branch');+ assert.equal(box.git(repo, 'status', '--porcelain'), '');+});