-
Notifications
You must be signed in to change notification settings - Fork 473
feat: attach the driving agent to telemetry events #8504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seancdavis
wants to merge
15
commits into
main
Choose a base branch
from
ex-3042-agent-telemetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
98d1e39
feat: add getDrivingAgent agent-detection helper
seancdavis 84c9b48
test: cover getDrivingAgent signals, nesting, and ignored markers
seancdavis 38c708f
docs: document NETLIFY_AGENT for agent detection
seancdavis ba67e09
fix: guard agent-name lookup against prototype keys
seancdavis 608b21e
test: consolidate prototype-key regression cases
seancdavis 5154f78
feat: detect Warp runs and let NETLIFY_AGENT override unconditionally
seancdavis 5b2eae4
fix: address CodeRabbit review on agent detection
seancdavis 4ec9772
fix: tighten agent-detection precedence and input hardening
seancdavis 000b3b8
fix: honor name@version announcements and let the first match win
seancdavis 6a205b5
feat: recognize documented AI_AGENT aliases
seancdavis 4d55c4d
Merge remote-tracking branch 'origin/main' into ex-3040-agent-detection
seancdavis 33d6d51
feat: attach the driving agent to telemetry events
seancdavis 4f10610
fix: keep agent telemetry fields authoritative and document them
seancdavis 70e9ccd
Merge remote-tracking branch 'origin/main' into ex-3042-agent-telemetry
seancdavis 996073d
fix: keep an announced "other" value in otherValue
seancdavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import { track } from '../../../../src/utils/telemetry/telemetry.js' | ||
| import { cliVersion } from '../../../../src/utils/telemetry/utils.js' | ||
| import execa from '../../../../src/utils/execa.js' | ||
|
|
||
| vi.mock('ci-info', () => ({ isCI: false })) | ||
|
|
||
| vi.mock('@netlify/dev-utils', async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof import('@netlify/dev-utils')>()), | ||
| getGlobalConfigStore: vi.fn(() => | ||
| Promise.resolve({ get: (key: string) => (key === 'telemetryDisabled' ? false : 'test-user-1') }), | ||
| ), | ||
| })) | ||
|
|
||
| vi.mock('../../../../src/utils/execa.js', () => ({ default: vi.fn(() => ({ unref: vi.fn() })) })) | ||
|
|
||
| const AGENT_ENV_KEYS = [ | ||
| 'NETLIFY_AGENT', | ||
| 'CODEX_CI', | ||
| 'CODEX_VERSION', | ||
| 'GEMINI_CLI', | ||
| 'COPILOT_CLI', | ||
| 'COPILOT_AGENT_SESSION_ID', | ||
| 'OPENCODE', | ||
| 'OPENCODE_TERMINAL', | ||
| 'AGENT_DISPLAY_OUT', | ||
| 'AGENT_CONTEXT_OUT', | ||
| 'OZ_RUN_ID', | ||
| 'WARP_RUN_ID', | ||
| 'AI_AGENT', | ||
| 'COPILOT_AGENT', | ||
| 'CURSOR_AGENT', | ||
| 'CLINE_ACTIVE', | ||
| 'AGENT', | ||
| 'CLAUDE_CODE_CHILD_SESSION', | ||
| ] | ||
|
|
||
| const getTrackedProperties = (): Record<string, unknown> => { | ||
| const { calls } = vi.mocked(execa).mock | ||
| const [, [, optionsJson]] = calls[calls.length - 1] as [string, string[]] | ||
| return (JSON.parse(optionsJson) as { data: { properties: Record<string, unknown> } }).data.properties | ||
| } | ||
|
|
||
| const getTrackedAgentProperties = () => | ||
| Object.fromEntries( | ||
| Object.entries(getTrackedProperties()).filter(([key]) => key === 'agent' || key.startsWith('agent_')), | ||
| ) | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| AGENT_ENV_KEYS.forEach((key) => vi.stubEnv(key, undefined)) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| describe('track', () => { | ||
| test('adds the driving agent alongside the existing properties', async () => { | ||
| vi.stubEnv('AI_AGENT', 'claude-code') | ||
|
|
||
| await track('command', { command: 'status' }) | ||
|
|
||
| expect(getTrackedProperties()).toMatchObject({ command: 'status', cliVersion }) | ||
| expect(getTrackedAgentProperties()).toEqual({ agent: 'claude', agent_source: 'AI_AGENT' }) | ||
| }) | ||
|
|
||
| test('adds no agent properties when no agent is detected', async () => { | ||
| await track('command', { command: 'status' }) | ||
|
|
||
| expect(getTrackedAgentProperties()).toEqual({}) | ||
| }) | ||
|
|
||
| test('drops agent properties supplied by the caller', async () => { | ||
| await track('command', { | ||
| command: 'status', | ||
| agent: 'spoofed', | ||
| agent_source: 'spoofed', | ||
| agent_version: 'spoofed', | ||
| agent_markers: ['spoofed'], | ||
| agent_other_value: 'spoofed', | ||
| }) | ||
|
|
||
| expect(getTrackedAgentProperties()).toEqual({}) | ||
| }) | ||
|
|
||
| test('adds the agent version when the agent announces one', async () => { | ||
| vi.stubEnv('AI_AGENT', 'claude-code_2-1-263_agent') | ||
|
|
||
| await track('command', { command: 'status' }) | ||
|
|
||
| expect(getTrackedAgentProperties()).toEqual({ | ||
| agent: 'claude', | ||
| agent_source: 'AI_AGENT', | ||
| agent_version: '2.1.263', | ||
| }) | ||
| }) | ||
|
|
||
| test('lists every matched agent when agents are nested', async () => { | ||
| vi.stubEnv('AI_AGENT', 'claude-code') | ||
| vi.stubEnv('CODEX_CI', '1') | ||
|
|
||
| await track('command', { command: 'status' }) | ||
|
|
||
| expect(getTrackedAgentProperties()).toEqual({ | ||
| agent: 'codex', | ||
| agent_source: 'CODEX_CI', | ||
| agent_markers: ['codex', 'claude'], | ||
| }) | ||
| }) | ||
|
|
||
| test('reports an unknown AI_AGENT value as other with its sanitized value', async () => { | ||
| vi.stubEnv('AI_AGENT', 'some-new-tool') | ||
|
|
||
| await track('command', { command: 'status' }) | ||
|
|
||
| expect(getTrackedAgentProperties()).toEqual({ | ||
| agent: 'other', | ||
| agent_source: 'AI_AGENT', | ||
| agent_other_value: 'some-new-tool', | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use smart apostrophes.
Replace the straight apostrophes in
isn'twithisn’t.lint-docsreports both occurrences.Also applies to: 233-233
🧰 Tools
🪛 GitHub Check: lint-docs
[warning] 221-221:
[vale] reported by reviewdog 🐶
[smart-marks.smartApostrophes] Use a smart apostrophe (’) instead of a straight single quote mark in 'isn't'
Raw Output:
{"message": "[smart-marks.smartApostrophes] Use a smart apostrophe (’) instead of a straight single quote mark in 'isn't'", "location": {"path": "docs/index.md", "range": {"start": {"line": 221, "column": 192}}}, "severity": "WARNING"}
🤖 Prompt for AI Agents
Source: Linters/SAST tools