|
1 | | -import { Layer, ManagedRuntime } from "effect" |
| 1 | +import { Effect, Layer, ManagedRuntime } from "effect" |
2 | 2 | import { attach } from "./run-service" |
3 | 3 | import * as Observability from "@opencode-ai/core/effect/observability" |
4 | 4 |
|
@@ -49,13 +49,30 @@ import { SessionShare } from "@/share/session" |
49 | 49 | import { Npm } from "@opencode-ai/core/npm" |
50 | 50 | import { memoMap } from "@opencode-ai/core/effect/memo-map" |
51 | 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 ConfigWithPluginPriority = Layer.effect( |
| 55 | + Config.Service, |
| 56 | + Effect.gen(function* () { |
| 57 | + const config = yield* Config.Service |
| 58 | + const plugin = yield* Plugin.Service |
| 59 | + |
| 60 | + return { |
| 61 | + ...config, |
| 62 | + get: () => Effect.andThen(plugin.init(), config.get), |
| 63 | + getGlobal: () => Effect.andThen(plugin.init(), config.getGlobal), |
| 64 | + getConsoleState: () => Effect.andThen(plugin.init(), config.getConsoleState), |
| 65 | + } |
| 66 | + }), |
| 67 | +).pipe(Layer.provide(Layer.merge(Plugin.defaultLayer, Config.defaultLayer))) |
| 68 | + |
52 | 69 | export const AppLayer = Layer.mergeAll( |
53 | 70 | Npm.defaultLayer, |
54 | 71 | AppFileSystem.defaultLayer, |
55 | 72 | Bus.defaultLayer, |
56 | 73 | Auth.defaultLayer, |
57 | 74 | Account.defaultLayer, |
58 | | - Config.defaultLayer, |
| 75 | + ConfigWithPluginPriority, |
59 | 76 | Git.defaultLayer, |
60 | 77 | Ripgrep.defaultLayer, |
61 | 78 | File.defaultLayer, |
|
0 commit comments