library: a skill brought in from an app's versioned folder follows the app's updates (#2635)
iomect's ego lite keeps its skill in a framework version folder and points its own links at the current one: ~/.agents/skills/ego-browser -> ~/.local/share/ego/ego-skills ~/.local/share/ego/ego-skills -> ~/.local/share/ego/active_version_dir/Resources/ego-skills/ego-browser ~/.local/share/ego/active_version_dir -> /Applications/ego lite.app/.../Versions/0.6.0.12 .../Versions/Current -> 0.6.0.12 ImportSkill linked the library to the fully resolved folder (Versions/0.5.1.13/...). After the update to 0.6.0.12 the old folder was still there, so the library and every agent it gives skills to kept the old skill. importSkill now links to linkVia(f.at, f.real), and Source.Dir is that same path. linkVia follows the found entry's links one at a time, and stops at the first one outside every skills folder (the agents', the shared ~/.agents/skills and the library's): for ego that is ~/.local/share/ego/ego-skills, which the app keeps pointing at its current version. A Versions/<v> part is named Versions/Current when Current is a link to that same version, which covers an entry that links straight into the versioned folder. If that path doesn't resolve to the same folder as today, linkVia returns the resolved folder, as before. Nothing else changes: every comparison of Source.Dir already goes through realDir. Tests (skill_version_test.go): - TestImportedSkillFollowsAppUpdate uses the reporter's layout (ego lite.app, ego Framework.framework/Versions, active_version_dir, ego-skills, ~/.agents/skills/ego-browser), brings it in at 0.5.1.13, then moves the app's links to 0.6.0.12 and checks the library's skill is 0.6.0.12's, listed and not missing. - TestImportedSkillThroughVersionsCurrent does the same with an entry linking straight into Versions/0.5.1.13. - TestImportedSkillPlainLink checks that a link to a plain folder is still linked to that folder. Broken by hand: - with `via := f.real` (the old link), FollowsAppUpdate and ThroughVersionsCurrent went red (the skill stayed "ego 0.5.1.13"); - with the Versions/Current step taken out, ThroughVersionsCurrent went red. Not done: a skill brought in before this keeps its old resolved link until it is brought in again, or its link in the library is replaced. No ego install here; the tests use the layout from the reporter's ls. Run: gofmt -l clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags nogui ./... clean. go test -timeout 45m ./... under set -o pipefail with a sandbox HOME, load ~280: 65 packages ok (internal/library 352s), internal/gui red with 8 real-window AppKit tests killed at their deadlines (#2645). internal/gui doesn't use this code. It passed alone with the real HOME, with this change (186s at load ~260-341) and on8bb9375e7without it (204s at ~300). With the sandbox HOME it went red again when run alone; the runs are on #2645. No GUI files touched. Rebased ontoebf3f48f7, which changes nothing under internal/library or internal/agent; go build ./... and go test ./internal/library ok there (697s).
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// egoLite lays out iomect's ego lite (#2635) under h at version v: the
|
||||
// framework's Versions/<v> holding the skill, Versions/Current, and the
|
||||
// app's own links in ~/.local/share/ego, which it points at the new
|
||||
// version when it updates.
|
||||
func egoLite(t *testing.T, h, v string) (versions string) {
|
||||
t.Helper()
|
||||
versions = filepath.Join(h, "Applications/ego lite.app/Contents/Frameworks/ego Framework.framework/Versions")
|
||||
skill(t, filepath.Join(versions, v, "Resources/ego-skills/ego-browser"), "ego-browser", "ego "+v)
|
||||
share := filepath.Join(h, ".local/share/ego")
|
||||
if err := os.MkdirAll(share, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for link, to := range map[string]string{
|
||||
filepath.Join(versions, "Current"): v,
|
||||
filepath.Join(share, "active_version_dir"): filepath.Join(versions, v),
|
||||
filepath.Join(share, "ego-skills"): filepath.Join(share, "active_version_dir/Resources/ego-skills/ego-browser"),
|
||||
} {
|
||||
os.Remove(link)
|
||||
if err := os.Symlink(to, link); err != nil {
|
||||
t.Skip("no symlinks here:", err)
|
||||
}
|
||||
}
|
||||
return versions
|
||||
}
|
||||
|
||||
// A skill an app keeps in a versioned folder, brought in, is the app's
|
||||
// current one after the app updates (iomect, #2635): ~/.agents/skills/
|
||||
// ego-browser -> ~/.local/share/ego/ego-skills -> active_version_dir/... ->
|
||||
// Versions/0.5.1.13, and the update points active_version_dir at 0.6.0.12.
|
||||
func TestImportedSkillFollowsAppUpdate(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
egoLite(t, h, "0.5.1.13")
|
||||
shared := filepath.Join(h, ".agents/skills")
|
||||
if err := os.MkdirAll(shared, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(h, ".local/share/ego/ego-skills"), filepath.Join(shared, "ego-browser")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ImportSkill("ego-browser"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
egoLite(t, h, "0.6.0.12")
|
||||
if m, ok := readMeta(skillDir("ego-browser")); !ok || m.Description != "ego 0.6.0.12" {
|
||||
to, _ := os.Readlink(skillDir("ego-browser"))
|
||||
t.Errorf("after the update the library's ego-browser is %q (links to %s), want 0.6.0.12's", m.Description, to)
|
||||
}
|
||||
v, _ := Read(nil)
|
||||
if len(v.Skills) != 1 || v.Skills[0].Missing || len(v.FoundSkills) != 0 {
|
||||
t.Errorf("skills %+v, found %+v", v.Skills, v.FoundSkills)
|
||||
}
|
||||
}
|
||||
|
||||
// An agent's link straight into Versions/<v> is brought in through
|
||||
// Versions/Current, which an update moves on.
|
||||
func TestImportedSkillThroughVersionsCurrent(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
versions := egoLite(t, h, "0.5.1.13")
|
||||
shared := filepath.Join(h, ".agents/skills")
|
||||
if err := os.MkdirAll(shared, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(versions, "0.5.1.13/Resources/ego-skills/ego-browser"), filepath.Join(shared, "ego-browser")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ImportSkill("ego-browser"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
egoLite(t, h, "0.6.0.12")
|
||||
if m, ok := readMeta(skillDir("ego-browser")); !ok || m.Description != "ego 0.6.0.12" {
|
||||
t.Errorf("after the update the library's ego-browser is %q, want 0.6.0.12's", m.Description)
|
||||
}
|
||||
}
|
||||
|
||||
// A link to a folder that isn't versioned is linked to where it is, as
|
||||
// before.
|
||||
func TestImportedSkillPlainLink(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
src := filepath.Join(h, "code/notes")
|
||||
skill(t, src, "notes", "Mine")
|
||||
if err := os.MkdirAll(filepath.Join(h, ".claude/skills"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(src, filepath.Join(h, ".claude/skills/notes")); err != nil {
|
||||
t.Skip("no symlinks here:", err)
|
||||
}
|
||||
if _, err := ImportSkill("notes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if to, err := os.Readlink(skillDir("notes")); err != nil || realDir(to) != realDir(src) {
|
||||
t.Errorf("library's notes links to %q (%v), want %s", to, err, src)
|
||||
}
|
||||
}
|
||||
@@ -1798,6 +1798,65 @@ func foundSkills(l *Library) []FoundSkill {
|
||||
return res
|
||||
}
|
||||
|
||||
// linkVia is what the library links to for a skill found at the entry at,
|
||||
// whose folder is really at real: the first link on the way from at that
|
||||
// is outside every skills folder (the agents', the shared one and the
|
||||
// library's), which the app that made it keeps pointing at its current
|
||||
// folder, as ego lite's ~/.local/share/ego/ego-skills does. A folder in a
|
||||
// bundle's Versions/<v> is named through Versions/Current when Current is
|
||||
// that very version. It is real when nothing on the way is any steadier,
|
||||
// or when the way doesn't end at real.
|
||||
func linkVia(at, real string) string {
|
||||
var homes []string
|
||||
for _, d := range []string{skillsDir(), sharedSkillsDir()} {
|
||||
homes = append(homes, realBelow(d))
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
if t.Skills != "" {
|
||||
homes = append(homes, realBelow(t.Skills))
|
||||
}
|
||||
}
|
||||
inHome := func(p string) bool {
|
||||
up := realBelow(filepath.Dir(p))
|
||||
return slices.ContainsFunc(homes, func(h string) bool { return within(up, h) })
|
||||
}
|
||||
cur := filepath.Clean(at)
|
||||
for i := 0; inHome(cur); i++ {
|
||||
to, ok := linkTarget(cur)
|
||||
if !ok || i > 40 {
|
||||
cur = real
|
||||
break
|
||||
}
|
||||
if !filepath.IsAbs(to) {
|
||||
to = filepath.Join(filepath.Dir(cur), to)
|
||||
}
|
||||
cur = filepath.Clean(to)
|
||||
}
|
||||
cur = currentVersion(cur)
|
||||
if realDir(cur) != real {
|
||||
return real
|
||||
}
|
||||
return cur
|
||||
}
|
||||
|
||||
// currentVersion is p with a Versions/<v> part of it named Versions/Current,
|
||||
// when that link is there and points at <v>: a macOS framework's versions,
|
||||
// of which an update leaves the old one behind.
|
||||
func currentVersion(p string) string {
|
||||
parts := strings.Split(p, string(filepath.Separator))
|
||||
for i := len(parts) - 2; i > 0; i-- {
|
||||
if parts[i] != "Versions" || parts[i+1] == "Current" {
|
||||
continue
|
||||
}
|
||||
vs := strings.Join(parts[:i+1], string(filepath.Separator))
|
||||
cur := filepath.Join(vs, "Current")
|
||||
if realDir(cur) == realDir(filepath.Join(vs, parts[i+1])) && linked(cur) {
|
||||
return filepath.Join(append([]string{cur}, parts[i+2:]...)...)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ImportSkill takes a skill the agents have of their own into the library:
|
||||
// a folder is moved in, a link to a folder elsewhere is linked to from the
|
||||
// library, and the agents that had it get the library's from then on.
|
||||
@@ -1858,9 +1917,15 @@ func importSkill(l *Library, found []FoundSkill, name string) error {
|
||||
src = nil
|
||||
}
|
||||
case f.Link != "" || shared:
|
||||
if err := dirLink(f.real, skillDir(name)); err != nil {
|
||||
// linked through the way the agent's own link goes, not to where
|
||||
// it ends today: an app that keeps its skills in a versioned
|
||||
// folder points its own link at the new one when it updates
|
||||
// (iomect's ego lite, #2635), and the library follows
|
||||
via := linkVia(f.at, f.real)
|
||||
if err := dirLink(via, skillDir(name)); err != nil {
|
||||
return err
|
||||
}
|
||||
src.Dir = via
|
||||
default:
|
||||
// a move that copied it all but couldn't take the whole folder away
|
||||
// (a file in it held open) has brought it in all the same: what is
|
||||
|
||||
Reference in New Issue
Block a user