|
1 | | -import { spawn, type IPty } from "bun-pty" |
| 1 | +import { type IPty } from "bun-pty" |
2 | 2 | import z from "zod" |
3 | 3 | import { Identifier } from "../id/id" |
4 | 4 | import { Log } from "../util/log" |
5 | 5 | import { Bus } from "../bus" |
6 | 6 | import type { WSContext } from "hono/ws" |
7 | 7 | import { Instance } from "../project/instance" |
8 | 8 | import { shell } from "@opencode-ai/util/shell" |
| 9 | +import { lazy } from "@opencode-ai/util/lazy" |
| 10 | +import {} from "process" |
9 | 11 |
|
10 | 12 | export namespace Pty { |
11 | 13 | const log = Log.create({ service: "pty" }) |
12 | 14 |
|
| 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 | + |
13 | 37 | export const Info = z |
14 | 38 | .object({ |
15 | 39 | id: Identifier.schema("pty"), |
@@ -91,6 +115,7 @@ export namespace Pty { |
91 | 115 | const env = { ...process.env, ...input.env } as Record<string, string> |
92 | 116 | log.info("creating session", { id, cmd: command, args, cwd }) |
93 | 117 |
|
| 118 | + const spawn = await pty() |
94 | 119 | const ptyProcess = spawn(command, args, { |
95 | 120 | name: "xterm-256color", |
96 | 121 | cwd, |
|
0 commit comments