Skip to main content

ironflow_core/provider/
tool.rs

1//! [`Tool`] -- the tools an agent may be allowed or denied.
2
3use strum::Display;
4
5/// A tool an agent can call, for [`AgentConfig::allow_tool`](super::AgentConfig::allow_tool)
6/// [`AgentConfig::disallowed_tools`](super::AgentConfig::disallowed_tools)
7/// and [`AgentConfig::available_tools`](super::AgentConfig::available_tools).
8///
9/// The known variants are the Claude Code built-in tools; a misspelled
10/// variant does not compile, where a misspelled string is silently ignored by
11/// the CLI. [`Custom`](Tool::Custom) carries anything else verbatim: an MCP
12/// tool (`mcp__server__tool`) or a permission pattern (`Bash(git log:*)`).
13///
14/// # Examples
15///
16/// ```
17/// use ironflow_core::provider::Tool;
18///
19/// assert_eq!(Tool::WebSearch.to_string(), "WebSearch");
20/// assert_eq!(Tool::Custom("mcp__github__search".to_string()).to_string(), "mcp__github__search");
21/// ```
22#[derive(Debug, Clone, PartialEq, Eq, Hash, Display)]
23pub enum Tool {
24    /// Run shell commands.
25    Bash,
26    /// Read files.
27    Read,
28    /// Create or overwrite files.
29    Write,
30    /// Edit files in place.
31    Edit,
32    /// Find files by glob pattern.
33    Glob,
34    /// Search file contents.
35    Grep,
36    /// Fetch a URL.
37    WebFetch,
38    /// Search the web.
39    WebSearch,
40    /// Edit Jupyter notebooks.
41    NotebookEdit,
42    /// Maintain a todo list.
43    TodoWrite,
44    /// Delegate to a sub-agent.
45    Task,
46    /// Any other tool name or permission pattern, passed as is.
47    #[strum(transparent)]
48    Custom(String),
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn known_tools_use_the_claude_code_names() {
57        let names: Vec<String> = [
58            Tool::Bash,
59            Tool::Read,
60            Tool::Write,
61            Tool::Edit,
62            Tool::Glob,
63            Tool::Grep,
64            Tool::WebFetch,
65            Tool::WebSearch,
66            Tool::NotebookEdit,
67            Tool::TodoWrite,
68            Tool::Task,
69        ]
70        .iter()
71        .map(Tool::to_string)
72        .collect::<Vec<_>>();
73        assert_eq!(
74            names,
75            vec![
76                "Bash",
77                "Read",
78                "Write",
79                "Edit",
80                "Glob",
81                "Grep",
82                "WebFetch",
83                "WebSearch",
84                "NotebookEdit",
85                "TodoWrite",
86                "Task"
87            ]
88        );
89    }
90
91    #[test]
92    fn custom_tools_are_passed_verbatim() {
93        assert_eq!(
94            Tool::Custom("mcp__github__search".to_string()).to_string(),
95            "mcp__github__search"
96        );
97        assert_eq!(
98            Tool::Custom("Bash(git log:*)".to_string()).to_string(),
99            "Bash(git log:*)"
100        );
101        assert_eq!(Tool::Custom("é".to_string()).to_string(), "é");
102    }
103}