Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve Feishu alerts for unbound handoffs
guyonge2816ac152b5
diff --git a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.tsindex aeb3ade135..8d1fa147cd 100644--- a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts@@ -9,6 +9,7 @@ import {} from '@/lib/sessionEventNotification';import { applyRemoteSessionActivity, clearRemoteSessionActivity, getRemoteSessionActivity } from '@/features/device-link/remoteSessionActivityStore';import { SessionActivityRelay } from '../../main/agent-island/sessionActivityRelay';+import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';const gates = vi.hoisted(() => ({desktop: true,@@ -29,7 +30,9 @@ vi.mock('@/hooks/useAgentIslandSettings', () => ({}));const markAttention = vi.fn(() => Promise.resolve());-const showSessionEvent = vi.fn(() => Promise.resolve());+const showSessionEvent = vi.fn<typeof window.electronAPI.notificationShowSessionEvent>(() => Promise.resolve());+const getSession = vi.fn(async (): Promise<unknown> => ({ source: 'desktop', feishuOpenId: null }));+const resolveBinding = vi.fn(async () => ({ attached: false }));describe('shared session event notifications', () => {it.each(['before-clear', 'after-clear'])('does not notify for a cleared remote completion (%s)', order => {@@ -68,16 +71,20 @@ describe('shared session event notifications', () => {gates.islandEnabled = false;gates.islandSupported = false;vi.clearAllMocks();+ getSession.mockResolvedValue({ source: 'desktop', feishuOpenId: null });+ resolveBinding.mockResolvedValue({ attached: false });vi.spyOn(document, 'hasFocus').mockReturnValue(false);(window as unknown as { electronAPI: unknown }).electronAPI = {notificationMarkSessionAttention: markAttention,notificationShowSessionEvent: showSessionEvent,- localDb: { bots: { list: vi.fn(async () => []) } },+ localDb: { bots: { list: vi.fn(async () => []) }, sessions: { get: getSession } },+ binding: { resolveSession: resolveBinding },};});afterEach(() => {clearRemoteSessionActivity();+ setDataOwnerGeneration(null);vi.restoreAllMocks();});@@ -109,6 +116,72 @@ describe('shared session event notifications', () => {});});+ // #6754: only channel-driven / attached handoffs already have Main's pointer.+ // Exercise the shared delivery entry, including the channels sent to Main.+ it.each([+ { source: 'desktop', openId: null, attached: false, fallback: true },+ { source: 'feishu', openId: 'ou_native', attached: false, fallback: false },+ { source: 'desktop', openId: 'ou_legacy', attached: false, fallback: false },+ { source: 'desktop', openId: null, attached: true, fallback: false },+ { source: 'telegram', openId: null, attached: false, fallback: false },+ ])('preserves handoff Feishu delivery only without Main channel ownership: %j', async entry => {+ gates.feishu = true;+ getSession.mockResolvedValue({ source: entry.source, feishuOpenId: entry.openId });+ resolveBinding.mockResolvedValue({ attached: entry.attached });++ sendSessionEventNotification('handoff', 'Task', 'needs-reply', { inputHandoff: true });+ // Desktop must not wait for the asynchronous route lookup.+ expect(showSessionEvent).toHaveBeenCalledWith({+ sessionId: 'handoff', title: 'Task', kind: 'needs-reply',+ channels: { desktop: true, feishu: false, mobile: false },+ });+ await Promise.resolve();+ await Promise.resolve();++ expect(showSessionEvent.mock.calls.map(([payload]) => payload.channels)).toEqual([+ { desktop: true, feishu: false, mobile: false },+ ...(entry.fallback ? [{ desktop: false, feishu: true, mobile: false }] : []),+ ]);+ expect(markAttention).toHaveBeenCalledTimes(1);+ if (entry.fallback) expect(showSessionEvent).toHaveBeenLastCalledWith({+ sessionId: 'handoff', title: 'Task', kind: 'needs-reply', markAttention: false,+ channels: { desktop: false, feishu: true, mobile: false },+ });+ });++ it.each(['owner-change', 'setting-off', 'focused', 'read-failed'] as const)(+ 'drops a pending handoff Feishu fallback after %s', async change => {+ gates.feishu = true;+ let release!: (row: unknown) => void;+ getSession.mockReturnValueOnce(new Promise(resolve => { release = resolve; }));+ sendSessionEventNotification('handoff', 'Task', 'needs-reply', { inputHandoff: true });+ if (change === 'owner-change') setDataOwnerGeneration('another-owner');+ if (change === 'setting-off') gates.feishu = false;+ if (change === 'focused') vi.mocked(document.hasFocus).mockReturnValue(true);+ release(change === 'read-failed' ? null : { source: 'desktop' });+ await Promise.resolve();+ await Promise.resolve();+ expect(showSessionEvent).toHaveBeenCalledTimes(1);+ expect(showSessionEvent).toHaveBeenCalledWith({+ sessionId: 'handoff', title: 'Task', kind: 'needs-reply',+ channels: { desktop: true, feishu: false, mobile: false },+ });+ },+ );++ it('keeps remote handoff routing on the execution host without querying local IM bindings', () => {+ gates.feishu = true;+ sendSessionEventNotification('remote-handoff', 'Task', 'needs-reply', {+ inputHandoff: true, remoteDevice: true, remoteDeviceId: 'host',+ });+ expect(showSessionEvent).toHaveBeenCalledExactlyOnceWith({+ sessionId: 'remote-handoff', title: 'Task', kind: 'needs-reply', markAttention: false,+ channels: { desktop: false, feishu: false, mobile: false },+ });+ expect(getSession).not.toHaveBeenCalled();+ expect(resolveBinding).not.toHaveBeenCalled();+ });+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__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.tsindex 6e25095c2d..97cf395c24 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', { mobile: false, feishu: false });+ expect(onSessionNeedsReply).toHaveBeenCalledExactlyOnceWith('s-handoff', { inputHandoff: true });first.result.current.clearNotification('s-handoff');first.unmount();vi.mocked(addSessionAttention).mockClear();@@ -693,7 +693,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);- expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-handoff', { mobile: false, feishu: false });+ expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-handoff', { inputHandoff: true });expect(addSessionAttention).toHaveBeenCalledWith('s-handoff', 'awaiting');await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);@@ -708,7 +708,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {...status(false), hasPendingInputHandoff: true, hasActionableInputHandoff: true,pendingRequestKeys: ['handoff:same-request:1'],}]]));- expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-mixed', { mobile: false, feishu: false });+ expect(onSessionNeedsReply).toHaveBeenLastCalledWith('s-mixed', { inputHandoff: true });await emitSnapshot(new Map([['s-mixed', {...status(false), hasPendingInputHandoff: true, hasActionableInputHandoff: true,diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsxindex d4bc3e4446..0d20af112c 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', options?: { mobile: false; feishu: false }) => {+ (sessionId: string, kind: 'done' | 'error' | 'needs-reply', options?: { inputHandoff: true }) => {const session = findSessionNotificationSession(sessionId, [sessionsRef.current,allSessionsForNotificationRef.current,@@ -1266,7 +1266,7 @@ function ExpandedView({[fireSessionNotification],);const handleSessionNeedsReply = useCallback(- (sessionId: string, options?: { mobile: false; feishu: false }) => fireSessionNotification(sessionId, 'needs-reply', options),+ (sessionId: string, options?: { inputHandoff: true }) => fireSessionNotification(sessionId, 'needs-reply', options),[fireSessionNotification],);diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex ea62b6b007..0180e70779 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, options?: { mobile: false; feishu: false }) => void;+ onSessionNeedsReply?: (sessionId: string, options?: { inputHandoff: true }) => void;}/**@@ -383,9 +383,8 @@ export function useSessionRunningStatus(addSessionAttention(id, 'awaiting');}if (!wasAlreadyPending) {- // Main sends each actionable step its fixed-copy phone push and one- // Feishu/channel pointer per request (including desktop /ctr). Keep- // the desktop reminder without repeating those external notices.+ // Main owns the fixed-copy phone push. The notification helper checks+ // existing IM routing before deciding whether Feishu needs a fallback.const handoffOnly = newKeys?.length? newKeys.every((key) => key.startsWith('handoff:')): info.hasActionableInputHandoff === true@@ -393,7 +392,7 @@ export function useSessionRunningStatus(&& !info.hasPendingPermission&& !info.hasPendingPlanReview&& !info.hasPendingPluginSetup;- if (handoffOnly) onSessionNeedsReplyRef.current?.(id, { mobile: false, feishu: false });+ if (handoffOnly) onSessionNeedsReplyRef.current?.(id, { inputHandoff: true });else onSessionNeedsReplyRef.current?.(id);}// Other hook consumers only read running status. They may add thediff --git a/apps/desktop/src/renderer/lib/sessionEventNotification.ts b/apps/desktop/src/renderer/lib/sessionEventNotification.tsindex ead32ababd..0862caff26 100644--- a/apps/desktop/src/renderer/lib/sessionEventNotification.ts+++ b/apps/desktop/src/renderer/lib/sessionEventNotification.ts@@ -4,6 +4,7 @@ import { getNotificationsEnabled } from '@/hooks/useNotificationSettings';import { isDefaultDraftSessionTitle } from '@cindy/maker-shared/session-title';import { getRemoteSessionActivity, subscribeRemoteSessionActivity } from '@/features/device-link/remoteSessionActivityStore';import { isReviewSessionSource } from '../../shared/sessionSource';+import { getDataOwnerGeneration, isDataOwnerGenerationCurrent } from '@/contexts/dataOwnerGeneration';export type SessionEventNotificationKind = 'done' | 'error' | 'needs-reply';@@ -110,14 +111,28 @@ export function sendSessionEventNotification(remoteDeviceId?: string | null;/** Main owns the fixed-copy phone push for input-handoff steps. */mobile?: boolean;- /** Main owns the one-time Feishu/channel pointer for input handoffs. */+ /** Explicit Feishu delivery override for the ordinary notification path. */feishu?: boolean;+ /** Main owns the phone push; Feishu falls back only without an IM target. */+ inputHandoff?: true;} = {},): void {// The user is already looking at Cindy. In-app attention remains available,// but an OS/external notification would be duplicate noise.if (typeof document !== 'undefined' && document.hasFocus()) return;+ if (kind === 'needs-reply' && options.inputHandoff) {+ // Keep the desktop reminder immediate while existing IPC reads determine+ // whether Main already sends the request's fixed pointer in an IM channel.+ deliverSessionEventNotification(sessionId, title, kind, options.remoteDevice === true,+ { ...options, mobile: false, feishu: false });+ // The controller cannot resolve the execution host's IM bindings locally.+ if (options.remoteDevice !== true && options.feishu !== false && getFeishuNotificationsEnabled()) {+ void sendUnhandledHandoffFeishuNotification(sessionId, title);+ }+ return;+ }+if (kind === 'done' && options.remoteDeviceId) {sendRemoteCompletionNotification(sessionId, options.remoteDeviceId, () =>deliverSessionEventNotification(sessionId, title, kind, true, options));@@ -127,6 +142,33 @@ export function sendSessionEventNotification(deliverSessionEventNotification(sessionId, title, kind, options.remoteDevice === true, options);}+const IM_SESSION_SOURCES = new Set(['feishu', 'slack', 'telegram', 'x', 'discord', 'wechat', 'dingtalk', 'wecom']);++/** Ordinary Desktop handoffs have no Main IM pointer; preserve the owner's global Feishu setting. */+async function sendUnhandledHandoffFeishuNotification(sessionId: string, title: string): Promise<void> {+ const owner = getDataOwnerGeneration();+ try {+ const [row, binding] = await Promise.all([+ window.electronAPI.localDb.sessions.get(sessionId),+ window.electronAPI.binding.resolveSession(sessionId),+ ]);+ // Failed/absent routing data is not proof that Main has no target.+ if (!row || typeof row !== 'object' || Array.isArray(row)) return;+ const session = row as { source?: unknown; feishuOpenId?: unknown };+ if (binding.attached+ || (typeof session.source === 'string' && IM_SESSION_SOURCES.has(session.source))+ || (typeof session.feishuOpenId === 'string' && session.feishuOpenId.trim())) return;+ if (!isDataOwnerGenerationCurrent(owner) || !getFeishuNotificationsEnabled()+ || (typeof document !== 'undefined' && document.hasFocus())) return;+ await window.electronAPI.notificationShowSessionEvent({+ sessionId, title, kind: 'needs-reply', markAttention: false,+ channels: { desktop: false, feishu: true, mobile: false },+ });+ } catch {+ // Best effort: a failed lookup never delays the desktop or duplicates an IM pointer.+ }+}+const pendingRemoteCompletions = new Map<string, () => void>();/** The execution host owns this decision; the controller has no delegation DB row. */