Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
})
}

export function tui(input: { url: string; args: Args; onExit?: () => Promise<void> }) {
export function tui(input: { url: string; args: Args; stdin?: NodeJS.ReadStream; onExit?: () => Promise<void> }) {
// promise to prevent immediate exit
return new Promise<void>(async (resolve) => {
const mode = await getTerminalBackgroundColor()
Expand Down Expand Up @@ -138,6 +138,7 @@ export function tui(input: { url: string; args: Args; onExit?: () => Promise<voi
gatherStats: false,
exitOnCtrlC: false,
useKittyKeyboard: true,
stdin: input.stdin,
},
)
})
Expand Down
16 changes: 15 additions & 1 deletion packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { type rpc } from "./worker"
import path from "path"
import { UI } from "@/cli/ui"
import { iife } from "@/util/iife"
import fs from "fs/promises"
import tty from "tty"

declare global {
const OPENCODE_WORKER_PATH: string
Expand Down Expand Up @@ -94,8 +96,19 @@ export const TuiThreadCommand = cmd({
const prompt = await iife(async () => {
const piped = !process.stdin.isTTY ? await Bun.stdin.text() : undefined
if (!args.prompt) return piped
return piped ? piped + "\n" + args.prompt : args.prompt
return piped ? args.prompt + "\n" + piped : args.prompt
})

let stdin: NodeJS.ReadStream
try {
stdin = process.stdin.isTTY ? process.stdin : new tty.ReadStream((await fs.open("/dev/tty", "r")).fd)
} catch (err) {
console.error(
"Failed to open /dev/tty for input. Prompt piping from stdin might not be supported on your platform.",
)
process.exit(1)
}

await tui({
url: server.url,
args: {
Expand All @@ -105,6 +118,7 @@ export const TuiThreadCommand = cmd({
model: args.model,
prompt,
},
stdin,
onExit: async () => {
await client.call("shutdown", undefined)
},
Expand Down