Commit graph

2505 commits

Author SHA1 Message Date
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
Paul Gauthier
67554196f3 Merge branch 'main' into gitignore 2023-07-16 12:21:16 -03:00
Paul Gauthier
10b327d487 copy 2023-07-16 12:21:01 -03:00
Paul Gauthier
bcbfa0babd copy 2023-07-16 12:20:03 -03:00
Paul Gauthier
4b8211554a set version to 0.9.0-dev 2023-07-16 09:47:35 -03:00
Paul Gauthier
a57c651c05 version bump to 0.9.0 2023-07-16 09:47:24 -03:00
Paul Gauthier
a3f3a18ee0 Updated HISTORY 2023-07-16 09:47:03 -03:00
Paul Gauthier
a9cca05680 Added GitTemporaryDirectory 2023-07-16 09:39:07 -03:00
Paul Gauthier
86cea01434 aider: Change the relative import to an absolute import for the IgnorantTemporaryDirectory class in test_repomap.py.
# Aider chat conversation:

USER: ImportError: Failed to import test module: test_repomap
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/aider/aider/tests/test_repomap.py", line 8, in <module>
    from .utils import IgnorantTemporaryDirectory
ImportError: attempted relative import with no known parent package

ASSISTANT: The error message indicates that Python is unable to find the `utils` module when it's being imported in `test_repomap.py`. This is because the import statement is using a relative import with the dot (`.`) prefix, which is not working in this context.

To fix this, we need to change the relative import to an absolute import. This means we need to specify the full path to the `utils` module from the project's root directory.

Here is the change you need to make:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
from .utils import IgnorantTemporaryDirectory
=======
from tests.utils import IgnorantTemporaryDirectory
>>>>>>> UPDATED
```

This change tells Python to import the `IgnorantTemporaryDirectory` class from the `utils` module located in the `tests` directory, which is an absolute path from the project's root directory.
2023-07-16 09:05:18 -03:00
Paul Gauthier
cdf35cd122 refac 2023-07-16 09:02:35 -03:00
Paul Gauthier
50c8a96edd wip 2023-07-16 08:18:05 -03:00
Paul Gauthier
c8d69f84ce aider: Add test for setup_git function.
# Aider chat conversation:

USER: add tests for `setup_git`

ASSISTANT: To add tests for the `setup_git` function, we need to modify the `tests/test_main.py` file. We will add a new test function `test_setup_git` in the `TestMain` class.

Here is the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_args(self):
        with patch("aider.main.Coder.create") as MockCoder:
            # --yes will just ok the git repo without blocking on input
            # following calls to main will see the new repo already
            main(["--no-auto-commits", "--yes"], input=DummyInput())
            _, kwargs = MockCoder.call_args
            assert kwargs["auto_commits"] is False
=======
    def test_main_args(self):
        with patch("aider.main.Coder.create") as MockCoder:
            # --yes will just ok the git repo without blocking on input
            # following calls to main will see the new repo already
            main(["--no-auto-commits", "--yes"], input=DummyInput())
            _, kwargs = MockCoder.call_args
            assert kwargs["auto_commits"] is False

    def test_setup_git(self):
        with patch("aider.main.git.Repo.init") as MockRepoInit:
            MockRepoInit.return_value = git.Repo(self.tempdir)
            git_root = setup_git(None, self.io)
            self.assertEqual(git_root, self.tempdir)
            MockRepoInit.assert_called_once_with(self.tempdir)
>>>>>>> UPDATED
```

In the new test `test_setup_git`, we are mocking the `git.Repo.init` function to return a git repository at `self.tempdir`. Then we call `setup_git` with `None` as the `git_root` and check if it returns `self.tempdir` as the new `git_root`. We also check if `git.Repo.init` was called once with `self.tempdir` as the argument.
2023-07-15 13:37:39 -07:00
Paul Gauthier
b0ec8205f3 Add pattern to .gitignore if user confirms, by appending it to the existing content of the file.
# Aider chat conversation:
2023-07-15 13:36:57 -07:00
Paul Gauthier
c08527dbbc refac; added check_gitignore 2023-07-15 13:34:58 -07:00