truncate (hide) tool output at the top, add some spacing, also fix shell output interval change accidentally undone in a previous commit (#619)
This commit is contained in:
parent
a3b557222a
commit
7c4a5464f6
|
@ -47,7 +47,7 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
|
||||||
const displayableResult = React.useMemo(
|
const displayableResult = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
resultIsString
|
resultIsString
|
||||||
? lines.slice(0, contentHeightEstimate).join('\n')
|
? lines.slice(-contentHeightEstimate).join('\n')
|
||||||
: resultDisplay,
|
: resultDisplay,
|
||||||
[lines, resultIsString, contentHeightEstimate, resultDisplay],
|
[lines, resultIsString, contentHeightEstimate, resultDisplay],
|
||||||
);
|
);
|
||||||
|
@ -66,8 +66,16 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
|
||||||
{emphasis === 'high' && <TrailingIndicator />}
|
{emphasis === 'high' && <TrailingIndicator />}
|
||||||
</Box>
|
</Box>
|
||||||
{displayableResult && (
|
{displayableResult && (
|
||||||
<Box paddingLeft={STATUS_INDICATOR_WIDTH} width="100%">
|
<Box paddingLeft={STATUS_INDICATOR_WIDTH} width="100%" marginTop={1}>
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
|
{hiddenLines > 0 && (
|
||||||
|
<Box>
|
||||||
|
<Text color={Colors.SubtleComment}>
|
||||||
|
... first {hiddenLines} line{hiddenLines === 1 ? '' : 's'}{' '}
|
||||||
|
hidden ...
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
{typeof displayableResult === 'string' && (
|
{typeof displayableResult === 'string' && (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
<MarkdownDisplay
|
<MarkdownDisplay
|
||||||
|
@ -83,14 +91,6 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
|
||||||
filename={displayableResult.fileName}
|
filename={displayableResult.fileName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{hiddenLines > 0 && (
|
|
||||||
<Box>
|
|
||||||
<Text color={Colors.SubtleComment}>
|
|
||||||
... {hiddenLines} more line{hiddenLines === 1 ? '' : 's'}{' '}
|
|
||||||
hidden ...
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -25,6 +25,8 @@ export interface ShellToolParams {
|
||||||
}
|
}
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
|
|
||||||
|
const OUTPUT_UPDATE_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
static Name: string = 'execute_bash_command';
|
static Name: string = 'execute_bash_command';
|
||||||
private whitelist: Set<string> = new Set();
|
private whitelist: Set<string> = new Set();
|
||||||
|
@ -124,7 +126,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
async execute(
|
async execute(
|
||||||
params: ShellToolParams,
|
params: ShellToolParams,
|
||||||
abortSignal: AbortSignal,
|
abortSignal: AbortSignal,
|
||||||
onOutputChunk?: (chunk: string) => void,
|
updateOutput?: (chunk: string) => void,
|
||||||
): Promise<ToolResult> {
|
): Promise<ToolResult> {
|
||||||
const validationError = this.validateToolParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
|
@ -155,6 +157,19 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
let exited = false;
|
let exited = false;
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let output = '';
|
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) => {
|
shell.stdout.on('data', (data: Buffer) => {
|
||||||
// continue to consume post-exit for background processes
|
// continue to consume post-exit for background processes
|
||||||
// removing listeners can overflow OS buffer and block subprocesses
|
// removing listeners can overflow OS buffer and block subprocesses
|
||||||
|
@ -162,10 +177,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
if (!exited) {
|
if (!exited) {
|
||||||
const str = data.toString();
|
const str = data.toString();
|
||||||
stdout += str;
|
stdout += str;
|
||||||
output += str;
|
appendOutput(str);
|
||||||
if (onOutputChunk) {
|
|
||||||
onOutputChunk(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,10 +186,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
if (!exited) {
|
if (!exited) {
|
||||||
const str = data.toString();
|
const str = data.toString();
|
||||||
stderr += str;
|
stderr += str;
|
||||||
output += str;
|
appendOutput(str);
|
||||||
if (onOutputChunk) {
|
|
||||||
onOutputChunk(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue