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:
parent
fa50f1c826
commit
5b07a81aa7
7 changed files with 106 additions and 130 deletions
|
|
@ -179,7 +179,7 @@ macro_rules! memory_tool {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut map = serde_json::Map::new();
|
let mut map = serde_json::Map::new();
|
||||||
$($(memory_tool!(@insert_json map, $arg, $($typ)+);)*)?
|
$($(memory_tool!(@insert_json map, $arg, $($typ)+);)*)?
|
||||||
return crate::mcp_server::memory_rpc(concat!("memory_", stringify!($name)), serde_json::Value::Object(map));
|
return crate::mcp_server::memory_rpc(stringify!($name), serde_json::Value::Object(map));
|
||||||
}
|
}
|
||||||
let prov = match agent {
|
let prov = match agent {
|
||||||
Some(a) => a.state.lock().await.provenance.clone(),
|
Some(a) => a.state.lock().await.provenance.clone(),
|
||||||
|
|
@ -208,7 +208,7 @@ macro_rules! memory_tool {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut map = serde_json::Map::new();
|
let mut map = serde_json::Map::new();
|
||||||
$($(memory_tool!(@insert_json map, $arg, $($typ)+);)*)?
|
$($(memory_tool!(@insert_json map, $arg, $($typ)+);)*)?
|
||||||
return crate::mcp_server::memory_rpc(concat!("memory_", stringify!($name)), serde_json::Value::Object(map));
|
return crate::mcp_server::memory_rpc(stringify!($name), serde_json::Value::Object(map));
|
||||||
}
|
}
|
||||||
let prov = match agent {
|
let prov = match agent {
|
||||||
Some(a) => a.state.lock().await.provenance.clone(),
|
Some(a) => a.state.lock().await.provenance.clone(),
|
||||||
|
|
@ -224,18 +224,18 @@ macro_rules! memory_tool {
|
||||||
|
|
||||||
// ── Memory tools ───────────────────────────────────────────────
|
// ── Memory tools ───────────────────────────────────────────────
|
||||||
|
|
||||||
memory_tool!(render, ref, key: [str], raw: [Option<bool>]);
|
memory_tool!(memory_render, ref, key: [str], raw: [Option<bool>]);
|
||||||
memory_tool!(write, mut, key: [str], content: [str]);
|
memory_tool!(memory_write, mut, key: [str], content: [str]);
|
||||||
memory_tool!(search, ref, keys: [Vec<String>], max_hops: [Option<u32>], edge_decay: [Option<f64>], min_activation: [Option<f64>], limit: [Option<usize>]);
|
memory_tool!(memory_search, ref, keys: [Vec<String>], max_hops: [Option<u32>], edge_decay: [Option<f64>], min_activation: [Option<f64>], limit: [Option<usize>]);
|
||||||
memory_tool!(links, ref, key: [str]);
|
memory_tool!(memory_links, ref, key: [str]);
|
||||||
memory_tool!(link_set, mut, source: [str], target: [str], strength: [f32]);
|
memory_tool!(memory_link_set, mut, source: [str], target: [str], strength: [f32]);
|
||||||
memory_tool!(link_add, mut, source: [str], target: [str]);
|
memory_tool!(memory_link_add, mut, source: [str], target: [str]);
|
||||||
memory_tool!(delete, mut, key: [str]);
|
memory_tool!(memory_delete, mut, key: [str]);
|
||||||
memory_tool!(history, ref, key: [str], full: [Option<bool>]);
|
memory_tool!(memory_history, ref, key: [str], full: [Option<bool>]);
|
||||||
memory_tool!(weight_set, mut, key: [str], weight: [f32]);
|
memory_tool!(memory_weight_set, mut, key: [str], weight: [f32]);
|
||||||
memory_tool!(rename, mut, old_key: [str], new_key: [str]);
|
memory_tool!(memory_rename, mut, old_key: [str], new_key: [str]);
|
||||||
memory_tool!(supersede, mut, old_key: [str], new_key: [str], reason: [Option<&str>]);
|
memory_tool!(memory_supersede, mut, old_key: [str], new_key: [str], reason: [Option<&str>]);
|
||||||
memory_tool!(query, ref, query: [str], format: [Option<&str>]);
|
memory_tool!(memory_query, ref, query: [str], format: [Option<&str>]);
|
||||||
|
|
||||||
// ── Journal tools ──────────────────────────────────────────────
|
// ── Journal tools ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
@ -276,18 +276,18 @@ async fn dispatch(
|
||||||
|
|
||||||
// Daemon path - dispatch to implementation
|
// Daemon path - dispatch to implementation
|
||||||
match tool_name {
|
match tool_name {
|
||||||
"memory_render" => jsonargs_render(&args).await,
|
"memory_render" => jsonargs_memory_render(&args).await,
|
||||||
"memory_write" => jsonargs_write(&args).await,
|
"memory_write" => jsonargs_memory_write(&args).await,
|
||||||
"memory_search" => jsonargs_search(&args).await,
|
"memory_search" => jsonargs_memory_search(&args).await,
|
||||||
"memory_links" => jsonargs_links(&args).await,
|
"memory_links" => jsonargs_memory_links(&args).await,
|
||||||
"memory_link_set" => jsonargs_link_set(&args).await,
|
"memory_link_set" => jsonargs_memory_link_set(&args).await,
|
||||||
"memory_link_add" => jsonargs_link_add(&args).await,
|
"memory_link_add" => jsonargs_memory_link_add(&args).await,
|
||||||
"memory_delete" => jsonargs_delete(&args).await,
|
"memory_delete" => jsonargs_memory_delete(&args).await,
|
||||||
"memory_history" => jsonargs_history(&args).await,
|
"memory_history" => jsonargs_memory_history(&args).await,
|
||||||
"memory_weight_set" => jsonargs_weight_set(&args).await,
|
"memory_weight_set" => jsonargs_memory_weight_set(&args).await,
|
||||||
"memory_rename" => jsonargs_rename(&args).await,
|
"memory_rename" => jsonargs_memory_rename(&args).await,
|
||||||
"memory_supersede" => jsonargs_supersede(&args).await,
|
"memory_supersede" => jsonargs_memory_supersede(&args).await,
|
||||||
"memory_query" => jsonargs_query(&args).await,
|
"memory_query" => jsonargs_memory_query(&args).await,
|
||||||
"graph_topology" => jsonargs_graph_topology(&args).await,
|
"graph_topology" => jsonargs_graph_topology(&args).await,
|
||||||
"graph_health" => jsonargs_graph_health(&args).await,
|
"graph_health" => jsonargs_graph_health(&args).await,
|
||||||
"graph_communities" => jsonargs_graph_communities(&args).await,
|
"graph_communities" => jsonargs_graph_communities(&args).await,
|
||||||
|
|
|
||||||
|
|
@ -328,20 +328,18 @@ pub fn cmd_dedup(apply: bool) -> Result<(), String> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_health() -> Result<(), String> {
|
pub async fn cmd_health() -> Result<(), String> {
|
||||||
let result = crate::mcp_server::memory_rpc(
|
use crate::agent::tools::memory;
|
||||||
"graph_health",
|
let result = memory::graph_health(None).await
|
||||||
serde_json::json!({}),
|
.map_err(|e| e.to_string())?;
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_topology() -> Result<(), String> {
|
pub async fn cmd_topology() -> Result<(), String> {
|
||||||
let result = crate::mcp_server::memory_rpc(
|
use crate::agent::tools::memory;
|
||||||
"graph_topology",
|
let result = memory::graph_topology(None).await
|
||||||
serde_json::json!({}),
|
.map_err(|e| e.to_string())?;
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -422,11 +420,10 @@ pub fn cmd_export(files: &[String], export_all: bool) -> Result<(), String> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_status() -> Result<(), String> {
|
pub async fn cmd_status() -> Result<(), String> {
|
||||||
let result = crate::mcp_server::memory_rpc(
|
use crate::agent::tools::memory;
|
||||||
"graph_topology",
|
let result = memory::graph_topology(None).await
|
||||||
serde_json::json!({}),
|
.map_err(|e| e.to_string())?;
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
// link, link-add, link-impact, link-audit, cap-degree,
|
// link, link-add, link-impact, link-audit, cap-degree,
|
||||||
// normalize-strengths, trace, spectral-*, organize, communities.
|
// normalize-strengths, trace, spectral-*, organize, communities.
|
||||||
|
|
||||||
|
use crate::agent::tools::memory;
|
||||||
use crate::store;
|
use crate::store;
|
||||||
|
|
||||||
pub fn cmd_cap_degree(max_deg: usize) -> Result<(), String> {
|
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(())
|
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(); }
|
if apply { super::check_dry_run(); }
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::graph_normalize_strengths(None, Some(apply)).await
|
||||||
"graph_normalize_strengths",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"apply": apply}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_link(key: &[String]) -> Result<(), String> {
|
pub async fn cmd_link(key: &[String]) -> Result<(), String> {
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
return Err("link requires a key".into());
|
return Err("link requires a key".into());
|
||||||
}
|
}
|
||||||
let key = key.join(" ");
|
let key = key.join(" ");
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::memory_links(None, &key).await
|
||||||
"memory_links",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"key": key}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
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();
|
super::check_dry_run();
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::memory_link_add(None, source, target).await
|
||||||
"memory_link_add",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"source": source, "target": target}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
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();
|
super::check_dry_run();
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::memory_link_set(None, source, target, strength).await
|
||||||
"memory_link_set",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"source": source, "target": target, "strength": strength}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_link_impact(source: &str, target: &str) -> Result<(), String> {
|
pub async fn cmd_link_impact(source: &str, target: &str) -> Result<(), String> {
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::graph_link_impact(None, source, target).await
|
||||||
"graph_link_impact",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"source": source, "target": target}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_trace(key: &[String]) -> Result<(), String> {
|
pub async fn cmd_trace(key: &[String]) -> Result<(), String> {
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
return Err("trace requires a key".into());
|
return Err("trace requires a key".into());
|
||||||
}
|
}
|
||||||
let key = key.join(" ");
|
let key = key.join(" ");
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::graph_trace(None, &key).await
|
||||||
"graph_trace",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"key": key}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -82,11 +71,9 @@ pub fn cmd_trace(key: &[String]) -> Result<(), String> {
|
||||||
/// Show communities sorted by isolation (most isolated first).
|
/// Show communities sorted by isolation (most isolated first).
|
||||||
/// Useful for finding poorly-integrated knowledge clusters that need
|
/// Useful for finding poorly-integrated knowledge clusters that need
|
||||||
/// organize agents aimed at them.
|
/// organize agents aimed at them.
|
||||||
pub fn cmd_communities(top_n: usize, min_size: usize) -> Result<(), String> {
|
pub async fn cmd_communities(top_n: usize, min_size: usize) -> Result<(), String> {
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::graph_communities(None, Some(top_n), Some(min_size)).await
|
||||||
"graph_communities",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"top_n": top_n, "min_size": min_size}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// cli/journal.rs — journal subcommand handlers
|
// 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> {
|
pub fn cmd_tail(n: usize, full: bool, provenance: Option<&str>, dedup: bool) -> Result<(), String> {
|
||||||
let path = crate::store::nodes_path();
|
let path = crate::store::nodes_path();
|
||||||
|
|
@ -66,32 +67,23 @@ pub fn cmd_tail(n: usize, full: bool, provenance: Option<&str>, dedup: bool) ->
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_journal_tail(n: usize, full: bool, level: u8) -> Result<(), String> {
|
pub async fn cmd_journal_tail(n: usize, full: bool, level: u8) -> Result<(), String> {
|
||||||
let format = if full { "full" } else { "compact" };
|
let format = if full { Some("full") } else { Some("compact") };
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::journal_tail(None, Some(n as u64), Some(level as u64), format, None).await
|
||||||
"journal_tail",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({"count": n, "level": level, "format": format}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
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() {
|
if text.is_empty() {
|
||||||
return Err("journal write requires text".into());
|
return Err("journal write requires text".into());
|
||||||
}
|
}
|
||||||
super::check_dry_run();
|
super::check_dry_run();
|
||||||
let body = text.join(" ");
|
let body = text.join(" ");
|
||||||
|
|
||||||
let result = crate::mcp_server::memory_rpc(
|
let result = memory::journal_new(None, name, name, &body, Some(0)).await
|
||||||
"journal_new",
|
.map_err(|e| e.to_string())?;
|
||||||
serde_json::json!({
|
|
||||||
"name": name,
|
|
||||||
"title": name,
|
|
||||||
"body": body,
|
|
||||||
"level": 0
|
|
||||||
}),
|
|
||||||
).map_err(|e| e.to_string())?;
|
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::store;
|
||||||
|
|
||||||
pub async fn cmd_weight_set(key: &str, weight: f32) -> Result<(), String> {
|
pub async fn cmd_weight_set(key: &str, weight: f32) -> Result<(), String> {
|
||||||
super::check_dry_run();
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -20,7 +20,7 @@ pub async fn cmd_node_delete(key: &[String]) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
super::check_dry_run();
|
super::check_dry_run();
|
||||||
let key = key.join(" ");
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
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> {
|
pub async fn cmd_node_rename(old_key: &str, new_key: &str) -> Result<(), String> {
|
||||||
super::check_dry_run();
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -41,7 +41,7 @@ pub async fn cmd_render(key: &[String]) -> Result<(), String> {
|
||||||
let key = key.join(" ");
|
let key = key.join(" ");
|
||||||
let bare = store::strip_md_suffix(&key);
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
print!("{}", rendered);
|
print!("{}", rendered);
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ pub async fn cmd_history(key: &[String], full: bool) -> Result<(), String> {
|
||||||
return Err("history requires a key".into());
|
return Err("history requires a key".into());
|
||||||
}
|
}
|
||||||
let key = key.join(" ");
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -91,7 +91,7 @@ pub async fn cmd_write(key: &[String]) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
super::check_dry_run();
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -104,7 +104,7 @@ pub async fn cmd_edit(key: &[String]) -> Result<(), String> {
|
||||||
let key = key.join(" ");
|
let key = key.join(" ");
|
||||||
|
|
||||||
// Get raw content
|
// 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();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let tmp = std::env::temp_dir().join(format!("poc-memory-edit-{}.md", key.replace('/', "_")));
|
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();
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -146,7 +146,7 @@ pub async fn cmd_search(keys: &[String]) -> Result<(), String> {
|
||||||
if keys.is_empty() {
|
if keys.is_empty() {
|
||||||
return Err("search requires seed keys".into());
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -158,7 +158,7 @@ pub async fn cmd_query(expr: &[String]) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let query_str = expr.join(" ");
|
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())?;
|
.map_err(|e| e.to_string())?;
|
||||||
print!("{}", result);
|
print!("{}", result);
|
||||||
Ok(())
|
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:{}",
|
let query = format!("all | type:episodic | age:<{} | sort:timestamp | limit:{}",
|
||||||
window, cfg.journal_max);
|
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,
|
Ok(s) => s,
|
||||||
Err(_) => return vec![],
|
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
|
// Parse keys (one per line) and render each
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
for key in keys_str.lines().filter(|k| !k.is_empty() && *k != "no results") {
|
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() {
|
if !content.trim().is_empty() {
|
||||||
results.push((key.to_string(), content));
|
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 => {
|
crate::config::ContextSource::Store => {
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
for key in &group.keys {
|
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() {
|
if !content.trim().is_empty() {
|
||||||
results.push((key.clone(), content.trim().to_string()));
|
results.push((key.clone(), content.trim().to_string()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ use crate::neuro::{consolidation_priority, ReplayItem};
|
||||||
|
|
||||||
// ── Memory operations ──────────────────────────────────────────
|
// ── Memory operations ──────────────────────────────────────────
|
||||||
|
|
||||||
pub fn render(store: &Store, _provenance: &str, key: &str, raw: Option<bool>) -> Result<String> {
|
pub fn memory_render(store: &Store, _provenance: &str, key: &str, raw: Option<bool>) -> Result<String> {
|
||||||
let node = MemoryNode::from_store(store, key)
|
let node = MemoryNode::from_store(store, key)
|
||||||
.ok_or_else(|| anyhow::anyhow!("node not found: {}", key))?;
|
.ok_or_else(|| anyhow::anyhow!("node not found: {}", key))?;
|
||||||
if raw.unwrap_or(false) {
|
if raw.unwrap_or(false) {
|
||||||
|
|
@ -36,14 +36,14 @@ pub fn render(store: &Store, _provenance: &str, key: &str, raw: Option<bool>) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(store: &mut Store, provenance: &str, key: &str, content: &str) -> Result<String> {
|
pub fn memory_write(store: &mut Store, provenance: &str, key: &str, content: &str) -> Result<String> {
|
||||||
let result = store.upsert_provenance(key, content, provenance)
|
let result = store.upsert_provenance(key, content, provenance)
|
||||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
Ok(format!("{} '{}'", result, key))
|
Ok(format!("{} '{}'", result, key))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search(
|
pub fn memory_search(
|
||||||
store: &Store,
|
store: &Store,
|
||||||
_provenance: &str,
|
_provenance: &str,
|
||||||
keys: Vec<String>,
|
keys: Vec<String>,
|
||||||
|
|
@ -84,7 +84,7 @@ pub fn search(
|
||||||
.collect::<Vec<_>>().join("\n"))
|
.collect::<Vec<_>>().join("\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn links(store: &Store, _provenance: &str, key: &str) -> Result<String> {
|
pub fn memory_links(store: &Store, _provenance: &str, key: &str) -> Result<String> {
|
||||||
let node = MemoryNode::from_store(store, key)
|
let node = MemoryNode::from_store(store, key)
|
||||||
.ok_or_else(|| anyhow::anyhow!("node not found: {}", key))?;
|
.ok_or_else(|| anyhow::anyhow!("node not found: {}", key))?;
|
||||||
let mut out = format!("Neighbors of '{}':\n", key);
|
let mut out = format!("Neighbors of '{}':\n", key);
|
||||||
|
|
@ -95,7 +95,7 @@ pub fn links(store: &Store, _provenance: &str, key: &str) -> Result<String> {
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_set(store: &mut Store, _provenance: &str, source: &str, target: &str, strength: f32) -> Result<String> {
|
pub fn memory_link_set(store: &mut Store, _provenance: &str, source: &str, target: &str, strength: f32) -> Result<String> {
|
||||||
let s = store.resolve_key(source).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let s = store.resolve_key(source).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let t = store.resolve_key(target).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let t = store.resolve_key(target).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let old = store.set_link_strength(&s, &t, strength).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let old = store.set_link_strength(&s, &t, strength).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
|
|
@ -103,7 +103,7 @@ pub fn link_set(store: &mut Store, _provenance: &str, source: &str, target: &str
|
||||||
Ok(format!("{} ↔ {} strength {:.2} → {:.2}", s, t, old, strength))
|
Ok(format!("{} ↔ {} strength {:.2} → {:.2}", s, t, old, strength))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_add(store: &mut Store, provenance: &str, source: &str, target: &str) -> Result<String> {
|
pub fn memory_link_add(store: &mut Store, provenance: &str, source: &str, target: &str) -> Result<String> {
|
||||||
let s = store.resolve_key(source).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let s = store.resolve_key(source).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let t = store.resolve_key(target).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let t = store.resolve_key(target).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let strength = store.add_link(&s, &t, provenance).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let strength = store.add_link(&s, &t, provenance).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
|
|
@ -111,14 +111,14 @@ pub fn link_add(store: &mut Store, provenance: &str, source: &str, target: &str)
|
||||||
Ok(format!("linked {} → {} (strength={:.2})", s, t, strength))
|
Ok(format!("linked {} → {} (strength={:.2})", s, t, strength))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(store: &mut Store, _provenance: &str, key: &str) -> Result<String> {
|
pub fn memory_delete(store: &mut Store, _provenance: &str, key: &str) -> Result<String> {
|
||||||
let resolved = store.resolve_key(key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let resolved = store.resolve_key(key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.delete_node(&resolved).map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.delete_node(&resolved).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
Ok(format!("deleted {}", resolved))
|
Ok(format!("deleted {}", resolved))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn history(store: &Store, _provenance: &str, key: &str, full: Option<bool>) -> Result<String> {
|
pub fn memory_history(store: &Store, _provenance: &str, key: &str, full: Option<bool>) -> Result<String> {
|
||||||
let key = store.resolve_key(key).unwrap_or_else(|_| key.to_string());
|
let key = store.resolve_key(key).unwrap_or_else(|_| key.to_string());
|
||||||
let full = full.unwrap_or(false);
|
let full = full.unwrap_or(false);
|
||||||
|
|
||||||
|
|
@ -168,21 +168,21 @@ pub fn history(store: &Store, _provenance: &str, key: &str, full: Option<bool>)
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn weight_set(store: &mut Store, _provenance: &str, key: &str, weight: f32) -> Result<String> {
|
pub fn memory_weight_set(store: &mut Store, _provenance: &str, key: &str, weight: f32) -> Result<String> {
|
||||||
let resolved = store.resolve_key(key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let resolved = store.resolve_key(key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let (old, new) = store.set_weight(&resolved, weight).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let (old, new) = store.set_weight(&resolved, weight).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
Ok(format!("weight {} {:.2} → {:.2}", resolved, old, new))
|
Ok(format!("weight {} {:.2} → {:.2}", resolved, old, new))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rename(store: &mut Store, _provenance: &str, old_key: &str, new_key: &str) -> Result<String> {
|
pub fn memory_rename(store: &mut Store, _provenance: &str, old_key: &str, new_key: &str) -> Result<String> {
|
||||||
let resolved = store.resolve_key(old_key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
let resolved = store.resolve_key(old_key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.rename_node(&resolved, new_key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.rename_node(&resolved, new_key).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
Ok(format!("Renamed '{}' → '{}'", resolved, new_key))
|
Ok(format!("Renamed '{}' → '{}'", resolved, new_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn supersede(store: &mut Store, provenance: &str, old_key: &str, new_key: &str, reason: Option<&str>) -> Result<String> {
|
pub fn memory_supersede(store: &mut Store, provenance: &str, old_key: &str, new_key: &str, reason: Option<&str>) -> Result<String> {
|
||||||
let reason = reason.unwrap_or("superseded");
|
let reason = reason.unwrap_or("superseded");
|
||||||
let content = store.nodes.get(old_key)
|
let content = store.nodes.get(old_key)
|
||||||
.map(|n| n.content.clone())
|
.map(|n| n.content.clone())
|
||||||
|
|
@ -221,7 +221,7 @@ pub fn keys_to_replay_items(
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query(store: &Store, _provenance: &str, query_str: &str, format: Option<&str>) -> Result<String> {
|
pub fn memory_query(store: &Store, _provenance: &str, query_str: &str, format: Option<&str>) -> Result<String> {
|
||||||
let graph = store.build_graph();
|
let graph = store.build_graph();
|
||||||
|
|
||||||
match format.unwrap_or("compact") {
|
match format.unwrap_or("compact") {
|
||||||
|
|
@ -267,7 +267,7 @@ pub fn journal_tail(store: &Store, _provenance: &str, count: Option<u64>, level:
|
||||||
}
|
}
|
||||||
q.push_str(&std::format!(" | limit:{}", count));
|
q.push_str(&std::format!(" | limit:{}", count));
|
||||||
|
|
||||||
query(store, _provenance, &q, Some(format))
|
memory_query(store, _provenance, &q, Some(format))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn level_to_node_type(level: i64) -> crate::store::NodeType {
|
fn level_to_node_type(level: i64) -> crate::store::NodeType {
|
||||||
|
|
|
||||||
24
src/main.rs
24
src/main.rs
|
|
@ -397,7 +397,7 @@ impl Run for Command {
|
||||||
Self::History { full, key } => cli::node::cmd_history(&key, full).await,
|
Self::History { full, key } => cli::node::cmd_history(&key, full).await,
|
||||||
Self::Tail { n, full, provenance, all_versions }
|
Self::Tail { n, full, provenance, all_versions }
|
||||||
=> cli::journal::cmd_tail(n, full, provenance.as_deref(), !all_versions),
|
=> cli::journal::cmd_tail(n, full, provenance.as_deref(), !all_versions),
|
||||||
Self::Status => cli::admin::cmd_status(),
|
Self::Status => cli::admin::cmd_status().await,
|
||||||
Self::Query { expr } => cli::node::cmd_query(&expr).await,
|
Self::Query { expr } => cli::node::cmd_query(&expr).await,
|
||||||
Self::WeightSet { key, weight } => cli::node::cmd_weight_set(&key, weight).await,
|
Self::WeightSet { key, weight } => cli::node::cmd_weight_set(&key, weight).await,
|
||||||
Self::Node(sub) => sub.run().await,
|
Self::Node(sub) => sub.run().await,
|
||||||
|
|
@ -422,8 +422,8 @@ impl Run for NodeCmd {
|
||||||
impl Run for JournalCmd {
|
impl Run for JournalCmd {
|
||||||
async fn run(self) -> Result<(), String> {
|
async fn run(self) -> Result<(), String> {
|
||||||
match self {
|
match self {
|
||||||
Self::Write { name, text } => cli::journal::cmd_journal_write(&name, &text),
|
Self::Write { name, text } => cli::journal::cmd_journal_write(&name, &text).await,
|
||||||
Self::Tail { n, full, level } => cli::journal::cmd_journal_tail(n, full, level),
|
Self::Tail { n, full, level } => cli::journal::cmd_journal_tail(n, full, level).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -431,16 +431,16 @@ impl Run for JournalCmd {
|
||||||
impl Run for GraphCmd {
|
impl Run for GraphCmd {
|
||||||
async fn run(self) -> Result<(), String> {
|
async fn run(self) -> Result<(), String> {
|
||||||
match self {
|
match self {
|
||||||
Self::Link { key } => cli::graph::cmd_link(&key),
|
Self::Link { key } => cli::graph::cmd_link(&key).await,
|
||||||
Self::LinkAdd { source, target, reason }
|
Self::LinkAdd { source, target, reason }
|
||||||
=> cli::graph::cmd_link_add(&source, &target, &reason),
|
=> cli::graph::cmd_link_add(&source, &target, &reason).await,
|
||||||
Self::LinkSet { source, target, strength }
|
Self::LinkSet { source, target, strength }
|
||||||
=> cli::graph::cmd_link_set(&source, &target, strength),
|
=> cli::graph::cmd_link_set(&source, &target, strength).await,
|
||||||
Self::LinkImpact { source, target } => cli::graph::cmd_link_impact(&source, &target),
|
Self::LinkImpact { source, target } => cli::graph::cmd_link_impact(&source, &target).await,
|
||||||
Self::CapDegree { max_degree } => cli::graph::cmd_cap_degree(max_degree),
|
Self::CapDegree { max_degree } => cli::graph::cmd_cap_degree(max_degree),
|
||||||
Self::NormalizeStrengths { apply } => cli::graph::cmd_normalize_strengths(apply),
|
Self::NormalizeStrengths { apply } => cli::graph::cmd_normalize_strengths(apply).await,
|
||||||
Self::Trace { key } => cli::graph::cmd_trace(&key),
|
Self::Trace { key } => cli::graph::cmd_trace(&key).await,
|
||||||
Self::Communities { top_n, min_size } => cli::graph::cmd_communities(top_n, min_size),
|
Self::Communities { top_n, min_size } => cli::graph::cmd_communities(top_n, min_size).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -458,8 +458,8 @@ impl Run for AdminCmd {
|
||||||
async fn run(self) -> Result<(), String> {
|
async fn run(self) -> Result<(), String> {
|
||||||
match self {
|
match self {
|
||||||
Self::Init => cli::admin::cmd_init(),
|
Self::Init => cli::admin::cmd_init(),
|
||||||
Self::Health => cli::admin::cmd_health(),
|
Self::Health => cli::admin::cmd_health().await,
|
||||||
Self::Topology => cli::admin::cmd_topology(),
|
Self::Topology => cli::admin::cmd_topology().await,
|
||||||
Self::Fsck => cli::admin::cmd_fsck(),
|
Self::Fsck => cli::admin::cmd_fsck(),
|
||||||
Self::Dedup { apply } => cli::admin::cmd_dedup(apply),
|
Self::Dedup { apply } => cli::admin::cmd_dedup(apply),
|
||||||
Self::DailyCheck => cli::admin::cmd_daily_check(),
|
Self::DailyCheck => cli::admin::cmd_daily_check(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue