mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
fix(cli): stop opencode run from leaving a background service running (#61564)
This commit is contained in:
committed by
GitHub
Unverified
parent
55276f2108
commit
d85283496f
@@ -7,7 +7,8 @@ export default Runtime.handler(Commands.commands.run, (input) =>
|
||||
Effect.gen(function* () {
|
||||
const { reportRunError, runNonInteractive } = yield* Effect.promise(() => import("../../run/run"))
|
||||
const separator = process.argv.indexOf("--", 2)
|
||||
const server = yield* ServerConnection.resolve().pipe(
|
||||
// A one-off run uses the background service when it is already up, but never leaves a new one running.
|
||||
const server = yield* ServerConnection.resolve({ autostart: false }).pipe(
|
||||
Effect.tapError((error) => Effect.logError("run could not resolve its server", { cause: error })),
|
||||
Effect.catch((error) => Effect.sync(() => reportRunError(input, error.message))),
|
||||
)
|
||||
|
||||
@@ -12,6 +12,8 @@ export type Args = {
|
||||
readonly server?: string
|
||||
readonly standalone?: boolean
|
||||
readonly mismatch?: "replace" | "ignore" | "error"
|
||||
/** Start the background service when none is running. When false, use a standalone server instead. */
|
||||
readonly autostart?: boolean
|
||||
readonly onStart?: EnsureOptions["onStart"]
|
||||
}
|
||||
|
||||
@@ -50,6 +52,11 @@ export const resolve = Effect.fn("cli.server-connection.resolve")(function* (arg
|
||||
|
||||
const mismatch = args.mismatch ?? "ignore"
|
||||
const options = yield* ServiceConfig.options({ checkVersion: mismatch !== "ignore" })
|
||||
if (args.autostart === false) {
|
||||
const endpoint = yield* Service.discover({ ...options, version: undefined })
|
||||
if (!endpoint) return { endpoint: yield* Standalone.start() } satisfies Resolved
|
||||
return { endpoint, service: managedService(options) } satisfies Resolved
|
||||
}
|
||||
return {
|
||||
endpoint: yield* resolveManaged({ ...options, onStart: args.onStart }, mismatch),
|
||||
service: managedService(options),
|
||||
|
||||
@@ -51,6 +51,10 @@ test("resolution groups Effect-native lifecycle operations only for the managed
|
||||
expect(Effect.isEffect(resolved.service.restart())).toBe(true)
|
||||
expect(await runPromise(resolved.service.reconnect())).toEqual(resolved.endpoint)
|
||||
|
||||
const existing = await runPromise(ServerConnection.resolve({ autostart: false }))
|
||||
expect(existing.endpoint.url).toBe(server.url.toString())
|
||||
expect(existing.service).toBeDefined()
|
||||
|
||||
const explicit = await runPromise(ServerConnection.resolve({ server: server.url.toString() }))
|
||||
expect(explicit.endpoint.url).toBe(server.url.toString())
|
||||
expect(explicit.service).toBeUndefined()
|
||||
|
||||
Reference in New Issue
Block a user