Skip to content

Conversation

@demouo
Copy link

@demouo demouo commented May 6, 2025

Hi! Backgroud and motivation from #698

When I got an error command, I would like to correct ai that the command ... was wrong with the output ..., please fix it.

example follows:
image

This PR introduces a --fix flag. When used, sgpt retrieves the last executed command and its output, then prompts the AI to provide a corrected version based on the error.

Key changes:

  • Added --fix option to sgpt/app.py.
  • Created sgpt/command.py to manage storing and retrieving the last command and output in json format.
  • Updated sgpt/utils.py to set and get the last command.
  • Replaced os.system with subprocess.Popen in run_command to capture output.
  • Added get_fixed_prompt to generate the prompt for the AI.
  • Store command and output using the new Command class.
  • Updated tests in tests/test_shell.py to reflect the use of subprocess.
  • Added necessary configuration in sgpt/config.py.

make sure the lint and test result as usual:
image

Closes #698

@demouo
Copy link
Author

demouo commented May 7, 2025

The 2nd~4th Commits' changes:

  1. LLM sometimes could not completely return the pure shell code, so I wrote the extracting function

  2. Due to I was not familiar with the operation, I accidentally wrote several empty prompts, which should be ended before chatting with LLM

  3. The idea of fix last command was added in REPL mode.

Hope everything goes well!

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.

Is there an elegant way to provide feedback and rechat on the wrong commands and results?

1 participant