improve performance of shell commands with lots of output (#7680)

This commit is contained in:
Jacob MacDonald
2025-09-04 09:20:24 -07:00
committed by GitHub
parent c31e37b30e
commit 45d494a8d8
4 changed files with 12 additions and 9 deletions

View File

@@ -313,7 +313,7 @@ describe('ShellTool', () => {
// Send a second chunk. THIS event triggers the update with the CUMULATIVE content.
mockShellOutputCallback({
type: 'data',
chunk: 'hello world',
chunk: 'world',
});
// It should have been called once now with the combined output.

View File

@@ -132,6 +132,7 @@ class ShellToolInvocation extends BaseToolInvocation<
);
let cumulativeOutput = '';
let outputChunks: string[] = [cumulativeOutput];
let lastUpdateTime = Date.now();
let isBinaryStream = false;
@@ -149,9 +150,11 @@ class ShellToolInvocation extends BaseToolInvocation<
switch (event.type) {
case 'data':
if (isBinaryStream) break;
cumulativeOutput = event.chunk;
currentDisplayOutput = cumulativeOutput;
outputChunks.push(event.chunk);
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
cumulativeOutput = outputChunks.join('');
outputChunks = [cumulativeOutput];
currentDisplayOutput = cumulativeOutput;
shouldUpdate = true;
}
break;