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.

Desktop: Auto rename names a tab for its repo and work, from the daemon's window_name (#994)

lingrd6a9eb9a0171f
diff --git a/desktop/lib/settings/sections/appearance_section.dart b/desktop/lib/settings/sections/appearance_section.dart
index e234607c8..c5470167a 100644
--- a/desktop/lib/settings/sections/appearance_section.dart
+++ b/desktop/lib/settings/sections/appearance_section.dart
@@ -48,6 +48,26 @@ class AppearanceSection extends StatelessWidget {
),
),
),
+ const SizedBox(height: 10),
+ ValueListenableBuilder<AppearancePrefs>(
+ valueListenable: preferences,
+ builder: (context, prefs, _) => SettingRow(
+ title: 'Auto rename',
+ controlSemanticLabel: 'Auto rename tabs',
+ detail:
+ 'Names a tab for its repo and the work in it, in the '
+ 'background — e.g. Harness TUI LMStudio',
+ control: Align(
+ alignment: Alignment.centerLeft,
+ child: Switch(
+ key: const ValueKey('auto-rename-tabs'),
+ value: prefs.autoRenameTabs,
+ onChanged: (enabled) =>
+ unawaited(preferences.setAutoRenameTabs(enabled)),
+ ),
+ ),
+ ),
+ ),
const SizedBox(height: 24),
PaletteSection(store: store),
// Room under the last card so a scrolled-to-bottom pane does not end
diff --git a/desktop/lib/shared/theme/appearance_prefs_store.dart b/desktop/lib/shared/theme/appearance_prefs_store.dart
index dbfe50eea..f9e0faf1b 100644
--- a/desktop/lib/shared/theme/appearance_prefs_store.dart
+++ b/desktop/lib/shared/theme/appearance_prefs_store.dart
@@ -24,6 +24,7 @@ class AppearancePrefs {
this.custom = const CustomBackground(),
this.paneOpacity = paneOpacityDefault,
this.shadeInactivePanes = false,
+ this.autoRenameTabs = false,
this.prompt = const PromptPrefs(),
});
@@ -43,6 +44,11 @@ class AppearancePrefs {
/// Whether panes outside the current focus receive a neutral-gray veil.
final bool shadeInactivePanes;
+ /// Whether a tab without a custom name asks its machine's daemon for one
+ /// (`window_name`) and shows it instead of the voted label. Off, no request
+ /// is made and every label is the one it always was.
+ final bool autoRenameTabs;
+
/// Whether a running harness tab paints the background at all: Blank has
/// nothing to show through.
bool get showsBackground => background != HarnessBackground.plain;
@@ -70,6 +76,7 @@ class AppearancePrefs {
CustomBackground? custom,
double? paneOpacity,
bool? shadeInactivePanes,
+ bool? autoRenameTabs,
PromptPrefs? prompt,
bool clearUiFamily = false,
}) => AppearancePrefs(
@@ -80,6 +87,7 @@ class AppearancePrefs {
custom: custom ?? this.custom,
paneOpacity: paneOpacity ?? this.paneOpacity,
shadeInactivePanes: shadeInactivePanes ?? this.shadeInactivePanes,
+ autoRenameTabs: autoRenameTabs ?? this.autoRenameTabs,
prompt: prompt ?? this.prompt,
);
@@ -93,6 +101,7 @@ class AppearancePrefs {
other.custom == custom &&
other.paneOpacity == paneOpacity &&
other.shadeInactivePanes == shadeInactivePanes &&
+ other.autoRenameTabs == autoRenameTabs &&
other.prompt == prompt;
@override
@@ -104,6 +113,7 @@ class AppearancePrefs {
custom,
paneOpacity,
shadeInactivePanes,
+ autoRenameTabs,
prompt,
);
}
@@ -130,6 +140,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
// Named for the retired on/off choice; it now holds only pane opacity.
static const _paneOpacityKey = 'harness_background_behind_harnesses';
static const _shadeInactivePanesKey = 'harness_shade_inactive_panes';
+ static const _autoRenameTabsKey = 'harness_auto_rename_tabs';
static const _promptKey = 'workspace_prompt_v1';
Future<void>? _promptSave;
Future<void>? _paletteSave;
@@ -137,6 +148,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
Future<void>? _customSave;
Future<void>? _paneOpacitySave;
Future<void>? _shadeInactivePanesSave;
+ Future<void>? _autoRenameTabsSave;
final LocalKeyValueStore _storage;
final Directory? _backgroundsDirectory;
@@ -168,6 +180,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
_customKey,
_paneOpacityKey,
_shadeInactivePanesKey,
+ _autoRenameTabsKey,
_promptKey,
]);
final custom = _customFrom(saved[_customKey]);
@@ -184,6 +197,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
custom: custom,
paneOpacity: _paneOpacityFrom(saved[_paneOpacityKey]),
shadeInactivePanes: saved[_shadeInactivePanesKey] == 'true',
+ autoRenameTabs: saved[_autoRenameTabsKey] == 'true',
prompt: _promptFrom(saved[_promptKey]),
);
} catch (_) {
@@ -337,6 +351,29 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
}
}
+ /// Same ordering as [setShadeInactivePanes].
+ Future<void> setAutoRenameTabs(bool enabled) {
+ if (value.autoRenameTabs == enabled) {
+ return _autoRenameTabsSave ?? Future.value();
+ }
+ value = value.copyWith(autoRenameTabs: enabled);
+ return _autoRenameTabsSave ??= _saveAutoRenameTabs();
+ }
+
+ Future<void> _saveAutoRenameTabs() async {
+ try {
+ while (true) {
+ final enabled = value.autoRenameTabs;
+ await _storage.write(_autoRenameTabsKey, enabled.toString());
+ if (value.autoRenameTabs == enabled) break;
+ }
+ } catch (_) {
+ // Keep the choice for this run if storage is unavailable.
+ } finally {
+ _autoRenameTabsSave = null;
+ }
+ }
+
/// Older builds also saved an `on` flag here; it is ignored.
static double _paneOpacityFrom(String? raw) {
try {
@@ -430,6 +467,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
await _customSave;
await _paneOpacitySave;
await _shadeInactivePanesSave;
+ await _autoRenameTabsSave;
await _promptSave;
try {
await _storage.delete(_familyKey);
@@ -439,6 +477,7 @@ class AppearancePrefsStore extends ValueNotifier<AppearancePrefs> {
await _storage.delete(_customKey);
await _storage.delete(_paneOpacityKey);
await _storage.delete(_shadeInactivePanesKey);
+ await _storage.delete(_autoRenameTabsKey);
await _storage.delete(_promptKey);
} catch (_) {
// See above.
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 38886fc6f..fc297b151 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -103,6 +103,8 @@ import 'search_when.dart';
import 'session_content_search.dart';
import 'session_preview.dart';
import 'session_tail.dart';
+import 'window_names.dart';
+import '../shared/theme/appearance_prefs_store.dart';
import '../usage/models_menu_controller.dart';
import '../usage/remote_usage.dart';
import '../usage/usage_accounts.dart';
@@ -2956,6 +2958,8 @@ class AppNotifier extends ChangeNotifier {
this.agentUnread.addListener(_announceUnreadToDial);
experimentalFeatures.addListener(_devicesExperimentChanged);
addListener(_syncDeviceHosts);
+ _autoRenameTabs = appearancePrefsStore.value.autoRenameTabs;
+ appearancePrefsStore.addListener(_autoRenameChanged);
}
/// Through the local CLI in a desktop build; straight to the backend, signed, in a viewer.
@@ -10197,6 +10201,51 @@ class AppNotifier extends ChangeNotifier {
}
}
+ /// Names for tabs from their machines' daemons, asked only while
+ /// [autoRenameTabs] is on (see `workspaceTabNames`).
+ late final windowNames = WindowNames(
+ ask: (machineId, agentIds) => _conn(machineId).request(
+ 'window_name',
+ payload: {'agentIds': agentIds},
+ timeout: const Duration(seconds: 10),
+ ),
+ onChanged: () {
+ if (!_disposed) notifyListeners();
+ },
+ );
+
+ /// Settings ▸ Appearance ▸ Auto rename.
+ bool get autoRenameTabs => _autoRenameTabs;
+ bool _autoRenameTabs = false;
+
+ void _autoRenameChanged() {
+ final enabled = appearancePrefsStore.value.autoRenameTabs;
+ if (enabled == _autoRenameTabs) return;
+ _autoRenameTabs = enabled;
+ // Every tab label switches between the daemon's name and the voted one.
+ if (!_disposed) notifyListeners();
+ }
+
+ /// The daemon's name for one tab's [request], or null to keep the voted
+ /// label. Only this computer's own daemon is asked: a relayed machine's
+ /// request would cross the relay unsealed, since `window_name` is not in the
+ /// e2ee lists (cli/src/lib/e2ee/core.ts) yet. A machine that is offline or
+ /// shared view-only is not asked either: its silence would read as an
+ /// older daemon and quiet it for long.
+ String? windowNameFor(WindowNameRequest request) {
+ final machine = machineStates[request.machineId];
+ return windowNames.nameFor(
+ request,
+ reachable:
+ machine != null &&
+ machine.isLocalMachine &&
+ !machine.machine.isShared &&
+ !machine.needsLink &&
+ machine.nodeOnline != false &&
+ machine.connectionStatus == ConnectionStatus.connected,
+ );
+ }
+
Future<MachineUsage?> _readMachineUsage(MachineState machine) async {
try {
final reply = await _conn(machine.machine.machineId)
@@ -16300,6 +16349,8 @@ class AppNotifier extends ChangeNotifier {
}
grid.AppTheme.palette.removeListener(_announceTerminalThemeEverywhere);
terminalThemeStore.removeListener(_announceTerminalThemeEverywhere);
+ appearancePrefsStore.removeListener(_autoRenameChanged);
+ windowNames.dispose();
_localGitProjects.dispose();
sessionPreviews.dispose();
agentPulse.dispose();
diff --git a/desktop/lib/state/window_names.dart b/desktop/lib/state/window_names.dart
new file mode 100644
index 000000000..727f586d7
--- /dev/null
+++ b/desktop/lib/state/window_names.dart
@@ -0,0 +1,153 @@
+import 'dart:async';
+import 'dart:convert';
+
+import 'package:flutter/foundation.dart';
+
+/// One tab's `window_name` question: every agent of the tab on [machineId], in
+/// pane order, with the name each one shows now — so a title change is a new
+/// question rather than an old answer.
+typedef WindowNameRequest = ({
+ String machineId,
+ List<String> agentIds,
+ List<String> names,
+});
+
+/// Tab names a machine's daemon writes for the repo work in a tab
+/// (`window_name`, docs/plans/2026-10-07-002-window-auto-rename-daemon-plan.md).
+///
+/// Answers live in memory only. A read never waits: it returns what is known
+/// and asks in the background, at most once at a time per question. While a
+/// new question for the same agents is out (a title changed), their last name
+/// stays rather than flicking back to the voted label. `pending` is asked
+/// again after [retryAfter] — one timer for every pending question, which only
+/// wakes the app; the tabs still shown then ask again. An error (an older
+/// daemon, the service off) keeps that machine quiet for [quietFor]; a `null`
+/// name (no repo, no model, a failed naming) is asked again after as long.
+class WindowNames {
+ WindowNames({
+ required this.ask,
+ required this.onChanged,
+ this.retryAfter = const Duration(seconds: 5),
+ this.quietFor = const Duration(minutes: 10),
+ });
+
+ /// Sends `window_name` to the machine and returns its `window_name_result`.
+ final Future<Map<String, dynamic>> Function(
+ String machineId,
+ List<String> agentIds,
+ )
+ ask;
+
+ /// A name came or went, or pending questions may be asked again.
+ final VoidCallback onChanged;
+ final Duration retryAfter, quietFor;
+
+ static const _kept = 200;
+
+ /// The daemon's answer per question, oldest first; null is "keep the voted
+ /// label".
+ final _answers = <String, String?>{};
+
+ /// The last name per machine and agents, whatever their titles.
+ final _shown = <String, String>{};
+ final _asking = <String>{};
+ final _pending = <String>{};
+ final _quiet = <String, Timer>{};
+ final _forget = <Timer>[];
+ Timer? _retry;
+ bool _disposed = false;
+
+ /// The daemon's name for [request], or null to keep the voted label. Asks
+ /// when nothing is known yet and [reachable] says the machine can answer.
+ String? nameFor(WindowNameRequest request, {bool reachable = true}) {
+ final agents = jsonEncode([request.machineId, request.agentIds]);
+ final key = jsonEncode([
+ request.machineId,
+ request.agentIds,
+ request.names,
+ ]);
+ if (_answers.containsKey(key)) return _answers[key];
+ if (_quiet.containsKey(request.machineId)) return null;
+ if (reachable &&
+ !_disposed &&
+ !_asking.contains(key) &&
+ !_pending.contains(key)) {
+ _asking.add(key);
+ // Labels are read while widgets build; the request (and the notify its
+ // answer causes) starts after that frame.
+ scheduleMicrotask(() => _ask(key, agents, request));
+ }
+ return _shown[agents];
+ }
+
+ Future<void> _ask(
+ String key,
+ String agents,
+ WindowNameRequest request,
+ ) async {
+ Map<String, dynamic>? reply;
+ try {
+ reply = await ask(request.machineId, request.agentIds);
+ } catch (_) {
+ reply = null;
+ }
+ _asking.remove(key);
+ if (_disposed) return;
+ final name = reply?['name'];
+ if (reply == null || reply['error'] != null) {
+ _quiet[request.machineId] ??= Timer(
+ quietFor,
+ () => _quiet.remove(request.machineId),
+ );
+ // Its tabs still asking go back to the voted label.
+ onChanged();
+ } else if (name is String && name.trim().isNotEmpty) {
+ _remember(key, name.trim());
+ _shown.remove(agents);
+ _shown[agents] = name.trim();
+ _trim(_shown);
+ onChanged();
+ } else if (reply['pending'] == true) {
+ _pending.add(key);
+ _retry ??= Timer(retryAfter, () {
+ _retry = null;
+ _pending.clear();
+ if (!_disposed) onChanged();
+ });
+ } else {
+ _remember(key, null);
+ // The daemon retries a failed naming after [quietFor] too; ask then.
+ _forget.add(
+ Timer(quietFor, () {
+ if (_answers.containsKey(key) && _answers[key] == null) {
+ _answers.remove(key);
+ }
+ }),
+ );
+ _forget.removeWhere((timer) => !timer.isActive);
+ if (_shown.remove(agents) != null) onChanged();
+ }
+ }
+
+ void _remember(String key, String? name) {
+ _answers[key] = name;
+ _trim(_answers);
+ }
+
+ /// Map literals keep insertion order, so the first key is the oldest.
+ static void _trim(Map<String, Object?> map) {
+ while (map.length > _kept) {
+ map.remove(map.keys.first);
+ }
+ }
+
+ void dispose() {
+ _disposed = true;
+ _retry?.cancel();
+ for (final timer in [..._quiet.values, ..._forget]) {
+ timer.cancel();
+ }
+ _quiet.clear();
+ _forget.clear();
+ }
+}
diff --git a/desktop/lib/state/workspace_status.dart b/desktop/lib/state/workspace_status.dart
index 3cfba92f7..b77c20cea 100644
--- a/desktop/lib/state/workspace_status.dart
+++ b/desktop/lib/state/workspace_status.dart
@@ -6,6 +6,7 @@ import '../widgets/engine_identity.dart';
import 'app_state.dart';
import 'swarm.dart';
import 'terminal_pane.dart';
+import 'window_names.dart';
/// A tab's type describes its harness panes. Viewers never cast a second vote
/// for their owner. Ties follow pane order, independently of keyboard focus.
@@ -41,8 +42,55 @@ enum _TabTrait { type, project, machine }
typedef _TabName = ({_TabTrait trait, String label, int count});
+/// What `window_name` asks for [tab]: the machine most of its harness panes in
+/// a git repo are on (a tie: the first such pane's), with every agent of the
+/// tab on that machine in pane order — the daemon picks the repo ones itself.
+/// Null for a custom-named or special tab, or one with no harness in a repo.
+WindowNameRequest? windowNameRequest(AppNotifier app, Swarm tab) {
+ if (tab.nameIsCustom ||
+ tab.isStore ||
+ tab.isCompanions ||
+ tab.isDevices ||
+ tab.isOrchestrator) {
+ return null;
+ }
+ final agents = <String, List<Agent>>{};
+ final inRepo = <String, int>{};
+ for (final pane in tab.panes) {
+ final agent = pane.isViewer
+ ? null
+ : _agentFor(app, pane.machineId, pane.agentId);
+ if (agent == null) continue;
+ final mine = agents.putIfAbsent(pane.machineId, () => []);
+ if (mine.any((other) => other.id == agent.id)) continue;
+ mine.add(agent);
+ if (agent.project?.branch?.isNotEmpty == true &&
+ !isTerminalEngine(agent.engine)) {
+ inRepo.update(pane.machineId, (n) => n + 1, ifAbsent: () => 1);
+ }
+ }
+ if (inRepo.isEmpty) return null;
+ // Machines enter [inRepo] in pane order, so a tie keeps the earlier one.
+ final machineId = inRepo.entries
+ .reduce((a, b) => b.value > a.value ? b : a)
+ .key;
+ return (
+ machineId: machineId,
+ agentIds: [for (final agent in agents[machineId]!) agent.id],
+ names: [for (final agent in agents[machineId]!) agent.displayName],
+ );
+}
+
+/// The daemon's name for [tab] while Auto rename is on; null keeps the vote.
+String? _autoName(AppNotifier app, Swarm tab) {
+ if (!app.autoRenameTabs) return null;
+ final request = windowNameRequest(app, tab);
+ return request == null ? null : app.windowNameFor(request);
+}
+
/// Prefer the strongest shared trait, then the one least repeated in other
/// tabs. Type wins otherwise equal choices; focus and custom names never vote.
+/// With Auto rename on, a name from the tab's machine replaces the vote.
Map<String, String> workspaceTabNames(AppNotifier app) {
final candidates = <String, List<_TabName>>{};
for (final tab in app.swarms) {
@@ -98,6 +146,7 @@ Map<String, String> workspaceTabNames(AppNotifier app) {
),
)
.length;
+ final autoNames = {for (final tab in app.swarms) tab.id: _autoName(app, tab)};
return {
for (final tab in app.swarms)
tab.id: tab.nameIsCustom
@@ -110,6 +159,8 @@ Map<String, String> workspaceTabNames(AppNotifier app) {
? Swarm.devicesName
: tab.isOrchestrator
? 'orchestrator'
+ : autoNames[tab.id] != null
+ ? autoNames[tab.id]!
: candidates[tab.id]!.isEmpty
? Swarm.defaultName
: candidates[tab.id]!.reduce((a, b) {
diff --git a/desktop/lib/ws/ws_conn.dart b/desktop/lib/ws/ws_conn.dart
index f2e39eef4..c30e3bfdf 100644
--- a/desktop/lib/ws/ws_conn.dart
+++ b/desktop/lib/ws/ws_conn.dart
@@ -600,6 +600,10 @@ class WsConn {
'agent_handoff_prepare_result',
'project_preview',
'project_preview_result',
+ // A name made from the panes' titles, asked again every few seconds
+ // while the daemon is still writing it.
+ 'window_name',
+ 'window_name_result',
'git_project_info',
'git_project_info_result',
'terminal_output',
diff --git a/desktop/test/appearance_prefs_store_test.dart b/desktop/test/appearance_prefs_store_test.dart
index c9d85edfb..26dd364cb 100644
--- a/desktop/test/appearance_prefs_store_test.dart
+++ b/desktop/test/appearance_prefs_store_test.dart
@@ -35,6 +35,7 @@ void main() {
expect(prefs.uiFamily, isNull);
expect(prefs.uiSize, 14);
expect(prefs.shadeInactivePanes, isFalse);
+ expect(prefs.autoRenameTabs, isFalse);
// Legacy fields remain readable, but no longer control app typography.
});
@@ -129,6 +130,25 @@ void main() {
});
});
+ group('Auto rename', () {
+ test('is off until turned on, and stays on across launches', () async {
+ final storage = _FakeStore();
+ final store = AppearancePrefsStore(storage: storage);
+ await store.load();
+ expect(store.value.autoRenameTabs, isFalse);
+
+ await store.setAutoRenameTabs(true);
+ expect(storage.values['harness_auto_rename_tabs'], 'true');
+ final relaunched = AppearancePrefsStore(storage: storage);
+ await relaunched.load();
+ expect(relaunched.value.autoRenameTabs, isTrue);
+
+ await relaunched.reset();
+ expect(storage.values.containsKey('harness_auto_rename_tabs'), isFalse);
+ expect(relaunched.value.autoRenameTabs, isFalse);
+ });
+ });
+
group('copyWith can express "back to the system font"', () {
test('the clear flag unsets, where `?? this.x` cannot', () {
const chosen = AppearancePrefs(uiFamily: 'Menlo', uiSize: 16);
diff --git a/desktop/test/startup_test.dart b/desktop/test/startup_test.dart
index b51b09ceb..3ca32f974 100644
--- a/desktop/test/startup_test.dart
+++ b/desktop/test/startup_test.dart
@@ -181,6 +181,7 @@ void main() {
'harness_custom_background',
'harness_background_behind_harnesses',
'harness_shade_inactive_panes',
+ 'harness_auto_rename_tabs',
'workspace_prompt_v1',
},
]);
diff --git a/desktop/test/workspace_status_test.dart b/desktop/test/workspace_status_test.dart
index 8a5667ab5..a7aaa7be2 100644
--- a/desktop/test/workspace_status_test.dart
+++ b/desktop/test/workspace_status_test.dart
@@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:ui' as ui;
import 'dart:convert';
+import 'package:fake_async/fake_async.dart';
import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
@@ -95,6 +96,26 @@ class _PRConnection extends WsConn {
}
}
+/// A daemon that answers `window_name` from [replies] in order, the last one
+/// for every question after it, and remembers what it was asked.
+class _WindowNameConnection extends _PRConnection {
+ final asked = <List<String>>[];
+ final replies = <Map<String, dynamic>>[];
+ @override
+ Future<Map<String, dynamic>> request(
+ String type, {
+ Map<String, dynamic> payload = const {},
+ Duration timeout = const Duration(seconds: 20),
+ }) async {
+ if (type != 'window_name') {
+ return super.request(type, payload: payload, timeout: timeout);
+ }
+ asked.add([...(payload['agentIds'] as List).cast<String>()]);
+ if (replies.isEmpty) return {'name': null};
+ return replies.length == 1 ? replies.first : replies.removeAt(0);
+ }
+}
+
class _PaneModelConnection extends _PRConnection {
final retargets = <Map<String, dynamic>>[];
@override
@@ -1176,6 +1197,362 @@ void main() {
expect(workspaceTabNames(app).values.single, 'Test host');
});
+ group('Auto rename', () {
+ late AppearancePrefs saved;
+ setUp(() => saved = appearancePrefsStore.value);
+ tearDown(() => appearancePrefsStore.value = saved);
+ void autoRename(bool on) => appearancePrefsStore.value =
+ appearancePrefsStore.value.copyWith(autoRenameTabs: on);
+
+ const repo = AgentProject(
+ name: 'harness',
+ cwd: '/harness',
+ root: '/harness',
+ branch: 'main',
+ );
+ const folder = AgentProject(name: 'notes', cwd: '/notes');
+ Agent agent(
+ String id, {
+ String? name,
+ AgentProject? project = repo,
+ String engine = 'claude',
+ }) => Agent(
+ id: id,
+ name: name ?? 'Work $id',
+ engine: engine,
+ project: project,
+ );
+ TerminalPane pane(int id, String machineId, String agentId) =>
+ TerminalPane(id: id, machineId: machineId, agentId: agentId);
+
+ /// Machine `m` and a second connected machine `b`, each answered by its
+ /// own daemon in [daemons]. Both are local unless [relayed] says `b` is
+ /// reached through the relay.
+ AppNotifier appWith(
+ Map<String, _WindowNameConnection> daemons, {
+ bool relayed = false,
+ }) {
+ final app = createApp(
+ connectionForTest: (id) =>
+ daemons.putIfAbsent(id, _WindowNameConnection.new),
+ connected: true,
+ );
+ const box = Machine(
+ machineId: 'b',
+ authMode: MachineAuthMode.remote,
+ name: 'Box',
+ );
+ app.machines = [...app.machines, box];
+ app.machineStates['m']!.localOnly = true;
+ app.machineStates['b'] = MachineState(box)
+ ..localOnly = !relayed
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agentLoadStatus = AgentLoadStatus.loaded;
+ return app;
+ }
+
+ List<List<String>> asked(
+ Map<String, _WindowNameConnection> daemons,
+ String machineId,
+ ) => daemons[machineId]?.asked ?? const [];
+
+ test('off asks nothing and leaves every label as it was', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [agent('x'), agent('y')];
+ app.activeSwarm.panes.addAll([pane(1, 'm', 'x'), pane(2, 'm', 'y')]);
+ final id = app.activeSwarmId;
+ autoRename(false);
+ expect(workspaceTabNames(app)[id], 'code');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), isEmpty);
+
+ // A daemon with no name for it keeps the label too, and is not asked
+ // again for the same panes.
+ autoRename(true);
+ expect(workspaceTabNames(app)[id], 'code');
+ await pumpEventQueue();
+ expect(workspaceTabNames(app)[id], 'code');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), hasLength(1));
+
+ daemons['m']!.replies.add({'name': 'Harness Tabs'});
+ app.stateOf('m')!.agents = [agent('x', name: 'Fix tabs'), agent('y')];
+ autoRename(false);
+ expect(workspaceTabNames(app)[id], 'code');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), hasLength(1));
+ });
+
+ test('on asks the machine of the repo panes, in pane order, and shows its name', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [
+ agent('t', engine: 'terminal'),
+ agent('x'),
+ agent('y', engine: 'codex'),
+ ];
+ app.stateOf('b')!.agents = [agent('z', project: folder)];
+ app.activeSwarm.panes.addAll([
+ pane(1, 'm', 't'),
+ pane(2, 'b', 'z'),
+ pane(3, 'm', 'x'),
+ TerminalPane(
+ id: 4,
+ machineId: 'm',
+ kind: PaneKind.web,
+ ownerAgentId: 'x',
+ ),
+ pane(5, 'm', 'y'),
+ ]);
+ final id = app.activeSwarmId;
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.add({
+ 'name': 'Harness TUI LMStudio',
+ });
+ autoRename(true);
+ var notified = 0;
+ app.addListener(() => notified++);
+ final today = workspaceTabNames(app)[id];
+ expect(today, isNot('Harness TUI LMStudio'));
+ // Read again before the answer: still one question in flight.
+ expect(workspaceTabNames(app)[id], today);
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), [
+ ['t', 'x', 'y'],
+ ]);
+ expect(asked(daemons, 'b'), isEmpty);
+ expect(notified, greaterThan(0));
+ expect(workspaceTabNames(app)[id], 'Harness TUI LMStudio');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), hasLength(1));
+
+ autoRename(false);
+ expect(workspaceTabNames(app)[id], today);
+ });
+
+ test('a custom name wins and is never asked about', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [agent('x')];
+ app.activeSwarm.panes.add(pane(1, 'm', 'x'));
+ final id = app.activeSwarmId;
+ app.renameSwarm(id, 'My release');
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.add({
+ 'name': 'Harness Tabs',
+ });
+ autoRename(true);
+ expect(workspaceTabNames(app)[id], 'My release');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), isEmpty);
+ expect(workspaceTabNames(app)[id], 'My release');
+ });
+
+ test('pending is asked again once, five seconds later', () {
+ fakeAsync((async) {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ app.stateOf('m')!.agents = [agent('x')];
+ app.activeSwarm.panes.add(pane(1, 'm', 'x'));
+ final id = app.activeSwarmId;
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.addAll([
+ {'name': null, 'pending': true},
+ {'name': 'Mobile Test'},
+ ]);
+ autoRename(true);
+ final today = workspaceTabNames(app)[id];
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(1));
+ for (var i = 0; i < 20; i++) {
+ expect(workspaceTabNames(app)[id], today);
+ async.elapse(const Duration(milliseconds: 200));
+ }
+ expect(asked(daemons, 'm'), hasLength(1));
+ async.elapse(const Duration(seconds: 1));
+ workspaceTabNames(app);
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(2));
+ expect(workspaceTabNames(app)[id], 'Mobile Test');
+ app.dispose();
+ });
+ });
+
+ test('no name is asked about again only after ten minutes', () {
+ fakeAsync((async) {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ app.stateOf('m')!.agents = [agent('x')];
+ app.activeSwarm.panes.add(pane(1, 'm', 'x'));
+ final id = app.activeSwarmId;
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.addAll([
+ {'name': null},
+ {'name': 'Harness Tabs'},
+ ]);
+ autoRename(true);
+ final today = workspaceTabNames(app)[id];
+ async.flushMicrotasks();
+ async.elapse(const Duration(minutes: 9));
+ expect(workspaceTabNames(app)[id], today);
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(1));
+ async.elapse(const Duration(minutes: 1));
+ workspaceTabNames(app);
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(2));
+ expect(workspaceTabNames(app)[id], 'Harness Tabs');
+ app.dispose();
+ });
+ });
+
+ test('an error keeps the label and quiets that machine for a while', () {
+ fakeAsync((async) {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ app.stateOf('m')!.agents = [agent('x'), agent('y')];
+ app.activeSwarm.panes.add(pane(1, 'm', 'x'));
+ app.newSwarm();
+ app.activeSwarm.panes.add(pane(2, 'm', 'y'));
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.add({
+ 'name': null,
+ 'error': 'UNSUPPORTED',
+ });
+ autoRename(false);
+ final today = workspaceTabNames(app);
+ autoRename(true);
+ expect(workspaceTabNames(app), today);
+ async.flushMicrotasks();
+ // Both tabs asked at once; neither, nor anything after, again.
+ expect(asked(daemons, 'm'), hasLength(2));
+ for (var i = 0; i < 30; i++) {
+ expect(workspaceTabNames(app), today);
+ async.elapse(const Duration(seconds: 1));
+ }
+ app.stateOf('m')!.agents = [agent('x', name: 'Fix tabs'), agent('y')];
+ expect(workspaceTabNames(app), today);
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(2));
+
+ async.elapse(const Duration(minutes: 10));
+ workspaceTabNames(app);
+ async.flushMicrotasks();
+ expect(asked(daemons, 'm'), hasLength(4));
+ app.dispose();
+ });
+ });
+
+ test('a pane title change asks again', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [agent('x'), agent('y')];
+ app.activeSwarm.panes.addAll([pane(1, 'm', 'x'), pane(2, 'm', 'y')]);
+ final id = app.activeSwarmId;
+ daemons.putIfAbsent('m', _WindowNameConnection.new).replies.addAll([
+ {'name': 'Harness Tabs'},
+ {'name': 'Harness Rename'},
+ ]);
+ autoRename(true);
+ workspaceTabNames(app);
+ await pumpEventQueue();
+ expect(workspaceTabNames(app)[id], 'Harness Tabs');
+
+ app.stateOf('m')!.agents = [agent('x', name: 'Rename tabs'), agent('y')];
+ // The old name stays while the new question is out.
+ expect(workspaceTabNames(app)[id], 'Harness Tabs');
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), [
+ ['x', 'y'],
+ ['x', 'y'],
+ ]);
+ expect(workspaceTabNames(app)[id], 'Harness Rename');
+ });
+
+ test('the machine with the most repo panes is asked, not the one with the most panes', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [
+ agent('p', project: folder),
+ agent('q', project: null),
+ agent('s', engine: 'terminal'),
+ ];
+ app.stateOf('b')!.agents = [agent('r'), agent('v')];
+ app.activeSwarm.panes.addAll([
+ pane(1, 'm', 'p'),
+ pane(2, 'm', 'q'),
+ pane(3, 'm', 's'),
+ pane(4, 'b', 'r'),
+ ]);
+ // A tie goes to the machine of the first repo pane.
+ app.newSwarm();
+ app.stateOf('m')!.agents = [...app.stateOf('m')!.agents, agent('w')];
+ app.activeSwarm.panes.addAll([pane(5, 'b', 'v'), pane(6, 'm', 'w')]);
+ autoRename(true);
+ workspaceTabNames(app);
+ await pumpEventQueue();
+ expect(asked(daemons, 'b'), [
+ ['r'],
+ ['v'],
+ ]);
+ expect(asked(daemons, 'm'), isEmpty);
+ });
+
+ test(
+ 'a relayed machine is not asked until window_name is sealed',
+ () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons, relayed: true);
+ addTearDown(app.dispose);
+ app.stateOf('b')!.agents = [agent('r')];
+ app.activeSwarm.panes.add(pane(1, 'b', 'r'));
+ final id = app.activeSwarmId;
+ daemons.putIfAbsent('b', _WindowNameConnection.new).replies.add({
+ 'name': 'Harness Tabs',
+ });
+ autoRename(false);
+ final today = workspaceTabNames(app)[id];
+ autoRename(true);
+ expect(workspaceTabNames(app)[id], today);
+ await pumpEventQueue();
+ expect(asked(daemons, 'b'), isEmpty);
+ expect(workspaceTabNames(app)[id], today);
+ },
+ );
+
+ test('a tab with no harness in a repo asks nothing', () async {
+ final daemons = <String, _WindowNameConnection>{};
+ final app = appWith(daemons);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.agents = [
+ agent('p', project: folder),
+ agent('q', project: null),
+ agent('s', engine: 'terminal'),
+ agent(
+ 'u',
+ project: const AgentProject(
+ name: 'harness',
+ cwd: '/harness',
+ branch: '',
+ ),
+ ),
+ ];
+ app.activeSwarm.panes.addAll([
+ for (final (index, id) in ['p', 'q', 's', 'u'].indexed)
+ pane(index + 1, 'm', id),
+ ]);
+ final id = app.activeSwarmId;
+ autoRename(false);
+ final today = workspaceTabNames(app)[id];
+ autoRename(true);
+ expect(workspaceTabNames(app)[id], today);
+ await pumpEventQueue();
+ expect(asked(daemons, 'm'), isEmpty);
+ });
+ });
+
test('status presets retain real metadata and omit missing Git context', () {
const expected = {
StatusLineStyle.standard: 'OpenAI M2:app (main)',