Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
77ff16c
fix: flush stdin on POSIX exit to prevent stale bytes leaking to shell
altendky Mar 11, 2026
921959f
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 16, 2026
7e62a82
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 17, 2026
1d4a4c5
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 18, 2026
a93e350
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 20, 2026
26485eb
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 20, 2026
6b080e2
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 21, 2026
347774e
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 21, 2026
ebaa79f
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 23, 2026
bfe7964
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 29, 2026
52ab530
fix: update win32 imports to console after rename
altendky Mar 29, 2026
339e4ff
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 30, 2026
eeb175b
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Mar 31, 2026
4d70a6e
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 1, 2026
bf37011
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 3, 2026
0a63f84
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 6, 2026
85064ec
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 7, 2026
b1be508
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 8, 2026
caaa298
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 8, 2026
f0db226
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 9, 2026
a4dc9f1
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 12, 2026
38d35fb
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 13, 2026
a8ea240
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 16, 2026
430f8a2
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 16, 2026
4b55ab2
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 17, 2026
cac632c
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 17, 2026
a14bcf6
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 18, 2026
d255fdf
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 19, 2026
97f3c74
feat: update codex plugin to support 5.5 (#23789)
rekram1-node Apr 22, 2026
69e2f3b
chore: bump Bun to 1.3.13 (#23791)
Hona Apr 22, 2026
a45d9a9
fix(app): improve icon override handling in project edit dialog (#23768)
Brendonovich Apr 22, 2026
ed3d364
chore: update nix node_modules hashes
opencode-agent[bot] Apr 22, 2026
bb69648
fix: preserve BOM in text tool round-trips (#23797)
Hona Apr 22, 2026
bfb954e
chore: generate
opencode-agent[bot] Apr 22, 2026
0595c28
test: fix cross-spawn stderr race on Windows CI (#23808)
Hona Apr 22, 2026
6aa475f
chore: generate
opencode-agent[bot] Apr 22, 2026
88c5f6b
fix: consolidate project avatar source logic (#23819)
Brendonovich Apr 22, 2026
2a480a9
fix(tui): fail fast on invalid session startup (#23837)
nexxeln Apr 22, 2026
266e965
chore: generate
opencode-agent[bot] Apr 22, 2026
97100dc
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 22, 2026
ae19402
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 23, 2026
34108d0
undo
altendky Apr 23, 2026
19121fa
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 24, 2026
9618bc7
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 27, 2026
84cfc47
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 29, 2026
068512b
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 29, 2026
d5a75bb
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky Apr 30, 2026
69587ba
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky May 1, 2026
d7683dc
Merge branch 'dev' into fix/flush-stdin-on-exit
altendky May 3, 2026
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: 1 addition & 1 deletion packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Show,
on,
} from "solid-js"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./console"
import { Flag } from "@opencode-ai/core/flag/flag"
import semver from "semver"
import { DialogProvider, useDialog } from "@tui/ui/dialog"
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/tui/attach.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cmd } from "../cmd"
import { UI } from "@/cli/ui"
import { tui } from "./app"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./console"
import { TuiConfig } from "@/cli/cmd/tui/config/tui"
import { errorMessage } from "@/util/error"
import { validateSession } from "./validate-session"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { TextAttributes } from "@opentui/core"
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
import * as Clipboard from "@tui/util/clipboard"
import { createSignal } from "solid-js"
import { flushInputBuffer } from "../console"
import { InstallationVersion } from "@opencode-ai/core/installation/version"
import { win32FlushInputBuffer } from "../win32"
import { getScrollAcceleration } from "../util/scroll"

export function ErrorComponent(props: {
Expand All @@ -20,7 +20,7 @@ export function ErrorComponent(props: {
await props.onBeforeExit?.()
renderer.setTerminalTitle("")
renderer.destroy()
win32FlushInputBuffer()
flushInputBuffer()
await props.onExit()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { dlopen, ptr } from "bun:ffi"
import type { ReadStream } from "node:tty"

// -- Windows (kernel32) -------------------------------------------------------

const STD_INPUT_HANDLE = -10
const ENABLE_PROCESSED_INPUT = 0x0001

Expand All @@ -14,16 +16,32 @@ const kernel = () =>

let k32: ReturnType<typeof kernel> | undefined

// -- POSIX (libc) -------------------------------------------------------------

const libc = () =>
dlopen(process.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", {
tcflush: { args: ["i32", "i32"], returns: "i32" },
})

let lc: ReturnType<typeof libc> | undefined

// -----------------------------------------------------------------------------

function load() {
if (process.platform !== "win32") return false
try {
k32 ??= kernel()
if (process.platform === "win32") k32 ??= kernel()
else lc ??= libc()
return true
} catch {
return false
}
}

// TCIFLUSH: discard received-but-unread input
const TCIFLUSH = process.platform === "darwin" ? 1 : 0

// -- Exports ------------------------------------------------------------------

/**
* Clear ENABLE_PROCESSED_INPUT on the console stdin handle.
*/
Expand All @@ -42,15 +60,21 @@ export function win32DisableProcessedInput() {
}

/**
* Discard any queued console input (mouse events, key presses, etc.).
* Discard any queued console/tty input (mouse events, key presses, etc.).
*
* On Windows this calls FlushConsoleInputBuffer via kernel32.
* On POSIX this calls tcflush(STDIN_FILENO, TCIFLUSH) via libc.
*/
export function win32FlushInputBuffer() {
if (process.platform !== "win32") return
export function flushInputBuffer() {
if (!process.stdin.isTTY) return
if (!load()) return

const handle = k32!.symbols.GetStdHandle(STD_INPUT_HANDLE)
k32!.symbols.FlushConsoleInputBuffer(handle)
if (process.platform === "win32") {
const handle = k32!.symbols.GetStdHandle(STD_INPUT_HANDLE)
k32!.symbols.FlushConsoleInputBuffer(handle)
} else {
lc!.symbols.tcflush(0, TCIFLUSH)
}
}

let unhook: (() => void) | undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/cli/cmd/tui/context/exit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRenderer } from "@opentui/solid"
import { createSimpleContext } from "./helper"
import { FormatError, FormatUnknownError } from "@/cli/error"
import { win32FlushInputBuffer } from "../win32"
import { flushInputBuffer } from "../console"
type Exit = ((reason?: unknown) => Promise<void>) & {
message: {
set: (value?: string) => () => void
Expand Down Expand Up @@ -37,7 +37,7 @@ export const { use: useExit, provider: ExitProvider } = createSimpleContext({
// Reset window title before destroying renderer
renderer.setTerminalTitle("")
renderer.destroy()
win32FlushInputBuffer()
flushInputBuffer()
if (reason) {
const formatted = FormatError(reason) ?? FormatUnknownError(reason)
if (formatted) {
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { withNetworkOptions, resolveNetworkOptionsNoConfig } from "@/cli/network
import { Filesystem } from "@/util/filesystem"
import type { GlobalEvent } from "@opencode-ai/sdk/v2"
import type { EventSource } from "./context/sdk"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32"
import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./console"
import { writeHeapSnapshot } from "v8"
import { TuiConfig } from "./config/tui"
import {
Expand Down
Loading