Skip to main content

a3s_code_core/tools/builtin/
mod.rs

1//! Native Rust implementations of all built-in tools
2//!
3//! These replace the previous `a3s-tools` binary backend with direct Rust
4//! implementations that execute in-process. Each tool implements the `Tool` trait.
5
6mod bash;
7pub mod batch;
8pub mod codesearch;
9mod edit;
10mod git_worktree;
11mod glob_tool;
12mod grep;
13mod ls;
14mod patch;
15mod read;
16#[cfg(feature = "sandbox")]
17mod sandbox_tool;
18mod web_fetch;
19mod web_search;
20mod write;
21
22use super::registry::ToolRegistry;
23use std::sync::Arc;
24
25/// Register all built-in tools with the registry.
26///
27/// The `sandbox` tool is only registered when the `sandbox` Cargo feature is
28/// enabled. All other tools are always registered.
29///
30/// Note: `batch` is NOT registered here — it requires an `Arc<ToolRegistry>`
31/// and must be registered after the registry is wrapped in an Arc. Call
32/// `register_batch` separately once you have `Arc<ToolRegistry>`.
33pub fn register_builtins(registry: &ToolRegistry) {
34    registry.register_builtin(Arc::new(read::ReadTool));
35    registry.register_builtin(Arc::new(write::WriteTool));
36    registry.register_builtin(Arc::new(edit::EditTool));
37    registry.register_builtin(Arc::new(patch::PatchTool));
38    registry.register_builtin(Arc::new(bash::BashTool));
39    registry.register_builtin(Arc::new(grep::GrepTool));
40    registry.register_builtin(Arc::new(glob_tool::GlobTool));
41    registry.register_builtin(Arc::new(ls::LsTool));
42    registry.register_builtin(Arc::new(web_fetch::WebFetchTool));
43    registry.register_builtin(Arc::new(web_search::WebSearchTool));
44    registry.register_builtin(Arc::new(git_worktree::GitWorktreeTool));
45
46    // Register sandbox tool only when A3S Box feature is enabled.
47    #[cfg(feature = "sandbox")]
48    registry.register_builtin(Arc::new(sandbox_tool::SandboxTool::new()));
49}
50
51/// Register the batch tool. Must be called after the registry is wrapped in Arc.
52pub fn register_batch(registry: &Arc<ToolRegistry>) {
53    registry.register_builtin(Arc::new(batch::BatchTool::new(Arc::clone(registry))));
54}
55
56/// Register the task delegation tools (task, parallel_task).
57///
58/// Must be called after the registry is wrapped in Arc. Requires an LLM client
59/// and the workspace path so child agent loops can be spawned inline.
60/// Optionally accepts an MCP manager so child sessions inherit MCP tools.
61pub fn register_task(
62    registry: &Arc<ToolRegistry>,
63    llm_client: Arc<dyn crate::llm::LlmClient>,
64    agent_registry: Arc<crate::subagent::AgentRegistry>,
65    workspace: String,
66) {
67    register_task_with_mcp(registry, llm_client, agent_registry, workspace, None);
68}
69
70/// Register the task delegation tools with optional MCP manager.
71///
72/// When `mcp_manager` is provided, child subagent sessions will have access
73/// to all MCP tools from connected servers.
74pub fn register_task_with_mcp(
75    registry: &Arc<ToolRegistry>,
76    llm_client: Arc<dyn crate::llm::LlmClient>,
77    agent_registry: Arc<crate::subagent::AgentRegistry>,
78    workspace: String,
79    mcp_manager: Option<Arc<crate::mcp::manager::McpManager>>,
80) {
81    use crate::tools::task::{ParallelTaskTool, TaskExecutor, TaskTool};
82    let executor = Arc::new(match mcp_manager {
83        Some(mcp) => TaskExecutor::with_mcp(agent_registry, llm_client, workspace, mcp),
84        None => TaskExecutor::new(agent_registry, llm_client, workspace),
85    });
86    registry.register_builtin(Arc::new(TaskTool::new(Arc::clone(&executor))));
87    registry.register_builtin(Arc::new(ParallelTaskTool::new(executor)));
88}