use crate::tool_policy::{ToolPolicy, ToolPolicyManager};
use anyhow::Result;
use clap::Subcommand;
use console::style;
#[derive(Debug, Clone, Subcommand)]
pub enum ToolPolicyCommands {
Status,
Allow {
tool: String,
},
Deny {
tool: String,
},
Prompt {
tool: String,
},
AllowAll,
DenyAll,
ResetAll,
}
pub async fn handle_tool_policy_command(command: ToolPolicyCommands) -> Result<()> {
let mut policy_manager = ToolPolicyManager::new()?;
match command {
ToolPolicyCommands::Status => {
policy_manager.print_status();
}
ToolPolicyCommands::Allow { tool } => {
policy_manager.set_policy(&tool, ToolPolicy::Allow)?;
println!(
"{}",
style(format!("✓ Tool '{}' is now allowed", tool)).green()
);
}
ToolPolicyCommands::Deny { tool } => {
policy_manager.set_policy(&tool, ToolPolicy::Deny)?;
println!(
"{}",
style(format!("✗ Tool '{}' is now denied", tool)).red()
);
}
ToolPolicyCommands::Prompt { tool } => {
policy_manager.set_policy(&tool, ToolPolicy::Prompt)?;
println!(
"{}",
style(format!(
"? Tool '{}' will now prompt for confirmation",
tool
))
.yellow()
);
}
ToolPolicyCommands::AllowAll => {
policy_manager.allow_all_tools()?;
println!("{}", style("✓ All tools are now allowed").green());
}
ToolPolicyCommands::DenyAll => {
policy_manager.deny_all_tools()?;
println!("{}", style("✗ All tools are now denied").red());
}
ToolPolicyCommands::ResetAll => {
policy_manager.reset_all_to_prompt()?;
println!(
"{}",
style("? All tools reset to prompt for confirmation").yellow()
);
}
}
Ok(())
}
pub fn print_tool_policy_help() {
println!("{}", style("Tool Policy Management").cyan().bold());
println!();
println!("Tool policies control which tools the agent can use:");
println!();
println!(
" {} - Tool executes automatically without prompting",
style("allow").green()
);
println!(
" {} - Tool prompts for user confirmation each time",
style("prompt").yellow()
);
println!(
" {} - Tool is never allowed to execute",
style("deny").red()
);
println!();
println!("Policies are stored in ~/.vtcode/tool-policy.json");
println!("Once you approve or deny a tool, your choice is remembered for future runs.");
println!();
println!("Examples:");
println!(" vtcode tool-policy status # Show current policies");
println!(" vtcode tool-policy allow read_file # Allow read_file tool");
println!(" vtcode tool-policy deny rm # Deny rm tool");
println!(" vtcode tool-policy reset-all # Reset all to prompt");
}