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 loading sweep to terminal header
tony56f7205e687d
diff --git a/mobile/lib/phone/agent_home.dart b/mobile/lib/phone/agent_home.dartindex 3b6c102f1..2d798854b 100644--- a/mobile/lib/phone/agent_home.dart+++ b/mobile/lib/phone/agent_home.dart@@ -110,7 +110,9 @@ class _AgentHomeState extends State<AgentHome> {////// So the snapshot is taken when a pager opens, and replaced only when a new one does — which is/// exactly the rule every pushed pager already followed by being built once from a list the person- /// had just been looking at.+ /// had just been looking at — or when the tab's SET of agents changes. The pager then lines the new+ /// list up with the page already on screen rather than reading it by the old index (see+ /// `AgentSwipeHost`'s `didUpdateWidget`), which is what keeps the two in step through a swap.AgentSwipeList? _neighbours;/// The agent [_neighbours] was taken for. A different one means a different pager, and therefore a@@ -518,7 +520,18 @@ class _AgentHomeState extends State<AgentHome> {// it belongs to. An account with no tabs gets one group over everything,// which is the phone exactly as it was.final groups = deskGroups(widget.notifier, entries);- var group = activeDeskGroup(widget.notifier, groups, chosen);+ // The agent ON SCREEN while the pager is staying up — it may have been swiped to from the one+ // the pager opened on — and the tab the phone is in is that agent's. The agent held onto may be+ // in a different tab than the one the target named: a tab closed on another computer moves+ // what is on screen into another group, or into "Other".+ final showing = _showing;+ final onScreen = _neighboursFor == chosen && showing != null+ ? _entryFor(entries, showing)+ : null;+ final here = onScreen == null+ ? chosen+ : (machineId: onScreen.machineId, agentId: onScreen.agent.id);+ final group = activeDeskGroup(widget.notifier, groups, here);// ⚠️ **The swipe list is a snapshot, so it is retaken when the SET of agents changes.** It is// taken as the pager opens, and on launch that is as soon as one machine answers — a second// machine's agents arriving a moment later never reached it, and a pager built around one@@ -529,7 +542,7 @@ class _AgentHomeState extends State<AgentHome> {// retakes it too — an agent added to this tab in a window is one swipe// away here a moment later, and one closed there stops being reachable.//- // Rebuilt around the agent ON SCREEN, not the one the pager opened on — the person stays+ // Retaken around the agent ON SCREEN, not the one the pager opened on — the person stays// where they are, now with every agent of the tab beside them.final snapshot = _neighbours;if (snapshot != null &&@@ -543,18 +556,22 @@ class _AgentHomeState extends State<AgentHome> {// a frame and the terminal would stay where it was._neighboursFor == chosen &&!_sameAgents(snapshot, group.entries)) {- final showing = _showing;- final onScreen = showing == null ? null : _entryFor(entries, showing);- if (onScreen != null) {- chosen = (machineId: onScreen.machineId, agentId: onScreen.agent.id);- // The agent held onto may be in a different tab than the one the- // target named — a tab closed on another computer moves what is on- // screen into another group, or into "Other".- group = activeDeskGroup(widget.notifier, groups, chosen);+ final retaken = AgentSwipeList(group.entries);+ // ⚠️ **Handed to the pager already up, not a new pager.** A new list used to mean a new+ // key: the pager and every page in it disposed and built again, the terminal on screen+ // included. On a cold start that happened on EVERY launch — the pager opens on last run's+ // agents before the desk has answered, and the tabs arriving a second or two later cut its+ // list down to one tab's — so the header and the skeleton loaded, then jerked and loaded+ // again. The pager takes the list in place, keeping the page on screen (see+ // `AgentSwipeHost`'s `didUpdateWidget`); a new pager is built only for a list it cannot.+ if (onScreen != null && _pagerTakesInPlace(snapshot, retaken, here)) {+ _neighbours = retaken;+ } else {+ chosen = here;+ _neighboursFor = null;+ _neighbours = null;+ _pagerGeneration++;}- _neighboursFor = null;- _neighbours = null;- _pagerGeneration++;}// What the phone is in, recorded for the paths that cannot derive it: an// agent created here joins this tab (`PhoneDesk.adopt`).@@ -633,6 +650,22 @@ class _AgentHomeState extends State<AgentHome> {return before.length == now.length && before.containsAll(now);}+ /// Whether the pager already up can take [retaken] in place — keep the page on screen, [here], and+ /// change only the agents beside it — rather than be rebuilt.+ ///+ /// It can while the agent on screen is still in the list and the list pages the same way: a pager+ /// that does not wrap (one agent) numbers its pages differently, so a change of shape needs a+ /// pager of its own. The pager applies the same test and leaves alone a list that fails it — see+ /// `AgentSwipeHost`'s `didUpdateWidget`.+ static bool _pagerTakesInPlace(+ AgentSwipeList snapshot,+ AgentSwipeList retaken,+ ({String machineId, String agentId}) here,+ ) =>+ snapshot.wraps &&+ retaken.wraps &&+ retaken.indexOf(here.machineId, here.agentId) != null;+/// Bumped whenever the pager is thrown away and rebuilt, and part of its key.int _pagerGeneration = 0;diff --git a/mobile/lib/phone/agent_swipe.dart b/mobile/lib/phone/agent_swipe.dartindex 89f832923..efa7f6e81 100644--- a/mobile/lib/phone/agent_swipe.dart+++ b/mobile/lib/phone/agent_swipe.dart@@ -9,6 +9,7 @@ import 'package:harness_mobile/state/app_state.dart';import 'package:harness_mobile/terminal/terminal_session.dart'show TerminalSessionStatus;+import 'agent_index.dart' show AgentEntry;import 'agent_pane_prune.dart';import 'phone_search_catalog.dart' show phoneAgentId;import 'agent_swipe_list.dart';@@ -44,6 +45,10 @@ class AgentSwipeHost extends StatefulWidget {final String agentId;/// Null for a page opened without neighbours, which is then simply the page.+ ///+ /// May be replaced under a live pager — the tab's agents changed — and is then taken in without+ /// leaving the page on screen. See [_AgentSwipeHostState.didUpdateWidget] for which lists can be,+ /// and [AgentHome] for the pager it builds instead when one cannot.final AgentSwipeList? neighbours;/// Told which agent a swipe has arrived at, for a host that has to keep up with the pager.@@ -64,6 +69,24 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {PageController? _controller;+ /// The agents the pages are drawn from: [AgentSwipeHost.neighbours] as this pager opened on it, or+ /// as it was last taken in by [didUpdateWidget].+ AgentSwipeList? _neighbours;++ /// Added to a page number before it is read as a place in [_neighbours] — see [_entryAt].+ ///+ /// Zero for as long as the list this pager opened on is the list it draws. When [didUpdateWidget]+ /// takes in another, the page on screen keeps its NUMBER — the number is its key, and the key is+ /// what keeps its terminal, header and skeleton mounted — and this is what makes that same number+ /// name the same agent in the new list.+ int _shift = 0;++ /// The entry page [page] draws.+ AgentEntry _entryAt(AgentSwipeList neighbours, int page) {+ final count = neighbours.entries.length;+ return neighbours.entries[((page + _shift) % count + count) % count];+ }+/// The page being looked at, which is what decides [TerminalPage.isActive].////// ⚠️ **A page, not an agent, and on a short list the difference is a bug.** A wrapped pager of@@ -194,10 +217,11 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {widget.notifier.lastOpenedAgent.remember(_current);_rememberVisit(_current);final neighbours = widget.neighbours;+ _neighbours = neighbours;if (neighbours == null || neighbours.isEmpty) return;- // The snapshot is fixed for as long as this pager lives, so the opening page is the only index- // that ever has to be looked up — from there the controller and the list stay in step, and- // [_page] and [_current] both follow from `onPageChanged` alone.+ // The opening page is the only index looked up from scratch — from there the controller and the+ // list stay in step, and [_page] and [_current] both follow from `onPageChanged` alone. A list+ // taken in later is lined up with the page already on screen instead: see [didUpdateWidget].final start = neighbours.indexOf(widget.machineId, widget.agentId) ?? 0;// Opening in the MIDDLE of the endless run, not at its start, is what lets the first swipe go// either way: page 0 has nothing to its left, and the last agent has to be reachable by swiping@@ -219,6 +243,37 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {_armPrefetch();}+ /// Takes in a new neighbour list without leaving the page on screen.+ ///+ /// ⚠️ **In place, and that is the whole point.** The list is retaken whenever the tab's agents+ /// change — and on a cold start that is EVERY launch: the pager opens on last run's agents in half+ /// a second, and the tabs arrive from the desk a second or two later, cutting the list down to one+ /// tab's. That used to take a new pager: a new key, every page disposed and built again, and the+ /// terminal being looked at — header, skeleton sweep, the lot — thrown away and redrawn under the+ /// person. Here the page on screen keeps its number, so its key, so its state; only the pages+ /// beside it change agents, and those are keyed by agent (see [build]) so each is built fresh+ /// rather than handed another agent's state.+ ///+ /// Only a list that still holds the agent on screen, and that wraps as this one does: on a pager+ /// that does not wrap a page number IS a place in the list, so a change of shape needs a pager of+ /// its own, and [AgentHome] builds one for it. Anything else is left alone rather than half-applied.+ @override+ void didUpdateWidget(AgentSwipeHost oldWidget) {+ super.didUpdateWidget(oldWidget);+ final next = widget.neighbours;+ final held = _neighbours;+ if (next == null || held == null || identical(next, held)) return;+ final at = next.indexOf(_current.machineId, _current.agentId);+ if (at == null || !next.wraps || !held.wraps) return;+ final count = next.entries.length;+ _neighbours = next;+ _shift = ((at - _page) % count + count) % count;+ // The pages either side are other agents now: theirs are attached, and the ones they replaced+ // let go on the pruner's beat, as after a swipe.+ _pruner?.keep(_keepSet());+ _armPrefetch();+ }+@overridevoid dispose() {_prefetchTimer?.cancel();@@ -279,7 +334,7 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {@overrideWidget build(BuildContext context) {- final neighbours = widget.neighbours;+ final neighbours = _neighbours;final controller = _controller;if (neighbours == null || controller == null || neighbours.isEmpty) {return TerminalPage(@@ -334,7 +389,7 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {itemCount: neighbours.wraps ? null : neighbours.entries.length,onPageChanged: _onPageChanged,itemBuilder: (context, i) {- final entry = neighbours.entries[i % neighbours.entries.length];+ final entry = _entryAt(neighbours, i);// ⚠️ Tickers off for every page but the one on screen. Four pages are mounted beside it// now (see `scrollCacheExtent` above), and each has things that tick — the cursor blink,// the skeleton's sweep and pulse — which would otherwise run at frame rate for screens@@ -350,6 +405,11 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {key: ValueKey(i),enabled: i == _page,child: TerminalPage(+ // ⚠️ Keyed by AGENT as well, one level under the page's own key. A page keeps its+ // number for as long as the pager lives, but the agent at a number can change when a+ // new list is taken in (see [didUpdateWidget]) — and an unkeyed page would carry the+ // old agent's state (its attach, its chrome, its skeleton) into the new one's.+ key: ValueKey('${entry.machineId}/${entry.agent.id}'),notifier: widget.notifier,machineId: entry.machineId,agentId: entry.agent.id,@@ -364,10 +424,10 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {}void _onPageChanged(int index) {- final neighbours = widget.neighbours;+ final neighbours = _neighbours;if (neighbours == null || neighbours.isEmpty) return;// The page number runs off in both directions once the pager wraps; the agent it names does not.- final entry = neighbours.entries[index % neighbours.entries.length];+ final entry = _entryAt(neighbours, index);final arrived = (machineId: entry.machineId, agentId: entry.agent.id);// Recorded BEFORE the attach, so a pane always has an owner to close it — see [_attached]. An// agent added here that never finishes attaching costs nothing: [_detachAll] looks for its pane@@ -432,16 +492,14 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {/// `[N−2, N+2]`. An agent under several of those pages — a short list, wrapped — is named once,/// in the nearest ring, and [_current] not at all; a ring can therefore be short, or empty.List<List<AgentRef>> _rings() {- final neighbours = widget.neighbours;+ final neighbours = _neighbours;if (neighbours == null || neighbours.isEmpty) return const [];- final entries = neighbours.entries;- final count = entries.length;final seen = <AgentRef>{_current};final rings = <List<AgentRef>>[];for (var distance = 1; distance <= _reach; distance++) {final ring = <AgentRef>[];for (final step in [-distance, distance]) {- final entry = entries[((_page + step) % count + count) % count];+ final entry = _entryAt(neighbours, _page + step);final agent = (machineId: entry.machineId, agentId: entry.agent.id);if (seen.add(agent)) ring.add(agent);}diff --git a/mobile/lib/phone/agent_swipe_list.dart b/mobile/lib/phone/agent_swipe_list.dartindex 85d212300..fb856f0d6 100644--- a/mobile/lib/phone/agent_swipe_list.dart+++ b/mobile/lib/phone/agent_swipe_list.dart@@ -33,7 +33,8 @@ class AgentSwipeList {/// Where an agent sits in the snapshot, or null if it is not in it.///- /// Used once, to find the page to open on: the tapped row may be a "Waiting for you" row, an+ /// Used to find the page to open on, and the agent on screen in a list retaken under a live pager+ /// (`AgentSwipeHost`'s `didUpdateWidget`): the tapped row may be a "Waiting for you" row, an/// agent with no terminal may have been dropped by the constructor above, and neither the list's/// index nor the row's position can be assumed to survive either.int? indexOf(String machineId, String agentId) {diff --git a/mobile/lib/phone/phone_status.dart b/mobile/lib/phone/phone_status.dartindex 097cf28cc..e6b046954 100644--- a/mobile/lib/phone/phone_status.dart+++ b/mobile/lib/phone/phone_status.dart@@ -112,13 +112,49 @@ PhoneSummary phoneAgentSummary(MachineState machine, Agent agent) {);}+/// Whether the streams [machine] lost are on their way back without anybody asking: its socket is+/// dialling, or waiting out a backoff to dial again, or it is up and still fetching what the+/// reattach waits on — once that lands, `_attachPendingPanes` reopens every stream the drop left+/// dead.+///+/// For the terminal header, which reads a dead stream as "Reconnecting…" rather than as a dead end+/// while this holds — see [phoneSessionSummary]. A phone loses its socket every time it goes to the+/// background, so this is the ordinary way back into a terminal, and a Reconnect button over it+/// only ever meant "wait": the press is declined while the socket is down.+///+/// ⚠️ **`disconnected` is not on its way back.** It is a socket this app closed on purpose — signed+/// out, refused by the relay, shut — and nothing redials it; `connecting` and `reconnecting` are the+/// two with a dial behind them (`WsConn._scheduleReconnect`). An offline machine and one that needs+/// its password are out for the same reason: no dial fixes either.+bool phoneMachineRedialling(MachineState machine) {+ if (machine.nodeOnline == false || machine.needsLink) return false;+ return switch (machine.connectionStatus) {+ ConnectionStatus.connecting || ConnectionStatus.reconnecting => true,+ // ⚠️ **Up is not back yet.** The reattach waits for the agent list and the terminal+ // capabilities — `_attachPendingPanes` runs when the later of the two answers — and a refresh+ // over a list already held reports `agentsRefreshing` rather than `loading`. Counting only the+ // socket put "Disconnected" and its button back on screen for the stretch between the socket+ // answering and the stream reopening.+ ConnectionStatus.connected =>+ machine.agentLoadStatus == AgentLoadStatus.loading ||+ machine.agentsRefreshing ||+ machine.terminalCapabilityLoadInFlight != null,+ ConnectionStatus.disconnected => false,+ };+}+/// The terminal's own state, for the header over it. No session yet reads as attaching: the/// page opens before the pane has one./// [takerName]: who took the terminal, when known ([phoneTakerName]) — the/// dot's tooltip then says "Taken over by Mac mini" rather than just that it was.+/// [reconnecting]: a dead stream is already on its way back — its machine is redialling+/// ([phoneMachineRedialling]), or the person has just pressed Reconnect. Disconnected and Closed+/// then read as "Reconnecting…", busy like Attaching: there is nothing to press, and the header+/// draws the wait rather than a dead end.PhoneSummary phoneSessionSummary(TerminalSession? session, {String? takerName,+ bool reconnecting = false,}) {// ⚠️ Checked BEFORE the status, because a watcher's status is `controlling` — it holds a live// stream and renders every byte; what it does not hold is the terminal. "Live" would promise a@@ -140,6 +176,9 @@ PhoneSummary phoneSessionSummary(label: takerName == null ? 'Taken over' : 'Taken over by $takerName',tone: PhoneTone.attention,),+ TerminalSessionStatus.error || TerminalSessionStatus.closed+ when reconnecting =>+ (label: 'Reconnecting…', tone: PhoneTone.busy),TerminalSessionStatus.error => (label: 'Disconnected', tone: PhoneTone.bad),TerminalSessionStatus.closed => (label: 'Closed', tone: PhoneTone.quiet),};@@ -173,7 +212,14 @@ String? phoneTakeoverNotice(TerminalSession? session, String? takerName) =>/// The desktop puts the same two words on the same two states, in the tile/// header it draws (`widgets/terminal_panel.dart`); a phone hides that header/// and draws its own, which is how the way out went missing here.-PhoneSummary? phoneReclaimAction(TerminalSession? session) {+///+/// [reconnecting]: as for [phoneSessionSummary] — a dead stream already on its+/// way back offers no Reconnect, for the reason above: while the socket is down+/// the press is declined, so the button would only ever mean "wait".+PhoneSummary? phoneReclaimAction(+ TerminalSession? session, {+ bool reconnecting = false,+}) {// A watcher is the ordinary way onto an agent another app is driving: output is already on// screen, and this is the button that asks for the keyboard. See [TerminalSession.watching].if (session != null && session.watching) {@@ -185,6 +231,8 @@ PhoneSummary? phoneReclaimAction(TerminalSession? session) {tone: PhoneTone.attention,),TerminalSessionStatus.error ||+ TerminalSessionStatus.closed when reconnecting => null,+ TerminalSessionStatus.error ||TerminalSessionStatus.closed => (label: 'Reconnect', tone: PhoneTone.bad),_ => null,};diff --git a/mobile/lib/phone/status_pill.dart b/mobile/lib/phone/status_pill.dartindex 39a63fc93..f1b1ccc2c 100644--- a/mobile/lib/phone/status_pill.dart+++ b/mobile/lib/phone/status_pill.dart@@ -72,6 +72,7 @@ class StatusDot extends StatelessWidget {required this.summary,this.ring,this.size = defaultSize,+ this.spinnerColor,});/// The box every screen but the terminal's foot row draws it at.@@ -89,6 +90,10 @@ class StatusDot extends StatelessWidget {/// reads as notched into it rather than stuck on top.final Color? ring;+ /// The spinner's colour in place of the busy tone's, for a spinner drawn over a mark rather than+ /// beside its words — see `BadgedEngineMark`. Null keeps the tone's.+ final Color? spinnerColor;+@overrideWidget build(BuildContext context) {AppTheme.watch(context);@@ -99,7 +104,7 @@ class StatusDot extends StatelessWidget {child: summary.tone == PhoneTone.busy? CircularProgressIndicator(strokeWidth: 1.6 * size / defaultSize,- color: color,+ color: spinnerColor ?? color,): Center(child: DecoratedBox(diff --git a/mobile/lib/phone/terminal_header.dart b/mobile/lib/phone/terminal_header.dartindex 1a6439901..f25bd6fa1 100644--- a/mobile/lib/phone/terminal_header.dart+++ b/mobile/lib/phone/terminal_header.dart@@ -22,7 +22,9 @@ import 'status_pill.dart';/// rides the mark's bottom-right corner the way presence sits on an avatar in a/// messenger: green while live, a spinner while attaching, the warning or error/// colour when the stream is taken over or drops. The label is still there for-/// a screen reader and as the long-press tooltip — see [StatusDot].+/// a screen reader and as the long-press tooltip — see [StatusDot]. While the+/// terminal is on its way back, the rule under the row sweeps as well — see+/// [TerminalHeaderRule].////// ⚠️ **Search and New agent are not here.** They float over the terminal's/// bottom-right corner with the mic — see `terminal_action_column.dart` — so@@ -88,9 +90,7 @@ class TerminalHeader extends StatelessWidget {ring: AppPalette.windowBg,),const SizedBox(width: 11),- Expanded(- child: _Identity(agent: agent),- ),+ Expanded(child: _Identity(agent: agent)),...trailing,],),@@ -139,7 +139,16 @@ class BadgedEngineMark extends StatelessWidget {Positioned(right: -4,bottom: -4,- child: StatusDot(summary: status, ring: ring),+ child: StatusDot(+ summary: status,+ ring: ring,+ // ⚠️ **The accent as a mark, not as a fill.** `accent` is the+ // fill under white text, and as a 1.6pt ring on the dark ground+ // it all but vanished — the one sign on the row that the+ // terminal was on its way back went unseen. `accentOnSurface`+ // is the palette's accent for a mark on a surface.+ spinnerColor: AppPalette.accentOnSurface,+ ),),],),@@ -147,6 +156,179 @@ class BadgedEngineMark extends StatelessWidget {}}+/// The hairline under the header, which carries a sweep while the terminal is+/// on its way back — attaching, resyncing, reconnecting.+///+/// ```+/// [mark◌] agent-3 ⋯+/// autonomous-harness ⑂ main+/// ──────────────━━━━━━━━──────────────────────────────── → left to right+/// ```+///+/// ⚠️ **The spinner on the mark cannot carry a wait on its own.** It is 10pt in+/// the corner of a 28pt mark, and a reconnect after the phone comes back from+/// the background runs for seconds: at that size it read as a status rather+/// than as progress, and the page looked stuck. The sweep crosses the whole+/// width, so the wait is seen wherever the eye is.+///+/// ⚠️ **Painted, not laid out.** The rule takes one pixel of layout whatever it+/// draws — [TerminalHeader.height] counts it as one — and the two-pixel glint+/// hangs half a pixel over each side of it. A taller rule would move everything+/// under the header each time a reconnect began and ended.+///+/// Still, not blank, when it cannot animate: with animations turned off the+/// whole rule is drawn in the glint's colour, so the state still shows. A page+/// parked beside the one on screen needs nothing — its ticker is muted, and the+/// glint picks up where it stopped when the page comes back.+class TerminalHeaderRule extends StatefulWidget {+ const TerminalHeaderRule({super.key, required this.busy});++ /// The terminal is on its way back: attaching, resyncing or reconnecting.+ final bool busy;++ @override+ State<TerminalHeaderRule> createState() => _TerminalHeaderRuleState();+}++class _TerminalHeaderRuleState extends State<TerminalHeaderRule>+ with SingleTickerProviderStateMixin {+ /// One pass, left edge to right edge: quick enough to read as work going on,+ /// slow enough not to flicker at the edge of the eye.+ static const _period = Duration(milliseconds: 1150);++ late final AnimationController _sweep = AnimationController(+ vsync: this,+ duration: _period,+ );++ /// Eased in and out on every pass, so the glint gathers at the left, crosses,+ /// and trails off at the right rather than scrolling past at one speed.+ late final Animation<double> _travel = CurvedAnimation(+ parent: _sweep,+ curve: Curves.fastOutSlowIn,+ );++ /// False when the person has turned animations off.+ bool _canAnimate = true;++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();+ _canAnimate = !MediaQuery.disableAnimationsOf(context);+ _sync();+ }++ @override+ void didUpdateWidget(TerminalHeaderRule oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.busy != widget.busy) _sync();+ }++ /// Runs the sweep exactly while there is a wait to show and it may move.+ void _sync() {+ final run = widget.busy && _canAnimate;+ if (run == _sweep.isAnimating) return;+ if (run) {+ _sweep.repeat();+ } else {+ _sweep.stop();+ }+ }++ @override+ void dispose() {+ _sweep.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ AppTheme.watch(context);+ return Stack(+ clipBehavior: Clip.none,+ children: [+ Divider(height: 1, color: AppGlass.hair),+ if (widget.busy)+ Positioned(+ left: 0,+ right: 0,+ top: -0.5,+ height: 2,+ // ⚠️ A boundary of its own: the glint repaints every frame, and+ // without one each frame would repaint the header with it — the+ // row, the names, the mark — for a two-pixel line.+ child: RepaintBoundary(+ child: CustomPaint(+ painter: _GlintPainter(+ travel: _travel,+ color: AppPalette.accentOnSurface,+ still: !_canAnimate,+ ),+ ),+ ),+ ),+ ],+ );+ }+}++/// Paints [TerminalHeaderRule]'s glint: a short band of [color] that fades out+/// at both ends, carried across the rule by [travel].+class _GlintPainter extends CustomPainter {+ _GlintPainter({+ required this.travel,+ required this.color,+ required this.still,+ }) : super(repaint: travel);++ /// 0 with the glint wholly off the left edge, 1 with it wholly off the right.+ final Animation<double> travel;++ final Color color;++ /// Animations are off: the whole rule in [color], not a glint frozen+ /// somewhere along it.+ final bool still;++ /// The glint's length, as a fraction of the rule.+ static const _length = 0.34;++ @override+ void paint(Canvas canvas, Size size) {+ final full = Offset.zero & size;+ if (still) {+ canvas.drawRect(full, Paint()..color = color.withValues(alpha: 0.5));+ return;+ }+ final length = size.width * _length;+ // Enters from past the left edge and leaves past the right, so each pass+ // arrives and goes rather than appearing at one edge and vanishing at the+ // other.+ final left = -length + (size.width + length) * travel.value;+ final glint = Rect.fromLTWH(left, 0, length, size.height);+ canvas.save();+ canvas.clipRect(full);+ canvas.drawRect(+ glint,+ Paint()+ ..shader = LinearGradient(+ colors: [+ color.withValues(alpha: 0),+ color,+ color.withValues(alpha: 0),+ ],+ ).createShader(glint),+ );+ canvas.restore();+ }++ @override+ bool shouldRepaint(_GlintPainter old) =>+ old.color != color ||+ old.still != still ||+ !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 thediff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dartindex eb1a4ebce..5b65faf65 100644--- a/mobile/lib/phone/terminal_page.dart+++ b/mobile/lib/phone/terminal_page.dart@@ -175,11 +175,21 @@ typedef _PageFacts = ({AgentLoadStatus? agentLoadStatus,bool machinePresent,PhoneMachineStatus? machineStatus,+ bool redialling,bool imagePaste,String? machineName,bool deskTabs,});+/// What a page has asked for back — see [_TerminalPageState._reclaiming].+enum _Reclaim {+ /// The keyboard, off another app that holds the terminal or is driving it.+ control,++ /// A dead stream, reopened.+ reconnect,+}+class _TerminalPageState extends State<TerminalPage>with WidgetsBindingObserver, TickerProviderStateMixin {/// Whether this page's pane ever existed.@@ -391,11 +401,32 @@ class _TerminalPageState extends State<TerminalPage>/// compares the next tick against._PageFacts? _facts;- /// Set while THIS page has asked for the terminal back, so the banner can stay up through the- /// `opening` that answers it saying so — rather than blinking out and back as the status moves.+ /// What THIS page has asked for back and not yet heard about: the keyboard off another app, or a+ /// dead stream reopened. Null while it has asked for nothing.+ ///+ /// A take holds the banner up through the `opening` that answers it, so the banner can say so —+ /// rather than blinking out and back as the status moves. A reconnect raises no banner: the+ /// header draws it as the wait it is, the way it draws Attaching — see [phoneSessionSummary]'s+ /// `reconnecting`.+ ///+ /// ⚠️ **Two kinds, because they read differently.** Both are the same call, and this used to be+ /// one flag: pressing Reconnect raised a banner saying "Taking control…" over a stream nobody+ /// else held.+ ////// Taken back by [_onNotifier] once that open lands, and by [_takeControl] itself for a request/// the notifier declined without ever changing a status.- bool _takingControl = false;+ _Reclaim? _reclaiming;++ /// The skeleton's one identity across the two places the body draws it.+ ///+ /// ⚠️ **Two places, one skeleton.** It stands in for the panel while there is no session, and+ /// lies OVER the panel once there is one whose first keyframe has not landed. The session arrives+ /// a moment after the page — the attach is made after the first frame — so every launch crossed+ /// from one place to the other: the first skeleton was unmounted, a second mounted in its place,+ /// and the sweep started again from the top edge a beat after the page appeared. Under one+ /// [GlobalKey] Flutter moves the same skeleton across, and its sweep carries on. The two places+ /// are never built in the same frame: one wants no session, the other a session.+ final GlobalKey _skeletonKey = GlobalKey(debugLabel: 'terminal skeleton');/// Reads this page's own terminal buffer for an open question dialog.///@@ -520,6 +551,14 @@ class _TerminalPageState extends State<TerminalPage>agentLoadStatus: machine?.agentLoadStatus,machinePresent: machine != null,machineStatus: machine == null ? null : phoneMachineStatusOf(machine),+ // Only while the stream is dead — the one state it changes how the+ // header reads. A live page has no reason to rebuild each time the agent+ // list refreshes underneath it.+ redialling:+ machine != null &&+ (session?.status == TerminalSessionStatus.error ||+ session?.status == TerminalSessionStatus.closed) &&+ phoneMachineRedialling(machine),imagePaste: machine?.terminalImagePasteAvailable ?? false,machineName: machine?.machine.displayName,// ⚠️ Read here, and not in `build` alone, because this page is rebuilt@@ -550,10 +589,10 @@ class _TerminalPageState extends State<TerminalPage>// the bail would keep the band saying "Taking control…" over a page that had already been// told no. See [_takeControl].final settled =- _takingControl &&+ _reclaiming != null &&facts.status != TerminalSessionStatus.opening &&facts.status != null;- if (settled) _takingControl = false;+ if (settled) _reclaiming = null;if (facts == _facts) {if (settled) setState(() {});return;@@ -1070,7 +1109,16 @@ class _TerminalPageState extends State<TerminalPage>machine.agentLoadStatus == AgentLoadStatus.loaded;// Captured while the agent is still listed, for the sentence above.if (agent != null) _cachedAgentName = agent.name;- final reclaim = phoneReclaimAction(session);+ // A dead stream already on its way back: its machine is redialling, or this page has just+ // asked for it. The header draws that as the wait it is — spinner on the mark, sweep along the+ // rule — rather than as Disconnected beside a button. See [phoneSessionSummary].+ //+ // Never for an agent that is gone: nothing will reopen its stream, however the socket is doing.+ final reconnecting =+ !agentGone &&+ (_reclaiming == _Reclaim.reconnect ||+ (machine != null && phoneMachineRedialling(machine)));+ final reclaim = phoneReclaimAction(session, reconnecting: reconnecting);// Read-only either way — the terminal was never this pane's (a watcher) or was taken from it.// `_AgentGone` owns the page when the agent itself is missing, so this stays out of its way.final blocked =@@ -1082,6 +1130,11 @@ class _TerminalPageState extends State<TerminalPage>(id) => widget.notifier.stateOf(id)?.machine.displayName,);final takeoverNotice = phoneTakeoverNotice(session, takerName);+ final headerStatus = phoneSessionSummary(+ session,+ takerName: takerName,+ reconnecting: reconnecting,+ );// Creating needs the machine to list its folders and name its engines,// so one that is offline or still wants its password cannot host a new// agent — the same gate the Agents tab puts on its fab.@@ -1191,7 +1244,7 @@ class _TerminalPageState extends State<TerminalPage>onPickAnother: _pickAnotherAgent,): pane == null || session == null- ? const _Attaching()+ ? _Attaching(key: _skeletonKey): TerminalPanel(key: ValueKey(pane.id),notifier: widget.notifier,@@ -1289,7 +1342,9 @@ class _TerminalPageState extends State<TerminalPage>// difference. The header says who has it and offers// "Take control"; the body is the terminal.if (session != null && !session.hasRenderedFrame)- const Positioned.fill(child: _Attaching()),+ Positioned.fill(+ child: _Attaching(key: _skeletonKey),+ ),// The mic, Search and New agent, floating in the// terminal's bottom-right corner — see// [TerminalActionColumn].@@ -1378,10 +1433,7 @@ class _TerminalPageState extends State<TerminalPage>children: [TerminalHeader(agent: agent,- status: phoneSessionSummary(- session,- takerName: takerName,- ),+ status: headerStatus,trailing: [// Read-only is a state to get OUT of, so its way// out is a labelled button in the header rather@@ -1399,10 +1451,12 @@ class _TerminalPageState extends State<TerminalPage>//// Kept for the states the band does not cover:// "Reconnect", for a stream that died with nobody- // else involved. See [_ControlBanner].+ // else involved. See [_ControlBanner]. Gone while+ // that stream is already coming back — see+ // `reconnecting` above.if (reclaim != null &&!blocked &&- !_takingControl)+ _reclaiming == null)_ReclaimButton(action: reclaim,// The same call the band's button makes — see@@ -1461,11 +1515,20 @@ class _TerminalPageState extends State<TerminalPage>),],),- Divider(height: 1, color: AppGlass.hair),+ // The hairline, carrying a sweep while the header+ // reads as a wait — Attaching, Resyncing,+ // Reconnecting. See [TerminalHeaderRule].+ TerminalHeaderRule(+ busy: headerStatus.tone == PhoneTone.busy,+ ),// ⚠️ Inside the header's own slide, not under it: the two are one bar as far// as a scroll is concerned, and a band left behind while the header left// would sit on the output with nothing above it.- if (blocked || _takingControl)+ //+ // Up for a take in flight, not for a reconnect: that one is the header's+ // own wait, and a band over it said "Taking control…" of a stream nobody+ // else held. See [_reclaiming].+ if (blocked || _reclaiming == _Reclaim.control)_ControlBanner(watching: session?.watching ?? false,busy: !blocked,@@ -1689,23 +1752,37 @@ class _TerminalPageState extends State<TerminalPage>),];- /// Asks for the terminal this pane is only watching — the band's button, and the header's.- ///- /// [_takingControl] holds the band up through the `opening` this starts, so it reads as one- /// action answering rather than a band that vanished and came back. `selectAgent` declines- /// quietly when the pane cannot be attached at all (its machine went offline meanwhile, the- /// agent was withdrawn), and that leaves the status where it was — so the flag is taken back- /// here too, rather than left armed over a page nothing is going to answer for.+ /// Asks for the terminal this pane is only watching, or reopens the stream it lost — the band's+ /// button, and the header's.+ ///+ /// Which of the two it is comes from the stream as it stands, not from the button: somebody else+ /// holding or driving it makes this a take, and a dead one a reconnect. [_reclaiming] carries+ /// that through the `opening` this starts, so a take reads as one action answering rather than+ /// a band that vanished and came back, and a reconnect reads as the header's wait from the+ /// moment it is pressed. `selectAgent` declines quietly when the pane cannot be attached at all+ /// (its machine went offline meanwhile, the agent was withdrawn), and that leaves the status+ /// where it was — so the flag is taken back here too, rather than left armed over a page+ /// nothing is going to answer for.Future<void> _takeControl() async {final notifier = widget.notifier;- if (!_takingControl) setState(() => _takingControl = true);+ final before = notifier+ .paneOfAgent(widget.machineId, widget.agentId)+ ?.session;+ final kind =+ before != null &&+ (before.watching ||+ before.status == TerminalSessionStatus.takenOver)+ ? _Reclaim.control+ : _Reclaim.reconnect;+ if (_reclaiming != kind) setState(() => _reclaiming = kind);await notifier.selectAgent(widget.machineId, widget.agentId);if (!mounted) return;final session = notifier.paneOfAgent(widget.machineId, widget.agentId)?.session;- if (_takingControl && session?.status != TerminalSessionStatus.opening) {- setState(() => _takingControl = false);+ if (_reclaiming != null &&+ session?.status != TerminalSessionStatus.opening) {+ setState(() => _reclaiming = null);}}@@ -1979,14 +2056,14 @@ class _ControlBanner extends StatelessWidget {/// ⚠️ **It draws the transcript's STRUCTURE, not a stack of grey bars.** The/// first version was a column of plain lines and read as a loading page for some/// other app — nothing about it suggested a terminal. What actually arrives has-/// a strong, repeating shape: a prompt banner on its own lighter ground, a-/// bulleted answer indented under it, a dim meta line closing the turn. Standing+/// a strong, repeating shape: a prompt led by its `›`, a bulleted answer+/// indented under it, a dim meta line closing the turn. Standing/// in for THAT is what makes the wait read as "your session is coming back"/// rather than "something is loading", and it is the same rule/// `PhoneListSkeleton` follows for a list of cards — the same cards, empty, at a/// real row's height.class _Attaching extends StatefulWidget {- const _Attaching();+ const _Attaching({super.key});@overrideState<_Attaching> createState() => _AttachingState();@@ -2142,28 +2219,22 @@ class _AttachingState extends State<_Attaching> with TickerProviderStateMixin {// gets bars that are darker than its ground rather than lighter.final light =ThemeData.estimateBrightnessForColor(ground) == Brightness.light;- final rest = Color.alphaBlend(- (light ? Colors.black : Colors.white).withValues(alpha: 0.10),- ground,- );- final peak = Color.alphaBlend(- (light ? Colors.black : Colors.white).withValues(alpha: 0.17),- ground,- );- // The prompt's banner sits on its own ground, a step above the terminal's —- // the band an agent paints behind the line it is answering, and the one- // element that makes this block read as a transcript rather than as a list- // of lines.+ final ink = light ? Colors.black : Colors.white;+ final rest = Color.alphaBlend(ink.withValues(alpha: 0.10), ground);+ final peak = Color.alphaBlend(ink.withValues(alpha: 0.17), ground);+ // The prompt — the line the person typed — a step brighter than the answer+ // under it, and breathing with it.//- // 0.08, not the 0.05 this started at: the banner has to be legible as a BAND- // at arm's length on a phone, and at 0.05 over `#181818` it was a shade- // nobody would notice. Still well under the bars themselves (0.10–0.17), so- // it reads as the ground behind them rather than as another bar.- final banner = Color.lerp(- ground,- light ? Colors.black : Colors.white,- 0.08,- )!;+ // ⚠️ **This is what marks the prompt now, in place of a band.** The prompt+ // used to sit on its own full-width ground: a square-cornered band with a+ // rounded bar inside it — one shape nested in another, and the only square+ // corners in a block of rounded bars. It read as a table row with a+ // placeholder in it rather than as a line of a transcript. What sets the+ // prompt apart on the real screen is its `›` and its weight, so that is what+ // is drawn: the chevron in the gutter, and a bar a step brighter than the+ // answer's. Its rest is the answer's peak, so the two never meet mid-breath.+ final promptRest = Color.alphaBlend(ink.withValues(alpha: 0.17), ground);+ final promptPeak = Color.alphaBlend(ink.withValues(alpha: 0.25), ground);final bar = (fontSize * 0.62).clamp(5.0, 12.0).toDouble();return SkeletonBlock(semanticsLabel: 'Attaching to the harness',@@ -2183,7 +2254,8 @@ class _AttachingState extends State<_Attaching> with TickerProviderStateMixin {ground: ground,rest: rest,peak: peak,- banner: banner,+ promptRest: promptRest,+ promptPeak: promptPeak,),child: const SizedBox.expand(),),@@ -2194,12 +2266,12 @@ class _AttachingState extends State<_Attaching> with TickerProviderStateMixin {/// What one turn occupies, so the painter can work out how many fit.////// ⚠️ **Must stay in step with [_SkeletonPainter._turn]**, which is why the- /// terms are written in the same order as the rows it draws: banner, gap,+ /// terms are written in the same order as the rows it draws: prompt, gap,/// answer lines, gap and meta line, trailing gap. A drift here does not break/// the picture — the block is clipped either way — it just means a turn too/// few (a band of empty ground at the top) or one too many (wasted paint).static double _turnHeight(_SkeletonTurn turn, {required double lineHeight}) =>- lineHeight + // the prompt banner+ lineHeight + // the promptlineHeight * 0.35 + // the gap under itlineHeight * turn.answer.length +(turn.meta == null ? 0 : lineHeight * 0.35 + lineHeight) +@@ -2221,7 +2293,8 @@ class _SkeletonPainter extends CustomPainter {required this.ground,required this.rest,required this.peak,- required this.banner,+ required this.promptRest,+ required this.promptPeak,}) : super(repaint: Listenable.merge([breath, reveal]));/// 0 at rest, 1 at the peak of the breath.@@ -2239,7 +2312,11 @@ class _SkeletonPainter extends CustomPainter {final Color ground;final Color rest;final Color peak;- final Color banner;++ /// The prompt's bar at rest and at the peak of the breath — a step above+ /// [rest] and [peak]. See the note where they are mixed.+ final Color promptRest;+ final Color promptPeak;/// ⚠️ The terminal view's OWN padding (`TerminalPanel` passes/// `EdgeInsets.all(10)` to the xterm view), so a bar starts on the column the@@ -2296,6 +2373,7 @@ class _SkeletonPainter extends CustomPainter {// gap after it. See `last` in [_turn].total -= lineHeight * 0.9;final fill = Color.lerp(rest, peak, breath.value)!;+ final prompt = Color.lerp(promptRest, promptPeak, breath.value)!;canvas.save();canvas.clipRect(full);var top = inner.bottom - total;@@ -2313,7 +2391,7 @@ class _SkeletonPainter extends CustomPainter {inner: inner,top: top,fill: Color.lerp(ground, fill, opacity)!,- banner: Color.lerp(ground, banner, opacity)!,+ prompt: Color.lerp(ground, prompt, opacity)!,last: i == turns.length - 1,);}@@ -2321,8 +2399,8 @@ class _SkeletonPainter extends CustomPainter {canvas.restore();}- /// One turn: the prompt banner, the bulleted answer under it, the meta line —- /// drawn from [top] down, answering with where the next turn starts.+ /// One turn: the prompt, the bulleted answer under it, the meta line — drawn+ /// from [top] down, answering with where the next turn starts.////// Every row is exactly one terminal line box tall, so the whole block/// occupies a whole number of rows and the keyframe replaces it without the@@ -2336,22 +2414,26 @@ class _SkeletonPainter extends CustomPainter {required Rect inner,required double top,required Color fill,- required Color banner,+ required Color prompt,required bool last,}) {final x = inner.left;final width = inner.width;final paint = Paint()..color = fill;+ // Where every row's text starts — after the prompt's `›` and the answer's+ // bullet alike, so the block keeps the one left edge the transcript has.+ final indent = bar * 1.25;var y = top;- // The prompt, on its own full-width ground — the one element that makes- // this read as a transcript rather than as a list of lines.- canvas.drawRect(- Rect.fromLTWH(x, y, width, lineHeight),- Paint()..color = banner,+ // The prompt: its `›` in the gutter, then the line, a step brighter than+ // the answer — the two things that set it apart on the real screen.+ _chevron(canvas, x, y, prompt);+ _bar(+ canvas,+ x + indent,+ y,+ turn.prompt * (width - indent),+ Paint()..color = prompt,);- // The `›` gutter the real prompt keeps.- final gutter = bar * 0.9;- _bar(canvas, x + gutter, y, turn.prompt * (width - gutter), paint);y += lineHeight + lineHeight * 0.35;// The answer: a bullet on the first row, the rest indented under it.for (var i = 0; i < turn.answer.length; i++) {@@ -2362,26 +2444,54 @@ class _SkeletonPainter extends CustomPainter {dot / 2,paint,);- final indent = dot + bar * 0.7;- _bar(canvas, x + indent, y, turn.answer[i] * (width - indent), paint);- } else {- final indent = bar * 1.25;- _bar(canvas, x + indent, y, turn.answer[i] * (width - indent), paint);}+ _bar(canvas, x + indent, y, turn.answer[i] * (width - indent), paint);y += lineHeight;}final meta = turn.meta;if (meta != null) {y += lineHeight * 0.35;// The `✳ Crunched for 3s · done 10:36` line that closes a turn: always- // shorter, and thinner than a line of body text.- _bar(canvas, x, y, meta * width, paint, height: bar * 0.7);+ // shorter, thinner than a line of body text, and quieter than it — the+ // third step down from the prompt.+ _bar(+ canvas,+ x,+ y,+ meta * width,+ Paint()..color = Color.lerp(ground, fill, 0.7)!,+ height: bar * 0.7,+ );y += lineHeight;}if (!last) y += lineHeight * 0.9;return y;}+ /// The prompt's `›`, in the gutter the real one keeps: as tall as a bar and+ /// centred on the row like the bullet under it, so the two marks line up.+ void _chevron(Canvas canvas, double left, double top, Color color) {+ final height = bar * 0.84;+ final start = left + bar * 0.08;+ final middle = top + lineHeight / 2;+ final stroke = bar * 0.22;+ canvas.drawPath(+ Path()+ ..moveTo(start, middle - height / 2)+ ..lineTo(start + height * 0.5, middle)+ ..lineTo(start, middle + height / 2),+ Paint()+ ..color = color+ ..style = PaintingStyle.stroke+ // Floored at a pixel and a bit: at the smallest terminal fonts the bar+ // is 5pt, and a stroke in proportion to it would be a hairline beside+ // bars and a bullet that are not.+ ..strokeWidth = stroke < 1.2 ? 1.2 : stroke+ ..strokeCap = StrokeCap.round+ ..strokeJoin = StrokeJoin.round,+ );+ }+/// A bar of text, centred in the line box that starts at [top].void _bar(Canvas canvas,@@ -2400,7 +2510,10 @@ class _SkeletonPainter extends CustomPainter {width,thickness,),- const Radius.circular(3),+ // Round-ended, the same family as the bullet and the chevron's caps:+ // with a fixed 3pt corner a large terminal font drew square-shouldered+ // slabs beside a round dot.+ Radius.circular(thickness / 2),),paint,);@@ -2463,7 +2576,8 @@ class _SkeletonPainter extends CustomPainter {old.ground != ground ||old.rest != rest ||old.peak != peak ||- old.banner != banner ||+ old.promptRest != promptRest ||+ old.promptPeak != promptPeak ||!identical(old.breath, breath) ||!identical(old.reveal, reveal);}@@ -2476,7 +2590,7 @@ class _SkeletonTurn {required this.meta,});- /// Width of the prompt text inside its banner, as a fraction of the pane.+ /// Width of the prompt's text, as a fraction of the row after its `›`.final double prompt;/// The answer's lines, longest first — a paragraph wraps full-width and its