plugins: a runtime for built-in plugins, and Plugins › Built-in to switch them (P0)

Lxxyx on X (https://x.com/Lxxyx_/status/2109506752656150974): magpie has
too much in it. This is P0 of making magpie's parts plugins, as DeepSeek
Harness does: a runtime, plugins.yml, and the first five built-in plugins
the user can switch off.

- internal/pluginrt: a registry (Register from init), a manifest (API
  caret range, Requires/Provides, Essential, InUse, Apply, Parts,
  Defaults) and Reconcile: the plugins no longer wanted, with whatever
  needs a service they provided, are disposed newest first; the wanted
  ones are applied once their services are there. A plugin that fails or
  panics is failed and the rest run. TestPluginsImportOnlyCore keeps the
  boundary: nothing outside plugins/ imports one, none imports another.
- plugins.yml (appdir.Config()): default → preset (essentials | all) →
  the user's rows → in use. A new install is written Essentials, a magpie
  that ran here before (settings.RanBefore) All, so existing users keep
  everything. Writes are locked, whole and keep a .bak; a file that
  doesn't parse is an error, never empty, and is never written over.
- plugins/groups, library, otel, sessions, warmups. In P0 a plugin off
  is the window's alone: its page, sections and rows (data-feature) leave
  the window; the gateway, TUI and CLI serve the same, nothing is
  deleted. One in use stays on.
- The window: Plugins › Built-in, the first tab, a switch per plugin;
  GET/POST /api/plugins/builtin; boot.js says which are off before the
  first paint. CLI: magpie plugin builtin [on|off <id>], plugin preset,
  plugin dump [--json].
- docs/subsystems/plugin-runtime.md, gui-shell.md.

Run: go test ./internal/pluginrt/ ./internal/settings/ ./internal/gui/;
gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows
go vet ./.... GUI: builtins.test.cjs in Chromium and WebKit, 5 languages,
1100/800/420; list-sort, mobile-web, routing-keys-fold, routing-sessions
pass. By hand under a sandbox HOME: a new install gets essentials, an
existing one all, a broken plugins.yml is refused and kept, dump works.
Full suite results after the rebase are in the push notes.
This commit is contained in:
yetone
2026-10-13 16:19:13 +08:00
parent f2b0780fa2
commit 3ccbe6bc15
32 changed files with 2137 additions and 18 deletions
+18 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/yetone/magpie/internal/middleware"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/pluginrt"
"github.com/yetone/magpie/internal/provider"
)
@@ -24,7 +25,10 @@ const pluginUsage = `usage: magpie plugin [list] [--json]
magpie plugin login <provider> [<method>] sign in to a provider a plugin adds
magpie plugin logout <provider> forget the sign-in
magpie plugin move|migrate <subscription> run a built-in subscription's accounts on its community plugin
magpie plugin move-back|unmigrate <subscription> go back to the built-in, with its accounts`
magpie plugin move-back|unmigrate <subscription> go back to the built-in, with its accounts
magpie plugin builtin [on|off <id>] list magpie's built-in plugins (Sessions, Library, routing groups…), or turn one on or off
magpie plugin preset essentials|all start the built-in plugins from the Essentials preset, or from all of them
magpie plugin dump [--json] what plugins.yml comes to: each built-in plugin, its config, and the layer each value is from`
// pluginCmd: `magpie plugin …` — OpenCode's provider plugins and pi's
// packages, which sign in to a subscription and carry its requests
@@ -157,6 +161,19 @@ func pluginCmd(args []string) error {
}
fmt.Println(green.Render("✓"), rest[0], "is built-in again")
return nil
case "builtin", "builtins", "built-in":
return builtinCmd(rest)
case "preset":
if len(rest) != 1 {
return errors.New(pluginUsage)
}
if err := pluginrt.SetPreset(rest[0]); err != nil {
return err
}
fmt.Println(green.Render("✓"), "built-in plugins start from", rest[0])
return builtinCmd(nil)
case "dump":
return dumpPlugins(len(rest) > 0 && rest[0] == "--json")
case "help", "-h", "--help":
fmt.Println(pluginUsage)
return nil