From 5866adb09fa4fe5610d82d8edf6a3dce5a749796 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:07:07 -0400 Subject: [PATCH] Fixes to terminal output processing --- src/ClaudeDev.ts | 4 +++- src/integrations/TerminalManager.ts | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index c0991c7..bbe72e2 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -1362,7 +1362,7 @@ export class ClaudeDev { let result = "" process.on("line", (line) => { - result += line + result += line + "\n" sendCommandOutput(line) }) @@ -1384,6 +1384,8 @@ export class ClaudeDev { // grouping command_output messages despite any gaps anyways) await delay(50) + result = result.trim() + if (userFeedback) { await this.say("user_feedback", userFeedback.text, userFeedback.images) return this.formatToolResponseWithImages( diff --git a/src/integrations/TerminalManager.ts b/src/integrations/TerminalManager.ts index aa3188e..da7dd4e 100644 --- a/src/integrations/TerminalManager.ts +++ b/src/integrations/TerminalManager.ts @@ -291,21 +291,21 @@ export class TerminalProcess extends EventEmitter { // remove ansi data = stripAnsi(data) // Split data by newlines - let lines = data ? data.split("\n") : [] + // let lines = data ? data.split("\n") : [] // Remove non-human readable characters from the first line - if (lines.length > 0) { - lines[0] = lines[0].replace(/[^\x20-\x7E]/g, "") - } - // Check if first two characters are the same, if so remove the first character - if (lines.length > 0 && lines[0].length >= 2 && lines[0][0] === lines[0][1]) { - lines[0] = lines[0].slice(1) - } - // Process second line: remove everything up to the first alphanumeric character - if (lines.length > 1) { - lines[1] = lines[1].replace(/^[^a-zA-Z0-9]*/, "") - } + // if (lines.length > 0) { + // lines[0] = lines[0].replace(/[^\x20-\x7E]/g, "") + // } + // // Check if first two characters are the same, if so remove the first character + // if (lines.length > 0 && lines[0].length >= 2 && lines[0][0] === lines[0][1]) { + // lines[0] = lines[0].slice(1) + // } + // // Process second line: remove everything up to the first alphanumeric character + // if (lines.length > 1) { + // lines[1] = lines[1].replace(/^[^a-zA-Z0-9]*/, "") + // } // Join lines back - data = lines.join("\n") + // data = lines.join("\n") isFirstChunk = false } else { data = stripAnsi(data) @@ -369,7 +369,7 @@ export class TerminalProcess extends EventEmitter { this.buffer += chunk let lineEndIndex: number while ((lineEndIndex = this.buffer.indexOf("\n")) !== -1) { - let line = this.buffer.slice(0, lineEndIndex).trim() // removes trailing \r + let line = this.buffer.slice(0, lineEndIndex).trimEnd() // removes trailing \r // Remove \r if present (for Windows-style line endings) // if (line.endsWith("\r")) { // line = line.slice(0, -1)