Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(orca): retain awaiting badges for pending worker interactions

fmfsaisai937643356a11
diff --git a/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx b/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
index 8c511e4092..cadf017ce9 100644
--- a/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
@@ -16,7 +16,10 @@ import { useConversationSearch } from '../features/cc-agent/sidebar/Conversation
import { SidebarInlineSearch } from '../features/cc-agent/sidebar/SidebarInlineSearch';
import { ConfirmDialogProvider, useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
-vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
vi.mock('@/components/ui/tooltip', () => ({ Tip: ({ children }: { children: ReactNode }) => children }));
vi.mock('@/features/device-link/useMachineSwitcher', () => ({ useEffectiveSelectedMachineId: () => 'all' }));
vi.mock('@/hooks/useReducedMotion', () => ({ useReducedMotion: () => true }));
diff --git a/apps/desktop/src/renderer/__tests__/onlineDeviceHeaders.test.tsx b/apps/desktop/src/renderer/__tests__/onlineDeviceHeaders.test.tsx
index 08e87862c1..e4fc61d436 100644
--- a/apps/desktop/src/renderer/__tests__/onlineDeviceHeaders.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/onlineDeviceHeaders.test.tsx
@@ -11,7 +11,10 @@ import {
type ProjectsSectionProps,
} from '../features/cc-agent/sidebar/sections/ProjectsSection';
-vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
const feature = vi.hoisted(() => ({ enabled: true }));
vi.mock('@cindy/maker-shared/cindy-make-feature', async (importOriginal) => ({
...await importOriginal<typeof import('@cindy/maker-shared/cindy-make-feature')>(),
diff --git a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
index 539cea4b36..8c57286e8b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/RolePillDropdown.tsx
@@ -25,7 +25,8 @@ import { useReducedMotion } from '@/hooks/useReducedMotion';
import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
import { Tip } from '@/components/ui/tooltip';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
-import { useSessionsAttentionKindMap, type AttentionKind } from '@/lib/sessionAttentionStore';
+import type { AttentionKind } from '@/lib/sessionAttentionStore';
+import { localOrcaWorkerSessionIds, useOrcaWorkerTaskAttentionKinds } from './lib/orcaWorkerTaskAttention';
import { VendorIcon, agentKindToVendor } from '@/components/sidebar/VendorIcon';
import type { WorkerInfo } from './hooks/useWorkers';
import type { WorkerExecutionDevice } from './hooks/workerProjectionStore';
@@ -47,11 +48,7 @@ export function resolveWorkerListAttention(
/** 只订阅本列表本机任务的子映射:底层以 primitive key 比较,其他任务的广播不会重渲染列表。 */
function useWorkerTaskAttention(workers: readonly WorkerInfo[]) {
- return useSessionsAttentionKindMap(
- workers
- .filter((worker) => !worker.executionDevice && !isRemoteSessionSticky(worker.sessionId))
- .map((worker) => worker.sessionId),
- );
+ return useOrcaWorkerTaskAttentionKinds(localOrcaWorkerSessionIds(workers));
}
// Strip provider prefix: 'deepseek/deepseek-v4-pro' → 'deepseek-v4-pro'.
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RemoteWorkerSessionPane.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RemoteWorkerSessionPane.test.tsx
index 0124f8e842..c57ab36b74 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RemoteWorkerSessionPane.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RemoteWorkerSessionPane.test.tsx
@@ -21,6 +21,7 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({
t: (key: string, opts?: { device?: string }) => (opts?.device ? `${key}:${opts.device}` : key),
}),
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.anchorMenuResize.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.anchorMenuResize.test.tsx
index 868c513715..4eafa45178 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.anchorMenuResize.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.anchorMenuResize.test.tsx
@@ -7,6 +7,7 @@ import type { WorkerInfo } from '../hooks/useWorkers';
import { WorkerListToolbar } from '../RolePillDropdown';
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.executionDevice.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.executionDevice.test.tsx
index d217954c5b..7689110751 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.executionDevice.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.executionDevice.test.tsx
@@ -11,6 +11,7 @@ import { RolePillDropdown } from '../RolePillDropdown';
const confirm = vi.hoisted(() => vi.fn(async (_opts: { description: string }) => false));
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.layoutMenu.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.layoutMenu.test.tsx
index 0324fa79d1..063827a129 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.layoutMenu.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.layoutMenu.test.tsx
@@ -4,6 +4,7 @@ import { Profiler } from 'react';
import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { SessionStatusInfo } from '@/lib/makerChatStore';
import type { WorkerInfo } from '../hooks/useWorkers';
import { WorkerListToolbar } from '../RolePillDropdown';
import {
@@ -16,6 +17,31 @@ import {
__resetWorkerAttentionStoreForTest,
} from '../lib/workerAttentionStore';
+const chat = vi.hoisted(() => ({
+ statuses: new Map<string, SessionStatusInfo>(),
+ listeners: new Set<() => void>(),
+}));
+vi.mock('@/lib/makerChatStore', () => ({
+ makerChatStore: {
+ getRunningSnapshot: () => chat.statuses,
+ subscribeAll: (listener: () => void) => {
+ chat.listeners.add(listener);
+ return () => chat.listeners.delete(listener);
+ },
+ },
+}));
+function setPendingAsk(sessionId: string, pending: boolean) {
+ chat.statuses = new Map(chat.statuses).set(sessionId, {
+ isRunning: true,
+ hasError: false,
+ hasPendingAskUser: pending,
+ hasPendingPermission: false,
+ hasPendingPlanReview: false,
+ hasPendingPluginSetup: false,
+ });
+ for (const listener of chat.listeners) listener();
+}
+
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, values?: { totalCount: number; activeCount: number }) =>
@@ -216,6 +242,7 @@ describe('Worker list task attention', () => {
for (const id of getSessionAttentionKinds().keys())
clearSessionAttention(id, { intent: 'explicit' });
__resetWorkerAttentionStoreForTest();
+ chat.statuses = new Map();
});
it.each(['tabs', 'dropdown'] as const)(
@@ -325,6 +352,28 @@ describe('Worker list task attention', () => {
expect(screen.queryByLabelText('orca.rolePill.unread')).toBeNull();
});
+ it.each(['tabs', 'dropdown'] as const)(
+ '%s:切回后任务 awaiting 已清,未处理确认仍亮,处理后消失',
+ (layout) => {
+ localStorage.setItem('orca-worker-list-layout-v1', layout);
+ const current = worker();
+ renderToolbar();
+ act(() => {
+ setPendingAsk(current.sessionId, true);
+ addSessionAttention(current.sessionId, 'awaiting');
+ });
+ act(() => clearSessionAttention(current.sessionId));
+ expect(getSessionAttentionKinds().has(current.sessionId)).toBe(false);
+ expect(screen.getByLabelText('orca.rolePill.awaitingBadgeAria')).toBeTruthy();
+ fireEvent.click(
+ layout === 'tabs' ? menuButton() : screen.getByRole('button', { name: /developer/ }),
+ );
+ expect(screen.getAllByLabelText('orca.rolePill.awaitingBadgeAria').length).toBe(2);
+ act(() => setPendingAsk(current.sessionId, false));
+ expect(screen.queryByLabelText('orca.rolePill.awaitingBadgeAria')).toBeNull();
+ },
+ );
+
it('其他任务的提醒变化不重新渲染 Worker 列表', () => {
const onRender = vi.fn();
const current = worker();
@@ -347,6 +396,11 @@ describe('Worker list task attention', () => {
onRender.mockClear();
act(() => addSessionAttention('unrelated-session', 'error'));
expect(onRender).not.toHaveBeenCalled();
+ act(() => {
+ setPendingAsk('unrelated-session', true);
+ for (let i = 0; i < 100; i++) setPendingAsk(current.sessionId, false);
+ });
+ expect(onRender).not.toHaveBeenCalled();
act(() => addSessionAttention(current.sessionId, 'awaiting'));
expect(onRender).toHaveBeenCalled();
expect(screen.getByLabelText('orca.rolePill.awaitingBadgeAria')).toBeTruthy();
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.settings.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.settings.test.tsx
index 7e871af36b..56fca89519 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.settings.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.settings.test.tsx
@@ -7,6 +7,7 @@ import type { WorkerInfo } from '../hooks/useWorkers';
import { RolePillDropdown, WorkerListToolbar } from '../RolePillDropdown';
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx
index 794ae44b4c..b266f2f9e6 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/RolePillDropdown.tabsScroll.test.tsx
@@ -8,6 +8,7 @@ import { WorkerListToolbar, workerTabsScrollStep } from '../RolePillDropdown';
import { __resetWorkerAttentionStoreForTest, hasWorkerAttention, markWorkerAttention } from '../lib/workerAttentionStore';
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/workerEffortLabel.test.ts b/apps/desktop/src/renderer/features/cc-agent/__tests__/workerEffortLabel.test.ts
index 9bc5b2588d..dec726bab7 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/workerEffortLabel.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/workerEffortLabel.test.ts
@@ -8,6 +8,7 @@ import type { WorkerInfo } from '../hooks/useWorkers';
import { RolePillDropdown, WorkerListToolbar } from '../RolePillDropdown';
vi.mock('react-i18next', () => ({
+ initReactI18next: { type: '3rdParty', init: () => {} },
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/__tests__/orcaLeadWorkerAttention.test.ts b/apps/desktop/src/renderer/features/cc-agent/lib/__tests__/orcaLeadWorkerAttention.test.ts
index 8d91816525..57cb9ba794 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/__tests__/orcaLeadWorkerAttention.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/__tests__/orcaLeadWorkerAttention.test.ts
@@ -1,5 +1,8 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { Session } from '@/lib/ccAgent.types';
+import { countAppAttention } from '../appAttentionCount';
+import type { SessionStatusInfo } from '@/lib/makerChatStore';
import type { WorkersSnapshot } from '../../hooks/workerProjectionStore';
const projection = vi.hoisted(() => ({
@@ -8,6 +11,32 @@ const projection = vi.hoisted(() => ({
listeners: new Set<() => void>(),
}));
+const chat = vi.hoisted(() => ({
+ statuses: new Map<string, SessionStatusInfo>(),
+ listeners: new Set<() => void>(),
+}));
+vi.mock('@/lib/makerChatStore', () => ({
+ makerChatStore: {
+ getRunningSnapshot: () => chat.statuses,
+ subscribeAll: (listener: () => void) => {
+ chat.listeners.add(listener);
+ return () => chat.listeners.delete(listener);
+ },
+ },
+}));
+function setPending(sessionId: string, pending: Partial<SessionStatusInfo>) {
+ chat.statuses = new Map(chat.statuses).set(sessionId, {
+ isRunning: true,
+ hasError: false,
+ hasPendingAskUser: false,
+ hasPendingPermission: false,
+ hasPendingPlanReview: false,
+ hasPendingPluginSetup: false,
+ ...pending,
+ });
+ for (const listener of chat.listeners) listener();
+}
+
vi.mock('@/lib/makerTransport', () => ({
isRemoteSessionSticky: (sessionId: string) => sessionId === 'remote-lead',
}));
@@ -79,6 +108,7 @@ function kinds(entries: Array<[string, AttentionKind]>): Map<string, AttentionKi
afterEach(() => {
clearSessionAttentionMany([...getSessionAttentionKinds().keys()], { intent: 'explicit' });
setProjections([]);
+ chat.statuses = new Map();
});
describe('deriveOrcaLeadWorkerAttention', () => {
@@ -94,10 +124,12 @@ describe('deriveOrcaLeadWorkerAttention', () => {
['w3', 'awaiting'],
]),
);
- expect(result).toEqual(new Map([
- ['lead-a', 'error'],
- ['lead-b', 'awaiting'],
- ]));
+ expect(result).toEqual(
+ new Map([
+ ['lead-a', 'error'],
+ ['lead-b', 'awaiting'],
+ ]),
+ );
});
it('Worker 的完成不汇总;没有 Worker attention 时不出条目', () => {
@@ -156,7 +188,9 @@ describe('整表合并', () => {
expect(mergeOrcaLeadNotifications(notifications, new Map())).toBe(notifications);
// Lead 自身已是更高档:不新建 Map。
expect(
- mergeOrcaLeadAttentionKinds(kinds([['lead', 'error']]), new Map([['lead', 'awaiting']])).get('lead'),
+ mergeOrcaLeadAttentionKinds(kinds([['lead', 'error']]), new Map([['lead', 'awaiting']])).get(
+ 'lead',
+ ),
).toBe('error');
});
@@ -174,6 +208,86 @@ describe('整表合并', () => {
});
describe('模块级派生快照', () => {
+ it.each([
+ 'hasPendingAskUser',
+ 'hasPendingPermission',
+ 'hasPendingPlanReview',
+ 'hasPendingPluginSetup',
+ 'hasPendingInputHandoff',
+ ] as const)(
+ '%s 在任务 awaiting 被动清除后仍汇总,确认处理完才消失,且不写回任务提醒',
+ (field) => {
+ setProjections([['lead', snapshot('worker')]]);
+ const listener = vi.fn();
+ const unsubscribe = subscribeOrcaLeadWorkerAttention(listener);
+ try {
+ const dockCount = () => countAppAttention({
+ sessions: [{ id: 'lead', status: 'active' } as Session],
+ attentionKinds: getSessionAttentionKinds(), runningSessionIds: new Set(),
+ localActivities: new Map(), localSchedules: new Map(),
+ orcaLeadWorkerAttention: getOrcaLeadWorkerAttention(),
+ });
+ setPending('worker', { [field]: true });
+ expect(dockCount()).toBe(1);
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('awaiting');
+ expect(getSessionAttentionKindsWithOrcaLeads().get('lead')).toBe('awaiting');
+ addSessionAttention('worker', 'awaiting');
+ clearSessionAttentionMany(['worker']);
+ expect(getSessionAttentionKinds().has('worker')).toBe(false);
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('awaiting');
+ expect(listener).toHaveBeenCalledTimes(1);
+ expect(dockCount()).toBe(1);
+ addSessionAttention('worker', 'error');
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('error');
+ clearSessionAttentionMany(['worker'], { intent: 'explicit' });
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('awaiting');
+ setPending('worker', {});
+ expect(getOrcaLeadWorkerAttention().size).toBe(0);
+ expect(dockCount()).toBe(0);
+ expect(getSessionAttentionKinds().size).toBe(0);
+ } finally {
+ unsubscribe();
+ }
+ },
+ );
+
+ it('普通任务、运行设备与远程 Lead 的 pending 不汇总;大量输出不通知 Lead 消费方', () => {
+ const remote = snapshot('device-worker');
+ remote.workers[0].executionDevice = {
+ deviceId: 'host',
+ remoteSessionId: 'remote',
+ deviceName: 'Host',
+ reachable: true,
+ workingDir: null,
+ };
+ setProjections([
+ ['lead', snapshot('worker')],
+ ['device-lead', remote],
+ ['remote-lead', snapshot('remote-worker')],
+ ]);
+ const listener = vi.fn();
+ const unsubscribe = subscribeOrcaLeadWorkerAttention(listener);
+ try {
+ for (const id of ['ordinary', 'device-worker', 'remote-worker'])
+ setPending(id, { hasPendingAskUser: true });
+ expect(getOrcaLeadWorkerAttention().size).toBe(0);
+ expect(listener).not.toHaveBeenCalled();
+ setPending('worker', { hasPendingAskUser: true });
+ const before = getOrcaLeadWorkerAttention();
+ listener.mockClear();
+ for (let i = 0; i < 100; i++)
+ setPending('worker', { hasPendingAskUser: true, isRunning: i % 2 === 0 });
+ expect(listener).not.toHaveBeenCalled();
+ expect(getOrcaLeadWorkerAttention()).toBe(before);
+ // 普通任务仍由原 store 被动清除,本模块不替它保留提醒。
+ addSessionAttention('ordinary', 'awaiting');
+ clearSessionAttentionMany(['ordinary']);
+ expect(getSessionAttentionKindsWithOrcaLeads().has('ordinary')).toBe(false);
+ } finally {
+ unsubscribe();
+ }
+ });
+
it('跟随 Worker 自己的 attention 出现与消失,且不写回 attention store', () => {
setProjections([['lead', snapshot('worker')]]);
expect(getOrcaLeadWorkerAttention().size).toBe(0);
@@ -249,6 +363,8 @@ describe('Worker 通知', () => {
expect(formatOrcaWorkerNotificationTitle('Worker · developer', '重构登录')).toBe(
'重构登录 · Worker · developer',
);
- expect(formatOrcaWorkerNotificationTitle('Worker · developer', null)).toBe('Worker · developer');
+ expect(formatOrcaWorkerNotificationTitle('Worker · developer', null)).toBe(
+ 'Worker · developer',
+ );
});
});
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts b/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts
index 793907a10d..462c1521db 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts
@@ -1,12 +1,12 @@
/**
* Orca Lead 行汇总 Worker 的出错 / 等待确认(2026-10 用户裁决)。
*
- * Worker 不进普通侧栏,但它自己的 attention 已经记在 sessionAttentionStore(出错记
- * 'error',等待确认记 'awaiting'——当前打开的是 Lead,Worker 永远不算「正在看」)。
+ * Worker 不进普通侧栏;出错读取 sessionAttentionStore 的 error,等待确认读取
+ * awaiting 或未处理交互,避免看过 Worker 后丢失蓝点。
* 这里把它投到所属 Lead 行上,只做读侧派生:
* - 只汇总 error / awaiting;Worker 的 'done' 不汇总(完成由 Lead 被回报唤起的那一轮表达)。
* - 优先级:出错 > 等待确认 > Lead 自己的状态(与行内 error > awaiting > done 同一张表)。
- * - 生命周期完全跟随 Worker 自己的 attention,不新增清除逻辑;点开 Lead 不会消失。
+ * - 等待确认在未处理交互或任务 awaiting 任一存在时保持;不新增清除或通知逻辑。
*
* ⚠️ 汇总结果**不写回** sessionAttentionStore:那份会同步到 Main(Dock / 灵动岛 / 远端),
* 还会被「导航即已读」的被动清除抹掉,破坏 Lead 自己的 attention 生命周期与完成保持判定。
@@ -15,6 +15,12 @@
*/
import { useSyncExternalStore } from 'react';
+import { makerChatStore, type SessionStatusInfo } from '@/lib/makerChatStore';
+import {
+ localOrcaWorkerSessionIds,
+ resolveOrcaWorkerTaskAttention,
+ subscribeOrcaWorkerPendingInteractions,
+} from './orcaWorkerTaskAttention';
import { isRemoteSessionSticky } from '@/lib/makerTransport';
import {
@@ -38,13 +44,16 @@ const ATTENTION_RANK: Record<AttentionKind, number> = { done: 1, awaiting: 2, er
export function deriveOrcaLeadWorkerAttention(
leads: Iterable<LeadWorkerSessions>,
attentionKinds: ReadonlyMap<string, AttentionKind>,
+ statuses: ReadonlyMap<string, SessionStatusInfo> = new Map(),
): Map<string, OrcaLeadWorkerAttentionKind> {
const result = new Map<string, OrcaLeadWorkerAttentionKind>();
- if (attentionKinds.size === 0) return result;
for (const [leadSessionId, workerSessionIds] of leads) {
let kind: OrcaLeadWorkerAttentionKind | undefined;
for (const workerSessionId of workerSessionIds) {
- const workerKind = attentionKinds.get(workerSessionId);
+ const workerKind = resolveOrcaWorkerTaskAttention(
+ attentionKinds.get(workerSessionId),
+ statuses.get(workerSessionId),
+ );
if (workerKind === 'error') {
kind = 'error';
break;
@@ -108,18 +117,24 @@ function sameLeadAttention(
}
// —— 模块级派生快照 ——
-// useSyncExternalStore 要求内容不变时返回同一引用:按两个上游的快照引用 / 版本号缓存,
+// useSyncExternalStore 要求内容不变时返回同一引用:按上游快照引用 / 版本号缓存,
// 内容没变就复用旧 Map,逐行订阅与整表订阅都不会被无关广播惊动。
const EMPTY_LEAD_ATTENTION: ReadonlyMap<string, OrcaLeadWorkerAttentionKind> = new Map();
let cachedAttentionKinds: ReadonlyMap<string, AttentionKind> | null = null;
let cachedProjectionVersion = -1;
+let cachedStatuses: ReadonlyMap<string, SessionStatusInfo> | null = null;
let cachedLeadAttention: ReadonlyMap<string, OrcaLeadWorkerAttentionKind> = EMPTY_LEAD_ATTENTION;
let cachedMergedKinds: ReadonlyMap<string, AttentionKind> = new Map();
function refreshCache(): void {
const attentionKinds = getSessionAttentionKinds();
const projectionVersion = getAllWorkerProjectionVersion();
- if (attentionKinds === cachedAttentionKinds && projectionVersion === cachedProjectionVersion) {
+ const statuses = makerChatStore.getRunningSnapshot();
+ if (
+ attentionKinds === cachedAttentionKinds &&
+ projectionVersion === cachedProjectionVersion &&
+ statuses === cachedStatuses
+ ) {
return;
}
const leads: LeadWorkerSessions[] = [];
@@ -127,13 +142,14 @@ function refreshCache(): void {
// Worker(之前按本机查询只会得到空列表),且「已知远程」只增不减。
for (const [leadSessionId, snapshot] of listRetainedWorkerProjections()) {
if (snapshot.workers.length === 0 || isRemoteSessionSticky(leadSessionId)) continue;
- leads.push([leadSessionId, snapshot.workers.map((worker) => worker.sessionId)]);
+ leads.push([leadSessionId, localOrcaWorkerSessionIds(snapshot.workers, leadSessionId)]);
}
- const next = deriveOrcaLeadWorkerAttention(leads, attentionKinds);
+ const next = deriveOrcaLeadWorkerAttention(leads, attentionKinds, statuses);
const leadAttention = sameLeadAttention(next, cachedLeadAttention) ? cachedLeadAttention : next;
if (leadAttention !== cachedLeadAttention || attentionKinds !== cachedAttentionKinds) {
cachedMergedKinds = mergeOrcaLeadAttentionKinds(attentionKinds, leadAttention);
}
+ cachedStatuses = statuses;
cachedAttentionKinds = attentionKinds;
cachedProjectionVersion = projectionVersion;
cachedLeadAttention = leadAttention;
@@ -162,7 +178,15 @@ function subscribeDerived(listeners: Set<() => void>, listener: () => void): ()
refreshCache();
const unsubscribeAttention = subscribeSessionAttention(onUpstreamChange);
const unsubscribeProjections = subscribeAllWorkerProjections(onUpstreamChange);
+ const unsubscribePending = subscribeOrcaWorkerPendingInteractions(
+ () =>
+ listRetainedWorkerProjections().flatMap(([leadId, snapshot]) =>
+ localOrcaWorkerSessionIds(snapshot.workers, leadId),
+ ),
+ onUpstreamChange,
+ );
unsubscribeUpstream = () => {
+ unsubscribePending();
unsubscribeAttention();
unsubscribeProjections();
};
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/orcaWorkerTaskAttention.ts b/apps/desktop/src/renderer/features/cc-agent/lib/orcaWorkerTaskAttention.ts
new file mode 100644
index 0000000000..e60aa9e0dc
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/orcaWorkerTaskAttention.ts
@@ -0,0 +1,90 @@
+import { useCallback, useMemo, useSyncExternalStore } from 'react';
+
+import { makerChatStore, type SessionStatusInfo } from '@/lib/makerChatStore';
+import { isRemoteSessionSticky } from '@/lib/makerTransport';
+import {
+ getSessionAttentionKinds,
+ subscribeSessionAttention,
+ type AttentionKind,
+} from '@/lib/sessionAttentionStore';
+import type { WorkerInfo } from '../hooks/workerProjectionStore';
+
+/** 只派生 Orca 展示:不写回任务提醒,也不触发系统通知。 */
+export function resolveOrcaWorkerTaskAttention(
+ kind: AttentionKind | undefined,
+ status: SessionStatusInfo | undefined,
+): 'error' | 'awaiting' | undefined {
+ if (kind === 'error') return 'error';
+ return kind === 'awaiting' || hasPendingWorkerInteraction(status) ? 'awaiting' : undefined;
+}
+
+function hasPendingWorkerInteraction(status: SessionStatusInfo | undefined): boolean {
+ return Boolean(
+ status?.hasPendingAskUser ||
+ status?.hasPendingPermission ||
+ status?.hasPendingPlanReview ||
+ status?.hasPendingPluginSetup ||
+ status?.hasPendingInputHandoff,
+ );
+}
+
+export function localOrcaWorkerSessionIds(
+ workers: readonly Pick<WorkerInfo, 'sessionId' | 'executionDevice'>[],
+ leadSessionId?: string,
+): string[] {
+ if (leadSessionId && isRemoteSessionSticky(leadSessionId)) return [];
+ return workers
+ .filter((worker) => !worker.executionDevice && !isRemoteSessionSticky(worker.sessionId))
+ .map((worker) => worker.sessionId);
+}
+
+/** 流式消息会频繁广播;只在指定 Worker 的 pending 布尔值变化时通知消费方。 */
+export function subscribeOrcaWorkerPendingInteractions(
+ getSessionIds: () => readonly string[],
+ listener: () => void,
+): () => void {
+ const getKey = () => {
+ const statuses = makerChatStore.getRunningSnapshot();
+ return JSON.stringify(
+ getSessionIds().filter((id) => hasPendingWorkerInteraction(statuses.get(id))),
+ );
+ };
+ let previous = getKey();
+ return makerChatStore.subscribeAll(() => {
+ const next = getKey();
+ if (next === previous) return;
+ previous = next;
+ listener();
+ });
+}
+
+/** 同一组 Worker 只订阅一次,primitive 快照防止无关任务和输出内容使列表重渲染。 */
+export function useOrcaWorkerTaskAttentionKinds(
+ sessionIds: readonly string[],
+): ReadonlyMap<string, 'error' | 'awaiting'> {
+ const idsKey = JSON.stringify(sessionIds);
+ const ids = useMemo(() => JSON.parse(idsKey) as string[], [idsKey]);
+ const subscribe = useCallback(
+ (listener: () => void) => {
+ const offAttention = subscribeSessionAttention(listener);
+ const offPending = subscribeOrcaWorkerPendingInteractions(() => ids, listener);
+ return () => {
+ offAttention();
+ offPending();
+ };
+ },
+ [ids],
+ );
+ const getSnapshot = () => {
+ const attention = getSessionAttentionKinds();
+ const statuses = makerChatStore.getRunningSnapshot();
+ return JSON.stringify(
+ ids.flatMap((id) => {
+ const kind = resolveOrcaWorkerTaskAttention(attention.get(id), statuses.get(id));
+ return kind ? [[id, kind]] : [];
+ }),
+ );
+ };
+ const key = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
+ return useMemo(() => new Map(JSON.parse(key) as [string, 'error' | 'awaiting'][]), [key]);
+}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts
index ecc7266126..2b5605ce8c 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts
@@ -114,9 +114,16 @@ vi.mock('@/lib/toast', () => ({
toast: { success: vi.fn(), warning: vi.fn(), error: vi.fn() },
}));
-vi.mock('@/lib/makerChatStore', () => ({
- makerChatStore: { ensureInitialMessages: vi.fn() },
-}));
+vi.mock('@/lib/makerChatStore', () => {
+ const statuses = new Map();
+ return {
+ makerChatStore: {
+ ensureInitialMessages: vi.fn(),
+ getRunningSnapshot: () => statuses,
+ subscribeAll: () => () => {},
+ },
+ };
+});
// mock 之后再 import,确保 SessionItem 拿到的是探针版依赖。
import { SessionItem } from '../SessionItem';
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/OrcaWorkersAttentionIcon.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/OrcaWorkersAttentionIcon.tsx
index 7974948d45..92991e4ea7 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/OrcaWorkersAttentionIcon.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/OrcaWorkersAttentionIcon.tsx
@@ -1,18 +1,18 @@
-import { useMemo } from 'react';
import { UsersRound } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
import { useWorkerProjection } from '@/features/cc-agent/hooks/workerProjectionStore';
import { useWorkerAttentionSnapshot } from '@/features/cc-agent/lib/workerAttentionStore';
+import type { AttentionKind } from '@/lib/sessionAttentionStore';
import {
- useSessionsAttentionUrgentKind,
- type AttentionKind,
-} from '@/lib/sessionAttentionStore';
+ localOrcaWorkerSessionIds,
+ useOrcaWorkerTaskAttentionKinds,
+} from '@/features/cc-agent/lib/orcaWorkerTaskAttention';
/**
* 多个 Worker 时取最高一档:出错(红)> 等待确认(蓝)> 完成未读(绿)。
- * 出错 / 等待确认跟随 Worker 自己的 attention,tab 激活时同样显示(与侧栏 Lead 行同口径);
+ * 出错跟随任务 attention,等待确认同时读取 Worker 未处理交互,tab 激活时同样显示(与侧栏 Lead 行同口径);
* 完成未读沿用原语义,tab 激活即视为看到。
*/
export function resolveOrcaWorkersTabTone({
@@ -38,11 +38,14 @@ export function OrcaWorkersAttentionIcon({
const { t } = useTranslation();
const attention = useWorkerAttentionSnapshot();
const projection = useWorkerProjection(sessionId ?? '');
- const workerSessionIds = useMemo(
- () => (sessionId ? projection.workers.map((worker) => worker.sessionId) : []),
- [sessionId, projection.workers],
+ const taskAttention = useOrcaWorkerTaskAttentionKinds(
+ sessionId ? localOrcaWorkerSessionIds(projection.workers, sessionId) : [],
);
- const urgentKind = useSessionsAttentionUrgentKind(workerSessionIds);
+ const urgentKind = [...taskAttention.values()].includes('error')
+ ? 'error'
+ : taskAttention.size > 0
+ ? 'awaiting'
+ : undefined;
const hasDoneAttention = Boolean(
sessionId && projection.workers.some((worker) => attention.has(worker.workerId)),
);
diff --git a/docs/dev-rules/orca-team-architecture.md b/docs/dev-rules/orca-team-architecture.md
index 876d06fcdc..da507396ba 100644
--- a/docs/dev-rules/orca-team-architecture.md
+++ b/docs/dev-rules/orca-team-architecture.md
@@ -451,15 +451,20 @@ Worker turn 被 vendor 报终止型 error,但 interrupted-turn auto-resume 仍
创建 worker、`enableOrca` 创建首个 worker、任意真实 worker turn 开始后的 running、idle、archive、terminal done/error 都必须广播 `ORCA_WORKER_CHANGED`。worker DB `status` 跟随真实 turn 生命周期:Lead 派活或用户直接对话 worker 时,只有真实 turn 开始才置 `running`,**产品** terminal 才置 `done/error`(auto-resume 仍 pending/deferred 的 vendor 终态不是产品终态,见消息派发与 auto-bridge 5a);`switch_focus` / resume / restore 只能恢复可访问性,不能凭空置 `running`。实现指针:`orcaLifecycleService.ts` 的 `createWorker` / `enableTeam`、`orcaWorkerCreationService.ts` 的 `createWorkerInTeam`、`orcaTeamService.ts` 的 `dispatchWorkerTask` / `handleWorkerTurnStarted` / `handleWorkerTerminalTurn`、`register.ts` 的 status event adapter、`useWorkers.ts` 的 `useWorkers`。
5. **切换 session 不重置 worker 未读状态(状态:不变量)**
- worker done 的绿点由 renderer 进程级 edge-trigger attention store 维护,而不是跟随组件切换重置的局部 state。worker 状态跳变进 `done` 才标 attention;正在查看该 worker 时清除 attention;只切走 / 切回不应让同一轮 done 重新变未读。协同 tab 图标另外显示 Worker 的出错(红)与等待确认(蓝),取自 Worker 自己在 `sessionAttentionStore` 的 attention;多个 Worker 时按 红 > 蓝 > 绿(完成未读)取最高一档,红 / 蓝在 tab 激活时也显示,绿点仍是激活即视为看到。实现指针:`useOrcaWorkerAttentionWatcher.ts` 的 `computeWorkerAttentionUpdates`,`RolePillDropdown.tsx` 的 selected worker clear effect,`workerAttentionStore.ts` 的 `attentionWorkerIds`,`OrcaWorkersAttentionIcon.tsx` 的 `resolveOrcaWorkersTabTone`。
+ worker done 的绿点由 renderer 进程级 edge-trigger attention store 维护,而不是跟随组件切换重置的局部 state。worker 状态跳变进 `done` 才标 attention;正在查看该 worker 时清除 attention;只切走 / 切回不应让同一轮 done 重新变未读。协同 tab 图标另外显示 Worker 的出错(红)与等待确认(蓝),出错取自 Worker 自己在 `sessionAttentionStore` 的 attention,等待确认取自未处理交互或任务 awaiting;多个 Worker 时按 红 > 蓝 > 绿(完成未读)取最高一档,红 / 蓝在 tab 激活时也显示,绿点仍是激活即视为看到。实现指针:`useOrcaWorkerAttentionWatcher.ts` 的 `computeWorkerAttentionUpdates`,`RolePillDropdown.tsx` 的 selected worker clear effect,`workerAttentionStore.ts` 的 `attentionWorkerIds`,`OrcaWorkersAttentionIcon.tsx` 的 `resolveOrcaWorkersTabTone`。
Worker 列表(`RolePillDropdown.tsx` 的下拉行、平铺 tab、折叠入口)同样读取本机 Worker
自己的任务提醒:任务为 `error` 或运行状态为 `error` 时沿用红色描边与 ERR 徽章;没有错误时,
- `awaiting` 在头像右上显示蓝点,选中也保留;完成未读绿点仍只在未选中时显示。优先级为
+ Worker 有未处理交互(AskUserQuestion / 权限 / 计划审阅 / 插件设置 / 代输入)或任务为
+ `awaiting` 时,在头像右上显示蓝点,切到 Worker 再切走也保留,直到交互处理完且任务
+ awaiting 消失;完成未读绿点仍只在未选中时显示。优先级为
出错 > 等待确认 > 完成未读。折叠入口也提示被隐藏 Worker 的错误或等待确认,不汇总完成。
- 「运行设备」Worker 不读取本机任务提醒,保留运行状态为 `error` 的既有表达。判定统一为
- `resolveWorkerListAttention`,订阅使用 `useSessionsAttentionKindMap` 的本列表子映射,
- 不写回任何提醒状态,不改变 Worker 的运行状态。列表标题的「运行中」仅按
+ 「运行设备」Worker 不读取本机任务提醒,保留运行状态为 `error` 的既有表达。
+ `orcaWorkerTaskAttention.ts` 统一为列表、协同 tab、Lead 行及 Dock 派生任务提醒;列表
+ 另用 `resolveWorkerListAttention` 保留运行态 error。订阅只在相关 Worker 的 pending 布尔值
+ 变化时通知下游,primitive 快照避免流式输出或无关任务打穿渲染隔离。
+ 不写回任何提醒状态,不改变普通任务的被动清除、Worker 运行状态或系统通知发送规则,
+ 不改变 main / 灵动岛 / 手机端。列表标题的「运行中」仅按
`isRunningWorkerStatus` 计数;创建 Worker 的软、硬上限仍使用未归档的占槽数 `activeWorkerCount`。
6. **重启后对 known worker 懒登记(状态:不变量)**