library: a pasted "npx skills add owner/repo --skill x" reads as its repo
The skills page's add field now takes the command a skills page offers
to copy (npx, bunx, pnpx, pnpm or yarn dlx, bun x, with -y, --skill and
--agent flags) and installs from the repository it names (RockyShowlle
on X). Anything else is used as typed.
Run at base 78827954f with both changes:
- Full suite: go test -p 2 -tags nogui -count=1 -timeout 45m ./... ok in 66 packages, no FAIL.
- gofmt -l is clean, and go vet passes for GOOS=linux and GOOS=windows.
- Broken by hand: with the change disabled, TestPastedRepoBindsSameCopy and TestSkillsCommand are red. Restored, they are green.
- Not tried: a real npx skills install, or a real repo paste in the GUI.
This commit is contained in:
@@ -1011,6 +1011,42 @@ func TestGitHubSource(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A skills CLI command pasted whole installs from its source
|
||||
// (RockyShowlle on X: the npx line a skill's page gives), whatever runs
|
||||
// it and wherever its flags are; anything else is left as it is.
|
||||
func TestSkillsCommand(t *testing.T) {
|
||||
for in, want := range map[string]string{
|
||||
"npx skills add vercel-labs/agent-skills": "vercel-labs/agent-skills",
|
||||
" npx -y skills@latest add owner/repo --skill pdf ": "owner/repo",
|
||||
"npx skills add --skill pdf -a claude-code owner/repo": "owner/repo",
|
||||
"bunx skills add https://github.com/o/r/tree/main/skills/pdf": "https://github.com/o/r/tree/main/skills/pdf",
|
||||
"pnpm dlx skills add o/r": "o/r",
|
||||
"bun x skills add o/r -y": "o/r",
|
||||
"owner/repo": "owner/repo",
|
||||
"npx skills find pdf": "npx skills find pdf",
|
||||
"npx other add o/r": "npx other add o/r",
|
||||
"npx skills add --skill pdf": "npx skills add --skill pdf",
|
||||
"~/skills/pdf": "~/skills/pdf",
|
||||
} {
|
||||
if got := skillsCommand(in); got != want {
|
||||
t.Errorf("%q: %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
sandbox(t)
|
||||
newFakeGitHub(t)
|
||||
p, err := ProbeSkills("npx skills add someone/cli --skill pdf")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Kind != "github" || p.Source != "someone/cli" || len(p.Candidates) != 1 || p.Candidates[0].Name != "pdf" {
|
||||
t.Fatalf("probe: %+v", p)
|
||||
}
|
||||
ok(t)(InstallSkills("npx skills add someone/cli --skill pdf", []string{p.Candidates[0].Path}, nil))
|
||||
if l := mustLoad(t); l.skill("pdf") == nil || l.skill("pdf").Source.Repo != "someone/cli" {
|
||||
t.Fatalf("installed: %+v", l.skill("pdf"))
|
||||
}
|
||||
}
|
||||
|
||||
// A server or skill on no agent is listed with none, not null: the page
|
||||
// looks in the list, and a null blanked the whole Library.
|
||||
func TestReadNoAgents(t *testing.T) {
|
||||
|
||||
@@ -960,10 +960,44 @@ func unhiddenFirst[T any](list []T, path func(T) string, same func(a, b T) bool)
|
||||
return out
|
||||
}
|
||||
|
||||
// skillsCommand is the source a skills CLI command copied from a page
|
||||
// installs from (RockyShowlle on X): "npx skills add owner/repo --skill
|
||||
// x", run through npx, bunx, pnpm dlx and the like. Anything else is
|
||||
// given back as it is.
|
||||
func skillsCommand(input string) string {
|
||||
f := strings.Fields(strings.TrimSpace(input))
|
||||
i := 0
|
||||
switch {
|
||||
case len(f) > 1 && (f[0] == "npx" || f[0] == "bunx" || f[0] == "pnpx"):
|
||||
i = 1
|
||||
case len(f) > 2 && ((f[0] == "pnpm" || f[0] == "yarn") && f[1] == "dlx" || f[0] == "bun" && f[1] == "x"):
|
||||
i = 2
|
||||
default:
|
||||
return input
|
||||
}
|
||||
for i < len(f) && strings.HasPrefix(f[i], "-") { // npx -y
|
||||
i++
|
||||
}
|
||||
if i+1 >= len(f) || (f[i] != "skills" && !strings.HasPrefix(f[i], "skills@")) || f[i+1] != "add" {
|
||||
return input
|
||||
}
|
||||
for i += 2; i < len(f); i++ {
|
||||
switch a := f[i]; {
|
||||
case a == "--skill" || a == "-s" || a == "--agent" || a == "-a":
|
||||
i++ // and its value
|
||||
case strings.HasPrefix(a, "-"):
|
||||
default:
|
||||
return a
|
||||
}
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
// ProbeSkills looks for skills at what the user typed: a GitHub repository
|
||||
// (or a folder in one), or a folder on this machine.
|
||||
// (or a folder in one), a folder on this machine, or a skills CLI command
|
||||
// for either.
|
||||
func ProbeSkills(input string) (*Probe, error) {
|
||||
input = strings.TrimSpace(input)
|
||||
input = strings.TrimSpace(skillsCommand(input))
|
||||
if input == "" {
|
||||
return nil, fmt.Errorf("paste a GitHub link or a folder's path")
|
||||
}
|
||||
@@ -1007,7 +1041,7 @@ func ProbeSkills(input string) (*Probe, error) {
|
||||
|
||||
func cachedProbe(input string) (*Probe, error) {
|
||||
probes.Lock()
|
||||
e := probes.m[strings.TrimSpace(input)]
|
||||
e := probes.m[strings.TrimSpace(skillsCommand(input))]
|
||||
probes.Unlock()
|
||||
if e != nil {
|
||||
if _, err := os.Stat(e.tmp); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user