Allow the user to confirm commands forever

This commit is contained in:
Amar Sood (tekacs) 2025-04-12 10:25:40 -04:00
parent b51abd7fe7
commit 1841d105fe

View file

@ -6,25 +6,23 @@ def _execute_command(coder, command_string):
Execute a non-interactive shell command after user confirmation. Execute a non-interactive shell command after user confirmation.
""" """
try: try:
# Ask for confirmation before executing, allowing 'Always' # Ask for confirmation before executing.
# Use the command string itself as the group key to remember preference per command # allow_never=True enables the 'Always' option.
if not coder.io.confirm_ask( # confirm_ask handles remembering the 'Always' choice based on the subject.
confirmed = coder.io.confirm_ask(
"Allow execution of this command?", "Allow execution of this command?",
subject=command_string, subject=command_string,
explicit_yes_required=True, # Require explicit 'yes' or 'always' explicit_yes_required=True, # Require explicit 'yes' or 'always'
allow_never=True # Enable the 'Don't ask again' option allow_never=True # Enable the 'Always' option
): )
# Check if the reason for returning False was *not* because it's remembered
# (confirm_ask returns False if 'n' or 'no' is chosen, even if remembered) if not confirmed:
# We only want to skip if the user actively said no *this time* or if it's # This happens if the user explicitly says 'no' this time.
# remembered as 'never' (which shouldn't happen with allow_never=True, # If 'Always' was chosen previously, confirm_ask returns True directly.
# but checking io.never_ask_group is robust).
# If the command is in never_ask_group with a True value (meaning Always),
# confirm_ask would have returned True directly.
# So, if confirm_ask returns False here, it means the user chose No this time.
coder.io.tool_output(f"Skipped execution of shell command: {command_string}") coder.io.tool_output(f"Skipped execution of shell command: {command_string}")
return "Shell command execution skipped by user." return "Shell command execution skipped by user."
# Proceed with execution if confirmed is True
coder.io.tool_output(f"⚙️ Executing non-interactive shell command: {command_string}") coder.io.tool_output(f"⚙️ Executing non-interactive shell command: {command_string}")
# Use run_cmd_subprocess for non-interactive execution # Use run_cmd_subprocess for non-interactive execution