-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathagent_util.go
More file actions
53 lines (45 loc) · 1.36 KB
/
Copy pathagent_util.go
File metadata and controls
53 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"strings"
)
// ParseAgentString handles all agent string formats:
// - +name (built-in or user agent by name)
// - name (without + prefix, treated as agent name)
// - /path/to/agent.toml (direct file path)
// - builtin:name (builtin agent specification)
//
// Returns agentName and agentPath. If the input is a direct path,
// agentName will be empty.
func ParseAgentString(input string) (agentName, agentPath string) {
// Handle +agent syntax
if strings.HasPrefix(input, "+") {
agentName = input[1:] // Remove + prefix
// Check for builtin agents first
if _, exists := builtinAgents[agentName]; exists {
agentPath = "builtin:" + agentName
return
}
// Otherwise treat as user agent name
agentPath = expandHomePath(fmt.Sprintf("%s/%s.toml", DefaultAgentsDir, agentName))
return
}
// Handle direct path (contains / or ends with .toml)
if strings.Contains(input, "/") || strings.HasSuffix(input, ".toml") {
agentPath = input
if !strings.HasPrefix(agentPath, "/") {
agentPath = expandHomePath(agentPath)
}
return
}
// Handle plain name without + prefix
agentName = input
// Check for builtin agents
if _, exists := builtinAgents[agentName]; exists {
agentPath = "builtin:" + agentName
return
}
// Treat as user agent name
agentPath = expandHomePath(fmt.Sprintf("%s/%s.toml", DefaultAgentsDir, agentName))
return
}