From 269ddf9a0edd6bf1c4ad37658adb5bf04a516aa0 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Sun, 9 Mar 2025 19:10:19 -0700 Subject: [PATCH] fix: avoid duplicate terminal output accumulation Optimize terminal output handling to reduce memory pressure by: - Remove continuous result accumulation during line processing - Only store the same final output from the "completed" event that came from TerminalProcess Also: - Add clear error messages for undefined exit details Signed-off-by: Eric Wheeler --- src/core/Cline.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 98f45d4b70..d043e63412 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -966,9 +966,7 @@ export class Cline { const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {} - let result = "" process.on("line", (line) => { - result += line if (!didContinue) { sendCommandOutput(truncateOutput(line, terminalOutputLineLimit)) } else { @@ -977,10 +975,11 @@ export class Cline { }) let completed = false + let result: string = "" let exitDetails: ExitCodeDetails | undefined process.once("completed", (output?: string) => { // Use provided output if available, otherwise keep existing result. - result = output || result + result = output ?? "" completed = true }) @@ -1014,10 +1013,8 @@ export class Cline { userFeedback.images, ), ] - } - - if (completed) { - let exitStatus = "No exit code available" + } else if (completed) { + let exitStatus: string if (exitDetails !== undefined) { if (exitDetails.signal) { exitStatus = `Process terminated by signal ${exitDetails.signal} (${exitDetails.signalName})` @@ -1030,6 +1027,9 @@ export class Cline { } else { exitStatus = `Exit code: ${exitDetails.exitCode}` } + } else { + result += "" + exitStatus = `Exit code: ` } const workingDirInfo = workingDir ? ` from '${workingDir.toPosix()}'` : ""