Skip to content

Commit e639271

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

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UI } from "@/cli/ui"
88
import * as Log from "@opencode-ai/core/util/log"
99
import { errorMessage } from "@/util/error"
1010
import { withTimeout } from "@/util/timeout"
11+
import { WithInstance } from "@/project/with-instance"
1112
import { withNetworkOptions, resolveNetworkOptionsNoConfig } from "@/cli/network"
1213
import { Filesystem } from "@/util/filesystem"
1314
import type { GlobalEvent } from "@opencode-ai/sdk/v2"
@@ -190,7 +191,11 @@ export const TuiThreadCommand = cmd({
190191
const prompt = await input(args.prompt)
191192
const config = await TuiConfig.get()
192193

193-
const network = resolveNetworkOptionsNoConfig(args)
194+
const network = await WithInstance.provide({
195+
directory: cwd,
196+
fn: () => resolveNetworkOptionsNoConfig(args),
197+
})
198+
194199
const external =
195200
process.argv.includes("--port") ||
196201
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -36,10 +35,9 @@ export const layer = Layer.effect(
3635
const run = Effect.gen(function* () {
3736
const ctx = yield* InstanceState.context
3837
yield* Effect.logInfo("bootstrapping", { directory: ctx.directory })
39-
// everything depends on config so eager load it for nice traces
38+
// Config calls trigger plugin initialization via app-runtime override.
39+
// Eager-load config first so plugin boot and traces happen before services.
4040
yield* config.get()
41-
// Plugin can mutate config so it has to be initialized before anything else.
42-
yield* plugin.init()
4341
// Each service self-manages its own slow work via Effect.forkScoped against
4442
// its per-instance state scope. We just await materialization here.
4543
yield* Effect.forEach(

0 commit comments

Comments
 (0)