The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-mode): sweep CLI-born Bot Mode sessions out of the global sidebar (ownership-based)
Teknium4014eb7d5c28
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.jsindex 98c8c7aff92..a0901efd654 100644--- a/apps/desktop/src/plugins/hermes-bots/plugin.js+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js@@ -273,7 +273,8 @@ async function saveBotMeta(name, patch) {* and Bot Chats created before this policy (or while the old pref was off)* left visible rows behind. On every plugin load, sweep every session id we* own — canonical chats from bot meta plus each group room's member- * sessions — through the core session.set_hidden RPC. Idempotent (the DB+ * sessions — through the core session.set_hidden RPC, then run the+ * ownership-based sweep for the rows we DON'T know by id. Idempotent (the DB* setter is a no-op on already-hidden rows) and feature-detected: older* gateways lack session.set_hidden and simply keep the rows visible. */function hideOwnedBotSessions() {@@ -285,11 +286,83 @@ function hideOwnedBotSessions() {.filter(sid => Boolean(sid) && sid !== true)const ids = [...new Set([...canonical, ...rooms])]- return Promise.all(+ const known = Promise.all(ids.map(sid =>Promise.resolve(host.request('session.set_hidden', { session_id: sid, hidden: true })).catch(() => undefined)))++ return Promise.all([known, sweepBotProfileSessions().catch(() => undefined)])+}++// Titles Bot Mode itself mints for its plumbing sessions. Bot-to-bot CLI+// handoffs (`hermes -p <bot> chat --in ~ -c "Bot Chat" --create-if-missing`)+// and mention handoffs create sessions with EXACTLY these titles; the+// "Group: " prefix is the member-session title ensureGroupChatSession has+// used since group chats shipped. Exact/prefix matching is deliberate — a+// user's real conversation inside a bot profile keeps whatever title the+// user gave it and is never touched.+const BOT_MODE_SWEEP_TITLES = new Set(['Bot Chat', 'Agent Inbox'])++function isBotModeSweepTitle(title) {+ const t = String(title || '').trim()+ return BOT_MODE_SWEEP_TITLES.has(t) || t.startsWith('Group: ')+}++/** Ownership-based sweep: the id-based sweep above only covers sessions the+ * plugin recorded ($botMeta canonical chats, $groupChats member sids), but+ * Bot Mode sessions are ALSO minted outside the plugin — bot-to-bot CLI+ * handoffs ("Agent Inbox" / extra "Bot Chat" rows born visible in a bot's+ * profile) — and those ids the plugin never learns. So: enumerate each+ * roster bot's OWN profile sessions (only bot profiles — a non-bot profile+ * is never listed, so its sessions are never touched) and hide any VISIBLE+ * row whose title is Bot Mode plumbing. session.list without include_hidden+ * returns only visible rows, which keeps the sweep naturally idempotent.+ * Remote-source bots route to their own connection via requestForBot.+ * Feature-detected + fire-and-forget: older gateways without per-profile+ * session.list / session.set_hidden simply reject and the sweep no-ops. */+async function sweepBotProfileSessions() {+ const cached = $lastRoster.get()+ let roster = Array.isArray(cached) && cached.length ? cached : null++ if (!roster) {+ // Plugin load can run before the Bots pane hydrates $lastRoster — fall+ // back to the active gateway's own profile list (local bots; remote+ // sources get covered by the next sweep once the roster cache exists).+ try {+ const res = await host.request('profiles.list', {})+ roster = Array.isArray(res?.profiles) ? res.profiles : []+ } catch {+ return+ }+ }++ await Promise.all(+ roster.map(async bot => {+ const name = String(bot?.name || '').trim()++ if (!name) {+ return+ }++ try {+ const res = await requestForBot(bot, 'session.list', { profile: name, limit: PROFILE_SESSION_LIST_LIMIT })+ const rows = Array.isArray(res?.sessions) ? res.sessions : []++ await Promise.all(+ rows+ .filter(row => row && row.id && isBotModeSweepTitle(row.title))+ .map(row =>+ Promise.resolve(+ requestForBot(bot, 'session.set_hidden', { session_id: row.id, hidden: true, profile: name })+ ).catch(() => undefined)+ )+ )+ } catch {+ /* older gateway / unreachable source — leave this profile alone */+ }+ })+ )}/** Fetch server-side avatars for roster rows flagged has_avatar when thediff --git a/apps/desktop/src/plugins/hermes-bots/tests/bot-delete.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/bot-delete.test.mjsindex c6483824c82..872ad062788 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/bot-delete.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/bot-delete.test.mjs@@ -73,7 +73,11 @@ test('unit: older desktop without host.deleteProfile falls back to the non-interawait context.__delete.deleteBot({ name: 'researcher' })- assert.deepEqual(JSON.parse(JSON.stringify(requests[0])), {+ // The load-time hide sweep (hideOwnedBotSessions/sweepBotProfileSessions)+ // may interleave its own profiles.list / session.* traffic — filter to the+ // delete path's request.+ const exec = requests.filter(r => r.method === 'cli.exec')+ assert.deepEqual(JSON.parse(JSON.stringify(exec[0])), {method: 'cli.exec',params: { argv: ['profile', 'delete', 'researcher', '--yes'] }})diff --git a/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjsindex 3b068d2750e..fda52c1c068 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs@@ -80,6 +80,66 @@ test('hideOwnedBotSessions sweeps canonical chats AND room member sessions', asyassert.ok(calls.every(c => c.method === 'session.set_hidden' && c.params.hidden === true))})+test('sweepBotProfileSessions hides Bot-Mode-titled rows per roster bot, and only those', async () => {+ // Ownership-based half of the sweep: CLI-born "Agent Inbox" / extra+ // "Bot Chat" rows live in bot profiles but are unknown to $botMeta /+ // $groupChats, so the id-based sweep never reaches them. This sweep lists+ // each roster bot's own sessions and hides rows by exact plumbing title+ // ('Bot Chat', 'Agent Inbox', 'Group: …' prefix) — never a user-titled row.+ const start = source.indexOf('function hideOwnedBotSessions()')+ const end = source.indexOf('/** Fetch server-side avatars', start)+ const calls = []+ const rowsByProfile = {+ alpha: [+ { id: 'a-1', title: 'Bot Chat' },+ { id: 'a-2', title: 'Agent Inbox' },+ { id: 'a-3', title: 'Group: Core' },+ { id: 'a-4', title: 'My real conversation' },+ { id: 'a-5', title: 'Bot Chat notes' } // not an exact title — kept+ ],+ remy: [{ id: 'r-1', title: 'Agent Inbox' }]+ }+ const context = {+ host: { request: async () => ({}) },+ $botMeta: { get: () => ({}) },+ $groupChats: { get: () => ({}) },+ $lastRoster: { get: () => [{ name: 'alpha' }, { name: 'remy', remoteSource: true, connectionId: 'mini' }] },+ PROFILE_SESSION_LIST_LIMIT: 200,+ requestForBot: async (bot, method, params) => {+ calls.push({ bot: bot.name, method, params })+ if (method === 'session.list') {+ return { sessions: rowsByProfile[params.profile] || [] }+ }+ return {}+ }+ }+ const section = source.slice(start, end).concat('\nglobalThis.__h = { hideOwnedBotSessions, sweepBotProfileSessions };\n')+ vm.runInNewContext(section, context, { filename: 's.js' })+ await context.__h.sweepBotProfileSessions()++ const lists = calls.filter(c => c.method === 'session.list')+ assert.deepEqual(lists.map(c => c.params.profile).sort(), ['alpha', 'remy'])+ // Visible-rows-only listing keeps the sweep idempotent.+ assert.ok(lists.every(c => !c.params.include_hidden))++ const hidden = calls.filter(c => c.method === 'session.set_hidden')+ assert.deepEqual(+ hidden.map(c => c.params.session_id).sort(),+ ['a-1', 'a-2', 'a-3', 'r-1'],+ 'exact plumbing titles only — user-titled rows in bot profiles stay visible'+ )+ assert.ok(hidden.every(c => c.params.hidden === true))+ // Remote-source bots route through requestForBot with their own bot row.+ assert.equal(hidden.find(c => c.params.session_id === 'r-1').bot, 'remy')+})++test('hideOwnedBotSessions chains the ownership sweep and survives its absence of context', async () => {+ // The load/reconnect entrypoint runs BOTH halves: known ids first, then+ // the roster-wide title sweep (best-effort — a throwing sweep never+ // breaks the id half).+ assert.match(source, /return Promise\.all\(\[known, sweepBotProfileSessions\(\)\.catch\(\(\) => undefined\)\]\)/)+})+test('the Bots session browser lists with include_hidden', () => {// The one session.list consumer that must see the always-hidden rows.// (Canonical-chat recovery now goes through profiles.list