[Cody GA Docs] Guides on Cody Capabilities — Chat, Autocomplete, Bug Fixes, Commands (#58288)

* Guide on Cody Chat feature

* Guide on Cody Autocomplete feature

* Guide on Cody Commands

* Guide on Cody Custom Commands

* Guide on Debug Code

* Add debug code guide for Cody

* Add videos

* Add redirect

* Fix cody json

* Add code actions

* Rmv custom commands from nav

* Rmc file cc

* Update doc/cody/capabilities/chat.md

Co-authored-by: Tim Lucas <t@toolmantim.com>

* add .md

* Broken links

* Broken links

* Broken links

* Rmv beta label

* Add changes to Cody docs

---------

Co-authored-by: Tim Lucas <t@toolmantim.com>
This commit is contained in:
Maedah Batool 2023-12-11 09:33:02 -08:00 committed by GitHub
parent c96a3618bb
commit 51dc503221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 517 additions and 436 deletions

22
.vscode/cody.json vendored
View File

@ -1,23 +1,3 @@
{
"title": "[Experimental] Custom Workspace Commands",
"description": "This file showcases how to build custom commandss for Cody by Sourcegraph in VS Code.",
"doc": "For more information, see https://sourcegraph.com/notebooks/Tm90ZWJvb2s6MzA1NQ==",
"commands": {
"example-generate-readme": {
"description": "(example) Generate README.md for Current Directory",
"prompt": "Write a detailed README.md file to document the code in the same directory as my current selection. Summarize what the code in this directory is meant to accomplish. Explain the key files, functions, classes, and features. Use Markdown formatting for headings, code blocks, lists, etc. to make it organized and readable. Aim for a beginner-friendly explanation that gives a developer unfamiliar with the code a good starting point to understand it. Ensure to include: - Overview of directory purpose - Functionality explanations - Relevant diagrams or visuals if helpful. Write the README content clearly and concisely using complete sentences and paragraphs based on the shared context. Use proper spelling, grammar, and punctuation throughout. Surround your full README text with triple backticks so it renders properly as a code block. Do not make assumptions or fabricate additional details.",
"context": {
"currentDir": true,
"selection": true
}
},
"commit-message-suggestion": {
"description": "Commit Message Suggestion",
"prompt": "Suggest a informative commit message by summarizing code changes from the shared command output. The commit message should follow the conventional commit format and provide meaningful context for future readers.",
"context": {
"selection": false,
"command": "git diff"
}
}
}
"commands": {}
}

View File

@ -419,3 +419,6 @@
/cody/core-concepts/cody_gateway#configuring-custom-models /cody/core-concepts/cody-gateway#configuring-custom-models 308
/cody/core-concepts/cody_gateway#rate-limits-and-quotas /cody/core-concepts/cody-gateway#rate-limits-and-quotas 308
/cody/core-concepts/cody_gateway#privacy-and-security /cody/core-concepts/cody-gateway#privacy-and-security 308
# Custom Commands redirects
/cody/custom-commands /cody/capabilities/commands#custom-commands 308

View File

@ -1,143 +0,0 @@
<style>
.demo{
display: table;
width: 35%;
margin: 0.5em;
padding: 1rem 1rem;
color: var(--text-color);
border-radius: 4px;
border: 1px solid var(--sidebar-nav-active-bg);
padding: 1rem;
padding-top: 1rem;
background-color: var(--sidebar-nav-active-bg);
}
</style>
# Cody capabilities
<p class="subtitle">Learn and understand more about Cody's features and core AI functionality.</p>
## Autocomplete
Cody suggests completions as you type using context from your code, such as your open files and file history. Its powered by the latest instant LLM models for accuracy and performance.
Autocomplete supports any programming language because it uses LLMs trained on broad data. We've found that it works exceptionally well with JavaScript, TypeScript, Python, and Go code.
![Example of Cody autocomplete. You see a code snippet starting with async function getWeather(city: string) { and Cody response with a multi-line suggestion using a public weather API to return the current weather ](https://storage.googleapis.com/sourcegraph-assets/website/Product%20Animations/GIFS/cody-completions-may2023-optim.gif)
### Configure autocomplete on an enterprise Sourcegraph instance
By default, a fully configured Sourcegraph instance picks a default LLM to generate code autocomplete. Custom models can be used for Cody autocomplete via the `completionModel` option inside the `completions` site config.
We also recommend reading the [Enabling Cody on Sourcegraph Enterprise](overview/enable-cody-enterprise.md) guide before you configure the autocomplete feature.
> NOTE: Self-hosted customers need to update to a minimum of version 5.0.4 to use autocomplete.
<br />
> NOTE: Cody autocomplete currently only work with Anthropic's Claude Instant model. Support for other models will be coming later.
### Access autocomplete logs
VS Code logs can be accessed via the **Outputs** view. To access autocomplete logs, you need to enable Cody logs in verbose mode. To do so:
- Go to the Cody Extension Settings and enable: `Cody Debug: Enable` and `Cody Debug: Verbose`
- Restart or reload your VS Code editor
- You can now see the logs in the Outputs view
- Open the view via the menu bar: `View > Output`
- Select **Cody by Sourcegraph** from the dropdown list
![View Cody's autocomplete logs from the Output View in VS Code](https://storage.googleapis.com/sourcegraph-assets/Docs/view-autocomplete-logs.png)
## Chat
Chat lets you ask Cody general programming questions or questions about your specific code. You can chat with Cody in the `Chat` panel of the editor extensions or with the `Ask Cody` button in the Sourcegraph UI.
Cody uses several search methods (including keyword and semantic search) to find files in your codebase that are relevant to your chat questions. It then uses context from those files to provide an informed response based on your codebase. Cody also tells you which code files it reads to generate its responses.
Context retrieval isn't perfect, and Cody occasionally uses incorrect context or hallucinates answers. When Cody returns an incorrect response, it is often worth asking the question again slightly differently to see if Cody can find better context the second time.
Cody's chat function can handle use cases like:
- Ask Cody to generate an API call. Cody can gather context on your API schema to inform the code it writes
- Ask Cody where a specific component is defined within your codebase. Cody can retrieve and describe the files where that component is written
- Ask Cody questions that require an understanding of multiple files, such as how data is populated in a React app. Cody can find the React component definitions to understand what data is being passed and where it originates
More specifically, Cody can answer questions like:
- How is our app's secret storage implemented on Linux?
- Where is the CI config for the web integration tests?
- Can you write a new GraphQL resolver for the AuditLog?
- Why is the UserConnectionResolver giving an error `unknown user`, and how do I fix it?
![Example of Cody chat. You see the user ask Cody to describe what a file does, and Cody returns an answers that explains how the file is working in the context of the project.](https://storage.googleapis.com/sourcegraph-assets/cody/Docs/Sept2023/Context_Chat_SM.gif)
<div class="getting-started">
<a class="demo text-center" target="_blank" href="https://twitter.com/beyang/status/1647744307045228544">View Demo</a>
</div>
### Inline chat and code edits
You can also open Cody's chat inline in VS Code using the `+` icon. This opens a chat box that can be used for general chat questions, code edits, and refactors. Select a code snippet to ask Cody for an inline code edit, then type `/edit` plus your desired code change. Cody will generate edits, which you can accept or reject with the `Apply` button.
You can also use the or `/touch` command in the inline chat box if you'd like Cody to place its output in a new file.
![Example of Cody inline code fix ](https://storage.googleapis.com/sourcegraph-assets/website/Product%20Animations/GIFS/cody_inline_June23-sm.gif)
Examples of `/edit` instructions Cody can handle:
- Factor out any common helper functions (when multiple functions are selected)
- Use the imported CSS module's class `n`
- Extract the list item to a separate React component
- Handle errors in this code better
- Add helpful debug log statements
- Make this work (and yes, it often does work—give it a try!)
> NOTE: Inline chat functionality is currently only available in the VS Code extension. The `/edit` command was called `/fix` prior to version 0.10.0 of the VS Code extension.
<div class="getting-started">
<a class="demo text-center" target="_blank" href="https://twitter.com/sqs/status/1647673013343780864">View Demo</a>
</div>
## Commands
**Commands** allow you to run common actions quickly. Commands are predefined, reusable prompts accessible by hotkey from within the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=sourcegraph.cody-ai). Like autocomplete and chat, commands will search for context in your codebase to provide more contextually aware and informed answers (or to generate more idiomatic code snippets).
The commands available in VS Code include:
- Document Code
- Explain Code
- Generate Unit Tests
- Code Smell
![Cody Commands in VS Code](https://storage.googleapis.com/sourcegraph-assets/Docs/cody-commands.png)
There are three ways to run a command in VS Code:
1. Type `/` in the chat bar. Cody will then suggest a list of available commands
2. Right click and select `"Cody"` > Choose a command from the list
3. Use the predefined command hotkey: `⌥` + `C` / `Alt` + `C`
> NOTE: This functionality is also available in the JetBrains extension under the name `Recipes`. To access it, navigate to the `Recipes` panel (next to the `Chat` panel), and you can find each available recipe as a button within the UI.
![Example of the Cody 'Explain Code' command. The user highlights a section of code, then uses the hotkey to open the commands menu, then selects the command.](https://storage.googleapis.com/sourcegraph-assets/cody/Docs/Sept2023/Explain_Code_SM.gif)
### Custom commands <span class="badge badge-experimental">Experimental</span>
**Custom commands** let you save your quick actions and prompts for Cody based on your common workflows. They are defined in JSON format and allow you to call CLI tools, write custom prompts, and select context to be sent to Cody. This provides a flexible way to tailor Cody to your needs.
![Cody Custom Commands in VS Code](https://storage.googleapis.com/sourcegraph-assets/Docs/create-custom-commands.png)
You can invoke custom commands with the same hotkey as predefined commands. Alternatively, you can right-click the selected code, open the Cody context menu, and select the `Custom Commands (Experimental)` option.
![Example of a user creating a custom "/Variables" command. The user creates a command that automatically makes the variable names in selected code more helpful.](https://storage.googleapis.com/sourcegraph-assets/cody/Docs/Sept2023/Custom_Command_SM.gif)
### Defining commands in the `cody.json` file
You can define custom commands for Cody in the `cody.json` file. To make commands only available for a specific project, create the `cody.json` file in that project's `.vscode` directory. When you work on that project, these workspace-specific custom commands will be available.
To make custom commands globally available across multiple projects, create a new `cody.json` file in your home directory's `.vscode` folder. These global custom commands will be available in Cody in any workspace.
## Language support
Cody uses LLMs trained on broad code, and we've found it to support all common programming languages effectively. However, the quality of autocompletion and other features may vary based on how well the underlying LLM model was trained in a given language.

View File

@ -0,0 +1,64 @@
# Autocomplete
<p class="subtitle">Learn how Cody helps you get contextually-aware autocompletions for your codebase.</p>
Cody provides intelligent **autocomplete** suggestions as you type using context from your code, such as your open files and file history. Cody autocompletes single lines or whole functions in any programming language, configuration file, or documentation. Its powered by the latest instant LLM models for accuracy and performance.
Autocomplete supports any programming language because it uses LLMs trained on broad data. It works exceptionally well for Python, Go, JavaScript, and TypeScript.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/cody-in-action.mp4" type="video/mp4">
</video>
## Prerequisites
To view how Cody provides code completions , you'll need to have the following:
- An active Sourcegraph account (free or enterprise)
- A supported editor extension (VS Code, JetBrains, and Neovim) installed
## Working with code autocomplete
The autocomplete feature is enabled by default on all IDE extensions, i.e., VS Code, JetBrains, and Neovim. Generally, there's a checkbox in the extension settings that confirms whether the autocomplete feature is enabled or not. In addition, some autocomplete settings are optionally and explicitly supported by some IDEs. For example, JetBrains IDEs have a custom setting that allows you to:
- Enable autocompletions for specific programming languages
- Customize colors and styles of the autocomplete suggestions
Once ready, you can start typing and Cody will automatically provide suggestions and context-aware completions based on your coding patterns and the code context. These autocomplete suggestions appears as grayed text. To accept the suggestion, press the `Enter` or `Tab` key.
## Configure autocomplete on an Enterprise Sourcegraph instance
By default, a fully configured Sourcegraph instance picks a default LLM to generate code autocomplete. Custom models can be used for Cody autocomplete based on your specific requirements. To do so:
- Go to the **Site admin** of your Sourcegraph instance
- Navigate to **Configuration > Site configuration**
- Here, edit the `completionModel` option inside the `completions`
- Click the **Save** button to save the changes
> NOTE: Cody autocomplete works only with Anthropic's Claude Instant model. Support for other models will be coming later.
> NOTE: Self-hosted customers must update to version 5.0.4 or more to use autocomplete.
Before configuring the autocomplete feature, it's recommended to read more about [Enabling Cody on Sourcegraph Enterprise](../overview/enable-cody-enterprise.md) guide.
Cody Autocomplete goes beyond basic suggestions. It understands your code context, offering tailored recommendations based on your current project, language, and coding patterns. Let's view a quick demo using the VS Code extension.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/contexual-autocpmplete.mp4" type="video/mp4">
</video>
Here, Cody provides suggestions based on your current project, language, and coding patterns. Initially, the `code.js` file is empty. Start writing a function for `bubbleSort`. As you type, Cody suggests the function name and the function parameters.
Cody automatically suggests the next few code snippets for every new line based on your current context, i.e., functions for `insertionSort` and `selectionSort`.
## Access autocomplete logs
VS Code logs can be accessed via the **Outputs** view. To access autocomplete logs, you need to enable Cody logs in verbose mode. To do so:
- Go to the Cody Extension Settings and enable: `Cody Debug: Enable` and `Cody Debug: Verbose`
- Restart or reload your VS Code editor
- You can now see the logs in the Outputs view
- Open the view via the menu bar: `View > Output`
- Select **Cody by Sourcegraph** from the dropdown list
![View Cody's autocomplete logs from the Output View in VS Code](https://storage.googleapis.com/sourcegraph-assets/Docs/autocomplete-logs.png)

View File

@ -0,0 +1,66 @@
# Chat
<p class="subtitle">Use Cody's chat to get contextually-aware answers to your questions.</p>
Cody **chat** allows you to ask coding-related questions about your entire codebase or a specific code snippet. You can do it from the **Chat** panel of the supported editor extensions (VS Code, JetBrains, and Neovim) or via the **Ask Cody** button in the web app.
The feature allows you to have an engaging conversation experience with Cody across VS Code, JetBrains, and Neovim. Key functionalities in the VS Code extension include support for multiple simultaneous chats, enhanced chat context configurability through `@` commands, detailed visibility into the code that Cody read before providing a response, and more.
You can learn more about the IDE support for these functionalities in the [feature parity reference](./../feature-reference.md#chat).
## Prerequisites
To use Cody's chat, you'll need to have the following:
- An active Sourcegraph account (free or enterprise)
- A supported editor extension (VS Code, JetBrains, and Neovim) installed
## How does chat work?
Cody can use several methods (including keyword search and optional embeddings context) to ask relevant questions. For VS Code extension users, Cody also uses context from the files to provide an informed response based on your codebase. Cody also tells you which code files it reads to generate its responses.
Cody can assist you with various use cases by answering questions such as:
- Generating an API call: Cody can analyze your API schema to provide context for the code it generates
- Locating a specific component in your codebase: Cody can identify and describe the files where a particular component is defined
- Handling questions that involve multiple files, like understanding data population in a React app: Cody can locate React component definitions, helping you understand how data is passed and where it originates
## Ask Cody your first question
Let's use Cody VS Code extension's chat interface to answer your first question.
- Click the Cody icon in the sidebar to view the detailed panel
- Next, click the icon for **New Chat** to open a new chat window
- Here, you can directly write your question or type slash `/` to select one of the commands and then press **Enter**
For example, ask Cody "What does this file do?"
Cody will take a few seconds to process your question, providing contextual information about the files it reads and generating the answer.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/ask-cody-question.mp4" type="video/mp4">
</video>
## Ask Cody to write code
The chat feature can also write code for your questions. For example, in VS Code, ask Cody to "write a function that sorts an array in ascending order".
You are provided with code suggestions in the chat window along with the following options for using the code.
- The **Copy Code** icon to your clipboard and paste the code suggestion into your code editor
- Insert the code suggestion at the current cursor location by the **Insert Code at Cursor** icon
- The **Save Code to New File** icon to save the code suggestion to a new file in your project
>NOTE: These options are only available for VS Code extension users.
During the chat, if Cody needs additional context, it can ask you to provide more information with a follow-up question. If your question is beyond the scope of the context, Cody will ask you to provide an alternate question aligned with the context of your codebase.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/cody-write-code.mp4" type="video/mp4">
</video>
### Chat vs Commands
There could be scenarios when Cody's chat might not be able to answer your question. Or the answer lacks the context that you need. In these cases, it's recommended to use Cody **commands**. Cody's responses to commands might be better at times than responses to chats since they've been pre-packaged and prompt-engineered.
> NOTE: Commands are only supported in the VS Code and JetBrains extension.

View File

@ -0,0 +1,291 @@
# Commands
<p class="subtitle">Learn how Commands help you kick-start with reusable prompts.</p>
Cody offers quick, ready-to-use **commands** for common actions to write, describe, fix, and smell code. These allow you to run predefined actions with smart context-fetching anywhere in the editor. Like autocomplete and chat, commands will search for context in your codebase to provide more contextually aware and informed answers.
Commands are available in all Cody-supported IDE extensions (VS Code, JetBrains, and Neovim) and the Sourcegraph web app. Commands can handle tasks like:
- Editing and fixing code (`edit`)
- Explaining code (`explain`)
- Generating unit tests (`test`)
- Writing documentation (`doc`)
- Improving code quality (`smell`)
The support for one command may vary by IDE extension. Read the [feature parity reference to learn what commands are available in your IDE](./../feature-reference.md#commands).
> NOTE: Cody's responses to commands might be better than responses to chats since they've been pre-packaged and prompt-engineered.
## Running commands
The process of running a command varies from one IDE to another. For example, in VS Code, there are three ways to run a command:
1. Type `/` in the chat bar. Cody will then suggest a list of available commands
2. Right-click on any code element and select **Cody > Choose a command from the list**
3. Use the predefined command hotkey: `⌥` + `C` / `Alt` + `C`
Commands are also available in the JetBrains extension. To access it, navigate to the `Commands` panel (next to the `Chat` panel), and you can find each available command as a button within the UI.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/commands-working.mp4" type="video/mp4">
</video>
## Custom commands
<aside class="experimental">
<p>
<span style="margin-right:0.25rem;" class="badge badge-beta">Experimental</span> Custom Commands are in the Experimental stage.
<br />
For any feedback, you can <a href="https://about.sourcegraph.com/contact">contact us</a> directly, file an <a href="https://github.com/sourcegraph/cody/issues">issue</a>, join our <a href="https://discord.com/servers/sourcegraph-969688426372825169">Discord</a>, or <a href="https://twitter.com/sourcegraphcody">create a post on X</a>.
</p>
</aside>
<!-- <aside class="beta">
<p>
<span style="margin-right:0.25rem;" class="badge badge-beta">Beta</span> Custom Commands are in the Beta stage.
<br />
For any feedback, you can <a href="https://about.sourcegraph.com/contact">contact us</a> directly, file an <a href="https://github.com/sourcegraph/cody/issues">issue</a>, join our <a href="https://discord.com/servers/sourcegraph-969688426372825169">Discord</a>, or <a href="https://twitter.com/sourcegraphcody">create a post on X</a>.
</p>
</aside> -->
**Custom Commands** allow you to create and define reusable prompts for Cody tailored to your development workflows. They are defined in `JSON` format and will enable you to call CLI tools, write custom prompts, and select context to be sent to Cody. This provides a flexible way to configure Cody to handle use cases like:
- Integrate with your build system to suggest fixes for errors/warnings in the latest build
- Analyze software dependencies output to explain compatibility or suggest upgrades
- Read in test command failures to explain and suggest fixes
- Explain code quality output like linter warnings
> NOTE: Cody supports Custom Commands only for VS Code version 0.8 and above.
### Creating a Custom Command
You can create a custom command by editing the configuration JSON file or using the command builder within the VS Code editor. To access the command builder within VS Code:
- Open the Cody commands menu (`⌥C` on Mac or `Alt-C` on Windows/Linux)
- Select **Custom commands > New Custom Command**
- Type the slash `/` name you want to use, for example, `/my-custom-command`
- Next, write a suitable description for the command in the sentence case. For example, `Compare files in open tabs` or `Explain current directory`
- Provide the relevant instructions for Cody that it will follow. This is the `prompt` that Cody will use to pass relevant context to the LLM
- Then, make one or more options for the context selection for accurate responses
- Finally, choose the location where you want to save the custom command
- Press **Enter** to complete the process, and your custom command is successfully created
- You can hit `esc` key at any time to discard a new custom command
### Running Custom Commands
You can invoke custom commands with the same hotkey as predefined commands. Once created, your custom commands will appear with the rest of the predefined commands in the list. Let's type `/my-custom-command` in the chat window, and it will appear. Now, you can run this new command on your code and get answers to your questions accordingly.
![create-new-custom-command](https://storage.googleapis.com/sourcegraph-assets/Docs/custom-command.png)
Alternatively, you can right-click the selected code and select **Cody > Custom Commands**.
### Configuring file paths
Custom Commands can be defined in the following two file paths:
- **User Settings (`~/.vscode/code.json`)**: Stored locally. Use this for personal commands to use across all your projects
- **Workspace Settings (`.vscode/cody.json`)**: Stored in projects repository. Use this to share commands with others working on the same codebase and for project-specific commands
If you select **User Settings**, the new custom command will only be available to you. If you select **Workspace Settings** (as an enterprise user), the custom command will also be available to your teammates.
See the [examples](#examples) and [configuration properties](#configuration-properties) below for more details on configuring custom commands.
### Examples
### `/commit-message`
```json
{
"commit-message": {
"description": "Commit message for current changes",
"prompt": "Suggest an informative commit message by summarizing code changes from the shared command output. The commit message should follow the conventional commit format and provide meaningful context for future readers.",
"context": {
"selection": false,
"command": "git diff --cached"
}
}
}
```
### `/compare-tabs`
```json
{
"compare-tabs": {
"description": "Compare files in opened tabs",
"prompt": "Examine the shared code snippets from my opened tabs. Then explain the relationship between the code samples by answering these questions: 1. What are the main tasks or functions the code is performing? 2. Are there any similarities in functions or logic across the samples? 3. Does one code snippet call or import another? If so, how do they interact? 4. Are there any notable differences in how they approach similar problems? 5. Overall, how are the code snippets related - do they work together as part of a larger program, solve variants of the same problem, or serve entirely different purposes?",
"context": {
"openTabs": true,
"selection": false
}
}
}
```
### `/current-dir`
```json
{
"current-dir": {
"description": "Explain current directory",
"prompt": "At a high level, explain what this directory is used for.",
"context": {
"currentDir": true,
"seleection": false
}
}
}
```
### `/latest-cody-release`
```json
{
"latest-cody-release": {
"description": "Summarize latest Cody release",
"prompt": "What is the latest stable version of Cody? Briefly summarize the changes that were included in that release based on this CHANGELOG excerpt.",
"context": {
"selection": false,
"command": "curl https://raw.githubusercontent.com/sourcegraph/cody/main/vscode/CHANGELOG.md | head -n 50"
}
}
}
```
### `/readme`
```json
{
"readme": {
"description": "Readme for current dir",
"prompt": "Write a detailed README.md file to document the code located in the same directory as my current selection. Summarize what the code in this directory is meant to accomplish. Explain the key files, functions, classes, and features. Use Markdown formatting for headings, code blocks, lists, etc. to make the it organized and readable. Aim for a beginner-friendly explanation that gives a developer unfamiliar with the code a good starting point to understand it. Make sure to include: - Overview of directory purpose - Functionality explanations - Relevant diagrams or visuals if helpful. Write the README content clearly and concisely using complete sentences and paragraphs based on the shared context. Use proper spelling, grammar, and punctuation throughout. Surround your full README text with triple backticks so it renders properly as a code block. Do not make assumptions or fabricating additional details.",
"context": {
"currentDir": true,
"selection": true
}
}
}
```
### `/recent-git-changes`
```json
{
"recent-git-changes": {
"description": "Summarize recent changes",
"prompt": "Summarize the given git changes in 3-5 sentences",
"context": {
"command": "git log -10 --pretty=format:'%h - %an: %s' --stat",
"selection": false
}
}
}
```
### Configuration properties
#### `commands` (required)
- An object containing the commands
- Type: `object`
- Example: `{ "commands": {} }`
#### `commands.<id>` (required)
- The slash name used for the command
- Type: `string`
- Example: `"summarize-git-changes"`
#### `commands.<id>.description` (required)
- A short, sentence-case string description of what the command does
- Type: `string`
- Example: `"Summarize recent git changes"`
#### `commands.<id>.prompt`
- The set of instructions for Cody
- Type: `string`
- Example: `"Summarize the given git changes in 3-5 sentences"`
#### `commands.<id>.mode`
- The interaction mode to use
- Type: `string`
- Default: `"ask"`
Values:
- `"ask"` Focus the chat view and add to the current chat
- `"inline"` Start a new inline chat
- `"insert"` Insert the response above the code
- `"replace"` Replace the code with the response
#### `commands.<id>.context`
- Optional context data to generate and pass to Cody
- Type: `object`
- Default: `{ "codebase": true }`
#### `commands.<id>.context.codebase`
- Include embeddings and/or keyword code search (depending on availability)
- Type: `boolean`
- Default: `true`
#### `commands.<id>.context.command`
- Terminal command to run and include the output of
- Type: `string`
- Default: `""`
- Example: ` "git log --since=$(git describe --tags --abbrev=0) --pretty='Commit author: %an%nCommit message: %s%nChange description:%b%n'"`
#### `commands.<id>.context.currentDir`
- Include snippets from first 10 files in the current directory
- Type: `boolean`
- Default: `false`
#### `commands.<id>.context.currentFile`
- Include snippets from the current file. If the file is too long, only the content surrounding the current selection will be included
- Type: `boolean`
- Default: `false`
#### `commands.<id>.context.directoryPath`
- Include snippets from the first five files within the given relative path of the directory. Content will be limited and truncated according to the token limit
- Type: `string`
- Default: `""`
- Example: `"lib/common"`
#### `commands.<id>.context.filePath`
- Include snippets from the given file path relative to the codebase. If the file is too long, content will be truncated
- Type: `string`
- Default: `""`
- Example: `"CHANGELOG.md", "test/unit/example.test.ts"`
#### `commands.<id>.context.none`
- Provide only the prompt, and no additional context. If `true`, overrides all other context settings
- Type: `boolean`
- Default: `false`
#### `commands.<id>.context.openTabs`
- Include the text content of opened editor tabs
- Type: `boolean`
- Default: `false`
#### `commands.<id>.context.selection`
- Include currently selected code. When not specified, Cody will try to use visible content from the current file instead
- Type: `boolean`
- Default: `false`
<!-- ### Defining commands in the `cody.json` file
You can define custom commands for Cody in the `cody.json` file. To make commands only available for a specific project, create the `cody.json` file in that project's `.vscode` directory. When you work on that project, these workspace-specific custom commands will be available.
To make custom commands globally available across multiple projects, create a new `cody.json` file in your home directory's `.vscode` folder. These global custom commands will be available in Cody in any workspace. -->

View File

@ -0,0 +1,65 @@
# Debug Code
<p class="subtitle">Learn how Cody helps you identify errors in your code and provides code fixes.</p>
Cody is optimized to identify and fix errors in your code. Its debugging capability and autocomplete suggestions can significantly accelerate your debugging process, increasing developer productivity. All Cody IDE extensions (VS Code, JetBrains, and Neovim) support code debugging and fixes capabilities.
## Use chat for code fixes
When you encounter a code error, you can use the chat interface and ask Cody about it. You can paste the faulty code snippets directly in the chat window, and Cody will provide a fix.
The suggestions can be a corrected code snippet that you can copy and paste into your code. Or you can ask a follow-up question for additional context to help you debug the code further. Moreover, you can also paste an error message in chat and ask Cody to provide you with a list of possible solutions.
Let's look at a simple example to understand how Cody can help you debug your code. The following code snippet should print the sum of two numbers.
```js
function sum(a, b) {
var result = a + b;
console.log('The sum is: ' + $result);
}
sum(3 , 4);
```
When you try to `console.log` the `result`, it does not print the correct summed value. Cody can help you both identify the error and provide a solution to fix it. Let's debug the code snippet. Paste the code snippet inside the Cody chat window and ask Cody to fix it.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/fix-code.mp4" type="video/mp4">
</video>
In addition, Cody helps you reduce the chances of getting syntax and typo errors. The Cody IDE extensions provide context-aware suggestions based on your codebase, helping you avoid common mistakes and reduce your debugging time.
## Detecting code smell
Cody can detect early code smells to ensure coding best practices and quality and provide suggestions to improve your code. By detecting such potential errors early on, you can avoid scalability and code maintainability issues that might arise in the future.
VS Code users can detect code smells by the `/smell` command, and JetBrains users can achieve the same by clicking the **Smell Code** button from the **Commands** tab.
Let's identify code smells on the same function from the previous example.
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/code-smells.mp4" type="video/mp4">
</video>
As you can see, Cody not only detects code smells but also provides suggestions to improve your code.
## Code Actions
Cody VS Code extension users also get to use the **Code Actions** feature whenever there's an error in code syntax. When you make a mistake while writing code, Cody's Code Actions come into play, and a red warning triggers. Along this appears a lightbulb icon.
### How Code Actions work
Let's assume there's an error in the code, and the red warning triggers. Now follow these steps:
- Click this lightbulb icon in the project file
- Select **Ask Cody to fix** option
- **Cody is working** notice will appear and provide a quick fix with options for **Edits Applied**, **Retry**, **Undo**, and **Done**
- If you are satisfied with the fix, click **Edits Applied**
- To verify the applied changes, you can see a diff view of the fix in a new tab
- If you are not satisfied with the fix, you can **Retry** or **Undo** the changes
Here's a demo that shows how Code Actions work:
<video width="1920" height="1080" loop playsinline controls style="width: 100%; height: auto; max-width: 50rem">
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/code-actions.mp4" type="video/mp4">
</video>

View File

@ -0,0 +1,19 @@
# Cody Capabilities
<p class="subtitle">
Learn and understand more about Cody's features and core AI functionality.
</p>
Cody offers a rich set of capabilities and features that help you write better code faster. These include:
- Chat: Allows users to ask general programming questions or inquire about specific code
- Autocomplete: Suggests code completions as you type, utilizing context from your code, open files, and file history
- Commands & Custom Commands: Provide predefined, reusable prompts for common actions, such as documenting code, explaining code, generating unit tests, and identifying code smells
- Debug code: Helps you with identifying and fixing code errors and bugs.
Learn more about each by exploring their respective documentation:
- [Chat](./chat.md)
- [Autocomplete](./autocomplete.md)
- [Commands & Custom Commands](./commands.md)
- [Debug Code](./debug-code.md)

View File

@ -1,260 +0,0 @@
# Cody Custom Commands
<aside class="experimental">
<p>
<span class="badge badge-experimental">Experimental</span> This feature is experimental and might change or be removed in the future. We've released it as an experimental feature for testing and feedback.
</p>
</aside>
Custom Commands allow you to define reusable prompts tailored for your own needs. They are currently supported by [Cody for VS Code](overview/install-vscode.md) version 0.8 and above.
### Use cases
* Integrate with your build system to suggest fixes for errors/warnings in the latest build
* Read in test command failures to explain and suggest fixes
* Analyze software dependencies output to explain compatibility or suggest upgrades
* Explain code quality output like linter warnings
## Creating a Command
You can can create a custom command by editing the [configuration JSON file](#file-paths), or by using command builder within VS Code.
To access the command builder within VS Code, open the Cody commands menu (⌥C on Mac or Alt-C on Windows/Linux) → "Configure Custom Commands..." → "New Custom Command..."
![Cody Custom Command Setup in VS Code](https://storage.googleapis.com/sourcegraph-assets/docs/images/cody/custom-command-setup-1.png)
## Configuration File Paths
Custom Commands can be defined in the following two file paths:
* User Settings (`~/.vscode/code.json`) — Stored locally. Use this for personal commands to use across all your projects.
* Workspace Settings (`.vscode/cody.json`) — Stored in projects repository. Use this to share commands with others working on the same codebase, and for project-specific commands.
See the [examples](#examples) and [configuration properties](#configuration-properties) below for more details on how to configure custom commands.
## Examples
### `/commit-message`
```json
{
"commit-message": {
"description": "Commit message for current changes",
"prompt": "Suggest an informative commit message by summarizing code changes from the shared command output. The commit message should follow the conventional commit format and provide meaningful context for future readers.",
"context": {
"selection": false,
"command": "git diff --cached"
}
}
}
```
### `/compare-tabs`
```json
{
"compare-tabs": {
"description": "Compare files in opened tabs",
"prompt": "Examine the shared code snippets from my opened tabs. Then explain the relationship between the code samples by answering these questions: 1. What are the main tasks or functions the code is performing? 2. Are there any similarities in functions or logic across the samples? 3. Does one code snippet call or import another? If so, how do they interact? 4. Are there any notable differences in how they approach similar problems? 5. Overall, how are the code snippets related - do they work together as part of a larger program, solve variants of the same problem, or serve entirely different purposes?",
"context": {
"openTabs": true,
"selection": false
}
}
}
```
### `/current-dir`
```json
{
"current-dir": {
"description": "Explain current directory",
"prompt": "At a high level, explain what this directory is used for.",
"context": {
"currentDir": true,
"seleection": false
}
}
}
```
### `/latest-cody-release`
```json
{
"latest-cody-release": {
"description": "Summarize latest Cody release",
"prompt": "What is the latest stable version of Cody? Briefly summarize the changes that were included in that release based on this CHANGELOG excerpt.",
"context": {
"selection": false,
"command": "curl https://raw.githubusercontent.com/sourcegraph/cody/main/vscode/CHANGELOG.md | head -n 50"
}
}
}
```
### `/readme`
```json
{
"readme": {
"description": "Readme for current dir",
"prompt": "Write a detailed README.md file to document the code located in the same directory as my current selection. Summarize what the code in this directory is meant to accomplish. Explain the key files, functions, classes, and features. Use Markdown formatting for headings, code blocks, lists, etc. to make the it organized and readable. Aim for a beginner-friendly explanation that gives a developer unfamiliar with the code a good starting point to understand it. Make sure to include: - Overview of directory purpose - Functionality explanations - Relevant diagrams or visuals if helpful. Write the README content clearly and concisely using complete sentences and paragraphs based on the shared context. Use proper spelling, grammar, and punctuation throughout. Surround your full README text with triple backticks so it renders properly as a code block. Do not make assumptions or fabricating additional details.",
"context": {
"currentDir": true,
"selection": true
}
}
}
```
### `/recent-git-changes`
```json
{
"recent-git-changes": {
"description": "Summarize recent changes",
"prompt": "Summarize the given git changes in 3-5 sentences",
"context": {
"command": "git log -10 --pretty=format:'%h - %an: %s' --stat",
"selection": false
}
}
}
```
## Configuration Properties
#### `commands` (required)
An object containing the commands.
Type: `object`
Example: `{ "commands": {} }`
#### `commands.<id>` (required)
The slash name used for the command.
Type: `string`
Example: `"summarize-git-changes"`
#### `commands.<id>.description` (required)
A short, sentence-case string description of what the command does.
Type: `string`
Example: `"Summarize recent git changes"`
#### `commands.<id>.prompt`
The set of instructions for Cody.
Type: `string`
Example: `"Summarize the given git changes in 3-5 sentences"`
#### `commands.<id>.mode`
The interaction mode to use.
Type: `string`
Default: `"ask"`
Values:
- `"ask"` Focus the chat view and add to the current chat
- `"inline"` Start a new inline chat
- `"insert"` Insert the response above the code
- `"replace"` Replace the code with the response
#### `commands.<id>.context`
Optional context data to generate and pass to Cody.
Type: `object`
Default: `{ "codebase": true }`
#### `commands.<id>.context.codebase`
Include embeddings and/or keyword code search (depending on availability).
Type: `boolean`
Default: `true`
#### `commands.<id>.context.command`
Terminal command to run and include the output of.
Type: `string`
Default: `""`
Example: ` "git log --since=$(git describe --tags --abbrev=0) --pretty='Commit author: %an%nCommit message: %s%nChange description:%b%n'"`
#### `commands.<id>.context.currentDir`
Include snippets from first 10 files in the current directory.
Type: `boolean`
Default: `false`
#### `commands.<id>.context.currentFile`
Include snippets from the current file. If the file is too long, only the content surrounding the current selection will be included.
Type: `boolean`
Default: `false`
#### `commands.<id>.context.directoryPath`
Include snippets from the first five files within the given relative path of the directory. Content will be limited and truncated according to the token limit.
Type: `string`
Default: `""`
Example: `"lib/common"`
#### `commands.<id>.context.filePath`
Include snippets from the given file path relative to the codebase. If the file is too long, content will be truncated.
Type: `string`
Default: `""`
Example: `"CHANGELOG.md", "test/unit/example.test.ts"`
#### `commands.<id>.context.none`
Provide only the prompt, and no additional context. If `true`, overrides all other context settings.
Type: `boolean`
Default: `false`
#### `commands.<id>.context.openTabs`
Include the text content of opened editor tabs.
Type: `boolean`
Default: `false`
#### `commands.<id>.context.selection`
Include currently selected code. When not specified, Cody will try to use visible content from the current file instead.
Type: `boolean`
Default: `false`

View File

@ -44,6 +44,8 @@ Here's a feature parity matrix that compares the capabilities of Cody Clients ac
| Show context files | ✓ | ✓ | ✓ |
| Custom commands | ✓ | x | x |
| Clear chat history | ✓ | ✓ | x |
| LLM Selection | ✓ | x | x |
| Enhanced Context Selection | ✓ | x | x |
## Code Autocomplete
@ -66,14 +68,6 @@ Here's a feature parity matrix that compares the capabilities of Cody Clients ac
| Embeddings | ✓ | ✓ | ✓ |
| Context UI | ✓ | ✓ | x |
## Inline Chat
| **Feature** | **VS Code** | **JetBrains** | **Neovim** |
|-------------------------|---------|-----------|--------|
| Questions | ✓ | x | ✓ |
| Fix-ups | ✓ | x | ✓ |
| Touch | ✓ | x | x |
## Commands
| **Feature** | **VS Code** | **JetBrains** | **Neovim** |

View File

@ -162,8 +162,6 @@ Let's understand how the `/doc` command generates code documentation for a funct
In addition, to support customization and advanced use cases, you can create Custom Commands tailored to your requirements. Custom Commands are currently supported by Cody for the VS Code extension version 0.8 and above.
[Learn more about Custom Commands here →](./../custom-commands.md)
## Enable code graph context for context-aware answers (Optional)
After connecting Cody extension to Sourcegraph.com, you can optionally use [Code Graph Context](./../core-concepts/code-graph.md) to improve Cody's context of existing code. Note that Code Graph Context is only available for public repositories on Sourcegraph.com, which have embeddings.

View File

@ -35,10 +35,14 @@ Keep it as a single list with at most 2 levels. (Anything else may not render co
- [Cody Desktop App](cody/overview/app/index.md)
- [Cody Enterprise](cody/overview/enable-cody-enterprise.md)
- [Quickstart](cody/quickstart.md)
- [Capabilities](cody/capabilities.md)
- [Capabilities](cody/capabilities/index.md)
- [Chat](cody/capabilities/chat.md)
- [Autocomplete](cody/capabilities/autocomplete.md)
- [Commands](cody/capabilities/commands.md)
- [Debug Code](cody/capabilities/debug-code.md)
- [Core Concepts](cody/core-concepts/index.md)
- [Cody Use Cases](cody/use-cases.md)
- [Custom Commands](cody/custom-commands.md)
<!-- - [Custom Commands](cody/custom-commands.md) -->
- [Feature Parity Reference](cody/feature-reference.md)
- [Troubleshooting](cody/troubleshooting.md)
- [FAQ](cody/faq.md)