fix(AskUserQuestion): always include questions key and use question text as answer key#191
Open
sudo-yf wants to merge 1 commit into
Open
Conversation
…ext as answer key Two bugs in the AskUserQuestion round-trip with Claude Code: 1. askUserQuestionUpdatedInput omitted the 'questions' key when originalQuestions was nil (cast failure). Claude Code's mapToolResultToToolResultBlockParam calls H.map() on questions directly, so a missing key causes 'undefined is not an object (evaluating H.map)'. Fix: always write questions, falling back to the raw toolInput value. 2. answerKey was derived from the question's header, but Claude Code looks up answers by question text (answers[question.question]). The key mismatch caused every answer to come back as an empty string. Fix: use questionText as the base key instead of header.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two bugs in
Sources/CodeIsland/AppState.swiftcauseAskUserQuestionto fail when used through the CodeIsland hook:Bug 1:
H.map undefinedcrashaskUserQuestionUpdatedInputconditionally setupdatedInput["questions"]only when the[[String: Any]]cast succeeded:Claude Code's
mapToolResultToToolResultBlockParamdestructures the hook result as{questions: H, answers: _, annotations: q}and immediately callsH.map(). If thequestionskey is absent,Hisundefinedand the call throws:Bug 2: All answers returned as empty strings
handleAskUserQuestionbuiltanswerKeyfrom the question'sheaderfield:Claude Code looks up answers by question text:
answers[question.question]. Using the header as the dictionary key means every lookup misses, and all answers come back as empty strings.Fix
Bug 1 — always write the
questionskey, falling back to the rawtoolInputvalue when the cast fails:Bug 2 — use
questionTextas the answer key to match Claude Code's lookup:Testing
Verified with a 4-option
AskUserQuestioncall containing Chinese text in header/label/description fields. Before the fix: crash or empty answers. After: popup renders correctly and all selected answers are returned to Claude Code.