diff --git a/app/lib/features/chat/conversation/chat_question_card_fields.dart b/app/lib/features/chat/conversation/chat_question_card_fields.dart index 9ed4c3ff..9bf40a0a 100644 --- a/app/lib/features/chat/conversation/chat_question_card_fields.dart +++ b/app/lib/features/chat/conversation/chat_question_card_fields.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import '../../../core/api_gateway.dart'; import 'chat_card_styles.dart'; import 'chat_question_card_model.dart'; +import 'chat_question_markdown.dart'; import 'chat_composer_bar.dart' show chatEnterSends; import 'chat_no_reveal.dart'; import 'chat_question_option_controls.dart'; @@ -63,9 +64,12 @@ Widget _field({ crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.min, children: [ - Text(label, style: chatCardLabelStyle(context)), + ChatQuestionMarkdown(label, style: chatCardLabelStyle(context)), if (description.isNotEmpty && description != title) - Text(description, style: chatCardSecondaryStyle(context)), + ChatQuestionMarkdown( + description, + style: chatCardSecondaryStyle(context), + ), if ('${field['type'] ?? ''}' == 'external') _external(context, field) else if ('${field['type'] ?? ''}' == 'boolean') diff --git a/app/lib/features/chat/conversation/chat_question_markdown.dart b/app/lib/features/chat/conversation/chat_question_markdown.dart new file mode 100644 index 00000000..d31ba947 --- /dev/null +++ b/app/lib/features/chat/conversation/chat_question_markdown.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; + +import '../ui/transcript/chat_markdown_view.dart'; + +/// A question's text (its title, description or an option's description) +/// rendered as markdown in [style]: agents format questions with bold, code, +/// lists and links, the same subset the transcript draws. +class ChatQuestionMarkdown extends StatelessWidget { + const ChatQuestionMarkdown(this.text, {super.key, this.style}); + + final String text; + final TextStyle? style; + + @override + Widget build(BuildContext context) { + final view = ChatMarkdownView(text: text); + final style = this.style; + return style == null + ? view + : DefaultTextStyle.merge(style: style, child: view); + } +} diff --git a/app/lib/features/chat/conversation/chat_question_option_controls.dart b/app/lib/features/chat/conversation/chat_question_option_controls.dart index 57afa880..165b587d 100644 --- a/app/lib/features/chat/conversation/chat_question_option_controls.dart +++ b/app/lib/features/chat/conversation/chat_question_option_controls.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import 'chat_question_card_model.dart'; +import 'chat_question_markdown.dart'; /// Native option controls for one question field. Single-select uses the host's /// radio/checklist pattern, multi-select toggles choices, and `onChanged` @@ -30,7 +31,7 @@ Widget chatQuestionOptionsField({ title: Text(chatQuestionOptionLabel(option)), subtitle: '${option['description'] ?? ''}'.trim().isEmpty ? null - : Text('${option['description']}'.trim()), + : ChatQuestionMarkdown('${option['description']}'.trim()), contentPadding: EdgeInsets.zero, controlAffinity: ListTileControlAffinity.leading, onChanged: (on) => onChanged( @@ -53,7 +54,7 @@ Widget chatQuestionOptionsField({ title: Text(chatQuestionOptionLabel(option)), subtitle: '${option['description'] ?? ''}'.trim().isEmpty ? null - : Text('${option['description']}'.trim()), + : ChatQuestionMarkdown('${option['description']}'.trim()), contentPadding: EdgeInsets.zero, controlAffinity: ListTileControlAffinity.leading, ), 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 2a9383fa..ae8d6818 100644 --- a/app/test/features/chat/conversation/chat_question_card_test.dart +++ b/app/test/features/chat/conversation/chat_question_card_test.dart @@ -345,6 +345,57 @@ void main() { variant: TargetPlatformVariant.only(TargetPlatform.linux), ); + testWidgets('a question and its option descriptions render markdown', ( + tester, + ) async { + await tester.pumpWidget( + scrollHost( + ChatQuestionCard( + form: { + 'id': 'q', + 'kind': 'question', + 'fields': [ + { + 'key': 'q0', + 'title': 'Use **Postgres** or `sqlite`?', + 'type': 'string', + 'options': [ + { + 'value': 'A', + 'label': 'A', + 'description': 'Keeps **all** data', + }, + ], + }, + ], + }, + onSubmit: (answers, action) async {}, + ), + ), + ); + await tester.pumpAndSettle(); + // The markers are formatting, never shown as text. + expect(find.textContaining('**', findRichText: true), findsNothing); + expect(find.textContaining('`', findRichText: true), findsNothing); + // Bold wraps its words in a span of its own (visitChildren skips spans + // without text, so walk them directly). + final bold = []; + void walk(InlineSpan span) { + if (span is! TextSpan) return; + if (span.style?.fontWeight == FontWeight.bold) { + bold.add(span.toPlainText()); + } + for (final child in span.children ?? const []) { + walk(child); + } + } + + for (final text in tester.widgetList(find.byType(RichText))) { + walk(text.text); + } + expect(bold, containsAll(['Postgres', 'all'])); + }); + testWidgets('dismissing a question sends the reply to the composer', ( tester, ) async { diff --git a/app/tool/perf/chat_question_fixture.dart b/app/tool/perf/chat_question_fixture.dart index 3940ce9d..ccac765e 100644 --- a/app/tool/perf/chat_question_fixture.dart +++ b/app/tool/perf/chat_question_fixture.dart @@ -42,13 +42,22 @@ void chatQuestionStream(String sessionId, void Function(JsonMap frame) emit) { 'fields': [ { 'key': 'q0', - 'title': 'Which database should the release use?', + 'title': _mode == 'claude' + ? 'Which **database** should the `release` use?\n\n' + '- Postgres keeps the current schema\n' + '- SQLite needs a migration' + : 'Which database should the release use?', 'type': 'string', 'required': true, if (_mode == 'claude') 'custom': true, 'options': [ {'value': 'Postgres', 'label': 'Postgres'}, - {'value': 'SQLite', 'label': 'SQLite'}, + { + 'value': 'SQLite', + 'label': 'SQLite', + if (_mode == 'claude') + 'description': 'Smaller, but **no** concurrent writers', + }, ], }, ],