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(relay): list scoped token metadata for a person [H2,H9]
Corey Olson787b70e0a7f7
diff --git a/relay/auth-http.js b/relay/auth-http.jsindex 5c53fd4f..0010d27e 100644--- a/relay/auth-http.js+++ b/relay/auth-http.js@@ -36,7 +36,7 @@ export function createAuthHandler({ auth, publicOrigin }) {try { origin = new URL(publicOrigin); } catch { throw new Refused('RELAY_CONFIG', 'configure the relay public origin'); }if (origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash || (origin.protocol !== 'https:' && !(origin.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(origin.hostname)))) throw new Refused('RELAY_CONFIG', 'use an HTTPS public origin, or a loopback HTTP origin for local tests');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', 'GET /auth/session', 'GET /auth/boards', 'POST /auth/boards/link', 'POST /auth/tokens', 'POST /auth/tokens/revoke']);+ const routes = new Set(['GET /auth/github/start', 'GET /auth/github/callback', 'POST /auth/device/start', 'POST /auth/device/poll', 'GET /auth/session', 'GET /auth/boards', 'POST /auth/boards/link', '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) {@@ -73,13 +73,15 @@ export function createAuthHandler({ auth, publicOrigin }) {const input = await body(req);json(res, 200, await auth.pollDevice(input.ticket));} else if (route === 'GET /auth/session') {- json(res, 200, { session: await auth.authenticate(token(req)) });+ json(res, 200, { session: await auth.authenticate(token(req), { ...(url.searchParams.has('board') ? { board: url.searchParams.get('board') } : {}) }) });} else if (route === 'GET /auth/boards') {json(res, 200, { boards: await auth.boardsFor(token(req)) });} else if (route === 'POST /auth/boards/link') {const bearer = token(req, true);const input = await body(req);json(res, 200, { board: await auth.linkBoard(bearer, input.board, input.repository) });+ } else if (route === 'GET /auth/tokens') {+ json(res, 200, { tokens: await auth.listTokens(token(req), url.searchParams.get('board')) });} else if (route === 'POST /auth/tokens') {const bearer = token(req, true);const input = await body(req);diff --git a/relay/auth.js b/relay/auth.jsindex c220f321..592b9aff 100644--- a/relay/auth.js+++ b/relay/auth.js@@ -283,6 +283,15 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =credential(token);return { ...issue(principal.user, 'board', board, agent, expiresIn), board, agent };},+ /** List only owned board-token metadata after a fresh person permission check, never bearer values or hashes. */+ async listTokens(token, board) {+ identifier(board, 'BAD_BOARD');+ const principal = await auth.authenticate(token, { board, write: true });+ if (principal.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'sign in as a person to list agent tokens');+ credential(token);+ return db.prepare('SELECT id,board,agent,expires,revoked FROM relay_credentials WHERE user_id=? AND kind=? AND board=? ORDER BY agent,id')+ .all(principal.user.id, 'board', board).map((row) => ({ ...row, revoked: Boolean(row.revoked) }));+ },/** Revoke one owned credential; this never revokes an unrelated session or board token. */async revoke(token, id) {const row = credential(token);diff --git a/test/relay-http.test.js b/test/relay-http.test.jsindex 3aef177e..602b7d54 100644--- a/test/relay-http.test.js+++ b/test/relay-http.test.js@@ -93,6 +93,54 @@ test('CLI device HTTP flow returns a one-time session and individually revocableassert.equal((await revoked.json()).error.code, 'AUTH_REQUIRED');});+test('HTTP person controls expose only scoped token metadata, and agent identity stays board-bound [H2,H9]', async (t) => {+ const box = await relay(t);+ const signed = await browserLogin(box);+ const headers = { cookie: signed.cookie, origin: box.origin, 'content-type': 'application/json' };+ for (const board of ['alpha', 'beta']) {+ const linked = await fetch(box.origin + '/auth/boards/link', { method: 'POST', headers,+ body: JSON.stringify({ board, repository: 'fixture/repository' }) });+ assert.equal(linked.status, 200);+ }+ const issued = await fetch(box.origin + '/auth/tokens', { method: 'POST', headers,+ body: JSON.stringify({ board: 'alpha', agent: 'worker-one' }) });+ assert.equal(issued.status, 201);+ const scoped = await issued.json();+ const listed = await fetch(box.origin + '/auth/tokens?board=alpha', { headers: { cookie: signed.cookie } });+ assert.equal(listed.status, 200);+ assert.equal(listed.headers.get('cache-control'), 'no-store');+ const document = await listed.json();+ assert.equal(document.tokens.length, 1);+ assert.equal(document.tokens[0].id, scoped.id);+ assert.equal(document.tokens[0].agent, 'worker-one');+ assert.deepEqual(Object.keys(document.tokens[0]).sort(), ['agent', 'board', 'expires', 'id', 'revoked']);+ assert.equal(JSON.stringify(document).includes(scoped.token), false, 'HTTP listing never exposes bearer values');+ const agentHeaders = { authorization: 'Bearer ' + scoped.token };+ const identity = await fetch(box.origin + '/auth/session?board=alpha', { headers: agentHeaders });+ assert.equal(identity.status, 200);+ const session = (await identity.json()).session;+ assert.equal(session.kind, 'board');+ assert.equal(session.agent, 'worker-one');+ assert.equal(session.board, 'alpha');+ const wrong = await fetch(box.origin + '/auth/session?board=beta', { headers: agentHeaders });+ assert.equal(wrong.status, 403);+ assert.equal((await wrong.json()).error.code, 'TOKEN_BOARD');+ const forbidden = await fetch(box.origin + '/auth/tokens?board=alpha', { headers: agentHeaders });+ assert.equal(forbidden.status, 403);+ assert.equal((await forbidden.json()).error.code, 'HUMAN_REQUIRED');+ const deniedOrigin = await fetch(box.origin + '/auth/tokens/revoke', {+ method: 'POST', headers: { ...headers, origin: 'http://elsewhere.invalid' },+ body: JSON.stringify({ id: scoped.id }),+ });+ assert.equal(deniedOrigin.status, 403);+ const revoked = await fetch(box.origin + '/auth/tokens/revoke', { method: 'POST', headers,+ body: JSON.stringify({ id: scoped.id }) });+ assert.equal(revoked.status, 200);+ const immediately = await fetch(box.origin + '/auth/session?board=alpha', { headers: agentHeaders });+ assert.equal(immediately.status, 401);+ assert.equal((await immediately.json()).error.code, 'AUTH_REQUIRED');+});+test('HTTP errors are versioned and bounded; production cookies are Secure [H8, H1]', async (t) => {const box = await relay(t);const malformed = await fetch(box.origin + '/auth/device/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '[' });diff --git a/test/relay.test.js b/test/relay.test.jsindex 476d0a7a..ba637109 100644--- a/test/relay.test.js+++ b/test/relay.test.js@@ -4,6 +4,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';import { test } from 'node:test';+import { DatabaseSync } from 'node:sqlite';import { createGitHubClient } from '../relay/github.js';import { createRelayAuth, ACCESS_WINDOW_MS } from '../relay/auth.js';import { serveRelay } from '../relay/service.js';@@ -93,6 +94,42 @@ test('lost GitHub read access takes effect at ten minutes and before every boardassert.deepEqual(await box.auth.boardsFor(signed.token), [], 'a denied write invalidates an earlier allowed read');});+test('person token management lists only owned scoped metadata and preserves independent revocation [H2,H9]', async (t) => {+ const box = await fixture(t);+ const person = await login(box);+ await box.auth.linkBoard(person.token, 'alpha', 'fixture/repository');+ await box.auth.linkBoard(person.token, 'beta', 'fixture/repository');+ const first = await box.auth.issueToken(person.token, { board: 'alpha', agent: 'worker-one' });+ const second = await box.auth.issueToken(person.token, { board: 'alpha', agent: 'worker-two' });+ const other = await box.auth.issueToken(person.token, { board: 'beta', agent: 'worker-one' });+ const foreign = new DatabaseSync(box.database);+ try {+ foreign.prepare('INSERT INTO relay_users(id,login) VALUES (?,?)').run('8', 'other-person');+ foreign.prepare('INSERT INTO relay_credentials(id,hash,kind,user_id,board,agent,expires) VALUES (?,?,?,?,?,?,?)')+ .run('foreign-private-fixture', 'f'.repeat(64), 'board', '8', 'alpha', 'foreign-worker', Date.now() + 60_000);+ } finally { foreign.close(); }+ const listed = await box.auth.listTokens(person.token, 'alpha');+ assert.equal(listed.length, 2);+ assert.deepEqual(listed.map((row) => row.agent), ['worker-one', 'worker-two']);+ for (const row of listed) {+ assert.deepEqual(Object.keys(row).sort(), ['agent', 'board', 'expires', 'id', 'revoked']);+ assert.equal(row.board, 'alpha');+ assert.equal(row.revoked, false);+ }+ for (const secret of [person.token, first.token, second.token, other.token]) {+ assert.equal(JSON.stringify(listed).includes(secret), false, 'listing never includes a credential value');+ }+ await assert.rejects(box.auth.listTokens(first.token, 'alpha'), { code: 'HUMAN_REQUIRED' });+ await assert.rejects(box.auth.listTokens(first.token, 'beta'), { code: 'TOKEN_BOARD' });+ await box.auth.revoke(person.token, first.id);+ assert.equal((await box.auth.listTokens(person.token, 'alpha')).find((row) => row.id === first.id).revoked, true);+ await assert.rejects(box.auth.authenticate(first.token, { board: 'alpha', write: true }), { code: 'AUTH_REQUIRED' });+ assert.equal((await box.auth.authenticate(second.token, { board: 'alpha', write: true })).agent, 'worker-two');+ assert.equal((await box.auth.authenticate(other.token, { board: 'beta', write: true })).agent, 'worker-one');+ box.state.permission = 'read';+ await assert.rejects(box.auth.listTokens(person.token, 'alpha'), { code: 'WRITE_REQUIRED' });+});+test('credentials are hash-only, expire, revoke individually and survive relay restart [H8, H1]', async (t) => {const box = await fixture(t, { sessionTTL: 30_000 });const signed = await login(box);