The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(desktop): redesign the Share machine form
bitcoinbuilderaa9659bdc52e
diff --git a/desktop/lib/shared/widgets/app_icon_button.dart b/desktop/lib/shared/widgets/app_icon_button.dartindex 7cda7032c..a14e2e6ef 100644--- a/desktop/lib/shared/widgets/app_icon_button.dart+++ b/desktop/lib/shared/widgets/app_icon_button.dart@@ -17,12 +17,16 @@ class AppIconButton extends StatefulWidget {this.hoverFill,this.destructive = false,this.spinning = false,+ this.focusNode,});final IconData icon;final VoidCallback? onPressed;final String? tooltip;+ /// For a form that moves the keys between its controls itself (the picker's editors).+ final FocusNode? focusNode;+/// The glyph turns, and the button stops taking presses.////// For a control whose work the user cannot otherwise see finishing — the@@ -163,6 +167,7 @@ class _AppIconButtonState extends State<AppIconButton>return Semantics(value: widget.spinning ? 'Working' : null,child: IconButton(+ focusNode: widget.focusNode,tooltip: widget.tooltip,onPressed: enabled ? widget.onPressed : null,iconSize: widget.size,diff --git a/desktop/lib/widgets/machine_sharing_form.dart b/desktop/lib/widgets/machine_sharing_form.dartindex 76e2fd2e7..e372dcb7e 100644--- a/desktop/lib/widgets/machine_sharing_form.dart+++ b/desktop/lib/widgets/machine_sharing_form.dart@@ -3,7 +3,9 @@ import 'dart:async';import 'package:flutter/material.dart';import 'package:flutter/services.dart';+import '../shared/theme/app_icons.dart';import '../shared/theme/app_theme.dart' as grid;+import '../shared/widgets/app_icon_button.dart';import '../shortcuts/app_keymap.dart';import '../shortcuts/keymap.dart';import '../state/app_state.dart';@@ -23,10 +25,16 @@ final _emailPattern = RegExp(r"^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$",);+/// One person in the list: an address the owner named, or a colleague who added a domain share.+typedef _Person = ({String email, bool named, bool usingIt});+/// Sharing one of the account's machines with other accounts-/// (docs/plans/2026-10-15-share-machine-plan.md), in the Machines picker's preview like Rename: the-/// addresses it is shared with, and everyone at the owner's domain. The policy lives on the machine-/// itself, so it is read from and written to that machine (`shared_machines`).+/// (docs/plans/2026-10-15-share-machine-plan.md), in the Machines picker's preview like Rename.+///+/// Every change applies as it is made — the domain switch, an address added, one removed (with an+/// Undo) — the way a sharing sheet does, so there is no list typed and then lost for want of a Save.+/// Done closes. The policy lives on the machine itself, so it is read from and written to that+/// machine (`shared_machines`).class MachineSharingForm extends StatefulWidget {const MachineSharingForm({super.key,@@ -51,32 +59,44 @@ class MachineSharingFormState extends State<MachineSharingForm> {final _input = FocusNode(debugLabel: 'Share email');final _buttons = <String, FocusNode>{};final _value = TextEditingController();- bool _loading = true, _busy = false, _error = false;- String? _message;+ bool _loading = true, _busy = false;++ /// Why the sharing could not be read at all; the form offers Retry instead of its controls.+ String? _unavailable;++ /// What is wrong with what was typed, said under the field it was typed in.+ String? _fieldError;++ /// What the last change came to: an error (in error ink) or a quiet confirmation.+ String? _status;+ bool _statusIsError = false;++ /// The address the last removal took off, while its Undo is offered.+ String? _undo;++ /// Something changed while the form was open: Done leaves a summary in the machine's details.+ bool _changed = false;List<String> _emails = [];- List<String> _savedEmails = [];- bool _sameDomain = false, _savedSameDomain = false;+ bool _sameDomain = false;String? _domain;List<Map<String, dynamic>> _members = const [];AppNotifier get app => widget.app;String get _name =>app.stateOf(widget.machineId)?.machine.displayName ?? 'this machine';- bool get _changed =>- _sameDomain != _savedSameDomain ||- _emails.length != _savedEmails.length ||- _emails.any((email) => !_savedEmails.contains(email));bool get _composing =>_value.value.composing.isValid && !_value.value.composing.isCollapsed;@overridevoid initState() {super.initState();+ _value.addListener(_typed);unawaited(_load());}@overridevoid dispose() {+ _value.removeListener(_typed);_scope.dispose();_input.dispose();for (final node in _buttons.values) {@@ -86,180 +106,286 @@ class MachineSharingFormState extends State<MachineSharingForm> {super.dispose();}+ /// Typing clears an error the last change left, and the Share button follows the field.+ void _typed() {+ if (!mounted) return;+ setState(() {+ _fieldError = null;+ });+ }+Future<void> _load() async {+ setState(() {+ _loading = true;+ _unavailable = null;+ });Map<String, dynamic> answer;try {answer = await app.machineSharing(widget.machineId);} catch (error) {answer = {'error': 'UNAVAILABLE',- 'message': 'Could not reach $_name: $error',+ 'message': 'Could not reach $_name. Check that it is online.',};}if (!mounted) return;setState(() {_loading = false;- _show(answer);+ final error = answer['error'];+ if (error != null) {+ _unavailable = error == 'UNSUPPORTED'+ ? 'Update Harness on $_name to share it.'+ : answer['message'] as String? ??+ 'Could not read its sharing ($error).';+ } else {+ _show(answer);+ }});focus();}- /// What the machine answered: its sharing as saved, or why it could not say.+ /// The sharing as the machine holds it now.void _show(Map<String, dynamic> answer) {- _savedEmails = [+ _emails = [for (final email in answer['emails'] as List? ?? const [])if (email is String) email,];- _savedSameDomain = answer['sameDomain'] == true;- _emails = [..._savedEmails];- _sameDomain = _savedSameDomain;+ _sameDomain = answer['sameDomain'] == true;_domain = answer['domain'] as String?;_members = [for (final member in answer['members'] as List? ?? const [])if (member is Map) Map<String, dynamic>.from(member),];- final error = answer['error'];- _error = error != null;- _message = error == null- ? null- : error == 'UNSUPPORTED'- ? 'Update Harness on $_name to share it.'- : answer['message'] as String? ??- 'Could not read its sharing ($error).';+ }++ /// Everyone in the list: the addresses named, in order, then colleagues who added it through the+ /// domain. Whether each uses it now comes from the machine's members.+ List<_Person> get _people {+ bool usingIt(String email) => _members.any(+ (m) => m['email'] == email && ((m['machines'] as num?) ?? 0) > 0,+ );+ return [+ for (final email in _emails)+ (email: email, named: true, usingIt: usingIt(email)),+ for (final member in _members)+ if (member['via'] == 'domain' &&+ member['email'] is String &&+ !_emails.contains(member['email']))+ (+ email: member['email'] as String,+ named: false,+ usingIt: usingIt(member['email'] as String),+ ),+ ];}void focus() {- final target = _busy || _loading ? _scope : _input;+ final target = _loading || _unavailable != null+ ? (_buttons['retry'] ?? _scope)+ : _input;if (target.context != null) {target.requestFocus();} else {WidgetsBinding.instance.addPostFrameCallback((_) {- if (mounted) target.requestFocus();+ if (mounted && target.context != null) target.requestFocus();});}}- /// Every address typed in the field joins the list; false when one is not an address.- bool _addTyped() {- final typed = _value.text- .split(RegExp(r'[\s,;]+'))- .map((email) => email.trim().toLowerCase())- .where((email) => email.isNotEmpty)- .toList();- if (typed.isEmpty) return true;- final bad = typed- .where((email) => !_emailPattern.hasMatch(email))- .firstOrNull;- if (bad != null) {- _say('Not an email address: $bad');- return false;- }- final next = {..._emails, ...typed}.toList();- if (next.length > machineShareEmailsMax) {- _say('Share with up to $machineShareEmailsMax addresses.');- return false;- }+ void _say(String message, {bool error = false, String? undo}) {setState(() {- _emails = next;- _value.clear();- _message = null;+ _status = message;+ _statusIsError = error;+ _undo = undo;});- return true;}- void _say(String message, {bool error = true}) {+ /// Make the machine's sharing [emails] and [sameDomain], at once. While it is written nothing else+ /// can change; a refusal leaves the sharing as it was and says why.+ Future<bool> _apply(+ List<String> emails,+ bool sameDomain, {+ required String done,+ String? undo,+ }) async {+ if (_busy) return false;setState(() {- _message = message;- _error = error;+ _busy = true;+ _status = null;+ _undo = null;});- }-- void _remove(String email) {+ Map<String, dynamic> answer;+ try {+ answer = await app.setMachineSharing(+ widget.machineId,+ emails,+ sameDomain: sameDomain,+ );+ } catch (error) {+ answer = {+ 'error': 'UNAVAILABLE',+ 'message': 'Could not reach $_name. Nothing changed.',+ };+ }+ if (!mounted) return false;+ final error = answer['error'];setState(() {- _emails = [..._emails]..remove(email);- _message = null;+ _busy = false;+ if (error == null) _show(answer);});- focus();+ if (error != null) {+ _say(+ answer['message'] as String? ?? 'Could not share it ($error).',+ error: true,+ );+ return false;+ }+ _changed = true;+ _say(done, undo: undo);+ return true;+ }++ /// Done: closes, and says where the sharing now stands when it changed here.+ void _done() {+ if (!_changed) return widget.onClose(null);+ final people = _emails.length;+ final parts = [+ if (people > 0) people == 1 ? '1 person' : '$people people',+ if (_sameDomain && _domain != null) 'everyone at $_domain',+ ];+ widget.onClose(+ parts.isEmpty ? 'Not shared.' : 'Shared with ${parts.join(' and ')}.',+ );}- Future<void> _save() async {+ /// Every address typed in the field, shared at once.+ Future<void> _add() async {if (_busy || _loading || _composing) return;- if (!_addTyped()) {+ final typed = _value.text+ .split(RegExp(r'[\s,;]+'))+ .map((email) => email.trim().toLowerCase())+ .where((email) => email.isNotEmpty)+ .toList();+ if (typed.isEmpty) {_input.requestFocus();return;}- if (!_changed) {- widget.onClose(null);+ final bad = typed+ .where((email) => !_emailPattern.hasMatch(email))+ .firstOrNull;+ if (bad != null) {+ setState(() => _fieldError = '“$bad” is not an email address.');+ _input.requestFocus();return;}- setState(() {- _busy = true;- _message = null;- });- Map<String, dynamic> answer;- try {- answer = await app.setMachineSharing(- widget.machineId,- _emails,- sameDomain: _sameDomain,+ final fresh = typed.where((email) => !_emails.contains(email)).toSet();+ if (fresh.isEmpty) {+ _value.clear();+ _say(+ typed.length == 1+ ? 'Already shared with ${typed.single}.'+ : 'Already shared with them.',);- } catch (error) {- answer = {- 'error': 'UNAVAILABLE',- 'message': 'Could not reach $_name: $error',- };+ return;}- if (!mounted) return;- if (answer['error'] != null) {- setState(() {- _busy = false;- _error = true;- _message =- answer['message'] as String? ??- 'Could not share it (${answer['error']}).';- });- focus();+ if (_emails.length + fresh.length > machineShareEmailsMax) {+ setState(+ () => _fieldError =+ 'A machine can be shared with up to $machineShareEmailsMax people.',+ );return;}- setState(() => _busy = false);- final emails = (answer['emails'] as List? ?? const []).length;- final domain = answer['sameDomain'] == true- ? answer['domain'] as String?- : null;- widget.onClose(- emails == 0 && domain == null- ? 'Not shared.'- : 'Shared with ${[if (emails > 0) emails == 1 ? '1 person' : '$emails people', if (domain != null) 'everyone at @$domain'].join(' and ')}.',+ final added = await _apply(+ [..._emails, ...fresh],+ _sameDomain,+ done: fresh.length == 1+ ? 'Shared with ${fresh.single}.'+ : 'Shared with ${fresh.length} people.',);+ if (added) _value.clear();+ if (mounted) _input.requestFocus();}- List<({String id, String label, VoidCallback? run})> get _actions => [- if (_domain != null && !_loading)- (- id: 'domain',- label: 'Everyone at @$_domain: ${_sameDomain ? 'On' : 'Off'}',- run: _busy ? null : () => setState(() => _sameDomain = !_sameDomain),- ),- for (final email in _emails)+ Future<void> _remove(String email) async {+ await _apply(+ [..._emails]..remove(email),+ _sameDomain,+ done: 'Stopped sharing with $email.',+ undo: email,+ );+ if (mounted) focus();+ }++ Future<void> _undoRemove() async {+ final email = _undo;+ if (email == null) return;+ await _apply(+ [..._emails, email],+ _sameDomain,+ done: 'Shared with $email again.',+ );+ }++ Future<void> _toggleDomain() async {+ final domain = _domain;+ if (domain == null) return;+ final on = !_sameDomain;+ await _apply(+ _emails,+ on,+ done: on+ ? 'Everyone at $domain can add it now.'+ : 'No longer shared with everyone at $domain.',+ );+ }++ // ── keys ──────────────────────────────────────────────────────────────────────────────────────++ /// The editor's stops after the field, in reading order: Share, each person's remove, Undo, then+ /// Done (or Retry and Done when the sharing could not be read). The domain switch reads before the+ /// field.+ List<({String id, VoidCallback? run})> get _stops {+ if (_loading || _unavailable != null) {+ return [+ if (!_loading) (id: 'retry', run: () => unawaited(_load())),+ (id: 'done', run: _done),+ ];+ }+ return [+ if (_domain != null)+ (id: 'domain', run: _busy ? null : () => unawaited(_toggleDomain())),(- id: 'remove:$email',- label: 'Remove $email',- run: _busy ? null : () => _remove(email),+ id: 'add',+ run: _busy || _value.text.trim().isEmpty+ ? null+ : () => unawaited(_add()),),- (- id: 'save',- label: _busy ? 'Saving…' : 'Save',- run: _busy || _loading ? null : () => unawaited(_save()),- ),- (id: 'cancel', label: 'Cancel', run: () => widget.onClose(null)),- ];+ for (final person in _people)+ if (person.named)+ (+ id: 'remove:${person.email}',+ run: _busy ? null : () => unawaited(_remove(person.email)),+ ),+ if (_undo != null)+ (id: 'undo', run: _busy ? null : () => unawaited(_undoRemove())),+ (id: 'done', run: _done),+ ];+ }- List<FocusNode> get _nodes => [- if (!_loading && !_busy) _input,- for (final action in _actions)- if (action.run != null && _buttons[action.id] != null)- _buttons[action.id]!,- ];+ FocusNode _node(String id) =>+ _buttons.putIfAbsent(id, () => FocusNode(debugLabel: id));++ List<FocusNode> get _nodes {+ final stops = _stops.where((stop) => stop.run != null).toList();+ final field = !_loading && _unavailable == null && !_busy;+ return [+ for (final stop in stops)+ if (stop.id == 'domain') _node(stop.id),+ if (field) _input,+ for (final stop in stops)+ if (stop.id != 'domain') _node(stop.id),+ ];+ }void _move(bool forward) {if (_composing) return;@@ -288,16 +414,14 @@ class MachineSharingFormState extends State<MachineSharingForm> {void _accept() {if (_composing) return;- final action = _actions- .where((a) => _buttons[a.id]?.hasFocus == true)- .firstOrNull;- if (action != null) {- action.run?.call();- } else if (_input.hasFocus && _value.text.trim().isNotEmpty) {- _addTyped();- } else {- unawaited(_save());+ if (_input.hasFocus) {+ unawaited(_add());+ return;}+ final stop = _stops+ .where((s) => _buttons[s.id]?.hasFocus == true)+ .firstOrNull;+ stop?.run?.call();}/// The picker's commands, while this editor holds the keys.@@ -305,7 +429,7 @@ class MachineSharingFormState extends State<MachineSharingForm> {if (_composing) return true;switch (command) {case 'picker.cancel':- widget.onClose(null);+ _done();case 'picker.accept':_scope.hasFocus ? _accept() : focus();case 'picker.complete':@@ -328,7 +452,7 @@ class MachineSharingFormState extends State<MachineSharingForm> {composing: () => _composing,actions: {'picker.accept': _accept,- 'picker.cancel': () => widget.onClose(null),+ 'picker.cancel': _done,'picker.complete': () => _tab(true),'picker.complete_back': () => _tab(false),'picker.next': () => _move(true),@@ -345,8 +469,7 @@ class MachineSharingFormState extends State<MachineSharingForm> {LogicalKeyboardKey.numpadEnter,includeRepeats: false,): _accept,- const SingleActivator(LogicalKeyboardKey.escape): () =>- widget.onClose(null),+ const SingleActivator(LogicalKeyboardKey.escape): _done,const SingleActivator(LogicalKeyboardKey.tab): () => _tab(true),const SingleActivator(LogicalKeyboardKey.tab, shift: true): () =>_tab(false),@@ -357,265 +480,592 @@ class MachineSharingFormState extends State<MachineSharingForm> {);}+ // ── drawing ───────────────────────────────────────────────────────────────────────────────────+@overrideWidget build(BuildContext context) {TerminalFontScope.watch(context);grid.AppTheme.watch(context);final desktop = DesktopChrome.of(context);- final cell = desktop ? const Size(9, 14) : terminalCellSizeOf(context);- final theme = terminalThemeFor(- grid.AppTheme.palette.value,- terminalThemeStore.value,+ return _keys(+ Focus(+ focusNode: _scope,+ onFocusChange: widget.onFocusChanged,+ child: desktop ? _desktop(context) : _terminal(context),+ ),);- final gap = SizedBox(height: cell.height);- Widget line(String text, {bool muted = false}) => Text(- text,- style: desktop- ? DesktopChrome.text(- size: 13,- color: muted ? DesktopChrome.muted : null,- )- : terminalContentStyle(color: muted ? theme.muted : theme.foreground),+ }++ /// The person's mark: the first letter of their address, in a neutral disc.+ Widget _avatar(String email) => Container(+ width: 28,+ height: 28,+ alignment: Alignment.center,+ decoration: BoxDecoration(+ color: grid.AppSurface.selectedFill,+ shape: BoxShape.circle,+ border: Border.all(color: DesktopChrome.rim),+ ),+ child: Text(+ email.isEmpty ? '?' : email.characters.first.toUpperCase(),+ style: DesktopChrome.control(medium: true),+ ),+ );++ Widget _spinner() => SizedBox(+ width: 12,+ height: 12,+ child: CircularProgressIndicator(+ strokeWidth: 1.5,+ color: DesktopChrome.muted,+ ),+ );++ Widget _desktop(BuildContext context) {+ final error = Theme.of(context).colorScheme.error;+ final people = _people;+ final fieldBorder = OutlineInputBorder(+ borderRadius: BorderRadius.circular(grid.AppDesktop.fieldRadius),+ borderSide: BorderSide(color: DesktopChrome.rim),+ );+ final inset = BoxDecoration(+ color: DesktopChrome.field,+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),+ border: Border.all(color: DesktopChrome.rim),+ );+ const gap = SizedBox(height: DesktopChrome.groupGap);+ const small = SizedBox(height: DesktopChrome.controlGap);+ final muted13 = DesktopChrome.text(size: 13, color: DesktopChrome.muted);++ final heading = Text(+ 'Share $_name',+ style: DesktopChrome.heading(),+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ );++ // What sharing gives, said once and plainly: these people get the owner's own rights.+ final access = Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.only(top: 2),+ child: Icon(+ AppIcons.shield,+ size: AppIcons.inlineSize,+ color: DesktopChrome.muted,+ ),+ ),+ const SizedBox(width: 8),+ Expanded(+ child: Text(+ 'People you share it with get full access: they can run harnesses, open terminals and read files on it.',+ style: muted13,+ ),+ ),+ ],+ );++ Widget domainRow(String domain) => MergeSemantics(+ child: Material(+ color: Colors.transparent,+ child: InkWell(+ key: const ValueKey('machine-sharing:domain-row'),+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),+ canRequestFocus: false,+ onTap: _busy ? null : () => unawaited(_toggleDomain()),+ child: Ink(+ decoration: inset,+ padding: const EdgeInsets.fromLTRB(12, 10, 8, 10),+ child: Row(+ children: [+ Icon(+ AppIcons.globe,+ size: AppIcons.inlineSize,+ color: DesktopChrome.muted,+ ),+ const SizedBox(width: 12),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ 'Everyone at $domain',+ style: DesktopChrome.control(medium: true),+ ),+ const SizedBox(height: 2),+ Text(+ _sameDomain+ ? 'Anyone with an @$domain address can add it from Add machine.'+ : 'Let anyone with an @$domain address add it.',+ style: DesktopChrome.metadata(),+ ),+ ],+ ),+ ),+ const SizedBox(width: 12),+ Switch(+ key: const ValueKey('machine-sharing:domain'),+ focusNode: _node('domain'),+ value: _sameDomain,+ onChanged: _busy ? null : (_) => unawaited(_toggleDomain()),+ ),+ ],+ ),+ ),+ ),+ ),);- Widget button(({String id, String label, VoidCallback? run}) action) {- final node = _buttons.putIfAbsent(- action.id,- () => FocusNode(debugLabel: action.label),- );- final destructive = action.id.startsWith('remove:');- return desktop- ? DesktopPill(- key: ValueKey('machine-sharing:${action.id}'),- label: destructive ? 'Remove' : action.label,- compact: true,- focusNode: node,- foregroundColor: destructive- ? Theme.of(context).colorScheme.error- : null,- onPressed: action.run,- )- : TerminalTextAction(- key: ValueKey('machine-sharing:${action.id}'),- label: destructive ? 'Remove' : action.label,- padding: EdgeInsets.zero,- focusNode: node,- onPressed: action.run,- );- }- final actions = _actions;final field = ReadlineKeys(controller: _value,enabled: !_busy,- onChanged: (_) {- if (_message != null) setState(() => _message = null);- },+ onChanged: (_) {},child: TextField(key: const ValueKey('machine-sharing-email'),controller: _value,focusNode: _input,- readOnly: _busy || _loading,+ readOnly: _busy,onTapOutside: (_) {},enableSuggestions: false,autocorrect: false,keyboardType: TextInputType.emailAddress,- style: desktop- ? DesktopChrome.text(size: 13)- : terminalContentStyle(color: theme.foreground),- cursorColor: desktop ? DesktopChrome.accent : theme.foreground,- decoration: desktop- ? InputDecoration(- hintText: '[email protected]',- hintStyle: DesktopChrome.text(- size: 13,- color: DesktopChrome.muted,- ),- border: OutlineInputBorder(- borderRadius: BorderRadius.circular(- grid.AppDesktop.fieldRadius,- ),- borderSide: BorderSide(color: DesktopChrome.rim),- ),- enabledBorder: OutlineInputBorder(- borderRadius: BorderRadius.circular(- grid.AppDesktop.fieldRadius,- ),- borderSide: BorderSide(color: DesktopChrome.rim),+ style: DesktopChrome.text(size: 13),+ cursorColor: DesktopChrome.accent,+ decoration: InputDecoration(+ hintText: 'Add people by email',+ hintStyle: muted13,+ prefixIcon: Icon(+ AppIcons.user,+ size: AppIcons.inlineSize,+ color: DesktopChrome.muted,+ ),+ prefixIconConstraints: const BoxConstraints(minWidth: 36),+ border: fieldBorder,+ enabledBorder: _fieldError == null+ ? fieldBorder+ : fieldBorder.copyWith(borderSide: BorderSide(color: error)),+ disabledBorder: fieldBorder,+ focusedBorder: fieldBorder.copyWith(+ borderSide: BorderSide(+ color: _fieldError == null ? DesktopChrome.focusRing : error,+ width: grid.AppDesktop.focusWidth,+ ),+ ),+ filled: true,+ fillColor: DesktopChrome.field,+ isDense: true,+ contentPadding: const EdgeInsets.symmetric(+ horizontal: 10,+ vertical: 11,+ ),+ ),+ onEditingComplete: () {},+ ),+ );++ final addRow = Row(+ children: [+ Expanded(child: field),+ const SizedBox(width: DesktopChrome.controlGap),+ FilledButton(+ key: const ValueKey('machine-sharing:add'),+ focusNode: _node('add'),+ onPressed: !_busy && _value.text.trim().isNotEmpty+ ? () => unawaited(_add())+ : null,+ child: const Text('Share'),+ ),+ ],+ );++ Widget personRow(_Person person) => Padding(+ key: ValueKey('machine-sharing-person:${person.email}'),+ padding: const EdgeInsets.symmetric(vertical: 4),+ child: Row(+ children: [+ _avatar(person.email),+ const SizedBox(width: 12),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ person.email,+ style: DesktopChrome.control(medium: true),+ overflow: TextOverflow.ellipsis,),- focusedBorder: OutlineInputBorder(- borderRadius: BorderRadius.circular(- grid.AppDesktop.fieldRadius,- ),- borderSide: BorderSide(- color: DesktopChrome.focusRing,- width: grid.AppDesktop.focusWidth,- ),+ const SizedBox(height: 2),+ Row(+ children: [+ // Colour is never the only signal: the words say it too.+ if (person.usingIt) ...[+ Container(+ width: 6,+ height: 6,+ decoration: BoxDecoration(+ color: grid.AppPalette.online,+ shape: BoxShape.circle,+ ),+ ),+ const SizedBox(width: 6),+ ],+ Flexible(+ child: Text(+ person.usingIt+ ? person.named+ ? 'Using it'+ : 'Using it · added from $_domain'+ : person.named+ ? 'Invited · not using it yet'+ : 'Added from $_domain',+ style: DesktopChrome.metadata(),+ overflow: TextOverflow.ellipsis,+ ),+ ),+ ],),- filled: true,- fillColor: DesktopChrome.field,- isDense: true,- contentPadding: const EdgeInsets.symmetric(- horizontal: 10,- vertical: 10,+ ],+ ),+ ),+ if (person.named)+ AppIconButton(+ key: ValueKey('machine-sharing:remove:${person.email}'),+ icon: AppIcons.close,+ tooltip: 'Stop sharing with ${person.email}',+ destructive: true,+ focusNode: _node('remove:${person.email}'),+ onPressed: _busy ? null : () => unawaited(_remove(person.email)),+ )+ else+ Tooltip(+ message:+ 'Turn off Everyone at $_domain to stop sharing with them',+ child: Padding(+ padding: const EdgeInsets.all(8),+ child: Icon(+ AppIcons.globe,+ size: AppIcons.inlineSize,+ color: DesktopChrome.muted,),- )- : InputDecoration(- hintText: '[email protected]',- hintStyle: terminalContentStyle(color: theme.muted),- border: InputBorder.none,- enabledBorder: InputBorder.none,- focusedBorder: InputBorder.none,- filled: false,- isDense: true,- isCollapsed: true,- constraints: const BoxConstraints(),- contentPadding: EdgeInsets.zero,),- onEditingComplete: () {},- onChanged: (_) {- if (_message != null) setState(() => _message = null);- },+ ),+ ],),);- final using = [- for (final member in _members)- if (member['email'] is String) member['email'] as String,- ];- final body = SingleChildScrollView(- padding: EdgeInsets.symmetric(- horizontal: cell.width * 2,- vertical: cell.height,- ),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,++ final empty = Container(+ key: const ValueKey('machine-sharing:empty'),+ decoration: inset,+ padding: const EdgeInsets.all(12),+ child: Row(children: [- Text(- 'Share $_name',- style: desktop- ? DesktopChrome.heading()- : terminalContentStyle(color: theme.foreground),+ Icon(+ AppIcons.lock,+ size: AppIcons.inlineSize,+ color: DesktopChrome.muted,),- gap,- line(- 'People you share it with use it as their own: its harnesses, terminals and files.',- muted: true,+ const SizedBox(width: 12),+ Expanded(+ child: Text(+ _sameDomain+ ? 'No one at $_domain has added it yet.'+ : 'Not shared. Only your own devices can use it.',+ style: muted13,+ ),),- gap,- if (_loading)- line('Reading its sharing…', muted: true)- else ...[- if (actions.where((a) => a.id == 'domain').firstOrNull- case final domain?) ...[- button(domain),- if (_sameDomain)- line('They add it from Add machine.', muted: true),- gap,- ],- if (desktop) ...[- Text(- 'Email',- style: DesktopChrome.text(size: 12, color: DesktopChrome.muted),+ ],+ ),+ );++ final status = Semantics(+ liveRegion: true,+ child: Row(+ children: [+ if (_busy) ...[+ _spinner(),+ const SizedBox(width: 8),+ ] else if (_status != null) ...[+ Icon(+ _statusIsError ? AppIcons.circleAlert : AppIcons.check,+ size: 14,+ color: _statusIsError ? error : DesktopChrome.muted,+ ),+ const SizedBox(width: 8),+ ],+ Flexible(+ child: Text(+ _busy ? 'Saving…' : _status ?? '',+ style: DesktopChrome.text(+ size: 12,+ color: _statusIsError ? error : DesktopChrome.muted,),- const SizedBox(height: 6),- field,- ] else- Row(- children: [- SizedBox(- width: cell.width * 8,- child: Text(- 'email >',- style: terminalContentStyle(color: theme.muted),- ),- ),- Expanded(child: field),- ],+ ),+ ),+ if (!_busy && _undo != null) ...[+ const SizedBox(width: 4),+ TextButton(+ key: const ValueKey('machine-sharing:undo'),+ focusNode: _node('undo'),+ onPressed: () => unawaited(_undoRemove()),+ child: const Text('Undo'),+ ),+ ],+ ],+ ),+ );++ final List<Widget> content;+ if (_loading) {+ content = [+ heading,+ small,+ Row(+ children: [+ _spinner(),+ const SizedBox(width: 8),+ Text('Reading who it is shared with…', style: muted13),+ ],+ ),+ ];+ } else if (_unavailable case final reason?) {+ content = [+ heading,+ small,+ Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.only(top: 2),+ child: Icon(+ AppIcons.circleAlert,+ size: AppIcons.inlineSize,+ color: error,),- line('Enter adds it. They see it in their Machines.', muted: true),- if (_emails.isNotEmpty) ...[- gap,- for (final email in _emails)- Padding(- padding: EdgeInsets.only(bottom: desktop ? 4 : 0),- child: Row(- children: [- Expanded(child: line(email)),- button(- actions.firstWhere((a) => a.id == 'remove:$email'),- ),- ],- ),- ),- ],- if (using.isNotEmpty) ...[- gap,- line('Using it now: ${using.join(', ')}', muted: true),- ],+ ),+ const SizedBox(width: 8),+ Expanded(child: Text(reason, style: DesktopChrome.text(size: 13))),],- gap,- if (_message != null) ...[- Semantics(+ ),+ ];+ } else {+ content = [+ heading,+ small,+ access,+ gap,+ if (_domain case final domain?) ...[domainRow(domain), gap],+ Text('People', style: DesktopChrome.control(medium: true)),+ small,+ addRow,+ if (_fieldError case final problem?)+ Padding(+ padding: const EdgeInsets.only(top: 6, left: 2),+ child: Semantics(liveRegion: true,child: Text(- _message!,- style: desktop- ? DesktopChrome.text(- size: 12,- color: _error- ? Theme.of(context).colorScheme.error- : DesktopChrome.muted,- )- : terminalContentStyle(- color: _error ? theme.yellow : theme.muted,- ),+ problem,+ key: const ValueKey('machine-sharing:field-error'),+ style: DesktopChrome.text(size: 12, color: error),),),- gap,- ],- Wrap(- spacing: desktop ? 8 : cell.width * 2,- runSpacing: desktop ? 8 : cell.height,- children: [- for (final action in actions)- if (action.id == 'save' || action.id == 'cancel')- button(action),- ],),+ small,+ if (people.isEmpty) empty else ...people.map(personRow),+ ];+ }++ final actions = Row(+ children: [+ Expanded(child: status),+ const SizedBox(width: DesktopChrome.controlGap),+ if (!_loading && _unavailable != null) ...[+ TextButton(+ key: const ValueKey('machine-sharing:retry'),+ focusNode: _node('retry'),+ onPressed: () => unawaited(_load()),+ child: const Text('Retry'),+ ),+ const SizedBox(width: DesktopChrome.controlGap),],- ),+ // Quiet: every change has already applied, and Share is this surface's one strong action.+ TextButton(+ key: const ValueKey('machine-sharing:done'),+ focusNode: _node('done'),+ onPressed: _done,+ child: const Text('Done'),+ ),+ ],);String? hint(String command) => effectiveCommandHint(context,command,contextKind: KeymapContext.picker,)?.replaceAll('⇥', 'Tab').replaceAll('↵', 'Enter');- return _keys(- Focus(- focusNode: _scope,- onFocusChange: widget.onFocusChanged,- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- Expanded(child: body),- Padding(- padding: EdgeInsets.symmetric(- horizontal: cell.width * 2,- vertical: cell.height,+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Expanded(+ child: SingleChildScrollView(+ padding: const EdgeInsets.fromLTRB(18, 14, 18, 8),+ child: Align(+ alignment: Alignment.topLeft,+ // A short form keeps a short reading line, whatever the pane's width.+ child: ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: 520),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: content,+ ),),- child: Text(- [- if (hint('picker.accept') case final enter?)- '$enter add or save',- if (hint('picker.complete') case final tab?) '$tab next',- if (hint('picker.cancel') case final escape?) '$escape back',- ].join(' · '),- style: desktop- ? DesktopChrome.metadata()- : terminalContentStyle(color: theme.muted),+ ),+ ),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(18, 8, 18, 0),+ child: actions,+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(18, 8, 18, 14),+ child: Text(+ [+ if (hint('picker.accept') case final enter?) '$enter share',+ if (hint('picker.complete') case final tab?) '$tab next',+ if (hint('picker.cancel') case final escape?) '$escape done',+ ].join(' · '),+ style: DesktopChrome.metadata(),+ ),+ ),+ ],+ );+ }++ /// The terminal look: the same form and the same keys, in the terminal's own type.+ Widget _terminal(BuildContext context) {+ final cell = terminalCellSizeOf(context);+ final theme = terminalThemeFor(+ grid.AppTheme.palette.value,+ terminalThemeStore.value,+ );+ final gap = SizedBox(height: cell.height);+ Widget line(String text, {Color? color}) => Text(+ text,+ style: terminalContentStyle(color: color ?? theme.foreground),+ );+ Widget action(String id, String label, VoidCallback? run) =>+ TerminalTextAction(+ key: ValueKey('machine-sharing:$id'),+ label: label,+ padding: EdgeInsets.zero,+ focusNode: _node(id),+ onPressed: run,+ );+ final people = _people;+ return SingleChildScrollView(+ padding: EdgeInsets.symmetric(+ horizontal: cell.width * 2,+ vertical: cell.height,+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ line('Share $_name'),+ gap,+ if (_loading)+ line('Reading who it is shared with…', color: theme.muted)+ else if (_unavailable case final reason?) ...[+ line(reason, color: theme.yellow),+ gap,+ action('retry', 'Retry', () => unawaited(_load())),+ ] else ...[+ line(+ 'People you share it with get full access: harnesses, terminals and files.',+ color: theme.muted,+ ),+ gap,+ if (_domain case final domain?) ...[+ action(+ 'domain',+ '[${_sameDomain ? 'x' : ' '}] Everyone at $domain',+ _busy ? null : () => unawaited(_toggleDomain()),),+ gap,+ ],+ Row(+ children: [+ SizedBox(+ width: cell.width * 8,+ child: Text(+ 'email >',+ style: terminalContentStyle(color: theme.muted),+ ),+ ),+ Expanded(+ child: ReadlineKeys(+ controller: _value,+ enabled: !_busy,+ onChanged: (_) {},+ child: TextField(+ key: const ValueKey('machine-sharing-email'),+ controller: _value,+ focusNode: _input,+ readOnly: _busy,+ onTapOutside: (_) {},+ enableSuggestions: false,+ autocorrect: false,+ style: terminalContentStyle(color: theme.foreground),+ cursorColor: theme.foreground,+ decoration: const InputDecoration(+ border: InputBorder.none,+ isDense: true,+ isCollapsed: true,+ contentPadding: EdgeInsets.zero,+ ),+ onEditingComplete: () {},+ ),+ ),+ ),+ ],),+ gap,+ if (people.isEmpty)+ line(+ 'Not shared. Only your own devices can use it.',+ color: theme.muted,+ ),+ for (final person in people)+ Row(+ children: [+ Expanded(+ child: line(+ '${person.email} ${person.usingIt+ ? 'using it'+ : person.named+ ? 'invited'+ : 'added from $_domain'}',+ ),+ ),+ if (person.named)+ action(+ 'remove:${person.email}',+ 'Remove',+ _busy ? null : () => unawaited(_remove(person.email)),+ ),+ ],+ ),],- ),+ if (_fieldError case final problem?)+ line(problem, color: theme.yellow),+ gap,+ if (_busy)+ line('Saving…', color: theme.muted)+ else if (_status case final status?)+ line(status, color: _statusIsError ? theme.yellow : theme.muted),+ if (!_busy && _undo != null)+ action('undo', 'Undo', () => unawaited(_undoRemove())),+ gap,+ action('done', 'Done', _done),+ ],),);}diff --git a/desktop/test/machine_sharing_form_test.dart b/desktop/test/machine_sharing_form_test.dartnew file mode 100644index 000000000..3097dc208--- /dev/null+++ b/desktop/test/machine_sharing_form_test.dart@@ -0,0 +1,291 @@+import 'dart:io';+import 'dart:ui' as ui;++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/auth/auth_session.dart';+import 'package:harness/core/config.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/state/app_state.dart';+import 'package:harness/widgets/desktop_chrome.dart';+import 'package:harness/widgets/machine_sharing_form.dart';++import 'support/real_fonts.dart';++/// A machine's daemon answering `shared_machines` as services/sharedMachines.ts does.+class _SharingApp extends AppNotifier {+ _SharingApp()+ : super(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ );++ Map<String, dynamic> policy = {+ 'emails': <String>[],+ 'sameDomain': false,+ 'domain': 'autonomous.ai',+ 'members': <Map<String, dynamic>>[],+ };+ Map<String, dynamic>? unreadable;+ Map<String, dynamic>? refusal;+ final sets = <({List<String> emails, bool sameDomain})>[];++ @override+ Future<Map<String, dynamic>> machineSharing(String machineId) async =>+ unreadable ?? policy;++ @override+ Future<Map<String, dynamic>> setMachineSharing(+ String machineId,+ List<String> emails, {+ required bool sameDomain,+ }) async {+ sets.add((emails: emails, sameDomain: sameDomain));+ if (refusal != null) return refusal!;+ policy = {...policy, 'emails': emails, 'sameDomain': sameDomain};+ return policy;+ }+}++final _capture = Platform.environment['HARNESS_SHARE_CAPTURE_DIR'];++Future<void> _snap(WidgetTester tester, GlobalKey boundary, String name) async {+ final output = _capture;+ if (output == null) return;+ await tester.pumpAndSettle();+ final render =+ boundary.currentContext!.findRenderObject()! as RenderRepaintBoundary;+ await tester.runAsync(() async {+ final picture = await render.toImage(pixelRatio: 2);+ final bytes = await picture.toByteData(format: ui.ImageByteFormat.png);+ await Directory(output).create(recursive: true);+ await File('$output/$name.png').writeAsBytes(bytes!.buffer.asUint8List());+ picture.dispose();+ });+}++void main() {+ setUpAll(() async {+ // Captures use the macOS system face; regression runs the shared metric-compatible fonts.+ if (_capture != null && Platform.isMacOS) {+ for (final (family, path) in [+ ('.AppleSystemUIFont', '/System/Library/Fonts/SFNS.ttf'),+ ('Roboto', '/System/Library/Fonts/SFNS.ttf'),+ ]) {+ final bytes = ByteData.sublistView(await File(path).readAsBytes());+ await (FontLoader(family)..addFont(Future.value(bytes))).load();+ }+ } else {+ await loadRealFonts();+ }+ });++ Future<(String? Function(), GlobalKey)> open(+ WidgetTester tester,+ _SharingApp app, {+ Brightness brightness = Brightness.dark,+ }) async {+ // The app's tokens follow their own brightness (main.dart's _GridTokenScope), not the theme's.+ final saved = grid.AppTheme.brightness.value;+ grid.AppTheme.brightness.value = brightness;+ addTearDown(() => grid.AppTheme.brightness.value = saved);+ tester.view.physicalSize = const Size(1200, 1400);+ tester.view.devicePixelRatio = 2;+ addTearDown(tester.view.reset);+ String? closed;+ var wasClosed = false;+ final boundary = GlobalKey();+ await tester.pumpWidget(+ MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: brightness),+ home: Scaffold(+ backgroundColor: DesktopChrome.surface,+ body: DesktopChrome(+ child: Align(+ alignment: Alignment.topLeft,+ child: RepaintBoundary(+ key: boundary,+ child: ColoredBox(+ color: DesktopChrome.surface,+ child: SizedBox(+ width: 560,+ height: 640,+ child: MachineSharingForm(+ app: app,+ machineId: 'm1',+ onClose: (message) {+ wasClosed = true;+ closed = message;+ },+ onFocusChanged: (_) {},+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ return (() => wasClosed ? (closed ?? '') : null, boundary);+ }++ testWidgets(+ 'shares with people and the domain as each change is made, with Undo',+ (tester) async {+ final app = _SharingApp();+ final (closed, boundary) = await open(tester, app);+ expect(find.text('Share this machine'), findsOneWidget);+ expect(+ find.text('Not shared. Only your own devices can use it.'),+ findsOneWidget,+ );+ expect(find.text('Everyone at autonomous.ai'), findsOneWidget);+ await _snap(tester, boundary, 'share-empty-dark');++ // An address the backend would refuse is named, and nothing is sent.+ await tester.enterText(+ find.byKey(const ValueKey('machine-sharing-email')),+ 'bitcoinbuilder.ai@!gmail.com',+ );+ await tester.pump();+ await tester.tap(find.byKey(const ValueKey('machine-sharing:add')));+ await tester.pumpAndSettle();+ expect(+ find.text('“bitcoinbuilder.ai@!gmail.com” is not an email address.'),+ findsOneWidget,+ );+ expect(app.sets, isEmpty);+ await _snap(tester, boundary, 'share-invalid-dark');++ // Several at once, shared the moment Share is pressed.+ await tester.enterText(+ find.byKey(const ValueKey('machine-sharing-email')),+ );+ await tester.pump();+ app.policy = {+ ...app.policy,+ 'members': [+ {+ 'email': '[email protected]',+ 'name': 'Kim',+ 'via': 'email',+ 'machines': 1,+ },+ ],+ };+ await tester.tap(find.byKey(const ValueKey('machine-sharing:add')));+ await tester.pumpAndSettle();+ expect(app.sets.last.emails, ['[email protected]', '[email protected]']);+ expect(find.text('Shared with 2 people.'), findsOneWidget);+ expect(find.text('Using it'), findsOneWidget);+ expect(find.text('Invited · not using it yet'), findsOneWidget);++ // Everyone at the domain: the switch applies at once.+ await tester.tap(find.byKey(const ValueKey('machine-sharing:domain')));+ await tester.pumpAndSettle();+ expect(app.sets.last.sameDomain, isTrue);+ expect(+ find.text(+ 'Anyone with an @autonomous.ai address can add it from Add machine.',+ ),+ findsOneWidget,+ );+ await _snap(tester, boundary, 'share-people-dark');++ // Removing someone is undoable.+ await tester.tap(+ find.byKey(const ValueKey('machine-sharing:remove:[email protected]')),+ );+ await tester.pumpAndSettle();+ expect(app.sets.last.emails, ['[email protected]']);+ expect(find.text('Stopped sharing with [email protected].'), findsOneWidget);+ await _snap(tester, boundary, 'share-undo-dark');+ await tester.tap(find.byKey(const ValueKey('machine-sharing:undo')));+ await tester.pumpAndSettle();+ expect(app.sets.last.emails, ['[email protected]', '[email protected]']);++ // A refusal says why and changes nothing.+ app.refusal = {+ 'error': 'VALIDATION_ERROR',+ 'message': 'The backend refused it.',+ };+ await tester.tap(find.byKey(const ValueKey('machine-sharing:domain')));+ await tester.pumpAndSettle();+ expect(find.text('The backend refused it.'), findsOneWidget);+ expect(+ tester+ .widget<Switch>(+ find.byKey(const ValueKey('machine-sharing:domain')),+ )+ .value,+ isTrue,+ );++ // Done leaves where the sharing stands.+ await tester.tap(find.byKey(const ValueKey('machine-sharing:done')));+ await tester.pump();+ expect(closed(), 'Shared with 2 people and everyone at autonomous.ai.');+ },+ );++ testWidgets('Done with nothing changed closes quietly; light appearance', (+ tester,+ ) async {+ final app = _SharingApp()+ ..policy = {+ 'emails': ['[email protected]'],+ 'sameDomain': true,+ 'domain': 'autonomous.ai',+ 'members': [+ {'email': '[email protected]', 'via': 'email', 'machines': 2},+ {'email': '[email protected]', 'via': 'domain', 'machines': 1},+ ],+ };+ final (closed, boundary) = await open(+ tester,+ app,+ brightness: Brightness.light,+ );+ expect(find.text('Using it · added from autonomous.ai'), findsOneWidget);+ expect(+ find.byKey(const ValueKey('machine-sharing:remove:[email protected]')),+ findsNothing,+ );+ await _snap(tester, boundary, 'share-people-light');+ await tester.tap(find.byKey(const ValueKey('machine-sharing:done')));+ await tester.pump();+ expect(closed(), '');+ });++ testWidgets(+ 'a machine that cannot say offers Retry, and no domain at a public one',+ (tester) async {+ final app = _SharingApp()..unreadable = {'error': 'UNSUPPORTED'};+ final (_, boundary) = await open(tester, app);+ expect(+ find.text('Update Harness on this machine to share it.'),+ findsOneWidget,+ );+ await _snap(tester, boundary, 'share-unavailable-dark');+ app.unreadable = null;+ app.policy = {...app.policy, 'domain': null};+ await tester.tap(find.byKey(const ValueKey('machine-sharing:retry')));+ await tester.pumpAndSettle();+ expect(+ find.byKey(const ValueKey('machine-sharing:domain')),+ findsNothing,+ );+ expect(+ find.byKey(const ValueKey('machine-sharing-email')),+ findsOneWidget,+ );+ },+ );+}