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: enhance web interface for mobile and desktop

Dev jacob051edd7d9e19
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.md
index 97b442146..d797d8110 100644
--- a/desktop/CLAUDE.md
+++ b/desktop/CLAUDE.md
@@ -103,7 +103,10 @@ advertised. Browser-only UI lives in `lib/web/` and is never imported by desktop
it plugs into shared screens through additive seams whose default is today's desktop
behavior (e.g. `SwarmScreen.chrome` / `WorkspaceChrome` in `state/workspace_chrome.dart`,
which runs the same `_commands` table keys use, adds a bar over the picker, and turns off
-`KeyHints` — `widgets/key_hints.dart`, absent means hints shown). Do not change desktop behavior for the
+`KeyHints` — `widgets/key_hints.dart`, absent means hints shown). Below
+`WorkspaceChrome.compactBelow` (web: 720px, a phone) the workspace goes compact: a tab
+switcher replaces the tab row and `PaneGrid.soloFocused` draws only the focused harness —
+without touching zoom or the synced layout, so the same desk keeps its grid on a computer. Do not change desktop behavior for the
web, and do not copy shared screens into `lib/web/` — add a seam instead.
`kViewerMode` is true on the web:
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 26ce8e409..9386da288 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -6080,6 +6080,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
child: PaneGrid(
notifier: app,
swarmMode: true,
+ soloFocused: _compact(context),
empty:
app.panes.isEmpty &&
!app.activeSwarm.isStore &&
@@ -6407,7 +6408,8 @@ class _SwarmScreenState extends State<SwarmScreen> {
final shareWidth = _showShareButton
? math.min(WorkspaceShareButton.widthOf(context), available * .3)
: 0.0;
- final downloadWidth = kIsWeb ? available * .16 : 0.0;
+ final download = kIsWeb && !_compact(context);
+ final downloadWidth = download ? available * .16 : 0.0;
final modelWidth =
math.max(
0.0,
@@ -6473,7 +6475,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
)
: paneContext,
),
- if (kIsWeb) ...[
+ if (download) ...[
SizedBox(width: cell.width),
ConstrainedBox(
constraints: BoxConstraints(maxWidth: downloadWidth),
@@ -6526,6 +6528,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
grid.AppTheme.palette.value,
terminalThemeStore.value,
);
+ final chrome = widget.chrome;
+ if (chrome != null && _compact(context)) {
+ return _compactTabStrip(chrome, theme);
+ }
final names = workspaceTabNames(app);
final activities = [for (final tab in app.swarms) tabActivity(app, tab)];
final labels = [
@@ -6538,7 +6544,6 @@ class _SwarmScreenState extends State<SwarmScreen> {
WorkspaceStoreButton.widthOf(context),
math.max(0.0, constraints.maxWidth - cell.width * 14),
);
- final chrome = widget.chrome;
final leadingWidth = chrome?.leadingWidth(context) ?? 0.0;
final tabBudget = math.max(
0.0,
@@ -6737,34 +6742,8 @@ class _SwarmScreenState extends State<SwarmScreen> {
tooltip: 'New Swarm ${_keymap.hint('swarm.new') ?? ''}',
),
const Spacer(),
- WorkspaceBarControl(
- key: const ValueKey('swarm-search-button'),
- label: 'Search harnesses',
- tooltip:
- 'Search harnesses ${_keymap.hint('harnesses.list') ?? ''}',
- onPressed: _shortcutsEnabled ? _toggleSessions : null,
- builder: (context, emphasized) => SizedBox(
- width: cell.width * 4,
- height: toolHeight,
- child: Icon(
- LucideIcons.search,
- size: 17,
- color: theme.foreground.withValues(
- alpha: !_shortcutsEnabled
- ? .28
- : emphasized
- ? 1
- : .75,
- ),
- ),
- ),
- ),
- WorkspaceNotificationsButton(
- key: const ValueKey('workspace-notifications-button'),
- count: _unread,
- foreground: theme.foreground,
- onPressed: _shortcutsEnabled ? _showNotificationInbox : null,
- ),
+ _searchButton(theme),
+ _notificationsButton(theme),
WorkspaceStoreButton(
key: const ValueKey('swarm-store-button'),
width: storeWidth,
@@ -6779,6 +6758,75 @@ class _SwarmScreenState extends State<SwarmScreen> {
},
);
+ /// A host's narrow layout (the web on a phone): one harness at a time, a tab
+ /// switcher, a quieter status bar. Never true without a host that asks.
+ bool _compact(BuildContext context) {
+ final chrome = widget.chrome;
+ return chrome?.compactTabs != null &&
+ MediaQuery.sizeOf(context).width < chrome!.compactBelow;
+ }
+
+ Widget _searchButton(TerminalTheme theme) => WorkspaceBarControl(
+ key: const ValueKey('swarm-search-button'),
+ label: 'Search harnesses',
+ tooltip: 'Search harnesses ${_keymap.hint('harnesses.list') ?? ''}',
+ onPressed: _shortcutsEnabled ? _toggleSessions : null,
+ builder: (context, emphasized) => SizedBox(
+ width: workspaceBarCellSizeOf(context).width * 4,
+ height: workspaceBarControlHeight(context),
+ child: Icon(
+ LucideIcons.search,
+ size: 17,
+ color: theme.foreground.withValues(
+ alpha: !_shortcutsEnabled
+ ? .28
+ : emphasized
+ ? 1
+ : .75,
+ ),
+ ),
+ ),
+ );
+
+ Widget _notificationsButton(TerminalTheme theme) =>
+ WorkspaceNotificationsButton(
+ key: const ValueKey('workspace-notifications-button'),
+ count: _unread,
+ foreground: theme.foreground,
+ onPressed: _shortcutsEnabled ? _showNotificationInbox : null,
+ );
+
+ /// A host's narrow bar (the web on a phone): its tab switcher in place of
+ /// the tab list, and no Store button, which the host's menu already offers.
+ Widget _compactTabStrip(WorkspaceChrome chrome, TerminalTheme theme) =>
+ Builder(
+ builder: (context) {
+ final cell = workspaceBarCellSizeOf(context);
+ return Material(
+ key: const ValueKey('workspace-tab-bar'),
+ color: grid.AppPalette.swarmTabBar,
+ child: SizedBox(
+ height: math.max(_tabBarHeight, cell.height * 2),
+ child: Row(
+ children: [
+ SizedBox(width: cell.width),
+ SizedBox(
+ width: chrome.leadingWidth(context),
+ child: chrome.leading(context, _workspaceCommands),
+ ),
+ Expanded(
+ child: chrome.compactTabs!(context, _workspaceCommands),
+ ),
+ _searchButton(theme),
+ _notificationsButton(theme),
+ SizedBox(width: cell.width),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+
Widget _statusToolSymbol(
String id,
String label,
diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dart
index 6bc587816..11bba85d0 100644
--- a/desktop/lib/state/workspace_chrome.dart
+++ b/desktop/lib/state/workspace_chrome.dart
@@ -44,6 +44,8 @@ class WorkspaceChrome {
this.newHarnessMachine,
this.pickerBar,
this.showsKeyHints = true,
+ this.compactTabs,
+ this.compactBelow = 0,
});
final double Function(BuildContext context) leadingWidth;
@@ -60,4 +62,11 @@ class WorkspaceChrome {
/// False hides keyboard hints inside the workspace's pickers ([KeyHints]).
final bool showsKeyHints;
+
+ /// Below [compactBelow] of window width the workspace goes compact: this
+ /// replaces the tab list (the Store button steps aside), and only the focused
+ /// harness is drawn — a phone has room for neither a tab row nor a grid.
+ final Widget Function(BuildContext context, WorkspaceCommands commands)?
+ compactTabs;
+ final double compactBelow;
}
diff --git a/desktop/lib/web/shell/web_app_menu.dart b/desktop/lib/web/shell/web_app_menu.dart
index 8ee6e5c44..ef0aa2d0a 100644
--- a/desktop/lib/web/shell/web_app_menu.dart
+++ b/desktop/lib/web/shell/web_app_menu.dart
@@ -8,9 +8,11 @@ import '../../shared/theme/workspace_bar_style.dart';
import '../../state/app_state.dart';
import '../../state/workspace_chrome.dart';
import '../../terminal/terminal_theme.dart';
+import '../../theme/app_theme.dart' show AppColors;
import '../../terminal/terminal_theme_store.dart';
import '../../widgets/pane_menu.dart';
import '../../widgets/workspace_bar_control.dart';
+import 'web_layout.dart';
import 'web_menu_items.dart';
/// The browser has no native menu bar, so everything desktop keeps there is
@@ -65,7 +67,10 @@ class WebAppMenuButton extends StatelessWidget {
if (box == null || overlay == null) return;
final origin = box.localToGlobal(Offset.zero, ancestor: overlay);
// Resolved as it opens, so the rows match the workspace's state right now.
- final sections = runnableWebMenu(commands.canRun);
+ final groups = runnableWebMenu(
+ commands.canRun,
+ compact: isWebCompact(context),
+ );
final chosen = await showPaneMenu<String>(
context: context,
position: RelativeRect.fromLTRB(
@@ -76,7 +81,7 @@ class WebAppMenuButton extends StatelessWidget {
),
minWidth: 240,
maxWidth: 320,
- children: (close) => _rows(sections, close),
+ children: (close) => _rows(groups, close),
);
// Run after the menu closed and handed focus back, never inside it.
if (chosen == _signOut) {
@@ -89,7 +94,7 @@ class WebAppMenuButton extends StatelessWidget {
static const _signOut = 'web.sign_out';
List<Widget> _rows(
- List<WebMenuSection> sections,
+ List<List<WebMenuItem>> groups,
void Function(String?) close,
) {
Widget row(String id, String label) => paneMenuItem(
@@ -100,12 +105,19 @@ class WebAppMenuButton extends StatelessWidget {
title: label,
),
);
+ final rule = Divider(
+ height: 9,
+ thickness: 1,
+ indent: 14,
+ endIndent: 14,
+ color: AppColors.border,
+ );
return [
- for (final section in sections) ...[
- paneMenuHeader(section.title),
- for (final item in section.items) row(item.command, item.label),
+ for (final group in groups) ...[
+ for (final item in group) row(item.command, item.label),
+ rule,
],
- paneMenuHeader('Account', caption: app.currentUser?.email),
+ if (app.currentUser?.email case final email?) paneMenuEmpty(email),
row(_signOut, 'Sign out'),
];
}
diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dart
index 91904fb50..3f7fc9bdd 100644
--- a/desktop/lib/web/shell/web_chrome.dart
+++ b/desktop/lib/web/shell/web_chrome.dart
@@ -1,12 +1,15 @@
import '../../state/app_state.dart';
import '../../state/workspace_chrome.dart';
import '../picker/web_picker_bar.dart';
+import '../tabs/web_tab_switcher.dart';
import 'web_app_menu.dart';
+import 'web_layout.dart';
import 'web_machine_choice.dart';
/// Everything the browser adds to the shared workspace: a menu before the
-/// tabs, a clickable bar over the picker with its key hints hidden, and a
-/// connected machine for New Harness, since a browser is not a machine.
+/// tabs, a tab switcher on narrow screens, a clickable bar over the picker
+/// with its key hints hidden, and a connected machine for New Harness, since
+/// a browser is not a machine.
WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
leadingWidth: WebAppMenuButton.widthOf,
leading: (context, commands) =>
@@ -14,4 +17,7 @@ WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
newHarnessMachine: () => webNewHarnessMachine(app),
pickerBar: (context, picker) => WebPickerBar(picker: picker),
showsKeyHints: false,
+ compactTabs: (context, commands) =>
+ WebTabSwitcher(app: app, commands: commands),
+ compactBelow: kWebCompactBelow,
);
diff --git a/desktop/lib/web/shell/web_layout.dart b/desktop/lib/web/shell/web_layout.dart
new file mode 100644
index 000000000..03bc5d59e
--- /dev/null
+++ b/desktop/lib/web/shell/web_layout.dart
@@ -0,0 +1,10 @@
+import 'package:flutter/widgets.dart';
+
+/// Narrower than this a browser is laid out for a phone: a tab switcher for
+/// the tab row, one harness at a time for the grid. Covers a phone in either
+/// orientation, or a slim window beside another.
+const double kWebCompactBelow = 720;
+
+/// Whether this browser window gets the phone layout.
+bool isWebCompact(BuildContext context) =>
+ MediaQuery.sizeOf(context).width < kWebCompactBelow;
diff --git a/desktop/lib/web/shell/web_menu_items.dart b/desktop/lib/web/shell/web_menu_items.dart
index 01f4a4b9c..54df491ef 100644
--- a/desktop/lib/web/shell/web_menu_items.dart
+++ b/desktop/lib/web/shell/web_menu_items.dart
@@ -1,61 +1,59 @@
+/// Which layouts a menu row belongs to: some rows repeat a control the wide
+/// bar already shows, others make no sense on a phone.
+enum WebMenuWidth { any, compact, wide }
+
/// One entry of the web app menu: a workspace command id and its menu label.
/// The command itself lives in the workspace's shared command table.
-typedef WebMenuItem = ({String command, String label});
-
-/// A titled group of menu entries.
-typedef WebMenuSection = ({String title, List<WebMenuItem> items});
+typedef WebMenuItem = ({String command, String label, WebMenuWidth width});
-/// What desktop reaches through its native menu bar, for a mouse in a browser.
-/// Order follows the native menus: create, open, arrange, then the app itself.
-const List<WebMenuSection> kWebMenuSections = [
- (
- title: 'Harness',
- items: [
- (command: 'agent.new', label: 'New harness'),
- (command: 'swarm.new', label: 'New tab'),
- (command: 'harnesses.list', label: 'Agents'),
- (command: 'navigation.needs_input', label: 'Needing input'),
- (command: 'machines.list', label: 'Machines'),
- (command: 'models.list', label: 'Models'),
- (command: 'app.store', label: 'Store'),
- ],
- ),
- (
- title: 'Pane',
- items: [
- (command: 'pane.split_right', label: 'Split right'),
- (command: 'pane.split_down', label: 'Split down'),
- (command: 'pane.zoom', label: 'Zoom pane'),
- (command: 'pane.move_to_tab', label: 'Move pane to tab'),
- (command: 'agent.share', label: 'Share harness'),
- (command: 'pane.close', label: 'Close pane'),
- ],
- ),
- (
- title: 'Workspace',
- items: [
- (command: 'pane.layout', label: 'Layout'),
- (command: 'navigation.history', label: 'History'),
- (command: 'navigation.commands', label: 'All commands'),
- ],
- ),
- (
- title: 'App',
- items: [
- (command: 'app.settings', label: 'Settings'),
- (command: 'app.customize', label: 'Customize'),
- (command: 'app.add_phone', label: 'Add phone'),
- (command: 'keyboard.quick_start', label: 'Quick start'),
- (command: 'keyboard.help', label: 'Keyboard shortcuts'),
- ],
- ),
+/// What the menu offers, in groups a thin rule separates. Only what has no
+/// other door in the browser chrome: new work is the `+` beside the tabs
+/// (a new tab opens on "Start an agent"), agents the search button, tabs the
+/// tab bar and switcher, attention the bell; keyboard tours and grid layout
+/// stay out of a mouse-first menu. All commands still reaches every one.
+const List<List<WebMenuItem>> kWebMenuGroups = [
+ [
+ (command: 'machines.list', label: 'Machines', width: WebMenuWidth.any),
+ (command: 'models.list', label: 'Models', width: WebMenuWidth.any),
+ // The wide bar has its own Store button; the phone bar gives it up.
+ (command: 'app.store', label: 'Store', width: WebMenuWidth.compact),
+ ],
+ [
+ (command: 'agent.share', label: 'Share harness', width: WebMenuWidth.any),
+ (command: 'pane.close', label: 'Close pane', width: WebMenuWidth.any),
+ ],
+ [
+ (command: 'navigation.history', label: 'History', width: WebMenuWidth.any),
+ (
+ command: 'navigation.commands',
+ label: 'All commands',
+ width: WebMenuWidth.any,
+ ),
+ ],
+ [
+ (command: 'app.settings', label: 'Settings', width: WebMenuWidth.any),
+ (command: 'app.customize', label: 'Customize', width: WebMenuWidth.any),
+ // Pairing a phone is for a computer; a phone is already here.
+ (command: 'app.add_phone', label: 'Add phone', width: WebMenuWidth.wide),
+ ],
];
-/// The sections as they can be drawn right now: commands that cannot run in
-/// this workspace state are left out, and a section left empty goes with them.
-List<WebMenuSection> runnableWebMenu(bool Function(String command) canRun) => [
- for (final section in kWebMenuSections)
- if (section.items.where((item) => canRun(item.command)).toList()
+/// The groups as they can be drawn right now: rows for the other layout, and
+/// commands that cannot run in this workspace state, are left out, and a group
+/// left empty goes with them.
+List<List<WebMenuItem>> runnableWebMenu(
+ bool Function(String command) canRun, {
+ required bool compact,
+}) => [
+ for (final group in kWebMenuGroups)
+ if (group
+ .where(
+ (item) =>
+ item.width !=
+ (compact ? WebMenuWidth.wide : WebMenuWidth.compact) &&
+ canRun(item.command),
+ )
+ .toList()
case final items when items.isNotEmpty)
- (title: section.title, items: items),
+ items,
];
diff --git a/desktop/lib/web/tabs/web_tab_menu.dart b/desktop/lib/web/tabs/web_tab_menu.dart
new file mode 100644
index 000000000..09d745899
--- /dev/null
+++ b/desktop/lib/web/tabs/web_tab_menu.dart
@@ -0,0 +1,132 @@
+import 'package:flutter/material.dart';
+
+import '../../state/app_state.dart';
+import '../../state/harness_activity.dart';
+import '../../state/terminal_pane.dart';
+import '../../state/workspace_chrome.dart';
+import '../../state/workspace_status.dart';
+import '../../widgets/pane_grid.dart' show soloPaneId;
+import '../../widgets/pane_menu.dart';
+
+/// What a row of the tab menu asks for, carried out once the menu is gone.
+sealed class WebTabChoice {
+ const WebTabChoice();
+}
+
+class WebFocusPane extends WebTabChoice {
+ const WebFocusPane(this.paneId);
+ final int paneId;
+}
+
+class WebClosePane extends WebTabChoice {
+ const WebClosePane(this.paneId);
+ final int paneId;
+}
+
+class WebSelectTab extends WebTabChoice {
+ const WebSelectTab(this.id);
+ final String id;
+}
+
+class WebCloseTab extends WebTabChoice {
+ const WebCloseTab(this.id);
+ final String id;
+}
+
+class WebRunCommand extends WebTabChoice {
+ const WebRunCommand(this.command);
+ final String command;
+}
+
+/// A pane's name in the menu: its harness, or the harness a viewer watches.
+String webPaneTitle(AppNotifier app, TerminalPane pane) {
+ final id = pane.isWeb ? pane.ownerAgentId : pane.agentId;
+ final agent = app
+ .stateOf(pane.machineId)
+ ?.agents
+ .where((agent) => agent.id == id)
+ .firstOrNull;
+ final name = agent?.displayName ?? 'Harness';
+ return pane.isWeb ? '$name · viewer' : name;
+}
+
+/// The menu's rows: this tab's harnesses (a phone draws one at a time), then
+/// every tab, then rename. Harnesses and tabs both close from their row.
+List<Widget> webTabMenuRows(
+ AppNotifier app,
+ WorkspaceCommands commands,
+ void Function(WebTabChoice?) close,
+) {
+ final names = workspaceTabNames(app);
+ final shown = soloPaneId(app);
+ Widget row(String key, WebTabChoice choice, PaneMenuRow content) =>
+ paneMenuItem(
+ onTap: () => close(choice),
+ child: KeyedSubtree(key: ValueKey(key), child: content),
+ );
+ Widget closable({
+ required String key,
+ required WebTabChoice choice,
+ required String closeTooltip,
+ required WebTabChoice closeChoice,
+ required PaneMenuRow content,
+ }) => paneMenuItem(
+ onTap: () => close(choice),
+ child: Row(
+ children: [
+ Expanded(
+ child: KeyedSubtree(key: ValueKey(key), child: content),
+ ),
+ IconButton(
+ key: ValueKey('$key:close'),
+ tooltip: closeTooltip,
+ visualDensity: VisualDensity.compact,
+ iconSize: 16,
+ onPressed: () => close(closeChoice),
+ icon: const Icon(Icons.close),
+ ),
+ ],
+ ),
+ );
+ return [
+ if (app.panes.length > 1) ...[
+ paneMenuHeader('Harnesses in this tab'),
+ for (final pane in app.panes)
+ closable(
+ key: 'web-pane:${pane.id}',
+ choice: WebFocusPane(pane.id),
+ closeTooltip: 'Close pane',
+ closeChoice: WebClosePane(pane.id),
+ content: PaneMenuRow(
+ selected: pane.id == shown,
+ title: webPaneTitle(app, pane),
+ status: harnessActivity(
+ app,
+ pane.machineId,
+ (pane.isWeb ? pane.ownerAgentId : pane.agentId) ?? '',
+ )?.label,
+ ),
+ ),
+ ],
+ paneMenuHeader('Tabs'),
+ for (final (index, tab) in app.swarms.indexed)
+ closable(
+ key: 'web-tab:${tab.id}',
+ choice: WebSelectTab(tab.id),
+ closeTooltip: 'Close tab',
+ closeChoice: WebCloseTab(tab.id),
+ content: PaneMenuRow(
+ selected: tab.id == app.activeSwarmId,
+ title: '${index + 1}:${names[tab.id] ?? tab.name}',
+ status: tabActivity(app, tab)?.label,
+ ),
+ ),
+ // New tabs are the `+` beside the switcher, as on desktop.
+ if (commands.canRun('swarm.rename'))
+ row(
+ 'web-tab-run:swarm.rename',
+ const WebRunCommand('swarm.rename'),
+ const PaneMenuRow(selected: false, title: 'Rename this tab'),
+ ),
+ ];
+}
diff --git a/desktop/lib/web/tabs/web_tab_switcher.dart b/desktop/lib/web/tabs/web_tab_switcher.dart
new file mode 100644
index 000000000..b060f8a58
--- /dev/null
+++ b/desktop/lib/web/tabs/web_tab_switcher.dart
@@ -0,0 +1,153 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+import 'package:xterm/xterm.dart' show TerminalTheme;
+
+import '../../shared/theme/app_theme.dart' as grid;
+import '../../shared/theme/workspace_bar_style.dart';
+import '../../state/app_state.dart';
+import '../../state/harness_activity.dart';
+import '../../state/workspace_chrome.dart';
+import '../../state/workspace_status.dart';
+import '../../terminal/terminal_theme.dart';
+import '../../terminal/terminal_theme_store.dart';
+import '../../widgets/pane_menu.dart';
+import '../../widgets/pane_grid.dart' show soloPaneId;
+import 'web_tab_menu.dart';
+import '../../widgets/workspace_bar_control.dart';
+
+/// The tab list on a phone: the current tab as one control; its harnesses and
+/// every tab one tap away in a menu. A row of tabs leaves room for one, and a
+/// swipe along it reorders tabs instead of scrolling them.
+class WebTabSwitcher extends StatelessWidget {
+ const WebTabSwitcher({super.key, required this.app, required this.commands});
+
+ final AppNotifier app;
+ final WorkspaceCommands commands;
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = terminalThemeFor(
+ grid.AppTheme.palette.value,
+ terminalThemeStore.value,
+ );
+ final enabled = commands.enabled();
+ final index = app.swarms.indexWhere((tab) => tab.id == app.activeSwarmId);
+ final name = workspaceTabNames(app)[app.activeSwarmId] ?? '';
+ final activity = tabActivity(app, app.activeSwarm);
+ final panes = app.panes;
+ final shown = panes.indexWhere((pane) => pane.id == soloPaneId(app));
+ final label = [
+ '${index + 1}:$name',
+ // Which of the tab's harnesses is on screen: a phone draws one.
+ if (panes.length > 1) '· ${shown + 1}/${panes.length}',
+ if (activity?.mark.isNotEmpty == true) activity!.mark,
+ ].join(' ');
+ return Row(
+ children: [
+ Flexible(child: _switcher(context, label, enabled, theme)),
+ _newTabButton(context, enabled, theme),
+ ],
+ );
+ }
+
+ Widget _switcher(
+ BuildContext context,
+ String label,
+ bool enabled,
+ TerminalTheme theme,
+ ) => WorkspaceBarControl(
+ key: const ValueKey('web-tab-switcher'),
+ label: 'Tabs: $label',
+ tooltip: 'Tabs',
+ onPressed: enabled ? () => _open(context) : null,
+ builder: (context, emphasized) => SizedBox(
+ height: workspaceBarControlHeight(context),
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ horizontal: workspaceBarCellSizeOf(context).width,
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Flexible(
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: workspaceBarTextStyle(
+ color: theme.foreground,
+ emphasized: emphasized,
+ ),
+ ),
+ ),
+ // An icon, not "▾": the terminal face may have no such glyph.
+ Icon(
+ LucideIcons.chevronDown,
+ size: 14,
+ color: theme.foreground.withValues(alpha: .75),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+
+ /// Desktop's `+` beside the tabs: a new tab, which opens on "Start an agent".
+ Widget _newTabButton(
+ BuildContext context,
+ bool enabled,
+ TerminalTheme theme,
+ ) => WorkspaceBarControl(
+ key: const ValueKey('web-new-tab-button'),
+ label: 'New Swarm',
+ tooltip: 'New Swarm',
+ foreground: theme.foreground,
+ onPressed: enabled && commands.canRun('swarm.new')
+ ? () => commands.run('swarm.new')
+ : null,
+ builder: (context, emphasized) => SizedBox(
+ width: workspaceBarCellSizeOf(context).width * 3,
+ height: workspaceBarControlHeight(context),
+ child: Center(
+ child: Text('+', style: workspaceBarTextStyle(emphasized: emphasized)),
+ ),
+ ),
+ );
+
+ Future<void> _open(BuildContext context) async {
+ final box = context.findRenderObject() as RenderBox?;
+ final overlay =
+ Overlay.of(context).context.findRenderObject() as RenderBox?;
+ if (box == null || overlay == null) return;
+ final origin = box.localToGlobal(Offset.zero, ancestor: overlay);
+ final choice = await showPaneMenu<WebTabChoice>(
+ context: context,
+ position: RelativeRect.fromLTRB(
+ origin.dx,
+ origin.dy + box.size.height + 6,
+ overlay.size.width - origin.dx - box.size.width,
+ 0,
+ ),
+ minWidth: 260,
+ maxWidth: 360,
+ children: (close) => webTabMenuRows(app, commands, close),
+ );
+ // Acted on after the menu closed and handed focus back.
+ switch (choice) {
+ case WebFocusPane(:final paneId):
+ app.focusPane(paneId, reveal: true);
+ case WebClosePane(:final paneId):
+ unawaited(app.closePane(paneId));
+ case WebSelectTab(:final id):
+ app.selectSwarm(id);
+ case WebCloseTab(:final id):
+ unawaited(app.closeSwarm(id));
+ case WebRunCommand(:final command):
+ commands.run(command);
+ case null:
+ break;
+ }
+ }
+}
diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dart
index 8900a7020..5697cb340 100644
--- a/desktop/lib/widgets/pane_grid.dart
+++ b/desktop/lib/widgets/pane_grid.dart
@@ -37,6 +37,11 @@ import 'web_pane_panel.dart';
import 'pane_resize_handle.dart';
import 'box_chrome.dart';
+/// The view drawn alone when only one fits (a phone): the real zoom, else the
+/// focused view, else the first before anything has focus.
+int? soloPaneId(AppNotifier app) =>
+ app.zoomedPaneId ?? app.focusedPaneId ?? app.panes.firstOrNull?.id;
+
/// Terminal views arranged by the chosen preset. Swarms keep each view under
/// one stable parent as its rectangle, visibility and keyboard focus change.
class PaneGrid extends StatelessWidget {
@@ -45,12 +50,18 @@ class PaneGrid extends StatelessWidget {
required this.notifier,
this.swarmMode = false,
this.empty,
+ this.soloFocused = false,
});
final AppNotifier notifier;
final bool swarmMode;
final Widget? empty;
+ /// Draw only the focused view, full size, as if zoomed — without zooming:
+ /// the tab's saved layout and zoom stay as they are (a phone shows one
+ /// harness at a time; the same desk on a computer keeps its grid).
+ final bool soloFocused;
+
@override
Widget build(BuildContext context) {
TerminalFontScope.watch(context);
@@ -62,6 +73,7 @@ class PaneGrid extends StatelessWidget {
notifier: notifier,
dragging: dragging,
empty: empty,
+ soloFocused: soloFocused,
);
}
final panes = notifier.panes;
@@ -222,10 +234,12 @@ class _SwarmCanvas extends StatefulWidget {
required this.notifier,
required this.dragging,
this.empty,
+ this.soloFocused = false,
});
final AppNotifier notifier;
final AgentDragRef? dragging;
final Widget? empty;
+ final bool soloFocused;
@override
State<_SwarmCanvas> createState() => _SwarmCanvasState();
}
@@ -248,11 +262,16 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
Size? _viewportSize;
bool _focusRevealPending = false;
+ /// The view drawn alone: the real zoom, or [soloPaneId] when solo.
+ int? get _shownZoom => widget.soloFocused
+ ? soloPaneId(widget.notifier)
+ : widget.notifier.zoomedPaneId;
+
Object get _inputDestination => (
widget.notifier.activeSwarmId,
widget.notifier.focusedPaneId,
widget.notifier.paneFocusRequest,
- widget.notifier.zoomedPaneId,
+ _shownZoom,
widget.notifier.tabStripFocused,
);
@@ -321,7 +340,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
final app = widget.notifier;
final visible = {
for (final pane in app.panes)
- if (app.zoomedPaneId == null || pane.id == app.zoomedPaneId) pane.id,
+ if (_shownZoom == null || pane.id == _shownZoom) pane.id,
};
// Exclude the outgoing views and enable the destination's existing focus
// tree now. Painting/layout still happens in the normal scheduled frame.
@@ -348,7 +367,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
if (viewport == null || !_scroll.hasClients) return;
final app = widget.notifier;
final panes = app.panes
- .where((p) => app.zoomedPaneId == null || p.id == app.zoomedPaneId)
+ .where((p) => _shownZoom == null || p.id == _shownZoom)
.toList();
final index = panes.indexWhere((p) => p.id == app.focusedPaneId);
if (index < 0) return;
@@ -427,11 +446,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
return (
notifier: app,
location: (app.activeSwarmId, app.panes.indexOf(pane)),
- layoutRequest: (
- app.paneLayoutRequest,
- app.panes.length,
- app.zoomedPaneId,
- ),
+ layoutRequest: (app.paneLayoutRequest, app.panes.length, _shownZoom),
machine: machine?.machine,
local: machine?.isLocalMachine,
online: machine?.nodeOnline,
@@ -474,7 +489,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
_focusRevealPending = false;
final visible = [
for (final pane in app.panes)
- if (app.zoomedPaneId == null || pane.id == app.zoomedPaneId) pane,
+ if (_shownZoom == null || pane.id == _shownZoom) pane,
];
final layout = _SwarmGeometry(
count: visible.length,
@@ -483,7 +498,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
minimum: _MinTile.of(),
sizes: app.activeSwarm.paneSizes,
);
- if (app.zoomedPaneId == null) {
+ if (_shownZoom == null) {
app.activeSwarm.arranged = layout.arrangement;
app.activeSwarm.arrangedKey = layout.key;
final minimum = _MinTile.of();
@@ -559,10 +574,11 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
dragging: widget.dragging,
visible: rectangles.containsKey(pane.id),
swarmMode: true,
+ solo: widget.soloFocused,
),
),
),
- if (app.zoomedPaneId == null &&
+ if (_shownZoom == null &&
layout.arrangement?.dividers.isNotEmpty == true)
Positioned.fill(child: _resizeLayer(layout)),
],
@@ -1151,6 +1167,7 @@ class _PaneCell extends StatelessWidget {
required this.dragging,
this.visible = true,
this.swarmMode = false,
+ this.solo = false,
});
final AppNotifier notifier;
@@ -1159,7 +1176,11 @@ class _PaneCell extends StatelessWidget {
final bool visible;
final bool swarmMode;
- bool get _single => notifier.panes.length == 1;
+ /// Drawn alone under [PaneGrid.soloFocused]: it reads as the only view — no
+ /// dimming or focus ring, and no zoom, since it already fills the screen.
+ final bool solo;
+
+ bool get _single => solo || notifier.panes.length == 1;
@override
Widget build(BuildContext context) {
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index d319df0ae..a0c2a7bc7 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -95,6 +95,14 @@ TerminalNotice terminalNotice({
banner: banner,
);
+/// A browser on a phone or tablet, typing through its on-screen keyboard.
+/// Those keyboards send no Backspace key, so the terminal detects deletes in
+/// its input buffer instead ([TerminalView.deleteDetection]).
+bool get isTouchBrowser =>
+ kIsWeb &&
+ (defaultTargetPlatform == TargetPlatform.android ||
+ defaultTargetPlatform == TargetPlatform.iOS);
+
class TerminalPanel extends StatefulWidget {
final AppNotifier notifier;
final TerminalSession session;
@@ -2172,6 +2180,7 @@ class _TerminalPanelState extends State<TerminalPanel>
? SystemMouseCursors.basic
: SystemMouseCursors.text,
onSecondaryTapDown: (_, _) => _copyOrPaste(),
+ deleteDetection: isTouchBrowser,
onAltBufferScroll: session.scrollViaTmuxCopyMode
? (up) => session.sendScrollCommand(up, 1)
diff --git a/desktop/test/terminal_delete_detection_test.dart b/desktop/test/terminal_delete_detection_test.dart
new file mode 100644
index 000000000..39082b549
--- /dev/null
+++ b/desktop/test/terminal_delete_detection_test.dart
@@ -0,0 +1,91 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:xterm/xterm.dart';
+
+/// A phone's on-screen keyboard sends no Backspace key: it deletes from the
+/// terminal's hidden input buffer, and the terminal turns that into DEL. The
+/// buffer keeps a pad so the delete is seen even when nothing was typed —
+/// which is how a pasted `[Image #1]` at an agent's prompt gets removed.
+void main() {
+ Future<(List<String>, _SoftKeyboard)> mount(WidgetTester tester) async {
+ final output = <String>[];
+ await tester.pumpWidget(
+ MaterialApp(
+ home: TerminalView(
+ Terminal(onOutput: output.add),
+ autofocus: true,
+ deleteDetection: true,
+ ),
+ ),
+ );
+ await tester.pump();
+ return (output, _SoftKeyboard(tester));
+ }
+
+ testWidgets('every Backspace on an empty prompt reaches the terminal', (
+ tester,
+ ) async {
+ final (output, keyboard) = await mount(tester);
+ for (var i = 0; i < 5; i++) {
+ await keyboard.backspace();
+ }
+ expect(output.join(), '\x7f' * 5);
+ });
+
+ testWidgets('typed text still deletes one character at a time', (
+ tester,
+ ) async {
+ final (output, keyboard) = await mount(tester);
+ await keyboard.type('ab');
+ for (var i = 0; i < 4; i++) {
+ await keyboard.backspace();
+ }
+ expect(output.join(), 'ab${'\x7f' * 4}');
+ });
+}
+
+/// The on-screen keyboard's own copy of the buffer. `testTextInput` records
+/// only what the app sets, so the keyboard keeps what it typed and adopts the
+/// app's value whenever the app sets a new one.
+class _SoftKeyboard {
+ _SoftKeyboard(this.tester) {
+ _adoptAppState();
+ }
+
+ final WidgetTester tester;
+ String _text = '';
+ int _seenSets = 0;
+
+ int get _appSets => tester.testTextInput.log
+ .where((call) => call.method == 'TextInput.setEditingState')
+ .length;
+
+ void _adoptAppState() {
+ if (_appSets == _seenSets) return;
+ _seenSets = _appSets;
+ _text = tester.testTextInput.editingState!['text'] as String;
+ }
+
+ Future<void> _send(String text) async {
+ _adoptAppState();
+ _text = text;
+ tester.testTextInput.updateEditingValue(
+ TextEditingValue(
+ text: text,
+ selection: TextSelection.collapsed(offset: text.length),
+ ),
+ );
+ await tester.pump();
+ _adoptAppState();
+ }
+
+ Future<void> type(String typed) async {
+ _adoptAppState();
+ await _send('$_text$typed');
+ }
+
+ Future<void> backspace() async {
+ _adoptAppState();
+ await _send(_text.substring(0, _text.length - 1));
+ }
+}
diff --git a/desktop/test/web/terminal_backspace_test.dart b/desktop/test/web/terminal_backspace_test.dart
new file mode 100644
index 000000000..ee911766a
--- /dev/null
+++ b/desktop/test/web/terminal_backspace_test.dart
@@ -0,0 +1,40 @@
+@TestOn('browser')
+library;
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:xterm/xterm.dart';
+
+/// In a browser a physical Backspace is the terminal's to send, on every
+/// platform the browser reports — including the macOS and iOS that native
+/// builds hand to Apple's text input client. Nothing typed in the hidden
+/// input, it still reaches the pty (a pasted `[Image #1]` gets removed).
+void main() {
+ for (final platform in [
+ TargetPlatform.macOS,
+ TargetPlatform.iOS,
+ TargetPlatform.android,
+ TargetPlatform.windows,
+ ]) {
+ testWidgets('Backspace reaches the pty once on ${platform.name}', (
+ tester,
+ ) async {
+ debugDefaultTargetPlatformOverride = platform;
+ final output = <String>[];
+ await tester.pumpWidget(
+ MaterialApp(
+ home: TerminalView(Terminal(onOutput: output.add), autofocus: true),
+ ),
+ );
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.backspace);
+ await tester.pump();
+ // Reset inside the test: the binding checks debug overrides before
+ // tear-downs run.
+ debugDefaultTargetPlatformOverride = null;
+ expect(output.join(), '\x7f');
+ });
+ }
+}
diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dart
index eaaac67ba..efc50a9fb 100644
--- a/desktop/test/web/web_app_menu_test.dart
+++ b/desktop/test/web/web_app_menu_test.dart
@@ -76,8 +76,8 @@ void main() {
newHarnessOpensInBox = true;
addTearDown(() => newHarnessOpensInBox = false);
final app = await _mount(tester, connectedMachine: 'remote-box');
- await _openMenu(tester);
- await tester.tap(find.byKey(const ValueKey('web-menu:agent.new')));
+ // New work starts where a new tab opens: its "Start an agent" row.
+ await tester.tap(find.byKey(const ValueKey('welcome-agent.new')));
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 200)),
);
@@ -93,8 +93,8 @@ void main() {
tester,
) async {
final app = await _mount(tester);
- await _openMenu(tester);
- await tester.tap(find.byKey(const ValueKey('web-menu:agent.new')));
+ // New work starts where a new tab opens: its "Start an agent" row.
+ await tester.tap(find.byKey(const ValueKey('welcome-agent.new')));
await tester.pump(const Duration(milliseconds: 400));
expect(find.byType(NewHarnessForm), findsNothing);
expect(
diff --git a/desktop/test/web_menu_items_test.dart b/desktop/test/web_menu_items_test.dart
index dabca0cc0..ac0b0a971 100644
--- a/desktop/test/web_menu_items_test.dart
+++ b/desktop/test/web_menu_items_test.dart
@@ -2,27 +2,53 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/shortcuts/keymap_commands.dart';
import 'package:harness/web/shell/web_menu_items.dart';
+List<String> _commands(List<List<WebMenuItem>> menu) => [
+ for (final group in menu)
+ for (final item in group) item.command,
+];
+
void main() {
test('every web menu row names a registered workspace command', () {
final registered = {for (final command in harnessCommands) command.id};
- for (final section in kWebMenuSections) {
- for (final item in section.items) {
+ for (final group in kWebMenuGroups) {
+ for (final item in group) {
expect(registered, contains(item.command), reason: item.label);
}
}
});
- test('rows that cannot run, and sections left empty, are not drawn', () {
+ test('a phone gets Store, a wide window gets Add phone', () {
+ final phone = _commands(runnableWebMenu((_) => true, compact: true));
+ final wide = _commands(runnableWebMenu((_) => true, compact: false));
+ expect(phone, contains('app.store'));
+ expect(phone, isNot(contains('app.add_phone')));
+ expect(wide, contains('app.add_phone'));
+ expect(wide, isNot(contains('app.store')));
+ });
+
+ test('controls the bar already has, and keyboard tours, stay out', () {
+ final all = _commands(runnableWebMenu((_) => true, compact: true));
+ for (final elsewhere in [
+ 'agent.new',
+ 'swarm.new',
+ 'harnesses.list',
+ 'navigation.needs_input',
+ 'pane.split_right',
+ 'pane.zoom',
+ 'pane.layout',
+ 'keyboard.help',
+ 'keyboard.quick_start',
+ ]) {
+ expect(all, isNot(contains(elsewhere)), reason: elsewhere);
+ }
+ });
+
+ test('rows that cannot run, and groups left empty, are not drawn', () {
final menu = runnableWebMenu(
- (command) => !command.startsWith('pane.') && command != 'agent.share',
+ (command) => command != 'agent.share' && command != 'pane.close',
+ compact: false,
);
- final titles = [for (final section in menu) section.title];
- expect(titles, isNot(contains('Pane')));
- final workspace = menu.firstWhere((s) => s.title == 'Workspace');
- expect(workspace.items.map((i) => i.command), [
- 'navigation.history',
- 'navigation.commands',
- ]);
- expect(runnableWebMenu((_) => false), isEmpty);
+ expect(menu, hasLength(kWebMenuGroups.length - 1));
+ expect(runnableWebMenu((_) => false, compact: false), isEmpty);
});
}
diff --git a/desktop/test/web_tab_switcher_test.dart b/desktop/test/web_tab_switcher_test.dart
new file mode 100644
index 000000000..be94f7e35
--- /dev/null
+++ b/desktop/test/web_tab_switcher_test.dart
@@ -0,0 +1,191 @@
+import 'dart:io';
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/screens/swarm_screen.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/terminal_pane.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+
+import 'support/real_fonts.dart';
+
+/// The web workspace on a phone: one tab switcher instead of a tab row.
+void main() {
+ setUpAll(loadRealFonts);
+ final boundary = GlobalKey();
+
+ Future<AppNotifier> mount(
+ WidgetTester tester,
+ Size size, {
+ int harnesses = 0,
+ }) async {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ for (var i = 0; i < 4; i++) {
+ app.newSwarm(newTabPage: true);
+ }
+ if (harnesses > 0) {
+ const machine = Machine(
+ machineId: 'm',
+ name: 'box',
+ authMode: MachineAuthMode.remote,
+ );
+ app.machines.add(machine);
+ app.machineStates['m'] = MachineState(machine)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agents = [
+ for (var i = 0; i < harnesses; i++)
+ Agent(id: 'a$i', name: 'Agent $i'),
+ ];
+ app.activeSwarm.panes.addAll([
+ for (var i = 0; i < harnesses; i++)
+ TerminalPane(id: 100 + i, machineId: 'm', agentId: 'a$i'),
+ ]);
+ }
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ RepaintBoundary(
+ key: boundary,
+ child: MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: SwarmScreen(
+ notifier: app,
+ nativeTabs: false,
+ chrome: webWorkspaceChrome(app),
+ ),
+ ),
+ ),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ return app;
+ }
+
+ Future<void> capture(WidgetTester tester, String name) async {
+ final output = Platform.environment['HARNESS_REFINEMENT_CAPTURE_DIR'];
+ if (output == null) return;
+ await tester.runAsync(() async {
+ final image =
+ await (boundary.currentContext!.findRenderObject()
+ as RenderRepaintBoundary)
+ .toImage();
+ final data = await image.toByteData(format: ui.ImageByteFormat.png);
+ Directory(output).createSync(recursive: true);
+ File('$output/$name.png').writeAsBytesSync(data!.buffer.asUint8List());
+ image.dispose();
+ });
+ }
+
+ Future<void> openSwitcher(WidgetTester tester) async {
+ await tester.tap(find.byKey(const ValueKey('web-tab-switcher')));
+ await tester.pump(const Duration(milliseconds: 100));
+ }
+
+ testWidgets('a phone switches, opens and closes tabs from one menu', (
+ tester,
+ ) async {
+ final app = await mount(tester, const Size(390, 844));
+ expect(find.byKey(const ValueKey('web-tab-switcher')), findsOneWidget);
+ expect(find.byKey(const ValueKey('swarm-store-button')), findsNothing);
+ expect(find.byKey(const ValueKey('swarm-new-tab-button')), findsNothing);
+ await capture(tester, 'web-phone-tab-bar');
+
+ await openSwitcher(tester);
+ for (final tab in app.swarms) {
+ expect(find.byKey(ValueKey('web-tab:${tab.id}')), findsOneWidget);
+ }
+ await capture(tester, 'web-phone-tab-menu');
+ final first = app.swarms.first.id;
+ await tester.tap(find.byKey(ValueKey('web-tab:$first')));
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(app.activeSwarmId, first);
+
+ final count = app.swarms.length;
+ await tester.tap(find.byKey(const ValueKey('web-new-tab-button')));
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(app.swarms.length, count + 1);
+
+ await openSwitcher(tester);
+ final last = app.swarms.last.id;
+ await tester.tap(find.byKey(ValueKey('web-tab:$last:close')));
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(app.swarms.map((tab) => tab.id), isNot(contains(last)));
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+
+ testWidgets('a phone shows one harness of a tab, switched from the menu', (
+ tester,
+ ) async {
+ final app = await mount(tester, const Size(390, 844), harnesses: 3);
+ bool onScreen(String name) =>
+ find.text(name).hitTestable().evaluate().isNotEmpty;
+ expect(onScreen('Agent 0'), isTrue);
+ expect(onScreen('Agent 1'), isFalse);
+ expect(onScreen('Agent 2'), isFalse);
+ expect(
+ find.descendant(
+ of: find.byKey(const ValueKey('web-tab-switcher')),
+ matching: find.textContaining('1/3'),
+ ),
+ findsOneWidget,
+ );
+ await capture(tester, 'web-phone-solo-pane');
+
+ await openSwitcher(tester);
+ await capture(tester, 'web-phone-harness-menu');
+ await tester.tap(find.byKey(const ValueKey('web-pane:101')));
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(app.focusedPaneId, 101);
+ expect(onScreen('Agent 1'), isTrue);
+ expect(onScreen('Agent 0'), isFalse);
+ // Drawn alone, not zoomed: the desk's own layout is untouched.
+ expect(app.zoomedPaneId, isNull);
+
+ // A harness closes from its own row, like a tab.
+ await openSwitcher(tester);
+ await tester.tap(find.byKey(const ValueKey('web-pane:102:close')));
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(app.panes.map((pane) => pane.id), [100, 101]);
+
+ await tester.tap(find.byKey(const ValueKey('web-app-menu-button')));
+ await tester.pump(const Duration(milliseconds: 100));
+ // The phone menu carries Store (its bar has no Store button), not Add phone.
+ expect(find.byKey(const ValueKey('web-menu:app.store')), findsOneWidget);
+ expect(find.byKey(const ValueKey('web-menu:app.add_phone')), findsNothing);
+ await capture(tester, 'web-phone-app-menu');
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+
+ testWidgets('a wide window keeps the grid of harnesses', (tester) async {
+ final app = await mount(tester, const Size(1280, 800), harnesses: 3);
+ expect(find.text('Agent 0').hitTestable(), findsOneWidget);
+ expect(find.text('Agent 1').hitTestable(), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+
+ testWidgets('a wide window keeps the row of tabs', (tester) async {
+ final app = await mount(tester, const Size(1280, 800));
+ expect(find.byKey(const ValueKey('web-tab-switcher')), findsNothing);
+ expect(find.byKey(const ValueKey('swarm-store-button')), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+}
diff --git a/desktop/third_party/xterm/README.autonomous.md b/desktop/third_party/xterm/README.autonomous.md
index 9aeba298a..0143c690a 100644
--- a/desktop/third_party/xterm/README.autonomous.md
+++ b/desktop/third_party/xterm/README.autonomous.md
@@ -265,3 +265,24 @@ it if one is dropped.
as before; underlined spaces become U+00A0 as in the per-cell path.
Regression: `test/terminal_line_paint_cache_test.dart` (where runs are cut,
and a rendering within antialiasing of the per-cell one).
+
+15. **`deleteDetection` keeps its pad** (`lib/src/ui/custom_text_edit.dart`).
+ Upstream seeds the hidden input buffer with two spaces so an on-screen
+ keyboard's Backspace (which sends no key event) still deletes something
+ and is seen, but never puts them back: after two deletes the buffer was
+ empty and every later Backspace changed nothing, so nothing reached the
+ PTY — a pasted `[Image #1]` at an agent prompt could not be removed on a
+ phone. The pad is restored whenever deletes eat into it. Only reached with
+ `deleteDetection: true`, which the app sets for touch browsers alone
+ (`isTouchBrowser` in `lib/widgets/terminal_panel.dart`). Regression:
+ `test/terminal_delete_detection_test.dart`.
+
+16. **A browser sends its own Backspace** (`lib/src/terminal_view.dart`).
+ Native macOS/iOS hand a bare Backspace to Apple's text input client, which
+ answers with `deleteBackward:` (see 15's neighbour in
+ `custom_text_edit.dart`). Flutter web reports the same platforms — macOS in
+ Chrome on a Mac, iOS on an iPhone — but sends no performSelectors: the
+ browser only deleted from the hidden input, so with nothing typed there a
+ Backspace never reached the PTY. On the web the key now goes to
+ `keyInput` everywhere. Regression: `test/web/terminal_backspace_test.dart`
+ (run with `--platform=chrome`).
diff --git a/desktop/third_party/xterm/lib/src/terminal_view.dart b/desktop/third_party/xterm/lib/src/terminal_view.dart
index 30b04c84d..c54a09747 100644
--- a/desktop/third_party/xterm/lib/src/terminal_view.dart
+++ b/desktop/third_party/xterm/lib/src/terminal_view.dart
@@ -556,9 +556,15 @@ class TerminalViewState extends State<TerminalView> {
// internal deletes they make are plain Backspaces. It belongs to keyInput
// below, where ⌥ becomes the Meta prefix a prompt reads as "kill the word
// behind me" (see AltAsMetaInputHandler in lib/terminal/terminal_input.dart).
- final nativeClientOwnsBackspace =
- defaultTargetPlatform == TargetPlatform.macOS ||
- defaultTargetPlatform == TargetPlatform.iOS;
+ //
+ // A BROWSER IS NOT APPLE'S EMBEDDER, whatever `defaultTargetPlatform` says
+ // (it reads macOS in Chrome on a Mac, iOS on an iPhone). Flutter web sends
+ // no performSelectors; the browser just deletes from the hidden input, so
+ // a Backspace with nothing typed there — a pasted `[Image #1]` at an agent
+ // prompt — changed nothing and never reached the pty.
+ final nativeClientOwnsBackspace = !kIsWeb &&
+ (defaultTargetPlatform == TargetPlatform.macOS ||
+ defaultTargetPlatform == TargetPlatform.iOS);
if (key == TerminalKey.backspace &&
nativeClientOwnsBackspace &&
!widget.hardwareKeyboardOnly &&
diff --git a/desktop/third_party/xterm/lib/src/ui/custom_text_edit.dart b/desktop/third_party/xterm/lib/src/ui/custom_text_edit.dart
index d9de5c5d7..65ec760a5 100644
--- a/desktop/third_party/xterm/lib/src/ui/custom_text_edit.dart
+++ b/desktop/third_party/xterm/lib/src/ui/custom_text_edit.dart
@@ -389,6 +389,18 @@ class CustomTextEditState extends State<CustomTextEdit> with TextInputClient {
if (hasTextMutation || wasComposing || value.text != _terminalText) {
_syncTerminalText(value.text);
}
+ _restoreDeletePadding();
+ }
+
+ /// Under [CustomTextEdit.deleteDetection] the buffer keeps a pad in front of
+ /// what was typed, so a Backspace always has something to delete and is
+ /// seen. Once deletes eat into the pad it goes back: a phone's keyboard sends
+ /// no Backspace key, so a Backspace on an empty buffer changes nothing and
+ /// never reaches the terminal (a pasted `[Image #1]` could not be removed).
+ void _restoreDeletePadding() {
+ if (!widget.deleteDetection) return;
+ if (_currentEditingState.text.startsWith(_initEditingState.text)) return;
+ setEditingState(_initEditingState.copyWith());
}
void _syncTerminalText(String value) {