-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathinstall.go
More file actions
202 lines (174 loc) · 6.29 KB
/
install.go
File metadata and controls
202 lines (174 loc) · 6.29 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package aitools
import (
"context"
"errors"
"fmt"
"strings"
"github.com/charmbracelet/huh"
"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/installer"
"github.com/databricks/cli/libs/cmdio"
"github.com/spf13/cobra"
)
// Package-level for testability. Tests in this package override them via
// helpers in install_test.go.
var (
promptAgentSelection = defaultPromptAgentSelection
installSkillsForAgentsFn = installer.InstallSkillsForAgents
)
func defaultPromptAgentSelection(ctx context.Context, detected []*agents.Agent) ([]*agents.Agent, error) {
options := make([]huh.Option[string], 0, len(detected))
agentsByName := make(map[string]*agents.Agent, len(detected))
for _, a := range detected {
options = append(options, huh.NewOption(a.DisplayName, a.Name).Selected(true))
agentsByName[a.Name] = a
}
var selected []string
err := huh.NewMultiSelect[string]().
Title("Select coding agents to install skills for").
Description("space to toggle, enter to confirm").
Options(options...).
Value(&selected).
Run()
if err != nil {
return nil, err
}
if len(selected) == 0 {
return nil, errors.New("at least one agent must be selected")
}
result := make([]*agents.Agent, 0, len(selected))
for _, name := range selected {
result = append(result, agentsByName[name])
}
return result, nil
}
func NewInstallCmd() *cobra.Command {
var skillsFlag, agentsFlag, scopeFlag string
var includeExperimental bool
var projectFlag, globalFlag bool
cmd := &cobra.Command{
Use: "install",
Short: "Install AI skills for coding agents",
Long: `Install Databricks AI skills for detected coding agents.
By default, skills are installed globally to each agent's skills directory.
Use --scope=project to install to the current project directory instead.
When multiple agents are detected, skills are stored in a canonical location
and symlinked to each agent to avoid duplication.
Use --skills name1,name2 to install specific skills.
Agent selection:
--agents <name>[,<name>...] Install only for the named agents.
(unset, interactive) Multi-select prompt over detected agents.
(unset, non-interactive) Install for every detected agent.
The list of agents the command will act on is always logged to stderr before
the install runs, so callers can verify what was picked.
Supported agents: Claude Code, Cursor, Codex CLI, OpenCode, GitHub Copilot, Antigravity`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
projectFlag, globalFlag, err := parseScopeFlag(scopeFlag, projectFlag, globalFlag, false)
if err != nil {
return err
}
// Resolve scope.
scope, err := resolveScopeWithPrompt(ctx, projectFlag, globalFlag)
if err != nil {
return err
}
// Resolve target agents.
var targetAgents []*agents.Agent
if agentsFlag != "" {
targetAgents, err = resolveAgentNames(ctx, agentsFlag)
if err != nil {
return err
}
} else {
detected := agents.DetectInstalled(ctx)
if len(detected) == 0 {
printNoAgentsMessage(ctx)
return nil
}
// For project scope, pre-filter to compatible agents before prompting.
if scope == installer.ScopeProject {
detected = filterProjectScopeAgents(detected)
if len(detected) == 0 {
return errors.New("no detected agents support project-scoped skills")
}
}
switch {
case len(detected) == 1:
targetAgents = detected
case cmdio.IsPromptSupported(ctx):
targetAgents, err = promptAgentSelection(ctx, detected)
if err != nil {
return err
}
default:
targetAgents = detected
}
}
// Build install options.
opts := installer.InstallOptions{
IncludeExperimental: includeExperimental,
Scope: scope,
}
opts.SpecificSkills = splitAndTrim(skillsFlag)
installer.PrintInstallingFor(ctx, targetAgents)
src := &installer.GitHubManifestSource{}
return installSkillsForAgentsFn(ctx, src, targetAgents, opts)
},
}
cmd.Flags().StringVar(&skillsFlag, "skills", "", "Specific skills to install (comma-separated)")
cmd.Flags().StringVar(&agentsFlag, "agents", "", "Agents to install for (comma-separated, e.g. claude-code,cursor)")
cmd.Flags().BoolVar(&includeExperimental, "experimental", false, "Include experimental skills")
cmd.Flags().StringVar(&scopeFlag, "scope", "", "Install scope: project or global (default: global, or prompt when interactive)")
cmd.Flags().BoolVar(&projectFlag, "project", false, "Install to project directory (cwd)")
cmd.Flags().BoolVar(&globalFlag, "global", false, "Install globally (default)")
markScopeBoolsDeprecated(cmd)
return cmd
}
// resolveAgentNames parses a comma-separated list of agent names and validates
// them against the registry. Returns an error for unrecognized names.
func resolveAgentNames(ctx context.Context, names string) ([]*agents.Agent, error) {
available := make(map[string]*agents.Agent, len(agents.Registry))
var availableNames []string
for i := range agents.Registry {
a := &agents.Registry[i]
available[a.Name] = a
availableNames = append(availableNames, a.Name)
}
var result []*agents.Agent
seen := make(map[string]bool)
for name := range strings.SplitSeq(names, ",") {
name = strings.TrimSpace(name)
if name == "" || seen[name] {
continue
}
seen[name] = true
agent, ok := available[name]
if !ok {
return nil, fmt.Errorf("unknown agent %q. Available agents: %s", name, strings.Join(availableNames, ", "))
}
result = append(result, agent)
}
if len(result) == 0 {
return nil, errors.New("no agents specified")
}
return result, nil
}
// filterProjectScopeAgents returns only agents that support project-scoped skills.
func filterProjectScopeAgents(detected []*agents.Agent) []*agents.Agent {
var compatible []*agents.Agent
for _, a := range detected {
if a.SupportsProjectScope {
compatible = append(compatible, a)
}
}
return compatible
}
// printNoAgentsMessage prints the "no agents detected" message.
func printNoAgentsMessage(ctx context.Context) {
cmdio.LogString(ctx, cmdio.Yellow(ctx, "No supported coding agents detected."))
cmdio.LogString(ctx, "")
cmdio.LogString(ctx, "Supported agents: Claude Code, Cursor, Codex CLI, OpenCode, GitHub Copilot, Antigravity")
cmdio.LogString(ctx, "Please install at least one coding agent first.")
}