diff --git a/packages/core/src/flag/flag.ts b/packages/core/src/flag/flag.ts index 3ed67bb785d..58ae97232b7 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 8dac8faf012..07cdfaef55f 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 b13d3a8c813..a6b6fb57cd0 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,