mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 13:34:15 -07:00
feat(hooks): Hook Session Lifecycle & Compression Integration (#14151)
This commit is contained in:
@@ -157,6 +157,8 @@ describe('ChatCompressionService', () => {
|
||||
getContentGenerator: vi.fn().mockReturnValue({
|
||||
countTokens: vi.fn().mockResolvedValue({ totalTokens: 100 }),
|
||||
}),
|
||||
getEnableHooks: vi.fn().mockReturnValue(false),
|
||||
getMessageBus: vi.fn().mockReturnValue(undefined),
|
||||
} as unknown as Config;
|
||||
|
||||
vi.mocked(tokenLimit).mockReturnValue(1000);
|
||||
|
||||
@@ -21,6 +21,8 @@ import {
|
||||
DEFAULT_GEMINI_MODEL,
|
||||
PREVIEW_GEMINI_MODEL,
|
||||
} from '../config/models.js';
|
||||
import { firePreCompressHook } from '../core/sessionHookTriggers.js';
|
||||
import { PreCompressTrigger } from '../hooks/types.js';
|
||||
|
||||
/**
|
||||
* Default threshold for compression token count as a fraction of the model's
|
||||
@@ -123,6 +125,17 @@ export class ChatCompressionService {
|
||||
};
|
||||
}
|
||||
|
||||
// Fire PreCompress hook before compression (only if hooks are enabled)
|
||||
// This fires for both manual and auto compression attempts
|
||||
const hooksEnabled = config.getEnableHooks();
|
||||
const messageBus = config.getMessageBus();
|
||||
if (hooksEnabled && messageBus) {
|
||||
const trigger = force
|
||||
? PreCompressTrigger.Manual
|
||||
: PreCompressTrigger.Auto;
|
||||
await firePreCompressHook(messageBus, trigger);
|
||||
}
|
||||
|
||||
const originalTokenCount = chat.getLastPromptTokenCount();
|
||||
|
||||
// Don't compress if not forced and we are under the limit.
|
||||
|
||||
Reference in New Issue
Block a user