Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced ai command to perfom other commands #1156

Merged
merged 2 commits into from
Mar 8, 2025

Conversation

ntwari-bruce
Copy link
Contributor

This pull request enhances the ai command to recognize and execute system commands (e.g., mkdir, ls, etc.) directly from a prompt. Previously, the AI command could only respond with text, but now it can detect embedded commands and execute them seamlessly.

Changes Made
• Introduced logic to parse and extract system commands from the AI response using the pattern %%%command%%%.
• Added functionality to execute the extracted command within the shell environment.
• Moved the await ctx.externs.out.write(message + '\n'); statement into the else block to ensure regular messages are printed only when no command is detected. Now, ai command has enhanced capabilities where users can use it to interact with the terminal. This uses "ctx.shell.runPipeline" to run commands from inside a command.

@CLAassistant
Copy link

CLAassistant commented Mar 7, 2025

CLA assistant check
All committers have signed the CLA.

@KernelDeimos
Copy link
Contributor

Great work! Before I can merge this to main it's very important that the user is asked for confirmation before running an AI-generated command. Our release cycles are very fast so this will go into production soon after being merged.

This is mentioned in the issue:

Doing this with proper safeguards to prevent mistakes or damage to user data will be an important and interesting challenge.

Based on the source from the cat command, this should work to get a line of input from the user:

({ value: line } = await ctx.externs.in_.read())
if ( ! (line ?? '').toLowerCase().startsWith('y') ) {
  // Display error and return
}
// Run command

I haven't tested the code snippet above, but that's the general idea for capturing a Y/n prompt from the user.

@ntwari-bruce
Copy link
Contributor Author

I have updated the changes; Now, users will be able to confirm the command first before running it.

@KernelDeimos
Copy link
Contributor

Perfect, I no review comments so I'm going to merge this now. I'll open a new issue for using tool use which would potentially allow the ai command to take multiple steps for complex tasks.

@KernelDeimos KernelDeimos merged commit 7ed779b into HeyPuter:main Mar 8, 2025
1 check passed
@KernelDeimos
Copy link
Contributor

Added the subsequent issue. If you'd like you can take this too since you're already familiar with this command, or better yet you could help someone else through it.

@ntwari-bruce
Copy link
Contributor Author

@KernelDeimos yes i would like to take it

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.

3 participants