Skip to content

The agent that grows with you

fix(bot-mode): hand off group tabs to remote bots

Gille2599793271ca
diff --git a/apps/desktop/src/plugins/hermes-bots/group-bot-handoff.test.ts b/apps/desktop/src/plugins/hermes-bots/group-bot-handoff.test.ts
index 6a64a3852a1..40153bb120d 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-bot-handoff.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-bot-handoff.test.ts
@@ -76,6 +76,14 @@ async function loadRoom(): Promise<Room> {
const BOT: RosterRow = { name: 'alpha', title: 'Alpha' }
+const REMOTE_BOT: RosterRow = {
+ connectionId: 'remote-1',
+ name: 'alpha',
+ remoteSource: true,
+ sourceScoped: true,
+ title: 'Alpha'
+}
+
/** Seat a room and front it as a main-window tab, recording tab closes in
* the order they happen relative to the canonical open. */
function registerGroup(room: Room, group: string, timeline: string[]) {
@@ -111,6 +119,22 @@ describe('opening a bot from a fronted room', () => {
expect(room.panes.groupChatMainTabs.has('Core')).toBe(false)
})
+ it('retires the group tab before opening a bot from another connection', async () => {
+ const timeline: string[] = []
+ const room = await loadRoom()
+ registerGroup(room, 'Core', timeline)
+ openBotCanonicalChat.mockImplementation(async () => {
+ timeline.push('canonicalOpen')
+
+ return { openedId: 'stored-chat', registryId: 'stored-chat' }
+ })
+
+ expect(await room.actions.openRosterBot(REMOTE_BOT)).toBe(true)
+ expect(timeline.filter(event => event.includes(':group:'))).toHaveLength(1)
+ expect(timeline.findIndex(event => event.includes(':group:'))).toBeLessThan(timeline.indexOf('canonicalOpen'))
+ expect(room.panes.groupChatMainTabs.has('Core')).toBe(false)
+ })
+
it('is safe with no room fronted', async () => {
const timeline: string[] = []
const room = await loadRoom()
@@ -141,8 +165,9 @@ describe('a failed open must not steal the center', () => {
registerGroup(room, 'Core', [])
prepareBotSource.mockRejectedValue(new Error('source preparation failed'))
- expect(await room.actions.openRosterBot({ ...BOT, connectionId: 'local', sourceScoped: true })).toBe(false)
+ expect(await room.actions.openRosterBot(REMOTE_BOT)).toBe(false)
expect(room.chat.$groupChatWorkspace.get()).toBe('Core')
+ expect(room.panes.groupChatMainTabs.has('Core')).toBe(true)
})
it('restores the room by its immutable roomId, so a rename mid-open still finds it', async () => {
diff --git a/apps/desktop/src/plugins/hermes-bots/roster-actions.ts b/apps/desktop/src/plugins/hermes-bots/roster-actions.ts
index b3d1a2150af..8004b121539 100644
--- a/apps/desktop/src/plugins/hermes-bots/roster-actions.ts
+++ b/apps/desktop/src/plugins/hermes-bots/roster-actions.ts
@@ -201,7 +201,7 @@ export async function openRosterBot(bot: RosterRow): Promise<boolean> {
haptic('tap')
saveSelectedRosterBot(bot)
setBotsWorkspaceOwner(botWorkspaceOwnerKey(bot), bot)
- const dismissedGroup = bot.remoteSource ? null : dismissGroupChatForLocalBotOpen()
+ const dismissedGroup = dismissGroupChatForBotOpen()
if (!dismissedGroup) {
$groupChatWorkspace.set(null)
@@ -319,7 +319,7 @@ export async function openRosterBot(bot: RosterRow): Promise<boolean> {
/** Bot-open handoff: capture the selected group and retire its registered
* main tab (or clear the in-panel selection) before async source prep /
* canonical open. */
-function dismissGroupChatForLocalBotOpen(): null | { group: string; roomId: string } {
+function dismissGroupChatForBotOpen(): null | { group: string; roomId: string } {
const group = $groupChatWorkspace.get()
if (!group) {