WIP: Output tool via Arc<Mutex<Subconscious>>, ToolHandler to Arc<dyn Fn>

- ToolHandler changed to Arc<dyn Fn(...)> (supports closures)
- Subconscious wrapped in Arc<Mutex<>> on Mind
- init_output_tool() pushes output tool closure capturing the Arc
- Output removed from static memory_tools()
- Most tool handlers wrapped in Arc::new() but some have paren issues

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 20:37:19 -04:00
parent d167b11283
commit 12798eeae2
15 changed files with 74 additions and 51 deletions

View file

@ -15,27 +15,27 @@ pub fn tools() -> [Tool; 6] {
Tool { name: "channel_list",
description: "List all available channels and their status (connected, unread count).",
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: |_a, _v| Box::pin(async { channel_list().await }) },
handler: Arc::new(|_a, _v| Box::pin(async { channel_list().await })) },
Tool { name: "channel_recv",
description: "Read messages from a channel.",
parameters_json: r#"{"type":"object","properties":{"channel":{"type":"string","description":"Channel path (e.g. irc.#bcachefs, telegram.kent)"},"all_new":{"type":"boolean","description":"If true, return all unconsumed messages","default":true},"min_count":{"type":"integer","description":"Minimum number of lines to return","default":20}},"required":["channel"]}"#,
handler: |_a, v| Box::pin(async move { channel_recv(&v).await }) },
handler: Arc::new(|_a, v| Box::pin(async move { channel_recv(&v).await })) },
Tool { name: "channel_send",
description: "Send a message to a channel.",
parameters_json: r#"{"type":"object","properties":{"channel":{"type":"string","description":"Channel path (e.g. irc.#bcachefs, irc.pm.nick, telegram.kent)"},"message":{"type":"string","description":"Message to send"}},"required":["channel","message"]}"#,
handler: |_a, v| Box::pin(async move { channel_send(&v).await }) },
handler: Arc::new(|_a, v| Box::pin(async move { channel_send(&v).await })) },
Tool { name: "channel_notifications",
description: "Get pending channel notifications (unread signals). Does not consume messages — use channel_recv for that.",
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: |_a, _v| Box::pin(async { channel_notifications().await }) },
handler: Arc::new(|_a, _v| Box::pin(async { channel_notifications().await })) },
Tool { name: "channel_open",
description: "Open a channel — start monitoring. For tmux: finds the pane by name and attaches pipe-pane.",
parameters_json: r#"{"type":"object","properties":{"label":{"type":"string","description":"Channel label / tmux pane name"}},"required":["label"]}"#,
handler: |_a, v| Box::pin(async move { channel_open(&v).await }) },
handler: Arc::new(|_a, v| Box::pin(async move { channel_open(&v).await })) },
Tool { name: "channel_close",
description: "Close a channel — stop monitoring and clean up.",
parameters_json: r#"{"type":"object","properties":{"channel":{"type":"string","description":"Channel path (e.g. tmux.ktest)"}},"required":["channel"]}"#,
handler: |_a, v| Box::pin(async move { channel_close(&v).await }) },
handler: Arc::new(|_a, v| Box::pin(async move { channel_close(&v).await })) },
]
}