Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): Dock 角标不再被界面读不到的 attention 永久顶高
WZBbiao8047c4f19364
diff --git a/apps/desktop/src/main/__tests__/appBadgeService.test.ts b/apps/desktop/src/main/__tests__/appBadgeService.test.tsindex e8054e19eb..e17f4c2f82 100644--- a/apps/desktop/src/main/__tests__/appBadgeService.test.ts+++ b/apps/desktop/src/main/__tests__/appBadgeService.test.ts@@ -123,7 +123,7 @@ afterEach(() => {});describe('appBadgeService', () => {- it('suppresses late hidden Make notifications through the raw session catalog without dropping Bot attention', async () => {+ it('takes late hidden Make notifications from the raw catalog and keeps off-catalog ids out of the badge', async () => {const service = await freshService();service.markSessionNeedsAttention('hidden-make');expect(service.getAttentionCount()).toBe(1);@@ -131,8 +131,9 @@ describe('appBadgeService', () => {expect(service.getAttentionCount()).toBe(0);service.markSessionNeedsAttention('hidden-make-merge');expect(service.getAttentionCount()).toBe(0);+ // 目录外的任务在界面上没有行、也没有读到/删除这类清除入口:目录就绪后不再抬高角标。service.markSessionNeedsAttention('bot-task');- expect(service.getAttentionCount()).toBe(1);+ expect(service.getAttentionCount()).toBe(0);});it.each([@@ -181,18 +182,29 @@ describe('appBadgeService', () => {expect(dockSetBadge).toHaveBeenLastCalledWith('');});- it('preserves Bot attention outside the catalog and deduplicates IDs entering it', async () => {+ it('drops off-catalog attention once the projection arrives so the badge stays reader-clearable', async () => {const service = await freshService();const event = { sender: mainWebContents };+ // 首份投影前 renderer 还没挂载:逐任务通知独自撑角标,且重复打点不重复计数。+ service.markSessionNeedsAttention('early-task');+ service.markSessionNeedsAttention('early-task');+ expect(service.getAttentionCount()).toBe(1);+ service.markSessionNeedsAttention('late-review-run');+ expect(service.getAttentionCount()).toBe(2);+ // 目录就绪后它就是界面的权威清单:目录外的 id 既不可见也不可清除,必须丢弃,+ // 否则角标会永久停在界面读不掉的数字上(“有未读但点不掉”)。await publish(event, 3, ['a', 'b', 'c']);- service.markSessionNeedsAttention('bot-task');- service.markSessionNeedsAttention('bot-task');- expect(service.getAttentionCount()).toBe(4);- await publish(event, 2, ['a', 'b', 'c']);expect(service.getAttentionCount()).toBe(3);+ expect(service.hasSessionAttention('early-task')).toBe(false);+ expect(service.hasSessionAttention('late-review-run')).toBe(false);+ await publish(event, 2, ['a', 'b', 'c']);+ expect(service.getAttentionCount()).toBe(2);service.clearSessionAttention('bot-task');expect(service.getAttentionCount()).toBe(2);+ // 目录内的 id 始终由投影接管:重复打点、迟到打点都不叠加计数。+ service.markSessionNeedsAttention('bot-task');service.markSessionNeedsAttention('bot-task');+ expect(service.getAttentionCount()).toBe(2);await publish(event, 3, ['a', 'b', 'c', 'bot-task']);expect(service.getAttentionCount()).toBe(3);await publish(event, 0, []);@@ -247,7 +259,7 @@ describe('appBadgeService', () => {await expect(publish(event, 99, ['new-id'])).rejects.toMatchObject({ code: 'INVALID_PARAMS' });expect(service.getAttentionCount()).toBe(4);service.markSessionNeedsAttention('new-id');- expect(service.getAttentionCount()).toBe(5); // 被拒投影没有部分写入目录。+ expect(service.getAttentionCount()).toBe(4); // 被拒投影没有部分写入目录,目录外 id 也不抬角标。service.clearAllSessionAttention();await publish(event, 1, ['x'.repeat(512)]);expect(service.getAttentionCount()).toBe(1);@@ -270,9 +282,9 @@ describe('appBadgeService', () => {expect(setBadgeCount).not.toHaveBeenCalled();expect(setOverlayIcon).not.toHaveBeenCalled();service.markSessionNeedsAttention('rejected-id');- expect(service.getAttentionCount()).toBe(10_001); // Rejected snapshots cannot retain catalog IDs.+ expect(service.getAttentionCount()).toBe(10_000); // Rejected snapshots cannot retain catalog IDs.await publish(event, 0, []);- expect(service.getAttentionCount()).toBe(1); // Directory-external attention remains independent.+ expect(service.getAttentionCount()).toBe(0); // 目录就绪后目录外 attention 不参与计数。},);diff --git a/apps/desktop/src/main/appBadgeService.ts b/apps/desktop/src/main/appBadgeService.tsindex 8c7bdadb3b..57a907ca7a 100644--- a/apps/desktop/src/main/appBadgeService.ts+++ b/apps/desktop/src/main/appBadgeService.ts@@ -19,8 +19,9 @@ const MAX_SNAPSHOT_SESSION_IDS = 10_000;const MAX_SESSION_ID_LENGTH = 512;const MAX_RETAINED_SESSION_IDS = 100_000;const attentionSessionIds = new Set<string>();-// 侧栏就绪后目录内任务按当前状态计数;事件集合补齐伙伴等目录外任务,并服务灵动岛。-// 首份投影前保留事件计数,避免 renderer 尚未挂载时漏掉后台提醒。+// 侧栏就绪后目录内任务按当前状态计数;目录外的 id 既不在界面上出现,也没有+// 「读到 / 删除」这类清除入口,计入只会让角标停在用户点不掉的数字上,因此只在+// 首份投影前用事件集合兜底,避免 renderer 尚未挂载时漏掉后台提醒。let projectedAttentionCount: number | null = null;const projectedSessionIds = new Set<string>();@@ -90,6 +91,11 @@ export function initAppBadgeService(deps: AppBadgeServiceDeps): void {projectedAttentionCount = count;// 曾进入普通目录的任务始终归投影管理,删除/断连后不能被旧通知重新计入。for (const sessionId of uniqueSessionIds) projectedSessionIds.add(sessionId);+ // 目录已是权威清单:留在目录外的 attention 永远不会出现在界面上,也没有任何+ // 清除入口(读不到、删不掉),只会把角标撑出界面上读不掉的数字。直接丢弃。+ for (const sessionId of attentionSessionIds) {+ if (!projectedSessionIds.has(sessionId)) attentionSessionIds.delete(sessionId);+ }if (getAttentionCount() !== previousCount) applyBadge();});ipcMain.handle(@@ -151,19 +157,17 @@ function broadcastSessionAttentionCleared(export function clearAllSessionAttention(): void {attentionSessionIds.clear();- projectedAttentionCount = 0;+ // 回到「尚无投影」状态:新 owner / 退出后 renderer 还没推快照,这段窗口里+ // 逐任务通知必须还能自己撑起角标(写成 0 会让 mark 永远算成空投影)。+ projectedAttentionCount = null;projectedSessionIds.clear();applyBadge();}export function getAttentionCount(): number {+ // 首份投影前只有事件集合可用;此后目录就是界面的权威清单,逐任务通知不再叠加。if (projectedAttentionCount === null) return attentionSessionIds.size;- let count = projectedAttentionCount;- // 伙伴等不在普通目录中的任务沿用逐任务通知;目录内的任务只按投影计数。- for (const sessionId of attentionSessionIds) {- if (!projectedSessionIds.has(sessionId)) count += 1;- }- return count;+ return projectedAttentionCount;}export function hasSessionAttention(sessionId: string): boolean {diff --git a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsxindex ec4a4cb851..40ed26a906 100644--- a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx+++ b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx@@ -20,6 +20,8 @@ const state = vi.hoisted(() => ({workers: new Map<string, ReadonlySet<string>>(),owner: { dataOwnerId: 'owner-a', generation: 1 },isLoading: false,+ historyLoading: false,+ historyError: null as Error | null,publish: vi.fn().mockResolvedValue(undefined),}));const botState = vi.hoisted(() => ({@@ -64,8 +66,8 @@ vi.mock('@/hooks/useCCSessions', () => ({useCCSessions: (options: { includeArchived: string }) => ({sessions:options.includeArchived === 'all' ? (state.history ?? state.sessions) : state.sessions,- isLoading: state.isLoading,- error: null,+ isLoading: options.includeArchived === 'all' ? state.historyLoading : state.isLoading,+ error: options.includeArchived === 'all' ? state.historyError : null,}),}));vi.mock('@/features/device-link/remoteProjectsStore', () => ({@@ -99,6 +101,8 @@ afterEach(() => {state.publish.mockClear();botState.markRead.mockClear(); botState.markRemoteRead.mockClear();state.isLoading = false;+ state.historyLoading = false;+ state.historyError = null;state.sessions = ['a', 'b', 'c'].map((id) => ({ id, status: 'active' }));state.history = null;state.remoteSessions = [];@@ -184,6 +188,23 @@ describe('app badge projection lifecycle', () => {expect(projection.sessionIds).toEqual(expect.arrayContaining(['a', 'b', 'c', 'archived-0']));});+ it('keeps publishing the projection when the archived bucket is still loading or broken', () => {+ vi.stubGlobal('electronAPI', { notificationSetAppAttentionCount: state.publish });+ // 历史桶只补齐去重目录;它一直 loading / 报错也不得把计入数的投影一次次吞掉,+ // 否则角标会永久停在最后一次推送的旧值(界面上已经没有未读了)。+ state.historyLoading = true;+ state.historyError = new Error('db busy');+ render(<AppBadgeAttentionSync />);+ expect(state.publish).toHaveBeenLastCalledWith(+ expect.objectContaining({ count: 3, sessionIds: ['a', 'b', 'c'] }),+ );+ state.historyLoading = false;+ state.historyError = null;+ state.attention = new Map();+ render(<AppBadgeAttentionSync />);+ expect(state.publish).toHaveBeenLastCalledWith(expect.objectContaining({ count: 0 }));+ });+it('keeps remote IDs in the projection but excludes remote attention from the badge', () => {vi.stubGlobal('electronAPI', { notificationSetAppAttentionCount: state.publish });state.remoteSessions = [diff --git a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsxindex 16784243f6..d01169e592 100644--- a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx+++ b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx@@ -90,7 +90,9 @@ export function AppBadgeAttentionSync() {publishNavigationAttention({ tasks: count, teammates });}, [count, teammates, owner]);useEffect(() => {- if (isLoading || error || history.isLoading || history.error) return;+ // 历史桶(includeArchived:'all')只用于补齐目录 ID 做去重,它的加载/失败不影响+ // 本桶的计数;用它 gate 整次推送会让角标永久停在旧值上(投影响应一次永不再发)。+ if (isLoading || error) return;void window.electronAPI.notificationSetAppAttentionCount({count: count + localTeammates,@@ -102,6 +104,6 @@ export function AppBadgeAttentionSync() {log.warn('failed to update app attention count', err);});// 卸载/切路由不是已读,不清图标;下次挂载会重新提交完整投影。- }, [count, localTeammates, isLoading, error, history.isLoading, history.error, catalogSessionIds, owner]);+ }, [count, localTeammates, isLoading, error, catalogSessionIds, owner]);return null;}