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]

Feat(tools): Generalizatoin of review_submit

Kilian Lieret616d79c47da1
diff --git a/tools/review_on_submit_m/README.md b/tools/review_on_submit_m/README.md
new file mode 100644
index 00000000..131667da
--- /dev/null
+++ b/tools/review_on_submit_m/README.md
@@ -0,0 +1,6 @@
+# Review on submit.
+
+Provides an alternative for `submit` that does not immediately submit, but asks the
+agent to perform additional reviewing steps.
+
+Only `submit -f` will trigger the real submit.
\ No newline at end of file
diff --git a/tools/review_on_submit_m/bin/submit b/tools/review_on_submit_m/bin/submit
new file mode 100644
index 00000000..a0fe8240
--- /dev/null
+++ b/tools/review_on_submit_m/bin/submit
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+
+import argparse
+from pathlib import Path
+import subprocess
+import sys
+import os
+import io
+
+from registry import registry
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description="Submit changes for review")
+ parser.add_argument("-f", "--force", action="store_true", help="Force submit without review")
+ args = parser.parse_args()
+
+ repo_root = registry.get("ROOT", os.getenv("ROOT"))
+ assert repo_root
+
+ patch_path = Path("/root/model.patch")
+
+ subprocess.run(
+ f"git add -A && git diff --cached > {patch_path}",
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ cwd=repo_root,
+ )
+
+ patch = patch_path.read_text(errors="backslashreplace")
+
+ submit_review_messages = registry.get("SUBMIT_REVIEW_MESSAGES", [])
+ n_stages = len(submit_review_messages)
+ current_stage = registry.get("SUBMIT_STAGE", 0)
+ if not args.force and current_stage != n_stages:
+ message = submit_review_messages[current_stage]
+ message = message.replace("{{diff}}", patch)
+ message = message.replace("{{problem_statement}}", registry.get("PROBLEM_STATEMENT", ""))
+ registry["SUBMIT_STAGE"] = current_stage + 1
+ print(message)
+ sys.exit(0)
+
+ print("<<SWE_AGENT_SUBMISSION>>")
+ print(patch)
+ print("<<SWE_AGENT_SUBMISSION>>")
+
+
+if __name__ == "__main__":
+ # There are some super strange "ascii can't decode x" errors when printing to the terminal
+ # that can be solved with setting the default encoding for stdout
+ # (note that python3.6 doesn't have the reconfigure method)
+ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
+ main()
diff --git a/tools/review_on_submit_m/config.yaml b/tools/review_on_submit_m/config.yaml
new file mode 100644
index 00000000..082b3d65
--- /dev/null
+++ b/tools/review_on_submit_m/config.yaml
@@ -0,0 +1,6 @@
+tools:
+ submit:
+ signature: "submit"
+ docstring: "submits the current file"
+ # Do not actually show the -f argument to the model, only
+ # use it from the agent for submissiona after error
diff --git a/tools/review_on_submit_m/install.sh b/tools/review_on_submit_m/install.sh
new file mode 100644
index 00000000..e69de29b