diff --git a/aider/coder.py b/aider/coder.py index 76f26a700..f6da50f4b 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -159,17 +159,28 @@ class Coder: return prompt def get_files_messages(self): - files_content = prompts.files_content_prefix - files_content += self.get_files_content() - - all_content = files_content + all_content = "" + if self.abs_fnames: + files_content = prompts.files_content_prefix + files_content += self.get_files_content() + all_content += files_content if self.repo is not None: - files_listing = get_tags_map(self.get_all_abs_files()) - repo_content = prompts.repo_content_prefix - repo_content += files_listing + other_files = set(self.get_all_abs_files()) - set(self.abs_fnames) + if other_files: + files_listing = get_tags_map(other_files) + if self.abs_fnames: + other = "other " + else: + other = "" - all_content = repo_content + "\n\n" + files_content + repo_content = prompts.repo_content_prefix.format(other=other) + repo_content += files_listing + + if all_content: + all_content += "\n\n" + + all_content += repo_content files_messages = [ dict(role="user", content=all_content), @@ -180,7 +191,7 @@ class Coder: ), ] - # utils.show_messages(files_messages, "FILES") + utils.show_messages(files_messages, "FILES") return files_messages def run(self): diff --git a/aider/ctags.py b/aider/ctags.py index 0926d8918..722f3b57d 100644 --- a/aider/ctags.py +++ b/aider/ctags.py @@ -50,12 +50,13 @@ def split_path(path, root_dname): def get_tags(filename, root_dname): - yield split_path(filename, root_dname) - cmd = ["ctags", "--fields=+S", "--output-format=json", filename] output = subprocess.check_output(cmd).decode("utf-8") output = output.splitlines() + if not output: + yield split_path(filename, root_dname) + for line in output: tag = json.loads(line) path = tag.get("path") diff --git a/aider/prompts.py b/aider/prompts.py index 42aec8906..8d6c53d22 100644 --- a/aider/prompts.py +++ b/aider/prompts.py @@ -79,10 +79,13 @@ files_content_gpt_no_edits = "I wasn't able to see any properly formatted edits files_content_local_edits = "I made some changes to the files myself." -repo_content_prefix = "Here is a map showing all the other files and key content:\n\n" - files_content_prefix = ( - "You can propose changes to *only* these files (ask if you need to see others):\n\n" + "You can propose changes to *only* these files (ask before editing others):\n\n" +) + +repo_content_prefix = ( + "Here is a map showing all the {other}files and ctags content. You *must* ask with the full" + " path of the file before suggesting edits to these files:\n\n" ) files_content_suffix = ( diff --git a/tests/test_commands.py b/tests/test_commands.py index 50aa06427..7dbb62f2d 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -5,6 +5,7 @@ from unittest.mock import MagicMock from aider.commands import Commands from aider.io import InputOutput + class TestCommands(TestCase): def test_cmd_add(self): # Create a temporary directory and change the current working directory @@ -13,7 +14,9 @@ class TestCommands(TestCase): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) - coder = MagicMock() + from aider.coder import Coder + + coder = Coder(io) commands = Commands(io, coder) # Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string