mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-16 01:25:00 +00:00
stronger wholefile prompt about file listings; adopt allowed_to_edit in wholefile; tests
This commit is contained in:
parent
d00e7c39d1
commit
eaf02da46b
4 changed files with 50 additions and 12 deletions
|
@ -95,6 +95,9 @@ class Coder:
|
|||
stream=True,
|
||||
use_git=True,
|
||||
):
|
||||
if not fnames:
|
||||
fnames = []
|
||||
|
||||
self.verbose = verbose
|
||||
self.abs_fnames = set()
|
||||
self.cur_messages = []
|
||||
|
|
|
@ -28,14 +28,12 @@ class WholeFileCoder(Coder):
|
|||
|
||||
edited = set()
|
||||
chat_files = self.get_inchat_relative_files()
|
||||
if not chat_files:
|
||||
if mode == "diff":
|
||||
return content
|
||||
return
|
||||
|
||||
output = []
|
||||
lines = content.splitlines(keepends=True)
|
||||
|
||||
allowed_to_edit = False
|
||||
|
||||
fname = None
|
||||
new_lines = []
|
||||
for i, line in enumerate(lines):
|
||||
|
@ -55,10 +53,11 @@ class WholeFileCoder(Coder):
|
|||
).splitlines()
|
||||
output += show_diff
|
||||
else:
|
||||
edited.add(fname)
|
||||
if not self.dry_run:
|
||||
new_lines = "".join(new_lines)
|
||||
Path(full_path).write_text(new_lines)
|
||||
if allowed_to_edit:
|
||||
edited.add(fname)
|
||||
if not self.dry_run:
|
||||
new_lines = "".join(new_lines)
|
||||
Path(full_path).write_text(new_lines)
|
||||
|
||||
fname = None
|
||||
new_lines = []
|
||||
|
@ -74,8 +73,11 @@ class WholeFileCoder(Coder):
|
|||
else:
|
||||
fname = lines[i - 1].strip()
|
||||
|
||||
if mode == "update" and not self.allowed_to_edit(fname):
|
||||
raise ValueError(f"{fname} is not one of: {show_chat_files}")
|
||||
if mode == "update":
|
||||
if self.allowed_to_edit(fname):
|
||||
allowed_to_edit = True
|
||||
else:
|
||||
allowed_to_edit = False
|
||||
|
||||
elif fname:
|
||||
new_lines.append(line)
|
||||
|
|
|
@ -14,14 +14,20 @@ Once you understand the request you MUST:
|
|||
3. If changes are needed, output a copy of each file that needs changes.
|
||||
"""
|
||||
|
||||
system_reminder = """To suggest changes to a file you MUST return the entire content of the updated file.
|
||||
You MUST use this format:
|
||||
system_reminder = """
|
||||
To return code you MUST use this *file listing* format:
|
||||
|
||||
exact/path/to/filename.js
|
||||
```javascript
|
||||
// file content goes in the
|
||||
// triple backticked fenced block
|
||||
```
|
||||
|
||||
Every *file listing* must start with the full path!
|
||||
Every *file listing* must be fenced w/triple backticks with the correct code language.
|
||||
|
||||
To suggest changes to a file you MUST return a *file listing* that contains the entire content of the file.
|
||||
Create a new file you MUST return a *file listing* which includes an appropriate path/filename.
|
||||
"""
|
||||
|
||||
files_content_prefix = "Here is the current content of the files:\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue