Skip to content

Commit 98ada36

Browse files
Hackathon - Context Filters (#774)
<!-- Explain the changes introduced in your PR --> ## Pull Request approval You will need to get your PR approved by at least one member of the Sourcegraph team. For reviews of docs formatting, styles, and component usage, please tag the docs team via the #docs Slack channel. --------- Co-authored-by: Maedah Batool <[email protected]>
1 parent 5a42efd commit 98ada36

File tree

2 files changed

+31
-62
lines changed

2 files changed

+31
-62
lines changed
Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# Manage Cody Context
22

3-
<p className="subtitle">This documentation helps you control and manage what context from your codebase is used by Cody. You can do it via </p>
3+
<p className="subtitle">You can control and manage what context from your codebase is used by Cody. You can do this by using Cody Context Filters.</p>
44

5-
- Cody Context Filters (Cody Enterprise Only)
6-
- Cody Ignore File (Experimental) (All Cody users)
5+
<Callout type="note">Cody Context Filters is available only for Enterprise users on all supported [clients](/cody/clients).</Callout>
76

8-
## Cody Context Filters
7+
## Context Filters
98

10-
<Callout type="note">Context Filters is available only for Cody Enterprise users.</Callout>
11-
12-
Admins on the Sourcegraph Enterprise instance can use the Cody Context Filters to determine which repositories Cody can use as the context in its requests to third-party LLMs. Cody Context Filters can be used when the following conditions are met:
9+
Admins on the Sourcegraph Enterprise instance can use the Cody Context Filters to determine which repositories Cody can use as the context in its requests to third-party LLMs. You can use Context Filters if you have:
1310

1411
- A valid Cody Enterprise license running on Sourcegraph instance version `>=5.4.0`
1512
- Running the supported Cody client versions: VS Code `>=1.20.0` and JetBrains `>=6.0.0`
1613
- Setting the `cody-context-filters-enabled` feature flag to `true`
1714

18-
Administrators can configure the `cody.contextFilters` field in the site configuration with the repos that they wish Cody to exclude or only include using the following structure:
15+
Site admins can customize the `cody.contextFilters` field in the site configuration to specify which repositories Cody should `include` or `exclude`, using the following structure:
1916

2017
```json
2118
{
@@ -41,17 +38,19 @@ Administrators can configure the `cody.contextFilters` field in the site configu
4138

4239
```
4340

44-
### How include and exclude rules work
41+
## How `include` and `exclude` rules work
4542

4643
The `include` and `exclude` rules define the repositories Cody can use as context. The rules can be defined in the following combination:
4744

48-
1. `cody.contextFilters` field is not defined
45+
### `cody.contextFilters` field is not defined
46+
47+
By default, Cody can access all repositories for context when making requests to third-party LLMs, with no restrictions on inclusion or exclusion.
4948

50-
By default, there are no restrictions on the repositories Cody can use for context in requests to third-party LLMs. All repositories are included, and none are excluded.
49+
### Only `include` rules are specified
5150

52-
2. Only `include` rules are specified
51+
Cody is restricted to using content only from repositories whose names match the patterns specified in the `include` field. No repositories are explicitly excluded if no `exclude` rules are defined.
5352

54-
Cody is restricted from using content from repositories whose names match any specified patterns in the `include` field. Since no `exclude` rules are specified, no repositories are explicitly excluded. An `include` field might contain a catch-all pattern (e.g., a `regexp` matching any string). In this case, Cody can access content from any repository, as a single match in the `include` rules is sufficient for inclusion. For example,
53+
The `include` field can also contain a catch-all pattern (e.g., a `regexp` that matches any string), allowing Cody to access content from all repositories. A single match in the `include` rules is enough for a repository to be included. For example:
5554

5655
```json
5756
{
@@ -67,11 +66,13 @@ Cody is restricted from using content from repositories whose names match any sp
6766

6867
```
6968

70-
The `include` rules allow Cody to access the repository matching the `regexp`. This means Cody can now fully access the repository and its content to fetch context.
69+
These `include` rules allow Cody only to utilize the repository matching the `regexp` with full access to fetch context.
70+
71+
### Only `exclude` rules are specified
7172

72-
1. Only `exclude` rules are specified
73+
By default, all repositories are included unless specific `include` rules are defined. If **only** `exclude` rules are specified, Cody will not use content from any repository whose name matches at least one pattern in the `exclude` field.
7374

74-
All repositories are considered included by default without the `include` rules. Cody is prohibited from using content from any repository whose name matches at least one pattern specified in the exclude field. An `exclude` field may contain a catch-all condition (e.g., a `regexp` matching any string). If such a match occurs, Cody is restricted from using content from any repository. For example,
75+
The `exclude` field can also include a catch-all condition, such as a `regexp` that matches any string. When such a condition is present, Cody is entirely restricted from accessing content from any repository. For example:
7576

7677
```json
7778
{
@@ -87,19 +88,15 @@ All repositories are considered included by default without the `include` rules.
8788

8889
```
8990

90-
In this case, Cody's commands are disabled, and you cannot use them for context fetching. If you try running any of these, you'll be prompted with an error message. However, Cody chat will still work, and you can use it to ask questions.
91-
92-
![commands-disabled-exclude-rules](https://storage.googleapis.com/sourcegraph-assets/Docs/commands-disabled-082024.png)
91+
#### Chat behavior when exclude rules are defined
9392

94-
The demo shows what happens when you try to run commands due to the `exclude` rules.
93+
Some Cody features, such as using **Prompts**, will not work if the `exclude` rules are defined. They appear to be disabled in the Cody chat interface. If you try running any of these, you'll be prompted with an error message. However, Cody chat will still work; you can use it to ask questions.
9594

96-
<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
97-
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/exclude-rules.mp4" type="video/mp4"/>
98-
</video>
95+
![commands-disabled-exclude-rules](https://storage.googleapis.com/sourcegraph-assets/Docs/commands-disabled-082024.png)
9996

100-
1. Both `include` and `exclude` rules are specified
97+
### Both `include` and `exclude` rules are specified
10198

102-
When making requests to third-party LLMs, Cody can use content from a repository if its name matches any of the `include` patterns and does not match any of the `exclude` patterns. Thus, the `exclude` rules filter only the repositories allowed by the `include` rules. For example,
99+
When requesting third-party LLMs, Cody can use content from a repository if its name matches any of the `include` patterns and does not match any of the `exclude` patterns. Thus, the `exclude` rules filter only the repositories allowed by the `include` rules. For example,
103100

104101
```json
105102
{
@@ -127,39 +124,11 @@ In this case, Cody can access content from repositories whose names start with `
127124

128125
Depending on the client type, here's a breakdown of versions supported and the behavior for unsupported versions:
129126

130-
| **Client Versions** | Sourcegraph `v<5.4.0` | Sourcegraph `v=5.4.0` | Sourcegraph `v=5.4.12303` | Sourcegraph `v>=5.4.0` |
131-
| --------------------------------- | --------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- | ---------------------- |
132-
| **JetBrains `<= 5.5.9`** | N/A | Cody is not compatible | Respects policy and prompts to upgrade | Not affected |
133-
| **`5.5.10 <= JetBrains < 6.0.0`** | N/A | Cody is not compatible | Respects policy and prompts to upgrade | Not affected |
134-
| **JetBrains `>= 6.0.0`** | N/A | Respects policy | Respects policy | Not affected |
135-
| **VS Code `< 1.16.X`** | N/A | Cody is not compatible | Respects policy and prompts to upgrade | Not affected |
136-
| **`1.18.0 < VS Code < 1.20.0`** | N/A | Cody is not compatible | Respects policy and prompts to upgrade | Not affected |
137-
| **VS Code `>= 1.20.0`** | N/A | Respects policy | Respects policy | Not affected |
138-
139-
## Cody Ignore Files
140-
141-
<Callout type="note">The Cody Ignore feature has been sunsetted and will no longer be maintained. We recommend using Cody Context Filters with Cody Enterprise for more flexible file exclusion and inclusion rules.</Callout>
142-
143-
Cody users can configure the `.cody/ignore` file to specify files or folders from your codebase to be ignored as context by Cody through the following steps:
144-
145-
## Enabling Unstable Features
146-
147-
To use the ignore context feature, you first need to enable unstable features in Cody. Here's how:
148-
149-
1. Open your settings in Cody Extension
150-
2. Next, go to the `settings.json` file
151-
3. Add a new line: `"cody.unstableFeatures": true`.
152-
153-
This will enable experimental features, including the ignore context feature.
154-
155-
## Using the Ignore Context Feature
156-
157-
To ignore specific files or folders from the context Cody took, you need to create an `ignore` file for your project. Here's how:
158-
159-
1. Create a new folder in your project root named `.cody`.
160-
2. Inside the `.cody` folder, create a file named `ignore`.
161-
3. In the `ignore` file, specify the files or folders you want to ignore.
162-
163-
The `.cody/ignore` file works similarly to a `.gitignore` file. If you want to ignore a file named `secret.json`, you would add `secret.json` to your `.cody/ignore` file. If you're going to ignore a folder called `lib/shared`, you would add `lib/shared/` to your `.cody/ignore` file.
164-
165-
Once a file or folder is added to the `.cody/ignore` file, Cody will no longer provide autocomplete suggestions for that file or folder, and it will not appear in your chat results.
127+
| **Client** | Client version | Sourcegraph `v<5.4.0` | Sourcegraph `v=5.4.0` | Sourcegraph `v=5.4.12303` | Sourcegraph `v>=5.4.0` |
128+
| ------------- | ------------------------- | --------------------- | --------------------- | ------------------------------- | ---------------------- |
129+
| **VS Code** | `< 1.16.X` | N/A | Cody not compatible | Respects policy, ask to upgrade | Not affected |
130+
| | `1.18.0 <` and `< 1.20.0` | N/A | Cody not compatible | Respects policy, ask to upgrade | Not affected |
131+
| | `>= 1.20.0` | N/A | Respects policy | Respects policy | Not affected |
132+
| **JetBrains** | `<= 5.5.9` | N/A | Cody not compatible | Respects policy, ask to upgrade | Not affected |
133+
| | `5.5.10 <=` and `< 6.0.0` | N/A | Cody not compatible | Respects policy, ask to upgrade | Not affected |
134+
| | `>= 6.0.0` | N/A | Respects policy | Respects policy | Not affected |

docs/cody/clients/feature-reference.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Few exceptions that apply to Cody Pro and Cody Enterprise users:
5050
- Admin LLM selection is suported on VS Code, JetBrains, Visual Studio, and Web both for chat and code autocomplete
5151
- Multi-repo context is supported on VS Code, JetBrains, Visual Studio, and Web
5252
- [Guardrails](/cody/clients/enable-cody-enterprise#guardrails) are supported on VS Code, JetBrains, and Web
53-
- [Repo-based Cody Context Filters](/cody/capabilities/ignore-context#cody-context-filters) are supported on VS Code, JetBrains, and Web
53+
- [Repo-based Cody Context Filters](/cody/capabilities/ignore-context#cody-context-filters) are supported on all Cody clients.
5454
- `@-mention` directories are supported on VS Code, JetBrains, Visual Studio, and Web
5555

5656
</Accordion>

0 commit comments

Comments
 (0)