GitLabgitlab-org

cli

main
ply8 git calls342 ms99 KiB6 cachedprotocol v2
188 lines5.3 KiBRaw
1package install
3import (
4 "errors"
5 "fmt"
6 "os"
7 "path/filepath"
9 "github.com/MakeNowJust/heredoc/v2"
10 "github.com/spf13/cobra"
12 "gitlab.com/gitlab-org/cli/internal/cmdutils"
13 "gitlab.com/gitlab-org/cli/internal/commands/skills/registry"
14 "gitlab.com/gitlab-org/cli/internal/commands/skills/skill"
15 "gitlab.com/gitlab-org/cli/internal/git"
16 "gitlab.com/gitlab-org/cli/internal/iostreams"
17 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
18 "gitlab.com/gitlab-org/cli/internal/text"
21// skillsRelDir is the conventional directory for agent skills,
22// as defined by the Agent Skills specification (https://agentskills.io).
23var skillsRelDir = filepath.Join(".agents", "skills")
25// defaultSkillName is the skill installed when no positional argument
26// is given. Keeping the default to the single core `glab` skill
27// avoids polluting an agent's context with descriptions of bundled
28// skills the user may not need.
29const defaultSkillName = "glab"
31type options struct {
32 io *iostreams.IOStreams
33 global bool
34 path string
35 force bool
36 requested string
37 targetDir string
40func NewCmdInstall(f cmdutils.Factory) *cobra.Command {
41 opts := &options{
42 io: f.IO(),
43 }
45 cmd := &cobra.Command{
46 Use: "install [name]",
47 Short: "Install glab's bundled agent skills. (EXPERIMENTAL)",
48 Long: heredoc.Docf(`
49 Install bundled %[1]sSKILL.md%[1]s files to %[1]s.agents/skills/%[1]s, the
50 cross-agent standard defined by the Agent Skills specification. This works
51 with GitLab Duo Agent Platform, Claude Code, Codex, Gemini CLI, and any
52 other compliant agent.
54 By default, only the core %[1]sglab%[1]s skill is installed. Pass a positional
55 %[1]sname%[1]s argument to install a specific bundled skill instead. Run
56 %[1]sglab skills list%[1]s to see what is available.
58 Install scope:
60 - By default, skills are installed for the current project, in %[1]s.agents/skills/%[1]s
61 at the root of the current Git repository.
62 - Use %[1]s--global%[1]s to install skills for the current user, in
63 %[1]s~/.agents/skills/%[1]s.
64 - Use %[1]s--path%[1]s to install skills to a custom directory. The path is resolved
65 relative to the current working directory, not the repository root.
67 To overwrite an existing skill file, use %[1]s--force%[1]s.
68 `, "`") + text.ExperimentalString,
69 Example: heredoc.Doc(`
70 # Install the core glab skill in the current project (default)
71 glab skills install
73 # Install a specific bundled skill by name
74 glab skills install glab-stack
76 # Install the core skill globally (user scope)
77 glab skills install --global
79 # Install a skill to a custom directory
80 glab skills install glab-stack --path /path/to/skills
82 # Overwrite an existing skill file
83 glab skills install --force
84 `),
85 Args: cobra.MaximumNArgs(1),
86 Annotations: map[string]string{
87 mcpannotations.Destructive: "true",
88 },
89 RunE: func(cmd *cobra.Command, args []string) error {
90 if err := opts.complete(args); err != nil {
91 return err
92 }
93 return opts.run()
94 },
95 }
97 fl := cmd.Flags()
98 fl.BoolVarP(&opts.global, "global", "g", false, "Install skills at user scope (~/.agents/skills/).")
99 fl.StringVar(&opts.path, "path", "", "Install skills to the directory at <path>.")
100 fl.BoolVarP(&opts.force, "force", "f", false, "Overwrite existing skill files.")
101 cmd.MarkFlagsMutuallyExclusive("global", "path")
103 return cmd
106func (o *options) complete(args []string) error {
107 if len(args) == 1 {
108 o.requested = args[0]
109 }
111 if o.path != "" {
112 o.targetDir = o.path
113 return nil
114 }
116 if o.global {
117 home, err := os.UserHomeDir()
118 if err != nil {
119 return fmt.Errorf("could not determine home directory: %w", err)
120 }
121 o.targetDir = filepath.Join(home, skillsRelDir)
122 return nil
123 }
125 repoRoot, err := git.ToplevelDir()
126 if err != nil {
127 return fmt.Errorf("not in a Git repository. Use --global or --path to specify a target: %w", err)
128 }
129 o.targetDir = filepath.Join(repoRoot, skillsRelDir)
130 return nil
133func (o *options) run() error {
134 skills, err := o.resolveSkills()
135 if err != nil {
136 return err
137 }
139 var errs []error
140 for _, s := range skills {
141 if err := o.installOne(s); err != nil {
142 errs = append(errs, err)
143 }
144 }
145 return errors.Join(errs...)
148func (o *options) resolveSkills() ([]skill.Skill, error) {
149 name := o.requested
150 if name == "" {
151 name = defaultSkillName
152 }
153 s, err := registry.Get(name)
154 if err != nil {
155 return nil, err
156 }
157 return []skill.Skill{s}, nil
160func (o *options) installOne(s skill.Skill) error {
161 skillDir := filepath.Join(o.targetDir, s.Name)
162 skillMDPath := filepath.Join(skillDir, skill.FileName)
163 _, statErr := os.Stat(skillMDPath)
164 exists := statErr == nil
166 c := o.io.Color()
167 if exists && !o.force {
168 o.io.LogErrorf("%s %s already exists. Use --force to overwrite.\n", c.WarnIcon(), skillMDPath)
169 return nil
170 }
172 for rel, content := range s.Files {
173 destPath := filepath.Join(skillDir, filepath.FromSlash(rel))
174 if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
175 return fmt.Errorf("creating directory for %s: %w", destPath, err)
176 }
177 if err := os.WriteFile(destPath, content, 0o644); err != nil {
178 return fmt.Errorf("writing %s: %w", destPath, err)
179 }
180 }
182 if exists {
183 o.io.LogInfof("%s Overwrote %s\n", c.GreenCheck(), skillDir)
184 } else {
185 o.io.LogInfof("%s Installed %s\n", c.GreenCheck(), skillDir)
186 }
187 return nil
Diagnostics8 git calls · 342 ms
CallStatusSizeTime0342 ms
discover200185 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:02001.8 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200370 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=370
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=290ae7a62f76e23cbbd60697570f19b90ddcece6
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=370
git.pkt.payload.max=343
git.sideband.band1.bytes=343
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=343
git.pack.trailer=0795a26d2b25022c69da2ef2e68cfb92a77ef4bb
Open pack map
fetchtree:0200138 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=327
git.response.bytes=138
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=18b12de8710078c4768dfa464446990cb36bac1c
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=138
git.pkt.payload.max=111
git.sideband.band1.bytes=111
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=111
git.pack.trailer=f412c8fc7c405fded327f13a7b6b0effe29f99d4
Open pack map
fetch2002.1 KiB327 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2103
git.response.cache=MISS
git.response.duration_ms=327
git.fetch.wants=e7ed2dfb5e00f165db645ec52b792a5716e533ab
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2103
git.pkt.payload.max=2076
git.sideband.band1.bytes=2076
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2e0e94ac44af4
Request
2a8d195a…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format