Append agent/<id> to the User-Agent when driven by an AI coding agent#219
Draft
ctufts wants to merge 2 commits into
Draft
Append agent/<id> to the User-Agent when driven by an AI coding agent#219ctufts wants to merge 2 commits into
ctufts wants to merge 2 commits into
Conversation
Detects the calling AI coding agent from a hardcoded env-var allowlist and appends " agent/<id>" to the tilesets Session User-Agent when one is found. No server dependency: the header is already logged by CloudFront, and the agent's environment is directly visible to this CLI's subprocess.
- Reject fallback (AI_AGENT/AGENT) values outside a safe header charset so a stray newline/colon can no longer crash every CLI command with requests.exceptions.InvalidHeader. - Treat empty/whitespace-only harness env vars as unset, matching the fallback path's existing empty-value handling.
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.
Detects the calling AI coding agent (Claude Code, Codex, Cursor, etc.) from a hardcoded environment-variable allowlist and appends
agent/<id>to the tilesetsSessionUser-Agent header when one is found. No server-side change and no environment forwarding — the User-Agent is already logged by CloudFront, and the agent's environment is directly visible to this CLI's own subprocess. When nothing matches, the header is unchanged.agent_detect.py::detect_agent()checks, in order:warp/vtcodewhich require an exact value match)AI_AGENT/AGENTif nothing else matched, restricted to a safe charset so an unexpected value (e.g. containing a newline) can't reach the header and crashrequestsOnly the matched id is ever used — the full environment is never read, logged, or transmitted.
Tested with
pytest tests/test_agent_detect.py tests/test_utils.py(34 passing) and by manually checking_get_session()'s header against both a positive case (CLAUDECODE=1→.../<version> agent/claude-code) and a negative control (agent vars unset → unmodified baseline). No downstream or operational impact — this is a client-side header change with no server dependency.