chore: bump context window to match what zed uses

This commit is contained in:
2026-05-31 12:27:53 -05:00
parent fa2516e53e
commit f88377cd1d
2 changed files with 22 additions and 7 deletions
+19 -5
View File
@@ -3,6 +3,9 @@ import { type } from "arktype";
import type { ToolContext } from "./server.ts";
import { execute, tool } from "./shared.ts";
/** Hard cap on returned content to avoid flooding the model's context window. */
const MAX_CHARS = 6000;
export const ReadFileParams = type({
path: type.string.describe("absolute path to the file to read"),
"start_line?": type.number.describe("start line, 1-based inclusive (default: 1)"),
@@ -14,6 +17,8 @@ export function ReadFileTool(_ctx: ToolContext) {
name: "read_file",
description:
"Read lines from a file. Use this to read sections of the PR diff returned by checkout_pr. " +
`Returns at most ${MAX_CHARS} characters — use narrow line ranges to stay within budget. ` +
"Read selectively: only the files most relevant to the review, not the entire diff at once. " +
"Example: `read_file({ path: diffPath, start_line: 5, end_line: 42 })`.",
parameters: ReadFileParams,
execute: execute(async ({ path, start_line, end_line }) => {
@@ -25,14 +30,23 @@ export function ReadFileTool(_ctx: ToolContext) {
throw new Error(`failed to read ${path}: ${msg}`);
}
if (start_line === undefined && end_line === undefined) {
return { content };
}
const lines = content.split("\n");
const start = Math.max(0, (start_line ?? 1) - 1);
const end = Math.min(lines.length, end_line ?? lines.length);
return { content: lines.slice(start, end).join("\n") };
const slice = lines.slice(start, end).join("\n");
if (slice.length <= MAX_CHARS) {
return { content: slice };
}
const truncated = slice.slice(0, MAX_CHARS);
const linesShown = truncated.split("\n").length;
const linesTotal = end - start;
return {
content: truncated,
truncated: true,
note: `Output capped at ${MAX_CHARS} chars (showed ${linesShown}/${linesTotal} lines). Use a narrower line range to read the rest.`,
};
}),
});
}