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(web): implement web store banner for mobile browsers and update app frame handling

Dev jacobe12869860961
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.md
index dbedd1236..0696a842d 100644
--- a/desktop/CLAUDE.md
+++ b/desktop/CLAUDE.md
@@ -119,6 +119,13 @@ without touching zoom or the synced layout, so the same desk keeps its grid on a
arrangement (`Swarm.arranged`), because that is what a split divides: without it the menu's Split pane could never run on a phone. Do not change desktop behavior for the
web, and do not copy shared screens into `lib/web/` — add a seam instead.
+A browser on a phone or tablet (iOS, Android by `defaultTargetPlatform`, whatever the window's width) gets a bar over
+every screen, sign-in and shared harnesses included, sending it to the Harness app in its store
+(`web/shell/web_store_banner.dart`). It is the app's frame — `startHarness(frame:)`, which `main.dart` takes from the
+same conditional import as the workspace; native builds pass the app through. Closing it is remembered on that
+origin, and the on-screen keyboard hides it. It sits above the Navigator, so nothing in it may need an Overlay (no
+tooltips), and it keeps one tree shape shown or not so the app below is never remounted.
+
`kViewerMode` is true on the web:
the browser owns its OAuth session, peer links, and end-to-end relay encryption.
`viewer/browser_login.dart` validates the same-tab callback against the backend's
diff --git a/desktop/lib/app_shell.dart b/desktop/lib/app_shell.dart
index 48ce8a8c3..8033e92ea 100644
--- a/desktop/lib/app_shell.dart
+++ b/desktop/lib/app_shell.dart
@@ -47,6 +47,10 @@ import 'viewer/viewer_page.dart';
/// entry points disagree about; everything below is shared.
typedef AuthenticatedScreenBuilder = Widget Function(AppNotifier app);
+/// What a host draws around every screen of the app, sign-in included. The
+/// desktop draws nothing; a browser build stands its store bar over the app.
+typedef AppFrameBuilder = Widget Function(Widget app);
+
/// Everything both entry points do before their first frame: file logs, the
/// crash log, the keyboard config, the saved appearance, and the native window
/// where there is one.
@@ -59,6 +63,9 @@ typedef AuthenticatedScreenBuilder = Widget Function(AppNotifier app);
Future<void> startHarness({
required AuthenticatedScreenBuilder authenticatedScreen,
+ /// See [AppFrameBuilder]; none leaves the app unframed.
+ AppFrameBuilder? frame,
+
/// A viewer build's second wire to each machine (see
/// [TerminalTransportPlugin]); the desktop passes none.
TerminalTransportPluginFactory? transportPlugins,
@@ -89,6 +96,7 @@ Future<void> startHarness({
child: HarnessApp(
keymap: keymap,
authenticatedScreen: authenticatedScreen,
+ frame: frame,
),
),
);
@@ -98,9 +106,15 @@ Future<void> startHarness({
}
class HarnessApp extends StatelessWidget {
- const HarnessApp({super.key, this.keymap, required this.authenticatedScreen});
+ const HarnessApp({
+ super.key,
+ this.keymap,
+ required this.authenticatedScreen,
+ this.frame,
+ });
final AppKeymap? keymap;
final AuthenticatedScreenBuilder authenticatedScreen;
+ final AppFrameBuilder? frame;
@override
Widget build(BuildContext context) {
@@ -137,14 +151,15 @@ class HarnessApp extends StatelessWidget {
),
// Desktop forms respect the platform's text size. Fixed-grid terminal
// surfaces own their no-scaling boundary alongside terminal zoom.
- builder: (context, child) => _GridTokenScope(
- child: keymap == null
- ? child ?? const SizedBox.shrink()
- : KeymapProvider(
- keymap: keymap!,
- child: child ?? const SizedBox.shrink(),
- ),
- ),
+ builder: (context, child) {
+ final app = child ?? const SizedBox.shrink();
+ final framed = frame?.call(app) ?? app;
+ return _GridTokenScope(
+ child: keymap == null
+ ? framed
+ : KeymapProvider(keymap: keymap!, child: framed),
+ );
+ },
home: StatsLifecycle(
child: RootShell(authenticatedScreen: authenticatedScreen),
),
@@ -359,7 +374,8 @@ class _RootShellState extends ConsumerState<RootShell>
app.status != AppStatus.checkingEnvironment &&
app.status != AppStatus.preparingEnvironment)
UpdateNotice(notifier: app),
- if (app.newDevices.isNotEmpty && app.status == AppStatus.authenticated)
+ if (app.newDevices.isNotEmpty &&
+ app.status == AppStatus.authenticated)
NewDeviceNotice(notifier: app),
Expanded(child: framed),
],
diff --git a/desktop/lib/desktop_workspace.dart b/desktop/lib/desktop_workspace.dart
index 097d589cf..8320c2502 100644
--- a/desktop/lib/desktop_workspace.dart
+++ b/desktop/lib/desktop_workspace.dart
@@ -7,3 +7,6 @@ import 'state/app_state.dart';
/// `web/web_entry.dart` in its place (the conditional import in `main.dart`),
/// so native code never reaches `lib/web/`.
Widget authenticatedWorkspace(AppNotifier app) => SwarmScreen(notifier: app);
+
+/// A native build draws nothing around its screens.
+Widget appFrame(Widget app) => app;
diff --git a/desktop/lib/main.dart b/desktop/lib/main.dart
index 9d02c06ac..cdcea7f77 100644
--- a/desktop/lib/main.dart
+++ b/desktop/lib/main.dart
@@ -4,9 +4,10 @@ import 'desktop_workspace.dart'
/// Harness: a swarm of terminal panes in one window. Everything before the
/// first frame, and every screen up to sign-in, is [startHarness]; only the
-/// signed-in workspace differs, picked at compile time — a browser build gets
-/// the mouse-first `lib/web/` composition, native builds never compile it.
+/// signed-in workspace and the frame around the app differ, picked at compile
+/// time — a browser build gets the mouse-first `lib/web/` composition under
+/// its store bar, native builds never compile it.
/// `../mobile` mounts a phone shell into its own vendored copy of
/// [startHarness] rather than depending on this package.
Future<void> main() =>
- startHarness(authenticatedScreen: authenticatedWorkspace);
+ startHarness(authenticatedScreen: authenticatedWorkspace, frame: appFrame);
diff --git a/desktop/lib/web/shell/web_store_banner.dart b/desktop/lib/web/shell/web_store_banner.dart
new file mode 100644
index 000000000..780dae2f1
--- /dev/null
+++ b/desktop/lib/web/shell/web_store_banner.dart
@@ -0,0 +1,182 @@
+import 'dart:async';
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+
+import '../../core/harness_file_store.dart';
+import '../../core/local_key_value_store.dart';
+import '../../shared/theme/app_icons.dart';
+import '../../shared/theme/app_theme.dart' as grid;
+import '../../shared/theme/app_type.dart';
+import '../../widgets/web_download_button.dart' show openInNewTab;
+import 'web_hidden_under_keyboard.dart';
+
+final _appStore = Uri.parse(
+ 'https://apps.apple.com/us/app/harness-like-a-boss/id6812264068',
+);
+final _googlePlay = Uri.parse(
+ 'https://play.google.com/store/apps/details?id=ai.autonomous.harness.android',
+);
+
+/// The Harness app's store page for the phone or tablet this browser runs on;
+/// null on a computer, which has no store app to send anyone to.
+Uri? webStoreLink([TargetPlatform? platform]) =>
+ switch (platform ?? defaultTargetPlatform) {
+ TargetPlatform.iOS => _appStore,
+ TargetPlatform.android => _googlePlay,
+ _ => null,
+ };
+
+/// Everything a browser build draws, under a bar that sends a phone's browser
+/// to the Harness app in its store. It stands over every screen — sign-in, a
+/// shared harness, the workspace — until it is closed, and that is remembered.
+/// A computer's browser gets [child] alone.
+class WebStoreFrame extends StatefulWidget {
+ const WebStoreFrame({
+ super.key,
+ required this.child,
+ this.storage,
+ this.open = openInNewTab,
+ });
+
+ final Widget child;
+
+ /// Where a closed bar is remembered; the browser's own store when absent.
+ final LocalKeyValueStore? storage;
+
+ /// How the store page is opened; tests pass a recorder.
+ final Future<bool> Function(Uri uri) open;
+
+ @override
+ State<WebStoreFrame> createState() => _WebStoreFrameState();
+}
+
+class _WebStoreFrameState extends State<WebStoreFrame> {
+ static const _dismissedKey = 'web_store_banner_dismissed';
+
+ late final Uri? _link = webStoreLink();
+ late final LocalKeyValueStore _storage =
+ widget.storage ?? HarnessFileStore.shared;
+
+ /// Unknown until the saved answer is read: the bar never flashes up only to
+ /// leave for someone who closed it before.
+ bool? _dismissed;
+
+ @override
+ void initState() {
+ super.initState();
+ if (_link != null) unawaited(_restore());
+ }
+
+ Future<void> _restore() async {
+ // A browser that refuses storage still gets the bar, every visit.
+ final saved = await _storage.read(_dismissedKey).catchError((_) => null);
+ if (mounted) setState(() => _dismissed = saved != null);
+ }
+
+ void _dismiss() {
+ setState(() => _dismissed = true);
+ unawaited(_storage.write(_dismissedKey, '1').catchError((_) {}));
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final link = _link;
+ final shown = link != null && _dismissed == false;
+ final media = MediaQuery.of(context);
+ // One shape whether or not the bar shows: the app below must never be
+ // remounted by a bar coming or going.
+ return Column(
+ children: [
+ if (shown)
+ WebHiddenUnderKeyboard(
+ child: _WebStoreBar(
+ onOpen: () => unawaited(widget.open(link)),
+ onDismiss: _dismiss,
+ ),
+ ),
+ Expanded(
+ key: const ValueKey('web-store-frame-app'),
+ child: MediaQuery(
+ // The bar took the top inset; the app below starts under it.
+ data: shown ? media.removePadding(removeTop: true) : media,
+ child: widget.child,
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+/// Close, what the app is for, and the way to it.
+class _WebStoreBar extends StatelessWidget {
+ const _WebStoreBar({required this.onOpen, required this.onDismiss});
+
+ final VoidCallback onOpen;
+ final VoidCallback onDismiss;
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ return Material(
+ key: const ValueKey('web-store-banner'),
+ color: grid.AppPalette.swarmTabBar,
+ child: SafeArea(
+ bottom: false,
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ border: Border(bottom: BorderSide(color: grid.AppPalette.divider)),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(4, 8, 12, 8),
+ child: Row(
+ children: [
+ // No tooltip: this bar sits above the app's overlay.
+ Semantics(
+ button: true,
+ label: 'Close',
+ child: IconButton(
+ key: const ValueKey('web-store-banner-close'),
+ onPressed: onDismiss,
+ icon: const Icon(AppIcons.close, size: 16),
+ color: grid.AppPalette.textSecondary,
+ ),
+ ),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ 'Harness',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppType.label(
+ color: grid.AppPalette.textPrimary,
+ ),
+ ),
+ Text(
+ 'Run your fleet from your phone',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppType.caption(
+ color: grid.AppPalette.textSecondary,
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: 12),
+ FilledButton(
+ key: const ValueKey('web-store-banner-open'),
+ onPressed: onOpen,
+ child: const Text('Get the app'),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/desktop/lib/web/tabs/web_tab_menu.dart b/desktop/lib/web/tabs/web_tab_menu.dart
index 51560f751..bc11cc59f 100644
--- a/desktop/lib/web/tabs/web_tab_menu.dart
+++ b/desktop/lib/web/tabs/web_tab_menu.dart
@@ -51,6 +51,11 @@ String webPaneTitle(AppNotifier app, TerminalPane pane) {
return pane.isWeb ? '$name · viewer' : name;
}
+/// What a row says about its harness or tab. Idle says nothing: it is the
+/// resting state, and a column of it only hides the rows that are not.
+String? _statusLabel(HarnessActivity? activity) =>
+ activity == HarnessActivity.idle ? null : activity?.label;
+
/// 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(
@@ -101,11 +106,13 @@ List<Widget> webTabMenuRows(
content: PaneMenuRow(
selected: pane.id == shown,
title: webPaneTitle(app, pane),
- status: harnessActivity(
- app,
- pane.machineId,
- (pane.isWeb ? pane.ownerAgentId : pane.agentId) ?? '',
- )?.label,
+ status: _statusLabel(
+ harnessActivity(
+ app,
+ pane.machineId,
+ (pane.isWeb ? pane.ownerAgentId : pane.agentId) ?? '',
+ ),
+ ),
),
),
],
@@ -119,7 +126,7 @@ List<Widget> webTabMenuRows(
content: PaneMenuRow(
selected: tab.id == app.activeSwarmId,
title: '${index + 1}:${names[tab.id] ?? tab.name}',
- status: tabActivity(app, tab)?.label,
+ status: _statusLabel(tabActivity(app, tab)),
),
),
// New tabs are the `+` beside the switcher, as on desktop.
diff --git a/desktop/lib/web/web_entry.dart b/desktop/lib/web/web_entry.dart
index 223dc73ab..ffe37c873 100644
--- a/desktop/lib/web/web_entry.dart
+++ b/desktop/lib/web/web_entry.dart
@@ -1,9 +1,14 @@
import 'package:flutter/widgets.dart';
import '../state/app_state.dart';
+import 'shell/web_store_banner.dart';
import 'shell/web_workspace.dart';
/// The signed-in screen of a browser build, chosen over
/// `desktop_workspace.dart` by the conditional import in `main.dart`: the
/// shared workspace, composed for a mouse.
Widget authenticatedWorkspace(AppNotifier app) => WebWorkspace(app: app);
+
+/// What a browser build draws around every screen: on a phone, the bar that
+/// sends it to the Harness app in its store.
+Widget appFrame(Widget app) => WebStoreFrame(child: app);
diff --git a/desktop/test/web_store_banner_test.dart b/desktop/test/web_store_banner_test.dart
new file mode 100644
index 000000000..14cb0d163
--- /dev/null
+++ b/desktop/test/web_store_banner_test.dart
@@ -0,0 +1,147 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/local_key_value_store.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/web/shell/web_store_banner.dart';
+
+class _MemoryStore implements LocalKeyValueStore {
+ final values = <String, String>{};
+
+ @override
+ Future<String?> read(String key) async => values[key];
+
+ @override
+ Future<void> write(String key, String value) async => values[key] = value;
+
+ @override
+ Future<void> delete(String key) async => values.remove(key);
+}
+
+const _banner = ValueKey('web-store-banner');
+const _app = ValueKey('the-app');
+
+void main() {
+ Future<List<Uri>> mount(
+ WidgetTester tester,
+ TargetPlatform platform,
+ _MemoryStore store,
+ ) async {
+ debugDefaultTargetPlatformOverride = platform;
+ final opened = <Uri>[];
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(390, 844);
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ builder: (context, child) => WebStoreFrame(
+ storage: store,
+ open: (uri) async {
+ opened.add(uri);
+ return true;
+ },
+ child: child!,
+ ),
+ home: const _CountedApp(key: _app),
+ ),
+ );
+ await tester.pump();
+ return opened;
+ }
+
+ tearDown(() => debugDefaultTargetPlatformOverride = null);
+
+ test('a phone has a store page; a computer has none', () {
+ expect(webStoreLink(TargetPlatform.iOS)!.host, 'apps.apple.com');
+ expect(
+ webStoreLink(TargetPlatform.android)!.queryParameters['id'],
+ 'ai.autonomous.harness.android',
+ );
+ for (final computer in [
+ TargetPlatform.macOS,
+ TargetPlatform.linux,
+ TargetPlatform.windows,
+ ]) {
+ expect(webStoreLink(computer), isNull, reason: '$computer');
+ }
+ });
+
+ for (final platform in [TargetPlatform.iOS, TargetPlatform.android]) {
+ testWidgets('$platform: the bar opens its own store and fits a phone', (
+ tester,
+ ) async {
+ final opened = await mount(tester, platform, _MemoryStore());
+ expect(find.byKey(_banner), findsOneWidget);
+ // The bar is above the app, never over it.
+ expect(
+ tester.getRect(find.byKey(_banner)).bottom,
+ lessThanOrEqualTo(tester.getRect(find.byKey(_app)).top),
+ );
+ await tester.tap(find.byKey(const ValueKey('web-store-banner-open')));
+ expect(opened, [webStoreLink(platform)]);
+ expect(tester.takeException(), isNull);
+ debugDefaultTargetPlatformOverride = null;
+ });
+ }
+
+ testWidgets('closing it is remembered, and never remounts the app', (
+ tester,
+ ) async {
+ final store = _MemoryStore();
+ await mount(tester, TargetPlatform.iOS, store);
+ final mounted = _CountedApp.mounts;
+ await tester.tap(find.byKey(const ValueKey('web-store-banner-close')));
+ await tester.pump();
+ expect(find.byKey(_banner), findsNothing);
+ expect(_CountedApp.mounts, mounted);
+ expect(tester.getRect(find.byKey(_app)).top, 0);
+
+ // The next visit reads the answer before it draws a bar.
+ await tester.pumpWidget(const SizedBox.shrink());
+ await mount(tester, TargetPlatform.iOS, store);
+ expect(find.byKey(_banner), findsNothing);
+ debugDefaultTargetPlatformOverride = null;
+ });
+
+ testWidgets('the on-screen keyboard takes the bar away', (tester) async {
+ await mount(tester, TargetPlatform.android, _MemoryStore());
+ final mounted = _CountedApp.mounts;
+ tester.view.viewInsets = const FakeViewPadding(bottom: 300);
+ await tester.pump();
+ expect(find.byKey(_banner), findsNothing);
+ tester.view.resetViewInsets();
+ await tester.pump();
+ expect(find.byKey(_banner), findsOneWidget);
+ expect(_CountedApp.mounts, mounted);
+ debugDefaultTargetPlatformOverride = null;
+ });
+
+ testWidgets('a computer never sees the bar', (tester) async {
+ await mount(tester, TargetPlatform.macOS, _MemoryStore());
+ expect(find.byKey(_banner), findsNothing);
+ expect(tester.getRect(find.byKey(_app)).top, 0);
+ debugDefaultTargetPlatformOverride = null;
+ });
+}
+
+/// Stands in for the app below the bar, counting how often it is mounted.
+class _CountedApp extends StatefulWidget {
+ const _CountedApp({super.key});
+
+ static int mounts = 0;
+
+ @override
+ State<_CountedApp> createState() => _CountedAppState();
+}
+
+class _CountedAppState extends State<_CountedApp> {
+ @override
+ void initState() {
+ super.initState();
+ _CountedApp.mounts++;
+ }
+
+ @override
+ Widget build(BuildContext context) => const SizedBox.expand();
+}
diff --git a/desktop/test/web_tab_switcher_test.dart b/desktop/test/web_tab_switcher_test.dart
index d6c1a6e64..2f7333f3e 100644
--- a/desktop/test/web_tab_switcher_test.dart
+++ b/desktop/test/web_tab_switcher_test.dart
@@ -10,6 +10,7 @@ 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/harness_activity.dart';
import 'package:harness/state/terminal_pane.dart';
import 'package:harness/web/shell/web_chrome.dart';
import 'package:harness/widgets/web_download_button.dart';
@@ -146,6 +147,9 @@ void main() {
await capture(tester, 'web-phone-solo-pane');
await openSwitcher(tester);
+ // Resting harnesses say nothing: a column of "Idle" is only noise.
+ expect(harnessActivity(app, 'm', 'a0'), HarnessActivity.idle);
+ expect(find.text(HarnessActivity.idle.label), findsNothing);
await capture(tester, 'web-phone-harness-menu');
await tester.tap(find.byKey(const ValueKey('web-pane:101')));
await tester.pump(const Duration(milliseconds: 300));