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.

Use actual visits for welcome session recency (#439)

Deebcb24e6c8e05
diff --git a/desktop/lib/state/welcome_sessions.dart b/desktop/lib/state/welcome_sessions.dart
index 79fabc037..0f2dc0f89 100644
--- a/desktop/lib/state/welcome_sessions.dart
+++ b/desktop/lib/state/welcome_sessions.dart
@@ -8,7 +8,8 @@ import 'swarm_search.dart' show externalSessionDestination;
/// What the welcome page offers to pick up: the harnesses you were just with,
/// and the Claude Code and Codex conversations on your machines that Harness
-/// did not start — the latest [limit] of them by activity, whatever machine.
+/// did not start — the latest [limit] of them, whatever machine. Harnesses use
+/// recorded visits; external conversations use their conversation activity.
///
/// Read once when the page shows, like Cmd-P: the rows keep their order and
/// numbers while the page is on screen, and the next showing reads again.
@@ -41,6 +42,13 @@ class WelcomeSessions extends ChangeNotifier {
final _asked = <String>{};
bool _hadAgents = false;
List<SwarmDestination> _external = const [];
+ Map<String, DateTime?> _harnessVisits = const {};
+
+ /// The same snapshot supplies both order and age. An older daemon can tell
+ /// us a harness was opened without a visit time; leave its age unknown,
+ /// rather than presenting a background hook or transcript write as a visit.
+ DateTime? lastUsedAt(SwarmDestination row) =>
+ row.external != null ? row.lastActivityAt : _harnessVisits[row.id];
/// The app changed. At launch the page shows before machines connect and
/// their harnesses arrive — before most of what it offers exists — so a
@@ -51,19 +59,17 @@ class WelcomeSessions extends ChangeNotifier {
final unasked = app.searchableMachineIds.any(
(machine) => !_asked.contains(machine),
);
- if (unasked || (!_hadAgents && _anyAgents)) load();
+ if (unasked || (!_hadAgents && _readHarnessVisits().isNotEmpty)) load();
}
Future<void> load() async {
readAt = _now();
+ _harnessVisits = _readHarnessVisits();
final harnesses = [
for (final row in SwarmSearchCatalog().read(app, projects))
- if (row.agentId != null &&
- row.lastActivityAt != null &&
- app.stateOf(row.machineId ?? '')?.nodeOnline != false)
- row,
+ if (row.agentId != null && _harnessVisits.containsKey(row.id)) row,
];
- _hadAgents = _anyAgents;
+ _hadAgents = _harnessVisits.isNotEmpty;
// What the machines said last stays until they answer again.
_rows = _latest([...harnesses, ..._external]);
loading = true;
@@ -99,14 +105,27 @@ class WelcomeSessions extends ChangeNotifier {
notifyListeners();
}
- bool get _anyAgents =>
- app.machineStates.values.any((machine) => machine.agents.isNotEmpty);
+ Map<String, DateTime?> _readHarnessVisits() {
+ final open = {
+ for (final pane in app.allPanes) (pane.machineId, pane.agentId),
+ };
+ return {
+ for (final machine in app.machineStates.values)
+ if (machine.nodeOnline != false)
+ for (final agent in machine.agents)
+ if (agent.lastOpenedAt != null ||
+ open.contains((machine.machine.machineId, agent.id)) ||
+ app.hasOpenedHarness(machine.machine.machineId, agent.id))
+ agentDestinationId(machine.machine.machineId, agent.id):
+ agent.lastOpenedAt,
+ };
+ }
List<SwarmDestination> _latest(List<SwarmDestination> all) {
final sorted = [...all]
..sort(
- (a, b) => (b.lastActivityAt ?? DateTime(0)).compareTo(
- a.lastActivityAt ?? DateTime(0),
+ (a, b) => (lastUsedAt(b) ?? DateTime(0)).compareTo(
+ lastUsedAt(a) ?? DateTime(0),
),
);
return List.unmodifiable(sorted.take(limit));
diff --git a/desktop/lib/widgets/workspace_welcome.dart b/desktop/lib/widgets/workspace_welcome.dart
index 9fd67f2ea..36bbb60e9 100644
--- a/desktop/lib/widgets/workspace_welcome.dart
+++ b/desktop/lib/widgets/workspace_welcome.dart
@@ -471,7 +471,7 @@ class _WorkspaceWelcomeState extends State<WorkspaceWelcome> {
final agent = row.agentId == null
? null
: machine?.agents.where((agent) => agent.id == row.agentId).firstOrNull;
- final at = row.lastActivityAt;
+ final at = _sessions!.lastUsedAt(row);
final readAt = _sessions!.readAt;
final age = at == null
? ''
diff --git a/desktop/test/welcome_sessions_test.dart b/desktop/test/welcome_sessions_test.dart
index c409c811a..3a3f59881 100644
--- a/desktop/test/welcome_sessions_test.dart
+++ b/desktop/test/welcome_sessions_test.dart
@@ -46,6 +46,7 @@ Agent _agent(String id, String name, Duration ago) => Agent(
engine: 'claude',
terminalAvailable: true,
lastActivityAt: _now.subtract(ago),
+ lastOpenedAt: _now.subtract(ago),
);
/// A machine with three harnesses and, on its disk, three conversations
@@ -76,6 +77,136 @@ Agent _agent(String id, String name, Duration ago) => Agent(
}
void main() {
+ test(
+ 'discovered sessions never opened by the user stay out of recents',
+ () async {
+ final (:sessions, connection: _) = _setup();
+ sessions.app.machineStates['m']!.agents.addAll([
+ Agent(
+ id: 'probe',
+ name: 'Temporary engine test',
+ engine: 'grok',
+ terminalAvailable: true,
+ lastActivityAt: _now,
+ ),
+ Agent(
+ id: 'helper',
+ name: 'Background helper',
+ engine: 'codex',
+ terminalAvailable: true,
+ lastActivityAt: _now,
+ ),
+ ]);
+
+ await sessions.load();
+
+ expect(
+ sessions.rows.map((row) => row.external?.sessionId ?? row.agentId),
+ ['a1', 'e-nfc', 'a2', 'e-old'],
+ );
+ },
+ );
+
+ test(
+ 'a background conversation update does not count as a recent visit',
+ () async {
+ final (:sessions, connection: _) = _setup();
+ sessions.app.machineStates['m']!.agents = [
+ Agent(
+ id: 'old',
+ name: 'Last visited four days ago',
+ engine: 'codex',
+ terminalAvailable: true,
+ lastOpenedAt: _now.subtract(const Duration(days: 4)),
+ lastActivityAt: _now,
+ ),
+ _agent(
+ 'recent',
+ 'Last visited five minutes ago',
+ const Duration(minutes: 5),
+ ),
+ ];
+
+ await sessions.load();
+
+ expect(
+ sessions.rows.map((row) => row.external?.sessionId ?? row.agentId),
+ ['recent', 'e-nfc', 'old', 'e-old'],
+ );
+ },
+ );
+
+ test('discovery alone does not block visit history arriving later', () async {
+ final connection = SearchConnection({'': []});
+ final app = createApp(
+ connected: true,
+ connectionForTest: (_) => connection,
+ );
+ addTearDown(app.dispose);
+ final machine = app.machineStates['m']!;
+ machine.agents = [
+ Agent(
+ id: 'probe',
+ name: 'Unopened probe',
+ terminalAvailable: true,
+ lastActivityAt: _now,
+ ),
+ ];
+ final sessions = WelcomeSessions(app, now: () => _now);
+ addTearDown(sessions.dispose);
+ await sessions.load();
+ expect(sessions.rows, isEmpty);
+
+ machine.agents = [
+ ...machine.agents,
+ _agent('visited', 'Previously visited', const Duration(minutes: 5)),
+ ];
+ sessions.appChanged();
+ await pumpEventQueue();
+ expect(sessions.rows.map((row) => row.agentId), ['visited']);
+ });
+
+ testWidgets('the welcome age shows the visit, never background activity', (
+ tester,
+ ) async {
+ final connection = SearchConnection({'': []});
+ final app = createApp(
+ connected: true,
+ connectionForTest: (_) => connection,
+ );
+ addTearDown(app.dispose);
+ final now = DateTime.now();
+ app.machineStates['m']!.agents = [
+ Agent(
+ id: 'old',
+ name: 'Old conversation with new background activity',
+ engine: 'codex',
+ terminalAvailable: true,
+ lastOpenedAt: now.subtract(const Duration(days: 4)),
+ lastActivityAt: now,
+ ),
+ Agent(
+ id: 'legacy',
+ name: 'Previously opened on an older daemon',
+ engine: 'claude',
+ terminalAvailable: true,
+ lastActivityAt: now,
+ ),
+ ];
+ app.rememberOpenedHarness('m', 'legacy');
+ await tester.pumpWidget(
+ MaterialApp(
+ home: WorkspaceWelcome(onCommand: (_) {}, app: app, onOpen: (_) {}),
+ ),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 50));
+
+ expect(find.text('4d'), findsOneWidget);
+ expect(find.text('Previously opened on an older daemon'), findsOneWidget);
+ expect(find.text('now'), findsNothing);
+ });
+
test('offers harnesses and conversations Harness did not start, latest first, never one open elsewhere', () async {
final (:connection, :sessions) = _setup();
final loading = sessions.load();
@@ -348,5 +479,11 @@ void main() {
sessions.appChanged();
await pumpEventQueue();
expect(connection.asked, ['']);
+ expect(
+ sessions.lastUsedAt(sessions.rows.first),
+ _now.subtract(const Duration(minutes: 5)),
+ reason:
+ 'the displayed age stays with the same visit snapshot as the order',
+ );
});
}