The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): open a bot's most recent session from its roster row
teknium113f18198bd7e
diff --git a/apps/desktop/e2e/bot-row-open-recent-session.spec.ts b/apps/desktop/e2e/bot-row-open-recent-session.spec.tsnew file mode 100644index 00000000000..ff5cae467a7--- /dev/null+++ b/apps/desktop/e2e/bot-row-open-recent-session.spec.ts@@ -0,0 +1,119 @@+import fs from 'node:fs'+import path from 'node:path'++import { startMockServer } from '../../../tests-js/scripts/mock-server'++import {+ buildAppEnv,+ createSandbox,+ launchDesktop,+ type MockBackendFixture,+ waitForAppReady,+ writeEnvFile,+ writeMockProviderConfig+} from './fixtures'+import { RealSessionBuilder } from './real-session-builder'+import { expect, test } from './test'++// Right-click a bot row → "Open recent session" opens the bot's most recently+// active ordinary session as a tab in its workspace, while the row's left click+// keeps landing on the canonical Bot Chat (hermes-agent#93054).++type Page = MockBackendFixture['page']++let fixture: MockBackendFixture | null = null++// BOT_RECENT_SESSION_SCREENSHOT_DIR=<dir> saves full-window captures at the+// key states — PR evidence; never part of the assertions.+async function capture(page: Page, name: string): Promise<void> {+ const dir = process.env.BOT_RECENT_SESSION_SCREENSHOT_DIR++ if (!dir) {+ return+ }++ fs.mkdirSync(dir, { recursive: true })+ await page.screenshot({ path: path.join(dir, `${name}.png`) })+}++const RECENT_TITLE = 'Deploy notes'++test.beforeAll(async () => {+ const mock = await startMockServer()+ const sandbox = createSandbox('bots-recent-session')+ writeMockProviderConfig(sandbox.hermesHome, mock.url)+ writeEnvFile(sandbox.hermesHome)++ const dir = path.join(sandbox.hermesHome, 'profiles', 'alpha')+ fs.mkdirSync(dir, { recursive: true })+ writeMockProviderConfig(dir, mock.url)+ writeEnvFile(dir)+ const builder = await RealSessionBuilder.start(dir)++ try {+ // The canonical chat first, then an ordinary session so the latter is the+ // profile's newest listed conversation.+ await builder.createSession({ title: 'Bot Chat', turns: ['Hello alpha'] })+ await builder.createSession({ title: RECENT_TITLE, turns: ['Where are we on the deploy?'] })+ } finally {+ await builder.close()+ }++ const { app, page } = await launchDesktop(buildAppEnv(sandbox))++ fixture = {+ app,+ page,+ mock,+ mockUrl: mock.url,+ sandbox,+ cleanup: async () => {+ await app.close().catch(() => undefined)+ await mock.close()+ sandbox.cleanup()+ }+ }+ await waitForAppReady(fixture, 120_000)+})++test.afterAll(async () => {+ await fixture?.cleanup()+ fixture = null+})++test('the bot row menu opens the most recent session as a tab beside the Bot Chat', async () => {+ test.setTimeout(300_000)+ const page = fixture!.page++ const tab = page+ .getByRole('button', { name: 'Bots', exact: true })+ .or(page.getByRole('tab', { name: 'Bots', exact: true }))+ .first()++ await tab.click()+ await expect(page.getByRole('button', { name: 'New bot or group chat' })).toBeVisible()+ const row = page.locator('[data-slot="bots-roster"] [data-roster-key="local::alpha"]')+ await expect(row).toBeVisible({ timeout: 30_000 })++ // The row click is unchanged: the canonical Bot Chat opens, captioned with the bot's name.+ await row.click()+ const botChatTab = page.getByRole('tab', { name: /^Alpha\b/ })+ await expect(botChatTab).toBeVisible({ timeout: 60_000 })+ await expect(page.getByRole('tab', { name: new RegExp(`^${RECENT_TITLE}\\b`) })).toHaveCount(0)+ await capture(page, '1-row-click-opens-bot-chat')++ await row.click({ button: 'right' })+ const item = page.getByRole('menuitem', { name: 'Open recent session' })+ await expect(item).toBeVisible()+ await expect(item).toBeEnabled()+ await capture(page, '2-row-menu-open-recent-session')+ await item.click()++ const recentTab = page.getByRole('tab', { name: new RegExp(`^${RECENT_TITLE}\\b`) })+ await expect(recentTab).toBeVisible({ timeout: 60_000 })+ await expect(recentTab).toHaveAttribute('aria-selected', 'true')+ // A tab beside the Bot Chat, not in its place.+ await expect(botChatTab).toBeVisible()+ await expect(page.getByText('Where are we on the deploy?').first()).toBeVisible({ timeout: 60_000 })+ await capture(page, '3-recent-session-tab-open')+})diff --git a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx b/apps/desktop/src/plugins/hermes-bots/bot-row.tsxindex 77ab9adc5ce..aacedfb5f75 100644--- a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx+++ b/apps/desktop/src/plugins/hermes-bots/bot-row.tsx@@ -62,6 +62,7 @@ import { fallbackSelectionAfterHide, isBotHidden, isBotPinned } from './hidden-bimport { useBots } from './i18n'import { displayName, stripPreviewMarkdown } from './labels'import { duplicateBot } from './profile-ops'+import { botRecentSession, openBotRecentSession } from './recent-session'import { openRosterBot } from './roster-actions'import { botRosterMeta, botWorkspaceOwnerKey, setBotsWorkspaceOwner } from './routing'import {@@ -414,6 +415,12 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandl>{b.bot.newChatWith}</ContextMenuItem>+ {/* Click-to-latest (#93054): the freshest listed session — a cron run,+ a delegated job, a side thread — without moving the row click off+ the canonical Bot Chat. */}+ <ContextMenuItem disabled={!botRecentSession(bot)} onSelect={() => void openBotRecentSession(bot)}>+ Open recent session+ </ContextMenuItem><ContextMenuSeparator />{/* Filing. Membership is one field on the bot's meta (`sectionId`), sothis is a one-field write and no list anywhere has to be kept indiff --git a/apps/desktop/src/plugins/hermes-bots/recent-session.test.ts b/apps/desktop/src/plugins/hermes-bots/recent-session.test.tsnew file mode 100644index 00000000000..2c2352e2744--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/recent-session.test.ts@@ -0,0 +1,76 @@+/**+ * "Open recent session" on a bot row (hermes-agent#93054): opens the profile's+ * newest LISTED session as a tab in the bot's workspace — never in place of+ * the canonical Bot Chat — and hands a bot with nothing listable back to the+ * ordinary row click.+ */++import { beforeEach, describe, expect, it, vi } from 'vitest'++const { openRosterBot, openSession, prepareBotSource } = vi.hoisted(() => ({+ openRosterBot: vi.fn(async () => true),+ openSession: vi.fn(async () => undefined),+ prepareBotSource: vi.fn(async () => undefined)+}))++vi.mock('@hermes/plugin-sdk', () => ({+ BOT_CHAT_SESSION_HYDRATION_TIMEOUT_MS: 60_000,+ haptic: () => undefined,+ host: { openSession, notifyError: vi.fn() }+}))+vi.mock('./bot-state', () => ({ saveSelectedRosterBot: () => undefined }))+vi.mock('./canonical-chat', () => ({ prepareBotSource }))+vi.mock('./roster-actions', () => ({ openRosterBot }))+vi.mock('./routing', () => ({+ botConnectionRoute: () => ({ connectionId: 'local', mode: 'local', profile: 'researcher' }),+ botWorkspaceOwnerKey: () => 'bot:local::researcher',+ setBotsWorkspaceOwner: () => undefined+}))++import { botRecentSession, openBotRecentSession } from './recent-session'+import type { RosterRow } from './types'++const bot = (last_session: RosterRow['last_session']) =>+ ({ name: 'researcher', connectionId: 'local', last_session, canonical_session: { id: 'bot-chat-1' } }) as RosterRow++beforeEach(() => {+ openRosterBot.mockClear()+ openSession.mockClear()+})++describe('open recent session', () => {+ it('opens the newest listed session as a tab in the bot workspace, titled after the session', async () => {+ const row = bot({ id: 'sess-9', title: 'Deploy notes', message_count: 4, last_active: 1 })+ expect(botRecentSession(row)).toEqual({ id: 'sess-9', title: 'Deploy notes' })++ await expect(openBotRecentSession(row)).resolves.toBe(true)++ expect(prepareBotSource).toHaveBeenCalledWith(row)+ expect(openSession).toHaveBeenCalledTimes(1)+ const [id, options] = openSession.mock.calls[0] as unknown as [string, Record<string, unknown>]+ expect(id).toBe('sess-9')+ expect(options).toMatchObject({+ intent: 'tab',+ profile: 'researcher',+ workspaceMode: 'bots',+ workspaceOwnerKey: 'bot:local::researcher',+ expectHistory: true+ })+ // The stored row titles the tab; a tabTitle equal to it would caption the+ // tab as the bot (the canonical-chat rule) and hide which session it is.+ expect(options).not.toHaveProperty('tabTitle')+ // The canonical chat is never the target of this item.+ expect(id).not.toBe('bot-chat-1')+ expect(openRosterBot).not.toHaveBeenCalled()+ })++ it('falls back to the ordinary row click when the profile has no listed session', async () => {+ const row = bot(null)+ expect(botRecentSession(row)).toBeNull()++ await expect(openBotRecentSession(row)).resolves.toBe(true)++ expect(openRosterBot).toHaveBeenCalledWith(row)+ expect(openSession).not.toHaveBeenCalled()+ })+})diff --git a/apps/desktop/src/plugins/hermes-bots/recent-session.ts b/apps/desktop/src/plugins/hermes-bots/recent-session.tsnew file mode 100644index 00000000000..a9eaa51e2d8--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/recent-session.ts@@ -0,0 +1,79 @@+/**+ * "Open recent session" (hermes-agent#93054): a bot row's left click always+ * lands on the canonical Bot Chat — that is the bot's stable identity and+ * stays so. Multi-task users also want the freshest ORDINARY conversation+ * (a cron run, a delegated job, a `+` side thread) one gesture away, so the+ * row's context menu opens the bot's most recently active listed session.+ *+ * No new backend surface: `profiles.list` already ships `last_session` — the+ * newest row that `session.list` would show (hidden rows such as the Bot Chat+ * and group member sessions never win, tool/kanban workers are denied+ * server-side). Opened through the same `host.openSession` contract the+ * canonical open uses, in the bot's own workspace and connection route.+ */++import * as sdk from '@hermes/plugin-sdk'+import { haptic, host } from '@hermes/plugin-sdk'++import { saveSelectedRosterBot } from './bot-state'+import { prepareBotSource } from './canonical-chat'+import { openRosterBot } from './roster-actions'+import { botConnectionRoute, botWorkspaceOwnerKey, setBotsWorkspaceOwner } from './routing'+import type { RosterRow } from './types'++/** The listed session the menu item would open, or null when the profile has+ * none yet (a brand-new bot whose only conversation is its hidden Bot Chat). */+export function botRecentSession(bot: null | RosterRow | undefined): null | { id: string; title: string } {+ const last = bot?.last_session+ const id = String(last?.id || '').trim()++ return id ? { id, title: String(last?.title || '').trim() } : null+}++/** Open the bot's most recent listed session as a tab in its workspace.+ * Falls back to the row click (canonical chat) when nothing is listable. */+export async function openBotRecentSession(bot: RosterRow): Promise<boolean> {+ const recent = botRecentSession(bot)++ if (!recent || typeof host.openSession !== 'function') {+ return openRosterBot(bot)+ }++ haptic('tap')+ saveSelectedRosterBot(bot)+ const ownerKey = botWorkspaceOwnerKey(bot)+ setBotsWorkspaceOwner(ownerKey, bot)++ try {+ await prepareBotSource(bot)+ const route = botConnectionRoute(bot)++ await host.openSession(recent.id, {+ ...(route ? { route } : {}),+ profile: bot.name,+ // A tab beside the Bot Chat, never in its place: the canonical chat+ // stays where the row click expects it (same shape as `+` side threads).+ intent: 'tab',+ awaitHydration: true,+ expectHistory: (bot.last_session?.message_count ?? 1) > 0,+ forceResume: true,+ hydrationTimeoutMs: Number.isFinite(sdk.BOT_CHAT_SESSION_HYDRATION_TIMEOUT_MS)+ ? sdk.BOT_CHAT_SESSION_HYDRATION_TIMEOUT_MS+ : 60_000,+ keepAllProfilesScope: true,+ workspaceMode: 'bots',+ workspaceOwnerKey: ownerKey,+ // No tabTitle: the stored row supplies its own title. Passing the same+ // string as tabTitle would make the tab caption read as the bot's name+ // (workspaceOwnerTitle treats title === workspaceTabTitle as the+ // canonical chat), hiding which session this tab is.+ retryHydrationTimeoutOnce: true+ })++ return true+ } catch (error) {+ host.notifyError?.(error, 'Could not open the recent session')++ return false+ }+}diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.tsindex 823163d41ae..c0f18feb775 100644--- a/apps/desktop/src/plugins/hermes-bots/types.ts+++ b/apps/desktop/src/plugins/hermes-bots/types.ts@@ -46,9 +46,13 @@ export interface CanonicalSession {}export interface SessionPreview {+ /** Stored session id — what `host.openSession` takes. */+ id?: string/** Unix seconds, not milliseconds. */last_active?: number+ message_count?: numberpreview?: string+ title?: string}/** Per-bot presentation state, persisted in the profile's `ui_meta`. */diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.mdindex be41a8fee09..e3fb2920044 100644--- a/website/docs/user-guide/bot-mode.md+++ b/website/docs/user-guide/bot-mode.md@@ -21,6 +21,7 @@ Bot Mode relates to messaging bots and delegated subagents.The roster shows one row per agent profile: avatar, latest-message preview, and timestamp.- **Click a Bot** to land in its chat — every Bot has a canonical, persistent **Bot Chat** conversation that is created (and pinned) the moment the Bot is born. A row click always opens that Bot Chat (the same conversation the row previews), even when you have other tabs open for the Bot; those tabs stay open beside it. In the tab strip the Bot Chat is captioned with the Bot's name, so two open Bots are told apart at a glance.+- **Right-click a Bot → Open recent session** to jump to its most recently active ordinary conversation — a cron run, a delegated job, a side thread — as a tab beside the Bot Chat. The row click itself never changes; a Bot with no other conversation yet just opens its Bot Chat.- **Active now** — the roster's activity filter includes the owner of the focused live turn, Bots that wrote within the last 90 seconds, and Bots with a recent worker heartbeat. A connected gateway alone does not mean a Bot is working.- **Search** filters the roster as you type.- **Hide a Bot** — right-click a row → **Hide Bot** to take a Bot you don't use out of the roster and the Active-now strip. Hiding is display-only: @mentions still resolve, group-chat memberships are untouched, and routines keep running. Once at least one Bot is hidden, an **eye toggle** appears in the pane header — click it to reveal hidden Bots dimmed in place, then right-click → **Unhide Bot** to bring one back. Hidden Bots never toast, but they accumulate unread activity silently and the eye badges a dot so you know something happened. Hidden state is saved in the Bot's profile metadata, so it follows the Bot to every desktop connected to that backend.