diff options
| author | Gal Zahavi <[email protected]> | 2025-08-14 13:40:12 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-14 20:40:12 +0000 |
| commit | 980091cbc2a809690dbd401c16ec3ac34da56083 (patch) | |
| tree | 5bdadbdbebcaf6471f753ef31ef3fdc6a7716ae3 /packages/core/src/tools/shell.ts | |
| parent | 48af0456c1883834a83ae74281f0c871129779d8 (diff) | |
feat(core): refactor shell execution to use node-pty (#6088)
Diffstat (limited to 'packages/core/src/tools/shell.ts')
| -rw-r--r-- | packages/core/src/tools/shell.ts | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 5b01a82f..621ff90f 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -97,6 +97,8 @@ class ShellToolInvocation extends BaseToolInvocation< async execute( signal: AbortSignal, updateOutput?: (output: string) => void, + terminalColumns?: number, + terminalRows?: number, ): Promise<ToolResult> { const strippedCommand = stripShellWrapper(this.params.command); @@ -129,9 +131,7 @@ class ShellToolInvocation extends BaseToolInvocation< this.params.directory || '', ); - let cumulativeStdout = ''; - let cumulativeStderr = ''; - + let cumulativeOutput = ''; let lastUpdateTime = Date.now(); let isBinaryStream = false; @@ -148,15 +148,9 @@ class ShellToolInvocation extends BaseToolInvocation< switch (event.type) { case 'data': - 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 (isBinaryStream) break; + cumulativeOutput = event.chunk; + currentDisplayOutput = cumulativeOutput; if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) { shouldUpdate = true; } @@ -187,6 +181,8 @@ class ShellToolInvocation extends BaseToolInvocation< } }, signal, + terminalColumns, + terminalRows, ); const result = await resultPromise; @@ -218,7 +214,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 (on stdout and stderr) before it was cancelled:\n${result.output}`; + llmContent += ` Below is the output before it was cancelled:\n${result.output}`; } else { llmContent += ' There was no output before it was cancelled.'; } @@ -232,8 +228,7 @@ class ShellToolInvocation extends BaseToolInvocation< llmContent = [ `Command: ${this.params.command}`, `Directory: ${this.params.directory || '(root)'}`, - `Stdout: ${result.stdout || '(empty)'}`, - `Stderr: ${result.stderr || '(empty)'}`, + `Output: ${result.output || '(empty)'}`, `Error: ${finalError}`, // Use the cleaned error string. `Exit Code: ${result.exitCode ?? '(none)'}`, `Signal: ${result.signal ?? '(none)'}`, |
