Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

library: a skill's installed dependencies are no change of the user's

yetoned6284bf8a0aa
diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md
index c8cbd005f..f4b856a94 100644
--- a/docs/subsystems/library.md
+++ b/docs/subsystems/library.md
@@ -26,7 +26,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
| Skills market | `MarketSkills` lists skills.sh's most installed and what its search finds. magpie's own skills (`featuredSkills`), in [magpie-community/plugins](https://github.com/magpie-community/plugins/tree/main/skills), go first, marked official: `magpie-setup` has an agent set magpie up as the user asks through its commands (providers, accounts, agents, routing groups and rules, gateway keys and limits, models, the library), and `magpie-quota` lets an agent read `magpie quota --json` and wait with `magpie quota wait`. Their commands live in magpie's CLI, so a change to a command either uses gets the skill updated in that repository. Until skills.sh lists one it has no count of installs and no skills.sh link (`featured`). `InstallMarketSkill` installs any of them from its repository. | [`market.go`](../../internal/library/market.go) |
| Skills a repository added | A check for updates (`CheckSkills`) also asks, for each GitHub repository and ref the library has skills from, GitHub's list of its files (`repoTree`, one API request, free when the ETag still matches). Only when that list has a skill folder beside the installed ones (under `newBase`, their deepest common folder) that the library doesn't have and hasn't offered does `findNew` fetch the repository for the skills' names and descriptions. `SeenSkills` records per `repo@ref` the paths the install picker showed and the ones set aside, so they aren't offered again. The finds live in memory (`newFound`) and reach the page as `View.NewSkills`; `AddNewSkills` gives each to the agents that have its repository's other skills, and `IgnoreNewSkills` sets it aside (`/api/library/skills/{add-new,ignore-new}`). | [`skillnew.go`](../../internal/library/skillnew.go), [`skillcheck.go`](../../internal/library/skillcheck.go) |
| Skill groups | The page groups skills by `SkillView.Repo`, the repository each came from (`tracer.repoOf`): its GitHub source, CC Switch's `Origin`, `From`, the skills CLI's lock or the git checkout a linked folder is in. A lock entry of `sourceType: well-known` (a site's kit at its `/.well-known/agent-skills/`) is grouped by its `sourceBaseUrl` as host/path (`wellKnownBase`), not by each skill's own `sourceUrl`: Feishu's lark-* skills are one group and Fish Audio's another, while two kits under one host with different base URLs stay apart. An older entry with no base URL takes the part of its `sourceUrl` before `/.well-known/`, and one with neither is grouped by its `sourceUrl` as before. Such a kit is never fetched from GitHub by Group again, even when it reads like owner/repo (a GitHub owner has no dot), and its heading's link opens the site (#1862, `TestWellKnownKitGrouped`). `From` is written when a repository is probed (installing from it again, `noteFrom`): for a skill with the very same `SKILL.md`, and for one traced to nowhere by a name the repository has when the library has others from there, since a pack added a while ago is mostly older copies edited there since (White Immortal on Discord: 20 of mattpocock/skills' 38). Group again (`RegroupSkills`, `POST /api/library/skills/regroup`) fetches each GitHub repository the skills are traced to and does the same; it fails only when none could be fetched. A skill traced to another repository is never moved. A group's (or part's, or the Select bar's) agent chips count, give and take only the skills magpie decides for each agent: one kept in `~/.agents/skills` is in `SkillView.Always` for the agents that read that folder themselves, so a chip's `agents-some` for such an agent leaves it out, its tooltip and the status after a click say how many it still reads itself, and an agent that reads every one of them itself has a lit, locked chip as the row's is, which sends nothing (`groupChips` in plugins/library/client.js). The heading says how many of its skills are in `~/.agents/skills`. A row's locked chip is lit with a lock on its corner, not greyed like a chip that can't be given the skill (#1862, `skill-group-shared.test.cjs`). Collapse all / Expand all, beside the sort, folds or opens every group the list shows at once (`foldAllButton`): without a filter it sets each group's kept fold (`magpie.libSkillFolds`), as a click on each heading would; while filtering, only the groups the filter shows, till the filter changes (`unfiltered`), leaving the kept folds alone. It reads Collapse all while any shown group is open, is hidden with fewer than two groups (A→Z, or a filter one group matches), leaves a part's own fold as it is and sends nothing (#1862, `skill-fold-all.test.cjs`). | [`skill_from.go`](../../internal/library/skill_from.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
-| Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`, or `$XDG_STATE_HOME/skills/.skill-lock.json` when that is set, both read with the XDG one winning) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. A skill from another git repository (`kind: git`) keeps the repository's head commit it was fetched at in `Commit`, and `Hash`. A check runs `git ls-remote` for the ref (`gitRemoteHead`): the same head is current; another one is fetched shallowly, once per repository and ref in a check, and the skill's folder hashed, so a commit that left the skill as it was is current and its head is kept as `Commit` (`checkGitSkill`). Its `*EditedError` and the page's Changed here, Update and the question before replacing a change name that repository, not GitHub (`editedError`, `skill-git-source.test.cjs`). New skills in such a repository (`findNew`), Group again, icons and the market are GitHub's only. A skill whose source was read whole and no longer has its folder or `SKILL.md` was removed there (`goneFrom`; スライム on Discord): `UpdateSkill` returns `*GoneError`, `UpdateSkills`/`UpdateSomeSkills` list it in `Result.Gone`, not `Unupdated`, and a check gives it status `gone`. Each records `Skill.Gone` (the view's `gone`), cleared when a check or an update finds it there again. A fetch that failed, a skill left out of a fetch as too big (`leftOutAt`) and a folder that can't be read are unknown, never gone. Nothing is taken out by itself: `RemoveGoneSkills` (`POST /api/library/skills/remove-gone`, `magpie library skill rm --gone [--yes]`, the TUI's `d` on the row) takes the ones named, or every one marked, as `RemoveSkills` does, folders to the backups, and keeps one found in its source again. The page tags such a row Removed upstream with no Update, says them apart from failures after Update all, and offers Clean up N in the group's heading (in the bar with one group), which asks first, naming each one and which was changed here (`confirmRemoveGone`, `skill-gone.test.cjs`). | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skillgit.go`](../../internal/library/skillgit.go), [`skills.go`](../../internal/library/skills.go) |
+| Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. What installing a skill's dependencies or running it writes in its folder is no change (`fromInstall`: `node_modules`, `.venv`, `venv`, `__pycache__`, `.pytest_cache`, `.mypy_cache`, `.ruff_cache` folders, `*.pyc`/`*.pyo`, and `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock`, `bun.lockb`, `uv.lock` written again; ggbr on Discord): `Own` is the hash of the files as fetched leaving those aside (`ownHash`), and `onlyInstalled` compares the folder with it, or for a skill fetched before `Own` was kept with `Hash` (so a lock file the install wrote again still reads as changed until its next update). An update carries those entries over to the version fetched where it has none of its own (`carryInstalled`), so they aren't installed again. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`, or `$XDG_STATE_HOME/skills/.skill-lock.json` when that is set, both read with the XDG one winning) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. A skill from another git repository (`kind: git`) keeps the repository's head commit it was fetched at in `Commit`, and `Hash`. A check runs `git ls-remote` for the ref (`gitRemoteHead`): the same head is current; another one is fetched shallowly, once per repository and ref in a check, and the skill's folder hashed, so a commit that left the skill as it was is current and its head is kept as `Commit` (`checkGitSkill`). Its `*EditedError` and the page's Changed here, Update and the question before replacing a change name that repository, not GitHub (`editedError`, `skill-git-source.test.cjs`). New skills in such a repository (`findNew`), Group again, icons and the market are GitHub's only. A skill whose source was read whole and no longer has its folder or `SKILL.md` was removed there (`goneFrom`; スライム on Discord): `UpdateSkill` returns `*GoneError`, `UpdateSkills`/`UpdateSomeSkills` list it in `Result.Gone`, not `Unupdated`, and a check gives it status `gone`. Each records `Skill.Gone` (the view's `gone`), cleared when a check or an update finds it there again. A fetch that failed, a skill left out of a fetch as too big (`leftOutAt`) and a folder that can't be read are unknown, never gone. Nothing is taken out by itself: `RemoveGoneSkills` (`POST /api/library/skills/remove-gone`, `magpie library skill rm --gone [--yes]`, the TUI's `d` on the row) takes the ones named, or every one marked, as `RemoveSkills` does, folders to the backups, and keeps one found in its source again. The page tags such a row Removed upstream with no Update, says them apart from failures after Update all, and offers Clean up N in the group's heading (in the bar with one group), which asks first, naming each one and which was changed here (`confirmRemoveGone`, `skill-gone.test.cjs`). | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skillgit.go`](../../internal/library/skillgit.go), [`skills.go`](../../internal/library/skills.go) |
| Hooks | A `Hook` (#1790) is a command, an event, an optional matcher, a timeout and the agents ticked for it. Its optional `Description` (#2011) says what it is for in any language, since its name is letters, digits, - and _: one line of at most `maxHookDescription` (200) characters, shown under the name; only library.json keeps it, and no agent is given it. Its event is portable (`HookEvents`: turn-end, after-tool, before-tool, prompt, session-start, each under the agent's own name) or an agent's own (`"codex:PermissionRequest"`), which only that agent is given. A portable tool event can be narrowed to shell or edit tools, each agent's own tool names for them. `syncHooks` writes each into the agent's own file and shape (`hookSpecOf`): Claude Code `<claude dir>/settings.json`, Codex `hooks.json` beside its config.toml, Gemini CLI `~/.gemini/settings.json` (timeout in ms), Cursor `~/.cursor/hooks.json` (flat entries, `version: 1`), and Grok Build `~/.grok/config.toml` and Grok App `agent-home/config.toml` as `[[hooks.<Event>]]` array tables with a `[[hooks.<Event>.hooks]]` child. Grok Build and Grok App run the one CLI, so a `grok:<Event>` own event goes to both (`sameHookFamily`). Every other agent, and an agent in WSL, is refused with why, and the page greys its chip with that reason. The page also says when an agent has every hook turned off (`hooksOff`: Claude Code's `disableAllHooks`, Gemini's `hooksConfig.enabled`, Codex's `[features] hooks`). | [`hooks.go`](../../internal/library/hooks.go) |
| Subagents | A `Subagent` (#2283) is a name (lowercase letters, digits and -), a one-line description, a prompt, and the library's skills and MCP servers it uses, given to the agents ticked for it. `syncSubagents` writes it as a file of its own in each agent's user-level folder, in that agent's format (`subagentSpecOf`): Markdown with YAML front matter in `~/.claude/agents` (with `skills` and `mcpServers`), `~/.factory/droids` (with `mcpServers`), `~/.config/opencode/agents` (`mode: subagent`), `~/.gemini/agents`, `~/.qwen/agents`, `~/.grok/agents`, `~/.cursor/agents` and `~/.copilot/agents` (`<name>.agent.md`); a TOML role (`name`, `description`, `developer_instructions`) in `$CODEX_HOME/agents`. Skills and servers are named only where the agent's file can name them, and only those the library has. The page lists, per agent, whether it binds skills and servers (`SubagentAgentView`) and greys out an agent that takes none. | [`subagents.go`](../../internal/library/subagents.go) |
| Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/backup.go) |
diff --git a/internal/library/skill_changed.go b/internal/library/skill_changed.go
index db84b8407..c01178da2 100644
--- a/internal/library/skill_changed.go
+++ b/internal/library/skill_changed.go
@@ -10,15 +10,70 @@ package library
// asks first, an update of many leaves it as it is, and the version an
// update replaces is kept with the backups unless it is known to be
// GitHub's own.
+//
+// A skill may ask to have its dependencies installed in its own folder
+// (npm install in easyeda-api-skill; ggbr on Discord). What that writes
+// (node_modules, a Python virtualenv, bytecode, the lock file written
+// again) is the install's, not a change of the user's: it neither marks
+// the skill changed nor is lost to an update, which carries it over to
+// the version fetched (carryInstalled).
import (
"fmt"
+ "io/fs"
+ "log"
"os"
"path/filepath"
+ "strings"
"sync"
"time"
)
+// installedDirs are the folders installing a skill's dependencies, or
+// running it, makes in it, wherever in it they are.
+var installedDirs = map[string]bool{
+ "node_modules": true,
+ ".venv": true,
+ "venv": true,
+ "__pycache__": true,
+ ".pytest_cache": true,
+ ".mypy_cache": true,
+ ".ruff_cache": true,
+}
+
+// lockFiles are what a package manager writes again as it installs, even
+// over the one the skill came with.
+var lockFiles = map[string]bool{
+ "package-lock.json": true,
+ "yarn.lock": true,
+ "pnpm-lock.yaml": true,
+ "bun.lock": true,
+ "bun.lockb": true,
+ "uv.lock": true,
+}
+
+// fromInstall is whether an entry of a skill's folder called name was
+// written by installing its dependencies or running it rather than by
+// hand: one of installedDirs (a folder, or a link to one), compiled
+// Python, and with locks a lock file.
+func fromInstall(name string, dir, locks bool) bool {
+ if dir && installedDirs[name] {
+ return true
+ }
+ if dir {
+ return false
+ }
+ if strings.HasSuffix(name, ".pyc") || strings.HasSuffix(name, ".pyo") {
+ return true
+ }
+ return locks && lockFiles[name]
+}
+
+// ownHash is the hash of a skill's folder leaving aside, as well as what
+// Finder keeps in it, what installing its dependencies writes: what is
+// the skill's own. "" when it can't be read.
+func ownHash(dir string) string { return rememberedHash(dir, leaveInstalled) }
+
// EditedError is an update refused because the skill was changed here
// since it was fetched from GitHub, or From, the git repository it came
// from.
@@ -92,13 +147,16 @@ func (l *Library) editState(s *Skill, targets []*Target) (edited, known bool) {
if linked(lib) {
return false, false
}
- h := libraryHash(s.Name)
- if h == "" {
- return false, false
- }
- // the fetched files may hold a .DS_Store of their own
- if h != s.Hash && hashDir(lib) != s.Hash {
- return true, true
+ // asked first: the hashes after it read every installed dependency
+ if !onlyInstalled(s, lib) {
+ h := libraryHash(s.Name)
+ if h == "" {
+ return false, false
+ }
+ // the fetched files may hold a .DS_Store of their own
+ if h != s.Hash && hashDir(lib) != s.Hash {
+ return true, true
+ }
}
for _, t := range targets {
if t.Skills == "" || t.Desktop != nil || !s.gives(t.Agent.ID) {
@@ -121,13 +179,67 @@ func (l *Library) editState(s *Skill, targets []*Target) (edited, known bool) {
if !at.After(made) {
continue
}
- if !sameTree(p, lib) {
+ if !sameTree(p, lib) && ownHash(p) != ownHash(lib) {
return true, true
}
}
return false, true
}
+// onlyInstalled is whether the library's folder of s differs from the
+// files fetched only by what installing its dependencies wrote. Own is
+// kept from when this was known; one fetched before has only Hash, and
+// is the same when the lock file it may have come with was left as it
+// was, or it came with none.
+func onlyInstalled(s *Skill, lib string) bool {
+ if s.Own != "" {
+ h := ownHash(lib)
+ return h != "" && h == s.Own
+ }
+ if h := rememberedHash(lib, leaveBuilt); h != "" && h == s.Hash {
+ return true
+ }
+ h := ownHash(lib)
+ return h != "" && h == s.Hash
+}
+
+// carryInstalled moves what installing a skill's dependencies wrote in
+// its folder as it was, old, to the folder an update put in its place,
+// so they needn't be installed again: what the new version doesn't have
+// itself. What can't be moved stays in old.
+func carryInstalled(old, dir string) {
+ filepath.WalkDir(old, func(p string, d fs.DirEntry, err error) error {
+ if err != nil || p == old {
+ return nil
+ }
+ if d.IsDir() && d.Name() == ".git" {
+ return filepath.SkipDir
+ }
+ isDir := d.IsDir() || d.Type()&fs.ModeSymlink != 0
+ if !fromInstall(d.Name(), isDir, true) {
+ return nil
+ }
+ rel, _ := filepath.Rel(old, p)
+ dst := filepath.Join(dir, rel)
+ if _, err := os.Lstat(dst); err == nil {
+ // the new version's own, as fetched
+ if d.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ }
+ if err := os.MkdirAll(filepath.Dir(dst), 0o755); err == nil {
+ if err := os.Rename(p, dst); err != nil {
+ log.Printf("library: %s stays with the version replaced: %v", rel, err)
+ }
+ }
+ if d.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ })
+}
+
// keepReplaced moves the library's version of a skill an update replaces
// to the backups, where it is found as an edit taken over is.
func keepReplaced(name, old string) (string, error) {
diff --git a/internal/library/skill_from.go b/internal/library/skill_from.go
index a7abd76c5..b48bb3eef 100644
--- a/internal/library/skill_from.go
+++ b/internal/library/skill_from.go
@@ -322,7 +322,7 @@ func noteFrom(src Source, root string, cands []Candidate) int {
// git checkout), and an edited one stays only grouped.
if dir := skillDir(s.Name); s.Source == nil && !linked(dir) && sameTree(dir, filepath.Join(root, filepath.FromSlash(c.Path))) {
s.Source = &Source{Kind: "github", Repo: src.Repo, Ref: src.Ref, Path: c.Path}
- s.Hash, s.Commit, s.From = hashDir(dir), "", ""
+ s.Hash, s.Own, s.Commit, s.From = hashDir(dir), ownHash(dir), "", ""
l.seenAt(src.Repo, src.Ref, c.Path)
forgetCheck(s.Name)
bound++
diff --git a/internal/library/skill_installed_test.go b/internal/library/skill_installed_test.go
new file mode 100644
index 000000000..7cdca3606
--- /dev/null
+++ b/internal/library/skill_installed_test.go
@@ -0,0 +1,175 @@
+package library
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+ "time"
+)
+
+// fakeDepsTarball serves a repository whose skills/eda asks for its
+// dependencies to be installed (easyeda-api-skill: package.json and
+// package-lock.json beside SKILL.md), saying version.
+func fakeDepsTarball(t *testing.T, version *string) {
+ t.Helper()
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write(tarball(t, map[string]string{
+ "skills/eda/SKILL.md": "---\nname: eda\ndescription: EDA " + *version + "\n---\nRun npm install first.\n",
+ "skills/eda/package.json": `{"name":"eda","version":"` + *version + `"}`,
+ "skills/eda/package-lock.json": `{"lockfileVersion":3,"v":"` + *version + `"}`,
+ "skills/eda/run.py": "print('" + *version + "')\n",
+ }))
+ }))
+ t.Cleanup(srv.Close)
+ old := tarballURL
+ tarballURL = func(repo, ref string) string { return srv.URL + "/" + repo + "/" + ref }
+ t.Cleanup(func() { tarballURL = old })
+}
+
+// installDeps writes in dir what npm install and running the skill's
+// Python do: node_modules with a link in .bin, a virtualenv, bytecode, and
+// the lock file written again.
+func installDeps(t *testing.T, dir string) {
+ t.Helper()
+ write(t, filepath.Join(dir, "node_modules/left-pad/index.js"), "module.exports = 1")
+ bin := filepath.Join(dir, "node_modules/.bin")
+ if err := os.MkdirAll(bin, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ os.Remove(filepath.Join(bin, "left-pad"))
+ if err := os.Symlink("../left-pad/index.js", filepath.Join(bin, "left-pad")); err != nil {
+ t.Skip(err)
+ }
+ write(t, filepath.Join(dir, ".venv/bin/python"), "python")
+ write(t, filepath.Join(dir, "__pycache__/run.cpython-312.pyc"), "bytecode")
+ write(t, filepath.Join(dir, "package-lock.json"), `{"lockfileVersion":3,"packages":{"node_modules/left-pad":{}}}`)
+}
+
+// ggbr on Discord: a skill whose SKILL.md says to install its
+// dependencies was said to be changed here once they were, so an update
+// of every skill left it out and its own asked to replace "your changes".
+// What the install writes is no change of the user's: the skill isn't
+// said to be changed, updates with the rest, and its dependencies go on
+// with the version fetched. A file the user did change still counts.
+func TestInstalledDependenciesAreNoChange(t *testing.T) {
+ sandbox(t)
+ version := "one"
+ fakeDepsTarball(t, &version)
+ ok(t)(InstallSkills("owner/eda", []string{"skills/eda"}, []string{"claude"}))
+ dir := skillDir("eda")
+ installDeps(t, dir)
+ if s := skillView(t, "eda"); s.Edited {
+ t.Fatal("installing eda's dependencies made it changed here")
+ }
+
+ version = "two"
+ res, err := UpdateSkills()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !slices.Equal(res.Updated, []string{"eda"}) || len(res.Unupdated) != 0 {
+ t.Fatalf("updated %v, unupdated %+v", res.Updated, res.Unupdated)
+ }
+ if s := read(t, filepath.Join(dir, "run.py")); s != "print('two')\n" {
+ t.Fatalf("run.py after the update: %q", s)
+ }
+ // the new version's lock file is its own; what was installed stays
+ if s := read(t, filepath.Join(dir, "package-lock.json")); s != `{"lockfileVersion":3,"v":"two"}` {
+ t.Fatalf("package-lock.json after the update: %q", s)
+ }
+ for _, p := range []string{"node_modules/left-pad/index.js", ".venv/bin/python", "__pycache__/run.cpython-312.pyc"} {
+ if _, err := os.Stat(filepath.Join(dir, p)); err != nil {
+ t.Errorf("%s didn't go on with the update: %v", p, err)
+ }
+ }
+ if to, err := os.Readlink(filepath.Join(dir, "node_modules/.bin/left-pad")); err != nil || filepath.ToSlash(to) != "../left-pad/index.js" {
+ t.Errorf("node_modules/.bin/left-pad: %q, %v", to, err)
+ }
+ if got, _ := filepath.Glob(filepath.Join(BackupDir(), "*", "library", "skills", "eda")); len(got) != 0 {
+ t.Errorf("eda, only installed, was kept with the backups: %v", got)
+ }
+ if s := skillView(t, "eda"); s.Edited || s.Description != "EDA two" {
+ t.Fatalf("eda after the update: %+v", s)
+ }
+
+ // the install again, over the new version's lock file, then an edit
+ installDeps(t, dir)
+ if s := skillView(t, "eda"); s.Edited {
+ t.Fatal("installing again after the update made eda changed here")
+ }
+ write(t, filepath.Join(dir, "run.py"), "print('mine')\n")
+ if s := skillView(t, "eda"); !s.Edited {
+ t.Fatal("eda's run.py edited here isn't said to be")
+ }
+ version = "three"
+ res, err = UpdateSkills()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(res.Updated) != 0 || len(res.Unupdated) != 1 {
+ t.Fatalf("updated %v, unupdated %+v", res.Updated, res.Unupdated)
+ }
+ if s := read(t, filepath.Join(dir, "run.py")); s != "print('mine')\n" {
+ t.Fatalf("updating every skill wrote over the edit: %q", s)
+ }
+}
+
+// A skill fetched before magpie kept Own has only Hash, of the files
+// fetched with their lock file: installed folders and bytecode are no
+// change, and nor is the lock file left as it came. One the install
+// wrote again can't be told from an edit until the skill is updated.
+func TestInstalledDependenciesBeforeOwnWasKept(t *testing.T) {
+ sandbox(t)
+ version := "one"
+ fakeDepsTarball(t, &version)
+ ok(t)(InstallSkills("owner/eda", []string{"skills/eda"}, []string{"claude"}))
+ mu.Lock()
+ l, err := load()
+ if err == nil {
+ l.skill("eda").Own = ""
+ err = l.save()
+ }
+ mu.Unlock()
+ if err != nil {
+ t.Fatal(err)
+ }
+ dir := skillDir("eda")
+ lock := read(t, filepath.Join(dir, "package-lock.json"))
+ installDeps(t, dir)
+ write(t, filepath.Join(dir, "package-lock.json"), lock)
+ if s := skillView(t, "eda"); s.Edited {
+ t.Fatal("eda's installed folders made it changed here")
+ }
+ write(t, filepath.Join(dir, "package-lock.json"), lock+" ")
+ if s := skillView(t, "eda"); !s.Edited {
+ t.Fatal("with no Own, a lock file written again is no longer told as changed")
+ }
+}
+
+// An agent given its skills as copies runs the install in its copy: that
+// copy isn't changed by the user either.
+func TestInstalledDependenciesInACopy(t *testing.T) {
+ h := sandbox(t)
+ version := "one"
+ fakeDepsTarball(t, &version)
+ ok(t)(InstallSkills("owner/eda", []string{"skills/eda"}, []string{"claude"}))
+ ok(t)(SetSkillHow("", HowCopy))
+ p := filepath.Join(h, ".claude/skills/eda")
+ if linked(p) {
+ t.Fatal("claude's eda is still a link")
+ }
+ installDeps(t, p)
+ later := time.Now().Add(2 * time.Second)
+ os.Chtimes(filepath.Join(p, "node_modules/left-pad/index.js"), later, later)
+ if s := skillView(t, "eda"); s.Edited {
+ t.Fatal("installing in Claude Code's copy made eda changed here")
+ }
+ write(t, filepath.Join(p, "run.py"), "print('mine')\n")
+ os.Chtimes(filepath.Join(p, "run.py"), later, later)
+ if s := skillView(t, "eda"); !s.Edited {
+ t.Fatal("run.py edited in Claude Code's copy isn't said to be")
+ }
+}
diff --git a/internal/library/skillcheck.go b/internal/library/skillcheck.go
index 69b267539..f9266cef7 100644
--- a/internal/library/skillcheck.go
+++ b/internal/library/skillcheck.go
@@ -219,13 +219,27 @@ func hashDir(dir string) string { return hashFiles(dir, false) }
// a folder it shows when noFinder is set. A folder unchanged since it was
// last hashed isn't read again (treememo.go).
func hashFiles(dir string, noFinder bool) string {
- return rememberedHash(dir, noFinder)
+ if noFinder {
+ return rememberedHash(dir, leaveFinder)
+ }
+ return rememberedHash(dir, leaveNothing)
}
+// leave is what a hash of a skill's folder leaves aside, beyond its .git
+// and magpie's mark.
+type leave uint8
+
+const (
+ leaveNothing leave = iota
+ leaveFinder // .DS_Store
+ leaveBuilt // that, and what installing dependencies builds (fromInstall)
+ leaveInstalled // that, and the lock files an install writes again
+)
+
// hashWalk walks dir as hashFiles reads it, stamping each file and link
// it would hash (treememo.go); with read, it also hashes their bytes. ok
// is false when it can't be walked, or a file can't be read.
-func hashWalk(dir string, noFinder, read bool) (hash, stamp string, settled, ok bool) {
+func hashWalk(dir string, lv leave, read bool) (hash, stamp string, settled, ok bool) {
h := sha256.New()
st := newStamper()
err := filepath.WalkDir(dir, func(p string, d fs.DirEntry, err error) error {
@@ -234,6 +248,12 @@ func hashWalk(dir string, noFinder, read bool) (hash, stamp string, settled, ok
}
rel, _ := filepath.Rel(dir, p)
rel = filepath.ToSlash(rel)
+ if p != dir && lv >= leaveBuilt && fromInstall(d.Name(), d.IsDir() || d.Type()&fs.ModeSymlink != 0, lv == leaveInstalled) {
+ if d.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ }
switch {
case d.IsDir():
if d.Name() == ".git" && p != dir {
@@ -249,7 +269,7 @@ func hashWalk(dir string, noFinder, read bool) (hash, stamp string, settled, ok
t, _ := os.Readlink(p)
fmt.Fprintf(h, "link %s %s\n", rel, filepath.ToSlash(t))
}
- case d.Type().IsRegular() && rel != marker && !(noFinder && d.Name() == ".DS_Store"):
+ case d.Type().IsRegular() && rel != marker && !(lv >= leaveFinder && d.Name() == ".DS_Store"):
fi, err := d.Info()
if err != nil {
return err
diff --git a/internal/library/skills.go b/internal/library/skills.go
index 21ff11a57..700e14150 100644
--- a/internal/library/skills.go
+++ b/internal/library/skills.go
@@ -39,6 +39,10 @@ type Skill struct {
// Commit is the commit of the repository it was fetched at.
Hash string `json:"hash,omitempty"`
Commit string `json:"commit,omitempty"`
+ // Own is Hash leaving aside what installing the skill's dependencies
+ // writes (ownHash): set as it is fetched, so a lock file the install
+ // writes again isn't taken for a change of the user's
+ Own string `json:"own,omitempty"`
// From is the repository one not installed from GitHub was found to
// come from (skill_from.go), only to group it with the rest of it
From string `json:"from,omitempty"`
@@ -1339,10 +1343,10 @@ func installFrom(l *Library, p *Probe, paths, agents []string, shown bool, in *i
}
sk := &Skill{Name: c.Name, Source: &src, Agents: slices.Clone(agents)}
if src.Kind == "git" {
- sk.Hash, sk.Commit = hashDir(dir), gitHeadOf(p.root)
+ sk.Hash, sk.Own, sk.Commit = hashDir(dir), ownHash(dir), gitHeadOf(p.root)
}
if src.Kind == "github" {
- sk.Hash = hashDir(dir)
+ sk.Hash, sk.Own = hashDir(dir), ownHash(dir)
// every skill the picker showed was offered: a check
// offers only those the repository adds later
l.seenAt(src.Repo, src.Ref, c.Path)
@@ -1648,7 +1652,7 @@ func (up *skillUpdate) apply(l *Library, targets []*Target) error {
os.RemoveAll(next)
return err
}
- hash := hashDir(next)
+ hash, own := hashDir(next), ownHash(next)
if fi, err := os.Lstat(skillDir(name)); err == nil && linkEntry(fi) {
// a link to CC Switch's folder: only the link goes
if err := os.Remove(skillDir(name)); err != nil {
@@ -1672,13 +1676,15 @@ func (up *skillUpdate) apply(l *Library, targets []*Target) error {
}
// the commit it's at is known again once a check finds the files
// GitHub has to be these; a git repository's is the one fetched
- s.Hash, s.Commit = hash, up.commit
+ s.Hash, s.Own, s.Commit = hash, own, up.commit
s.Gone = "" // its source has it again
}
forgetCheck(name)
if old == "" {
return nil
}
+ // its installed dependencies go on with it
+ carryInstalled(old, skillDir(name))
if keep {
var lb *leftBehind
if _, err := keepReplaced(name, old); err != nil && !errors.As(err, &lb) {
diff --git a/internal/library/treememo.go b/internal/library/treememo.go
index 6ec3f2305..4123bae81 100644
--- a/internal/library/treememo.go
+++ b/internal/library/treememo.go
@@ -62,27 +62,27 @@ type treeMemo struct {
var memo = struct {
sync.Mutex
- hashes map[string]hashMemo // dir and noFinder: the folder's hash
+ hashes map[string]hashMemo // dir and what is left aside: the folder's hash
trees map[[2]string]treeMemo // two folders: whether they hold the same
}{hashes: map[string]hashMemo{}, trees: map[[2]string]treeMemo{}}
-// rememberedHash is hashFiles(dir, noFinder): the hash found before, while
-// a walk finds dir as it was then, else read. A folder hashed for the
-// first time is walked once, as before the memo.
-func rememberedHash(dir string, noFinder bool) string {
- key := fmt.Sprintf("%t\x00%s", noFinder, dir)
+// rememberedHash is the hash of dir leaving lv aside: the hash found
+// before, while a walk finds dir as it was then, else read. A folder
+// hashed for the first time is walked once, as before the memo.
+func rememberedHash(dir string, lv leave) string {
+ key := fmt.Sprintf("%d\x00%s", lv, dir)
memo.Lock()
m, hit := memo.hashes[key]
memo.Unlock()
if hit {
- if _, stamp, _, ok := hashWalk(dir, noFinder, false); ok && stamp == m.stamp {
+ if _, stamp, _, ok := hashWalk(dir, lv, false); ok && stamp == m.stamp {
return m.hash
}
memo.Lock()
delete(memo.hashes, key)
memo.Unlock()
}
- h, stamp, settled, ok := hashWalk(dir, noFinder, true)
+ h, stamp, settled, ok := hashWalk(dir, lv, true)
if !ok {
return ""
}