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.

feat(relay): a phone first screen says how to finish pairing [H17,H5]

Corey Olsone0122c86301a
diff --git a/relay/browser-client.js b/relay/browser-client.js
index 20644548..ad17d359 100644
--- a/relay/browser-client.js
+++ b/relay/browser-client.js
@@ -6,7 +6,7 @@ import { snapshotState, presentationState } from './model.js';
import { ENGINE_VERSION } from './engine.js';
import { Refused } from './refused.js';
import { enqueueStream, followStream } from './browser-stream.js';
-import { noticeLines, rememberOwnedRequestId, storedOwnedRequestState } from './browser-notice.js';
+import { homeLineDismissed, homeScreenLine, noticeLines, nothingShared, rememberOwnedRequestId, showRelayScreen, storedOwnedRequestState } from './browser-notice.js';
import { registerApp, requestPairingPersistence } from './install.js';
const KEYS = 'pullboard.relay.keys.v1';
@@ -138,21 +138,19 @@ export async function createTransport({ onUpdate = () => {} } = {}) {
paragraph.textContent = text;
element.append(paragraph);
}
+ // With nothing this device can open, the one-command screen shows; the page's poll fills the board in by itself.
+ showRelayScreen(document.documentElement, nothingShared({ paired, waitingBoards, failure }) ? 'share' : null);
}
- /** Ask once after pairing, retaining one refusal line through later board refreshes. */
+ /** Ask once after pairing; a refusal leaves one dismissible line under the board, never above it. */
function keepPairingStorage() {
persistenceRequest ??= requestPairingPersistence().then(kept => {
const current = document.getElementById('pairing-storage-notice');
- if (kept) { current?.remove(); return; }
- const target = document.getElementById('relay-notice');
- if (!target || accessLost) return;
- const paragraph = current ?? document.createElement('p');
- paragraph.id = 'pairing-storage-notice';
- paragraph.className = 'card-panel';
- paragraph.setAttribute('role', 'status');
- paragraph.textContent = 'This browser may remove your pairing. Add Pullboard to your Home Screen to help keep it.';
- if (!current) target.insertAdjacentElement('afterend', paragraph);
+ if (kept || homeLineDismissed(localStorage)) { current?.remove(); return; }
+ const main = document.querySelector('main');
+ // The answer comes later: a board lost meanwhile, or access lost, leaves no line about keeping it.
+ if (!main || accessLost || current || paired.size === 0) return;
+ main.append(homeScreenLine(document, localStorage));
});
}
@@ -518,6 +516,8 @@ export async function createTransport({ onUpdate = () => {} } = {}) {
catch { failure = 'The pairing link is invalid. Get a new link from a linked machine.'; failureBoard = null; notice(); }
}
addEventListener('hashchange', pairingChanged);
+ // A pairing link opened in another tab, as a scanned QR does, saves its key here: this page fills in by itself.
+ addEventListener('storage', event => { if (event.key === KEYS && !accessLost) listing().then(onUpdate, notice); });
addEventListener('pagehide', () => { for (const entry of paired.values()) entry.stream?.close(); });
if (await enrollPhone((path, options) => documentAt(path, denied, options))) keepPairingStorage();
await listing();
diff --git a/relay/browser-notice.js b/relay/browser-notice.js
index bb4fd1fa..ddeff3a4 100644
--- a/relay/browser-notice.js
+++ b/relay/browser-notice.js
@@ -64,3 +64,112 @@ export function noticeLines({ available, paired, ownedRequestIds = new Map(), wa
if (!available.length) lines.push('No linked boards are available for this account.');
return lines;
}
+
+/** The approved words of the two first screens another device can show (#757); the view may draw them from these. */
+export const RELAY_SCREEN_WORDS = Object.freeze({
+ signIn: Object.freeze({ title: 'Your boards, on your phone', say: 'Sign in with the GitHub account you use on your computer.',
+ action: 'Sign in with GitHub', small: 'Nothing to install on your phone.', help: 'Stuck? On your computer, ask your agent', ask: 'Help me see my boards on my phone.' }),
+ share: Object.freeze({ title: 'One step on your computer', say: 'On the computer with your projects, open a terminal and run this once:',
+ command: 'pullboard relay on --all', agent: 'Ask your agent', ask: 'Help me share my boards with my phone.',
+ small: 'It shares every project with your account. Your boards show up here by themselves.', waiting: 'Waiting for your boards' }),
+});
+
+const MARK = '<svg viewBox="0 0 64 64" aria-hidden="true"><path fill="currentColor" d="M8 7h35a6 6 0 0 1 6 6v7H8a5 5 0 0 1-5-5v-3a5 5 0 0 1 5-5Z"/><rect fill="var(--accent)" width="56" height="14" x="3" y="25" rx="5"/><path fill="currentColor" d="M8 43h35a6 6 0 0 1 6 6v8H8a5 5 0 0 1-5-5v-4a5 5 0 0 1 5-5Z"/></svg>';
+const GITHUB = '<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8Z"/></svg>';
+const SPEECH = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12Z"/></svg>';
+
+/**
+ * The markup of one first screen, served inside the hosted page and shown only while the page's state names it.
+ * Why markup on the server: the screen is there at first paint, before any script, so a phone never flashes the board.
+ * @param {'sign-in'|'share'} name
+ * @param {string} signIn - the same-site path that starts GitHub sign-in
+ */
+export function relayScreenMarkup(name, signIn) {
+ const head = '<div class="relay-mark">' + MARK + 'Pullboard</div>';
+ if (name === 'sign-in') {
+ const words = RELAY_SCREEN_WORDS.signIn;
+ return '<section id="relay-screen" aria-label="Pullboard"><div class="relay-panel" data-screen="sign-in">' + head
+ + '<h1>' + words.title + '</h1><p class="relay-say">' + words.say + '</p>'
+ + '<a class="relay-big relay-github" href="' + signIn + '">' + GITHUB + words.action + '</a>'
+ + '<p class="relay-small">' + words.small + '</p>'
+ + '<div class="relay-help">' + SPEECH + '<span>' + words.help + '<small>“' + words.ask + '”</small></span><button type="button" data-copy="' + words.ask + '">Copy</button></div>'
+ + '</div></section>';
+ }
+ const words = RELAY_SCREEN_WORDS.share;
+ return '<section id="relay-screen" aria-label="Pullboard"><div class="relay-panel" data-screen="share">' + head
+ + '<h1>' + words.title + '</h1><p class="relay-say">' + words.say + '</p>'
+ + '<div class="relay-box relay-command"><code><span aria-hidden="true">$ </span>' + words.command + '</code><button type="button" data-copy="' + words.command + '">Copy</button></div>'
+ + '<div class="relay-or">or</div>'
+ + '<div class="relay-box relay-agent">' + SPEECH + '<span>' + words.agent + '<small>“' + words.ask + '”</small></span><button type="button" data-copy="' + words.ask + '">Copy</button></div>'
+ + '<p class="relay-small">' + words.small + '</p>'
+ + '<p class="relay-live" role="status"><i aria-hidden="true"></i>' + words.waiting + '</p>'
+ + '</div></section>';
+}
+
+/** True when this device can open no board and none is on its way, so the one-command screen is the next step. */
+export function nothingShared({ paired, waitingBoards, failure }) {
+ return paired.size === 0 && waitingBoards.size === 0 && !failure;
+}
+
+/**
+ * Name the first screen the page shows, or none so the board shows. The state is the root's data-relay-screen,
+ * which the stylesheet reads; clearing it gives back only the screen this transport set.
+ */
+export function showRelayScreen(root, name) {
+ if (name) root.dataset.relayScreen = name;
+ else if (root.dataset.relayScreen === 'share') delete root.dataset.relayScreen;
+}
+
+/** Copy a screen's sentence or command; a browser without the clipboard API copies from a selected field. */
+async function copyText(text) {
+ try { await navigator.clipboard.writeText(text); return; }
+ catch { /* Fall back to a selected field below: older and embedded browsers refuse the clipboard API. */ }
+ const field = document.createElement('textarea');
+ field.value = text;
+ field.setAttribute('readonly', '');
+ field.style.position = 'fixed';
+ field.style.opacity = '0';
+ document.body.append(field);
+ field.select();
+ document.execCommand('copy');
+ field.remove();
+}
+
+/** Make every Copy button on the first screens copy its own words and say so for a moment. */
+export function wireRelayScreens(root) {
+ root.addEventListener('click', async event => {
+ const button = event.target instanceof Element ? event.target.closest('button[data-copy]') : null;
+ if (!button) return;
+ await copyText(button.dataset.copy);
+ button.textContent = 'Copied';
+ setTimeout(() => { button.textContent = 'Copy'; }, 1600);
+ });
+}
+
+const HOME_LINE = 'pullboard.relay.home-screen-line.v1';
+
+/** True once the person dismissed the Home Screen line on this device; unreadable storage shows it again. */
+export function homeLineDismissed(storage) {
+ try { return storage.getItem(HOME_LINE) === 'dismissed'; } catch { return false; }
+}
+
+/** One dismissible line, under the board, that suggests the Home Screen so the browser keeps this pairing. */
+export function homeScreenLine(doc, storage) {
+ const line = doc.createElement('p');
+ line.id = 'pairing-storage-notice';
+ line.className = 'relay-line';
+ line.setAttribute('role', 'status');
+ const text = doc.createElement('span');
+ text.textContent = 'Add to Home Screen to keep this pairing.';
+ const dismiss = doc.createElement('button');
+ dismiss.type = 'button';
+ dismiss.setAttribute('aria-label', 'Dismiss');
+ dismiss.title = 'Dismiss';
+ dismiss.innerHTML = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/></svg>';
+ dismiss.addEventListener('click', () => {
+ try { storage.setItem(HOME_LINE, 'dismissed'); } catch { /* Unsaved, the line comes back next visit; it still goes now. */ }
+ line.remove();
+ });
+ line.append(text, dismiss);
+ return line;
+}
diff --git a/relay/browser-page.js b/relay/browser-page.js
index 0847cfbe..de2c0ace 100644
--- a/relay/browser-page.js
+++ b/relay/browser-page.js
@@ -4,12 +4,22 @@ import { readFileSync } from 'node:fs';
import { cockpitPage } from '../src/cockpit.js';
import { ENGINE_VERSION } from '../src/machine.js';
import { Refused } from '../src/refused.js';
+import { relayScreenMarkup } from './browser-notice.js';
const STYLES = readFileSync(new URL('../src/view.css', import.meta.url), 'utf8');
/** Refuse relay startup locally while the public shell has no relay session; keep its sign-in link and never reload. */
const SIGN_IN_TRANSPORT = '/** Preserve device-only pairing before sign-in without starting relay reads. */\nimport { rememberPairing } from "./client.js";\nimport { registerApp } from "./install.js";\nexport function createTransport() {\n void registerApp();\n rememberPairing();\n throw new Error("Sign in with GitHub to open your linked boards.");\n}\n';
+/**
+ * Name the device before first paint: a phone or tablet (a coarse pointer and no hover) never runs Pullboard, so
+ * signed out it shows the sign-in screen and nothing about this computer. A computer keeps the page's own states.
+ */
+function deviceScript(relaySession) {
+ return "(() => { const root = document.documentElement; if (!matchMedia('(pointer: coarse)').matches || !matchMedia('(hover: none)').matches) return;"
+ + " root.dataset.relayDevice = 'phone';" + (relaySession ? '' : " root.dataset.relayScreen = 'sign-in';") + ' })();';
+}
+
/** Serve a fixed asset with cache and browser isolation boundaries, never a filesystem-derived URL. */
function respond(res, type, content, scriptHashes = []) {
const hashes = scriptHashes.map(hash => "'sha256-" + hash + "'").join(' ');
@@ -25,6 +35,8 @@ function respond(res, type, content, scriptHashes = []) {
export function createRelayBrowserHandler({ authenticate }) {
const assets = new Map([
['/view.css', ['text/css', STYLES]],
+ ['/relay/screens.css', ['text/css', readFileSync(new URL('./browser-screens.css', import.meta.url), 'utf8')]],
+ ['/relay/screens.js', ['text/javascript', '/** Wire the first screens\' Copy buttons [H17]. */\nimport { wireRelayScreens } from \'./browser-notice.js\';\nwireRelayScreens(document);\n']],
['/manifest.webmanifest', ['application/manifest+json', readFileSync(new URL('./app.webmanifest', import.meta.url), 'utf8')]],
['/service-worker.js', ['text/javascript', readFileSync(new URL('./service-worker.js', import.meta.url), 'utf8')]],
['/icons/pullboard.svg', ['image/svg+xml', readFileSync(new URL('./icons/pullboard.svg', import.meta.url), 'utf8')]],
@@ -66,7 +78,10 @@ export function createRelayBrowserHandler({ authenticate }) {
: '<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: relaySession, transportModule: relaySession ? '/relay/client.js' : '/relay/sign-in.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' })
.replace('<link rel="icon" href="data:,">', '<link rel="icon" href="/icons/pullboard.svg" type="image/svg+xml">\n<link rel="manifest" href="/manifest.webmanifest">\n<link rel="apple-touch-icon" href="/icons/pullboard-192.png">\n<meta name="theme-color" content="#f6faf7">')
- .replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status">' + notice + '</section>');
+ .replace('</head>', '<link rel="stylesheet" href="/relay/screens.css">\n<script>' + deviceScript(relaySession) + '</script>\n</head>')
+ .replace('<div class="shell">', relayScreenMarkup(relaySession ? 'share' : 'sign-in', '/auth/github/start') + '\n<div class="shell">')
+ .replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status">' + notice + '</section>')
+ .replace('</body>', '<script type="module" src="/relay/screens.js"></script>\n</body>');
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/relay/browser-screens.css b/relay/browser-screens.css
new file mode 100644
index 00000000..ceb48d2d
--- /dev/null
+++ b/relay/browser-screens.css
@@ -0,0 +1,57 @@
+/*
+ * The first screens another device shows on the hosted page (#757 [H17,H5]): "Your boards, on your phone" before
+ * sign-in on a phone or tablet, and "One step on your computer" once signed in with nothing to open. The page's
+ * root names the screen in data-relay-screen; while it does, the screen is all the page shows. Colours come from
+ * the view's tokens, so the theme the person picked applies here too.
+ */
+#relay-screen { display: none; }
+:root[data-relay-screen] body > :not(#relay-screen) { display: none !important; }
+:root[data-relay-screen="sign-in"] #relay-screen, :root[data-relay-screen="share"] #relay-screen {
+ display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 32px 20px; background: var(--ground);
+}
+.relay-panel { display: none; width: 100%; max-width: 440px; text-align: center; font-size: 16px; }
+:root[data-relay-screen="sign-in"] .relay-panel[data-screen="sign-in"],
+:root[data-relay-screen="share"] .relay-panel[data-screen="share"] { display: block; }
+.relay-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
+.relay-mark svg { width: 28px; height: 28px; }
+.relay-panel h1 { margin: 22px 0 0; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; text-wrap: balance; }
+.relay-say { margin: 12px auto 0; color: var(--ink-muted); font-size: 17px; text-wrap: balance; }
+.relay-small { margin: 12px auto 0; color: var(--ink-muted); font-size: 14.5px; text-wrap: balance; }
+
+/* One action, 60 px tall: the GitHub button is dark in either theme, and each box beside it is the same height. */
+.relay-big { display: flex; align-items: center; justify-content: center; gap: 12px; box-sizing: border-box; height: 60px; margin-top: 28px;
+ border-radius: 14px; background: #1f2328; color: #fff; font-weight: 600; font-size: 18px; text-decoration: none; }
+:root[data-scheme="dark"] .relay-big { border: 1px solid var(--line-strong); }
+.relay-big svg { width: 22px; height: 22px; }
+.relay-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; box-sizing: border-box; height: 60px;
+ padding: 0 8px 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-align: left; }
+.relay-command { margin-top: 28px; }
+.relay-command code { overflow: hidden; font: 600 14px var(--mono); white-space: nowrap; text-overflow: ellipsis; }
+.relay-command code span { color: var(--ink-faint); }
+.relay-agent > span, .relay-help > span { flex: 1; display: block; font-weight: 600; line-height: 1.3; }
+.relay-agent small, .relay-help small { display: block; color: var(--ink-muted); font-weight: 400; font-size: 13px; }
+.relay-agent svg, .relay-help svg { flex: none; width: 22px; height: 22px; color: var(--accent); }
+.relay-box button, .relay-help button { flex: none; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
+ background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer; }
+.relay-or { display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--ink-faint); font-size: 13.5px; }
+.relay-or::before, .relay-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
+.relay-help { display: flex; align-items: center; gap: 12px; margin-top: 26px; padding: 10px 10px 10px 14px; border: 1px dashed var(--line-strong);
+ border-radius: 14px; text-align: left; color: var(--ink-muted); font-size: 14.5px; }
+.relay-help > span { color: var(--ink-muted); font-weight: 400; }
+.relay-help small { color: var(--ink); font-size: 15px; font-weight: 600; }
+.relay-live { display: inline-flex; align-items: center; gap: 10px; margin: 22px 0 0; padding: 8px 14px; border: 1px solid var(--line);
+ border-radius: 999px; background: var(--surface); color: var(--ink-muted); font-size: 14.5px; }
+.relay-live i { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: relay-pulse 1.4s ease-in-out infinite; }
+@keyframes relay-pulse { 50% { opacity: .25; transform: scale(.8); } }
+@media (prefers-reduced-motion: reduce) { .relay-live i { animation: none; } }
+
+/* A phone never runs the view, so the note about reaching one on this computer is never its business. */
+:root[data-relay-device="phone"] #local-note { display: none !important; }
+
+/* The Home Screen suggestion: one line under the board, gone for good once dismissed. */
+.relay-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 0; padding: 6px 6px 6px 14px;
+ border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink-muted); white-space: nowrap; }
+.relay-line span { overflow: hidden; text-overflow: ellipsis; }
+.relay-line button { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none;
+ color: var(--ink-faint); cursor: pointer; }
+.relay-line button svg { width: 16px; height: 16px; }
diff --git a/test/relay-browser.test.js b/test/relay-browser.test.js
index 2b2653bd..87a421d6 100644
--- a/test/relay-browser.test.js
+++ b/test/relay-browser.test.js
@@ -482,6 +482,153 @@ test('an unauthenticated pairing link stays device-only through sign-in and a wr
assert.equal(box.keyInRequest(), false);
});
+/** Make this browser a 390-wide touch phone, so the page sees a coarse pointer and no hover. */
+async function asPhone(chrome) {
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
+ await chrome.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
+}
+
+/** Install the person's real stand-in session cookie without reading any board link. */
+async function personCookie(chrome, box) {
+ const result = await chrome.send('Network.setCookie', {
+ name: 'pb_session', value: (await box.phoneSession()).token, url: box.origin, httpOnly: true, sameSite: 'Lax',
+ });
+ assert.equal(result.success, true, 'the real person session is installed in this private browser');
+}
+
+/** What a person can read and press on the page now: visible text, actions, sizes and colours. */
+const SCREEN_FACTS = `(() => {
+ const shown = node => node.getClientRects().length > 0 && getComputedStyle(node).visibility !== 'hidden';
+ const box = selector => { const node = document.querySelector(selector); return node && shown(node) ? Math.round(node.getBoundingClientRect().height) : null; };
+ const github = document.querySelector('#relay-screen .relay-github');
+ const rgb = github && shown(github) ? getComputedStyle(github).backgroundColor.match(/[0-9.]+/g).slice(0, 3).map(Number) : null;
+ return {
+ screen: document.documentElement.dataset.relayScreen ?? null,
+ text: document.body.innerText,
+ actions: [...document.querySelectorAll('a[href], button')].filter(shown).map(node => node.textContent.trim()),
+ cards: [...document.querySelectorAll('.card-panel')].filter(shown).length,
+ footer: shown(document.querySelector('footer.status')),
+ github: box('#relay-screen .relay-github'), githubLight: rgb && (0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]) / 255,
+ command: box('#relay-screen .relay-command'), agent: box('#relay-screen .relay-agent'),
+ commandFont: document.querySelector('#relay-screen .relay-command code') ? getComputedStyle(document.querySelector('#relay-screen .relay-command code')).fontFamily : null,
+ };
+})()`;
+
+/** Press a screen's Copy button and return what it put on the clipboard. */
+async function copied(chrome, selector) {
+ return chrome.evaluate(`(async () => {
+ const written = new Promise(resolveCopy => {
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText: async value => resolveCopy(value) } });
+ });
+ document.querySelector(${JSON.stringify(selector)}).click();
+ return written;
+ })()`);
+}
+
+const THIS_COMPUTER = /this computer|this machine|pullboard view|local view|try again/iu;
+
+test('a phone not signed in sees one GitHub button and nothing about this computer [H17,H5]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+}, async t => {
+ const box = await relayClientFixture(t);
+ const marker = 'PHONE_FIRST_SCREEN_BOARD_757';
+ assert.equal((await box.cli('add', box.lane, marker)).code, 0);
+ await box.link();
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const encoded = readFileSync(box.keyFile, 'utf8').trim();
+ const computer = await startChrome();
+ t.after(() => computer.close());
+ await computer.navigate(box.origin);
+ await computer.waitFor("document.readyState === 'complete' && document.querySelector('#relay-screen') !== null");
+ assert.equal(await computer.evaluate('document.documentElement.dataset.relayScreen ?? null'), null, 'a computer keeps the page its own states draw');
+
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: "Object.defineProperty(navigator.storage, 'persist', { value: async () => false });" });
+ await asPhone(chrome);
+ const opened = [['directly', box.origin + '/'], ['after a pairing QR', box.origin + '/#device=' + 'A'.repeat(22) + '.' + 'B'.repeat(43)]];
+ for (const [how, url] of opened) {
+ await chrome.navigate('about:blank'); // A scanned QR opens a new page, never a fragment change in this one.
+ await chrome.navigate(url);
+ await chrome.waitFor("document.documentElement.dataset.relayScreen === 'sign-in' && location.hash === ''");
+ const facts = await chrome.evaluate(SCREEN_FACTS);
+ for (const words of ['Your boards, on your phone', 'Sign in with GitHub', 'Nothing to install on your phone.', 'Stuck? On your computer, ask your agent', 'Help me see my boards on my phone.']) {
+ assert.equal(facts.text.includes(words), true, how + ': the first screen says ' + words);
+ }
+ assert.deepEqual(facts.actions, ['Sign in with GitHub', 'Copy'], how + ': one GitHub button, and Copy for the sentence to the agent');
+ assert.doesNotMatch(facts.text, THIS_COMPUTER, how + ': nothing about this computer or pullboard view');
+ assert.doesNotMatch(facts.text, /\brelay\b|\blinked\b/iu, how + ': no relay or linked words');
+ assert.equal(facts.cards, 0, how + ': no empty cards');
+ assert.equal(facts.footer, false, how + ': no error footer');
+ assert.equal(facts.github, 60, how + ': the GitHub button is 60 px tall');
+ assert.ok(facts.githubLight < 0.2, how + ': the GitHub button is dark');
+ assert.equal(facts.text.trim().endsWith('Copy'), true, how + ': the screen ends with the Stuck line and its Copy');
+ }
+ assert.equal(await chrome.evaluate("sessionStorage.getItem('pullboard.relay.device-pair.v1') !== null"), true, 'the scanned pairing waits on this phone through sign-in');
+ assert.equal(await copied(chrome, '#relay-screen [data-copy]'), 'Help me see my boards on my phone.');
+ await chrome.evaluate('sessionStorage.clear()'); // The stand-in code above was never a real pairing.
+
+ await chrome.navigate('about:blank');
+ await chrome.navigate(box.origin + '/#board=' + link.board + '&key=' + encoded);
+ await chrome.waitFor("document.documentElement.dataset.relayScreen === 'sign-in' && location.hash === ''");
+ await chrome.evaluate("document.querySelector('#relay-screen .relay-github').click()");
+ await chrome.waitFor("document.querySelector('#chain')?.textContent.includes(" + JSON.stringify(marker) + ") && document.querySelector('#pairing-storage-notice') !== null");
+ const board = await chrome.evaluate(`({ text: document.body.innerText, screen: document.documentElement.dataset.relayScreen ?? null,
+ after: Boolean(document.querySelector('#chain').compareDocumentPosition(document.querySelector('#pairing-storage-notice')) & Node.DOCUMENT_POSITION_FOLLOWING),
+ line: (() => { const range = document.createRange(); range.selectNodeContents(document.querySelector('#pairing-storage-notice span')); return range.getClientRects().length; })(),
+ lineText: document.querySelector('#pairing-storage-notice').innerText })`);
+ assert.equal(board.screen, null, 'the GitHub button leads straight to the board');
+ assert.doesNotMatch(board.text, THIS_COMPUTER, 'the paired phone says nothing about this computer or pullboard view');
+ assert.equal(board.after, true, 'the board shows before the Home Screen line');
+ assert.equal(board.line, 1, 'the Home Screen notice is one line');
+ assert.match(board.lineText, /Home Screen/u);
+ await chrome.evaluate("document.querySelector('#pairing-storage-notice button').click()");
+ assert.equal(await chrome.evaluate("document.querySelector('#pairing-storage-notice') === null"), true, 'the Home Screen line dismisses');
+ await chrome.navigate(box.origin + '/');
+ await chrome.waitFor("document.querySelector('#chain')?.textContent.includes(" + JSON.stringify(marker) + ')');
+ assert.equal(await chrome.evaluate("document.querySelector('#pairing-storage-notice') === null"), true, 'a dismissed line stays dismissed');
+});
+
+test('signed in with nothing shared shows one command and waits [H5,H17]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+}, async t => {
+ const box = await relayClientFixture(t);
+ const marker = 'SHARED_WHILE_WAITING_757';
+ assert.equal((await box.cli('add', box.lane, marker)).code, 0);
+ for (const device of ['a phone', 'another computer']) {
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ if (device === 'a phone') await asPhone(chrome);
+ await personCookie(chrome, box);
+ await chrome.navigate(box.origin);
+ await chrome.waitFor("document.documentElement.dataset.relayScreen === 'share'");
+ const facts = await chrome.evaluate(SCREEN_FACTS);
+ for (const words of ['One step on your computer', 'pullboard relay on --all', 'Ask your agent', 'Help me share my boards with my phone.', 'Waiting for your boards']) {
+ assert.equal(facts.text.includes(words), true, device + ': the screen says ' + words);
+ }
+ assert.deepEqual(facts.actions, ['Copy', 'Copy'], device + ': Copy for the command and Copy for the agent sentence, and nothing to retry');
+ assert.doesNotMatch(facts.text.replace('pullboard relay on --all', ''), /\brelay\b|\blinked\b|local view|try again/iu, device + ': relay only inside the command');
+ assert.equal(facts.command, 60, device + ': the command box is 60 px tall');
+ assert.equal(facts.agent, 60, device + ': the agent box is the same height');
+ assert.match(facts.commandFont, /mono|Menlo|Consolas/iu, device + ': the command is in a mono box');
+ if (device === 'a phone') {
+ assert.doesNotMatch(facts.text, THIS_COMPUTER, 'the phone says nothing about this computer or pullboard view');
+ assert.equal(await copied(chrome, '#relay-screen .relay-command button'), 'pullboard relay on --all');
+ assert.equal(await copied(chrome, '#relay-screen .relay-agent button'), 'Help me share my boards with my phone.');
+ await chrome.evaluate('window.samePage757 = true');
+ await box.link();
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const encoded = readFileSync(box.keyFile, 'utf8').trim();
+ // The person scans the QR into a second tab of the same phone browser; this tab is never touched.
+ const tab = await chrome.send('Target.createTarget', { url: box.origin + '/#board=' + link.board + '&key=' + encoded });
+ assert.equal(typeof tab.targetId, 'string');
+ await chrome.waitFor("document.querySelector('#chain')?.textContent.includes(" + JSON.stringify(marker) + ')');
+ assert.equal(await chrome.evaluate("window.samePage757 === true && (document.documentElement.dataset.relayScreen ?? null) === null"), true,
+ 'the waiting page fills in by itself, with no click and no reload');
+ }
+ }
+});
+
/** A pre-ordered mirror's durable local outbox keeps its final browser projection recoverable. */
test('legacy queued presentations never disclose later unacknowledged moves [H5,H15]', async t => {
const box = await relayClientFixture(t);