Merge commit 'bd256ad1'

This commit is contained in:
2026-10-25 21:55:55 +00:00
6 changed files with 154 additions and 132 deletions
@@ -148,12 +148,13 @@ class _CupertinoSessionRow extends StatelessWidget {
final id = '${session['id'] ?? ''}'; final id = '${session['id'] ?? ''}';
// Cupertino's grouped list owns the separators and the native tile metrics; // Cupertino's grouped list owns the separators and the native tile metrics;
// the row only decides where the title, its state word and the muted meta // the row only decides where the title, its state word and the muted meta
// go. The meta line (recency first) keeps the tile's native 12pt style by // go. Each metadata line keeps the tile's native 12pt style by
// passing colour only, so `Text` merges with `CupertinoListTile`'s own // passing colour only, so `Text` merges with `CupertinoListTile`'s own
// `DefaultTextStyle` instead of overriding it with the title's size. // `DefaultTextStyle` instead of overriding it with the title's size.
final theme = CupertinoTheme.of(context); final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
final meta = chatSessionRowMetaLine(session); final meta = chatSessionMetaLines(session);
final recency = relativeChatSessionTime(session['updated_at']);
final status = chatSessionRowStatus(session, unseen: unseen); final status = chatSessionRowStatus(session, unseen: unseen);
final statusStyle = TextStyle( final statusStyle = TextStyle(
color: status == 'Closed' ? secondary : theme.primaryColor, color: status == 'Closed' ? secondary : theme.primaryColor,
@@ -171,20 +172,18 @@ class _CupertinoSessionRow extends StatelessWidget {
), ),
// As on the web: the title with the unread/closed word trailing, then // As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line. // the muted `recency · directory · model` line.
title: ChatSessionRowMeta( title: ChatSessionRowContent(
meta: chatSessionTitle(session), title: chatSessionTitle(session),
status: status, status: status,
metaStyle: const TextStyle(), recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle: theme.textTheme.textStyle.copyWith(
fontWeight: FontWeight.w600,
),
metaStyle: TextStyle(color: secondary),
statusStyle: statusStyle, statusStyle: statusStyle,
), ),
subtitle: meta.isEmpty subtitle: null,
? null
: Text(
meta,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: secondary),
),
onTap: () => onOpen(session), onTap: () => onOpen(session),
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -151,14 +151,15 @@ class _MaterialSessionRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}'; final id = '${session['id'] ?? ''}';
// The same content as the Cupertino row: title with the unread/closed word // The same content as the Cupertino row: title and state, then each
// trailing, then a muted `recency · directory · model` line. // recorded metadata field on its own muted line.
// `ListTile` does not force one ellipsised line like `CupertinoListTile`, // `ListTile` does not force one ellipsised line like `CupertinoListTile`,
// so both text widgets state their line limit themselves. The meta line // so both text widgets state their line limit themselves. The meta line
// passes colour only, so it keeps the tile's native subtitle style. // passes colour only, so it keeps the tile's native subtitle style.
final theme = Theme.of(context); final theme = Theme.of(context);
final secondary = theme.colorScheme.onSurfaceVariant; final secondary = theme.colorScheme.onSurfaceVariant;
final meta = chatSessionRowMetaLine(session); final meta = chatSessionMetaLines(session);
final recency = relativeChatSessionTime(session['updated_at']);
final status = chatSessionRowStatus(session, unseen: unseen); final status = chatSessionRowStatus(session, unseen: unseen);
final statusStyle = TextStyle( final statusStyle = TextStyle(
color: status == 'Closed' ? secondary : theme.colorScheme.primary, color: status == 'Closed' ? secondary : theme.colorScheme.primary,
@@ -171,20 +172,18 @@ class _MaterialSessionRow extends StatelessWidget {
leading: Icon(sessionMaterialIcon(session)), leading: Icon(sessionMaterialIcon(session)),
// As on the web: the title with the unread/closed word trailing, then // As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line. // the muted `recency · directory · model` line.
title: ChatSessionRowMeta( title: ChatSessionRowContent(
meta: chatSessionTitle(session), title: chatSessionTitle(session),
status: status, status: status,
metaStyle: const TextStyle(), recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle:
theme.textTheme.titleSmall ??
const TextStyle(fontWeight: FontWeight.w600),
metaStyle: TextStyle(color: secondary),
statusStyle: statusStyle, statusStyle: statusStyle,
), ),
subtitle: meta.isEmpty subtitle: null,
? null
: Text(
meta,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: secondary),
),
onTap: () => onOpen(session), onTap: () => onOpen(session),
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -1,83 +1,97 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// A chat session row line with the unread/closed word at its trailing edge: /// Hierarchical row copy shared by the Material and Cupertino list variants.
/// the row's title line, as on the web. /// Each server-recorded fact keeps its own line; recency is visually anchored
/// /// at the end of its own line rather than competing with the other metadata.
/// The directory/model is the part that ellipsises; the state word is the row's class ChatSessionRowContent extends StatelessWidget {
/// only unread marker, so it keeps its intrinsic width and the metadata shrinks const ChatSessionRowContent({
/// first. If even the whole text column cannot hold the word at the current
/// text scale it is scaled down rather than clipped, so `New`/`Closed` is never
/// replaced by an ellipsis.
class ChatSessionRowMeta extends StatelessWidget {
const ChatSessionRowMeta({
super.key, super.key,
required this.meta, required this.title,
required this.status, required this.status,
required this.recency,
required this.meta,
required this.titleStyle,
required this.metaStyle, required this.metaStyle,
required this.statusStyle, required this.statusStyle,
}); });
final String meta; final String title;
final String? status; final String? status;
final String? recency;
final List<String> meta;
final TextStyle titleStyle;
final TextStyle metaStyle; final TextStyle metaStyle;
final TextStyle statusStyle; final TextStyle statusStyle;
/// The trailing word's intrinsic width is measured against the full text
/// column, minus this gap, so the row can never overflow the line.
static const _statusGap = 8.0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return LayoutBuilder( return Column(
builder: (context, constraints) => Row( crossAxisAlignment: CrossAxisAlignment.start,
children: [ mainAxisSize: MainAxisSize.min,
Expanded( children: [
Text(
title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: titleStyle,
),
if (status != null) ...[
const SizedBox(height: 2),
Align(
alignment: AlignmentDirectional.centerStart,
child: _StatusLabel(status: status!, style: statusStyle),
),
],
if (recency != null && recency!.isNotEmpty) ...[
const SizedBox(height: 3),
Align(
alignment: AlignmentDirectional.centerEnd,
child: Text( child: Text(
meta, recency!,
maxLines: 1, maxLines: 2,
overflow: TextOverflow.ellipsis, textAlign: TextAlign.end,
style: metaStyle, style: metaStyle,
), ),
), ),
if (status != null)
ConstrainedBox(
constraints: BoxConstraints(maxWidth: constraints.maxWidth),
child: Padding(
padding: const EdgeInsetsDirectional.only(start: _statusGap),
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: AlignmentDirectional.centerEnd,
child: status == 'New'
? _UnreadBadge(style: statusStyle)
: Text(status!, maxLines: 1, style: statusStyle),
),
),
),
], ],
), for (final line in meta)
Text(
line,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: metaStyle,
),
],
); );
} }
} }
/// A chat with messages not yet seen: the word in a filled pill. class _StatusLabel extends StatelessWidget {
class _UnreadBadge extends StatelessWidget { const _StatusLabel({required this.status, required this.style});
const _UnreadBadge({required this.style});
final String status;
final TextStyle style; final TextStyle style;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = style.color ?? const Color(0xFF0A84FF); if (status != 'New') {
return Text(
status,
maxLines: 2,
style: style.copyWith(fontWeight: FontWeight.w600),
);
}
final color = style.color ?? Theme.of(context).colorScheme.primary;
return DecoratedBox( return DecoratedBox(
key: const Key('chat-row-unread'), key: const Key('chat-row-unread'),
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()), decoration: ShapeDecoration(color: color, shape: const StadiumBorder()),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1), padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
child: Text( child: Text(
'New', status,
maxLines: 1, maxLines: 2,
style: style.copyWith( style: style.copyWith(
color: const Color(0xFFFFFFFF), color: Colors.white,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
), ),
), ),
@@ -43,16 +43,14 @@ String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
return '${then.day} ${_shortMonths[then.month - 1]}'; return '${then.day} ${_shortMonths[then.month - 1]}';
} }
/// The row's muted second line: which agent runs the chat (an empty backend /// Recorded session fields rendered independently beneath the title.
/// is a legacy OpenCode row), its model, and the directory with the home List<String> chatSessionMetaLines(JsonMap session) {
/// folder written as `~`.
String chatSessionMeta(JsonMap session) {
final backend = '${session['backend'] ?? ''}'.trim(); final backend = '${session['backend'] ?? ''}'.trim();
return [ return [
backend.isEmpty ? 'opencode' : backend, backend.isEmpty ? 'opencode' : backend,
'${session['model'] ?? ''}'.trim(), '${session['model'] ?? ''}'.trim(),
homeRelativePath('${session['directory'] ?? ''}'.trim()), homeRelativePath('${session['directory'] ?? ''}'.trim()),
].where((part) => part.isNotEmpty).join(' · '); ].where((part) => part.isNotEmpty).toList();
} }
final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)'); final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
@@ -60,12 +58,11 @@ final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
/// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`. /// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`.
String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~'); String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~');
/// The row's muted second line as the web words it: recency first, then the /// All secondary row information, each as a distinct line.
/// directory and model (`1 day ago · /srv/probe · model-a`). List<String> chatSessionRowMetaLines(JsonMap session, {DateTime? now}) => [
String chatSessionRowMetaLine(JsonMap session, {DateTime? now}) => [
relativeChatSessionTime(session['updated_at'], now: now), relativeChatSessionTime(session['updated_at'], now: now),
chatSessionMeta(session), ...chatSessionMetaLines(session),
].where((part) => part.isNotEmpty).join(' · '); ].where((part) => part.isNotEmpty).toList();
/// The word on the row's trailing edge while the session has news or a state: /// The word on the row's trailing edge while the session has news or a state:
/// `Closed` from the row, otherwise `New`. A streaming session deliberately /// `Closed` from the row, otherwise `New`. A streaming session deliberately
@@ -107,20 +107,21 @@ void main() {
}); });
test('meta and status come only from the row', () { test('meta and status come only from the row', () {
expect( expect(chatSessionMetaLines({'directory': '/work', 'model': 'model-a'}), [
chatSessionMeta({'directory': '/work', 'model': 'model-a'}), 'opencode',
'opencode · model-a · /work', 'model-a',
); '/work',
expect(chatSessionMeta({'directory': '/work'}), 'opencode · /work'); ]);
expect(chatSessionMeta({}), 'opencode'); expect(chatSessionMetaLines({'directory': '/work'}), ['opencode', '/work']);
expect(chatSessionMetaLines({}), ['opencode']);
// The agent kind is the row's backend; the home folder reads as ~. // The agent kind is the row's backend; the home folder reads as ~.
expect( expect(
chatSessionMeta({ chatSessionMetaLines({
'backend': 'claude', 'backend': 'claude',
'model': 'opus', 'model': 'opus',
'directory': '/Users/alan/repos/pipelines', 'directory': '/Users/alan/repos/pipelines',
}), }),
'claude · opus · ~/repos/pipelines', ['claude', 'opus', '~/repos/pipelines'],
); );
expect(homeRelativePath('/home/dev/x'), '~/x'); expect(homeRelativePath('/home/dev/x'), '~/x');
expect(homeRelativePath('/Users/alan'), '~'); expect(homeRelativePath('/Users/alan'), '~');
@@ -169,24 +170,26 @@ void main() {
// As on the web: the unread word trails the title; the muted meta line // As on the web: the unread word trails the title; the muted meta line
// leads with the recency. // leads with the recency.
expect(find.text('Starred chat'), findsOneWidget); expect(find.text('Starred chat'), findsOneWidget);
expect(find.text('5 min ago · opencode · model-a · /work'), findsOneWidget); expect(find.text('5 min ago'), findsOneWidget);
expect(find.text('model-a'), findsOneWidget);
expect(find.text('New'), findsOneWidget); expect(find.text('New'), findsOneWidget);
expect(find.text('2 hr ago · opencode · /work'), findsOneWidget); expect(find.text('2 hr ago'), findsOneWidget);
expect(find.text('opencode'), findsNWidgets(2));
expect(find.text('/work'), findsNWidgets(2));
expect( expect(
(tester.getCenter(find.text('Starred chat')).dy - tester.getCenter(find.text('New')).dy,
tester.getCenter(find.text('New')).dy) greaterThan(tester.getCenter(find.text('Starred chat')).dy),
.abs(), );
lessThan(4), expect(
tester.getCenter(find.text('5 min ago')).dx,
greaterThan(tester.getCenter(find.text('Starred chat')).dx),
); );
// The meta line keeps `CupertinoListTile`'s native 12pt subtitle style; it // The meta line keeps `CupertinoListTile`'s native 12pt subtitle style; it
// must not be rendered at the title's body size. The colour-only style the // must not be rendered at the title's body size. The colour-only style the
// row passes merges with the tile's own `DefaultTextStyle`. // row passes merges with the tile's own `DefaultTextStyle`.
final titleStyle = _styleOf(tester, 'Starred chat'); final titleStyle = _styleOf(tester, 'Starred chat');
final metaStyle = _styleOf( final metaStyle = _styleOf(tester, '5 min ago');
tester,
'5 min ago · opencode · model-a · /work',
);
expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!)); expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!));
expect(metaStyle.fontSize, 12.0); expect(metaStyle.fontSize, 12.0);
expect(_styleOf(tester, 'New').fontSize, titleStyle.fontSize); expect(_styleOf(tester, 'New').fontSize, titleStyle.fontSize);
@@ -229,16 +232,19 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
const title = 'A conversation title long enough to need an ellipsis'; const title = 'A conversation title long enough to need an ellipsis';
const meta = const meta = '/a/very/long/directory/that/must/ellipsise';
'3 days ago · opencode · provider/an-extremely-long-recorded-model-id'
' · /a/very/long/directory/that/must/ellipsise';
final titleParagraph = tester.renderObject<RenderParagraph>( final titleParagraph = tester.renderObject<RenderParagraph>(
find.text(title), find.text(title),
); );
expect(titleParagraph.maxLines, 1); expect(titleParagraph.maxLines, 2);
expect(titleParagraph.didExceedMaxLines, isTrue); expect(titleParagraph.didExceedMaxLines, isTrue);
final metaParagraph = tester.renderObject<RenderParagraph>(find.text(meta)); final metaParagraph = tester.renderObject<RenderParagraph>(
expect(metaParagraph.maxLines, 1); find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.text(meta),
),
);
expect(metaParagraph.maxLines, 2);
expect(metaParagraph.didExceedMaxLines, isTrue); expect(metaParagraph.didExceedMaxLines, isTrue);
// The state word is the row's only unread marker: at the smallest supported // The state word is the row's only unread marker: at the smallest supported
@@ -259,12 +265,9 @@ void main() {
); );
} }
// The word shares the title's line, as on the web.
expect( expect(
(tester.getCenter(find.text(title)).dy - tester.getCenter(find.text('New')).dy,
tester.getCenter(find.text('New')).dy) greaterThan(tester.getCenter(find.text(title)).dy),
.abs(),
lessThan(20),
); );
}); });
} }
@@ -74,24 +74,24 @@ void main() {
], isUnseen: (session) => session['id'] == 's1'); ], isUnseen: (session) => session['id'] == 's1');
expect(find.text('Starred chat'), findsOneWidget); expect(find.text('Starred chat'), findsOneWidget);
expect(find.text('5 min ago · opencode · model-a · /work'), findsOneWidget); expect(find.text('5 min ago'), findsOneWidget);
expect(find.text('opencode'), findsNWidgets(2));
expect(find.text('model-a'), findsOneWidget);
expect(find.text('/work'), findsNWidgets(2));
expect(find.text('New'), findsOneWidget); expect(find.text('New'), findsOneWidget);
expect(find.text('2 hr ago · opencode · /work'), findsOneWidget); expect(find.text('2 hr ago'), findsOneWidget);
// As on the web, the unread word shares the title's line.
expect( expect(
(tester.getCenter(find.text('Starred chat')).dy - tester.getCenter(find.text('New')).dy,
tester.getCenter(find.text('New')).dy) greaterThan(tester.getCenter(find.text('Starred chat')).dy),
.abs(), );
lessThan(4), expect(
tester.getCenter(find.text('5 min ago')).dx,
greaterThan(tester.getCenter(find.text('Starred chat')).dx),
); );
// The meta line is the theme's muted colour, not the title colour. // The meta line is the theme's muted colour, not the title colour.
final meta = tester.widget<Text>( final meta = tester.widget<Text>(find.text('5 min ago'));
find.text('5 min ago · opencode · model-a · /work'), final context = tester.element(find.text('5 min ago'));
);
final context = tester.element(
find.text('5 min ago · opencode · model-a · /work'),
);
expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant); expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant);
// Native Material separators sit between rows, not around the group. // Native Material separators sit between rows, not around the group.
@@ -155,16 +155,19 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
const title = 'A conversation title long enough to need an ellipsis'; const title = 'A conversation title long enough to need an ellipsis';
const meta = const meta = '/a/very/long/directory/that/must/ellipsise';
'3 days ago · opencode · provider/an-extremely-long-recorded-model-id'
' · /a/very/long/directory/that/must/ellipsise';
final titleParagraph = tester.renderObject<RenderParagraph>( final titleParagraph = tester.renderObject<RenderParagraph>(
find.text(title), find.text(title),
); );
expect(titleParagraph.maxLines, 1); expect(titleParagraph.maxLines, 2);
expect(titleParagraph.didExceedMaxLines, isTrue); expect(titleParagraph.didExceedMaxLines, isTrue);
final metaParagraph = tester.renderObject<RenderParagraph>(find.text(meta)); final metaParagraph = tester.renderObject<RenderParagraph>(
expect(metaParagraph.maxLines, 1); find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.text(meta),
),
);
expect(metaParagraph.maxLines, 2);
expect(metaParagraph.didExceedMaxLines, isTrue); expect(metaParagraph.didExceedMaxLines, isTrue);
// `New`/`Closed` is the row's only unread marker; it stays whole at the // `New`/`Closed` is the row's only unread marker; it stays whole at the
@@ -184,9 +187,16 @@ void main() {
); );
} }
// Two lines: the title/word line, then the muted recency/meta line. // The title/state and every metadata field occupy distinct lines.
expect( expect(
tester.getCenter(find.text(meta)).dy, tester
.getCenter(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.text(meta).last,
),
)
.dy,
greaterThan(tester.getCenter(find.text(title)).dy), greaterThan(tester.getCenter(find.text(title)).dy),
); );
}); });