# Plugin runtime magpie's built-in plugins are the parts of magpie not everyone needs, each one a package under `plugins/` that the user can switch off. The runtime in `internal/pluginrt` keeps their registry, applies the ones that are on in the order their services make, and disposes of what each registered when it is turned off. `plugins.yml` says which are on. This page describes P0 (the runtime, the file and the window's switch) and P1 (the window's kernel: a plugin's page, its error boundary, the kit it draws with and its settings form, with the Gateway page as the first plugin to draw its own page), and P2 so far (a page moved out of the core whole: its code, styles and words, starting with Sessions). OpenCode plugins (npm packages in the plugin host) are a different thing; see [provider and plugin ownership](provider-plugins.md) and [gateway middleware](gateway-middleware.md). ## Responsibilities and boundaries | Part | What it does | Source | | --- | --- | --- | | Registry | A plugin calls `pluginrt.Register(Manifest)` from `init`. `Registered` lists them by id; two with one id panic. `plugins/all` imports every plugin, and only `main.go` imports `plugins/all`, so core code and its tests run without any. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go), [`plugins/all/all.go`](../../plugins/all/all.go) | | Manifest | `ID`, `API` (a caret range of the host API, `"^1"`; `pluginrt.API` is `"1.0"`), `Requires` and `Provides` (services), `Essential`, `Name`/`Sub` (English; the window translates them), `One`/`Many` (what is in use, of 1 or `{n}`), `InUse`, `Apply`, `Parts` (`{Slot, Key}`: the window's parts it is), `Defaults` (its config), `Settings` (a struct of its settings, made into `Defaults` and a schema at `Register`) and `Client` (its files in the window, under `internal/gui/assets/plugins//`: scripts, its `i18n.js` and a `.css`). | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | Lifecycle | `Runtime.Reconcile(on, config)`. Off first: every plugin no longer wanted, and every one requiring a service one of those provided, is disposed newest first. Then on: each wanted plugin whose requirements are provided (by `Core`, `settings`, `providers`, `gateway`, `window`, or an active plugin) is applied, again and again until no more can be. States: `off`, `pending` (waiting for a service, logged), `active`, `failed` (Apply returned an error or panicked, or the API range doesn't match; what it registered before is undone), `disposed`. A failed plugin never stops the others. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | Ctx | What `Apply` gets: `OnDispose(f)`, `Contribute(slot, key)`, `Provide(name, v)` (withdrawn when it goes), `Service(name)`, and its composed `Config`. Disposers run in reverse, each one's panic logged and the rest still run. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | plugins.yml | `appdir.Config()/plugins.yml`: `preset` (`essentials` or `all`) and `plugins`, rows of `{id, enabled, config}` holding only what the user set. | [`config.go`](../../internal/pluginrt/config.go) | | Settings schema | `SchemaOf(Settings)` makes a JSON Schema object of the struct, in its fields' order (`x-order`): each exported field with a json name is a setting, of `bool`, an int, `float64` or `string`, with tags `title` (English; the window translates it), `description`, `enum` (comma separated) and `min`/`max`. Its values are the defaults. A field a form can't draw, or a tag that doesn't parse, panics at `Register`. `Schema.Validate` takes a value only as the schema allows it (a JSON float64 or a YAML int for an integer); `SetConfig(id, config)` writes the user's row through it, and `Compose` leaves out a value edited into plugins.yml by hand that it doesn't allow, so the default stands. | [`schema.go`](../../internal/pluginrt/schema.go), [`config.go`](../../internal/pluginrt/config.go) | | Built-in plugins | `groups`, `library`, `otel`, `sessions`, `warmups` (P0), and `gateway` (P1), the Gateway page, which is Essential and in use while a gateway key is there (`access.List`). Its one setting, `callsPage` (10, 20, 50 or 100; 20), is how many recent calls the page shows at a time. The other five aren't Essential. Each one's `InUse` counts what the user made with it: routing groups not Auto and not hidden, library items given to agents, a collector sent to, gateway conversations recorded, warm-ups and check-ins on. | [`plugins/`](../../plugins) | The boundary is checked by `TestPluginsImportOnlyCore`: no package outside `plugins/` imports one (but `main.go`, through `plugins/all`), a plugin never imports another, and `plugins/all` imports every plugin folder. Plugins reach each other only through services. ## The window's kernel (P1) `internal/gui/assets/kernel.js` loads after `i18n.js` and before the plugins' scripts and `app.js`, all classic scripts sharing one scope. It is `window.magpie`: - `magpie.plugin(id, setup)`: a plugin's script registers, and `setup` gets a context: `config` (from boot.js's `pluginConfig`, then Plugins › Built-in), `onConfig(fn)`, `onDispose(fn)`, `slots.add(slot, part)` and `ui`. - **Slots.** The one slot is `page`: a part `{key, html, loads, mount, …hooks}` becomes `
` where index.html's `