summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/shell.ts
diff options
context:
space:
mode:
authorGal Zahavi <[email protected]>2025-08-15 10:27:33 -0700
committerGitHub <[email protected]>2025-08-15 17:27:33 +0000
commit1a2906a8ad6e9cf7a68441c956af91d189eff417 (patch)
tree599da5522cfa33c30793d57a73fd4ff93ab50daf /packages/core/src/tools/shell.ts
parentab1c483cab659ac2ab081e74a0e3bd0fcc48a734 (diff)
Revert #6088 (#6328)
Diffstat (limited to 'packages/core/src/tools/shell.ts')
-rw-r--r--packages/core/src/tools/shell.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts
index 621ff90f..5b01a82f 100644
--- a/packages/core/src/tools/shell.ts
+++ b/packages/core/src/tools/shell.ts
@@ -97,8 +97,6 @@ class ShellToolInvocation extends BaseToolInvocation<
async execute(
signal: AbortSignal,
updateOutput?: (output: string) => void,
- terminalColumns?: number,
- terminalRows?: number,
): Promise<ToolResult> {
const strippedCommand = stripShellWrapper(this.params.command);
@@ -131,7 +129,9 @@ class ShellToolInvocation extends BaseToolInvocation<
this.params.directory || '',
);
- let cumulativeOutput = '';
+ let cumulativeStdout = '';
+ let cumulativeStderr = '';
+
let lastUpdateTime = Date.now();
let isBinaryStream = false;
@@ -148,9 +148,15 @@ class ShellToolInvocation extends BaseToolInvocation<
switch (event.type) {
case 'data':
- if (isBinaryStream) break;
- cumulativeOutput = event.chunk;
- currentDisplayOutput = cumulativeOutput;
+ if (isBinaryStream) break; // Don't process text if we are in binary mode
+ if (event.stream === 'stdout') {
+ cumulativeStdout += event.chunk;
+ } else {
+ cumulativeStderr += event.chunk;
+ }
+ currentDisplayOutput =
+ cumulativeStdout +
+ (cumulativeStderr ? `\n${cumulativeStderr}` : '');
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
shouldUpdate = true;
}
@@ -181,8 +187,6 @@ class ShellToolInvocation extends BaseToolInvocation<
}
},
signal,
- terminalColumns,
- terminalRows,
);
const result = await resultPromise;
@@ -214,7 +218,7 @@ class ShellToolInvocation extends BaseToolInvocation<
if (result.aborted) {
llmContent = 'Command was cancelled by user before it could complete.';
if (result.output.trim()) {
- llmContent += ` Below is the output before it was cancelled:\n${result.output}`;
+ llmContent += ` Below is the output (on stdout and stderr) before it was cancelled:\n${result.output}`;
} else {
llmContent += ' There was no output before it was cancelled.';
}
@@ -228,7 +232,8 @@ class ShellToolInvocation extends BaseToolInvocation<
llmContent = [
`Command: ${this.params.command}`,
`Directory: ${this.params.directory || '(root)'}`,
- `Output: ${result.output || '(empty)'}`,
+ `Stdout: ${result.stdout || '(empty)'}`,
+ `Stderr: ${result.stderr || '(empty)'}`,
`Error: ${finalError}`, // Use the cleaned error string.
`Exit Code: ${result.exitCode ?? '(none)'}`,
`Signal: ${result.signal ?? '(none)'}`,