Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(sidebar): 记住置顶与首页分组的收起状态
Dash41de1ef30beb
diff --git a/apps/desktop/src/renderer/__tests__/useSidebarFilter.test.ts b/apps/desktop/src/renderer/__tests__/useSidebarFilter.test.tsindex 19b5781bde..741928c84b 100644--- a/apps/desktop/src/renderer/__tests__/useSidebarFilter.test.ts+++ b/apps/desktop/src/renderer/__tests__/useSidebarFilter.test.ts@@ -43,6 +43,8 @@ import {loadManualProjectOrder,loadDialogueGroupCollapsedKeys,persistDialogueGroupCollapsedKeys,+ loadPinnedSectionCollapsed,+ persistPinnedSectionCollapsed,persistStatus,persistProjects,persistGroupBy,@@ -464,6 +466,19 @@ describe('dialogueGroupCollapsedKeys(对话组按分组 key 独立折叠)',});});+describe('pinnedSectionCollapsed(置顶段收起跨重启保留)', () => {+ beforeEach(() => installMemoryLocalStorage());+ afterEach(() => uninstallLocalStorage());++ it('defaults to expanded and restores the last toggle', () => {+ expect(loadPinnedSectionCollapsed()).toBe(false);+ persistPinnedSectionCollapsed(true);+ expect(loadPinnedSectionCollapsed()).toBe(true);+ persistPinnedSectionCollapsed(false);+ expect(loadPinnedSectionCollapsed()).toBe(false);+ });+});+describe('loadManualProjectOrder', () => {beforeEach(() => installMemoryLocalStorage());afterEach(() => uninstallLocalStorage());diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.tsindex c625f19c3a..26921f26d7 100644--- a/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts@@ -38,6 +38,7 @@ export const GROUP_DIALOGUE_KEY = 'cc-agent.sidebar.filter.groupDialogue';export const GROUP_DEVICE_KEY = 'cc-agent.sidebar.filter.groupDevice';export const DEVICE_GROUP_COLLAPSED_KEY = 'cc-agent.sidebar.deviceGroupCollapsed';export const DIALOGUE_GROUP_COLLAPSED_KEY = 'cc-agent.sidebar.dialogueGroupCollapsed';+export const PINNED_SECTION_COLLAPSED_KEY = 'cc-agent.sidebar.pinnedSectionCollapsed';/** 单一混排列表(未按设备切段)里唯一对话组的折叠状态 key。 */export const DIALOGUE_GROUP_ALL_KEY = 'all';export const LAST_ACTIVITY_KEY = 'cc-agent.sidebar.filter.lastActivity';@@ -486,6 +487,31 @@ export function persistDialogueGroupCollapsedKeys(keys: ReadonlySet<string>): vo}}+/* ==================== pinned section collapsed load/persist ==================== */++/** 置顶段整段收起,与设备段、对话组同属本地显示偏好,默认展开。 */+export function loadPinnedSectionCollapsed(): boolean {+ const storage = safeStorage();+ if (!storage) return false;+ try {+ return storage.getItem(PINNED_SECTION_COLLAPSED_KEY) === 'true';+ } catch (err) {+ log.warn('[useSidebarFilter] failed to read pinnedSectionCollapsed:', err);+ return false;+ }+}++export function persistPinnedSectionCollapsed(collapsed: boolean): void {+ const storage = safeStorage();+ if (!storage) return;+ try {+ if (collapsed) storage.setItem(PINNED_SECTION_COLLAPSED_KEY, 'true');+ else storage.removeItem(PINNED_SECTION_COLLAPSED_KEY);+ } catch (err) {+ log.warn('[useSidebarFilter] failed to persist pinnedSectionCollapsed:', err);+ }+}+/* ============================== lastActivity load/persist ============================== */const LAST_ACTIVITY_VALUES: ReadonlySet<string> = new Set<FilterLastActivity>([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.tsxindex 6252cd638f..9adf262bea 100644--- 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@@ -65,6 +65,8 @@ afterEach(() => {resetSessionStartingStoreForTests();remoteProjectsStore.__resetPinnedOriginsForTest();view.mode = 'text';+ // The section's collapse is remembered; each case starts expanded.+ localStorage.clear();});describe('pinned section running indicator', () => {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.tsxindex 374ee15289..db2dc81ca0 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@@ -57,6 +57,10 @@ 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 {+ loadPinnedSectionCollapsed,+ persistPinnedSectionCollapsed,+} from '../../hooks/helpers/sidebarFilterCore';import {getRemoteSessionActivity,isRemoteSessionActivityActive,@@ -203,7 +207,12 @@ export function PinnedSection({const { mode, setMode } = useSidebarCardMode();// 段头 trigger 的图标 = 当前选中的显示模式(用户一眼看出现在是哪种)。const ViewStyleTriggerIcon = viewStyleIcon(mode);- const [collapsed, setCollapsed] = useState(false);+ const [collapsed, setCollapsed] = useState(loadPinnedSectionCollapsed);+ const toggleCollapsed = useCallback(() => {+ const next = !collapsed;+ setCollapsed(next);+ persistPinnedSectionCollapsed(next);+ }, [collapsed]);const visibleEntries = entries;// 聚合不受段级折叠影响;远程状态与 rail 入口复用同一设备隔离的灯语。@@ -374,7 +383,7 @@ export function PinnedSection({{/* 段标题:与 项目/对话 段头同款,2026-07 用户定稿。 */}<buttontype="button"- onClick={() => setCollapsed((value) => !value)}+ onClick={toggleCollapsed}aria-expanded={!collapsed}className="text-sm leading-5 font-medium text-[var(--sidebar-list-muted)] transition-colors hover:text-[var(--sidebar-nav-text)]">@@ -384,7 +393,7 @@ export function PinnedSection({<Tip text={toggleLabel} side="bottom"><buttontype="button"- onClick={() => setCollapsed((value) => !value)}+ onClick={toggleCollapsed}aria-label={toggleLabel}aria-expanded={!collapsed}className={cn(diff --git a/apps/mobile/src/__tests__/homeViewPreferenceStore.test.ts b/apps/mobile/src/__tests__/homeViewPreferenceStore.test.tsindex 8811338421..72e1a24548 100644--- a/apps/mobile/src/__tests__/homeViewPreferenceStore.test.ts+++ b/apps/mobile/src/__tests__/homeViewPreferenceStore.test.ts@@ -216,6 +216,19 @@ describe('homeViewPreferenceStore', () => {});});+ it('keeps group collapse per account, merges patches, and bounds stored keys', async () => {+ const { readHomeCollapsePreferences, saveHomeCollapsePreferences } = await import('@/session/homeViewPreferenceStore');+ await saveHomeCollapsePreferences(OWNER, { pinnedCollapsed: true, collapsedProjectKeys: ['dev:/a'] });+ await saveHomeCollapsePreferences(OWNER, { expandedAutomationGroups: ['auto-1'] });+ await expect(readHomeCollapsePreferences(OWNER)).resolves.toEqual({+ pinnedCollapsed: true, collapsedProjectKeys: ['dev:/a'], expandedAutomationGroups: ['auto-1'],+ });+ await expect(readHomeCollapsePreferences('another-owner')).resolves.toEqual({});+ const keys = Array.from({ length: 250 }, (_, index) => `dev:/p${index}`);+ await saveHomeCollapsePreferences(OWNER, { collapsedProjectKeys: keys });+ expect((await readHomeCollapsePreferences(OWNER)).collapsedProjectKeys).toEqual(keys.slice(-200));+ });+it('keeps old-blob defaults: project on, dialogue group off, time sort, active', async () => {const { __testing, readHomeViewPreferences } =await import('@/session/homeViewPreferenceStore');diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsxindex 48f41083b2..868e7c233e 100644--- a/apps/mobile/src/session/HomeSurface.tsx+++ b/apps/mobile/src/session/HomeSurface.tsx@@ -237,8 +237,11 @@ import {type HomeSection,} from '@/session/homeSections';import {+ readHomeCollapsePreferences,readHomeViewPreferences,+ saveHomeCollapsePreferences,saveHomeViewPreferences as persistHomeViewPreferences,+ type HomeCollapsePreferences,type HomeViewPreferencePatch,type HomeViewPreferences,} from '@/session/homeViewPreferenceStore';@@ -476,7 +479,6 @@ export function MobileHome(props: MobileHomeProps) {function HomeScreenContent({ active = true, width, newSessionInSystemBar = false, newSessionInHeader = false, onSelectSession, runNavigation, newSessionActionRef }: MobileHomeProps) {const ownedSharedTasks = useSharedTasks();- const [sharedCollapsed, setSharedCollapsed] = useState(false);// The retained page and its visible sidebar must never release each other's subscriptions.const HOME_LIST_SUBSCRIPTION_OWNER = `device-list:${useId()}`;const embedded = width !== undefined;@@ -518,6 +520,14 @@ function HomeScreenContent({ active = true, width, newSessionInSystemBar = false}});}, [t]);+ // 分组收起/展开按账号落盘;写失败只意味着下次启动显示旧状态,不打断操作。+ // 「已手动操作」记在视图会话上,常驻首页与侧栏两个实例共用,迟到的恢复不覆盖。+ const saveHomeCollapse = useCallback((patch: HomeCollapsePreferences) => {+ viewSession.write('collapseTouched', true);+ void saveHomeCollapsePreferences(preferenceOwnerRef.current, patch).catch(() => undefined);+ }, [viewSession]);+ const [sharedCollapsed, setSharedCollapsed] = useRetainedHomeState(viewSession, 'sharedCollapsed', false,+ (next) => saveHomeCollapse({ sharedCollapsed: next }));// 所有前进导航(进会话 / 新建 / 设置 / 组页面)统一走守卫 push:列表卡顿时的// 连点会各自触发一次裸 push,把同一页压进栈 N 层(返回也要 N 次)。const push = useGuardedPush();@@ -722,10 +732,13 @@ function HomeScreenContent({ active = true, width, newSessionInSystemBar = falseconst requestedListFilter = active ? remoteListStatusFilter(statusFilter) : 'active';const homeListFilterRef = useRef(requestedListFilter);const homeListFilterChanged = homeListFilterRef.current !== requestedListFilter;- const [collapsedProjectKeys, setCollapsedProjectKeys] = useRetainedHomeState<string[]>(viewSession, 'collapsedProjectKeys', []);- const [pinnedCollapsed, setPinnedCollapsed] = useRetainedHomeState(viewSession, 'pinnedCollapsed', false);+ const [collapsedProjectKeys, setCollapsedProjectKeys] = useRetainedHomeState<string[]>(viewSession, 'collapsedProjectKeys', [],+ (next) => saveHomeCollapse({ collapsedProjectKeys: next }));+ const [pinnedCollapsed, setPinnedCollapsed] = useRetainedHomeState(viewSession, 'pinnedCollapsed', false,+ (next) => saveHomeCollapse({ pinnedCollapsed: next }));// 已展开的自动化组 key(页面级 state:SectionList 虚拟化回收行组件时展开态不丢)。- const [expandedAutomationGroups, setExpandedAutomationGroups] = useRetainedHomeState<string[]>(viewSession, 'expandedAutomationGroups', []);+ const [expandedAutomationGroups, setExpandedAutomationGroups] = useRetainedHomeState<string[]>(viewSession, 'expandedAutomationGroups', [],+ (next) => saveHomeCollapse({ expandedAutomationGroups: next }));const [rawDeviceConnectionStates, setDeviceConnectionStates] = useState<Record<string, HomeDeviceConnectionState>>({});// 熔断 open(电脑端未响应)的设备复用既有 failed 渲染路径(红圈),不新增视觉:// 内部态映射覆盖在 hydrate 状态之上,熔断关闭后自动回落到原状态。@@ -1427,17 +1440,25 @@ function HomeScreenContent({ active = true, width, newSessionInSystemBar = falseuseEffect(() => {const expectedAccountGeneration = homeAccountGenerationRef.current;let cancelled = false;- const read = startBoundedStartupRead<HomeViewPreferences | null>(- readHomeViewPreferences(preferenceOwnerRef.current),+ const read = startBoundedStartupRead<[HomeViewPreferences, HomeCollapsePreferences] | null>(+ Promise.all([+ readHomeViewPreferences(preferenceOwnerRef.current),+ // 收起状态读不出来只回到全部展开,不连累显示偏好的恢复。+ readHomeCollapsePreferences(preferenceOwnerRef.current).catch((): HomeCollapsePreferences => ({})),+ ]),null,);- const applyPreferences = (preferences: HomeViewPreferences | null) => {- if (!preferences || restoredView) return;- if (- cancelled- || homeAccountGenerationRef.current !== expectedAccountGeneration- || viewPrefsTouchedRef.current- ) return;+ const applyPreferences = (stored: [HomeViewPreferences, HomeCollapsePreferences] | null) => {+ if (!stored || restoredView) return;+ if (cancelled || homeAccountGenerationRef.current !== expectedAccountGeneration) return;+ const [preferences, collapse] = stored;+ // 直接写入视图会话:恢复出来的值不需要再落盘一次。+ if (!viewSession.has('collapseTouched')) {+ for (const key of ['pinnedCollapsed', 'sharedCollapsed', 'collapsedProjectKeys', 'expandedAutomationGroups'] as const) {+ if (collapse[key] !== undefined) viewSession.write(key, collapse[key]);+ }+ }+ if (viewPrefsTouchedRef.current) return;setGroupByProject(preferences.groupByProject);setGroupDialogue(preferences.groupDialogue);setSortBy(preferences.sortBy);diff --git a/apps/mobile/src/session/homeViewPreferenceStore.ts b/apps/mobile/src/session/homeViewPreferenceStore.tsindex 03c6977d91..8e3c46de20 100644--- a/apps/mobile/src/session/homeViewPreferenceStore.ts+++ b/apps/mobile/src/session/homeViewPreferenceStore.ts@@ -303,7 +303,50 @@ export function saveHomeNavigationPreferences(return next;}+/** Task-home group disclosure. Keys carry device and path, so the record belongs to one account. */+export interface HomeCollapsePreferences {+ pinnedCollapsed?: boolean;+ sharedCollapsed?: boolean;+ collapsedProjectKeys?: string[];+ expandedAutomationGroups?: string[];+}+const COLLAPSE_PREFIX = 'cindy.mobile.home.collapse.v1.';+/** Removed projects never toggle again; keep the most recent choices instead of a GC pass. */+const COLLAPSE_KEY_LIMIT = 200;++function normalizeHomeCollapsePreferences(value: unknown): HomeCollapsePreferences {+ const record = readRecord(value);+ if (!record) return {};+ const next: HomeCollapsePreferences = {};+ for (const field of ['pinnedCollapsed', 'sharedCollapsed'] as const) {+ if (typeof record[field] === 'boolean') next[field] = record[field];+ }+ for (const field of ['collapsedProjectKeys', 'expandedAutomationGroups'] as const) {+ if (Array.isArray(record[field])) next[field] = readStringList(record[field]).slice(-COLLAPSE_KEY_LIMIT);+ }+ return next;+}++export async function readHomeCollapsePreferences(owner: string): Promise<HomeCollapsePreferences> {+ if (!owner) return {};+ const raw = await AsyncStorage.getItem(COLLAPSE_PREFIX + encodeURIComponent(owner));+ if (!raw) return {};+ try { return normalizeHomeCollapsePreferences(JSON.parse(raw)); } catch { return {}; }+}++export function saveHomeCollapsePreferences(owner: string, patch: HomeCollapsePreferences): Promise<void> {+ if (!owner) return Promise.resolve();+ const next = writeChain.then(async () => {+ const current = await readHomeCollapsePreferences(owner);+ const merged = normalizeHomeCollapsePreferences({ ...current, ...patch });+ await AsyncStorage.setItem(COLLAPSE_PREFIX + encodeURIComponent(owner), JSON.stringify(merged));+ });+ writeChain = next.catch(() => undefined);+ return next;+}+export const __testing = {storageKey: STORAGE_KEY,navigationPrefix: NAVIGATION_PREFIX,+ collapsePrefix: COLLAPSE_PREFIX,};diff --git a/apps/mobile/src/session/homeViewSession.ts b/apps/mobile/src/session/homeViewSession.tsindex 3e38319521..ba2610ee45 100644--- a/apps/mobile/src/session/homeViewSession.ts+++ b/apps/mobile/src/session/homeViewSession.ts@@ -37,8 +37,14 @@ export function getHomeViewSession(): HomeViewSession {}/** Retain committed interactions synchronously, before navigation can mount Home elsewhere. */-export function useRetainedHomeState<T>(session: HomeViewSession | undefined, key: string, initial: T | (() => T)):- [T, Dispatch<SetStateAction<T>>] {+export function useRetainedHomeState<T>(+ session: HomeViewSession | undefined,+ key: string,+ initial: T | (() => T),+ onCommit?: (next: T) => void,+): [T, Dispatch<SetStateAction<T>>] {+ const commitRef = useRef(onCommit);+ commitRef.current = onCommit;const [localValue, setValue] = useState<T>(() => session? session.read(key, initial): typeof initial === 'function' ? (initial as () => T)() : initial);@@ -54,6 +60,7 @@ export function useRetainedHomeState<T>(session: HomeViewSession | undefined, kelatest.current = next;session?.write(key, next);setValue(next);+ commitRef.current?.(next);}, [session, key]);return [value, update];}