mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-19 09:41:17 -07:00
feat(hooks): Hook Session Lifecycle & Compression Integration (#14151)
This commit is contained in:
@@ -4,7 +4,14 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { uiTelemetryService } from '@google/gemini-cli-core';
|
||||
import {
|
||||
uiTelemetryService,
|
||||
fireSessionEndHook,
|
||||
fireSessionStartHook,
|
||||
SessionEndReason,
|
||||
SessionStartSource,
|
||||
flushTelemetry,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { SlashCommand } from './types.js';
|
||||
import { CommandKind } from './types.js';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
@@ -21,6 +28,12 @@ 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);
|
||||
}
|
||||
|
||||
if (geminiClient) {
|
||||
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
|
||||
@@ -38,6 +51,21 @@ export const clearCommand: SlashCommand = {
|
||||
chatRecordingService.initialize();
|
||||
}
|
||||
|
||||
// Fire SessionStart hook after clearing
|
||||
if (config?.getEnableHooks() && messageBus) {
|
||||
await fireSessionStartHook(messageBus, 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
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
// Flush telemetry to ensure hooks are written to disk immediately
|
||||
// This is critical for tests and environments with I/O latency
|
||||
if (config) {
|
||||
await flushTelemetry(config);
|
||||
}
|
||||
|
||||
uiTelemetryService.setLastPromptTokenCount(0);
|
||||
context.ui.clear();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user