mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-24 04:52:43 -07:00
feat(hooks): Hook Session Lifecycle & Compression Integration (#14151)
This commit is contained in:
@@ -6,10 +6,16 @@
|
||||
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { Storage } from '@google/gemini-cli-core';
|
||||
import {
|
||||
Storage,
|
||||
shutdownTelemetry,
|
||||
isTelemetrySdkInitialized,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { Config } from '@google/gemini-cli-core';
|
||||
|
||||
const cleanupFunctions: Array<(() => void) | (() => Promise<void>)> = [];
|
||||
const syncCleanupFunctions: Array<() => void> = [];
|
||||
let configForTelemetry: Config | null = null;
|
||||
|
||||
export function registerCleanup(fn: (() => void) | (() => Promise<void>)) {
|
||||
cleanupFunctions.push(fn);
|
||||
@@ -30,6 +36,14 @@ export function runSyncCleanup() {
|
||||
syncCleanupFunctions.length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the config instance for telemetry shutdown.
|
||||
* This must be called early in the application lifecycle.
|
||||
*/
|
||||
export function registerTelemetryConfig(config: Config) {
|
||||
configForTelemetry = config;
|
||||
}
|
||||
|
||||
export async function runExitCleanup() {
|
||||
runSyncCleanup();
|
||||
for (const fn of cleanupFunctions) {
|
||||
@@ -40,6 +54,16 @@ export async function runExitCleanup() {
|
||||
}
|
||||
}
|
||||
cleanupFunctions.length = 0; // Clear the array
|
||||
|
||||
// IMPORTANT: Shutdown telemetry AFTER all other cleanup functions have run
|
||||
// This ensures SessionEnd hooks and other telemetry are properly flushed
|
||||
if (configForTelemetry && isTelemetrySdkInitialized()) {
|
||||
try {
|
||||
await shutdownTelemetry(configForTelemetry);
|
||||
} catch (_) {
|
||||
// Ignore errors during telemetry shutdown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function cleanupCheckpoints() {
|
||||
|
||||
Reference in New Issue
Block a user