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(core): allow lane merges from main [L3]

Corey Olsonae644ae0d575
diff --git a/src/hooks.js b/src/hooks.js
index 3f53e2b3..9e73ebc8 100644
--- a/src/hooks.js
+++ b/src/hooks.js
@@ -103,14 +103,16 @@ export function commitMsgProblems(raw, { rules, spec }) {
}
/**
- * Staged paths: every path the commit touches, and the ones it writes. Deletions and both sides of
- * a rename count as touched, so a lane cannot delete or move a file it does not own (L3).
+ * Staged paths: every path the commit touches, and the ones it writes. An optional base lets a
+ * merge check only differences from the merged commit. Deletions and both sides of a rename count
+ * as touched, so a lane cannot delete or move a file it does not own (L3).
*
* @param {string} root
+ * @param {string | null} [base]
* @returns {{ touched: string[], written: string[] }}
*/
-export function stagedPaths(root) {
- const fields = git(root, ['diff', '--cached', '--name-status', '-z']).split('\0');
+export function stagedPaths(root, base = null) {
+ const fields = git(root, ['diff', '--cached', '--name-status', '-z', ...(base ? [base] : [])]).split('\0');
const touched = [];
const written = [];
let index = 0;
@@ -211,13 +213,29 @@ export function preCommitProblems({ root, isMain, config, agent }) {
problems.push('this worktree has not joined a lane: pullboard join <lane>');
return problems;
}
- const foreign = outOfLane(config, agent.agent_lane, touched);
+ const mergeBase = mainMergeBase(root);
+ const ownershipTouched = mergeBase ? stagedPaths(root, mergeBase).touched : touched;
+ const foreign = outOfLane(config, agent.agent_lane, ownershipTouched);
problems.push(
...foreign.map((path) => `outside the ${agent.agent_lane} lane: ${path}; shout its owner instead`),
);
return problems;
}
+/**
+ * The commit being merged, only when it is already part of main's history.
+ *
+ * @param {string} root
+ * @returns {string | null}
+ */
+function mainMergeBase(root) {
+ const merge = tryGit(root, ['rev-parse', '--verify', 'MERGE_HEAD']);
+ if (merge.status !== 0) return null;
+ return tryGit(root, ['merge-base', '--is-ancestor', merge.stdout, 'refs/heads/main']).status === 0
+ ? merge.stdout
+ : null;
+}
+
/**
* A path quoted for the shell, whatever characters it holds.
*
diff --git a/test/e2e.test.js b/test/e2e.test.js
index 5e7dc058..6bb7c725 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -254,6 +254,36 @@ test('a lane commits only inside its folders; an unjoined worktree cannot commit
assert.match(taken.stderr, /outside the web lane: api\/b.js/, 'a move counts where it left, not only where it lands');
});
+test("a lane merges main's foreign changes but still refuses its own and non-main foreign changes [L3]", () => {
+ const mainChange = project();
+ assert.equal(commitFile(mainChange, mainChange.repo, 'api/main.js', 'from main', 'feat(api): main change [G2]').status, 0);
+ const preparedMerge = mainChange.tryGit(mainChange.web, 'merge', '--no-commit', '--no-ff', 'main');
+ assert.equal(preparedMerge.status, 0, preparedMerge.stderr);
+ const merged = mainChange.tryGit(mainChange.web, 'commit', '-q', '-m', 'Merge main');
+ assert.equal(merged.status, 0, merged.stderr);
+ assert.equal(mainChange.git(mainChange.web, 'show', 'HEAD:api/main.js'), 'from main');
+
+ const editedDuringMerge = project();
+ assert.equal(commitFile(editedDuringMerge, editedDuringMerge.repo, 'api/main.js', 'from main', 'feat(api): main change [G2]').status, 0);
+ const preparedMain = editedDuringMerge.tryGit(editedDuringMerge.web, 'merge', '--no-commit', '--no-ff', 'main');
+ assert.equal(preparedMain.status, 0, preparedMain.stderr);
+ writeFileSync(join(editedDuringMerge.web, 'api/main.js'), 'changed in the lane merge');
+ editedDuringMerge.git(editedDuringMerge.web, 'add', 'api/main.js');
+ const changedForeign = editedDuringMerge.tryGit(editedDuringMerge.web, 'commit', '-q', '-m', 'Merge main');
+ assert.notEqual(changedForeign.status, 0);
+ assert.match(changedForeign.stderr, /outside the web lane: api\/main.js/);
+
+ const sideBranch = project();
+ sideBranch.git(sideBranch.repo, 'switch', '-q', '-c', 'side');
+ assert.equal(commitFile(sideBranch, sideBranch.repo, 'api/side.js', 'from side', 'feat(api): side change [G2]').status, 0);
+ sideBranch.git(sideBranch.repo, 'switch', '-q', 'main');
+ const preparedSide = sideBranch.tryGit(sideBranch.web, 'merge', '--no-commit', '--no-ff', 'side');
+ assert.equal(preparedSide.status, 0, preparedSide.stderr);
+ const changedSide = sideBranch.tryGit(sideBranch.web, 'commit', '-q', '-m', 'Merge side');
+ assert.notEqual(changedSide.status, 0);
+ assert.match(changedSide.stderr, /outside the web lane: api\/side.js/);
+});
+
test('submit needs a clean tree, nothing untracked, and the gate green at HEAD [V4, B9]', () => {
const box = project();
box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1');