pub struct Store { /* private fields */ }Expand description
An append-only store of metadata-only batches, namespaced by agent/session. Each hook writes its own batch then renames it atomically. Concurrent hooks cannot overwrite each other, and readers never see a partially written batch.
Implementations§
Source§impl Store
impl Store
Sourcepub fn retained_from(&self, session: &SessionKey) -> Result<Option<i64>>
pub fn retained_from(&self, session: &SessionKey) -> Result<Option<i64>>
Fixed lower timestamp bound chosen by explicit retention. This also prevents a resumed session from reimporting expired transcript events.
Sourcepub fn maintain(
&self,
session: &SessionKey,
before: Option<i64>,
apply: bool,
) -> Result<MaintenanceReport>
pub fn maintain( &self, session: &SessionKey, before: Option<i64>, apply: bool, ) -> Result<MaintenanceReport>
Pack history into fewer files, optionally retaining only timestamps at
or after before, in Unix seconds. Preview is read-only apart from the
advisory lock. Refuses damaged history, unexpected files, and cutoffs in
the future. Never reconciles or discards raw observations unless an
explicit retention cutoff is supplied.
Source§impl Store
impl Store
Sourcepub fn new(root: impl Into<PathBuf>) -> Self
pub fn new(root: impl Into<PathBuf>) -> Self
Examples found in repository?
7fn main() -> Result<()> {
8 let mut args = std::env::args_os().skip(1);
9 let root = PathBuf::from(args.next().context("usage: inspect STORE_ROOT AGENT SESSION_ID")?);
10 let agent = AgentId::new(
11 args.next().context("missing agent")?.into_string().map_err(|_| anyhow::anyhow!("invalid agent"))?,
12 )?;
13 let session_id =
14 args.next().context("missing session ID")?.into_string().map_err(|_| anyhow::anyhow!("invalid session ID"))?;
15 anyhow::ensure!(args.next().is_none(), "unexpected argument");
16 let report = Store::new(root).read(&SessionKey { agent, session_id })?;
17 for warning in report.warnings {
18 eprintln!("{}: {}", warning.path.display(), warning.message);
19 }
20 println!("{}", serde_json::to_string_pretty(&files(report.events))?);
21 Ok(())
22}Sourcepub fn sessions(&self) -> SessionReport
pub fn sessions(&self) -> SessionReport
Enumerate retained session directories, including ended/compacted sessions. Does not create state or follow namespace/session directory symlinks.
Sourcepub fn read_all(&self) -> ReadReport
pub fn read_all(&self) -> ReadReport
Read retained history across agents/sessions. Per-session failures become warnings so one damaged checkpoint cannot hide other sessions. This is not a globally atomic snapshot; each session is read under its own lock.
pub fn append(&self, session: &SessionKey, events: &[FileEvent]) -> Result<()>
Sourcepub fn append_new(
&self,
session: &SessionKey,
events: &[FileEvent],
) -> Result<usize>
pub fn append_new( &self, session: &SessionKey, events: &[FileEvent], ) -> Result<usize>
Append the events not already retained, and return how many. Captures
repeat evidence, such as a transcript parsed at every turn; this keeps
one copy. concurrent is not part of an event’s identity, and the read
and append happen under one exclusive lock.
Sourcepub fn events(&self, session: &SessionKey) -> Result<Vec<FileEvent>>
pub fn events(&self, session: &SessionKey) -> Result<Vec<FileEvent>>
Strict reads remain available for callers that require complete history.
Sourcepub fn read(&self, session: &SessionKey) -> Result<ReadReport>
pub fn read(&self, session: &SessionKey) -> Result<ReadReport>
Read every valid batch and report damaged/unreadable batches separately. Bad batches are left untouched for inspection and recovery.
Examples found in repository?
7fn main() -> Result<()> {
8 let mut args = std::env::args_os().skip(1);
9 let root = PathBuf::from(args.next().context("usage: inspect STORE_ROOT AGENT SESSION_ID")?);
10 let agent = AgentId::new(
11 args.next().context("missing agent")?.into_string().map_err(|_| anyhow::anyhow!("invalid agent"))?,
12 )?;
13 let session_id =
14 args.next().context("missing session ID")?.into_string().map_err(|_| anyhow::anyhow!("invalid session ID"))?;
15 anyhow::ensure!(args.next().is_none(), "unexpected argument");
16 let report = Store::new(root).read(&SessionKey { agent, session_id })?;
17 for warning in report.warnings {
18 eprintln!("{}: {}", warning.path.display(), warning.message);
19 }
20 println!("{}", serde_json::to_string_pretty(&files(report.events))?);
21 Ok(())
22}