feat(core): pass plugin options to built-in plugins

Package plugins already receive the options from their plugins entry. Built-in, SDK, and instance plugins were only enabled, and their options were dropped. An exact add entry now passes its options to that plugin and folds them into its revision, so an edit restarts the plugin with the new values. Wildcards never set options, and a later plain entry for the same ID resets them.
This commit is contained in:
Shoubhit Dash 2026-10-06 19:44:34 +05:30
parent 50867e1b2d
commit 36e25abab9
3 changed files with 89 additions and 2 deletions

View file

@ -28,6 +28,7 @@ const resolve = Effect.fn("PluginSupervisor.resolve")(function* (
const definitions = [...pre, ...post]
const enabled = new Set(definitions.map((plugin) => plugin.id))
const packages = new Map<string, Plugin.Generation>()
const options = new Map<string, Record<string, unknown>>()
const pending = new Set<string>()
const failures = new Map<
string,
@ -52,6 +53,7 @@ const resolve = Effect.fn("PluginSupervisor.resolve")(function* (
operation.target.startsWith("opencode.")
if (selectsPlugins) {
matched.forEach((plugin) => enabled.add(plugin.id))
if (definitions.some((plugin) => plugin.id === operation.target)) options.set(operation.target, operation.options)
continue
}
@ -88,10 +90,19 @@ const resolve = Effect.fn("PluginSupervisor.resolve")(function* (
enabled.add(plugin.id)
}
const withOptions = (plugin: Plugin.Generation): Plugin.Generation => {
const selected = options.get(plugin.id)
if (!selected || Object.keys(selected).length === 0) return plugin
return {
...plugin,
revision: JSON.stringify([plugin.revision, selected]),
effect: (host) => plugin.effect({ ...host, options: selected }),
}
}
const ordered = [
...pre.filter((plugin) => enabled.has(plugin.id)),
...pre.filter((plugin) => enabled.has(plugin.id)).map(withOptions),
...[...packages.values()].filter((plugin) => enabled.has(plugin.id)),
...post.filter((plugin) => enabled.has(plugin.id)),
...post.filter((plugin) => enabled.has(plugin.id)).map(withOptions),
]
// Registry activation dies on a duplicate ID, which would drop the whole generation including builtins.
// Keep the first occurrence in boot order and report later ones like any other plugin setup failure.

View file

@ -258,4 +258,71 @@ describe("PluginSupervisor", () => {
expect(source.activations).toBe(2)
}),
)
it.effect("passes exact add options to a non-package plugin and restarts it when they change", () =>
Effect.gen(function* () {
const seen = new Array<Record<string, unknown>>()
const sdk = yield* SdkPlugins.Service
yield* sdk.register(
define({
id: "options-probe",
effect: (ctx) => Effect.sync(() => seen.push(ctx.options)),
}),
)
source.activations = 0
source.operations = [{ type: "add", target: "options-probe", options: { directory: "/plans" } }]
const directory = yield* tmpdirScoped()
const locations = yield* LocationServiceMap.Service
yield* Effect.gen(function* () {
const plugins = yield* Plugin.Service
yield* plugins.awaitActivation
expect(seen).toEqual([{ directory: "/plans" }])
source.operations = [{ type: "add", target: "options-probe", options: { directory: "/srv/plans" } }]
yield* sdk.register(define({ id: "options-reload", effect: () => Effect.void }))
yield* advance(() => source.activations === 2)
yield* plugins.awaitActivation
expect(seen).toEqual([{ directory: "/plans" }, { directory: "/srv/plans" }])
}).pipe(
Effect.scoped,
Effect.provide(locations.get(Location.Ref.make({ directory: AbsolutePath.make(directory.path) }))),
)
}).pipe(
Effect.ensuring(
Effect.sync(() => {
source.operations = []
}),
),
),
)
it.effect("ignores options from a wildcard selector", () =>
Effect.gen(function* () {
const seen = new Array<Record<string, unknown>>()
const sdk = yield* SdkPlugins.Service
yield* sdk.register(
define({
id: "options-probe",
effect: (ctx) => Effect.sync(() => seen.push(ctx.options)),
}),
)
source.operations = [{ type: "add", target: "*", options: { directory: "/plans" } }]
const directory = yield* tmpdirScoped()
const locations = yield* LocationServiceMap.Service
yield* Effect.gen(function* () {
const plugins = yield* Plugin.Service
yield* plugins.awaitActivation
expect(seen).toEqual([{}])
}).pipe(
Effect.scoped,
Effect.provide(locations.get(Location.Ref.make({ directory: AbsolutePath.make(directory.path) }))),
)
}).pipe(
Effect.ensuring(
Effect.sync(() => {
source.operations = []
}),
),
),
)
})

View file

@ -81,6 +81,15 @@ Two built-in plugins ignore removals so that a repository cannot switch off
`opencode.provider.opencode`, the Console connection that delivers organization
policy.
To pass options to a built-in plugin, use the object form with the plugin ID as `package`. A later entry for the same
ID replaces its options. Wildcards enable plugins but never set options.
```jsonc title="opencode.jsonc"
{
"plugins": [{ "package": "opencode.plan", "options": { "directory": ".opencode/plans" } }]
}
```
## Manage
Install, list, check, update, or remove global package plugins with the CLI.