pub struct ToolPolicyManager { /* private fields */ }Expand description
Tool policy manager
Implementations§
Source§impl ToolPolicyManager
impl ToolPolicyManager
Sourcepub async fn new_with_workspace(workspace_root: &Path) -> Result<Self>
pub async fn new_with_workspace(workspace_root: &Path) -> Result<Self>
Create a new tool policy manager with workspace-specific config
Sourcepub async fn new_with_config_path<P: Into<PathBuf>>(
config_path: P,
) -> Result<Self>
pub async fn new_with_config_path<P: Into<PathBuf>>( config_path: P, ) -> Result<Self>
Create a new tool policy manager backed by a custom configuration path.
This helper allows downstream consumers to store policy data alongside
their own configuration hierarchy instead of writing to the default
.vtcode directory.
Sourcepub fn set_permission_handler(
&mut self,
handler: Box<dyn PermissionPromptHandler>,
)
pub fn set_permission_handler( &mut self, handler: Box<dyn PermissionPromptHandler>, )
Set the permission handler for this manager
Sourcepub async fn apply_tools_config(
&mut self,
tools_config: &ToolsConfig,
) -> Result<()>
pub async fn apply_tools_config( &mut self, tools_config: &ToolsConfig, ) -> Result<()>
Apply policies defined in vtcode.toml to the runtime policy manager
Sourcepub async fn update_available_tools(&mut self, tools: Vec<String>) -> Result<()>
pub async fn update_available_tools(&mut self, tools: Vec<String>) -> Result<()>
Update the tool list and save configuration
Sourcepub async fn update_mcp_tools(
&mut self,
provider_tools: &HashMap<String, Vec<String>>,
) -> Result<()>
pub async fn update_mcp_tools( &mut self, provider_tools: &HashMap<String, Vec<String>>, ) -> Result<()>
Synchronize MCP provider tool lists with persisted policies
Sourcepub fn get_mcp_tool_policy(&self, provider: &str, tool: &str) -> ToolPolicy
pub fn get_mcp_tool_policy(&self, provider: &str, tool: &str) -> ToolPolicy
Retrieve policy for a specific MCP tool
Sourcepub async fn set_mcp_tool_policy(
&mut self,
provider: &str,
tool: &str,
policy: ToolPolicy,
) -> Result<()>
pub async fn set_mcp_tool_policy( &mut self, provider: &str, tool: &str, policy: ToolPolicy, ) -> Result<()>
Update policy for a specific MCP tool
Sourcepub fn mcp_allowlist(&self) -> &McpAllowListConfig
pub fn mcp_allowlist(&self) -> &McpAllowListConfig
Access the persisted MCP allow list configuration
Sourcepub async fn set_mcp_allowlist(
&mut self,
allowlist: McpAllowListConfig,
) -> Result<()>
pub async fn set_mcp_allowlist( &mut self, allowlist: McpAllowListConfig, ) -> Result<()>
Replace the persisted MCP allow list configuration
Sourcepub fn get_policy(&self, tool_name: &str) -> ToolPolicy
pub fn get_policy(&self, tool_name: &str) -> ToolPolicy
Get policy for a specific tool
Sourcepub fn get_constraints(&self, tool_name: &str) -> Option<&ToolConstraints>
pub fn get_constraints(&self, tool_name: &str) -> Option<&ToolConstraints>
Get optional constraints for a specific tool
Sourcepub async fn should_execute_tool(
&mut self,
tool_name: &str,
) -> Result<ToolExecutionDecision>
pub async fn should_execute_tool( &mut self, tool_name: &str, ) -> Result<ToolExecutionDecision>
Check if tool should be executed based on policy
pub fn is_auto_allow_tool(tool_name: &str) -> bool
Sourcepub fn prompt_user_for_tool(
&mut self,
tool_name: &str,
) -> Result<ToolExecutionDecision>
pub fn prompt_user_for_tool( &mut self, tool_name: &str, ) -> Result<ToolExecutionDecision>
Prompt user for tool execution permission using the configured handler.
This function delegates to the PermissionPromptHandler if one is configured. In TUI mode, the handler should be set to use TUI-based prompts via the permission handler mechanism.
Sourcepub async fn set_policy(
&mut self,
tool_name: &str,
policy: ToolPolicy,
) -> Result<()>
pub async fn set_policy( &mut self, tool_name: &str, policy: ToolPolicy, ) -> Result<()>
Set policy for a specific tool
Sourcepub async fn reset_all_to_prompt(&mut self) -> Result<()>
pub async fn reset_all_to_prompt(&mut self) -> Result<()>
Reset all tools to prompt
Sourcepub async fn allow_all_tools(&mut self) -> Result<()>
pub async fn allow_all_tools(&mut self) -> Result<()>
Allow all tools
Sourcepub async fn deny_all_tools(&mut self) -> Result<()>
pub async fn deny_all_tools(&mut self) -> Result<()>
Deny all tools
Sourcepub fn get_policy_summary(&self) -> IndexMap<String, ToolPolicy>
pub fn get_policy_summary(&self) -> IndexMap<String, ToolPolicy>
Get summary of current policies
Sourcepub fn has_approval_cache_key(&self, approval_key: &str) -> bool
pub fn has_approval_cache_key(&self, approval_key: &str) -> bool
Check whether an explicit approval key is remembered for this workspace.
Performs three levels of matching:
- Exact match against persisted allowed keys
- Word-prefix match: checks if the approval key starts with any persisted prefix
- Regex match against persisted regex patterns
Sourcepub fn find_matching_cache_prefix(&self, approval_key: &str) -> Option<String>
pub fn find_matching_cache_prefix(&self, approval_key: &str) -> Option<String>
Find the best matching cache key for a given approval key using fuzzy prefix matching. Returns the longest matching prefix key if one exists.
Sourcepub async fn add_approval_cache_key(
&mut self,
approval_key: impl Into<String>,
) -> Result<()>
pub async fn add_approval_cache_key( &mut self, approval_key: impl Into<String>, ) -> Result<()>
Persist an explicit approval key for future prompts in this workspace.
Sourcepub async fn add_approval_cache_key_with_segments(
&mut self,
approval_key: impl Into<String>,
) -> Result<()>
pub async fn add_approval_cache_key_with_segments( &mut self, approval_key: impl Into<String>, ) -> Result<()>
Persist an approval key and automatically derive shorter segment-prefix keys so that future similar commands also match without re-prompting.
For example, approving “cargo check –target x86_64” also caches “cargo check” as a segment prefix, so “cargo check –release” also matches.
Sourcepub async fn add_approval_cache_prefix(
&mut self,
prefix_entry: impl Into<String>,
) -> Result<()>
pub async fn add_approval_cache_prefix( &mut self, prefix_entry: impl Into<String>, ) -> Result<()>
Persist a shell prefix approval entry for future prompts in this workspace.
Sourcepub fn matching_shell_approval_prefix(
&self,
command_words: &[String],
scope_signature: &str,
) -> Option<String>
pub fn matching_shell_approval_prefix( &self, command_words: &[String], scope_signature: &str, ) -> Option<String>
Check whether a persisted shell prefix approval matches the command words and scope.
Sourcepub async fn clear_approval_cache(&mut self) -> Result<()>
pub async fn clear_approval_cache(&mut self) -> Result<()>
Remove all persisted approval cache entries.
Sourcepub fn print_status(&self)
pub fn print_status(&self)
Print current policy status
Sourcepub fn config_path(&self) -> &Path
pub fn config_path(&self) -> &Path
Expose path of the underlying policy configuration file
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ToolPolicyManager
impl !UnwindSafe for ToolPolicyManager
impl Freeze for ToolPolicyManager
impl Send for ToolPolicyManager
impl Sync for ToolPolicyManager
impl Unpin for ToolPolicyManager
impl UnsafeUnpin for ToolPolicyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> CacheValue for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more