CLI/hippocampus: rename core memory functions to memory_*

Aligns function names with tool names for consistency:
- hippocampus: render → memory_render, write → memory_write, etc.
- tools/memory.rs: macro no longer prepends memory_ prefix
- CLI files: use typed async API throughout (graph.rs, journal.rs, admin.rs)

This eliminates the "memory_graph_topology" tool name bug where
graph_* and journal_* tools were incorrectly prefixed.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-13 13:26:22 -04:00
parent fa50f1c826
commit 5b07a81aa7
7 changed files with 106 additions and 130 deletions

View file

@ -328,20 +328,18 @@ pub fn cmd_dedup(apply: bool) -> Result<(), String> {
Ok(())
}
pub fn cmd_health() -> Result<(), String> {
let result = crate::mcp_server::memory_rpc(
"graph_health",
serde_json::json!({}),
).map_err(|e| e.to_string())?;
pub async fn cmd_health() -> Result<(), String> {
use crate::agent::tools::memory;
let result = memory::graph_health(None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
pub fn cmd_topology() -> Result<(), String> {
let result = crate::mcp_server::memory_rpc(
"graph_topology",
serde_json::json!({}),
).map_err(|e| e.to_string())?;
pub async fn cmd_topology() -> Result<(), String> {
use crate::agent::tools::memory;
let result = memory::graph_topology(None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
@ -422,11 +420,10 @@ pub fn cmd_export(files: &[String], export_all: bool) -> Result<(), String> {
Ok(())
}
pub fn cmd_status() -> Result<(), String> {
let result = crate::mcp_server::memory_rpc(
"graph_topology",
serde_json::json!({}),
).map_err(|e| e.to_string())?;
pub async fn cmd_status() -> Result<(), String> {
use crate::agent::tools::memory;
let result = memory::graph_topology(None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}

View file

@ -4,6 +4,7 @@
// link, link-add, link-impact, link-audit, cap-degree,
// normalize-strengths, trace, spectral-*, organize, communities.
use crate::agent::tools::memory;
use crate::store;
pub fn cmd_cap_degree(max_deg: usize) -> Result<(), String> {
@ -14,67 +15,55 @@ pub fn cmd_cap_degree(max_deg: usize) -> Result<(), String> {
Ok(())
}
pub fn cmd_normalize_strengths(apply: bool) -> Result<(), String> {
pub async fn cmd_normalize_strengths(apply: bool) -> Result<(), String> {
if apply { super::check_dry_run(); }
let result = crate::mcp_server::memory_rpc(
"graph_normalize_strengths",
serde_json::json!({"apply": apply}),
).map_err(|e| e.to_string())?;
let result = memory::graph_normalize_strengths(None, Some(apply)).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
pub fn cmd_link(key: &[String]) -> Result<(), String> {
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 result = crate::mcp_server::memory_rpc(
"memory_links",
serde_json::json!({"key": key}),
).map_err(|e| e.to_string())?;
let result = memory::memory_links(None, &key).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
pub fn cmd_link_add(source: &str, target: &str, _reason: &[String]) -> Result<(), String> {
pub async fn cmd_link_add(source: &str, target: &str, _reason: &[String]) -> Result<(), String> {
super::check_dry_run();
let result = crate::mcp_server::memory_rpc(
"memory_link_add",
serde_json::json!({"source": source, "target": target}),
).map_err(|e| e.to_string())?;
let result = memory::memory_link_add(None, source, target).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
}
pub fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<(), String> {
pub async fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<(), String> {
super::check_dry_run();
let result = crate::mcp_server::memory_rpc(
"memory_link_set",
serde_json::json!({"source": source, "target": target, "strength": strength}),
).map_err(|e| e.to_string())?;
let result = memory::memory_link_set(None, source, target, strength).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
}
pub fn cmd_link_impact(source: &str, target: &str) -> Result<(), String> {
let result = crate::mcp_server::memory_rpc(
"graph_link_impact",
serde_json::json!({"source": source, "target": target}),
).map_err(|e| e.to_string())?;
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 fn cmd_trace(key: &[String]) -> Result<(), String> {
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 = crate::mcp_server::memory_rpc(
"graph_trace",
serde_json::json!({"key": key}),
).map_err(|e| e.to_string())?;
let result = memory::graph_trace(None, &key).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
@ -82,11 +71,9 @@ pub fn cmd_trace(key: &[String]) -> Result<(), String> {
/// Show communities sorted by isolation (most isolated first).
/// Useful for finding poorly-integrated knowledge clusters that need
/// organize agents aimed at them.
pub fn cmd_communities(top_n: usize, min_size: usize) -> Result<(), String> {
let result = crate::mcp_server::memory_rpc(
"graph_communities",
serde_json::json!({"top_n": top_n, "min_size": min_size}),
).map_err(|e| e.to_string())?;
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(())
}

View file

@ -1,5 +1,6 @@
// cli/journal.rs — journal subcommand handlers
use crate::agent::tools::memory;
pub fn cmd_tail(n: usize, full: bool, provenance: Option<&str>, dedup: bool) -> Result<(), String> {
let path = crate::store::nodes_path();
@ -66,32 +67,23 @@ pub fn cmd_tail(n: usize, full: bool, provenance: Option<&str>, dedup: bool) ->
Ok(())
}
pub fn cmd_journal_tail(n: usize, full: bool, level: u8) -> Result<(), String> {
let format = if full { "full" } else { "compact" };
let result = crate::mcp_server::memory_rpc(
"journal_tail",
serde_json::json!({"count": n, "level": level, "format": format}),
).map_err(|e| e.to_string())?;
pub async fn cmd_journal_tail(n: usize, full: bool, level: u8) -> Result<(), String> {
let format = if full { Some("full") } else { Some("compact") };
let result = memory::journal_tail(None, Some(n as u64), Some(level as u64), format, None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
}
pub fn cmd_journal_write(name: &str, text: &[String]) -> Result<(), String> {
pub async fn cmd_journal_write(name: &str, text: &[String]) -> Result<(), String> {
if text.is_empty() {
return Err("journal write requires text".into());
}
super::check_dry_run();
let body = text.join(" ");
let result = crate::mcp_server::memory_rpc(
"journal_new",
serde_json::json!({
"name": name,
"title": name,
"body": body,
"level": 0
}),
).map_err(|e| e.to_string())?;
let result = memory::journal_new(None, name, name, &body, Some(0)).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
}

View file

@ -8,7 +8,7 @@ use crate::store;
pub async fn cmd_weight_set(key: &str, weight: f32) -> Result<(), String> {
super::check_dry_run();
let result = memory::weight_set(None, key, weight).await
let result = memory::memory_weight_set(None, key, weight).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
@ -20,7 +20,7 @@ pub async fn cmd_node_delete(key: &[String]) -> Result<(), String> {
}
super::check_dry_run();
let key = key.join(" ");
let result = memory::delete(None, &key).await
let result = memory::memory_delete(None, &key).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
@ -28,7 +28,7 @@ pub async fn cmd_node_delete(key: &[String]) -> Result<(), String> {
pub async fn cmd_node_rename(old_key: &str, new_key: &str) -> Result<(), String> {
super::check_dry_run();
let result = memory::rename(None, old_key, new_key).await
let result = memory::memory_rename(None, old_key, new_key).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
@ -41,7 +41,7 @@ pub async fn cmd_render(key: &[String]) -> Result<(), String> {
let key = key.join(" ");
let bare = store::strip_md_suffix(&key);
let rendered = memory::render(None, &bare, None).await
let rendered = memory::memory_render(None, &bare, None).await
.map_err(|e| e.to_string())?;
print!("{}", rendered);
@ -71,7 +71,7 @@ pub async fn cmd_history(key: &[String], full: bool) -> Result<(), String> {
return Err("history requires a key".into());
}
let key = key.join(" ");
let result = memory::history(None, &key, Some(full)).await
let result = memory::memory_history(None, &key, Some(full)).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
@ -91,7 +91,7 @@ pub async fn cmd_write(key: &[String]) -> Result<(), String> {
}
super::check_dry_run();
let result = memory::write(None, &key, &content).await
let result = memory::memory_write(None, &key, &content).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
@ -104,7 +104,7 @@ pub async fn cmd_edit(key: &[String]) -> Result<(), String> {
let key = key.join(" ");
// Get raw content
let content = memory::render(None, &key, Some(true)).await
let content = memory::memory_render(None, &key, Some(true)).await
.unwrap_or_default();
let tmp = std::env::temp_dir().join(format!("poc-memory-edit-{}.md", key.replace('/', "_")));
@ -136,7 +136,7 @@ pub async fn cmd_edit(key: &[String]) -> Result<(), String> {
}
super::check_dry_run();
let result = memory::write(None, &key, &new_content).await
let result = memory::memory_write(None, &key, &new_content).await
.map_err(|e| e.to_string())?;
println!("{}", result);
Ok(())
@ -146,7 +146,7 @@ pub async fn cmd_search(keys: &[String]) -> Result<(), String> {
if keys.is_empty() {
return Err("search requires seed keys".into());
}
let result = memory::search(None, keys.to_vec(), None, None, None, None).await
let result = memory::memory_search(None, keys.to_vec(), None, None, None, None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
@ -158,7 +158,7 @@ pub async fn cmd_query(expr: &[String]) -> Result<(), String> {
}
let query_str = expr.join(" ");
let result = memory::query(None, &query_str, None).await
let result = memory::memory_query(None, &query_str, None).await
.map_err(|e| e.to_string())?;
print!("{}", result);
Ok(())
@ -173,7 +173,7 @@ pub async fn get_group_content(group: &crate::config::ContextGroup, cfg: &crate:
let query = format!("all | type:episodic | age:<{} | sort:timestamp | limit:{}",
window, cfg.journal_max);
let keys_str = match memory::query(None, &query, None).await {
let keys_str = match memory::memory_query(None, &query, None).await {
Ok(s) => s,
Err(_) => return vec![],
};
@ -181,7 +181,7 @@ pub async fn get_group_content(group: &crate::config::ContextGroup, cfg: &crate:
// Parse keys (one per line) and render each
let mut results = Vec::new();
for key in keys_str.lines().filter(|k| !k.is_empty() && *k != "no results") {
if let Ok(content) = memory::render(None, key, Some(true)).await {
if let Ok(content) = memory::memory_render(None, key, Some(true)).await {
if !content.trim().is_empty() {
results.push((key.to_string(), content));
}
@ -199,7 +199,7 @@ pub async fn get_group_content(group: &crate::config::ContextGroup, cfg: &crate:
crate::config::ContextSource::Store => {
let mut results = Vec::new();
for key in &group.keys {
if let Ok(content) = memory::render(None, key, Some(true)).await {
if let Ok(content) = memory::memory_render(None, key, Some(true)).await {
if !content.trim().is_empty() {
results.push((key.clone(), content.trim().to_string()));
}