diff --git a/packages/cli/src/commands/handlers/default.ts b/packages/cli/src/commands/handlers/default.ts index dd6a4a0831..35c5635a09 100644 --- a/packages/cli/src/commands/handlers/default.ts +++ b/packages/cli/src/commands/handlers/default.ts @@ -11,7 +11,6 @@ import { UpdatePreflight } from "../../services/update-preflight" import { Npm } from "@opencode-ai/util/npm" import { OPENCODE_CHANNEL, OPENCODE_VERSION } from "../../version" import { Env } from "../../env" -import type { EnsureReason } from "@opencode-ai/client/effect/service" export default Runtime.handler(Commands, (input) => Effect.gen(function* () { @@ -20,7 +19,10 @@ export default Runtime.handler(Commands, (input) => if (requestedDirectory !== undefined) process.chdir(requestedDirectory) const preflight = UpdatePreflight.make() yield* Effect.addFinalizer(() => Effect.promise(() => preflight.close())) - const serviceStarts = yield* Queue.unbounded<{ readonly reason: EnsureReason; readonly previousVersion?: string }>() + const serviceStarts = yield* Queue.unbounded<{ + readonly reason: "missing" | "version-mismatch" + readonly previousVersion?: string + }>() yield* Queue.take(serviceStarts).pipe( Effect.flatMap((event) => Effect.logInfo("background service starting", event)), Effect.forever, @@ -36,9 +38,7 @@ export default Runtime.handler(Commands, (input) => process.stderr.write( reason === "version-mismatch" ? "Restarting background server (version mismatch)...\n" - : reason === "replacement" - ? "Restarting background server...\n" - : "Starting background server...\n", + : "Starting background server...\n", ) }, }).pipe( diff --git a/packages/client/src/effect/service.ts b/packages/client/src/effect/service.ts index 309518c471..91e0a61666 100644 --- a/packages/client/src/effect/service.ts +++ b/packages/client/src/effect/service.ts @@ -2,7 +2,7 @@ import { ServiceStatus } from "@opencode-ai/protocol/groups/health" import { Effect, FileSystem, Option, Schedule, Schema } from "effect" import { homedir } from "node:os" import { join } from "node:path" -import type { DiscoverOptions, Endpoint, EnsureOptions, EnsureReason, StopOptions } from "../service.js" +import type { DiscoverOptions, Endpoint, EnsureOptions, StopOptions } from "../service.js" import { contenderFailure, contenderFinished, @@ -67,7 +67,7 @@ const ensureService = Effect.fnUntraced(function* (options: EnsureOptions, force let announced = false let lastSpawn = 0 let spawnDelay = timing.spawnDelay - const announce = (reason: EnsureReason, previousVersion?: string) => + const announce = (reason: "missing" | "version-mismatch", previousVersion?: string) => Effect.sync(() => { if (announced) return announced = true @@ -113,7 +113,7 @@ const ensureService = Effect.fnUntraced(function* (options: EnsureOptions, force if (!replacing && compatible && service.state === "failed") return yield* Effect.fail(new Error("Background service failed to start")) if (!replacing && compatible) return Option.none() - yield* announce(replacing ? "replacement" : "version-mismatch", service.version) + yield* announce("version-mismatch", service.version) if (!service.legacy && service.state === "ready") yield* Effect.tryPromise(() => PtyHandoff.prepare(options.file ?? fallback(), service.info, timing.requestTimeout), diff --git a/packages/client/src/promise/service.ts b/packages/client/src/promise/service.ts index 873a842f30..3f8bde3313 100644 --- a/packages/client/src/promise/service.ts +++ b/packages/client/src/promise/service.ts @@ -1,7 +1,7 @@ import { readFile, rm } from "node:fs/promises" import { homedir } from "node:os" import { join } from "node:path" -import type { DiscoverOptions, Endpoint, Info, EnsureOptions, EnsureReason, StopOptions } from "../service.js" +import type { DiscoverOptions, Endpoint, Info, EnsureOptions, StopOptions } from "../service.js" import { contenderFailure, contenderFinished, @@ -49,7 +49,7 @@ async function ensureService(options: EnsureOptions, forceReplacement: boolean): let lastSpawn = 0 let spawnDelay = timing.spawnDelay - const announce = (reason: EnsureReason, previousVersion?: string) => { + const announce = (reason: "missing" | "version-mismatch", previousVersion?: string) => { if (announced) return announced = true options.onStart?.(reason, previousVersion) @@ -95,7 +95,7 @@ async function ensureService(options: EnsureOptions, forceReplacement: boolean): if (!replacing && compatible && service.state === "failed") throw new Error("Background service failed to start") if (replacing || !compatible) { - announce(replacing ? "replacement" : "version-mismatch", service.version) + announce("version-mismatch", service.version) if (!service.legacy && service.state === "ready") await PtyHandoff.prepare(options.file ?? fallback(), service.info, timing.requestTimeout) else { diff --git a/packages/client/src/service.ts b/packages/client/src/service.ts index 779c5f5863..1db78885aa 100644 --- a/packages/client/src/service.ts +++ b/packages/client/src/service.ts @@ -22,7 +22,7 @@ export type DiscoverOptions = { } /** Reason ensuring the service requires a new process. */ -export type EnsureReason = "missing" | "version-mismatch" | "replacement" +export type EnsureReason = "missing" | "version-mismatch" /** Options used to ensure the local OpenCode service is running. */ export type EnsureOptions = DiscoverOptions & {