refactor(opencode): roll out serviceUse proxy across 14 services + tests (#28576)

This commit is contained in:
Kit Langton 2026-05-20 23:36:27 -04:00 • committed by GitHub
commit 39ea816a72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 646 additions and 628 deletions

View file

@ -1,4 +1,5 @@
import { Cache, Clock, Duration, Effect, Layer, Option, Schema, SchemaGetter, Context } from "effect"
import { serviceUse } from "@/effect/service-use"
import {
FetchHttpClient,
HttpClient,
@ -181,6 +182,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Account") {}
export const use = serviceUse(Service)
export const layer: Layer.Layer<Service, never, AccountRepo.Service | HttpClient.HttpClient> = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { eq } from "drizzle-orm"
import { serviceUse } from "@/effect/service-use"
import { Effect, Layer, Option, Schema, Context } from "effect"
import { Database } from "@/storage/db"
@ -38,6 +39,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/AccountRepo") {}
export const use = serviceUse(Service)
export const layer: Layer.Layer<Service> = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { Config } from "@/config/config"
import { serviceUse } from "@/effect/service-use"
import { Provider } from "@/provider/provider"
import { ModelID, ProviderID } from "../provider/schema"
import { generateObject, streamObject, type ModelMessage } from "ai"
@ -76,6 +77,8 @@ type State = Omit<Interface, "generate">
export class Service extends Context.Service<Service, Interface>()("@opencode/Agent") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import * as Log from "@opencode-ai/core/util/log"
import { serviceUse } from "@/effect/service-use"
import path from "path"
import { pathToFileURL } from "url"
import os from "os"
@ -319,6 +320,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Config") {}
export const use = serviceUse(Service)
function globalConfigFile() {
const candidates = ["opencode.jsonc", "opencode.json", "config.json"].map((file) =>
path.join(Global.Path.config, file),

View file

@ -1,4 +1,5 @@
import { Context, Effect, Layer } from "effect"
import { serviceUse } from "@/effect/service-use"
import { InstanceState } from "@/effect/instance-state"
type State = Record<string, string | undefined>
@ -12,6 +13,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Env") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { BusEvent } from "@/bus/bus-event"
import { serviceUse } from "@/effect/service-use"
import { InstanceState } from "@/effect/instance-state"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
@ -326,6 +327,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/File") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import path from "path"
import { serviceUse } from "@/effect/service-use"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { Cause, Context, Effect, Fiber, Layer, Queue, Schema, Stream } from "effect"
import type { PlatformError } from "effect/PlatformError"
@ -141,6 +142,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Ripgrep") {}
export const use = serviceUse(Service)
function env() {
const env = sanitizedProcessEnv()
delete env.RIPGREP_CONFIG_PATH

View file

@ -1,4 +1,5 @@
import { Effect, Layer, Context, Schema } from "effect"
import { serviceUse } from "@/effect/service-use"
import { ChildProcess } from "effect/unstable/process"
import { AppProcess } from "@opencode-ai/core/process"
import { InstanceState } from "@/effect/instance-state"
@ -27,6 +28,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Format") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { Effect, Layer, Schema, Context, Stream } from "effect"
import { serviceUse } from "@/effect/service-use"
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
import { withTransientReadRetry } from "@/util/effect-http-client"
import { errorMessage } from "@/util/error"
@ -89,6 +90,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/Installation") {}
export const use = serviceUse(Service)
export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | AppProcess.Service> = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import path from "path"
import { serviceUse } from "@/effect/service-use"
import { Global } from "@opencode-ai/core/global"
import { Effect, Layer, Context, Option, Schema } from "effect"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
@ -51,6 +52,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/McpAuth") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { dynamicTool, type Tool, jsonSchema, type JSONSchema7 } from "ai"
import { serviceUse } from "@/effect/service-use"
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
@ -264,6 +265,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/MCP") {}
export const use = serviceUse(Service)
export const layer = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import { GlobalBus } from "@/bus/global"
import { serviceUse } from "@/effect/service-use"
import { WorkspaceContext } from "@/control-plane/workspace-context"
import { InstanceRef } from "@/effect/instance-ref"
import { disposeInstance as runDisposers } from "@/effect/instance-registry"
@ -24,6 +25,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/InstanceStore") {}
export const use = serviceUse(Service)
interface Entry {
readonly deferred: Deferred.Deferred<InstanceContext>
}

View file

@ -1,4 +1,5 @@
import type { AuthOAuthResult, Hooks } from "@opencode-ai/plugin"
import { serviceUse } from "@/effect/service-use"
import { Auth } from "@/auth"
import { InstanceState } from "@/effect/instance-state"
import { optionalOmitUndefined } from "@opencode-ai/core/schema"
@ -102,6 +103,8 @@ interface State {
export class Service extends Context.Service<Service, Interface>()("@opencode/ProviderAuth") {}
export const use = serviceUse(Service)
export const layer: Layer.Layer<Service, never, Auth.Service | Plugin.Service> = Layer.effect(
Service,
Effect.gen(function* () {

View file

@ -1,4 +1,5 @@
import type * as SDK from "@opencode-ai/sdk/v2"
import { serviceUse } from "@/effect/service-use"
import { Effect, Exit, Layer, Option, Schema, Scope, Context, Stream } from "effect"
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
import { Account } from "@/account/account"
@ -76,6 +77,8 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/ShareNext") {}
export const use = serviceUse(Service)
const db = <T>(fn: (d: Parameters<typeof Database.use>[0] extends (trx: infer D) => any ? D : never) => T) =>
Effect.sync(() => Database.use(fn))

View file

@ -18,14 +18,14 @@ const it = testEffect(Layer.merge(AccountRepo.layer, truncate))
it.live("list returns empty when no accounts exist", () =>
Effect.gen(function* () {
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts).toEqual([])
}),
)
it.live("active returns none when no accounts exist", () =>
Effect.gen(function* () {
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isNone(active)).toBe(true)
}),
)
@ -45,13 +45,13 @@ it.live("persistAccount inserts and getRow retrieves", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.isSome(row)).toBe(true)
const value = Option.getOrThrow(row)
expect(value.id).toBe(AccountID.make("user-1"))
expect(value.email).toBe("test@example.com")
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-1"))
}),
)
@ -72,9 +72,9 @@ it.live("persistAccount normalizes trailing slashes in stored server URLs", () =
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const active = yield* AccountRepo.Service.use((r) => r.active())
const list = yield* AccountRepo.Service.use((r) => r.list())
const row = yield* AccountRepo.use.getRow(id)
const active = yield* AccountRepo.use.active()
const list = yield* AccountRepo.use.list()
expect(Option.getOrThrow(row).url).toBe("https://control.example.com")
expect(Option.getOrThrow(active).url).toBe("https://control.example.com")
@ -112,7 +112,7 @@ it.live("persistAccount sets the active account and org", () =>
)
// Last persisted account is active with its org
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isSome(active)).toBe(true)
expect(Option.getOrThrow(active).id).toBe(AccountID.make("user-2"))
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-2"))
@ -148,7 +148,7 @@ it.live("list returns all accounts", () =>
}),
)
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts.length).toBe(2)
expect(accounts.map((a) => a.email).sort()).toEqual(["a@example.com", "b@example.com"])
}),
@ -170,9 +170,9 @@ it.live("remove deletes an account", () =>
}),
)
yield* AccountRepo.Service.use((r) => r.remove(id))
yield* AccountRepo.use.remove(id)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.isNone(row)).toBe(true)
}),
)
@ -207,12 +207,12 @@ it.live("use stores the selected org and marks the account active", () =>
)
yield* AccountRepo.Service.use((r) => r.use(id1, Option.some(OrgID.make("org-99"))))
const active1 = yield* AccountRepo.Service.use((r) => r.active())
const active1 = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active1).id).toBe(id1)
expect(Option.getOrThrow(active1).active_org_id).toBe(OrgID.make("org-99"))
yield* AccountRepo.Service.use((r) => r.use(id1, Option.none()))
const active2 = yield* AccountRepo.Service.use((r) => r.active())
const active2 = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active2).active_org_id).toBeNull()
}),
)
@ -243,7 +243,7 @@ it.live("persistToken updates token fields", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("new_token"))
expect(value.refresh_token).toBe(RefreshToken.make("new_refresh"))
@ -276,7 +276,7 @@ it.live("persistToken with no expiry sets token_expiry to null", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.getOrThrow(row).token_expiry).toBeNull()
}),
)
@ -309,14 +309,14 @@ it.live("persistAccount upserts on conflict", () =>
}),
)
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts.length).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_v2"))
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-2"))
}),
)
@ -337,9 +337,9 @@ it.live("remove clears active state when deleting the active account", () =>
}),
)
yield* AccountRepo.Service.use((r) => r.remove(id))
yield* AccountRepo.use.remove(id)
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isNone(active)).toBe(true)
}),
)

View file

@ -88,7 +88,7 @@ it.live("login normalizes trailing slashes in the provided server URL", () =>
}),
)
const result = yield* Account.Service.use((s) => s.login("https://one.example.com/")).pipe(
const result = yield* Account.use.login("https://one.example.com/").pipe(
Effect.provide(live(client)),
)
@ -109,7 +109,7 @@ it.live("login maps transport failures to account transport errors", () =>
)
const error = yield* Effect.flip(
Account.Service.use((s) => s.login("https://one.example.com")).pipe(Effect.provide(live(client))),
Account.use.login("https://one.example.com").pipe(Effect.provide(live(client))),
)
expect(error).toBeInstanceOf(AccountTransportError)
@ -163,7 +163,7 @@ it.live("orgsByAccount groups orgs per account", () =>
}),
)
const rows = yield* Account.Service.use((s) => s.orgsByAccount()).pipe(Effect.provide(live(client)))
const rows = yield* Account.use.orgsByAccount().pipe(Effect.provide(live(client)))
expect(rows.map((row) => [row.account.id, row.orgs.map((org) => org.id)]).map(([id, orgs]) => [id, orgs])).toEqual([
[AccountID.make("user-1"), [OrgID.make("org-1")]],
@ -201,12 +201,12 @@ it.live("token refresh persists the new token", () =>
),
)
const token = yield* Account.Service.use((s) => s.token(id)).pipe(Effect.provide(live(client)))
const token = yield* Account.use.token(id).pipe(Effect.provide(live(client)))
expect(Option.getOrThrow(token)).toBeDefined()
expect(String(Option.getOrThrow(token))).toBe("at_new")
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@ -246,12 +246,12 @@ it.live("token refreshes before expiry when inside the eager refresh window", ()
}),
)
const token = yield* Account.Service.use((s) => s.token(id)).pipe(Effect.provide(live(client)))
const token = yield* Account.use.token(id).pipe(Effect.provide(live(client)))
expect(String(Option.getOrThrow(token))).toBe("at_new")
expect(refreshCalls).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@ -315,7 +315,7 @@ it.live("concurrent config and token requests coalesce token refresh", () =>
expect(String(Option.getOrThrow(token))).toBe("at_new")
expect(refreshCalls).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@ -388,7 +388,7 @@ it.live("poll stores the account and first org on success", () =>
expect(res.email).toBe("user@example.com")
}
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active)).toEqual(
expect.objectContaining({
id: "user-1",

View file

@ -46,8 +46,8 @@ function testAgent(input: {
it.instance("[#26514] subagent spawned from plan mode inherits read-only restriction (edit denied)", () =>
Effect.gen(function* () {
const planAgent = yield* Agent.Service.use((svc) => svc.get("plan"))
const generalAgent = yield* Agent.Service.use((svc) => svc.get("general"))
const planAgent = yield* Agent.use.get("plan")
const generalAgent = yield* Agent.use.get("general")
expect(planAgent).toBeDefined()
expect(generalAgent).toBeDefined()
@ -83,8 +83,8 @@ it.instance("[#26514] explore subagent launched from plan mode also stays read-o
// should propagate the parent **agent** permissions, not just deny edit
// when the subagent happens to already deny it.
Effect.gen(function* () {
const planAgent = yield* Agent.Service.use((svc) => svc.get("plan"))
const explore = yield* Agent.Service.use((svc) => svc.get("explore"))
const planAgent = yield* Agent.use.get("plan")
const explore = yield* Agent.use.get("explore")
expect(planAgent).toBeDefined()
expect(explore).toBeDefined()
@ -108,8 +108,8 @@ it.instance(
// be able to edit when the parent agent is `plan`.
() =>
Effect.gen(function* () {
const planAgent = yield* Agent.Service.use((svc) => svc.get("plan"))
const my = yield* Agent.Service.use((svc) => svc.get("my_subagent"))
const planAgent = yield* Agent.use.get("plan")
const my = yield* Agent.use.get("my_subagent")
expect(planAgent).toBeDefined()
expect(my).toBeDefined()

View file

@ -51,7 +51,7 @@ it.instance(
() =>
Effect.gen(function* () {
yield* Plugin.Service.use((p) => p.init())
const agents = yield* Agent.Service.use((svc) => svc.list())
const agents = yield* Agent.use.list()
const added = agents.find((agent) => agent.name === PLUGIN_AGENT.name)
expect(added?.description).toBe(PLUGIN_AGENT.description)
expect(added?.mode).toBe(PLUGIN_AGENT.mode)

View file

@ -11,7 +11,7 @@ it.instance(
"agent color parsed from project config",
() =>
Effect.gen(function* () {
const cfg = yield* Config.Service.use((svc) => svc.get())
const cfg = yield* Config.use.get()
expect(cfg.agent?.["build"]?.color).toBe("#FFA500")
expect(cfg.agent?.["plan"]?.color).toBe("primary")
}),
@ -30,9 +30,9 @@ it.instance(
"Agent.get includes color from config",
() =>
Effect.gen(function* () {
const plan = yield* AgentSvc.Service.use((svc) => svc.get("plan"))
const plan = yield* AgentSvc.use.get("plan")
expect(plan?.color).toBe("#A855F7")
const build = yield* AgentSvc.Service.use((svc) => svc.get("build"))
const build = yield* AgentSvc.use.get("build")
expect(build?.color).toBe("accent")
}),
{

View file

@ -70,14 +70,14 @@ const load = (ctx: InstanceContext) =>
)
const saveGlobal = (config: Config.Info) =>
Effect.runPromise(
Config.Service.use((svc) => svc.updateGlobal(config)).pipe(
Config.use.updateGlobal(config).pipe(
Effect.map((result) => result.info),
Effect.scoped,
Effect.provide(layer),
),
)
const clear = async (wait = false) => {
await Effect.runPromise(Config.Service.use((svc) => svc.invalidate()).pipe(Effect.scoped, Effect.provide(layer)))
await Effect.runPromise(Config.use.invalidate().pipe(Effect.scoped, Effect.provide(layer)))
if (wait) await InstanceRuntime.disposeAllInstances()
}
const listDirs = (ctx: InstanceContext) =>
@ -162,7 +162,7 @@ async function check(map: (dir: string) => string) {
it.instance("loads config with defaults when no files exist", () =>
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.username).toBeDefined()
}),
)
@ -218,7 +218,7 @@ test("does not create global config when OPENCODE_CONFIG_DIR is set", async () =
it.instance(
"loads JSON config file",
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("test/model")
expect(config.username).toBe("testuser")
}),
@ -228,7 +228,7 @@ it.instance(
it.instance(
"loads shell config field",
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.shell).toBe("bash")
}),
{ config: { shell: "bash" } },
@ -313,7 +313,7 @@ test("updates global config and omits empty shell key in jsonc", async () => {
it.instance(
"loads formatter boolean config",
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.formatter).toBe(true)
}),
{ config: { formatter: true } },
@ -322,7 +322,7 @@ it.instance(
it.instance(
"loads lsp boolean config",
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.lsp).toBe(true)
}),
{ config: { lsp: true } },
@ -355,7 +355,7 @@ it.instance("ignores legacy tui keys in opencode config", () =>
tui: { scroll_speed: 4 },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("test/model")
expect((config as Record<string, unknown>).theme).toBeUndefined()
expect((config as Record<string, unknown>).tui).toBeUndefined()
@ -376,7 +376,7 @@ it.instance("loads JSONC config file", () =>
}`,
),
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("test/model")
expect(config.username).toBe("testuser")
}),
@ -398,7 +398,7 @@ it.instance("jsonc overrides json in the same directory", () =>
$schema: "https://opencode.ai/config.json",
model: "override",
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("base")
expect(config.username).toBe("base")
}),
@ -414,7 +414,7 @@ it.instance("handles environment variable substitution", () =>
$schema: "https://opencode.ai/config.json",
username: "{env:TEST_VAR}",
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.username).toBe("test-user")
}),
),
@ -435,7 +435,7 @@ it.instance("preserves env variables when adding $schema to config", () =>
}),
),
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.username).toBe("secret_value")
// Read the file to verify the env variable was preserved
@ -455,7 +455,7 @@ it.instance("handles file inclusion substitution", () =>
$schema: "https://opencode.ai/config.json",
username: "{file:included.txt}",
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.username).toBe("test-user")
}),
)
@ -470,7 +470,7 @@ it.instance("handles file inclusion with replacement tokens", () =>
$schema: "https://opencode.ai/config.json",
username: "{file:included.md}",
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.username).toBe("const out = await Bun.$`echo hi`")
}),
)
@ -547,7 +547,7 @@ it.instance("validates config schema and throws on invalid fields", () =>
$schema: "https://opencode.ai/config.json",
invalid_field: "should cause error",
})
const exit = yield* Config.Service.use((svc) => svc.get()).pipe(Effect.exit)
const exit = yield* Config.use.get().pipe(Effect.exit)
expect(Exit.isFailure(exit)).toBe(true)
}),
)
@ -556,7 +556,7 @@ it.instance("throws error for invalid JSON", () =>
Effect.gen(function* () {
const test = yield* TestInstance
yield* Effect.promise(() => Filesystem.write(path.join(test.directory, "opencode.json"), "{ invalid json }"))
const exit = yield* Config.Service.use((svc) => svc.get()).pipe(Effect.exit)
const exit = yield* Config.use.get().pipe(Effect.exit)
expect(Exit.isFailure(exit)).toBe(true)
}),
)
@ -574,7 +574,7 @@ it.instance("handles agent configuration", () =>
},
},
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test_agent"]).toEqual(
expect.objectContaining({
model: "test/model",
@ -598,7 +598,7 @@ it.instance("treats agent variant as model-scoped setting (not provider option)"
},
},
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
const agent = config.agent?.["test_agent"]
expect(agent?.variant).toBe("xhigh")
@ -622,7 +622,7 @@ it.instance("handles command configuration", () =>
},
},
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.command?.["test_command"]).toEqual({
template: "test template",
description: "test command",
@ -638,7 +638,7 @@ it.instance("migrates autoshare to share field", () =>
$schema: "https://opencode.ai/config.json",
autoshare: true,
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.share).toBe("auto")
expect(config.autoshare).toBe(true)
}),
@ -656,7 +656,7 @@ it.instance("migrates mode field to agent field", () =>
},
},
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test_mode"]).toEqual({
model: "test/model",
temperature: 0.5,
@ -679,7 +679,7 @@ model: test/model
Test agent prompt`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]).toEqual(
expect.objectContaining({
name: "test",
@ -705,7 +705,7 @@ permission:
Ordered permissions`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(Object.keys(config.agent?.ordered?.permission ?? {})).toEqual(["bash", "*", "edit"])
}),
)
@ -732,7 +732,7 @@ mode: subagent
Nested agent prompt`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["helper"]).toMatchObject({
name: "helper",
@ -770,7 +770,7 @@ description: Nested command
Nested command template`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.command?.["hello"]).toEqual({
description: "Test command",
@ -804,7 +804,7 @@ description: Nested command
Nested command template`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.command?.["hello"]).toEqual({
description: "Test command",
@ -834,7 +834,7 @@ it.instance("updates config and writes to file", () =>
it.instance("gets config directories", () =>
Effect.gen(function* () {
const dirs = yield* Config.Service.use((svc) => svc.directories())
const dirs = yield* Config.use.directories()
expect(dirs.length).toBeGreaterThanOrEqual(1)
}),
)
@ -950,7 +950,7 @@ it.instance("resolves scoped npm plugins in config", () =>
yield* writeTextEffect(path.join(pluginDir, "index.js"), "export default {}\n")
yield* writeConfigEffect(test.directory, { plugin: ["@scope/plugin"] })
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.plugin ?? []).toContain("@scope/plugin")
}),
)
@ -1014,7 +1014,7 @@ mode: subagent
Helper subagent prompt`,
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["helper"]).toMatchObject({
name: "helper",
model: "test/model",
@ -1212,7 +1212,7 @@ it.instance("migrates legacy tools config to permissions - allow", () =>
agent: { test: { tools: { bash: true, read: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({
bash: "allow",
read: "allow",
@ -1228,7 +1228,7 @@ it.instance("migrates legacy tools config to permissions - deny", () =>
agent: { test: { tools: { bash: false, webfetch: false } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({
bash: "deny",
webfetch: "deny",
@ -1244,7 +1244,7 @@ it.instance("migrates legacy write tool to edit permission", () =>
agent: { test: { tools: { write: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
}),
)
@ -1261,7 +1261,7 @@ it.instance(
share: "disabled",
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("managed/model")
expect(config.share).toBe("disabled")
expect(config.username).toBe("testuser")
@ -1278,7 +1278,7 @@ it.instance(
disabled_providers: ["openai"],
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.autoupdate).toBe(false)
expect(config.disabled_providers).toEqual(["openai"])
}),
@ -1288,7 +1288,7 @@ it.instance(
it.instance(
"missing managed settings file is not an error",
Effect.gen(function* () {
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.model).toBe("user/model")
}),
{ config: { model: "user/model" } },
@ -1302,7 +1302,7 @@ it.instance("migrates legacy edit tool to edit permission", () =>
agent: { test: { tools: { edit: false } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({ edit: "deny" })
}),
)
@ -1315,7 +1315,7 @@ it.instance("migrates legacy patch tool to edit permission", () =>
agent: { test: { tools: { patch: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
}),
)
@ -1328,7 +1328,7 @@ it.instance("migrates mixed legacy tools config", () =>
agent: { test: { tools: { bash: true, write: true, read: false, webfetch: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({
bash: "allow",
edit: "allow",
@ -1346,7 +1346,7 @@ it.instance("merges legacy tools with existing permission config", () =>
agent: { test: { permission: { glob: "allow" }, tools: { bash: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.agent?.["test"]?.permission).toEqual({
glob: "allow",
bash: "allow",
@ -1375,7 +1375,7 @@ it.instance("permission config preserves user key order", () =>
},
})
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(Object.keys(config.permission!)).toEqual([
"*",
"edit",
@ -1451,7 +1451,7 @@ it.instance("project config can override MCP server enabled status", () =>
"opencode.jsonc",
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.mcp?.jira).toEqual({
type: "remote",
url: "https://jira.example.com/mcp",
@ -1496,7 +1496,7 @@ it.instance("MCP config deep merges preserving base config properties", () =>
"opencode.jsonc",
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.mcp?.myserver).toEqual({
type: "remote",
url: "https://myserver.example.com/mcp",
@ -1537,7 +1537,7 @@ it.instance("local .opencode config can override MCP from project config", () =>
"opencode.json",
)
const config = yield* Config.Service.use((svc) => svc.get())
const config = yield* Config.use.get()
expect(config.mcp?.docs?.enabled).toBe(true)
}),
)

Some files were not shown because too many files have changed in this diff Show more