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(hooks): admit accepted main merge files [H16,B26]
Corey Olson5f5b8b0f9fea
diff --git a/src/cli.js b/src/cli.jsindex 6ba39bf2..4003c5e3 100644--- a/src/cli.js+++ b/src/cli.js@@ -4294,7 +4294,7 @@ async function hookCommand(io, { first, second }) {const landing = hookRead(ctx, (board) => store.landingBatches(board).some((batch) => batch.root === info.root && !['landed', 'blocked'].includes(batch.state)));if (landing) io.caller('coordinator', info.root);else if (agent) io.caller('seat', info.root);- problems = preCommitProblems({ root: info.root, isMain: info.isMain || landing, config: ctx.config, agent, boardFile: ctx.file });+ problems = preCommitProblems({ root: info.root, isMain: info.isMain || landing, config: ctx.config, agent, boardFile: ctx.file, preMergeHook: first === 'pre-merge-commit' });} else if (first === 'commit-msg') {const message = readFileSync(second ?? '', 'utf8');const spec = loadSpec(info.root, ctx.config);diff --git a/src/hooks.js b/src/hooks.jsindex e2903e81..12bc7458 100644--- a/src/hooks.js+++ b/src/hooks.js@@ -251,10 +251,10 @@ export function blockedPaths(paths, protect) {* changes outside its folders. The main checkout is the coordinator's and may change anything; any* other worktree must have joined a lane.*- * @param {{ root: string, isMain: boolean, config: any, agent: any, boardFile?: string }} context+ * @param {{ root: string, isMain: boolean, config: any, agent: any, boardFile?: string, preMergeHook?: boolean }} context* @returns {string[]}*/-export function preCommitProblems({ root, isMain, config, agent, boardFile }) {+export function preCommitProblems({ root, isMain, config, agent, boardFile, preMergeHook = false }) {if (!isMain) refuseGrafts(root);const { touched, written } = stagedPaths(root);const problems = blockedPaths(written, config.protect).map(@@ -277,11 +277,11 @@ export function preCommitProblems({ root, isMain, config, agent, boardFile }) {problems.push('this worktree has not joined a lane: pullboard join <lane> --model "<model name>"');return problems;}- const mergeBase = mainMergeBase(root);+ const mergeHeads = mainMergeHeads(root, preMergeHook);const ownershipConfig = committedLaneConfig(root);- const ownershipTouched = mergeBase- ? [...new Set([...touched, ...stagedPaths(root, mergeBase).touched])]- .filter((path) => !outOfLane(ownershipConfig, agent.agent_lane, [path]).length || !unchangedMergePath(root, path, mergeBase))+ const ownershipTouched = mergeHeads+ ? [...new Set([...touched, ...mergeHeads.flatMap((mergeHead) => stagedPaths(root, mergeHead).touched)])]+ .filter((path) => !outOfLane(ownershipConfig, agent.agent_lane, [path]).length || !unchangedMergePath(root, path, mergeHeads)): touched;const foreign = outOfLane(ownershipConfig, agent.agent_lane, ownershipTouched);problems.push(@@ -430,24 +430,37 @@ export function unwiredHookProblems(root) {}/**- * The commit being merged, only when it is already part of the primary checkout's history.+ * Validate incoming commit candidates against primary main, using Git's pre-MERGE_HEAD inputs only+ * for the merge hook; GITHEAD is ordinary environment data, not proof of who invoked this hook.** @param {string} root- * @returns {string | null}+ * @param {boolean} preMergeHook Whether the CLI was invoked for pre-merge-commit.+ * @returns {string[] | null}*/-function mainMergeBase(root) {+function mainMergeHeads(root, preMergeHook) {const gitPath = tryGit(root, ['rev-parse', '--git-path', 'MERGE_HEAD']);if (gitPath.status !== 0) return null;- let merge;- try { merge = readFileSync(resolve(root, gitPath.stdout.trim()), 'utf8').split(/\r?\n/u, 1)[0]; } catch { return null; }- if (!/^[0-9a-f]{40}$/i.test(merge ?? '')) return null;- if (tryGit(root, ['cat-file', '-e', `${merge}^{commit}`]).status !== 0) return null;- if (tryGit(root, ['merge-base', '--is-ancestor', merge, 'HEAD']).status === 0) return null;+ let merges;+ const mergeFile = resolve(root, gitPath.stdout.trim());+ try {+ if (existsSync(mergeFile)) merges = readFileSync(mergeFile, 'utf8').split(/\r?\n/u).filter(Boolean);+ else if (preMergeHook) {+ const names = Object.keys(process.env).filter((name) => name.startsWith('GITHEAD_'));+ if (names.some((name) => !/^GITHEAD_(?:[0-9a-f]{40}|[0-9a-f]{64})$/iu.test(name))) return null;+ merges = names.map((name) => name.slice('GITHEAD_'.length));+ } else return null;+ } catch { return null; }+ if (!merges.length || merges.some((merge) => !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/iu.test(merge))) return null;+ merges = [...new Set(merges)];+ for (const merge of merges) {+ if (tryGit(root, ['cat-file', '-e', `${merge}^{commit}`]).status !== 0) return null;+ if (tryGit(root, ['merge-base', '--is-ancestor', merge, 'HEAD']).status !== 1) return null;+ }let main;try { main = mainCheckout(root)?.commit; } catch { return null; }if (!main) return null;- return tryGit(root, ['merge-base', '--is-ancestor', merge, main]).status === 0- ? merge+ return merges.every((merge) => tryGit(root, ['merge-base', '--is-ancestor', merge, main]).status === 0)+ ? merges: null;}@@ -473,9 +486,9 @@ function committedObject(root, commit, path) {}/** Main integration may preserve either parent's exact foreign object; a new resolution remains lane-owned. */-function unchangedMergePath(root, path, mergeBase) {+function unchangedMergePath(root, path, mergeHeads) {const staged = stagedObject(root, path);- return staged !== null && (staged === committedObject(root, mergeBase, path) || staged === committedObject(root, 'HEAD', path));+ return staged !== null && (mergeHeads.some((mergeHead) => staged === committedObject(root, mergeHead, path)) || staged === committedObject(root, 'HEAD', path));}/**diff --git a/test/merge-hooks.test.js b/test/merge-hooks.test.jsindex e7426e44..28fdfcf9 100644--- a/test/merge-hooks.test.js+++ b/test/merge-hooks.test.js@@ -1,7 +1,7 @@-/** Real merge indexes prove exact foreign-object preservation without weakening lane ownership [L3]. */+/** Real merge hooks prove main integration without weakening lane ownership [L3,H16,B26]. */import assert from 'node:assert/strict';import { runFixtureChild, runFixtureGit } from './fixture-child.js';-import { chmodSync, mkdirSync, mkdtempSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { test } from 'node:test';@@ -265,3 +265,79 @@ test('installed pre-commit matches an exact foreign path during a merge [L3]', (assert.notEqual(result.status, 0, 'the owned child path cannot impersonate its foreign parent path');assert.match(result.stderr, /outside the core lane: view\/file/u);});++test("merging main brings in main's own changes outside the lane [H16,B26]", (t) => {+ const box = nativeFixture(t);+ writeFileSync(join(box.lane, 'core', 'file'), 'lane core\n');+ let result = box.git(box.lane, 'add', '-A');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.lane, 'feat(core): update owned file [L3]');+ assert.equal(result.status, 0, result.stderr);++ const mainConfig = { ...box.config, lease: '3h' };+ writeFileSync(join(box.main, 'pullboard.json'), JSON.stringify(mainConfig, null, 2));+ result = box.git(box.main, 'add', 'pullboard.json');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.main, 'chore: update main policy');+ assert.equal(result.status, 0, result.stderr);++ result = box.git(box.lane, 'merge', '--no-edit', 'main');+ assert.equal(result.status, 0, result.stderr);+ assert.equal(box.git(box.lane, 'rev-parse', '--verify', 'HEAD^2').status, 0,+ 'the automatic merge completed and created a merge commit');+ assert.deepEqual(JSON.parse(readFileSync(join(box.lane, 'pullboard.json'), 'utf8')), mainConfig,+ 'the exact policy change from main is present in the lane checkout');+});++test('an inherited main candidate cannot authorize an automatic merge from an unaccepted branch [H16,B26]', (t) => {+ const box = nativeFixture(t);+ writeFileSync(join(box.lane, 'core', 'file'), 'lane core\n');+ let result = box.git(box.lane, 'add', '-A');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.lane, 'feat(core): update owned file [L3]');+ assert.equal(result.status, 0, result.stderr);++ result = box.git(box.main, 'switch', '-c', 'unaccepted');+ assert.equal(result.status, 0, result.stderr);+ writeFileSync(join(box.main, 'view', 'file'), 'unaccepted foreign\n');+ result = box.git(box.main, 'add', 'view/file');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.main, 'chore: change a foreign file');+ assert.equal(result.status, 0, result.stderr);++ result = box.git(box.main, 'switch', 'main');+ assert.equal(result.status, 0, result.stderr);+ const mainConfig = { ...box.config, lease: '3h' };+ writeFileSync(join(box.main, 'pullboard.json'), JSON.stringify(mainConfig, null, 2));+ result = box.git(box.main, 'add', 'pullboard.json');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.main, 'chore: update main policy');+ assert.equal(result.status, 0, result.stderr);+ const mainHead = box.git(box.main, 'rev-parse', 'HEAD').stdout.trim();+ box.env[`GITHEAD_${mainHead}`] = 'main';++ result = box.git(box.lane, 'merge', '--no-edit', 'unaccepted');+ assert.notEqual(result.status, 0, 'the lane hook refuses the real unaccepted merge head');+ assert.match(result.stderr, /outside the core lane: view\/file/u);+ assert.notEqual(box.git(box.lane, 'rev-parse', '--verify', 'HEAD^2').status, 0,+ 'the refused merge did not create a merge commit');+});++test('an inherited main candidate cannot authorize an ordinary foreign commit [H16,B26]', (t) => {+ const box = nativeFixture(t);+ const mainConfig = { ...box.config, lease: '3h' };+ writeFileSync(join(box.main, 'pullboard.json'), JSON.stringify(mainConfig, null, 2));+ let result = box.git(box.main, 'add', 'pullboard.json');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.main, 'chore: update main policy');+ assert.equal(result.status, 0, result.stderr);+ const mainHead = box.git(box.main, 'rev-parse', 'HEAD').stdout.trim();+ box.env[`GITHEAD_${mainHead}`] = 'main';++ writeFileSync(join(box.lane, 'view', 'file'), 'sneaked foreign edit\n');+ result = box.git(box.lane, 'add', 'view/file');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.lane, 'chore: stage a foreign edit');+ assert.notEqual(result.status, 0, 'the ordinary pre-commit hook ignores GITHEAD candidates');+ assert.match(result.stderr, /outside the core lane: view\/file/u);+});