Expand description
Read/write/append snapshot state for the agent:<defId>:current zone,
including the global-mirror normalization + one-shot heal.
Constants§
- OUTPUT_
FILE - Raw NDJSON stream for crash-recovery replay.
- SNAPSHOT_
FILE - Full UI snapshot (JSON). Frontend reads this on pane mount.
- TSIDX_
FILE - Receive-time sidecar for
output: one NDJSON{"off":<byte offset of the appended batch>,"ms":<unix ms>}record per append batch. A pure addition —output’s own format and every existing parser are untouched; a missing or corrupt sidecar degrades reads to “no stamps” (today’s behavior). Gives replayed transcript nodes real timestamps (hover peek after restore, day separators). Spec: SPEC_AGENT_PANE_SESSION_SCOPED_SCROLLBACK_AND_AGENT_HISTORY_VIEW_2026_08_09.md §4.4.
Functions§
- append_
session_ output - Append
line(with a trailing newline added if not present) tooutputinagent:<defId>:current. Creates the file if missing. - heal_
global_ snapshot_ source_ block_ ids - One-shot heal for global snapshots poisoned before the normalize-on-mirror fix
(a channel-local
sourceBlockIdwas mirrored intoagent:<defId>:current, breaking cross-channel opens). For eachdef_id, rewrite its global snapshot’ssourceBlockIdto “” iff it isn’t already. Idempotent and cheap (one small JSON per agent); returns the number healed. Best-effort per agent. - normalize_
snapshot_ for_ global - Strip
sourceBlockIdto “” for the GLOBAL (cross-channel) snapshot mirror. - read_
session_ state - Read
output.state.jsonfromagent:<defId>:current. ReturnsOk((None, None))when the zone doesn’t exist — that’s the “fresh agent, nothing to restore” path and is NOT an error. - read_
snapshot_ 🔒from - Read
output.state.jsonfromzoneinstore.Ok(None)when absent. - write_
session_ state - Write
contenttooutput.state.jsoninagent:<defId>:current. Idempotent — creates the file if missing, overwrites otherwise.