kodegraf-cli 0.1.0

Structural code intelligence for AI coding assistants — CLI
use anyhow::Result;
use kodegraf_core::build::get_changed_files;
use kodegraf_core::config::Config;
use kodegraf_core::graph::GraphStore;

pub fn run() -> Result<()> {
    let repo_root = kodegraf_core::config::find_repo_root()?;
    let db_path = Config::graph_db_path(&repo_root);

    if !db_path.exists() {
        anyhow::bail!("Graph not built. Run `kodegraf init && kodegraf build` first.");
    }

    let store = GraphStore::open(&db_path)?;

    // Get changed files from git
    let changed = get_changed_files(&repo_root, "HEAD")?;

    if changed.is_empty() {
        println!("No changes detected since HEAD.");
        return Ok(());
    }

    println!("Changed files:");
    for f in &changed {
        println!("  * {}", f);
    }
    println!();

    let result = store.get_impact_radius(&changed, 2, 500)?;

    println!("Blast radius:");
    println!("  Changed nodes:  {}", result.changed_nodes.len());
    println!("  Impacted nodes: {}", result.total_impacted);
    println!("  Impacted files: {}", result.impacted_files.len());
    if result.truncated {
        println!("  (results truncated at 500 nodes)");
    }

    if !result.impacted_files.is_empty() {
        println!();
        println!("Impacted files:");
        for f in &result.impacted_files {
            println!("{}", f);
        }
    }

    Ok(())
}