|
42 | 42 | from cecli.exceptions import LiteLLMExceptions |
43 | 43 | from cecli.helpers import command_parser, coroutines, nested, responses |
44 | 44 | from cecli.helpers.conversation import ConversationService, MessageTag |
| 45 | +from cecli.helpers.file_system import FileSystemService |
45 | 46 | from cecli.helpers.io_proxy import IOProxy |
46 | 47 | from cecli.helpers.observations.service import ObservationService |
47 | 48 | from cecli.helpers.profiler import TokenProfiler |
@@ -459,9 +460,7 @@ def __init__( |
459 | 460 |
|
460 | 461 | self.context_compaction_max_tokens = context_compaction_max_tokens |
461 | 462 | self.context_compaction_summary_tokens = context_compaction_summary_tokens |
462 | | - self.max_reflections = ( |
463 | | - 3 if self.edit_format == "agent" else nested.getter(self.args, "max_reflections", 3) |
464 | | - ) |
| 463 | + self.max_reflections = nested.getter(self.args, "max_reflections", 3) |
465 | 464 |
|
466 | 465 | if not fnames: |
467 | 466 | fnames = [] |
@@ -547,7 +546,6 @@ def __init__( |
547 | 546 |
|
548 | 547 | self.data_cache = { |
549 | 548 | "repo": {"last_key": "", "read_only_count": None}, |
550 | | - "relative_files": None, |
551 | 549 | } |
552 | 550 |
|
553 | 551 | self.repo = repo |
@@ -594,6 +592,12 @@ def __init__( |
594 | 592 | if not self.repo: |
595 | 593 | self.root = utils.find_common_root(self.abs_fnames) |
596 | 594 |
|
| 595 | + # Initialize the FileSystemService singleton for all agents |
| 596 | + FileSystemService.get_instance( |
| 597 | + root=self.root if hasattr(self, "root") else ".", |
| 598 | + repo=self.repo if hasattr(self, "repo") else None, |
| 599 | + ) |
| 600 | + |
597 | 601 | if read_only_fnames: |
598 | 602 | self.abs_read_only_fnames = set() |
599 | 603 | for fname in read_only_fnames: |
@@ -3226,7 +3230,7 @@ async def check_for_file_mentions(self, content): |
3226 | 3230 | group = ConfirmGroup(new_mentions) |
3227 | 3231 | for rel_fname in sorted(new_mentions): |
3228 | 3232 | message = "Add file to the chat?" |
3229 | | - if self.args.tui: |
| 3233 | + if self.args and self.args.tui: |
3230 | 3234 | message = f"Add file to the chat? ({rel_fname})" |
3231 | 3235 |
|
3232 | 3236 | if await self.io.confirm_ask( |
@@ -3909,37 +3913,16 @@ def is_file_safe(self, fname): |
3909 | 3913 | return |
3910 | 3914 |
|
3911 | 3915 | def get_all_relative_files(self): |
3912 | | - if self.repo_map and self.repo: |
3913 | | - try: |
3914 | | - staged_files_hash = hash( |
3915 | | - str([item.a_path for item in self.repo.repo.index.diff("HEAD")]) |
3916 | | - ) |
3917 | | - if ( |
3918 | | - staged_files_hash == self.data_cache["repo"]["last_key"] |
3919 | | - and self.data_cache["relative_files"] |
3920 | | - ): |
3921 | | - return self.data_cache["relative_files"] |
3922 | | - except ANY_GIT_ERROR as err: |
3923 | | - # Handle git errors gracefully - fall back to getting tracked files |
3924 | | - if self.verbose: |
3925 | | - self.io.tool_warning(f"Git error while checking staged files: {err}") |
3926 | | - # Continue to get tracked files normally |
3927 | | - |
3928 | | - if self.repo: |
3929 | | - if hasattr(self.repo, "workspace_path") and self.repo.workspace_path: |
3930 | | - files = self.repo.get_workspace_files() |
3931 | | - elif not self.repo.cecli_ignore_file or not self.repo.cecli_ignore_file.is_file(): |
3932 | | - files = self.repo.get_tracked_files() |
3933 | | - else: |
3934 | | - files = self.repo.get_non_ignored_files_from_root() |
3935 | | - else: |
3936 | | - files = self.get_inchat_relative_files() |
3937 | | - # This is quite slow in large repos |
3938 | | - # files = [fname for fname in files if self.is_file_safe(fname)] |
3939 | | - |
3940 | | - self.data_cache["relative_files"] = sorted(set(files)) |
3941 | | - |
3942 | | - return self.data_cache["relative_files"] |
| 3916 | + """Get all files known to the file service singleton.""" |
| 3917 | + fs = FileSystemService.get_instance() |
| 3918 | + if fs.trie: |
| 3919 | + # Auto-rebuild if the repository state has changed |
| 3920 | + # (e.g., new commits, staged files, or HEAD change) |
| 3921 | + if fs.needs_rebuild(): |
| 3922 | + fs.rebuild() |
| 3923 | + files = fs.list_all() |
| 3924 | + return files |
| 3925 | + return self.get_inchat_relative_files() |
3943 | 3926 |
|
3944 | 3927 | def get_all_abs_files(self): |
3945 | 3928 | files = self.get_all_relative_files() |
|
0 commit comments