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

use local chat/input history files if present, otherwise create local | use global #2684

Open
zachvalenta opened this issue Dec 22, 2024 · 0 comments

Comments

@zachvalenta
Copy link

Issue

By default, aider tries to write history files to $CWD. This should provide good context if, say, I'm returning to a repo where I've previously used aider.

On the other hand, let's say I just have an off-hand question and I happen to be outside a Git repo in a random directory on my filesystem (~/Desktop, for example). If I start aider in this directory (or any dir not under version control), my filesystem will soon be littered with .aider.chat.history.md files and I won't notice they're being created (unless I'm in the habit of ls -al after every cd).

The other thing is that a global history file would provide its own context i.e. if I've been thinking a bunch about, say, DataFusion or the semantic web or whatever over a series of queries during the past month, the global history file would have that entire context vs. a bunch of .aider.chat.history.md files scattered around the file system.

One way around this filesystem clutter is to use a single unified history file by setting AIDER_CHAT_HISTORY_FILE. The potential downside of this solution, however, is that it will reduce the efficacy of aider when it comes to specific repos, given that they won't have their own .aider.chat.history.md.

My workaround for this is a simple bash script:

#!/usr/bin/env bash

###
# SET OPENAI KEY
###
OPENAI_KEY_PATH="path/to/key/export"
if [ -f $OPENAI_KEY_PATH ]; then
    gum log --structured --time rfc822 --level info "🔑 OPENAI_API_KEY key set"
    source $OPENAI_KEY_PATH
fi
if [ -z "$OPENAI_API_KEY" ]; then
    gum log --structured --time rfc822 --level info "🔑 OPENAI_API_KEY not set, set in aider.env"
    exit 1
fi

###
# USE LOCAL CHAT/INPUT HISTORY FILES IF PRESENT, OTHERWISE CREATE LOCAL | USE GLOBAL
###
LOCAL_HISTORY_CHAT="$PWD/.aider.chat.history.md"
LOCAL_HISTORY_INPUT="$PWD/.aider.input.history.md"
GLOBAL_HISTORY_CHAT="$HOME/Documents/denv/dotfiles/ai/aider-chat-history.md"
GLOBAL_HISTORY_INPUT="$HOME/Documents/denv/dotfiles/ai/aider-input-history.md"
if [ -f "$LOCAL_HISTORY_CHAT" ]; then
    export AIDER_CHAT_HISTORY_FILE="$LOCAL_HISTORY_CHAT"
    export AIDER_INPUT_HISTORY_FILE="$LOCAL_HISTORY_INPUT"
    gum log --structured --time rfc822 --level info "🗃️ use existing local history files: $AIDER_CHAT_HISTORY_FILE $AIDER_INPUT_HISTORY_FILE"
else
    choices=("use global" "create local")
    choice=$(printf "%s\n" "${choices[@]}" | gum filter)
    if [ "$choice" == "create local" ]; then
        touch "$LOCAL_HISTORY_CHAT"
        touch "$LOCAL_HISTORY_INPUT"
        export AIDER_CHAT_HISTORY_FILE="$LOCAL_HISTORY_CHAT"
        export AIDER_INPUT_HISTORY_FILE="$LOCAL_HISTORY_INPUT"
        gum log --structured --time rfc822 --level info "🗃️ create/use local history files: $AIDER_CHAT_HISTORY_FILE $AIDER_INPUT_HISTORY_FILE"
    elif [ "$choice" == "use global" ]; then
        export AIDER_CHAT_HISTORY_FILE="$GLOBAL_HISTORY_CHAT"
        export AIDER_INPUT_HISTORY_FILE="$GLOBAL_HISTORY_INPUT"
        gum log --structured --time rfc822 --level info "🗃️ use global history files: $AIDER_CHAT_HISTORY_FILE $AIDER_INPUT_HISTORY_FILE"
    fi
fi

###
# RUN AIDER
###
aider "$@"

but it might be nice to have this workflow built into aider itself.

Version and model info

No response

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

1 participant