Skip to content

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

plugin: add takes a community plugin's name (WorkBuddy, think-tags, qoder-cn)

yetonea2ff7e6cab21
diff --git a/docs/reference.md b/docs/reference.md
index 36a529bf3..ff93ec06d 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -966,6 +966,7 @@ time a plugin needs it, and the plugin signs in, lists the models and makes
each request; magpie serves them to agents like any provider's.
```sh
+magpie plugin add workbuddy # a community plugin by its name (WorkBuddy, think-tags, Qoder)
magpie plugin add opencode-gemini-auth # an npm package, or a path to a plugin of your own
magpie plugin add pi-antigravity # a pi package, the same way
magpie plugin # the plugins, what each signs in to, and whether you are
diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md
index 540c395a5..cb5d65804 100644
--- a/docs/subsystems/provider-plugins.md
+++ b/docs/subsystems/provider-plugins.md
@@ -164,6 +164,8 @@ A `@magpie-community` package npm doesn't give is installed from the community r
A plugin on the list whose package isn't in `plugins/` is installed again from its own spec, switched off or not, by `plugin.InstallMissing`. `KeepUpdated` runs it 30 seconds after start and then hourly, before `CheckUpdates`. Nothing else did this. An update skips a plugin with no installed version, so the host said `no such plugin: …\node_modules\…` at every start until the user removed the plugin and added it again (#2002, Windows, after an update). Every bun command that changes `plugins/` runs one at a time under `installMu`: `install` (with the first `package.json` it writes), `reinstall`'s `bun update`, and `Remove`'s and `add`'s `bun remove`. At start, `KeepUpdated` and `keepMovedCurrent` both run `bun add`. Two at once each read `package.json` before either writes it, so one change was lost (reproduced with Bun 1.4.3 on Windows), and a git plugin whose dependency was dropped can't be found. `TestMissingPluginsInstalledAgain` and `TestBunCommandsOneAtATime` in [`plugin_missing_test.go`](../../internal/plugin/plugin_missing_test.go) cover both.
+A name the user types is resolved before anything is installed (`resolve` in [`resolve.go`](../../internal/plugin/resolve.go)), in `plugin.Add`, which the CLI's `magpie plugin add`, the Plugins page's field (`/api/plugins/add`) and the movers all go through. A bare name that one of the community's listings goes by, case aside, is that package at the version given: its package or that without the scope, its short name (`workbuddy`, `think-tags`), its shown name (`WorkBuddy`, `Command Code`), a provider id it serves or the subscription it replaces, and a retired subscription's id through its mover (`qoder-cn`, `plugin.SubscriptionPlugin` = `MovePackage`). A name two listings go by, or one no listing goes by that isn't an npm name, is refused with the community plugins named. A name no listing goes by is npm's own package (`opencode-gemini-auth`) only when the list was fetched within the six hours: when the fetch fails, the copy kept or built in may not name a newer plugin, so the name is refused with why, and `npm:<name>` installs npm's package as written. Before, `WorkBuddy` failed as no npm name, and `workbuddy` installed npm's unscoped `workbuddy` (Atlas on Discord, 10-25). Scoped names, paths and git specs are kept as written, and a backup's or a sync's plugins are installed by their own spec (`plugin.AddExact`), never resolved. `TestResolveCommunityNames`, `TestResolveRefusesWhatItCantName`, `TestResolveListUnread` and `TestAddByCommunityName` in [`resolve_test.go`](../../internal/plugin/resolve_test.go) cover these.
+
A plugin the user turned off stays off through every install path: `add` keeps `Off` when it replaces an existing entry, so Add, Update, Update all and Upgrade all leave it as the user left it.
## Constraints for fixes
diff --git a/internal/cli/plugins_cli.go b/internal/cli/plugins_cli.go
index 83ce70dac..6efe395c0 100644
--- a/internal/cli/plugins_cli.go
+++ b/internal/cli/plugins_cli.go
@@ -20,7 +20,7 @@ import (
)
const pluginUsage = `usage: magpie plugin [list] [--json]
- magpie plugin add <npm | git | path> install an OpenCode provider plugin, a pi package or a gateway hook/middleware (opencode-gemini-auth, pi-antigravity, github:owner/repo, ./my-plugin.js, ./alias.middleware.js, ./recall.hooks.ts)
+ magpie plugin add <name | npm | git | path> install a community plugin by its name (workbuddy, think-tags, Qoder), an OpenCode provider plugin, a pi package or a gateway hook/middleware (opencode-gemini-auth, pi-antigravity, github:owner/repo, ./my-plugin.js, ./alias.middleware.js, ./recall.hooks.ts); npm:<name> is npm's package of a name a community plugin goes by
magpie plugin rm <name> remove one
magpie plugin update install the newest version of each
magpie plugin on|off <name> turn one on or off
@@ -59,6 +59,10 @@ func pluginCmd(args []string) error {
return err
}
fmt.Println(green.Render("✓"), "added", e.Spec)
+ // a community plugin's name (workbuddy, WorkBuddy) stood for it
+ if typed := strings.TrimSpace(rest[0]); !plugin.IsPath(typed) && !plugin.IsGit(typed) && !strings.HasPrefix(typed, "npm:") && plugin.Name(typed) != plugin.Name(e.Spec) {
+ fmt.Println(faint.Render(" " + strconv.Quote(plugin.Name(typed)) + " is magpie's community plugin " + plugin.Name(e.Spec)))
+ }
// a deprecated built-in it serves, not signed in to, is its now
provider.HandOver(ctx, false)
return listPlugins(ctx, false)
diff --git a/internal/plugin/market.go b/internal/plugin/market.go
index e4ced05fe..ba6951bba 100644
--- a/internal/plugin/market.go
+++ b/internal/plugin/market.go
@@ -83,6 +83,7 @@ var (
marketMu sync.Mutex
marketList []Listing
marketAt time.Time
+ marketErr error // why marketList isn't a list just fetched; nil when it is
npmMu sync.Mutex
npmCache map[string]npmEntry // nil until read from npmCacheFile
)
@@ -180,15 +181,25 @@ func parseMarket(b []byte) ([]Listing, error) {
// Market is the list of plugins magpie suggests: fetched at most every six
// hours, else the copy fetched last, else the one built in.
func Market(ctx context.Context) []Listing {
+ l, _ := market(ctx)
+ return l
+}
+
+// market is Market, and why the list it gives isn't one fetched within
+// the six hours: the fetch's failure, when it is the copy fetched some
+// time before or the one built in. A newer list may name a plugin
+// neither does, so what one leaves out is unknown, not absent.
+func market(ctx context.Context) ([]Listing, error) {
marketMu.Lock()
defer marketMu.Unlock()
if marketList != nil && time.Since(marketAt) < 6*time.Hour {
- return marketList
+ return marketList, marketErr
}
src := os.Getenv("MAGPIE_PLUGIN_MARKET")
if src == "" {
src = MarketURL
}
+ ferr := errors.New("the list is off (MAGPIE_PLUGIN_MARKET=off)")
if src != "off" {
c, cancel := context.WithTimeout(ctx, 6*time.Second)
// the list names the packages installed: a copy of the very file
@@ -196,24 +207,27 @@ func Market(ctx context.Context) []Listing {
b, err := fetchJSONFaithful(c, src, 1<<20)
cancel()
if err == nil {
- if l, err := parseMarket(b); err == nil {
- marketList, marketAt = l, time.Now()
+ l, perr := parseMarket(b)
+ if perr == nil {
+ marketList, marketAt, marketErr = l, time.Now(), nil
_ = os.MkdirAll(filepath.Dir(marketCache()), 0o755)
_ = os.WriteFile(marketCache(), b, 0o644)
- return l
+ return l, nil
}
+ err = perr
}
+ ferr = err
if b, err := os.ReadFile(marketCache()); err == nil {
if l, err := parseMarket(b); err == nil {
// tried again in a minute, not six hours
- marketList, marketAt = l, time.Now().Add(-6*time.Hour+time.Minute)
- return l
+ marketList, marketAt, marketErr = l, time.Now().Add(-6*time.Hour+time.Minute), ferr
+ return l, ferr
}
}
}
l, _ := parseMarket(builtinMarket)
- marketList, marketAt = l, time.Now().Add(-6*time.Hour+time.Minute)
- return l
+ marketList, marketAt, marketErr = l, time.Now().Add(-6*time.Hour+time.Minute), ferr
+ return l, ferr
}
// RefreshMarket has the next Market fetch the list again, as with the
diff --git a/internal/plugin/resolve.go b/internal/plugin/resolve.go
new file mode 100644
index 000000000..d1a6f5085
--- /dev/null
+++ b/internal/plugin/resolve.go
@@ -0,0 +1,119 @@
+package plugin
+
+import (
+ "context"
+ "fmt"
+ "slices"
+ "sort"
+ "strings"
+)
+
+// SubscriptionPlugin is the community package that serves a retired
+// built-in subscription, by its id (commandcode-plan, qoder-cn), "" for
+// none: provider's movers, which plugin can't import, set it.
+var SubscriptionPlugin = func(id string) string { return "" }
+
+// npmPrefix asks for npm's own package of a name, as written, where the
+// name is also one a community plugin is called by: npm:think-tags is
+// npm's think-tags, not @magpie-community/middleware-think-tags.
+const npmPrefix = "npm:"
+
+// callNames are the names a listing goes by, lower-cased: its package,
+// that without the scope and its short name (think-tags, workbuddy), its
+// name as shown (WorkBuddy, Command Code, with and without the space),
+// and the provider ids it serves or the subscription it replaces.
+func callNames(l Listing) []string {
+ n := strings.ToLower(strings.TrimSpace(l.Name))
+ out := []string{l.Package, bareName(l.Package), ShortName(l.Package), n, strings.ReplaceAll(n, " ", ""), strings.ReplaceAll(n, " ", "-"), l.Replaces}
+ out = append(out, l.Providers...)
+ for i := range out {
+ out[i] = strings.ToLower(out[i])
+ }
+ return out
+}
+
+// resolve is the npm spec a user's name for a plugin stands for: a short
+// or shown name (workbuddy, WorkBuddy, think-tags, "Qoder", qoder-cn)
+// that names one of magpie's community plugins, case aside, is that
+// package, at the version given. A scoped package, a path or a git spec is
+// kept as it is, and so is a name no community plugin goes by, which is
+// npm's own (opencode-gemini-auth) once the list was read just now: a
+// short name never reaches npm's unscoped package of that name while a
+// community plugin is called by it, or may be, as far as magpie knows.
+// npm:name is npm's name, as written.
+func resolve(ctx context.Context, spec string) (string, error) {
+ if after, ok := strings.CutPrefix(spec, npmPrefix); ok {
+ after = strings.TrimSpace(after)
+ if !pkgName.MatchString(Name(after)) {
+ return "", fmt.Errorf("%q isn't an npm package name", after)
+ }
+ return after, nil
+ }
+ if IsPath(spec) || IsGit(spec) || strings.HasPrefix(spec, "@") {
+ return spec, nil
+ }
+ name, version := spec, ""
+ if at := strings.LastIndex(spec, "@"); at > 0 {
+ name, version = spec[:at], spec[at:]
+ }
+ key := strings.ToLower(strings.TrimSpace(name))
+ if key == "" {
+ return spec, nil
+ }
+ list, lerr := market(ctx)
+ var found []string
+ for _, l := range list {
+ if slices.Contains(callNames(l), key) && !slices.Contains(found, l.Package) {
+ found = append(found, l.Package)
+ }
+ }
+ if p := SubscriptionPlugin(key); p != "" && !slices.Contains(found, p) {
+ found = append(found, p)
+ }
+ switch {
+ case len(found) == 1:
+ return found[0] + version, nil
+ case len(found) > 1:
+ sort.Strings(found)
+ return "", fmt.Errorf("%q names more than one of magpie's community plugins: %s; give the one you mean", name, strings.Join(found, ", "))
+ }
+ valid := pkgName.MatchString(name)
+ if valid && lerr == nil {
+ // npm's own package: no community plugin goes by the name
+ return spec, nil
+ }
+ var b strings.Builder
+ if lerr != nil {
+ fmt.Fprintf(&b, "couldn't read the community plugin list (%v), so there is no telling whether %q is one of them", lerr, name)
+ } else {
+ fmt.Fprintf(&b, "no plugin is called %q", name)
+ }
+ if names := listNames(list); names != "" {
+ b.WriteString(". The community plugins")
+ if lerr != nil {
+ b.WriteString(" magpie knows of")
+ }
+ b.WriteString(": " + names)
+ }
+ if valid {
+ fmt.Fprintf(&b, ". Try again once the list can be read, give the plugin's full package name (@magpie-community/…), or npm:%s for npm's package %s", name, name)
+ } else {
+ b.WriteString(". Or give an npm package, a GitHub repo (github:owner/repo) or a folder")
+ }
+ return "", fmt.Errorf("%s", b.String())
+}
+
+// listNames are the listings as a user writes them: the short name, and
+// the name shown where it differs.
+func listNames(list []Listing) string {
+ var out []string
+ for _, l := range list {
+ s := ShortName(l.Package)
+ if l.Name != "" && !strings.EqualFold(l.Name, s) {
+ s += " (" + l.Name + ")"
+ }
+ out = append(out, s)
+ }
+ sort.Strings(out)
+ return strings.Join(out, ", ")
+}
diff --git a/internal/plugin/resolve_test.go b/internal/plugin/resolve_test.go
new file mode 100644
index 000000000..4fadecb19
--- /dev/null
+++ b/internal/plugin/resolve_test.go
@@ -0,0 +1,164 @@
+package plugin
+
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// testRegistry is the community's registry.json as these tests serve it:
+// the real file's shape, a provider plugin with two ids, a middleware, and
+// two plugins that share a provider id.
+const testRegistry = `{"version":1,"plugins":[
+{"package":"@magpie-community/opencode-workbuddy-auth","name":"WorkBuddy","providers":["workbuddy","workbuddy-ai"],"replaces":"workbuddy","community":true},
+{"package":"@magpie-community/opencode-qoder-auth","name":"Qoder","providers":["qoder"],"replaces":"qoder","community":true},
+{"package":"@magpie-community/opencode-commandcode-auth","name":"Command Code","providers":["commandcode-plan"],"replaces":"commandcode-plan","community":true},
+{"package":"@magpie-community/opencode-zed-auth","name":"Zed","providers":["zed"],"replaces":"zed","community":true},
+{"package":"@magpie-community/middleware-think-tags","name":"Think Tags","kind":"middleware","community":true},
+{"package":"@magpie-community/opencode-twin-a-auth","name":"Twin A","providers":["twin"],"community":true},
+{"package":"@magpie-community/opencode-twin-b-auth","name":"Twin B","providers":["twin"],"community":true}
+]}`
+
+// serveRegistry has the market read testRegistry from a server of the
+// test's own, or fail to when down is set; nothing is kept between tests.
+func serveRegistry(t *testing.T, down *bool) {
+ t.Helper()
+ t.Setenv("XDG_CACHE_HOME", t.TempDir())
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if down != nil && *down {
+ http.Error(w, "down", http.StatusBadGateway)
+ return
+ }
+ w.Write([]byte(testRegistry))
+ }))
+ t.Cleanup(srv.Close)
+ t.Setenv("MAGPIE_PLUGIN_MARKET", srv.URL)
+ forgetMarket := func() { marketMu.Lock(); marketList, marketErr = nil, nil; marketMu.Unlock() }
+ forgetMarket()
+ t.Cleanup(forgetMarket)
+ old := SubscriptionPlugin
+ SubscriptionPlugin = func(id string) string {
+ if id == "qoder-cn" {
+ return "@magpie-community/opencode-qoder-auth"
+ }
+ return ""
+ }
+ t.Cleanup(func() { SubscriptionPlugin = old })
+}
+
+// A community plugin's short or shown name, case aside, is its package
+// (Atlas on Discord: `magpie plugin add WorkBuddy` said it "isn't an npm
+// package name", and a bare workbuddy would have installed npm's unscoped
+// workbuddy). npm's own package names, scoped ones, paths and git specs
+// are kept as written; npm: asks for npm's package of a name a community
+// plugin goes by.
+func TestResolveCommunityNames(t *testing.T) {
+ serveRegistry(t, nil)
+ ctx := context.Background()
+ for in, want := range map[string]string{
+ "workbuddy": "@magpie-community/opencode-workbuddy-auth",
+ "WorkBuddy": "@magpie-community/opencode-workbuddy-auth",
+ " WORKBUDDY ": "@magpie-community/opencode-workbuddy-auth",
+ "workbuddy-ai": "@magpie-community/opencode-workbuddy-auth",
+ "opencode-workbuddy-auth": "@magpie-community/opencode-workbuddy-auth",
+ "[email protected]": "@magpie-community/[email protected]",
+ "Qoder": "@magpie-community/opencode-qoder-auth",
+ "qoder-cn": "@magpie-community/opencode-qoder-auth", // a mover's id, not in the registry
+ "think-tags": "@magpie-community/middleware-think-tags",
+ "Think Tags": "@magpie-community/middleware-think-tags",
+ "Command Code": "@magpie-community/opencode-commandcode-auth",
+ "commandcode": "@magpie-community/opencode-commandcode-auth",
+ "commandcode-plan": "@magpie-community/opencode-commandcode-auth",
+ "zed": "@magpie-community/opencode-zed-auth",
+ "opencode-gemini-auth": "opencode-gemini-auth",
+ "@acme/workbuddy": "@acme/workbuddy",
+ "npm:think-tags": "think-tags",
+ "github:someone/workbuddy": "github:someone/workbuddy",
+ "./workbuddy": "./workbuddy",
+ "@magpie-community/zed-new": "@magpie-community/zed-new",
+ } {
+ got, err := resolve(ctx, strings.TrimSpace(in))
+ if err != nil || got != want {
+ t.Errorf("resolve(%q) = %q, %v; want %q", in, got, err, want)
+ }
+ }
+}
+
+// A name that two plugins go by, or none and isn't npm's, is refused with
+// the plugins it could be; never sent to npm.
+func TestResolveRefusesWhatItCantName(t *testing.T) {
+ serveRegistry(t, nil)
+ ctx := context.Background()
+ _, err := resolve(ctx, "twin")
+ if err == nil || !strings.Contains(err.Error(), "opencode-twin-a-auth") || !strings.Contains(err.Error(), "opencode-twin-b-auth") {
+ t.Fatalf("twin: %v, want both candidates named", err)
+ }
+ _, err = resolve(ctx, "Work Buddy Pro")
+ if err == nil || !strings.Contains(err.Error(), "workbuddy, zed") || !strings.Contains(err.Error(), "think-tags (Think Tags)") {
+ t.Fatalf("Work Buddy Pro: %v, want the community plugins listed", err)
+ }
+ if _, err := resolve(ctx, "npm:Not A Name"); err == nil {
+ t.Fatal("npm:Not A Name: no error")
+ }
+}
+
+// The list unread is unknown, not empty: a name it would have to rule out
+// isn't sent to npm on a guess, while one a copy magpie has names is still
+// its package, and npm: is still npm's.
+func TestResolveListUnread(t *testing.T) {
+ down := true
+ serveRegistry(t, &down)
+ ctx := context.Background()
+ _, err := resolve(ctx, "opencode-gemini-auth")
+ if err == nil || !strings.Contains(err.Error(), "couldn't read the community plugin list") || !strings.Contains(err.Error(), "npm:opencode-gemini-auth") {
+ t.Fatalf("list down: %v, want it refused, saying why and npm:", err)
+ }
+ // the copy built in names WorkBuddy
+ if got, err := resolve(ctx, "WorkBuddy"); err != nil || got != "@magpie-community/opencode-workbuddy-auth" {
+ t.Fatalf("list down, WorkBuddy: %q, %v", got, err)
+ }
+ if got, err := resolve(ctx, "npm:opencode-gemini-auth"); err != nil || got != "opencode-gemini-auth" {
+ t.Fatalf("list down, npm:: %q, %v", got, err)
+ }
+ // up again: read anew once the held copy's minute is over
+ down = false
+ marketMu.Lock()
+ marketAt = time.Time{}
+ marketMu.Unlock()
+ if got, err := resolve(ctx, "opencode-gemini-auth"); err != nil || got != "opencode-gemini-auth" {
+ t.Fatalf("list up: %q, %v", got, err)
+ }
+}
+
+// Add is where every route installs by name (the CLI, the Plugins page's
+// field, a backup's plugins): WorkBuddy installs the community package,
+// and bun is never asked for npm's unscoped workbuddy.
+func TestAddByCommunityName(t *testing.T) {
+ for _, in := range []string{"WorkBuddy", "workbuddy"} {
+ t.Run(in, func(t *testing.T) {
+ dir := offSandbox(t)
+ serveRegistry(t, nil)
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+ e, err := Add(ctx, in)
+ if err != nil {
+ t.Fatal(err)
+ }
+ const want = "@magpie-community/opencode-workbuddy-auth@latest"
+ if e.Spec != want {
+ t.Fatalf("Add(%q) = %s, want %s", in, e.Spec, want)
+ }
+ b, _ := os.ReadFile(filepath.Join(dir, "bun.log"))
+ if !strings.Contains(string(b), "add --ignore-scripts "+want) || strings.Contains(string(b), " workbuddy@") {
+ t.Fatalf("bun was asked:\n%s", b)
+ }
+ })
+ }
+}
diff --git a/internal/plugin/store.go b/internal/plugin/store.go
index a96096c83..7ff970b9f 100644
--- a/internal/plugin/store.go
+++ b/internal/plugin/store.go
@@ -360,8 +360,20 @@ func Target(spec string) string {
}
// Add installs a plugin and adds it to the list, in place of one of the
-// same package. A package is installed with its scripts left unrun.
-func Add(ctx context.Context, spec string) (Entry, error) { return add(ctx, spec, "") }
+// same package. A package is installed with its scripts left unrun. A
+// community plugin's short or shown name (workbuddy, WorkBuddy) is its
+// package (resolve); the entry gives the package installed.
+func Add(ctx context.Context, spec string) (Entry, error) {
+ spec, err := resolve(ctx, strings.TrimSpace(spec))
+ if err != nil {
+ return Entry{}, err
+ }
+ return add(ctx, spec, "")
+}
+
+// AddExact is Add of a spec that is a package's own (another computer's
+// plugins.json), installed as written, never taken for a name.
+func AddExact(ctx context.Context, spec string) (Entry, error) { return add(ctx, spec, "") }
// add is Add, an npm package installed at the version given when there is
// one (installAt), its spec kept as given.
diff --git a/internal/plugin/update_held_test.go b/internal/plugin/update_held_test.go
index 859b106bb..a281761e1 100644
--- a/internal/plugin/update_held_test.go
+++ b/internal/plugin/update_held_test.go
@@ -174,6 +174,9 @@ func TestAgeText(t *testing.T) {
// A pinned one already at npm's newest stays pinned.
func TestUpdateAllUpdatesAPinnedPlugin(t *testing.T) {
sandbox(t)
+ // the community's list, read: no plugin of it is called this, so the
+ // name is npm's own package
+ serveRegistry(t, nil)
const pkg = "opencode-someones-auth"
heldRegistry(t, pkg, map[string]time.Time{"1.0.0": time.Now().Add(-72 * time.Hour), "2.0.0": time.Now().Add(-48 * time.Hour)}, "2.0.0")
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
diff --git a/internal/provider/backup.go b/internal/provider/backup.go
index baf6066dc..1738f4ea9 100644
--- a/internal/provider/backup.go
+++ b/internal/provider/backup.go
@@ -182,7 +182,10 @@ func AddPlugins(ctx context.Context, es []plugin.Entry) (added []string, failed
continue
}
here[plugin.Name(e.Spec)] = true
- got, err := AddPlugin(ctx, e.Spec)
+ // the package that computer installed, as it has it: never
+ // taken for a community plugin's name, or held while the
+ // community's list can't be read
+ got, err := addPluginWith(ctx, e.Spec, addPluginExact)
if err == nil && e.Off {
err = plugin.SetOff(got.Spec, true)
}
diff --git a/internal/provider/backup_test.go b/internal/provider/backup_test.go
index b28a6e2a8..cf157bdbc 100644
--- a/internal/provider/backup_test.go
+++ b/internal/provider/backup_test.go
@@ -127,10 +127,11 @@ func TestPluginsCarried(t *testing.T) {
// the other computer: the model-map middleware is here already, as the
// user set it; the cursor plugin is not
write(`{"plugins":[{"spec":"@magpie-community/[email protected]","options":{"map":{"x":"y"}}}]}`)
- oldAdd, oldHand := addPlugin, handOver
- t.Cleanup(func() { addPlugin, handOver = oldAdd, oldHand })
+ oldAdd, oldHand := addPluginExact, handOver
+ t.Cleanup(func() { addPluginExact, handOver = oldAdd, oldHand })
var asked []string
- addPlugin = func(_ context.Context, spec string) (plugin.Entry, error) {
+ // the spec as the other computer has it, never resolved as a name
+ addPluginExact = func(_ context.Context, spec string) (plugin.Entry, error) {
asked = append(asked, spec)
l := plugin.Load()
l.Plugins = append(l.Plugins, plugin.Entry{Spec: spec})
diff --git a/internal/provider/migrate.go b/internal/provider/migrate.go
index 7634f79bf..a041009df 100644
--- a/internal/provider/migrate.go
+++ b/internal/provider/migrate.go
@@ -347,6 +347,10 @@ func MoveCandidates() []MoveCandidate {
return out
}
+// a retired subscription's id names its plugin to `magpie plugin add`
+// and the Plugins page's field (qoder-cn, commandcode-plan)
+func init() { plugin.SubscriptionPlugin = MovePackage }
+
// MovePackage is the plugin the built-in id moves to.
func MovePackage(id string) string {
if m := movers[id]; m != nil {
@@ -539,6 +543,9 @@ var (
// so a test can read what it is handed
addPlugin = plugin.Add
upgradePlugin = plugin.Upgrade
+ // addPluginExact is a backup's or a sync's install: the spec as the
+ // other computer has it, never taken for a name
+ addPluginExact = plugin.AddExact
// importAuth keeps a built-in's sign-in as one of the plugin's
importAuth = plugin.Import
)
diff --git a/internal/provider/plugin_left.go b/internal/provider/plugin_left.go
index db760050e..18f5585d6 100644
--- a/internal/provider/plugin_left.go
+++ b/internal/provider/plugin_left.go
@@ -131,7 +131,13 @@ func takeBackLeft(spec string) error {
// AddPlugin installs the plugin spec, as plugin.Add does, and puts back
// what was set aside of it when it was last removed.
func AddPlugin(ctx context.Context, spec string) (plugin.Entry, error) {
- e, err := addPlugin(ctx, spec)
+ return addPluginWith(ctx, spec, addPlugin)
+}
+
+// addPluginWith is AddPlugin, installing with add: plugin.Add for a name
+// the user typed, plugin.AddExact for a spec carried from elsewhere.
+func addPluginWith(ctx context.Context, spec string, add func(context.Context, string) (plugin.Entry, error)) (plugin.Entry, error) {
+ e, err := add(ctx, spec)
if err != nil {
return e, err
}