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): refuse detached review claim policies [V4,V16]

Corey Olson808a3aa023a3
diff --git a/docs/formats.md b/docs/formats.md
index 15d2d2b3..241e9902 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -246,7 +246,7 @@ The `event` table is a SQLite schema object governed by `SCHEMA_VERSION`; its ap
| `answer` | answerer | `shout`, `to`, `decision`, `request`, `answers`, `outcome` |
<!-- events:end -->
-New CLI claims include a `policy` object (`version: 1`, `commit`) in the frozen criterion. It pins the coordinator checkout’s committed configuration. Legacy claims use their recorded claim-base commit. A CLI `submit` records the pre-merge coordinator HEAD as optional `policyCommit`; historical doctor and acceptance checks use this snapshot when allowing unchanged foreign files brought in from MAIN. Verified dependencies may also contribute unchanged files in their own lanes before a MAIN merge; foreign deletion or replacement is not authorized by an unrelated dependency’s tree. The complete candidate diff against both claim base and frozen MAIN is checked with rename detection disabled, preserving deleted paths and whitespace in names. Frozen item checks run against the exact submitted commit in an isolated checkout when accepting and auditing; repairing a reviewer’s checkout cannot make a red submission green.
+New CLI claims include a `policy` object (`version: 1`, `commit`) in the frozen criterion. It pins the coordinator checkout’s committed configuration on its attached main branch. A temporary detached review checkout refuses new policy-dependent claims or project gates with `NO_POLICY`; the coordinator returns to its main branch. Existing frozen submissions remain verifiable. Legacy claims use their recorded claim-base commit. A CLI `submit` records the pre-merge coordinator HEAD as optional `policyCommit`; historical doctor and acceptance checks use this snapshot when allowing unchanged foreign files brought in from MAIN. Verified dependencies may also contribute unchanged files in their own lanes before a MAIN merge; foreign deletion or replacement is not authorized by an unrelated dependency’s tree. The complete candidate diff against both claim base and frozen MAIN is checked with rename detection disabled, preserving deleted paths and whitespace in names. Frozen item checks run against the exact submitted commit in an isolated checkout when accepting and auditing; repairing a reviewer’s checkout cannot make a red submission green.
Migration preserves event rows and adds only schema objects that are missing.
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index ebe36130..2ee6b4a7 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -26,7 +26,10 @@ function policyGit(root, args) {
/** Resolve the primary checkout's committed HEAD, independently of a linked or detached checkout. */
export function mainPolicy(root) {
const common = policyGit(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim();
- const commit = policyGit(root, ['--git-dir', common, 'rev-parse', '--verify', 'HEAD^{commit}']).trim();
+ let branch;
+ try { branch = policyGit(root, ['--git-dir', common, 'symbolic-ref', '--quiet', 'HEAD']).trim(); }
+ catch { throw new Refused('NO_POLICY', 'the coordinator checkout is detached for review; ask it to return to its main branch before claiming or running the project gate'); }
+ const commit = policyGit(root, ['--git-dir', common, 'rev-parse', '--verify', branch + '^{commit}']).trim();
return policyAt(root, commit);
}
diff --git a/test/e2e.test.js b/test/e2e.test.js
index ab2fbc4b..3143373b 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -1944,3 +1944,23 @@ test('replacement refs cannot turn a red committed owned tree into a clean green
assert.equal(submitted.code, 1);
assert.equal(JSON.parse(submitted.out).error.code, 'DIRTY', 'the underlying tree differs from the files the gate would execute');
});
+
+test('a detached coordinator review cannot become a new claim policy [V4,V16]', () => {
+ const box = project('test ! -f web/RED');
+ assert.equal(box.run(box.repo, 'add', 'web', 'Detached policy', '--specs', 'G1').code, 0);
+ const config = JSON.parse(readFileSync(join(box.web, 'pullboard.json'), 'utf8'));
+ config.gate = 'true';
+ config.lanes.web.owns.push('pullboard.json');
+ writeFileSync(join(box.web, 'pullboard.json'), JSON.stringify(config));
+ const candidate = attackCommit(box, box.web);
+ box.git(box.repo, 'switch', '-q', '--detach', candidate);
+ const refused = box.run(box.web, 'claim', '1', '--json');
+ assert.equal(refused.code, 1);
+ assert.equal(JSON.parse(refused.out).error.code, 'NO_POLICY');
+ assert.match(JSON.parse(refused.out).error.message, /return to its main branch/);
+ box.git(box.repo, 'switch', '-q', 'main');
+ assert.equal(box.run(box.web, 'claim', '1').code, 0);
+ const submitted = box.run(box.web, 'submit', '1', '--json');
+ assert.equal(submitted.code, 1);
+ assert.equal(JSON.parse(submitted.out).error.code, 'OUTSIDE_LANE');
+});