Expand description
Mist WebSocket transport.
Local-first JSON-RPC over WebSocket for the Sky↔Cocoon direct path (B7-S6). The aim is to remove the Tauri-invoke + Mountain-gRPC double hop on extension-API traffic, which is ~95 % of total IPC volume in interactive sessions.
§Wire format
Every text frame is a JSON envelope:
{ "id": <u64>, "method": "<wire-name>", "params": [...] } // request
{ "id": <u64>, "result": <value> } // success
{ "id": <u64>, "error": "<message>" } // failureNotifications (no response expected) carry "id": null and the
peer must not reply.
Binary frames are reserved for B7-S6 phase 2 (length-prefixed prost-encoded payloads for diagnostic batches and tree children) - current implementation logs and ignores them.
§Auth
Per-spawn 32-byte shared secret. The connecting side sends it
in the WebSocket upgrade X-Land-Secret header; the server
rejects connections whose header doesn’t match. Mountain
generates the secret at boot, passes it to Cocoon as an env
variable, and exposes it to Sky via the existing
MountainGetWorkbenchConfiguration Tauri invoke.
§Backpressure
Each side keeps a HashMap<u64, oneshot::Sender> of pending
requests. On disconnect the map is drained with errors; the
Effect-TS supervisor on Sky decides whether to retry or fail.
§Reconnect
Client side runs an exponential backoff (100 ms, 200 ms, 400 ms, 1 s, 2 s, capped at 5 s). After 30 s of failed reconnect the client reports the channel dead.
Structs§
- Client
- Client-side connection. Holds the write half of the WebSocket and a map of pending requests keyed by id.
- Handler
Registry - Method dispatch table.
- Shared
Secret - Per-spawn shared secret for WebSocket connection auth.
Functions§
- Handle
Connection 🔒 - Serve
Local - Run a WebSocket server on
127.0.0.1:<port>. Loops forever accepting connections; spawns a task per connection.
Type Aliases§
- Handler
Fn - Server-side handler signature. One closure per JSON-RPC method; returns the result Value or an error string.
- Pending
Map 🔒 - Pending-request map: request id → response sender.