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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(mobile): Focus title and the sample's end card no longer overflow at large text
dee4f91a8112e79
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dartindex 623c3f9e3..7be215d85 100644--- a/mobile/lib/phone/terminal_page.dart+++ b/mobile/lib/phone/terminal_page.dart@@ -3771,33 +3771,52 @@ class _SampleEndCard extends StatelessWidget {child: SafeArea(child: Padding(padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- const Spacer(),- TtyText('That’s Harness.', size: 26, weight: FontWeight.w600),- const SizedBox(height: 20),- tick('watched a harness work'),- tick('answered its question'),- tick('started $started'),- const SizedBox(height: 6),- TtyText('3 passed', size: TtySize.meta, color: tty.green),- const SizedBox(height: 24),- Text(- 'Now do it on your own code. The real ones run on your '- 'computer; this phone is the remote.',- style: tty.style(size: TtySize.row),- ),- const Spacer(),- TtyPrimaryButton(label: 'Set up my computer', onPressed: onSetUp),- const SizedBox(height: 4),- Center(- child: TtyTextButton(- label: 'Keep playing',- onPressed: onKeepPlaying,+ // ⚠️ **Scrolls when it does not fit.** Centred by its spacers on a screen with room, but+ // a small phone at a large text size has less room than the card has words — as a+ // fixed column it overflowed, and the one button that leads anywhere went off the foot.+ child: LayoutBuilder(+ builder: (context, box) => SingleChildScrollView(+ child: ConstrainedBox(+ constraints: BoxConstraints(minHeight: box.maxHeight),+ child: IntrinsicHeight(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ const Spacer(),+ TtyText(+ 'That’s Harness.',+ size: 26,+ weight: FontWeight.w600,+ ),+ const SizedBox(height: 20),+ tick('watched a harness work'),+ tick('answered its question'),+ tick('started $started'),+ const SizedBox(height: 6),+ TtyText('3 passed', size: TtySize.meta, color: tty.green),+ const SizedBox(height: 24),+ Text(+ 'Now do it on your own code. The real ones run on your '+ 'computer; this phone is the remote.',+ style: tty.style(size: TtySize.row),+ ),+ const Spacer(),+ TtyPrimaryButton(+ label: 'Set up my computer',+ onPressed: onSetUp,+ ),+ const SizedBox(height: 4),+ Center(+ child: TtyTextButton(+ label: 'Keep playing',+ onPressed: onKeepPlaying,+ ),+ ),+ ],+ ),),),- ],+ ),),),),diff --git a/mobile/lib/phone/terminal_title.dart b/mobile/lib/phone/terminal_title.dartindex 6f12bcd28..5dff25803 100644--- a/mobile/lib/phone/terminal_title.dart+++ b/mobile/lib/phone/terminal_title.dart@@ -84,8 +84,11 @@ class TerminalTitle extends StatelessWidget {child: DecoratedBox(// No rule under it: the output fades out beneath instead — see the gradient below.decoration: BoxDecoration(color: tty.ground),- child: SizedBox(- height: height,+ // ⚠️ **At least four rows, not exactly four.** The rows are the terminal's, which the+ // text scale does not touch, and the three lines are the app's type, which it does: at+ // Settings ▸ Text size's largest the lines outgrew a fixed box and overflowed it.+ child: ConstrainedBox(+ constraints: BoxConstraints(minHeight: height),child: Padding(padding: const EdgeInsets.symmetric(horizontal: Tty.origin),child: Row(diff --git a/mobile/test/phone_edge/edge_fixture.dart b/mobile/test/phone_edge/edge_fixture.dartnew file mode 100644index 000000000..22ca65cf0--- /dev/null+++ b/mobile/test/phone_edge/edge_fixture.dart@@ -0,0 +1,326 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/demo/sample_mode.dart';+import 'package:harness_mobile/phone/voice_input_controller.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;+import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/terminal/terminal_session.dart';+import 'package:harness_mobile/ws/ws_conn.dart';++import '../agent_pager_fixture.dart' show goLive;+import '../voice_fakes.dart';++/// The phone screens under the edge cases a real phone meets: a small one and a large one, the+/// text scales a person can set, both brightnesses, names nobody would design for.+///+/// Everything here is a fake — no daemon, no network, no disk outside memory. See the rules in+/// `mobile/README.md` and the incident they came from.++/// iPhone SE (2nd/3rd gen), in logical pixels.+const smallPhone = Size(375, 667);++/// iPhone 15 Pro Max, in logical pixels.+const largePhone = Size(430, 932);++const phones = {'SE': smallPhone, 'Pro Max': largePhone};++/// The scales the brief asks for, and the largest the app itself can reach: `HarnessApp` pins the+/// text scale to Settings ▸ Text size, 11–19pt over a 14pt default.+const textScales = [1.0, 19 / 14, 1.5, 2.0];++/// A name nobody designs for.+const longName =+ 'refactor-the-authentication-middleware-so-that-sessions-survive-a-relaunch-of-the-app';+const emojiName = '🚀 ship it 👩💻🔥 fix 🐛 in 🇯🇵 build';+const rtlName = 'مساعد البرمجة الذكي للمشروع الكبير';+const longMachine = 'Ada’s MacBook Pro (16-inch, 2024) in the upstairs office';+const longProject =+ 'an-extraordinarily-long-project-folder-name-that-keeps-going';+const longBranch =+ 'feature/authentication-middleware-session-survival-across-relaunch';++/// Claude Code's permission dialog, as it lands in the pane: three answers, the first and last of+/// which Focus puts beside the mic.+const permissionDialog =+ '\r\n\x1b[2m────────────────────────────────────────────\x1b[0m\r\n'+ ' \x1b[1mBash command\x1b[0m\r\n'+ ' rm -rf build/ && flutter build ios\r\n'+ ' Do you want to proceed?\r\n'+ ' \x1b[36m❯ 1. Yes\x1b[0m\r\n'+ " 2. Yes, and don't ask again for rm commands\r\n"+ ' 3. No, and tell Claude what to do differently\r\n'+ '\r\n'+ ' \x1b[2mEsc to cancel · Enter to confirm\x1b[0m';++/// Sample mode around a screen, without the sample's own runtime.+class FakeSample implements SampleSession {+ FakeSample(this.notifier);++ @override+ final AppNotifier notifier;++ @override+ bool endCardSeen = false;++ final List<String?> left = [];++ @override+ void leave([String? result]) => left.add(result);+}++/// A machine the fake conn answers every request for, and accepts every frame.+class EdgeConn extends WsConn {+ EdgeConn()+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'm',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );++ final List<(String, Map<String, dynamic>)> frames = [];+ final List<String> requests = [];++ @override+ Future<bool> sendTerminalFrame(+ String type,+ Map<String, dynamic> payload,+ ) async {+ frames.add((type, payload));+ return true;+ }++ @override+ Future<Map<String, dynamic>> request(+ String type, {+ Map<String, dynamic> payload = const {},+ Duration timeout = const Duration(seconds: 20),+ }) async {+ requests.add(type);+ return {};+ }+}++Agent edgeAgent(+ String id, {+ String? name,+ String engine = 'claude',+ String project = 'web',+ String? branch = 'main',+ int minutesAgo = 5,+}) => Agent(+ id: id,+ name: name ?? id,+ engine: engine,+ sessionId: 'session-$id',+ status: 'active',+ project: AgentProject(name: project, cwd: '/code/$project', branch: branch),+ updatedAt: DateTime.now().subtract(Duration(minutes: minutesAgo)),+ terminalAvailable: true,+);++/// An account with one machine, `m`, running [agents] — as a phone sees it when [online], or as it+/// sees a machine that has gone away when not.+AppNotifier edgeApp({+ List<Agent>? agents,+ String machineName = 'studio',+ bool online = true,+ AgentLoadStatus load = AgentLoadStatus.loaded,+ EdgeConn? conn,+ bool noMachines = false,+}) {+ final app = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ connectionForTest: (_) => conn ?? EdgeConn(),+ );+ if (noMachines) return app;+ final machine = Machine(+ machineId: 'm',+ authMode: MachineAuthMode.remote,+ name: machineName,+ );+ app.machines = [machine];+ app.machineStates['m'] = MachineState(machine)+ ..nodeOnline = online+ ..connectionStatus = online+ ? ConnectionStatus.connected+ : ConnectionStatus.disconnected+ ..agentLoadStatus = load+ ..terminalCapabilityAvailable = true+ ..agents = agents ?? [edgeAgent('a')];+ return app;+}++/// [count] agents, `a0`…, the first named [firstName] when given.+List<Agent> manyAgents(int count, {String? firstName}) => [+ for (var i = 0; i < count; i++)+ edgeAgent(+ 'a$i',+ name: i == 0 && firstName != null ? firstName : 'agent-$i',+ minutesAgo: i,+ ),+];++/// A live terminal for [agentId] on `m`: adopted as the pane and given its first keyframe, so the+/// page draws a screen rather than its skeleton.+Future<TerminalSession> liveTerminal(+ AppNotifier app,+ String agentId, {+ String? name,+}) async {+ final session = TerminalSession(+ machineId: 'm',+ agentId: agentId,+ agentName: name ?? agentId,+ engineId: 'claude',+ send: (_, _) async => true,+ sendBinary: (_) async => true,+ );+ app.adoptSessionForTest(session);+ await goLive(session);+ session.status = TerminalSessionStatus.controlling;+ return session;+}++/// A voice controller on fakes, disposed with the test.+({VoiceInputController voice, FakeVoiceRecorder recorder, FakeTranscriber stt})+edgeVoice() {+ final language = ValueNotifier('en');+ final recorder = FakeVoiceRecorder();+ final stt = FakeTranscriber();+ final voice = VoiceInputController(+ transcriber: stt.call,+ recorder: recorder,+ language: language,+ );+ addTearDown(() {+ voice.dispose();+ language.dispose();+ });+ return (voice: voice, recorder: recorder, stt: stt);+}++/// Sizes the test's window as [size] logical pixels on a 3x phone, with an iPhone's status bar and+/// home indicator — reset when the test ends.+void setPhone(WidgetTester tester, Size size) {+ tester.view.physicalSize = size * 3;+ tester.view.devicePixelRatio = 3;+ tester.view.padding = const FakeViewPadding(top: 47 * 3, bottom: 34 * 3);+ tester.view.viewPadding = const FakeViewPadding(top: 47 * 3, bottom: 34 * 3);+ addTearDown(tester.view.reset);+}++/// Sets the app's brightness for the test, and puts the dark it ships with back afterwards.+void setBrightness(Brightness brightness) {+ final before = grid.AppTheme.brightness.value;+ grid.AppTheme.brightness.value = brightness;+ addTearDown(() => grid.AppTheme.brightness.value = before);+}++/// [home] as the phone app mounts a screen: its theme, and the text scale set in the builder the+/// way `HarnessApp` sets it.+Widget phoneApp(+ Widget home, {+ double textScale = 1.0,+ Brightness brightness = Brightness.dark,+ List<NavigatorObserver> observers = const [],+}) => grid.BrightnessScope(+ child: MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: brightness),+ navigatorObservers: observers,+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(context)+ .copyWith(textScaler: TextScaler.linear(textScale)),+ child: child!,+ ),+ home: home,+ ),+);++/// Every error Flutter reports while [body] runs — an overflow, an exception in a build — rather+/// than only the first, which is all `takeException` keeps.+Future<List<String>> collectErrors(Future<void> Function() body) async {+ final errors = <String>[];+ final previous = FlutterError.onError;+ FlutterError.onError = (details) {+ final text = details.exceptionAsString().split('\n').first;+ errors.add(text);+ };+ try {+ await body();+ } finally {+ FlutterError.onError = previous;+ }+ return errors;+}++/// Runs [pump] at every phone, scale and brightness, and fails listing every combination that+/// reported an error — so one run shows the whole picture rather than the first overflow.+Future<void> expectNoLayoutErrors(+ WidgetTester tester,+ Future<void> Function(double scale, Brightness brightness) pump, {+ Map<String, Size> sizes = phones,+ List<double> scales = textScales,+ List<Brightness> brightnesses = const [Brightness.dark, Brightness.light],+}) async {+ final failures = <String>[];+ for (final MapEntry(key: phone, value: size) in sizes.entries) {+ for (final scale in scales) {+ for (final brightness in brightnesses) {+ setPhone(tester, size);+ final before = grid.AppTheme.brightness.value;+ grid.AppTheme.brightness.value = brightness;+ try {+ final errors = await collectErrors(() => pump(scale, brightness));+ for (final error in errors.toSet()) {+ failures.add(+ '$phone ×${scale.toStringAsFixed(2)} ${brightness.name}: $error',+ );+ }+ } finally {+ grid.AppTheme.brightness.value = before;+ }+ await tester.pumpWidget(const SizedBox());+ await tester.pump(const Duration(seconds: 1));+ }+ }+ }+ expect(failures, isEmpty, reason: failures.join('\n'));+}++/// Takes the screen down and runs its clocks out, so no timer outlives the test.+Future<void> unmount(WidgetTester tester) async {+ await tester.pumpWidget(const SizedBox());+ await tester.pump(const Duration(seconds: 30));+}++/// Pumps a few frames of [duration] each — enough for an entrance to finish without+/// `pumpAndSettle`, which a breathing skeleton or a spinner would never let return.+Future<void> frames(+ WidgetTester tester, {+ int count = 4,+ Duration duration = const Duration(milliseconds: 150),+}) async {+ for (var i = 0; i < count; i++) {+ await tester.pump(duration);+ }+}++/// Resolves [future] inside the test's fake clock.+Future<T> settle<T>(WidgetTester tester, Future<T> future) async {+ T? value;+ unawaited(future.then((v) => value = v));+ await tester.pump();+ return value as T;+}diff --git a/mobile/test/phone_edge/focus_layout_test.dart b/mobile/test/phone_edge/focus_layout_test.dartnew file mode 100644index 000000000..b1d1f5956--- /dev/null+++ b/mobile/test/phone_edge/focus_layout_test.dart@@ -0,0 +1,213 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/demo/sample_mode.dart';+import 'package:harness_mobile/phone/terminal_page.dart';+import 'package:harness_mobile/phone/voice_input_controller.dart';+import 'package:harness_mobile/phone/voice_mic_face.dart';+import 'package:harness_mobile/state/app_state.dart';+import 'package:xterm/xterm.dart';++import 'edge_fixture.dart';++/// Focus — one agent's terminal, full screen — laid out at every phone, scale and brightness the+/// phone meets, with the names that break layouts. None may report an overflow.+void main() {+ Future<void> pumpFocus(+ WidgetTester tester,+ AppNotifier app,+ double scale,+ Brightness brightness, {+ String agentId = 'a',+ }) async {+ final voice = edgeVoice().voice;+ await tester.pumpWidget(+ phoneApp(+ TerminalPage(+ notifier: app,+ machineId: 'm',+ agentId: agentId,+ voice: voice,+ ),+ textScale: scale,+ brightness: brightness,+ ),+ );+ await frames(tester);+ }++ for (final (label, name) in [+ ('a long name', longName),+ ('an emoji name', emojiName),+ ('a right-to-left name', rtlName),+ ]) {+ testWidgets('a live agent with $label', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(+ machineName: longMachine,+ agents: [+ edgeAgent(+ 'a',+ name: name,+ project: longProject,+ branch: longBranch,+ ),+ ],+ );+ addTearDown(app.dispose);+ await liveTerminal(app, 'a', name: name);+ await pumpFocus(tester, app, scale, brightness);+ });+ });+ }++ testWidgets('an agent among 200, several of them asking', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: manyAgents(200, firstName: longName));+ addTearDown(app.dispose);+ await liveTerminal(app, 'a0');+ await pumpFocus(tester, app, scale, brightness, agentId: 'a0');+ });+ });++ testWidgets('attaching: no terminal yet', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('a', name: longName)]);+ addTearDown(app.dispose);+ await pumpFocus(tester, app, scale, brightness);+ });+ });++ testWidgets('the agent is gone', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('other')]);+ addTearDown(app.dispose);+ app.stateOf('m')!.agentsFromCache = false;+ await pumpFocus(tester, app, scale, brightness);+ });+ });++ testWidgets('a question open, with its keys beside the mic', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('a', name: longName)]);+ addTearDown(app.dispose);+ final session = await liveTerminal(app, 'a');+ session.terminal.write(permissionDialog);+ await pumpFocus(tester, app, scale, brightness);+ expect(find.bySemanticsLabel(RegExp('^Answer 1')), findsOneWidget);+ });+ });++ testWidgets('the keyboard up, with the pane\'s own keys on the strip', (+ tester,+ ) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('a', name: emojiName)]);+ addTearDown(app.dispose);+ final session = await liveTerminal(app, 'a');+ session.terminal.write(+ '\r\n ⏵⏵ accept edits on (shift+tab to cycle)\r\n',+ );+ await pumpFocus(tester, app, scale, brightness);+ await tester.tap(find.byType(TerminalView));+ await tester.pump();+ tester.view.viewInsets = const FakeViewPadding(bottom: 336 * 3);+ await frames(tester);+ expect(find.byKey(const ValueKey('terminal-key-esc')), findsOneWidget);+ tester.view.viewInsets = FakeViewPadding.zero;+ await frames(tester);+ });+ });++ testWidgets('recording, with what was heard on the line above the mic', (+ tester,+ ) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('a', name: rtlName)]);+ addTearDown(app.dispose);+ await liveTerminal(app, 'a');+ final voice = edgeVoice().voice;+ await tester.pumpWidget(+ phoneApp(+ TerminalPage(+ notifier: app,+ machineId: 'm',+ agentId: 'a',+ voice: voice,+ ),+ textScale: scale,+ brightness: brightness,+ ),+ );+ await frames(tester);+ await tester.tap(find.byType(VoiceMicCore));+ await frames(tester);+ expect(voice.status, VoiceInputStatus.listening);+ voice.clear();+ await frames(tester);+ });+ });++ testWidgets('the title\'s menu, for an agent with every name long', (+ tester,+ ) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(+ machineName: longMachine,+ agents: [+ edgeAgent(+ 'a',+ name: longName,+ project: longProject,+ branch: longBranch,+ ),+ ],+ );+ addTearDown(app.dispose);+ await liveTerminal(app, 'a');+ await pumpFocus(tester, app, scale, brightness);+ await tester.tap(find.byKey(const ValueKey('terminal-title')));+ await frames(tester);+ expect(find.text('Rename…'), findsOneWidget);+ });+ });++ testWidgets('the sample\'s end card', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(agents: [edgeAgent('sample-new-1', name: longName)]);+ addTearDown(app.dispose);+ await liveTerminal(app, 'sample-new-1');+ final voice = edgeVoice().voice;+ await tester.pumpWidget(+ phoneApp(+ SampleMode(+ session: FakeSample(app),+ child: TerminalPage(+ notifier: app,+ machineId: 'm',+ agentId: 'sample-new-1',+ voice: voice,+ ),+ ),+ textScale: scale,+ brightness: brightness,+ ),+ );+ await frames(tester);+ await tester.pump(const Duration(seconds: 9));+ await frames(tester);+ expect(find.text('That’s Harness.'), findsOneWidget);+ });+ });++ testWidgets('the machine is offline', (tester) async {+ await expectNoLayoutErrors(tester, (scale, brightness) async {+ final app = edgeApp(+ online: false,+ machineName: longMachine,+ agents: [edgeAgent('a', name: longName)],+ );+ addTearDown(app.dispose);+ await pumpFocus(tester, app, scale, brightness);+ });+ });+}