Skip to content

Commit b591b64

Browse files
committed
refactor: Update context handling and repo map logic
1 parent a337768 commit b591b64

5 files changed

Lines changed: 52 additions & 16 deletions

File tree

aider/coders/context_coder.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ class ContextCoder(Coder):
88
edit_format = "context"
99
gpt_prompts = ContextPrompts()
1010

11+
def __init__(self, *args, **kwargs):
12+
super().__init__(*args, **kwargs)
13+
14+
if not self.repo_map:
15+
return
16+
17+
self.repo_map.refresh = "always"
18+
self.repo_map.max_map_tokens *= self.repo_map.map_mul_no_files
19+
self.repo_map.map_mul_no_files = 1.0
20+
1121
def reply_completed(self):
1222
content = self.partial_response_content
1323
if not content or not content.strip():

aider/coders/context_prompts.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,41 @@
55

66
class ContextPrompts(CoderPrompts):
77
main_system = """Act as an expert code analyst.
8-
Understand the user's question or request, solely to determine the correct set of relevant source files.
9-
Return the *complete* list of files which will need to be read or modified based on the user's request.
8+
Understand the user's question or request, solely to determine ALL the existing sources files which will need to be modified.
9+
Return the *complete* list of files which will need to be modified based on the user's request.
1010
Explain why each file is needed, including names of key classes/functions/methods/variables.
1111
Be sure to include or omit the names of files already added to the chat, based on whether they are actually needed or not.
1212
13-
Be selective!
14-
Adding more files adds more lines of code which increases processing costs.
15-
If we need to see or edit the contents of a file to satisfy the user's request, definitely add it.
16-
But if not, don't add irrelevant files -- especially large ones, which will cost a lot to process.
13+
The user will use every file you mention, regardless of your commentary.
14+
So *ONLY* mention the names of relevant files.
15+
If a file is not relevant DO NOT mention it.
16+
17+
Only return files that will need to be modified, not files that contain useful/relevant functions.
18+
19+
You are only to discuss EXISTING files and symbols.
20+
Only return existing files, don't suggest the names of new files we will need to create.
1721
1822
Always reply to the user in {language}.
1923
20-
Return a simple bulleted list:
24+
Be concise in your replies.
25+
Return:
26+
1. A bulleted list of files the will need to be edited, and symbols that are highly relevant to the user's request.
27+
2. A list of classes/functions/methods/variables that are located OUTSIDE those files which will need to be understood. Just the symbols names, *NOT* file names.
28+
29+
Here an example response, use this format:
30+
31+
## Files to modify, with their relevant symbols:
32+
33+
- alarms/buzz.py
34+
- `Buzzer` class which can make the needed sound
35+
- `Buzzer.buzz_buzz()` method triggers the sound
36+
- alarms/time.py
37+
- `Time.set_alarm(hour, minute)` to set the alarm
38+
39+
## Relevant symbols from OTHER files:
40+
41+
- AlarmManager class for setup/teardown of alarms
42+
- SoundFactory will be used to create a Buzzer
2143
"""
2244

2345
example_messages = []
@@ -46,6 +68,8 @@ class ContextPrompts(CoderPrompts):
4668
"""
4769

4870
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.
71+
Review them to decide if this is the correct set of files or if we need to add more or remove files.
72+
5073
If this is the right set, just return the current list of files.
74+
Or return a smaller or larger set of files which need to be edited, with symbols that are highly relevant to the user's request.
5175
"""

aider/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def cmd_chat_mode(self, args):
149149
),
150150
(
151151
"context",
152-
"Work with surrounding code context for more contextually-aware edits.",
152+
"Automatically identify which files will need to be edited.",
153153
),
154154
]
155155
)

aider/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ def send_completion(self, messages, functions, stream, temperature=None):
748748

749749
kwargs = dict(
750750
model=self.name,
751-
messages=messages,
752751
stream=stream,
753752
)
754753

@@ -779,6 +778,8 @@ def send_completion(self, messages, functions, stream, temperature=None):
779778
kwargs["timeout"] = request_timeout
780779
if self.verbose:
781780
dump(kwargs)
781+
kwargs["messages"] = messages
782+
782783
res = litellm.completion(**kwargs)
783784
return hash_object, res
784785

aider/repomap.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,17 @@ def get_ranked_tags(
447447
definers = defines[ident]
448448

449449
mul = 1.0
450-
# Check for snake_case (contains underscore, no uppercase)
451-
if "_" in ident and not any(c.isupper() for c in ident):
452-
mul *= 10
453-
# Check for camelCase (no underscore, starts with lowercase, has uppercase)
454-
elif not "_" in ident and ident[0].islower() and any(c.isupper() for c in ident):
455-
mul *= 10
450+
451+
is_snake = ("_" in ident) and any(c.isalpha() for c in ident)
452+
is_camel = any(c.isupper() for c in ident) and any(c.islower() for c in ident)
456453
if ident in mentioned_idents:
457454
mul *= 10
455+
if (is_snake or is_camel) and len(ident) >= 8:
456+
mul *= 10
458457
if ident.startswith("_"):
459458
mul *= 0.1
459+
if len(defines[ident]) > 5:
460+
mul *= 0.1
460461

461462
for referencer, num_refs in Counter(references[ident]).items():
462463
for definer in definers:

0 commit comments

Comments
 (0)