forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cody: development branch (sourcegraph#49761)
## Test plan * Chatting and executing recipes should still work. * `pnpm run build && pnpm run test:integration && pnpm run test:unit` should be green. ## App preview: - [Web](https://sg-web-cody-main.onrender.com/search) Check out the [client app preview documentation](https://docs.sourcegraph.com/dev/how-to/client_pr_previews) to learn more. --------- Co-authored-by: Beyang Liu <[email protected]> Co-authored-by: Dominic Cooney <[email protected]> Co-authored-by: Beatrix <[email protected]>
- Loading branch information
1 parent
3c90dda
commit 50c6b27
Showing
172 changed files
with
3,137 additions
and
4,693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,3 @@ cmd/sitemap | |
# temporary ignores | ||
|
||
internal/cmd/progress-bot | ||
client/cody |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules/ | ||
tsconfig.tsbuildinfo | ||
.vsix | ||
.envrc | ||
out/ | ||
.vscode-test/ | ||
dist/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Contributing to the Sourcegraph Cody VS Code Extension | ||
|
||
1. Update your VS Code user setting to turn on debugging mode: | ||
|
||
```json | ||
"cody.debug": true, | ||
``` | ||
|
||
2. Run `pnpm install` from the **root** of this repository | ||
3. Select `Launch Cody Extension` from the dropdown menu in the `RUN AND DEBUG` sidebar | ||
1. Remove `node_modeules` from `root` and `client/cody` before re-running `pnpm install` if the start up failed | ||
4. Refresh the extension to see updated changes | ||
|
||
## File structure | ||
|
||
- `src`: source code of the components for the extension | ||
host | ||
- `webviews`: source code of the extension UI (webviews), | ||
build with Vite and rollup.js using the `vite.config.ts` file at directory | ||
root | ||
- `dist`: build outputs from both webpack and vite | ||
- `resources`: everything in this directory will be move to | ||
the ./dist directory automatically during build time for easy packaging | ||
- `index.html`: the entry file that Vite looks for to build | ||
the webviews. The extension host reads this file at run time and replace | ||
the variables inside the file with webview specific uri and info | ||
|
||
## Testing | ||
|
||
1. Unit tests: | ||
|
||
```shell | ||
$ cd client/cody | ||
$ pnpm test:unit | ||
``` | ||
|
||
2. Integration tests: | ||
|
||
```shell | ||
$ cd client/cody | ||
$ pnpm test:integration | ||
``` | ||
|
||
## Release Process | ||
|
||
Follow the steps below to package and publish the VS Code extension. | ||
|
||
> NOTE: Since the extension has already been bundled during build, we will need to add the `--no-dependencies` flag to the `vsce` step during the packaging step to exclude the npm dependencies ([source](https://github.com/microsoft/vscode-vsce/issues/421#issuecomment-1038911725)) | ||
### Prerequisite | ||
|
||
- Install the [VSCE CLI tool](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#vsce) | ||
- Obtain the marketplace token for publishing Cody from 1Password | ||
|
||
### Release Steps | ||
|
||
1. Increment the `version` in [`package.json`](package.json) and then run: | ||
|
||
```shell | ||
$ cd client/cody | ||
$ pnpm run vsce:package | ||
``` | ||
|
||
2. To try the packaged extension locally, disable any other installations of it and then run: | ||
|
||
```sh | ||
$ code --install-extension dist/cody.vsix | ||
``` | ||
|
||
3. To publish the packaged extension to the VS Code Extension Marketplace: | ||
|
||
```sh | ||
$ cd client/cody | ||
$ pnpm run vsce:publish | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,90 @@ | ||
# Cody | ||
<div align="center"> | ||
<p>Cody: An AI-Powered Programming Assistant</p> | ||
<a href="https://docs.sourcegraph.com/cody">Docs</a> • | ||
<a href="https://discord.gg/s2qDtYGnAE">Discord</a> • | ||
<a href="https://twitter.com/sourcegraph">Twitter</a> | ||
<br /><br /> | ||
<a href="https://srcgr.ph/discord"> | ||
<img src="https://img.shields.io/discord/969688426372825169?color=5765F2" alt="Discord" /> | ||
</a> | ||
<a href="https://marketplace.visualstudio.com/items?itemName=sourcegraph.cody-ai"> | ||
<img src="https://img.shields.io/vscode-marketplace/v/sourcegraph.cody-ai.svg?label=vs%20marketplace" alt="VS Marketplace" /> | ||
</a> | ||
</div> | ||
|
||
## Usage and features | ||
## Cody Enterprise | ||
|
||
- Autocomplete: `alt-\` to show autocompletion suggestions | ||
- Chatbot: Click the robot icon in the primary side panel | ||
Cody is in private alpha (experimental) at this stage. Please contact your techical advisor or [signup here](https://sourcegraph.typeform.com/to/pIXTgwrd?typeform-source=t.co) to get access. | ||
|
||
## Install | ||
We have limited capacity to onboard customers at first, but we're working hard to open Cody up to the world fast! | ||
|
||
See the [#announce-cody Slack channel](https://app.slack.com/client/T02FSM7DL/C04MZPE4JKD) for instructions. | ||
## What is Cody? | ||
|
||
## Development | ||
|
||
There are four separate components: | ||
|
||
- `vscode-codegen`: the VS Code extension | ||
- `server`: the server that serves the completion and chat endpoints | ||
- `embeddings`: generates the embeddings and serves the embeddings endpoint | ||
- `common`: a library shared by the extension and server with common types | ||
|
||
### Setup | ||
|
||
1. Install [asdf](https://asdf-vm.com/) | ||
1. Run `asdf install` (if needed, run `asdf plugin add NAME` for any missing plugins) | ||
1. Set the following environment variables: | ||
|
||
``` | ||
export OPENAI_API_KEY=sk-... | ||
export ANTHROPIC_API_KEY=... | ||
export EMBEDDINGS_DIR=/path/to/embeddings/dir | ||
export CODY_USERS_PATH=/path/to/users.json | ||
``` | ||
|
||
See [Cody secrets](https://docs.google.com/document/d/1b5oqnE0kSUrgrb4Z2Alnhfods5e4Y5gx_oaIcQH4TZM/edit) (internal Google Doc) for these secret values. | ||
Cody is your hyper-intelligent programming sidekick - an AI assistant developed by Sourcegraph to supercharge your productivity as a developer. | ||
|
||
1. Install dependencies: | ||
## Highlighted features | ||
|
||
```shell | ||
brew install wget # Use your system's package manager | ||
pnpm install | ||
(cd embeddings && pip3 install -r requirements.txt) | ||
``` | ||
- Answer questions about your codebase instantly | ||
- Generate documentation and unit tests on demand | ||
- Write code snippets and prototypes for you | ||
- Translate comments and functions in your code between languages | ||
|
||
### Build and run | ||
## Installation | ||
|
||
Build and watch the TypeScript code (if you're running VS Code, this runs automatically in the background): | ||
Here are the ways to install Cody in Visual Studio Code: | ||
|
||
1. `pnpm exec tsc --build` | ||
### In Visual Studio Code | ||
|
||
Run the server: | ||
1. Open the Extensions tab on the left side of VS Code (<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd>). | ||
2. Search for `Sourcegraph Cody` and click Install. | ||
3. Once installed, **reload** VS Code. | ||
4. After reloading, click the Cody icon in the VS Code Activity Bar to open the extension. | ||
- Alternatively, you can launch the extension by pressing <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> and searching for "Cody: Focus on chat view" and searching for "Cody: Focus on chat view". | ||
|
||
1. `cd server && CODY_PORT=9300 pnpm run dev` | ||
### Through the Visual Studio Marketplace | ||
|
||
Run the embeddings API: | ||
1. Install Cody from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sourcegraph.cody-ai). | ||
2. After installing the plugin, click the Cody icon in the VS Code Activity Bar to open the extension. | ||
|
||
1. Generate embeddings, including for at least 1 codebase. See [embeddings/README.md](embeddings/README.md). | ||
## Setting up the Cody extension | ||
|
||
For example: | ||
To set up the Cody extension, you will need to enter the URL of your Sourcegraph instance and an access token used for authentication. | ||
|
||
```shell | ||
cd embeddings | ||
python3 embed_repos.py --repos https://github.com/sourcegraph/conc --output-dir=$EMBEDDINGS_DIR | ||
python3 embed_context_dataset.py --output-dir=$EMBEDDINGS_DIR | ||
``` | ||
1. Open the Cody chat view by clicking on the Cody icon in the sidebar. | ||
2. If you are setting up Cody for the first time, you should see the terms of service. | ||
3. To proceed, read the terms and click "I accept", if you accept the terms of service. | ||
4. Aftewards, you should see the login screen, where you have to enter the URL of your Sourcegraph instance and an access token used for authentication. | ||
5. Once you have filled out the login form, click the Login button to login to Cody. | ||
|
||
If you do this, ensure your `CODY_USERS_PATH` file has `github.com/sourcegraph/conc` in the `accessibleCodebaseIDs`. | ||
### Generating a Sourcegraph access token | ||
|
||
1. `cd embeddings && asdf env python uvicorn api:app --reload --port 9301` | ||
1. Go to your Sourcegraph instance. | ||
2. In your account settings, navigate to `Access tokens`. | ||
3. Click `Generate new token`. | ||
4. Copy the token. | ||
|
||
### Developing the [VS Code extension](vscode-codegen/) | ||
### Codebase | ||
|
||
1. Change your VS Code user settings to use your local dev servers: | ||
To enable codebase-aware answers, you have to set the codebase setting to let Cody know which repository you are working on in the current workspace. You can do that as follows: | ||
|
||
```json | ||
"cody.serverEndpoint": "http://localhost:9300", | ||
"cody.embeddingsEndpoint": "http://localhost:9301", | ||
"cody.debug": true, | ||
``` | ||
1. Open the VS Code workspace settings by pressing <kbd>Cmd</kbd>, (or File > Preferences (Settings) on Windows & Linux). | ||
2. Search for the "Cody: Codebase" setting. | ||
3. Enter the repository name as listed on your Sourcegraph instance. | ||
1. For example: `github.com/sourcegraph/sourcegraph` without the `https` protocol | ||
|
||
2. Run `pnpm install` from the root of this repository | ||
3. Select `Launch Cody Extension` from the dropdown menu in the `RUN AND DEBUG` sidebar | ||
1. Remove `node_modeules` and rerun `pnpm install` if the start up failed | ||
4. Refresh the extension to see updated changes | ||
Setting the codebase will edit the `.vscode/settings.json` file in your repository, which you can then commit and save for future usage. | ||
|
||
#### File structure | ||
## Extension Settings | ||
|
||
- `vscode-codegen/src`: source code of the components for the extension | ||
host | ||
- `vscode-codegen/webviews`: source code of the extension UI (webviews), | ||
build with Vite and rollup.js using the `vscode-codegen/vite.config.ts` file at directory | ||
root | ||
- `vscode-codegen/dist`: build outputs from both webpack and vite | ||
- `vscode-codegen/resources`: everything in this directory will be move to | ||
the ./dist directory automatically during build time for easy packaging | ||
- `vscode-codegen/index.html`: the entry file that Vite looks for to build | ||
the webviews. The extension host reads this file at run time and replace | ||
the variables inside the file with webview specific uri and info | ||
This extension contributes the following settings: | ||
|
||
### Testing the [VS Code extension](vscode-codegen/) | ||
| Setting | Description | Example | | ||
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | | ||
| cody.enabled | Enable or disable Cody. | true/false | | ||
| cody.serverEndpoint | URL of the Sourcegraph instance. | "https://example.sourcegraph.com" | | ||
| cody.codebase | Name of the repository opened in the current workspace. Use the same repository name as listed on your Sourcegraph instance. | "github.com/sourcegraph/sourcegraph" | | ||
| cody.useContext | Context source for Cody. One of: "embeddings", "keyword", "blended", or "none". | "embeddings" | | ||
|
||
``` | ||
$ cd vscode-codegen | ||
$ pnpm test | ||
``` | ||
|
||
### Publishing the [VS Code extension](vscode-codegen/) | ||
|
||
Increment the `version` in [`vscode-codegen/package.json`](vscode-codegen/package.json) and then run: | ||
|
||
```shell | ||
cd vscode-codegen | ||
pnpm run vsce:package | ||
|
||
# To try the packaged extension locally, disable any other installations of it and then run: | ||
# code --install-extension dist/kodj.vsix | ||
|
||
# To publish the packaged extension to the VS Code Extension Marketplace: | ||
pnpm exec vsce publish --packagePath dist/kodj.vsix | ||
``` | ||
## Development | ||
|
||
> NOTE: Since the extension has already been bundled, we will need to add the `--no-dependencies` flag during the packaging step to exclude the npm dependencies ([source](https://github.com/microsoft/vscode-vsce/issues/421#issuecomment-1038911725)) | ||
Please see the [CONTRIBUTING](./CONTRIBUTING.md) document if you are interested in contributing to our code base. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.