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: move commands away from recipe #2542

Merged
merged 23 commits into from
Jan 5, 2024
Merged

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Jan 2, 2024

This PR includes the following changes:

  • Moves commands and custom commands away from recipes.
  • Addresses issue detailed in bug: currentDir context is not shown in UI #2548
  • Removes SimpleChatRecipeAdapter
  • Removes executeRecipe from SimpleChatPanelProvider and ChatManager
  • Removes the custom-prompts recipe which was used for commands and custom commands
  • Runs executeCommand from top level in main.ts and turns it into a vscode command
  • Fixes issue where all context is showing up as via embeddings
  • Adds range to editor context for commands RE: bug: "from ${n} files" missing line counts #1984
  • Updates to execute all edit commands in CommandRunner so that we won't need to rely on sidebar view to execute fixup or custom commands recipes.

Test plan

All the current tests for chat, commands, and custom commands should still pass and work correctly.

  1. Run the explain command
    • from sidebar
    • from left-click menu
    • from chat
  2. Run the doc command
    • from sidebar
    • from left-click menu
    • from chat
  3. Run a custom command
    • from sidebar
    • from left-click menu
    • from chat
  4. Run an edit command
  • Make sure context for each command is showing up correctly

Demo

Screen.Recording.2024-01-03.at.7.57.41.AM.mov

Before - context for test command are now showing up in context list

image

After

  • Context sources for commands + Context for text command are showing up correctly
  • Context for commands include range

image

@abeatrix abeatrix changed the title intergrate command in simple chat refactor: move commands away from recipe Jan 3, 2024
@abeatrix abeatrix marked this pull request as ready for review January 3, 2024 23:54
@abeatrix abeatrix requested review from beyang, umpox and a team January 3, 2024 23:54
(await this.editor.getActiveTextEditorSmartSelection()) ||
this.editor.getActiveTextEditorSelectionOrVisibleContent()
if (!selection || isCodyIgnoredFile(vscode.Uri.file(selection.fileName))) {
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we use getActiveTextEditorSelectionOrVisibleContent some places (above, for executeCommand) but this "smart" selection when the command has the 'selection' property? And generate an error about opening a file in one case but not another? And checks for isCodyIgnoredFile happen within one (this one) but not the other?

Can these be brought together, simplified, and handle things like Cody ignored files consistently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good questions! We check if it's an ignored file or not when we try to create context item from a selection object.

If a command requires user to have a current selection, we will try to use Smart Selection to auto select code for the user. We won't try to fall back to use visible context as selection for commands that require selection specifically.

If a command doesn't require a selection, we will try to get the visible context to use as selection context, like the explain or smell commands for example, unless the command.context.selection for the command is specified to be false.

Does this answer your questions? If yes, I will add these as docstring!

Copy link
Contributor Author

@abeatrix abeatrix Jan 4, 2024

Choose a reason for hiding this comment

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

TL;DR

  • we check for isCodyIgnoredFile in ContextProvider when creating context item
  • We generate error about no file opened in webview provider where we handle command execution

@@ -89,8 +89,9 @@ test('@-file empty state', async ({ page, sidebar }) => {
)
).toBeVisible()

// TODO bee fix
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the plan for this? If it's a TODO to land, let's specify what and when.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops i forgot to delete this, will update. Thank you!

@dominiccooney
Copy link
Contributor

It would be great if we added automated tests to cover the essential functionality not already covered by tests.

Copy link
Contributor

@dominiccooney dominiccooney left a comment

Choose a reason for hiding this comment

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

Looks good. Please consider adding automated tests in a follow up change so we can keep broadening the contributor base.

@abeatrix
Copy link
Contributor Author

abeatrix commented Jan 4, 2024

Looks good. Please consider adding automated tests in a follow up change so we can keep broadening the contributor base.

Updated existing tests and added new tests for the new simple chat provider! Thanks for the review @dominiccooney!

@abeatrix abeatrix merged commit 7ea2514 into main Jan 5, 2024
16 checks passed
@abeatrix abeatrix deleted the bee/execute-command-simple branch January 5, 2024 00:29
olafurpg added a commit that referenced this pull request Jan 5, 2024
olafurpg added a commit that referenced this pull request Jan 5, 2024
The agent tests started failing after merging the PR #2542 when you
re-record the HTTP requests. The tests were passing in replay mode for
some reason, and we suspect it's due to a buggy merge in
`recording.har`. When you `rm -rf agent/recordings` and record from
scratch then the tests fail.

To prevent this from happening again, we're planning to provide scripts
to cleanly update the recordings.

## Test plan

Green CI.
<!-- Required. See
https://sourcegraph.com/docs/dev/background-information/testing_principles.
-->
abeatrix added a commit that referenced this pull request Jan 5, 2024
abeatrix added a commit that referenced this pull request Jan 5, 2024
…th new fixes (#2583)

Close #2588

- Reverts #2575 with updated fixes from
#2580 that I've confirmed with
@Gedochao on call.

- Merged main and updated the recording to confirm there are no errors
caused by the changes in this branch in all covered tests:


![image](https://github.com/sourcegraph/cody/assets/68532117/e54d893a-0798-48af-a838-061056fbc889)

- Also confirmed this change also passed the new rate limit test
introduced in #2535

- Fixed upresponsive stop button when error is presented


https://github.com/sourcegraph/cody/assets/68532117/6d9263b0-3e9c-419e-939d-20a2ea011824

## Test Plan

- run `pnpm run test:unit` to confirm all the tests are passing
olafurpg pushed a commit that referenced this pull request Jan 8, 2024
This PR includes the following changes:
- Moves commands and custom commands away from recipes.
- Addresses issue detailed in
#2548
- Removes `SimpleChatRecipeAdapter`
- Removes `executeRecipe` from SimpleChatPanelProvider and ChatManager
- Removes the `custom-prompts` recipe which was used for commands and
custom commands
- Runs `executeCommand` from top level in `main.ts` and turns it into a
vscode command
- Fixes issue where all context is showing up as `via embeddings`
- Adds range to editor context for commands RE:
#1984
- Updates to execute all edit commands in CommandRunner so that we won't
need to rely on sidebar view to execute fixup or custom commands
recipes.

<!-- Required. See
https://sourcegraph.com/docs/dev/background-information/testing_principles.
-->

All the current tests for chat, commands, and custom commands should
still pass and work correctly.

1. Run the explain command
   - [ ] from sidebar
   - [ ] from left-click menu
   - [ ] from chat
2. Run the doc command
   - [ ] from sidebar
   - [ ] from left-click menu
   - [ ] from chat
3. Run a custom command
   - [ ] from sidebar
   - [ ] from left-click menu
   - [ ] from chat
4. Run an edit command

- Make sure context for each command is showing up correctly

https://github.com/sourcegraph/cody/assets/68532117/7e4d9118-9a0a-48cd-823a-af2646e52357

list

![image](https://github.com/sourcegraph/cody/assets/68532117/9471dcee-cdce-499a-8eae-caf7dd3ce607)

- Context sources for commands + Context for text command are showing up
correctly
- Context for commands include range

![image](https://github.com/sourcegraph/cody/assets/68532117/c95b4407-98c4-47af-a288-76fce10a0d5e)
@abeatrix abeatrix self-assigned this Jan 9, 2024
@beyang beyang mentioned this pull request Jan 22, 2024
4 tasks
beyang added a commit that referenced this pull request Jan 22, 2024
This PR addresses some code quality issues and complexity in the chat
implementation.
* #2542 introduced a separate
code path for handling command-initiated chats. This introduced a flag
that special-cased handling of commands in a number of places—in the
view controller (SimpleChatPanelProvider), prompt constructor, and
context fetcher. These flags make chat more difficult to reason about,
requiring the dev to reason about the conditional flag at multiple
places in the lifecycle of a chat request.

Code changes
* Instead of checking a flag to see if the user request was a command in
`DefaultPrompter`, introduces a new `CommandPrompter` to customize
prompt construction for commands
* Breaks apart `ContextProvider` into separate functions, moved to a
`context.ts` file. Enhanced context can be fetched by either prompter.
* Simplifies the core code paths in `SimpleChatPanelProvider`. Now there
are two top-level message handlers: `handleNewUserMessage` (for regular
chat) and `handleCommand` (for commands). These then execute the
necessary steps without entangling other methods that must then support
both code paths via conditional.
  * Previously, we had the following mess:
    * `executeChat` -> `handleHumanMessageSubmitted`
* `handleHumanMessageSubmitted` -> 'handleChatRequest` OR
`handleCommands`
    * `handleCommands` -> `handleChatRequest`
    * `handleChatRequest` -> `generateAssistantResponse`

Behavior changes
* This change removes the already defunct
`cody.experimental.chatPredictions` setting.
* This change disables codebase-wide context fetching for commands. This
field appears unused by first-party commands, and it's unclear whether
it was actually being used for custom commands.

Test changes:
* Fixes some flakiness in macOS e2e tests
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.

None yet

2 participants