Add AI agent detection to CLI analytics - #8523
Draft
amcaplan wants to merge 1 commit into
Draft
Conversation
amcaplan
force-pushed
the
detect-agents
branch
2 times, most recently
from
September 10, 2026 19:19
d35d699 to
0758c94
Compare
Detect the agent running the CLI with @vercel/detect-agent and report it as n:<name> inside SHOPIFY_CLI_AGENT_INFO, the packed format the Shopify AI toolkit already uses, so a detected name resolves through the same field as a declared one. Detection only fills the gap. It is skipped when a producer declared SHOPIFY_CLI_AGENT_INFO or SHOPIFY_CLI_AGENT_IDS, because writing INFO ourselves would clobber their whole packed value, not just the name. SHOPIFY_CLI_AGENT_DETECTED marks a name as derived rather than declared. Assisted-By: devx/105d6a35-ec6d-462e-9e36-a9fde4ec06fc Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
amcaplan
force-pushed
the
detect-agents
branch
from
September 10, 2026 20:02
0758c94 to
39b0ef0
Compare
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/private/node/context/agent.d.tsexport declare function detectedAgentEnvironmentVariables(env?: NodeJS.ProcessEnv): Promise<NodeJS.ProcessEnv>;
Existing type declarationspackages/cli-kit/dist/private/node/analytics.d.ts@@ -31,4 +31,6 @@ export declare function getSensitiveEnvironmentData(config: Interfaces.Config):
env_plugin_installed_all: string;
env_shopify_variables: string;
}>;
+export declare function monorailAnalyticsSkipped(): boolean;
+export declare function metricAnalyticsSkipped(): boolean;
export {};
\ No newline at end of file
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
WHY are these changes introduced?
We can't currently distinguish CLI runs made by AI coding agents from runs made by humans or scripts. The Shopify AI toolkit has agents declare themselves through
SHOPIFY_CLI_AGENT_INFOandSHOPIFY_CLI_AGENT_IDS, but agents outside that toolkit stay invisible in analytics.https://github.com/shop/issues-develop/issues/23864
WHAT is this pull request doing?
Detect the agent with
@vercel/detect-agentand report it through the existing sensitiveenv_shopify_variablesfield, so there is no Monorail schema change.Detected names use the packed format producers already send —
SHOPIFY_CLI_AGENT_INFO="n:<name>"— so theagentcolumn resolves the same way whether a name was declared or detected. Only then:tag is set: detection cannot resolve version, provider or model, so those tags are omitted rather than padded, leaving those columns null instead of a literalnone.Detection is a fallback. It is skipped when
SHOPIFY_CLI_AGENT_INFOorSHOPIFY_CLI_AGENT_IDSis declared, because writingSHOPIFY_CLI_AGENT_INFOourselves would clobber the producer's whole packed value.SHOPIFY_CLI_AGENT_DETECTED=truerecords that a name was derived rather than declared; nothing consumes it downstream yet.Detected names have
|stripped. It is the tag separator with no escape sequence, and theAI_AGENTconvention passes arbitrary values through verbatim, so a name containing one could otherwise fabricate tags such asv:.Detection runs only when the event will actually be sent, so an opted-out user pays nothing for it.
How to manually test your changes?
bin/dev.jsruns the bundle rather than the source, so bundle first:A detected agent, with nothing declared:
env -u SHOPIFY_CLI_AGENT_INFO -u SHOPIFY_CLI_AGENT_IDS AI_AGENT=codex SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS=1 node packages/cli/bin/dev.js version --verbose | grep env_shopify_variablesReports
{"SHOPIFY_CLI_AGENT_INFO":"n:codex","SHOPIFY_CLI_AGENT_DETECTED":"true"}.A declared agent, which detection must leave alone:
Reports the declared value unchanged, with no
SHOPIFY_CLI_AGENT_DETECTED.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add🤖 Generated with Claude Code