Skip to content

Commit 856e1e2

Browse files
committed
fix pty builds
1 parent bef4fdf commit 856e1e2

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

packages/opencode/src/pty/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1-
import { spawn, type IPty } from "bun-pty"
1+
import { type IPty } from "bun-pty"
22
import z from "zod"
33
import { Identifier } from "../id/id"
44
import { Log } from "../util/log"
55
import { Bus } from "../bus"
66
import type { WSContext } from "hono/ws"
77
import { Instance } from "../project/instance"
88
import { shell } from "@opencode-ai/util/shell"
9+
import { lazy } from "@opencode-ai/util/lazy"
10+
import {} from "process"
911

1012
export namespace Pty {
1113
const log = Log.create({ service: "pty" })
1214

15+
const pty = lazy(async () => {
16+
const path = require(
17+
`bun-pty/rust-pty/target/release/${
18+
process.platform === "win32"
19+
? "rust_pty.dll"
20+
: process.platform === "linux" && process.arch === "x64"
21+
? "librust_pty.so"
22+
: process.platform === "darwin" && process.arch === "x64"
23+
? "librust_pty.dylib"
24+
: process.platform === "darwin" && process.arch === "arm64"
25+
? "librust_pty_arm64.dylib"
26+
: process.platform === "linux" && process.arch === "arm64"
27+
? "librust_pty_arm64.so"
28+
: ""
29+
}`,
30+
)
31+
console.log(path)
32+
process.env.BUN_PTY_LIB = path
33+
const { spawn } = await import("bun-pty")
34+
return spawn
35+
})
36+
1337
export const Info = z
1438
.object({
1539
id: Identifier.schema("pty"),
@@ -91,6 +115,7 @@ export namespace Pty {
91115
const env = { ...process.env, ...input.env } as Record<string, string>
92116
log.info("creating session", { id, cmd: command, args, cwd })
93117

118+
const spawn = await pty()
94119
const ptyProcess = spawn(command, args, {
95120
name: "xterm-256color",
96121
cwd,

0 commit comments

Comments
 (0)