Chat: draw agent follow-ups and automatic continues apart from the operator

The server now names a user turn's origin (followup, auto_continue,
auto_switch, scheduled) on chat messages, user frames and queued prompts,
from the prompt's operation id while it holds the prompt and from its own
text prefixes in history read later. Origin is a new field, so older
clients keep treating these as ordinary user turns.

The app draws an agent follow-up, auto-continue and account-switch prompt
as a quiet outlined card on the agent's side with an icon, label and the
schedule facts from the preamble; the operator's own scheduled message
keeps its bubble with a small Scheduled mark. Find searches the drawn text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 15:40:34 +00:00
parent 608b6b8edb
commit 9a6363b80e
22 changed files with 946 additions and 26 deletions
@@ -11,7 +11,7 @@ class ChatServerQueue {
List<JsonMap> _prompts = const [];
/// The queued prompts, each `{operation_id, message_id, native_message_id,
/// text, client, attachments}` as the server sent it.
/// text, client, attachments, send_at, origin}` as the server sent it.
List<JsonMap> get prompts => _prompts;
bool get isEmpty => _prompts.isEmpty;
@@ -45,6 +45,7 @@ class ChatServerQueue {
'operation_id': operation,
'native_message_id': prompt['native_message_id'] ?? '',
'client': prompt['client'],
'origin': ?prompt['origin'],
'parts': [
{'type': 'text', 'text': '${prompt['text'] ?? ''}'},
for (final attachment in prompt['attachments'] as List? ?? const [])
@@ -1919,6 +1919,7 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
() => ChatMessageView(
row: row,
speechScope: widget.sessionId,
scheduleShown: sendAt != null,
// The same reader id as the reply's Read aloud button, so the spoken
// word is highlighted in this reply's text.
textBuilder: (context, text) => ChatMarkdownView(
@@ -1983,6 +1984,7 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
row: {'kind': 'user', 'key': message['id'], 'message': message},
textBuilder: chatMarkdownText,
images: _images,
scheduleShown: true,
footer: [
ChatDeliveryIndicator(
state: ChatDelivery.queued,
@@ -2005,6 +2007,7 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
},
textBuilder: chatMarkdownText,
images: _images,
scheduleShown: true,
footer: [
ChatDeliveryIndicator(
state: ChatDelivery.failed,
+5 -1
View File
@@ -1,4 +1,5 @@
import '../../../core/api_gateway.dart';
import 'chat_prompt_origin.dart';
/// One piece of transcript text find searches, as the transcript shows it:
/// a user turn's text (its text parts joined by line breaks, as its bubble
@@ -75,7 +76,10 @@ List<ChatFindUnit> chatFindUnits(List<JsonMap> rows, List<String> keys) {
final kind = row['kind'];
if (kind == 'user') {
final message = row['message'] is Map ? row['message'] as Map : row;
final text = _textParts(message).join('\n');
final text = chatPromptDisplayText(
message,
_textParts(message).join('\n'),
);
if (text.trim().isEmpty) continue;
final id = '${row['key'] ?? message['id'] ?? ''}';
units.add(ChatFindUnit(index, keys[index], text, [id]));
@@ -0,0 +1,130 @@
/// Who put a user turn into the chat when the operator did not type it just
/// now. The server names it in `origin` (on a message, a user frame and a
/// queued prompt); an older server's operation ids and the server's own text
/// prefixes say the same.
enum ChatPromptOrigin {
/// The operator's own message, sent now.
operator,
/// The operator's own message they scheduled to send later.
scheduled,
/// A follow-up the agent scheduled for itself (schedule_followup).
followup,
/// The server resending the chat after its usage limit reset.
autoContinue,
/// The server continuing the chat on another Claude account.
autoSwitch;
/// Whether the agent or the server, not the operator, sent it.
bool get automated =>
this == followup || this == autoContinue || this == autoSwitch;
}
const _followupTextPrefix = '[Follow-up you scheduled at ';
const _autoSwitchTextPrefix = '[Sent automatically by Pipelines]';
/// The origin of a user [message] (a transcript message or a queued prompt).
ChatPromptOrigin chatPromptOrigin(Map<dynamic, dynamic> message) {
switch ('${message['origin'] ?? ''}') {
case 'followup':
return ChatPromptOrigin.followup;
case 'auto_continue':
return ChatPromptOrigin.autoContinue;
case 'auto_switch':
return ChatPromptOrigin.autoSwitch;
case 'scheduled':
return ChatPromptOrigin.scheduled;
}
final operation = '${message['operation_id'] ?? ''}';
if (operation.startsWith('followup-')) return ChatPromptOrigin.followup;
if (operation.startsWith('auto-continue-')) {
return ChatPromptOrigin.autoContinue;
}
if (operation.startsWith('auto-switch-')) return ChatPromptOrigin.autoSwitch;
final text = _firstText(message).trimLeft();
if (text.startsWith(_followupTextPrefix)) return ChatPromptOrigin.followup;
if (text.startsWith(_autoSwitchTextPrefix)) {
return ChatPromptOrigin.autoSwitch;
}
final sendAt = message['send_at'];
if (sendAt is num && sendAt > 0) return ChatPromptOrigin.scheduled;
return ChatPromptOrigin.operator;
}
/// An automated prompt as the transcript shows it: the server's bracketed
/// preamble becomes the header's facts and [body] is the message itself.
class ChatAutomatedPrompt {
const ChatAutomatedPrompt({
required this.origin,
required this.body,
this.scheduledAt,
this.condition,
});
final ChatPromptOrigin origin;
/// The prompt's text less the server's preamble.
final String body;
/// When the agent scheduled a follow-up, from its preamble.
final DateTime? scheduledAt;
/// What a run-triggered follow-up waits for: "run 42 finishes".
final String? condition;
}
final RegExp _followupPreamble = RegExp(
r'^\s*\[Follow-up you scheduled at (\S+) with schedule_followup'
r'(?:, for when (run \d+ [^;\]]+?))?'
r'(?:; delivered at \S+ at the latest)?\]\s*',
);
/// [text] of a prompt from [origin], split into its preamble's facts and body.
ChatAutomatedPrompt chatAutomatedPrompt(ChatPromptOrigin origin, String text) {
if (origin == ChatPromptOrigin.followup) {
final match = _followupPreamble.firstMatch(text);
if (match != null) {
return ChatAutomatedPrompt(
origin: origin,
body: text.substring(match.end),
scheduledAt: DateTime.tryParse(match.group(1)!)?.toLocal(),
condition: match.group(2),
);
}
}
if (origin == ChatPromptOrigin.autoSwitch) {
final trimmed = text.trimLeft();
if (trimmed.startsWith(_autoSwitchTextPrefix)) {
return ChatAutomatedPrompt(
origin: origin,
body: trimmed.substring(_autoSwitchTextPrefix.length).trimLeft(),
);
}
}
return ChatAutomatedPrompt(origin: origin, body: text);
}
/// The text a user turn's row draws for its joined text parts [text]: an
/// automated prompt's body without the server's preamble, else [text].
/// Find searches this same string, so its matches line up with the drawing.
String chatPromptDisplayText(Map<dynamic, dynamic> message, String text) {
final origin = chatPromptOrigin(message);
if (!origin.automated) return text;
return chatAutomatedPrompt(origin, text).body;
}
String _firstText(Map<dynamic, dynamic> message) {
final parts = message['parts'];
if (parts is! List) return '';
for (final part in parts) {
if (part is Map &&
(part['type'] == null || part['type'] == 'text') &&
part['text'] is String) {
return part['text'] as String;
}
}
return '';
}
@@ -212,6 +212,7 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame, {int Function()? now}) {
'created_at': arrived(),
'client': frame['client'],
'operation_id': frame['operation_id'],
'origin': ?frame['origin'],
'parts': [
{'type': 'text', 'text': text},
...(frame['attachments'] is List
@@ -0,0 +1,149 @@
import 'package:flutter/material.dart';
import '../../conversation/chat_schedule_time.dart';
import '../../domain/chat_prompt_origin.dart';
import 'chat_copy_button.dart';
import 'chat_hover_actions.dart';
/// The header words of an automated prompt.
String chatAutomatedPromptLabel(ChatPromptOrigin origin) => switch (origin) {
ChatPromptOrigin.followup => 'Follow-up from agent',
ChatPromptOrigin.autoContinue => 'Auto-continue after limit reset',
ChatPromptOrigin.autoSwitch => 'Continued on another account',
_ => '',
};
IconData _icon(ChatPromptOrigin origin) => switch (origin) {
ChatPromptOrigin.followup => Icons.update,
ChatPromptOrigin.autoContinue => Icons.autorenew,
_ => Icons.swap_horiz,
};
/// A prompt the agent or the server sent on the operator's behalf. It is not
/// the operator's filled bubble: a quiet outlined card on the agent's side,
/// headed by what sent it (and, for a follow-up, when the agent scheduled it
/// or what run it waited for), with the prompt's [body] beneath. [footer]
/// (its delivery line) and the time sit under the card with its Copy.
class ChatAutomatedPromptCard extends StatelessWidget {
const ChatAutomatedPromptCard({
super.key,
required this.prompt,
required this.body,
this.footer = const [],
this.timestamp,
});
final ChatAutomatedPrompt prompt;
final Widget body;
final List<Widget> footer;
final Widget? timestamp;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final label = chatAutomatedPromptLabel(prompt.origin);
final detail = switch (prompt) {
ChatAutomatedPrompt(:final condition?) => 'when $condition',
ChatAutomatedPrompt(:final scheduledAt?) =>
'scheduled ${chatScheduleTime(context, scheduledAt)}',
_ => null,
};
final muted = theme.textTheme.labelMedium?.copyWith(
color: scheme.onSurfaceVariant,
);
final header = SelectionContainer.disabled(
child: Wrap(
key: const Key('chat-automated-prompt-header'),
spacing: 6,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Icon(_icon(prompt.origin), size: 16, color: scheme.tertiary),
Text(label, style: muted?.copyWith(fontWeight: FontWeight.w600)),
if (detail != null) Text('· $detail', style: muted),
],
),
);
final card = Material(
key: const Key('chat-automated-prompt'),
color: scheme.surfaceContainerLow,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.all(Radius.circular(16)),
side: BorderSide(color: scheme.outlineVariant),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(14, 8, 14, 10),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
header,
if (prompt.body.trim().isNotEmpty) ...[
const SizedBox(height: 4),
DefaultTextStyle.merge(
style: theme.textTheme.bodyMedium,
child: body,
),
],
],
),
),
);
final copy = prompt.body.trim().isEmpty
? null
: ChatHoverReveal(child: ChatCopyButton(text: prompt.body.trim()));
return ChatHoverRegion(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
card,
if (footer.isNotEmpty || timestamp != null || copy != null)
Padding(
padding: const EdgeInsetsDirectional.only(start: 14, top: 2),
child: Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [...footer, ?timestamp, ?copy],
),
),
],
),
);
}
}
/// The small "Scheduled" mark under the operator's own message they had
/// scheduled to send later, once it is no longer waiting.
class ChatScheduledMark extends StatelessWidget {
const ChatScheduledMark({super.key});
@override
Widget build(BuildContext context) {
final style = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
return SelectionContainer.disabled(
child: Semantics(
container: true,
label: 'Scheduled message',
excludeSemantics: true,
child: Row(
key: const Key('chat-scheduled-mark'),
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.schedule_send,
size: (style?.fontSize ?? 12) + 2,
color: style?.color,
),
const SizedBox(width: 4),
Text('Scheduled', style: style),
],
),
),
);
}
}
@@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../data/chat_attachment_images.dart';
import 'chat_attachment_gallery.dart';
import 'chat_automated_prompt.dart';
import '../../domain/chat_prompt_origin.dart';
import '../../domain/chat_tool_calls.dart';
import '../../domain/chat_transcript.dart';
import 'chat_copy_button.dart';
@@ -31,8 +33,14 @@ class ChatMessageView extends StatelessWidget {
this.footer = const [],
this.images,
this.speechScope = 'chat',
this.scheduleShown = false,
});
/// Whether [footer] already says the message is scheduled (its delivery
/// line reads "Scheduled · sends at …"), so the operator's own scheduled
/// message needs no second mark.
final bool scheduleShown;
final JsonMap row;
/// Names the conversation in the reader's message ids, so leaving it can
@@ -53,7 +61,17 @@ class ChatMessageView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final user = row['kind'] == 'user';
final role = user ? 'User' : 'Assistant';
final origin = user
? chatPromptOrigin(_userMessage)
: ChatPromptOrigin.operator;
// A prompt the agent or the server sent reads as neither side's turn: a
// quiet card on the agent's side, headed by what sent it.
final automated = origin.automated;
final role = automated
? chatAutomatedPromptLabel(origin)
: user
? 'User'
: 'Assistant';
final content = user ? _userParts(context) : _agentParts(context);
// A wide window draws an answer's Copy in the gutter left of the reading
// column; without room it trails the time in the answer's footer.
@@ -78,7 +96,7 @@ class ChatMessageView extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 6),
child: LayoutBuilder(
builder: (context, constraints) => Align(
alignment: user
alignment: user && !automated
? AlignmentDirectional.centerEnd
: AlignmentDirectional.centerStart,
child: ConstrainedBox(
@@ -90,8 +108,10 @@ class ChatMessageView extends StatelessWidget {
? (constraints.maxWidth * 0.85).clamp(0, 560).toDouble()
: 720 + gutter,
),
child: user
? _userTurn(content, body)
child: automated
? _automatedTurn(origin, content)
: user
? _userTurn(content, body, origin)
: _agentRow(
context,
content,
@@ -115,7 +135,7 @@ class ChatMessageView extends StatelessWidget {
/// Attached images sit above the operator's bubble, as their own thumbnails;
/// an images-only turn draws no empty bubble. The footer (the delivery line)
/// sits under the bubble's trailing corner.
Widget _userTurn(List<Widget> content, Widget body) {
Widget _userTurn(List<Widget> content, Widget body, ChatPromptOrigin origin) {
final thumbnails = [
for (final part in _partsOf(_userMessage))
if (_isFile(part) && chatPartIsThumbnail(part)) part,
@@ -124,7 +144,8 @@ class ChatMessageView extends StatelessWidget {
createdAt: chatMessageCreatedAt(_userMessage),
);
final hasTimestamp = chatMessageCreatedAt(_userMessage) != null;
if (thumbnails.isEmpty && footer.isEmpty && !hasTimestamp) {
final marked = origin == ChatPromptOrigin.scheduled && !scheduleShown;
if (thumbnails.isEmpty && footer.isEmpty && !hasTimestamp && !marked) {
return ChatUserBubble(child: body);
}
return Column(
@@ -141,27 +162,53 @@ class ChatMessageView extends StatelessWidget {
if (content.isNotEmpty || thumbnails.isEmpty)
ChatUserBubble(child: body),
// The delivery line and the time share one line under the bubble.
if (footer.isNotEmpty || hasTimestamp) ...[
if (footer.isNotEmpty || hasTimestamp || marked) ...[
const SizedBox(height: 2),
Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: [...footer, if (hasTimestamp) timestamp],
children: [
...footer,
if (marked) const ChatScheduledMark(),
if (hasTimestamp) timestamp,
],
),
],
],
);
}
/// A prompt the agent or the server sent: its card, with the delivery line
/// and time beneath.
Widget _automatedTurn(ChatPromptOrigin origin, List<Widget> content) {
final created = chatMessageCreatedAt(_userMessage);
return ChatAutomatedPromptCard(
prompt: chatAutomatedPrompt(origin, _userText(_userMessage)),
body: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: content,
),
footer: footer,
timestamp: created == null
? null
: ChatMessageTimestamp(createdAt: created),
);
}
/// The user turn's text parts joined as its row draws them.
static String _userText(JsonMap message) => _partsOf(message)
.where((part) => part['type'] == null || part['type'] == 'text')
.map((part) => '${part['text'] ?? ''}')
.join('\n');
List<Widget> _userParts(BuildContext context) {
final message = _userMessage;
final parts = _partsOf(message);
final text = parts
.where((part) => part['type'] == null || part['type'] == 'text')
.map((part) => '${part['text'] ?? ''}')
.join('\n');
final automated = chatPromptOrigin(message).automated;
final text = chatPromptDisplayText(message, _userText(message));
final widgets = <Widget>[
if (text.trim().isNotEmpty) ChatLinkText(text),
for (final part in parts.where(_isFile))
@@ -173,7 +220,7 @@ class ChatMessageView extends StatelessWidget {
_unrecognised(part),
];
final client = '${message['client'] ?? ''}'.trim();
if (client.isNotEmpty) {
if (client.isNotEmpty && !automated) {
widgets.insert(0, Text(client, style: _clientStyle(context)));
}
return widgets;
@@ -0,0 +1,109 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_find.dart';
import 'package:pipelines_app/features/chat/domain/chat_prompt_origin.dart';
Map<String, dynamic> _user(
String text, [
Map<String, dynamic> extra = const {},
]) => {
'id': 'u1',
'role': 'user',
'parts': [
{'type': 'text', 'text': text},
],
...extra,
};
const _followup =
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup] '
'Check the deploy.';
void main() {
test('the server origin names who sent a user turn', () {
expect(
chatPromptOrigin(_user('x', {'origin': 'followup'})),
ChatPromptOrigin.followup,
);
expect(
chatPromptOrigin(_user('continue', {'origin': 'auto_continue'})),
ChatPromptOrigin.autoContinue,
);
expect(
chatPromptOrigin(_user('x', {'origin': 'auto_switch'})),
ChatPromptOrigin.autoSwitch,
);
expect(
chatPromptOrigin(_user('x', {'origin': 'scheduled'})),
ChatPromptOrigin.scheduled,
);
expect(chatPromptOrigin(_user('hello')), ChatPromptOrigin.operator);
});
test('an older server is read from operation ids and its own text', () {
expect(
chatPromptOrigin(_user('x', {'operation_id': 'followup-ab12'})),
ChatPromptOrigin.followup,
);
expect(
chatPromptOrigin(_user('again', {'operation_id': 'auto-continue-m1'})),
ChatPromptOrigin.autoContinue,
);
expect(
chatPromptOrigin(_user('x', {'operation_id': 'auto-switch-m1'})),
ChatPromptOrigin.autoSwitch,
);
expect(chatPromptOrigin(_user(_followup)), ChatPromptOrigin.followup);
expect(
chatPromptOrigin(
_user('[Sent automatically by Pipelines] Usage ran out'),
),
ChatPromptOrigin.autoSwitch,
);
expect(
chatPromptOrigin(_user('later', {'send_at': 1764756000000})),
ChatPromptOrigin.scheduled,
);
expect(
chatPromptOrigin(_user('see [Follow-up you scheduled at noon]')),
ChatPromptOrigin.operator,
);
});
test('a follow-up preamble becomes the header facts', () {
final plain = chatAutomatedPrompt(ChatPromptOrigin.followup, _followup);
expect(plain.body, 'Check the deploy.');
expect(plain.scheduledAt, DateTime.utc(2026, 12, 3, 10).toLocal());
expect(plain.condition, isNull);
final run = chatAutomatedPrompt(
ChatPromptOrigin.followup,
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup, '
'for when run 42 needs the operator or finishes; delivered at '
'2026-12-04T10:00:00Z at the latest] Review it.\n\n'
'[Pipelines: run 42 is now succeeded; read it with pipelines inspect 42.]',
);
expect(run.condition, 'run 42 needs the operator or finishes');
expect(run.body, startsWith('Review it.\n\n[Pipelines: run 42'));
final unknown = chatAutomatedPrompt(ChatPromptOrigin.followup, 'raw');
expect(unknown.body, 'raw');
expect(
chatAutomatedPrompt(
ChatPromptOrigin.autoSwitch,
'[Sent automatically by Pipelines] Usage ran out.',
).body,
'Usage ran out.',
);
});
test('find searches the text a follow-up draws', () {
final units = chatFindUnits(
[
{'kind': 'user', 'key': 'u1', 'message': _user(_followup)},
{'kind': 'user', 'key': 'u2', 'message': _user('mine')},
],
['u1', 'u2'],
);
expect(units.map((unit) => unit.text), ['Check the deploy.', 'mine']);
});
}
@@ -0,0 +1,183 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
JsonMap _row(Map<String, dynamic> message) => {
'kind': 'user',
'key': message['id'],
'message': message,
};
JsonMap _message(String text, [Map<String, dynamic> extra = const {}]) => {
'id': 'u1',
'role': 'user',
'created_at': DateTime.utc(2026, 12, 3, 11).millisecondsSinceEpoch,
'client': 'Agent follow-up',
'parts': [
{'type': 'text', 'text': text},
],
...extra,
};
const _followup =
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup] '
'Check the deploy finished.';
Widget _host(
JsonMap row, {
Brightness brightness = Brightness.light,
bool scheduleShown = false,
}) => MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(
body: ListView(
children: [ChatMessageView(row: row, scheduleShown: scheduleShown)],
),
),
);
void _wide(WidgetTester tester) {
tester.view.physicalSize = const Size(1000, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
void main() {
for (final brightness in Brightness.values) {
testWidgets('an agent follow-up is a quiet card on the agent side '
'(${brightness.name})', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(
_row(_message(_followup, {'origin': 'followup'})),
brightness: brightness,
),
);
expect(find.byType(ChatUserBubble), findsNothing);
final card = find.byKey(const Key('chat-automated-prompt'));
expect(card, findsOneWidget);
expect(find.text('Follow-up from agent'), findsOneWidget);
expect(find.textContaining('· scheduled '), findsOneWidget);
expect(find.byIcon(Icons.update), findsOneWidget);
// The preamble is header facts, not body text; the sender label is not
// repeated inside the card.
expect(find.text('Check the deploy finished.'), findsOneWidget);
expect(find.textContaining('[Follow-up'), findsNothing);
expect(find.text('Agent follow-up'), findsNothing);
// Start-aligned, not on the operator's trailing side.
expect(tester.getTopLeft(card).dx, lessThan(40));
final material = tester.widget<Material>(card);
final scheme = Theme.of(tester.element(card)).colorScheme;
expect(material.color, scheme.surfaceContainerLow);
expect(
(material.shape! as RoundedRectangleBorder).side.color,
scheme.outlineVariant,
);
expect(
find.bySemanticsLabel('Follow-up from agent message'),
findsOneWidget,
);
});
}
testWidgets('the follow-up body stays selectable and copies without the '
'preamble', (tester) async {
_wide(tester);
String? copied;
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method == 'Clipboard.setData') {
copied = (call.arguments as Map)['text'] as String?;
}
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await tester.pumpWidget(
_host(_row(_message(_followup, {'operation_id': 'followup-ab'}))),
);
expect(
find.widgetWithText(SelectableText, 'Check the deploy finished.'),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('chat-message-copy')));
await tester.pump();
expect(copied, 'Check the deploy finished.');
await tester.pump(const Duration(seconds: 3));
});
testWidgets('auto-continue and auto-switch name the server', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(_row(_message('continue', {'origin': 'auto_continue'}))),
);
expect(find.text('Auto-continue after limit reset'), findsOneWidget);
expect(find.text('continue'), findsOneWidget);
await tester.pumpWidget(
_host(
_row(
_message('[Sent automatically by Pipelines] Usage ran out on a.', {
'operation_id': 'auto-switch-m1',
}),
),
),
);
expect(find.text('Continued on another account'), findsOneWidget);
expect(find.text('Usage ran out on a.'), findsOneWidget);
});
testWidgets('a run follow-up says what it waited for', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(
_row(
_message(
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with '
'schedule_followup, for when run 42 finishes; delivered at '
'2026-12-04T10:00:00Z at the latest] Review it.',
),
),
),
);
expect(find.text('· when run 42 finishes'), findsOneWidget);
expect(find.text('Review it.'), findsOneWidget);
});
testWidgets("the operator's scheduled message keeps its bubble with a mark", (
tester,
) async {
_wide(tester);
final row = _row(
_message('send this later', {'origin': 'scheduled', 'client': 'Laptop'}),
);
await tester.pumpWidget(_host(row));
expect(find.byType(ChatUserBubble), findsOneWidget);
expect(find.byKey(const Key('chat-automated-prompt')), findsNothing);
expect(find.byKey(const Key('chat-scheduled-mark')), findsOneWidget);
expect(find.text('Laptop'), findsOneWidget);
// While the delivery line already reads "Scheduled · sends at", no mark.
await tester.pumpWidget(_host(row, scheduleShown: true));
expect(find.byKey(const Key('chat-scheduled-mark')), findsNothing);
});
testWidgets('an ordinary message is unchanged', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(_row(_message('hello', {'client': 'Phone'}))),
);
expect(find.byType(ChatUserBubble), findsOneWidget);
expect(find.byKey(const Key('chat-scheduled-mark')), findsNothing);
expect(find.byKey(const Key('chat-automated-prompt')), findsNothing);
expect(find.bySemanticsLabel('User message'), findsOneWidget);
});
}
+82
View File
@@ -0,0 +1,82 @@
import 'package:pipelines_app/core/api_gateway.dart';
/// `?followups=1`: the prompts the operator did not type just now, between
/// ordinary turns: an agent's follow-up (timed and run-triggered), the
/// server's auto-continue and account switch, and the operator's own
/// scheduled message.
List<JsonMap> chatFollowupMessages(String chat) {
var minute = 0;
int at() => DateTime.utc(2026, 12, 3, 9, minute += 7).millisecondsSinceEpoch;
JsonMap user(String id, String text, [JsonMap extra = const {}]) => {
'id': '$chat-fu-$id',
'role': 'user',
'created_at': at(),
'parts': [
{'type': 'text', 'text': text},
],
...extra,
};
JsonMap reply(String id, String text) => {
'id': '$chat-fu-$id',
'role': 'assistant',
'created_at': at(),
'parts': [
{'type': 'text', 'text': text},
],
};
return [
user('q', 'Deploy the release and keep an eye on it.', {
'client': 'Laptop',
}),
reply(
'a1',
'Started run 42. I scheduled a follow-up to check it in 30 minutes.',
),
user(
'f1',
'[Follow-up you scheduled at 2026-12-03T09:14:00Z with '
'schedule_followup] Check whether run 42 finished and report the '
'deploy status.',
{
'client': 'Agent follow-up',
'operation_id': 'followup-1a2b',
'origin': 'followup',
},
),
reply('a2', 'Run 42 finished; the deploy is healthy.'),
user(
'f2',
'[Follow-up you scheduled at 2026-12-03T09:28:00Z with '
'schedule_followup, for when run 43 finishes; delivered at '
'2026-12-04T09:28:00Z at the latest] Review the canary results.'
'\n\n[Pipelines: run 43 is now succeeded; read it with pipelines '
'inspect 43.]',
{'client': 'Agent follow-up', 'origin': 'followup'},
),
reply('a3', 'You\'ve hit your 5-hour limit · resets 2pm'),
user('c1', 'Review the canary results.', {
'client': 'Pipelines (automatic)',
'operation_id': 'auto-continue-a3',
'origin': 'auto_continue',
}),
reply('a4', 'The canary results look good.'),
user(
's1',
'[Sent automatically by Pipelines] Usage ran out on ada@example.com, '
'so Pipelines switched this chat to bob@example.com. Before '
'continuing: briefly check your progress against my original '
'request and your plan.',
{
'client': 'Pipelines (automatic)',
'operation_id': 'auto-switch-a4',
'origin': 'auto_switch',
},
),
reply('a5', 'Still on track; continuing.'),
user('l1', 'Summarise the release for the team channel.', {
'client': 'Laptop',
'origin': 'scheduled',
}),
reply('a6', 'Here is the summary for the team channel.'),
];
}
+4
View File
@@ -20,9 +20,12 @@
// `?tables=1` answers carry a wrapping table, one with a long token and
// one too wide for a phone (it scrolls sideways);
// `?timestamps=1` messages carry recorded times over two calendar days.
// `?followups=1` appends agent follow-ups, auto-continue/switch prompts and
// a scheduled operator message (chat_followup_fixture.dart).
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
import 'chat_followup_fixture.dart';
Map<String, String> _params = const {};
@@ -275,6 +278,7 @@ JsonMap chatScrollHistory(String sessionId, int index, String cursor) {
for (var i = 0; i < messages.length; i++)
_timed(messages[i], i, messages.length),
if (_bgwork) ..._backgroundWork(sessionId),
if (_params['followups'] == '1') ...chatFollowupMessages(sessionId),
],
'next_cursor': _older ? 'older' : '',
'has_more': _older,