Duo Chat in Web: Explain code feature prints `/explain` into the chat giving the wrong impression that this could be used by the user

Problem

  • When in GitLab on a blob page, select code, and then click the to get the code explained Duo Chat shows /explain in the chat.
  • Given we have this pattern of slash commands in our IDEs and given that slash commands are becoming common in the industry, this suggests to the users that they can use this by typing it in the Chat in GitLab.
  • However, in the GitLab they can't because they can't select anything and then type /explain to get that explained.

Solution proposal

So until we can select something in GitLab and then execute a slash command, we should probably apply a different logic than in the IDE where it is possible to select something. There two quick fixes that we could choose from:

  1. When the user is on a blob page and types /explain into the chat we send the whole file in that case.
  2. When in GitLab on a blob page, select code, and then click the to get the code explained Duo Chat shows either
    1. /explain <deeplink to selected lines> in the chat history and make sure that the same command would work if the user entered it. E.g. /explain https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/spec/lib/gitlab/code_owners/validator_spec.rb#L29-38 where the latter is a clickable link.
    2. Explain lines m to n in <File name>. We don't necessarily need to make that work for the user typing this question.

I favor 2.1.

Proposed Implementation

To address solution 2.1:

  1. Implement functionality to capture the selected lines when a user uses line number selection (e.g., #L29-38 in the URL).
  2. Enable the /explain command to work with this selection, sending the selected text to the AI for explanation.
Edited by Matt Nohr