use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SyncMode {
ReadThrough,
WriteThrough,
Mirror,
}
impl SyncMode {
pub fn as_str(&self) -> &'static str {
match self {
SyncMode::ReadThrough => "read_through",
SyncMode::WriteThrough => "write_through",
SyncMode::Mirror => "mirror",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CmaTreeRoot {
pub root: PathBuf,
pub namespace: String,
pub sync: SyncMode,
}
impl CmaTreeRoot {
pub fn new(root: PathBuf, namespace: impl Into<String>, sync: SyncMode) -> Self {
Self {
root,
namespace: namespace.into(),
sync,
}
}
pub fn memory_dir(&self) -> PathBuf {
self.root.join(".memory")
}
pub fn audit_log(&self) -> PathBuf {
self.root.join("audit.jsonl")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn paths_are_relative_to_root() {
let r = CmaTreeRoot::new(
PathBuf::from("/tmp/agent"),
"primary",
SyncMode::WriteThrough,
);
assert_eq!(r.memory_dir(), PathBuf::from("/tmp/agent/.memory"));
assert_eq!(r.audit_log(), PathBuf::from("/tmp/agent/audit.jsonl"));
}
#[test]
fn sync_mode_strings_are_stable() {
for m in [
SyncMode::ReadThrough,
SyncMode::WriteThrough,
SyncMode::Mirror,
] {
assert!(!m.as_str().is_empty());
}
}
}