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
feat(mobile): add machine name to terminal header and implement TerminalPlaceLine
Dev jacobe5224a224cf7
diff --git a/mobile/lib/phone/terminal_header.dart b/mobile/lib/phone/terminal_header.dartindex bca50887d..a1c622067 100644--- a/mobile/lib/phone/terminal_header.dart+++ b/mobile/lib/phone/terminal_header.dart@@ -9,13 +9,14 @@ import 'package:harness_mobile/widgets/engine_identity.dart';import 'phone_status.dart';import 'status_pill.dart';+import 'terminal_place_line.dart';/// The terminal page's own header: whose terminal this is, in two lines, with/// the page's controls at the right end.////// ```-/// [mark●] agent-3 ⋯-/// autonomous-harness ⑂ main+/// [mark●] Fix login redirect ⋯+/// ▭ MacBookPro2021.local ▢ autonomous-harness ⑂ main/// ```////// ⚠️ **The connection state is the dot on the engine mark, not a word.** It@@ -38,12 +39,17 @@ class TerminalHeader extends StatelessWidget {super.key,required this.agent,required this.status,+ this.machineName,this.trailing = const [],});/// The agent this terminal belongs to. Null while it is still loading.final Agent? agent;+ /// The machine it runs on, drawn first on the second line. Null while that+ /// machine is not known yet.+ final String? machineName;+/// The session's state, drawn as the dot on the engine mark.final PhoneSummary status;@@ -90,7 +96,9 @@ class TerminalHeader extends StatelessWidget {ring: AppPalette.windowBg,),const SizedBox(width: 11),- Expanded(child: _Identity(agent: agent)),+ Expanded(+ child: _Identity(agent: agent, machineName: machineName),+ ),...trailing,],),@@ -328,28 +336,28 @@ class _GlintPainter extends CustomPainter {!identical(old.travel, travel);}-/// The two lines: *agent*, then *folder ⑂ branch*.-///-/// On the second line each name takes only the width it needs, and only the-/// overflow is shared out — see [_PlaceLine]. The folder is the one kept whole-/// where the two cannot both fit.+/// The two lines: *agent*, then *machine · folder ⑂ branch*.////// ⚠️ **The desktop's pane header, word for word.** The name is-/// [Agent.displayName], the folder [AgentProject.label] — the repository, not a-/// worktree's made-up folder — and the branch [AgentProject.shownBranch], so a-/// harness reads the same in both.+/// [Agent.displayName], then the machine it runs on — which the desktop leaves+/// out only for its own computer, and a phone is never that — the folder+/// [AgentProject.label], the repository rather than a worktree's made-up folder,+/// and the branch [AgentProject.shownBranch]. See [TerminalPlaceLine] for how+/// the three share the width.class _Identity extends StatelessWidget {- const _Identity({required this.agent});+ const _Identity({required this.agent, required this.machineName});final Agent? agent;+ final String? machineName;@overrideWidget build(BuildContext context) {AppTheme.watch(context);final agent = this.agent;final project = agent?.project;- final branch = project?.shownBranch;- final hasPlace = project != null || branch != null;+ final machineName = this.machineName;+ final hasPlace =+ project != null || (machineName != null && machineName.isNotEmpty);return Column(mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.start,@@ -367,9 +375,10 @@ class _Identity extends StatelessWidget {),if (hasPlace) ...[const SizedBox(height: 2),- _PlaceLine(+ TerminalPlaceLine(+ machine: machineName,folder: project?.label,- branch: branch,+ branch: project?.shownBranch,style: _placeStyle,),],@@ -385,143 +394,6 @@ class _Identity extends StatelessWidget {);}-/// The second line: *folder ⑂ branch*, each name given the width it asks for.-///-/// ⚠️ **A `flex` here would ellipsis a name with the room to spare beside it.**-/// Two `Flexible`s split the line in their own fixed ratio whatever they hold,-/// so a short folder hands its slack back to the empty end of the row rather-/// than to the branch, and `worktree-command-box` is cut next to a gap. This-/// lays both out at their natural width and shortens them only when the two-/// together overrun the line.-///-/// ⚠️ **The folder is the one kept whole.** It is what tells two of an owner's-/// agents apart; a branch is read to its end far less often, so the overflow-/// comes off the branch first and the folder only gives way once the branch is-/// down to its own floor.-class _PlaceLine extends StatelessWidget {- const _PlaceLine({- required this.folder,- required this.branch,- required this.style,- });-- /// Null leaves the folder out, and the branch then has the whole line.- final String? folder;-- /// Null leaves the branch and its mark out.- final String? branch;-- final TextStyle style;-- /// What a shortened branch is never cut below, so it keeps enough characters- /// to be told from its neighbours rather than becoming a bare `…`.- static const double _branchFloor = 54;-- /// The gap left of the branch mark, and the one between mark and name.- static const double _gapBeforeMark = 8;- static const double _gapAfterMark = 3;- static const double _markSize = 12;-- @override- Widget build(BuildContext context) {- final folder = this.folder;- final branch = this.branch;- if (branch == null) {- if (folder == null) return const SizedBox.shrink();- return Text(- folder,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: style,- );- }-- final mark = Icon(- LucideIcons.gitBranch300,- size: _markSize,- color: AppPalette.textFaint,- );- final branchText = Text(- branch,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: style,- );-- if (folder == null) {- return Row(- children: [- mark,- const SizedBox(width: _gapAfterMark),- Flexible(child: branchText),- ],- );- }-- return LayoutBuilder(- builder: (context, constraints) {- final line = constraints.maxWidth;- // The mark and its two gaps are spent before either name gets a say.- final free = math.max(- 0.0,- line - _markSize - _gapBeforeMark - _gapAfterMark,- );- final folderWanted = _measure(context, folder, line);- final branchWanted = _measure(context, branch, line);-- final double folderWidth;- if (folderWanted + branchWanted <= free) {- // Both fit whole. The folder is laid out at its own width so the- // slack falls at the end of the line, not between the two names.- folderWidth = folderWanted;- } else {- // The branch gives way first: it is left whatever the folder does- // not want, but never less than its floor — and never more than it- // wants, so a short branch beside a long folder still hands its- // slack back to the folder.- final forBranch = math.min(- branchWanted,- math.max(_branchFloor, free - folderWanted),- );- folderWidth = math.max(0.0, free - forBranch);- }-- return Row(- children: [- SizedBox(- width: math.min(folderWidth, free),- child: Text(- folder,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: style,- ),- ),- const SizedBox(width: _gapBeforeMark),- mark,- const SizedBox(width: _gapAfterMark),- Flexible(child: branchText),- ],- );- },- );- }-- /// How wide [text] wants to be on one line, capped at [limit] so a very long- /// name does not measure out to something the arithmetic cannot use.- double _measure(BuildContext context, String text, double limit) {- final painter = TextPainter(- text: TextSpan(text: text, style: style),- maxLines: 1,- textDirection: Directionality.of(context),- textScaler: MediaQuery.textScalerOf(context),- )..layout();- final width = painter.width;- painter.dispose();- return math.min(width, limit);- }-}-/// Where an agent runs, as the `⋯` sheet shows it under the agent's name, each/// part behind its icon: the machine on a line of its own, then the folder with/// its parent — `~/…/autonomous-harness/mobile` — and the branch side by side,diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dartindex 5099faed3..f0c61f0dd 100644--- a/mobile/lib/phone/terminal_page.dart+++ b/mobile/lib/phone/terminal_page.dart@@ -1463,6 +1463,7 @@ class _TerminalPageState extends State<TerminalPage>TerminalHeader(agent: agent,status: headerStatus,+ machineName: machine?.machine.displayName,trailing: [// Read-only is a state to get OUT of, so its way// out is a labelled button in the header ratherdiff --git a/mobile/lib/phone/terminal_place_line.dart b/mobile/lib/phone/terminal_place_line.dartnew file mode 100644index 000000000..b5ac29fdd--- /dev/null+++ b/mobile/lib/phone/terminal_place_line.dart@@ -0,0 +1,134 @@+import 'dart:math' as math;++import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import 'package:harness_mobile/shared/theme/app_theme.dart';++/// The header's second line: *machine · folder ⑂ branch*, the desktop pane+/// header's order (`PromptContextView`), each behind its mark.+///+/// Each name is laid out at the width it asks for, and only the overflow is+/// shared out — see [placeWidths].+///+/// ⚠️ **A `flex` here would ellipsis a name with the room to spare beside it.**+/// `Flexible`s split the line in their own fixed ratio whatever they hold, so a+/// short folder hands its slack back to the empty end of the row rather than to+/// the branch, and `worktree-command-box` is cut next to a gap.+class TerminalPlaceLine extends StatelessWidget {+ const TerminalPlaceLine({+ super.key,+ required this.machine,+ required this.folder,+ required this.branch,+ required this.style,+ });++ /// Null or empty leaves that part, and its mark, out.+ final String? machine, folder, branch;++ final TextStyle style;++ static const double _markSize = 12;+ static const double _gapAfterMark = 3;+ static const double _gapBetween = 8;++ @override+ Widget build(BuildContext context) {+ AppTheme.watch(context);+ final places = [+ if (machine case final text? when text.isNotEmpty)+ (icon: LucideIcons.monitor300, text: text, givesWay: 1),+ if (folder case final text? when text.isNotEmpty)+ (icon: LucideIcons.folder300, text: text, givesWay: 2),+ if (branch case final text? when text.isNotEmpty)+ (icon: LucideIcons.gitBranch300, text: text, givesWay: 0),+ ];+ if (places.isEmpty) return const SizedBox.shrink();+ return LayoutBuilder(+ builder: (context, constraints) {+ final line = constraints.maxWidth;+ // The marks and the gaps are spent before any name gets a say.+ final free = math.max(+ 0.0,+ line -+ places.length * (_markSize + _gapAfterMark) -+ (places.length - 1) * _gapBetween,+ );+ final widths = placeWidths(+ wanted: [+ for (final place in places) _measure(context, place.text, line),+ ],+ givesWay: [for (final place in places) place.givesWay],+ free: free,+ );+ return Row(+ children: [+ for (final (i, place) in places.indexed) ...[+ if (i > 0) const SizedBox(width: _gapBetween),+ Icon(place.icon, size: _markSize, color: AppPalette.textFaint),+ const SizedBox(width: _gapAfterMark),+ SizedBox(+ width: widths[i],+ child: Text(+ place.text,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: style,+ ),+ ),+ ],+ ],+ );+ },+ );+ }++ /// How wide [text] wants to be on one line, capped at [limit] so a very long+ /// name does not measure out to something the arithmetic cannot use.+ double _measure(BuildContext context, String text, double limit) {+ final painter = TextPainter(+ text: TextSpan(text: text, style: style),+ maxLines: 1,+ textDirection: Directionality.of(context),+ textScaler: MediaQuery.textScalerOf(context),+ )..layout();+ final width = painter.width;+ painter.dispose();+ return math.min(width, limit);+ }+}++/// What a name is never cut below while another can still give, so it keeps+/// enough characters to be told from its neighbours rather than becoming `…`.+const double kPlaceFloor = 54;++/// The widths [wanted] get on a line with [free] room: whole where they fit,+/// and otherwise cut in [givesWay] order — lowest first — each down to+/// [kPlaceFloor] before the next is touched, and below the floors only once+/// every name is at its own.+///+/// ⚠️ **The branch gives way first, then the machine; the folder is the one+/// kept whole.** The folder is what tells two of an owner's agents apart; the+/// machine is one of a handful, recognisable from its first letters, and a+/// branch is read to its end least often of all.+List<double> placeWidths({+ required List<double> wanted,+ required List<int> givesWay,+ required double free,+}) {+ final widths = [...wanted];+ var over = wanted.fold(0.0, (sum, width) => sum + width) - free;+ final order = [for (var i = 0; i < wanted.length; i++) i]+ ..sort((a, b) => givesWay[a].compareTo(givesWay[b]));+ for (final floor in [kPlaceFloor, 0.0]) {+ for (final i in order) {+ if (over <= 0) return widths;+ final give = math.min(over, widths[i] - math.min(floor, widths[i]));+ if (give <= 0) continue;+ widths[i] -= give;+ over -= give;+ }+ }+ return widths;+}diff --git a/mobile/test/terminal_header_test.dart b/mobile/test/terminal_header_test.dartindex 5e3347136..4ab6fb464 100644--- a/mobile/test/terminal_header_test.dart+++ b/mobile/test/terminal_header_test.dart@@ -4,6 +4,7 @@ import 'package:harness_mobile/core/models.dart';import 'package:harness_mobile/phone/phone_status.dart';import 'package:harness_mobile/phone/status_pill.dart';import 'package:harness_mobile/phone/terminal_header.dart';+import 'package:harness_mobile/phone/terminal_place_line.dart';/// The terminal's top bar: *agent* over *folder ⑂ branch*, with the/// connection state as a dot on the engine mark.@@ -34,6 +35,7 @@ void main() {body: TerminalHeader(agent: Agent.fromJson({'id': 'a', 'engine': 'claude', ...wire}),status: (label: 'Live', tone: PhoneTone.good),+ machineName: 'MacBookPro2021.local',),),),@@ -50,8 +52,18 @@ void main() {});expect(find.text('api'), findsOneWidget);- expect(find.text('autonomous-harness'), findsOneWidget);- expect(find.text('feat/mobile-ios-android'), findsOneWidget);+ // The desktop's order: the machine, the folder, the branch.+ final place = [+ for (final text in tester.widgetList<Text>(find.byType(Text))) text.data,+ ];+ expect(+ place,+ containsAllInOrder([+ 'MacBookPro2021.local',+ 'autonomous-harness',+ 'feat/mobile-ios-android',+ ]),+ );// No word for the state — the dot says it, and its tooltip.expect(find.text('Live'), findsNothing);expect(find.byType(StatusDot), findsOneWidget);@@ -78,4 +90,35 @@ void main() {expect(find.text('worktree-35ab'), findsNothing);expect(find.text('harness/3'), findsNothing);});++ group('the second line shares out only what overruns it', () {+ // Machine, folder, branch — the order they are drawn in, and the order each gives way in.+ const givesWay = [1, 2, 0];++ test('everything whole where it fits', () {+ expect(+ placeWidths(wanted: [100, 90, 80], givesWay: givesWay, free: 300),+ [100, 90, 80],+ );+ });++ test('the branch gives way first, then the machine; the folder last', () {+ expect(+ placeWidths(wanted: [100, 90, 80], givesWay: givesWay, free: 250),+ [100, 90, 60],+ );+ expect(+ placeWidths(wanted: [100, 90, 80], givesWay: givesWay, free: 200),+ [56, 90, kPlaceFloor],+ );+ });++ test('below the floors only once every name is down to its own', () {+ // Then in the same order: the branch first again.+ expect(+ placeWidths(wanted: [100, 90, 80], givesWay: givesWay, free: 150),+ [kPlaceFloor, kPlaceFloor, 42],+ );+ });+ });}