Merge branch 'main' into ask-plan-simple

This commit is contained in:
Paul Gauthier 2024-09-25 07:46:15 -07:00
commit a9e9f9cdbe
51 changed files with 2565 additions and 368 deletions

View file

@ -493,9 +493,10 @@ class Coder:
if content is not None:
all_content += content + "\n"
lines = all_content.splitlines()
good = False
for fence_open, fence_close in self.fences:
if fence_open in all_content or fence_close in all_content:
if any(line.startswith(fence_open) or line.startswith(fence_close) for line in lines):
continue
good = True
break
@ -1101,7 +1102,10 @@ class Coder:
utils.show_messages(messages, functions=self.functions)
self.multi_response_content = ""
self.mdstream = self.io.assistant_output("", self.stream)
if self.show_pretty() and self.stream:
self.mdstream = self.io.get_assistant_mdstream()
else:
self.mdstream = None
retry_delay = 0.125
@ -1395,6 +1399,7 @@ class Coder:
self.stream,
temp,
extra_headers=model.extra_headers,
extra_body=model.extra_body,
max_tokens=model.max_tokens,
)
self.chat_completion_call_hashes.append(hash_object.hexdigest())
@ -1458,7 +1463,7 @@ class Coder:
raise Exception("No data found in LLM response!")
show_resp = self.render_incremental_response(True)
self.io.assistant_output(show_resp)
self.io.assistant_output(show_resp, pretty=self.show_pretty())
if (
hasattr(completion.choices[0], "finish_reason")
@ -1897,8 +1902,6 @@ class Coder:
return
if self.commit_before_message[-1] != self.repo.get_head_commit_sha():
self.io.tool_output("You can use /undo to undo and discard each aider commit.")
else:
self.io.tool_output("No changes made to git tracked files.")
def dirty_commit(self):
if not self.need_commit_before_edits:

View file

@ -365,9 +365,13 @@ def do_replace(fname, content, before_text, after_text, fence=None):
return new_content
HEAD = "<<<<<<< SEARCH"
DIVIDER = "======="
UPDATED = ">>>>>>> REPLACE"
HEAD = r"<{5,9} SEARCH"
DIVIDER = r"={5,9}"
UPDATED = r">{5,9} REPLACE"
HEAD_ERR = "<<<<<<< SEARCH"
DIVIDER_ERR = "======="
UPDATED_ERR = ">>>>>>> REPLACE"
separators = "|".join([HEAD, DIVIDER, UPDATED])
@ -407,6 +411,10 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
i = 0
current_filename = None
head_pattern = re.compile(HEAD)
divider_pattern = re.compile(DIVIDER)
updated_pattern = re.compile(UPDATED)
while i < len(lines):
line = lines[i]
@ -425,7 +433,7 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
"```csh",
"```tcsh",
]
next_is_editblock = i + 1 < len(lines) and lines[i + 1].rstrip() == HEAD
next_is_editblock = i + 1 < len(lines) and head_pattern.match(lines[i + 1].strip())
if any(line.strip().startswith(start) for start in shell_starts) and not next_is_editblock:
shell_content = []
@ -440,15 +448,13 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
continue
# Check for SEARCH/REPLACE blocks
if line.strip() == HEAD:
if head_pattern.match(line.strip()):
try:
# if next line after HEAD exists and is DIVIDER, it's a new file
if i + 1 < len(lines) and lines[i + 1].strip() == DIVIDER:
if i + 1 < len(lines) and divider_pattern.match(lines[i + 1].strip()):
filename = find_filename(lines[max(0, i - 3) : i], fence, None)
else:
filename = find_filename(
lines[max(0, i - 3) : i], fence, valid_fnames
)
filename = find_filename(lines[max(0, i - 3) : i], fence, valid_fnames)
if not filename:
if current_filename:
@ -460,21 +466,27 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
original_text = []
i += 1
while i < len(lines) and not lines[i].strip() == DIVIDER:
while i < len(lines) and not divider_pattern.match(lines[i].strip()):
original_text.append(lines[i])
i += 1
if i >= len(lines) or lines[i].strip() != DIVIDER:
raise ValueError(f"Expected `{DIVIDER}`")
if i >= len(lines) or not divider_pattern.match(lines[i].strip()):
raise ValueError(f"Expected `{DIVIDER_ERR}`")
updated_text = []
i += 1
while i < len(lines) and not lines[i].strip() in (UPDATED, DIVIDER):
while i < len(lines) and not (
updated_pattern.match(lines[i].strip())
or divider_pattern.match(lines[i].strip())
):
updated_text.append(lines[i])
i += 1
if i >= len(lines) or lines[i].strip() not in (UPDATED, DIVIDER):
raise ValueError(f"Expected `{UPDATED}` or `{DIVIDER}`")
if i >= len(lines) or not (
updated_pattern.match(lines[i].strip())
or divider_pattern.match(lines[i].strip())
):
raise ValueError(f"Expected `{UPDATED_ERR}` or `{DIVIDER_ERR}`")
yield filename, "".join(original_text), "".join(updated_text)

View file

@ -58,6 +58,8 @@ class WholeFileCoder(Coder):
fname = fname.strip("*") # handle **filename.py**
fname = fname.rstrip(":")
fname = fname.strip("`")
fname = fname.lstrip("#")
fname = fname.strip()
# Issue #1232
if len(fname) > 250: