callisto-graph 0.3.1

Dependency graph, cascade, aggregation, and config resolution for callisto.
Documentation
use callisto_model::{CommandRunner, InitReport, SCHEMA_VERSION};

use crate::error::GraphError;
use crate::resolver::DependencyResolver;
use crate::Workspace;

#[derive(Clone, Debug, Default)]
pub struct InitOptions {
    pub yes: bool,
}

pub fn init<R: CommandRunner, D: DependencyResolver>(
    ws: &Workspace<'_, R, D>,
    opts: &InitOptions,
) -> Result<InitReport, GraphError> {
    let _yes = opts.yes;
    let config_path = ws.root.join("callisto.toml");
    let mut written = false;

    if !config_path.exists() {
        let content = r#"# callisto configuration

[changesets]
dir = ".changeset"

[cascade]
mode = "out-of-range"
bump-severity = "patch"
peer-escalation = true
preserve-npm-ranges = true
"#;
        callisto_manifests::atomic::atomic_write(&config_path, content).map_err(|e| {
            GraphError::Command(callisto_model::CommandError::Io {
                program: "fs".to_string(),
                message: e.to_string(),
            })
        })?;
        written = true;
    }

    let cs_dir = ws.root.join(".changeset");
    if !cs_dir.exists() {
        std::fs::create_dir_all(&cs_dir).map_err(|e| {
            GraphError::Command(callisto_model::CommandError::Io {
                program: "fs".to_string(),
                message: e.to_string(),
            })
        })?;
    }
    let readme_path = cs_dir.join("README.md");
    if !readme_path.exists() {
        let readme_content = r#"# Changesets

This directory contains markdown changeset files generated by Callisto CLI (`callisto add`).
Each changeset describes a package version bump and associated release summary.
"#;
        callisto_manifests::atomic::atomic_write(&readme_path, readme_content).map_err(|e| {
            GraphError::Command(callisto_model::CommandError::Io {
                program: "fs".to_string(),
                message: e.to_string(),
            })
        })?;
    }

    Ok(InitReport {
        schema_version: SCHEMA_VERSION,
        initialized: written,
        config_path,
        diagnostics: Vec::new(),
    })
}