فهرست منبع

Tweaks to file read auto-truncate (#1934)

* Tweaks to file read auto-truncate

* Change to use a text input

* Changeset
Matt Rubens 9 ماه پیش
والد
کامیت
5720b6b129

+ 5 - 0
.changeset/old-llamas-fold.md

@@ -0,0 +1,5 @@
+---
+"roo-cline": patch
+---
+
+Auto-truncate

+ 3 - 2
src/core/Cline.ts

@@ -2326,6 +2326,7 @@ export class Cline extends EventEmitter<ClineEvents> {
 								let sourceCodeDef = ""
 
 								const isBinary = await isBinaryFile(absolutePath).catch(() => false)
+								const autoTruncate = block.params.auto_truncate === "true"
 
 								if (isRangeRead) {
 									if (startLine === undefined) {
@@ -2336,7 +2337,7 @@ export class Cline extends EventEmitter<ClineEvents> {
 											startLine + 1,
 										)
 									}
-								} else if (!isBinary && totalLines > maxReadFileLine) {
+								} else if (autoTruncate && !isBinary && totalLines > maxReadFileLine) {
 									// If file is too large, only read the first maxReadFileLine lines
 									isFileTruncated = true
 
@@ -2357,7 +2358,7 @@ export class Cline extends EventEmitter<ClineEvents> {
 
 								// Add truncation notice if applicable
 								if (isFileTruncated) {
-									content += `\n\n[File truncated: showing ${maxReadFileLine} of ${totalLines} total lines. Use start_line and end_line if you need to read more.].${sourceCodeDef}`
+									content += `\n\n[File truncated: showing ${maxReadFileLine} of ${totalLines} total lines. Use start_line and end_line or set auto_truncate to false if you need to read more.].${sourceCodeDef}`
 								}
 
 								pushToolResult(content)

+ 1 - 0
src/core/assistant-message/index.ts

@@ -51,6 +51,7 @@ export const toolParamNames = [
 	"diff",
 	"start_line",
 	"end_line",
+	"auto_truncate",
 	"mode_slug",
 	"reason",
 	"operations",

+ 150 - 15
src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

@@ -35,11 +35,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -68,9 +70,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -412,11 +421,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -445,9 +456,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -878,11 +896,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -911,9 +931,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -1308,11 +1335,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -1341,9 +1370,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -1685,11 +1721,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -1718,9 +1756,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -2062,11 +2107,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -2095,9 +2142,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -2439,11 +2493,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -2472,9 +2528,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -2865,11 +2928,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -2898,9 +2963,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -3696,11 +3768,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -3729,9 +3803,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -4122,11 +4203,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -4155,9 +4238,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -4561,11 +4651,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -4594,9 +4686,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -4980,11 +5079,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -5013,9 +5114,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -5519,11 +5627,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -5552,9 +5662,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -5972,11 +6089,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -6005,9 +6124,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:
@@ -6323,11 +6449,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory /test/path)
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -6356,9 +6484,16 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
-
 Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.
+
 ## search_files
 Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
 Parameters:

+ 10 - 1
src/core/prompts/tools/read-file.ts

@@ -7,11 +7,13 @@ Parameters:
 - path: (required) The path of the file to read (relative to the current working directory ${args.cwd})
 - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
 - end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
+- auto_truncate: (optional) Whether to automatically truncate large files when start_line and end_line are not specified. If true and the file exceeds a certain line threshold, it will: a) return only a subset of lines to save tokens, b) include information about the total line count, and c) provide a summary of method definitions with their line ranges. You should set this to true unless you've been explicitly asked to read an entire large file at once, as this prevents context bloat that can lead to truncated responses. For backwards compatibility, it defaults to false when omitted.
 Usage:
 <read_file>
 <path>File path here</path>
 <start_line>Starting line number (optional)</start_line>
 <end_line>Ending line number (optional)</end_line>
+<auto_truncate>true or false (optional)</auto_truncate>
 </read_file>
 
 Examples:
@@ -40,6 +42,13 @@ Examples:
 <start_line>46</start_line>
 <end_line>68</end_line>
 </read_file>
+Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.
 
-Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.`
+5. Reading a large file with automatic truncation:
+<read_file>
+<path>src/large-module.ts</path>
+<auto_truncate>true</auto_truncate>
+</read_file>
+
+This will return a truncated version of the file with information about total line count and method definitions, helping to prevent context size issues with very large files.`
 }

+ 14 - 8
webview-ui/src/components/settings/ContextManagementSettings.tsx

@@ -96,18 +96,24 @@ export const ContextManagementSettings = ({
 					<div className="flex flex-col gap-2">
 						<span className="font-medium">{t("settings:contextManagement.maxReadFile.label")}</span>
 						<div className="flex items-center gap-2">
-							<Slider
+							<input
+								type="number"
+								className="w-24 bg-vscode-input-background text-vscode-input-foreground border border-vscode-input-border px-2 py-1 rounded text-right [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
+								value={maxReadFileLine ?? 500}
 								min={0}
-								max={2000}
-								step={10}
-								value={[maxReadFileLine ?? 450]}
-								onValueChange={([value]) => setCachedStateField("maxReadFileLine", value)}
-								data-testid="max-read-file-line-slider"
+								onChange={(e) => {
+									const newValue = parseInt(e.target.value, 10)
+									if (!isNaN(newValue) && newValue >= 0) {
+										setCachedStateField("maxReadFileLine", newValue)
+									}
+								}}
+								onClick={(e) => e.currentTarget.select()}
+								data-testid="max-read-file-line-input"
 							/>
-							<span className="w-10">{maxReadFileLine ?? 450}</span>
+							<span>{t("settings:contextManagement.maxReadFile.lines")}</span>
 						</div>
 					</div>
-					<div className="text-vscode-descriptionForeground text-sm mt-0">
+					<div className="text-vscode-descriptionForeground text-sm mt-2">
 						{t("settings:contextManagement.maxReadFile.description")}
 					</div>
 				</div>

+ 3 - 2
webview-ui/src/i18n/locales/ca/settings.json

@@ -267,8 +267,9 @@
 			"description": "Quan està habilitat, els fitxers que coincideixen amb els patrons a .rooignore es mostraran en llistes amb un símbol de cadenat. Quan està deshabilitat, aquests fitxers s'ocultaran completament de les llistes de fitxers i cerques."
 		},
 		"maxReadFile": {
-			"label": "Nombre màxim de línies per llegir d'un fitxer",
-			"description": "Nombre màxim de línies per llegir d'un fitxer a la vegada. Valors més baixos redueixen l'ús de context/recursos però poden requerir més lectures per a fitxers grans."
+			"label": "Llindar d'auto-truncament de lectura de fitxers",
+			"description": "El nombre predeterminat de línies per llegir d'un fitxer en un lot. Valors més baixos redueixen l'ús de context/recursos però poden requerir més lectures per a fitxers grans.",
+			"lines": "línies"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/de/settings.json

@@ -267,8 +267,9 @@
 			"description": "Wenn aktiviert, werden Dateien, die mit Mustern in .rooignore übereinstimmen, in Listen mit einem Schlosssymbol angezeigt. Wenn deaktiviert, werden diese Dateien vollständig aus Dateilisten und Suchen ausgeblendet."
 		},
 		"maxReadFile": {
-			"label": "Maximale Anzahl an Zeilen, die aus einer Datei gelesen werden",
-			"description": "Maximale Anzahl an Zeilen, die auf einmal aus einer Datei gelesen werden. Niedrigere Werte reduzieren den Kontext-/Ressourcenverbrauch, können aber mehr Lesevorgänge für große Dateien erfordern."
+			"label": "Schwellenwert für automatische Dateilesekürzung",
+			"description": "Die Standardanzahl an Zeilen, die in einem Durchgang aus einer Datei gelesen werden. Niedrigere Werte reduzieren den Kontext-/Ressourcenverbrauch, können aber mehr Lesevorgänge für große Dateien erfordern.",
+			"lines": "Zeilen"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/en/settings.json

@@ -267,8 +267,9 @@
 			"description": "When enabled, files matching patterns in .rooignore will be shown in lists with a lock symbol. When disabled, these files will be completely hidden from file lists and searches."
 		},
 		"maxReadFile": {
-			"label": "Maximum lines to read from a file",
-			"description": "Maximum number of lines to read from a file at once. Lower values reduce context/resource usage but may require more reads for large files."
+			"label": "File read auto-truncate threshold",
+			"description": "The default number of lines to read from a file in one batch. Lower values reduce context/resource usage but may require more reads for large files.",
+			"lines": "lines"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/es/settings.json

@@ -267,8 +267,9 @@
 			"description": "Cuando está habilitado, los archivos que coinciden con los patrones en .rooignore se mostrarán en listas con un símbolo de candado. Cuando está deshabilitado, estos archivos se ocultarán completamente de las listas de archivos y búsquedas."
 		},
 		"maxReadFile": {
-			"label": "Número máximo de líneas para leer de un archivo",
-			"description": "Número máximo de líneas para leer de un archivo a la vez. Valores más bajos reducen el uso de contexto/recursos pero pueden requerir más lecturas para archivos grandes."
+			"label": "Umbral de auto-truncado de lectura de archivos",
+			"description": "El número predeterminado de líneas para leer de un archivo en un lote. Valores más bajos reducen el uso de contexto/recursos pero pueden requerir más lecturas para archivos grandes.",
+			"lines": "líneas"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/fr/settings.json

@@ -267,8 +267,9 @@
 			"description": "Lorsque cette option est activée, les fichiers correspondant aux modèles dans .rooignore seront affichés dans les listes avec un symbole de cadenas. Lorsqu'elle est désactivée, ces fichiers seront complètement masqués des listes de fichiers et des recherches."
 		},
 		"maxReadFile": {
-			"label": "Nombre maximum de lignes à lire depuis un fichier",
-			"description": "Nombre maximum de lignes à lire depuis un fichier à la fois. Des valeurs plus basses réduisent l'utilisation de contexte/ressources mais peuvent nécessiter plus de lectures pour les fichiers volumineux."
+			"label": "Seuil d'auto-troncature de lecture de fichier",
+			"description": "Le nombre par défaut de lignes à lire depuis un fichier en un lot. Des valeurs plus basses réduisent l'utilisation de contexte/ressources mais peuvent nécessiter plus de lectures pour les fichiers volumineux.",
+			"lines": "lignes"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/hi/settings.json

@@ -267,8 +267,9 @@
 			"description": "जब सक्षम होता है, .rooignore में पैटर्न से मेल खाने वाली फाइलें लॉक प्रतीक के साथ सूचियों में दिखाई जाएंगी। जब अक्षम होता है, ये फाइलें फाइल सूचियों और खोजों से पूरी तरह छिपा दी जाएंगी।"
 		},
 		"maxReadFile": {
-			"label": "फ़ाइल से पढ़ने के लिए अधिकतम लाइनें",
-			"description": "फ़ाइल से एक बार में पढ़ने के लिए अधिकतम लाइनों की संख्या। कम मान संदर्भ/संसाधन उपयोग को कम करते हैं लेकिन बड़ी फाइलों के लिए अधिक पठन की आवश्यकता हो सकती है।"
+			"label": "फ़ाइल पढ़ने का स्वचालित काटने की सीमा",
+			"description": "एक बैच में फ़ाइल से पढ़ने के लिए डिफ़ॉल्ट लाइनों की संख्या। कम मान संदर्भ/संसाधन उपयोग को कम करते हैं लेकिन बड़ी फाइलों के लिए अधिक पठन की आवश्यकता हो सकती है।",
+			"lines": "पंक्तियाँ"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/it/settings.json

@@ -267,8 +267,9 @@
 			"description": "Quando abilitato, i file che corrispondono ai pattern in .rooignore verranno mostrati negli elenchi con un simbolo di blocco. Quando disabilitato, questi file saranno completamente nascosti dagli elenchi di file e dalle ricerche."
 		},
 		"maxReadFile": {
-			"label": "Numero massimo di righe da leggere da un file",
-			"description": "Numero massimo di righe da leggere da un file alla volta. Valori più bassi riducono l'utilizzo di contesto/risorse ma potrebbero richiedere più letture per file di grandi dimensioni."
+			"label": "Soglia di auto-troncamento lettura file",
+			"description": "Il numero predefinito di righe da leggere da un file in un singolo batch. Valori più bassi riducono l'utilizzo di contesto/risorse ma potrebbero richiedere più letture per file di grandi dimensioni.",
+			"lines": "righe"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/ja/settings.json

@@ -267,8 +267,9 @@
 			"description": "有効にすると、.rooignoreのパターンに一致するファイルがロックシンボル付きでリストに表示されます。無効にすると、これらのファイルはファイルリストや検索から完全に非表示になります。"
 		},
 		"maxReadFile": {
-			"label": "ファイルから読み込む最大行数",
-			"description": "一度にファイルから読み込む最大行数。低い値はコンテキスト/リソース使用量を減らしますが、大きなファイルではより多くの読み込みが必要になる場合があります。"
+			"label": "ファイル読み込み自動切り詰めしきい値",
+			"description": "一括でファイルから読み込むデフォルトの行数。低い値はコンテキスト/リソース使用量を減らしますが、大きなファイルではより多くの読み込みが必要になる場合があります。",
+			"lines": "行"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/ko/settings.json

@@ -267,8 +267,9 @@
 			"description": "활성화되면 .rooignore의 패턴과 일치하는 파일이 잠금 기호와 함께 목록에 표시됩니다. 비활성화되면 이러한 파일은 파일 목록 및 검색에서 완전히 숨겨집니다."
 		},
 		"maxReadFile": {
-			"label": "파일에서 읽을 최대 라인 수",
-			"description": "한 번에 파일에서 읽을 최대 라인 수. 낮은 값은 컨텍스트/리소스 사용량을 줄이지만 대용량 파일의 경우 더 많은 읽기가 필요할 수 있습니다."
+			"label": "파일 읽기 자동 축소 임계값",
+			"description": "한 번에 파일에서 읽을 기본 라인 수. 낮은 값은 컨텍스트/리소스 사용량을 줄이지만 대용량 파일의 경우 더 많은 읽기가 필요할 수 있습니다.",
+			"lines": "줄"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/pl/settings.json

@@ -267,8 +267,9 @@
 			"description": "Gdy włączone, pliki pasujące do wzorców w .rooignore będą pokazywane na listach z symbolem kłódki. Gdy wyłączone, te pliki będą całkowicie ukryte z list plików i wyszukiwań."
 		},
 		"maxReadFile": {
-			"label": "Maksymalna liczba linii do odczytu z pliku",
-			"description": "Maksymalna liczba linii odczytywanych z pliku jednocześnie. Niższe wartości zmniejszają użycie kontekstu/zasobów, ale mogą wymagać więcej odczytów dla dużych plików."
+			"label": "Próg automatycznego skracania odczytu pliku",
+			"description": "Domyślna liczba linii odczytywanych z pliku w jednej partii. Niższe wartości zmniejszają użycie kontekstu/zasobów, ale mogą wymagać więcej odczytów dla dużych plików.",
+			"lines": "linii"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/pt-BR/settings.json

@@ -267,8 +267,9 @@
 			"description": "Quando ativado, os arquivos que correspondem aos padrões em .rooignore serão mostrados em listas com um símbolo de cadeado. Quando desativado, esses arquivos serão completamente ocultos das listas de arquivos e pesquisas."
 		},
 		"maxReadFile": {
-			"label": "Número máximo de linhas para ler de um arquivo",
-			"description": "Número máximo de linhas para ler de um arquivo de uma vez. Valores mais baixos reduzem o uso de contexto/recursos, mas podem exigir mais leituras para arquivos grandes."
+			"label": "Limite de auto-truncamento de leitura de arquivo",
+			"description": "O número padrão de linhas para ler de um arquivo em um lote. Valores mais baixos reduzem o uso de contexto/recursos, mas podem exigir mais leituras para arquivos grandes.",
+			"lines": "linhas"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/tr/settings.json

@@ -267,8 +267,9 @@
 			"description": "Etkinleştirildiğinde, .rooignore'daki desenlerle eşleşen dosyalar kilit sembolü ile listelerde gösterilecektir. Devre dışı bırakıldığında, bu dosyalar dosya listelerinden ve aramalardan tamamen gizlenecektir."
 		},
 		"maxReadFile": {
-			"label": "Bir dosyadan okunacak maksimum satır sayısı",
-			"description": "Bir dosyadan bir kerede okunacak maksimum satır sayısı. Daha düşük değerler bağlam/kaynak kullanımını azaltır ancak büyük dosyalar için daha fazla okuma gerektirebilir."
+			"label": "Dosya okuma otomatik kısaltma eşiği",
+			"description": "Bir dosyadan bir partide okunacak varsayılan satır sayısı. Daha düşük değerler bağlam/kaynak kullanımını azaltır ancak büyük dosyalar için daha fazla okuma gerektirebilir.",
+			"lines": "satır"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/vi/settings.json

@@ -267,8 +267,9 @@
 			"description": "Khi được bật, các tệp khớp với mẫu trong .rooignore sẽ được hiển thị trong danh sách với biểu tượng khóa. Khi bị tắt, các tệp này sẽ hoàn toàn bị ẩn khỏi danh sách tệp và tìm kiếm."
 		},
 		"maxReadFile": {
-			"label": "Số dòng tối đa để đọc từ một tệp",
-			"description": "Số dòng tối đa để đọc từ một tệp cùng một lúc. Giá trị thấp hơn giảm sử dụng ngữ cảnh/tài nguyên nhưng có thể yêu cầu đọc nhiều lần hơn cho các tệp lớn."
+			"label": "Ngưỡng tự động cắt ngắn khi đọc tệp",
+			"description": "Số dòng mặc định để đọc từ một tệp trong một lô. Giá trị thấp hơn giảm sử dụng ngữ cảnh/tài nguyên nhưng có thể yêu cầu đọc nhiều lần hơn cho các tệp lớn.",
+			"lines": "dòng"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/zh-CN/settings.json

@@ -267,8 +267,9 @@
 			"description": "启用后,与 .rooignore 中模式匹配的文件将在列表中显示锁定符号。禁用时,这些文件将从文件列表和搜索中完全隐藏。"
 		},
 		"maxReadFile": {
-			"label": "文件读取的最大行数",
-			"description": "一次从文件读取的最大行数。较低的值会减少上下文/资源使用,但可能需要对大文件进行更多次读取。"
+			"label": "文件读取自动截断阈值",
+			"description": "一次批处理中从文件读取的默认行数。较低的值会减少上下文/资源使用,但可能需要对大文件进行更多次读取。",
+			"lines": "行"
 		}
 	},
 	"terminal": {

+ 3 - 2
webview-ui/src/i18n/locales/zh-TW/settings.json

@@ -267,8 +267,9 @@
 			"description": "啟用後,與 .rooignore 中模式匹配的檔案將在列表中顯示鎖定符號。禁用時,這些檔案將從檔案列表和搜尋中完全隱藏。"
 		},
 		"maxReadFile": {
-			"label": "從檔案讀取的最大行數",
-			"description": "一次從檔案讀取的最大行數。較低的值會減少內容/資源使用,但可能需要對大型檔案進行更多次讀取。"
+			"label": "檔案讀取自動截斷閾值",
+			"description": "一批中從檔案讀取的預設行數。較低的值會減少內容/資源使用,但可能需要對大型檔案進行更多次讀取。",
+			"lines": "行"
 		}
 	},
 	"terminal": {