From 3e5388ce6ea2be58b8b002d2a96cb04ef74bc6aa Mon Sep 17 00:00:00 2001 From: coredevorg <73153008+coredevorg@users.noreply.github.com> Date: Tue, 22 Apr 2025 15:36:03 +0200 Subject: [PATCH] feature: repomap cache directory configuration setting --- aider/args.py | 12 +++++++++++- aider/coders/base_coder.py | 6 +++++- aider/main.py | 1 + aider/repomap.py | 17 +++++++++++------ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/aider/args.py b/aider/args.py index 6df19778b..5f7f73645 100644 --- a/aider/args.py +++ b/aider/args.py @@ -247,6 +247,16 @@ def get_parser(default_config_files, git_root): default=2, help="Multiplier for map tokens when no files are specified (default: 2)", ) + group.add_argument( + "--map-cache-dir", + metavar="MAP_CACHE_DIR", + dest="map_cache_dir", + default=".", + help=( + "Directory for the repository map cache .aider.tags.cache.v3" + " (default: current directory)" + ), + ) ########## group = parser.add_argument_group("History Files") @@ -522,7 +532,7 @@ def get_parser(default_config_files, git_root): help="Run tests, fix problems found and then exit", default=False, ) - + ########## group = parser.add_argument_group("Analytics") group.add_argument( diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 675570c60..e04b60558 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -323,7 +323,11 @@ class Coder: file_watcher=None, auto_copy_context=False, auto_accept_architect=True, + map_cache_dir='.', ): + # initialize from args.map_cache_dir + self.map_cache_dir = map_cache_dir + # Fill in a dummy Analytics if needed, but it is never .enable()'d self.analytics = analytics if analytics is not None else Analytics() @@ -475,7 +479,7 @@ class Coder: if use_repo_map and self.repo and has_map_prompt: self.repo_map = RepoMap( map_tokens, - self.root, + self.map_cache_dir, self.main_model, io, self.gpt_prompts.repo_content_prefix, diff --git a/aider/main.py b/aider/main.py index 89286e1de..5fa4ffc3a 100644 --- a/aider/main.py +++ b/aider/main.py @@ -988,6 +988,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F detect_urls=args.detect_urls, auto_copy_context=args.copy_paste, auto_accept_architect=args.auto_accept_architect, + map_cache_dir=args.map_cache_dir, ) except UnknownEditFormat as err: io.tool_error(str(err)) diff --git a/aider/repomap.py b/aider/repomap.py index 598770d18..a28d0bd3a 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -44,7 +44,7 @@ class RepoMap: def __init__( self, map_tokens=1024, - root=None, + map_cache_dir='.', main_model=None, io=None, repo_content_prefix=None, @@ -57,9 +57,8 @@ class RepoMap: self.verbose = verbose self.refresh = refresh - if not root: - root = os.getcwd() - self.root = root + self.map_cache_dir = map_cache_dir + self.root = os.getcwd() self.load_tags_cache() self.cache_threshold = 0.95 @@ -82,6 +81,12 @@ class RepoMap: self.io.tool_output( f"RepoMap initialized with map_mul_no_files: {self.map_mul_no_files}" ) + self.io.tool_output( + f"RepoMap initialized with map_cache_dir: {self.map_cache_dir}" + ) + self.io.tool_output( + f"RepoMap assumes repo root is: {self.root}" + ) def token_count(self, text): len_text = len(text) @@ -180,7 +185,7 @@ class RepoMap: if isinstance(getattr(self, "TAGS_CACHE", None), dict): return - path = Path(self.root) / self.TAGS_CACHE_DIR + path = Path(self.map_cache_dir) / self.TAGS_CACHE_DIR # Try to recreate the cache try: @@ -212,7 +217,7 @@ class RepoMap: self.TAGS_CACHE = dict() def load_tags_cache(self): - path = Path(self.root) / self.TAGS_CACHE_DIR + path = Path(self.map_cache_dir) / self.TAGS_CACHE_DIR try: self.TAGS_CACHE = Cache(path) except SQLITE_ERRORS as e: