Skip to content

Commit d1b8482

Browse files
committed
Merge branch 'main' into v0.91.2
2 parents 75a72c9 + 99c9c1e commit d1b8482

70 files changed

Lines changed: 1455 additions & 1241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aider/coders/agent_coder.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
view_files_with_symbol,
7373
)
7474

75-
from .agent_prompts import AgentPrompts
7675
from .base_coder import ChatChunks, Coder
7776
from .editblock_coder import do_replace, find_original_update_blocks, find_similar_lines
7877

@@ -81,7 +80,7 @@ class AgentCoder(Coder):
8180
"""Mode where the LLM autonomously manages which files are in context."""
8281

8382
edit_format = "agent"
84-
gpt_prompts = AgentPrompts()
83+
prompt_format = "agent"
8584

8685
def __init__(self, *args, **kwargs):
8786
# Dictionary to track recently removed files
@@ -876,6 +875,10 @@ def format_chat_chunks(self):
876875
tool_context = self._generate_tool_context(repetitive_tools)
877876
if tool_context:
878877
post_message_blocks.append(tool_context)
878+
else:
879+
write_context = self._generate_write_context()
880+
if write_context:
881+
post_message_blocks.append(write_context)
879882

880883
if static_blocks:
881884
for block in static_blocks:
@@ -1934,6 +1937,26 @@ def _generate_tool_context(self, repetitive_tools):
19341937
context_parts.append("</context>")
19351938
return "\n".join(context_parts)
19361939

1940+
def _generate_write_context(self):
1941+
if self.last_round_tools:
1942+
last_round_has_write = any(
1943+
tool.lower() in self.write_tools for tool in self.last_round_tools
1944+
)
1945+
if last_round_has_write:
1946+
context_parts = [
1947+
'<context name="tool_usage_history">',
1948+
"A file was just edited.",
1949+
(
1950+
" Do not just modify comments"
1951+
" and/or logging statements with placeholder information."
1952+
),
1953+
"Make sure that something of value was done.</context>",
1954+
]
1955+
1956+
return "\n".join(context_parts)
1957+
1958+
return ""
1959+
19371960
async def _apply_edits_from_response(self):
19381961
"""
19391962
Parses and applies SEARCH/REPLACE edits found in self.partial_response_content.

aider/coders/agent_prompts.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

aider/coders/architect_coder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import asyncio
22

33
from ..commands import SwitchCoder
4-
from .architect_prompts import ArchitectPrompts
54
from .ask_coder import AskCoder
65
from .base_coder import Coder
76

87

98
class ArchitectCoder(AskCoder):
109
edit_format = "architect"
11-
gpt_prompts = ArchitectPrompts()
10+
prompt_format = "architect"
1211
auto_accept_architect = False
1312

1413
async def reply_completed(self):

aider/coders/architect_prompts.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

aider/coders/ask_coder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from .ask_prompts import AskPrompts
21
from .base_coder import Coder
32

43

54
class AskCoder(Coder):
65
"""Ask questions about code without making any changes."""
76

87
edit_format = "ask"
9-
gpt_prompts = AskPrompts()
8+
prompt_format = "ask"

aider/coders/ask_prompts.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

aider/coders/base_coder.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from prompt_toolkit.patch_stdout import patch_stdout
3535
from rich.console import Console
3636

37-
from aider import __version__, models, prompts, urls, utils
37+
import aider.prompts.utils.system as prompts
38+
from aider import __version__, models, urls, utils
3839
from aider.commands import Commands, SwitchCoder
3940
from aider.exceptions import LiteLLMExceptions
4041
from aider.helpers import coroutines
@@ -58,6 +59,7 @@
5859
from aider.utils import format_tokens, is_image_file
5960

6061
from ..dump import dump # noqa: F401
62+
from ..prompts.utils.prompt_registry import registry
6163
from .chat_chunks import ChatChunks
6264

6365

@@ -155,6 +157,8 @@ class Coder:
155157
# Weak reference to TUI app instance (when running in TUI mode)
156158
tui = None
157159

160+
_prompt_cache = {}
161+
158162
@classmethod
159163
async def create(
160164
self,
@@ -556,6 +560,45 @@ def __init__(
556560
self.io.tool_output("JSON Schema:")
557561
self.io.tool_output(json.dumps(self.functions, indent=4))
558562

563+
@property
564+
def gpt_prompts(self):
565+
"""Get prompts from the registry based on the coder type."""
566+
cls = self.__class__
567+
568+
# Every coder class MUST have a prompt_format attribute
569+
if not hasattr(cls, "prompt_format"):
570+
raise AttributeError(
571+
f"Coder class {cls.__name__} must have a 'prompt_format' attribute. "
572+
"Add 'prompt_format = \"<format_name>\"' to the class definition."
573+
)
574+
575+
if cls.prompt_format is None:
576+
raise AttributeError(
577+
f"Coder class {cls.__name__} has prompt_format=None. "
578+
"It must have a valid prompt format name."
579+
)
580+
581+
prompt_name = cls.prompt_format
582+
583+
# Check cache first
584+
if prompt_name in Coder._prompt_cache:
585+
return Coder._prompt_cache[prompt_name]
586+
587+
# Get prompts from registry
588+
prompts = registry.get_prompt(prompt_name)
589+
590+
# Create a simple object that allows attribute access
591+
class PromptObject:
592+
def __init__(self, prompts_dict):
593+
for key, value in prompts_dict.items():
594+
setattr(self, key, value)
595+
596+
# Cache the prompt object
597+
prompt_obj = PromptObject(prompts)
598+
Coder._prompt_cache[prompt_name] = prompt_obj
599+
600+
return prompt_obj
601+
559602
def get_announcements(self):
560603
lines = []
561604
lines.append(f"cecli v{__version__}")

0 commit comments

Comments
 (0)