diff --git a/extensions/cli/src/compaction.ts b/extensions/cli/src/compaction.ts index c52ba0147..692ef19be 100644 --- a/extensions/cli/src/compaction.ts +++ b/extensions/cli/src/compaction.ts @@ -28,6 +28,11 @@ export interface CompactionOptions { systemMessageTokens?: number; } +const COMPACTION_PROMPT = + "Please provide a concise summary of our conversation so far, capturing the key context, decisions made, and current state. Format this as a single comprehensive message that preserves all important information needed to continue our work. You do not need to recap the system message, as this will remain. Make sure it is clear what the current stream of work was at the very end prior to compaction so that you can continue exactly where you left off without missing any information."; + +const COMPACTION_PROMPT_TOKENS = 150; // rough generous token count of ^ + /** * Compacts a chat history into a summarized form * @param chatHistory The current chat history to compact @@ -47,8 +52,7 @@ export async function compactChatHistory( const compactionPrompt: ChatHistoryItem = { message: { role: "user" as const, - content: - "Please provide a concise summary of our conversation so far, capturing the key context, decisions made, and current state. Format this as a single comprehensive message that preserves all important information needed to continue our work. You do not need to recap the system message, as this will remain. Make sure it is clear what the current stream of work was at the very end prior to compaction so that you can continue exactly where you left off without missing any information.", + content: COMPACTION_PROMPT, }, contextItems: [], }; @@ -67,13 +71,15 @@ export async function compactChatHistory( (item) => item.message.role === "system", ); - // Account for system message (if not already in history) AND safety buffer - const SAFETY_BUFFER = 100; + // Account for system message (if not already in history) AND compaction prompt const systemMessageReservation = hasSystemMessageInHistory ? 0 : systemMessageTokens; const availableForInput = - contextLimit - reservedForOutput - systemMessageReservation - SAFETY_BUFFER; + contextLimit - + reservedForOutput - + systemMessageReservation - + COMPACTION_PROMPT_TOKENS; // Check if we need to prune to fit within context while ( diff --git a/extensions/cli/src/tools/readFile.ts b/extensions/cli/src/tools/readFile.ts index bde647a07..9fa2c1630 100644 --- a/extensions/cli/src/tools/readFile.ts +++ b/extensions/cli/src/tools/readFile.ts @@ -3,10 +3,7 @@ import * as fs from "fs"; import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js"; import { ContinueError, ContinueErrorReason } from "core/util/errors.js"; -import { - parseEnvNumber, - truncateByLinesAndChars, -} from "../util/truncateOutput.js"; +import { parseEnvNumber } from "../util/truncateOutput.js"; import { formatToolArgument } from "./formatters.js"; import { Tool } from "./types.js"; @@ -82,20 +79,26 @@ export const readFileTool: Tool = { } const realPath = fs.realpathSync(filepath); const content = fs.readFileSync(realPath, "utf-8"); - // Mark this file as read for the edit tool - markFileAsRead(realPath); const maxLines = getReadFileMaxLines(); const maxChars = getReadFileMaxChars(); + const lineCount = content.split("\n").length; + const charCount = content.length; - const { output: truncatedContent, wasTruncated } = - truncateByLinesAndChars(content, maxLines, maxChars, "file content"); - - if (wasTruncated) { - return `Content of ${filepath} (truncated):\n${truncatedContent}`; + if (charCount > maxChars || lineCount > maxLines) { + throw new ContinueError( + ContinueErrorReason.FileTooLarge, + `File is too large to read: ${filepath} (${charCount.toLocaleString()} characters, ${lineCount.toLocaleString()} lines). ` + + `Maximum allowed: ${maxChars.toLocaleString()} characters or ${maxLines.toLocaleString()} lines. ` + + `To adjust these limits, set CONTINUE_CLI_READ_FILE_MAX_OUTPUT_CHARS or CONTINUE_CLI_READ_FILE_MAX_OUTPUT_LINES environment variables. ` + + `Alternatively, use shell commands like 'head', 'tail', 'sed', or 'grep' to read targeted parts of the file.`, + ); } - return `Content of ${filepath}:\n${truncatedContent}`; + // Mark this file as read for the edit tool + markFileAsRead(realPath); + + return `Content of ${filepath}:\n${content}`; } catch (error) { if (error instanceof ContinueError) { throw error;