aa_storage_sqlite_buffer/config.rs
1//! Configuration for the SQLite event buffer.
2
3use std::path::PathBuf;
4
5use serde::Deserialize;
6
7/// Default maximum number of events retained before the oldest are evicted.
8///
9/// Bounds disk use while still tolerating a multi-minute upstream outage at
10/// typical audit-event rates.
11pub const DEFAULT_CAP: usize = 10_000;
12
13/// Resolve the default buffer database path.
14///
15/// Returns the platform data directory joined with `agent-assembly/buffer.db` —
16/// `~/.local/share/agent-assembly/buffer.db` on Linux (per the XDG
17/// base-directory spec). Falls back to a relative `buffer.db` when no data
18/// directory can be determined.
19#[must_use]
20pub fn default_path() -> PathBuf {
21 dirs::data_dir()
22 .map(|dir| dir.join("agent-assembly").join("buffer.db"))
23 .unwrap_or_else(|| PathBuf::from("buffer.db"))
24}
25
26/// Operator configuration for the SQLite event buffer.
27///
28/// Deserialized from the `[storage.sqlite_buffer]` table of
29/// `agent-assembly.toml`. Both fields are optional; omitted fields fall back to
30/// [`default_path`] and [`DEFAULT_CAP`].
31///
32/// ```
33/// use aa_storage_sqlite_buffer::{SqliteBufferConfig, DEFAULT_CAP};
34///
35/// let cfg = SqliteBufferConfig::default();
36/// assert_eq!(cfg.cap, DEFAULT_CAP);
37/// ```
38#[derive(Debug, Clone, Deserialize)]
39#[serde(default)]
40pub struct SqliteBufferConfig {
41 /// Filesystem path to the single-file SQLite buffer database.
42 pub path: PathBuf,
43 /// Maximum number of events retained before the oldest are evicted.
44 pub cap: usize,
45}
46
47impl Default for SqliteBufferConfig {
48 fn default() -> Self {
49 Self {
50 path: default_path(),
51 cap: DEFAULT_CAP,
52 }
53 }
54}