Skip to main content

totalreclaw_memory/
lib.rs

1//! TotalReclaw Memory Backend
2//!
3//! Rust implementation of the TotalReclaw E2EE memory pipeline.
4//! Produces byte-for-byte identical crypto output to the TypeScript MCP server.
5//!
6//! # Modules
7//!
8//! - [`crypto`] — Key derivation (BIP-39 + HKDF-SHA256), XChaCha20-Poly1305 encrypt/decrypt
9//! - [`blind`] — Blind index generation (SHA-256 token hashing + Porter stemming)
10//! - [`fingerprint`] — Content fingerprint (HMAC-SHA256 with NFC normalization)
11//! - [`lsh`] — Locality-sensitive hashing (random hyperplane LSH)
12//! - [`embedding`] — Embedding pipeline (Local ONNX, Ollama, ZeroClaw, LLM provider)
13//! - [`reranker`] — BM25 + Cosine + RRF fusion reranker
14//! - [`relay`] — HTTP client for TotalReclaw relay server
15//! - [`protobuf`] — Minimal protobuf encoder for fact payloads
16//! - [`store`] — Encrypt → index → encode → submit pipeline (with Phase 2 KG contradiction check)
17//! - [`search`] — Subgraph query → decrypt → rerank pipeline
18//! - [`backend`] — ZeroClaw Memory trait implementation
19//! - [`setup`] — First-use setup wizard (credentials + embedding config)
20
21pub mod backend;
22pub mod billing;
23pub mod blind;
24pub mod crypto;
25pub mod debrief;
26pub mod embedding;
27pub mod fingerprint;
28pub mod hotcache;
29pub mod lsh;
30pub mod protobuf;
31pub mod relay;
32pub mod reranker;
33pub mod search;
34pub mod setup;
35pub mod stemmer;
36pub mod store;
37pub mod userop;
38pub mod wallet;
39
40pub use backend::{MemoryCategory, MemoryEntry, TotalReclawConfig, TotalReclawMemory};
41
42// Re-export core Phase 2 KG types for downstream consumers.
43pub use totalreclaw_core::claims::{
44    Claim, ClaimCategory, ClaimStatus, EntityRef, EntityType, ResolutionAction, SkipReason,
45    TIE_ZONE_SCORE_TOLERANCE, is_pinned_claim, is_pinned_json, respect_pin_in_resolution,
46};
47// Memory Taxonomy v1 types. As of totalreclaw-memory 2.0 these are the
48// canonical taxonomy; v0 categories remain for pre-2.0 vault back-compat.
49pub use totalreclaw_core::claims::{
50    MemoryClaimV1, MemoryEntityV1, MemorySource, MemoryScope, MemoryTypeV1,
51    MemoryVolatility, MEMORY_CLAIM_V1_SCHEMA_VERSION,
52};
53pub use totalreclaw_core::contradiction::{
54    Contradiction, ResolutionOutcome, ResolutionWeights, ScoreComponents,
55    resolve_with_candidates, resolve_pair, detect_contradictions, default_weights,
56    DEFAULT_LOWER_THRESHOLD, DEFAULT_UPPER_THRESHOLD,
57};
58pub use totalreclaw_core::decision_log::{
59    DecisionLogEntry, DECISION_LOG_MAX_LINES, CONTRADICTION_CANDIDATE_CAP,
60    find_loser_claim_in_decision_log, find_decision_for_pin,
61    build_feedback_from_decision, append_decision_entry,
62};
63pub use store::ContradictionStoreResult;
64
65/// Crate-level error type.
66#[derive(Debug, thiserror::Error)]
67pub enum Error {
68    #[error("crypto error: {0}")]
69    Crypto(String),
70
71    #[error("invalid mnemonic: {0}")]
72    InvalidMnemonic(String),
73
74    #[error("embedding error: {0}")]
75    Embedding(String),
76
77    #[error("reranker error: {0}")]
78    Reranker(String),
79
80    #[error("LSH error: {0}")]
81    Lsh(String),
82
83    #[error("IO error: {0}")]
84    Io(#[from] std::io::Error),
85
86    #[error("HTTP error: {0}")]
87    Http(String),
88
89    #[error("quota exceeded: {0}")]
90    QuotaExceeded(String),
91}
92
93/// Bridge totalreclaw_core errors into this crate's Error type.
94impl From<totalreclaw_core::Error> for Error {
95    fn from(e: totalreclaw_core::Error) -> Self {
96        match e {
97            totalreclaw_core::Error::Crypto(msg) => Error::Crypto(msg),
98            totalreclaw_core::Error::InvalidMnemonic(msg) => Error::InvalidMnemonic(msg),
99            totalreclaw_core::Error::Lsh(msg) => Error::Lsh(msg),
100            totalreclaw_core::Error::Reranker(msg) => Error::Reranker(msg),
101        }
102    }
103}
104
105pub type Result<T> = std::result::Result<T, Error>;