plugin: on Windows a folder plugin's path is read as an npm package, so a backup or a sync carries it
What's wrong
A plugin added from a file or a folder is this computer's alone: a backup or a sync leaves it out, and the machine restoring one doesn't try to install it (Carried in internal/provider/backup.go, AddPlugins). On Windows that doesn't hold for a folder path written the way macOS and Linux write one.
plugin.IsPath (internal/plugin/store.go) reads a spec as a path when it starts with file:// or ., when filepath.IsAbs says so on the host, or when it matches ^[A-Za-z]:[\\/]. That regexp only ever fires off Windows (C:\p is absolute there already), so a path of another system was meant to count too — but the mirror case is missing: on Windows filepath.IsAbs("/Users/me/plugin") is false, so a Unix-style folder path is read as an npm package.
Impact
Who: a user whose plugin is installed from a folder and who moves plugins.json between machines with a backup or a WebDAV sync, one side being Windows.
What happens:
- the machine's own folder path is carried into the backup and into the sync, though the file is meant to hold only what travels, and
- the machine restoring it asks bun to install that path as a package and reports a failure:
"/Users/me/plugin" isn't an npm package name.
Repro (Windows, main c524bc01)
The three tests that assert a folder plugin stays put are red there, and each red is the report above:
> go test -tags nogui -count=1 -run TestPluginsCarried ./internal/provider/
--- FAIL: TestPluginsCarried (0.02s)
backup_test.go:115: carried: [{Spec:@magpie-community/[email protected] ...} {Spec:/Users/me/my-plugin ...} ...], want the npm plugins only
> go test -tags nogui -count=1 -run TestRestorePluginsAndSignIn ./internal/backup/
--- FAIL: TestRestorePluginsAndSignIn (0.72s)
backup_test.go:482: asked to install [@magpie-community/opencode-cursor-auth /Users/me/mine], want the npm plugin only
> go test -tags nogui -count=1 -run TestSyncPluginsAndSignIn ./internal/davsync/
--- FAIL: TestSyncPluginsAndSignIn (1.83s)
davsync_test.go:679: b asked to install [@magpie-community/opencode-cursor-auth /Users/me/mine], want the npm plugin only
They pass on Linux and macOS, where the bug can't show, and the Windows run only compiles the suite (.github/workflows/test.yml), so a Windows-only red shows on no run (LESSONS.md, "Windows CI only compiles the tests, so a Windows-only red shows nowhere").
At the function itself:
> go test -tags nogui -count=1 -run TestIsPath ./internal/plugin/
--- FAIL: TestIsPath (0.00s)
store_test.go:59: IsPath("/Users/me/plugin") = false, want true
store_test.go:59: IsPath("\\Users\\me\\plugin") = false, want true
Expected
A spec rooted the way any system roots one is a path whichever system magpie runs on — a leading /, a leading \ (a UNC path among them), a drive letter, file:// or . — so a folder plugin is left out of a backup and a sync on Windows too, and IsPath is not the host's own answer to a spec that came from another machine.
A PR follows with a fix and a test that fails on every system without it.
The fix is ready to fetch, but I could not open a pull request for it.
Why no PR. gh pr create --repo yetone/magpie --base main --head JasonBuildAI:fix/plugin-ispath-crossos-jx4d answers GraphQL: JasonBuildAI does not have the correct permissions to execute CreatePullRequest, and the REST endpoint answers 404 for the same head; a main -> main probe from the same fork is refused the same way, so it is not this branch. The same account opened pull requests in other repositories today, and this fork is listed under repos/yetone/magpie/forks, so it looks like a per-repository restriction that needs someone on your side.
Branch, ready to fetch: fix/plugin-ispath-crossos-jx4d in github.com/JasonBuildAI/magpie, commit d2865faa, cut from main 8e8316ed.
git fetch https://github.com/JasonBuildAI/magpie fix/plugin-ispath-crossos-jx4d
or apply the diff at the end.
What it changes (3 files, 33 lines)
plugin.IsPath: a spec rooted the way any system roots one counts as a path - a leading/or\(a UNC path among them) - besidefile://,., the drive letters and the host's own absolute paths.internal/plugin/store_test.go: a newTestIsPath.docs/subsystems/provider-plugins.md: one line beside the store's other spec rules.
Evidence, Windows box (Bun 1.4.2 on PATH), at main 8e8316ed first and then at d2865faa:
> go test -tags nogui -count=1 -run TestPluginsCarried ./internal/provider/
--- FAIL: TestPluginsCarried (0.29s)
backup_test.go:115: carried: [{Spec:@magpie-community/[email protected] Off:false Options:map[]} {Spec:/Users/me/my-plugin Off:false Options:map[]} {Spec:@magpie-community/middleware-model-map Off:true Options:map[map:map[a:b] nested:map[keep:1]]}], want the npm plugins only
> go test -tags nogui -count=1 -run TestRestorePluginsAndSignIn ./internal/backup/
--- FAIL: TestRestorePluginsAndSignIn (2.03s)
backup_test.go:482: asked to install [@magpie-community/opencode-cursor-auth /Users/me/mine], want the npm plugin only
> go test -tags nogui -count=1 -run TestSyncPluginsAndSignIn ./internal/davsync/
--- FAIL: TestSyncPluginsAndSignIn (7.51s)
davsync_test.go:679: b asked to install [@magpie-community/opencode-cursor-auth /Users/me/mine], want the npm plugin only
> (a two-line probe on the new rows, TestIsPath not existing at the base)
--- FAIL: TestZZProbeIsPath (0.00s)
zz_probe_test.go:8: IsPath("/Users/me/plugin") = false, want true
zz_probe_test.go:8: IsPath("\\Users\\me\\plugin") = false, want true
> go test -tags nogui -count=1 -run TestIsPath ./internal/plugin/
ok github.com/yetone/magpie/internal/plugin 0.432s
> go test -tags nogui -count=1 -run TestPluginsCarried ./internal/provider/
ok github.com/yetone/magpie/internal/provider 2.046s
> go test -tags nogui -count=1 -run TestRestorePluginsAndSignIn ./internal/backup/
ok github.com/yetone/magpie/internal/backup 3.950s
> go test -tags nogui -count=1 -run TestSyncPluginsAndSignIn ./internal/davsync/
ok github.com/yetone/magpie/internal/davsync 23.031s
Taking the two new conditions back out of IsPath by hand reddens TestIsPath (both rows), TestPluginsCarried and TestSyncPluginsAndSignIn again at this head, so the conditions carry the fix. gofmt -l . (nothing), go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build ./... and GOOS=darwin go build -tags nogui ./... are all clean.
One correction to the report above, from an independent review of the change: a sync on its own does not put such a path on the other machine. A Mac's or Linux's Carried already drops its own folder plugin, and so does a Windows magpie for its C:\... one, so nothing magpie itself writes has the wrong shape. The path is in a Windows plugins.json when the user moves that file there (a hand copy, or a config folder synced by another tool), and from then on everything above follows: the entry goes into a backup and a sync that are meant to leave folder plugins out, the machine restoring one asks bun for it and fails, and Updates/npmPlugin ask npm about it. That is narrower than my first write-up - worth fixing anyway, since it is the row your own TestPluginsCarried/TestRestorePluginsAndSignIn/TestSyncPluginsAndSignIn assert and Windows runs none of them, and it is the same wrong answer on a Mac for a Windows UNC path (\\server\share).
Diff:
diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md
index 0fe68b16..72d80aa8 100644
--- a/docs/subsystems/provider-plugins.md
+++ b/docs/subsystems/provider-plugins.md
@@ -109,6 +109,7 @@ How the store handles picks and names:
- Switching a plugin off hands the id to the other plugin until it is switched on again.
- Re-adding a plugin under a new version or spec keeps its picks.
- Remove, off, options and prefer find a plugin by its exact spec first, then by package name (`indexOf` in `store.go`). This way, acting on one plugin never reaches another plugin that has the same package name.
+- A plugin added from a file or a folder is this computer's alone: `Carried` leaves it out of a backup, and `AddPlugins` doesn't install it on the machine restoring one. A spec rooted the way any system roots one — a leading `/` or `\` (a UNC path among them), a drive letter, `file://` — is a path here (`IsPath` in `store.go`). Before, Windows read a Mac's or Linux's `/Users/me/plugin` as an npm package (`filepath.IsAbs` and a drive letter only), so a sync carried the folder's path and the machine restoring it failed to install it (#2229). `TestIsPath` (internal/plugin), `TestPluginsCarried` (internal/provider), `TestRestorePluginsAndSignIn` (internal/backup) and `TestSyncPluginsAndSignIn` (internal/davsync) cover it.
## How ownership changes
diff --git a/internal/plugin/store.go b/internal/plugin/store.go
index e81696fa..afda2841 100644
--- a/internal/plugin/store.go
+++ b/internal/plugin/store.go
@@ -280,10 +280,16 @@ func checkList() {
changed()
}
-// IsPath is whether spec names a file or folder rather than a package,
-// as OpenCode tells them apart.
+// IsPath is whether spec names a file or folder rather than a package, as
+// OpenCode tells them apart, a path of another system counting too:
+// plugins.json is carried between machines by a backup or a sync, so a
+// folder added on a Mac (/Users/me/p) comes to a Windows magpie and is
+// one there, and one added on Windows (C:\p, \\server\share) comes
+// to a Mac, where a drive letter alone is no absolute path.
func IsPath(spec string) bool {
- return strings.HasPrefix(spec, "file://") || strings.HasPrefix(spec, ".") || filepath.IsAbs(spec) || regexp.MustCompile(`^[A-Za-z]:[\\/]`).MatchString(spec)
+ return strings.HasPrefix(spec, "file://") || strings.HasPrefix(spec, ".") ||
+ strings.HasPrefix(spec, "/") || strings.HasPrefix(spec, `\`) ||
+ filepath.IsAbs(spec) || regexp.MustCompile(`^[A-Za-z]:[\\/]`).MatchString(spec)
}
var pkgName = regexp.MustCompile(`^(@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$`)
diff --git a/internal/plugin/store_test.go b/internal/plugin/store_test.go
index ccb09ff7..ef74b7a7 100644
--- a/internal/plugin/store_test.go
+++ b/internal/plugin/store_test.go
@@ -38,6 +38,29 @@ func writeList(t testing.TB, body string) {
}
}
+// A path is a path on every system, not only on the one that wrote it:
+// plugins.json is carried between machines by a backup or a sync, so a
+// folder added on a Mac comes to a Windows magpie, and it is a folder
+// there, not an npm package to install.
+func TestIsPath(t *testing.T) {
+ for spec, want := range map[string]bool{
+ "/Users/me/plugin": true,
+ `\Users\me\plugin`: true,
+ `\\server\share`: true,
+ "C:/Users/me/plugin": true,
+ `C:\Users\me\plugin`: true,
+ "./plugin.js": true,
+ "file:///abs/plugin": true,
+ "@scope/[email protected]": false,
+ "owner/repo": false,
+ "github:owner/repo": false,
+ } {
+ if got := IsPath(spec); got != want {
+ t.Errorf("IsPath(%q) = %v, want %v", spec, got, want)
+ }
+ }
+}
+
func TestLoadMissingIsEmptyNotGrown(t *testing.T) {
storeSandbox(t)
l := Load()
AI disclosure: this was drafted with AI assistance at my request, under my direction and review.
Thanks @JasonBuildAI, this is fixed in 8bf98110b.
Cause. plugin.IsPath asked filepath.IsAbs on the machine reading the spec. On Windows, /Users/me/plugin is not absolute, so a folder plugin added on a Mac was read as an npm package. Backup and WebDAV sync then carried it as one, and the restoring Windows machine asked bun to install /Users/me/plugin.
Fix. A spec that starts with / or \ (UNC paths included) now counts as a path on every OS, the same way a drive-rooted path already did off Windows.
What was run:
- The new
TestIsPathWhicheverSystemWroteIt. It fails on the old code on the Windows box and on macOS, and passes with the fix. - The three reds you named, on the Windows box:
TestPluginsCarried,TestRestorePluginsAndSignInandTestSyncPluginsAndSignIn. Each failed before the fix and passes after it. go test -tags nogui ./...on macOS: every package ok.- gofmt, plus
go veton darwin, linux and windows: clean.
This ships in the next release after v0.1.1231. I'll leave this open until you confirm it works for you.
Confirmed on main (82f48f09), Windows box, Go 1.26.8 - the three reds in the report and the unit test all pass now:
> go test -tags nogui -count=1 -run TestIsPathWhicheverSystemWroteIt ./internal/plugin/
ok github.com/yetone/magpie/internal/plugin 0.130s
> go test -tags nogui -count=1 -run TestPluginsCarried ./internal/provider/
ok github.com/yetone/magpie/internal/provider 0.118s
> go test -tags nogui -count=1 -run TestRestorePluginsAndSignIn ./internal/backup/
ok github.com/yetone/magpie/internal/backup 0.678s
> go test -tags nogui -count=1 -run TestSyncPluginsAndSignIn ./internal/davsync/
ok github.com/yetone/magpie/internal/davsync 1.416s
8bf98110b reads a spec rooted with / or \ as a path on this host rather than as an npm package, which is what the report asked for, and the folder plugin is left out of the carried list again.
My branch fix/plugin-ispath-crossos-jx4d (d2865faa) is the same change and your commit covers it, so it stays unmerged. 8bf98110b is on main but not in v0.1.1242, so this ships in the next release. Closing.
AI disclosure: this verification was produced with AI assistance at my request, under my direction and review.