refactor: simplify tool output truncation to single config (#18446)

This commit is contained in:
Sandy Tao
2026-02-06 13:41:19 -08:00
committed by GitHub
parent fd72a8c40f
commit 28805a4b2d
22 changed files with 56 additions and 189 deletions
+4 -4
View File
@@ -1104,8 +1104,8 @@ describe('Server Config (config.ts)', () => {
1000,
);
// 4 * (32000 - 1000) = 4 * 31000 = 124000
// default is 4_000_000
expect(config.getTruncateToolOutputThreshold()).toBe(124000);
// default is 40_000, so min(124000, 40000) = 40000
expect(config.getTruncateToolOutputThreshold()).toBe(40_000);
});
it('should return the default threshold when the calculated value is larger', () => {
@@ -1115,8 +1115,8 @@ describe('Server Config (config.ts)', () => {
500_000,
);
// 4 * (2_000_000 - 500_000) = 4 * 1_500_000 = 6_000_000
// default is 4_000_000
expect(config.getTruncateToolOutputThreshold()).toBe(4_000_000);
// default is 40_000
expect(config.getTruncateToolOutputThreshold()).toBe(40_000);
});
it('should use a custom truncateToolOutputThreshold if provided', () => {
+1 -17
View File
@@ -303,8 +303,7 @@ export {
DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
};
export const DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD = 4_000_000;
export const DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES = 1000;
export const DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD = 40_000;
export class MCPServerConfig {
constructor(
@@ -442,8 +441,6 @@ export interface ConfigParameters {
extensionManagement?: boolean;
enablePromptCompletion?: boolean;
truncateToolOutputThreshold?: number;
truncateToolOutputLines?: number;
enableToolOutputTruncation?: boolean;
eventEmitter?: EventEmitter;
useWriteTodos?: boolean;
policyEngineConfig?: PolicyEngineConfig;
@@ -586,9 +583,7 @@ export class Config {
private readonly extensionManagement: boolean = true;
private readonly enablePromptCompletion: boolean = false;
private readonly truncateToolOutputThreshold: number;
private readonly truncateToolOutputLines: number;
private compressionTruncationCounter = 0;
private readonly enableToolOutputTruncation: boolean;
private initialized: boolean = false;
readonly storage: Storage;
private readonly fileExclusions: FileExclusions;
@@ -778,9 +773,6 @@ export class Config {
this.truncateToolOutputThreshold =
params.truncateToolOutputThreshold ??
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD;
this.truncateToolOutputLines =
params.truncateToolOutputLines ?? DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES;
this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true;
// // TODO(joshualitt): Re-evaluate the todo tool for 3 family.
this.useWriteTodos = isPreviewModel(this.model)
? false
@@ -2063,10 +2055,6 @@ export class Config {
return this.enablePromptCompletion;
}
getEnableToolOutputTruncation(): boolean {
return this.enableToolOutputTruncation;
}
getTruncateToolOutputThreshold(): number {
return Math.min(
// Estimate remaining context window in characters (1 token ~= 4 chars).
@@ -2076,10 +2064,6 @@ export class Config {
);
}
getTruncateToolOutputLines(): number {
return this.truncateToolOutputLines;
}
getNextCompressionTruncationId(): number {
return ++this.compressionTruncationCounter;
}