Skip to content

Commit

Permalink
feat: create .aider.working when ai! comment is detected, remove when…
Browse files Browse the repository at this point in the history
… processing is finished (closes Aider-AI#2562)
  • Loading branch information
wizzard0 committed Dec 12, 2024
1 parent 8ee8279 commit d1420b5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
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
22 changes: 22 additions & 0 deletions scripts/wait-for-aider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

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."

0 comments on commit d1420b5

Please sign in to comment.