pub struct ToolRegistry { /* private fields */ }Expand description
NOTE: Clone shares Arc state with all tools. Use fork() for isolation.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
pub async fn invoke(&self, name: &str, arguments: Value) -> Result<String>
Sourcepub async fn invoke_with_audit(
&self,
name: &str,
arguments: Value,
) -> ToolDispatch
pub async fn invoke_with_audit( &self, name: &str, arguments: Value, ) -> ToolDispatch
Invoke a tool and return both its result and a populated
AuditMeta. Callers that need to persist audit data should
use this method; callers that don’t can call invoke which
discards the audit half.
Source§impl ToolRegistry
impl ToolRegistry
pub fn new(transport: Arc<dyn ToolTransport>) -> Self
Sourcepub fn transport(&self) -> &Arc<dyn ToolTransport> ⓘ
pub fn transport(&self) -> &Arc<dyn ToolTransport> ⓘ
Returns a reference to the transport layer.
Sourcepub fn with_same_transport(&self) -> Self
pub fn with_same_transport(&self) -> Self
Create a new empty registry that shares the same transport.
Sourcepub fn fork(&self) -> Self
pub fn fork(&self) -> Self
Create an isolated copy of this registry.
Unlike clone(), fork() calls tool.fork() on each registered
tool so that tools with internal state (e.g. scratchpad, memory)
get independent copies rather than shared Arc references.
Tools that do not implement fork() (stateless tools) are simply
cloned as usual.
For now, this is equivalent to clone() — a full fork requires
per-tool fork support. This method exists as a named extension
point so call sites can opt in to isolation semantics explicitly.
Sourcepub fn with_permission_hook(self, hook: Arc<dyn PermissionHook>) -> Self
pub fn with_permission_hook(self, hook: Arc<dyn PermissionHook>) -> Self
Attach a PermissionHook (Goal 161). When set, ask_permission
is called before every tool invocation; returning false causes
invoke to return Error::PermissionDenied without running the tool.
Sourcepub fn set_permission_hook(&mut self, hook: Arc<dyn PermissionHook>)
pub fn set_permission_hook(&mut self, hook: Arc<dyn PermissionHook>)
Attach a permission hook via mutable reference.
Equivalent to [with_permission_hook] but usable on existing registries.
Sourcepub fn clear_permission_hook(&mut self)
pub fn clear_permission_hook(&mut self)
Remove any previously attached permission hook.
Sourcepub fn with_policy(self, policy: PolicyConfig) -> Self
pub fn with_policy(self, policy: PolicyConfig) -> Self
Attach an L1 policy config. The registry stores the policy so that
individual tools (e.g. run_shell) can query it via
registry.policy() at call time.
Sourcepub fn set_policy(&mut self, policy: PolicyConfig)
pub fn set_policy(&mut self, policy: PolicyConfig)
Set the L1 policy config via mutable reference.
Sourcepub fn policy(&self) -> Option<&PolicyConfig>
pub fn policy(&self) -> Option<&PolicyConfig>
Return the attached policy config, if any.
Sourcepub fn with_headless(self, headless: bool) -> Self
pub fn with_headless(self, headless: bool) -> Self
Enable headless mode (Goal 199): interactive tools go through external hooks instead of waiting for terminal input.
Sourcepub fn set_headless(&mut self, headless: bool)
pub fn set_headless(&mut self, headless: bool)
Set headless mode via mutable reference.
Sourcepub fn with_hook_runner(self, hook_runner: ExternalHookRunner) -> Self
pub fn with_hook_runner(self, hook_runner: ExternalHookRunner) -> Self
Attach an [ExternalHookRunner] for headless permission checks.
Sourcepub fn set_hook_runner(&mut self, hook_runner: ExternalHookRunner)
pub fn set_hook_runner(&mut self, hook_runner: ExternalHookRunner)
Set the external hook runner via mutable reference.
Sourcepub fn with_permissions(self, permissions: PermissionsConfig) -> Self
pub fn with_permissions(self, permissions: PermissionsConfig) -> Self
Set the permissions configuration for this registry.
Attach a SharedPermissions reference for runtime rule updates.
Unlike [with_permissions], this accepts an already-constructed
Arc<RwLock<LayeredPermissionsConfig>> so that multiple components
can share the same mutable config. Changes made via
add_session_rule / remove_session_rule on the shared config
are immediately visible through this registry.
Sourcepub fn with_auto_classifier(self, classifier: AutoClassifier) -> Self
pub fn with_auto_classifier(self, classifier: AutoClassifier) -> Self
Attach an AutoClassifier for PermissionMode::Auto.
When the registry’s permission mode is Auto,
each tool call is sent to the classifier before execution. The
classifier is wrapped in Arc<Mutex<...>> so it can be shared
across clones of the registry.
Sourcepub fn permission_mode(&self) -> PermissionMode
pub fn permission_mode(&self) -> PermissionMode
Return the current permission mode.
Sourcepub fn set_permission_mode(&mut self, mode: PermissionMode)
pub fn set_permission_mode(&mut self, mode: PermissionMode)
Update the permission mode at runtime (Claude set_permission_mode).
Writes through to the shared [LayeredPermissionsConfig] so
invoke_with_audit sees the new mode. If no shared config is attached
yet, one is created with the given mode and empty rule layers.
Shared permissions handle for mid-run control updates, if any.
Sourcepub fn permissions_config(&self) -> Option<PermissionsConfig>
pub fn permissions_config(&self) -> Option<PermissionsConfig>
Return a reference to the current permissions config, if any. Return a cloned snapshot of the current permissions config.
Uses try_read() — returns None if the lock is held for writing
(which is rare and brief). Callers that need a guaranteed read
should use [invoke_with_audit] which does an async .read().await.
Sourcepub fn is_plan_mode(&self, tool_name: &str) -> bool
pub fn is_plan_mode(&self, tool_name: &str) -> bool
Check whether a tool requires plan mode according to the current permissions configuration.
Sourcepub fn with_touched_files(self, slot: Arc<Mutex<TouchedFiles>>) -> Self
pub fn with_touched_files(self, slot: Arc<Mutex<TouchedFiles>>) -> Self
Attach a TouchedFiles collector. Tool invocations on
structured filesystem tools will record their path arguments
onto the shared collector. Used by AgentRuntime to assemble
per-turn checkpoint metadata.
Sourcepub fn clear_touched_files(&mut self)
pub fn clear_touched_files(&mut self)
Detach any previously attached collector.
Sourcepub fn touched_files(&self) -> Option<Arc<Mutex<TouchedFiles>>>
pub fn touched_files(&self) -> Option<Arc<Mutex<TouchedFiles>>>
Return the currently attached touched-files collector, if any.
Sourcepub fn with_read_file_state(self, slot: Arc<Mutex<ReadFileState>>) -> Self
pub fn with_read_file_state(self, slot: Arc<Mutex<ReadFileState>>) -> Self
Attach shared ReadFileState so ReadFile records reads and
EditTool can enforce the partial-read guard.
Sourcepub fn read_file_state(&self) -> Option<Arc<Mutex<ReadFileState>>>
pub fn read_file_state(&self) -> Option<Arc<Mutex<ReadFileState>>>
Return the currently attached read-file state, if any.
Sourcepub fn with_session_roots(self, roots: SharedSandboxRoots) -> Self
pub fn with_session_roots(self, roots: SharedSandboxRoots) -> Self
Attach a shared sandbox-roots slot for mid-run expansion.
Sourcepub fn session_roots(&self) -> Option<SharedSandboxRoots>
pub fn session_roots(&self) -> Option<SharedSandboxRoots>
Return the shared sandbox-roots slot, if any.
Sourcepub fn with_elicitation_slot(self, slot: SharedElicitationHandler) -> Self
pub fn with_elicitation_slot(self, slot: SharedElicitationHandler) -> Self
Attach a shared MCP elicitation-handler slot.
Sourcepub fn elicitation_slot(&self) -> Option<SharedElicitationHandler>
pub fn elicitation_slot(&self) -> Option<SharedElicitationHandler>
Return the shared elicitation-handler slot, if any.
pub fn register(self, tool: Arc<dyn Tool>) -> Self
Sourcepub fn register_with_aliases(
self,
tool: Arc<dyn Tool>,
aliases: &[&str],
) -> Self
pub fn register_with_aliases( self, tool: Arc<dyn Tool>, aliases: &[&str], ) -> Self
Register a tool and associate one or more aliases with it.
Aliases are not sent to the LLM — they are only used by
[find_by_name] so sandboxed replacements can be looked up under
the original name the model knows.
Sourcepub fn register_mut(&mut self, tool: Arc<dyn Tool>)
pub fn register_mut(&mut self, tool: Arc<dyn Tool>)
Register a tool via mutable reference (for use with shared registries).
Sourcepub fn register_mut_with_aliases(
&mut self,
tool: Arc<dyn Tool>,
aliases: &[&str],
)
pub fn register_mut_with_aliases( &mut self, tool: Arc<dyn Tool>, aliases: &[&str], )
Register a tool with aliases via mutable reference.
Sourcepub fn find_by_name(&self, name: &str) -> Option<Arc<dyn Tool>>
pub fn find_by_name(&self, name: &str) -> Option<Arc<dyn Tool>>
Find a registered tool by its primary name or any alias.
This is the preferred lookup path. invoke delegates to this so that
sandboxed tool replacements can be reached under the original name.
pub fn specs(&self) -> Vec<ToolSpec>
Sourcepub fn specs_partitioned(&self) -> (Vec<ToolSpec>, Vec<ToolSpec>)
pub fn specs_partitioned(&self) -> (Vec<ToolSpec>, Vec<ToolSpec>)
Return (eager_specs, deferred_specs).
Eager tools are sent to the LLM with full schemas.
Deferred tools are not — their names appear in
<available-deferred-tools> so the model can call ToolSearchTool.
Sourcepub fn retain_tools(&mut self, allow: &[String])
pub fn retain_tools(&mut self, allow: &[String])
Restrict the registry to only the named tools, removing all others.
Tool names are matched case-insensitively. Aliases for removed tools
are also dropped. Used by --allow-tools to give agents a limited
tool set (e.g. read-only review agents).
Sourcepub fn split_eager_deferred(&self) -> (Vec<SpecWithHint>, Vec<SpecWithHint>)
pub fn split_eager_deferred(&self) -> (Vec<SpecWithHint>, Vec<SpecWithHint>)
Split the registry’s tools into eager and deferred partitions.
Returns (eager, deferred) where each element is a
(ToolSpec, optional_search_hint) pair. Eager tools carry their
full schema; deferred tools carry only the name (the full schema is
returned on demand when the model calls ToolSearch). The
search hint is the first sentence of the tool’s description,
suitable for injection into the deferred tool list so the model
knows what is available without the full schema.
Sourcepub fn is_deferred_spec(&self, spec: &ToolSpec) -> bool
pub fn is_deferred_spec(&self, spec: &ToolSpec) -> bool
Check whether a spec is deferred by looking up the tool in the registry.
Sourcepub fn freeze_deferred_specs(&mut self)
pub fn freeze_deferred_specs(&mut self)
Finalize deferred tool support: collect all deferred tool specs into a
shared catalog and register a ToolSearchTool backed by that catalog.
Call this once after all other tools have been registered. If there are no deferred tools, this is a no-op (ToolSearchTool is not registered).
pub fn names(&self) -> Vec<String>
pub fn get(&self, name: &str) -> Option<Arc<dyn Tool>>
Sourcepub fn is_readonly(&self, name: &str) -> bool
pub fn is_readonly(&self, name: &str) -> bool
Check if a tool is read-only (no side effects).
Sourcepub fn build_kind_map(&self) -> HashMap<String, ToolKind>
pub fn build_kind_map(&self) -> HashMap<String, ToolKind>
Build a HashMap<String, ToolKind> mapping every registered tool
name to its ACP ToolKind (Sprint 3). Used by AcpBridge to
populate the kind field in tool_call notifications.
Sourcepub fn is_readonly_for_call(&self, name: &str, args: &Value) -> bool
pub fn is_readonly_for_call(&self, name: &str, args: &Value) -> bool
Like is_readonly but passes call-time arguments to the tool so it can
make an argument-specific decision (e.g. sub_agent checking
subagent_type: "explore").