Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: commands #2869

Merged
merged 36 commits into from
Jan 29, 2024
Merged

refactor: commands #2869

merged 36 commits into from
Jan 29, 2024

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Jan 23, 2024

Refactor and clean up the existing commands set up, update and add new e2e tests to cover commands and custom commands.

Note: A lot of the files were updated due to attempts to clean up and unify method names, commands, and file names.
For example:

  • "cody.action.commands.custom.menu" -> "cody.menu.custom-commands"
  • "cody.action.commands.menu" -> "cody.menu.commands"
  • "cody.action.commands.exec" -> "cody.action.command"
  • "CustomPrompts" -> "CustomCommands"
  • file name "CommandRunnerr" -> runner.ts etc

The major change in this PR is moving command to the top level and decouple it from chat and edit. This allows other services to execute a command anywhere through:

  • executeCodyCommand: a function that is tied to the execution step in the CommandsController class.
    1. When a command is executed, the request will be sent to the CommandsController
    2. CommandsController will look up the command based on the input, before creating a CommandRunner
    3. Each CommandRunner handles identifying if the command is a chat request or an edit request, then fetch for the relevant context before sending creating the request via executeChat for chat request and executeEdit for edit request respectively.
  • 0r via vscode.commands.executeCommand('cody.action.command'): a global command that is connected to executeCodyCommand.
  • All the default commands can also be initiated by other services via the vscode commands registered in main.ts.

Summary:

  • Context used for custom commands are broken down into individual files inside vscode/src/commands/context
  • Default commands are broken down into individual files inside vscode/src/commands/default
  • Command controller now handles the sorting and execution at top level
  • Slash commands support have been removed from chat
  • All the command-handling methods have been removed from the chat panel class
  • All the command-context fetching methods have been removed from the chat context provider class

Checklist:

  • moved command execution step to top level
  • decouple commands from chat
  • decouple default commands from custom commands
  • remove /ask command from chat
  • remove slash commands from chat
  • unify command menus
  • support codebase as custom command context via addEnhancedContext in cody.action.chat command
  • remove command handling from chat panel
  • remove get command context from chat
  • command runner handles context fetching and categorizing command before sending command prompt with context as either a chat request or inline edit request
  • rename files
  • replace "custom prompt" with "custom commands"
  • clean up command controller
  • clean up command provider
  • clean up command runner
  • clean up command context
  • clean up custom command store
  • update integration tests for commands
  • add e2etests to cover custom command menu
  • add e2e tests to cover executing custom command defined in cody.json file
  • add e2e tests to cover context defined for a custom command
  • add e2e test to cover default command selection context

Test plan

Try executing

  • the default chat commands (explain, test, smell)
  • default edit command (doc, new test command)
  • a custom command

@abeatrix abeatrix marked this pull request as ready for review January 26, 2024 06:33
@abeatrix abeatrix requested review from umpox and a team January 26, 2024 06:33
agent/src/index.test.ts Outdated Show resolved Hide resolved
@abeatrix abeatrix changed the title wip: refactor commands refactor: commands Jan 26, 2024
@abeatrix abeatrix requested a review from beyang January 26, 2024 09:32
@umpox
Copy link
Contributor

umpox commented Jan 26, 2024

Right click -> Explain code seems to show the full explain prompt, instead of /explain. Is that intended? Also happens with Smell code.

image

The cog in the Command palette seems to open the custom commands menu. Is that expected? I would have thought it would open VS Code settings 🤔

image

Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a high level look over the code and it's looking really good. Left some minor comments and a few possible bugs I noticed

vscode/src/commands/context/test-files.ts Outdated Show resolved Hide resolved
vscode/src/commands/menus/index.ts Outdated Show resolved Hide resolved
vscode/src/commands/default/doc.ts Outdated Show resolved Hide resolved
vscode/src/commands/default/test.ts Outdated Show resolved Hide resolved
vscode/src/commands/menus/index.ts Outdated Show resolved Hide resolved
@abeatrix
Copy link
Contributor Author

Right click -> Explain code seems to show the full explain prompt, instead of /explain. Is that intended? Also happens with Smell code.

image The cog in the Command palette seems to open the custom commands menu. Is that expected? I would have thought it would open VS Code settings 🤔

@umpox Thanks for the thorough review!

Right click -> Explain code seems to show the full explain prompt, instead of /explain. Is that intended? Also happens with Smell code.

That's intended as part of removing slash commands from chat. This allows user to see the underlaying prompt and tweak it via the new edit buttons as right now, we are disabling the edit buttons on command messages due to this issue.

The cog in the Command palette seems to open the custom commands menu. Is that expected? I would have thought it would open VS Code settings 🤔

Yea that's the current behavior! I do think we can give this menu a makeover in a follow up, but i've updated the menu so that it runs edit command by default instead of ask :D

@abeatrix abeatrix requested a review from umpox January 27, 2024 20:47
Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! and nice tests 👍

agent/src/index.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abeatrix the very large addition to the recording file (+15k lines) hints to me that we're adding a lot of unused recordings. The pnpm update-agent-recordings command is supposed to clean up unused recordings but I'm sensing it's not working 100% correctly yet.

You can run this command to reset the commands from origin/main

./agent/scripts/reset-recordings-to-main.sh

I don't see any new LLM requests in the updated tests that could explain why we need 15k new lines to the recording file.

@olafurpg
Copy link
Member

FYI I figured out the bug with keepUnusedRecording so that pnpm update-agent-recordings no longer keeps adding new recordings #2926

@abeatrix abeatrix merged commit 771e48f into main Jan 29, 2024
14 of 15 checks passed
@abeatrix abeatrix deleted the bee/refactor-commands branch January 29, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants