From 5be49e1d1559cca8db63f4022f8059e64276da13 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Sun, 9 Mar 2025 16:09:27 -0700 Subject: [PATCH] fix: apply terminal output line limits consistently Apply terminalOutputLineLimit to command output lines as they are received, rather than only at the end of command execution. Also apply the limit to terminal output shown in environment details. This ensures consistent output truncation behavior across all terminal output paths, preventing potential memory issues from large outputs. Signed-off-by: Eric Wheeler --- src/core/Cline.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index a6c5fdf563..98f45d4b70 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -964,13 +964,15 @@ export class Cline { } } + const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {} + let result = "" process.on("line", (line) => { result += line if (!didContinue) { - sendCommandOutput(line) + sendCommandOutput(truncateOutput(line, terminalOutputLineLimit)) } else { - this.say("command_output", line) + this.say("command_output", truncateOutput(line, terminalOutputLineLimit)) } }) @@ -999,7 +1001,6 @@ export class Cline { // grouping command_output messages despite any gaps anyways) await delay(50) - const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {} result = truncateOutput(result, terminalOutputLineLimit) if (userFeedback) { @@ -3461,6 +3462,8 @@ export class Cline { async getEnvironmentDetails(includeFileDetails: boolean = false) { let details = "" + const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {} + // It could be useful for cline to know if the user went from one or no file to another between messages, so we always include this context details += "\n\n# VSCode Visible Files" const visibleFilePaths = vscode.window.visibleTextEditors @@ -3541,8 +3544,9 @@ export class Cline { terminalDetails += "\n\n# Actively Running Terminals" for (const busyTerminal of busyTerminals) { terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\`` - const newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id) + let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id) if (newOutput) { + newOutput = truncateOutput(newOutput, terminalOutputLineLimit) terminalDetails += `\n### New Output\n${newOutput}` } else { // details += `\n(Still running, no new output)` // don't want to show this right after running the command @@ -3567,8 +3571,9 @@ export class Cline { // Get output from completed processes queue const completedProcesses = inactiveTerminal.getProcessesWithOutput() for (const process of completedProcesses) { - const output = process.getUnretrievedOutput() + let output = process.getUnretrievedOutput() if (output) { + output = truncateOutput(output, terminalOutputLineLimit) terminalOutputs.push(`Command: \`${process.command}\`\n${output}`) } }