Skip to content

Commit fc74d5e

Browse files
committed
Allow for /commit and /review commands to be run in sidekick
Resolves #63 In `cli.py`, the commit process has been refined to provide better user feedback and control. The user is now asked for confirmation before committing changes, and has the option to abort the commit if they choose. This makes the commit process more interactive and user-friendly. 🎉 In `coder.py`, the autocomplete feature has been enhanced. Now, it supports autocomplete for the `/review` and `/commit` commands, and the file listing for the `/add` command is now cached for performance. This should make the CLI more responsive and easier to use. 🚀 Additionally, the `/commit` and `/review` commands have been added to the sidekick command in `cli.py`, providing more functionality to the user. 🛠️ These changes should improve the overall user experience of the CLI. 😊
1 parent 3aba213 commit fc74d5e

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

aicodebot/cli.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ def commit(verbose, response_token_size, yes, skip_pre_commit, files): # noqa:
106106
if not staged_files:
107107
# If no files are staged, they probably want to commit all changed files, confirm.
108108
if not files and not yes:
109-
click.confirm(
109+
confirm = click.confirm(
110110
"Since there are no git staged files, all of the modified files will be committed:\n\t"
111111
+ "\n\t".join(unstaged_files)
112112
+ "\nDoes that look correct?",
113113
default=True,
114-
abort=True,
115114
)
115+
if not confirm:
116+
console.print("Aborting commit.")
117+
return
118+
116119
files = unstaged_files
117120
else:
118121
# The list of files to be committed is the same as the list of staged files
@@ -189,10 +192,14 @@ def commit(verbose, response_token_size, yes, skip_pre_commit, files): # noqa:
189192
subprocess.call([editor, temp_file_name]) # noqa: S603
190193

191194
# Ask the user if they want to commit the changes
192-
if yes or click.confirm("Are you ready to commit the changes?", default=True, abort=True):
193-
# Commit the changes using the temporary file for the commit message
194-
exec_and_get_output(["git", "commit", "-F", temp_file_name])
195-
console.print(f"✅ {len(files)} file(s) committed.")
195+
if not yes:
196+
confirm = click.confirm("Are you ready to commit the changes?", default=True)
197+
if confirm:
198+
# Commit the changes using the temporary file for the commit message
199+
exec_and_get_output(["git", "commit", "-F", temp_file_name])
200+
console.print(f"✅ {len(files)} file(s) committed.")
201+
else:
202+
console.print("Aborting commit.")
196203

197204
# Delete the temporary file
198205
Path(temp_file_name).unlink()
@@ -562,12 +569,23 @@ def calc_response_token_size(files):
562569
show_file_context(files)
563570
continue
564571

572+
elif cmd == "/commit":
573+
# Call the commit function with the parsed arguments
574+
args = human_input.split()[1:]
575+
ctx = click.get_current_context()
576+
ctx.invoke(commit, *args)
577+
continue
565578
elif cmd == "/edit":
566579
human_input = edited_input = click.edit()
567580
elif cmd == "/files":
568581
show_file_context(files)
569582
continue
570-
583+
elif cmd == "/review":
584+
# Call the review function with the parsed arguments
585+
args = human_input.split()[1:]
586+
ctx = click.get_current_context()
587+
ctx.invoke(review, *args)
588+
continue
571589
elif cmd == "/quit":
572590
break
573591

aicodebot/coder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,13 @@ class SidekickCompleter(Completer):
445445
"""
446446

447447
files = [] # List of files that we have loaded in the current context
448+
project_files = Coder.filtered_file_list(".", use_gitignore=True, ignore_patterns=[".git"])
448449

449450
def get_completions(self, document, complete_event):
450451
# Get the text before the cursor
451452
text = document.text_before_cursor
452453

453-
supported_commands = ["/add", "/drop", "/edit", "/files", "/quit"]
454+
supported_commands = ["/add", "/commit", "/drop", "/edit", "/files", "/review", "/quit"]
454455

455456
# If the text starts with a slash, it's a command
456457
if text.startswith("/"):
@@ -459,15 +460,21 @@ def get_completions(self, document, complete_event):
459460
yield Completion(command, start_position=-len(text))
460461

461462
if text.startswith("/add "):
462-
# If the text starts with /add or /drop, it's a file, so autocomplete the file name
463+
# For /add autocomplete the file name from the project file listing
463464
# Get the list of files in the current directory, filtered by the .gitignore file
464-
project_files = Coder.filtered_file_list(".", use_gitignore=True, ignore_patterns=[".git"])
465-
for file in project_files:
465+
for file in self.project_files:
466466
if str(file).startswith(text.split()[-1]):
467467
yield Completion(str(file), start_position=-len(text.split()[-1]))
468468

469469
elif text.startswith("/drop "):
470-
# If the text starts with /drop, use the current context files for autocomplete
470+
# For /drop, use the current context files for autocomplete
471471
for file in self.files:
472472
if file.startswith(text.split()[-1]):
473473
yield Completion(file, start_position=-len(text.split()[-1]))
474+
475+
elif text.startswith(("/review ", "/commit ")):
476+
# For /review and /commit, use the staged/unstaged files for autocomplete
477+
changed_files = Coder.git_staged_files() + Coder.git_unstaged_files()
478+
for file in changed_files:
479+
if file.startswith(text.split()[-1]):
480+
yield Completion(file, start_position=-len(text.split()[-1]))

0 commit comments

Comments
 (0)