Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
}

export function tui(input: {
stdin?: NodeJS.ReadStream,
url: string
sessionID?: string
model?: string
Expand Down Expand Up @@ -158,6 +159,7 @@ export function tui(input: {
gatherStats: false,
exitOnCtrlC: false,
useKittyKeyboard: true,
stdin: input.stdin,
},
)
})
Expand Down
21 changes: 20 additions & 1 deletion packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Session } from "@/session"
import { bootstrap } from "@/cli/bootstrap"
import path from "path"
import { UI } from "@/cli/ui"
import fs from "fs/promises"
import tty from "tty"

declare global {
const OPENCODE_WORKER_PATH: string
Expand Down Expand Up @@ -59,9 +61,25 @@ export const TuiThreadCommand = cmd({
const prompt = await (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(
process.platform === "win32"
? (await fs.open("CONIN$", "rw", 0o644)).fd
: (await fs.open("/dev/tty", "r")).fd
)
} catch (err) {
console.error(
"Failed to open TTY for input. Prompt piping from stdin might not be supported on your platform.",
)
process.exit(1)
}

// Resolve relative paths against PWD to preserve behavior when using --cwd flag
const baseCwd = process.env.PWD ?? process.cwd()
const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
Expand Down Expand Up @@ -120,6 +138,7 @@ export const TuiThreadCommand = cmd({
hostname: args.hostname,
})
await tui({
stdin,
url: server.url,
sessionID,
model: args.model,
Expand Down