pub mod adapter;
pub mod code;
pub mod data_processing;
pub mod file_ops;
pub mod git_tools;
pub mod memory_tools;
pub mod network;
pub mod network_tools;
pub mod search;
pub mod shell;
pub mod system_tools;
pub mod text_tools;
pub mod web_search;
pub mod workflow_tools;
pub use adapter::{register_builtin_tools, ToolAdapter};
use crate::types::{Layer3Result, ToolCategory, ToolMeta};
use async_trait::async_trait;
use std::collections::HashMap;
#[async_trait]
pub trait BuiltinTool: Send + Sync {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn parameters_schema(&self) -> serde_json::Value;
fn category(&self) -> ToolCategory;
fn requires_confirmation(&self) -> bool {
false
}
fn is_dangerous(&self) -> bool {
false
}
async fn execute(&self, args: serde_json::Value) -> Layer3Result<String>;
fn meta(&self) -> ToolMeta {
ToolMeta {
name: self.name().to_string(),
description: self.description().to_string(),
parameters: self.parameters_schema(),
requires_confirmation: self.requires_confirmation(),
is_dangerous: self.is_dangerous(),
category: self.category(),
}
}
}
pub struct BuiltinToolRegistry {
tools: HashMap<String, Box<dyn BuiltinTool>>,
}
impl BuiltinToolRegistry {
pub fn new() -> Self {
Self {
tools: HashMap::new(),
}
}
pub fn with_defaults() -> Self {
let mut registry = Self::new();
registry.register(Box::new(shell::BashTool));
registry.register(Box::new(search::GrepTool));
registry.register(Box::new(search::GlobTool));
registry.register(Box::new(web_search::WebSearchTool::new()));
registry.register(Box::new(file_ops::ReadFileTool));
registry.register(Box::new(file_ops::WriteFileTool));
registry.register(Box::new(file_ops::EditFileTool));
registry.register(Box::new(file_ops::ListDirectoryTool));
registry.register(Box::new(file_ops::CreateDirectoryTool));
registry.register(Box::new(file_ops::MoveFileTool));
registry.register(Box::new(file_ops::CopyFileTool));
registry.register(Box::new(file_ops::DeleteFileTool));
registry.register(Box::new(workflow_tools::CreateCheckpointTool::new()));
registry.register(Box::new(workflow_tools::RestoreCheckpointTool::new()));
registry.register(Box::new(workflow_tools::ListCheckpointsTool::new()));
registry.register(Box::new(code::GoToDefinitionTool));
registry.register(Box::new(code::FindReferencesTool));
registry.register(Box::new(code::GetHoverTool));
registry.register(Box::new(code::RenameSymbolTool));
registry.register(Box::new(network::HttpRequestTool));
registry.register(Box::new(network::WebFetchTool));
registry.register(Box::new(memory_tools::SaveMemoryTool::new()));
registry.register(Box::new(memory_tools::QueryMemoryTool::new()));
registry.register(Box::new(memory_tools::ClearMemoryTool::new()));
registry.register(Box::new(data_processing::JsonParseTool));
registry.register(Box::new(data_processing::JsonStringifyTool));
registry.register(Box::new(data_processing::YamlParseTool));
registry.register(Box::new(data_processing::YamlStringifyTool));
registry.register(Box::new(data_processing::TomlParseTool));
registry.register(Box::new(data_processing::CsvParseTool));
registry.register(Box::new(data_processing::Base64EncodeTool));
registry.register(Box::new(data_processing::Base64DecodeTool));
registry.register(Box::new(data_processing::UrlEncodeTool));
registry.register(Box::new(data_processing::UrlDecodeTool));
registry.register(Box::new(data_processing::HashTool));
registry.register(Box::new(data_processing::UuidGenerateTool));
registry.register(Box::new(network_tools::HttpGetTool));
registry.register(Box::new(network_tools::HttpPostTool));
registry.register(Box::new(network_tools::DownloadFileTool));
registry.register(Box::new(network_tools::PingTool));
registry.register(Box::new(network_tools::DnsLookupTool));
registry.register(Box::new(git_tools::GitStatusTool));
registry.register(Box::new(git_tools::GitLogTool));
registry.register(Box::new(git_tools::GitDiffTool));
registry.register(Box::new(git_tools::GitBranchTool));
registry.register(Box::new(git_tools::GitAddTool));
registry.register(Box::new(git_tools::GitCommitTool));
registry.register(Box::new(git_tools::GitShowTool));
registry.register(Box::new(git_tools::GitStashTool));
registry.register(Box::new(system_tools::GetEnvTool));
registry.register(Box::new(system_tools::ListEnvTool));
registry.register(Box::new(system_tools::SetEnvTool));
registry.register(Box::new(system_tools::GetCwdTool));
registry.register(Box::new(system_tools::ChangeDirTool));
registry.register(Box::new(system_tools::SystemInfoTool));
registry.register(Box::new(system_tools::ProcessListTool));
registry.register(Box::new(system_tools::DiskUsageTool));
registry.register(Box::new(system_tools::MemoryUsageTool));
registry.register(Box::new(text_tools::CountLinesTool));
registry.register(Box::new(text_tools::WordFrequencyTool));
registry.register(Box::new(text_tools::TextTransformTool));
registry.register(Box::new(text_tools::TextSplitTool));
registry.register(Box::new(text_tools::RegexMatchTool));
registry.register(Box::new(text_tools::TextDiffTool));
registry.register(Box::new(text_tools::SortLinesTool));
registry
}
pub fn register(&mut self, tool: Box<dyn BuiltinTool>) {
let name = tool.name().to_string();
self.tools.insert(name, tool);
}
pub fn get(&self, name: &str) -> Option<&dyn BuiltinTool> {
self.tools.get(name).map(|b| b.as_ref())
}
pub fn list(&self) -> Vec<&dyn BuiltinTool> {
self.tools.values().map(|b| b.as_ref()).collect()
}
pub fn list_meta(&self) -> Vec<ToolMeta> {
self.tools.values().map(|t| t.meta()).collect()
}
pub fn list_by_category(&self, category: ToolCategory) -> Vec<&dyn BuiltinTool> {
self.tools
.values()
.filter(|t| t.category() == category)
.map(|b| b.as_ref())
.collect()
}
}
impl Default for BuiltinToolRegistry {
fn default() -> Self {
Self::new()
}
}
pub const FILE_OPS_TOOLS: &[&str] = &[
"read_file",
"write_file",
"edit_file",
"create_file",
"delete_file",
"list_directory",
"copy_file",
"move_file",
];
pub const SEARCH_TOOLS: &[&str] = &["grep", "glob", "find_in_files", "search_content"];
pub const SHELL_TOOLS: &[&str] = &["bash", "run_command", "shell_exec"];
pub const CODE_TOOLS: &[&str] = &[
"go_to_definition",
"find_references",
"get_hover",
"list_symbols",
];
pub const MEMORY_TOOLS: &[&str] = &["save_memory", "load_memory", "query_memory", "clear_memory"];
pub const WORKFLOW_TOOLS: &[&str] = &[
"create_checkpoint",
"restore_checkpoint",
"list_checkpoints",
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_registry_creation() {
let registry = BuiltinToolRegistry::new();
assert!(registry.list().is_empty());
}
#[test]
fn test_tool_categories() {
assert!(!FILE_OPS_TOOLS.is_empty());
assert!(!SEARCH_TOOLS.is_empty());
}
}