From bfccf396713a726b1cfdd472717979c6afb10b76 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 25 Nov 2026 00:02:59 +0000 Subject: [PATCH] Answer Claude questions in your own words, or dismiss them Claude's question forms now accept a free-text answer beside the offered options and can be dismissed. A dismissal tells Claude the operator will reply in the chat instead, the card's button reads Dismiss, and the composer takes the keyboard so the reply can be typed at once. Co-Authored-By: Claude Opus 5.5 --- .../chat/conversation/chat_question_card.dart | 13 ++++++++++ .../chat_question_card_controls.dart | 3 ++- .../conversation/chat_question_card_test.dart | 25 ++++++++++++++++++- internal/claude/chat.go | 8 ++++-- internal/claude/claude_test.go | 9 +++++-- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/app/lib/features/chat/conversation/chat_question_card.dart b/app/lib/features/chat/conversation/chat_question_card.dart index 475b252f..067a4cdc 100644 --- a/app/lib/features/chat/conversation/chat_question_card.dart +++ b/app/lib/features/chat/conversation/chat_question_card.dart @@ -7,6 +7,7 @@ import 'chat_question_card_fields.dart'; import 'chat_question_card_model.dart'; import 'chat_question_recorded_answers.dart'; import 'chat_question_validation.dart'; +import 'composer_focus_request.dart'; /// One recorded agent question as a native card. /// @@ -117,7 +118,14 @@ class _ChatQuestionCardState extends State { _sending = true; _localError = ''; }); + // Read before the await: the card leaves the tree once answered. + final composer = ChatComposerFocusScope.maybeOf(context); await widget.onSubmit(const {}, action); + // A dismissed question is answered in the chat: the composer takes the + // keyboard so the reply can be typed straight away. + if (action == 'decline' && widget.form['kind'] == 'question') { + composer?.requests.request(composer.sessionId); + } if (mounted) setState(() => _sending = false); } @@ -177,6 +185,11 @@ class _ChatQuestionCardState extends State { sending: _sending, onSubmit: _submit, onAction: _action, + // A dismissed question tells the agent the operator will reply in + // the chat instead. + declineLabel: widget.form['kind'] == 'question' + ? 'Dismiss' + : 'Decline', ), ], ], diff --git a/app/lib/features/chat/conversation/chat_question_card_controls.dart b/app/lib/features/chat/conversation/chat_question_card_controls.dart index 3a175d87..0f80ce8e 100644 --- a/app/lib/features/chat/conversation/chat_question_card_controls.dart +++ b/app/lib/features/chat/conversation/chat_question_card_controls.dart @@ -12,6 +12,7 @@ Widget chatQuestionControls({ required bool sending, required VoidCallback onSubmit, required void Function(String action) onAction, + String declineLabel = 'Decline', }) { final canDecline = actions is List && actions.contains('decline'); final canCancel = actions is List && actions.contains('cancel'); @@ -26,7 +27,7 @@ Widget chatQuestionControls({ if (canDecline) TextButton( onPressed: sending ? null : () => onAction('decline'), - child: const Text('Decline'), + child: Text(declineLabel), ), if (canCancel) TextButton( diff --git a/app/test/features/chat/conversation/chat_question_card_test.dart b/app/test/features/chat/conversation/chat_question_card_test.dart index 7f4d43b0..1a2e9fa4 100644 --- a/app/test/features/chat/conversation/chat_question_card_test.dart +++ b/app/test/features/chat/conversation/chat_question_card_test.dart @@ -9,6 +9,7 @@ import 'package:pipelines_app/features/chat/conversation/chat_question_validatio import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'chat_thread_fixtures.dart'; +import 'package:pipelines_app/features/chat/conversation/composer_focus_request.dart'; Widget materialHost(Widget child) => MaterialApp( theme: ThemeData(platform: TargetPlatform.android), @@ -286,7 +287,8 @@ void main() { ), ), ); - await tester.tap(find.text('Decline')); + // A question's decline dismisses it so the reply goes in the chat. + await tester.tap(find.text('Dismiss')); await tester.pumpAndSettle(); await tester.tap(find.text('Cancel question')); await tester.pumpAndSettle(); @@ -295,6 +297,27 @@ void main() { }, ); + testWidgets('dismissing a question sends the reply to the composer', ( + tester, + ) async { + final requests = ChatComposerFocusRequests(); + await tester.pumpWidget( + scrollHost( + ChatComposerFocusScope( + sessionId: 's', + requests: requests, + child: ChatQuestionCard( + form: question(), + onSubmit: (sent, action) async {}, + ), + ), + ), + ); + await tester.tap(find.text('Dismiss')); + await tester.pumpAndSettle(); + expect(requests.take('s'), isTrue); + }); + testWidgets( 'an all-external form confirms completion without field answers', (tester) async { diff --git a/internal/claude/chat.go b/internal/claude/chat.go index 75c838d1..2f0bbd09 100644 --- a/internal/claude/chat.go +++ b/internal/claude/chat.go @@ -625,7 +625,7 @@ func (c *Chat) Answer(ctx context.Context, request protocol.ChatAnswerRequest) e deny := request.Action == "cancel" || request.Action == "decline" var response any if deny { - response = map[string]any{"behavior": "deny", "message": "The operator declined to answer"} + response = map[string]any{"behavior": "deny", "message": "The operator dismissed the question and will reply in the chat instead; wait for their message."} } else { answers := map[string]string{} for index, question := range form.questions { @@ -837,7 +837,10 @@ func (s *session) receiveQuestion(p *process, requestID string, request toolRequ s.receivePermission(p, requestID, toolRequest{ToolName: "AskUserQuestion", Input: request.Input}) return } - form := protocol.ChatForm{ID: requestID, SessionID: s.id, Kind: "question", Title: "Claude asked a question"} + // Claude's question tool always takes an answer of the operator's own + // beside its options, and a dismissed question goes back as a denial, so + // every field accepts free text and the form can be declined. + form := protocol.ChatForm{ID: requestID, SessionID: s.id, Kind: "question", Title: "Claude asked a question", Actions: []string{"accept", "decline"}} questions := make([]string, 0, len(payload.Questions)) for index, question := range payload.Questions { questions = append(questions, question.Question) @@ -846,6 +849,7 @@ func (s *session) receiveQuestion(p *process, requestID string, request toolRequ Title: question.Question, Type: "string", Required: true, + Custom: true, } if question.Header != "" { form.Title = question.Header diff --git a/internal/claude/claude_test.go b/internal/claude/claude_test.go index bfecade7..36e3936f 100644 --- a/internal/claude/claude_test.go +++ b/internal/claude/claude_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "os" "path/filepath" + "slices" "strings" "testing" "time" @@ -224,13 +225,17 @@ func TestQuestionBecomesAFormAndAnswerReturnsToCLI(t *testing.T) { if form.Kind != "question" || len(form.Fields) != 1 || len(form.Fields[0].Options) != 2 { t.Fatalf("form: %+v", form) } - if err := chat.Answer(context.Background(), protocol.ChatAnswerRequest{SessionID: session.ID, FormID: form.ID, Answers: map[string]any{"q0": "Alpha"}}); err != nil { + // The operator may answer in their own words or dismiss the question. + if !form.Fields[0].Custom || !slices.Contains(form.Actions, "decline") { + t.Fatalf("a Claude question must take a custom answer and a dismissal: %+v", form) + } + if err := chat.Answer(context.Background(), protocol.ChatAnswerRequest{SessionID: session.ID, FormID: form.ID, Answers: map[string]any{"q0": "Neither, use the cache"}}); err != nil { t.Fatal(err) } waitFrame(t, frames, "answered tool", func(frame protocol.ChatEventFrame) bool { return frame.Kind == protocol.ChatEventTool && frame.Part != nil && frame.Part.State != nil && frame.Part.State.Status == protocol.ChatToolCompleted && len(frame.Part.State.Content) == 1 && - strings.Contains(frame.Part.State.Content[0].Text, "Alpha") + strings.Contains(frame.Part.State.Content[0].Text, "Neither, use the cache") }) waitStepEnded(t, frames) if forms, _ := chat.Forms(context.Background(), session.ID); len(forms) != 0 {