-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wrangler] Add AI agent detection to analytics events #11820
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
Conversation
🦋 Changeset detectedLatest commit: 6687834 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Claude finished @MattieTK's task —— View job Changeset Review
Version Type IssueThe changeset is marked as Analysis: Based on
This change adds new functionality (AI agent detection with a new
Recommendation: This is borderline, but Changeset Quality✅ Title: Clear and imperative ("Add AI agent detection to analytics events") Cuteness ReportThis is Loading Icon. They're just a simple orange circle doing their best. Minimal effort, maximum charm. Would spin again. 7/10 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
7f10c5d to
08ad648
Compare
| try { | ||
| const processAncestry = process.platform === "win32" ? [] : undefined; | ||
| const agentDetection = detectAgenticEnvironment( | ||
| process.env, | ||
| processAncestry | ||
| ); | ||
| agent = agentDetection.id; | ||
| } catch { |
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.
Seems like something that should be fixed upstream
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.
I am not even sure if there is actually an issue or if open-code just produced some (potentially overly) defensive code here
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.
This is a problem in the Windows tests at the moment, but happy for you to fix it upstream @ascorbic. I stopped Opencode from going mad at this, and was going to chat to you about it anyway.
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.
Have tested this further and resolving this as wmic is not throwing or printing errors in win 11 currently I was very wrong
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.
@ascorbic as discussed, I think we agree this should be resolved upstream, but I also think we should aim to get this in for as many clients as possible asap, so I'm pushing the change to prevent the windows errors for the time being and we can revisit. Hopefully that unblocks this in the tests 🙏
dario-piotrowicz
left a comment
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.
LGTM
.changeset/agentic-analytics.md
Outdated
| @@ -0,0 +1,9 @@ | |||
| --- | |||
| "wrangler": minor | |||
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.
I am not sure if this should maybe be a patch since it doesn't introduce any new user-facing feature 🤔
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.
Yep, probably right here again, I think we possibly need some clearer instructions for the LLMs.
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.
⬆️ we definitely need better instructions: one minute ago it was complaining this was still a minor based on your comment, now it's suggesting that it should be a minor again.
Leaving this unresolved for clarity.
This reverts commit 6cf6cfc.
The am-i-vibing library's detectAgenticEnvironment function uses
process-ancestry to check for running processes. When processAncestry
is undefined, it calls getProcessAncestry() which uses execSync('ps ...')
to walk up the entire process tree.
For each provider with processChecks (6 providers), it would call
getProcessAncestry() separately, causing:
- Massive slowdowns (tests took 78+ seconds instead of 3 seconds)
- Timeouts in CI environments (especially on Linux)
- Race conditions where output wasn't captured properly
By passing an empty array [], we skip process tree traversal entirely.
Environment variable detection is sufficient for identifying most
agentic environments (Claude Code, Cursor, Windsurf, etc.) and is
instantaneous.
Summary
This PR adds AI agent detection to Wrangler analytics events using the
am-i-vibinglibrary. When Wrangler commands are executed by AI coding agents (such as Claude Code, Cursor, GitHub Copilot, etc.), the agent ID is now included as anagentproperty in all analytics events.agentproperty toCommonEventPropertiestypenullwhen not running in an agentic environmentSupported Agents
The library detects agents including: Claude Code, Cursor, GitHub Copilot, Windsurf, Zed, Aider, Codex CLI, Jules, Replit, Warp, and others.
telemetry.mdA picture of a cute animal (not mandatory, but encouraged)