From cf7551752a79ffd4633a8494fe1211e73062a420 Mon Sep 17 00:00:00 2001 From: patrikbraborec Date: Thu, 26 Nov 2026 14:23:57 +0100 Subject: [PATCH 1/6] feat(telemetry): detect more AI agents Adds Codex, Claude Cowork, Cursor agent-exec, Antigravity, Augment, OpenCode client, Hermes, Grok, Kiro, Replit, GitHub Copilot, the generic AI_AGENT/AGENT variables, and Devin. Agent-specific signals win over the generic ones. Part of #1519. --- src/lib/hooks/telemetry/detectEnvironment.ts | 52 +++++++++++++++++-- .../hooks/telemetry/detectEnvironment.test.ts | 49 +++++++++++++++++ 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/lib/hooks/telemetry/detectEnvironment.ts b/src/lib/hooks/telemetry/detectEnvironment.ts index c21cd0e36..2b315e19b 100644 --- a/src/lib/hooks/telemetry/detectEnvironment.ts +++ b/src/lib/hooks/telemetry/detectEnvironment.ts @@ -1,24 +1,70 @@ +import { existsSync } from 'node:fs'; +import process from 'node:process'; + import ciInfo from 'ci-info'; +// Agent-specific signals: the agent is detected when any of these is set to a non-empty value. const AI_AGENT_ENV_VARS: [string, string][] = [ ['CLAUDECODE', 'claude_code'], ['CLAUDE_CODE_ENTRYPOINT', 'claude_code'], + ['CLAUDE_CODE', 'claude_code'], ['CURSOR_AGENT', 'cursor'], ['CLINE_ACTIVE', 'cline'], ['CODEX_SANDBOX', 'codex_cli'], ['CODEX_THREAD_ID', 'codex_cli'], + ['CODEX_CI', 'codex_cli'], + ['CODEX_SANDBOX_NETWORK_DISABLED', 'codex_cli'], + ['CODEX_INTERNAL_ORIGINATOR_OVERRIDE', 'codex_cli'], ['GEMINI_CLI', 'gemini_cli'], ['OPENCODE', 'open_code'], + ['OPENCODE_CLIENT', 'open_code'], ['OPENCLAW_SHELL', 'openclaw'], + ['ANTIGRAVITY_AGENT', 'antigravity'], + ['ANTIGRAVITY_CLI_ALIAS', 'antigravity'], + ['AUGMENT_AGENT', 'augment'], + ['HERMES_AGENT', 'hermes'], + ['GROK_AGENT', 'grok'], + ['GROK_SESSION_ID', 'grok'], + ['KIRO_SESSION_ID', 'kiro'], + ['REPL_ID', 'replit'], + ['COPILOT_MODEL', 'github_copilot'], + ['COPILOT_ALLOW_ALL', 'github_copilot'], + ['COPILOT_GITHUB_TOKEN', 'github_copilot'], ]; +// Generic signals carry the agent's name as their value, which is free-form. +const GENERIC_AI_AGENT_ENV_VARS = ['AI_AGENT', 'AGENT']; + +const AI_AGENT_NAME_MAX_LENGTH = 64; + export function detectAiAgent(): string | undefined { - for (const [envVar, agent] of AI_AGENT_ENV_VARS) { - if (process.env[envVar]) { - return agent; + const agent = AI_AGENT_ENV_VARS.find(([envVar]) => process.env[envVar])?.[1]; + + if (agent) { + return agent === 'claude_code' && process.env.CLAUDE_CODE_IS_COWORK ? 'claude_cowork' : agent; + } + + if (process.env.CURSOR_EXTENSION_HOST_ROLE === 'agent-exec') { + return 'cursor'; + } + + // Kiro's integrated terminal sets this for humans too; only a non-interactive stdin points to the agent. + if (process.env.TERM_PROGRAM === 'kiro' && !process.stdin.isTTY) { + return 'kiro'; + } + + for (const envVar of GENERIC_AI_AGENT_ENV_VARS) { + const name = process.env[envVar]?.trim(); + + if (name) { + return name.slice(0, AI_AGENT_NAME_MAX_LENGTH); } } + if (existsSync('/opt/.devin')) { + return 'devin'; + } + return undefined; } diff --git a/test/lib/hooks/telemetry/detectEnvironment.test.ts b/test/lib/hooks/telemetry/detectEnvironment.test.ts index 65bfe3d2f..0dab67e44 100644 --- a/test/lib/hooks/telemetry/detectEnvironment.test.ts +++ b/test/lib/hooks/telemetry/detectEnvironment.test.ts @@ -4,17 +4,45 @@ import { detectAiAgent, detectCi, detectIsInteractive } from '../../../../src/li // so we mock it to control the return value per-test. vi.mock('ci-info', () => ({ default: { isCI: false, id: null } })); +// Devin is detected by a file on disk, so keep the suite deterministic when it runs inside Devin. +vi.mock('node:fs', async (importOriginal) => ({ + ...(await importOriginal()), + existsSync: () => false, +})); + describe('detectAiAgent', () => { const agentEnvVars = [ 'CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', + 'CLAUDE_CODE', + 'CLAUDE_CODE_IS_COWORK', 'CURSOR_AGENT', + 'CURSOR_EXTENSION_HOST_ROLE', + 'CURSOR_TRACE_ID', 'CLINE_ACTIVE', 'CODEX_SANDBOX', 'CODEX_THREAD_ID', + 'CODEX_CI', + 'CODEX_SANDBOX_NETWORK_DISABLED', + 'CODEX_INTERNAL_ORIGINATOR_OVERRIDE', 'GEMINI_CLI', 'OPENCODE', + 'OPENCODE_CLIENT', 'OPENCLAW_SHELL', + 'ANTIGRAVITY_AGENT', + 'ANTIGRAVITY_CLI_ALIAS', + 'AUGMENT_AGENT', + 'HERMES_AGENT', + 'GROK_AGENT', + 'GROK_SESSION_ID', + 'KIRO_SESSION_ID', + 'TERM_PROGRAM', + 'REPL_ID', + 'COPILOT_MODEL', + 'COPILOT_ALLOW_ALL', + 'COPILOT_GITHUB_TOKEN', + 'AI_AGENT', + 'AGENT', ]; beforeEach(() => { @@ -44,6 +72,27 @@ describe('detectAiAgent', () => { // CURSOR_AGENT appears before GEMINI_CLI in the lookup table expect(detectAiAgent()).toBe('cursor'); }); + + test('detects an agent from a newly added env var', () => { + vi.stubEnv('CODEX_CI', '1'); + expect(detectAiAgent()).toBe('codex_cli'); + }); + + test('prefers an agent-specific env var over the generic AI_AGENT', () => { + vi.stubEnv('CLAUDECODE', '1'); + vi.stubEnv('AI_AGENT', 'something-else'); + expect(detectAiAgent()).toBe('claude_code'); + }); + + test('returns the trimmed AI_AGENT value as the agent name', () => { + vi.stubEnv('AI_AGENT', ' my-agent '); + expect(detectAiAgent()).toBe('my-agent'); + }); + + test('does not treat CURSOR_TRACE_ID alone as an agent', () => { + vi.stubEnv('CURSOR_TRACE_ID', 'abc123'); + expect(detectAiAgent()).toBeUndefined(); + }); }); describe('detectCi', () => { From 385b9e48c5b490a097926c583320c37a82dbdc67 Mon Sep 17 00:00:00 2001 From: patrikbraborec Date: Thu, 26 Nov 2026 14:29:41 +0100 Subject: [PATCH 2/6] feat(feedback): add apify feedback command Lets humans and agents report a problem, or say something worked, from the terminal. The report goes to Segment as a 'CLI Reported Problem' event with the same properties as the MCP server's, plus the previous command and its exit code. It's sent even when telemetry is disabled, and the command exits 1 if Segment doesn't accept it. Part of #1519. --- docs/reference.md | 49 ++++++ scripts/generate-cli-docs.ts | 1 + src/commands/_register.ts | 2 + src/commands/feedback.ts | 142 +++++++++++++++++ src/lib/command-framework/apify-command.ts | 5 +- src/lib/hooks/telemetry/trackEvent.ts | 113 +++++++++----- src/lib/hooks/telemetry/useTelemetryState.ts | 4 +- .../checkAndUpdateLastCommand.test.ts | 21 +-- test/local/commands/feedback.test.ts | 146 ++++++++++++++++++ 9 files changed, 431 insertions(+), 52 deletions(-) create mode 100644 src/commands/feedback.ts create mode 100644 test/local/commands/feedback.test.ts diff --git a/docs/reference.md b/docs/reference.md index c3d5a073b..38e736d0e 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -130,6 +130,55 @@ DESCRIPTION USAGE $ apify telemetry disable ``` + +##### `apify feedback` + +```sh +DESCRIPTION + Sends feedback about the Apify CLI to the Apify team: report a problem, or + tell us something worked well. + It's one-way, so you won't get a reply. For support, use + https://apify.com/contact. + It's sent even when telemetry is disabled, because you asked to send it. Don't + include personal data, credentials, or secrets. + +USAGE + $ apify feedback [--actor-id ] + [--actor-run-id ] [--actual ] + [--category + bug|spec_mismatch|readme_unclear|missing_capability|improvement|worked_well] + [--expected ] [--json] [--sent-by human|agent] + [--sentiment positive|negative|neutral] [--source user|model] + +ARGUMENTS + message What happened, or what worked. At most 2000 characters. + +FLAGS + --actor-id= ID of the Actor the feedback + is about. + --actor-run-id= ID of the Actor run the + feedback is about. + --actual= What actually happened. At + most 2000 characters. + --category=