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
Merge landed trunk into computed grants [E21,H16]
Corey Olson49c637066ca1
diff --cc docs/formats.mdindex d6fd1766,84e362fc..f79666ab--- a/docs/formats.md+++ b/docs/formats.md@@@ -115,7 -115,7 +115,7 @@@ The version table is generated from th| `row grammar` | `1` | `SPEC_GRAMMAR_VERSION` in `src/spec.js`; optional `<!-- pullboard-grammar N -->` line in either file (absence means the current grammar) | Both files share the version. A declared version must match; an incompatible grammar change requires a coordinated version bump and compatible files. No automatic conversion occurs. || `board schema` | `3` | `SCHEMA_VERSION` in `src/board.js`, persisted as `PRAGMA user_version` | On a write open of a board whose version is behind: create missing tables and indexes (version 3 adds the hot-path indexes), add missing columns in place with declared defaults, restore missing or changed triggers, and remove stale machine triggers without replacing rows. Read opens never migrate; a board at the current version whose shape differs is reported once on stderr and left as it is. || `event log` | `1` | `EVENT_LOG_VERSION` in `src/board.js`, persisted in `board_meta` as `event_log_version` | Older event-log versions upgrade in place; newer versions are refused with `EVENT_LOG_VERSION`. Preserve event rows when the board schema changes. |- | `move engine` | `120` | `ENGINE_VERSION` in `src/machine.js`, carried as `engine` in every sealed executable move | Bump when a move's meaning changes, independently of the event log and sealed envelope. A newer engine is refused with `ENGINE_VERSION`, naming both versions and asking you to upgrade Pullboard. |-| `move engine` | `121` | `ENGINE_VERSION` in `src/machine.js`, carried as `engine` in every sealed executable move | Bump when a move's meaning changes, independently of the event log and sealed envelope. A newer engine is refused with `ENGINE_VERSION`, naming both versions and asking you to upgrade Pullboard. |++| `move engine` | `122` | `ENGINE_VERSION` in `src/machine.js`, carried as `engine` in every sealed executable move | Bump when a move's meaning changes, independently of the event log and sealed envelope. A newer engine is refused with `ENGINE_VERSION`, naming both versions and asking you to upgrade Pullboard. |<!-- format-versions:end -->A builder never picks an engine number (#1101). An item that adds a board move adds its own `src/<name>-engine.js` leaf as `export const NAME_ENGINE = unassignedEngine();` (importing `unassignedEngine` from `./engine-next.js`); on its branch the leaf reads as one above the highest landed engine. The landing merge writes the next number into the leaf, in landing order, inside that item's merge commit, and sets the `move engine` row above to the highest landed number. A landed number never changes, so recorded moves replay as they were written. Moves are recorded under landed numbers only: code with an unnumbered engine is for its branch's own tests, and a move it records on a real board before landing may later read under another item's number, so the item lands before its moves are used.@@@ -429,9 -427,10 +429,10 @@@ The computed-grant engine adds `grantEn| `edit` | editor | `brief`, `route`, `criterion`, `check`, `unfrozen`, optional `after`, optional `pendingRefreeze`, engine-19 `reason`, `barCorrection` || `escalate` | builder | `from`, `to`, `note`, `attempt` || `attempt` | reporting agent | `n`, `seconds`, `result` |+ | `board_members` | coordinator | `document` (exact version-1 body with board, repository, revision and complete members, approving login and SSH signature; native moves and checkpoints carry it sealed) || `fact` | author | `id`, `kind`, `text`, `ref`, `supersedes`, engine-20 `implies`, `decision`, `supersededBy`, engine-30 `cause`, `neverAgain`, `channel` |-| `claim` | builder | `leaseUntil`, `digest` |-| `renew` | builder | `leaseUntil`, `digest` |+| `claim` | builder | `leaseUntil`, `digest`, optional `grantEngine` |+| `renew` | builder | `leaseUntil`, `digest`, optional `grantEngine` || `release` | builder | — || `submit` | builder | `commit`, `tree`, `policyCommit`, engine-9 `criterionDigest`, engine-38 `submissionProof`, optional `submissionSize` || `reserve` | reviewer | `until` |diff --cc src/board.jsindex 88ff0abf,148e0b5d..e4803430--- a/src/board.js+++ b/src/board.js@@@ -1,6 -1,4 +1,7 @@@+import { AGENT_GRANT_ENGINE } from './agent-grant-engine.js';+import * as computedConflictEvidence from './computed-conflict-receipt.js';+import { reopenAuthority } from './reopen-authority.js';+ export { readBoardMembers, setBoardMembers } from './board-members.js';import { heartbeatSeat } from './seat-presence.js';import * as itemDecisions from './item-decision-queue.js';import * as activityDeliveryStore from './activity-delivery-store.js';diff --cc src/relay.jsindex 9f833ebe,08b30e8c..50622bfa--- a/src/relay.js+++ b/src/relay.js@@@ -1,4 -1,7 +1,8 @@@+import * as conflictRecords from './relay-conflict-record.js';+ import {+ cancellationOutcome,+ waitForDevicePoll,+ } from './relay-device-poll.js';import {formatSnapshotLimit,reportedSnapshotSize,diff --cc test/move-registry-baseline.jsonindex a04590d8,1e81beea..2bb4a683--- a/test/move-registry-baseline.json+++ b/test/move-registry-baseline.json@@@ -7033,10 -7042,20 +7042,24 @@@"ROW_VERIFY_PROVENANCE": "draft the row through pullboard spec draft and join normally before verifying it","ROW_VERIFY_PENDING": "ask the coordinator to run pullboard spec apply before recording a verifier verdict","ROW_VERIFY_SELF": "ask an outside-parent verifier to run pullboard spec verify",+ "AGENT_GRANT_EXPIRED": "claim the intended item, or shout the coordinator if its claim is unavailable",+ "AGENT_GRANT_ITEM": "finish or release the claim, then claim the intended item; use shout for coordination",+ "AGENT_GRANT_LANE": "join a seat in the intended lane or ask its owner to make the item change",- "GIT_REPLACE_REFS": "ask the coordinator to remove this replica's refs/replace entries, then resume the same ordered move"++ "GIT_REPLACE_REFS": "ask the coordinator to remove this replica's refs/replace entries, then resume the same ordered move",+ "BOARD_MEMBERS_INVALID": "ask a committed approver to publish a complete signed board member list",+ "BOARD_MEMBERS_REVISION": "read the current member revision, then sign a new list",+ "RELAY_NOT_MEMBER": "ask a committed approver to publish the board member list with pullboard relay members set <login>, then retry relay on",+ "BOARD_REPLACE": "run pullboard relay on again; a relink replaces only the repository's active board",+ "BOARD_REPO_LINKED": "pull pullboard.json from main, which names the repository's board, then run pullboard relay on again to join it",+ "GITHUB_UNAVAILABLE": "run any pullboard command again once GitHub answers; the new device keeps waiting",+ "RELAY_JOIN_NOT_EMPTY": "keep this board, then run pullboard init and pullboard relay on in a fresh clone to join the team board",+ "RELAY_KEY_VOUCH": "add the SSH key that signed this device to your GitHub account with gh ssh-key add, then run pullboard relay on again",+ "RELAY_KEY_WAIT_EXPIRED": "run pullboard relay on again while a linked computer of this repository is online",+ "RELAY_SSH_KEY": "make an SSH key with ssh-keygen -t ed25519, add it to GitHub with gh ssh-key add, then run pullboard relay on again",+ "RELAY_SSH_KEYGEN": "install OpenSSH, then run pullboard relay on again",+ "RELAY_SSH_SIGN": "load the key with ssh-add, or set PULLBOARD_SSH_KEY to a key on your GitHub account, then run pullboard relay on again",+ "BAD_DECISION_OPTIONS": "ask an item decision with --decision --item <id> --options '[\"first\",\"second\"]'",+ "NOT_YOUR_ITEM_DECISION": "ask on an item you build or review, or ask the coordinator for a cross-item decision"},"replay": {"initial": {diff --cc test/team.test.jsindex b213bd7c,c7ac8f7c..7f72fbac--- a/test/team.test.js+++ b/test/team.test.js@@@ -13,9 -11,8 +13,9 @@@ import { after, test } from 'node:test'import * as store from '../src/board.js';import { exportBoard, importBoard } from '../src/exchange.js';import { applyEngineMove, prepareEngineMove } from '../src/engine.js';+import { appliedSequence } from '../src/engine.js';import { relayClientFixture as sessionRelay, relayFixtureChild as sessionChild, relayClientFixture, relayFixtureChild } from './relay-client-fixture.js';- import { runFixtureGit as sessionGit, runFixtureGit } from './fixture-child.js';+ import { runFixtureGit as sessionGit, runFixtureGit, runFixtureChild } from './fixture-child.js';import { createE2eHelpers } from './e2e-helpers.js';import { serveApi } from '../src/api.js';import { main } from '../src/cli.js';@@@ -877,358 -1021,56 +1024,412 @@@ test('a landing lease renewal or waite});+test('an agent grant narrows at claim and expires identically on independent replicas [E21]', () => {+ const box = helpers.project();+ for (const title of ['Claimed work', 'Other work']) {+ run(box, box.repo, 'add', 'web', title, '--specs', 'G1', '--check', 'test -f web/grant-proof');+ }+ run(box, box.repo, 'add', 'api', 'Other lane', '--specs', 'G2', '--check', 'test -f api/grant-proof');+ const fresh = join(box.dir, 'fresh-seat');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', fresh, 'main');+ run(box, fresh, 'join', 'web');+ const freshActor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === fresh).agent_id);+ run(box, box.web, 'claim', '1');+ const actor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === box.web).agent_id);+ const held = withBoard(box.repo, board => store.getItem(board, 1));+ const snapshot = withBoard(box.repo, exportBoard);+ const peer = join(box.dir, 'grant-replica');+ box.git(box.dir, 'clone', '-q', box.repo, peer);+ withBoard(peer, board => importBoard(board, snapshot));+ const roots = [box.repo, peer];+ const during = new Date(Date.parse(held.item_lease_until) - 1000).toISOString();+ const expired = new Date(Date.parse(held.item_lease_until) + 1).toISOString();+ /** Replay one sealed public engine move on both real SQLite replicas at its ordered receipt time. */+ const replay = (operation, args, at = during) => {+ const move = withBoard(box.repo, board => prepareEngineMove(board, operation, args));+ const outcomes = roots.map(root => withBoard(root, board => applyEngineMove(board, move,+ { sequence: appliedSequence(board) + 1, at })));+ assert.deepEqual(outcomes[0], outcomes[1], 'the same move has the same public result on both replicas');+ return outcomes[0];+ };+ /** Facts remain communication; escalation supplies the state-change grant witness. */+ const fact = (item, text, at, by = actor) => replay('appendFact', [item, { agentId: by, kind: 'note', text }], at);+ /** Escalation changes item state and must stay inside the computed grant. */+ const change = (item, note, at, by = actor) => replay('escalate', [item, { agentId: by, note }], at);+ assert.equal(fact(1, 'Own claimed item remains writable').error, undefined, 'positive own-item communication reached the engine');+ const before = roots.map(root => withBoard(root, board => store.getItem(board, 2)));+ const outside = change(2, 'This must not change another item');+ assert.equal(outside.error?.code, 'AGENT_GRANT_ITEM', 'claim narrows item mutations even inside the same lane');+ assert.deepEqual(roots.map(root => withBoard(root, board => store.getItem(board, 2))), before,+ 'a refused state change cannot modify either replica');+ assert.equal(change(1, 'The expired lease no longer authorizes a move', expired).error?.code,+ 'AGENT_GRANT_EXPIRED', 'ordered receipt time, not the receiving machine clock, ends the grant');+ // Administrative communication and release cannot be trapped behind the grant being reported.+ assert.equal(replay('shout', [{ from: actor, to: 'coordinator', text: 'My claim expired; arranging the next work.', lanes: ['web', 'api'] }], expired).error,+ undefined, 'ordinary coordination remains available after expiry');+ assert.equal(replay('release', [1, actor, 'Done with this claim.'], expired).error, undefined);+ assert.equal(change(1, 'Release does not revive an expired grant', expired).error?.code, 'AGENT_GRANT_EXPIRED',+ 'a fresh claim is required after expiry even after administrative release');+ assert.equal(change(3, 'An agent cannot mutate another lane', expired, freshActor).error?.code, 'AGENT_GRANT_LANE',+ 'a fresh unclaimed seat still has only its registered lane');+});++test('an agent grant narrows at claim without changing old receipts or permitting an old-engine bypass [E21,H16]', async t => {+ const { AGENT_GRANT_ENGINE } = await import('../src/agent-grant-engine.js');+ const box = helpers.project();+ const clock = { now: () => new Date('2026-10-01T00:00:00.000Z') };+ const boards = ['legacy-authority.sqlite', 'legacy-peer.sqlite'].map(name => store.openBoard(join(box.dir, name), clock));+ t.after(() => boards.forEach(board => store.closeBoard(board)));+ const legacy = AGENT_GRANT_ENGINE - 1;+ const head = box.git(box.repo, 'rev-parse', 'HEAD');+ /** Apply the same actual public engine record on both private replicas. */+ const apply = (operation, args, engine = legacy) => {+ const move = prepareEngineMove(boards[0], operation, args);+ move.engine = engine;+ const sequence = appliedSequence(boards[0]) + 1;+ const outcomes = boards.map(board => applyEngineMove(board, move, { sequence, at: clock.now().toISOString() }));+ assert.deepEqual(outcomes[0], outcomes[1]);+ assert.equal(outcomes[0].error, undefined, JSON.stringify(outcomes[0]));+ return { move, sequence, outcome: outcomes[0] };+ };+ apply('register', [{ lane: 'coordinator', path: box.repo, model: 'fixture-model' }]);+ const actor = apply('register', [{ lane: 'web', path: box.web, model: 'fixture-model' }]).outcome.result;+ const other = apply('register', [{ lane: 'web', path: join(box.dir, 'legacy-other-seat'), model: 'fixture-model' }]).outcome.result;+ for (const title of ['First', 'Second']) apply('addItem', [{ by: 'coordinator', lane: 'web', title,+ criterion: 'A real file must exist', specIds: [], check: 'test -f grant-proof' }]);+ /** Freeze an actual private Git revision; replicas receive only the canonical frozen value. */+ const freeze = item => {+ const text = JSON.stringify({ title: item.item_title, criterion: item.item_criterion,+ check: item.item_check, rows: [], policy: { version: 1, commit: head, verify: { policy: 'any', family: 'off' } } });+ return { text, digest: createHash('sha256').update(text).digest('hex') };+ };+ const options = { agentId: actor, lane: 'web', leaseMs: 60_000, freeze };+ apply('claim', [1, options]);+ const prior = apply('appendFact', [2, { agentId: actor, kind: 'note', text: 'Legacy behavior stays recorded.' }]);+ const forged = prepareEngineMove(boards[0], 'escalate', [2, { agentId: actor, note: 'Old engine cannot bypass the new claim.' }]);+ forged.engine = legacy;+ const oldPeer = prepareEngineMove(boards[0], 'escalate', [1, { agentId: other, note: 'Another old seat must understand the new item grant.' }]);+ oldPeer.engine = legacy;+ const oldTextPeer = prepareEngineMove(boards[0], 'escalate', ['1', { agentId: other, note: 'Numeric text cannot hide the newly claimed target from an old engine.' }]);+ oldTextPeer.engine = legacy;+ apply('claim', [1, options], AGENT_GRANT_ENGINE);+ for (const board of boards) {+ const before = store.itemThread(board, 2);+ assert.deepEqual(applyEngineMove(board, prior.move, { sequence: prior.sequence, at: clock.now().toISOString() }),+ prior.outcome, 'an acknowledged legacy outcome is returned unchanged after activation');+ assert.throws(() => applyEngineMove(board, forged, { sequence: appliedSequence(board) + 1, at: clock.now().toISOString() }),+ error => error.code === 'RELAY_MOVE' && error.message.includes(String(AGENT_GRANT_ENGINE)),+ 'a freshly sealed old-engine move cannot bypass new-claim authority');+ assert.throws(() => applyEngineMove(board, oldPeer, { sequence: appliedSequence(board) + 1, at: clock.now().toISOString() }),+ error => error.code === 'RELAY_MOVE' && error.message.includes(String(AGENT_GRANT_ENGINE)),+ 'another legacy seat cannot interpret a newly claimed item under old grant semantics');+ assert.throws(() => applyEngineMove(board, oldTextPeer, { sequence: appliedSequence(board) + 1, at: clock.now().toISOString() }),+ error => error.code === 'RELAY_MOVE' && error.message.includes(String(AGENT_GRANT_ENGINE)),+ 'the same target expressed as numeric text still requires the new grant engine');+ assert.deepEqual(store.itemThread(board, 2), before, 'neither old receipt replay nor a forged old move adds a fact');+ }+});+++test('an agent grant narrows at claim without trapping its own handoff facts [E21,B3]', () => {+ const box = helpers.project();+ for (const title of ['Claimed work', 'Unrelated work']) {+ run(box, box.repo, 'add', 'web', title, '--specs', 'G1', '--check', 'test -f web/grant-proof', '--wait');+ }+ run(box, box.web, 'claim', '1');+ const actor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === box.web).agent_id);+ const held = withBoard(box.repo, board => store.getItem(board, 1));+ // Finish real baseline observations before cloning the prefix; no detached writer may advance only one replica.+ for (const id of [1, 2]) {+ const baseline = withBoard(box.repo, board => store.getItem(board, id).item_check_baseline);+ assert.ok(baseline, 'each setup item retains its baseline observation');+ assert.notEqual(baseline.result, 'pending', 'setup baselines finish before replica export');+ }+ const snapshot = withBoard(box.repo, exportBoard);+ const peer = join(box.dir, 'handoff-grant-replica');+ box.git(box.dir, 'clone', '-q', box.repo, peer);+ withBoard(peer, board => importBoard(board, snapshot));+ const roots = [box.repo, peer];+ const during = new Date(Date.parse(held.item_lease_until) - 1000).toISOString();+ const expired = new Date(Date.parse(held.item_lease_until) + 1).toISOString();+ /** Apply one genuine engine record at the same ordered time on independent databases. */+ const replay = (operation, args, at = during) => {+ const move = withBoard(box.repo, board => prepareEngineMove(board, operation, args));+ const outcomes = roots.map(root => withBoard(root, board => applyEngineMove(board, move,+ { sequence: appliedSequence(board) + 1, at })));+ assert.deepEqual(outcomes[0], outcomes[1]);+ return outcomes[0];+ };+ assert.equal(replay('openHandoff', [{ agentId: actor }]).error, undefined, 'a claim does not trap channel creation');+ const channels = roots.map(root => withBoard(root, board => board.db.prepare(+ "SELECT item_id FROM event WHERE event_by=? AND event_kind='handoff-open' ORDER BY event_id DESC LIMIT 1").get(actor).item_id));+ assert.equal(channels[0], channels[1]);+ /** Handoff and ordinary item facts both remain available without state-change authority. */+ const fact = (item, text, at) => replay('appendFact', [item, { agentId: actor, kind: 'note', text }], at);+ assert.equal(fact(channels[0], 'Context for the incoming seat').error, undefined,+ 'the live build claim cannot block facts on its own handoff channel');+ assert.equal(fact(2, 'Findings also belong on ordinary items').error, undefined);+ assert.equal(fact(channels[0], 'More context after the build lease ended', expired).error, undefined);+ assert.equal(fact(2, 'Expiry does not block findings', expired).error, undefined);+});+++test('an agent grant narrows at claim for accepted numeric-text item ids [E21,H16]', () => {+ const box = helpers.project();+ for (const title of ['Claimed work', 'Other work']) {+ run(box, box.repo, 'add', 'web', title, '--specs', 'G1', '--check', 'test -f web/grant-proof', '--wait');+ }+ run(box, box.web, 'claim', '1');+ const actor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === box.web).agent_id);+ const held = withBoard(box.repo, board => store.getItem(board, 1));+ // Detached baseline completion would write only the source after this replica is copied.+ // The public synchronous path finishes both setup observations before capturing the prefix.+ for (const id of [1, 2]) {+ const baseline = withBoard(box.repo, board => store.getItem(board, id).item_check_baseline);+ assert.ok(baseline, 'each setup item retains its baseline observation');+ assert.notEqual(baseline.result, 'pending', 'no setup baseline can append after replica export');+ }+ const snapshot = withBoard(box.repo, exportBoard);+ const peer = join(box.dir, 'text-id-grant-replica');+ box.git(box.dir, 'clone', '-q', box.repo, peer);+ withBoard(peer, board => importBoard(board, snapshot));+ const roots = [box.repo, peer];+ const during = new Date(Date.parse(held.item_lease_until) - 1000).toISOString();+ const expired = new Date(Date.parse(held.item_lease_until) + 1).toISOString();+ /** Keep the public engine argument bytes while both replicas resolve the same native row. */+ const change = (item, note, at = during) => {+ const move = withBoard(box.repo, board => prepareEngineMove(board, 'escalate', [item, { agentId: actor, note }]));+ const outcomes = roots.map(root => withBoard(root, board => applyEngineMove(board, move,+ { sequence: appliedSequence(board) + 1, at })));+ assert.deepEqual(outcomes[0], outcomes[1]);+ return outcomes[0];+ };+ const before = roots.map(root => withBoard(root, board => store.itemThread(board, 2)));+ for (const item of ['2', '02', '2.0', ' 2 ']) {+ assert.equal(change(item, 'An alternate spelling does not enlarge authority').error?.code, 'AGENT_GRANT_ITEM',+ `the existing target ${JSON.stringify(item)} is still outside the claim`);+ }+ assert.deepEqual(roots.map(root => withBoard(root, board => store.itemThread(board, 2))), before,+ 'numeric-text refusals add no item facts on either replica');+ assert.equal(change('1', 'Text cannot extend an expired lease', expired).error?.code, 'AGENT_GRANT_EXPIRED');+ assert.equal(change('999999', 'A missing target stays missing', expired).error?.code, 'NO_ITEM');+ assert.equal(change('not-an-id', 'Malformed text keeps its existing refusal', expired).error?.code, 'NO_ITEM');+ assert.equal(change('1', 'Accepted numeric text still names the own item').error, undefined,+ 'a state change must preserve the existing accepted item-id form');+});++/** Real Git and two private SQLite replicas; seeded acceptances are lifecycle fixtures, not executed gates. */+test('an agent grant narrows at claim without trapping its own verdict withdrawal [E21,V2,V6,H16]', t => {+ const box = helpers.project();+ let instant = Date.parse('2026-10-24T00:00:00Z');+ const clock = { now: () => new Date(instant) };+ const boards = ['withdraw-grant-primary.sqlite', 'withdraw-grant-peer.sqlite']+ .map(name => store.openBoard(join(box.dir, name), clock));+ t.after(() => boards.forEach(board => store.closeBoard(board)));+ const primary = boards[0];+ store.register(primary, { lane: 'coordinator', path: box.repo });+ const builder = store.register(primary, { lane: 'web', path: box.web, route: 'strong', parent: 'withdraw-builder', session: 'builder-child' });+ const reviewer = store.register(primary, { lane: 'tests', path: join(box.dir, 'withdraw-reviewer'), route: 'strong', parent: 'withdraw-reviewer', session: 'reviewer-child' });+ const stranger = store.register(primary, { lane: 'tests', path: join(box.dir, 'withdraw-stranger'), route: 'strong', parent: 'withdraw-stranger', session: 'stranger-child' });+ /** Supply the ordinary frozen criterion for this explicitly synthetic lifecycle setup. */+ const freeze = item => ({ text: item.item_title, digest: `withdraw:${item.item_id}` });+ const prior = store.addItem(primary, { by: 'coordinator', lane: 'tests', title: 'Earlier reviewer build' });+ const priorClaim = store.claim(primary, prior, { agentId: reviewer, lane: 'tests', leaseMs: 1000, freeze });+ const commit = box.git(box.repo, 'rev-parse', 'HEAD');+ const tree = box.git(box.repo, 'rev-parse', 'HEAD^{tree}');+ /** Create a current, immutable acceptance through the public board lifecycle. */+ function accepted(title) {+ const id = store.addItem(primary, { by: 'coordinator', lane: 'web', title });+ store.claim(primary, id, { agentId: builder, lane: 'web', leaseMs: 60_000, freeze });+ submitBoardStateFixture(primary, id, { agentId: builder, commit, tree });+ store.reserveReview(primary, id, { agentId: reviewer, leaseMs: 60_000, policy: 'any' });+ store.verify(primary, id, { agentId: reviewer, decision: 'ACCEPT', policy: 'any', head: commit,+ digest: store.getItem(primary, id).item_frozen_digest, note: 'Private lifecycle state only; no gate execution claimed.' });+ return id;+ }+ const own = accepted('Acceptance held by the different-lane reviewer');+ const control = accepted('Coordinator withdrawal positive control');+ instant += 1001;+ assert.ok(priorClaim.leaseUntil < clock.now().toISOString(), 'the earlier build lease really expired');+ assert.equal(store.getItem(primary, prior).item_status, 'open', 'the normal reader also treats that claim as expired');+ const original = store.verdictsFor(primary, own)[0];+ importBoard(boards[1], exportBoard(primary));+ /** One ordinary ordered move has the same outcome on both independent SQLite replicas. */+ function replay(operation, args) {+ const move = prepareEngineMove(primary, operation, args);+ const outcomes = boards.map(board => applyEngineMove(board, move,+ { sequence: appliedSequence(board) + 1, at: clock.now().toISOString() }));+ assert.deepEqual(outcomes[0], outcomes[1], 'the two replicas agree on the actual engine result');+ return outcomes[0];+ }+ const positive = replay('reopen', [control, { agentId: 'coordinator', withdrawVerdict: true,+ note: 'Positive control of the existing withdrawal lifecycle' }]);+ assert.equal(positive.error, undefined, 'the fixture supports a valid current verdict withdrawal');+ const conflict = replay('reopen', [own, { agentId: reviewer, conflict: { files: ['web/page.js'], trunk: commit },+ note: 'Conflict administration is not a reviewer exception' }]);+ assert.ok(conflict.error, 'a reviewer cannot substitute conflict reopening for its own verdict withdrawal');+ const withdrawn = replay('reopen', [String(own), { agentId: reviewer, withdrawVerdict: true,+ note: 'The reviewer corrects its own current acceptance after its old claim expired' }]);+ assert.equal(withdrawn.error, undefined, 'own verdict withdrawal remains review administration across lanes and expired build claims');+ for (const board of boards) {+ assert.equal(store.getItem(board, own).item_status, 'open');+ const verdict = store.verdictsFor(board, own).find(row => row.verdict_id === original.verdict_id);+ assert.equal(verdict.withdrawn, true);+ assert.equal(verdict.verdict_commit, original.verdict_commit, 'the acceptance continues to name its original commit');+ assert.equal(verdict.verdict_note, original.verdict_note, 'withdrawal never rewrites the original proof note');+ }+ const unrelated = replay('reopen', [control, { agentId: stranger, withdrawVerdict: true, note: 'Not this seat’s verdict' }]);+ assert.ok(unrelated.error, 'the exception gives a stranger no reopening authority');+});+++/** Append-only findings are communication, not authority to change item state. */+test('an agent grant narrows at claim but any joined seat can append attributed findings on every replica [E21,H16]', () => {+ const box = helpers.project();+ for (const title of ['Claimed work', 'Other work']) {+ run(box, box.repo, 'add', 'web', title, '--specs', 'G1', '--check', 'test -f web/grant-proof');+ }+ run(box, box.repo, 'add', 'api', 'Different lane', '--specs', 'G2', '--check', 'test -f api/grant-proof');+ const fresh = join(box.dir, 'finding-seat');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', fresh, 'main');+ run(box, fresh, 'join', 'web');+ const freshActor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === fresh).agent_id);+ run(box, box.web, 'claim', '1');+ const actor = withBoard(box.repo, board => store.listAgents(board).find(agent => agent.agent_path === box.web).agent_id);+ const held = withBoard(box.repo, board => store.getItem(board, 1));+ const snapshot = withBoard(box.repo, exportBoard);+ const peer = join(box.dir, 'findings-replica');+ box.git(box.dir, 'clone', '-q', box.repo, peer);+ withBoard(peer, board => importBoard(board, snapshot));+ const roots = [box.repo, peer];+ const during = new Date(Date.parse(held.item_lease_until) - 1000).toISOString();+ const expired = new Date(Date.parse(held.item_lease_until) + 1).toISOString();+ /** Apply a genuine fact record on both private boards and inspect its public attribution. */+ const finding = (item, by, at, text) => {+ const move = withBoard(box.repo, board => prepareEngineMove(board, 'appendFact',+ [item, { agentId: by, kind: 'note', text }]));+ const outcomes = roots.map(root => withBoard(root, board => applyEngineMove(board, move,+ { sequence: appliedSequence(board) + 1, at })));+ assert.deepEqual(outcomes[0], outcomes[1], 'independent replicas agree on the public result');+ assert.equal(outcomes[0].error, undefined, `${text}: ${JSON.stringify(outcomes[0])}`);+ const threads = roots.map(root => withBoard(root, board => store.itemThread(board, item)));+ assert.deepEqual(threads[0], threads[1], 'the attributed finding is the same on both replicas');+ assert.ok(threads[0].some(entry => entry.type === 'fact' && entry.text === text && entry.by === by), 'the attributed finding is actually recorded');+ };+ finding(1, actor, during, 'Positive own-item finding');+ finding(2, actor, during, 'A different claim cannot block a finding');+ finding(3, freshActor, during, 'An unclaimed seat may report a different lane');+ finding(2, actor, expired, 'An expired build claim cannot block a finding');+ finding(3, actor, expired, 'No review reservation is required for a finding');+});+++/** The activation boundary is an ordered engine prefix, not a client opening the database. */+test('an agent grant narrows at claim after the recorded engine high-water mark [E21,H16]', async t => {+ const { AGENT_GRANT_ENGINE } = await import('../src/agent-grant-engine.js');+ const box = helpers.project();+ const directory = join(box.dir, 'actual-pre-grant-writer');+ mkdirSync(directory);+ unpackRelease('e4b7c30d674cde73803f8e8cb3f53fb2f9f62621', directory);+ const oldStore = await import(pathToFileURL(join(directory, 'src/board.js')).href);+ const oldEngine = await import(pathToFileURL(join(directory, 'src/engine.js')).href);+ const oldExchange = await import(pathToFileURL(join(directory, 'src/exchange.js')).href);+ const old = oldStore.openBoard(':memory:');+ const replicas = [store.openBoard(':memory:'), store.openBoard(':memory:')];+ t.after(() => { oldStore.closeBoard(old); replicas.forEach(board => store.closeBoard(board)); });+ let sequence = 0;+ const at = new Date().toISOString();+ /** The accepted old writer records actual legacy move bytes and outcomes before activation. */+ const recordOld = (operation, args) => {+ const move = oldEngine.prepareEngineMove(old, operation, args);+ const receipt = { sequence: ++sequence, at };+ const outcome = oldEngine.applyEngineMove(old, move, receipt);+ assert.equal(outcome.error, undefined, JSON.stringify(outcome));+ return { move, receipt, outcome };+ };+ recordOld('register', [{ lane: 'coordinator', path: box.repo }]);+ const actor = recordOld('register', [{ lane: 'web', path: box.web }]).outcome.result;+ recordOld('addItem', [{ by: 'coordinator', lane: 'web', title: 'Legacy unclaimed work', criterion: 'Keep old history.' }]);+ const acknowledged = recordOld('appendFact', [1, { agentId: actor, kind: 'note', text: 'Recorded before activation.' }]);+ const snapshot = oldExchange.exportBoard(old);+ assert.ok(snapshot.tables.event.filter(event => ['join', 'claim', 'renew'].includes(event.event_kind))+ .every(event => JSON.parse(event.event_detail).grantEngine === undefined), 'the old writer emits no future marker');+ const frozen = JSON.stringify({ title: 'Legacy unclaimed work', criterion: 'Keep old history.', check: '', rows: [] });+ const staleClaim = oldEngine.prepareEngineMove(old, 'claim', [1, { agentId: actor, lane: 'web', leaseMs: 60_000,+ freeze: () => ({ text: frozen, digest: createHash('sha256').update(frozen).digest('hex') }) }]);+ const staleAdd = oldEngine.prepareEngineMove(old, 'addItem', [{ by: actor, lane: 'web', title: 'Fresh old-engine item', criterion: 'Must not bypass activation.' }]);+ assert.ok(staleClaim.engine < AGENT_GRANT_ENGINE);+ for (const board of replicas) importBoard(board, snapshot);+ const activation = prepareEngineMove(replicas[0], 'shout', [{ from: 'coordinator', to: actor, text: 'The modern engine is now recorded.', lanes: ['web'] }]);+ assert.ok(activation.engine >= AGENT_GRANT_ENGINE);+ const activationReceipt = { sequence: sequence + 1, at };+ const activated = replicas.map(board => applyEngineMove(board, activation, activationReceipt));+ assert.deepEqual(activated[0], activated[1]);+ assert.equal(activated[0].error, undefined);+ for (const board of replicas) {+ assert.deepEqual(applyEngineMove(board, acknowledged.move, acknowledged.receipt), acknowledged.outcome,+ 'the acknowledged pre-activation receipt replays byte-for-byte after activation');+ const before = appliedSequence(board);+ for (const move of [staleClaim, staleAdd]) {+ assert.throws(() => applyEngineMove(board, move, { sequence: before + 1, at }),+ error => error.code === 'RELAY_MOVE' && error.message.includes(String(AGENT_GRANT_ENGINE)),+ 'a newly ordered old-engine move cannot use wholly unmarked legacy seats or targets');+ assert.equal(appliedSequence(board), before, 'a version refusal leaves the ordered position retryable');+ }+ assert.equal(store.getItem(board, 1).item_status, 'open');+ }+});+++ test('a non-approver device without a signed member list receives no board key [H15,E17]', async t => {+ const folder = mkdtempSync(join(tmpdir(), 'pullboard-handover-membership-'));+ t.after(() => rmSync(folder, { recursive: true, force: true }));+ const box = helpers.project();+ const state = { board: withBoard(box.repo, store.boardId), repository: 'fixture/repository', login: 'alice' };+ const boardKey = randomBytes(32);+ /** Make an actual SSH signature and device key, independent of what the malicious relay asserts. */+ async function request(login) {+ const file = join(folder, login);+ const made = runFixtureChild('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-f', file], { encoding: 'utf8' });+ assert.equal(made.status, 0, 'OpenSSH creates the private fixture signing key');+ const device = await createDeviceKeys();+ const statement = { v: 1, board: state.board, repository: state.repository, login, device: device.deviceId,+ publicKey: device.publicKey, engine: PEOPLE_VERSION, expires: Date.now() + 60_000 };+ const input = file + '.statement';+ writeFileSync(input, statementBytes(statement), { mode: 0o600 });+ const signed = runFixtureChild('ssh-keygen', ['-Y', 'sign', '-q', '-n', 'pullboard-device-key', '-f', file, input], { encoding: 'utf8' });+ assert.equal(signed.status, 0, "the request is genuinely signed by that login's SSH key");+ return { device, signingKey: file, publicKey: readFileSync(file + '.pub', 'utf8').trim().split(' ').slice(0, 2).join(' '),+ entry: { id: login, login, statement, signature: readFileSync(input + '.sig', 'utf8') } };+ }+ const outsider = await request('bob');+ const member = await request('alice');+ const body = { v: 1, board: state.board, repository: state.repository, login: 'alice' };+ const identity = { body, signature: signSshVouch(JSON.stringify(['pullboard-person-identity', body]), 'pullboard-person-identity', member.signingKey) };+ /** Present attacker-controlled relay entries while resolving SSH ownership directly for each account. */+ async function answer(person) {+ const deliveries = [];+ await handOverBoardKeys(state, boardKey, {+ root: box.repo, identity,+ async send(_state, _path, options) {+ if (options.method === 'PUT') { deliveries.push(options.body); return {}; }+ return { requests: [person.entry] };+ },+ async githubKeys(login) { return login === person.entry.login ? [person.publicKey] : []; },+ }, { err() {} });+ assert.equal(deliveries.length, 1, 'each request gets one explicit refusal or delivery');+ return deliveries[0];+ }+ const refused = await answer(outsider);+ const leaked = refused.wrapped ? await unwrapDeviceBoardKey(outsider.device.privateKey,+ JSON.parse(Buffer.from(refused.wrapped, 'base64url').toString('utf8')),+ { board: state.board, device: outsider.device.deviceId, engine: PEOPLE_VERSION }) : null;+ assert.equal(leaked !== null && Buffer.from(leaked).equals(boardKey), false, 'the outsider cannot decrypt the actual board key');+ assert.equal(refused.refused?.code, 'RELAY_NOT_MEMBER', 'a valid outsider signature cannot establish trusted board membership');+ assert.equal(Object.hasOwn(refused, 'wrapped'), false, 'the relay receives no key ciphertext it could unwrap as the outsider');+ const allowed = await answer(member);+ assert.ok(allowed.wrapped, 'the linked person can still bootstrap their own independently vouched device');+ const unwrapped = await unwrapDeviceBoardKey(member.device.privateKey,+ JSON.parse(Buffer.from(allowed.wrapped, 'base64url').toString('utf8')),+ { board: state.board, device: member.device.deviceId, engine: PEOPLE_VERSION });+ assert.deepEqual(Buffer.from(unwrapped), boardKey, 'the legitimate new device receives the actual board key');+ });