From 5720b6b12915f0eea11163e28c446f0271cc2593 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 24 Mar 2025 00:49:37 -0400 Subject: [PATCH] Tweaks to file read auto-truncate (#1934) * Tweaks to file read auto-truncate * Change to use a text input * Changeset --- .changeset/old-llamas-fold.md | 5 + src/core/Cline.ts | 5 +- src/core/assistant-message/index.ts | 1 + .../__snapshots__/system.test.ts.snap | 165 ++++++++++++++++-- src/core/prompts/tools/read-file.ts | 11 +- .../settings/ContextManagementSettings.tsx | 22 ++- webview-ui/src/i18n/locales/ca/settings.json | 5 +- webview-ui/src/i18n/locales/de/settings.json | 5 +- webview-ui/src/i18n/locales/en/settings.json | 5 +- webview-ui/src/i18n/locales/es/settings.json | 5 +- webview-ui/src/i18n/locales/fr/settings.json | 5 +- webview-ui/src/i18n/locales/hi/settings.json | 5 +- webview-ui/src/i18n/locales/it/settings.json | 5 +- webview-ui/src/i18n/locales/ja/settings.json | 5 +- webview-ui/src/i18n/locales/ko/settings.json | 5 +- webview-ui/src/i18n/locales/pl/settings.json | 5 +- .../src/i18n/locales/pt-BR/settings.json | 5 +- webview-ui/src/i18n/locales/tr/settings.json | 5 +- webview-ui/src/i18n/locales/vi/settings.json | 5 +- .../src/i18n/locales/zh-CN/settings.json | 5 +- .../src/i18n/locales/zh-TW/settings.json | 5 +- 21 files changed, 228 insertions(+), 56 deletions(-) create mode 100644 .changeset/old-llamas-fold.md diff --git a/.changeset/old-llamas-fold.md b/.changeset/old-llamas-fold.md new file mode 100644 index 0000000000..e57e80e378 --- /dev/null +++ b/.changeset/old-llamas-fold.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Auto-truncate diff --git a/src/core/Cline.ts b/src/core/Cline.ts index cdc9b5d6ec..81cdd671fc 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -2326,6 +2326,7 @@ export class Cline extends EventEmitter { 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 { 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 { // 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) diff --git a/src/core/assistant-message/index.ts b/src/core/assistant-message/index.ts index 81e6edb95b..5409c4bbe2 100644 --- a/src/core/assistant-message/index.ts +++ b/src/core/assistant-message/index.ts @@ -51,6 +51,7 @@ export const toolParamNames = [ "diff", "start_line", "end_line", + "auto_truncate", "mode_slug", "reason", "operations", diff --git a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap index 1bfc98ac0b..de3c920d19 100644 --- a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap +++ b/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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -68,9 +70,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -445,9 +456,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -911,9 +931,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -1341,9 +1370,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -1718,9 +1756,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -2095,9 +2142,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -2472,9 +2528,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -2898,9 +2963,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -3729,9 +3803,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -4155,9 +4238,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -4594,9 +4686,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -5013,9 +5114,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -5552,9 +5662,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -6005,9 +6124,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -6356,9 +6484,16 @@ Examples: 46 68 - 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: + +src/large-module.ts +true + + +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: diff --git a/src/core/prompts/tools/read-file.ts b/src/core/prompts/tools/read-file.ts index 5586b90dc4..4932297319 100644 --- a/src/core/prompts/tools/read-file.ts +++ b/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: File path here Starting line number (optional) Ending line number (optional) +true or false (optional) Examples: @@ -40,6 +42,13 @@ Examples: 46 68 +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: + +src/large-module.ts +true + + +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.` } diff --git a/webview-ui/src/components/settings/ContextManagementSettings.tsx b/webview-ui/src/components/settings/ContextManagementSettings.tsx index 947ba7382c..0e8a580be6 100644 --- a/webview-ui/src/components/settings/ContextManagementSettings.tsx +++ b/webview-ui/src/components/settings/ContextManagementSettings.tsx @@ -96,18 +96,24 @@ export const ContextManagementSettings = ({
{t("settings:contextManagement.maxReadFile.label")}
- 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" /> - {maxReadFileLine ?? 450} + {t("settings:contextManagement.maxReadFile.lines")}
-
+
{t("settings:contextManagement.maxReadFile.description")}
diff --git a/webview-ui/src/i18n/locales/ca/settings.json b/webview-ui/src/i18n/locales/ca/settings.json index 571da595eb..b5d5ff2708 100644 --- a/webview-ui/src/i18n/locales/ca/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/de/settings.json b/webview-ui/src/i18n/locales/de/settings.json index 277ab83982..05d195a093 100644 --- a/webview-ui/src/i18n/locales/de/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/en/settings.json b/webview-ui/src/i18n/locales/en/settings.json index 29b163512e..7fd923b4ee 100644 --- a/webview-ui/src/i18n/locales/en/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/es/settings.json b/webview-ui/src/i18n/locales/es/settings.json index ccc255e8a1..9c5ae82da9 100644 --- a/webview-ui/src/i18n/locales/es/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/fr/settings.json b/webview-ui/src/i18n/locales/fr/settings.json index 63a3c4be71..1553e11876 100644 --- a/webview-ui/src/i18n/locales/fr/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/hi/settings.json b/webview-ui/src/i18n/locales/hi/settings.json index ba0461071f..26054ea70d 100644 --- a/webview-ui/src/i18n/locales/hi/settings.json +++ b/webview-ui/src/i18n/locales/hi/settings.json @@ -267,8 +267,9 @@ "description": "जब सक्षम होता है, .rooignore में पैटर्न से मेल खाने वाली फाइलें लॉक प्रतीक के साथ सूचियों में दिखाई जाएंगी। जब अक्षम होता है, ये फाइलें फाइल सूचियों और खोजों से पूरी तरह छिपा दी जाएंगी।" }, "maxReadFile": { - "label": "फ़ाइल से पढ़ने के लिए अधिकतम लाइनें", - "description": "फ़ाइल से एक बार में पढ़ने के लिए अधिकतम लाइनों की संख्या। कम मान संदर्भ/संसाधन उपयोग को कम करते हैं लेकिन बड़ी फाइलों के लिए अधिक पठन की आवश्यकता हो सकती है।" + "label": "फ़ाइल पढ़ने का स्वचालित काटने की सीमा", + "description": "एक बैच में फ़ाइल से पढ़ने के लिए डिफ़ॉल्ट लाइनों की संख्या। कम मान संदर्भ/संसाधन उपयोग को कम करते हैं लेकिन बड़ी फाइलों के लिए अधिक पठन की आवश्यकता हो सकती है।", + "lines": "पंक्तियाँ" } }, "terminal": { diff --git a/webview-ui/src/i18n/locales/it/settings.json b/webview-ui/src/i18n/locales/it/settings.json index 4d5ea142a2..1e62f7bac8 100644 --- a/webview-ui/src/i18n/locales/it/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/ja/settings.json b/webview-ui/src/i18n/locales/ja/settings.json index 21a2f5410e..5bbbc20a6f 100644 --- a/webview-ui/src/i18n/locales/ja/settings.json +++ b/webview-ui/src/i18n/locales/ja/settings.json @@ -267,8 +267,9 @@ "description": "有効にすると、.rooignoreのパターンに一致するファイルがロックシンボル付きでリストに表示されます。無効にすると、これらのファイルはファイルリストや検索から完全に非表示になります。" }, "maxReadFile": { - "label": "ファイルから読み込む最大行数", - "description": "一度にファイルから読み込む最大行数。低い値はコンテキスト/リソース使用量を減らしますが、大きなファイルではより多くの読み込みが必要になる場合があります。" + "label": "ファイル読み込み自動切り詰めしきい値", + "description": "一括でファイルから読み込むデフォルトの行数。低い値はコンテキスト/リソース使用量を減らしますが、大きなファイルではより多くの読み込みが必要になる場合があります。", + "lines": "行" } }, "terminal": { diff --git a/webview-ui/src/i18n/locales/ko/settings.json b/webview-ui/src/i18n/locales/ko/settings.json index 54debd390f..60d0e94405 100644 --- a/webview-ui/src/i18n/locales/ko/settings.json +++ b/webview-ui/src/i18n/locales/ko/settings.json @@ -267,8 +267,9 @@ "description": "활성화되면 .rooignore의 패턴과 일치하는 파일이 잠금 기호와 함께 목록에 표시됩니다. 비활성화되면 이러한 파일은 파일 목록 및 검색에서 완전히 숨겨집니다." }, "maxReadFile": { - "label": "파일에서 읽을 최대 라인 수", - "description": "한 번에 파일에서 읽을 최대 라인 수. 낮은 값은 컨텍스트/리소스 사용량을 줄이지만 대용량 파일의 경우 더 많은 읽기가 필요할 수 있습니다." + "label": "파일 읽기 자동 축소 임계값", + "description": "한 번에 파일에서 읽을 기본 라인 수. 낮은 값은 컨텍스트/리소스 사용량을 줄이지만 대용량 파일의 경우 더 많은 읽기가 필요할 수 있습니다.", + "lines": "줄" } }, "terminal": { diff --git a/webview-ui/src/i18n/locales/pl/settings.json b/webview-ui/src/i18n/locales/pl/settings.json index 2b5938ddd7..1e4709df3f 100644 --- a/webview-ui/src/i18n/locales/pl/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/pt-BR/settings.json b/webview-ui/src/i18n/locales/pt-BR/settings.json index a7c4b7283e..db3f745830 100644 --- a/webview-ui/src/i18n/locales/pt-BR/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/tr/settings.json b/webview-ui/src/i18n/locales/tr/settings.json index 078c495c46..d02e16cd5c 100644 --- a/webview-ui/src/i18n/locales/tr/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/vi/settings.json b/webview-ui/src/i18n/locales/vi/settings.json index 5344cc7330..bd197f2aab 100644 --- a/webview-ui/src/i18n/locales/vi/settings.json +++ b/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": { diff --git a/webview-ui/src/i18n/locales/zh-CN/settings.json b/webview-ui/src/i18n/locales/zh-CN/settings.json index aec816d94a..d19096787d 100644 --- a/webview-ui/src/i18n/locales/zh-CN/settings.json +++ b/webview-ui/src/i18n/locales/zh-CN/settings.json @@ -267,8 +267,9 @@ "description": "启用后,与 .rooignore 中模式匹配的文件将在列表中显示锁定符号。禁用时,这些文件将从文件列表和搜索中完全隐藏。" }, "maxReadFile": { - "label": "文件读取的最大行数", - "description": "一次从文件读取的最大行数。较低的值会减少上下文/资源使用,但可能需要对大文件进行更多次读取。" + "label": "文件读取自动截断阈值", + "description": "一次批处理中从文件读取的默认行数。较低的值会减少上下文/资源使用,但可能需要对大文件进行更多次读取。", + "lines": "行" } }, "terminal": { diff --git a/webview-ui/src/i18n/locales/zh-TW/settings.json b/webview-ui/src/i18n/locales/zh-TW/settings.json index a2778f5bb8..aed74ae3aa 100644 --- a/webview-ui/src/i18n/locales/zh-TW/settings.json +++ b/webview-ui/src/i18n/locales/zh-TW/settings.json @@ -267,8 +267,9 @@ "description": "啟用後,與 .rooignore 中模式匹配的檔案將在列表中顯示鎖定符號。禁用時,這些檔案將從檔案列表和搜尋中完全隱藏。" }, "maxReadFile": { - "label": "從檔案讀取的最大行數", - "description": "一次從檔案讀取的最大行數。較低的值會減少內容/資源使用,但可能需要對大型檔案進行更多次讀取。" + "label": "檔案讀取自動截斷閾值", + "description": "一批中從檔案讀取的預設行數。較低的值會減少內容/資源使用,但可能需要對大型檔案進行更多次讀取。", + "lines": "行" } }, "terminal": {