Skip to main content

crabtalk_runtime/
bridge.rs

1//! RuntimeBridge — trait for server-specific tool dispatch.
2//!
3//! The runtime crate defines this trait. The daemon implements it to provide
4//! `ask_user`, `delegate`, and per-session CWD resolution. Embedded users
5//! get [`NoBridge`] with no-op defaults.
6
7use std::path::PathBuf;
8
9/// Trait for server-specific tool dispatch that the runtime cannot handle locally.
10pub trait RuntimeBridge: Send + Sync {
11    /// Handle `ask_user` — block until user replies.
12    fn dispatch_ask_user(
13        &self,
14        args: &str,
15        session_id: Option<u64>,
16    ) -> impl std::future::Future<Output = String> + Send {
17        let _ = (args, session_id);
18        async { "ask_user is not available in this runtime mode".to_owned() }
19    }
20
21    /// Handle `delegate` — spawn sub-agent tasks.
22    fn dispatch_delegate(
23        &self,
24        args: &str,
25        agent: &str,
26    ) -> impl std::future::Future<Output = String> + Send {
27        let _ = (args, agent);
28        async { "delegate is not available in this runtime mode".to_owned() }
29    }
30
31    /// Resolve the working directory for a session.
32    /// Returns `None` to fall back to the runtime's base cwd.
33    fn session_cwd(&self, _session_id: u64) -> Option<PathBuf> {
34        None
35    }
36
37    /// Called when an agent event occurs. The daemon uses this to broadcast
38    /// protobuf events to console subscribers. Default: no-op.
39    fn on_agent_event(&self, _agent: &str, _session_id: u64, _event: &wcore::AgentEvent) {}
40}
41
42/// No-op bridge for embedded use.
43pub struct NoBridge;
44
45impl RuntimeBridge for NoBridge {}