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]
lint: use `typos` as precommit's hook (#259)
Jirka Borovec230effc3f1fd
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex ca6a5daa..c6d5d844 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -13,6 +13,15 @@ repos:- id: detect-private-key- id: check-ast+ - repo: https://github.com/crate-ci/typos+ rev: v1.20.7+ hooks:+ - id: typos+ files: \.(py|md|rst|yaml|toml)+ # empty to do not write fixes+ args: []+ exclude: pyproject.toml+- repo: https://github.com/astral-sh/ruff-pre-commitrev: v0.4.3hooks:diff --git a/config/commands/README.md b/config/commands/README.mdindex 132b1074..945ca35f 100644--- a/config/commands/README.md+++ b/config/commands/README.md@@ -23,7 +23,7 @@ Every command subscribes to the following skeleton code.* If there are no arguments, omit the `arguments` section.* The implementation for your command is unconstrained. There are no limitations on the form of the underlying command code.* The minimal documentation requirements are `signature` and `docstring`.-* If you'd like multiple commands to make modifications to a similar body of functions, we recommend using global varibles.+* If you'd like multiple commands to make modifications to a similar body of functions, we recommend using global variables.* For instance, in `config/commands/default.sh`, you'll see we define the `CURRENT_LINE` variable for the file viewer. This variable is modified across multiple commands, including `open`, `goto`, `scroll_up`, `scroll_down`, and `edit`.* You can also leverage third party libraries (check out how we do linting enabled `edit` in `config/commands/edit_linting.sh`).* To show effects of the command, print to standard output (i.e. `echo`). SWE-agent is implemented such that it does not look for a return value from these commands.diff --git a/inspector/server.py b/inspector/server.pyindex 0b0c8027..18d5a7b6 100644--- a/inspector/server.py+++ b/inspector/server.py@@ -139,7 +139,7 @@ def load_content(file_name, gold_patches, test_patches):with open(scorecards_file) as infile:scorecards = json.load(infile)- content = append_exit(content) # accomodate new and old format+ content = append_exit(content) # accommodate new and old formatcontent = append_patch(Path(file_name).stem, content, gold_patches, "Gold")content = append_patch(Path(file_name).stem, content, test_patches, "Test")content = append_results(diff --git a/make_demos/convert_traj_to_demo.py b/make_demos/convert_traj_to_demo.pyindex c171910c..286cdf2f 100644--- a/make_demos/convert_traj_to_demo.py+++ b/make_demos/convert_traj_to_demo.py@@ -58,9 +58,9 @@ def convert_traj_to_action_demo(traj_path: str, output_file: str = None, includetraj = json.load(open(traj_path))history = traj["history"]action_traj = list()- admissable_roles = {"assistant", "user"} if include_user else {"assistant"}+ admissible_roles = {"assistant", "user"} if include_user else {"assistant"}for step in history:- if step['role'] in admissable_roles and step.get('agent', 'primary') == 'primary':+ if step['role'] in admissible_roles and step.get('agent', 'primary') == 'primary':action_traj.append({k: v for k, v in step.items() if k in {'content', 'role'}})save_demo(action_traj, output_file, traj_path)print(f"Saved demo to {output_file}")diff --git a/pyproject.toml b/pyproject.tomlindex ac07a134..5aeaba1f 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -127,3 +127,11 @@ skip-magic-trailing-comma = false# Like Black, automatically detect the appropriate line ending.line-ending = "auto"++[tool.typos.default.extend-identifiers]+# *sigh* this just isn't worth the cost of fixing+ACI = "ACI"++[tool.typos.default.extend-words]+# Don't correct the surname "Teh"+aci = "aci"diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex e62fc062..9708f7f1 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -353,12 +353,12 @@ def get_container(ctr_name: str, image_name: str, persistent: bool = False) -> Ttry:client = docker.from_env()except docker.errors.DockerException as e:- docker_not_runnnig = any((+ docker_not_running = any(("connection aborted" in str(e).lower(),"connection refused" in str(e).lower(),"error while fetching server api version" in str(e).lower(),))- if docker_not_runnnig:+ if docker_not_running:msg = ("Probably the Docker daemon is not running. Please start the Docker daemon and try again. ""You might need to allow the use of the docker socket "diff --git a/tests/test_data/trajectories/gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml b/tests/test_data/trajectories/gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yamlindex 2a793f0b..ab65af14 100644--- a/tests/test_data/trajectories/gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml+++ b/tests/test_data/trajectories/gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml@@ -234,7 +234,7 @@ agent:"File updated. Please review the changes and make sure they are correct (correctindentation, no duplicate lines, etc). Edit the file again if necessary." else echo"Your proposed edit has introduced new syntax error(s). Please understand- the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string+ the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #Update values export CURRENT_LINE=$(( (line_count / 2) + start_line)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show@@ -406,7 +406,7 @@ agent:\ environment, and run it to make sure you can reproduce the bug.\n Then start\\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\\ reproduction script to make sure that the bug has indeed been fixed.\n \n\- \ If the bug reproduction script does not print anything when it succesfully\+ \ If the bug reproduction script does not print anything when it successfully\\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\) command at the end of the file,\n so that you can be sure that the script\\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\diff --git a/tests/test_data/trajectories/gpt4__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml b/tests/test_data/trajectories/gpt4__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yamlindex 8183a596..f80221e0 100644--- a/tests/test_data/trajectories/gpt4__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml+++ b/tests/test_data/trajectories/gpt4__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml@@ -235,7 +235,7 @@ agent:"File updated. Please review the changes and make sure they are correct (correctindentation, no duplicate lines, etc). Edit the file again if necessary." else echo"Your proposed edit has introduced new syntax error(s). Please understand- the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string+ the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #Update values export CURRENT_LINE=$(( (line_count / 2) + start_line)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show@@ -407,7 +407,7 @@ agent:\ environment, and run it to make sure you can reproduce the bug.\n Then start\\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\\ reproduction script to make sure that the bug has indeed been fixed.\n \n\- \ If the bug reproduction script does not print anything when it succesfully\+ \ If the bug reproduction script does not print anything when it successfully\\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\) command at the end of the file,\n so that you can be sure that the script\\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\diff --git a/tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yaml b/tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yamlindex b61f5313..6362216f 100644--- a/tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yaml+++ b/tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yaml@@ -235,7 +235,7 @@ agent:"File updated. Please review the changes and make sure they are correct (correctindentation, no duplicate lines, etc). Edit the file again if necessary." else echo"Your proposed edit has introduced new syntax error(s). Please understand- the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string+ the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #Update values export CURRENT_LINE=$(( (line_count / 2) + start_line)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show@@ -407,7 +407,7 @@ agent:\ environment, and run it to make sure you can reproduce the bug.\n Then start\\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\\ reproduction script to make sure that the bug has indeed been fixed.\n \n\- \ If the bug reproduction script does not print anything when it succesfully\+ \ If the bug reproduction script does not print anything when it successfully\\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\) command at the end of the file,\n so that you can be sure that the script\\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\diff --git a/tests/test_models.py b/tests/test_models.pyindex c706c94c..887da3cf 100644--- a/tests/test_models.py+++ b/tests/test_models.py@@ -6,13 +6,13 @@ import pytest@pytest.fixturedef openai_mock_client():model = Mock()- reponse = Mock()+ response = Mock()choice = Mock()choice.message.content = "test"- reponse.choices = [choice]- reponse.usage.prompt_tokens = 10- reponse.usage.completion_tokens = 10- model.chat.completions.create = MagicMock(return_value=reponse)+ response.choices = [choice]+ response.usage.prompt_tokens = 10+ response.usage.completion_tokens = 10+ model.chat.completions.create = MagicMock(return_value=response)return modeldiff --git a/tests/test_replay.py b/tests/test_replay.pyindex c6ed3fb6..4db58088 100644--- a/tests/test_replay.py+++ b/tests/test_replay.py@@ -102,8 +102,8 @@ def test_model_replay_local_repo(swe_agent_test_repo_clone, swe_agent_test_repo_"--raise_exceptions",]print(run_cmd)- args, remaing_args = get_args(run_cmd)- main(**vars(args), forward_args=remaing_args)+ args, remaining_args = get_args(run_cmd)+ main(**vars(args), forward_args=remaining_args)solution = (swe_agent_test_repo_traj.parent / "solution_missing_colon.py").read_text().strip()solution_retrieved = (local_repo_path / "tests" / "missing_colon.py").read_text().strip()assert solution == solution_retrieved@@ -127,6 +127,6 @@ def test_exception_replay_local_dirty(swe_agent_test_repo_clone, swe_agent_test_"--apply_patch","--raise_exceptions",]- args, remaing_args = get_args(run_cmd)+ args, remaining_args = get_args(run_cmd)with pytest.raises(ValueError, match=".*dirty.*"):- main(**vars(args), forward_args=remaing_args)\ No newline at end of file+ main(**vars(args), forward_args=remaining_args)\ No newline at end of file