Skip to content

Commit 0b4fa0b

Browse files
author
Eric Wheeler
committed
feat: compress repeated terminal output lines
Add Terminal.compressTerminalOutput static method to apply run-length encoding before truncating terminal output. This significantly reduces output size for repeated lines while maintaining readability. - Add compressTerminalOutput static method to Terminal class - Replace all truncateOutput calls with Terminal.compressTerminalOutput - Import required functions from extract-text Test program demonstrating compression: ```python def generate_repeats(): patterns = [ ("A\n", 10), # 10 lines ("AA\n", 100), # 100 lines ("AAA\n", 1000), # 1K lines ("AAAA\n", 10000), # 10K lines ("AAAAA\n", 100000), # 100K lines ("AAAAAA\n", 1000000) # 1M lines ] for text, count in patterns: print(text * count, end="") ``` Sample output showing compression: ``` A A A A A A A A A A AA <previous line repeated 99 additional times> AAA <previous line repeated 999 additional times> AAAA <previous line repeated 9999 additional times> AAAAA <previous line repeated 99999 additional times> AAAAAA <previous line repeated 999999 additional times> ``` Signed-off-by: Eric Wheeler <[email protected]>
1 parent 131f9ad commit 0b4fa0b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/core/Cline.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import {
2525
addLineNumbers,
2626
stripLineNumbers,
2727
everyLineHasLineNumbers,
28-
truncateOutput,
2928
} from "../integrations/misc/extract-text"
3029
import { ExitCodeDetails } from "../integrations/terminal/TerminalProcess"
30+
import { Terminal } from "../integrations/terminal/Terminal"
3131
import { TerminalRegistry } from "../integrations/terminal/TerminalRegistry"
3232
import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
3333
import { listFiles } from "../services/glob/list-files"
@@ -968,9 +968,9 @@ export class Cline {
968968

969969
process.on("line", (line) => {
970970
if (!didContinue) {
971-
sendCommandOutput(truncateOutput(line, terminalOutputLineLimit))
971+
sendCommandOutput(Terminal.compressTerminalOutput(line, terminalOutputLineLimit))
972972
} else {
973-
this.say("command_output", truncateOutput(line, terminalOutputLineLimit))
973+
this.say("command_output", Terminal.compressTerminalOutput(line, terminalOutputLineLimit))
974974
}
975975
})
976976

@@ -1000,7 +1000,7 @@ export class Cline {
10001000
// grouping command_output messages despite any gaps anyways)
10011001
await delay(50)
10021002

1003-
result = truncateOutput(result, terminalOutputLineLimit)
1003+
result = Terminal.compressTerminalOutput(result, terminalOutputLineLimit)
10041004

10051005
if (userFeedback) {
10061006
await this.say("user_feedback", userFeedback.text, userFeedback.images)
@@ -3546,7 +3546,7 @@ export class Cline {
35463546
terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\``
35473547
let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)
35483548
if (newOutput) {
3549-
newOutput = truncateOutput(newOutput, terminalOutputLineLimit)
3549+
newOutput = Terminal.compressTerminalOutput(newOutput, terminalOutputLineLimit)
35503550
terminalDetails += `\n### New Output\n${newOutput}`
35513551
} else {
35523552
// details += `\n(Still running, no new output)` // don't want to show this right after running the command
@@ -3573,7 +3573,7 @@ export class Cline {
35733573
for (const process of completedProcesses) {
35743574
let output = process.getUnretrievedOutput()
35753575
if (output) {
3576-
output = truncateOutput(output, terminalOutputLineLimit)
3576+
output = Terminal.compressTerminalOutput(output, terminalOutputLineLimit)
35773577
terminalOutputs.push(`Command: \`${process.command}\`\n${output}`)
35783578
}
35793579
}

src/integrations/terminal/Terminal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode"
22
import pWaitFor from "p-wait-for"
33
import { ExitCodeDetails, mergePromise, TerminalProcess, TerminalProcessResultPromise } from "./TerminalProcess"
4+
import { truncateOutput, applyRunLengthEncoding } from "../misc/extract-text"
45

56
export class Terminal {
67
public terminal: vscode.Terminal
@@ -218,4 +219,13 @@ export class Terminal {
218219
throw error
219220
}
220221
}
222+
223+
/**
224+
* Compresses terminal output by applying run-length encoding and truncating to line limit
225+
* @param input The terminal output to compress
226+
* @returns The compressed terminal output
227+
*/
228+
public static compressTerminalOutput(input: string, lineLimit: number): string {
229+
return truncateOutput(applyRunLengthEncoding(input), lineLimit)
230+
}
221231
}

0 commit comments

Comments
 (0)