Skip to content

Commit cd640df

Browse files
committed
Merge Commit 'b9f8858bf': refactor: migrate clearCommand hook calls to HookSystem (google-gemini#16157)
2 parents a67adaf + b9f8858 commit cd640df

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,13 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import type { DefaultHookOutput } from '@google/gemini-cli-core';
87
import {
98
uiTelemetryService,
109
clearContextBackups,
1110
clearCollaborativeWriting,
12-
fireSessionEndHook,
13-
fireSessionStartHook,
1411
SessionEndReason,
1512
SessionStartSource,
1613
flushTelemetry,
@@ -32,12 +29,9 @@ export const clearCommand: SlashCommand = {
3229
?.getGeminiClient()
3330
?.getChat()
3431
.getChatRecordingService();
35-
const messageBus = config?.getMessageBus();
3632

3733
// Fire SessionEnd hook before clearing
38-
if (config?.getEnableHooks() && messageBus) {
39-
await fireSessionEndHook(messageBus, SessionEndReason.Clear);
40-
}
34+
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);
4135

4236
if (geminiClient) {
4337
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
@@ -66,10 +60,9 @@ export const clearCommand: SlashCommand = {
6660
// AUDITARIA_FEATURE_END
6761

6862
// Fire SessionStart hook after clearing
69-
let result: DefaultHookOutput | undefined;
70-
if (config?.getEnableHooks() && messageBus) {
71-
result = await fireSessionStartHook(messageBus, SessionStartSource.Clear);
72-
}
63+
const result = await config
64+
?.getHookSystem()
65+
?.fireSessionStartEvent(SessionStartSource.Clear);
7366

7467
// Give the event loop a chance to process any pending telemetry operations
7568
// This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor
@@ -84,11 +77,11 @@ export const clearCommand: SlashCommand = {
8477
uiTelemetryService.setLastPromptTokenCount(0);
8578
context.ui.clear();
8679

87-
if (result?.systemMessage) {
80+
if (result?.finalOutput?.systemMessage) {
8881
context.ui.addItem(
8982
{
9083
type: MessageType.INFO,
91-
text: result.systemMessage,
84+
text: result.finalOutput.systemMessage,
9285
},
9386
Date.now(),
9487
);

0 commit comments

Comments
 (0)