Skip to content

Commit 5be49e1

Browse files
author
Eric Wheeler
committed
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 <[email protected]>
1 parent c31a5e5 commit 5be49e1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/core/Cline.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,13 +964,15 @@ export class Cline {
964964
}
965965
}
966966

967+
const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {}
968+
967969
let result = ""
968970
process.on("line", (line) => {
969971
result += line
970972
if (!didContinue) {
971-
sendCommandOutput(line)
973+
sendCommandOutput(truncateOutput(line, terminalOutputLineLimit))
972974
} else {
973-
this.say("command_output", line)
975+
this.say("command_output", truncateOutput(line, terminalOutputLineLimit))
974976
}
975977
})
976978

@@ -999,7 +1001,6 @@ export class Cline {
9991001
// grouping command_output messages despite any gaps anyways)
10001002
await delay(50)
10011003

1002-
const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {}
10031004
result = truncateOutput(result, terminalOutputLineLimit)
10041005

10051006
if (userFeedback) {
@@ -3461,6 +3462,8 @@ export class Cline {
34613462
async getEnvironmentDetails(includeFileDetails: boolean = false) {
34623463
let details = ""
34633464

3465+
const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {}
3466+
34643467
// 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
34653468
details += "\n\n# VSCode Visible Files"
34663469
const visibleFilePaths = vscode.window.visibleTextEditors
@@ -3541,8 +3544,9 @@ export class Cline {
35413544
terminalDetails += "\n\n# Actively Running Terminals"
35423545
for (const busyTerminal of busyTerminals) {
35433546
terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\``
3544-
const newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)
3547+
let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)
35453548
if (newOutput) {
3549+
newOutput = truncateOutput(newOutput, terminalOutputLineLimit)
35463550
terminalDetails += `\n### New Output\n${newOutput}`
35473551
} else {
35483552
// 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 {
35673571
// Get output from completed processes queue
35683572
const completedProcesses = inactiveTerminal.getProcessesWithOutput()
35693573
for (const process of completedProcesses) {
3570-
const output = process.getUnretrievedOutput()
3574+
let output = process.getUnretrievedOutput()
35713575
if (output) {
3576+
output = truncateOutput(output, terminalOutputLineLimit)
35723577
terminalOutputs.push(`Command: \`${process.command}\`\n${output}`)
35733578
}
35743579
}

0 commit comments

Comments
 (0)