Skip to content

Commit 7e769ac

Browse files
Apply PR #22753: core: move plugin intialisation to config layer override
2 parents 20ab9a7 + 9b85d2c commit 7e769ac

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
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") ||
@@ -258,4 +263,3 @@ export const TuiThreadCommand = cmd({
258263
process.exit(0)
259264
},
260265
})
261-
// scratch

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,

0 commit comments

Comments
 (0)