aider icon indicating copy to clipboard operation
aider copied to clipboard

Configure aider to always add specific files to the chat (eg, conventions file)

Open rodion-m opened this issue 1 year ago • 7 comments

Question and suggestion.

Suggestion: Augment .editorconfig file content into all queries as an additional context.

Question: Is there a way to specify files that will be augmented to the context of all queries by default? Is there is no, I suggest to implement it.

rodion-m avatar Jun 10 '24 06:06 rodion-m

Thanks for trying aider and filing this issue.

https://aider.chat/docs/conventions.html

paul-gauthier avatar Jun 10 '24 12:06 paul-gauthier

Thank you for the answer!

So, we can use aider like aider .editorconfig, right?

It would be great if aider itself would automatically pick up known code-styles files (.editorconfig, .DotSettings, etc.) and inject them in the prompt in the right place. So, I think, we can convert the issue into feature request.

rodion-m avatar Jun 10 '24 13:06 rodion-m

As I mentioned in #743, I would like to see this as an option flag / env var.

Something like...

## Automatically add this file to each chat
AIDER_AUTO_ADD=./CONVENTIONS.md

rsweetland avatar Jun 30 '24 22:06 rsweetland

What about writing a function that overrides the aider command in your shell? In have this which searches for CONVENTIONS.md in the current directory and parent directories until it finds that file or the .aider* project files:

aider() {
    current_dir="$PWD"
    while [ "$current_dir" != "/" ]; do
    if [ -f "$current_dir/CONVENTIONS.md" ]; then
        echo "Using CONVENTIONS.md found at $current_dir/CONVENTIONS.md :"
        echo
        cat "$current_dir/CONVENTIONS.md"
        echo
        command aider "$@" "$current_dir/CONVENTIONS.md"
        return 0
    fi
    if find -maxdepth 1 -name ".aider*" -type f -print 2>/dev/null | grep -q .; then
        echo ".aider* files were found but CONVENTIONS.md was not"
        break
    fi
    current_dir=$(dirname "$current_dir")
    done
    command aider "$@"
}

I work with different languages and frameworks, so i'm thinking of having different convention files such as python_conventions.md and bash_conventions.md, in which case I would change the function above to automatically include these convention files based on grepping the shebang line

sudomain avatar Jul 12 '24 20:07 sudomain

It would be great to have a configuration rather than a hack, like we have it for input-history-file or chat-history-file. Something like conventions-file to give a location even from outside of the repository. I am using the same convention in multiple projects. No need to have it in the repo.

r7l avatar Jul 15 '24 13:07 r7l

I am using the same convention in multiple projects. No need to have it in the repo.

fwiw it seems we're allowed to add files outside of the repo when invoking aider:

aider ~/testfile.conventions.md

But it's not allowed when using the /add command. I'm not sure if this is a bug

sudomain avatar Jul 15 '24 16:07 sudomain

Also, it'll be convenient if aider preserves the convention files after /drop command.

rodion-m avatar Jul 15 '24 19:07 rodion-m

You can now add file: CONVENTIONS.md to .aider.conf.yml to always load a specific file.

  • Or file: [file1, file2, file3] to always load multiple files.

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 for you.

paul-gauthier avatar Jul 29 '24 00:07 paul-gauthier

Wow, great news! Thanks a lot, Paul! I can't wait for this feature in the release via pipx.

rodion-m avatar Jul 29 '24 08:07 rodion-m

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.

paul-gauthier avatar Jul 29 '24 16:07 paul-gauthier

Thanks for getting this done, @paul-gauthier!

WilliamAGH avatar Jul 29 '24 16:07 WilliamAGH

Shouldn't file always be relative to .aider.conf or git repository root?

For example,

# /some/repo/.aider.yml
file: CONVENTIONS.md

If you open aider in /some/repo/subdirectory/, aider will try to add subdirectory/CONVENTIONS.md to chat. It does not exist so it will create an empty file CONVENTIONS.md in subdirectory.

This makes it impractical to launch aider in a subdirectory of a repo to get simpler paths in aider, if you want to use file.

Workaround is to use an absolute path in file, but I feel the path being relative to .aider.yml (or repo root) is more intuitive.

raine avatar Oct 12 '24 08:10 raine