Commit graph

3031 commits

Author SHA1 Message Date
Paul Gauthier
98bacd0b5b test case and fix for /add blowing up in subdir #201 2023-09-29 10:49:27 -07:00
Paul Gauthier
545f10551e Show supported models when avail check fails 2023-09-29 09:20:36 -07:00
Paul Gauthier
82d7f04865 handle the case of no git repo 2023-09-27 18:37:26 -07:00
Paul Gauthier
1d0d91d71e improved gitignore check logic 2023-09-27 18:32:18 -07:00
Paul Gauthier
19e4787502 aider: Refactored check_gitignore function to use gitpython library to check if the .aider pattern is already ignored by the repository before adding it to .gitignore.
# Aider chat conversation:

USER: in `check_gitignore` use gitpython to see if the repo is already ignoring `.aider`. if so, don't add anything to gitignore

ASSISTANT: To implement this change, we need to modify the `check_gitignore` function in the `aider/main.py` file. We will use the `gitpython` library to check if the `.aider` pattern is already ignored by the repository. If it is, we won't add anything to the `.gitignore` file.

Here are the steps we need to take:

1. Import the `git` module at the top of the file.
2. In the `check_gitignore` function, create a `git.Repo` object for the current repository.
3. Use the `Repo.ignored` method to check if the `.aider` pattern is already ignored.
4. Only add the `.aider` pattern to the `.gitignore` file if it's not already ignored.

Here is the *edit block* for this change:

```python
aider/main.py
<<<<<<< HEAD
def check_gitignore(git_root, io, ask=True):
    if not git_root:
        return

    pat = ".aider*"

    gitignore_file = Path(git_root) / ".gitignore"
    if gitignore_file.exists():
        content = io.read_text(gitignore_file)
        if pat in content.splitlines():
            return
    else:
        content = ""

    if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
        return

    if content and not content.endswith("\n"):
        content += "\n"
    content += pat + "\n"
    io.write_text(gitignore_file, content)

    io.tool_output(f"Added {pat} to .gitignore")
=======
import git

def check_gitignore(git_root, io, ask=True):
    if not git_root:
        return

    pat = ".aider*"

    gitignore_file = Path(git_root) / ".gitignore"
    if gitignore_file.exists():
        content = io.read_text(gitignore_file)
        if pat in content.splitlines():
            return
    else:
        content = ""

    repo = git.Repo(git_root)
    if repo.is_ignored(pat):
        return

    if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
        return

    if content and not content.endswith("\n"):
        content += "\n"
    content += pat + "\n"
    io.write_text(gitignore_file, content)

    io.tool_output(f"Added {pat} to .gitignore")
>>>>>>> updated
```
Please note that this change assumes that the `gitpython` library is already installed in your environment. If it's not, you will need to install it using pip (`pip install gitpython`).
2023-09-27 18:30:26 -07:00
Paul Gauthier
14eb12364d aider: Add --gitignore/--no-gitignore switches (like the others) default is true, only call check_gitignore if it's true.
# Aider chat conversation:

USER: add --gitignore/--no-gitignore switches (like the others) default is true. only call `check_gitignore` if it's true.

ASSISTANT: To add the `--gitignore/--no-gitignore` switches, we need to modify the `aider/main.py` file.

Here are the steps:

1. Add a new argument to the `git_group` in the `main` function to handle the `--gitignore/--no-gitignore` switches.
2. Modify the `if args.git:` block to only call `check_gitignore` if `args.gitignore` is `True`.

Here are the proposed changes:

```python
aider/main.py
<<<<<<< HEAD
    git_group = parser.add_argument_group("Git Settings")
    git_group.add_argument(
        "--git",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable looking for a git repo (default: True)",
    )
    git_group.add_argument(
        "--auto-commits",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable auto commit of GPT changes (default: True)",
    )
    git_group.add_argument(
        "--dirty-commits",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable commits when repo is found dirty (default: True)",
    )
    git_group.add_argument(
        "--dry-run",
        action=argparse.BooleanOptionalAction,
        default=False,
        help="Enable/disable performing a dry run without modifying files (default: False)",
    )
=======
    git_group = parser.add_argument_group("Git Settings")
    git_group.add_argument(
        "--git",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable looking for a git repo (default: True)",
    )
    git_group.add_argument(
        "--gitignore",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable adding .aider* to .gitignore (default: True)",
    )
    git_group.add_argument(
        "--auto-commits",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable auto commit of GPT changes (default: True)",
    )
    git_group.add_argument(
        "--dirty-commits",
        action=argparse.BooleanOptionalAction,
        default=True,
        help="Enable/disable commits when repo is found dirty (default: True)",
    )
    git_group.add_argument(
        "--dry-run",
        action=argparse.BooleanOptionalAction,
        default=False,
        help="Enable/disable performing a dry run without modifying files (default: False)",
    )
>>>>>>> updated
```

```python
aider/main.py
<<<<<<< HEAD
    if args.git:
        git_root = setup_git(git_root, io)
        check_gitignore(git_root, io)
=======
    if args.git:
        git_root = setup_git(git_root, io)
        if args.gitignore:
            check_gitignore(git_root, io)
>>>>>>> updated
```
2023-09-27 16:24:43 -07:00
Paul Gauthier
6a7fd93580 copy 2023-09-27 10:20:59 -07:00
Paul Gauthier
2ec453ab2a copy 2023-09-27 10:17:19 -07:00
Paul Gauthier
6d5827643f don't try and commit unless there are changes #264 2023-09-25 14:55:00 -07:00
Paul Gauthier
7910c2f731 copy 2023-09-25 12:25:22 -07:00
paul-gauthier
ede5bd4bf0
Merge pull request #254 from fahmad91/main 2023-09-18 18:00:51 -07:00
Farhan Ahmad
7137b29744 Moved instructions from README.md into FAQs section. 2023-09-18 15:04:00 -04:00
Farhan Ahmad
e255b2f500 Removed .gitignore from repo 2023-09-18 14:41:46 -04:00
Farhan Ahmad
b7e3911afc aider: Updated the instructions for running the project locally.
# Aider chat conversation:

USER: update the instruction for running locally to include step by step instructions like cloning the repo / creating a fork. Switch to the correct directly. Install all the dependencies inside `requirements.txt` file using pip install -r. and finally running the program using python -m aider.main

ASSISTANT: To update the instructions for running the project locally, we need to modify the README.md file.

Here are the changes:

<source>markdown
README.md
<<<<<<< HEAD
## Running Locally

After cloning the repository or creating your fork, you can run the local version of Aider using the following command:

```
python -m aider.main
```
=======
## Running Locally

To run the project locally, follow these steps:

1. Clone the repository or create your fork:

```
git clone https://github.com/your-username/aider.git
```

2. Navigate to the project directory:

```
cd aider
```

3. Install the dependencies listed in the `requirements.txt` file:

```
pip install -r requirements.txt
```

4. Run the local version of Aider:

```
python -m aider.main
```
>>>>>>> updated
</source>
2023-09-16 15:45:46 -04:00
Farhan Ahmad
53c467ae88 Updated gitignore 2023-09-16 15:41:42 -04:00
Farhan Ahmad
8bac324b0f aider: Add instructions for running the project locally.
# Aider chat conversation:

USER: Update the readme to include instruction for running the project locally after closing the repo or creating your fork. Make sure to mention how you will go about running the local version aider by using the following command: python -m aider.main

ASSISTANT: To add instructions for running the project locally, we need to modify the README.md file.

Here are the changes:

<source>markdown
README.md
<<<<<<< HEAD
## Installation

See the [installation instructions](https://aider.chat/docs/install.html).
=======
## Installation

See the [installation instructions](https://aider.chat/docs/install.html).

## Running Locally

After cloning the repository or creating your fork, you can run the local version of Aider using the following command:

```
python -m aider.main
```
>>>>>>> updated
</source>
2023-09-16 15:40:05 -04:00
paul-gauthier
93184d1fc2
Merge pull request #250 from joshuavial/fix-benchmark 2023-09-08 17:18:21 -07:00
Joshua Vial
9a91d8fbad set git config safe dir in benchmark docker 2023-09-09 12:07:11 +12:00
paul-gauthier
e073d6901b
Merge pull request #234 from Taik/main 2023-09-08 17:07:02 -07:00
Joshua Vial
91b7648f33 update model creation method 2023-09-09 12:06:34 +12:00
Thinh Nguyen
2f835e9c46
Add default value for skip_model_availabily_check 2023-09-08 16:09:35 -07:00
Thinh Nguyen
45298f8af6
Add option to skip model availability check 2023-09-08 14:04:02 -07:00
Paul Gauthier
2a8c7ef70d set version to 0.14.1-dev 2023-09-08 09:54:43 -07:00
Paul Gauthier
f852bcabcd version bump to 0.14.0 2023-09-08 09:54:15 -07:00
Paul Gauthier
68e3d98f24 Updated HISTORY 2023-09-08 09:53:52 -07:00
Paul Gauthier
aee1338670 copy 2023-09-08 09:49:58 -07:00
Paul Gauthier
239fb92563 Merge remote-tracking branch 'origin/main' 2023-09-08 09:13:07 -07:00
Paul Gauthier
491993f979 Added a benchmarking readme 2023-09-08 09:12:34 -07:00
paul-gauthier
7ba70632e8
Merge pull request #244 from joshuavial/fix-openrouter-token-usage
only show token costs if usage exists
2023-09-08 08:37:09 -07:00
Paul Gauthier
ad3eeca80e Added __all__ to models/__init__ 2023-09-08 08:28:12 -07:00
Paul Gauthier
bfbd7b8416 Merge remote-tracking branch 'origin/main' 2023-09-08 08:26:23 -07:00
Paul Gauthier
4347823c36 improved debug main() func 2023-09-08 08:26:06 -07:00
Joshua Vial
166984e94a only show token costs if usage exists 2023-09-08 11:49:41 +12:00
paul-gauthier
93ea45f588
Merge pull request #241 from joshuavial/fix-231 2023-09-06 16:29:03 -07:00
Joshua Vial
98097005c7 small fix for better error handling if the summarizer ever fails
- fix #231
2023-09-06 15:03:54 +12:00
Paul Gauthier
fb5616f854 aider: Updated the tags based on the grammar.
# Aider chat conversation:

USER: update the tags based on the grammar

ASSISTANT: No changes are needed.
2023-09-01 16:14:01 -07:00
Paul Gauthier
aac393f12a aider: Added queries for functions, structs, unions, and enums in the tree-sitter-c-tags.scm file.
# Aider chat conversation:

USER: I did `git reset --hard HEAD~1` to discard the last edits.

ASSISTANT: Alright. If you have any other requests or need further assistance, feel free to ask.

USER: make tags queries for the c language, following the conventions used in the c-sharp tags file. like the example, only tag definitions of *named code*, like functions, methods, classes, modules. not types, etc.

ASSISTANT: To create tags queries for the C language, we need to follow the conventions used in the C# tags file. We will create a new file named `tree-sitter-c-tags.scm` in the `aider/queries` directory.

The C language has different constructs compared to C#, so we will need to adjust the queries accordingly. For example, C doesn't have classes or interfaces, but it does have structs and unions. Also, C doesn't have namespaces, but it does have functions and variables at the global scope.

Here is the proposed content for the new file:

```scheme
aider/queries/tree-sitter-c-tags.scm
<<<<<<< HEAD
=======
(translation_unit
  (function_definition
    declarator: (function_declarator
      declarator: (identifier) @name.definition.function
    )
  ) @definition.function

  (struct_specifier
    name: (type_identifier) @name.definition.struct
  ) @definition.struct

  (union_specifier
    name: (type_identifier) @name.definition.union
  ) @definition.union

  (enum_specifier
    name: (type_identifier) @name.definition.enum
  ) @definition.enum
)
>>>>>>> updated
```

This file includes queries for functions, structs, unions, and enums. Please note that these are just the basic constructs and you might need to add more queries depending on your needs.
2023-09-01 16:02:55 -07:00
Paul Gauthier
c9685ebca1 Merge branch 'main' into sitter-map 2023-09-01 15:56:20 -07:00
Paul Gauthier
9b22b39a8d lint 2023-09-01 15:55:36 -07:00
Paul Gauthier
3045c5e94d aider: Removed unused imports and changed comparison to None to use is instead of == in aider/history.py, aider/models/__init__.py, and aider/models/openrouter.py.
# Aider chat conversation:

USER: I ran this command:

 pre-commit run --all-files

And got this output:

isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

aider/history.py:4:1: F401 'tiktoken' imported but unused
import tiktoken
^
aider/models/__init__.py:2:1: F401 '.openai.OpenAIModel' imported but unused
from .openai import OpenAIModel
^
aider/models/__init__.py:3:1: F401 '.openrouter.OpenRouterModel' imported but unused
from .openrouter import OpenRouterModel
^
aider/models/openrouter.py:26:33: E711 comparison to None should be 'if cond is None:'
        if cached_model_details == None:
                                ^

ASSISTANT: It seems like there are some unused imports and a comparison to None that is not following the Pythonic way. To fix these issues, we need to modify the following files:

1. `aider/history.py`
2. `aider/models/__init__.py`
3. `aider/models/openrouter.py`

Please add these files to the chat so I can propose the necessary changes.

USER: I added these *read-write* files: aider/history.py, aider/models/openrouter.py, aider/models/__init__.py

ASSISTANT: Great! Now, let's make the necessary changes to these files.

First, in `aider/history.py`, we need to remove the unused import `tiktoken`.

```python
aider/history.py
<<<<<<< HEAD
import tiktoken
=======
>>>>>>> updated
```

Next, in `aider/models/__init__.py`, we need to remove the unused imports `OpenAIModel` and `OpenRouterModel`.

```python
aider/models/__init__.py
<<<<<<< HEAD
from .openai import OpenAIModel
from .openrouter import OpenRouterModel
=======
>>>>>>> updated
```

Finally, in `aider/models/openrouter.py`, we need to change the comparison to None to use `is` instead of `==`.

```python
aider/models/openrouter.py
<<<<<<< HEAD
        if cached_model_details == None:
=======
        if cached_model_details is None:
>>>>>>> updated
```

These changes should resolve the issues reported by the `flake8` linter.
2023-09-01 15:54:22 -07:00
Paul Gauthier
1334392418 lint 2023-09-01 15:53:19 -07:00
Paul Gauthier
0de722a7b3 lint 2023-09-01 15:52:56 -07:00
Paul Gauthier
427c9129a4 ssh 2023-09-01 15:52:27 -07:00
Paul Gauthier
a5e84a5302 fixed inclusion of queries for package 2023-09-01 14:14:47 -07:00
Paul Gauthier
6c5208246c aider: Fixed the queries directory not being included in the package by moving it inside the aider package and adjusting the package_data argument in the setup.py file.
# Aider chat conversation:

ASSISTANT: The `queries` directory might not be included in the package because it's not specified correctly in the `setup.py` file.

In the `setup.py` file, you have specified `package_data={'': ['queries/*']}`. This means that setuptools will include all files in the `queries` directory that are inside any package. However, if the `queries` directory is not inside a Python package (i.e., a directory containing an `__init__.py` file), it will not be included.

To fix this, you need to move the `queries` directory inside the `aider` package and adjust the `package_data` argument in the `setup.py` file. Here's how you can do it:

```python
setup.py
<<<<<<< HEAD
    package_data={
        '': ['queries/*'],
    },
=======
    package_data={
        'aider': ['queries/*'],
    },
>>>>>>> updated
```

This code changes the `package_data` argument to include all files in the `queries` directory that is inside the `aider` package.

After making this change, you need to move the `queries` directory inside the `aider` package. If the `queries` directory is currently in the same directory as the `setup.py` file, you can do this by running `mv queries aider/` in the terminal.

Finally, you need to adjust the `scm_fname` assignment in the `repomap.py` file to reflect the new location of the `queries` directory:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm")
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("queries", f"tree-sitter-{lang}-tags.scm")
        )
>>>>>>> updated
```

This code changes the path in the `resource_filename` call to look for the `queries` directory inside the `aider` package.
2023-09-01 14:14:05 -07:00
Paul Gauthier
7b95aef9d6 Add a debug statement to dump the scm filename. 2023-09-01 14:14:03 -07:00
Paul Gauthier
72d6afc470 aider: Imported pkg_resources module in repomap.py.
# Aider chat conversation:

USER:   File "/Users/gauthier/tmp/queries/.venv/lib/python3.11/site-packages/aider/repomap.py", line 180, in get_tags
    scm_fname = pkg_resources.resource_filename(
                ^^^^^^^^^^^^^
NameError: name 'pkg_resources' is not defined

ASSISTANT: The error message indicates that the `pkg_resources` module is not imported in the `repomap.py` file. This module is part of setuptools and is used to access files included in the package.

To fix this, you need to import the `pkg_resources` module at the beginning of the `repomap.py` file. Here's how you can do it:

```python
aider/repomap.py
<<<<<<< HEAD
import colorsys
import os
import random
import sys
from collections import Counter, defaultdict, namedtuple
from pathlib import Path
=======
import colorsys
import os
import pkg_resources
import random
import sys
from collections import Counter, defaultdict, namedtuple
from pathlib import Path
>>>>>>> updated
```

This code adds the `import pkg_resources` line right after the `import os` line.
2023-09-01 14:11:19 -07:00
Paul Gauthier
9d9ea5c4a8 aider: Refactor the scm_fname assignment in repomap.py to use os.path.join for Windows safety.
# Aider chat conversation:

USER: that's not windows safe is it?

ASSISTANT: You're correct. The use of `..` to refer to the parent directory is not Windows safe. On Windows, the path separator is `\` instead of `/`. However, Python's `os` and `os.path` modules provide functions that handle paths in a way that is safe for both Unix and Windows.

You can use `os.path.join` to construct the path to the scm file. This function takes care of using the correct path separator for the current operating system.

Here's how you can modify the `scm_fname` assignment in `repomap.py`:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, f"../queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm")
        )
>>>>>>> updated
```

This code will work correctly on both Unix and Windows.
2023-09-01 14:08:59 -07:00
Paul Gauthier
b587685dc6 aider: Adjusted path in repomap.py to correctly locate the queries directory in the parent directory.
# Aider chat conversation:

USER: the queries directory is currently in the parent dir of repomap.py. what should i do?

ASSISTANT: If the `queries` directory is in the parent directory of `repomap.py`, you need to adjust the path in the `resource_filename` call accordingly.

You can use `..` to refer to the parent directory. Here's how you can modify the `scm_fname` assignment in `repomap.py`:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, f"queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, f"../queries/tree-sitter-{lang}-tags.scm"
        )
>>>>>>> updated
```

Please note that this assumes that the `queries` directory is directly in the parent directory of `repomap.py`. If it's in a different location, you'll need to adjust the path accordingly.
2023-09-01 14:08:35 -07:00
Paul Gauthier
7b77dbb88d aider: Updated package data to include the queries directory and modified repomap.py to use pkg_resources to access the scm files at runtime.
# Aider chat conversation:

USER: the `scm_fname` is using a path in my local filesystem. how do i package up the queries directory for pip install in a way that the script can find those scm files at runtime

ASSISTANT: To package the queries directory for pip install, you need to include it in your package data in the `setup.py` file. This will ensure that the directory is included when your package is installed.

Then, you can use the `pkg_resources` module to access the files at runtime. This module is part of `setuptools`, so it's already installed if you're using pip.

Here are the steps:

1. Modify `setup.py` to include the queries directory in the package data.

```python
setup.py
<<<<<<< HEAD
    packages=find_packages(),
    include_package_data=True,
=======
    packages=find_packages(),
    include_package_data=True,
    package_data={
        '': ['queries/*'],
    },
>>>>>>> updated
```

2. Modify `aider/repomap.py` to use `pkg_resources` to access the scm files at runtime.

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = (
            f"/Users/gauthier/tmp/py-tree-sitter-languages/queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, f"queries/tree-sitter-{lang}-tags.scm"
        )
>>>>>>> updated
```

Please note that the `queries` directory should be in the same directory as the `repomap.py` file for this to work. If it's in a different location, you'll need to adjust the path in the `resource_filename` call accordingly.
2023-09-01 14:06:51 -07:00