feat(core): Only summarize long tool output for shell command (#8039)

This commit is contained in:
Sandy Tao
2025-09-09 13:01:25 -07:00
committed by GitHub
parent 94187114e9
commit 54744958fa
4 changed files with 25 additions and 3 deletions

View File

@@ -225,6 +225,7 @@ export interface ConfigParameters {
enablePromptCompletion?: boolean;
truncateToolOutputThreshold?: number;
truncateToolOutputLines?: number;
enableToolOutputTruncation?: boolean;
eventEmitter?: EventEmitter;
useSmartEdit?: boolean;
}
@@ -303,6 +304,7 @@ export class Config {
private readonly enablePromptCompletion: boolean = false;
private readonly truncateToolOutputThreshold: number;
private readonly truncateToolOutputLines: number;
private readonly enableToolOutputTruncation: boolean;
private initialized: boolean = false;
readonly storage: Storage;
private readonly fileExclusions: FileExclusions;
@@ -383,6 +385,8 @@ export class Config {
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD;
this.truncateToolOutputLines =
params.truncateToolOutputLines ?? DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES;
this.enableToolOutputTruncation =
params.enableToolOutputTruncation ?? false;
this.useSmartEdit = params.useSmartEdit ?? true;
this.extensionManagement = params.extensionManagement ?? true;
this.storage = new Storage(this.targetDir);
@@ -860,6 +864,10 @@ export class Config {
return this.enablePromptCompletion;
}
getEnableToolOutputTruncation(): boolean {
return this.enableToolOutputTruncation;
}
getTruncateToolOutputThreshold(): number {
return this.truncateToolOutputThreshold;
}

View File

@@ -24,6 +24,7 @@ import {
ReadFileTool,
ToolErrorType,
ToolCallEvent,
ShellTool,
} from '../index.js';
import type { Part, PartListUnion } from '@google/genai';
import { getResponseTextFromParts } from '../utils/generateContentResponseUtilities.js';
@@ -976,7 +977,10 @@ export class CoreToolScheduler {
let outputFile: string | undefined = undefined;
if (
typeof content === 'string' &&
this.config.getTruncateToolOutputThreshold() > 0
toolName === ShellTool.Name &&
this.config.getEnableToolOutputTruncation() &&
this.config.getTruncateToolOutputThreshold() > 0 &&
this.config.getTruncateToolOutputLines() > 0
) {
({ content, outputFile } = await truncateAndSaveToFile(
content,