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(api): deny person authority to serve moves [P6,B26]

Corey Olsonb38e56a0606d
diff --git a/docs/api.md b/docs/api.md
index dc73067c..e9d5a8ba 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -290,3 +290,10 @@ Row approval and decline first record the person's exact decision through the sa
`pullboard land [--max N] [--dry-run] [--adopt]` is coordinator-only. It merges verified items in verdict order in a separate landing worktree, gates the batch once and records pushed merges. Conflicts and stacked unverified items are named separately. Reproducible failures are bisected; a failing file which passes alone files one flake and holds the batch without retries. Resume includes `landingBatches`, each with its state, owner, exact tip, items and log path.
Only the person can run `pullboard land --waive <test> --until <date> --reason "why"`. A waiver retains every test in the full gate. The batch records its exact tree and each failing test with its covering live waiver; pre-push validates that distinct proof and creates no ordinary green stamp. Expired waivers cannot authorize a push. Existing gate-stamped pushes and `pullboard merged` remain available.
+
+
+### Person authority stays outside the standalone API
+
+A `pullboard serve` key grants access to a board; it does not identify the person. API moves always use a non-person channel, including when the server was started in an ordinary terminal. `spec-approve`, `spec-decline`, answering or verifying with `as: person`, and any other person-only move are refused with `B26_PERSON_CHANNEL` without recording an event. Token revocation through the standalone API is refused for the same reason. Spec signing off is not an offered API move. Use the person's terminal or the actual `pullboard view` page for person actions; ordinary agent moves remain available through the API.
+
+The view's own page retains its person channel. Residual: an agent that starts `pullboard view` itself also holds that view's link; this change does not isolate that link from the agent. Signed person moves (#408) address that separate boundary.
diff --git a/src/api.js b/src/api.js
index 5f97ec57..ea5ec94b 100644
--- a/src/api.js
+++ b/src/api.js
@@ -219,7 +219,7 @@ function agentPath(root, name = COORDINATOR, isMain) {
}
/** Execute one actual CLI command and retain its emitted event without a latest-row race. */
-export async function executeMove(root, body, runCommand, isMain) {
+export async function executeMove(root, body, runCommand, isMain, personChannel = 'view') {
if (Object.keys(body).some((key) => !['verb', 'item', 'args', 'agent'].includes(key))) throw new Refused('BAD_REQUEST', 'a move takes only verb, item, args and agent; remove the unknown fields');
const argv = moveArgs(body);
let cwd;
@@ -232,7 +232,7 @@ export async function executeMove(root, body, runCommand, isMain) {
const events = [];
const status = await runCommand(argv, {
cwd,
- personChannel: 'view',
+ personChannel,
stdout: { isTTY: false, write: (text) => { output += text; } },
stderr: { write: (text) => { diagnostics += text; } },
onEvent: (row) => { events.push(row); },
@@ -264,8 +264,8 @@ async function createRequest(root, body, isMain) {
}, isMain);
}
-/** Create the authenticated local adapter used by the HTTP server and other local transports. */
-export function createLocalApiHandler({ secret, getPort, runCommand, projects = listApiProjects, isMain, allowedOrigins = [], onStateBuild } = {}) {
+/** Share the local router with the person's view; the standalone API explicitly denies person authority. */
+export function createLocalApiHandler({ secret, getPort, runCommand, projects = listApiProjects, isMain, allowedOrigins = [], onStateBuild, personChannel = 'view' } = {}) {
if (typeof getPort !== 'function') throw new TypeError('createLocalApiHandler needs a bound-port getter');
if (typeof runCommand !== 'function') throw new TypeError('createLocalApiHandler needs the actual CLI entry point as runCommand');
const codeIsMain = codeIsFromMain() && isMain !== false;
@@ -323,10 +323,10 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =
code: (board, ref) => codeAt(board.root, ref),
events: (board, after) => afterEvents(board.root, after, codeIsMain),
eventLogVersion: () => store.EVENT_LOG_VERSION,
- move: (board, body) => executeMove(board.root, body, runCommand, codeIsMain),
+ move: (board, body) => executeMove(board.root, body, runCommand, codeIsMain, personChannel),
request: (board, body) => createRequest(board.root, body, codeIsMain),
tokens: async (board) => (await relayTokens(board.root, { err() {} })).tokens,
- revokeToken: (board, id) => relayRevoke(board.root, id, { personChannel: 'view', say() {}, err() {} }),
+ revokeToken: (board, id) => relayRevoke(board.root, id, { personChannel, say() {}, err() {} }),
});
}
@@ -334,7 +334,8 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =
export function serveApi({ port = 0, secret = randomBytes(18).toString('base64url'), runCommand, projects = listApiProjects, isMain, onStateBuild } = {}) {
if (typeof runCommand !== 'function') throw new TypeError('serveApi needs the actual CLI entry point as runCommand');
let bound;
- const handler = createLocalApiHandler({ secret, getPort: () => bound, runCommand, projects, isMain, onStateBuild });
+ // A serve key authenticates board access, never a person, even in an ordinary terminal.
+ const handler = createLocalApiHandler({ secret, getPort: () => bound, runCommand, projects, isMain, onStateBuild, personChannel: 'api' });
const server = createServer(handler);
server.requestTimeout = 15_000;
return new Promise((ready, fail) => {
diff --git a/test/api-http.test.js b/test/api-http.test.js
index ee9df79f..4983a087 100644
--- a/test/api-http.test.js
+++ b/test/api-http.test.js
@@ -1,13 +1,14 @@
/** Real HTTP calls against an isolated Git repo and the actual board engine (A2). */
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
-import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { runFixtureChild, runFixtureGit, startFixtureChild } from './fixture-child.js';
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { createServer, request as httpRequest } from 'node:http';
import { join, resolve } from 'node:path';
import { test } from 'node:test';
import { serveApi } from '../src/api.js';
+import { serveView } from '../src/serve.js';
import { main } from '../src/cli.js';
import { createApiHandler } from '../src/api-http.js';
import { registryFile, registerProject } from '../src/projects.js';
@@ -689,3 +690,89 @@ test('[A2, N26] state JSON fragments preserve the API envelope and legacy adapte
assert.equal(legacyResponse.headers.get('cache-control'), 'no-store');
assert.equal(legacyResponse.headers.get('etag'), null);
});
+
+
+test("an agent-shell serve cannot record a person's move [P6,B26]", { timeout: 60_000 }, // budget: hang ceiling for private CLI/API startup and person-channel checks, not a throughput claim.
+async (t) => {
+ const box = fixture(t);
+ const spec = join(box.root, 'SPEC.md');
+ writeFileSync(spec, readFileSync(spec, 'utf8') + '\n- G2 [pending, must] Person approval only. | gate: true\n- G3 [pending, must] Person decline only. | gate: true\n');
+ runFixtureGit(['add', 'SPEC.md'], { cwd: box.root, env: box.env });
+ runFixtureGit(['commit', '-qm', 'chore(test): prepare person-only rows'], { cwd: box.root, env: box.env });
+ const item = box.cli(box.root, 'add', 'app', 'Private channel item', '--specs', 'G1', '--criterion', 'No person bypass').item.item_id;
+ const decision = box.cli(box.root, 'shout', 'person', 'Choose the private fixture decision', '--decision').id;
+ const child = startFixtureChild(process.execPath, [BIN, 'serve', '--port', '0', '--json'], {
+ cwd: box.root, env: { ...box.env, CLAUDECODE: '1' }, stdio: ['ignore', 'pipe', 'pipe'],
+ });
+ const closed = new Promise(resolveClosed => child.once('close', resolveClosed));
+ let stopped = false;
+ /** Stop only the private server and await its terminal close before deleting its fixture. */
+ async function stopServer() {
+ if (stopped) return;
+ stopped = true;
+ if (child.exitCode === null && child.signalCode === null) child.kill('SIGTERM');
+ let timer;
+ try {
+ const ended = await Promise.race([closed.then(() => true), new Promise(resolveWait => { timer = setTimeout(() => resolveWait(false), 2000); })]);
+ if (!ended) { child.kill('SIGKILL'); await closed; }
+ } finally { clearTimeout(timer); }
+ }
+ t.after(stopServer);
+ const served = await new Promise((resolveAddress, rejectAddress) => {
+ let output = '';
+ const timer = setTimeout(() => rejectAddress(new Error('private agent serve did not announce its address')), 20_000);
+ child.once('exit', () => { clearTimeout(timer); rejectAddress(new Error('private agent serve exited before its address')); });
+ child.stdout.on('data', chunk => {
+ output += chunk;
+ try {
+ const document = JSON.parse(output);
+ if (typeof document.url === 'string') { clearTimeout(timer); resolveAddress(new URL(document.url)); }
+ } catch { /* Wait for the complete private JSON announcement, never print its key. */ }
+ });
+ });
+ const headers = { 'x-pullboard-key': served.searchParams.get('k'), 'content-type': 'application/json' };
+ const listing = await (await fetchFresh(served.origin + '/api/v1/boards', { headers })).json();
+ const id = listing.boards.find(board => resolve(board.root) === resolve(box.root)).id;
+ const path = '/api/v1/boards/' + id;
+ const before = box.cli(box.root, 'log').events.length;
+ const attempts = [
+ { verb: 'spec-approve', args: { ids: 'G2' } },
+ { verb: 'spec-decline', args: { ids: 'G3', reason: 'Not approved by a person' } },
+ { verb: 'answer', item: decision, args: { text: 'Forged person answer', as: 'person' } },
+ { verb: 'verify', item, args: { decision: 'accept', as: 'person', note: 'Forged person verification' } },
+ { verb: 'next', args: { as: 'person' } },
+ ];
+ for (const move of attempts) {
+ const response = await fetchFresh(served.origin + path + '/moves', { method: 'POST', headers, body: JSON.stringify(move) });
+ const document = await response.json();
+ assert.equal(document.error?.code, 'B26_PERSON_CHANNEL', move.verb + ' never receives person authority from an API key');
+ assert.notEqual(response.status, 200);
+ assert.equal(box.cli(box.root, 'log').events.length, before, move.verb + ' records no event');
+ }
+ const tokenResponse = await fetchFresh(served.origin + path + '/tokens', { method: 'POST', headers, body: JSON.stringify({ id: randomUUID() }) });
+ assert.equal((await tokenResponse.json()).error?.code, 'B26_PERSON_CHANNEL', 'API token management has no person authority either');
+ assert.equal(box.cli(box.root, 'log').events.length, before);
+ await stopServer();
+ // Denial belongs to the interface, even when the server has no agent-shell marker.
+ const plain = await serveApi({ port: 0, runCommand: main, projects: () => [{ root: box.root, name: 'Plain API fixture' }] });
+ t.after(() => plain.close());
+ const plainAddress = new URL(plain.url);
+ const plainReply = await fetchFresh(plainAddress.origin + path + '/moves', {
+ method: 'POST', headers: { 'x-pullboard-key': plainAddress.searchParams.get('k'), 'content-type': 'application/json' },
+ body: JSON.stringify({ verb: 'spec-approve', args: { ids: 'G2' } }),
+ });
+ assert.equal((await plainReply.json()).error?.code, 'B26_PERSON_CHANNEL', 'an ordinary-shell API has no person authority');
+ assert.equal(box.cli(box.root, 'log').events.length, before);
+ registerProject(box.root);
+ const view = await serveView({ port: 0 });
+ t.after(() => view.close());
+ const viewAddress = new URL(view.url);
+ const response = await fetchFresh(viewAddress.origin + path + '/moves', {
+ method: 'POST', headers: { 'x-pullboard-key': viewAddress.searchParams.get('k'), 'content-type': 'application/json' },
+ body: JSON.stringify({ verb: 'spec-approve', args: { ids: 'G2' } }),
+ });
+ assert.equal(response.status, 200, 'the actual view keeps the person channel');
+ const approved = (await response.json()).event;
+ assert.equal(approved.event_by, 'person');
+ assert.equal(box.cli(box.root, 'log').events.length, before + 1);
+});