Skip to content

Append agent/<id> to the User-Agent when driven by an AI coding agent#219

Draft
ctufts wants to merge 2 commits into
masterfrom
agi-1011-agent-user-agent
Draft

Append agent/<id> to the User-Agent when driven by an AI coding agent#219
ctufts wants to merge 2 commits into
masterfrom
agi-1011-agent-user-agent

Conversation

@ctufts

@ctufts ctufts commented Jul 17, 2026

Copy link
Copy Markdown

Detects the calling AI coding agent (Claude Code, Codex, Cursor, etc.) from a hardcoded environment-variable allowlist and appends agent/<id> to the tilesets Session User-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:

  • ~22 harness-specific env vars in a fixed precedence order (presence-only, except warp/vtcode which require an exact value match)
  • a fallback to AI_AGENT/AGENT if nothing else matched, restricted to a safe charset so an unexpected value (e.g. containing a newline) can't reach the header and crash requests

Only 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.

ctufts added 2 commits July 17, 2026 16:50
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.
@ctufts ctufts added the locationai-team-skills Opened via the location-ai PR creation skill label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

locationai-team-skills Opened via the location-ai PR creation skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant