Skip to content

Commit

Permalink
feat: let user tweak architect prompt before passing to editor-model
Browse files Browse the repository at this point in the history
  • Loading branch information
gitkenan committed Jan 31, 2025
1 parent 778e54e commit e4f9cfb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
28 changes: 19 additions & 9 deletions aider/coders/architect_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,32 @@ def reply_completed(self):
if not content or not content.strip():
return

if not self.io.confirm_ask("Edit the files?"):
response = self.io.confirm_ask("Edit the files?", skip_chat_history=True, allow_tweak=True)
if response == "tweak":
content = self.io.edit_in_editor(content)
# Now that content is finalized, append the edit decision to chat history
self.io.append_chat_history("> Edit the files? (Y)es/(T)weak/(N)o [Yes]: \n", blockquote=True)
elif not response:
return
else:
# For yes/no responses, append to chat history
self.io.append_chat_history("> Edit the files? (Y)es/(T)weak/(N)o [Yes]: \n", blockquote=True)

kwargs = dict()

# Use the editor_model from the main_model if it exists, otherwise use the main_model itself
editor_model = self.main_model.editor_model or self.main_model

kwargs["main_model"] = editor_model
kwargs["edit_format"] = self.main_model.editor_edit_format
kwargs["suggest_shell_commands"] = False
kwargs["map_tokens"] = 0
kwargs["total_cost"] = self.total_cost
kwargs["cache_prompts"] = False
kwargs["num_cache_warming_pings"] = 0
kwargs["summarize_from_coder"] = False
kwargs = {
"main_model": editor_model,
"edit_format": self.main_model.editor_edit_format,
"suggest_shell_commands": False,
"map_tokens": 0,
"total_cost": self.total_cost,
"cache_prompts": False,
"num_cache_warming_pings": 0,
"summarize_from_coder": False
}

new_kwargs = dict(io=self.io, from_coder=self)
new_kwargs.update(kwargs)
Expand Down
41 changes: 30 additions & 11 deletions aider/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,22 @@ def offer_url(self, url, prompt="Open URL for more info?", allow_never=True):
return True
return False

def edit_in_editor(self, content):
import tempfile
import subprocess

with tempfile.NamedTemporaryFile(suffix=".md", mode="w", delete=False, encoding=self.encoding) as tmpfile:
tmpfile.write(content)
tmpfile.flush()
editor = os.environ.get('EDITOR', 'vi')
subprocess.call([editor, tmpfile.name])

with open(tmpfile.name, "r", encoding=self.encoding) as f:
edited = f.read()

os.unlink(tmpfile.name)
return edited

def confirm_ask(
self,
question,
Expand All @@ -670,6 +686,8 @@ def confirm_ask(
explicit_yes_required=False,
group=None,
allow_never=False,
skip_chat_history=False,
allow_tweak=False,
):
# Temporarily disable multiline mode for yes/no prompts
orig_multiline = self.multiline_mode
Expand All @@ -688,6 +706,9 @@ def confirm_ask(

valid_responses = ["yes", "no"]
options = " (Y)es/(N)o"
if allow_tweak:
valid_responses.append("tweak")
options = " (Y)es/(T)weak/(N)o"
if group:
if not explicit_yes_required:
options += "/(A)ll"
Expand All @@ -713,11 +734,6 @@ def confirm_ask(

style = self._get_style()

def is_valid_response(text):
if not text:
return True
return text.lower() in valid_responses

if self.yes is True:
res = "n" if explicit_yes_required else "y"
elif self.yes is False:
Expand Down Expand Up @@ -749,13 +765,16 @@ def is_valid_response(text):
self.tool_error(error_message)

res = res.lower()[0]

if res == "d" and allow_never:
self.never_prompts.add(question_id)
hist = f"{question.strip()} {res}"
self.append_chat_history(hist, linebreak=True, blockquote=True)
if not skip_chat_history:
hist = f"{question.strip()} {res}"
self.append_chat_history(hist, linebreak=True, blockquote=True)
return False

if res == "t":
return "tweak"

if explicit_yes_required:
is_yes = res == "y"
else:
Expand All @@ -770,9 +789,9 @@ def is_valid_response(text):
elif is_skip:
group.preference = "skip"

hist = f"{question.strip()} {res}"
self.append_chat_history(hist, linebreak=True, blockquote=True)

if not skip_chat_history:
hist = f"{question.strip()} {res}"
self.append_chat_history(hist, linebreak=True, blockquote=True)
# Restore original multiline mode
self.multiline_mode = orig_multiline

Expand Down

0 comments on commit e4f9cfb

Please sign in to comment.