Skip to content

Commit 7b4fa42

Browse files
ved015sumansaurabh
authored andcommitted
refactor: migrate clearCommand hook calls to HookSystem (google-gemini#16157)
1 parent 5eb1b36 commit 7b4fa42

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/cli/src/ui/commands/clearCommand.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ describe('clearCommand', () => {
4646
setSessionId: vi.fn(),
4747
getEnableHooks: vi.fn().mockReturnValue(false),
4848
getMessageBus: vi.fn().mockReturnValue(undefined),
49+
getHookSystem: vi.fn().mockReturnValue({
50+
fireSessionEndEvent: vi.fn().mockResolvedValue(undefined),
51+
fireSessionStartEvent: vi.fn().mockResolvedValue(undefined),
52+
}),
4953
},
5054
},
5155
});

packages/cli/src/ui/commands/clearCommand.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import type { DefaultHookOutput } from '@google/gemini-cli-core';
87
import {
98
uiTelemetryService,
10-
fireSessionEndHook,
11-
fireSessionStartHook,
129
SessionEndReason,
1310
SessionStartSource,
1411
flushTelemetry,
@@ -30,12 +27,9 @@ export const clearCommand: SlashCommand = {
3027
?.getGeminiClient()
3128
?.getChat()
3229
.getChatRecordingService();
33-
const messageBus = config?.getMessageBus();
3430

3531
// Fire SessionEnd hook before clearing
36-
if (config?.getEnableHooks() && messageBus) {
37-
await fireSessionEndHook(messageBus, SessionEndReason.Clear);
38-
}
32+
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);
3933

4034
if (geminiClient) {
4135
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
@@ -54,10 +48,9 @@ export const clearCommand: SlashCommand = {
5448
}
5549

5650
// Fire SessionStart hook after clearing
57-
let result: DefaultHookOutput | undefined;
58-
if (config?.getEnableHooks() && messageBus) {
59-
result = await fireSessionStartHook(messageBus, SessionStartSource.Clear);
60-
}
51+
const result = await config
52+
?.getHookSystem()
53+
?.fireSessionStartEvent(SessionStartSource.Clear);
6154

6255
// Give the event loop a chance to process any pending telemetry operations
6356
// This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor
@@ -72,11 +65,11 @@ export const clearCommand: SlashCommand = {
7265
uiTelemetryService.setLastPromptTokenCount(0);
7366
context.ui.clear();
7467

75-
if (result?.systemMessage) {
68+
if (result?.finalOutput?.systemMessage) {
7669
context.ui.addItem(
7770
{
7871
type: MessageType.INFO,
79-
text: result.systemMessage,
72+
text: result.finalOutput.systemMessage,
8073
},
8174
Date.now(),
8275
);

0 commit comments

Comments
 (0)