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]
Merge branch 'main' into allow-run-locally
Kilian Lieret2e9b7381835d
diff --cc run.pyindex 2d5a2f69,aa36a547..92809de6--- a/run.py+++ b/run.py@@@ -2,9 -2,12 +2,13 @@@ import jsoimport loggingimport osimport re+import subprocessimport tracebackfrom typing import Any, Dict, Optional+ import rich.console+ import rich.markdown+ import rich.panel+ import rich.markdownimport yamlfrom dataclasses import dataclass@@@ -277,20 -281,30 +283,45 @@@ def save_patch(traj_dir: Path, instancereturn patch_output_file+def apply_patch(local_dir: Path, patch_file: Path) -> None:+ """Apply a patch to a local directory."""+ assert local_dir.is_dir()+ assert patch_file.exists()+ # The resolve() is important, because we're gonna run the cmd+ # somewhere else+ cmd = ["git", "apply", str(patch_file.resolve())]+ try:+ subprocess.run(cmd, cwd=local_dir, check=True)+ except subprocess.CalledProcessError as e:+ logger.error(f"Failed to apply patch {patch_file} to {local_dir}: {e}")+ return+ logger.info(f"Applied patch {patch_file} to {local_dir}")++++ def _print_patch_message(patch_output_file: Path):+ console = rich.console.Console()+ msg = [+ "SWE-agent has produced a patch that it believes will solve the issue you submitted!",+ "Use the code snippet below to inspect or apply it!"+ ]+ panel = rich.panel.Panel.fit(+ "\n".join(msg),+ title="🎉 Submission successful 🎉",+ )+ console.print(panel)+ content = [+ "```bash",+ f"# The patch has been saved to your local filesystem at:",+ f"PATCH_FILE_PATH='{patch_output_file.resolve()}'",+ "# Inspect it:",+ "cat \"${PATCH_FILE_PATH}\"",+ "# Apply it to a local repository:",+ f"cd <your local repo root>",+ "git apply \"${PATCH_FILE_PATH}\"",+ "```",+ ]+ console.print(rich.markdown.Markdown("\n".join(content)))+def get_args(args=None) -> ScriptArguments:"""Parse command line arguments and return a ScriptArguments object.diff --cc run_replay.pyindex ec524600,863d4b26..fb56401a--- a/run_replay.py+++ b/run_replay.py@@@ -63,9 -64,9 +63,9 @@@ def process_single_traj(traj_path: strwith open(tmp_path, "w") as f:for d in data:print(json.dumps(d), file=f, end="\n", flush=True)- return replay_task_instances_path+ return tmp_path- is_github = False+ is_other = Falseif data_path.endswith(".jsonl"):replay_task_instances_path = create_task_instances_tmp_file([json.loads(x) for x in open(data_path, "r").readlines()])elif data_path.endswith(".json"):