diff --git a/app/lib/features/runs/ui/run_detail_tab_bodies.dart b/app/lib/features/runs/ui/run_detail_tab_bodies.dart index 44dca4ef..19ba07c3 100644 --- a/app/lib/features/runs/ui/run_detail_tab_bodies.dart +++ b/app/lib/features/runs/ui/run_detail_tab_bodies.dart @@ -5,6 +5,7 @@ import '../../../core/api_gateway.dart'; import 'run_detail_content.dart'; import 'run_detail_summary_fields.dart'; import 'run_detail_visit_facts.dart'; +import 'run_field_body.dart'; import '../../../ui/text/monospace.dart'; /// The Summary tab: the run's identity, the recorded facts as key/value rows, @@ -27,7 +28,7 @@ Widget runDetailSummaryTab({ }) { final rows = detailSummaryRows(run); final identity = detailSummaryIdentity(run); - final prompt = detailPrompt(run); + // No separate "Original prompt": the run's Input carries it, as data. if (cupertino) { return ListView( key: const Key('run-detail-tab-body-summary'), @@ -44,14 +45,6 @@ Widget runDetailSummaryTab({ CupertinoListSection.insetGrouped( children: [_cupertinoBlock(context, row)], ), - if (prompt != null) - _cupertinoPrompt( - context, - prompt: prompt, - copying: copying, - copyStatus: copyStatus, - onCopy: onCopy, - ), _cupertinoFieldSection( context, key: 'run-detail-summary-input', @@ -87,14 +80,6 @@ Widget runDetailSummaryTab({ ), for (final row in rows) row.block ? _materialBlock(context, row) : _materialRow(context, row), - if (prompt != null) - _materialPrompt( - context, - prompt: prompt, - copying: copying, - copyStatus: copyStatus, - onCopy: onCopy, - ), _materialFieldSection( context, key: 'run-detail-summary-input', @@ -215,50 +200,7 @@ Widget _materialFieldSection( title: Text(title), expandedCrossAxisAlignment: CrossAxisAlignment.start, childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), - children: [SelectableText(detailEmpty(value) ? empty : detailJson(value))], - ); -} - -Widget _materialPrompt( - BuildContext context, { - required String prompt, - required bool copying, - required String? copyStatus, - required VoidCallback onCopy, -}) { - final theme = Theme.of(context); - return Padding( - padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.only(top: 12), - child: Text( - 'Original prompt', - style: theme.textTheme.titleMedium, - ), - ), - ), - IconButton( - tooltip: 'Copy prompt', - onPressed: copying ? null : onCopy, - icon: const Icon(Icons.copy), - ), - ], - ), - SelectableText(prompt), - if (copyStatus != null) - Padding( - padding: const EdgeInsets.only(top: 4), - child: Semantics(liveRegion: true, child: Text(copyStatus)), - ), - ], - ), + children: [RunFieldBody(value: value, empty: empty, cupertino: false)], ); } @@ -343,8 +285,11 @@ Widget _cupertinoFieldSection( padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), child: Align( alignment: AlignmentDirectional.centerStart, - child: _CupertinoSelectableText( - detailEmpty(value) ? empty : detailJson(value), + child: RunFieldBody( + value: value, + empty: empty, + cupertino: true, + textBuilder: _CupertinoSelectableText.new, ), ), ), @@ -353,44 +298,6 @@ Widget _cupertinoFieldSection( ); } -Widget _cupertinoPrompt( - BuildContext context, { - required String prompt, - required bool copying, - required String? copyStatus, - required VoidCallback onCopy, -}) { - final theme = CupertinoTheme.of(context); - return Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Wrap( - alignment: WrapAlignment.spaceBetween, - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 8, - runSpacing: 4, - children: [ - Text('Original prompt', style: theme.textTheme.navTitleTextStyle), - CupertinoButton( - padding: EdgeInsets.zero, - onPressed: copying ? null : onCopy, - child: const Text('Copy prompt'), - ), - ], - ), - _CupertinoSelectableText(prompt), - if (copyStatus != null) - Padding( - padding: const EdgeInsets.only(top: 4), - child: Semantics(liveRegion: true, child: Text(copyStatus)), - ), - ], - ), - ); -} - String _slug(String label) => label.toLowerCase().replaceAll(' ', '-'); /// A read-only Cupertino text control: plain, selectable text without a diff --git a/app/lib/features/runs/ui/run_field_body.dart b/app/lib/features/runs/ui/run_field_body.dart new file mode 100644 index 00000000..d02ba9ee --- /dev/null +++ b/app/lib/features/runs/ui/run_field_body.dart @@ -0,0 +1,88 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../chat/ui/transcript/chat_markdown_view.dart'; + +/// The web's `displayText`: a list joins its items, a map reads `key=value` +/// pairs, anything else is its plain string. +String runFieldText(dynamic value) { + if (value is List) return value.map(runFieldText).join(', '); + if (value is Map) { + return value.entries + .map((entry) => '${entry.key}=${runFieldText(entry.value)}') + .join(', '); + } + return '${value ?? 'null'}'; +} + +/// The web's `looksLikeMarkdown`: a heading, fence, list item or table row. +bool runFieldLooksLikeMarkdown(String text) => + RegExp(r'^#{1,6}\s', multiLine: true).hasMatch(text) || + text.contains('```') || + RegExp(r'^\s*(?:[-*]|\d+\.)\s+', multiLine: true).hasMatch(text) || + RegExp(r'^\|.+\|', multiLine: true).hasMatch(text); + +/// A run's recorded Input or Output as the web draws it: each field under its +/// own name with its value as text, markdown when it reads as markdown, and a +/// lone `markdown` field as the document itself. Never raw JSON. +class RunFieldBody extends StatelessWidget { + const RunFieldBody({ + super.key, + required this.value, + required this.empty, + required this.cupertino, + this.textBuilder, + }); + + final dynamic value; + final String empty; + final bool cupertino; + + /// Draws a plain value; the host's selectable text by default. + final Widget Function(String text)? textBuilder; + + @override + Widget build(BuildContext context) { + final map = value is Map ? Map.from(value as Map) : null; + if (map == null || map.isEmpty) return _plain(empty); + if (map.length == 1 && map.keys.single.toLowerCase() == 'markdown') { + return _value(runFieldText(map.values.single)); + } + final caption = + (cupertino + ? CupertinoTheme.of(context).textTheme.textStyle + : Theme.of(context).textTheme.labelMedium) + ?.copyWith( + fontWeight: FontWeight.w600, + color: cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant, + ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (final (index, entry) in map.entries.indexed) + Padding( + padding: EdgeInsets.only(top: index == 0 ? 0 : 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + entry.key.trim().isEmpty ? 'value' : entry.key, + style: caption, + ), + const SizedBox(height: 2), + _value(runFieldText(entry.value)), + ], + ), + ), + ], + ); + } + + Widget _value(String text) => runFieldLooksLikeMarkdown(text) + ? ChatMarkdownView(text: text) + : _plain(text); + + Widget _plain(String text) => textBuilder?.call(text) ?? SelectableText(text); +} diff --git a/app/test/features/runs/ui/run_detail_summary_fields_test.dart b/app/test/features/runs/ui/run_detail_summary_fields_test.dart index 4ede97f0..2d7ae67e 100644 --- a/app/test/features/runs/ui/run_detail_summary_fields_test.dart +++ b/app/test/features/runs/ui/run_detail_summary_fields_test.dart @@ -151,7 +151,8 @@ void main() { // The web run detail has no usage block, so no metrics tile is drawn. expect(find.text('Metrics'), findsNothing); expect(find.text('Unavailable'), findsNothing); - expect(find.text('Original prompt'), findsOneWidget); + // The prompt is part of Input, shown as data, not a block of its own. + expect(find.text('Original prompt'), findsNothing); if (platform == RunDetailTestPlatform.material) { final hash = tester.widget( @@ -207,7 +208,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.text('Input')); await tester.pumpAndSettle(); - expect(find.textContaining('"prompt": "ship it"'), findsOneWidget); + expect(find.text('ship it'), findsOneWidget); }); } } diff --git a/app/test/features/runs/ui/run_detail_widget_test.dart b/app/test/features/runs/ui/run_detail_widget_test.dart index cd9697d8..09099d8e 100644 --- a/app/test/features/runs/ui/run_detail_widget_test.dart +++ b/app/test/features/runs/ui/run_detail_widget_test.dart @@ -146,7 +146,7 @@ void main() { ); expect(tester.takeException(), isNull); expect(find.text('Nightly build'), findsOneWidget); - expect(find.textContaining('Original prompt'), findsOneWidget); + expect(find.textContaining('Original prompt'), findsNothing); // Both hosts lead with the web's status kicker above the title. expect(find.byKey(const Key('run-status-kicker')), findsOneWidget); expect( @@ -187,10 +187,13 @@ void main() { } await openSummarySection('Input'); - expect(find.textContaining('"alpha": 1'), findsOneWidget); + // Each field reads under its own name as data, never as JSON. + expect(find.text('nested'), findsOneWidget); + expect(find.text('alpha=1, items=1, 2'), findsOneWidget); + expect(find.textContaining('"alpha"'), findsNothing); await openSummarySection('Output'); - expect(find.textContaining('"ok": true'), findsOneWidget); + expect(find.text('ok=true'), findsOneWidget); await tapTab('Timeline'); final timelineScroll = find.descendant( @@ -261,30 +264,5 @@ void main() { await tester.tap(find.text('Back to list')); expect(backs, 1); }); - - testWidgets('${platform.name} copies the exact prompt and reports denial', ( - tester, - ) async { - final copied = []; - var denied = false; - mockClipboard(tester, copied, denied: () => denied); - final copy = platform == AppPlatform.material - ? find.byTooltip('Copy prompt') - : find.text('Copy prompt'); - await controller.select(1); - await pumpDetail(tester, platform, controller, gateway); - await tester.tap(copy); - await tester.pumpAndSettle(); - expect(copied.single, prompt); - expect(find.text('Prompt copied to clipboard.'), findsOneWidget); - if (platform == AppPlatform.material) { - await tester.pump(const Duration(seconds: 5)); - await tester.pumpAndSettle(); - } - denied = true; - await tester.tap(copy); - await tester.pumpAndSettle(); - expect(find.text('Could not copy prompt to clipboard.'), findsOneWidget); - }); } } diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart index 188955b6..3fa7a8df 100644 --- a/app/test/features/runs/ui/run_search_selection_test.dart +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -146,8 +146,8 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); - expect(find.textContaining('"prompt": "ship it"'), findsOneWidget); - expect(find.textContaining('"result": "ok"'), findsNothing); + expect(find.text('ship it'), findsOneWidget); + expect(find.text('ok'), findsNothing); }); testWidgets( @@ -163,8 +163,8 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); - expect(find.textContaining('"result": "ok"'), findsOneWidget); - expect(find.textContaining('"prompt": "ship it"'), findsNothing); + expect(find.text('ok'), findsOneWidget); + expect(find.text('ship it'), findsNothing); }, ); } @@ -180,8 +180,8 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); - expect(find.textContaining('"prompt": "ship it"'), findsNothing); - expect(find.textContaining('"result": "ok"'), findsNothing); + expect(find.text('ship it'), findsNothing); + expect(find.text('ok'), findsNothing); }); for (final platform in RunDetailTestPlatform.values) { @@ -207,8 +207,8 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); - expect(find.textContaining('"prompt": "ship it"'), findsNothing); - expect(find.textContaining('"result": "ok"'), findsNothing); + expect(find.text('ship it'), findsNothing); + expect(find.text('ok'), findsNothing); }, ); } diff --git a/app/test/features/runs/ui/runs_screen_test.dart b/app/test/features/runs/ui/runs_screen_test.dart index e044e234..8646d9f5 100644 --- a/app/test/features/runs/ui/runs_screen_test.dart +++ b/app/test/features/runs/ui/runs_screen_test.dart @@ -113,7 +113,7 @@ void main() { await tester.pump(); expect(find.text('Alpha run'), findsOneWidget); - expect(find.text('initial prompt'), findsOneWidget); + expect(find.text('Input'), findsOneWidget); expect(find.text('Loading run details…'), findsNothing); });