The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(mobile): harden hold-to-talk voice input
Dev jacob571f86669c8d
diff --git a/mobile/lib/phone/voice_input_controller.dart b/mobile/lib/phone/voice_input_controller.dartindex 66c94f08e..da5d4f23c 100644--- a/mobile/lib/phone/voice_input_controller.dart+++ b/mobile/lib/phone/voice_input_controller.dart@@ -118,6 +118,7 @@ class VoiceInputController extends ChangeNotifier {/// 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.void clear() {+ if (_disposed) return;_abandonTake();_heard = '';_setStatus(VoiceInputStatus.idle);@@ -238,8 +239,12 @@ class VoiceInputController extends ChangeNotifier {var sent = false;try {sent = await deliver(text);- } on Exception {+ } catch (error) {// Reported below exactly like a refusal: the words stay, Send stays live.+ // ⚠️ Every throwable, not only [Exception]: anything that escaped here+ // would leave [isSending] set, and the mic busy for the pager's life.+ // The type only: what failed to send is what someone said.+ appLog.warn('voice', 'send failed: ${error.runtimeType}');}_isSending = false;if (sent) _heard = '';@@ -308,7 +313,10 @@ class VoiceInputController extends ChangeNotifier {notice: words.isEmpty ? VoiceNotice.nothingHeard : null,);return words.isNotEmpty;- } on Exception catch (error) {+ } catch (error) {+ // ⚠️ Every throwable, not only [Exception]: a reply of an unexpected shape+ // fails as a TypeError, and one that escaped would leave the status on+ // `transcribing` — the mic busy, for good, until the pager is closed.appLog.warn('voice', 'stt[${_language.value}] failed', error: error);if (take == _take) {_setStatus(VoiceInputStatus.idle, notice: VoiceNotice.notTranscribed);@@ -355,7 +363,11 @@ class VoiceInputController extends ChangeNotifier {void _restartNoticeTimer() {_noticeLimit?.cancel();_noticeLimit = null;- if (_notice == null || _status == VoiceInputStatus.unavailable) return;+ if (_disposed ||+ _notice == null ||+ _status == VoiceInputStatus.unavailable) {+ return;+ }_noticeLimit = Timer(noticeLinger, () {_noticeLimit = null;// Only if it is still the same notice: anything that has set another onediff --git a/mobile/lib/phone/voice_mic_action.dart b/mobile/lib/phone/voice_mic_action.dartindex 0ce7b13f1..f3827d1e9 100644--- a/mobile/lib/phone/voice_mic_action.dart+++ b/mobile/lib/phone/voice_mic_action.dart@@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart';import 'package:harness_mobile/terminal/terminal_session.dart';import 'voice_input_controller.dart';-import 'voice_mic_button.dart';+import 'voice_mic_face.dart';import 'voice_mic_mode.dart';typedef VoiceMicAction = ({diff --git a/mobile/lib/phone/voice_mic_button.dart b/mobile/lib/phone/voice_mic_button.dartindex f5458c2a1..86e8ffbf8 100644--- a/mobile/lib/phone/voice_mic_button.dart+++ b/mobile/lib/phone/voice_mic_button.dart@@ -1,42 +1,13 @@+import 'dart:async';+import 'package:flutter/material.dart';import 'package:flutter/services.dart';-import 'package:lucide_icons_flutter/lucide_icons.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';-import 'package:harness_mobile/shared/widgets/pulse.dart';+import 'voice_mic_face.dart';import 'voice_mic_mode.dart';-/// What the mic says it will do when tapped.-enum VoiceMicFace {- /// At rest: tap to talk.- talk,-- /// The microphone is opening: tap to call it off.- starting,-- /// Recording: tap to send what was said. It breathes while it listens.- listening,-- /// Transcribing or sending: nothing to tap until that is back.- busy,-- /// A send failed and its words are held: tap to send them again.- retry,-- /// The microphone was refused: tap to ask again.- off,-- /// Recording with the thumb dragged off the button — letting go now throws- /// the take away. [VoiceMicMode.holdToTalk] only.- ///- /// Its own face rather than a flag on [listening] because it is the opposite- /// promise: the ring stops breathing, the fill goes to the warning colour and- /// the glyph becomes a `×`. What is about to happen has to be readable at a- /// glance, by someone whose thumb is covering the button.- cancelling,-}-/// The one voice control on a terminal page — a small round button floating/// over the terminal's bottom right corner. [VoiceMicFab] is what places it.///@@ -118,9 +89,6 @@ class VoiceMicButton extends StatefulWidget {/// presses. See the gap above the mic in `voice_mic_fab.dart`.static const double touchOverhang = (touchExtent - extent) / 2;- /// The visible circle.- static const double _core = 48;-/// How far past [touchExtent] the thumb may stray and still count as "on" the/// button.///@@ -139,6 +107,14 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {/// progress. Drives the [VoiceMicFace.cancelling] face.bool _slippedOff = false;+ /// The pointer holding the mic down, or null with no hold in progress.+ ///+ /// ⚠️ Only the pointer that STARTED a hold may finish it. A press that landed+ /// while the button was dead started nothing, and its release must not send+ /// words held from an earlier failed send; a second finger must not end the+ /// first one's take.+ int? _holdPointer;+bool get _live => widget.onPressed != null;/// What to draw: the face given, unless a hold has been dragged off the@@ -183,14 +159,15 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {}void _onPointerDown(PointerDownEvent event) {- if (!_live) return;+ if (!_live || _holdPointer != null) return;+ _holdPointer = event.pointer;_setSlipped(false);HapticFeedback.lightImpact();widget.onHoldStart?.call();}void _onPointerMove(PointerMoveEvent event) {- if (!_live || widget.onHoldFinish == null) return;+ if (event.pointer != _holdPointer || widget.onHoldFinish == null) return;final off = !_within(event.localPosition);if (off == _slippedOff) return;// Felt as well as seen: the thumb is over the button, so the change of@@ -200,19 +177,41 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {}void _onPointerUp(PointerUpEvent event) {- if (widget.onHoldFinish == null) return;+ if (event.pointer != _holdPointer) return;+ _holdPointer = null;final cancelled = _slippedOff;_setSlipped(false);- widget.onHoldFinish!(cancelled: cancelled);+ widget.onHoldFinish?.call(cancelled: cancelled);}- /// The gesture was taken over by something else — a scroll that won the- /// arena, the app going away. Treated as a cancel: a take nobody ended- /// deliberately must not be sent.+ /// The gesture was taken away by the system — the app going away. Treated as+ /// a cancel: a take nobody ended deliberately must not be sent.void _onPointerCancel(PointerCancelEvent event) {- if (widget.onHoldFinish == null) return;+ if (event.pointer != _holdPointer) return;+ _holdPointer = null;_setSlipped(false);- widget.onHoldFinish!(cancelled: true);+ widget.onHoldFinish?.call(cancelled: true);+ }++ /// ⚠️ **A hold whose button leaves the tree mid-take is cancelled.** The+ /// button is unmounted while the thumb is still down whenever the page drops+ /// it — the keyboard coming up, the pane going away — and the release then+ /// reaches no one: without this the microphone stays open with no thumb on it+ /// until [VoiceInputController.maxTake] ends it.+ ///+ /// Deferred to a microtask: the cancel notifies listeners that rebuild, and+ /// the tree is locked while it is being finalised.+ @override+ void dispose() {+ if (_holdPointer != null) {+ final finish = widget.onHoldFinish;+ final slipChanged = _slippedOff ? widget.onSlipChanged : null;+ scheduleMicrotask(() {+ slipChanged?.call(false);+ finish?.call(cancelled: true);+ });+ }+ super.dispose();}/// ⚠️ Tells the row BEFORE rebuilding itself. The listener sits in an ancestor@@ -281,8 +280,8 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {// ⚠️ Not while cancelling: the ring means "listening, carry// on talking", and leaving it breathing under a `×` would// say both things at once.- if (_face == VoiceMicFace.listening) const _Ring(),- _Core(face: _face, lit: _lit),+ if (_face == VoiceMicFace.listening) const VoiceMicRing(),+ VoiceMicCore(face: _face, lit: _lit),],),),@@ -319,155 +318,25 @@ class _VoiceMicButtonState extends State<VoiceMicButton> {child: child,);}- return Listener(- key: const ValueKey('voice-mic'),+ // ⚠️ **The drag recognizers are here to WIN the arena, and do nothing else.**+ // A [Listener] never enters the gesture arena, so the pager this button sits+ // in would otherwise take any thumb that shifted past touch slop mid-sentence+ // and swipe to the next agent under a live take. Being deeper in the tree,+ // these accept first and the pager's drag never starts; the raw pointer+ // events above keep arriving either way.+ return GestureDetector(behavior: HitTestBehavior.opaque,- onPointerDown: _onPointerDown,- onPointerMove: _onPointerMove,- onPointerUp: _onPointerUp,- onPointerCancel: _onPointerCancel,- child: child,- );- }-}--class _Core extends StatelessWidget {- const _Core({required this.face, required this.lit});-- final VoiceMicFace face;- final bool lit;-- /// The fill's hue. Cancelling takes the warning colour: the button is about- /// to throw away what was just said, and that is not something the accent —- /// which everywhere else in the app means "go" — should be saying.- Color get _tint =>- face == VoiceMicFace.cancelling ? AppPalette.warn : AppPalette.accent;-- @override- Widget build(BuildContext context) => AnimatedContainer(- duration: const Duration(milliseconds: 220),- curve: Curves.easeOutCubic,- width: VoiceMicButton._core,- height: VoiceMicButton._core,- decoration: BoxDecoration(- shape: BoxShape.circle,- gradient: lit- ? LinearGradient(- begin: Alignment.topLeft,- end: Alignment.bottomRight,- colors: [Color.lerp(_tint, Colors.white, 0.18)!, _tint],- )- : null,- color: lit ? null : AppGlass.surfaceFill,- border: Border.all(- color: lit ? Colors.white.withValues(alpha: 0.28) : AppGlass.lift,- ),- // ⚠️ **Two different shadows for two different jobs, and the resting one- // is not optional.** Lit, the button glows in its own colour — that is- // state, saying the mic is open. At rest it casts a plain drop shadow- // instead: it floats over streaming output rather than over a surface, and- // without one its edge disappears against every dark line it happens to- // sit on. The screenshot that prompted this had it all but invisible.- boxShadow: lit- ? [- BoxShadow(color: _tint.withValues(alpha: 0.4), blurRadius: 12),- // The lift, under the glow. The glow says "recording"; it does- // not separate the circle from the text behind it, because it is- // the same brightness as the accent the terminal itself uses.- BoxShadow(- color: Colors.black.withValues(alpha: 0.35),- blurRadius: 10,- offset: const Offset(0, 3),- ),- ]- : [- // Cast down and soft: enough to lift the circle off the text- // behind it without reading as a second ring around it.- BoxShadow(- color: Colors.black.withValues(alpha: 0.45),- blurRadius: 12,- offset: const Offset(0, 3),- ),- // A tight, darker core under the edge, which is what keeps the- // outline readable where the blur alone washes out over a bright- // line of output.- BoxShadow(- color: Colors.black.withValues(alpha: 0.3),- blurRadius: 3,- offset: const Offset(0, 1),- ),- ],- ),- child: Center(- child: AnimatedSwitcher(- duration: const Duration(milliseconds: 160),- child: _Glyph(key: ValueKey(face), face: face, lit: lit),+ onHorizontalDragStart: (_) {},+ onVerticalDragStart: (_) {},+ child: Listener(+ key: const ValueKey('voice-mic'),+ behavior: HitTestBehavior.opaque,+ onPointerDown: _onPointerDown,+ onPointerMove: _onPointerMove,+ onPointerUp: _onPointerUp,+ onPointerCancel: _onPointerCancel,+ child: child,),- ),- );-}--class _Glyph extends StatelessWidget {- const _Glyph({super.key, required this.face, required this.lit});-- final VoiceMicFace face;- final bool lit;-- @override- Widget build(BuildContext context) {- if (face == VoiceMicFace.busy) {- return SizedBox.square(- dimension: 21,- child: CircularProgressIndicator(- strokeWidth: 2.4,- color: AppPalette.accent,- ),- );- }- return Icon(- switch (face) {- // ⚠️ 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.- VoiceMicFace.listening =>- micHoldsToTalk ? LucideIcons.mic300 : LucideIcons.arrowUp300,- VoiceMicFace.retry => LucideIcons.arrowUp300,- VoiceMicFace.cancelling => LucideIcons.x300,- VoiceMicFace.off => LucideIcons.micOff300,- VoiceMicFace.talk ||- VoiceMicFace.starting ||- VoiceMicFace.busy => LucideIcons.mic300,- },- size: 25,- color: lit- ? Colors.white- : face == VoiceMicFace.off- ? AppPalette.textFaint- : AppPalette.textPrimary,);}}--/// The glow that swells out of the button while it listens, on the app's one-/// [Pulse] — which is also what holds it still under Reduce Motion.-class _Ring extends StatelessWidget {- const _Ring();-- @override- Widget build(BuildContext context) => Pulse(- duration: const Duration(milliseconds: 900),- curve: Curves.easeOut,- builder: (context, t, _) => Transform.scale(- scale: 1 + 0.45 * t,- child: Container(- width: VoiceMicButton._core,- height: VoiceMicButton._core,- decoration: BoxDecoration(- shape: BoxShape.circle,- color: AppPalette.accent.withValues(alpha: 0.35 * (1 - t)),- ),- ),- ),- );-}diff --git a/mobile/lib/phone/voice_mic_face.dart b/mobile/lib/phone/voice_mic_face.dartnew file mode 100644index 000000000..3c3ed1e32--- /dev/null+++ b/mobile/lib/phone/voice_mic_face.dart@@ -0,0 +1,183 @@+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/shared/widgets/pulse.dart';++import 'voice_mic_mode.dart';++/// What the mic says it will do when tapped.+enum VoiceMicFace {+ /// At rest: tap to talk.+ talk,++ /// The microphone is opening: tap to call it off.+ starting,++ /// Recording: tap to send what was said. It breathes while it listens.+ listening,++ /// Transcribing or sending: nothing to tap until that is back.+ busy,++ /// A send failed and its words are held: tap to send them again.+ retry,++ /// The microphone was refused: tap to ask again.+ off,++ /// Recording with the thumb dragged off the button — letting go now throws+ /// the take away. [VoiceMicMode.holdToTalk] only.+ ///+ /// Its own face rather than a flag on [listening] because it is the opposite+ /// promise: the ring stops breathing, the fill goes to the warning colour and+ /// the glyph becomes a `×`. What is about to happen has to be readable at a+ /// glance, by someone whose thumb is covering the button.+ cancelling,+}++/// The round, filled part of the mic: its colour, its glow, and the glyph for+/// what a press will do.+class VoiceMicCore extends StatelessWidget {+ const VoiceMicCore({super.key, required this.face, required this.lit});++ /// The visible circle's diameter — the ring breathes out from the same size.+ static const double diameter = 48;++ final VoiceMicFace face;+ final bool lit;++ /// The fill's hue. Cancelling takes the warning colour: the button is about+ /// to throw away what was just said, and that is not something the accent —+ /// which everywhere else in the app means "go" — should be saying.+ Color get _tint =>+ face == VoiceMicFace.cancelling ? AppPalette.warn : AppPalette.accent;++ @override+ Widget build(BuildContext context) => AnimatedContainer(+ duration: const Duration(milliseconds: 220),+ curve: Curves.easeOutCubic,+ width: VoiceMicCore.diameter,+ height: VoiceMicCore.diameter,+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ gradient: lit+ ? LinearGradient(+ begin: Alignment.topLeft,+ end: Alignment.bottomRight,+ colors: [Color.lerp(_tint, Colors.white, 0.18)!, _tint],+ )+ : null,+ color: lit ? null : AppGlass.surfaceFill,+ border: Border.all(+ color: lit ? Colors.white.withValues(alpha: 0.28) : AppGlass.lift,+ ),+ // ⚠️ **Two different shadows for two different jobs, and the resting one+ // is not optional.** Lit, the button glows in its own colour — that is+ // state, saying the mic is open. At rest it casts a plain drop shadow+ // instead: it floats over streaming output rather than over a surface, and+ // without one its edge disappears against every dark line it happens to+ // sit on. The screenshot that prompted this had it all but invisible.+ boxShadow: lit+ ? [+ BoxShadow(color: _tint.withValues(alpha: 0.4), blurRadius: 12),+ // The lift, under the glow. The glow says "recording"; it does+ // not separate the circle from the text behind it, because it is+ // the same brightness as the accent the terminal itself uses.+ BoxShadow(+ color: Colors.black.withValues(alpha: 0.35),+ blurRadius: 10,+ offset: const Offset(0, 3),+ ),+ ]+ : [+ // Cast down and soft: enough to lift the circle off the text+ // behind it without reading as a second ring around it.+ BoxShadow(+ color: Colors.black.withValues(alpha: 0.45),+ blurRadius: 12,+ offset: const Offset(0, 3),+ ),+ // A tight, darker core under the edge, which is what keeps the+ // outline readable where the blur alone washes out over a bright+ // line of output.+ BoxShadow(+ color: Colors.black.withValues(alpha: 0.3),+ blurRadius: 3,+ offset: const Offset(0, 1),+ ),+ ],+ ),+ child: Center(+ child: AnimatedSwitcher(+ duration: const Duration(milliseconds: 160),+ child: _Glyph(key: ValueKey(face), face: face, lit: lit),+ ),+ ),+ );+}++class _Glyph extends StatelessWidget {+ const _Glyph({super.key, required this.face, required this.lit});++ final VoiceMicFace face;+ final bool lit;++ @override+ Widget build(BuildContext context) {+ if (face == VoiceMicFace.busy) {+ return SizedBox.square(+ dimension: 21,+ child: CircularProgressIndicator(+ strokeWidth: 2.4,+ color: AppPalette.accent,+ ),+ );+ }+ return Icon(+ switch (face) {+ // ⚠️ 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.+ VoiceMicFace.listening =>+ micHoldsToTalk ? LucideIcons.mic300 : LucideIcons.arrowUp300,+ VoiceMicFace.retry => LucideIcons.arrowUp300,+ VoiceMicFace.cancelling => LucideIcons.x300,+ VoiceMicFace.off => LucideIcons.micOff300,+ VoiceMicFace.talk ||+ VoiceMicFace.starting ||+ VoiceMicFace.busy => LucideIcons.mic300,+ },+ size: 25,+ color: lit+ ? Colors.white+ : face == VoiceMicFace.off+ ? AppPalette.textFaint+ : AppPalette.textPrimary,+ );+ }+}++/// The glow that swells out of the button while it listens, on the app's one+/// [Pulse] — which is also what holds it still under Reduce Motion.+class VoiceMicRing extends StatelessWidget {+ const VoiceMicRing({super.key});++ @override+ Widget build(BuildContext context) => Pulse(+ duration: const Duration(milliseconds: 900),+ curve: Curves.easeOut,+ builder: (context, t, _) => Transform.scale(+ scale: 1 + 0.45 * t,+ child: Container(+ width: VoiceMicCore.diameter,+ height: VoiceMicCore.diameter,+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ color: AppPalette.accent.withValues(alpha: 0.35 * (1 - t)),+ ),+ ),+ ),+ );+}diff --git a/mobile/lib/phone/voice_recorder.dart b/mobile/lib/phone/voice_recorder.dartindex 330f93db3..fb9e406b6 100644--- a/mobile/lib/phone/voice_recorder.dart+++ b/mobile/lib/phone/voice_recorder.dart@@ -61,8 +61,25 @@ class MicVoiceRecorder implements VoiceRecorder {@overrideFuture<bool> allowed() => _recorder.hasPermission();+ /// The tail of the operations running on the plugin, one at a time.+ ///+ /// ⚠️ **Serial, because the controller fires `cancel` without awaiting it.**+ /// A take slid off and a new hold pressed straight after would otherwise run+ /// the old cancel's `_discardTake` AFTER the new start had subscribed — the new+ /// take's stream cancelled under it, coming back as "No sound reached the+ /// microphone" — or land the plugin's own cancel on the new recording.+ Future<void> _tail = Future.value();++ Future<T> _serially<T>(Future<T> Function() operation) {+ final result = _tail.then((_) => operation());+ _tail = result.then((_) {}, onError: (Object _) {});+ return result;+ }+@override- Future<void> start() async {+ Future<void> start() => _serially(_start);++ Future<void> _start() async {await _discardTake();_sampleRate = _requested.sampleRate;_channels = _requested.numChannels;@@ -80,13 +97,18 @@ class MicVoiceRecorder implements VoiceRecorder {}@override- Future<VoiceTake?> stop() async {+ Future<VoiceTake?> stop() => _serially(_stop);++ Future<VoiceTake?> _stop() async {final drained = _drained;if (drained == null) return null;await _recorder.stop();// The plugin's own rule: the last buffer arrives with the stream's close,// not with `stop()`, so the take is only whole once the stream is done.await drained.future.timeout(const Duration(seconds: 2), onTimeout: () {});+ // Cancelled rather than dropped: after a timeout the stream is still open,+ // and a late buffer would otherwise land in the NEXT take.+ await _subscription?.cancel();_subscription = null;_drained = null;final pcm = _pcm.takeBytes();@@ -100,14 +122,18 @@ class MicVoiceRecorder implements VoiceRecorder {}@override- Future<void> cancel() async {+ Future<void> cancel() => _serially(_cancel);++ Future<void> _cancel() async {if (_drained == null) return;await _recorder.cancel();await _discardTake();}@override- Future<void> dispose() async {+ Future<void> dispose() => _serially(_dispose);++ Future<void> _dispose() async {await _discardTake();await _recorder.dispose();}diff --git a/mobile/test/terminal_foot_bar_test.dart b/mobile/test/terminal_foot_bar_test.dartindex a68a8d095..7e2982c0d 100644--- a/mobile/test/terminal_foot_bar_test.dart+++ b/mobile/test/terminal_foot_bar_test.dart@@ -3,22 +3,23 @@ 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 'package:harness_mobile/terminal/terminal_session.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;- late TerminalSession session;- late List<(String, Map<String, dynamic>)> frames;const live = (label: 'Live', tone: PhoneTone.good);- final mic = find.byKey(const ValueKey('voice-mic'));- final cancel = find.byKey(const ValueKey('voice-cancel'));+ final dismiss = find.byKey(const ValueKey('voice-cancel'));setUp(() {recorder = FakeVoiceRecorder();@@ -29,133 +30,87 @@ void main() {recorder: recorder,language: language,);- frames = [];- session =- TerminalSession(- machineId: 'm',- agentId: 'a',- agentName: 'Agent',- engineId: 'claude',- send: (type, payload) async {- frames.add((type, payload));- return true;- },- sendBinary: (_) async => true,- )- ..status = TerminalSessionStatus.controlling- ..streamId = 's';});tearDown(() {voice.dispose();language.dispose();- session.dispose();});- Future<void> pumpBar(WidgetTester tester) => tester.pumpWidget(- MaterialApp(- home: Scaffold(- body: Align(- alignment: Alignment.bottomCenter,- child: TerminalFootBar(- name: 'MacBookPro2021.local',- status: live,- voice: voice,- session: session,+ 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 is the machine, its state, and one mic', (- tester,- ) async {+ 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(mic, findsOneWidget);- expect(cancel, findsNothing);- expect(recorder.starts, 0);+ expect(dismiss, findsNothing);});- testWidgets('tap to talk, tap again to send it as a turn', (tester) async {+ testWidgets('while recording it says what the mic is doing', (tester) async {await pumpBar(tester);- backend.replies.add('summarise the diff');- await tester.tap(mic);- await tester.pump();- expect(voice.status, VoiceInputStatus.listening);- expect(find.text('Listening…'), findsOneWidget);-- await tester.tap(mic);+ await voice.startListening();await tester.pumpAndSettle();- // The composer's frame, not typed bytes — the machine owns the Enter.- expect(frames, hasLength(1));- expect(frames.single.$1, 'message');- expect(frames.single.$2['content'], 'summarise the diff');- expect(voice.isIdle, isTrue);- 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 tester.tap(mic);- await tester.pump();-- expect(tester.getSize(find.byType(TerminalFootBar)), atRest);+ expect(find.text(voiceActivityLabel(voice)!), findsOneWidget);+ expect(find.text('MacBookPro2021.local'), findsNothing);voice.clear();await tester.pumpAndSettle();});- testWidgets('× throws a take away and sends nothing', (tester) async {- await pumpBar(tester);- await tester.tap(mic);- await tester.pump();-- await tester.tap(cancel);+ testWidgets('a hold dragged off the mic says letting go cancels', (+ tester,+ ) async {+ await pumpBar(tester, slippedOff: true);await tester.pumpAndSettle();- expect(recorder.cancels, 1);- expect(frames, isEmpty);- expect(cancel, findsNothing);- expect(find.text('Live'), findsOneWidget);+ expect(find.text('Release to cancel'), findsOneWidget);});- testWidgets('a failed send keeps the words, and the mic sends them again', (- tester,- ) async {- session.status = TerminalSessionStatus.takenOver;+ testWidgets('a failed send says so, and × puts the row back', (tester) async {await pumpBar(tester);backend.replies.add('deploy');await voice.startListening();- await tester.pump();-- await tester.tap(mic);+ await voice.stopListening();+ await voice.submit((_) async => false);await tester.pumpAndSettle();- expect(frames, isEmpty);+expect(find.text(VoiceNotice.notSent), findsOneWidget);- expect(voice.transcript, 'deploy');- session.status = TerminalSessionStatus.controlling;- await pumpBar(tester);- await tester.tap(mic);+ // 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(frames.single.$2['content'], 'deploy');+ expect(voice.transcript, isEmpty);+ expect(find.text('MacBookPro2021.local'), findsOneWidget);});- testWidgets('no talking while the terminal takes no input', (tester) async {- session.status = TerminalSessionStatus.takenOver;+ testWidgets('the height holds still whatever the row says', (tester) async {await pumpBar(tester);+ final atRest = tester.getSize(find.byType(TerminalFootBar));- await tester.tap(mic, warnIfMissed: false);- await tester.pump();+ await voice.startListening();+ await tester.pumpAndSettle();- expect(recorder.starts, 0);+ expect(tester.getSize(find.byType(TerminalFootBar)), atRest);+ voice.clear();+ await tester.pumpAndSettle();});}diff --git a/mobile/test/voice_mic_fab_test.dart b/mobile/test/voice_mic_fab_test.dartnew file mode 100644index 000000000..9e3a1f370--- /dev/null+++ b/mobile/test/voice_mic_fab_test.dart@@ -0,0 +1,193 @@+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/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.+void main() {+ late FakeVoiceRecorder recorder;+ late FakeTranscriber backend;+ late ValueNotifier<String> language;+ late VoiceInputController voice;+ late TerminalSession session;+ late List<(String, Map<String, dynamic>)> frames;++ final mic = find.byKey(const ValueKey('voice-mic'));++ setUp(() {+ recorder = FakeVoiceRecorder();+ backend = FakeTranscriber();+ language = ValueNotifier('en');+ voice = VoiceInputController(+ transcriber: backend.call,+ recorder: recorder,+ language: language,+ );+ frames = [];+ session = TerminalSession(+ machineId: 'm',+ agentId: 'a',+ agentName: 'Agent',+ engineId: 'claude',+ send: (type, payload) async {+ frames.add((type, payload));+ return true;+ },+ sendBinary: (_) async => true,+ );+ session.status = TerminalSessionStatus.controlling;+ session.streamId = 's';+ });++ tearDown(() {+ voice.dispose();+ language.dispose();+ session.dispose();+ });++ Widget fab() =>+ VoiceMicFab(voice: voice, session: session, onSlipChanged: (_) {});++ Future<void> pumpFab(WidgetTester tester, {Widget? around}) =>+ tester.pumpWidget(+ MaterialApp(+ home: Scaffold(body: around ?? Center(child: fab())),+ ),+ );++ List<Object?> sentTurns() => [+ for (final (type, payload) in frames)+ if (type == 'message') payload['content'],+ ];++ testWidgets('hold to talk, release to send it as a turn', (tester) async {+ await pumpFab(tester);+ backend.replies.add('summarise the diff');++ final thumb = await tester.startGesture(tester.getCenter(mic));+ await tester.pump();+ expect(voice.status, VoiceInputStatus.listening);++ await thumb.up();+ await tester.pumpAndSettle();++ // The composer's frame, not typed bytes — the machine owns the Enter.+ expect(sentTurns(), ['summarise the diff']);+ expect(voice.isIdle, isTrue);+ });++ testWidgets('sliding off before letting go throws the take away', (+ tester,+ ) async {+ await pumpFab(tester);+ backend.replies.add('never mind');++ final thumb = await tester.startGesture(tester.getCenter(mic));+ await tester.pump();+ await thumb.moveBy(const Offset(0, -300));+ await tester.pump();+ await thumb.up();+ await tester.pumpAndSettle();++ expect(recorder.cancels, 1);+ expect(frames, isEmpty);+ });++ testWidgets('no talking while the terminal takes no input', (tester) async {+ session.status = TerminalSessionStatus.takenOver;+ await pumpFab(tester);++ final thumb = await tester.startGesture(tester.getCenter(mic));+ await tester.pump();+ await thumb.up();+ await tester.pumpAndSettle();++ expect(recorder.starts, 0);+ expect(frames, isEmpty);+ });++ 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(),+ ],+ ),+ );++ final thumb = await tester.startGesture(tester.getCenter(mic));+ 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.pumpAndSettle();++ expect(pager.page, 0);+ });++ testWidgets('a second finger does not end the first one\'s take', (+ tester,+ ) async {+ 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.pumpAndSettle();++ expect(sentTurns(), ['ship it']);+ });++ testWidgets('a hold whose mic leaves the screen is cancelled', (+ 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()),+ ),+ );++ final thumb = await tester.startGesture(tester.getCenter(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();+ await tester.pumpAndSettle();+ expect(frames, isEmpty);+ });+}