Skip to content

feature: Read and edit the current TUI draft through ask() #313

Description

@aemonge

Prerequisites

  • I searched the docs
  • I searched existing issues

Is your feature request related to a problem? Please describe.

require("opencode").ask() can open an input and send its result to
OpenCode, but it cannot read the prompt text already being composed in
the active OpenCode TUI.

For example:

  1. Start writing a prompt in the OpenCode TUI.
  2. Switch to Neovim.
  3. Call require("opencode").ask().
  4. Ask opens without the existing TUI draft.

I would like to edit that same draft from Neovim and return the modified
text to the active TUI.

The intended workflow is similar to OpenCode's /editor command:

  1. Start composing in the TUI.
  2. Open the current draft in Neovim.
  3. Edit it using the existing Neovim instance.
  4. Return the edited draft to the same TUI.
  5. Continue editing or submit it from there.

This must stay in the current OpenCode session/conversation. It should
not create a new session, fork the conversation, or send the existing
draft as a separate message.

This is distinct from #185. The main request is reading and replacing
the active TUI draft, rather than generally replacing Ask with a
multiline input widget.

Describe the solution you'd like

Expose an opt-in "edit current TUI prompt" flow through ask(). The exact
public API is less important than the following behavior:

  1. Read the current prompt from the connected OpenCode TUI.
  2. Use that text as the initial value shown by Ask.
  3. Let the user edit it in Neovim.
  4. On confirmation, replace the TUI prompt with the edited value instead
    of appending to the old value.
  5. Leave the prompt unsubmitted by default, matching /editor.
  6. Keep the same active TUI and session.
  7. On cancellation, leave the original TUI prompt unchanged.
  8. If the edited value is empty, clear the TUI prompt.
  9. Round-trip the complete prompt text, including newlines.

Existing behavior for explicit calls such as:

require("opencode").ask("@this: ")

### Describe alternatives you've considered

Using the EDITOR command from the TUI, but since I open the TUI from `nvim +terminal` , it's harder to use the same NVIM editor as EDITOR and keeping the conversation visible while a hover editor is on top of the TUI prompt

### Additional context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions