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(web): mark shared harnesses Public or Private in the pane header
Dev jacobd86322ebf9fc
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex deceef8a9..f0e727769 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -96,6 +96,7 @@ import '../widgets/box_chrome.dart';import '../widgets/new_harness_form.dart';import '../widgets/open_harness_intent.dart';import '../widgets/pane_grid.dart';+import '../widgets/pane_share_badge.dart';import '../widgets/remote_folder_picker.dart';import '../widgets/shortcuts_sheet.dart';import '../widgets/harness_customize_pane.dart';@@ -6300,93 +6301,98 @@ class _SwarmScreenState extends State<SwarmScreen> {child: Stack(children: [Positioned.fill(- child: PaneGrid(- notifier: app,- swarmMode: true,- soloFocused: _compact(context),- empty:- app.panes.isEmpty &&- !app.activeSwarm.isUtility &&- !app- .activeSwarm- .isOrchestrator- ? newHarnessOpensInBox ||- app- .activeSwarm- .isNewTabPage- ? _startGuide()- : HarnessStartPage(- key: ValueKey(- 'harness-start:${app.activeSwarmId}',- ),- focusNode:- _startSearchFocus,- createSearch: () =>- SwarmSearchController(- app,- _navigation- .recent,- projects:- _projects,- commands:- _searchCommands,- recentCommands: () =>- _navigation- .recentCommands,- // The first box a new- // person meets is the same- // box: its placeholder- // promises `?` and a way- // to create, so it has them.- modes:- _searchModes,- adding: true,- offersCreate:- true,- placement:- HarnessPlacement- .currentTab,- catalog:- _searchCatalog,- ),- onNewTab: _newTab,- onNewPane: () =>- unawaited(- _addAgent(- query: '',- ),- ),- onCommands:- _showSearchCommands,- onQuickStart:- _learning.offer- ? _startQuickStart- : null,- onPractice:- _practiceKeyboard,- onNew: () => _newAgent(- placement:- HarnessPlacement- .currentTab,- ),- onNewWithTask: (task) =>- _newAgent(- task: task,- placement:- HarnessPlacement- .currentTab,- ),- onStore: _openStore,- onResourceSearch:- (query) =>- _openSearch(- adding: true,- query: query,+ child: PaneShareStatus(+ visible:+ widget.chrome?.showsShareStatus ==+ true,+ child: PaneGrid(+ notifier: app,+ swarmMode: true,+ soloFocused: _compact(context),+ empty:+ app.panes.isEmpty &&+ !app+ .activeSwarm+ .isUtility &&+ !app+ .activeSwarm+ .isOrchestrator+ ? newHarnessOpensInBox ||+ app+ .activeSwarm+ .isNewTabPage+ ? _startGuide()+ : HarnessStartPage(+ key: ValueKey(+ 'harness-start:${app.activeSwarmId}',+ ),+ focusNode:+ _startSearchFocus,+ createSearch: () => SwarmSearchController(+ app,+ _navigation.recent,+ projects: _projects,+ commands:+ _searchCommands,+ recentCommands: () =>+ _navigation+ .recentCommands,+ // The first box a new+ // person meets is the same+ // box: its placeholder+ // promises `?` and a way+ // to create, so it has them.+ modes: _searchModes,+ adding: true,+ offersCreate: true,+ placement:+ HarnessPlacement+ .currentTab,+ catalog:+ _searchCatalog,+ ),+ onNewTab: _newTab,+ onNewPane: () =>+ unawaited(+ _addAgent(+ query: '',),- onChoose:- _chooseStartSearch,- )- : null,+ ),+ onCommands:+ _showSearchCommands,+ onQuickStart:+ _learning.offer+ ? _startQuickStart+ : null,+ onPractice:+ _practiceKeyboard,+ onNew: () => _newAgent(+ placement:+ HarnessPlacement+ .currentTab,+ ),+ onNewWithTask:+ (+ task,+ ) => _newAgent(+ task: task,+ placement:+ HarnessPlacement+ .currentTab,+ ),+ onStore: _openStore,+ onResourceSearch:+ (+ query,+ ) => _openSearch(+ adding: true,+ query: query,+ ),+ onChoose:+ _chooseStartSearch,+ )+ : null,+ ),),),],diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 3f1802562..6d596086c 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -67,6 +67,7 @@ import 'dial_status.dart';import 'grid_pictures.dart';import 'model_start_watch.dart';import 'harness_placement.dart';+import 'harness_share_status.dart';import 'desk_sync.dart';import 'machine_profile.dart';import 'pane_layout_store.dart';@@ -737,6 +738,11 @@ class AppNotifier extends ChangeNotifier {),);+ /// Which of the owner's harnesses are shared, and how — for marking panes.+ late final shareStatus = HarnessShareStatus(+ (machineId, agentId) => manageHarnessShares(machineId, agentId, 'list'),+ );+/// The end of the session a Cmd-P row previews, from its machine's index/// (`session_tail`, cli/src/lib/sessionSearch/). Apart from/// [sessionPreviews], whose excerpts come from the live agent.@@ -4084,6 +4090,7 @@ class AppNotifier extends ChangeNotifier {machineStates.clear();sessionPreviews.clear();sessionTails.clear();+ shareStatus.clear();gridPictures.clear();_stopWakeFollowers();expandedMachines.clear();@@ -4731,10 +4738,15 @@ class AppNotifier extends ChangeNotifier {if (machineStates[machineId]?.machine.isShared == true) {return Future.error(StateError('Only the owner can change sharing.'));}- return _conn(machineId).request(- 'harness_share_$action',- payload: {'agentId': agentId, ...payload},- );+ return _conn(machineId)+ .request(+ 'harness_share_$action',+ payload: {'agentId': agentId, ...payload},+ )+ .then((response) {+ shareStatus.record(machineId, agentId, response);+ return response;+ });}/// The browser controls only a linked, owned machine's managed viewer. Requests fail whilediff --git a/desktop/lib/state/harness_share_status.dart b/desktop/lib/state/harness_share_status.dartnew file mode 100644index 000000000..09f4243c5--- /dev/null+++ b/desktop/lib/state/harness_share_status.dart@@ -0,0 +1,105 @@+import 'dart:async';++import 'package:flutter/foundation.dart';++/// How a harness is shared: its link's visibility, or private invitations.+enum HarnessShareAccess { public, private }++/// A shared harness as its owner sees it at a glance. Absent means not shared.+@immutable+class HarnessShare {+ const HarnessShare(this.access, {this.people = 0});++ final HarnessShareAccess access;++ /// Accounts invited by email. A public link needs none.+ final int people;++ String get label => switch (access) {+ HarnessShareAccess.public => 'Public',+ HarnessShareAccess.private when people > 0 => 'Private · $people',+ HarnessShareAccess.private => 'Private',+ };++ String get detail => switch (access) {+ HarnessShareAccess.public =>+ 'Shared publicly: anyone with the link watches',+ HarnessShareAccess.private when people == 1 =>+ 'Shared privately with 1 person',+ HarnessShareAccess.private when people > 1 =>+ 'Shared privately with $people people',+ HarnessShareAccess.private => 'Shared privately: only invited accounts',+ };++ @override+ bool operator ==(Object other) =>+ other is HarnessShare && other.access == access && other.people == people;++ @override+ int get hashCode => Object.hash(access, people);+}++/// What a `harness_share_*` answer says about sharing — every action answers+/// with the same list (cli/src/sharing/owner.ts). Null means not shared.+HarnessShare? harnessShareFrom(Map<String, dynamic> response) {+ final link = response['link'];+ final visibility = link is Map ? link['visibility'] : null;+ final people = (response['shares'] as List?)?.length ?? 0;+ if (visibility == 'public') return HarnessShare(HarnessShareAccess.public);+ if (visibility == 'private' || people > 0) {+ return HarnessShare(HarnessShareAccess.private, people: people);+ }+ return null;+}++typedef HarnessShareKey = (String machineId, String agentId);++/// The owner's harnesses and how each is shared, for marking panes. Learnt+/// from every share answer (the Share dialog's included) and asked once per+/// harness a pane shows; the daemon pushes no share events.+class HarnessShareStatus extends ChangeNotifier {+ HarnessShareStatus(this._list);++ final Future<Map<String, dynamic>> Function(String machineId, String agentId)+ _list;++ final _shares = <HarnessShareKey, HarnessShare>{};+ final _asked = <HarnessShareKey>{};++ HarnessShare? of(String machineId, String agentId) =>+ _shares[(machineId, agentId)];++ /// Takes in a share answer for this harness.+ void record(String machineId, String agentId, Map<String, dynamic> response) {+ final key = (machineId, agentId);+ _asked.add(key);+ final next = harnessShareFrom(response);+ if (_shares[key] == next) return;+ if (next == null) {+ _shares.remove(key);+ } else {+ _shares[key] = next;+ }+ notifyListeners();+ }++ /// Asks once. A failed answer (an older CLI, no connection) is asked again+ /// the next time a pane shows this harness.+ void ensure(String machineId, String agentId) {+ final key = (machineId, agentId);+ if (!_asked.add(key)) return;+ unawaited(+ Future.sync(() => _list(machineId, agentId)).then<void>(+ (response) => record(machineId, agentId, response),+ onError: (Object _) => _asked.remove(key),+ ),+ );+ }++ void clear() {+ _asked.clear();+ if (_shares.isEmpty) return;+ _shares.clear();+ notifyListeners();+ }+}diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dartindex 2a0aea1ea..08e30df03 100644--- a/desktop/lib/state/workspace_chrome.dart+++ b/desktop/lib/state/workspace_chrome.dart@@ -46,6 +46,7 @@ class WorkspaceChrome {this.showsKeyHints = true,this.viewMachineCloses = false,this.closesTabs = false,+ this.showsShareStatus = false,this.compactTabs,this.compactBelow = 0,});@@ -73,6 +74,9 @@ class WorkspaceChrome {/// no ⌘W menu to close one — an empty New Tab included.final bool closesTabs;+ /// True marks each shared harness's pane header Public or Private.+ final bool showsShareStatus;+/// Below [compactBelow] of window width the workspace goes compact: this/// replaces the tab list (the Store button steps aside), and only the focused/// harness is drawn — a phone has room for neither a tab row nor a grid.diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dartindex e0225984d..750aecc6d 100644--- a/desktop/lib/web/shell/web_chrome.dart+++ b/desktop/lib/web/shell/web_chrome.dart@@ -19,6 +19,7 @@ WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(showsKeyHints: false,viewMachineCloses: true,closesTabs: true,+ showsShareStatus: true,compactTabs: (context, commands) =>WebTabSwitcher(app: app, commands: commands),compactBelow: kWebCompactBelow,diff --git a/desktop/lib/widgets/pane_share_badge.dart b/desktop/lib/widgets/pane_share_badge.dartnew file mode 100644index 000000000..b18a50e12--- /dev/null+++ b/desktop/lib/widgets/pane_share_badge.dart@@ -0,0 +1,144 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import '../shared/theme/app_theme.dart' as grid;+import '../sharing/share_harness_dialog.dart';+import '../state/app_state.dart';+import '../state/harness_share_status.dart';+import '../terminal/terminal_theme.dart';+import '../terminal/terminal_theme_store.dart';++/// Whether pane headers mark shared harnesses. Absent means not — desktop+/// never places one; the web build does ([WorkspaceChrome.showsShareStatus]).+class PaneShareStatus extends InheritedWidget {+ const PaneShareStatus({+ super.key,+ required this.visible,+ required super.child,+ });++ final bool visible;++ static bool visibleOf(BuildContext context) =>+ context.dependOnInheritedWidgetOfExactType<PaneShareStatus>()?.visible ??+ false;++ @override+ bool updateShouldNotify(PaneShareStatus oldWidget) =>+ visible != oldWidget.visible;+}++/// A pane's share mark: Public or Private (with its invitees), nothing when+/// the harness is not shared. Clicking it opens Share for this harness.+class PaneShareBadge extends StatefulWidget {+ const PaneShareBadge({+ super.key,+ required this.notifier,+ required this.machineId,+ required this.agentId,+ required this.name,+ this.compact = false,+ });++ final AppNotifier notifier;+ final String machineId, agentId, name;++ /// The icon alone, for a narrow header.+ final bool compact;++ @override+ State<PaneShareBadge> createState() => _PaneShareBadgeState();+}++class _PaneShareBadgeState extends State<PaneShareBadge> {+ // Only the owner can ask; a machine shared with this account answers no.+ bool get _owned =>+ widget.notifier.stateOf(widget.machineId)?.machine.isShared == false;++ @override+ void initState() {+ super.initState();+ _ask();+ }++ @override+ void didUpdateWidget(PaneShareBadge oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.machineId != widget.machineId ||+ oldWidget.agentId != widget.agentId) {+ _ask();+ }+ }++ void _ask() {+ if (_owned) {+ widget.notifier.shareStatus.ensure(widget.machineId, widget.agentId);+ }+ }++ @override+ Widget build(BuildContext context) => ListenableBuilder(+ listenable: widget.notifier.shareStatus,+ builder: (context, _) {+ final share = widget.notifier.shareStatus.of(+ widget.machineId,+ widget.agentId,+ );+ if (share == null) return const SizedBox.shrink();+ // The terminal's own ANSI ramp: tuned to read on the pane it sits on,+ // in light and dark themes alike.+ final theme = terminalThemeFor(+ grid.AppTheme.palette.value,+ terminalThemeStore.value,+ );+ final color = share.access == HarnessShareAccess.public+ ? theme.brightGreen+ : theme.brightYellow;+ return Tooltip(+ message: share.detail,+ child: TextButton(+ key: ValueKey('pane-share:${widget.machineId}:${widget.agentId}'),+ onPressed: () => unawaited(+ showShareHarnessDialog(+ context,+ widget.notifier,+ widget.machineId,+ widget.agentId,+ widget.name,+ ),+ ),+ style: TextButton.styleFrom(+ foregroundColor: color,+ minimumSize: Size.zero,+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(+ share.access == HarnessShareAccess.public+ ? LucideIcons.globe+ : LucideIcons.lock,+ size: 13,+ ),+ if (!widget.compact) ...[+ const SizedBox(width: 6),+ Flexible(+ child: Text(+ share.label,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: grid.AppType.monoLabel(fontWeight: FontWeight.w400),+ ),+ ),+ ],+ ],+ ),+ ),+ );+ },+ );+}diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dartindex 76e495aac..833a7c7db 100644--- a/desktop/lib/widgets/terminal_panel.dart+++ b/desktop/lib/widgets/terminal_panel.dart@@ -45,6 +45,7 @@ import 'engine_identity.dart';import 'harness_activity_mark.dart';import 'grid_model_picker.dart';import 'pane_header_actions.dart';+import 'pane_share_badge.dart';import 'pane_model_status.dart';/// The pane header's own horizontal inset.@@ -2891,6 +2892,17 @@ class _TerminalHeader extends StatelessWidget {),),const SizedBox(width: 8),+ // At the right edge, outside the right side's width budget:+ // a workspace pane's compact header leaves that only its close+ // button, and a status beside the name fills the name's row.+ if (agent != null && PaneShareStatus.visibleOf(context))+ PaneShareBadge(+ notifier: notifier,+ machineId: session.machineId,+ agentId: agent.id,+ name: agent.displayName,+ compact: narrow,+ ),// Which of the three paths carries this pane's bytes. Absent for a local machine's own// terminal, which has no such distinction and so gets no badge.//diff --git a/desktop/test/harness_share_status_test.dart b/desktop/test/harness_share_status_test.dartnew file mode 100644index 000000000..7c31258db--- /dev/null+++ b/desktop/test/harness_share_status_test.dart@@ -0,0 +1,115 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/core/config.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/state/harness_share_status.dart';+import 'package:harness/widgets/pane_share_badge.dart';++Map<String, dynamic> _answer({String? visibility, int people = 0}) => {+ 'link': visibility == null ? null : {'id': 'l1', 'visibility': visibility},+ 'shares': [+ for (var i = 0; i < people; i++) {'id': 's$i', 'email': '[email protected]'},+ ],+ 'collaboration': true,+};++void main() {+ group('harnessShareFrom', () {+ test('a public link reads Public, whoever was invited', () {+ // Share hides People while a link is public: invitations do not apply.+ expect(+ harnessShareFrom(_answer(visibility: 'public', people: 2)),+ const HarnessShare(HarnessShareAccess.public),+ );+ });++ test('a private link or invitations read Private, with the count', () {+ expect(+ harnessShareFrom(_answer(visibility: 'private'))?.label,+ 'Private',+ );+ expect(harnessShareFrom(_answer(people: 3))?.label, 'Private · 3');+ });++ test('no link, a link turned off, and no invitations: not shared', () {+ expect(harnessShareFrom(_answer()), isNull);+ expect(harnessShareFrom(_answer(visibility: 'off')), isNull);+ expect(harnessShareFrom(const {'error': 'UNSUPPORTED'}), isNull);+ });+ });++ group('HarnessShareStatus', () {+ test('asks once per harness and keeps the answer', () async {+ var asks = 0;+ final status = HarnessShareStatus((_, _) async {+ asks++;+ return _answer(visibility: 'public');+ });+ status.ensure('m', 'a');+ status.ensure('m', 'a');+ await pumpEventQueue();+ expect(asks, 1);+ expect(status.of('m', 'a')?.access, HarnessShareAccess.public);+ });++ test('a failed ask is asked again next time', () async {+ var asks = 0;+ final status = HarnessShareStatus((_, _) {+ asks++;+ if (asks == 1) throw StateError('offline');+ return Future.value(_answer(people: 1));+ });+ status.ensure('m', 'a');+ await pumpEventQueue();+ expect(status.of('m', 'a'), isNull);+ status.ensure('m', 'a');+ await pumpEventQueue();+ expect(asks, 2);+ expect(status.of('m', 'a')?.label, 'Private · 1');+ });++ test('stopping sharing clears the mark, and only changes notify', () {+ final status = HarnessShareStatus((_, _) => Completer<Never>().future);+ var notified = 0;+ status.addListener(() => notified++);+ status.record('m', 'a', _answer(visibility: 'private'));+ status.record('m', 'a', _answer(visibility: 'private'));+ expect(notified, 1);+ status.record('m', 'a', _answer(visibility: 'off'));+ expect(status.of('m', 'a'), isNull);+ expect(notified, 2);+ });+ });++ testWidgets('the pane badge names the share and hides when there is none', (+ tester,+ ) async {+ final app = AppNotifier(config: AppConfig.dev, authSession: AuthSession());+ addTearDown(app.dispose);+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: PaneShareBadge(+ notifier: app,+ machineId: 'm',+ agentId: 'a',+ name: 'Weather',+ ),+ ),+ ),+ );+ expect(find.byKey(const ValueKey('pane-share:m:a')), findsNothing);+ app.shareStatus.record('m', 'a', _answer(visibility: 'public'));+ await tester.pump();+ expect(find.text('Public'), findsOneWidget);+ app.shareStatus.record('m', 'a', _answer(visibility: 'private', people: 2));+ await tester.pump();+ expect(find.text('Private · 2'), findsOneWidget);+ app.shareStatus.record('m', 'a', _answer());+ await tester.pump();+ expect(find.byKey(const ValueKey('pane-share:m:a')), findsNothing);+ });+}diff --git a/desktop/test/terminal_panel_header_test.dart b/desktop/test/terminal_panel_header_test.dartindex d2ee8ba57..c1fe7718d 100644--- a/desktop/test/terminal_panel_header_test.dart+++ b/desktop/test/terminal_panel_header_test.dart@@ -9,6 +9,7 @@ import 'package:harness/core/models.dart';import 'package:harness/state/app_state.dart';import 'package:harness/terminal/terminal_session.dart';import 'package:harness/theme/app_theme.dart';+import 'package:harness/widgets/pane_share_badge.dart';import 'package:harness/widgets/terminal_panel.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';@@ -54,6 +55,9 @@ void main() {TerminalSession session, {double width = 900,bool withPr = false,+ bool compactHeader = false,+ bool showsShares = false,+ Map<String, dynamic>? share,}) async {// Wider than the pane, and stated: the default test window is 800px, and a// `SizedBox(width: 900)` inside it is silently clamped to 800.@@ -88,16 +92,21 @@ void main() {),];addTearDown(notifier.dispose);+ if (share != null) notifier.shareStatus.record('local', 'agent-1', share);await tester.pumpWidget(MaterialApp(home: Scaffold(body: SizedBox(width: width,height: 320,- child: TerminalPanel(- notifier: notifier,- session: session,- focused: true,+ child: PaneShareStatus(+ visible: showsShares,+ child: TerminalPanel(+ notifier: notifier,+ session: session,+ focused: true,+ compactHeader: compactHeader,+ ),),),),@@ -119,6 +128,63 @@ void main() {});}+ const publicShare = {+ 'link': {'id': 'l1', 'visibility': 'public'},+ 'shares': [],+ };++ // A workspace pane's header is compact: its right side's budget holds only+ // the close button, and a status beside the name fills the name's row. The+ // mark sits at the right edge either way.+ for (final width in [420.0, 900.0]) {+ for (final status in [+ TerminalSessionStatus.controlling,+ TerminalSessionStatus.takenOver,+ ]) {+ testWidgets(+ 'a shared pane says so at the right edge, ${status.name}, width $width',+ (tester) async {+ final session = sessionNamed('Desktop')..status = status;+ addTearDown(session.dispose);+ await pump(+ tester,+ session,+ width: width,+ compactHeader: true,+ showsShares: true,+ share: publicShare,+ );+ final badge = find.byKey(const ValueKey('pane-share:local:agent-1'));+ expect(badge, findsOneWidget);+ final rect = tester.getRect(badge);+ expect(rect.width, greaterThan(12));+ expect(+ rect.left,+ greaterThan(tester.getRect(find.text('Desktop')).right),+ );+ expect(rect.right, greaterThan(width - 40));+ expect(rect.right, lessThanOrEqualTo(width));+ if (width > 560) expect(find.text('Public'), findsOneWidget);+ expect(tester.takeException(), isNull);+ await tester.pumpWidget(const SizedBox());+ },+ );+ }+ }++ testWidgets('without the web scope a shared pane shows no mark', (+ tester,+ ) async {+ final session = sessionNamed('Desktop');+ addTearDown(session.dispose);+ await pump(tester, session, compactHeader: true, share: publicShare);+ expect(+ find.byKey(const ValueKey('pane-share:local:agent-1')),+ findsNothing,+ );+ await tester.pumpWidget(const SizedBox());+ });+// Each shape describes the path topology, not an assumed speed: direct link, intermediate hop,// backend server. Tooltip and semantics use the protocol names people will diagnose with.testWidgets(