The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(hermes-bots): suppress duplicate activity toasts for unchanged preview
rain6100a0d2d26b6bb
diff --git a/apps/desktop/src/plugins/hermes-bots/bot-state.ts b/apps/desktop/src/plugins/hermes-bots/bot-state.tsindex a3000c4a0ed..96fb48df716 100644--- a/apps/desktop/src/plugins/hermes-bots/bot-state.ts+++ b/apps/desktop/src/plugins/hermes-bots/bot-state.ts@@ -18,6 +18,12 @@ import type { RosterRow } from './types'// fresh mount doesn't mark ancient history unread.export const rosterWatermarks = new Map<string, number>()+// Last preview text we actually surfaced (toasted) per bot, used to suppress+// duplicate activity toasts when last_active keeps advancing (a busy bridge+// re-pinging the same message) but the visible content is unchanged. Seeded on+// the first poll alongside rosterWatermarks.+export const lastToastedPreview = new Map<string, string>()+// Bot Mode sessions are ALWAYS hidden from the global Sessions sidebar:// canonical Bot Chats are plugin-owned forever-chats and group-chat member// sessions are room plumbing — neither is a scratch conversation, and adiff --git a/apps/desktop/src/plugins/hermes-bots/roster-actions.test.ts b/apps/desktop/src/plugins/hermes-bots/roster-actions.test.tsindex f6a13cc0b3f..7a23a8ad973 100644--- a/apps/desktop/src/plugins/hermes-bots/roster-actions.test.ts+++ b/apps/desktop/src/plugins/hermes-bots/roster-actions.test.ts@@ -146,6 +146,32 @@ describe('new activity after the seed', () => {expect(markUnreadMock).not.toHaveBeenCalled()})+ it('does not re-toast an unchanged preview when last_active keeps advancing', async () => {+ const { $activityToasts, trackInboundActivity } = await loadActions()++ $activityToasts.set(true)+ trackInboundActivity([chatting('researcher', 5000)])+ trackInboundActivity([chatting('researcher', 6000, 'same message')])+ // A busy bridge (Feishu) re-pings the same message; last_active moved on+ // but the preview is identical — must not produce a second toast.+ trackInboundActivity([chatting('researcher', 7000, 'same message')])++ const toasts = hostMock.notify.mock.calls.filter((c) => c[0].title.includes('has new activity') || c[0].title.includes('New message for'))+ expect(toasts.length).toBe(1)+ })++ it('toasts again once the preview actually changes', async () => {+ const { $activityToasts, trackInboundActivity } = await loadActions()++ $activityToasts.set(true)+ trackInboundActivity([chatting('researcher', 5000)])+ trackInboundActivity([chatting('researcher', 6000, 'first message')])+ trackInboundActivity([chatting('researcher', 7000, 'second message')])++ const toasts = hostMock.notify.mock.calls.filter((c) => c[0].title.includes('has new activity') || c[0].title.includes('New message for'))+ expect(toasts.length).toBe(2)+ })+it('keeps marking a roster-hidden bot but never toasts it', async () => {const { $activityToasts, $botMeta, trackInboundActivity } = await loadActions()diff --git a/apps/desktop/src/plugins/hermes-bots/roster-actions.ts b/apps/desktop/src/plugins/hermes-bots/roster-actions.tsindex 95e60f45b47..769ba230bf9 100644--- a/apps/desktop/src/plugins/hermes-bots/roster-actions.ts+++ b/apps/desktop/src/plugins/hermes-bots/roster-actions.ts@@ -10,7 +10,7 @@import { ackStoredSessionId, atom, haptic, host, markSessionUnreadFinished } from '@hermes/plugin-sdk'-import { $openBotChat, $selectedBot, rosterWatermarks, saveSelectedRosterBot } from './bot-state'+import { $openBotChat, $selectedBot, lastToastedPreview, rosterWatermarks, saveSelectedRosterBot } from './bot-state'import { CANONICAL_CHAT_TITLE, notifyBotOpenFailure, openBotCanonicalChat, prepareBotSource } from './canonical-chat'import { $botMeta, botActivitySession, botRosterKey, botSelectionKey, newBotChat } from './data'import { $groupChats, $groupChatWorkspace } from './group-chat'@@ -65,6 +65,11 @@ export function trackInboundActivity(roster: RosterRow[]) {rosterWatermarks.set(key, Math.max(prev, ts))if (seeding || ts <= prev) {+ // Seed (or refresh) the last-toasted preview so a fresh mount, or a row+ // whose activity hasn't advanced, treats current content as already-seen+ // rather than replaying it — or a busy bridge's unchanged preview — as a+ // duplicate toast.+ lastToastedPreview.set(key, (activity?.preview || '').trim())continue}@@ -93,10 +98,20 @@ export function trackInboundActivity(roster: RosterRow[]) {// Toasts are opt-in: the unread mark is recorded above regardless, but the// per-message notification fires only when the user enabled it.+ const preview = (activity?.preview || '').trim()++ // Content-level dedup, tracked independently of the toast pref so the+ // memory stays accurate whether or not toasts are on: skip re-surfacing an+ // identical preview a busy bridge keeps re-pinging (last_active advances+ // but the visible content is unchanged). Unread marking above is unaffected.+ if (lastToastedPreview.get(key) === preview) {+ continue+ }+ lastToastedPreview.set(key, preview)+if ($activityToasts.get()) {const meta = botRosterMeta(bot, $botMeta.get())const label = displayName(bot, meta)- const preview = (activity?.preview || '').trim()const inbound = /^Message from/i.test(preview)host.notify({kind: 'info',