Skip to main content

klieo_runlog/
lib.rs

1#![deny(rustdoc::broken_intra_doc_links)]
2//! `klieo-runlog` — Tier 2 observability for klieo agents.
3//!
4//! This crate ships:
5//! - A [`RunLog`] aggregate type (the spec §8.2 view: `run_id`,
6//!   `agent`, `started_at`, `finished_at`, `status`, `steps`, `tokens`,
7//!   `cost_estimate`).
8//! - A pluggable [`RunLogStore`] trait. Default in-memory;
9//!   SQLite behind `sqlite` feature.
10//! - Deterministic [`compaction`](mod@compaction) (drop-by-rule). LLM-summarise
11//!   compaction behind `compaction-llm` feature.
12//! - A deterministic-only [`replay`](mod@replay) engine that re-runs recorded
13//!   LLM + tool calls.
14//!
15//! ## Design: projection over `EpisodicMemory`, not a new trait
16//!
17//! `RunLog` is **not** a separate sink. It is a projection computed by walking
18//! a `Vec<klieo_core::Episode>` returned from any
19//! `EpisodicMemory::replay(run_id)`. The crate adds **zero traits** to
20//! `klieo-core`. Plan #11 froze that surface.
21//!
22//! Typical wiring:
23//! ```text
24//!   EpisodicMemory --(replay)--> Vec<Episode> --(project)--> RunLog --(put)--> RunLogStore
25//! ```
26//!
27//! ## Replay caveats
28//!
29//! [`replay`](mod@replay) is **deterministic-only**. It asserts that user-supplied
30//! test-double `LlmClient` + `ToolInvoker` produce byte-identical outputs to
31//! the recorded ones. Side effects that do not flow through these traits
32//! (timestamps, randomness, network calls outside the recorded LLM/tool
33//! calls) cannot be replayed.
34#![deny(missing_docs)]
35
36pub mod capture;
37pub mod capture_sink;
38pub mod capture_store;
39pub mod compaction;
40pub mod divergence;
41pub mod error;
42pub mod fingerprint;
43pub mod pricing;
44pub mod projector;
45pub mod replay;
46pub mod replay_llm;
47pub mod store;
48#[cfg(feature = "sqlite")]
49pub mod store_sqlite;
50#[cfg(feature = "test-utils")]
51pub mod test_utils;
52pub mod types;
53
54pub use crate::capture::Capture;
55pub use crate::capture_sink::RunLogCaptureSink;
56pub use crate::capture_store::{gc_captures, load_capture, persist_capture, CAPTURE_BUCKET};
57#[cfg(feature = "compaction-llm")]
58pub use crate::compaction::LlmCompaction;
59pub use crate::compaction::{CompactionPolicy, DeterministicCompaction};
60pub use crate::divergence::{
61    replay_with_divergence, DivergenceReport, ReplayMode, ReproVerdict, StepDivergence,
62};
63pub use crate::error::RunLogError;
64pub use crate::fingerprint::request_fingerprint;
65pub use crate::pricing::{PriceTable, Rates, RatesError};
66pub use crate::projector::{project, project_with_llm_io, project_with_price_table};
67pub use crate::replay::replay;
68pub use crate::replay_llm::ReplayLlmClient;
69pub use crate::store::{InMemoryRunLogStore, RunLogQuery, RunLogStore};
70#[cfg(feature = "sqlite")]
71pub use crate::store_sqlite::SqliteRunLogStore;
72pub use crate::types::{Cost, LlmIo, RunLog, RunStatus, Step, StepKind, Usage};