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
Phone: the chat composer as one floating card, with X, @ Tag and voice that never sends (Tony) (#2477)
0xken15fd3cd0463752
diff --git a/mobile/lib/shared/theme/swarm_tokens_set_b.dart b/mobile/lib/shared/theme/swarm_tokens_set_b.dartindex 141ba8267..167296eb9 100644--- a/mobile/lib/shared/theme/swarm_tokens_set_b.dart+++ b/mobile/lib/shared/theme/swarm_tokens_set_b.dart@@ -18,3 +18,33 @@ abstract final class SwarmConfetti {Color(0xff6ad08a),];}++/// The chat composer's card (Tony's composer brief, 11-01): the measures the+/// shared roles have no name for. Used by the chat, New message and a+/// thread's reply box.+abstract final class SwarmComposer {+ /// Around the composer column: no band of its own, the card floats.+ static const EdgeInsets padding = EdgeInsets.symmetric(+ horizontal: 8,+ vertical: 6,+ );++ static const double cardRadius = 24;++ /// The files going, inside the card above the field.+ static const EdgeInsets chipsPadding = EdgeInsets.fromLTRB(10, 10, 10, 0);++ /// The field's text. The right 44 is always kept for the X, so the text+ /// does not rewrap as it comes and goes.+ static const EdgeInsets fieldPadding = EdgeInsets.fromLTRB(16, 12, 44, 2);++ /// The toolbar's 44pt row inside the card.+ static const EdgeInsets toolbarPadding = EdgeInsets.fromLTRB(6, 0, 6, 4);++ /// The @ Tag chip's pill.+ static const EdgeInsets tagPadding = EdgeInsets.only(left: 10, right: 13);+ static const double tagRadius = 18;++ /// The voice row's stop: a filled square with softened corners.+ static const double stopRadius = 2;+}diff --git a/mobile/lib/swarm/swarm_attach.dart b/mobile/lib/swarm/swarm_attach.dartindex 8d4235196..5516b6d37 100644--- a/mobile/lib/swarm/swarm_attach.dart+++ b/mobile/lib/swarm/swarm_attach.dart@@ -186,12 +186,13 @@ class SwarmOutgoingChips extends StatelessWidget {Widget build(BuildContext context) {final files = box.files.files;if (files.isEmpty) return const SizedBox.shrink();+ // Inside the composer's card, which spaces it ([SwarmComposerCard]).return SizedBox(- height: _chipHeight + AppSpace.s,+ height: _chipHeight,child: ListView.separated(key: const ValueKey('swarm-outgoing'),scrollDirection: Axis.horizontal,- padding: const EdgeInsets.only(bottom: AppSpace.s),+ padding: EdgeInsets.zero,itemCount: files.length,separatorBuilder: (_, _) => const SizedBox(width: AppSpace.s),itemBuilder: (context, i) => _Chip(diff --git a/mobile/lib/swarm/swarm_conversation.dart b/mobile/lib/swarm/swarm_conversation.dartindex 53ab6ea55..dbc13042b 100644--- a/mobile/lib/swarm/swarm_conversation.dart+++ b/mobile/lib/swarm/swarm_conversation.dart@@ -354,6 +354,20 @@ class SwarmConversation extends ChangeNotifier implements SwarmFilesBox {mention(id);}+ /// The Tag chip: ends the draft in an @, which opens the picker, or takes+ /// back an @ with no name typed after it. A name being typed is left alone.+ void toggleMention() {+ switch (mentionQuery) {+ case null:+ final spaced = _draft.isEmpty || RegExp(r'\s$').hasMatch(_draft);+ draft = '$_draft${spaced ? '' : ' '}@';+ case '':+ draft = _draft.substring(0, _draft.length - 1);+ case _:+ break;+ }+ }+/// Adds [id]'s name to the draft: an agent's (the post goes to it) or a/// person's username (the post tags them), while the name stays in the/// text.diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dartindex a2586eb09..f77f2df9b 100644--- a/mobile/lib/swarm/swarm_conversation_page.dart+++ b/mobile/lib/swarm/swarm_conversation_page.dart@@ -9,10 +9,10 @@ import 'package:harness_mobile/phone/composing_keyboard.dart';import 'package:harness_mobile/phone/phone_navigation.dart';import 'package:harness_mobile/phone/tty.dart';import 'package:harness_mobile/phone/tty_controls.dart';-import 'package:harness_mobile/shared/theme/app_icon_size.dart';import 'package:harness_mobile/shared/theme/app_ink.dart';import 'package:harness_mobile/shared/theme/app_space.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/theme/swarm_tokens_set_b.dart';import 'package:harness_mobile/shared/theme/app_type.dart';import 'package:harness_mobile/shared/widgets/skeleton.dart';@@ -300,7 +300,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>dictation: SwarmScope.dictationOf(context),draft: () => _conversation?.draft ?? '',write: (text) => _conversation?.draft = text,- send: _spoken,);}}@@ -422,9 +421,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>if (c.heldAt == _undecided) c.heldAt = widget.messageId ?? _held.value;}- /// A read came in: the line, if a failed read left it to place; the notice's- /// message, once a read has brought what to look for it in; and what is- /// offered of the line, since the list changed./// A take goes with the right to post here, as in a thread: the chat lost,/// archived, or the person no longer a writer. Its words land nowhere/// ([SwarmVoice.hide]). Nothing while the chat is still being read.@@ -436,6 +432,9 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>if (c.state == SwarmChatState.lost || !c.canPost) _voice?.hide();}+ /// A read came in: the line, if a failed read left it to place; the notice's+ /// message, once a read has brought what to look for it in; and what is+ /// offered of the line, since the list changed.void _chatMoved() {final c = _conversation;if (c == null || !_firstRead) return;@@ -701,15 +700,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>);}- /// The second tap on the mic ended a take: what is in the box goes, as Send- /// would send it. Nothing when the box is empty, the chat is covered, or a- /// post is already on its way.- void _spoken() {- final c = _conversation;- if (c == null || !_visible || c.draft.trim().isEmpty || !c.canSend) return;- _send(c);- }-/// The composer's + ([attachSwarmFiles]), its files into [c]'s.Future<void> _pickFiles(SwarmConversation c) async {if (_picking) return;@@ -1229,111 +1219,147 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>),),if (_buddy case final buddy?) SwarmBuddyBar(actions: buddy),+ // The composer takes what it needs, up to all of the room under the+ // header: on a short phone with the keyboard up its field gives up lines+ // before anything overflows; the messages have the rest.Expanded(- child: Stack(- children: [- Positioned.fill(- child: ListenableBuilder(- listenable: Listenable.merge([c, _held]),- builder: (context, _) =>- _messages(context, session, c, view, tty),- ),- ),- // At the top of the list, as Jump to latest is at its foot: the- // two can show at once.- Positioned(- left: 0,- right: 0,- top: 8,- child: ListenableBuilder(- listenable: Listenable.merge([c, _offersUnread]),- builder: (context, _) =>- _offersUnread.value &&- c.state != SwarmChatState.lost &&- c.stream.isNotEmpty- ? Center(- child: SwarmJumpToUnreadPill(onTap: _jumpToFirstUnread),- )- : const SizedBox.shrink(),- ),- ),- Positioned(- left: 0,- right: 0,- bottom: 8,- child: ListenableBuilder(- listenable: Listenable.merge([c, _held, _farBack]),- builder: (context, _) => switch (_waiting(c)) {- 0 when !_farBack.value || c.state == SwarmChatState.lost =>- const SizedBox.shrink(),- final count => Center(- child: SwarmNewPill(count: count, onTap: _toFoot),- ),- },- ),- ),- ],- ),- ),- ListenableBuilder(- listenable: c,- builder: (context, _) {- final note = _finding ? 'Finding the original message…' : _note;- return Column(+ child: LayoutBuilder(+ builder: (context, below) => Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [- if (note != null)- Padding(- padding: const EdgeInsets.fromLTRB(- AppSpace.screenInset,- AppSpace.s,- AppSpace.screenInset,- 0,- ),- child: Text(- note,- key: const ValueKey('swarm-find-note'),- style: swarmChatText(13.5, color: AppPalette.textSecondary),- ),+ Expanded(+ child: Stack(+ children: [+ Positioned.fill(+ child: ListenableBuilder(+ listenable: Listenable.merge([c, _held]),+ builder: (context, _) =>+ _messages(context, session, c, view, tty),+ ),+ ),+ // At the top of the list, as Jump to latest is at its foot: the+ // two can show at once.+ Positioned(+ left: 0,+ right: 0,+ top: 8,+ child: ListenableBuilder(+ listenable: Listenable.merge([c, _offersUnread]),+ builder: (context, _) =>+ _offersUnread.value &&+ c.state != SwarmChatState.lost &&+ c.stream.isNotEmpty+ ? Center(+ child: SwarmJumpToUnreadPill(+ onTap: _jumpToFirstUnread,+ ),+ )+ : const SizedBox.shrink(),+ ),+ ),+ Positioned(+ left: 0,+ right: 0,+ bottom: 8,+ child: ListenableBuilder(+ listenable: Listenable.merge([c, _held, _farBack]),+ builder: (context, _) => switch (_waiting(c)) {+ 0+ when !_farBack.value ||+ c.state == SwarmChatState.lost =>+ const SizedBox.shrink(),+ final count => Center(+ child: SwarmNewPill(count: count, onTap: _toFoot),+ ),+ },+ ),+ ),+ ],),- // Unless the body says it already: not open, or no conversation- // and nothing read.- if (c.error case final error?- when c.state != SwarmChatState.lost &&- (view.known || c.messages.isNotEmpty))- Padding(- padding: const EdgeInsets.fromLTRB(- AppSpace.screenInset,- AppSpace.s,- AppSpace.screenInset,- 0,- ),- child: Text(- error,- key: const ValueKey('swarm-post-error'),- style: swarmChatText(13.5, color: tty.red),- ),+ ),+ ConstrainedBox(+ constraints: BoxConstraints(maxHeight: below.maxHeight),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ ListenableBuilder(+ listenable: c,+ builder: (context, _) {+ final note = _finding+ ? 'Finding the original message…'+ : _note;+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ if (note != null)+ Padding(+ padding: const EdgeInsets.fromLTRB(+ AppSpace.screenInset,+ AppSpace.s,+ AppSpace.screenInset,+ 0,+ ),+ child: Text(+ note,+ key: const ValueKey('swarm-find-note'),+ style: swarmChatText(+ 13.5,+ color: AppPalette.textSecondary,+ ),+ ),+ ),+ // Unless the body says it already: not open, or no conversation+ // and nothing read.+ if (c.error case final error?+ when c.state != SwarmChatState.lost &&+ (view.known || c.messages.isNotEmpty))+ Padding(+ padding: const EdgeInsets.fromLTRB(+ AppSpace.screenInset,+ AppSpace.s,+ AppSpace.screenInset,+ 0,+ ),+ child: Text(+ error,+ key: const ValueKey('swarm-post-error'),+ style: swarmChatText(13.5, color: tty.red),+ ),+ ),+ ],+ );+ },+ ),+ if (view.canPost)+ Flexible(+ child: ListenableBuilder(+ listenable: Listenable.merge([c.composer, _voice]),+ builder: (context, _) =>+ _composer(c, tty, hint: view.hint),+ ),+ )+ else if (view.known)+ Padding(+ padding: const EdgeInsets.all(AppSpace.l),+ child: Text(+ view.archived+ ? 'This chat is archived.'+ : 'You can read this chat, not post in it.',+ key: const ValueKey('swarm-read-only'),+ style: swarmChatText(+ 13.5,+ color: AppPalette.textSecondary,+ ),+ ),+ ),+ ],),+ ),],- );- },- ),- if (view.canPost)- ListenableBuilder(- listenable: Listenable.merge([c.composer, _voice]),- builder: (context, _) => _composer(c, tty, hint: view.hint),- )- else if (view.known)- Padding(- padding: const EdgeInsets.all(AppSpace.l),- child: Text(- view.archived- ? 'This chat is archived.'- : 'You can read this chat, not post in it.',- key: const ValueKey('swarm-read-only'),- style: swarmChatText(13.5, color: AppPalette.textSecondary),),),+ ),],);@@ -1854,30 +1880,31 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>}/// The @ picker while a name is typed, the reply bar while the draft- /// answers a message, what the last pick left out, the files going with the- /// post, what the mic could not hear, then +, a field that grows with what- /// is typed, the mic and a round Send. An @ is typed in the field: it has no- /// button of its own.+ /// answers a message, what the last pick left out and what the mic could+ /// not hear, then the card ([SwarmComposerCard]): the files going with the+ /// post, a field that grows with what is typed and its X, and the toolbar —+ /// +, @ Tag, the mic and a round Send. While a take is under way the toolbar+ /// is the voice row ([SwarmVoiceRow]) and the picker and X are hidden. An @+ /// is typed in the field or put there by Tag: both open the same picker.Widget _composer(SwarmConversation c, Tty tty, {required String hint}) {final snapshot = c.reader.snapshot;final query = c.mentionQuery;final replying = c.replyingTo;+ final voice = _voice;+ final talking = voice?.face != null;// A post on its way never holds the next back; one not confirmed is sent// again from where it shows. Files alone are a post too.final canSend = c.canSend;- return Container(- decoration: BoxDecoration(- color: Color.alphaBlend(tty.text.withValues(alpha: 0.02), tty.ground),- border: Border(top: BorderSide(color: swarmChatHair(tty))),- ),- padding: const EdgeInsets.symmetric(- horizontal: AppSpace.m,- vertical: AppSpace.s,- ),+ final taggable =+ snapshot != null &&+ (c.mentionablePeople.isNotEmpty || c.mentionable.isNotEmpty);+ return Padding(+ padding: SwarmComposer.padding,child: Column(+ mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.stretch,children: [- if (query != null && snapshot != null)+ if (query != null && snapshot != null && !talking)_MentionPicker(people: c.mentionablePeople,agents: c.mentionable,@@ -1995,47 +2022,61 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>style: AppType.caption(color: AppPalette.textSecondary),),),- SwarmOutgoingChips(box: c),- Row(- crossAxisAlignment: CrossAxisAlignment.end,- children: [- if (swarmSendsFiles)- SwarmAttachButton(- key: const ValueKey('swarm-attach'),- onTap: c.uploading || c.files.room <= 0- ? null- : () => unawaited(_pickFiles(c)),- ),- const SizedBox(width: 6),- Expanded(- child: SwarmMessageField(- controller: _text,- focus: _focus,- hint: hint,- imagePaste: swarmSendsFiles- ? SwarmImagePaste(- enabled: !c.uploading && c.files.room > 0,- onImage: (image) => unawaited(_pasteImage(c, image)),- )- : null,- ),- ),- if (_voice case final voice?)- SwarmVoiceMic(voice: voice)- else- const SizedBox(width: 6),- SwarmRoundButton(- key: const ValueKey('swarm-send'),- label: 'Send',- fill: canSend ? AppPalette.accent : ttyRaised(tty),- onTap: canSend ? () => _send(c) : null,- child: Icon(- LucideIcons.arrowUp,- size: 20,- color: canSend ? AppInk.onFill : AppPalette.textFaint,- ),+ Flexible(+ child: SwarmComposerCard(+ focus: _focus,+ fit: true,+ chips: c.files.files.isEmpty ? null : SwarmOutgoingChips(box: c),+ field: SwarmMessageField(+ controller: _text,+ focus: _focus,+ hint: hint,+ clearable: !talking,+ imagePaste: swarmSendsFiles+ ? SwarmImagePaste(+ enabled: !c.uploading && c.files.room > 0,+ onImage: (image) => unawaited(_pasteImage(c, image)),+ )+ : null,),- ],+ toolbar: talking+ ? SwarmVoiceRow(voice: voice!)+ : Row(+ children: [+ if (swarmSendsFiles)+ SwarmAttachButton(+ key: const ValueKey('swarm-attach'),+ onTap: c.uploading || c.files.room <= 0+ ? null+ : () => unawaited(_pickFiles(c)),+ ),+ if (taggable)+ _TagChip(+ open: query != null,+ onTap: () {+ c.toggleMention();+ _focus.requestFocus();+ },+ ),+ const Spacer(),+ if (voice != null) SwarmVoiceMic(voice: voice),+ SwarmRoundButton(+ key: const ValueKey('swarm-send'),+ label: 'Send',+ face: 36,+ fill: canSend ? AppPalette.accent : ttyRaised(tty),+ onTap: canSend ? () => _send(c) : null,+ child: Icon(+ LucideIcons.arrowUp,+ size: 20,+ color: canSend+ ? AppInk.onFill+ : AppPalette.textFaint,+ ),+ ),+ ],+ ),+ ),),],),@@ -3039,8 +3080,10 @@ class _AnswerIn extends StatelessWidget {);}-/// The composer's field: one rounded line that grows with what is typed, up-/// to five, in the app's own face. A thread's reply box has it too.+/// The composer's field inside [SwarmComposerCard]: text that grows with+/// what is typed, 1 to 5 lines and then scrolls, in the app's own face, with+/// an X pinned at its top right that clears the text (Tony, 11-01). A thread's+/// reply box and New message have it too.class SwarmMessageField extends StatelessWidget {const SwarmMessageField({super.key,@@ -3048,6 +3091,8 @@ class SwarmMessageField extends StatelessWidget {required this.focus,required this.hint,this.fieldKey = const ValueKey('swarm-field'),+ this.clearKey = const ValueKey('swarm-field-clear'),+ this.clearable = true,this.imagePaste,});@@ -3059,90 +3104,194 @@ class SwarmMessageField extends StatelessWidget {/// takes text alone.final SwarmImagePaste? imagePaste;- /// The pill's key: the chat's and a thread's box are told apart by it.+ /// The field's key: the chat's, a thread's and New message's are told+ /// apart by it.final Key fieldKey;+ /// The X's key.+ final Key clearKey;++ /// Whether the X shows while there is text: not during a take.+ final bool clearable;+@overrideWidget build(BuildContext context) {final tty = Tty.of(context);- return GestureDetector(- // A tap anywhere in the pill — not only on the text — takes the keyboard.- behavior: HitTestBehavior.opaque,- onTap: focus.requestFocus,- child: Container(- key: fieldKey,- constraints: const BoxConstraints(minHeight: 44),- alignment: Alignment.centerLeft,- // One line rests at the 44 of the buttons beside it.- padding: const EdgeInsets.symmetric(- horizontal: AppSpace.l,- vertical: AppSpace.s,- ),- decoration: BoxDecoration(- color: ttyRaised(tty),- border: Border.all(color: swarmChatHair(tty)),- // A text field's rounded rectangle.- borderRadius: BorderRadius.circular(AppControl.radius),- ),- child: TextSelectionTheme(- data: TextSelectionThemeData(- cursorColor: AppPalette.accentOnSurface,- selectionColor: AppPalette.accentOnSurface.withValues(alpha: 0.3),- selectionHandleColor: AppPalette.accentOnSurface,- ),- child: TextField(- controller: controller,- focusNode: focus,- minLines: 1,- maxLines: 5,- keyboardType: TextInputType.multiline,- textInputAction: TextInputAction.newline,- textCapitalization: TextCapitalization.sentences,- // The keyboard's own composing, left on: Vietnamese Telex on iOS- // rides on autocorrection. See `ComposingKeyboard`.- autocorrect: ComposingKeyboard.autocorrect,- enableSuggestions: ComposingKeyboard.enableSuggestions,- smartDashesType: SmartDashesType.disabled,- smartQuotesType: SmartQuotesType.disabled,- contextMenuBuilder: (context, field) =>- swarmFieldMenu(context, field, imagePaste),- contentInsertionConfiguration: switch (imagePaste) {- final paste? => ContentInsertionConfiguration(- allowedMimeTypes: swarmInsertedImageTypes,- onContentInserted: (content) =>- paste.onImage(SwarmPastedImage.inserted(content)),+ return Stack(+ children: [+ GestureDetector(+ // A tap anywhere in the field's area — not only on the text — takes+ // the keyboard.+ behavior: HitTestBehavior.opaque,+ onTap: focus.requestFocus,+ child: Container(+ key: fieldKey,+ // The right 44 is always kept for the X, so the text does not+ // rewrap as it comes and goes.+ padding: SwarmComposer.fieldPadding,+ child: TextSelectionTheme(+ data: TextSelectionThemeData(+ cursorColor: AppPalette.accentOnSurface,+ selectionColor: AppPalette.accentOnSurface.withValues(+ alpha: 0.3,+ ),+ selectionHandleColor: AppPalette.accentOnSurface,),- null => null,- },- cursorColor: AppPalette.accentOnSurface,- cursorWidth: 2,- style: swarmChatText(16, height: 22 / 16),- decoration: InputDecoration(- isCollapsed: true,- // No minimum of its own: the pill's 44 is the field's height.- constraints: const BoxConstraints(),- filled: false,- border: InputBorder.none,- enabledBorder: InputBorder.none,- focusedBorder: InputBorder.none,- disabledBorder: InputBorder.none,- contentPadding: EdgeInsets.zero,- hintText: hint,- hintStyle: swarmChatText(- 16,- height: 22 / 16,- color: AppPalette.textFaint,+ child: TextField(+ controller: controller,+ focusNode: focus,+ minLines: 1,+ maxLines: 5,+ keyboardType: TextInputType.multiline,+ textInputAction: TextInputAction.newline,+ textCapitalization: TextCapitalization.sentences,+ // The keyboard's own composing, left on: Vietnamese Telex on+ // iOS rides on autocorrection. See `ComposingKeyboard`.+ autocorrect: ComposingKeyboard.autocorrect,+ enableSuggestions: ComposingKeyboard.enableSuggestions,+ smartDashesType: SmartDashesType.disabled,+ smartQuotesType: SmartQuotesType.disabled,+ contextMenuBuilder: (context, field) =>+ swarmFieldMenu(context, field, imagePaste),+ contentInsertionConfiguration: switch (imagePaste) {+ final paste? => ContentInsertionConfiguration(+ allowedMimeTypes: swarmInsertedImageTypes,+ onContentInserted: (content) =>+ paste.onImage(SwarmPastedImage.inserted(content)),+ ),+ null => null,+ },+ cursorColor: AppPalette.accentOnSurface,+ cursorWidth: 2,+ style: swarmChatText(16, height: 22 / 16),+ decoration: InputDecoration(+ isCollapsed: true,+ constraints: const BoxConstraints(),+ filled: false,+ border: InputBorder.none,+ enabledBorder: InputBorder.none,+ focusedBorder: InputBorder.none,+ disabledBorder: InputBorder.none,+ contentPadding: EdgeInsets.zero,+ hintText: hint,+ hintStyle: swarmChatText(+ 16,+ height: 22 / 16,+ color: AppPalette.textFaint,+ ),+ ),),),),),+ if (clearable)+ Positioned(+ top: 1,+ right: 0,+ child: ValueListenableBuilder<TextEditingValue>(+ valueListenable: controller,+ builder: (context, value, _) => value.text.isEmpty+ ? const SizedBox.shrink()+ : Semantics(+ button: true,+ label: 'Clear text',+ excludeSemantics: true,+ onTap: controller.clear,+ child: GestureDetector(+ key: clearKey,+ behavior: HitTestBehavior.opaque,+ // Text only: files and the reply stay, and so do the+ // focus and the keyboard.+ onTap: controller.clear,+ child: SizedBox.square(+ dimension: 44,+ child: Center(+ child: Container(+ width: 24,+ height: 24,+ alignment: Alignment.center,+ decoration: BoxDecoration(+ color: tty.text.withValues(alpha: 0.11),+ shape: BoxShape.circle,+ ),+ child: Icon(+ LucideIcons.x,+ size: 14,+ color: AppPalette.textSecondary,+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ ],+ );+ }+}++/// The composer as one floating card (Tony, 11-01; Claude and Slack's+/// layout): the files going, the field, then the toolbar. Used by the chat,+/// New message and a thread's reply box. The border darkens while [focus]+/// has the keyboard.+class SwarmComposerCard extends StatelessWidget {+ const SwarmComposerCard({+ super.key,+ this.chips,+ required this.field,+ required this.toolbar,+ required this.focus,+ this.fit = false,+ });++ /// The files going with the post; null while there are none.+ final Widget? chips;++ /// Under a height limit, the field gives up lines first (fewer than five,+ /// then it scrolls): the chat's composer on a short phone with the keyboard+ /// up. Only where the card's parent bounds its height.+ final bool fit;+ final Widget field;+ final Widget toolbar;+ final FocusNode focus;++ @override+ Widget build(BuildContext context) {+ final tty = Tty.of(context);+ return ListenableBuilder(+ listenable: focus,+ builder: (context, _) => Container(+ key: const ValueKey('swarm-composer-card'),+ decoration: BoxDecoration(+ color: swarmChatCard(tty),+ border: Border.all(+ color: focus.hasFocus+ ? tty.text.withValues(alpha: 0.26)+ : swarmChatHair(tty),+ ),+ borderRadius: BorderRadius.circular(SwarmComposer.cardRadius),+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ if (chips case final chips?)+ Padding(padding: SwarmComposer.chipsPadding, child: chips),+ if (fit) Flexible(child: field) else field,+ Padding(+ padding: SwarmComposer.toolbarPadding,+ child: SizedBox(height: 44, child: toolbar),+ ),+ ],+ ),),);}}-/// A round 44pt button: @, Send, the reply bar's ✕, a thread's Send. [fill]-/// draws it solid.+/// A round button in a 44pt target: Send, the reply bar's ✕, +. [fill] draws+/// it solid; with [face] the fill is a circle that wide, centred in the 44.class SwarmRoundButton extends StatelessWidget {const SwarmRoundButton({super.key,@@ -3150,6 +3299,7 @@ class SwarmRoundButton extends StatelessWidget {required this.onTap,required this.child,this.fill,+ this.face,});final String label;@@ -3157,6 +3307,9 @@ class SwarmRoundButton extends StatelessWidget {final Widget child;final Color? fill;+ /// The visible circle's width; null fills the whole 44.+ final double? face;+@overrideWidget build(BuildContext context) => Semantics(button: true,@@ -3166,13 +3319,27 @@ class SwarmRoundButton extends StatelessWidget {child: GestureDetector(behavior: HitTestBehavior.opaque,onTap: onTap,- child: Container(- width: 44,- height: 44,- alignment: Alignment.center,- decoration: BoxDecoration(color: fill, shape: BoxShape.circle),- child: child,- ),+ child: switch (face) {+ null => Container(+ width: 44,+ height: 44,+ alignment: Alignment.center,+ decoration: BoxDecoration(color: fill, shape: BoxShape.circle),+ child: child,+ ),+ final face => SizedBox.square(+ dimension: 44,+ child: Center(+ child: SizedBox.square(+ dimension: face,+ child: DecoratedBox(+ decoration: BoxDecoration(color: fill, shape: BoxShape.circle),+ child: Center(child: child),+ ),+ ),+ ),+ ),+ },),);}@@ -3188,14 +3355,74 @@ class SwarmAttachButton extends StatelessWidget {Widget build(BuildContext context) => SwarmRoundButton(label: 'Attach files',onTap: onTap,+ face: 36,+ fill: Tty.of(context).text.withValues(alpha: 0.08),child: Icon(LucideIcons.plus,- size: AppIconSize.standalone,+ size: 22,color: onTap == null ? AppPalette.textFaint : AppPalette.textSecondary,),);}+/// The chat composer's @ Tag chip ([SwarmConversation.toggleMention]): ends+/// the draft in an @, which opens the picker, or closes it again while no+/// name is typed. In the accent while the picker is open.+class _TagChip extends StatelessWidget {+ const _TagChip({required this.open, required this.onTap});++ final bool open;+ final VoidCallback onTap;++ @override+ Widget build(BuildContext context) {+ final tty = Tty.of(context);+ final ink = open ? AppPalette.accentOnSurface : AppPalette.textSecondary;+ return Semantics(+ button: true,+ label: 'Tag a member or agent',+ excludeSemantics: true,+ onTap: onTap,+ child: GestureDetector(+ key: const ValueKey('swarm-tag'),+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: SizedBox(+ height: 44,+ child: Center(+ child: Container(+ height: 36,+ padding: SwarmComposer.tagPadding,+ decoration: BoxDecoration(+ color: open+ ? AppPalette.accentOnSurface.withValues(alpha: 0.16)+ : tty.text.withValues(alpha: 0.08),+ borderRadius: BorderRadius.circular(SwarmComposer.tagRadius),+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(LucideIcons.atSign, size: 17, color: ink),+ const SizedBox(width: 5),+ Text(+ 'Tag',+ style: swarmChatText(+ 14,+ color: ink,+ weight: FontWeight.w500,+ height: 1.2,+ ),+ ),+ ],+ ),+ ),+ ),+ ),+ ),+ );+ }+}+/// A link in the accent: Earlier messages.class _Link extends StatelessWidget {const _Link({super.key, required this.label, required this.onTap});diff --git a/mobile/lib/swarm/swarm_new_message_sheet.dart b/mobile/lib/swarm/swarm_new_message_sheet.dartindex 4b6dd7256..5ff702b53 100644--- a/mobile/lib/swarm/swarm_new_message_sheet.dart+++ b/mobile/lib/swarm/swarm_new_message_sheet.dart@@ -1,4 +1,5 @@import 'dart:async';+import 'dart:math' as math;import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';@@ -12,6 +13,7 @@ import 'package:harness_mobile/shared/theme/app_icon_size.dart';import 'package:harness_mobile/shared/theme/app_ink.dart';import 'package:harness_mobile/shared/theme/app_space.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/theme/swarm_tokens_set_b.dart';import 'package:harness_mobile/shared/theme/app_type.dart';import 'package:harness_mobile/shared/widgets/touch_target.dart';import 'package:harness_mobile/theme/app_theme.dart' show AppColors;@@ -23,6 +25,7 @@ import 'swarm_conversation.dart';import 'swarm_conversation_page.dart'showSwarmAttachButton,+ SwarmComposerCard,SwarmMessageField,SwarmRoundButton,attachSwarmFiles;@@ -215,6 +218,10 @@ class SwarmNewMessageSheet extends StatefulWidget {State<SwarmNewMessageSheet> createState() => _SwarmNewMessageSheetState();}+/// What the list keeps under the composer at the least: one 44pt row and its+/// padding, so ✕ stays a scroll away with the keyboard up.+const double _listRoom = 44 + AppSpace.m;+class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>implements SwarmFilesBox {final _query = TextEditingController();@@ -290,7 +297,6 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>selection: TextSelection.collapsed(offset: text.length),);},- send: _spoken,)..addListener(_redraw);}}@@ -419,14 +425,6 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>_focus.requestFocus();}- /// The second tap on the mic ended a take: what is in the box goes, as- /// Send would send it.- void _spoken() {- if (_visible && _text.text.trim().isNotEmpty && _canSend) {- unawaited(_send());- }- }-/// +'s sheet and picker ([attachSwarmFiles]), their files into [files].Future<void> _attach() async {if (_picking || _locked) return;@@ -521,33 +519,44 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom,),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- // ✕, To: and the chats scroll as one, and only the composer is- // pinned: on a small phone with the keyboard up, a long draft,- // a reason or files still leave Send above the keys.- Expanded(- child: ListView(- key: const ValueKey('swarm-new-message-list'),- keyboardDismissBehavior:- ScrollViewKeyboardDismissBehavior.onDrag,- padding: const EdgeInsets.only(bottom: AppSpace.m),- children: [- _header(),- _to(),- Padding(- padding: const EdgeInsets.symmetric(horizontal: AppSpace.m),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: _rows(list, several: shown.length > 1),+ child: LayoutBuilder(+ builder: (context, below) => Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ // ✕, To: and the chats scroll as one, and only the composer is+ // pinned: on a small phone with the keyboard up, a long draft,+ // a reason or files still leave Send above the keys.+ Expanded(+ child: ListView(+ key: const ValueKey('swarm-new-message-list'),+ keyboardDismissBehavior:+ ScrollViewKeyboardDismissBehavior.onDrag,+ padding: const EdgeInsets.only(bottom: AppSpace.m),+ children: [+ _header(),+ _to(),+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: AppSpace.m,+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: _rows(list, several: shown.length > 1),+ ),),- ),- ],+ ],+ ),),- ),- SafeArea(top: false, child: _composer(tty, picked)),- ],+ // At most what leaves the list one row, so ✕ stays a scroll+ // away: past that the field gives up lines.+ ConstrainedBox(+ constraints: BoxConstraints(+ maxHeight: math.max(0, below.maxHeight - _listRoom),+ ),+ child: SafeArea(top: false, child: _composer(tty, picked)),+ ),+ ],+ ),),),);@@ -692,10 +701,15 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>}/// Why the last Send did not go, what the last pick left out, what the mic- /// could not hear, the files going, then +, the field, the mic and Send.+ /// could not hear, then the card ([SwarmComposerCard]): the files going,+ /// the field and its X, then +, the mic and Send — or, while a take is+ /// under way, the voice row ([SwarmVoiceRow]). No Tag: New message has no+ /// @ picker.Widget _composer(Tty tty, SwarmNewMessageChat? picked) {final canSend = _canSend;final locked = _locked;+ final voice = _voice;+ final talking = voice?.face != null;Widget note(String text, String key, Color color) => Padding(padding: const EdgeInsets.fromLTRB(AppSpace.xs,@@ -709,16 +723,10 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>style: AppType.caption(color: color),),);- return Container(- decoration: BoxDecoration(- color: Color.alphaBlend(tty.text.withValues(alpha: 0.02), tty.ground),- border: Border(top: BorderSide(color: AppGlass.hair)),- ),- padding: const EdgeInsets.symmetric(- horizontal: AppSpace.m,- vertical: AppSpace.s,- ),+ return Padding(+ padding: SwarmComposer.padding,child: Column(+ mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.stretch,children: [if (_error case final error?)@@ -733,62 +741,74 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>'swarm-new-message-voice-stopped',AppPalette.textSecondary,),- SwarmOutgoingChips(box: this),- Row(- crossAxisAlignment: CrossAxisAlignment.end,- children: [- if (swarmSendsFiles)- SwarmAttachButton(- key: const ValueKey('swarm-new-message-attach'),- onTap: locked || files.room <= 0- ? null- : () => unawaited(_attach()),- ),- const SizedBox(width: AppSpace.xs),- Expanded(- child: IgnorePointer(- ignoring: locked,- child: SwarmMessageField(- controller: _text,- focus: _focus,- hint: picked == null- ? 'Write a message…'- : 'Message ${picked.title}',- fieldKey: const ValueKey('swarm-new-message-field'),- imagePaste: swarmSendsFiles- ? SwarmImagePaste(- enabled: !locked && files.room > 0,- onImage: (image) => unawaited(_pasteImage(image)),- )- : null,- ),+ Flexible(+ child: SwarmComposerCard(+ focus: _focus,+ fit: true,+ chips: files.files.isEmpty ? null : SwarmOutgoingChips(box: this),+ // While locked the field and its X take no touch.+ field: IgnorePointer(+ ignoring: locked,+ child: SwarmMessageField(+ controller: _text,+ focus: _focus,+ hint: picked == null+ ? 'Write a message…'+ : 'Message ${picked.title}',+ fieldKey: const ValueKey('swarm-new-message-field'),+ clearKey: const ValueKey('swarm-new-message-clear'),+ clearable: !talking,+ imagePaste: swarmSendsFiles+ ? SwarmImagePaste(+ enabled: !locked && files.room > 0,+ onImage: (image) => unawaited(_pasteImage(image)),+ )+ : null,),),- if (_voice case final voice?)- SwarmVoiceMic(voice: voice)- else- const SizedBox(width: AppSpace.xs),- SwarmRoundButton(- key: const ValueKey('swarm-new-message-send'),- label: 'Send',- fill: canSend || _sending ? AppPalette.accent : ttyRaised(tty),- onTap: canSend ? () => unawaited(_send()) : null,- child: _sending- ? SizedBox.square(- dimension: AppIconSize.besideText,- child: CircularProgressIndicator(- key: const ValueKey('swarm-new-message-sending'),- strokeWidth: 2,- color: AppInk.onFill,+ toolbar: talking+ ? SwarmVoiceRow(voice: voice!)+ : Row(+ children: [+ if (swarmSendsFiles)+ SwarmAttachButton(+ key: const ValueKey('swarm-new-message-attach'),+ onTap: locked || files.room <= 0+ ? null+ : () => unawaited(_attach()),+ ),+ const Spacer(),+ if (voice != null) SwarmVoiceMic(voice: voice),+ SwarmRoundButton(+ key: const ValueKey('swarm-new-message-send'),+ label: 'Send',+ face: 36,+ fill: canSend || _sending+ ? AppPalette.accent+ : ttyRaised(tty),+ onTap: canSend ? () => unawaited(_send()) : null,+ child: _sending+ ? SizedBox.square(+ dimension: AppIconSize.besideText,+ child: CircularProgressIndicator(+ key: const ValueKey(+ 'swarm-new-message-sending',+ ),+ strokeWidth: 2,+ color: AppInk.onFill,+ ),+ )+ : Icon(+ LucideIcons.arrowUp,+ size: 20,+ color: canSend+ ? AppInk.onFill+ : AppPalette.textFaint,+ ),),- )- : Icon(- LucideIcons.arrowUp,- size: AppIconSize.besideText,- color: canSend ? AppInk.onFill : AppPalette.textFaint,- ),- ),- ],+ ],+ ),+ ),),],),diff --git a/mobile/lib/swarm/swarm_thread_page.dart b/mobile/lib/swarm/swarm_thread_page.dartindex ac75dee0c..008769566 100644--- a/mobile/lib/swarm/swarm_thread_page.dart+++ b/mobile/lib/swarm/swarm_thread_page.dart@@ -8,6 +8,7 @@ import 'package:harness_mobile/phone/tty_controls.dart';import 'package:harness_mobile/shared/theme/app_ink.dart';import 'package:harness_mobile/shared/theme/app_space.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/theme/swarm_tokens_set_b.dart';import 'package:harness_mobile/shared/theme/app_type.dart';import 'model.dart';@@ -162,7 +163,6 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {write: (text) {if (_mayReply) _thread.draft = text;},- send: _spoken,);}}@@ -211,17 +211,6 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {);}- /// The second tap on the mic ended a take: what is in the box goes as a- /// reply, as Send would send it, to the chat too with Also send. Nothing- /// when the box is empty, the thread is covered or no longer the person's- /// to reply in, or a reply or files are already on their way.- void _spoken() {- final t = _thread;- if (!mounted || !_visible || !_mayReply) return;- if (t.draft.trim().isEmpty || !t.canSend) return;- unawaited(_send());- }-/// The box's + ([attachSwarmFiles]), its files into the thread's.Future<void> _pickFiles() async {if (_picking) return;@@ -548,25 +537,22 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {);}- /// The reply box: the files going with the reply, a field that grows with- /// what is typed, then Also send, the +, the mic and a round Send (the- /// desktop's thread composer, with the main chat's mic).+ /// The reply box: notes, then the card ([SwarmComposerCard]) — the files+ /// going with the reply, a field that grows with what is typed and its X,+ /// then +, Also send, the mic and a round Send (the desktop's thread+ /// composer, with the main chat's mic). While a take is under way the+ /// toolbar is the voice row ([SwarmVoiceRow]): Also send is hidden, and+ /// keeps its tick for the Send after the take. No Tag: a thread has no @+ /// picker.Widget _box(SwarmThread t, Tty tty) {// A reply on its way never holds the box: the next is typed meanwhile.final canSend = t.canSend;final canAttach = !t.uploading && t.files.room > 0;- return Container(+ final voice = _voice;+ final talking = voice?.face != null;+ return Padding(key: const ValueKey('swarm-thread-box'),- decoration: BoxDecoration(- color: Color.alphaBlend(tty.text.withValues(alpha: 0.02), tty.ground),- border: Border(top: BorderSide(color: swarmChatHair(tty))),- ),- padding: const EdgeInsets.fromLTRB(- AppSpace.m,- AppSpace.s,- AppSpace.m,- AppSpace.xs,- ),+ padding: SwarmComposer.padding,child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [@@ -617,47 +603,57 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {style: AppType.caption(color: AppPalette.textSecondary),),),- SwarmOutgoingChips(box: t),- SwarmMessageField(- controller: _text,+ SwarmComposerCard(focus: _focus,- hint: 'Reply',- fieldKey: const ValueKey('swarm-thread-field'),- imagePaste: swarmSendsFiles- ? SwarmImagePaste(- enabled: canAttach,- onImage: (image) => unawaited(_pasteImage(image)),- )- : null,- ),- Row(- children: [- Expanded(- child: _AlsoSend(- label: t.alsoSendLabel,- value: t.alsoSend,- onChanged: (on) => t.alsoSend = on,- ),- ),- if (swarmSendsFiles)- SwarmAttachButton(- key: const ValueKey('swarm-thread-attach'),- onTap: canAttach ? () => unawaited(_pickFiles()) : null,- ),- // The main chat's mic, beside Send as there.- if (_voice case final voice?) SwarmVoiceMic(voice: voice),- SwarmRoundButton(- key: const ValueKey('swarm-thread-send'),- label: 'Send reply',- fill: canSend ? AppPalette.accent : ttyRaised(tty),- onTap: canSend ? () => unawaited(_send()) : null,- child: Icon(- LucideIcons.arrowUp,- size: 20,- color: canSend ? AppInk.onFill : AppPalette.textFaint,- ),- ),- ],+ chips: t.files.files.isEmpty ? null : SwarmOutgoingChips(box: t),+ field: SwarmMessageField(+ controller: _text,+ focus: _focus,+ hint: 'Reply',+ fieldKey: const ValueKey('swarm-thread-field'),+ clearKey: const ValueKey('swarm-thread-clear'),+ clearable: !talking,+ imagePaste: swarmSendsFiles+ ? SwarmImagePaste(+ enabled: canAttach,+ onImage: (image) => unawaited(_pasteImage(image)),+ )+ : null,+ ),+ toolbar: talking+ ? SwarmVoiceRow(voice: voice!)+ : Row(+ children: [+ if (swarmSendsFiles)+ SwarmAttachButton(+ key: const ValueKey('swarm-thread-attach'),+ onTap: canAttach+ ? () => unawaited(_pickFiles())+ : null,+ ),+ Expanded(+ child: _AlsoSend(+ label: t.alsoSendLabel,+ value: t.alsoSend,+ onChanged: (on) => t.alsoSend = on,+ ),+ ),+ // The main chat's mic, beside Send as there.+ if (voice != null) SwarmVoiceMic(voice: voice),+ SwarmRoundButton(+ key: const ValueKey('swarm-thread-send'),+ label: 'Send reply',+ face: 36,+ fill: canSend ? AppPalette.accent : ttyRaised(tty),+ onTap: canSend ? () => unawaited(_send()) : null,+ child: Icon(+ LucideIcons.arrowUp,+ size: 20,+ color: canSend ? AppInk.onFill : AppPalette.textFaint,+ ),+ ),+ ],+ ),),],),diff --git a/mobile/lib/swarm/swarm_voice.dart b/mobile/lib/swarm/swarm_voice.dartindex 78e74049b..1cc66463a 100644--- a/mobile/lib/swarm/swarm_voice.dart+++ b/mobile/lib/swarm/swarm_voice.dart@@ -1,25 +1,31 @@import 'dart:async';+import 'dart:math' as math;import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';+import 'package:flutter/scheduler.dart';import 'package:flutter/services.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';+import 'package:harness_mobile/phone/tty.dart';import 'package:harness_mobile/phone/voice_input_controller.dart';import 'package:harness_mobile/phone/voice_language_store.dart';import 'package:harness_mobile/phone/voice_mic_face.dart';import 'package:harness_mobile/phone/voice_notice.dart';-import 'package:harness_mobile/shared/theme/app_icon_size.dart';+import 'package:harness_mobile/shared/theme/app_space.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/theme/swarm_tokens_set_b.dart';import 'swarm_dictation.dart';/// Talking instead of typing in a chat, into the message box (Tony, 10-28:-/// "like the Claude app"). Tap to talk; tap again and what is in the box is-/// sent ([send]) — what the person typed or changed meanwhile included. Only-/// that tap ends a take (10-29: "until I tap"): no pause does — save [idle]-/// without a new word, which stops listening with the words left in the box.-/// A long press picks the language ([voiceLanguageStore]).+/// "like the Claude app"). Tap the mic to talk. While talking the composer+/// shows [SwarmVoiceRow]: [stop] ends the take with its words left in the box,+/// [cancel] throws away what the take added. Voice never sends by itself+/// (Tony, 11-01): sending is a tap on Send. No pause ends a take (10-29:+/// "until I tap") — save [idle] without a new word, which stops listening+/// with the words left in the box. A long press on the mic picks the language+/// ([voiceLanguageStore]).////// Two ways to hear, the first wherever it can:///@@ -27,8 +33,9 @@ import 'swarm_dictation.dart';/// dictation uses: the words show in the box as they are said. Asked for/// once, with the microphone./// - **The terminal's voice input** ([VoiceInputController]): the take is-/// recorded and the backend transcribes it as it ends — at the tap, or at-/// [VoiceInputController.maxTake] with its words left in the box, unsent.+/// recorded and the backend transcribes it as it ends — at [stop], or at+/// [VoiceInputController.maxTake] — its words left in the box, unsent.+/// They reach the box only once transcribed, after the take: no live words./// Where there is no recognizer (Android, sample mode), speech recognition/// was refused, or the recognizer has no such language.///@@ -44,7 +51,6 @@ class SwarmVoice extends ChangeNotifier {this.dictation,required this.draft,required this.write,- required this.send,});/// How long the recognizer listens without hearing a new word before it@@ -59,8 +65,8 @@ class SwarmVoice extends ChangeNotifier {static const stoppedListening = 'Stopped listening';static const stoppedLinger = Duration(seconds: 3);- /// How long the recognizer has to say it has stopped, after a tap asked it- /// to, before its take is given up and what the box holds is sent.+ /// How long the recognizer has to say it has stopped, after [stop] asked it+ /// to, before its take is given up with what the box holds left there.static const _endWait = Duration(seconds: 2);/// Makes the voice input, which this owns and disposes.@@ -73,11 +79,8 @@ class SwarmVoice extends ChangeNotifier {final String Function() draft;final void Function(String text) write;- /// Sends the draft: the second tap ended a take.- final void Function() send;-/// The recognizer's take: asking for it, listening, or waiting for it to- /// say it has stopped — as only the second tap asks, to send the draft.+ /// say it has stopped — as only [stop] asks._Live _live = _Live.off;/// Bumped by everything that ends a recognizer's take, so what an earlier@@ -155,9 +158,9 @@ class SwarmVoice extends ChangeNotifier {ValueListenable<double>? get level =>_live == _Live.off ? _voice?.level : _liveLevel;- /// Starts a take; ends it and sends the box, calls it off while the- /// microphone opens or its permission is asked, or does nothing while its- /// words are on their way.+ /// Starts a take, or calls it off while the microphone opens or its+ /// permission is asked. While listening it is [stop]; while the words are+ /// on their way it does nothing.void tap() {if (_disposed) return;switch (_live) {@@ -196,12 +199,39 @@ class SwarmVoice extends ChangeNotifier {case VoiceInputStatus.starting:unawaited(voice.stopListening());case VoiceInputStatus.listening:- _finish(voice, send: true);+ _finish(voice);case VoiceInputStatus.transcribing:break;}}+ /// Ends the take with its words left in the box. Nothing is sent.+ void stop() {+ if (_disposed) return;+ if (_live == _Live.listening) {+ _endLive();+ return;+ }+ final voice = _voice;+ if (voice != null && voice.status == VoiceInputStatus.listening) {+ _finish(voice);+ }+ }++ /// Throws the take away: what it added leaves the box, the person's edits+ /// stay. A recorded take is dropped with its words, even while they are+ /// being transcribed ([VoiceInputController.clear]).+ void cancel() {+ if (_disposed) return;+ if (_live != _Live.off) {+ if (_live != _Live.asking && draft() == _liveShown) write(_liveFrom);+ _offLive();+ return;+ }+ final voice = _voice;+ if (voice != null && !voice.isIdle) voice.clear();+ }+/// Throws away the take under way — opening, recording or being/// transcribed — with its words: the chat went out of sight. What it was/// waiting on lands nowhere ([VoiceInputController.clear]), and the next@@ -325,8 +355,8 @@ class SwarmVoice extends ChangeNotifier {return same;}- /// The second tap: asks the recognizer to stop — its last words, then its- /// end ([_liveEnded]), which sends the draft.+ /// [stop]: asks the recognizer to stop — its last words, then its end+ /// ([_liveEnded]), with the words left in the box.void _endLive() {final dictation = this.dictation;if (_live != _Live.listening || dictation == null) return;@@ -342,25 +372,23 @@ class SwarmVoice extends ChangeNotifier {unawaited(dictation.stop());}- /// The recognizer has stopped: as the second tap asked — and then what the- /// box holds is sent, however its last session ended (Tony, 10-29) — or- /// because it cannot go on, its words left in the box. A notice only when- /// nothing goes.+ /// The recognizer has stopped, as [stop] asked or because it cannot go on:+ /// its words stay in the box and nothing is sent. No notice after a stop+ /// with words in the box, however the recognizer's last session ended.void _liveEnded(int take, SwarmDictationEnd end) {if (take != _liveTake || _live == _Live.off) return;- final send = _live == _Live.ending && draft().trim().isNotEmpty;+ final stopped = _live == _Live.ending && draft().trim().isNotEmpty;_liveTake++;_live = _Live.off;_stopLiveTimers();_liveLevel.value = 0;_setLiveNotice(switch (end) {- _ when send => null,+ _ when stopped => null,SwarmDictationEnd.failed => VoiceNotice.notTranscribed,_ when _liveHeard.isEmpty => VoiceNotice.nothingHeard,_ => null,});notifyListeners();- if (send && !_disposed) this.send();}/// Calls off the recognizer's take, whatever it is doing: the words already@@ -464,21 +492,14 @@ class SwarmVoice extends ChangeNotifier {held?.complete(go);}- /// Ends the take, its words into the draft, and with [send] sends the draft- /// once they are there. A take that fails keeps the draft as it was, sends- /// nothing and leaves its [notice].- void _finish(VoiceInputController voice, {bool send = false}) {- var heard = false;+ /// Ends the take, its words into the draft. A take that fails keeps the+ /// draft as it was and leaves its [notice]. Nothing is sent.+ void _finish(VoiceInputController voice) {unawaited(- voice- .submit((words) async {- write(_joined(draft(), words));- heard = true;- return true;- })- .then((_) {- if (heard && send && !_disposed) this.send();- }),+ voice.submit((words) async {+ write(_joined(draft(), words));+ return true;+ }),);}@@ -505,22 +526,18 @@ class SwarmVoice extends ChangeNotifier {}}-/// The composer's mic, a 44pt round like its other buttons: a plain mic at-/// rest, and the terminal's face ([VoiceMicCore]) while a take is under way —-/// opening, listening with its bars moving to the voice, transcribing. A long-/// press picks the language, from the terminal's list.+/// The composer's mic: a 36pt circle in a 44pt target, like the card's other+/// round buttons. A tap starts a take; a long press picks the language, from+/// the terminal's list. While a take is under way the composer shows+/// [SwarmVoiceRow] in its place, so the mic draws no live face of its own.class SwarmVoiceMic extends StatelessWidget {const SwarmVoiceMic({super.key, required this.voice});final SwarmVoice voice;- /// How wide the terminal's face is drawn here: inside the 44pt round, as- /// the filled Send beside it is.- static const double _face = 36;-@overrideWidget build(BuildContext context) {- final face = voice.face;+ final tty = Tty.of(context);final off = voice.off;void talk() {HapticFeedback.lightImpact();@@ -535,15 +552,7 @@ class SwarmVoiceMic extends StatelessWidget {enabled: true,onTap: talk,onLongPress: chooseLanguage,- // One word while the mic is open: VoiceOver reads the label aloud, and- // a sentence read into an open microphone lands in the take.- label: switch (face) {- VoiceMicFace.starting => 'Cancel',- VoiceMicFace.listening => 'Done',- null when off => 'Voice input is off',- null => 'Talk',- _ => 'Working',- },+ label: off ? 'Voice input is off' : 'Talk',onLongPressHint: 'Choose language',excludeSemantics: true,child: GestureDetector(@@ -551,33 +560,327 @@ class SwarmVoiceMic extends StatelessWidget {behavior: HitTestBehavior.opaque,onTap: talk,onLongPress: chooseLanguage,- child: SizedBox.square(- dimension: 44,- child: Center(- child: face == null- ? Icon(- off ? LucideIcons.micOff : LucideIcons.mic,- size: AppIconSize.standalone,- color: off- ? AppPalette.textFaint- : AppPalette.textSecondary,- )- : SizedBox.square(- dimension: _face,- child: FittedBox(- child: VoiceMicCore(- face: face,- dead: false,- level: voice.level,- ),- ),+ child: _VoiceRound(+ fill: tty.text.withValues(alpha: 0.08),+ child: Icon(+ off ? LucideIcons.micOff : LucideIcons.mic,+ size: 22,+ color: off ? AppPalette.textFaint : AppPalette.textSecondary,+ ),+ ),+ ),+ );+ }+}++/// The card's toolbar while a take is under way (Tony, 11-01): cancel, the+/// wave, stop — no +, Tag, mic or Send, so nothing is sent from here.+///+/// - Opening ([VoiceMicFace.starting]): cancel and a flat wave.+/// - Listening: cancel, the wave following [SwarmVoice.level], and stop.+/// - Busy (the recognizer stopping, or the recording being transcribed):+/// cancel and the terminal's busy face where stop was.+///+/// Cancel and Stop are one word each: VoiceOver reads a label aloud, and a+/// sentence read into an open microphone lands in the take.+class SwarmVoiceRow extends StatelessWidget {+ const SwarmVoiceRow({super.key, required this.voice});++ final SwarmVoice voice;++ @override+ Widget build(BuildContext context) {+ final tty = Tty.of(context);+ final face = voice.face;+ final fill = tty.text.withValues(alpha: 0.08);+ return Row(+ children: [+ _VoiceButton(+ key: const ValueKey('swarm-voice-cancel'),+ label: 'Cancel',+ onTap: voice.cancel,+ child: _VoiceRound(+ fill: fill,+ child: Icon(+ LucideIcons.x,+ size: 20,+ color: AppPalette.textSecondary,+ ),+ ),+ ),+ const SizedBox(width: AppSpace.xs),+ Expanded(+ child: SwarmVoiceWave(+ key: const ValueKey('swarm-voice-wave'),+ level: face == VoiceMicFace.listening ? voice.level : null,+ flat: face != VoiceMicFace.listening,+ ),+ ),+ const SizedBox(width: AppSpace.xs),+ switch (face) {+ VoiceMicFace.listening => _VoiceButton(+ key: const ValueKey('swarm-voice-stop'),+ label: 'Stop',+ onTap: voice.stop,+ child: _VoiceRound(+ fill: fill,+ child: Container(+ width: 14,+ height: 14,+ decoration: BoxDecoration(+ color: AppPalette.textPrimary,+ borderRadius: BorderRadius.circular(SwarmComposer.stopRadius),+ ),+ ),+ ),+ ),+ VoiceMicFace.starting || null => const SizedBox(width: 44),+ final face => Semantics(+ key: const ValueKey('swarm-voice-busy'),+ label: 'Working',+ excludeSemantics: true,+ child: SizedBox.square(+ dimension: 44,+ child: Center(+ child: SizedBox.square(+ dimension: 36,+ child: FittedBox(+ child: VoiceMicCore(face: face, dead: false),),+ ),+ ),+ ),+ ),+ },+ ],+ );+ }+}++/// A 44pt target with [child] on a 36pt circle of [fill].+class _VoiceRound extends StatelessWidget {+ const _VoiceRound({required this.fill, required this.child});++ final Color fill;+ final Widget child;++ @override+ Widget build(BuildContext context) => SizedBox.square(+ dimension: 44,+ child: Center(+ child: SizedBox.square(+ dimension: 36,+ child: DecoratedBox(+ decoration: BoxDecoration(color: fill, shape: BoxShape.circle),+ child: Center(child: child),+ ),+ ),+ ),+ );+}++/// One of [SwarmVoiceRow]'s buttons, with a light tap felt.+class _VoiceButton extends StatelessWidget {+ const _VoiceButton({+ super.key,+ required this.label,+ required this.onTap,+ required this.child,+ });++ final String label;+ final VoidCallback onTap;+ final Widget child;++ @override+ Widget build(BuildContext context) {+ void tap() {+ HapticFeedback.lightImpact();+ onTap();+ }++ return Semantics(+ button: true,+ enabled: true,+ label: label,+ onTap: tap,+ excludeSemantics: true,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: tap,+ child: child,+ ),+ );+ }+}++/// The voice row's wave: a history of the microphone's [level] scrolling in+/// from the right, one bar 2 wide every 2, 3 to 24 tall. A breath of motion+/// even in silence, so a listening take never looks frozen; [flat] draws the+/// bars at rest while the microphone opens or the words are on their way.+///+/// Painted, not built: the history moves in a [CustomPainter] behind a+/// [RepaintBoundary], so the composer around it is not rebuilt at every+/// frame. Under Reduce Motion nothing scrolls: the bars hold one shape that+/// rises and falls with the level alone.+class SwarmVoiceWave extends StatefulWidget {+ const SwarmVoiceWave({super.key, required this.level, this.flat = false});++ final ValueListenable<double>? level;+ final bool flat;++ static const double bar = 2;+ static const double gap = 2;+ static const double low = 3;+ static const double high = 24;++ /// How often a new bar comes in on the right.+ static const Duration step = Duration(milliseconds: 70);++ /// The most bars kept: enough for any phone's width.+ static const int _keep = 160;++ @override+ State<SwarmVoiceWave> createState() => _SwarmVoiceWaveState();+}++class _SwarmVoiceWaveState extends State<SwarmVoiceWave>+ with SingleTickerProviderStateMixin {+ late final Ticker _ticker = createTicker(_tick);++ /// Each bar's height, 0 to 1, oldest first.+ final List<double> _history = [];++ /// Bumped as the history moves: what repaints the painter.+ final ValueNotifier<int> _moved = ValueNotifier(0);+ Duration _last = Duration.zero;+ double _shown = 0;+ bool _motion = true;++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();+ _motion = !MediaQuery.disableAnimationsOf(context);+ _sync();+ }++ @override+ void didUpdateWidget(SwarmVoiceWave old) {+ super.didUpdateWidget(old);+ if (widget.flat && !old.flat) {+ _history.clear();+ _moved.value++;+ }+ _sync();+ }++ void _sync() {+ final run = _motion && !widget.flat;+ if (run && !_ticker.isActive) {+ _last = Duration.zero;+ unawaited(_ticker.start());+ } else if (!run && _ticker.isActive) {+ _ticker.stop();+ }+ }++ void _tick(Duration elapsed) {+ if (elapsed - _last < SwarmVoiceWave.step) return;+ _last = elapsed;+ final target = (widget.level?.value ?? 0).clamp(0.0, 1.0);+ _shown += (target - _shown) * 0.6;+ // A breath in silence: never a flat, frozen line while listening.+ final breath = 0.06 + 0.05 * math.sin(elapsed.inMilliseconds / 180.0).abs();+ _history.add(math.max(_shown, breath).clamp(0.0, 1.0));+ if (_history.length > SwarmVoiceWave._keep) _history.removeAt(0);+ _moved.value++;+ }++ @override+ void dispose() {+ _ticker.dispose();+ _moved.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final level = widget.level;+ return RepaintBoundary(+ child: SizedBox(+ height: 44,+ child: CustomPaint(+ painter: _WavePainter(+ history: _history,+ moved: _moved,+ color: AppPalette.textPrimary,+ flat: widget.flat,+ still: !_motion && level != null ? level : null,),+ size: Size.infinite,),),);}}+class _WavePainter extends CustomPainter {+ _WavePainter({+ required this.history,+ required this.moved,+ required this.color,+ required this.flat,+ required this.still,+ }) : super(repaint: still == null ? moved : Listenable.merge([moved, still]));++ final List<double> history;+ final Listenable moved;+ final Color color;+ final bool flat;++ /// Under Reduce Motion: the level the one still shape follows.+ final ValueListenable<double>? still;++ @override+ void paint(Canvas canvas, Size size) {+ const pitch = SwarmVoiceWave.bar + SwarmVoiceWave.gap;+ final count = (size.width / pitch).floor();+ if (count <= 0) return;+ final paint = Paint()..color = color;+ final mid = size.height / 2;+ double heightOf(int i) {+ if (flat) return 0;+ if (still case final still?) {+ // One shape, taller toward the middle, scaled by the level.+ final shape = 0.35 + 0.65 * math.sin(math.pi * (i + 0.5) / count);+ return (0.08 + 0.92 * still.value.clamp(0.0, 1.0)) * shape;+ }+ // Newest on the right.+ final back = count - 1 - i;+ final at = history.length - 1 - back;+ return at < 0 ? 0 : history[at];+ }++ for (var i = 0; i < count; i++) {+ final amount = heightOf(i);+ final h =+ SwarmVoiceWave.low ++ (SwarmVoiceWave.high - SwarmVoiceWave.low) * amount;+ final x = size.width - (count - i) * pitch + SwarmVoiceWave.gap;+ canvas.drawRRect(+ RRect.fromRectAndRadius(+ Rect.fromLTWH(x, mid - h / 2, SwarmVoiceWave.bar, h),+ const Radius.circular(SwarmVoiceWave.bar / 2),+ ),+ paint,+ );+ }+ }++ @override+ bool shouldRepaint(_WavePainter old) =>+ old.flat != flat || old.color != color || old.still != still;+}+/// Where [SwarmVoice]'s take with the phone's recognizer is.enum _Live { off, asking, listening, ending }diff --git a/mobile/test/render/swarm_composer_render_test.dart b/mobile/test/render/swarm_composer_render_test.dartnew file mode 100644index 000000000..87a138fac--- /dev/null+++ b/mobile/test/render/swarm_composer_render_test.dart@@ -0,0 +1,331 @@+import 'dart:async';+import 'dart:io';+import 'dart:ui' as ui;++import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/phone/voice_input_controller.dart';+import 'package:harness_mobile/phone/voice_recorder.dart';+import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;+import 'package:harness_mobile/shared/theme/color_palette.dart';+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_file_picker.dart';+import 'package:harness_mobile/swarm/swarm_outgoing_files.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:image_picker/image_picker.dart' show XFile;++import '../voice_fakes.dart';+import '../swarm/swarm_fixture.dart';++/// Renders a phone Swarm chat's composer in the states Tony's composer brief+/// (11-01) names — empty, text, five lines, the @ picker open, a reply, files+/// and listening — in light and dark, on a 393 x 852 iPhone with the keyboard+/// up (336 tall), in the system fonts, to PNGs a reviewer can compare.+///+/// Only keys the composer has had since before the card are used, so the same+/// file draws the old composer too.+///+/// Skipped unless PHONE_RENDER_DIR names a directory to write into:+///+/// PHONE_RENDER_DIR=/tmp/renders flutter test test/render/swarm_composer_render_test.dart+///+/// macOS only: it loads SF Pro and SF Mono from /System/Library/Fonts.+final _outDir = Platform.environment['PHONE_RENDER_DIR'];++Future<void> _loadFonts() async {+ Future<void> load(String family, String path) async {+ final bytes = await File(path).readAsBytes();+ await (FontLoader(+ family,+ )..addFont(Future.value(ByteData.view(bytes.buffer)))).load();+ }++ for (final family in ['.AppleSystemUIFont', 'SF Pro Text', 'Roboto']) {+ await load(family, '/System/Library/Fonts/SFNS.ttf');+ }+ for (final family in ['.AppleSystemUIFontMonospaced', 'SF Mono']) {+ await load(family, '/System/Library/Fonts/SFNSMono.ttf');+ }+ final lucide =+ '${Platform.environment['HOME']}/.pub-cache/hosted/pub.dev/lucide_icons_flutter-3.1.19/assets';+ await load('packages/lucide_icons_flutter/Lucide', '$lucide/lucide.ttf');+ for (final weight in [100, 200, 300, 400, 500, 600]) {+ await load(+ 'packages/lucide_icons_flutter/Lucide$weight',+ '$lucide/build_font/LucideVariable-w$weight.ttf',+ );+ }+}++/// A photo-like picture: a sky over a field, encoded as PNG.+Future<Uint8List> _photo(Color sky, Color ground) async {+ final recorder = ui.PictureRecorder();+ final canvas = Canvas(recorder);+ canvas.drawRect(const Rect.fromLTWH(0, 0, 120, 80), Paint()..color = sky);+ canvas.drawRect(const Rect.fromLTWH(0, 50, 120, 30), Paint()..color = ground);+ final image = await recorder.endRecording().toImage(120, 80);+ final png = await image.toByteData(format: ui.ImageByteFormat.png);+ return png!.buffer.asUint8List();+}++void main() {+ final skip = _outDir == null;+ const messages = '/api/super-tabs/$tab/conversations/g1/messages';+ const sample = 'Check whether PR #2466 has merged yet';++ final original = (photos: pickSwarmPhotos, copies: swarmPickerCopyFolders);+ setUp(() => swarmPickerCopyFolders = () async => const []);+ tearDown(() {+ swarmPickerCopyFolders = original.copies;+ pickSwarmPhotos = original.photos;+ });++ FakeSwarm backend() {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {+ ...firstLoad(+ groups: [+ groupData(+ 'g1',+ title: 'Login crash on iPhone',+ agentIds: ['agent-lead', 'agent-builder'],+ status: 'working',+ lastMessageSequence: 1,+ ),+ ],+ ),+ 'members': [part(me, 1, person(me))],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes[messages] = (_) => {+ 'messages': [+ {+ 'id': 'm1',+ 'conversationId': 'g1',+ 'text': 'The fix is ready. Ship it to TestFlight today?',+ 'sequence': 1,+ 'author': {'kind': 'agent', 'id': 'agent-lead', 'name': 'River'},+ 'attachments': <Object>[],+ 'reactions': <Object>[],+ 'createdAt': DateTime.utc(2026, 11, 1, 4, 1).toIso8601String(),+ },+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/commands'] = (_) =>+ Completer<Object?>().future;+ return fake;+ }++ /// Uploads held where they are, a fixed part of the way up.+ Future<Map<String, dynamic>> stuck({+ required String tabId,+ required String conversationId,+ required String name,+ required String mime,+ required SwarmOutgoingFile file,+ required dynamic cancel,+ required void Function(double sent) onProgress,+ }) => Completer<Map<String, dynamic>>().future;++ Future<void> shoot(WidgetTester tester, GlobalKey key, String name) async {+ await tester.runAsync(() async {+ final boundary =+ key.currentContext!.findRenderObject()! as RenderRepaintBoundary;+ final image = await boundary.toImage(pixelRatio: 3);+ final png = await image.toByteData(format: ui.ImageByteFormat.png);+ final file = File('$_outDir/$name.png');+ await file.parent.create(recursive: true);+ await file.writeAsBytes(png!.buffer.asUint8List());+ });+ }++ for (final brightness in Brightness.values) {+ final look = brightness.name;++ Future<GlobalKey> chat(+ WidgetTester tester, {+ _MeteredRecorder? recorder,+ }) async {+ await tester.runAsync(_loadFonts);+ final photos = (await tester.runAsync(+ () async => [+ await _photo(const Color(0xFF7FB2E5), const Color(0xFF5E8C4A)),+ await _photo(const Color(0xFFE9A86B), const Color(0xFF3F5B73)),+ ],+ ))!;+ pickSwarmPhotos = (limit) async => [+ XFile.fromData(photos[0], path: '/copies/IMG_2041.jpg'),+ XFile.fromData(photos[1], path: '/copies/IMG_2050.jpg'),+ ];+ final palette = HarnessPalette.values.firstWhere(+ (p) => p.brightness == brightness,+ );+ final previous = (+ grid.AppTheme.brightness.value,+ grid.AppTheme.palette.value,+ );+ grid.AppTheme.palette.value = palette;+ grid.AppTheme.brightness.value = brightness;+ addTearDown(() {+ grid.AppTheme.brightness.value = previous.$1;+ grid.AppTheme.palette.value = previous.$2;+ });+ // A 393 x 852 iPhone with the keyboard up, as the prototype draws it.+ tester.view.physicalSize = const Size(393 * 3, 852 * 3);+ tester.view.devicePixelRatio = 3;+ tester.view.padding = const FakeViewPadding(top: 59 * 3);+ tester.view.viewPadding = const FakeViewPadding(+ top: 59 * 3,+ bottom: 34 * 3,+ );+ tester.view.viewInsets = const FakeViewPadding(bottom: 336 * 3);+ addTearDown(tester.view.reset);++ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: backend().request,+ upload: stuck,+ notices: SilentSystemNotices(),+ features: features,+ voice: () => VoiceInputController(+ transcriber: FakeTranscriber().call,+ recorder: recorder ?? _MeteredRecorder(),+ language: ValueNotifier('en'),+ ),+ )..foreground = false;+ addTearDown(host.dispose);+ final key = GlobalKey();+ await tester.pumpWidget(+ RepaintBoundary(+ key: key,+ child: grid.BrightnessScope(+ child: MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: brightness),+ builder: (context, child) =>+ SwarmScope(notifier: host, child: child!),+ home: const SwarmConversationPage(+ swarmId: tab,+ conversationId: 'g1',+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ return key;+ }++ Future<void> type(WidgetTester tester, String text) async {+ await tester.showKeyboard(find.byType(TextField));+ await tester.enterText(find.byType(TextField), text);+ await tester.pumpAndSettle();+ }++ testWidgets('empty ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await shoot(tester, key, 'composer-empty-$look');+ });++ testWidgets('text ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await type(tester, sample);+ await shoot(tester, key, 'composer-text-$look');+ });++ testWidgets('five lines and more ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await type(+ tester,+ [+ 'Check whether PR #2466 has merged yet.',+ 'If it has, cut the next phone build.',+ 'Then tell Dee and the Lead.',+ 'Attach the release notes.',+ 'Check the crash rate after an hour.',+ 'And the one on Android too.',+ 'Last: close the old ticket.',+ ].join('\n'),+ );+ await shoot(tester, key, 'composer-long-$look');+ });++ testWidgets('@ picker open ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await type(tester, 'Check whether PR #2466 @');+ await shoot(tester, key, 'composer-tag-$look');+ });++ testWidgets('reply ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await tester.tap(+ find.text('The fix is ready. Ship it to TestFlight today?'),+ );+ await tester.pumpAndSettle();+ await tester.tap(find.byKey(const ValueKey('swarm-reply-m1')));+ await tester.pumpAndSettle();+ await type(tester, sample);+ await shoot(tester, key, 'composer-reply-$look');+ });++ testWidgets('files ($look)', skip: skip, (tester) async {+ final key = await chat(tester);+ await tester.tap(find.byKey(const ValueKey('swarm-attach')));+ await tester.pumpAndSettle();+ await tester.tap(find.byKey(const ValueKey('swarm-attach-library')));+ await tester.pumpAndSettle();+ await tester.runAsync(+ () => Future<void>.delayed(const Duration(milliseconds: 300)),+ );+ await tester.pumpAndSettle();+ await type(tester, sample);+ await shoot(tester, key, 'composer-files-$look');+ });++ testWidgets('listening ($look)', skip: skip, (tester) async {+ final recorder = _MeteredRecorder();+ final key = await chat(tester, recorder: recorder);+ await type(tester, 'Check whether PR #2466');+ await tester.tap(find.byKey(const ValueKey('swarm-mic')));+ for (var i = 0; i < 5; i++) {+ await tester.pump();+ }+ for (var i = 0; i < 48; i++) {+ final level = const [0.2, 0.6, 0.9, 0.4, 0.7, 0.3, 0.8, 0.5][i % 8];+ recorder.meter.value = level;+ await tester.pump(const Duration(milliseconds: 120));+ }+ await shoot(tester, key, 'composer-listening-$look');+ });+ }+}++/// A microphone that also says how loud it is: what the wave follows.+class _MeteredRecorder extends FakeVoiceRecorder implements VoiceLevelMeter {+ final meter = ValueNotifier<double>(0);++ @override+ ValueListenable<double> get level => meter;+}diff --git a/mobile/test/render/swarm_voice_render_test.dart b/mobile/test/render/swarm_voice_render_test.dartindex c186411e2..6c1429b72 100644--- a/mobile/test/render/swarm_voice_render_test.dart+++ b/mobile/test/render/swarm_voice_render_test.dart@@ -218,7 +218,8 @@ void main() {..replies.add('Yes, ship it today and tell me when it is up.');final key = await chat(tester, _MeteredRecorder(), stt);await tapMic(tester);- await tapMic(tester);+ // Stop: the words land in the box, unsent.+ await tester.tap(find.byKey(const ValueKey('swarm-voice-stop')));await tester.pumpAndSettle();await shoot(tester, key, 'swarm-voice-heard-$look');});diff --git a/mobile/test/swarm/swarm_chat_dictation_test.dart b/mobile/test/swarm/swarm_chat_dictation_test.dartindex 56c7d4231..95e8bd2a6 100644--- a/mobile/test/swarm/swarm_chat_dictation_test.dart+++ b/mobile/test/swarm/swarm_chat_dictation_test.dart@@ -13,6 +13,7 @@ import 'package:harness_mobile/swarm/swarm_conversation_page.dart';import 'package:harness_mobile/swarm/swarm_dictation.dart';import 'package:harness_mobile/swarm/swarm_file_picker.dart';import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_voice.dart';import 'package:image_picker/image_picker.dart' show XFile;import '../voice_fakes.dart';@@ -20,11 +21,12 @@ import 'swarm_fixture.dart';/// A Swarm chat's mic on the phone's own speech recognizer (Tony, 10-28: the/// one the keyboard's dictation uses): the words show in the message box as-/// they are said, and it listens on — through any pause — until a second tap-/// stops it and sends what is in the box (Tony, 10-29); only two minutes-/// without a new word stop it before that, the words left in the box (Lead,-/// review of #2056). Refused, or without the language, the mic records and the-/// backend transcribes.+/// they are said, and it listens on — through any pause — until Stop ends it+/// with the words left in the box, or Cancel takes back what it added. Voice+/// never sends by itself (Tony, 11-01): Send does. Only two minutes without a+/// new word stop it before that, the words left in the box (Lead, review of+/// #2056). Refused, or without the language, the mic records and the backend+/// transcribes.void main() {const messages = '/api/super-tabs/$tab/conversations/g1/messages';const commands = '/api/super-tabs/$tab/commands';@@ -132,6 +134,25 @@ void main() {await frames(tester);}+ /// The voice row's Stop: the take ends, its words left in the box.+ Future<void> stop(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-stop'));+ await frames(tester);+ }++ /// The voice row's Cancel: what the take added leaves the box.+ Future<void> cancel(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-cancel'));+ await frames(tester);+ }++ /// Back at rest: the mic and Send in the toolbar, no voice row.+ void atRest() {+ expect(key('swarm-voice-wave'), findsNothing);+ expect(key('swarm-mic'), findsOneWidget);+ expect(key('swarm-send'), findsOneWidget);+ }+Future<void> say(WidgetTester tester, String words) async {dictation.say(words);await frames(tester);@@ -158,10 +179,8 @@ void main() {await tapMic(tester);expect(dictation.locales, ['vi-VN']);expect(recorder.starts, 0, reason: 'the recognizer has the microphone');- expect(- tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).face,- VoiceMicFace.listening,- );+ expect(key('swarm-voice-stop'), findsOneWidget);+ expect(key('swarm-mic'), findsNothing);await say(tester, 'hôm');expect(box(tester), 'hôm');@@ -173,23 +192,31 @@ void main() {expect(fake.commands, isEmpty);});- testWidgets('the second tap stops listening and sends what is in the box, '- 'its last words included', (tester) async {+ // Tony, 11-01: voice never sends by itself; sending is a tap on Send.+ testWidgets('Stop ends listening with its last words in the box, sends '+ 'nothing and says nothing; Send then posts them', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'một hai ba');dictation.lastWords = 'một hai ba bốn';- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(dictation.stops, 1);+ expect(box(tester), 'một hai ba bốn');+ expect(fake.commands, isEmpty, reason: 'Stop never sends');+ expect(key('swarm-voice-note'), findsNothing);+ atRest();++ await tester.tap(key('swarm-send'));+ await tester.pumpAndSettle();expect(fake.commands.single['text'], 'một hai ba bốn');expect(box(tester), isEmpty);});testWidgets('what was typed stays in front, and an edit made while talking '- 'is kept and sent', (tester) async {+ 'is kept in the box after Stop', (tester) async {await pump(tester);await tester.enterText(find.byType(TextField), 'Nova:');await tester.pump();@@ -203,9 +230,128 @@ void main() {await say(tester, 'ship it today');expect(box(tester), 'Nova: ship it now today');+ await stop(tester);+ await tester.pumpAndSettle();+ expect(box(tester), 'Nova: ship it now today');+ expect(fake.commands, isEmpty);+ });++ testWidgets('Cancel takes back what the take said and keeps what was typed '+ 'before it', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Nova:');+ await tester.pump();+await tapMic(tester);+ await say(tester, 'ship it');+ expect(box(tester), 'Nova: ship it');++ await cancel(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'Nova: ship it now today');+ expect(box(tester), 'Nova:');+ expect(dictation.cancels, 1, reason: 'the microphone released');+ expect(dictation.listening, isFalse);+ expect(fake.commands, isEmpty);+ expect(key('swarm-voice-note'), findsNothing);+ atRest();+ });++ testWidgets('Cancel keeps an edit made during the take and drops only the '+ 'words said after it', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'ship it');+ await tester.enterText(find.byType(TextField), 'ship it now');+ await tester.pump();+ await say(tester, 'ship it today');+ expect(box(tester), 'ship it now today');++ await cancel(tester);+ await tester.pumpAndSettle();+ expect(box(tester), 'ship it now');+ expect(fake.commands, isEmpty);+ });++ testWidgets('Cancel right after an edit, with no word since, keeps the box '+ 'as the person left it', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'ship it');+ await tester.enterText(find.byType(TextField), 'ship it now!');+ await tester.pump();++ await cancel(tester);+ await tester.pumpAndSettle();+ expect(box(tester), 'ship it now!');+ expect(fake.commands, isEmpty);+ });++ testWidgets('Cancel while the recognizer is stopping drops what the take '+ 'said', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ await tapMic(tester);+ await say(tester, 'gửi đi');++ dictation.stopsSilently = true;+ await stop(tester);+ expect(key('swarm-voice-busy'), findsOneWidget);+ await cancel(tester);+ await tester.pumpAndSettle();++ expect(box(tester), 'Draft');+ expect(dictation.cancels, 1);+ expect(fake.commands, isEmpty);+ atRest();+ });++ testWidgets('no Send, +, Tag or X during a take; they come back after '+ 'Stop', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ expect(key('swarm-field-clear'), findsOneWidget);++ await tapMic(tester);+ expect(key('swarm-send'), findsNothing);+ expect(key('swarm-attach'), findsNothing);+ expect(key('swarm-tag'), findsNothing);+ expect(key('swarm-mic'), findsNothing);+ expect(key('swarm-field-clear'), findsNothing);+ expect(key('swarm-voice-cancel'), findsOneWidget);+ expect(key('swarm-voice-wave'), findsOneWidget);+ expect(key('swarm-voice-stop'), findsOneWidget);++ await say(tester, 'ship it');+ await stop(tester);+ await tester.pumpAndSettle();+ atRest();+ expect(key('swarm-attach'), findsOneWidget);+ expect(key('swarm-tag'), findsOneWidget);+ expect(key('swarm-field-clear'), findsOneWidget);+ expect(+ tester.widget<SwarmRoundButton>(key('swarm-send')).onTap,+ isNotNull,+ reason: 'Send is live again',+ );+ });++ testWidgets('the @ picker hides during a take and comes back after Cancel', (+ tester,+ ) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), '@');+ await tester.pump();+ expect(key('swarm-mention-picker'), findsOneWidget);++ await tapMic(tester);+ expect(key('swarm-mention-picker'), findsNothing);++ await cancel(tester);+ await tester.pumpAndSettle();+ expect(box(tester), '@');+ expect(key('swarm-mention-picker'), findsOneWidget);});// Lead, review of #2056 at a43760af3: an edit, then the recognizer revising@@ -223,14 +369,15 @@ void main() {await say(tester, '123 bốn');expect(box(tester), 'một hai, 123 bốn');- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'một hai, 123 bốn');+ expect(box(tester), 'một hai, 123 bốn');+ expect(fake.commands, isEmpty);});// Tony, 10-29: "listening continues until I tap".testWidgets('listening goes on through a silence of nearly two minutes '- 'until the tap, which sends what was said', (tester) async {+ 'until Stop, which leaves what was said in the box', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'xong rồi');@@ -241,15 +388,13 @@ void main() {await tester.pump(const Duration(seconds: 9));expect(dictation.stops, 0);expect(dictation.listening, isTrue);- expect(- tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).face,- VoiceMicFace.listening,- );- expect(fake.commands, isEmpty, reason: 'only the tap sends');+ expect(key('swarm-voice-stop'), findsOneWidget);+ expect(fake.commands, isEmpty);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'xong rồi');+ expect(box(tester), 'xong rồi');+ expect(fake.commands, isEmpty, reason: 'only Send sends');});testWidgets('talking with pauses under two minutes never stops it', (@@ -268,9 +413,10 @@ void main() {expect(dictation.listening, isTrue, reason: 'ten minutes in');expect(dictation.stops + dictation.cancels, 0);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], said);+ expect(box(tester), said);+ expect(fake.commands, isEmpty);});// Lead, review of #2056 at a43760af3 (privacy): the microphone is not held@@ -290,7 +436,7 @@ void main() {await frames(tester);expect(dictation.listening, isFalse);expect(dictation.cancels, 1, reason: 'the microphone released at once');- expect(find.byType(VoiceMicCore), findsNothing, reason: 'the mic at rest');+ atRest();expect(box(tester), 'gần xong');expect(fake.commands, isEmpty);@@ -344,14 +490,14 @@ void main() {expect(fake.commands, isEmpty);});- testWidgets('a tap ends no take with Stopped listening, and a new take '+ testWidgets('Stop ends no take with Stopped listening, and a new take ''takes it away', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'Ship it');- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(find.text('Stopped listening'), findsNothing, reason: 'tapped');+ expect(find.text('Stopped listening'), findsNothing, reason: 'stopped');await tapMic(tester);await tester.pump(const Duration(minutes: 2));@@ -361,10 +507,10 @@ void main() {expect(find.text('Stopped listening'), findsNothing);});- testWidgets('a second tap with nothing said sends nothing', (tester) async {+ testWidgets('Stop with nothing said sends nothing', (tester) async {await pump(tester);await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(dictation.stops, 1);@@ -372,28 +518,27 @@ void main() {expect(fake.commands, isEmpty);});- testWidgets('a second tap with nothing said sends what was typed', (- tester,- ) async {+ testWidgets('Stop with nothing said leaves what was typed, unsent and with '+ 'no notice', (tester) async {await pump(tester);await tester.enterText(find.byType(TextField), 'Draft');await tester.pump();await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'Draft');- expect(box(tester), isEmpty);+ expect(box(tester), 'Draft');+ expect(fake.commands, isEmpty);expect(find.text("Didn't catch that · tap the mic again"), findsNothing);});- testWidgets('a second tap with nothing said and an empty box says so', (+ testWidgets('Stop with nothing said and an empty box says so', (tester,) async {await pump(tester);await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(fake.commands, isEmpty);@@ -401,31 +546,35 @@ void main() {});testWidgets('a recognizer that never says it stopped is given up after two '- 'seconds, and what is in the box is sent', (tester) async {+ 'seconds, its words left in the box, unsent', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'gửi đi');dictation.stopsSilently = true;- await tapMic(tester);+ await stop(tester);await tester.pump(const Duration(milliseconds: 1900));expect(tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).face,VoiceMicFace.busy,reason: 'still waiting for its last words',);+ expect(key('swarm-voice-stop'), findsNothing);+ expect(key('swarm-voice-cancel'), findsOneWidget);await tester.pump(const Duration(milliseconds: 200));await frames(tester);expect(find.byType(VoiceMicCore), findsNothing);expect(dictation.cancels, 1);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'gửi đi');- expect(box(tester), isEmpty);+ expect(box(tester), 'gửi đi');+ expect(fake.commands, isEmpty);+ expect(key('swarm-voice-note'), findsNothing);+ atRest();});- testWidgets('a second tap sends nothing once the box was emptied, though '- 'files wait to go', (tester) async {+ testWidgets('Stop after the box was emptied leaves it empty and sends '+ 'nothing, though files wait to go', (tester) async {final documents = pickSwarmFiles, copies = swarmPickerCopyFolders;addTearDown(() {pickSwarmFiles = documents;@@ -450,13 +599,18 @@ void main() {await tester.enterText(find.byType(TextField), '');await tester.pump();dictation.lastWords = 'nhầm rồi';- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(box(tester), isEmpty);expect(uploads, isEmpty);expect(fake.commands, isEmpty);expect(key('swarm-outgoing-crash.log'), findsOneWidget);+ expect(+ tester.widget<SwarmRoundButton>(key('swarm-send')).onTap,+ isNotNull,+ reason: 'the files can still go, by Send',+ );});testWidgets('listening that cannot go on stops, its words left unsent', (@@ -492,30 +646,33 @@ void main() {expect(fake.commands, isEmpty);});- testWidgets('a second tap on a recognizer that fails as it stops still '- 'sends what is in the box', (tester) async {+ testWidgets('Stop on a recognizer that fails as it stops keeps the box, '+ 'says nothing and sends nothing', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'gửi');dictation.stopEnd = SwarmDictationEnd.failed;- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'gửi');+ expect(box(tester), 'gửi');+ expect(fake.commands, isEmpty);+ expect(find.text("Couldn't transcribe · tap the mic again"), findsNothing);});- testWidgets('a second tap sends what was said though the last session heard '+ testWidgets('Stop keeps what was said though the last session heard ''nothing', (tester) async {await pump(tester);await tapMic(tester);await say(tester, 'xin chào');dictation.stopEnd = SwarmDictationEnd.noSpeech;- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'xin chào');+ expect(box(tester), 'xin chào');+ expect(fake.commands, isEmpty);expect(find.text("Didn't catch that · tap the mic again"), findsNothing);});@@ -531,9 +688,7 @@ void main() {expect(find.text("Didn't catch that · tap the mic again"), findsOneWidget);});- testWidgets('the mic is drawn as loud as the recognizer hears', (- tester,- ) async {+ testWidgets('the wave follows how loud the recognizer hears', (tester) async {await pump(tester);await tapMic(tester);@@ -541,24 +696,30 @@ void main() {await tester.pump();expect(- tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).level!.value,+ tester.widget<SwarmVoiceWave>(key('swarm-voice-wave')).level!.value,0.8,);});- /// How tall the mic's bars stand, all together: the face's 4pt-wide boxes.- double bars(WidgetTester tester) => tester- .widgetList<Container>(- find.descendant(- of: find.byType(VoiceMicCore),- matching: find.byType(Container),- ),- )- .map((box) => box.constraints)- .where((size) => size?.maxWidth == 4)- .fold(0, (sum, bar) => sum + bar!.maxHeight);+ /// The wave's bars as it paints them now, on a 200 x 44 strip: each one's+ /// height.+ List<double> waveBars(WidgetTester tester) {+ final painter = tester+ .widget<CustomPaint>(+ find.descendant(+ of: key('swarm-voice-wave'),+ matching: find.byType(CustomPaint),+ ),+ )+ .painter!;+ final canvas = _BarCanvas();+ painter.paint(canvas, const Size(200, 44));+ return canvas.heights;+ }++ double total(List<double> bars) => bars.fold(0, (sum, bar) => sum + bar);- /// Half a second of the bars' frames.+ /// Half a second of the wave's frames.Future<void> wave(WidgetTester tester) async {for (var i = 0; i < 10; i++) {await tester.pump(const Duration(milliseconds: 50));@@ -566,30 +727,48 @@ void main() {}// Lead, 10-29: "a live wave animation driven by the mic level".- testWidgets('the bars rise as the voice does', (tester) async {+ testWidgets('the wave rises as the voice does', (tester) async {await pump(tester);await tapMic(tester);dictation.loud(0);await wave(tester);- final quiet = bars(tester);+ final quiet = total(waveBars(tester));dictation.loud(0.8);await wave(tester);- expect(bars(tester), greaterThan(quiet + 20));+ expect(total(waveBars(tester)), greaterThan(quiet + 40));+ expect(waveBars(tester).every((h) => h >= 3 && h <= 24), isTrue);});- testWidgets('with Reduce Motion on, the bars still follow the voice', (+ testWidgets('the wave is not frozen in silence: it keeps moving', (tester,) async {+ await pump(tester);+ await tapMic(tester);+ dictation.loud(0);+ await wave(tester);+ final before = waveBars(tester);++ await wave(tester);+ final after = waveBars(tester);+ expect(after, isNot(equals(before)), reason: 'the history scrolls');+ expect(after.any((h) => h > 3), isTrue, reason: 'a breath, not a line');+ });++ testWidgets('with Reduce Motion on, the wave holds still but follows the '+ 'voice', (tester) async {await pump(tester, reduceMotion: true);await tapMic(tester);dictation.loud(0);await tester.pump();- final quiet = bars(tester);+ final quiet = waveBars(tester);++ await wave(tester);+ expect(waveBars(tester), equals(quiet), reason: 'nothing scrolls');dictation.loud(0.8);await tester.pump();- expect(bars(tester), greaterThan(quiet + 20));+ expect(total(waveBars(tester)), greaterThan(total(quiet) + 40));});testWidgets('the long-press language is the one listened in', (tester) async {@@ -601,8 +780,8 @@ void main() {expect(dictation.locales, ['ja-JP']);});- testWidgets('speech recognition refused: the mic records and transcribes, '- 'and is not asked again', (tester) async {+ testWidgets('speech recognition refused: the mic records, Stop transcribes '+ 'into the box unsent, and it is not asked again', (tester) async {dictation.answer = SwarmDictationAccess.denied;await pump(tester);stt.replies.addAll(['ghi âm', 'lần nữa']);@@ -610,9 +789,10 @@ void main() {await tapMic(tester);expect(dictation.locales, isEmpty);expect(recorder.recording, isTrue);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'ghi âm');+ expect(box(tester), 'ghi âm');+ expect(fake.commands, isEmpty);await tapMic(tester);expect(dictation.asks, 1);@@ -630,20 +810,22 @@ void main() {expect(recorder.recording, isTrue);});- testWidgets('a tap while the permission prompt is up calls the take off', (+ testWidgets('Cancel while the permission prompt is up calls the take off', (tester,) async {dictation.pendingAccess = Completer();await pump(tester);await tapMic(tester);- await tapMic(tester);+ expect(key('swarm-voice-cancel'), findsOneWidget);+ expect(key('swarm-voice-stop'), findsNothing, reason: 'still opening');+ await cancel(tester);dictation.pendingAccess!.complete(SwarmDictationAccess.allowed);await frames(tester);expect(dictation.locales, isEmpty);expect(recorder.starts, 0);- expect(find.byType(VoiceMicCore), findsNothing, reason: 'back at rest');+ atRest();});testWidgets('the permission prompt over the app keeps the take it asks for', (@@ -818,3 +1000,14 @@ class FakeDictation implements SwarmDictation {_end = null;}}++/// A canvas that keeps the height of each bar painted on it, and nothing else.+class _BarCanvas implements Canvas {+ final List<double> heights = [];++ @override+ void drawRRect(RRect rrect, Paint paint) => heights.add(rrect.height);++ @override+ dynamic noSuchMethod(Invocation invocation) => null;+}diff --git a/mobile/test/swarm/swarm_chat_test.dart b/mobile/test/swarm/swarm_chat_test.dartindex 6c031395b..b109c6e78 100644--- a/mobile/test/swarm/swarm_chat_test.dart+++ b/mobile/test/swarm/swarm_chat_test.dart@@ -663,21 +663,36 @@ void main() {expect(fake.commands.single['replyTo'], isNull);});- testWidgets('the composer has no @ button: an @ typed in the field opens '- 'the picker', (tester) async {+ testWidgets('the composer has an @ Tag chip (Tony, 11-01): it and an @ '+ 'typed in the field open the same picker', (tester) async {await pump(tester, backend([message('m1', 1)]));expect(key('swarm-attach'), findsOneWidget);expect(key('swarm-field'), findsOneWidget);expect(key('swarm-send'), findsOneWidget);- expect(key('swarm-mention'), findsNothing);- expect(find.byIcon(LucideIcons.atSign), findsNothing);+ expect(key('swarm-tag'), findsOneWidget);+ expect(+ find.descendant(+ of: key('swarm-tag'),+ matching: find.byIcon(LucideIcons.atSign),+ ),+ findsOneWidget,+ );await tester.enterText(find.byType(TextField), '@');await tester.pump();expect(key('swarm-mention-picker'), findsOneWidget);expect(key('swarm-pick-agent-lead'), findsOneWidget);expect(key('swarm-pick-agent-builder'), findsOneWidget);++ await tester.enterText(find.byType(TextField), '');+ await tester.pump();+ expect(key('swarm-mention-picker'), findsNothing);+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(key('swarm-mention-picker'), findsOneWidget);+ expect(key('swarm-pick-agent-lead'), findsOneWidget);+ expect(key('swarm-pick-agent-builder'), findsOneWidget);});testWidgets('the @ picker lists the chat\'s agents with role and state, '@@ -1547,8 +1562,8 @@ void main() {expect(marked, ['@Nova']);});- testWidgets('the field is one rounded line until more is typed; Send is a '- 'round arrow that waits for text', (tester) async {+ testWidgets('the field is one line in the card until more is typed; Send '+ 'is a round arrow that waits for text', (tester) async {final fake = backend([message('m1', 1)]);await pump(tester, fake);@@ -1609,12 +1624,18 @@ void main() {});testWidgets(- 'on an iPhone the field rests at the 44 of the buttons beside it',+ 'on an iPhone one line rests in an 86pt card: the field over a toolbar '+ 'of 44pt targets',(tester) async {await pump(tester, backend([message('m1', 1)]));- expect(tester.getSize(key('swarm-field')).height, 44);+ expect(tester.getSize(key('swarm-composer-card')).height, 86);+ expect(tester.getSize(key('swarm-field')).height, 36);expect(tester.getSize(key('swarm-send')).height, 44);+ expect(+ tester.getRect(key('swarm-send')).top,+ greaterThanOrEqualTo(tester.getRect(key('swarm-field')).bottom),+ );},variant: TargetPlatformVariant.only(TargetPlatform.iOS),);diff --git a/mobile/test/swarm/swarm_chat_voice_test.dart b/mobile/test/swarm/swarm_chat_voice_test.dartindex 7c3a3ee87..83bb9b231 100644--- a/mobile/test/swarm/swarm_chat_voice_test.dart+++ b/mobile/test/swarm/swarm_chat_voice_test.dart@@ -12,6 +12,7 @@ import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;import 'package:harness_mobile/swarm/swarm_conversation_page.dart';import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_voice.dart';import '../voice_fakes.dart';import 'swarm_fixture.dart';@@ -19,10 +20,11 @@ import 'swarm_fixture.dart';/// Talking instead of typing in a Swarm chat (Tony, 10-28), where the phone/// has no speech recognizer of its own to use: the terminal's mic in the/// composer records, and what the backend hears lands in the message box as-/// the take ends; a second tap on the mic stops and sends what is in the box,-/// and nothing but its 5-minute limit ends a take before that (Tony, 10-29). A-/// long press on the mic picks the language. With the phone's recognizer:-/// `swarm_chat_dictation_test`.+/// the take ends. While a take runs the toolbar is cancel, wave and stop:+/// stop leaves the words in the box and sends nothing — sending is a tap on+/// Send (Tony, 11-01) — and nothing but stop, cancel or its 5-minute limit+/// ends a take (Tony, 10-29). A long press on the mic picks the language.+/// With the phone's recognizer: `swarm_chat_dictation_test`.void main() {const messages = '/api/super-tabs/$tab/conversations/g1/messages';const commands = '/api/super-tabs/$tab/commands';@@ -126,53 +128,75 @@ void main() {await frames(tester);}+ /// The voice row's stop: the take ends with its words left in the box.+ Future<void> stop(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-stop'));+ await frames(tester);+ }++ /// The voice row's cancel: the take is thrown away.+ Future<void> cancel(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-cancel'));+ await frames(tester);+ }++ Future<void> send(WidgetTester tester) async {+ await tester.tap(key('swarm-send'));+ await tester.pumpAndSettle();+ }+String box(WidgetTester tester) =>tester.widget<TextField>(find.byType(TextField)).controller!.text;- testWidgets('a second tap stops the take and sends what it heard', (- tester,- ) async {+ testWidgets('stop ends the take with what it heard in the box and sends '+ 'nothing; Send then posts it', (tester) async {await pump(tester);stt.replies.add('ship the fix today');await tapMic(tester);expect(recorder.recording, isTrue);+ expect(key('swarm-voice-stop'), findsOneWidget);expect(- tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).face,- VoiceMicFace.listening,- reason: 'the terminal\'s listening face, its bars moving with the voice',+ find.byType(SwarmVoiceWave),+ findsOneWidget,+ reason: 'the wave, moving with the voice',);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(recorder.recording, isFalse);+ expect(box(tester), 'ship the fix today');+ expect(fake.commands, isEmpty, reason: 'voice never sends by itself');++ await send(tester);expect(fake.commands.single['text'], 'ship the fix today');expect(box(tester), isEmpty);});- testWidgets('what was typed goes with what is said, on the second tap', (- tester,- ) async {+ testWidgets('what was typed stays in front of what is said; stop leaves '+ 'both in the box, unsent', (tester) async {await pump(tester);await tester.enterText(find.byType(TextField), 'Nova:');await tester.pump();stt.replies.add('ship the fix');await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();+ expect(box(tester), 'Nova: ship the fix');+ expect(fake.commands, isEmpty);+ await send(tester);expect(fake.commands.single['text'], 'Nova: ship the fix');- expect(box(tester), isEmpty);});- testWidgets('a second tap with nothing in the box sends nothing', (+ testWidgets('a stop with nothing heard sends nothing and says so', (tester,) async {await pump(tester);await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(recorder.recording, isFalse);@@ -183,7 +207,7 @@ void main() {// Tony, 10-29: "listening continues until I tap".testWidgets('a pause after speaking does not end the take: it records until '- 'the tap, which sends', (tester) async {+ 'stop, which leaves the words in the box', (tester) async {await pump(tester);stt.replies.add('looks good');@@ -195,9 +219,10 @@ void main() {expect(recorder.recording, isTrue);expect(fake.commands, isEmpty);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'looks good');+ expect(box(tester), 'looks good');+ expect(fake.commands, isEmpty);});testWidgets('the take runs on through quiet before anything is said, and '@@ -220,19 +245,25 @@ void main() {expect(recorder.recording, isTrue, reason: 'talking again restarts it');});- testWidgets('a tap while the microphone is opening calls the take off', (- tester,- ) async {+ testWidgets('while the microphone opens the row is cancel and a flat '+ 'wave, no stop; cancel calls the take off', (tester) async {recorder.pendingPermission = Completer();await pump(tester);await tapMic(tester);- await tapMic(tester);+ expect(key('swarm-voice-cancel'), findsOneWidget);+ expect(key('swarm-voice-wave'), findsOneWidget);+ expect(tester.widget<SwarmVoiceWave>(key('swarm-voice-wave')).flat, isTrue);+ expect(key('swarm-voice-stop'), findsNothing);+ expect(key('swarm-mic'), findsNothing);++ await cancel(tester);recorder.pendingPermission!.complete(true);await frames(tester);expect(recorder.starts, 0);- expect(find.byType(VoiceMicCore), findsNothing, reason: 'back at rest');+ expect(key('swarm-voice-cancel'), findsNothing, reason: 'back at rest');+ expect(key('swarm-mic'), findsOneWidget);});testWidgets('a refused microphone says so, and records nothing', (@@ -255,7 +286,7 @@ void main() {stt.fails = true;await tapMic(tester);- await tapMic(tester);+ await stop(tester);expect(box(tester), 'Draft');expect(@@ -279,9 +310,8 @@ void main() {// Put away without choosing: a choice writes the real preferences file.});- testWidgets('VoiceOver can talk, finish and choose the language', (- tester,- ) async {+ testWidgets('VoiceOver can talk, stop, cancel and choose the language, '+ 'each a one-word label while the mic is open', (tester) async {final semantics = tester.ensureSemantics();await pump(tester);stt.replies.add('on my way');@@ -302,11 +332,33 @@ void main() {tester.semantics.tap(find.semantics.byLabel('Talk'));await frames(tester);expect(recorder.recording, isTrue);- expect(find.semantics.byLabel('Done'), findsOne);+ for (final (control, label) in [+ ('swarm-voice-cancel', 'Cancel'),+ ('swarm-voice-stop', 'Stop'),+ ]) {+ expect(+ tester.getSemantics(key(control)),+ matchesSemantics(+ label: label,+ isButton: true,+ hasEnabledState: true,+ isEnabled: true,+ hasTapAction: true,+ ),+ );+ }++ tester.semantics.tap(find.semantics.byLabel('Stop'));+ await tester.pumpAndSettle();+ expect(box(tester), 'on my way');+ expect(fake.commands, isEmpty);- tester.semantics.tap(find.semantics.byLabel('Done'));+ tester.semantics.tap(find.semantics.byLabel('Talk'));+ await frames(tester);+ tester.semantics.tap(find.semantics.byLabel('Cancel'));await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'on my way');+ expect(recorder.recording, isFalse);+ expect(box(tester), 'on my way', reason: 'what was there before stays');tester.semantics.longPress(find.semantics.byLabel('Talk'));await tester.pumpAndSettle();@@ -427,7 +479,7 @@ void main() {// Review of #2014 at 42c8eac9c: the reviewer's probe, in its order.testWidgets('quiet under a system prompt ends nothing; the take goes on '- 'once the app is back, until the tap', (tester) async {+ 'once the app is back, until stop', (tester) async {addTearDown(() => tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed,@@ -448,9 +500,10 @@ void main() {await lifecycle(tester, [AppLifecycleState.resumed]);await tester.pump(const Duration(seconds: 10));expect(recorder.recording, isTrue);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'said before Control Center');+ expect(box(tester), 'said before Control Center');+ expect(fake.commands, isEmpty);});testWidgets('a take kept under a system prompt goes if the app then goes '@@ -524,11 +577,13 @@ void main() {expect(box(tester), 'held over the limit');});- // Review of #2014 at 61a2bce93: the reviewer's probe, with the tap that- // ends a take now (Tony, 10-29) — a system prompt comes up while the- // microphone is still closing.+ // Review of #2014 at 61a2bce93: the reviewer's probe, with stop ending the+ // take now (Tony, 11-01) — a system prompt comes up while the microphone is+ // still closing.testWidgets('a take whose microphone closes under a system prompt is sent '- 'to be transcribed only once the app is back', (tester) async {+ 'to be transcribed only once the app is back, into the box', (+ tester,+ ) async {addTearDown(() => tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed,@@ -540,7 +595,7 @@ void main() {await tapMic(tester);recorder.meter.value = 0.8;await tester.pump(const Duration(milliseconds: 500));- await tapMic(tester);+ await stop(tester);expect(recorder.stops, 1);expect(stt.calls, isEmpty);@@ -558,7 +613,8 @@ void main() {await lifecycle(tester, [AppLifecycleState.resumed]);await tester.pumpAndSettle();expect(stt.calls, hasLength(1));- expect(fake.commands.single['text'], 'said just before Control Center');+ expect(box(tester), 'said just before Control Center');+ expect(fake.commands, isEmpty);});testWidgets('a take that reaches its limit as a system prompt comes up '@@ -596,7 +652,7 @@ void main() {stt.replies.add('never heard');recorder.heldStop = Completer();await tapMic(tester);- await tapMic(tester);+ await stop(tester);expect(recorder.stops, 1);await lifecycle(tester, [AppLifecycleState.inactive]);@@ -624,7 +680,7 @@ void main() {stt.replies.add('said behind another screen');recorder.heldStop = Completer();await tapMic(tester);- await tapMic(tester);+ await stop(tester);await cover(tester);recorder.heldStop!.complete(recorder.captured);@@ -645,9 +701,10 @@ void main() {await tapMic(tester);expect(recorder.starts, 2);expect(recorder.recording, isTrue);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();- expect(fake.commands.single['text'], 'second try');+ expect(box(tester), 'second try');+ expect(fake.commands, isEmpty);});testWidgets('a microphone allowed after the chat was covered never opens', (@@ -670,7 +727,7 @@ void main() {await pump(tester);stt.pending = Completer();await tapMic(tester);- await tapMic(tester);+ await stop(tester);expect(stt.calls, hasLength(1), reason: 'sent while the chat was seen');await cover(tester);@@ -682,6 +739,99 @@ void main() {expect(fake.commands, isEmpty);});+ testWidgets('during a take the toolbar is cancel, wave and stop: no Send, '+ '+, Tag, mic, X or @ picker; all come back after stop', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), '@');+ await tester.pump();+ expect(key('swarm-mention-picker'), findsOneWidget);+ expect(key('swarm-field-clear'), findsOneWidget);+ stt.replies.add('Nova');++ await tapMic(tester);+ for (final gone in [+ 'swarm-send',+ 'swarm-attach',+ 'swarm-tag',+ 'swarm-mic',+ 'swarm-field-clear',+ 'swarm-mention-picker',+ ]) {+ expect(key(gone), findsNothing, reason: '$gone during a take');+ }+ for (final shown in [+ 'swarm-voice-cancel',+ 'swarm-voice-wave',+ 'swarm-voice-stop',+ ]) {+ expect(key(shown), findsOneWidget, reason: '$shown during a take');+ }++ await stop(tester);+ await tester.pumpAndSettle();+ expect(box(tester), '@ Nova');+ for (final back in [+ 'swarm-send',+ 'swarm-attach',+ 'swarm-tag',+ 'swarm-mic',+ 'swarm-field-clear',+ ]) {+ expect(key(back), findsOneWidget, reason: '$back after stop');+ }+ expect(key('swarm-voice-stop'), findsNothing);+ expect(fake.commands, isEmpty);+ });++ testWidgets('cancel throws the take away and leaves what was typed before', (+ tester,+ ) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ stt.replies.add('never wanted');++ await tapMic(tester);+ recorder.meter.value = 0.8;+ await tester.pump(const Duration(milliseconds: 500));+ await cancel(tester);+ await tester.pumpAndSettle();++ expect(recorder.recording, isFalse);+ expect(recorder.cancels, 1);+ expect(stt.calls, isEmpty, reason: 'a cancelled take is not transcribed');+ expect(box(tester), 'Draft');+ expect(fake.commands, isEmpty);+ expect(key('swarm-mic'), findsOneWidget);+ });++ testWidgets('while the words are being transcribed the row is cancel and '+ 'the busy face, no stop; cancel then puts nothing in the box', (+ tester,+ ) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ stt.pending = Completer();++ await tapMic(tester);+ await stop(tester);+ expect(stt.calls, hasLength(1));+ expect(key('swarm-voice-busy'), findsOneWidget);+ expect(key('swarm-voice-stop'), findsNothing);+ expect(key('swarm-send'), findsNothing);++ await cancel(tester);+ stt.pending!.complete('late words');+ await frames(tester);+ await tester.pumpAndSettle();++ expect(box(tester), 'Draft');+ expect(fake.commands, isEmpty);+ expect(key('swarm-voice-busy'), findsNothing);+ expect(key('swarm-mic'), findsOneWidget);+ });+testWidgets('with no voice input the composer has no mic', (tester) async {await pump(tester, voice: false);@@ -766,7 +916,7 @@ void main() {await tapMic(tester);recorder.meter.value = 0.8;await tester.pump(const Duration(milliseconds: 500));- await tapMic(tester);+ await stop(tester);expect(stt.calls, hasLength(1), reason: 'the take is being transcribed');await reread(tester, host, role: 'viewer');diff --git a/mobile/test/swarm/swarm_composer_test.dart b/mobile/test/swarm/swarm_composer_test.dartnew file mode 100644index 000000000..6d4e3d61f--- /dev/null+++ b/mobile/test/swarm/swarm_composer_test.dart@@ -0,0 +1,785 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/phone/voice_input_controller.dart';+import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;+import 'package:harness_mobile/shared/theme/app_theme.dart' show AppPalette;+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_file_picker.dart';+import 'package:harness_mobile/swarm/swarm_outgoing_files.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:image_picker/image_picker.dart' show XFile;+import 'package:lucide_icons_flutter/lucide_icons.dart';++import '../voice_fakes.dart';+import 'swarm_fixture.dart';++/// The composer card (Tony, 11-01): the X that clears the text, the @ Tag+/// chip, and the card's layout on the chat and in a thread — with the+/// keyboard up, on a 320pt phone, with files and a reply.+void main() {+ const messages = '/api/super-tabs/$tab/conversations/g1/messages';+ const commands = '/api/super-tabs/$tab/commands';++ Map<String, dynamic> message(+ String id,+ int sequence, {+ String text = 'Which name for the flag?',+ String author = 'agent-builder',+ String? thread,+ String? replyTo,+ }) => {+ 'id': id,+ 'conversationId': 'g1',+ 'text': text,+ 'sequence': sequence,+ 'thread': ?thread,+ 'replyTo': ?replyTo,+ 'author': {+ 'kind': 'agent',+ 'id': author,+ 'name': author == 'agent-lead' ? 'River' : 'Nova',+ },+ 'attachments': <Object>[],+ 'reactions': <Object>[],+ 'createdAt': DateTime.utc(2026, 11, 1, 1, sequence).toIso8601String(),+ };++ /// Chat g1 with River and Nova in it (or [agentIds]), reading [page], with+ /// [members] in its Swarm and the line of a thread under m1 if [threads].+ FakeSwarm backend(+ List<Map<String, dynamic>> page, {+ List<String> agentIds = const ['agent-lead', 'agent-builder'],+ List<Map<String, dynamic>>? members,+ bool threads = false,+ }) {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {+ ...firstLoad(+ groups: [+ groupData(+ 'g1',+ title: 'Fix login',+ agentIds: agentIds,+ status: 'working',+ lastMessageSequence: page.length,+ ),+ ],+ ),+ 'members': [+ for (final member in members ?? [person(me)])+ part(member['id'] as String, 1, member),+ ],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ final line = {+ 'id': 'm1',+ 'replies': 1,+ 'lastSequence': 2,+ 'lastAt': DateTime.now().toUtc().toIso8601String(),+ 'authors': [+ {'kind': 'agent', 'id': 'agent-builder', 'name': 'Nova'},+ ],+ 'people': <String>[],+ };+ fake.routes[messages] = (_) => {+ 'messages': [+ for (final m in page.reversed)+ if (m['thread'] == null || m['id'] == m['thread']) m,+ ],+ 'next': null,+ 'threads': [if (threads) line],+ };+ fake.routes['$messages?thread=m1'] = (_) => {+ 'messages': [+ for (final m in page.reversed)+ if (m['thread'] == 'm1') m,+ ],+ 'next': null,+ 'threads': [if (threads) line],+ };+ fake.routes[commands] = (_) => {'result': <String, dynamic>{}};+ return fake;+ }++ /// An upload answered at once.+ Future<Map<String, dynamic>> uploaded({+ required String tabId,+ required String conversationId,+ required String name,+ required String mime,+ required SwarmOutgoingFile file,+ required dynamic cancel,+ required void Function(double sent) onProgress,+ }) async => {+ 'attachment': {+ 'id': 'f-$name',+ 'name': name,+ 'mime': mime,+ 'size': 12,+ 'url': 'https://cdn.harness.autonomous.ai/f/$name',+ },+ };++ final picker = (documents: pickSwarmFiles, copies: swarmPickerCopyFolders);+ setUp(() {+ swarmPickerCopyFolders = () async => const [];+ pickSwarmFiles = () async => [+ XFile.fromData(Uint8List(12), path: '/copies/crash.log', length: 12),+ ];+ });+ tearDown(() {+ swarmPickerCopyFolders = picker.copies;+ pickSwarmFiles = picker.documents;+ });++ /// A [width] x [height] phone, with a keyboard [keyboard] tall up.+ void phone(+ WidgetTester tester, {+ double width = 393,+ double height = 852,+ double keyboard = 0,+ }) {+ tester.view.devicePixelRatio = 3;+ tester.view.physicalSize = Size(width * 3, height * 3);+ tester.view.padding = FakeViewPadding(+ top: 59 * 3,+ bottom: keyboard > 0 ? 0 : 34 * 3,+ );+ tester.view.viewPadding = const FakeViewPadding(+ top: 59 * 3,+ bottom: 34 * 3,+ );+ tester.view.viewInsets = FakeViewPadding(bottom: keyboard * 3);+ addTearDown(tester.view.reset);+ }++ /// Chat g1 on screen; with [shell], under an outer Scaffold as the phone's+ /// shell puts every page (it takes the keyboard's inset out for its body).+ late ValueNotifier<String?> account;++ /// The microphone and the transcriber of the last [pump] with a voice.+ late FakeVoiceRecorder recorder;+ late FakeTranscriber stt;++ Future<SwarmHost> pump(+ WidgetTester tester,+ FakeSwarm fake, {+ bool shell = false,+ bool voice = false,+ SwarmUpload upload = refuseSwarmUpload,+ }) async {+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ account = ValueNotifier<String?>(me);+ recorder = FakeVoiceRecorder();+ stt = FakeTranscriber();+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: fake.request,+ upload: upload,+ notices: SilentSystemNotices(),+ features: features,+ readMarks: MemoryKeyValueStore(),+ voice: voice+ ? () => VoiceInputController(+ transcriber: stt.call,+ recorder: recorder,+ language: ValueNotifier('en'),+ )+ : null,+ )..foreground = false;+ addTearDown(host.dispose);+ const page = SwarmConversationPage(swarmId: tab, conversationId: 'g1');+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ builder: (context, child) => SwarmScope(notifier: host, child: child!),+ home: shell ? const Scaffold(body: page) : page,+ ),+ );+ await tester.pumpAndSettle();+ return host;+ }++ Finder key(String value) => find.byKey(ValueKey(value));+ TextEditingController field(+ WidgetTester tester, [+ String at = 'swarm-field',+ ]) => tester+ .widget<TextField>(+ find.descendant(of: key(at), matching: find.byType(TextField)),+ )+ .controller!;+ bool focused(WidgetTester tester, [String at = 'swarm-field']) => tester+ .widget<TextField>(+ find.descendant(of: key(at), matching: find.byType(TextField)),+ )+ .focusNode!+ .hasFocus;+ bool sendable(WidgetTester tester, [String send = 'swarm-send']) =>+ tester.widget<SwarmRoundButton>(key(send)).onTap != null;++ /// [text] typed into the field at [at]: focused as the keyboard would be,+ /// with no tap, so no selection handle is left over the toolbar.+ Future<void> type(+ WidgetTester tester,+ String text, [+ String at = 'swarm-field',+ ]) async {+ final input = find.descendant(+ of: key(at),+ matching: find.byType(TextField),+ );+ tester.widget<TextField>(input).focusNode!.requestFocus();+ await tester.pump();+ tester.testTextInput.enterText(text);+ await tester.pump();+ // The test keyboard leaves a caret handle over the toolbar (main does the+ // same); typing on a phone does not. Hidden, so taps reach the chips.+ tester.state<EditableTextState>(find.byType(EditableText)).hideToolbar();+ await tester.pump();+ }++ group('X on the chat', () {+ testWidgets('hidden while the box is empty; shows on the first '+ 'character, a space included', (tester) async {+ await pump(tester, backend([message('m1', 1)]));++ expect(key('swarm-field-clear'), findsNothing);+ await type(tester, ' ');+ expect(key('swarm-field-clear'), findsOneWidget);+ expect(tester.getSemantics(key('swarm-field-clear')).label, 'Clear text');+ });++ testWidgets('clears the text only: focus and the keyboard stay, Send goes '+ 'off with nothing left to send', (tester) async {+ final fake = backend([message('m1', 1)]);+ await pump(tester, fake);+ await type(tester, 'Ship it');+ expect(sendable(tester), isTrue);++ await tester.tap(key('swarm-field-clear'));+ await tester.pump();++ expect(field(tester).text, '');+ expect(key('swarm-field-clear'), findsNothing);+ expect(focused(tester), isTrue);+ expect(tester.testTextInput.isVisible, isTrue);+ expect(sendable(tester), isFalse);+ expect(fake.commands, isEmpty);+ });++ testWidgets('the reply and the files stay, and Send stays on for the '+ 'files', (tester) async {+ final fake = backend([message('m1', 1)]);+ await pump(tester, fake, upload: uploaded);+ await tester.tap(find.text('Which name for the flag?'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-reply-m1'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach-files'));+ await tester.pumpAndSettle();+ await type(tester, 'The log');++ await tester.tap(key('swarm-field-clear'));+ await tester.pumpAndSettle();++ expect(field(tester).text, '');+ expect(key('swarm-reply-bar'), findsOneWidget);+ expect(key('swarm-outgoing-crash.log'), findsOneWidget);+ expect(sendable(tester), isTrue);+ await tester.tap(key('swarm-send'));+ await tester.pumpAndSettle();+ expect(fake.commands.single['replyTo'], 'm1');+ expect(fake.commands.single['text'], '');+ });++ testWidgets('a mention cleared with the text goes to nobody', (+ tester,+ ) async {+ final fake = backend([message('m1', 1)]);+ await pump(tester, fake);+ await type(tester, 'ask @N');+ await tester.tap(key('swarm-pick-agent-builder'));+ await tester.pump();+ expect(field(tester).text, 'ask @Nova ');++ await tester.tap(key('swarm-field-clear'));+ await tester.pump();+ await type(tester, 'ship it');+ await tester.tap(key('swarm-send'));+ await tester.pumpAndSettle();++ expect(fake.commands.single['text'], 'ship it');+ expect(fake.commands.single['recipientIds'], anyOf(isNull, isEmpty));+ });++ testWidgets('clearing while a Telex word is still being composed leaves '+ 'no stray characters', (tester) async {+ await pump(tester, backend([message('m1', 1)]));+ await tester.showKeyboard(key('swarm-field'));+ // The keyboard composing "Viêt": its marked text still open.+ tester.testTextInput.updateEditingValue(+ const TextEditingValue(+ text: 'Kiểm tra Viêt',+ selection: TextSelection.collapsed(offset: 13),+ composing: TextRange(start: 9, end: 13),+ ),+ );+ await tester.pump();++ await tester.tap(key('swarm-field-clear'));+ await tester.pump();++ expect(field(tester).value.text, '');+ expect(field(tester).value.composing, TextRange.empty);+ expect(tester.testTextInput.editingState?['text'], '');+ });++ testWidgets('stays pinned at the top right while the text scrolls', (+ tester,+ ) async {+ phone(tester);+ await pump(tester, backend([message('m1', 1)]));+ await type(tester, 'one');+ final field = tester.getRect(key('swarm-field'));+ final x = tester.getRect(key('swarm-field-clear'));+ expect(x.top - field.top, 1);+ expect(field.right - x.right, 0);++ await type(tester, List.generate(9, (i) => 'line $i').join('\n'));+ final tall = tester.getRect(key('swarm-field'));+ // Five lines of 22 and the field's 14 of padding, then it scrolls.+ expect(tall.height, 5 * 22 + 14);+ expect(tester.getRect(key('swarm-field-clear')).top - tall.top, 1);+ expect(tester.getRect(key('swarm-field-clear')).right, tall.right);+ });+ });++ group('@ Tag on the chat', () {+ testWidgets('on an empty box: an @ that opens the picker, focus in the '+ 'field; a second tap takes it back and closes it', (tester) async {+ await pump(tester, backend([message('m1', 1)]));+ expect(key('swarm-tag'), findsOneWidget);+ expect(+ tester.getSemantics(key('swarm-tag')).label,+ 'Tag a member or agent',+ );++ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, '@');+ expect(key('swarm-mention-picker'), findsOneWidget);+ expect(focused(tester), isTrue);+ expect(field(tester).selection, const TextSelection.collapsed(offset: 1));+ // In the accent while the picker is open.+ expect(+ tester+ .widget<Icon>(+ find.descendant(+ of: key('swarm-tag'),+ matching: find.byIcon(LucideIcons.atSign),+ ),+ )+ .color,+ AppPalette.accentOnSurface,+ );++ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, '');+ expect(key('swarm-mention-picker'), findsNothing);+ expect(+ tester+ .widget<Icon>(+ find.descendant(+ of: key('swarm-tag'),+ matching: find.byIcon(LucideIcons.atSign),+ ),+ )+ .color,+ AppPalette.textSecondary,+ );+ });++ testWidgets('after words, a space before the @; after a space, none', (+ tester,+ ) async {+ await pump(tester, backend([message('m1', 1)]));+ await type(tester, 'ask');+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, 'ask @');++ await type(tester, 'ask ');+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, 'ask @');++ await type(tester, 'ask\n');+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, 'ask\n@');+ });++ testWidgets('a name being typed is left alone', (tester) async {+ await pump(tester, backend([message('m1', 1)]));+ await type(tester, 'ask @No');+ expect(key('swarm-mention-picker'), findsOneWidget);++ await tester.tap(key('swarm-tag'));+ await tester.pump();++ expect(field(tester).text, 'ask @No');+ expect(key('swarm-mention-picker'), findsOneWidget);+ });++ testWidgets('a pick fills the name in, and the post goes to them', (+ tester,+ ) async {+ final fake = backend([message('m1', 1)]);+ await pump(tester, fake);+ await type(tester, 'ask');+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ await tester.tap(key('swarm-pick-agent-builder'));+ await tester.pump();+ expect(field(tester).text, 'ask @Nova ');+ expect(key('swarm-mention-picker'), findsNothing);++ await type(tester, 'ask @Nova to look');+ await tester.tap(key('swarm-send'));+ await tester.pumpAndSettle();+ expect(fake.commands.single['recipientIds'], ['agent-builder']);+ });++ testWidgets('typing an @ opens the same picker, and Tag then takes it '+ 'back', (tester) async {+ await pump(tester, backend([message('m1', 1)]));+ await type(tester, 'ask @');+ expect(key('swarm-mention-picker'), findsOneWidget);++ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(field(tester).text, 'ask ');+ expect(key('swarm-mention-picker'), findsNothing);+ });++ testWidgets('no chip when nobody can be tagged', (tester) async {+ await pump(tester, backend([message('m1', 1)], agentIds: const []));++ expect(key('swarm-field'), findsOneWidget);+ expect(key('swarm-tag'), findsNothing);+ });++ testWidgets('a person alone in the chat is enough for the chip', (+ tester,+ ) async {+ await pump(+ tester,+ backend(+ [message('m1', 1)],+ agentIds: const [],+ members: [+ person(me),+ person('dee', role: 'collaborator'),+ ],+ ),+ );++ expect(key('swarm-tag'), findsOneWidget);+ });+ });++ group('card layout', () {+ testWidgets('one line is a 98pt composer: an 86pt card, text over '+ '+, Tag, the mic and Send, all 44pt targets with 36pt faces', (+ tester,+ ) async {+ phone(tester);+ await pump(tester, backend([message('m1', 1)]));++ expect(tester.getSize(key('swarm-composer-card')).height, 86);+ expect(tester.getSize(key('swarm-field')).height, 36);+ for (final button in ['swarm-attach', 'swarm-send']) {+ expect(tester.getSize(key(button)), const Size(44, 44));+ }+ expect(tester.getSize(key('swarm-tag')).height, 44);+ final card = tester.getRect(key('swarm-composer-card'));+ final send = tester.getRect(key('swarm-send'));+ final attach = tester.getRect(key('swarm-attach'));+ final tag = tester.getRect(key('swarm-tag'));+ // The toolbar: + then Tag at the left, Send at the right, 4 from the foot.+ expect(attach.left - card.left, 1 + 6);+ expect(tag.left, attach.right);+ expect(card.right - send.right, 1 + 6);+ expect(card.bottom - send.bottom, 1 + 4);+ // 8 at the sides, 6 above and below: no hairline, no band of its own.+ expect(card.left, 8);+ expect(tester.view.physicalSize.width / 3 - card.right, 8);+ });++ for (final shell in [false, true]) {+ testWidgets('with the keyboard up the card sits on it, the inset taken '+ 'once${shell ? ' under the phone shell\'s Scaffold' : ''}', (+ tester,+ ) async {+ phone(tester, keyboard: 336);+ await pump(tester, backend([message('m1', 1)]), shell: shell);+ await tester.showKeyboard(key('swarm-field'));+ await tester.pump();++ final card = tester.getRect(key('swarm-composer-card'));+ expect(card.bottom, 852 - 336 - 6);+ expect(card.height, 86);+ });+ }++ testWidgets('a 320pt phone with the keyboard up: five lines, files, a '+ 'reply and the toolbar fit', (tester) async {+ phone(tester, width: 320, height: 568, keyboard: 253);+ await pump(tester, backend([message('m1', 1)]), upload: uploaded);+ await tester.tap(find.text('Which name for the flag?'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-reply-m1'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach-files'));+ await tester.pumpAndSettle();+ await type(tester, List.generate(6, (i) => 'line $i').join('\n'));+ await tester.pumpAndSettle();++ expect(tester.takeException(), isNull);+ final card = tester.getRect(key('swarm-composer-card'));+ expect(card.bottom, 568 - 253 - 6);+ expect(card.right, lessThanOrEqualTo(320 - 8));+ expect(tester.getRect(key('swarm-send')).right, lessThan(card.right));+ expect(+ tester.getRect(key('swarm-reply-bar')).bottom,+ lessThanOrEqualTo(card.top),+ );+ });+ });++ group('the thread\'s reply box', () {+ Future<void> openThread(WidgetTester tester, FakeSwarm fake) async {+ await pump(tester, fake, upload: uploaded);+ await tester.tap(key('swarm-thread-line-m1'));+ await tester.pumpAndSettle();+ }++ FakeSwarm threaded() => backend([+ message('m1', 1, author: 'agent-lead', thread: 'm1'),+ message('m2', 2, text: 'Looks good.', thread: 'm1', replyTo: 'm1'),+ ], threads: true);++ testWidgets('the same card: + at the left, then Also send, the mic and '+ 'Send; no Tag', (tester) async {+ phone(tester);+ await openThread(tester, threaded());++ expect(+ find.descendant(+ of: key('swarm-thread-box'),+ matching: key('swarm-composer-card'),+ ),+ findsOneWidget,+ );+ expect(key('swarm-tag'), findsNothing);+ final attach = tester.getRect(key('swarm-thread-attach'));+ final also = tester.getRect(key('swarm-thread-also-send'));+ final send = tester.getRect(key('swarm-thread-send'));+ expect(attach.right, lessThanOrEqualTo(also.left));+ expect(also.right, lessThanOrEqualTo(send.left));+ });++ testWidgets('its X clears the text only: the files stay, Send stays on '+ 'for them, focus stays', (tester) async {+ await openThread(tester, threaded());+ expect(key('swarm-thread-clear'), findsNothing);+ await tester.tap(key('swarm-thread-attach'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach-files'));+ await tester.pumpAndSettle();+ await type(tester, 'The log', 'swarm-thread-field');+ expect(key('swarm-thread-clear'), findsOneWidget);++ await tester.tap(key('swarm-thread-clear'));+ await tester.pump();++ expect(field(tester, 'swarm-thread-field').text, '');+ expect(key('swarm-thread-clear'), findsNothing);+ expect(key('swarm-outgoing-crash.log'), findsOneWidget);+ expect(focused(tester, 'swarm-thread-field'), isTrue);+ expect(sendable(tester, 'swarm-thread-send'), isTrue);+ });++ testWidgets('a 320pt phone: the toolbar fits a long Also send label', (+ tester,+ ) async {+ phone(tester, width: 320, height: 568, keyboard: 253);+ tester.platformDispatcher.textScaleFactorTestValue = 1.3;+ addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);+ await openThread(tester, threaded());+ await type(tester, 'one more', 'swarm-thread-field');+ await tester.pumpAndSettle();++ expect(tester.takeException(), isNull);+ final card = tester.getRect(key('swarm-composer-card'));+ expect(+ tester.getRect(key('swarm-thread-send')).right,+ lessThan(card.right),+ );+ });+ });++ group('access lost on the chat', () {+ const refused = SuperTabFailure('FORBIDDEN', 'Not yours.', statusCode: 403);++ /// The Swarm read again: refused, or with the person a [role].+ Future<void> reread(+ WidgetTester tester,+ SwarmHost host,+ FakeSwarm fake, {+ bool lost = false,+ String? role,+ }) async {+ if (lost) {+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => throw refused;+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => throw refused;+ } else {+ final parts = fake.routes['/api/super-tabs/$tab/parts']!;+ fake.routes['/api/super-tabs/$tab/parts'] = (body) => {+ ...(parts(body) as Map<String, dynamic>),+ 'members': [part(me, 2, person(me, role: role!))],+ };+ // The changes say read it all again.+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => {'reload': true};+ }+ await host.session!.inbox.reader(tab)!.refresh();+ for (var i = 0; i < 5; i++) {+ await tester.pump();+ }+ }++ testWidgets('signed out mid-take: the microphone closes, and nothing is '+ 'transcribed or kept', (tester) async {+ await pump(tester, backend([message('m1', 1)]), voice: true);+ stt.replies.add('after sign out');+ await tester.tap(key('swarm-mic'));+ await tester.pump();+ await tester.pump();+ expect(recorder.recording, isTrue);++ account.value = null;+ for (var i = 0; i < 5; i++) {+ await tester.pump();+ }++ expect(recorder.recording, isFalse);+ expect(stt.calls, isEmpty);+ expect(find.text('after sign out'), findsNothing);+ });++ testWidgets('made read-only mid-take: the take goes with the composer', (+ tester,+ ) async {+ final fake = backend([message('m1', 1)]);+ final host = await pump(tester, fake, voice: true);+ await tester.tap(key('swarm-mic'));+ await tester.pump();+ await tester.pump();+ expect(recorder.recording, isTrue);++ await reread(tester, host, fake, role: 'viewer');++ expect(key('swarm-composer-card'), findsNothing);+ expect(key('swarm-read-only'), findsOneWidget);+ expect(recorder.recording, isFalse);+ expect(stt.calls, isEmpty);+ });++ testWidgets('words transcribed after the Swarm was lost land nowhere', (+ tester,+ ) async {+ final fake = backend([message('m1', 1)]);+ final host = await pump(tester, fake, voice: true);+ stt.pending = Completer<String>();+ await tester.tap(key('swarm-mic'));+ await tester.pump();+ await tester.pump();+ await tester.tap(key('swarm-voice-stop'));+ await tester.pump();+ expect(stt.calls, hasLength(1), reason: 'the take is being transcribed');++ await reread(tester, host, fake, lost: true);+ stt.pending!.complete('too late');+ await tester.pumpAndSettle();++ expect(find.text('too late'), findsNothing);+ expect(fake.commands, isEmpty);+ });++ testWidgets('the Swarm lost with the picker Tag opened: no picker, no '+ 'chip, no name', (tester) async {+ final fake = backend(+ [message('m1', 1)],+ members: [+ person(me),+ person('dee', role: 'collaborator'),+ ],+ );+ final host = await pump(tester, fake);+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(key('swarm-mention-picker'), findsOneWidget);++ await reread(tester, host, fake, lost: true);+ await tester.pumpAndSettle();++ expect(key('swarm-mention-picker'), findsNothing);+ expect(key('swarm-tag'), findsNothing);+ for (final name in ['dee', 'River', 'Nova']) {+ expect(find.textContaining(name), findsNothing, reason: name);+ }+ });++ testWidgets('signed out with the picker Tag opened: no picker, no chip', (+ tester,+ ) async {+ await pump(tester, backend([message('m1', 1)]));+ await tester.tap(key('swarm-tag'));+ await tester.pump();+ expect(key('swarm-mention-picker'), findsOneWidget);++ account.value = null;+ await tester.pumpAndSettle();++ expect(key('swarm-mention-picker'), findsNothing);+ expect(key('swarm-tag'), findsNothing);+ expect(find.textContaining('River'), findsNothing);+ });+ });+}diff --git a/mobile/test/swarm/swarm_new_message_test.dart b/mobile/test/swarm/swarm_new_message_test.dartindex d716ac9d5..e330a36ae 100644--- a/mobile/test/swarm/swarm_new_message_test.dart+++ b/mobile/test/swarm/swarm_new_message_test.dart@@ -823,9 +823,79 @@ void main() {expect(sheetOpen(), isFalse);});- testWidgets('the mic writes into the box, and its second tap sends to '- 'the chat picked', (tester) async {- final dictation = _Dictation();+ testWidgets('its X clears the text only: hidden while empty, the files '+ 'stay with Send on for them, focus stays, and no Tag', (tester) async {+ final fake = backend();+ pickSwarmFiles = () async => [+ XFile.fromData(+ Uint8List.fromList([1, 2, 3]),+ name: 'build.log',+ path: '/copies/build.log',+ ),+ ];+ await pump(tester, fake, upload: FakeUploads().upload);+ await open(tester);+ await tester.tap(row(webLead));+ await tester.pump();+ expect(key('swarm-tag'), findsNothing, reason: 'no @ picker here');+ expect(key('swarm-new-message-clear'), findsNothing);+ await tester.tap(key('swarm-new-message-attach'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-attach-files'));+ await tester.pumpAndSettle();+ await write(tester, 'The log');+ expect(key('swarm-new-message-clear'), findsOneWidget);++ await tester.tap(key('swarm-new-message-clear'));+ await tester.pump();++ expect(field(tester), '');+ expect(key('swarm-new-message-clear'), findsNothing);+ expect(key('swarm-outgoing-build.log'), findsOneWidget);+ expect(+ tester+ .widget<TextField>(+ inside(key('swarm-new-message-field'), find.byType(TextField)),+ )+ .focusNode!+ .hasFocus,+ isTrue,+ );+ expect(+ tester.widget<SwarmRoundButton>(key('swarm-new-message-send')).onTap,+ isNotNull,+ );+ expect(sends(fake), isEmpty);+ });++ testWidgets('while a message is on its way its X takes no touch, as the '+ 'field does', (tester) async {+ final fake = backend();+ final take = fake.routes['/api/super-tabs/$tab/commands']!;+ final answer = Completer<void>();+ fake.routes['/api/super-tabs/$tab/commands'] = (body) async {+ await answer.future;+ return take(body);+ };+ await pump(tester, fake);+ await open(tester);+ await tester.tap(row(webLead));+ await write(tester, 'Ship it tonight');+ await tester.tap(key('swarm-new-message-send'));+ await tester.pump();+ expect(key('swarm-new-message-sending'), findsOneWidget);++ await tester.tap(key('swarm-new-message-clear'), warnIfMissed: false);+ await tester.pump();++ expect(field(tester), 'Ship it tonight');+ answer.complete();+ await tester.pumpAndSettle();+ expect(sends(fake).single['command']['text'], 'Ship it tonight');+ });++ /// The sheet open on the Lead's chat, its mic heard by [dictation].+ Future<FakeSwarm> talking(WidgetTester tester, _Dictation dictation) async {final fake = backend();await pump(tester,@@ -840,26 +910,67 @@ void main() {await open(tester);await tester.tap(row(leadChat));await tester.pump();+ return fake;+ }- await tester.tap(- inside(find.byType(SwarmNewMessageSheet), key('swarm-mic')),- );+ Finder inSheet(String value) =>+ inside(find.byType(SwarmNewMessageSheet), key(value));++ Future<void> tapIn(WidgetTester tester, String value) async {+ await tester.tap(inSheet(value));for (var i = 0; i < 5; i++) {await tester.pump();}+ }++ testWidgets('the mic writes into the box; stop keeps the words and sends '+ 'nothing, and Send then sends to the chat picked', (tester) async {+ final dictation = _Dictation();+ final fake = await talking(tester, dictation);++ await tapIn(tester, 'swarm-mic');dictation.say('Mai họp lúc 9 giờ');await tester.pump();expect(field(tester), 'Mai họp lúc 9 giờ');+ expect(inSheet('swarm-new-message-send'), findsNothing);+ expect(inSheet('swarm-new-message-attach'), findsNothing);+ expect(inSheet('swarm-new-message-clear'), findsNothing);+ expect(inSheet('swarm-voice-stop'), findsOneWidget);- await tester.tap(- inside(find.byType(SwarmNewMessageSheet), key('swarm-mic')),- );+ await tapIn(tester, 'swarm-voice-stop');+ await tester.pumpAndSettle();+ expect(sends(fake), isEmpty, reason: 'voice never sends by itself');+ expect(field(tester), 'Mai họp lúc 9 giờ');+ expect(sheetOpen(), isTrue);+ expect(inSheet('swarm-new-message-send'), findsOneWidget);+ expect(inSheet('swarm-new-message-clear'), findsOneWidget);++ await tester.tap(inSheet('swarm-new-message-send'));await tester.pumpAndSettle();expect(sends(fake).single['command']['text'], 'Mai họp lúc 9 giờ');expect(sends(fake).single['command']['conversationId'], leadChat);expect(sheetOpen(), isFalse);});+ testWidgets('cancel takes back what the take added and keeps what was '+ 'typed before it', (tester) async {+ final dictation = _Dictation();+ final fake = await talking(tester, dictation);+ await write(tester, 'Ghi chú:');++ await tapIn(tester, 'swarm-mic');+ dictation.say('bỏ câu này');+ await tester.pump();+ expect(field(tester), 'Ghi chú: bỏ câu này');++ await tapIn(tester, 'swarm-voice-cancel');+ await tester.pumpAndSettle();+ expect(field(tester), 'Ghi chú:');+ expect(sends(fake), isEmpty);+ expect(inSheet('swarm-mic'), findsOneWidget);+ expect(inSheet('swarm-new-message-send'), findsOneWidget);+ });+testWidgets('taken while Home is out of sight, it opens nothing, and the ''chat is read through the post, as posting in it reads it: Home ''shows no news of what the person wrote', (tester) async {diff --git a/mobile/test/swarm/swarm_thread_voice_test.dart b/mobile/test/swarm/swarm_thread_voice_test.dartindex a4458447b..b88af50d2 100644--- a/mobile/test/swarm/swarm_thread_voice_test.dart+++ b/mobile/test/swarm/swarm_thread_voice_test.dart@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/notify/system_notices.dart';import 'package:harness_mobile/phone/voice_input_controller.dart';-import 'package:harness_mobile/phone/voice_mic_face.dart';import 'package:harness_mobile/settings/experimental_features.dart';import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;import 'package:harness_mobile/swarm/swarm_conversation_page.dart';@@ -17,10 +16,11 @@ import 'swarm_fixture.dart';/// Talking instead of typing in a thread (Dee, 11-01: "how do I voice in a/// thread?"): the main chat's mic, in the thread's reply box beside Send. Tap-/// to talk, tap again and the box goes as a reply — to the chat too with Also-/// send. A take goes, nothing of it written or sent, once the person can no-/// longer reply there. The mic itself: `swarm_chat_voice_test` and-/// `swarm_chat_dictation_test`.+/// to talk; while talking the toolbar is cancel, the wave and stop. Voice never+/// sends by itself (Tony, 11-01): stop leaves the words in the box, and Send+/// posts them as a reply — to the chat too with Also send. A take goes,+/// nothing of it written or sent, once the person can no longer reply there.+/// The mic itself: `swarm_chat_voice_test` and `swarm_chat_dictation_test`.void main() {const messages = '/api/super-tabs/$tab/conversations/g1/messages';const commands = '/api/super-tabs/$tab/commands';@@ -163,6 +163,18 @@ void main() {await frames(tester);}+ /// The voice row's stop: the take ends, its words left in the box.+ Future<void> stop(WidgetTester tester) async {+ await tester.tap(inBox(key('swarm-voice-stop')));+ await frames(tester);+ }++ /// The voice row's cancel: what the take added leaves the box.+ Future<void> cancel(WidgetTester tester) async {+ await tester.tap(inBox(key('swarm-voice-cancel')));+ await frames(tester);+ }+String box(WidgetTester tester) => tester.widget<TextField>(find.descendant(@@ -192,17 +204,21 @@ void main() {await frames(tester);}- testWidgets('the thread\'s reply box has the main chat\'s mic, just left of '- 'Send', (tester) async {+ testWidgets('the thread\'s reply box: +, Also send, then the main chat\'s '+ 'mic just left of Send, in one row', (tester) async {await pump(tester);expect(inBox(key('swarm-mic')), findsOneWidget);final mic = tester.getCenter(inBox(key('swarm-mic')));final send = tester.getCenter(key('swarm-thread-send'));final attach = tester.getCenter(key('swarm-thread-attach'));- expect(mic.dy, send.dy, reason: 'in Send\'s row');+ final also = tester.getCenter(key('swarm-thread-also-send'));+ for (final other in [send, attach, also]) {+ expect(mic.dy, other.dy, reason: 'in one row');+ }+ expect(attach.dx, lessThan(also.dx), reason: '+ moved to the left');+ expect(also.dx, lessThan(mic.dx));expect(mic.dx, lessThan(send.dx));- expect(mic.dx, greaterThan(attach.dx));});testWidgets('with no voice input the reply box has no mic', (tester) async {@@ -212,22 +228,28 @@ void main() {expect(key('swarm-thread-send'), findsOneWidget);});- testWidgets('a second tap sends what was said as a reply in the thread, '- 'not to the chat', (tester) async {+ testWidgets('stop leaves what was said in the reply box and sends nothing; '+ 'Send then posts it as a reply in the thread, not to the chat', (+ tester,+ ) async {await pump(tester);stt.replies.add('ship the fix today');await tapMic(tester);expect(recorder.recording, isTrue);- expect(- tester.widget<VoiceMicCore>(find.byType(VoiceMicCore)).face,- VoiceMicFace.listening,- );+ expect(inBox(key('swarm-voice-stop')), findsOneWidget);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(recorder.recording, isFalse);+ expect(fake.commands, isEmpty, reason: 'voice never sends by itself');+ expect(box(tester), 'ship the fix today');+ expect(inBox(key('swarm-voice-stop')), findsNothing);++ await tester.tap(key('swarm-thread-send'));+ await tester.pumpAndSettle();+expect(fake.commands.single, {'type': 'message.send','conversationId': 'g1',@@ -245,23 +267,40 @@ void main() {stt.replies.add('ship the fix');await tapMic(tester);- await tapMic(tester);+ await stop(tester);+ await tester.pumpAndSettle();+ expect(box(tester), 'Nova: ship the fix');+ expect(fake.commands, isEmpty);++ await tester.tap(key('swarm-thread-send'));await tester.pumpAndSettle();expect(fake.commands.single['text'], 'Nova: ship the fix');expect(fake.commands.single['replyTo'], 'm1');});- testWidgets('with Also send ticked, a take goes to the chat too', (- tester,- ) async {+ testWidgets('Also send ticked, a take, stop, then Send posts to the chat '+ 'too: the tick survives the take', (tester) async {await pump(tester);await tester.tap(key('swarm-thread-also-send'));await tester.pump();stt.replies.add('also for everyone');await tapMic(tester);- await tapMic(tester);+ expect(key('swarm-thread-also-send'), findsNothing, reason: 'hidden');+ await stop(tester);+ await tester.pumpAndSettle();+ expect(fake.commands, isEmpty);+ expect(+ tester+ .widget<Semantics>(key('swarm-thread-also-send'))+ .properties+ .checked,+ isTrue,+ reason: 'still ticked after the take',+ );++ await tester.tap(key('swarm-thread-send'));await tester.pumpAndSettle();expect(fake.commands.single['text'], 'also for everyone');@@ -269,11 +308,11 @@ void main() {expect(fake.commands.single['alsoSend'], isTrue);});- // After #2471 a reply on its way no longer holds the box: a take that ends- // meanwhile goes as the next reply, as Send would, and the first keeps its- // own text.- testWidgets('a take ending while a reply is still on its way goes as the '- 'next reply, in order', (tester) async {+ // After #2471 a reply on its way no longer holds the box: a take stopped+ // meanwhile leaves its words for the next reply, which Send posts after the+ // first, and the first keeps its own text.+ testWidgets('a take stopped while a reply is still on its way: Send posts '+ 'it as the next reply, in order', (tester) async {await pump(tester);final first = Completer<Object?>();fake.routes[commands] = (_) =>@@ -287,7 +326,11 @@ void main() {stt.replies.add('spoken reply');await tapMic(tester);- await tapMic(tester);+ await stop(tester);+ await frames(tester);+ expect(box(tester), 'spoken reply');+ expect(fake.commands, hasLength(1), reason: 'stop sends nothing');+ await tester.tap(key('swarm-thread-send'));await frames(tester);first.complete({'result': <String, dynamic>{}});await tester.pumpAndSettle();@@ -305,13 +348,96 @@ void main() {await pump(tester);await tapMic(tester);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(fake.commands, isEmpty);expect(inBox(key('swarm-thread-voice-note')), findsOneWidget);});+ testWidgets('during a take the toolbar is cancel, the wave and stop: no '+ 'Send, Also send, + or X, which come back after stop', (tester) async {+ await pump(tester);+ await tester.enterText(key('swarm-thread-field'), 'Nova:');+ await tester.pump();+ expect(inBox(key('swarm-thread-clear')), findsOneWidget);+ stt.replies.add('ship it');++ await tapMic(tester);++ for (final gone in [+ 'swarm-thread-send',+ 'swarm-thread-also-send',+ 'swarm-thread-attach',+ 'swarm-thread-clear',+ 'swarm-mic',+ ]) {+ expect(inBox(key(gone)), findsNothing, reason: gone);+ }+ for (final shown in [+ 'swarm-voice-cancel',+ 'swarm-voice-wave',+ 'swarm-voice-stop',+ ]) {+ expect(inBox(key(shown)), findsOneWidget, reason: shown);+ }++ await stop(tester);+ await tester.pumpAndSettle();++ for (final back in [+ 'swarm-thread-send',+ 'swarm-thread-also-send',+ 'swarm-thread-attach',+ 'swarm-thread-clear',+ 'swarm-mic',+ ]) {+ expect(inBox(key(back)), findsOneWidget, reason: back);+ }+ expect(inBox(key('swarm-voice-stop')), findsNothing);+ expect(fake.commands, isEmpty);+ });++ testWidgets('cancel throws the take away: nothing transcribed, the box as '+ 'it was before, nothing sent', (tester) async {+ await pump(tester);+ await tester.enterText(key('swarm-thread-field'), 'Nova:');+ await tester.pump();+ stt.replies.add('never said');++ await tapMic(tester);+ expect(recorder.recording, isTrue);+ await cancel(tester);+ await tester.pumpAndSettle();++ expect(recorder.recording, isFalse);+ expect(recorder.cancels, 1);+ expect(stt.calls, isEmpty, reason: 'nothing leaves the phone');+ expect(box(tester), 'Nova:');+ expect(fake.commands, isEmpty);+ expect(inBox(key('swarm-mic')), findsOneWidget);+ });++ testWidgets('cancel while the take is transcribed puts nothing in the box', (+ tester,+ ) async {+ await pump(tester);+ stt.pending = Completer<String>();+ await tapMic(tester);+ await stop(tester);+ expect(stt.calls, hasLength(1), reason: 'the take is being transcribed');+ expect(inBox(key('swarm-voice-stop')), findsNothing, reason: 'busy');+ expect(inBox(key('swarm-voice-cancel')), findsOneWidget);++ await cancel(tester);+ stt.pending!.complete('too late');+ await tester.pumpAndSettle();++ expect(box(tester), isEmpty);+ expect(fake.commands, isEmpty);+ expect(inBox(key('swarm-mic')), findsOneWidget);+ });+testWidgets('taken out of the chat mid-take: the microphone closes, and ''nothing is transcribed, written or sent', (tester) async {final host = await pump(tester);@@ -336,7 +462,7 @@ void main() {final host = await pump(tester);stt.pending = Completer<String>();await tapMic(tester);- await tapMic(tester);+ await stop(tester);expect(stt.calls, hasLength(1), reason: 'the take is being transcribed');await reread(tester, host, listed: false);@@ -437,8 +563,10 @@ void main() {late FakeDictation dictation;setUp(() => dictation = FakeDictation());- testWidgets('words show in the reply box as they are said; the second '- 'tap sends them as a reply', (tester) async {+ testWidgets('words show in the reply box as they are said; stop keeps '+ 'them and sends nothing, and Send posts them as a reply', (+ tester,+ ) async {await pump(tester, dictation: dictation);await tapMic(tester);@@ -447,15 +575,41 @@ void main() {expect(box(tester), 'looks good to me');expect(fake.commands, isEmpty);- await tapMic(tester);+ await stop(tester);await tester.pumpAndSettle();expect(dictation.stops, 1);+ expect(box(tester), 'looks good to me');+ expect(fake.commands, isEmpty, reason: 'voice never sends by itself');++ await tester.tap(key('swarm-thread-send'));+ await tester.pumpAndSettle();+expect(fake.commands.single['text'], 'looks good to me');expect(fake.commands.single['replyTo'], 'm1');expect(box(tester), isEmpty);});+ testWidgets('cancel takes back what the take added and keeps what was '+ 'typed before it', (tester) async {+ await pump(tester, dictation: dictation);+ await tester.enterText(key('swarm-thread-field'), 'Nova:');+ await tester.pump();++ await tapMic(tester);+ dictation.say('scrap that');+ await frames(tester);+ expect(box(tester), 'Nova: scrap that');++ await cancel(tester);+ await tester.pumpAndSettle();++ expect(box(tester), 'Nova:');+ expect(dictation.cancels, 1);+ expect(dictation.listening, isFalse);+ expect(fake.commands, isEmpty);+ });+testWidgets('taken out of the chat while listening: the recognizer stops, ''and what it still says lands nowhere', (tester) async {final host = await pump(tester, dictation: dictation);