From 112abb200094f7174469e518c7beb9fb61644b16 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sat, 4 Apr 2026 15:13:27 -0400 Subject: [PATCH] tools: delete old dispatch functions All dispatch now goes through the Tool registry. Removed: - memory::dispatch() (20-line match) - channels::dispatch() and dispatch_blocking() - channel_list_blocking(), channel_notifications_blocking() Channel tool functions made pub so registry calls them directly. Co-Authored-By: Proof of Concept --- src/agent/tools/channels.rs | 48 ++++--------------------------------- src/agent/tools/memory.rs | 23 ------------------ src/agent/tools/mod.rs | 8 +++---- 3 files changed, 8 insertions(+), 71 deletions(-) diff --git a/src/agent/tools/channels.rs b/src/agent/tools/channels.rs index 9e67347..bc02a68 100644 --- a/src/agent/tools/channels.rs +++ b/src/agent/tools/channels.rs @@ -53,49 +53,13 @@ pub fn definitions() -> Vec { // ── Dispatch ─────────────────────────────────────────────────── -pub async fn dispatch(name: &str, args: &serde_json::Value) -> Result { - match name { - "channel_list" => channel_list().await, - "channel_recv" => channel_recv(args).await, - "channel_send" => channel_send(args).await, - "channel_notifications" => channel_notifications().await, - _ => anyhow::bail!("unknown channel tool: {}", name), - } -} - -/// Blocking dispatch for synchronous contexts (MCP server). -pub fn dispatch_blocking(name: &str, args: &serde_json::Value) -> Result { - match name { - "channel_list" => Ok(channel_list_blocking()), - "channel_notifications" => Ok(channel_notifications_blocking()), - "channel_recv" | "channel_send" => { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build()?; - let local = tokio::task::LocalSet::new(); - local.block_on(&rt, async { - match name { - "channel_recv" => channel_recv(args).await, - "channel_send" => channel_send(args).await, - _ => unreachable!(), - } - }) - } - _ => anyhow::bail!("unknown channel tool: {}", name), - } -} - // ── Tool implementations ─────────────────────────────────────── -async fn channel_list() -> Result { +pub async fn channel_list() -> Result { let result = fetch_all_channels().await; Ok(format_channel_list(&result)) } -fn channel_list_blocking() -> String { - let result = fetch_all_channels_blocking(); - format_channel_list(&result) -} fn format_channel_list(channels: &[(String, bool, u32)]) -> String { if channels.is_empty() { @@ -119,7 +83,7 @@ struct RecvArgs { fn default_true() -> bool { true } fn default_min_count() -> u32 { 20 } -async fn channel_recv(args: &serde_json::Value) -> Result { +pub async fn channel_recv(args: &serde_json::Value) -> Result { let a: RecvArgs = serde_json::from_value(args.clone()) .context("invalid channel_recv arguments")?; let sock = daemon_sock(&a.channel)?; @@ -140,7 +104,7 @@ struct SendArgs { message: String, } -async fn channel_send(args: &serde_json::Value) -> Result { +pub async fn channel_send(args: &serde_json::Value) -> Result { let a: SendArgs = serde_json::from_value(args.clone()) .context("invalid channel_send arguments")?; let sock = daemon_sock(&a.channel)?; @@ -154,15 +118,11 @@ async fn channel_send(args: &serde_json::Value) -> Result { .map_err(|e| anyhow::anyhow!("{}", e)) } -async fn channel_notifications() -> Result { +pub async fn channel_notifications() -> Result { let result = fetch_all_channels().await; Ok(format_notifications(&result)) } -fn channel_notifications_blocking() -> String { - let result = fetch_all_channels_blocking(); - format_notifications(&result) -} fn format_notifications(channels: &[(String, bool, u32)]) -> String { let unread: Vec<_> = channels.iter().filter(|(_, _, u)| *u > 0).collect(); diff --git a/src/agent/tools/memory.rs b/src/agent/tools/memory.rs index e07d9d1..b626693 100644 --- a/src/agent/tools/memory.rs +++ b/src/agent/tools/memory.rs @@ -41,29 +41,6 @@ pub fn journal_definitions() -> Vec { vec![journal_tail_def(), journal_new_def(), journal_update_def()] } -// ── Dispatch (legacy — to be replaced by Tool registry) ─────── - -pub fn dispatch(name: &str, args: &serde_json::Value, provenance: Option<&str>) -> Result { - match name { - "memory_render" => render(args), - "memory_write" => write(args), - "memory_search" => search(args), - "memory_links" => links(args), - "memory_link_set" => link_set(args), - "memory_link_add" => link_add(args), - "memory_used" => used(args), - "memory_weight_set" => weight_set(args), - "memory_rename" => rename(args), - "memory_supersede" => supersede(args), - "memory_query" => query(args), - "output" => output(args), - "journal_tail" => journal_tail(args), - "journal_new" => journal_new(args), - "journal_update" => journal_update(args), - _ => anyhow::bail!("Unknown memory tool: {}", name), - } -} - // ── Memory tools ─────────────────────────────────────────────── pub fn render_def() -> ToolDef { diff --git a/src/agent/tools/mod.rs b/src/agent/tools/mod.rs index 408ba34..b3a6936 100644 --- a/src/agent/tools/mod.rs +++ b/src/agent/tools/mod.rs @@ -233,10 +233,10 @@ pub fn tools() -> Vec { Tool { def: memory::output_def(), handler: |_a, v| Box::pin(async move { memory::output(&v) }) }, // Channel tools - Tool { def: channels::definitions()[0].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_list", &v).await }) }, - Tool { def: channels::definitions()[1].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_recv", &v).await }) }, - Tool { def: channels::definitions()[2].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_send", &v).await }) }, - Tool { def: channels::definitions()[3].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_notifications", &v).await }) }, + Tool { def: channels::definitions()[0].clone(), handler: |_a, v| Box::pin(async move { channels::channel_list().await }) }, + Tool { def: channels::definitions()[1].clone(), handler: |_a, v| Box::pin(async move { channels::channel_recv(&v).await }) }, + Tool { def: channels::definitions()[2].clone(), handler: |_a, v| Box::pin(async move { channels::channel_send(&v).await }) }, + Tool { def: channels::definitions()[3].clone(), handler: |_a, v| Box::pin(async move { channels::channel_notifications().await }) }, // Control tools Tool { def: control::definitions()[0].clone(),