Commit graph

1071 commits

Author SHA1 Message Date
Paul Gauthier
9c28bbc98e Refactored linting process and error handling in commands. 2024-05-20 08:55:49 -07:00
Paul Gauthier
e758b01fb6 Merge branch 'main' into swe-bench 2024-05-19 15:20:46 -07:00
Paul Gauthier
04539feccb bump deps to get grep-ast 0.3.1 2024-05-19 15:10:57 -07:00
Paul Gauthier
5745657991 ask to fix lint/test 2024-05-19 15:02:16 -07:00
Paul Gauthier
038806f694 max_reflex=3, auto fix lint/test 2024-05-19 14:24:06 -07:00
Paul Gauthier
642be2a8f0 S/R uniq prompt 2024-05-19 14:22:29 -07:00
Paul Gauthier
5641483a3b S/R will replace all matches 2024-05-19 10:31:36 -07:00
Paul Gauthier
ec7af731e0 confirm auto lint and test 2024-05-19 10:26:06 -07:00
Paul Gauthier
cb6e7cabb6 Added lint/test_outcome 2024-05-19 08:13:20 -07:00
Paul Gauthier
0b18f3b4ef Add check to skip setting up lint commands if none are provided. 2024-05-19 07:42:39 -07:00
Paul Gauthier
25e44f584b aider: Fixed extra blank lines and added missing whitespace after a comma.
# Aider chat conversation:

USER: # Fix any errors below, if possible.

## Running: flake8 aider/coders/base_coder.py

aider/coders/base_coder.py:43:1: E303 too many blank lines (3)
aider/coders/base_coder.py:334:17: E231 missing whitespace after ','

## See relevant lines below marked with █.

aider/coders/base_coder.py:
...⋮...
 40│
 41│
 42│
 43█def wrap_fence(name):
 44│    return f"<{name}>", f"</{name}>"
 45│
 46│
 47│class Coder:
 48│    abs_fnames = None
...⋮...
331│                self.io.tool_output(json.dumps(self.functions, indent=4))
332│
333│    def setup_lint_cmds(self, lint_cmds):
334█        for lang,cmd in lint_cmds.items():
335│            self.linter.set_linter(lang, cmd)
336│
337│    def show_announcements(self):
...⋮...

ASSISTANT: Here are the necessary changes to fix the flake8 errors:

1. Remove the extra blank lines before the `wrap_fence` function.
2. Add a missing whitespace after the comma in the `setup_lint_cmds` function.

aider/coders/base_coder.py
```python
<<<<<<< SEARCH
class ExhaustedContextWindow(Exception):
    pass

def wrap_fence(name):
=======
class ExhaustedContextWindow(Exception):
    pass

def wrap_fence(name):
>>>>>>> REPLACE
```

aider/coders/base_coder.py
```python
<<<<<<< SEARCH
        for lang,cmd in lint_cmds.items():
=======
        for lang, cmd in lint_cmds.items():
>>>>>>> REPLACE
```
2024-05-19 07:40:48 -07:00
Paul Gauthier
9bd78d7ff3 Refactored lint command parsing and setup logic. 2024-05-19 07:40:41 -07:00
Paul Gauthier
990dda1122 Added empty lines for better readability. 2024-05-19 07:35:27 -07:00
Paul Gauthier
9ee332f5d9 Added options for automatic linting and testing after changes. 2024-05-19 07:34:19 -07:00
Paul Gauthier
6fac50a3a1 aider: Fix undefined name 'Path' errors by importing the Path class from the pathlib module.
# Aider chat conversation:

USER: # Fix any errors below

## Running: flake8 --select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source aider/coders/wholefile_coder.py

aider/coders/wholefile_coder.py:73:62: F821 undefined name 'Path'
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                                                             ^
aider/coders/wholefile_coder.py:74:33: F821 undefined name 'Path'
                        fname = Path(fname).name
                                ^
aider/coders/wholefile_coder.py:103:30: F821 undefined name 'Path'
                full_path = (Path(self.root) / fname).absolute()
                             ^
aider/coders/wholefile_coder.py:133:12: F821 undefined name 'Path'
        if Path(full_path).exists():
           ^

## See relevant lines below marked with █.

aider/coders/wholefile_coder.py:
...⋮...
  2│from aider import diffs
  3│
...⋮...
  9│class WholeFileCoder(Coder):
 10│    edit_format = "whole"
 11│
...⋮...
 30│    def get_edits(self, mode="update"):
 31│        content = self.partial_response_content
 32│
...⋮...
 44│        for i, line in enumerate(lines):
 45│            if line.startswith(self.fence[0]) or line.startswith(self.fence[1]):
 46│                if fname is not None:
 47│                    # ending an existing block
 48│                    saw_fname = None
 49│
 50│                    full_path = self.abs_root_path(fname)
 51│
 52│                    if mode == "diff":
 53│                        output += self.do_live_diff(full_path, new_lines, True)
 54│                    else:
 55│                        edits.append((fname, fname_source, new_lines))
 56│
...⋮...
 63│                if i > 0:
 64│                    fname_source = "block"
...⋮...
 70│                    # Did gpt prepend a bogus dir? It especially likes to
 71│                    # include the path/to prefix from the one-shot example in
 72│                    # the prompt.
 73█                    if fname and fname not in chat_files and Path(fname).name in chat_files:
 74█                        fname = Path(fname).name
 75│                if not fname:  # blank line? or ``` was on first line i==0
 76│                    if saw_fname:
 77│                        fname = saw_fname
...⋮...
100│        if mode == "diff":
101│            if fname is not None:
102│                # ending an existing block
103█                full_path = (Path(self.root) / fname).absolute()
104│                output += self.do_live_diff(full_path, new_lines, False)
105│            return "\n".join(output)
106│
...⋮...
130│            self.io.write_text(full_path, new_lines)
131│
132│    def do_live_diff(self, full_path, new_lines, final):
133█        if Path(full_path).exists():
134│            orig_lines = self.io.read_text(full_path).splitlines(keepends=True)
135│
136│            show_diff = diffs.diff_partial_update(
137│                orig_lines,
138│                new_lines,
139│                final=final,
140│            ).splitlines()
141│            output = show_diff
142│        else:
...⋮...

ASSISTANT: To fix the errors, we need to import the `Path` class from the `pathlib` module. Here are the necessary changes:

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
from aider import diffs
=======
from aider import diffs
from pathlib import Path
>>>>>>> REPLACE
</source>

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                        fname = Path(fname).name
=======
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                        fname = Path(fname).name
>>>>>>> REPLACE
</source>

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
                full_path = (Path(self.root) / fname).absolute()
=======
                full_path = (Path(self.root) / fname).absolute()
>>>>>>> REPLACE
</source>

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
        if Path(full_path).exists():
=======
        if Path(full_path).exists():
>>>>>>> REPLACE
</source>
2024-05-18 20:49:17 -07:00
Paul Gauthier
a50f01a004 Removed unnecessary import of Path from pathlib. 2024-05-18 20:49:10 -07:00
Paul Gauthier
8a2ce8ec0e aider: Import 'Path' from 'pathlib' to fix undefined name errors.
# Aider chat conversation:

USER: # Running: /Users/gauthier/Projects/aider/tmp.sh aider/coders/wholefile_coder.py

aider/coders/wholefile_coder.py
aider/coders/wholefile_coder.py:72:62: F821 undefined name 'Path'
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                                                             ^
aider/coders/wholefile_coder.py:73:33: F821 undefined name 'Path'
                        fname = Path(fname).name
                                ^
aider/coders/wholefile_coder.py:102:30: F821 undefined name 'Path'
                full_path = (Path(self.root) / fname).absolute()
                             ^
aider/coders/wholefile_coder.py:132:12: F821 undefined name 'Path'
        if Path(full_path).exists():
           ^

ASSISTANT: To fix the `undefined name 'Path'` errors, we need to import `Path` from the `pathlib` module at the beginning of the file. Here are the necessary changes:

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
from aider import diffs
=======
from pathlib import Path
from aider import diffs
>>>>>>> REPLACE
</source>
2024-05-18 19:18:43 -07:00
Paul Gauthier
5805007885 Removed unused import statement from wholefile_coder.py. 2024-05-18 19:18:38 -07:00
Paul Gauthier
4bbeb9de6f aider: Import 'Path' from 'pathlib' to fix undefined name errors.
# Aider chat conversation:

USER: # Running: /Users/gauthier/Projects/aider/tmp.sh aider/coders/wholefile_coder.py

aider/coders/wholefile_coder.py
aider/coders/wholefile_coder.py:72:62: F821 undefined name 'Path'
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                                                             ^
aider/coders/wholefile_coder.py:73:33: F821 undefined name 'Path'
                        fname = Path(fname).name
                                ^
aider/coders/wholefile_coder.py:102:30: F821 undefined name 'Path'
                full_path = (Path(self.root) / fname).absolute()
                             ^
aider/coders/wholefile_coder.py:132:12: F821 undefined name 'Path'
        if Path(full_path).exists():
           ^

ASSISTANT: To fix the `undefined name 'Path'` errors, we need to import `Path` from the `pathlib` module at the beginning of the file. Here are the necessary changes:

aider/coders/wholefile_coder.py
<source>python
<<<<<<< SEARCH
from aider import diffs
=======
from pathlib import Path
from aider import diffs
>>>>>>> REPLACE
</source>
2024-05-18 19:16:25 -07:00
Paul Gauthier
1d519cdf1e Removed unused import from wholefile_coder.py. 2024-05-18 19:16:24 -07:00
Paul Gauthier
b26969ea90 Refactored linting to use absolute file path. 2024-05-17 19:22:17 -07:00
Paul Gauthier
0412b19f6b aider: Fix flake8 errors by removing unnecessary f-string prefixes in aider/coders/base_coder.py.
# Aider chat conversation:

USER: I ran this command:

 pre-commit run --files aider/coders/base_coder.py

And got this output:

isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

aider/coders/base_coder.py:1135:32: F541 f-string is missing placeholders
            self.io.tool_error(f"The LLM did not conform to the edit format.")
                               ^
aider/coders/base_coder.py:1148:32: F541 f-string is missing placeholders
            self.io.tool_error(f"Exception while updating files:")
                               ^

ASSISTANT: Please add `aider/coders/base_coder.py` to the chat so I can propose the necessary changes to fix the flake8 errors.

USER: I added these *read-write* files: aider/coders/base_coder.py

ASSISTANT: Here are the changes to fix the flake8 errors related to the f-strings missing placeholders in `aider/coders/base_coder.py`:

```diff
--- aider/coders/base_coder.py
+++ aider/coders/base_coder.py
@@ ... @@
-            self.io.tool_error(f"The LLM did not conform to the edit format.")
+            self.io.tool_error("The LLM did not conform to the edit format.")
@@ ... @@
-            self.io.tool_error(f"Exception while updating files:")
+            self.io.tool_error("Exception while updating files:")
```

These changes remove the unnecessary f-string prefixes since there are no variables or expressions to be evaluated inside the strings.
2024-05-17 19:11:49 -07:00
Paul Gauthier
8f194c8313 Add reflection tracking and limit to Coder class. 2024-05-17 19:11:48 -07:00
Paul Gauthier
4b0c38254e added lint reflection 2024-05-17 16:58:04 -07:00
Paul Gauthier
819fccc7a4 added temp param, prompt strong that files message is truth 2024-05-16 08:52:30 -07:00
Paul Gauthier
ecc46bd3e3 16x 2024-05-14 14:04:45 -07:00
Paul Gauthier
73e6949287 refac 2024-05-14 11:12:36 -07:00
Paul Gauthier
6638efbee4 better prompting for LLM to suggest files 2024-05-14 06:02:16 -07:00
Paul Gauthier
292250db4f prompt and token adjustments when no files in chat with repo 2024-05-13 12:30:42 -07:00
Paul Gauthier
edc70bdf84 Handle multiline tool_error() better 2024-05-13 11:42:22 -07:00
Paul Gauthier
ea05cf05e1 Added --restore-chat-history 2024-05-13 11:09:28 -07:00
Paul Gauthier
eea8e50c60 ask llm are you sure? when REPLACE exists 2024-05-11 16:56:14 -07:00
Paul Gauthier
90c0a5b9a4 reflect multiple messages; do not strip edit error messages 2024-05-11 16:40:37 -07:00
Paul Gauthier
0f9e314bb2 emit edit errors as proper tool_error() markdown 2024-05-11 15:38:03 -07:00
Paul Gauthier
cd78080fa5 on search/replace error ask the LLM did you mean? 2024-05-11 15:02:22 -07:00
Paul Gauthier
6c45b58698 aider: Implemented find_similar_lines to fuzzy search content and return closest matching contiguous chunk of lines.
# Aider chat conversation:

USER: implement `find_similar_lines` which will fuzzy search the content for the original lines and return the contiguous chunk of lines from content which are the closest match

ASSISTANT: Here is the implementation of `find_similar_lines` to fuzzy search the content and return the closest matching contiguous chunk of lines:

aider/coders/editblock_coder.py
<source>python
<<<<<<< SEARCH
    #did_you_mean = find_similar_lines(original, content)
=======
    did_you_mean = find_similar_lines(original, content)
>>>>>>> REPLACE
</source>

aider/coders/editblock_coder.py
<source>python
<<<<<<< SEARCH
=======
def find_similar_lines(search_lines, content_lines, threshold=0.8):
    search_lines = search_lines.splitlines()
    content_lines = content_lines.splitlines()

    best_ratio = 0
    best_match = None

    for i in range(len(content_lines) - len(search_lines) + 1):
        chunk = content_lines[i:i+len(search_lines)]
        ratio = SequenceMatcher(None, search_lines, chunk).ratio()
        if ratio > best_ratio:
            best_ratio = ratio
            best_match = chunk

    if best_ratio >= threshold:
        return "\n".join(best_match)
    else:
        return ""
>>>>>>> REPLACE
</source>

This adds the `find_similar_lines` function which:

1. Splits the search lines and content lines on newlines
2. Iterates through the content lines, considering each contiguous chunk the same length as the search lines
3. Calculates the SequenceMatcher ratio between the search lines and each chunk
4. Keeps track of the chunk with the highest ratio
5. If the best ratio is above the threshold (default 0.8), it returns the best matching chunk joined back into a string
6. Otherwise it returns an empty string to indicate no close enough match was found

It also uncomments the line to call `find_similar_lines` and store the result in `did_you_mean`.

Let me know if you have any other questions!
2024-05-11 10:49:34 -07:00
Paul Gauthier
056dae6530 Removed unused find_similar_lines function call from EditBlockCoder class. 2024-05-11 10:49:33 -07:00
Paul Gauthier
fd6f31f972 Replaced find_similar_text with find_similar_lines in editblock_coder.py. 2024-05-11 10:48:45 -07:00
Paul Gauthier
d02506db16 aider: Implemented find_similar_text function to fuzzy search the content for the closest match to the original text.
# Aider chat conversation:

USER: I did `git reset --hard HEAD~1` to discard the last edits. Please wait for further instructions before attempting that change again. Feel free to ask relevant questions about why the changes were reverted.

ASSISTANT: I understand you reverted the previous changes. Before I attempt to implement the `find_similar_lines` function again, I have a few questions to ensure I follow your guidelines correctly:

1. When proposing changes, should I only modify the `aider/coders/editblock_coder.py` file since that is the only one you have explicitly added to the chat
^C KeyboardInterrupt

USER: implement `find_similar_text` which will fuzzy search the content for the original text and return the part of content which is the closest match

ASSISTANT: Here is the implementation of `find_similar_text` to fuzzy search the content for the closest match to the original text:

aider/coders/editblock_coder.py
<source>python
<<<<<<< SEARCH
=======
from difflib import SequenceMatcher

def find_similar_text(original, content):
    content_len = len(content)
    original_len = len(original)

    best_ratio = 0
    best_match = None

    for i in range(content_len - original_len + 1):
        chunk = content[i:i+original_len]
        ratio = SequenceMatcher(None, original, chunk).ratio()

        if ratio > best_ratio:
            best_ratio = ratio
            best_match = chunk

    return best_match
>>>>>>> REPLACE
</source>

This function:

1. Iterates through the content, considering each chunk of text the same length as the original
2. Calculates the SequenceMatcher ratio between the original text and each chunk
3. Keeps track of the chunk with the highest ratio
4. Returns the chunk of content that best matches the original text

It will return the portion of `content` that is the closest fuzzy match to `original`.

Let me know if you have any other questions!
2024-05-11 10:43:40 -07:00
Paul Gauthier
6d39e2c857 Replaced find_similar_lines with find_similar_text in the EditBlockCoder class. 2024-05-11 10:43:38 -07:00
Paul Gauthier
587ba4d676 Added functionality to suggest similar lines when a search block fails to match in EditBlockCoder. 2024-05-11 10:38:44 -07:00
Paul Gauthier
785259b59c try patching any of the other files in the chat 2024-05-11 10:33:46 -07:00
Paul Gauthier
5ec441dd2c More clear feedback when SEARCH/REPLACE blocks fail to match 2024-05-11 10:25:16 -07:00
Paul Gauthier
602a0c7c31 refac utils.split_chat_history_markdown 2024-05-11 07:52:06 -07:00
paul-gauthier
45b2ba8a10
Merge pull request #591 from paul-gauthier/restore-chat-history
Restore prior chat history on launch
2024-05-11 07:49:43 -07:00
Paul Gauthier
1098b428e6 prompt tweaks, retry on httpx.ReadTimeout 2024-05-11 07:47:53 -07:00
Paul Gauthier
3171789b1f look for mentions with trailing : 2024-05-10 19:38:05 -07:00
Paul Gauthier
a5bc2e8b97 Added prompt to reply in the users language #597 2024-05-09 14:06:31 -07:00
Paul Gauthier
4eec60f42c updated assistant auto-reply to no files 2024-05-09 11:56:11 -07:00
Paul Gauthier
444d17de93 reverted prompt closer to e9da401, added helpful assistant replies to repo and files messages 2024-05-09 11:27:13 -07:00