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
chore(merge): integrate accepted decision answer guard [H16,B26]
Corey Olson5bb1da89bbd7
diff --cc test/engine.test.jsindex 2598c416,c53d19e8..c541b85a--- a/test/engine.test.js+++ b/test/engine.test.js@@@ -117,54 -117,19 +117,67 @@@ test('missing relay senders are refuseassert.deepEqual(exportBoard(one).tables, exportBoard(two).tables);});+test('sealed shouts cannot bypass addressee, already answered or person decision rules [H16,B26]', t => {+ const questions = [];+ const { copies } = engineCopies(t, source => {+ const lanes = ['web'];+ questions.push(store.shout(source, { from: 'coordinator', to: 'person', text: 'Person decision', decision: true, lanes }));+ questions.push(store.shout(source, { from: 'coordinator', to: 'web-2', text: 'Another agent decision', decision: true, lanes }));+ const closed = store.shout(source, { from: 'coordinator', to: 'web-1', text: 'Already answered decision', decision: true, lanes });+ store.answerDecision(source, closed, { agentId: 'web-1', text: 'Original answer', lanes });+ questions.push(closed);+ questions.push(store.shout(source, { from: 'web-1', to: 'coordinator', text: 'Needs passing', decision: true, lanes }));+ });+ for (const board of copies) {+ const original = exportBoard(board);+ let sequence = 0;+ for (const sender of [{ kind: 'agent', userId: 'fixture-user', agent: 'web-1' }, { kind: 'person', userId: 'fixture-user' }]) {+ for (const answers of questions.slice(0, 3)) {+ const move = prepareEngineMove(board, 'shout', [{ from: 'web-1', to: 'coordinator', text: 'Bypass attempted', answers, lanes: ['web'] }], { id: 'bypass-' + ++sequence });+ const refused = applyRelayMove(board, move, { sequence, at: CLAIM_AT, kind: 'move', sender });+ assert.equal(refused.error?.code, 'RELAY_ANSWER');+ assert.match(refused.error.next, /pullboard answer.*pullboard pass/);+ assert.deepEqual(exportBoard(board).tables.shout, original.tables.shout);+ assert.deepEqual(exportBoard(board).tables.item, original.tables.item);+ }+ }+ const agentSender = { kind: 'agent', userId: 'fixture-user', agent: 'web-1' };+ for (const [index, expected] of ['NOT_YOUR_DECISION', 'NOT_YOUR_DECISION', 'ALREADY_ANSWERED'].entries()) {+ const move = prepareEngineMove(board, 'answerDecision', [questions[index], { agentId: 'web-1', text: 'Guarded attempt', lanes: ['web'] }], { id: 'answer-' + ++sequence });+ assert.equal(applyRelayMove(board, move, { sequence, at: CLAIM_AT, kind: 'move', sender: agentSender }).error.code, expected);+ assert.deepEqual(exportBoard(board).tables.shout, original.tables.shout);+ }+ assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [questions[0]]);+ const permitted = prepareEngineMove(board, 'answerDecision', [questions[0], { agentId: 'coordinator', asPerson: true, text: 'Person answered', lanes: ['web'], channel: 'view' }], { id: 'person-answer' });+ assert.equal(Boolean(applyRelayMove(board, permitted, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: { kind: 'person', userId: 'fixture-user' } }).error), false);+ assert.deepEqual(store.openDecisions(board, 'person'), []);+ const personSender = { kind: 'person', userId: 'fixture-user' };+ const pass = prepareEngineMove(board, 'passDecision', [questions[3], { agentId: 'coordinator', note: 'Needs the person', lanes: ['web'] }], { id: 'guarded-pass' });+ const passed = applyRelayMove(board, pass, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: personSender });+ assert.equal(Boolean(passed.error), false);+ assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [passed.result]);+ const response = prepareEngineMove(board, 'answerDecision', [passed.result, { agentId: 'coordinator', asPerson: true, text: 'Passed decision answered', lanes: ['web'] }], { id: 'passed-answer' });+ assert.equal(Boolean(applyRelayMove(board, response, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: personSender }).error), false);+ assert.deepEqual(store.openDecisions(board, 'person'), []);+ assert.deepEqual(store.openDecisions(board, 'coordinator'), []);+ assert.ok(exportBoard(board).tables.shout.some(row => row.shout_answers === questions[3] && row.shout_from === 'person'), 'guarded person answers reach the original asker');+ }+ assert.deepEqual(exportBoard(copies[0]).tables, exportBoard(copies[1]).tables);+});++ test('future engine relay records stop before every sender shape without changing a replica [H16]', t => {+ const { copies, item } = engineCopies(t);+ const move = { ...claimMove(copies[0], item, 'web-1'), engine: ENGINE_VERSION + 1 };+ for (const sender of [undefined, {}, { kind: 'person', userId: 'fixture-user' }, { kind: 'agent', userId: 'fixture-user', agent: 'web-2' }]) {+ for (const board of copies) {+ const before = exportBoard(board);+ assert.throws(() => applyRelayMove(board, move, { sequence: 1, at: CLAIM_AT, kind: 'request', sender }), error => error.code === 'ENGINE_VERSION');+ assert.deepEqual(exportBoard(board), before);+ assert.equal(appliedSequence(board), 0);+ }+ }+ });+test('a relay refusal receipt failure rolls back its log and cursor together [H2,H16]', t => {const { copies, item } = engineCopies(t);const board = copies[0];diff --cc test/relay-sealed.test.jsindex 62b3efd3,46ed25f3..5174cef2--- a/test/relay-sealed.test.js+++ b/test/relay-sealed.test.js@@@ -145,115 -145,87 +145,196 @@@ function replayResult(root, env, ...arg});}+test('sealed agent shout cannot answer a person decision on either independent client [H16,B26]', async t => {+ const box = await fixture(t);+ const source = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));+ let document, question, forged, ordinary, answer;+ try {+ const lane = store.getItem(source, 1).item_lane;+ assert.equal(store.register(source, { lane: 'remote', path: join(box.directory, 'remote') }), 'remote-1');+ question = store.shout(source, {+ from: 'coordinator', to: 'person', text: 'Approve this change?', decision: true, lanes: [lane],+ });+ checkpointSequence(source, 0);+ // This is intentionally a raw authenticated-agent shout, not answerDecision.+ // The relay must reject its answer relation before insertShout can close the question.+ forged = prepareEngineMove(source, 'shout', [{+ from: 'remote-1', to: 'coordinator', text: 'Forged approval', answers: question, lanes: [lane],+ }]);+ ordinary = prepareEngineMove(source, 'shout', [{+ from: 'remote-1', to: 'all', text: 'Ordinary agent observation', lanes: [lane],+ }]);+ answer = prepareEngineMove(source, 'answerDecision', [question, {+ agentId: 'coordinator', asPerson: true, text: 'Approved by the person', lanes: [lane],+ }]);+ document = JSON.parse(JSON.stringify(exportBoard(source)));+ } finally { store.closeBoard(source); }++ const remote = await box.auth.issueToken(box.person.token, { board: box.id, agent: 'remote-1' });+ const roots = [box.root, join(box.directory, 'second-client')];+ const homes = [box.home, join(box.directory, 'second-home')];+ const envs = homes.map(home => ({ ...box.env, HOME: home, PULLBOARD_HOME: home }));+ mkdirSync(roots[1]); mkdirSync(homes[1], { mode: 0o700 });+ assert.equal(spawnSync('git', ['init', '-q', '-b', 'main'], { cwd: roots[1], env: envs[1] }).status, 0);+ await replayClient(roots[1], envs[1], 'init');+ const native = join(box.directory, 'native.json');+ writeFileSync(native, JSON.stringify(document), { mode: 0o600 });+ await replayClient(roots[1], envs[1], 'import', native);+ for (let i = 0; i < roots.length; i++) {+ const keyDirectory = join(homes[i], 'relay-keys');+ mkdirSync(keyDirectory, { mode: 0o700 });+ writeFileSync(join(keyDirectory, box.id + '.key'), box.key.toString('base64url') + '\n', { mode: 0o600 });+ const url = await independentReplayOrigin(t, box.origin);+ writeFileSync(join(roots[i], '.git/pullboard/relay.json'), JSON.stringify({+ version: 1, mode: 'ordered', board: box.id, url, repository: 'fixture/repository',+ token: box.person.token, sequence: 0, cursor: document.tables.event.at(-1).event_id,+ }) + '\n', { mode: 0o600 });+ }++ /** Send a production-sealed move using its actual authenticated relay credential. */+ async function upload(move, sequence, token = remote.token) {+ const sealed = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(move)), {+ boardId: box.id, kind: 'move', sequence,+ })).toString('base64url');+ const reply = await box.call(box.path + '/moves', {+ method: 'POST', token, body: { sequence, sealed },+ });+ assert.equal(reply.status, 200);+ return reply;+ }+ const snapshot = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(document)), {+ boardId: box.id, kind: 'snapshot', sequence: 0,+ })).toString('base64url');+ assert.equal((await box.call(box.path + '/state', {+ method: 'PUT', token: box.person.token, body: { sequence: 0, sealed: snapshot },+ })).status, 200);+ const forgedUpload = await upload(forged, 1);+ assert.equal(forgedUpload.body.event.sender.agent, 'remote-1');+ await upload(ordinary, 2);++ const refusedReplicas = [];+ for (let i = 0; i < roots.length; i++) {+ const result = await replayResult(roots[i], envs[i], 'export');+ assert.equal(result.status, 0);+ const doc = result.document;+ const q = doc.tables.shout.find(row => row.shout_id === question);+ assert.ok(q && q.shout_decision, 'the person decision remains present');+ assert.equal(doc.tables.shout.some(row => row.shout_answers === question), false, 'the refused agent record did not answer it');+ assert.equal(doc.tables.shout.at(-1).shout_text, 'Ordinary agent observation', 'ordinary agent shouts remain allowed');+ const refusal = doc.tables.event.find(row => row.event_kind === 'relay_refused' && row.event_by === 'remote-1');+ assert.equal(JSON.parse(refusal.event_detail).code, 'RELAY_ANSWER');+ assert.equal(doc.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value, '2');+ const board = store.openBoard(join(roots[i], '.git/pullboard/board.sqlite'));+ try { assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [question]); }+ finally { store.closeBoard(board); }+ refusedReplicas.push(doc.tables);+ }+ assert.deepEqual(refusedReplicas[0], refusedReplicas[1], 'both clients independently replay the refusal and allowed shout');+ const beforeAnswer = refusedReplicas[0];++ // A valid, sealed person decision preserves the existing guarded answer path.+ await upload(answer, 3, box.person.token);+ const answered = [];+ for (let i = 0; i < roots.length; i++) {+ const result = await replayResult(roots[i], envs[i], 'export');+ assert.equal(result.status, 0);+ const doc = result.document;+ assert.equal(doc.tables.shout.some(row => row.shout_answers === question && row.shout_text === 'Approved by the person'), true);+ assert.equal(doc.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value, '3');+ assert.deepEqual(doc.tables.event.slice(0, beforeAnswer.event.length), beforeAnswer.event, 'the guarded answer preserves every earlier event row');+ assert.deepEqual(doc.tables.shout.slice(0, beforeAnswer.shout.length), beforeAnswer.shout, 'the guarded answer preserves earlier shout IDs and raw rows');+ const board = store.openBoard(join(roots[i], '.git/pullboard/board.sqlite'));+ try { assert.deepEqual(store.openDecisions(board, 'person'), []); }+ finally { store.closeBoard(board); }+ answered.push(doc.tables);+ }+ assert.deepEqual(answered[0], answered[1], 'both clients apply the actual guarded person answer identically');+ const retained = await box.call(box.path + '/state');+ assert.equal(retained.body.state.sequence, 0);+ assert.equal(retained.body.state.sealed, snapshot, 'both clients independently replayed rather than importing a published checkpoint');+});++ test('two real clients stop before sender checks for newer operations and actor layouts without advancing [H16]', async t => {+ const unknown = { version: 1, engine: 4, id: 'future-operation', operation: 'futureOp', args: [{ agentId: 'remote-1' }] };+ const shifted = { version: 1, engine: 4, id: 'future-claim', operation: 'claim', args: [1, {}, { agentId: 'remote-1' }] };+ for (const [name, moves] of [['new operation', [unknown]], ['new actor layout', [shifted]], ['current engine sender checks', [unknown, shifted].map(move => ({ ...move, engine: 3 }))]]) {+ await t.test(name, async sub => {+ const box = await fixture(sub);+ const source = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));+ let document;+ try {+ checkpointSequence(source, 0);+ document = JSON.parse(JSON.stringify(exportBoard(source)));+ } finally { store.closeBoard(source); }+ const remote = await box.auth.issueToken(box.person.token, { board: box.id, agent: 'remote-1' });+ const roots = [box.root, join(box.directory, 'second-client')];+ const homes = [box.home, join(box.directory, 'second-home')];+ const envs = homes.map(home => ({ ...box.env, HOME: home, PULLBOARD_HOME: home }));+ mkdirSync(roots[1]); mkdirSync(homes[1], { mode: 0o700 });+ assert.equal(spawnSync('git', ['init', '-q', '-b', 'main'], { cwd: roots[1], env: envs[1] }).status, 0);+ await replayClient(roots[1], envs[1], 'init');+ const native = join(box.directory, 'native.json');+ writeFileSync(native, JSON.stringify(document), { mode: 0o600 });+ await replayClient(roots[1], envs[1], 'import', native);+ const links = roots.map(root => join(root, '.git/pullboard/relay.json'));+ for (let index = 0; index < roots.length; index += 1) {+ const keyDirectory = join(homes[index], 'relay-keys');+ mkdirSync(keyDirectory, { mode: 0o700 });+ writeFileSync(join(keyDirectory, box.id + '.key'), box.key.toString('base64url') + '\n', { mode: 0o600 });+ const replayOrigin = await independentReplayOrigin(sub, box.origin);+ writeFileSync(links[index], JSON.stringify({ version: 1, mode: 'ordered', board: box.id, url: replayOrigin, repository: 'fixture/repository', token: box.person.token, sequence: 0, cursor: document.tables.event.at(-1).event_id }) + '\n', { mode: 0o600 });+ }+ const originalLinks = links.map(file => readFileSync(file, 'utf8'));+ const initialSnapshot = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(document)), { boardId: box.id, kind: 'snapshot', sequence: 0 })).toString('base64url');+ assert.equal((await box.call(box.path + '/state', { method: 'PUT', token: box.person.token, body: { sequence: 0, sealed: initialSnapshot } })).status, 200);+ for (let index = 0; index < moves.length; index += 1) {+ const sequence = index + 1;+ const sealed = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(moves[index])), { boardId: box.id, kind: 'move', sequence })).toString('base64url');+ const uploaded = await box.call(box.path + '/moves', { method: 'POST', token: remote.token, body: { sequence, sealed } });+ assert.equal(uploaded.status, 200);+ assert.equal(uploaded.body.event.sender.agent, 'remote-1');+ }+ const results = [];+ for (let index = 0; index < roots.length; index += 1) {+ const result = await replayResult(roots[index], envs[index], 'export');+ assert.equal(result.status, 0);+ results.push(result.document);+ if (moves[0].engine === 4) {+ assert.match((result.document.diagnostics ?? []).join('\n'), /\[ENGINE_VERSION\].*engine version 4.*engine version 3.*upgrade pullboard/, 'future records stop before interpreting the sending agent');+ assert.deepEqual(result.document.tables, document.tables, 'no board row, receipt or persisted cursor changes');+ assert.equal(readFileSync(links[index], 'utf8'), originalLinks[index], 'the saved transport cursor is unchanged');+ const retried = await replayResult(roots[index], envs[index], 'export');+ assert.match((retried.document.diagnostics ?? []).join('\n'), /\[ENGINE_VERSION\]/);+ assert.equal(retried.status, 0);+ assert.deepEqual(retried.document.tables, document.tables, 'retry still stops at the same unapplied record');+ const attempted = await replayResult(roots[index], envs[index], 'add', document.tables.item[0].item_lane, 'Later local move must wait');+ assert.equal(attempted.status, 1);+ assert.equal(attempted.document.error.code, 'ENGINE_VERSION');+ assert.match(attempted.document.error.message, /engine version 4.*engine version 3/);+ assert.equal(readFileSync(links[index], 'utf8'), originalLinks[index]);+ const board = store.openBoard(join(roots[index], '.git/pullboard/board.sqlite'));+ try { assert.deepEqual(JSON.parse(JSON.stringify(exportBoard(board))).tables, document.tables, 'a later local mutation cannot pass the future record'); }+ finally { store.closeBoard(board); }+ } else {+ assert.doesNotMatch((result.document.diagnostics ?? []).join('\n'), /\[ENGINE_VERSION\]/);+ assert.deepEqual(result.document.tables.item, document.tables.item);+ assert.deepEqual(result.document.tables.shout, document.tables.shout);+ assert.deepEqual(result.document.tables.verdict, document.tables.verdict);+ const refused = result.document.tables.event.filter(row => row.event_kind === 'relay_refused');+ assert.deepEqual(refused.map(row => JSON.parse(row.event_detail).code), ['RELAY_SENDER_MISMATCH', 'RELAY_SENDER_MISMATCH']);+ assert.ok(refused.every(row => row.event_by === 'remote-1'));+ assert.equal(result.document.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value, '2');+ assert.equal(JSON.parse(readFileSync(links[index], 'utf8')).sequence, 2);+ }+ }+ assert.deepEqual(results[0].tables, results[1].tables, 'the two independent clients retain identical board rows');+ const snapshot = await box.call(box.path + '/state');+ assert.equal(snapshot.body.state.sequence, 0);+ assert.equal(snapshot.body.state.sealed, initialSnapshot, 'neither client replaced independent replay with a shared checkpoint');+ });+ }+ });+test('two real clients refuse forged relay actors and person-only requests while advancing identically [H2,H16]', async t => {const box = await fixture(t);const source = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));