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(core): retain the trunk outside board data [B34,V6]
Corey Olsond615c1c0a7d0
diff --git a/src/board.js b/src/board.jsindex aa998242..b7a6f0b1 100644--- a/src/board.js+++ b/src/board.js@@ -432,12 +432,6 @@ export function agentAt(board, path) {return board.db.prepare('SELECT * FROM agent WHERE agent_path = ?').get(path);}-/** Remember the primary branch locally, so a detached review can still check its current trunk [B34,V6]. */-export function trunkRef(board, branch) {- if (branch !== undefined) board.db.prepare('INSERT INTO board_meta(meta_key,meta_value) VALUES (?,?) ON CONFLICT(meta_key) DO UPDATE SET meta_value=excluded.meta_value').run('trunk_ref', branch);- return board.db.prepare('SELECT meta_value FROM board_meta WHERE meta_key=?').get('trunk_ref')?.meta_value ?? null;-}-/*** Register a worktree as an agent (B3): the main checkout as the one coordinator, any other* worktree as the next agent in its lane (`web-1`, `web-2`, ...), on a route: the tier of modeldiff --git a/src/cli.js b/src/cli.jsindex e28dcece..f7ff6890 100644--- a/src/cli.js+++ b/src/cli.js@@ -56,7 +56,7 @@ import { exportView, serveView } from './serve.js';import { serveApi } from './api.js';import { doctorProblems, doctrineProblems } from './doctor.js';import { staleFrozenItems, staleItemFinding } from './approved-rows.js';-import { mainPolicy, itemPolicy, submissionPaths, frozenCheck, checkAtCommit, dependencySnapshots, requireTrunkMerge } from './trusted-policy.js';+import { mainPolicy, itemPolicy, submissionPaths, frozenCheck, checkAtCommit, dependencySnapshots, requireTrunkMerge, trunkRef } from './trusted-policy.js';import { exportBoard, importBoard } from './exchange.js';import { addSigner, assertRequiredSigners, defaultPrincipal, hasSignerFile } from './signature.js';import { loadMachineSettings, setGateSlots } from './settings.js';@@ -631,13 +631,7 @@ function withBoard(ctx, work) {store.closeBoard(board);};let result;- try {- if (ctx.info.isMain) {- const primary = mainCheckout(ctx.info.root);- if (primary?.branch) store.trunkRef(board, primary.branch);- }- result = work(board);- }+ try { result = work(board); }catch (error) { finish(); throw error; }if (result && typeof result.then === 'function') return result.finally(finish);finish();@@ -1443,7 +1437,7 @@ async function submitHere(ctx, id) {if (stray.length) throw new Refused('UNTRACKED', `commit or ignore ${stray.length} untracked file(s), e.g. ${stray[0]}`);const commit = headCommit(root);if (!commit) throw new Refused('NO_COMMIT', 'nothing committed yet');- withBoard(ctx, board => requireTrunkMerge(root, commit, store.trunkRef(board)));+ requireTrunkMerge(root, commit);// Submit runs the gate itself, every time: a stamp from an earlier run is a file any agent can// write, so it never stands in for this run (V16). It starts on the commit submitted, and must end// on it too. What the gate's own code does in between is the submitted tree's, under review.@@ -1455,7 +1449,7 @@ async function submitHere(ctx, id) {`when the gate ended, HEAD or a tracked file differed from ${commit.slice(0, 12)}, the commit it started on, so the gate did not end on what you would submit; leave the worktree alone until the gate finishes, then submit again`,);}- withBoard(ctx, board => requireTrunkMerge(root, commit, store.trunkRef(board))); // The trunk may have moved while the gate ran.+ requireTrunkMerge(root, commit); // The trunk may have moved while the gate ran.await withBoard(ctx, async (board) => await ordered(ctx, board, 'submit', [id, { agentId: me.id, commit, tree: headTree(root) ?? '', files: filesSince(root, id, claimHead, commit), policyCommit: acceptedMain.commit }]));const pin = `refs/pullboard/items/${id}/${commit.slice(0, 12)}`;git(root, ['update-ref', pin, commit]);@@ -1501,11 +1495,11 @@ async function verifyHere(ctx, id, { second, values }) {}if (decision === 'ACCEPT') {if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');- requireTrunkMerge(root, commit, store.trunkRef(board));+ requireTrunkMerge(root, commit);if (!checkAtCommit(root, item).green) throw new Refused('CHECK_RED', 'the frozen item check is red at the submitted commit; reject with the failing behavior or ask the builder to fix and resubmit');const receipt = store.events(board, { itemId: id }).filter(event => event.event_kind === 'submit').map(event => JSON.parse(event.event_detail)).find(event => event.commit === commit);submissionPaths(root, item, commit, { mainCommit: receipt?.policyCommit, dependencies: dependencySnapshots(board.db, item) });- requireTrunkMerge(root, commit, store.trunkRef(board)); // Re-read after the frozen check, before accepting.+ requireTrunkMerge(root, commit); // Re-read after the frozen check, before accepting.}return await ordered(ctx, board, 'verify', [id, {agentId: me.id,@@ -2340,13 +2334,8 @@ function rememberTrunk(io) {throw error;}if (!info.isMain) return;- const file = join(info.commonDir, 'pullboard', 'board.sqlite');- if (!existsSync(file)) return;const primary = mainCheckout(info.root);- if (!primary?.branch) return;- const board = store.openBoard(file, io.clock ?? store.systemClock);- try { store.trunkRef(board, primary.branch); }- finally { store.closeBoard(board); }+ if (primary?.branch) trunkRef(info.root, primary.branch);}/** Run one command and emit its single versioned JSON result when requested (A1). */diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex 788d4fa9..e98703ab 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -23,8 +23,23 @@ export function mainPolicy(root) {return policyAt(root, checkout.commit);}+/** Retain the local primary branch outside replicated board data and read-only diagnostics [B34,V6]. */+export function trunkRef(root, branch) {+ const read = spawnSync('git', ['--no-replace-objects', 'config', '--local', '--get', 'pullboard.trunk'], {+ cwd: root, env: cleanGitEnvironment(), encoding: 'utf8',+ });+ if (read.status !== 0 && read.status !== 1) throw new Refused('NO_POLICY', 'the retained trunk cannot be read; restore the local Git configuration and retry');+ const current = read.status === 0 ? read.stdout.trim() : null;+ if (branch === undefined || branch === current) return current;+ const saved = spawnSync('git', ['--no-replace-objects', 'config', '--local', '--replace-all', 'pullboard.trunk', branch], {+ cwd: root, env: cleanGitEnvironment(), encoding: 'utf8',+ });+ if (saved.status !== 0) throw new Refused('NO_POLICY', 'the trunk branch cannot be recorded; restore writable local Git configuration and retry');+ return branch;+}+/** Refuse a candidate that conflicts with the current primary branch, without touching an index or worktree [B34,V6]. */-export function requireTrunkMerge(root, commit, retainedRef = null) {+export function requireTrunkMerge(root, commit, retainedRef = trunkRef(root)) {const checkout = mainCheckout(root);const branchRef = checkout?.branch ?? retainedRef;if (!branchRef?.startsWith('refs/heads/')) throw new Refused('NO_TRUNK', 'no trunk branch was recorded; check out the trunk branch in the main checkout once and run pullboard inbox');diff --git a/test/trunk.test.js b/test/trunk.test.jsindex 0198103d..530d7559 100644--- a/test/trunk.test.js+++ b/test/trunk.test.js@@ -242,8 +242,10 @@ test('[B34,V6] a detached coordinator accept checks the retained non-main trunktest('[B34,V6] an unrecorded detached trunk refuses with NO_TRUNK and its repair', () => {const box = project('trunk');const commit = box.git(box.repo, 'rev-parse', 'HEAD');- box.git(box.repo, 'switch', '-q', '--detach', commit);- const before = checkoutState(box, box.repo);- assert.throws(() => requireTrunkMerge(box.repo, commit), error => error.code === 'NO_TRUNK' && /check out the trunk branch in the main checkout once/.test(error.message));- assert.deepEqual(checkoutState(box, box.repo), before);+ const clone = join(box.dir, 'unrecorded-clone');+ box.git(box.repo, 'clone', '-q', box.repo, clone);+ box.git(clone, 'switch', '-q', '--detach', commit);+ const before = checkoutState(box, clone);+ assert.throws(() => requireTrunkMerge(clone, commit), error => error.code === 'NO_TRUNK' && /check out the trunk branch in the main checkout once/.test(error.message));+ assert.deepEqual(checkoutState(box, clone), before);});