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
Refactor voice input handling and language selection
Dev jacob3bb3c3cb0bfe
diff --git a/mobile/RELEASE.md b/mobile/RELEASE.mdindex 080e47e0f..caddd3b34 100644--- a/mobile/RELEASE.md+++ b/mobile/RELEASE.md@@ -185,9 +185,9 @@ owned by the user's own machine, which is why an account with no paired machineThe camera permission is used only when sending a photo into a session (Agents ▸ a session ▸ theimage button).-The microphone permission is used only for voice input: tapping a session's terminal records what is-said, and it is transcribed into the message sent to that session (Agents ▸ a session ▸ tap the-terminal).+The microphone permission is used only for voice input: the mic button under a session's terminal+records what is said, and it is transcribed into the message sent to that session (a session ▸ the+mic at the bottom right).```## Submittingdiff --git a/mobile/lib/core/startup.dart b/mobile/lib/core/startup.dartindex e036b24e8..9962d3d94 100644--- a/mobile/lib/core/startup.dart+++ b/mobile/lib/core/startup.dart@@ -1,4 +1,4 @@-import '../phone/phone_input_mode_store.dart';+import '../phone/voice_language_store.dart';import '../shared/theme/appearance_prefs_store.dart';import '../stats/harness_stats.dart';import '../terminal/terminal_font_store.dart';@@ -21,7 +21,7 @@ Future<void> loadPersistedSettings({TerminalThemeStore? terminalTheme,AppearancePrefsStore? appearance,HarnessStats? stats,- PhoneInputModeStore? inputMode,+ VoiceLanguageStore? voiceLanguage,}) async {// Independent stores may load together, but all must finish before runApp.// Font and appearance share a serialized file store; each reads its related@@ -38,8 +38,8 @@ Future<void> loadPersistedSettings({// Counters begin moving with the first agent event. Loading them later// could overwrite a new event with the old count from disk.(stats ?? harnessStats).load(),- // What the first tap on a terminal opens. Read late, that tap could open voice input for- // somebody who chose the keyboard.- (inputMode ?? phoneInputModeStore).load(),+ // The language the mic transcribes in. Read late, a first take could be sent to the backend+ // in the phone's language by somebody who chose another.+ (voiceLanguage ?? voiceLanguageStore).load(),]);}diff --git a/mobile/lib/phone/agent_swipe.dart b/mobile/lib/phone/agent_swipe.dartindex 3ea4b4e5d..3656b0dbf 100644--- a/mobile/lib/phone/agent_swipe.dart+++ b/mobile/lib/phone/agent_swipe.dart@@ -133,7 +133,7 @@ class _AgentSwipeHostState extends State<AgentSwipeHost> {/// and the panes to close are the ones actually opened, not the ones a fresh list would name.final Set<({String machineId, String agentId})> _attached = {};- /// Voice input for every page of this pager: open or closed, and what has been heard so far,+ /// Voice input for every page of this pager: a take in progress, and what has been heard so far,/// survive a swipe the way a keyboard that is up does. Disposed with the pager, which is what/// turns the microphone off on the way out.///diff --git a/mobile/lib/phone/phone_input_mode_store.dart b/mobile/lib/phone/phone_input_mode_store.dartdeleted file mode 100644index 1a239c080..000000000--- a/mobile/lib/phone/phone_input_mode_store.dart+++ /dev/null@@ -1,62 +0,0 @@-import 'package:flutter/foundation.dart';--import '../core/harness_file_store.dart';-import '../core/local_key_value_store.dart';--/// What a tap on a terminal brings up.-enum PhoneInputMode {- /// Voice input with its mic button, and a Keyboard button beside it for typing. The default: on a- /// phone, talking to an agent is quicker than thumbing a prompt.- voice('Voice', 'Tap the terminal to talk; Keyboard is one tap away'),-- /// The software keyboard straight away, the way the phone worked before voice input.- keyboard('Keyboard', 'Tap the terminal to type');-- const PhoneInputMode(this.label, this.detail);-- final String label;- final String detail;-- static const fallback = voice;-}--/// The chosen [PhoneInputMode], remembered across launches.-///-/// Loaded by `loadPersistedSettings()` before the first frame, like the terminal's other-/// preferences: a terminal that opened voice input on its first tap and the keyboard on its second-/// would look like a bug rather than a late read.-class PhoneInputModeStore extends ValueNotifier<PhoneInputMode> {- PhoneInputModeStore({LocalKeyValueStore? storage})- : _storage = storage ?? HarnessFileStore.shared,- super(PhoneInputMode.fallback);-- static const _key = 'phone_input_mode';-- final LocalKeyValueStore _storage;-- /// An unreadable file, or a mode name this build does not know, lands on the default.- Future<void> load() async {- try {- final saved = await _storage.readMany([_key]);- value =- PhoneInputMode.values- .where((mode) => mode.name == saved[_key])- .firstOrNull ??- PhoneInputMode.fallback;- } catch (_) {- value = PhoneInputMode.fallback;- }- }-- Future<void> set(PhoneInputMode mode) async {- if (mode == value) return;- value = mode;- try {- await _storage.write(_key, mode.name);- } catch (_) {- // Kept in memory for this run.- }- }-}--final phoneInputModeStore = PhoneInputModeStore();diff --git a/mobile/lib/phone/settings_page.dart b/mobile/lib/phone/settings_page.dartindex d1148bd08..3a171d139 100644--- a/mobile/lib/phone/settings_page.dart+++ b/mobile/lib/phone/settings_page.dart@@ -13,11 +13,12 @@ import 'package:harness_mobile/terminal/terminal_font_store.dart';import 'package:harness_mobile/terminal/terminal_theme_store.dart';import 'phone_header.dart';-import 'phone_input_mode_store.dart';import 'phone_sheet.dart';import 'settings_row.dart';import 'stats_entry.dart';import 'usage_entry.dart';+import 'voice_language.dart';+import 'voice_language_store.dart';/// The phone's Settings tab.///@@ -123,7 +124,7 @@ class _Body extends StatelessWidget {const SettingsCaption('Terminal'),SettingsGroup(children: [- _InputModeRow(),+ _VoiceLanguageRow(),_FontRow(),_SizeRow(),_TerminalThemeRow(),@@ -193,33 +194,18 @@ class _Avatar extends StatelessWidget {}}-/// What a tap on the terminal opens: voice input (the default) or the keyboard, as before voice.-class _InputModeRow extends StatelessWidget {+/// The language the mic under every terminal transcribes in. A long press on the mic opens the+/// same picker.+class _VoiceLanguageRow extends StatelessWidget {@overrideWidget build(BuildContext context) => ValueListenableBuilder(- valueListenable: phoneInputModeStore,- builder: (context, mode, _) {+ valueListenable: voiceLanguageStore,+ builder: (context, code, _) {AppTheme.watch(context);return SettingsRow(- title: 'Input',- value: mode.label,- onTap: () => showPhoneSheet(- context,- title: 'Tapping the terminal opens',- actions: [- for (final choice in PhoneInputMode.values)- PhoneSheetAction(- icon: choice == mode- ? LucideIcons.check300- : switch (choice) {- PhoneInputMode.voice => LucideIcons.mic300,- PhoneInputMode.keyboard => LucideIcons.keyboard300,- },- label: choice.label,- onTap: () => unawaited(phoneInputModeStore.set(choice)),- ),- ],- ),+ title: 'Voice language',+ value: voiceLanguageName(code),+ onTap: () => unawaited(showVoiceLanguagePicker(context)),);},);diff --git a/mobile/lib/phone/terminal_foot_bar.dart b/mobile/lib/phone/terminal_foot_bar.dartnew file mode 100644index 000000000..fdb684443--- /dev/null+++ b/mobile/lib/phone/terminal_foot_bar.dart@@ -0,0 +1,198 @@+import 'dart:async';++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 'phone_status.dart';+import 'status_pill.dart';+import 'voice_input_controller.dart';+import 'voice_language_store.dart';+import 'voice_mic_action.dart';+import 'voice_mic_button.dart';++/// The foot of a terminal page, one row: which computer the agent runs on,+/// whether it is still answering, and the mic.+///+/// Voice is this one button and nothing else — no panel. Tap to talk, tap again+/// to send; the row's left half says what the mic is doing while it is doing it,+/// and goes back to the machine when it is done. A tap on the terminal instead+/// raises the keyboard with what was said typed into the prompt, which is how a+/// sentence is corrected before it goes.+///+/// ⚠️ **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, or that lost+/// its mic while a pane attached, 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.session,+ });++ final String name;++ /// Null while the header's reclaim button is saying the state instead — see+ /// the call site. The row then carries the machine alone, at the same height.+ final PhoneSummary? status;++ final VoiceInputController voice;++ /// Null while the pane is still attaching: there is nothing to talk to yet,+ /// and the mic is not drawn.+ final TerminalSession? session;++ static const double height = VoiceMicButton.extent + 4;++ @override+ Widget build(BuildContext context) {+ AppTheme.watch(context);+ final session = this.session;+ // Nothing to say — the machine has not loaded, the header is carrying the+ // state, and there is no pane to talk to. Draw no row rather than an empty+ // one holding its height open under the terminal.+ if (name.isEmpty && status == null && session == null) {+ return const SizedBox.shrink();+ }+ return SizedBox(+ height: height,+ child: Padding(+ padding: const EdgeInsets.only(left: 20, right: 8),+ child: ListenableBuilder(+ listenable: Listenable.merge([voice, session]),+ builder: (context, _) => Row(+ children: [+ Expanded(+ child: AnimatedSwitcher(+ duration: const Duration(milliseconds: 180),+ layoutBuilder: _alignStart,+ child: _voiceLine(voice) ?? _machineLine(),+ ),+ ),+ if (session != null) ...[+ if ((!voice.isIdle && !voice.isSending) || voice.notice != null)+ _DismissButton(onTap: voice.clear),+ _mic(context, session),+ ],+ ],+ ),+ ),+ ),+ );+ }++ Widget _machineLine() =>+ _MachineLine(key: const ValueKey('machine'), name: name, status: status);++ VoiceMicButton _mic(BuildContext context, TerminalSession session) {+ final action = voiceMicAction(voice, session);+ return VoiceMicButton(+ face: action.face,+ onPressed: action.onPressed,+ onLongPress: () => unawaited(showVoiceLanguagePicker(context)),+ );+ }+}++/// What the row's left half says instead of the machine 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) {+ final notice = voice.notice;+ final label = notice ?? voiceActivityLabel(voice);+ if (label == null) return null;+ return Text(+ label,+ key: ValueKey(label),+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: TextStyle(+ fontSize: 12,+ height: 1.3,+ fontWeight: FontWeight.w500,+ color: notice != null ? AppPalette.warn : AppPalette.accent,+ ),+ );+}++Widget _alignStart(Widget? current, List<Widget> previous) =>+ Stack(alignment: Alignment.centerLeft, children: [...previous, ?current]);++/// The machine and its state, as one sentence — *on that machine, live*.+///+/// ⚠️ The name is what yields when the row is narrow. A truncated state word+/// is the bug this layout was moved out of the header to avoid — "Taken over"+/// ellipsed to "Ta…" there — so [StatusPill] keeps its intrinsic width and the+/// [Flexible] is on the name alone. A machine called "Macbook Pro của Phát"+/// loses its tail; "Disconnected" never does.+class _MachineLine extends StatelessWidget {+ const _MachineLine({super.key, required this.name, required this.status});++ final String name;+ final PhoneSummary? status;++ @override+ Widget build(BuildContext context) {+ final status = this.status;+ return Row(+ children: [+ if (name.isNotEmpty)+ Flexible(+ child: Text(+ name,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: TextStyle(+ color: AppPalette.textSecondary,+ fontSize: 12,+ fontWeight: FontWeight.w500,+ ),+ ),+ ),+ if (name.isNotEmpty && status != null)+ // A separator the eye passes over rather than reads: the two halves+ // are one sentence, and a heavier mark between them made the row+ // look like two controls.+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 7),+ child: Text(+ '·',+ style: TextStyle(color: AppPalette.textFaint, fontSize: 12),+ ),+ ),+ if (status != null) StatusPill(fontSize: 12, summary: status),+ ],+ );+ }+}++/// `×` beside the mic while there is something to drop: a take being recorded,+/// words held from a failed send, or a notice. Gone again at rest.+class _DismissButton extends StatelessWidget {+ const _DismissButton({required this.onTap});++ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) => Semantics(+ button: true,+ label: 'Cancel',+ child: GestureDetector(+ key: const ValueKey('voice-cancel'),+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: SizedBox.square(+ dimension: VoiceMicButton.extent,+ child: Icon(+ LucideIcons.x300,+ size: 16,+ color: AppPalette.textSecondary,+ ),+ ),+ ),+ );+}diff --git a/mobile/lib/phone/terminal_input_dock.dart b/mobile/lib/phone/terminal_input_dock.dartindex f61651600..39fcca661 100644--- a/mobile/lib/phone/terminal_input_dock.dart+++ b/mobile/lib/phone/terminal_input_dock.dart@@ -1,96 +1,46 @@-import 'dart:async';-import 'package:flutter/material.dart';-import 'package:xterm/xterm.dart';import 'package:harness_mobile/terminal/terminal_session.dart';import 'terminal_key_bar.dart';-import 'voice_input_controller.dart';-import 'voice_input_panel.dart';-/// The bottom of a terminal page: [TerminalKeyBar] over the keyboard, or-/// [VoiceInputPanel] in its place.-///-/// Voice is what a tap on the terminal opens; the keyboard is what its-/// Keyboard button hands over to. One at a time, and the key bar goes with the-/// keyboard: `esc`, the arrows and the digits are keys to TYPE with, and while-/// someone is talking they are two rows of terminal the panel does not need.+/// The bottom of a terminal page while the keyboard is up: [TerminalKeyBar] over+/// it, following the session's input state. Nothing while it is down — the foot+/// row with the mic is the page's then.class TerminalInputDock extends StatelessWidget {const TerminalInputDock({super.key,required this.session,- required this.voice,required this.keyboardUp,required this.onDismiss,- required this.onUseKeyboard,this.onPickImage,this.onTakePhoto,});final TerminalSession session;- final VoiceInputController voice;/// The software keyboard is up, or has been asked for and is on its way.final bool keyboardUp;- /// `⌄`, on the key bar or on the panel: puts away whichever input is up.+ /// `⌄` on the key bar: puts the keyboard away.final VoidCallback onDismiss;- final VoidCallback onUseKeyboard;final VoidCallback? onPickImage;final VoidCallback? onTakePhoto;- /// Send: what was said, or — with nothing said — what is already in the- /// prompt.- ///- /// Speech goes the composer's own path, not as typed bytes: the machine- /// injects it as one turn and owns the submit Enter — see- /// `TerminalSession.sendComposerText`.- ///- /// ⚠️ With no speech, Send is Enter. The prompt can hold text this panel- /// never saw — typed, pasted, or dictated by the keyboard's own mic before- /// switching back — and a Send that stayed dead over it left no way to send- /// that text short of raising the keyboard again for its return key.- void _send() {- if (voice.hasSpeech) {- unawaited(voice.submit(session.sendComposerText));- return;- }- session.terminal.keyInput(TerminalKey.enter);- voice.clear();- }-@override- Widget build(BuildContext context) => ValueListenableBuilder<bool>(- valueListenable: voice.openState,- builder: (context, voiceOpen, _) {- if (!keyboardUp && !voiceOpen) return const SizedBox.shrink();- return ListenableBuilder(- listenable: session,- builder: (context, _) => Column(- mainAxisSize: MainAxisSize.min,- children: [- if (keyboardUp)- TerminalKeyBar(- terminal: session.terminal,- enabled: session.acceptsInput,- controlArmed: session.controlArmed,- onControlToggle: session.armControl,- onDismissKeyboard: onDismiss,- onPickImage: onPickImage,- onTakePhoto: onTakePhoto,- )- else- VoiceInputPanel(- voice: voice,- canSend: session.acceptsInput,- onSend: _send,- onUseKeyboard: onUseKeyboard,- onDismiss: onDismiss,- ),- ],- ),- );- },- );+ Widget build(BuildContext context) {+ if (!keyboardUp) return const SizedBox.shrink();+ return ListenableBuilder(+ listenable: session,+ builder: (context, _) => TerminalKeyBar(+ terminal: session.terminal,+ enabled: session.acceptsInput,+ controlArmed: session.controlArmed,+ onControlToggle: session.armControl,+ onDismissKeyboard: onDismiss,+ onPickImage: onPickImage,+ onTakePhoto: onTakePhoto,+ ),+ );+ }}diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dartindex 26dc4d8a9..6ef64869f 100644--- a/mobile/lib/phone/terminal_page.dart+++ b/mobile/lib/phone/terminal_page.dart@@ -19,13 +19,13 @@ import 'package:harness_mobile/widgets/terminal_panel.dart';import 'agents_page.dart' show openNewAgent;import 'delete_agent.dart';import 'phone_header.dart';-import 'phone_input_mode_store.dart';import 'phone_navigation.dart' show phoneRoute;import 'phone_search_page.dart' show openPhoneSearch;import 'phone_sheet.dart';import 'phone_status.dart';import 'settings_page.dart';import 'status_pill.dart';+import 'terminal_foot_bar.dart';import 'terminal_input_dock.dart';import 'voice_input_controller.dart';@@ -106,14 +106,14 @@ class _TerminalPageState extends State<TerminalPage>/// TerminalPage still sitting in the Agents tab's stack.bool _hadPane = false;- /// Whether the Keyboard button in voice input has asked for the keyboard,- /// and it has not risen yet.+ /// Whether a tap on the terminal has asked for the keyboard, and it has not+ /// risen yet.////// What makes [TerminalPanel] claim focus at all: arriving on a page raises- /// nothing, and a tap on the terminal opens voice input, so this is the one- /// way the keyboard is SUMMONED. Spent the moment the keyboard is up — from- /// then on [_keyboardIsUp] holds it — so Back or `⌄` can put it away without- /// a claim fetching it straight back.+ /// nothing, and the panel takes the terminal's tap for [_raiseKeyboard], so+ /// this is the one way the keyboard is SUMMONED. Spent the moment the+ /// keyboard is up — from then on [_keyboardIsUp] holds it — so Back or `⌄`+ /// can put it away without a claim fetching it straight back.////// It stays set when no inset ever arrives, which is what a hardware keyboard/// looks like: the terminal keeps its focus, and the key bar stays for `esc`.@@ -203,8 +203,10 @@ class _TerminalPageState extends State<TerminalPage>// finish. Spending it this early is the point: it is off long before any// Back press can arrive.final requested = _keyboardRequested && !up;- // One input at a time. Whatever raised the keyboard, voice input yields.- if (up && widget.voice.isOpen) widget.voice.close();+ // One input at a time. Whatever raised the keyboard, voice input yields —+ // the mic's row is hidden under the key bar, and a take nobody can see is a+ // microphone left on.+ if (up && !widget.voice.isIdle) widget.voice.clear();// Every tick that MOVES the inset is the animation still running; the run// ends when one window passes without another move. Gated on a real change@@ -246,53 +248,33 @@ class _TerminalPageState extends State<TerminalPage>bool get _shouldFocus =>widget.isActive && (_keyboardIsUp || _keyboardRequested);- /// A tap on the terminal while no keyboard is up or coming: voice input,- /// waiting on its mic button. Null while the keyboard is, so the tap is- /// xterm's and the keyboard stays.+ /// 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].///- /// In [PhoneInputMode.keyboard] the same tap asks for the keyboard instead, the way the phone- /// worked before voice input — through [_keyboardRequested], the path the Keyboard button in voice- /// input already takes, so the two ways of getting a keyboard behave identically once it is up.- VoidCallback? get _onInputTap {- if (_shouldFocus) return null;- return switch (phoneInputModeStore.value) {- PhoneInputMode.voice => widget.voice.open,- PhoneInputMode.keyboard => () => setState(- () => _keyboardRequested = true,- ),- };- }-- /// The Keyboard button in voice input. What was heard is typed into the- /// prompt rather than dropped, so the keyboard picks up where the voice left- /// off — to correct a word, or to finish the sentence. A take still being- /// recorded is transcribed first: pressing Keyboard mid-sentence is asking to- /// fix that sentence, not to lose it.- Future<void> _useKeyboard(TerminalSession session) async {+ /// 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+ /// word, or to finish the sentence. A take still being recorded is+ /// transcribed first: tapping the terminal mid-sentence is asking to fix that+ /// sentence, not to lose it.+ Future<void> _raiseKeyboard(TerminalSession session) async {final heard = await widget.voice.takeTranscript();if (!mounted) return;- widget.voice.close();if (heard.isNotEmpty && session.acceptsInput) {session.terminal.textInput(heard);}setState(() => _keyboardRequested = true);}- /// Puts away whichever input is up without leaving the page — the `⌄` key on+ /// Puts the keyboard away without leaving the page — the `⌄` key on/// [TerminalKeyBar]. Dropping focus is what closes the input connection.void _dismissInput() {- widget.voice.close();FocusManager.instance.primaryFocus?.unfocus();if (_keyboardRequested) setState(() => _keyboardRequested = false);}- /// Whether an input on screen is THIS page's — the keyboard, or voice input- /// in its place — the question the machine row at the foot of the page asks,- /// which [_keyboardUp] alone answers wrongly.- ///- /// Voice input counts for the same reason the keyboard does: the panel takes- /// the keyboard's place, and a status line under it is a row the terminal- /// loses while someone is talking to the agent.+ /// Whether the keyboard on screen is THIS page's — the question the foot row+ /// asks, 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,@@ -310,8 +292,7 @@ class _TerminalPageState extends State<TerminalPage>/// keyboard ITSELF, which is screen-wide, and a covered page must keep/// tracking it to know what to do when it is uncovered.bool get _ownsInput =>- (_keyboardUp || widget.voice.isOpen) &&- (ModalRoute.of(context)?.isCurrent ?? true);+ _keyboardUp && (ModalRoute.of(context)?.isCurrent ?? true);/// Guards against a second picker while one is already up.///@@ -380,15 +361,9 @@ class _TerminalPageState extends State<TerminalPage>@overrideWidget build(BuildContext context) {return ListenableBuilder(- // The panel opening or closing hides or shows the machine row — see- // [_ownsInput]. Its open STATE only: what it hears repaints the panel.- // The input mode too: Settings is pushed over this page, and what a tap opens has to follow a- // change made there the moment the person comes back.- listenable: Listenable.merge([- widget.notifier,- widget.voice.openState,- phoneInputModeStore,- ]),+ // Not the voice controller: what the mic hears repaints the foot row,+ // which listens for itself, and never rebuilds the terminal above it.+ listenable: widget.notifier,builder: (context, _) {AppTheme.watch(context);final pane = widget.notifier.panes@@ -438,7 +413,8 @@ class _TerminalPageState extends State<TerminalPage>size: 22,),// ⚠️ No subtitle. The machine and its state moved to- // [_MachineBar] at the foot of the page — see there for why.+ // [TerminalFootBar] at the foot of the page — see there for+ // why.// A header carrying both a name and a status line spent two// rows on identity and left the filename, the one thing that// says WHICH agent this is, sharing its row with four@@ -572,19 +548,23 @@ class _TerminalPageState extends State<TerminalPage>// ⚠️ The tap is taken in the panel, not by a// `Listener` over it. xterm's own `_onTapDown`// calls `requestKeyboard()`, so anything that- // merely ALSO reacted to the tap would get the- // keyboard rising under voice input — and a- // re-armed claim on top of it was measured- // asking Android twice per tap, which answers a- // show mid-animation by cancelling and- // restarting it.- onInputTap: _onInputTap,+ // merely ALSO reacted to the tap would raise+ // the keyboard before the words said were typed+ // into the prompt — and a re-armed claim on top+ // of it was measured asking Android twice per+ // tap, which answers a show mid-animation by+ // cancelling and restarting it. Null while the+ // keyboard is up or coming, so the tap is+ // xterm's and the keyboard stays.+ onInputTap: _shouldFocus+ ? null+ : () => unawaited(_raiseKeyboard(session)),showHeader: false,// No composer, and so no grip above it: the// page hands the pane its full height and the// software keyboard drives the terminal- // directly. Voice input's Send is what kept- // the composer's batched turn.+ // directly. The mic's send is what kept the+ // composer's batched turn.),),// The bottom of this page IS just above the keyboard:@@ -594,10 +574,8 @@ class _TerminalPageState extends State<TerminalPage>if (session != null)TerminalInputDock(session: session,- voice: widget.voice,keyboardUp: _keyboardUp || _keyboardRequested,onDismiss: _dismissInput,- onUseKeyboard: () => unawaited(_useKeyboard(session)),// Only where the far side can actually take one: an// older CLI never advertises the binary kind, so the// upload would go nowhere silently. Null leaves the@@ -615,9 +593,10 @@ class _TerminalPageState extends State<TerminalPage>): null,),- // Which computer this is running on, and whether it is- // still answering — the pair that used to sit under the- // filename in the header.+ // Which computer this is running on, whether it is still+ // answering, and the mic — the pair that used to sit+ // under the filename in the header, and the one voice+ // control the page has.//// ⚠️ Below the key bar, not above it. The bar is what the// thumb works, and a line that moves every time it@@ -631,8 +610,10 @@ class _TerminalPageState extends State<TerminalPage>// chrome the terminal loses for nothing — state is not// what is being read mid-typing.if (!_ownsInput)- _MachineBar(+ TerminalFootBar(name: machine?.machine.displayName ?? '',+ voice: widget.voice,+ session: session,// ⚠️ The machine ALONE once the reclaim button is up.// The two say the same fact in different words —// "Taken over" here against "Take control" there,@@ -899,70 +880,3 @@ class _HeaderAction extends StatelessWidget {),);}--/// The foot of the page: which computer the agent runs on, and whether that-/// computer is still answering.-///-/// It reads as one fact — *this agent, on that machine, live* — so the machine-/// and the state share a row rather than stacking. The dot belongs to the-/// state, not to the name, which is why [StatusPill] draws the pair and this-/// widget only puts the machine in front of it.-///-/// ⚠️ The name is what yields when the row is narrow. A truncated state word-/// is the bug this layout was moved out of the header to avoid — "Taken over"-/// ellipsed to "Ta…" there — so [StatusPill] keeps its intrinsic width and the-/// [Flexible] is on the name alone. A machine called "Macbook Pro của Phát"-/// loses its tail; "Disconnected" never does.-class _MachineBar extends StatelessWidget {- const _MachineBar({required this.name, required this.status});-- final String name;-- /// Null while the header's reclaim button is saying the state instead — see- /// the call site. The row then carries the machine alone, at the same height- /// it has with both, so nothing under the terminal moves when a session is- /// taken over.- final PhoneSummary? status;-- @override- Widget build(BuildContext context) {- AppTheme.watch(context);- final status = this.status;- // Nothing to say — the machine has not loaded and the header is carrying- // the state. Draw no row rather than an empty one holding its padding- // open under the terminal.- if (name.isEmpty && status == null) return const SizedBox.shrink();- return Padding(- padding: const EdgeInsets.fromLTRB(20, 8, 20, 10),- child: Row(- children: [- if (name.isNotEmpty)- Flexible(- child: Text(- name,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: TextStyle(- color: AppPalette.textSecondary,- fontSize: 12,- fontWeight: FontWeight.w500,- ),- ),- ),- if (name.isNotEmpty && status != null)- // A separator the eye passes over rather than reads: the two halves- // are one sentence, and a heavier mark between them made the row- // look like two controls.- Padding(- padding: const EdgeInsets.symmetric(horizontal: 7),- child: Text(- '·',- style: TextStyle(color: AppPalette.textFaint, fontSize: 12),- ),- ),- if (status != null) StatusPill(fontSize: 12, summary: status),- ],- ),- );- }-}diff --git a/mobile/lib/phone/voice_input_controller.dart b/mobile/lib/phone/voice_input_controller.dartindex 282570b6a..cd63503b0 100644--- a/mobile/lib/phone/voice_input_controller.dart+++ b/mobile/lib/phone/voice_input_controller.dart@@ -1,13 +1,10 @@import 'dart:async';-import 'dart:ui' show Locale;import 'package:flutter/foundation.dart';-import 'package:harness_mobile/core/harness_file_store.dart';-import 'package:harness_mobile/core/local_key_value_store.dart';import 'package:harness_mobile/logging/app_log.dart';-import 'voice_language.dart';+import 'voice_language_store.dart';import 'voice_notice.dart';import 'voice_recorder.dart';@@ -32,8 +29,8 @@ enum VoiceInputStatus {unavailable,}-/// Voice input for one pager of terminal pages: whether its panel is open, what-/// has been heard, and the language it is transcribed in.+/// Voice input for one pager of terminal pages: what is being recorded, and what+/// has been heard and not yet sent.////// Record, then transcribe — the dial's shape, and the backend's: its/// `/api/voice/stt` takes a finished recording and answers with its words, so@@ -42,23 +39,14 @@ enum VoiceInputStatus {////// Owned by `AgentSwipeHost`, not by a page, for the reason the keyboard is one/// screen-wide fact in `terminal_page.dart`: swiping to the next agent must not-/// close what is open, nor drop what was said. What is SENT goes to whichever-/// page is active when Send is pressed.+/// drop what was said. What is SENT goes to whichever page's mic is pressed.class VoiceInputController extends ChangeNotifier {VoiceInputController({required this.transcriber,VoiceRecorder? recorder,- LocalKeyValueStore? storage,- List<Locale>? preferredLocales,+ ValueListenable<String>? language,}) : _recorder = recorder ?? MicVoiceRecorder(),- _storage = storage ?? HarnessFileStore.shared,- _language = defaultVoiceLanguage(- preferredLocales ?? PlatformDispatcher.instance.locales,- ) {- unawaited(_loadLanguage());- }-- static const _languageKey = 'voice_input_language';+ _language = language ?? voiceLanguageStore;/// Below this, a take is silence rather than quiet speech: digital zero, or/// the hiss of an input nobody is speaking into. Speech peaks in the@@ -72,68 +60,44 @@ class VoiceInputController extends ChangeNotifier {final VoiceTranscriber transcriber;final VoiceRecorder _recorder;- final LocalKeyValueStore _storage;- final ValueNotifier<bool> _open = ValueNotifier(false);+ /// A code from `voiceLanguages`, read when a take is transcribed — so a language picked+ /// mid-take is the one that take is heard in.+ final ValueListenable<String> _language;+VoiceInputStatus _status = VoiceInputStatus.idle;String _heard = '';String? _notice;- String _language;- bool _languageChosen = false;bool _isSending = false;bool _disposed = false;Timer? _takeLimit;/// Bumped by everything that abandons a take, so a recording or a/// transcription still in flight from it lands nowhere — above all after- /// Close, where words arriving late would reopen what was put away.+ /// [clear], where words arriving late would bring back what was dropped.int _take = 0;- /// Whether the panel is up, as its own listenable: the terminal page watches- /// THIS, not the controller, so the panel's own changes repaint the panel and- /// never rebuild the terminal above it.- ValueListenable<bool> get openState => _open;- bool get isOpen => _open.value;bool get isSending => _isSending;VoiceInputStatus get status => _status;String get transcript => _heard;String? get notice => _notice;- /// A code from [voiceLanguages].- String get language => _language;-- /// Whether Send has speech to send: words already heard, or a take still- /// being recorded that Send will finish first.- bool get hasSpeech =>- _heard.isNotEmpty || _status == VoiceInputStatus.listening;-- /// Opens the panel — what a tap on the terminal does. It does NOT record.- ///- /// ⚠️ The microphone is the mic button's alone. Opening straight into a- /// recording turned every tap on the terminal — to put the caret back, to- /// send what was already typed — into a take of room noise that came back- /// as "didn't catch that", and a microphone that switches itself on is not- /// one anybody asked for.- void open() => _open.value = true;-- /// Closes the panel, discarding anything not sent.- void close() {- _open.value = false;- clear();- }+ /// Nothing being recorded, heard 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 &&+ !_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.void clear() {_abandonTake();_heard = '';_setStatus(VoiceInputStatus.idle);}- Future<void> toggleListening() => switch (_status) {- VoiceInputStatus.starting || VoiceInputStatus.listening => stopListening(),- VoiceInputStatus.transcribing => Future.value(),- VoiceInputStatus.idle || VoiceInputStatus.unavailable => startListening(),- };-Future<void> startListening() async {if (_isSending || _disposed) return;if (_status != VoiceInputStatus.idle &&@@ -174,8 +138,8 @@ class VoiceInputController extends ChangeNotifier {if (_status == VoiceInputStatus.listening) await _transcribeTake();}- /// Sends everything heard, and empties the panel once it is sent — kept when- /// delivery fails, so nothing said has to be said twice.+ /// Sends everything heard, and empties the transcript once it is sent — kept+ /// when delivery fails, so nothing said has to be said twice.////// Send while still talking ends the take first: one tap finishes the/// sentence and sends it. A take that comes back as nothing sends nothing,@@ -204,33 +168,22 @@ class VoiceInputController extends ChangeNotifier {}/// Everything heard — the take still being recorded included, once it is- /// transcribed — emptied out of the panel, for the keyboard to carry on from.+ /// transcribed — emptied out of here, for the keyboard to carry on from.+ ///+ /// Nothing while a send is on its way: those words are already the message,+ /// and handing them to the keyboard too would put them in the prompt twice.Future<String> takeTranscript() async {+ if (_isSending) return '';if (_status == VoiceInputStatus.listening) await _transcribeTake();final text = transcript;clear();return text;}- /// Transcribes in [code] from now on — the take being recorded included —- /// on this phone and in later pagers too.- Future<void> selectLanguage(String code) async {- if (!isVoiceLanguage(code)) return;- _language = code;- _languageChosen = true;- _notify();- try {- await _storage.write(_languageKey, code);- } on Exception {- // Still used for this pager; only remembering it failed.- }- }-@overridevoid dispose() {_abandonTake();_disposed = true;- _open.dispose();unawaited(_recorder.dispose());super.dispose();}@@ -254,9 +207,10 @@ class VoiceInputController extends ChangeNotifier {_setStatus(VoiceInputStatus.idle, notice: VoiceNotice.noSound);return false;}- final words = await transcriber(recording.wav, _language);+ final language = _language.value;+ final words = await transcriber(recording.wav, language);// The count, never the words: a transcript is what someone said.- appLog.info('voice', 'stt[$_language]: ${words.length} chars');+ appLog.info('voice', 'stt[$language]: ${words.length} chars');if (take != _take) return false;_heard = _joinWords(_heard, words);_setStatus(@@ -265,7 +219,7 @@ class VoiceInputController extends ChangeNotifier {);return words.isNotEmpty;} on Exception catch (error) {- appLog.warn('voice', 'stt[$_language] failed', error: error);+ appLog.warn('voice', 'stt[${_language.value}] failed', error: error);if (take == _take) {_setStatus(VoiceInputStatus.idle, notice: VoiceNotice.notTranscribed);}@@ -281,18 +235,6 @@ class VoiceInputController extends ChangeNotifier {}}- Future<void> _loadLanguage() async {- try {- final saved = await _storage.read(_languageKey);- // A choice made while this was loading is newer than the saved one.- if (_languageChosen || _disposed || !isVoiceLanguage(saved)) return;- _language = saved!;- _notify();- } on Exception {- // The phone's own language still works; only the memory is missing.- }- }-void _abandonTake() {_take++;_takeLimit?.cancel();diff --git a/mobile/lib/phone/voice_input_panel.dart b/mobile/lib/phone/voice_input_panel.dartdeleted file mode 100644index b63f64b77..000000000--- a/mobile/lib/phone/voice_input_panel.dart+++ /dev/null@@ -1,215 +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 'voice_input_controller.dart';-import 'voice_language.dart';-import 'voice_mic_button.dart';-import 'voice_panel_parts.dart';--/// What a tap on the terminal opens: talk to the agent, read back what was-/// heard, send it — or hand over to the keyboard.-///-/// Words arrive when a take ENDS, not while it is being spoken: they come from-/// the backend's `/api/voice/stt`, which transcribes a finished recording. Send-/// works mid-take for that reason — it ends the take and sends what it heard.-///-/// Opening it records nothing: the mic button starts a take.-///-/// It sits where the keyboard would, alone: [TerminalKeyBar] belongs to the-/// keyboard, so this panel carries its own `⌄`.-///-/// ⚠️ **One fixed height, whatever it says.** The transcript scrolls inside a-/// box of its own rather than growing the panel: this panel's top edge is the-/// terminal's bottom edge, so a panel that grew by a line per sentence would-/// resize the remote shell once per sentence.-class VoiceInputPanel extends StatelessWidget {- const VoiceInputPanel({- super.key,- required this.voice,- required this.canSend,- required this.onSend,- required this.onUseKeyboard,- required this.onDismiss,- });-- final VoiceInputController voice;-- /// False while the stream is not accepting input. Recording still works —- /// what was said waits for Send.- final bool canSend;- final VoidCallback onSend;-- /// Closes this panel for the keyboard, carrying what was heard with it.- final VoidCallback onUseKeyboard;-- /// Puts the panel away, and what was not sent with it.- final VoidCallback onDismiss;-- @override- Widget build(BuildContext context) {- AppTheme.watch(context);- return ListenableBuilder(- listenable: voice,- builder: (context, _) {- final status = voice.status;- return ExcludeFocus(- // Same reason as the key bar's: nothing here may take focus from the- // terminal the keyboard button is about to hand it to.- child: DecoratedBox(- decoration: BoxDecoration(- color: AppPalette.panelBg,- border: Border(top: BorderSide(color: AppGlass.hair)),- ),- child: Padding(- padding: const EdgeInsets.fromLTRB(12, 8, 12, 10),- child: MediaQuery.withNoTextScaling(- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- _StatusRow(voice: voice, onDismiss: onDismiss),- _Transcript(voice: voice),- const SizedBox(height: 6),- Row(- children: [- VoicePanelAction(- key: const ValueKey('voice-keyboard'),- icon: LucideIcons.keyboard300,- label: 'Keyboard',- onTap: onUseKeyboard,- ),- const Spacer(),- VoiceMicButton(- status: status,- onPressed: voice.toggleListening,- ),- const Spacer(),- VoicePanelAction(- key: const ValueKey('voice-send'),- icon: LucideIcons.arrowUp300,- label: 'Send',- emphasized: true,- // Live with nothing said too: Send is then Enter- // for what is already in the prompt — see- // `TerminalInputDock`. Dead only while a take is- // opening or its words are still on the way.- onTap:- canSend &&- !voice.isSending &&- status != VoiceInputStatus.starting &&- status != VoiceInputStatus.transcribing- ? onSend- : null,- ),- ],- ),- ],- ),- ),- ),- ),- );- },- );- }-}--/// Language, what the recognizer is doing, the way to start over and the way-/// out.-class _StatusRow extends StatelessWidget {- const _StatusRow({required this.voice, required this.onDismiss});-- final VoiceInputController voice;- final VoidCallback onDismiss;-- String get _label => switch (voice.status) {- VoiceInputStatus.starting => 'Starting…',- VoiceInputStatus.listening => 'Listening…',- VoiceInputStatus.transcribing => 'Transcribing…',- VoiceInputStatus.unavailable => 'Voice input is off',- VoiceInputStatus.idle when voice.isSending => 'Sending…',- VoiceInputStatus.idle => 'Tap the mic to talk',- };-- @override- Widget build(BuildContext context) {- // With words on screen the transcript box has no room for a notice, so a- // failed Send says so here instead.- final notice = voice.transcript.isNotEmpty ? voice.notice : null;- return SizedBox(- height: 28,- child: Row(- children: [- VoiceLanguageChip(- label: voice.language.toUpperCase(),- onTap: () => showVoiceLanguagePicker(- context,- current: voice.language,- onSelected: voice.selectLanguage,- ),- ),- const SizedBox(width: 8),- Expanded(- child: Text(- notice ?? _label,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: TextStyle(- fontSize: 12,- color: notice != null- ? AppPalette.warn- : AppPalette.textSecondary,- ),- ),- ),- if (voice.transcript.isNotEmpty)- VoicePanelIconButton(- key: const ValueKey('voice-clear'),- icon: LucideIcons.x300,- semanticLabel: 'Clear',- onTap: voice.clear,- ),- VoicePanelIconButton(- key: const ValueKey('voice-hide'),- icon: LucideIcons.chevronDown300,- semanticLabel: 'Hide voice input',- onTap: onDismiss,- ),- ],- ),- );- }-}--/// What was heard, newest words kept in view; the notice when there are none.-class _Transcript extends StatelessWidget {- const _Transcript({required this.voice});-- final VoiceInputController voice;-- static const double _height = 58;-- @override- Widget build(BuildContext context) {- final words = voice.transcript;- final notice = voice.notice;- final showsWords = words.isNotEmpty;- return SizedBox(- height: _height,- width: double.infinity,- child: SingleChildScrollView(- // Reversed so the latest words are the ones on screen as they arrive.- reverse: true,- child: Text(- showsWords ? words : notice ?? '',- style: TextStyle(- fontSize: showsWords ? 16 : 13,- height: 1.35,- color: showsWords ? AppPalette.textPrimary : AppPalette.warn,- ),- ),- ),- );- }-}diff --git a/mobile/lib/phone/voice_language.dart b/mobile/lib/phone/voice_language.dartindex d8796fb10..2fd73beae 100644--- a/mobile/lib/phone/voice_language.dart+++ b/mobile/lib/phone/voice_language.dart@@ -1,7 +1,4 @@-import 'package:flutter/widgets.dart';-import 'package:lucide_icons_flutter/lucide_icons.dart';--import 'phone_sheet.dart';+import 'dart:ui' show Locale;typedef VoiceLanguage = ({String code, String name});@@ -30,22 +27,10 @@ String defaultVoiceLanguage(List<Locale> preferred) {return 'en';}-/// Picks the language voice input is transcribed in.-Future<void> showVoiceLanguagePicker(- BuildContext context, {- required String current,- required ValueChanged<String> onSelected,-}) => showPhoneSheet(- context,- title: 'Voice input language',- actions: [- for (final language in voiceLanguages)- PhoneSheetAction(- icon: language.code == current- ? LucideIcons.check300- : LucideIcons.languages300,- label: language.name,- onTap: () => onSelected(language.code),- ),- ],-);+/// The language's own name, for a code from [voiceLanguages].+String voiceLanguageName(String code) =>+ voiceLanguages+ .where((language) => language.code == code)+ .firstOrNull+ ?.name ??+ code;diff --git a/mobile/lib/phone/voice_language_store.dart b/mobile/lib/phone/voice_language_store.dartnew file mode 100644index 000000000..e249a7fcc--- /dev/null+++ b/mobile/lib/phone/voice_language_store.dart@@ -0,0 +1,78 @@+import 'dart:async';+import 'dart:ui' show Locale, PlatformDispatcher;++import 'package:flutter/widgets.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import 'package:harness_mobile/core/harness_file_store.dart';+import 'package:harness_mobile/core/local_key_value_store.dart';++import 'phone_sheet.dart';+import 'voice_language.dart';++/// The language voice input is transcribed in — a code from [voiceLanguages] — remembered across+/// launches.+///+/// One app-wide value, not one per pager: it is picked in Settings or from a long press on the mic,+/// and every terminal after that hears in it. Loaded by `loadPersistedSettings()` before the first+/// frame, so the first take is never sent in the phone's language by a late read.+class VoiceLanguageStore extends ValueNotifier<String> {+ VoiceLanguageStore({+ LocalKeyValueStore? storage,+ List<Locale>? preferredLocales,+ }) : _storage = storage ?? HarnessFileStore.shared,+ super(+ defaultVoiceLanguage(+ preferredLocales ?? PlatformDispatcher.instance.locales,+ ),+ );++ /// The key the per-pager controller used, kept so an existing choice survives the move here.+ static const _key = 'voice_input_language';++ final LocalKeyValueStore _storage;++ /// An unreadable file, or a code the backend no longer serves, keeps the phone's own language.+ Future<void> load() async {+ try {+ final saved = await _storage.read(_key);+ if (isVoiceLanguage(saved)) value = saved!;+ } on Exception {+ // The phone's own language still works; only the memory is missing.+ }+ }++ Future<void> select(String code) async {+ if (!isVoiceLanguage(code) || code == value) return;+ value = code;+ try {+ await _storage.write(_key, code);+ } on Exception {+ // Kept in memory for this run.+ }+ }+}++final voiceLanguageStore = VoiceLanguageStore();++/// Picks the language voice input is transcribed in.+Future<void> showVoiceLanguagePicker(+ BuildContext context, {+ VoiceLanguageStore? store,+}) {+ final languages = store ?? voiceLanguageStore;+ return showPhoneSheet(+ context,+ title: 'Voice input language',+ actions: [+ for (final language in voiceLanguages)+ PhoneSheetAction(+ icon: language.code == languages.value+ ? LucideIcons.check300+ : LucideIcons.languages300,+ label: language.name,+ onTap: () => unawaited(languages.select(language.code)),+ ),+ ],+ );+}diff --git a/mobile/lib/phone/voice_mic_action.dart b/mobile/lib/phone/voice_mic_action.dartnew file mode 100644index 000000000..57dacf436--- /dev/null+++ b/mobile/lib/phone/voice_mic_action.dart@@ -0,0 +1,58 @@+import 'dart:async';++import 'package:flutter/foundation.dart';++import 'package:harness_mobile/terminal/terminal_session.dart';++import 'voice_input_controller.dart';+import 'voice_mic_button.dart';++typedef VoiceMicAction = ({VoiceMicFace face, VoidCallback? onPressed});++/// What the mic shows and does for the voice input's state right now.+///+/// ⚠️ 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.+VoiceMicAction voiceMicAction(+ VoiceInputController voice,+ TerminalSession session,+) {+ void send() => unawaited(voice.submit(session.sendComposerText));+ final canSend = session.acceptsInput;+ if (voice.isSending) return (face: VoiceMicFace.busy, onPressed: null);+ return switch (voice.status) {+ VoiceInputStatus.transcribing => (face: VoiceMicFace.busy, onPressed: null),+ VoiceInputStatus.starting => (+ face: VoiceMicFace.starting,+ onPressed: () => unawaited(voice.stopListening()),+ ),+ VoiceInputStatus.listening => (+ face: VoiceMicFace.listening,+ onPressed: send,+ ),+ _ when voice.transcript.isNotEmpty => (+ face: VoiceMicFace.retry,+ onPressed: canSend ? send : null,+ ),+ VoiceInputStatus.unavailable => (+ face: VoiceMicFace.off,+ onPressed: () => unawaited(voice.startListening()),+ ),+ VoiceInputStatus.idle => (+ face: VoiceMicFace.talk,+ onPressed: canSend ? () => unawaited(voice.startListening()) : null,+ ),+ };+}++/// What the mic is doing, in a word or two — null with it at rest.+String? voiceActivityLabel(VoiceInputController voice) {+ if (voice.isSending) return 'Sending…';+ return switch (voice.status) {+ VoiceInputStatus.starting => 'Starting…',+ VoiceInputStatus.listening => 'Listening…',+ 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.dartindex 67c6a4ece..4b0f2aca4 100644--- a/mobile/lib/phone/voice_mic_button.dart+++ b/mobile/lib/phone/voice_mic_button.dart@@ -3,157 +3,109 @@ 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_input_controller.dart';+/// What the mic says it will do when tapped.+enum VoiceMicFace {+ /// At rest: tap to talk.+ talk,-/// The round button voice input is started and stopped with.+ /// 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,+}++/// The one voice control on a terminal page — a small round button at the foot+/// of the page, beside the machine it is talking to.///-/// While listening it breathes — a glow and a ring that swell and fade — so it-/// reads as hearing from across the screen, which is where the eyes are: on the-/// terminal, not on this button.+/// Talk and send are the same tap, walkie-talkie style: tap to start, tap again+/// to finish the sentence and send it. The face changes to say which tap is+/// next — a mic, then an arrow.///-/// ⚠️ The swell is painted, never laid out. The button sits in a fixed square-/// with room for the ring already in it: a panel whose height moved with the-/// animation would resize the terminal above it, and every resize is a-/// SIGWINCH on the far machine.-class VoiceMicButton extends StatefulWidget {+/// ⚠️ **The swell is painted, never laid out.** The breathing ring scales past+/// the button's box with [Clip.none] rather than growing it: this button's row+/// sits under the terminal, and a row whose height moved with the animation+/// would resize the remote shell every frame.+class VoiceMicButton extends StatelessWidget {const VoiceMicButton({super.key,- required this.status,+ required this.face,required this.onPressed,+ this.onLongPress,});- final VoiceInputStatus status;- final VoidCallback onPressed;-- static const double _extent = 72;- static const double _core = 56;-- @override- State<VoiceMicButton> createState() => _VoiceMicButtonState();-}--class _VoiceMicButtonState extends State<VoiceMicButton>- with SingleTickerProviderStateMixin {- late final AnimationController _breath = AnimationController(- vsync: this,- duration: const Duration(milliseconds: 1400),- );+ final VoiceMicFace face;- bool get _listening => widget.status == VoiceInputStatus.listening;+ /// Null draws the button dimmed and dead.+ final VoidCallback? onPressed;- @override- void initState() {- super.initState();- _syncBreath();- }+ /// The language picker — a shortcut to the Settings row, for someone who+ /// talks in two languages.+ final VoidCallback? onLongPress;- @override- void didUpdateWidget(VoiceMicButton oldWidget) {- super.didUpdateWidget(oldWidget);- if (oldWidget.status != widget.status) _syncBreath();- }+ /// The tap target: iOS's 44pt minimum, around a smaller mark.+ static const double extent = 44;+ static const double _core = 32;- @override- void dispose() {- _breath.dispose();- super.dispose();- }+ bool get _lit => switch (face) {+ VoiceMicFace.starting ||+ VoiceMicFace.listening ||+ VoiceMicFace.retry => true,+ VoiceMicFace.talk || VoiceMicFace.busy || VoiceMicFace.off => false,+ };- void _syncBreath() {- if (_listening) {- _breath.repeat();- return;- }- _breath- ..stop()- ..value = 0;- }+ String get _semanticLabel => switch (face) {+ VoiceMicFace.talk => 'Talk to the agent',+ VoiceMicFace.starting => 'Cancel',+ VoiceMicFace.listening => 'Send what was said',+ VoiceMicFace.busy => 'Working',+ VoiceMicFace.retry => 'Send again',+ VoiceMicFace.off => 'Voice input is off',+ };@overrideWidget build(BuildContext context) {AppTheme.watch(context);- final status = widget.status;- final lit =- status == VoiceInputStatus.listening ||- status == VoiceInputStatus.starting;- final off = status == VoiceInputStatus.unavailable;- final transcribing = status == VoiceInputStatus.transcribing;+ final live = onPressed != null;return Semantics(button: true,- label: transcribing- ? 'Transcribing'- : lit- ? 'Stop listening'- : 'Start listening',+ enabled: live,+ label: _semanticLabel,+ onLongPressHint: onLongPress == null ? null : 'Choose language',child: GestureDetector(key: const ValueKey('voice-mic'),behavior: HitTestBehavior.opaque,- onTap: () {- HapticFeedback.lightImpact();- widget.onPressed();- },+ onTap: live+ ? () {+ HapticFeedback.lightImpact();+ onPressed!();+ }+ : null,+ onLongPress: onLongPress,child: SizedBox.square(- dimension: VoiceMicButton._extent,- child: Stack(- alignment: Alignment.center,- children: [- if (_listening) _Ring(breath: _breath),- 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(AppPalette.accent, Colors.white, 0.18)!,- AppPalette.accent,- ],- )- : null,- color: lit ? null : AppGlass.surfaceFill,- border: Border.all(- color: lit- ? Colors.white.withValues(alpha: 0.28)- : AppGlass.lift,- ),- boxShadow: lit- ? [- BoxShadow(- color: AppPalette.accent.withValues(alpha: 0.45),- blurRadius: 18,- ),- ]- : null,- ),- // The words are with the backend: nothing to start or stop- // until they are back, and the button says it is busy.- child: transcribing- ? Center(- child: SizedBox.square(- dimension: 22,- child: CircularProgressIndicator(- strokeWidth: 2,- color: AppPalette.accent,- ),- ),- )- : Icon(- off ? LucideIcons.micOff300 : LucideIcons.mic300,- size: 24,- color: lit- ? Colors.white- : off- ? AppPalette.textFaint- : AppPalette.textPrimary,- ),- ),- ],+ dimension: extent,+ child: AnimatedOpacity(+ duration: const Duration(milliseconds: 160),+ opacity: live ? 1 : 0.4,+ child: Stack(+ alignment: Alignment.center,+ clipBehavior: Clip.none,+ children: [+ if (face == VoiceMicFace.listening) const _Ring(),+ _Core(face: face, lit: _lit),+ ],+ ),),),),@@ -161,28 +113,106 @@ class _VoiceMicButtonState extends State<VoiceMicButton>}}-/// The ring that leaves the button while it listens.-class _Ring extends StatelessWidget {- const _Ring({required this.breath});+class _Core extends StatelessWidget {+ const _Core({required this.face, required this.lit});- final Animation<double> breath;+ final VoiceMicFace face;+ final bool lit;@override- Widget build(BuildContext context) => AnimatedBuilder(- animation: breath,- builder: (context, _) {- final t = Curves.easeOut.transform(breath.value);- return Transform.scale(- scale: 1 + 0.28 * t,- child: Container(- width: VoiceMicButton._core,- height: VoiceMicButton._core,- decoration: BoxDecoration(- shape: BoxShape.circle,- color: AppPalette.accent.withValues(alpha: 0.35 * (1 - t)),- ),+ 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(AppPalette.accent, Colors.white, 0.18)!,+ AppPalette.accent,+ ],+ )+ : null,+ color: lit ? null : AppGlass.surfaceFill,+ border: Border.all(+ color: lit ? Colors.white.withValues(alpha: 0.28) : AppGlass.lift,+ ),+ boxShadow: lit+ ? [+ BoxShadow(+ color: AppPalette.accent.withValues(alpha: 0.4),+ blurRadius: 12,+ ),+ ]+ : null,+ ),+ 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: 14,+ child: CircularProgressIndicator(+ strokeWidth: 1.8,+ color: AppPalette.accent,),);- },+ }+ return Icon(+ switch (face) {+ VoiceMicFace.listening || VoiceMicFace.retry => LucideIcons.arrowUp300,+ VoiceMicFace.off => LucideIcons.micOff300,+ VoiceMicFace.talk ||+ VoiceMicFace.starting ||+ VoiceMicFace.busy => LucideIcons.mic300,+ },+ size: 16,+ 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_panel_parts.dart b/mobile/lib/phone/voice_panel_parts.dartdeleted file mode 100644index 12b290a07..000000000--- a/mobile/lib/phone/voice_panel_parts.dart+++ /dev/null@@ -1,135 +0,0 @@-import 'package:flutter/material.dart';--import 'package:harness_mobile/shared/theme/app_theme.dart';--/// The language voice input is transcribed in, as a two-letter chip.-class VoiceLanguageChip extends StatelessWidget {- const VoiceLanguageChip({- super.key,- required this.label,- required this.onTap,- });-- final String label;- final VoidCallback onTap;-- @override- Widget build(BuildContext context) => Semantics(- button: true,- label: 'Voice input language, $label',- child: GestureDetector(- key: const ValueKey('voice-language'),- onTap: onTap,- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),- decoration: BoxDecoration(- color: AppGlass.surfaceFill,- borderRadius: BorderRadius.circular(6),- border: Border.all(color: AppGlass.lift),- ),- child: Text(- label,- style: TextStyle(- fontSize: 11,- fontWeight: FontWeight.w600,- color: AppPalette.textPrimary,- ),- ),- ),- ),- );-}--/// A pill beside the mic. Null [onTap] draws it dimmed and dead.-class VoicePanelAction extends StatelessWidget {- const VoicePanelAction({- super.key,- required this.icon,- required this.label,- required this.onTap,- this.emphasized = false,- });-- final IconData icon;- final String label;- final VoidCallback? onTap;- final bool emphasized;-- @override- Widget build(BuildContext context) {- final live = onTap != null;- final filled = emphasized && live;- final foreground = filled- ? Colors.white- : live- ? AppPalette.textPrimary- : AppPalette.textFaint;- return Semantics(- button: true,- enabled: live,- label: label,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: onTap,- child: AnimatedContainer(- duration: const Duration(milliseconds: 160),- curve: Curves.easeOut,- height: 40,- padding: const EdgeInsets.symmetric(horizontal: 14),- decoration: BoxDecoration(- color: filled ? AppPalette.accent : AppGlass.surfaceFill,- borderRadius: BorderRadius.circular(20),- border: Border.all(- color: filled- ? Colors.white.withValues(alpha: 0.2)- : AppGlass.lift,- ),- ),- child: Row(- mainAxisSize: MainAxisSize.min,- children: [- Icon(icon, size: 16, color: foreground),- const SizedBox(width: 6),- Text(- label,- style: TextStyle(- fontSize: 14,- fontWeight: FontWeight.w600,- color: foreground,- ),- ),- ],- ),- ),- ),- );- }-}--/// A bare icon in the panel's status row: Clear, and `⌄`.-class VoicePanelIconButton extends StatelessWidget {- const VoicePanelIconButton({- super.key,- required this.icon,- required this.semanticLabel,- required this.onTap,- });-- final IconData icon;- final String semanticLabel;- final VoidCallback onTap;-- @override- Widget build(BuildContext context) => Semantics(- button: true,- label: semanticLabel,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: onTap,- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),- child: Icon(icon, size: 18, color: AppPalette.textSecondary),- ),- ),- );-}diff --git a/mobile/lib/widgets/terminal_panel.dart b/mobile/lib/widgets/terminal_panel.dartindex 943c7e10e..16408d961 100644--- a/mobile/lib/widgets/terminal_panel.dart+++ b/mobile/lib/widgets/terminal_panel.dart@@ -92,11 +92,12 @@ class TerminalPanel extends StatefulWidget {/// Takes over the tap that would raise the software keyboard. Null leaves it/// to xterm, which is what every desktop tile does.///- /// Set on the phone, where that tap opens voice input instead- /// (`phone/terminal_page.dart`). Claimed on tap DOWN — xterm then neither- /// raises the keyboard nor reports the click to a mouse-tracking program —- /// but run on tap UP, so a scroll that began as a press opens nothing. A tap- /// that clears a selection, or opens a link, is still exactly that.+ /// Set on the phone, where the page raises the keyboard itself, with what the+ /// mic heard typed into the prompt first (`phone/terminal_page.dart`).+ /// Claimed on tap DOWN — xterm then neither raises the keyboard nor reports+ /// the click to a mouse-tracking program — but run on tap UP, so a scroll+ /// that began as a press opens nothing. A tap that clears a selection, or+ /// opens a link, is still exactly that.final VoidCallback? onInputTap;/// Whether this tile's composer textbox is showing. Only consulted for a remote machine.diff --git a/mobile/test/terminal_foot_bar_test.dart b/mobile/test/terminal_foot_bar_test.dartnew file mode 100644index 000000000..a68a8d095--- /dev/null+++ b/mobile/test/terminal_foot_bar_test.dart@@ -0,0 +1,161 @@+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_notice.dart';+import 'package:harness_mobile/terminal/terminal_session.dart';++import 'voice_fakes.dart';++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'));++ 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,+ )+ ..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,+ ),+ ),+ ),+ ),+ );++ testWidgets('at rest it is the machine, its state, and one mic', (+ 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);+ });++ testWidgets('tap to talk, tap again to send it as a turn', (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 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);+ 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);+ await tester.pumpAndSettle();++ expect(recorder.cancels, 1);+ expect(frames, isEmpty);+ expect(cancel, findsNothing);+ expect(find.text('Live'), findsOneWidget);+ });++ testWidgets('a failed send keeps the words, and the mic sends them again', (+ tester,+ ) async {+ session.status = TerminalSessionStatus.takenOver;+ await pumpBar(tester);+ backend.replies.add('deploy');+ await voice.startListening();+ await tester.pump();++ await tester.tap(mic);+ 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);+ await tester.pumpAndSettle();++ expect(frames.single.$2['content'], 'deploy');+ });++ testWidgets('no talking while the terminal takes no input', (tester) async {+ session.status = TerminalSessionStatus.takenOver;+ await pumpBar(tester);++ await tester.tap(mic, warnIfMissed: false);+ await tester.pump();++ expect(recorder.starts, 0);+ });+}diff --git a/mobile/test/terminal_input_dock_test.dart b/mobile/test/terminal_input_dock_test.dartdeleted file mode 100644index cab2385d8..000000000--- a/mobile/test/terminal_input_dock_test.dart+++ /dev/null@@ -1,223 +0,0 @@-import 'package:flutter/material.dart';-import 'package:flutter_test/flutter_test.dart';-import 'package:harness_mobile/phone/terminal_input_dock.dart';-import 'package:harness_mobile/phone/terminal_key_bar.dart';-import 'package:harness_mobile/phone/voice_input_controller.dart';-import 'package:harness_mobile/phone/voice_input_panel.dart';-import 'package:harness_mobile/terminal/terminal_binary.dart';-import 'package:harness_mobile/terminal/terminal_session.dart';--import 'voice_fakes.dart';--void main() {- late FakeVoiceRecorder recorder;- late FakeTranscriber backend;- late VoiceInputController voice;- late TerminalSession session;- late List<(String, Map<String, dynamic>)> frames;- late List<TerminalBinaryFrame> keystrokes;- late int dismissals;- late int keyboardRequests;-- setUp(() {- recorder = FakeVoiceRecorder();- backend = FakeTranscriber();- voice = VoiceInputController(- transcriber: backend.call,- recorder: recorder,- storage: MemoryKeyValueStore(),- preferredLocales: const [],- );- frames = [];- keystrokes = [];- dismissals = 0;- keyboardRequests = 0;- session =- TerminalSession(- machineId: 'm',- agentId: 'a',- agentName: 'Agent',- engineId: 'claude',- send: (type, payload) async {- frames.add((type, payload));- return true;- },- sendBinary: (frame) async {- keystrokes.add(frame);- return true;- },- )- ..status = TerminalSessionStatus.controlling- ..streamId = 's';- });-- tearDown(() {- voice.dispose();- session.dispose();- });-- Future<void> pumpDock(WidgetTester tester, {bool keyboardUp = false}) =>- tester.pumpWidget(- MaterialApp(- home: Scaffold(- body: Align(- alignment: Alignment.bottomCenter,- child: TerminalInputDock(- session: session,- voice: voice,- keyboardUp: keyboardUp,- onDismiss: () => dismissals++,- onUseKeyboard: () => keyboardRequests++,- ),- ),- ),- ),- );-- testWidgets('nothing is drawn while no input is up', (tester) async {- await pumpDock(tester);-- expect(find.byType(TerminalKeyBar), findsNothing);- expect(find.byType(VoiceInputPanel), findsNothing);- });-- testWidgets('the keyboard gets the key bar alone', (tester) async {- await pumpDock(tester, keyboardUp: true);-- expect(find.byType(TerminalKeyBar), findsOneWidget);- expect(find.byType(VoiceInputPanel), findsNothing);- });-- testWidgets('voice input takes the key bar\'s place, and Send makes a turn', (- tester,- ) async {- await pumpDock(tester);- voice.open();- await tester.pump();-- expect(find.byType(TerminalKeyBar), findsNothing);- expect(find.byType(VoiceInputPanel), findsOneWidget);- // Open is not recording: the mic waits to be pressed.- expect(find.text('Tap the mic to talk'), findsOneWidget);- expect(recorder.starts, 0);-- backend.replies.add('summarise the diff');- await tester.tap(find.byKey(const ValueKey('voice-mic')));- await tester.pump();- expect(find.text('Listening…'), findsOneWidget);- await tester.tap(find.byKey(const ValueKey('voice-mic')));- await tester.pump();- expect(find.text('summarise the diff'), findsOneWidget);-- await tester.tap(find.byKey(const ValueKey('voice-send')));- 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(find.text('summarise the diff'), findsNothing);- });-- testWidgets('Send is dead while the terminal takes no input', (tester) async {- session.status = TerminalSessionStatus.takenOver;- await pumpDock(tester);- backend.replies.add('hello');- voice.open();- await voice.startListening();- await voice.stopListening();- await tester.pump();-- await tester.tap(find.byKey(const ValueKey('voice-send')));- await tester.pump();-- expect(frames, isEmpty);- expect(voice.transcript, 'hello');- });-- testWidgets('Keyboard and ⌄ hand back to the page', (tester) async {- await pumpDock(tester);- voice.open();- await tester.pump();-- await tester.tap(find.byKey(const ValueKey('voice-keyboard')));- await tester.tap(find.byKey(const ValueKey('voice-hide')));-- expect(keyboardRequests, 1);- expect(dismissals, 1);- });-- testWidgets('with nothing said, Send is Enter for what the prompt holds', (- tester,- ) async {- await pumpDock(tester);- voice.open();- await tester.pump();-- await tester.tap(find.byKey(const ValueKey('voice-send')));- await tester.pump();- // The input path queues its send on a future chain the fake clock does not- // drain; a real turn of the event loop does.- await tester.runAsync(() => Future<void>.delayed(Duration.zero));-- expect(frames, isEmpty, reason: 'no message: nothing was said');- expect(- keystrokes- .where((frame) => frame.kind == TerminalBinaryKind.input)- .expand((frame) => frame.bytes),- [13],- );- });-- testWidgets('Send mid-sentence finishes the take and sends it', (- tester,- ) async {- backend.replies.add('ship it');- await pumpDock(tester);- voice.open();- await voice.startListening();- await tester.pump();-- await tester.tap(find.byKey(const ValueKey('voice-send')));- await tester.pumpAndSettle();-- expect(recorder.stops, 1);- expect(frames.single.$2['content'], 'ship it');- });-- testWidgets('the language chip names the language takes are sent in', (- tester,- ) async {- await pumpDock(tester);- voice.open();- await tester.pump();- expect(find.text('EN'), findsOneWidget);-- await tester.tap(find.byKey(const ValueKey('voice-language')));- await tester.pumpAndSettle();- await tester.tap(find.text('Tiếng Việt'));- await tester.pumpAndSettle();-- expect(find.text('VI'), findsOneWidget);- expect(voice.language, 'vi');- });-- testWidgets('the mic stops a take and starts the next', (tester) async {- await pumpDock(tester);- voice.open();- await voice.startListening();- await tester.pump();-- await tester.tap(find.byKey(const ValueKey('voice-mic')));- await tester.pump();- expect(voice.status, VoiceInputStatus.idle);- expect(recorder.stops, 1);-- await tester.tap(find.byKey(const ValueKey('voice-mic')));- await tester.pump();- expect(voice.status, VoiceInputStatus.listening);- // Stopped here, not left breathing: the ring repeats forever.- voice.close();- await tester.pumpAndSettle();- });-}diff --git a/mobile/test/terminal_panel_input_tap_test.dart b/mobile/test/terminal_panel_input_tap_test.dartindex 9e228a63c..fee916b49 100644--- a/mobile/test/terminal_panel_input_tap_test.dart+++ b/mobile/test/terminal_panel_input_tap_test.dart@@ -8,10 +8,10 @@ import 'package:harness_mobile/terminal/terminal_session.dart';import 'package:harness_mobile/widgets/terminal_panel.dart';import 'package:xterm/xterm.dart';-/// On the phone a tap on the terminal opens voice input, and the keyboard is-/// only ever what voice input hands over to. The panel is where that tap is-/// taken: xterm would otherwise raise the keyboard itself before anyone else-/// could say otherwise.+/// On the phone the page decides what a tap on the terminal does — it types+/// what the mic heard into the prompt before it raises the keyboard. The panel+/// is where that tap is taken: xterm would otherwise raise the keyboard itself+/// before anyone else could say otherwise.void main() {late AppNotifier notifier;late TerminalSession session;diff --git a/mobile/test/voice_input_controller_test.dart b/mobile/test/voice_input_controller_test.dartindex d3f18380d..39cb0b426 100644--- a/mobile/test/voice_input_controller_test.dart+++ b/mobile/test/voice_input_controller_test.dart@@ -1,7 +1,6 @@import 'dart:async';-import 'dart:typed_data';-import 'dart:ui';+import 'package:flutter/foundation.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/phone/voice_input_controller.dart';import 'package:harness_mobile/phone/voice_notice.dart';@@ -11,55 +10,43 @@ import 'voice_fakes.dart';void main() {late FakeVoiceRecorder recorder;late FakeTranscriber backend;- late MemoryKeyValueStore storage;+ late ValueNotifier<String> language;late VoiceInputController voice;- VoiceInputController controller({List<Locale> locales = const []}) =>- VoiceInputController(- transcriber: backend.call,- recorder: recorder,- storage: storage,- preferredLocales: locales,- );-setUp(() {recorder = FakeVoiceRecorder();backend = FakeTranscriber();- storage = MemoryKeyValueStore();- voice = controller();+ language = ValueNotifier('en');+ voice = VoiceInputController(+ transcriber: backend.call,+ recorder: recorder,+ language: language,+ );});- tearDown(() => voice.dispose());-- test('opening puts the panel up and leaves the microphone off', () {- voice.open();-- expect(voice.isOpen, isTrue);- expect(voice.status, VoiceInputStatus.idle);- expect(recorder.starts, 0);+ tearDown(() {+ voice.dispose();+ language.dispose();});- test('the mic button is what records', () async {- voice.open();+ test('at rest until the mic is pressed', () async {+ expect(voice.isIdle, isTrue);+ expect(recorder.starts, 0);- await voice.toggleListening();+ await voice.startListening();expect(voice.status, VoiceInputStatus.listening);expect(recorder.recording, isTrue);+ expect(voice.isIdle, isFalse);});- test(- 'Send has speech only once something was said or is being said',- () async {- expect(voice.hasSpeech, isFalse);+ test('an empty take leaves the mic at rest again', () async {+ await voice.startListening();- await voice.startListening();- expect(voice.hasSpeech, isTrue);+ await voice.stopListening();- await voice.stopListening();- expect(voice.hasSpeech, isFalse, reason: 'the take came back empty');- },- );+ expect(voice.isIdle, isTrue, reason: 'the take came back empty');+ });test('stopping sends the take to the backend and keeps its words', () async {backend.replies.add('fix the failing test');@@ -92,15 +79,15 @@ void main() {test('a second take adds to what the first one heard', () async {backend.replies.addAll(['run the tests', 'then commit']);await voice.startListening();- await voice.toggleListening();+ await voice.stopListening();- await voice.toggleListening();- await voice.toggleListening();+ await voice.startListening();+ await voice.stopListening();expect(voice.transcript, 'run the tests then commit');});- test('a refused microphone says so, and the next open asks again', () async {+ test('a refused microphone says so, and the next press asks again', () async {recorder.permitted = false;await voice.startListening();@@ -108,17 +95,16 @@ void main() {expect(voice.notice, VoiceNotice.unavailable);recorder.permitted = true;- voice.close();await voice.startListening();expect(voice.status, VoiceInputStatus.listening);});- test('closing while the permission prompt is up records nothing', () async {+ test('clearing while the permission prompt is up records nothing', () async {recorder.pendingPermission = Completer<bool>();final opening = voice.startListening();expect(voice.status, VoiceInputStatus.starting);- voice.close();+ voice.clear();recorder.pendingPermission!.complete(true);await opening;@@ -169,7 +155,7 @@ void main() {expect(voice.notice, VoiceNotice.noSound);});- test('send hands over everything heard and empties the panel', () async {+ test('send hands over everything heard and empties the transcript', () async {backend.replies.add('open a PR');await voice.startListening();await voice.stopListening();@@ -227,24 +213,24 @@ void main() {expect(voice.isSending, isFalse);});- test('closing mid-transcription drops the words when they arrive', () async {+ test('clearing mid-transcription drops the words when they arrive', () async {backend.pending = Completer<String>();await voice.startListening();final stopping = voice.stopListening();await Future<void>.delayed(Duration.zero);- voice.close();+ voice.clear();backend.pending!.complete('never mind');await stopping;- expect(voice.isOpen, isFalse);expect(voice.transcript, isEmpty);+ expect(voice.isIdle, isTrue);});- test('closing while recording throws the recording away', () async {+ test('clearing while recording throws the recording away', () async {await voice.startListening();- voice.close();+ voice.clear();expect(recorder.cancels, 1);expect(backend.calls, isEmpty);@@ -263,37 +249,27 @@ void main() {},);- test("the phone's language is the default, when the backend serves it", () {- final vietnamese = controller(locales: const [Locale('vi', 'VN')]);- final german = controller(locales: const [Locale('de'), Locale('fr')]);- addTearDown(vietnamese.dispose);- addTearDown(german.dispose);+ test('words already on their way are not handed to the keyboard', () async {+ backend.replies.add('ship it');+ await voice.startListening();+ await voice.stopListening();+ final delivery = Completer<bool>();+ final sending = voice.submit((_) => delivery.future);+ await Future<void>.delayed(Duration.zero);- expect(vietnamese.language, 'vi');- expect(german.language, 'fr');- });+ expect(await voice.takeTranscript(), isEmpty);- test(- 'a chosen language is used, remembered, and restored next time',- () async {- await voice.selectLanguage('vi');- backend.replies.add('xin chào');- await voice.startListening();- await voice.stopListening();-- expect(backend.calls.single.lang, 'vi');- expect(storage.values['voice_input_language'], 'vi');+ delivery.complete(true);+ await sending;+ });- final later = controller();- addTearDown(later.dispose);- await Future<void>.delayed(Duration.zero);- expect(later.language, 'vi');- },- );+ test('a take is heard in the language chosen by the time it ends', () async {+ backend.replies.add('xin chào');+ await voice.startListening();- test('a language the backend does not serve is refused', () async {- await voice.selectLanguage('de');+ language.value = 'vi';+ await voice.stopListening();- expect(voice.language, 'en');+ expect(backend.calls.single.lang, 'vi');});}diff --git a/mobile/test/voice_language_store_test.dart b/mobile/test/voice_language_store_test.dartnew file mode 100644index 000000000..0c2154e93--- /dev/null+++ b/mobile/test/voice_language_store_test.dart@@ -0,0 +1,42 @@+import 'dart:ui';++import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/phone/voice_language_store.dart';++import 'voice_fakes.dart';++void main() {+ late MemoryKeyValueStore storage;++ VoiceLanguageStore store({List<Locale> locales = const []}) =>+ VoiceLanguageStore(storage: storage, preferredLocales: locales);++ setUp(() => storage = MemoryKeyValueStore());++ test("the phone's language is the default, when the backend serves it", () {+ expect(store(locales: const [Locale('vi', 'VN')]).value, 'vi');+ expect(store(locales: const [Locale('de'), Locale('fr')]).value, 'fr');+ expect(store().value, 'en');+ });++ test('a chosen language is remembered and restored next time', () async {+ await store().select('vi');++ expect(storage.values['voice_input_language'], 'vi');++ final later = store();+ await later.load();+ expect(later.value, 'vi');+ });++ test('a language the backend does not serve is refused', () async {+ final languages = store();++ await languages.select('de');+ expect(languages.value, 'en');++ storage.values['voice_input_language'] = 'de';+ await languages.load();+ expect(languages.value, 'en');+ });+}