[Feature] Support adding file read-only.
Issue
I am looking for a way to add files read-only to the context. Let's say I have a requirements document called requirements.md. When i have added that to the context I have seen Aider changing the requirements to match the implementation want is normaly not want is intended. Same with predefined testcases. At sometime I would like to mark testcases read-only to make sure Aider changes the code and not the tests ;)
Version and model info
Aider v0.45.1 Model: openai/aws/claude-3.5-sonnet with diff edit format Git repo: .git with 18 files Repo-map: using 1024 tokens
I agree. Very often the AI only has needs to know the content of a file but it should not be modified. Instead the AI goes and changes everything. It is very annoying reverting the code every time, removing the source file, ask the AI to make the changes again, and then adding the file again to continue developing.
Another Use Case: I generated an API Client with the OpenAPI Tools. These files must be part of the context but must not be changed.
Agreed. It would be a very nice feature to differentiate what can be modified and what can't. Currently, all the files added to the context are treated the same and are modifiable.
Agree. See my detailed suggestion here of an approach that would cover these use cases.
https://github.com/paul-gauthier/aider/issues/939
Main branch now lets you /read <file> from anywhere, including outside the repo. The LLM can see it, but not edit it. Also has --read <file> on command line and read: <file> in the yaml.
The change is available in the main branch. You can get it by installing the latest version from github:
python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git
If you have a chance to try it, let me know if it works better for you.
this is a great feature! thanks
¿is it intentional that the read-only files are not listed in the "added" files list? I can see it's there if I run a /tokens command, but otherwise it's not displayed.
It also is absent when running the /ls command.
They are listed in /ls in the main branch. Where else would like like/expect to see them? In the list above the prompt?
that was my intuition. I'm not positive that intuition is the right one, but my mind was at "if it's being sent to [LMM] when I hit enter, then it's in the list of files I'm looking at when I'm writing my instruction".
The change is available in the main branch. You can get it by installing the latest version from github:
python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git
If you have a chance to try it, let me know if it works better for you.
I'm going to close this issue for now, but feel free to add a comment here and I will re-open or file a new issue any time.
the lastest version works great! thanks so much.
now that it was there I noticed a behavior which may be worth addressing.
- file is added in read only mode (either via config or
/read) - I now want to change it to edit mode
- I type
/add my-file.md
the unexpected behavior is that it now shows up in BOTH read-only and edit modes: it's listed twice when I use /tokens or /ls
In this example, the original add was done via a config file
(.venv) XXXX@XXXX XXXX % aider
Aider v0.49.2-dev
Models: claude-3-5-sonnet-20240620 with diff edit format, weak model claude-3-haiku-20240307
Git repo: .git with 3 files
Repo-map: using 1536 tokens
Use /help <question> for help, run "aider --help" to see cmd line args
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /add CONVENTIONS.md
Added /Users/XXXX/projects/XXXX/CONVENTIONS.md to the chat
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /ls
Repo files not in the chat:
indication.py
indicator.py
indicator_type.py
Read-only files:
CONVENTIONS.md
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /tokens
Approximate context window usage for claude-3-5-sonnet-20240620, in tokens:
$ 0.0034 1,117 system messages
$ 0.0007 238 CONVENTIONS.md /drop to remove
$ 0.0007 238 CONVENTIONS.md (read-only) /drop to remove
==================
$ 0.0048 1,593 tokens total
198,407 tokens remaining in context window
200,000 tokens max context window size
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
>
Here's another scenario showing how it stops you from /adding twice, but not from /reading after /adding.
Dropping all files from the chat session.
───────────────────────────────────────────────────────────────────────────────────────────────────
> /add CONVENTIONS.md
Added /Users/XXXX/projects/XXXX/CONVENTIONS.md to the chat
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /tokens
Approximate context window usage for claude-3-5-sonnet-20240620, in tokens:
$ 0.0034 1,117 system messages
$ 0.0007 238 CONVENTIONS.md /drop to remove
==================
$ 0.0041 1,355 tokens total
198,645 tokens remaining in context window
200,000 tokens max context window size
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /add CONVENTIONS.md
/Users/XXXX/projects/XXXX/CONVENTIONS.md is already in the chat
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /read CONVENTIONS.md
Added /Users/XXXX/projects/XXXX/CONVENTIONS.md to read-only files.
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
> /tokens
Approximate context window usage for claude-3-5-sonnet-20240620, in tokens:
$ 0.0034 1,117 system messages
$ 0.0007 238 CONVENTIONS.md /drop to remove
$ 0.0007 238 CONVENTIONS.md (read-only) /drop to remove
==================
$ 0.0048 1,593 tokens total
198,407 tokens remaining in context window
200,000 tokens max context window size
───────────────────────────────────────────────────────────────────────────────────────────────────
CONVENTIONS.md
>
Thank you so much. Great addition. A small glitch might be that aider keeps asking to add the file but it's still added read-only.
api/openapi.yaml
Add these files to the chat? n