Merge branch 'main' into glob-add

This commit is contained in:
Paul Gauthier 2023-07-06 17:53:46 -07:00
commit cb2b2c5ce3
22 changed files with 465 additions and 94 deletions

View file

@ -4,12 +4,13 @@ import os
import shlex
import subprocess
import sys
from pathlib import Path
import git
import tiktoken
from prompt_toolkit.completion import Completion
from aider import prompts, utils
from aider import prompts
class Commands:
@ -117,8 +118,10 @@ class Commands:
# files
for fname in self.coder.abs_fnames:
relative_fname = self.coder.get_rel_fname(fname)
quoted = utils.quoted_file(fname, relative_fname)
tokens = len(self.tokenizer.encode(quoted))
content = self.io.read_text(fname)
# approximate
content = f"{relative_fname}\n```\n" + content + "```\n"
tokens = len(self.tokenizer.encode(content))
res.append((tokens, f"{relative_fname}", "use /drop to drop from chat"))
self.io.tool_output("Approximate context window usage, in tokens:")
@ -231,8 +234,8 @@ class Commands:
if self.coder.repo is not None:
create_file = self.io.confirm_ask(
(
f"No files matched '{word}'. Do you want to create the file and add it"
" to git?"
f"No files matched '{word}'. Do you want to create the file and add"
" it to git?"
),
)
else:
@ -241,8 +244,7 @@ class Commands:
)
if create_file:
with open(os.path.join(self.coder.root, word), "w"):
pass
(Path(self.coder.root) / word).touch()
matched_files = [word]
if self.coder.repo is not None:
self.coder.repo.git.add(os.path.join(self.coder.root, word))
@ -254,9 +256,11 @@ class Commands:
for matched_file in matched_files:
abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file))
if abs_file_path not in self.coder.abs_fnames:
self.coder.abs_fnames.add(abs_file_path)
self.io.tool_output(f"Added {matched_file} to the chat")
added_fnames.append(matched_file)
content = self.io.read_text(abs_file_path)
if content is not None:
self.coder.abs_fnames.add(abs_file_path)
self.io.tool_output(f"Added {matched_file} to the chat")
added_fnames.append(matched_file)
else:
self.io.tool_error(f"{matched_file} is already in the chat")
@ -339,6 +343,10 @@ class Commands:
else:
other_files.append(file)
if not chat_files and not other_files:
self.io.tool_output("\nNo files in chat or git repo.")
return
if chat_files:
self.io.tool_output("Files in chat:\n")
for file in chat_files: