refactor: migrate clearCommand hook calls to HookSystem (#16157)

This commit is contained in:
Vedant Mahajan
2026-01-09 22:18:55 +05:30
committed by GitHub
parent f7b97ef55e
commit b9f8858bfb
2 changed files with 10 additions and 13 deletions
@@ -46,6 +46,10 @@ describe('clearCommand', () => {
setSessionId: vi.fn(), setSessionId: vi.fn(),
getEnableHooks: vi.fn().mockReturnValue(false), getEnableHooks: vi.fn().mockReturnValue(false),
getMessageBus: vi.fn().mockReturnValue(undefined), getMessageBus: vi.fn().mockReturnValue(undefined),
getHookSystem: vi.fn().mockReturnValue({
fireSessionEndEvent: vi.fn().mockResolvedValue(undefined),
fireSessionStartEvent: vi.fn().mockResolvedValue(undefined),
}),
}, },
}, },
}); });
+6 -13
View File
@@ -4,11 +4,8 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import type { DefaultHookOutput } from '@google/gemini-cli-core';
import { import {
uiTelemetryService, uiTelemetryService,
fireSessionEndHook,
fireSessionStartHook,
SessionEndReason, SessionEndReason,
SessionStartSource, SessionStartSource,
flushTelemetry, flushTelemetry,
@@ -30,12 +27,9 @@ export const clearCommand: SlashCommand = {
?.getGeminiClient() ?.getGeminiClient()
?.getChat() ?.getChat()
.getChatRecordingService(); .getChatRecordingService();
const messageBus = config?.getMessageBus();
// Fire SessionEnd hook before clearing // Fire SessionEnd hook before clearing
if (config?.getEnableHooks() && messageBus) { await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);
await fireSessionEndHook(messageBus, SessionEndReason.Clear);
}
if (geminiClient) { if (geminiClient) {
context.ui.setDebugMessage('Clearing terminal and resetting chat.'); context.ui.setDebugMessage('Clearing terminal and resetting chat.');
@@ -54,10 +48,9 @@ export const clearCommand: SlashCommand = {
} }
// Fire SessionStart hook after clearing // Fire SessionStart hook after clearing
let result: DefaultHookOutput | undefined; const result = await config
if (config?.getEnableHooks() && messageBus) { ?.getHookSystem()
result = await fireSessionStartHook(messageBus, SessionStartSource.Clear); ?.fireSessionStartEvent(SessionStartSource.Clear);
}
// Give the event loop a chance to process any pending telemetry operations // Give the event loop a chance to process any pending telemetry operations
// This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor // This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor
@@ -72,11 +65,11 @@ export const clearCommand: SlashCommand = {
uiTelemetryService.setLastPromptTokenCount(0); uiTelemetryService.setLastPromptTokenCount(0);
context.ui.clear(); context.ui.clear();
if (result?.systemMessage) { if (result?.finalOutput?.systemMessage) {
context.ui.addItem( context.ui.addItem(
{ {
type: MessageType.INFO, type: MessageType.INFO,
text: result.systemMessage, text: result.finalOutput.systemMessage,
}, },
Date.now(), Date.now(),
); );