pub(crate) mod bash;
pub mod batch;
mod edit;
mod generate_object;
pub(crate) mod git;
mod glob_tool;
mod grep;
mod ls;
mod patch;
mod read;
mod web_fetch;
mod web_search;
mod write;
use super::registry::ToolRegistry;
use std::sync::Arc;
pub fn register_builtins(
registry: &ToolRegistry,
capabilities: &crate::workspace::WorkspaceCapabilities,
) {
if capabilities.read {
registry.register_builtin(Arc::new(read::ReadTool));
registry.register_builtin(Arc::new(ls::LsTool));
}
if capabilities.write {
registry.register_builtin(Arc::new(write::WriteTool));
}
if capabilities.read && capabilities.write {
registry.register_builtin(Arc::new(edit::EditTool));
registry.register_builtin(Arc::new(patch::PatchTool));
}
if capabilities.exec {
registry.register_builtin(Arc::new(bash::BashTool));
}
if capabilities.search {
registry.register_builtin(Arc::new(grep::GrepTool));
registry.register_builtin(Arc::new(glob_tool::GlobTool));
}
if capabilities.git {
registry.register_builtin(Arc::new(git::GitTool));
}
registry.register_builtin(Arc::new(web_fetch::WebFetchTool));
registry.register_builtin(Arc::new(web_search::WebSearchTool::new()));
}
pub fn register_batch(registry: &Arc<ToolRegistry>) {
registry.register_builtin(Arc::new(batch::BatchTool::new(Arc::clone(registry))));
}
pub fn register_program(registry: &Arc<ToolRegistry>) {
register_program_with_catalog(
registry,
crate::program::ProgramCatalog::with_builtin_programs(),
);
}
pub fn register_program_with_catalog(
registry: &Arc<ToolRegistry>,
catalog: crate::program::ProgramCatalog,
) {
registry.register_builtin(Arc::new(crate::tools::ProgramTool::with_catalog(
Arc::clone(registry),
catalog,
)));
}
pub fn register_task(
registry: &Arc<ToolRegistry>,
llm_client: Arc<dyn crate::llm::LlmClient>,
agent_registry: Arc<crate::subagent::AgentRegistry>,
workspace: String,
) {
register_task_with_mcp(
registry,
llm_client,
agent_registry,
workspace,
None,
None,
None,
);
}
pub fn register_task_with_mcp(
registry: &Arc<ToolRegistry>,
llm_client: Arc<dyn crate::llm::LlmClient>,
agent_registry: Arc<crate::subagent::AgentRegistry>,
workspace: String,
mcp_manager: Option<Arc<crate::mcp::manager::McpManager>>,
parent_context: Option<crate::child_run::ChildRunContext>,
subagent_tracker: Option<Arc<crate::subagent_task_tracker::InMemorySubagentTaskTracker>>,
) {
use crate::tools::task::{ParallelTaskTool, TaskExecutor, TaskTool};
let mut executor = match mcp_manager {
Some(mcp) => TaskExecutor::with_mcp(agent_registry, llm_client, workspace, mcp),
None => TaskExecutor::new(agent_registry, llm_client, workspace),
};
if let Some(ctx) = parent_context {
executor = executor.with_parent_context(ctx);
}
if let Some(tracker) = subagent_tracker {
executor = executor.with_subagent_tracker(tracker);
}
let executor = Arc::new(executor);
registry.register_builtin(Arc::new(TaskTool::new(Arc::clone(&executor))));
registry.register_builtin(Arc::new(ParallelTaskTool::new(Arc::clone(&executor))));
}
pub(crate) fn register_skill(
registry: &Arc<ToolRegistry>,
llm_client: Arc<dyn crate::llm::LlmClient>,
skill_registry: Arc<crate::skills::SkillRegistry>,
tool_executor: Arc<crate::tools::ToolExecutor>,
base_config: crate::agent::AgentConfig,
) {
use crate::tools::skill::{SearchSkillsTool, SkillTool};
registry.register_builtin(Arc::new(SearchSkillsTool::new(Arc::clone(&skill_registry))));
registry.register_builtin(Arc::new(SkillTool::new(
skill_registry,
llm_client,
tool_executor,
base_config,
)));
}
pub fn register_generate_object(
registry: &Arc<ToolRegistry>,
llm_client: Arc<dyn crate::llm::LlmClient>,
) {
registry.register_builtin(Arc::new(generate_object::GenerateObjectTool::new(
llm_client,
)));
}