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。

feat(desktop): Orca Worker 出错和等确认汇总到 Lead 行并单独通知

fmfsaisai21a5212bc6a5
diff --git a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx
index bf1ed258e6..104f398931 100644
--- a/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/AppBadgeAttentionSync.test.tsx
@@ -72,7 +72,11 @@ vi.mock('@/features/device-link/remoteSessionActivityStore', () => ({}));
vi.mock('@/lib/makerChatStore', () => ({
makerChatStore: { subscribeAll: () => () => {}, getRunningSnapshot: () => state.running },
}));
-vi.mock('@/lib/sessionAttentionStore', () => ({ useSessionAttentionKinds: () => state.attention }));
+vi.mock('@/lib/sessionAttentionStore', () => ({
+ useSessionAttentionKinds: () => state.attention,
+ getSessionAttentionKinds: () => state.attention,
+ subscribeSessionAttention: () => () => undefined,
+}));
vi.mock('@/state/agentIslandActivity', () => ({ useAgentIslandActivityMap: () => state.empty }));
vi.mock('@/lib/orcaSessionIdentity', () => ({ isOrcaWorkerSession: () => false }));
diff --git a/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts b/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts
index 0bcae13849..996d323aee 100644
--- a/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts
+++ b/apps/desktop/src/renderer/__tests__/appAttentionCount.test.ts
@@ -202,4 +202,36 @@ describe('app attention total', () => {
),
).toBe(0);
});
+
+ it('counts an Orca Lead once for its workers\' error / awaiting, matching the Lead row', () => {
+ const sessions = [
+ session('lead', { orcaRole: 'lead' }),
+ session('w1', { orcaRole: 'worker' }),
+ session('w2', { orcaRole: 'worker' }),
+ ];
+ const attentionKinds = new Map<string, 'done' | 'awaiting' | 'error'>([
+ ['w1', 'error'],
+ ['w2', 'awaiting'],
+ ]);
+ // 汇总表由 orcaLeadWorkerAttention 派生;两个 Worker 出问题,Lead 仍只算 1。
+ expect(
+ countAppAttention(input({
+ sessions,
+ attentionKinds,
+ orcaLeadWorkerAttention: new Map([['lead', 'error']]),
+ })),
+ ).toBe(1);
+ // Lead 运行中 + Worker 等待确认:等待确认盖过运行中,计入角标。
+ expect(
+ countAppAttention(input({
+ sessions,
+ attentionKinds,
+ runningSessionIds: new Set(['lead']),
+ localActivities: new Map([['lead', { phase: 'running', currentTurnActive: true }]]),
+ orcaLeadWorkerAttention: new Map([['lead', 'awaiting']]),
+ })),
+ ).toBe(1);
+ // 没有汇总时 Worker 自身不计入。
+ expect(countAppAttention(input({ sessions, attentionKinds }))).toBe(0);
+ });
});
diff --git a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx
index 5ff4144c3c..a26a037b4f 100644
--- a/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx
+++ b/apps/desktop/src/renderer/components/layout/AppBadgeAttentionSync.tsx
@@ -12,6 +12,7 @@ import { countAppAttention } from '@/features/cc-agent/lib/appAttentionCount';
import { getDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';
import { useAuth } from '@/contexts/AuthContext';
import { useSessionDisplayRunningState } from '@/features/cc-agent/hooks/useSessionDisplayRunningState';
+import { useOrcaLeadWorkerAttention } from '@/features/cc-agent/lib/orcaLeadWorkerAttention';
import { useBotProfiles, useBotUnreadCounts } from '@/features/bots/botStore';
import { useBotGroupList } from '@/features/bots/botGroupStore';
@@ -52,6 +53,8 @@ export function AppBadgeAttentionSync() {
);
const localSchedules = usePublishedAutomationScheduleSessionIndex();
const attentionKinds = useSessionAttentionKinds();
+ // Worker 的投影由下面的 useSessionDisplayRunningState 持有(本机全部活跃 Lead)。
+ const orcaLeadWorkerAttention = useOrcaLeadWorkerAttention();
const localActivities = useAgentIslandActivityMap();
const running = useSyncExternalStore(
makerChatStore.subscribeAll,
@@ -72,6 +75,7 @@ export function AppBadgeAttentionSync() {
attentionKinds,
localActivities,
runningSessionIds: displayRunningSessionIds,
+ orcaLeadWorkerAttention,
});
useEffect(() => {
publishNavigationAttention({ tasks: count, teammates });
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index ec374ce56e..77273a7e5a 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -115,9 +115,16 @@ import type { Session } from '@/lib/ccAgent.types';
import {
clearSessionAttentionMany,
clearSystemSessionAttention,
- useSessionAttentionKinds,
useSessionAttentionSnapshot,
} from '@/lib/sessionAttentionStore';
+import {
+ findOrcaLeadSessionIdForWorker,
+ formatOrcaWorkerNotificationTitle,
+ mergeOrcaLeadNotifications,
+ shouldNotifyOrcaWorkerEvent,
+ useOrcaLeadWorkerAttention,
+ useSessionAttentionKindsWithOrcaLeads,
+} from './lib/orcaLeadWorkerAttention';
import { patchDraft as patchNewMakerDraft } from '@/state/newMakerDraft';
import { consumePendingProjectFocus, usePendingProjectFocus } from '@/state/pendingProjectFocus';
import {
@@ -518,7 +525,13 @@ export function CCAgentSidebarUpper() {
).map((session) => session.id),
[searchProjectSessions, hiddenProjectKeys, localPlatform],
);
- const attentionNotifications = useSessionAttentionSnapshot();
+ const rawAttentionNotifications = useSessionAttentionSnapshot();
+ // Orca Lead 汇总其 Worker 的出错 / 等待确认(只读派生,不写回 attention store)。
+ const orcaLeadWorkerAttention = useOrcaLeadWorkerAttention();
+ const attentionNotifications = useMemo(
+ () => mergeOrcaLeadNotifications(rawAttentionNotifications, orcaLeadWorkerAttention),
+ [rawAttentionNotifications, orcaLeadWorkerAttention],
+ );
// Sidebar is rendered outside the :sessionId route, so useParams won't work.
// Use useMatch to extract the active session id from the URL.
const match = useMatch('/cc-agent/:sessionId');
@@ -1180,10 +1193,25 @@ function ExpandedView({
remoteSessionsForNotificationRef.current,
]);
if (!CINDY_MAKE_ENABLED && session && isCindyMakeSource(session.source)) return;
- // Orca worker 自身状态翻转不发独立通知 —— 等 lead 接到 worker_report 处理完
- // 再以 lead 名义统一推一条,避免同一事件双重打扰。语义上用户应回到 lead 主对话
- // 查看,而非跳到 worker 实现细节;与 effectiveRunningSessionIds 的角色聚合口径一致。
- if (session && isOrcaWorkerSession(session)) return;
+ // Orca Worker 的完成不发独立通知 —— 等 Lead 接到 worker_report 处理完再以 Lead
+ // 名义统一推一条。出错与需要确认要用户本人处理,单独通知,标题带上所属 Lead;
+ // 点击按 Worker id 走 resolveSessionRoute,落到 Lead 并打开该 Worker。
+ if (session && isOrcaWorkerSession(session)) {
+ if (!shouldNotifyOrcaWorkerEvent(kind, session)) return;
+ const leadSessionId = findOrcaLeadSessionIdForWorker(sessionId);
+ const leadSession = leadSessionId
+ ? findSessionNotificationSession(leadSessionId, [
+ sessionsRef.current,
+ allSessionsForNotificationRef.current,
+ ])
+ : null;
+ const title = formatOrcaWorkerNotificationTitle(
+ projectDraftSessionTitle(session.title, unnamedLabelRef.current),
+ leadSession ? projectDraftSessionTitle(leadSession.title, unnamedLabelRef.current) : null,
+ );
+ sendSessionEventNotification(sessionId, title, kind);
+ return;
+ }
// /review 审查任务不单独通知:结果回到来源任务,由来源任务的轮次收尾通知。
if (session && isReviewSessionSource(session.source)) return;
// 插件后台隐藏任务不单独通知;显示到任务列表后恢复。
@@ -1236,7 +1264,9 @@ function ExpandedView({
},
);
const remoteScheduleIndex = useRemoteScheduleIndex();
- const attentionKinds = useSessionAttentionKinds();
+ // Lead 的 kind / 未读已并入其 Worker 的出错 / 等待确认(lib/orcaLeadWorkerAttention.ts)。
+ const attentionKinds = useSessionAttentionKindsWithOrcaLeads();
+ const orcaLeadWorkerAttention = useOrcaLeadWorkerAttention();
const urgentSet = useSessionAttentionUrgencySet();
const unreadScheduleSessionIds = useMemo(() => {
const next = new Set<string>();
@@ -1255,9 +1285,10 @@ function ExpandedView({
[scheduleSessionIndex, remoteScheduleIndex],
);
const sidebarNotifications = useMemo(() => {
- if (unreadScheduleSessionIds.size === 0) return notifications;
- return new Set([...notifications, ...unreadScheduleSessionIds]);
- }, [notifications, unreadScheduleSessionIds]);
+ const withOrcaLeads = mergeOrcaLeadNotifications(notifications, orcaLeadWorkerAttention);
+ if (unreadScheduleSessionIds.size === 0) return withOrcaLeads;
+ return new Set([...withOrcaLeads, ...unreadScheduleSessionIds]);
+ }, [notifications, orcaLeadWorkerAttention, unreadScheduleSessionIds]);
const remoteActivityRevision = useRemoteSessionActivityRevision();
const markAutomationSessionRunsRead = useCallback(
@@ -4103,8 +4134,8 @@ function CollapsedView({
const { runningSessionIds } = useSessionRunningStatus(attentionSessionId);
// 瓷砖未读点颜色按 attention kind(done 绿 / awaiting TapTap 蓝 / error 红);组件层
// 取一次,renderItem 里查表(renderItem 非组件,不能 per-item 用 hook)。
-
- const attentionKinds = useSessionAttentionKinds();
+ // Lead 的 kind 已并入其 Worker 的出错 / 等待确认(notifications 由上层同口径合并)。
+ const attentionKinds = useSessionAttentionKindsWithOrcaLeads();
// 失败 automation urgency 集合 —— rail 瓷砖也要按此把 failed schedule 涂红,不能
// 让"失败的定时任务"落到默认绿色 done tone(否则和 SessionItem 不一致,
// 折叠视图会把失败误传成"完成了")。
@@ -4369,7 +4400,8 @@ function RailPanels({
// (只是 return null),下次打开面板旧菜单会按旧坐标复现并引用旧项目(review)。
// 与下方 showAllProjects 的复位同构。
- const attentionKinds = useSessionAttentionKinds();
+ // Lead 的 kind 已并入其 Worker 的出错 / 等待确认(notifications 由 ExpandedView 同口径合并)。
+ const attentionKinds = useSessionAttentionKindsWithOrcaLeads();
const urgentSet = useSessionAttentionUrgencySet();
// 项目列表「显示全部」:面板关闭后复位(与 ProjectsSection 的段收起复位同语义)。
const [showAllProjects, setShowAllProjects] = useState(false);
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts b/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
index 089b8b81de..19e13e7f95 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
@@ -7,6 +7,10 @@ import { projectDraftSessionTitle } from '@cindy/maker-shared/session-title';
import { isOrcaWorkerSession } from '@/lib/orcaSessionIdentity';
import { BOT_GROUP_LANE_SESSION, findSessionNotificationSession, isBackgroundTaskNotificationTarget } from '@/lib/sessionEventNotification';
import { isReviewSessionSource } from '../../../../shared/sessionSource';
+import {
+ formatOrcaWorkerNotificationTitle,
+ shouldNotifyOrcaWorkerEvent,
+} from '../lib/orcaLeadWorkerAttention';
const source = ts.createSourceFile('sidebar.tsx', readFileSync(resolve(
process.cwd(), 'src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx',
@@ -45,10 +49,12 @@ type NotificationSession = {
status?: 'active' | 'archived';
deviceLinkDeviceId?: string;
hiddenAt?: string | null;
+ orcaRole?: 'lead' | 'worker';
};
const send = vi.fn();
const reviewTarget = vi.fn(async () => false);
const botTitle = vi.fn(async (): Promise<string | null> => null);
+const leadOfWorker = vi.fn<(workerSessionId: string) => string | null>(() => null);
beforeEach(() => { vi.clearAllMocks(); });
function dispatcher(local: NotificationSession[], remote: NotificationSession[] = []) {
@@ -71,6 +77,9 @@ function dispatcher(local: NotificationSession[], remote: NotificationSession[]
isBackgroundTaskNotificationTarget,
botOwnedSessionNotificationTitle: botTitle,
BOT_GROUP_LANE_SESSION,
+ shouldNotifyOrcaWorkerEvent,
+ formatOrcaWorkerNotificationTitle,
+ findOrcaLeadSessionIdForWorker: leadOfWorker,
t: () => 'Unnamed task',
};
return new Function(...Object.keys(bindings), emitted)(...Object.values(bindings)) as (
@@ -147,3 +156,35 @@ describe('disabled Make notification dispatch', () => {
expect(props.get('remoteSessionsForNotification')).toBe('remoteProjectSessionsRaw');
});
});
+
+describe('Orca Worker notification dispatch', () => {
+ const lead: NotificationSession = { id: 'lead', title: '重构登录', source: 'desktop', orcaRole: 'lead' };
+ const worker: NotificationSession = {
+ id: 'worker', title: 'Worker · developer', source: 'desktop', orcaRole: 'worker',
+ };
+
+ it('Worker 的完成仍不单独通知', () => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([lead, worker])('worker', 'done');
+ expect(send).not.toHaveBeenCalled();
+ });
+
+ it.each(['error', 'needs-reply'] as const)('Worker 的 %s 以「Lead 标题 · Worker 标题」单独通知', (kind) => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([lead, worker])('worker', kind);
+ expect(leadOfWorker).toHaveBeenCalledWith('worker');
+ expect(send).toHaveBeenCalledWith('worker', '重构登录 · Worker · developer', kind);
+ });
+
+ it('找不到 Lead 时退回 Worker 标题', () => {
+ leadOfWorker.mockReturnValue(null);
+ dispatcher([worker])('worker', 'error');
+ expect(send).toHaveBeenCalledWith('worker', 'Worker · developer', 'error');
+ });
+
+ it('远程控制另一台电脑的 Worker 不在范围内', () => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([], [{ ...worker, deviceLinkDeviceId: 'host' }])('worker', 'error');
+ expect(send).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useWorkers.test.tsx b/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useWorkers.test.tsx
index c4356dc77b..9802f62b66 100644
--- a/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useWorkers.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useWorkers.test.tsx
@@ -34,6 +34,8 @@ import { clearWorkersCache, useWorkers } from '../useWorkers';
import {
__getWorkerProjectionOwnerCountForTest,
__setWorkerProjectionCoalesceMsForTest,
+ getAllWorkerProjectionVersion,
+ listRetainedWorkerProjections,
retainWorkerProjection,
revalidateActiveWorkerSettings,
revalidateActiveWorkersProjection,
@@ -174,6 +176,21 @@ describe('useWorkers / worker projection store', () => {
expect(mocks.listWorkersByLead).not.toHaveBeenCalled();
});
+ it('lists only retained lead projections and broadcasts when the last owner releases', async () => {
+ const release = retainWorkerProjection('lead-retained');
+ await waitFor(() => {
+ expect(listRetainedWorkerProjections().map(([leadSessionId, snapshot]) => [
+ leadSessionId,
+ snapshot.workers.map((worker) => worker.sessionId),
+ ])).toEqual([['lead-retained', ['session-lead-retained']]]);
+ });
+ const versionBeforeRelease = getAllWorkerProjectionVersion();
+ act(() => release());
+ // 快照仍留在 store,但无人持有后不再作为派生依据,且整表视图要被通知收敛。
+ expect(listRetainedWorkerProjections()).toEqual([]);
+ expect(getAllWorkerProjectionVersion()).toBeGreaterThan(versionBeforeRelease);
+ });
+
it('keeps projection owners when the lead collection is only reordered', async () => {
vi.useFakeTimers();
const hook = renderHook(({ sessions }) => useOrcaLeadWorkerMap(sessions), {
diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/workerProjectionStore.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/workerProjectionStore.ts
index 7eefbe4e1b..f64304a2a2 100644
--- a/apps/desktop/src/renderer/features/cc-agent/hooks/workerProjectionStore.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/workerProjectionStore.ts
@@ -548,6 +548,8 @@ export function retainWorkerProjection(leadSessionId: string | undefined): () =>
entry.queuedRefresh.resolve(failedWorkersResult(leadSessionId, entry));
entry.queuedRefresh = null;
}
+ // 无人持有后快照不再刷新;按持有范围派生的整表视图(listRetainedWorkerProjections)要随之收敛。
+ emitGlobal();
};
}
@@ -623,6 +625,19 @@ export function getAllWorkerProjectionVersion(): number {
return globalVersion;
}
+/**
+ * 当前有人持有的 Lead 投影。无人持有的条目不再订阅 Worker 变化(如协同已结束、Lead 已
+ * 不在任何列表里),快照可能过期,不能作为跨 Lead 派生的依据。变化随
+ * subscribeAllWorkerProjections / getAllWorkerProjectionVersion 广播。
+ */
+export function listRetainedWorkerProjections(): Array<readonly [string, WorkersSnapshot]> {
+ const result: Array<readonly [string, WorkersSnapshot]> = [];
+ for (const [leadSessionId, entry] of entries) {
+ if (entry.ownerCount > 0) result.push([leadSessionId, entry.snapshot]);
+ }
+ return result;
+}
+
export function useWorkerProjectionVersion(): number {
return useSyncExternalStore(
subscribeAllWorkerProjections,
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
new file mode 100644
index 0000000000..8d91816525
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/__tests__/orcaLeadWorkerAttention.test.ts
@@ -0,0 +1,254 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import type { WorkersSnapshot } from '../../hooks/workerProjectionStore';
+
+const projection = vi.hoisted(() => ({
+ version: 0,
+ retained: [] as Array<readonly [string, WorkersSnapshot]>,
+ listeners: new Set<() => void>(),
+}));
+
+vi.mock('@/lib/makerTransport', () => ({
+ isRemoteSessionSticky: (sessionId: string) => sessionId === 'remote-lead',
+}));
+
+vi.mock('../../hooks/workerProjectionStore', () => ({
+ getAllWorkerProjectionVersion: () => projection.version,
+ listRetainedWorkerProjections: () => projection.retained,
+ subscribeAllWorkerProjections: (listener: () => void) => {
+ projection.listeners.add(listener);
+ return () => projection.listeners.delete(listener);
+ },
+}));
+
+import {
+ addSessionAttention,
+ clearSessionAttentionMany,
+ getSessionAttentionKinds,
+ type AttentionKind,
+} from '@/lib/sessionAttentionStore';
+import {
+ projectSidebarSessionActivity,
+ resolveSidebarRightStatus,
+} from '../../sidebar/sidebarRightStatus';
+import {
+ deriveOrcaLeadWorkerAttention,
+ findOrcaLeadSessionIdForWorker,
+ formatOrcaWorkerNotificationTitle,
+ getOrcaLeadWorkerAttention,
+ getSessionAttentionKindsWithOrcaLeads,
+ mergeOrcaLeadAttentionKind,
+ subscribeOrcaLeadWorkerAttention,
+ mergeOrcaLeadAttentionKinds,
+ mergeOrcaLeadNotifications,
+ shouldNotifyOrcaWorkerEvent,
+} from '../orcaLeadWorkerAttention';
+
+function snapshot(...workerSessionIds: string[]): WorkersSnapshot {
+ return {
+ workers: workerSessionIds.map((sessionId) => ({
+ workerId: `id-${sessionId}`,
+ sessionId,
+ role: 'developer',
+ agent: 'claude-code',
+ model: 'm',
+ effort: null,
+ label: null,
+ status: 'running',
+ focused: false,
+ idleSince: null,
+ })),
+ softLimit: 5,
+ hardLimit: 8,
+ workerStatus: 'applied',
+ requestId: 1,
+ updatedAt: 0,
+ };
+}
+
+function setProjections(entries: Array<readonly [string, WorkersSnapshot]>): void {
+ projection.retained = entries;
+ projection.version += 1;
+ for (const listener of projection.listeners) listener();
+}
+
+function kinds(entries: Array<[string, AttentionKind]>): Map<string, AttentionKind> {
+ return new Map(entries);
+}
+
+afterEach(() => {
+ clearSessionAttentionMany([...getSessionAttentionKinds().keys()], { intent: 'explicit' });
+ setProjections([]);
+});
+
+describe('deriveOrcaLeadWorkerAttention', () => {
+ it('汇总 Worker 的出错 / 等待确认,出错优先', () => {
+ const result = deriveOrcaLeadWorkerAttention(
+ [
+ ['lead-a', ['w1', 'w2']],
+ ['lead-b', ['w3']],
+ ],
+ kinds([
+ ['w1', 'awaiting'],
+ ['w2', 'error'],
+ ['w3', 'awaiting'],
+ ]),
+ );
+ expect(result).toEqual(new Map([
+ ['lead-a', 'error'],
+ ['lead-b', 'awaiting'],
+ ]));
+ });
+
+ it('Worker 的完成不汇总;没有 Worker attention 时不出条目', () => {
+ expect(
+ deriveOrcaLeadWorkerAttention([['lead', ['w1', 'w2']]], kinds([['w1', 'done']])).size,
+ ).toBe(0);
+ expect(deriveOrcaLeadWorkerAttention([['lead', []]], kinds([['lead', 'error']])).size).toBe(0);
+ });
+});
+
+describe('mergeOrcaLeadAttentionKind', () => {
+ it('出错 > 等待确认 > Lead 自身', () => {
+ expect(mergeOrcaLeadAttentionKind(undefined, 'awaiting')).toBe('awaiting');
+ expect(mergeOrcaLeadAttentionKind('done', 'awaiting')).toBe('awaiting');
+ expect(mergeOrcaLeadAttentionKind('done', 'error')).toBe('error');
+ expect(mergeOrcaLeadAttentionKind('awaiting', 'error')).toBe('error');
+ expect(mergeOrcaLeadAttentionKind('error', 'awaiting')).toBe('error');
+ expect(mergeOrcaLeadAttentionKind('done', undefined)).toBe('done');
+ expect(mergeOrcaLeadAttentionKind(undefined, undefined)).toBeUndefined();
+ });
+
+ it('Lead 运行中 + Worker 等待确认:侧栏 Lead 行显示蓝点而不是转圈', () => {
+ const workerKind = deriveOrcaLeadWorkerAttention(
+ [['lead', ['worker']]],
+ kinds([['worker', 'awaiting']]),
+ ).get('lead');
+ const activity = projectSidebarSessionActivity({
+ sessionId: 'lead',
+ liveActivity: { phase: 'running', currentTurnActive: true },
+ attentionKind: mergeOrcaLeadAttentionKind(undefined, workerKind),
+ isUrgentFromContext: false,
+ isRunning: true,
+ hasAttentionNotification: workerKind !== undefined,
+ });
+ expect(resolveSidebarRightStatus(activity)).toBe('awaiting');
+ });
+
+ it('Lead 运行中 + Worker 出错:红点盖过运行中', () => {
+ const activity = projectSidebarSessionActivity({
+ sessionId: 'lead',
+ liveActivity: { phase: 'running', currentTurnActive: true },
+ attentionKind: mergeOrcaLeadAttentionKind(undefined, 'error'),
+ isUrgentFromContext: false,
+ isRunning: true,
+ hasAttentionNotification: true,
+ });
+ expect(resolveSidebarRightStatus(activity)).toBe('error');
+ });
+});
+
+describe('整表合并', () => {
+ it('没有 Worker 汇总时原样返回入参引用', () => {
+ const attention = kinds([['a', 'done']]);
+ const notifications = new Set(['a']);
+ expect(mergeOrcaLeadAttentionKinds(attention, new Map())).toBe(attention);
+ expect(mergeOrcaLeadNotifications(notifications, new Map())).toBe(notifications);
+ // Lead 自身已是更高档:不新建 Map。
+ expect(
+ mergeOrcaLeadAttentionKinds(kinds([['lead', 'error']]), new Map([['lead', 'awaiting']])).get('lead'),
+ ).toBe('error');
+ });
+
+ it('并入 Lead 的 kind 与未读,不改动入参', () => {
+ const attention = kinds([['lead', 'done']]);
+ const merged = mergeOrcaLeadAttentionKinds(attention, new Map([['lead', 'awaiting']]));
+ expect(merged.get('lead')).toBe('awaiting');
+ expect(attention.get('lead')).toBe('done');
+ const notifications = new Set<string>();
+ expect([...mergeOrcaLeadNotifications(notifications, new Map([['lead', 'error']]))]).toEqual([
+ 'lead',
+ ]);
+ expect(notifications.size).toBe(0);
+ });
+});
+
+describe('模块级派生快照', () => {
+ it('跟随 Worker 自己的 attention 出现与消失,且不写回 attention store', () => {
+ setProjections([['lead', snapshot('worker')]]);
+ expect(getOrcaLeadWorkerAttention().size).toBe(0);
+
+ addSessionAttention('worker', 'awaiting');
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('awaiting');
+ expect(getSessionAttentionKindsWithOrcaLeads().get('lead')).toBe('awaiting');
+ expect(getSessionAttentionKinds().has('lead')).toBe(false);
+
+ addSessionAttention('worker', 'error');
+ expect(getOrcaLeadWorkerAttention().get('lead')).toBe('error');
+
+ clearSessionAttentionMany(['worker'], { intent: 'explicit' });
+ expect(getOrcaLeadWorkerAttention().has('lead')).toBe(false);
+ });
+
+ it('内容不变时复用同一引用;无汇总时合并表就是原表', () => {
+ setProjections([['lead', snapshot('worker')]]);
+ addSessionAttention('worker', 'error');
+ const first = getOrcaLeadWorkerAttention();
+ // 无关会话变化:attention 表换了引用,但 Lead 汇总内容不变。
+ addSessionAttention('other', 'done');
+ expect(getOrcaLeadWorkerAttention()).toBe(first);
+
+ clearSessionAttentionMany(['worker'], { intent: 'explicit' });
+ expect(getSessionAttentionKindsWithOrcaLeads()).toBe(getSessionAttentionKinds());
+ });
+
+ it('Worker 离开投影(归档 / 协同结束)后不再汇总;远程 Lead 不在范围内', () => {
+ addSessionAttention('worker', 'error');
+ addSessionAttention('remote-worker', 'error');
+ setProjections([
+ ['lead', snapshot('worker')],
+ ['remote-lead', snapshot('remote-worker')],
+ ]);
+ expect([...getOrcaLeadWorkerAttention().keys()]).toEqual(['lead']);
+
+ setProjections([['lead', snapshot()]]);
+ expect(getOrcaLeadWorkerAttention().size).toBe(0);
+ });
+
+ it('逐行订阅只在 Lead 汇总内容变化时被唤醒', () => {
+ setProjections([['lead', snapshot('worker')]]);
+ const listener = vi.fn();
+ const unsubscribe = subscribeOrcaLeadWorkerAttention(listener);
+ addSessionAttention('other', 'error');
+ setProjections([['lead', snapshot('worker', 'worker-2')]]);
+ expect(listener).not.toHaveBeenCalled();
+
+ addSessionAttention('worker', 'awaiting');
+ expect(listener).toHaveBeenCalledTimes(1);
+ addSessionAttention('worker-2', 'awaiting');
+ expect(listener).toHaveBeenCalledTimes(1);
+ unsubscribe();
+ });
+
+ it('按投影反查 Worker 所属 Lead', () => {
+ setProjections([['lead', snapshot('w1', 'w2')]]);
+ expect(findOrcaLeadSessionIdForWorker('w2')).toBe('lead');
+ expect(findOrcaLeadSessionIdForWorker('unknown')).toBeNull();
+ });
+});
+
+describe('Worker 通知', () => {
+ it('只放行本机 Worker 的出错与需要确认,完成不单独通知', () => {
+ expect(shouldNotifyOrcaWorkerEvent('done', {})).toBe(false);
+ expect(shouldNotifyOrcaWorkerEvent('error', {})).toBe(true);
+ expect(shouldNotifyOrcaWorkerEvent('needs-reply', {})).toBe(true);
+ expect(shouldNotifyOrcaWorkerEvent('error', { deviceLinkDeviceId: 'host' })).toBe(false);
+ });
+
+ it('标题为「Lead 标题 · Worker 标题」,找不到 Lead 时退回 Worker 标题', () => {
+ expect(formatOrcaWorkerNotificationTitle('Worker · developer', '重构登录')).toBe(
+ '重构登录 · Worker · developer',
+ );
+ expect(formatOrcaWorkerNotificationTitle('Worker · developer', null)).toBe('Worker · developer');
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts b/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts
index 1b59b32991..19acb175e8 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/appAttentionCount.ts
@@ -8,6 +8,10 @@ import {
type SidebarRightStatusInput,
} from '../sidebar/sidebarRightStatus';
import { isAutomationGeneratedSession } from './scheduledSessionGrouping';
+import {
+ mergeOrcaLeadAttentionKind,
+ type OrcaLeadWorkerAttentionKind,
+} from './orcaLeadWorkerAttention';
type ScheduleAttention = { hasUnreadRun: boolean; hasUnreadFailedRun: boolean };
@@ -17,6 +21,8 @@ export interface AppAttentionCountInput {
runningSessionIds: ReadonlySet<string>;
localActivities: ReadonlyMap<string, SidebarRightStatusInput['liveActivity']>;
localSchedules: ReadonlyMap<string, ScheduleAttention>;
+ /** Orca Lead → 其 Worker 汇总的出错 / 等待确认;与侧栏 Lead 行同口径,一个 Lead 只算 1。 */
+ orcaLeadWorkerAttention?: ReadonlyMap<string, OrcaLeadWorkerAttentionKind>;
}
/** 与任务行的红/蓝/绿点同源,不随搜索、折叠或当前机器筛选改变。 */
@@ -33,16 +39,21 @@ export function countAppAttention(input: AppAttentionCountInput): number {
session.source === 'learn'
)
continue;
+ const orcaWorkerAttentionKind = input.orcaLeadWorkerAttention?.get(session.id);
const activity = projectSidebarSessionActivity({
interruption: session,
sessionId: session.id,
title: session.title,
recordStatus: session.status,
liveActivity: input.localActivities.get(session.id),
- attentionKind: input.attentionKinds.get(session.id),
+ attentionKind: mergeOrcaLeadAttentionKind(
+ input.attentionKinds.get(session.id),
+ orcaWorkerAttentionKind,
+ ),
isUrgentFromContext: false,
isRunning: input.runningSessionIds.has(session.id),
- hasAttentionNotification: input.attentionKinds.has(session.id),
+ hasAttentionNotification:
+ input.attentionKinds.has(session.id) || orcaWorkerAttentionKind !== undefined,
});
const status = resolveSidebarRightStatus(activity);
// heartbeat 绑普通任务时 runner 保留 desktop 来源,完成会写入 done;
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts b/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts
new file mode 100644
index 0000000000..793907a10d
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts
@@ -0,0 +1,261 @@
+/**
+ * Orca Lead 行汇总 Worker 的出错 / 等待确认(2026-10 用户裁决)。
+ *
+ * Worker 不进普通侧栏,但它自己的 attention 已经记在 sessionAttentionStore(出错记
+ * 'error',等待确认记 'awaiting'——当前打开的是 Lead,Worker 永远不算「正在看」)。
+ * 这里把它投到所属 Lead 行上,只做读侧派生:
+ * - 只汇总 error / awaiting;Worker 的 'done' 不汇总(完成由 Lead 被回报唤起的那一轮表达)。
+ * - 优先级:出错 > 等待确认 > Lead 自己的状态(与行内 error > awaiting > done 同一张表)。
+ * - 生命周期完全跟随 Worker 自己的 attention,不新增清除逻辑;点开 Lead 不会消失。
+ *
+ * ⚠️ 汇总结果**不写回** sessionAttentionStore:那份会同步到 Main(Dock / 灵动岛 / 远端),
+ * 还会被「导航即已读」的被动清除抹掉,破坏 Lead 自己的 attention 生命周期与完成保持判定。
+ *
+ * 只覆盖本机 Lead:远程控制另一台电脑的 Lead 不在范围内,投影里的远程 Lead 直接跳过。
+ */
+
+import { useSyncExternalStore } from 'react';
+
+import { isRemoteSessionSticky } from '@/lib/makerTransport';
+import {
+ getSessionAttentionKinds,
+ subscribeSessionAttention,
+ type AttentionKind,
+} from '@/lib/sessionAttentionStore';
+import {
+ getAllWorkerProjectionVersion,
+ listRetainedWorkerProjections,
+ subscribeAllWorkerProjections,
+} from '../hooks/workerProjectionStore';
+
+export type OrcaLeadWorkerAttentionKind = 'error' | 'awaiting';
+
+type LeadWorkerSessions = readonly [leadSessionId: string, workerSessionIds: readonly string[]];
+
+const ATTENTION_RANK: Record<AttentionKind, number> = { done: 1, awaiting: 2, error: 3 };
+
+/** 按 Lead 汇总其 Worker 的 error / awaiting;Worker 的 done 不汇总。 */
+export function deriveOrcaLeadWorkerAttention(
+ leads: Iterable<LeadWorkerSessions>,
+ attentionKinds: ReadonlyMap<string, AttentionKind>,
+): 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);
+ if (workerKind === 'error') {
+ kind = 'error';
+ break;
+ }
+ if (workerKind === 'awaiting') kind = 'awaiting';
+ }
+ if (kind) result.set(leadSessionId, kind);
+ }
+ return result;
+}
+
+/** Lead 自身 kind 与 Worker 汇总取严重度更高的一档(error > awaiting > done)。 */
+export function mergeOrcaLeadAttentionKind(
+ own: AttentionKind | undefined,
+ worker: OrcaLeadWorkerAttentionKind | undefined,
+): AttentionKind | undefined {
+ if (!worker) return own;
+ if (!own) return worker;
+ return ATTENTION_RANK[worker] > ATTENTION_RANK[own] ? worker : own;
+}
+
+/** 整表合并;没有任何改动时原样返回入参引用,下游 memo 不被打穿。 */
+export function mergeOrcaLeadAttentionKinds(
+ attentionKinds: ReadonlyMap<string, AttentionKind>,
+ leadAttention: ReadonlyMap<string, OrcaLeadWorkerAttentionKind>,
+): ReadonlyMap<string, AttentionKind> {
+ let merged: Map<string, AttentionKind> | null = null;
+ for (const [leadSessionId, workerKind] of leadAttention) {
+ const own = attentionKinds.get(leadSessionId);
+ const next = mergeOrcaLeadAttentionKind(own, workerKind);
+ if (next === own || next === undefined) continue;
+ merged ??= new Map(attentionKinds);
+ merged.set(leadSessionId, next);
+ }
+ return merged ?? attentionKinds;
+}
+
+/** 未读集合并入有 Worker 汇总的 Lead;没有新增成员时原样返回入参引用。 */
+export function mergeOrcaLeadNotifications(
+ notifications: ReadonlySet<string>,
+ leadAttention: ReadonlyMap<string, OrcaLeadWorkerAttentionKind>,
+): ReadonlySet<string> {
+ let merged: Set<string> | null = null;
+ for (const leadSessionId of leadAttention.keys()) {
+ if (notifications.has(leadSessionId)) continue;
+ merged ??= new Set(notifications);
+ merged.add(leadSessionId);
+ }
+ return merged ?? notifications;
+}
+
+function sameLeadAttention(
+ a: ReadonlyMap<string, OrcaLeadWorkerAttentionKind>,
+ b: ReadonlyMap<string, OrcaLeadWorkerAttentionKind>,
+): boolean {
+ if (a.size !== b.size) return false;
+ for (const [key, value] of a) {
+ if (b.get(key) !== value) return false;
+ }
+ return true;
+}
+
+// —— 模块级派生快照 ——
+// useSyncExternalStore 要求内容不变时返回同一引用:按两个上游的快照引用 / 版本号缓存,
+// 内容没变就复用旧 Map,逐行订阅与整表订阅都不会被无关广播惊动。
+const EMPTY_LEAD_ATTENTION: ReadonlyMap<string, OrcaLeadWorkerAttentionKind> = new Map();
+let cachedAttentionKinds: ReadonlyMap<string, AttentionKind> | null = null;
+let cachedProjectionVersion = -1;
+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) {
+ return;
+ }
+ const leads: LeadWorkerSessions[] = [];
+ // 远程判定不进缓存键也不会过期:远程 Lead 的投影只有在已知远程后才会走隧道拿到
+ // Worker(之前按本机查询只会得到空列表),且「已知远程」只增不减。
+ for (const [leadSessionId, snapshot] of listRetainedWorkerProjections()) {
+ if (snapshot.workers.length === 0 || isRemoteSessionSticky(leadSessionId)) continue;
+ leads.push([leadSessionId, snapshot.workers.map((worker) => worker.sessionId)]);
+ }
+ const next = deriveOrcaLeadWorkerAttention(leads, attentionKinds);
+ const leadAttention = sameLeadAttention(next, cachedLeadAttention) ? cachedLeadAttention : next;
+ if (leadAttention !== cachedLeadAttention || attentionKinds !== cachedAttentionKinds) {
+ cachedMergedKinds = mergeOrcaLeadAttentionKinds(attentionKinds, leadAttention);
+ }
+ cachedAttentionKinds = attentionKinds;
+ cachedProjectionVersion = projectionVersion;
+ cachedLeadAttention = leadAttention;
+}
+
+// 两组订阅者只在各自关心的派生结果换引用时才被唤醒:逐行订阅 Lead 汇总的组件不会因
+// 无关会话的 attention 或 Worker 状态变化而全部重跑 getSnapshot。上游订阅按需建立。
+const leadAttentionListeners = new Set<() => void>();
+const mergedKindsListeners = new Set<() => void>();
+let unsubscribeUpstream: (() => void) | null = null;
+
+function onUpstreamChange(): void {
+ const previousLeadAttention = cachedLeadAttention;
+ const previousMergedKinds = cachedMergedKinds;
+ refreshCache();
+ if (cachedLeadAttention !== previousLeadAttention) {
+ for (const listener of [...leadAttentionListeners]) listener();
+ }
+ if (cachedMergedKinds !== previousMergedKinds) {
+ for (const listener of [...mergedKindsListeners]) listener();
+ }
+}
+
+function subscribeDerived(listeners: Set<() => void>, listener: () => void): () => void {
+ if (!unsubscribeUpstream) {
+ refreshCache();
+ const unsubscribeAttention = subscribeSessionAttention(onUpstreamChange);
+ const unsubscribeProjections = subscribeAllWorkerProjections(onUpstreamChange);
+ unsubscribeUpstream = () => {
+ unsubscribeAttention();
+ unsubscribeProjections();
+ };
+ }
+ listeners.add(listener);
+ return () => {
+ listeners.delete(listener);
+ if (leadAttentionListeners.size === 0 && mergedKindsListeners.size === 0) {
+ unsubscribeUpstream?.();
+ unsubscribeUpstream = null;
+ }
+ };
+}
+
+/** Lead 汇总表换引用(内容变化)时通知。 */
+export function subscribeOrcaLeadWorkerAttention(listener: () => void): () => void {
+ return subscribeDerived(leadAttentionListeners, listener);
+}
+
+/** 合并后的 kind 表换引用时通知(与 sessionAttentionStore 每次广播同频)。 */
+export function subscribeSessionAttentionKindsWithOrcaLeads(listener: () => void): () => void {
+ return subscribeDerived(mergedKindsListeners, listener);
+}
+
+/** Lead → 汇总的 Worker kind。 */
+export function getOrcaLeadWorkerAttention(): ReadonlyMap<string, OrcaLeadWorkerAttentionKind> {
+ refreshCache();
+ return cachedLeadAttention;
+}
+
+/** sessionAttentionStore 的 kind 表并入 Lead 汇总;无 Orca 汇总时与原表同一引用。 */
+export function getSessionAttentionKindsWithOrcaLeads(): ReadonlyMap<string, AttentionKind> {
+ refreshCache();
+ return cachedMergedKinds;
+}
+
+/**
+ * Worker 自身事件是否单独发通知:只放行本机 Worker 的出错与需要确认;完成仍不单独通知,
+ * 等 Lead 被回报唤起的那一轮以 Lead 名义统一通知。远程控制另一台电脑的 Worker 不在范围内。
+ */
+export function shouldNotifyOrcaWorkerEvent(
+ kind: 'done' | 'error' | 'needs-reply',
+ worker: { deviceLinkDeviceId?: string | null },
+): boolean {
+ return kind !== 'done' && !worker.deviceLinkDeviceId;
+}
+
+/** Worker 通知标题:「Lead 标题 · Worker 标题」;找不到 Lead 时退回 Worker 标题。 */
+export function formatOrcaWorkerNotificationTitle(
+ workerTitle: string,
+ leadTitle: string | null,
+): string {
+ return leadTitle ? `${leadTitle} · ${workerTitle}` : workerTitle;
+}
+
+/** Worker 会话所属的本机 Lead(按已持有的投影反查);查不到返回 null。 */
+export function findOrcaLeadSessionIdForWorker(workerSessionId: string): string | null {
+ for (const [leadSessionId, snapshot] of listRetainedWorkerProjections()) {
+ if (snapshot.workers.some((worker) => worker.sessionId === workerSessionId)) {
+ return leadSessionId;
+ }
+ }
+ return null;
+}
+
+/**
+ * 逐行用:只订阅本行 Lead 的汇总 kind(primitive 快照),其它 Lead 或无关会话变化不重渲染。
+ * 性能不变量同 useSessionAttentionKind,列表行禁止改用下面的整表 hook。
+ */
+export function useOrcaLeadWorkerAttentionKind(
+ sessionId: string,
+): OrcaLeadWorkerAttentionKind | undefined {
+ const getSnapshot = () => getOrcaLeadWorkerAttention().get(sessionId);
+ return useSyncExternalStore(subscribeOrcaLeadWorkerAttention, getSnapshot, getSnapshot);
+}
+
+/** 聚合视图用:整张 Lead 汇总表(只在内容变化时换引用)。 */
+export function useOrcaLeadWorkerAttention(): ReadonlyMap<string, OrcaLeadWorkerAttentionKind> {
+ return useSyncExternalStore(
+ subscribeOrcaLeadWorkerAttention,
+ getOrcaLeadWorkerAttention,
+ getOrcaLeadWorkerAttention,
+ );
+}
+
+/**
+ * 聚合视图用:替代 useSessionAttentionKinds,Lead 的 kind 已并入 Worker 汇总。
+ * 与 useSessionAttentionKinds 一样每次 attention 广播都可能换引用,不要进逐行组件。
+ */
+export function useSessionAttentionKindsWithOrcaLeads(): ReadonlyMap<string, AttentionKind> {
+ return useSyncExternalStore(
+ subscribeSessionAttentionKindsWithOrcaLeads,
+ getSessionAttentionKindsWithOrcaLeads,
+ getSessionAttentionKindsWithOrcaLeads,
+ );
+}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
index 75bc875735..54b8d97df8 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
@@ -78,6 +78,10 @@ import { isRemoteSessionWriteBlocked } from '../lib/remoteSessionWriteGuard';
import { prefetchDirtyWorktreeForRemoval } from '@/lib/worktreeRemovalWarning';
import { resolveSessionCardBody } from './sessionCardPreview';
import { useSessionAttentionKind } from '@/lib/sessionAttentionStore';
+import {
+ mergeOrcaLeadAttentionKind,
+ useOrcaLeadWorkerAttentionKind,
+} from '../lib/orcaLeadWorkerAttention';
import { useSessionAttentionUrgency } from '../contexts/SessionAttentionUrgencyContext';
import { useRemoteSessionScheduleInfo } from '@/features/device-link/remoteProjectsStore';
import { useRemoteSessionActivity } from '@/features/device-link/remoteSessionActivityStore';
@@ -173,7 +177,10 @@ export const SessionCard = withSidebarNavigation<SessionCardProps>(function Sess
// list 变体与文字模式共用右侧状态优先级:
// error > awaiting > running > done > time。远程会话由被控端活动镜像覆盖
// 本地 attention 链路,与 SessionItem 完全一致。
- const attentionKind = useSessionAttentionKind(session.id);
+ // Orca Lead 另并入其 Worker 的出错 / 等待确认,见 lib/orcaLeadWorkerAttention.ts。
+ const ownAttentionKind = useSessionAttentionKind(session.id);
+ const orcaWorkerAttentionKind = useOrcaLeadWorkerAttentionKind(session.id);
+ const attentionKind = mergeOrcaLeadAttentionKind(ownAttentionKind, orcaWorkerAttentionKind);
const isUrgentFromContext = useSessionAttentionUrgency(session.id);
const remoteActivity = useRemoteSessionActivity(session.id, session.deviceLinkDeviceId);
const remoteSchedule = useRemoteSessionScheduleInfo(session.id);
@@ -188,7 +195,10 @@ export const SessionCard = withSidebarNavigation<SessionCardProps>(function Sess
isRunning: session.deviceLinkDeviceId
? remoteActivity?.phase === 'running'
: isRunning || cindyMakeActivity != null,
- hasAttentionNotification: hasAttentionNotification || remoteSchedule?.hasUnreadRun === true,
+ hasAttentionNotification:
+ hasAttentionNotification ||
+ orcaWorkerAttentionKind !== undefined ||
+ remoteSchedule?.hasUnreadRun === true,
});
const leftIconRunning = sessionActivity.currentTurnActive === true;
const rightStatusKind = resolveSidebarRightStatus(sessionActivity);
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
index a45155f324..3e80a4e5ae 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
@@ -86,6 +86,10 @@ import { isRemoteSessionWriteBlocked } from '../lib/remoteSessionWriteGuard';
import { Tip } from '@/components/ui/tooltip';
import { prefetchDirtyWorktreeForRemoval } from '@/lib/worktreeRemovalWarning';
import { useSessionAttentionKind } from '@/lib/sessionAttentionStore';
+import {
+ mergeOrcaLeadAttentionKind,
+ useOrcaLeadWorkerAttentionKind,
+} from '../lib/orcaLeadWorkerAttention';
import { useSessionAttentionUrgency } from '../contexts/SessionAttentionUrgencyContext';
import { useRemoteSessionScheduleInfo } from '@/features/device-link/remoteProjectsStore';
import { useRemoteSessionActivity } from '@/features/device-link/remoteSessionActivityStore';
@@ -407,7 +411,12 @@ export const SessionItem = withSidebarNavigation<SessionItemProps>(function Sess
//
// 额外 error 来源:定时任务未读且非成功(failed / aborted / interrupted)结局的 session ——
// 通过 SessionAttentionUrgencyContext 由上游注入,避免误把失败的 automation 涂成 Completed。
- const attentionKind = useSessionAttentionKind(session.id);
+ //
+ // Orca Lead 行另并入其 Worker 的出错 / 等待确认(出错 > 等待确认 > Lead 自身),
+ // 见 lib/orcaLeadWorkerAttention.ts。
+ const ownAttentionKind = useSessionAttentionKind(session.id);
+ const orcaWorkerAttentionKind = useOrcaLeadWorkerAttentionKind(session.id);
+ const attentionKind = mergeOrcaLeadAttentionKind(ownAttentionKind, orcaWorkerAttentionKind);
const isUrgentFromContext = useSessionAttentionUrgency(session.id);
const islandActivity = useAgentIslandActivity(session.id);
// device-link 远程会话行:本地 attention/running 链路对被控端后台会话是盲区,状态改由
@@ -426,7 +435,10 @@ export const SessionItem = withSidebarNavigation<SessionItemProps>(function Sess
isRunning: session.deviceLinkDeviceId
? remoteActivity?.phase === 'running'
: isRunning || cindyMakeActivity != null,
- hasAttentionNotification: hasAttentionNotification || remoteSchedule?.hasUnreadRun === true,
+ hasAttentionNotification:
+ hasAttentionNotification ||
+ orcaWorkerAttentionKind !== undefined ||
+ remoteSchedule?.hasUnreadRun === true,
});
const leftIconRunning = sessionActivity.currentTurnActive === true;
const rightStatusKind = resolveSidebarRightStatus(sessionActivity);
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
index 86127e9f4b..095cfa7654 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
@@ -27,6 +27,10 @@ import { useComposerDraftPresence } from '@/hooks/useComposerDraftPresence';
import { useSessionPausedQueue } from '@/hooks/useSessionPausedQueue';
import { useGhostSessionBusy } from '@/cindy-brain/ghostSessionActivityStore';
import { useSessionAttentionKind } from '@/lib/sessionAttentionStore';
+import {
+ mergeOrcaLeadAttentionKind,
+ useOrcaLeadWorkerAttentionKind,
+} from '../lib/orcaLeadWorkerAttention';
import { useSessionAttentionUrgency } from '../contexts/SessionAttentionUrgencyContext';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
import {
@@ -140,7 +144,12 @@ export function SessionStatusIcon({
// 角标 tone:error(含定时任务失败的 urgency context)红 > awaiting 蓝 > 完成未读绿。
// 两个 hook 都是按 sessionId 的 primitive 精准订阅(性能不变量,见 SessionItem 头注),
// 本组件也被逐行挂载,禁止退回整表订阅。
- const attentionKind = useSessionAttentionKind(session.id);
+ // Orca Lead 另并入其 Worker 的出错 / 等待确认(同为按 id 的 primitive 订阅),
+ // 见 lib/orcaLeadWorkerAttention.ts。
+ const ownAttentionKind = useSessionAttentionKind(session.id);
+ const orcaWorkerAttentionKind = useOrcaLeadWorkerAttentionKind(session.id);
+ const attentionKind = mergeOrcaLeadAttentionKind(ownAttentionKind, orcaWorkerAttentionKind);
+ const hasAttentionDot = hasAttentionNotification || orcaWorkerAttentionKind !== undefined;
const isUrgentFromContext = useSessionAttentionUrgency(session.id);
const attentionTone =
attentionToneOverride ??
@@ -205,7 +214,7 @@ export function SessionStatusIcon({
<AgentDeviceVendorIcon
deviceId={agentDeviceId}
controlledTask={Boolean(session.deviceLinkDeviceId)}
- showSignal={!(showAttentionDot && hasAttentionNotification)}
+ showSignal={!(showAttentionDot && hasAttentionDot)}
vendor={vendor}
size={size ?? (vendor === 'cc' ? 13 : 12)}
running={isRunning}
@@ -219,7 +228,7 @@ export function SessionStatusIcon({
colorClassName={isActive ? 'text-[var(--sidebar-item-active-foreground)]' : undefined}
/>
)}
- {showAttentionDot && hasAttentionNotification && (
+ {showAttentionDot && hasAttentionDot && (
<AttentionDot size={6} tone={attentionTone} className="absolute -top-0.5 -right-0.5" />
)}
{showDraftIndicator && (
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
index 2d94a5c52d..7ddb2dfe3b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
@@ -164,6 +164,8 @@ vi.mock('@/hooks/useSessionPausedQueue', () => ({
vi.mock('@/lib/sessionAttentionStore', () => ({
useSessionAttentionKind: (sessionId: string) => mocks.attentionKindBySession.get(sessionId),
+ getSessionAttentionKinds: () => mocks.attentionKindBySession,
+ subscribeSessionAttention: () => () => undefined,
}));
vi.mock('../../lib/scrollIntoNearestView', () => ({
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
index b52e69d702..58c050541f 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
@@ -96,7 +96,7 @@ import { buildSessionSourceLabelMap } from '../../lib/sessionSourceLabel';
import { aggregateSessionLamps, type SessionLampAggregate } from '../../lib/sessionLampAggregation';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
import { SidebarRightStatusIndicator } from '../SidebarRightStatusIndicator';
-import { useSessionAttentionKinds } from '@/lib/sessionAttentionStore';
+import { useSessionAttentionKindsWithOrcaLeads } from '../../lib/orcaLeadWorkerAttention';
import { useSessionAttentionUrgencySet } from '../../contexts/SessionAttentionUrgencyContext';
import {
getRemoteSessionActivity,
@@ -470,7 +470,8 @@ export function ProjectsSection({
// 整表订阅仅限本聚合组件(两个 store 头注的性能边界):本组件本就随
// notifications 整集变化重渲染,不额外放大;远程镜像走整表版本号 + 逐 id 读,
// 与 CCAgentSidebarUpper.projectAgg 同款先例。
- const attentionKinds = useSessionAttentionKinds();
+ // Lead 的 kind 已并入其 Worker 的出错 / 等待确认(notifications 由上层同口径合并)。
+ const attentionKinds = useSessionAttentionKindsWithOrcaLeads();
const urgentSet = useSessionAttentionUrgencySet();
const remoteActivityRevision = useRemoteSessionActivityRevision();
const collapsedAttentionToneFor = useCallback(
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 8541fa169a..7974948d45 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,9 +1,32 @@
+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 {
+ useSessionsAttentionUrgentKind,
+ type AttentionKind,
+} from '@/lib/sessionAttentionStore';
+
+/**
+ * 多个 Worker 时取最高一档:出错(红)> 等待确认(蓝)> 完成未读(绿)。
+ * 出错 / 等待确认跟随 Worker 自己的 attention,tab 激活时同样显示(与侧栏 Lead 行同口径);
+ * 完成未读沿用原语义,tab 激活即视为看到。
+ */
+export function resolveOrcaWorkersTabTone({
+ urgentKind,
+ hasDoneAttention,
+ active,
+}: {
+ urgentKind: 'error' | 'awaiting' | undefined;
+ hasDoneAttention: boolean;
+ active: boolean;
+}): AttentionKind | null {
+ if (urgentKind) return urgentKind;
+ return hasDoneAttention && !active ? 'done' : null;
+}
export function OrcaWorkersAttentionIcon({
sessionId,
@@ -15,20 +38,32 @@ export function OrcaWorkersAttentionIcon({
const { t } = useTranslation();
const attention = useWorkerAttentionSnapshot();
const projection = useWorkerProjection(sessionId ?? '');
- const hasAttention = Boolean(
+ const workerSessionIds = useMemo(
+ () => (sessionId ? projection.workers.map((worker) => worker.sessionId) : []),
+ [sessionId, projection.workers],
+ );
+ const urgentKind = useSessionsAttentionUrgentKind(workerSessionIds);
+ const hasDoneAttention = Boolean(
sessionId && projection.workers.some((worker) => attention.has(worker.workerId)),
);
+ const tone = resolveOrcaWorkersTabTone({ urgentKind, hasDoneAttention, active });
+ const toneLabel =
+ tone === 'error'
+ ? t('orca.rolePill.errorBadgeAria')
+ : tone === 'awaiting'
+ ? t('orca.rolePill.awaitingBadgeAria')
+ : t('orca.rolePill.unread');
return (
<span className="relative inline-flex">
<UsersRound size={13} />
- {!active && hasAttention && (
+ {tone && (
<span
- aria-label={t('orca.rolePill.unread')}
+ aria-label={toneLabel}
className="absolute -right-[3px] -top-[3px] inline-flex rounded-full"
style={{ boxShadow: '0 0 0 1.5px var(--surface)' }}
>
- <AttentionDot size={6} />
+ <AttentionDot size={6} tone={tone} />
</span>
)}
</span>
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/__tests__/OrcaWorkersAttentionIcon.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/__tests__/OrcaWorkersAttentionIcon.test.ts
new file mode 100644
index 0000000000..1a572ca6b6
--- /dev/null
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/__tests__/OrcaWorkersAttentionIcon.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest';
+
+import { resolveOrcaWorkersTabTone } from '../OrcaWorkersAttentionIcon';
+
+describe('resolveOrcaWorkersTabTone', () => {
+ it('多个 Worker 时按 出错 > 等待确认 > 完成未读 取最高一档', () => {
+ expect(resolveOrcaWorkersTabTone({ urgentKind: 'error', hasDoneAttention: true, active: false }))
+ .toBe('error');
+ expect(resolveOrcaWorkersTabTone({ urgentKind: 'awaiting', hasDoneAttention: true, active: false }))
+ .toBe('awaiting');
+ expect(resolveOrcaWorkersTabTone({ urgentKind: undefined, hasDoneAttention: true, active: false }))
+ .toBe('done');
+ expect(resolveOrcaWorkersTabTone({ urgentKind: undefined, hasDoneAttention: false, active: false }))
+ .toBeNull();
+ });
+
+ it('出错 / 等待确认在 tab 激活时也显示;完成未读激活即视为看到', () => {
+ expect(resolveOrcaWorkersTabTone({ urgentKind: 'awaiting', hasDoneAttention: false, active: true }))
+ .toBe('awaiting');
+ expect(resolveOrcaWorkersTabTone({ urgentKind: 'error', hasDoneAttention: false, active: true }))
+ .toBe('error');
+ expect(resolveOrcaWorkersTabTone({ urgentKind: undefined, hasDoneAttention: true, active: true }))
+ .toBeNull();
+ });
+});
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 12febe0879..33b29ac5fd 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -14598,6 +14598,7 @@
"scrollWorkersRightEdge": "Already at the latest worker",
"errorBadge": "ERR",
"errorBadgeAria": "A worker has an error",
+ "awaitingBadgeAria": "A worker is awaiting your reply",
"executionDevice": "Runs on {{device}}",
"deviceUnreachable": "Status unavailable",
"unknownDevice": "Another computer",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index bd7570c657..0b66a6a8a8 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -14539,6 +14539,7 @@
"scrollWorkersRightEdge": "すでに末尾の Worker を表示しています",
"errorBadge": "エラー",
"errorBadgeAria": "エラーが発生した Worker があります",
+ "awaitingBadgeAria": "返信を待っている Worker があります",
"executionDevice": "{{device}} で実行",
"deviceUnreachable": "状態を取得できません",
"unknownDevice": "別のコンピューター",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 977648c683..8a1ee4a900 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -14539,6 +14539,7 @@
"scrollWorkersRightEdge": "이미 마지막 Worker 를 표시하고 있습니다",
"errorBadge": "오류",
"errorBadgeAria": "오류가 발생한 Worker 가 있습니다",
+ "awaitingBadgeAria": "회신을 기다리는 Worker 가 있습니다",
"executionDevice": "{{device}}에서 실행",
"deviceUnreachable": "상태를 가져올 수 없음",
"unknownDevice": "다른 컴퓨터",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index f808e8269e..7109a1c979 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -14539,6 +14539,7 @@
"scrollWorkersRightEdge": "已是最右侧的 Worker",
"errorBadge": "错误",
"errorBadgeAria": "有 Worker 出错",
+ "awaitingBadgeAria": "有 Worker 等待你回复",
"executionDevice": "在 {{device}} 运行",
"deviceUnreachable": "暂时无法获取状态",
"unknownDevice": "另一台电脑",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 344cb28aa9..2a308314f9 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -14539,6 +14539,7 @@
"scrollWorkersRightEdge": "已是最右側的 Worker",
"errorBadge": "錯誤",
"errorBadgeAria": "有 Worker 出錯",
+ "awaitingBadgeAria": "有 Worker 等待你回覆",
"executionDevice": "在 {{device}} 執行",
"deviceUnreachable": "暫時無法取得狀態",
"unknownDevice": "另一台電腦",
diff --git a/docs/dev-rules/orca-team-architecture.md b/docs/dev-rules/orca-team-architecture.md
index 4a95611cf4..6f6cdea2a2 100644
--- a/docs/dev-rules/orca-team-architecture.md
+++ b/docs/dev-rules/orca-team-architecture.md
@@ -209,6 +209,8 @@ doc rail 不走右侧栏 tab,也不做 route navigate。WorkdirBrowseRoute 的
Worker 不出现在普通 sidebar。renderer 用 `isOrcaWorkerSession(session) => session.orcaRole === 'worker'` 识别 worker,sidebar filter 直接排除 worker,见 `apps/desktop/src/renderer/lib/orcaSessionIdentity.ts` 的 `isOrcaWorkerSession` 与 `apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx` 的 `sidebarSessions` filter。worker deep link 会解析到所属 Lead 的普通 route,并通过 `?worker=` 一次性聚焦右侧栏协同 tab,见 `apps/desktop/src/renderer/lib/orcaSessionIdentity.ts` 的 `resolveSessionRoute`。
+Worker 虽不进侧栏,它的出错与等待确认会汇总到所属 Lead 行(2026-10 用户裁决,只覆盖本机 Lead):Lead 行的状态点、项目折叠灯、rail 瓷砖、排序钉住与 Dock 角标都按「Worker 出错(红)> Worker 等待确认(蓝)> Lead 自己的状态」取一档,红 / 蓝同样盖过运行中;Worker 的完成不汇总。汇总只是读侧派生:来源是 Worker 自己在 `sessionAttentionStore` 里的 attention 与 Worker 投影(`workerProjectionStore` 中仍被持有的 Lead;已归档 Worker、已结束协同的团队不在投影里,自然不计),生命周期完全跟随 Worker 的 attention(重试 / 关横幅、Lead 重新派活、确认被回答即消失),点开 Lead 不会清掉,正在看该 Lead 时也照常显示。汇总结果**不得写回** `sessionAttentionStore`:那份会同步到 Main(Dock / 灵动岛 / 远端),并被「导航即已读」的被动清除抹掉,会破坏 Lead 自身的 attention 生命周期与完成保持判定。Dock 角标一个 Lead 只算 1,口径与侧栏行一致。逐行组件(`SessionItem` / `SessionCard` / `SessionStatusIcon`)只能用按 id 的 primitive 订阅 `useOrcaLeadWorkerAttentionKind`,聚合视图用 `useSessionAttentionKindsWithOrcaLeads` / `useOrcaLeadWorkerAttention` 与 `mergeOrcaLeadNotifications`。实现指针:`apps/desktop/src/renderer/features/cc-agent/lib/orcaLeadWorkerAttention.ts`、`workerProjectionStore.ts` 的 `listRetainedWorkerProjections`、`lib/appAttentionCount.ts` 的 `orcaLeadWorkerAttention` 入参。
+
Worktree 现状:Orca 与普通 session 对齐,worktree 是可选项,不强制;toggle off 时 Lead/Worker 使用用户选的 workingDir,toggle on 时 Lead/Worker 共用同一个 worktree。
`create_worker` / `create_workers` 的每个 Worker 可显式指定 `working_dir`(Worker
@@ -370,7 +372,7 @@ 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 重新变未读。实现指针:`useOrcaWorkerAttentionWatcher.ts` 的 `computeWorkerAttentionUpdates`,`RolePillDropdown.tsx` 的 selected worker clear effect,`workerAttentionStore.ts` 的 `attentionWorkerIds`。
+ 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`。
6. **重启后对 known worker 懒登记(状态:不变量)**
app 重启后内存里的 known worker / vendorOptions 都会丢。恢复时不能只信内存 cache,必须通过 DB 的 `sessions.orca_role`、`orca_workers`、`orca_teams` 懒合成 Orca vendorOptions / worker link,保证手动 stop、terminal turn、worker 列表仍能识别已存在 worker;手动中断跟踪只能作为运行时优化,不能作为唯一事实源。刚开启协同但 worker 尚未对话时,也必须先写出可恢复的 agent 侧历史;当前通过 ready placeholder 触发 worker 首次 send,避免 Codex worker 因 rollout 缺失在重启后无法 resume。实现指针:`register.ts` 的 `synthesizeOrcaVendorOptionsFromDb`、`sessionCreateHandler.ts` 的 `sendWorkerReadyMessage`、`orcaLifecycleService.ts` 的 `enableTeam` / `sendWorkerReadyPlaceholder` 依赖、`orcaTeamStore.ts` 的 `listWorkersByLead` / `getWorkerLink`、`orcaManualInterrupt.ts` 的 known worker / manual interrupt store。
@@ -382,7 +384,7 @@ Worker turn 被 vendor 报终止型 error,但 interrupted-turn auto-resume 仍
worker 的回报 settle(`send_to_lead` 被接受/入队)会先把持久化状态置 `done`,而 worker 自己的 turn 可能还在收尾;renderer「看到 done 即 ack」此时会被 active-turn / send 锁守卫以 `WORKER_STATE_CHANGED` 拒绝。被这两类守卫拒绝的确认必须登记下来,在该 turn 的 `handleWorkerTerminalTurn` done 分支重试一次(fire-once,重试失败不重登记);新 turn 开始(`handleWorkerTurnStarted`)必须作废登记。没有登记过的 done 不得在 terminal 边界自动收口——`done` 的产品语义是「保持到用户看到为止」。实现指针:`orcaTeamService.ts` 的 `deferredDoneAcknowledgements`、`idleWorker`、`handleWorkerTurnStarted`、`handleWorkerTerminalTurn`。
9. **Lead 的完成以团队收口为准(状态:不变量)**
- Lead 派完活结束本轮时,团队仍在干活,这一轮不是完成:灵动岛保持 Lead 为运行中(不出完成卡片、不响完成音、不记未读),Work Louder 键盘、侧栏卡片与远程会话列表读同一份活动快照,因此一起保持运行中;renderer 不发完成通知(桌面/手机/飞书)、不亮完成角标。Worker 回报送达后 Lead 被唤起,那一轮的 done 才是团队完成。判据只有一份,在 Main:以「仍有 accepted 派活欠 Lead 回报」(auto-bridge pending)为准,最后一份回报送达或被丢弃(手动停止、归档等)时,若 Lead 空闲则补发被推迟的完成;renderer 不自行推算 Worker 状态,完成去抖落地时读灵动岛活动快照,Main 仍把该会话保持为 `running` 就不算完成(暂停的输入队列同样会让灵动岛保持运行中,但保留原有完成提醒,故排除)。Worker 自身仍不进灵动岛、不单独发通知。已知边界(刻意不处理,保持简单):派给正忙 Worker、尚在其队列里未被接收的任务还没有待回报记录(Worker 正忙通常意味着已有同一 Lead 的待回报记录);静默完成(如静默的自动运行)不走推迟,Lead 活动会直接变为完成。实现指针:`orcaTeamService.ts` 的 `hasPendingWorkerReports` / `deletePendingReport` / `onLeadWorkerReportsSettled`,`register.ts` 的 `setCompletionDeferResolver` 与 `onLeadWorkerReportsSettled` wiring,`agent-island/service.ts` 的 `notifyQueueEmptied`,renderer `state/agentIslandActivity.ts` 的 `isSessionCompletionHeldByAgentIsland` 与 `useSessionRunningStatus.ts` 的 done debounce。
+ Lead 派完活结束本轮时,团队仍在干活,这一轮不是完成:灵动岛保持 Lead 为运行中(不出完成卡片、不响完成音、不记未读),Work Louder 键盘、侧栏卡片与远程会话列表读同一份活动快照,因此一起保持运行中;renderer 不发完成通知(桌面/手机/飞书)、不亮完成角标。Worker 回报送达后 Lead 被唤起,那一轮的 done 才是团队完成。判据只有一份,在 Main:以「仍有 accepted 派活欠 Lead 回报」(auto-bridge pending)为准,最后一份回报送达或被丢弃(手动停止、归档等)时,若 Lead 空闲则补发被推迟的完成;renderer 不自行推算 Worker 状态,完成去抖落地时读灵动岛活动快照,Main 仍把该会话保持为 `running` 就不算完成(暂停的输入队列同样会让灵动岛保持运行中,但保留原有完成提醒,故排除)。Worker 自身仍不进灵动岛;Worker 的完成不单独通知,出错与需要确认以「Lead 标题 · Worker 标题」单独通知(桌面 / 飞书 / 手机推送,走同一个 `sendSessionEventNotification`;找不到 Lead 时退回 Worker 标题;只覆盖本机 Worker),点击按 Worker id 经 `resolveSessionRoute` 落到 Lead 并打开该 Worker。Worker 出错后 Lead 被唤起处理完还会有一条 Lead 完成通知,两条都保留。已知空档(用户接受):开启灵动岛时渲染端不弹系统横幅,而 Worker 不进灵动岛,这段时间 Worker 的出错 / 确认收不到桌面弹窗,飞书 / 手机推送不受影响。实现指针:`CCAgentSidebarUpper.tsx` 的 `fireSessionNotification`,`orcaLeadWorkerAttention.ts` 的 `shouldNotifyOrcaWorkerEvent` / `formatOrcaWorkerNotificationTitle` / `findOrcaLeadSessionIdForWorker`。已知边界(刻意不处理,保持简单):派给正忙 Worker、尚在其队列里未被接收的任务还没有待回报记录(Worker 正忙通常意味着已有同一 Lead 的待回报记录);静默完成(如静默的自动运行)不走推迟,Lead 活动会直接变为完成。实现指针:`orcaTeamService.ts` 的 `hasPendingWorkerReports` / `deletePendingReport` / `onLeadWorkerReportsSettled`,`register.ts` 的 `setCompletionDeferResolver` 与 `onLeadWorkerReportsSettled` wiring,`agent-island/service.ts` 的 `notifyQueueEmptied`,renderer `state/agentIslandActivity.ts` 的 `isSessionCompletionHeldByAgentIsland` 与 `useSessionRunningStatus.ts` 的 done debounce。
10. **远端 Worker 只在运行设备上跑(状态:不变量)**
Worker 可以放到同账号另一台电脑(运行设备)上运行:真实任务在那台,本机只有一条不跑 Agent、`working_dir` 为空的代理任务行,`orca_workers.execution_device_id` / `remote_session_id` 记录位置。代理行承接计槽、状态机、auto-bridge 与归档,任何路径都不得在本机为它起 Agent(`bootstrapSession` 对远端 Worker 直接拒绝)、不得把它复制到其他电脑;派活、停止与存活查询经 `orcaRemoteWorkers.ts` 的 `wrapTeamDeps` 分流到运行设备,其余依赖原样透传,不另造状态机。回报靠轮询:派出的消息已进入对话(投递回执 accepted)且设备不在跑时,分页读取 user / assistant 历史,按派活 user 的 clientId 定位对应的最后一条 assistant 回复并按消息 id 去重;后续用户插话的回复和异常状态不得归给此前派活,历史读取期间的新派活不得被旧回报清除。每轮最多扫描 2000 行,预算不足时保留游标下一轮续读,不误判缺少回复;宿主 onAccepted / onAcceptedCommit 完成后才冻结回报身份并允许轮询收尾,accepted 回调失败恢复上一代等待状态,保存旧结果期间不得消费新派活身份或写入其捕获文本。同一远端 Worker 的 enqueue、accepted / commit 和身份确认复用现成 session 发送锁串行执行,避免并发回调与投递顺序错位。用户在运行设备上直接发的消息算插话,不触发回报。设备不可达只是运行期投影(`executionDevice.reachable`),不扩展 `OrcaWorkerStatus`;派活时不可达直接失败,不回退到本机。首版远端 Worker 没有 `send_to_lead` 桥,也不支持 steer / 队列编辑。界面:创建弹窗的「运行设备」只在本机 Lead 上出现(`CreateWorkerPopover` 的 `executionDevicesEnabled`),复用标准下拉列表,以有界滚动和键盘按名称定位应对多设备;选了其他电脑后,工作目录提供「对话 / 指定目录」,「对话」不传 `workingDir`、在运行设备创建不绑定项目的任务,「指定目录」只使用那台电脑上的绝对路径。手机版的新任务「开启协同」与 Lead「创建 Worker」共用设备下拉列表和两种目录模式;设备列表从 Lead 所在电脑读取,Agent、模型和供应商目录从所选运行设备读取。协同面板对远端 Worker 展示运行设备上的真实任务(`RemoteWorkerSessionPane`,先登记归属再读写)。实现指针:`orcaRemoteWorkerRuntime.ts`、`orcaRemoteWorkers.ts`、`orcaWorkerCreationService.ts` 的 `createRemoteWorkerInTeam`、运行设备侧 `orcaRemoteWorkerHost.ts`;协议见 `protocol-compatibility.md`「协同远端 Worker」。