Skip to content

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]

Tools: Add retry mechanic to `insert` as well

Kilian Lieret59f34fb8f802
diff --git a/tools/edit_replace/bin/edit b/tools/edit_replace/bin/edit
index 3eb2b239..63082378 100644
--- a/tools/edit_replace/bin/edit
+++ b/tools/edit_replace/bin/edit
@@ -65,7 +65,7 @@ def main(search: str, replace: str, replace_all: bool):
try:
wf = WindowedFile(exit_on_exception=False)
except FileNotOpened:
- print("No file opened. Either `open` a file first.")
+ print("No file opened. Either `open` or `create` a file first.")
exit(1)
# Turn \\n into \n etc., i.e., undo the escaping
diff --git a/tools/edit_replace/bin/insert b/tools/edit_replace/bin/insert
index 4a1187c6..ebba8b80 100644
--- a/tools/edit_replace/bin/insert
+++ b/tools/edit_replace/bin/insert
@@ -6,14 +6,15 @@ from typing import Union
from default_utils import FileNotOpened, WindowedFile # type: ignore
from flake8_utils import flake8, format_flake8_output # type: ignore
-_SINGLE_EDIT_SUCCESS_MSG = """Text appended. Please review the changes and make sure they are correct
-(correct indentation, no duplicate lines, etc). Edit the file again if necessary."""
+RETRY_WITH_OUTPUT_TOKEN = "###SWE-AGENT-RETRY-WITH-OUTPUT###"
-_LINT_ERROR_TEMPLATE = """ Your proposed edit has introduced new syntax error(s). Please read this error message carefully and then retry editing the file.
+_LINT_ERROR_TEMPLATE = """Your proposed edit has introduced new syntax error(s).
+Please read this error message carefully and then retry editing the file.
ERRORS:
{errors}
+
This is how your edit would have looked if applied
------------------------------------------------
{window_applied}
@@ -41,6 +42,7 @@ def main(text: str, line: Union[int, None] = None):
wf = WindowedFile(exit_on_exception=False)
except FileNotOpened:
print("No file opened. Use the `create` or `open` command first.")
+ print(RETRY_WITH_OUTPUT_TOKEN)
exit(1)
pre_edit_lint = flake8(wf.path)
@@ -65,6 +67,7 @@ def main(text: str, line: Union[int, None] = None):
errors=new_flake8_output, window_applied=with_edits, window_original=without_edits
)
)
+ print(RETRY_WITH_OUTPUT_TOKEN)
exit(4)
wf.print_window()