pub struct ToolManager { /* private fields */ }Implementations§
Source§impl ToolManager
impl ToolManager
pub fn new() -> Self
Sourcepub fn set_path_guard(&mut self, guard: PathGuard)
pub fn set_path_guard(&mut self, guard: PathGuard)
Confine the built-in file tools (ls, read, write, edit,
grep, glob) to the paths the guard allows.
Must be called before ToolManager::register_defaults: the
guard is checked in ToolManager::execute_tool_call and cloned
into the ls/read/write/edit handlers, which verify the opened
file descriptor against it (closing the check-then-open race).
Sourcepub fn path_guard(&self) -> Option<&PathGuard>
pub fn path_guard(&self) -> Option<&PathGuard>
The active path guard, if any.
Sourcepub fn set_sandbox(&mut self, sandbox: Sandbox)
pub fn set_sandbox(&mut self, sandbox: Sandbox)
Enable the OS-level sandbox for run and custom tools.
Must be called before register_defaults and
register_custom_tools: tool handlers are opaque closures, so the
sandbox is cloned into them at construction. Setting it afterwards
leaves the already-registered tools unsandboxed.
Sourcepub fn guard_arguments(
&self,
tool_name: &str,
arguments: &Value,
) -> Result<Value, String>
pub fn guard_arguments( &self, tool_name: &str, arguments: &Value, ) -> Result<Value, String>
Validate a tool call’s path arguments against the guard and return arguments with every path replaced by its resolved absolute form.
Substitution is the point: a handler that received the raw string would resolve a relative path against the process cwd, while the guard resolved it against the workspace root. Those coincide only when the harness happens to be started in the workspace, so checking one and opening the other leaves the containment purely incidental.
Returns Err(violation_message) when the guard rejects a path, or the
arguments unchanged when no guard is active.
Sourcepub fn register_defaults(&mut self)
pub fn register_defaults(&mut self)
Register all built-in tools.
pub fn register_tool(&mut self, tool: Tool)
Sourcepub fn register_custom_tools(&mut self, tools: &[CustomToolDefinition])
pub fn register_custom_tools(&mut self, tools: &[CustomToolDefinition])
Register custom tools from crate::custom_tools::CustomToolManager.
Tools whose names collide with built-in tools are silently skipped.
Sourcepub fn get_all_tool_definitions(&self) -> Vec<ToolDefinition>
pub fn get_all_tool_definitions(&self) -> Vec<ToolDefinition>
Returns the tool definitions for all registered tools.
Sourcepub fn tools_for_mode(
&self,
mode: AgentMode,
availability: ToolAvailability,
) -> Vec<ToolDefinition>
pub fn tools_for_mode( &self, mode: AgentMode, availability: ToolAvailability, ) -> Vec<ToolDefinition>
Returns the tool definitions appropriate for the given agent mode.
Tools disabled in availability (e.g. auto_compact, question) are
excluded, so the model never sees them.
Sourcepub fn category_of(&self, tool_name: &str) -> Option<ToolCategory>
pub fn category_of(&self, tool_name: &str) -> Option<ToolCategory>
Returns the category of a tool by name, or None if not found.
Sourcepub fn needs_approval(&self, tool_name: &str) -> bool
pub fn needs_approval(&self, tool_name: &str) -> bool
Returns true if the tool requires user approval before execution.
Destructive tools (write, edit, run) and signal tools (switch_mode,
question, auto_compact) require approval.
Sourcepub fn is_signal_tool(&self, tool_name: &str) -> bool
pub fn is_signal_tool(&self, tool_name: &str) -> bool
Returns true if the tool is a signal tool (switch_mode, question, auto_compact).
Signal tools are handled specially by the agent loop rather than executed generically.
Sourcepub fn parse_signal_event(
&self,
tool_name: &str,
arguments: &Value,
) -> Option<SignalEvent>
pub fn parse_signal_event( &self, tool_name: &str, arguments: &Value, ) -> Option<SignalEvent>
Parse a signal tool’s result string into a structured SignalEvent.
Signal tools return plain strings, but the agent loop needs structured data to dispatch them correctly. This method interprets the tool call arguments (not the result string) to produce the appropriate event.
Returns None if the tool is not a signal tool or the arguments are invalid.