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

bug: currentDir context is not shown in UI #2548

Closed
Bruno-DaSilva opened this issue Jan 3, 2024 · 7 comments
Closed

bug: currentDir context is not shown in UI #2548

Bruno-DaSilva opened this issue Jan 3, 2024 · 7 comments
Assignees
Labels
bug Something isn't working clients/vscode

Comments

@Bruno-DaSilva
Copy link

Bruno-DaSilva commented Jan 3, 2024

Version

v1.0.4

Describe the bug

When using the currentDir context option, eg. when running the generate-tests command (/test), the list of files used for context is incomplete. None of the files generated by the currentDir context are shown. Yet, if you examine the debug promptCompletion output, the context files are there..

bugged2 bugged1

Expected behavior

The UI that shows the list of files sent as context should contain the files from the currentDir context option.
Here's what it looks like with one of the below fixes applied:
fixed2
fixed1

Additional context

To be clear, I'm talking about this UI Component:
Screen Shot 2024-01-03 at 6 01 37 AM

Why this happens:

After some debugging within the extension, I found the prompt message generated for currentDir context files is hardcoded in here:

const templateText = 'Codebase context from file path {fileName}: '

EDIT: also in getCurrentDirFilteredContext().

Yet, the SimpleChatRecipeAdapter calls contextMessageToContextItem(message):

const fullContext = await interaction.getFullContext()
const prompt: Message[] = fullContext.concat([humanInteractionMessage] as Message[])
const contextItems = fullContext
.map(m => contextMessageToContextItem(m))
.filter((m): m is ContextItem => m !== null)

which strips the prompt messages down to the file information so long as they match these strings:
const start = text.indexOf('Use following code snippet')

const start = text.indexOf('Use the following text from file')

const start = text.indexOf('My selected ')

And otherwise returns undefined.

Well, as you can see, the currentDir prompt string doesn't match any of these. Thus all files from this context are filtered out and don't appear in the UI.

Proposed Fixes:

  1. add the hardcoded Codebase context from file path to the prompt templates file and then add it to the stripContextWrapper() function in chat-helpers.ts, OR
  2. change the hardcoded prompt prefix to use one of the already existing file context templates, which will match what's used in chat-helpers.ts.
@Bruno-DaSilva Bruno-DaSilva added bug Something isn't working clients/vscode labels Jan 3, 2024
@Bruno-DaSilva
Copy link
Author

I've updated the original with root cause and proposed fixes. Hoping that can mean a swift fix from someone :)

@Bruno-DaSilva
Copy link
Author

Bruno-DaSilva commented Jan 3, 2024

quick ping to @abeatrix as you're the implementer of vscode-context and @beyang as you're the implementer of the simplify-chat-prompts refactor:
I assume one of you should know which fix is preferred here.

@Bruno-DaSilva
Copy link
Author

Bruno-DaSilva commented Jan 3, 2024

Note this hardcoding-not-matching seems to happen in at least one other place: getCurrentDirFilteredContext(). So that will have to change as well. Might be worth verifying that there aren't more places with this problem.

@abeatrix
Copy link
Contributor

abeatrix commented Jan 3, 2024

@Bruno-DaSilva hey there, thank you so much for the detailed report! I am working on a PR that would address this issue, will keep you posted here!

@Bruno-DaSilva
Copy link
Author

hahaha you were already working on it before I reported, I see. Wonderful. Thanks for picking this up, @abeatrix!

abeatrix added a commit that referenced this issue Jan 5, 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.

## Test plan

<!-- 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

## Demo


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

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


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


#### After

- 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
Copy link
Contributor

abeatrix commented Jan 5, 2024

@Bruno-DaSilva This should be fixed on the latest pre-release version. Can you give that a try and let us know if that doesn't work, please? 🙇‍♀️

@Bruno-DaSilva
Copy link
Author

Bruno-DaSilva commented Jan 6, 2024

This looks like it's working on the pre-release version! Thanks for the quick fix 🙌

I'll leave it to you to close this issue (dunno if your definition of done includes waiting for full release)

olafurpg pushed a commit that referenced this issue 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 closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working clients/vscode
Projects
None yet
Development

No branches or pull requests

2 participants