Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): avoid duplicate handoff phone reminders
guyong06677bf72e2d
diff --git a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.tsindex 96068e0b60..91f48d563f 100644--- a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts@@ -95,6 +95,20 @@ describe('shared session event notifications', () => {});});+ it('keeps desktop and Feishu reminders but skips generic phone delivery for an input handoff', () => {+ gates.feishu = true;++ sendSessionEventNotification('handoff-session', 'Task', 'needs-reply', { mobile: false });++ expect(markAttention).toHaveBeenCalledWith('handoff-session');+ expect(showSessionEvent).toHaveBeenCalledWith({+ sessionId: 'handoff-session',+ title: 'Task',+ kind: 'needs-reply',+ channels: { desktop: true, feishu: true, mobile: false },+ });+ });+it('lets Agent Island replace desktop notification without suppressing other channels', () => {gates.islandSupported = true;gates.islandEnabled = true;diff --git a/apps/desktop/src/renderer/__tests__/sessionTitleProjectionOutlets.test.ts b/apps/desktop/src/renderer/__tests__/sessionTitleProjectionOutlets.test.tsindex 878041b9d5..7838f7ee95 100644--- a/apps/desktop/src/renderer/__tests__/sessionTitleProjectionOutlets.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionTitleProjectionOutlets.test.ts@@ -126,7 +126,7 @@ describe('desktop 会话标题投影出口', () => {// lanes never notify (docs/product-rules/bot-group-chat.md §3).expect(sidebarUpper).toContain('if (botTitle === BOT_GROUP_LANE_SESSION) return;');expect(sidebarUpper).toContain(- 'sendSessionEventNotification(sessionId, botTitle ?? unnamedLabelRef.current, kind);',+ 'sendSessionEventNotification(sessionId, botTitle ?? unnamedLabelRef.current, kind, options);',);expect(sidebarUpper).toContain("unnamedLabelRef.current = t('ccAgent.common.unnamedSession');");});diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.tsindex 50c9862dd6..88764e40ad 100644--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts@@ -673,7 +673,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {});await emitSnapshot(new Map([['s-handoff', handoffStatus(1)]]));- expect(onSessionNeedsReply).toHaveBeenCalledExactlyOnceWith('s-handoff');+ expect(onSessionNeedsReply).toHaveBeenCalledExactlyOnceWith('s-handoff', { mobile: false });first.result.current.clearNotification('s-handoff');first.unmount();vi.mocked(addSessionAttention).mockClear();@@ -693,11 +693,32 @@ describe('useSessionRunningStatus silenced completion handling', () => {await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);+ expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-handoff', { mobile: false });expect(addSessionAttention).toHaveBeenCalledWith('s-handoff', 'awaiting');await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);});+ it('keeps generic mobile delivery for a new permission alongside a handoff step', async () => {+ setDataOwnerGeneration('mixed-handoff-owner');+ const onSessionNeedsReply = vi.fn();+ renderHook(() => useSessionRunningStatus(undefined, { onSessionNeedsReply }));++ await emitSnapshot(new Map([['s-mixed', {+ ...status(false), hasPendingInputHandoff: true, hasActionableInputHandoff: true,+ pendingRequestKeys: ['handoff:same-request:1'],+ }]]));+ expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-mixed', { mobile: false });++ await emitSnapshot(new Map([['s-mixed', {+ ...status(false), hasPendingInputHandoff: true, hasActionableInputHandoff: true,+ hasPendingPermission: true,+ pendingRequestKeys: ['handoff:same-request:1', 'permission:new-request'],+ }]]));+ expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-mixed');+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);+ });+it('alerts for a different request while the sidebar is hidden, then again for a new owner', async () => {setDataOwnerGeneration('first-owner');const onSessionNeedsReply = vi.fn();diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsxindex 19646851b9..ee2405e0da 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx@@ -1206,7 +1206,7 @@ function ExpandedView({const unnamedLabelRef = useRef('');unnamedLabelRef.current = t('ccAgent.common.unnamedSession');const fireSessionNotification = useCallback(- (sessionId: string, kind: 'done' | 'error' | 'needs-reply') => {+ (sessionId: string, kind: 'done' | 'error' | 'needs-reply', options?: { mobile: false }) => {const session = findSessionNotificationSession(sessionId, [sessionsRef.current,allSessionsForNotificationRef.current,@@ -1229,7 +1229,7 @@ function ExpandedView({projectDraftSessionTitle(session.title, unnamedLabelRef.current),leadSession ? projectDraftSessionTitle(leadSession.title, unnamedLabelRef.current) : null,);- sendSessionEventNotification(sessionId, title, kind);+ sendSessionEventNotification(sessionId, title, kind, options);return;}// /review 审查任务不单独通知:结果回到来源任务,由来源任务的轮次收尾通知。@@ -1241,6 +1241,7 @@ function ExpandedView({sendSessionEventNotification(sessionId, title, kind, {remoteDevice: !!session.deviceLinkDeviceId,remoteDeviceId: session.deviceLinkDeviceId,+ ...options,});return;}@@ -1249,7 +1250,7 @@ function ExpandedView({const botTitle = await botOwnedSessionNotificationTitle(sessionId);// 伙伴群专线不发系统通知,确认请求在群聊里提示(docs/product-rules/bot-group-chat.md §3)。if (botTitle === BOT_GROUP_LANE_SESSION) return;- sendSessionEventNotification(sessionId, botTitle ?? unnamedLabelRef.current, kind);+ sendSessionEventNotification(sessionId, botTitle ?? unnamedLabelRef.current, kind, options);})();},[],@@ -1263,7 +1264,7 @@ function ExpandedView({[fireSessionNotification],);const handleSessionNeedsReply = useCallback(- (sessionId: string) => fireSessionNotification(sessionId, 'needs-reply'),+ (sessionId: string, options?: { mobile: false }) => fireSessionNotification(sessionId, 'needs-reply', options),[fireSessionNotification],);diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex 8cdd06d0f3..abbacde465 100644--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts@@ -103,7 +103,7 @@ interface UseSessionRunningStatusOptions {* edge fires for a new request (or new input-handoff step) in the session.* Like onSessionDone, no active-session filter; the consumer decides.*/- onSessionNeedsReply?: (sessionId: string) => void;+ onSessionNeedsReply?: (sessionId: string, options?: { mobile: false }) => void;}/**@@ -370,10 +370,11 @@ export function useSessionRunningStatus(const keys = info.hasActionableInputHandoff? info.pendingRequestKeys: info.pendingRequestKeys?.filter((key) => !key.startsWith('handoff:'));+ const newKeys = keys?.filter((key) =>+ !notifiedPendingRequests.get(id)?.has(key)+ && !prevPendingKeysRef.current.get(id)?.has(key));const wasAlreadyPending = keys?.length- ? !keys.some((key) =>- !notifiedPendingRequests.get(id)?.has(key)- && !prevPendingKeysRef.current.get(id)?.has(key))+ ? newKeys?.length === 0: prevPendingRef.current.has(id);if (keys?.length) currentPendingKeys.set(id, new Set(keys));// A cleared dot stays cleared for the same request across status ticks@@ -382,7 +383,17 @@ export function useSessionRunningStatus(addSessionAttention(id, 'awaiting');}if (!wasAlreadyPending) {- onSessionNeedsReplyRef.current?.(id);+ // Main already sends each actionable handoff step its fixed-copy phone+ // push. Keep the desktop reminder without sending a second generic one.+ const handoffOnly = newKeys?.length+ ? newKeys.every((key) => key.startsWith('handoff:'))+ : info.hasActionableInputHandoff === true+ && !info.hasPendingAskUser+ && !info.hasPendingPermission+ && !info.hasPendingPlanReview+ && !info.hasPendingPluginSetup;+ if (handoffOnly) onSessionNeedsReplyRef.current?.(id, { mobile: false });+ else onSessionNeedsReplyRef.current?.(id);}// Other hook consumers only read running status. They may add the// in-app dot, but must not consume the system notification owner's edge.diff --git a/apps/desktop/src/renderer/lib/sessionEventNotification.ts b/apps/desktop/src/renderer/lib/sessionEventNotification.tsindex 3f865392be..4f7f7e7649 100644--- a/apps/desktop/src/renderer/lib/sessionEventNotification.ts+++ b/apps/desktop/src/renderer/lib/sessionEventNotification.ts@@ -108,6 +108,8 @@ export function sendSessionEventNotification(*/remoteDevice?: boolean;remoteDeviceId?: string | null;+ /** Main owns the fixed-copy phone push for input-handoff steps. */+ mobile?: boolean;} = {},): void {// The user is already looking at Cindy. In-app attention remains available,@@ -116,11 +118,11 @@ export function sendSessionEventNotification(if (kind === 'done' && options.remoteDeviceId) {sendRemoteCompletionNotification(sessionId, options.remoteDeviceId, () =>- deliverSessionEventNotification(sessionId, title, kind, true));+ deliverSessionEventNotification(sessionId, title, kind, true, options.mobile !== false));return;}- deliverSessionEventNotification(sessionId, title, kind, options.remoteDevice === true);+ deliverSessionEventNotification(sessionId, title, kind, options.remoteDevice === true, options.mobile !== false);}const pendingRemoteCompletions = new Map<string, () => void>();@@ -158,7 +160,7 @@ function sendRemoteCompletionNotification(sessionId: string, deviceId: string, dpendingRemoteCompletions.set(key, cancel);}-function deliverSessionEventNotification(sessionId: string, title: string, kind: SessionEventNotificationKind, remoteDevice: boolean): void {+function deliverSessionEventNotification(sessionId: string, title: string, kind: SessionEventNotificationKind, remoteDevice: boolean, mobile: boolean): void {// A handoff can finish after the user has opened Cindy or changed preferences.if (typeof document !== 'undefined' && document.hasFocus()) return;@@ -174,7 +176,7 @@ function deliverSessionEventNotification(sessionId: string, title: string, kind:feishu: getFeishuNotificationsEnabled(),// Mobile owns registration/unregistration of its push token. There is// deliberately no second desktop setting for the same channel.- mobile: true,+ mobile,},});}