GeezerVison is showing github.com — feat(core): run local Windows shell commands in the process daemon (#… · drpr/opencode@63dd3f1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bun.lock +12-12Lines changed: 12 additions & 12 deletions Collapse file Copy file name to clipboardExpand all lines: packages/cli/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 32 | 32 | "@effect/platform-node": "catalog:", | 33 | 33 | "@opencode/client": "workspace:*", | 34 | 34 | "@opencode/plugin": "workspace:*", | 35 | | - "@opencode/pty": "0.5.0", | | 35 | + "@opencode/pty": "0.5.2", | 36 | 36 | "@opencode/schema": "workspace:*", | 37 | 37 | "@opencode/server": "workspace:*", | 38 | 38 | "@opencode/tui": "workspace:*", | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 104 | 104 | "@modelcontextprotocol/client": "2.4.0", | 105 | 105 | "@modelcontextprotocol/core": "2.4.0", | 106 | 106 | "@modelcontextprotocol/server": "2.4.0", | 107 | | - "@opencode/pty": "0.5.0", | | 107 | + "@opencode/pty": "0.5.2", | 108 | 108 | "@opencode/ai": "workspace:*", | 109 | 109 | "@opencode/codemode": "workspace:*", | 110 | 110 | "@opencode/plugin": "workspace:*", | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/shell.ts +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,8 +141,8 @@ type Ended = { | 141 | 141 | * here; callers (e.g. `ShellTool`) own that association and store the shell ID. | 142 | 142 | * | 143 | 143 | * Local commands run in the process daemon when it is available (`Daemon`), so they outlive a planned server | 144 | | - * restart: the next server takes them back. Remote workspaces, Windows and an unavailable daemon keep spawning | 145 | | - * them from the server. | | 144 | + * restart: the next server takes them back. Remote workspaces and an unavailable daemon keep spawning them from | | 145 | + * the server. | 146 | 146 | */ | 147 | 147 | export interface Interface { | 148 | 148 | readonly create: <E = never, R = never>( | @@ -615,12 +615,9 @@ const layer = () => | 615 | 615 | // Commands this server spawned for the Location; daemon commands live in `runs`, owned by the server. | 616 | 616 | const commands = new Map<Shell.ID, Spawned>() | 617 | 617 | const exitOrder: Shell.ID[] = [] | 618 | | - // Remote workspaces and Windows keep spawning commands from the server. Taken back before the service is | 619 | | - // returned, so session restart recovery sees them. | | 618 | + // Take local commands back before returning the service so session restart recovery sees them. | 620 | 619 | const runs = | 621 | | - location.workspaceID === undefined && process.platform !== "win32" && PersistentPty.available | 622 | | - ? yield* daemon.at(location) | 623 | | - : undefined | | 620 | + location.workspaceID === undefined && PersistentPty.available ? yield* daemon.at(location) : undefined | 624 | 621 |
| 625 | 622 | const outputDir = path.join(global.data, DIRECTORY, location.project.id) | 626 | 623 | const { mkdir, unlink, stat } = yield* Effect.promise(() => import("fs/promises")) | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/persistent-pty-session.test.ts +25-31Lines changed: 25 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect } from "bun:test" | | 2 | +import path from "node:path" | 2 | 3 | import { Effect, Fiber, Layer, Option, Stream } from "effect" | 3 | 4 | import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder" | 4 | 5 | import { LayerNode } from "@opencode/util/effect/layer-node" | @@ -110,25 +111,24 @@ describe("PersistentPty rename", () => { | 110 | 111 | ) | 111 | 112 | }) | 112 | 113 |
| 113 | | -// Pipe mode is Unix-only: Windows daemons reject create_pipe, so OpenCode keeps spawning shell commands there. | 114 | | -describe.skipIf(process.platform === "win32")("PersistentPty pipe processes", () => { | 115 | | - const input = { | 116 | | - program: "/bin/sh", | 117 | | - args: ["-c", "echo hi"], | 118 | | - cwd: "/tmp", | 119 | | - env: { PATH: "/usr/bin" }, | 120 | | - groupID: "proj_test", | 121 | | - outputPath: "/tmp/sh_test.out", | 122 | | - metadata: { id: "sh_test", command: "echo hi" }, | 123 | | - } | | 114 | +const pipeInput = (cwd: string) => ({ | | 115 | + program: process.execPath, | | 116 | + args: ["--version"], | | 117 | + cwd, | | 118 | + env: { TEST: "1" }, | | 119 | + groupID: "proj_test", | | 120 | + outputPath: path.join(cwd, "sh_test.out"), | | 121 | + metadata: { id: "sh_test", command: "--version" }, | | 122 | +}) | 124 | 123 |
| | 124 | +describe("PersistentPty pipe processes", () => { | 125 | 125 | it.live("knows a handoff is prepared until a shutdown or until its ticket expires", () => | 126 | 126 | Effect.gen(function* () { | 127 | 127 | const daemon = yield* fakeDaemon() | 128 | 128 | yield* Effect.gen(function* () { | 129 | 129 | const pty = yield* PersistentPty.Service | 130 | 130 | expect(pty.handoffPrepared()).toBe(false) | 131 | | - yield* pty.createPipe(input) | | 131 | + yield* pty.createPipe(pipeInput(daemon.options.root)) | 132 | 132 | expect(yield* pty.handoff()).not.toBeNull() | 133 | 133 | expect(pty.handoffPrepared()).toBe(true) | 134 | 134 | // Abandoned by a shutdown. | @@ -141,7 +141,7 @@ describe.skipIf(process.platform === "win32")("PersistentPty pipe processes", () | 141 | 141 | expiring.handoffTTL.ms = 50 | 142 | 142 | yield* Effect.gen(function* () { | 143 | 143 | const pty = yield* PersistentPty.Service | 144 | | - yield* pty.createPipe(input) | | 144 | + yield* pty.createPipe(pipeInput(expiring.options.root)) | 145 | 145 | expect(yield* pty.handoff()).not.toBeNull() | 146 | 146 | expect(pty.handoffPrepared()).toBe(true) | 147 | 147 | yield* Effect.sleep(80) | @@ -155,20 +155,21 @@ describe.skipIf(process.platform === "win32")("PersistentPty pipe processes", () | 155 | 155 | const daemon = yield* fakeDaemon() | 156 | 156 | yield* Effect.gen(function* () { | 157 | 157 | const pty = yield* PersistentPty.Service | | 158 | + const input = pipeInput(daemon.options.root) | 158 | 159 | const created = yield* pty.createPipe(input) | 159 | 160 | expect(daemon.requests.at(-1)).toEqual({ | 160 | 161 | op: "create_pipe", | 161 | | - program: "/bin/sh", | 162 | | - args: ["-c", "echo hi"], | 163 | | - cwd: "/tmp", | 164 | | - env: { PATH: "/usr/bin" }, | | 162 | + program: input.program, | | 163 | + args: input.args, | | 164 | + cwd: input.cwd, | | 165 | + env: input.env, | 165 | 166 | group_id: "proj_test", | 166 | | - output_path: "/tmp/sh_test.out", | 167 | | - metadata: { id: "sh_test", command: "echo hi" }, | | 167 | + output_path: input.outputPath, | | 168 | + metadata: input.metadata, | 168 | 169 | }) | 169 | 170 | expect(created).toMatchObject({ | 170 | 171 | groupID: "proj_test", | 171 | | - outputPath: "/tmp/sh_test.out", | | 172 | + outputPath: input.outputPath, | 172 | 173 | lifecycle: { status: "running" }, | 173 | 174 | metadata: input.metadata, | 174 | 175 | exitedAt: undefined, | @@ -210,7 +211,7 @@ describe.skipIf(process.platform === "win32")("PersistentPty pipe processes", () | 210 | 211 | title: "test", | 211 | 212 | env: {}, | 212 | 213 | }) | 213 | | - const pipe = yield* pty.createPipe(input) | | 214 | + const pipe = yield* pty.createPipe(pipeInput(directory.path)) | 214 | 215 |
| 215 | 216 | expect((yield* pty.list()).map((item) => item.id)).toEqual([terminal.id]) | 216 | 217 | expect((yield* pty.listPipes()).map((item) => item.id)).toEqual([pipe.id]) | @@ -225,6 +226,7 @@ describe.skipIf(process.platform === "win32")("PersistentPty pipe processes", () | 225 | 226 | const daemon = yield* fakeDaemon() | 226 | 227 | yield* Effect.gen(function* () { | 227 | 228 | const pty = yield* PersistentPty.Service | | 229 | + const input = pipeInput(daemon.options.root) | 228 | 230 | expect(yield* Effect.flip(pty.createPipe({ ...input, cwd: "relative" }))).toEqual( | 229 | 231 | new PersistentPty.RequestError({ message: "cwd must be absolute" }), | 230 | 232 | ) | @@ -278,21 +280,13 @@ const layer = (daemon: { readonly options: PersistentPty.Options }) => | 278 | 280 | ], | 279 | 281 | ) | 280 | 282 |
| 281 | | -describe.skipIf(process.platform === "win32")("PersistentPty handoff", () => { | | 283 | +describe("PersistentPty handoff", () => { | 282 | 284 | it.live("prepares a handoff more than once on the same owner connection", () => | 283 | 285 | Effect.gen(function* () { | 284 | 286 | const daemon = yield* fakeDaemon() | 285 | 287 | yield* Effect.gen(function* () { | 286 | 288 | const pty = yield* PersistentPty.Service | 287 | | - yield* pty.createPipe({ | 288 | | - program: "/bin/sh", | 289 | | - args: ["-c", "echo hi"], | 290 | | - cwd: "/tmp", | 291 | | - env: {}, | 292 | | - groupID: "proj_test", | 293 | | - outputPath: "/tmp/sh_handoff.out", | 294 | | - metadata: {}, | 295 | | - }) | | 289 | + yield* pty.createPipe(pipeInput(daemon.options.root)) | 296 | 290 | expect(yield* pty.handoff()).toMatchObject({ ticket: "next" }) | 297 | 291 | expect(yield* pty.handoff()).toMatchObject({ ticket: "next" }) | 298 | 292 | }).pipe(Effect.provide(layer(daemon))) | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/session-execution.test.ts +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -438,9 +438,6 @@ describe("SessionExecution lifecycle", () => { | 438 | 438 | ) | 439 | 439 | }) | 440 | 440 |
| 441 | | -// Shell commands only run in the process daemon off Windows (pipe mode is Unix-only), so the daemon shell cases skip there. | 442 | | -const daemonLive = process.platform === "win32" ? it.live.skip : it.live | 443 | | - | 444 | 441 | describe("SessionRestart background recovery", () => { | 445 | 442 | it.effect("keeps shell owners idle until a user prompt delivers recovered notices exactly once", () => | 446 | 443 | Effect.gen(function* () { | @@ -530,7 +527,7 @@ describe("SessionRestart background recovery", () => { | 530 | 527 | }), | 531 | 528 | ) | 532 | 529 |
| 533 | | - daemonLive("counts a suspended parent's restart attempt before its shell-woken child can wake it", () => | | 530 | + it.live("counts a suspended parent's restart attempt before its shell-woken child can wake it", () => | 534 | 531 | Effect.gen(function* () { | 535 | 532 | const db = yield* Database.Service | 536 | 533 | const jobs = yield* Job.Service | @@ -608,7 +605,7 @@ describe("SessionRestart background recovery", () => { | 608 | 605 | }), | 609 | 606 | ) | 610 | 607 |
| 611 | | - daemonLive("watches shell jobs whose commands survived the restart", () => | | 608 | + it.live("watches shell jobs whose commands survived the restart", () => | 612 | 609 | Effect.gen(function* () { | 613 | 610 | const database = yield* Database.Service | 614 | 611 | const store = yield* SessionStore.Service | @@ -670,7 +667,7 @@ describe("SessionRestart background recovery", () => { | 670 | 667 | }), | 671 | 668 | ) | 672 | 669 |
| 673 | | - daemonLive("settles a shell call a killed server left running as moved to the background", () => | | 670 | + it.live("settles a shell call a killed server left running as moved to the background", () => | 674 | 671 | Effect.gen(function* () { | 675 | 672 | const database = yield* Database.Service | 676 | 673 | const store = yield* SessionStore.Service | @@ -757,7 +754,7 @@ describe("SessionRestart background recovery", () => { | 757 | 754 | ) | 758 | 755 |
| 759 | 756 | for (const exited of [false, true]) | 760 | | - daemonLive( | | 757 | + it.live( | 761 | 758 | `reattaches once a ${exited ? "finished" : "running"} shell a killed server backgrounded without settling its call`, | 762 | 759 | () => | 763 | 760 | Effect.gen(function* () { | @@ -818,7 +815,7 @@ describe("SessionRestart background recovery", () => { | 818 | 815 | }), | 819 | 816 | ) | 820 | 817 |
| 821 | | - daemonLive("settles a recovered child's unsettled shell call before the child resumes", () => | | 818 | + it.live("settles a recovered child's unsettled shell call before the child resumes", () => | 822 | 819 | Effect.gen(function* () { | 823 | 820 | const database = yield* Database.Service | 824 | 821 | const store = yield* SessionStore.Service | |
|