Chat: group consecutive background-task notices into one collapsed chip
Two or more consecutive Claude Code task notices fold into one task_notices row: a chip 'N background tasks' (tinted when one failed) that opens a sheet with one compact row per task (outcome icon, summary, outcome word), like the tools and permissions chips. A lone notice stays one line. The server also treats Claude Code's [SYSTEM NOTIFICATION] banner as harness text, so a bannered notification without an origin is still a notice, never the operator's turn. The chat fixture gains ?tasks=N.
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_task_notices.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
|
||||
/// A run of background-task notices as one quiet chip on the agent's side,
|
||||
/// like a turn's tools and permissions chips: `N background tasks`, tinted
|
||||
/// when one failed. It opens a sheet with one compact row per task.
|
||||
class ChatTaskNoticesGroup extends StatelessWidget {
|
||||
const ChatTaskNoticesGroup({super.key, required this.row});
|
||||
|
||||
/// A `task_notices` row (see [groupTaskNotices]).
|
||||
final JsonMap row;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final notices = chatTaskNoticesOf(row);
|
||||
if (notices.isEmpty) return const SizedBox.shrink();
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final failed = notices
|
||||
.where((n) => n.outcome == ChatTaskOutcome.failed)
|
||||
.length;
|
||||
final color = failed > 0
|
||||
? _errorColor(context, cupertino)
|
||||
: _secondaryColor(context, cupertino);
|
||||
final label = chatTaskNoticesLabel(notices.length);
|
||||
final shown = failed > 0 ? '$label · $failed failed' : label;
|
||||
return Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ChatTurnChip(
|
||||
chipKey: const Key('chat-task-notices-chip'),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.square_stack_3d_up : Icons.task_alt,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
label: shown,
|
||||
color: color,
|
||||
semanticsLabel: '$shown ended, expand for details',
|
||||
sheet: _TaskNoticesSheet(notices: notices, title: label),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Color _secondaryColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
Color _errorColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error;
|
||||
|
||||
String _outcomeLabel(ChatTaskOutcome outcome) => switch (outcome) {
|
||||
ChatTaskOutcome.finished => 'Finished',
|
||||
ChatTaskOutcome.failed => 'Failed',
|
||||
ChatTaskOutcome.stopped => 'Stopped',
|
||||
};
|
||||
|
||||
class _TaskNoticesSheet extends StatelessWidget {
|
||||
const _TaskNoticesSheet({required this.notices, required this.title});
|
||||
|
||||
final List<ChatTaskNotice> notices;
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return DefaultTextStyle.merge(
|
||||
style: style,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
),
|
||||
child: ListView(
|
||||
key: const Key('chat-task-notices-sheet'),
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
for (final notice in notices) _TaskNoticeRow(notice: notice),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One task: its outcome icon, the harness's summary and the outcome word.
|
||||
class _TaskNoticeRow extends StatelessWidget {
|
||||
const _TaskNoticeRow({required this.notice});
|
||||
|
||||
final ChatTaskNotice notice;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final secondary = _secondaryColor(context, cupertino);
|
||||
final outcome = _outcomeLabel(notice.outcome);
|
||||
final (icon, color) = switch (notice.outcome) {
|
||||
ChatTaskOutcome.finished => (
|
||||
cupertino
|
||||
? CupertinoIcons.checkmark_circle
|
||||
: Icons.check_circle_outline,
|
||||
secondary,
|
||||
),
|
||||
ChatTaskOutcome.failed => (
|
||||
cupertino ? CupertinoIcons.xmark_circle : Icons.error_outline,
|
||||
_errorColor(context, cupertino),
|
||||
),
|
||||
ChatTaskOutcome.stopped => (
|
||||
cupertino ? CupertinoIcons.stop_circle : Icons.stop_circle_outlined,
|
||||
secondary,
|
||||
),
|
||||
};
|
||||
final summary = notice.summary.isEmpty
|
||||
? 'Background task ${outcome.toLowerCase()}'
|
||||
: notice.summary;
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: '$outcome: $summary',
|
||||
child: ExcludeSemantics(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 8, top: 2),
|
||||
child: Icon(icon, size: 16, color: color),
|
||||
),
|
||||
Expanded(child: Text(summary)),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
child: Text(
|
||||
outcome,
|
||||
style: TextStyle(color: color, fontSize: 13),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user