opencode icon indicating copy to clipboard operation
opencode copied to clipboard

tui: add prompt history search (ctrl+r), shell-style

Open robertolopezlopez opened this issue 1 week ago • 2 comments

Summary

The TUI prompt has history cycling (up / down, prompt.history.previous / prompt.history.next) but no way to search it. Coming from a shell, ctrl+r is the natural key for it, yet ctrl+r is bound to session.rename and there is no prompt.history.search command to bind instead.

Environment

  • opencode version: 2.3.0
  • OS: Linux 6.1.189-1-MANJARO (Manjaro, x64)
  • Terminal: Ghostty 1.3.1, TERM=xterm-256color inside tmux 3.7c
  • Shell: /usr/bin/fish
  • Install/channel: release (latest)
  • Active plugins: @dietrichgebert/ponytail, ./plugins/caveman

Reproduction

  1. Submit two prompts in one session, e.g. alpha one then beta two.
  2. Press up in the empty prompt: beta two appears; up again: alpha one. Cycling works.
  3. Type alpha, then press up: the line stays alpha — the history is not filtered by what has been typed.
  4. Look for a search binding in cli.json: the only history command IDs are prompt.history.previous and prompt.history.next; ctrl+r is taken by session.rename.

Expected Behavior

A searchable prompt history, like a shell's reverse-i-search: one key opens a picker or an incremental filter over previous prompts, the query narrows the matches, and Enter puts the chosen prompt back into the input at the cursor.

Actual Behavior

Only linear cycling. Typing a prefix and pressing up does not narrow anything, and there is no command ID, dialog, or cli.json setting that searches history. Rebinding ctrl+r can only map it to prompt.history.previous, i.e. one step back per press.

Additional Context

The prompts are already stored (cycling reaches them), so this looks like a picker that does not exist rather than new data plumbing.

A minimal shape that would solve it:

  • a command ID such as prompt.history.search, free to bind, with no default binding (so ctrl+r stays as it is unless the user opts in);
  • opening it shows the session's previous prompt texts, newest first, with fuzzy/incremental filtering as the user types;
  • Enter writes the selected prompt into the input line at the cursor, Escape cancels without touching the input.

Fuzzy matching plus the existing dialog.select({ search }) plumbing in the TUI plugin API would be enough; the missing part is access to the history from a command.

Workaround in use today: press up repeatedly, or keep long prompts in a scratch file and paste them.

robertolopezlopez avatar Nov 18 '26 08:11 robertolopezlopez

Thanks for the detailed request. You'd like a bindable prompt.history.search command, with no default key, that opens a fuzzy-filtered list of previous prompts and puts the one you pick into the input.

Your reading of the code is right. History is only cycled with prompt.history.previous / prompt.history.next (up / down), and ctrl+r is bound to session.rename by default. One detail that may matter for the design: the TUI keeps prompt history in a single prompt-history.jsonl file, capped at the last 50 entries, not per session.

I looked at doing this as a plugin for now. The TUI plugin API has dialog.select({ search }) and can register named commands, but in the code I read I found no way for a plugin to read the prompt history or write text into the input box, so a plugin can't do this today. Maintainers will consider the request.

Related issues:

  • #51209: an open request to expose the V2 TUI input box to plugins, which would also let this be built as a plugin
  • #5062: earlier request for ctrl+r prompt history search, closed as not planned
  • #23780: another earlier ctrl+r reverse-i-search request, also closed as not planned

opencodejr[bot] avatar Nov 18 '26 09:11 opencodejr[bot]

i'd like to explore Ctrl+R prompt history for the TUI. Plan: match existing keybinding patterns and keep scope to history search only. Is this aligned with what you'd accept before I open a PR?

amrsorne avatar Nov 18 '26 10:11 amrsorne