Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
ADR 0286: Remote-host desktop kernel
- Status: Accepted for implementation
- Date: 2026-09-18
- Decision: D449
- Related: ADR 0205 (D373 / D374 / D375), ADR 0285 (D448),
03-runtime/19-remote-agent-control-protocol.md§3.4
Context
ADR 0285 delivered the RACP-WS transport and pairing on both ends, but the
desktop still lacked the kernel that lets the renderer treat a remote session
exactly like a local one (spec §3.4). The renderer must not learn the transport,
index.ts is pinned at 1500 LOC by the architecture gate, and the desktop cannot
open a network listener, so every outbound flow goes through the RACP client to a
paired host.
Decision
- A single interception seam:
backend-router.ts. The router is consulted fromipc/register.ts'shandle()wrapper and returnsROUTE_LOCALwhen noRemoteBackendis registered for the call's session id, so a session turns remote only once itsremote:<hostKey>:<hostSessionId>id is registered. - A stateless per-request session id.
sessionIdForCallrecovers the session from the first positional argument,first.sessionId,first.id, or the<remoteSessionId>#racp-approval:<hostApprovalId>requestId used by tool approval, so approval routing needs no correlation map. - A transport-agnostic backend:
remote-backend.ts. One instance per paired host serves all of its sessions, translating 17 channels into RACP requests and reshaping results into the shapesapi.tsalready returns; channels the remote profile does not cover report false fromhandles()or throwCAPABILITY_UNAVAILABLEand fall back to the local handler. - Two synthesis rules to reconcile schema mismatches without a round-trip.
Tool approval encodes the session into its requestId, and
plansResolvesynthesizes a minimalPlanProposalthat the follow-upsession.changedevent replaces with the authoritative snapshot. - A pure event bridge:
remote-event-bridge.ts. RACP events becomeIPC.event.agentMessage/IPC.event.sessionsChanged, forwarding theAgentEventinpayload.event, turningtoolkindapproval.requestedintotool_permission_request, dropping plan and goal approvals in favour ofplanning_state, and signallingsession.created/archived. - A coordinator per paired host:
remote-host-connection.ts. Itsopen()sequence of attach listener, subscribe host scope,session/list, per-session subscribes closes the create race, andclose()is idempotent and safe beforeopen(). - A
RemoteHostClientseam with multi-listenersubscribe.racp-remote-host-client.tsis the only remote module importing@pi-desktop/racp; it fans the client's single callback out to every listener and swallows listener throws. - Encrypted-at-rest registry:
remote-host-registry.ts. Paired hosts live in<dataDir>/remote-hosts.jsonwith device tokens encrypted throughsafeStoragebehind anEncryptionPort,upsertrefuses to write when the keychain is unavailable, andlistdrops records it cannot decrypt. - Boot hook:
bootstrap/remote-hosts.ts. It opens one adapter and one connection per registered host, logging and skipping a failing host, with an empty registry as a full no-op;startup.tsopens in the background andshutdown.tscloses paired sockets before host-core is disposed.
Consequences
- Adding an encrypted host entry to
<dataDir>/remote-hosts.jsonis enough for the desktop to connect and stream events into the existing renderer. - With no pairing the kernel is a zero-behavior change:
route()returnsROUTE_LOCALfor every call and existing handlers run unchanged. apps/desktopgains an additive@pi-desktop/racpdependency,index.tsstays at 1500 LOC, and later stages plug into the router, bridge, and registry seams.
Alternatives considered
- Route from each per-domain IPC handler: every handler would duplicate the same dispatch and every new channel would need wiring twice.
- Bake remote knowledge into the renderer: a
remote:prefix inapi.tsforces every store slice to know the transport, which spec §3.4 forbids. - A plain-text registry: a compromised backup would hand out device tokens that
authenticate against a real
pi-host.