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. Preview is read-only apart from the advisory lock.
Refuses damaged history. 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 claude|codex SESSION_ID")?);
10 let agent = match args.next().and_then(|s| s.into_string().ok()).as_deref() {
11 Some("claude") => Agent::Claude,
12 Some("codex") => Agent::Codex,
13 _ => bail!("agent must be claude or codex"),
14 };
15 let session_id =
16 args.next().context("missing session ID")?.into_string().map_err(|_| anyhow::anyhow!("invalid session ID"))?;
17 anyhow::ensure!(args.next().is_none(), "unexpected argument");
18 let report = Store::new(root).read(&SessionKey { agent, session_id })?;
19 for warning in report.warnings {
20 eprintln!("{}: {}", warning.path.display(), warning.message);
21 }
22 println!("{}", serde_json::to_string_pretty(&files(report.events))?);
23 Ok(())
24}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 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 claude|codex SESSION_ID")?);
10 let agent = match args.next().and_then(|s| s.into_string().ok()).as_deref() {
11 Some("claude") => Agent::Claude,
12 Some("codex") => Agent::Codex,
13 _ => bail!("agent must be claude or codex"),
14 };
15 let session_id =
16 args.next().context("missing session ID")?.into_string().map_err(|_| anyhow::anyhow!("invalid session ID"))?;
17 anyhow::ensure!(args.next().is_none(), "unexpected argument");
18 let report = Store::new(root).read(&SessionKey { agent, session_id })?;
19 for warning in report.warnings {
20 eprintln!("{}: {}", warning.path.display(), warning.message);
21 }
22 println!("{}", serde_json::to_string_pretty(&files(report.events))?);
23 Ok(())
24}