Skip to content

feat(runtime,cli): remote_enable returns a phoneUrl; agentproto remote enable --qr - #1402

Merged
agentiknet merged 3 commits into
mainfrom
wt/phone-link-qr
Sep 26, 2026
Merged

agentiknet merged 3 commits into
mainfrom
wt/phone-link-qr

Conversation

@agentiknet

Copy link
Copy Markdown
Contributor

PHONE-PLAN.md P1.2. Builds on #1398 (merged) — pairs with agentproto/cli-site#14.

What changed

remote_enable (MCP tool, and the new POST /remote/enable REST route) now also returns phoneUrl — a single link to open on a phone:

  • @agentik/session-chat installed with a UI on this daemon → <tunnelUrl>/apps/@agentik/session-chat/ui#token=<t> (lands straight in Control Center).
  • otherwise → https://cli.agentproto.sh/panel#daemon=<tunnelUrl>&token=<t> (hosted-panel fallback).

The token rides in a URL fragment, never a ? query string — fragments never reach a server (no Referer, no access/proxy log, no CDN cache key), matching readFragmentConnection added in agentproto/cli-site#14. phoneUrl is omitted for passthrough tunnels (targetPort pointing at a different local service), same condition as bearerToken/mcpEndpoint — there's no daemon UI to link to in that mode. The bearer token itself is still shown exactly once, unchanged.

RemoteController gets a REST surface (GET /remote/status, POST /remote/enable, POST /remote/disable, http-server.ts's handleRemoteControl) — it was MCP-only before this. No new gate beyond what already applies to every route (#1398's central tunnel-bearer check for non-loopback traffic); same trust model as /tunnels, which also has none beyond that.

New CLI verb agentproto remote enable/disable/status (packages/cli/src/commands/remote.ts), built on those REST routes via the same discoverDaemon()/httpPostJson/httpGetJson helpers agentproto tunnel already uses. --qr renders phoneUrl as an in-terminal QR code.

QR library

qrcode-terminal was already a dependency (used by agentproto pair offer's printQr, pair.ts) — no new dependency. Extracted printQr into packages/cli/src/util/qr.ts so both commands share the exact same renderer instead of a second copy.

Tests

packages/runtime/src/__tests__/remote-controller-phone-url.test.ts — RemoteController.enable()'s phoneUrl in all three shapes (session-chat installed, not installed/omitted, and omitted entirely for a passthrough tunnel). Mocks the quick-tunnel provider so no real cloudflared process spawns.

Real check

Ran a live daemon and the built CLI end to end (real cloudflared quick tunnel, torn down immediately after):

$ agentproto remote enable --qr
tunnel up  https://ensure-opera-satisfactory-embassy.trycloudflare.com
  bearer   bE2C9kyQ2fgcodKsG9nY2mPRF24razhjAZSlm4RPM38  (shown once — only its hash is persisted)
  mcp      https://ensure-opera-satisfactory-embassy.trycloudflare.com/mcp
  phone    https://ensure-opera-satisfactory-embassy.trycloudflare.com/apps/@agentik/session-chat/ui#token=bE2C9kyQ2fgcodKsG9nY2mPRF24razhjAZSlm4RPM38
[QR rendered]

$ agentproto remote status --json
{ "enabled": true, "provider": "quick", ... }

$ agentproto remote disable
tunnel disabled

Gate

pnpm --filter @agentproto/runtime check-types/test/build and pnpm --filter @agentproto/cli check-types/test/build all exit 0 against a full monorepo rebuild. (Two unrelated tests — transmitter-bindings.test.ts and install-skill.test.ts/pack-skill.test.ts — flaked once under the heavy parallel load of that rebuild; both pass cleanly re-run in isolation.) No changeset, no new dependencies, no any/unknown escapes, no AI attribution.

@ponytail-coder ponytail-coder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds agentproto remote enable/disable/status (REST twin of the MCP remote tools), a shared QR util extracted from pair.ts, and a phoneUrl on RemoteController.enable() that puts the bearer in a URL fragment — never a query string — with good test coverage of both link shapes.

Changeset

package bump reason
@agentproto/runtime minor new optional EnableResult.phoneUrl export + RemoteControllerOptions.isSessionChatInstalled
@agentproto/cli minor new remote subcommand with enable/disable/status verbs

Findings

Security

  • http-server.ts:6164-6224 — /remote/* rides the global P0 tunnel-bearer gate (tunnelBearerAllowed at http-server.ts:1824), so non-loopback callers need the bearer; consistent with /tunnels. Token-in-fragment design is correct (fragments never reach server logs). ✅
  • Observation (pre-existing, not introduced here): EnableInput.targetHost (remote-controller.ts:214) is unvalidated, so remote enable can tunnel to any host the daemon can reach. Fine for the loopback-trusted CLI model, but worth hardening in a follow-up.

Correctness

  • remote.ts:175-183 — --qr with no phoneUrl prints a stderr warning but still exits 0; acceptable since the tunnel itself succeeded, though a distinct message ordering (QR before/after the summary) is a nit.
  • remote-controller.ts:272 — fragment token is concatenated unencoded; fine for base64url bearers, but encodeURIComponent(bearerToken) would be safer if the token alphabet ever changes.

Tests

  • remote-controller-phone-url.test.ts covers both phoneUrl shapes and the passthrough case — good. No test yet for the new /remote/* HTTP routes or the CLI subcommand; suggest adding an http-server-level route test in a follow-up.

Refactor

  • pair.ts/qr.ts — clean extraction, no behavior change; qrcode-terminal remains an optional dep of @agentproto/cli (cli/package.json:105). ✅

Verdict

LGTM ✅ — no sensitive paths touched, the auth model is respected, and the fragment-based phoneUrl design is sound; remaining items are minor nits and follow-up hardening.

@ponytail-coder ponytail-coder Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds a phoneUrl field to RemoteController.enable()'s EnableResult (a single fragment-carried link into Control Center, or the hosted panel fallback when @agentik/session-chat isn't installed), wires REST twins of the MCP remote_enable/remote_disable/remote_status tools (GET/POST /remote/*) into http-server.ts, and introduces agentproto remote enable|disable|status [--qr]. printQr is extracted from pair.ts into a shared util/qr.ts so both commands render the same best-effort in-terminal QR code.

Changeset

package bump reason
@agentproto/runtime minor new exported EnableResult.phoneUrl field, new RemoteControllerOptions.isSessionChatInstalled, new /remote/* REST routes
@agentproto/cli minor new agentproto remote verb (enable/disable/status, --qr)

Findings

Correctness

  • Auth model checked carefully: handleRemoteControl (like handleTunnels) intentionally has no per-route bearer gate, relying on the global tunnelBearerAllowed P0 gate applied once ahead of the whole route dispatch. This matches /tunnels's existing trust model and is explicitly documented in the new function's doc comment — no gap introduced here.
  • phoneUrl construction correctly mirrors the bearerToken/mcpEndpoint gating (exposesGateway && bearerToken), so a passthrough (targetPort) tunnel never gets a phone link pointing at an ungated surface — good, and covered by a dedicated test.
  • Token placement in a URL fragment (never query string) is correct and well-reasoned for avoiding proxy/log/CDN leakage.

Tests

  • remote-controller-phone-url.test.ts covers all four branches (installed / not installed / option omitted / passthrough) with a mocked provider — solid, deterministic, no real cloudflared spawn. No CLI-level test for runRemote, but it's a thin dispatch/formatting layer over already-tested primitives (discoverDaemon, httpPostJson), consistent with sibling commands (tunnel.ts, pair.ts) that also ship without dedicated CLI tests.

Nits

  • runEnable's non-JSON success output doesn't print mcpConfigSnippet (unlike the MCP tool's response, which includes it) — likely intentional to keep terminal output short, but worth a one-line mention in --help if that's deliberate.
  • --qr's "nothing to render" message could suggest --target-port was omitted rather than assuming it's why phoneUrl is missing (e.g. it's also absent if enable fails), but this is a minor UX nit since the flow already returns early on failure before reaching the --qr branch.

Simplify (ponytail pass)

Nothing over-engineered here — the printQr extraction actually removes duplication (a real net win), and remote.ts doesn't introduce speculative abstraction beyond what tunnel.ts/pair.ts already establish. No cuts to suggest.

Verdict

LGTM ✅ — correct, typed, tested, and the new REST surface follows the existing (and here explicitly documented) trust model rather than introducing a new gap.


🤖 @agentproto-bot — review · session sess_61098f42 (agent-step:opencode) · opencode / api-key · model openrouter/z-ai/glm-5.3-flash · $0.0042 · run 36203162718 · sha 9ca05166c3ccdeae73ff348d9d371ad3850b1d3c

…e enable --qr

PHONE-PLAN.md P1.2. remote_enable (MCP tool and the new POST /remote/enable
REST route) now also returns phoneUrl: the installed session-chat app's UI
when present (<tunnel>/apps/@agentik/session-chat/ui#token=<t>), else the
hosted panel fallback (https://cli.agentproto.sh/panel#daemon=<tunnel>&token=<t>).
The token rides in a URL fragment, never a query string, so it never reaches
a server log — matching agentproto/cli-site#14's readFragmentConnection.
Omitted for passthrough tunnels, same condition as bearerToken/mcpEndpoint.

Adds GET/POST /remote/status/enable/disable REST routes (RemoteController
was previously MCP-only) and a new `agentproto remote enable/disable/status`
CLI verb built on them, mirroring `agentproto tunnel`'s discoverDaemon()
pattern. `--qr` renders phoneUrl as a terminal QR code via the existing
qrcode-terminal dependency, extracted from pair.ts's printQr into a shared
util so both commands use the same renderer.
The docs.mjs --check gate failed CI: a new verb (remote) with no
docs/cli/verbs/ page is a hard error. Covers enable [--qr]/disable/status,
the two phoneUrl shapes (session-chat link vs. the cli.agentproto.sh/panel
fallback) and why the token rides in a URL fragment, and the post-#1398
security model (every non-loopback route needs the bearer once enabled).

@ponytail-coder ponytail-coder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The increment since my prior review (9ca0516, rebased — same feature content now landed as e3f871ef) is a single docs-only commit: ff6f91fe adds docs/cli/verbs/remote.md plus its README.md index entry, driven by the docs.mjs --check gate failing on the new remote verb.

Changeset

package bump reason
@agentproto/runtime minor (unchanged from prior review) new EnableResult.phoneUrl, isSessionChatInstalled option, /remote/* routes
@agentproto/cli minor (unchanged from prior review) agentproto remote verb

Findings

Docs accuracy

  • docs/cli/verbs/remote.md was cross-checked against the code: the enable output shape (bearer "shown once" wording, phone line only when phoneUrl exists, remote.ts:136-140), the --qr nothing-to-render message, disable's idempotent {"disabled":false}, and the phoneUrl fragment-vs-query rationale all match the implementation, including the two phoneUrl shapes. The security-model section correctly describes the post-#1398 bearer gating and its three loopback-origin exceptions. README index entry points at the right page.

Prior findings

  • Both prior nits (missing mcpConfigSnippet in non-JSON enable output; --qr message attribution) are acknowledged in the docs page's flag table and remain open but non-blocking.

Verdict

LGTM ✅ — the increment is accurate documentation that fixes the CI gate; no code changes since the previously approved feature commit.

@ponytail-coder ponytail-coder Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds phoneUrl to RemoteController.enable() / remote_enable (fragment-carried bearer token, two shapes depending on whether @agentik/session-chat is installed), new GET/POST /remote/{status,enable,disable} REST routes mirroring the existing MCP tools, and a new agentproto remote enable|disable|status CLI verb (with --qr rendering via a printQr util extracted from pair.ts).

Changeset

package bump reason
@agentproto/runtime minor new phoneUrl field on EnableResult, new REST routes on handleRemoteControl, all backward-compatible additions
@agentproto/cli minor new agentproto remote verb (new public CLI surface)

Findings

Correctness

  • phoneUrl/bearerToken/mcpEndpoint are correctly gated on exposesGateway, matching the passthrough-tunnel warning path — remote-controller-phone-url.test.ts covers both installed/not-installed/omitted/passthrough cases.
  • The token rides in a URL fragment (#token=) for both phoneUrl shapes, consistent with the stated goal of never leaking it via query string/Referer/logs.
  • New REST routes reuse the same RemoteController singleton as the MCP tools, so REST and MCP can't disagree on state — good.
  • --target-port validation in the CLI (1-65535, Number.isFinite) matches the zod schema on the MCP tool side.
  • handleRemoteControl intentionally has no gate beyond the existing loopback/bearer trust model, explicitly documented as matching /tunnels' precedent — consistent with house convention, not a new hole introduced by this PR.

Type Safety

  • No any in new exported signatures; EnableResult/RemoteStatus/EnableInput already flow through @agentproto/runtime's public export surface, so the CLI's import type usage is valid.
  • pickProvider's exhaustive never guard predates this PR but still holds.

Tests

  • Good regression coverage for the new phoneUrl construction logic (4 cases: installed, not-installed, omitted callback, passthrough-omits-url).
  • No dedicated test for the new REST routes (handleRemoteControl) or the new CLI remote.ts command, but this matches the existing convention in this codebase — tunnel.ts/its REST routes aren't unit-tested either, since they're thin transport wrappers over already-tested controller logic.

Nits

  • The top-level agentproto --help banner line for remote enable omits --provider/--target-host (only shown in remote.ts's own --help) — consistent with how tunnel's banner line is already abbreviated, so not a real inconsistency, just noting it's easy to miss when adding a new flag later.

Simplify

Nothing over-engineered here — printQr extraction is a legitimate dedup (was already duplicated once, now shared by two call sites), and the REST handler mirrors the existing /tunnels//workflows dispatch pattern rather than introducing a new abstraction.
net: -0 lines possible.

Verdict

LGTM ✅ — additive, well-tested phoneUrl logic, and the new REST/CLI surface consistently follows existing patterns (auth model, daemon discovery, transport mirroring).


🤖 @agentproto-bot — review · session sess_55feb11f (agent-step:opencode) · opencode / api-key · model openrouter/z-ai/glm-5.3-flash · $0.0031 · run 36206465984 · sha ac39f9dbe17344da01a93ce76d80cd2633f24399

@agentiknet
agentiknet enabled auto-merge (squash) September 26, 2026 01:04
@agentiknet
agentiknet merged commit dc2a7c7 into main Sep 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant