Commit graph

169 commits

Author SHA1 Message Date
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
Paul Gauthier
fa6ae80653 Merge branch 'main' into sitter-map 2023-09-01 12:00:48 -07:00
Joshua Vial
abbc93678b finishing openrouter integration 2023-08-23 21:26:27 +12:00
JV
041f3a4a38 initial code for working with openrouter 2023-08-23 14:39:12 +12:00
Paul Gauthier
6b41581f91 added header_max, more whitespace 2023-08-22 07:45:06 -07:00
Paul Gauthier
057aa0a736 prettier 2023-08-20 15:11:12 -07:00
Paul Gauthier
189446b04e roughed in tree-sitter 2023-08-20 14:11:06 -07:00
Paul Gauthier
de0cfe4d39 refac to remove ctags 2023-08-19 19:24:42 -07:00
Paul Gauthier
f26e40d48e Skip non-files when building repomap #174 2023-08-08 12:02:40 -03:00
Paul Gauthier
3ef16827fc show a progress bar if there are on tags/idents caches 2023-08-03 12:07:53 -03:00
Paul Gauthier
b685695fef Anchor the cache to the project root 2023-07-13 14:01:07 -07:00
Paul Gauthier
7c0ac4d92f Tell git to stop quoting the paths in ls-files 2023-07-11 08:12:44 -07:00
Paul Gauthier
fe959be85d Pass unicode encodings into ctags 2023-07-07 15:08:40 -07:00
Paul Gauthier
fb5af6ec8b catch and report json errors parsing ctags output #63 2023-07-07 09:54:50 -07:00
Paul Gauthier
c8fb1ddaa7 refactor to use io.read_text 2023-07-05 20:46:15 -07:00
Paul Gauthier
1f16b15f92 Added more clear error messages when universal-ctags is disabled per issue #31 2023-07-03 10:31:04 -07:00
Paul Gauthier
ce8069196c Improve messaging about universal ctags 2023-06-14 16:12:51 -07:00
Paul Gauthier
be34086ac0 aider: Captured stdout/err in check_for_ctags subprocess call.
# Context:
USER: in `check_for_ctags` capture stdout/err so they aren't displayed
ASSISTANT: No changes are needed.
2023-06-14 15:58:47 -07:00
Paul Gauthier
07c5c7f477 Update debugging main in repomap 2023-06-07 14:57:57 -07:00
Paul Gauthier
a874d617d3 rename 2023-06-07 12:29:51 -07:00
Paul Gauthier
9cef379abd refac 2023-06-07 12:28:45 -07:00
Paul Gauthier
fcd8a6df73 Use the Models enum instead of .value 2023-06-05 17:06:34 -07:00
Paul Gauthier
95b32a74a9 Moved all model names into an enum 2023-06-05 09:19:29 -07:00
Paul Gauthier
efb8cad881 Merge branch 'main' into gpt-35 2023-06-05 09:07:03 -07:00
Paul Gauthier
4121b9900e aider: Added cache versioning to RepoMap class.
# Context:
USER: is there a standard way to version these cache files?
ASSISTANT: Yes, a standard way to version cache files is to include a version number in the cache file name or within the cache data. This allows you to easily identify and manage different versions of the cache, and update the cache handling logic when needed.

Here's how you can implement cache versioning in your `RepoMap` class:

1. Add a constant for the cache version at the beginning of the class.
2. Modify the cache directory names to include the version number.
3. When loading the cache, check if the version matches the current version. If not, clear the cache and start fresh.

Here are the changes you need to make in `aider/repomap.py`:

```python
aider/repomap.py
<<<<<<< ORIGINAL
class RepoMap:
    ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
    IDENT_CACHE_DIR = ".aider.ident.cache"
    TAGS_CACHE_DIR = ".aider.tags.cache"
=======
class RepoMap:
    CACHE_VERSION = 1
    ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
    IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}"
    TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}"
>>>>>>> UPDATED
```

Now, whenever you need to change the cache format or handling logic, you can simply increment the `CACHE_VERSION` constant, and the cache will be automatically invalidated and recreated with the new version.
2023-06-05 08:30:00 -07:00
Paul Gauthier
baa08e12f8 ssh 2023-06-05 08:29:30 -07:00
Paul Gauthier
27db4c038f bugfix 2023-06-05 08:29:08 -07:00
Paul Gauthier
93ca588bab sssh 2023-06-05 08:24:02 -07:00
Paul Gauthier
0256b8e260 Merge branch 'call-graph' into gpt-35 2023-06-04 15:03:46 -07:00
Paul Gauthier
53e8c65745 Return files without any tags at all at the tail of the ranked_tags list 2023-06-04 14:53:14 -07:00
Paul Gauthier
dfcf813ad6 include individual files in the ranked tags list, following specific ranked idents 2023-06-04 14:45:57 -07:00
Paul Gauthier
b339df3f70 Merge branch 'call-graph' into gpt-35 2023-06-04 14:28:28 -07:00
Paul Gauthier
95cb482938 bugfix 2023-06-04 14:13:56 -07:00
Paul Gauthier
9088d139b2 refactor prompts 2023-06-04 11:36:50 -07:00
Paul Gauthier
12512df707 Handle the case where there is no rank flow 2023-06-04 09:53:09 -07:00
Paul Gauthier
91f48dfdf1 aider: Added a check for an empty tags list in to_tree function.
# Context:
USER:  File "/Users/gauthier/Projects/aider/aider/repomap.py", line 107, in choose_files_listing
    files_listing = self.get_ranked_tags_map(chat_files, other_files)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/repomap.py", line 318, in get_ranked_tags_map
    tree = to_tree(ranked_tags[:middle])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/repomap.py", line 26, in to_tree
    last = [None] * len(tags[0])
                        ~~~~^^^
ASSISTANT: I see the code snippets from the `aider/repomap.py` file. Please let me know what changes you would like to make, and make sure to provide me with the *read-write* access to the file.
USER: I added these *read-write* files: aider/repomap.py
ASSISTANT: Great! Now, please let me know what changes you would like to make in the `aider/repomap.py` file.
USER:   File "/Users/gauthier/Projects/aider/aider/repomap.py", line 318, in get_ranked_tags_map
    tree = to_tree(ranked_tags[:middle])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/repomap.py", line 26, in to_tree
    last = [None] * len(tags[0])
                        ~~~~^^^
IndexError: list index out of range
ASSISTANT: It seems like you are encountering an IndexError due to an empty `tags` list. To fix this issue, you can add a check to ensure that the `tags` list is not empty before accessing its elements. Here's the change you need to make in the `aider/repomap.py` file:

```python
aider/repomap.py
<<<<<<< ORIGINAL
def to_tree(tags):
    tags = sorted(tags)

    output = ""
    last = [None] * len(tags[0])
=======
def to_tree(tags):
    if not tags:
        return ""

    tags = sorted(tags)

    output = ""
    last = [None] * len(tags[0])
>>>>>>> UPDATED
```

This change adds a check for an empty `tags` list and returns an empty string if the list is empty, preventing the IndexError.
2023-06-04 06:43:30 -07:00
Paul Gauthier
b4fc6c2caa sssh 2023-06-03 18:11:45 -07:00
Paul Gauthier
ef22f44d19 final details on --map-tokens 2023-06-03 18:06:14 -07:00
Paul Gauthier
1f9e9be64d aider: Replaced use_ctags with map_tokens parameter in RepoMap class.
# Context:
USER: update `aider/repomap.py`
ASSISTANT: Please provide the specific changes you would like me to make in the `aider/repomap.py` file.
USER: to use map_tokens not `use_ctags`
ASSISTANT: I will update the `aider/repomap.py` file to use `map_tokens` instead of `use_ctags`.

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def __init__(self, use_ctags=None, root=None, main_model="gpt-4", io=None):
        self.io = io

        if not root:
            root = os.getcwd()
        self.root = root

        self.load_ident_cache()
        self.load_tags_cache()

        if use_ctags is None:
            self.use_ctags = self.check_for_ctags()
        else:
            self.use_ctags = use_ctags

        self.tokenizer = tiktoken.encoding_for_model(main_model)
=======
    def __init__(self, map_tokens=1024, root=None, main_model="gpt-4", io=None):
        self.io = io

        if not root:
            root = os.getcwd()
        self.root = root

        self.load_ident_cache()
        self.load_tags_cache()

        self.map_tokens = map_tokens

        self.tokenizer = tiktoken.encoding_for_model(main_model)
>>>>>>> UPDATED
```

This change replaces the `use_ctags` parameter with the `map_tokens` parameter in the `__init__` method of the `RepoMap` class. Make sure to update any other parts of the code that use `use_ctags` to use `map_tokens` instead.
2023-06-03 17:48:45 -07:00
Paul Gauthier
575c6e2db6 Stop closing 2023-06-02 16:40:21 -07:00
Paul Gauthier
c5ed12e0c3 aider: Replaced shelve with diskcache for persistent dictionary-like object.
# Context:
USER: is there another persistent dictionary besides shelve?
ASSISTANT: Yes, there are several alternatives to `shelve` for creating persistent dictionaries in Python. Some popular options include:

1. `pickle`: A built-in Python module for object serialization and deserialization. You can use it to store dictionaries in binary format and load them back into memory when needed.

2. `json`: Another built-in Python module for working with JSON data. You can use it to store dictionaries in a human-readable format and load them back into memory when needed.

3. `sqlite3`: A built-in Python module for working with SQLite databases. You can use it to create a simple key-value store with SQL queries.

4. `TinyDB`: A lightweight, document-oriented database for Python
^C KeyboardInterrupt
USER: i want something which presents as a dict though
ASSISTANT: In that case, you can use the `sqlite3` module to create a custom class that behaves like a dictionary. Here's an example of how you can create a persistent dictionary using SQLite:

```python
import sqlite3

class
^C KeyboardInterrupt
USER: i don't want to build something. i want an existing package.
ASSISTANT: I apologize for the confusion. In that case, you can use the `diskcache` package, which provides a dictionary-like interface for disk-based storage. It is easy to use and has good performance.

To install `diskcache`, you can use pip:

```
pip install diskcache
```

Here's an example of how to use `diskcache`:

```python
from diskcache import Cache

cache = Cache('path/to/cache/directory')

# Set a key-value pair
cache['key'] = 'value'

# Get the value for a key
value = cache['key']

# Check if a key is in the cache
if 'key' in cache:
    print('Key exists')

# Delete a key-value pair
del cache['key']

# Close the cache when done
cache.close()
```

This will create a persistent dictionary-like object using the `diskcache` package. The data will be stored on disk in the specified directory, and you can use the standard dictionary methods to interact with it.
USER: great. use that.
ASSISTANT: To use `diskcache` in the `aider/repomap.py` file, you'll need to replace the `shelve` usage with `diskcache`. Here are the changes you need to make:

1. Install `diskcache` using pip:

```
pip install diskcache
```

2. Modify the `aider/repomap.py` file:

```python
aider/repomap.py
<<<<<<< ORIGINAL
import colorsys
import json
import os
import random
import subprocess
import sys
import tempfile
from collections import Counter, defaultdict

# import shelve
=======
import colorsys
import json
import os
import random
import subprocess
import sys
import tempfile
from collections import Counter, defaultdict
from diskcache import Cache

>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    IDENT_CACHE_FILE = ".aider.ident.cache"
    TAGS_CACHE_FILE = ".aider.tags.cache"
=======
    IDENT_CACHE_DIR = ".aider.ident.cache"
    TAGS_CACHE_DIR = ".aider.tags.cache"
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def load_tags_cache(self):
        self.TAGS_CACHE = dict()  # shelve.open(self.TAGS_CACHE_FILE)

    def save_tags_cache(self):
        # self.TAGS_CACHE.sync()
        pass

    def load_ident_cache(self):
        self.IDENT_CACHE = dict()  # shelve.open(self.IDENT_CACHE_FILE)

    def save_ident_cache(self):
        # self.IDENT_CACHE.sync()
        pass
=======
    def load_tags_cache(self):
        self.TAGS_CACHE = Cache(self.TAGS_CACHE_DIR)

    def save_tags_cache(self):
        self.TAGS_CACHE.close()

    def load_ident_cache(self):
        self.IDENT_CACHE = Cache(self.IDENT_CACHE_DIR)

    def save_ident_cache(self):
        self.IDENT_CACHE.close()
>>>>>>> UPDATED
```

These changes will replace the usage of `shelve` with `diskcache` for the `IDENT_CACHE` and `TAGS_CACHE` dictionaries. Make sure to install the `diskcache` package before running the updated code.
2023-06-02 16:36:03 -07:00
Paul Gauthier
f5b68a4f69 personalization 2023-06-02 13:28:40 -07:00
Paul Gauthier
68434cbaa1 cleanup 2023-06-02 13:24:29 -07:00
Paul Gauthier
47293c5ba9 removed graph 2023-06-02 13:22:25 -07:00
Paul Gauthier
36f21fcfb6 refac 2023-06-02 13:22:00 -07:00