Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 25 additions & 38 deletions packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ import {
startupProfiler,
SessionStartSource,
SessionEndReason,
fireSessionStartHook,
fireSessionEndHook,
generateSummary,
} from '@google/gemini-cli-core';
import { validateAuthMethod } from '../config/auth.js';
Expand Down Expand Up @@ -294,38 +292,31 @@ export const AppContainer = (props: AppContainerProps) => {
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;
const result = await fireSessionStartHook(
hookMessageBus,
sessionStartSource,
);
const sessionStartSource = resumedSessionData
? SessionStartSource.Resume
: SessionStartSource.Startup;
const result = await config
.getHookSystem()
?.fireSessionStartEvent(sessionStartSource);

if (result?.finalOutput) {
if (result.finalOutput?.systemMessage) {
historyManager.addItem(
{
type: MessageType.INFO,
text: result.finalOutput.systemMessage,
},
Date.now(),
);
}

if (result) {
if (result.systemMessage) {
historyManager.addItem(
{
type: MessageType.INFO,
text: result.systemMessage,
},
Date.now(),
);
}

const additionalContext = result.getAdditionalContext();
const geminiClient = config.getGeminiClient();
if (additionalContext && geminiClient) {
await geminiClient.addHistory({
role: 'user',
parts: [{ text: additionalContext }],
});
}
const additionalContext = result.finalOutput.getAdditionalContext();
const geminiClient = config.getGeminiClient();
if (additionalContext && geminiClient) {
await geminiClient.addHistory({
role: 'user',
parts: [{ text: additionalContext }],
});
}
}

Expand All @@ -341,11 +332,7 @@ export const AppContainer = (props: AppContainerProps) => {
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);
}
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit);
});
// Disable the dependencies check here. historyManager gets flagged
// but we don't want to react to changes to it because each new history
Expand Down
Loading