From ddb95646ecb92672a885f3467de19d94ddefb047 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 25 Mar 2026 15:23:45 -0400 Subject: [PATCH] cleanup: remove dead code, fix types, simplify updateGlobal - readConfigFile: use typed Effect.catchIf instead of (e as any) cast - Remove dead readFile re-export (no callers) - Remove inaccurate comments - updateGlobal: replace unnecessary Effect.suspend with plain if/else --- packages/opencode/src/config/config.ts | 34 +++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 1148797fd6..0699b54241 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -1060,8 +1060,6 @@ export namespace Config { export class Service extends ServiceMap.Service()("@opencode/Config") {} - // Pure helpers (no I/O dependencies) - function globalConfigFile() { const candidates = ["opencode.jsonc", "opencode.json", "config.json"].map((file) => path.join(Global.Path.config, file), @@ -1127,7 +1125,6 @@ export namespace Config { }) } - export const { readFile } = ConfigPaths export const { JsonError, InvalidError } = ConfigPaths export const ConfigDirectoryTypoError = NamedError.create( @@ -1139,7 +1136,6 @@ export namespace Config { }), ) - // Module-level global config cache (reset sync from tests) let _cachedGlobal: Info | undefined export const layer: Layer.Layer = Layer.effect( @@ -1149,11 +1145,11 @@ export namespace Config { const readConfigFile = Effect.fnUntraced(function* (filepath: string) { return yield* fs.readFileString(filepath).pipe( - Effect.catch((e) => - "reason" in e && (e as any).reason?._tag === "NotFound" - ? Effect.succeed(undefined) - : Effect.die(e), + Effect.catchIf( + (e) => e.reason._tag === "NotFound", + () => Effect.succeed(undefined), ), + Effect.orDie, ) }) @@ -1477,19 +1473,17 @@ export namespace Config { const file = globalConfigFile() const before = (yield* readConfigFile(file)) ?? "{}" - const next: Info = yield* Effect.suspend(() => { - if (!file.endsWith(".jsonc")) { - const existing = parseConfig(before, file) - const merged = mergeDeep(existing, config) - return fs - .writeFileString(file, JSON.stringify(merged, null, 2)) - .pipe(Effect.orDie, Effect.as(merged)) - } - + let next: Info + if (!file.endsWith(".jsonc")) { + const existing = parseConfig(before, file) + const merged = mergeDeep(existing, config) + yield* fs.writeFileString(file, JSON.stringify(merged, null, 2)).pipe(Effect.orDie) + next = merged + } else { const updated = patchJsonc(before, config) - const merged = parseConfig(updated, file) - return fs.writeFileString(file, updated).pipe(Effect.orDie, Effect.as(merged)) - }) + next = parseConfig(updated, file) + yield* fs.writeFileString(file, updated).pipe(Effect.orDie) + } yield* invalidate() return next