Skip to content

Commit 4212e4a

Browse files
author
Eric Wheeler
committed
fix: restore file truncation backward compatibility and fix regressions
Fixes #1934 - Setting maxReadFileLine=-1 provides equivalent functionality for reading entire files - Revert to system-controlled maxReadFileLine for file truncation, fixing regressions with: - Overridden system prompts lacking auto_truncate parameter information - Insufficient user control over truncation behavior - Add 'Always read entire file' checkbox for easier access to full file reading - Update translations across all locales with improved descriptions - Update truncation notice to be more concise Signed-off-by: Eric Wheeler <[email protected]>
1 parent 55bbe88 commit 4212e4a

File tree

20 files changed

+77
-198
lines changed

20 files changed

+77
-198
lines changed

src/core/Cline.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,6 @@ export class Cline extends EventEmitter<ClineEvents> {
23552355
let sourceCodeDef = ""
23562356

23572357
const isBinary = await isBinaryFile(absolutePath).catch(() => false)
2358-
const autoTruncate = block.params.auto_truncate === "true"
23592358

23602359
if (isRangeRead) {
23612360
if (startLine === undefined) {
@@ -2366,7 +2365,7 @@ export class Cline extends EventEmitter<ClineEvents> {
23662365
startLine + 1,
23672366
)
23682367
}
2369-
} else if (autoTruncate && !isBinary && totalLines > maxReadFileLine) {
2368+
} else if (!isBinary && maxReadFileLine >= 0 && totalLines > maxReadFileLine) {
23702369
// If file is too large, only read the first maxReadFileLine lines
23712370
isFileTruncated = true
23722371

@@ -2387,7 +2386,7 @@ export class Cline extends EventEmitter<ClineEvents> {
23872386

23882387
// Add truncation notice if applicable
23892388
if (isFileTruncated) {
2390-
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}`
2389+
content += `\n\n[Showing only ${maxReadFileLine} of ${totalLines} total lines. Use start_line and end_line if you need to read more]${sourceCodeDef}`
23912390
}
23922391

23932392
pushToolResult(content)

src/core/assistant-message/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const toolParamNames = [
5252
"diff",
5353
"start_line",
5454
"end_line",
55-
"auto_truncate",
5655
"mode_slug",
5756
"reason",
5857
"operations",

src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Lines changed: 15 additions & 150 deletions
Large diffs are not rendered by default.

src/core/prompts/tools/read-file.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ Parameters:
77
- path: (required) The path of the file to read (relative to the current working directory ${args.cwd})
88
- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
99
- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
10-
- 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.
1110
Usage:
1211
<read_file>
1312
<path>File path here</path>
1413
<start_line>Starting line number (optional)</start_line>
1514
<end_line>Ending line number (optional)</end_line>
16-
<auto_truncate>true or false (optional)</auto_truncate>
1715
</read_file>
1816
1917
Examples:
@@ -42,13 +40,6 @@ Examples:
4240
<start_line>46</start_line>
4341
<end_line>68</end_line>
4442
</read_file>
45-
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.
4643
47-
5. Reading a large file with automatic truncation:
48-
<read_file>
49-
<path>src/large-module.ts</path>
50-
<auto_truncate>true</auto_truncate>
51-
</read_file>
52-
53-
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.`
44+
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.`
5445
}

webview-ui/src/components/settings/ContextManagementSettings.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,32 @@ export const ContextManagementSettings = ({
9595
<div>
9696
<div className="flex flex-col gap-2">
9797
<span className="font-medium">{t("settings:contextManagement.maxReadFile.label")}</span>
98-
<div className="flex items-center gap-2">
98+
<div className="flex items-center gap-4">
9999
<input
100100
type="number"
101-
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"
101+
pattern="-?[0-9]*"
102+
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 disabled:opacity-50"
102103
value={maxReadFileLine ?? 500}
103-
min={0}
104+
min={-1}
104105
onChange={(e) => {
105106
const newValue = parseInt(e.target.value, 10)
106-
if (!isNaN(newValue) && newValue >= 0) {
107+
if (!isNaN(newValue) && newValue >= -1) {
107108
setCachedStateField("maxReadFileLine", newValue)
108109
}
109110
}}
110111
onClick={(e) => e.currentTarget.select()}
111112
data-testid="max-read-file-line-input"
113+
disabled={maxReadFileLine === -1}
112114
/>
113115
<span>{t("settings:contextManagement.maxReadFile.lines")}</span>
116+
<VSCodeCheckbox
117+
checked={maxReadFileLine === -1}
118+
onChange={(e: any) =>
119+
setCachedStateField("maxReadFileLine", e.target.checked ? -1 : 500)
120+
}
121+
data-testid="max-read-file-always-full-checkbox">
122+
{t("settings:contextManagement.maxReadFile.always_full_read")}
123+
</VSCodeCheckbox>
114124
</div>
115125
</div>
116126
<div className="text-vscode-descriptionForeground text-sm mt-2">

webview-ui/src/i18n/locales/ca/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@
276276
},
277277
"maxReadFile": {
278278
"label": "Llindar d'auto-truncament de lectura de fitxers",
279-
"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.",
280-
"lines": "línies"
279+
"description": "Roo llegeix aquest nombre de línies quan el model omet els valors d'inici/final. Si aquest nombre és menor que el total del fitxer, Roo genera un índex de números de línia de les definicions de codi. Casos especials: -1 indica a Roo que llegeixi tot el fitxer (sense indexació), i 0 indica que no llegeixi cap línia i proporcioni només índexs de línia per a un context mínim. Valors més baixos minimitzen l'ús inicial de context, permetent lectures posteriors de rangs de línies precisos. Les sol·licituds amb inici/final explícits no estan limitades per aquesta configuració.",
280+
"lines": "línies",
281+
"always_full_read": "Llegeix sempre el fitxer sencer"
281282
}
282283
},
283284
"terminal": {

webview-ui/src/i18n/locales/de/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@
276276
},
277277
"maxReadFile": {
278278
"label": "Schwellenwert für automatische Dateilesekürzung",
279-
"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.",
280-
"lines": "Zeilen"
279+
"description": "Roo liest diese Anzahl von Zeilen, wenn das Modell keine Start-/Endwerte angibt. Wenn diese Zahl kleiner als die Gesamtzahl der Zeilen ist, erstellt Roo einen Zeilennummernindex der Codedefinitionen. Spezialfälle: -1 weist Roo an, die gesamte Datei zu lesen (ohne Indexierung), und 0 weist an, keine Zeilen zu lesen und nur Zeilenindizes für minimalen Kontext bereitzustellen. Niedrigere Werte minimieren die anfängliche Kontextnutzung und ermöglichen präzise nachfolgende Zeilenbereich-Lesungen. Explizite Start-/End-Anfragen sind von dieser Einstellung nicht begrenzt.",
280+
"lines": "Zeilen",
281+
"always_full_read": "Immer die gesamte Datei lesen"
281282
}
282283
},
283284
"terminal": {

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@
276276
},
277277
"maxReadFile": {
278278
"label": "File read auto-truncate threshold",
279-
"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.",
280-
"lines": "lines"
279+
"description": "Roo reads this number of lines when the model omits start/end values. If this number is less than the file's total, Roo generates a line number index of code definitions. Special cases: -1 instructs Roo to read the entire file (without indexing), and 0 instructs it to read no lines and provides line indexes only for minimal context. Lower values minimize initial context usage, enabling precise subsequent line-range reads. Explicit start/end requests are not limited by this setting.",
280+
"lines": "lines",
281+
"always_full_read": "Always read entire file"
281282
}
282283
},
283284
"terminal": {

webview-ui/src/i18n/locales/es/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@
276276
},
277277
"maxReadFile": {
278278
"label": "Umbral de auto-truncado de lectura de archivos",
279-
"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.",
280-
"lines": "líneas"
279+
"description": "Roo lee este número de líneas cuando el modelo omite valores de inicio/fin. Si este número es menor que el total del archivo, Roo genera un índice de números de línea de las definiciones de código. Casos especiales: -1 indica a Roo que lea el archivo completo (sin indexación), y 0 indica que no lea líneas y proporcione solo índices de línea para un contexto mínimo. Valores más bajos minimizan el uso inicial de contexto, permitiendo lecturas posteriores de rangos de líneas precisos. Las solicitudes con inicio/fin explícitos no están limitadas por esta configuración.",
280+
"lines": "líneas",
281+
"always_full_read": "Siempre leer el archivo completo"
281282
}
282283
},
283284
"terminal": {

webview-ui/src/i18n/locales/fr/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@
276276
},
277277
"maxReadFile": {
278278
"label": "Seuil d'auto-troncature de lecture de fichier",
279-
"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.",
280-
"lines": "lignes"
279+
"description": "Roo lit ce nombre de lignes lorsque le modèle omet les valeurs de début/fin. Si ce nombre est inférieur au total du fichier, Roo génère un index des numéros de ligne des définitions de code. Cas spéciaux : -1 indique à Roo de lire le fichier entier (sans indexation), et 0 indique de ne lire aucune ligne et de fournir uniquement les index de ligne pour un contexte minimal. Des valeurs plus basses minimisent l'utilisation initiale du contexte, permettant des lectures ultérieures de plages de lignes précises. Les requêtes avec début/fin explicites ne sont pas limitées par ce paramètre.",
280+
"lines": "lignes",
281+
"always_full_read": "Toujours lire le fichier entier"
281282
}
282283
},
283284
"terminal": {

0 commit comments

Comments
 (0)