From 36e25abab9e9e0bf139b1f6aad205c4edffb00a3 Mon Sep 17 00:00:00 2001 From: Shoubhit Dash Date: Tue, 6 Oct 2026 19:44:34 +0530 Subject: [PATCH] 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. --- packages/core/src/plugin/supervisor.ts | 15 ++++- packages/core/test/plugin/supervisor.test.ts | 67 ++++++++++++++++++++ services/www/src/docs/content/plugins.mdx | 9 +++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/packages/core/src/plugin/supervisor.ts b/packages/core/src/plugin/supervisor.ts index bb5a8e7e5a9..be65631fc83 100644 --- a/packages/core/src/plugin/supervisor.ts +++ b/packages/core/src/plugin/supervisor.ts @@ -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() + const options = new Map>() const pending = new Set() 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. diff --git a/packages/core/test/plugin/supervisor.test.ts b/packages/core/test/plugin/supervisor.test.ts index 111a02b2074..c985b2d0a3f 100644 --- a/packages/core/test/plugin/supervisor.test.ts +++ b/packages/core/test/plugin/supervisor.test.ts @@ -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>() + 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>() + 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 = [] + }), + ), + ), + ) }) diff --git a/services/www/src/docs/content/plugins.mdx b/services/www/src/docs/content/plugins.mdx index 4901d3d17c4..b4322ef8ffe 100644 --- a/services/www/src/docs/content/plugins.mdx +++ b/services/www/src/docs/content/plugins.mdx @@ -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.