pub struct StateStore { /* private fields */ }Expand description
Reads, writes and lists AttentionEntry files under a single state directory.
Each session writes one file keyed by its session_id, so concurrent writers from
different sessions never contend on the same path — no locking is required.
Implementations§
Source§impl StateStore
impl StateStore
Sourcepub fn new(dir: PathBuf) -> Self
pub fn new(dir: PathBuf) -> Self
Construct a store backed by dir.
The directory does not need to exist yet — write creates it on demand.
Sourcepub fn write(&self, session_id: &str, entry: &AttentionEntry) -> Result<()>
pub fn write(&self, session_id: &str, entry: &AttentionEntry) -> Result<()>
Write an entry for session_id, creating the state directory if needed.
§Errors
Returns the underlying I/O error if the directory cannot be created or the file cannot
be written. Returns io::ErrorKind::InvalidInput when session_id is empty or
contains a path separator (defense against path-traversal).
Sourcepub fn remove(&self, session_id: &str) -> Result<bool>
pub fn remove(&self, session_id: &str) -> Result<bool>
Remove the entry for session_id. Idempotent: returns Ok(false) when
the file is absent and Ok(true) when a file was actually deleted.
Callers can use the bool to skip side effects (e.g. tmux refresh) on
no-op clears — relevant for hooks like Claude Code’s PreToolUse that
fire on every tool call and would otherwise generate excessive refreshes.
§Errors
Returns the underlying I/O error if removal fails for a reason other
than NotFound. Returns io::ErrorKind::InvalidInput when
session_id is empty or contains a path separator.
Sourcepub fn list(&self) -> Result<Vec<(String, AttentionEntry)>>
pub fn list(&self) -> Result<Vec<(String, AttentionEntry)>>
List all entries in the state directory, sorted by timestamp ascending then session_id.
Files with invalid JSON or unreadable content are silently skipped — they are treated
as if absent. Returns an empty Vec when the directory does not exist.
§Errors
Returns the underlying I/O error if read_dir or per-entry metadata access fails for
a reason other than NotFound.