Просмотр исходного кода

core: move plugin intialisation to config layer override

Brendan Allan 3 дней назад
Родитель
Сommit
3d90405bfd

+ 18 - 1
packages/opencode/src/effect/app-runtime.ts

@@ -48,6 +48,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,
@@ -55,7 +72,7 @@ export const AppLayer = Layer.mergeAll(
   Bus.defaultLayer,
   Auth.defaultLayer,
   Account.defaultLayer,
-  Config.defaultLayer,
+  PluginPriorityConfigLayer,
   Git.defaultLayer,
   Ripgrep.defaultLayer,
   FileTime.defaultLayer,

+ 0 - 6
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,