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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Phone: project status card at the top of the project chat (Tony 11-01, task 1) (#2462)
harness-for-autonomous[bot]ecc97ae87a0b
diff --git a/mobile/lib/swarm/model.dart b/mobile/lib/swarm/model.dartindex 03c484643..a1348c7f1 100644--- a/mobile/lib/swarm/model.dart+++ b/mobile/lib/swarm/model.dart@@ -452,8 +452,8 @@ class SuperTabProject {_memberGenerations[person.id] == person.generation;final int updateMinutes;- /// The project's status card text, read as the desktop's model reads it;- /// the phone shows no card yet.+ /// The project's status card text, read as the desktop's model reads it+ /// (`SwarmProjectStatusCard`).final SuperTabProjectStatus? status;final Map<String, dynamic>? repository;}diff --git a/mobile/lib/swarm/swarm_home_prefs.dart b/mobile/lib/swarm/swarm_home_prefs.dartindex b0d0d914d..7feac4357 100644--- a/mobile/lib/swarm/swarm_home_prefs.dart+++ b/mobile/lib/swarm/swarm_home_prefs.dart@@ -9,11 +9,12 @@ import 'swarm_home_list.dart';/// What the person chose for Swarm Home on this phone (Tony, 2026-10-29):/// the projects pinned at its top ([pins]), and the one Swarm it shows/// ([swarmId]; none shows them all); and when they last left the app-/// ([seenAt]), what While you were away counts from. Neither the server nor-/// the desktop has pins, so they stay on this phone, under the account-/// ([store]): ids and a time only, nothing read of a Swarm, and at most-/// [keptPins]. A Swarm the account no longer has takes its pins and its-/// choice with it ([keepOnly]).+/// ([seenAt]), what While you were away counts from; and the projects whose+/// status card is folded ([folded]), as the desktop keeps it on its computer.+/// Neither the server nor the desktop has pins, so they stay on this phone,+/// under the account ([store]): ids and a time only, nothing read of a Swarm,+/// and at most [keptPins] pins and [keptFolds] folds. A Swarm the account no+/// longer has takes its pins, folds and choice with it ([keepOnly]).class SwarmHomePrefs extends ChangeNotifier {SwarmHomePrefs({required this.accountId, this.store}) {unawaited(_load());@@ -22,6 +23,10 @@ class SwarmHomePrefs extends ChangeNotifier {/// The most pins kept; the oldest goes first.static const keptPins = 50;+ /// The most folded status cards kept, as the desktop keeps+ /// (`SuperTabController.statusFoldedKept`); the oldest goes first.+ static const keptFolds = 200;+final String accountId;/// Where the choices are kept; null keeps them in memory only.@@ -33,6 +38,11 @@ class SwarmHomePrefs extends ChangeNotifier {Set<String> get pins => Set.unmodifiable(_pins);final _pins = <String>{};+ /// The projects whose status card is folded, by [swarmHomeProjectKey],+ /// oldest first.+ Set<String> get folds => Set.unmodifiable(_folds);+ final _folds = <String>{};+/// The one Swarm Home shows; null for all of them.String? get swarmId => _swarmId;String? _swarmId;@@ -46,10 +56,10 @@ class SwarmHomePrefs extends ChangeNotifier {/// with what was read, and written only then, so as not to write over it.bool _touched = false;- /// Before the choices are read back: the pins taken off meanwhile, which- /// what is read does not bring back, and whether a Swarm was chosen to- /// show, which stands over the one read.- final _unpinned = <String>{};+ /// Before the choices are read back: the pins taken off and the cards+ /// unfolded meanwhile, which what is read does not bring back, and whether+ /// a Swarm was chosen to show, which stands over the one read.+ final _unpinned = <String>{}, _unfolded = <String>{};bool _shownChosen = false;/// The account's Swarms, as [keepOnly] last heard them; null before. What@@ -80,6 +90,26 @@ class SwarmHomePrefs extends ChangeNotifier {_changed();}+ /// Whether [projectId]'s status card in [swarmId] is folded to its heading.+ bool folded(String swarmId, String projectId) =>+ _folds.contains(swarmHomeProjectKey(swarmId, projectId));++ /// Folds [projectId]'s status card in [swarmId] ([on]), or opens it.+ void fold(String swarmId, String projectId, bool on) {+ final key = swarmHomeProjectKey(swarmId, projectId);+ if (!_loaded) {+ if (on) {+ _unfolded.remove(key);+ } else if (_unfolded.add(key)) {+ // Read back folded, it stays open.+ _touched = true;+ }+ }+ if (on ? !_folds.add(key) : !_folds.remove(key)) return;+ _cap();+ _changed();+ }+/// Home shows Swarm [swarmId] alone; null shows them all.void show(String? swarmId) {if (!_loaded) {@@ -109,22 +139,30 @@ class SwarmHomePrefs extends ChangeNotifier {if (_keep(swarmIds)) _changed();}- /// Drops the pins and the choice of any Swarm but [swarmIds]; whether any- /// went.+ /// Drops the pins, folds and choice of any Swarm but [swarmIds]; whether+ /// any went.bool _keep(Set<String> swarmIds) {- final before = _pins.length;- _pins.removeWhere((key) => !swarmIds.contains(key.split('/').first));+ final before = _pins.length + _folds.length;+ bool other(String key) => !swarmIds.contains(key.split('/').first);+ _pins.removeWhere(other);+ _folds.removeWhere(other);final gone = _swarmId != null && !swarmIds.contains(_swarmId);if (gone) _swarmId = null;- return gone || _pins.length != before;+ return gone || _pins.length + _folds.length != before;}- /// At most [keptPins], the oldest going first; whether any went.+ /// At most [keptPins] pins and [keptFolds] folds, the oldest going first;+ /// whether any went.bool _cap() {- final over = _pins.length - keptPins;- if (over <= 0) return false;- _pins.removeAll(_pins.take(over).toList());- return true;+ bool trim(Set<String> keys, int kept) {+ final over = keys.length - kept;+ if (over <= 0) return false;+ keys.removeAll(keys.take(over).toList());+ return true;+ }++ final pins = trim(_pins, keptPins);+ return trim(_folds, keptFolds) || pins;}void _changed() {@@ -145,22 +183,29 @@ class SwarmHomePrefs extends ChangeNotifier {}if (_disposed) return;_loaded = true;- final (pins, swarmId, seenAt) = text == null- ? (const <String>[], null, null)+ final (pins, folds, swarmId, seenAt) = text == null+ ? (const <String>[], const <String>[], null, null): _decode(text);- // Chosen meanwhile: the pins pinned join those read, oldest first, those- // taken off stay off, and a Swarm chosen stands.- final mine = [..._pins];- _pins- ..clear()- ..addAll(pins.where((key) => !_unpinned.contains(key)))- ..addAll(mine);+ // Chosen meanwhile: the pins pinned and cards folded join those read,+ // oldest first, those taken off or opened stay so, and a Swarm chosen+ // stands.+ void merge(Set<String> keys, List<String> read, Set<String> undone) {+ final mine = [...keys];+ keys+ ..clear()+ ..addAll(read.where((key) => !undone.contains(key)))+ ..addAll(mine);+ }++ merge(_pins, pins, _unpinned);+ merge(_folds, folds, _unfolded);if (!_shownChosen) _swarmId = swarmId;// Left meanwhile: the later time stands.if (seenAt != null && seenAt.isAfter(_seenAt ?? DateTime(0))) {_seenAt = seenAt;}_unpinned.clear();+ _unfolded.clear();// Swarms the account lost meanwhile take what was read of them too.final kept = _swarms;final dropped = kept != null && _keep(kept);@@ -168,15 +213,18 @@ class SwarmHomePrefs extends ChangeNotifier {notifyListeners();}- static (List<String>, String?, DateTime?) _decode(String text) {+ /// What was kept: written before folds were, it has none.+ static (List<String>, List<String>, String?, DateTime?) _decode(String text) {+ List<String> keys(Object? list) => [+ for (final key in list is List ? list : const [])+ if (key is String && key.contains('/')) key,+ ];try {final json = jsonDecode(text);- if (json is! Map) return (const [], null, null);+ if (json is! Map) return (const [], const [], null, null);return (- [- for (final pin in json['pins'] is List ? json['pins'] as List : [])- if (pin is String && pin.contains('/')) pin,- ],+ keys(json['pins']),+ keys(json['folded']),json['swarm'] is String ? json['swarm'] as String : null,switch (json['seen']) {final int ms when ms > 0 => DateTime.fromMillisecondsSinceEpoch(ms),@@ -184,7 +232,7 @@ class SwarmHomePrefs extends ChangeNotifier {},);} on FormatException {- return (const [], null, null);+ return (const [], const [], null, null);}}@@ -192,13 +240,17 @@ class SwarmHomePrefs extends ChangeNotifier {final store = this.store;if (store == null) return;try {- if (_pins.isEmpty && _swarmId == null && _seenAt == null) {+ if (_pins.isEmpty &&+ _folds.isEmpty &&+ _swarmId == null &&+ _seenAt == null) {await store.delete(_key);} else {await store.write(_key,jsonEncode({'pins': [..._pins],+ if (_folds.isNotEmpty) 'folded': [..._folds],'swarm': ?_swarmId,'seen': ?_seenAt?.millisecondsSinceEpoch,}),diff --git a/mobile/lib/swarm/swarm_need_rows.dart b/mobile/lib/swarm/swarm_need_rows.dartindex d23079b6e..c025a27d9 100644--- a/mobile/lib/swarm/swarm_need_rows.dart+++ b/mobile/lib/swarm/swarm_need_rows.dart@@ -141,12 +141,16 @@ class SwarmNeedLine extends StatelessWidget {required this.session,required this.need,required this.onTap,+ this.chevron = LucideIcons.chevronDown300,});final SwarmSession session;final SwarmNeed need;final VoidCallback onTap;+ /// Down where it opens in place on Home; right where it opens elsewhere.+ final IconData chevron;+@overrideWidget build(BuildContext context) {AppTheme.watch(context);@@ -168,7 +172,7 @@ class SwarmNeedLine extends StatelessWidget {),title: swarmNeedTitle(need),detail: line.isEmpty ? null : SwarmRow.line(line),- chevron: LucideIcons.chevronDown300,+ chevron: chevron,onTap: onTap,);}diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dartindex 80a974f9a..8ae9175ae 100644--- a/mobile/lib/swarm/swarm_project_page.dart+++ b/mobile/lib/swarm/swarm_project_page.dart@@ -23,6 +23,7 @@ import 'swarm_inbox.dart';import 'swarm_leaderboard.dart';import 'swarm_message_row.dart';import 'swarm_pm_chat.dart';+import 'swarm_project_status.dart';import 'swarm_project_tabs.dart';import 'swarm_project_tasks.dart';import 'swarm_project_team.dart';@@ -643,6 +644,16 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {}),),),+ // Over the chat, outside it: it never moves the composer.+ if (_tab == SwarmProjectTab.chat)+ SwarmProjectStatusCard(+ session: session,+ reader: reader,+ swarmId: widget.swarmId,+ projectId: project.id,+ // Read here, above the Scaffold that takes it away.+ typing: MediaQuery.viewInsetsOf(context).bottom > 0,+ ),],),// Under a sheet the chat is not seen, so nothing it gets is read.diff --git a/mobile/lib/swarm/swarm_project_status.dart b/mobile/lib/swarm/swarm_project_status.dartnew file mode 100644index 000000000..39e29a818--- /dev/null+++ b/mobile/lib/swarm/swarm_project_status.dart@@ -0,0 +1,457 @@+import 'dart:async';+import 'dart:math' as math;++import 'package:flutter/gestures.dart';+import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';+import 'package:url_launcher/url_launcher.dart';++import '../shared/theme/app_space.dart';+import '../shared/theme/app_theme.dart';+import '../shared/theme/app_type.dart';+import 'model.dart';+import 'swarm_inbox.dart';+import 'swarm_need_rows.dart';+import 'swarm_needs_page.dart';+import 'swarm_reader.dart';+import 'swarm_session.dart';+import 'swarm_style.dart';++/// The decisions waiting on the person in [projectId] of Swarm [swarmId], as+/// Activity lists them ([swarmNeedsOf]): each asked in a conversation of that+/// project the person still reads, so one from another project, or whose+/// conversation they lost, never shows — the desktop's+/// `SuperTabProjectStatusCard.needsYou`.+List<SwarmDecisionNeed> swarmProjectNeedsYou(+ SwarmSession session,+ SwarmReader reader,+ String swarmId,+ String projectId,+) {+ final snapshot = reader.snapshot;+ if (snapshot == null || reader.accessRevoked) return const [];+ return [+ for (final need in swarmNeedsOf(session.inbox, swarmId))+ if (need is SwarmDecisionNeed &&+ need.decision.projectId == projectId &&+ snapshot.conversation(need.conversationId)?.projectId == projectId)+ need,+ ];+}++/// Whether the person reads [project], as the server does (`canReadProject`):+/// a private project is its owner's and its members'. The server sends no+/// other; the card holds to this if it ever did.+bool swarmReadsProject(SwarmReader reader, SuperTabProject project) {+ if (!project.isPrivate || project.ownerId == reader.accountId) return true;+ final me = reader.snapshot?.people+ .where((p) => p.id == reader.accountId)+ .firstOrNull;+ return me != null && project.hasMember(me);+}++/// "16:52" today, "Oct 30, 16:52" before, in this phone's time: the+/// desktop's `SuperTabProjectStatusCard.updatedAt`.+String swarmStatusUpdatedAt(DateTime at, DateTime now) {+ final local = at.toLocal(), today = now.toLocal();+ String two(int n) => n.toString().padLeft(2, '0');+ final clock = '${two(local.hour)}:${two(local.minute)}';+ if (local.year == today.year &&+ local.month == today.month &&+ local.day == today.day) {+ return clock;+ }+ const months = [+ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', //+ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',+ ];+ final year = local.year == today.year ? '' : ' ${local.year}';+ return '${months[local.month - 1]} ${local.day}$year, $clock';+}++/// Opens a link in the status text; tests replace it.+@visibleForTesting+Future<bool> Function(Uri url) swarmOpenStatusLink = (url) =>+ launchUrl(url, mode: LaunchMode.inAppBrowserView);++/// The status card at the top of a project's chat, as the desktop draws it+/// (`desktop/lib/super_tabs/project_status_card.dart`): what the coordinator+/// last reported, replaced in place by each report, and the decisions in this+/// project waiting on the person, each opening Activity at it, where the+/// desktop opens Notifications. Hidden while there is neither; folded to its+/// heading by the person, remembered on this phone+/// ([SwarmHomePrefs.folded]), and while the keyboard is up, so it never+/// pushes the composer.+///+/// It reads nothing of its own: the text comes with the Swarm read, the+/// decisions are Activity's ([swarmProjectNeedsYou]).+class SwarmProjectStatusCard extends StatelessWidget {+ const SwarmProjectStatusCard({+ super.key,+ required this.session,+ required this.reader,+ required this.swarmId,+ required this.projectId,+ this.typing = false,+ this.now = DateTime.now,+ });++ final SwarmSession session;+ final SwarmReader reader;+ final String swarmId, projectId;++ /// The keyboard is up. Told by the page: inside its Scaffold the inset is+ /// taken away, so the card cannot see it.+ final bool typing;+ final DateTime Function() now;++ /// How tall the open card grows before its text scrolls inside it.+ static const maxBody = 200.0;++ @override+ Widget build(BuildContext context) => ListenableBuilder(+ // The session tells of answers held for Undo, which the rows say.+ listenable: Listenable.merge([+ reader,+ session.inbox,+ session.home,+ session,+ ]),+ builder: (context, _) {+ AppTheme.watch(context);+ final snapshot = reader.accessRevoked ? null : reader.snapshot;+ final project = snapshot?.projectById(projectId);+ if (project == null || !swarmReadsProject(reader, project)) {+ return const SizedBox.shrink();+ }+ final status = project.status;+ final waiting = swarmProjectNeedsYou(session, reader, swarmId, projectId);+ if (status == null && waiting.isEmpty) return const SizedBox.shrink();+ final chosen = session.home.folded(swarmId, projectId);+ final folded = chosen || typing;+ return Padding(+ padding: const EdgeInsets.fromLTRB(+ AppSpace.screenInset,+ AppSpace.xs,+ AppSpace.screenInset,+ AppSpace.xs,+ ),+ child: Semantics(+ container: true,+ label: 'Project status',+ child: DecoratedBox(+ key: ValueKey('swarm-project-status-$projectId'),+ decoration: BoxDecoration(+ color: AppPalette.cardBg,+ borderRadius: BorderRadius.circular(AppCard.radius),+ border: Border.all(color: AppGlass.hair),+ ),+ child: Padding(+ padding: EdgeInsets.fromLTRB(+ AppSpace.m,+ 0,+ 0,+ folded ? 0 : AppSpace.s,+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ _heading(status?.at, waiting.length, folded, chosen),+ if (!folded)+ // A long report, or many decisions, scroll inside the+ // card, so the chat keeps its room. Each part takes what+ // it needs; only when both overflow do they share it+ // half and half, so a long report never hides what waits+ // on the person.+ _Shares(+ maxHeight: maxBody,+ gap: AppSpace.s,+ children: [+ if (status != null)+ SingleChildScrollView(+ key: ValueKey(+ 'swarm-project-status-body-$projectId',+ ),+ padding: const EdgeInsets.only(right: AppSpace.m),+ child: _StatusText(status.text),+ ),+ if (waiting.isNotEmpty)+ SingleChildScrollView(+ key: ValueKey(+ 'swarm-project-status-needs-$projectId',+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ for (final need in waiting)+ SwarmNeedLine(+ key: ValueKey(+ 'swarm-project-status-need-${need.key}',+ ),+ session: session,+ need: need,+ chevron: LucideIcons.chevronRight300,+ onTap: () => openSwarmNeeds(+ context,+ focus: need.key,+ swarmId: swarmId,+ ),+ ),+ ],+ ),+ ),+ ],+ ),+ ],+ ),+ ),+ ),+ ),+ );+ },+ );++ /// "Status · updated 09:52", with how many wait on the person while+ /// folded, and the fold at its end. While the keyboard alone folds it,+ /// there is no button, only its room: a tap then would save a fold, or an+ /// unfold, the person never saw.+ Widget _heading(DateTime? at, int waiting, bool folded, bool chosen) => Row(+ children: [+ Expanded(+ child: Text.rich(+ TextSpan(+ children: [+ TextSpan(+ text: 'Status',+ style: AppType.label(color: AppPalette.textPrimary),+ ),+ if (at != null)+ TextSpan(+ text: ' · updated ${swarmStatusUpdatedAt(at, now())}',+ style: AppType.caption(color: AppPalette.textSecondary),+ ),+ // Folded, the heading still says something waits.+ if (folded && waiting > 0)+ TextSpan(+ text: ' · $waiting ${waiting == 1 ? 'needs' : 'need'} you',+ style: AppType.caption(color: AppPalette.swarmAccent),+ ),+ ],+ ),+ key: ValueKey('swarm-project-status-heading-$projectId'),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ),+ if (typing)+ const SizedBox.square(dimension: 44)+ else+ SwarmIconButton(+ key: ValueKey('swarm-project-status-fold-$projectId'),+ label: chosen ? 'Show status' : 'Fold status',+ icon: chosen ? LucideIcons.chevronDown300 : LucideIcons.chevronUp300,+ size: 18,+ onPressed: () => session.home.fold(swarmId, projectId, !chosen),+ ),+ ],+ );+}++/// The report as the coordinator wrote it, line for line, with its web links+/// tappable. Not Markdown: the card is a glance, not a message.+class _StatusText extends StatefulWidget {+ const _StatusText(this.text);+ final String text;++ @override+ State<_StatusText> createState() => _StatusTextState();+}++class _StatusTextState extends State<_StatusText> {+ static final _link = RegExp(r'https?://[^\s<>()\[\]]+');++ /// The text cut into plain pieces and links, with one tap per link: made+ /// again only when the text changes, so a rebuild (a theme flip, a Swarm+ /// read) never drops a tap under the finger.+ var _pieces = <(String, TapGestureRecognizer?)>[];++ @override+ void initState() {+ super.initState();+ _cut();+ }++ @override+ void didUpdateWidget(_StatusText old) {+ super.didUpdateWidget(old);+ if (old.text != widget.text) _cut();+ }++ @override+ void dispose() {+ _release();+ super.dispose();+ }++ void _release() {+ for (final (_, tap) in _pieces) {+ tap?.dispose();+ }+ }++ /// A web address the card opens: http or https with a host, as the+ /// desktop's `SuperTabMessageText.webLink`.+ static Uri? _webLink(String href) {+ final uri = Uri.tryParse(href);+ return uri != null &&+ (uri.scheme == 'https' || uri.scheme == 'http') &&+ uri.host.isNotEmpty+ ? uri+ : null;+ }++ void _cut() {+ _release();+ final text = widget.text.trimRight();+ final pieces = <(String, TapGestureRecognizer?)>[];+ var at = 0;+ for (final match in _link.allMatches(text)) {+ // A sentence's closing punctuation is not part of its link.+ var url = match[0]!;+ while (url.isNotEmpty && '.,;:!?\'"'.contains(url[url.length - 1])) {+ url = url.substring(0, url.length - 1);+ }+ final uri = _webLink(url);+ if (uri == null) continue;+ if (match.start > at) pieces.add((text.substring(at, match.start), null));+ pieces.add((+ url,+ TapGestureRecognizer()+ ..onTap = () => unawaited(swarmOpenStatusLink(uri)),+ ));+ at = match.start + url.length;+ }+ if (at < text.length) pieces.add((text.substring(at), null));+ _pieces = pieces;+ }++ @override+ Widget build(BuildContext context) {+ final link = TextStyle(+ color: AppPalette.swarmAccent,+ decoration: TextDecoration.underline,+ decorationColor: AppPalette.swarmAccent,+ );+ return Text.rich(+ key: const ValueKey('swarm-project-status-text'),+ TextSpan(+ style: AppType.body(color: AppPalette.textPrimary, height: 1.4),+ children: [+ for (final (text, tap) in _pieces)+ tap == null+ ? TextSpan(text: text)+ : TextSpan(text: text, style: link, recognizer: tap),+ ],+ ),+ );+ }+}++/// One or two scrolling parts, one over the other, no taller together than+/// [maxHeight]: each as tall as it needs while they fit; when they do not,+/// one that needs no more than half keeps all it needs and the other takes+/// the rest; only when both need more than half does each take half.+class _Shares extends MultiChildRenderObjectWidget {+ const _Shares({+ required this.maxHeight,+ required this.gap,+ required super.children,+ });++ final double maxHeight, gap;++ @override+ RenderObject createRenderObject(BuildContext context) =>+ _RenderShares(maxHeight, gap);++ @override+ void updateRenderObject(BuildContext context, _RenderShares render) => render+ ..maxHeight = maxHeight+ ..gap = gap;+}++class _ShareData extends ContainerBoxParentData<RenderBox> {}++class _RenderShares extends RenderBox+ with+ ContainerRenderObjectMixin<RenderBox, _ShareData>,+ RenderBoxContainerDefaultsMixin<RenderBox, _ShareData> {+ _RenderShares(this._maxHeight, this._gap);++ double _maxHeight, _gap;+ set maxHeight(double value) {+ if (value == _maxHeight) return;+ _maxHeight = value;+ markNeedsLayout();+ }++ set gap(double value) {+ if (value == _gap) return;+ _gap = value;+ markNeedsLayout();+ }++ @override+ void setupParentData(RenderBox child) {+ if (child.parentData is! _ShareData) child.parentData = _ShareData();+ }++ /// The heights [needs] get within [room], as [_Shares] says.+ static List<double> share(List<double> needs, double room) {+ if (needs.fold(0.0, (a, b) => a + b) <= room) return needs;+ if (needs.length == 1) return [room];+ final half = room / 2;+ final [a, b] = needs;+ if (a <= half) return [a, room - a];+ if (b <= half) return [room - b, b];+ return [half, half];+ }++ @override+ void performLayout() {+ final width = constraints.maxWidth;+ final kids = getChildrenAsList();+ final gaps = kids.isEmpty ? 0.0 : _gap * (kids.length - 1);+ final room = math.max(+ 0.0,+ math.min(_maxHeight, constraints.maxHeight) - gaps,+ );+ BoxConstraints within(double height) =>+ BoxConstraints(minWidth: width, maxWidth: width, maxHeight: height);+ // What each needs, within all the room: a scroll view is as tall as its+ // content, up to its bound.+ final needs = [+ for (final kid in kids)+ (kid..layout(within(room), parentUsesSize: true)).size.height,+ ];+ final heights = share(needs, room);+ var y = 0.0;+ for (final (i, kid) in kids.indexed) {+ if (heights[i] != needs[i]) {+ kid.layout(within(heights[i]), parentUsesSize: true);+ }+ (kid.parentData! as _ShareData).offset = Offset(0, y);+ y += kid.size.height + (i < kids.length - 1 ? _gap : 0);+ }+ size = constraints.constrain(Size(width, y));+ }++ @override+ void paint(PaintingContext context, Offset offset) =>+ defaultPaint(context, offset);++ @override+ bool hitTestChildren(BoxHitTestResult result, {required Offset position}) =>+ defaultHitTestChildren(result, position: position);+}diff --git a/mobile/test/swarm/swarm_project_status_shots_test.dart b/mobile/test/swarm/swarm_project_status_shots_test.dartnew file mode 100644index 000000000..d3fc36d29--- /dev/null+++ b/mobile/test/swarm/swarm_project_status_shots_test.dart@@ -0,0 +1,207 @@+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_project_page.dart';+import 'package:harness_mobile/swarm/swarm_project_tabs.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';++/// Review screenshots of the project status card at the top of a project's+/// chat (Tony 11-01, task 1): open, with the report and a decision waiting,+/// then folded. On a 390-point phone in both phone themes, from made-up data+/// only, to the folder `SWARM_PROJECT_STATUS_SHOTS` names.+final shots = Platform.environment['SWARM_PROJECT_STATUS_SHOTS'];+void main() {+ setUpAll(() async {+ if (shots == null || !Platform.isMacOS) return;+ final sf = ByteData.sublistView(+ await File('/System/Library/Fonts/SFNS.ttf').readAsBytes(),+ );+ // Every name the app's text asks for: the reading face and its+ // fallbacks, and the terminal's, which the chat's header, times and+ // chips are set in. A name left out draws as solid blocks.+ for (final family in {+ '.AppleSystemUIFont',+ 'Roboto',+ AppFont.sans,+ ...AppFont.sansFallback,+ }) {+ await (FontLoader(family)..addFont(Future.value(sf))).load();+ }+ 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('the status card open and folded, in both phone themes', (+ 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]) {+ const size = Size(390, 844);+ tester.view+ ..physicalSize = size * 3+ ..devicePixelRatio = 3;+ final brightness = palette.brightness;+ AppTheme.palette.value = palette;+ AppTheme.brightness.value = brightness;+ final now = DateTime.now().toUtc();+ String ago(int minutes) =>+ now.subtract(Duration(minutes: minutes)).toIso8601String();+ Map<String, dynamic> said(String id, int sequence, String text) => {+ 'id': id,+ 'conversationId': leadChat,+ 'text': text,+ 'sequence': sequence,+ 'author': {'kind': 'agent', 'id': 'agent-lead', 'name': 'River'},+ 'createdAt': ago(40 - sequence * 4),+ };+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Autonomous', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(+ head: headData(+ projects: [+ {+ 'id': project,+ 'name': 'openharness',+ 'ownerId': me,+ 'leadConversationId': leadChat,+ 'visibility': 'public',+ 'members': <Object>[],+ 'updateMinutes': 5,+ 'status': {+ 'text':+ 'Running: phone status card (Lark), Activity filters '+ '(Nova)\nWaiting on you: 1 decision\nDone today: #2459 '+ 'Swarm phone direct reads, #2460 signed chat files',+ 'at': ago(12),+ },+ },+ ],+ ),+ derived: {'decisionsWaiting': 1},+ );+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ changes(cursor: 'c2', derived: {'decisionsWaiting': 1});+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': [+ {+ 'id': 'd1',+ 'projectId': project,+ 'projectName': 'openharness',+ 'conversationId': leadChat,+ 'conversationTitle': 'openharness',+ 'askerName': 'River',+ 'question': 'Fold the card by default on small phones?',+ 'options': ['Yes', 'No'],+ 'recommended': 1,+ 'unblocks': 'The card',+ 'createdAt': ago(5),+ },+ ],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/'] = (_) => {+ 'messages': [+ said('m3', 3, 'Lark has the status card mockup up for Tony.'),+ said('m2', 2, 'CI on #2460 is green; merging.'),+ said('m1', 1, 'Morning all. Phone catch-up is today\'s focus.'),+ ],+ 'next': null,+ };+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => me,+ account: account,+ request: fake.request,+ notices: SilentSystemNotices(),+ features: features,+ readMarks: MemoryKeyValueStore(),+ )..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 SwarmProjectPage(+ swarmId: tab,+ projectId: project,+ tabs: SwarmProjectTab.homeC,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ Future<void> capture(String name) => 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/project-status-390-$name-${brightness.name}.png')+ .writeAsBytes(png!.buffer.asUint8List());+ image.dispose();+ });+ expect(+ find.byKey(const ValueKey('swarm-project-status-$project')),+ findsOneWidget,+ );+ await capture('open');+ await tester.tap(+ find.byKey(const ValueKey('swarm-project-status-fold-$project')),+ );+ await tester.pumpAndSettle();+ await capture('folded');+ await tester.pumpWidget(const SizedBox());+ host.dispose();+ }+ debugDisableShadows = true;+ }, skip: shots == null);+}diff --git a/mobile/test/swarm/swarm_project_status_test.dart b/mobile/test/swarm/swarm_project_status_test.dartnew file mode 100644index 000000000..32788b2f3--- /dev/null+++ b/mobile/test/swarm/swarm_project_status_test.dart@@ -0,0 +1,742 @@+import 'dart:async';+import 'dart:convert';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/core/local_key_value_store.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/swarm/swarm_activity_page.dart';+import 'package:harness_mobile/swarm/swarm_home_prefs.dart';+import 'package:harness_mobile/swarm/swarm_project_page.dart';+import 'package:harness_mobile/swarm/swarm_project_status.dart';+import 'package:harness_mobile/swarm/swarm_project_tabs.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';++import '../voice_fakes.dart';+import 'swarm_fixture.dart';++/// The project status card at the top of a project's chat (Tony 11-01, task+/// 1), as the desktop draws it (project_status_card.dart): the coordinator's+/// last report and the decisions in this project waiting on the person.+void main() {+ const other = 'project-2', otherChat = 'group-lead-2';+ const today = '2026-11-01T09:52:00.000Z';++ Map<String, dynamic> projectData(+ String id,+ String chat, {+ Map<String, dynamic>? status,+ }) => {+ 'id': id,+ 'name': id == project ? 'Mobile' : 'Backend',+ 'ownerId': me,+ 'leadConversationId': chat,+ 'visibility': 'public',+ 'members': <Object>[],+ 'updateMinutes': 5,+ 'status': ?status,+ };++ Map<String, dynamic> head({Map<String, dynamic>? status}) => headData(+ projects: [+ projectData(project, leadChat, status: status),+ projectData(other, otherChat),+ ],+ );++ /// A decision asked of the person by River (the Lead of both projects:+ /// the same agent id and name in each) in [chat] of [projectId].+ Map<String, dynamic> decision(+ String id, {+ String projectId = project,+ String chat = leadChat,+ String question = 'Fold the card by default?',+ }) => {+ 'id': id,+ 'projectId': projectId,+ 'projectName': projectId == project ? 'Mobile' : 'Backend',+ 'conversationId': chat,+ 'conversationTitle': 'Secret title $id',+ 'askerName': 'River',+ 'question': question,+ 'options': ['Yes', 'No'],+ 'recommended': 0,+ 'unblocks': 'The card',+ 'createdAt': '2026-11-01T09:00:00.000Z',+ };++ /// The Swarm with [status] on project Mobile and [decisions] open; its+ /// other project Backend has its own Lead chat, and the person's Buddy chat+ /// and a private chat they cannot read sit in Mobile.+ FakeSwarm backend({+ Map<String, dynamic>? status,+ List<Map<String, dynamic>> decisions = const [],+ }) {+ 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(+ head: head(status: status),+ groups: [+ {+ ...groupData(otherChat, title: 'Backend', agentIds: ['agent-lead']),+ 'projectId': other,+ },+ buddyChatData('buddy-me'),+ ],+ derived: {'decisionsWaiting': decisions.length},+ );+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ changes(cursor: 'c2', derived: {'decisionsWaiting': decisions.length});+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': decisions,+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/'] = (_) => {+ 'messages': <Object>[],+ 'next': null,+ };+ return fake;+ }++ /// A change read whose head carries [status] on Mobile.+ Map<String, dynamic> statusChange(+ Map<String, dynamic>? status, {+ int version = 2,+ }) => {+ ...changes(cursor: 'c$version', lastChangedAt: 100 + version),+ 'head': part('head', version, head(status: status)),+ };++ Future<SwarmHost> pump(+ WidgetTester tester,+ FakeSwarm fake, {+ LocalKeyValueStore? marks,+ Widget? home,+ }) async {+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: fake.request,+ notices: SilentSystemNotices(),+ features: features,+ readMarks: marks ?? MemoryKeyValueStore(),+ )..foreground = false;+ addTearDown(host.dispose);+ await tester.pumpWidget(+ MaterialApp(+ builder: (context, child) => SwarmScope(notifier: host, child: child!),+ home:+ home ??+ const SwarmProjectPage(+ swarmId: tab,+ projectId: project,+ tabs: SwarmProjectTab.homeC,+ ),+ ),+ );+ await tester.pumpAndSettle();+ return host;+ }++ Finder key(String value) => find.byKey(ValueKey(value));+ final card = key('swarm-project-status-$project');+ final heading = key('swarm-project-status-heading-$project');+ final fold = key('swarm-project-status-fold-$project');+ String headingText(WidgetTester tester) =>+ tester.widget<Text>(heading).textSpan!.toPlainText();++ group('states', () {+ testWidgets('empty: no report and nothing waiting draws no card', (+ tester,+ ) async {+ await pump(tester, backend());+ expect(key('swarm-project-chat-$leadChat'), findsOneWidget);+ expect(card, findsNothing);+ });++ testWidgets('running: the report word for word under Status · updated', (+ tester,+ ) async {+ await pump(+ tester,+ backend(+ status: {+ 'text': 'Running: phone status card\nDone today: #2459',+ 'at': today,+ },+ ),+ );+ expect(card, findsOneWidget);+ expect(headingText(tester), startsWith('Status · updated '));+ expect(+ find.text('Running: phone status card\nDone today: #2459'),+ findsOneWidget,+ );+ expect(key('swarm-project-status-need-decision:d1'), findsNothing);+ });++ testWidgets('needs you: a decision here, with no report, still shows; a '+ 'tap opens Activity at it', (tester) async {+ await pump(tester, backend(decisions: [decision('d1')]));+ expect(card, findsOneWidget);+ expect(headingText(tester), 'Status');+ final row = key('swarm-project-status-need-decision:d1');+ expect(row, findsOneWidget);+ expect(+ find.descendant(of: row, matching: find.text('River asks you')),+ findsOneWidget,+ );+ expect(+ find.descendant(+ of: row,+ matching: find.text('Fold the card by default?'),+ ),+ findsOneWidget,+ );+ await tester.tap(row);+ await tester.pumpAndSettle();+ final activity = tester.widget<SwarmActivityPage>(+ find.byType(SwarmActivityPage),+ );+ expect(activity.focus, 'decision:d1');+ expect(activity.swarmId, tab);+ });++ testWidgets('done and waiting: the report, then each decision, newest '+ 'first as Activity orders them', (tester) async {+ await pump(+ tester,+ backend(+ status: {'text': 'Done today: #2459, #2460', 'at': today},+ decisions: [+ decision('d1', question: 'First?'),+ {+ ...decision('d2', question: 'Second?'),+ 'createdAt': '2026-11-01T09:30:00.000Z',+ },+ ],+ ),+ );+ final text = tester.getTopLeft(find.text('Done today: #2459, #2460'));+ final d2 = tester.getTopLeft(+ key('swarm-project-status-need-decision:d2'),+ );+ final d1 = tester.getTopLeft(+ key('swarm-project-status-need-decision:d1'),+ );+ expect(text.dy, lessThan(d2.dy));+ expect(d2.dy, lessThan(d1.dy));+ });++ testWidgets('long text scrolls inside the card, which never grows past '+ 'its limit', (tester) async {+ final fake = backend(status: {'text': 'Short', 'at': today});+ await pump(tester, fake);+ final shortCard = tester.getSize(card).height;++ final long = List.generate(60, (i) => 'Line $i of the report').join('\n');+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ statusChange({'text': long, 'at': today});+ await host(tester).inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();++ final longCard = tester.getSize(card).height;+ expect(longCard, greaterThan(shortCard));+ expect(+ longCard,+ lessThanOrEqualTo(SwarmProjectStatusCard.maxBody + 44 + 8 + 2),+ );+ final body = key('swarm-project-status-body-$project');+ final scrollable = find.descendant(+ of: body,+ matching: find.byType(Scrollable),+ );+ expect(+ tester.state<ScrollableState>(scrollable).position.maxScrollExtent,+ greaterThan(0),+ );+ });+ });++ testWidgets('the card takes its room from the chat alone: folding it gives '+ 'the chat exactly what the card gave up, and the composer stays put', (+ tester,+ ) async {+ final long = List.generate(30, (i) => 'Line $i of the report').join('\n');+ await pump(+ tester,+ backend(status: {'text': long, 'at': today}, decisions: [decision('d1')]),+ );+ final chat = key('swarm-messages');+ final composer = find.byType(EditableText);+ final openCard = tester.getSize(card).height;+ final openChat = tester.getSize(chat).height;+ final openComposer = tester.getTopLeft(composer).dy;++ await tester.tap(fold);+ await tester.pumpAndSettle();+ final foldedCard = tester.getSize(card).height;+ final foldedChat = tester.getSize(chat).height;++ expect(openCard - foldedCard, greaterThan(100));+ expect(foldedChat - openChat, moreOrLessEquals(openCard - foldedCard));+ expect(tester.getTopLeft(composer).dy, openComposer);+ });++ testWidgets('on a 320-point phone a one-line report leaves its room to the '+ 'decisions: at least two of three show in full', (tester) async {+ tester.view+ ..physicalSize = const Size(320, 568) * 3+ ..devicePixelRatio = 3;+ addTearDown(tester.view.reset);+ await pump(+ tester,+ backend(+ status: {'text': 'Building the card', 'at': today},+ decisions: [+ for (final (i, at) in ['09:10', '09:20', '09:30'].indexed)+ {+ ...decision('d$i', question: 'Question $i?'),+ 'createdAt': '2026-11-01T$at:00.000Z',+ },+ ],+ ),+ );+ final box = tester.getRect(card);+ final shown = [+ for (final i in [0, 1, 2])+ if (tester.getRect(key('swarm-project-status-need-decision:d$i'))+ case final row when row.top >= box.top && row.bottom <= box.bottom)+ i,+ ];+ expect(shown.length, greaterThanOrEqualTo(2));+ expect(find.text('Building the card'), findsOneWidget);+ });++ testWidgets('a long report never hides what waits: the decision shows in '+ 'full inside the card', (tester) async {+ final long = List.generate(30, (i) => 'Line $i of the report').join('\n');+ await pump(+ tester,+ backend(status: {'text': long, 'at': today}, decisions: [decision('d1')]),+ );+ final row = tester.getRect(key('swarm-project-status-need-decision:d1'));+ final box = tester.getRect(card);+ expect(row.top, greaterThanOrEqualTo(box.top));+ expect(row.bottom, lessThanOrEqualTo(box.bottom));+ expect(row.height, greaterThanOrEqualTo(56));+ });++ group('arrives late, fails, recovers', () {+ testWidgets('a report that arrives with a later read shows then, in place '+ 'of none, and a newer one replaces it', (tester) async {+ final fake = backend();+ final host = await pump(tester, fake);+ expect(card, findsNothing);++ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ statusChange({'text': 'Building the card', 'at': today});+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.text('Building the card'), findsOneWidget);++ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ statusChange({'text': 'Card shipped', 'at': today}, version: 3);+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.text('Card shipped'), findsOneWidget);+ expect(find.text('Building the card'), findsNothing);+ });++ testWidgets('a first read that fails shows no card and no endless '+ 'loading; the read that recovers brings the card', (tester) async {+ final fake = backend(status: {'text': 'Building', 'at': today});+ final parts = fake.routes['/api/super-tabs/$tab/parts']!;+ fake.routes['/api/super-tabs/$tab/parts'] = (_) =>+ throw const SuperTabFailure('UNAVAILABLE', 'Down.', statusCode: 503);+ final host = await pump(tester, fake);+ expect(card, findsNothing);+ expect(find.text('Down.'), findsOneWidget);++ fake.routes['/api/super-tabs/$tab/parts'] = parts;+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.text('Building'), findsOneWidget);+ });++ testWidgets('decisions that fail to load leave the report, and come when '+ 'a later read gets through', (tester) async {+ final fake = backend(+ status: {'text': 'Building', 'at': today},+ decisions: [decision('d1')],+ );+ final open = fake.routes['/api/super-tabs/$tab/decisions?state=open']!;+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) =>+ throw const SuperTabFailure('UNAVAILABLE', 'Down.', statusCode: 503);+ final host = await pump(tester, fake);+ expect(find.text('Building'), findsOneWidget);+ expect(key('swarm-project-status-need-decision:d1'), findsNothing);++ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = open;+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(key('swarm-project-status-need-decision:d1'), findsOneWidget);+ });+ });++ group('privacy', () {+ testWidgets('a decision from another project, or from a chat of this '+ 'project the person does not read, never shows, nor its title', (+ tester,+ ) async {+ await pump(+ tester,+ backend(+ decisions: [+ // Another project, by the same River.+ decision('other', projectId: other, chat: otherChat),+ // Claims this project, asked in another project's chat.+ decision('claims', chat: otherChat),+ // A private chat of this project the read does not carry.+ decision('private', chat: 'group-private'),+ // Another person's Buddy chat, not in the read either.+ decision('buddy', chat: 'buddy-theirs'),+ ],+ ),+ );+ expect(card, findsNothing);+ expect(find.textContaining('Secret title'), findsNothing);+ expect(find.text('River asks you'), findsNothing);+ });++ testWidgets('a private project the person is not a member of shows no '+ 'card, as the server reads it; made a member, it shows', (+ tester,+ ) async {+ Map<String, dynamic> privateHead({required bool member}) => headData(+ projects: [+ {+ ...projectData(+ project,+ leadChat,+ status: {'text': 'Private plans', 'at': today},+ ),+ 'ownerId': 'diego',+ 'visibility': 'private',+ 'members': [+ if (member) {'id': me, 'generation': 'gen-$me'},+ ],+ },+ projectData(other, otherChat),+ ],+ );+ final fake = backend(decisions: [decision('d1')]);+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => firstLoad(+ head: privateHead(member: false),+ derived: {'decisionsWaiting': 1},+ );+ final host = await pump(tester, fake);+ expect(key('swarm-project-chat-$leadChat'), findsOneWidget);+ expect(card, findsNothing);+ expect(find.text('Private plans'), findsNothing);+ expect(find.text('River asks you'), findsNothing);++ fake.routes['/api/super-tabs/$tab/changes'] = (_) => {+ ...changes(+ cursor: 'c2',+ lastChangedAt: 102,+ derived: {'decisionsWaiting': 1},+ ),+ 'head': part('head', 2, privateHead(member: true)),+ };+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.text('Private plans'), findsOneWidget);+ });++ testWidgets('access lost while the card is open takes it away, with what '+ 'it held', (tester) async {+ final host = await pump(+ tester,+ backend(+ status: {'text': 'Building', 'at': today},+ decisions: [decision('d1')],+ ),+ );+ expect(find.text('Building'), findsOneWidget);+ host.session!.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(card, findsNothing);+ expect(find.text('Building'), findsNothing);+ expect(find.text('River asks you'), findsNothing);+ });++ testWidgets('a project taken away by a later read takes its card with it', (+ tester,+ ) async {+ final fake = backend(status: {'text': 'Building', 'at': today});+ final host = await pump(tester, fake);+ expect(card, findsOneWidget);+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => {+ ...changes(cursor: 'c2', lastChangedAt: 102),+ 'head': part(+ 'head',+ 2,+ headData(projects: [projectData(other, otherChat)]),+ ),+ };+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(card, findsNothing);+ expect(find.text('Building'), findsNothing);+ });++ testWidgets('decisions read before access was lost, answered after, are '+ 'never drawn', (tester) async {+ final fake = backend(+ status: {'text': 'Building', 'at': today},+ decisions: [decision('d1')],+ );+ final held = Completer<Object?>();+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) =>+ held.future;+ final host = await pump(tester, fake);+ expect(find.text('Building'), findsOneWidget);+ host.session!.inbox.reader(tab)!.revoke();+ await tester.pump();+ held.complete({+ 'decisions': [decision('d1')],+ });+ await tester.pumpAndSettle();+ expect(card, findsNothing);+ expect(find.text('River asks you'), findsNothing);+ });+ });++ group('fold', () {+ testWidgets('folds to its heading, which still says what waits, and stays '+ 'folded when the project opens again', (tester) async {+ final marks = MemoryKeyValueStore();+ final fake = backend(+ status: {'text': 'Building', 'at': today},+ decisions: [decision('d1')],+ );+ await pump(tester, fake, marks: marks);+ expect(find.text('Building'), findsOneWidget);++ await tester.tap(fold);+ await tester.pumpAndSettle();+ expect(find.text('Building'), findsNothing);+ expect(key('swarm-project-status-need-decision:d1'), findsNothing);+ expect(headingText(tester), endsWith(' · 1 needs you'));++ // Opened again, with the same phone's store.+ await tester.pumpWidget(const SizedBox());+ await pump(tester, fake, marks: marks);+ expect(card, findsOneWidget);+ expect(find.text('Building'), findsNothing);+ await tester.tap(fold);+ await tester.pumpAndSettle();+ expect(find.text('Building'), findsOneWidget);+ });++ testWidgets('a report that arrives while folded changes only the heading: '+ 'the card keeps its height, so the chat does not jump', (tester) async {+ final fake = backend(status: {'text': 'Building', 'at': today});+ final host = await pump(tester, fake);+ await tester.tap(fold);+ await tester.pumpAndSettle();+ final height = tester.getSize(card).height;+ final composer = tester.getTopLeft(find.byType(EditableText)).dy;+ final before = headingText(tester);++ fake.routes['/api/super-tabs/$tab/changes'] = (_) => statusChange({+ 'text': List.filled(40, 'A much longer report').join('\n'),+ 'at': '2026-11-01T10:07:00.000Z',+ });+ await host.session!.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.textContaining('A much longer report'), findsNothing);+ expect(headingText(tester), isNot(before));+ expect(tester.getSize(card).height, height);+ expect(tester.getTopLeft(find.byType(EditableText)).dy, composer);+ });++ testWidgets('folds while the keyboard is up, so it never pushes the '+ 'composer, and opens again when it goes', (tester) async {+ await pump(tester, backend(status: {'text': 'Building', 'at': today}));+ expect(find.text('Building'), findsOneWidget);+ tester.view.viewInsets = const FakeViewPadding(bottom: 900);+ addTearDown(tester.view.resetViewInsets);+ await tester.pumpAndSettle();+ expect(card, findsOneWidget);+ expect(find.text('Building'), findsNothing);+ tester.view.resetViewInsets();+ await tester.pumpAndSettle();+ expect(find.text('Building'), findsOneWidget);+ });++ testWidgets('while the keyboard folds it there is no fold button, so no '+ 'tap saves a fold the person never saw', (tester) async {+ final host = await pump(+ tester,+ backend(status: {'text': 'Building', 'at': today}),+ );+ tester.view.viewInsets = const FakeViewPadding(bottom: 900);+ addTearDown(tester.view.resetViewInsets);+ await tester.pumpAndSettle();+ expect(fold, findsNothing);+ final byKeyboard = tester.getSize(card).height;+ expect(host.session!.home.folded(tab, project), isFalse);++ // Folded by the person, then the keyboard: still no button.+ tester.view.resetViewInsets();+ await tester.pumpAndSettle();+ await tester.tap(fold);+ await tester.pumpAndSettle();+ // Folded either way, the card is as tall: no jump as the button goes.+ expect(tester.getSize(card).height, byKeyboard);+ tester.view.viewInsets = const FakeViewPadding(bottom: 900);+ await tester.pumpAndSettle();+ expect(fold, findsNothing);+ expect(host.session!.home.folded(tab, project), isTrue);+ });+ });++ group('text', () {+ testWidgets('web links open; a sentence\'s full stop is not part of one; '+ 'a link with no host stays text', (tester) async {+ final opened = <Uri>[];+ final was = swarmOpenStatusLink;+ swarmOpenStatusLink = (url) async {+ opened.add(url);+ return true;+ };+ addTearDown(() => swarmOpenStatusLink = was);+ await pump(+ tester,+ backend(+ status: {+ 'text': 'PR https://github.com/o/r/pull/1. Not http:///etc/passwd',+ 'at': today,+ },+ ),+ );+ final text = tester.widget<Text>(key('swarm-project-status-text'));+ final spans = <TextSpan>[];+ text.textSpan!.visitChildren((span) {+ if (span is TextSpan && span.recognizer != null) spans.add(span);+ return true;+ });+ expect(+ [for (final s in spans) s.text],+ ['https://github.com/o/r/pull/1'],+ );+ (spans.single.recognizer! as dynamic).onTap();+ expect(opened, [Uri.parse('https://github.com/o/r/pull/1')]);+ });++ test('updated: the time alone today, the date before, the year in '+ 'another year', () {+ final now = DateTime(2026, 11, 1, 18);+ expect(swarmStatusUpdatedAt(DateTime(2026, 11, 1, 9, 5), now), '09:05');+ expect(+ swarmStatusUpdatedAt(DateTime(2026, 10, 30, 16, 52), now),+ 'Oct 30, 16:52',+ );+ expect(+ swarmStatusUpdatedAt(DateTime(2025, 12, 31, 23, 59), now),+ 'Dec 31 2025, 23:59',+ );+ });+ });++ group('kept folds', () {+ String keyOf(int i) => '$tab/p$i';++ test('kept from before folds existed, read back and folded, it saves '+ 'with its pins and Swarm intact', () async {+ final store = MemoryKeyValueStore();+ await store.write(+ 'swarm_home.$me',+ jsonEncode({+ 'pins': ['$tab/$project'],+ 'swarm': tab,+ }),+ );+ final prefs = SwarmHomePrefs(accountId: me, store: store);+ await until(() => prefs.loaded);+ expect(prefs.folds, isEmpty);+ prefs.fold(tab, project, true);+ await settle();+ final saved = jsonDecode((await store.read('swarm_home.$me'))!) as Map;+ expect(saved['pins'], ['$tab/$project']);+ expect(saved['swarm'], tab);+ expect(saved['folded'], ['$tab/$project']);+ prefs.dispose();+ });++ test(+ 'at the limit the oldest fold goes; read back, it still saves',+ () async {+ final store = MemoryKeyValueStore();+ final prefs = SwarmHomePrefs(accountId: me, store: store);+ await until(() => prefs.loaded);+ for (var i = 0; i <= SwarmHomePrefs.keptFolds; i++) {+ prefs.fold(tab, 'p$i', true);+ }+ await settle();+ expect(prefs.folds, hasLength(SwarmHomePrefs.keptFolds));+ expect(prefs.folded(tab, 'p0'), isFalse);+ prefs.dispose();++ final again = SwarmHomePrefs(accountId: me, store: store);+ await until(() => again.loaded);+ expect(again.folds, hasLength(SwarmHomePrefs.keptFolds));+ expect(again.folds.first, keyOf(1));+ again.fold(tab, 'new', true);+ await settle();+ final saved = jsonDecode((await store.read('swarm_home.$me'))!) as Map;+ expect(saved['folded'], hasLength(SwarmHomePrefs.keptFolds));+ expect((saved['folded'] as List).last, '$tab/new');+ expect(saved['folded'], isNot(contains(keyOf(1))));+ again.dispose();+ },+ );++ test('a fold chosen before the kept ones are read joins them; one opened '+ 'meanwhile stays open; a Swarm gone takes its folds', () async {+ final store = MemoryKeyValueStore();+ await store.write(+ 'swarm_home.$me',+ jsonEncode({+ 'pins': <String>[],+ 'folded': ['$tab/a', '$tab/b', 'gone/c'],+ }),+ );+ final prefs = SwarmHomePrefs(accountId: me, store: store)+ ..fold(tab, 'b', false)+ ..fold(tab, 'd', true)+ ..keepOnly({tab});+ await until(() => prefs.loaded);+ expect(prefs.folds, ['$tab/a', '$tab/d']);+ prefs.dispose();+ });+ });+}++/// The session of the host the page was pumped under.+SwarmSession host(WidgetTester tester) =>+ SwarmScope.of(tester.element(find.byType(SwarmProjectPage)))!;