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): allow accepted main conflict resolution [H16,B26]
Corey Olsonc063141688f1
diff --git a/src/cli.js b/src/cli.jsindex cca99e44..820e2092 100644--- a/src/cli.js+++ b/src/cli.js@@ -4293,7 +4293,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, preMergeHook: first === 'pre-merge-commit' });+ problems = preCommitProblems({ root: info.root, isMain: info.isMain || landing, config: ctx.config, agent, boardFile: ctx.file, preMergeHook: first === 'pre-merge-commit', onNotice: (message) => io.err(`pullboard pre-commit: warning: ${message}`) });} 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 12bc7458..b9e23dda 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, preMergeHook?: boolean }} context+ * @param {{ root: string, isMain: boolean, config: any, agent: any, boardFile?: string, preMergeHook?: boolean, onNotice?: (message: string) => void }} context* @returns {string[]}*/-export function preCommitProblems({ root, isMain, config, agent, boardFile, preMergeHook = false }) {+export function preCommitProblems({ root, isMain, config, agent, boardFile, preMergeHook = false, onNotice }) {if (!isMain) refuseGrafts(root);const { touched, written } = stagedPaths(root);const problems = blockedPaths(written, config.protect).map(@@ -283,9 +283,15 @@ export function preCommitProblems({ root, isMain, config, agent, boardFile, preM? [...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);+ const foreignPaths = ownershipTouched.filter((path) => outOfLane(ownershipConfig, agent.agent_lane, [path]).length);+ const resolved = mergeHeads && !preMergeHook+ ? foreignPaths.filter((path) => resolvedMergeConflictPath(root, path, mergeHeads))+ : [];+ resolved.forEach((path) => onNotice?.(`resolved accepted-main conflict in ${path}; the coordinator owns ${path}`));problems.push(- ...foreign.map((path) => `outside the ${agent.agent_lane} lane: ${path}; shout its owner instead`),+ ...foreignPaths.filter((path) => !resolved.includes(path))+ .flatMap((path) => outOfLane(ownershipConfig, agent.agent_lane, [path]))+ .map((path) => `outside the ${agent.agent_lane} lane: ${path}; shout its owner instead`),);return problems;}@@ -485,12 +491,47 @@ function committedObject(root, commit, path) {return fields ? fields[1] + ' ' + fields[2] : null;}-/** Main integration may preserve either parent's exact foreign object; a new resolution remains lane-owned. */+/** Main integration may preserve either parent's exact foreign object. */function unchangedMergePath(root, path, mergeHeads) {const staged = stagedObject(root, path);return staged !== null && (mergeHeads.some((mergeHead) => staged === committedObject(root, mergeHead, path)) || staged === committedObject(root, 'HEAD', path));}+/** Allow a new foreign object only when Git records both exact parents in the resolved conflict index. */+function resolvedMergeConflictPath(root, path, mergeHeads) {+ const staged = stagedObject(root, path);+ if (!staged) return false;+ const records = git(root, ['ls-files', '--resolve-undo', '--stage', '-z', '--', ':(literal)' + path])+ .split('\0').filter(Boolean);+ const stages = new Map();+ for (const record of records) {+ const separator = record.indexOf('\t');+ if (separator === -1 || record.slice(separator + 1) !== path) continue;+ const fields = /^(\d{6}) ([0-9a-f]{40,64}) ([0123])$/iu.exec(record.slice(0, separator));+ if (fields?.[3] === '0') {+ if (fields[1] + ' ' + fields[2] !== staged) return false;+ continue;+ }+ if (!fields || stages.has(fields[3])) return false;+ stages.set(fields[3], fields[1] + ' ' + fields[2]);+ }+ const bases = mergeHeads.flatMap((mergeHead) => {+ const result = tryGit(root, ['merge-base', '--all', 'HEAD', mergeHead]);+ return result.status === 0 ? result.stdout.trim().split(/\r?\n/u).filter(Boolean) : [];+ });+ if (!bases.length) return false;+ const baseStage = stages.get('1');+ const hasBaseProvenance = baseStage+ ? bases.some((base) => baseStage === committedObject(root, base, path))+ : bases.every((base) => committedObject(root, base, path) === '');+ const stagedMode = staged.split(' ', 1)[0];+ const parentModes = [stages.get('2'), stages.get('3')].filter(Boolean).map((entry) => entry.split(' ', 1)[0]);+ return hasBaseProvenance+ && stages.get('2') === committedObject(root, 'HEAD', path)+ && mergeHeads.some((mergeHead) => stages.get('3') === committedObject(root, mergeHead, path))+ && parentModes.includes(stagedMode);+}+/*** A path quoted for the shell, whatever characters it holds.*diff --git a/test/merge-hooks.test.js b/test/merge-hooks.test.jsindex 28fdfcf9..fa2c16e6 100644--- a/test/merge-hooks.test.js+++ b/test/merge-hooks.test.js@@ -89,6 +89,41 @@ function nativeCommit(box, cwd, message = 'test: native fixture commit') {return box.git(cwd, 'commit', '-m', message);}+/** Stage a real conflict between coordinator-authored policy versions after the lane joins. */+function stagedCoordinatorPolicyConflict(t) {+ const box = nativeFixture(t);+ let result = box.git(box.main, 'switch', '-c', 'historical-policy');+ assert.equal(result.status, 0, result.stderr);+ const historicalConfig = { ...box.config, lease: '3h' };+ writeFileSync(join(box.main, 'pullboard.json'), JSON.stringify(historicalConfig, null, 2));+ result = box.git(box.main, 'add', 'pullboard.json');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.main, 'chore: retain historical coordinator policy');+ assert.equal(result.status, 0, result.stderr);+ result = box.git(box.lane, 'reset', '--hard', 'historical-policy');+ 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: '4h' };+ 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 accepted coordinator policy');+ assert.equal(result.status, 0, result.stderr);+ const mainHead = box.git(box.main, 'rev-parse', 'HEAD').stdout.trim();++ result = box.git(box.lane, 'merge', '--no-edit', 'main');+ assert.equal(result.status, 1, 'the fixture must create a real policy conflict');+ assert.match(result.stdout + result.stderr, /CONFLICT.*pullboard\.json/u);+ assert.match(box.git(box.lane, 'ls-files', '--unmerged').stdout, /pullboard\.json/u);+ const resolvedConfig = { ...box.config, lease: '5h' };+ writeFileSync(join(box.lane, 'pullboard.json'), JSON.stringify(resolvedConfig, null, 2));+ result = box.git(box.lane, 'add', 'pullboard.json');+ assert.equal(result.status, 0);+ return { box, mainHead };+}+/** Commit one lane-owned edit and one main-owned edit to force a real pending merge. */function diverge(box, { conflict = false } = {}) {writeFileSync(join(box.lane, 'core', 'file'), 'lane core\n');@@ -128,7 +163,7 @@ test('owned conflict resolutions commit while foreign edits and mode changes rem'an unchanged blob does not authorize a different executable mode');});-test('a foreign resolution identical to HEAD is allowed, including literal odd filenames [L3]', (t) => {+test('an accepted-main conflict permits a foreign resolution, including literal odd filenames [L3,H16,B26]', (t) => {const box = fixture(t);const path = 'view/literal [x] \n file';writeFileSync(join(box.main, path), 'base literal\n');@@ -149,8 +184,8 @@ test('a foreign resolution identical to HEAD is allowed, including literal odd fassert.deepEqual(preCommitProblems(box.context), []);writeFileSync(join(box.lane, path), 'neither parent\n');git(box.lane, 'add', '--', path);- assert.ok(preCommitProblems(box.context).some((problem) => problem.includes('literal')),- 'a new foreign object is refused without interpreting brackets or line breaks');+ assert.deepEqual(preCommitProblems(box.context), [],+ 'a resolved accepted-main conflict may choose new content at its coordinator-owned path');});test('merging an unaccepted branch never authorizes foreign changes [L3]', (t) => {@@ -289,6 +324,39 @@ test("merging main brings in main's own changes outside the lane [H16,B26]", (t)'the exact policy change from main is present in the lane checkout');});+test('resolving a foreign main conflict completes the merge and names the coordinator [H16,B26]', (t) => {+ const { box, mainHead } = stagedCoordinatorPolicyConflict(t);+ const result = nativeCommit(box, box.lane, 'chore: resolve accepted coordinator policy');+ assert.equal(result.status, 0, result.stderr);+ assert.match(result.stderr, /the coordinator owns pullboard\.json/u);+ assert.equal(box.git(box.lane, 'rev-parse', 'HEAD^2').stdout.trim(), mainHead,+ 'the resolved commit retains the accepted main commit as its second parent');+});++test('a foreign edit beside a resolved main conflict remains refused [H16,B26]', (t) => {+ const { box } = stagedCoordinatorPolicyConflict(t);+ writeFileSync(join(box.lane, 'view', 'file'), 'unrelated foreign edit\n');+ let result = box.git(box.lane, 'add', 'view/file');+ assert.equal(result.status, 0);+ result = nativeCommit(box, box.lane, 'chore: resolve policy with foreign edit');+ assert.notEqual(result.status, 0, 'the conflict exception cannot authorize unrelated foreign content');+ 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 commit did not finish the merge');+});++test('a mode change on a resolved foreign main conflict remains refused [H16,B26]', (t) => {+ const { box } = stagedCoordinatorPolicyConflict(t);+ chmodSync(join(box.lane, 'pullboard.json'), 0o755);+ const staged = box.git(box.lane, 'add', 'pullboard.json');+ assert.equal(staged.status, 0, staged.stderr);+ const result = nativeCommit(box, box.lane, 'chore: resolve policy with mode change');+ assert.notEqual(result.status, 0, 'conflict resolution cannot authorize a new executable mode');+ assert.match(result.stderr, /outside the core lane: pullboard\.json/u);+ assert.notEqual(box.git(box.lane, 'rev-parse', '--verify', 'HEAD^2').status, 0,+ 'the refused commit did not finish the merge');+});+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');