Skip to main content

ai_agent/tools/
mod.rs

1pub mod agent;
2pub mod assemble;
3pub mod ask;
4pub mod brief;
5pub mod bash;
6pub mod config;
7pub mod config_tools;
8pub mod cron;
9pub mod deferred_tools;
10pub mod edit;
11pub mod glob;
12pub mod discover_skills;
13pub mod grep;
14pub mod lsp;
15pub mod mcp;
16pub mod mcp_resource_reader;
17pub mod mcp_resources;
18pub mod mcp_tool;
19pub mod mcp_auth;
20pub mod monitor;
21pub mod notebook_edit;
22pub mod orchestration;
23pub mod placeholder;
24pub mod plan;
25pub mod powershell;
26pub mod read;
27pub mod remote_trigger;
28pub mod repl;
29pub mod search;
30pub mod send_user_file;
31pub mod skill;
32pub mod sleep_tool;
33pub mod snip;
34pub mod task_output;
35pub mod task_stop;
36pub mod terminal_capture;
37pub mod tasks;
38pub mod team;
39pub mod todo;
40pub mod types;
41pub mod synthetic_output;
42pub mod web_browser;
43pub mod web_fetch;
44pub mod web_search;
45pub mod worktree;
46pub mod overflow_test;
47pub mod review_artifact;
48pub mod workflow;
49pub mod write;
50
51pub use types::{
52    Tool, ToolDefinition, ToolFuture, ToolInputSchema, filter_tools, get_all_base_tools,
53};
54pub use assemble::{assemble_tool_pool, filter_tools_by_deny_rules};
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_get_all_base_tools_returns_all_tools() {
62        let tools = get_all_base_tools();
63        // Should have 50 built-in tools (42 + OverflowTest + ReviewArtifact + Workflow + Snip + DiscoverSkills + TerminalCapture + MCPTool + McpAuth)
64        assert_eq!(tools.len(), 50);
65    }
66
67    #[test]
68    fn test_get_all_base_tools_contains_bash_tool() {
69        let tools = get_all_base_tools();
70        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
71        assert!(tool_names.contains(&"Bash"));
72    }
73
74    #[test]
75    fn test_get_all_base_tools_contains_file_read_tool() {
76        let tools = get_all_base_tools();
77        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
78        assert!(tool_names.contains(&"Read"));
79    }
80
81    #[test]
82    fn test_get_all_base_tools_contains_file_write_tool() {
83        let tools = get_all_base_tools();
84        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
85        assert!(tool_names.contains(&"Write"));
86    }
87
88    #[test]
89    fn test_get_all_base_tools_contains_glob_tool() {
90        let tools = get_all_base_tools();
91        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
92        assert!(tool_names.contains(&"Glob"));
93    }
94
95    #[test]
96    fn test_get_all_base_tools_contains_grep_tool() {
97        let tools = get_all_base_tools();
98        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
99        assert!(tool_names.contains(&"Grep"));
100    }
101
102    #[test]
103    fn test_get_all_base_tools_contains_file_edit_tool() {
104        let tools = get_all_base_tools();
105        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
106        assert!(tool_names.contains(&"FileEdit"));
107    }
108
109    #[test]
110    fn test_get_all_base_tools_contains_notebook_edit_tool() {
111        let tools = get_all_base_tools();
112        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
113        assert!(tool_names.contains(&"NotebookEdit"));
114    }
115
116    #[test]
117    fn test_get_all_base_tools_contains_web_fetch_tool() {
118        let tools = get_all_base_tools();
119        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
120        assert!(tool_names.contains(&"WebFetch"));
121    }
122
123    #[test]
124    fn test_get_all_base_tools_contains_web_search_tool() {
125        let tools = get_all_base_tools();
126        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
127        assert!(tool_names.contains(&"WebSearch"));
128    }
129
130    #[test]
131    fn test_get_all_base_tools_contains_agent_tool() {
132        let tools = get_all_base_tools();
133        let tool_names: Vec<&str> = tools.iter().map(|t| t.name.as_str()).collect();
134        assert!(tool_names.contains(&"Agent"));
135    }
136
137    #[test]
138    fn test_filter_tools_by_allowed() {
139        let tools = vec![
140            ToolDefinition {
141                name: "Bash".to_string(),
142                description: "Execute shell commands".to_string(),
143                input_schema: ToolInputSchema {
144                    schema_type: "object".to_string(),
145                    properties: serde_json::json!({}),
146                    required: None,
147                },
148                annotations: None,
149                should_defer: None,
150                always_load: None,
151                is_mcp: None,
152                search_hint: None,
153                aliases: None,
154                user_facing_name: None,
155                interrupt_behavior: None,
156            },
157            ToolDefinition {
158                name: "Read".to_string(),
159                description: "Read files".to_string(),
160                input_schema: ToolInputSchema {
161                    schema_type: "object".to_string(),
162                    properties: serde_json::json!({}),
163                    required: None,
164                },
165                annotations: None,
166                should_defer: None,
167                always_load: None,
168                is_mcp: None,
169                search_hint: None,
170                aliases: None,
171                user_facing_name: None,
172                interrupt_behavior: None,
173            },
174        ];
175        let filtered = filter_tools(tools, Some(vec!["Bash".to_string()]), None);
176        assert_eq!(filtered.len(), 1);
177        assert_eq!(filtered[0].name, "Bash");
178    }
179
180    #[test]
181    fn test_filter_tools_by_disallowed() {
182        let tools = vec![
183            ToolDefinition {
184                name: "Bash".to_string(),
185                description: "Execute shell commands".to_string(),
186                input_schema: ToolInputSchema {
187                    schema_type: "object".to_string(),
188                    properties: serde_json::json!({}),
189                    required: None,
190                },
191                annotations: None,
192                should_defer: None,
193                always_load: None,
194                is_mcp: None,
195                search_hint: None,
196                aliases: None,
197                user_facing_name: None,
198                interrupt_behavior: None,
199            },
200            ToolDefinition {
201                name: "Read".to_string(),
202                description: "Read files".to_string(),
203                input_schema: ToolInputSchema {
204                    schema_type: "object".to_string(),
205                    properties: serde_json::json!({}),
206                    required: None,
207                },
208                annotations: None,
209                should_defer: None,
210                always_load: None,
211                is_mcp: None,
212                search_hint: None,
213                aliases: None,
214                user_facing_name: None,
215                interrupt_behavior: None,
216            },
217        ];
218        let filtered = filter_tools(tools, None, Some(vec!["Bash".to_string()]));
219        assert_eq!(filtered.len(), 1);
220        assert_eq!(filtered[0].name, "Read");
221    }
222}