Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge batch 11-03 bn: #2690 (#2710)

0xken1551037678b1c9
diff --git a/docs/plans/2026-11-03-phone-special-rows-plan.md b/docs/plans/2026-11-03-phone-special-rows-plan.md
new file mode 100644
index 000000000..722bb14da
--- /dev/null
+++ b/docs/plans/2026-11-03-phone-special-rows-plan.md
@@ -0,0 +1,77 @@
+# Phone: special message rows drawn as Desktop draws them Implementation Plan
+
+> **Way of working:** by this project's instructions (Engineer role), not subagent-driven-development: each failing test committed before its code, the branch pushed after each task, one independent review of the pull request. There is no Execution Handoff.
+
+**Goal:** 'Routed to', terminal input and alerts, proposals, Excerpt and 'Response interrupted' stop looking like ordinary messages on the phone, and each reads as it does on Desktop.
+
+**Architecture:** `SwarmMessageRow` already hands task lines and ship rows to their own widgets. It does the same for three more kinds, in a new `swarm_special_rows.dart`, and adds Desktop's small lines to an ordinary row. The words and rules are Desktop's (`route_row.dart`, `terminal_row.dart`, `task_line.dart`, `message_row.dart`, `view.dart`).
+
+**Tech Stack:** Flutter widgets and `flutter_test`, in `mobile/`.
+
+**Spec:** Task #2284 (Tony).
+
+## Global Constraints
+
+- The PR body starts with: Requested by [email protected] through Harness.
+- Mobile only. No new colors or icons beyond the phone's existing set. Phone tests use fakes. Never install on a phone. No on/off switch.
+
+## Sketch
+
+```
+ Routed to River Details no avatar, no name, quiet
+ (Details open) the pick, why, how it was chosen, who else was considered
+
+ ⌨ River typed `2` + Enter into Nico's terminal quiet, what was typed in mono
+ ⚠ Nico is waiting at a prompt quiet, the mark in warning colour
+ ⚠ River hit its usage limit until 18:00
+
+ › Proposal from diego: Activity read fix one line; a tap opens its thread
+
+ In that thread, the proposal reads whole:
+ ◉ Buddy 8:02
+ [Proposal · on diego's behalf]
+ Goal: Activity read fix …
+
+ ◉ Nico 8:12
+ Terminal answer quiet line above a terminal's answer
+ The build passed.
+
+ ◉ Nico 8:12
+ The build passed…
+ Excerpt · open the terminal for the full response quiet line under it
+ Response interrupted (or this one)
+```
+
+## Review Focus
+
+- A route row from an older server with no decision id, or a pick that isn't well formed, is an ordinary message, as on Desktop.
+- Route details that fail to load say so and offer Retry.
+- What was typed containing backticks shows whole: only the first and last are the wrapper.
+- A proposal's owner who left the Swarm reads "its owner".
+- None of these rows groups with the message before it, and a terminal answer groups only with one of the same note.
+
+Not in this task: Desktop's Switch PM… on a PM's limit note. The phone has no Switch PM screen, so the note says the limit and its time alone.
+
+## Design
+
+- **Growth, concurrency, migration, audience, identity:** N/A because this only draws what the reader already reads; route details use the checked read Desktop uses.
+- **Read cost:** route details read only when opened, once.
+- **Scale:** N/A because the rows are built as today's are.
+- **Compatibility:** a kind the phone doesn't know stays an ordinary message.
+- **Failure:** a failed details read says so, with Retry.
+- **Platforms:** iOS and Android share these rows.
+
+---
+
+### Task 1: The rows
+
+**Files:**
+- Create: `mobile/lib/swarm/swarm_special_rows.dart`
+- Modify: `mobile/lib/swarm/swarm_message_row.dart`, `mobile/lib/swarm/swarm_conversation_page.dart`
+- Test: `mobile/test/swarm/swarm_special_rows_test.dart`
+
+- [ ] **Step 1: Write the failing tests,** one per kind: route, terminal input, terminal alert, proposal, proposal in its thread, terminal answer, Excerpt, Response interrupted; and the Review Focus lines above.
+- [ ] **Step 2: Run to verify they fail.** Run: `flutter test test/swarm/swarm_special_rows_test.dart`. Expected: FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run to verify they pass,** then `flutter test test/swarm`.
+- [ ] **Step 5: Commit** the test first, then the code; push. Add screenshots to the PR.
diff --git a/mobile/lib/swarm/model.dart b/mobile/lib/swarm/model.dart
index 6b8767e29..791678939 100644
--- a/mobile/lib/swarm/model.dart
+++ b/mobile/lib/swarm/model.dart
@@ -1279,6 +1279,15 @@ class SuperTabMessage {
? source['agentId'] as String?
: null;
+ /// The Product Manager a usage-limit note is about; null for any other row
+ /// (desktop model.dart).
+ String? get leadLimitAgentId =>
+ source['kind'] == 'terminal-alert' &&
+ source['alert'] == 'limit' &&
+ source['lead'] == true
+ ? source['agentId'] as String?
+ : null;
+
/// A note the backend writes about a terminal: a Lead's typing, or an alert.
bool get terminalEvent =>
source['kind'] == 'terminal-input' || source['kind'] == 'terminal-alert';
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dart
index fc1686eb0..8c2e0646d 100644
--- a/mobile/lib/swarm/swarm_conversation_page.dart
+++ b/mobile/lib/swarm/swarm_conversation_page.dart
@@ -1983,6 +1983,9 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>
? () => _openThread(c, root)
: () => _reply(c, m),
inThread: root != null,
+ onOpenProposal: m.proposalOwnerId == null
+ ? null
+ : () => _openThread(c, m.id),
card: card == null
? null
: SwarmLiveCard(
@@ -2821,6 +2824,9 @@ Set<String> swarmGroupedMessages(List<SuperTabMessage> messages) {
bool plain(SuperTabMessage m) =>
!swarmIsTaskLine(m) &&
m.source['kind'] != 'ship' &&
+ m.route == null &&
+ !m.terminalEvent &&
+ m.proposalOwnerId == null &&
m.replyTo == null &&
m.text.length <= 280 &&
!m.text.contains('\n') &&
@@ -2830,6 +2836,7 @@ Set<String> swarmGroupedMessages(List<SuperTabMessage> messages) {
!plain(previous) ||
current.authorId.isEmpty ||
current.authorId != previous.authorId ||
+ current.terminalNote != previous.terminalNote ||
current.authorName != previous.authorName ||
current.author['kind'] != previous.author['kind'] ||
current.author['membershipGeneration'] !=
diff --git a/mobile/lib/swarm/swarm_message_row.dart b/mobile/lib/swarm/swarm_message_row.dart
index 9023d3596..c72111bd7 100644
--- a/mobile/lib/swarm/swarm_message_row.dart
+++ b/mobile/lib/swarm/swarm_message_row.dart
@@ -23,6 +23,7 @@ import 'swarm_message_text.dart';
import 'swarm_message_style.dart';
import 'swarm_face.dart';
import 'swarm_ship_row.dart';
+import 'swarm_special_rows.dart';
import 'swarm_task_line.dart';
/// `@name` or `@name@domain`, as people tag in chat. Never right after a
@@ -275,6 +276,7 @@ class SwarmMessageRow extends StatelessWidget {
this.card,
this.onLongPress,
this.onOpenTask,
+ this.onOpenProposal,
this.references = const {},
this.onOpenConversation,
});
@@ -313,6 +315,10 @@ class SwarmMessageRow extends StatelessWidget {
/// Opens a task held by the current reader; null for an unavailable target.
final VoidCallback? onOpenTask;
+ /// Opens a Buddy's proposal's thread: given in the chat, where a proposal is
+ /// one line; none in its thread, where it reads whole.
+ final VoidCallback? onOpenProposal;
+
/// The numbered conversations `#N` links in a message can open.
final Map<int, String> references;
@@ -385,6 +391,21 @@ class SwarmMessageRow extends StatelessWidget {
message: message,
);
}
+ // Notes that are not chat from their author, as Desktop draws them.
+ final special = ValueKey('swarm-message-${message.id}');
+ if (message.proposalOwnerId != null && onOpenProposal != null) {
+ return SwarmProposalLine(
+ key: special,
+ message: message,
+ onOpen: onOpenProposal!,
+ );
+ }
+ if (message.terminalEvent) {
+ return SwarmTerminalRow(key: special, message: message);
+ }
+ if (message.route case final route?) {
+ return SwarmRouteRow(key: special, message: message, route: route);
+ }
// A row kept as it was is not built again: it follows a theme or font
// change itself.
AppTheme.watch(context);
@@ -420,6 +441,9 @@ class SwarmMessageRow extends StatelessWidget {
body: [
if (lit) SizedBox(key: ValueKey('swarm-lit-${message.id}')),
?quote,
+ if (message.proposalOwnerId != null)
+ SwarmProposalLabel(owner: swarmProposalOwner(context, message)),
+ ?swarmTerminalNote(message),
for (final part in swarmTextParts(message.text))
if (part.code)
SwarmCodeBlock(code: part.text, name: part.name, onTap: onTap)
@@ -436,6 +460,7 @@ class SwarmMessageRow extends StatelessWidget {
onOpenConversation: onOpenConversation,
),
),
+ ?swarmCutShort(message),
for (final file in message.attachments) _attachment(context, file),
?card,
?reactions,
diff --git a/mobile/lib/swarm/swarm_special_rows.dart b/mobile/lib/swarm/swarm_special_rows.dart
new file mode 100644
index 000000000..8574903be
--- /dev/null
+++ b/mobile/lib/swarm/swarm_special_rows.dart
@@ -0,0 +1,420 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/core/relative_time.dart';
+import 'package:harness_mobile/shared/theme/app_space.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+import 'model.dart';
+import 'swarm_message_row.dart' show SwarmMessageFrame, swarmChatText;
+import 'swarm_reader.dart';
+import 'swarm_session.dart';
+
+// The notes in a chat that are not chat from their author, drawn as Desktop
+// draws them: a routing note (route_row.dart), a note about a terminal
+// (terminal_row.dart), and a Buddy's proposal as one line that opens its
+// thread (task_line.dart). Each has no author heading, reply or receipt.
+
+/// The reader of the Swarm whose chat [conversationId] is; null until one is
+/// read (as the ship card finds its people).
+SwarmReader? swarmReaderOf(BuildContext context, String conversationId) {
+ final inbox = SwarmScope.of(context)?.inbox;
+ if (inbox == null) return null;
+ for (final swarm in inbox.swarms) {
+ final reader = inbox.reader(swarm.id);
+ if (reader?.snapshot?.conversation(conversationId) != null) return reader;
+ }
+ return null;
+}
+
+TextStyle _quiet() => swarmChatText(14, color: AppPalette.textSecondary);
+
+/// A note's place: under a message's text, past the avatar's column.
+const EdgeInsets _inset = EdgeInsets.fromLTRB(
+ AppSpace.s + SwarmMessageFrame.column,
+ AppSpace.xs,
+ AppSpace.s,
+ AppSpace.xs,
+);
+
+/// A quiet action beside a note, a finger's size.
+class _NoteAction extends StatelessWidget {
+ const _NoteAction({required this.label, required this.onTap});
+ final String label;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) => Semantics(
+ button: true,
+ label: label,
+ excludeSemantics: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 44, minWidth: 44),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: AppSpace.s),
+ child: Center(
+ widthFactor: 1,
+ child: Text(
+ label,
+ style: swarmChatText(14, color: AppPalette.accentOnSurface),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+}
+
+/// "Routed to …" with Details, read only (Desktop's `SuperTabRouteRow`).
+class SwarmRouteRow extends StatefulWidget {
+ const SwarmRouteRow({super.key, required this.message, required this.route});
+ final SuperTabMessage message;
+ final SuperTabRoute route;
+
+ @override
+ State<SwarmRouteRow> createState() => _SwarmRouteRowState();
+}
+
+class _SwarmRouteRowState extends State<SwarmRouteRow> {
+ Map<String, dynamic>? _details;
+ bool _expanded = false, _loading = false, _failed = false;
+
+ /// The CLI's titleOf writes "name · engine model effort · machine"; a name
+ /// with separators, or a title in another form, is kept whole.
+ String get _target {
+ final title = widget.route.pick.title;
+ final parts = RegExp(r'^(.*) · ((?:Claude|Codex) .*) · (.*)$')
+ .firstMatch(title);
+ if (parts == null) return title;
+ final name = parts.group(1)!;
+ return name == 'New agent'
+ ? 'new ${parts.group(2)!.split(' ').first} agent'
+ : name;
+ }
+
+ String get _how => switch (widget.route.via) {
+ 'jev' => 'Jev ${((widget.route.p ?? 0) * 100).round()}%',
+ 'only' => 'Only available candidate',
+ _ => 'Ranked by strength, price and quota',
+ };
+
+ Future<void> _load() async {
+ if (_loading || _details != null) return;
+ final reader = swarmReaderOf(context, widget.message.conversationId);
+ setState(() {
+ _loading = true;
+ _failed = false;
+ });
+ try {
+ if (reader == null) throw StateError('No Swarm read yet');
+ final answer = superTabMap(
+ await reader.request(
+ 'GET',
+ '/api/super-tabs/${Uri.encodeComponent(reader.tabId)}/route-decisions/'
+ '${Uri.encodeComponent(widget.route.decisionId)}',
+ ),
+ );
+ if (mounted) setState(() => _details = answer);
+ } catch (_) {
+ if (mounted) setState(() => _failed = true);
+ } finally {
+ if (mounted) setState(() => _loading = false);
+ }
+ }
+
+ void _toggle() {
+ setState(() => _expanded = !_expanded);
+ if (_expanded) unawaited(_load());
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final style = _quiet();
+ return Padding(
+ padding: _inset,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Flexible(child: Text('Routed to $_target', style: style)),
+ Semantics(
+ expanded: _expanded,
+ child: _NoteAction(
+ label: _expanded ? 'Hide details' : 'Details',
+ onTap: _toggle,
+ ),
+ ),
+ ],
+ ),
+ if (_expanded) _detailsView(style),
+ ],
+ ),
+ );
+ }
+
+ Widget _detailsView(TextStyle style) {
+ Text line(String words) => Text(words, style: style);
+ final r = widget.route;
+ final record = superTabMap(_details?['record'] ?? const {});
+ final candidates = (record['candidates'] as List? ?? const []).map(
+ superTabMap,
+ );
+ final excluded = (record['excluded'] as List? ?? const []).map(superTabMap);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ spacing: AppSpace.xs,
+ children: [
+ line(r.pick.title),
+ if (r.why.isNotEmpty) line(r.why),
+ line('Selection: $_how'),
+ if (_loading) line('Loading details…'),
+ if (_failed)
+ Row(
+ children: [
+ Flexible(child: line('Could not load this decision.')),
+ _NoteAction(label: 'Retry', onTap: () => unawaited(_load())),
+ ],
+ ),
+ if (record['instructionsRevision'] case final num revision)
+ line(
+ revision == 0
+ ? 'Relied on the built-in instructions'
+ : 'Relied on instructions revision ${revision.toInt()}',
+ ),
+ if (candidates.isNotEmpty) ...[
+ line('Considered'),
+ for (final c in candidates)
+ if (c['title'] case final String title)
+ line(
+ [
+ title,
+ if (c['label'] case final String label) label,
+ ].join(' — '),
+ ),
+ ],
+ for (final e in excluded)
+ line('Unavailable: ${e['title']} — ${e['reason']}'),
+ ],
+ );
+ }
+}
+
+/// A Lead's typing into a worker's terminal, or a machine's alert about one
+/// (Desktop's `SuperTabTerminalRow`). Desktop's Switch PM… on a PM's limit
+/// note waits for the phone's Switch PM screen.
+class SwarmTerminalRow extends StatelessWidget {
+ const SwarmTerminalRow({super.key, required this.message});
+ final SuperTabMessage message;
+
+ /// The backend wraps what was typed in one pair of backticks, and the text
+ /// inside is as typed, backticks included: the first and the last are the
+ /// wrapper, and what lies between is shown whole, in the terminal's face.
+ static TextSpan typed(String text, TextStyle style) {
+ final open = text.indexOf('`'), close = text.lastIndexOf('`');
+ if (open < 0 || close == open) return TextSpan(text: text);
+ return TextSpan(
+ children: [
+ TextSpan(text: text.substring(0, open)),
+ TextSpan(
+ text: text.substring(open + 1, close),
+ style: style.copyWith(fontFamily: AppFont.mono),
+ ),
+ TextSpan(text: text.substring(close + 1)),
+ ],
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final alert = message.source['kind'] != 'terminal-input';
+ final style = _quiet();
+ // Only the coordinator's: a worker's note says its time in its own words.
+ final until = message.leadLimitAgentId != null
+ ? DateTime.tryParse(message.source['limitedUntil'] as String? ?? '')
+ : null;
+ return Padding(
+ padding: EdgeInsets.fromLTRB(
+ AppSpace.s,
+ _inset.top,
+ _inset.right,
+ _inset.bottom,
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ width: SwarmMessageFrame.column,
+ child: Align(
+ alignment: Alignment.topRight,
+ child: Padding(
+ padding: const EdgeInsets.only(right: AppSpace.s),
+ child: Icon(
+ alert
+ ? LucideIcons.triangleAlert300
+ : LucideIcons.keyboard300,
+ size: 15,
+ color: alert ? AppPalette.warn : style.color,
+ ),
+ ),
+ ),
+ ),
+ Expanded(
+ child: Text.rich(
+ TextSpan(
+ children: [
+ typed(message.text, style),
+ if (until != null) TextSpan(text: ' until ${_time(until)}'),
+ ],
+ ),
+ style: style,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+/// The time when [at] is today, else the date and time, in local time.
+String _time(DateTime at) {
+ final local = at.toLocal(), today = DateTime.now();
+ if (local.year == today.year &&
+ local.month == today.month &&
+ local.day == today.day) {
+ String two(int n) => n.toString().padLeft(2, '0');
+ return '${two(local.hour)}:${two(local.minute)}';
+ }
+ return fullDateTime(at);
+}
+
+/// The person a proposal speaks for, by username; "its owner" for one no
+/// longer in the Swarm (Desktop's `buddyPersonName`).
+String swarmProposalOwner(BuildContext context, SuperTabMessage message) {
+ final id = message.proposalOwnerId!;
+ return swarmReaderOf(
+ context,
+ message.conversationId,
+ )?.snapshot?.people.where((p) => p.id == id).firstOrNull?.username ??
+ 'its owner';
+}
+
+/// A proposal's name: its Goal line, else its first line (Desktop's
+/// `_proposalName`).
+String swarmProposalName(String text) {
+ final lines = text.split('\n').map((line) => line.trim());
+ for (final line in lines) {
+ if (line.startsWith('Goal: ')) return line.substring(6).trim();
+ }
+ return lines.first;
+}
+
+/// "Proposal from dee: …", one line that opens its thread, where it reads
+/// whole (Desktop's `SuperTabProposalLine`, Quiet Swarm).
+class SwarmProposalLine extends StatelessWidget {
+ const SwarmProposalLine({
+ super.key,
+ required this.message,
+ required this.onOpen,
+ });
+ final SuperTabMessage message;
+ final VoidCallback onOpen;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final text =
+ 'Proposal from ${swarmProposalOwner(context, message)}: '
+ '${swarmProposalName(message.text)}';
+ return Semantics(
+ button: true,
+ label: text,
+ excludeSemantics: true,
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onTap: onOpen,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 44),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: AppSpace.l,
+ vertical: AppSpace.s,
+ ),
+ child: Row(
+ children: [
+ Icon(
+ LucideIcons.chevronRight300,
+ size: 16,
+ color: AppPalette.textSecondary,
+ ),
+ const SizedBox(width: AppSpace.s),
+ Expanded(
+ child: Text(
+ text,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: swarmChatText(16),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+/// Above a proposal read whole: whom it speaks for (Desktop's label).
+class SwarmProposalLabel extends StatelessWidget {
+ const SwarmProposalLabel({super.key, required this.owner});
+ final String owner;
+
+ @override
+ Widget build(BuildContext context) => Padding(
+ padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
+ child: Container(
+ key: const ValueKey('swarm-proposal-label'),
+ padding: const EdgeInsets.symmetric(horizontal: AppSpace.s),
+ decoration: BoxDecoration(
+ border: Border.all(color: AppPalette.textFaint),
+ borderRadius: BorderRadius.circular(AppSpace.s),
+ ),
+ child: Text("Proposal · on $owner's behalf", style: _quiet()),
+ ),
+ );
+}
+
+/// The quiet line a terminal's answer starts with, and the one under a
+/// response that was cut short (Desktop's view.dart).
+Widget? swarmTerminalNote(SuperTabMessage message) =>
+ switch (message.terminalNote) {
+ final note? => Padding(
+ padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
+ child: Text(note, style: _quiet()),
+ ),
+ null => null,
+ };
+
+Widget? swarmCutShort(SuperTabMessage message) {
+ final words = message.source['truncated'] == true
+ ? 'Excerpt · open the terminal for the full response'
+ : message.source['interrupted'] == true
+ ? 'Response interrupted'
+ : null;
+ return words == null
+ ? null
+ : Padding(
+ padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
+ child: Text(words, style: _quiet()),
+ );
+}
diff --git a/mobile/test/swarm/swarm_special_rows_shots_test.dart b/mobile/test/swarm/swarm_special_rows_shots_test.dart
new file mode 100644
index 000000000..678ff8b6f
--- /dev/null
+++ b/mobile/test/swarm/swarm_special_rows_shots_test.dart
@@ -0,0 +1,155 @@
+import 'dart:convert';
+import 'dart:io';
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/settings/experimental_features.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/theme/color_palette.dart';
+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+import 'package:harness_mobile/terminal/terminal_font_store.dart';
+
+import '../voice_fakes.dart';
+import 'swarm_fixture.dart';
+import 'swarm_special_rows_test.dart' show backend, routeSource, row;
+
+/// Review screenshots of the special rows (Tony's list, task 28), on a
+/// 390-point phone in both phone themes, from made-up data only, to the folder
+/// `SWARM_SPECIAL_ROWS_SHOTS` names.
+final shots = Platform.environment['SWARM_SPECIAL_ROWS_SHOTS'];
+void main() {
+ setUpAll(() async {
+ if (shots == null || !Platform.isMacOS) return;
+ final sf = ByteData.sublistView(
+ await File('/System/Library/Fonts/SFNS.ttf').readAsBytes(),
+ );
+ for (final family in {
+ '.AppleSystemUIFont',
+ 'Roboto',
+ AppFont.sans,
+ ...AppFont.sansFallback,
+ }) {
+ await (FontLoader(family)..addFont(Future.value(sf))).load();
+ }
+ // The tab's title is set in the terminal's face.
+ final mono = ByteData.sublistView(
+ await File('/System/Library/Fonts/SFNSMono.ttf').readAsBytes(),
+ );
+ final terminal = terminalFontStore.value;
+ for (final family in {
+ '.AppleSystemUIFontMonospaced',
+ 'monospace',
+ AppFont.mono,
+ ...AppFont.monoFallback,
+ terminal.fontFamily,
+ ...terminal.fontFamilyFallback,
+ }) {
+ await (FontLoader(family)..addFont(Future.value(mono))).load();
+ }
+ final manifest =
+ jsonDecode(await rootBundle.loadString('FontManifest.json')) as List;
+ for (final entry in manifest.cast<Map<String, dynamic>>()) {
+ final loader = FontLoader(entry['family'] as String);
+ for (final font in (entry['fonts'] as List).cast<Map>()) {
+ loader.addFont(rootBundle.load(font['asset'] as String));
+ }
+ await loader.load();
+ }
+ });
+
+ testWidgets('pictures of the special rows', (tester) async {
+ addTearDown(tester.view.reset);
+ debugDisableShadows = false;
+ tester.view.padding = const FakeViewPadding(top: 47 * 3, bottom: 34 * 3);
+ addTearDown(tester.view.resetPadding);
+ for (final palette in [HarnessPalette.graphite, HarnessPalette.paper]) {
+ tester.view
+ ..physicalSize = const Size(390, 844) * 3
+ ..devicePixelRatio = 3;
+ final brightness = palette.brightness;
+ AppTheme.palette.value = palette;
+ AppTheme.brightness.value = brightness;
+ final fake = backend([
+ row('m1', 1, 'Can someone take the login fix?', {
+ 'kind': 'message',
+ }, author: 'River'),
+ row('r1', 2, 'x', routeSource()),
+ row('t1', 3, 'River typed `2` + Enter into Nico\'s terminal', {
+ 'kind': 'terminal-input',
+ }),
+ row('t2', 4, 'Nico is waiting at a prompt', {
+ 'kind': 'terminal-alert',
+ 'alert': 'other',
+ }),
+ {
+ ...row('p1', 5, 'Asked by dee.\nGoal: Activity read fix', {
+ 'kind': 'buddy-proposal',
+ 'personId': me,
+ }, author: 'Buddy'),
+ 'thread': 'p1',
+ },
+ row('n1', 6, 'The build passed. 312 tests, no failures, and the …', {
+ 'kind': 'native',
+ 'truncated': true,
+ }, author: 'Nico'),
+ ]);
+ fake.routes['/api/super-tabs/$tab/route-decisions/d1'] = (_) => {
+ 'record': {'instructionsRevision': 7},
+ };
+ final account = ValueNotifier<String?>(me);
+ final host = SwarmHost(
+ accountId: () => me,
+ account: account,
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())
+ ..value = {PhoneExperiment.swarm},
+ )..foreground = false;
+ final boundary = GlobalKey();
+ await tester.pumpWidget(
+ RepaintBoundary(
+ key: boundary,
+ child: MaterialApp(
+ debugShowCheckedModeBanner: false,
+ theme: buildAppTheme(brightness: brightness),
+ builder: (_, child) => SwarmScope(notifier: host, child: child!),
+ home: const Scaffold(
+ body: SwarmConversationPage(
+ swarmId: tab,
+ conversationId: leadChat,
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(
+ find.descendant(
+ of: find.byKey(const ValueKey('swarm-message-r1')),
+ matching: find.text('Details'),
+ ),
+ );
+ await tester.pumpAndSettle();
+ if (shots != null) {
+ await tester.runAsync(() async {
+ final image =
+ await (boundary.currentContext!.findRenderObject()!
+ as RenderRepaintBoundary)
+ .toImage(pixelRatio: 3);
+ final png = await image.toByteData(format: ui.ImageByteFormat.png);
+ await File('$shots/special-rows-${brightness.name}.png')
+ .writeAsBytes(png!.buffer.asUint8List());
+ image.dispose();
+ });
+ }
+ await tester.pumpWidget(const SizedBox());
+ host.dispose();
+ }
+ debugDisableShadows = true;
+ }, skip: shots == null);
+}
diff --git a/mobile/test/swarm/swarm_special_rows_test.dart b/mobile/test/swarm/swarm_special_rows_test.dart
new file mode 100644
index 000000000..5a468c1bf
--- /dev/null
+++ b/mobile/test/swarm/swarm_special_rows_test.dart
@@ -0,0 +1,389 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/settings/experimental_features.dart';
+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+import 'package:harness_mobile/swarm/swarm_thread_page.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import '../voice_fakes.dart';
+import 'swarm_fixture.dart';
+
+// Literal server payloads, as Desktop's rows read them.
+Map<String, dynamic> row(
+ String id,
+ int sequence,
+ String text,
+ Map<String, dynamic> source, {
+ String author = 'River',
+}) => {
+ 'id': id,
+ 'conversationId': leadChat,
+ 'sequence': sequence,
+ 'text': text,
+ 'author': {'kind': 'agent', 'id': 'agent-$author', 'name': author},
+ 'createdAt': DateTime.utc(2026, 11, 2, 17, sequence).toIso8601String(),
+ 'source': source,
+};
+
+Map<String, dynamic> routeSource({Object? decision = 'd1'}) => {
+ 'kind': 'route',
+ 'decisionId': decision,
+ 'via': 'order',
+ 'why': 'A small fix',
+ 'pick': {'id': 'c0', 'title': 'Nico · Claude opus high · Mac Studio'},
+ 'alternatives': <Object>[],
+};
+
+const decisions = '/api/super-tabs/$tab/route-decisions/d1';
+
+FakeSwarm backend(List<Map<String, dynamic>> page) {
+ final fake = FakeSwarm();
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},
+ ],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(
+ groups: [
+ groupData(leadChat, title: 'Project chat', lastMessageSequence: 10),
+ ],
+ );
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(cursor: 'c2');
+ fake.routes['/api/super-tabs/$tab/decisions'] = (_) => {
+ 'decisions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/mentions'] = (_) => {
+ 'mentions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/conversations/$leadChat/messages'] = (_) =>
+ {'messages': page.reversed.toList(), 'threads': <Object>[], 'next': null};
+ return fake;
+}
+
+Future<void> show(WidgetTester tester, FakeSwarm fake) async {
+ await tester.binding.setSurfaceSize(const Size(390, 844));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ final account = ValueNotifier<String?>(me);
+ final host = SwarmHost(
+ accountId: () => account.value,
+ account: account,
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())
+ ..value = {PhoneExperiment.swarm},
+ readMarks: MemoryKeyValueStore(),
+ )..foreground = false;
+ addTearDown(host.dispose);
+ await tester.pumpWidget(
+ MaterialApp(
+ builder: (context, child) => SwarmScope(notifier: host, child: child!),
+ home: const SwarmConversationPage(swarmId: tab, conversationId: leadChat),
+ ),
+ );
+ await tester.pumpAndSettle();
+}
+
+Finder inRow(String id, Finder inner) => find.descendant(
+ of: find.byKey(ValueKey('swarm-message-$id')),
+ matching: inner,
+);
+
+/// The plain text of everything drawn in message [id].
+String textOf(WidgetTester tester, String id) => [
+ for (final text in tester.widgetList<RichText>(
+ inRow(id, find.byType(RichText)),
+ ))
+ text.text.toPlainText(),
+].join('\n');
+
+void main() {
+ group('a route row', () {
+ testWidgets('is a quiet line naming who it went to, with no author', (
+ tester,
+ ) async {
+ await show(
+ tester,
+ backend([row('r1', 2, 'Routed to Nico', routeSource())]),
+ );
+ expect(textOf(tester, 'r1'), contains('Routed to Nico'));
+ expect(inRow('r1', find.text('River')), findsNothing);
+ expect(inRow('r1', find.text('Details')), findsOneWidget);
+ });
+
+ testWidgets('a new agent reads as its engine', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('r1', 2, 'x', {
+ ...routeSource(),
+ 'pick': {'id': 'c0', 'title': 'New agent · Codex gpt high · Mac'},
+ }),
+ ]),
+ );
+ expect(textOf(tester, 'r1'), contains('Routed to new Codex agent'));
+ });
+
+ testWidgets('Details reads the decision once, and hides again', (
+ tester,
+ ) async {
+ final fake = backend([row('r1', 2, 'x', routeSource())]);
+ fake.routes[decisions] = (_) => {
+ 'record': {
+ 'instructionsRevision': 7,
+ 'candidates': [
+ {'title': 'Echo · Claude', 'label': 'busy'},
+ ],
+ 'excluded': [
+ {'title': 'Mac 3', 'reason': 'offline'},
+ ],
+ },
+ };
+ await show(tester, fake);
+ await tester.tap(inRow('r1', find.text('Details')));
+ await tester.pumpAndSettle();
+ for (final words in const [
+ 'Nico · Claude opus high · Mac Studio',
+ 'A small fix',
+ 'Selection: Ranked by strength, price and quota',
+ 'Relied on instructions revision 7',
+ 'Considered',
+ 'Echo · Claude — busy',
+ 'Unavailable: Mac 3 — offline',
+ ]) {
+ expect(inRow('r1', find.text(words)), findsOneWidget, reason: words);
+ }
+ await tester.tap(inRow('r1', find.text('Hide details')));
+ await tester.pumpAndSettle();
+ expect(inRow('r1', find.text('Considered')), findsNothing);
+ await tester.tap(inRow('r1', find.text('Details')));
+ await tester.pumpAndSettle();
+ expect(fake.paths.where((p) => p == decisions), hasLength(1));
+ });
+
+ testWidgets('a failed read says so, and Retry reads again', (tester) async {
+ final fake = backend([row('r1', 2, 'x', routeSource())]);
+ var fails = true;
+ fake.routes[decisions] = (_) {
+ if (fails) throw StateError('offline');
+ return {
+ 'record': {'instructionsRevision': 0},
+ };
+ };
+ await show(tester, fake);
+ await tester.tap(inRow('r1', find.text('Details')));
+ await tester.pumpAndSettle();
+ expect(
+ inRow('r1', find.text('Could not load this decision.')),
+ findsOneWidget,
+ );
+ fails = false;
+ await tester.tap(inRow('r1', find.text('Retry')));
+ await tester.pumpAndSettle();
+ expect(
+ inRow('r1', find.text('Relied on the built-in instructions')),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('one with no decision is an ordinary message', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('r1', 2, 'Routed somewhere', routeSource(decision: null)),
+ ]),
+ );
+ expect(inRow('r1', find.text('Details')), findsNothing);
+ expect(inRow('r1', find.text('River')), findsOneWidget);
+ });
+ });
+
+ group('a terminal note', () {
+ testWidgets('of input: a quiet line, what was typed in the mono face', (
+ tester,
+ ) async {
+ await show(
+ tester,
+ backend([
+ row('t1', 2, 'River typed `echo `date`` into the terminal', {
+ 'kind': 'terminal-input',
+ }),
+ ]),
+ );
+ expect(inRow('t1', find.byIcon(LucideIcons.keyboard300)), findsOneWidget);
+ expect(inRow('t1', find.text('River')), findsNothing);
+ // Only the first and last backtick are the wrapper.
+ final spans = <TextSpan>[];
+ for (final text in tester.widgetList<RichText>(
+ inRow('t1', find.byType(RichText)),
+ )) {
+ text.text.visitChildren((span) {
+ if (span is TextSpan) spans.add(span);
+ return true;
+ });
+ }
+ expect(
+ spans.where((s) => s.text == 'echo `date`').single.style?.fontFamily,
+ isNotNull,
+ );
+ });
+
+ testWidgets('of an alert: a warning mark, and no author', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('t1', 2, 'Nico is waiting at a prompt', {
+ 'kind': 'terminal-alert',
+ 'alert': 'other',
+ }),
+ ]),
+ );
+ expect(
+ inRow('t1', find.byIcon(LucideIcons.triangleAlert300)),
+ findsOneWidget,
+ );
+ expect(inRow('t1', find.text('River')), findsNothing);
+ });
+
+ testWidgets('of the coordinator\'s usage limit says until when', (
+ tester,
+ ) async {
+ await show(
+ tester,
+ backend([
+ row('t1', 2, 'River hit its usage limit', {
+ 'kind': 'terminal-alert',
+ 'alert': 'limit',
+ 'lead': true,
+ 'agentId': 'agent-River',
+ 'limitedUntil': DateTime(2026, 11, 3, 18, 5).toIso8601String(),
+ }),
+ ]),
+ );
+ expect(textOf(tester, 't1'), contains('until'));
+ expect(textOf(tester, 't1'), contains('18:05'));
+ });
+ });
+
+ testWidgets('a worker\'s usage limit says only what its text says', (
+ tester,
+ ) async {
+ await show(
+ tester,
+ backend([
+ row(
+ 't1',
+ 2,
+ 'Nico hit its usage limit. Routing skips it until 14:30 UTC.',
+ {
+ 'kind': 'terminal-alert',
+ 'alert': 'limit',
+ 'agentId': 'agent-Nico',
+ 'limitedUntil': DateTime.utc(2026, 11, 3, 14, 30).toIso8601String(),
+ },
+ ),
+ ]),
+ );
+ expect(textOf(tester, 't1'), endsWith('Routing skips it until 14:30 UTC.'));
+ });
+
+ group('a proposal', () {
+ // A message from threads on roots its own thread.
+ Map<String, dynamic> proposal() => {
+ ...row(
+ 'p1',
+ 2,
+ 'Asked by dee.\nGoal: Activity read fix\nChanges: more words',
+ {'kind': 'buddy-proposal', 'personId': me},
+ author: 'Buddy',
+ ),
+ 'thread': 'p1',
+ };
+
+ testWidgets('is one line, named by its goal, with no author', (
+ tester,
+ ) async {
+ await show(tester, backend([proposal()]));
+ expect(textOf(tester, 'p1'), contains(': Activity read fix'));
+ expect(textOf(tester, 'p1'), contains('Proposal from '));
+ expect(textOf(tester, 'p1'), isNot(contains('Changes: more words')));
+ expect(inRow('p1', find.text('Buddy')), findsNothing);
+ });
+
+ testWidgets('opens its thread, where it reads whole and says for whom', (
+ tester,
+ ) async {
+ final fake = backend([proposal()]);
+ fake.routes['/api/super-tabs/$tab/conversations/$leadChat/messages'] =
+ (_) => {
+ 'messages': [proposal()],
+ 'threads': <Object>[],
+ 'next': null,
+ };
+ await show(tester, fake);
+ await tester.tap(find.byKey(const ValueKey('swarm-message-p1')));
+ await tester.pumpAndSettle();
+ expect(find.byType(SwarmThreadPage), findsOneWidget);
+ expect(find.textContaining('on '), findsWidgets);
+ expect(
+ find.byKey(const ValueKey('swarm-proposal-label')),
+ findsOneWidget,
+ );
+ expect(find.textContaining('Changes: more words'), findsOneWidget);
+ });
+ });
+
+ group('an ordinary message says', () {
+ testWidgets('Terminal answer above a terminal\'s answer', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('n1', 2, 'The build passed.', {'kind': 'native'}),
+ ]),
+ );
+ expect(inRow('n1', find.text('Terminal answer')), findsOneWidget);
+ expect(inRow('n1', find.text('River')), findsOneWidget);
+ });
+
+ testWidgets('Excerpt under a truncated response', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('n1', 2, 'The build…', {'kind': 'native', 'truncated': true}),
+ ]),
+ );
+ expect(
+ inRow(
+ 'n1',
+ find.text('Excerpt · open the terminal for the full response'),
+ ),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('Response interrupted under an interrupted one', (
+ tester,
+ ) async {
+ await show(
+ tester,
+ backend([
+ row('n1', 2, 'The build', {'kind': 'native', 'interrupted': true}),
+ ]),
+ );
+ expect(inRow('n1', find.text('Response interrupted')), findsOneWidget);
+ });
+ });
+
+ testWidgets('none of them groups with the message before it', (tester) async {
+ await show(
+ tester,
+ backend([
+ row('a', 2, 'Short.', {'kind': 'message'}),
+ row('b', 3, 'Short too.', {'kind': 'native'}),
+ ]),
+ );
+ expect(inRow('b', find.text('River')), findsOneWidget);
+ });
+}