From ee79bff04835697fee1b2d90d49513f1a3b8fcf8 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 22 Aug 2025 19:01:27 -0700 Subject: [PATCH] fix: truncate Read tool output to avoid context overflow --- extensions/cli/src/tools/readFile.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/cli/src/tools/readFile.ts b/extensions/cli/src/tools/readFile.ts index f7258a3bf..37a15639c 100644 --- a/extensions/cli/src/tools/readFile.ts +++ b/extensions/cli/src/tools/readFile.ts @@ -39,6 +39,13 @@ export const readFileTool: Tool = { const content = fs.readFileSync(args.filepath, "utf-8"); // Mark this file as read for the edit tool markFileAsRead(args.filepath); + + const lines = content.split('\n'); + if (lines.length > 5000) { + const truncatedContent = lines.slice(0, 5000).join('\n'); + return `Content of ${args.filepath} (truncated to first 5000 lines of ${lines.length} total):\n${truncatedContent}`; + } + return `Content of ${args.filepath}:\n${content}`; } catch (error) { return `Error reading file: ${