Repository navigation
feat(pair): phone pairing page and per-daemon service worker proxy - #15
Draft
agentiknet wants to merge 3 commits into
Draft
agentiknet wants to merge 3 commits into
agentiknet wants to merge 3 commits into
Conversation
/pair reads the offer from the URL fragment (what `agentproto pair offer --qr` links to), clears it from history, runs the E2E handshake through the rendezvous with @agentproto/pair-client, and asks the user to confirm the daemon's name and fingerprint before storing the credential in IndexedDB. A service worker registered per pairing at /d/<fingerprint>/ holds the one TunnelClient and answers every request under that scope from the daemon, so the Control Center loads unchanged from the daemon at /d/<id>/apps/@agentik/session-chat/ui/ with its REST, /mcp and SSE calls tunnelled too. /d/<id> is the state page (connecting, daemon offline and retrying, revoked, not paired); the worker sends an open Control Center there when the tunnel is revoked or stays offline. Adds an add-to-home-screen manifest. The worker is bundled by scripts/build-sw.mjs (esbuild) into public/pair-sw.js before dev/build.
A stored credential or a scanned offer from before pair/v2 can never connect again (pair-client's `outdated` state / `protocol_outdated`, refused before any dial). The worker treats it as terminal like a revocation and sends an open Control Center to /d/<id>, which now shows a "not paired · outdated pairing" page telling the user to update agentproto and pair again from a new QR. /pair shows a matching message for a v1 offer. Screenshots re-taken against pair/v2 through a rendezvous at its default 1 MiB message cap.
On a shared origin every stored pairing sits in the same IndexedDB and behind the same service-worker origin, so any daemon's Control Center could use every other daemon's pairing. The pairing pages now also run on a dedicated per-daemon origin, https://<daemon fingerprint>.agentproto.cloud (pair domain set at build time by NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN): - /pair refuses an offer whose daemon fingerprint isn't the host label, before any handshake (the offer stays unspent), and links to the offer on its daemon's own origin. Nothing is stored. - The credential store, in the pages and in the worker, is scoped to the origin's daemon: other ids read as absent and are never written. - /d/<id> for another daemon points to that daemon's origin; the bare pair domain or a non-fingerprint label refuses to pair. Any other host (cli.agentproto.sh, localhost) keeps working as a shared origin and says so in a short notice.
agentiknet
added a commit
to agentproto/ts
that referenced
this pull request
Sep 26, 2026
… Worker) (#1457) * feat(pair-page): per-daemon pair page on agentproto.cloud (Cloudflare Worker) A private package with the phone pair page as one static bundle, served identically on every <daemon-fingerprint>.agentproto.cloud by a Cloudflare Worker (AIP-59 §5.8). Isolation comes from the browser origin; there is no per-daemon server logic. - /pair pairs from the offer in the fragment with @agentproto/pair-client, refuses an offer whose fingerprint isn't the origin's first label before any network I/O (the offer stays unspent), and asks to confirm the daemon. - /d/<fp> is the status page (connecting, offline, revoked, outdated, not paired, wrong address). The service worker (dist/pair-sw.js) proxies /d/<fp>/ to the daemon over one tunnel client, so the Control Center loads from the daemon. - The IndexedDB store, in the page and the worker, holds only the origin's daemon. - Plain DOM, bundled with esbuild into dist/: no framework, no inline script or style, no third-party code. The build checks index.html for that. - src/worker.ts (logic in src/edge.ts): 404 for the apex and any host whose first label isn't a fingerprint, extra hosts only via PREVIEW_HOSTS (a labelled preview mode), a strict CSP and security headers on every response, no-cache for the worker script and immutable hashed assets. wrangler.toml: workers_dev, [assets] with run_worker_first, no routes. - scripts/preview.mjs serves dist/ through the same edge handler locally. Ported from agentproto/cli-site#15. * feat(secrets,cli,runtime): default pair page is one origin per daemon `pair offer --qr` now links to https://{fp}.agentproto.cloud/pair by default (DEFAULT_PAIR_PAGE = PAIR_WEB_URL_TEMPLATE_CLOUD), the page from packages/pair-page. It stays configurable with pairing.pairPage and --pair-page, as AIP-59 requires. encodeOfferWebUrl and the pairing.pairPage config default follow. PAIR_WEB_URL (https://cli.agentproto.sh/pair) stays exported as the explicit shared-origin option. * feat(secrets)!: 128-bit identity fingerprint identityFingerprint is now the first 32 lowercase hex chars (128 bits) of sha256(x25519 pub), was 16 (64 bits). The fingerprint names the daemon's browser origin (<fingerprint>.agentproto.cloud, AIP-59 §5.8): at 64 bits a well-resourced attacker could grind a daemon key whose fingerprint collides with a victim's and get their daemon's UI onto the victim's origin. 32 hex is still one DNS label. One fingerprint concept: the handshake's peerFingerprint (the daemon's key seen by the client, the client's key seen by the daemon, the pairing handle) uses the same function and widens with it. - The offer codec requires `id` to be exactly 32 lowercase hex. - The pair page and its Worker match ^[0-9a-f]{32}$. - sealKeyId keeps 16 hex (it is persisted in keyring files); it is the fingerprint's prefix. - Golden vectors: the fingerprint fields and the v2 offer URL id are re-derived; a KAT checks that the captured 64-bit values are their 16-char prefix, so only the length changed. The captured v1 offer keeps its id. - pair ls widens its column; docs, examples and READMEs use 32-hex values. BREAKING CHANGE: fingerprints, offer URLs and stored pairings from before this change don't validate. pair/v2 is unreleased, so there is no migration. * feat(pair-page): show the 128-bit fingerprint in groups of 4 32 hex chars don't fit one line on a phone; groups of 4 wrap between groups and are easier to compare with the terminal. The gaps are CSS margins, so a copy still yields the raw hex. Screenshots re-taken with 32-hex fingerprints. * chore(pair-page): route *.agentproto.cloud/* to the Worker Deployed after the workers.dev preview was verified; the zone carries the proxied wildcard record (AAAA 100::) the route needs. * docs(pair-page): production proof screenshots (agentproto.cloud, hosted rdv) Captured on 2026-09-26 against the deployed Worker (cae88bea) and wss://rdv.agentproto.sh/v1 with two scratch daemons: confirm and session list on daemon A's origin, B's offer refused on A's origin, B paired on its own origin, A's paired list, A revoked, B unaffected. * fix(pair-page): don't rebuild the status page on an unchanged worker state The status page redrew its whole view on every worker reply (every 2.5 s), replacing its buttons each time, so a tap could land on a node that was just swapped out (the production proof's Forget click failed that way). Draw only when the shown state, error, name or fingerprint changes. * chore: agentic reviewer — changeset --------- Co-authored-by: agentproto-bot <bot@agentproto.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of the phone ↔ daemon over rendezvous plan (RDV-BROWSER-PLAN PR 3).
What it does
/pairreads the offer from the fragment (https://cli.agentproto.sh/pair#v=2&…, whatagentproto pair offer --qrprints) and wipes it from the URL withhistory.replaceStatebefore anything else runs. It then callspairFromOfferand shows the daemon's name and fingerprint. Confirm stores the credential withcreateIndexedDbCredentialStore(IndexedDB only, nothing in localStorage). Cancel drops it and tells the user how to remove the daemon's record. Errors get their own page: expired or spent offer, unreachable daemon, and a v1 offer, which is refused as outdated with no network dial. With no offer,/pairlists this phone's paired daemons. The manifest'sstart_urlis/pair?launch=1, which goes straight to the daemon when only one is paired.Service worker, one registration per pairing, scoped to
/d/<fingerprint>/(src/sw/pair-sw.ts, bundled byscripts/build-sw.mjsintopublic/pair-sw.js, which is gitignored). It keeps oneTunnelClientat module scope, shared by every fetch event and rebuilt lazily if the browser killed the worker. It answers every fetch under its scope withclient.fetch(event.request)andmapPathstripping/d/<id>. The pages never connect themselves; they ask the worker overpostMessage, which keeps the daemon's 2 standing slots per pairing free. The script is served from/, so its default max scope covers/d/<id>/without aService-Worker-Allowedheader.The Control Center loads from the daemon, unchanged, at
/d/<id>/apps/@agentik/session-chat/ui/. No session-chat code lives here./d/<id>(outside the scope) is the state page:onlineoutdated/protocol_outdated); update agentproto and re-pairThe worker sends an open Control Center here on revoke or outdated (both terminal), or after 8 s offline. A page load that can't reach the daemon is redirected here too. Once the tunnel is up again, the page returns to where the user was.
Add-to-home-screen manifest and icons.
One origin per daemon (
<fingerprint>.agentproto.cloud)On one shared origin, every stored pairing sits in the same IndexedDB and behind the same service-worker origin, so any daemon's Control Center could use every other daemon's pairing. The app is now host-agnostic (
src/lib/pair-host.ts):https://<daemon-fingerprint>.<pair domain>(pair domain fromNEXT_PUBLIC_AGENTPROTO_PAIR_DOMAINat build time, defaultagentproto.cloud, inlined into the pages by Next and into the worker bybuild-sw.mjs). The origin belongs to exactly one daemon./pairrefuses an offer whose fingerprint isn't the host label. It checks withinspectOffer, before any handshake, so the offer stays unspent. The refusal page links to the same offer on that daemon's own origin, and nothing is stored. A second check after the handshake cancels on a mismatch.putrefuses them./d/<other-id>on a per-daemon origin points to that daemon's origin. The bare pair domain, or a label that isn't a fingerprint, refuses to pair./d/<id>/worker layout is unchanged (id= the same fingerprint)./pairthat pairings on this address share it (to link AIP-59 §5.8 once it exists).expectedPairHost/{fp}pair-page templates) wasn't on #1450 yet (head3228a8a7), so the host check is local: a few lines inpair-host.ts. It can switch to the helper once it lands. The CLI side, wherepair offer --qrprintshttps://<fp>.agentproto.cloud/pair#…, is #1450's{fp}template work.Deployment notes (not done here; no DNS or deploy config touched)
*.agentproto.cloud: a wildcard domain on the service (Coolify / reverse proxy), or a Cloudflare Worker route that forwards*.agentproto.cloud/*to it.*DNS record onagentproto.cloud, SSL/TLS Full (strict), and Universal SSL covering*.agentproto.cloud. The origin certificate must also cover the wildcard if the origin terminates TLS.agentproto.cloudneedn't serve the app; if it does, it refuses to pair.NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAINat build time (the Dockerfile doesn't forward it yet; add anARG/ENVif needed).session-chat base path (studio: agentik-studio#313)
session-chat resolved its API base as the injected
window.__AGENTPROTO_BASEURL__, elselocation.origin. Behind the tunnel, the daemon builds that injected value from the Host it sees,http://127.0.0.1:<port>, so every REST,/mcpand SSE call escaped the SW scope. #313 derives the base from the served document instead: origin plus whatever prefix comes before/apps/. The daemon-served page then calls…/d/<id>/mcp,…/d/<id>/sessions/…. Screenshot 3 showsdaemon: http://localhost:3010/d/ae5be03faa146dd7. react-agentproto builds every URL from that base. Phones need a daemon that ships #313's session-chat build.End-to-end run (local, nothing live touched)
Setup: a local
rendezvous serveat its default--max-message-bytes(1 MiB), a scratch daemon from the #1450 build (ownHOME, port 18897) serving #313's session-chatindex.html(byte-identical), and headless Chrome at 390×844 mobile./pairshowed "from an older agentproto", and the broker logged no dial.pair offer --qrprinted/pair#v=2&…&s=…. The page ran the handshake and showed name + fingerprint, and the fragment was gone. Confirm replaced the old credential and reset the worker.session_list) and the send path (agent_start) went through/d/<id>/mcp.agentproto pair revokemoved the open Control Center to revoked on its own. "Forget" removed the credential and unregistered the worker, leaving not paired.Not verified: a streamed agent reply. The scratch daemon has no LLM credentials (
agent_start→missing_auth_credential), and I didn't copy real ones into a scratch home.Per-daemon origins (local,
NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN=localhost)*.localhostresolves to loopback and is a secure context in Chrome.*.localtest.meover http isn't, so service workers and WebCrypto are off there.ae5be03faa146dd7offer opened on0123456789abcdef.localhost:3010/pairwas refused ("for a different daemon"). That origin ended with no IndexedDB database and no worker.ae5be03faa146dd7.localhost:3010. It paired, showed no shared notice, and loaded the Control Center from the daemon./d/id:/d/0123456789abcdefon that origin showed "this address serves another daemon" with a link to the right origin.127.0.0.1:3010paired and loaded the Control Center as before, with the shared-origin notice.localhost:3010/pair(standing in foragentproto.cloud) refused to pair.SSE through the service worker
/sessions/:id/events/streamdelivered its: keep-alivecomments at 0, 25, 50 … 375 s, each as its own read./eventsbus used to die at exactly 120 s: the daemon tunnel'shttpStreamIdleTimeoutMswith no keep-alive to reset it. With #1450's keep-alive fix it now ticks every 25 s and stayed open past 159 s./mcpGET SSE: session-chat doesn't open one. react-agentproto sends each MCP call as its own shortPOST /mcp(client.ts), and the network log shows onlyPOST …/mcp. So the 120 s idle cut can't hit it.Gates
pnpm typecheck→ exit 0 (runstscfor the app, then forsrc/swwith the webworker lib).pnpm build→ exit 0.pnpm lint→ exit 1, and it fails onmaintoo: Next 16 removednext lint(chore(cli-site): migrate lint to ESLint 9 flat config #11 migrates it). CI doesn't run lint.No lockfile committed (as before).
esbuildis a new devDependency.Screenshots (390×844 mobile, pair/v2, default-cap broker)
/d/<id>/🤖 @agentproto-bot — PR · session
sess_515e1367(rdv-browser PR3: cli-site /pair + service worker) · claude-code / subscription · auth-profileClaude Subs Agentik· modelclaude-opus-5-5· supervisorsess_d3e835f4· $43.0072 (daemon) · hostmac.home· cwdagentik-studio/rdv-pair-page