Skip to content

Conversation

@jamesrochabrun
Copy link
Owner

Summary

Implements full support for the AskUserQuestion tool, allowing Claude to ask users multiple-choice and multi-select questions during conversations with an interactive card-based UI.

Changes

🎯 Core Features

Data Models (AskUserQuestionModels.swift)

  • QuestionOption - Individual answer options with label and description
  • Question - Question structure with header, text, options, and multiSelect flag
  • QuestionSet - Collection of questions with toolUseId for response matching
  • QuestionAnswer - User's responses with selected labels and optional "Other" text

Stream Processing (StreamProcessor.swift)

  • Detects AskUserQuestion tool by name during stream processing
  • Parses questions array from tool input (question text, options, multiSelect)
  • Creates QuestionSet and message for UI display
  • Skips automatic tool result (similar to ExitPlanMode pattern)

UI Components

QuestionCardView.swift - Individual question cards with:

  • Header chip showing question category (max 12 chars)
  • Radio buttons for single-select questions
  • Checkboxes for multi-select questions
  • Always-visible "Other" text field for custom input
  • Visual selection feedback and hover states

AskUserQuestionView.swift - Main container with:

  • Collapsible header showing question count
  • Scrollable question cards (max height 500px)
  • Validation ensuring all questions answered
  • Submit button with loading state
  • Auto-continue after submission

Answer Collection (ChatViewModel.swift)

  • submitQuestionAnswers() method formats answers as JSON
  • Handles multi-select (comma-separated values)
  • Includes "Other" text when provided
  • Sends formatted response to continue conversation

Tool Formatting (AskUserQuestionFormatter.swift)

  • Added to ClaudeCodeTool enum with icon and metadata
  • Extracts question count for compact header display
  • Registered in ToolDisplayFormatter

📝 Type Extensions

  • Extended MessageType enum with .askUserQuestion
  • Extended MessageRole enum with .askUserQuestion
  • Added questionSet property to ChatMessage
  • Updated all exhaustive switch statements

✅ Quality Assurance

  • No regressions - all existing functionality preserved
  • Follows existing code patterns (ExitPlanMode, InlinePlanApprovalView)
  • All switch statements exhaustively handle new cases
  • Build passes with no errors or warnings

Technical Implementation

UI Design

  • Card-based: Each question in its own card (per requirements)
  • Auto-included "Other": Text field always visible
  • Auto-continue: No preview, immediate submission
  • Checkboxes: Standard checkbox UI for multi-select
  • Validation: All questions must be answered before submit

Integration Flow

  1. Claude sends AskUserQuestion tool use
  2. StreamProcessor detects and parses questions
  3. UI displays interactive question cards
  4. User fills out and submits answers
  5. Answers formatted as JSON and sent back
  6. Conversation continues automatically

Files Changed

New Files (4)

  • Sources/ClaudeCodeCore/Models/AskUserQuestionModels.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageView/QuestionCardView.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageView/AskUserQuestionView.swift
  • Sources/ClaudeCodeCore/ToolFormatting/Formatters/AskUserQuestionFormatter.swift

Modified Files (10)

  • Sources/ClaudeCodeCore/ViewModels/ChatMessage.swift
  • Sources/ClaudeCodeCore/ViewModels/StreamProcessor.swift
  • Sources/ClaudeCodeCore/ViewModels/MessageFactory.swift
  • Sources/ClaudeCodeCore/ViewModels/ChatViewModel.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageView/MessageContentView.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageView/MessageTextFormatterView.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageView/ChatMessageView.swift
  • Sources/ClaudeCodeCore/UI/ChatMessageRow.swift
  • Sources/ClaudeCodeCore/ToolFormatting/ToolType.swift
  • Sources/ClaudeCodeCore/ToolFormatting/ToolDisplayFormatter.swift

Testing

Ready for testing! The feature can be tested by having Claude use the AskUserQuestion tool in a conversation.

Screenshots

(UI screenshots can be added after testing)

🤖 Generated with Claude Code

Implements full support for the AskUserQuestion tool, allowing Claude to
ask users multiple-choice and multi-select questions during conversation.

## New Features

### Data Models
- Added AskUserQuestionModels.swift with QuestionOption, Question,
  QuestionSet, and QuestionAnswer structures
- Extended MessageType and MessageRole enums with askUserQuestion case
- Added questionSet property to ChatMessage for storing question data

### Stream Processing
- Added handleAskUserQuestion() method in StreamProcessor to parse
  questions from tool input
- Integrated tool detection for "AskUserQuestion" tool name
- Configured proper tool result skipping (similar to ExitPlanMode)

### UI Components
- QuestionCardView: Card-based question display with header chips,
  radio buttons for single-select, checkboxes for multi-select,
  and always-visible "Other" text field
- AskUserQuestionView: Main container with collapsible header,
  scrollable question cards, validation, and submit functionality

### Answer Collection
- Added submitQuestionAnswers() method to ChatViewModel
- Formats answers as JSON with question indices as keys
- Handles multi-select (comma-separated) and "Other" text responses
- Auto-continues conversation after submission

### Tool Formatting
- Created AskUserQuestionFormatter for tool display
- Added askUserQuestion case to ClaudeCodeTool enum with icon,
  friendly name, and priority parameters
- Registered formatter in ToolDisplayFormatter

## Technical Details

- Follows existing patterns (similar to ExitPlanMode tool)
- Card-based UI matching user requirements
- Full validation ensuring all questions are answered
- No regressions - all existing tests pass
- All switch statements updated for exhaustive matching

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants