Skip to content

fix: restore Bun stdin reads for prompt input#16300

Merged
thdxr merged 2 commits intodevfrom
fix/run-stdin-bun
Mar 6, 2026
Merged

fix: restore Bun stdin reads for prompt input#16300
thdxr merged 2 commits intodevfrom
fix/run-stdin-bun

Conversation

@thdxr
Copy link
Member

@thdxr thdxr commented Mar 6, 2026

Summary

  • switch run and TUI prompt stdin reads back to Bun.stdin.text()
  • restore support for prompts passed through Bun.spawn({ stdin: Buffer.from(...) }) in the compiled CLI
  • remove the node:stream/consumers stdin path that regressed prefilled stdin handling

Testing

  • Not run (not requested)

Use Bun.stdin.text() again for run and TUI stdin so Bun.spawn() prefilled buffers reach the compiled CLI. This avoids the regression introduced by the node:stream/consumers path.
@greptile-apps
Copy link

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR reverts a regression introduced by the node:stream/consumers stdin path, restoring the original Bun.stdin.text() API in both the run command handler and the TUI thread's input() helper. The fix ensures that pre-filled stdin payloads passed via Bun.spawn({ stdin: Buffer.from(...) }) in the compiled CLI are correctly consumed, since Bun's native stdin handle is what receives the data rather than the Node.js-compatible process.stdin stream object.

Key changes:

  • packages/opencode/src/cli/cmd/run.ts: streamText(process.stdin)Bun.stdin.text() (line 340); unused import removed.
  • packages/opencode/src/cli/cmd/tui/thread.ts: same substitution in the input() helper (line 56); unused import removed.
  • No logic, control-flow, or interface changes; purely an API swap back to the Bun-native call.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted revert of a known regression with no side effects.
  • The change is a two-line swap (plus two import removals) that restores a previously working API call. Bun.stdin.text() is the idiomatic Bun way to read all of stdin and is consistent with the rest of the codebase's Bun-first approach. The replaced node:stream/consumers path was introduced as an apparent compatibility improvement but broke the pre-filled stdin contract when the CLI is invoked programmatically via Bun.spawn. No new logic is added, no interfaces change, and the fix is well-scoped.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/opencode/src/cli/cmd/run.ts Replaces streamText(process.stdin) from node:stream/consumers with Bun.stdin.text() on line 340 to restore correct pre-filled stdin handling when invoked via Bun.spawn({ stdin: Buffer.from(...) }); import of streamText is removed.
packages/opencode/src/cli/cmd/tui/thread.ts Same targeted fix in the TUI input() helper: streamText(process.stdin) replaced with Bun.stdin.text() and the now-unused import removed; no other logic changed.

Sequence Diagram

sequenceDiagram
    participant Caller as Caller (Bun.spawn / shell pipe)
    participant Main as CLI entry (run.ts / thread.ts)
    participant Stdin as Bun.stdin
    participant Handler as Command handler

    Caller->>Main: invoke opencode run / tui
    Main->>Main: parse args (message, --prompt, etc.)
    Main->>Main: check process.stdin.isTTY
    alt stdin is NOT a TTY (piped input)
        Main->>Stdin: Bun.stdin.text()
        Stdin-->>Main: piped string content
        Main->>Main: append piped content to message / prompt
    else stdin IS a TTY (interactive)
        Main->>Main: skip stdin read (piped = undefined)
    end
    Main->>Handler: execute with combined message/prompt
    Handler-->>Caller: stream events / TUI render
Loading

Last reviewed commit: 015c785

@thdxr thdxr enabled auto-merge (squash) March 6, 2026 07:07
@thdxr thdxr disabled auto-merge March 6, 2026 07:08
@thdxr thdxr merged commit 326c701 into dev Mar 6, 2026
6 checks passed
@thdxr thdxr deleted the fix/run-stdin-bun branch March 6, 2026 07:08
github-actions bot pushed a commit to chrn11/opencode that referenced this pull request Mar 6, 2026
jerome-benoit pushed a commit to jerome-benoit/opencode that referenced this pull request Mar 6, 2026
qdddddd pushed a commit to qdddddd/opencode that referenced this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant