diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index 922f59d0..51d3dffb 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -47,7 +47,7 @@ export const ToolMessage: React.FC = ({ const displayableResult = React.useMemo( () => resultIsString - ? lines.slice(0, contentHeightEstimate).join('\n') + ? lines.slice(-contentHeightEstimate).join('\n') : resultDisplay, [lines, resultIsString, contentHeightEstimate, resultDisplay], ); @@ -66,8 +66,16 @@ export const ToolMessage: React.FC = ({ {emphasis === 'high' && } {displayableResult && ( - + + {hiddenLines > 0 && ( + + + ... first {hiddenLines} line{hiddenLines === 1 ? '' : 's'}{' '} + hidden ... + + + )} {typeof displayableResult === 'string' && ( = ({ filename={displayableResult.fileName} /> )} - {hiddenLines > 0 && ( - - - ... {hiddenLines} more line{hiddenLines === 1 ? '' : 's'}{' '} - hidden ... - - - )} )} diff --git a/packages/server/src/tools/shell.ts b/packages/server/src/tools/shell.ts index b43b2d0a..388c1543 100644 --- a/packages/server/src/tools/shell.ts +++ b/packages/server/src/tools/shell.ts @@ -25,6 +25,8 @@ export interface ShellToolParams { } import { spawn } from 'child_process'; +const OUTPUT_UPDATE_INTERVAL_MS = 1000; + export class ShellTool extends BaseTool { static Name: string = 'execute_bash_command'; private whitelist: Set = new Set(); @@ -124,7 +126,7 @@ export class ShellTool extends BaseTool { async execute( params: ShellToolParams, abortSignal: AbortSignal, - onOutputChunk?: (chunk: string) => void, + updateOutput?: (chunk: string) => void, ): Promise { const validationError = this.validateToolParams(params); if (validationError) { @@ -155,6 +157,19 @@ export class ShellTool extends BaseTool { let exited = false; let stdout = ''; let output = ''; + let lastUpdateTime = Date.now(); + + const appendOutput = (str: string) => { + output += str; + if ( + updateOutput && + Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS + ) { + updateOutput(output); + lastUpdateTime = Date.now(); + } + }; + shell.stdout.on('data', (data: Buffer) => { // continue to consume post-exit for background processes // removing listeners can overflow OS buffer and block subprocesses @@ -162,10 +177,7 @@ export class ShellTool extends BaseTool { if (!exited) { const str = data.toString(); stdout += str; - output += str; - if (onOutputChunk) { - onOutputChunk(str); - } + appendOutput(str); } }); @@ -174,10 +186,7 @@ export class ShellTool extends BaseTool { if (!exited) { const str = data.toString(); stderr += str; - output += str; - if (onOutputChunk) { - onOutputChunk(str); - } + appendOutput(str); } });