This commit is contained in:
Amar Sood 2025-05-13 16:48:46 -07:00 committed by GitHub
commit ab08ebc65c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 89 additions and 23 deletions

View file

@ -443,6 +443,11 @@ class Commands:
self.coder.choose_fence()
# Show progress indicator
total_files = len(self.coder.abs_fnames) + len(self.coder.abs_read_only_fnames)
if total_files > 20:
self.io.tool_output(f"Calculating tokens for {total_files} files...")
# system messages
main_sys = self.coder.fmt_system_prompt(self.coder.gpt_prompts.main_system)
main_sys += "\n" + self.coder.fmt_system_prompt(self.coder.gpt_prompts.system_reminder)
@ -474,8 +479,20 @@ class Commands:
fence = "`" * 3
file_res = []
# files
for fname in self.coder.abs_fnames:
# Process files with progress indication
total_editable_files = len(self.coder.abs_fnames)
total_readonly_files = len(self.coder.abs_read_only_fnames)
# Display progress for editable files
if total_editable_files > 0:
if total_editable_files > 20:
self.io.tool_output(f"Calculating tokens for {total_editable_files} editable files...")
# Calculate tokens for editable files
for i, fname in enumerate(self.coder.abs_fnames):
if i > 0 and i % 20 == 0 and total_editable_files > 20:
self.io.tool_output(f"Processed {i}/{total_editable_files} editable files...")
relative_fname = self.coder.get_rel_fname(fname)
content = self.io.read_text(fname)
if is_image_file(relative_fname):
@ -486,8 +503,16 @@ class Commands:
tokens = self.coder.main_model.token_count(content)
file_res.append((tokens, f"{relative_fname}", "/drop to remove"))
# read-only files
for fname in self.coder.abs_read_only_fnames:
# Display progress for read-only files
if total_readonly_files > 0:
if total_readonly_files > 20:
self.io.tool_output(f"Calculating tokens for {total_readonly_files} read-only files...")
# Calculate tokens for read-only files
for i, fname in enumerate(self.coder.abs_read_only_fnames):
if i > 0 and i % 20 == 0 and total_readonly_files > 20:
self.io.tool_output(f"Processed {i}/{total_readonly_files} read-only files...")
relative_fname = self.coder.get_rel_fname(fname)
content = self.io.read_text(fname)
if content is not None and not is_image_file(relative_fname):
@ -496,6 +521,9 @@ class Commands:
tokens = self.coder.main_model.token_count(content)
file_res.append((tokens, f"{relative_fname} (read-only)", "/drop to remove"))
if total_files > 20:
self.io.tool_output("Token calculation complete. Generating report...")
file_res.sort()
res.extend(file_res)
@ -510,7 +538,7 @@ class Commands:
def fmt(v):
return format(int(v), ",").rjust(width)
col_width = max(len(row[1]) for row in res)
col_width = max(len(row[1]) for row in res) if res else 0
cost_pad = " " * cost_width
total = 0

View file

@ -129,7 +129,19 @@ class AutoCompleter(Completer):
return
self.tokenized = True
for fname in self.all_fnames:
# Performance optimization for large file sets
if len(self.all_fnames) > 100:
# Skip tokenization for very large numbers of files to avoid input lag
self.tokenized = True
return
# Limit number of files to process to avoid excessive tokenization time
process_fnames = self.all_fnames
if len(process_fnames) > 50:
# Only process a subset of files to maintain responsiveness
process_fnames = process_fnames[:50]
for fname in process_fnames:
try:
with open(fname, "r", encoding=self.encoding) as f:
content = f.read()
@ -1120,6 +1132,21 @@ class InputOutput:
self.chat_history_file = None # Disable further attempts to write
def format_files_for_input(self, rel_fnames, rel_read_only_fnames):
# Optimization for large number of files
total_files = len(rel_fnames) + len(rel_read_only_fnames or [])
# For very large numbers of files, use a summary display
if total_files > 50:
read_only_count = len(rel_read_only_fnames or [])
editable_count = len([f for f in rel_fnames if f not in (rel_read_only_fnames or [])])
summary = f"{editable_count} editable file(s)"
if read_only_count > 0:
summary += f", {read_only_count} read-only file(s)"
summary += " (use /ls to list all files)\n"
return summary
# Original implementation for reasonable number of files
if not self.pretty:
read_only_files = []
for full_path in sorted(rel_read_only_fnames or []):

View file

@ -126,6 +126,17 @@ def format_messages(messages, title=None):
else:
output.append(f"{role} {item}")
elif isinstance(content, str): # Handle string content
# For large content, especially with many files, use a truncated display approach
if len(content) > 5000:
# Count the number of code blocks (approximation)
fence_count = content.count("```") // 2
if fence_count > 5:
# Show truncated content with file count for large files to improve performance
first_line = content.split("\n", 1)[0]
output.append(f"{role} {first_line} [content with ~{fence_count} files truncated]")
else:
output.append(format_content(role, content))
else:
output.append(format_content(role, content))
function_call = msg.get("function_call")
if function_call: