refactor(opencode): drop AppRuntime from instance-runtime

Builds a local ManagedRuntime over InstanceLayer.layer with the shared
process-wide memoMap, so the four exported Promise helpers (load,
disposeInstance, disposeAllInstances, reloadInstance) no longer go
through AppRuntime. Service identity is preserved via memoMap; every
caller's behavior is unchanged.

One step in the broader AppRuntime removal. All public-facing exports
stay the same — callers in src/cli/bootstrap, src/cli/cmd/tui/worker,
src/acp/runtime, and the test fixtures don't need to change.
This commit is contained in:
Kit Langton
2026-05-20 20:16:50 -04:00
parent ddbd119dcb
commit 07b357de04
@@ -1,16 +1,21 @@
import { AppRuntime } from "@/effect/app-runtime"
import { Effect, ManagedRuntime } from "effect"
import { memoMap } from "@opencode-ai/core/effect/memo-map"
import { type InstanceContext } from "./instance-context"
import { InstanceLayer } from "./instance-layer"
import { InstanceStore, type LoadInput } from "./instance-store"
// Bridge for Promise/ALS callers that cannot yet yield InstanceStore.Service.
// Delete this module once those callers are migrated to Effect boundaries that
// provide InstanceStore directly.
export const load = (input: LoadInput) => AppRuntime.runPromise(InstanceStore.Service.use((store) => store.load(input)))
export const disposeInstance = (ctx: InstanceContext) =>
AppRuntime.runPromise(InstanceStore.Service.use((store) => store.dispose(ctx)))
export const disposeAllInstances = () => AppRuntime.runPromise(InstanceStore.Service.use((store) => store.disposeAll()))
export const reloadInstance = (input: LoadInput) =>
AppRuntime.runPromise(InstanceStore.Service.use((store) => store.reload(input)))
const runtime = ManagedRuntime.make(InstanceLayer.layer, { memoMap })
const run = <A, E>(fn: (store: InstanceStore.Interface) => Effect.Effect<A, E>) =>
runtime.runPromise(InstanceStore.Service.use(fn))
export const load = (input: LoadInput) => run((store) => store.load(input))
export const disposeInstance = (ctx: InstanceContext) => run((store) => store.dispose(ctx))
export const disposeAllInstances = () => run((store) => store.disposeAll())
export const reloadInstance = (input: LoadInput) => run((store) => store.reload(input))
export * as InstanceRuntime from "./instance-runtime"