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