library: a grouped git repository's skills go in under their own names
Refeccd on X (0.1.4209, macOS): skills from a git repository that keeps
them in groups (writing/blog, coding/review) went into the Library with
the repository owner's name added (blog-team), though they were the
Library's own blog and review.
Two causes:
- followsHere and the same-files link in installFrom gated on GitHub
only. Added from a git repository on another host, a skill the
Library already traced to it (From, the skills CLI's lock, a checkout)
wasn't linked; it went in beside itself as name-owner. Both now take
any remote source, matched by tracedTo (owner/repo for GitHub,
host/path or the address for git), and linkSkill records the git
commit it was fetched at.
- A skill the repository moved into a group folder (same repo, same
name, new path, old path gone from the fetched tree) was taken for
another skill. movedIn now finds it as had: the probe says Have and
the install repaths it instead of adding name-owner.
Where one repository really has two skills by one name (installed from
two subfolders), the second takes its group's name (notes-coding,
besideName), which tells them apart; the owner, the same for both, never
did.
Skills already suffixed: on the next change of the Library, foldBeside
puts a name-owner copy back under its name when the skill by that name
is traced to the copy's repository, or is from that repository's old
folder and found gone. The skill keeps its name and agents and takes the
copy's files, source and agents; its own files and the copy go to the
backups. A copy beside a skill from elsewhere stays as it is
(TestSkillBesideAnotherStays).
Not changed: noteFrom and RegroupSkills still group with GitHub only
(#6710). The "folder in the way" case still uses the owner suffix.
Run (mote, at 142994b21 + this commit, the pushed head):
- new tests in skill_group_suffix_test.go red on the old code:
TestGitRepoLinksTracedSkills (blog-003/review-003),
TestGitRepoSkillMovedIntoGroup, TestSameNameInAnotherGroup...
(notes-003), TestSkillBesideItselfFoldsBack (2 skills); green now.
- broken by hand: movedIn returning false turns
TestGitRepoSkillMovedIntoGroup red.
- go test -timeout 45m ./...: exit 0, every package ok (library 380s,
gateway 976s). gofmt -l clean. GOOS=windows go vet ./... ok;
GOOS=linux go vet ./internal/library ok (the whole tree's linux vet
stops in wails' cgo files on a Mac, as on main).
- GUI: no file touched; the change is in the Go library package and the
GUI tests mock /api, so none was run.
Not tried: a real self-hosted GitLab repository; the fixtures are bare
git repositories served over file://.
This commit is contained in:
@@ -384,6 +384,7 @@ func changeLocked(f func(l *Library) error) (*Result, error) {
|
||||
if err := f(l); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.foldBeside() // a skill that went in beside itself (skill_beside.go)
|
||||
l.settleAway()
|
||||
l.heal() // a server f brought in, from another computer too
|
||||
if err := l.save(); err != nil {
|
||||
|
||||
@@ -5,8 +5,11 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
slash "path" // a repository's paths, always with /
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Two skills from different places can go by one name: anthropics/skills'
|
||||
@@ -30,9 +33,47 @@ func (l *Library) hadSkill(src Source, c Candidate, from string) *Skill {
|
||||
if s := l.skill(c.Name); s != nil && s.Source == nil && sameTree(skillDir(s.Name), from) {
|
||||
return s
|
||||
}
|
||||
if s := l.skill(c.Name); s != nil && movedIn(s, src, c, from) {
|
||||
return s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// movedIn is whether the library's skill s, by the name of the one at
|
||||
// from, is that skill moved to another folder of its repository: the
|
||||
// repository put its skills in groups since (skills/pdf to
|
||||
// skills/documents/pdf), and its old folder isn't there any more. Taken
|
||||
// for another skill, it went in beside itself under its owner's name
|
||||
// (Refeccd on X).
|
||||
func movedIn(s *Skill, src Source, c Candidate, from string) bool {
|
||||
if !sameRepo(s.Source, src) || s.Called != "" || s.Source.Path == c.Path {
|
||||
return false
|
||||
}
|
||||
// only a folder the fetch had: one fetched as far as src.Path holds
|
||||
// nothing of the rest of the repository
|
||||
if src.Path != "" && s.Source.Path != src.Path && !strings.HasPrefix(s.Source.Path, src.Path+"/") {
|
||||
return false
|
||||
}
|
||||
return goneFrom(repoRoot(from, c.Path), s.Source.Path)
|
||||
}
|
||||
|
||||
// besideName is the name the skill at path of src goes in beside the
|
||||
// library's skill called name by. One from another folder of the same
|
||||
// repository takes that folder's name, which tells the two apart, where
|
||||
// the owner both have would not (skills/writing/blog beside
|
||||
// skills/coding/blog is blog-writing); one from elsewhere takes its
|
||||
// source's (freeSkillName).
|
||||
func (l *Library) besideName(name string, src Source, path string) string {
|
||||
if s := l.skill(name); s != nil && sameRepo(s.Source, src) {
|
||||
if dir := slash.Dir(path); dir != "." && dir != "" {
|
||||
if n := withSuffix(name, slash.Base(dir)); n != "" && !l.skillNameTaken(n) {
|
||||
return n
|
||||
}
|
||||
}
|
||||
}
|
||||
return l.freeSkillName(name, src)
|
||||
}
|
||||
|
||||
// skillNameTaken is whether the library has a skill called name, or its
|
||||
// folder has something by that name. One that can't be looked at is
|
||||
// taken: what is there is unknown.
|
||||
@@ -185,3 +226,77 @@ func (s *Skill) fetchedHash(from string) string {
|
||||
}
|
||||
return hashDir(dir)
|
||||
}
|
||||
|
||||
// foldBeside puts back together a skill that went in beside itself
|
||||
// (Refeccd on X): installed from a repository the library's skill by its
|
||||
// name was traced to, or moved into a group of, it was taken for another
|
||||
// skill and kept as name-owner. The skill by the name it was called keeps
|
||||
// its name and takes the copy's files, source and agents, its own files
|
||||
// going to the backups when they differ (linkSkill); the copy, by then
|
||||
// the same, goes to the backups too. A skill kept beside one from
|
||||
// elsewhere, which was right, stays as it is. It gives the names it put
|
||||
// back together.
|
||||
func (l *Library) foldBeside() []string {
|
||||
var folded []string
|
||||
tr := &tracer{}
|
||||
for _, s := range slices.Clone(l.Skills) {
|
||||
if s.Called == "" || s.Called == s.Name || !s.Source.remote() {
|
||||
continue
|
||||
}
|
||||
t := l.skill(s.Called)
|
||||
if t == nil || t.Called != "" {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case !t.Source.remote():
|
||||
// the library's own, traced to that repository
|
||||
if r := tr.repoOf(t); r == "" || !tracedTo(r, *s.Source) {
|
||||
continue
|
||||
}
|
||||
case sameRepo(t.Source, *s.Source):
|
||||
// from another folder of that repository, which a check found
|
||||
// it no longer has: moved into a group there
|
||||
if t.Gone == "" || t.Source.Path == s.Source.Path {
|
||||
continue
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if err := l.foldInto(t, s); err != nil {
|
||||
continue
|
||||
}
|
||||
folded = append(folded, t.Name)
|
||||
}
|
||||
return folded
|
||||
}
|
||||
|
||||
// foldInto is foldBeside for t, the skill by the name s was called.
|
||||
func (l *Library) foldInto(t, s *Skill) error {
|
||||
// s's files, named as t is
|
||||
tmp := skillDir("." + t.Name + ".fold")
|
||||
os.RemoveAll(tmp)
|
||||
defer os.RemoveAll(tmp)
|
||||
if err := copyDir(skillDir(s.Name), tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := nameSkill(tmp, t.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
src, commit := *s.Source, s.Commit
|
||||
if _, err := l.linkSkill(t, src, src.Path, tmp, s.Agents); err != nil {
|
||||
return err
|
||||
}
|
||||
if t.Commit == "" {
|
||||
t.Commit = commit
|
||||
}
|
||||
t.Gone = ""
|
||||
for _, p := range l.Projects {
|
||||
if agents, ok := p.Skills[s.Name]; ok {
|
||||
if p.Skills[t.Name] == nil {
|
||||
p.Skills[t.Name] = agents
|
||||
}
|
||||
delete(p.Skills, s.Name)
|
||||
}
|
||||
}
|
||||
return removeSkill(l, s.Name, time.Now().Format("2006-01-02_15-04-05.000"))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Refeccd on X: skills in a git repository kept in groups
|
||||
// (writing/blog, coding/review) went into the library with the
|
||||
// repository's owner added to their names, though the library's skills by
|
||||
// those names were those very skills.
|
||||
|
||||
// groupedRepo is a git repository with its skills in groups.
|
||||
func groupedRepo(t *testing.T) (string, func(map[string]string)) {
|
||||
return gitRepo(t, map[string]string{
|
||||
"writing/blog/SKILL.md": "---\nname: blog\ndescription: Write blog posts\n---\nv2\n",
|
||||
"writing/poem/SKILL.md": "---\nname: poem\ndescription: Write poems\n---\nv2\n",
|
||||
"coding/review/SKILL.md": "---\nname: review\ndescription: Review code\n---\nv2\n",
|
||||
})
|
||||
}
|
||||
|
||||
// noSuffix fails when a probe or an install gave any skill a name of its
|
||||
// own, or the library has more skills than want.
|
||||
func noSuffix(t *testing.T, p *Probe, want int) {
|
||||
t.Helper()
|
||||
for _, c := range p.Candidates {
|
||||
if c.As != "" {
|
||||
t.Errorf("%s would go in as %s", c.Path, c.As)
|
||||
}
|
||||
}
|
||||
l, _ := load()
|
||||
var names []string
|
||||
for _, s := range l.Skills {
|
||||
names = append(names, s.Name)
|
||||
if s.Called != "" {
|
||||
t.Errorf("%s is kept as %s", s.Called, s.Name)
|
||||
}
|
||||
}
|
||||
if len(names) != want {
|
||||
t.Errorf("the library has %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
// The library's own blog and review, grouped with the repository (its
|
||||
// address in From, as the skills CLI's lock or a checkout gives it), then
|
||||
// the repository added by that address: each links to it, as a GitHub
|
||||
// repository's skills do, rather than going in beside itself.
|
||||
func TestGitRepoLinksTracedSkills(t *testing.T) {
|
||||
sandbox(t)
|
||||
addr, _ := groupedRepo(t)
|
||||
write(t, filepath.Join(skillDir("blog"), "SKILL.md"), "---\nname: blog\ndescription: Blog posts\n---\nv1\n")
|
||||
write(t, filepath.Join(skillDir("review"), "SKILL.md"), "---\nname: review\ndescription: Code review\n---\nv1\n")
|
||||
ok(t)(change(func(l *Library) error {
|
||||
l.Skills = append(l.Skills, &Skill{Name: "blog", From: addr, Agents: []string{"claude"}}, &Skill{Name: "review", From: addr, Agents: []string{"claude"}})
|
||||
return nil
|
||||
}))
|
||||
|
||||
p, err := ProbeSkills(addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range p.Candidates {
|
||||
if want := c.Name != "poem"; c.Links != want {
|
||||
t.Errorf("%s links: %v", c.Path, c.Links)
|
||||
}
|
||||
}
|
||||
noSuffix(t, p, 2)
|
||||
r := ok(t)(InstallSkills(addr, []string{"writing/blog", "writing/poem", "coding/review"}, []string{"claude"}))
|
||||
if !slices.Equal(r.Linked, []string{"blog", "review"}) || !slices.Equal(r.Installed, []string{"poem"}) {
|
||||
t.Fatalf("linked %v installed %v skipped %+v", r.Linked, r.Installed, r.Skipped)
|
||||
}
|
||||
noSuffix(t, p, 3)
|
||||
l, _ := load()
|
||||
for _, n := range []string{"blog", "review"} {
|
||||
s := l.skill(n)
|
||||
if s.Source == nil || s.Source.Kind != "git" || s.Source.Repo != addr || len(s.Commit) != 40 {
|
||||
t.Errorf("%s: %+v %+v", n, s, s.Source)
|
||||
}
|
||||
if got := read(t, filepath.Join(skillDir(n), "SKILL.md")); !strings.Contains(got, "v2") {
|
||||
t.Errorf("%s's SKILL.md: %q", n, got)
|
||||
}
|
||||
}
|
||||
// and they update from there, as one installed from it does
|
||||
ok(t)(UpdateSkills())
|
||||
}
|
||||
|
||||
// A repository that put its skills in groups since: the skill the library
|
||||
// has from its old folder is that skill, and follows it to its group.
|
||||
func TestGitRepoSkillMovedIntoGroup(t *testing.T) {
|
||||
sandbox(t)
|
||||
addr, commit := gitRepo(t, map[string]string{
|
||||
"skills/blog/SKILL.md": "---\nname: blog\ndescription: Write blog posts\n---\nv1\n",
|
||||
})
|
||||
ok(t)(InstallSkills(addr, []string{"skills/blog"}, []string{"claude"}))
|
||||
commit(map[string]string{
|
||||
"skills/blog/SKILL.md": gitRemoved,
|
||||
"skills/writing/blog/SKILL.md": "---\nname: blog\ndescription: Write blog posts\n---\nv2\n",
|
||||
"skills/writing/poem/SKILL.md": "---\nname: poem\ndescription: Write poems\n---\nv2\n",
|
||||
})
|
||||
p, err := ProbeSkills(addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
i := slices.IndexFunc(p.Candidates, func(c Candidate) bool { return c.Name == "blog" })
|
||||
if i < 0 || !p.Candidates[i].Have {
|
||||
t.Fatalf("probed as %+v", p.Candidates)
|
||||
}
|
||||
noSuffix(t, p, 1)
|
||||
ok(t)(InstallSkills(addr, []string{"skills/writing/blog", "skills/writing/poem"}, []string{"claude"}))
|
||||
noSuffix(t, p, 2)
|
||||
l, _ := load()
|
||||
if s := l.skill("blog"); s.Source.Path != "skills/writing/blog" {
|
||||
t.Errorf("blog updates from %+v", s.Source)
|
||||
}
|
||||
ok(t)(UpdateSkill("blog", false))
|
||||
if got := read(t, filepath.Join(skillDir("blog"), "SKILL.md")); !strings.Contains(got, "v2") {
|
||||
t.Errorf("blog's SKILL.md: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Two skills by one name in two groups of a repository are two skills:
|
||||
// the second goes in beside the first by its group's name, which tells
|
||||
// them apart where the owner both have would not.
|
||||
func TestSameNameInAnotherGroupTakesTheGroupsName(t *testing.T) {
|
||||
sandbox(t)
|
||||
addr, _ := gitRepo(t, map[string]string{
|
||||
"writing/notes/SKILL.md": "---\nname: notes\ndescription: Writing notes\n---\n",
|
||||
"coding/notes/SKILL.md": "---\nname: notes\ndescription: Code notes\n---\n",
|
||||
})
|
||||
w, c := addr+"/-/tree/main/writing", addr+"/-/tree/main/coding"
|
||||
pw, err := ProbeSkills(w)
|
||||
if err != nil || len(pw.Candidates) != 1 {
|
||||
t.Fatalf("probed %s as %+v, %v", w, pw, err)
|
||||
}
|
||||
ok(t)(InstallSkills(w, []string{pw.Candidates[0].Path}, nil))
|
||||
p, err := ProbeSkills(c)
|
||||
if err != nil || len(p.Candidates) != 1 || p.Candidates[0].As != "notes-coding" {
|
||||
t.Fatalf("probed %s as %+v, %v", c, p, err)
|
||||
}
|
||||
r := ok(t)(InstallSkills(c, []string{p.Candidates[0].Path}, nil))
|
||||
if !slices.Equal(r.Installed, []string{"notes-coding"}) {
|
||||
t.Fatalf("installed %v", r.Installed)
|
||||
}
|
||||
}
|
||||
|
||||
// What an earlier install left: review-<owner> beside the library's own
|
||||
// review traced to that repository. The next change of the library puts
|
||||
// them back together under review, from the repository, with the copy's
|
||||
// agents; both old folders are kept with the backups.
|
||||
func TestSkillBesideItselfFoldsBack(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
addr, _ := groupedRepo(t)
|
||||
write(t, filepath.Join(skillDir("review"), "SKILL.md"), "---\nname: review\ndescription: Code review\n---\nv1\n")
|
||||
ok(t)(change(func(l *Library) error {
|
||||
l.Skills = append(l.Skills, &Skill{Name: "review", From: addr, Agents: []string{"claude"}})
|
||||
return nil
|
||||
}))
|
||||
// as the old install made it
|
||||
write(t, filepath.Join(skillDir("review-team"), "SKILL.md"), "---\nname: review-team\ndescription: Review code\n---\nv2\n")
|
||||
ok(t)(change(func(l *Library) error {
|
||||
src := Source{Kind: "git", Repo: addr, Path: "coding/review"}
|
||||
dir := skillDir("review-team")
|
||||
l.Skills = append(l.Skills, &Skill{Name: "review-team", Called: "review", Source: &src, Agents: []string{"codex"}, Hash: hashDir(dir), Own: ownHash(dir)})
|
||||
return nil
|
||||
}))
|
||||
|
||||
l, _ := load()
|
||||
if len(l.Skills) != 1 {
|
||||
t.Fatalf("the library has %d skills", len(l.Skills))
|
||||
}
|
||||
s := l.skill("review")
|
||||
if s == nil || s.Called != "" || s.Source == nil || s.Source.Kind != "git" || s.Source.Path != "coding/review" {
|
||||
t.Fatalf("review is %+v", s)
|
||||
}
|
||||
if !slices.Equal(s.Agents, []string{"claude", "codex"}) {
|
||||
t.Errorf("review is on %v", s.Agents)
|
||||
}
|
||||
got := read(t, filepath.Join(skillDir("review"), "SKILL.md"))
|
||||
if !strings.Contains(got, "name: review\n") || !strings.Contains(got, "v2") {
|
||||
t.Errorf("review's SKILL.md: %q", got)
|
||||
}
|
||||
if _, err := os.Lstat(skillDir("review-team")); err == nil {
|
||||
t.Error("review-team is still in the library's folder")
|
||||
}
|
||||
if got := read(t, filepath.Join(h, ".codex/skills/review/SKILL.md")); !strings.Contains(got, "v2") {
|
||||
t.Errorf("codex's review: %q", got)
|
||||
}
|
||||
backups, _ := filepath.Glob(filepath.Join(BackupDir(), "*", "skills", "*"))
|
||||
replaced, _ := filepath.Glob(filepath.Join(BackupDir(), "*", "library", "skills", "*"))
|
||||
backups = append(backups, replaced...)
|
||||
var kept []string
|
||||
for _, b := range backups {
|
||||
kept = append(kept, filepath.Base(b))
|
||||
}
|
||||
slices.Sort(kept)
|
||||
if !slices.Equal(kept, []string{"review", "review-team"}) {
|
||||
t.Errorf("backups: %v", kept)
|
||||
}
|
||||
}
|
||||
|
||||
// One beside a skill from elsewhere is another skill, and stays beside it.
|
||||
func TestSkillBesideAnotherStays(t *testing.T) {
|
||||
sandbox(t)
|
||||
addr, _ := groupedRepo(t)
|
||||
write(t, filepath.Join(skillDir("review"), "SKILL.md"), "---\nname: review\ndescription: Code review\n---\nv1\n")
|
||||
write(t, filepath.Join(skillDir("review-team"), "SKILL.md"), "---\nname: review-team\ndescription: Review code\n---\nv2\n")
|
||||
ok(t)(change(func(l *Library) error {
|
||||
src := Source{Kind: "git", Repo: addr, Path: "coding/review"}
|
||||
l.Skills = append(l.Skills, &Skill{Name: "review", From: "elsewhere/skills"},
|
||||
&Skill{Name: "review-team", Called: "review", Source: &src})
|
||||
return nil
|
||||
}))
|
||||
ok(t)(change(func(l *Library) error { return nil }))
|
||||
l, _ := load()
|
||||
if len(l.Skills) != 2 || l.skill("review-team") == nil {
|
||||
t.Fatalf("the library has %d skills", len(l.Skills))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
@@ -25,15 +26,20 @@ import (
|
||||
// does). One traced to another repository, or one of the user's own that
|
||||
// describes something else, is another skill by that name, and goes in
|
||||
// beside it (skill_beside.go, TestInstallSetPutsAnotherByTheSameNameBeside).
|
||||
//
|
||||
// A git repository on another host is followed as GitHub is (Refeccd on
|
||||
// X): a skill the Library groups with gitlab.example.com/team/skills, from
|
||||
// the skills CLI's lock or a checkout of it, went in beside itself as
|
||||
// name-team when that repository was added, every skill of it.
|
||||
func followsHere(s *Skill, src Source, from string) bool {
|
||||
if src.Kind != "github" || s.Source.remote() || s.Called != "" {
|
||||
if !src.remote() || s.Source.remote() || s.Called != "" {
|
||||
return false
|
||||
}
|
||||
// where it is traced to: CC Switch's record, the skills CLI's lock,
|
||||
// the git checkout its folder is in, or the repository it was grouped
|
||||
// with (skill_from.go)
|
||||
if r := (&tracer{}).repoOf(s); r != "" {
|
||||
return strings.EqualFold(r, src.Repo)
|
||||
return tracedTo(r, src)
|
||||
}
|
||||
here, ok := readMeta(skillDir(s.Name))
|
||||
there, ok2 := readMeta(from)
|
||||
@@ -47,16 +53,21 @@ func followsHere(s *Skill, src Source, from string) bool {
|
||||
func (l *Library) linkSkill(s *Skill, src Source, path, from string, agents []string) (kept bool, err error) {
|
||||
src.Path = path
|
||||
dir := skillDir(s.Name)
|
||||
// a git repository's skill updates from the commit it was fetched at
|
||||
commit := ""
|
||||
if src.Kind == "git" {
|
||||
commit = gitHeadOf(repoRoot(from, path))
|
||||
}
|
||||
if linked(dir) || !sameTree(dir, from) {
|
||||
kept = !linked(dir)
|
||||
up := &skillUpdate{name: s.Name, src: &src, adopt: true, from: from}
|
||||
up := &skillUpdate{name: s.Name, src: &src, adopt: true, from: from, commit: commit}
|
||||
if err := up.apply(l, Targets()); err != nil {
|
||||
return false, err
|
||||
}
|
||||
} else {
|
||||
// its files are the source's already: only where it updates from
|
||||
// is new
|
||||
s.Hash, s.Own, s.Commit = hashDir(dir), ownHash(dir), ""
|
||||
s.Hash, s.Own, s.Commit = hashDir(dir), ownHash(dir), commit
|
||||
forgetCheck(s.Name)
|
||||
}
|
||||
s.Source, s.From, s.Gone = &src, "", ""
|
||||
@@ -67,3 +78,43 @@ func (l *Library) linkSkill(s *Skill, src Source, path, from string, agents []st
|
||||
}
|
||||
return kept, nil
|
||||
}
|
||||
|
||||
// tracedTo is whether r, the repository a skill is traced to (owner/repo
|
||||
// for GitHub, host/path for another host, as repoOf gives it), is src's.
|
||||
func tracedTo(r string, src Source) bool {
|
||||
switch src.Kind {
|
||||
case "github":
|
||||
return strings.EqualFold(r, src.Repo)
|
||||
case "git":
|
||||
k := remoteRepo(src.Repo)
|
||||
return k != "" && strings.EqualFold(r, k) || strings.EqualFold(strings.TrimSuffix(r, ".git"), strings.TrimSuffix(src.Repo, ".git"))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// sameRepo is whether a skill's source is the repository src is, at any
|
||||
// folder of it.
|
||||
func sameRepo(a *Source, src Source) bool {
|
||||
if a == nil || a.Kind != src.Kind {
|
||||
return false
|
||||
}
|
||||
switch src.Kind {
|
||||
case "github":
|
||||
return strings.EqualFold(a.Repo, src.Repo)
|
||||
case "git":
|
||||
return sameGitRepo(a.Repo, src.Repo)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// repoRoot is the folder a repository was fetched to, from where the
|
||||
// skill at path in it is: from less path's folders.
|
||||
func repoRoot(from, path string) string {
|
||||
if path == "" {
|
||||
return from
|
||||
}
|
||||
for range strings.Split(path, "/") {
|
||||
from = filepath.Dir(from)
|
||||
}
|
||||
return from
|
||||
}
|
||||
|
||||
@@ -1460,7 +1460,7 @@ func probeSkills(input, name string) (*Probe, error) {
|
||||
if followsHere(s, p.src, from) {
|
||||
p.Candidates[i].Links = true
|
||||
} else if p.src.remote() {
|
||||
p.Candidates[i].As = l.freeSkillName(c.Name, p.src)
|
||||
p.Candidates[i].As = l.besideName(c.Name, p.src, c.Path)
|
||||
} else {
|
||||
// a folder of the user's isn't added beside it
|
||||
// (installFrom): shown as had by that name, as before
|
||||
@@ -1596,12 +1596,19 @@ func installFrom(l *Library, p *Probe, paths, agents []string, shown bool, in *i
|
||||
// is that skill, and updates from there from now on (as
|
||||
// noteFrom binds it when probed): another by that name from
|
||||
// elsewhere goes in beside it, not in its place
|
||||
if s.Source == nil && src.Kind == "github" && !linked(skillDir(s.Name)) {
|
||||
if s.Source == nil && src.remote() && !linked(skillDir(s.Name)) {
|
||||
if _, err := l.linkSkill(s, src, c.Path, from, nil); err != nil {
|
||||
in.skip(c.Name, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
// moved to a group of its repository: it updates from there
|
||||
if s.Source.remote() && s.Source.Path != c.Path && movedIn(s, src, c, from) {
|
||||
moved := *s.Source
|
||||
moved.Path = c.Path
|
||||
s.Source, s.Gone = &moved, ""
|
||||
forgetCheck(s.Name)
|
||||
}
|
||||
in.had = append(in.had, s.Name)
|
||||
l.offered(p, c.Path, shown)
|
||||
continue
|
||||
@@ -1628,7 +1635,7 @@ func installFrom(l *Library, p *Probe, paths, agents []string, shown bool, in *i
|
||||
in.skip(c.Name, fmt.Errorf("the library already has another skill called %s, left as it is: give this one another name in its SKILL.md to add it beside it", c.Name))
|
||||
continue
|
||||
}
|
||||
name = l.freeSkillName(c.Name, src)
|
||||
name = l.besideName(c.Name, src, c.Path)
|
||||
}
|
||||
dir := skillDir(name)
|
||||
// something by that name in the library's folder that the
|
||||
|
||||
Reference in New Issue
Block a user