hygiea 0.1.0

Dev tool proxy for Claude skills — wraps java, mvn, find and more
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Config {
    // Add fields here as needed
}

/// Return the path to `~/.config/hygiea/config.json`.
pub fn config_path() -> PathBuf {
    dirs_next().join("config.json")
}

fn dirs_next() -> PathBuf {
    let base = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
    PathBuf::from(base).join(".config/hygiea")
}

/// Load config from disk. Returns `Default` if the file does not exist yet.
pub fn load() -> Result<Config> {
    let path = config_path();
    if !path.exists() {
        return Ok(Config::default());
    }
    let content = std::fs::read_to_string(&path)
        .with_context(|| format!("cannot read {}", path.display()))?;
    serde_json::from_str(&content)
        .with_context(|| format!("invalid JSON in {}", path.display()))
}

/// Persist config to `~/.config/hygiea/config.json`, creating the directory if needed.
pub fn save(cfg: &Config) -> Result<()> {
    let path = config_path();
    let dir = path.parent().with_context(|| format!("invalid config path: {}", path.display()))?;
    std::fs::create_dir_all(dir)
        .with_context(|| format!("cannot create {}", dir.display()))?;
    let json = serde_json::to_string_pretty(cfg)?;
    std::fs::write(&path, json)
        .with_context(|| format!("cannot write {}", path.display()))
}