Skip to content

Commit

Permalink
lint: simplify hooks already covered by Ruff (#1204)
Browse files Browse the repository at this point in the history
* lint: simplify hooks already covered by Ruff

* prune dev dependency

* setting E, W, F

* poetry?

* autopep8

* quote-style = "single"

* double-quote-string-fixer

* --all-files

* apply

* Q

* drop double-quote-string-fixer

* --all-files

* apply pre-commit

* python3.11 -m poetry lock --no-update

---------

Co-authored-by: Robert Brennan <accounts@rbren.io>
  • Loading branch information
Borda and rbren committed Apr 27, 2024
1 parent 7d5856e commit e32d95c
Show file tree
Hide file tree
Showing 36 changed files with 130 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1 +1 @@
*.ipynb linguist-vendored
*.ipynb linguist-vendored
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Expand Up @@ -35,4 +35,8 @@ jobs:
- name: Install pre-commit
run: pip install pre-commit==3.7.0
- name: Run pre-commit hooks
run: pre-commit run --files opendevin/**/* agenthub/**/* --show-diff-on-failure --config ./dev_config/python/.pre-commit-config.yaml
run: |
pre-commit run \
--all-files \
--show-diff-on-failure \
--config ./dev_config/python/.pre-commit-config.yaml
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -149,7 +149,7 @@ install-precommit-hooks:

lint:
@echo "$(YELLOW)Running linters...$(RESET)"
@poetry run pre-commit run --files opendevin/**/* agenthub/**/* --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH)
@poetry run pre-commit run --all-files --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH)

build-frontend:
@echo "$(YELLOW)Building frontend...$(RESET)"
Expand Down
4 changes: 2 additions & 2 deletions agenthub/SWE_agent/parser.py
Expand Up @@ -20,7 +20,7 @@


def invalid_error(cmd, docs):
return f'''ERROR:
return f"""ERROR:
Invalid command structure for
```
{cmd}
Expand All @@ -30,7 +30,7 @@ def invalid_error(cmd, docs):
Try again using this format:
{COMMAND_USAGE[docs]}
'''
"""


def get_action_from_string(command_string: str, path: str, line: int, thoughts: str = '') -> Action | None:
Expand Down
32 changes: 16 additions & 16 deletions agenthub/SWE_agent/prompts.py
@@ -1,7 +1,7 @@

DEFAULT_COMMANDS_DICT = {
'exit': 'Executed when task is complete',
'read <file_name> [<start_line>] [<end_line>]': 'Shows a given file\'s contents starting from <start_line> up to <end_line>. Default: start_line = 0, end_line = -1. By default the whole file will be read.',
'read <file_name> [<start_line>] [<end_line>]': "Shows a given file's contents starting from <start_line> up to <end_line>. Default: start_line = 0, end_line = -1. By default the whole file will be read.",
'write <file> <changes> [<start_line>] [<end_line>]': 'Modifies a <file> by replacing the current lines between <start_line> and <end_line> with <changes>. Default start_line = 0 and end_line = -1. Calling this with no line args will replace the whole file.',
'browse <url>': 'Returns the text version of any url, this can be useful to look up documentation or finding issues on github',
'scroll_up': 'Takes no arguments. This will scroll up and show you the 100 lines above your current lines',
Expand All @@ -16,7 +16,7 @@

COMMAND_USAGE = {
'exit': 'Usage:\n```\nexit\n```\nExecuted when task is complete',
'read': 'Args:\n<file_name> [<start_line>] [<end_line>]\nUsage:\n```\nread file.py\n```\nor\n```\nread example.py <start_line> <end_line>\n```\nShows a given file\'s contents starting from <start_line> up to <end_line>. Default: start_line = 0, end_line = -1. by default the whole file will be read.',
'read': "Args:\n<file_name> [<start_line>] [<end_line>]\nUsage:\n```\nread file.py\n```\nor\n```\nread example.py <start_line> <end_line>\n```\nShows a given file's contents starting from <start_line> up to <end_line>. Default: start_line = 0, end_line = -1. by default the whole file will be read.",
'write': 'Args:\n<file> <changes> [<start_line>] [<end_line>]\nUsage:\n```\nwrite "def main():\n print("This is line one")" 0 2\n```\nModifies a <file> by replacing the current lines between <start_line> and <end_line> with <changes>. Default start_line = 0 and end_line = -1. Calling this with no line args will replace the whole file.',
'edit': 'Args:\n<start_line> <end_line> <changes>\nUsage:\n```\nedit 0 1 import pandas as pd\n```\nThis will modify the current file you are in with the changes you make between the line numbers you designate',
'goto': 'Args:\n<line_num>\nUsage:\n```\ngoto <line_num>\n```\nThis will show you the 100 lines below and including the line you specify within your current file.',
Expand Down Expand Up @@ -52,7 +52,7 @@
when using write and edit do not surround the code with any "" just write the code.
"""

GENERAL_GUIDELINES = '''INSTRUCTIONS:
GENERAL_GUIDELINES = """INSTRUCTIONS:
Now, you're going to solve this issue on your own. You can use any bash commands or custom commands you wish to complete your task. Edit all the files you need to and run any checks or tests that you want.
Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command.
When you're satisfied with all of the changes you've made, you can indicate that you are done by running the exit command.
Expand All @@ -69,9 +69,9 @@
5. Understand your context: Always make sure to look at the currently open file and the current working directory. The currently open file might be in a different directory than the working directory.
6. Verify your edits: When editing files, it is easy to accidentally specify a wrong line number or to write code with incorrect indentation. Always check the code after you issue an edit to make sure that it reflects what you wanted to accomplish. If it didn't, issue another command to fix it.
7. Thoroughly test your solution: After making any changes to fix a bug, be sure to thoroughly test your solution to ensure the bug has been resolved. Re-run the bug reproduction script and verify that the issue has been addressed.
'''
"""

RESPONSE_FORMAT = '''RESPONSE FORMAT:
RESPONSE_FORMAT = """RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.
Expand Down Expand Up @@ -113,20 +113,20 @@
[ END FORMAT ]
Do not provide anything extra just your thought and action.
'''
"""

SYSTEM_MESSAGE = f'''SYSTEM INFO:
SYSTEM_MESSAGE = f"""SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
You have access to a variety of tools and commands that you can use to help you solve problems efficiently.
{GENERAL_GUIDELINES}
{DOCUMENTATION}
'''.strip()
""".strip()


def NO_ACTION(latest): return f'''
def NO_ACTION(latest): return f"""
You did not include any action to take in your most recent output:
===== Output ======
Expand All @@ -141,20 +141,20 @@ def NO_ACTION(latest): return f'''
{RESPONSE_FORMAT}
It is crucial you use the format provided as the output will be parsed automatically.
'''
"""


def file_info(file: str, line: int):
if file:
return f'''CURRENT WORKSPACE:
return f"""CURRENT WORKSPACE:
Open File: {file} on line {line}
You can use these commands with the current file:
Navigation: `scroll_up`, `scroll_down`, and `goto <line>`
Modification: `edit <start_line> <end_line> <changes>`
'''
"""


def STEP_PROMPT(task, file, line_num): return f'''
def STEP_PROMPT(task, file, line_num): return f"""
{RESPONSE_FORMAT}
You are currently trying to complete this task:
{task}
Expand All @@ -168,7 +168,7 @@ def STEP_PROMPT(task, file, line_num): return f'''
NEVER output multiple commands. ONLY take ONE STEP at a time.
When you have completed your task run the "exit" command.
Begin with your thought about the next step and then come up with an action to perform your thought.
'''.strip()
""".strip()


def unpack_dict(data: dict, restrict: list[str] = []):
Expand All @@ -185,13 +185,13 @@ def unpack_dict(data: dict, restrict: list[str] = []):
return '\n'.join(lines)


def MEMORY_FORMAT(act, obs): return f'''
def MEMORY_FORMAT(act, obs): return f"""
Previous Action:
{unpack_dict(act, ["content"])}
Output from Action:
{unpack_dict(obs)}
'''.strip()
""".strip()


def CONTEXT_PROMPT(memory, window):
Expand Down
4 changes: 2 additions & 2 deletions agenthub/planner_agent/prompt.py
Expand Up @@ -134,12 +134,12 @@ def get_hint(latest_action_id: str) -> str:
""" Returns action type hint based on given action_id """

hints = {
'': 'You haven\'t taken any actions yet. Start by using `ls` to check out what files you\'re working with.',
'': "You haven't taken any actions yet. Start by using `ls` to check out what files you're working with.",
ActionType.RUN: 'You should think about the command you just ran, what output it gave, and how that affects your plan.',
ActionType.READ: 'You should think about the file you just read, what you learned from it, and how that affects your plan.',
ActionType.WRITE: 'You just changed a file. You should think about how it affects your plan.',
ActionType.BROWSE: 'You should think about the page you just visited, and what you learned from it.',
ActionType.THINK: 'Look at your last thought in the history above. What does it suggest? Don\'t think anymore--take action.',
ActionType.THINK: "Look at your last thought in the history above. What does it suggest? Don't think anymore--take action.",
ActionType.RECALL: 'You should think about the information you just recalled, and how it should affect your plan.',
ActionType.ADD_TASK: 'You should think about the next action to take.',
ActionType.MODIFY_TASK: 'You should think about the next action to take.',
Expand Down
13 changes: 0 additions & 13 deletions dev_config/python/.pre-commit-config.yaml
Expand Up @@ -7,19 +7,6 @@ repos:
- id: check-yaml
- id: debug-statements

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ['--select=Q000'] # Q000 is the error code for single quote enforcement
additional_dependencies:
- flake8-quotes

- repo: https://github.com/hhatto/autopep8
rev: v2.1.0
hooks:
- id: autopep8

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
Expand Down
19 changes: 18 additions & 1 deletion dev_config/python/ruff.toml
@@ -1,3 +1,20 @@
exclude = [
"agenthub/monologue_agent/regression/",
]
]

[lint]
select = [
"E",
"W",
"F",
"Q",
]

ignore = [
"E501",
]

flake8-quotes = {inline-quotes = "single"}

[format]
quote-style = "single"
2 changes: 1 addition & 1 deletion docs/architecture/Architecture.md
Expand Up @@ -11,4 +11,4 @@ This Overview is simplified to show the main components and their interactions.

*__Disclaimer__: The backend architecture is a work in progress and is subject to change. The following diagram shows the current architecture of the backend based on the commit that is shown in the footer of the diagram.*

![backend_architecture.svg](backend_architecture.svg)
![backend_architecture.svg](backend_architecture.svg)
7 changes: 3 additions & 4 deletions docs/architecture/README.md
Expand Up @@ -6,18 +6,17 @@ The generation of the backend architecture diagram is partially automated. The d
- [py2puml](https://github.com/lucsorel/py2puml) installed

## Steps
1. Autogenerate the diagram by running the following command from the root of the repository:
1. Autogenerate the diagram by running the following command from the root of the repository:
```py2puml opendevin opendevin > docs/architecture/backend_architecture.puml```

2. Open the generated file in a PlantUML editor, e.g. Visual Studio Code with the PlantUML extension or [PlantText](https://www.planttext.com/)

3. Review the generated PUML and make all necessary adjustments to the diagram (add missing parts, fix mistakes, improve positioning).
3. Review the generated PUML and make all necessary adjustments to the diagram (add missing parts, fix mistakes, improve positioning).
*py2puml creates the diagram based on the type hints in the code, so missing or incorrect type hints may result in an incomplete or incorrect diagram.*

4. Review the diff between the new and the previous diagram and manually check if the changes are correct.
4. Review the diff between the new and the previous diagram and manually check if the changes are correct.
*Make sure not to remove parts that were manually added to the diagram in the past and are still relevant.*

4. Add the commit hash of the commit that was used to generate the diagram to the diagram footer.

5. Export the diagram as PNG and SVG files and replace the existing diagrams in the `docs/architecture` directory. This can be done with (e.g. [PlantText](https://www.planttext.com/))

2 changes: 1 addition & 1 deletion docs/architecture/backend_architecture.puml
Expand Up @@ -219,4 +219,4 @@ opendevin.controller.agent_controller.AgentController -> opendevin.controller.co
opendevin.controller.command_manager.CommandManager -> opendevin.sandbox.sandbox.DockerInteractive

footer Based on f3fda42; Generated by //py2puml//
@enduml
@enduml
2 changes: 1 addition & 1 deletion docs/architecture/backend_architecture.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions docs/architecture/system_architecture.puml
Expand Up @@ -2,13 +2,13 @@


node frontend as frontend{

component App

package components{

component Terminal

component ChatInterface

component BannerSettings
Expand Down Expand Up @@ -37,8 +37,8 @@ node frontend as frontend{

Terminal -[hidden]u-> ChatInterface
ChatInterface -[hidden]u-> BannerSettings



interface "HTTP (:3001)" as HTTP
HTTP - App
Expand All @@ -50,13 +50,13 @@ node backend{
component Server

'defined in server/server.py, port is defined at startup with uvicorn
interface "Client WS\n(:3000/ws)" as client_socket
interface "Client WS\n(:3000/ws)" as client_socket
client_socket - Server


}
node AgentController{
node AgentController{

}
Server -d-> AgentController
}
Expand Down

0 comments on commit e32d95c

Please sign in to comment.