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

Prompt undo and redo command for --no-auto-commit mode #1093

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Aeraxys
Copy link

@Aeraxys Aeraxys commented Aug 15, 2024

So here is my implementation of my suggestion in issue #1018.

It's probably not perfect, but it works for me. And since there seemed to be some interest, I thought I'd make a PR.

When the --no-auto-commit flag is set, the /undo command becomes what I described in #1018. It reverts all edits done by the last prompt, resets the chat history to what it was before the last prompt was issued, and deletes all files and folders created by aider during the last prompt. This works by popping off a stack that saves states every prompt, this way the command can be issued multiple times to undo prompts in the order they were issued.

The reason I decided to just replace the /undo command is because in --no-auto-commit mode, the current /undo command doesn't do anything useful. What I have implemented here is what I would expect /undo to do in --no-auto-commit mode.

For clarification, when --no-auto-commit is not set, /undo is unchanged.

I have now also added a /redo command, which accompanies this /undo command in --no-auto-commit mode, and effectively reverses /undo.

Please let me know if you spot any issues or ways to improve!

    from .main import main
ImportError: attempted relative import with no known parent package

if not done like this
@Aeraxys Aeraxys marked this pull request as draft August 16, 2024 13:17
@Aeraxys Aeraxys marked this pull request as ready for review August 16, 2024 23:58
@Aeraxys Aeraxys marked this pull request as draft August 19, 2024 18:48
@Aeraxys
Copy link
Author

Aeraxys commented Aug 19, 2024

I'm going to add a /redo command

@Aeraxys Aeraxys marked this pull request as ready for review August 19, 2024 23:08
@Mage1507
Copy link

Hi, @Aeraxys I tried your implementation, and it works great! However, when using the /undo command, changes made to existing files are successfully reverted, but newly created files by Aider during implementation are not removed. Is there any reason or way to fix this issue?

@Aeraxys
Copy link
Author

Aeraxys commented Aug 28, 2024

Hi, @Aeraxys I tried your implementation, and it works great! However, when using the /undo command, changes made to existing files are successfully reverted, but newly created files by Aider during implementation are not removed. Is there any reason or way to fix this issue?

Hmm, I have actually thought of this and fixed it, I'm gonna check if I maybe have forgotten to push it. Thanks for notifying me!

Okay so I checked, and no I haven't forgotten to push. It should work, according to line 389 to 401 in commands.py:

                # This file was created during the last prompt, so we should delete it
                if rel_fname in self.coder.created_by_aider:
                    try:
                        # Use drop_rel_fname to drop the deleted file
                        self.coder.drop_rel_fname(rel_fname)

                        # Remove the file from git and untrack it
                        if self.coder.repo:
                            self.coder.repo.remove_file_from_tracking(rel_fname)

                        if os.path.exists(fname):
                            os.remove(fname)
                            self.io.tool_output(f"Deleted file: {fname}")

This should delete files if they were created by aider during the last prompt. It works for me at least.

@Aeraxys Aeraxys changed the title Prompt undo command for --no-auto-commit mode Prompt undo and redo command for --no-auto-commit mode Aug 28, 2024
@Aeraxys
Copy link
Author

Aeraxys commented Aug 28, 2024

I now realize the /redo command doesn't restore files /undo has deleted. I'm gonna fix that real quick.

@Aeraxys Aeraxys marked this pull request as draft August 28, 2024 17:29
@Aeraxys Aeraxys marked this pull request as ready for review August 29, 2024 07:18
@Mage1507
Copy link

Hi, @Aeraxys I tried your implementation, and it works great! However, when using the /undo command, changes made to existing files are successfully reverted, but newly created files by Aider during implementation are not removed. Is there any reason or way to fix this issue?

Hmm, I have actually thought of this and fixed it, I'm gonna check if I maybe have forgotten to push it. Thanks for notifying me!

Okay so I checked, and no I haven't forgotten to push. It should work, according to line 389 to 401 in commands.py:

                # This file was created during the last prompt, so we should delete it
                if rel_fname in self.coder.created_by_aider:
                    try:
                        # Use drop_rel_fname to drop the deleted file
                        self.coder.drop_rel_fname(rel_fname)

                        # Remove the file from git and untrack it
                        if self.coder.repo:
                            self.coder.repo.remove_file_from_tracking(rel_fname)

                        if os.path.exists(fname):
                            os.remove(fname)
                            self.io.tool_output(f"Deleted file: {fname}")

This should delete files if they were created by aider during the last prompt. It works for me at least.

I'm not sure why it's not working for me, but I'll validate it again. However, when I manually delete the file created by Aider and use the /redo command, it successfully recreates the file with the content that was applied earlier.

@Aeraxys
Copy link
Author

Aeraxys commented Aug 30, 2024

Hi, @Aeraxys I tried your implementation, and it works great! However, when using the /undo command, changes made to existing files are successfully reverted, but newly created files by Aider during implementation are not removed. Is there any reason or way to fix this issue?

Hmm, I have actually thought of this and fixed it, I'm gonna check if I maybe have forgotten to push it. Thanks for notifying me!
Okay so I checked, and no I haven't forgotten to push. It should work, according to line 389 to 401 in commands.py:

                # This file was created during the last prompt, so we should delete it
                if rel_fname in self.coder.created_by_aider:
                    try:
                        # Use drop_rel_fname to drop the deleted file
                        self.coder.drop_rel_fname(rel_fname)

                        # Remove the file from git and untrack it
                        if self.coder.repo:
                            self.coder.repo.remove_file_from_tracking(rel_fname)

                        if os.path.exists(fname):
                            os.remove(fname)
                            self.io.tool_output(f"Deleted file: {fname}")

This should delete files if they were created by aider during the last prompt. It works for me at least.

I'm not sure why it's not working for me, but I'll validate it again. However, when I manually delete the file created by Aider and use the /redo command, it successfully recreates the file with the content that was applied earlier.

Hmm yeah not sure what it could be. I'm running on a Macbook and it works fine

@CLAassistant
Copy link

CLAassistant commented Oct 16, 2024

CLA assistant check
All committers have signed the CLA.

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