Commit fe65d2d9 authored by Andrew Imm's avatar Andrew Imm

Add agent detection to telemetry metadata

Track which AI agent (if any) is running when telemetry events are sent.
Adds agentName field to anonymous metadata, detected via environment
variables set by known agents (Cursor, Claude, Copilot, Codex, etc.).
parent 5db26f98
...@@ -3,6 +3,7 @@ import isWslBoolean from 'next/dist/compiled/is-wsl' ...@@ -3,6 +3,7 @@ import isWslBoolean from 'next/dist/compiled/is-wsl'
import os from 'os' import os from 'os'
import * as ciEnvironment from '../server/ci-info' import * as ciEnvironment from '../server/ci-info'
import { detectAgent } from './detect-agent'
type AnonymousMeta = { type AnonymousMeta = {
systemPlatform: NodeJS.Platform systemPlatform: NodeJS.Platform
...@@ -18,6 +19,7 @@ type AnonymousMeta = { ...@@ -18,6 +19,7 @@ type AnonymousMeta = {
isCI: boolean isCI: boolean
ciName: string | null ciName: string | null
nextVersion: string nextVersion: string
agentName: string | null
} }
let traits: AnonymousMeta | undefined let traits: AnonymousMeta | undefined
...@@ -46,6 +48,7 @@ export function getAnonymousMeta(): AnonymousMeta { ...@@ -46,6 +48,7 @@ export function getAnonymousMeta(): AnonymousMeta {
isCI: ciEnvironment.isCI, isCI: ciEnvironment.isCI,
ciName: (ciEnvironment.isCI && ciEnvironment.name) || null, ciName: (ciEnvironment.isCI && ciEnvironment.name) || null,
nextVersion: process.env.__NEXT_VERSION as string, nextVersion: process.env.__NEXT_VERSION as string,
agentName: detectAgent(),
} }
return traits return traits
......
export type AgentName =
| 'cursor'
| 'cursor-cli'
| 'claude'
| 'cowork'
| 'devin'
| 'replit'
| 'gemini'
| 'codex'
| 'antigravity'
| 'augment-cli'
| 'opencode'
| 'github-copilot'
export function detectAgent(): AgentName | null {
if (process.env.AI_AGENT) {
const name = process.env.AI_AGENT.trim()
if (name) {
const normalized = name === 'github-copilot-cli' ? 'github-copilot' : name
return normalized as AgentName
}
}
if (process.env.CURSOR_TRACE_ID) {
return 'cursor'
}
if (process.env.CURSOR_AGENT) {
return 'cursor-cli'
}
if (process.env.GEMINI_CLI) {
return 'gemini'
}
if (
process.env.CODEX_SANDBOX ||
process.env.CODEX_CI ||
process.env.CODEX_THREAD_ID
) {
return 'codex'
}
if (process.env.ANTIGRAVITY_AGENT) {
return 'antigravity'
}
if (process.env.AUGMENT_AGENT) {
return 'augment-cli'
}
if (process.env.OPENCODE_CLIENT) {
return 'opencode'
}
if (process.env.CLAUDECODE || process.env.CLAUDE_CODE) {
if (process.env.CLAUDE_CODE_IS_COWORK) {
return 'cowork'
}
return 'claude'
}
if (process.env.REPL_ID) {
return 'replit'
}
if (
process.env.COPILOT_MODEL ||
process.env.COPILOT_ALLOW_ALL ||
process.env.COPILOT_GITHUB_TOKEN
) {
return 'github-copilot'
}
return null
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment