Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/persistent-pty/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
10 changes: 1 addition & 9 deletions packages/core/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down Expand Up @@ -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)),
),
)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/fixture/persistent-pty-daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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: [] }),
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/persistent-pty-daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/shell-daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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([])
}),
)
Expand Down
14 changes: 1 addition & 13 deletions packages/core/test/tool-shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down
Loading