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
+23 -1
View File
@@ -59,6 +59,10 @@ import {
disableLineWrapping,
shouldEnterAlternateScreen,
startupProfiler,
SessionStartSource,
SessionEndReason,
fireSessionStartHook,
fireSessionEndHook,
} from '@google/gemini-cli-core';
import { validateAuthMethod } from '../config/auth.js';
import process from 'node:process';
@@ -284,14 +288,32 @@ export const AppContainer = (props: AppContainerProps) => {
await config.initialize();
setConfigInitialized(true);
startupProfiler.flush(config);
// Fire SessionStart hook through MessageBus (only if hooks are enabled)
// Must be called AFTER config.initialize() to ensure HookRegistry is loaded
const hooksEnabled = config.getEnableHooks();
const hookMessageBus = config.getMessageBus();
if (hooksEnabled && hookMessageBus) {
const sessionStartSource = resumedSessionData
? SessionStartSource.Resume
: SessionStartSource.Startup;
await fireSessionStartHook(hookMessageBus, sessionStartSource);
}
})();
registerCleanup(async () => {
// Turn off mouse scroll.
disableMouseEvents();
const ideClient = await IdeClient.getInstance();
await ideClient.disconnect();
// Fire SessionEnd hook on cleanup (only if hooks are enabled)
const hooksEnabled = config.getEnableHooks();
const hookMessageBus = config.getMessageBus();
if (hooksEnabled && hookMessageBus) {
await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit);
}
});
}, [config]);
}, [config, resumedSessionData]);
useEffect(
() => setUpdateHandler(historyManager.addItem, setUpdateInfo),