library: a Claude plugin goes to another computer whole, its hooks naming that computer's folder (#6685)
A plugin installed from Library > Claude plugins didn't reach the other
computer by sync: the bundle carried its parts as plain items, with
${CLAUDE_PLUGIN_ROOT} already resolved to the first computer's
<library>/plugins/<name>, and neither the plugin record nor its folder.
Hooks there pointed at a path that doesn't exist, Windows' too.
Now Bundle.Plugins carries each plugin's record (name, version, source,
pick, agents, Off, parts taken out by hand) and never its parts:
- A GitHub or git link goes as its source. The receiving computer
installs it from there, as UpdatePlugin does, after the library's lock
is let go. Re-installing from the source was chosen because the files
stay the vendor's and an update keeps working there; a fetch that
fails keeps the plugin Pending (shown on its row, "Update tries again")
with a problem, and the next sync or Update tries again.
- A plugin from a local folder, or from a link holding a token (whose
link must not be synced), goes with its files on the skills' budget,
executables kept executable, and is installed from them.
- Either way the parts are read again there, so every hook, server and
skill names that computer's own plugin folder. A plugin the bundle no
longer has is removed with its folder; Off spreads.
- A bundle from an older magpie has no plugins list: this computer's
plugins keep their parts over the same-named items it carries.
- An empty list hashes as before, so computers without plugins don't
see a change; the preview names each plugin, its files as one digest.
- Sibling: a plugin installed from a marketplace under a name other
than its manifest's named the manifest's folder in its parts.
- The sync settings' text says Claude plugins go with the Library (en,
zh, zh-TW, ja, de); "Claude plugins" moved into the core i18n.js since
the core now says it.
Run at this head (54e682dc5's tree on f1b0663f1, mote):
- go test -tags nogui -timeout 45m ./internal/library ./internal/davsync
./internal/backup: ok
- gofmt -l: empty; go vet GOOS=darwin (library, davsync, backup, gui),
GOOS=linux -tags nogui ./..., GOOS=windows ./...: clean
- Windows (win-run, xiaomi-gpu): go test ./internal/library -run
TestPlugin and ./internal/davsync -run Plugin: ok. The hook there names
B's C:\...\plugins\kit/bin/done (TestSyncLibraryPlugins first failed
on Windows for the test's own path form; fixed in the test).
- GUI, Chromium and WebKit, every language the files test:
library-plugins, library-items, agent-plugin-agents, i18n-keys,
i18n-en-no-cjk, old-webkit, every sync-*, github-sync, s3-sync,
auto-backup: 337 pass, 1 fail: webkit en "S3 sync settings", red the
same at origin/main f1b0663f1 (#2448, #3413, open).
Broken by hand, each red, then restored:
- parts not skipped and Plugins not set in Collect:
TestPluginCarriedWhole, TestPluginCarriedBySource,
TestSyncLibraryPlugins
- held.without dropped: TestPluginOldBundleKeepsPlugins
- fetchPlugins dropped: TestPluginCarriedBySource
- marketplace name fix reverted: TestPluginMarketplaceNameIsItsFolder
- empty list not hashed as none: TestNoPluginsHashAsBefore
- TestPluginFromFilesEitherOS guards that a Mac path is files on
Windows and C:\ on a Mac; it passed without a new check (such paths
are no git source), so none was added.
Not tried:
- a real two-computer sync through the GUI, Mac to Windows;
- a local marketplace entry's own fields (strict: false) aren't carried,
so there it is read from its files alone;
- a private git source over ssh on the receiving computer.
Reported by JJasonsun on Discord; issue by JJasonSun (#6685).
This commit is contained in:
@@ -39,7 +39,7 @@ Pi's extensions and packages.
|
||||
| Subagents from a repository | The Subagents tab's find line (CHENGJIAHEGOXIS on X: msitarzewski/agency-agents) takes what the skill installer does, owner/repo, a GitHub or GitLab link to the repository, a folder or a file in it, any git address, or a folder here, and fetches it the same way (`fetchSourceRoot`, shared with `resolvePluginRoot`; `tooBig` refuses a whole repository too big to download and asks for its folder's link). `ProbeSubagents` lists each Markdown file with front matter that has a description (`readSubagentAt`): its name is the slug of `name` (`subagentName`), else the file's own name when it sits in an `agents` or `droids` folder; its description is folded to one line of at most 1000 characters; the body is the prompt. Every other key (`color`, `emoji`, `vibe`, `tools`, `author`, `model`, …) is dropped, a Codex TOML role is not read, and a skill's folder (one with a SKILL.md) and `.git`, `.github`, `node_modules` are skipped. Of two files with one name the shallower is taken and the other is listed in `Left` with why, as is one `Subagent.check` refuses (a reserved name). `ImportSubagents` (`POST /api/library/subagents/probe`, then `subagents/import` with `source`, `paths`, `agents`) adds the picked ones for the agents ticked, recording where each came from (`From`, a `Source` with the file's path) and the hash of its description and prompt as imported (`FromHash`). Imported again, from the repository's link or a folder's or a file's, a subagent from the same file is `have` when it is the same, `update` when upstream changed and the library's still matches `FromHash` (its description and prompt are replaced, its agents, skills, servers and model kept), and `edited` when the user changed it here (`SaveSubagent` keeps `From`; it is left as it is). A name the library has for another subagent is never written over: the import takes the next free `name-N`. A carried library carries `From`. The page lists what was found to pick from, with Select all, a filter past eight, a tag for each state and the files left out (`TestSubagentsFromAgencyAgents`, `TestSubagentImportLeavesTheUsersOwn`, `TestSubagentImportAgainUpdates`, `TestSubagentsFromAFolder`, `library-subagents-import.test.cjs`; the fixture is agency-agents' own files in `testdata/agency-agents`). | [`subagent_import.go`](../../internal/library/subagent_import.go), [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
|
||||
| Slash commands | A `Command` (miantiao_me on X) is a name (lowercase letters, digits, - and _), a one-line description and a prompt, given to the agents ticked for it, and typed as /name there. The prompt says `$ARGUMENTS` for every word typed after the name and `$1`, `$2`… for the first, second… of them. `syncCommands` writes it as a file of its own in each agent's user-level folder, in that agent's shape (`commandSpecOf`): `<claude dir>/commands/<name>.md` (front matter `description`; `$n` becomes Claude Code's `$ARGUMENTS[n-1]`, counted from 0), OpenCode's `commands/<name>.md` beside its config and Pi's `<agent dir>/prompts/<name>.md` (`$ARGUMENTS` and `$n` as magpie's), `~/.gemini/commands/<name>.toml` (`description`, `prompt`, `$ARGUMENTS` as `{{args}}`), Qwen Code's `commands/<name>.md` (`{{args}}`) and `~/.factory/commands/<name>.md` (`$ARGUMENTS`). Gemini CLI, Qwen Code and Droid take no words by place, so a command that uses `$1`… isn't written for them: the agent gets a problem, the editor names them under the prompt while it uses one, and the tab says so under the list. Codex is listed but greyed: Codex 0.165 has no loader of `~/.codex/prompts` any more, its skills took their place. An agent in a WSL distro gets none. The page lists, per agent, its folder and whether it takes `$1`… (`CommandAgentView`). There is no CLI for them yet. | [`commands.go`](../../internal/library/commands.go), `TestCommandsEachAgentsFile`, `TestCommandsWordsByPlace` |
|
||||
| Slash commands from the agents | The Slash commands tab's "Find in agents" (miantiao_me on X: "can the ones I defined in Pi be imported?") lists the commands the user already made in each agent here (`ProbeCommands`), read where that agent reads them, at the folder's top only: Pi's `prompts/*.md`, Claude Code's `commands/*.md`, OpenCode's `commands/*.md` and `command/*.md`, Gemini CLI's `commands/*.toml`, Qwen Code's `commands/*.md` and `*.toml` (its FileCommandLoader reads both) and Droid's `commands/*.md`. The file's name is the command's; the description is the front matter's (a TOML's `description`), the prompt the body (a TOML's `prompt`), and each agent's way of saying the words typed in reads back as magpie's: Claude Code's `$ARGUMENTS[n]` and `$n`, counted from 0, as `$n+1` (the `\$0` magpie writes as `$0`), Pi's `$@` and Gemini's and Qwen's `{{args}}` as `$ARGUMENTS`; Pi's `${@:N}` is left as written. A name magpie can't take, a file over 1 MB or one with no prompt is listed as left out, with why. A file magpie wrote, still as it wrote it (`Applied.Commands`), isn't listed. One name saying the same in several agents is one candidate for all of them; saying different things, each is listed, tagged, and only one can be picked. A name the library has saying the same is tagged and joins (the import ticks these agents too); one the library has for another command can't be picked, and the user's file stays as it is. `ImportCommands` takes the paths picked, reads them again, and ticks the agents each was found in. Each command keeps the files it came from (`Command.Taken`, per agent: path, bytes, and a hash of what they said): while the command says the same, `syncCommands` writes those bytes at that path, so `syncOwnFiles` takes the user's own file as magpie's byte for byte, and nothing is doubled or written over (OpenCode's `command/` file stays there). After an edit here, the command is written in the agent's shape at the same path when its extension is the one magpie writes, else at magpie's own path. A rename drops `Taken`. Unticking or removing an imported command takes its file away, into the backups, as with any file of magpie's. `Taken` is this computer's: never in `Bundle.Commands` or the page's view, and a bundle put here keeps it for a command of the same name. | [`command_import.go`](../../internal/library/command_import.go), `TestCommandImportPiPrompts` (Pi's own `.pi/prompts` files in `testdata/pi-prompts`), `TestCommandImportArgs`, `TestCommandImportByName`, `TestCommandImportNotCarried`, `library-commands-import.test.cjs` |
|
||||
| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json`, `skills/<name>/SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `<library>/plugins/<name>`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `<library>/plugin-data/<name>`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_<KEY>` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: <plugin>`, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts, and `UpdatePlugin` reads the source again. A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:<Event>`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `<plugin>-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A backup file carries the parts but not the plugin record or its folder, so on another computer they are ordinary items whose `${CLAUDE_PLUGIN_ROOT}` paths don't exist (`TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
|
||||
| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json`, `skills/<name>/SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `<library>/plugins/<name>`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `<library>/plugin-data/<name>`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_<KEY>` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: <plugin>`, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts, and `UpdatePlugin` reads the source again. A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:<Event>`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `<plugin>-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A plugin goes to another computer whole, by sync or a backup file (#6685, JJasonsun on Discord; [`plugin_carry.go`](../../internal/library/plugin_carry.go)): `Bundle.Plugins` carries each record (name, version, source, pick, agents, `Off`, and the parts taken out by hand), never its parts, which name this computer's folder. A plugin from a GitHub or git link goes as that source, and the other computer installs it from there as `UpdatePlugin` does, outside the library's lock; one it can't fetch yet is kept with `Pending`, its old parts if any, and a problem, the row says so, and Update or the next sync tries again. A plugin from a folder, or a link holding a sign-in (whose link isn't carried), goes with its files, on the skills' budget, and is installed from them. Either way that computer reads the parts again, so every hook, server and skill names its own `<library>/plugins/<name>`, Windows' too. A plugin the bundle no longer has is removed with its folder. A bundle from a magpie before this has no `plugins`, and this computer's plugins keep their parts over the same-named items it carries. A marketplace entry's own fields (`strict: false`) aren't carried, so a local marketplace plugin is read from its files alone there. A plugin installed from a marketplace under a name other than its manifest's names that folder in its parts too (`TestPluginCarriedWhole`, `TestPluginCarriedBySource`, `TestPluginOldBundleKeepsPlugins`, `TestPluginMarketplaceNameIsItsFolder`, davsync's `TestSyncLibraryPlugins`, `TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
|
||||
| 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) |
|
||||
| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. An rtk.exe in one of winget's folders that winget has no record of (`winget list` says so, or its records name another folder; netube99 on X, 0x8A150014) is upgraded from rtk's own Windows release over the file a `WinGet\Links` link points to, not by `winget upgrade`. `ReadRTK` reads each agent's files to say which have the hook. An agent gone for its CLI (`CLIMissing`, #2254) isn't offered rtk, but one that still has the hook is listed so it can be taken out. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. OpenCode 2 loads only the plugin rtk 0.52 on writes (one default object with `id` and `setup()`, rtk-ai/rtk#4187); an older rtk's plugin is for OpenCode 1 and OpenCode 2 refuses it, so with an OpenCode 2 here an older rtk is `blocked` (`openCodeBlocked`) and the row says to update RTK (#2295). Under OpenCode 2, an old plugin left from before an rtk update counts as off once the rtk here can write the new one (`openCodeHas`), so switching it on writes the new one over it; with an older rtk it counts as on, so it can be switched off. Factory's Droid (lml0664 on Discord) gets rtk's own `rtk init -g --agent droid`, given Droid's folder as `FACTORY_HOME_OVERRIDE`; rtk puts its `Execute` group (`rtk hook droid`) in the root `hooks.json`, or in `settings.json`'s `hooks.PreToolUse` where Droid's hooks already are, so `droidHookFiles` reads and switches off all three places rtk 1.1.0 may use (`hooks.json`, `hooks/hooks.json`, `settings.json`), leaving the user's own hooks. rtk before 0.44 has no Droid agent, so it is `blocked` (`droidBlocked`). A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off; Qoder and Qoder CN: rtk 1.1.0 has no Qoder agent; Cline and Kimi Code: `rtk init --agent cline|kimi` writes only one project's `.clinerules` or `AGENTS.md`, instructions with no hook, and Kimi's refuses `-g`). RTK 1.1.0's Trae, Windsurf, Kilo Code and Mistral Vibe have no magpie agent. The page's No RTK hook tag gives each agent's own reason and rtk-ai/rtk issue (`rtkNoHookWhy` in plugins/library/client.js: dsh #3847, Grok Build and Grok App #2136, Qoder and Qoder CN #1327, Cline #3841), and an agent with no entry gets no link; `TestRTKNoHookIssuesAreEachAgents` fails when the page and `rtkNoHook` cite different issues, or two agents cite the same ones without a reason in `sharedRTKIssues`. | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
| RTK in WSL | An agent in a WSL distro (`claude@wsl:Ubuntu`) is listed by its kind (`rtkKind`), and its hook runs in the distro, where Windows' rtk.exe is no command, so it gets the distro's own rtk (lex on Discord). `rtkDistroOf` asks the distro with `wsl.exe -d <distro> -e sh -lc` where rtk is (a login or interactive shell's PATH; else `~/.local/bin` or `~/.cargo/bin`, `offPath`), kept 15s; `ReadRTK` lists one `RTKDistro` for each distro its agents are in. Install RTK in WSL `<distro>` (`InstallRTKIn`, `POST /api/library/rtk/install` with `distro`, `magpie library rtk install <distro>`) runs RTK's own Linux installer in the distro (`curl -fsSL …/install.sh \| sh`, wget where there's no curl). Switching an agent on runs the distro's rtk there (`rtkInstallWSL`: `rtk init -g …` with its folder on PATH, Claude Code pointed at a folder of its own for the OpenCode and Cursor installers), and reads and edits its files under the distro's home as magpie opens it (`rtkClaudeDir`, `rtkCodexDir`, `rtkHome`). A distro that isn't running is never started (#3896): `rtkWSLLive` and `rtkDistroOf` check `agent.WSLRunning` first, its agents are listed `asleep` with the switch off, and switching or installing says to start it (`TestRTKWSLAsleep`). The page gives each distro a card (`rtkDistroCard` in plugins/library/client.js; library-rtk-wsl.test.cjs). | [`rtk_wsl.go`](../../internal/library/rtk_wsl.go) |
|
||||
|
||||
@@ -627,6 +627,18 @@ such plugins carries none and hashes as before (`TestClaudePluginsCollected`,
|
||||
`TestClaudePluginsInLibraryPart`). The preview names each marketplace and
|
||||
plugin (`TestClaudePluginsInPreview`).
|
||||
|
||||
The Library's own Claude plugins (`library.Bundle.Plugins`,
|
||||
[`plugin_carry.go`](../../internal/library/plugin_carry.go), #6685) go in
|
||||
the library part as one record each, never as their parts: a plugin from a
|
||||
GitHub or git link as its source, which the other computer installs from
|
||||
itself, and one from a folder (or a link holding a sign-in) with its files.
|
||||
The other computer makes the parts again, each naming its own plugin
|
||||
folder, removes a plugin the bundle lacks, and keeps one it can't fetch yet
|
||||
as pending, with a problem. An empty list hashes as a bundle from before
|
||||
plugins were carried, and a bundle without the list leaves this computer's
|
||||
plugins alone. The preview names each plugin, its files as one digest
|
||||
(`TestSyncLibraryPlugins`, `TestNoPluginsHashAsBefore`).
|
||||
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
|
||||
@@ -979,6 +979,11 @@ func hashes(b backup.Bundle) map[string]string {
|
||||
c.Hooks = nil
|
||||
lib = &c
|
||||
}
|
||||
if lib != nil && lib.Plugins != nil && len(*lib.Plugins) == 0 { // as before them, without one
|
||||
c := *lib
|
||||
c.Plugins = nil
|
||||
lib = &c
|
||||
}
|
||||
out := map[string]string{
|
||||
"providers": h(providers),
|
||||
"settings": settingsHash,
|
||||
@@ -1048,7 +1053,7 @@ func unset(b backup.Bundle, p string) bool {
|
||||
}
|
||||
return len(l.MCP) == 0 && len(l.Skills) == 0 &&
|
||||
(l.Subagents == nil || len(*l.Subagents) == 0) && (l.Commands == nil || len(*l.Commands) == 0) && (l.Hooks == nil || len(*l.Hooks) == 0) &&
|
||||
(l.Bili == nil || strings.TrimSpace(*l.Bili) == "") && l.ClaudePlugins == nil
|
||||
(l.Bili == nil || strings.TrimSpace(*l.Bili) == "") && l.ClaudePlugins == nil && (l.Plugins == nil || len(*l.Plugins) == 0)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -292,12 +292,41 @@ func itemsOf(b backup.Bundle, p string) map[string]item {
|
||||
}
|
||||
continue
|
||||
}
|
||||
// the library's own plugins, each by its name: what it is and
|
||||
// where from, its files as one digest, not as their bytes
|
||||
if k == "plugins" {
|
||||
var ps []*library.CarriedPlugin
|
||||
json.Unmarshal(v, &ps)
|
||||
for _, p := range ps {
|
||||
if p == nil {
|
||||
continue
|
||||
}
|
||||
c := *p
|
||||
c.Files, c.Exec, c.Left = nil, nil, nil
|
||||
r, _ := json.Marshal(struct {
|
||||
library.CarriedPlugin
|
||||
Files string `json:"files,omitempty"`
|
||||
}{c, filesDigest(p.Files)})
|
||||
out["plugin\x00"+p.Name] = item{Kind: "plugin", Name: p.Name, Raw: string(r)}
|
||||
}
|
||||
continue
|
||||
}
|
||||
flatten(out, k, x)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// filesDigest is a digest of a plugin's carried files, "" for none: a
|
||||
// change to one of them is a change to the plugin.
|
||||
func filesDigest(files map[string][]byte) string {
|
||||
if files == nil {
|
||||
return ""
|
||||
}
|
||||
j, _ := json.Marshal(files) // its keys in order
|
||||
return sum(j)
|
||||
}
|
||||
|
||||
type item struct {
|
||||
Kind, Name, Raw string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package davsync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/backup"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
)
|
||||
|
||||
// #6685: a plugin installed through the Library on one computer is on the
|
||||
// other after its next sync, whole, with its hook naming that computer's
|
||||
// folder for it; the second computer pushes nothing back, and a plugin
|
||||
// taken out on the first goes from the second.
|
||||
func TestSyncLibraryPlugins(t *testing.T) {
|
||||
fake := &fakeDAV{files: map[string][]byte{}, etags: map[string]string{}, dirs: map[string]bool{"/dav": true}}
|
||||
srv := httptest.NewServer(fake)
|
||||
defer srv.Close()
|
||||
ctx := context.Background()
|
||||
cfg := Config{URL: srv.URL + "/dav/", User: "me", Password: "pw", Passphrase: "correct horse", Keys: true, Agents: true}
|
||||
now := func(t *testing.T) {
|
||||
t.Helper()
|
||||
if err := Now(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := Status(); v.Error != "" {
|
||||
t.Fatalf("sync: %+v", v)
|
||||
}
|
||||
}
|
||||
write := func(p, s string) {
|
||||
os.MkdirAll(filepath.Dir(p), 0o755)
|
||||
if err := os.WriteFile(p, []byte(s), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
a, b := newComputer(t), newComputer(t)
|
||||
a.use(t)
|
||||
write(filepath.Join(string(a), ".claude", "settings.json"), "{}\n")
|
||||
src := filepath.Join(string(a), "work", "kit")
|
||||
write(filepath.Join(src, ".claude-plugin", "plugin.json"), `{"name":"kit","version":"1.0.0"}`)
|
||||
write(filepath.Join(src, "hooks", "hooks.json"), `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${CLAUDE_PLUGIN_ROOT}/bin/done"}]}]}}`)
|
||||
write(filepath.Join(src, "bin", "done"), "#!/bin/sh\n")
|
||||
if _, err := library.InstallPlugins(src, nil, []string{"claude"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Configure(cfg)
|
||||
now(t)
|
||||
|
||||
b.use(t)
|
||||
write(filepath.Join(string(b), ".claude", "settings.json"), "{}\n")
|
||||
Configure(cfg)
|
||||
now(t)
|
||||
v, err := library.Read(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(v.Plugins) != 1 || v.Plugins[0].Name != "kit" {
|
||||
t.Fatalf("b's plugins: %+v", v.Plugins)
|
||||
}
|
||||
// as the plugin wrote it: ${CLAUDE_PLUGIN_ROOT}/bin/done, on Windows too
|
||||
inJSON := func(s string) string { j, _ := json.Marshal(s); return strings.Trim(string(j), `"`) }
|
||||
want := inJSON(v.Plugins[0].Dir + "/bin/done")
|
||||
s, _ := os.ReadFile(filepath.Join(string(b), ".claude", "settings.json"))
|
||||
if !strings.Contains(string(s), want) || strings.Contains(string(s), inJSON(string(a))) {
|
||||
t.Fatalf("b's Claude Code hook doesn't name b's folder for the plugin %s: %s", want, s)
|
||||
}
|
||||
puts := fake.puts
|
||||
now(t)
|
||||
if fake.puts != puts {
|
||||
t.Fatalf("b pushed back the plugin it brought in (%d puts)", fake.puts-puts)
|
||||
}
|
||||
|
||||
a.use(t)
|
||||
if _, err := library.RemovePlugin("kit"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now(t)
|
||||
b.use(t)
|
||||
now(t)
|
||||
if v, _ := library.Read(nil); len(v.Plugins) != 0 || len(v.Hooks) != 0 {
|
||||
t.Errorf("the plugin stays on b after a took it out: %+v", v.Plugins)
|
||||
}
|
||||
if s, _ := os.ReadFile(filepath.Join(string(b), ".claude", "settings.json")); strings.Contains(string(s), "bin/done") {
|
||||
t.Errorf("the hook stays in b's Claude Code: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// A library with no plugins hashes as it did before they were carried, so
|
||||
// a magpie that starts carrying them doesn't see a change to sync.
|
||||
func TestNoPluginsHashAsBefore(t *testing.T) {
|
||||
none := []*library.CarriedPlugin{}
|
||||
with := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}, Plugins: &none}}
|
||||
before := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}}}
|
||||
if hashes(with)["library"] != hashes(before)["library"] {
|
||||
t.Error("an empty list of plugins changed the library's hash")
|
||||
}
|
||||
one := []*library.CarriedPlugin{{Name: "kit", Source: "https://github.com/acme/kit", Agents: []string{"claude"}}}
|
||||
with.Library.Plugins = &one
|
||||
if hashes(with)["library"] == hashes(before)["library"] {
|
||||
t.Error("a plugin didn't change the library's hash")
|
||||
}
|
||||
items := itemsOf(with, "library")
|
||||
if it, ok := items["plugin\x00kit"]; !ok || it.Name != "kit" {
|
||||
t.Errorf("the plugin as the preview lists it: %+v", items)
|
||||
}
|
||||
}
|
||||
+16
-12
@@ -3495,7 +3495,8 @@ const I18N = {
|
||||
"password, or an app password": "密码或应用密码",
|
||||
"the same on every computer": "每台电脑上都一样",
|
||||
"Agents' models": "各 agent 选的模型",
|
||||
"Library: instructions, MCP servers, skills, hooks and subagents": "资源库:指令、MCP 服务器、技能、Hooks 和子代理",
|
||||
"Library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "资源库:指令、MCP 服务器、技能、Hooks、子代理和 Claude 插件",
|
||||
"Claude plugins": "Claude 插件",
|
||||
"Usage: this computer's calls, for the Usage page on the others": "用量:本机的请求,在其他电脑的用量页里显示",
|
||||
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "用量每天一个文件:时间、token、模型和费用,不含对话内容。每台要共享用量的电脑都需各自打开。",
|
||||
"usage": "用量",
|
||||
@@ -3532,13 +3533,13 @@ const I18N = {
|
||||
"Pick a passphrase: the file is sealed with it": "请设置口令:文件会用它加密",
|
||||
"passphrase": "口令", "again": "再输入一次",
|
||||
"With the providers' API keys": "包含供应商的 API Key",
|
||||
"With the library: instructions, MCP servers, skills, hooks and subagents": "包含资源库:指令、MCP 服务器、技能、Hooks 和子代理",
|
||||
"With the library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "包含资源库:指令、MCP 服务器、技能、Hooks、子代理和 Claude 插件",
|
||||
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "打开文件时需要。订阅账号不在其中,请在另一台电脑上各自登录。",
|
||||
"The two passphrases differ": "两次输入的口令不一致",
|
||||
"Saved to {path}": "已保存到 {path}",
|
||||
"No file chosen": "未选择文件", "Choose…": "选择…", "File": "文件",
|
||||
"Set the agents' models too": "同时设置各 agent 的模型",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks and subagents": "同时导入资源库:指令、MCP 服务器、技能、Hooks 和子代理",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "同时导入资源库:指令、MCP 服务器、技能、Hooks、子代理和 Claude 插件",
|
||||
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同 id 的供应商会被替换;不带 Key 的保留本机已有的 Key。资源库将替换本机资源库,原内容保存在备份中。",
|
||||
"Choose a file first": "请先选择文件",
|
||||
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供应商:新增 {added} 个,替换 {replaced} 个;Profile {profiles} 个;agent 设置改动 {agents} 项",
|
||||
@@ -8888,7 +8889,8 @@ const I18N = {
|
||||
"password, or an app password": "密碼或應用密碼",
|
||||
"the same on every computer": "每臺電腦上都一樣",
|
||||
"Agents' models": "各 agent 選的模型",
|
||||
"Library: instructions, MCP servers, skills, hooks and subagents": "資源庫:指令、MCP 伺服器、技能、Hooks 和子代理",
|
||||
"Library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "資源庫:指令、MCP 伺服器、技能、Hooks、子代理和 Claude 外掛",
|
||||
"Claude plugins": "Claude 外掛",
|
||||
"Usage: this computer's calls, for the Usage page on the others": "用量:本機的請求,在其他電腦的用量頁裡顯示",
|
||||
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "用量每天一個檔案:時間、token、模型和費用,不含對話內容。每臺要共享用量的電腦都需各自開啟。",
|
||||
"usage": "用量",
|
||||
@@ -8932,7 +8934,7 @@ const I18N = {
|
||||
"passphrase": "口令",
|
||||
"again": "再輸入一次",
|
||||
"With the providers' API keys": "包含供應商的 API Key",
|
||||
"With the library: instructions, MCP servers, skills, hooks and subagents": "包含資源庫:指令、MCP 伺服器、技能、Hooks 和子代理",
|
||||
"With the library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "包含資源庫:指令、MCP 伺服器、技能、Hooks、子代理和 Claude 外掛",
|
||||
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "開啟檔案時需要。訂閱帳號不在其中,請在另一臺電腦上各自登入。",
|
||||
"The two passphrases differ": "兩次輸入的口令不一致",
|
||||
"Saved to {path}": "已儲存到 {path}",
|
||||
@@ -8940,7 +8942,7 @@ const I18N = {
|
||||
"Choose…": "選擇…",
|
||||
"File": "檔案",
|
||||
"Set the agents' models too": "同時設定各 agent 的模型",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks and subagents": "同時匯入資源庫:指令、MCP 伺服器、技能、Hooks 和子代理",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "同時匯入資源庫:指令、MCP 伺服器、技能、Hooks、子代理和 Claude 外掛",
|
||||
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同 id 的供應商會被替換;不帶 Key 的保留本機已有的 Key。資源庫將替換本機資源庫,原內容儲存在備份中。",
|
||||
"Choose a file first": "請先選擇檔案",
|
||||
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供應商:新增 {added} 個,替換 {replaced} 個;Profile {profiles} 個;agent 設定改動 {agents} 項",
|
||||
@@ -14291,7 +14293,8 @@ const I18N = {
|
||||
"password, or an app password": "パスワードまたはアプリパスワード",
|
||||
"the same on every computer": "すべてのコンピューターで共通",
|
||||
"Agents' models": "エージェントのモデル",
|
||||
"Library: instructions, MCP servers, skills, hooks and subagents": "ライブラリ:指示、MCP サーバー、スキル、フック、サブエージェント",
|
||||
"Library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "ライブラリ:指示、MCP サーバー、スキル、フック、サブエージェント、Claude プラグイン",
|
||||
"Claude plugins": "Claude プラグイン",
|
||||
"Usage: this computer's calls, for the Usage page on the others": "使用量:このコンピューターの呼び出し(他のコンピューターの「使用量」ページ用)",
|
||||
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "使用量は1日1ファイルで送られます:時刻、トークン、モデル、費用のみで、会話内容は含みません。自分の使用量を共有する各コンピューターでオンにしてください。",
|
||||
"usage": "使用量",
|
||||
@@ -14335,7 +14338,7 @@ const I18N = {
|
||||
"passphrase": "パスフレーズ",
|
||||
"again": "もう一度",
|
||||
"With the providers' API keys": "プロバイダの APIキーを含める",
|
||||
"With the library: instructions, MCP servers, skills, hooks and subagents": "ライブラリを含める:指示、MCP サーバー、スキル、フック、サブエージェント",
|
||||
"With the library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "ライブラリを含める:指示、MCP サーバー、スキル、フック、サブエージェント、Claude プラグイン",
|
||||
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "ファイルを開くときに必要です。サブスクリプションは含まれないため、別のコンピューターでサインインしてください。",
|
||||
"The two passphrases differ": "2つのパスフレーズが一致しません",
|
||||
"Saved to {path}": "{path} に保存しました",
|
||||
@@ -14343,7 +14346,7 @@ const I18N = {
|
||||
"Choose…": "選択…",
|
||||
"File": "ファイル",
|
||||
"Set the agents' models too": "エージェントのモデルも設定する",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks and subagents": "ライブラリも取り込む:指示、MCP サーバー、スキル、フック、サブエージェント",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "ライブラリも取り込む:指示、MCP サーバー、スキル、フック、サブエージェント、Claude プラグイン",
|
||||
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同じ ID のプロバイダは置き換えられます。キーなしで来たものはここにあるキーを保持します。ライブラリはここのものを置き換え、置き換えられたものはバックアップとともに保持されます。",
|
||||
"Choose a file first": "先にファイルを選んでください",
|
||||
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "プロバイダ:{added} 件追加、{replaced} 件置換。プロファイル {profiles} 件。エージェント設定 {agents} 件を変更",
|
||||
@@ -19707,7 +19710,8 @@ const I18N = {
|
||||
"password, or an app password": "Passwort oder App-Passwort",
|
||||
"the same on every computer": "auf jedem Computer gleich",
|
||||
"Agents' models": "Modelle der Agenten",
|
||||
"Library: instructions, MCP servers, skills, hooks and subagents": "Bibliothek: Anweisungen, MCP-Server, Skills, Hooks und Subagenten",
|
||||
"Library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "Bibliothek: Anweisungen, MCP-Server, Skills, Hooks, Subagenten und Claude-Plugins",
|
||||
"Claude plugins": "Claude-Plugins",
|
||||
"Usage: this computer's calls, for the Usage page on the others": "Nutzung: Aufrufe dieses Computers, für die Seite „Nutzung“ auf den anderen",
|
||||
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "Die Nutzung wird als eine Datei pro Tag übertragen: Zeiten, Token, Modelle und Kosten, nie die Inhalte. Auf jedem Computer einschalten, der seine eigene teilt.",
|
||||
"usage": "Nutzung",
|
||||
@@ -19751,7 +19755,7 @@ const I18N = {
|
||||
"passphrase": "Passphrase",
|
||||
"again": "wiederholen",
|
||||
"With the providers' API keys": "Mit den API-Schlüsseln der Anbieter",
|
||||
"With the library: instructions, MCP servers, skills, hooks and subagents": "Mit der Bibliothek: Anweisungen, MCP-Server, Skills, Hooks und Subagenten",
|
||||
"With the library: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "Mit der Bibliothek: Anweisungen, MCP-Server, Skills, Hooks, Subagenten und Claude-Plugins",
|
||||
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "Wird zum Öffnen der Datei benötigt. Abos sind nicht enthalten: Melden Sie sich auf dem anderen Computer bei ihnen an.",
|
||||
"The two passphrases differ": "Die beiden Passphrasen stimmen nicht überein",
|
||||
"Saved to {path}": "Gespeichert unter {path}",
|
||||
@@ -19759,7 +19763,7 @@ const I18N = {
|
||||
"Choose…": "Auswählen…",
|
||||
"File": "Datei",
|
||||
"Set the agents' models too": "Auch die Modelle der Agenten setzen",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks and subagents": "Auch die Bibliothek importieren: Anweisungen, MCP-Server, Skills, Hooks und Subagenten",
|
||||
"Bring in the library too: instructions, MCP servers, skills, hooks, subagents and Claude plugins": "Auch die Bibliothek importieren: Anweisungen, MCP-Server, Skills, Hooks, Subagenten und Claude-Plugins",
|
||||
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "Anbieter mit gleicher ID werden ersetzt; einer ohne Schlüssel behält den hier vorhandenen Schlüssel. Die Bibliothek ersetzt die hiesige, die in den Backups erhalten bleibt.",
|
||||
"Choose a file first": "Wählen Sie zuerst eine Datei",
|
||||
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "Anbieter: {added} hinzugefügt, {replaced} ersetzt; {profiles} Profile; {agents} Agenteneinstellungen geändert",
|
||||
|
||||
@@ -5499,6 +5499,8 @@ magpie.plugin("library", (ctx) => {
|
||||
const line = [[t("Skills"), p.skills], [t("MCP servers"), p.mcp], [t("Hooks"), p.hooks], [t("Subagents"), p.subagents]]
|
||||
.filter(([, v]) => v?.length).map(([k, v]) => k + " " + v.length).join(" · ");
|
||||
if (line) who.append(el("div", "sub lib-plparts", line));
|
||||
// synced in from another computer, its source not reached here yet
|
||||
if (p.pending) who.append(el("div", "sub lib-plpending", t("Not fetched on this computer yet: Update tries again")));
|
||||
row.append(glyph(GLYPH.folder), who,
|
||||
agentChips(all, p.agents, chipsChange("plugins/agents", p.name, "plugins", (x) => pluginRow(x, all)), { all: true }),
|
||||
toggle(!p.off, t("Turn {name} on or off", { name: p.name }), (v) => change("plugins/on", { name: p.name, on: v },
|
||||
|
||||
@@ -1062,7 +1062,7 @@ magpie.strings({
|
||||
"Nothing folded yet over {requests}: billion-context folds a session once it nears the model's window.": "已经过 {requests},还没有折叠:会话接近模型窗口时 billion-context 才会折叠。",
|
||||
"billion-context's own count, after the rebuilds a fold causes and the summaries' cost ({gross} before them): every session it ran on this computer, from any agent.": "这是 billion-context 自己的统计,已扣除折叠后的重建和摘要的开销(扣除前 {gross}):包括这台电脑上它运行过的所有会话,不分 Agent。",
|
||||
"As of {time}: billion-context isn't running now.": "截至 {time}:billion-context 现在没有运行。",
|
||||
"Claude plugins": "Claude 插件",
|
||||
"Not fetched on this computer yet: Update tries again": "尚未在这台电脑上获取:点「更新」重试",
|
||||
"A Claude Code plugin is skills, MCP servers, hooks and subagents in one package. Install it once: magpie gives each part to the agents you pick, and you turn the plugin on, off or remove it as a whole. Its parts also show under their own tabs.": "Claude Code 插件把技能、MCP 服务器、hooks 和子代理装成一个包。装一次,magpie 就把每一部分交给你选的智能体;插件可以整体开启、关闭或移除。它的各部分也会出现在各自的标签页里。",
|
||||
"No Claude plugins in the library yet": "资源库里还没有 Claude 插件",
|
||||
"Install one from a folder, a git address or a marketplace.json.": "从文件夹、git 地址或 marketplace.json 安装。",
|
||||
@@ -2156,7 +2156,7 @@ magpie.strings({
|
||||
"Nothing folded yet over {requests}: billion-context folds a session once it nears the model's window.": "已經過 {requests},還沒有摺疊:工作階段接近模型視窗時 billion-context 才會摺疊。",
|
||||
"billion-context's own count, after the rebuilds a fold causes and the summaries' cost ({gross} before them): every session it ran on this computer, from any agent.": "這是 billion-context 自己的統計,已扣除摺疊後的重建和摘要的開銷(扣除前 {gross}):包括這台電腦上它執行過的所有工作階段,不分 Agent。",
|
||||
"As of {time}: billion-context isn't running now.": "截至 {time}:billion-context 現在沒有執行。",
|
||||
"Claude plugins": "Claude 外掛",
|
||||
"Not fetched on this computer yet: Update tries again": "尚未在這台電腦上取得:按「更新」重試",
|
||||
"A Claude Code plugin is skills, MCP servers, hooks and subagents in one package. Install it once: magpie gives each part to the agents you pick, and you turn the plugin on, off or remove it as a whole. Its parts also show under their own tabs.": "Claude Code 外掛把技能、MCP 伺服器、hooks 和子代理裝成一個包。裝一次,magpie 就把每一部分交給你選的代理;外掛可以整體開啟、關閉或移除。它的各部分也會出現在各自的分頁裡。",
|
||||
"No Claude plugins in the library yet": "資源庫裡還沒有 Claude 外掛",
|
||||
"Install one from a folder, a git address or a marketplace.json.": "從資料夾、git 位址或 marketplace.json 安裝。",
|
||||
@@ -3250,7 +3250,7 @@ magpie.strings({
|
||||
"Nothing folded yet over {requests}: billion-context folds a session once it nears the model's window.": "{requests}を処理しましたが、まだ折りたたんでいません。billion-context はセッションがモデルのウィンドウに近づくと折りたたみます。",
|
||||
"billion-context's own count, after the rebuilds a fold causes and the summaries' cost ({gross} before them): every session it ran on this computer, from any agent.": "billion-context 自身の集計で、折りたたみ後の再構築と要約のコストを差し引いた値です(差し引く前は {gross})。このコンピューターで動いたすべてのセッションが対象で、エージェントは問いません。",
|
||||
"As of {time}: billion-context isn't running now.": "{time} 時点:billion-context は現在動いていません。",
|
||||
"Claude plugins": "Claude プラグイン",
|
||||
"Not fetched on this computer yet: Update tries again": "このコンピューターではまだ取得していません:「アップデート」で再試行",
|
||||
"A Claude Code plugin is skills, MCP servers, hooks and subagents in one package. Install it once: magpie gives each part to the agents you pick, and you turn the plugin on, off or remove it as a whole. Its parts also show under their own tabs.": "Claude Code プラグインは、スキル、MCP サーバー、フック、サブエージェントを 1 つにまとめたパッケージです。一度インストールすると、magpie が選んだエージェントに各パーツを渡し、プラグイン全体をオン、オフ、削除できます。各パーツはそれぞれのタブにも表示されます。",
|
||||
"No Claude plugins in the library yet": "ライブラリにはまだ Claude プラグインがありません",
|
||||
"Install one from a folder, a git address or a marketplace.json.": "フォルダ、git アドレス、marketplace.json からインストールします。",
|
||||
@@ -4344,7 +4344,7 @@ magpie.strings({
|
||||
"Nothing folded yet over {requests}: billion-context folds a session once it nears the model's window.": "Noch nichts gefaltet nach {requests}: billion-context faltet eine Sitzung, wenn sie sich dem Fenster des Modells nähert.",
|
||||
"billion-context's own count, after the rebuilds a fold causes and the summaries' cost ({gross} before them): every session it ran on this computer, from any agent.": "Die eigene Zählung von billion-context, abzüglich der Neuaufbauten nach einer Faltung und der Kosten der Zusammenfassungen ({gross} davor): jede Sitzung, in der es auf diesem Computer lief, von jedem Agenten.",
|
||||
"As of {time}: billion-context isn't running now.": "Stand {time}: billion-context läuft gerade nicht.",
|
||||
"Claude plugins": "Claude-Plugins",
|
||||
"Not fetched on this computer yet: Update tries again": "Auf diesem Computer noch nicht geladen: „Aktualisieren“ versucht es erneut",
|
||||
"A Claude Code plugin is skills, MCP servers, hooks and subagents in one package. Install it once: magpie gives each part to the agents you pick, and you turn the plugin on, off or remove it as a whole. Its parts also show under their own tabs.": "Ein Claude-Code-Plugin bündelt Skills, MCP-Server, Hooks und Subagenten in einem Paket. Einmal installieren: magpie gibt jeden Teil den gewählten Agenten, und das Plugin lässt sich als Ganzes ein-, ausschalten oder entfernen. Die Teile erscheinen auch in ihren eigenen Tabs.",
|
||||
"No Claude plugins in the library yet": "Noch keine Claude-Plugins in der Bibliothek",
|
||||
"Install one from a folder, a git address or a marketplace.json.": "Aus einem Ordner, einer Git-Adresse oder einer marketplace.json installieren.",
|
||||
|
||||
@@ -39,7 +39,7 @@ window.davForm = function (v) {
|
||||
keysL.classList.add("sync-sub-tick");
|
||||
const [setL, sets] = tick(t("Settings"), v.settings !== false);
|
||||
const [agentsL, agents] = tick(t("Agents' models"), v.agents !== false);
|
||||
const [libL, lib] = tick(t("Library: instructions, MCP servers, skills, hooks and subagents"), v.library !== false);
|
||||
const [libL, lib] = tick(t("Library: instructions, MCP servers, skills, hooks, subagents and Claude plugins"), v.library !== false);
|
||||
const [memL, mem] = tick(t("Memory: what the agents know, merged memory by memory"), v.memory !== false);
|
||||
const keysShow = () => { keysL.hidden = !prov.checked; };
|
||||
keysShow();
|
||||
@@ -237,7 +237,7 @@ window.exportForm = function () {
|
||||
const p1 = input("", t("passphrase"), "password");
|
||||
const p2 = input("", t("again"), "password");
|
||||
const [keysL, keys] = tick(t("With the providers' API keys"), true);
|
||||
const [libL, lib] = tick(t("With the library: instructions, MCP servers, skills, hooks and subagents"), true);
|
||||
const [libL, lib] = tick(t("With the library: instructions, MCP servers, skills, hooks, subagents and Claude plugins"), true);
|
||||
const [memL, mem] = tick(t("With memory: what the agents know"), true);
|
||||
const [useL, use] = tick(t("With the usage history"), true);
|
||||
// sign-ins: off unless picked (qianxunji, curtinp118 on Discord)
|
||||
@@ -302,7 +302,7 @@ window.importForm = function () {
|
||||
pf.append(name, pick, file);
|
||||
const pass = input("", t("passphrase"), "password");
|
||||
const [agentsL, agents] = tick(t("Set the agents' models too"), true);
|
||||
const [libL, lib] = tick(t("Bring in the library too: instructions, MCP servers, skills, hooks and subagents"), true);
|
||||
const [libL, lib] = tick(t("Bring in the library too: instructions, MCP servers, skills, hooks, subagents and Claude plugins"), true);
|
||||
const [memL, mem] = tick(t("Bring in memory too, merged with the memories here"), true);
|
||||
const [useL, use] = tick(t("Bring in the usage history too, merged with the one here"), true);
|
||||
const [siL, si] = tick(t("Bring in the sign-ins too, when the file has them"), true);
|
||||
|
||||
@@ -55,6 +55,12 @@ type Bundle struct {
|
||||
// nothing then. Put only adds, so one computer's never takes away
|
||||
// another's.
|
||||
ClaudePlugins *ClaudePlugins `json:"claudePlugins,omitempty"`
|
||||
// Plugins are the library's own Claude plugins (plugin.go), each as a
|
||||
// whole: its parts aren't among the skills, servers, hooks and
|
||||
// subagents above, and each computer makes them again from it
|
||||
// (plugin_carry.go). nil in a bundle from a magpie before they were
|
||||
// carried: Put keeps this computer's then.
|
||||
Plugins *[]*CarriedPlugin `json:"plugins,omitempty"`
|
||||
}
|
||||
|
||||
// CarriedSkill is a skill with its folder's files.
|
||||
@@ -126,19 +132,32 @@ func Collect() (*Bundle, error) {
|
||||
// a server kept to this computer stays out; another computer's by its
|
||||
// name, which a sync brought, goes on as it came (mcp_local.go)
|
||||
for _, s := range sorted(l.carriedServers(), func(s *Server) string { return s.Name }) {
|
||||
if l.ownedPart(s.Bundle) { // with its plugin (plugin_carry.go)
|
||||
continue
|
||||
}
|
||||
// magpie's own by name, each computer's own binary; a server
|
||||
// started its own way here goes with the synced start (mcp_here.go)
|
||||
c := *carried(carriedStart(s))
|
||||
c.Agents = orNone(slices.Sorted(slices.Values(s.Agents)))
|
||||
b.MCP = append(b.MCP, &c)
|
||||
}
|
||||
skills := sorted(l.Skills, func(s *Skill) string { return s.Name })
|
||||
skills := sorted(slices.DeleteFunc(slices.Clone(l.Skills), func(s *Skill) bool { return l.ownedPart(s.Bundle) }),
|
||||
func(s *Skill) string { return s.Name })
|
||||
dirs := []string{}
|
||||
for _, s := range skills {
|
||||
dirs = append(dirs, realDir(skillDir(s.Name)))
|
||||
}
|
||||
// a plugin's files from a folder are read with the skills', in one
|
||||
// budget
|
||||
plugins, pdirs, at := l.carriedPlugins()
|
||||
read := readSkills(append(dirs, pdirs...))
|
||||
for i, f := range read[len(skills):] {
|
||||
c := plugins[at[i]]
|
||||
c.Files, c.Exec, c.Left = f.Files, f.Exec, f.Left
|
||||
}
|
||||
b.Plugins = &plugins
|
||||
tr := &tracer{}
|
||||
for i, c := range readSkills(dirs) {
|
||||
for i, c := range read[:len(skills)] {
|
||||
s := skills[i]
|
||||
if s.Source == nil || s.Source.Kind == "folder" {
|
||||
c.From = tr.repoOf(s)
|
||||
@@ -148,6 +167,9 @@ func Collect() (*Bundle, error) {
|
||||
}
|
||||
subs := []*Subagent{}
|
||||
for _, s := range sorted(l.Subagents, func(s *Subagent) string { return s.Name }) {
|
||||
if l.ownedPart(s.Bundle) {
|
||||
continue
|
||||
}
|
||||
c := *s
|
||||
c.Skills, c.MCP = slices.Sorted(slices.Values(s.Skills)), slices.Sorted(slices.Values(s.MCP))
|
||||
c.Agents = orNone(slices.Sorted(slices.Values(s.Agents)))
|
||||
@@ -165,6 +187,9 @@ func Collect() (*Bundle, error) {
|
||||
b.Commands = &cmds
|
||||
hooks := []*Hook{}
|
||||
for _, h := range sorted(l.Hooks, func(h *Hook) string { return h.Name }) {
|
||||
if l.ownedPart(h.Bundle) {
|
||||
continue
|
||||
}
|
||||
c := *h
|
||||
c.Agents = orNone(slices.Sorted(slices.Values(h.Agents)))
|
||||
hooks = append(hooks, &c)
|
||||
@@ -360,6 +385,27 @@ func (b *Bundle) check() error {
|
||||
seen[e.Name] = true
|
||||
}
|
||||
}
|
||||
if b.Plugins != nil {
|
||||
seen := map[string]bool{}
|
||||
for _, p := range *b.Plugins {
|
||||
if p == nil {
|
||||
return fmt.Errorf("an empty plugin")
|
||||
}
|
||||
// its folder's name in the library
|
||||
if p.Name == "" || pluginSlug(p.Name) != p.Name {
|
||||
return fmt.Errorf("the plugin name %q", p.Name)
|
||||
}
|
||||
if seen[p.Name] {
|
||||
return fmt.Errorf("the plugin %s twice", p.Name)
|
||||
}
|
||||
seen[p.Name] = true
|
||||
for _, rel := range slices.Concat(slices.Collect(maps.Keys(p.Files)), p.Left) {
|
||||
if !localFile(rel) {
|
||||
return fmt.Errorf("plugin %s: %q is not a file in its folder", p.Name, rel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if b.Hooks != nil {
|
||||
seen := map[string]bool{}
|
||||
for _, h := range *b.Hooks {
|
||||
@@ -515,7 +561,11 @@ func Put(b *Bundle) (*Result, error) {
|
||||
return nil, err
|
||||
}
|
||||
biliWrote := false
|
||||
var fetch []*CarriedPlugin
|
||||
var gone []string
|
||||
var plProblems []Problem
|
||||
res, err := change(func(l *Library) error {
|
||||
fetch, gone, plProblems = nil, nil, nil
|
||||
if err := os.MkdirAll(skillsDir(), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -524,6 +574,16 @@ func Put(b *Bundle) (*Result, error) {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(stage)
|
||||
// this computer's plugins' parts stand aside while the items are
|
||||
// replaced, the bundle carrying none of them, and the plugins
|
||||
// are put after (plugin_carry.go). A bundle from a magpie before
|
||||
// plugins were carried has their parts as its own items, naming
|
||||
// the other computer's folder: this computer's stay instead
|
||||
held := l.holdPluginParts()
|
||||
b := b
|
||||
if b.Plugins == nil {
|
||||
b = held.without(b)
|
||||
}
|
||||
|
||||
keep, link := map[string]bool{}, map[string]string{}
|
||||
for _, s := range b.Skills {
|
||||
@@ -709,6 +769,10 @@ func Put(b *Bundle) (*Result, error) {
|
||||
}
|
||||
l.Env = envs
|
||||
}
|
||||
l.putBack(held)
|
||||
if b.Plugins != nil {
|
||||
fetch, gone, plProblems = l.putPlugins(*b.Plugins, stage)
|
||||
}
|
||||
if b.Bili != nil {
|
||||
wrote, err := putBili(*b.Bili, kept)
|
||||
if err != nil {
|
||||
@@ -728,6 +792,11 @@ func Put(b *Bundle) (*Result, error) {
|
||||
// started later reads the file anyway)
|
||||
biliReload()
|
||||
}
|
||||
if err == nil {
|
||||
removePluginDirs(gone)
|
||||
res.Problems = append(res.Problems, plProblems...)
|
||||
fetchPlugins(fetch, res)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ type Plugin struct {
|
||||
Left []PluginLeft `json:"left,omitempty"`
|
||||
// Installed is when it was installed or last updated
|
||||
Installed string `json:"installed,omitempty"`
|
||||
// Pending is set while a plugin another computer has, by a source
|
||||
// this one fetches it from, hasn't been fetched here yet: it was
|
||||
// synced in and the fetch failed (plugin_carry.go). Update tries again
|
||||
Pending bool `json:"pending,omitempty"`
|
||||
}
|
||||
|
||||
// PluginLeft is a part of a plugin that wasn't carried.
|
||||
@@ -184,8 +188,11 @@ func isPlugin(dir string) bool {
|
||||
|
||||
// readPlugin reads the plugin in dir. over are the fields a marketplace's
|
||||
// entry gives for it, which a plugin.json overrides; hint is the name the
|
||||
// marketplace calls it by.
|
||||
func readPlugin(dir, hint string, over map[string]any) (*plLoaded, error) {
|
||||
// marketplace calls it by. Its name is force when that is set (a
|
||||
// marketplace's name for it, a synced plugin's), else its manifest's,
|
||||
// else hint: the name is its folder's in the library, and every
|
||||
// ${CLAUDE_PLUGIN_ROOT} in its parts is replaced with that folder.
|
||||
func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error) {
|
||||
man := map[string]any{}
|
||||
if m, err := readJSONFile(filepath.Join(dir, ".claude-plugin", "plugin.json")); err == nil {
|
||||
man = m
|
||||
@@ -200,7 +207,10 @@ func readPlugin(dir, hint string, over map[string]any) (*plLoaded, error) {
|
||||
if !isPlugin(dir) && len(man) == 0 {
|
||||
return nil, fmt.Errorf("no Claude Code plugin in %s: it has no .claude-plugin/plugin.json, skills, agents, hooks or .mcp.json", dir)
|
||||
}
|
||||
name := pluginSlug(plStr(man["name"]))
|
||||
name := pluginSlug(force)
|
||||
if name == "" {
|
||||
name = pluginSlug(plStr(man["name"]))
|
||||
}
|
||||
if name == "" {
|
||||
name = pluginSlug(hint)
|
||||
}
|
||||
@@ -729,7 +739,7 @@ func findPlugins(root string) (*PluginProbe, error) {
|
||||
return nil, err
|
||||
}
|
||||
if mk == nil {
|
||||
pl, err := readPlugin(root, filepath.Base(root), nil)
|
||||
pl, err := readPlugin(root, filepath.Base(root), "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -761,7 +771,7 @@ func findPlugins(root string) (*PluginProbe, error) {
|
||||
c.Left = []PluginLeft{{What: c.Name, Why: "its source leaves the marketplace's folder"}}
|
||||
break
|
||||
}
|
||||
if pl, err := readPlugin(d, c.Name, over); err == nil {
|
||||
if pl, err := readPlugin(d, c.Name, "", over); err == nil {
|
||||
c2 := candidateOf(pl, d, over)
|
||||
c2.Name = c.Name
|
||||
c = c2
|
||||
@@ -947,13 +957,17 @@ func installPlugins(p *PluginProbe, input string, names, agents []string) (*Resu
|
||||
return nil, fmt.Errorf("%s: its folder %s leaves its repository", c.Name, c.path)
|
||||
}
|
||||
}
|
||||
pl, err := readPlugin(d, c.Name, c.over)
|
||||
// a marketplace's name for it is its folder's: read with it, so
|
||||
// its parts name that folder, not the one its manifest's name
|
||||
// would have
|
||||
force := ""
|
||||
if len(p.Candidates) > 1 || c.Remote {
|
||||
force = c.Name
|
||||
}
|
||||
pl, err := readPlugin(d, c.Name, force, c.over)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", c.Name, err)
|
||||
}
|
||||
if len(p.Candidates) > 1 || c.Remote {
|
||||
pl.name = c.Name // a marketplace's name for it
|
||||
}
|
||||
if pl.parts() == 0 {
|
||||
return nil, fmt.Errorf("%s has no skills, MCP servers, hooks or subagents magpie can give an agent", pl.name)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A plugin goes with the library to another computer whole (#6685,
|
||||
// JJasonsun on Discord): its record, and how that computer gets its
|
||||
// files, and that computer makes its parts again itself. Its parts are
|
||||
// never carried as the ordinary skills, servers, hooks and subagents they
|
||||
// are here: each names this computer's folder for the plugin (a hook's
|
||||
// ${CLAUDE_PLUGIN_ROOT}, made /Users/a/… at install), which on the other
|
||||
// computer is no folder, and the two would trade their own paths back and
|
||||
// forth on every sync.
|
||||
//
|
||||
// A plugin installed from a repository or a marketplace link is carried
|
||||
// as its source, and the other computer installs it from there, as
|
||||
// Update does: the bundle stays small and both end on the same version. A
|
||||
// plugin from a folder of this computer's, or one whose link holds a
|
||||
// sign-in, is carried with its files (the skills' budget, readSkills),
|
||||
// and the other computer installs it from them. Either way the parts are
|
||||
// read again there, with its own folder in every hook, server and skill.
|
||||
|
||||
// CarriedPlugin is a library plugin as a sync carries it.
|
||||
type CarriedPlugin struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Source string `json:"source,omitempty"`
|
||||
Pick string `json:"pick,omitempty"`
|
||||
Agents []string `json:"agents"`
|
||||
Off bool `json:"off,omitempty"`
|
||||
// Taken are the parts the user took out one by one (PluginView's
|
||||
// Missing), taken out on the other computer too
|
||||
Taken []string `json:"taken,omitempty"`
|
||||
// Files are a plugin's from a folder, as a skill's are; nil for one
|
||||
// fetched from its source
|
||||
Files map[string][]byte `json:"files"`
|
||||
Exec []string `json:"exec,omitempty"`
|
||||
Left []string `json:"left,omitempty"`
|
||||
}
|
||||
|
||||
// fromFiles reports whether a plugin installed from source goes with its
|
||||
// files: any source but a repository's link (a folder here, which no
|
||||
// other computer has, C:\ on Windows too), and a link that holds a
|
||||
// sign-in, which isn't carried (signedIn).
|
||||
func fromFiles(source string) bool {
|
||||
if source == "" || filepath.IsAbs(expand(source)) || signedIn(source) {
|
||||
return true
|
||||
}
|
||||
if _, ok := githubSource(source); ok {
|
||||
return false
|
||||
}
|
||||
_, ok, err := gitSource(source)
|
||||
return !ok || err != nil
|
||||
}
|
||||
|
||||
// signedIn reports whether a link holds a token: https://TOKEN@host/…,
|
||||
// or a password. ssh://git@host/… names the user SSH signs in as, which
|
||||
// is no secret.
|
||||
func signedIn(source string) bool {
|
||||
u, err := url.Parse(source)
|
||||
if err != nil || u.User == nil {
|
||||
return false
|
||||
}
|
||||
_, pw := u.User.Password()
|
||||
return pw || u.Scheme == "http" || u.Scheme == "https"
|
||||
}
|
||||
|
||||
// ownedPart reports whether an item is a part of a plugin the library has:
|
||||
// such an item goes with its plugin, not on its own.
|
||||
func (l *Library) ownedPart(bundle string) bool {
|
||||
return bundle != "" && l.plugin(bundle) != nil
|
||||
}
|
||||
|
||||
// carriedPlugins are the library's plugins for Collect; dirs are the
|
||||
// folders whose files go with them, read with the skills', one for each
|
||||
// plugin carried with files, in order, and at the index in out.
|
||||
func (l *Library) carriedPlugins() (out []*CarriedPlugin, dirs []string, at []int) {
|
||||
out = []*CarriedPlugin{}
|
||||
missing := map[string][]string{}
|
||||
for _, v := range l.pluginsView() {
|
||||
missing[v.Name] = v.Missing
|
||||
}
|
||||
for _, p := range sorted(l.Plugins, func(p *Plugin) string { return p.Name }) {
|
||||
c := &CarriedPlugin{Name: p.Name, Description: p.Description, Version: p.Version, Source: p.Source, Pick: p.Pick,
|
||||
Agents: orNone(slices.Sorted(slices.Values(p.Agents))), Off: p.Off}
|
||||
if m := missing[p.Name]; len(m) > 0 {
|
||||
c.Taken = slices.Sorted(slices.Values(m))
|
||||
}
|
||||
if fromFiles(p.Source) && !p.Pending {
|
||||
if signedIn(p.Source) {
|
||||
c.Source = ""
|
||||
}
|
||||
dirs, at = append(dirs, realDir(pluginDir(p.Name))), append(at, len(out))
|
||||
}
|
||||
out = append(out, c)
|
||||
}
|
||||
return out, dirs, at
|
||||
}
|
||||
|
||||
// heldParts are the parts of this computer's plugins, kept out of l while
|
||||
// Put replaces its items with a bundle's (which carries none of them),
|
||||
// and put back after.
|
||||
type heldParts struct {
|
||||
skills []*Skill
|
||||
servers []*Server
|
||||
hooks []*Hook
|
||||
subagents []*Subagent
|
||||
}
|
||||
|
||||
func (l *Library) holdPluginParts() *heldParts {
|
||||
h := &heldParts{}
|
||||
l.Skills = slices.DeleteFunc(l.Skills, func(s *Skill) bool {
|
||||
if l.ownedPart(s.Bundle) {
|
||||
h.skills = append(h.skills, s)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
l.MCP = slices.DeleteFunc(l.MCP, func(s *Server) bool {
|
||||
if l.ownedPart(s.Bundle) {
|
||||
h.servers = append(h.servers, s)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
l.Hooks = slices.DeleteFunc(l.Hooks, func(x *Hook) bool {
|
||||
if l.ownedPart(x.Bundle) {
|
||||
h.hooks = append(h.hooks, x)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
l.Subagents = slices.DeleteFunc(l.Subagents, func(s *Subagent) bool {
|
||||
if l.ownedPart(s.Bundle) {
|
||||
h.subagents = append(h.subagents, s)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return h
|
||||
}
|
||||
|
||||
// without is b without the items that have the name of a held part: a
|
||||
// bundle from a magpie before plugins were carried has a plugin's parts as
|
||||
// its own items, and this computer's plugin keeps its own.
|
||||
func (h *heldParts) without(b *Bundle) *Bundle {
|
||||
c := *b
|
||||
skills := map[string]bool{}
|
||||
for _, s := range h.skills {
|
||||
skills[s.Name] = true
|
||||
}
|
||||
c.Skills = slices.DeleteFunc(slices.Clone(b.Skills), func(s *CarriedSkill) bool { return skills[s.Name] })
|
||||
servers := map[string]bool{}
|
||||
for _, s := range h.servers {
|
||||
servers[s.Name] = true
|
||||
}
|
||||
c.MCP = slices.DeleteFunc(slices.Clone(b.MCP), func(s *Server) bool { return servers[s.Name] })
|
||||
if b.Hooks != nil {
|
||||
names := map[string]bool{}
|
||||
for _, x := range h.hooks {
|
||||
names[x.Name] = true
|
||||
}
|
||||
hooks := slices.DeleteFunc(slices.Clone(*b.Hooks), func(x *Hook) bool { return names[x.Name] })
|
||||
c.Hooks = &hooks
|
||||
}
|
||||
if b.Subagents != nil {
|
||||
names := map[string]bool{}
|
||||
for _, s := range h.subagents {
|
||||
names[s.Name] = true
|
||||
}
|
||||
subs := slices.DeleteFunc(slices.Clone(*b.Subagents), func(s *Subagent) bool { return names[s.Name] })
|
||||
c.Subagents = &subs
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
// putBack returns the held parts to l, but for one whose name an item the
|
||||
// bundle brought has now: that one is the library's, and the plugin's part
|
||||
// is gone (the page lists it as taken out).
|
||||
func (l *Library) putBack(h *heldParts) {
|
||||
for _, s := range h.skills {
|
||||
if l.skill(s.Name) == nil {
|
||||
l.Skills = append(l.Skills, s)
|
||||
}
|
||||
}
|
||||
for _, s := range h.servers {
|
||||
if l.server(s.Name) == nil {
|
||||
l.MCP = append(l.MCP, s)
|
||||
}
|
||||
}
|
||||
for _, x := range h.hooks {
|
||||
if l.hook(x.Name) == nil {
|
||||
l.Hooks = append(l.Hooks, x)
|
||||
}
|
||||
}
|
||||
for _, s := range h.subagents {
|
||||
if l.subagent(s.Name) == nil {
|
||||
l.Subagents = append(l.Subagents, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// putPlugins makes l's plugins the ones carried, inside Put's change: a
|
||||
// plugin as it is here only takes the agents and the switch; one carried
|
||||
// with its files is installed from them, in stage; one carried by its
|
||||
// source is recorded as pending, to be fetched once the library is let go
|
||||
// (fetch); one the bundle hasn't is taken out, its folder after (gone).
|
||||
func (l *Library) putPlugins(in []*CarriedPlugin, stage string) (fetch []*CarriedPlugin, gone []string, problems []Problem) {
|
||||
want := map[string]bool{}
|
||||
for _, c := range in {
|
||||
want[c.Name] = true
|
||||
}
|
||||
for _, p := range slices.Clone(l.Plugins) {
|
||||
if !want[p.Name] {
|
||||
removePluginParts(l, p)
|
||||
l.Plugins = slices.DeleteFunc(l.Plugins, func(x *Plugin) bool { return x.Name == p.Name })
|
||||
gone = append(gone, p.Name)
|
||||
}
|
||||
}
|
||||
settle := func(p *Plugin, c *CarriedPlugin) {
|
||||
p.Agents, p.Off = slices.Clone(orNone(c.Agents)), c.Off
|
||||
if c.Description != "" {
|
||||
p.Description = c.Description
|
||||
}
|
||||
takeOut(l, p, c.Taken)
|
||||
l.givePlugin(p)
|
||||
}
|
||||
for _, c := range in {
|
||||
have := l.plugin(c.Name)
|
||||
local := c.Files != nil
|
||||
same := have != nil && !have.Pending && have.Source == c.Source && have.Pick == c.Pick && have.Version == c.Version
|
||||
if same && local {
|
||||
here := readSkills([]string{realDir(pluginDir(c.Name))})[0]
|
||||
same = sameFiles(here, &CarriedSkill{Files: c.Files, Exec: c.Exec})
|
||||
}
|
||||
if same {
|
||||
settle(have, c)
|
||||
continue
|
||||
}
|
||||
if !local {
|
||||
p := have
|
||||
if p == nil {
|
||||
p = &Plugin{Name: c.Name}
|
||||
l.Plugins = append(l.Plugins, p)
|
||||
sort.Slice(l.Plugins, func(i, j int) bool { return l.Plugins[i].Name < l.Plugins[j].Name })
|
||||
}
|
||||
// the old version's parts stay until the new one is in
|
||||
p.Description, p.Version, p.Source, p.Pick, p.Pending = c.Description, c.Version, c.Source, c.Pick, true
|
||||
settle(p, c)
|
||||
fetch = append(fetch, c)
|
||||
continue
|
||||
}
|
||||
fail := func(err error) {
|
||||
problems = append(problems, Problem{What: "plugin:" + c.Name, Error: err.Error()})
|
||||
}
|
||||
dir := filepath.Join(stage, ".plugin-"+c.Name)
|
||||
files := &CarriedSkill{Files: c.Files, Exec: c.Exec, Left: c.Left}
|
||||
if err := writeSkill(dir, files); err != nil {
|
||||
fail(err)
|
||||
continue
|
||||
}
|
||||
if err := keepLeft(dir, realDir(pluginDir(c.Name)), files); err != nil {
|
||||
fail(err)
|
||||
continue
|
||||
}
|
||||
pl, err := readPlugin(dir, c.Name, c.Name, nil)
|
||||
if err != nil {
|
||||
fail(err)
|
||||
continue
|
||||
}
|
||||
if pl.parts() == 0 {
|
||||
fail(fmt.Errorf("%s has no skills, MCP servers, hooks or subagents magpie can give an agent", c.Name))
|
||||
continue
|
||||
}
|
||||
skipped, err := installPlugin(l, pl, dir, c.Source, c.Pick, c.Agents)
|
||||
if err != nil {
|
||||
fail(err)
|
||||
continue
|
||||
}
|
||||
problems = append(problems, skipped...)
|
||||
if p := l.plugin(c.Name); p != nil {
|
||||
if c.Version != "" {
|
||||
p.Version = c.Version
|
||||
}
|
||||
settle(p, c)
|
||||
}
|
||||
}
|
||||
return fetch, gone, problems
|
||||
}
|
||||
|
||||
// takeOut takes out of l the parts of p the user took out by hand on the
|
||||
// other computer, named as PluginView's Missing names them.
|
||||
func takeOut(l *Library, p *Plugin, taken []string) {
|
||||
stamp := time.Now().Format("2006-01-02_15-04-05.000")
|
||||
for _, t := range taken {
|
||||
switch {
|
||||
case strings.HasPrefix(t, "skill "):
|
||||
if s := l.skill(strings.TrimPrefix(t, "skill ")); s != nil && s.Bundle == p.Name {
|
||||
_ = removeSkill(l, s.Name, stamp)
|
||||
}
|
||||
case strings.HasPrefix(t, "MCP server "):
|
||||
if s := l.server(strings.TrimPrefix(t, "MCP server ")); s != nil && s.Bundle == p.Name {
|
||||
_ = removeServer(l, s.Name)
|
||||
}
|
||||
case strings.HasPrefix(t, "hook "):
|
||||
n := strings.TrimPrefix(t, "hook ")
|
||||
l.Hooks = slices.DeleteFunc(l.Hooks, func(h *Hook) bool { return h.Name == n && h.Bundle == p.Name })
|
||||
case strings.HasPrefix(t, "subagent "):
|
||||
n := strings.TrimPrefix(t, "subagent ")
|
||||
l.Subagents = slices.DeleteFunc(l.Subagents, func(s *Subagent) bool { return s.Name == n && s.Bundle == p.Name })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fetchPlugins installs the plugins Put recorded as pending from their
|
||||
// sources, the library let go of while each downloads; what fails stays
|
||||
// pending, said in problems, for Update or the next sync to try again.
|
||||
func fetchPlugins(in []*CarriedPlugin, res *Result) {
|
||||
for _, c := range in {
|
||||
r, err := UpdatePlugin(c.Name)
|
||||
if err != nil {
|
||||
res.Problems = append(res.Problems, Problem{What: "plugin:" + c.Name,
|
||||
Error: "not fetched from its source on this computer yet (Update tries again): " + err.Error()})
|
||||
continue
|
||||
}
|
||||
if len(c.Taken) > 0 {
|
||||
if t, err := change(func(l *Library) error {
|
||||
if p := l.plugin(c.Name); p != nil {
|
||||
takeOut(l, p, c.Taken)
|
||||
}
|
||||
return nil
|
||||
}); err == nil {
|
||||
r.Changed = append(r.Changed, t.Changed...)
|
||||
r.Problems = append(r.Problems, t.Problems...)
|
||||
}
|
||||
}
|
||||
for _, a := range r.Changed {
|
||||
if !slices.Contains(res.Changed, a) {
|
||||
res.Changed = append(res.Changed, a)
|
||||
}
|
||||
}
|
||||
res.Problems = append(res.Problems, r.Problems...)
|
||||
res.Problems = append(res.Problems, r.Skipped...)
|
||||
}
|
||||
}
|
||||
|
||||
// removePluginDirs takes the folders of the plugins Put took out.
|
||||
func removePluginDirs(names []string) {
|
||||
for _, n := range names {
|
||||
os.RemoveAll(pluginDir(n))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// inJSON is s as a JSON file holds it, without its quotes.
|
||||
func inJSON(s string) string { b, _ := json.Marshal(s); return string(b[1 : len(b)-1]) }
|
||||
|
||||
// #6685 (JJasonsun on Discord): a plugin installed through the Library
|
||||
// on one computer never reached the other. Its parts went as ordinary
|
||||
// skills, hooks and servers naming the first computer's folder, and its
|
||||
// record didn't go at all. Now the plugin goes whole, from a folder with
|
||||
// its files, and the second computer installs it in its own folder: its
|
||||
// hook names that folder, its script is there, and nothing the first
|
||||
// computer's paths are in goes back.
|
||||
func TestPluginCarriedWhole(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(h, "work", "acme")
|
||||
writePlugin(t, src)
|
||||
write(t, filepath.Join(src, "scripts/lint.sh"), "#!/bin/sh\necho lint\n")
|
||||
os.Chmod(filepath.Join(src, "scripts/lint.sh"), 0o755)
|
||||
ok(t)(InstallPlugins(src, nil, []string{"claude"}))
|
||||
ok(t)(PluginOn("acme-kit", true))
|
||||
first := pluginDir("acme-kit")
|
||||
|
||||
b, err := Collect()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
carried := mustJSON(t, b)
|
||||
if b.Plugins == nil || len(*b.Plugins) != 1 {
|
||||
t.Fatalf("plugins carried: %s", carried)
|
||||
}
|
||||
p := (*b.Plugins)[0]
|
||||
if p.Name != "acme-kit" || p.Version != "1.2.0" || p.Source != src || p.Files["hooks/hooks.json"] == nil || p.Files["scripts/lint.sh"] == nil {
|
||||
t.Fatalf("the plugin carried: %+v", p)
|
||||
}
|
||||
if runtime.GOOS != "windows" && (len(p.Exec) != 1 || p.Exec[0] != "scripts/lint.sh") {
|
||||
t.Errorf("the script that runs: %v", p.Exec)
|
||||
}
|
||||
// its parts don't go on their own: each names this computer's folder
|
||||
if len(b.Skills) != 0 || len(b.MCP) != 0 || len(*b.Hooks) != 0 || len(*b.Subagents) != 0 {
|
||||
t.Errorf("a plugin's parts carried as the library's own: %d skills, %d servers, %d hooks, %d subagents",
|
||||
len(b.Skills), len(b.MCP), len(*b.Hooks), len(*b.Subagents))
|
||||
}
|
||||
if strings.Contains(carried, inJSON(first)) {
|
||||
t.Errorf("the bundle names the first computer's plugin folder %s", first)
|
||||
}
|
||||
|
||||
// the second computer has no such folder
|
||||
h2 := sandbox(t)
|
||||
pluginAgents(t, h2)
|
||||
second := pluginDir("acme-kit")
|
||||
if second == first {
|
||||
t.Fatal("one library folder for both computers")
|
||||
}
|
||||
r := putJSON(t, carried)
|
||||
for _, pr := range r.Problems {
|
||||
if pr.What != "plugin:acme-kit" || !strings.Contains(pr.Error, "commands") && !strings.Contains(pr.Error, "PreCompact") {
|
||||
t.Errorf("a problem: %+v", pr)
|
||||
}
|
||||
}
|
||||
v := View0(t)
|
||||
if len(v.Plugins) != 1 || v.Plugins[0].Name != "acme-kit" || v.Plugins[0].Version != "1.2.0" || len(v.Plugins[0].Hooks) != 3 || len(v.Plugins[0].Skills) != 1 {
|
||||
t.Fatalf("the plugin on the second computer: %+v", v.Plugins)
|
||||
}
|
||||
if len(v.Skills) != 1 || v.Skills[0].Bundle != "acme-kit" {
|
||||
t.Errorf("its skill: %+v", v.Skills)
|
||||
}
|
||||
settings := read(t, filepath.Join(h2, ".claude/settings.json"))
|
||||
if !strings.Contains(settings, inJSON(second+"/scripts/lint.sh")) {
|
||||
t.Errorf("claude's hook doesn't name this computer's folder %s:\n%s", second, settings)
|
||||
}
|
||||
if strings.Contains(settings, inJSON(first)) {
|
||||
t.Errorf("claude's hook names the first computer's folder:\n%s", settings)
|
||||
}
|
||||
if cj := read(t, filepath.Join(h2, ".claude.json")); !strings.Contains(cj, inJSON(second+"/bin/db")) {
|
||||
t.Errorf("claude's server doesn't name this computer's folder:\n%s", cj)
|
||||
}
|
||||
fi, err := os.Stat(filepath.Join(second, "scripts", "lint.sh"))
|
||||
if err != nil {
|
||||
t.Fatalf("the hook's script: %v", err)
|
||||
}
|
||||
if runtime.GOOS != "windows" && fi.Mode().Perm()&0o111 == 0 {
|
||||
t.Errorf("the hook's script doesn't run: %v", fi.Mode())
|
||||
}
|
||||
|
||||
// what it carries back is what came: no sync goes back and forth
|
||||
b2, err := Collect()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if back := mustJSON(t, b2); back != carried {
|
||||
t.Errorf("the second computer carries back another library:\n%s\nwas\n%s", back, carried)
|
||||
}
|
||||
// and the same bundle again installs nothing again
|
||||
installed := v.Plugins[0].Installed
|
||||
putJSON(t, carried)
|
||||
if v := View0(t); v.Plugins[0].Installed != installed {
|
||||
t.Errorf("the same plugin installed again: %s, was %s", v.Plugins[0].Installed, installed)
|
||||
}
|
||||
|
||||
// turned off on the first: off on the second
|
||||
(*b.Plugins)[0].Off = true
|
||||
putJSON(t, mustJSON(t, b))
|
||||
if s := read(t, filepath.Join(h2, ".claude/settings.json")); strings.Contains(s, "lint.sh") {
|
||||
t.Errorf("the hook stays while the plugin is off:\n%s", s)
|
||||
}
|
||||
|
||||
// taken out on the first: out of the second, its folder too
|
||||
none := []*CarriedPlugin{}
|
||||
b.Plugins = &none
|
||||
putJSON(t, mustJSON(t, b))
|
||||
if v := View0(t); len(v.Plugins) != 0 || len(v.Skills) != 0 || len(v.Hooks) != 0 || len(v.Servers) != 0 || len(v.Subagents) != 0 {
|
||||
t.Errorf("the plugin stays: %+v", v)
|
||||
}
|
||||
if _, err := os.Stat(second); err == nil {
|
||||
t.Errorf("its folder stays")
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin from a repository goes as its source, without its files, and
|
||||
// the second computer installs it from there, in its own folder. One
|
||||
// that can't be fetched there yet is kept as pending, with the problem
|
||||
// said, and Update fetches it.
|
||||
func TestPluginCarriedBySource(t *testing.T) {
|
||||
files := map[string]string{
|
||||
".claude-plugin/plugin.json": `{"name":"repo-kit","version":"2.0.0"}`,
|
||||
"hooks/hooks.json": `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${CLAUDE_PLUGIN_ROOT}/bin/done"}]}]}}`,
|
||||
"skills/a/SKILL.md": "---\nname: a\ndescription: A\n---\nA\n",
|
||||
}
|
||||
var down atomic.Bool
|
||||
tar := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if down.Load() {
|
||||
http.Error(w, "no", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
w.Write(tarball(t, files))
|
||||
}))
|
||||
t.Cleanup(tar.Close)
|
||||
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(`[{"sha":"p1","commit":{"message":"x","committer":{"date":"2026-09-01T10:00:00Z"}}}]`))
|
||||
}))
|
||||
t.Cleanup(api.Close)
|
||||
oldT, oldA := tarballURL, githubAPI
|
||||
tarballURL = func(repo, ref string) string { return tar.URL + "/tar/" + repo }
|
||||
githubAPI = api.URL
|
||||
t.Cleanup(func() { tarballURL, githubAPI = oldT, oldA })
|
||||
|
||||
const link = "https://github.com/acme/repo-kit"
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
ok(t)(InstallPlugins(link, nil, []string{"claude"}))
|
||||
b, err := Collect()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(*b.Plugins) != 1 || (*b.Plugins)[0].Source != link || (*b.Plugins)[0].Files != nil {
|
||||
t.Fatalf("carried: %s", mustJSON(t, b.Plugins))
|
||||
}
|
||||
carried := mustJSON(t, b)
|
||||
|
||||
h2 := sandbox(t)
|
||||
pluginAgents(t, h2)
|
||||
putJSON(t, carried)
|
||||
second := pluginDir("repo-kit")
|
||||
if s := read(t, filepath.Join(h2, ".claude/settings.json")); !strings.Contains(s, inJSON(second+"/bin/done")) {
|
||||
t.Errorf("claude's hook doesn't name this computer's folder:\n%s", s)
|
||||
}
|
||||
if v := View0(t); len(v.Plugins) != 1 || v.Plugins[0].Pending || len(v.Plugins[0].Skills) != 1 || v.Plugins[0].Source != link {
|
||||
t.Errorf("installed from its source: %+v", v.Plugins)
|
||||
}
|
||||
if back := mustJSON(t, must(Collect())); back != carried {
|
||||
t.Errorf("the second computer carries back another library:\n%s\nwas\n%s", back, carried)
|
||||
}
|
||||
|
||||
// a third computer that can't reach it yet
|
||||
h3 := sandbox(t)
|
||||
pluginAgents(t, h3)
|
||||
down.Store(true)
|
||||
r := putJSON(t, carried)
|
||||
if len(r.Problems) != 1 || r.Problems[0].What != "plugin:repo-kit" {
|
||||
t.Errorf("problems: %+v", r.Problems)
|
||||
}
|
||||
if v := View0(t); len(v.Plugins) != 1 || !v.Plugins[0].Pending {
|
||||
t.Fatalf("not kept as pending: %+v", v.Plugins)
|
||||
}
|
||||
// carried on as it came, so the others aren't told to change
|
||||
if back := mustJSON(t, must(Collect())); back != carried {
|
||||
t.Errorf("a pending plugin carried as another:\n%s\nwas\n%s", back, carried)
|
||||
}
|
||||
down.Store(false)
|
||||
ok(t)(UpdatePlugin("repo-kit"))
|
||||
if v := View0(t); v.Plugins[0].Pending || len(v.Plugins[0].Hooks) != 1 {
|
||||
t.Errorf("after Update: %+v", v.Plugins[0])
|
||||
}
|
||||
}
|
||||
|
||||
func must[T any](v T, err error) T {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// A bundle from a magpie before plugins were carried has a plugin's parts
|
||||
// as its own items, naming the other computer's folder, and no plugins:
|
||||
// this computer's plugin stays, with its own parts.
|
||||
func TestPluginOldBundleKeepsPlugins(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(h, "acme")
|
||||
writePlugin(t, src)
|
||||
ok(t)(InstallPlugins(src, nil, []string{"claude"}))
|
||||
b, err := Collect()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.Plugins = nil
|
||||
const there = "/Users/other/.config/magpie/library/plugins/acme-kit"
|
||||
b.Skills = append(b.Skills, &CarriedSkill{Name: "tdd", Agents: []string{"claude"},
|
||||
Files: map[string][]byte{"SKILL.md": []byte("---\nname: tdd\ndescription: Test first\n---\nRun " + there + "/x\n")}})
|
||||
hooks := []*Hook{{Name: "acme-kit-1", Event: "PostToolUse", Matcher: "Bash", Command: there + "/scripts/lint.sh", Agents: []string{"claude"}, Bundle: "acme-kit"}}
|
||||
b.Hooks = &hooks
|
||||
old := mustJSON(t, b)
|
||||
if strings.Contains(old, `"plugins"`) {
|
||||
t.Fatalf("not as an older magpie wrote it: %s", old)
|
||||
}
|
||||
putJSON(t, old)
|
||||
v := View0(t)
|
||||
if len(v.Plugins) != 1 || len(v.Plugins[0].Missing) != 0 || len(v.Skills) != 1 || len(v.Hooks) != 3 {
|
||||
t.Errorf("an old bundle took this computer's plugin: plugins %+v, %d skills, %d hooks", v.Plugins, len(v.Skills), len(v.Hooks))
|
||||
}
|
||||
if s := read(t, filepath.Join(h, ".claude/settings.json")); strings.Contains(s, there) || !strings.Contains(s, inJSON(pluginDir("acme-kit"))) {
|
||||
t.Errorf("claude's hooks after an old bundle:\n%s", s)
|
||||
}
|
||||
if s := read(t, filepath.Join(skillDir("tdd"), "SKILL.md")); strings.Contains(s, there) {
|
||||
t.Errorf("the plugin's skill written over: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// The parts of a plugin a marketplace names other than its manifest does
|
||||
// name the folder it is kept in, the marketplace's name's: they named the
|
||||
// manifest's, a folder that isn't there.
|
||||
func TestPluginMarketplaceNameIsItsFolder(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
mk := filepath.Join(h, "market")
|
||||
write(t, filepath.Join(mk, ".claude-plugin/marketplace.json"), `{"name":"m","plugins":[
|
||||
{"name":"one","source":"./plugins/one"},{"name":"two","source":"./plugins/two"}]}`)
|
||||
write(t, filepath.Join(mk, "plugins/one/.claude-plugin/plugin.json"), `{"name":"one-by-its-own-name"}`)
|
||||
write(t, filepath.Join(mk, "plugins/one/hooks/hooks.json"), `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${CLAUDE_PLUGIN_ROOT}/run"}]}]}}`)
|
||||
write(t, filepath.Join(mk, "plugins/two/skills/b/SKILL.md"), "---\nname: b\ndescription: B\n---\nB\n")
|
||||
ok(t)(InstallPlugins(mk, []string{"one"}, []string{"claude"}))
|
||||
s := read(t, filepath.Join(h, ".claude/settings.json"))
|
||||
if !strings.Contains(s, inJSON(pluginDir("one")+"/run")) {
|
||||
t.Errorf("the hook doesn't name the plugin's folder %s:\n%s", pluginDir("one"), s)
|
||||
}
|
||||
if _, err := os.Stat(pluginDir("one")); err != nil {
|
||||
t.Errorf("its folder: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Whether a plugin goes with its files is the same on every computer: a
|
||||
// record synced from a Mac names /Users/…, one from Windows C:\…, and the
|
||||
// computer carrying it on may be the other one.
|
||||
func TestPluginFromFilesEitherOS(t *testing.T) {
|
||||
for src, want := range map[string]bool{
|
||||
"/Users/a/work/kit": true,
|
||||
`C:\Users\a\kit`: true,
|
||||
"c:/Users/a/kit": true,
|
||||
`\\nas\share\kit`: true,
|
||||
"~/kit": true,
|
||||
"": true,
|
||||
"https://tok@github.com/acme/kit": true,
|
||||
"https://github.com/acme/kit": false,
|
||||
"acme/kit": false,
|
||||
"git@github.com:acme/kit.git": false,
|
||||
"ssh://git@git.example.com/acme/kit.git": false,
|
||||
} {
|
||||
if got := fromFiles(src); got != want {
|
||||
t.Errorf("fromFiles(%q) = %v, want %v", src, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user