#![forbid(unsafe_code)]
#![warn(missing_docs)]
mod cache;
mod crypto;
mod embed;
mod embed_cmd;
mod error;
mod format;
mod index;
pub mod mcp;
mod memory;
mod pager;
mod result_cache;
mod session;
mod store;
mod wal;
pub use crypto::KdfParams;
pub use embed::{Embedder, EmbedderIdentity};
pub use embed_cmd::{EmbedCmd, DEFAULT_EMBED_TIMEOUT};
pub use error::{MnemoError, Result};
pub use index::{IndexConfig, IndexInfo};
pub use memory::{Memory, MemoryType, Metric, Scope, ScoreWeights};
pub use result_cache::{
CacheBudget, CacheFlushPolicy, CachePutOpts, CacheStats, CachedValue, SemanticCachePutOpts,
DEFAULT_BATCH_MAX_AGE, DEFAULT_BATCH_MAX_DIRTY, DEFAULT_MAX_BYTES, DEFAULT_MAX_ENTRIES,
DEFAULT_SEMANTIC_THRESHOLD,
};
pub use session::{Role, Session, Turn};
pub use store::{
CompactReport, Mnemo, MnemoConfig, RecallRequest, RecallResult, SnapshotInfo, Stats,
};
pub use ulid::Ulid;
mod fsync_counter {
use std::cell::Cell;
thread_local! {
static COUNT: Cell<u64> = const { Cell::new(0) };
}
pub(crate) fn bump() {
COUNT.with(|c| c.set(c.get().wrapping_add(1)));
}
pub(crate) fn count() -> u64 {
COUNT.with(|c| c.get())
}
}
pub(crate) use fsync_counter::{bump as bump_fsync, count as fsync_count};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BuildInfo {
pub version: &'static str,
pub target: &'static str,
pub aes_backend: &'static str,
pub polyval_backend: &'static str,
}
pub fn build_info() -> BuildInfo {
BuildInfo {
version: env!("CARGO_PKG_VERSION"),
target: TARGET_TRIPLE,
aes_backend: aes_backend_name(),
polyval_backend: polyval_backend_name(),
}
}
const TARGET_TRIPLE: &str = {
if cfg!(all(target_arch = "aarch64", target_os = "macos")) {
"aarch64-apple-darwin"
} else if cfg!(all(target_arch = "aarch64", target_os = "linux")) {
"aarch64-unknown-linux-gnu"
} else if cfg!(all(target_arch = "x86_64", target_os = "macos")) {
"x86_64-apple-darwin"
} else if cfg!(all(target_arch = "x86_64", target_os = "linux")) {
"x86_64-unknown-linux-gnu"
} else if cfg!(all(target_arch = "x86_64", target_os = "windows")) {
"x86_64-pc-windows-msvc"
} else {
"unknown"
}
};
const fn aes_backend_name() -> &'static str {
if cfg!(aes_armv8) {
"armv8 hardware"
} else if cfg!(target_arch = "aarch64") {
"armv8 software (constant-time fallback)"
} else if cfg!(target_arch = "x86_64") {
"x86_64 AES-NI (runtime detect)"
} else {
"portable software"
}
}
const fn polyval_backend_name() -> &'static str {
if cfg!(polyval_armv8) {
"armv8 PMULL hardware"
} else if cfg!(target_arch = "aarch64") {
"armv8 software (constant-time fallback)"
} else if cfg!(target_arch = "x86_64") {
"x86_64 CLMUL (runtime detect)"
} else {
"portable software"
}
}
#[cfg(any(test, feature = "failpoints"))]
#[doc(hidden)]
pub mod __failpoints {
pub fn set_writes_until_fail(n: i64) {
crate::pager::failpoints::set_writes_until_fail(n)
}
}
#[doc(hidden)]
pub mod __fuzz {
pub fn parse_header(bytes: &[u8]) -> crate::Result<()> {
crate::format::Header::from_page(bytes).map(|_| ())
}
pub fn wal_recover_bytes(region: &[u8], wal_seq: u64) -> crate::Result<()> {
crate::wal::recover_bytes(region, wal_seq).map(|_| ())
}
pub fn decode_memory(bytes: &[u8]) -> crate::Result<()> {
rmp_serde::from_slice::<crate::Memory>(bytes)
.map(|_| ())
.map_err(|e| crate::MnemoError::Serialize(e.to_string()))
}
pub fn decode_cache_entry(bytes: &[u8]) -> crate::Result<()> {
rmp_serde::from_slice::<crate::result_cache::CacheEntry>(bytes)
.map(|_| ())
.map_err(|e| crate::MnemoError::Serialize(e.to_string()))
}
pub fn decode_cache_directory(bytes: &[u8]) -> crate::Result<()> {
rmp_serde::from_slice::<Vec<crate::result_cache::CacheDirectoryEntry>>(bytes)
.map(|_| ())
.map_err(|e| crate::MnemoError::Serialize(e.to_string()))
}
pub fn parse_mcp_request_line(line: &str) -> Result<(), String> {
crate::mcp::__fuzz_parse_request_line(line)
}
}