feat: Add support for ! and ? action comments

This commit is contained in:
Paul Gauthier 2024-12-11 20:23:29 -08:00 committed by Paul Gauthier (aider)
parent b16ba547ab
commit 11512c6281
3 changed files with 16 additions and 8 deletions

View file

@ -9,7 +9,7 @@ from pathspec.patterns import GitWildMatchPattern
from watchfiles import watch from watchfiles import watch
from aider.dump import dump # noqa from aider.dump import dump # noqa
from aider.watch_prompts import watch_prompt from aider.watch_prompts import watch_ask_prompt, watch_code_prompt
def is_source_file(path: Path) -> bool: def is_source_file(path: Path) -> bool:
@ -188,11 +188,14 @@ class FileWatcher:
self.analytics.event("ai-comments execute") self.analytics.event("ai-comments execute")
self.io.tool_output("Processing your request...") self.io.tool_output("Processing your request...")
res = watch_prompt if has_action == "!":
res = watch_code_prompt
elif has_action == "?":
res = watch_ask_prompt
# Refresh all AI comments from tracked files # Refresh all AI comments from tracked files
for fname in self.coder.abs_fnames: for fname in self.coder.abs_fnames:
line_nums, comments, _has_bang = self.get_ai_comments(fname) line_nums, comments, _action = self.get_ai_comments(fname)
if not line_nums: if not line_nums:
continue continue

View file

@ -1,6 +1,11 @@
watch_prompt = """ watch_code_prompt = """
Find the "AI" comments below (marked with ) in the code files I've shared with you. Find the "AI" comments below (marked with ) in the code files I've shared with you.
They contain your instructions. They contain your instructions.
Make the requested changes. Make the requested changes.
Be sure to remove all these "AI" comments from the code! Be sure to remove all these "AI" comments from the code!
""" """
watch_ask_prompt = """/ask
Find the "AI" comments below (marked with ) in the code files I've shared with you.
They contain your questions you need to answer and other instructions.
"""

View file

@ -32,7 +32,7 @@ def test_ai_comment_pattern():
f"Expected {py_expected} unique AI comments in Python fixture, found" f"Expected {py_expected} unique AI comments in Python fixture, found"
f" {len(unique_py_comments)}" f" {len(unique_py_comments)}"
) )
assert py_has_bang, "Expected at least one bang (!) comment in Python fixture" assert py_has_bang == "!", "Expected at least one bang (!) comment in Python fixture"
# Test JavaScript fixture # Test JavaScript fixture
js_path = fixtures_dir / "watch.js" js_path = fixtures_dir / "watch.js"
@ -41,18 +41,18 @@ def test_ai_comment_pattern():
assert ( assert (
len(js_lines) == js_expected len(js_lines) == js_expected
), f"Expected {js_expected} AI comments in JavaScript fixture, found {len(js_lines)}" ), f"Expected {js_expected} AI comments in JavaScript fixture, found {len(js_lines)}"
assert js_has_bang, "Expected at least one bang (!) comment in JavaScript fixture" assert js_has_bang == "!", "Expected at least one bang (!) comment in JavaScript fixture"
# Test watch_question.js fixture # Test watch_question.js fixture
question_js_path = fixtures_dir / "watch_question.js" question_js_path = fixtures_dir / "watch_question.js"
question_js_lines, question_js_comments, question_js_has_bang = watcher.get_ai_comments( question_js_lines, question_js_comments, question_js_has_bang = watcher.get_ai_comments(
str(question_js_path) str(question_js_path)
) )
question_js_expected = 5 question_js_expected = 6
assert len(question_js_lines) == question_js_expected, ( assert len(question_js_lines) == question_js_expected, (
f"Expected {question_js_expected} AI comments in watch_question.js fixture, found" f"Expected {question_js_expected} AI comments in watch_question.js fixture, found"
f" {len(question_js_lines)}" f" {len(question_js_lines)}"
) )
assert ( assert (
question_js_has_bang question_js_has_bang == "?"
), "Expected at least one bang (!) comment in watch_question.js fixture" ), "Expected at least one bang (!) comment in watch_question.js fixture"