pub mod config;
pub mod db;
pub mod diff_engine;
pub mod file_watcher;
pub mod policy;
pub mod process_wrapper;
pub mod session_capture;
pub mod snapshot;
use anyhow::Result;
use std::path::{Path, PathBuf};
pub const AGENTLOG_DIR: &str = ".agentlog";
pub const DB_FILE: &str = "events.db";
pub fn find_project_root() -> Result<PathBuf> {
let current_dir = std::env::current_dir()?;
if current_dir.join(AGENTLOG_DIR).exists() {
return Ok(current_dir);
}
for ancestor in current_dir.ancestors().skip(1) {
if ancestor.join(AGENTLOG_DIR).exists() {
return Ok(ancestor.to_path_buf());
}
}
Err(anyhow::anyhow!(
"Not an agentlog project. Run 'agentlog init' first."
))
}
pub fn agentlog_path(root: &Path) -> PathBuf {
root.join(AGENTLOG_DIR)
}
pub fn db_path(root: &Path) -> PathBuf {
agentlog_path(root).join(DB_FILE)
}
pub fn ensure_initialized() -> Result<PathBuf> {
match find_project_root() {
Ok(root) => Ok(root),
Err(_) => Err(anyhow::anyhow!(
"AgentLog is not initialized. Run 'agentlog init' to set up."
)),
}
}