From 54744958fa55a0fbf929618ccba0c18a6bb2de05 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Tue, 9 Sep 2025 13:01:25 -0700 Subject: [PATCH] feat(core): Only summarize long tool output for shell command (#8039) --- packages/cli/src/config/config.ts | 1 + packages/cli/src/config/settingsSchema.ts | 13 +++++++++++-- packages/core/src/config/config.ts | 8 ++++++++ packages/core/src/core/coreToolScheduler.ts | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index a911518a87..8a23230add 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -624,6 +624,7 @@ export async function loadCliConfig( enablePromptCompletion: settings.general?.enablePromptCompletion ?? false, truncateToolOutputThreshold: settings.tools?.truncateToolOutputThreshold, truncateToolOutputLines: settings.tools?.truncateToolOutputLines, + enableToolOutputTruncation: settings.tools?.enableToolOutputTruncation, eventEmitter: appEvents, useSmartEdit: argv.useSmartEdit ?? settings.useSmartEdit, }); diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index 381a4c855f..dfb28e6931 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -691,11 +691,20 @@ const SETTINGS_SCHEMA = { 'Use ripgrep for file content search instead of the fallback implementation. Provides faster search performance.', showInDialog: true, }, + enableToolOutputTruncation: { + type: 'boolean', + label: 'Enable Tool Output Truncation', + category: 'General', + requiresRestart: true, + default: false, + description: 'Enable truncation of large tool outputs.', + showInDialog: true, + }, truncateToolOutputThreshold: { type: 'number', label: 'Tool Output Truncation Threshold', category: 'General', - requiresRestart: false, + requiresRestart: true, default: DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD, description: 'Truncate tool output if it is larger than this many characters. Set to -1 to disable.', @@ -705,7 +714,7 @@ const SETTINGS_SCHEMA = { type: 'number', label: 'Tool Output Truncation Lines', category: 'General', - requiresRestart: false, + requiresRestart: true, default: DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES, description: 'The number of lines to keep when truncating tool output.', showInDialog: true, diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index c4dfc3a56c..abbd6d3754 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -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; } diff --git a/packages/core/src/core/coreToolScheduler.ts b/packages/core/src/core/coreToolScheduler.ts index 5cdb3d5e9c..c4f337dae4 100644 --- a/packages/core/src/core/coreToolScheduler.ts +++ b/packages/core/src/core/coreToolScheduler.ts @@ -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,