library: a well-known kit brought in before v0.1.1223 groups as one source again (#1862, WardLu)
WardLu's Feishu skills (3) and Fish Audio skills (2) still showed as 3 and 2 groups on v0.1.1223, which grouped well-known kits by their base. The lock now says the kit's base, but each skill's From was recorded when it was brought in from ~/.agents/skills (ImportSkills), and back then that was the skill's own sourceUrl, e.g. "docs.fish.audio/.well-known/agent-skills/fish-audio-api/skill.md". repoOf takes From before the lock, so the stale per-skill key won. fromKey reads a From that carries /.well-known/ as the base before it, so those skills group as the lock now says, without rewriting the user's library. Run: TestWellKnownKitFromBeforeGrouped, built from the reporter's five lock entries with From set to the old form, passes; on the old skill_from.go it fails with five per-skill groups. go test ./internal/library ok; gofmt -l clean; go vet (darwin) and GOOS=linux / GOOS=windows go vet -tags nogui ./internal/library ok. Not tried in the reporter's own GUI.
This commit is contained in:
@@ -30,7 +30,7 @@ func (tr *tracer) repoOf(s *Skill) string {
|
||||
return o.Repo
|
||||
}
|
||||
if s.From != "" {
|
||||
return s.From
|
||||
return fromKey(s.From)
|
||||
}
|
||||
dir := skillDir(s.Name)
|
||||
if !linked(dir) {
|
||||
@@ -121,6 +121,19 @@ func wellKnownBase(base, src string) string {
|
||||
return remoteRepo(src)
|
||||
}
|
||||
|
||||
// fromKey is the group a skill's From names. A skill brought in from
|
||||
// ~/.agents/skills keeps the lock's key as it was then (ImportSkills), and
|
||||
// before well-known kits were grouped by their base that was each skill's
|
||||
// own sourceUrl, "docs.fish.audio/.well-known/agent-skills/fish-audio-api/
|
||||
// skill.md": read as the base before /.well-known/, so a kit brought in
|
||||
// then is one group as the lock now says (#1862, WardLu on v0.1.1223).
|
||||
func fromKey(from string) string {
|
||||
if before, _, ok := strings.Cut(from, "/.well-known/"); ok && before != "" {
|
||||
return before
|
||||
}
|
||||
return from
|
||||
}
|
||||
|
||||
// siteOf reads a web address as host/path, or the host alone, with no
|
||||
// user, query or trailing slash: "" when it isn't an http(s) address.
|
||||
func siteOf(s string) string {
|
||||
|
||||
@@ -136,6 +136,55 @@ func TestWellKnownKitGrouped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// #1862 (WardLu, v0.1.1223): skills brought into the library before
|
||||
// well-known kits were grouped by their base kept the lock's key of then
|
||||
// as their From, each skill's own sourceUrl, and From is read before the
|
||||
// lock, so Feishu's three were three groups and Fish Audio's two were two
|
||||
// after the fix. The reporter's lock entries, with From as v0.1.1217's
|
||||
// ImportSkills wrote it.
|
||||
func TestWellKnownKitFromBeforeGrouped(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
lock := `{"skills":{
|
||||
"lark-base":{"source":"open.feishu.cn","sourceType":"well-known","sourceUrl":"https://open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-base.tar.gz","sourceBaseUrl":"https://open.feishu.cn/lark-cli/skills/regular"},
|
||||
"lark-doc":{"source":"open.feishu.cn","sourceType":"well-known","sourceUrl":"https://open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-doc.tar.gz","sourceBaseUrl":"https://open.feishu.cn/lark-cli/skills/regular"},
|
||||
"lark-sheets":{"source":"open.feishu.cn","sourceType":"well-known","sourceUrl":"https://open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-sheets.tar.gz","sourceBaseUrl":"https://open.feishu.cn/lark-cli/skills/regular"},
|
||||
"fish-audio-api":{"source":"docs.fish.audio","sourceType":"well-known","sourceUrl":"https://docs.fish.audio/.well-known/agent-skills/fish-audio-api/skill.md","sourceBaseUrl":"https://docs.fish.audio"},
|
||||
"fish-audio-sdk":{"source":"docs.fish.audio","sourceType":"well-known","sourceUrl":"https://docs.fish.audio/.well-known/agent-skills/fish-audio-sdk/skill.md","sourceBaseUrl":"https://docs.fish.audio"}
|
||||
}}`
|
||||
write(t, filepath.Join(h, ".agents/.skill-lock.json"), lock)
|
||||
before := map[string]string{ // remoteRepo of each sourceUrl, the key before 97dfed0f3
|
||||
"lark-base": "open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-base.tar.gz",
|
||||
"lark-doc": "open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-doc.tar.gz",
|
||||
"lark-sheets": "open.feishu.cn/lark-cli/skills/regular/.well-known/agent-skills/lark-sheets.tar.gz",
|
||||
"fish-audio-api": "docs.fish.audio/.well-known/agent-skills/fish-audio-api/skill.md",
|
||||
"fish-audio-sdk": "docs.fish.audio/.well-known/agent-skills/fish-audio-sdk/skill.md",
|
||||
}
|
||||
var names []string
|
||||
for n := range before {
|
||||
skill(t, filepath.Join(h, ".agents/skills", n), n, "D")
|
||||
names = append(names, n)
|
||||
}
|
||||
ok(t)(ImportSkills(names))
|
||||
l := mustLoad(t)
|
||||
for n, f := range before {
|
||||
l.skill(n).From = f
|
||||
}
|
||||
if err := l.save(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := repoIn(t)
|
||||
for n := range before {
|
||||
want := "docs.fish.audio"
|
||||
if strings.HasPrefix(n, "lark-") {
|
||||
want = "open.feishu.cn/lark-cli/skills/regular"
|
||||
}
|
||||
if got[n] != want {
|
||||
t.Errorf("%s: repo %q, want %q", n, got[n], want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A well-known kit's base, from the lock's sourceBaseUrl or else its
|
||||
// sourceUrl; neither an http(s) address, its sourceUrl as a remote.
|
||||
func TestWellKnownBase(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user