Skip to main content

claw_core/
lib.rs

1#![deny(missing_docs)]
2#![deny(clippy::unwrap_used)]
3#![cfg_attr(test, allow(clippy::unwrap_used))]
4#![allow(clippy::module_inception)]
5//! # claw-core
6//!
7//! `claw-core` is the embedded local database engine for **ClawDB** — an
8//! agent-native cognitive database. It provides local-first, ultra-low-latency
9//! storage for AI agents, wrapping SQLite with a clean async Rust API that
10//! includes WAL journaling, migrations, LRU caching, FTS5 full-text search,
11//! transactions, and snapshot/restore support.
12//!
13//! ## Quick start
14//!
15//! ```rust,no_run
16//! use claw_core::prelude::*;
17//!
18//! #[tokio::main]
19//! async fn main() -> claw_core::ClawResult<()> {
20//!     // Open (or create) the database with default settings.
21//!     let engine = ClawEngine::open_default().await?;
22//!
23//!     // Insert a memory record.
24//!     let record = MemoryRecord::new(
25//!         "The capital of France is Paris",
26//!         MemoryType::Semantic,
27//!         vec!["geography".to_string()],
28//!         None,
29//!     );
30//!     let id = engine.insert_memory(&record).await?;
31//!
32//!     // Retrieve it back.
33//!     let fetched = engine.get_memory(id).await?;
34//!     assert_eq!(fetched.content, "The capital of France is Paris");
35//!
36//!     // Close the engine cleanly.
37//!     engine.close().await;
38//!     Ok(())
39//! }
40//! ```
41//!
42//! ## Key types
43//!
44//! | Type | Description |
45//! |------|-------------|
46//! | [`ClawEngine`] | Root handle for all database operations |
47//! | [`ClawConfig`] | Runtime configuration built via [`ClawConfigBuilder`] |
48//! | [`MemoryRecord`] | A persistent memory record with type, tags, and TTL |
49//! | [`MemoryType`] | Enum classifying memory records (Semantic, Episodic, …) |
50//! | [`ClawTransaction`] | Atomic transaction wrapper |
51//! | [`ClawError`] | Unified error type |
52
53// ── module declarations ──────────────────────────────────────────────────────
54
55pub mod cache;
56pub mod config;
57pub mod engine;
58pub mod error;
59pub mod index;
60pub mod journal;
61pub mod schema;
62pub mod snapshot;
63pub mod store;
64pub mod transaction;
65
66// ── top-level re-exports ─────────────────────────────────────────────────────
67
68pub use cache::CacheStats;
69pub use config::{ClawConfig, ClawConfigBuilder, JournalMode};
70pub use engine::{ClawEngine, ClawStats, DbStats};
71pub use error::{ClawError, ClawResult};
72pub use journal::{CheckpointMode, CheckpointResult};
73pub use snapshot::{SnapshotManifest, SnapshotMeta, Snapshotter};
74pub use store::memory::{ListOptions, MemoryRecord, MemoryType};
75pub use store::session_lifecycle::Session;
76pub use store::tool_output::ToolOutputRecord as ToolOutput;
77pub use transaction::{CacheOp, CacheRecord, ClawTransaction, StagedOp};
78
79/// The claw-core prelude — import this for the most commonly used types.
80///
81/// ```rust,no_run
82/// use claw_core::prelude::*;
83/// ```
84pub mod prelude {
85    pub use crate::{ClawConfig, ClawEngine, ClawError, ClawResult, MemoryRecord, MemoryType};
86}