Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions useragent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func listKnownAgents() []knownAgent {
{envVar: "CLINE_ACTIVE", product: "cline"}, // https://github.com/cline/cline (v3.24.0+)
{envVar: "CODEX_CI", product: "codex"}, // https://github.com/openai/codex
{envVar: "COPILOT_CLI", product: "copilot-cli"}, // https://github.com/features/copilot
{envVar: "COPILOT_MODEL", product: "copilot-vscode"}, // VS Code Copilot terminal, best-effort heuristic, not officially identified
{envVar: "CURSOR_AGENT", product: "cursor"}, // Closed source
{envVar: "GEMINI_CLI", product: "gemini-cli"}, // https://google-gemini.github.io/gemini-cli
{envVar: "GOOSE_TERMINAL", product: "goose"}, // https://block.github.io/goose/ (also sets AGENT=goose, handled by the central fallback in lookupAgentProvider)
{envVar: "KIRO", product: "kiro"}, // https://kiro.dev/ (Amazon)
{envVar: "OPENCLAW_SHELL", product: "openclaw"}, // https://github.com/anthropics/openclaw
{envVar: "OPENCODE", product: "opencode"}, // https://github.com/opencode-ai/opencode
{envVar: "VSCODE_AGENT", product: "vscode-agent"}, // Set by VS Code 1.121+ for agent-initiated terminal commands (https://code.visualstudio.com/updates/v1_121)
{envVar: "WINDSURF_AGENT", product: "windsurf"}, // https://codeium.com/windsurf (Codeium)
}
}
Expand Down Expand Up @@ -75,11 +75,6 @@ func lookupAgentProvider() string {
}
}

// Known BYOK false positive: Copilot CLI users often set COPILOT_MODEL
// alongside COPILOT_CLI. That is a single copilot-cli signal, not a
// stacked multi-agent setup, so drop the copilot-vscode match.
matches = collapseCopilotBYOK(matches)

switch len(matches) {
case 1:
return matches[0]
Expand All @@ -90,29 +85,6 @@ func lookupAgentProvider() string {
}
}

func collapseCopilotBYOK(matches []string) []string {
hasCLI, hasVSCode := false, false
for _, m := range matches {
if m == "copilot-cli" {
hasCLI = true
}
if m == "copilot-vscode" {
hasVSCode = true
}
}
if !hasCLI || !hasVSCode {
return matches
}
filtered := make([]string, 0, len(matches)-1)
for _, m := range matches {
if m == "copilot-vscode" {
continue
}
filtered = append(filtered, m)
}
return filtered
}

// agentEnvFallback returns a sanitized, length-capped name from AGENT
// or AI_AGENT, preferring AGENT when both are non-empty. The value is
// passed through rather than categorized so that new names are propagated
Expand Down
20 changes: 7 additions & 13 deletions useragent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func TestLookupAgentProvider(t *testing.T) {
expect: "augment",
},
{
name: "copilot vscode",
envs: map[string]string{"COPILOT_MODEL": "gpt-4"},
expect: "copilot-vscode",
name: "vscode-agent",
envs: map[string]string{"VSCODE_AGENT": "1"},
expect: "vscode-agent",
},
{
name: "kiro",
Expand Down Expand Up @@ -176,17 +176,11 @@ func TestLookupAgentProvider(t *testing.T) {
envs: map[string]string{"GOOSE_TERMINAL": "1", "AGENT": "cursor"},
expect: "goose",
},
// Known BYOK false positive: Copilot CLI users often set COPILOT_MODEL
// alongside COPILOT_CLI. The pair is treated as a single copilot-cli
// signal rather than a stacked multi-agent setup.
// VSCODE_AGENT can legitimately stack with other agents (e.g. running
// Copilot CLI from a VS Code agent terminal).
{
name: "COPILOT_CLI + COPILOT_MODEL collapses to copilot-cli (BYOK)",
envs: map[string]string{"COPILOT_CLI": "1", "COPILOT_MODEL": "gpt-4"},
expect: "copilot-cli",
},
{
name: "COPILOT_CLI + COPILOT_MODEL + CLAUDECODE still reports multiple after BYOK collapse",
envs: map[string]string{"COPILOT_CLI": "1", "COPILOT_MODEL": "gpt-4", "CLAUDECODE": "1"},
name: "VSCODE_AGENT + COPILOT_CLI reports multiple",
envs: map[string]string{"VSCODE_AGENT": "1", "COPILOT_CLI": "1"},
expect: "multiple",
},
// AI_AGENT fallback (Vercel @vercel/detect-agent convention).
Expand Down
Loading