luft_storage/lib.rs
1//! # luft-storage
2//!
3//! **SQLite-backed structured persistence for Luft.**
4//!
5//! Replaces the JSONL `events.jsonl` + `checkpoint.json` pair with a queryable,
6//! relational store. Provides a UI-ready query API for listing runs, inspecting
7//! agent turns, and searching event spans.
8//!
9//! ## Module Layout
10//!
11//! | Module | Responsibility |
12//! |--------|---------------|
13//! | [`db`] | Connection pool (`DbPool`) + schema migration |
14//! | [`writer`] | `AgentEvent` → SQL write path ([`EventWriter`]) |
15//! | [`reader`] | UI-ready query API: [`get_run_overview`], [`get_agent_turns`], etc. |
16//! | [`error`] | Unified [`StorageError`] type |
17//!
18//! ## Usage
19//!
20//! ```no_run
21//! use luft_storage::{open_db, EventWriter};
22//! use std::path::Path;
23//!
24//! # tokio::runtime::Runtime::new().unwrap().block_on(async {
25//! let pool = open_db(Path::new("./.luft/runs/latest/luft.db")).await?;
26//! let writer = EventWriter::new(pool.clone());
27//! // writer.write_event(&event).await?;
28//! # Ok::<(), Box<dyn std::error::Error>>(())
29//! # });
30//! ```
31
32pub mod db;
33pub mod error;
34pub mod reader;
35pub mod writer;
36
37pub use db::{open_db, DbPool, DEFAULT_DB_PATH};
38pub use error::StorageError;
39pub use reader::{
40 get_agent_overview, get_agent_turns, get_run_agents, get_run_overview, get_run_spans,
41 get_run_tree, list_runs, search_turns, AgentOverview, RunOverview, RunSummary, SpanRow,
42 TurnKindCount, TurnRow,
43};
44pub use writer::EventWriter;
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49 use std::path::Path;
50
51 #[test]
52 fn default_db_path_is_luft_db_filename() {
53 let p = DEFAULT_DB_PATH;
54 assert_eq!(p, "luft.db");
55 assert!(p.ends_with(".db"));
56 }
57
58 #[test]
59 fn storage_error_re_export_matches_crate_path() {
60 let _e: StorageError = StorageError::Invalid("ping".into());
61 let msg = _e.to_string();
62 assert!(msg.contains("invalid input"));
63 }
64
65 #[test]
66 fn submodules_are_publicly_accessible() {
67 // Compile-time check: each module path resolves through the crate root.
68 let _: db::__DbProbe = ();
69 let _: error::__ErrorProbe = ();
70 let _: reader::__ReaderProbe = ();
71 let _: writer::__WriterProbe = ();
72 // The above consts are injected by the macros below for compile checks.
73 // If this test compiles, the module surface is exposed.
74 }
75
76 // Each submodule declares a `pub const __Probe: () = ();` only under cfg(test)
77 // so we can reference them generically above. Implemented inline below.
78 mod db {
79 #[cfg(test)]
80 pub type __DbProbe = ();
81 }
82 mod error {
83 #[cfg(test)]
84 pub type __ErrorProbe = ();
85 }
86 mod reader {
87 #[cfg(test)]
88 pub type __ReaderProbe = ();
89 }
90 mod writer {
91 #[cfg(test)]
92 pub type __WriterProbe = ();
93 }
94}