|
104 | 104 | 'FLEXIBLE_CHECKSUMS_REQ_XXHASH3': 'AG', |
105 | 105 | 'FLEXIBLE_CHECKSUMS_REQ_XXHASH64': 'AH', |
106 | 106 | 'FLEXIBLE_CHECKSUMS_REQ_XXHASH128': 'AI', |
| 107 | + 'AGENTIC_CALLER_CLAUDE_CODE': 'AN', |
| 108 | + 'AGENTIC_CALLER_GEMINI_CLI': 'AO', |
| 109 | + 'AGENTIC_CALLER_CODEX': 'AP', |
| 110 | + 'AGENTIC_CALLER_KIRO': 'AQ', |
| 111 | + 'AGENTIC_CALLER_OPENCODE': 'AR', |
| 112 | + 'AGENTIC_CALLER_ANTIGRAVITY': 'AS', |
| 113 | + 'AGENTIC_CALLER_AMP': 'AT', |
| 114 | + 'AGENTIC_CALLER_PI': 'AU', |
| 115 | + 'AGENTIC_CALLER_COPILOT_CLI': 'AV', |
| 116 | + 'AGENTIC_CALLER_CURSOR': 'AW', |
107 | 117 | } |
| 118 | +_USERAGENT_AGENTIC_CALLER_ENV_VAR_MAPPINGS = ( |
| 119 | + ('CLAUDECODE', 'AGENTIC_CALLER_CLAUDE_CODE', '1'), |
| 120 | + ('GEMINI_CLI', 'AGENTIC_CALLER_GEMINI_CLI', '1'), |
| 121 | + ('CODEX_THREAD_ID', 'AGENTIC_CALLER_CODEX', None), |
| 122 | + ('KIRO_SESSION_ID', 'AGENTIC_CALLER_KIRO', None), |
| 123 | + ('OPENCODE', 'AGENTIC_CALLER_OPENCODE', None), |
| 124 | + ('ANTIGRAVITY_AGENT', 'AGENTIC_CALLER_ANTIGRAVITY', None), |
| 125 | + ('AMP_CURRENT_THREAD_ID', 'AGENTIC_CALLER_AMP', None), |
| 126 | + ('PI_CODING_AGENT', 'AGENTIC_CALLER_PI', 'true'), |
| 127 | + ('COPILOT_CLI', 'AGENTIC_CALLER_COPILOT_CLI', '1'), |
| 128 | + ('CURSOR_AGENT', 'AGENTIC_CALLER_CURSOR', '1'), |
| 129 | +) |
108 | 130 |
|
109 | 131 |
|
110 | 132 | def register_feature_id(feature_id): |
@@ -136,6 +158,27 @@ def register_feature_ids(feature_ids): |
136 | 158 | register_feature_id(feature_id) |
137 | 159 |
|
138 | 160 |
|
| 161 | +def _agentic_env_var_is_set(env_var, expected_value): |
| 162 | + """ |
| 163 | + Returns true if an environment variable is set, |
| 164 | + optionally with specific value |
| 165 | + """ |
| 166 | + value = os.environ.get(env_var) |
| 167 | + if expected_value is None: |
| 168 | + return value not in (None, '') |
| 169 | + return value == expected_value |
| 170 | + |
| 171 | + |
| 172 | +def _register_agentic_caller_env_features(): |
| 173 | + for ( |
| 174 | + env_var, |
| 175 | + feature_id, |
| 176 | + expected_value, |
| 177 | + ) in _USERAGENT_AGENTIC_CALLER_ENV_VAR_MAPPINGS: |
| 178 | + if _agentic_env_var_is_set(env_var, expected_value): |
| 179 | + register_feature_id(feature_id) |
| 180 | + |
| 181 | + |
139 | 182 | def sanitize_user_agent_string_component(raw_str, allow_hash): |
140 | 183 | """Replaces all not allowed characters in the string with a dash ("-"). |
141 | 184 |
|
@@ -549,6 +592,7 @@ def _build_feature_metadata(self): |
549 | 592 | Returns a single component with prefix "m" followed by a list of |
550 | 593 | comma-separated metric values. |
551 | 594 | """ |
| 595 | + _register_agentic_caller_env_features() |
552 | 596 | ctx = get_context() |
553 | 597 | context_features = set() if ctx is None else ctx.features |
554 | 598 | client_features = self._client_features or set() |
|
0 commit comments