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(sidebar): 折叠项目汇总任务状态点 (#2925)

Dash9385d6be24b5
diff --git a/apps/desktop/src/renderer/__tests__/projectCollapsedAttention.test.ts b/apps/desktop/src/renderer/__tests__/projectCollapsedAttention.test.ts
new file mode 100644
index 0000000000..b695685f9c
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/projectCollapsedAttention.test.ts
@@ -0,0 +1,131 @@
+import { readFileSync } from 'node:fs';
+import { resolve as resolvePath } from 'node:path';
+
+import { describe, expect, it } from 'vitest';
+
+import type { AttentionKind } from '@/lib/sessionAttentionStore';
+import type { RemoteSessionActivityPhase } from '@/features/device-link/remoteSessionActivityStore';
+import { resolveCollapsedProjectAttentionTone } from '../features/cc-agent/sidebar/projectCollapsedAttention';
+
+const sidebarDir = resolvePath(__dirname, '..', 'features', 'cc-agent', 'sidebar');
+const projectNodeSource = readFileSync(
+ resolvePath(sidebarDir, 'sections', 'ProjectNode.tsx'),
+ 'utf8',
+);
+const projectsSectionSource = readFileSync(
+ resolvePath(sidebarDir, 'sections', 'ProjectsSection.tsx'),
+ 'utf8',
+);
+const sidebarUpperSource = readFileSync(
+ resolvePath(__dirname, '..', 'features', 'cc-agent', 'CCAgentSidebarUpper.tsx'),
+ 'utf8',
+);
+
+const sessions = (ids: string[]) => ids.map((id) => ({ id }));
+
+function resolve({
+ ids = ['session-1'],
+ running = [],
+ notifications = [],
+ attentionKinds = [],
+ urgent = [],
+ remotePhases = [],
+}: {
+ ids?: string[];
+ running?: string[];
+ notifications?: string[];
+ attentionKinds?: [string, AttentionKind][];
+ urgent?: string[];
+ remotePhases?: [string, RemoteSessionActivityPhase][];
+} = {}) {
+ const phases = new Map(remotePhases);
+ return resolveCollapsedProjectAttentionTone({
+ sessions: sessions(ids),
+ runningSessionIds: new Set(running),
+ notifications: new Set(notifications),
+ attentionKinds: new Map(attentionKinds),
+ urgentSessionIds: new Set(urgent),
+ remotePhaseOf: (sessionId) => phases.get(sessionId),
+ });
+}
+
+describe('collapsed project attention tone', () => {
+ it('returns no aggregate for idle, running, or awaiting-only children', () => {
+ expect(resolve()).toBeNull();
+ expect(
+ resolve({ notifications: ['session-1'], attentionKinds: [['session-1', 'awaiting']] }),
+ ).toBeNull();
+ expect(resolve({ remotePhases: [['session-1', 'running']] })).toBeNull();
+ expect(resolve({ remotePhases: [['session-1', 'needs-interaction']] })).toBeNull();
+ });
+
+ it('shows green for local and remote completed unread children', () => {
+ expect(resolve({ notifications: ['session-1'], attentionKinds: [['session-1', 'done']] })).toBe(
+ 'done',
+ );
+ // 定时任务未读可能没有 attention kind,子任务行仍显示完成绿点。
+ expect(resolve({ notifications: ['session-1'] })).toBe('done');
+ expect(resolve({ remotePhases: [['session-1', 'completed']] })).toBe('done');
+ });
+
+ it('shows red for local errors, urgent schedules, and remote errors', () => {
+ expect(
+ resolve({ notifications: ['session-1'], attentionKinds: [['session-1', 'error']] }),
+ ).toBe('error');
+ expect(resolve({ urgent: ['session-1'] })).toBe('error');
+ expect(resolve({ remotePhases: [['session-1', 'error']] })).toBe('error');
+ });
+
+ it('gives red priority when red and green children coexist', () => {
+ expect(
+ resolve({
+ ids: ['done', 'error'],
+ notifications: ['done', 'error'],
+ attentionKinds: [
+ ['done', 'done'],
+ ['error', 'error'],
+ ],
+ }),
+ ).toBe('error');
+ });
+
+ it('treats a remote running state as authoritative over stale local attention', () => {
+ expect(
+ resolve({
+ notifications: ['session-1'],
+ attentionKinds: [['session-1', 'error']],
+ remotePhases: [['session-1', 'running']],
+ }),
+ ).toBeNull();
+ });
+
+ it('does not aggregate stale local completion while the child is running again', () => {
+ expect(
+ resolve({
+ running: ['session-1'],
+ notifications: ['session-1'],
+ attentionKinds: [['session-1', 'done']],
+ }),
+ ).toBeNull();
+ });
+});
+
+describe('collapsed project attention wiring', () => {
+ it('renders the aggregate dot only while the project is collapsed', () => {
+ expect(projectNodeSource).toContain(
+ '!isEditingName && isCollapsed && collapsedAttentionTone ? (',
+ );
+ expect(projectNodeSource).toContain(
+ '<AttentionDot size={6} tone={collapsedAttentionTone} className="shrink-0" />',
+ );
+ });
+
+ it('feeds both regular and pinned project rows from their displayed children', () => {
+ expect(projectsSectionSource).toContain(
+ 'collapsed.has(project.projectKey) ? collapsedAttentionToneFor(project.sessions) : null',
+ );
+ expect(sidebarUpperSource).toMatch(
+ /collapse\.collapsed\.has\(project\.projectKey\)[\s\S]*?collapsedAttentionToneFor\(displaySessions \?\? project\.sessions\)[\s\S]*?: null/,
+ );
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 45558e2fca..a8c42cbdb5 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -169,9 +169,11 @@ import type {
} from './lib/automationSidebarGrouping';
import { getSessionDeviceId } from '@/features/device-link/remoteProjectsStore';
import {
+ getRemoteSessionActivity,
useRemoteSessionActivity,
useRemoteSessionActivityRevision,
} from '@/features/device-link/remoteSessionActivityStore';
+import { resolveCollapsedProjectAttentionTone } from './sidebar/projectCollapsedAttention';
import { WorkdirBrowseSidebar } from './workdir-browse/WorkdirBrowseSidebar';
import {
buildDocModeSwitchProjects,
@@ -1073,6 +1075,7 @@ function ExpandedView({
if (unreadScheduleSessionIds.size === 0) return notifications;
return new Set([...notifications, ...unreadScheduleSessionIds]);
}, [notifications, unreadScheduleSessionIds]);
+ const remoteActivityRevision = useRemoteSessionActivityRevision();
const markAutomationSessionRunsRead = useCallback(
(sessionId: string) => {
@@ -1118,6 +1121,25 @@ function ExpandedView({
}
return next;
}, [effectiveRunningSessionIds, backgroundActivitySessionIds, orcaLeadWorkerMap]);
+ const collapsedAttentionToneFor = useCallback(
+ (sessions: readonly Session[]) =>
+ resolveCollapsedProjectAttentionTone({
+ sessions,
+ runningSessionIds: displayRunningSessionIds,
+ notifications: sidebarNotifications,
+ attentionKinds,
+ urgentSessionIds: urgentSet,
+ remotePhaseOf: (sessionId) => getRemoteSessionActivity(sessionId)?.phase,
+ }),
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- remoteActivityRevision 代表 getRemoteSessionActivity 读到的整表内容
+ [
+ displayRunningSessionIds,
+ sidebarNotifications,
+ attentionKinds,
+ urgentSet,
+ remoteActivityRevision,
+ ],
+ );
// 本地会话用 effectiveIncludeArchived(snapshot 实际所属桶)避免切桶时先闪空;
// device-link 远程镜像同时持有 active / archived 两桶,必须独立按 filter.status 筛选,
@@ -3346,6 +3368,11 @@ function ExpandedView({
sessionVariant={sessionVariant}
statusFilter={filter.status}
isCollapsed={collapse.collapsed.has(project.projectKey)}
+ collapsedAttentionTone={
+ collapse.collapsed.has(project.projectKey)
+ ? collapsedAttentionToneFor(displaySessions ?? project.sessions)
+ : null
+ }
parentSectionCollapsed={parentSectionCollapsed}
activeSessionId={activeSessionId}
runningSessionIds={displayRunningSessionIds}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/projectCollapsedAttention.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/projectCollapsedAttention.ts
new file mode 100644
index 0000000000..8fea4ba2de
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/projectCollapsedAttention.ts
@@ -0,0 +1,49 @@
+import type { AttentionKind } from '@/lib/sessionAttentionStore';
+import type { RemoteSessionActivityPhase } from '@/features/device-link/remoteSessionActivityStore';
+
+export type CollapsedProjectAttentionTone = 'error' | 'done';
+
+interface CollapsedProjectAttentionInput {
+ sessions: readonly { id: string }[];
+ runningSessionIds: ReadonlySet<string>;
+ notifications: ReadonlySet<string>;
+ attentionKinds: ReadonlyMap<string, AttentionKind>;
+ urgentSessionIds: ReadonlySet<string>;
+ remotePhaseOf: (sessionId: string) => RemoteSessionActivityPhase | undefined;
+}
+
+/**
+ * 折叠项目只汇总子任务实际可见的红/绿状态点。等待回复(蓝)与运行态不在此处
+ * 升格;若红绿同时存在,错误红点优先。
+ */
+export function resolveCollapsedProjectAttentionTone({
+ sessions,
+ runningSessionIds,
+ notifications,
+ attentionKinds,
+ urgentSessionIds,
+ remotePhaseOf,
+}: CollapsedProjectAttentionInput): CollapsedProjectAttentionTone | null {
+ let hasDone = false;
+
+ for (const session of sessions) {
+ const remotePhase = remotePhaseOf(session.id);
+ if (remotePhase) {
+ if (remotePhase === 'error') return 'error';
+ if (remotePhase === 'completed') hasDone = true;
+ // 远程活动镜像是远程行右侧状态的权威来源;running / needs-interaction
+ // 分别显示 spinner / 蓝点,不能再被本地残留状态误汇总成红绿点。
+ continue;
+ }
+
+ if (urgentSessionIds.has(session.id)) return 'error';
+ if (!notifications.has(session.id)) continue;
+
+ const attentionKind = attentionKinds.get(session.id);
+ if (attentionKind === 'error') return 'error';
+ if (attentionKind === 'awaiting' || runningSessionIds.has(session.id)) continue;
+ hasDone = true;
+ }
+
+ return hasDone ? 'done' : null;
+}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectNode.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectNode.tsx
index 63e4a48efb..8142f84e0f 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectNode.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectNode.tsx
@@ -29,6 +29,7 @@ import { useTranslation } from 'react-i18next';
import { cn } from '@/lib/utils';
import { Tip } from '@/components/ui/tooltip';
+import { AttentionDot } from '@/components/sidebar/AttentionDot';
import {
DropdownMenu,
DropdownMenuContent,
@@ -57,6 +58,7 @@ import { RemoteProjectIcon } from '../RemoteProjectIcon';
import { isDeviceLinkWriteBlocked } from '../../lib/remoteSessionWriteGuard';
import { projectBulkArchiveActionForStatus } from '../../lib/projectBulkArchiveAction';
import { getRemoteProjectMachineIdentity } from '../../lib/remoteProjectIdentity';
+import type { CollapsedProjectAttentionTone } from '../projectCollapsedAttention';
const log = createLogger('ProjectNode');
@@ -69,6 +71,8 @@ export interface ProjectNodeProps {
/** 当前会话状态筛选,决定项目菜单是批量归档还是批量恢复。 */
statusFilter: FilterStatus;
isCollapsed: boolean;
+ /** 折叠时汇总子任务的红/绿状态点;展开态由子任务行各自展示。 */
+ collapsedAttentionTone?: CollapsedProjectAttentionTone | null;
/** 父级 Projects 段整体收起时,也要让项目内「显示全部」在动画后复位。 */
parentSectionCollapsed: boolean;
activeSessionId?: string;
@@ -123,6 +127,7 @@ export function ProjectNode({
sessionVariant = 'text',
statusFilter,
isCollapsed,
+ collapsedAttentionTone = null,
parentSectionCollapsed,
activeSessionId,
runningSessionIds,
@@ -342,6 +347,9 @@ export function ProjectNode({
// (2026-08-12 用户裁决,与会话行的标题 + 远程图标同款)。
<span className="min-w-0 max-w-full shrink truncate">{project.displayName}</span>
)}
+ {!isEditingName && isCollapsed && collapsedAttentionTone ? (
+ <AttentionDot size={6} tone={collapsedAttentionTone} className="shrink-0" />
+ ) : null}
{!isEditingName && isDeviceLink ? (
<Tip text={remoteIdentity?.displayLabel ?? project.deviceLinkDeviceId ?? ''}>
<RemoteProjectIcon
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 024b64d39c..68a4f9cfa8 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
@@ -87,6 +87,7 @@ import type {
import type { Session } from '@/lib/ccAgent.types';
import type { FolderPickerOption } from '@/components/new-chat/FolderPickerPopover';
import type { SessionMoveTarget } from '../sessionMoveTarget';
+import { resolveCollapsedProjectAttentionTone } from '../projectCollapsedAttention';
/** 设备段折叠/对话组折叠共用的段 key:本机段 'local',远程段用 deviceId。 */
const deviceSectionKey = (deviceId: string | null) => deviceId ?? 'local';
@@ -318,6 +319,19 @@ export function ProjectsSection({
const attentionKinds = useSessionAttentionKinds();
const urgentSet = useSessionAttentionUrgencySet();
const remoteActivityRevision = useRemoteSessionActivityRevision();
+ const collapsedAttentionToneFor = useCallback(
+ (sessions: readonly Session[]) =>
+ resolveCollapsedProjectAttentionTone({
+ sessions,
+ runningSessionIds,
+ notifications,
+ attentionKinds,
+ urgentSessionIds: urgentSet,
+ remotePhaseOf: (sessionId) => getRemoteSessionActivity(sessionId)?.phase,
+ }),
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- remoteActivityRevision 代表 getRemoteSessionActivity 读到的整表内容
+ [runningSessionIds, notifications, attentionKinds, urgentSet, remoteActivityRevision],
+ );
// 正在看的任务 id:files 路由下回落到被浏览文件所属任务。
const viewedIdForSort = viewedSessionId ?? activeSessionId;
const priorityContext = useMemo(() => {
@@ -617,6 +631,9 @@ export function ProjectsSection({
project={project}
statusFilter={filter.status}
isCollapsed={collapsed.has(project.projectKey)}
+ collapsedAttentionTone={
+ collapsed.has(project.projectKey) ? collapsedAttentionToneFor(project.sessions) : null
+ }
parentSectionCollapsed={false}
activeSessionId={activeSessionId}
runningSessionIds={runningSessionIds}