Skip to content

Commit f256ce8

Browse files
authored
refactor: migrate app containter hook calls to hook system (google-gemini#16161)
1 parent ccb2db9 commit f256ce8

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

packages/cli/src/ui/AppContainer.tsx

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ import {
5959
startupProfiler,
6060
SessionStartSource,
6161
SessionEndReason,
62-
fireSessionStartHook,
63-
fireSessionEndHook,
6462
generateSummary,
6563
} from '@google/gemini-cli-core';
6664
import { validateAuthMethod } from '../config/auth.js';
@@ -294,38 +292,31 @@ export const AppContainer = (props: AppContainerProps) => {
294292
setConfigInitialized(true);
295293
startupProfiler.flush(config);
296294

297-
// Fire SessionStart hook through MessageBus (only if hooks are enabled)
298-
// Must be called AFTER config.initialize() to ensure HookRegistry is loaded
299-
const hooksEnabled = config.getEnableHooks();
300-
const hookMessageBus = config.getMessageBus();
301-
if (hooksEnabled && hookMessageBus) {
302-
const sessionStartSource = resumedSessionData
303-
? SessionStartSource.Resume
304-
: SessionStartSource.Startup;
305-
const result = await fireSessionStartHook(
306-
hookMessageBus,
307-
sessionStartSource,
308-
);
295+
const sessionStartSource = resumedSessionData
296+
? SessionStartSource.Resume
297+
: SessionStartSource.Startup;
298+
const result = await config
299+
.getHookSystem()
300+
?.fireSessionStartEvent(sessionStartSource);
301+
302+
if (result?.finalOutput) {
303+
if (result.finalOutput?.systemMessage) {
304+
historyManager.addItem(
305+
{
306+
type: MessageType.INFO,
307+
text: result.finalOutput.systemMessage,
308+
},
309+
Date.now(),
310+
);
311+
}
309312

310-
if (result) {
311-
if (result.systemMessage) {
312-
historyManager.addItem(
313-
{
314-
type: MessageType.INFO,
315-
text: result.systemMessage,
316-
},
317-
Date.now(),
318-
);
319-
}
320-
321-
const additionalContext = result.getAdditionalContext();
322-
const geminiClient = config.getGeminiClient();
323-
if (additionalContext && geminiClient) {
324-
await geminiClient.addHistory({
325-
role: 'user',
326-
parts: [{ text: additionalContext }],
327-
});
328-
}
313+
const additionalContext = result.finalOutput.getAdditionalContext();
314+
const geminiClient = config.getGeminiClient();
315+
if (additionalContext && geminiClient) {
316+
await geminiClient.addHistory({
317+
role: 'user',
318+
parts: [{ text: additionalContext }],
319+
});
329320
}
330321
}
331322

@@ -341,11 +332,7 @@ export const AppContainer = (props: AppContainerProps) => {
341332
await ideClient.disconnect();
342333

343334
// Fire SessionEnd hook on cleanup (only if hooks are enabled)
344-
const hooksEnabled = config.getEnableHooks();
345-
const hookMessageBus = config.getMessageBus();
346-
if (hooksEnabled && hookMessageBus) {
347-
await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit);
348-
}
335+
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit);
349336
});
350337
// Disable the dependencies check here. historyManager gets flagged
351338
// but we don't want to react to changes to it because each new history

0 commit comments

Comments
 (0)