// cli/graph.rs — graph subcommand handlers // // Extracted from main.rs. All graph-related CLI commands: // link, link-add, link-impact, link-audit, cap-degree, // normalize-strengths, trace, spectral-*, organize, communities. use anyhow::{bail, Result}; use crate::hippocampus as memory; pub async fn cmd_cap_degree(max_deg: usize) -> Result<()> { let arc = memory::access_local()?; let mut store = arc.lock().await; let (hubs, pruned) = store.cap_degree(max_deg)?; store.save()?; println!("Capped {} hubs, pruned {} weak Auto edges (max_degree={})", hubs, pruned, max_deg); Ok(()) } pub async fn cmd_normalize_strengths(apply: bool) -> Result<()> { if apply { super::check_dry_run(); } let result = memory::graph_normalize_strengths(None, Some(apply)).await?; print!("{}", result); Ok(()) } pub async fn cmd_link(key: &[String]) -> Result<()> { if key.is_empty() { bail!("link requires a key"); } let key = key.join(" "); let links = memory::memory_links(None, &key).await?; println!("Neighbors of '{}':", key); for link in links { println!(" ({:.2}) {} [w={:.2}]", link.link_strength, link.key, link.node_weight); } Ok(()) } pub async fn cmd_link_add(source: &str, target: &str, _reason: &[String]) -> Result<()> { super::check_dry_run(); let result = memory::memory_link_add(None, source, target).await?; println!("{}", result); Ok(()) } pub async fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<()> { super::check_dry_run(); let result = memory::memory_link_set(None, source, target, strength).await?; println!("{}", result); Ok(()) } pub async fn cmd_link_impact(source: &str, target: &str) -> Result<()> { let result = memory::graph_link_impact(None, source, target).await?; print!("{}", result); Ok(()) } pub async fn cmd_trace(key: &[String]) -> Result<()> { if key.is_empty() { bail!("trace requires a key"); } let key = key.join(" "); let result = memory::graph_trace(None, &key).await?; print!("{}", result); Ok(()) } /// Show communities sorted by isolation (most isolated first). /// Useful for finding poorly-integrated knowledge clusters that need /// organize agents aimed at them. pub async fn cmd_communities(top_n: usize, min_size: usize) -> Result<()> { let result = memory::graph_communities(None, Some(top_n), Some(min_size)).await?; print!("{}", result); Ok(()) }