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::new()));
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 programmatic tool calling wrapper.
46pub fn register_program(registry: &Arc<ToolRegistry>) {
47    register_program_with_catalog(
48        registry,
49        crate::program::ProgramCatalog::with_builtin_programs(),
50    );
51}
52
53/// Register the programmatic tool calling wrapper with a custom catalog.
54pub fn register_program_with_catalog(
55    registry: &Arc<ToolRegistry>,
56    catalog: crate::program::ProgramCatalog,
57) {
58    registry.register_builtin(Arc::new(crate::tools::ProgramTool::with_catalog(
59        Arc::clone(registry),
60        catalog,
61    )));
62}
63
64/// Register the task delegation tools (task, parallel_task).
65///
66/// Must be called after the registry is wrapped in Arc. Requires an LLM client
67/// and the workspace path so child agent loops can be spawned inline.
68/// Optionally accepts an MCP manager so child sessions inherit MCP tools.
69pub fn register_task(
70    registry: &Arc<ToolRegistry>,
71    llm_client: Arc<dyn crate::llm::LlmClient>,
72    agent_registry: Arc<crate::subagent::AgentRegistry>,
73    workspace: String,
74) {
75    register_task_with_mcp(registry, llm_client, agent_registry, workspace, None);
76}
77
78/// Register the task delegation tools with optional MCP manager.
79///
80/// When `mcp_manager` is provided, child subagent sessions will have access
81/// to all MCP tools from connected servers.
82pub fn register_task_with_mcp(
83    registry: &Arc<ToolRegistry>,
84    llm_client: Arc<dyn crate::llm::LlmClient>,
85    agent_registry: Arc<crate::subagent::AgentRegistry>,
86    workspace: String,
87    mcp_manager: Option<Arc<crate::mcp::manager::McpManager>>,
88) {
89    use crate::tools::task::{ParallelTaskTool, TaskExecutor, TaskTool};
90    let executor = Arc::new(match mcp_manager {
91        Some(mcp) => TaskExecutor::with_mcp(agent_registry, llm_client, workspace, mcp),
92        None => TaskExecutor::new(agent_registry, llm_client, workspace),
93    });
94    registry.register_builtin(Arc::new(TaskTool::new(Arc::clone(&executor))));
95    registry.register_builtin(Arc::new(ParallelTaskTool::new(Arc::clone(&executor))));
96}
97
98/// Register the Skill tool for skill-based tool access control.
99pub(crate) fn register_skill(
100    registry: &Arc<ToolRegistry>,
101    llm_client: Arc<dyn crate::llm::LlmClient>,
102    skill_registry: Arc<crate::skills::SkillRegistry>,
103    tool_executor: Arc<crate::tools::ToolExecutor>,
104    base_config: crate::agent::AgentConfig,
105) {
106    use crate::tools::skill::{SearchSkillsTool, SkillTool};
107    registry.register_builtin(Arc::new(SearchSkillsTool::new(Arc::clone(&skill_registry))));
108    registry.register_builtin(Arc::new(SkillTool::new(
109        skill_registry,
110        llm_client,
111        tool_executor,
112        base_config,
113    )));
114}