feat(plan): telemetry to track adoption and usage of plan mode (#16863)

This commit is contained in:
Adib234
2026-01-20 13:57:34 -05:00
committed by GitHub
parent 12b0fe1cc2
commit e5745f16cb
6 changed files with 181 additions and 2 deletions
+31
View File
@@ -64,6 +64,8 @@ import { logRipgrepFallback, logFlashFallback } from '../telemetry/loggers.js';
import {
RipgrepFallbackEvent,
FlashFallbackEvent,
ApprovalModeSwitchEvent,
ApprovalModeDurationEvent,
} from '../telemetry/types.js';
import type { FallbackModelHandler } from '../fallback/types.js';
import { ModelAvailabilityService } from '../availability/modelAvailabilityService.js';
@@ -105,6 +107,10 @@ import { debugLogger } from '../utils/debugLogger.js';
import { SkillManager, type SkillDefinition } from '../skills/skillManager.js';
import { startupProfiler } from '../telemetry/startupProfiler.js';
import type { AgentDefinition } from '../agents/types.js';
import {
logApprovalModeSwitch,
logApprovalModeDuration,
} from '../telemetry/loggers.js';
import { fetchAdminControls } from '../code_assist/admin/admin_controls.js';
export interface AccessibilitySettings {
@@ -544,6 +550,7 @@ export class Config {
private terminalBackground: string | undefined = undefined;
private remoteAdminSettings: FetchAdminControlsResponse | undefined;
private latestApiRequest: GenerateContentParameters | undefined;
private lastModeSwitchTime: number = Date.now();
constructor(params: ConfigParameters) {
this.sessionId = params.sessionId;
@@ -1348,9 +1355,32 @@ export class Config {
'Cannot enable privileged approval modes in an untrusted folder.',
);
}
const currentMode = this.getApprovalMode();
if (currentMode !== mode) {
this.logCurrentModeDuration(this.getApprovalMode());
logApprovalModeSwitch(
this,
new ApprovalModeSwitchEvent(currentMode, mode),
);
this.lastModeSwitchTime = Date.now();
}
this.policyEngine.setApprovalMode(mode);
}
/**
* Logs the duration of the current approval mode.
*/
logCurrentModeDuration(mode: ApprovalMode): void {
const now = Date.now();
const duration = now - this.lastModeSwitchTime;
logApprovalModeDuration(
this,
new ApprovalModeDurationEvent(mode, duration),
);
}
isYoloModeDisabled(): boolean {
return this.disableYoloMode || !this.isTrustedFolder();
}
@@ -2054,6 +2084,7 @@ export class Config {
* Disposes of resources and removes event listeners.
*/
async dispose(): Promise<void> {
this.logCurrentModeDuration(this.getApprovalMode());
coreEvents.off(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed);
this.agentRegistry?.dispose();
this.geminiClient?.dispose();