Skip to content

Commit 5661d14

Browse files
committed
refactor: Enhance file mention handling and context coder logic
1 parent f543c1e commit 5661d14

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

aider/coders/base_coder.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,8 @@ def send_message(self, inp):
14561456
return
14571457

14581458
try:
1459-
self.reply_completed()
1459+
if self.reply_completed():
1460+
return
14601461
except KeyboardInterrupt:
14611462
interrupted = True
14621463

@@ -1599,7 +1600,7 @@ def add_assistant_reply_to_cur_messages(self):
15991600
)
16001601
]
16011602

1602-
def get_file_mentions(self, content):
1603+
def get_file_mentions(self, content, ignore_current=False):
16031604
words = set(word for word in content.split())
16041605

16051606
# drop sentence punctuation from the end
@@ -1609,12 +1610,16 @@ def get_file_mentions(self, content):
16091610
quotes = "\"'`*_"
16101611
words = set(word.strip(quotes) for word in words)
16111612

1612-
addable_rel_fnames = self.get_addable_relative_files()
1613+
if ignore_current:
1614+
addable_rel_fnames = self.get_all_relative_files()
1615+
existing_basenames = {}
1616+
else:
1617+
addable_rel_fnames = self.get_addable_relative_files()
16131618

1614-
# Get basenames of files already in chat or read-only
1615-
existing_basenames = {os.path.basename(f) for f in self.get_inchat_relative_files()} | {
1616-
os.path.basename(self.get_rel_fname(f)) for f in self.abs_read_only_fnames
1617-
}
1619+
# Get basenames of files already in chat or read-only
1620+
existing_basenames = {os.path.basename(f) for f in self.get_inchat_relative_files()} | {
1621+
os.path.basename(self.get_rel_fname(f)) for f in self.abs_read_only_fnames
1622+
}
16181623

16191624
mentioned_rel_fnames = set()
16201625
fname_to_rel_fnames = {}

aider/coders/context_coder.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from aider.dump import dump
2+
13
from .base_coder import Coder
24
from .context_prompts import ContextPrompts
35

@@ -7,3 +9,28 @@ class ContextCoder(Coder):
79

810
edit_format = "context"
911
gpt_prompts = ContextPrompts()
12+
13+
def reply_completed(self):
14+
content = self.partial_response_content
15+
if not content or not content.strip():
16+
return True
17+
18+
dump(repr(content))
19+
current_rel_fnames = set(self.get_inchat_relative_files())
20+
mentioned_rel_fnames = set(self.get_file_mentions(content, ignore_current=True))
21+
22+
dump(current_rel_fnames)
23+
dump(mentioned_rel_fnames)
24+
dump(current_rel_fnames == mentioned_rel_fnames)
25+
26+
if mentioned_rel_fnames != current_rel_fnames:
27+
self.abs_fnames = set()
28+
for fname in mentioned_rel_fnames:
29+
self.add_rel_fname(fname)
30+
dump(self.get_inchat_relative_files())
31+
self.reflected_message = self.gpt_prompts.try_again
32+
33+
return True
34+
35+
def check_for_file_mentions(self, content):
36+
pass

aider/coders/context_prompts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ class ContextPrompts(CoderPrompts):
4343

4444
system_reminder = """
4545
NEVER RETURN CODE!
46+
"""
47+
48+
try_again = """I have updated the set of files added to the chat.
49+
Review them to decide if this is the correct set of files or if we need to add more.
50+
If this is the right set, just return the current list of files.
4651
"""

0 commit comments

Comments
 (0)