This commit is contained in:
A.K.M. Adib
2026-01-24 10:40:17 -05:00
parent 84e882770b
commit f45b5e0f02
6 changed files with 75 additions and 1 deletions

View File

@@ -21,7 +21,12 @@ import type {
ChatRecordingService,
GeminiClient,
} from '@google/gemini-cli-core';
import { coreEvents, debugLogger } from '@google/gemini-cli-core';
import {
coreEvents,
debugLogger,
logRewind,
RewindEvent,
} from '@google/gemini-cli-core';
/**
* Helper function to handle the core logic of rewinding a conversation.
@@ -144,6 +149,9 @@ export const rewindCommand: SlashCommand = {
context.ui.removeComponent();
}}
onRewind={async (messageId, newText, outcome) => {
if (outcome !== RewindOutcome.Cancel) {
logRewind(config, new RewindEvent(outcome));
}
switch (outcome) {
case RewindOutcome.Cancel:
context.ui.removeComponent();

View File

@@ -18,6 +18,7 @@ import type {
LoopDetectedEvent,
NextSpeakerCheckEvent,
SlashCommandEvent,
RewindEvent,
MalformedJsonResponseEvent,
IdeConnectionEvent,
ConversationFinishedEvent,
@@ -78,6 +79,7 @@ export enum EventNames {
LOOP_DETECTION_DISABLED = 'loop_detection_disabled',
NEXT_SPEAKER_CHECK = 'next_speaker_check',
SLASH_COMMAND = 'slash_command',
REWIND = 'rewind',
MALFORMED_JSON_RESPONSE = 'malformed_json_response',
IDE_CONNECTION = 'ide_connection',
KITTY_SEQUENCE_OVERFLOW = 'kitty_sequence_overflow',
@@ -945,6 +947,18 @@ export class ClearcutLogger {
this.flushIfNeeded();
}
logRewindEvent(event: RewindEvent): void {
const data: EventValue[] = [
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_REWIND_OUTCOME,
value: event.outcome,
},
];
this.enqueueLogEvent(this.createLogEvent(EventNames.REWIND, data));
this.flushIfNeeded();
}
logMalformedJsonResponseEvent(event: MalformedJsonResponseEvent): void {
const data: EventValue[] = [
{

View File

@@ -542,4 +542,7 @@ export enum EventMetadataKey {
// Logs the duration spent in an approval mode in milliseconds.
GEMINI_CLI_APPROVAL_MODE_DURATION_MS = 143,
// Logs the outcome of a rewind operation.
GEMINI_CLI_REWIND_OUTCOME = 144,
}

View File

@@ -46,6 +46,7 @@ export {
logExtensionUninstall,
logExtensionUpdateEvent,
logWebFetchFallbackAttempt,
logRewind,
} from './loggers.js';
export type { SlashCommandEvent, ChatCompressionEvent } from './types.js';
export {
@@ -62,6 +63,7 @@ export {
ToolOutputTruncatedEvent,
WebFetchFallbackAttemptEvent,
ToolCallDecision,
RewindEvent,
} from './types.js';
export { makeSlashCommandEvent, makeChatCompressionEvent } from './types.js';
export type { TelemetryEvent } from './types.js';

View File

@@ -12,6 +12,7 @@ import {
EVENT_API_ERROR,
EVENT_API_RESPONSE,
EVENT_TOOL_CALL,
EVENT_REWIND,
} from './types.js';
import type {
ApiErrorEvent,
@@ -27,6 +28,7 @@ import type {
LoopDetectedEvent,
LoopDetectionDisabledEvent,
SlashCommandEvent,
RewindEvent,
ConversationFinishedEvent,
ChatCompressionEvent,
MalformedJsonResponseEvent,
@@ -351,6 +353,24 @@ export function logSlashCommand(
});
}
export function logRewind(config: Config, event: RewindEvent): void {
const uiEvent = {
...event,
'event.name': EVENT_REWIND,
'event.timestamp': new Date().toISOString(),
} as UiEvent;
uiTelemetryService.addEvent(uiEvent);
ClearcutLogger.getInstance(config)?.logRewindEvent(event);
bufferTelemetryEvent(() => {
const logger = logs.getLogger(SERVICE_NAME);
const logRecord: LogRecord = {
body: event.toLogBody(),
attributes: event.toOpenTelemetryAttributes(config),
};
logger.emit(logRecord);
});
}
export function logIdeConnection(
config: Config,
event: IdeConnectionEvent,

View File

@@ -889,6 +889,32 @@ export enum SlashCommandStatus {
ERROR = 'error',
}
export const EVENT_REWIND = 'gemini_cli.rewind';
export class RewindEvent implements BaseTelemetryEvent {
'event.name': 'rewind';
'event.timestamp': string;
outcome: string;
constructor(outcome: string) {
this['event.name'] = 'rewind';
this['event.timestamp'] = new Date().toISOString();
this.outcome = outcome;
}
toOpenTelemetryAttributes(config: Config): LogAttributes {
return {
...getCommonAttributes(config),
'event.name': EVENT_REWIND,
'event.timestamp': this['event.timestamp'],
outcome: this.outcome,
};
}
toLogBody(): string {
return `Rewind performed. Outcome: ${this.outcome}.`;
}
}
export const EVENT_CHAT_COMPRESSION = 'gemini_cli.chat_compression';
export interface ChatCompressionEvent extends BaseTelemetryEvent {
'event.name': 'chat_compression';
@@ -1577,6 +1603,7 @@ export type TelemetryEvent =
| StartupStatsEvent
| WebFetchFallbackAttemptEvent
| EditStrategyEvent
| RewindEvent
| EditCorrectionEvent;
export const EVENT_EXTENSION_DISABLE = 'gemini_cli.extension_disable';