refactor: use node:stream/consumers for stdin reading

This commit is contained in:
Dax Raad
2026-03-05 22:08:50 -05:00
parent ae5c9ed3dd
commit 7e28098365
2 changed files with 4 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ import { cmd } from "./cmd"
import { Flag } from "../../flag/flag"
import { bootstrap } from "../bootstrap"
import { EOL } from "os"
import { text as streamText } from "node:stream/consumers"
import { Filesystem } from "../../util/filesystem"
import { createOpencodeClient, type Message, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
import { Server } from "../../server/server"
@@ -337,14 +338,7 @@ export const RunCommand = cmd({
}
}
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 (!process.stdin.isTTY) message += "\n" + (await streamText(process.stdin))
if (message.trim().length === 0 && !args.command) {
UI.error("You must provide a message or a command")