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]
added functionality to load from challenge.json
Talor Abramovich132176d859a2
diff --git a/config/commands/defaults.sh b/config/commands/defaults.shindex 226942a2..57f005b0 100644--- a/config/commands/defaults.sh+++ b/config/commands/defaults.sh@@ -174,22 +174,3 @@ create() {# Use the existing open command to open the created fileopen "$1"}--# @yaml-# signature: submit-# docstring: submits your current code and terminates the session-submit() {- cd $ROOT-- # Check if the patch file exists and is non-empty- if [ -s "/root/test.patch" ]; then- # Apply the patch in reverse- git apply -R < "/root/test.patch"- fi-- git add -A- git diff --cached > model.patch- echo "<<SUBMISSION||"- cat model.patch- echo "||SUBMISSION>>"-}diff --git a/config/default_ctf.yaml b/config/default_ctf.yamlindex edbb7fcc..70b05dc1 100644--- a/config/default_ctf.yaml+++ b/config/default_ctf.yaml@@ -29,6 +29,10 @@ system_template: |-If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command.You're free to use any other bash commands you want (e.g. find, grep, cat, ls, cd) in addition to the special commands listed above.However, the environment does NOT support interactive session commands (e.g. python, vim), so please do not invoke them.+challenge_template: |-+ The CTF challenge is a {category_friendly} problem named "{name}", worth {points} points. The description is:+ {description}+ Files included in the challenge: {files}instance_template: |-We're currently solving the following CTF challenge. Here's the CTF description:CTF Challenge:diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 89301b5f..d5e50006 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -223,11 +223,22 @@ class SWEEnv(gym.Env):for hook in self.hooks:hook.on_copy_repo_started(repo_type=self.record["repo_type"], repo_path=self.record["repo"])if self.record["repo_type"] == "local":- copy_anything_to_container(- self.container_obj,- self.record["repo"].removeprefix("local://"),- "/" + self._repo_name,- )+ if "files" in self.record:+ self.communicate_with_handling(input=f"mkdir {self._repo_name}",+ error_msg=f"Failed to create {self._repo_name} in container")+ for file_name in self.record["files"]:+ self.logger.debug(f"Copying file {file_name} to container")+ copy_anything_to_container(+ self.container_obj,+ str(Path(self.record["repo"].removeprefix("local://")) / file_name),+ "/" + self._repo_name+ )+ else:+ copy_anything_to_container(+ self.container_obj,+ self.record["repo"].removeprefix("local://"),+ "/" + self._repo_name,+ )self.communicate_with_handling(input=f"chown -R root:root {self._repo_name}",error_msg="Failed to change permissions on copied repository",diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex b6870757..4009ea7c 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -527,9 +527,21 @@ class InstanceBuilder:)self.args["instance_id"] = f"{owner}__{repo}-i{issue_number}"self.args["problem_statement_source"] = "online"++ def set_problem_statement_from_challenge_json(self, file_path: str) -> str:+ challenge = json.loads(Path(file_path).read_text())+ # TODO: need to proper load the template from the configuration+ self.set_problem_statement_from_text("""+The CTF challenge is a {category_friendly} problem named "{name}", worth {points} points. The description is:+{description}+Files included in the challenge: {files}""".format(name=challenge.get("name"), description=challenge.get("description"), points=challenge.get("points"), files=challenge.get("files"), category_friendly="cryptography"))+ self.args["files"] = challenge["files"]def set_problem_statement_from_file(self, file_path: str):- self.set_problem_statement_from_text(Path(file_path).read_text())+ if Path(file_path).name == "challenge.json":+ self.set_problem_statement_from_challenge_json(file_path)+ else:+ self.set_problem_statement_from_text(Path(file_path).read_text())def set_problem_statement_from_text(self, text: str):self.args["problem_statement"] = text@@ -658,7 +670,7 @@ def get_instances(# The next if statement is very brittle logic to determine if we're processing a single instanceif (file_path.startswith("text://")- or (Path(file_path).is_file() and Path(file_path).suffix in [".md", ".txt"])+ or (Path(file_path).is_file() and (Path(file_path).suffix in [".md", ".txt"] or Path(file_path).name == "challenge.json"))or is_github_issue_url(file_path)):ib = InstanceBuilder(token=token)