vtcode_core/ui/
user_confirmation.rs1use crate::utils::colors::style;
7use anyhow::Result;
8use dialoguer::{Confirm, Input, Select};
9
10pub struct UserConfirmation;
12
13#[derive(Debug, Clone, PartialEq)]
15pub enum ToolConfirmationResult {
16 Yes,
18 YesAutoAccept,
20 No,
22 Feedback(String),
24}
25
26impl UserConfirmation {
27 #[must_use = "confirmation action failure is silently ignored"]
29 pub fn confirm_action(message: &str, default: bool) -> Result<bool> {
30 Confirm::new()
31 .with_prompt(message)
32 .default(default)
33 .interact()
34 .map_err(Into::into)
35 }
36
37 pub fn confirm_tool_usage(tool_name: &str, tool_args: Option<&str>) -> Result<ToolConfirmationResult> {
39 println!("{}", style("Tool Execution Confirmation").cyan().bold());
40 println!("Tool: {}", style(tool_name).cyan().bold());
41 if let Some(args) = tool_args {
42 println!("Args: {}", style(args).dim());
43 }
44 println!();
45
46 let options = vec![
47 "Yes - Allow this execution",
48 "Yes - Always allow this tool (Auto-accept)",
49 "No - Deny this execution",
50 "No - Deny and provide feedback to agent",
51 ];
52
53 let selection = Select::new()
54 .with_prompt("How would you like to proceed?")
55 .default(0)
56 .items(&options)
57 .interact()?;
58
59 match selection {
60 0 => Ok(ToolConfirmationResult::Yes),
61 1 => Ok(ToolConfirmationResult::YesAutoAccept),
62 2 => Ok(ToolConfirmationResult::No),
63 3 => {
64 let feedback: String = Input::new()
65 .with_prompt("Enter feedback for the agent")
66 .allow_empty(false)
67 .interact_text()?;
68 Ok(ToolConfirmationResult::Feedback(feedback))
69 }
70 _ => Ok(ToolConfirmationResult::No),
71 }
72 }
73}