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;
8mod edit;
9mod git;
10mod glob_tool;
11mod grep;
12mod ls;
13mod patch;
14mod read;
15mod web_fetch;
16mod web_search;
17mod write;
18
19use super::registry::ToolRegistry;
20use std::sync::Arc;
21
22/// Register all baseline built-in tools with the registry.
23///
24/// Note: `batch` is NOT registered here — it requires an `Arc<ToolRegistry>`
25/// and must be registered after the registry is wrapped in an Arc.
26pub fn register_builtins(registry: &ToolRegistry) {
27    registry.register_builtin(Arc::new(read::ReadTool));
28    registry.register_builtin(Arc::new(write::WriteTool));
29    registry.register_builtin(Arc::new(edit::EditTool));
30    registry.register_builtin(Arc::new(patch::PatchTool));
31    registry.register_builtin(Arc::new(bash::BashTool));
32    registry.register_builtin(Arc::new(grep::GrepTool));
33    registry.register_builtin(Arc::new(glob_tool::GlobTool));
34    registry.register_builtin(Arc::new(ls::LsTool));
35    registry.register_builtin(Arc::new(web_fetch::WebFetchTool));
36    registry.register_builtin(Arc::new(web_search::WebSearchTool));
37    registry.register_builtin(Arc::new(git::GitTool));
38}
39
40/// Register the batch tool. Must be called after the registry is wrapped in Arc.
41pub fn register_batch(registry: &Arc<ToolRegistry>) {
42    registry.register_builtin(Arc::new(batch::BatchTool::new(Arc::clone(registry))));
43}
44
45/// Register the task delegation tools (task, parallel_task).
46///
47/// Must be called after the registry is wrapped in Arc. Requires an LLM client
48/// and the workspace path so child agent loops can be spawned inline.
49/// Optionally accepts an MCP manager so child sessions inherit MCP tools.
50pub fn register_task(
51    registry: &Arc<ToolRegistry>,
52    llm_client: Arc<dyn crate::llm::LlmClient>,
53    agent_registry: Arc<crate::subagent::AgentRegistry>,
54    workspace: String,
55) {
56    register_task_with_mcp(registry, llm_client, agent_registry, workspace, None);
57}
58
59/// Register the task delegation tools with optional MCP manager.
60///
61/// When `mcp_manager` is provided, child subagent sessions will have access
62/// to all MCP tools from connected servers.
63pub fn register_task_with_mcp(
64    registry: &Arc<ToolRegistry>,
65    llm_client: Arc<dyn crate::llm::LlmClient>,
66    agent_registry: Arc<crate::subagent::AgentRegistry>,
67    workspace: String,
68    mcp_manager: Option<Arc<crate::mcp::manager::McpManager>>,
69) {
70    use crate::tools::task::{ParallelTaskTool, RunTeamTool, TaskExecutor, TaskTool};
71    let executor = Arc::new(match mcp_manager {
72        Some(mcp) => TaskExecutor::with_mcp(agent_registry, llm_client, workspace, mcp),
73        None => TaskExecutor::new(agent_registry, llm_client, workspace),
74    });
75    registry.register_builtin(Arc::new(TaskTool::new(Arc::clone(&executor))));
76    registry.register_builtin(Arc::new(ParallelTaskTool::new(Arc::clone(&executor))));
77    registry.register_builtin(Arc::new(RunTeamTool::new(executor)));
78}
79
80/// Register the Skill tool for skill-based tool access control.
81pub fn register_skill(
82    registry: &Arc<ToolRegistry>,
83    llm_client: Arc<dyn crate::llm::LlmClient>,
84    skill_registry: Arc<crate::skills::SkillRegistry>,
85    tool_executor: Arc<crate::tools::ToolExecutor>,
86    base_config: crate::agent::AgentConfig,
87) {
88    use crate::tools::skill::SkillTool;
89    registry.register_builtin(Arc::new(SkillTool::new(
90        skill_registry,
91        llm_client,
92        tool_executor,
93        base_config,
94    )));
95}