From 43790db48e4492404c45af90feb69a8241cb6807 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 25 Oct 2024 13:22:13 -0700 Subject: [PATCH] feat: add AI marker detection in source file watcher --- aider/watch.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/aider/watch.py b/aider/watch.py index 5bfaa22a3..78bb42595 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -93,8 +93,17 @@ def watch_source_files( if ignore_func and ignore_func(rel_path): return False - # ai: check to see if the file contains "# *ai\w", "// *ai\w", case insensitive and only return files that do - return is_source_file(path_obj) + if not is_source_file(path_obj): + return False + + # Check if file contains AI markers + try: + with open(path_abs) as f: + content = f.read() + import re + return bool(re.search(r'(?:^|\n)(?:#|//) *ai\w', content, re.IGNORECASE)) + except (IOError, UnicodeDecodeError): + return False # Watch the directory for changes for changes in watch(root, watch_filter=filter_func, stop_event=stop_event):