Skip to content

Commit fd34e6f

Browse files
Apply PR #22753: core: move plugin intialisation to config layer override
2 parents 78fa979 + 9b85d2c commit fd34e6f

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

packages/opencode/src/cli/cmd/tui/thread.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const TuiThreadCommand = cmd({
191191
const config = await TuiConfig.get()
192192

193193
const network = resolveNetworkOptionsNoConfig(args)
194+
194195
const external =
195196
process.argv.includes("--port") ||
196197
process.argv.includes("--hostname") ||

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,37 @@ import { Worktree } from "@/worktree"
4848
import { Pty } from "@/pty"
4949
import { PtyTicket } from "@/pty/ticket"
5050
import { Installation } from "@/installation"
51+
import * as Effect from "effect/Effect"
5152
import { ShareNext } from "@/share/share-next"
5253
import { SessionShare } from "@/share/session"
5354
import { SyncEvent } from "@/sync"
5455
import { Npm } from "@opencode-ai/core/npm"
5556
import { memoMap } from "@opencode-ai/core/effect/memo-map"
5657

58+
// Adjusts the default Config layer to ensure that plugins are always initialised before
59+
// any other layers read the current config
60+
const ConfigWithPluginPriority = Layer.effect(
61+
Config.Service,
62+
Effect.gen(function* () {
63+
const config = yield* Config.Service
64+
const plugin = yield* Plugin.Service
65+
66+
return {
67+
...config,
68+
get: () => Effect.andThen(plugin.init(), config.get),
69+
getGlobal: () => Effect.andThen(plugin.init(), config.getGlobal),
70+
getConsoleState: () => Effect.andThen(plugin.init(), config.getConsoleState),
71+
}
72+
}),
73+
).pipe(Layer.provide(Layer.merge(Plugin.defaultLayer, Config.defaultLayer)))
74+
5775
export const AppLayer = Layer.mergeAll(
5876
Npm.defaultLayer,
5977
AppFileSystem.defaultLayer,
6078
Bus.defaultLayer,
6179
Auth.defaultLayer,
6280
Account.defaultLayer,
63-
Config.defaultLayer,
81+
ConfigWithPluginPriority,
6482
Git.defaultLayer,
6583
Ripgrep.defaultLayer,
6684
File.defaultLayer,

packages/opencode/src/project/bootstrap.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Plugin } from "../plugin"
21
import { Format } from "../format"
32
import { LSP } from "@/lsp/lsp"
43
import { File } from "../file"
54
import { Snapshot } from "../snapshot"
65
import * as Project from "./project"
76
import * as Vcs from "./vcs"
87
import { Bus } from "../bus"
8+
import { Plugin } from "../plugin"
99
import { InstanceState } from "@/effect/instance-state"
1010
import { FileWatcher } from "@/file/watcher"
1111
import { ShareNext } from "@/share/share-next"
@@ -27,7 +27,6 @@ export const layer = Layer.effect(
2727
const fileWatcher = yield* FileWatcher.Service
2828
const format = yield* Format.Service
2929
const lsp = yield* LSP.Service
30-
const plugin = yield* Plugin.Service
3130
const project = yield* Project.Service
3231
const shareNext = yield* ShareNext.Service
3332
const snapshot = yield* Snapshot.Service
@@ -38,8 +37,6 @@ export const layer = Layer.effect(
3837
yield* Effect.logInfo("bootstrapping", { directory: ctx.directory })
3938
// everything depends on config so eager load it for nice traces
4039
yield* config.get()
41-
// Plugin can mutate config so it has to be initialized before anything else.
42-
yield* plugin.init()
4340
// Each service self-manages its own slow work via Effect.forkScoped against
4441
// its per-instance state scope. We just await materialization here.
4542
yield* Effect.forEach(

0 commit comments

Comments
 (0)