Skip to content

Commit b05fb81

Browse files
Apply PR #22753: core: move plugin intialisation to config layer override
2 parents 69da6b5 + cbbb08e commit b05fb81

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export const TuiThreadCommand = cmd({
190190
const prompt = await input(args.prompt)
191191
const config = await TuiConfig.get()
192192

193-
const network = resolveNetworkOptionsNoConfig(args)
193+
const network = await 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 & 7 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"
@@ -22,12 +22,10 @@ export const layer = Layer.effect(
2222
// Yield each bootstrap dep at layer init so `run` itself has R = never.
2323
// InstanceStore imports only the lightweight tag from bootstrap-service.ts,
2424
// so it can depend on bootstrap without importing this implementation graph.
25-
const config = yield* Config.Service
2625
const file = yield* File.Service
2726
const fileWatcher = yield* FileWatcher.Service
2827
const format = yield* Format.Service
2928
const lsp = yield* LSP.Service
30-
const plugin = yield* Plugin.Service
3129
const project = yield* Project.Service
3230
const shareNext = yield* ShareNext.Service
3331
const snapshot = yield* Snapshot.Service
@@ -36,10 +34,6 @@ export const layer = Layer.effect(
3634
const run = Effect.gen(function* () {
3735
const ctx = yield* InstanceState.context
3836
yield* Effect.logInfo("bootstrapping", { directory: ctx.directory })
39-
// everything depends on config so eager load it for nice traces
40-
yield* config.get()
41-
// Plugin can mutate config so it has to be initialized before anything else.
42-
yield* plugin.init()
4337
// Each service self-manages its own slow work via Effect.forkScoped against
4438
// its per-instance state scope. We just await materialization here.
4539
yield* Effect.forEach(

0 commit comments

Comments
 (0)