refactor: migrate app containter hook calls to hook system (#16161)

This commit is contained in:
Ishaan Gupta
2026-01-09 22:17:54 +05:30
committed by GitHub
parent 88f1ec8d0a
commit f7b97ef55e
+24 -37
View File
@@ -59,8 +59,6 @@ import {
startupProfiler, startupProfiler,
SessionStartSource, SessionStartSource,
SessionEndReason, SessionEndReason,
fireSessionStartHook,
fireSessionEndHook,
generateSummary, generateSummary,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import { validateAuthMethod } from '../config/auth.js'; import { validateAuthMethod } from '../config/auth.js';
@@ -294,38 +292,31 @@ export const AppContainer = (props: AppContainerProps) => {
setConfigInitialized(true); setConfigInitialized(true);
startupProfiler.flush(config); startupProfiler.flush(config);
// Fire SessionStart hook through MessageBus (only if hooks are enabled) const sessionStartSource = resumedSessionData
// Must be called AFTER config.initialize() to ensure HookRegistry is loaded ? SessionStartSource.Resume
const hooksEnabled = config.getEnableHooks(); : SessionStartSource.Startup;
const hookMessageBus = config.getMessageBus(); const result = await config
if (hooksEnabled && hookMessageBus) { .getHookSystem()
const sessionStartSource = resumedSessionData ?.fireSessionStartEvent(sessionStartSource);
? SessionStartSource.Resume
: SessionStartSource.Startup;
const result = await fireSessionStartHook(
hookMessageBus,
sessionStartSource,
);
if (result) { if (result?.finalOutput) {
if (result.systemMessage) { if (result.finalOutput?.systemMessage) {
historyManager.addItem( historyManager.addItem(
{ {
type: MessageType.INFO, type: MessageType.INFO,
text: result.systemMessage, text: result.finalOutput.systemMessage,
}, },
Date.now(), Date.now(),
); );
} }
const additionalContext = result.getAdditionalContext(); const additionalContext = result.finalOutput.getAdditionalContext();
const geminiClient = config.getGeminiClient(); const geminiClient = config.getGeminiClient();
if (additionalContext && geminiClient) { if (additionalContext && geminiClient) {
await geminiClient.addHistory({ await geminiClient.addHistory({
role: 'user', role: 'user',
parts: [{ text: additionalContext }], parts: [{ text: additionalContext }],
}); });
}
} }
} }
@@ -341,11 +332,7 @@ export const AppContainer = (props: AppContainerProps) => {
await ideClient.disconnect(); await ideClient.disconnect();
// Fire SessionEnd hook on cleanup (only if hooks are enabled) // Fire SessionEnd hook on cleanup (only if hooks are enabled)
const hooksEnabled = config.getEnableHooks(); await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit);
const hookMessageBus = config.getMessageBus();
if (hooksEnabled && hookMessageBus) {
await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit);
}
}); });
// Disable the dependencies check here. historyManager gets flagged // Disable the dependencies check here. historyManager gets flagged
// but we don't want to react to changes to it because each new history // but we don't want to react to changes to it because each new history