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
fix(cli): ignored hooks and a deleted config, named [I4,C4]
Corey Olsonbc03055c2851
diff --git a/docs/proof/run-mutants.mjs b/docs/proof/run-mutants.mjsindex c0a65c0f..8c25be8b 100644--- a/docs/proof/run-mutants.mjs+++ b/docs/proof/run-mutants.mjs@@ -12,6 +12,7 @@ const GUIDE = ['test/practice.test.js', 'the run guide takes one agent through tconst 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'];+const IGNORED_OR_DELETED = ['test/e2e.test.js', 'a hook git ignores is committed by force before a worktree'];/** Row, the change, its edits as [file, from, to], the test that judges it, and the outcome expected. */const MUTANTS = [@@ -31,6 +32,9 @@ const MUTANTS = [['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'],+ ['I4', 'a hook git ignores passes', [['src/git.js', " for (const path of listed(['ls-files', '-z', '--others', '--ignored', '--exclude-standard', '--', ...paths])) {", ' for (const path of []) {']], IGNORED_OR_DELETED, 'red'],+ ['C4', 'a file git ignores is not added by force', [['src/cli.js', " const force = differ.some(({ ignored }) => ignored) ? ' -f' : '';", " const force = '';"]], IGNORED_OR_DELETED, 'red'],+ ['C4', 'a deleted config is sent to init', [['src/cli.js', " if (tryGit(info.root, ['cat-file', '-e', `HEAD:${CONFIG_FILE}`]).status === 0) {", ' if (false) {']], IGNORED_OR_DELETED, '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/src/cli.js b/src/cli.jsindex f418a4b8..54f97891 100644--- a/src/cli.js+++ b/src/cli.js@@ -305,8 +305,9 @@ function context(io) {}/**- * 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).+ * This checkout's config. Init is the fix only where pullboard never was (C4): a config deleted+ * from a checkout whose last commit has it is restored, and a linked worktree made from a commit+ * that lacks it, beside a main checkout that has one, is made again from there.** @param {{ root: string, commonDir: string, isMain: boolean }} info* @returns {any}@@ -315,8 +316,12 @@ function configHere(info) {try {return loadConfig(info.root);} catch (error) {+ if (!(error instanceof Refused) || error.code !== 'NO_CONFIG') throw error;+ if (tryGit(info.root, ['cat-file', '-e', `HEAD:${CONFIG_FILE}`]).status === 0) {+ throw new Refused('NO_CONFIG', `${CONFIG_FILE} is deleted here, though this checkout's last commit has it: restore it: ${cdTo(info.root)} git checkout HEAD -- ${CONFIG_FILE}`);+ }const mainRoot = resolve(info.commonDir, '..');- if (!(error instanceof Refused) || error.code !== 'NO_CONFIG' || info.isMain || !existsSync(join(mainRoot, CONFIG_FILE))) throw error;+ if (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>`,@@ -750,18 +755,17 @@ function setupFiles(mainRoot, config) {* @param {any} config*/function refuseUncommittedSetup(mainRoot, config) {- const files = setupFiles(mainRoot, config);const hasCommit = headCommit(mainRoot) !== null;- let differ = differFromHead(mainRoot, files);+ const differ = differFromHead(mainRoot, setupFiles(mainRoot, config));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(', ')}`;+ : `this repo has no commit yet, and a new worktree starts from one; not committed: ${differ.map(({ path, ignored }) => (ignored ? `${path} (git ignores it)` : path)).join(', ')}`;const words = differ.map(({ path }) => shellWord(path)).join(' ');+ // No commit holds a file git ignores unless it is added by force.+ const force = differ.some(({ ignored }) => ignored) ? ' -f' : '';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}`);+ throw new Refused('NOT_COMMITTED', `${why}. Commit them first: ${cdTo(mainRoot)} git add${force} -- ${words} && git commit -q -m "${subject}" -- ${words}`);}/**diff --git a/src/git.js b/src/git.jsindex ec06adfd..824df135 100644--- a/src/git.js+++ b/src/git.js@@ -100,24 +100,27 @@ export function isClean(root) {/*** 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.+ * committed, changed or deleted. A file git ignores counts too, marked, since no commit holds it.+ * 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 }[]}+ * @returns {{ path: string, how: string, ignored: boolean }[]}*/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 listed = (args) =>+ execFileSync('git', ['--no-optional-locks', ...GIT_FLAGS, ...args], { cwd: root, encoding: 'utf8', 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' });+ found.push({ path: fields[i + 1], how: { A: 'not committed', D: 'deleted' }[fields[i]] ?? 'changed', ignored: false });}for (const path of listed(['ls-files', '-z', '--others', '--exclude-standard', '--', ...paths])) {- found.push({ path, how: 'not committed' });+ found.push({ path, how: 'not committed', ignored: false });+ }+ for (const path of listed(['ls-files', '-z', '--others', '--ignored', '--exclude-standard', '--', ...paths])) {+ found.push({ path, how: 'not committed; git ignores it', ignored: true });}return found.sort((a, b) => (a.path < b.path ? -1 : 1));}diff --git a/test/e2e.test.js b/test/e2e.test.jsindex 10330b05..922ed956 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -365,6 +365,40 @@ test("a worktree starts only from a commit that holds pullboard's files as the massert.match(foreign.stderr, /outside the web lane: api\/a.js/, 'its hooks run');});+test('a hook git ignores is committed by force before a worktree; a deleted config is restored, never re-initialized [I4, C4]', () => {+ const box = project();+ const sh = (command) => execFileSync('sh', ['-c', command], { env: box.env, encoding: 'utf8', stdio: 'pipe' });+ writeFileSync(join(box.repo, '.gitignore'), '.githooks/post-checkout\n');+ box.git(box.repo, 'add', '.gitignore');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: ignore a local hook');+ writeFileSync(join(box.repo, '.githooks', 'post-checkout'), '#!/bin/sh\n');+ const ignored = box.run(box.repo, 'worktree', 'web');+ assert.equal(ignored.code, 1, ignored.out);+ assert.match(ignored.err, /\[NOT_COMMITTED\] a new worktree starts from the last commit, and these differ from it here: \.githooks\/post-checkout \(not committed; git ignores it\)\. /);+ assert.ok(!existsSync(join(box.dir, 'repo-web-1')), 'no folder');+ const [, command] = ignored.err.match(/Commit them first: (.*)\n/);+ assert.ok(command.includes(' && git add -f -- .githooks/post-checkout && git commit '), command);+ sh(command);+ assert.equal(box.git(box.repo, 'ls-tree', '--name-only', 'HEAD', '--', '.githooks/post-checkout'), '.githooks/post-checkout', 'the ignored hook is committed');+ const made = box.run(box.repo, 'worktree', 'web');+ assert.equal(made.code, 0, made.err);+ assert.ok(existsSync(join(box.dir, 'repo-web-1', '.githooks', 'post-checkout')), 'the worktree has the hook the main checkout runs');++ box.git(box.repo, 'rm', '-q', 'pullboard.json');+ const restore = `cd ${box.repo} && git checkout HEAD -- pullboard.json`;+ for (const args of [['worktree', 'web'], ['status'], ['next']]) {+ const said = box.run(box.repo, ...args);+ assert.equal(said.code, 1, said.out);+ assert.ok(said.err.includes(`[NO_CONFIG] pullboard.json is deleted here, though this checkout's last commit has it: restore it: ${restore}\n`), said.err);+ assert.ok(!said.err.includes('pullboard init'), `${args[0]} never says to run init`);+ }+ assert.ok(!existsSync(join(box.dir, 'repo-web-2')), 'the refused worktree made nothing');+ sh(restore);+ assert.equal(box.run(box.repo, 'status').code, 0, 'restored, the board works again');+ rmSync(join(box.web, 'pullboard.json'));+ assert.ok(box.run(box.web, 'next').err.includes(`restore it: cd ${box.web} && git checkout HEAD -- pullboard.json`), 'a linked worktree restores its own');+});+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');