GitLabgitlab-org
cli
main
1package api
3import (
4 "os"
5 "regexp"
6 "strings"
7)
9// envTokenRE validates caller-supplied environment values before they reach
10// telemetry: alphanumeric, dots, hyphens, underscores, max 64 chars.
11var envTokenRE = regexp.MustCompile(`^[A-Za-z0-9._-]{1,64}$`)
13// AI_AGENT is the universal escape hatch; hardcoded agents are alphabetical,
14// except where a fork inherits its parent's marker and must be checked first.
15func DetectCodingAgent() string {
16 if v := os.Getenv("AI_AGENT"); envTokenRE.MatchString(v) && !isBooleanWord(v) {
17 return v
18 }
19 if os.Getenv("CLAUDECODE") == "1" {
20 return "claude-code"
21 }
22 if os.Getenv("CLINE_ACTIVE") == "true" {
23 return "cline"
24 }
25 // CODEX_THREAD_ID is an opaque thread identifier, not a boolean flag.
26 if os.Getenv("CODEX_THREAD_ID") != "" {
27 return "codex"
28 }
29 // GitHub Copilot CLI sets COPILOT_CLI=1
30 if os.Getenv("COPILOT_CLI") == "1" {
31 return "copilot"
32 }
33 if os.Getenv("CURSOR_AGENT") == "1" {
34 return "cursor"
35 }
36 if os.Getenv("GEMINI_CLI") == "1" {
37 return "gemini"
38 }
39 if os.Getenv("GOOSE_TERMINAL") == "1" {
40 return "goose"
41 }
42 if os.Getenv("JUNIE_SHIM_PATH") != "" {
43 return "junie"
44 }
45 // Kilo Code is an OpenCode fork and also sets OPENCODE=1.
46 if os.Getenv("KILO") == "1" {
47 return "kilo-code"
48 }
49 if os.Getenv("KIRO_CLI_IS_CHILD_PROCESS") == "1" {
50 return "kiro-cli"
51 }
52 // Set in the Kiro IDE agent's shell but not in the user's Kiro terminal.
53 if os.Getenv("KIRO_SESSION_ID") != "" {
54 return "kiro"
55 }
56 // Kiro CLI also sets this, so it is checked after Kiro.
57 if strings.Contains(os.Getenv("AWS_EXECUTION_ENV"), "AmazonQ-For-CLI") {
58 return "amazon-q"
59 }
60 if os.Getenv("OPENCODE") == "1" {
61 return "opencode"
62 }
63 if os.Getenv("QWEN_CODE") == "1" {
64 return "qwen-code"
65 }
66 // ROO_CLI_RUNTIME is the Roo CLI; ROO_ACTIVE is the VS Code extension's terminals.
67 if os.Getenv("ROO_CLI_RUNTIME") == "1" || os.Getenv("ROO_ACTIVE") == "true" {
68 return "roo-code"
69 }
70 // Set by Warp's Oz cloud agent runs to the run's ID.
71 if os.Getenv("OZ_RUN_ID") != "" {
72 return "warp"
73 }
74 // TERM_PROGRAM is a weaker signal: it fires for any command run in those IDE
75 // terminals, not only agent-driven invocations. The `-terminal` suffix lets
76 // analytics distinguish these from explicit agent env vars handled above,
77 // except for Zed's agent terminal, which its pager overrides identify.
78 switch strings.ToLower(os.Getenv("TERM_PROGRAM")) {
79 case "cursor":
80 return "cursor-terminal"
81 case "kiro":
82 return "kiro-terminal"
83 case "windsurf":
84 return "windsurf-terminal"
85 case "zed":
86 // Zed's agent terminal disables pagers; its user terminal does not.
87 if pager, ok := os.LookupEnv("PAGER"); ok && pager == "" && os.Getenv("GIT_PAGER") == "cat" {
88 return "zed"
89 }
90 return "zed-terminal"
91 }
92 return ""
93}
95// isBooleanWord reports whether v is a flag value, which names no agent.
96func isBooleanWord(v string) bool {
97 switch strings.ToLower(v) {
98 case "0", "1", "true", "false", "yes", "no":
99 return true
100 }
101 return false
102}
Diagnostics6 git calls · 336 ms
CallStatusSizeTime0336 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:02001.1 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=1165 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=71c8407e0ff0e0af10f6a041ae330f754b68e7eb git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1165 git.pkt.payload.max=1138 git.sideband.band1.bytes=1138 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1138 git.pack.trailer=61886367c69619d8db2b2cf2d7d24dca2016141cOpen pack map
fetch2001.4 KiB326 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=326 git.response.bytes=1403 git.response.cache=MISS git.response.duration_ms=326 git.fetch.wants=81dfbe6be94d8fba42c5e885df6fd3efce2e9562 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1403 git.pkt.payload.max=1376 git.sideband.band1.bytes=1376 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e11ffd6f5d7fd8
- Request
- 82780e73…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format