Skip to content

Commit cb1e911

Browse files
Apply PR #22517: refactor: remove makeRuntime from TuiConfig
2 parents 34fbe49 + a8d6379 commit cb1e911

File tree

15 files changed

+181
-133
lines changed

15 files changed

+181
-133
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { tui } from "./app"
44
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
55
import { TuiConfig } from "@/config/tui"
66
import { Instance } from "@/project/instance"
7+
import { AppRuntime } from "@/effect/app-runtime"
78
import { existsSync } from "fs"
89

910
export const AttachCommand = cmd({
@@ -68,7 +69,7 @@ export const AttachCommand = cmd({
6869
})()
6970
const config = await Instance.provide({
7071
directory: directory && existsSync(directory) ? directory : process.cwd(),
71-
fn: () => TuiConfig.get(),
72+
fn: () => AppRuntime.runPromise(TuiConfig.Service.use((svc) => svc.get())),
7273
})
7374
await tui({
7475
url: args.url,

packages/opencode/src/cli/cmd/tui/plugin/runtime.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { fileURLToPath } from "url"
1515

1616
import { Config } from "@/config/config"
1717
import { TuiConfig } from "@/config/tui"
18+
import { AppRuntime } from "@/effect/app-runtime"
1819
import { Log } from "@/util/log"
1920
import { errorData, errorMessage } from "@/util/error"
2021
import { isRecord } from "@/util/record"
@@ -794,7 +795,10 @@ async function addPluginBySpec(state: RuntimeState | undefined, raw: string) {
794795

795796
const ready = await Instance.provide({
796797
directory: state.directory,
797-
fn: () => resolveExternalPlugins([cfg], () => TuiConfig.waitForDependencies()),
798+
fn: () =>
799+
resolveExternalPlugins([cfg], () =>
800+
AppRuntime.runPromise(TuiConfig.Service.use((svc) => svc.waitForDependencies())),
801+
),
798802
}).catch((error) => {
799803
fail("failed to add tui plugin", { path: next, error })
800804
return [] as PluginLoad[]
@@ -991,7 +995,7 @@ export namespace TuiPluginRuntime {
991995
await Instance.provide({
992996
directory: cwd,
993997
fn: async () => {
994-
const config = await TuiConfig.get()
998+
const config = await AppRuntime.runPromise(TuiConfig.Service.use((svc) => svc.get()))
995999
const records = Flag.OPENCODE_PURE ? [] : (config.plugin_origins ?? [])
9961000
if (Flag.OPENCODE_PURE && config.plugin_origins?.length) {
9971001
log.info("skipping external tui plugins in pure mode", { count: config.plugin_origins.length })
@@ -1011,7 +1015,9 @@ export namespace TuiPluginRuntime {
10111015
})
10121016
}
10131017

1014-
const ready = await resolveExternalPlugins(records, () => TuiConfig.waitForDependencies())
1018+
const ready = await resolveExternalPlugins(records, () =>
1019+
AppRuntime.runPromise(TuiConfig.Service.use((svc) => svc.waitForDependencies())),
1020+
)
10151021
await addExternalPluginEntries(next, ready)
10161022

10171023
applyInitialPluginEnabledState(next, config)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { EventSource } from "./context/sdk"
1515
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
1616
import { TuiConfig } from "@/config/tui"
1717
import { Instance } from "@/project/instance"
18+
import { AppRuntime } from "@/effect/app-runtime"
1819
import { writeHeapSnapshot } from "v8"
1920

2021
declare global {
@@ -179,7 +180,7 @@ export const TuiThreadCommand = cmd({
179180
const prompt = await input(args.prompt)
180181
const config = await Instance.provide({
181182
directory: cwd,
182-
fn: () => TuiConfig.get(),
183+
fn: () => AppRuntime.runPromise(TuiConfig.Service.use((svc) => svc.get())),
183184
})
184185

185186
const network = await resolveNetworkOptions(args)

packages/opencode/src/config/tui.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { isRecord } from "@/util/record"
1212
import { Global } from "@/global"
1313
import { Filesystem } from "@/util/filesystem"
1414
import { InstanceState } from "@/effect/instance-state"
15-
import { makeRuntime } from "@/effect/run-service"
1615
import { AppFileSystem } from "@/filesystem"
1716

1817
export namespace TuiConfig {
@@ -170,16 +169,6 @@ export namespace TuiConfig {
170169

171170
export const defaultLayer = layer.pipe(Layer.provide(Config.defaultLayer))
172171

173-
const { runPromise } = makeRuntime(Service, defaultLayer)
174-
175-
export async function get() {
176-
return runPromise((svc) => svc.get())
177-
}
178-
179-
export async function waitForDependencies() {
180-
await runPromise((svc) => svc.waitForDependencies())
181-
}
182-
183172
async function loadFile(filepath: string): Promise<Info> {
184173
const text = await ConfigPaths.readFile(filepath)
185174
if (!text) return {}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { Pty } from "@/pty"
4747
import { Installation } from "@/installation"
4848
import { ShareNext } from "@/share/share-next"
4949
import { SessionShare } from "@/share/session"
50+
import { TuiConfig } from "@/config/tui"
5051

5152
export const AppLayer = Layer.mergeAll(
5253
Observability.layer,
@@ -95,6 +96,7 @@ export const AppLayer = Layer.mergeAll(
9596
Installation.defaultLayer,
9697
ShareNext.defaultLayer,
9798
SessionShare.defaultLayer,
99+
TuiConfig.defaultLayer,
98100
)
99101

100102
const rt = ManagedRuntime.make(AppLayer, { memoMap })

packages/opencode/test/cli/tui/plugin-add.test.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { expect, spyOn, test } from "bun:test"
22
import fs from "fs/promises"
33
import path from "path"
4+
import { Effect } from "effect"
45
import { pathToFileURL } from "url"
56
import { tmpdir } from "../../fixture/fixture"
67
import { createTuiPluginApi } from "../../fixture/tui-plugin"
7-
import { TuiConfig } from "../../../src/config/tui"
8+
import { mockTuiService } from "../../fixture/tui-runtime"
89

910
const { TuiPluginRuntime } = await import("../../../src/cli/cmd/tui/plugin/runtime")
1011

@@ -31,11 +32,10 @@ test("adds tui plugin at runtime from spec", async () => {
3132
})
3233

3334
process.env.OPENCODE_PLUGIN_META_FILE = path.join(tmp.path, "plugin-meta.json")
34-
const get = spyOn(TuiConfig, "get").mockResolvedValue({
35+
const restore = mockTuiService({
3536
plugin: [],
3637
plugin_origins: undefined,
3738
})
38-
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
3939
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
4040

4141
try {
@@ -54,8 +54,7 @@ test("adds tui plugin at runtime from spec", async () => {
5454
} finally {
5555
await TuiPluginRuntime.dispose()
5656
cwd.mockRestore()
57-
get.mockRestore()
58-
wait.mockRestore()
57+
restore()
5958
delete process.env.OPENCODE_PLUGIN_META_FILE
6059
}
6160
})
@@ -72,36 +71,39 @@ test("retries runtime add for file plugins after dependency wait", async () => {
7271
})
7372

7473
process.env.OPENCODE_PLUGIN_META_FILE = path.join(tmp.path, "plugin-meta.json")
75-
const get = spyOn(TuiConfig, "get").mockResolvedValue({
76-
plugin: [],
77-
plugin_origins: undefined,
78-
})
79-
const wait = spyOn(TuiConfig, "waitForDependencies").mockImplementation(async () => {
80-
await Bun.write(
81-
path.join(tmp.extra.mod, "index.ts"),
82-
`export default {
74+
const restore = mockTuiService(
75+
{
76+
plugin: [],
77+
plugin_origins: undefined,
78+
},
79+
{
80+
wait: () =>
81+
Effect.promise(async () => {
82+
await Bun.write(
83+
path.join(tmp.extra.mod, "index.ts"),
84+
`export default {
8385
id: "demo.add.retry",
8486
tui: async () => {
8587
await Bun.write(${JSON.stringify(tmp.extra.marker)}, "called")
8688
},
8789
}
8890
`,
89-
)
90-
})
91+
)
92+
}),
93+
},
94+
)
9195
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
9296

9397
try {
9498
await TuiPluginRuntime.init(createTuiPluginApi())
9599

96100
await expect(TuiPluginRuntime.addPlugin(tmp.extra.spec)).resolves.toBe(true)
97101
await expect(fs.readFile(tmp.extra.marker, "utf8")).resolves.toBe("called")
98-
expect(wait).toHaveBeenCalledTimes(1)
99102
expect(TuiPluginRuntime.list().find((item) => item.id === "demo.add.retry")?.active).toBe(true)
100103
} finally {
101104
await TuiPluginRuntime.dispose()
102105
cwd.mockRestore()
103-
get.mockRestore()
104-
wait.mockRestore()
106+
restore()
105107
delete process.env.OPENCODE_PLUGIN_META_FILE
106108
}
107109
})

packages/opencode/test/cli/tui/plugin-install.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { pathToFileURL } from "url"
55
import { tmpdir } from "../../fixture/fixture"
66
import { createTuiPluginApi } from "../../fixture/tui-plugin"
77
import { TuiConfig } from "../../../src/config/tui"
8+
import { mockTuiService } from "../../fixture/tui-runtime"
89

910
const { TuiPluginRuntime } = await import("../../../src/cli/cmd/tui/plugin/runtime")
1011

@@ -50,12 +51,11 @@ test("installs plugin without loading it", async () => {
5051
})
5152

5253
process.env.OPENCODE_PLUGIN_META_FILE = path.join(tmp.path, "plugin-meta.json")
53-
const cfg: Awaited<ReturnType<typeof TuiConfig.get>> = {
54+
const cfg: TuiConfig.Info = {
5455
plugin: [],
5556
plugin_origins: undefined,
5657
}
57-
const get = spyOn(TuiConfig, "get").mockImplementation(async () => cfg)
58-
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
58+
const restore = mockTuiService(cfg)
5959
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
6060
const api = createTuiPluginApi({
6161
state: {
@@ -82,8 +82,7 @@ test("installs plugin without loading it", async () => {
8282
} finally {
8383
await TuiPluginRuntime.dispose()
8484
cwd.mockRestore()
85-
get.mockRestore()
86-
wait.mockRestore()
85+
restore()
8786
delete process.env.OPENCODE_PLUGIN_META_FILE
8887
}
8988
})

packages/opencode/test/cli/tui/plugin-lifecycle.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { pathToFileURL } from "url"
55
import { tmpdir } from "../../fixture/fixture"
66
import { createTuiPluginApi } from "../../fixture/tui-plugin"
77
import { mockTuiRuntime } from "../../fixture/tui-runtime"
8-
import { TuiConfig } from "../../../src/config/tui"
98

109
const { TuiPluginRuntime } = await import("../../../src/cli/cmd/tui/plugin/runtime")
1110

0 commit comments

Comments
 (0)