diff --git a/promptshell/ai_terminal_assistant.py b/promptshell/ai_terminal_assistant.py index c7169aa..0af9905 100644 --- a/promptshell/ai_terminal_assistant.py +++ b/promptshell/ai_terminal_assistant.py @@ -272,10 +272,15 @@ def execute_command(self, user_input: str) -> str: choice = questionary.confirm(f"Do you want to run the command '{command}'?").ask() if choice: if command.startswith("CONFIRM:"): - confirmation = questionary.confirm(f"Warning: This command may be destructive. Are you sure you want to run '{command[8:]}'?").ask() + confirmation = questionary.confirm(f"Warning: This command may be destructive. Are you sure you want to run '{command[9:]}'?").ask() if not confirmation: return format_text('red') + "Command execution aborted." + reset_format() - command = command[8:] + + # Add second-layer verification for dangerous commands + if not self.verify_dangerous_command(command[9:]): + return format_text('red') + "Command verification failed. Execution aborted." + reset_format() + + command = command[9:] formatted_command = format_text('cyan') + f"Command: {command}" + reset_format() print(formatted_command) self.command_history.append(command) @@ -439,4 +444,17 @@ def handle_error(self, error: str, user_input: str, command: str) -> str: confirmation = questionary.confirm("Would you like to execute the suggested command?").ask() if confirmation: return self.execute_command(error_analysis) - return format_text('red') + "Command execution aborted." + reset_format() \ No newline at end of file + return format_text('red') + "Command execution aborted." + reset_format() + + def verify_dangerous_command(self, command: str) -> bool: + """Verify dangerous command by asking user to re-type it. + + Args: + command: The command to verify + + Returns: + bool: True if verification successful, False otherwise + """ + print(format_text('yellow') + "\nFor safety, please re-type or paste the exact command to proceed:" + reset_format()) + user_input = input("> ").strip() + return user_input == command \ No newline at end of file