Expand description
AG-2a: the protocol-neutral editor read-state cache.
Per mode-ownership ([[feedback_mode_owns_its_surface]]), the read state
the agent read tools answer from belongs to this crate, not the host
and not any one agent-protocol adapter. Adapters subscribe to the generic
event bus (DocumentOpened / DocumentClosed / SelectionsChanged) and
fold those events into an EditorStateCache. A dedicated updater task
owns the writes; agent tasks read the cache off the editor thread. The
editor thread pays nothing new — it already publishes these events.
On-demand text / path / dirty come from the generic BufferStore
service at read time, not this cache — the cache only tracks the
open-editor set and the active selection, which aren’t otherwise
queryable off-thread.
Structs§
- Active
Selection - The active buffer’s selection, tracked from
SelectionsChanged. - Editor
State Cache - Crate-owned snapshot of the editor state the read tools answer from.
Holds no host types — only protocol-level ids / selections / paths.
Mutated solely by the updater task (draining generic events); read by
consumers under the
EditorStateHandlemutex. - Open
Buffer - One open editor buffer, tracked from
DocumentOpened.
Functions§
- spawn_
read_ cache - Subscribe to the generic event bus and spawn the cache-updater task. Returns the shared cache handle. Fully crate-owned: the host only publishes the (generic) events; this task + cache live here.
Type Aliases§
- Editor
State Handle - Thread-safe handle to the read cache, shared between the updater task
(writer) and agent tasks (readers). A plain
Mutex— updates are O(1) in-place (no per-event clone) and reads are rare (agent-initiated), so there’s no contention worth a wait-free structure.