use std::process;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use agentmem::cli::output::{
print_error, print_field, print_heading, print_info, print_success,
};
use agentmem::config::{resolve_local_config_path, Config};
use agentmem::store::Store;
const IDLE_INTERVAL: Duration = Duration::from_secs(5);
fn main() {
let code = match run() {
Ok(()) => 0,
Err(error) => {
print_error(&error);
1
}
};
process::exit(code);
}
fn run() -> agentmem::Result<()> {
print_heading("agentmemd");
print_info("starting local daemon");
let config_path = resolve_local_config_path()?;
let config = Config::load(&config_path)?;
let store = Store::open_locked(config)?;
let info = store.info();
print_success("store opened");
print_field("Project", info.project_name.as_str());
print_field("Path", &info.path.to_string());
print_field("Entries", &store.len().to_string());
let running = Arc::new(AtomicBool::new(true));
while running.load(Ordering::Relaxed) {
thread::sleep(IDLE_INTERVAL);
}
Ok(())
}