2026-04-08 20:41:42 -04:00
|
|
|
use std::sync::Arc;
|
2026-03-27 15:22:48 -04:00
|
|
|
// tools/memory.rs — Native memory graph operations
|
|
|
|
|
//
|
2026-04-12 21:16:13 -04:00
|
|
|
// If running in the daemon process (STORE_HANDLE set), accesses
|
|
|
|
|
// the store directly. Otherwise forwards to the daemon via socket.
|
2026-03-27 15:22:48 -04:00
|
|
|
|
|
|
|
|
use anyhow::{Context, Result};
|
2026-04-12 21:16:13 -04:00
|
|
|
use std::sync::OnceLock;
|
2026-03-27 15:22:48 -04:00
|
|
|
|
|
|
|
|
use crate::store::Store;
|
|
|
|
|
|
2026-04-12 21:16:13 -04:00
|
|
|
// ── Store handle ───────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/// Global store handle. Set by daemon at startup.
|
|
|
|
|
/// If None, tools forward to daemon socket.
|
|
|
|
|
static STORE_HANDLE: OnceLock<Arc<crate::Mutex<Store>>> = OnceLock::new();
|
|
|
|
|
|
|
|
|
|
// Thread-local store for rpc_local fallback path.
|
|
|
|
|
thread_local! {
|
|
|
|
|
static LOCAL_STORE: std::cell::RefCell<Option<Arc<crate::Mutex<Store>>>> =
|
|
|
|
|
const { std::cell::RefCell::new(None) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Set the global store handle. Call once at daemon startup.
|
|
|
|
|
pub fn set_store(store: Arc<crate::Mutex<Store>>) {
|
|
|
|
|
STORE_HANDLE.set(store).ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check if we're running in daemon mode (have direct store access).
|
|
|
|
|
pub fn is_daemon() -> bool {
|
|
|
|
|
STORE_HANDLE.get().is_some() || LOCAL_STORE.with(|s| s.borrow().is_some())
|
|
|
|
|
}
|
|
|
|
|
|
tools/memory: one function per tool
Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.
The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 15:03:04 -04:00
|
|
|
// ── Helpers ────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
fn get_str<'a>(args: &'a serde_json::Value, name: &'a str) -> Result<&'a str> {
|
|
|
|
|
args.get(name).and_then(|v| v.as_str()).context(format!("{} is required", name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_f64(args: &serde_json::Value, name: &str) -> Result<f64> {
|
|
|
|
|
args.get(name).and_then(|v| v.as_f64()).context(format!("{} is required", name))
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 21:16:13 -04:00
|
|
|
async fn cached_store() -> Result<Arc<crate::Mutex<Store>>> {
|
|
|
|
|
// Check thread-local first (rpc_local fallback path)
|
|
|
|
|
if let Some(store) = LOCAL_STORE.with(|s| s.borrow().clone()) {
|
|
|
|
|
return Ok(store);
|
|
|
|
|
}
|
|
|
|
|
// Use global handle if set (daemon mode)
|
|
|
|
|
if let Some(store) = STORE_HANDLE.get() {
|
|
|
|
|
return Ok(store.clone());
|
|
|
|
|
}
|
|
|
|
|
// Fallback to loading (for backwards compat during transition)
|
2026-04-07 03:35:08 -04:00
|
|
|
Store::cached().await.map_err(|e| anyhow::anyhow!("{}", e))
|
tools/memory: one function per tool
Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.
The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 15:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 21:16:13 -04:00
|
|
|
/// Run a tool with a temporarily-opened store (for rpc_local fallback).
|
2026-04-13 11:23:52 -04:00
|
|
|
pub async fn run_with_local_store(tool_name: &str, args: serde_json::Value) -> Result<String> {
|
|
|
|
|
let store = Store::cached().await.map_err(|e| anyhow::anyhow!("{}", e))?;
|
|
|
|
|
|
|
|
|
|
LOCAL_STORE.with(|s| *s.borrow_mut() = Some(store));
|
|
|
|
|
let result = dispatch(tool_name, &None, args).await;
|
2026-04-12 21:16:13 -04:00
|
|
|
LOCAL_STORE.with(|s| *s.borrow_mut() = None);
|
|
|
|
|
|
2026-04-13 11:23:52 -04:00
|
|
|
result
|
2026-04-12 21:16:13 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:08:46 -04:00
|
|
|
/// Get provenance from args._provenance, or "manual".
|
|
|
|
|
fn get_provenance(args: &serde_json::Value) -> String {
|
|
|
|
|
args.get("_provenance")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.unwrap_or("manual")
|
|
|
|
|
.to_string()
|
2026-04-07 17:46:40 -04:00
|
|
|
}
|
tools/memory: one function per tool
Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.
The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 15:03:04 -04:00
|
|
|
|
memory tools: typed hippocampus fns + macro dispatch
Move tool implementations from tools/memory.rs to hippocampus/mod.rs
with proper typed signatures:
fn name(store, provenance, ...typed args...) -> Result<String>
Optional params take Option<T>, defaults applied in implementation.
tools/memory.rs is now a thin dispatch layer using memory_tool! macro:
memory_tool!(write, mut, key: [str], content: [str]);
memory_tool!(search, ref, keys: [Vec<String>], max_hops: [Option<u32>], ...);
~634 lines of boilerplate replaced with ~30 one-liner invocations.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:03:24 -04:00
|
|
|
// ── Macro for generating tool wrappers ─────────────────────────
|
|
|
|
|
//
|
|
|
|
|
// memory_tool!(name, mut, arg1: str, arg2: f32, arg3: ?str)
|
|
|
|
|
// - mut/ref for store mutability
|
|
|
|
|
// - type suffixes: str, f32, f64, u64, i64, bool
|
|
|
|
|
// - ?type for optional args with default
|
|
|
|
|
|
|
|
|
|
macro_rules! memory_tool {
|
|
|
|
|
// Mutable store variant
|
|
|
|
|
($name:ident, mut $(, $($arg:ident : [$($typ:tt)+]),* $(,)?)?) => {
|
|
|
|
|
async fn $name(args: &serde_json::Value) -> Result<String> {
|
|
|
|
|
$($(let $arg = memory_tool!(@extract args, $arg, $($typ)+);)*)?
|
|
|
|
|
let prov = get_provenance(args);
|
|
|
|
|
let arc = cached_store().await?;
|
|
|
|
|
let mut store = arc.lock().await;
|
|
|
|
|
crate::hippocampus::$name(&mut store, &prov $($(, $arg)*)?)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// Immutable store variant
|
|
|
|
|
($name:ident, ref $(, $($arg:ident : [$($typ:tt)+]),* $(,)?)?) => {
|
|
|
|
|
async fn $name(args: &serde_json::Value) -> Result<String> {
|
|
|
|
|
$($(let $arg = memory_tool!(@extract args, $arg, $($typ)+);)*)?
|
|
|
|
|
let prov = get_provenance(args);
|
|
|
|
|
let arc = cached_store().await?;
|
|
|
|
|
let store = arc.lock().await;
|
|
|
|
|
crate::hippocampus::$name(&store, &prov $($(, $arg)*)?)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// Required extractors - fail if missing
|
|
|
|
|
(@extract $args:ident, $name:ident, str) => {
|
|
|
|
|
get_str($args, stringify!($name))?
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, f32) => {
|
|
|
|
|
get_f64($args, stringify!($name))? as f32
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Vec<String>) => {
|
|
|
|
|
$args.get(stringify!($name))
|
|
|
|
|
.and_then(|v| v.as_array())
|
|
|
|
|
.map(|arr| arr.iter().filter_map(|v| v.as_str().map(String::from)).collect::<Vec<_>>())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Optional extractors - return Option<T>
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<&str>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_str())
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<bool>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_bool())
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<u64>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_u64())
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<i64>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_i64())
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<usize>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_u64()).map(|v| v as usize)
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<u32>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_u64()).map(|v| v as u32)
|
|
|
|
|
};
|
|
|
|
|
(@extract $args:ident, $name:ident, Option<f64>) => {
|
|
|
|
|
$args.get(stringify!($name)).and_then(|v| v.as_f64())
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Memory tools ───────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
memory_tool!(render, ref, key: [str], raw: [Option<bool>]);
|
|
|
|
|
memory_tool!(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!(links, ref, key: [str]);
|
|
|
|
|
memory_tool!(link_set, mut, source: [str], target: [str], strength: [f32]);
|
|
|
|
|
memory_tool!(link_add, mut, source: [str], target: [str]);
|
|
|
|
|
memory_tool!(delete, mut, key: [str]);
|
|
|
|
|
memory_tool!(history, ref, key: [str], full: [Option<bool>]);
|
|
|
|
|
memory_tool!(weight_set, mut, key: [str], weight: [f32]);
|
|
|
|
|
memory_tool!(rename, mut, old_key: [str], new_key: [str]);
|
|
|
|
|
memory_tool!(supersede, mut, old_key: [str], new_key: [str], reason: [Option<&str>]);
|
|
|
|
|
memory_tool!(query, ref, query: [str], format: [Option<&str>]);
|
|
|
|
|
|
|
|
|
|
// ── Journal tools ──────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
memory_tool!(journal_tail, ref, count: [Option<u64>], level: [Option<u64>], format: [Option<&str>], after: [Option<&str>]);
|
|
|
|
|
memory_tool!(journal_new, mut, name: [str], title: [str], body: [str], level: [Option<i64>]);
|
|
|
|
|
memory_tool!(journal_update, mut, body: [str], level: [Option<i64>]);
|
|
|
|
|
|
|
|
|
|
// ── Graph tools ───────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
memory_tool!(graph_topology, ref);
|
|
|
|
|
memory_tool!(graph_health, ref);
|
|
|
|
|
memory_tool!(graph_communities, ref, top_n: [Option<usize>], min_size: [Option<usize>]);
|
|
|
|
|
memory_tool!(graph_normalize_strengths, mut, apply: [Option<bool>]);
|
|
|
|
|
memory_tool!(graph_link_impact, ref, source: [str], target: [str]);
|
|
|
|
|
memory_tool!(graph_hubs, ref, count: [Option<usize>]);
|
|
|
|
|
memory_tool!(graph_trace, ref, key: [str]);
|
|
|
|
|
|
2026-04-12 21:16:13 -04:00
|
|
|
/// Single entry point for all memory/journal tool calls.
|
|
|
|
|
/// If not daemon, forwards to daemon with provenance attached.
|
|
|
|
|
async fn dispatch(
|
|
|
|
|
tool_name: &str,
|
|
|
|
|
agent: &Option<std::sync::Arc<crate::agent::Agent>>,
|
|
|
|
|
args: serde_json::Value,
|
|
|
|
|
) -> Result<String> {
|
2026-04-13 12:08:46 -04:00
|
|
|
let mut args = args;
|
|
|
|
|
if let Some(a) = agent {
|
|
|
|
|
let prov = a.state.lock().await.provenance.clone();
|
|
|
|
|
args.as_object_mut().map(|o| o.insert("_provenance".into(), prov.into()));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 21:16:13 -04:00
|
|
|
if !is_daemon() {
|
2026-04-13 12:08:46 -04:00
|
|
|
// Forward to daemon
|
2026-04-12 21:16:13 -04:00
|
|
|
let name = tool_name.to_string();
|
|
|
|
|
return tokio::task::spawn_blocking(move || {
|
|
|
|
|
crate::mcp_server::memory_rpc(&name, args)
|
|
|
|
|
}).await.map_err(|e| anyhow::anyhow!("spawn_blocking: {}", e))?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Daemon path - dispatch to implementation
|
|
|
|
|
match tool_name {
|
|
|
|
|
"memory_render" => render(&args).await,
|
2026-04-13 12:08:46 -04:00
|
|
|
"memory_write" => write(&args).await,
|
2026-04-12 21:16:13 -04:00
|
|
|
"memory_search" => search(&args).await,
|
|
|
|
|
"memory_links" => links(&args).await,
|
|
|
|
|
"memory_link_set" => link_set(&args).await,
|
2026-04-13 12:08:46 -04:00
|
|
|
"memory_link_add" => link_add(&args).await,
|
2026-04-12 22:15:53 -04:00
|
|
|
"memory_delete" => delete(&args).await,
|
2026-04-12 22:24:34 -04:00
|
|
|
"memory_history" => history(&args).await,
|
2026-04-12 21:16:13 -04:00
|
|
|
"memory_weight_set" => weight_set(&args).await,
|
|
|
|
|
"memory_rename" => rename(&args).await,
|
2026-04-13 12:08:46 -04:00
|
|
|
"memory_supersede" => supersede(&args).await,
|
2026-04-12 21:16:13 -04:00
|
|
|
"memory_query" => query(&args).await,
|
memory tools: typed hippocampus fns + macro dispatch
Move tool implementations from tools/memory.rs to hippocampus/mod.rs
with proper typed signatures:
fn name(store, provenance, ...typed args...) -> Result<String>
Optional params take Option<T>, defaults applied in implementation.
tools/memory.rs is now a thin dispatch layer using memory_tool! macro:
memory_tool!(write, mut, key: [str], content: [str]);
memory_tool!(search, ref, keys: [Vec<String>], max_hops: [Option<u32>], ...);
~634 lines of boilerplate replaced with ~30 one-liner invocations.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:03:24 -04:00
|
|
|
"graph_topology" => graph_topology(&args).await,
|
|
|
|
|
"graph_health" => graph_health(&args).await,
|
2026-04-12 23:09:12 -04:00
|
|
|
"graph_communities" => graph_communities(&args).await,
|
2026-04-12 23:12:42 -04:00
|
|
|
"graph_normalize_strengths" => graph_normalize_strengths(&args).await,
|
2026-04-12 23:16:12 -04:00
|
|
|
"graph_trace" => graph_trace(&args).await,
|
|
|
|
|
"graph_link_impact" => graph_link_impact(&args).await,
|
2026-04-13 01:37:33 -04:00
|
|
|
"graph_hubs" => graph_hubs(&args).await,
|
2026-04-12 21:16:13 -04:00
|
|
|
"journal_tail" => journal_tail(&args).await,
|
2026-04-13 12:08:46 -04:00
|
|
|
"journal_new" => journal_new(&args).await,
|
|
|
|
|
"journal_update" => journal_update(&args).await,
|
2026-04-12 21:16:13 -04:00
|
|
|
_ => anyhow::bail!("unknown tool: {}", tool_name),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
tools/memory: one function per tool
Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.
The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 15:03:04 -04:00
|
|
|
// ── Definitions ────────────────────────────────────────────────
|
|
|
|
|
|
2026-04-13 01:37:33 -04:00
|
|
|
pub fn memory_tools() -> [super::Tool; 15] {
|
2026-04-04 15:22:03 -04:00
|
|
|
use super::Tool;
|
2026-04-04 15:50:14 -04:00
|
|
|
[
|
|
|
|
|
Tool { name: "memory_render", description: "Read a memory node's content and links.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Node key"}},"required":["key"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_render", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_write", description: "Create or update a memory node.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Node key"},"content":{"type":"string","description":"Full content (markdown)"}},"required":["key","content"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_write", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_search", description: "Search the memory graph via spreading activation. Give 2-4 seed node keys.",
|
2026-04-12 22:49:40 -04:00
|
|
|
parameters_json: r#"{"type":"object","properties":{"keys":{"type":"array","items":{"type":"string"},"description":"Seed node keys to activate from"},"max_hops":{"type":"integer","description":"Max graph hops (default 3)"},"edge_decay":{"type":"number","description":"Decay per hop (default 0.3)"},"min_activation":{"type":"number","description":"Cutoff threshold (default 0.01)"},"limit":{"type":"integer","description":"Max results (default 20)"}},"required":["keys"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_search", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_links", description: "Show a node's neighbors with link strengths.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Node key"}},"required":["key"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_links", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_link_set", description: "Set link strength between two nodes.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"source":{"type":"string"},"target":{"type":"string"},"strength":{"type":"number","description":"0.01 to 1.0"}},"required":["source","target","strength"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_link_set", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_link_add", description: "Add a new link between two nodes.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"source":{"type":"string"},"target":{"type":"string"}},"required":["source","target"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_link_add", &a, v).await })) },
|
2026-04-12 22:15:53 -04:00
|
|
|
Tool { name: "memory_delete", description: "Delete a memory node.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Node key"}},"required":["key"]}"#,
|
|
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_delete", &a, v).await })) },
|
2026-04-12 22:24:34 -04:00
|
|
|
Tool { name: "memory_history", description: "Show version history for a node.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Node key"},"full":{"type":"boolean","description":"Show full content for each version"}},"required":["key"]}"#,
|
|
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_history", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_weight_set", description: "Set a node's weight directly (0.01 to 1.0).",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string"},"weight":{"type":"number","description":"0.01 to 1.0"}},"required":["key","weight"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_weight_set", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_rename", description: "Rename a node key in place.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"old_key":{"type":"string"},"new_key":{"type":"string"}},"required":["old_key","new_key"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_rename", &a, v).await })) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "memory_supersede", description: "Mark a node as superseded by another (sets weight to 0.01).",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"old_key":{"type":"string"},"new_key":{"type":"string"},"reason":{"type":"string"}},"required":["old_key","new_key"]}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_supersede", &a, v).await })) },
|
2026-04-10 16:04:31 -04:00
|
|
|
Tool { name: "memory_query",
|
|
|
|
|
description: "Run a structured query against the memory graph.",
|
|
|
|
|
parameters_json: r#"{
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"query": {"type": "string", "description": "Query expression"},
|
|
|
|
|
"format": {"type": "string", "description": "compact (default) or full (with content and graph metrics)", "default": "compact"}
|
|
|
|
|
},
|
|
|
|
|
"required": ["query"]
|
|
|
|
|
}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("memory_query", &a, v).await })) },
|
2026-04-10 15:25:57 -04:00
|
|
|
Tool { name: "graph_topology", description: "Show graph topology stats (nodes, edges, clustering, hubs).",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{}}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("graph_topology", &a, v).await })) },
|
2026-04-10 15:25:57 -04:00
|
|
|
Tool { name: "graph_health", description: "Show graph health report with maintenance recommendations.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{}}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("graph_health", &a, v).await })) },
|
2026-04-13 01:37:33 -04:00
|
|
|
Tool { name: "graph_hubs", description: "Show top hub nodes by degree, spread apart for diverse link targets.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"count":{"type":"integer","description":"Number of hubs to return (default 20)"}}}"#,
|
|
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("graph_hubs", &a, v).await })) },
|
2026-04-01 15:12:14 -04:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 15:50:14 -04:00
|
|
|
pub fn journal_tools() -> [super::Tool; 3] {
|
2026-04-04 15:22:03 -04:00
|
|
|
use super::Tool;
|
2026-04-04 15:50:14 -04:00
|
|
|
[
|
2026-04-10 16:04:31 -04:00
|
|
|
Tool { name: "journal_tail",
|
|
|
|
|
description: "Read the last N entries at a given level.",
|
|
|
|
|
parameters_json: r#"{
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
2026-04-10 16:09:46 -04:00
|
|
|
"count": {"type": "integer", "description": "Number of entries", "default": 1},
|
|
|
|
|
"level": {"type": "integer", "description": "0=journal, 1=daily, 2=weekly, 3=monthly", "default": 0},
|
|
|
|
|
"format": {"type": "string", "description": "compact or full (with content)", "default": "full"},
|
|
|
|
|
"after": {"type": "string", "description": "Only entries after this date (YYYY-MM-DD)"}
|
2026-04-10 16:04:31 -04:00
|
|
|
}
|
|
|
|
|
}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("journal_tail", &a, v).await })) },
|
2026-04-12 02:04:50 -04:00
|
|
|
Tool { name: "journal_new", description: "Start a new journal/digest entry.",
|
|
|
|
|
parameters_json: r#"{
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"name": {"type": "string", "description": "Short node name (becomes the key)"},
|
|
|
|
|
"title": {"type": "string", "description": "Descriptive title"},
|
|
|
|
|
"body": {"type": "string", "description": "Entry body"},
|
|
|
|
|
"level": {"type": "integer", "description": "0=journal, 1=daily, 2=weekly, 3=monthly", "default": 0}
|
|
|
|
|
},
|
|
|
|
|
"required": ["name", "title", "body"]
|
|
|
|
|
}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("journal_new", &a, v).await })) },
|
2026-04-12 02:04:50 -04:00
|
|
|
Tool { name: "journal_update", description: "Append text to the most recent entry at a level.",
|
|
|
|
|
parameters_json: r#"{
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"body": {"type": "string", "description": "Text to append"},
|
|
|
|
|
"level": {"type": "integer", "description": "0=journal, 1=daily, 2=weekly, 3=monthly", "default": 0}
|
|
|
|
|
},
|
|
|
|
|
"required": ["body"]
|
|
|
|
|
}"#,
|
2026-04-12 21:16:13 -04:00
|
|
|
handler: Arc::new(|a, v| Box::pin(async move { dispatch("journal_update", &a, v).await })) },
|
2026-04-04 15:22:03 -04:00
|
|
|
]
|
2026-03-27 15:22:48 -04:00
|
|
|
}
|