Repository navigation
Description
Problem
scripts/j5/pr-env.sh <pr> --peer (#255) starts two servers from one build and peers them, but the browser still has to be told about the second server by hand: pair with Local's startup URL, then Settings → Connections → Add environment with Remote's startup URL. For a routine two-server test that is two extra manual steps every run, and the second one depends on a one-time token that only a server restart can replace with administrative scope.
Why it is not automatic
- The browser owns its list of saved environments. It lives in the browser's IndexedDB (
apps/web/src/connection/storage.ts); the server keeps no copy, so neither the peer CLI nor the script can add an environment to a browser profile. - The only ways to mint a new pairing token without a restart carry standard client scopes:
j5 auth pairing createandj5 pairhave no--scopeflag in the fork (upstream fix(auth): preserve explicitly granted pairing scopes pingdotgg/t3code#9785 adds one; fix(clients): remote pairing keeps the scopes the link grants #197 deliberately took only its client half). The Settings → Connections link picker can mintaccess:write, but it renders only when the server's auth policy is remote-reachable, so it is hidden on a loopback bind. A browser paired with a standard-scope token cannot peer, because the peer-credential route needsaccess:write.
What already exists to build on
The web app accepts /pair?host=<origin>&label=<label>#token=<pairing token> on any served instance, not only the hosted app. The root route treats a /pair request with both host and a token as an add-environment request and runs the same flow as the Add Environment dialog, saving the environment into that browser and connecting. See apps/web/src/routes/__root.tsx (hasHostedPairingRequest) and apps/web/src/hostedPairing.ts.
Proposal
- Script prints a ready add-Remote link. After peering,
pr-env.sh --peercomposeshttp://127.0.0.1:<local port>/pair?host=http://127.0.0.1:<remote port>&label=Remote#token=<Remote startup token>beside Local's pairing URL. Pair the browser with Local, click the link, done. Two lines in the summary; the tokens are already extracted there. --scopeonj5 auth pairing create. Take the CLI half of upstream fix(auth): preserve explicitly granted pairing scopes pingdotgg/t3code#9785 (repeatable--scope, deduplicated, defaults unchanged) so a fresh administrative pairing token can be minted from the server host without a restart. The script then mints Remote's token itself instead of scraping the startup one, which also makes the link work for a second browser.
Caveats to keep: the token in the link is one-time, so the link is per browser; the browser must be paired with Local before opening it. The composed link has been read from the code, not yet clicked.
Out of scope
Anything that syncs a browser's environment list from a server, or a server-side registry of client environments. The browser stays the owner of what it is connected to.
Built by Claude Fable 5.1 in Claude Code.
Activity
bryantderosier commentedon Dec 1, 2026
Both halves of this are done. They just landed in the live-test script, not in
pr-env.sh.a5e2e7d4d2) added--peertoscripts/j5/setup-agent-live-test.ts. Its output now prints the exact link proposed here under Remote, as "Add to the browser, after pairing with Local (works once)".addRemoteUrl()buildshttp://localhost:<local web>/pair?host=http://localhost:<remote port>&label=Remote#token=…, and a test covers it insetup-agent-live-test.test.ts. The token is minted fresh from the running Remote withpaireach time, not scraped from startup, so the second-browser caveat is covered too.--scopewithout a restart:j5 auth pairing createandpairboth take--scopenow (apps/server/src/cli/auth.ts:114, FORK.md case 79). The live-test script uses it to mint admin-scoped tokens for both servers.pr-env.sh --peeritself never got the link, but that doesn't matter anymore. Thej5-live-testskill sends all live testing throughsetup-agent-live-test.ts(--peer,--peer --poll,--peer --reachable), and nothing points people atpr-env.shanymore. Closing.