import { type CaptureAgentUnexpectedReasoningTokensInput, captureAgentUnexpectedReasoningTokens, type ITelemetryService, type TelemetryProperties } from "@cline/shared"; import type { CoreCompactionBudgetPolicyIntent, CoreCompactionLiveTailHandling } from "../../types/config"; export type TelemetryAgentKind = "root" | "subagent" | "team_lead" | "team_teammate"; export interface TelemetryAgentIdentityProperties { agentId: string; agentKind: TelemetryAgentKind; conversationId?: string; parentAgentId?: string; createdByAgentId?: string; isSubagent: boolean; teamId?: string; teamName?: string; teamRole?: "lead" | "teammate"; teamAgentId?: string; } export declare const CORE_TELEMETRY_EVENTS: { readonly CLIENT: { readonly EXTENSION_ACTIVATED: "user.extension_activated"; }; readonly SESSION: { readonly STARTED: "session.started"; readonly ENDED: "session.ended"; }; readonly AGENT: { readonly UNEXPECTED_REASONING_TOKENS: "agent.reasoning.unexpected_tokens"; }; readonly USER: { readonly AUTH_STARTED: "user.auth_started"; readonly AUTH_SUCCEEDED: "user.auth_succeeded"; readonly AUTH_FAILED: "user.auth_failed"; readonly AUTH_LOGGED_OUT: "user.auth_logged_out"; readonly AUTH_REFRESH_SOFT_FAILURE: "user.auth_refresh_soft_failure"; readonly AUTH_RUN_RETRY: "user.auth_run_retry"; readonly PROVIDER_CONFIGURED: "user.provider_configured"; readonly TELEMETRY_OPT_OUT: "user.opt_out"; }; readonly TASK: { readonly CREATED: "task.created"; readonly RESTARTED: "task.restarted"; readonly COMPLETED: "task.completed"; readonly CONVERSATION_TURN: "task.conversation_turn"; readonly TOKEN_USAGE: "task.tokens"; readonly MODE_SWITCH: "task.mode"; readonly TOOL_USED: "task.tool_used"; readonly SKILL_USED: "task.skill_used"; readonly DIFF_EDIT_FAILED: "task.diff_edit_failed"; readonly PROVIDER_API_ERROR: "task.provider_api_error"; readonly MISTAKE_LIMIT_REACHED: "task.mistake_limit_reached"; readonly MENTION_USED: "task.mention_used"; readonly MENTION_FAILED: "task.mention_failed"; readonly MENTION_SEARCH_RESULTS: "task.mention_search_results"; readonly AGENT_CREATED: "task.agent_created"; readonly AGENT_TEAM_CREATED: "task.agent_team_created"; readonly SUBAGENT_STARTED: "task.subagent_started"; readonly SUBAGENT_COMPLETED: "task.subagent_completed"; readonly COMPACTION_EXECUTED: "task.compaction_executed"; readonly COMPACTION_SKIPPED: "task.compaction_skipped"; readonly COMPACTION_BUDGET_EMERGENCY: "task.compaction_budget_emergency"; }; readonly HOOKS: { readonly DISCOVERY_COMPLETED: "hooks.discovery_completed"; }; readonly WORKSPACE: { readonly INITIALIZED: "workspace.initialized"; readonly INIT_ERROR: "workspace.init_error"; readonly PATH_RESOLVED: "workspace.path_resolved"; }; readonly SDK: { readonly ERROR: "sdk.error"; readonly TOOL_TIMEOUT: "sdk.tool_timeout"; }; readonly FEATURE_FLAGS: { readonly FLAG_CALLED: "$feature_flag_called"; }; }; export interface RunCommandsTimeoutTelemetryProperties { tool_name: "run_commands"; effective_timeout_ms: number; timeout_source: "default_setting" | "configured_setting"; command_count: number; duration_ms: number; ulid?: string; mode?: string; source?: string; session_id?: string; agent_id?: string; conversation_id?: string; run_id?: string; iteration?: number; tool_call_id?: string; } export { captureAgentUnexpectedReasoningTokens, type CaptureAgentUnexpectedReasoningTokensInput, }; export interface WorkspaceInitializedProperties { root_count: number; vcs_types: ReadonlyArray; init_duration_ms?: number; feature_flag_enabled?: boolean; is_remote_workspace?: boolean; } export interface WorkspaceInitErrorProperties { fallback_to_single_root: boolean; workspace_count?: number; } export interface WorkspacePathResolvedProperties { ulid: string; context: string; resolution_type: "hint_provided" | "fallback_to_primary" | "cross_workspace_search"; hint_type?: "workspace_name" | "workspace_path" | "invalid"; resolution_success?: boolean; target_workspace_index?: number; is_multi_root_enabled?: boolean; } export declare function captureExtensionActivated(telemetry: ITelemetryService | undefined): void; export declare function captureWorkspaceInitialized(telemetry: ITelemetryService | undefined, properties: WorkspaceInitializedProperties): void; export declare function captureWorkspaceInitError(telemetry: ITelemetryService | undefined, error: Error | string, properties: WorkspaceInitErrorProperties): void; export declare function captureWorkspacePathResolved(telemetry: ITelemetryService | undefined, properties: WorkspacePathResolvedProperties): void; export declare function captureAuthStarted(telemetry: ITelemetryService | undefined, provider?: string): void; export declare function captureAuthSucceeded(telemetry: ITelemetryService | undefined, provider?: string): void; export declare function captureAuthFailed(telemetry: ITelemetryService | undefined, provider?: string, errorMessage?: string): void; export declare function captureAuthLoggedOut(telemetry: ITelemetryService | undefined, provider?: string, reason?: string, details?: { status?: number; errorCode?: string; }): void; /** * Fires when a token refresh fails for a reason that does NOT invalidate the * session (network error, timeout, 5xx) and stored credentials were kept. * Before the transient-vs-invalid_grant fix, `tokenExpired: true` instances * were misclassified as invalid grants and wiped stored credentials — this * event is the "prevented logout" counter for tracking that fix in * production. */ export declare function captureAuthRefreshSoftFailure(telemetry: ITelemetryService | undefined, provider?: string, details?: { status?: number; errorCode?: string; errorName?: string; tokenExpired?: boolean; }): void; /** * Fires when a run failed with an auth-like error, credentials were * refreshed, and the run was retried once. `recovered: true` means the retry * completed — a run that would previously have surfaced a raw provider 401 * (e.g. a teammate stranded on a spawn-time token snapshot past its TTL). */ export declare function captureAuthRunRetry(telemetry: ITelemetryService | undefined, provider?: string, details?: { recovered?: boolean; }): void; /** * Fires when the user finishes configuring a "bring your own provider" * (API-key based) provider during onboarding or via settings. * * Unlike the OAuth/device-code `captureAuth*` events, the configure step is a * synchronous local credential save with no network roundtrip, so there is no * start/fail counterpart — the credential is validated lazily on the first * subsequent API call. Mirrors the `{ provider }` payload shape of * {@link captureAuthSucceeded} for funnel consistency. */ export declare function captureProviderConfigured(telemetry: ITelemetryService | undefined, provider?: string): void; export declare function captureTelemetryOptOut(telemetry: ITelemetryService | undefined, properties?: TelemetryProperties): void; export declare function identifyAccount(telemetry: ITelemetryService | undefined, account: { id?: string; email?: string; provider?: string; organizationId?: string; organizationName?: string; memberId?: string; }): void; export declare function captureTaskCreated(telemetry: ITelemetryService | undefined, properties: { ulid: string; apiProvider?: string; openAiCompatibleDomain?: string; } & Partial): void; export declare function captureTaskRestarted(telemetry: ITelemetryService | undefined, properties: { ulid: string; apiProvider?: string; openAiCompatibleDomain?: string; } & Partial): void; /** * Distinguishes the trigger that produced a `task.completed` telemetry event. * * - `submit_and_exit`: the assistant explicitly declared completion by * invoking the canonical completion tool. Parity with original Cline's * `attempt_completion`-anchored emission. * - `shutdown`: the session lifecycle completed (typically a non-interactive * single-run that finished without an explicit completion tool). Acts as a * safety-net so we still report completed runs that never observed * `submit_and_exit`. */ export type TaskCompletedSource = "submit_and_exit" | "shutdown"; export declare function captureTaskCompleted(telemetry: ITelemetryService | undefined, properties: { ulid: string; provider?: string; modelId?: string; mode?: string; durationMs?: number; source?: TaskCompletedSource; } & Partial): void; export declare function captureConversationTurnEvent(telemetry: ITelemetryService | undefined, properties: { ulid: string; provider?: string; model?: string; source: "user" | "assistant"; mode?: string; } & Partial): void; export declare function captureTokenUsage(telemetry: ITelemetryService | undefined, properties: { ulid: string; tokensIn: number; tokensOut: number; cacheWriteTokens?: number; cacheReadTokens?: number; totalCost?: number; model: string; } & Partial): void; export declare function captureModeSwitch(telemetry: ITelemetryService | undefined, ulid: string, mode?: string): void; export declare function captureToolUsage(telemetry: ITelemetryService | undefined, properties: { ulid: string; tool: string; modelId?: string; provider?: string; autoApproved?: boolean; success: boolean; } & Partial): void; export declare function captureSkillUsed(telemetry: ITelemetryService | undefined, properties: { ulid: string; skillName: string; skillSource: "global" | "project"; skillsAvailableGlobal: number; skillsAvailableProject: number; provider?: string; modelId?: string; } & Partial): void; export declare function captureDiffEditFailure(telemetry: ITelemetryService | undefined, properties: { ulid: string; modelId?: string; provider?: string; errorType?: string; } & Partial): void; export declare function captureProviderApiError(telemetry: ITelemetryService | undefined, properties: { ulid: string; model: string; errorMessage: string; provider?: string; errorStatus?: number; requestId?: string; } & Partial): void; /** * Records when the consecutive mistake limit is reached, right before the * limit decision (host prompt / auto-stop) is resolved. */ export declare function captureMistakeLimitReached(telemetry: ITelemetryService | undefined, properties: { ulid: string; model: string; provider?: string; /** What kind of mistake tripped the limit. */ reason: string; consecutiveMistakes: number; maxConsecutiveMistakes: number; } & Partial): void; export declare function captureRunCommandsTimeout(telemetry: ITelemetryService | undefined, properties: RunCommandsTimeoutTelemetryProperties): void; export declare function captureMentionUsed(telemetry: ITelemetryService | undefined, mentionType: "file" | "folder" | "url" | "problems" | "terminal" | "git-changes" | "commit", contentLength?: number): void; export declare function captureMentionFailed(telemetry: ITelemetryService | undefined, mentionType: "file" | "folder" | "url" | "problems" | "terminal" | "git-changes" | "commit", errorType: "not_found" | "permission_denied" | "network_error" | "parse_error" | "unknown", errorMessage?: string): void; export declare function captureMentionSearchResults(telemetry: ITelemetryService | undefined, query: string, resultCount: number, searchType: "file" | "folder" | "all", isEmpty: boolean): void; export declare function captureAgentCreated(telemetry: ITelemetryService | undefined, properties: { ulid: string; modelId?: string; provider?: string; } & TelemetryAgentIdentityProperties): void; export declare function captureAgentTeamCreated(telemetry: ITelemetryService | undefined, properties: { ulid: string; teamId: string; teamName: string; leadAgentId?: string; restoredFromPersistence?: boolean; }): void; export declare function captureSubagentExecution(telemetry: ITelemetryService | undefined, properties: { ulid: string; durationMs: number; outputLines?: number; event: "created" | "started" | "ended"; agentId: string; parentId?: string; errorMessage?: string; type?: "agent" | "team"; } & Partial): void; export declare function captureHookDiscovery(telemetry: ITelemetryService | undefined, hookName: string, globalCount: number, workspaceCount: number): void; /** * Identifies which compaction implementation produced a * `task.compaction_executed` / `task.compaction_skipped` event. * * - `basic` — built-in token-budget truncation * (see `extensions/context/basic-compaction.ts`). * - `agentic` — built-in LLM-powered summarization * (see `extensions/context/agentic-compaction.ts`). * - `custom` — user-supplied `compaction.compact()` callback on * `CoreSessionConfig`. */ export type TelemetryCompactionStrategy = "basic" | "agentic" | "custom"; /** * Trigger mode for a compaction attempt. * * - `auto` — fired automatically by `createContextCompactionPrepareTurn` * when input tokens reach the fixed compaction threshold. * - `manual` — user-initiated (e.g. CLI `/compact`). */ export type TelemetryCompactionMode = "auto" | "manual"; export interface CaptureCompactionExecutedProperties { ulid: string; strategy: TelemetryCompactionStrategy; mode: TelemetryCompactionMode; messagesBefore: number; messagesAfter: number; messagesRemoved: number; /** Full-request token estimates, in the same units as the trigger and limit. */ tokensBefore: number; tokensAfter: number; tokensSaved: number; triggerTokens: number; maxInputTokens: number; thresholdRatio: number; durationMs: number; provider?: string; modelId?: string; } export declare function captureCompactionExecuted(telemetry: ITelemetryService | undefined, properties: CaptureCompactionExecutedProperties & Partial): void; export interface CaptureCompactionSkippedProperties { ulid: string; strategy: TelemetryCompactionStrategy; mode: TelemetryCompactionMode; /** * Why the strategy decided not to compact. Currently only one value is * emitted by the wrapper: * - `no_result` — strategy returned `undefined` (e.g. there was nothing * safe to remove). Strategy *exceptions* propagate up instead of * firing telemetry, so no `strategy_error` value is emitted today. * The field is kept loosely typed (`string`) so additional reasons can * be introduced without changing the schema. */ reason: string; /** Full-request token estimate, in the same units as the trigger and limit. */ tokensBefore: number; triggerTokens: number; maxInputTokens: number; thresholdRatio: number; durationMs: number; provider?: string; modelId?: string; } export declare function captureCompactionSkipped(telemetry: ITelemetryService | undefined, properties: CaptureCompactionSkippedProperties & Partial): void; export interface CaptureCompactionBudgetEmergencyProperties { ulid: string; strategy: TelemetryCompactionStrategy; mode: TelemetryCompactionMode; policyIntent: CoreCompactionBudgetPolicyIntent; actionCount: number; warningCount: number; liveTailHandling: CoreCompactionLiveTailHandling; provider?: string; modelId?: string; } export declare function captureCompactionBudgetEmergency(telemetry: ITelemetryService | undefined, properties: CaptureCompactionBudgetEmergencyProperties & Partial): void;