-
Notifications
You must be signed in to change notification settings - Fork 31
feat: log AI coding agents in user-agent, telemetry, and tracing #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9646902
e172f13
ce067b0
4251b27
61ead39
dfb062c
eedcf9d
96cd3e3
5bd7a8c
082c836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ type EventData struct { | |
|
|
||
| // EventContext contains information / metadata about the CLI session | ||
| type EventContext struct { | ||
| AIAgent string `json:"ai_agent,omitempty"` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: I chose |
||
| Arch string `json:"arch"` | ||
| Binary string `json:"bin"` | ||
| CLIVersion string `json:"cli_version"` | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| // Copyright 2022-2026 Salesforce, Inc. | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
| package useragent | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "runtime" | ||||||
| "strings" | ||||||
| ) | ||||||
|
|
||||||
| // AIAgent represents a detected AI coding agent that invoked the CLI. | ||||||
| type AIAgent struct { | ||||||
| Name string | ||||||
| Entry string | ||||||
| } | ||||||
|
|
||||||
| // Detect checks environment variables to determine if the CLI is being run by | ||||||
| // an AI coding agent. Returns nil if no agent is detected. Detection priority: | ||||||
| // CLAUDECODE > CODEX_CI > GEMINI_CLI > CLINE_ACTIVE > CURSOR_AGENT > AGENT. | ||||||
| func Detect() *AIAgent { | ||||||
| switch { | ||||||
| case os.Getenv("CLAUDECODE") == "1": | ||||||
| return &AIAgent{ | ||||||
| Name: "claude-code", | ||||||
| Entry: os.Getenv("CLAUDE_CODE_ENTRYPOINT"), | ||||||
| } | ||||||
| case os.Getenv("CODEX_CI") == "1": | ||||||
| return &AIAgent{Name: "codex"} | ||||||
| case os.Getenv("GEMINI_CLI") == "1": | ||||||
| return &AIAgent{Name: "gemini-cli"} | ||||||
| case os.Getenv("CLINE_ACTIVE") == "true": | ||||||
| return &AIAgent{Name: "cline"} | ||||||
| case os.Getenv("CURSOR_AGENT") == "1": | ||||||
| return &AIAgent{Name: "cursor"} | ||||||
| case os.Getenv("AGENT") != "": | ||||||
| return &AIAgent{Name: os.Getenv("AGENT")} | ||||||
| default: | ||||||
| return nil | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // DetectName returns the normalized name of the detected AI agent, or an empty | ||||||
| // string if no agent is detected. | ||||||
| func DetectName() string { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
🪬 question: Forgive these words but this is an unusual export for the value found I think but I also admit to not being so familiar with practices encouraged here!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌃 ramble: It does seem solid if we're framing this as the... actual user agent though? I'm understanding more I hope! |
||||||
| if agent := Detect(); agent != nil { | ||||||
| return agent.Name | ||||||
| } | ||||||
| return "" | ||||||
| } | ||||||
|
|
||||||
| // BuildUserAgent constructs the HTTP User-Agent header value for the CLI. If an | ||||||
| // AI agent is detected, an "AI-Agent (name=..., entry=...)" suffix is appended. | ||||||
|
Comment on lines
+64
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📚 quibble: It'd be helpful to have a full example here but no blocker! |
||||||
| func BuildUserAgent(cliVersion string) string { | ||||||
| ua := fmt.Sprintf("slack-cli/%s (os: %s)", cliVersion, runtime.GOOS) | ||||||
| if agent := Detect(); agent != nil { | ||||||
| var parts []string | ||||||
| parts = append(parts, "name="+agent.Name) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
☎️ question: A ":" separator might match the |
||||||
| if agent.Entry != "" { | ||||||
| parts = append(parts, "entry="+agent.Entry) | ||||||
| } | ||||||
| ua += " AI-Agent (" + strings.Join(parts, ", ") + ")" | ||||||
| } | ||||||
| return ua | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This is a new addition to our verbose logs. For a while, I've wanted to see our user-agent which is used for each API request. This may also be helpful when diagnosing user reported issues.