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
feat(api): resolve addressed shout history [N38]
Corey Olson681abab0831f
diff --git a/docs/api.md b/docs/api.mdindex d003ce8f..19a21650 100644--- a/docs/api.md+++ b/docs/api.md@@ -131,12 +131,15 @@ The server checks any Origin against its own address and grants no CORS permissi| --- | --- || `GET /api/v1/boards` | Registered boards with their project details and ids || `GET /api/v1/boards/:board/state?seen=N` | The view's board state, including open coordinator requests and the unseen shout count since N |+| `GET /api/v1/boards/:board/shouts/:id` | One shout from any point in the board's history, including its decision and answer fields || `GET /api/v1/boards/:board/code?ref=path:lines@commit&before=...` | A bounded preview of committed file lines from that registered board || `GET /api/v1/boards/:board/events?after=N` | Events after sequence N, in order, and their event-log format version || `POST /api/v1/boards/:board/moves` | One CLI move and its emitted event || `POST /api/v1/boards/:board/requests` | A person's request for the coordinator |-The boards response keeps `boards` and may include `warnings` for registered entries that could not be opened. State `seen` must be a nonnegative safe integer; omitting it retains the `unseen: null` result. Code previews read only a registered repo's committed tree, use a plain commit SHA and at most 60 lines, and never read the working tree. The shared router lets adapters omit the optional code capability; such adapters return the versioned `CODE_NOT_AVAILABLE` refusal.+The boards response keeps `boards` and may include `warnings` for registered entries that could not be opened. State `seen` must be a nonnegative safe integer; omitting it retains the `unseen: null` result. State continues to include only the newest 40 shouts. Use `GET /api/v1/boards/:board/shouts/:id` to resolve an older address; its `{ shout }` result contains the complete stored shout row, including sender, recipient, text, timestamp, decision flag and reply relationship. Decision shouts also include `decision_state` (`open` or `answered`) and `decision_answer` (the reply row or `null`); other shouts use `null` for both fields. A missing id returns `NO_SHOUT` with HTTP 404; malformed ids are refused with HTTP 400. Code previews read only a registered repo's committed tree, use a plain commit SHA and at most 60 lines, and never read the working tree. The shared router lets adapters omit the optional code capability; such adapters return the versioned `CODE_NOT_AVAILABLE` refusal.++Core readers can call `allShouts(board)` for every stored shout, oldest first, without advancing any agent's unread cursor. Static exports can use that read to retain text for old shout addresses. Relay snapshots carry the same history only inside their authenticated, encrypted presentation; the relay service receives no plaintext shout history. Older presentations without complete history return `SHOUT_NOT_AVAILABLE`; refresh them with a current CLI.The local board state and events responses include `eventLogVersion`, which identifies the persisted event-record format separately from the HTTP envelope's `version`. Static view exports keep this field in both state.json and events.json so a reader can refuse a format newer than it understands. Sealed relay events do not use this local board format marker.@@ -147,6 +150,7 @@ The coordinator maintains the roadmap with `milestone add <name> [--note ...] [-| --- | --- || `boards` | `version:number`, `boards:array` || `state` | `version:number`, `state:object` |+| `shout` | `version:number`, `shout:object` || `events` | `version:number`, `events:array` || `move` | `version:number`, `event:object`, `result:object` || `request` | `version:number`, `event:object`, `result:object` |@@ -173,7 +177,7 @@ For live events, send `Accept: text/event-stream` to the events path. Each messaThe local server uses a shared HTTP router. Streams recheck access before each poll and close with a versioned refusal if access ends. Slow readers pause delivery and resume from the last delivered sequence.-HTTP refusals use the same versioned error envelope above: 400 for malformed calls, 401 for a missing or wrong session secret, 403 for an agent belonging to another board, 404 for an unknown board or path, and 409 for the CLI engine's refusal. Shouts and answers append their events in the same transaction as their records. A move returns its own event, including when it also sends a coordinator shout.+HTTP refusals use the same versioned error envelope above: 400 for malformed calls, 401 for a missing or wrong session secret, 403 for an agent belonging to another board, 404 for an unknown board, path or shout, and 409 for the CLI engine's refusal. Shouts and answers append their events in the same transaction as their records. A move returns its own event, including when it also sends a coordinator shout.## SSH spec sign-offsdiff --git a/src/api-http.js b/src/api-http.jsindex d01fcec4..fa4518d3 100644--- a/src/api-http.js+++ b/src/api-http.js@@ -105,13 +105,22 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {let url;try { url = new URL(req.url ?? '/', 'http://127.0.0.1'); } catch { throw new Refused('BAD_REQUEST', 'use a valid path under /api/v1/boards'); }const route = /^\/api\/v1\/boards\/([^/]+)\/(state|events|moves|requests|code)$/.exec(url.pathname);- const who = await adapter.authenticate(req, { board: route?.[1] ?? null, write: req.method === 'POST' });+ const shoutRoute = /^\/api\/v1\/boards\/([^/]+)\/shouts\/([^/]+)$/.exec(url.pathname);+ const boardId = route?.[1] ?? shoutRoute?.[1] ?? null;+ const who = await adapter.authenticate(req, { board: boardId, write: req.method === 'POST' });if (req.method === 'GET' && url.pathname === '/api/v1/boards') {const listing = await adapter.boards(who);return json(res, 200, Array.isArray(listing) ? { boards: listing } : listing);}- if (!route) return json(res, 404, refusal(new Refused('NO_ENDPOINT', 'no API v1 endpoint here; use /api/v1/boards and a board state, code, events, moves or requests path')));- const board = await adapter.board(route[1], who);+ if (!route && !shoutRoute) return json(res, 404, refusal(new Refused('NO_ENDPOINT', 'no API v1 endpoint here; use /api/v1/boards and a board state, shout, code, events, moves or requests path')));+ const board = await adapter.board(boardId, who);+ if (req.method === 'GET' && shoutRoute) {+ const rawId = shoutRoute[2];+ if (!/^[1-9]\d*$/.test(rawId) || !Number.isSafeInteger(Number(rawId))) throw new Refused('BAD_REQUEST', 'shout needs a positive integer id; use the id from the event or recent state');+ if (typeof adapter.shout !== 'function') throw new Refused('SHOUT_NOT_AVAILABLE', 'this API adapter does not provide addressed shout reads');+ return json(res, 200, { shout: await adapter.shout(board, Number(rawId), who) });+ }+ if (shoutRoute) throw new Refused('BAD_REQUEST', 'read an addressed shout with GET; use a board move to create or answer shouts');if (req.method === 'GET' && route[2] === 'state') {const seen = url.searchParams.has('seen') ? seenCursor(url.searchParams.get('seen')) : null;const state = await adapter.state(board, who, seen);@@ -153,7 +162,7 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {/** Choose the same HTTP refusal class for local and sealed relay adapters. */export function apiStatus(error) {- return { AUTH_REQUIRED: 401, TOKEN_BOARD: 403, API_ORIGIN: 403, BAD_ORIGIN: 403, WRITE_REQUIRED: 403, HUMAN_REQUIRED: 403, NO_REPO_ACCESS: 403, NO_BOARD: 404, BOARD_NOT_LINKED: 404, NO_SNAPSHOT: 404, SNAPSHOT_REQUIRED: 409, SEQUENCE_REPEAT: 409, SEQUENCE_GAP: 409 }[error.code] ?? (error instanceof Refused ? 400 : 500);+ return { AUTH_REQUIRED: 401, TOKEN_BOARD: 403, API_ORIGIN: 403, BAD_ORIGIN: 403, WRITE_REQUIRED: 403, HUMAN_REQUIRED: 403, NO_REPO_ACCESS: 403, NO_BOARD: 404, NO_SHOUT: 404, BOARD_NOT_LINKED: 404, NO_SNAPSHOT: 404, SNAPSHOT_REQUIRED: 409, SEQUENCE_REPEAT: 409, SEQUENCE_GAP: 409 }[error.code] ?? (error instanceof Refused ? 400 : 500);}// Relay-only snapshot/delete routes reuse the exact shared bounded-body and refusal boundary.diff --git a/src/api.js b/src/api.jsindex 582c9aca..eb5bd1d7 100644--- a/src/api.js+++ b/src/api.js@@ -13,6 +13,7 @@ import { milestoneRoadmap } from './roadmap.js';import { projectRowDecisions } from './row-decisions.js';import { Refused } from './refused.js';import { codeAt, projectState } from './serve.js';+import { relayPresentationShout } from './relay-presentation.js';import { createApiHandler } from './api-http.js';const ADDRESS = '127.0.0.1';@@ -211,6 +212,9 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =state = projectRowDecisions(projectData.rowDecisions, state);return state;},+ shout: (board, id) => relayLinked(board.root)+ ? relayPresentationShout(board.root, id)+ : withBoard(board.root, (db) => store.shoutDetails(db, id)),code: (board, ref) => codeAt(board.root, ref),events: (board, after) => afterEvents(board.root, after),eventLogVersion: () => store.EVENT_LOG_VERSION,diff --git a/src/board.js b/src/board.jsindex a7f77d0d..36408df2 100644--- a/src/board.js+++ b/src/board.js@@ -1482,6 +1482,20 @@ export function getShout(board, id) {return found;}+/** Read every shout in creation order without marking it read, for addressed history and exports. */+export function allShouts(board) {+ return board.db.prepare('SELECT * FROM shout ORDER BY shout_id').all();+}++/** Read one shout with the current open or answered state of its decision, if it is one. */+export function shoutDetails(board, id) {+ const shout = getShout(board, id);+ const answer = shout.shout_decision+ ? board.db.prepare('SELECT * FROM shout WHERE shout_answers = ? ORDER BY shout_id LIMIT 1').get(id) ?? null+ : null;+ return { ...shout, decision_state: shout.shout_decision ? (answer ? 'answered' : 'open') : null, decision_answer: answer };+}+/*** Shouts that asked for a decision nobody has answered yet, oldest first (B21). An optional* recipient limits the queue; an array matches any listed recipient. Without one this returnsdiff --git a/src/json.js b/src/json.jsindex a61589e7..f58c160b 100644--- a/src/json.js+++ b/src/json.js@@ -81,6 +81,7 @@ export const JSON_SHAPES = {http: {boards: shape({ boards: 'array' }),state: shape({ state: 'object' }),+ shout: shape({ shout: 'object' }),events: shape({ events: 'array' }),move: shape({ event: 'object', result: 'object' }),request: shape({ event: 'object', result: 'object' }),diff --git a/src/relay-presentation.js b/src/relay-presentation.jsindex 276fbe8e..def3464c 100644--- a/src/relay-presentation.js+++ b/src/relay-presentation.js@@ -10,7 +10,25 @@ import { projectState } from './serve.js';/** Capture spec, doctrine, config and board presentation without sending plaintext to a relay. */export function relayPresentation(root) {- return { version: 1, state: projectState(root), config: loadConfig(root) };+ const info = repoInfo(root);+ const board = store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'));+ let shouts;+ try { shouts = store.allShouts(board); } finally { store.closeBoard(board); }+ return { version: 1, state: projectState(root), config: loadConfig(root), shouts };+}++/** Resolve one shout from the complete history carried only inside the sealed presentation. */+export function relayPresentationShout(root, id) {+ return presentationShout(relayPresentation(root), id);+}++/** Resolve one addressed shout from an already decoded snapshot without local repository access. */+export function presentationShout(presentation, id) {+ if (!Array.isArray(presentation?.shouts)) throw new Refused('SHOUT_NOT_AVAILABLE', 'this snapshot does not include addressed shout history; refresh it with a current CLI');+ const found = presentation.shouts.find((shout) => shout.shout_id === id);+ if (!found) throw new Refused('NO_SHOUT', `no shout #${id}`);+ const answer = found.shout_decision ? presentation.shouts.find((shout) => shout.shout_answers === id) ?? null : null;+ return { ...found, decision_state: found.shout_decision ? (answer ? 'answered' : 'open') : null, decision_answer: answer };}/** Notice presentation-only changes, including a spec or doctrine edit without a board move. */diff --git a/test/api.test.js b/test/api.test.jsindex a1a9cb49..3aac8785 100644--- a/test/api.test.js+++ b/test/api.test.js@@ -17,7 +17,8 @@ import { once } from 'node:events';import { join, dirname, resolve, basename, delimiter } from 'node:path';import { after, test } from 'node:test';import { resultCommands } from '../src/cli.js';-import { EVENT_LOG_VERSION, openBoard } from '../src/board.js';+import { allShouts, closeBoard, EVENT_LOG_VERSION, openBoard } from '../src/board.js';+import { presentationShout, relayPresentation } from '../src/relay-presentation.js';import { JSON_SHAPES } from '../src/json.js';const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');@@ -718,6 +719,74 @@ async function nextSseEvent(reader, pending = { text: '' }) {}}+test('[N38] local API and sealed presentation resolve shouts beyond recent state, with complete export history', async (t) => {+ const box = project();+ const api = await startApi(t, box);+ const boards = await (await apiFetch(api, '/api/v1/boards')).json();+ const boardId = boards.boards.find((candidate) => candidate.root === box.repo).id;+ const boardPath = `/api/v1/boards/${boardId}`;+ const decision = json(box, box.repo, 'shout', ['person', 'An old decision', '--decision']);+ json(box, box.repo, 'answer', [String(decision.id), 'Approved', '--as', 'person']);+ const openDecision = json(box, box.repo, 'shout', ['person', 'An old open decision', '--decision']);+ for (let index = 0; index < 40; index += 1) json(box, box.repo, 'shout', ['app', `recent message ${index}`]);++ const state = await (await apiFetch(api, `${boardPath}/state`)).json();+ assert.equal(state.state.shouts.length, 40);+ assert.ok(!state.state.shouts.some((shout) => shout.shout_id === decision.id), 'the addressed shout is older than the existing recent-40 state');+ assert.ok(!state.state.shouts.some((shout) => shout.shout_id === openDecision.id));+ const direct = await apiFetch(api, `${boardPath}/shouts/${decision.id}`);+ assert.equal(direct.status, 200);+ const directDocument = await direct.json();+ assertRequiredShape(directDocument, JSON_SHAPES.http.shout.required, 'shout response');+ assert.equal(directDocument.version, JSON_SHAPES.version);+ const oldShout = directDocument.shout;+ assert.equal(oldShout.shout_id, decision.id);+ assert.equal(oldShout.shout_from, 'coordinator');+ assert.equal(oldShout.shout_to, 'person');+ assert.equal(oldShout.shout_text, 'An old decision');+ assert.equal(oldShout.shout_decision, 1);+ assert.equal(oldShout.decision_state, 'answered');+ assert.equal(oldShout.decision_answer.shout_text, 'Approved');+ assert.ok(oldShout.shout_at);+ const open = await (await apiFetch(api, `${boardPath}/shouts/${openDecision.id}`)).json();+ assert.equal(open.shout.decision_state, 'open');+ assert.equal(open.shout.decision_answer, null);++ const board = openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));+ let history;+ try { history = allShouts(board); } finally { closeBoard(board); }+ assert.equal(history.length, 43);+ const answer = history.find((shout) => shout.shout_answers === decision.id);+ assert.ok(answer, 'the complete read retains the decision reply relationship');+ assert.equal(answer.shout_text, 'Approved');+ const presentation = relayPresentation(box.repo);+ assert.throws(() => presentationShout({ state: presentation.state }, decision.id), { code: 'SHOUT_NOT_AVAILABLE' },+ 'older snapshots without complete history refuse the capability clearly');+ assert.equal(presentation.shouts.length, 43);+ assert.equal(presentation.shouts[0].shout_id, decision.id);+ assert.equal(presentation.shouts[0].shout_text, 'An old decision');+ assert.equal(presentation.state.shouts.length, 40, 'sealed presentation keeps the state window bounded separately');++ const linkFile = join(box.repo, '.git', 'pullboard', 'relay.json');+ writeFileSync(linkFile, JSON.stringify({ version: 1, mode: 'ordered', board: boardId,+ url: 'https://app.pullboard.dev', repository: 'fixture/repository', token: 'ps_' + 'a'.repeat(43), sequence: 0, cursor: 0 }) + '\n', { mode: 0o600 });+ const throughRelayPresentation = await apiFetch(api, `${boardPath}/shouts/${decision.id}`);+ const relayDocument = await throughRelayPresentation.json();+ assert.equal(throughRelayPresentation.status, 200, JSON.stringify(relayDocument));+ assert.deepEqual(relayDocument.shout, JSON.parse(JSON.stringify(oldShout)));++ const missing = await apiFetch(api, `${boardPath}/shouts/999999`);+ assert.equal((await apiError(missing, 404)).code, 'NO_SHOUT');+ const malformed = await apiFetch(api, `${boardPath}/shouts/0`);+ assert.equal((await apiError(malformed, 400)).code, 'BAD_REQUEST');+ const malformedText = await apiFetch(api, `${boardPath}/shouts/nope`);+ assert.equal((await apiError(malformedText, 400)).code, 'BAD_REQUEST');+ await apiError(await apiFetch(api, `${boardPath}/shouts/${decision.id}`, { noSecret: true }), 401);+ await apiError(await apiFetch(api, `${boardPath}/shouts/${decision.id}`, { headers: { 'x-pullboard-key': 'wrong-session-secret' } }), 401);+ assert.equal((await (await apiFetch(api, `${boardPath}/state`)).json()).state.shouts.length, 40,+ 'addressed reads and refusals do not change the recent-40 projection');+});+test('[A2] local HTTP v1 versions state and moves, authenticates, and preserves CLI refusals', async (t) => {const box = project();const api = await startApi(t, box);diff --git a/test/relay-client.test.js b/test/relay-client.test.jsindex b1129089..ec8dd572 100644--- a/test/relay-client.test.js+++ b/test/relay-client.test.js@@ -21,6 +21,7 @@ import { main } from '../src/cli.js';import { appliedSequence, prepareEngineMove } from '../src/engine.js';import { storeBoardKey } from '../src/relay-key.js';import { ENGINE_VERSION } from '../src/machine.js';+import { presentationShout } from '../src/relay-presentation.js';const SIGN_INS = new Map();@@ -162,7 +163,19 @@ test('[H1,H3,H7,H15,H16] relay on snapshots and orders ciphertext, refuses offliconst marker = 'RELAY_CLIENT_KNOWN_PRIVATE_CRITERION';const lane = Object.keys(config.lanes)[0];await cli(root, env, 'add', lane, 'initial private item', '--criterion', marker);+ const oldHistoryText = 'RELAY_PRIVATE_OLD_HISTORY_SHOUT_000';const boardFile = join(root, '.git', 'pullboard', 'board.sqlite');+ const board = store.openBoard(boardFile);+ const lanes = Object.keys(config.lanes);+ let oldestShoutId;+ try {+ for (let index = 0; index < 41; index += 1) {+ const id = store.shout(board, { from: 'coordinator', to: 'person', text: index === 0 ? oldHistoryText : `old private history ${index}`, lanes });+ if (index === 0) oldestShoutId = id;+ }+ } finally {+ store.closeBoard(board);+ }const beforeLink = await cli(root, env, 'export');const boardId = beforeLink.tables.board_meta.find((row) => row.meta_key === 'board_id').meta_value;@@ -203,6 +216,11 @@ test('[H1,H3,H7,H15,H16] relay on snapshots and orders ciphertext, refuses offliconst linkedExport = await cli(root, env, 'export');assert.deepEqual(openedSnapshot.tables, linkedExport.tables, 'the first sealed record is the exact native board snapshot');assert.ok(openedSnapshot.presentation.state.items.some((item) => item.title === 'initial private item'));+ assert.equal(openedSnapshot.presentation.state.shouts.length, 40, 'the view state remains bounded to the recent forty');+ assert.equal(openedSnapshot.presentation.shouts.length, 41, 'the sealed presentation retains full history for addressed reads');+ assert.equal(openedSnapshot.presentation.shouts[0].shout_text, oldHistoryText, 'the sealed history includes the oldest addressed shout');+ assert.equal(presentationShout(openedSnapshot.presentation, oldestShoutId).shout_text, oldHistoryText,+ 'a receiver can resolve an old shout from decoded presentation data without opening the repository');for (const [table, rows] of Object.entries(beforeLink.tables)) {if (table !== 'board_meta') assert.deepEqual(openedSnapshot.tables[table], rows, 'linking preserves every existing board row');}@@ -273,7 +291,7 @@ test('[H1,H3,H7,H15,H16] relay on snapshots and orders ciphertext, refuses offlirelay.advance(0);const stored = Buffer.concat(readdirSync(relayDirectory).map((name) => readFileSync(join(relayDirectory, name))));- for (const secret of [marker, 'initial private item', 'mirrored private move', 'mirrored private shout', 'queued private move', 'second queued private move', 'committed reply lost', root]) {+ for (const secret of [marker, 'initial private item', oldHistoryText, 'mirrored private move', 'mirrored private shout', 'queued private move', 'second queued private move', 'committed reply lost', root]) {assert.equal(stored.includes(Buffer.from(secret)), false, `relay journal does not contain known plaintext ${secret}`);}assert.equal(stored.includes(key), false, 'relay journal does not contain raw key bytes');