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.

Merge remote-tracking branch 'origin/main' into core/579-claude

Corey Olson09829dc9c4a8
diff --cc docs/api.md
index 0262f9d2,8565b8d7..3d5d5603
--- a/docs/api.md
+++ b/docs/api.md
@@@ -202,16 -244,12 +244,20 @@@ Only the coordinator sets or edits an i
Phone enrollment uses a one-use `#device=<locator>.<secret>` fragment, removed before sign-in. The secret remains on the phone and Mac. Person-authenticated `/api/v1/devices/session` returns the current account id. `/api/v1/devices/enrollments/:locator` supports POST `{}` to start a ten-minute locator, PUT of the exact public enrollment and MAC, GET of `{version, enrollment}` and DELETE to consume it. A native Mac checks the MAC locally before retaining any recipient. `/api/v1/devices/:deviceId` supports POST `{}` to record an authenticated recipient and DELETE to revoke it. PUT `/api/v1/devices/:deviceId/boards/:boardId` stores `{engine, wrapped}`; GET `/api/v1/devices/:deviceId/boards` returns `{version, wraps: [{board, engine, wrapped}]}` filtered by current board access. `wrapped` is opaque base64url client ciphertext. Enrollment, device listing and direct revocation require a person session. A board-scoped machine credential can PUT only its own board wrap to an already enrolled device. Cookie writes require the exact configured Origin, and all responses are no-store. Device ids and grants belong to the authenticated GitHub account. Revoked ids cannot be registered or uploaded again.
-`POST /auth/machines {board,machine}` requires a foreground person session and returns a `pm_` credential bound to that board and machine. This delegate can mint board-scoped `pa_` tokens through `/auth/tokens` and list only its board’s token ids and metadata. It cannot link a board, issue a machine credential, post a phone request, revoke another credential directly, or use person-only cookie endpoints. Agent tokens cannot mint any credential.
+`POST /auth/machines {board,machine}` requires a foreground person session and returns a `pm_` credential bound to that board and machine. This delegate can list only its board’s token ids and metadata, and through `POST /auth/tokens {board,agent}` it first-mints a `pa_` token only for a seat the relay never issued a token to, including after that token expired or was revoked (`TOKEN_EXISTS` otherwise). Such a seat (a manual `pullboard join`, or any name minted ahead) is machine-origin for good: it builds, never verifies on a linked board, and its name cannot later be registered (`SEAT_TAKEN`). The native client also checks that the seat is registered, which the relay cannot see. It cannot link a board, issue a machine credential, post a phone request, revoke another credential directly, or use person-only cookie endpoints.
+
+A `pa_` token renews only its own seat: `POST /auth/tokens {board,agent}` naming itself returns a new token and revokes the one that asked (`TOKEN_AGENT` for any other seat). A seat's first token from another seat comes only with the move that registers it: `POST /api/v1/boards/:board/moves {sequence, sealed, registration}`, sent with the creating seat's token, where `registration` is `{target, creator, sequence, digest}` (the creator is the sender, the sequence is this upload's, and the digest is the SHA-256 of the `sealed` text). The relay appends the move and issues the target's first token in one board lock and returns it only in that reply as `enrollment`; the public event carries the receipt and never the token. An exact retry returns the same issuance id and expiry without a token. The receipt commits in the same journal transaction as the move and is kept through compaction, and it claims the target from that moment: the machine credential and a person are refused a first mint for any name a receipt claims, under the same board lock that appends receipts, so no failure between the append and the enrollment leaves a window. If enrollment fails after the append, the creator's exact retry, or its `recover:true` reissue, rolls the first mint forward from the journalled receipt. A lost token is reissued by its creator, `POST /auth/tokens {board,agent,recover:true}` with the creator's token, which revokes the old ones. `/auth/tokens` refuses a `registration` field (`REGISTRATION_IN_MOVE`), so a copied receipt never mints. Replicas apply an engine-27 registration by another seat only with the receipt that names its target, creator, position and digest, so the board's record of who created a seat matches the relay's.
+
+`POST /auth/coordinators {board}` takes a person session only and issues the coordinator's token: the first one (`bootstrap`), a fresh one after loss, expiry or revocation (`reissue`), or the person's reset of a coordinator first minted by the machine (`reset`). It revokes every older coordinator token. `pullboard relay on` calls it inside its own sign-in, so a board needs no extra tap. `GET /auth/tokens` also returns `coordinatorEvents`, each with its reason, the person session id, the revoked token ids, the issued id and the time; `pullboard relay tokens` prints them.
+
+On a linked board, an engine-27 verdict, review reservation or review offer needs verifier standing: the verifier was enrolled through the relay by its creator, each creator up the line was too, the line ends at the coordinator, and neither the builder nor a machine join is on it. The coordinator stands on the token the person set up. A seat without standing is refused with `VERIFIER_STANDING` in one line that names the fix, `pullboard worktree <lane> --model "<model name>"` run by the coordinator from the main checkout. Seats from before engine 27, or from before the board was linked, keep building; reviews need a fresh seat made that way. Each person-made coordinator token carries a machine lineage (a reissue that replaces a token keeps it; another machine's token starts its own), and a seat enrolled from it, or from a seat in its line, records that lineage. A coordinator claim records the lineage of the machine that builds it. When the coordinator built an item, a seat from another machine's registration lineage, or the person, verifies it; a seat from the building machine's own lineage is refused and told so. On an unlinked board who may verify is unchanged. The relay stamps each record it stores with `policy` (and `root` for the person-made coordinator token); a stamped record below engine 27 is refused, older unstamped records replay as they did, and a board with machine or agent credentials requires engine 27.
+
+Residual: tokens on disk, in the repository's shared `relay.json`, are readable by every process of the same operating-system user, so a process that reads another seat's current `pa_` can act as that seat and renew it; signed moves (#408) close that. An agent holding the machine credential can still make a seat of its own, by a manual join or by minting a never-issued name, which also makes a creator skip that name. That seat cannot verify that agent's work, nor any work on a linked board, and cannot act as any existing seat. A sealed snapshot uploaded with the machine credential remains a trusted checkpoint for replicas that restore from it.
+ `GET /auth/machines?board=<id>` returns `{version, machines: [{machine}]}` for the live computer credentials on that board, with duplicate computer ids listed once. It requires that board's machine credential or a person session with current repository write access; agent tokens and credentials from another board are refused. `relay off` excludes its own computer from the list and warns which joined computers lose the shared copy if the phone approves deletion. JSON also returns those ids in `affectedMachines`. Local unlink still succeeds when the relay cannot supply the list.
+
+ After phone-approved deletion, a previously live scoped credential receives HTTP 410 / `RELAY_BOARD_DELETED` for that deleted copy. The relay retains only its hash, board id and original expiry as a deletion receipt, prunes expired receipts, and grants no access through them. Unknown, already revoked and already expired credentials receive `AUTH_REQUIRED` as before. Only a versioned deletion response naming this link's own board turns a joined computer back into a local board. The CLI removes the inert link and its device key, excludes the project from automatic relinking, and retains a private credential-free notice that the relay copy was deleted; native board contents remain local. A successful explicit `relay on` starts a new link and clears that notice. A network outage or ordinary credential refusal does not authorize this transition. Before forgetting a deleted copy, the CLI commits any pending native move and its durable receipt locally. The notice keeps only the receipt id and intent digests, so interrupted cleanup or an explicit repeat can return the original outcome without applying that move twice; different local work can continue beside it.
+
A machine publishes an opaque approval with `POST /api/v1/devices/approvals {context,sealed}`. The publishing machine may GET only its own requests. The paired phone reads `/api/v1/devices/:deviceId/approvals`, explicitly POSTs `/:requestId/authorize {}` and completes the encrypted reply through `/:requestId/complete {response}`. The publishing machine executes a native revocation through `/:requestId/execute {grant}`; the two-minute grant binds the entire context and is atomically consumed once. Native reply keys and grants never persist. A refused foreground approval fails immediately with the original refusal code and reason plus its request id. A refused remote approval makes local unlinking or registration exit nonzero while retaining the completed local work: one line names that completion, the refusal code and reason, the request id and the next action. The JSON result preserves the local outcome and includes `remote: {code, reason, requestId}`. New-board linking uses a durable non-person reply key and returns only a board-scoped machine credential. `relay off` immediately unlinks locally even offline or in an agent shell, reports that the relay copy remains, and queues a separate one-tap phone deletion request when possible.
The result and refusal tables are checked against `JSON_SHAPES` in `src/json.js` by `docs/api.test.js`.
diff --cc relay/auth-http.js
index df911f39,5f7a3e04..fb04f455
--- a/relay/auth-http.js
+++ b/relay/auth-http.js
@@@ -67,7 -67,7 +67,7 @@@ export function createAuthHandler({ aut
const secure = origin.protocol === 'https:' ? '; Secure' : '';
const routes = new Set(['GET /auth/github/start', 'GET /auth/github/callback', 'POST /auth/device/start', 'POST /auth/device/poll', 'POST /auth/device/cancel',
'GET /auth/device/confirm', 'POST /auth/device/confirmation/open', 'POST /auth/device/confirmation/status', 'POST /auth/device/confirmation',
- 'GET /auth/session', 'GET /auth/boards', 'POST /auth/boards/link', 'POST /auth/machines', 'POST /auth/coordinators', 'GET /auth/tokens', 'POST /auth/tokens', 'POST /auth/tokens/revoke']);
- 'GET /auth/session', 'GET /auth/boards', 'POST /auth/boards/link', 'POST /auth/machines', 'GET /auth/machines', 'GET /auth/tokens', 'POST /auth/tokens', 'POST /auth/tokens/revoke']);
++ 'GET /auth/session', 'GET /auth/boards', 'POST /auth/boards/link', 'POST /auth/machines', 'GET /auth/machines', 'POST /auth/coordinators', 'GET /auth/tokens', 'POST /auth/tokens', 'POST /auth/tokens/revoke']);
/** Resolve a bearer or cookie credential; cookie writes require an exact trusted Origin. */
function token(req, write = false) {
diff --cc relay/auth.js
index 97fccd97,4ee6e18d..eb3e8938
--- a/relay/auth.js
+++ b/relay/auth.js
@@@ -512,10 -478,9 +518,12 @@@ export function createRelayAuth({ datab
identifier(board, 'BAD_BOARD');
lifecycle(() => {
db.prepare('INSERT OR IGNORE INTO relay_cleanup (board) VALUES (?)').run(board);
+ db.prepare('DELETE FROM relay_deleted_credentials WHERE expires<=?').run(now());
+ db.prepare('INSERT OR REPLACE INTO relay_deleted_credentials (hash,board,expires) SELECT hash,board,expires FROM relay_credentials WHERE board=? AND revoked=0 AND expires>?').run(board, now());
db.prepare('DELETE FROM relay_credentials WHERE board=?').run(board);
+ // A person unlinked the board; a later link starts its seats afresh with the new journal.
+ db.prepare('DELETE FROM relay_seats WHERE board=?').run(board);
+ db.prepare('DELETE FROM relay_coordinator_events WHERE board=?').run(board);
db.prepare('DELETE FROM relay_boards WHERE id=?').run(board);
});
for (const key of permissions.keys()) if (key.endsWith(':' + board)) permissions.delete(key);
@@@ -558,125 -522,23 +566,133 @@@
credential(token);
return { ...issue(principal.user, 'machine', board, machine, expiresIn), board, machine };
},
+ /** List live computer identities only for this board's machine or a freshly authorized person. */
+ async listMachines(token, board) {
+ identifier(board, 'BAD_BOARD');
+ const principal = await auth.authenticate(token, { board, write: true });
+ if (!['session', 'machine'].includes(principal.kind)) throw new Refused('HUMAN_REQUIRED', 'use this board’s machine credential or the signed-in phone to list joined computers');
+ credential(token);
+ return db.prepare("SELECT DISTINCT agent AS machine FROM relay_credentials WHERE board=? AND kind='machine' AND revoked=0 AND expires>? ORDER BY agent").all(board, now());
+ },
- /** Mint an agent credential scoped to a single readable board and immutable human identity. */
- async issueToken(token, { board, agent, expiresIn = tokenTTL }) {
+ /**
+ * Mint an agent credential scoped to one board (#579). The machine credential, or a person,
+ * first-mints only a seat the relay never issued a token to, and that seat is machine-origin
+ * for good. A seat's own current token renews it, revoking itself. Its creator may reissue a
+ * lost token for a seat it registered, revoking the old ones. A seat's first token from a
+ * creator comes only with its registration move (`enrollSeat`), never from this route.
+ */
+ async issueToken(token, { board, agent, expiresIn = tokenTTL, recover = false, registration }) {
identifier(board, 'BAD_BOARD');
identifier(agent, 'BAD_AGENT');
- if (!Number.isSafeInteger(expiresIn) || expiresIn <= 0 || expiresIn > MAX_TTL) throw new Refused('BAD_EXPIRY', 'choose a token expiry between one millisecond and thirty days');
+ expiry(expiresIn, 'token');
+ if (registration !== undefined) throw new Refused('REGISTRATION_IN_MOVE', 'a seat receipt counts only inside its registration move; post the move with its receipt from the creating seat');
+ if (typeof recover !== 'boolean') throw new Refused('BAD_REQUEST', 'send recover as true or false');
const principal = await auth.authenticate(token, { board, write: true });
- if (!['session', 'machine'].includes(principal.kind)) throw new Refused('HUMAN_REQUIRED', 'use this board’s machine credential to issue an agent token');
- credential(token);
- return { ...issue(principal.user, 'board', board, agent, expiresIn), board, agent };
+ return lifecycle(() => {
+ const current = credential(token);
+ const existing = seat(board, agent);
+ if (principal.kind === 'board') {
+ if (!recover && principal.agent === agent) {
+ const renewed = issue(principal.user, 'board', board, agent, expiresIn, Boolean(current.root), current.lineage ?? null);
+ db.prepare('UPDATE relay_credentials SET revoked=1 WHERE id=?').run(current.id);
+ return { ...renewed, board, agent };
+ }
+ const claim = !existing && recover ? registrationClaim(board, agent) : null;
+ if (recover && claim?.creator === principal.agent && agent !== principal.agent) {
+ // A receipt published without its enrollment: the creator rolls the first mint forward.
+ return firstMint({ id: current.user_id }, board, agent, tokenTTL,
+ { origin: 'registered', creator: claim.creator, sequence: claim.sequence, digest: claim.digest });
+ }
+ if (recover && existing?.origin === 'registered' && existing.creator === principal.agent && agent !== principal.agent) {
+ db.prepare("UPDATE relay_credentials SET revoked=1 WHERE board=? AND kind='board' AND agent=?").run(board, agent);
+ return { ...issue(principal.user, 'board', board, agent, expiresIn), board, agent };
+ }
+ throw new Refused('TOKEN_AGENT', recover
+ ? 'only the seat that registered this one reissues its token; ask its creator'
+ : 'an agent token renews only its own seat; a new seat gets its first token from its creator\'s registration');
+ }
+ if (recover) throw new Refused('TOKEN_AGENT', 'only the seat that registered this one reissues its token; ask its creator');
+ if (existing) {
+ throw new Refused('TOKEN_EXISTS', agent === 'coordinator'
+ ? 'the coordinator already has a token; it renews with its own, or the person reissues it with pullboard relay on'
+ : 'this seat already had a token; it renews only with its own current token, or its creator reissues it');
+ }
+ // A published receipt claims its target even before enrollment finishes: no machine race.
+ if (registrationClaim(board, agent)) {
+ throw new Refused('TOKEN_EXISTS', 'a creator registered this seat; its first token comes only through that registration or its creator');
+ }
+ return firstMint(principal.user, board, agent, expiresIn, { origin: 'machine' });
+ });
+ },
+ /** Wire the relay journal's receipt lookup; token issuance then honors every published claim. */
+ setRegistrationClaims(reader) {
+ if (typeof reader !== 'function') throw new Refused('RELAY_CONFIG', 'configure a seat receipt reader');
+ registrationClaim = reader;
+ },
+ /**
+ * Give a registration move's target its first token, inside the board lock that appended the
+ * move (#579). The creator is the authenticated agent token that sent the move; the target
+ * must be new to the relay. An exact retry returns the same issuance without a token.
+ */
+ enrollSeat(token, board, receipt) {
+ identifier(board, 'BAD_BOARD');
+ return lifecycle(() => {
+ const current = credential(token);
+ if (current.kind !== 'board' || current.agent !== receipt.creator || current.board !== board) {
+ throw new Refused('REGISTRATION_SENDER', 'register a seat with the creating seat\'s own token');
+ }
+ const existing = seat(board, receipt.target);
+ if (existing) {
+ if (existing.origin === 'registered' && existing.creator === receipt.creator && existing.sequence === receipt.sequence && existing.digest === receipt.digest) {
+ return { id: existing.first_id, created: existing.first_created, expires: existing.first_expires, board, agent: receipt.target, retried: true };
+ }
+ throw new Refused('SEAT_TAKEN', `the relay already issued ${receipt.target} a token, so it cannot be registered again; register the next free name`);
+ }
+ return firstMint({ id: current.user_id }, board, receipt.target, tokenTTL,
+ { origin: 'registered', creator: receipt.creator, sequence: receipt.sequence, digest: receipt.digest });
+ });
+ },
+ /** Read one seat's first-mint record for the registration check before a move is appended. */
+ seatRecord(board, agent) {
+ open();
+ identifier(board, 'BAD_BOARD');
+ identifier(agent, 'BAD_AGENT');
+ const row = seat(board, agent);
+ return row && { origin: row.origin, creator: row.creator, sequence: row.sequence, digest: row.digest };
+ },
+ /**
+ * Set up the coordinator's token from a person session only (#579): the first one on a board
+ * (bootstrap), a fresh one after loss, expiry or revocation, or for another of the person's
+ * machines (reissue), or the person's reset of a coordinator first minted by the machine
+ * (reset), which revokes every older coordinator token. A reissue revokes the token it names
+ * as replaced. Each issue leaves an audit row naming the session, the revoked ids and the new id.
+ */
+ async issueCoordinator(token, { board, expiresIn = tokenTTL, replaces }) {
+ identifier(board, 'BAD_BOARD');
+ expiry(expiresIn, 'coordinator');
+ const principal = await auth.authenticate(token, { board, write: true });
+ if (principal.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'only the person sets up the coordinator credential: run pullboard relay on in the main checkout');
+ return lifecycle(() => {
+ const current = credential(token);
+ const existing = seat(board, 'coordinator');
+ const reason = !existing ? 'bootstrap' : existing.origin === 'root' ? 'reissue' : existing.origin === 'machine' ? 'reset' : null;
+ if (!reason) throw new Refused('COORDINATOR_SEAT', 'the coordinator seat on this board was registered by another seat; unlink and link the board again');
+ if (replaces !== undefined && typeof replaces !== 'string') throw new Refused('BAD_REQUEST', 'name the coordinator token id this one replaces');
+ // A reset revokes every machine-minted coordinator token; a reissue revokes the one it
+ // replaces, so each of the person's linked machines keeps its own coordinator token.
+ const revoked = db.prepare("SELECT id FROM relay_credentials WHERE board=? AND kind='board' AND agent='coordinator' AND revoked=0 AND expires>?").all(board, now())
+ .map((row) => row.id).filter((id) => reason === 'reset' || id === replaces);
+ // A replacement keeps its machine's lineage; a token for another machine starts a new one.
+ const replaced = replaces === undefined ? null : db.prepare("SELECT lineage FROM relay_credentials WHERE id=? AND board=? AND kind='board' AND agent='coordinator' AND root=1").get(replaces, board);
+ const lineage = reason !== 'reset' && replaced?.lineage ? replaced.lineage : randomUUID();
+ for (const id of revoked) db.prepare('UPDATE relay_credentials SET revoked=1 WHERE id=?').run(id);
+ const issued = reason === 'reissue'
+ ? { ...issue(principal.user, 'board', board, 'coordinator', expiresIn, true, lineage), board, agent: 'coordinator' }
+ : firstMint(principal.user, board, 'coordinator', expiresIn, { origin: 'root', root: true, lineage });
+ db.prepare('INSERT INTO relay_coordinator_events (id,board,reason,session_id,revoked,issued_id,at) VALUES (?,?,?,?,?,?,?)')
+ .run(randomUUID(), board, reason, current.id, JSON.stringify(revoked), issued.id, issued.created);
+ return { ...issued, root: true, reason };
+ });
},
/** List only owned board-token metadata after a fresh repository write check, never bearer values or hashes. */
async listTokens(token, board) {
diff --cc src/cli.js
index d7ebbaf3,be1e8c61..f2e4a898
--- a/src/cli.js
+++ b/src/cli.js
@@@ -579,15 -585,9 +585,15 @@@ function withBoard(ctx, work)
/** Dispatch a board mutation locally, or seal it before any linked replica applies it. */
async function ordered(ctx, board, operation, args) {
+ // Every engine-27 registration records the seat that made it: the coordinator from the main
+ // checkout, the joined agent from its worktree, or `machine` for a join no seat made (#579).
+ if (operation === 'register' && args[0] && args[0].createdBy === undefined) {
+ const joined = store.agentAt(board, ctx.info.root)?.agent_id;
+ args = [{ ...args[0], createdBy: ctx.info.isMain ? COORDINATOR : joined ?? 'machine' }, ...args.slice(1)];
+ }
const command = ['add', 'edit', 'merged'].includes(ctx.io.relayCommand?.cliOperation) ? ctx.io.relayCommand : undefined;
/** Dispatch while this session holds the checkout, including long-running next/run loops. */
- const execute = () => relayLinked(ctx.info.root)
+ const execute = () => relayLinked(ctx.info.root) || relayRecovered(ctx.info.root)
? relayOperation(ctx.info.root, operation, args, ctx.io, command, () => store[operation](board, ...args)) : store[operation](board, ...args);
const digest = agentSessionDigest();
const boardOnly = CHECKOUT_BOARD_ONLY.get(ctx.io);
diff --cc src/relay.js
index 00ffd79b,f8900245..9637dfdb
--- a/src/relay.js
+++ b/src/relay.js
@@@ -6,10 -6,9 +6,10 @@@ import { basename, dirname, join } fro
import { gunzipSync, gzipSync } from 'node:zlib';
import * as store from './board.js';
import { exportBoard, importBoard, restoreRelaySnapshot, semanticBoardDigest } from './exchange.js';
- import { appliedSequence, applyRelayMove, checkpointSequence, engineReceipt, prepareEngineMove, refuseRelayMove, requireSupportedEngine, startRelayEpoch } from './engine.js';
+ import { appliedSequence, applyEngineMove, applyRelayMove, checkpointSequence, engineReceipt, prepareEngineMove, refuseRelayMove, requireSupportedEngine, startRelayEpoch } from './engine.js';
import { relayMoveActor } from './relay-sender.js';
-import { ENGINE_VERSION } from './machine.js';
+import { actorTransport, cacheSeatToken, ensurePersonCoordinator, nameNextSeat, seatReceipt, withSeatName } from './relay-seats.js';
+import { ENGINE_VERSION, VERIFIER_STANDING_ENGINE } from './machine.js';
import { presentationDigest, relayPresentation, relaySnapshot } from './relay-presentation.js';
import { codeIsFromMain, repoInfo, tryGit } from './git.js';
import { forgetBoardKey, readBoardKey, storeBoardKey } from './relay-key.js';