Skip to content

The open source coding agent.

TypeScript

refactor: replace Bun.stdin.text with Node.js stream reading

Dax Raadae5c9ed3dd7a
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts
index 61bc609bb7c..be546beff8a 100644
--- a/packages/opencode/src/cli/cmd/run.ts
+++ b/packages/opencode/src/cli/cmd/run.ts
@@ -337,7 +337,14 @@ export const RunCommand = cmd({
}
}
- if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
+ if (!process.stdin.isTTY) {
+ const stdinText = await new Promise<string>((resolve) => {
+ const chunks: Buffer[] = []
+ process.stdin.on("data", (chunk) => chunks.push(chunk))
+ process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")))
+ })
+ message += "\n" + stdinText
+ }
if (message.trim().length === 0 && !args.command) {
UI.error("You must provide a message or a command")
diff --git a/packages/opencode/src/cli/cmd/tui/thread.ts b/packages/opencode/src/cli/cmd/tui/thread.ts
index f53cc392552..cca96dd8c6b 100644
--- a/packages/opencode/src/cli/cmd/tui/thread.ts
+++ b/packages/opencode/src/cli/cmd/tui/thread.ts
@@ -53,7 +53,13 @@ async function target() {
}
async function input(value?: string) {
- const piped = process.stdin.isTTY ? undefined : await Bun.stdin.text()
+ const piped = process.stdin.isTTY
+ ? undefined
+ : await new Promise<string>((resolve) => {
+ const chunks: Buffer[] = []
+ process.stdin.on("data", (chunk) => chunks.push(chunk))
+ process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")))
+ })
if (!value) return piped
if (!piped) return value
return piped + "\n" + value