mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-11-22 23:47:02 -10:00
refactor(client): reuse mismatch reason for replacement
This commit is contained in:
1 parent
7cee402232
commit
d7e642b80d
4 files changed
+12
-12
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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<LocalService>()
|
||||
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),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 & {
|
||||
|
||||
Reference in new issue
Block a user