rig_memory_policy/lib.rs
1//! Backend-agnostic memory-policy primitives shared across Rig memory-store
2//! adapters (`rig-memvid` and future backends like SQLite, LanceDB, Qdrant,
3//! plain filesystem, etc.).
4//!
5//! Public surface:
6//!
7//! - [`dedup`] — in-process content-hash dedup for hooks/compactors that must
8//! satisfy `rig::memory::{DemotionHook, Compactor}`'s idempotency contract.
9//! - [`metadata`] — typed envelope written into a backend's per-entry
10//! metadata so downstream tools (evals, inspectors, RAG pipelines) can
11//! reason about the lifecycle that produced each entry.
12//! - [`inmem`] — a deterministic no-disk reference store for tests,
13//! examples, and offline modes.
14//! - [`scope`] — normalized exact and hierarchical scope matching helpers for
15//! backend isolation and provenance projection.
16//! - [`retention`] — deterministic keep/drop/defer policy evaluation over
17//! backend-provided frame metadata and optional timestamps/sequence numbers.
18//! - [`store`] — the minimal [`TextWriter`] + [`Committable`] capability
19//! traits backends impl so hooks and compactors can be generic over the
20//! storage engine.
21//! - [`error`] — neutral `PolicyError` for failures in the above helpers.
22//!
23//! This crate has **no** dependency on `memvid-core` or any specific storage
24//! engine. Backends are expected to wrap these primitives in their own
25//! adapter (e.g. `rig-memvid` adds `.mv2` framing on top).
26//!
27//! See the [`store`] module docs for the audit-driven rationale behind the
28//! deliberately narrow trait surface.
29
30#![deny(missing_docs)]
31#![deny(rustdoc::broken_intra_doc_links)]
32
33pub mod dedup;
34pub mod error;
35pub mod inmem;
36pub mod metadata;
37pub mod retention;
38pub mod scope;
39pub mod store;
40
41pub use error::PolicyError;
42pub use inmem::{Episode, InMemoryHit, InMemoryStore};
43pub use metadata::{FrameKind, FrameMetadata};
44pub use retention::{RetentionCandidate, RetentionDecision, RetentionPolicy, RetentionRule};
45pub use scope::{Scope, normalize_scope, scope_matches, scope_path};
46pub use store::{Committable, TextWriter};