Skip to content

Commit 14eacb4

Browse files
committed
core: move plugin intialisation to config layer override
1 parent c57c531 commit 14eacb4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/opencode/src/effect/app-runtime.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,31 @@ import { Installation } from "@/installation"
4747
import { ShareNext } from "@/share"
4848
import { SessionShare } from "@/share"
4949
import { Npm } from "@opencode-ai/shared/npm"
50+
import * as Effect from "effect/Effect"
51+
52+
// Adjusts the default Config layer to ensure that plugins are always initialised before
53+
// any other layers read the current config
54+
const PluginPriorityConfigLayer = Layer.unwrap(
55+
Effect.gen(function* () {
56+
const configSvc = yield* Config.Service
57+
const pluginSvc = yield* Plugin.Service
58+
59+
return Layer.succeed(Config.Service, {
60+
...configSvc,
61+
get: () => Effect.andThen(pluginSvc.init(), configSvc.get),
62+
getGlobal: () => Effect.andThen(pluginSvc.init(), configSvc.getGlobal),
63+
getConsoleState: () => Effect.andThen(pluginSvc.init(), configSvc.getConsoleState),
64+
})
65+
}),
66+
).pipe(Layer.provideMerge(Layer.merge(Plugin.defaultLayer, Config.defaultLayer)))
5067

5168
export const AppLayer = Layer.mergeAll(
5269
Npm.defaultLayer,
5370
AppFileSystem.defaultLayer,
5471
Bus.defaultLayer,
5572
Auth.defaultLayer,
5673
Account.defaultLayer,
57-
Config.defaultLayer,
74+
PluginPriorityConfigLayer,
5875
Git.defaultLayer,
5976
Ripgrep.defaultLayer,
6077
File.defaultLayer,

packages/opencode/src/project/bootstrap.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Plugin } from "../plugin"
21
import { Format } from "../format"
32
import { LSP } from "../lsp"
43
import { File } from "../file"
@@ -12,14 +11,9 @@ import { Log } from "@/util"
1211
import { FileWatcher } from "@/file/watcher"
1312
import { ShareNext } from "@/share"
1413
import * as Effect from "effect/Effect"
15-
import { Config } from "@/config"
1614

1715
export const InstanceBootstrap = Effect.gen(function* () {
1816
Log.Default.info("bootstrapping", { directory: Instance.directory })
19-
// everything depends on config so eager load it for nice traces
20-
yield* Config.Service.use((svc) => svc.get())
21-
// Plugin can mutate config so it has to be initialized before anything else.
22-
yield* Plugin.Service.use((svc) => svc.init())
2317
yield* Effect.all(
2418
[
2519
LSP.Service,

0 commit comments

Comments
 (0)