Module ipc

Module ipc 

Source
Expand description

Phase B.2 IPC wire protocol — shared between agentmux-launcher (server) and agentmux-cef (client). One source of truth so the Command / Event shapes can’t drift between binaries on a version-skew release.

See specs/SPEC_WINDOW_PROCESS_STATE_MACHINE_2026_04_27.md §5.

Wire format: newline-delimited JSON. One message per line, parsed via serde_json. Format chosen for debuggability — operators can cat / nc the named pipe and read traffic without a binary protocol decoder.

Backward compat policy (B.2 baseline; harden in Phase D):

  • Externally tagged enums ({"cmd":"register",...}) so adding variants is non-breaking; clients send what they know.
  • Unknown commands → server replies Event::Error rather than crashing.
  • version: u64 on every Event lets Phase D’s GetSnapshot / resync detect skew. For B.2 it’s set but not enforced.

Structs§

Rect
Phase B.9.1 — rectangle in Win32 screen coordinates (pixels). Matches Windows’ RECT semantics: right and bottom are one past the last included pixel, so right - left == width.
WindowSnapshot
Phase D.1 — serializable view of one window in the launcher reducer’s canonical state. Maps 1:1 to the launcher’s internal WindowMirror minus opened_at (which is launcher-local clock data not meaningful to subscribers).

Enums§

ClientKind
Stable identifier for a connected client. Tagged so the launcher can route replies + log who said what.
Command
Commands flow client → launcher.
DriftKind
Phase B.4 follow-up — which mirror diverged. Tagged so subscribers can route alerts (windows-drift might page; pool-drift is more ephemeral since the pool turns over fast).
ErrorCode
Discriminant for Event::Error — keeps clients structured against failure modes without parsing message text.
Event
Events flow launcher → client. Versioned per spec §5.2 — every event carries a monotonic version: u64 per launcher run, used by Phase D’s resync protocol.
HostFrame
Phase CPD-1 (cross-process dispatch) — envelope enum for frames sent over the launcher → host pipe direction. Today the host’s read loop only expects Event JSON; CPD-2 extends the read loop to recognize this tagged union and dispatch by kind:
HwndDriftKind
Phase B.9.1 — six classes of CEF↔Win32 disagreement the reducer can detect at event-dispatch time. See the WRR design doc for the per-kind triggering Command and reducer action.
LifecyclePhase
Coarse-grained launcher state. Spec §4: Starting → Running → Quitting → Dead, no other transitions allowed. The reducer in agentmux-launcher::reducer enforces this; a violation panics (Job Object reaps via OS).
Severity
Phase B.9.1 — drift severity. Operator-tunable severity floor in WrrConfig.severity_floor controls which events get broadcast (ones below the floor are still logged at DEBUG so they show up in --diag wrr post-mortem).
WindowKind
Wire-side enum for WindowKind. Mirrors agentmux-cef::state::WindowKind — kept here so the launcher can deserialize without depending on the host crate. The host serializes its own type via serde(rename_all = "snake_case") so the JSON shape matches exactly.