Cody code is being moved to https://github.com/sourcegraph/cody. This PR
removes the moved code and configures this repository to use the
`@sourcegraph/cody-{shared,ui}` packages published by the new separate
Cody repository.
## Test plan
Ensure that the new separate Cody repository tests pass. Ensure that
this repository's tests pass now that it uses 2 npm packages published
by the new separate Cody repository.
This adds three recipes to the welcome chat message in VScode to help
users get started. Fixes issue #54232 .
## Test plan
Open Cody. A new chat now has buttons. Clicking the buttons starts those
recipes.
---------
Co-authored-by: Beatrix <beatrix@sourcegraph.com>
Required adding a few import ignore directives in
`client/web/BUILD.bazel`. @jbedard is working on a fix for those. Has to
do with tsconfig paths. Fix will land in a future release.
## Test plan
5.4.11 output:
```
$ bazel configure
Updating BUILD files for protobuf, go, javascript
WARN[0000] Failed to load base tsconfig file @sourcegraph/tsconfig: open /Users/greg/aspect/sourcegraph/sourcegraph/@sourcegraph/tsconfig: no such file or directory
client/app-shell/src/app-shell.tsx parse error(s):
50: Top-level await is currently not supported with the "iife" output format
Failed to parse tsconfig file client/completions-review-tool/tsconfig.json: ERR: position:298 object key must be string pos:298 :
933 BUILD files visited
0 BUILD files updated
```
5.5.2 output has some new spam as well:
```
$ bazel configure
Updating BUILD files for protobuf, go, javascript
WARN[0000] Failed to load base tsconfig file @sourcegraph/tsconfig: open /Users/greg/aspect/sourcegraph/sourcegraph/@sourcegraph/tsconfig: no such file or directory
Failed to parse tsconfig file client/completions-review-tool/tsconfig.json: ERR: position:298 object key must be string pos:298 :
client/web/src/globals.d.ts:
17: }
^
client/web/src/storm/backend/route-loader.ts:
41: usePreloadedQueryData: () => ReturnType<typeof useSuspenseQuery<D, V>>
^
41: usePreloadedQueryData: () => ReturnType<typeof useSuspenseQuery<D, V>>
^
934 BUILD files visited
0 BUILD files updated
```
Closes#52597
This PR adds a new status bar item for Cody that we can use as a global
loading indicator (helpful for completions) and an easy way to
enable/disable features. More features coming soon!
As a follow-up we should make sure that all of these three features can
be turned on/off without having to reload the editor cc @abeatrix
@lrhacker
## Test plan
https://github.com/sourcegraph/sourcegraph/assets/458591/ab2b5a5e-6b38-4010-92f1-1796ef0a3c10
<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
---------
Co-authored-by: Tom Ross <tomross8@googlemail.com>
Co-authored-by: Beatrix <68532117+abeatrix@users.noreply.github.com>
Co-authored-by: Tim Lucas <t@toolmantim.com>
This PR closes#52544, #52848, #52889 and #52890.
The issues mostly overlapped, so I handled it in this PR.
Changes made:
1. Add history to the history list on each new conversation started.
2. Display the last human message in history instead of the assistant
message.
3. Add a delete button to delete individual chats from history.
4. Load the most recent chat, if available, from the history.
5. Fix the loading of context files.
6. Load the history messages to the end of the scroll position.
## Test plan
All E2E tests have passed.
https://www.loom.com/share/3dca98dd0db94c298df38ab79c5e72d1
---------
Co-authored-by: Philipp Spiess <hello@philippspiess.com>
- Revert "revert "bazel: improve ESLint rule" (#52853)"
- bazel: fix eslint custom rule so js_binary runfiles are included as
tool inputs to ctx.actions.run_shell
## Test plan
Tested locally that fix commit resolves the
```
FATAL: aspect_rules_js[js_test]: RUNFILES environment variable is not set
```
flaky issue that prompted the revert
- Custom ESLint Bazel rule now relies on `sh_test`. The build part of
the rule produces the output file with ESLint errors, and the `sh_test`
target verifies that it's empty. If it's not empty, the ESLint test
fails, and the report content is printed to stdout.
- Added additional ESLint targets to `*.js` files in the root of each
client package.
- Added additional ESLint targets for `*.story.tsx` files for client
packages with stories. It's temporary until we start building Storybook
story modules with `ts_project`.
- Disabled ESLint outside of Bazel: **10-12m job is gone!** 🎉
## Test plan
bazel test `bazel query 'attr("name", ".*_eslint$", //client/...)'`
Sorry for the big PR, but there was no other way.
This PR almost entirely re-writes the Cody web client and state
management. The old state management was powered by zustand and not
native react states. It then internally integrated the chat client,
which was non-reactive. The old chat client was just builder function,
and it was required to re-create the client with every single change.
The old client then also used callbacks to update the state at the
parent level, and the state was partially duplicated. Basically, it
needed a makeover.
- The new client is reactive and uses native react states.
- The new chat store allows having separate chat states for the sidebar
and standalone chat.
- The states are not partially duplicated at two places anymore.
- It also prepares for multi-repo scope.
- It introduces URL-based routing for /chat.
- It disables the editor widget when a message is in progress.
- It also prepares for editing any message and not just the last one.
- It also fixes the re-rendering of the whole chat on input change.
Future PRs:
- update Codebase context and context fetcher clients to support new
CodyClientScope aka multi-repo context
- implement cody scope selector UI
- save the scope with each interaction and the current scope with the
transcript.
- load the current scope from the transcript on load.
- show scope with each human message.
- show scope selector with edit message form.
- Allow editing of any message and not just the last.
## Test plan
- visit /cody on web and check if messages, history and all other
actions are working as expected.
- Check same for vs code & app.
- Upgraded `aspect_bazel_lib`, `aspect_rules_js` and `aspect_rules_ts`
to the latest versions.
- Ran [bazel run
//.aspect/bazelrc:update_aspect_bazelrc_presets](40a7422385)
- Added `eslint_config` macro for client package eslint configuration
`js_library` targets.
- Implemented the custom ESLint rule, which copies `srcs` with
dependencies and **declarations** to the Bazel to lint them. This way,
we maintain the ability to do type-aware linting in Bazel.
- Added a custom ESLint formatter used in Bazel to print out relative
paths in ESLint reports.
In the follow-up PR, I will look into improvements suggested by
@alexeagle that should allow us to convert ESLint build targets into
test targets and gracefully manage linting failures.
## Test plan
1. CI
2. `bazel build $(bazel query 'kind("_eslint_test_with_types",
//client/...)')`
Closes#51575.
Some issues that were fixed:
- Down arrow did not navigate history forward
- You couldn't navigate the WIP prompt with the up arrow as it would
navigate history always; now we only navigate to backwards when the up
arrow is pressed at the start of the prompt and forwards then the down
arrow is pressed at the end of the prompt
- There was a typo that prevented the history index from being set
properly in VSCode
- Input history wasn't populated on the web
## Test plan
Tested history navigation in VSCode and web.
No more "Fetching context" text, which just adds noise IMO.
[Slack
thread](https://sourcegraph.slack.com/archives/C052G9Y5Y8H/p1682136846050229):
As a user I don’t like the Fetching context or Working on it
(https://github.com/sourcegraph/sourcegraph/pull/50969/files#r1174224321)
text displaying. It just adds noise. Maybe we could show something if
it’s taking a long time, and we should show errors, but otherwise, I’m
just like “I get it, it is thinking and blinking, I don’t need to see
other text”. Anyone else agree?
## Test plan
n/a
---------
Co-authored-by: Philipp Spiess <hello@philippspiess.com>
Fix a bunch of things in Cody Web UI:
1. Input box overlaps the last chat message.
2. `<code>` in message overflows.
3. Switching to the old chat doesn't scroll down to the latest message.
## Test plan
- visit cody web chat
This replaces #51144
The previous implementation was limiting in various factors:
- The `sanitze` option of the Markdown library is deprecated since
forever. It actually logged a bunch of nasty warnings to the console.
The recommended way to deal with escaping is by using a library (like
`DOMPurify` in our case) _after_ the markdown step.
We already do the above, hooray! This means that in no point in time did
we ever had a XSS vulnerability but only a style related issue.
The problem is that sometimes Cody emits HTML outside of code blocks and
any visual HTML is allowed by our current `DOMPurify` config. We could
change this, but then we would have to maintain a complicated allowlist
for all HTML tags generated in the markdown transformation and all
compliant tags are removed. In addition to that, Cody could still emit
these HTML events outside of code blocks. E.g. use this prompt "Write
some HTML but don't use Markdown to format it". The rule of thumb here
is that anything from cody should be relayed to the user 1:1, so we can
neither remove nor "render" some tags (even if they are just empty
`<div>` that do nothing). When Cody returns `<div>I’m a banana</div>` we
want to surface the `<div>` string to the user.
- We have to support two use cases where we insert HTML into the message
deliberately (and we will have more of these as we add more code intel
goodies): Error messages and hallucination detection. I wanted to keep
these abstractions similar to where they are though, as anything more
complicated would require bigger restructurings.
Because of this, I came up with a different implementation: We have two
clear boundaries of where these messages come from: Either form the Cody
API endpoint _or_ from the user input (because similarly, if a user
types `<div>I’m a banana</div>` into the input box and presses enter, it
would be strange if only `I’m a banana` shows up in the prompt.).
At these distinct places, we now call `escapeCodyMarkdown` which will
replace `<` and `>` to `<` and `>` respectively (as long as the
content is outside of a code block where we just leave it as-is.
Remember: This is not a security related XSS prevention. We already do
that because the output from the markdown parser is being escaped but
`DOMPurify`. The goal here is just to preserve HTML tags in the prompt
and relay them to the end user.
## ToDo
- [ ] Apply the same fix to the web client
## Test plan
<img width="587" alt="Screenshot 2023-04-26 at 14 27 41"
src="https://user-images.githubusercontent.com/458591/234578592-dfb1ff15-53b2-4b9b-b342-6e9dfeb55206.png">
<img width="619" alt="Screenshot 2023-04-26 at 14 17 13"
src="https://user-images.githubusercontent.com/458591/234578597-9dc23401-62ac-43ca-b273-632c6fb9b2cf.png">
<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
---------
Co-authored-by: David Veszelovszki <veszelovszki@gmail.com>
Closes#50974
## Test plan
Tested locally in VSCode and it *seems* to work - feel free to suggest
additional testing methodologies :)
---------
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>