cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
// cli/graph.rs — graph subcommand handlers
|
|
|
|
|
//
|
|
|
|
|
// Extracted from main.rs. All graph-related CLI commands:
|
Delete similarity module, rewrite module, and all text-similarity code
Text cosine similarity was being used as a crutch for operations
the graph structure should handle: interference detection, orphan
linking, triangle closing, hub differentiation. These are all
graph-structural operations that the agents (linker, extractor)
handle with actual semantic understanding.
Removed: similarity.rs (stemming + cosine), rewrite.rs (orphan
linking, triangle closing, hub differentiation), detect_interference,
and all CLI commands and consolidation steps that used them.
-794 lines.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-10 15:44:10 -04:00
|
|
|
// link, link-add, link-impact, link-audit, cap-degree,
|
|
|
|
|
// normalize-strengths, trace, spectral-*, organize, communities.
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
|
2026-04-13 17:44:33 -04:00
|
|
|
use crate::hippocampus as memory;
|
2026-04-12 23:19:28 -04:00
|
|
|
use crate::store;
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
|
|
|
|
|
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(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
pub async fn cmd_normalize_strengths(apply: bool) -> Result<(), String> {
|
2026-04-12 23:12:42 -04:00
|
|
|
if apply { super::check_dry_run(); }
|
2026-04-13 13:26:22 -04:00
|
|
|
let result = memory::graph_normalize_strengths(None, Some(apply)).await
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
2026-04-12 23:12:42 -04:00
|
|
|
print!("{}", result);
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
pub async fn cmd_link(key: &[String]) -> Result<(), String> {
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
if key.is_empty() {
|
|
|
|
|
return Err("link requires a key".into());
|
|
|
|
|
}
|
|
|
|
|
let key = key.join(" ");
|
2026-04-13 15:12:06 -04:00
|
|
|
let links = memory::memory_links(None, &key).await
|
2026-04-13 13:26:22 -04:00
|
|
|
.map_err(|e| e.to_string())?;
|
2026-04-13 15:12:06 -04:00
|
|
|
println!("Neighbors of '{}':", key);
|
|
|
|
|
for link in links {
|
|
|
|
|
println!(" ({:.2}) {} [w={:.2}]", link.link_strength, link.key, link.node_weight);
|
|
|
|
|
}
|
2026-04-12 23:07:06 -04:00
|
|
|
Ok(())
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
pub async fn cmd_link_add(source: &str, target: &str, _reason: &[String]) -> Result<(), String> {
|
poc-memory: POC_MEMORY_DRY_RUN=1 for agent testing
All mutating commands (write, delete, rename, link-add, journal write,
used, wrong, not-useful, gap) check POC_MEMORY_DRY_RUN after argument
validation but before mutation. If set, process exits silently — agent
tool calls are visible in the LLM output so we can see what it tried
to do without applying changes.
Read commands (render, search, graph link, journal tail) work normally
in dry-run mode so agents can still explore the graph.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 18:09:56 -04:00
|
|
|
super::check_dry_run();
|
2026-04-13 13:26:22 -04:00
|
|
|
let result = memory::memory_link_add(None, source, target).await
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
2026-04-12 21:54:34 -04:00
|
|
|
println!("{}", result);
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
pub async fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<(), String> {
|
2026-03-17 01:39:41 -04:00
|
|
|
super::check_dry_run();
|
2026-04-13 13:26:22 -04:00
|
|
|
let result = memory::memory_link_set(None, source, target, strength).await
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
2026-04-12 21:54:34 -04:00
|
|
|
println!("{}", result);
|
2026-03-17 01:39:41 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
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())?;
|
2026-04-12 23:16:12 -04:00
|
|
|
print!("{}", result);
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:26:22 -04:00
|
|
|
pub async fn cmd_trace(key: &[String]) -> Result<(), String> {
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
if key.is_empty() {
|
|
|
|
|
return Err("trace requires a key".into());
|
|
|
|
|
}
|
|
|
|
|
let key = key.join(" ");
|
2026-04-13 13:26:22 -04:00
|
|
|
let result = memory::graph_trace(None, &key).await
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
2026-04-12 23:16:12 -04:00
|
|
|
print!("{}", result);
|
cli: extract graph commands from main.rs into cli/graph.rs
Move 18 graph subcommand handlers (594 lines) out of main.rs:
link, link-add, link-impact, link-audit, link-orphans,
triangle-close, cap-degree, normalize-strengths, differentiate,
trace, spectral-*, organize, interference.
main.rs: 3130 → 2518 lines.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-14 17:59:46 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:55:14 -04:00
|
|
|
/// Show communities sorted by isolation (most isolated first).
|
|
|
|
|
/// Useful for finding poorly-integrated knowledge clusters that need
|
|
|
|
|
/// organize agents aimed at them.
|
2026-04-13 13:26:22 -04:00
|
|
|
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())?;
|
2026-04-12 23:09:12 -04:00
|
|
|
print!("{}", result);
|
2026-03-20 12:55:14 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|