Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Aider-inspired linting functionality #2220

Closed
2 tasks
neubig opened this issue Jun 3, 2024 · 10 comments
Closed
2 tasks

[Feature]: Aider-inspired linting functionality #2220

neubig opened this issue Jun 3, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request medium effort Estimated medium effort
Milestone

Comments

@neubig
Copy link
Contributor

neubig commented Jun 3, 2024

What problem or use case are you trying to solve?

Aider has functionality for linting code in multiple languages that could be helpful for OpenDevin.

Describe the UX of the solution you'd like

It would be good if OpenDevin agents (optionally?) linted the code they generated so that they could create code that passes basic syntax and style checks.

Do you have thoughts on the technical implementation?

Currently OpenDevin supports some rudimentary linting.

In contrast, Aider's linting has a number of good points that OpenDevin does not yet support:

  • Multi-language support with treesitter
  • The conversion of the output into a prompt seems more sophisticated

We may want to take some inspiration from their work, either by importing the library wholesale and replacing our current agentskills implementation with theirs, or more piecemeal.

Additional context

Aider article on swe-bench lite.
Aider super-issue #120

@neubig neubig added the enhancement New feature or request label Jun 3, 2024
@tobitege
Copy link
Collaborator

tobitege commented Jun 5, 2024

Fyi, started working on a PR to make use of Aider's Linter class within agentskills edit_file.
Unit tests already done.

@jeremi
Copy link
Contributor

jeremi commented Jun 5, 2024

What about also supporting pre-commit? That would allow linting to be more customizable and add an abstraction, so this project does not need to support all the linting systems.

@tobitege
Copy link
Collaborator

tobitege commented Jun 5, 2024

What about also supporting pre-commit? That would allow linting to be more customizable and add an abstraction, so this project does not need to support all the linting systems.

Pre-commit already has linting enabled. Here we are talking about linting of LLM-generated code.

@jeremi
Copy link
Contributor

jeremi commented Jun 5, 2024

Yes, the generated code could be linted with pre-commit before it being run.
pre-commit run --files $(git ls-files -m)
In our case, we run many different linters, some specific to our project. The advantage is that they already have all the code to install the needed dependencies for almost all linters out there.

@tobitege
Copy link
Collaborator

tobitege commented Jun 5, 2024

That's an interesting approach for sure. Does it install dependencies by file extention, for example?
Just wondering whether it auto-magically works with .cs or .lua files instead of .py

@jeremi
Copy link
Contributor

jeremi commented Jun 5, 2024

We can make it do it if we configure all the languages. However, by configuring all the languages, I guess the issue is the time it will take to set up the virtual environment with all the linters.
I see different options:

  • Project create their own config, specifying the one they want.
  • Based on the language used in the project we generate the adapted config (for example, just supporting Python & JS if the project just use this).

For example, ours is quite advanced:
https://github.com/OpenSPP/openspp-modules/blob/17.0/.pre-commit-config.yaml

but some can be simpler:
https://github.com/pre-commit/pre-commit/blob/main/.pre-commit-config.yaml

I like that it standardizes the way to run them, and most are already integrated with it:
https://pre-commit.com/hooks.html

@neubig
Copy link
Contributor Author

neubig commented Jun 5, 2024

@jeremi I love this idea! Overall one big philosophy of OpenDevin is that we want to re-use the tools that already exist for software development, and pre-commit is exactly that sort of tool.

jigsawlabs-student pushed a commit to JeffKatzy/OpenDevin that referenced this issue Jun 18, 2024
jigsawlabs-student pushed a commit to JeffKatzy/OpenDevin that referenced this issue Jun 22, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student pushed a commit to JeffKatzy/OpenDevin that referenced this issue Jun 24, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
JeffKatzy referenced this issue in JeffKatzy/OpenDevin Jun 24, 2024
Updated aider linter to:
    * Always return text and line numbers, and pass to agent_skills
    * Moved extract line number to aider library function
    * Changed pylint to stop after first linter detects errors

Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
JeffKatzy referenced this issue in JeffKatzy/OpenDevin Jun 24, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jun 25, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jun 26, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
@JeffKatzy
Copy link
Contributor

I'm working on integrating the aider linter, and with Python code everything works fine. But was also trying to get fixes with non-Python code. For example, with ruby code, the linter detects the error, and creates an ipythoncellobservation indicating there is a syntax error, but the agent does not actually provide the correct fix -- it just repeats the code with poor syntax. Any ideas?

I tried some prompt engineering with the observation, but it doesn't matter.

All of this is good

**IPythonRunCellAction**
THOUGHT: Now, I will write the Ruby code with the syntax error into the file `run.rb`:
CODE:
EDITED_CODE="""def print_hello_world()\n puts 'Hello World'\n"""
edit_file('run.rb', start=1, end=1, content=EDITED_CODE)
21:29:06 - opendevin:INFO: browser_env.py:95 - Browser env started.
21:29:06 - OBSERVATION
**IPythonRunCellObservation**
Now linting file run.rb
[Your proposed edit has introduced new syntax error(s) in the Ruby programming language. Please understand the errors and retry your edit command.]
ERRORS:
/workspace/run.rb:0
[This is how your edit would have looked if applied]
-------------------------------------------------
1|def print_hello_world()
2| puts 'Hello World'
-------------------------------------------------

This code in line 1 has a syntax error: 1|def print_hello_world()
Your changes have NOT been applied. Please fix your edit command and try again.
You either need to 1) Specify the correct start/end line arguments or 2) Correct your edit code.
DO NOT re-run the same failed edit command. Running it again will lead to the same error.

But this is bad. In ruby, the parentheses should be removed. So the updated code should be def print_hello_world. But it just outputs the original code.

**IPythonRunCellAction**
THOUGHT: It seems there was a syntax error in the provided Ruby code. Let me correct the syntax error and update the file `run.rb` with the corrected code:
CODE:
EDITED_CODE="""def print_hello_world()\n puts 'Hello World'\nend"""
edit_file('run.rb', start=1, end=1, content=EDITED_CODE)

In python, with similar level of hints in the observation, it just makes the fix.

Any ideas on how to correct this? Is multi-language support needed?

jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jun 28, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 1, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 2, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 3, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
@tobitege
Copy link
Collaborator

tobitege commented Jul 6, 2024

cc @neubig please also see #2489 which @JeffKatzy has been working on for a while.
Wanted to get your review first before merging. Might need a little work to catch up with the refactors now, but other than that, was good to go.

@mamoodi mamoodi added the medium effort Estimated medium effort label Jul 6, 2024
@neubig neubig added this to the 2024-07 milestone Jul 6, 2024
@neubig neubig assigned JeffKatzy and unassigned JeffKatzy Jul 6, 2024
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 10, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 10, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 10, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 15, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
jigsawlabs-student referenced this issue in JeffKatzy/OpenDevin Jul 15, 2024
Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby
xingyaoww added a commit that referenced this issue Jul 19, 2024
…2489)

* WIP for integrate aider linter, see OpenDevin#2220

Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby

* move to agent_skills, fixes not seeing skills error

* format/lint to new code, fix failing tests, remove unused code from aider linter

* small changes (remove litellm, fix readme typo)

* fix failing sandbox test

* keep, change dumping of metadata

* WIP for integrate aider linter, see OpenDevin#2220

Updated aider linter to:
    * Always return text and line numbers
    * Moved extract line number more consistently
    * Changed pylint to stop after first linter detects errors
Updated agentskills
    * To get back a LintResult object and then use lines and text for error message and related line number
    * Moved code for extracting line number to aider linter
Tests:
* Added additional unit tests for aider to test for
* Return values from lint failures
* Confirm linter works for non-configured languages like Ruby

* move to agent_skills, fixes not seeing skills error

* format/lint to new code, fix failing tests, remove unused code from aider linter

* remove duplication of tree-sitter, grep-ast and update poetry.lock

* revert to main branch poetry.lock version

* only update necessary package

* fix jupyter kernel wrong interpreter issue (only for swebench)

* fix failing lint tests

* update syntax error checks for flake

* update poetry lock file

* update poetry.lock file, which update content-hash

* add grep ast

* remove extra stuff caused by merge

* update pyproject

* remove extra pytest fixture, ruff styling fixes

* lint files

* update poetry.lock file

---------

Co-authored-by: Jeff Katzy <jeffreyerickatz@gmail.com>
Co-authored-by: yufansong <yufan@risingwave-labs.com>
Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
Co-authored-by: tobitege <tobitege@gmx.de>
@neubig
Copy link
Contributor Author

neubig commented Jul 25, 2024

Fixed by #2489 !

@neubig neubig closed this as completed Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium effort Estimated medium effort
Projects
None yet
Development

No branches or pull requests

5 participants