Skip to content

Commit 4307f20

Browse files
Apply PR #22753: core: move plugin intialisation to config layer override
2 parents efab0dd + 4c72bfd commit 4307f20

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Flag } from "../../flag/flag"
88
import { PushRelay } from "../../server/push-relay"
99
import * as Log from "../../util/log"
1010
import * as QRCode from "qrcode"
11+
import { bootstrap } from "../bootstrap"
1112

1213
const log = Log.create({ service: "serve" })
1314

@@ -196,7 +197,7 @@ export const ServeCommand = cmd({
196197
}),
197198
describe: "starts a headless opencode server",
198199
handler: async (args) => {
199-
const opts = await resolveNetworkOptions(args)
200+
const opts = await bootstrap(process.cwd(), () => resolveNetworkOptions(args))
200201
const relayURL = (
201202
args["relay-url"] ??
202203
process.env.OPENCODE_EXPERIMENTAL_PUSH_RELAY_URL ??
@@ -251,7 +252,6 @@ export const ServeCommand = cmd({
251252
if (!Flag.OPENCODE_SERVER_PASSWORD) {
252253
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
253254
}
254-
255255
const server = await Server.listen(opts)
256256
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
257257

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { UI } from "@/cli/ui"
88
import { Log } from "@/util"
99
import { errorMessage } from "@/util/error"
1010
import { withTimeout } from "@/util/timeout"
11-
import { withNetworkOptions, resolveNetworkOptionsNoConfig } from "@/cli/network"
11+
import { withNetworkOptions, resolveNetworkOptions } from "@/cli/network"
1212
import { Filesystem } from "@/util"
1313
import type { GlobalEvent } from "@opencode-ai/sdk/v2"
1414
import type { EventSource } from "./context/sdk"
1515
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
1616
import { writeHeapSnapshot } from "v8"
1717
import { TuiConfig } from "./config/tui"
18+
import { Instance } from "@/project/instance"
1819

1920
declare global {
2021
const OPENCODE_WORKER_PATH: string
@@ -176,9 +177,13 @@ export const TuiThreadCommand = cmd({
176177
}
177178

178179
const prompt = await input(args.prompt)
179-
const config = await TuiConfig.get()
180-
181-
const network = resolveNetworkOptionsNoConfig(args)
180+
const { config, network } = await Instance.provide({
181+
directory: cwd,
182+
fn: async () => ({
183+
config: await TuiConfig.get(),
184+
network: await resolveNetworkOptions(args),
185+
}),
186+
})
182187
const external =
183188
process.argv.includes("--port") ||
184189
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
@@ -5,6 +5,7 @@ import { withNetworkOptions, resolveNetworkOptions } from "../network"
55
import { Flag } from "../../flag/flag"
66
import open from "open"
77
import { networkInterfaces } from "os"
8+
import { bootstrap } from "../bootstrap"
89

910
function getNetworkIPs() {
1011
const nets = networkInterfaces()
@@ -36,7 +37,7 @@ export const WebCommand = cmd({
3637
if (!Flag.OPENCODE_SERVER_PASSWORD) {
3738
UI.println(UI.Style.TEXT_WARNING_BOLD + "! OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
3839
}
39-
const opts = await resolveNetworkOptions(args)
40+
const opts = await bootstrap(process.cwd(), () => resolveNetworkOptions(args))
4041
const server = await Server.listen(opts)
4142
UI.empty()
4243
UI.println(UI.logo(" "))

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Layer, ManagedRuntime } from "effect"
22
import { attach, memoMap } from "./run-service"
33
import * as Observability from "./observability"
4+
import * as Effect from "effect/Effect"
45

56
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
67
import { Bus } from "@/bus"
@@ -49,13 +50,28 @@ import { ShareNext } from "@/share"
4950
import { SessionShare } from "@/share"
5051
import { Npm } from "@opencode-ai/shared/npm"
5152

53+
const ConfigWithPluginPriority = Layer.effect(
54+
Config.Service,
55+
Effect.gen(function* () {
56+
const config = yield* Config.Service
57+
const plugin = yield* Plugin.Service
58+
59+
return {
60+
...config,
61+
get: () => Effect.andThen(plugin.init(), config.get),
62+
getGlobal: () => Effect.andThen(plugin.init(), config.getGlobal),
63+
getConsoleState: () => Effect.andThen(plugin.init(), config.getConsoleState),
64+
}
65+
}),
66+
).pipe(Layer.provide(Layer.merge(Plugin.defaultLayer, Config.defaultLayer)))
67+
5268
export const AppLayer = Layer.mergeAll(
5369
Npm.defaultLayer,
5470
AppFileSystem.defaultLayer,
5571
Bus.defaultLayer,
5672
Auth.defaultLayer,
5773
Account.defaultLayer,
58-
Config.defaultLayer,
74+
ConfigWithPluginPriority,
5975
Git.defaultLayer,
6076
Ripgrep.defaultLayer,
6177
FileTime.defaultLayer,

packages/opencode/src/project/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import * as Effect from "effect/Effect"
1515

1616
export const InstanceBootstrap = Effect.gen(function* () {
1717
Log.Default.info("bootstrapping", { directory: Instance.directory })
18-
yield* Plugin.Service.use((svc) => svc.init())
1918
yield* Effect.all(
2019
[
20+
Plugin.Service,
2121
LSP.Service,
2222
ShareNext.Service,
2323
Format.Service,

0 commit comments

Comments
 (0)