Add a context percentage threshold setting for auto compression (#5721)

This commit is contained in:
Jacob MacDonald
2025-08-07 07:34:40 -07:00
committed by GitHub
parent 36750ca49b
commit 6ae75c9f32
8 changed files with 219 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import {
GEMINI_CONFIG_DIR as GEMINI_DIR,
getErrorMessage,
BugCommandSettings,
ChatCompressionSettings,
TelemetrySettings,
AuthType,
} from '@google/gemini-cli-core';
@@ -134,6 +135,8 @@ export interface Settings {
includeDirectories?: string[];
loadMemoryFromIncludeDirectories?: boolean;
chatCompression?: ChatCompressionSettings;
}
export interface SettingsError {
@@ -194,6 +197,11 @@ export class LoadedSettings {
...(user.includeDirectories || []),
...(workspace.includeDirectories || []),
],
chatCompression: {
...(system.chatCompression || {}),
...(user.chatCompression || {}),
...(workspace.chatCompression || {}),
},
};
}
@@ -482,6 +490,19 @@ export function loadSettings(workspaceDir: string): LoadedSettings {
settingsErrors,
);
// Validate chatCompression settings
const chatCompression = loadedSettings.merged.chatCompression;
const threshold = chatCompression?.contextPercentageThreshold;
if (
threshold != null &&
(typeof threshold !== 'number' || threshold < 0 || threshold > 1)
) {
console.warn(
`Invalid value for chatCompression.contextPercentageThreshold: "${threshold}". Please use a value between 0 and 1. Using default compression settings.`,
);
delete loadedSettings.merged.chatCompression;
}
// Load environment with merged settings
loadEnvironment(loadedSettings.merged);