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(super-tabs): remove agents in Desktop and notify Leads (#1538)
0xken158942f0a08dd1
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex 368af8002..9cf511cc6 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -91,6 +91,29 @@ describe('five-part task persistence', () => {})})+describe('person removal notices', () => {+ it('records one Lead notice per group and replays removal without another notice or delivery', async () => {+ const { tab, lead } = await fixture()+ const group = (await run(tab, { type: 'conversation.create', title: 'Pending drafts', brief: 'Keep drafts offline',+ checks: [{ description: 'Draft survives reconnect', independent: false }] })).result.conversationId as string+ const worker = (await run(tab, { type: 'agent.add', conversationId: group, machineId: 'test-host', harnessId: randomUUID(),+ name: 'Draft worker', configuration: config, lead: false })).result.agentId as string+ await run(tab, { type: 'conversation.agent', conversationId: 'lead', agentId: worker, present: true, lead: false })+ await run(tab, { type: 'work.assign', conversationId: group, agentId: worker })+ const operationId = randomUUID(), command: Command = { type: 'agent.remove', agentId: worker }+ const first = await run(tab, command, owner, undefined, operationId)+ const notices = await db.superTabMessage.findMany({ where: { tabId: tab, text: { contains: 'removed' } } })+ expect(notices).toHaveLength(2)+ expect(notices.find(n => n.conversationId === group)!.text).toContain('Pending drafts')+ const deliveries = await db.superTabDelivery.findMany({ where: { tabId: tab, messageId: { in: notices.map(n => n.id) } } })+ expect(deliveries).toHaveLength(2)+ expect(deliveries.every(d => d.agentId === lead)).toBe(true)+ expect(await run(tab, command, owner, undefined, operationId)).toEqual(first)+ expect(await db.superTabMessage.count({ where: { tabId: tab, text: { contains: 'removed' } } })).toBe(2)+ expect(await db.superTabDelivery.count({ where: { tabId: tab, messageId: { in: notices.map(n => n.id) } } })).toBe(2)+ })+})+describe('agent member identities', () => {it('keeps a name through replay and removal, including the stored message author', async () => {const tab = (await store.create(owner, randomUUID(), 'People and agents')).iddiff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 616f856eb..e4f5bee85 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -78,6 +78,47 @@ describe('five-part tasks', () => {})})+describe('person removal notices', () => {+ it('tells each remaining Lead who removed an agent and its open task', () => {+ const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group(), worker = f.add('worker', 'owner', group)+ f.run({ type: 'conversation.agent', conversationId: 'lead', agentId: worker, present: true, lead: false })+ f.run({ type: 'work.assign', conversationId: group, agentId: worker })+ const name = f.state.agents.find(a => a.id === worker)!.displayName!+ const effects = f.run({ type: 'agent.remove', agentId: worker })+ expect(effects.messages).toHaveLength(2)+ expect(new Set(effects.messages.map(m => m.id)).size).toBe(2)+ const notice = effects.messages.find(m => m.conversationId === group)!+ expect(notice).toMatchObject({ author: { kind: 'person', id: 'owner' }, recipients: [lead] })+ expect(notice.text).toContain('owner removed')+ expect(notice.text).toContain(name)+ expect(notice.text).toContain('Offline editing')+ expect(effects.messages.find(m => m.conversationId === 'lead')!.recipients).toEqual([lead])+ expect(f.state.conversations.find(c => c.id === group)!.assignment!.status).toBe('reconciling')+ })++ it('finds a held assignment even when the worker is missing from the group roster', () => {+ const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group(), worker = f.add('worker', 'owner', group)+ f.run({ type: 'work.assign', conversationId: group, agentId: worker })+ f.state.conversations[1]!.agentIds = [lead]+ expect(f.run({ type: 'agent.remove', agentId: worker }).messages).toEqual([+ expect.objectContaining({ conversationId: group, recipients: [lead], text: expect.stringContaining('Offline editing') }),+ ])+ })++ it('posts a notice without claiming inactive work stopped or delivering to the removed Lead', () => {+ const f = fixture(), worker = f.add('lead', 'owner', 'lead', true)+ const effects = f.run({ type: 'agent.remove', agentId: worker })+ expect(effects.messages).toEqual([expect.objectContaining({ conversationId: 'lead', recipients: [] })])+ expect(effects.messages[0]!.text).not.toContain('task')+ })++ it('posts nothing for an agent with no conversations', () => {+ const f = fixture(), worker = f.add('worker')+ f.state.conversations[0]!.agentIds = []+ expect(f.run({ type: 'agent.remove', agentId: worker }).messages).toEqual([])+ })+})+describe('Super Tab collaboration policy', () => {it('records host-observed runtime changes without rewriting an assignment\'s starting configuration', () => {const f = fixture(), group = f.group(), worker = f.add('worker', 'owner', group)@@ -719,6 +760,7 @@ describe('message attachments', () => {expect(() => f.run({ type: 'agent.remove', agentId: worker }, { ...workerActor, agentId: other })).toThrow()const releaseId = f.state.agents.find(a => a.id === worker)!.releaseId!const removed = f.run({ type: 'agent.remove', agentId: worker, releaseId }, workerActor)+ expect(removed.messages).toEqual([])expect(removed.cancelledAgents).toContain(worker)expect(f.state.agents.some(a => a.id === worker)).toBe(false)})diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex c1eecd0c4..84c1a4399 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -572,7 +572,18 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma&& !state.releasedHarnesses?.some(r => r.machineId === target.machineId && r.harnessId === target.harnessId)) {reserveHarnessSlot(state, target.machineId, target.harnessId, operationId)}+ const affected = actor.kind === 'person' ? state.conversations.filter(group => group.agentIds.includes(target.id)+ || group.leadId === target.id || group.assignment?.agentId === target.id) : []removeAgent(target)+ for (const group of affected) {+ const task = group.assignment?.agentId === target.id && activeWork(group)+ ? ` Its task "${group.title}" needs to be assigned again or closed.` : ''+ const lead = group.leadId && group.agentIds.includes(group.leadId) ? group.leadId : null+ // One person can withdraw an agent from several groups. Each notice needs its own durable message ID.+ effects.messages.push({ id: stableId(operationId, 'agent-removed', group.id), conversationId: group.id,+ author: sender, text: `${sender.name.split('@')[0]} removed ${target.displayName ?? target.name} from the Swarm.${task}`,+ replyTo: null, recipients: lead ? [lead] : [] })+ }break}case 'conversation.agent': {diff --git a/desktop/lib/super_tabs/roster.dart b/desktop/lib/super_tabs/roster.dartindex bb0b243ed..c7e394916 100644--- a/desktop/lib/super_tabs/roster.dart+++ b/desktop/lib/super_tabs/roster.dart@@ -13,6 +13,7 @@ import '../widgets/desktop_chrome.dart';import '../widgets/engine_identity.dart';import '../widgets/harness_activity_mark.dart';import 'controller.dart';+import 'dialog_scope.dart';import 'identity.dart';import 'model.dart';import 'section_heading.dart';@@ -52,6 +53,112 @@ class _SuperTabRosterState extends State<SuperTabRoster> {String _role(SuperTabAgent agent) =>c.snapshot!.isLead(agent.id) ? 'Product Manager' : 'Engineer';+ bool _canRemove(SuperTabAgent agent) =>+ c.canWrite && (c.isOwner || agent.contributorId == c.accountId);++ Future<void> _remove(SuperTabAgent agent) async {+ var busy = false, attempted = false;+ final name = c.snapshot!.agentName(agent.id);+ final machine =+ widget.app?.stateOf(agent.machineId)?.machine.displayName ??+ c.snapshot?.machines+ .where((m) => m['machineId'] == agent.machineId)+ .firstOrNull?['name']+ as String? ??+ 'its computer';+ await showAppDialog<void>(+ context: context,+ builder: (context) => SuperTabDialogScope(+ controller: c,+ child: StatefulBuilder(+ builder: (context, update) => ListenableBuilder(+ listenable: c,+ builder: (context, _) {+ final current = c.snapshot?.agent(agent.id);+ final pending = c.pendingCommand;+ final checking =+ pending?['type'] == 'agent.remove' &&+ pending?['agentId'] == agent.id;+ final available = current != null || checking || busy;+ final permitted = _canRemove(current ?? agent);+ final enabled =+ permitted &&+ !busy &&+ !c.saving &&+ (checking || !c.hasPendingAction);+ return PopScope(+ canPop: !busy,+ child: AlertDialog(+ title: Text(+ available+ ? 'Remove $name from this Swarm?'+ : 'Agent unavailable',+ ),+ content: SizedBox(+ width: 400,+ child: SingleChildScrollView(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ 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.',+ ),+ if (attempted && c.operationError != null) ...[+ const SizedBox(height: 12),+ Text(c.operationError!),+ ],+ ],+ ),+ ),+ ),+ actions: [+ TextButton(+ autofocus: true,+ onPressed: busy ? null : () => Navigator.pop(context),+ child: Text(+ checking || !available || !permitted+ ? 'Close'+ : 'Cancel',+ ),+ ),+ if (available && permitted)+ FilledButton(+ style: grid.dangerButtonStyle(),+ onPressed: !enabled+ ? null+ : () async {+ update(() {+ busy = true;+ attempted = true;+ });+ final result = checking+ ? await c.retry()+ : await c.command({+ 'type': 'agent.remove',+ 'agentId': agent.id,+ });+ if (!context.mounted) return;+ if (result != null) {+ Navigator.pop(context);+ } else {+ update(() => busy = false);+ }+ },+ child: Text(checking ? 'Retry' : 'Remove from Swarm'),+ ),+ ],+ ),+ );+ },+ ),+ ),+ ),+ );+ }+HarnessActivity _activity(SuperTabAgent agent) {final app = widget.app;final native = app == null@@ -153,9 +260,18 @@ class _SuperTabRosterState extends State<SuperTabRoster> {),items: [const PopupMenuItem(value: 'details', child: Text('Details')),+ if (_canRemove(c.snapshot?.agent(agent.id) ?? agent))+ const PopupMenuItem(+ value: 'remove',+ child: Text('Remove from Swarm'),+ ),],);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);+ }},child: ListTile(key: ValueKey('super-member-${agent.id}'),diff --git a/desktop/test/super_tab_roster_test.dart b/desktop/test/super_tab_roster_test.dartindex 0ea9febac..2740f0183 100644--- a/desktop/test/super_tab_roster_test.dart+++ b/desktop/test/super_tab_roster_test.dart@@ -1,5 +1,6 @@import 'dart:io';+import 'package:flutter/gestures.dart';import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';import 'package:flutter/services.dart';@@ -19,15 +20,24 @@ import 'support/super_tab_fixture.dart';import 'swarm_state_test.dart' show createApp;class RosterFixture {+ RosterFixture({this.account = 'owner'});+ final String account;final app = createApp(connected: true);final server = ConversationServer();- late final controller = server.controller();+ late final controller = server.controller(account: account);SuperTabAgent? opened;SuperTabConversation? added;final boundary = GlobalKey();bool disposed = false;Future<void> initialize() async {+ if (account != 'owner') {+ (server.state['people'] as List).add({+ 'id': account,+ 'email': '[email protected]',+ 'role': 'collaborator',+ });+ }server.state['projects'] = [projectFixture('lead', 'openharness', 'lead'),projectFixture('os', 'autonomous-os', 'os-lead'),@@ -125,15 +135,161 @@ void main() {}});- Future<RosterFixture> fixture(WidgetTester tester) async {+ Future<RosterFixture> fixture(+ WidgetTester tester, {+ String account = 'owner',+ }) async {await tester.binding.setSurfaceSize(const Size(280, 700));addTearDown(() => tester.binding.setSurfaceSize(null));- final f = RosterFixture();+ final f = RosterFixture(account: account);await f.initialize();addTearDown(f.dispose);return f;}+ Future<void> openRemoval(+ WidgetTester tester,+ RosterFixture f, {+ int agent = 1,+ }) async {+ await tester.tap(f.row(agent), buttons: kSecondaryMouseButton);+ await tester.pumpAndSettle();+ await tester.tap(find.text('Remove from Swarm'));+ await tester.pumpAndSettle();+ }++ testWidgets(+ 'owner confirms Remove from Swarm without stopping the native session',+ (tester) async {+ final f = await fixture(tester);+ f.app.stateOf('m')!.agents = const [+ Agent(id: 'a1', name: 'Multiply', engine: 'claude'),+ ];+ await f.show(tester);+ await openRemoval(tester, f);+ expect(find.text('Remove Sage from this Swarm?'), findsOneWidget);+ expect(+ find.descendant(+ of: find.byType(AlertDialog),+ matching: find.textContaining('Test host'),+ ),+ findsOneWidget,+ );+ expect(f.server.posts, isEmpty);+ expect(+ tester+ .widget<TextButton>(find.widgetWithText(TextButton, 'Cancel'))+ .autofocus,+ isTrue,+ );+ await tester.tap(find.widgetWithText(FilledButton, 'Remove from Swarm'));+ await tester.pumpAndSettle();+ expect(f.server.posts.single['command'], {+ 'type': 'agent.remove',+ 'agentId': 'agent-1',+ });+ expect(find.byType(AlertDialog), findsNothing);+ expect(f.app.stateOf('m')!.agents.single.id, 'a1');+ await f.close(tester);+ },+ );++ testWidgets('cancelling Remove from Swarm sends nothing', (tester) async {+ final f = await fixture(tester);+ await f.show(tester);+ await openRemoval(tester, f);+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));+ await tester.pumpAndSettle();+ expect(f.server.posts, isEmpty);+ expect(find.byType(AlertDialog), findsNothing);+ await f.close(tester);+ });++ testWidgets(+ 'Remove from Swarm is hidden from unrelated people and shown for their own contribution',+ (tester) async {+ final f = await fixture(tester, account: 'peer');+ await f.show(tester);+ await tester.tap(f.row(1), buttons: kSecondaryMouseButton);+ await tester.pumpAndSettle();+ expect(find.text('Remove from Swarm'), findsNothing);+ expect(find.text('Details'), findsOneWidget);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ (f.server.state['agents'] as List)[1]['contributorId'] = 'peer';+ await f.controller.refresh();+ await tester.pumpAndSettle();+ await openRemoval(tester, f);+ await tester.tap(find.widgetWithText(FilledButton, 'Remove from Swarm'));+ await tester.pumpAndSettle();+ expect(f.server.posts.single['command'], {+ 'type': 'agent.remove',+ 'agentId': 'agent-1',+ });+ await f.close(tester);+ },+ );++ testWidgets('Remove from Swarm keeps the server refusal visible', (+ tester,+ ) async {+ final f = await fixture(tester);+ f.server.refuse = {+ 'code': 'FORBIDDEN',+ 'message': 'Only its contributor can remove this agent.',+ };+ await f.show(tester);+ await openRemoval(tester, f);+ await tester.tap(find.widgetWithText(FilledButton, 'Remove from Swarm'));+ await tester.pumpAndSettle();+ expect(+ find.text('Only its contributor can remove this agent.'),+ findsOneWidget,+ );+ expect(find.byType(AlertDialog), findsOneWidget);+ await f.close(tester);+ });++ testWidgets(+ 'Remove from Swarm retries a lost reply with the same operation',+ (tester) async {+ final f = await fixture(tester);+ f.server.loseReply = true;+ await f.show(tester);+ await openRemoval(tester, f);+ await tester.tap(find.widgetWithText(FilledButton, 'Remove from Swarm'));+ await tester.pumpAndSettle();+ expect(f.controller.hasPendingAction, isTrue);+ (f.server.state['agents'] as List).removeWhere(+ (a) => a['id'] == 'agent-1',+ );+ await f.controller.refresh();+ await tester.pumpAndSettle();+ await tester.tap(find.widgetWithText(FilledButton, 'Retry'));+ await tester.pumpAndSettle();+ expect(f.server.posts, hasLength(2));+ expect(f.server.posts[1], f.server.posts[0]);+ expect(find.byType(AlertDialog), findsNothing);+ await f.close(tester);+ },+ );++ testWidgets('Remove from Swarm cannot submit after access is revoked', (+ tester,+ ) async {+ final f = await fixture(tester);+ await f.show(tester);+ await openRemoval(tester, f);+ f.controller.revokeAccess('Access removed');+ await tester.pumpAndSettle();+ expect(+ find.widgetWithText(FilledButton, 'Remove from Swarm'),+ findsNothing,+ );+ expect(f.server.posts, isEmpty);+ await f.close(tester);+ });+testWidgets('agents follow project selection', (tester) async {final f = await fixture(tester);f.app.stateOf('m')!.agents = const [diff --git a/docs/plans/2026-10-22-remove-swarm-agent.md b/docs/plans/2026-10-22-remove-swarm-agent.mdnew file mode 100644index 000000000..57582198d--- /dev/null+++ b/docs/plans/2026-10-22-remove-swarm-agent.md@@ -0,0 +1,49 @@+# Remove agents from a Swarm implementation plan++> **For agentic workers:** Use superpowers:executing-plans and the built-in swarm-dev workflow. Run each behavior test red, implement, then verify green.++**Goal:** Let a Swarm owner or contributor remove an agent with confirmation, and notify affected Leads immediately.++**Architecture:** Extend the existing roster context menu and shared dialog/controller plumbing. Add person-only notices inside the backend agent.remove case, using distinct operation-derived message IDs per conversation; existing transactional receipts prevent duplicate notices on retry. Preserve existing session ownership and stop-confirmation behavior.++**Stack:** Flutter/Dart, TypeScript, Vitest; no dependencies.++**Spec:** Owner-approved workgroup “Remove agent from the Swarm in Desktop”, expanded assignment of 2026-10-22: owner/contributor-only action, plain confirmation naming agent and machine, backend refusal displayed, one notice per affected group identifying remover, agent and open task, delivered to that group's remaining Lead; no notices for host-agent removal or agents without groups.++## Constraints and review focus++- Own roster.dart, controller.dart only if necessary, roster tests; backend agent.remove case and command tests. Add one isolated store integration test to prove receipt replay; no store implementation changes.+- Existing permission, native stop and reservation behavior stays authoritative. No native session operations from Desktop.+- Cancel, permission loss or access revocation sends no removal. Guard duplicate confirmation and retain pending operation receipts for uncertain replies.+- Multiple affected groups need distinct message IDs. A removed Lead cannot receive its own notice; other recipients must remain members.+- Removal without active work must not claim a task stopped. Replays return the original receipt without another message or delivery.+- Tests use in-memory Desktop state and disposable MongoDB, never production homes, port 18473 or real tmux.+- Branch from current main; deliver a draft PR only. No merge/release.++## Task 1: Desktop removal action++Files: desktop/lib/super_tabs/roster.dart, desktop/test/super_tab_roster_test.dart; controller.dart only if existing plumbing cannot suffice.++- [x] Add widget tests for owner confirm/cancel, contributor vs unrelated person, refused removal, lost acknowledgement retry, permission revocation and existing details action.+- [x] Run the new tests and observe the missing action.+- [x] Add Remove from Swarm to the existing menu when canWrite and owner/contributor. Use showAppDialog and SuperTabDialogScope, recompute permission from the current snapshot, and call controller.command / retry.+- [x] Verify roster and related controller/dialog tests; analyze changed Dart files.++## Task 2: Lead notices++Files: backend/src/superTabs/commands.ts (agent.remove only), commands.test.ts; backend/integration/superTabs.test.ts (receipt regression only).++- [x] Add failing tests for active work, memberships across groups, named person/agent/task, unique message IDs, no groups/no active task, and person-only notices.+- [x] Add a database integration test removing once and retrying the same operation; assert one notice and delivery per group.+- [x] Capture affected groups before removal, retain the existing removal helper, then append person-authored notices with stableId(operationId, removal notice, group.id) and remaining Lead recipients.+- [x] Run backend typecheck, Super Tab unit tests and isolated integration suite.++## Task 3: Review and draft handoff++- [x] Inspect a rendered confirmation and permission-specific menus, then get a fresh read-only code review.+- [ ] Resolve material findings, fetch/rebase main, and run only checks affected by new source changes.+- [ ] Push the branch and create a draft PR with exact tests and screenshot. Report Ready: yes/no, head, links and any unverified behavior to the workgroup.++## Validation scope++Flutter: changed-file analyze; super_tab_roster_test.dart, super_tab_controller_test.dart and super_tab_project_delete_test.dart (shared pending-dialog conventions). Backend: npx tsc --noEmit; NODE_ENV=test with the existing fixture encryption key, vitest run src/superTabs; npm run test:super-tabs. Use two workers and bounded runs. Full unrelated suites are outside this isolated menu/notice change; CI component suites start after owner marks the draft ready.