aider.el
aider.el copied to clipboard
Unexpected behaviour when starting aider.el from buffer with file
Steps
- Visit a project (I'm using projectile)
- Open a file in the project, e.g.
tests/test_am_types.py - Start aider.el (transient menu ->
a) - Add the current buffer to aider (transient menu ->
f) - Answer "no" to question about creating the file that's being added.
Expected behaviour
The question in step 5 isn't asked, and the file visited in the buffer is added to aider's context.
Observed behaviour
No file is added to aider's context.
Contents of the aider buffer
This is what I get in the aider buffer when executing the steps above
Detected dumb terminal, disabling fancy input and pretty output.
Aider v0.82.2
Main model: claude-3-7-sonnet-latest with diff edit format, infinite output
Weak model: claude-3-5-haiku-20241022
Git repo: none
Repo-map: disabled
Note: in-chat filenames are always relative to the git working dir, not the current working dir.
Cur working dir: /home/elrond/Work/py-am/tests
Git working dir: /home/elrond/Work/py-am
> /add tests/test_am_types.py
> > >
No files matched 'tests/test_am_types.py'. Do you want to create /home/elrond/Work/py-am/tests/tests/test_am_types.py? (Y)es/(N)o [Yes]: no
> /ls
No files in chat, git repo, or read-only list.
Comparison to running aider in a terminal
Since I'll start aider in the project's root folder I don't see the same behaviour.
Behaviour when answering "yes" when asked about creating the file
If I answer "yes" in step 5 above, i.e. I tell aider to create the file, then an empty file is created at tests/tests/test_am_types.py. It's also added to the context.
Related issues
I think that both #23 and #26 could be related issues.
I've tried to instead start aider from a dired buffer visiting the project's root folder. That works for a while, but after adding a few files aider gets confused and starts asking about creating files.
This behaviour makes aider.el useless for me at the moment and I've had to go back to running aider in a terminal.
Thanks for the feedback! Your Steps are very clear. I tried to reproduce it using aider.el repo with these steps, but I cannot reproduce the issue.
- Have .projectile in aider.el home dir (bottom right in screenshot)
- Opened ./examples/connect4/game.py (top left, path in top right)
- C-c a a open aider session from game.py buffer, we can see the Cur dir and Working dir are different (bottom left)
- Switch back to game.py, C-c a f add it to aider session
- The session do shows:
Added examples/connect4/game.py to the chat. It didn't ask me to create a new file. (bottom left)
screenshot below:
Could you pleases provide a public github repo where I can reproduce the issue; or you can attach your repo zip file and I'll check if I can reproduce this on my laptop?
It happens to me in all repos... but I'll find a specific one and reproduce it there.
In the mean time... what happens if you jump to a second file, a file in another folder, and add it?
In aider.el repo, under example directory, I jump from test_game.py of connect4 game to game.py of battle ship, with projectile, the file add work for me:
- Open the aider.el project
- Open
aider.el/examples/battleship/fleet.py - Start aider, transient menu ->
a - Add the current file, transient menu ->
f
I'll see if I can put together a minimal Emacs config and see if I can reproduce it then as well.
I just installed aider.el from melpa (to avoid potential discrepancy with the one I used directly from working repo) and try to reproduce the issue following your above steps, still cannot reproduce it. I'll try the straight installation later
I tried the straight installation one (same as yours), still cannot reproduce the issue..
But I do hit some weird dependency installation error msg with straight. I'll update the README and put melpa installation one to the first.
From your above screenshot, it seems that the elisp code build the right relative path to the git root, (/add examples/battleship/fleet.py), and sent it to aider session. But that aider session seems rebuild the path given the work dir, instead of git root dir (examples/battleship/examples/battleship/fleet.py)
Wonder if you can try two things:
- will manual copy paste this command in aider session still not work? /add examples/battleship/fleet.py
- if you start aider session in the git root directory. (eg. open README.org, and then start the aider session). will the above command work?
This is the line derive the git root relative path: https://github.com/tninja/aider.el/blob/main/aider-file.el#L24. I guess for some reason /add
- will manual copy paste this command in aider session still not work? /add examples/battleship/fleet.py
If I do that I get asked about creating the file, i.e. it doesn't work as expected.
- if you start aider session in the git root directory. (eg. open README.org, and then start the aider session). will the above command work?
When I do that I don't get asked about creating the file, i.e. it does work as expected.
For fun I tried one other thing
- Open
examples/battleship/fleet.pyin aider.el - Start aider session
- Manually add the file with the full absolute path,
/add /home/elrond/.emacs.d/straight/repos/aider.el/examples/battleship/fleet.py - Manually add one of the elisp files with the full absolute path,
/add /home/elrond/.emacs.d/straight/repos/aider.el/aider-agile.el
The behaviour supports your observation that
aider session seems rebuild the path given the work dir, instead of git root dir
So, how can I force the aider session to start in the project root? (Ideally without having to remember to always start the session from a file in the project root.)
Another thing that I find confusing is that when I start aider in the project root, where the .git/ folder is, then aider claims there is no git repo:
That's got nothing to do with aider.el though:
I still find it confusing though.
- will manual copy paste this command in aider session still not work? /add examples/battleship/fleet.py
If I do that I get asked about creating the file, i.e. it doesn't work as expected.
- if you start aider session in the git root directory. (eg. open README.org, and then start the aider session). will the above command work?
When I do that I don't get asked about creating the file, i.e. it does work as expected.
Seems the temporary solution on your laptop, without changing anything, is to start aider from any file (eg. README.org) in git root directory. Aider.el start the aider session based on the directory of the current file buffer.
I followed these steps, both files can be added to aider session on my laptop. If same thing also happens in your terminal aider (start aider in this directory: /home/elrond/.emacs.d/straight/repos/aider.el/examples/battleship/, and then do others), I suspect something wrong with this aider installation.
For fun I tried one other thing
1. Open `examples/battleship/fleet.py` in aider.el 2. Start aider session 3. Manually add the file with the full absolute path, `/add /home/elrond/.emacs.d/straight/repos/aider.el/examples/battleship/fleet.py` 4. Manually add one of the elisp files with the full absolute path, `/add /home/elrond/.emacs.d/straight/repos/aider.el/aider-agile.el`
The behaviour supports your observation that
aider session seems rebuild the path given the work dir, instead of git root dir
So, how can I force the aider session to start in the project root? (Ideally without having to remember to always start the session from a file in the project root.)
Aider started from git root directory does't have this problem on my laptop. I suspect sth wrong with your aider installation. Maybe reinstall it, or try it on a different computer and see if it can resolve the problem?
Another thing that I find confusing is that when I start aider in the project root, where the
.git/folder is, then aider claims there is no git repo:
That's got nothing to do with aider.el though:
I still find it confusing though.
Ah, yes indeed... there's something strange with aider itself I guess:
its claim that
Note: in-chat filenames are always relative to the git working dir, not the current working dir.
Is clearly not true. If it were I wouldn't be able to /add fleet.py, right?
I created ticket on aider: https://github.com/Aider-AI/aider/issues/3941
Yes. In past months, wherever aider start (cur working dir), with or without --subtree-only, it can add file, with git root relative path format. So aider.el use this logic to add file. If in future something changed in aider, we can adapt that change in aider.el.
Ah, yes indeed... there's something strange with aider itself I guess:
its claim that
Note: in-chat filenames are always relative to the git working dir, not the current working dir.
Is clearly not true. If it were I wouldn't be able to
/add fleet.py, right?
Yes. In past months, wherever aider start (cur working dir), with or without --subtree-only, it can add file, with git root relative path format.
Isn't the problem I have exactly the opposite of this statement?
When I run aider, directly in a terminal or via aider.el, it never adds anything relative to the git root. Instead it always only adds relative to the working dir.
Correct. The problem you see opposite of this statement (what I saw on my laptop, and expected aider behavior from aider.el)
Tried it again on my laptop, aider in terminal, still need the git root relative path, and path relative to the working dir doesn't work.
Isn't the problem I have exactly the opposite of this statement?
When I run aider, directly in a terminal or via aider.el, it never adds anything relative to the git root. Instead it always only adds relative to the working dir.
Close this since it doesn't seems to be an aider.el issue. Free free reopen this if you think we should address it from aider.el side.
Ah, sorry for not coming back with an update.
At some point I realised I didn't want to make git commits so I added
export AIDER_GIT=false
to my shell setup. I'm not sure if it was me reading too quickly, or that it at the time was the only git-related envvar, probably the former 😅 , but what I should have set is
export GIT_AUTO_COMMIT=false
So 👍 to closing this.
(I've already passed this on to one of my co-workers who had the same setting, and had noticed the same behaviour but was too lazy to dig into it. 😁 )
I see.. Thanks for feedback on git auto commit preference. Yes seems that lots of people prefer to turn it off. I personally still like it since it help me track the code change history, the commit history can also indicate if it is by AI. If I don't like it, I can easily HARD reset to check point with X key in magit.
I thought it might be helpful to protect main branch with this change https://github.com/tninja/aider.el/pull/194, but it might not be necessary for everyone, and people prefer directly change on main branch.
In that case, we can (setq aider-confirm-on-main-branch nil) to bypass that protection.