Skip to main content

oxios_kernel/memory/
mod.rs

1//! Agent memory system.
2//!
3//! Core logic lives in [`oxios_memory`]. This module provides:
4//!
5//! 1. **Trait bridge** — `impl MemoryStorage for StateStore`, `impl MemoryGit for GitLayer`
6//! 2. **Config bridge** — `From<&ConsolidationConfig> for DreamConfig`
7//! 3. **Re-exports** — types used by kernel internals and the web surface
8//! 4. **Sub-modules** — `markdown_bridge` (orphan-rule wrapper),
9//!    `auto_memory_bridge` (oxios_memory re-export)
10
11// ── Trait: StateStore → MemoryStorage ───────────────────────────────
12
13use async_trait::async_trait;
14use oxios_memory::memory::storage::{MemoryGit, MemoryStorage};
15use serde_json::Value;
16
17#[async_trait]
18impl MemoryStorage for crate::state_store::StateStore {
19    async fn save_json_value(&self, c: &str, k: &str, v: &Value) -> anyhow::Result<()> {
20        self.save_json(c, k, v).await
21    }
22    async fn load_json_value(&self, c: &str, k: &str) -> anyhow::Result<Option<Value>> {
23        self.load_json::<Value>(c, k).await
24    }
25    async fn list_category(&self, category: &str) -> anyhow::Result<Vec<String>> {
26        crate::state_store::StateStore::list_category(self, category).await
27    }
28    async fn delete_file(&self, category: &str, key: &str) -> anyhow::Result<bool> {
29        crate::state_store::StateStore::delete_file(self, category, key).await
30    }
31}
32
33// ── Trait: GitLayer → MemoryGit ─────────────────────────────────────
34
35#[async_trait]
36impl MemoryGit for crate::git_layer::GitLayer {
37    async fn commit_file(&self, path: &str, message: &str) -> anyhow::Result<()> {
38        crate::git_layer::GitLayer::commit_file(self, path, message)?;
39        Ok(())
40    }
41    fn is_enabled(&self) -> bool {
42        crate::git_layer::GitLayer::is_enabled(self)
43    }
44}
45
46// ── Config bridge: ConsolidationConfig → DreamConfig ────────────────
47
48impl From<&crate::config::ConsolidationConfig> for oxios_memory::memory::dream::DreamConfig {
49    fn from(c: &crate::config::ConsolidationConfig) -> Self {
50        Self {
51            dream_enabled: c.dream_enabled,
52            dream_interval_hours: c.dream_interval_hours,
53            dream_min_sessions: c.dream_min_sessions,
54            hot_max_entries: c.hot_max_entries,
55            warm_max_entries: c.warm_max_entries,
56            cold_max_entries: c.cold_max_entries,
57            hot_token_budget: c.hot_token_budget,
58            decay_threshold: c.decay_threshold,
59            retention_days: c.retention_days,
60            decay_multiplier: c.decay_multiplier,
61            auto_protection: c.auto_protection,
62            protection_low_access: c.protection_low_access,
63            protection_medium_access: c.protection_medium_access,
64            protection_high_access: c.protection_high_access,
65            protection_medium_sessions: c.protection_medium_sessions,
66            protection_high_sessions: c.protection_high_sessions,
67            protection_demotion_enabled: c.protection_demotion_enabled,
68            protection_demotion_stale_days: c.protection_demotion_stale_days,
69            auto_classification: c.auto_classification,
70            type_promotion_repetitions: c.type_promotion_repetitions,
71            compaction_line_threshold: c.compaction_line_threshold,
72            proactive_recall_limit: c.proactive_recall_limit,
73            proactive_recall_threshold: c.proactive_recall_threshold,
74            pagerank_enabled: true,
75            pagerank_damping: 0.85,
76            pagerank_iterations: 30,
77            pagerank_boost_factor: 0.3,
78        }
79    }
80}
81
82// ── Re-exports ──────────────────────────────────────────────────────
83//
84// Minimal set: only types used by kernel internals or re-exported
85// through lib.rs for the web surface / binary crate.
86
87// Core types (kernel internal consumers)
88pub use oxios_memory::memory::manager::MemoryManager;
89pub use oxios_memory::memory::types::{
90    content_hash, MemoryEntry, MemoryTier, MemoryType, ProtectionLevel, TextVector,
91};
92
93// Dream + Proactive (binary crate)
94pub use oxios_memory::memory::dream::{DreamCheckpoint, DreamConfig, DreamProcess, DreamReport};
95pub use oxios_memory::memory::proactive::{ProactiveRecall, RecallTiming};
96
97// Web surface consumers (embedding viz, HNSW, graph)
98pub use oxios_memory::memory::embedding_viz::{
99    compute_pca_2d, compute_top_neighbors, MemoryMapEntry, MemoryNeighbor,
100};
101pub use oxios_memory::memory::hnsw::HnswIndex;
102pub use oxios_memory::memory::hnsw_memory_index::{HnswMemoryIndex, SemanticHit};
103
104// SQLite backend (feature-gated) — re-exported through lib.rs
105// to avoid duplicate re-exports. Don't re-export here.
106
107// ── Sub-modules ─────────────────────────────────────────────────────
108
109/// Orphan-rule wrapper implementing `MarkdownSource` for `KnowledgeBase`.
110pub mod markdown_bridge;
111
112/// Re-export of `oxios_memory::memory::auto_bridge` under the
113/// kernel's `memory::` namespace for back-compat.
114pub mod auto_memory_bridge {
115    pub use oxios_memory::memory::auto_bridge::*;
116}