Skip to content

Commit f0f8404

Browse files
committed
work within latest changes on main
1 parent 90fcbc1 commit f0f8404

File tree

2 files changed

+27
-55
lines changed

2 files changed

+27
-55
lines changed

packages/cli/src/gemini.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ vi.mock('./config/config.js', () => ({
132132
getQuestion: vi.fn(() => ''),
133133
isInteractive: () => false,
134134
getHookRegistry: vi.fn(() => null),
135+
getHookSystem: vi.fn(() => null),
135136
getDisabledHooks: vi.fn(() => []),
136137
} as unknown as Config),
137138
parseArguments: vi.fn().mockResolvedValue({}),
@@ -272,6 +273,7 @@ describe('gemini.tsx main function', () => {
272273
getExtensions: () => [],
273274
getUsageStatisticsEnabled: () => false,
274275
getHookRegistry: vi.fn(() => null),
276+
getHookSystem: vi.fn(() => null),
275277
getDisabledHooks: vi.fn(() => []),
276278
} as unknown as Config;
277279
});
@@ -506,6 +508,7 @@ describe('gemini.tsx main function kitty protocol', () => {
506508
getExtensions: () => [],
507509
getUsageStatisticsEnabled: () => false,
508510
getHookRegistry: vi.fn(() => null),
511+
getHookSystem: vi.fn(() => null),
509512
getDisabledHooks: vi.fn(() => []),
510513
} as unknown as Config);
511514
vi.mocked(loadSettings).mockReturnValue({
@@ -762,6 +765,7 @@ describe('gemini.tsx main function kitty protocol', () => {
762765
getFileFilteringRespectGitIgnore: () => true,
763766
getOutputFormat: () => 'text',
764767
getUsageStatisticsEnabled: () => false,
768+
getHookSystem: () => null,
765769
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
766770

767771
vi.spyOn(themeManager, 'setActiveTheme').mockReturnValue(false);
@@ -990,6 +994,7 @@ describe('gemini.tsx main function kitty protocol', () => {
990994
getFileFilteringRespectGitIgnore: () => true,
991995
getOutputFormat: () => 'text',
992996
getUsageStatisticsEnabled: () => false,
997+
getHookSystem: () => null,
993998
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
994999

9951000
vi.mock('./utils/readStdin.js', () => ({
@@ -1148,6 +1153,7 @@ describe('gemini.tsx main function exit codes', () => {
11481153
getOutputFormat: () => 'text',
11491154
getExtensions: () => [],
11501155
getUsageStatisticsEnabled: () => false,
1156+
getHookSystem: () => null,
11511157
} as unknown as Config);
11521158
vi.mocked(loadSettings).mockReturnValue({
11531159
merged: { security: { auth: {} }, ui: {} },
@@ -1209,6 +1215,7 @@ describe('gemini.tsx main function exit codes', () => {
12091215
getOutputFormat: () => 'text',
12101216
getExtensions: () => [],
12111217
getUsageStatisticsEnabled: () => false,
1218+
getHookSystem: () => null,
12121219
} as unknown as Config);
12131220
vi.mocked(loadSettings).mockReturnValue({
12141221
merged: { security: { auth: {} }, ui: {} },
@@ -1273,6 +1280,7 @@ describe('startInteractiveUI', () => {
12731280
getScreenReader: () => false,
12741281
getDebugMode: () => false,
12751282
getHookRegistry: vi.fn(() => null),
1283+
getHookSystem: vi.fn(() => null),
12761284
getDisabledHooks: vi.fn(() => []),
12771285
} as unknown as Config;
12781286
const mockSettings = {

packages/cli/src/gemini.tsx

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AppContainer } from './ui/AppContainer.js';
1010
import { loadCliConfig, parseArguments } from './config/config.js';
1111
import * as cliConfig from './config/config.js';
1212
import { readStdin } from './utils/readStdin.js';
13-
import { basename, join } from 'node:path';
13+
import { basename } from 'node:path';
1414
import v8 from 'node:v8';
1515
import os from 'node:os';
1616
import dns from 'node:dns';
@@ -57,12 +57,8 @@ import {
5757
disableLineWrapping,
5858
shouldEnterAlternateScreen,
5959
ExitCodes,
60-
HookEventName,
61-
type SessionStartInput,
62-
type SessionEndInput,
6360
SessionStartSource,
6461
SessionEndReason,
65-
HookRunner,
6662
} from '@google/gemini-cli-core';
6763
import {
6864
initializeApp,
@@ -577,61 +573,29 @@ export async function main() {
577573

578574
await config.initialize();
579575

580-
// Hook: SessionStart
581-
const hookRegistry = config.getHookRegistry();
582-
const hookRunner = new HookRunner();
583-
if (hookRegistry) {
584-
const hooks = hookRegistry.getHooksForEvent(HookEventName.SessionStart);
585-
if (hooks.length > 0) {
586-
try {
587-
const hookConfigs = hooks.map((h) => h.config);
588-
const input: SessionStartInput = {
589-
session_id: config.getSessionId(),
590-
transcript_path: join(
591-
config.storage.getHistoryDir(),
592-
config.getSessionId() + '.json',
593-
),
594-
cwd: config.getWorkingDir(),
595-
hook_event_name: HookEventName.SessionStart,
596-
timestamp: new Date().toISOString(),
597-
source: argv.resume
598-
? SessionStartSource.Resume
599-
: SessionStartSource.Startup,
600-
};
601-
await hookRunner.executeHooksSequential(
602-
hookConfigs,
603-
HookEventName.SessionStart,
604-
input,
605-
);
606-
} catch (error) {
607-
// Log the error but don't block startup
608-
debugLogger.error('Error executing SessionStart hooks:', error);
609-
}
576+
// Hook: SessionStart - use HookSystem if available
577+
const hookSystem = config.getHookSystem();
578+
if (hookSystem) {
579+
try {
580+
const source = argv.resume
581+
? SessionStartSource.Resume
582+
: SessionStartSource.Startup;
583+
await hookSystem.getEventHandler().fireSessionStartEvent(source);
584+
} catch (error) {
585+
// Log the error but don't block startup
586+
debugLogger.error('Error executing SessionStart hooks:', error);
610587
}
611588
}
612589

613590
// Register SessionEnd hook
614591
registerCleanup(async () => {
615-
if (hookRegistry) {
616-
const hooks = hookRegistry.getHooksForEvent(HookEventName.SessionEnd);
617-
if (hooks.length > 0) {
618-
const hookConfigs = hooks.map((h) => h.config);
619-
const input: SessionEndInput = {
620-
session_id: config.getSessionId(),
621-
transcript_path: join(
622-
config.storage.getHistoryDir(),
623-
config.getSessionId() + '.json',
624-
),
625-
cwd: config.getWorkingDir(),
626-
hook_event_name: HookEventName.SessionEnd,
627-
timestamp: new Date().toISOString(),
628-
reason: SessionEndReason.Exit, // Simplified for now
629-
};
630-
await hookRunner.executeHooksSequential(
631-
hookConfigs,
632-
HookEventName.SessionEnd,
633-
input,
634-
);
592+
if (hookSystem) {
593+
try {
594+
await hookSystem
595+
.getEventHandler()
596+
.fireSessionEndEvent(SessionEndReason.Exit);
597+
} catch (error) {
598+
debugLogger.error('Error executing SessionEnd hooks:', error);
635599
}
636600
}
637601
});

0 commit comments

Comments
 (0)