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.

Web UX 3: pane header and its states (S2, S3, S4, S1 header, S8) (#1683)

Jacob Phamee05f79b0f05
diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dart
index 535e6fe76..44d08d64b 100644
--- a/desktop/lib/state/workspace_chrome.dart
+++ b/desktop/lib/state/workspace_chrome.dart
@@ -64,6 +64,7 @@ class WorkspaceChrome {
this.compactTabs,
this.compactFooter,
this.compactBelow = 0,
+ this.twoPaneColumnsBelow = 0,
this.firstMachine,
this.menuOnEveryTab = false,
this.labelsPaneStatus = false,
@@ -124,6 +125,15 @@ class WorkspaceChrome {
compactFooter;
final double compactBelow;
+ /// Below [twoPaneColumnsBelow] of window width the pane grid is drawn at
+ /// most two columns wide, so a tablet's panes keep a readable header. Only
+ /// the drawing: the tab's saved layout stays the one a wider window shows.
+ /// Zero, the default, never applies. Audit finding S2.
+ final double twoPaneColumnsBelow;
+
+ /// The most pane columns a window [width] wide draws, or null for no limit.
+ int? maxPaneColumnsAt(double width) => width < twoPaneColumnsBelow ? 2 : null;
+
/// True gives every tab a right-click menu (Rename Tab, Close Tab), not only
/// a shared one. Audit finding S10.
final bool menuOnEveryTab;
diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dart
index c670bcfc0..b53f2144b 100644
--- a/desktop/lib/web/shell/web_chrome.dart
+++ b/desktop/lib/web/shell/web_chrome.dart
@@ -37,6 +37,7 @@ WorkspaceChrome _webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
WebTabSwitcher(app: app, commands: commands),
compactFooter: (context, footer) => WebFooterBar(footer: footer),
compactBelow: kWebCompactBelow,
+ twoPaneColumnsBelow: 1000,
firstMachine: (context) => WebFirstMachine(app: app),
menuOnEveryTab: true,
labelsPaneStatus: true,
diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dart
index fe75fc147..4cd2889ba 100644
--- a/desktop/lib/widgets/pane_grid.dart
+++ b/desktop/lib/widgets/pane_grid.dart
@@ -15,7 +15,7 @@ import 'window_chrome.dart';
import '../clipboard/image_bytes.dart';
import '../core/dsh_catalog.dart' show DshEntry;
-import '../core/models.dart' show Agent, kUntitledPane;
+import '../core/models.dart' show Agent, ConnectionStatus, kUntitledPane;
import '../clipboard/native_clipboard.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/theme/appearance_prefs_store.dart';
@@ -29,6 +29,7 @@ import '../state/pane_preset.dart';
import '../state/pane_arrangement.dart';
import 'pane_fixed_width.dart';
import '../state/terminal_pane.dart';
+import '../state/workspace_chrome.dart';
import '../terminal/terminal_binary.dart';
import '../terminal/terminal_text.dart';
import '../terminal/terminal_session.dart';
@@ -315,6 +316,9 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
Size? _viewportSize;
bool _focusRevealPending = false;
+ /// The most columns the host draws at this window's width, read at build.
+ int? _maxColumns;
+
/// The view drawn alone: the real zoom, or [soloPaneId] when solo.
int? get _shownZoom => widget.soloFocused
? soloPaneId(widget.notifier)
@@ -430,7 +434,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
preset: app.presetFor(panes.length),
minimum: _MinTile.of(),
sizes: app.activeSwarm.paneSizes,
- );
+ ).within(_maxColumns, viewport: viewport, minimum: _MinTile.of());
final rect = geometry.rectangles[index];
void reveal(
ScrollController scroll,
@@ -503,6 +507,8 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
machine: machine?.machine,
local: machine?.isLocalMachine,
online: machine?.nodeOnline,
+ // The web words a computer on its way back; the pane follows it.
+ connection: machine?.connectionStatus,
needsLink: machine?.needsLink,
localTransport: machine?.usesLocalTransport,
agent: agent,
@@ -576,16 +582,23 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
);
}
if (layout.columns != null) app.gridColumns = layout.columns;
+ _maxColumns = WorkspaceChrome.of(context)
+ .maxPaneColumnsAt(MediaQuery.sizeOf(context).width);
+ final drawn = layout.within(
+ _maxColumns,
+ viewport: constraints.biggest,
+ minimum: _MinTile.of(),
+ );
// A tile that asks for its own width (a Finder showing only its
// files) takes it; its divider is not dragged while it does.
final pinned = pinFixedColumn(
- layout.rectangles,
+ drawn.rectangles,
[for (final pane in visible) pane.fixedWidth],
- Size(layout.width, layout.height),
+ Size(drawn.width, drawn.height),
gap: kPaneGap,
minOther: _MinTile.of().width,
);
- final tiles = pinned ?? layout.rectangles;
+ final tiles = pinned ?? drawn.rectangles;
final rectangles = {
for (var i = 0; i < visible.length; i++) visible[i].id: tiles[i],
};
@@ -600,7 +613,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
child: Scrollbar(
key: const ValueKey('swarm-horizontal-scrollbar'),
controller: _horizontalScroll,
- thumbVisibility: layout.width > constraints.maxWidth,
+ thumbVisibility: drawn.width > constraints.maxWidth,
scrollbarOrientation: ScrollbarOrientation.bottom,
notificationPredicate: (notification) =>
notification.depth == 1 &&
@@ -617,8 +630,8 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
child: ScrollConfiguration(
behavior: scrollBehavior,
child: SizedBox(
- width: layout.width,
- height: layout.height,
+ width: drawn.width,
+ height: drawn.height,
child: Stack(
children: [
if (visible.isEmpty)
@@ -663,8 +676,11 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
),
),
),
+ // Dividers resize the recorded layout, so none
+ // while a narrower drawing stands in for it.
if (_shownZoom == null &&
pinned == null &&
+ identical(drawn, layout) &&
layout.arrangement?.dividers.isNotEmpty == true)
Positioned.fill(child: _resizeLayer(layout)),
],
@@ -851,22 +867,67 @@ class _SwarmGeometry {
double.infinity,
);
}
- rectangles = [
- for (final tile in arrangement!.tiles)
- Rect.fromLTWH(
- tile.left * (width + kPaneGap),
- tile.top * (height + kPaneGap),
- (tile.width * (width + kPaneGap) - kPaneGap).clamp(
- 0,
- double.infinity,
- ),
- (tile.height * (height + kPaneGap) - kPaneGap).clamp(
- 0,
- double.infinity,
- ),
- ),
- ];
+ rectangles = _pixels(arrangement!.tiles, width, height);
+ }
+
+ /// [tiles] across [viewport]'s width, each row at least [minimum] tall:
+ /// taller than the viewport, and scrolled, when the rows need it.
+ _SwarmGeometry._balanced(
+ List<Rect> tiles, {
+ required Size viewport,
+ required Size minimum,
+ }) : width = viewport.width,
+ height = viewport.height {
+ final rows = {for (final tile in tiles) tile.top}.length;
+ height = (rows * minimum.height + kPaneGap * (rows - 1)).clamp(
+ viewport.height,
+ double.infinity,
+ );
+ arrangement = PaneArrangement(tiles);
+ rectangles = _pixels(tiles, width, height);
}
+
+ /// This layout drawn at most [maxColumns] wide, the tiles in balanced rows:
+ /// a tablet browser's grid ([WorkspaceChrome.maxPaneColumnsAt]). Only the
+ /// drawing — what the tab records stays this layout, so the same desk keeps
+ /// its grid on a computer. Itself when it is no wider than that.
+ _SwarmGeometry within(
+ int? maxColumns, {
+ required Size viewport,
+ required Size minimum,
+ }) {
+ final tiles = arrangement?.tiles;
+ if (maxColumns == null || tiles == null) return this;
+ final columns = {for (final tile in tiles) tile.left}.length;
+ if (columns <= maxColumns) return this;
+ final shape = switch (maxColumns) {
+ <= 2 => PanePreset.balanced2,
+ 3 => PanePreset.balanced3,
+ 4 => PanePreset.balanced4,
+ _ => PanePreset.balanced5,
+ };
+ return _SwarmGeometry._balanced(
+ shape.tilesFor(tiles.length),
+ viewport: viewport,
+ minimum: minimum,
+ );
+ }
+
+ /// Unit [tiles] in pixels on a [width] by [height] canvas. A boundary at
+ /// fraction f lands at f * (extent + gap), less one gap per tile.
+ static List<Rect> _pixels(List<Rect> tiles, double width, double height) => [
+ for (final tile in tiles)
+ Rect.fromLTWH(
+ tile.left * (width + kPaneGap),
+ tile.top * (height + kPaneGap),
+ (tile.width * (width + kPaneGap) - kPaneGap).clamp(0, double.infinity),
+ (tile.height * (height + kPaneGap) - kPaneGap).clamp(
+ 0,
+ double.infinity,
+ ),
+ ),
+ ];
+
String? key;
PaneArrangement? arrangement;
double width, height;
@@ -1686,6 +1747,14 @@ class _PaneContent extends StatelessWidget {
machine != null &&
(machine.nodeOnline == false ||
(machine.isLocalMachine && !machine.usesLocalTransport));
+ // On its way back rather than gone: worded where the host labels pane
+ // states (the web), and not typed into until it is back.
+ final dialing =
+ WorkspaceChrome.of(context).labelsPaneStatus &&
+ machine != null &&
+ !machine.machine.isShared &&
+ (machine.connectionStatus == ConnectionStatus.connecting ||
+ machine.connectionStatus == ConnectionStatus.reconnecting);
// Availability changes the header and input permission, never the renderer's
// ancestry. Retained output, selection, scroll and Find stay in this view.
@@ -1780,6 +1849,15 @@ class _PaneContent extends StatelessWidget {
detail:
'${machine.machine.displayName} is offline. Retained output is read only.',
);
+ } else if (dialing) {
+ final again = machine.connectionStatus == ConnectionStatus.reconnecting;
+ notice = terminalNotice(
+ label: again ? 'Reconnecting…' : 'Connecting…',
+ icon: AppIcons.refreshCw,
+ detail:
+ '${again ? 'Reconnecting' : 'Connecting'} to ${machine.machine.displayName}. Keys typed now are not sent.',
+ dimsScreen: true,
+ );
} else if (agent?.isStopped == true) {
final opening = notifier.pendingAgentRestart(
pane.machineId,
@@ -1899,6 +1977,7 @@ class _PaneContent extends StatelessWidget {
machine == null ||
needsLink ||
offline ||
+ dialing ||
agent == null ||
!agent.terminalAvailable,
notice: notice,
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index c86fe0a03..3476fdd1f 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -17,6 +17,7 @@ import '../clipboard/native_clipboard.dart';
import '../core/models.dart';
import '../core/runtime_platform.dart';
import '../state/app_state.dart';
+import '../state/workspace_chrome.dart';
import '../state/harness_activity.dart';
import '../state/model_start_watch.dart';
import '../super_tabs/pane.dart';
@@ -46,7 +47,11 @@ import '../shared/theme/app_theme.dart' as grid;
import '../shared/theme/workspace_bar_style.dart';
import '../theme/app_theme.dart';
import 'engine_identity.dart';
+import 'finger_target.dart';
import 'harness_agent_control.dart';
+import 'harness_agent_picker.dart';
+import 'pane_menu.dart';
+import 'workspace_bar_control.dart';
import '../agent_messages/pane_message_mark.dart';
import '../agent_messages/pane_shared_chips.dart';
import 'harness_activity_mark.dart';
@@ -84,6 +89,11 @@ typedef TerminalNotice = ({
/// An offline machine is neither confusing nor rare, and a band on every one
/// of those would cost rows in every tile.
bool banner,
+
+ /// Whether the output underneath is not live: it is veiled, and this
+ /// notice's band lies over it rather than taking rows from it — a computer
+ /// on its way back, whose terminal comes back the size it was.
+ bool dimsScreen,
});
/// A [TerminalNotice] without spelling out the fields it does not have.
@@ -100,6 +110,7 @@ TerminalNotice terminalNotice({
String? secondaryLabel,
VoidCallback? onSecondary,
bool banner = false,
+ bool dimsScreen = false,
}) => (
label: label,
detail: detail,
@@ -109,6 +120,7 @@ TerminalNotice terminalNotice({
secondaryLabel: secondaryLabel,
onSecondary: onSecondary,
banner: banner,
+ dimsScreen: dimsScreen,
);
/// A browser on a phone or tablet, typing through its on-screen keyboard.
@@ -276,6 +288,11 @@ class _TerminalPanelState extends State<TerminalPanel>
String? _passageStream;
bool _passageRefreshPending = false;
bool _cursorBlinkVisible = true;
+
+ /// A view-only terminal, where the host labels pane states (the web): a
+ /// lock is drawn where its cursor is, and the cursor is hidden. Audit S4.
+ bool _cursorLocked = false;
+ final _cursorLockKey = GlobalKey(debugLabel: 'terminal cursor lock');
double _alternateScrollRemainder = 0;
int? _lastInertiaMicros;
late final TerminalLinkOpener _linkOpener;
@@ -989,6 +1006,23 @@ class _TerminalPanelState extends State<TerminalPanel>
void _stopCursorBlink() {
_cursorBlinkTimer?.cancel();
_cursorBlinkTimer = null;
+ _setCursorBlinkVisible(!_cursorLocked);
+ }
+
+ /// Follows [_cursorLocked] to what the session is now; read in build, where
+ /// the host's chrome can be.
+ void _syncCursorLock(bool locked) {
+ if (locked) {
+ _cursorLocked = true;
+ _stopCursorBlink();
+ // On every build, not only when the lock comes: a keyframe (a reopen or
+ // a resync) brings a new emulator and resets the session's blink phase,
+ // which would show the cursor again under the lock.
+ if (widget.session.setCursorBlinkPhase(false)) _repaintTerminalCursor();
+ return;
+ }
+ if (!_cursorLocked) return;
+ _cursorLocked = false;
_setCursorBlinkVisible(true);
}
@@ -1874,6 +1908,17 @@ class _TerminalPanelState extends State<TerminalPanel>
return KeyEventResult.handled;
}
final keyboard = HardwareKeyboard.instance;
+ // A computer on its way back ([TerminalNotice.dimsScreen]): what is typed
+ // now is dropped, as its band says, rather than sent to a link that is
+ // down. ⌘ chords are still the app's.
+ if (widget.notice?.dimsScreen == true &&
+ event is! KeyUpEvent &&
+ !keyboard.isMetaPressed &&
+ (_isTypingKey(event) ||
+ event.logicalKey == LogicalKeyboardKey.enter ||
+ event.logicalKey == LogicalKeyboardKey.numpadEnter)) {
+ return KeyEventResult.handled;
+ }
// A pane that lost control still gets the keys (xterm's read-only mode
// keeps the focus node, it only stops opening an input connection), and
// dropping them silently is how people sit typing into a frozen pane. ⏎
@@ -2175,6 +2220,9 @@ class _TerminalPanelState extends State<TerminalPanel>
final session = widget.session;
_syncTerminal(session.terminal);
_builtStatus = session.status;
+ _syncCursorLock(
+ session.readOnly && WorkspaceChrome.of(context).labelsPaneStatus,
+ );
final machineState = widget.notifier.stateOf(session.machineId);
final remote = machineState != null && !machineState.isLocalMachine;
final showComposer = _showsComposer;
@@ -2405,6 +2453,7 @@ class _TerminalPanelState extends State<TerminalPanel>
onTakeControl: _inputBlocked
? () => unawaited(_takeControl())
: null,
+ keyHints: WorkspaceChrome.of(context).showsKeyHints,
),
),
if (session.uploadProgress != null ||
@@ -2438,6 +2487,58 @@ class _TerminalPanelState extends State<TerminalPanel>
],
),
),
+ // Last, so nothing above moves when they come and go.
+ if (_cursorLocked)
+ ValueListenableBuilder<bool>(
+ // A cursor the program hid (ESC[?25l) gets no lock
+ // either, rather than one in a stray cell.
+ valueListenable: session.remoteCursorVisibility,
+ builder: (context, shown, lock) => Positioned.fill(
+ child: shown ? lock! : const SizedBox.shrink(),
+ ),
+ child: IgnorePointer(
+ child: KeyedSubtree(
+ key: const ValueKey('terminal-cursor-lock'),
+ child: CustomPaint(
+ key: _cursorLockKey,
+ painter: _CursorLockPainter(
+ source: session.terminal,
+ terminal: _laidOutTerminalView,
+ host: () =>
+ _cursorLockKey.currentContext
+ ?.findRenderObject()
+ as RenderBox?,
+ color: terminalThemeFor(
+ grid.AppTheme.palette.value,
+ terminalThemeStore.value,
+ ).foreground.withValues(alpha: .70),
+ repaint: Listenable.merge([
+ _scrollController,
+ _TerminalChanges(session.terminal),
+ ]),
+ ),
+ ),
+ ),
+ ),
+ ),
+ if (widget.notice case final notice?
+ when notice.dimsScreen) ...[
+ Positioned.fill(
+ child: IgnorePointer(
+ child: ColoredBox(
+ color: grid.AppPalette.windowBg.withValues(
+ alpha: .55,
+ ),
+ ),
+ ),
+ ),
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ child: _ControlBanner.notice(notice),
+ ),
+ ],
],
),
),
@@ -2717,6 +2818,163 @@ class _TerminalHeader extends StatelessWidget {
Widget build(BuildContext context) =>
MediaQuery.withNoTextScaling(child: Builder(builder: _buildHeader));
+ /// The header on a phone ([WorkspaceChrome.compactPaneHeaderAt]): the name
+ /// first, the pane's state in words, agent and model behind one menu, and
+ /// controls a finger can hit. Audit findings S2 and S1.
+ Widget _phoneHeader(
+ BuildContext context, {
+ required String title,
+ required TextStyle titleStyle,
+ required String identityDetail,
+ required bool renamable,
+ required TerminalNotice? status,
+ required Color statusColor,
+ required VoidCallback? statusAction,
+ required ModelStartPhase? starting,
+ required Agent? agent,
+ required bool canChangeModel,
+ }) {
+ final machine = notifier.stateOf(session.machineId);
+ final openAgentPicker = notifier.openAgentPicker;
+ final changeAgent =
+ agent != null &&
+ openAgentPicker != null &&
+ machine?.machine.isShared == false &&
+ machine?.nodeOnline != false
+ ? () => openAgentPicker(session.machineId, agent.id)
+ : null;
+ final changeModel =
+ canChangeModel && onOpenModels != null && !readOnly && !session.readOnly
+ ? pickerController?.open
+ : null;
+ return SizedBox(
+ height: kFingerTarget,
+ child: Padding(
+ padding: const EdgeInsets.only(
+ left: _stripPadding,
+ right: grid.AppDesktop.paneCloseInset,
+ ),
+ child: LayoutBuilder(
+ builder: (context, constraints) => Row(
+ children: [
+ Expanded(
+ child: Tooltip(
+ message: identityDetail,
+ waitDuration: const Duration(milliseconds: 500),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onDoubleTap: renamable
+ ? () => unawaited(
+ showAgentRenameDialog(
+ context,
+ notifier,
+ session.machineId,
+ session.agentId,
+ session.agentName,
+ ),
+ )
+ : null,
+ child: Text(
+ title,
+ key: const ValueKey('terminal-pane-title'),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: titleStyle,
+ ),
+ ),
+ ),
+ ),
+ // A state in words says what the activity mark's ⊘ would.
+ if (status == null)
+ HarnessActivityMark(
+ app: notifier,
+ machineId: session.machineId,
+ agentId: session.agentId,
+ ),
+ if (status != null || starting != null) const SizedBox(width: 8),
+ if (status != null)
+ ConstrainedBox(
+ key: const ValueKey('pane-header-status'),
+ constraints: BoxConstraints(
+ maxWidth: constraints.maxWidth * .45,
+ ),
+ // Pressable (Take control, Reconnect): a finger's height.
+ child: fingerTarget(
+ enabled: statusAction != null,
+ _PaneStatusChip(
+ status: status,
+ color: statusColor,
+ onPressed: statusAction,
+ showsIcon: false,
+ labelWhenInert: true,
+ ),
+ ),
+ )
+ else if (starting != null)
+ PaneStartingChip(phase: starting, narrow: true),
+ if (canChangeModel) _modelPicker(context, agent, menuOnly: true),
+ fingerTarget(
+ enabled: true,
+ _PaneIdentityMenuButton(
+ engine: session.engineId,
+ agentLabel: agent == null
+ ? null
+ : HarnessAgentPicker.label(agent.engine ?? ''),
+ model: agent?.gridModel ?? agent?.modelName,
+ onChangeAgent: changeAgent,
+ onChangeModel: changeModel,
+ ),
+ ),
+ if (onClose != null)
+ fingerTarget(
+ enabled: true,
+ PaneCloseButton(onPressed: onClose!),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ /// This pane's model control: the header's label, or with [menuOnly] none,
+ /// opened from elsewhere through [pickerController].
+ GridModelPicker _modelPicker(
+ BuildContext context,
+ Agent? agent, {
+ bool compact = false,
+ bool menuOnly = false,
+ }) => GridModelPicker(
+ key: ValueKey(('pane-model', session.machineId, session.agentId)),
+ paneHeader: true,
+ menuOnly: menuOnly,
+ onOpen: onOpenModels,
+ enabled: !readOnly && !session.readOnly,
+ compact: compact,
+ notifier: notifier,
+ machineId: session.machineId,
+ currentModel: agent?.gridModel,
+ subscriptionModel: agent?.modelName,
+ webSearch: agent?.gridWebSearch,
+ engineLabel: session.engineId,
+ controller: pickerController,
+ onSelected: (model) => unawaited(
+ notifier.retargetAgentToGridModel(
+ session.machineId,
+ session.agentId,
+ model.id,
+ gridName: model.grid,
+ ),
+ ),
+ onUseOwnLogin: () =>
+ unawaited(notifier.clearAgentGrid(session.machineId, session.agentId)),
+ // Discovery opens the local Models popover. Selection above
+ // continues to target this pane's existing session.
+ onRunLocalModel: () => unawaited(
+ notifier.runLocalModel(context, machineId: session.machineId),
+ ),
+ );
+
Widget _buildHeader(BuildContext context) {
TerminalFontScope.watch(context);
final titleStyle = workspaceBarTextStyle(
@@ -2772,7 +3030,16 @@ class _TerminalHeader extends StatelessWidget {
session.errorCode ??
'This stream is closed. Retained output is read only.',
),
- };
+ } ??
+ // Watched, not controlled: said in words where the host labels pane
+ // states (the web), where it was only a greyed model name.
+ (session.readOnly && WorkspaceChrome.of(context).labelsPaneStatus
+ ? terminalNotice(
+ label: 'View only',
+ icon: AppIcons.lock,
+ detail: 'You can watch this terminal. Typing is off.',
+ )
+ : null);
// A notice that carries its own way out owns the button — a machine that
// needs linking asks for its password there. Otherwise the button is the
// session's own reconnect, which a notice has always suppressed.
@@ -2827,6 +3094,24 @@ class _TerminalHeader extends StatelessWidget {
// A fork says so first: "forked from X" is the one fact about this pane
// that the folder and the branch — shared with its source — cannot tell.
final forkedFrom = agent?.forkedFrom;
+ if (WorkspaceChrome.of(context)
+ .compactPaneHeaderAt(MediaQuery.sizeOf(context).width)) {
+ return _carried(
+ _phoneHeader(
+ context,
+ title: title,
+ titleStyle: titleStyle,
+ identityDetail: identityDetail,
+ renamable: roleTitle == null,
+ status: status,
+ statusColor: color,
+ statusAction: statusAction,
+ starting: starting,
+ agent: agent,
+ canChangeModel: showModelPicker,
+ ),
+ );
+ }
final header = SizedBox(
height: compact ? 38 : 46,
child: Padding(
@@ -3069,46 +3354,10 @@ class _TerminalHeader extends StatelessWidget {
),
child: Align(
alignment: Alignment.centerLeft,
- child: Tooltip(
- message: status.detail,
- child: TextButton(
- onPressed: statusAction,
- style: TextButton.styleFrom(
- foregroundColor: color,
- disabledForegroundColor:
- AppColors.textSoft,
- minimumSize: Size.zero,
- tapTargetSize:
- MaterialTapTargetSize.shrinkWrap,
- padding: const EdgeInsets.symmetric(
- horizontal: 6,
- vertical: 4,
- ),
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(status.icon, size: 14),
- const SizedBox(width: 6),
- Flexible(
- child: Text(
- // The chip names the STATE; what
- // pressing it does is in the tooltip
- // and in `actionLabel`. "Link
- // required" that can be pressed reads
- // better than a bare verb where every
- // neighbour is a status.
- status.label,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: grid.AppType.monoLabel(
- fontWeight: FontWeight.w400,
- ),
- ),
- ),
- ],
- ),
- ),
+ child: _PaneStatusChip(
+ status: status,
+ color: color,
+ onPressed: statusAction,
),
),
)
@@ -3213,46 +3462,7 @@ class _TerminalHeader extends StatelessWidget {
)
: null,
modelPicker: showModelPicker
- ? GridModelPicker(
- key: ValueKey((
- 'pane-model',
- session.machineId,
- session.agentId,
- )),
- paneHeader: true,
- onOpen: onOpenModels,
- enabled: !readOnly && !session.readOnly,
- compact: narrow,
- notifier: notifier,
- machineId: session.machineId,
- currentModel: agent?.gridModel,
- subscriptionModel: agent?.modelName,
- webSearch: agent?.gridWebSearch,
- engineLabel: session.engineId,
- controller: pickerController,
- onSelected: (model) => unawaited(
- notifier.retargetAgentToGridModel(
- session.machineId,
- session.agentId,
- model.id,
- gridName: model.grid,
- ),
- ),
- onUseOwnLogin: () => unawaited(
- notifier.clearAgentGrid(
- session.machineId,
- session.agentId,
- ),
- ),
- // Discovery opens the local Models popover. Selection above
- // continues to target this pane's existing session.
- onRunLocalModel: () => unawaited(
- notifier.runLocalModel(
- context,
- machineId: session.machineId,
- ),
- ),
- )
+ ? _modelPicker(context, agent, compact: narrow)
: null,
details: compact || narrow
? null
@@ -3299,7 +3509,11 @@ class _TerminalHeader extends StatelessWidget {
),
),
);
- final strip = header;
+ return _carried(header);
+ }
+
+ /// [strip], carried by this pane's drag when it has one.
+ Widget _carried(Widget strip) {
final handle = paneDrag;
if (handle == null) return strip;
@@ -3328,6 +3542,236 @@ class _TerminalHeader extends StatelessWidget {
}
}
+/// A pane's state as a chip: its icon and its word, the detail in the tooltip,
+/// pressed for the way out it offers when it offers one.
+class _PaneStatusChip extends StatelessWidget {
+ const _PaneStatusChip({
+ required this.status,
+ required this.color,
+ required this.onPressed,
+ this.showsIcon = true,
+ this.labelWhenInert = false,
+ });
+
+ final TerminalNotice status;
+ final Color color;
+ final VoidCallback? onPressed;
+
+ /// False on a phone, where the word is what the room is for.
+ final bool showsIcon;
+
+ /// True on a phone: a state with nothing to press is drawn as words, not
+ /// as a disabled button a finger would try.
+ final bool labelWhenInert;
+
+ static const _padding = EdgeInsets.symmetric(horizontal: 6, vertical: 4);
+
+ @override
+ Widget build(BuildContext context) {
+ final content = Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (showsIcon) ...[
+ Icon(status.icon, size: 14),
+ const SizedBox(width: 6),
+ ],
+ Flexible(
+ child: Text(
+ // The chip names the STATE; what pressing it does is in the
+ // tooltip and in `actionLabel`. "Link required" that can be
+ // pressed reads better than a bare verb where every neighbour is
+ // a status.
+ status.label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: grid.AppType.monoLabel(fontWeight: FontWeight.w400),
+ ),
+ ),
+ ],
+ );
+ return Tooltip(
+ message: status.detail,
+ child: labelWhenInert && onPressed == null
+ ? Padding(
+ padding: _padding,
+ child: IconTheme.merge(
+ data: IconThemeData(color: AppColors.textSoft),
+ child: DefaultTextStyle.merge(
+ style: TextStyle(color: AppColors.textSoft),
+ child: content,
+ ),
+ ),
+ )
+ : TextButton(
+ onPressed: onPressed,
+ style: TextButton.styleFrom(
+ foregroundColor: color,
+ disabledForegroundColor: AppColors.textSoft,
+ minimumSize: Size.zero,
+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ padding: _padding,
+ ),
+ child: content,
+ ),
+ );
+ }
+}
+
+/// Agent and model behind one control, for a phone's header: the engine's
+/// mark, and a menu with a row for each picker the header would show.
+class _PaneIdentityMenuButton extends StatelessWidget {
+ const _PaneIdentityMenuButton({
+ required this.engine,
+ required this.agentLabel,
+ required this.model,
+ required this.onChangeAgent,
+ required this.onChangeModel,
+ });
+
+ final String? engine;
+ final String? agentLabel;
+ final String? model;
+ final VoidCallback? onChangeAgent, onChangeModel;
+
+ 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<VoidCallback>(
+ context: context,
+ // Opened by a press: no row is lit until the pointer picks one.
+ focusFirst: false,
+ position: RelativeRect.fromLTRB(
+ origin.dx,
+ origin.dy + box.size.height,
+ overlay.size.width - origin.dx - box.size.width,
+ 0,
+ ),
+ minWidth: 220,
+ maxWidth: 320,
+ children: (close) => [
+ for (final (title, detail, action) in [
+ ('Agent', agentLabel, onChangeAgent),
+ ('Model', model, onChangeModel),
+ ])
+ if (action != null)
+ paneMenuItem(
+ onTap: () => close(action),
+ child: fingerTarget(
+ enabled: true,
+ PaneMenuRow(selected: false, title: title, status: detail),
+ ),
+ ),
+ ],
+ );
+ // Run once the menu has closed and handed focus back.
+ choice?.call();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ final foreground = terminalThemeFor(
+ grid.AppTheme.palette.value,
+ terminalThemeStore.value,
+ ).foreground;
+ final enabled = onChangeAgent != null || onChangeModel != null;
+ return WorkspaceBarControl(
+ label: 'Agent and model',
+ tooltip: [?agentLabel, ?model].join(' · '),
+ foreground: foreground,
+ onPressed: enabled ? () => unawaited(_open(context)) : null,
+ builder: (context, emphasized) => SizedBox(
+ height: workspaceBarControlHeight(context),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ EngineMark(engine: engine, size: 14, enabled: enabled),
+ Icon(
+ AppIcons.chevronDown,
+ size: 12,
+ color: foreground.withValues(alpha: emphasized ? 1 : .75),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+/// A lock in the cursor's cell, for a terminal that cannot be typed into.
+class _CursorLockPainter extends CustomPainter {
+ _CursorLockPainter({
+ required this.source,
+ required this.terminal,
+ required this.host,
+ required this.color,
+ super.repaint,
+ });
+
+ final Terminal source;
+ final TerminalViewState? Function() terminal;
+ final RenderBox? Function() host;
+ final Color color;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final render = terminal()?.renderTerminal;
+ final box = host();
+ if (render == null || box == null || !render.attached) return;
+ final buffer = source.buffer;
+ final at = box.globalToLocal(
+ render.localToGlobal(
+ render.getOffset(CellOffset(buffer.cursorX, buffer.absoluteCursorY)),
+ ),
+ );
+ final cell = render.cellSize;
+ final icon = AppIcons.lock;
+ final glyph = TextPainter(
+ text: TextSpan(
+ text: String.fromCharCode(icon.codePoint),
+ style: TextStyle(
+ fontFamily: icon.fontFamily,
+ package: icon.fontPackage,
+ fontSize: cell.height * .8,
+ color: color,
+ ),
+ ),
+ textDirection: TextDirection.ltr,
+ )..layout();
+ glyph.paint(
+ canvas,
+ at +
+ Offset(
+ (cell.width - glyph.width) / 2,
+ (cell.height - glyph.height) / 2,
+ ),
+ );
+ glyph.dispose();
+ }
+
+ @override
+ bool shouldRepaint(_CursorLockPainter old) =>
+ !identical(old.source, source) || old.color != color;
+}
+
+/// The emulator's change notices as a [Listenable], to repaint by.
+class _TerminalChanges implements Listenable {
+ const _TerminalChanges(this.terminal);
+
+ final Terminal terminal;
+
+ @override
+ void addListener(VoidCallback listener) => terminal.addListener(listener);
+
+ @override
+ void removeListener(VoidCallback listener) =>
+ terminal.removeListener(listener);
+}
+
/// A domain harness's verdict on the agent's workspace, in one word or one count.
///
/// Green "Ready" is the harness's one machine fact — fab-ready, every gate passed. Red carries the
@@ -3451,12 +3895,17 @@ class _ControlBanner extends StatelessWidget {
/// person can act on. Null for the takeover band above.
final TerminalNotice? notice;
+ /// False where the host hides key hints ([WorkspaceChrome.showsKeyHints]):
+ /// the band names the click alone, and its button draws no ⏎. Audit S8.
+ final bool keyHints;
+
const _ControlBanner({
required this.busy,
required this.nudged,
required this.nudge,
required this.onTakeControl,
this.takerName,
+ this.keyHints = true,
}) : notice = null;
/// The band for a notice that offers a way out — the same strip, the same
@@ -3467,7 +3916,8 @@ class _ControlBanner extends StatelessWidget {
nudged = false,
nudge = 0,
onTakeControl = null,
- takerName = null;
+ takerName = null,
+ keyHints = true;
String get title => notice != null
? notice!.label
@@ -3480,8 +3930,14 @@ class _ControlBanner extends StatelessWidget {
String? get detail {
if (notice != null) return notice!.detail;
if (busy) return null;
- if (nudged) return 'Keys are ignored — press ⏎ to take control.';
- return 'Typing is paused. Click here or press ⏎ to take control.';
+ if (nudged) {
+ return keyHints
+ ? 'Keys are ignored — press ⏎ to take control.'
+ : 'Keys are ignored — click here to take control.';
+ }
+ return keyHints
+ ? 'Typing is paused. Click here or press ⏎ to take control.'
+ : 'Typing is paused. Click here to take control.';
}
@override
@@ -3598,7 +4054,10 @@ class _ControlBanner extends StatelessWidget {
))
: busy
? null
- : _ControlBannerButton(onPressed: onTakeControl);
+ : _ControlBannerButton(
+ onPressed: onTakeControl,
+ showReturnKey: keyHints,
+ );
final secondary = notice?.secondaryLabel;
final button = secondary == null
? primary
diff --git a/desktop/test/pane_columns_test.dart b/desktop/test/pane_columns_test.dart
new file mode 100644
index 000000000..a3b8308bc
--- /dev/null
+++ b/desktop/test/pane_columns_test.dart
@@ -0,0 +1,142 @@
+// The web's column rule (WorkspaceChrome.twoPaneColumnsBelow): a tablet's
+// grid is drawn at most two columns wide, a computer's is not, and the tab's
+// recorded layout is the same either way.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/workspace_chrome.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/widgets/pane_grid.dart';
+import 'package:harness/widgets/pane_resize_handle.dart';
+
+import 'swarm_screen_test.dart' show terminal;
+import 'swarm_state_test.dart' show createApp;
+
+AppNotifier _threePanes() {
+ final app = createApp();
+ app.machineStates['m']!.nodeOnline = true;
+ for (var i = 0; i < 3; i++) {
+ app.adoptSessionForTest(terminal('a$i', []));
+ }
+ addTearDown(app.dispose);
+ return app;
+}
+
+Future<void> _mount(
+ WidgetTester tester,
+ AppNotifier app, {
+ required Size size,
+ WorkspaceChrome? chrome,
+}) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+ final grid = PaneGrid(notifier: app, swarmMode: true);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: chrome == null
+ ? grid
+ : WorkspaceChromeScope(chrome: chrome, child: grid),
+ ),
+ );
+ await tester.pump();
+}
+
+/// How many columns the panes are drawn in: the distinct left edges.
+int _drawnColumns(WidgetTester tester, AppNotifier app) => {
+ for (final pane in app.panes)
+ tester.getTopLeft(find.byKey(ValueKey('pane-frame:${pane.id}'))).dx,
+}.length;
+
+/// What the tab records of its layout — what a split divides, what the
+/// neighbour walk reads, and what is saved.
+List<Object?> _recorded(AppNotifier app) => [
+ app.activeSwarm.arranged?.tiles,
+ app.activeSwarm.arrangedKey,
+ app.activeSwarm.gridColumns,
+ Map.of(app.activeSwarm.paneSizes),
+];
+
+void main() {
+ testWidgets('three panes on a 768 px browser are drawn in two columns', (
+ tester,
+ ) async {
+ final app = _threePanes();
+
+ await _mount(
+ tester,
+ app,
+ size: const Size(768, 1024),
+ chrome: webWorkspaceChrome(app),
+ );
+
+ expect(_drawnColumns(tester, app), 2);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a 1440 px browser keeps three columns', (tester) async {
+ final app = _threePanes();
+
+ await _mount(
+ tester,
+ app,
+ size: const Size(1440, 900),
+ chrome: webWorkspaceChrome(app),
+ );
+
+ expect(_drawnColumns(tester, app), 3);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a 768 px Desktop window keeps three columns', (tester) async {
+ final app = _threePanes();
+
+ await _mount(tester, app, size: const Size(768, 1024));
+
+ expect(_drawnColumns(tester, app), 3);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('the two-column drawing records the layout a computer does', (
+ tester,
+ ) async {
+ final desktop = _threePanes();
+ await _mount(tester, desktop, size: const Size(768, 1024));
+ final recordedOnDesktop = _recorded(desktop);
+ await tester.pumpWidget(const SizedBox());
+
+ final web = _threePanes();
+ await _mount(
+ tester,
+ web,
+ size: const Size(768, 1024),
+ chrome: webWorkspaceChrome(web),
+ );
+
+ expect(_drawnColumns(tester, web), 2);
+ expect(_recorded(web), recordedOnDesktop);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('no divider is offered while two columns stand in for three', (
+ tester,
+ ) async {
+ final desktop = _threePanes();
+ await _mount(tester, desktop, size: const Size(768, 1024));
+ expect(find.byType(PaneResizeHandle), findsWidgets);
+ await tester.pumpWidget(const SizedBox());
+
+ final web = _threePanes();
+ await _mount(
+ tester,
+ web,
+ size: const Size(768, 1024),
+ chrome: webWorkspaceChrome(web),
+ );
+
+ expect(find.byType(PaneResizeHandle), findsNothing);
+ await tester.pumpWidget(const SizedBox());
+ });
+}
diff --git a/desktop/test/pane_phone_header_test.dart b/desktop/test/pane_phone_header_test.dart
new file mode 100644
index 000000000..833d66f60
--- /dev/null
+++ b/desktop/test/pane_phone_header_test.dart
@@ -0,0 +1,266 @@
+// The pane header on a phone browser (WorkspaceChrome.compactPaneHeaderAt,
+// audit findings S2 and S1): the harness name first, its state in words,
+// agent and model behind one menu, and controls a finger can hit. A narrow
+// Desktop window keeps today's header.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/workspace_chrome.dart';
+import 'package:harness/terminal/terminal_session.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/widgets/box_chrome.dart' show kWorkspaceInset;
+import 'package:harness/widgets/pane_grid.dart';
+
+import 'support/real_fonts.dart';
+import 'swarm_state_test.dart' show createApp;
+
+const _name = 'Fix checkout flow tests';
+const _titleKey = ValueKey('terminal-pane-title');
+
+AppNotifier _app({
+ ConnectionStatus connection = ConnectionStatus.connected,
+ bool online = true,
+ bool viewOnly = false,
+ TerminalSessionStatus status = TerminalSessionStatus.controlling,
+}) {
+ final app = createApp(connected: true);
+ app.machineStates['m']!
+ ..connectionStatus = connection
+ ..nodeOnline = online;
+ app.adoptSessionForTest(
+ TerminalSession(
+ machineId: 'm',
+ agentId: 'a0',
+ agentName: _name,
+ engineId: 'claude',
+ readOnly: viewOnly,
+ send: (_, _) async => true,
+ sendBinary: (_) async => true,
+ )
+ ..status = status
+ ..streamId = 'stream-a0',
+ );
+ addTearDown(app.dispose);
+ return app;
+}
+
+/// A second computer, still connected, so an offline one keeps its pane.
+void _withSecondComputer(AppNotifier app) {
+ const machine = Machine(
+ machineId: 'm2',
+ authMode: MachineAuthMode.remote,
+ name: 'Build server',
+ );
+ app.machines = [...app.machines, machine];
+ app.machineStates['m2'] = MachineState(machine)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected;
+}
+
+Future<void> _mount(
+ WidgetTester tester,
+ AppNotifier app, {
+ WorkspaceChrome? chrome,
+ Size size = const Size(390, 844),
+ void Function(int paneId, String machineId, String agentId)? onOpenModels,
+}) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+ final grid = PaneGrid(
+ notifier: app,
+ swarmMode: true,
+ onOpenModels: onOpenModels ?? (_, _, _) {},
+ );
+ // Inset as the workspace insets its grid, so the pane is as wide as a
+ // phone's.
+ final inset = Padding(
+ padding: const EdgeInsets.symmetric(horizontal: kWorkspaceInset),
+ child: grid,
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ home: chrome == null
+ ? inset
+ : WorkspaceChromeScope(chrome: chrome, child: inset),
+ ),
+ );
+ await tester.pump();
+}
+
+/// How wide "Fix checkout flo…" is in the title's own style: sixteen
+/// characters and the ellipsis a cut name ends in.
+double _sixteenCharacters(WidgetTester tester) {
+ final style = tester.widget<Text>(find.byKey(_titleKey)).style;
+ final painter = TextPainter(
+ text: TextSpan(text: '${_name.substring(0, 16)}…', style: style),
+ textDirection: TextDirection.ltr,
+ )..layout();
+ final width = painter.width;
+ painter.dispose();
+ return width;
+}
+
+void main() {
+ // Widths are the point here: measured in real fonts, not the test font's
+ // one-em squares.
+ setUpAll(loadRealFonts);
+
+ testWidgets('at 390 the name keeps at least sixteen characters', (
+ tester,
+ ) async {
+ final app = _app(connection: ConnectionStatus.reconnecting);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ expect(
+ tester.getSize(find.byKey(_titleKey)).width,
+ greaterThanOrEqualTo(_sixteenCharacters(tester)),
+ );
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ for (final (word, app) in <(String, AppNotifier Function())>[
+ ('Connecting', () => _app(status: TerminalSessionStatus.opening)),
+ ('Reconnecting…', () => _app(connection: ConnectionStatus.reconnecting)),
+ ('Offline', () => _app(online: false)..let(_withSecondComputer)),
+ ('View only', () => _app(viewOnly: true)),
+ ]) {
+ testWidgets('at 390 "$word", which nothing here fixes, is a label', (
+ tester,
+ ) async {
+ final semantics = tester.ensureSemantics();
+ final notifier = app();
+
+ await _mount(tester, notifier, chrome: webWorkspaceChrome(notifier));
+
+ final status = find.byKey(const ValueKey('pane-header-status'));
+ expect(
+ find.descendant(of: status, matching: find.byType(ButtonStyleButton)),
+ findsNothing,
+ );
+ expect(
+ tester
+ .getSemantics(
+ find.descendant(of: status, matching: find.text(word)),
+ )
+ .flagsCollection
+ .isButton,
+ isFalse,
+ );
+ await tester.pumpWidget(const SizedBox());
+ semantics.dispose();
+ });
+ }
+
+ for (final (word, app) in <(String, AppNotifier Function())>[
+ ('Connecting', () => _app(status: TerminalSessionStatus.opening)),
+ ('Reconnecting…', () => _app(connection: ConnectionStatus.reconnecting)),
+ ('Offline', () => _app(online: false)..let(_withSecondComputer)),
+ ('View only', () => _app(viewOnly: true)),
+ ('Take control', () => _app(status: TerminalSessionStatus.takenOver)),
+ ]) {
+ testWidgets('at 390 the header says "$word" in words', (tester) async {
+ final notifier = app();
+
+ await _mount(tester, notifier, chrome: webWorkspaceChrome(notifier));
+
+ expect(
+ find.descendant(
+ of: find.byKey(const ValueKey('pane-header-status')),
+ matching: find.text(word),
+ ),
+ findsOneWidget,
+ );
+ expect(
+ tester.getSize(find.byKey(_titleKey)).width,
+ greaterThanOrEqualTo(_sixteenCharacters(tester)),
+ );
+ await tester.pumpWidget(const SizedBox());
+ });
+ }
+
+ testWidgets('agent and model share one menu that runs both pickers', (
+ tester,
+ ) async {
+ final semantics = tester.ensureSemantics();
+ final app = _app();
+ final agentPicks = <(String, String)>[];
+ app.openAgentPicker = (machine, agent) => agentPicks.add((machine, agent));
+ final modelPicks = <int>[];
+ await _mount(
+ tester,
+ app,
+ chrome: webWorkspaceChrome(app),
+ onOpenModels: (pane, _, _) => modelPicks.add(pane),
+ );
+ expect(find.bySemanticsLabel(RegExp('^Agent: ')), findsNothing);
+ expect(find.bySemanticsLabel(RegExp('^Model: ')), findsNothing);
+
+ await tester.tap(find.bySemanticsLabel('Agent and model'));
+ await tester.pump();
+ await tester.tap(find.text('Agent'));
+ await tester.pump();
+ expect(agentPicks, [('m', 'a0')]);
+
+ await tester.tap(find.bySemanticsLabel('Agent and model'));
+ await tester.pump();
+ await tester.tap(find.text('Model'));
+ await tester.pump();
+ expect(modelPicks, [app.panes.single.id]);
+
+ await tester.pumpWidget(const SizedBox());
+ semantics.dispose();
+ });
+
+ testWidgets('header controls are a finger wide on a phone', (tester) async {
+ final semantics = tester.ensureSemantics();
+ final app = _app();
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ for (final label in ['Close Pane', 'Agent and model']) {
+ final size = tester.getSize(find.bySemanticsLabel(label));
+ expect(size.width, greaterThanOrEqualTo(44), reason: label);
+ expect(size.height, greaterThanOrEqualTo(44), reason: label);
+ }
+ await tester.pumpWidget(const SizedBox());
+ semantics.dispose();
+ });
+
+ testWidgets('a status that can be pressed is a finger tall', (tester) async {
+ final app = _app(status: TerminalSessionStatus.takenOver);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ final chip = find.descendant(
+ of: find.byKey(const ValueKey('pane-header-status')),
+ matching: find.byType(TextButton),
+ );
+ expect(tester.getSize(chip).height, greaterThanOrEqualTo(44));
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a 390 px Desktop window keeps today\'s header', (tester) async {
+ final semantics = tester.ensureSemantics();
+ final app = _app();
+
+ await _mount(tester, app);
+
+ expect(find.bySemanticsLabel(RegExp('^Agent: ')), findsOneWidget);
+ expect(find.bySemanticsLabel(RegExp('^Model: ')), findsOneWidget);
+ expect(find.bySemanticsLabel('Agent and model'), findsNothing);
+ expect(tester.getSize(find.bySemanticsLabel('Close Pane')).width, 28);
+ await tester.pumpWidget(const SizedBox());
+ semantics.dispose();
+ });
+}
+
+extension<T> on T {
+ T let(void Function(T) f) {
+ f(this);
+ return this;
+ }
+}
diff --git a/desktop/test/pane_status_words_test.dart b/desktop/test/pane_status_words_test.dart
new file mode 100644
index 000000000..bb19c5290
--- /dev/null
+++ b/desktop/test/pane_status_words_test.dart
@@ -0,0 +1,297 @@
+// Pane states in words on the web (WorkspaceChrome.labelsPaneStatus, audit
+// findings S3 and S4): a computer that is connecting or reconnecting, and a
+// terminal this browser may only watch. Desktop keeps today's pane.
+
+import 'dart:convert';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/terminal/terminal_binary.dart';
+import 'package:harness/terminal/terminal_session.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/state/workspace_chrome.dart';
+import 'package:harness/widgets/pane_grid.dart';
+import 'package:xterm/xterm.dart';
+
+import 'swarm_state_test.dart' show createApp;
+
+const _streamId = '00112233-4455-6677-8899-aabbccddeeff';
+
+/// Agent a0's terminal past `terminal_ready` and its first keyframe, so it
+/// takes keys; what it sends lands in [wire].
+Future<TerminalSession> _liveSession(
+ List<TerminalBinaryFrame> wire, {
+ bool viewOnly = false,
+}) async {
+ Object? openRequestId;
+ final session = TerminalSession(
+ machineId: 'm',
+ agentId: 'a0',
+ agentName: 'Fix checkout flow tests',
+ engineId: 'codex',
+ readOnly: viewOnly,
+ send: (type, payload) async {
+ if (type == 'terminal_open') openRequestId = payload['requestId'];
+ return true;
+ },
+ sendBinary: (frame) async {
+ wire.add(frame);
+ return true;
+ },
+ );
+ await session.open(initialCols: 80, initialRows: 24);
+ await session.handleFrame('terminal_ready', {
+ 'requestId': openRequestId,
+ 'protocolVersion': 3,
+ 'streamId': _streamId,
+ 'agentId': 'a0',
+ });
+ await session.handleBinary(
+ TerminalBinaryFrame(
+ kind: TerminalBinaryKind.keyframe,
+ streamId: _streamId,
+ seq: 0,
+ bytes: Uint8List.fromList(utf8.encode(r'$ ')),
+ compressed: false,
+ cols: 80,
+ rows: 24,
+ ),
+ );
+ return session;
+}
+
+String _typed(List<TerminalBinaryFrame> wire) => utf8.decode([
+ for (final frame in wire)
+ if (frame.kind == TerminalBinaryKind.input) ...frame.bytes,
+]);
+
+Future<AppNotifier> _app(
+ WidgetTester tester,
+ List<TerminalBinaryFrame> wire, {
+ ConnectionStatus status = ConnectionStatus.connected,
+ bool viewOnly = false,
+}) async {
+ final app = createApp(connected: true);
+ app.machineStates['m']!.connectionStatus = status;
+ final session = await _liveSession(wire, viewOnly: viewOnly);
+ app.adoptSessionForTest(session);
+ return app;
+}
+
+Future<void> _mount(
+ WidgetTester tester,
+ AppNotifier app, {
+ WorkspaceChrome? chrome,
+}) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(1440, 900);
+ addTearDown(tester.view.reset);
+ final grid = PaneGrid(notifier: app, swarmMode: true);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: chrome == null
+ ? grid
+ : WorkspaceChromeScope(chrome: chrome, child: grid),
+ ),
+ );
+ await tester.pump();
+}
+
+/// Takes the pane down and ends the app with its session, whose clocks would
+/// otherwise outlive the test.
+Future<void> _unmount(WidgetTester tester, AppNotifier app) async {
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+}
+
+const _cursorLock = ValueKey('terminal-cursor-lock');
+
+Terminal _terminal(AppNotifier app) => app.panes.single.session!.terminal;
+
+TerminalView _view(WidgetTester tester) =>
+ tester.widget<TerminalView>(find.byType(TerminalView));
+
+void main() {
+ testWidgets('a reconnecting computer\'s pane says so on the web', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], status: ConnectionStatus.reconnecting);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ expect(find.text('Reconnecting…'), findsWidgets);
+ expect(find.textContaining('Keys typed now are not sent'), findsOneWidget);
+ expect(_view(tester).readOnly, isTrue);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('a connecting computer\'s pane says so on the web', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], status: ConnectionStatus.connecting);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ expect(find.text('Connecting…'), findsWidgets);
+ expect(_view(tester).readOnly, isTrue);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('Desktop keeps a reconnecting pane as it is today', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], status: ConnectionStatus.reconnecting);
+
+ await _mount(tester, app);
+
+ expect(find.text('Reconnecting…'), findsNothing);
+ expect(find.textContaining('Keys typed now'), findsNothing);
+ expect(_view(tester).readOnly, isFalse);
+ await _unmount(tester, app);
+ });
+
+ testWidgets(
+ 'keys typed while reconnecting are dropped, later ones are sent',
+ (tester) async {
+ final wire = <TerminalBinaryFrame>[];
+ final app = await _app(
+ tester,
+ wire,
+ status: ConnectionStatus.reconnecting,
+ );
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+ await tester.tap(find.byType(TerminalView));
+ // Past the terminal's double-tap window.
+ await tester.pump(const Duration(milliseconds: 350));
+
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump(const Duration(milliseconds: 50));
+ expect(_typed(wire), isEmpty);
+
+ app.machineStates['m']!.connectionStatus = ConnectionStatus.connected;
+ app.notifyListeners();
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump(const Duration(milliseconds: 50));
+
+ expect(_typed(wire), '\r');
+ await _unmount(tester, app);
+ },
+ );
+
+ testWidgets('a view-only terminal says so on the web', (tester) async {
+ final app = await _app(tester, [], viewOnly: true);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ expect(find.text('View only'), findsOneWidget);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('Desktop adds no words to a view-only terminal', (tester) async {
+ final app = await _app(tester, [], viewOnly: true);
+
+ await _mount(tester, app);
+
+ expect(find.text('View only'), findsNothing);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('a view-only terminal on the web shows a lock, not a cursor', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], viewOnly: true);
+
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+
+ expect(find.byKey(_cursorLock), findsOneWidget);
+ expect(_terminal(app).cursorVisibleMode, isFalse);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('Desktop keeps a view-only terminal\'s cursor', (tester) async {
+ final app = await _app(tester, [], viewOnly: true);
+
+ await _mount(tester, app);
+
+ expect(find.byKey(_cursorLock), findsNothing);
+ expect(_terminal(app).cursorVisibleMode, isTrue);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('the lock goes once the terminal can be typed into again', (
+ tester,
+ ) async {
+ final app = await _app(tester, []);
+ final session = app.panes.single.session!
+ ..stageInputContext(null, watchOnly: true);
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+ expect(find.byKey(_cursorLock), findsOneWidget);
+
+ // Control comes back as a stream does: reopened, then live.
+ session
+ ..stageInputContext(null)
+ ..status = TerminalSessionStatus.opening
+ ..notifyListeners();
+ await tester.pump();
+ session
+ ..status = TerminalSessionStatus.controlling
+ ..notifyListeners();
+ await tester.pump();
+
+ expect(find.byKey(_cursorLock), findsNothing);
+ expect(_terminal(app).cursorVisibleMode, isTrue);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('a new keyframe does not bring the cursor back under the lock', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], viewOnly: true);
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+ expect(_terminal(app).cursorVisibleMode, isFalse);
+
+ // A resync: the whole screen again, on a new emulator.
+ await app.panes.single.session!.handleBinary(_frame(1, r'$ ls'));
+ await tester.pump();
+
+ expect(find.byKey(_cursorLock), findsOneWidget);
+ expect(_terminal(app).cursorVisibleMode, isFalse);
+ await _unmount(tester, app);
+ });
+
+ testWidgets('no lock where the program has hidden its cursor', (
+ tester,
+ ) async {
+ final app = await _app(tester, [], viewOnly: true);
+ await _mount(tester, app, chrome: webWorkspaceChrome(app));
+ expect(find.byKey(_cursorLock), findsOneWidget);
+
+ await app.panes.single.session!.handleBinary(
+ _frame(1, '\x1b[?25l', kind: TerminalBinaryKind.output),
+ );
+ await tester.pump();
+
+ expect(find.byKey(_cursorLock), findsNothing);
+ await _unmount(tester, app);
+ });
+}
+
+/// A frame of agent a0's stream: a whole screen ([TerminalBinaryKind.keyframe])
+/// or more output.
+TerminalBinaryFrame _frame(
+ int seq,
+ String text, {
+ TerminalBinaryKind kind = TerminalBinaryKind.keyframe,
+}) => TerminalBinaryFrame(
+ kind: kind,
+ streamId: _streamId,
+ seq: seq,
+ bytes: Uint8List.fromList(utf8.encode(text)),
+ compressed: false,
+ cols: 80,
+ rows: 24,
+);
diff --git a/desktop/test/terminal_control_banner_hints_test.dart b/desktop/test/terminal_control_banner_hints_test.dart
new file mode 100644
index 000000000..2cea6b2f5
--- /dev/null
+++ b/desktop/test/terminal_control_banner_hints_test.dart
@@ -0,0 +1,130 @@
+// The Take control band where the host hides key hints (the web,
+// WorkspaceChrome.showsKeyHints false; audit finding S8): it names the click,
+// not a key a touch screen does not have. Desktop keeps its ⏎.
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/shared/theme/app_icons.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/workspace_chrome.dart';
+import 'package:harness/terminal/terminal_session.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/widgets/terminal_panel.dart';
+
+import 'swarm_state_test.dart' show createApp;
+
+final _button = find.widgetWithText(FilledButton, 'Take control');
+
+Future<(AppNotifier, TerminalSession)> _takenOver(
+ WidgetTester tester, {
+ required bool web,
+}) async {
+ final app = createApp();
+ app.stateOf('m')!
+ ..nodeOnline = true
+ ..terminalCapabilityAvailable = true;
+ final session =
+ TerminalSession(
+ machineId: 'm',
+ agentId: 'a0',
+ agentName: 'Session a0',
+ engineId: 'codex',
+ send: (_, _) async => true,
+ sendBinary: (_) async => true,
+ )
+ ..status = TerminalSessionStatus.controlling
+ ..streamId = 'stream-a0';
+ app.adoptSessionForTest(session);
+ final panel = TerminalPanel(
+ notifier: app,
+ session: session,
+ focused: true,
+ onToggleComposer: () {},
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SizedBox(
+ width: 900,
+ height: 400,
+ child: web
+ ? WorkspaceChromeScope(
+ chrome: webWorkspaceChrome(app),
+ child: panel,
+ )
+ : panel,
+ ),
+ ),
+ ),
+ );
+ await tester.pump();
+ session.handleFrame('terminal_closed', {
+ 'streamId': 'stream-a0',
+ 'code': 'TERMINAL_TAKEN_OVER',
+ 'reason': 'Another client connected to this terminal.',
+ });
+ await tester.pump();
+ return (app, session);
+}
+
+Future<void> _finish(WidgetTester tester, AppNotifier app) async {
+ await tester.pump(const Duration(milliseconds: 500));
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+}
+
+void main() {
+ testWidgets('on the web the band asks for a click and draws no key', (
+ tester,
+ ) async {
+ final (app, _) = await _takenOver(tester, web: true);
+
+ expect(
+ find.text('Typing is paused. Click here to take control.'),
+ findsOneWidget,
+ );
+ expect(find.textContaining('⏎'), findsNothing);
+ expect(
+ find.descendant(
+ of: _button,
+ matching: find.byIcon(AppIcons.cornerDownLeft),
+ ),
+ findsNothing,
+ );
+ await _finish(tester, app);
+ });
+
+ testWidgets('on the web a stray key is answered without naming a key', (
+ tester,
+ ) async {
+ final (app, _) = await _takenOver(tester, web: true);
+
+ await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
+ await tester.pump();
+
+ expect(
+ find.text('Keys are ignored — click here to take control.'),
+ findsOneWidget,
+ );
+ expect(find.textContaining('⏎'), findsNothing);
+ await _finish(tester, app);
+ });
+
+ testWidgets('Desktop keeps ⏎ on the band and on its button', (tester) async {
+ final (app, _) = await _takenOver(tester, web: false);
+
+ expect(
+ find.text('Typing is paused. Click here or press ⏎ to take control.'),
+ findsOneWidget,
+ );
+ expect(
+ find.descendant(
+ of: _button,
+ matching: find.byIcon(AppIcons.cornerDownLeft),
+ ),
+ findsOneWidget,
+ );
+ await _finish(tester, app);
+ });
+}
diff --git a/desktop/test/workspace_chrome_scope_test.dart b/desktop/test/workspace_chrome_scope_test.dart
index 70621123f..9a192d3f3 100644
--- a/desktop/test/workspace_chrome_scope_test.dart
+++ b/desktop/test/workspace_chrome_scope_test.dart
@@ -85,6 +85,7 @@ void main() {
expect(chrome.labelsPaneStatus, isFalse);
expect(chrome.compactPaneHeader, isFalse);
expect(chrome.compactPaneHeaderAt(320), isFalse);
+ expect(chrome.maxPaneColumnsAt(768), isNull);
await tester.pumpWidget(const SizedBox.shrink());
});
@@ -119,6 +120,27 @@ void main() {
expect(chrome.compactPaneHeaderAt(1440), isFalse);
});
+ test(
+ 'the web grid is two columns at most below 1000 px, any number above',
+ () {
+ final app = createApp();
+ addTearDown(app.dispose);
+ final chrome = webWorkspaceChrome(app);
+
+ expect(chrome.maxPaneColumnsAt(768), 2);
+ expect(chrome.maxPaneColumnsAt(999), 2);
+ expect(chrome.maxPaneColumnsAt(1000), isNull);
+ expect(chrome.maxPaneColumnsAt(1440), isNull);
+ },
+ );
+
+ test('a host chrome that names no column rule keeps every column', () {
+ final chrome = _hostChrome(flags: true);
+
+ expect(chrome.maxPaneColumnsAt(320), isNull);
+ expect(chrome.maxPaneColumnsAt(768), isNull);
+ });
+
testWidgets('a new chrome reaches the workspace without remounting it', (
tester,
) async {
diff --git a/desktop/tool/web_ux/flows/pane.mjs b/desktop/tool/web_ux/flows/pane.mjs
index 546116171..3ad8200a2 100644
--- a/desktop/tool/web_ux/flows/pane.mjs
+++ b/desktop/tool/web_ux/flows/pane.mjs
@@ -11,6 +11,10 @@ export const FLOWS = [
{ name: 'opening', scenario: 'opening' },
{ name: 'taken-over', scenario: 'taken-over' },
{ name: 'terminal-error', scenario: 'terminal-error' },
- { name: 'agent-picker', scenario: 'workspace', steps: [['click', 'Agent: ']] },
- { name: 'model-picker', scenario: 'workspace', steps: [['click', 'Model: ']] },
+ // A computer's header names agent and model; a phone's puts both behind one menu.
+ { name: 'agent-picker', scenario: 'workspace', only: 'wide', steps: [['click', 'Agent: ']] },
+ { name: 'model-picker', scenario: 'workspace', only: 'wide', steps: [['click', 'Model: ']] },
+ // Group 3's own: three panes (two columns on a tablet), and the phone's Agent and model menu.
+ { name: 'pane-three', scenario: 'pane-three' },
+ { name: 'agent-model-menu', scenario: 'workspace-one', only: 'compact', steps: [['exact', 'Agent and model']] },
];
diff --git a/desktop/tool/web_ux/scenarios/pane.dart b/desktop/tool/web_ux/scenarios/pane.dart
index a5192c2c6..c3c84d4af 100644
--- a/desktop/tool/web_ux/scenarios/pane.dart
+++ b/desktop/tool/web_ux/scenarios/pane.dart
@@ -7,36 +7,78 @@ library;
import 'package:harness/core/models.dart';
import 'package:harness/terminal/terminal_session.dart';
+import '../../../test/support/web_ux_app.dart';
import '../../web_ux_seed.dart';
import 'scenario.dart';
+/// The harness the pane header is measured by (plan ruling 7): a name long
+/// enough that a phone has to choose what to cut.
+const _measuredName = 'Fix checkout flow tests';
+
+/// [app] with its first harness renamed to [_measuredName].
+WebUxApp _measured(WebUxApp app) {
+ final machine = app.machineStates['m1']!;
+ final first = machine.agents.first;
+ machine.agents = [
+ first.copyWith(name: _measuredName),
+ ...machine.agents.skip(1),
+ ];
+ for (final pane in app.panes) {
+ if (pane.agentId == first.id) pane.session?.agentName = _measuredName;
+ }
+ return app;
+}
+
+/// [count] panes on one computer, the first named [_measuredName].
+WebUxApp _panes(
+ int count, {
+ ConnectionStatus status = ConnectionStatus.connected,
+ bool online = true,
+ bool readOnly = false,
+ TerminalSessionStatus session = TerminalSessionStatus.controlling,
+ bool secondComputer = false,
+}) {
+ final app = signedIn();
+ if (secondComputer) app.addMachine('m2', 'Build server');
+ return _measured(
+ withPanes(
+ app,
+ count,
+ status: status,
+ online: online,
+ readOnly: readOnly,
+ session: session,
+ ),
+ );
+}
+
final Map<String, WebUxScenario> paneScenarios = {
- 'workspace-one': WebUxScenario(() => withPanes(signedIn(), 1)),
+ 'workspace-one': WebUxScenario(() => _panes(1)),
+ // Three panes: two columns on a tablet, today's grid on a computer.
+ 'pane-three': WebUxScenario(() => _panes(3)),
'connecting': WebUxScenario(
- () => withPanes(signedIn(), 1, status: ConnectionStatus.connecting),
+ () => _panes(1, status: ConnectionStatus.connecting),
),
'reconnecting': WebUxScenario(
- () => withPanes(signedIn(), 1, status: ConnectionStatus.reconnecting),
+ () => _panes(1, status: ConnectionStatus.reconnecting),
),
// Offline while another computer stays connected, so the pane shows.
'offline': WebUxScenario(
- () => withPanes(
- signedIn()..addMachine('m2', 'Build server'),
+ () => _panes(
1,
status: ConnectionStatus.disconnected,
online: false,
+ secondComputer: true,
),
),
- 'view-only': WebUxScenario(
- () => withPanes(signedIn(), 1, readOnly: true),
- ),
+ 'view-only': WebUxScenario(() => _panes(1, readOnly: true)),
'opening': WebUxScenario(
- () => withPanes(signedIn(), 1, session: TerminalSessionStatus.opening),
+ () => _panes(1, session: TerminalSessionStatus.opening),
),
'taken-over': WebUxScenario(
- () => withPanes(signedIn(), 1, session: TerminalSessionStatus.takenOver),
+ () => _panes(1, session: TerminalSessionStatus.takenOver),
),
'terminal-error': WebUxScenario(
- () => withPanes(signedIn(), 1, session: TerminalSessionStatus.error),
+ () => _panes(1, session: TerminalSessionStatus.error),
),
};