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.

feat(mobile): update agent naming to use displayName and enhance desk tab naming logic

Dev jacob8a7ea4b9878d
diff --git a/mobile/lib/phone/desk_groups.dart b/mobile/lib/phone/desk_groups.dart
index 9ec93e8b4..b692cee1a 100644
--- a/mobile/lib/phone/desk_groups.dart
+++ b/mobile/lib/phone/desk_groups.dart
@@ -1,6 +1,8 @@
import 'package:harness_mobile/core/last_opened_agent.dart' show AgentRef;
+import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/state/desk_sync.dart';
+import 'package:harness_mobile/state/swarm.dart';
import 'agent_index.dart';
@@ -64,21 +66,42 @@ List<DeskGroup> deskGroups(AppNotifier notifier, List<AgentEntry> visible) {
if (tabs.isEmpty) {
return [DeskGroup(id: null, name: kEveryAgentGroupName, entries: openable)];
}
- final byKey = {
- for (final entry in openable)
+ Map<String, AgentEntry> keyed(Iterable<AgentEntry> entries) => {
+ for (final entry in entries)
DeskPaneRef(machineId: entry.machineId, agentId: entry.agent.id).key:
entry,
};
+ final byKey = keyed(openable);
+ final known = keyed(visible);
return [
for (final tab in tabs)
DeskGroup(
id: tab.id,
- name: tab.name,
+ name: deskTabName(
+ tab,
+ tab.panes.isEmpty ? null : known[tab.panes.first.key]?.agent,
+ ),
entries: [for (final pane in tab.panes) ?byKey[pane.key]],
),
];
}
+/// What a tab is called — the desktop's rule (`AppNotifier._syncAgentName`).
+///
+/// A name somebody gave it stands. Otherwise the tab is named after its first
+/// agent ([first]), and follows that agent's [Agent.displayName] as its session
+/// titles it — `Greet user` rather than the `Untitled Tab` the desk was left
+/// holding. An agent with no name of its own leaves the tab [Swarm.defaultName].
+///
+/// ⚠️ **Derived here, never written back.** Every window derives it the same
+/// way, and the desk syncs only names a person chose (`nameIsCustom`); writing a
+/// derived one would turn it into a chosen one on every computer.
+String deskTabName(DeskTab tab, Agent? first) {
+ if (tab.nameIsCustom || first == null) return tab.name;
+ final name = first.displayName;
+ return name == kUntitledPane ? Swarm.defaultName : name;
+}
+
/// Whether [agent] is on none of the desk's tabs — one opened from search or a
/// notification, which know nothing of tabs. False on a phone with no tabs,
/// where the single group holds everything.
diff --git a/mobile/lib/phone/desk_tabs_panel.dart b/mobile/lib/phone/desk_tabs_panel.dart
index 7d90012b2..36c6c6b8d 100644
--- a/mobile/lib/phone/desk_tabs_panel.dart
+++ b/mobile/lib/phone/desk_tabs_panel.dart
@@ -203,9 +203,9 @@ class _DeskTabsPanelState extends State<DeskTabsPanel> {
final group = DeskGroup(
id: notifier.createDeskTabFor(
_refOf(entry),
- name: entry.agent.name,
+ name: entry.agent.displayName,
),
- name: entry.agent.name,
+ name: entry.agent.displayName,
entries: [entry],
);
if (group.id == null) return;
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index f10957357..e659ee59b 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -5055,7 +5055,10 @@ class AppNotifier extends ChangeNotifier {
// Created HERE, so it joins the tab this phone is in — the way an agent
// created in a window joins that window's tab. See [PhoneDesk.adopt] for
// what happens when the phone is in no tab.
- _desk.adopt((machineId: machineId, agentId: agent.id), name: agent.name);
+ _desk.adopt(
+ (machineId: machineId, agentId: agent.id),
+ name: agent.displayName,
+ );
await assignAgentToPane(
null,
machineId,
diff --git a/mobile/test/desk_fixture.dart b/mobile/test/desk_fixture.dart
index 2f6ee384e..37c10bc39 100644
--- a/mobile/test/desk_fixture.dart
+++ b/mobile/test/desk_fixture.dart
@@ -40,10 +40,17 @@ class DeskApi extends ApiClient {
}
}
-/// A tab of `m`'s agents, named.
-DeskTab deskTab(String id, String name, List<String> agentIds) => DeskTab(
+/// A tab of `m`'s agents, named — by hand unless [custom] is false, when the
+/// name is the desk's placeholder and the tab is called after its first agent.
+DeskTab deskTab(
+ String id,
+ String name,
+ List<String> agentIds, {
+ bool custom = true,
+}) => DeskTab(
id: id,
name: name,
+ nameIsCustom: custom,
panes: [
for (final agentId in agentIds)
DeskPaneRef(machineId: 'm', agentId: agentId),
diff --git a/mobile/test/desk_groups_test.dart b/mobile/test/desk_groups_test.dart
index 7a72c6610..fb97695b4 100644
--- a/mobile/test/desk_groups_test.dart
+++ b/mobile/test/desk_groups_test.dart
@@ -1,7 +1,9 @@
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/phone/agent_index.dart';
import 'package:harness_mobile/phone/desk_groups.dart';
import 'package:harness_mobile/state/app_state.dart';
+import 'package:harness_mobile/state/desk_sync.dart';
import 'agent_pager_fixture.dart';
import 'desk_fixture.dart';
@@ -47,10 +49,10 @@ void main() {
test('the agents no tab holds are in no group — there is no Other', () async {
final built = await appWith(['a'], ['b']);
- expect([for (final group in groupsOf(built)) group.name], [
- 'Desktop',
- 'Docker',
- ]);
+ expect(
+ [for (final group in groupsOf(built)) group.name],
+ ['Desktop', 'Docker'],
+ );
expect(isUntabbed(built, (machineId: 'm', agentId: 'c')), isTrue);
expect(isUntabbed(built, (machineId: 'm', agentId: 'a')), isFalse);
});
@@ -111,4 +113,44 @@ void main() {
expect(activeDeskGroup(built, groups, null).name, 'Docker');
});
+
+ group('a tab nobody named is called after its first agent', () {
+ Future<AppNotifier> named(List<DeskTab> tabs) async {
+ final built = await deskApp(conn, tabs: tabs);
+ addTearDown(built.dispose);
+ return built;
+ }
+
+ test('its display name, as the desktop names the tab', () async {
+ final built = await named([
+ deskTab('t1', 'Untitled Tab', ['c', 'a'], custom: false),
+ ]);
+ built.stateOf('m')!.agents = [
+ for (final agent in built.stateOf('m')!.agents)
+ agent.id == 'c'
+ ? Agent(id: 'c', name: 'harness-3', title: 'Greet user')
+ : agent,
+ ];
+
+ expect(groupsOf(built).single.name, 'Greet user');
+ });
+
+ test('a name somebody chose stands', () async {
+ final built = await named([
+ deskTab('t1', 'Docker', ['c']),
+ ]);
+
+ expect(groupsOf(built).single.name, 'Docker');
+ });
+
+ test('an agent with no name of its own leaves the placeholder', () {
+ final tab = deskTab('t1', 'Untitled Tab', ['c'], custom: false);
+
+ expect(
+ deskTabName(tab, const Agent(id: 'c', name: 'harness-3')),
+ 'Untitled Tab',
+ );
+ expect(deskTabName(tab, null), 'Untitled Tab');
+ });
+ });
}