Skip to main content

StateStore

Struct StateStore 

Source
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

Source

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.

Source

pub fn from_env() -> Self

Construct a store under ${XDG_RUNTIME_DIR:-/tmp}/agent-status/.

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.