Commit graph

441 commits

Author SHA1 Message Date
Paul Gauthier
fe0f8928a2 honor the user provided /commit message 2023-05-11 09:37:20 -07:00
Paul Gauthier
db2e062634 wip: Added methods to get context from history and commit message. 2023-05-11 09:36:34 -07:00
Paul Gauthier
adbdbbcb74 Added import of dump function from aider.dump module to cmd_commit function in commands.py. 2023-05-11 09:30:17 -07:00
Paul Gauthier
c9ff2ed7e9 Added a dump statement to cmd_commit function. 2023-05-11 09:29:51 -07:00
Paul Gauthier
1f4a54cf01 Fixed a bug where the commit command was not being executed when the repo was dirty. 2023-05-11 09:29:11 -07:00
Paul Gauthier
34fac7b4b9 Fixed a bug where the commit command was being triggered when the repo was dirty. 2023-05-11 09:28:36 -07:00
Paul Gauthier
0434f71c9f wip: Refactor console message for uncommitted changes in coder.py. 2023-05-11 09:26:55 -07:00
Paul Gauthier
23a0339a15 Removed dump function call from coder.py. 2023-05-11 09:25:09 -07:00
Paul Gauthier
4d263eda10 Removed get_last_modified method and replaced last_modified check with repo.is_dirty. 2023-05-11 09:24:32 -07:00
Paul Gauthier
14b45f40f6 finishing support for which=repo_files 2023-05-11 09:22:51 -07:00
Paul Gauthier
6e68562cd0 fixed reference to repo var 2023-05-11 09:15:12 -07:00
Paul Gauthier
cee1dfd3b9 aider: Added an elif clause for which == "chat_files" and a final else clause to raise a ValueError if the value of which is not valid.
# Context:
USER: nice! in the change the else: to elseif which==chat_files and throw a valueerror as a final else clause
ASSISTANT: To update the `commit()` function with the requested changes, we will modify the `if` statement to include an `elif` clause for `which == "chat_files"` and add a final `else` clause to raise a `ValueError`.

```python
aider/coder.py
<<<<<<< ORIGINAL
        if which == "repo_files":
            all_files = [os.path.join(self.root, f) for f in self.get_all_relative_files()]
            dirty_fnames, relative_dirty_fnames = get_dirty_files(all_files)
        else:
            dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
=======
        if which == "repo_files":
            all_files = [os.path.join(self.root, f) for f in self.get_all_relative_files()]
            dirty_fnames, relative_dirty_fnames = get_dirty_files(all_files)
        elif which == "chat_files":
            dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
        else:
            raise ValueError(f"Invalid value for 'which': {which}")
>>>>>>> UPDATED
```

This change adds an `elif` clause for `which == "chat_files"` and a final `else` clause to raise a `ValueError` if the value of `which` is not valid.
2023-05-11 09:13:25 -07:00
Paul Gauthier
da40aaa6ca aider: Updated commit() to handle which="repo_files", committing all pending changes to all the files in the repo.
# Context:
USER: update commit() to handle which="repo_files". in that case, it should commit all pending changes to all the files in the repo, not just the chat files in self.abs_fnames
ASSISTANT: To update the `commit()` function to handle `which="repo_files"`, we will modify the function to commit all pending changes to all the files in the repo when `which` is set to `"repo_files"`.

```python
aider/coder.py
<<<<<<< ORIGINAL
    def commit(self, history=None, prefix=None, ask=False, message=None, which="chat_files"):
=======
    def commit(self, history=None, prefix=None, ask=False, message=None, which="chat_files"):
        def get_dirty_files(file_list):
            dirty_files = []
            relative_dirty_files = []
            for fname in file_list:
                relative_fname = os.path.relpath(fname, repo.working_tree_dir)
                if self.pretty:
                    these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
                else:
                    these_diffs = repo.git.diff("HEAD", relative_fname)

                if these_diffs:
                    dirty_files.append(fname)
                    relative_dirty_files.append(relative_fname)

            return dirty_files, relative_dirty_files

        if which == "repo_files":
            all_files = [os.path.join(self.root, f) for f in self.get_all_relative_files()]
            dirty_fnames, relative_dirty_fnames = get_dirty_files(all_files)
        else:
            dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
>>>>>>> UPDATED
```

This change adds a new function `get_dirty_files()` inside the `commit()` function to get the dirty files and their relative paths based on the provided file list. Then, we check the value of `which` and set the `dirty_fnames` and `relative_dirty_fnames` accordingly. If `which` is `"repo_files"`, we use all the files in the repo; otherwise, we use the chat files in `self.abs_fnames`.
2023-05-11 09:11:48 -07:00
Paul Gauthier
f5bfd41ecd updated readme 2023-05-11 06:20:29 -07:00
Paul Gauthier
05cbb79069 fixed merge conflict 2023-05-11 06:17:53 -07:00
Paul Gauthier
0a7c5d1a78 wip: Removed unnecessary lines of code in coder.py. 2023-05-11 06:03:11 -07:00
Paul Gauthier
e875d0ca7f Refactor loop to use class attribute instead of parameter. 2023-05-11 06:02:21 -07:00
Paul Gauthier
a614179209 fix logic when there is no git repo 2023-05-11 06:01:37 -07:00
paul-gauthier
ce26146075
Update README.md 2023-05-10 22:54:29 -07:00
Paul Gauthier
86ba5c778c updated readme 2023-05-10 22:50:25 -07:00
Paul Gauthier
d9789f3fd7 updated readme 2023-05-10 22:48:26 -07:00
Paul Gauthier
13760f3071 updated readme 2023-05-10 22:27:52 -07:00
Paul Gauthier
c313c85f1a updated readme 2023-05-10 22:26:13 -07:00
Paul Gauthier
d0a557cb36 updated readme 2023-05-10 22:22:56 -07:00
Paul Gauthier
94548b712e show_send_output should respect silent 2023-05-10 22:12:13 -07:00
Paul Gauthier
579d28dcf0 remove debug output 2023-05-10 22:08:40 -07:00
Paul Gauthier
a3fa9d46df remove debug output 2023-05-10 22:06:50 -07:00
Paul Gauthier
62d68a77bd updated readme 2023-05-10 22:05:21 -07:00
Paul Gauthier
f026f1eeeb sniff when GPT mentions files that are not in the chat, prompt the user to add them 2023-05-10 22:05:00 -07:00
Paul Gauthier
65436ae255 refactor send output code 2023-05-10 21:42:22 -07:00
Paul Gauthier
84776593d3 black config 2023-05-10 21:35:10 -07:00
Paul Gauthier
36fe08ae13 fixed regex; black config 2023-05-10 21:32:23 -07:00
Paul Gauthier
a73ad25c55 fix 2023-05-10 21:20:04 -07:00
Paul Gauthier
22b151fdd0 aider: Added try-except block to handle ClassNotFound exception in guess_lexer_for_filename function.
# Context:
USER: Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/gauthier/Projects/aider/aider/main.py", line 74, in <module>
    status = main()
             ^^^^^^
  File "/Users/gauthier/Projects/aider/aider/main.py", line 70, in main
    coder.run()
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 185, in run
    self.run_loop()
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 200, in run_loop
    inp = get_input(self.history_file, self.abs_fnames, self.commands)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/getinput.py", line 92, in get_input
    completer_instance = FileContentCompleter(fnames, commands)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/getinput.py", line 24, in __init__
    lexer = guess_lexer_for_filename(fname, content)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/.venv/lib/python3.11/site-packages/pygments/lexers/__init__.py", line 282, in guess_lexer_for_filename
    raise ClassNotFound('no lexer for filename %r found' % fn)
pygments.util.ClassNotFound: no lexer for filename '.flake8' found

ASSISTANT: It seems that the `guess_lexer_for_filename` function from Pygments is raising a `ClassNotFound` exception because it cannot find a lexer for the '.flake8' file. To fix this issue, you can add a try-except block around the `guess_lexer_for_filename` function call to handle the exception and continue processing other files.

Here's the change you need to make in the `aider/getinput.py` file:

```python
aider/getinput.py
<<<<<<< ORIGINAL
            lexer = guess_lexer_for_filename(fname, content)
=======
            try:
                lexer = guess_lexer_for_filename(fname, content)
            except ClassNotFound:
                continue
>>>>>>> UPDATED
```

This change will catch the `ClassNotFound` exception and continue processing the remaining files without raising an error.
2023-05-10 21:19:03 -07:00
Paul Gauthier
a4c58cf106 aider: Updated regex pattern to recognize file paths that start with a dot.
# Context:
USER: the file path part of the regex is not recognizing files that start with a . like .bash_history
ASSISTANT: I see. I'll update the regex pattern in `aider/coder.py` to recognize file paths that start with a dot (e.g., `.bash_history`). Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
        r"^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)"
=======
        r"^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*(?:\w+|\.\w+)(\.[\w\s.-]+)*)"
>>>>>>> UPDATED
```

This update should now correctly recognize file paths that start with a dot.
2023-05-10 21:17:45 -07:00
Paul Gauthier
aca96263d8 aider: Added comments to the regex pattern in aider/coder.py to make it clearer.
# Context:
USER: can you modify the code to add your earlier regex comments?
ASSISTANT: Sure, I will add comments to the regex pattern in the `aider/coder.py` file to make it clearer. Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
    pattern = re.compile(
        r"(^```\S*\s*)?^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)\s+(^```\S*\s*)?^<<<<<<< ORIGINAL\n(.*?\n?)^=======\n(.*?)^>>>>>>> UPDATED",  # noqa: E501
        re.MULTILINE | re.DOTALL,
    )
=======
    pattern = re.compile(
        # Optional: Matches the start of a code block (e.g., ```python) and any following whitespace
        r"(^```\S*\s*)?"
        # Matches the file path
        r"^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)"
        # Optional: Matches the end of a code block (e.g., ```) and any following whitespace
        r"\s+(^```\S*\s*)?"
        # Matches the start of the ORIGINAL section and captures its content
        r"^<<<<<<< ORIGINAL\n(.*?\n?)"
        # Matches the separator between ORIGINAL and UPDATED sections and captures the UPDATED content
        r"^=======\n(.*?)"
        # Matches the end of the UPDATED section
        r"^>>>>>>> UPDATED",
        re.MULTILINE | re.DOTALL,
    )
>>>>>>> UPDATED
```

This should make the regex pattern more understandable.
2023-05-10 21:16:22 -07:00
Paul Gauthier
f26a215ff4 bugfix 2023-05-10 21:13:23 -07:00
Paul Gauthier
d1c62ce09f lint 2023-05-10 20:04:56 -07:00
Paul Gauthier
6fe656c093 removed 2023-05-10 20:03:30 -07:00
Paul Gauthier
4b02f040b0 fixed indent 2023-05-10 19:56:32 -07:00
Paul Gauthier
d0222a7129 color edits 2023-05-10 19:55:59 -07:00
Paul Gauthier
c9efc43c98 aider: Added pyproject.toml file to configure black to use a maximum line length of 100 characters.
# Context:
USER: can i tell black to fix these automatically?
ASSISTANT: Yes, you can use the `black` code formatter to automatically fix formatting issues in your Python files. To do this, you need to have `black` installed. If you don't have it installed, you can install it using pip:

```
pip install black
```

Once `black` is installed, you can run it on a specific file or directory to automatically format the code:

```
black aider/coder.py
```

This command will format the `aider/coder.py` file according to the `black` code style. If you want to format all the Python files in your project, you can run `black` on the project directory:

```
black .
```

This command will format all the Python files in the current directory and its subdirectories.
USER: Please note that I shared content of these additional files: .pre-commit-config.yaml
ASSISTANT: Yes, I see the content of the .pre-commit-config.yaml file. It shows that you have already configured pre-commit hooks for `black` and `flake8`.

When you commit your changes, the pre-commit hooks will automatically run `black` to format your code and `flake8` to check for any linting issues. If there are any issues, the commit will be blocked, and you'll need to fix them before committing again.

To run the pre-commit hooks manually without committing, you can use the following command:

```
pre-commit run --all-files
```

This command will run all the configured hooks on all the files in your repository. If there
^C KeyboardInterrupt
USER: can we configure black to shorten lines to less than 100 chars so flake8 doesn't complain about E501
ASSISTANT: Yes, you can configure `black` to use a specific line length by adding a `pyproject.toml` file to your project's root directory with the desired line length setting. Here's how to create and configure the `pyproject.toml` file:

```toml
pyproject.toml
<<<<<<< ORIGINAL
=======
[tool.black]
line-length = 100
>>>>>>> UPDATED
```

This configuration sets the maximum line length for `black` to 100 characters, which will match the line length requirement of `flake8`. After adding this configuration, `black` will automatically format your code to keep lines within the specified limit.
2023-05-10 19:54:45 -07:00
Paul Gauthier
ff62734fa1 aider: Fixed line length issue by splitting a long line into two lines.
# Context:
USER: aider/commands.py:155:101: E501 line too long (117 > 100 characters)

ASSISTANT: To fix the line length issue, you can split the long line into multiple lines. Here's the change:

```python
aider/commands.py
<<<<<<< ORIGINAL
        if not matched_files:
            if self.coder.repo is not None:
                create_file = Confirm.ask(
                    f"[bright_black]No files matched '{word}'. Do you want to create the file and add it to git?"
                )
=======
        if not matched_files:
            if self.coder.repo is not None:
                create_file = Confirm.ask(
                    f"[bright_black]No files matched '{word}'. "
                    "Do you want to create the file and add it to git?"
                )
>>>>>>> UPDATED
```

This change splits the long line into two lines, keeping the code within the 100 characters limit.
2023-05-10 19:51:25 -07:00
Paul Gauthier
a4398dc503 aider: Removed unused 'new_file' variable in aider/commands.py.
# Context:
USER: Please note that I shared content of these additional files: aider/commands.py
ASSISTANT: Yes, I see the content of aider/commands.py. The issue mentioned earlier is about the local variable 'new_file' being assigned but never used. To fix this, you can remove the 'new_file' variable and use a 'pass' statement instead. Here's the change:

```python
aider/commands.py
<<<<<<< ORIGINAL
                    with open(os.path.join(self.coder.root, word), "w") as new_file:
                        pass
=======
                    with open(os.path.join(self.coder.root, word), "w"):
                        pass
>>>>>>> UPDATED
```

This change removes the unused 'new_file' variable while keeping the file creation functionality intact.
2023-05-10 19:50:34 -07:00
Paul Gauthier
8abf56ae94 change most aider messages to bright_black instead of red; use that for errors 2023-05-10 19:49:26 -07:00
Paul Gauthier
f7b58b780b Changed prompt message for creating a file when no files matched the search term. 2023-05-10 19:41:30 -07:00
Paul Gauthier
296053a8d7 aider: Added commit message to cmd_add method to indicate that the file was created and added by the aider.
# Context:
USER: also commit the add with a suitable message
ASSISTANT: To commit the added file with a suitable message, we will modify the `cmd_add` method in the `aider/commands.py` file. After adding the file to git, we will commit it with a message indicating that the file was created and added by the aider.

Here are the changes to the `aider/commands.py` file:

```python
aider/commands.py
<<<<<<< ORIGINAL
                    if self.coder.repo is not None:
                        self.coder.repo.git.add(os.path.join(self.coder.root, word))
=======
                    if self.coder.repo is not None:
                        self.coder.repo.git.add(os.path.join(self.coder.root, word))
                        commit_message = f"aider: Created and added {word} to git."
                        self.coder.repo.git.commit("-m", commit_message, "--no-verify")
>>>>>>> UPDATED
```

These changes commit the added file with a message indicating that the file was created and added by the aider.
2023-05-10 19:40:35 -07:00
Paul Gauthier
c6d388595d aider: Added ability to create and add file to git if coder repo is not None.
# Context:
USER: say "do you want to create the file and add it to git?" if self.coder.repo is not none. and then add it to git.
ASSISTANT: To implement this feature, we will modify the `cmd_add` method in the `aider/commands.py` file. We will check if `self.coder.repo` is not `None` and then ask the user if they want to create the file and add it to git. If the user confirms, we will create the file, add it to `matched_files`, and add it to the git repository.

Here are the changes to the `aider/commands.py` file:

```python
aider/commands.py
<<<<<<< ORIGINAL
                create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file?")
                if create_file:
                    with open(os.path.join(self.coder.root, word), 'w') as new_file:
                        pass
                    matched_files = [word]
=======
                if self.coder.repo is not None:
                    create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file and add it to git?")
                else:
                    create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file?")

                if create_file:
                    with open(os.path.join(self.coder.root, word), 'w') as new_file:
                        pass
                    matched_files = [word]
                    if self.coder.repo is not None:
                        self.coder.repo.git.add(os.path.join(self.coder.root, word))
>>>>>>> UPDATED
```

These changes check if `self.coder.repo` is not `None` and modify the question asked to the user accordingly. If the user confirms, the new file is created, added to `matched_files`, and added to the git repository if `self.coder.repo` is not `None`.
2023-05-10 19:39:52 -07:00
Paul Gauthier
42d48bcf35 aider: Added functionality to ask the user if they want to create a new file when no matching files are found.
# Context:
USER: Please note that I shared content of these additional files: aider/commands.py
ASSISTANT: Yes, I see the content of the `aider/commands.py` file. If you need any changes or improvements to the code, please let me know.
USER: in cmd_add if word matches no files, use Confirm.ask to ask the user if they would like to create the file. If so, touch the file and put it into matched_files so the for loop adds it
ASSISTANT: To implement this feature, we will use `Confirm.ask` from the `prompt_toolkit` library to ask the user if they want to create the file. If the user confirms, we will create the file using `open` with the 'w' flag and add it to `matched_files` so that it gets added in the for loop.

Here are the changes to the `aider/commands.py` file:

```python
aider/commands.py
<<<<<<< ORIGINAL
from prompt_toolkit.completion import Completion
from aider import prompts
=======
from prompt_toolkit.completion import Completion
from prompt_toolkit.shortcuts import Confirm
from aider import prompts
>>>>>>> UPDATED

aider/commands.py
<<<<<<< ORIGINAL
        for word in args.split():
            matched_files = [file for file in files if word in file]
            if not matched_files:
                self.console.print(f"[red]No files matched '{word}'")
=======
        for word in args.split():
            matched_files = [file for file in files if word in file]
            if not matched_files:
                create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create
^C KeyboardInterrupt
USER: in cmd_add if word matches no files, use rich.prompt.Confirm.ask to ask the user if they would like to create the file. If so, touch the file and put it into matched_files so the for loop adds it
ASSISTANT: To implement this feature, we will use `Confirm.ask` from the `rich.prompt` library to ask the user if they want to create the file. If the user confirms, we will create the file using `open` with the 'w' flag and add it to `matched_files` so that it gets added in the for loop.

Here are the changes to the `aider/commands.py` file:

```python
aider/commands.py
<<<<<<< ORIGINAL
from rich.text import Text
from prompt_toolkit.completion import Completion
from aider import prompts
=======
from rich.text import Text
from rich.prompt import Confirm
from prompt_toolkit.completion import Completion
from aider import prompts
>>>>>>> UPDATED

aider/commands.py
<<<<<<< ORIGINAL
        for word in args.split():
            matched_files = [file for file in files if word in file]
            if not matched_files:
                self.console.print(f"[red]No files matched '{word}'")
=======
        for word in args.split():
            matched_files = [file for file in files if word in file]
            if not matched_files:
                create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file?")
                if create_file:
                    with open(os.path.join(self.coder.root, word), 'w') as new_file:
                        pass
                    matched_files = [word]
                else:
                    self.console.print(f"[red]No files matched '{word}'")
>>>>>>> UPDATED
```

These changes import `Confirm` from `rich.prompt` and use it to ask the user if they want to create a new file when no matching files are found. If the user confirms, the new file is created and added to `matched_files`.
2023-05-10 19:36:51 -07:00
Paul Gauthier
cda834f7fd updated readme 2023-05-10 19:32:23 -07:00