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 trunk in private verifier clones [D4,A5]
Corey Olson1243f95b0fdd
diff --git a/src/cli.js b/src/cli.jsindex 561870a5..4d59b3d1 100644--- a/src/cli.js+++ b/src/cli.js@@ -76,7 +76,7 @@ export const VERSION = PACKAGE.version;const CHECKOUT_LEASES = new WeakMap();/**- * Read the grandfather baseline from the primary checkout's attached branch, never a builder's head.+ * Read the collision baseline from the primary branch, or its retained trunk when detached.** @param {string} root* @param {string} path@@ -87,15 +87,19 @@ function coordinatorFile(root, path, revision) {const commonDir = git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']);const coordinatorRoot = dirname(commonDir);const env = { ...gitChildEnv(root), GIT_NO_REPLACE_OBJECTS: '1' };- const branch = spawnSync('git', ['symbolic-ref', '--quiet', 'HEAD'], {- cwd: coordinatorRoot, env, encoding: 'utf8',- });- const ref = (branch.stdout ?? '').trim();- if (branch.status !== 0 || !ref.startsWith('refs/heads/')) {- throw new Refused(- 'COORDINATOR_DETACHED',- 'the primary checkout must be on its attached local branch to establish the collision baseline; the coordinator returns it to its branch',- );+ const primary = mainCheckout(coordinatorRoot);+ let ref = primary?.branch ?? trunkRef(coordinatorRoot);+ if (!ref?.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');+ }+ if (!primary) {+ const tip = spawnSync('git', ['--no-replace-objects', 'rev-parse', '--verify', '--quiet', `${ref}^{commit}`], {+ cwd: coordinatorRoot, env, encoding: 'utf8',+ });+ if (tip.status !== 0) {+ throw new Refused('NO_TRUNK', 'the recorded trunk branch has no readable tip; check out the trunk branch in the main checkout once and run pullboard inbox');+ }+ ref = tip.stdout.trim();}const result = spawnSync('git', ['--no-replace-objects', 'show', `${revision ?? ref}:${path}`], {cwd: coordinatorRoot, env, encoding: 'utf8',diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex 90f1ae3b..404ffac3 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -153,6 +153,25 @@ export function checkAtCommit(root, item) {try {const common = policyGit(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim();const clone = spawnSync('git', ['clone', '--quiet', '--shared', '--no-checkout', common, copy], { env, stdio: 'ignore' });+ if (clone.status === 0) {+ const retainedTrunk = trunkRef(root);+ if (retainedTrunk) {+ const savedTrunk = spawnSync('git', ['config', '--local', '--replace-all', 'pullboard.trunk', retainedTrunk], {+ cwd: copy, env, stdio: 'ignore',+ });+ if (savedTrunk.status !== 0) return finish('unverified', 'retained trunk could not be copied into the private clone');+ // Cloning a detached primary HEAD omits its local trunk branch, even when the source has it.+ const retainedTip = spawnSync('git', ['--no-replace-objects', 'rev-parse', '--verify', '--quiet', `${retainedTrunk}^{commit}`], {+ cwd: root, env, encoding: 'utf8',+ });+ if (retainedTip.status === 0 && retainedTrunk.startsWith('refs/heads/')) {+ const savedTip = spawnSync('git', ['update-ref', retainedTrunk, retainedTip.stdout.trim()], {+ cwd: copy, env, stdio: 'ignore',+ });+ if (savedTip.status !== 0) return finish('unverified', 'retained trunk tip could not be copied into the private clone');+ }+ }+ }const checkout = clone.status === 0 && spawnSync('git', ['checkout', '--quiet', '--detach', item.item_commit], { cwd: copy, env, stdio: 'ignore' });if (!checkout || checkout.status !== 0) return finish('unverified', 'clone or checkout could not start');const deadline = Date.now() + timeout;diff --git a/test/doctrine-name.test.js b/test/doctrine-name.test.jsindex 1bc6f71e..70994a90 100644--- a/test/doctrine-name.test.js+++ b/test/doctrine-name.test.js@@ -6,6 +6,7 @@ import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { after, test } from 'node:test';import { projectState } from '../src/serve.js';+import { checkAtCommit } from '../src/trusted-policy.js';const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');const DOCTRINE = 'DOCTRINE.md';@@ -270,3 +271,87 @@ test('[D4,A5] a staged rename keeps known duplicates before its rename commit',assert.match(check.stdout, /SPEC\.md:4 G1 warning: known duplicate id; also appears at DOCTRINE\.md:4/u);assert.match(check.stdout, /DOCTRINE\.md:4 G1 warning: known duplicate id; also appears at SPEC\.md:4/u);});++test('[D4,A5] detached checkout reads the trunk baseline through the verifier clone', function verifierCloneRetainsTrunkBaseline() {+ const box = sandbox();+ const source = renamedDoctrineFixture(box, 'detached-source');+ const initialized = box.run(source, 'init');+ assert.equal(initialized.status, 0, `${initialized.stdout}${initialized.stderr}`);+ box.git(source, 'add', '-A');+ box.git(source, 'commit', '-q', '-m', 'chore: initialize detached spec fixture');+ assert.equal(box.git(source, 'config', '--local', '--get', 'pullboard.trunk'), 'refs/heads/main', 'initialization records the actual source trunk');+ const commit = box.git(source, 'rev-parse', 'HEAD');+ const item = { item_id: 324, item_claim_head: commit, item_commit: commit,+ item_frozen: JSON.stringify({ check: `${shellWord(process.execPath)} ${shellWord(BIN)} spec check` }) };++ const checked = checkAtCommit(source, item);+ assert.equal(checked.state, 'pass', `${checked.stage}\n${checked.output}`);+ assert.match(checked.output, /SPEC\.md: \d+ rows, 0 errors, \d+ warnings/u);+ assert.match(checked.output, /DOCTRINE\.md: \d+ rows, 0 errors, \d+ warnings/u);+ assert.match(checked.output, /SPEC\.md:4 G1 warning: known duplicate id; also appears at DOCTRINE\.md:4/u);+ assert.match(checked.output, /DOCTRINE\.md:4 G1 warning: known duplicate id; also appears at SPEC\.md:4/u);++ const attached = box.run(source, 'spec', 'check');+ assert.equal(attached.status, 0, `${attached.stdout}${attached.stderr}`);+ const attachedRows = specRows(box, source);+ const jsonFile = join(box.dir, 'verifier-spec-rows.json');+ const json = checkAtCommit(source, { ...item, item_frozen: JSON.stringify({ check: `${shellWord(process.execPath)} ${shellWord(BIN)} spec --json > ${shellWord(jsonFile)}` }) });+ assert.equal(json.state, 'pass', `${json.stage}\n${json.output}`);+ const rows = JSON.parse(readFileSync(jsonFile, 'utf8')).rows;+ assert.deepEqual(rows, attachedRows, 'the production verifier clone reports the same rows as attached main');+ assert.ok(rows.some(row => row.file === 'SPEC.md' && row.id === 'G1'));+ assert.ok(rows.some(row => row.file === DOCTRINE && row.id === 'G1'));++ const withoutTrunk = renamedDoctrineFixture(box, 'detached-source-without-trunk');+ const noTrunkInit = box.run(withoutTrunk, 'init');+ assert.equal(noTrunkInit.status, 0, `${noTrunkInit.stdout}${noTrunkInit.stderr}`);+ box.git(withoutTrunk, 'add', '-A');+ box.git(withoutTrunk, 'commit', '-q', '-m', 'chore: initialize no-trunk spec fixture');+ const noTrunkCommit = box.git(withoutTrunk, 'rev-parse', 'HEAD');+ // Init and the installed commit hook both remember the attached trunk; remove it only after them.+ box.git(withoutTrunk, 'config', '--local', '--unset-all', 'pullboard.trunk');+ assert.equal(spawnSync('git', ['config', '--local', '--get', 'pullboard.trunk'], {+ cwd: withoutTrunk, env: box.env,+ }).status, 1, 'the negative source actually has no retained trunk');+ const refused = checkAtCommit(withoutTrunk, { ...item, item_claim_head: noTrunkCommit, item_commit: noTrunkCommit });+ assert.equal(refused.state, 'red');+ assert.match(`${refused.output}\n${refused.outputTail}`, /NO_TRUNK/u);+ assert.match(`${refused.output}\n${refused.outputTail}`, /check out the trunk branch in the main checkout once/u);+});++test('[D4,A5] verify in a detached checkout reads the trunk baseline for a doctrine frozen check', function verifyDoctrineFrozenCheck() {+ const box = sandbox();+ const source = renamedDoctrineFixture(box, 'verify-doctrine-source');+ const initialized = box.run(source, 'init');+ assert.equal(initialized.status, 0, `${initialized.stdout}${initialized.stderr}`);+ const configPath = join(source, 'pullboard.json');+ const config = JSON.parse(readFileSync(configPath, 'utf8'));+ writeFileSync(configPath, JSON.stringify({ ...config, gate: 'true', verify: 'coordinator',+ lanes: { web: { owns: ['web/'], specs: [] } }, shared: [] }, null, 2) + '\n');+ box.git(source, 'add', '-A');+ box.git(source, 'commit', '-q', '-m', 'chore: initialize doctrine verification fixture');+ const check = `${shellWord(process.execPath)} ${shellWord(BIN)} spec check | grep -E 'DOCTRINE[.]md: .*0 errors'`;+ const added = box.run(source, 'add', 'web', 'Doctrine review fixture', '--criterion', 'The frozen doctrine check passes in the verifier clone.', '--check', check, '--json');+ assert.equal(added.status, 0, `${added.stdout}${added.stderr}`);+ const id = JSON.parse(added.stdout).item.item_id;+ const builder = join(box.dir, 'verify-doctrine-builder');+ box.git(source, 'worktree', 'add', '-q', '-b', 'web/doctrine-review', builder);+ assert.equal(box.run(builder, 'join', 'web').status, 0);+ assert.equal(box.run(builder, 'claim', String(id)).status, 0);+ mkdirSync(join(builder, 'web'));+ writeFileSync(join(builder, 'web/candidate.txt'), 'doctrine verification fixture\n');+ box.git(builder, 'add', 'web/candidate.txt');+ box.git(builder, 'commit', '-q', '-m', 'feat(web): build doctrine verification fixture [G1]');+ const submitted = box.run(builder, 'submit', String(id), '--json');+ assert.equal(submitted.status, 0, `${submitted.stdout}${submitted.stderr}`);+ const commit = JSON.parse(submitted.stdout).commit;+ box.git(source, 'switch', '-q', '--detach', commit);+ const accepted = box.run(source, 'verify', String(id), 'accept', '--as', 'coordinator', '--note', 'The exact private frozen doctrine check passed.', '--json');+ assert.equal(accepted.status, 0, `${accepted.stdout}${accepted.stderr}`);+ const result = JSON.parse(accepted.stdout);+ assert.equal(result.decision, 'ACCEPT');+ assert.equal(result.check, 'green', 'the real verifier records that the frozen doctrine check ran and passed');+ const shown = box.run(source, 'show', String(id), '--json');+ assert.equal(shown.status, 0, `${shown.stdout}${shown.stderr}`);+ assert.equal(JSON.parse(shown.stdout).item_status, 'verified');+});diff --git a/test/spec.test.js b/test/spec.test.jsindex 138fbda0..fd04c80d 100644--- a/test/spec.test.js+++ b/test/spec.test.js@@ -141,7 +141,7 @@ test('spec check lists primary-branch collisions as known warnings [A5]', (t) =>assert.match(result.stdout, /PRACTICE\.md:4 G1 warning: known duplicate id; also appears at SPEC\.md:6/u);});-test('spec check refuses a collision committed on a linked builder after coordinator trunk [A5]', (t) => {+test('spec check uses the retained trunk after its coordinator checkout detaches [A5]', (t) => {const practice = '# Practice\n\n## P\n- P1 [draft] A local rule.\n';const box = specBox(t, { practice });const gitAt = (cwd, ...args) => execFileSync('git', args, { cwd, env: box.env, encoding: 'utf8', stdio: 'pipe' });@@ -149,6 +149,7 @@ test('spec check refuses a collision committed on a linked builder after coordincwd, env: box.env, encoding: 'utf8',});gitAt(box.root, 'branch', '-m', 'trunk');+ gitAt(box.root, 'config', '--local', 'pullboard.trunk', 'refs/heads/trunk');const configPath = join(box.root, 'pullboard.json');const config = JSON.parse(readFileSync(configPath, 'utf8'));config.lanes.spec = { owns: ['PRACTICE.md'] };@@ -170,7 +171,8 @@ test('spec check refuses a collision committed on a linked builder after coordingitAt(box.root, 'switch', '-q', '--detach');const detached = runAt(builder, 'spec', 'check');assert.equal(detached.status, 1);- assert.match(detached.stderr, /COORDINATOR_DETACHED/u);+ assert.match(detached.stdout, /duplicate id; also appears at PRACTICE\.md:\d+/u);+ assert.doesNotMatch(`${detached.stdout}${detached.stderr}`, /COORDINATOR_DETACHED/u);gitAt(box.root, 'switch', '-q', 'trunk');});