Skip to content

Loosen LLM telemetry env detection to presence-based and add missing agent variables#54659

Merged
baronfel merged 4 commits into
mainfrom
baronfel/loosen-llm-env-detection
Jun 18, 2026
Merged

Loosen LLM telemetry env detection to presence-based and add missing agent variables#54659
baronfel merged 4 commits into
mainfrom
baronfel/loosen-llm-env-detection

Conversation

@baronfel

@baronfel baronfel commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

Enhances the AI-agent / LLM environment detector used for telemetry (LLMEnvironmentDetectorForTelemetry), drawing on Pulumi's equivalent detector in pulumi/pulumi sdk/go/common/util/agentdetect/agentdetect.go.

(a) Loosen checks to presence-based

Several rules previously used BooleanEnvironmentRule, which only matched when the variable parsed as the literal value true. These are now presence-based (the variable being set/non-empty is enough), matching Pulumi's "is this env var non-empty?" approach. Converted to AnyPresentEnvironmentRule:

  • gemini — GEMINI_CLI
  • legacy copilot — GITHUB_COPILOT_CLI_MODE (the copilot rule's AnyMatchEnvironmentRule wrapper is collapsed into a single AnyPresentEnvironmentRule)
  • droid — DROID_CLI
  • kimi — KIMI_CLI
  • generic agent — AGENT_CLI

The OR_APP_NAME exact-value rules (aider/plandex/openhands) are left as EnvironmentVariableValueRule since those distinguish multiple tools sharing one variable. The shared BooleanEnvironmentRule type is not removed — it is still used by CIEnvironmentDetectorForTelemetry.

(b) Add missing variable sets from Pulumi

  • cursor: + CURSOR_TRACE_ID, CURSOR_AGENT
  • codex: + CODEX_CI, CODEX_THREAD_ID
  • copilot: + COPILOT_MODEL, COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKEN
  • goose: + GOOSE_PROVIDER
  • claude: + CLAUDE_CODE
  • New agents: coworkCLAUDE_CODE_IS_COWORK (placed before claude, mirroring Pulumi's specific-before-broad ordering), replitREPL_ID, augmentAUGMENT_AGENT, antigravityANTIGRAVITY_AGENT

All existing extra agents that Pulumi lacks (aider, plandex, amp, qwen, droid, kimi, zed, cline, roo, windsurf, opencode) are preserved.

(c) Test coverage

Extended TelemetryCommonPropertiesTests:

  • Presence-based matching of loosened vars (e.g. GEMINI_CLI=0gemini; the previously null-expected false-valued cases for gemini/copilot/agent/droid/kimi now match).
  • Detection of each newly added variable/agent.
  • A multi-value cowork, claude case verifying CLAUDE_CODE_IS_COWORK is reported independently of CLAUDE_CODE.

Notes

  • This is a user-visible telemetry behavior change (looser matching + new agent values).
  • Our detector joins all matching results with string.Join(", ", ...) (unlike Pulumi, which returns the first match), so overlapping environments can produce multi-value output such as cowork, claude.

Validation

Clean build (0 warnings); all telemetry test cases pass via the repo-local SDK.

…agent variables

Loosen the AI-agent/LLM environment detector used for telemetry so detection
is presence-based (variable set/non-empty) rather than requiring a literal
`true` value. Converts the BooleanEnvironmentRule usages for gemini
(GEMINI_CLI), legacy copilot (GITHUB_COPILOT_CLI_MODE), droid (DROID_CLI),
kimi (KIMI_CLI) and the generic agent flag (AGENT_CLI) to
AnyPresentEnvironmentRule, matching Pulumi's agentdetect approach. The shared
BooleanEnvironmentRule type is retained (still used by the CI detector).

Add the agent variable sets present in pulumi/pulumi's
sdk/go/common/util/agentdetect/agentdetect.go: cursor (CURSOR_TRACE_ID,
CURSOR_AGENT), codex (CODEX_CI, CODEX_THREAD_ID), copilot (COPILOT_MODEL,
COPILOT_ALLOW_ALL, COPILOT_GITHUB_TOKEN), goose (GOOSE_PROVIDER),
claude (CLAUDE_CODE), and new rules cowork (CLAUDE_CODE_IS_COWORK),
replit (REPL_ID), augment (AUGMENT_AGENT) and antigravity (ANTIGRAVITY_AGENT).

Extends the telemetry tests to cover presence-based matching of the loosened
variables and detection of each newly added variable/agent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 9, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the CLI’s LLM/agent environment detection used for telemetry to align with presence-based env-var detection and expands the set of recognized agents/variables, with corresponding test coverage updates.

Changes:

  • Switched several LLM detector rules from strict boolean parsing to “env var present/non-empty” matching.
  • Added additional env vars and new agent identifiers (e.g., cowork, replit, augment, antigravity) to improve detection coverage.
  • Expanded TelemetryCommonPropertiesTests to validate the loosened matching behavior and all newly added variables/agents, including multi-detection output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/dotnet.Tests/TelemetryTests/TelemetryCommonPropertiesTests.cs Extends LLM telemetry test matrix to cover presence-based matching and newly recognized agents/variables, including combined detections.
src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs Updates LLM environment detection rules to presence-based matching and adds missing/new agent env var indicators; keeps multi-match output behavior.

Comment thread src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs Outdated
@baronfel baronfel self-assigned this Jun 9, 2026
@baronfel baronfel requested a review from a team June 9, 2026 20:39
@baronfel baronfel requested a review from DamianEdwards June 9, 2026 21:54
Comment thread src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs Outdated
baronfel and others added 2 commits June 10, 2026 13:16
Address review feedback: the Copilot CLI sets COPILOT_CLI (and related
GITHUB_COPILOT_CLI_MODE/GH_COPILOT_WORKING_DIRECTORY/COPILOT_AGENT/COPILOT_MODEL/
COPILOT_ALLOW_ALL/COPILOT_GITHUB_TOKEN) variables, whereas GitHub Copilot in
VS and VS Code does not set environment variables. Report the more specific
`copilot-cli` value for these CLI experiences so they can be distinguished
from (currently undetectable) editor-hosted Copilot, and clarify the rule
comments to note that not all rules are presence-based and that all matching
rules contribute to the result.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GitHub Copilot agent mode in VS Code injects AI_AGENT=github_copilot_vscode_agent
and COPILOT_AGENT=1 into the terminals it runs commands in (see vscode's
toolTerminalCreator.ts), so COPILOT_AGENT is not a Copilot CLI signal. Move it
out of the copilot-cli rule into a new copilot-vscode rule keyed on
COPILOT_AGENT and the AI_AGENT=github_copilot_vscode_agent marker, so editor-
hosted agent usage is reported as copilot-vscode rather than copilot-cli.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@baronfel

Copy link
Copy Markdown
Member Author

/ba-g flaky test

@baronfel baronfel merged commit 2d088b7 into main Jun 18, 2026
23 of 25 checks passed
@baronfel baronfel deleted the baronfel/loosen-llm-env-detection branch June 18, 2026 16:22
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants