The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): don't alert for prompts a reconnect replayed
Brooklyn Nicholsone9bb4c39511f
diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.tsindex 61b6f46abcc..f9e89ca434d 100644--- a/apps/desktop/src/store/gateway.ts+++ b/apps/desktop/src/store/gateway.ts@@ -2,6 +2,7 @@ import { type ConnectionState, type GatewayEvent, resolveGatewayWsUrl } from '@himport { atom } from 'nanostores'import { HermesGateway } from '@/hermes'+import { markNativeNotifyBaseline } from '@/store/notify-baseline'import { setGatewayState } from '@/store/session'// ── Multi-profile gateway routing ──────────────────────────────────────────@@ -136,6 +137,12 @@ export function activeGateway(): HermesGateway | null {// composer reflect the active profile's socket without a background reconnect// flipping the foreground enabled/disabled state.function reportGatewayState(profile: string, state: ConnectionState): void {+ // Any socket opening replays parked prompts; hold OS notifications so a+ // launch/reconnect doesn't alert about state that already existed.+ if (state === 'open') {+ markNativeNotifyBaseline()+ }+if (normKey(profile) === g.activeKey) {setGatewayState(state)}diff --git a/apps/desktop/src/store/native-notifications.test.ts b/apps/desktop/src/store/native-notifications.test.tsindex de0bf876542..4ebfd95a88e 100644--- a/apps/desktop/src/store/native-notifications.test.ts+++ b/apps/desktop/src/store/native-notifications.test.ts@@ -9,6 +9,7 @@ import {setNativeNotifyEnabled,setNativeNotifyKind} from './native-notifications'+import { __resetNativeNotifyBaselineForTests, markNativeNotifyBaseline } from './notify-baseline'import { $approvalRequest, setApprovalRequest } from './prompts'import { $activeSessionId, setActiveSessionId } from './session'@@ -43,6 +44,7 @@ beforeEach(() => {setActiveSessionId(null)setWindowState({ focused: false, hidden: true })+ __resetNativeNotifyBaselineForTests()})afterEach(() => {@@ -139,6 +141,35 @@ describe('dispatchNativeNotification preferences', () => {})})+describe('dispatchNativeNotification post-connect baseline', () => {+ it('suppresses a prompt replayed right after a socket opens', () => {+ markNativeNotifyBaseline()+ dispatchNativeNotification({ kind: 'approval', sessionId: freshSession(), title: 'approve' })+ expect(notify).not.toHaveBeenCalled()+ })++ it('suppresses a completion replayed right after a socket opens', () => {+ const sessionId = freshSession()+ setActiveSessionId(sessionId)+ markNativeNotifyBaseline()+ dispatchNativeNotification({ kind: 'turnDone', sessionId, title: 'done' })+ expect(notify).not.toHaveBeenCalled()+ })++ it('fires again once the window has passed', () => {+ vi.useFakeTimers()++ try {+ markNativeNotifyBaseline()+ vi.advanceTimersByTime(5000)+ dispatchNativeNotification({ kind: 'approval', sessionId: freshSession(), title: 'approve' })+ expect(notify).toHaveBeenCalledTimes(1)+ } finally {+ vi.useRealTimers()+ }+ })+})+describe('dispatchNativeNotification throttle', () => {it('collapses duplicate kind+session within the throttle window', () => {const sessionId = freshSession()diff --git a/apps/desktop/src/store/native-notifications.ts b/apps/desktop/src/store/native-notifications.tsindex db56d94a3fa..450360b7666 100644--- a/apps/desktop/src/store/native-notifications.ts+++ b/apps/desktop/src/store/native-notifications.ts@@ -3,6 +3,7 @@ import { atom } from 'nanostores'import { persistString, storedString } from '@/lib/storage'import { $gateway } from './gateway'+import { withinNativeNotifyBaseline } from './notify-baseline'import { clearApprovalRequest } from './prompts'import { $activeSessionId } from './session'@@ -160,6 +161,10 @@ export function dispatchNativeNotification(input: NativeNotificationInput): voidreturn}+ if (withinNativeNotifyBaseline()) {+ return+ }+if (!shouldFire(input.kind, input.sessionId, input.global)) {return}diff --git a/apps/desktop/src/store/notify-baseline.ts b/apps/desktop/src/store/notify-baseline.tsnew file mode 100644index 00000000000..e48fde8ba13--- /dev/null+++ b/apps/desktop/src/store/notify-baseline.ts@@ -0,0 +1,30 @@+// Post-connect quiet window for native (OS) notifications.+//+// A socket opening replays state that already existed: a session parked on an+// approval re-emits its request so the UI can render the prompt. Those are not+// things that just happened, so launching Hermes — or any reconnect, profile+// switch, or gateway-mode apply — would otherwise fire an OS notification for a+// prompt the user has known about for an hour. The in-app surfaces (sidebar+// row, inline approval bar) still show the prompt immediately; only the OS+// notification is held.+//+// Lives in its own leaf module so `store/gateway` (which marks the baseline)+// and `store/native-notifications` (which reads it) don't import each other.++const SEED_QUIET_MS = 4000++let quietUntil = 0++/** Called on every gateway `open`. Opens the quiet window. */+export function markNativeNotifyBaseline(): void {+ quietUntil = Date.now() + SEED_QUIET_MS+}++/** True while replayed post-connect state should not raise an OS notification. */+export function withinNativeNotifyBaseline(): boolean {+ return Date.now() < quietUntil+}++export function __resetNativeNotifyBaselineForTests(): void {+ quietUntil = 0+}