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.

Phone: Team agent rows say how long since each agent's last progress, as Desktop does (#2352)

harness-for-autonomous[bot]ee73926ae41d
diff --git a/mobile/lib/swarm/swarm_project_team.dart b/mobile/lib/swarm/swarm_project_team.dart
index 48c723232..3927ea6b5 100644
--- a/mobile/lib/swarm/swarm_project_team.dart
+++ b/mobile/lib/swarm/swarm_project_team.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:clock/clock.dart';
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
@@ -46,36 +48,66 @@ enum SwarmMemberState {
final String counted;
}
-/// One agent on a project's Team: its state in a word or two ([label]) and
-/// the open work it holds ([task]).
+/// How long since an agent's last progress, shortest: "now", "4m", "2h",
+/// "3d" — the desktop's `superTabAgentAge`, word for word.
+String swarmAgentAge(Duration age) {
+ if (age.inMinutes < 1) return 'now';
+ if (age.inMinutes < 60) return '${age.inMinutes}m';
+ if (age.inHours < 24) return '${age.inHours}h';
+ return '${age.inDays}d';
+}
+
+/// One agent on a project's Team: its state in a word or two ([label]), the
+/// open work it holds ([task]) and how long since its last progress on it
+/// ([age]).
class SwarmTeamAgent {
- SwarmTeamAgent(this.agent, this.name, this.state, this.label, this.task);
+ SwarmTeamAgent(
+ this.agent,
+ this.name,
+ this.state,
+ this.label,
+ this.task, {
+ this.age,
+ });
final SuperTabAgent agent;
final String name;
final SwarmMemberState state;
final String label;
final SuperTabConversation? task;
- /// Its row's quiet line: "Working · #2156 Buddy chat header".
- String get line => [label, ?task?.label].join(' · ');
+ /// "4m" since the agent last reported progress on [task] (the Swarm's
+ /// assignment.progressAt, which every status, check or post it sends
+ /// renews), as the desktop's Agents list says it (#2281); null with no
+ /// task named, or none the Swarm sent a time for.
+ final String? age;
+
+ /// Its state and task: "Working · #2156 Buddy chat header".
+ String get doing => [label, ?task?.label].join(' · ');
+
+ /// Its row's quiet line: "Working · #2156 Buddy chat header · 4m".
+ String get line => [doing, ?age].join(' · ');
}
/// [projectId]'s agents as its Team lists them: each in its state
/// ([SwarmMemberState]), the most urgent first, then by name, letter case
/// aside. Read from the Swarm alone, as the team glance is: an agent is of
/// the project it records or whose work it is in, matched by id, never by
-/// name; a Buddy is no one's team. Work it still holds in another project is
-/// not named here, nor opened: its state stays, as the glance counts it.
+/// name; a Buddy is no one's team. Work it still holds in another project, a
+/// Buddy chat or a private chat whose people leave out [viewerId] is not
+/// named here, nor timed, nor opened: its state stays, as the glance counts
+/// it.
List<SwarmTeamAgent> swarmProjectAgents(
SuperTabSnapshot snapshot,
String projectId, {
DateTime? now,
+ String? viewerId,
}) {
- final glance = swarmTeamGlance(snapshot, projectId: projectId, now: now);
+ final at = now ?? clock.now();
+ final glance = swarmTeamGlance(snapshot, projectId: projectId, now: at);
final team = [
// The read names its Buddies; one it has not named yet says so itself.
for (final a in glance.agents)
- if (!a.agent.isBuddy) _member(a, projectId),
+ if (!a.agent.isBuddy) _member(a, projectId, at, viewerId),
];
String sortName(SwarmTeamAgent a) => a.name.toLowerCase();
return team..sort((a, b) {
@@ -86,7 +118,12 @@ List<SwarmTeamAgent> swarmProjectAgents(
});
}
-SwarmTeamAgent _member(SwarmAgentGlance glance, String projectId) {
+SwarmTeamAgent _member(
+ SwarmAgentGlance glance,
+ String projectId,
+ DateTime now,
+ String? viewerId,
+) {
final agent = glance.agent;
final work = glance.task?.assignment?['status'];
// Offline outranks a stop, which outranks the work it still holds.
@@ -110,13 +147,24 @@ SwarmTeamAgent _member(SwarmAgentGlance glance, String projectId) {
),
SwarmAgentState.idle => (SwarmMemberState.idle, 'Idle'),
};
- final task = glance.task;
+ // Only a task the viewer reads in this project: the desktop's
+ // superTabGroupReadable, should the server ever send another.
+ final task = switch (glance.task) {
+ final t?
+ when t.projectId == projectId &&
+ !t.isBuddyChat &&
+ (t.audience == null || t.audience!.contains(viewerId)) =>
+ t,
+ _ => null,
+ };
+ final since = task == null ? null : swarmProgressAt(task);
return SwarmTeamAgent(
agent,
glance.name,
state,
label,
- task?.projectId == projectId ? task : null,
+ task,
+ age: since == null ? null : swarmAgentAge(now.difference(since)),
);
}
@@ -193,8 +241,10 @@ class SwarmProjectTeamSheet extends StatelessWidget {
/// a row that shows the rest in place — each opening its chat ([onOpen]).
/// Then its agents, each in its state with the task it holds, the most urgent
/// first ([swarmProjectAgents]), with what needs a look counted beside their
-/// caption, each opening the task it holds ([onOpen]). Its humans are on the
-/// project's leaderboard. A pull reads the Swarm again.
+/// caption, each opening the task it holds ([onOpen]), its time since its
+/// last progress kept true by a tick a minute ([tick]) and on coming back to
+/// the app. Its humans are on the project's leaderboard. A pull reads the
+/// Swarm again.
class SwarmProjectTeam extends StatefulWidget {
const SwarmProjectTeam({
super.key,
@@ -215,6 +265,11 @@ class SwarmProjectTeam extends StatefulWidget {
/// hundred open tasks still reaches its agents (Tony, 2026-10-30).
static const workShown = 5;
+ /// How often the agents' times are worked out again on a quiet Swarm: they
+ /// count minutes, so no more often than once a minute; a read of the Swarm
+ /// redraws them anyway.
+ static const tick = Duration(minutes: 1);
+
@override
State<SwarmProjectTeam> createState() => _SwarmProjectTeamState();
}
@@ -223,6 +278,31 @@ class _SwarmProjectTeamState extends State<SwarmProjectTeam> {
/// See all was tapped: kept here, so no read of the Swarm folds it again.
bool _allWork = false;
+ /// One tick for the whole Team, cancelled with it.
+ late final Timer _tick;
+
+ /// Back in the app, times are worked out at once: a phone asleep for an
+ /// hour does not show the hour before until the next tick.
+ late final AppLifecycleListener _lifecycle;
+
+ void _redraw() {
+ if (mounted) setState(() {});
+ }
+
+ @override
+ void initState() {
+ super.initState();
+ _tick = Timer.periodic(SwarmProjectTeam.tick, (_) => _redraw());
+ _lifecycle = AppLifecycleListener(onResume: _redraw);
+ }
+
+ @override
+ void dispose() {
+ _tick.cancel();
+ _lifecycle.dispose();
+ super.dispose();
+ }
+
@override
void didUpdateWidget(SwarmProjectTeam old) {
super.didUpdateWidget(old);
@@ -249,7 +329,12 @@ class _SwarmProjectTeamState extends State<SwarmProjectTeam> {
final now = clock.now();
final tasks = swarmProjectTasks(session.inbox, reader, project.id, now);
final personName = swarmTaskPersonName(snapshot);
- final agents = swarmProjectAgents(snapshot, project.id);
+ final agents = swarmProjectAgents(
+ snapshot,
+ project.id,
+ now: now,
+ viewerId: reader.accountId,
+ );
final working = tasks.working;
final folds = working.length > SwarmProjectTeam.workShown;
final work = folds && !_allWork
@@ -352,7 +437,8 @@ class _SwarmProjectTeamState extends State<SwarmProjectTeam> {
),
dot: swarmMemberColor(a.state),
name: a.name,
- detail: a.line,
+ detail: a.doing,
+ age: a.age,
onTap: switch (a.task) {
final task? => () => widget.onOpen(task.id),
null => null,
@@ -369,9 +455,10 @@ class _SwarmProjectTeamState extends State<SwarmProjectTeam> {
}
/// One agent on a project's Team (Dee, 2026-10-29): the face in one column,
-/// with its state's [dot], the name and a quiet [detail] line beneath. The
-/// same height with or without the line; a tap does [onTap], when there is
-/// one.
+/// with its state's [dot], the name and a quiet [detail] line beneath, ending
+/// in its [age], which a narrow phone never cuts: the line's words give way
+/// first. The same height with or without the line; a tap does [onTap], when
+/// there is one.
class SwarmMemberRow extends StatelessWidget {
const SwarmMemberRow({
super.key,
@@ -379,6 +466,7 @@ class SwarmMemberRow extends StatelessWidget {
required this.name,
this.dot,
this.detail,
+ this.age,
this.onTap,
});
@@ -388,6 +476,9 @@ class SwarmMemberRow extends StatelessWidget {
/// The state's colour on the face's corner.
final Color? dot;
final String? detail;
+
+ /// How long since the agent's last progress: "4m".
+ final String? age;
final VoidCallback? onTap;
static const double _face = 36, _dot = 11;
@@ -395,12 +486,20 @@ class SwarmMemberRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
- final dot = this.dot, detail = this.detail;
+ final dot = this.dot, detail = this.detail, age = this.age;
+ final line = [
+ if (detail != null && detail.isNotEmpty) detail,
+ ?age,
+ ].join(' · ');
+ final quiet = AppType.caption(
+ color: AppPalette.textSecondary,
+ height: 1.35,
+ );
return Semantics(
// Its own node, a tap or not: one row, said as one.
container: true,
button: onTap != null,
- label: [name, if (detail != null && detail.isNotEmpty) detail].join(', '),
+ label: [name, if (line.isNotEmpty) line].join(', '),
excludeSemantics: true,
child: InkWell(
onTap: onTap,
@@ -454,16 +553,29 @@ class SwarmMemberRow extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: AppType.label(color: AppPalette.textPrimary),
),
- if (detail != null && detail.isNotEmpty) ...[
+ if (line.isNotEmpty) ...[
const SizedBox(height: 2),
- Text(
- detail,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: AppType.caption(
- color: AppPalette.textSecondary,
- height: 1.35,
- ),
+ Row(
+ children: [
+ if (detail != null && detail.isNotEmpty)
+ Flexible(
+ child: Text(
+ detail,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: quiet,
+ ),
+ ),
+ if (age != null)
+ Text(
+ detail != null && detail.isNotEmpty
+ ? ' · $age'
+ : age,
+ key: const ValueKey('swarm-member-age'),
+ maxLines: 1,
+ style: quiet,
+ ),
+ ],
),
],
],
diff --git a/mobile/test/swarm/swarm_project_c_shots_test.dart b/mobile/test/swarm/swarm_project_c_shots_test.dart
index e661fe636..d9590f047 100644
--- a/mobile/test/swarm/swarm_project_c_shots_test.dart
+++ b/mobile/test/swarm/swarm_project_c_shots_test.dart
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:ui' as ui;
+import 'package:clock/clock.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
@@ -170,6 +171,24 @@ void main() {
.subtract(Duration(minutes: row['key'] == 'g2' ? 7 : 2))
.millisecondsSinceEpoch;
}
+ // Each agent's last progress on its task, by the test's clock, which
+ // the Team counts by: Nova's 4 minutes ago, Juno's question 7.
+ for (final row in groups.cast<Map>()) {
+ final minutes = switch (row['key']) {
+ 'g1' => 4,
+ 'g2' => 7,
+ _ => null,
+ };
+ if (minutes == null) continue;
+ final data = row['data'] as Map;
+ data['assignment'] = <String, dynamic>{
+ ...data['assignment'] as Map,
+ 'progressAt': clock
+ .now()
+ .subtract(Duration(minutes: minutes))
+ .millisecondsSinceEpoch,
+ };
+ }
final lead = (groups.first as Map)['data'] as Map;
lead
..['lastMessageSequence'] = 7
diff --git a/mobile/test/swarm/swarm_project_c_test.dart b/mobile/test/swarm/swarm_project_c_test.dart
index 26cdf381b..40eb0440f 100644
--- a/mobile/test/swarm/swarm_project_c_test.dart
+++ b/mobile/test/swarm/swarm_project_c_test.dart
@@ -1,6 +1,8 @@
import 'dart:async';
+import 'package:clock/clock.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/rendering.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';
@@ -186,6 +188,52 @@ void main() {
Future<SwarmHost> team(WidgetTester tester, FakeSwarm fake) =>
fromMenu(tester, fake, 'swarm-project-menu-team');
+ /// [data] of a group whose agent last reported progress [ago] before [at].
+ Map<String, dynamic> progressed(
+ Map<String, dynamic> data,
+ DateTime at,
+ Duration ago,
+ ) => {
+ ...data,
+ 'assignment': <String, dynamic>{
+ ...data['assignment'] as Map<String, dynamic>,
+ 'progressAt': at.subtract(ago).millisecondsSinceEpoch,
+ },
+ };
+
+ /// [fake] whose first read has Nova's g1 progress 4m 30s and Juno's g2
+ /// 2h before [at].
+ FakeSwarm timed(FakeSwarm fake, DateTime at) {
+ final load = fake.routes['/api/super-tabs/$tab/parts']!;
+ fake.routes['/api/super-tabs/$tab/parts'] = (body) async {
+ final read = (await load(body))! as Map<String, dynamic>;
+ read['groups'] = [
+ for (final g in (read['groups'] as List).cast<Map<String, dynamic>>())
+ switch (g['key']) {
+ 'g1' => {
+ ...g,
+ 'data': progressed(
+ g['data'] as Map<String, dynamic>,
+ at,
+ const Duration(minutes: 4, seconds: 30),
+ ),
+ },
+ 'g2' => {
+ ...g,
+ 'data': progressed(
+ g['data'] as Map<String, dynamic>,
+ at,
+ const Duration(hours: 2),
+ ),
+ },
+ _ => g,
+ },
+ ];
+ return read;
+ };
+ return fake;
+ }
+
/// The page with its Leaderboard sheet open.
Future<SwarmHost> leaderboard(WidgetTester tester, FakeSwarm fake) =>
fromMenu(tester, fake, 'swarm-project-menu-leaderboard');
@@ -919,6 +967,154 @@ void main() {
}
});
+ testWidgets("each says how long since its agent's last progress, in the "
+ "desktop's words, worked out again no more than once a minute, and "
+ 'from now when its state changes', (tester) async {
+ final start = clock.now();
+ final fake = timed(backend(), start);
+ await team(tester, fake);
+
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 4m',
+ );
+ expect(
+ heard(tester, 'swarm-member-agent-juno'),
+ 'Juno, Needs input · #2160 Saved views cache · 2h',
+ );
+ expect(heard(tester, 'swarm-member-agent-ash'), 'Ash, Idle');
+
+ // Past 5m since its progress, but the minute's tick is not due yet.
+ expect(SwarmProjectTeam.tick, const Duration(minutes: 1));
+ await tester.pump(const Duration(seconds: 40));
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 4m',
+ );
+ await tester.pump(const Duration(seconds: 20));
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 5m',
+ );
+
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(
+ cursor: 'c3',
+ groups: [
+ part(
+ 'g1',
+ 9,
+ progressed(
+ groupData(
+ 'g1',
+ title: 'Buddy chat header',
+ number: 2156,
+ agentIds: ['agent-lead', 'agent-builder'],
+ status: 'needs_human',
+ workerId: 'agent-builder',
+ lastMessageSequence: 3,
+ ),
+ clock.now(),
+ Duration.zero,
+ ),
+ ),
+ ],
+ );
+ await host(tester).session!.inbox.reader(tab)!.refresh();
+ await tester.pumpAndSettle();
+
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Needs input · #2156 Buddy chat header · now',
+ );
+ });
+
+ testWidgets('on a 320-point phone a long task gives way and its time '
+ 'stays whole', (tester) async {
+ tester.view
+ ..physicalSize = const Size(320, 568) * 3
+ ..devicePixelRatio = 3;
+ addTearDown(tester.view.reset);
+ final start = clock.now();
+ final fake = timed(backend(), start);
+ final load = fake.routes['/api/super-tabs/$tab/parts']!;
+ fake.routes['/api/super-tabs/$tab/parts'] = (body) async {
+ final read = (await load(body))! as Map<String, dynamic>;
+ for (final g in (read['groups'] as List).cast<Map>()) {
+ if (g['key'] == 'g1') {
+ (g['data'] as Map)['title'] =
+ 'Buddy chat header that runs far past the edge of a phone';
+ }
+ }
+ return read;
+ };
+ await team(tester, fake);
+ await tester.ensureVisible(key('swarm-member-agent-builder'));
+ await tester.pumpAndSettle();
+
+ final row = key('swarm-member-agent-builder');
+ final age = find.descendant(of: row, matching: key('swarm-member-age'));
+ expect(tester.widget<Text>(age).data, ' · 4m');
+ expect(
+ tester.getRect(age).right,
+ lessThanOrEqualTo(tester.getRect(row).right),
+ );
+ final words = find.descendant(
+ of: row,
+ matching: find.textContaining('Working · #2156'),
+ );
+ expect(
+ tester.renderObject<RenderParagraph>(words).didExceedMaxLines,
+ isTrue,
+ reason: 'the title is cut, not the time',
+ );
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header that runs far past the edge '
+ 'of a phone · 4m',
+ );
+ });
+
+ testWidgets('back in the app, its times are worked out at once', (
+ tester,
+ ) async {
+ final start = clock.now();
+ await team(tester, timed(backend(), start));
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 4m',
+ );
+
+ // Away for 40s, short of the minute's tick, in the states a phone
+ // passes through.
+ void go(List<AppLifecycleState> states) {
+ for (final state in states) {
+ tester.binding.handleAppLifecycleStateChanged(state);
+ }
+ }
+
+ go(const [
+ AppLifecycleState.inactive,
+ AppLifecycleState.hidden,
+ AppLifecycleState.paused,
+ ]);
+ await tester.pump(const Duration(seconds: 40));
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 4m',
+ );
+ go(const [
+ AppLifecycleState.hidden,
+ AppLifecycleState.inactive,
+ AppLifecycleState.resumed,
+ ]);
+ await tester.pump();
+
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 5m',
+ );
+ });
+
testWidgets('a row opens the task its agent holds', (tester) async {
await team(tester, backend());
@@ -1728,7 +1924,8 @@ void main() {
const messages = '/api/super-tabs/$tab/conversations/$leadChat/messages';
/// [backend] whose Swarm has a second project, Desktop, the person reads
- /// too: Ash, Mobile's agent, still holds work there; another agent named
+ /// too: Ash, Mobile's agent, still holds work there, its last progress 3h
+ /// ago; another agent named
/// Nova waits on the person there; and Mobile has the person's Buddy chat
/// with Pip.
FakeSwarm twoProjects() {
@@ -1773,14 +1970,18 @@ void main() {
'g3',
8,
there(
- groupData(
- 'g3',
- title: 'Desktop sign-in',
- number: 3001,
- agentIds: ['agent-ash'],
- status: 'working',
- workerId: 'agent-ash',
- lastMessageSequence: 2,
+ progressed(
+ groupData(
+ 'g3',
+ title: 'Desktop sign-in',
+ number: 3001,
+ agentIds: ['agent-ash'],
+ status: 'working',
+ workerId: 'agent-ash',
+ lastMessageSequence: 2,
+ ),
+ clock.now(),
+ const Duration(hours: 3),
),
),
),
@@ -1960,6 +2161,26 @@ void main() {
expect(fake.commands, isEmpty);
});
+ testWidgets('access taken away with the Team open says none of its '
+ "agents' times again, though its minute ticks by", (tester) async {
+ await team(tester, timed(backend(), clock.now()));
+ expect(
+ heard(tester, 'swarm-member-agent-builder'),
+ 'Nova, Working · #2156 Buddy chat header · 4m',
+ );
+
+ host(tester).session!.inbox.reader(tab)!.revoke();
+ await tester.pumpAndSettle();
+ await tester.pump(SwarmProjectTeam.tick * 3);
+ await tester.pumpAndSettle();
+
+ expect(find.byType(SwarmProjectTeamSheet), findsNothing);
+ expect(find.byType(SwarmMemberRow), findsNothing);
+ for (final words in ['· 4m', '· 5m', '· 7m', '· 2h', 'Nova', 'Juno']) {
+ expect(shown(words), findsNothing, reason: words);
+ }
+ });
+
testWidgets('access taken away with the menu open: it closes, and its rows '
'open nothing', (tester) async {
await pump(tester, backend(), page);
diff --git a/mobile/test/swarm/swarm_project_team_test.dart b/mobile/test/swarm/swarm_project_team_test.dart
index 3f6048dba..aca9b2abd 100644
--- a/mobile/test/swarm/swarm_project_team_test.dart
+++ b/mobile/test/swarm/swarm_project_team_test.dart
@@ -20,15 +20,29 @@ void main() {
).state,
);
- Map<String, dynamic> work(String agentId, String status, {int? number}) =>
- groupData(
- 'work-$agentId',
- title: 'Task of $agentId',
- number: number,
- agentIds: [agentId],
- status: status,
- workerId: agentId,
- );
+ Map<String, dynamic> work(
+ String agentId,
+ String status, {
+ int? number,
+ Duration? since,
+ }) {
+ final g = groupData(
+ 'work-$agentId',
+ title: 'Task of $agentId',
+ number: number,
+ agentIds: [agentId],
+ status: status,
+ workerId: agentId,
+ );
+ if (since == null) return g;
+ return {
+ ...g,
+ 'assignment': <String, dynamic>{
+ ...g['assignment'] as Map<String, dynamic>,
+ 'progressAt': now.subtract(since).millisecondsSinceEpoch,
+ },
+ };
+ }
SwarmTeamAgent of(List<SwarmTeamAgent> team, String agentId) =>
team.singleWhere((a) => a.agent.id == agentId);
@@ -268,4 +282,222 @@ void main() {
expect(swarmTeamAgentsLine(const []), '');
});
});
+ group('its time since its last progress', () {
+ test("is said in the desktop's words", () {
+ String age(Duration d) => swarmAgentAge(d);
+ expect(age(Duration.zero), 'now');
+ expect(age(const Duration(seconds: 59)), 'now');
+ expect(
+ age(const Duration(seconds: -30)),
+ 'now',
+ reason: 'a phone clock a little behind the Swarm',
+ );
+ expect(age(const Duration(minutes: 1)), '1m');
+ expect(age(const Duration(minutes: 59, seconds: 59)), '59m');
+ expect(age(const Duration(hours: 1)), '1h');
+ expect(age(const Duration(hours: 23, minutes: 59)), '23h');
+ expect(age(const Duration(days: 1)), '1d');
+ expect(age(const Duration(days: 12, hours: 5)), '12d');
+ });
+
+ test('ends the line of every state that holds a task', () {
+ final team = swarmProjectAgents(
+ swarm(
+ agents: [
+ agent('a-input', displayName: 'Ana'),
+ agent('a-stuck', displayName: 'Bo'),
+ agent('a-review', displayName: 'Cy'),
+ {
+ ...agent('a-limit', displayName: 'Di'),
+ 'limitedUntil': DateTime(
+ 2026,
+ 10,
+ 30,
+ 9,
+ 5,
+ ).toUtc().toIso8601String(),
+ },
+ {
+ ...agent('a-down', displayName: 'Ed'),
+ 'downSince': '2026-10-30T01:00:00Z',
+ },
+ agent('a-work', displayName: 'Gu'),
+ agent('a-check', displayName: 'Hu'),
+ {...agent('a-stop', displayName: 'Lu'), 'workDecision': 'stop'},
+ ],
+ groups: [
+ work('a-input', 'needs_human', since: const Duration(minutes: 4)),
+ work('a-stuck', 'blocked', since: const Duration(hours: 2)),
+ work('a-review', 'review', since: const Duration(minutes: 40)),
+ work('a-limit', 'working', since: const Duration(minutes: 12)),
+ work('a-down', 'working', since: const Duration(days: 3)),
+ work('a-work', 'working', since: const Duration(seconds: 20)),
+ work('a-check', 'reconciling', since: const Duration(minutes: 7)),
+ work('a-stop', 'working', since: const Duration(hours: 5)),
+ ],
+ ),
+ project,
+ now: now,
+ );
+
+ expect(
+ {for (final a in team) a.agent.id: a.line},
+ {
+ 'a-input': 'Needs input · Task of a-input · 4m',
+ 'a-stuck': 'Stuck · Task of a-stuck · 2h',
+ 'a-review': 'Waiting for review · Task of a-review · 40m',
+ 'a-limit': 'Limited until 09:05 · Task of a-limit · 12m',
+ 'a-down': 'Offline · Task of a-down · 3d',
+ 'a-work': 'Working · Task of a-work · now',
+ 'a-check': 'Checking · Task of a-check · 7m',
+ 'a-stop': 'Stopped · Task of a-stop · 5h',
+ },
+ );
+ });
+
+ test('is none with no task, or none the Swarm sent a time for', () {
+ final team = swarmProjectAgents(
+ swarm(
+ agents: [
+ agent('a-idle', displayName: 'Ana'),
+ {...agent('a-done', displayName: 'Bo'), 'workDecision': 'awaiting'},
+ agent('a-old', displayName: 'Cy'),
+ ],
+ groups: [work('a-old', 'working', number: 12)],
+ ),
+ project,
+ now: now,
+ );
+
+ expect(of(team, 'a-idle').line, 'Idle');
+ expect(of(team, 'a-done').line, 'Done');
+ expect(
+ of(team, 'a-old').line,
+ 'Working · #12 Task of a-old',
+ reason: 'an older server, or a read without the time, says no age',
+ );
+ });
+
+ test('starts again when its state changes: the agent posting it is '
+ 'progress', () {
+ List<SwarmTeamAgent> read(String status, Duration since) =>
+ swarmProjectAgents(
+ swarm(
+ agents: [agent('a1', displayName: 'Ana')],
+ groups: [work('a1', status, since: since)],
+ ),
+ project,
+ now: now,
+ );
+
+ expect(
+ of(read('working', const Duration(hours: 2)), 'a1').line,
+ 'Working · Task of a1 · 2h',
+ );
+ expect(
+ of(read('needs_human', Duration.zero), 'a1').line,
+ 'Needs input · Task of a1 · now',
+ );
+ });
+
+ test('counts by the time it is given', () {
+ final snapshot = swarm(
+ agents: [agent('a1', displayName: 'Ana')],
+ groups: [work('a1', 'working', since: const Duration(minutes: 4))],
+ );
+ String at(Duration later) => of(
+ swarmProjectAgents(snapshot, project, now: now.add(later)),
+ 'a1',
+ ).line;
+
+ expect(at(Duration.zero), 'Working · Task of a1 · 4m');
+ expect(at(const Duration(seconds: 59)), 'Working · Task of a1 · 4m');
+ expect(at(const Duration(minutes: 1)), 'Working · Task of a1 · 5m');
+ expect(at(const Duration(hours: 1)), 'Working · Task of a1 · 1h');
+ });
+
+ test("is never another project's, nor a Buddy chat's, nor a private "
+ "chat's the viewer is not in: no title and no time", () {
+ final team = swarmProjectAgents(
+ swarm(
+ agents: [
+ agent('a-there', displayName: 'Ash'),
+ agent('a-buddy', displayName: 'Bo'),
+ agent('a-private', displayName: 'Cy'),
+ agent('a-mine', displayName: 'Di'),
+ ],
+ groups: [
+ {
+ ...work('a-there', 'working', since: const Duration(hours: 3)),
+ 'projectId': 'project-2',
+ },
+ {
+ ...work('a-buddy', 'working', since: const Duration(hours: 3)),
+ 'kind': 'buddy',
+ 'buddyOwnerId': 'diego',
+ },
+ {
+ ...work('a-private', 'working', since: const Duration(hours: 3)),
+ 'audience': {
+ 'people': [
+ {'id': 'diego', 'generation': 'gen-diego'},
+ ],
+ },
+ },
+ {
+ ...work('a-mine', 'working', since: const Duration(hours: 3)),
+ 'audience': {
+ 'people': [
+ {'id': me, 'generation': 'gen-$me'},
+ ],
+ },
+ },
+ ],
+ ),
+ project,
+ now: now,
+ viewerId: me,
+ );
+
+ for (final id in ['a-there', 'a-buddy', 'a-private']) {
+ expect(of(team, id).task, isNull, reason: id);
+ expect(of(team, id).age, isNull, reason: id);
+ expect(of(team, id).line, 'Working', reason: id);
+ }
+ expect(of(team, 'a-mine').line, 'Working · Task of a-mine · 3h');
+ });
+
+ test('of an agent id or name reused in another project is not this '
+ "agent's", () {
+ final team = swarmProjectAgents(
+ swarm(
+ agents: [
+ agent('a-nova', displayName: 'Nova'),
+ {...agent('b-nova', displayName: 'Nova'), 'projectId': 'project-2'},
+ ],
+ groups: [
+ {
+ ...work('b-nova', 'working', since: const Duration(hours: 6)),
+ 'projectId': 'project-2',
+ },
+ {
+ ...groupData(
+ 'reused',
+ title: 'Reused id',
+ agentIds: ['a-nova'],
+ status: 'working',
+ workerId: 'a-nova',
+ ),
+ 'projectId': 'project-2',
+ },
+ ],
+ ),
+ project,
+ now: now,
+ );
+
+ expect([for (final a in team) a.agent.id], ['a-nova']);
+ expect(of(team, 'a-nova').line, 'Working');
+ });
+ });
}