Skip to content

Commit 49767f5

Browse files
committed
sdk: Truncate terminal command output past 50k chars
1 parent e8f185a commit 49767f5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sdk/src/tools/run-terminal-command.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import { spawn } from 'child_process'
22
import * as os from 'os'
33
import * as path from 'path'
44

5+
import {
6+
stripColors,
7+
truncateStringWithMessage,
8+
} from '../../../common/src/util/string'
59
import type { CodebuffToolOutput } from '../../../common/src/tools/list'
610

11+
const COMMAND_OUTPUT_LIMIT = 50_000
12+
713
export function runTerminalCommand({
814
command,
915
process_type,
@@ -75,10 +81,17 @@ export function runTerminalCommand({
7581
clearTimeout(timer)
7682
}
7783

84+
// Truncate stdout to prevent excessive output
85+
const truncatedStdout = truncateStringWithMessage({
86+
str: stripColors(stdout),
87+
maxLength: COMMAND_OUTPUT_LIMIT,
88+
remove: 'MIDDLE',
89+
})
90+
7891
// Include stderr in stdout for compatibility with existing behavior
7992
const combinedOutput = {
8093
command,
81-
stdout,
94+
stdout: truncatedStdout,
8295
...(stderr ? { stderr } : {}),
8396
...(exitCode !== null ? { exitCode } : {}),
8497
}

0 commit comments

Comments
 (0)