Host SDK reference
escope-host provides a Tokio-based Rust Session shared by the CLI and Inspector. Add the SDK from crates.io:
ConnectOptions and Session
Session::connect(endpoint, baud, timeout) uses dtr=None. Both connection functions return only after validating Hello. Endpoints accept direct serial paths, serial:// paths, and tcp://host:port. TCP does not use serial settings.
Session methods
All asynchronous operations below return escope_host::Result<T>.
Session is cloneable; clones share the same connection and closing one closes that shared connection. One reader matches responses by ID, operation, version, and session. Limits are 32 in-flight calls, a 32-request writer queue, and a 128-event broadcast channel.
ui_tree() retries a full traversal on Stale for at most three attempts. It rejects duplicate IDs/cursors, missing parents, parent cycles, zero revision, and more than 4096 nodes. It does not synchronize its result with a separate capture.
Log events
Create a local receiver before starting device logs so immediate events have a receiver:
Event contains session, operation, and payload. Event::log() validates and decodes a Log event into an owned LogRecord. A long-lived collector handles RecvError::Lagged(n) separately from closure and device dropped. A local receiver does not itself create a device subscription.
start_logs uses numeric levels 1…5, inclusive toward lower values. Target substring filtering is implemented by the CLI, without a current wire target field. Device sequence and drop accounting reset when log state is cleared by unsubscribe, Hello, or reset. Device timestamps use milliseconds since boot.
Data models
Public host models use owned strings and implement serialization.
Metric memory fields are optional u64 byte counts. frame_ms and queue_depth are optional u32 values. uptime_ms and dropped_logs are u64. Missing values remain None/JSON null. Their source and statistical scope are defined by the platform.
devices() -> Result<Vec<PortInfo>> enumerates serial metadata without opening a port. PortInfo fields and OS interface conventions are listed in the CLI reference. capability_names(mask) maps known capability bits to their command-facing names. tree_depths(nodes) validates parents and returns a node-to-depth map.
Capture
Capture has meta: protocol::CaptureMeta and rgb: Vec<u8>. The RGB data uses packed RGB888 rows with raw padding removed. Capture::from_raw(meta, raw) validates metadata and length before conversion.
The SDK validates a raw-frame budget of 32 MiB, positive dimensions and ID, checked stride/total arithmetic, supported format, matching read ID/offset, nonempty bounded data, and the exact terminal done flag. Read size is min(negotiated max_payload − 64, 768) bytes.
Capture::save_png(path) performs synchronous filesystem I/O with create_new(true). It preserves an existing path. Call it in a worker when the caller has a UI or other latency-sensitive loop. The Inspector supplies a separate export thread; the SDK method itself is synchronous.
Capture uses Start → Read → End with a cleanup lease. A confirmed device rejection at Start, including Busy, leaves the Session usable. An unknown-ID start timeout/cancellation or undecodable response closes it. Once an ID is known, failure/cancellation attempts End on the current Tokio runtime. Failed cleanup other than Stale closes the Session. See Architecture and lifecycles for reset responsibilities.
Errors and cancellation
Dropping a request future removes its host waiter. Late responses are ignored. It does not universally cancel remote work. Requests with side effects, including input, are not replayed automatically. Busy is returned directly without SDK polling.
There is no typed Session::cancel method. Protocol Cancel is available through request_raw only when the platform defines its behavior. It is separate from capture lease cleanup. Reconnect when the Session closes, and rely on platform Backend::reset to release resources at that boundary.