mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-03 08:24:10 -07:00
refactor: migrate app containter hook calls to hook system (#16161)
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user