Skip to content

Commit

Permalink
fix/CLI: fail fast if the provided --context-file is too large (#5191)
Browse files Browse the repository at this point in the history
Previously, the CLI didn't give any hint when `--context-file` was too
    large to fit into the context window. The VS Code chat UI refuses to
add these files as explicit context. This PR fixes the problem so that
    the CLI also fails fast in the same scenario. Users can pass the
    `--ignore-context-window-error` to skip this check.

## Test plan
Manually tested with
```
> pnpm -C agent build:agent && node agent/dist/index.js chat --context-file agent/src/cli/scip-codegen/scip.ts --context-file agent/src/agent.ts -m 'list all the methods here'
✖ The provided context is too large to fit into the context window.
To fix this problem, either remove the files from --context-file or
edit these files so they become small enough to fit into the context window.
Alternatively, set the flag --ignore-context-window-errors to skip this check.

File                                                                     Reason
-----------------------------------------------------------------------  --------------------------------------------------------------------------
/Users/olafurpg/dev/sourcegraph/cody/agent/src/cli/scip-codegen/scip.ts  user context tokens exceeded remaining user context tokens (49538 > 29970)
```

To skip the check
```
pnpm -C agent build:agent && node agent/dist/index.js chat --context-file agent/src/cli/scip-codegen/scip.ts --context-file agent/src/agent.ts -m 'list all the methods here' --ignore-context-window-errors
```
<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
  • Loading branch information
olafurpg authored Aug 14, 2024
1 parent a9921b9 commit efae786
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 532 deletions.
9 changes: 9 additions & 0 deletions agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ This is a log of all notable changes to the Cody command-line tool. [Unreleased]

### Changed

## 5.5.12

### Fixed

- `cody chat --context-file` will now fail fast if the provided file is too
large to fit into the context window. Previously, `cody chat` silently ignored
this error and the LLM would respond with a confusing message about missing
context. To bypass this check, use `--ignore-context-window-errors`.

## 5.5.11

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sourcegraph/cody",
"version": "5.5.11",
"version": "5.5.12",
"description": "Cody CLI is the same technology that powers Cody in the IDE but available from the command-line.",
"license": "Apache-2.0",
"repository": {
Expand All @@ -13,6 +13,7 @@
"scripts": {
"build:root": "pnpm -C .. run -s build",
"build:agent": "node src/esbuild.mjs",
"build:for-tests": "pnpm run -s build:root && pnpm run -s build:agent",
"build:webviews": "pnpm -C ../vscode _build:webviews --mode production --outDir ../../agent/dist/webviews",
"build": "pnpm run -s build:root && pnpm run -s build:webviews && pnpm run -s build:agent",
"build-minify": "pnpm run build --minify",
Expand Down
Loading

0 comments on commit efae786

Please sign in to comment.