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

Failure when using the --watch-files feature #25

Open
magthe opened this issue Dec 11, 2024 · 9 comments
Open

Failure when using the --watch-files feature #25

magthe opened this issue Dec 11, 2024 · 9 comments

Comments

@magthe
Copy link

magthe commented Dec 11, 2024

Aider has gained the ability to watch for commands in comments and act on them (documented here). Unfortunately enabling that in aider.el isn't working, it causes the following exception

> Exception in thread Thread-2 (watch_files):
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1012, in run
    self._target(*self._args, **self._kwargs)
  File "/home/elrond/.local/share/pipx/venvs/aider-chat/lib/python3.12/site-packages/aider/watch.py", line 151, in watch_files
    raise e
  File "/home/elrond/.local/share/pipx/venvs/aider-chat/lib/python3.12/site-packages/aider/watch.py", line 146, in watch_files
    self.io.interrupt_input()
  File "/home/elrond/.local/share/pipx/venvs/aider-chat/lib/python3.12/site-packages/aider/io.py", line 393, in interrupt_input
    self.prompt_session.app.exit()
  File "/home/elrond/.local/share/pipx/venvs/aider-chat/lib/python3.12/site-packages/prompt_toolkit/application/application.py", line 1289, in exit
    raise Exception("Application is not running. Application.exit() failed.")
Exception: Application is not running. Application.exit() failed.

It would be absolutely wonderful to have this feature work with aider.el.

@magthe
Copy link
Author

magthe commented Dec 11, 2024

I thought maybe that --no-fancy-input would be a workaround, but it wasn't because surprisingly --watch-files and --no-fancy-input don't work together: Aider-AI/aider#2600

@tninja
Copy link
Owner

tninja commented Dec 11, 2024

Thanks for sharing. This feature looks interesting. Will look into it.

@tninja
Copy link
Owner

tninja commented Dec 12, 2024

Confirmed the exception.. it might because comint buffer is not a full functional term.
I am wondering is there a corresponding command in aider, to manually trigger the scan and the follow up action? if there is, we can easily add a menu item for it. It won't take much more effort than automatically triggered

@tninja
Copy link
Owner

tninja commented Dec 12, 2024

Seems that adding the following code to commands.py in aider, can add a new command /process-comment-ai, it will manually scan added files and do the magic. tested in aider code base.

    def cmd_process_comment_ai(self, args=""):
        "Process any AI comments in tracked files"
        from aider.watch import FileWatcher

        class SafeFileWatcher(FileWatcher):
            def start(self):
                # Override to do nothing, avoid calling self.io.intercept
                pass

            def stop(self):
                # Override to do nothing
                pass

        # Create a temporary watcher that won't do file monitoring
        watcher = SafeFileWatcher(self.coder)

        # Get all files in chat
        for fname in self.coder.abs_fnames:
            watcher.changed_files.add(fname)

        # Process the changes without any file monitoring
        return watcher.process_changes()

I tested and it seems work for me.

This will need to change the aider code base. not sure if it is OK. If it is doable, from emacs side we can add a short cut to send aider session the command which trigger the magic

@magthe
Copy link
Author

magthe commented Dec 12, 2024

That sounds like a nice way of dealing with it. Will you put together a PR for aider itself?

@tninja
Copy link
Owner

tninja commented Dec 17, 2024

Opened this PR: Aider-AI/aider#2641, wish it can be accepted.

@tninja
Copy link
Owner

tninja commented Dec 29, 2024

found that this command can somehow do the simple case for the AI comment:

/code check added file, find any comment end with AI! and implement the request in place.

Yeah it is definitely not as good as the aider code base implementation. The watch.py do have lots of logic to handle different cases in detail.

@tninja
Copy link
Owner

tninja commented Jan 11, 2025

Seems that recent aider update in 0.71.0: Turn off fancy input and watch files if terminal is dumb.

Not sure if it help on this case?

@magthe
Copy link
Author

magthe commented Jan 12, 2025

No, it only seems to mean that passing --watch-files does exactly nothing. It doesn't break `aider.el, but adding a "AI!" in a comment also has no effect at all.

I still think your suggestion, and PR, to add a command to "run" the comments is the most elegant and appealing solution. Upstream does seem hesitant though.

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

No branches or pull requests

2 participants