Skip to content

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.

Protect Product Managers from Desktop Stop and Remove actions (#1632)

0xken157f12b8b29457
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 2dab61668..ac3b8debf 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -35,6 +35,7 @@ import '../models/model_search_catalog.dart';
import '../widgets/resting_section.dart'
show confirmStopInUse, confirmSwitchAnyway;
import '../widgets/session_close_dialog.dart';
+import '../super_tabs/lead_guard.dart';
import '../notify/system_notifications.dart';
import '../widgets/account_device_detail.dart';
import '../widgets/approve_device_code.dart';
@@ -2882,6 +2883,11 @@ class _SwarmScreenState extends State<SwarmScreen> {
SessionCloseItem(
name: targets[i].$2.displayName,
activity: activities[i],
+ protectionReason: superTabLeadProtectionReason(
+ app,
+ targets[i].$1,
+ targets[i].$2.id,
+ ),
machineName: showMachines
? app.stateOf(targets[i].$1)?.machine.displayName ??
targets[i].$1
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 1d3ca3a44..d9b994d9a 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -3485,7 +3485,12 @@ class AppNotifier extends ChangeNotifier {
// A Swarm pane is only a view into shared work. This guard also covers
// the close shortcut, native menu and whole-tab dismissal, including a
// regular tab becoming a Swarm while a close review is pending.
- if (tab.isSuperTab) return false;
+ // A Product Manager keeps running when its ordinary view closes too.
+ if (tab.isSuperTab ||
+ superTabs.leadProtectionReasonForHarness(machineId, agentId) !=
+ null) {
+ return false;
+ }
if (!swarms.contains(tab) ||
(wholeTab &&
(tab.panes.length != closing.length ||
diff --git a/desktop/lib/super_tabs/client.dart b/desktop/lib/super_tabs/client.dart
index fb26465e4..24218fc63 100644
--- a/desktop/lib/super_tabs/client.dart
+++ b/desktop/lib/super_tabs/client.dart
@@ -47,6 +47,24 @@ class SuperTabClient {
final _controllers = <String, Future<SuperTabController>>{};
final _loaded = <String, SuperTabController>{};
SuperTabController? peek(String id) => _loaded[id];
+ Iterable<SuperTabController> get loadedControllers => _loaded.values;
+
+ /// Native close actions name the machine's harness id, not the Swarm agent id.
+ String? leadProtectionReasonForHarness(String machineId, String harnessId) {
+ for (final controller in loadedControllers) {
+ final snapshot = controller.snapshot;
+ if (snapshot == null) continue;
+ for (final agent in snapshot.agents) {
+ if (agent.machineId != machineId || agent.harnessId != harnessId) {
+ continue;
+ }
+ if (snapshot.leadProtectionReason(agent.id) case final reason?) {
+ return reason;
+ }
+ }
+ }
+ return null;
+ }
/// The tabs closed on this computer. Only discovery says which of them the
/// account still belongs to.
diff --git a/desktop/lib/super_tabs/lead_guard.dart b/desktop/lib/super_tabs/lead_guard.dart
new file mode 100644
index 000000000..6b19fb303
--- /dev/null
+++ b/desktop/lib/super_tabs/lead_guard.dart
@@ -0,0 +1,10 @@
+import '../state/app_state.dart';
+
+/// The backend agent id is stable; native Stop/Delete uses the machine's harness id.
+String? superTabLeadProtectionReason(
+ AppNotifier app,
+ String machineId,
+ String harnessId,
+) {
+ return app.superTabs.leadProtectionReasonForHarness(machineId, harnessId);
+}
diff --git a/desktop/lib/super_tabs/machines.dart b/desktop/lib/super_tabs/machines.dart
index ac8cb3e69..5a4203c81 100644
--- a/desktop/lib/super_tabs/machines.dart
+++ b/desktop/lib/super_tabs/machines.dart
@@ -1095,6 +1095,17 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
if (a.machineId == machineId) a,
];
+ String? _removeReason(String machineId) {
+ final snapshot = c.snapshot;
+ if (snapshot == null) return null;
+ for (final agent in _agentsOn(machineId)) {
+ if (snapshot.leadProtectionReason(agent.id) case final reason?) {
+ return reason;
+ }
+ }
+ return null;
+ }
+
/// The Swarm owner removes any machine; anyone else, one that is all theirs: their contribution and
/// only their agents (backend `machine.remove`).
bool _canRemove(String machineId) {
@@ -1108,8 +1119,7 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
_agentsOn(machineId).every((a) => a.contributorId == c.accountId);
}
- /// Takes a machine out of this Swarm, and the Swarm's agents on it with it, after a yes. Their sessions keep
- /// running on the machine, as Remove from Swarm leaves one agent's (roster.dart).
+ /// Takes a machine out of this Swarm, and stops its ordinary agents after confirmation.
Future<void> _remove(_MachineView v) async {
final id = v.id, name = superTabMachineName(v.name);
var busy = false, attempted = false;
@@ -1127,8 +1137,10 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
pending?['machineId'] == id;
final available = _ids.contains(id) || checking || busy;
final permitted = _canRemove(id) || checking;
+ final reason = _removeReason(id);
final enabled =
permitted &&
+ reason == null &&
!busy &&
!c.saving &&
(checking || !c.hasPendingAction);
@@ -1156,12 +1168,13 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
- !available || !permitted
- ? 'This action is no longer available.'
- : shown == null
- ? 'The Swarm stops using it for new work.'
- : '$shown ${names.length == 1 ? 'leaves' : 'leave'} the Swarm with it and keep running on $name. '
- 'Any open task needs to be assigned again or closed.',
+ reason ??
+ (!available || !permitted
+ ? 'This action is no longer available.'
+ : shown == null
+ ? 'The Swarm stops using it for new work.'
+ : '$shown ${names.length == 1 ? 'leaves' : 'leave'} the Swarm with it and ${names.length == 1 ? 'stops' : 'stop'} on $name. '
+ 'Any open task needs to be assigned again or closed.'),
),
if (attempted && c.operationError != null) ...[
const SizedBox(height: 12),
@@ -1225,16 +1238,27 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
items: [
const PopupMenuItem(value: 'details', child: Text('Details')),
if (_canRemove(view.id))
- const PopupMenuItem(
+ PopupMenuItem(
key: ValueKey('super-machine-menu-remove'),
value: 'remove',
- child: Text('Remove from Swarm'),
+ enabled: _removeReason(view.id) == null,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const Text('Remove from Swarm'),
+ if (_removeReason(view.id) case final reason?) Text(reason),
+ ],
+ ),
),
],
);
if (!mounted) return;
if (choice == 'details') await _openDetails(view);
- if (choice == 'remove' && _canRemove(view.id)) await _remove(view);
+ if (choice == 'remove' &&
+ _canRemove(view.id) &&
+ _removeReason(view.id) == null) {
+ await _remove(view);
+ }
}
Future<void> _details(_MachineView v) {
@@ -1247,76 +1271,97 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
builder: (context) => SuperTabDialogScope(
controller: c,
requireWrite: false,
- child: AlertDialog(
- title: Row(
- children: [
- Expanded(child: Text(superTabMachineName(name))),
- // Out of the way of the everyday actions below: a quiet mark that turns red when pointed at.
- if (_canRemove(id))
- AppIconButton(
- key: const ValueKey('super-machine-remove'),
- icon: AppIcons.trash2,
- tooltip: 'Remove from Swarm',
- color: DesktopChrome.muted,
- destructive: true,
- onPressed: () {
- Navigator.pop(context);
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) unawaited(_remove(v));
- });
- },
- ),
- ],
- ),
- content: SuperTabMachineDetails(
- name: name,
- owner: person?.email,
- status: details,
- // Details follow the same freshness rule as the row and its disclosure.
- resources: dim ? null : value,
- cwd: shared?['cwd'] as String?,
- engines: allowed,
- accounts: dim ? const [] : accounts,
- ),
- actions: [
- if (shared != null && contributor == c.accountId)
- TextButton(
- onPressed: () async {
- final result = await c.command({
- 'type': 'machine.pause',
- 'machineId': id,
- 'paused': !paused,
- });
- if (context.mounted && result != null) {
- Navigator.pop(context);
- }
- },
- child: Text(paused ? 'Resume new work' : 'Pause new work'),
- ),
- if (contributor == c.accountId)
- TextButton(
- onPressed: () {
- Navigator.pop(context);
- unawaited(_contribute(existing: shared ?? {'machineId': id}));
- },
- child: const Text('Configure'),
+ child: ListenableBuilder(
+ listenable: c,
+ builder: (context, _) {
+ final removeReason = _removeReason(id);
+ return AlertDialog(
+ title: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Expanded(child: Text(superTabMachineName(name))),
+ // Out of the way of the everyday actions below: a quiet mark that turns red when pointed at.
+ if (_canRemove(id))
+ AppIconButton(
+ key: const ValueKey('super-machine-remove'),
+ icon: AppIcons.trash2,
+ tooltip: removeReason ?? 'Remove from Swarm',
+ color: DesktopChrome.muted,
+ destructive: true,
+ onPressed: removeReason != null
+ ? null
+ : () {
+ if (_removeReason(id) != null) return;
+ Navigator.pop(context);
+ WidgetsBinding.instance.addPostFrameCallback((
+ _,
+ ) {
+ if (mounted) unawaited(_remove(v));
+ });
+ },
+ ),
+ ],
+ ),
+ if (_canRemove(id) && removeReason != null)
+ Text(removeReason, style: DesktopChrome.metadata()),
+ ],
),
- if (c.canWrite && c.selected != null)
- TextButton(
- onPressed: () {
- final group = c.selected!;
- Navigator.pop(context);
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) widget.onAddAgent(group);
- });
- },
- child: const Text('Attach running agent'),
+ content: SuperTabMachineDetails(
+ name: name,
+ owner: person?.email,
+ status: details,
+ // Details follow the same freshness rule as the row and its disclosure.
+ resources: dim ? null : value,
+ cwd: shared?['cwd'] as String?,
+ engines: allowed,
+ accounts: dim ? const [] : accounts,
),
- TextButton(
- onPressed: () => Navigator.pop(context),
- child: const Text('Close'),
- ),
- ],
+ actions: [
+ if (shared != null && contributor == c.accountId)
+ TextButton(
+ onPressed: () async {
+ final result = await c.command({
+ 'type': 'machine.pause',
+ 'machineId': id,
+ 'paused': !paused,
+ });
+ if (context.mounted && result != null) {
+ Navigator.pop(context);
+ }
+ },
+ child: Text(paused ? 'Resume new work' : 'Pause new work'),
+ ),
+ if (contributor == c.accountId)
+ TextButton(
+ onPressed: () {
+ Navigator.pop(context);
+ unawaited(
+ _contribute(existing: shared ?? {'machineId': id}),
+ );
+ },
+ child: const Text('Configure'),
+ ),
+ if (c.canWrite && c.selected != null)
+ TextButton(
+ onPressed: () {
+ final group = c.selected!;
+ Navigator.pop(context);
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) widget.onAddAgent(group);
+ });
+ },
+ child: const Text('Attach running agent'),
+ ),
+ TextButton(
+ onPressed: () => Navigator.pop(context),
+ child: const Text('Close'),
+ ),
+ ],
+ );
+ },
),
),
);
diff --git a/desktop/lib/super_tabs/model.dart b/desktop/lib/super_tabs/model.dart
index 0346881a4..d6930ed4a 100644
--- a/desktop/lib/super_tabs/model.dart
+++ b/desktop/lib/super_tabs/model.dart
@@ -192,9 +192,17 @@ class SuperTabSnapshot {
bool isProjectLead(String conversationId) =>
projects.any((p) => p.leadConversationId == conversationId);
- bool isLead(String agentId) => projects.any(
- (p) => conversation(p.leadConversationId)?.leadId == agentId,
- );
+ SuperTabProject? leadProjectForAgent(String agentId) => projects
+ .where((p) => conversation(p.leadConversationId)?.leadId == agentId)
+ .firstOrNull;
+
+ bool isLead(String agentId) => leadProjectForAgent(agentId) != null;
+
+ String? leadProtectionReason(String agentId) {
+ final project = leadProjectForAgent(agentId);
+ if (project == null) return null;
+ return '${agentName(agentId)} is the Product Manager of project ${project.name}. Delete the project first.';
+ }
/// The agents of a workgroup whose role is Reviewer.
List<SuperTabAgent> reviewers(SuperTabConversation group) => [
diff --git a/desktop/lib/super_tabs/project_options.dart b/desktop/lib/super_tabs/project_options.dart
index f0b79f33a..1059c820f 100644
--- a/desktop/lib/super_tabs/project_options.dart
+++ b/desktop/lib/super_tabs/project_options.dart
@@ -298,7 +298,7 @@ Future<void> _deleteProject(
children: [
Text(
available
- ? '“${current?.name ?? project.name}” and all of its conversations will be permanently deleted. This can’t be undone.'
+ ? '“${current?.name ?? project.name}” and all of its conversations will be permanently deleted. Its Product Manager’s session will close too. This can’t be undone.'
: 'This project is no longer available.',
style: DesktopChrome.text(),
),
diff --git a/desktop/lib/super_tabs/roster.dart b/desktop/lib/super_tabs/roster.dart
index 725e404bc..414e60599 100644
--- a/desktop/lib/super_tabs/roster.dart
+++ b/desktop/lib/super_tabs/roster.dart
@@ -56,6 +56,9 @@ class _SuperTabRosterState extends State<SuperTabRoster> {
bool _canRemove(SuperTabAgent agent) =>
c.canWrite && (c.isOwner || agent.contributorId == c.accountId);
+ String? _removeReason(SuperTabAgent agent) =>
+ c.snapshot?.leadProtectionReason(agent.id);
+
Future<void> _remove(SuperTabAgent agent) async {
var busy = false, attempted = false;
final name = c.snapshot!.agentName(agent.id);
@@ -81,8 +84,10 @@ class _SuperTabRosterState extends State<SuperTabRoster> {
pending?['agentId'] == agent.id;
final available = current != null || checking || busy;
final permitted = _canRemove(current ?? agent);
+ final reason = _removeReason(current ?? agent);
final enabled =
permitted &&
+ reason == null &&
!busy &&
!c.saving &&
(checking || !c.hasPendingAction);
@@ -102,9 +107,10 @@ class _SuperTabRosterState extends State<SuperTabRoster> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
- available && permitted
- ? 'Any open task needs to be assigned again or closed. Its session on $machine is left to its owner.'
- : 'This action is no longer available.',
+ reason ??
+ (available && permitted
+ ? 'Any open task needs to be assigned again or closed. Its session on $machine will stop.'
+ : 'This action is no longer available.'),
),
if (attempted && c.operationError != null) ...[
const SizedBox(height: 12),
@@ -301,16 +307,27 @@ class _SuperTabRosterState extends State<SuperTabRoster> {
items: [
const PopupMenuItem(value: 'details', child: Text('Details')),
if (_canRemove(c.snapshot?.agent(agent.id) ?? agent))
- const PopupMenuItem(
+ PopupMenuItem(
value: 'remove',
- child: Text('Remove from Swarm'),
+ enabled: _removeReason(agent) == null,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const Text('Remove from Swarm'),
+ if (_removeReason(agent) case final reason?) Text(reason),
+ ],
+ ),
),
],
);
if (choice == 'details' && mounted) await _details(agent);
if (choice == 'remove' && mounted) {
final current = c.snapshot?.agent(agent.id);
- if (current != null && _canRemove(current)) await _remove(current);
+ if (current != null &&
+ _canRemove(current) &&
+ _removeReason(current) == null) {
+ await _remove(current);
+ }
}
},
child: ListTile(
diff --git a/desktop/lib/super_tabs/sharing.dart b/desktop/lib/super_tabs/sharing.dart
index e11fc1e09..ed7778a2a 100644
--- a/desktop/lib/super_tabs/sharing.dart
+++ b/desktop/lib/super_tabs/sharing.dart
@@ -236,6 +236,7 @@ class _SwarmSharingDialogState extends State<SwarmSharingDialog> {
}
Future<void> _remove(SuperTabPerson person) async {
+ if (_removeReason(person) != null) return;
final leaving = person.id == c.accountId;
final confirmed = await showAppDialog<bool>(
context: context,
@@ -268,6 +269,18 @@ class _SwarmSharingDialogState extends State<SwarmSharingDialog> {
if (result != null && leaving && mounted) Navigator.pop(context);
}
+ String? _removeReason(SuperTabPerson person) {
+ final snapshot = c.snapshot;
+ if (snapshot == null) return null;
+ for (final agent in snapshot.agents) {
+ if (agent.contributorId != person.id) continue;
+ if (snapshot.leadProtectionReason(agent.id) case final reason?) {
+ return reason;
+ }
+ }
+ return null;
+ }
+
Widget _select({
required Key key,
required String value,
@@ -330,6 +343,8 @@ class _SwarmSharingDialogState extends State<SwarmSharingDialog> {
: 'Can collaborate',
style: DesktopChrome.metadata(),
),
+ if (_removeReason(person) case final reason?)
+ Text(reason, style: DesktopChrome.metadata()),
],
),
),
@@ -337,7 +352,9 @@ class _SwarmSharingDialogState extends State<SwarmSharingDialog> {
(c.isOwner || person.id == c.accountId)) ...[
const SizedBox(width: 8),
TextButton(
- onPressed: _busy ? null : () => _remove(person),
+ onPressed: _busy || _removeReason(person) != null
+ ? null
+ : () => _remove(person),
child: Text(person.id == c.accountId ? 'Leave' : 'Remove'),
),
],
diff --git a/desktop/lib/widgets/delete_agent_dialog.dart b/desktop/lib/widgets/delete_agent_dialog.dart
index 56241232f..e056aef07 100644
--- a/desktop/lib/widgets/delete_agent_dialog.dart
+++ b/desktop/lib/widgets/delete_agent_dialog.dart
@@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
import '../core/models.dart';
import '../shortcuts/app_keymap.dart';
import '../state/app_state.dart';
+import '../super_tabs/lead_guard.dart';
+import '../super_tabs/controller.dart';
import '../shared/theme/app_theme.dart' as grid;
import 'desktop_chrome.dart';
import 'desktop_prompt_surface.dart';
@@ -50,6 +52,11 @@ class _StopAgentPrompt extends StatefulWidget {
}
class _StopAgentPromptState extends State<_StopAgentPrompt> {
+ String? get _protectionReason => superTabLeadProtectionReason(
+ widget.notifier,
+ widget.machineId,
+ widget.agentId,
+ );
Agent? get _agent => widget.notifier
.stateOf(widget.machineId)
?.agents
@@ -62,6 +69,7 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
final _promptFocus = FocusNode(debugLabel: 'Pending stop');
final _body = ScrollController();
final _announcer = BoxAnnouncer();
+ final _observedTabs = <SuperTabController>[];
late final Future<String?> Function() _requestStop;
bool _stopping = false;
String? _error;
@@ -69,12 +77,19 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
@override
void initState() {
super.initState();
+ _observedTabs.addAll(widget.notifier.superTabs.loadedControllers);
+ for (final tab in _observedTabs) {
+ tab.addListener(_onTabChanged);
+ }
_requestStop = widget.notifier.prepareAgentStop(
widget.machineId,
widget.agentId,
);
- if (widget.notifier.pendingAgentStop(widget.machineId, widget.agentId)
- case final pending?) {
+ final pending = widget.notifier.pendingAgentStop(
+ widget.machineId,
+ widget.agentId,
+ );
+ if (_protectionReason == null && pending != null) {
_stopping = true;
unawaited(_finish(pending));
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -85,6 +100,10 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
}
}
+ void _onTabChanged() {
+ if (mounted) setState(() {});
+ }
+
void _focusCancel() => WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && ModalRoute.of(context)?.isCurrent != false) {
_cancel.requestFocus();
@@ -93,6 +112,9 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
@override
void dispose() {
+ for (final tab in _observedTabs) {
+ tab.removeListener(_onTabChanged);
+ }
_cancel.dispose();
_promptFocus.dispose();
_body.dispose();
@@ -113,7 +135,7 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
}
void _stop() {
- if (_stopping) return;
+ if (_stopping || _protectionReason != null) return;
// The Stop button is removed while pending; keep Escape and custom keys
// in the prompt instead of letting focus fall back to the terminal.
_promptFocus.requestFocus();
@@ -180,22 +202,28 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
],
const SizedBox(height: DesktopChrome.groupGap),
Text(
- widget.terminal
- ? 'End this shell and anything running in it? Files are kept.'
- // A cloud agent stops where its maker lets it: Devin Cloud
- // and Cursor Cloud sleep; Fo keeps working on its own.
- : _cloud != null
- ? (_engine == 'fo'
- ? 'Stop following this harness here? Fo keeps working on its own, and its conversation is kept.'
- : 'Stop this harness? Its session goes to sleep and stops spending; its conversation is kept, and a message wakes it.')
- : 'Stop this harness? Project files and saved conversation history are kept.',
+ _protectionReason ??
+ (widget.terminal
+ ? 'End this shell and anything running in it? Files are kept.'
+ // A cloud agent stops where its maker lets it: Devin Cloud
+ // and Cursor Cloud sleep; Fo keeps working on its own.
+ : _cloud != null
+ ? (_engine == 'fo'
+ ? 'Stop following this harness here? Fo keeps working on its own, and its conversation is kept.'
+ : 'Stop this harness? Its session goes to sleep and stops spending; its conversation is kept, and a message wakes it.')
+ : 'Stop this harness? Project files and saved conversation history are kept.'),
style: DesktopChrome.text(size: 13),
),
- const SizedBox(height: 8),
- Text(
- 'Its panes close across tabs. Switching tabs keeps it running.',
- style: DesktopChrome.text(size: 13, color: DesktopChrome.muted),
- ),
+ if (_protectionReason == null) ...[
+ const SizedBox(height: 8),
+ Text(
+ 'Its panes close across tabs. Switching tabs keeps it running.',
+ style: DesktopChrome.text(
+ size: 13,
+ color: DesktopChrome.muted,
+ ),
+ ),
+ ],
if (_stopping) ...[
const SizedBox(height: 12),
Text(
@@ -231,10 +259,11 @@ class _StopAgentPromptState extends State<_StopAgentPrompt> {
if (!_stopping)
Tooltip(
message:
+ _protectionReason ??
'Stop · ${terminalPromptHint(context, 'picker.accept', 'enter')}',
child: FilledButton(
key: const Key('agent-stop-confirm'),
- onPressed: _stop,
+ onPressed: _protectionReason == null ? _stop : null,
style: grid.dangerButtonStyle(),
child: const Text('Stop'),
),
diff --git a/desktop/lib/widgets/delete_harness_dialog.dart b/desktop/lib/widgets/delete_harness_dialog.dart
index 347a455a2..692515a33 100644
--- a/desktop/lib/widgets/delete_harness_dialog.dart
+++ b/desktop/lib/widgets/delete_harness_dialog.dart
@@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import '../shortcuts/app_keymap.dart';
import '../state/app_state.dart';
+import '../super_tabs/lead_guard.dart';
+import '../super_tabs/controller.dart';
import '../shared/theme/app_theme.dart' as grid;
import 'desktop_chrome.dart';
import 'desktop_prompt_surface.dart';
@@ -45,19 +47,33 @@ class _DeleteHarnessPrompt extends StatefulWidget {
}
class _DeleteHarnessPromptState extends State<_DeleteHarnessPrompt> {
+ String? get _protectionReason => superTabLeadProtectionReason(
+ widget.notifier,
+ widget.machineId,
+ widget.agentId,
+ );
final _cancel = FocusNode(debugLabel: 'Cancel delete');
final _promptFocus = FocusNode(debugLabel: 'Pending delete');
final _body = ScrollController();
final _announcer = BoxAnnouncer();
+ final _observedTabs = <SuperTabController>[];
bool _deleting = false;
String? _error;
@override
void initState() {
super.initState();
+ _observedTabs.addAll(widget.notifier.superTabs.loadedControllers);
+ for (final tab in _observedTabs) {
+ tab.addListener(_onTabChanged);
+ }
_focusCancel();
}
+ void _onTabChanged() {
+ if (mounted) setState(() {});
+ }
+
void _focusCancel() => WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && ModalRoute.of(context)?.isCurrent != false) {
_cancel.requestFocus();
@@ -66,6 +82,9 @@ class _DeleteHarnessPromptState extends State<_DeleteHarnessPrompt> {
@override
void dispose() {
+ for (final tab in _observedTabs) {
+ tab.removeListener(_onTabChanged);
+ }
_cancel.dispose();
_promptFocus.dispose();
_body.dispose();
@@ -85,7 +104,7 @@ class _DeleteHarnessPromptState extends State<_DeleteHarnessPrompt> {
}
Future<void> _delete() async {
- if (_deleting) return;
+ if (_deleting || _protectionReason != null) return;
_promptFocus.requestFocus();
setState(() {
_deleting = true;
@@ -135,25 +154,28 @@ class _DeleteHarnessPromptState extends State<_DeleteHarnessPrompt> {
widget.name,
style: DesktopChrome.text(size: 14, medium: true),
),
- if (widget.notifier
- .stateOf(widget.machineId)
- ?.machine
- .displayName
+ if (widget.notifier.stateOf(widget.machineId)?.machine.displayName
case final machine?) ...[
const SizedBox(height: 4),
Text(machine, style: DesktopChrome.metadata()),
],
const SizedBox(height: DesktopChrome.groupGap),
Text(
- 'Delete this harness and its saved conversation? It stops if '
- 'running, and it cannot be opened again. Project files are kept.',
+ _protectionReason ??
+ 'Delete this harness and its saved conversation? It stops if '
+ 'running, and it cannot be opened again. Project files are kept.',
style: DesktopChrome.text(size: 13),
),
- const SizedBox(height: 8),
- Text(
- 'To keep the conversation to reopen later, use Stop Harness instead.',
- style: DesktopChrome.text(size: 13, color: DesktopChrome.muted),
- ),
+ if (_protectionReason == null) ...[
+ const SizedBox(height: 8),
+ Text(
+ 'To keep the conversation to reopen later, use Stop Harness instead.',
+ style: DesktopChrome.text(
+ size: 13,
+ color: DesktopChrome.muted,
+ ),
+ ),
+ ],
],
),
),
@@ -179,10 +201,13 @@ class _DeleteHarnessPromptState extends State<_DeleteHarnessPrompt> {
if (!_deleting)
Tooltip(
message:
+ _protectionReason ??
'Delete · ${terminalPromptHint(context, 'picker.accept', 'enter')}',
child: FilledButton(
key: const Key('agent-delete-confirm'),
- onPressed: () => unawaited(_delete()),
+ onPressed: _protectionReason == null
+ ? () => unawaited(_delete())
+ : null,
style: grid.dangerButtonStyle(),
child: const Text('Delete'),
),
diff --git a/desktop/lib/widgets/session_close_dialog.dart b/desktop/lib/widgets/session_close_dialog.dart
index c94b15873..5c131060b 100644
--- a/desktop/lib/widgets/session_close_dialog.dart
+++ b/desktop/lib/widgets/session_close_dialog.dart
@@ -11,11 +11,13 @@ class SessionCloseItem {
required this.name,
required this.activity,
this.machineName,
+ this.protectionReason,
});
final String name;
final String activity;
final String? machineName;
+ final String? protectionReason;
bool get completed => activity == 'stopped' || activity == 'deferred';
}
@@ -104,8 +106,14 @@ class _SessionClosePromptState extends State<_SessionClosePrompt> {
final scope = widget.tabName == null
? 'this pane'
: 'the tab “${widget.tabName}”';
- final description = widget.error ?? _summary(attention);
- final visible = widget.error == null ? attention : widget.sessions;
+ final protectionReason = widget.sessions
+ .map((item) => item.protectionReason)
+ .whereType<String>()
+ .firstOrNull;
+ final description = widget.error ?? protectionReason ?? _summary(attention);
+ final visible = widget.error == null && protectionReason == null
+ ? attention
+ : widget.sessions;
final completed = widget.sessions.where((item) => item.completed).length;
return TerminalPromptKeys(
focusNode: _keys,
@@ -123,7 +131,9 @@ class _SessionClosePromptState extends State<_SessionClosePrompt> {
Text(description, style: DesktopChrome.text(size: 13)),
const SizedBox(height: DesktopChrome.controlGap),
Text(
- widget.error == null
+ protectionReason != null
+ ? 'You can close $scope. The Product Manager will keep running.'
+ : widget.error == null
? 'Stopping ${count == 1 ? 'this session' : 'all $count sessions'} will close $scope. History will be saved.'
: widget.tabName == null
? 'You can close this pane. The session may still be running.'
@@ -173,9 +183,19 @@ class _SessionClosePromptState extends State<_SessionClosePrompt> {
FilledButton(
key: const Key('session-close-now'),
style: grid.dangerButtonStyle(),
- onPressed: () => _choose('now'),
+ onPressed: protectionReason == null
+ ? () => _choose('now')
+ : null,
child: const Text('Stop'),
),
+ if (protectionReason != null)
+ FilledButton(
+ key: const Key('session-close-view'),
+ onPressed: () => _choose('close_view'),
+ child: Text(
+ widget.tabName == null ? 'Close pane' : 'Close Tab',
+ ),
+ ),
] else
FilledButton(
key: const Key('session-close-view'),
diff --git a/desktop/test/session_close_dialog_test.dart b/desktop/test/session_close_dialog_test.dart
index 9e4ec16ef..6b6ee87c6 100644
--- a/desktop/test/session_close_dialog_test.dart
+++ b/desktop/test/session_close_dialog_test.dart
@@ -13,6 +13,49 @@ import 'package:harness/widgets/session_close_dialog.dart';
import 'box_render_preview_test.dart' show loadPreviewFonts;
void main() {
+ testWidgets(
+ 'a protected Product Manager is explained and cannot be stopped',
+ (tester) async {
+ String? choice;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () async => choice = await showSessionCloseDialog(
+ context,
+ [
+ const SessionCloseItem(
+ name: 'Quinn',
+ activity: 'working',
+ protectionReason: 'Quinn is the Product Manager of project Pilot. Delete the project first.',
+ ),
+ ],
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ expect(
+ find.textContaining('Product Manager of project Pilot'),
+ findsOneWidget,
+ );
+ expect(
+ tester
+ .widget<FilledButton>(find.byKey(const Key('session-close-now')))
+ .onPressed,
+ isNull,
+ );
+ await tester.tap(find.byKey(const Key('session-close-view')));
+ await tester.pumpAndSettle();
+ expect(choice, 'close_view');
+ },
+ );
+
final renderDir = kIsWeb
? null
: Platform.environment['SESSION_CLOSE_RENDER_DIR'];
diff --git a/desktop/test/super_tab_lead_actions_test.dart b/desktop/test/super_tab_lead_actions_test.dart
new file mode 100644
index 000000000..d77e15de0
--- /dev/null
+++ b/desktop/test/super_tab_lead_actions_test.dart
@@ -0,0 +1,441 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/widgets/desktop_prompt_surface.dart';
+import 'package:harness/widgets/delete_agent_dialog.dart';
+import 'package:harness/widgets/delete_harness_dialog.dart';
+
+import 'super_tab_launch_test.dart'
+ show SuperTabFixtureConnection, SuperTabLaunchFixture, tabId;
+import 'swarm_screen_test.dart' show mount, terminal;
+
+class _CloseFixtureConnection extends SuperTabFixtureConnection {
+ _CloseFixtureConnection(super.store);
+
+ @override
+ Future<Map<String, dynamic>> request(
+ String type, {
+ Map<String, dynamic> payload = const {},
+ Duration timeout = const Duration(seconds: 20),
+ }) async {
+ if (type != 'agent_close') {
+ return super.request(type, payload: payload, timeout: timeout);
+ }
+ calls.add((type, Map.of(payload)));
+ if (payload['mode'] == 'inspect') return {'activity': 'working'};
+ await event('agent_deleted', {'agentId': payload['agentId']});
+ return {'closed': true};
+ }
+}
+
+void main() {
+ for (final action in ['stop', 'stop terminal', 'delete']) {
+ testWidgets('$action is disabled for a project Product Manager', (
+ tester,
+ ) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'pm',
+ 'name': 'Quinn',
+ 'machineId': 'm',
+ 'harnessId': 'native-pm',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ (f.connection.server.state['conversations'] as List)[0]['leadId'] = 'pm';
+ f.app.machineStates['m']!.agents = [
+ Agent(
+ id: 'native-pm',
+ name: 'Quinn',
+ engine: action == 'stop terminal' ? 'terminal' : 'claude',
+ ),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => action == 'delete'
+ ? confirmDeleteHarness(
+ context,
+ f.app,
+ 'm',
+ 'native-pm',
+ 'Quinn',
+ )
+ : confirmDeleteAgent(
+ context,
+ f.app,
+ 'm',
+ 'native-pm',
+ 'Quinn',
+ engine: action == 'stop terminal'
+ ? 'terminal'
+ : 'claude',
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ expect(
+ find.text(
+ 'Quinn is the Product Manager of project Pilot. Delete the project first.',
+ ),
+ findsOneWidget,
+ );
+ if (action == 'delete') {
+ expect(find.textContaining('To keep the conversation'), findsNothing);
+ } else {
+ expect(
+ find.textContaining('Its panes close across tabs'),
+ findsNothing,
+ );
+ }
+ final confirm = find.byKey(
+ Key(action == 'delete' ? 'agent-delete-confirm' : 'agent-stop-confirm'),
+ );
+ expect(tester.widget<FilledButton>(confirm).onPressed, isNull);
+ expect(
+ f.connection.calls.where((call) => call.$1 == 'agent_delete'),
+ isEmpty,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ });
+ }
+
+ testWidgets('ordinary Swarm agent keeps Stop and Delete available', (
+ tester,
+ ) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'worker',
+ 'name': 'Sage',
+ 'machineId': 'm',
+ 'harnessId': 'native-worker',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ f.app.machineStates['m']!.agents = [
+ const Agent(id: 'native-worker', name: 'Sage', engine: 'claude'),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ Future<void> mount(bool delete) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => delete
+ ? confirmDeleteHarness(
+ context,
+ f.app,
+ 'm',
+ 'native-worker',
+ 'Sage',
+ )
+ : confirmDeleteAgent(
+ context,
+ f.app,
+ 'm',
+ 'native-worker',
+ 'Sage',
+ engine: 'claude',
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ final button = find.byKey(
+ Key(delete ? 'agent-delete-confirm' : 'agent-stop-confirm'),
+ );
+ expect(tester.widget<FilledButton>(button).onPressed, isNotNull);
+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));
+ await tester.pumpAndSettle();
+ }
+
+ await mount(false);
+ await mount(true);
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ });
+
+ testWidgets('a closed Swarm view still protects its Product Manager', (
+ tester,
+ ) async {
+ final f = SuperTabLaunchFixture();
+ final swarmId = f.app.activeSwarmId;
+ f.app.bindSuperTab(swarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'pm',
+ 'name': 'Quinn',
+ 'machineId': 'm',
+ 'harnessId': 'native-pm',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ (f.connection.server.state['conversations'] as List)[0]['leadId'] = 'pm';
+ f.app.machineStates['m']!.agents = [
+ const Agent(id: 'native-pm', name: 'Quinn', engine: 'claude'),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await f.app.requestCloseSwarm(swarmId);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => confirmDeleteAgent(
+ context,
+ f.app,
+ 'm',
+ 'native-pm',
+ 'Quinn',
+ engine: 'claude',
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ expect(
+ find.textContaining('Product Manager of project Pilot'),
+ findsOneWidget,
+ );
+ expect(
+ tester
+ .widget<FilledButton>(find.byKey(const Key('agent-stop-confirm')))
+ .onPressed,
+ isNull,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ });
+
+ testWidgets(
+ 'closing an ordinary pane keeps a Swarm Product Manager running',
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ final swarmId = f.app.activeSwarmId;
+ f.app.bindSuperTab(swarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'pm',
+ 'name': 'Quinn',
+ 'machineId': 'm',
+ 'harnessId': 'native-pm',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ (f.connection.server.state['conversations'] as List)[0]['leadId'] = 'pm';
+ f.app.machineStates['m']!.agents = [
+ Agent(
+ id: 'native-pm',
+ name: 'Quinn',
+ engine: 'claude',
+ sessionId: 'saved',
+ closeSupported: true,
+ terminalAvailable: true,
+ ),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await f.app.requestCloseSwarm(swarmId);
+ final pane = f.app.adoptSessionForTest(terminal('native-pm', []));
+ await mount(tester, f.app);
+ unawaited(f.app.requestClosePane(pane.id));
+ await tester.pumpAndSettle();
+ expect(find.byKey(const Key('session-close-now')), findsNothing);
+ expect(f.app.allPanes, isEmpty);
+ expect(
+ f.connection.calls.where((call) => call.$1 == 'agent_close'),
+ isEmpty,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ },
+ );
+
+ testWidgets(
+ 'closing a mixed tab stops its Engineer but keeps its Product Manager',
+ (tester) async {
+ final f = SuperTabLaunchFixture(
+ connectionFactory: (store) => _CloseFixtureConnection(store),
+ );
+ final swarmId = f.app.activeSwarmId;
+ f.app.bindSuperTab(swarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'pm',
+ 'name': 'Quinn',
+ 'machineId': 'm',
+ 'harnessId': 'native-pm',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ {
+ 'id': 'worker',
+ 'name': 'Sage',
+ 'machineId': 'm',
+ 'harnessId': 'native-worker',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ (f.connection.server.state['conversations'] as List)[0]['leadId'] = 'pm';
+ Agent closeable(String id, String name) => Agent(
+ id: id,
+ name: name,
+ engine: 'claude',
+ createdAt: DateTime.utc(2026, 9, 30, 12),
+ sessionId: 'saved-$id',
+ closeSupported: true,
+ terminalAvailable: true,
+ );
+ f.app.machineStates['m']!.agents = [
+ closeable('native-pm', 'Quinn'),
+ closeable('native-worker', 'Sage'),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await f.app.requestCloseSwarm(swarmId);
+ f.app.adoptSessionForTest(terminal('native-pm', []));
+ f.app.adoptSessionForTest(terminal('native-worker', []));
+ final ordinaryTab = f.app.activeSwarm;
+ await mount(tester, f.app);
+
+ unawaited(f.app.requestCloseSwarm(ordinaryTab.id));
+ await tester.pumpAndSettle();
+ final closePrompt = find.byType(DesktopPromptSurface);
+ final stop = find.descendant(
+ of: closePrompt,
+ matching: find.widgetWithText(FilledButton, 'Stop'),
+ );
+ expect(stop, findsOneWidget);
+ expect(tester.widget<FilledButton>(stop).onPressed, isNotNull);
+ expect(
+ find.descendant(of: closePrompt, matching: find.text('Sage')),
+ findsOneWidget,
+ );
+ expect(
+ find.descendant(of: closePrompt, matching: find.text('Quinn')),
+ findsNothing,
+ );
+ await tester.tap(stop);
+ await tester.pumpAndSettle();
+
+ final closes = f.connection.calls
+ .where((call) => call.$1 == 'agent_close')
+ .map((call) => call.$2)
+ .toList();
+ expect(closes.map((call) => call['agentId']), [
+ 'native-worker',
+ 'native-worker',
+ ]);
+ expect(closes.map((call) => call['mode']), ['inspect', 'now']);
+ expect(f.app.swarms, isNot(contains(ordinaryTab)));
+ expect(
+ f.app.machineStates['m']!.agents.any((a) => a.id == 'native-pm'),
+ isTrue,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ },
+ );
+ testWidgets('Stop becomes disabled if its agent becomes Product Manager', (
+ tester,
+ ) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['agents'] = [
+ {
+ 'id': 'worker',
+ 'name': 'Sage',
+ 'machineId': 'm',
+ 'harnessId': 'native-worker',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ f.app.machineStates['m']!.agents = [
+ const Agent(id: 'native-worker', name: 'Sage', engine: 'claude'),
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => confirmDeleteAgent(
+ context,
+ f.app,
+ 'm',
+ 'native-worker',
+ 'Sage',
+ engine: 'claude',
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ expect(
+ tester
+ .widget<FilledButton>(find.byKey(const Key('agent-stop-confirm')))
+ .onPressed,
+ isNotNull,
+ );
+ (f.connection.server.state['conversations'] as List)[0]['leadId'] =
+ 'worker';
+ await c.refresh();
+ await tester.pumpAndSettle();
+ expect(
+ find.textContaining('Product Manager of project Pilot'),
+ findsOneWidget,
+ );
+ expect(
+ tester
+ .widget<FilledButton>(find.byKey(const Key('agent-stop-confirm')))
+ .onPressed,
+ isNull,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ });
+}
diff --git a/desktop/test/super_tab_machines_test.dart b/desktop/test/super_tab_machines_test.dart
index 0ef302f55..67ab38791 100644
--- a/desktop/test/super_tab_machines_test.dart
+++ b/desktop/test/super_tab_machines_test.dart
@@ -918,7 +918,7 @@ void main() {
expect(find.text('Remove Studio from this Swarm?'), findsOneWidget);
expect(
find.textContaining(
- 'Mira and River leave the Swarm with it and keep running on Studio.',
+ 'Mira and River leave the Swarm with it and stop on Studio.',
),
findsOneWidget,
);
@@ -982,6 +982,56 @@ void main() {
c.dispose();
});
+ testWidgets('machine with a Product Manager cannot be removed', (
+ tester,
+ ) async {
+ final server = ConversationServer();
+ server.state['machines'] = [machine('owner')];
+ server.state['agents'] = [agent('a1', 'owner')];
+ (server.state['conversations'] as List)[0]['leadId'] = 'a1';
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
+ await tester.tap(find.byKey(const ValueKey('super-machine-studio')));
+ await tester.pumpAndSettle();
+ final remove = find.byKey(const ValueKey('super-machine-remove'));
+ expect(remove, findsOneWidget);
+ expect(
+ find.text(
+ 'Mira is the Product Manager of project Pilot. Delete the project first.',
+ ),
+ findsOneWidget,
+ );
+ expect(server.posts, isEmpty);
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ });
+
+ testWidgets('machine details disable Remove when its agent becomes Product Manager', (
+ tester,
+ ) async {
+ final server = ConversationServer();
+ server.state['machines'] = [machine('owner')];
+ server.state['agents'] = [agent('a1', 'owner')];
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
+ await tester.tap(find.byKey(const ValueKey('super-machine-studio')));
+ await tester.pumpAndSettle();
+ (server.state['conversations'] as List)[0]['leadId'] = 'a1';
+ await c.refresh();
+ await tester.pumpAndSettle();
+ expect(find.textContaining('Product Manager of project Pilot'), findsOneWidget);
+ final remove = tester.widget<AppIconButton>(
+ find.byKey(const ValueKey('super-machine-remove')),
+ );
+ expect(remove.onPressed, isNull);
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ });
+
testWidgets('a collaborator removes only a machine that is all theirs', (
tester,
) async {
diff --git a/desktop/test/super_tab_project_delete_test.dart b/desktop/test/super_tab_project_delete_test.dart
index 49e3fa95b..89bf1b253 100644
--- a/desktop/test/super_tab_project_delete_test.dart
+++ b/desktop/test/super_tab_project_delete_test.dart
@@ -60,7 +60,7 @@ void main() {
expect(server.posts, isEmpty);
expect(
find.text(
- '“Pilot” and all of its conversations will be permanently deleted. This can’t be undone.',
+ '“Pilot” and all of its conversations will be permanently deleted. Its Product Manager’s session will close too. This can’t be undone.',
),
findsOneWidget,
);
diff --git a/desktop/test/super_tab_roster_test.dart b/desktop/test/super_tab_roster_test.dart
index f2b26add9..40d1987e2 100644
--- a/desktop/test/super_tab_roster_test.dart
+++ b/desktop/test/super_tab_roster_test.dart
@@ -561,28 +561,27 @@ void main() {
},
);
- testWidgets(
- 'a replaced member keeps its identity and shows its new engine',
- (tester) async {
- final f = await fixture(tester);
- await f.show(tester);
- final agents = f.server.state['agents'] as List;
- agents[0]['harnessId'] = 'replacement';
- agents[0]['configuration'] = {'engine': 'claude', 'model': 'sonnet'};
- await f.controller.refresh();
- await tester.pumpAndSettle();
- expect(f.controller.snapshot!.agents.first.id, 'agent-0');
- expect(f.controller.snapshot!.agents.first.harnessId, 'replacement');
- expect(f.controller.snapshot!.agents.first.engine, 'claude');
- await tester.tap(f.row(0));
- await tester.pumpAndSettle();
- expect(find.text('Claude'), findsOneWidget);
- expect(find.text('sonnet'), findsOneWidget);
- await tester.tap(find.widgetWithText(TextButton, 'Close'));
- await tester.pumpAndSettle();
- await f.close(tester);
- },
- );
+ testWidgets('a replaced member keeps its identity and shows its new engine', (
+ tester,
+ ) async {
+ final f = await fixture(tester);
+ await f.show(tester);
+ final agents = f.server.state['agents'] as List;
+ agents[0]['harnessId'] = 'replacement';
+ agents[0]['configuration'] = {'engine': 'claude', 'model': 'sonnet'};
+ await f.controller.refresh();
+ await tester.pumpAndSettle();
+ expect(f.controller.snapshot!.agents.first.id, 'agent-0');
+ expect(f.controller.snapshot!.agents.first.harnessId, 'replacement');
+ expect(f.controller.snapshot!.agents.first.engine, 'claude');
+ await tester.tap(f.row(0));
+ await tester.pumpAndSettle();
+ expect(find.text('Claude'), findsOneWidget);
+ expect(find.text('sonnet'), findsOneWidget);
+ await tester.tap(find.widgetWithText(TextButton, 'Close'));
+ await tester.pumpAndSettle();
+ await f.close(tester);
+ });
testWidgets(
'owner confirms Remove from Swarm without stopping the native session',
@@ -631,6 +630,29 @@ void main() {
await f.close(tester);
});
+ testWidgets('project Product Manager cannot be removed from the roster', (
+ tester,
+ ) async {
+ final f = await fixture(tester);
+ await f.show(tester);
+ await tester.tap(f.row(0), buttons: kSecondaryMouseButton);
+ await tester.pumpAndSettle();
+ final remove = find.widgetWithText(
+ PopupMenuItem<String>,
+ 'Remove from Swarm',
+ );
+ expect(remove, findsOneWidget);
+ expect(tester.widget<PopupMenuItem<String>>(remove).enabled, isFalse);
+ expect(
+ find.text(
+ 'Atlas is the Product Manager of project openharness. Delete the project first.',
+ ),
+ findsOneWidget,
+ );
+ expect(f.server.posts, isEmpty);
+ await f.close(tester);
+ });
+
testWidgets(
'Remove from Swarm is hidden from unrelated people and shown for their own contribution',
(tester) async {
diff --git a/desktop/test/swarm_sharing_test.dart b/desktop/test/swarm_sharing_test.dart
index c9171e86a..273e331d1 100644
--- a/desktop/test/swarm_sharing_test.dart
+++ b/desktop/test/swarm_sharing_test.dart
@@ -407,6 +407,69 @@ void main() {
expect(find.text('Leave'), findsOneWidget);
});
+ testWidgets('contributor of a Product Manager cannot be removed', (
+ tester,
+ ) async {
+ final server = SwarmSharingServer();
+ (server.state['people'] as List).add({
+ 'id': 'peer',
+ 'email': '[email protected]',
+ 'role': 'collaborator',
+ });
+ server.state['agents'] = [
+ {
+ 'id': 'pm',
+ 'name': 'Quinn',
+ 'machineId': 'm',
+ 'harnessId': 'native-pm',
+ 'contributorId': 'peer',
+ 'configuration': {'engine': 'claude'},
+ },
+ ];
+ (server.state['conversations'] as List)[0]['leadId'] = 'pm';
+ await _open(tester, server);
+ await tester.tap(find.byKey(const Key('swarm-sharing-people')));
+ await tester.pumpAndSettle();
+ final remove = find.widgetWithText(TextButton, 'Remove');
+ expect(remove, findsOneWidget);
+ expect(tester.widget<TextButton>(remove).onPressed, isNull);
+ expect(
+ find.text(
+ 'Quinn is the Product Manager of project Pilot. Delete the project first.',
+ ),
+ findsOneWidget,
+ );
+ expect(server.posts, isEmpty);
+ });
+
+ testWidgets('member removal shows a backend Product Manager refusal', (
+ tester,
+ ) async {
+ final server = SwarmSharingServer();
+ (server.state['people'] as List).add({
+ 'id': 'peer',
+ 'email': '[email protected]',
+ 'role': 'collaborator',
+ });
+ server.refuse = {
+ 'code': 'LEAD_PROTECTED',
+ 'message': 'Sage is now the Product Manager of project Pilot. Delete the project first.',
+ };
+ await _open(tester, server);
+ await tester.tap(find.byKey(const Key('swarm-sharing-people')));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(TextButton, 'Remove'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(FilledButton, 'Remove'));
+ await tester.pumpAndSettle();
+ expect(
+ find.text(
+ 'Sage is now the Product Manager of project Pilot. Delete the project first.',
+ ),
+ findsOneWidget,
+ );
+ });
+
testWidgets(
'revocation removes the captured Share dialog and late settings cannot restore it',
(tester) async {