Skip to content

feat(telemetry): emit cli_context property on main events#269

Merged
LorrisSaintGenez merged 4 commits into
mainfrom
feat/agent-telemetry
Jul 15, 2026
Merged

feat(telemetry): emit cli_context property on main events#269
LorrisSaintGenez merged 4 commits into
mainfrom
feat/agent-telemetry

Conversation

@LorrisSaintGenez

@LorrisSaintGenez LorrisSaintGenez commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What

  • Emit cli_context on every telemetry Track event: agent:<name>, agent:unknown, or human
  • Detect once at startup (pkg/telemetry/clicontext.go); merge as a base property in Track() — single injection point, no changes outside pkg/telemetry
  • Detection order:
    1. Named agent env vars — Claude Code, Cursor, Codex, Gemini, Copilot, OpenCode, Amp, Augment, Goose, Cline, Antigravity, Pi, Kiro
    2. Generic AI_AGENT/AGENT — lowercase, trim, truncate at first _ (Claude Code stamps claude-code_<version>_agent); empty after normalization falls through
    3. stdin and stdout both non-TTY outside CI → agent:unknown
    4. Else → human
  • Bare AGENT is deliberate — set by Goose and Amp; the named table wins over generic vars
  • V1 limits: CLAUDECODE is also set by IDE-extension integrated terminals (counted as agent); CI runs fold into human

Test

go build -o /tmp/algolia-test ./cmd/algolia

# expect agent:claude-code
DEBUG=1 CLAUDECODE=1 /tmp/algolia-test auth status 2>&1 | grep -io 'cli_context:[^ ]*'

# expect agent:unknown (agent vars cleared, stdin AND stdout detached — piping only detaches stdout, so </dev/null is required from a terminal)
DEBUG=1 env -u CLAUDECODE -u CLAUDE_CODE_SESSION_ID -u AI_AGENT /tmp/algolia-test auth status </dev/null 2>&1 | grep -io 'cli_context:[^ ]*'

# expect human (agent vars cleared, real TTY)
env -u CLAUDECODE -u CLAUDE_CODE_SESSION_ID -u AI_AGENT DEBUG=1 script -q /tmp/ctx.log /tmp/algolia-test auth status >/dev/null; grep -io 'cli_context:[^ ]*' /tmp/ctx.log

# expect agent:claude-code (generic var only, version-stamped → normalized)
DEBUG=1 env -u CLAUDECODE -u CLAUDE_CODE_SESSION_ID AI_AGENT=claude-code_2-1-210_agent /tmp/algolia-test auth status 2>&1 | grep -io 'cli_context:[^ ]*'

GROUT-387

@codacy-production

codacy-production Bot commented Jul 15, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 30 complexity · 5 duplication

Metric Results
Complexity 30
Duplication 5

View in Codacy

TIP This summary will be updated as you push new changes.

@LorrisSaintGenez LorrisSaintGenez self-assigned this Jul 15, 2026
@LorrisSaintGenez
LorrisSaintGenez marked this pull request as ready for review July 15, 2026 19:45
Comment thread pkg/telemetry/clicontext.go

@8bittitan 8bittitan 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.

🫡

@LorrisSaintGenez
LorrisSaintGenez merged commit 3beb908 into main Jul 15, 2026
3 checks passed
@LorrisSaintGenez
LorrisSaintGenez deleted the feat/agent-telemetry branch July 15, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants