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(mobile): floating mic, Search and New agent; search as its own overlay

bubu-dudu4a3a0f642475
diff --git a/mobile/lib/phone/terminal_action_column.dart b/mobile/lib/phone/terminal_action_column.dart
new file mode 100644
index 000000000..80e13a22f
--- /dev/null
+++ b/mobile/lib/phone/terminal_action_column.dart
@@ -0,0 +1,207 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/terminal/terminal_session.dart';
+
+import 'voice_input_controller.dart';
+import 'voice_mic_button.dart';
+import 'voice_mic_fab.dart';
+import 'voice_status_pill.dart';
+
+/// The terminal's floating controls, stacked in its bottom-right corner:
+/// the mic, then Search, then New agent.
+///
+/// ```
+/// ( Listening… × ) (🎤)
+/// (🔍)
+/// (+)
+/// ```
+///
+/// ⚠️ **The mic is on top, and that is what "moved up" means.** It used to sit
+/// alone in the corner, over the agent's own status line; Search and New agent
+/// now take the corner under it, and the mic rides above them. The three share
+/// one column so they read as one set of controls rather than three strays.
+///
+/// ⚠️ **The gaps are set by the mic's hit area, not by the look.** The mic's
+/// target spills [VoiceMicButton.touchOverhang] past its slot on every side and
+/// is generous on purpose — a button under it that sat any closer would lose
+/// the top of its own target to the mic, and a tap aimed at Search would start
+/// a recording.
+class TerminalActionColumn extends StatelessWidget {
+ const TerminalActionColumn({
+ super.key,
+ required this.voice,
+ required this.session,
+ required this.onSearch,
+ required this.onNewAgent,
+ });
+
+ final VoiceInputController voice;
+
+ /// Null while the terminal is still attaching: no mic, since there is nothing
+ /// to talk to yet, but Search and New agent stay where the thumb expects them.
+ final TerminalSession? session;
+
+ final VoidCallback onSearch;
+
+ /// Null when the machine cannot host a new agent right now — offline, or
+ /// still asking for its password. The button is left out rather than drawn
+ /// dead.
+ final VoidCallback? onNewAgent;
+
+ /// The column's width: the mic's slot, which the smaller buttons centre under.
+ static const double width = VoiceMicButton.extent;
+
+ /// How far the column sits from the terminal's right and bottom edges.
+ static const double inset = VoiceMicFab.inset;
+
+ /// The gap from the mic's slot to the first button under it — the mic's
+ /// overhang plus the button's own, so the two targets meet and do not overlap.
+ static const double _underMic =
+ VoiceMicButton.touchOverhang + TerminalRoundAction.touchOverhang;
+
+ /// Between Search and New agent.
+ static const double _between = 10;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final session = this.session;
+ final onNewAgent = this.onNewAgent;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ if (session != null) ...[
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Left of the mic, on its centreline: the words the mic has
+ // nowhere to put, and the `×` that calls it off.
+ ConstrainedBox(
+ constraints: BoxConstraints(
+ maxWidth:
+ (MediaQuery.sizeOf(context).width -
+ width -
+ inset * 2 -
+ 24)
+ .clamp(0, double.infinity),
+ ),
+ child: VoiceStatusPill(voice: voice, session: session),
+ ),
+ const SizedBox(width: 6),
+ VoiceMicFab(voice: voice, session: session),
+ ],
+ ),
+ const SizedBox(height: _underMic),
+ ],
+ _centred(
+ TerminalRoundAction(
+ key: const ValueKey('terminal-search'),
+ icon: LucideIcons.search300,
+ label: 'Search agents and machines',
+ onTap: onSearch,
+ ),
+ ),
+ if (onNewAgent != null) ...[
+ const SizedBox(height: _between),
+ _centred(
+ TerminalRoundAction(
+ key: const ValueKey('terminal-new-agent'),
+ icon: LucideIcons.plus300,
+ label: 'New agent',
+ onTap: onNewAgent,
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+
+ Widget _centred(Widget child) => SizedBox(
+ width: width,
+ child: Center(child: child),
+ );
+}
+
+/// A round floating button in the mic's style, one size down.
+///
+/// ⚠️ Smaller than the mic, and that is the right way round: the mic is the
+/// page's one action, and these are tapped once and rarely.
+class TerminalRoundAction extends StatelessWidget {
+ const TerminalRoundAction({
+ super.key,
+ required this.icon,
+ required this.label,
+ required this.onTap,
+ });
+
+ final IconData icon;
+
+ /// For screen readers and the long-press tooltip.
+ final String label;
+
+ final VoidCallback onTap;
+
+ /// The drawn circle.
+ static const double diameter = 42;
+
+ /// What the finger may land on, spilling past the circle on every side.
+ static const double touchExtent = 50;
+
+ static const double touchOverhang = (touchExtent - diameter) / 2;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ return Semantics(
+ button: true,
+ label: label,
+ child: Tooltip(
+ message: label,
+ child: SizedBox.square(
+ dimension: diameter,
+ child: OverflowBox(
+ maxWidth: touchExtent,
+ maxHeight: touchExtent,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: SizedBox.square(
+ dimension: touchExtent,
+ child: Center(
+ child: Container(
+ width: diameter,
+ height: diameter,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: AppGlass.surfaceFill,
+ border: Border.all(color: AppGlass.lift),
+ // The mic's resting shadows: these float over streaming
+ // output too, and without them the edge is lost on every
+ // bright line under it.
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.45),
+ blurRadius: 12,
+ offset: const Offset(0, 3),
+ ),
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.3),
+ blurRadius: 3,
+ offset: const Offset(0, 1),
+ ),
+ ],
+ ),
+ child: Icon(icon, size: 20, color: AppPalette.textPrimary),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/terminal_chrome_scroll.dart b/mobile/lib/phone/terminal_chrome_scroll.dart
index beac90b00..a9e833cb7 100644
--- a/mobile/lib/phone/terminal_chrome_scroll.dart
+++ b/mobile/lib/phone/terminal_chrome_scroll.dart
@@ -27,10 +27,9 @@ import 'package:flutter/widgets.dart';
/// that simply went would have left the page with no way to search or to reach
/// the actions until somebody scrolled back for it.
///
-/// ⚠️ **The foot row is not driven from here and must not be.** An earlier
-/// version hid it on any scroll at all. It costs the terminal one short line and
-/// carries what the mic needs somebody to read, which is wanted most while
-/// things are moving.
+/// ⚠️ **The floating mic, Search and New agent are not driven from here and
+/// must not be.** They carry what the mic needs somebody to read, which is
+/// wanted most while things are moving.
///
/// ⚠️ **A value, not a boolean, and it animates.** The page reads it as 0 (fully
/// down) to 1 (fully gone) so the row can slide rather than blink.
diff --git a/mobile/lib/phone/terminal_foot_bar.dart b/mobile/lib/phone/terminal_foot_bar.dart
deleted file mode 100644
index 2b89ee2f5..000000000
--- a/mobile/lib/phone/terminal_foot_bar.dart
+++ /dev/null
@@ -1,341 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:lucide_icons_flutter/lucide_icons.dart';
-
-import 'package:harness_mobile/shared/theme/app_theme.dart';
-import 'package:harness_mobile/core/models.dart';
-import 'package:harness_mobile/widgets/engine_identity.dart';
-
-import 'phone_status.dart';
-import 'status_pill.dart';
-import 'voice_input_controller.dart';
-import 'voice_mic_action.dart';
-import 'voice_mic_mode.dart';
-
-/// The foot of a terminal page, one short row: which agent this is, on which
-/// computer, and what the mic is doing while it is doing it.
-///
-/// ⚠️ **The mic is no longer in here.** It floats over the terminal's bottom
-/// right corner instead — see `voice_mic_fab.dart` — which is what let this row
-/// shrink to a line of text. What stayed is the line the mic needs somebody to
-/// read: "Listening… release to send", "Didn't catch that". A floating button
-/// has nowhere to put words.
-///
-/// ⚠️ **One fixed height, whatever it says.** This row's top edge is the
-/// terminal's bottom edge: a row that grew for a two-line notice would resize
-/// the remote shell under it.
-class TerminalFootBar extends StatelessWidget {
- const TerminalFootBar({
- super.key,
- required this.name,
- required this.status,
- required this.voice,
- required this.agent,
- this.slippedOff = false,
- });
-
- /// The machine's name. Empty leaves it out.
- final String name;
-
- /// Null while the header's reclaim button is saying the state instead — the
- /// row then carries the identity alone, at the same height.
- final PhoneSummary? status;
-
- final VoiceInputController voice;
-
- /// The agent this terminal belongs to — its engine mark and its name are the
- /// identity this row leads with. Null while it is still loading.
- final Agent? agent;
-
- /// Whether a hold in progress has been dragged off the mic, so letting go
- /// would cancel. A fact about the FINGER, which only the button knows; it is
- /// passed down so this row can say what the release will now do.
- final bool slippedOff;
-
- /// ⚠️ Short on purpose, and the whole reason the mic left. Every point here
- /// is a point taken off the terminal above, which is then resized.
- ///
- /// ⚠️ **18 is what one line of 10.5pt text fits in, and nothing more.** The
- /// type, the engine mark and the status dot were all cut to match — a child
- /// that kept its old size would overflow rather than shrink the row, because
- /// the height is fixed above everything in it.
- ///
- /// The sums, for whoever comes to change one of these: the system face lays
- /// 10.5pt out in a line box of about 12.5, the engine mark is the tallest
- /// thing in the row at 11, and that leaves roughly 3pt of air above and below.
- /// It is tight on purpose — this row's top edge is the terminal's bottom edge
- /// — but it is tight enough that the text scale below is no longer optional.
- static const double height = 18;
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- return SizedBox(
- height: height,
- // ⚠️ **Text scaling is pinned here, and this row is one of the few places
- // in the app where that is right.** Its height is fixed — the terminal's
- // bottom edge sits on it — so type that grew with the system setting would
- // overflow rather than reflow, and there is no second line for it to take.
- // The words here are chrome that names the agent; the terminal above,
- // which is what somebody is actually reading, honours the setting as it
- // always did.
- child: MediaQuery.withNoTextScaling(
- child: Padding(
- // The mic floats over the terminal ABOVE this row rather than over the
- // row itself, so the right inset is only the screen's own margin — but
- // it stays generous, because the mic's hit area reaches down to within
- // a few points of this line and text running right up to it would look
- // like part of the button.
- padding: const EdgeInsets.only(left: 16, right: 16),
- child: ListenableBuilder(
- listenable: voice,
- builder: (context, _) => Row(
- children: [
- Expanded(
- child: AnimatedSwitcher(
- duration: const Duration(milliseconds: 180),
- layoutBuilder: _alignStart,
- child:
- _voiceLine(voice, slippedOff) ??
- _IdentityLine(
- key: const ValueKey('identity'),
- name: name,
- status: status,
- agent: agent,
- ),
- ),
- ),
- // ⚠️ **At the END OF THE LINE it dismisses, not over the mic.**
- // Stacked above the floating button it sat in the middle of the
- // terminal with nothing beside it — a lone glyph over streaming
- // output, which reads as a rendering fault rather than as a
- // control. Here it is plainly the way to get rid of the words to
- // its left.
- //
- // The mic cannot be shifted by it either, which is what put it
- // over there in the first place: the mic floats and this is in
- // the layout, so they no longer share a row.
- if (_showsDismiss(voice)) _DismissButton(onTap: voice.clear),
- ],
- ),
- ),
- ),
- ),
- );
- }
-}
-
-/// What the row says instead of the agent while voice is in use — a notice
-/// first, since it is the one thing here that asks to be read. Null with the mic
-/// at rest.
-Widget? _voiceLine(VoiceInputController voice, bool slippedOff) {
- final notice = voice.notice;
- // ⚠️ The slip outranks the notice and the activity alike. A thumb held off
- // the button is one release away from throwing the take away, and that is the
- // only thing on this row worth the space at that moment.
- final label = slippedOff
- ? 'Release to cancel'
- : notice ?? voiceActivityLabel(voice);
- if (label == null) return null;
- return Text(
- label,
- key: ValueKey(label),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- fontSize: 10.5,
- height: 1.2,
- fontWeight: FontWeight.w500,
- // The warning colour for both things that are about to go wrong or go
- // away, matching the mic's own fill while it is under a slipped thumb.
- color: (slippedOff || notice != null)
- ? AppPalette.warn
- : AppPalette.accent,
- ),
- );
-}
-
-Widget _alignStart(Widget? current, List<Widget> previous) =>
- Stack(alignment: Alignment.centerLeft, children: [...previous, ?current]);
-
-/// Whether the `×` at the end of the row is drawn.
-///
-/// ⚠️ **Never while a take is being recorded in hold-to-talk.** It is not needed
-/// there — releasing off the button is the cancel, and the recording cannot
-/// outlast the thumb. What remains is what the gesture cannot reach: words held
-/// from a failed send, and notices, which are also the only state hold mode
-/// leaves standing after the finger is up.
-bool _showsDismiss(VoiceInputController voice) {
- if (voice.notice != null) return true;
- if (voice.isSending) return false;
- if (micHoldsToTalk) {
- return switch (voice.status) {
- VoiceInputStatus.starting ||
- VoiceInputStatus.listening ||
- VoiceInputStatus.transcribing => false,
- VoiceInputStatus.idle ||
- VoiceInputStatus.unavailable => voice.transcript.isNotEmpty,
- };
- }
- return !voice.isIdle;
-}
-
-/// `×` at the end of the row while there is something to drop: words held from
-/// a failed send, or a notice. Gone again at rest.
-///
-/// ⚠️ **The glyph is tiny and the target is not.** The row is 20pt tall and this
-/// has to read as punctuation at the end of a sentence rather than as a button
-/// competing with the mic — but 20pt of glass is not something a thumb can hit.
-/// An [OverflowBox] gives it a 40pt target while the row keeps its height.
-///
-/// ⚠️ **The target grows DOWNWARD, never up, and that is the one thing here
-/// that must not change.** The mic floats above this row at the same right-hand
-/// end, its own hit area spills below its box, and it is painted after this — so
-/// a target reaching up meets the mic's coming down, the mic wins, and a tap
-/// meant to dismiss a notice starts a recording. Everything below this row is
-/// the home indicator's margin, which has nothing to collide with.
-class _DismissButton extends StatelessWidget {
- const _DismissButton({required this.onTap});
-
- final VoidCallback onTap;
-
- /// What the finger may land on, against the 18pt the row gives it.
- static const double _touch = 40;
-
- /// How wide the glyph's own slot is.
- ///
- /// ⚠️ **Wider than the row is tall, on purpose.** The row's height came down
- /// to 18 for the type, but the `×` is round and 18pt of width crowds it hard
- /// against the words to its left. Width costs the terminal nothing — only the
- /// height is shared with it.
- static const double _slot = 24;
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- return Semantics(
- button: true,
- label: 'Cancel',
- child: SizedBox(
- width: _slot,
- height: TerminalFootBar.height,
- child: OverflowBox(
- maxWidth: _touch,
- maxHeight: _touch,
- // Pinned to the row's TOP edge, so the box that overflows hangs off
- // the bottom rather than straddling both sides. See the note above.
- alignment: Alignment.topCenter,
- child: GestureDetector(
- key: const ValueKey('voice-cancel'),
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: SizedBox.square(
- dimension: _touch,
- // ⚠️ **Aligned to the ROW's middle, not the target's.** The hit
- // box is 40pt pinned to an 18pt row's top edge, so its own centre
- // sits 11pt BELOW the line of text — a `Center` here drew the
- // glyph hanging off the bottom of the bar, clear of the words it
- // belongs to. The fraction puts it back on the text's centreline
- // while the target it lives in still reaches down past the row.
- child: Align(
- alignment: Alignment(0, -1 + (TerminalFootBar.height / _touch)),
- child: Icon(
- LucideIcons.x300,
- size: 12,
- color: AppPalette.textSecondary,
- ),
- ),
- ),
- ),
- ),
- ),
- );
- }
-}
-
-/// Who this terminal belongs to, as one line — *engine mark, agent, machine,
-/// state*.
-///
-/// ⚠️ **The agent's name is what yields when the row is narrow, and the state
-/// word never does.** A truncated "Ta…" for "Taken over" is the bug this layout
-/// exists to avoid, so [StatusPill] keeps its intrinsic width and the
-/// [Flexible]s are on the two names. The agent's name gets the larger share: it
-/// is the thing that says WHICH terminal this is.
-class _IdentityLine extends StatelessWidget {
- const _IdentityLine({
- super.key,
- required this.name,
- required this.status,
- required this.agent,
- });
-
- final String name;
- final PhoneSummary? status;
- final Agent? agent;
-
- @override
- Widget build(BuildContext context) {
- final status = this.status;
- final agent = this.agent;
- return Row(
- children: [
- if (agent != null) ...[
- // ⚠️ The TALLEST thing in the row, so it is what sets the floor under
- // [TerminalFootBar.height] — not the text. Small enough to read as a
- // mark beside the name rather than as an avatar.
- EngineMark(
- engine: agent.engine,
- displayName: agent.engineDisplayName,
- size: 11,
- ),
- const SizedBox(width: 5),
- Flexible(
- flex: 3,
- child: Text(
- agent.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- color: AppPalette.textPrimary,
- fontSize: 10.5,
- fontWeight: FontWeight.w600,
- ),
- ),
- ),
- ],
- if (agent != null && name.isNotEmpty) _dot(),
- if (name.isNotEmpty)
- Flexible(
- flex: 2,
- child: Text(
- name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- color: AppPalette.textSecondary,
- fontSize: 10.5,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- if ((agent != null || name.isNotEmpty) && status != null) _dot(),
- if (status != null)
- // The dot and its gap come down with the type: at the row's default
- // 10pt the dot was wider than the cap height beside it and read as a
- // bullet rather than as a state.
- StatusPill(fontSize: 10.5, dotSize: 8, gap: 5, summary: status),
- ],
- );
- }
-
- /// A separator the eye passes over rather than reads: the halves are one
- /// sentence, and a heavier mark between them made the row look like controls.
- Widget _dot() => Padding(
- padding: const EdgeInsets.symmetric(horizontal: 4),
- child: Text(
- '·',
- // Down with everything else in the row: left at 12 it was the tallest
- // piece of type here and set the line box on its own.
- style: TextStyle(color: AppPalette.textFaint, fontSize: 10.5),
- ),
- );
-}
diff --git a/mobile/lib/phone/terminal_header.dart b/mobile/lib/phone/terminal_header.dart
index b5c612eaf..bd86935cb 100644
--- a/mobile/lib/phone/terminal_header.dart
+++ b/mobile/lib/phone/terminal_header.dart
@@ -1,87 +1,79 @@
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
+import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/widgets/engine_identity.dart';
-/// The terminal page's own header: a search bar across the row, with the page's
-/// controls at its right end.
+import 'phone_status.dart';
+import 'status_pill.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 · MacBooks-MacBook-Pro-6 ⋯
+/// ~/…/autonomous-harness ⑂ main
+/// ```
///
-/// ⚠️ **Not [PhoneHeader], and the agent's name is not here.** The phone opens
-/// straight into a terminal now, so this row is the only place search can live —
-/// and a title beside a field leaves the field too narrow to read a hint in. The
-/// name moved to the foot of the page, beside the engine mark, where it is
-/// identity rather than chrome. See `terminal_foot_bar.dart`.
+/// ⚠️ **The connection state is the dot on the engine mark, not a word.** It
+/// 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].
///
-/// The bar is a button wearing a field's clothes: tapping it does not push
-/// anything, it grows in place into the search screen — see
-/// `terminal_search.dart`, which draws the same bar at the same geometry so the
-/// two frames line up. That is what the measurements below are public for: the
-/// expanded bar has to land on the pixels the collapsed one left.
+/// ⚠️ **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
+/// this row is identity plus `⋯`, and nothing competes with the names for width.
///
-/// ⚠️ **It leaves on a scroll, and its controls carry on without it.** The page
-/// shrinks this row away as the terminal is scrolled forward, and the search
-/// bar, `+` and `⋯` fly out of it to become floating buttons down the right
-/// edge — see `terminal_header_floats.dart`. Nothing here knows about that; the
-/// row is either laid out or it is not.
+/// ⚠️ **It leaves on a scroll, and `⋯` carries on without it.** The page slides
+/// this row away as the terminal is scrolled forward, and `⋯` flies out of it to
+/// become a floating button at the top-right — see `terminal_header_floats.dart`.
+/// Nothing here knows about that; the row is either laid out or it is not.
class TerminalHeader extends StatelessWidget {
const TerminalHeader({
super.key,
- required this.onSearch,
+ required this.agent,
+ required this.machineName,
+ required this.status,
this.trailing = const [],
- this.barHidden = false,
});
- final VoidCallback onSearch;
+ /// The agent this terminal belongs to. Null while it is still loading.
+ final Agent? agent;
- /// Whether the search overlay is drawing the bar instead of this row.
- ///
- /// ⚠️ **The bar still takes its space — it is only not PAINTED.** The overlay
- /// draws an identical field at these very pixels, and two of them stacked put
- /// one translucent rim over another: the border comes out darker than either
- /// alone, and the fill deepens, for the whole of the open. Keeping the layout
- /// and dropping the paint leaves this row doing what it still has to do —
- /// holding the trailing controls in place while they fade — without a second
- /// field showing through the first.
- final bool barHidden;
-
- /// The page's controls, right of the bar: `+`, `⋯`, and the reclaim button
- /// when the stream is read-only.
+ /// The machine's name. Empty leaves it out.
+ final String machineName;
+
+ /// The session's state, drawn as the dot on the engine mark.
+ final PhoneSummary status;
+
+ /// The page's controls, right of the names: `⋯`, and the reclaim button when
+ /// the stream is read-only.
final List<Widget> trailing;
- /// The bar's height, and with it the header's.
- static const double barHeight = 38;
+ /// The row's height, not counting its insets.
+ ///
+ /// Two lines of type: 15pt names over 12.5pt folder, with the engine mark
+ /// centred against the pair.
+ static const double rowHeight = 40;
- /// The row's padding, shared with the expanded bar. See the class note.
static const double sideInset = 14;
static const double topInset = 6;
static const double bottomInset = 8;
- /// Inside the bar: the inset before the magnifier, and the magnifier itself.
- static const double barPadding = 10;
- static const double glyphSize = 16;
-
- /// The hint's type.
- static const double hintSize = 14;
+ /// The whole header, insets and divider included — what floats over the
+ /// terminal's top rows while it is shown.
+ static const double height = topInset + rowHeight + bottomInset + 1;
- /// The gap between the bar and whatever sits right of it.
- ///
- /// ⚠️ Carried by the trailing controls themselves, not laid in this row. The
- /// page sizes their slot from one count, and the search field is laid out
- /// from that same number; a gap sitting outside the slot would be points
- /// neither side accounts for — see `_TrailingFade` in `terminal_page.dart`.
- static const double barGap = 6;
-
- /// What the bar says it will search.
- ///
- /// ⚠️ Names both kinds on purpose. The query spans agents AND machines, and
- /// the two tabs this screen replaced each answered half the question — a bare
- /// "Search" left somebody who remembers "that review thing" unsure whether
- /// this is where to look for it.
- static const String searchHint = 'Search agents and machines';
+ /// The engine mark's size. Big enough to carry the status dot on its corner
+ /// without the dot hiding it.
+ static const double markSize = 28;
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
+ final agent = this.agent;
return Padding(
padding: const EdgeInsets.fromLTRB(
sideInset,
@@ -89,85 +81,200 @@ class TerminalHeader extends StatelessWidget {
sideInset,
bottomInset,
),
- child: Row(
- children: [
- Expanded(
- child: Visibility(
- visible: !barHidden,
- // Keeps the box, drops the paint and the hit test. See [barHidden].
- maintainSize: true,
- maintainAnimation: true,
- maintainState: true,
- child: _SearchBar(onTap: onSearch),
+ child: SizedBox(
+ height: rowHeight,
+ child: Row(
+ children: [
+ _BadgedMark(agent: agent, status: status),
+ const SizedBox(width: 11),
+ Expanded(
+ child: _Identity(agent: agent, machineName: machineName),
),
- ),
- // ⚠️ **No gap of its own before these — see [barGap].** The page
- // sizes their slot from one count. A spacer sitting outside that slot
- // is points the count does not know about, so the search overlay's
- // field — which is laid out from the same number — would stop short
- // of where this row's own does, by exactly six.
- ...trailing,
- ],
+ ...trailing,
+ ],
+ ),
),
);
}
}
-/// The field-shaped target. Opaque hit test so the whole bar answers, not just
-/// the glyph and the words in it.
-class _SearchBar extends StatelessWidget {
- const _SearchBar({required this.onTap});
+/// The engine mark with the session's state notched into its corner.
+class _BadgedMark extends StatelessWidget {
+ const _BadgedMark({required this.agent, required this.status});
- final VoidCallback onTap;
+ final Agent? agent;
+ final PhoneSummary status;
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
- return Semantics(
- button: true,
- label: TerminalHeader.searchHint,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: Container(
- height: TerminalHeader.barHeight,
- padding: const EdgeInsets.symmetric(
- horizontal: TerminalHeader.barPadding,
+ return SizedBox.square(
+ dimension: TerminalHeader.markSize,
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ EngineMark(
+ engine: agent?.engine,
+ displayName: agent?.engineDisplayName,
+ size: TerminalHeader.markSize,
),
- decoration: BoxDecoration(
- color: AppGlass.rowFill,
- borderRadius: BorderRadius.circular(AppCard.radius),
- border: Border.all(color: AppGlass.hair),
+ // Bottom-right, hanging a little past the mark — the corner a
+ // messenger puts presence on an avatar. The ring is the header's own
+ // colour, so the dot reads as cut into the mark rather than stuck on.
+ Positioned(
+ right: -4,
+ bottom: -4,
+ child: StatusDot(summary: status, ring: AppPalette.windowBg),
),
- child: Row(
- children: [
- Icon(
- LucideIcons.search300,
- size: TerminalHeader.glyphSize,
- color: AppPalette.textFaint,
+ ],
+ ),
+ );
+ }
+}
+
+/// The two lines: *agent · machine*, then *folder ⑂ branch*.
+///
+/// ⚠️ **The agent's name is what yields last.** It is the thing that says WHICH
+/// terminal this is, so it takes the larger share of the first line and the
+/// machine is cut first. On the second line the folder is kept whole where it
+/// can be and the branch gives way — see [projectPathLabel].
+class _Identity extends StatelessWidget {
+ const _Identity({required this.agent, required this.machineName});
+
+ final Agent? agent;
+ final String machineName;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final agent = this.agent;
+ final project = agent?.project;
+ final branch = project?.branchLabel;
+ final hasPlace = project != null || branch != null;
+ return Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Flexible(
+ flex: 3,
+ child: Text(
+ agent?.name ?? 'Agent',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ color: AppPalette.textPrimary,
+ fontSize: 15,
+ fontWeight: FontWeight.w600,
+ height: 1.2,
+ ),
),
- const SizedBox(width: 8),
- Expanded(
+ ),
+ if (machineName.isNotEmpty) ...[
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 5),
child: Text(
- TerminalHeader.searchHint,
+ '·',
+ style: TextStyle(color: AppPalette.textFaint, fontSize: 13),
+ ),
+ ),
+ Flexible(
+ flex: 2,
+ child: Text(
+ machineName,
maxLines: 1,
- // ⚠️ Fades rather than ellipses. The hint names two things and
- // the second one is what somebody is scanning for — a cut at
- // "Search agents and mac…" reads as a bug, while a soft edge
- // reads as a line that ran out of room.
- overflow: TextOverflow.fade,
- softWrap: false,
+ overflow: TextOverflow.ellipsis,
style: TextStyle(
- color: AppPalette.textFaint,
- fontSize: TerminalHeader.hintSize,
+ color: AppPalette.textSecondary,
+ fontSize: 13,
fontWeight: FontWeight.w500,
+ height: 1.2,
),
),
),
],
- ),
+ ],
),
- ),
+ if (hasPlace) ...[
+ const SizedBox(height: 2),
+ Row(
+ children: [
+ if (project != null)
+ Flexible(
+ flex: 3,
+ child: Text(
+ projectPathLabel(project.cwd),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: _placeStyle,
+ ),
+ ),
+ if (branch != null) ...[
+ if (project != null) const SizedBox(width: 8),
+ Icon(
+ LucideIcons.gitBranch300,
+ size: 12,
+ color: AppPalette.textFaint,
+ ),
+ const SizedBox(width: 3),
+ Flexible(
+ flex: 2,
+ child: Text(
+ branch,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: _placeStyle,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ],
+ ],
);
}
+
+ TextStyle get _placeStyle => TextStyle(
+ color: AppPalette.textSecondary,
+ fontSize: 12.5,
+ fontWeight: FontWeight.w500,
+ height: 1.2,
+ );
+}
+
+/// A folder as the header names it: its own name, with everything above it
+/// folded into `…` — `~/…/autonomous-harness`.
+///
+/// Home is written `~` the way a shell prompt writes it, so a folder directly in
+/// home keeps its whole path (`~/notes`) and home itself is `~`. A folder
+/// outside home keeps its root: `/…/srv`.
+///
+/// ⚠️ The parents are the part every agent somebody owns has in common — the
+/// folder's own name is what tells two of them apart, so it is the one thing
+/// never cut here.
+String projectPathLabel(String cwd) {
+ final path = cwd.replaceAll('\\', '/');
+ final parts = path.split('/').where((part) => part.isNotEmpty).toList();
+ if (parts.isEmpty) return path.isEmpty ? '~' : '/';
+
+ // `/Users/<name>/…` on a Mac, `/home/<name>/…` on Linux, `/root` for root.
+ var homeDepth = 0;
+ if (path.startsWith('/') && parts.length >= 2) {
+ if (parts[0] == 'Users' || parts[0] == 'home') homeDepth = 2;
+ }
+ if (path.startsWith('/') && parts[0] == 'root') homeDepth = 1;
+ if (path.startsWith('~')) homeDepth = 1;
+
+ if (homeDepth > 0) {
+ final below = parts.length - homeDepth;
+ if (below <= 0) return '~';
+ if (below == 1) return '~/${parts.last}';
+ return '~/…/${parts.last}';
+ }
+ // Outside home: a Windows drive keeps its letter, anything else its root.
+ final lead = RegExp(r'^[A-Za-z]:$').hasMatch(parts.first) ? parts.first : '';
+ if (parts.length == 1) return '$lead/${parts.last}';
+ if (lead.isNotEmpty && parts.length == 2) return '$lead/${parts.last}';
+ return '$lead/…/${parts.last}';
}
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 888ee6e1a..1fd8aa639 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -24,15 +24,13 @@ import 'phone_sheet.dart';
import 'phone_status.dart';
import 'settings_page.dart';
import 'status_pill.dart';
+import 'terminal_action_column.dart';
import 'terminal_chrome_scroll.dart';
-import 'terminal_foot_bar.dart';
import 'terminal_header.dart';
import 'terminal_header_floats.dart';
import 'terminal_input_dock.dart';
import 'terminal_search.dart';
import 'voice_input_controller.dart';
-import 'voice_mic_fab.dart';
-import 'voice_mic_mode.dart';
/// One agent's terminal, filling the phone. The header says whose it is and whether it is live;
/// everything below it is the same [TerminalPanel] a desktop tile draws, minus that tile's own
@@ -172,18 +170,6 @@ class _TerminalPageState extends State<TerminalPage>
/// the remote resize until this clears.
bool _keyboardSettling = false;
- /// Whether a hold in progress on the mic has been dragged off it, so letting
- /// go would throw the take away.
- ///
- /// Kept here rather than in either widget because it crosses between them: the
- /// floating button is what feels the finger leave, and the foot row at the
- /// other end of the page is what can say so in words — the thumb is covering
- /// the button itself.
- ///
- /// [VoiceMicMode.tapToToggle] leaves it false forever; that mode has no hold
- /// to slide out of.
- bool _micSlippedOff = false;
-
/// Drives search opening out of the header bar and collapsing back into it.
///
/// ⚠️ **One controller for both halves of the move, read by both.** The search
@@ -285,32 +271,16 @@ class _TerminalPageState extends State<TerminalPage>
super.dispose();
}
- /// The three the header held, for when the row is not on screen to hold them.
+ /// What the header held, for when the row is not on screen to hold it: `⋯`.
///
- /// ⚠️ Built from the same conditions as the header's own row, so the column
- /// never offers something the row would have withheld — `+` needs a machine
- /// that is answering, `⋯` needs an agent that has loaded. That also means the
- /// column can be two buttons rather than three, which is why its height is
- /// computed rather than fixed.
+ /// ⚠️ Built from the same condition as the header's own row, so the float
+ /// never offers something the row would have withheld — `⋯` needs an agent
+ /// that has loaded. Search and New agent are not here: they float in the
+ /// bottom-right corner with the mic whether the header is up or not.
List<TerminalHeaderChoice> _headerChoices(
MachineState? machine,
Agent? agent,
) => [
- TerminalHeaderChoice(
- icon: LucideIcons.search300,
- label: 'Search',
- onTap: _openSearch,
- ),
- if (machine != null &&
- phoneMachineStatusOf(machine) == PhoneMachineStatus.ready)
- TerminalHeaderChoice(
- icon: LucideIcons.plus300,
- label: 'New agent',
- onTap: () async {
- await openNewAgent(context, widget.notifier, widget.machineId);
- if (mounted) setState(() {});
- },
- ),
if (agent != null)
TerminalHeaderChoice(
icon: LucideIcons.ellipsis300,
@@ -324,71 +294,50 @@ class _TerminalPageState extends State<TerminalPage>
/// Where each floating button starts its flight, relative to where it lands.
///
- /// ⚠️ **Worked out from the header's own constants rather than measured.** A
- /// [GlobalKey] on each control would give the true rectangles, but the header
- /// is being taken apart at exactly the moment these are read — its render
- /// objects are mid-shrink, and half of them are already gone. Constants are
- /// the only description of where the row's controls WERE that survives the row
- /// leaving.
- ///
- /// The trade is that the origins drift if the header's layout changes without
- /// this changing with it. That shows up as buttons flying from slightly the
- /// wrong place, never as a crash or a missed target.
+ /// ⚠️ **Worked out from the header's own constants rather than measured.** The
+ /// header is being taken apart at exactly the moment these are read, so
+ /// constants are the only description of where its controls WERE that
+ /// survives the row leaving. The trade is that the origins drift if the
+ /// header's layout changes without this changing with it — buttons flying
+ /// from slightly the wrong place, never a crash or a missed target.
List<Offset> _headerOrigins(int count) {
- // The column's own geometry: each button rests [pitch] below the one above,
- // with the first at [inset] from the top.
const inset = TerminalHeaderFloats.inset;
const pitch = TerminalHeaderFloats.pitch;
const extent = TerminalHeaderFloats.extent;
-
- // Where the header's controls sat, as centres measured from the top-right of
- // the safe area. The trailing actions are [_HeaderAction]s: 24px boxes with
- // 7 either side, laid from the right edge inwards past the header's own
- // 14pt inset.
+ // The trailing actions are [_HeaderAction]s: 24px boxes with 7 either side,
+ // the last one's trailing pad dropped, laid from the right edge inwards past
+ // the header's own inset.
const actionPitch = 24 + _HeaderAction.gap * 2;
- final headerMidY = TerminalHeader.topInset + TerminalHeader.barHeight / 2;
-
+ const headerMidY = TerminalHeader.topInset + TerminalHeader.rowHeight / 2;
return [
for (var i = 0; i < count; i++)
() {
- // ⚠️ The FIRST choice is search, and it came from the bar — which
- // spans the row rather than sitting at a point. Its left end is where
- // the magnifier is, and that is what the button flies from.
- final fromRight = i == 0
- ? _searchGlyphFromRight(context)
- : TerminalHeader.sideInset +
- actionPitch * (count - 1 - i) +
- actionPitch / 2;
- final restFromRight = inset + extent / 2;
+ final fromRight =
+ TerminalHeader.sideInset + actionPitch * (count - 1 - i) + 12;
+ const restFromRight = inset + extent / 2;
final restY = inset + i * pitch + extent / 2;
return Offset(restFromRight - fromRight, headerMidY - restY);
}(),
];
}
- /// How far the search bar's magnifier sits from the screen's right edge.
+ /// Opens the machine's new-agent form.
///
- /// The bar fills what the trailing actions leave, so this is the whole width
- /// less the row's insets and the glyph's own place inside the bar.
- double _searchGlyphFromRight(BuildContext context) =>
- MediaQuery.sizeOf(context).width -
- TerminalHeader.sideInset -
- TerminalHeader.barPadding -
- TerminalHeader.glyphSize / 2;
+ /// Awaited: the form may be backed out of rather than completed, and this page
+ /// gets no rebuild when it lands back on top.
+ Future<void> _newAgent() async {
+ await openNewAgent(context, widget.notifier, widget.machineId);
+ if (mounted) setState(() {});
+ }
- /// Grows the header's bar into the search screen.
+ /// Fades the search screen up over the terminal.
///
/// ⚠️ The overlay is mounted on THIS frame and the animation started on it,
- /// so the field is there to take the keyboard as the bar opens. Starting the
- /// animation first and mounting at the end would land the caret after the
- /// move, which is a beat too late for a bar that was tapped to type in.
+ /// so the field is there to take the keyboard as the screen opens. Mounting
+ /// at the end of the fade would land the caret a beat too late for a button
+ /// that was tapped to type in.
void _openSearch() {
if (_searching) return;
- // The bar being tapped may be a bar that scrolling had slid halfway off. It
- // has to be home before the overlay's copy grows out of it, or the two start
- // from different places and the expansion reads as a jump.
- //
- _chrome.reveal();
setState(() {
_searching = true;
// ⚠️ Handed over, not left standing. The bar can be tapped with the
@@ -402,8 +351,8 @@ class _TerminalPageState extends State<TerminalPage>
/// Collapses it back into the bar, and takes the overlay down once it is home.
///
- /// ⚠️ **Guarded on the controller's own status, not on [_searching].** The
- /// field's chevron and the system back gesture can both arrive while the reverse is already
+ /// ⚠️ **Guarded on the controller's own status, not on [_searching].** Cancel
+ /// and the system back gesture can both arrive while the reverse is already
/// running — a second `reverse()` restarts it from wherever it had got to, and
/// the bar visibly bounces.
void _closeSearch() {
@@ -504,8 +453,7 @@ class _TerminalPageState extends State<TerminalPage>
widget.isActive && !_searching && (_keyboardIsUp || _keyboardRequested);
/// A tap on the terminal while no keyboard is up or coming: the keyboard.
- /// Voice is the mic at the foot of the page, never this tap — see
- /// [TerminalFootBar].
+ /// Voice is the floating mic, never this tap — see [TerminalActionColumn].
///
/// What was said and not sent is typed into the prompt on the way rather than
/// dropped, so the keyboard picks up where the voice left off — to correct a
@@ -531,8 +479,8 @@ class _TerminalPageState extends State<TerminalPage>
if (_keyboardRequested) setState(() => _keyboardRequested = false);
}
- /// Whether the keyboard on screen is THIS page's — the question the foot row
- /// asks, which [_keyboardUp] alone answers wrongly.
+ /// Whether the keyboard on screen is THIS page's — the question the floating
+ /// controls ask, which [_keyboardUp] alone answers wrongly.
///
/// ⚠️ [_keyboardUp] means "an inset exists", not "this page raised it". A
/// pushed page with a text field — search, rename — raises one of its own,
@@ -619,8 +567,9 @@ class _TerminalPageState extends State<TerminalPage>
@override
Widget build(BuildContext context) {
return ListenableBuilder(
- // Not the voice controller: what the mic hears repaints the foot row,
- // which listens for itself, and never rebuilds the terminal above it.
+ // Not the voice controller: what the mic hears repaints the floating mic
+ // and its pill, which listen for themselves, and never rebuilds the
+ // terminal under them.
listenable: widget.notifier,
builder: (context, _) {
AppTheme.watch(context);
@@ -649,26 +598,12 @@ class _TerminalPageState extends State<TerminalPage>
.where((a) => a.id == widget.agentId)
.firstOrNull;
final reclaim = phoneReclaimAction(session);
- // The header's trailing controls, counted before they are built: their
- // slot is sized from this, and the search field is laid out against
- // that same width. The conditions must match the ones guarding each
- // control below — see [_TrailingFade.extentFor].
- //
- // ⚠️ [reclaim] is counted too, though it is a labelled button rather
- // than one of the fixed 24px icon boxes. It cannot be measured from a
- // constant — its width is its label's — so the slot treats it as a
- // MINIMUM rather than a fixed size: see [_TrailingFade], which floors
- // the width it is given instead of forcing it. Sizing it exactly is not
- // worth a second TextPainter for a button that shows only on a
- // read-only stream.
- final headerActions =
- (machine != null &&
- phoneMachineStatusOf(machine) == PhoneMachineStatus.ready
- ? 1
- : 0) +
- (agent != null ? 1 : 0) +
- (reclaim != null ? 1 : 0);
- final trailingExtent = _TrailingFade.extentFor(context, headerActions);
+ // 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.
+ final canCreate =
+ machine != null &&
+ phoneMachineStatusOf(machine) == PhoneMachineStatus.ready;
return Scaffold(
backgroundColor: AppPalette.windowBg,
// ⚠️ No fab. New agent is the `+` in the header — see the note there.
@@ -768,28 +703,26 @@ class _TerminalPageState extends State<TerminalPage>
),
),
),
- // The mic — the one voice control the page has,
- // floating over the terminal's bottom right corner
- // rather than sitting in a row of its own.
+ // The mic, Search and New agent, floating in the
+ // terminal's bottom-right corner — see
+ // [TerminalActionColumn].
//
- // ⚠️ Hidden while this page owns the keyboard, the
- // same gate the foot row takes. Typing is the other
- // way of saying the same thing, the key bar is
- // already under the thumb, and a button floating
- // over it would be in the way of both.
- if (session != null && !_ownsInput)
+ // ⚠️ Hidden while this page owns the keyboard.
+ // Typing is the other way of saying what the mic
+ // says, the key bar is already under the thumb, and
+ // a column floating over the prompt being typed into
+ // would be in the way of both.
+ if (!_ownsInput)
Positioned(
- right: VoiceMicFab.inset,
- bottom: VoiceMicFab.inset,
- child: VoiceMicFab(
+ right: TerminalActionColumn.inset,
+ bottom: TerminalActionColumn.inset,
+ child: TerminalActionColumn(
voice: widget.voice,
session: session,
- onSlipChanged: (off) {
- if (!mounted || off == _micSlippedOff) {
- return;
- }
- setState(() => _micSlippedOff = off);
- },
+ onSearch: _openSearch,
+ onNewAgent: canCreate
+ ? () => unawaited(_newAgent())
+ : null,
),
),
],
@@ -821,36 +754,6 @@ class _TerminalPageState extends State<TerminalPage>
)
: null,
),
- // Who this terminal belongs to, and what the mic is doing
- // while it is doing it — the words the floating button
- // has nowhere to put.
- //
- // ⚠️ Below the key bar, not above it. The bar is what the
- // thumb works, and a line that moves every time it
- // appears would shift the keys under it. Here it is the
- // last row on the page and nothing it does moves
- // anything above it.
- //
- // ⚠️ Hidden while this page owns the keyboard. The key
- // bar is already tall, and a line wedged under it is a
- // row of chrome the terminal loses for nothing — who the
- // agent is is not what is being read mid-typing.
- //
- // ⚠️ **It does not move with scrolling, and an earlier
- // version that did was wrong.** This row is one line
- // of identity and the mic's running commentary — it
- // costs the terminal 20 points, and hiding it whenever
- // the content moved meant the words the mic needs read
- // went away exactly while somebody was looking for
- // them.
- if (!_ownsInput)
- TerminalFootBar(
- name: machine?.machine.displayName ?? '',
- voice: widget.voice,
- agent: agent,
- status: phoneSessionSummary(session),
- slippedOff: _micSlippedOff,
- ),
],
),
// The header, laid OVER the terminal rather than above it in the
@@ -887,113 +790,41 @@ class _TerminalPageState extends State<TerminalPage>
mainAxisSize: MainAxisSize.min,
children: [
TerminalHeader(
- // ⚠️ Grows in place — no route is pushed. [openPhoneSearch]
- // is still what the LIST screens use, and this page used it
- // too until the bar arrived: pushing slid a fresh screen in
- // from the right, so the bar the finger had just touched left
- // the frame while an identical one came in from off-screen.
- // See `terminal_search.dart`.
- onSearch: _openSearch,
- // ⚠️ Tracks [_searching], NOT the animation's value:
- // the overlay's own bar exists for exactly as long as
- // the overlay is mounted, including the closing frames
- // where the animation is already near zero. Reading the
- // value here would paint this row's field back under
- // the overlay's for the tail of every collapse.
- barHidden: _searching,
- // ⚠️ No title and no engine mark up here any more: the search
- // bar takes the row, and the agent's name moved to
- // [TerminalFootBar] at the foot of the page, where it reads
- // as identity rather than as chrome.
- //
- // ⚠️ **Wrapped so they can step aside for search.** They act
- // on the agent underneath, which is not what is on screen once
- // search is up — so they fade out while the search field
- // widens over their place. No Cancel takes it: the way out
- // is the chevron at the field's own leading edge. See
- // [_TrailingFade] and `terminal_search.dart`.
+ agent: agent,
+ machineName: machine?.machine.displayName ?? '',
+ status: phoneSessionSummary(session),
trailing: [
- _TrailingFade(
- progress: _searchCurve,
- extent: trailingExtent,
- children: [
- // Read-only is a state to get OUT of, so its way out is a
- // labelled button in the header rather than a line in the
- // actions sheet: the sheet is where you go having decided
- // to do something, and this is the thing telling you that
- // typing will go nowhere until you do.
- if (reclaim != null)
- _ReclaimButton(
- action: reclaim,
- onPressed: () =>
- widget.notifier.selectAgent(
- widget.machineId,
- widget.agentId,
- ),
- ),
- // New agent, search and the actions menu: the three the
- // page offers, in the order they are reached for — create,
- // find, then everything else.
- //
- // ⚠️ They are spaced by [_HeaderAction], not drawn bare.
- // [AppIconButton] is a fixed 24px box whatever glyph size
- // it is given, so a 22px search glyph fills its box edge to
- // edge while a 20px ellipsis sits inside one — three
- // buttons butted together then read as unevenly spaced
- // when the gaps are in fact identical. One glyph size and
- // one padding across the three is what evens the rhythm.
- //
- // ⚠️ `+` here rather than floating over the terminal. A fab
- // covers the last line of output — the line being read —
- // and this page has no list to scroll it clear of.
- //
- // Gated on the machine ANSWERING, the same gate the Agents
- // tab puts on its fab: 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.
- if (machine != null &&
- phoneMachineStatusOf(machine) ==
- PhoneMachineStatus.ready)
- _HeaderAction(
- icon: LucideIcons.plus300,
- size: 21,
- tooltip: 'New agent',
- // Awaited for the same reason search is: the form may
- // be backed out of rather than completed, and this page
- // gets no rebuild when it lands back on top.
- onPressed: () async {
- await openNewAgent(
- context,
- widget.notifier,
- widget.machineId,
- );
- if (mounted) setState(() {});
- },
- ),
- // ⚠️ Both stay put while the keyboard is up. They were once
- // hidden while typing to spare the row — but the row was
- // never what was short, and the controls jumping position
- // on every keyboard raise cost more than the two columns
- // bought back. A header that holds still is worth more.
- //
- // Null while the agent is not loaded: there is nothing to act on yet, and a
- // menu of actions that all fail is worse than no menu.
- if (agent != null)
- _HeaderAction(
- icon: LucideIcons.ellipsis300,
- size: 21,
- tooltip: 'Agent actions',
- // Last in the row, so its padding stops at the header's
- // own right inset rather than adding to it.
- last: true,
- onPressed: () => _showActions(
- machineName:
- machine?.machine.displayName ?? '',
- agentName: agent.name,
- ),
- ),
- ],
- ),
+ // Read-only is a state to get OUT of, so its way
+ // out is a labelled button in the header rather
+ // than a line in the actions sheet: the sheet is
+ // where you go having decided to do something,
+ // and this is the thing telling you that typing
+ // will go nowhere until you do.
+ if (reclaim != null)
+ _ReclaimButton(
+ action: reclaim,
+ onPressed: () => widget.notifier.selectAgent(
+ widget.machineId,
+ widget.agentId,
+ ),
+ ),
+ // Null while the agent is not loaded: there is
+ // nothing to act on yet, and a menu of actions
+ // that all fail is worse than no menu.
+ if (agent != null)
+ _HeaderAction(
+ icon: LucideIcons.ellipsis300,
+ size: 21,
+ tooltip: 'Agent actions',
+ // Last in the row, so its padding stops at
+ // the header's own right inset.
+ last: true,
+ onPressed: () => _showActions(
+ machineName:
+ machine?.machine.displayName ?? '',
+ agentName: agent.name,
+ ),
+ ),
],
),
Divider(height: 1, color: AppGlass.hair),
@@ -1029,25 +860,14 @@ class _TerminalPageState extends State<TerminalPage>
);
},
),
- // Search, grown out of the header bar. Only built while it is
+ // Search, faded up over the whole page. Only built while it is
// on its way in, up, or on its way out — see [_searching].
- //
- // ⚠️ **No fade and no scale on the whole overlay.** It carries
- // its own move — the bar widening, the list rising into it —
- // and dipping the opacity of the lot on top of that only made
- // the terminal show through the gaps. It is opaque from its
- // first frame.
if (_searching)
Positioned.fill(
child: TerminalSearchOverlay(
notifier: widget.notifier,
animation: _searchCurve,
onClose: _closeSearch,
- // What the header's trailing slot holds — where the field
- // starts from before it widens over the fading controls.
- // The same number the header lays that slot out from, so
- // the two agree on the first frame.
- trailingExtent: trailingExtent,
),
),
],
@@ -1312,10 +1132,9 @@ const int _titleMaxChars = 20;
/// string; that one still catches a 20-character name on a narrow screen, and
/// neither makes the other redundant.
///
-/// ⚠️ **Nothing calls it since the title left the header** — the name is drawn
-/// in [TerminalFootBar] now, where it has a whole row and ellipses on width
-/// alone. Kept because a title may come back to the chrome, and this is the
-/// rune-correct cut it would want.
+/// ⚠️ **Nothing calls it** — [TerminalHeader] ellipses the name on width alone,
+/// beside the machine. Kept because a count cut may be wanted there again, and
+/// this is the rune-correct one it would want.
// ignore: unused_element
String _clipTitle(String name) {
final runes = name.runes.toList();
@@ -1324,83 +1143,6 @@ String _clipTitle(String name) {
return '${String.fromCharCodes(runes.take(_titleMaxChars)).trimRight()}…';
}
-/// The header's trailing end, fading its controls out as search opens — in a
-/// column whose width the search field can count on.
-///
-/// There is no Cancel to swap in: the way out of search is the chevron at the
-/// field's leading edge, as on the search page. The field widens over this slot
-/// as the controls fade, one move in one direction; see `_Bar` in
-/// `terminal_search.dart`.
-///
-/// ⚠️ **The slot is given an explicit width, not sized by its children.** The
-/// search overlay draws its field up to this slot's left edge on the first frame
-/// of the open, so it must be able to predict that edge. [extentFor] is that
-/// number, and both this and the overlay are laid out from it.
-class _TrailingFade extends StatelessWidget {
- const _TrailingFade({
- required this.progress,
- required this.children,
- required this.extent,
- });
-
- /// 0 the page's own controls are showing, 1 search is fully open.
- final Animation<double> progress;
-
- /// The header's controls: `+`, `⋯`, and reclaim when the stream is read-only.
- final List<Widget> children;
-
- /// The slot's width, from [extentFor].
- final double extent;
-
- /// How wide a slot holding [actions] controls must be.
- ///
- /// ⚠️ Counts [TerminalHeader.barGap] once, at the front: the gap between the
- /// field and the controls belongs to the slot, so the field's right edge is
- /// the slot's left one.
- static double extentFor(BuildContext context, int actions) {
- // Each action is [AppIconButton]'s fixed 24px box with [_HeaderAction.gap]
- // either side, except the last, whose trailing pad is dropped so the row
- // stops on the header's own inset.
- const box = 24.0;
- final controls = actions == 0
- ? 0.0
- : actions * (box + _HeaderAction.gap * 2) - _HeaderAction.gap;
- return TerminalHeader.barGap + controls;
- }
-
- @override
- Widget build(BuildContext context) => AnimatedBuilder(
- animation: progress,
- builder: (context, child) => ConstrainedBox(
- // ⚠️ A MINIMUM, not a fixed width. The reclaim button is labelled, so its
- // width is its text's and no constant describes it — forcing the counted
- // width on the row would clip it.
- constraints: BoxConstraints(minWidth: extent),
- child: Align(
- // Against the right edge, so the controls end on the header's own inset
- // rather than floating inside the slot.
- alignment: Alignment.centerRight,
- widthFactor: 1,
- child: Opacity(
- // Gone by the midpoint: the field is widening into this space, and
- // controls still lit under it read as two things fighting for it.
- opacity: (1 - progress.value * 2).clamp(0.0, 1.0),
- child: IgnorePointer(
- // Untappable from the first frame of the open: they act on the
- // agent underneath, and search is what is on screen now.
- ignoring: progress.value > 0,
- child: child,
- ),
- ),
- ),
- ),
- // ⚠️ No gap of its own before these — the slot's width already carries
- // [TerminalHeader.barGap], and a second one here would push the controls
- // off the header's right inset.
- child: Row(mainAxisSize: MainAxisSize.min, children: children),
- );
-}
-
/// One of the header's trailing controls, padded so the three sit evenly.
///
/// ⚠️ The padding is what makes the row look right, and the reason is that
diff --git a/mobile/lib/phone/terminal_search.dart b/mobile/lib/phone/terminal_search.dart
index daeec07a2..8b12fb24c 100644
--- a/mobile/lib/phone/terminal_search.dart
+++ b/mobile/lib/phone/terminal_search.dart
@@ -7,28 +7,21 @@ import 'package:harness_mobile/state/app_state.dart';
import 'composing_keyboard.dart';
import 'phone_search_results.dart';
-import 'terminal_header.dart';
/// Search, opened in place over a terminal rather than pushed as a page.
///
-/// ⚠️ **Not a route, and that is the point of the whole file.** The bar sits in
-/// the terminal's header, and pushing [PhoneSearchPage] slid a fresh screen in
-/// from the right — the bar the finger had just touched went out of the frame
-/// while an identical one arrived from off-screen. Opening in place leaves the
-/// thing that was tapped exactly where it was.
+/// ⚠️ **Not a route.** Pushing [PhoneSearchPage] slid a fresh screen in from the
+/// right over a terminal that is still streaming underneath; opening in place
+/// fades the search up over it instead, and Cancel fades it back down onto the
+/// same screen, mid-stream.
///
-/// ⚠️ **One bar, no Cancel — the search page's shape.** The way out is the
-/// chevron at the field's leading edge, which the magnifier turns into as the
-/// search opens, exactly where [PhoneSearchField] keeps its own. A Cancel beside
-/// the bar was a second way out sitting next to the field's clear, and it cost
-/// the field the width of a word.
+/// It is opened from the floating Search button in the terminal's bottom-right
+/// corner (`terminal_action_column.dart`), so it draws its whole self — field,
+/// Cancel and results — over an opaque page, rather than borrowing any of the
+/// header's.
///
-/// ⚠️ **The field moves once, in one direction.** It starts on the header's own
-/// bar, then widens over `+` and `⋯` as they fade (see `_TrailingFade` in
-/// `terminal_page.dart`). An earlier Cancel widened the field and then narrowed
-/// it again within the one gesture, which is felt as the row snapping about;
-/// with nothing claiming the space back, that cannot happen. The system back
-/// gesture closes it too — see [TerminalSearchOverlay]'s [PopScope].
+/// The way out is Cancel. The system back gesture reaches it too — see
+/// [TerminalSearchOverlay]'s [PopScope].
///
/// ⚠️ **It must stay mounted only while searching.** The [TextField] inside
/// autofocuses, so a copy left built behind the terminal would keep the keyboard
@@ -39,17 +32,22 @@ class TerminalSearchOverlay extends StatefulWidget {
required this.notifier,
required this.animation,
required this.onClose,
- required this.trailingExtent,
});
final AppNotifier notifier;
- /// How much of the header's row its trailing slot is holding: where the
- /// field starts from before it widens over that slot. See [_Bar].
- final double trailingExtent;
+ /// The bar's height.
+ static const double barHeight = 38;
- /// The open/close animation the terminal page drives — 0 collapsed into the
- /// header bar, 1 filling the screen.
+ /// What the field says it will search.
+ ///
+ /// ⚠️ Names both kinds on purpose. The query spans agents AND machines, and a
+ /// bare "Search" left somebody who remembers "that review thing" unsure
+ /// whether this is where to look for it.
+ static const String searchHint = 'Search agents and machines';
+
+ /// The open/close animation the terminal page drives — 0 gone, 1 filling the
+ /// screen.
///
/// Run by the page rather than here, because the page is what decides when
/// this widget stops existing: the collapse has to finish before the overlay
@@ -98,34 +96,23 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay> {
// watches the notifier itself — and its recall store with it — so a
// second listener here would rebuild the field on every agent-list tick
// for nothing.
- child: Column(
- children: [
- // ⚠️ **The bar never fades in.** It lands exactly on the header's
- // own, which hides its picture of a field while this real one is up,
- // and then only widens — see [_Bar].
- //
- // ⚠️ Transparent, and that is what lets the fade be seen. This row
- // sits directly over the header, so a fill here would cover `+` and
- // `⋯` stepping aside for the field.
- _Bar(
- controller: _controller,
- focus: _focus,
- animation: widget.animation,
- onChanged: (value) => setState(() => _query = value),
- onBack: _close,
- trailingExtent: widget.trailingExtent,
- ),
- // ⚠️ Fades on the back half of the animation alone. The header's
- // controls are still stepping aside over the front half, and rows
- // arriving under them is two things happening at once.
- Expanded(
- child: _FadeIn(
- animation: widget.animation,
- child: ColoredBox(
- color: AppPalette.windowBg,
- // ⚠️ Handed the query and nothing else. Ranking lives inside
- // it now, so this screen and [PhoneSearchPage] cannot drift
- // into returning different rows for the same words.
+ child: FadeTransition(
+ opacity: widget.animation,
+ child: ColoredBox(
+ color: AppPalette.windowBg,
+ child: Column(
+ children: [
+ _Bar(
+ controller: _controller,
+ focus: _focus,
+ onChanged: (value) => setState(() => _query = value),
+ onCancel: _close,
+ ),
+ Divider(height: 1, color: AppGlass.hair),
+ // ⚠️ Handed the query and nothing else. Ranking lives inside it,
+ // so this screen and [PhoneSearchPage] cannot drift into
+ // returning different rows for the same words.
+ Expanded(
child: PhoneSearchResults(
notifier: widget.notifier,
query: _query,
@@ -136,220 +123,129 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay> {
onOpen: _close,
),
),
- ),
+ ],
),
- ],
+ ),
),
);
}
}
-/// The real field, drawn over the header's picture of one.
-///
-/// ⚠️ **It starts on exactly [TerminalHeader]'s geometry.** The header draws a
-/// tappable box that only looks like a field; this draws the [TextField] that
-/// replaces it, and the header hides its own for as long as this is up (see
-/// `barHidden`). On the first frame the two must land on the same pixels — same
-/// height, same corner radius, same outer padding, same right edge — or the bar
-/// jumps as the overlay takes over.
-///
-/// From there it only widens: its right edge travels from the header's
-/// trailing slot to the header's own inset while `+` and `⋯` fade out of the
-/// way, so the open search is one bar across the row, as on the search page.
+/// The field, with Cancel at its right end.
class _Bar extends StatelessWidget {
const _Bar({
required this.controller,
required this.focus,
- required this.animation,
required this.onChanged,
- required this.onBack,
- required this.trailingExtent,
+ required this.onCancel,
});
final TextEditingController controller;
final FocusNode focus;
- /// 0 sitting on the header's bar, 1 across the whole row.
- final Animation<double> animation;
-
final ValueChanged<String> onChanged;
- /// Closes the search — the chevron at the field's leading edge.
- final VoidCallback onBack;
-
- /// How much of the row the header's trailing slot is holding, so this field
- /// starts exactly where the header's picture of it ends.
- ///
- /// ⚠️ Measured by the header rather than guessed at here. The slot's width
- /// depends on which controls the page is showing — `+` comes and goes with the
- /// machine's readiness, reclaim with the stream — and a field that assumed a
- /// fixed number of them would start short of, or over, the header's own.
- final double trailingExtent;
+ final VoidCallback onCancel;
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
- // ⚠️ **No fill of its own.** The real header is directly underneath and is
- // already opaque — [_TerminalPageState] reveals it before opening this — so
- // this row only has to draw the field. Filling it would cover `+` and `⋯`
- // fading out of the field's way.
- return AnimatedBuilder(
- animation: animation,
- builder: (context, field) => Padding(
- padding: EdgeInsets.fromLTRB(
- TerminalHeader.sideInset,
- TerminalHeader.topInset,
- // The header's own inset, plus whatever of its trailing slot the
- // field has not yet taken over.
- TerminalHeader.sideInset + trailingExtent * (1 - animation.value),
- TerminalHeader.bottomInset,
- ),
- child: field,
- ),
- // ⚠️ **The field rides through as the builder's child.** Only the inset
- // above changes per frame; the [TextField] holds the input connection and
- // is not rebuilt for it.
- child: ListenableBuilder(
- listenable: focus,
- builder: (context, child) => AnimatedContainer(
- duration: AppMotion.hover,
- curve: AppMotion.curve,
- height: TerminalHeader.barHeight,
- padding: const EdgeInsets.symmetric(
- horizontal: TerminalHeader.barPadding,
- ),
- decoration: BoxDecoration(
- color: AppGlass.rowFill,
- borderRadius: BorderRadius.circular(AppCard.radius),
- // Focus is said once, by the rim of the box the field fills. The
- // accent is the same one the caret already uses.
- border: Border.all(
- color: focus.hasFocus
- ? AppPalette.accentOnSurface
- : AppGlass.hair,
- ),
- ),
- child: child,
- ),
- // ⚠️ **Everything that does NOT change with focus stays here.** The
- // [TextField] especially: it holds the input connection, and rebuilding
- // it on every focus tick is work on the one widget that can least
- // afford it.
- child: Row(
- children: [
- _BackGlyph(animation: animation, onTap: onBack),
- const SizedBox(width: 8),
- Expanded(
- child: _Input(
- controller: controller,
- focus: focus,
- onChanged: onChanged,
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(14, 6, 14, 8),
+ child: Row(
+ children: [
+ Expanded(
+ child: ListenableBuilder(
+ listenable: focus,
+ builder: (context, child) => AnimatedContainer(
+ duration: AppMotion.hover,
+ curve: AppMotion.curve,
+ height: TerminalSearchOverlay.barHeight,
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ decoration: BoxDecoration(
+ color: AppGlass.rowFill,
+ borderRadius: BorderRadius.circular(AppCard.radius),
+ // Focus is said by the rim of the box the field fills, and by
+ // the magnifier inside it — see the icon below.
+ border: Border.all(
+ color: focus.hasFocus
+ ? AppPalette.accentOnSurface
+ : AppGlass.hair,
+ ),
+ ),
+ child: Row(
+ children: [
+ // ⚠️ **Inside the builder, not the child passed through
+ // it.** The glyph lifts with focus, so it has to be rebuilt
+ // when focus changes; left in the `child` it would be built
+ // once and keep its resting ink for good.
+ //
+ // It climbs to the same accent the rim and the caret
+ // already use, over the same beat as the rim, so the three
+ // read as one state arriving rather than as three
+ // decorations each doing their own thing.
+ TweenAnimationBuilder<Color?>(
+ duration: AppMotion.hover,
+ curve: AppMotion.curve,
+ // ⚠️ [begin] is the RESTING ink, not left null. A null
+ // begin lerps from null on the first build, which hands
+ // the icon a null colour for that frame — it falls back
+ // to the theme's default ink, and the glyph flashes a
+ // colour it never otherwise wears. The field autofocuses,
+ // so that first build is on screen every time search
+ // opens; starting from rest also makes the very first
+ // climb an animation rather than a jump.
+ tween: ColorTween(
+ begin: AppPalette.textFaint,
+ end: focus.hasFocus
+ ? AppPalette.accentOnSurface
+ : AppPalette.textFaint,
+ ),
+ builder: (context, color, _) =>
+ Icon(LucideIcons.search300, size: 16, color: color),
+ ),
+ const SizedBox(width: 8),
+ // The field and its clear, built once and passed through:
+ // neither depends on focus, and the field in particular must
+ // not be rebuilt from a focus tick — see below.
+ Expanded(child: child!),
+ ],
+ ),
),
- ),
- _ClearButton(
- controller: controller,
- onTap: () {
- controller.clear();
- onChanged('');
- // Clearing is a step back into browsing, not out of the
- // search — the caret stays where the next query will go.
- focus.requestFocus();
- },
- ),
- ],
- ),
- ),
- );
- }
-}
-
-/// The field's leading glyph: the header's magnifier, turning into the chevron
-/// that closes the search as it opens.
-///
-/// ⚠️ **The magnifier's own footprint, and a thumb's reach.** Both glyphs are
-/// drawn in [TerminalHeader.glyphSize] on the spot the header's magnifier holds,
-/// so the hint beside them does not shift as one becomes the other;
-/// [TouchTarget] takes the tap to 44pt without moving either.
-class _BackGlyph extends StatelessWidget {
- const _BackGlyph({required this.animation, required this.onTap});
-
- final Animation<double> animation;
- final VoidCallback onTap;
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- return Semantics(
- button: true,
- label: 'Close search',
- child: TouchTarget(
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: SizedBox.square(
- dimension: TerminalHeader.glyphSize,
- child: AnimatedBuilder(
- animation: animation,
- builder: (context, _) => Stack(
- alignment: Alignment.center,
+ // ⚠️ **Everything that does NOT change with focus stays here.**
+ // The [TextField] especially: it holds the input connection, and
+ // rebuilding it on every focus tick is work on the one widget
+ // that can least afford it.
+ child: Row(
children: [
- Opacity(
- opacity: 1 - animation.value,
- child: Icon(
- LucideIcons.search300,
- size: TerminalHeader.glyphSize,
- color: AppPalette.textFaint,
+ Expanded(
+ child: _Input(
+ controller: controller,
+ focus: focus,
+ onChanged: onChanged,
),
),
- Opacity(
- opacity: animation.value,
- child: Icon(
- LucideIcons.chevronLeft,
- size: TerminalHeader.glyphSize,
- color: AppPalette.textPrimary,
- ),
+ _ClearButton(
+ controller: controller,
+ onTap: () {
+ controller.clear();
+ onChanged('');
+ // Clearing is a step back into browsing, not out of the
+ // search — the caret stays where the next query will go.
+ focus.requestFocus();
+ },
),
],
),
),
),
- ),
+ _CancelButton(onTap: onCancel),
+ ],
),
);
}
}
-/// The results, fading in under the bar.
-///
-/// ⚠️ **A fade alone, and it was once a rise too.** It used to
-/// translate 18pt as it faded, which belonged to a screen whose bar was also
-/// growing: one move explaining another. Now that the bar holds still, a list
-/// sliding under it was the only thing on screen that moved, and it read as the
-/// results being nudged rather than as the terminal being replaced.
-///
-/// ⚠️ On the back half of the animation only. The header's controls are still
-/// trading places over the first half, and rows arriving under them makes two
-/// things happen at once; waiting lets the eye finish one before the next.
-class _FadeIn extends StatelessWidget {
- const _FadeIn({required this.animation, required this.child});
-
- final Animation<double> animation;
- final Widget child;
-
- @override
- Widget build(BuildContext context) {
- final curve = CurvedAnimation(
- parent: animation,
- curve: const Interval(0.35, 1, curve: Curves.easeInOut),
- );
- return AnimatedBuilder(
- animation: curve,
- builder: (context, child) => Opacity(opacity: curve.value, child: child),
- child: child,
- );
- }
-}
-
class _Input extends StatelessWidget {
const _Input({
required this.controller,
@@ -408,7 +304,7 @@ class _Input extends StatelessWidget {
filled: false,
contentPadding: EdgeInsets.zero,
constraints: const BoxConstraints(),
- hintText: TerminalHeader.searchHint,
+ hintText: TerminalSearchOverlay.searchHint,
hintStyle: TextStyle(color: AppPalette.textFaint, fontSize: 14),
),
);
@@ -453,3 +349,42 @@ class _ClearButton extends StatelessWidget {
);
}
}
+
+/// The way out: the word, not a glyph. A second `×` beside the field's own
+/// clear would be two ways out sitting together.
+class _CancelButton extends StatelessWidget {
+ const _CancelButton({required this.onTap});
+
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ return Semantics(
+ button: true,
+ label: 'Cancel search',
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: SizedBox(
+ height: TerminalSearchOverlay.barHeight,
+ child: Padding(
+ padding: const EdgeInsets.only(left: 12, right: 2),
+ child: Center(
+ child: Text(
+ 'Cancel',
+ maxLines: 1,
+ softWrap: false,
+ style: TextStyle(
+ color: AppPalette.accentOnSurface,
+ fontSize: 14,
+ fontWeight: FontWeight.w500,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/voice_input_controller.dart b/mobile/lib/phone/voice_input_controller.dart
index 383e7b778..cd5ed0964 100644
--- a/mobile/lib/phone/voice_input_controller.dart
+++ b/mobile/lib/phone/voice_input_controller.dart
@@ -102,28 +102,111 @@ class VoiceInputController extends ChangeNotifier {
/// [clear], where words arriving late would bring back what was dropped.
int _take = 0;
+ /// Words already written into a terminal's prompt by [stage], waiting for the
+ /// second tap to send them — and the terminal they were written into.
+ ///
+ /// ⚠️ **Kept apart from [transcript], and that is what stops them being typed
+ /// twice.** These are ON the remote screen already; [transcript] is words
+ /// held here and nowhere else. Handing these to the keyboard, or sending them
+ /// as a composer turn, would put them in the prompt a second time.
+ String? _staged;
+ Object? _stagedIn;
+
bool get isSending => _isSending;
VoiceInputStatus get status => _status;
String get transcript => _heard;
String? get notice => _notice;
- /// Nothing being recorded, heard or sent — the mic at rest. A refused
- /// microphone is at rest too: nothing is in flight.
+ /// The words sitting unsent in a prompt, or null. See [isStagedIn].
+ String? get staged => _staged;
+
+ /// Whether [staged] words are waiting in [target]'s prompt — the terminal the
+ /// mic is being looked at on. A page swiped to afterwards is not it: its mic
+ /// is at rest, and a take started there forgets the words left behind.
+ bool isStagedIn(Object target) =>
+ _staged != null && identical(_stagedIn, target);
+
+ /// Nothing being recorded, heard, waiting in a prompt or sent — the mic at
+ /// rest. A refused microphone is at rest too: nothing is in flight.
bool get isIdle =>
(_status == VoiceInputStatus.idle ||
_status == VoiceInputStatus.unavailable) &&
_heard.isEmpty &&
+ _staged == null &&
!_isSending;
/// Drops the take in progress, the words held from a send that failed, and
/// the notice. A send already on its way is not recalled.
+ ///
+ /// Words already written into a prompt are FORGOTTEN here, not erased: they
+ /// stay on the remote screen, where the keyboard can finish them. Erasing is
+ /// [discardStaged].
void clear() {
if (_disposed) return;
_abandonTake();
_heard = '';
+ _forgetStaged();
+ _setStatus(VoiceInputStatus.idle);
+ }
+
+ /// Ends the take and writes its words into the prompt through [write] —
+ /// typed, not sent. The next tap on the mic sends them ([sendStaged]); `×`
+ /// takes them back out ([discardStaged]).
+ ///
+ /// [target] is the terminal written into — see [isStagedIn].
+ ///
+ /// [write] answers false when the terminal will not take input. The words are
+ /// then held as [transcript] instead, and the mic offers to send them the old
+ /// way, as a composer turn, once the terminal is back.
+ ///
+ /// Tapped while the microphone is still opening, there is no take yet: it is
+ /// called off rather than written.
+ Future<void> stage(Object target, bool Function(String text) write) async {
+ if (_isSending || _disposed) return;
+ if (_status == VoiceInputStatus.starting) {
+ _abandonTake();
+ _setStatus(VoiceInputStatus.idle);
+ return;
+ }
+ if (_status != VoiceInputStatus.listening) return;
+ if (await _transcribeTake() != _Take.heard) return;
+ final text = _heard.trim();
+ if (text.isEmpty || _disposed) return;
+ if (!write(text)) {
+ _setStatus(VoiceInputStatus.idle, notice: VoiceNotice.notSent);
+ return;
+ }
+ _heard = '';
+ _staged = text;
+ _stagedIn = target;
_setStatus(VoiceInputStatus.idle);
}
+ /// Sends the words [stage] wrote — [enter] presses Return in that prompt, and
+ /// answers false when the terminal would not take it.
+ void sendStaged(bool Function() enter) {
+ if (_staged == null || _disposed) return;
+ if (!enter()) {
+ _setStatus(_status, notice: VoiceNotice.notSent);
+ return;
+ }
+ _forgetStaged();
+ _setStatus(VoiceInputStatus.idle);
+ }
+
+ /// Takes the words [stage] wrote back out of the prompt — [erase] is handed
+ /// them, to delete as many characters — and puts the mic back at rest.
+ void discardStaged(void Function(String text) erase) {
+ final staged = _staged;
+ if (staged != null) erase(staged);
+ clear();
+ }
+
+ void _forgetStaged() {
+ _staged = null;
+ _stagedIn = null;
+ }
+
Future<void> startListening() async {
if (_isSending || _disposed) return;
if (_status != VoiceInputStatus.idle &&
@@ -131,6 +214,9 @@ class VoiceInputController extends ChangeNotifier {
return;
}
final take = ++_take;
+ // A new take is a new message. Words left waiting in another agent's prompt
+ // stay there for its keyboard; this mic is no longer about them.
+ _forgetStaged();
_setStatus(VoiceInputStatus.starting);
if (!await _micAllowed()) {
if (take != _take) return;
diff --git a/mobile/lib/phone/voice_mic_action.dart b/mobile/lib/phone/voice_mic_action.dart
index edc2746ce..7d49adf9a 100644
--- a/mobile/lib/phone/voice_mic_action.dart
+++ b/mobile/lib/phone/voice_mic_action.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
+import 'package:xterm/xterm.dart' show TerminalKey;
import 'package:harness_mobile/terminal/terminal_session.dart';
@@ -26,15 +27,27 @@ VoiceMicAction voiceMicAction(
TerminalSession session,
) => micHoldsToTalk ? _holdAction(voice, session) : _tapAction(voice, session);
-/// Tap to start, tap again to send — [VoiceMicMode.tapToToggle].
+/// Tap to talk, tap when done, tap to send — [VoiceMicMode.tapToToggle].
+///
+/// The second tap does NOT send. It writes what was heard into the terminal's
+/// prompt — [typeIntoPrompt] — so it can be read, and corrected with the
+/// keyboard, before it goes; the arrow that face turns into is the send. `×`
+/// in the pill beside the mic is the way out at every step.
///
/// ⚠️ Tapping while the microphone is still OPENING calls it off rather than
-/// sending: there is no take yet, and a send of nothing would leave the
-/// recording to start behind the person's back.
+/// writing: there is no take yet, and leaving the recording to start behind
+/// the person's back is worse than asking for one more tap.
VoiceMicAction _tapAction(VoiceInputController voice, TerminalSession session) {
- void send() => unawaited(voice.submit(session.sendComposerText));
final canSend = session.acceptsInput;
if (voice.isSending) return _face(VoiceMicFace.busy);
+ if (voice.isStagedIn(session)) {
+ return _face(
+ VoiceMicFace.send,
+ onPressed: canSend
+ ? () => voice.sendStaged(() => pressEnter(session))
+ : null,
+ );
+ }
return switch (voice.status) {
VoiceInputStatus.transcribing => _face(VoiceMicFace.busy),
VoiceInputStatus.starting => _face(
@@ -43,11 +56,17 @@ VoiceMicAction _tapAction(VoiceInputController voice, TerminalSession session) {
),
VoiceInputStatus.listening => _face(
VoiceMicFace.listening,
- onPressed: send,
+ onPressed: () => unawaited(
+ voice.stage(session, (text) => typeIntoPrompt(session, text)),
+ ),
),
+ // Words held from a write or send that did not land: sent as a composer
+ // turn, which is the one path that does not depend on the prompt.
_ when voice.transcript.isNotEmpty => _face(
VoiceMicFace.retry,
- onPressed: canSend ? send : null,
+ onPressed: canSend
+ ? () => unawaited(voice.submit(session.sendComposerText))
+ : null,
),
VoiceInputStatus.unavailable => _face(
VoiceMicFace.off,
@@ -60,6 +79,38 @@ VoiceMicAction _tapAction(VoiceInputController voice, TerminalSession session) {
};
}
+/// Types [text] into the terminal's prompt, as the keyboard would, without
+/// pressing Return. False when the terminal is not taking input.
+///
+/// Typed rather than pasted: it is what the keyboard's own path does with words
+/// said before a tap on the terminal, and it is what Backspace can take back
+/// one character at a time — see [eraseFromPrompt].
+bool typeIntoPrompt(TerminalSession session, String text) {
+ if (!session.acceptsInput || text.isEmpty) return false;
+ session.terminal.textInput(text);
+ return true;
+}
+
+/// Presses Return in the terminal — the send for words [typeIntoPrompt] wrote.
+bool pressEnter(TerminalSession session) {
+ if (!session.acceptsInput) return false;
+ session.terminal.keyInput(TerminalKey.enter);
+ return true;
+}
+
+/// Takes [text] back out of the prompt it was typed into: one Backspace per
+/// character, from the end, where the words were left.
+///
+/// ⚠️ Per character, counted in runes — `String.length` counts UTF-16 units,
+/// and an emoji would cost two Backspaces for the one character it is,
+/// deleting a character that was there before the words.
+void eraseFromPrompt(TerminalSession session, String text) {
+ if (!session.acceptsInput) return;
+ for (var i = 0; i < text.runes.length; i++) {
+ session.terminal.keyInput(TerminalKey.backspace);
+ }
+}
+
/// Hold to talk, release to send — [VoiceMicMode.holdToTalk].
///
/// The whole cycle is one gesture, so there is no state the person can be left
@@ -171,8 +222,16 @@ VoiceMicAction _face(
/// naming the state: the thumb is already down and holding, so "Listening…" is
/// the one thing the person can see for themselves, and what happens when they
/// let go is the thing they cannot.
-String? voiceActivityLabel(VoiceInputController voice) {
+///
+/// [session] is the terminal the mic is on: words waiting in ITS prompt say
+/// how to send them. Words waiting in another agent's prompt are not this
+/// page's business.
+String? voiceActivityLabel(
+ VoiceInputController voice, [
+ TerminalSession? session,
+]) {
if (voice.isSending) return 'Sending…';
+ if (session != null && voice.isStagedIn(session)) return 'Tap ↑ to send';
return switch (voice.status) {
// ⚠️ "Wait" rather than "Starting…" in hold mode, and it is the difference
// between working and not. Opening the microphone is real hardware time, and
@@ -186,7 +245,7 @@ String? voiceActivityLabel(VoiceInputController voice) {
VoiceInputStatus.listening =>
micHoldsToTalk
? 'Listening… release to send, slide off to cancel'
- : 'Listening…',
+ : 'Listening… tap ✓ when done',
VoiceInputStatus.transcribing => 'Transcribing…',
VoiceInputStatus.idle || VoiceInputStatus.unavailable => null,
};
diff --git a/mobile/lib/phone/voice_mic_button.dart b/mobile/lib/phone/voice_mic_button.dart
index 86e8ffbf8..8906c951b 100644
--- a/mobile/lib/phone/voice_mic_button.dart
+++ b/mobile/lib/phone/voice_mic_button.dart
@@ -126,6 +126,7 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {
bool get _lit => switch (_face) {
VoiceMicFace.starting ||
VoiceMicFace.listening ||
+ VoiceMicFace.send ||
VoiceMicFace.cancelling ||
VoiceMicFace.retry => true,
VoiceMicFace.talk || VoiceMicFace.busy || VoiceMicFace.off => false,
@@ -136,7 +137,8 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {
micHoldsToTalk ? 'Hold to talk to the agent' : 'Talk to the agent',
VoiceMicFace.starting => 'Cancel',
VoiceMicFace.listening =>
- micHoldsToTalk ? 'Release to send' : 'Send what was said',
+ micHoldsToTalk ? 'Release to send' : 'Done talking',
+ VoiceMicFace.send => 'Send',
VoiceMicFace.cancelling => 'Release to cancel',
VoiceMicFace.busy => 'Working',
VoiceMicFace.retry => 'Send again',
diff --git a/mobile/lib/phone/voice_mic_fab.dart b/mobile/lib/phone/voice_mic_fab.dart
index 2f650efcf..d0b7446eb 100644
--- a/mobile/lib/phone/voice_mic_fab.dart
+++ b/mobile/lib/phone/voice_mic_fab.dart
@@ -11,37 +11,33 @@ import 'voice_mic_action.dart';
import 'voice_mic_button.dart';
import 'voice_mic_mode.dart';
-/// The mic, floating over the terminal's bottom right corner.
+/// The mic, floating over the terminal's bottom right corner at the top of
+/// [TerminalActionColumn].
///
-/// ⚠️ **Floating rather than in a row, and that is what the row below it pays
-/// for.** The foot bar used to hold this button, which set its height at 56 —
-/// and that row's top edge is the terminal's bottom edge, so every point of it
-/// was a point taken off the remote shell. Lifting the mic out of the layout let
-/// the row shrink to one line of text; the button now costs the terminal nothing
-/// but the corner it covers.
+/// ⚠️ **Floating rather than in a row.** A row under the terminal would take
+/// its height off the remote shell; floating, the button costs the terminal
+/// nothing but the corner it covers.
///
/// ⚠️ **The corner, deliberately — not centred, and not over the middle.** A
/// terminal's newest output is the line being read, and it runs left to right:
/// the right end of the last few lines is the least of it.
///
-/// ⚠️ **The `×` is NOT here.** It lives at the end of the foot row's line, next
-/// to the words it dismisses — see `terminal_foot_bar.dart`. Stacked over this
-/// button it floated in the middle of the terminal with nothing beside it, a
-/// glyph on its own over streaming output that read as a rendering fault.
+/// ⚠️ **The `×` is NOT here.** It is in the pill beside the mic, next to the
+/// words it dismisses — see `voice_status_pill.dart`.
class VoiceMicFab extends StatefulWidget {
const VoiceMicFab({
super.key,
required this.voice,
required this.session,
- required this.onSlipChanged,
+ this.onSlipChanged,
});
final VoiceInputController voice;
final TerminalSession session;
- /// The thumb crossed in or out of the button mid-hold. The foot bar is what
- /// says "Release to cancel" — this button is under a thumb and cannot.
- final ValueChanged<bool> onSlipChanged;
+ /// The thumb crossed in or out of the button mid-hold, in
+ /// [VoiceMicMode.holdToTalk]. Unused in the tap mode, which has no hold.
+ final ValueChanged<bool>? onSlipChanged;
/// What the whole floating cluster asks of the corner it sits in.
///
@@ -49,8 +45,7 @@ class VoiceMicFab extends StatefulWidget {
/// its slot: this is what the page keeps clear of anything else tappable.
static const double extent = VoiceMicButton.touchExtent;
- /// How far the cluster sits from the screen's right edge and from the foot row
- /// under it.
+ /// How far the cluster sits from the terminal's right and bottom edges.
static const double inset = 8;
@override
diff --git a/mobile/lib/phone/voice_mic_face.dart b/mobile/lib/phone/voice_mic_face.dart
index 3c3ed1e32..c48e2d814 100644
--- a/mobile/lib/phone/voice_mic_face.dart
+++ b/mobile/lib/phone/voice_mic_face.dart
@@ -14,9 +14,13 @@ enum VoiceMicFace {
/// The microphone is opening: tap to call it off.
starting,
- /// Recording: tap to send what was said. It breathes while it listens.
+ /// Recording: tap when done, and what was said is written into the prompt.
+ /// It breathes while it listens.
listening,
+ /// What was said is in the prompt, unsent: tap to send it.
+ send,
+
/// Transcribing or sending: nothing to tap until that is back.
busy,
@@ -140,9 +144,17 @@ class _Glyph extends StatelessWidget {
// pressing this, it is sent by letting go. The mic stays up for the
// whole take and the thumb never leaves it, so there is no second press
// for an arrow to describe.
+ //
+ // ⚠️ In hold-to-talk the arrow would be a lie: nothing is sent by
+ // pressing this, it is sent by letting go. The mic stays up for the
+ // whole take and the thumb never leaves it, so there is no second press
+ // for an arrow to describe.
+ //
+ // Tap mode: a tick, "done talking" — the tap writes the words into the
+ // prompt, it does not send them. The arrow is the NEXT tap's.
VoiceMicFace.listening =>
- micHoldsToTalk ? LucideIcons.mic300 : LucideIcons.arrowUp300,
- VoiceMicFace.retry => LucideIcons.arrowUp300,
+ micHoldsToTalk ? LucideIcons.mic300 : LucideIcons.check300,
+ VoiceMicFace.send || VoiceMicFace.retry => LucideIcons.arrowUp300,
VoiceMicFace.cancelling => LucideIcons.x300,
VoiceMicFace.off => LucideIcons.micOff300,
VoiceMicFace.talk ||
diff --git a/mobile/lib/phone/voice_mic_mode.dart b/mobile/lib/phone/voice_mic_mode.dart
index b952f7eb7..68dd7ea88 100644
--- a/mobile/lib/phone/voice_mic_mode.dart
+++ b/mobile/lib/phone/voice_mic_mode.dart
@@ -6,8 +6,11 @@
/// listens for, the faces it can show, and what a release does — and nothing
/// else in the app branches on it.
enum VoiceMicMode {
- /// Tap to start, tap again to send. Walkie-talkie: the button holds the
- /// recording open with nothing held down, so a long sentence costs no thumb.
+ /// Tap to start talking, tap again when done — the words are written into the
+ /// terminal's prompt, unsent — and tap a third time to send them. `×` beside
+ /// the mic calls the take off, or takes the words back out of the prompt.
+ /// The button holds the recording open with nothing held down, so a long
+ /// sentence costs no thumb, and nothing is sent before it has been read.
///
/// Long-press stays the language shortcut here, because nothing else wants it.
tapToToggle,
@@ -31,7 +34,7 @@ enum VoiceMicMode {
/// want — a preference would mean a Settings row, a stored value, and two
/// behaviours live at once in a button whose whole job is to be unambiguous
/// under the thumb. Change this line, rebuild, and the app is the other app.
-const VoiceMicMode voiceMicMode = VoiceMicMode.holdToTalk;
+const VoiceMicMode voiceMicMode = VoiceMicMode.tapToToggle;
/// Whether the mic records only while held down.
bool get micHoldsToTalk => voiceMicMode == VoiceMicMode.holdToTalk;
diff --git a/mobile/lib/phone/voice_status_pill.dart b/mobile/lib/phone/voice_status_pill.dart
new file mode 100644
index 000000000..1db061798
--- /dev/null
+++ b/mobile/lib/phone/voice_status_pill.dart
@@ -0,0 +1,158 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/terminal/terminal_session.dart';
+
+import 'voice_input_controller.dart';
+import 'voice_mic_action.dart';
+
+/// What the mic is doing, in words, floating beside it — with the `×` that
+/// calls it off.
+///
+/// ```
+/// ( Listening… tap ✓ when done × ) (✓)
+/// ```
+///
+/// ⚠️ **The `×` is the way out of every step, and what it undoes depends on
+/// the step.** While the mic is opening, recording or transcribing, it throws
+/// the take away. Once the words are written into the prompt, it takes them
+/// back OUT of the prompt — they are on the remote screen by then, and a cancel
+/// that left them there would not be one. With a notice up, it dismisses it.
+///
+/// ⚠️ **Nothing at rest.** The pill exists only while there is something to
+/// read; a label that stayed would sit over the terminal's newest lines.
+class VoiceStatusPill extends StatelessWidget {
+ const VoiceStatusPill({
+ super.key,
+ required this.voice,
+ required this.session,
+ });
+
+ final VoiceInputController voice;
+
+ /// The terminal the mic is on — whose prompt staged words are erased from.
+ final TerminalSession session;
+
+ /// The pill's height: the mic's visible circle, less a little, so the two
+ /// read as one control rather than two of a size.
+ static const double height = 36;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ return ListenableBuilder(
+ listenable: voice,
+ builder: (context, _) {
+ final notice = voice.notice;
+ final label =
+ notice ??
+ voiceActivityLabel(voice, session) ??
+ (voice.transcript.isNotEmpty ? 'Tap ↑ to send again' : null);
+ return AnimatedSwitcher(
+ duration: const Duration(milliseconds: 180),
+ transitionBuilder: (child, animation) =>
+ FadeTransition(opacity: animation, child: child),
+ layoutBuilder: (current, previous) => Stack(
+ alignment: Alignment.centerRight,
+ children: [...previous, ?current],
+ ),
+ child: label == null
+ ? const SizedBox.shrink(key: ValueKey('voice-pill-none'))
+ : _Pill(
+ key: const ValueKey('voice-pill'),
+ label: label,
+ warn: notice != null,
+ // A send already on its way cannot be recalled, so no `×`
+ // offers to.
+ onCancel: voice.isSending ? null : _cancel,
+ ),
+ );
+ },
+ );
+ }
+
+ void _cancel() {
+ if (voice.isStagedIn(session)) {
+ voice.discardStaged((text) => eraseFromPrompt(session, text));
+ } else {
+ voice.clear();
+ }
+ }
+}
+
+class _Pill extends StatelessWidget {
+ const _Pill({
+ super.key,
+ required this.label,
+ required this.warn,
+ required this.onCancel,
+ });
+
+ final String label;
+
+ /// A notice — something that went wrong — rather than what the mic is doing.
+ final bool warn;
+
+ final VoidCallback? onCancel;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final onCancel = this.onCancel;
+ return Container(
+ height: VoiceStatusPill.height,
+ padding: EdgeInsets.only(left: 14, right: onCancel == null ? 14 : 2),
+ decoration: BoxDecoration(
+ color: AppGlass.surfaceFill,
+ borderRadius: BorderRadius.circular(VoiceStatusPill.height / 2),
+ border: Border.all(color: AppGlass.lift),
+ // It floats over streaming output, like the buttons beside it, and
+ // needs the same lift to keep its edge over a bright line.
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.35),
+ blurRadius: 10,
+ offset: const Offset(0, 2),
+ ),
+ ],
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Flexible(
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: 12.5,
+ fontWeight: FontWeight.w500,
+ color: warn ? AppPalette.warn : AppPalette.accentOnSurface,
+ ),
+ ),
+ ),
+ if (onCancel != null)
+ Semantics(
+ button: true,
+ label: 'Cancel',
+ child: GestureDetector(
+ key: const ValueKey('voice-cancel'),
+ behavior: HitTestBehavior.opaque,
+ onTap: onCancel,
+ child: SizedBox(
+ width: 34,
+ height: VoiceStatusPill.height,
+ child: Icon(
+ LucideIcons.x300,
+ size: 16,
+ color: AppPalette.textSecondary,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/test/phone_search_test.dart b/mobile/test/phone_search_test.dart
index 7a628cb72..eeab33f0f 100644
--- a/mobile/test/phone_search_test.dart
+++ b/mobile/test/phone_search_test.dart
@@ -403,7 +403,6 @@ void main() {
notifier: app,
animation: const AlwaysStoppedAnimation(1),
onClose: () {},
- trailingExtent: 0,
),
),
};
@@ -448,39 +447,6 @@ void main() {
}
});
- testWidgets('terminal search: one bar, no Cancel, its chevron closes it', (
- tester,
- ) async {
- final app = _app([
- _machine('box', [_agent('3188', minutesAgo: 4)]),
- ]);
- addTearDown(app.dispose);
- var closed = 0;
- await tester.pumpWidget(
- MaterialApp(
- home: Scaffold(
- body: TerminalSearchOverlay(
- notifier: app,
- animation: const AlwaysStoppedAnimation(1),
- onClose: () => closed++,
- trailingExtent: 62,
- ),
- ),
- ),
- );
- await tester.pump();
- expect(find.text('Cancel'), findsNothing);
- // Open all the way, the field runs to the header's own inset: the trailing
- // slot it started beside is its to take.
- final screen = tester.getSize(find.byType(Scaffold)).width;
- final field = tester.getRect(find.byType(AnimatedContainer).first);
- expect(field.right, closeTo(screen - 14, 0.5));
-
- await tester.tap(find.bySemanticsLabel('Close search'));
- await tester.pump();
- expect(closed, 1);
- });
-
testWidgets('one bar: no Cancel beside it, and its chevron closes search', (
tester,
) async {
diff --git a/mobile/test/terminal_foot_bar_test.dart b/mobile/test/terminal_foot_bar_test.dart
deleted file mode 100644
index 7e2982c0d..000000000
--- a/mobile/test/terminal_foot_bar_test.dart
+++ /dev/null
@@ -1,116 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:harness_mobile/phone/phone_status.dart';
-import 'package:harness_mobile/phone/terminal_foot_bar.dart';
-import 'package:harness_mobile/phone/voice_input_controller.dart';
-import 'package:harness_mobile/phone/voice_mic_action.dart';
-import 'package:harness_mobile/phone/voice_notice.dart';
-
-import 'voice_fakes.dart';
-
-/// The row under the terminal: who the agent is while nothing is being said,
-/// and what the mic is doing while something is. The mic itself floats over the
-/// terminal (`voice_mic_fab_test.dart`); this row carries the words it has
-/// nowhere to put.
-void main() {
- late FakeVoiceRecorder recorder;
- late FakeTranscriber backend;
- late ValueNotifier<String> language;
- late VoiceInputController voice;
-
- const live = (label: 'Live', tone: PhoneTone.good);
- final dismiss = find.byKey(const ValueKey('voice-cancel'));
-
- setUp(() {
- recorder = FakeVoiceRecorder();
- backend = FakeTranscriber();
- language = ValueNotifier('en');
- voice = VoiceInputController(
- transcriber: backend.call,
- recorder: recorder,
- language: language,
- );
- });
-
- tearDown(() {
- voice.dispose();
- language.dispose();
- });
-
- Future<void> pumpBar(WidgetTester tester, {bool slippedOff = false}) =>
- tester.pumpWidget(
- MaterialApp(
- home: Scaffold(
- body: Center(
- child: TerminalFootBar(
- name: 'MacBookPro2021.local',
- status: live,
- voice: voice,
- agent: null,
- slippedOff: slippedOff,
- ),
- ),
- ),
- ),
- );
-
- testWidgets('at rest it names the machine and its state', (tester) async {
- await pumpBar(tester);
-
- expect(find.text('MacBookPro2021.local'), findsOneWidget);
- expect(find.text('Live'), findsOneWidget);
- expect(dismiss, findsNothing);
- });
-
- testWidgets('while recording it says what the mic is doing', (tester) async {
- await pumpBar(tester);
-
- await voice.startListening();
- await tester.pumpAndSettle();
-
- expect(find.text(voiceActivityLabel(voice)!), findsOneWidget);
- expect(find.text('MacBookPro2021.local'), findsNothing);
- voice.clear();
- await tester.pumpAndSettle();
- });
-
- testWidgets('a hold dragged off the mic says letting go cancels', (
- tester,
- ) async {
- await pumpBar(tester, slippedOff: true);
- await tester.pumpAndSettle();
-
- expect(find.text('Release to cancel'), findsOneWidget);
- });
-
- testWidgets('a failed send says so, and × puts the row back', (tester) async {
- await pumpBar(tester);
- backend.replies.add('deploy');
- await voice.startListening();
- await voice.stopListening();
- await voice.submit((_) async => false);
- await tester.pumpAndSettle();
-
- expect(find.text(VoiceNotice.notSent), findsOneWidget);
-
- // On the glyph: the target only answers inside the row's own 24×18 slot —
- // hit testing stops at a parent's bounds, whatever the OverflowBox draws.
- await tester.tap(find.descendant(of: dismiss, matching: find.byType(Icon)));
- await tester.pumpAndSettle();
-
- expect(voice.transcript, isEmpty);
- expect(find.text('MacBookPro2021.local'), findsOneWidget);
- });
-
- testWidgets('the height holds still whatever the row says', (tester) async {
- await pumpBar(tester);
- final atRest = tester.getSize(find.byType(TerminalFootBar));
-
- await voice.startListening();
- await tester.pumpAndSettle();
-
- expect(tester.getSize(find.byType(TerminalFootBar)), atRest);
- voice.clear();
- await tester.pumpAndSettle();
- });
-}
diff --git a/mobile/test/terminal_header_test.dart b/mobile/test/terminal_header_test.dart
new file mode 100644
index 000000000..0a737de4e
--- /dev/null
+++ b/mobile/test/terminal_header_test.dart
@@ -0,0 +1,62 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+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';
+
+/// The terminal's top bar: *agent · machine* over *folder ⑂ branch*, with the
+/// connection state as a dot on the engine mark.
+void main() {
+ group('the folder is named by its own name, parents folded', () {
+ for (final (cwd, label) in [
+ (
+ '/Users/dudu/Bitcoin_builder/Grid/autonomous-harness',
+ '~/…/autonomous-harness',
+ ),
+ ('/home/tony/work/harness', '~/…/harness'),
+ ('/Users/dudu/notes', '~/notes'),
+ ('/Users/dudu', '~'),
+ ('/root/app', '~/app'),
+ ('/srv', '/srv'),
+ ('/opt/tools/grid', '/…/grid'),
+ (r'C:\Users\tony\code\harness', 'C:/…/harness'),
+ ('/', '/'),
+ ]) {
+ test('$cwd → $label', () => expect(projectPathLabel(cwd), label));
+ }
+ });
+
+ testWidgets('two lines, and the state on the mark', (tester) async {
+ final agent = Agent.fromJson({
+ 'id': 'a',
+ 'name': 'agent-3',
+ 'engine': 'claude',
+ 'project': {
+ 'name': 'autonomous-harness',
+ 'cwd': '/Users/dudu/Bitcoin_builder/Grid/autonomous-harness',
+ 'branch': 'feat/mobile-ios-android',
+ },
+ });
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: TerminalHeader(
+ agent: agent,
+ machineName: 'MacBooks-MacBook-Pro-6.local',
+ status: (label: 'Live', tone: PhoneTone.good),
+ ),
+ ),
+ ),
+ );
+
+ expect(find.text('agent-3'), findsOneWidget);
+ expect(find.text('MacBooks-MacBook-Pro-6.local'), findsOneWidget);
+ expect(find.text('~/…/autonomous-harness'), findsOneWidget);
+ expect(find.text('feat/mobile-ios-android'), findsOneWidget);
+ // No word for the state — the dot says it, and its tooltip.
+ expect(find.text('Live'), findsNothing);
+ expect(find.byType(StatusDot), findsOneWidget);
+ expect(find.byTooltip('Live'), findsOneWidget);
+ });
+}
diff --git a/mobile/test/terminal_page_header_fold_test.dart b/mobile/test/terminal_page_header_fold_test.dart
index 01e089167..412328150 100644
--- a/mobile/test/terminal_page_header_fold_test.dart
+++ b/mobile/test/terminal_page_header_fold_test.dart
@@ -89,8 +89,8 @@ void main() {
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
- // Folded: the search bar is no longer where a tap would land on it.
- expect(find.text(TerminalHeader.searchHint).hitTestable(), findsNothing);
+ // Folded: the header is no longer where a tap would land on it.
+ expect(find.byType(TerminalHeader).hitTestable(), findsNothing);
expect(tester.getSize(find.byType(TerminalView)), before);
// The slide is over; a resize owed to it would be on its way by now.
await tester.pump(const Duration(seconds: 1));
@@ -113,7 +113,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
resizes.clear();
- await tester.tap(find.text(TerminalHeader.searchHint));
+ await tester.tap(find.byKey(const ValueKey('terminal-search')));
await tester.pump();
// The search field's keyboard slides up, and the page shrinks above it.
tester.view.viewInsets = const FakeViewPadding(bottom: 900);
diff --git a/mobile/test/voice_input_controller_test.dart b/mobile/test/voice_input_controller_test.dart
index 46a952e1e..e76aab2eb 100644
--- a/mobile/test/voice_input_controller_test.dart
+++ b/mobile/test/voice_input_controller_test.dart
@@ -331,4 +331,89 @@ void main() {
expect(backend.calls.single.lang, 'vi');
});
+
+ group('staging: the words go into the prompt before they are sent', () {
+ final prompt = Object();
+
+ test('done talking writes the words, and nothing is sent', () async {
+ backend.replies.add('run the tests');
+ final written = <String>[];
+ await voice.startListening();
+ await voice.stage(prompt, (text) {
+ written.add(text);
+ return true;
+ });
+
+ expect(written, ['run the tests']);
+ expect(voice.staged, 'run the tests');
+ expect(voice.isStagedIn(prompt), isTrue);
+ expect(voice.transcript, isEmpty);
+ expect(voice.isIdle, isFalse);
+ });
+
+ test('send presses Return and puts the mic at rest', () async {
+ backend.replies.add('run the tests');
+ await voice.startListening();
+ await voice.stage(prompt, (_) => true);
+ var enters = 0;
+ voice.sendStaged(() {
+ enters++;
+ return true;
+ });
+
+ expect(enters, 1);
+ expect(voice.staged, isNull);
+ expect(voice.isIdle, isTrue);
+ });
+
+ test('discarding hands the words back to be erased', () async {
+ backend.replies.add('never mind');
+ await voice.startListening();
+ await voice.stage(prompt, (_) => true);
+ final erased = <String>[];
+ voice.discardStaged(erased.add);
+
+ expect(erased, ['never mind']);
+ expect(voice.isIdle, isTrue);
+ });
+
+ test('a prompt that will not take them keeps the words here', () async {
+ backend.replies.add('run the tests');
+ await voice.startListening();
+ await voice.stage(prompt, (_) => false);
+
+ expect(voice.staged, isNull);
+ expect(voice.transcript, 'run the tests');
+ expect(voice.notice, VoiceNotice.notSent);
+ });
+
+ test('done while the mic is still opening calls it off', () async {
+ recorder.pendingPermission = Completer<bool>();
+ final starting = voice.startListening();
+ final written = <String>[];
+ await voice.stage(prompt, (text) {
+ written.add(text);
+ return true;
+ });
+ recorder.pendingPermission!.complete(true);
+ await starting;
+
+ expect(written, isEmpty);
+ expect(recorder.starts, 0);
+ expect(voice.status, VoiceInputStatus.idle);
+ });
+
+ test(
+ 'the keyboard taking over forgets them, and leaves them typed',
+ () async {
+ backend.replies.add('almost right');
+ await voice.startListening();
+ await voice.stage(prompt, (_) => true);
+
+ expect(await voice.takeTranscript(), isEmpty);
+ expect(voice.staged, isNull);
+ expect(voice.isIdle, isTrue);
+ },
+ );
+ });
}
diff --git a/mobile/test/voice_mic_fab_test.dart b/mobile/test/voice_mic_fab_test.dart
index 9e3a1f370..3ea0a7eef 100644
--- a/mobile/test/voice_mic_fab_test.dart
+++ b/mobile/test/voice_mic_fab_test.dart
@@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/phone/voice_input_controller.dart';
import 'package:harness_mobile/phone/voice_mic_fab.dart';
+import 'package:harness_mobile/phone/voice_status_pill.dart';
import 'package:harness_mobile/terminal/terminal_session.dart';
import 'voice_fakes.dart';
-/// The mic over the terminal, held to talk: press to record, release to send the
-/// take as a turn, slide off to throw it away.
+/// The mic over the terminal: tap to talk, tap when done — the words are typed
+/// into the prompt, unsent — and tap again to send them with Return. `×` in the
+/// pill beside it calls the take off, or takes the typed words back out.
void main() {
late FakeVoiceRecorder recorder;
late FakeTranscriber backend;
@@ -16,6 +18,9 @@ void main() {
late TerminalSession session;
late List<(String, Map<String, dynamic>)> frames;
+ /// What reached the prompt, keystroke by keystroke.
+ late List<String> typed;
+
final mic = find.byKey(const ValueKey('voice-mic'));
setUp(() {
@@ -41,6 +46,8 @@ void main() {
);
session.status = TerminalSessionStatus.controlling;
session.streamId = 's';
+ typed = [];
+ session.terminal.onOutput = typed.add;
});
tearDown(() {
@@ -49,8 +56,17 @@ void main() {
session.dispose();
});
- Widget fab() =>
- VoiceMicFab(voice: voice, session: session, onSlipChanged: (_) {});
+ Widget fab() => Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Flexible(
+ child: VoiceStatusPill(voice: voice, session: session),
+ ),
+ VoiceMicFab(voice: voice, session: session),
+ ],
+ );
+
+ final cancel = find.byKey(const ValueKey('voice-cancel'));
Future<void> pumpFab(WidgetTester tester, {Widget? around}) =>
tester.pumpWidget(
@@ -64,130 +80,106 @@ void main() {
if (type == 'message') payload['content'],
];
- testWidgets('hold to talk, release to send it as a turn', (tester) async {
+ testWidgets('tap, talk, tap: the words are typed into the prompt, unsent', (
+ tester,
+ ) async {
await pumpFab(tester);
backend.replies.add('summarise the diff');
- final thumb = await tester.startGesture(tester.getCenter(mic));
+ await tester.tap(mic);
await tester.pump();
expect(voice.status, VoiceInputStatus.listening);
- await thumb.up();
- await tester.pumpAndSettle();
+ await tester.tap(mic);
+ await tester.pump();
+ await tester.pump();
- // The composer's frame, not typed bytes — the machine owns the Enter.
- expect(sentTurns(), ['summarise the diff']);
- expect(voice.isIdle, isTrue);
+ expect(typed, ['summarise the diff']);
+ expect(sentTurns(), isEmpty);
+ expect(find.text('Tap ↑ to send'), findsOneWidget);
+ await tester.pumpAndSettle();
});
- testWidgets('sliding off before letting go throws the take away', (
- tester,
- ) async {
+ testWidgets('a third tap sends them with Return', (tester) async {
await pumpFab(tester);
- backend.replies.add('never mind');
+ backend.replies.add('ship it');
- final thumb = await tester.startGesture(tester.getCenter(mic));
+ await tester.tap(mic);
await tester.pump();
- await thumb.moveBy(const Offset(0, -300));
+ await tester.tap(mic);
await tester.pump();
- await thumb.up();
+ await tester.pump();
+ await tester.tap(mic);
await tester.pumpAndSettle();
- expect(recorder.cancels, 1);
- expect(frames, isEmpty);
+ expect(typed, ['ship it', '\r']);
+ expect(voice.isIdle, isTrue);
+ expect(find.text('Tap ↑ to send'), findsNothing);
});
- testWidgets('no talking while the terminal takes no input', (tester) async {
- session.status = TerminalSessionStatus.takenOver;
+ testWidgets('× while talking throws the take away', (tester) async {
await pumpFab(tester);
+ backend.replies.add('never mind');
- final thumb = await tester.startGesture(tester.getCenter(mic));
+ await tester.tap(mic);
await tester.pump();
- await thumb.up();
+ await tester.tap(cancel);
await tester.pumpAndSettle();
- expect(recorder.starts, 0);
- expect(frames, isEmpty);
+ expect(recorder.cancels, 1);
+ expect(backend.calls, isEmpty);
+ expect(typed, isEmpty);
+ expect(voice.isIdle, isTrue);
});
- testWidgets('a thumb drifting sideways mid-take does not swipe the pager', (
- tester,
- ) async {
- final pager = PageController();
- addTearDown(pager.dispose);
- await pumpFab(
- tester,
- around: PageView(
- controller: pager,
- children: [
- Center(child: fab()),
- const SizedBox.expand(),
- ],
- ),
- );
+ testWidgets('× once the words are typed takes them back out', (tester) async {
+ await pumpFab(tester);
+ backend.replies.add('xin chào');
- final thumb = await tester.startGesture(tester.getCenter(mic));
+ await tester.tap(mic);
+ await tester.pump();
+ await tester.tap(mic);
+ await tester.pump();
await tester.pump();
- // Past half the page: a pager that had the thumb would settle on the next
- // agent rather than snap back.
- for (var step = 0; step < 6; step++) {
- await thumb.moveBy(const Offset(-100, 0));
- await tester.pump();
- }
- await thumb.up();
+ await tester.tap(cancel);
await tester.pumpAndSettle();
- expect(pager.page, 0);
+ // One Backspace per character, counted in runes.
+ expect(typed.first, 'xin chào');
+ expect(typed.skip(1), List.filled('xin chào'.runes.length, '\x7f'));
+ expect(frames, isEmpty);
+ expect(voice.isIdle, isTrue);
});
- testWidgets('a second finger does not end the first one\'s take', (
- tester,
- ) async {
+ testWidgets('no talking while the terminal takes no input', (tester) async {
+ session.status = TerminalSessionStatus.takenOver;
await pumpFab(tester);
- backend.replies.add('ship it');
- final first = await tester.startGesture(tester.getCenter(mic));
- await tester.pump();
- final second = await tester.startGesture(tester.getCenter(mic), pointer: 7);
- await second.up();
- // `pump`, not `pumpAndSettle`: the listening ring never settles, and running
- // the clock out would end the take on its own five-minute limit.
- await tester.pump(const Duration(milliseconds: 100));
- expect(voice.status, VoiceInputStatus.listening);
- expect(frames, isEmpty);
-
- await first.up();
+ await tester.tap(mic);
await tester.pumpAndSettle();
- expect(sentTurns(), ['ship it']);
+ expect(recorder.starts, 0);
+ expect(frames, isEmpty);
});
- testWidgets('a hold whose mic leaves the screen is cancelled', (
+ testWidgets('words typed on another agent do not arm this send', (
tester,
) async {
- final shown = ValueNotifier(true);
- addTearDown(shown.dispose);
- await pumpFab(
- tester,
- around: ValueListenableBuilder<bool>(
- valueListenable: shown,
- builder: (context, on, _) =>
- Center(child: on ? fab() : const SizedBox.shrink()),
- ),
- );
+ await pumpFab(tester);
+ backend.replies.add('for the other one');
+ final other = Object();
+ await voice.startListening();
+ await voice.stage(other, (_) => true);
+ await tester.pump();
- final thumb = await tester.startGesture(tester.getCenter(mic));
+ // This page's mic is at rest: a tap starts a new take rather than
+ // pressing Return in a prompt nobody here is looking at.
+ expect(find.text('Tap ↑ to send'), findsNothing);
+ await tester.tap(mic);
await tester.pump();
expect(voice.status, VoiceInputStatus.listening);
-
- // The keyboard coming up, say — the page drops the mic under the thumb.
- shown.value = false;
- await tester.pumpAndSettle();
-
- expect(recorder.cancels, 1);
- expect(voice.isIdle, isTrue);
- await thumb.up();
+ expect(typed, isEmpty);
+ voice.clear();
await tester.pumpAndSettle();
- expect(frames, isEmpty);
});
}