Skip to content

pr-env --peer: add Remote to the browser with a ready link, and mint scoped pairing tokens without a restart #257

Done

Description

@Jacksondr5

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 create and j5 pair have no --scope flag 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 mint access: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 needs access: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

  1. Script prints a ready add-Remote link. After peering, pr-env.sh --peer composes http://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.
  2. --scope on j5 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

  1. bryantderosier commented on Dec 1, 2026

    @bryantderosier
    Collaborator

    Both halves of this are done. They just landed in the live-test script, not in pr-env.sh.

    • Ready add-Remote link: feat(scripts): --peer runs two peered live-test servers #555 (a5e2e7d4d2) added --peer to scripts/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() builds http://localhost:<local web>/pair?host=http://localhost:<remote port>&label=Remote#token=…, and a test covers it in setup-agent-live-test.test.ts. The token is minted fresh from the running Remote with pair each time, not scraped from startup, so the second-browser caveat is covered too.
    • --scope without a restart: j5 auth pairing create and pair both take --scope now (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 --peer itself never got the link, but that doesn't matter anymore. The j5-live-test skill sends all live testing through setup-agent-live-test.ts (--peer, --peer --poll, --peer --reachable), and nothing points people at pr-env.sh anymore. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions