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]
changes problem statement to match CTF problem setting
Talor Abramovich0104aa63d7c4
diff --git a/config/default_ctf.yaml b/config/default_ctf.yamlindex 70b05dc1..34c2117e 100644--- a/config/default_ctf.yaml+++ b/config/default_ctf.yaml@@ -29,14 +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:+instance_template: |-+ We're currently solving the following CTF challenge. 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:- {issue}INSTRUCTIONS:Now, you're going to solve this challenge on your own. Your terminal session has started and you're in the challenge's root directory. You can use any bash commands or the special interface to help you.diff --git a/run.py b/run.pyindex df2c05cb..a07101be 100644--- a/run.py+++ b/run.py@@ -360,8 +360,18 @@ class Main:tests = ""if "FAIL_endTO_PASS" in self.env.record:tests = "\n".join([f"- {x}" for x in self.env.record["FAIL_TO_PASS"]])-- setup_args = {"issue": issue, "files": files, "test_files": test_files, "tests": tests}++ challenge = getattr(self.env, "challenge", None)+ if challenge is not None:+ name = challenge["name"]+ description = challenge["description"]+ category_friendly = challenge["category_friendly"]+ points = challenge["points"]+ files = challenge["files"]++ setup_args = {"issue": issue, "files": files, "test_files": test_files, "tests": tests,+ "name": name, "description": description, "category_friendly": category_friendly,+ "points": points}info, trajectory = self.agent.run(setup_args=setup_args,env=self.env,diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex d5e50006..30426771 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -312,6 +312,7 @@ class SWEEnv(gym.Env):# Set query, gold commandself.base_commit = self.record["base_commit"]self.query = self.record["problem_statement"]+ self.challenge = self.record.get("challenge")self.reward = None### Reset Container ###diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex 4009ea7c..a4e3db71 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -29,6 +29,15 @@ DOCKER_START_UP_DELAY = float(keys_config.get("SWE_AGENT_DOCKER_START_UP_DELAY",GITHUB_ISSUE_URL_PATTERN = re.compile(r"github\.com\/(.*?)\/(.*?)\/issues\/(\d+)")GITHUB_REPO_URL_PATTERN = re.compile(r".*[/@]?github\.com\/([^/]+)\/([^/]+)")+CTF_CHALLENGES_CATEGORIES = {+ "rev": "reverse engineering",+ "pwn": "binary exploitation",+ "web": "web security",+ "crypto": "cryptography",+ "misc": "miscellaneous",+ "forensics": "forensics",+}+logger = get_logger("env_utils")@@ -530,12 +539,13 @@ class InstanceBuilder: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"]+ self.args["challenge"] = dict()+ self.args["challenge"]["files"] = challenge.get("files", "No files are provided in this challenge.")+ self.args["challenge"]["name"] = challenge["name"]+ self.args["challenge"]["description"] = challenge["description"]+ self.args["challenge"]["points"] = challenge.get("points", 10)+ self.args["challenge"]["category_friendly"] = CTF_CHALLENGES_CATEGORIES.get(challenge["category"])+ self.set_problem_statement_from_text(f"{challenge['name']} {challenge['description']}")def set_problem_statement_from_file(self, file_path: str):if Path(file_path).name == "challenge.json":