Skip to content

Commit 07b9e8d

Browse files
Apply PR #22753: core: move plugin intialisation to config layer override
2 parents 613c599 + 9b85d2c commit 07b9e8d

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

packages/opencode/src/cli/cmd/serve.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Effect } from "effect"
22
import { Server } from "../../server/server"
33
import { effectCmd } from "../effect-cmd"
44
import { withNetworkOptions, resolveNetworkOptions } from "../network"
5+
import { bootstrap } from "../bootstrap"
56
import { Flag } from "@opencode-ai/core/flag/flag"
67

78
export const ServeCommand = effectCmd({
@@ -15,7 +16,7 @@ export const ServeCommand = effectCmd({
1516
if (!Flag.OPENCODE_SERVER_PASSWORD) {
1617
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
1718
}
18-
const opts = yield* Effect.promise(() => resolveNetworkOptions(args))
19+
const opts = yield* Effect.promise(() => bootstrap(process.cwd(), () => resolveNetworkOptions(args)))
1920
const server = yield* Effect.promise(() => Server.listen(opts))
2021
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
2122

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/cli/cmd/web.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { withNetworkOptions, resolveNetworkOptions } from "../network"
66
import { Flag } from "@opencode-ai/core/flag/flag"
77
import open from "open"
88
import { networkInterfaces } from "os"
9+
import { bootstrap } from "../bootstrap"
910

1011
function getNetworkIPs() {
1112
const nets = networkInterfaces()
@@ -40,7 +41,7 @@ export const WebCommand = effectCmd({
4041
if (!Flag.OPENCODE_SERVER_PASSWORD) {
4142
UI.println(UI.Style.TEXT_WARNING_BOLD + "! OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
4243
}
43-
const opts = yield* Effect.promise(() => resolveNetworkOptions(args))
44+
const opts = yield* Effect.promise(() => bootstrap(process.cwd(), () => resolveNetworkOptions(args)))
4445
const server = yield* Effect.promise(() => Server.listen(opts))
4546
UI.empty()
4647
UI.println(UI.logo(" "))

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 & 1 deletion
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"

0 commit comments

Comments
 (0)