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(sidebar): 为置顶入口补齐任务运行提示 (#7382)

xuzini-xzncd73325f7176
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/pinnedRunningActivity.test.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/pinnedRunningActivity.test.tsx
new file mode 100644
index 0000000000..0559d990eb
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/pinnedRunningActivity.test.tsx
@@ -0,0 +1,183 @@
+// @vitest-environment jsdom
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { ReactNode } from 'react';
+import type { Session } from '@/lib/ccAgent.types';
+import {
+ applyRemoteSessionActivity,
+ clearRemoteSessionActivity,
+} from '@/features/device-link/remoteSessionActivityStore';
+import { remoteProjectsStore } from '@/features/device-link/remoteProjectsStore';
+import {
+ getStartingSessionIds,
+ markSessionStarting,
+ resetSessionStartingStoreForTests,
+ useStartingSessionIds,
+} from '@/lib/sessionStartingStore';
+import {
+ PinnedSection,
+ type PinnedSectionProps,
+ type PinnedSidebarEntry,
+} from '../sections/PinnedSection';
+
+const view = vi.hoisted(() => ({ mode: 'text' }));
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+vi.mock('@/hooks/useReducedMotion', () => ({ useReducedMotion: () => false }));
+vi.mock('@/hooks/useSidebarCardMode', () => ({
+ useSidebarCardMode: () => ({ mode: view.mode, setMode: vi.fn() }),
+}));
+vi.mock('../SessionItem', () => ({ SessionItem: () => null }));
+vi.mock('../SessionCard', () => ({ SessionCard: () => null }));
+vi.mock('../CardMasonry', () => ({ CardMasonry: () => null }));
+vi.mock('@/components/sidebar/SortableList', () => ({ SortableList: () => null }));
+vi.mock('@/components/ui/tooltip', () => ({
+ Tip: ({ children }: { children: ReactNode }) => children,
+}));
+vi.mock('@/components/ui/dropdown-menu', () => ({
+ DropdownMenu: ({ children }: { children: ReactNode }) => children,
+ DropdownMenuTrigger: ({ children }: { children: ReactNode }) => children,
+ DropdownMenuContent: () => null,
+ DropdownMenuItem: () => null,
+}));
+
+const session = (id: string, deviceLinkDeviceId: string | null = null) =>
+ ({ id, deviceLinkDeviceId }) as Session;
+const entry = (s: Session): PinnedSidebarEntry => ({ kind: 'session', id: s.id, session: s });
+const props = (entries: PinnedSidebarEntry[], running: string[] = []): PinnedSectionProps => ({
+ entries,
+ allKnownProjects: [],
+ renderProject: () => null,
+ runningSessionIds: new Set(running),
+ attachedSessionIds: new Set(),
+ notifications: new Set(),
+ onSessionClick: vi.fn(),
+ onAction: vi.fn(),
+ onRename: vi.fn(),
+ onTogglePin: vi.fn(),
+ onReorder: vi.fn(),
+});
+const pin = (container: HTMLElement) => container.querySelector('svg.lucide-pin')?.parentElement;
+const isRunning = (container: HTMLElement) =>
+ pin(container)?.classList.contains('session-status-breathing');
+afterEach(() => {
+ cleanup();
+ clearRemoteSessionActivity();
+ resetSessionStartingStoreForTests();
+ remoteProjectsStore.__resetPinnedOriginsForTest();
+ view.mode = 'text';
+});
+
+describe('pinned section running indicator', () => {
+ it.each(['text', 'list', 'card'])('updates while expanded or collapsed in %s mode', (mode) => {
+ view.mode = mode;
+ const entries = [entry(session('pinned'))];
+ const { container, rerender } = render(<PinnedSection {...props(entries)} />);
+ expect(isRunning(container)).toBe(false);
+ rerender(<PinnedSection {...props(entries, ['other'])} />);
+ expect(isRunning(container)).toBe(false);
+ rerender(<PinnedSection {...props(entries, ['pinned'])} />);
+ expect(isRunning(container)).toBe(true);
+ expect(container.querySelector('svg.session-status-breathing')).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'ccAgent.sidebar.pinned' }));
+ expect(isRunning(container)).toBe(true);
+ rerender(<PinnedSection {...props(entries)} />);
+ expect(isRunning(container)).toBe(false);
+ expect(pin(container)?.getAttribute('aria-hidden')).toBe('true');
+ });
+
+ it('includes project children beyond the visible collapse limit', () => {
+ const children = Array.from({ length: 25 }, (_, i) => session(`child-${i}`));
+ const projectEntry = {
+ kind: 'project',
+ id: 'project',
+ project: { sessions: children },
+ displaySessions: children,
+ } as PinnedSidebarEntry;
+ const { container, rerender } = render(
+ <PinnedSection {...props([projectEntry], ['child-24'])} />,
+ );
+ expect(isRunning(container)).toBe(true);
+ rerender(<PinnedSection {...props([], ['child-24'])} />);
+ expect(container.innerHTML).toBe('');
+ });
+
+ it('tracks remote updates after collapse without confusing same-ID devices or local tasks', () => {
+ const entries = [entry(session('same', 'device-a'))];
+ const { container } = render(<PinnedSection {...props(entries, ['same'])} />);
+ expect(isRunning(container)).toBe(false);
+ fireEvent.click(screen.getByRole('button', { name: 'ccAgent.sidebar.pinned' }));
+ act(() => applyRemoteSessionActivity('device-b', { sessionId: 'same', phase: 'running' }));
+ expect(isRunning(container)).toBe(false);
+ act(() => applyRemoteSessionActivity('device-a', { sessionId: 'same', phase: 'running' }));
+ expect(isRunning(container)).toBe(true);
+ act(() =>
+ applyRemoteSessionActivity('device-a', { sessionId: 'same', phase: 'needs-interaction' }),
+ );
+ expect(isRunning(container)).toBe(false);
+ act(() => applyRemoteSessionActivity('device-a', { sessionId: 'same', phase: 'running' }));
+ expect(isRunning(container)).toBe(true);
+ act(() => clearRemoteSessionActivity());
+ expect(isRunning(container)).toBe(false);
+ });
+
+ it.each(['session', 'project'] as const)(
+ 'settles remote optimistic starting for a collapsed pinned %s',
+ (kind) => {
+ const task = session('optimistic', 'device-a');
+ remoteProjectsStore.pinSessionOrigin('device-a', task.id);
+ const entries: PinnedSidebarEntry[] =
+ kind === 'session'
+ ? [entry(task)]
+ : [
+ {
+ kind: 'project',
+ id: 'remote-project',
+ project: { sessions: [task] },
+ displaySessions: [task],
+ } as PinnedSidebarEntry,
+ ];
+ function StartingPinned() {
+ const starting = useStartingSessionIds();
+ return <PinnedSection {...props([...entries])} runningSessionIds={starting} />;
+ }
+ markSessionStarting(task.id);
+ const { container } = render(<StartingPinned />);
+ expect(isRunning(container)).toBe(true);
+ fireEvent.click(screen.getByRole('button', { name: 'ccAgent.sidebar.pinned' }));
+ act(() => applyRemoteSessionActivity('device-b', { sessionId: task.id, phase: 'running' }));
+ expect(getStartingSessionIds().has(task.id)).toBe(true);
+ act(() => applyRemoteSessionActivity('device-a', { sessionId: task.id, phase: 'running' }));
+ expect(getStartingSessionIds().has(task.id)).toBe(false);
+ expect(isRunning(container)).toBe(true);
+ act(() =>
+ applyRemoteSessionActivity('device-a', { sessionId: task.id, phase: 'needs-interaction' }),
+ );
+ expect(isRunning(container)).toBe(false);
+ // Answering an existing interaction must keep the new send's prelight.
+ act(() => markSessionStarting(task.id));
+ expect(isRunning(container)).toBe(true);
+ act(() =>
+ applyRemoteSessionActivity('device-b', { sessionId: 'unrelated', phase: 'running' }),
+ );
+ expect(isRunning(container)).toBe(true);
+ act(() => applyRemoteSessionActivity('device-a', { sessionId: task.id, phase: 'running' }));
+ expect(getStartingSessionIds().has(task.id)).toBe(false);
+ act(() =>
+ applyRemoteSessionActivity('device-a', {
+ sessionId: task.id,
+ phase: 'completed',
+ attention: true,
+ }),
+ );
+ expect(isRunning(container)).toBe(false);
+ // A new send discards the old terminal mirror and keeps its optimistic lamp.
+ act(() => markSessionStarting(task.id));
+ expect(isRunning(container)).toBe(true);
+ act(() =>
+ applyRemoteSessionActivity('device-a', { sessionId: task.id, phase: 'needs-interaction' }),
+ );
+ expect(getStartingSessionIds().has(task.id)).toBe(false);
+ expect(isRunning(container)).toBe(false);
+ },
+ );
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
index f9e5c0cf06..050c044d84 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
@@ -21,7 +21,7 @@
* 受控组件——entries 为空时返回 null(不渲染段)。
*/
-import { useCallback, useMemo, useState, type ReactNode } from 'react';
+import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
import {
AlignJustify,
ChevronDown,
@@ -29,6 +29,7 @@ import {
LayoutGrid,
LayoutList,
Check,
+ Pin,
type LucideIcon,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
@@ -55,6 +56,19 @@ import { buildSessionSourceLabelMap } from '../../lib/sessionSourceLabel';
import type { Session } from '@/lib/ccAgent.types';
import type { FolderPickerOption } from '@/components/new-chat/FolderPickerPopover';
import type { SessionMoveTarget } from '../sessionMoveTarget';
+import { aggregateSessionLamps } from '../../lib/sessionLampAggregation';
+import {
+ getRemoteSessionActivity,
+ isRemoteSessionActivityActive,
+ subscribeRemoteSessionActivity,
+ useRemoteSessionActivityRevision,
+} from '@/features/device-link/remoteSessionActivityStore';
+import { getSessionDeviceId } from '@/features/device-link/remoteProjectsStore';
+import { absorbSessionStarting } from '@/lib/sessionStartingStore';
+
+// This header consumes only running state; unread tones remain on task rows.
+const EMPTY_ATTENTION_KINDS = new Map<string, never>();
+const EMPTY_SESSION_IDS = new Set<string>();
const HEADER_HOVER_ACTION_CLASS = cn(
'pointer-events-none opacity-0 transition-opacity duration-150',
@@ -192,6 +206,44 @@ export function PinnedSection({
const [collapsed, setCollapsed] = useState(false);
const visibleEntries = entries;
+ // 聚合不受段级折叠影响;远程状态与 rail 入口复用同一设备隔离的灯语。
+ const remoteActivityRevision = useRemoteSessionActivityRevision();
+ const pinnedSessions = useMemo(
+ () =>
+ visibleEntries.flatMap((entry) =>
+ entry.kind === 'session' ? [entry.session] : entry.displaySessions,
+ ),
+ [visibleEntries],
+ );
+ // Pinned rows are absent from ProjectsSection's starting settlement.
+ // Settle only the activity being pushed, never an old waiting phase on rerender.
+ useEffect(
+ () =>
+ subscribeRemoteSessionActivity((deviceId, sessionId) => {
+ if (!deviceId || !sessionId || getSessionDeviceId(sessionId) !== deviceId) return;
+ if (
+ !pinnedSessions.some(
+ (session) => session.id === sessionId && session.deviceLinkDeviceId === deviceId,
+ )
+ )
+ return;
+ if (isRemoteSessionActivityActive(getRemoteSessionActivity(sessionId, deviceId))) {
+ absorbSessionStarting([sessionId]);
+ }
+ }),
+ [pinnedSessions],
+ );
+ const hasRunningSession = useMemo(
+ () =>
+ aggregateSessionLamps(pinnedSessions, {
+ runningSessionIds,
+ notifications: EMPTY_SESSION_IDS,
+ attentionKinds: EMPTY_ATTENTION_KINDS,
+ urgentSessionIds: EMPTY_SESSION_IDS,
+ }).running,
+ // revision tracks the shared aggregate's remote store reads.
+ [pinnedSessions, runningSessionIds, remoteActivityRevision],
+ );
const visibleSessions = useMemo(
() => visibleEntries.flatMap((entry) => (entry.kind === 'session' ? [entry.session] : [])),
[visibleEntries],
@@ -306,7 +358,18 @@ export function PinnedSection({
右侧固定的"显示样式"切换钮(justify-between 推到最右,与 DialogueSection
等对话列表段头的右侧动作同款 hover 行为)。cardMode 只影响菜单里的勾选项,
不改变段头文字样式或按钮位置。 */}
- <div className="group/sidebar-header flex h-6 items-center justify-between pr-3 pl-6">
+ <div className="group/sidebar-header relative flex h-6 items-center justify-between pr-3 pl-6">
+ <span
+ aria-hidden
+ className={cn(
+ 'absolute left-1.5 inline-flex shrink-0',
+ hasRunningSession
+ ? 'text-[var(--status-bar-accent)] session-status-breathing'
+ : 'text-[var(--sidebar-list-muted)]',
+ )}
+ >
+ <Pin size={13} strokeWidth={2} />
+ </span>
<div className="flex min-w-0 items-center gap-1">
{/* 段标题:与 项目/对话 段头同款,2026-07 用户定稿。 */}
<button