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): a worktree needs pullboard's files committed [I4,C4,N31]

Corey Olson243ffb26c371
diff --git a/docs/proof/run-mutants.mjs b/docs/proof/run-mutants.mjs
index d7633b47..c0a65c0f 100644
--- a/docs/proof/run-mutants.mjs
+++ b/docs/proof/run-mutants.mjs
@@ -1,7 +1,8 @@
/**
* The proof that one sentence to an agent starts the team (item #66): the run guide (N31), the
- * coordinator's resume (N32) and init's word to an agent (I9). Each change below removes one of
- * them, and its test must go red. The harness works on a temporary copy, never a real checkout.
+ * coordinator's resume (N32) and init's word to an agent (I9). And that the first worktree starts
+ * with pullboard's files, or says what to commit (item #69: I4, C4). Each change below removes one
+ * of them, and its test must go red. The harness works on a temporary copy, never a real checkout.
*
* Run it from the repo root: node docs/proof/run-mutants.mjs
*/
@@ -9,6 +10,8 @@ import { audit } from './harness.mjs';
const GUIDE = ['test/practice.test.js', 'the run guide takes one agent through the whole team'];
const STAGES = ['test/e2e.test.js', "the coordinator's resume names its next step"];
+const FIRST_WORKTREE = ['test/e2e.test.js', "a worktree starts only from a commit that holds pullboard's files"];
+const NO_INIT = ['test/e2e.test.js', 'a worktree whose commit has no pullboard.json is sent to the main checkout'];
/** Row, the change, its edits as [file, from, to], the test that judges it, and the outcome expected. */
const MUTANTS = [
@@ -22,6 +25,14 @@ const MUTANTS = [
['N32', 'verified work is never named for merging', [['src/cli.js', ' if (card.toMerge.length) {', ' if (false) {']], STAGES, 'red'],
['N32', 'open items get no builders', [['src/cli.js', ' if (card.open.length) {\n const lanes', ' if (false) {\n const lanes']], STAGES, 'red'],
['N32', 'approved rows no item cites are never planned', [['src/cli.js', ' if (unplanned.length) {', ' if (false) {']], STAGES, 'red'],
+ ['I4', "a worktree starts from a commit without pullboard's files", [['src/cli.js', ' refuseUncommittedSetup(mainRoot, ctx.config);\n', '']], FIRST_WORKTREE, 'red'],
+ ['I4', 'once there is a commit, a file changed since passes', [['src/cli.js', ' if (hasCommit && !differ.length) return;', ' if (hasCommit) return;']], FIRST_WORKTREE, 'red'],
+ ['I4', 'the hooks are left out', [['src/cli.js', ", ...(inEach ? [hooks] : [])]", ']']], FIRST_WORKTREE, 'red'],
+ ['I4', 'a file never added to git passes', [['src/git.js', " for (const path of listed(['ls-files', '-z', '--others', '--exclude-standard', '--', ...paths])) {", ' for (const path of []) {']], FIRST_WORKTREE, 'red'],
+ ['C4', 'a deleted file is called changed', [['src/git.js', "{ A: 'not committed', D: 'deleted' }", "{ A: 'not committed' }"]], FIRST_WORKTREE, 'red'],
+ ['C4', 'the command commits everything staged', [['src/cli.js', 'git commit -q -m "${subject}" -- ${words}`);', 'git commit -q -m "${subject}"`);']], FIRST_WORKTREE, 'red'],
+ ['C4', 'a worktree with no config is told to run init', [['src/cli.js', ' const config = configHere(info);', ' const config = loadConfig(info.root);']], NO_INIT, 'red'],
+ ['N31', 'the guide does not say to commit before the first worktree', [['skills/pullboard-run/SKILL.md', ' A worktree starts from the last commit, so first commit what init wrote, the spec and the lanes; `pullboard worktree` refuses until they are.', '']], GUIDE, 'red'],
['I9', 'init says nothing to an agent', [['src/cli.js', " io.say('with an agent: start a new Claude Code session here, which loads the pullboard skills, then tell it what to build; the pullboard-run skill runs the team');\n", '']], STAGES, 'red'],
];
diff --git a/skills/pullboard-run/SKILL.md b/skills/pullboard-run/SKILL.md
index 8781cc5d..252ebe94 100644
--- a/skills/pullboard-run/SKILL.md
+++ b/skills/pullboard-run/SKILL.md
@@ -12,7 +12,7 @@ You are the coordinator: the agent in the repo's main checkout. You talk with th
1. **Spec, with the person.** If SPEC.md has no rows for what they want, follow the pullboard-decompose skill: one question at a time, rows as drafts. Only the person approves a row. A yes relayed by another agent is not theirs.
2. **Lanes.** Builders can only commit inside their lane's folders. If `pullboard lanes` shows nothing that fits the work, propose lanes in pullboard.json to the person, plus a `review` lane that owns no folders. Commit them once agreed.
3. **Plan.** Follow the pullboard-plan skill, or give it to a subagent: one item per verifiable piece, in the lane that owns its files. Each has a criterion a stranger could check, and `--after` where one waits on another.
-4. **Build: one builder subagent per lane.** For each lane with open items, run `pullboard worktree <lane>` here in the main checkout. It makes the lane's worktree and prints the opening lines for its builder. Start a subagent with those lines and this task: "Run pullboard next. Build the item inside your lane's folders, commit citing its rows, and run pullboard submit. Repeat until pullboard next finds nothing. Report every refusal word for word." Lanes run side by side. A builder waiting on another lane takes other work, or waits with `pullboard next --wait 9`.
+4. **Build: one builder subagent per lane.** A worktree starts from the last commit, so first commit what init wrote, the spec and the lanes; `pullboard worktree` refuses until they are. For each lane with open items, run `pullboard worktree <lane>` here in the main checkout. It makes the lane's worktree and prints the opening lines for its builder. Start a subagent with those lines and this task: "Run pullboard next. Build the item inside your lane's folders, commit citing its rows, and run pullboard submit. Repeat until pullboard next finds nothing. Report every refusal word for word." Lanes run side by side. A builder waiting on another lane takes other work, or waits with `pullboard next --wait 9`.
5. **Verify: a subagent that built nothing.** Run `pullboard worktree review` once and start a subagent with its opening lines and this task: "Follow the pullboard-verify skill. Run pullboard next --verify, check out the commit it names, and prove or disprove the frozen criterion. Record the verdict. Repeat until nothing is left to verify." If another model family is available, such as Codex, let it verify: different families miss different things.
6. **Merge what is verified.** For each verified item, in the order verified:
- run `git merge --no-edit <its commit>` here;
diff --git a/src/cli.js b/src/cli.js
index 0c9542e2..f418a4b8 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -4,13 +4,13 @@
*/
import { spawn, spawnSync } from 'node:child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
-import { basename, dirname, join, resolve } from 'node:path';
+import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { parseArgs } from 'node:util';
import * as store from './board.js';
import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
import { digestOf, gateReport, runGate, runShell } from './gate.js';
-import { contains, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
+import { contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
import {
FIX_NOTE,
applyFixers,
@@ -299,11 +299,31 @@ function sayBrief(io, brief) {
*/
function context(io) {
const info = repoInfo(io.cwd);
- const config = loadConfig(info.root);
+ const config = configHere(info);
const file = join(info.commonDir, 'pullboard', 'board.sqlite');
return { info, config, file, io, clock: io.clock ?? store.systemClock };
}
+/**
+ * This checkout's config. A linked worktree with none, beside a main checkout that has one, was
+ * made from a commit that lacks pullboard's files, and init there would be the wrong fix (C4).
+ *
+ * @param {{ root: string, commonDir: string, isMain: boolean }} info
+ * @returns {any}
+ */
+function configHere(info) {
+ try {
+ return loadConfig(info.root);
+ } catch (error) {
+ const mainRoot = resolve(info.commonDir, '..');
+ if (!(error instanceof Refused) || error.code !== 'NO_CONFIG' || info.isMain || !existsSync(join(mainRoot, CONFIG_FILE))) throw error;
+ throw new Refused(
+ 'NO_CONFIG',
+ `this worktree's commit has no ${CONFIG_FILE}, though the main checkout has one: make a new worktree from the main checkout, which says what to commit first: ${cdTo(mainRoot)} pullboard worktree <lane>`,
+ );
+ }
+}
+
/**
* Open the board, run `work`, and always close it.
*
@@ -686,6 +706,7 @@ function worktreeFor(io, lane, route) {
throw new Refused('BAD_ROUTE', `route "${route}" is strong (needs a frontier model) or light (any model can build it from the brief)`);
}
const mainRoot = resolve(ctx.info.commonDir, '..');
+ refuseUncommittedSetup(mainRoot, ctx.config);
const pathFor = (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;
@@ -705,6 +726,44 @@ function worktreeFor(io, lane, route) {
return 0;
}
+/**
+ * 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
+ * inside each worktree.
+ *
+ * @param {string} mainRoot
+ * @param {any} config
+ * @returns {string[]}
+ */
+function setupFiles(mainRoot, config) {
+ const hooks = tryGit(mainRoot, ['config', '--get', 'core.hooksPath']).stdout;
+ const inEach = hooks && !isAbsolute(hooks) && !relative(mainRoot, resolve(mainRoot, hooks)).startsWith('..');
+ return [CONFIG_FILE, config.spec, config.practice, 'AGENTS.md', ...(inEach ? [hooks] : [])].filter(Boolean);
+}
+
+/**
+ * Refuse a worktree whose agent would start without pullboard's files as the main checkout has
+ * them: no config, rules or hooks, or older ones (I4). Name each file and how it differs, and the
+ * command that commits just those (C4).
+ *
+ * @param {string} mainRoot
+ * @param {any} config
+ */
+function refuseUncommittedSetup(mainRoot, config) {
+ const files = setupFiles(mainRoot, config);
+ const hasCommit = headCommit(mainRoot) !== null;
+ let differ = differFromHead(mainRoot, files);
+ if (hasCommit && !differ.length) return;
+ // With no commit, a file git ignores still has to be committed; git add will name the ignore.
+ if (!differ.length) differ = files.filter((path) => existsSync(join(mainRoot, path))).map((path) => ({ path, how: 'not committed' }));
+ const why = hasCommit
+ ? `a new worktree starts from the last commit, and these differ from it here: ${differ.map(({ path, how }) => `${path} (${how})`).join(', ')}`
+ : `this repo has no commit yet, and a new worktree starts from one; not committed: ${differ.map(({ path }) => path).join(', ')}`;
+ const words = differ.map(({ path }) => shellWord(path)).join(' ');
+ const subject = hasCommit ? 'chore: commit pullboard files' : 'chore: set up pullboard';
+ throw new Refused('NOT_COMMITTED', `${why}. Commit them first: ${cdTo(mainRoot)} git add -- ${words} && git commit -q -m "${subject}" -- ${words}`);
+}
+
/**
* The commands that read the board without changing it.
*
diff --git a/src/git.js b/src/git.js
index ec617df3..ec06adfd 100644
--- a/src/git.js
+++ b/src/git.js
@@ -98,6 +98,30 @@ export function isClean(root) {
return git(root, ['status', '--porcelain', '--untracked-files=no']) === '';
}
+/**
+ * How each file under `paths` in the work tree differs from HEAD, whatever is staged: not
+ * committed, changed or deleted. With no commits yet, every file there is not committed.
+ * Read-only: git takes no index lock.
+ *
+ * @param {string} root
+ * @param {string[]} paths
+ * @returns {{ path: string, how: string }[]}
+ */
+export function differFromHead(root, paths) {
+ const listed = (args, input) =>
+ execFileSync('git', ['--no-optional-locks', ...GIT_FLAGS, ...args], { cwd: root, encoding: 'utf8', input: input ?? '' }).split('\0').filter(Boolean);
+ const base = headCommit(root) ?? listed(['hash-object', '-t', 'tree', '--stdin'])[0].trim();
+ const fields = listed(['diff', '--no-renames', '--name-status', '-z', base, '--', ...paths]);
+ const found = [];
+ for (let i = 0; i + 1 < fields.length; i += 2) {
+ found.push({ path: fields[i + 1], how: { A: 'not committed', D: 'deleted' }[fields[i]] ?? 'changed' });
+ }
+ for (const path of listed(['ls-files', '-z', '--others', '--exclude-standard', '--', ...paths])) {
+ found.push({ path, how: 'not committed' });
+ }
+ return found.sort((a, b) => (a.path < b.path ? -1 : 1));
+}
+
/**
* Files git would show as untracked: new, and not ignored.
*
diff --git a/test/e2e.test.js b/test/e2e.test.js
index 4e3a2aff..10330b05 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -303,6 +303,92 @@ test('pullboard worktree makes a joined worktree for a lane in one command [I4]'
assert.match(box.run(box.repo, 'worktree', 'nope').err, /NO_LANE/);
});
+test("a worktree starts only from a commit that holds pullboard's files as the main checkout has them [I4, C4]", () => {
+ const box = sandbox();
+ const repo = join(box.dir, 'repo');
+ mkdirSync(repo);
+ box.git(repo, 'init', '-q', '-b', 'main');
+ assert.equal(box.run(repo, 'init').code, 0);
+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(CONFIG, null, 2));
+ writeFileSync(join(repo, 'SPEC.md'), SPEC);
+ writeFileSync(join(repo, 'notes.txt'), 'mine\n');
+ const nothingMade = () => {
+ assert.ok(!existsSync(join(box.dir, 'repo-web-1')), 'no folder');
+ assert.notEqual(box.tryGit(repo, 'rev-parse', '--verify', '--quiet', 'refs/heads/web/1').status, 0, 'no branch');
+ };
+ /** Refused, with the files it names; returns the command it gives. */
+ const refused = (pattern, named) => {
+ const said = box.run(repo, 'worktree', 'web');
+ assert.equal(said.code, 1, said.out);
+ assert.match(said.err, pattern);
+ for (const file of named) assert.ok(said.err.includes(file), `names ${file}: ${said.err}`);
+ assert.ok(!said.err.includes('notes.txt'), 'leaves the person\'s own files out');
+ nothingMade();
+ const [, command] = said.err.match(/Commit them first: (.*)\n/);
+ assert.ok(command.startsWith(`cd ${repo} && git add -- `), command);
+ return command;
+ };
+ const sh = (command) => execFileSync('sh', ['-c', command], { env: box.env, encoding: 'utf8', stdio: 'pipe' });
+
+ const first = refused(/\[NOT_COMMITTED\] this repo has no commit yet, and a new worktree starts from one; not committed: /, [
+ '.githooks/pre-commit',
+ 'AGENTS.md',
+ 'PRACTICE.md',
+ 'SPEC.md',
+ 'pullboard.json',
+ ]);
+ sh(first);
+ for (const file of ['.githooks/pre-commit', 'AGENTS.md', 'PRACTICE.md', 'SPEC.md', 'pullboard.json']) {
+ assert.equal(box.git(repo, 'ls-tree', '--name-only', 'HEAD', '--', file), file, `${file} is committed`);
+ }
+ assert.equal(box.git(repo, 'ls-tree', '--name-only', 'HEAD', '--', 'notes.txt'), '', 'the command commits only those files');
+
+ writeFileSync(join(repo, 'SPEC.md'), `${SPEC}- G3 [draft, aim] A third goal. | gate: test\n`);
+ writeFileSync(join(repo, '.githooks', 'post-checkout'), '#!/bin/sh\n');
+ rmSync(join(repo, 'PRACTICE.md'));
+ box.git(repo, 'add', 'notes.txt');
+ refused(/\[NOT_COMMITTED\] a new worktree starts from the last commit, and these differ from it here: /, [
+ '.githooks/post-checkout (not committed)',
+ 'PRACTICE.md (deleted)',
+ 'SPEC.md (changed)',
+ ]);
+ box.git(repo, 'checkout', '--', 'PRACTICE.md');
+ sh(refused(/these differ from it here: \.githooks\/post-checkout \(not committed\), SPEC\.md \(changed\)\. /, []));
+ assert.equal(box.git(repo, 'diff', '--cached', '--name-only'), 'notes.txt', "the person's staged file stays staged, and out of the commit");
+
+ const made = box.run(repo, 'worktree', 'web');
+ assert.equal(made.code, 0, made.err);
+ assert.match(made.out, /repo-web-1 on branch web\/1, joined as web-1 in the web lane/, 'the refusals made nothing and joined no one');
+ const web = join(box.dir, 'repo-web-1');
+ assert.ok(readFileSync(join(web, 'SPEC.md'), 'utf8').includes('- G3 [draft'), 'it starts with the spec as committed');
+ const foreign = commitFile(box, web, 'api/a.js', 'a', 'feat(web): page [G1]');
+ assert.match(foreign.stderr, /outside the web lane: api\/a.js/, 'its hooks run');
+});
+
+test('a worktree whose commit has no pullboard.json is sent to the main checkout, never told to run init [C4]', () => {
+ const box = sandbox();
+ const repo = join(box.dir, 'repo');
+ mkdirSync(repo);
+ box.git(repo, 'init', '-q', '-b', 'main');
+ writeFileSync(join(repo, 'README.md'), '# app\n');
+ box.git(repo, 'add', 'README.md');
+ box.git(repo, 'commit', '-q', '-m', 'docs: readme');
+ assert.equal(box.run(repo, 'init').code, 0);
+ const old = join(box.dir, 'old');
+ box.git(repo, 'worktree', 'add', '-q', '--detach', old, 'HEAD');
+ for (const command of [['next'], ['status'], ['join', 'web']]) {
+ const said = box.run(old, ...command);
+ assert.equal(said.code, 1, said.out);
+ assert.match(said.err, /\[NO_CONFIG\] this worktree's commit has no pullboard\.json, though the main checkout has one: /);
+ assert.ok(said.err.includes(`which says what to commit first: cd ${repo} && pullboard worktree <lane>`), said.err);
+ assert.ok(!said.err.includes('pullboard init'), `${command[0]} never says to run init`);
+ }
+ const plain = join(box.dir, 'plain');
+ mkdirSync(plain);
+ box.git(plain, 'init', '-q');
+ assert.match(box.run(plain, 'next').err, /\[NO_CONFIG\] no pullboard\.json in .*; run: pullboard init/, 'a repo with no pullboard is still told to init');
+});
+
test('a red gate refuses submit [V4]', () => {
const box = project();
writeFileSync(join(box.repo, 'RED'), 'red');
diff --git a/test/practice.test.js b/test/practice.test.js
index e0e5d614..36cb4ea8 100644
--- a/test/practice.test.js
+++ b/test/practice.test.js
@@ -41,6 +41,7 @@ test('the run guide takes one agent through the whole team, and init installs it
]) {
assert.ok(guide.includes(step), `the run guide says: ${step}`);
}
+ assert.match(guide, /\*\*Build[^\n]*A worktree starts from the last commit, so first commit what init wrote, the spec and the lanes/, 'the build step commits the setup before the first worktree');
assert.match(installSkills(root)[0], /pullboard-run/);
assert.ok(existsSync(join(root, '.claude', 'skills', 'pullboard-run', 'SKILL.md')), 'init installs it as a skill');
assert.match(agentsBlock(), /pullboard prompt run/, 'AGENTS.md names it');