MCPcopy Index your code
hub / github.com/coder/coder / expandedAgentName

Function expandedAgentName

agent/agentcontainers/api.go:1123–1138  ·  view source on GitHub ↗

expandedAgentName creates an agent name by including parent directories from the workspace folder path to avoid name collisions. Like `safeAgentName`, the second returned value will be true if using the workspace folder name, and false if it fell back to the friendly name.

(workspaceFolder string, friendlyName string, depth int)

Source from the content-addressed store, hash-verified

1121// the second returned value will be true if using the workspace folder name,
1122// and false if it fell back to the friendly name.
1123func expandedAgentName(workspaceFolder string, friendlyName string, depth int) (string, bool) {
1124 var parts []string
1125 for part := range strings.SplitSeq(filepath.ToSlash(workspaceFolder), "/") {
1126 if part = strings.TrimSpace(part); part != "" {
1127 parts = append(parts, part)
1128 }
1129 }
1130 if len(parts) == 0 {
1131 return safeFriendlyName(friendlyName), false
1132 }
1133
1134 components := parts[max(0, len(parts)-depth-1):]
1135 expanded := strings.Join(components, "-")
1136
1137 return safeAgentName(expanded, friendlyName)
1138}
1139
1140// makeAgentName attempts to create an agent name. It will first attempt to create an
1141// agent name based off of the workspace folder, and will eventually fallback to a

Callers 3

makeAgentNameMethod · 0.85
TestExpandedAgentNameFunction · 0.85

Calls 2

safeFriendlyNameFunction · 0.85
safeAgentNameFunction · 0.85

Tested by 1

TestExpandedAgentNameFunction · 0.68