defs.rs: convert organize placeholder to use RPC
Uses memory_render RPC instead of direct store access. Simplifies from ~60 to ~20 lines. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
4cfeb9ee2f
commit
c688b812ef
1 changed files with 9 additions and 47 deletions
|
|
@ -235,62 +235,24 @@ fn resolve(
|
||||||
}
|
}
|
||||||
|
|
||||||
"organize" => {
|
"organize" => {
|
||||||
// Show seed nodes with their neighbors for exploratory organizing
|
// Show seed nodes with content and links via RPC
|
||||||
use crate::store::NodeType;
|
|
||||||
|
|
||||||
// Helper: shell-quote keys containing #
|
|
||||||
let sq = |k: &str| -> String {
|
|
||||||
if k.contains('#') { format!("'{}'", k) } else { k.to_string() }
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut text = format!("### Seed nodes ({} starting points)\n\n", keys.len());
|
let mut text = format!("### Seed nodes ({} starting points)\n\n", keys.len());
|
||||||
let mut result_keys = Vec::new();
|
let mut result_keys = Vec::new();
|
||||||
|
|
||||||
for key in keys {
|
for key in keys {
|
||||||
let Some(node) = store.nodes.get(key) else { continue };
|
match crate::mcp_server::memory_rpc(
|
||||||
if node.deleted { continue; }
|
"memory_render",
|
||||||
|
serde_json::json!({"key": key}),
|
||||||
let is_journal = node.node_type == NodeType::EpisodicSession;
|
) {
|
||||||
let tag = if is_journal { " [JOURNAL — no delete]" } else { "" };
|
Ok(content) if !content.trim().is_empty() => {
|
||||||
let words = node.content.split_whitespace().count();
|
text.push_str(&format!("#### {}\n\n{}\n\n---\n\n", key, content));
|
||||||
|
result_keys.push(key.clone());
|
||||||
text.push_str(&format!("#### {}{} ({} words)\n\n", sq(key), tag, words));
|
|
||||||
|
|
||||||
// Show first ~200 words of content as preview
|
|
||||||
let preview: String = node.content.split_whitespace()
|
|
||||||
.take(200).collect::<Vec<_>>().join(" ");
|
|
||||||
if words > 200 {
|
|
||||||
text.push_str(&format!("{}...\n\n", preview));
|
|
||||||
} else {
|
|
||||||
text.push_str(&format!("{}\n\n", node.content));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show neighbors with strengths
|
|
||||||
let neighbors = graph.neighbors(key);
|
|
||||||
if !neighbors.is_empty() {
|
|
||||||
text.push_str("**Neighbors:**\n");
|
|
||||||
for (nbr, strength) in neighbors.iter().take(15) {
|
|
||||||
let nbr_type = store.nodes.get(nbr.as_str())
|
|
||||||
.map(|n| match n.node_type {
|
|
||||||
NodeType::EpisodicSession => " [journal]",
|
|
||||||
NodeType::EpisodicDaily => " [daily]",
|
|
||||||
_ => "",
|
|
||||||
})
|
|
||||||
.unwrap_or("");
|
|
||||||
text.push_str(&format!(" [{:.1}] {}{}\n", strength, sq(nbr), nbr_type));
|
|
||||||
}
|
}
|
||||||
if neighbors.len() > 15 {
|
_ => continue,
|
||||||
text.push_str(&format!(" ... and {} more\n", neighbors.len() - 15));
|
|
||||||
}
|
|
||||||
text.push('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text.push_str("---\n\n");
|
|
||||||
result_keys.push(key.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text.push_str("Use memory_render(KEY) and memory_links(KEY) to explore further.\n");
|
text.push_str("Use memory_render(KEY) and memory_links(KEY) to explore further.\n");
|
||||||
|
|
||||||
Some(Resolved { text, keys: result_keys })
|
Some(Resolved { text, keys: result_keys })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue