Skip to main content

Module mps_client

Module mps_client 

Source
Expand description

Thin HTTP client for publishing MPS events to the AgentMux sidecar.

Reads AGENTMUX_LOCAL_URL and AGENTMUX_AUTH_KEY from the process environment (inherited from the agentmux-srv → claude → bash subprocess chain). Attaches X-AuthKey per PR #801 to authenticate against the auth_middleware-gated publish endpoint.

Designed to silently degrade: if env vars are absent or the sidecar is unreachable, publishes fail-fast and the caller emits a kind: "system" chunk that surfaces the degradation to the user without aborting the command itself.

Structs§

WpsClient
Per-launch sidecar config + reusable HTTP client. Cheap to clone (the inner reqwest::Client uses Arc internally).

Constants§

COMPACTION_STARTED_EVENT 🔒
Event name for the PreCompact-hook-sourced “compaction started” signal. See docs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md §4.2 / Tier 1.
COMPACTION_STARTED_PERSIST 🔒
persist: 0 — never retained/replayed. A late/reconnecting subscriber must NOT see a past “compaction started” ping: there is no matching completion tombstone (compact_boundary arrives over the separate NDJSON stream, not MPS), so replaying a retained start indistinguishably resurrects “Compacting…” for a compaction that may have finished seconds after the ping — a timestamp-age guard alone can’t tell “recently finished” apart from “still running” (Codex P1, PR #2378 round 2). Only a currently-live subscriber should ever see this event; a disconnected pane already clears its own compacting flag on StreamUnsubscribe (reducer.ts), so there is nothing worth replaying on reconnect regardless.
COMPACTION_STARTED_TIMEOUT 🔒
Fail-fast timeout for publish_compaction_started specifically — much shorter than the 5s client-wide default used for tool_chunk streaming (from_env). That default is fine for exec’s own async runtime, but precompact is invoked as Claude Code’s SYNCHRONOUS PreCompact hook: the CLI blocks compaction on this process’s exit, so inheriting the 5s default means a wedged (but TCP-accepting) backend delays the user’s actual compaction by up to 5 real seconds — directly contradicting this hook’s own “never block/delay the operation for observability” contract (see precompact.rs’s module doc comment). Codex P2, PR #2378 round 4. 500ms comfortably covers a normal same-host round trip while keeping the worst case imperceptible.
PUBLISH_PATH 🔒
TOOL_CHUNK_EVENT 🔒
Event name for streaming bash chunks. Held constant across every publish so the frontend can subscribe once per block on mount.
TOOL_CHUNK_PERSIST 🔒
How many tool_chunk events the broker keeps per block:<id> scope. Sized for npm-install class output (~1000 lines is typical; 1024 covers all but heavy CI builds). Each event is ~200–500 bytes, so the steady-state ceiling is ~512 KB per actively-streaming block.