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): open the hosted cockpit publicly [N26,H5,A2]
Corey Olson0124a37b05e6
diff --git a/relay/browser-page.js b/relay/browser-page.jsindex 02b4bb9e..1be4ddf9 100644--- a/relay/browser-page.js+++ b/relay/browser-page.js@@ -6,7 +6,6 @@ import { ENGINE_VERSION } from '../src/machine.js';import { Refused } from '../src/refused.js';const STYLES = readFileSync(new URL('../src/view.css', import.meta.url), 'utf8');-const SIGN_IN = '<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Pullboard</title><link rel="stylesheet" href="/view.css"><body><main class="card-panel"><h1>Pullboard</h1><p>Sign in to see your linked boards.</p><a href="/auth/github/start">Sign in with GitHub</a></main><script type="module">import { rememberPairing } from "/relay/client.js"; try { rememberPairing(); } catch { document.querySelector("main p").textContent = "The pairing link is invalid. Get a new link from a linked machine."; }</script></body></html>';/** Serve a fixed asset with cache and browser isolation boundaries, never a filesystem-derived URL. */function respond(res, type, content, scriptHashes = []) {@@ -14,12 +13,12 @@ function respond(res, type, content, scriptHashes = []) {res.writeHead(200, {'content-type': type + '; charset=utf-8', 'cache-control': 'no-store','x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer',- 'content-security-policy': "default-src 'none'; script-src 'self' " + hashes + "; style-src 'self'; connect-src 'self'; img-src 'self' data:; base-uri 'none'; form-action 'self'; frame-ancestors 'none'",+ 'content-security-policy': "default-src 'none'; script-src 'self' " + hashes + "; style-src 'self'; connect-src 'self' http://127.0.0.1:4890 http://localhost:4890; img-src 'self' data:; base-uri 'none'; form-action 'self'; frame-ancestors 'none'",});res.end(content);}-/** Serve generic assets publicly and board-free sign-in HTML until a person is authenticated. */+/** Serve the board-free shell publicly; a session enables only its separate read-only relay transport. */export function createRelayBrowserHandler({ authenticate }) {const assets = new Map([['/view.css', ['text/css', STYLES]],@@ -45,17 +44,18 @@ export function createRelayBrowserHandler({ authenticate }) {return true;}if (path !== '/') return false;+ let relaySession = false;try {const who = await authenticate(req);if (who.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'Sign in as a person to open the relay view.');+ relaySession = true;} catch (error) {if (!(error instanceof Refused) || !['AUTH_REQUIRED', 'HUMAN_REQUIRED'].includes(error.code)) throw error;- const script = /<script type="module">([\s\S]*?)<\/script>/.exec(SIGN_IN)[1];- respond(res, 'text/html', SIGN_IN, [createHash('sha256').update(script).digest('base64')]);- return true;}- const page = cockpitPage('', { readOnly: true, requests: true, transportModule: '/relay/client.js', apiHeaders: {}, stylesheet: '/view.css' })- .replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status"><p>Pairing this browser…</p></section>');+ const notice = relaySession ? '<p>Pairing this browser…</p>'+ : '<p>Connecting to this machine. Sign in to see your linked boards.</p><a href="/auth/github/start">Sign in with GitHub</a>';+ const page = cockpitPage('', { readOnly: true, requests: true, transportModule: '/relay/client.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' })+ .replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status">' + notice + '</section>');const scripts = [...page.matchAll(/<script>([\s\S]*?)<\/script>/g)].map(match => createHash('sha256').update(match[1]).digest('base64'));respond(res, 'text/html', page, scripts);return true;diff --git a/test/relay-person-page.test.js b/test/relay-person-page.test.jsindex 90af54c5..781c4088 100644--- a/test/relay-person-page.test.js+++ b/test/relay-person-page.test.js@@ -11,6 +11,81 @@ import { relayClientFixture } from './relay-client-fixture.js';const chromeOptions = { skip: !findChromeExecutable() && 'Chrome is not installed' };+test("the relay page opens without a session and may call only the local view's default port [N26,H5,A2]", async t => {+ const box = await relayClientFixture(t);+ const privateTitle = 'PRIVATE_RELAY_BOARD_533';+ assert.equal((await box.cli('add', box.lane, privateTitle)).code, 0);+ await box.link();+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));+ const privateKey = readFileSync(box.keyFile, 'utf8').trim();+ const response = await fetch(box.origin + '/');+ assert.equal(response.status, 200, 'the public entry does not require a relay session');+ const page = await response.text();+ assert.ok(page.includes('id="chain"'), 'the anonymous response is the cockpit shell');+ for (const privateValue of [privateTitle, link.board, privateKey, link.token]) {+ assert.equal(page.includes(privateValue), false, 'the shell contains no private board or credential value');+ }+ const policy = response.headers.get('content-security-policy');+ const directives = new Map(policy.split(';').map(part => part.trim().split(/\s+/u)).map(([name, ...values]) => [name, values]));+ assert.deepEqual(directives.get('connect-src'), ["'self'", 'http://127.0.0.1:4890', 'http://localhost:4890'],+ 'only the relay itself and the two exact loopback default-port origins can be contacted');+ assert.deepEqual(directives.get('frame-ancestors'), ["'none'"]);+ assert.equal(response.headers.get('cache-control'), 'no-store');+ assert.equal(response.headers.get('x-content-type-options'), 'nosniff');+ assert.equal(response.headers.get('referrer-policy'), 'no-referrer');+ assert.match(page, /Sign in with GitHub/u, 'relay mode retains its sign-in path');+});++test('relay data still needs a session [N26,H5,A2]', async t => {+ const box = await relayClientFixture(t);+ const before = (await box.cli('export')).document.tables;+ const board = 'a'.repeat(32);+ const device = 'device-' + 'b'.repeat(32);+ const locator = 'c'.repeat(22);+ const prefix = '/api/v1/boards/' + board;+ const routes = [+ ['GET', '/api/v1/boards'], ['GET', '/api/v1/events?boards=' + board],+ ['GET', prefix + '/state'], ['PUT', prefix + '/state'], ['DELETE', prefix],+ ['GET', prefix + '/events?after=0'], ['POST', prefix + '/moves'], ['POST', prefix + '/requests'],+ ['GET', prefix + '/code'], ['GET', prefix + '/tokens'], ['POST', prefix + '/tokens'],+ ['GET', prefix + '/items'], ['GET', prefix + '/items/1'], ['GET', prefix + '/shouts/1'],+ ['POST', '/api/v1/pairings/' + board + '/' + locator],+ ['POST', '/api/v1/pairings/' + board + '/' + locator + '/consume'],+ ['GET', '/api/v1/devices/session'], ['POST', '/api/v1/devices/approvals'],+ ['GET', '/api/v1/devices/approvals/approval'],+ ...['authorize', 'complete', 'execute'].map(action => ['POST', '/api/v1/devices/approvals/approval/' + action]),+ ['GET', '/api/v1/devices/' + device + '/approvals'],+ ...['GET', 'POST', 'PUT', 'DELETE'].map(method => [method, '/api/v1/devices/enrollments/' + locator]),+ ['GET', '/api/v1/devices/' + device + '/boards'],+ ['PUT', '/api/v1/devices/' + device + '/boards/' + board],+ ['POST', '/api/v1/devices/' + device], ['DELETE', '/api/v1/devices/' + device],+ ...['session', 'boards'].map(path => ['GET', '/auth/' + path]),+ ['GET', '/auth/tokens?board=' + board],+ ['POST', '/auth/boards/link', { board, repository: 'fixture/project' }],+ ['POST', '/auth/machines', { board, machine: 'fixture-machine' }],+ ['POST', '/auth/tokens', { board, agent: 'fixture-agent' }],+ ['POST', '/auth/tokens/revoke', { id: 'fixture-token-id' }],+ ];+ for (const [method, path, payload] of routes) {+ const response = await fetch(box.origin + path, {+ method,+ headers: { origin: box.origin, 'content-type': 'application/json', 'x-pullboard-engine': String(ENGINE_VERSION),+ ...(path.startsWith('/api/v1/events?') ? { accept: 'text/event-stream' } : {}) },+ ...(['POST', 'PUT'].includes(method) ? { body: JSON.stringify(payload ?? {}) } : {}),+ });+ const document = await response.json();+ assert.equal(response.status, 401, method + ' ' + path + ' refuses before returning data or applying an action');+ assert.equal(document.error?.code, 'AUTH_REQUIRED', method + ' ' + path + ' reaches its authentication boundary');+ for (const field of ['boards', 'state', 'events', 'item', 'shout', 'session', 'tokens', 'wraps', 'approval']) {+ assert.equal(Object.hasOwn(document, field), false, 'an anonymous refusal carries no relay data');+ }+ }+ const after = (await box.cli('export')).document.tables;+ for (const table of ['item', 'event', 'shout', 'verdict']) {+ assert.deepEqual(after[table], before[table], 'anonymous relay calls do not change local board ' + table);+ }+});+test('the actual relay page seals its shout and refuses generic direct moves [H12,H5]', chromeOptions, async t => {const box = await relayClientFixture(t);await box.link();