Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add multi-repo context selector to Cody Web#53046

Merged
0xnmn merged 2 commits into
mainfrom
naman/cody-scope-selector
Jun 7, 2023
Merged

Add multi-repo context selector to Cody Web#53046
0xnmn merged 2 commits into
mainfrom
naman/cody-scope-selector

Conversation

@0xnmn

@0xnmn 0xnmn commented Jun 6, 2023

Copy link
Copy Markdown
Contributor
  • Add multi-repo content selector to Cody Web based on Figma designs.
  • Auto-infer scope from currently opened markdown files.
  • Auto-infer readme.md content from the repo home page.

https://www.loom.com/share/340bd0e72bc5477ab517ce8143838a47

Test plan

  • visit /cody
  • click on add repostiories
  • search of repos & select
  • ask cody a question
  • reload page the the context should persist

@cla-bot cla-bot Bot added the cla-signed label Jun 6, 2023
@0xnmn 0xnmn self-assigned this Jun 6, 2023
@sourcegraph-bot

sourcegraph-bot commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@0xnmn 0xnmn force-pushed the naman/cody-scope-selector branch from b109cc5 to 0460540 Compare June 6, 2023 22:21
@0xnmn 0xnmn requested review from a team, almeidapaulooliveira and philipp-spiess June 6, 2023 22:24
@0xnmn 0xnmn force-pushed the naman/cody-scope-selector branch from da2e05c to b59f9b0 Compare June 6, 2023 22:46
@0xnmn 0xnmn removed the request for review from philipp-spiess June 6, 2023 23:17
@almeidapaulooliveira

almeidapaulooliveira commented Jun 7, 2023

Copy link
Copy Markdown
Contributor

Minor fixings

  • When adding repositories, the chevron keeps getting smaller. In this case, since we have empty space to the right, couldn't this component occupy 100% of the width?
Screen.Recording.2023-06-06.at.9.48.51.PM.mov

Desirable changes

  • The (-) button only shows when hovering.

Screenshot 2023-06-06 at 9 51 55 PM

@almeidapaulooliveira

Copy link
Copy Markdown
Contributor

@toolmantim, I think we'll need that 'Clear all' button in this UI. Look at how many clicks a user should have to clean the context and start over.

Screen.Recording.2023-06-06.at.10.00.49.PM.mov

@philipp-spiess philipp-spiess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome! Comments inline.

Comment thread client/cody-shared/src/chat/preamble.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any particular reason that this formatted with backticks instead of just the repo names?

If i understand this right, this will e expanded to something like this:

You have access to the `sourcegraph/sourcegraph, sourcegraph/cody repositories'`. You are able to answer questions about the `sourcegraph/sourcegraph, sourcegraph/cody repositories'`.

Which feels a bit unnatural to me (may be fine though, the LLMs are smarter than I am :D)

There's also a lot of repetition of the codebase var going on. If this holds e.g. 10 repos, this might contribute a lot to the prompt already. Maybe we can simplify this a bit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the template based on your suggestions.

Comment on lines 198 to 199

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see await here. One issue that we repeateldy run into again is that if we start to await anything in the recipe execution path, it would often cause a delay after a message is submitted and before the loading indicator is displayed in the UI. Is there a way to refactor this to not require async code paths in this branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This promise, will ideally be already resolved. We fetch repoIDs, whenever the context is changed and cache it. Because the type is still a promise, we need to await it here as well. But by the time the user enters the message, it should already be resolved. There should be only 1 event loop delay.

Comment on lines 200 to 217

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m not really sure what's gping on here. Is this adding the inferred context? If so, should this all be behidn an if(scope.includeInferredFIie)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah this can be confusing. I'll add comments in the code as well.

So basically, we allow users to disable inference of the current file and repo right? But what if they use the editor widget? The editor recipes still need the context of the current repo & file.

So here, if we are getting options.scope.editor as an argument of executeRecipe, we make sure the repo & file is included irrespective of includeInferredRepo/File.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this always be created or only if the unified scope is set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is only for web and it uses unified scope. If other clients use this is future we can make it dynamic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m a bit out of sync on the latest architecture but is this file used only for web or also for vs code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

only for web.

Comment on lines 23 to 54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The indentation in this file is a mix of tabs and spaces

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m a bit confused by this hook. Does it mean if scope changes, we setScope? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are checking for scopeInitialized so it will only happen at load.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this abstraction still makes sense if 80% of the classes that implement this interface have most of the API calls stubbed out 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lol yeah. I think this will improve in-future when we have extensions for other IDEs building in TS. As the code is shared, we need to keep it for now.

Comment on lines 455 to 477

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we instead of constructing a HTML string return JSX here? We can't use .replace, granted, but we can just loop over the regex matches manually and return a fragment maybe?

I’m worried that this code is reused for something else in the future and then the item may contain XSS vulnerabilities

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Really good idea. Updated:
image

@0xnmn 0xnmn force-pushed the naman/cody-scope-selector branch from 60bfcbf to a4b1235 Compare June 7, 2023 19:30
@0xnmn 0xnmn merged commit 5542e02 into main Jun 7, 2023
@0xnmn 0xnmn deleted the naman/cody-scope-selector branch June 7, 2023 20:01
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
- Add multi-repo content selector to Cody Web based on
[Figma](https://www.figma.com/file/HnUQ9Rf7GYDtHsFBnNdjM1/Cody%E2%80%99s-Context-Scope?type=design&node-id=53-518&t=NmT0MUWyx6zG8emz-0)
designs.
- Auto-infer scope from currently opened markdown files.
- Auto-infer readme.md content from the repo home page.

https://www.loom.com/share/340bd0e72bc5477ab517ce8143838a47

## Test plan

- visit /cody
- click on add repostiories
- search of repos & select
- ask cody a question
- reload page the the context should persist
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants