library: a skill linked into an app version the update deleted follows it to the current one (tjhhhh on Discord)
tjhhhh: ego lite keeps its skills in its framework's Versions/<v>. After the app updated, the skill was in the new version's folder, the old folder was gone, and magpie still linked the old one.dccfefdf7(#2635) linked new imports through the app's own steady link (~/.local/share/ego/ego-skills, or Versions/Current), but a skill brought in before then links straight to the resolved Versions/<old> path. tjhhhh's case is that old link: an import made sincedccfefdf7already follows the update (TestImportedSkillFollowsAppUpdate). followMovedSkills (skill_moved.go) runs on every read of the Library page, under the read's link memo, which is restarted when a link is mended. It also runs as the first step of every sync. For each library skill that is a link: - Target gone, and its first missing part named like a version: link the same place under the folder's Current/current/latest link. With no such link, use the highest version beside it that has a SKILL.md there (1.10 after 1.9). - Target in Versions/<v> while the bundle's Versions/Current links to another version with the same skill: link it through Current. Source.Dir follows. Only the link is replaced (os.Remove of the link, then dirLink, and the old link is put back if the new one can't be made). A folder of the library's own, a link the user deleted that isn't a version (still shown missing), and the app's old version folder are left alone. docs/subsystems/library.md says so. Run (all on mote via mote-run): - New tests on ego lite's real layout (egoLite: framework Versions/<v>, Current, ~/.local/share/ego links): TestOldImportFollowsDeletedVersion (0.5.1.13 deleted, then 0.6.0.12, then the next update to 0.7.0.1 by itself, plus the agents' link through the library), TestOldImportFollowsVersionsCurrent (old kept, through Sync()), TestOldImportFollowsHighestVersion, TestMovedSkillsLeaveTheRest and TestVersionLess. All pass, as do dccfefdf7's three tests. - Broken by hand: with followMovedSkills returning false at once, the three OldImport tests are red. - go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: clean. gofmt -l: nothing. - Full go test -tags nogui -count=1 -timeout 45m ./... in a sandbox HOME: 80 ok, 3 FAIL. - internal/library TestReadLooksAtEachFolderOnce was mine: the mend ran before the read's memo, so each skill link was looked at twice. Fixed (the memo starts first and restarts after a mend). The whole internal/library package then passed (75s). - internal/gui TestSettingsSaveKeepsWhatItDoesNotSend is red on origin/main3ecc02b78andccc791231alike (#4514, SearchAll). - internal/cli TestAgentFieldNameShowsIt failed once under load. It passes alone and in a whole internal/cli run, and its message was lost to my grep of the log (#4583). The full ./... was not run again after the memo fix. - At the pushed head, rebased ona51776f9c(which changed internal/library too): go vet and the whole internal/library package ok (95s). Not tried: tjhhhh's own machine and ego lite's real update (the layout is the #2635 fixture, built from iomect's report). Windows junctions to a deleted version (dirLink is the same call ImportSkill uses). An app that renames the folder above the version is not followed: it stays missing.
This commit is contained in:
@@ -66,6 +66,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
- A carried library (`Collect`) has every file of each skill, its templates and other binaries included, up to `maxCarried` (16 MiB) a file and `maxCarriedAll` (32 MiB) in all, chosen smallest first across the skills (`readSkills`), so every skill's text goes before any big file. The total keeps a sealed backup under the 64 MiB a sync reads: the files are base64 twice in it. What is left out is named in `Left`, and `Put` keeps this computer's copy of such a file in the skill it puts (`keepLeft`). [`carry.go`](../../internal/library/carry.go)
|
||||
- A skill can be turned off on this computer alone (`OffHere`, `SkillHere`; the row's power button, `magpie library skill off-here <name>` and `on-here`; hanslin1666 on Discord). No agent here gets it, whatever its `Agents` say (`gives`, which every reader of `Agents` for giving goes through: `syncSkills`, `desktop_skills.go`, `skill_changed.go`, `skill_edits.go`, `behind`, `Targets`). `Agents` stays what a sync carries, and the page leaves its chips as they are, faded. `Collect` never carries `OffHere`, so turning it off changes no part a sync uploads, and `Put` keeps this computer's `OffHere` for a skill it puts, so a sync from a computer that has it on, or gives it to more agents, never turns it on here. A library.json from before has no `offHere` and every skill stays on. Not covered: a project's skills; a library skill kept in `~/.agents/skills`, which agents read in place, until it is handed over (below); and a skill another computer removes, which takes the flag with it. [`skills.go`](../../internal/library/skills.go), [`carry.go`](../../internal/library/carry.go)
|
||||
- An MCP server can be kept to this computer (`Server.Local`; the editor's "This computer only" switch, `magpie library mcp add --local`, `magpie library mcp local <name> on|off`; huhuy72219405 on X). `Collect` never carries it (`carriedServers`), so a sync or a backup file never takes it to another computer, and turning a shared server local takes it out of what is carried: the other computers drop it at their next sync. `Put` (sync, join, Restore, Undo, a backup file) keeps every local server here, with its agents, and clears `Local` on what comes in (`putServers`). Another computer's server by the name of a local one doesn't take its place: it goes to `Library.Away`, given to no agent, not in the router, not checked, and carried on as it came, so a push from here never takes it from the computers that have it. `settleAway` runs on every change: while the name is local here the away copy stays; once no server of that name is left here (removed or renamed) it comes in as a sync would bring it; once a shared server has the name (local turned off) this computer's is the one carried. The router serves local servers like any other, since it runs on this computer. A carried subagent names its servers, a local one too; a computer without that server leaves it out of the agents' files, as any server the library hasn't. The TUI keeps the flag on edit and marks the row. (`TestLocalServerNotCarried`, `TestPutKeepsLocalServer`, `TestPutSameNameAsLocal`, `TestRestoreKeepsLocalServer`, `TestLocalServerThroughSync`, `mcp-local-server.test.cjs`) [`mcp_local.go`](../../internal/library/mcp_local.go), [`carry.go`](../../internal/library/carry.go)
|
||||
- A skill brought in from a link into a folder an app keeps per version (ego lite's framework `Versions/<v>`, #2635) is linked through the app's own steady link, or through `Versions/Current` when Current is that version (`linkVia`, `currentVersion`; `TestImportedSkillFollowsAppUpdate`, `TestImportedSkillThroughVersionsCurrent`). One brought in before that links straight to `Versions/<old>`, which the app's update deletes (tjhhhh on Discord). Every read of the page (looking at each link once, `readParts`, and starting that over when a link was mended) and the first step of every sync mend such links (`followMovedSkills`): a library skill that is a link, whose target isn't there, and whose first missing part is named like a version (`versionName`) is linked to the same place under that folder's `Current`, `current` or `latest` link, else under the highest version beside it that has a `SKILL.md` there (`movedVersion`, `versionLess`); one whose target is in `Versions/<v>` while the bundle's `Versions/Current` is a link to another version with the same skill is linked through Current (`laterCurrent`). `Source.Dir` follows. Only the library's link is replaced (`os.Remove` of the link, then `dirLink`; put back as it was when the new link can't be made). A folder of the library's own, a link to a folder the user deleted that isn't a version (shown missing as before) and the app's old version folder are left as they are (`TestOldImportFollowsDeletedVersion`, `TestOldImportFollowsVersionsCurrent`, `TestOldImportFollowsHighestVersion`, `TestMovedSkillsLeaveTheRest`). [`skill_moved.go`](../../internal/library/skill_moved.go)
|
||||
- A skill kept in `~/.agents/skills` is handed over to the library on the user's click (`HandOverSkills`, `POST /api/library/skills/hand-over` with `names`; the row's Manage in magpie in its source line, Manage {n} in magpie in the skills' heading, each asking first; `magpie library skill hand-over <name…>|--all`; tnt1223 on Discord). "Kept there" is `sharedEntry`: the entry in that folder that is the library skill's own folder, by its name or, for a library link into it under another folder's name, by that folder's (`SkillView.Shared`; `SharedElsewhere` when the entry only links to a folder kept elsewhere). Every reader of `sharedHas`/`sharedEntry` follows: `Always`, `syncSkills`' `inShared`, and the shared folder's own target (Goose, Kimi Code, Cindy), which is given no second link beside such an entry (`TestSharedUnderAnotherName`). Handed over, a folder in `~/.agents/skills` moves into the library's skills folder (`moveIn`: renamed, or copied, read back the same with `sameTree` and only then set aside with the backups; a failure leaves it where it was and the library's link as it was, `TestHandOverFailureKeepsOriginal`), and an entry that only links elsewhere is taken away while the library links past it to that folder. The user's own links to it in agents' folders, which would point at nothing, go too. Every agent here that read it (`readsSharedHere`, and the agent of each such link) is ticked, so each keeps it, now from the library, till it is unticked or turned off here. A skill found there and not in the library yet is brought in first. One that can't be handed over is left as it was, in `Result.Unmoved`, and the others are handed over all the same. `HandBackSkill` (`magpie library skill hand-back <name>`, CLI only; the sheet names it) moves the folder back and links the library to it, its ticks as they are. Not covered: another computer whose skill is still in its own `~/.agents/skills` gets the library's copy from a sync beside its own, until it is handed over there too; and the skills CLI's lock (`npx skills update`) may put the entry back (`TestHandOverSharedFolder`, `TestHandOverSharedLink`, `TestHandOverFound`, `TestHandOverWithGoose`, `TestLibrarySkillHandOver`, `skill-handover.test.cjs`). [`skill_handover.go`](../../internal/library/skill_handover.go)
|
||||
- WorkBuddy's servers go in `$WORKBUDDY_CONFIG_DIR/mcp.json` (default `~/.workbuddy`; WorkBuddy AI, the international build, keeps its own in `~/.workbuddy-ai`, #1494), and CodeBuddy Code's go in the first of `.mcp.json`, `mcp.json` and `~/.codebuddy.json` that exists, as `resolveMcpFilePath` reads them (#1266). WorkBuddy connects a server only after the user has switched it on once in its own MCP settings. It keeps that approval in `mcp-approvals.json`, keyed by the command, args and env names or the URL's origin, so changing those asks again. magpie never writes the approval, and the servers page says so, by the build's name, when a server is given to WorkBuddy or WorkBuddy AI.
|
||||
- Alma's servers go in `~/.config/alma/mcp.json` on every system (its home, not its data folder), as its own MCP settings write them: `command`/`args`/`env`, or `url`/`headers` with `transport: "sse"` only for SSE (#1292). Alma reads the file as it starts and when its MCP settings refresh, so a server given to it while it runs reaches it after one of those.
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package library
|
||||
|
||||
// A skill brought in from a folder an app keeps per version, which the
|
||||
// app's update moved (tjhhhh on Discord, after #2635). ego lite keeps its
|
||||
// skills in its framework's Versions/<v>; an update puts them in the new
|
||||
// version's folder and deletes the old one. dccfefdf7 links a skill
|
||||
// brought in from then on through the app's own steady link, but one
|
||||
// brought in before it links straight into Versions/<old>: after the
|
||||
// update the library's link points at nothing, and every agent's copy of
|
||||
// it with it. followMovedSkills mends such links each time the library is
|
||||
// read or synced. Only a link is replaced, never a folder: a skill that is
|
||||
// a folder of the library's own, or a link that still leads somewhere
|
||||
// that isn't a version the app has moved on from, is left as it is.
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// followMovedSkills re-points each library skill linked into a version
|
||||
// folder an app has moved on from: one gone, or one the app's
|
||||
// Versions/Current no longer is. It says whether a skill was changed.
|
||||
func (l *Library) followMovedSkills() bool {
|
||||
changed := false
|
||||
for _, s := range l.Skills {
|
||||
if s.Source == nil || s.Source.Kind != "folder" {
|
||||
continue
|
||||
}
|
||||
p := skillDir(s.Name)
|
||||
to, ok := linkTarget(p)
|
||||
if !ok {
|
||||
continue // the library's own folder: nothing to follow
|
||||
}
|
||||
if !filepath.IsAbs(to) {
|
||||
to = filepath.Join(filepath.Dir(p), to)
|
||||
}
|
||||
to = filepath.Clean(to)
|
||||
next := ""
|
||||
if _, err := os.Stat(p); err != nil {
|
||||
if !absent(err) {
|
||||
continue // can't be read: unknown, not gone
|
||||
}
|
||||
next = movedVersion(to)
|
||||
} else {
|
||||
next = laterCurrent(to)
|
||||
}
|
||||
if next == "" || next == to {
|
||||
continue
|
||||
}
|
||||
// os.Remove takes the link away, never what it points at
|
||||
if err := os.Remove(p); err != nil {
|
||||
log.Printf("library: following %s to %s: %v", s.Name, next, err)
|
||||
continue
|
||||
}
|
||||
if err := dirLink(next, p); err != nil {
|
||||
log.Printf("library: following %s to %s: %v", s.Name, next, err)
|
||||
if err := dirLink(to, p); err != nil {
|
||||
log.Printf("library: putting %s's link back: %v", s.Name, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
log.Printf("library: %s moved with its app, from %s to %s", s.Name, to, next)
|
||||
s.Source.Dir = next
|
||||
changed = true
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
// versionName is a folder named for a version: 0.6.0.12, v2.1, 1.4.2-beta.
|
||||
var versionName = regexp.MustCompile(`^[vV]?\d+(\.\d+)*([-+_][0-9A-Za-z.]+)?$`)
|
||||
|
||||
// currentNames are the links an app keeps beside its version folders to
|
||||
// the one in use.
|
||||
var currentNames = []string{"Current", "current", "latest"}
|
||||
|
||||
// movedVersion is where a skill folder at p, which isn't there, is in the
|
||||
// app's version now: p's first missing part is a version folder, and a
|
||||
// version beside it has the same skill at the same place. The app's link
|
||||
// to its current version is taken first, as it moves on with the next
|
||||
// update too; then the highest version that has it. "" when there's none.
|
||||
func movedVersion(p string) string {
|
||||
// up is the nearest folder above p that is there, gone the part of p
|
||||
// in it that isn't, and rest the way on from gone
|
||||
d, rest := filepath.Clean(p), ""
|
||||
for {
|
||||
up := filepath.Dir(d)
|
||||
if up == d {
|
||||
return ""
|
||||
}
|
||||
if _, err := os.Stat(up); err == nil {
|
||||
break
|
||||
} else if !absent(err) {
|
||||
return "" // can't be read: unknown
|
||||
}
|
||||
rest = filepath.Join(filepath.Base(d), rest)
|
||||
d = up
|
||||
}
|
||||
up, gone := filepath.Dir(d), filepath.Base(d)
|
||||
if !versionName.MatchString(gone) {
|
||||
return ""
|
||||
}
|
||||
for _, c := range currentNames {
|
||||
if at := filepath.Join(up, c); linked(at) && hasSkillMD(filepath.Join(at, rest)) {
|
||||
return filepath.Join(at, rest)
|
||||
}
|
||||
}
|
||||
es, err := os.ReadDir(up)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
best := ""
|
||||
for _, e := range es {
|
||||
if !versionName.MatchString(e.Name()) || !hasSkillMD(filepath.Join(up, e.Name(), rest)) {
|
||||
continue
|
||||
}
|
||||
if best == "" || versionLess(best, e.Name()) {
|
||||
best = e.Name()
|
||||
}
|
||||
}
|
||||
if best == "" {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(up, best, rest)
|
||||
}
|
||||
|
||||
// laterCurrent is p, a folder in a bundle's Versions/<v>, named through
|
||||
// Versions/Current when Current has moved on to another version that has
|
||||
// the same skill at the same place: the app was updated and left the old
|
||||
// version behind. "" when p isn't in such a folder.
|
||||
func laterCurrent(p string) string {
|
||||
parts := strings.Split(p, string(filepath.Separator))
|
||||
for i := len(parts) - 2; i > 0; i-- {
|
||||
if parts[i] != "Versions" || !versionName.MatchString(parts[i+1]) {
|
||||
continue
|
||||
}
|
||||
vs := strings.Join(parts[:i+1], string(filepath.Separator))
|
||||
cur := filepath.Join(vs, "Current")
|
||||
if !linked(cur) || realDir(cur) == realDir(filepath.Join(vs, parts[i+1])) {
|
||||
return ""
|
||||
}
|
||||
next := filepath.Join(append([]string{cur}, parts[i+2:]...)...)
|
||||
if !hasSkillMD(next) {
|
||||
return ""
|
||||
}
|
||||
return next
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func hasSkillMD(dir string) bool {
|
||||
fi, err := os.Stat(filepath.Join(dir, "SKILL.md"))
|
||||
return err == nil && !fi.IsDir()
|
||||
}
|
||||
|
||||
// versionLess is whether version a comes before b, a number at a time.
|
||||
func versionLess(a, b string) bool {
|
||||
num := func(s string) []int {
|
||||
s = strings.TrimLeft(s, "vV")
|
||||
if i := strings.IndexAny(s, "-+_"); i >= 0 {
|
||||
s = s[:i]
|
||||
}
|
||||
var out []int
|
||||
for _, f := range strings.Split(s, ".") {
|
||||
n, _ := strconv.Atoi(f)
|
||||
out = append(out, n)
|
||||
}
|
||||
return out
|
||||
}
|
||||
x, y := num(a), num(b)
|
||||
for i := 0; i < len(x) || i < len(y); i++ {
|
||||
var m, n int
|
||||
if i < len(x) {
|
||||
m = x[i]
|
||||
}
|
||||
if i < len(y) {
|
||||
n = y[i]
|
||||
}
|
||||
if m != n {
|
||||
return m < n
|
||||
}
|
||||
}
|
||||
return a < b
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// oldImport brings the skill in at the agent's entry at as the library
|
||||
// did before dccfefdf7: linked to where it really was, Versions/<v> and all.
|
||||
func oldImport(t *testing.T, name, at string) string {
|
||||
t.Helper()
|
||||
if _, err := ImportSkill(name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
real := realDir(at)
|
||||
if err := os.Remove(skillDir(name)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(real, skillDir(name)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := change(func(l *Library) error { l.skill(name).Source.Dir = real; return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return real
|
||||
}
|
||||
|
||||
func agentLink(t *testing.T, h, name, to string) string {
|
||||
t.Helper()
|
||||
shared := filepath.Join(h, ".agents/skills")
|
||||
if err := os.MkdirAll(shared, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
at := filepath.Join(shared, name)
|
||||
if err := os.Symlink(to, at); err != nil {
|
||||
t.Skip("no symlinks here:", err)
|
||||
}
|
||||
return at
|
||||
}
|
||||
|
||||
// tjhhhh on Discord: ego lite brought in before dccfefdf7 links into
|
||||
// Versions/0.5.1.13; the update to 0.6.0.12 deletes that folder. Reading
|
||||
// the library links it through Versions/Current, where the skill is now,
|
||||
// and the agents have the new one through the library.
|
||||
func TestOldImportFollowsDeletedVersion(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
versions := egoLite(t, h, "0.5.1.13")
|
||||
at := agentLink(t, h, "ego-browser", filepath.Join(h, ".local/share/ego/ego-skills"))
|
||||
old := oldImport(t, "ego-browser", at)
|
||||
if !strings.Contains(old, "0.5.1.13") {
|
||||
t.Fatalf("the old import links to %s", old)
|
||||
}
|
||||
egoLite(t, h, "0.6.0.12")
|
||||
if err := os.RemoveAll(filepath.Join(versions, "0.5.1.13")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := readMeta(skillDir("ego-browser")); ok {
|
||||
t.Fatal("the old link still reads: the fixture didn't break it")
|
||||
}
|
||||
v, err := Read(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(v.Skills) != 1 || v.Skills[0].Missing {
|
||||
t.Fatalf("skills %+v", v.Skills)
|
||||
}
|
||||
if m, ok := readMeta(skillDir("ego-browser")); !ok || m.Description != "ego 0.6.0.12" {
|
||||
t.Errorf("the library's ego-browser is %q, want 0.6.0.12's", m.Description)
|
||||
}
|
||||
want := filepath.Join(realDir(versions), "Current/Resources/ego-skills/ego-browser")
|
||||
if to, _ := os.Readlink(skillDir("ego-browser")); filepath.Clean(to) != want {
|
||||
t.Errorf("links to %s, want %s, which the next update moves on too", to, want)
|
||||
}
|
||||
l, _ := load()
|
||||
if d := l.skill("ego-browser").Source.Dir; d != want {
|
||||
t.Errorf("source %s, want %s", d, want)
|
||||
}
|
||||
if m, ok := readMeta(at); !ok || m.Description != "ego 0.6.0.12" {
|
||||
t.Errorf("the agents' ego-browser is %q, want 0.6.0.12's", m.Description)
|
||||
}
|
||||
// and it then follows the next update by itself
|
||||
egoLite(t, h, "0.7.0.1")
|
||||
if err := os.RemoveAll(filepath.Join(versions, "0.6.0.12")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, ok := readMeta(skillDir("ego-browser")); !ok || m.Description != "ego 0.7.0.1" {
|
||||
t.Errorf("after the next update it is %q", m.Description)
|
||||
}
|
||||
}
|
||||
|
||||
// An update that leaves the old version behind: the library follows
|
||||
// Versions/Current, now the new one, on a sync too.
|
||||
func TestOldImportFollowsVersionsCurrent(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
versions := egoLite(t, h, "0.5.1.13")
|
||||
at := agentLink(t, h, "ego-browser", filepath.Join(versions, "0.5.1.13/Resources/ego-skills/ego-browser"))
|
||||
oldImport(t, "ego-browser", at)
|
||||
egoLite(t, h, "0.6.0.12")
|
||||
if m, _ := readMeta(skillDir("ego-browser")); m.Description != "ego 0.5.1.13" {
|
||||
t.Fatalf("before a sync the library's is %q", m.Description)
|
||||
}
|
||||
if _, err := Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, ok := readMeta(skillDir("ego-browser")); !ok || m.Description != "ego 0.6.0.12" {
|
||||
t.Errorf("the library's ego-browser is %q, want 0.6.0.12's", m.Description)
|
||||
}
|
||||
// the old version is the app's to delete, not the library's
|
||||
if _, err := os.Stat(filepath.Join(versions, "0.5.1.13/Resources/ego-skills/ego-browser/SKILL.md")); err != nil {
|
||||
t.Errorf("the old version's folder: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// An app with no Current link: the highest version beside the gone one
|
||||
// that has the same skill, by number (1.10 after 1.9).
|
||||
func TestOldImportFollowsHighestVersion(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
vs := filepath.Join(h, ".tool/versions")
|
||||
skill(t, filepath.Join(vs, "1.2.0/skills/review"), "review", "1.2.0")
|
||||
at := agentLink(t, h, "review", filepath.Join(vs, "1.2.0/skills/review"))
|
||||
oldImport(t, "review", at)
|
||||
skill(t, filepath.Join(vs, "1.9.0/skills/review"), "review", "1.9.0")
|
||||
skill(t, filepath.Join(vs, "1.10.0/skills/review"), "review", "1.10.0")
|
||||
skill(t, filepath.Join(vs, "2.0.0/other"), "other", "2.0.0") // no review here
|
||||
if err := os.RemoveAll(filepath.Join(vs, "1.2.0")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Read(nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, ok := readMeta(skillDir("review")); !ok || m.Description != "1.10.0" {
|
||||
t.Errorf("the library's review is %q, want 1.10.0's", m.Description)
|
||||
}
|
||||
}
|
||||
|
||||
// What isn't a version moved on from is left as it is: a folder of the
|
||||
// library's own, and a link to a folder the user deleted, which shows as
|
||||
// missing rather than being pointed at something else.
|
||||
func TestMovedSkillsLeaveTheRest(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
src := filepath.Join(h, "code/notes")
|
||||
skill(t, src, "notes", "Mine")
|
||||
agentLink(t, h, "notes", src)
|
||||
if _, err := ImportSkill("notes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
skill(t, filepath.Join(h, "code/notes-2"), "notes", "Another")
|
||||
own := filepath.Join(h, ".claude/skills/own")
|
||||
skill(t, own, "own", "Moved in")
|
||||
if _, err := ImportSkill("own"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.RemoveAll(src); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v, err := Read(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if to, err := os.Readlink(skillDir("notes")); err != nil || realBelow(to) != realBelow(src) {
|
||||
t.Errorf("notes links to %q (%v), want %s as it was", to, err, src)
|
||||
}
|
||||
for _, s := range v.Skills {
|
||||
if s.Name == "notes" && !s.Missing {
|
||||
t.Errorf("notes, deleted by the user, isn't shown missing")
|
||||
}
|
||||
}
|
||||
if fi, err := os.Lstat(skillDir("own")); err != nil || !fi.IsDir() {
|
||||
t.Errorf("the library's own folder: %v %v", fi, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionLess(t *testing.T) {
|
||||
for _, c := range [][2]string{{"1.9.0", "1.10.0"}, {"0.5.1.13", "0.6.0.12"}, {"v1.2", "v1.2.1"}, {"2.0.0-beta", "2.0.1"}} {
|
||||
if !versionLess(c[0], c[1]) || versionLess(c[1], c[0]) {
|
||||
t.Errorf("%s < %s", c[0], c[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,9 @@ func (l *Library) sync() *Result {
|
||||
// agents gone from here that still have what magpie gave them (held) only
|
||||
// have what was unticked taken out, after the rest.
|
||||
func syncSteps(all, gone []*Target, b *backups, res *Result) []func(*Library) {
|
||||
var steps []func(*Library)
|
||||
// a skill whose app moved it is followed first, for every agent to
|
||||
// get the moved one (skill_moved.go)
|
||||
steps := []func(*Library){func(l *Library) { l.followMovedSkills() }}
|
||||
for _, t := range all {
|
||||
steps = append(steps, func(l *Library) {
|
||||
l.syncInstructions(t, b, res)
|
||||
@@ -521,9 +523,7 @@ func Glance(problems []Problem) (*View, error) { return readView(problems, true)
|
||||
func readView(problems []Problem, glance bool) (*View, error) {
|
||||
mu.Lock()
|
||||
locked := true
|
||||
// each folder on the way to a path is looked at once while the lock
|
||||
// is held (linkmemo.go, #1771)
|
||||
forget := readParts()
|
||||
forget := func() {}
|
||||
defer func() {
|
||||
if locked {
|
||||
forget()
|
||||
@@ -534,6 +534,19 @@ func readView(problems []Problem, glance bool) (*View, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// each folder on the way to a path is looked at once while the lock
|
||||
// is held (linkmemo.go, #1771)
|
||||
forget = readParts()
|
||||
// a skill whose app moved it to its new version's folder is linked
|
||||
// there (skill_moved.go); what was kept of the links is let go then,
|
||||
// for the rest of the read to see the new one
|
||||
if l.followMovedSkills() {
|
||||
forget()
|
||||
forget = readParts()
|
||||
if err := l.save(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// a plugin's tools, a server of their own (plugin_tools.go): saved,
|
||||
// and given to the agents by a sync of their own
|
||||
if l.adoptPlugins() {
|
||||
|
||||
Reference in New Issue
Block a user