Skip to main content

agent_commander/tools/
mod.rs

1//! Tool configurations and utilities
2//! Provides configuration for different CLI agents: claude, codex, opencode, agent, gemini, qwen
3
4pub mod agent;
5pub mod claude;
6pub mod codex;
7pub mod gemini;
8pub mod opencode;
9pub mod qwen;
10pub(crate) mod shell;
11pub(crate) mod usage;
12
13use std::collections::HashMap;
14
15pub use agent::{AgentBuildOptions, AgentTool, AgentUsage, ErrorResult};
16pub use claude::{ClaudeBuildOptions, ClaudeTool, ClaudeUsage};
17pub use codex::{CodexBuildOptions, CodexTool, CodexUsage};
18pub use gemini::{GeminiBuildOptions, GeminiErrorResult, GeminiTool, GeminiUsage};
19pub use opencode::{OpencodeBuildOptions, OpencodeTool, OpencodeUsage};
20pub use qwen::{QwenBuildOptions, QwenErrorResult, QwenTool, QwenUsage};
21
22/// Generic tool trait
23pub trait Tool {
24    fn name(&self) -> &'static str;
25    fn display_name(&self) -> &'static str;
26    fn executable(&self) -> &'static str;
27    fn supports_json_output(&self) -> bool;
28    fn supports_json_input(&self) -> bool;
29    fn supports_system_prompt(&self) -> bool;
30    fn supports_resume(&self) -> bool;
31    fn default_model(&self) -> &'static str;
32}
33
34impl Tool for ClaudeTool {
35    fn name(&self) -> &'static str {
36        self.name
37    }
38    fn display_name(&self) -> &'static str {
39        self.display_name
40    }
41    fn executable(&self) -> &'static str {
42        self.executable
43    }
44    fn supports_json_output(&self) -> bool {
45        self.supports_json_output
46    }
47    fn supports_json_input(&self) -> bool {
48        self.supports_json_input
49    }
50    fn supports_system_prompt(&self) -> bool {
51        self.supports_system_prompt
52    }
53    fn supports_resume(&self) -> bool {
54        self.supports_resume
55    }
56    fn default_model(&self) -> &'static str {
57        self.default_model
58    }
59}
60
61impl Tool for CodexTool {
62    fn name(&self) -> &'static str {
63        self.name
64    }
65    fn display_name(&self) -> &'static str {
66        self.display_name
67    }
68    fn executable(&self) -> &'static str {
69        self.executable
70    }
71    fn supports_json_output(&self) -> bool {
72        self.supports_json_output
73    }
74    fn supports_json_input(&self) -> bool {
75        self.supports_json_input
76    }
77    fn supports_system_prompt(&self) -> bool {
78        self.supports_system_prompt
79    }
80    fn supports_resume(&self) -> bool {
81        self.supports_resume
82    }
83    fn default_model(&self) -> &'static str {
84        self.default_model
85    }
86}
87
88impl Tool for OpencodeTool {
89    fn name(&self) -> &'static str {
90        self.name
91    }
92    fn display_name(&self) -> &'static str {
93        self.display_name
94    }
95    fn executable(&self) -> &'static str {
96        self.executable
97    }
98    fn supports_json_output(&self) -> bool {
99        self.supports_json_output
100    }
101    fn supports_json_input(&self) -> bool {
102        self.supports_json_input
103    }
104    fn supports_system_prompt(&self) -> bool {
105        self.supports_system_prompt
106    }
107    fn supports_resume(&self) -> bool {
108        self.supports_resume
109    }
110    fn default_model(&self) -> &'static str {
111        self.default_model
112    }
113}
114
115impl Tool for AgentTool {
116    fn name(&self) -> &'static str {
117        self.name
118    }
119    fn display_name(&self) -> &'static str {
120        self.display_name
121    }
122    fn executable(&self) -> &'static str {
123        self.executable
124    }
125    fn supports_json_output(&self) -> bool {
126        self.supports_json_output
127    }
128    fn supports_json_input(&self) -> bool {
129        self.supports_json_input
130    }
131    fn supports_system_prompt(&self) -> bool {
132        self.supports_system_prompt
133    }
134    fn supports_resume(&self) -> bool {
135        self.supports_resume
136    }
137    fn default_model(&self) -> &'static str {
138        self.default_model
139    }
140}
141
142impl Tool for GeminiTool {
143    fn name(&self) -> &'static str {
144        self.name
145    }
146    fn display_name(&self) -> &'static str {
147        self.display_name
148    }
149    fn executable(&self) -> &'static str {
150        self.executable
151    }
152    fn supports_json_output(&self) -> bool {
153        self.supports_json_output
154    }
155    fn supports_json_input(&self) -> bool {
156        self.supports_json_input
157    }
158    fn supports_system_prompt(&self) -> bool {
159        self.supports_system_prompt
160    }
161    fn supports_resume(&self) -> bool {
162        self.supports_resume
163    }
164    fn default_model(&self) -> &'static str {
165        self.default_model
166    }
167}
168
169impl Tool for QwenTool {
170    fn name(&self) -> &'static str {
171        self.name
172    }
173    fn display_name(&self) -> &'static str {
174        self.display_name
175    }
176    fn executable(&self) -> &'static str {
177        self.executable
178    }
179    fn supports_json_output(&self) -> bool {
180        self.supports_json_output
181    }
182    fn supports_json_input(&self) -> bool {
183        self.supports_json_input
184    }
185    fn supports_system_prompt(&self) -> bool {
186        self.supports_system_prompt
187    }
188    fn supports_resume(&self) -> bool {
189        self.supports_resume
190    }
191    fn default_model(&self) -> &'static str {
192        self.default_model
193    }
194}
195
196/// Tool registry for all supported tools
197pub struct ToolRegistry {
198    tools: HashMap<&'static str, Box<dyn Tool + Send + Sync>>,
199}
200
201impl Default for ToolRegistry {
202    fn default() -> Self {
203        Self::new()
204    }
205}
206
207impl ToolRegistry {
208    /// Create a new tool registry with all supported tools
209    pub fn new() -> Self {
210        let mut tools: HashMap<&'static str, Box<dyn Tool + Send + Sync>> = HashMap::new();
211        tools.insert("claude", Box::new(ClaudeTool::default()));
212        tools.insert("codex", Box::new(CodexTool::default()));
213        tools.insert("opencode", Box::new(OpencodeTool::default()));
214        tools.insert("agent", Box::new(AgentTool::default()));
215        tools.insert("gemini", Box::new(GeminiTool::default()));
216        tools.insert("qwen", Box::new(QwenTool::default()));
217        Self { tools }
218    }
219
220    /// Get tool by name
221    pub fn get(&self, name: &str) -> Option<&(dyn Tool + Send + Sync)> {
222        self.tools.get(name).map(|t| t.as_ref())
223    }
224
225    /// Check if a tool is supported
226    pub fn is_supported(&self, name: &str) -> bool {
227        self.tools.contains_key(name)
228    }
229
230    /// List all available tool names
231    pub fn list(&self) -> Vec<&'static str> {
232        self.tools.keys().copied().collect()
233    }
234}
235
236/// Get tool configuration by name
237///
238/// # Arguments
239/// * `tool_name` - Name of the tool
240///
241/// # Returns
242/// Result with tool reference or error
243pub fn get_tool(tool_name: &str) -> Result<Box<dyn Tool + Send + Sync>, String> {
244    match tool_name {
245        "claude" => Ok(Box::new(ClaudeTool::default())),
246        "codex" => Ok(Box::new(CodexTool::default())),
247        "opencode" => Ok(Box::new(OpencodeTool::default())),
248        "agent" => Ok(Box::new(AgentTool::default())),
249        "gemini" => Ok(Box::new(GeminiTool::default())),
250        "qwen" => Ok(Box::new(QwenTool::default())),
251        _ => Err(format!(
252            "Unknown tool: {}. Available tools: claude, codex, opencode, agent, gemini, qwen",
253            tool_name
254        )),
255    }
256}
257
258/// List available tools
259pub fn list_tools() -> Vec<&'static str> {
260    vec!["claude", "codex", "opencode", "agent", "gemini", "qwen"]
261}
262
263/// Check if a tool is supported
264///
265/// # Arguments
266/// * `tool_name` - Name of the tool
267///
268/// # Returns
269/// True if tool is supported
270pub fn is_tool_supported(tool_name: &str) -> bool {
271    ["claude", "codex", "opencode", "agent", "gemini", "qwen"].contains(&tool_name)
272}
273
274// Tests are in rust/tests/tools_tests.rs