Setting for number of terminal lines to return from commands

This commit is contained in:
Matt Rubens
2024-12-30 23:02:26 -08:00
parent 667312e48c
commit c8b8eff147
8 changed files with 72 additions and 5 deletions

View File

@@ -721,9 +721,9 @@ export class Cline {
}
}
let result = ""
let lines: string[] = []
process.on("line", (line) => {
result += line + "\n"
lines.push(line)
if (!didContinue) {
sendCommandOutput(line)
} else {
@@ -731,6 +731,22 @@ export class Cline {
}
})
const getFormattedOutput = async () => {
const { terminalOutputLineLimit } = await this.providerRef.deref()?.getState() ?? {}
const limit = terminalOutputLineLimit ?? 0
if (limit > 0 && lines.length > limit) {
const beforeLimit = Math.floor(limit * 0.2) // 20% of lines before
const afterLimit = limit - beforeLimit // remaining 80% after
return [
...lines.slice(0, beforeLimit),
`\n[...${lines.length - limit} lines omitted...]\n`,
...lines.slice(-afterLimit)
].join('\n')
}
return lines.join('\n')
}
let completed = false
process.once("completed", () => {
completed = true
@@ -749,7 +765,8 @@ export class Cline {
// grouping command_output messages despite any gaps anyways)
await delay(50)
result = result.trim()
const output = await getFormattedOutput()
const result = output.trim()
if (userFeedback) {
await this.say("user_feedback", userFeedback.text, userFeedback.images)