opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add ask_user tool for interactive user questions

Open durutheguru opened this issue 2 weeks ago • 2 comments

Similar to AskUserQuestion tool in ClaudeCode. Adds a new tool that allows the AI to pause execution and present clarifying questions with selectable options to the user. Useful for gathering user preferences before proceeding with implementation.

  • Tool: ask_user with question, options (2-6), and optional context
  • TUI: DialogAsk component with keyboard navigation (↑/↓/j/k, 1-6, Enter, Esc)
  • Server: POST /ask/:id/reply endpoint for user responses
  • Events: askuser.question, askuser.answer, askuser.cancelled

Summary

  • Adds ask_user tool enabling the AI to pause and present clarifying questions with selectable options
  • Implements TUI dialog with full keyboard navigation for option selection
  • Follows existing permission system architecture (Bus events → SSE → TUI → API reply)
  • Events: askuser.question, askuser.answer, askuser.cancelled

Changes

New Files:

  • src/tool/ask.ts - Tool definition with Bus events and promise-based execution
  • src/tool/ask.txt - LLM description explaining when to use/avoid the tool
  • src/cli/cmd/tui/ui/dialog-ask.tsx - SolidJS dialog component

Modified Files:

  • src/server/server.ts - Added POST /ask/:id/reply endpoint
  • src/tool/registry.ts - Registered AskUserTool
  • src/cli/cmd/tui/context/sync.tsx - Added ask event handlers to sync state
  • src/cli/cmd/tui/routes/session/index.tsx - Renders DialogAsk, handles responses
  • src/id/id.ts - Added "ask" prefix for ID generation
  • packages/sdk/ - Regenerated client SDK

Testing

cd packages/opencode && bun dev

Try prompts like:

  • "Help me choose a testing framework for TypeScript"
  • "Interview me about building a REST API"

The AI should present options with keyboard navigation (↑ / ↓ / j / k , 1-6 number keys, Enter to select, Esc to cancel).

durutheguru avatar Jan 02 '26 20:01 durutheguru