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
+3 -2
View File
@@ -120,7 +120,7 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
keep_alive: "10m", keep_alive: "10m",
options: { options: {
think: true, think: true,
num_ctx: 32768, num_ctx: 262144,
} as Record<string, unknown>, } as Record<string, unknown>,
}); });
} catch (err) { } catch (err) {
@@ -216,7 +216,8 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
const parsed = JSON.parse( const parsed = JSON.parse(
typeof lastToolMsg.content === "string" ? lastToolMsg.content : "", typeof lastToolMsg.content === "string" ? lastToolMsg.content : "",
); );
if (typeof parsed?.modeName === "string") selectedMode = parsed.modeName; if (typeof parsed?.modeName === "string")
selectedMode = parsed.modeName;
} catch { } catch {
// best-effort // best-effort
} }
+19 -5
View File
@@ -3,6 +3,9 @@ import { type } from "arktype";
import type { ToolContext } from "./server.ts"; import type { ToolContext } from "./server.ts";
import { execute, tool } from "./shared.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({ export const ReadFileParams = type({
path: type.string.describe("absolute path to the file to read"), path: type.string.describe("absolute path to the file to read"),
"start_line?": type.number.describe("start line, 1-based inclusive (default: 1)"), "start_line?": type.number.describe("start line, 1-based inclusive (default: 1)"),
@@ -14,6 +17,8 @@ export function ReadFileTool(_ctx: ToolContext) {
name: "read_file", name: "read_file",
description: description:
"Read lines from a file. Use this to read sections of the PR diff returned by checkout_pr. " + "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 })`.", "Example: `read_file({ path: diffPath, start_line: 5, end_line: 42 })`.",
parameters: ReadFileParams, parameters: ReadFileParams,
execute: execute(async ({ path, start_line, end_line }) => { 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}`); throw new Error(`failed to read ${path}: ${msg}`);
} }
if (start_line === undefined && end_line === undefined) {
return { content };
}
const lines = content.split("\n"); const lines = content.split("\n");
const start = Math.max(0, (start_line ?? 1) - 1); const start = Math.max(0, (start_line ?? 1) - 1);
const end = Math.min(lines.length, end_line ?? lines.length); 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.`,
};
}), }),
}); });
} }