Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 排除远程和自动化角标 (#4430)
Lizi27299eaf305c
diff --git a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsxindex bc8e856e34..6aa1bcc475 100644--- a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx+++ b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx@@ -5,7 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';const state = vi.hoisted(() => ({sessions: ['a', 'b', 'c'].map((id) => ({ id, status: 'active' })),history: null as { id: string; status: string }[] | null,- remoteSessions: [] as { id: string; status: string }[],+ remoteSessions: [] as { id: string; status: string; deviceLinkDeviceId?: string }[],attention: new Map<string, string>([['a', 'done'],['b', 'done'],@@ -41,15 +41,11 @@ vi.mock('@/hooks/useCCSessions', () => ({}));vi.mock('@/features/device-link/remoteProjectsStore', () => ({useRemoteProjectSessions: () => state.remoteSessions,- useRemoteScheduleIndex: () => state.empty,}));vi.mock('@/features/cc-agent/hooks/useAutomationScheduleSessionIndex', () => ({usePublishedAutomationScheduleSessionIndex: () => state.empty,}));-vi.mock('@/features/device-link/remoteSessionActivityStore', () => ({- getRemoteSessionActivity: () => undefined,- useRemoteSessionActivityRevision: () => 0,-}));+vi.mock('@/features/device-link/remoteSessionActivityStore', () => ({}));vi.mock('@/lib/makerChatStore', () => ({makerChatStore: { subscribeAll: () => () => {}, getRunningSnapshot: () => state.running },}));@@ -93,9 +89,11 @@ describe('app badge projection lifecycle', () => {expect(projection.sessionIds).toEqual(expect.arrayContaining(['a', 'b', 'c', 'archived-0']));});- it('includes remote leads when projecting active workers', () => {+ it('keeps remote IDs in the projection but excludes remote attention from the badge', () => {vi.stubGlobal('electronAPI', { notificationSetAppAttentionCount: state.publish });- state.remoteSessions = [{ id: 'remote-lead', status: 'active' }];+ state.remoteSessions = [+ { id: 'remote-lead', status: 'active', deviceLinkDeviceId: 'device-a' },+ ];state.attention.set('remote-lead', 'done');state.workers = new Map([['remote-lead', new Set(['remote-worker'])]]);state.starting = new Set(['remote-worker']);@@ -105,7 +103,7 @@ describe('app badge projection lifecycle', () => {);state.starting = new Set();view.rerender(<AppBadgeAttentionSync />);- expect(state.publish).toHaveBeenLastCalledWith(expect.objectContaining({ count: 4 }));+ expect(state.publish).toHaveBeenLastCalledWith(expect.objectContaining({ count: 3 }));});it('tracks starting, background and worker activity through their transitions', () => {diff --git a/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts b/apps/desktop/src/renderer/__tests__/appAttentionCount.test.tsindex 25e032fef0..abab568db3 100644--- a/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts+++ b/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts@@ -16,9 +16,7 @@ function input(overrides: Partial<AppAttentionCountInput> = {}): AppAttentionCouattentionKinds: new Map(),runningSessionIds: new Set(),localActivities: new Map(),- getRemoteActivity: () => undefined,localSchedules: new Map(),- remoteSchedules: new Map(),...overrides,};}@@ -35,29 +33,99 @@ describe('app attention total', () => {expect(countAppAttention(input({ attentionKinds }))).toBe(2);});- it('restores scheduled unread results without in-memory notification events', () => {- const unread = { hasUnreadRun: true, hasUnreadFailedRun: false };+ it('excludes remote and automated sessions from the system badge', () => {expect(countAppAttention(input({+ sessions: [+ session('local'),+ session('remote', { deviceLinkDeviceId: 'device-a' }),+ session('scheduler', { source: 'scheduler' }),+ session('learn', { source: 'learn' }),+ session('legacy', { title: '[Schedule] nightly', source: 'desktop' }),+ ],+ attentionKinds: new Map([+ ['local', 'done'],+ ['remote', 'done'],+ ['scheduler', 'error'],+ ['learn', 'awaiting'],+ ['legacy', 'done'],+ ]),+ }),+ ),+ ).toBe(1);+ });++ it('still counts user-driven attention on ordinary tasks bound by a heartbeat schedule', () => {+ expect(+ countAppAttention(+ input({+ sessions: [+ session('bound-read'),+ session('bound-unread'),+ session('bound-paused'),+ session('scheduler', { source: 'scheduler' }),+ ],+ attentionKinds: new Map([+ ['bound-read', 'done'],+ ['bound-unread', 'awaiting'],+ ['bound-paused', 'error'],+ ['scheduler', 'done'],+ ]),localSchedules: new Map([- ['a', unread],- ['b', unread],+ ['bound-read', { hasUnreadRun: false, hasUnreadFailedRun: false }],+ ['bound-unread', { hasUnreadRun: true, hasUnreadFailedRun: false }],+ ['bound-paused', { hasUnreadRun: false, hasUnreadFailedRun: false }],+ ['scheduler', { hasUnreadRun: true, hasUnreadFailedRun: true }],]),- remoteSchedules: new Map([['c', unread]]),}),),).toBe(3);});- it('deduplicates the same task across activity, notifications and schedule history', () => {+ it('excludes heartbeat-generated done on a bound ordinary task without dropping later user attention', () => {+ const sessions = [session('bound')];+ const localSchedules = new Map([+ ['bound', { hasUnreadRun: true, hasUnreadFailedRun: false }],+ ]);+ expect(+ countAppAttention(+ input({+ sessions,+ attentionKinds: new Map([['bound', 'done']]),+ localSchedules,+ }),+ ),+ ).toBe(0);+ expect(+ countAppAttention(+ input({+ sessions,+ attentionKinds: new Map([['bound', 'awaiting']]),+ localSchedules,+ }),+ ),+ ).toBe(1);+ expect(+ countAppAttention(+ input({+ sessions,+ attentionKinds: new Map([['bound', 'error']]),+ localSchedules: new Map([+ ['bound', { hasUnreadRun: false, hasUnreadFailedRun: false }],+ ]),+ }),+ ),+ ).toBe(1);+ });++ it('deduplicates the same local task across activity and notifications', () => {expect(countAppAttention(input({sessions: [session('a'), session('a')],attentionKinds: new Map([['a', 'error']]),localActivities: new Map([['a', { phase: 'error', attention: true }]]),- localSchedules: new Map([['a', { hasUnreadRun: true, hasUnreadFailedRun: true }]]),}),),).toBe(1);@@ -78,20 +146,14 @@ describe('app attention total', () => {).toBe(2);});- it('includes remote live attention with the same precedence as task rows', () => {+ it('does not promote local activity without an attention signal', () => {expect(countAppAttention(input({localActivities: new Map([['a', { phase: 'running' }]]),- getRemoteActivity: (id) =>- id === 'a'- ? { phase: 'completed', attention: true }- : id === 'b'- ? { phase: 'needs-interaction' }- : undefined,}),),- ).toBe(2);+ ).toBe(0);});it('excludes archived, deleted, worker and missing task records', () => {diff --git a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsxindex 2089939c03..a0f5ecd875 100644--- a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx+++ b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx@@ -1,15 +1,8 @@import { useEffect, useMemo, useSyncExternalStore } from 'react';-import {- getRemoteSessionActivity,- useRemoteSessionActivityRevision,-} from '@/features/device-link/remoteSessionActivityStore';import { makerChatStore } from '@/lib/makerChatStore';import { useCCSessions } from '@/hooks/useCCSessions';-import {- useRemoteProjectSessions,- useRemoteScheduleIndex,-} from '@/features/device-link/remoteProjectsStore';+import { useRemoteProjectSessions } from '@/features/device-link/remoteProjectsStore';import { usePublishedAutomationScheduleSessionIndex } from '@/features/cc-agent/hooks/useAutomationScheduleSessionIndex';import { useSessionAttentionKinds } from '@/lib/sessionAttentionStore';import { useAgentIslandActivityMap } from '@/state/agentIslandActivity';@@ -35,10 +28,8 @@ export function AppBadgeAttentionSync() {[allSessions, history.sessions],);const localSchedules = usePublishedAutomationScheduleSessionIndex();- const remoteSchedules = useRemoteScheduleIndex();const attentionKinds = useSessionAttentionKinds();const localActivities = useAgentIslandActivityMap();- useRemoteSessionActivityRevision();const running = useSyncExternalStore(makerChatStore.subscribeAll,makerChatStore.getRunningSnapshot,@@ -55,10 +46,8 @@ export function AppBadgeAttentionSync() {const count = countAppAttention({sessions: allSessions,localSchedules,- remoteSchedules,attentionKinds,localActivities,- getRemoteActivity: getRemoteSessionActivity,runningSessionIds: displayRunningSessionIds,});useEffect(() => {diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts b/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.tsindex a054e29173..a6cc288166 100644--- a/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts+++ b/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts@@ -6,6 +6,7 @@ import {resolveSidebarRightStatus,type SidebarRightStatusInput,} from '../sidebar/sidebarRightStatus';+import { isAutomationGeneratedSession } from './scheduledSessionGrouping';type ScheduleAttention = { hasUnreadRun: boolean; hasUnreadFailedRun: boolean };@@ -14,34 +15,38 @@ export interface AppAttentionCountInput {attentionKinds: ReadonlyMap<string, AttentionKind>;runningSessionIds: ReadonlySet<string>;localActivities: ReadonlyMap<string, SidebarRightStatusInput['liveActivity']>;- getRemoteActivity: (sessionId: string) => SidebarRightStatusInput['liveActivity'];localSchedules: ReadonlyMap<string, ScheduleAttention>;- remoteSchedules: ReadonlyMap<string, ScheduleAttention>;}/** 与任务行的红/蓝/绿点同源,不随搜索、折叠或当前机器筛选改变。 */export function countAppAttention(input: AppAttentionCountInput): number {const attentionIds = new Set<string>();for (const session of input.sessions) {- if (session.status !== 'active' || isOrcaWorkerSession(session)) continue;- const localSchedule = input.localSchedules.get(session.id);- const remoteSchedule = input.remoteSchedules.get(session.id);+ if (+ session.status !== 'active' ||+ isOrcaWorkerSession(session) ||+ session.deviceLinkDeviceId !== undefined ||+ isAutomationGeneratedSession(session) ||+ session.source === 'learn'+ )+ continue;const activity = projectSidebarSessionActivity({interruption: session,sessionId: session.id,title: session.title,recordStatus: session.status,- liveActivity: input.getRemoteActivity(session.id) ?? input.localActivities.get(session.id),+ liveActivity: input.localActivities.get(session.id),attentionKind: input.attentionKinds.get(session.id),- isUrgentFromContext:- localSchedule?.hasUnreadFailedRun === true || remoteSchedule?.hasUnreadFailedRun === true,+ isUrgentFromContext: false,isRunning: input.runningSessionIds.has(session.id),- hasAttentionNotification:- input.attentionKinds.has(session.id) ||- localSchedule?.hasUnreadRun === true ||- remoteSchedule?.hasUnreadRun === true,+ hasAttentionNotification: input.attentionKinds.has(session.id),});const status = resolveSidebarRightStatus(activity);+ // heartbeat 绑普通任务时 runner 保留 desktop 来源,完成会写入 done;+ // 只压未读自动化 done,不连同之后的 awaiting / error 一起丢掉。+ if (status === 'done' && input.localSchedules.get(session.id)?.hasUnreadRun === true) {+ continue;+ }if (status === 'done' || status === 'awaiting' || status === 'error') {attentionIds.add(session.id);}