Repository navigation
feat(runtime,cli): remote_enable returns a phoneUrl; agentproto remote enable --qr - #1402
Conversation
There was a problem hiding this comment.
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, soremote enablecan 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 —
--qrwith nophoneUrlprints 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-terminalremains 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.
There was a problem hiding this comment.
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(likehandleTunnels) intentionally has no per-route bearer gate, relying on the globaltunnelBearerAllowedP0 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. phoneUrlconstruction correctly mirrors thebearerToken/mcpEndpointgating (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.tscovers all four branches (installed / not installed / option omitted / passthrough) with a mocked provider — solid, deterministic, no realcloudflaredspawn. No CLI-level test forrunRemote, 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 printmcpConfigSnippet(unlike the MCP tool's response, which includes it) — likely intentional to keep terminal output short, but worth a one-line mention in--helpif that's deliberate.--qr's "nothing to render" message could suggest--target-portwas omitted rather than assuming it's whyphoneUrlis missing (e.g. it's also absent ifenablefails), but this is a minor UX nit since the flow already returns early on failure before reaching the--qrbranch.
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).
9ca0516 to
ff6f91f
Compare
There was a problem hiding this comment.
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.mdwas cross-checked against the code: the enable output shape (bearer "shown once" wording,phoneline only whenphoneUrlexists, remote.ts:136-140), the--qrnothing-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
mcpConfigSnippetin non-JSON enable output;--qrmessage 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.
There was a problem hiding this comment.
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/mcpEndpointare correctly gated onexposesGateway, matching the passthrough-tunnel warning path —remote-controller-phone-url.test.tscovers both installed/not-installed/omitted/passthrough cases.- The token rides in a URL fragment (
#token=) for bothphoneUrlshapes, consistent with the stated goal of never leaking it via query string/Referer/logs. - New REST routes reuse the same
RemoteControllersingleton as the MCP tools, so REST and MCP can't disagree on state — good. --target-portvalidation in the CLI (1-65535,Number.isFinite) matches the zod schema on the MCP tool side.handleRemoteControlintentionally 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
anyin new exported signatures;EnableResult/RemoteStatus/EnableInputalready flow through@agentproto/runtime's public export surface, so the CLI'simport typeusage is valid. pickProvider's exhaustiveneverguard predates this PR but still holds.
Tests
- Good regression coverage for the new
phoneUrlconstruction logic (4 cases: installed, not-installed, omitted callback, passthrough-omits-url). - No dedicated test for the new REST routes (
handleRemoteControl) or the new CLIremote.tscommand, 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 --helpbanner line forremote enableomits--provider/--target-host(only shown inremote.ts's own--help) — consistent with howtunnel'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
PHONE-PLAN.md P1.2. Builds on #1398 (merged) — pairs with agentproto/cli-site#14.
What changed
remote_enable(MCP tool, and the newPOST /remote/enableREST route) now also returnsphoneUrl— a single link to open on a phone:@agentik/session-chatinstalled with a UI on this daemon →<tunnelUrl>/apps/@agentik/session-chat/ui#token=<t>(lands straight in Control Center).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), matchingreadFragmentConnectionadded in agentproto/cli-site#14.phoneUrlis omitted for passthrough tunnels (targetPortpointing at a different local service), same condition asbearerToken/mcpEndpoint— there's no daemon UI to link to in that mode. The bearer token itself is still shown exactly once, unchanged.RemoteControllergets a REST surface (GET /remote/status,POST /remote/enable,POST /remote/disable, http-server.ts'shandleRemoteControl) — 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 samediscoverDaemon()/httpPostJson/httpGetJsonhelpersagentproto tunnelalready uses.--qrrendersphoneUrlas an in-terminal QR code.QR library
qrcode-terminalwas already a dependency (used byagentproto pair offer'sprintQr,pair.ts) — no new dependency. ExtractedprintQrintopackages/cli/src/util/qr.tsso 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()'sphoneUrlin all three shapes (session-chat installed, not installed/omitted, and omitted entirely for a passthrough tunnel). Mocks the quick-tunnel provider so no realcloudflaredprocess spawns.Real check
Ran a live daemon and the built CLI end to end (real
cloudflaredquick tunnel, torn down immediately after):Gate
pnpm --filter @agentproto/runtime check-types/test/buildandpnpm --filter @agentproto/cli check-types/test/buildall exit 0 against a full monorepo rebuild. (Two unrelated tests —transmitter-bindings.test.tsandinstall-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, noany/unknownescapes, no AI attribution.