use crate::core::policy::PolicyConfig;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub version: String,
pub schema_version: String,
pub settings: Settings,
#[serde(default)]
pub policy: PolicyConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Settings {
pub capture_diffs: bool,
pub max_diff_size_kb: usize,
pub ignore_patterns: Vec<String>,
pub auto_watch: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
version: env!("CARGO_PKG_VERSION").to_string(),
schema_version: "1.0".to_string(),
settings: Settings::default(),
policy: PolicyConfig::default(),
}
}
}
impl Default for Settings {
fn default() -> Self {
Self {
capture_diffs: true,
max_diff_size_kb: 100,
ignore_patterns: vec![
".git".to_string(),
"node_modules".to_string(),
"target".to_string(),
".agentlog".to_string(),
],
auto_watch: false,
}
}
}
impl Config {
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
let content = std::fs::read_to_string(path)?;
let config: Config = serde_json::from_str(&content)?;
Ok(config)
}
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()> {
let content = serde_json::to_string_pretty(self)?;
std::fs::write(path, content)?;
Ok(())
}
}