From f88377cd1d1e62666d5391917d8019340c8d1766 Mon Sep 17 00:00:00 2001 From: wolfy Date: Sun, 31 May 2026 12:27:53 -0500 Subject: [PATCH] chore: bump context window to match what zed uses --- agents/ollama.ts | 5 +++-- mcp/readFile.ts | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/agents/ollama.ts b/agents/ollama.ts index 5f7f99b..c5b2024 100644 --- a/agents/ollama.ts +++ b/agents/ollama.ts @@ -120,7 +120,7 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise { keep_alive: "10m", options: { think: true, - num_ctx: 32768, + num_ctx: 262144, } as Record, }); } catch (err) { @@ -216,7 +216,8 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise { const parsed = JSON.parse( typeof lastToolMsg.content === "string" ? lastToolMsg.content : "", ); - if (typeof parsed?.modeName === "string") selectedMode = parsed.modeName; + if (typeof parsed?.modeName === "string") + selectedMode = parsed.modeName; } catch { // best-effort } diff --git a/mcp/readFile.ts b/mcp/readFile.ts index c3decf9..07ec0c6 100644 --- a/mcp/readFile.ts +++ b/mcp/readFile.ts @@ -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.`, + }; }), }); }