Skip to content

Conversation

@RAJVEER42
Copy link
Contributor

Hey @Kirti-Rathi ,

I've implemented all the required changes as discussed:

✅ The manual safeguard now includes an additional confirmation step:
After the user confirms execution of a dangerous command, they’re also required to retype the exact command as a second-layer verification.

✅ This ensures the user’s input doesn't rely on simply typing CONFIRM, and adds stronger protection before execution.

✅ Try running a dangerous command like: delete spare_file.txt — you’ll now see both confirmation prompts working as intended.

✅ The main logic for this is updated in ai_terminal_assistant.py.

🔄 Also made sure my branch is up-to-date with main.

Let me know if anything else needs refining!

Added manual command re-entry as a second-layer safety check for destructive commands
like 'rm', 'delete', and 'shutdown'. Now, after initial confirmation, users must re-type
the command exactly before execution.
- Implement manual reentry safeguard for dangerous commands
- Remove CONFIRM prefix handling
- Improve dangerous command detection patterns
- Add better error handling and user feedback
- Ensure proper validation before executing destructive commands
@RAJVEER42
Copy link
Contributor Author

RAJVEER42 commented Jun 16, 2025

Hi @Kirti-Rathi ,

I've implemented all the necessary changes.

The manual safeguard is now enforced after the user confirms execution, and before the actual execution of any dangerous command. It now includes an additional verification step requiring the user to re-type the exact command as a second-layer check, as requested.

You can test this by triggering a dangerous command like:

cpp
Copy
Edit
delete <spare_file_name>
You'll see the flow now prompts for:

Initial confirmation (yes/no)

Exact re-entry of the command

The changes have been made in ai_terminal_assistant.py, where the execution flow is handled.

Also, I’ve made sure my branch is up-to-date with main.

Please review it when you get a chance. Let me know if any further adjustments are needed!

Thanks!
Rajveer

*also could you please guide me to resolve through the the conflicts in the code, if possible.

Copy link
Owner

@Kirti-Rathi Kirti-Rathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added a detailed review, but I’d strongly recommend closing this PR and the associated branches. Please create a fresh branch and apply only the necessary modifications, as done in PR #10 and refer to it for the scope and structure of changes expected.

Also, make sure to your fork is up-to-date with main.

This PR includes a number of unnecessary changes, which made reviewing a fairly straightforward issue more time consuming than needed.

Comment on lines +15 to +17
def get_current_os():
return platform.system()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is already defined in format_utils.py. Remove this

from .node import Node
from .data_gatherer import DataGatherer
from .format_utils import format_text, reset_format, get_current_os, get_os_specific_examples
from .format_utils import format_text, reset_format
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from .format_utils import format_text, reset_format
from .format_utils import format_text, reset_format, get_current_os, get_os_specific_examples

Keep it as it was, importing functions from format_utils only

return ""
if user_input.startswith('!'):
return self.run_direct_command(user_input[1:])
additional_data = self.gather_additional_data(user_input)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this line, it's a required arguement in command_executor

Comment on lines -221 to +227
Current OS: {get_current_os()}
Current OS specific examples: {get_os_specific_examples()}
Current OS: {platform.system()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change these, the functions are well-defined in format_utils and are required.
Keep it as it was

Comment on lines -224 to +229
Translate the user input into a SINGLE shell command according to the operating system.
Translate the user input into a SINGLE shell command.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes required here as well. keep the original line.

Comment on lines -229 to +231
""", additional_data=additional_data).strip()
""", additional_data=self.gather_additional_data(user_input)).strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the additional data variable defined above only

        """, additional_data=additional_data).strip()

Comment on lines +234 to +237
if self.is_dangerous_command(command):
print(format_text('yellow', bold=True) +
f"\n⚠️ Warning: The command '{command}' may be destructive." +
reset_format())
Copy link
Owner

@Kirti-Rathi Kirti-Rathi Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the identification method of dangerous commads.
The api response prefixed with "CONFIRM: " gives consistent results and has been found to be more accurate.
Some destructive commands escapes the regex method used in is_dangerous_command function, which causes inconsistency in behaviour and faulty deletions.

Comment on lines -231 to -257
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()
if not confirmation:
return format_text('red') + "Command execution aborted." + reset_format()
command = command[8:]
formatted_command = format_text('cyan') + f"Command: {command}" + reset_format()
print(formatted_command)
self.command_history.append(command)
if len(self.command_history) > 10:
self.command_history.pop(0)
if command.startswith("cd "):
path = command.split(" ", 1)[1]
os.chdir(os.path.expanduser(path))
result = f"Changed directory to {os.getcwd()}"
exit_code = 0
else:
stdout, stderr, exit_code = self.execute_command_with_live_output(command)
result = ""
if exit_code != 0:
debug_suggestion = self.debug_error(command, stderr, exit_code)
result += format_text('yellow') + f"\n\nDebugging Suggestion:\n{debug_suggestion}" + reset_format()
return result.strip()
else:
print(format_text('red') + "Command cancelled!" + reset_format())
return ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the clarification. I’ll get back to you as soon as possible with the necessary corrections. @Kirti-Rathi

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to reach out in case you've doubts

@RAJVEER42 RAJVEER42 closed this Jun 20, 2025
@RAJVEER42 RAJVEER42 deleted the feature/improved-dangerous-command-safeguard branch June 20, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants