From 14eacb40192be0b14e7f8d6273c3a735a5bdd255 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Wed, 15 Apr 2026 21:07:58 +0800 Subject: [PATCH] core: move plugin intialisation to config layer override --- packages/opencode/src/effect/app-runtime.ts | 19 ++++++++++++++++++- packages/opencode/src/project/bootstrap.ts | 6 ------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/opencode/src/effect/app-runtime.ts b/packages/opencode/src/effect/app-runtime.ts index eae52d6366..17be3ac634 100644 --- a/packages/opencode/src/effect/app-runtime.ts +++ b/packages/opencode/src/effect/app-runtime.ts @@ -47,6 +47,23 @@ import { Installation } from "@/installation" import { ShareNext } from "@/share" import { SessionShare } from "@/share" import { Npm } from "@opencode-ai/shared/npm" +import * as Effect from "effect/Effect" + +// Adjusts the default Config layer to ensure that plugins are always initialised before +// any other layers read the current config +const PluginPriorityConfigLayer = Layer.unwrap( + Effect.gen(function* () { + const configSvc = yield* Config.Service + const pluginSvc = yield* Plugin.Service + + return Layer.succeed(Config.Service, { + ...configSvc, + get: () => Effect.andThen(pluginSvc.init(), configSvc.get), + getGlobal: () => Effect.andThen(pluginSvc.init(), configSvc.getGlobal), + getConsoleState: () => Effect.andThen(pluginSvc.init(), configSvc.getConsoleState), + }) + }), +).pipe(Layer.provideMerge(Layer.merge(Plugin.defaultLayer, Config.defaultLayer))) export const AppLayer = Layer.mergeAll( Npm.defaultLayer, @@ -54,7 +71,7 @@ export const AppLayer = Layer.mergeAll( Bus.defaultLayer, Auth.defaultLayer, Account.defaultLayer, - Config.defaultLayer, + PluginPriorityConfigLayer, Git.defaultLayer, Ripgrep.defaultLayer, File.defaultLayer, diff --git a/packages/opencode/src/project/bootstrap.ts b/packages/opencode/src/project/bootstrap.ts index a7c071a9f8..012b10ef86 100644 --- a/packages/opencode/src/project/bootstrap.ts +++ b/packages/opencode/src/project/bootstrap.ts @@ -1,4 +1,3 @@ -import { Plugin } from "../plugin" import { Format } from "../format" import { LSP } from "../lsp" import { File } from "../file" @@ -12,14 +11,9 @@ import { Log } from "@/util" import { FileWatcher } from "@/file/watcher" import { ShareNext } from "@/share" import * as Effect from "effect/Effect" -import { Config } from "@/config" export const InstanceBootstrap = Effect.gen(function* () { Log.Default.info("bootstrapping", { directory: Instance.directory }) - // everything depends on config so eager load it for nice traces - yield* Config.Service.use((svc) => svc.get()) - // Plugin can mutate config so it has to be initialized before anything else. - yield* Plugin.Service.use((svc) => svc.init()) yield* Effect.all( [ LSP.Service,