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): a kept side names the coordinator; renames merge [H16]
Corey Olson7982c7d279a6
diff --git a/src/hooks.js b/src/hooks.jsindex 2182b763..535fcef6 100644--- a/src/hooks.js+++ b/src/hooks.js@@ -279,9 +279,15 @@ export function preCommitProblems({ root, isMain, config, agent, boardFile, preM}const mergeHeads = mainMergeHeads(root, preMergeHook);const ownershipConfig = committedLaneConfig(root);+ const mergeTouched = mergeHeads ? [...new Set([...touched, ...mergeHeads.flatMap((mergeHead) => stagedPaths(root, mergeHead).touched)])] : touched;+ // Keeping either parent's exact content of a foreign file is accepted unchanged; when that file had a real conflict+ // in this merge, the resolution still names its owner (#860).+ const kept = mergeHeads && !preMergeHook+ ? mergeTouched.filter((path) => outOfLane(ownershipConfig, agent.agent_lane, [path]).length && unchangedMergePath(root, path, mergeHeads) && conflictedInMerge(root, path))+ : [];+ kept.forEach((path) => onNotice?.(`resolved accepted-main conflict in ${path}; the coordinator owns ${path}`));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))+ ? mergeTouched.filter((path) => !outOfLane(ownershipConfig, agent.agent_lane, [path]).length || !unchangedMergePath(root, path, mergeHeads)): touched;const foreignPaths = ownershipTouched.filter((path) => outOfLane(ownershipConfig, agent.agent_lane, [path]).length);const resolved = mergeHeads && !preMergeHook@@ -497,6 +503,12 @@ function unchangedMergePath(root, path, mergeHeads) {return staged !== null && (mergeHeads.some((mergeHead) => staged === committedObject(root, mergeHead, path)) || staged === committedObject(root, 'HEAD', path));}+/** Whether Git's resolve-undo index records a real conflict for this path in the merge being committed. */+function conflictedInMerge(root, path) {+ return git(root, ['ls-files', '--resolve-undo', '--stage', '-z', '--', ':(literal)' + path]).split('\0').filter(Boolean)+ .some((record) => record.slice(record.indexOf('\t') + 1) === path && /^\d{6} [0-9a-f]{40,64} [123]\t/iu.test(record));+}+/*** Allow a new foreign object, or the file's removal, only when Git records both exact parents in the* resolved conflict index. Removing the file is a resolution like any other (#860): `git rm` after adiff --git a/test/merge-hooks.test.js b/test/merge-hooks.test.jsindex dfdfa1a4..64a78d2a 100644--- a/test/merge-hooks.test.js+++ b/test/merge-hooks.test.js@@ -444,3 +444,54 @@ test('removing a conflicted foreign file resolves a main merge and names the cooassert.notEqual(result.status, 0, 'a foreign edit with no conflict stays refused');assert.match(result.stderr, /outside the core lane: view\/file/u);});++test("merging main brings in the foreign files main added, deleted and renamed [H16,B26]", (t) => {+ const box = nativeFixture(t);+ writeFileSync(join(box.lane, 'core', 'file'), 'lane core\n');+ assert.equal(box.git(box.lane, 'add', '-A').status, 0);+ let result = nativeCommit(box, box.lane, 'feat(core): update owned file [L3]');+ assert.equal(result.status, 0, result.stderr);+ writeFileSync(join(box.main, 'view', 'added'), 'added on main\n');+ assert.equal(box.git(box.main, 'add', 'view/added').status, 0);+ assert.equal(box.git(box.main, 'mv', 'view/file', 'view/moved').status, 0);+ result = nativeCommit(box, box.main, 'chore: add and rename view files on main');+ assert.equal(result.status, 0, result.stderr);+ assert.equal(box.git(box.main, 'rm', '-q', 'view/added').status, 0);+ result = nativeCommit(box, box.main, 'chore: delete a view file on main');+ assert.equal(result.status, 0, result.stderr);++ result = box.git(box.lane, 'merge', '--no-edit', 'main');+ assert.equal(result.status, 0, `main's own additions, deletions and renames merge: ${result.stderr}`);+ assert.equal(box.git(box.lane, 'rev-parse', '--verify', 'HEAD^2').status, 0, 'the merge completed');+ assert.equal(readFileSync(join(box.lane, 'view', 'moved'), 'utf8').length > 0, true, "main's rename arrived");+});++test('keeping this side of a conflicted foreign file resolves a main merge [H16,B26]', (t) => {+ const box = nativeFixture(t);+ let result = box.git(box.main, 'switch', '-c', 'historical-view');+ assert.equal(result.status, 0, result.stderr);+ writeFileSync(join(box.main, 'view', 'file'), 'historical view\n');+ assert.equal(box.git(box.main, 'add', 'view/file').status, 0);+ result = nativeCommit(box, box.main, 'chore: retain historical view file');+ assert.equal(result.status, 0, result.stderr);+ assert.equal(box.git(box.lane, 'reset', '--hard', 'historical-view').status, 0);+ assert.equal(box.git(box.main, 'switch', 'main').status, 0);+ writeFileSync(join(box.main, 'view', 'file'), 'current view\n');+ assert.equal(box.git(box.main, 'add', 'view/file').status, 0);+ result = nativeCommit(box, box.main, 'chore: update the view file on main');+ assert.equal(result.status, 0, result.stderr);++ result = box.git(box.lane, 'merge', '--no-edit', 'main');+ assert.equal(result.status, 1, 'the fixture must create a real conflict in a foreign file');+ assert.equal(box.git(box.lane, 'checkout', '--ours', '--', 'view/file').status, 0);+ assert.equal(box.git(box.lane, 'add', 'view/file').status, 0);+ result = nativeCommit(box, box.lane, 'chore: keep this side of the view conflict');+ assert.equal(result.status, 0, `keeping one side is a resolution: ${result.stderr}`);+ assert.match(result.stderr, /the coordinator owns view\/file/u);++ // Renaming a conflicted file to a name main never had is the worktree's own new path, refused with its owner named.+ assert.equal(box.git(box.lane, 'mv', 'view/file', 'view/renamed').status, 0);+ result = nativeCommit(box, box.lane, 'chore: rename a foreign file');+ assert.notEqual(result.status, 0, 'a new foreign path the worktree creates stays refused');+ assert.match(result.stderr, /outside the core lane: view\/renamed \(\w+'s\)/u, 'the refusal names the new path and its owner');+});