Commit graph

39 commits

Author SHA1 Message Date
Paul Gauthier
f26a215ff4 bugfix 2023-05-10 21:13:23 -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
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
ad4e1659aa better /ls output 2023-05-10 19:31:57 -07:00
Paul Gauthier
35a4a14a6a Avoid sending 2 copies of the added files 2023-05-10 19:13:33 -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
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
42ccd9c550 improved completions for /add and /drop 2023-05-10 17:48:15 -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
4e9119a0e0 Refactor the cmd_ commands into Coder 2023-05-10 11:34:34 -07:00
Paul Gauthier
475bc486d2 Fixed console print formatting in commands.py. 2023-05-10 11:23:36 -07:00
Paul Gauthier
7170324214 aider: Implemented cmd_help to print out a list of all the commands along with their docstring description.
# Context:
USER: implement cmd_help. have it print out a list of all the commands along with their docstring description
ASSISTANT: To implement the `cmd_help` method, we will iterate through the available commands and print their names along with their docstring descriptions.

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

```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_help(self, args):
        "Show help about all commands"
        pass
=======
    def cmd_help(self, args):
        "Show help about all commands"
        commands = self.get_commands()
        for cmd in commands:
            cmd_method_name = f"cmd_{cmd[1:]}"
            cmd_method = getattr(self, cmd_method_name, None)
            if cmd_method:
                description = cmd_method.__doc__
                self.console.print(f"{cmd}: {description}")
            else:
                self.console.print(f"{cmd}: No description available.")
>>>>>>> UPDATED
```

This will print the command names along with their docstring descriptions when the `cmd_help` method is called.
2023-05-10 11:22:55 -07:00
Paul Gauthier
c169bdf4ba wip: Changed cmd_help and cmd_ls to include command descriptions. 2023-05-10 11:21:46 -07:00
Paul Gauthier
6076cd0fb7 Added Commands.console 2023-05-10 11:20:25 -07:00
Paul Gauthier
c368737e70 aider: Added __init__ function to Commands class to assign console to self.console.
# Context:
USER: pass the console into do_run and into each cmd_ function.
ASSISTANT: To pass the `console` object into the `do_run` method and each `cmd_` function, we need to modify the `do_run` method and update the `cmd_help` and `cmd_ls` methods to accept the `console` parameter.

Here are the changes to the `aider
^C KeyboardInterrupt
USER: add an __init__ function which takes the console and assigns it to self.console
ASSISTANT: To add an `__init__` function that takes the `console` parameter and assigns it to `self.console`, we need to modify the `Commands` class in the `aider/commands.py` file.

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

```python
aider/commands.py
<<<<<<< ORIGINAL
class Commands:
=======
class Commands:
    def __init__(self, console):
        self.console = console
>>>>>>> UPDATED
```

Now, you can use `self.console` in the `Commands` class methods instead of passing the `console` parameter to each method.
2023-05-10 11:18:24 -07:00
Paul Gauthier
e33ee46fe1 aider: Implemented do_run method to invoke the correct cmd_ method function based on the provided cmd_name and passing it the args.
# Context:
USER: implement do_run. use the cmd_name (which has no /) to invoke the correct cmd_ method function, passing it the args.
ASSISTANT: To implement the `do_run` method, we will use the `cmd_name` to find the corresponding `cmd_` method and invoke it with the provided `args`. We can use the `getattr` function to get the method by its name and then call it with the `args`.

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

```python
aider/commands.py
<<<<<<< ORIGINAL
    def do_run(self, cmd_name, args):
        pass
=======
    def do_run(self, cmd_name, args):
        cmd_method_name = f"cmd_{cmd_name}"
        cmd_method = getattr(self, cmd_method_name, None)
        if cmd_method:
            cmd_method(args)
        else:
            print(f"Error: Command {cmd_name} not found.")
>>>>>>> UPDATED
```
2023-05-10 11:16:56 -07:00
Paul Gauthier
126b5e1f3b Added a new method do_run and improved error messages. 2023-05-10 11:15:20 -07:00
Paul Gauthier
8b2fdd4b92 aider: Modified run method to compare first word of input to commands and print partial matches or error message.
# Context:
USER: in run, compare the first word to all the get_commands to figure out which cmd is being run. the first word may only be part of the name of a command. if it uniquely matches just one command, print 'run' and that command. if it matches more than one command, print the list of partial matches. if it matches none, print an error
ASSISTANT: To implement the requested feature, we need to modify the `run` method in the `Commands` class. We will compare the first word of the input to the commands returned by `get_commands`. If there is a unique partial match, we will print 'run' and the command. If there are multiple partial matches, we will print the list of partial matches. If there are no matches, we will print an error message.

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

```python
aider/commands.py
<<<<<<< ORIGINAL
    def run(self, inp, console):
        console.print('[red]', inp)
        words = inp.strip().split()
=======
    def run(self, inp, console):
        words = inp.strip().split()
        if not words:
            return

        first_word = words[0]
        all_commands = self.get_commands()
        matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]

        if len(matching_commands) == 1:
            console.print('[green]run', matching_commands[0])
        elif len(matching_commands) > 1:
            console.print('[yellow]Partial matches:', ', '.join(matching_commands))
        else:
            console.print('[red]Error: Command not found')
>>>>>>> UPDATED
```
2023-05-10 11:12:17 -07:00
Paul Gauthier
82ee7fe0a5 Initial commit: Added new files to the git repo: aider/commands.py 2023-05-10 11:08:24 -07:00