GitLabgitlab-org

cli

main
ply8 git calls342 ms99 KiB5 cachedprotocol v2
161 lines3.9 KiBRaw
1package get
3import (
4 "errors"
5 "fmt"
6 "sort"
7 "strings"
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/bundled"
14 "gitlab.com/gitlab-org/cli/internal/commands/skills/skill"
15 "gitlab.com/gitlab-org/cli/internal/iostreams"
16 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17 "gitlab.com/gitlab-org/cli/internal/text"
20type options struct {
21 io *iostreams.IOStreams
22 getSkill func(string) (skill.Skill, error)
23 allSkills func() ([]skill.Skill, error)
25 name string
26 filePath string
29func NewCmd(f cmdutils.Factory) *cobra.Command {
30 return newCmd(f, bundled.Get, bundled.All)
33func newCmd(
34 f cmdutils.Factory,
35 getSkill func(string) (skill.Skill, error),
36 allSkills func() ([]skill.Skill, error),
37) *cobra.Command {
38 opts := &options{
39 io: f.IO(),
40 getSkill: getSkill,
41 allSkills: allSkills,
42 }
44 cmd := &cobra.Command{
45 Use: "get <name> [<path>]",
46 Short: "Print a bundled agent skill file. (EXPERIMENTAL)",
47 Long: heredoc.Docf(`
48 Print a file from an agent skill bundled with this glab binary without installing it.
50 The path is relative to the skill root and defaults to %[1]sSKILL.md%[1]s.
51 `, "`") + text.ExperimentalString,
52 Example: heredoc.Doc(`
53 # Print the manifest for the bundled glab skill
54 glab skills get glab
56 # Print the other bundled skill
57 glab skills get glab-stack
59 # For skills that ship supporting files, use the path form
60 # glab skills get <name> references/<file>.md
61 `),
62 Args: cobra.MaximumNArgs(2),
63 Annotations: map[string]string{
64 mcpannotations.Safe: "true",
65 },
66 RunE: func(cmd *cobra.Command, args []string) error {
67 opts.complete(args)
68 if err := opts.validate(); err != nil {
69 return err
70 }
71 return opts.run()
72 },
73 }
75 return cmd
78func (o *options) complete(args []string) {
79 if len(args) > 0 {
80 o.name = args[0]
81 }
82 o.filePath = skill.FileName
83 if len(args) > 1 {
84 o.filePath = args[1]
85 }
88func (o *options) validate() error {
89 if o.name != "" {
90 return nil
91 }
92 names, err := o.bundledSkillNames()
93 if err != nil {
94 return err
95 }
96 return fmt.Errorf("skill name is required; available bundled skills: %s", strings.Join(names, ", "))
99func (o *options) run() error {
100 s, err := o.getSkill(o.name)
101 if err != nil {
102 if !errors.Is(err, bundled.ErrNotFound) {
103 return err
104 }
105 names, listErr := o.bundledSkillNames()
106 if listErr != nil {
107 return listErr
108 }
109 return fmt.Errorf("unknown skill %q; only bundled skills can be printed (available: %s), and remote skills from 'glab skills list' can be installed with 'glab skills install <name>'", o.name, strings.Join(names, ", "))
110 }
112 files := sortedFileNames(s.Files)
113 content, ok := s.Files[o.filePath]
114 if !ok {
115 return fmt.Errorf("unknown path %q for bundled skill %q; available files: %s", o.filePath, o.name, strings.Join(files, ", "))
116 }
117 if o.filePath == skill.FileName {
118 for _, file := range files {
119 if file == skill.FileName {
120 continue
121 }
122 content = appendManifestFooter(content, s.Name)
123 break
124 }
125 }
127 if err := o.io.StartPager(); err != nil {
128 return err
129 }
130 defer o.io.StopPager()
132 _, err = o.io.StdOut.Write(content)
133 return err
136func (o *options) bundledSkillNames() ([]string, error) {
137 skills, err := o.allSkills()
138 if err != nil {
139 return nil, err
140 }
141 names := make([]string, len(skills))
142 for i, s := range skills {
143 names[i] = s.Name
144 }
145 sort.Strings(names)
146 return names, nil
149func sortedFileNames(files map[string][]byte) []string {
150 names := make([]string, 0, len(files))
151 for name := range files {
152 names = append(names, name)
153 }
154 sort.Strings(names)
155 return names
158func appendManifestFooter(content []byte, name string) []byte {
159 footer := fmt.Sprintf("\n\n---\n\nYou are viewing this via `glab`; the links above are relative to the on-disk skill tree. Fetch referenced files with `glab skills get %s <path>`.\n", name)
160 return append(append([]byte(nil), content...), footer...)
Diagnostics8 git calls · 342 ms
CallStatusSizeTime0342 ms
discover200185 B3 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 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 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=2
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: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=2
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
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:0200134 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=329
git.response.bytes=134
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=7000abd6d60488755d722ac33013da7d82691672
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=134
git.pkt.payload.max=107
git.sideband.band1.bytes=107
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=107
git.pack.trailer=d73c332613bf5e79dd341d7d24aeb952a14e0d50
Open pack map
fetch2001.6 KiB329 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1614
git.response.cache=MISS
git.response.duration_ms=329
git.fetch.wants=50e49f9ac29176c7d9f9f6ecf59267511022d919
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=1614
git.pkt.payload.max=1587
git.sideband.band1.bytes=1587
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
a5e2e94688bdecfa
Request
14430a2e…
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