From fec1719832479aeb06ab9e6706d0db4ed0606853 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sun, 17 May 2026 01:53:15 +0800 Subject: [PATCH] fix: wire pluginAutoInstall config to plugin install behavior Add OPENCODE_DISABLE_PLUGIN_INSTALL flag and check it in Npm.add() and Npm.install() to prevent automatic plugin installation when the user sets pluginAutoInstall: false in their config. Previously, the pluginAutoInstall config field existed in the schema but was never connected to any behavior. Only the OPENCODE_DISABLE_PLUGIN_INSTALL env var worked. Now setting pluginAutoInstall: false in config will set the env var at load time, which the npm module checks before installing plugins. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- packages/core/src/flag/flag.ts | 3 +++ packages/core/src/npm.ts | 6 ++++++ packages/opencode/src/config/config.ts | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/packages/core/src/flag/flag.ts b/packages/core/src/flag/flag.ts index 3ed67bb785d4..58ae97232b7c 100644 --- a/packages/core/src/flag/flag.ts +++ b/packages/core/src/flag/flag.ts @@ -65,4 +65,7 @@ export const Flag = { get OPENCODE_CLIENT() { return process.env["OPENCODE_CLIENT"] ?? "cli" }, + get OPENCODE_DISABLE_PLUGIN_INSTALL() { + return truthy("OPENCODE_DISABLE_PLUGIN_INSTALL") + }, } diff --git a/packages/core/src/npm.ts b/packages/core/src/npm.ts index 8dac8faf0129..07cdfaef55fc 100644 --- a/packages/core/src/npm.ts +++ b/packages/core/src/npm.ts @@ -9,6 +9,7 @@ import { Global } from "./global" import { EffectFlock } from "./util/effect-flock" import { makeRuntime } from "./effect/runtime" import { NpmConfig } from "./npm-config" +import { Flag } from "./flag/flag" export class InstallFailedError extends Schema.TaggedErrorClass()("NpmInstallFailedError", { add: Schema.Array(Schema.String).pipe(Schema.optional), @@ -111,6 +112,9 @@ export const layer = Layer.effect( ) const add = Effect.fn("Npm.add")(function* (pkg: string) { + if (Flag.OPENCODE_DISABLE_PLUGIN_INSTALL) { + return resolveEntryPoint(pkg, "") + } const dir = directory(pkg) const name = (() => { try { @@ -135,6 +139,8 @@ export const layer = Layer.effect( }, Effect.scoped) const install: Interface["install"] = Effect.fn("Npm.install")(function* (dir, input) { + if (Flag.OPENCODE_DISABLE_PLUGIN_INSTALL) return + const canWrite = yield* afs.access(dir, { writable: true }).pipe( Effect.as(true), Effect.orElseSucceed(() => false), diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index b13d3a8c8131..a6b6fb57cd0e 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -156,6 +156,10 @@ export const Info = Schema.Struct({ description: "Automatically update to the latest version. Set to true to auto-update, false to disable, or 'notify' to show update notifications", }), + pluginAutoInstall: Schema.optional(Schema.Boolean).annotate({ + description: + "Enable or disable automatic plugin installation. When false, plugins will not be auto-installed (equivalent to OPENCODE_DISABLE_PLUGIN_INSTALL=true)", + }), disabled_providers: Schema.optional(Schema.mutable(Schema.Array(Schema.String))).annotate({ description: "Disable providers that are loaded automatically", }), @@ -732,6 +736,10 @@ export const layer = Layer.effect( result.compaction = { ...result.compaction, prune: false } } + if (result.pluginAutoInstall === false) { + process.env["OPENCODE_DISABLE_PLUGIN_INSTALL"] = "true" + } + return { config: result, directories,