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
fix(relay): show phone approvals before boards [N26,H5,H17]
Corey Olson7a8402104102
diff --git a/relay/browser-approval-card.js b/relay/browser-approval-card.jsindex 12da6043..718788c1 100644--- a/relay/browser-approval-card.js+++ b/relay/browser-approval-card.js@@ -35,9 +35,26 @@ export function deletedText(names) {/** Card spacing for the relay page; served after the shared view styles. */export const APPROVAL_CARD_STYLES = `+#phone-approvals:empty { display: none; }+.relay-panel #phone-approvals { margin-top: 20px; text-align: left; }.phone-approval { display: grid; gap: 10px; padding: 14px 16px; }.phone-approval p { margin: 0; overflow-wrap: anywhere; }.phone-approval-title { font-weight: 600; }.phone-approval-detail { color: var(--ink-muted); }.phone-approval button { justify-self: start; }`;++/** Keep the same authenticated cards and live handlers on the phone's visible screen until a board can draw. */+export function placePhoneApprovals(doc) {+ const panel = doc.getElementById('phone-approvals');+ if (!panel) return null;+ const root = doc.documentElement;+ const frame = root?.dataset.relayDevice === 'phone' && root.dataset.relayScreen === 'share'+ ? doc.querySelector('#relay-screen .relay-panel[data-screen="share"]') : null;+ const host = frame ?? doc.querySelector('main');+ if (!host || panel.parentElement === host) return panel;+ const mark = frame?.querySelector('.relay-mark');+ if (mark) mark.after(panel);+ else host.prepend(panel);+ return panel;+}diff --git a/relay/browser-client.js b/relay/browser-client.jsindex a6e067ec..670e467b 100644--- a/relay/browser-client.js+++ b/relay/browser-client.js@@ -8,6 +8,7 @@ import { Refused } from './refused.js';import { enqueueStream, followStream } from './browser-stream.js';import { homeLineDismissed, homeScreenLine, noticeLines, nothingShared, rememberOwnedRequestId, showRelayScreen, storedOwnedRequestState } from './browser-notice.js';import { registerApp, requestPairingPersistence } from './install.js';+import { placePhoneApprovals } from './browser-approval-card.js';const KEYS = 'pullboard.relay.keys.v1';const PENDING = 'pullboard.relay.pair.v1';@@ -180,6 +181,7 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>const phoneWaiting = root.dataset.relayDevice === 'phone' && paired.size === 0;showRelayScreen(root, phoneWaiting || nothingShared({ paired, waitingBoards, failure }) ? 'share' : null,phoneWaiting && (failure || waitingBoards.size) ? lines.join(' ') : '');+ placePhoneApprovals(document);}/** Ask once after pairing; a refusal leaves one dismissible line under the board, never above it. */@@ -589,6 +591,8 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>if (await enrollPhone((path, options) => documentAt(path, denied, options))) keepPairingStorage();await listing();await installPhoneApprovals((path, options) => documentAt(path, denied, options), keys, openApprovedBoard, access.signal);+ // The existing startup awaits the first feed; move its authenticated cards before handing the transport to the view.+ placePhoneApprovals(document);return {/** Return decoded API state or seal narrow person intent; no board key or plaintext leaves the device. */async request(path, body) {diff --git a/test/relay-client-fixture.js b/test/relay-client-fixture.jsindex d62211f9..f8f28893 100644--- a/test/relay-client-fixture.js+++ b/test/relay-client-fixture.js@@ -544,9 +544,9 @@ globalThis.fetch = function tracedFetch(input, init) {cliChildDeadlineMs(snapshotUploads);return runCliChild(args, snapshotUploads, true);}- /** Start the production CLI with live output so a browser confirmation can interleave with SSH sign-in. */- function startCli(args, extraEnv = {}) {- const child = spawn(process.execPath, [CLI, ...args, '--json'], { cwd: root, env: { ...env, ...extraEnv }, stdio: ['ignore', 'pipe', 'pipe'] });+ /** Start live CLI output; raw mode also preserves the foreground wait for an already-paired phone's link tap. */+ function startCli(args, extraEnv = {}, { json = true } = {}) {+ const child = spawn(process.execPath, [CLI, ...args, ...(json ? ['--json'] : [])], { cwd: root, env: { ...env, ...extraEnv }, stdio: ['ignore', 'pipe', 'pipe'] });let stdout = '';let stderr = '';const deadlineMs = cliChildDeadlineMs(DEFAULT_SNAPSHOT_UPLOADS);diff --git a/test/relay-person-page.test.js b/test/relay-person-page.test.jsindex 780e847e..94254cc6 100644--- a/test/relay-person-page.test.js+++ b/test/relay-person-page.test.js@@ -1,17 +1,116 @@/** Actual relay cockpit request capability and exported read-only guards [H12,H5]. */import assert from 'node:assert/strict';import { createServer } from 'node:http';-import { existsSync, readFileSync, statSync } from 'node:fs';-import { join } from 'node:path';+import { existsSync, mkdirSync, readFileSync, statSync } from 'node:fs';+import { dirname, join } from 'node:path';import { test } from 'node:test';import { cockpitPage } from '../src/cockpit.js';import { ENGINE_VERSION } from '../src/machine.js';import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';import { relayClientFixture } from './relay-client-fixture.js';import { createRelayBrowserHandler } from '../relay/browser-page.js';+import { runFixtureGit } from './fixture-child.js';const chromeOptions = { skip: !findChromeExecutable() && 'Chrome is not installed' };+/** Wait for a private native setup transition without repeating its command or weakening an assertion. */+async function phoneSetupState(read, message) {+ const deadline = Date.now() + 20_000; // budget: declared hang ceiling for a private enrollment/approval metadata transition.+ while (Date.now() < deadline) {+ const value = read();+ if (value) return value;+ await new Promise(resolveWait => setTimeout(resolveWait, 25));+ }+ assert.fail(message);+}++test('a phone with no readable board can tap its pending link and open that board [N26,H5,H17]', chromeOptions, async t => {+ const box = await relayClientFixture(t);+ const chrome = await startChrome();+ t.after(() => chrome.close());+ // Set the input device before navigation; resizing a page after its desktop startup cannot prove the phone path.+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });+ await chrome.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `const phoneFixtureFetch = window.fetch;+window.fetch = (input, options) => {+ const url = new URL(typeof input === 'string' ? input : input.url, location.href);+ if (['http://127.0.0.1:4890', 'http://localhost:4890'].includes(url.origin)) return Promise.reject(new TypeError('No local view in this private phone fixture'));+ return phoneFixtureFetch(input, options);+};` });+ assert.equal((await chrome.send('Network.setCookie', {+ name: 'pb_session', value: (await box.phoneSession()).token, url: box.origin, httpOnly: true, sameSite: 'Lax',+ })).success, true, 'only the synthetic fixture session is installed');+ const setup = box.startCli(['relay', 'on', '--all', '--url', box.origin]);+ const machineFile = join(box.env.PULLBOARD_HOME, 'relay-machine/state.json');+ const pending = await phoneSetupState(() => existsSync(machineFile) && JSON.parse(readFileSync(machineFile, 'utf8')).pending,+ 'the native command publishes its one-time phone enrollment');+ await chrome.navigate(box.origin + '/#device=' + pending.locator + '.' + pending.secret);+ const paired = await setup.closed;+ assert.equal(paired.code, 0, 'native setup authenticates this browser and delivers its original board key');+ await chrome.waitFor("document.documentElement.dataset.relayDevice === 'phone' && document.querySelector('#phone-approvals') !== null");++ const publisher = JSON.parse(readFileSync(box.linkFile, 'utf8')).board;+ // Only the phone cannot read its publisher; keep native setup healthy and preserve each real authorization read.+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `const authorizedPhoneFetch = window.fetch;+window.fetch = async (input, options) => {+ const url = new URL(typeof input === 'string' ? input : input.url, location.href);+ const response = await authorizedPhoneFetch(input, options);+ if (url.pathname === ${JSON.stringify('/api/v1/boards/' + publisher + '/state')} && response.ok) {+ return new Response(JSON.stringify({ version: 1, error: { code: 'NO_SNAPSHOT', message: 'This private phone snapshot is unavailable.' } }), {+ status: 404, headers: { 'content-type': 'application/json' },+ });+ }+ return response;+};` });+ box.providerState.repositories.push('phone-first-link');+ const target = join(dirname(box.root), 'phone-first-link');+ mkdirSync(target);+ for (const args of [['init', '-q', '-b', 'main'], ['-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-q', '-m', 'fixture base'],+ ['remote', 'add', 'origin', '[email protected]:fixture/phone-first-link.git']]) {+ runFixtureGit(args, { cwd: target, env: box.env, encoding: 'utf8' });+ }+ assert.equal((await box.cliAt(target, 'init')).code, 0, 'the actual new-project init publishes its sealed approval');+ const marker = 'FIRST_READABLE_BOARD_AFTER_ONE_PHONE_TAP_901';+ assert.equal((await box.cliAt(target, 'add', box.lane, marker)).code, 0);+ const proposal = JSON.parse(readFileSync(machineFile, 'utf8')).approvals.find(entry => entry.root === target);+ assert.equal(proposal?.published, true, 'the actual native proposal is waiting for this enrolled browser');+ const selector = '#phone-approve-' + proposal.context.id;+ const beforeForeground = box.calls.length;+ const run = box.startCli(['relay', 'on', '--all', '--url', box.origin], {}, { json: false });+ await phoneSetupState(() => box.calls.slice(beforeForeground).some(call => call.method === 'GET'+ && call.path === '/api/v1/devices/approvals/' + proposal.context.id), 'the same foreground command is actually waiting for this approval');+ await chrome.navigate('about:blank');+ await chrome.navigate(box.origin);+ await chrome.waitFor(`document.querySelector(${JSON.stringify(selector)}) !== null && Array.isArray(data?.projects)`);+ const before = await chrome.evaluate(`(() => {+ const button = document.querySelector(${JSON.stringify(selector)});+ const rect = button.getBoundingClientRect();+ return { phone: document.documentElement.dataset.relayDevice, screen: document.documentElement.dataset.relayScreen,+ listed: data?.projects?.length ?? null, shown: rect.width > 0 && rect.height > 0, cards: document.querySelectorAll('.phone-approval').length };+ })()`);+ console.log(JSON.stringify({ firstPhoneApprovalControl: before }));+ assert.equal(before.phone, 'phone');+ assert.equal(before.listed, 0, 'no readable board can dismiss the first screen');+ assert.equal(run.child.exitCode, null, 'the native foreground command is still waiting for the person');+ assert.equal(before.shown, true, 'the pending native approval must be visible, not merely present under the hidden board shell');+ await chrome.evaluate(`document.querySelector(${JSON.stringify(selector)}).scrollIntoView({ block: 'center' })`);+ const point = await chrome.evaluate(`(() => {+ const button = document.querySelector(${JSON.stringify(selector)}); const rect = button.getBoundingClientRect();+ const x = rect.left + rect.width / 2, y = rect.top + rect.height / 2;+ return { x, y, hit: button.contains(document.elementFromPoint(x, y)) };+ })()`);+ assert.equal(point.hit, true, 'the actual input target is the approval button');+ const authorizations = box.calls.filter(call => call.path.endsWith('/authorize')).length;+ await chrome.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x: point.x, y: point.y }] }, 'touch the visible native approval');+ await chrome.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }, 'release the single approval tap');+ const linked = await run.closed;+ assert.equal(linked.code, 0, 'the same foreground command finishes after one real phone tap');+ await chrome.waitFor(`document.body.innerText.includes(${JSON.stringify(marker)}) && data?.root === ${JSON.stringify(proposal.context.board)}`);+ assert.equal(await chrome.evaluate('document.documentElement.dataset.relayScreen ?? null'), null, 'the readable board replaces the first screen');+ assert.equal(box.calls.filter(call => call.path.endsWith('/authorize')).length - authorizations, 1, 'one tap authorizes exactly once');+});++test('a signed-in phone shows its first screen before a local probe can answer [N26,H5,H17]', chromeOptions, async t => {const handle = createRelayBrowserHandler({ authenticate: async () => ({ kind: 'session' }) });const server = createServer(async (req, res) => {