Commit graph

2618 commits

Author SHA1 Message Date
Paul Gauthier
12cf19010f Refactor check_version function to accept a print_cmd argument and update print statements accordingly.
# Aider chat conversation:
2023-07-20 08:37:44 -03:00
Paul Gauthier
fe9bcef676 Add support for printing the Python executable name in the upgrade message.
# Aider chat conversation:
2023-07-20 08:36:26 -03:00
Paul Gauthier
4b133929c8 aider: Add print statement with upgrade command in check_version function.
# Aider chat conversation:

USER: also print the command the user should use to upgrade

ASSISTANT: To print the command the user should use to upgrade, we can add a print statement in the `check_version` function in the `aider/versioncheck.py` file. This print statement will provide the command to upgrade the `aider-chat` package using pip.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import requests
import pkg_resources
import aider

from aider.dump import dump

def check_version():
    response = requests.get('https://pypi.org/pypi/aider-chat/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider-chat').version

    if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(current_version):
        return

    print(f"Running aider version {current_version}, newer version available: {latest_version}")

if __name__ == "__main__":
    check_version()
=======
import requests
import pkg_resources
import aider

from aider.dump import dump

def check_version():
    response = requests.get('https://pypi.org/pypi/aider-chat/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider-chat').version

    if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(current_version):
        return

    print(f"Running aider version {current_version}, newer version available: {latest_version}")
    print("To upgrade, run: pip install --upgrade aider-chat")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

This will print the command `pip install --upgrade aider-chat` when a newer version is available. The user can then copy this command and run it in their terminal to upgrade the `aider-chat` package.
2023-07-20 08:34:54 -03:00
Paul Gauthier
e94f85b61e Refactor version check to include the package name in the URL and print the current version.
# Aider chat conversation:
2023-07-20 08:33:18 -03:00
Paul Gauthier
cf8f76533d aider: Refactored versioncheck.py to use the PyPI JSON API instead of web scraping.
# Aider chat conversation:

USER: can we use a json api not scrape?

ASSISTANT: Yes, we can use the PyPI JSON API to get the information about the latest version of the package.

We will modify the `aider/versioncheck.py` file.

Here are the steps:

1. Send a GET request to the PyPI JSON API for the `aider` package.
2. Parse the JSON response to find the latest version number.
3. Compare this version number with the current version of `aider` installed in the system.
4. Print a message indicating whether a newer version is available.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import requests
from bs4 import BeautifulSoup
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/project/aider/')
    soup = BeautifulSoup(response.text, 'html.parser')
    latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1]
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
=======
import requests
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/pypi/aider/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

This version of the script uses the PyPI JSON API, which is more reliable and faster than web scraping.
2023-07-20 08:24:46 -03:00
Paul Gauthier
51943b68e2 aider: Added a script to check the latest version of the 'aider' package on PyPI and compare it with the current installed version.
# Aider chat conversation:

USER: write a script that checks pypi to see if a newer version of aider is available

ASSISTANT: To accomplish this, we will use the `requests` and `bs4` (BeautifulSoup) libraries in Python to scrape the PyPI website for the latest version of the `aider` package.

We will add this script to the `aider/versioncheck.py` file.

Here are the steps:

1. Import the necessary libraries.
2. Define a function that sends a GET request to the PyPI page for the `aider` package.
3. Parse the HTML response to find the latest version number.
4. Compare this version number with the current version of `aider` installed in the system.
5. Print a message indicating whether a newer version is available.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL

=======
import requests
from bs4 import BeautifulSoup
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/project/aider/')
    soup = BeautifulSoup(response.text, 'html.parser')
    latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1]
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

Please note that this script assumes that `requests`, `bs4`, and `pkg_resources` are installed in your Python environment. If not, you can install them using pip:

```bash
pip install requests beautifulsoup4 setuptools
```
2023-07-20 08:24:11 -03:00
Paul Gauthier
7d9d163561 Added new files to the git repo: aider/versioncheck.py 2023-07-20 08:22:05 -03:00
Paul Gauthier
7778d9a72d Merge branch 'main' into retry-edit-errors 2023-07-20 08:16:21 -03:00
Paul Gauthier
fab04efc53 Updated HISTORY 2023-07-20 08:16:16 -03:00
Paul Gauthier
405aeaaa61 updated ctags doc 2023-07-20 07:53:08 -03:00
Joshua Vial
03442d3c84 remove argument from /help in docs 2023-07-20 10:43:18 +12:00
Joshua Vial
53de30c1ac Add docs for commands and prompt-toolkit defaults 2023-07-20 10:32:34 +12:00
Paul Gauthier
4bc35a7376 Ask GPT to retry if original block is not found 2023-07-19 17:24:53 -03:00
Paul Gauthier
691c013272 Added discord link 2023-07-19 09:57:33 -03:00
Paul Gauthier
aeb11fd8f7 Updated HISTORY 2023-07-19 09:11:09 -03:00
Paul Gauthier
81a3a7f7af Disable pretty output and print a message when running in a VSCode terminal.
# Aider chat conversation:
2023-07-19 09:07:27 -03:00
Paul Gauthier
7930cea227 aider: Disable pretty output and inform the user if a VSCode terminal has been detected.
# Aider chat conversation:

USER: if VSCODE_GIT_IPC_HANDLE is set in the environment, turn off pretty and tell the user a VSCode terminal has been detected so pretty output has been disabled

ASSISTANT: To implement this change, we need to modify the `main` function in the `aider/main.py` file. We will check if the `VSCODE_GIT_IPC_HANDLE` environment variable is set and if so, disable pretty output and inform the user.

Here is the proposed change:

```python
aider/main.py
<<<<<<< ORIGINAL
    args = parser.parse_args(args)

    if args.dark_mode:
        args.user_input_color = "#32FF32"
        args.tool_error_color = "#FF3333"
        args.assistant_output_color = "#00FFFF"
        args.code_theme = "monokai"

    if args.light_mode:
        args.user_input_color = "green"
        args.tool_error_color = "red"
        args.assistant_output_color = "blue"
        args.code_theme = "default"
=======
    args = parser.parse_args(args)

    if 'VSCODE_GIT_IPC_HANDLE' in os.environ:
        args.pretty = False
        print("VSCode terminal detected, pretty output has been disabled.")

    if args.dark_mode:
        args.user_input_color = "#32FF32"
        args.tool_error_color = "#FF3333"
        args.assistant_output_color = "#00FFFF"
        args.code_theme = "monokai"

    if args.light_mode:
        args.user_input_color = "green"
        args.tool_error_color = "red"
        args.assistant_output_color = "blue"
        args.code_theme = "default"
>>>>>>> UPDATED
```

This change checks for the `VSCODE_GIT_IPC_HANDLE` environment variable right after parsing the arguments. If it's present, it sets `args.pretty` to `False` and prints a message to the user.
2023-07-19 09:06:49 -03:00
Paul Gauthier
60e49ae40c added test_replace_part_with_missing_varied_leading_whitespace 2023-07-18 15:13:14 -03:00
Paul Gauthier
6ac2c45735 copy 2023-07-18 10:26:09 -03:00
Paul Gauthier
77f8be10b1 restore test_cmd_tokens 2023-07-17 16:01:37 -03:00
Paul Gauthier
fd6ceb167c fixed test 2023-07-17 16:00:29 -03:00
Paul Gauthier
8dcff175bc aider: Added a test for cmd_git that creates a temporary git repository, adds a file, runs the cmd_git method with the arguments "commit -a -m msg", and confirms that the file is in the repository.
# Aider chat conversation:

USER: write a test for `cmd_git`. use `GitTemporaryDirectory` to make a temp git repo. add a file. then run `/git commit -a -m msg` and confirm that the file is in the repo

ASSISTANT: To write a test for `cmd_git`, we need to modify the `tests/test_commands.py` file.

Here are the steps we need to follow:

1. Import `GitTemporaryDirectory` from `tests.utils`.
2. Create a new test method `test_cmd_git`.
3. Inside this method, create a temporary git repository using `GitTemporaryDirectory`.
4. Add a file to the repository.
5. Run the `cmd_git` method with the arguments `"commit -a -m msg"`.
6. Check if the file has been committed to the repository.

Here is the *edit block* for these changes:

<source>python
tests/test_commands.py
<<<<<<< ORIGINAL
from unittest import TestCase

from aider import models
from aider.coders import Coder
from aider.commands import Commands
from aider.dump import dump  # noqa: F401
from aider.io import InputOutput
=======
from unittest import TestCase
from tests.utils import GitTemporaryDirectory

from aider import models
from aider.coders import Coder
from aider.commands import Commands
from aider.dump import dump  # noqa: F401
from aider.io import InputOutput
>>>>>>> UPDATED
</source>

<source>python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_tokens(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)

        coder = Coder.create(models.GPT35, None, io)
        commands = Commands(io, coder)

        commands.cmd_add("foo.txt bar.txt")

        # Redirect the standard output to an instance of io.StringIO
        stdout = StringIO()
        sys.stdout = stdout

        commands.cmd_tokens("")

        # Reset the standard output
        sys.stdout = sys.__stdout__

        # Get the console output
        console_output = stdout.getvalue()

        self.assertIn("foo.txt", console_output)
        self.assertIn("bar.txt", console_output)
=======
    def test_cmd_git(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)

        with GitTemporaryDirectory() as tempdir:
            # Create a file in the temporary directory
            with open(f"{tempdir}/test.txt", "w") as f:
                f.write("test")

            coder = Coder.create(models.GPT35, None, io)
            commands = Commands(io, coder)

            # Run the cmd_git method with the arguments "commit -a -m msg"
            commands.cmd_git("commit -a -m msg")

            # Check if the file has been committed to the repository
            repo = git.Repo(tempdir)
            files_in_repo = [item.a_path for item in repo.index.diff(None)]
            self.assertIn("test.txt", files_in_repo)
>>>>>>> UPDATED
</source>
2023-07-17 15:58:28 -03:00
Paul Gauthier
c05efad274 aider: Add a new /git command to run git.
# Aider chat conversation:

USER: Add a new /git command to run git. so you could do `/git commit -a -m "message goes here"` or any other git command. It should work like `cmd_run` but prepends "git" to the `args`. Don't offer to send the output to gpt.

ASSISTANT: To add a new `/git` command, we need to modify the `aider/commands.py` file. We will add a new method `cmd_git` that will prepend "git" to the `args` and run the command. This method will be similar to `cmd_run` but will not offer to send the output to gpt.

Here is the change:

<source>python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_run(self, args):
        "Run a shell command and optionally add the output to the chat"
        combined_output = None
        try:
            parsed_args = shlex.split(args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

        if self.io.confirm_ask("Add the output to the chat?", default="y"):
            for line in combined_output.splitlines():
                self.io.tool_output(line, log_only=True)

            msg = prompts.run_output.format(
                command=args,
                output=combined_output,
            )
            return msg

    def cmd_exit(self, args):
        "Exit the application"
        sys.exit()
=======
    def cmd_git(self, args):
        "Run a git command"
        combined_output = None
        try:
            parsed_args = shlex.split("git " + args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running git command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

    def cmd_run(self, args):
        "Run a shell command and optionally add the output to the chat"
        combined_output = None
        try:
            parsed_args = shlex.split(args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

        if self.io.confirm_ask("Add the output to the chat?", default="y"):
            for line in combined_output.splitlines():
                self.io.tool_output(line, log_only=True)

            msg = prompts.run_output.format(
                command=args,
                output=combined_output,
            )
            return msg

    def cmd_exit(self, args):
        "Exit the application"
        sys.exit()
>>>>>>> UPDATED
</source>
2023-07-17 15:51:14 -03:00
paul-gauthier
f89119696b
Merge pull request #113 from paul-gauthier/gitignore
Try to prevent users from accidentally adding .aider* files to the git repo
2023-07-17 10:59:47 -03:00
Paul Gauthier
72646f9733 use io.read/write text 2023-07-17 10:53:49 -03:00
Paul Gauthier
4b01f20b73 print when greating gitignore 2023-07-17 08:32:32 -03:00
Paul Gauthier
402f8f4971 Merge branch 'main' into gitignore 2023-07-17 08:27:09 -03:00
Paul Gauthier
aff5949d87 Merge remote-tracking branch 'origin/main' 2023-07-17 08:19:30 -03:00
Paul Gauthier
1f07de8670 Added hint to Use --encoding to set the unicode encoding. 2023-07-17 08:19:21 -03:00
paul-gauthier
f1cc8acc0e
Merge pull request #115 from ameramayreh/issue-114
Handled Issue #114
2023-07-17 04:09:40 -07:00
Amer Amayreh
a2d8bed155
Handled Issue #114
Handled the UnboundLocalError tat occurs when wrong prams are passed to the `/run` command
2023-07-17 06:04:47 +03:00
Paul Gauthier
e7692fc9d1 added apt update 2023-07-16 18:27:51 -03:00
Paul Gauthier
9c40fc3415 Path.cwd 2023-07-16 18:27:17 -03:00
Paul Gauthier
6f7936e5f8 Merge branch 'main' into gitignore 2023-07-16 18:06:01 -03:00
Paul Gauthier
d349693205 copy 2023-07-16 17:36:19 -03:00
Paul Gauthier
e7f35e2cf7 Apparently prompt toolkit can not express control-enter? 2023-07-16 14:26:49 -03:00
Paul Gauthier
dbf3b09c06 copy 2023-07-16 14:18:57 -03:00
Paul Gauthier
36af2a51af Change keybinding from ControlJ to ControlM for inserting a new line.
# Aider chat conversation:
2023-07-16 14:15:18 -03:00
Paul Gauthier
6244df8352 aider: get_input now treats control+enter as a newline with prompt toolkit KeyBindings.
# Aider chat conversation:

USER: can we have `get_input` treat control+enter as a newline with prompt toolkit KeyBindings

ASSISTANT: To implement this feature, we need to modify the `get_input` method in the `InputOutput` class in the `aider/io.py` file. We will use the `KeyBindings` class from `prompt_toolkit.keys` to bind the `Control+Enter` key combination to insert a newline.

Here are the changes:

```python
aider/io.py
<<<<<<< ORIGINAL
from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt
=======
from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt
from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding import KeyBindings
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
            session = PromptSession(**session_kwargs)
=======
            kb = KeyBindings()

            @kb.add(Keys.ControlJ, eager=True)
            def _(event):
                event.current_buffer.insert_text('\n')

            session = PromptSession(key_bindings=kb, **session_kwargs)
>>>>>>> UPDATED
```

This code creates a new `KeyBindings` instance and adds a binding for `Control+Enter` (represented by `Keys.ControlJ`) to insert a newline. Then, it passes this key bindings instance to the `PromptSession` constructor.
2023-07-16 14:12:01 -03:00
Paul Gauthier
668b8841e2 outdent toc 2023-07-16 13:56:46 -03:00
Paul Gauthier
7df07c7ae7 aider: Add a table of contents to the docs/install.md file.
# Aider chat conversation:

USER: add a table of contents

ASSISTANT: To add a table of contents to the `docs/install.md` file, we need to add a list of links to the headers in the document.

Here is how to do it:

<source>markdown
docs/install.md
<<<<<<< ORIGINAL
# Installing aider

## pip install aider-chat
=======
# Installing aider

- [Installing aider](#installing-aider)
  - [pip install aider-chat](#pip-install-aider-chat)
  - [Provide your OpenAI API key](#provide-your-openai-api-key)
  - [Install git](#install-git)
  - [Install universal ctags (optional)](#install-universal-ctags-optional)
  - [Add aider to your editor (optional)](#add-aider-to-your-editor-optional)

## pip install aider-chat
>>>>>>> UPDATED
</source>

This change adds a table of contents at the beginning of the document, with links to each of the main sections. The links use the header text, converted to lowercase and with spaces replaced by hyphens, as the target of the link. This is the standard way that markdown generates ids for headers, so these links will jump to the correct section when clicked.
2023-07-16 13:55:10 -03:00
Paul Gauthier
5dc7bc055e Whitelist more /cmds for no dirty commit 2023-07-16 13:42:36 -03:00
Paul Gauthier
180ca7c464 test_main_git_ignore 2023-07-16 12:56:55 -03:00
Paul Gauthier
0f14947a4c test_check_gitignore 2023-07-16 12:49:27 -03:00
Paul Gauthier
1e0443cc86 better test 2023-07-16 12:36:19 -03:00
Paul Gauthier
7d8069d778 test_setup_git works 2023-07-16 12:33:56 -03:00
Paul Gauthier
7096f7287c simplify with make_repo 2023-07-16 12:30:40 -03:00
Paul Gauthier
108abe4a49 aider: Replace all subprocess.run(git calls that are making new repos and setting config with make_repo calls.
# Aider chat conversation:

USER: replace all the `subprocess.run(git` calls that are making new repos and setting config with `make_repo` calls

ASSISTANT: To replace all the `subprocess.run(git` calls that are making new repos and setting config with `make_repo` calls, we need to modify the `tests/test_main.py` file.

Here are the changes:

```python
tests/test_main.py
<<<<<<< ORIGINAL
        subprocess.run(["git", "init"])
        subprocess.run(["git", "config", "user.email", "dummy@example.com"])
        subprocess.run(["git", "config", "user.name", "Dummy User"])
=======
        from tests.utils import make_repo
        make_repo()
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
        subprocess.run(["git", "init"])
        subprocess.run(["git", "config", "user.email", "dummy@example.com"])
        subprocess.run(["git", "config", "user.name", "Dummy User"])
=======
        from tests.utils import make_repo
        make_repo()
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
        subprocess.run(["git", "init"])
        subprocess.run(["git", "config", "user.email", "dummy@example.com"])
        subprocess.run(["git", "config", "user.name", "Dummy User"])
=======
        from tests.utils import make_repo
        make_repo()
>>>>>>> UPDATED
```

Please note that you need to import the `make_repo` function from `tests.utils` in each test where it's used.
2023-07-16 12:26:31 -03:00
Paul Gauthier
611e21e457 Merge branch 'main' into gitignore 2023-07-16 12:25:23 -03:00
Paul Gauthier
4447f61dc6 refac make_repo 2023-07-16 12:25:18 -03:00