Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions promptshell/ai_terminal_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
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