graph: community isolation scoring + sort:isolation query

Add community_isolation() to Graph — computes per-community ratio of
internal vs total edge weight. 1.0 = fully isolated, 0.0 = all edges
external.

New query: sort:isolation — sorts nodes by their community's isolation
score, most isolated first. Useful for aiming organize agents at
poorly-integrated knowledge clusters.

New CLI: poc-memory graph communities [N] [--min-size M] — lists
communities sorted by isolation with member preview. Reveals islands
like the Shannon theory cluster (3 nodes, 100% isolated, 0 cross-edges)
and large agent-journal clusters (20-30 nodes, 95% isolated).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kent Overstreet 2026-03-20 12:55:14 -04:00
parent d0f126b709
commit e6613f97bb
4 changed files with 141 additions and 0 deletions

View file

@ -391,6 +391,15 @@ enum GraphCmd {
#[arg(long, default_value_t = 0.4)]
threshold: f32,
},
/// Show communities sorted by isolation (most isolated first)
Communities {
/// Number of communities to show
#[arg(default_value_t = 20)]
top_n: usize,
/// Minimum community size to show
#[arg(long, default_value_t = 2)]
min_size: usize,
},
/// Show graph structure overview
Overview,
/// Spectral decomposition of the memory graph
@ -817,6 +826,7 @@ fn main() {
=> cli::graph::cmd_differentiate(key.as_deref(), apply),
GraphCmd::Trace { key } => cli::graph::cmd_trace(&key),
GraphCmd::Interference { threshold } => cli::graph::cmd_interference(threshold),
GraphCmd::Communities { top_n, min_size } => cli::graph::cmd_communities(top_n, min_size),
GraphCmd::Overview => cli::graph::cmd_graph(),
GraphCmd::Spectral { k } => cli::graph::cmd_spectral(k),
GraphCmd::SpectralSave { k } => cli::graph::cmd_spectral_save(k),