diff --git a/app/lib/features/chat/ui/sessions/chat_compact_avatar.dart b/app/lib/features/chat/ui/sessions/chat_compact_avatar.dart new file mode 100644 index 00000000..754b05ed --- /dev/null +++ b/app/lib/features/chat/ui/sessions/chat_compact_avatar.dart @@ -0,0 +1,88 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'chat_session_state.dart'; +import 'session_activity_badge.dart'; + +/// Compact mode keeps task attention and pane state alongside identity. +class ChatCompactAvatar extends StatelessWidget { + const ChatCompactAvatar({ + super.key, + required this.title, + required this.color, + required this.active, + required this.visible, + required this.running, + required this.backgroundTasks, + required this.unread, + required this.cupertino, + }); + final String title; + final Color color; + final bool active, visible, running, unread, cupertino; + final int backgroundTasks; + + @override + Widget build(BuildContext context) => Stack( + clipBehavior: Clip.none, + children: [ + CircleAvatar( + foregroundColor: color, + backgroundColor: color.withValues(alpha: active ? .26 : .12), + child: Text( + title.characters.take(2).toString(), + style: TextStyle(fontWeight: active ? FontWeight.bold : null), + ), + ), + if (active || visible) + PositionedDirectional( + top: -2, + start: -5, + child: _Disc( + cupertino: cupertino, + child: Icon( + active ? Icons.radio_button_checked : Icons.visibility_outlined, + size: 14, + color: chatStateForeground(context), + ), + ), + ), + if (chatSessionActivityBadge( + cupertino: cupertino, + running: running, + backgroundTasks: backgroundTasks, + ) + case final badge?) + PositionedDirectional(bottom: -2, end: -3, child: badge), + if (unread) + PositionedDirectional( + top: -2, + end: -3, + child: _Disc( + cupertino: cupertino, + child: Icon( + Icons.mark_chat_unread_outlined, + key: const Key('chat-compact-unread'), + size: 14, + color: chatStateForeground(context), + ), + ), + ), + ], + ); +} + +class _Disc extends StatelessWidget { + const _Disc({required this.cupertino, required this.child}); + final bool cupertino; + final Widget child; + @override + Widget build(BuildContext context) => DecoratedBox( + decoration: BoxDecoration( + shape: BoxShape.circle, + color: cupertino + ? CupertinoColors.systemBackground.resolveFrom(context) + : Theme.of(context).colorScheme.surface, + ), + child: Padding(padding: const EdgeInsets.all(1), child: child), + ); +} diff --git a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart index 30e2ad6d..38d5e4e9 100644 --- a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart +++ b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart @@ -8,6 +8,9 @@ import 'chat_adaptive.dart'; import '../../domain/chat_colors.dart'; import 'chat_color_palette.dart'; import 'chat_visibility_marker.dart'; +import 'chat_compact_avatar.dart'; +import 'session_row_style.dart'; +import '../../domain/chat_list_activity.dart'; import 'chat_sessions_body.dart'; import 'chat_sessions_controller.dart'; @@ -21,6 +24,7 @@ class ChatCompactSidebar extends StatelessWidget { this.visibleSessionIds = const {}, required this.onOpen, required this.onExpand, + this.navigation, }); final ChatSessionsController controller; final ChatSectionFolds folds; @@ -28,6 +32,7 @@ class ChatCompactSidebar extends StatelessWidget { final Set visibleSessionIds; final ValueChanged onOpen; final VoidCallback onExpand; + final Widget? navigation; static const width = 72.0; Widget _button( @@ -62,6 +67,21 @@ class ChatCompactSidebar extends StatelessWidget { Widget _session(BuildContext context, JsonMap row) { final id = '${row['id'] ?? ''}'; final selected = id == activeSessionId; + final visible = visibleSessionIds.contains(id); + final unread = controller.isUnseen(row); + final running = row['running'] == true; + final backgroundTasks = chatSessionBackgroundTasks(row); + final title = chatSessionTitle(row); + final details = [ + title, + if (chatSessionSubtitle(row).isNotEmpty) chatSessionSubtitle(row), + if (relativeChatSessionTime(row['updated_at']).isNotEmpty) + 'Updated ${relativeChatSessionTime(row['updated_at'])} ago', + if (selected) 'Active chat' else if (visible) 'Visible chat', + if (running) 'Working', + if (backgroundTasks > 0) 'Background tasks running ($backgroundTasks)', + if (unread) 'New messages', + ].join('\n'); final color = chatColorShade(context, chatSessionColor(row)) ?? (chatControlsStyleOf(context) == ChatControlsStyle.cupertino @@ -70,7 +90,7 @@ class ChatCompactSidebar extends StatelessWidget { return ChatVisibilityMarker( sessionId: id, color: color, - visible: visibleSessionIds.contains(id), + visible: visible, active: selected, child: AnimatedContainer( duration: MediaQuery.disableAnimationsOf(context) @@ -79,13 +99,18 @@ class ChatCompactSidebar extends StatelessWidget { color: selected ? Colors.transparent : color.withValues(alpha: .07), child: _button( context, - chatSessionTitle(row), - CircleAvatar( - foregroundColor: color, - backgroundColor: color.withValues(alpha: selected ? .26 : .12), - child: Text( - chatSessionTitle(row).characters.take(2).toString(), - style: TextStyle(fontWeight: selected ? FontWeight.bold : null), + details, + ExcludeSemantics( + child: ChatCompactAvatar( + title: title, + color: color, + active: selected, + visible: visible, + running: running, + backgroundTasks: backgroundTasks, + unread: unread, + cupertino: + chatControlsStyleOf(context) == ChatControlsStyle.cupertino, ), ), () { @@ -108,10 +133,16 @@ class ChatCompactSidebar extends StatelessWidget { _button( context, 'Expand chat list', - Icon( - chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? CupertinoIcons.sidebar_left - : Icons.menu_open, + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + chatControlsStyleOf(context) == ChatControlsStyle.cupertino + ? CupertinoIcons.sidebar_left + : Icons.menu_open, + ), + const Text('Expand', textAlign: TextAlign.center), + ], ), onExpand, ), @@ -130,6 +161,7 @@ class ChatCompactSidebar extends StatelessWidget { }, ), ), + ?navigation, ], ), ), diff --git a/app/lib/features/chat/ui/sessions/chat_session_state.dart b/app/lib/features/chat/ui/sessions/chat_session_state.dart new file mode 100644 index 00000000..cf170cb7 --- /dev/null +++ b/app/lib/features/chat/ui/sessions/chat_session_state.dart @@ -0,0 +1,108 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'chat_adaptive.dart'; + +/// State uses neutral text and shapes; the chat's chosen color stays identity. +Color chatStateForeground(BuildContext context) => + chatControlsStyleOf(context) == ChatControlsStyle.cupertino + ? CupertinoColors.label.resolveFrom(context) + : Theme.of(context).colorScheme.onSurface; + +Color chatMetadataForeground(BuildContext context) => + chatControlsStyleOf(context) == ChatControlsStyle.cupertino + ? CupertinoColors.label.resolveFrom(context).withValues(alpha: .82) + : Theme.of(context).colorScheme.onSurfaceVariant; + +class ChatSessionStateLine extends StatelessWidget { + const ChatSessionStateLine({ + super.key, + required this.active, + required this.visible, + required this.running, + required this.backgroundTasks, + required this.unread, + }); + final bool active, visible, running, unread; + final int backgroundTasks; + + @override + Widget build(BuildContext context) { + final entries = <(IconData, String)>[ + if (active) + (Icons.radio_button_checked, 'Active') + else if (visible) + (Icons.visibility_outlined, 'Visible'), + if (running) (Icons.play_circle_outline, 'Working'), + if (backgroundTasks > 0) + (Icons.pending_actions, '$backgroundTasks background'), + if (unread) (Icons.mark_chat_unread_outlined, 'New'), + ]; + return Wrap( + spacing: 10, + runSpacing: 4, + children: [ + for (final (icon, label) in entries) + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(icon, size: 14, color: chatStateForeground(context)), + const SizedBox(width: 4), + Flexible( + child: Text( + label, + style: TextStyle(color: chatStateForeground(context)), + ), + ), + ], + ), + ], + ); + } +} + +class ChatSessionSubtitle extends StatelessWidget { + const ChatSessionSubtitle({ + super.key, + required this.metadata, + required this.closed, + required this.active, + required this.visible, + required this.running, + required this.backgroundTasks, + required this.unread, + }); + final String metadata; + final bool closed, active, visible, running, unread; + final int backgroundTasks; + @override + Widget build(BuildContext context) => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text.rich( + TextSpan( + children: [ + if (closed) + const TextSpan( + text: 'Closed', + style: TextStyle(fontWeight: FontWeight.w600), + ), + if (closed && metadata.isNotEmpty) const TextSpan(text: ' · '), + TextSpan(text: metadata), + ], + ), + style: TextStyle(color: chatMetadataForeground(context)), + ), + if (active || visible || running || backgroundTasks > 0 || unread) + Padding( + padding: const EdgeInsets.only(top: 4), + child: ChatSessionStateLine( + active: active, + visible: visible, + running: running, + backgroundTasks: backgroundTasks, + unread: unread, + ), + ), + ], + ); +} diff --git a/app/lib/features/chat/ui/sessions/session_activity_badge.dart b/app/lib/features/chat/ui/sessions/session_activity_badge.dart index 75a51cf1..3503dddb 100644 --- a/app/lib/features/chat/ui/sessions/session_activity_badge.dart +++ b/app/lib/features/chat/ui/sessions/session_activity_badge.dart @@ -28,7 +28,7 @@ Widget? chatSessionActivityBadge({ excludeFromSemantics: true, child: Semantics( label: label, - child: _BackgroundBadge(cupertino: cupertino), + child: _BackgroundBadge(cupertino: cupertino, count: backgroundTasks), ), ); } @@ -72,9 +72,10 @@ class _WorkingBadge extends StatelessWidget { } class _BackgroundBadge extends StatelessWidget { - const _BackgroundBadge({required this.cupertino}); + const _BackgroundBadge({required this.cupertino, required this.count}); final bool cupertino; + final int count; @override Widget build(BuildContext context) { @@ -83,10 +84,13 @@ class _BackgroundBadge extends StatelessWidget { : Theme.of(context).colorScheme.onSurfaceVariant; return _BadgeDisc( cupertino: cupertino, - child: Icon( - cupertino ? CupertinoIcons.ellipsis_circle_fill : Icons.pending, - size: 12, - color: color, + child: Text( + '$count', + style: TextStyle( + color: color, + fontSize: 12, + fontWeight: FontWeight.w600, + ), ), ); } diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index 810fd27f..cecafabe 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -11,6 +11,7 @@ import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; import 'chat_color_palette.dart'; import 'chat_visibility_marker.dart'; +import 'chat_session_state.dart'; import 'session_actions.dart'; import 'session_activity_badge.dart'; import 'session_harness_icon.dart'; @@ -112,20 +113,21 @@ class ChatSessionRow extends StatelessWidget { ), timeWidget: updatedAt == null ? null - : RelativeTimeLabel(instant: updatedAt), - // `Closed` leads the line of a closed chat, then the model and folder. - subtitle: Text.rich( - TextSpan( - children: [ - if (closed) - const TextSpan( - text: 'Closed', - style: TextStyle(fontWeight: FontWeight.w600), + : DefaultTextStyle.merge( + style: TextStyle( + color: unread ? accent : chatMetadataForeground(context), ), - if (closed && text.isNotEmpty) const TextSpan(text: ' · '), - TextSpan(text: text), - ], - ), + child: RelativeTimeLabel(instant: updatedAt), + ), + // `Closed` leads the line of a closed chat, then the model and folder. + subtitle: ChatSessionSubtitle( + metadata: text, + closed: closed, + active: selected, + visible: visible, + running: session['running'] == true, + backgroundTasks: chatSessionBackgroundTasks(session), + unread: unread, ), subtitleTrailing: unread ? AppListStatusDot( diff --git a/app/notes/chat-state-navigation.md b/app/notes/chat-state-navigation.md new file mode 100644 index 00000000..ffd7ab41 --- /dev/null +++ b/app/notes/chat-state-navigation.md @@ -0,0 +1,26 @@ +# Chat identity, state and compact-rail legibility + +User identity colors and the animated visible/active edges remain unchanged. +Normal rows now state Active or Visible with a neutral shape/text marker; +Working, background task counts and New are explicit independent facts. A +running row with unread content retains the prior quiet avatar behavior but +now still says Working, so unread and execution are not conflated. + +Compact avatars retain neutral pane-state shapes, a foreground spinner or +background count, and a separate unread mark. Native button tooltips/accessibility +labels contain full title, model, directory, recency and current activity facts. +Expand is visible text, not just an icon. An optional navigation footer lets the +shell supply its destination launcher without this feature opening routes. + +Background avatars show an actual count instead of an indistinct ellipsis. +Cupertino secondary metadata and recency now use the native label at .82 alpha; +Material retains onSurfaceVariant. Neutral state text uses native onSurface or +label. The new calculation test covers both native hosts, light/dark and eight +identity colors at the strongest active gradient tint: 64 foreground/background +combinations meet at least 4.5:1. This is a bounded palette check, not a complete +accessibility audit of custom themes, focus or disabled controls. + +Tests: 132 session tests passed (/tmp/memwatch/out.CVA6FK); six final state, +compact-facts and native palette tests passed (/tmp/memwatch/out.iFGOhB). +Analyzer clean (flutter-analyze.WdYBd8). Parent owns integrated browser captures +and shell launcher testing. No server or device operations performed. diff --git a/app/test/features/chat/ui/sessions/chat_sessions_activity_test.dart b/app/test/features/chat/ui/sessions/chat_sessions_activity_test.dart index 63e95324..5f3ff4fb 100644 --- a/app/test/features/chat/ui/sessions/chat_sessions_activity_test.dart +++ b/app/test/features/chat/ui/sessions/chat_sessions_activity_test.dart @@ -110,7 +110,7 @@ void main() { expect(tooltip.message, 'Background tasks running (2)'); expect(tooltip.triggerMode, TooltipTriggerMode.manual); expect( - find.descendant(of: _badge('bg'), matching: find.byIcon(Icons.pending)), + find.descendant(of: _badge('bg'), matching: find.text('2')), findsOneWidget, ); expect( @@ -177,17 +177,16 @@ void main() { expect(_badge('s1'), findsNothing); }); - testWidgets('the Cupertino host draws its own glyph', (tester) async { + testWidgets('the Cupertino host shows the background task count', ( + tester, + ) async { final fake = FakeChatGateway() ..sessionsReply = { 'chat_sessions': [_row('bg', activity: _activity(tasks: 1))], }; await _pump(tester, fake, cupertino: true); expect( - find.descendant( - of: _badge('bg'), - matching: find.byIcon(CupertinoIcons.ellipsis_circle_fill), - ), + find.descendant(of: _badge('bg'), matching: find.text('1')), findsOneWidget, ); expect(_label(1), findsOneWidget); diff --git a/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart b/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart new file mode 100644 index 00000000..cc8141af --- /dev/null +++ b/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart @@ -0,0 +1,175 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_session_state.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_compact_sidebar.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_body.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart'; +import 'package:pipelines_app/features/chat/data/chat_repository.dart'; +import 'fake_chat_gateway.dart'; +import 'chat_test_harness.dart'; + +void main() { + testWidgets('state is readable without identity color at narrow large text', ( + tester, + ) async { + tester.view.physicalSize = const Size(320, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData(textScaler: TextScaler.linear(2)), + child: Scaffold( + body: ChatSessionRow( + session: const { + 'id': 'a', + 'title': 'Task', + 'color': 'red', + 'running': true, + 'background_tasks': 2, + 'model': 'model', + 'directory': '/work', + }, + selected: true, + visible: true, + unseen: true, + onOpen: (_) {}, + onAction: (_) {}, + ), + ), + ), + ), + ); + await tester.pump(); + for (final text in ['Active', 'Working', '2 background', 'New']) { + expect(find.text(text), findsOneWidget); + } + expect(tester.takeException(), isNull); + }); + + testWidgets( + 'compact rail retains facts in badges and accessible full labels', + (tester) async { + final gateway = FakeChatGateway() + ..sessionsReply = { + 'chat_sessions': [ + { + 'id': 'a', + 'title': 'Alpha review', + 'directory': '/work/alpha', + 'model': 'model-a', + 'activity': {'background_tasks': 2, 'seq': 1}, + }, + ], + }; + final controller = ChatSessionsController( + ChatRepository(gateway), + localStore: MemoryChatSessionLocalStore( + const ChatSessionLocal(unseen: ['a']), + ), + ); + final folds = ChatSectionFolds(); + addTearDown(controller.dispose); + addTearDown(folds.dispose); + addTearDown(gateway.pushed.close); + await controller.refresh(); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ChatCompactSidebar( + controller: controller, + folds: folds, + activeSessionId: null, + visibleSessionIds: const {'a'}, + onOpen: (_) {}, + onExpand: () {}, + navigation: const Text('Destinations'), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect(find.text('Expand'), findsOneWidget); + expect(find.text('Destinations'), findsOneWidget); + expect(find.byKey(const Key('chat-row-background')), findsOneWidget); + expect(find.byKey(const Key('chat-compact-unread')), findsOneWidget); + final tooltip = tester + .widgetList(find.byType(Tooltip)) + .firstWhere((t) => t.message!.contains('Alpha review')); + expect(tooltip.message, contains('model-a · /work/alpha')); + expect(tooltip.message, contains('Background tasks running (2)')); + expect(tooltip.message, contains('New messages')); + expect(tooltip.message, contains('Visible chat')); + }, + ); + + for (final cupertino in [false, true]) { + for (final brightness in Brightness.values) { + testWidgets( + 'native metadata and state contrast on tinted rows $cupertino $brightness', + (tester) async { + late BuildContext context; + final theme = ThemeData(brightness: brightness); + final body = Builder( + builder: (value) { + context = value; + return const SizedBox(); + }, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp( + theme: CupertinoThemeData(brightness: brightness), + home: body, + ) + : MaterialApp(theme: theme, home: body), + ); + final surface = cupertino + ? CupertinoDynamicColor.resolve( + CupertinoTheme.of(context).scaffoldBackgroundColor, + context, + ) + : theme.colorScheme.surface; + for (final name in [ + 'red', + 'orange', + 'amber', + 'green', + 'teal', + 'blue', + 'purple', + 'pink', + ]) { + final color = chatColorShade(context, name)!; + final background = Color.alphaBlend( + color.withValues( + alpha: brightness == Brightness.dark ? .30 : .22, + ), + surface, + ); + for (final foreground in [ + chatStateForeground(context), + chatMetadataForeground(context), + ]) { + final rendered = Color.alphaBlend(foreground, background); + final a = rendered.computeLuminance(), + b = background.computeLuminance(); + final ratio = (a > b + ? (a + .05) / (b + .05) + : (b + .05) / (a + .05)); + expect( + ratio, + greaterThanOrEqualTo(4.5), + reason: '$name metadata contrast', + ); + } + } + }, + ); + } + } +}