SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Fix(tools): Avoid breaking assertions
Kilian Lieret1d1f3673298f
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editorindex d47255dc..c7778dbe 100644--- a/tools/edit_anthropic/bin/str_replace_editor+++ b/tools/edit_anthropic/bin/str_replace_editor@@ -177,18 +177,18 @@ class WindowExpander:Both inclusive."""# print("Input:", start, stop)- assert 1 <= start <= stop <= len(lines)+ assert 1 <= start <= stop <= len(lines), (start, stop, len(lines))if max_added_lines <= 0:# Already at max range, no expansionreturn start, stopnew_start = self._find_breakpoints(lines, start, direction=-1, max_added_lines=max_added_lines)new_stop = self._find_breakpoints(lines, stop, direction=1, max_added_lines=max_added_lines)# print(f"Expanded window is {new_start} to {new_stop}")- assert new_start <= new_stop+ assert new_start <= new_stop, (new_start, new_stop)assert new_start <= start, (new_start, start)- assert start - new_start <= max_added_lines+ assert start - new_start <= max_added_lines, (start, new_start)assert new_stop >= stop, (new_stop, stop)- assert new_stop - stop <= max_added_lines+ assert new_stop - stop <= max_added_lines, (new_stop, stop)return new_start, new_stop@@ -397,8 +397,8 @@ class EditTool:# Create a snippet of the edited sectionreplacement_line = file_content.split(old_str)[0].count("\n")- start_line = max(0, replacement_line - SNIPPET_LINES)- end_line = replacement_line + SNIPPET_LINES + new_str.count("\n")+ start_line = max(1, replacement_line - SNIPPET_LINES)+ end_line = min(replacement_line + SNIPPET_LINES + new_str.count("\n"), len(new_file_content.splitlines()))start_line, end_line = WindowExpander(suffix=path.suffix).expand_window(new_file_content.split("\n"), start_line, end_line, max_added_lines=MAX_WINDOW_EXPANSION_EDIT_CONFIRM)