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(rigor): only a person sender records a never-again [D1,H16,B26]
Corey Olsona08bf8562a8a
diff --git a/docs/api.md b/docs/api.mdindex 639d98e1..26e2af54 100644--- a/docs/api.md+++ b/docs/api.md@@ -159,7 +159,7 @@ Rigor is how errors become doctrine or specs. It starts by noticing a failure ca`pullboard rigor` is read-only. It lists each cause that repeated: on 2 items, or on 1 item at 2 different commits. Each line shows the key, how it reads (`work` for `doctrine:` and `refusal:`, `product` for `row:`, `both` for `test:`), its failure count and its items. Its JSON result is `{version, causes: [{key, reads, occurrences, neverAgain, items: [{id, commits}]}], uncaused}`; `uncaused` counts rejects and reopens with no cause key.-The person can mark a cause never-again from the main checkout's terminal: `pullboard fact <id> root-cause "<why>" --cause <key> --never-again --as person`. The fact is recorded as the person's, carries `cause` and `neverAgain: true`, and `rigor` lists its cause at once. An agent or a fact without `--as person` is refused with `RIGOR_PERSON_ONLY`. A move that carries a cause key needs move engine 13; moves without one replay as before.+The person can mark a cause never-again from the main checkout's terminal: `pullboard fact <id> root-cause "<why>" --cause <key> --never-again --as person`. The fact is recorded as the person's, carries `cause` and `neverAgain: true`, and `rigor` lists its cause at once. An agent or a fact without `--as person` is refused with `RIGOR_PERSON_ONLY`. Over the relay, a fact move with person mode, a never-again or a cause key is accepted only from an authenticated person sender; an agent, a coordinator seat or the machine credential is refused with `RELAY_PERSON_ONLY` whatever channel the move names, and nothing is recorded. A move that carries a cause key needs move engine 13; moves without one replay as before.## Refusalsdiff --git a/src/relay-sender.js b/src/relay-sender.jsindex e6a284d3..e088ac2f 100644--- a/src/relay-sender.js+++ b/src/relay-sender.js@@ -22,6 +22,16 @@ export function validRelaySender(sender) {(sender.kind !== 'machine' || (typeof sender.machine === 'string' && sender.machine.length > 0 && sender.machine.length <= 256)));}+/**+ * True for a fact move that claims the person's authority: a never-again, a cause key, or person+ * mode (#713). Only an authenticated person sender may make it, whatever channel it names, so no+ * agent, coordinator seat or machine credential can make rigor list a cause as the person's.+ */+function personFact(move) {+ const options = move?.operation === 'appendFact' ? move.args?.[1] : null;+ return Boolean(options && typeof options === 'object' && (options.asPerson || options.neverAgain || (options.cause !== undefined && options.cause !== null)));+}+/** Make the same authorization decision on every device, without inspecting its shell or checkout. */export function relaySenderProblem(move, sender, kind, { phoneReceipt = false } = {}) {if (!validRelaySender(sender)) {@@ -31,6 +41,9 @@ export function relaySenderProblem(move, sender, kind, { phoneReceipt = false }return new Refused('RELAY_ANSWER', 'a sealed shout cannot answer or pass a decision; use pullboard answer <id> "<answer>" or pullboard pass <id> --note "<reason>" so the decision rules are checked');}if (sender.kind === 'person') return null;+ if (personFact(move)) {+ return new Refused('RELAY_PERSON_ONLY', `${sender.kind === 'agent' ? `agent ${sender.agent}` : 'a machine'} cannot record the person's never-again; the person marks it from their own session`);+ }if (sender.kind === 'machine') {if (kind === 'snapshot') return null;if (kind === 'move' && move?.engine >= 6 && (phoneReceipt ||diff --git a/test/relay-rigor.test.js b/test/relay-rigor.test.jsnew file mode 100644index 00000000..29e7fda5--- /dev/null+++ b/test/relay-rigor.test.js@@ -0,0 +1,104 @@+/** Over the real relay, only an authenticated person sender records a never-again fact [D1,H16,B26]. */+import assert from 'node:assert/strict';+import { readFileSync } from 'node:fs';+import { join } from 'node:path';+import { test } from 'node:test';+import { closeBoard, events, openBoard, PERSON } from '../src/board.js';+import { applyRelayMove, prepareEngineMove } from '../src/engine.js';+import { exportBoard, importBoard } from '../src/exchange.js';+import { ENGINE_VERSION } from '../src/machine.js';+import { rigorReport } from '../src/rigor.js';+import { decodeBoardKey, seal, unseal } from '../src/seal.js';+import { relayClientFixture } from './relay-client-fixture.js';++/** Call the real relay API with one bearer credential and the current engine header. */+async function relay(box, path, token, { method = 'GET', body } = {}) {+ const response = await fetch(box.origin + path, {+ method, headers: { authorization: 'Bearer ' + token, 'x-pullboard-engine': String(ENGINE_VERSION), ...(body ? { 'content-type': 'application/json' } : {}) },+ ...(body ? { body: JSON.stringify(body) } : {}),+ });+ return { status: response.status, body: await response.json() };+}++/** Mint a real board-scoped agent token for one seat through the machine credential. */+async function agentToken(box, link, agent) {+ const minted = await relay(box, '/auth/tokens', link.token, { method: 'POST', body: { board: link.board, agent } });+ assert.equal(minted.status, 201, `the relay mints a token for ${agent}: ${JSON.stringify(minted.body)}`);+ return minted.body.token;+}++test('only an authenticated person sender records a never-again over the relay [D1,H16,B26]', async (t) => {+ const box = await relayClientFixture(t);+ const added = await box.cli('add', box.lane, 'Never-again target', '--criterion', 'a person marks a cause never again');+ assert.equal(added.code, 0, JSON.stringify(added.document));+ const id = added.document.item.item_id;+ await box.link();+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));+ const key = decodeBoardKey(readFileSync(box.keyFile, 'utf8').trim());+ const file = join(box.root, '.git', 'pullboard', 'board.sqlite');++ // A second replica starts from the native board as it is before any never-again move.+ assert.equal((await box.cli('status')).code, 0);+ const native = openBoard(file);+ const before = exportBoard(native);+ const start = Number(before.tables.board_meta.find((row) => row.meta_key === 'relay_applied_sequence')?.meta_value ?? 0);+ /** Seal the person-mode fact move a sender attempts, as the CLI would. */+ const attempt = (label, extra) => prepareEngineMove(native, 'appendFact', [id, {+ agentId: 'coordinator', kind: 'root-cause', text: `never again from ${label}`, cause: 'doctrine:C3', neverAgain: true, asPerson: true, channel: 'view', ...extra,+ }], { id: `rigor-relay-${label}` });+ const moves = [+ ['agent', attempt('agent', { agentId: 'rigor-relay-agent' })],+ ['machine', attempt('machine')],+ ['coordinator', attempt('coordinator')],+ ['coordinator-cause-only', prepareEngineMove(native, 'appendFact', [id, { agentId: 'coordinator', kind: 'note', text: 'a cause with no person mode', cause: 'doctrine:C3' }], { id: 'rigor-relay-cause-only' })],+ ['person', attempt('person')],+ ];+ closeBoard(native);+ const tokens = {+ agent: await agentToken(box, link, 'rigor-relay-agent'),+ machine: link.token,+ coordinator: await agentToken(box, link, 'coordinator'),+ 'coordinator-cause-only': null,+ person: (await box.phoneSession()).token,+ };+ tokens['coordinator-cause-only'] = tokens.coordinator;+ let sequence = (await relay(box, `/api/v1/boards/${link.board}/state`, link.token)).body.state.sequence;+ for (const [label, move] of moves) {+ sequence += 1;+ const sealed = Buffer.from(await seal(key, new TextEncoder().encode(JSON.stringify(move)), { boardId: link.board, kind: 'move', sequence })).toString('base64url');+ const stored = await relay(box, `/api/v1/boards/${link.board}/moves`, tokens[label], { method: 'POST', body: { sequence, sealed } });+ assert.equal(stored.status, 200, `the relay stores the ${label} envelope: ${JSON.stringify(stored.body)}`);+ }++ // Read the sealed journal as the relay stored it, before the native replica checkpoints past it.+ const read = await relay(box, `/api/v1/boards/${link.board}/events?after=${start}`, link.token);+ assert.equal(read.status, 200, JSON.stringify(read.body));+ const journal = read.body.events;+ assert.ok(journal.length >= moves.length, 'the journal holds every attempted move');++ // The native replica replays the journal and records each refusal by its sealed sender.+ assert.equal((await box.cli('status')).code, 0, 'native replay records the refusals and the person fact');+ const exported = (await box.cli('export')).document;+ const refusals = exported.tables.event.filter((row) => row.event_kind === 'relay_refused').map((row) => [row.event_by, JSON.parse(row.event_detail).code]);+ assert.deepEqual(refusals.slice(-4), [['rigor-relay-agent', 'RELAY_PERSON_ONLY'], [refusals.at(-3)[0], 'RELAY_PERSON_ONLY'], ['coordinator', 'RELAY_PERSON_ONLY'], ['coordinator', 'RELAY_PERSON_ONLY']],+ 'an agent, the machine credential and the coordinator seat are refused RELAY_PERSON_ONLY');+ const facts = exported.tables.event.filter((row) => row.event_kind === 'fact');+ assert.deepEqual(facts.map((row) => [row.event_by, JSON.parse(row.event_detail).text]), [[PERSON, 'never again from person']],+ 'only the person sender recorded a fact; nothing was recorded for the refused senders');+ assert.deepEqual(rigorReport(exported.tables.event.map((row) => ({ ...row })), { person: PERSON }).causes.map((cause) => cause.key), ['doctrine:C3']);++ // A second replica replays the same sealed journal, with the relay's sender metadata, identically.+ const replica = openBoard(join(box.root, '.git', 'rigor-replica.sqlite'));+ t.after(() => closeBoard(replica));+ importBoard(replica, before);+ for (const record of journal) {+ const plain = JSON.parse(new TextDecoder().decode(await unseal(key, Buffer.from(record.sealed, 'base64url'), { boardId: link.board, kind: record.kind, sequence: record.event_id })));+ if (record.kind !== 'move') continue;+ const outcome = applyRelayMove(replica, plain, { sequence: record.event_id, at: record.event_at, sender: record.sender, kind: record.kind });+ const label = moves.find(([, move]) => move.id === plain.id)?.[0];+ if (label) assert.equal(outcome.error?.code, label === 'person' ? undefined : 'RELAY_PERSON_ONLY', `${label} replays with the same verdict`);+ }+ const replayed = events(replica).filter((row) => ['fact', 'relay_refused'].includes(row.event_kind)).map(({ event_by, event_kind, event_detail }) => ({ event_by, event_kind, event_detail }));+ const nativeRows = exported.tables.event.filter((row) => ['fact', 'relay_refused'].includes(row.event_kind)).map(({ event_by, event_kind, event_detail }) => ({ event_by, event_kind, event_detail }));+ assert.deepEqual(replayed, nativeRows, 'two replicas replay the same journal identically');+});