1pub mod auto_dream;
2pub mod auto_memory;
3pub mod checkpoint_writer;
4pub mod embedding;
5pub mod extract;
6pub mod global_memory;
7pub mod history_store;
8pub mod maintenance;
9pub mod memory_store;
10pub mod rebuild_context;
11pub mod schemas;
12
13#[cfg(test)]
14pub mod tests;
15
16pub use auto_dream::AutoDreamState;
17pub use auto_memory::{
18 AutoMemoryStore, ConsolidationReport, MemoryEntry, MemoryStatus, MemorySummary, MemoryType,
19 configure_connection, cosine_similarity, new_entry, sanitize_id,
20};
21pub use checkpoint_writer::run_checkpoint_writer;
22pub use embedding::{
23 DEFAULT_MODEL_FILE, DEFAULT_MODEL_REPO, DEFAULT_TOKENIZER_FILE, DEFAULT_TOKENIZER_REPO,
24 EMBED_DIM, Embedder, EmbeddingConfig, NoEmbedder, create_embedder, embeddings_available,
25};
26pub use global_memory::GlobalMemoryStore;
27pub use history_store::{HistoryEvent, HistoryStore, SessionSummary};
28pub use maintenance::{
29 DreamOptions, DreamResult, run_distill_maintenance, run_dream_maintenance,
30 run_dream_maintenance_with_options,
31};
32pub use memory_store::{MemoryStore, write_atomic};
33pub use rebuild_context::build_rebuild_context;
34pub use schemas::SessionCheckpoint;
35
36use anyhow::Result;
37use std::path::PathBuf;
38
39#[derive(Debug, Clone)]
41pub struct MemoryManager {
42 pub store: MemoryStore,
43 pub history: HistoryStore,
44 pub auto_memory: AutoMemoryStore,
45 pub global_memory: GlobalMemoryStore,
46}
47
48impl MemoryManager {
49 pub fn new(
51 project_dir: PathBuf,
52 data_dir: PathBuf,
53 config: &crate::config::MemoryConfig,
54 ) -> Result<Self> {
55 let store = MemoryStore::new(project_dir, data_dir.clone(), &config.root);
56 store.ensure_initialized()?;
57
58 let resolved_sqlite_path =
59 memory_store::resolve_memory_path(&config.history.sqlite_path, &store.memory_root);
60 let history = HistoryStore::new(&resolved_sqlite_path)?;
61
62 let auto_memory_db = store.memory_root.join("memories.db");
63 let auto_memory = AutoMemoryStore::open(&auto_memory_db)?;
64
65 let global_memory_db = data_dir.join("memory").join("global-memory.db");
66 let global_memory = GlobalMemoryStore::open(&global_memory_db)?;
67
68 Ok(Self {
69 store,
70 history,
71 auto_memory,
72 global_memory,
73 })
74 }
75}