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

fix(chat): expansion of current-tab generic mention when non editor tabs are opened #6910

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ichim-david
Copy link
Collaborator

@ichim-david ichim-david commented Feb 1, 2025

Here are a few short videos:

  1. The bug in action:
broken-current-tabs-behavior.mp4
  1. Besides fixing the generic replacement I also added an option to selectedCodePromptWithExtraFiles
    in order to get rid of parenthesis wrapping the otherMentions if we don't need it such as in the case of the current-tabs.
current-tabs-with-parenthesis.mp4

and the fix:

current-tabs-without-parenthesis.mp4

Test plan

  1. Create a prompt that uses the current-tab mention.
  2. Open the Settings panel on VSCode (command + ,)
  3. Run the prompt and notice it being replaced by the opened editor tabs instead of remaining on cody://current-tabs

- This change filters out any null tab inputs from the list of open tabs, ensuring that the returned `ContextItem[]` array only contains valid tab inputs.
- Without this filtering the cody://current-tabs will not expand when
encountering  opened windows such as VSCode Settings
…arenthesis

- This change adds an optional `wrapJoinedMentions` parameter to the `selectedCodePromptWithExtraFiles` function.
- When `wrapJoinedMentions` is `true` (the default), the joined mentions will be wrapped in parentheses.
- This allows PROMPT_HYDRATION_MODIFIERS to return results
  without any (). Especially useful when using cody://current-tabs
- This ensures that the results returned by `hydrateWithOpenTabs`
  do not contain any unnecessary parentheses.
Copy link
Member

@beyang beyang left a comment

Choose a reason for hiding this comment

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

Do we ever need the "wrapped in parentheses" behavior? IMO, it's not clear that improves response quality (at best, it probably just makes whatever is sent to the LLM look janky; at worst, the non-standard formatting of having parens wrap multiple code snippets might throw the LLM "off distribution)". If there is no reason to have the parens, we could just remove them entirely and save the extra parameter here.

Copy link
Contributor

@vovakulikov vovakulikov left a comment

Choose a reason for hiding this comment

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

Nice, thanks for fixing this, I agree that wrapping is actually not needed anymore (I think it was used at some point when we had one "primary" file and "other" files, but I can't think of any current usage of this where this is still important.

@ichim-david
Copy link
Collaborator Author

ichim-david commented Feb 2, 2025

@beyang @vovakulikov
You guys are using the wrapping within the execute of default commands such as explain code, document code,
find code smell etc.
See all calls for "selectedCodePromptWithExtraFiles":
https://github.com/search?q=repo%3Asourcegraph%2Fcody%20selectedCodePromptWithExtraFiles&type=code

There you are taking "the selected code" and replacing it with file:linenumber-linenumber(file)
https://github.com/sourcegraph/cody/blob/main/vscode/src/commands/execute/explain.ts#L48

This only happens when you use the execute command and not when you call the prompt directly.
Have a look at this video where I show what I mean:

explain-code-command-vs-prompt.mp4

Given the fact that this doesn't happen when you call the prompt from the prompt choose, I would be in favor
of getting rid of this replacing behavior and we could also remove the addition of ().

The reason why I kept this functionality working was because I was aware that it is used in the command execution
and I didn't want to fix a bug only to insert a bug :).

If we are also on the topic of having parenthesis added I would set my flag to remove them also from this
prompt:
https://github.com/sourcegraph/cody/blob/main/vscode/src/prompts/prompt-hydration.ts#L309

I chose not todo it in order to keep this pull request pure, fix only issues for current-tab replacement and get
feedback on my actions.

What happens from here is up to what you guys want me todo now that I have presented these situations.

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