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