sqry_daemon/ipc/mod.rs
1//! IPC surface of the sqryd daemon.
2//!
3//! Task 8 Phase 8a wires the wire format, framing, version handshake,
4//! request validator, and the first four daemon management methods
5//! (`daemon/status`, `daemon/load`, `daemon/unload`, `daemon/stop`) that
6//! together give a CLI client a fully usable remote-control channel.
7//!
8//! # Module layout
9//!
10//! - [`framing`] — 4-byte little-endian length-prefix codec.
11//! - [`protocol`] — wire types: [`protocol::DaemonHello`],
12//! [`protocol::DaemonHelloResponse`], [`protocol::ResponseEnvelope`],
13//! [`protocol::ResponseMeta`], [`protocol::JsonRpcRequest`],
14//! [`protocol::JsonRpcResponse`], [`protocol::JsonRpcError`],
15//! [`protocol::JsonRpcId`].
16//! - [`validation`] — JSON-RPC 2.0 request validator.
17//! - [`path_policy`] — canonicalisation policy for
18//! [`crate::workspace::WorkspaceKey`] construction from user paths.
19//! - [`shim_registry`] — shim-connection registry (Phase 8c public surface).
20//! - [`server`] — [`server::IpcServer`] accept loop (UDS + named pipe).
21//! - [`router`] — connection router + batch dispatch.
22//! - [`methods`] — one module per JSON-RPC method handler.
23//!
24//! # Concurrency
25//!
26//! The accept loop and every per-connection task are spawned on the
27//! current Tokio runtime. The router holds no locks across `.await`
28//! points; [`crate::workspace::WorkspaceManager`]-mutating method
29//! handlers use [`tokio::task::spawn_blocking`] when they call sync
30//! long-running operations (e.g. [`crate::workspace::WorkspaceManager::get_or_load`]).
31//! §J.4 lock order (`workspaces → rebuild_lane → admission`) is
32//! preserved: no IPC-owned lock is ever acquired.
33//!
34//! # Shutdown
35//!
36//! IPC server construction takes a
37//! [`tokio_util::sync::CancellationToken`]. The `daemon/stop` method
38//! and Task 9's signal handler both flip the token; the accept loop
39//! observes cancellation in a biased `tokio::select!` arm and drains
40//! active connections for up to
41//! [`crate::config::DaemonConfig::ipc_shutdown_drain_secs`] before
42//! returning.
43
44pub mod framing;
45pub(crate) mod methods;
46pub(crate) mod path_policy;
47pub mod protocol;
48pub(crate) mod router;
49pub mod server;
50pub mod shim_registry;
51pub mod tool_core;
52pub mod validation;
53
54pub use protocol::{
55 CancelRebuildResult, DaemonHello, DaemonHelloResponse, JsonRpcError, JsonRpcId, JsonRpcPayload,
56 JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, RebuildResult, ResponseEnvelope, ResponseMeta,
57};
58pub use server::IpcServer;
59pub use shim_registry::{ShimConnEntry, ShimConnId, ShimHandle, ShimRegistry};