Feature: Implement V0 Episodic Context Manager

- Re-wrote the monolithic string-based context manipulation logic into an elegant, immutable Episodic IR pipeline.
- Implemented four non-destructive degradation processors: `HistorySquashingProcessor`, `ToolMaskingProcessor`, `BlobDegradationProcessor`, and `SemanticCompressionProcessor`.
- Added dynamic configuration knobs (`budget` and `strategies`) to precisely tune the retention algorithms.
- Implemented a power-user `incrementalGc` flag for maximum context preservation beneath the ceiling.
- Enforced strict typing across the new pipeline, replacing unsafe casts with robust mapping interfaces.
- Added `powerUserProfile` to support features for those wanting a bit
  more quality at the cost of tokens.
This commit is contained in:
Your Name
2026-04-03 20:43:19 +00:00
parent 06173c0885
commit 1f567965d2
39 changed files with 2612 additions and 2315 deletions
+12 -17
View File
@@ -21,7 +21,7 @@ import {
type MCPServerConfig,
type GeminiCLIExtension,
Storage,
generalistProfile,
GENERALIST_PROFILE,
type ContextManagementConfig,
} from '@google/gemini-cli-core';
import { loadCliConfig, parseArguments, type CliArgs } from './config.js';
@@ -2211,7 +2211,7 @@ describe('loadCliConfig context management', () => {
});
const config = await loadCliConfig(settings, 'test-session', argv);
expect(config.getContextManagementConfig()).toStrictEqual(
generalistProfile,
GENERALIST_PROFILE,
);
expect(config.isContextManagementEnabled()).toBe(true);
});
@@ -2220,24 +2220,19 @@ describe('loadCliConfig context management', () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments(createTestMergedSettings());
const contextManagementConfig: Partial<ContextManagementConfig> = {
historyWindow: {
budget: {
incrementalGc: false,
maxTokens: 100_000,
retainedTokens: 50_000,
protectedEpisodes: 1,
protectSystemEpisode: true,
},
messageLimits: {
normalMaxTokens: 1000,
retainedMaxTokens: 10_000,
normalizationHeadRatio: 0.25,
},
tools: {
distillation: {
maxOutputTokens: 10_000,
summarizationThresholdTokens: 15_000,
},
outputMasking: {
protectionThresholdTokens: 30_000,
minPrunableThresholdTokens: 10_000,
protectLatestTurn: false,
strategies: {
historySquashing: { maxTokensPerNode: 12000 },
toolMasking: { stringLengthThresholdTokens: 10000 },
semanticCompression: {
nodeThresholdTokens: 5000,
compressionModel: 'chat-compression-2.5-flash-lite',
},
},
};
+7 -3
View File
@@ -46,7 +46,8 @@ import {
type HookEventName,
type OutputFormat,
detectIdeFromEnv,
generalistProfile,
GENERALIST_PROFILE,
POWER_USER_PROFILE,
} from '@google/gemini-cli-core';
import {
type Settings,
@@ -886,12 +887,15 @@ export async function loadCliConfig(
const useGeneralistProfile =
settings.experimental?.generalistProfile ?? false;
const usePowerUserProfile =
settings.experimental?.powerUserProfile ?? false;
const useContextManagement =
settings.experimental?.contextManagement ?? false;
const contextManagement = {
...(useGeneralistProfile ? generalistProfile : {}),
...(useGeneralistProfile ? GENERALIST_PROFILE : {}),
...(usePowerUserProfile ? POWER_USER_PROFILE : {}),
...(useContextManagement ? settings?.contextManagement : {}),
enabled: useContextManagement || useGeneralistProfile,
enabled: useContextManagement || useGeneralistProfile || usePowerUserProfile,
};
return new Config({
@@ -2149,6 +2149,15 @@ const SETTINGS_SCHEMA = {
'Replace the built-in save_memory tool with a memory manager subagent that supports adding, removing, de-duplicating, and organizing memories.',
showInDialog: true,
},
powerUserProfile: {
type: 'boolean',
label: 'Use the power user profile for massive contexts.',
category: 'Experimental',
requiresRestart: true,
default: false,
description: 'Enables continuous minimal GC near the max tokens limit instead of a blocked backbuffer.',
showInDialog: true,
},
generalistProfile: {
type: 'boolean',
label: 'Use the generalist profile to manage agent contexts.',