Fixes to terminal output processing

This commit is contained in:
Saoud Rizwan
2024-09-09 12:07:07 -04:00
parent 3bb4c3d408
commit 5866adb09f
2 changed files with 17 additions and 15 deletions

View File

@@ -1362,7 +1362,7 @@ export class ClaudeDev {
let result = "" let result = ""
process.on("line", (line) => { process.on("line", (line) => {
result += line result += line + "\n"
sendCommandOutput(line) sendCommandOutput(line)
}) })
@@ -1384,6 +1384,8 @@ export class ClaudeDev {
// grouping command_output messages despite any gaps anyways) // grouping command_output messages despite any gaps anyways)
await delay(50) await delay(50)
result = result.trim()
if (userFeedback) { if (userFeedback) {
await this.say("user_feedback", userFeedback.text, userFeedback.images) await this.say("user_feedback", userFeedback.text, userFeedback.images)
return this.formatToolResponseWithImages( return this.formatToolResponseWithImages(

View File

@@ -291,21 +291,21 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
// remove ansi // remove ansi
data = stripAnsi(data) data = stripAnsi(data)
// Split data by newlines // 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 // Remove non-human readable characters from the first line
if (lines.length > 0) { // if (lines.length > 0) {
lines[0] = lines[0].replace(/[^\x20-\x7E]/g, "") // lines[0] = lines[0].replace(/[^\x20-\x7E]/g, "")
} // }
// Check if first two characters are the same, if so remove the first character // // 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]) { // if (lines.length > 0 && lines[0].length >= 2 && lines[0][0] === lines[0][1]) {
lines[0] = lines[0].slice(1) // lines[0] = lines[0].slice(1)
} // }
// Process second line: remove everything up to the first alphanumeric character // // Process second line: remove everything up to the first alphanumeric character
if (lines.length > 1) { // if (lines.length > 1) {
lines[1] = lines[1].replace(/^[^a-zA-Z0-9]*/, "") // lines[1] = lines[1].replace(/^[^a-zA-Z0-9]*/, "")
} // }
// Join lines back // Join lines back
data = lines.join("\n") // data = lines.join("\n")
isFirstChunk = false isFirstChunk = false
} else { } else {
data = stripAnsi(data) data = stripAnsi(data)
@@ -369,7 +369,7 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
this.buffer += chunk this.buffer += chunk
let lineEndIndex: number let lineEndIndex: number
while ((lineEndIndex = this.buffer.indexOf("\n")) !== -1) { 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) // Remove \r if present (for Windows-style line endings)
// if (line.endsWith("\r")) { // if (line.endsWith("\r")) {
// line = line.slice(0, -1) // line = line.slice(0, -1)