diff options
| author | Dax Raad <[email protected]> | 2026-03-05 22:08:50 -0500 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2026-03-05 22:08:50 -0500 |
| commit | 7e280983654f7943086263b2fe352c05d24fdb4e (patch) | |
| tree | e877326e7d7f6b855bad38573c88db032b03c397 /packages | |
| parent | ae5c9ed3dd7a393e540643f3ecc79b9dea793ecc (diff) | |
| download | opencode-7e280983654f7943086263b2fe352c05d24fdb4e.tar.gz opencode-7e280983654f7943086263b2fe352c05d24fdb4e.zip | |
refactor: use node:stream/consumers for stdin reading
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/cli/cmd/run.ts | 10 | ||||
| -rw-r--r-- | packages/opencode/src/cli/cmd/tui/thread.ts | 9 |
2 files changed, 4 insertions, 15 deletions
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index be546beff..d74eb2aa4 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -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") diff --git a/packages/opencode/src/cli/cmd/tui/thread.ts b/packages/opencode/src/cli/cmd/tui/thread.ts index cca96dd8c..57acfd199 100644 --- a/packages/opencode/src/cli/cmd/tui/thread.ts +++ b/packages/opencode/src/cli/cmd/tui/thread.ts @@ -3,6 +3,7 @@ import { tui } from "./app" import { Rpc } from "@/util/rpc" import { type rpc } from "./worker" import path from "path" +import { text as streamText } from "node:stream/consumers" import { fileURLToPath } from "url" import { UI } from "@/cli/ui" import { Log } from "@/util/log" @@ -53,13 +54,7 @@ async function target() { } async function input(value?: string) { - 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"))) - }) + const piped = process.stdin.isTTY ? undefined : await streamText(process.stdin) if (!value) return piped if (!piped) return value return piped + "\n" + value |
