mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-19 15:14:49 +00:00
refactor: use node:stream/consumers for stdin reading
This commit is contained in:
@@ -6,6 +6,7 @@ import { cmd } from "./cmd"
|
|||||||
import { Flag } from "../../flag/flag"
|
import { Flag } from "../../flag/flag"
|
||||||
import { bootstrap } from "../bootstrap"
|
import { bootstrap } from "../bootstrap"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
|
import { text as streamText } from "node:stream/consumers"
|
||||||
import { Filesystem } from "../../util/filesystem"
|
import { Filesystem } from "../../util/filesystem"
|
||||||
import { createOpencodeClient, type Message, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
|
import { createOpencodeClient, type Message, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
|
||||||
import { Server } from "../../server/server"
|
import { Server } from "../../server/server"
|
||||||
@@ -337,14 +338,7 @@ export const RunCommand = cmd({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.stdin.isTTY) {
|
if (!process.stdin.isTTY) message += "\n" + (await streamText(process.stdin))
|
||||||
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) {
|
if (message.trim().length === 0 && !args.command) {
|
||||||
UI.error("You must provide a message or a command")
|
UI.error("You must provide a message or a command")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { tui } from "./app"
|
|||||||
import { Rpc } from "@/util/rpc"
|
import { Rpc } from "@/util/rpc"
|
||||||
import { type rpc } from "./worker"
|
import { type rpc } from "./worker"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { text as streamText } from "node:stream/consumers"
|
||||||
import { fileURLToPath } from "url"
|
import { fileURLToPath } from "url"
|
||||||
import { UI } from "@/cli/ui"
|
import { UI } from "@/cli/ui"
|
||||||
import { Log } from "@/util/log"
|
import { Log } from "@/util/log"
|
||||||
@@ -53,13 +54,7 @@ async function target() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function input(value?: string) {
|
async function input(value?: string) {
|
||||||
const piped = process.stdin.isTTY
|
const piped = process.stdin.isTTY ? undefined : await streamText(process.stdin)
|
||||||
? 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 (!value) return piped
|
||||||
if (!piped) return value
|
if (!piped) return value
|
||||||
return piped + "\n" + value
|
return piped + "\n" + value
|
||||||
|
|||||||
Reference in New Issue
Block a user