feat(hooks): Hook Session Lifecycle & Compression Integration (#14151)

This commit is contained in:
Edilmo Palencia
2025-12-03 09:04:13 -08:00
committed by GitHub
parent 7a6d3067c6
commit 1c12da1fad
27 changed files with 1026 additions and 302 deletions
@@ -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.