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

feat: create .aider.working when ai! comment is detected (closes #2562) #2612

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion aider/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from aider.mdstream import MarkdownStream

from .dump import dump # noqa: F401
from .utils import is_image_file
from .utils import is_image_file, get_canary_path


@dataclass
Expand Down Expand Up @@ -405,6 +405,14 @@ def get_input(
):
self.rule()

canary_path=get_canary_path(root)
try: # remove canary file if it exists, so wait-for-aider.sh can continue
if os.path.exists(canary_path):
os.remove(canary_path)
except:
pass # yes we don't care if it fails


rel_fnames = list(rel_fnames)
show = ""
if rel_fnames:
Expand Down
11 changes: 11 additions & 0 deletions aider/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def make_repo(path=None):

return repo

def get_canary_path(from_path=None):
"""used by scripts/wait-for-aider.sh"""
return Path(get_repo_root(from_path or os.getcwd())) / ".aider.working"

def get_repo_root(path):
"""Get the repository root directory for the given path."""
try:
repo = git.Repo(path, search_parent_directories=True)
return repo.git.rev_parse("--show-toplevel")
except:
return path

def is_image_file(file_name):
"""
Expand Down
4 changes: 4 additions & 0 deletions aider/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from watchfiles import watch

from aider.dump import dump # noqa
from aider.utils import get_canary_path
from aider.watch_prompts import watch_ask_prompt, watch_code_prompt


Expand Down Expand Up @@ -162,6 +163,9 @@ def process_changes(self):
if not has_action:
return ""

with open(get_canary_path(self.root), 'w') as file:
file.write("this is a canary file for wait-for-aider.sh which will be deleted after Aider finishes processing changes")

if self.analytics:
self.analytics.event("ai-comments execute")
self.io.tool_output("Processing your request...")
Expand Down
29 changes: 29 additions & 0 deletions scripts/wait-for-aider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# usage: pycharm preferences > tools > file watchers > add
#
# - Files to watch > File type > Any;
# - Tool to run on changes: wait-for-aider.sh
# - Output paths to refresh: $Projectpath$
# - [x] autosave, [-] trigger on external, [x] trigger regardless of syntax errors, [-] create output from stdout

repo_root=$(git rev-parse --show-toplevel)
# created in FileWatcher.process_changes, removed in InputOutput.get_input
filename="$repo_root/.aider.working"

has_one_second_passed() {
local current_time=$(date +%s)
local time_diff=$((current_time - start_time))
[ $time_diff -ge 1 ]
}

start_time=$(date +%s)

# wait while the file exists and at least one second has passed so we don't exit immediately
echo "waiting for $filename to be deleted..."

while [ -e "$filename" ] || ! has_one_second_passed; do
sleep 0.1
done

echo "exiting."