Commit graph

10395 commits

Author SHA1 Message Date
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
Paul Gauthier
ad4e1659aa better /ls output 2023-05-10 19:31:57 -07:00
Paul Gauthier
fb04016ec9 Use cwd if no files provided 2023-05-10 19:29:31 -07:00
Paul Gauthier
6e1282202d aider: Changed nargs attribute of "files" argument to make it optional.
# Context:
USER: make the file args optionall. the user can run the command without specifying files.
ASSISTANT: To make the file arguments optional, we need to change the nargs attribute of the "files" argument in the ArgumentParser.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "files",
        metavar="FILE",
        nargs="+",
        help="a list of source code files",
    )
=======
    parser.add_argument(
        "files",
        metavar="FILE",
        nargs="*",
        help="a list of source code files (optional)",
    )
>>>>>>> UPDATED
```
2023-05-10 19:28:58 -07:00
Paul Gauthier
775fbe95f9 allow directories to be provided on the command line; use them to find the git repo 2023-05-10 19:27:45 -07:00
Paul Gauthier
35a4a14a6a Avoid sending 2 copies of the added files 2023-05-10 19:13:33 -07:00
Paul Gauthier
b139dbf475 refactor 2023-05-10 18:41:36 -07:00
Paul Gauthier
fcaf4e15c8 reply with new files content on /add 2023-05-10 18:33:04 -07:00
Paul Gauthier
7a0e020c66 undo print & reply 2023-05-10 18:27:05 -07:00
Paul Gauthier
79d38b5d68 handle the simple replace case quickly 2023-05-10 18:21:41 -07:00
Paul Gauthier
395cf4c14f wip: Added a new prompt message for undo command and updated the message format. 2023-05-10 18:14:47 -07:00
Paul Gauthier
bce64f1986 allow commands to reply to gpt; /undo tells it with discarded the changes 2023-05-10 18:08:33 -07:00
Paul Gauthier
fcacc3c139 noop 2023-05-10 18:05:30 -07:00
Paul Gauthier
ee73e8eb41 noop 2023-05-10 18:02:50 -07:00
Paul Gauthier
b74779d1b7 bugfixes 2023-05-10 18:01:09 -07:00
Paul Gauthier
f8939c55a5 aider: Updated the Usage section in README.md to show the new environment variable default for the --model command-line argument.
# Context:
USER: update readme
ASSISTANT: Please provide more information about what you would like to update in the README.md file.
USER: so usage shows the new env default for --model
ASSISTANT: I will update the Usage section in the README.md file to show the new environment variable default for the `--model` command-line argument.

```python
README.md
<<<<<<< ORIGINAL
- `--model MODEL`: Specify the model to use for the main chat (default: gpt-4). No environment variable override.
=======
- `--model MODEL`: Specify the model to use for the main chat (default: gpt-4). Override with the environment variable `AIDER_MODEL`.
>>>>>>> UPDATED
```

Now, the Usage section in the README.md file shows the environment variable default for the `--model` command-line argument.
2023-05-10 17:58:34 -07:00
Paul Gauthier
1fedba8505 aider: Added environment variable override for --model command-line argument.
# Context:
USER: add an env override for --model
ASSISTANT: I will add an environment variable override for the `--model` command-line argument in the `aider/main.py` file.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--model",
        metavar="MODEL",
        default="gpt-4",
        help="Specify the model to use for the main chat (default: gpt-4)",
    )
=======
    parser.add_argument(
        "--model",
        metavar="MODEL",
        default=os.environ.get(f"{env_prefix}MODEL", "gpt-4"),
        help=f"Specify the model to use for the main chat (default: gpt-4, ${env_prefix}MODEL)",
    )
>>>>>>> UPDATED
```

Now, the `--model` command-line argument can be overridden using the `AIDER_MODEL` environment variable.
2023-05-10 17:57:51 -07:00
Paul Gauthier
8ce2f381b8 Added --commit-dirty option to commit dirty files without confirmation on launch. 2023-05-10 17:56:57 -07:00
Paul Gauthier
5e438941ce aider: Updated the Usage section in README.md to explain all the command-line arguments and their environment variable overrides.
# Context:
USER: update the Usage section to explain all the command line args and their env overrides
ASSISTANT: I will update the Usage section in the README.md file to explain all the command-line arguments and their environment variable overrides.

```python
README.md
<<<<<<< ORIGINAL
Run the Aider tool by executing the following command:

```
aider <file1> <file2> ...
```

Replace `<file1>`, `<file2>`, etc., with the paths to the source code files you want to work on.

You can also use additional command-line options to customize the behavior of the tool. The following options are available:

- `--history-file HISTORY_FILE`: Specify the history file (default: .aider.history, AIDER_HISTORY_FILE).
- `--model MODEL`: Specify the model to use for the main chat (default: gpt-4).
- `-3`: Use gpt-3.5-turbo model for the main chat (basically won't work).
- `--no-pretty`: Disable pretty, colorized output (AIDER_PRETTY).
- `--apply FILE`: Apply the changes from the given file instead of running the chat.
- `--commit-dirty`: On launch, commit dirty files w/o confirmation (default: False, AIDER_COMMIT_DIRTY).
- `--show-diffs`: Show diffs when committing changes (default: False, AIDER_SHOW_DIFFS).
=======
Run the Aider tool by executing the following command:

```
aider <file1> <file2> ...
```

Replace `<file1>`, `<file2>`, etc., with the paths to the source code files you want to work on.

You can also use additional command-line options to customize the behavior of the tool. The following options are available, along with their corresponding environment variable overrides:

- `--history-file HISTORY_FILE`: Specify the history file (default: .aider.history). Override with the environment variable `AIDER_HISTORY_FILE`.
- `--model MODEL`: Specify the model to use for the main chat (default: gpt-4). No environment variable override.
- `-3`: Use gpt-3.5-turbo model for the main chat (basically won't work). No environment variable override.
- `--no-pretty`: Disable pretty, colorized output. Override with the environment variable `AIDER_PRETTY` (default: 1 for enabled, 0 for disabled).
- `--apply FILE`: Apply the changes from the given file instead of running the chat. No environment variable override.
- `--commit-dirty`: On launch, commit dirty files without confirmation (default: False). Override with the environment variable `AIDER_COMMIT_DIRTY` (default: 0 for False, 1 for True).
- `--show-diffs`: Show diffs when committing changes (default: False). Override with the environment variable `AIDER_SHOW_DIFFS` (default: 0 for False, 1 for True).
>>>>>>> UPDATED
```

This update provides a clearer explanation of the command-line arguments and their environment variable overrides.
2023-05-10 17:56:37 -07:00
Paul Gauthier
4c139ee0a2 wip: Changed the help message for the history file and removed the commit-dirty option, added a debug option to apply changes from a file. 2023-05-10 17:54:49 -07:00
Paul Gauthier
1b7b0fddfe aider: Updated Usage section in README.md to explain all the command line arguments and their environment variable overrides.
# Context:
USER: update the Usage section to explain all the command line args and their env overrides
ASSISTANT: I will update the Usage section in the README.md file to explain all the command line arguments and their environment variable overrides.

```python
README.md
<<<<<<< ORIGINAL
Run the Aider tool by executing the following command:

```
aider <file1> <file2> ...
```

Replace `<file1>`, `<file2>`, etc., with the paths to the source code files you want to work on.

You can also use additional command-line options to customize the behavior of the tool. For more information, run `aider --help`. Many defaults can be set with `.env` or environment variables, see the help output.
=======
Run the Aider tool by executing the following command:

```
aider <file1> <file2> ...
```

Replace `<file1>`, `<file2>`, etc., with the paths to the source code files you want to work on.

You can also use additional command-line options to customize the behavior of the tool. The following options are available:

- `--history-file HISTORY_FILE`: Specify the history file (default: .aider.history, AIDER_HISTORY_FILE).
- `--model MODEL`: Specify the model to use for the main chat (default: gpt-4).
- `-3`: Use gpt-3.5-turbo model for the main chat (basically won't work).
- `--no-pretty`: Disable pretty, colorized output (AIDER_PRETTY).
- `--apply FILE`: Apply the changes from the given file instead of running the chat.
- `--commit-dirty`: On launch, commit dirty files w/o confirmation (default: False, AIDER_COMMIT_DIRTY).
- `--show-diffs`: Show diffs when committing changes (default: False, AIDER_SHOW_DIFFS).

For more information, run `aider --help`. Many defaults can be set with `.env` or environment variables, see the help output.
>>>>>>> UPDATED
```
2023-05-10 17:52:12 -07:00
Paul Gauthier
42ccd9c550 improved completions for /add and /drop 2023-05-10 17:48:15 -07:00
Paul Gauthier
923e42c176 fixed off by 1 error in replace_most_similar_chunk() 2023-05-10 16:22:08 -07:00
Paul Gauthier
9ad44d5d7a Refactor filename handling for clarity 2023-05-10 16:14:32 -07:00
Paul Gauthier
d50e9755ed aider: Added completions_drop method that returns the list of active files that are also in self.coder.fnames.
# Context:
USER: create completions_drop which returns the list of get_active_files which are also in self.coder.fnames
ASSISTANT: ```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_drop(self, args):
        "Remove matching files from the chat"

        for word in args.split():
            matched_files = [
                file
                for file in self.coder.fnames
                if word in os.path.relpath(file, self.coder.root)
            ]
            if not matched_files:
                self.console.print(f"[red]No files matched '{word}'")
            for matched_file in matched_files:
                relative_fname = os.path.relpath(matched_file, self.coder.root)
                self.coder.fnames.remove(matched_file)
                self.console.print(f"[red]Removed {relative_fname} from the chat")
=======
    def completions_drop(self):
        active_files = self.coder.get_active_files()
        return [
            os.path.relpath(file, self.coder.root)
            for file in self.coder.fnames
            if file in active_files
        ]

    def cmd_drop(self, args):
        "Remove matching files from the chat"

        for word in args.split():
            matched_files = [
                file
                for file in self.coder.fnames
                if word in os.path.relpath(file, self.coder.root)
            ]
            if not matched_files:
                self.console.print(f"[red]No files matched '{word}'")
            for matched_file in matched_files:
                relative_fname = os.path.relpath(matched_file, self.coder.root)
                self.coder.fnames.remove(matched_file)
                self.console.print(f"[red]Removed {relative_fname} from the chat")
>>>>>>> UPDATED
```

I added the `completions_drop` method that returns the list of active files that are also in `self.coder.fnames`.
2023-05-10 16:02:29 -07:00
Paul Gauthier
bc43d9ac31 allow /commands to provide their own completions 2023-05-10 16:00:04 -07:00
Paul Gauthier
623d36d831 aider: Implemented get_command_completions method to call the corresponding cmd_{cmd_name}_completions method if it exists and return its result, otherwise return None.
# Context:
USER: implement get_command_completions. it should look for f"cmd_{cmd_name}_completions" and call that function and return the results. if the functionn isn't found return None.
ASSISTANT: To implement the `get_command_completions` method, we will call the corresponding `cmd_{cmd_name}_completions` method if it exists and return its result. If the method is not found, we will return None.

Here's the updated code for `aider/commands.py`:

```python
aider/commands.py
<<<<<<< ORIGINAL
    def get_command_completions(self, cmd_name):
        pass
=======
    def get_command_completions(self, cmd_name):
        cmd_completions_method_name = f"cmd_{cmd_name}_completions"
        cmd_completions_method = getattr(self, cmd_completions_method_name, None)
        if cmd_completions_method:
            return cmd_completions_method()
        else:
            return None
>>>>>>> UPDATED
```
2023-05-10 15:53:58 -07:00
Paul Gauthier
b66ac52388 changed /ls output format 2023-05-10 15:48:31 -07:00
Paul Gauthier
9f55e07849 wip: Changed ls command output to show files in chat with red color. 2023-05-10 15:44:51 -07:00
Paul Gauthier
a793e9ac56 fix linting errors 2023-05-10 15:44:03 -07:00
Paul Gauthier
9776c5c615 aider: Fixed unused import, long line, undefined name, and missing f-string placeholder.
# Context:
USER: aider/coder.py:13:1: F401 'rich.syntax.Syntax' imported but unused
aider/commands.py:59:101: E501 line too long (106 > 100 characters)
aider/commands.py:120:28: F821 undefined name 'Text'
aider/commands.py:159:28: F541 f-string is missing placeholders

ASSISTANT: I will fix the issues mentioned in the provided code.

1. Remove the unused import 'rich.syntax.Syntax' from aider/coder.py.
2. Break the long line in aider/commands.py:59 into multiple lines.
3. Import 'Text' from 'rich.text' in aider/commands.py.
4. Add a placeholder in the f-string in aider/commands.py:159.

Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
from rich.syntax import Syntax
=======
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
        matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
=======
        matching_commands = [
            cmd for cmd in all_commands if cmd.startswith(first_word)
        ]
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.live import Live
from rich.text import Text
=======
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.live import Live
from rich.text import Text, Text
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
            self.console.print(f"[red]Ambiguous command:", ", ".join(matching_commands))
=======
            self.console.print(f"[red]Ambiguous command: {', '.join(matching_commands)}")
>>>>>>> UPDATED
```
2023-05-10 15:40:48 -07:00
Paul Gauthier
409cf8d93b Refactor the cmd_ funcs to Commands 2023-05-10 15:39:39 -07:00
Paul Gauthier
9bd635a7a4 aider: Populate self.words using Pygments lexer to tokenize the file content and add all the Token.Name tokens to self.words.
# Context:
USER: in FileContentCompleter instead of populating self.words by splitting words with a regex, run the pygments lexer on each file and add all the Token.Name tokens to words. ask the lexer to guess the language type.
ASSISTANT: To use Pygments lexer to populate `self.words`, you need to first install the Pygments package by adding it to your `requirements.txt` file. Then, you can use the `guess_lexer_for_filename` function to guess the lexer based on the file name and use the lexer to tokenize the file content. Finally, you can filter the tokens by `Token.Name` and add them to `self.words`.

Here are the changes you need to make:

```python
requirements.txt
<<<<<<< ORIGINAL
=======
pygments
>>>>>>> UPDATED
```

```python
aider/getinput.py
<<<<<<< ORIGINAL
import os
import re
=======
import os
from pygments import highlight
from pygments.lexers import guess_lexer_for_filename
from pygments.token import Token
>>>>>>> UPDATED
```

```python
aider/getinput.py
<<<<<<< ORIGINAL
    def __init__(self, fnames, commands):
        self.commands = commands

        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
            self.words.update(re.split(r"\W+", content))
=======
    def __init__(self, fnames, commands):
        self.commands = commands

        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
            lexer = guess_lexer_for_filename(fname, content)
            tokens = list(lexer.get_tokens(content))
            self.words.update(
                token[1] for token in tokens if token[0] in Token.Name
            )
>>>>>>> UPDATED
```

These changes will use the Pygments lexer to populate `self.words` with the `Token.Name` tokens.
2023-05-10 15:26:40 -07:00
Paul Gauthier
7cc2b59a25 updated readme 2023-05-10 13:02:37 -07:00
Paul Gauthier
6f922f4674 aider: Added /commit, /undo, and /diff commands to the README.md file.
# Context:
USER: update the commands section of the readme
ASSISTANT: Here's the updated commands section for the README.md file:

```markdown
README.md
<<<<<<< ORIGINAL
* `/add <file>`: Add matching files to the chat.
* `/drop <file>`: Remove matching files from the chat.
* `/ls`: List files and show their chat status.
=======
* `/add <file>`: Add matching files to the chat.
* `/drop <file>`: Remove matching files from the chat.
* `/ls`: List files and show their chat status.
* `/commit [message]`: Commit outstanding changes to the chat files. Aider will provide a commit message if you don't.
* `/undo`: Undo the last git commit if it was done by aider.
* `/diff`: Display the diff of the last aider commit.
>>>>>>> UPDATED
```

I've added the `/commit`, `/undo`, and `/diff` commands to the list.
2023-05-10 12:56:28 -07:00
Paul Gauthier
b04359747f Changed commit message to display error message when unable to get commit message from gpt-3.5-turbo. 2023-05-10 12:55:07 -07:00
Paul Gauthier
921546881e aider: Added error message when no files matched in cmd_add and cmd_drop.
# Context:
USER: in cmd_add and cmd_drop, print an error if no files matched
ASSISTANT: To print an error message when no files are matched in `cmd_add` and `cmd_drop`, you can add a check for the length of `matched_files` and print an error message if it's zero. Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def cmd_add(self, args):
        "Add matching files to the chat"

        files = self.get_active_files()
        for word in args.split():
            matched_files = [file for file in files if word in file]
=======
    def cmd_add(self, args):
        "Add matching files to the chat"

        files = self.get_active_files()
        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}'")
>>>>>>> UPDATED

aider/coder.py
<<<<<<< ORIGINAL
    def cmd_drop(self, args):
        "Remove matching files from the chat"

        for word in args.split():
            matched_files = [file for file in self.fnames if word in os.path.relpath(file, self.root)]
=======
    def cmd_drop(self, args):
        "Remove matching files from the chat"

        for word in args.split():
            matched_files = [file for file in self.fnames if word in os.path.relpath(file, self.root)]
            if not matched_files:
                self.console.print(f"[red]No files matched '{word}'")
>>>>>>> UPDATED
```
2023-05-10 12:54:09 -07:00
Paul Gauthier
ff23292f83 Changed the way to display git diff in coder.py. 2023-05-10 12:51:02 -07:00
Paul Gauthier
ff62c39feb aider: Added colorization to cmd_diff method when self.pretty is True.
# Context:
USER: in cmd_diff, check self.pretty and colorize the diff if it's true
ASSISTANT: To colorize the diff output in the `cmd_diff` method when `self.pretty` is True, we will use the `rich.syntax` module to highlight the diff.

```python
aider/coder.py
<<<<<<< ORIGINAL
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.live import Live
from rich.text import Text
from rich.markdown import Markdown
=======
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.live import Live
from rich.text import Text
from rich.markdown import Markdown
from rich.syntax import Syntax
>>>>>>> UPDATED

aider/coder.py
<<<<<<< ORIGINAL
    def cmd_diff(self, args):
        "Display the diff of the last aider commit"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        if not self.last_aider_commit_hash:
            self.console.print("[red]No previous aider commit found.")
            return

        diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
        self.console.print(Text(diff))
=======
    def cmd_diff(self, args):
        "Display the diff of the last aider commit"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        if not self.last_aider_commit_hash:
            self.console.print("[red]No previous aider commit found.")
            return

        diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
        if self.pretty:
            syntax_diff = Syntax(diff, "diff", theme="monokai", line_numbers=False)
            self.console.print(syntax_diff)
        else:
            self.console.print(Text(diff))
>>>>>>> UPDATED
```

Now, the `cmd_diff` method will colorize the diff output when `self.pretty` is True.
2023-05-10 12:49:37 -07:00
Paul Gauthier
143683c7fd Saving dirty files before chat 2023-05-10 12:47:34 -07:00
Paul Gauthier
8d6eafb1dc aider: Added cmd_diff command to display the diff of the last aider commit.
# Context:
USER: add cmd_diff which displays the diff of the last aider commit
ASSISTANT: To add the `cmd_diff` command, we will update the `aider/coder.py` file. We will add a new method called `cmd_diff` to the `Coder` class and update the `Commands` instance to include the new command.

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.commands = Commands(self.console, self)
=======
        self.commands = Commands(self.console, self)
        self.commands.add("diff", self.cmd_diff, "Display the diff of the last aider commit")
>>>>>>> UPDATED

aider/coder.py
<<<<<<< ORIGINAL
    def cmd_ls(self, args):
        "List files and show their chat status"

        self.console.print(f"* denotes files included in the chat\n")
        files = self.get_active_files()

        for file in files:
            abs_file_path = os.path.abspath(os.path.join(self.root, file))
            if abs_file_path in self.fnames:
                self.console.print(f"* {file}")
            else:
                self.console.print(f"  {file}")
=======
    def cmd_diff(self, args):
        "Display the diff of the last aider commit"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        if not self.last_aider_commit_hash:
            self.console.print("[red]No previous aider commit found.")
            return

        diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
        self.console.print(Text(diff))

    def cmd_ls(self, args):
        "List files and show their chat status"

        self.console.print(f"* denotes files included in the chat\n")
        files = self.get_active_files()

        for file in files:
            abs_file_path = os.path.abspath(os.path.join(self.root, file))
            if abs_file_path in self.fnames:
                self.console.print(f"* {file}")
            else:
                self.console.print(f"  {file}")
>>>>>>> UPDATED
```

This will add the `cmd_diff` command to display the diff of the last aider commit.
2023-05-10 12:46:44 -07:00
Paul Gauthier
540c12fafa wip: Added optional commit message to commit method and updated cmd_commit to use it or provide a default message. 2023-05-10 12:44:28 -07:00
Paul Gauthier
6b24072973 aider: Added cmd_commit method to commit outstanding changes to the chat files with a sensible commit message.
# Context:
USER: finish implementing cmd_commit
ASSISTANT: To finish implementing the `cmd_commit` method in the `Coder` class, you can add the following code to `aider/coder.py`. This method will commit outstanding changes to the chat files with a sensible commit message.

```python
aider/coder.py
<<<<<<< ORIGINAL
    def cmd_commit(self, args):
        "Commit outstanding changes to the chat files with a sensible commit message"
=======
    def cmd_commit(self, args):
        "Commit outstanding changes to the chat files with a sensible commit message"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        if not self.repo.is_dirty():
            self.console.print("[red]No changes to commit.")
            return

        commit_message = args.strip()
        if not commit_message:
            commit_message = "aider: Manual commit of outstanding changes"

        self.repo.git.add(*[os.path.relpath(fname, self.repo.working_tree_dir) for fname in self.fnames])
        self.repo.git.commit("-m", commit_message, "--no-verify")
        commit_hash = self.repo.head.commit.hexsha[:7]
        self.console.print(f"[red]{commit_hash} {commit_message}")
>>>>>>> UPDATED
```

This code checks if there is a git repository and if there are any outstanding changes. If there are changes, it commits them with the provided commit message or a default one if no message is provided.
2023-05-10 12:39:45 -07:00
Paul Gauthier
cfd27c84e9 aider: Added condition to check if the last commit's hash matches last_aider_commit_hash before undoing the commit.
# Context:
USER: also double check the last commit against last_aider_commit_hash
ASSISTANT: To double-check the last commit against `last_aider_commit_hash` before undoing the commit, you can add a condition to the `cmd_undo` method in the `Coder` class in `aider/coder.py`.

```python
aider/coder.py
<<<<<<< ORIGINAL
        last_commit = self.repo.head.commit
        if not last_commit.message.startswith("aider:"):
            self.console.print("[red]The last commit was not made by Aider.")
            return
=======
        last_commit = self.repo.head.commit
        if not last_commit.message.startswith("aider:") or last_commit.hexsha[:7] != self.last_aider_commit_hash:
            self.console.print("[red]The last commit was not made by Aider or the commit hash does not match.")
            return
>>>>>>> UPDATED
```

This change adds a condition to check if the last commit's hash matches `last_aider_commit_hash` before undoing the commit. If it doesn't match, the method will print a message and return without undoing the commit.
2023-05-10 12:36:06 -07:00
Paul Gauthier
59ab516cbb aider: Added functionality to undo the last git commit if it was done by Aider.
# Context:
USER: finish cmd_undo
ASSISTANT: To finish the `cmd_undo` method in the `Coder` class, you can add the following code to `aider/coder.py`. This method will undo the last git commit if it was done by Aider.

```python
aider/coder.py
<<<<<<< ORIGINAL
    def cmd_undo(self, args):
        "Undo the last git commit if it was done by aider"
=======
    def cmd_undo(self, args):
        "Undo the last git commit if it was done by aider"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        last_commit = self.repo.head.commit
        if not last_commit.message.startswith("aider:"):
            self.console.print("[red]The last commit was not made by Aider.")
            return

        self.repo.git.reset("--hard", "HEAD~1")
        self.console.print(f"[red]Undid the last commit: {last_commit.message.strip()}")
>>>>>>> UPDATED
```

This code checks if there is a git repository, and if the last commit was made by Aider. If so, it undoes the last commit using `git reset --hard HEAD~1`.
2023-05-10 12:35:00 -07:00
Paul Gauthier
4fc7b99de4 Added ability to undo last aider commit. 2023-05-10 12:34:16 -07:00
Paul Gauthier
24593a345f Changed command descriptions to be more specific. 2023-05-10 12:30:28 -07:00