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.

Preserve tab names during desk sync and finalize workspace shortcuts (#420)

Dee1e5c2d6cd8f7
diff --git a/desktop/design/terminal-workspace.md b/desktop/design/terminal-workspace.md
index f4386cbe9..2f76a4b79 100644
--- a/desktop/design/terminal-workspace.md
+++ b/desktop/design/terminal-workspace.md
@@ -31,6 +31,10 @@ User content and embedded viewers retain their own visual language.
## Keyboard is the primary path
Every workspace action needs an existing command or a clear keyboard interaction.
+Cmd-S opens the Store tab, Cmd-M opens Machines (`@`), and Cmd-I opens Models (`:`).
+History remains available from its menu without a default shortcut. Cmd-Y and Cmd-U
+have no default workspace action. On macOS, Minimize remains available from the
+yellow window button and the Window menu; Cmd-M belongs to Machines inside Harness.
Resolve shortcut hints from the live keymap. Cmd-N creates a harness, Cmd-O opens projects (`#`), Cmd-P searches harnesses, and Cmd-Shift-P opens
commands (`>`) in the shared picker. Cmd-I opens models with `:` already entered;
typing Shift is unnecessary. From a live harness pane, Enter uses a served or
diff --git a/desktop/lib/shortcuts/app_shortcuts.dart b/desktop/lib/shortcuts/app_shortcuts.dart
index 59cc48aea..8e5330a67 100644
--- a/desktop/lib/shortcuts/app_shortcuts.dart
+++ b/desktop/lib/shortcuts/app_shortcuts.dart
@@ -5,7 +5,8 @@ import 'package:flutter/widgets.dart';
import '../logging/debug_surface.dart';
/// Harness uses Command as a direct prefix for frequent workspace actions.
-/// T opens a tab, O opens projects, P finds harnesses, Shift-P opens commands, N creates a harness, S opens the Store,
+/// T opens a tab, N creates a harness. S opens Store, M machines, I models,
+/// O projects, P harnesses, and Shift-P commands.
/// Shift-L chooses a layout. H/J/K/L and arrows focus panes; B routes a task.
/// The same definitions feed live keys, help and search.
///
@@ -441,12 +442,6 @@ const kSwarmShortcuts = [
label: 'Open Harness',
group: ShortcutGroup.actions,
),
- AppShortcut(
- action: ShortcutAction.showHistory,
- activator: SingleActivator(LogicalKeyboardKey.keyY, meta: true),
- label: 'Show full history',
- group: ShortcutGroup.navigate,
- ),
AppShortcut(
action: ShortcutAction.newSwarm,
activator: SingleActivator(LogicalKeyboardKey.keyT, meta: true),
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 41e03c6f2..61b7be256 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -11103,6 +11103,13 @@ class AppNotifier extends ChangeNotifier {
}
Future<void> _deskJoin(int authRevision) async {
+ // Edits remain available while the first read is pending. Remember the
+ // existing desk tabs now so its eventual reply cannot undo a rename,
+ // close, or move made during that wait. New/local tabs are seeded below.
+ final beforeRead = _deskProjection()
+ .where((tab) => isDeskId(tab.id))
+ .toList();
+ final beforeReadIds = beforeRead.map((tab) => tab.id).toSet();
Map<String, dynamic>? raw;
try {
raw = await api.desk();
@@ -11131,6 +11138,10 @@ class AppNotifier extends ChangeNotifier {
}
}
final own = _deskProjection();
+ final duringRead = deskDiff(
+ beforeRead,
+ own.where((tab) => beforeReadIds.contains(tab.id)).toList(),
+ );
final unknown = own
.where((t) => !doc.tabs.any((d) => d.id == t.id))
.toList();
@@ -11145,6 +11156,7 @@ class AppNotifier extends ChangeNotifier {
'tabs': [for (final t in unknown) t.toJson()],
});
}
+ _desk.pending.addAll(duringRead);
appLog.info(
'desk',
'joined at rev ${doc.revision} · ${doc.tabs.length} on the desk · ${unknown.length} of ours to seed',
diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swift
index 41baff25a..0684863cd 100644
--- a/desktop/macos/Runner/SwarmTitlebar.swift
+++ b/desktop/macos/Runner/SwarmTitlebar.swift
@@ -391,7 +391,7 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {
historyMenu.addItem(.separator())
appendHistorySection("Recently Visited", entries: visited, closed: false, trailingEdge: trailingEdge)
historyMenu.addItem(.separator())
- command("Show Full History", "y", "showHistory")
+ command("Show Full History", "", "showHistory")
if let keymap { keymap.applyMenuKeys(to: historyMenu, context: flutterKeyContext) }
let rowWidth = ceil(historyMenu.size.width * 1.2)
historyMenu.minimumWidth = rowWidth
diff --git a/desktop/test/desk_sync_test.dart b/desktop/test/desk_sync_test.dart
index 3cea574c0..269e57e92 100644
--- a/desktop/test/desk_sync_test.dart
+++ b/desktop/test/desk_sync_test.dart
@@ -1,6 +1,7 @@
// The desk: the account's tabs, the same on every computer. The pure half
// (diff and replay) and the window's half (a document becomes `swarms`, an
// edit becomes ops, and what a window keeps for itself stays put).
+import 'dart:async';
import 'dart:ui' show Rect;
import 'package:flutter_test/flutter_test.dart';
@@ -36,6 +37,7 @@ class _DeskApi extends ApiClient {
DeskDoc? doc = const DeskDoc(revision: 0, tabs: []);
bool available = true;
Object? failWith;
+ Completer<void>? readGate;
final batches = <List<Map<String, dynamic>>>[];
Map<String, dynamic>? _json(DeskDoc d) => {
@@ -47,7 +49,9 @@ class _DeskApi extends ApiClient {
Future<Map<String, dynamic>?> desk() async {
if (failWith != null) throw failWith!;
if (!available || doc == null) return null;
- return _json(doc!);
+ final snapshot = _json(doc!);
+ if (readGate case final gate?) await gate.future;
+ return snapshot;
}
@override
@@ -392,6 +396,127 @@ void main() {
},
);
+ test('a pending desk join preserves a rename and neighboring tab closure', () async {
+ final officeId = newDeskId(), termId = newDeskId();
+ final office = Swarm(id: officeId, name: 'term');
+ final term = Swarm(id: termId, name: 'term');
+ final api = _DeskApi()
+ ..doc = DeskDoc(
+ revision: 1,
+ tabs: [
+ tab(termId, name: 'term', custom: true),
+ tab(officeId, name: 'term', custom: true),
+ ],
+ )
+ ..readGate = Completer<void>();
+ final app = createApp()..api = api;
+ addTearDown(app.dispose);
+ app.swarms
+ ..clear()
+ ..addAll([term, office]);
+ app.selectSwarm(termId);
+ final joining = app.deskStartForTest();
+
+ app.renameSwarm(officeId, 'office');
+ await app.closeSwarm(termId);
+ expect(app.activeSwarm, same(office));
+ expect(office.name, 'office');
+
+ api.readGate!.complete();
+ await joining;
+ expect(office.name, 'office');
+ expect(app.swarms, [office]);
+ expect(api.doc!.tabs.single.id, officeId);
+ expect(api.doc!.tabs.single.name, 'office');
+ expect(api.doc!.tabs.single.nameIsCustom, isTrue);
+ expect(app.deskSyncForTest.pending, isEmpty);
+ });
+
+ test('a pending join keeps remote renames and seeds new tabs with local edits', () async {
+ final officeId = newDeskId(), termId = newDeskId();
+ final office = Swarm(id: officeId, name: 'term');
+ final term = Swarm(id: termId, name: 'term');
+ final api = _DeskApi()
+ ..doc = DeskDoc(
+ revision: 2,
+ tabs: [
+ tab(termId, name: 'term', custom: true),
+ tab(officeId, name: 'office', custom: true),
+ ],
+ )
+ ..readGate = Completer<void>();
+ final app = createApp()..api = api;
+ addTearDown(app.dispose);
+ app.swarms
+ ..clear()
+ ..addAll([term, office]);
+ app.selectSwarm(termId);
+ final joining = app.deskStartForTest();
+
+ await app.closeSwarm(termId);
+ app.newSwarm(name: 'scratch');
+ final scratch = app.activeSwarm;
+ api.readGate!.complete();
+ await joining;
+
+ expect(office.name, 'office');
+ expect(app.swarms, [office, scratch]);
+ expect(app.activeSwarm, same(scratch));
+ expect(isDeskId(scratch.id), isTrue);
+ expect(api.doc!.tabs.map((tab) => tab.name), ['office', 'scratch']);
+ expect(
+ api.batches
+ .expand((batch) => batch)
+ .where((op) => op['op'] == 'tab.rename'),
+ isEmpty,
+ reason: 'An unchanged local name must not undo a rename on another machine',
+ );
+ });
+
+ test('closing term preserves office through an older desk reply and retry', () async {
+ final officeId = newDeskId(), termId = newDeskId();
+ final api = _DeskApi()
+ ..doc = DeskDoc(
+ revision: 1,
+ tabs: [
+ tab(termId, name: 'term', custom: true, agents: ['a2']),
+ tab(officeId, name: 'office', custom: true, agents: ['a0', 'a1']),
+ ],
+ );
+ final app = createApp()..api = api;
+ addTearDown(app.dispose);
+ await app.deskStartForTest();
+ final office = app.swarms.singleWhere((tab) => tab.id == officeId);
+ final panes = office.panes.toList();
+ app.selectSwarm(termId);
+ api.batches.clear();
+ api.failWith = StateError('offline');
+ await app.closeSwarm(termId);
+ await Future<void>.delayed(Duration.zero);
+ expect(app.activeSwarm, same(office));
+
+ api.failWith = null;
+ await app.deskFetchForTest();
+ expect(app.swarms.any((tab) => tab.id == termId), isFalse);
+ expect(office.name, 'office');
+ expect(office.nameIsCustom, isTrue);
+ expect(office.panes, orderedEquals(panes));
+ expect(app.deskSyncForTest.pending, [
+ {'op': 'tab.close', 'id': termId},
+ ]);
+
+ await app.deskFlushForTest();
+ expect(app.deskSyncForTest.pending, isEmpty);
+ expect(office.name, 'office');
+ expect(
+ api.doc!.tabs.singleWhere((tab) => tab.id == officeId).name,
+ 'office',
+ );
+ expect(api.batches.expand((batch) => batch), [
+ {'op': 'tab.close', 'id': termId},
+ ]);
+ });
+
test('a desk_changed push closes a tab closed elsewhere and opens one opened elsewhere, keeping this window\'s focus', () async {
final api = _DeskApi()
..doc = DeskDoc(
diff --git a/desktop/test/keymap_host_test.dart b/desktop/test/keymap_host_test.dart
index 99f033398..b89efb392 100644
--- a/desktop/test/keymap_host_test.dart
+++ b/desktop/test/keymap_host_test.dart
@@ -119,7 +119,7 @@ void main() {
final id = command(stroke.toString());
expect(harnessCommandById[id]?.action, shortcut.action);
}
- for (final retired in ['cmd+shift+h', 'cmd+shift+k', 'cmd+u']) {
+ for (final retired in ['cmd+shift+h', 'cmd+shift+k', 'cmd+u', 'cmd+y']) {
expect(command(retired), isNull, reason: retired);
}
expect(command('cmd+alt+left'), isNull);
diff --git a/desktop/test/swarm_interactions_test.dart b/desktop/test/swarm_interactions_test.dart
index 88b201956..8034c8844 100644
--- a/desktop/test/swarm_interactions_test.dart
+++ b/desktop/test/swarm_interactions_test.dart
@@ -176,6 +176,66 @@ void main() {
);
}
+ for (final native in [false, true]) {
+ testWidgets(
+ 'Cmd-W preserves term renamed to office beside another term (native=$native)',
+ (tester) async {
+ const channel = MethodChannel('harness/swarm_tabs');
+ final updates = <Map>[];
+ final messenger = tester.binding.defaultBinaryMessenger;
+ messenger.setMockMethodCallHandler(channel, (call) async {
+ if (call.method == 'update') updates.add(call.arguments as Map);
+ return true;
+ });
+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
+ final app = createApp();
+ addTearDown(app.dispose);
+ final projects = SwarmProjectStore(storage: MemoryStore());
+ addTearDown(projects.dispose);
+ final input = <TerminalBinaryFrame>[];
+ final session = terminal('a0', input);
+ app.machineStates['m']!.nodeOnline = true;
+ final pane = app.adoptSessionForTest(session);
+ final office = app.activeSwarm;
+ app.renameSwarm(office.id, 'term');
+ app.newSwarm(name: 'term');
+ final term = app.activeSwarm;
+ app.adoptSessionForTest(terminal('a1', input));
+ app.selectSwarm(office.id);
+ await mount(tester, app, projects: projects, nativeTabs: native);
+
+ await chord(tester, LogicalKeyboardKey.keyR, shift: true);
+ await tester.enterText(
+ find.byKey(const Key('tab-rename-input')),
+ 'office',
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(office.name, 'office');
+ expect(office.nameIsCustom, isTrue);
+
+ app.selectSwarm(term.id);
+ await tester.pump();
+ await chord(tester, LogicalKeyboardKey.keyW);
+ expect(app.swarms, [office]);
+ expect(app.activeSwarm, same(office));
+ expect(office.name, 'office');
+ expect(office.panes.single, same(pane));
+ expect(pane.session, same(session));
+ expect(input, isEmpty);
+ if (native) {
+ final tab = (updates.last['tabs'] as List).single as Map;
+ expect(tab['id'], office.id);
+ expect(tab['label'], '1:office');
+ } else {
+ expect(find.text('1:office'), findsOneWidget);
+ }
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox());
+ },
+ );
+ }
+
testWidgets(
'welcome opens the shared search and supports readline selection',
(tester) async {
diff --git a/desktop/test/workspace_status_test.dart b/desktop/test/workspace_status_test.dart
index 7761de465..07c4212ca 100644
--- a/desktop/test/workspace_status_test.dart
+++ b/desktop/test/workspace_status_test.dart
@@ -619,6 +619,59 @@ void main() {
},
);
+ for (final custom in [false, true]) {
+ test(
+ 'closing term keeps the revealed office tab name (custom=$custom)',
+ () async {
+ final storage = MemoryStore();
+ final app = createApp(store: storage);
+ addTearDown(app.dispose);
+ final machine = app.stateOf('m')!;
+ machine.agents = const [
+ Agent(id: 'a0', name: 'Code', engine: 'codex'),
+ Agent(id: 'a1', name: 'Terminal', engine: 'terminal'),
+ Agent(id: 'a2', name: 'Other terminal', engine: 'terminal'),
+ ];
+ app.renameSwarm(app.activeSwarmId, 'growth');
+ app.newSwarm(name: 'term');
+ final term = app.activeSwarm;
+ await app.addAgentToSwarm('m', 'a2');
+ app.newSwarm();
+ final office = app.activeSwarm;
+ await app.addAgentToSwarm('m', 'a0');
+ await app.addAgentToSwarm('m', 'a1');
+ if (custom) app.renameSwarm(office.id, 'office');
+ final expected = custom ? 'office' : 'Test host';
+ final panes = office.panes.toList();
+ expect(workspaceTabNames(app)[office.id], expected);
+
+ app.selectSwarm(term.id);
+ await app.closeSwarm(term.id);
+ expect(app.activeSwarm, same(office));
+ expect(workspaceTabNames(app)[office.id], expected);
+ expect(office.panes, orderedEquals(panes));
+ expect(office.nameIsCustom, custom);
+
+ app.reopenClosedSwarm();
+ expect(workspaceTabNames(app)[term.id], 'term');
+ expect(workspaceTabNames(app)[office.id], expected);
+ await app.closeSwarm(term.id);
+ await app.flushPaneLayout();
+
+ final restored = createApp(store: storage);
+ addTearDown(restored.dispose);
+ restored.stateOf('m')!.agents = machine.agents;
+ await restored.restorePaneLayoutForTest();
+ expect(workspaceTabNames(restored)[office.id], expected);
+ expect(restored.swarms.any((tab) => tab.id == term.id), isFalse);
+ expect(
+ restored.swarms.singleWhere((tab) => tab.id == office.id).nameIsCustom,
+ custom,
+ );
+ },
+ );
+ }
+
test('project names distinguish code tabs while a distinct harness keeps its type', () {
final app = createApp();
addTearDown(app.dispose);
diff --git a/desktop/tool/history_menu_checks.swift b/desktop/tool/history_menu_checks.swift
index bc426f0a8..f4baefe61 100644
--- a/desktop/tool/history_menu_checks.swift
+++ b/desktop/tool/history_menu_checks.swift
@@ -51,8 +51,8 @@ private extension SwarmTitlebar {
updateHistory(recent, closed: closed)
try checkHistory(historyMenu.items[0] === back && historyMenu.items[1] === forward && historyMenu.items.last === full,
"Closed updates retain installed command items")
- try checkHistory(back.keyEquivalent == "[" && forward.keyEquivalent == "]" && full.keyEquivalent == "y",
- "Navigation and full-history shortcuts remain installed while closed")
+ try checkHistory(back.keyEquivalent == "[" && forward.keyEquivalent == "]" && full.keyEquivalent.isEmpty,
+ "Back and forward retain their shortcuts; full history has no default shortcut")
try checkHistory(validateMenuItem(back) && !validateMenuItem(forward) && validateMenuItem(reopen),
"Command availability updates independently of row construction")
try checkHistory(historyMenu.items.allSatisfy { $0.action != #selector(historyAction(_:)) },
diff --git a/desktop/tool/keymap_native_checks.swift b/desktop/tool/keymap_native_checks.swift
index e56c6592c..40d72e911 100644
--- a/desktop/tool/keymap_native_checks.swift
+++ b/desktop/tool/keymap_native_checks.swift
@@ -54,7 +54,12 @@ for context in HarnessNativeKeymap.contexts {
try checkKeymap(directModels == nil,
"Command-semicolon is unbound from \(context)")
try checkKeymap(defaults.match([stroke("cmd+u")], context: context).binding == nil,
- "The former Machines shortcut is unbound")
+ "Command-U has no default workspace action")
+ try checkKeymap(defaults.match([stroke("cmd+y")], context: context).binding == nil,
+ "Command-Y has no default workspace action")
+ let store = defaults.match([stroke("cmd+s")], context: context).binding
+ try checkKeymap(store?.command == "app.store" && store?.menuAction == "store" && store?.hint == "⌘S",
+ "Command-S opens Store with the matching native action and hint")
try checkKeymap(defaults.match([stroke("cmd+o")], context: context).binding?.command == "agent.open",
"Command-O opens the project picker")
try checkKeymap(defaults.match([stroke("cmd+shift+n")], context: context).binding?.command == "agent.clone",
diff --git a/desktop/tool/swarm_titlebar_checks.swift b/desktop/tool/swarm_titlebar_checks.swift
index 3a2e463b7..44764fbb5 100644
--- a/desktop/tool/swarm_titlebar_checks.swift
+++ b/desktop/tool/swarm_titlebar_checks.swift
@@ -1224,7 +1224,7 @@ private extension SwarmTitlebar {
try checkTitlebar(strip.newButton.accessibilityLabel() == "New Tab", "The plus announces New Tab")
try checkTitlebar(main.defersToInput(event("n", 45, .command)) && main.defersToInput(event("t", 17, .command)),
"Command-N and Command-T reach creation and New Tab")
- try checkTitlebar(main.defersToInput(event("p", 35, .command)), "Command-P reaches Open Harness")
+ try checkTitlebar(main.defersToInput(event("p", 35, .command)), "Command-P reaches Harnesses")
try checkTitlebar(main.defersToInput(event("p", 35, [.command, .shift])), "Command-Shift-P reaches commands")
try checkTitlebar(main.defersToInput(event("o", 31, .command)), "Command-O reaches the project picker")
try checkTitlebar(!main.defersToInput(event(";", 41, .command)) &&
@@ -1235,8 +1235,12 @@ private extension SwarmTitlebar {
"Command-I reaches Flutter exactly once")
try checkTitlebar(main.defersToInput(event("m", 46, .command)) &&
!main.performKeyEquivalent(with: event("m", 46, .command)),
- "Command-M reaches Flutter exactly once instead of invoking a native window action")
- try checkTitlebar(!main.defersToInput(event("u", 32, .command)), "Command-U is no longer claimed")
+ "Command-M reaches Machines exactly once instead of invoking a native window action")
+ try checkTitlebar(main.defersToInput(event("s", 1, .command)) &&
+ !main.performKeyEquivalent(with: event("s", 1, .command)),
+ "Command-S reaches Store exactly once")
+ try checkTitlebar(!main.defersToInput(event("u", 32, .command)), "Command-U has no default workspace action")
+ try checkTitlebar(!main.defersToInput(event("y", 16, .command)), "Command-Y has no default workspace action")
flutterKeyContext = "picker"
syncMenuKeys()
try checkTitlebar(!main.performKeyEquivalent(with: event("\u{f701}", 125)), "Result arrows are owned by the shared picker")
@@ -1258,7 +1262,7 @@ private extension SwarmTitlebar {
}
actionsEnabled = true
// Orchestrator has no default chord now. Exercise an explicit user binding;
- // Cmd-O opens projects; Cmd-P opens search through the exported default keymap.
+ // Cmd-O opens projects; Cmd-Shift-P opens commands through the exported default keymap.
let viewerMap = HarnessNativeKeymap(["version": 1, "contexts": [
"workspace": [["keys": ["cmd+y"], "command": "project.orchestrate", "hint": "⌘Y", "repeatable": false]],
"terminal": [], "picker": [], "project": [],
@@ -1471,7 +1475,7 @@ private extension SwarmTitlebar {
let closedItems = historyMenu.items.filter { $0.action == #selector(closedHistoryAction(_:)) }
try checkTitlebar(recentItems.count == 15 && closedItems.count == 10, "Chrome-style direct History sections remain bounded")
try checkTitlebar(historyMenu.items.filter { !$0.isSeparatorItem }.prefix(2).map(\.title) == ["Back", "Forward"], "History begins with Back and Forward")
- try checkTitlebar(historyMenu.items.last?.title == "Show Full History" && historyMenu.items.last?.keyEquivalent == "y", "Full History uses Command-Y")
+ try checkTitlebar(historyMenu.items.last?.title == "Show Full History" && historyMenu.items.last?.keyEquivalent.isEmpty == true, "Full History remains available without a default shortcut")
try checkTitlebar(historyMenu.items.allSatisfy { $0.submenu == nil }, "Recent work is available without nested menus")
let recent = recentItems[0]
let closed = closedItems[0]