library: skills are grouped by source when the skills CLI keeps its lock under $XDG_STATE_HOME (@_yukirock on X)

skills 1.7 writes its global lock to $XDG_STATE_HOME/skills/.skill-lock.json
when that variable is set, and only to ~/.agents/.skill-lock.json otherwise.
The Library read only the ~/.agents one, so with XDG_STATE_HOME set every
`npx skills add` skill had no repository and the "By source" view could not
group them. Both locks are now read, the XDG one winning per skill, since a
lock written before the variable was set still names older skills.

XDG_STATE_HOME joins agentenv.Vars, so the desktop app takes it from the
login shell like the other folder variables (TestFolderVarsAreListed).

Not handled: a project install's ./skills-lock.json.

Run (worktree at origin/main 1eba266a9 plus this change):
- TestSkillRepoFromXDGLock: red on the old lock() (grill-me "", tdd
  "stale/repo"), green after.
- go test -p 2 -tags nogui -count=1 -timeout 45m ./...: 66 packages ok.
  The first run had TestFolderVarsAreListed red (fixed here) and
  TestMaxRPMWaitsForRoomInTheMinute red under load, the open #1791; the
  rerun had both green.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet clean.
This commit is contained in:
yetone
2026-10-17 01:22:21 +08:00
parent 1978eabe58
commit 9228bd443f
5 changed files with 48 additions and 2 deletions
+1 -1
View File
@@ -24,7 +24,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`) go first, marked official: `magpie-quota`, in [magpie-community/plugins](https://github.com/magpie-community/plugins/tree/main/skills/magpie-quota), lets an agent read `magpie quota --json` and wait with `magpie quota wait`. 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`) 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. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.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. `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. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.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) |
+3
View File
@@ -77,6 +77,9 @@ var Vars = []string{
"REASONIX_HOME",
// Reasonix's state folder, where it reads REASONIX.md
"REASONIX_STATE_HOME",
// the skills CLI's lock ($XDG_STATE_HOME/skills/.skill-lock.json), which
// the Library groups skills by; the desktop app has it from the login shell
"XDG_STATE_HOME",
// PI-Desktop's data folder, where Sessions reads its chat titles
"PI_DESKTOP_DATA_DIR",
// Mister Morph's config file
+1
View File
@@ -32,6 +32,7 @@ func sandbox(t *testing.T) string {
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("XDG_STATE_HOME", "")
// Gemini CLI is found by its binary alone
bin := filepath.Join(h, "bin")
testenv.Program(t, filepath.Join(bin, "gemini"), "#!/bin/sh\n")
+15 -1
View File
@@ -9,6 +9,8 @@ import (
"regexp"
"slices"
"strings"
"github.com/yetone/magpie/internal/appdir"
)
// Where a skill came from, for the page to group it with the others from
@@ -16,7 +18,7 @@ import (
// github.com/mattpocock/skills together, however each came in). One
// installed from GitHub says so itself; for the others it is traced:
// CC Switch's record, the skills CLI's lock (npx skills add, in
// ~/.agents/.skill-lock.json), the git checkout a linked folder is in,
// ~/.agents/.skill-lock.json or $XDG_STATE_HOME/skills), the git checkout a linked folder is in,
// or the repository the user installed from since that has the very same
// skill (From). It only groups: such a skill is not updated from there,
// unless the library's own copy is the repository's to the file, which
@@ -63,9 +65,21 @@ type tracer struct {
}
// lock is the skills CLI's lock: each skill's repository by its name.
// The CLI keeps it in ~/.agents, or under $XDG_STATE_HOME when that is set
// (skills 1.7: $XDG_STATE_HOME/skills/.skill-lock.json, the skills still
// in ~/.agents/skills). Both are read, the XDG one's entries winning: one
// written before the variable was set names skills the newer doesn't.
func (tr *tracer) lock() map[string]string {
if !tr.read {
tr.read, tr.locked = true, readSkillLock(filepath.Join(home(), ".agents", ".skill-lock.json"))
if x := appdir.Getenv("XDG_STATE_HOME"); x != "" {
for name, r := range readSkillLock(filepath.Join(x, "skills", ".skill-lock.json")) {
if tr.locked == nil {
tr.locked = map[string]string{}
}
tr.locked[name] = r
}
}
}
return tr.locked
}
+28
View File
@@ -24,6 +24,34 @@ func repoIn(t *testing.T) map[string]string {
return out
}
// npx skills add with $XDG_STATE_HOME set (@_yukirock on X): the skills
// CLI keeps its lock at $XDG_STATE_HOME/skills/.skill-lock.json and the
// skills in ~/.agents/skills, and each is grouped by the repository that
// lock names. One the older ~/.agents lock alone names is grouped too.
func TestSkillRepoFromXDGLock(t *testing.T) {
h := sandbox(t)
state := filepath.Join(h, "state")
t.Setenv("XDG_STATE_HOME", state)
for _, n := range []string{"grill-me", "tdd", "old"} {
skill(t, filepath.Join(h, ".agents/skills", n), n, n)
os.MkdirAll(filepath.Join(h, ".claude/skills"), 0o755)
dirLink(filepath.Join(h, ".agents/skills", n), filepath.Join(h, ".claude/skills", n))
}
write(t, filepath.Join(state, "skills/.skill-lock.json"), `{"version":3,"skills":{
"grill-me":{"source":"mattpocock/skills","sourceType":"github","sourceUrl":"https://github.com/mattpocock/skills.git"},
"tdd":{"source":"obra/superpowers","sourceType":"github","sourceUrl":"https://github.com/obra/superpowers.git"}}}`)
write(t, filepath.Join(h, ".agents/.skill-lock.json"), `{"version":3,"skills":{
"tdd":{"source":"stale/repo","sourceType":"github"},
"old":{"source":"me/old-skills","sourceType":"github"}}}`)
ok(t)(ImportSkills([]string{"grill-me", "tdd", "old"}))
got := repoIn(t)
for n, r := range map[string]string{"grill-me": "mattpocock/skills", "tdd": "obra/superpowers", "old": "me/old-skills"} {
if got[n] != r {
t.Errorf("%s: repo %q, want %q", n, got[n], r)
}
}
}
// A skill not installed from GitHub is grouped with the repository it
// came from all the same (White Immortal on Discord): the skills CLI's
// lock names it, or the git checkout it's in, whatever the remote's form,