forked from kent/consciousness
82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
// 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 crate::hippocampus as memory;
|
|
use crate::store;
|
|
|
|
pub fn cmd_cap_degree(max_deg: usize) -> Result<(), String> {
|
|
let mut store = store::Store::load()?;
|
|
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<(), String> {
|
|
if apply { super::check_dry_run(); }
|
|
let result = memory::graph_normalize_strengths(None, Some(apply)).await
|
|
.map_err(|e| e.to_string())?;
|
|
print!("{}", result);
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_link(key: &[String]) -> Result<(), String> {
|
|
if key.is_empty() {
|
|
return Err("link requires a key".into());
|
|
}
|
|
let key = key.join(" ");
|
|
let links = memory::memory_links(None, &key).await
|
|
.map_err(|e| e.to_string())?;
|
|
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<(), String> {
|
|
super::check_dry_run();
|
|
let result = memory::memory_link_add(None, source, target).await
|
|
.map_err(|e| e.to_string())?;
|
|
println!("{}", result);
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<(), String> {
|
|
super::check_dry_run();
|
|
let result = memory::memory_link_set(None, source, target, strength).await
|
|
.map_err(|e| e.to_string())?;
|
|
println!("{}", result);
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_link_impact(source: &str, target: &str) -> Result<(), String> {
|
|
let result = memory::graph_link_impact(None, source, target).await
|
|
.map_err(|e| e.to_string())?;
|
|
print!("{}", result);
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_trace(key: &[String]) -> Result<(), String> {
|
|
if key.is_empty() {
|
|
return Err("trace requires a key".into());
|
|
}
|
|
let key = key.join(" ");
|
|
let result = memory::graph_trace(None, &key).await
|
|
.map_err(|e| e.to_string())?;
|
|
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<(), String> {
|
|
let result = memory::graph_communities(None, Some(top_n), Some(min_size)).await
|
|
.map_err(|e| e.to_string())?;
|
|
print!("{}", result);
|
|
Ok(())
|
|
}
|