Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions packages/cli/src/ui/commands/clearCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('clearCommand', () => {
setSessionId: vi.fn(),
getEnableHooks: vi.fn().mockReturnValue(false),
getMessageBus: vi.fn().mockReturnValue(undefined),
getHookSystem: vi.fn().mockReturnValue({
fireSessionEndEvent: vi.fn().mockResolvedValue(undefined),
fireSessionStartEvent: vi.fn().mockResolvedValue(undefined),
}),
},
},
});
Expand Down
19 changes: 6 additions & 13 deletions packages/cli/src/ui/commands/clearCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type { DefaultHookOutput } from '@google/gemini-cli-core';
import {
uiTelemetryService,
fireSessionEndHook,
fireSessionStartHook,
SessionEndReason,
SessionStartSource,
flushTelemetry,
Expand All @@ -30,12 +27,9 @@ export const clearCommand: SlashCommand = {
?.getGeminiClient()
?.getChat()
.getChatRecordingService();
const messageBus = config?.getMessageBus();

// Fire SessionEnd hook before clearing
if (config?.getEnableHooks() && messageBus) {
await fireSessionEndHook(messageBus, SessionEndReason.Clear);
}
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);

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

// Fire SessionStart hook after clearing
let result: DefaultHookOutput | undefined;
if (config?.getEnableHooks() && messageBus) {
result = await fireSessionStartHook(messageBus, SessionStartSource.Clear);
}
const result = await config
?.getHookSystem()
?.fireSessionStartEvent(SessionStartSource.Clear);

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

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