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

@@ -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,
});

View File

@@ -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,

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,