Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
ADR 0284: Headless runtime boundary in packages/host-runtime
- Status: Accepted for implementation
- Date: 2026-09-18
- Decision: D447
- Related: ADR 0205 (D373 / D374 / D375), ADR 0213 (D386),
02-architecture/05-remote-agent-control.md§4 and §11,03-runtime/07-process-model.md§4,06-delivery/07-remote-control-rollout.mdR2
Context
Rollout R1 delivered the headless Agent Host module (packages/agent-host), but
everything underneath it lived in apps/desktop/electron/main and was reached
through the desktop's own IPC handlers: the stdio transports to host-core and the
sidecar, the restart supervisor, the durable turn lifecycle, transcript persistence,
the in-flight reply checkpoint, and approved Plan/Goal execution (D189).
R2 needs the same runtime where no Electron exists: the pi-host bundle
(02-architecture/05-remote-agent-control.md §5.2) must run the Agent Host module,
the sidecar, and host-core behind a RACP server. Re-implementing the turn lifecycle
would create a second source of truth for the invariants the desktop spent a year
fixing — abort locks, stale terminal events, single-flight finalization, queue
release after durable settlement.
Decision
- A new workspace package,
packages/host-runtime, owns the Electron-independent runtime layer, depending onshared,agent-host, andagent-runtimeonly, never onelectronorapps/desktop:HostProcessandAgentSidecar— the stdio NDJSON JSON-RPC transports, unchanged in behavior but taking their launch as options, with the sidecar'shost.proxyallowlist, local-tool short circuit, Plan-mode gate, vendor-auth check, and trusted-extension bridge intact.RuntimeSupervisor— the process-model §4 restart policy, single flight per child, never during shutdown, stopping on the first unrecoverable failure.RuntimeService—RuntimePortfor the module: prompt admission with the durable turn row and user message appended before the sidecar starts, steer, stop, the abort lock, asktool answers, manual compaction, andfinishTurnwith the desktop's claim-before-await rule, stale-terminal guard, and settlement announcement.TurnEventPipelineandTurnPersistence— the per-event pass (tool-call tracking, D299 checkpoints, terminal events, completed rows) and an ordered append queue with bounded retry while host-core restarts; api-hostprocess ends only with its supervisor, so no file-backed outbox is duplicated.createHeadlessLaunchResolver,PlanExecutionDispatcher(D189), and host-core adapters forSessionPort,QueueStore(schema v15),permissions.pending, the session-message ledger, the inflight checkpointer, and the plan-execution decoders. The resolver refuses vendor OAuth accounts and plugin agents.
- Electron main keeps thin adapters:
host-process.tsandagent-sidecar.tssubclass the package classes to add packaged locations,ELECTRON_RUN_AS_NODE, redacted stderr, and schema-too-new / glibc diagnoses, whileruntime/lifecycle.tsdrives the shared supervisor and renderer status pushes. The local prompt path (agent-ipc.ts) stays desktop-owned. TurnStartRequestgains an optionaluserMessageIdso a client keeps its optimistic user row id through the headless runtime (D288). Additive.- No wire contract changes: Electron IPC, sidecar JSON-RPC, host-core RPC, and the Plugin SDK are untouched, and desktop behavior, defaults, and persisted data are unchanged.
Consequences
pi-hostcomposesHostProcess + AgentSidecar + RuntimeService + AgentHost + RuntimeSupervisorin plain Node, and the restart policy, turn lifecycle, and transports become testable without Electron; the RACP server binds to the module rather than to Electron IPC.- Local desktop sessions still run their own prompt path, and the headless resolver deliberately supports less — no attachments, plugin tools, MCP relay, or vendor OAuth — returning typed errors instead of degrading silently.
Alternatives
- Extract only the transports and re-implement the lifecycle in
pi-host: the invariants are the hard part and a copy would drift. - Keep the modules in
apps/desktop/electron/main:packages/*must not depend on desktop implementation code. - Put the runtime into
packages/agent-host: that module must stay free of process and filesystem knowledge.