diff --git a/bun.lock b/bun.lock index 6c94e94150ab..065c1f754df8 100644 --- a/bun.lock +++ b/bun.lock @@ -118,7 +118,7 @@ "@effect/platform-node": "catalog:", "@opencode/client": "workspace:*", "@opencode/plugin": "workspace:*", - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@opencode/schema": "workspace:*", "@opencode/server": "workspace:*", "@opencode/tui": "workspace:*", @@ -227,7 +227,7 @@ "@opencode/codemode": "workspace:*", "@opencode/plugin": "workspace:*", "@opencode/plugin-browser": "workspace:*", - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@opencode/schema": "workspace:*", "@opencode/util": "workspace:*", "@parcel/watcher": "2.5.1", @@ -667,7 +667,7 @@ "devDependencies": { "@opencode/client": "workspace:*", "@opencode/plugin": "workspace:*", - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@tsconfig/bun": "catalog:", "@types/bun": "catalog:", "@typescript/native": "catalog:", @@ -1833,23 +1833,23 @@ "@opencode/protocol": ["@opencode/protocol@workspace:packages/protocol"], - "@opencode/pty": ["@opencode/pty@0.5.2", "", { "optionalDependencies": { "@opencode/pty-darwin-arm64": "0.5.2", "@opencode/pty-darwin-x64": "0.5.2", "@opencode/pty-linux-arm64-gnu": "0.5.2", "@opencode/pty-linux-arm64-musl": "0.5.2", "@opencode/pty-linux-x64-gnu": "0.5.2", "@opencode/pty-linux-x64-musl": "0.5.2", "@opencode/pty-win32-arm64": "0.5.2", "@opencode/pty-win32-x64": "0.5.2" }, "bin": { "opencode-pty": "bin/opencode-pty.js" } }, "sha512-SZrzOFZDQHvPndC+ZfDYB52qY/RFxeW0OmKeosSlm4I7tmdDxtvUYN/vy8yynh8678bL+1efbQGxhKa1nz0DCA=="], + "@opencode/pty": ["@opencode/pty@0.6.0", "", { "optionalDependencies": { "@opencode/pty-darwin-arm64": "0.6.0", "@opencode/pty-darwin-x64": "0.6.0", "@opencode/pty-linux-arm64-gnu": "0.6.0", "@opencode/pty-linux-arm64-musl": "0.6.0", "@opencode/pty-linux-x64-gnu": "0.6.0", "@opencode/pty-linux-x64-musl": "0.6.0", "@opencode/pty-win32-arm64": "0.6.0", "@opencode/pty-win32-x64": "0.6.0" }, "bin": { "opencode-pty": "bin/opencode-pty.js" } }, "sha512-H4sID90Vuj0AxRN+WFILS65xUZCrltFfRQF7kL8VG6DGyg7bUsNE9LZHgvoWecTWxSZ4HT5ZFd/wUx2eCLTL6w=="], - "@opencode/pty-darwin-arm64": ["@opencode/pty-darwin-arm64@0.5.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-CxlLA/+ruVwt+QGOQEnBxiIImgpYU9EdW7bjvA0m+qSDOrFc0hAHOD13Suq3B2JJQxSsj7IM3XicQqmJfqe32Q=="], + "@opencode/pty-darwin-arm64": ["@opencode/pty-darwin-arm64@0.6.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-KDDVvVVcJJlb5vqtzqs/os1DxNwviKV1iwfjODww9y6qAl/Dx/IFZnqlDjp7sTwrAmX2HnJgqIqhwSii+QFRIw=="], - "@opencode/pty-darwin-x64": ["@opencode/pty-darwin-x64@0.5.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-xn4W7y8D+93WM+5+VAwTsPJjw/U9TTEZJQdtIQqFwcCgPCQUylMGu4/xhFbyMllzSycZyysJuhV6CHq/J798zw=="], + "@opencode/pty-darwin-x64": ["@opencode/pty-darwin-x64@0.6.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-A97X8lI7EvEcLhIEPHi79hKZDlBpjO2hopL0ehphjzzQpoS8iCivY+6lo2+9Lf+B/sAHVQYWE4jqpymdM4l6nw=="], - "@opencode/pty-linux-arm64-gnu": ["@opencode/pty-linux-arm64-gnu@0.5.2", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-0Kg1477t9VYHLkaOStiDuoC8S3qHH92ZY/QEgNSOavgkCAAbSEU0NrkIBhEi3Gnw5+ElvfgVcLzEwcM5cfiYAA=="], + "@opencode/pty-linux-arm64-gnu": ["@opencode/pty-linux-arm64-gnu@0.6.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-XMLczimkpuY1fYxn1UmybhbRt7bvDL33qY3NcJq0xE3mNhFTT75SEneduG+3i56+WmIa2QXLrbvubvOWk/u9CQ=="], - "@opencode/pty-linux-arm64-musl": ["@opencode/pty-linux-arm64-musl@0.5.2", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-ZNk4nBooiVCvkB8cCfwn2nDV5OQHdFk/MfRQzBfwk28LakM1YC4lSwZPzY0McvFVjUILie9UEKntHRzgPaDBcA=="], + "@opencode/pty-linux-arm64-musl": ["@opencode/pty-linux-arm64-musl@0.6.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-JjC0D3xhdr0ArDydPg1j0ubo0qypeGPM7fLYbjpvAn3HVgFwdHvhX8DmUqjZHsCtiBVZLGsu5o51vluLLN47/g=="], - "@opencode/pty-linux-x64-gnu": ["@opencode/pty-linux-x64-gnu@0.5.2", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-iLEq9nWOKfm9iWqDGlhqcx+SSLFqBz3toX83n/W+MSlxWg5048HzlGd/3RxY04sxmI6dlg/Ygz3KqP3bCgfusg=="], + "@opencode/pty-linux-x64-gnu": ["@opencode/pty-linux-x64-gnu@0.6.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-OdeuIfAzBM78DNTBoqcwoDanmlokHg+/wPIIB38QbvTms1mNlbUZhILBOw7ra9EwUfSOy6jfcUlrBFLMKj1aOA=="], - "@opencode/pty-linux-x64-musl": ["@opencode/pty-linux-x64-musl@0.5.2", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-jBIw7oimeoTXoHH4yvtVFoPZGU1Rx+kdTVU8HVFGwCDNmeP4hI+R7QhF/pEsKZxzykTskR5x9u5ciiVJ5WEnMg=="], + "@opencode/pty-linux-x64-musl": ["@opencode/pty-linux-x64-musl@0.6.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-8Vm4xBxMQZK212ccHdhVtkAgumueVODYJuazsXzw0yOp5jZhuGCNdxSHeTCItM/SuvoVgVV7c0yySrwszTXwTg=="], - "@opencode/pty-win32-arm64": ["@opencode/pty-win32-arm64@0.5.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-giPMQUcSyoe2z6wQN6MKhRgu4rVv/xqscX8qOVt2lu7yfRNfviPFVY0qFPGOcu1L3e+DT5VrIo2QZeRBeV1Bdw=="], + "@opencode/pty-win32-arm64": ["@opencode/pty-win32-arm64@0.6.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-lYPHn9pqM/0dpuDw+aqAx4k88oHEGM4lNvleQf0Pw+LF+aWTQjHtnx3LoUJEKAlYFOuCbNvLUr4SfAKwhPLsGQ=="], - "@opencode/pty-win32-x64": ["@opencode/pty-win32-x64@0.5.2", "", { "os": "win32", "cpu": "x64" }, "sha512-hXdQWx+gHhQMRovDS3Fm0n4LuvSgLxRqEdicpVQzjjCTPYBMSBysWYRheQ2ydZlP0GCQ2Ymoi0dixgAHTYHO8A=="], + "@opencode/pty-win32-x64": ["@opencode/pty-win32-x64@0.6.0", "", { "os": "win32", "cpu": "x64" }, "sha512-Qb0dqKJyRqe8Q2olfiEc47UybtIUEH12SWag0PkVqDqXabWA3urvcO4+hhD4g/WDkm9F6lPzafiSddtjb2HMtA=="], "@opencode/schema": ["@opencode/schema@workspace:packages/schema"], diff --git a/packages/cli/package.json b/packages/cli/package.json index 232259ba3265..991ed97f001c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,7 +32,7 @@ "@effect/platform-node": "catalog:", "@opencode/client": "workspace:*", "@opencode/plugin": "workspace:*", - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@opencode/schema": "workspace:*", "@opencode/server": "workspace:*", "@opencode/tui": "workspace:*", diff --git a/packages/core/package.json b/packages/core/package.json index d036299f6879..eb9934ccc3fa 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -110,7 +110,7 @@ "@modelcontextprotocol/client": "2.4.0", "@modelcontextprotocol/core": "2.4.0", "@modelcontextprotocol/server": "2.4.0", - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@opencode/ai": "workspace:*", "@opencode/codemode": "workspace:*", "@opencode/plugin": "workspace:*", diff --git a/packages/core/src/persistent-pty/daemon.ts b/packages/core/src/persistent-pty/daemon.ts index 95382daf0a41..09649b37e287 100644 --- a/packages/core/src/persistent-pty/daemon.ts +++ b/packages/core/src/persistent-pty/daemon.ts @@ -5,7 +5,7 @@ import path from "node:path" import { Cause, Data, Duration, Effect, Schema, Semaphore } from "effect" import type { Handoff } from "@opencode/schema/persistent-pty" -const ProtocolVersion = 8 +const ProtocolVersion = 9 const MaxFrameBytes = 8 * 1024 * 1024 const Lifecycle = Schema.Union([ diff --git a/packages/core/src/shell.ts b/packages/core/src/shell.ts index 383becbd6195..c33a3784c99f 100644 --- a/packages/core/src/shell.ts +++ b/packages/core/src/shell.ts @@ -327,8 +327,7 @@ const daemonLayer = Layer.effect( if (run.stopping) yield* Fiber.interrupt(run.stopping) // Stop waiting first, so forgetting the process is not mistaken for losing it. if (run.wait) yield* Fiber.interrupt(run.wait) - // Forget the process before deleting its file. This also kills what is left of its group, even after a - // successful exit, which a spawned command would leave running: the daemon cannot forget a process otherwise. + // Terminate a running command or just forget a finished one before deleting its file. yield* pty.terminatePipe(run.process).pipe(Effect.ignore) yield* Effect.promise(() => unlink(run.info.file).catch(() => {})) yield* Deferred.fail(run.done, new NotFoundError({ id })) @@ -431,13 +430,6 @@ const daemonLayer = Layer.effect( ), ), ), - // Like spawned commands: what a failed command left running in its group is stopped with it, while a - // successful one may leave background processes (`cmd &`) behind. - Effect.tap((outcome) => - outcome.status === "exited" && outcome.exit !== undefined && outcome.exit !== 0 - ? pty.signalPipe(run.process, "SIGTERM").pipe(Effect.ignore) - : Effect.void, - ), Effect.flatMap((outcome) => finish(run, outcome)), ), ) diff --git a/packages/core/test/fixture/persistent-pty-daemon.ts b/packages/core/test/fixture/persistent-pty-daemon.ts index e692d52411d9..6b4ef4c7a410 100644 --- a/packages/core/test/fixture/persistent-pty-daemon.ts +++ b/packages/core/test/fixture/persistent-pty-daemon.ts @@ -5,7 +5,7 @@ import os from "node:os" import path from "node:path" import { Effect } from "effect" -export const pong = { type: "pong", instance_id: "test", pid: process.pid, protocol: 8, features: [] } +export const pong = { type: "pong", instance_id: "test", pid: process.pid, protocol: 9, features: [] } export function temporaryDirectory() { return Effect.acquireRelease( @@ -105,7 +105,7 @@ export function frame(value: object) { export function writeRegistration(directory: string, socket: string, instance = "test", token = "test") { return writeFile( path.join(directory, "service.json"), - JSON.stringify({ instance_id: instance, pid: process.pid, protocol: 8, socket, token, features: [] }), + JSON.stringify({ instance_id: instance, pid: process.pid, protocol: 9, socket, token, features: [] }), ) } diff --git a/packages/core/test/persistent-pty-daemon.test.ts b/packages/core/test/persistent-pty-daemon.test.ts index b3f6aae45831..b5e61eda8640 100644 --- a/packages/core/test/persistent-pty-daemon.test.ts +++ b/packages/core/test/persistent-pty-daemon.test.ts @@ -235,7 +235,7 @@ it.live("rejects incompatible daemons without replacing or killing them", () => const optional = yield* Effect.flip(daemon.requestIfRunning({ op: "list" })) expect(optional).toMatchObject({ kind: "protocol", - message: "opencode-pty protocol mismatch: daemon=7, client=8", + message: "opencode-pty protocol mismatch: daemon=7, client=9", pid: existing.pid, }) diff --git a/packages/core/test/shell-daemon.test.ts b/packages/core/test/shell-daemon.test.ts index e5a714260bb1..641e5a6e690e 100644 --- a/packages/core/test/shell-daemon.test.ts +++ b/packages/core/test/shell-daemon.test.ts @@ -250,7 +250,7 @@ describe("Shell on the process daemon", () => { }), ) - it.live("stops what a failed command left in its group, and leaves a successful one's", () => + it.live("records successful and failed exits without signalling a finished command", () => Effect.gen(function* () { const env = yield* daemonShells() yield* env.withShell(env.directory, (shell) => @@ -262,7 +262,7 @@ describe("Shell on the process daemon", () => { env.daemon.exit(2, 3) expect(yield* shell.wait(failed.id)).toMatchObject({ status: "exited", exit: 3 }) expect(yield* shell.wait(succeeded.id)).toMatchObject({ status: "exited", exit: 0 }) - expect(env.signals(2)).toEqual(["SIGTERM"]) + expect(env.signals(2)).toEqual([]) expect(env.signals(1)).toEqual([]) }), ) diff --git a/packages/core/test/tool-shell.test.ts b/packages/core/test/tool-shell.test.ts index 2518b6bf3f49..0c8e7acd5d2e 100644 --- a/packages/core/test/tool-shell.test.ts +++ b/packages/core/test/tool-shell.test.ts @@ -232,18 +232,6 @@ const call = (input: typeof ShellTool.Input.Type, id = "call-shell") => ({ const isWindows = process.platform === "win32" -// The process daemon keeps a finished command's zombie until the command is forgotten. -const running = (pid: number) => { - try { - process.kill(pid, 0) - } catch { - return false - } - return !Bun.spawnSync(["ps", "-o", "stat=", "-p", String(pid)]) - .stdout.toString() - .trim() - .startsWith("Z") -} const cwdCommand = isWindows ? "(Get-Location).Path; Start-Sleep -Milliseconds 100" : "pwd" const helloCommand = isWindows ? "[Console]::Out.Write('hello'); Start-Sleep -Milliseconds 100" : "printf hello" const stderrCommand = isWindows @@ -2044,7 +2032,7 @@ describe("ShellTool", () => { }) const pid = info.pid if (pid === undefined) throw new Error("Expected shell PID") - expect(running(pid)).toBe(false) + expect(() => process.kill(pid, 0)).toThrow(expect.objectContaining({ code: "ESRCH" })) }), (info) => Effect.try(() => { diff --git a/packages/server/package.json b/packages/server/package.json index a598638a2aae..d29459954004 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -37,7 +37,7 @@ "effect": "catalog:" }, "devDependencies": { - "@opencode/pty": "0.5.2", + "@opencode/pty": "0.6.0", "@opencode/client": "workspace:*", "@opencode/plugin": "workspace:*", "@tsconfig/bun": "catalog:",