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): 侧栏默认配置分老新——老用户保文字视图,新用户列表视图

Dash809112c1c7b4
diff --git a/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts b/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts
new file mode 100644
index 0000000000..9a1bc73e80
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts
@@ -0,0 +1,194 @@
+/**
+ * 侧边栏升级兼容性契约(2026-08-12 用户裁决)
+ * ---------------------------------------------------------------------------
+ * 目标:老用户升级后左侧任务列表**尽量不变**;新用户才吃新默认。
+ * - 分组默认老新一致:按项目 + 按设备 + 对话归组(用户明确要求不分老新)。
+ * - 排序默认按时间;任务信息默认只显示时间。
+ * - **显示模式是唯一按安装新旧分叉的项**:新装 'list',老装 'text'。
+ * 最难的一类是「从没动过显示模式的老用户」——localStorage 里没有 cardMode,
+ * 与全新安装无法直接区分,靠 sidebarInstallVintage 的旧版使用痕迹识别。
+ */
+
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import {
+ loadGroupBy,
+ loadGroupDevice,
+ loadGroupDialogue,
+ loadSortBy,
+ loadTaskInfoFields,
+ GROUP_DIALOGUE_KEY,
+} from '@/features/cc-agent/hooks/helpers/sidebarFilterCore';
+import {
+ getSidebarInstallVintage,
+ __testing as vintageTesting,
+} from '@/features/cc-agent/lib/sidebarInstallVintage';
+
+/* ------------ in-memory localStorage shim ------------ */
+
+function installMemoryLocalStorage(): Map<string, string> {
+ const store = new Map<string, string>();
+ const fakeStorage: Storage = {
+ get length() {
+ return store.size;
+ },
+ clear() {
+ store.clear();
+ },
+ getItem(key: string) {
+ return store.has(key) ? (store.get(key) as string) : null;
+ },
+ setItem(key: string, value: string) {
+ store.set(key, String(value));
+ },
+ removeItem(key: string) {
+ store.delete(key);
+ },
+ key(idx: number) {
+ return Array.from(store.keys())[idx] ?? null;
+ },
+ };
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (globalThis as any).localStorage = fakeStorage;
+ return store;
+}
+
+function uninstallLocalStorage(): void {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ delete (globalThis as any).localStorage;
+}
+
+/**
+ * 主列表显示模式的解析在模块级缓存了内存值,无法在同一进程里反复重置;
+ * 这里直接复刻 getSidebarMainViewMode 的判定顺序做契约测试(显式值 > 迁移 >
+ * 按安装新旧给默认),源码侧的接线由 sidebarUpgradeDefaults 的静态断言守住。
+ */
+function resolveMainViewMode(): 'text' | 'list' {
+ const explicit = localStorage.getItem('sidebar.mainListMode');
+ if (explicit === 'text' || explicit === 'list') return explicit;
+ const legacy = localStorage.getItem('sidebar.cardMode');
+ if (legacy === 'text' || legacy === 'false') return 'text';
+ if (legacy === 'card' || legacy === 'list' || legacy === 'true') return 'list';
+ return getSidebarInstallVintage() === 'legacy' ? 'text' : 'list';
+}
+
+describe('侧边栏升级兼容性:默认配置', () => {
+ beforeEach(() => {
+ installMemoryLocalStorage();
+ vintageTesting.resetMemo();
+ });
+ afterEach(() => {
+ uninstallLocalStorage();
+ vintageTesting.resetMemo();
+ });
+
+ it('新用户默认:项目 + 设备 + 对话三层分组,按时间排序,任务信息只显示时间', () => {
+ expect(loadGroupBy()).toBe('project');
+ expect(loadGroupDevice()).toBe(true);
+ expect(loadGroupDialogue()).toBe(true);
+ expect(loadSortBy()).toBe('recency');
+ expect(loadTaskInfoFields()).toEqual(['time']);
+ });
+
+ it('分组默认不分老新:老安装拿到同一套分组默认', () => {
+ localStorage.setItem('cc-agent.lastChatView.v1', '{"kind":"new"}');
+ expect(getSidebarInstallVintage()).toBe('legacy');
+ expect(loadGroupBy()).toBe('project');
+ expect(loadGroupDevice()).toBe(true);
+ expect(loadGroupDialogue()).toBe(true);
+ });
+
+ it('对话归组仍可显式关闭(默认翻转后 false 必须仍被尊重)', () => {
+ localStorage.setItem(GROUP_DIALOGUE_KEY, 'false');
+ expect(loadGroupDialogue()).toBe(false);
+ });
+});
+
+describe('sidebarInstallVintage:老安装识别', () => {
+ beforeEach(() => {
+ installMemoryLocalStorage();
+ vintageTesting.resetMemo();
+ });
+ afterEach(() => {
+ uninstallLocalStorage();
+ vintageTesting.resetMemo();
+ });
+
+ it('空 localStorage = 全新安装', () => {
+ expect(getSidebarInstallVintage()).toBe('fresh');
+ });
+
+ it.each(vintageTesting.LEGACY_USAGE_KEYS)('任一旧版使用痕迹即判为老安装:%s', (key) => {
+ localStorage.setItem(key, 'x');
+ expect(getSidebarInstallVintage()).toBe('legacy');
+ });
+
+ it('owner-scoped 后缀的痕迹同样命中(前缀匹配)', () => {
+ localStorage.setItem('cc-agent.sidebar.collapsedProjects:owner-1', '[]');
+ expect(getSidebarInstallVintage()).toBe('legacy');
+ });
+
+ it('判定固化后不再随新出现的痕迹翻转(避免默认值中途漂移)', () => {
+ expect(getSidebarInstallVintage()).toBe('fresh');
+ expect(localStorage.getItem(vintageTesting.INSTALL_VINTAGE_KEY)).toBe('fresh');
+ // 新用户用一阵后自然会写 lastChatView —— 不能因此变成「老用户」。
+ localStorage.setItem('cc-agent.lastChatView.v1', '{"kind":"new"}');
+ vintageTesting.resetMemo();
+ expect(getSidebarInstallVintage()).toBe('fresh');
+ });
+
+ it('localStorage 不可用时按 fresh 兜底,不抛错', () => {
+ uninstallLocalStorage();
+ expect(getSidebarInstallVintage()).toBe('fresh');
+ });
+});
+
+describe('显示模式:唯一按安装新旧分叉的默认', () => {
+ beforeEach(() => {
+ installMemoryLocalStorage();
+ vintageTesting.resetMemo();
+ });
+ afterEach(() => {
+ uninstallLocalStorage();
+ vintageTesting.resetMemo();
+ });
+
+ it('全新安装 → 列表视图', () => {
+ expect(resolveMainViewMode()).toBe('list');
+ });
+
+ it('从没动过显示模式的老用户 → 文字视图(本次兼容性的核心用例)', () => {
+ localStorage.setItem('cc-agent.lastChatView.v1', '{"kind":"new"}');
+ expect(resolveMainViewMode()).toBe('text');
+ });
+
+ it('老用户显式设过 cardMode:仍按旧值迁移,不受安装新旧影响', () => {
+ localStorage.setItem('cc-agent.lastChatView.v1', '{"kind":"new"}');
+ localStorage.setItem('sidebar.cardMode', 'card');
+ expect(resolveMainViewMode()).toBe('list');
+ });
+
+ it('显式设过主列表模式时,安装新旧不参与判定', () => {
+ localStorage.setItem('cc-agent.lastChatView.v1', '{"kind":"new"}');
+ localStorage.setItem('sidebar.mainListMode', 'list');
+ expect(resolveMainViewMode()).toBe('list');
+ });
+
+ // 上面的用例复刻了判定顺序(源码里的内存 SoT 无法在同进程反复重置),
+ // 这条静态断言保证源码确实按同一顺序接线,两者不脱钩。
+ it('源码接线:显式值 → cardMode 迁移 → 按安装新旧兜底', () => {
+ const source = readFileSync(resolve(__dirname, '..', 'hooks', 'useSidebarCardMode.ts'), 'utf8');
+ const explicitIdx = source.indexOf('parseMainMode(localStorage.getItem(MAIN_STORAGE_KEY))');
+ // 注意 'parseMode(' 是 'parseMainMode(' 的子串,必须带 const legacy = 前缀定位。
+ const legacyIdx = source.indexOf('const legacy = parseMode(localStorage.getItem(STORAGE_KEY))');
+ const vintageIdx = source.indexOf("getSidebarInstallVintage() === 'legacy'");
+ expect(explicitIdx).toBeGreaterThanOrEqual(0);
+ expect(legacyIdx).toBeGreaterThan(explicitIdx);
+ expect(vintageIdx).toBeGreaterThan(legacyIdx);
+ expect(source).toContain("return (mainMemoryValue = 'text')");
+ expect(source).toContain("const DEFAULT_MAIN_MODE: SidebarMainViewMode = 'list'");
+ });
+});
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.ts
index 6bdb993c06..ab1baa5905 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
@@ -290,16 +290,19 @@ export function persistGroupBy(groupBy: FilterGroupBy): void {
/**
* 「对话归为一组」开关(D 期):true = 无项目任务收进「对话」组;
- * false(默认,定稿)= 散排在主列表里与项目行混排。
+ * false = 散排在主列表里与项目行混排。
+ * **默认 true**(2026-08-12 用户裁决,推翻 D 期定稿的默认关):默认配置是
+ * 设备 + 项目 + 对话三层都分组。老用户与新用户同一套分组默认(用户明确要求),
+ * 差异只在显示模式(见 useSidebarCardMode)。
*/
export function loadGroupDialogue(): boolean {
const storage = safeStorage();
- if (!storage) return false;
+ if (!storage) return true;
try {
- return storage.getItem(GROUP_DIALOGUE_KEY) === 'true';
+ return storage.getItem(GROUP_DIALOGUE_KEY) !== 'false';
} catch (err) {
log.warn('[useSidebarFilter] failed to read groupDialogue:', err);
- return false;
+ return true;
}
}
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts b/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts
new file mode 100644
index 0000000000..cdfad6e1c5
--- /dev/null
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts
@@ -0,0 +1,109 @@
+/**
+ * sidebarInstallVintage —— 判定「这份安装是升级上来的老用户,还是全新安装」。
+ * ---------------------------------------------------------------------------
+ * 为什么需要:侧边栏重设计给新用户定了一套新默认(列表视图),但**老用户升级后
+ * 侧栏观感应尽量不变**(2026-08-12 用户裁决)。老用户里有一类最难办——从没动过
+ * 显示模式设置的人:他们的 `sidebar.cardMode` 是空的,与全新安装的用户在
+ * localStorage 上无法区分,若直接吃新默认就会升级后突然跳成列表视图。
+ *
+ * 判据:renderer 侧没有「安装时间 / 上次运行版本」这类现成信号(main 也没有持久化
+ * 版本号),因此用**一组只有用过旧版才会留下的 localStorage 痕迹**取并集来判定。
+ * 这些 key 全部在本次重设计之前就存在(见下方 LEGACY_USAGE_KEYS 的来源注释):
+ * - 只要用户在旧版里打开过会话 / 用过侧栏筛选 / 折叠过项目,就至少命中一个;
+ * - 全新安装在首帧读取时一个都不会有。
+ *
+ * 判定结果**一次性固化**到 INSTALL_VINTAGE_KEY:此后不再重新推断。原因是这些痕迹
+ * 会随用户使用自然出现(新用户用几分钟后也会写 lastChatView),不固化的话「新装」
+ * ��在某一刻悄悄变成「老用户」,默认值随之漂移——用户会看到侧栏莫名其妙换了样子。
+ * 固化后即使痕迹被清理(换账号 / 清缓存),判定也不再翻转。
+ *
+ * 边界:这是启发式,不是精确考古。误判的代价是有限且对称的——把老用户误判成新装
+ * (他清过缓存)会让他看到列表视图;把新装误判成老用户(极罕见)会让他看到文字
+ * 视图。两者都只是显示密度差异,用户在「整理侧边栏 → 显示」里一键可改,且改完就
+ * 落盘、此后与本模块无关。
+ */
+
+/** 固化判定结果;值为 'legacy' | 'fresh'。 */
+const INSTALL_VINTAGE_KEY = 'cc-agent.sidebar.installVintage.v1';
+
+/**
+ * 「用过旧版」的痕迹 key。全部早于侧边栏重设计存在,且都不需要用户主动改设置:
+ * - lastChatView / lastDocView:打开过任意会话 / 文件视图就写(最强信号)。
+ * - collapsedProjects / collapsedAutomationGroups:折叠过任意分组。
+ * - identityOwnerClaim:侧栏 owner-scoped 存储建账(登录后用过侧栏)。
+ * - pinnedSessionOrder / filter.projects / filter.manualProjectOrder:置顶拖拽、
+ * 项目筛选与手动排序(owner-scoped 前的历史裸 key,老安装才会有)。
+ * - sidebar.cardMode:显式改过显示模式(这类用户本就能被 cardMode 自身识别,
+ * 列在这里是为了让判定对「只改过显示模式」的人同样成立)。
+ * 注:owner-scoped 之后这些 key 会带 owner 后缀,故用前缀匹配而非全等。
+ */
+const LEGACY_USAGE_KEYS = [
+ 'cc-agent.lastChatView.v1',
+ 'cc-agent.lastDocView.v1',
+ 'cc-agent.sidebar.collapsedProjects',
+ 'cc-agent.sidebar.collapsedAutomationGroups',
+ 'cc-agent.sidebar.identityOwnerClaim.v1',
+ 'cc-agent.sidebar.pinnedSessionOrder',
+ 'cc-agent.sidebar.filter.projects',
+ 'cc-agent.sidebar.filter.manualProjectOrder',
+ 'sidebar.cardMode',
+] as const;
+
+export type SidebarInstallVintage = 'legacy' | 'fresh';
+
+/** 模块级缓存:同一次运行内判定只做一遍(读 localStorage 的 key 遍历不必重复)。 */
+let memoized: SidebarInstallVintage | null = null;
+
+function safeStorage(): Storage | null {
+ try {
+ return typeof localStorage === 'undefined' ? null : localStorage;
+ } catch {
+ return null;
+ }
+}
+
+function hasLegacyUsageTrace(storage: Storage): boolean {
+ // owner-scoped key 形如 `<base>::<ownerId>`,故按前缀匹配整张表。
+ for (let i = 0; i < storage.length; i += 1) {
+ const key = storage.key(i);
+ if (key == null) continue;
+ if (LEGACY_USAGE_KEYS.some((base) => key === base || key.startsWith(`${base}:`))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * 本安装是升级上来的老用户(legacy)还是全新安装(fresh)。
+ * 首次调用时推断并固化;此后直接读固化值。localStorage 不可用时按 fresh 处理
+ * (读不到痕迹也写不了标记,给新默认是更合理的兜底)。
+ */
+export function getSidebarInstallVintage(): SidebarInstallVintage {
+ if (memoized !== null) return memoized;
+ const storage = safeStorage();
+ if (!storage) return (memoized = 'fresh');
+
+ try {
+ const stored = storage.getItem(INSTALL_VINTAGE_KEY);
+ if (stored === 'legacy' || stored === 'fresh') return (memoized = stored);
+ } catch {
+ return (memoized = 'fresh');
+ }
+
+ const vintage: SidebarInstallVintage = hasLegacyUsageTrace(storage) ? 'legacy' : 'fresh';
+ try {
+ storage.setItem(INSTALL_VINTAGE_KEY, vintage);
+ } catch {
+ // 写不进去也不影响本次判定;下次启动会重新推断(痕迹只增不减,结论稳定)。
+ }
+ return (memoized = vintage);
+}
+
+export const __testing = {
+ INSTALL_VINTAGE_KEY,
+ LEGACY_USAGE_KEYS,
+ resetMemo(): void {
+ memoized = null;
+ },
+};
diff --git a/apps/desktop/src/renderer/hooks/useSidebarCardMode.ts b/apps/desktop/src/renderer/hooks/useSidebarCardMode.ts
index 8baf961727..04656a54e3 100644
--- a/apps/desktop/src/renderer/hooks/useSidebarCardMode.ts
+++ b/apps/desktop/src/renderer/hooks/useSidebarCardMode.ts
@@ -10,12 +10,16 @@
* ('true'→'card','false'→'text')。
* - 主列表新增 `sidebar.mainListMode`。首次读取(无值)时从置顶段旧值粗略迁移:
* text→text,card/list→list(主列表无 card 档;定稿:迁移不追求完美)。
+ * 两处都没有痕迹时按安装新旧给默认:新安装 'list',**老安装 'text'**——
+ * 老用户升级后侧栏观感不变(2026-08-12 用户裁决,见 sidebarInstallVintage)。
*
* 模块级内存值做跨实例 SoT;`storage` 事件做跨窗口同步(同 useNotificationSettings 模式)。
*/
import { useCallback, useEffect, useState } from 'react';
+import { getSidebarInstallVintage } from '@/features/cc-agent/lib/sidebarInstallVintage';
+
export type SidebarViewMode = 'text' | 'card' | 'list';
/** 主列表显示模式:无 card 档(卡片版仅置顶区支持)。 */
export type SidebarMainViewMode = 'text' | 'list';
@@ -58,7 +62,13 @@ export function getSidebarViewMode(): SidebarViewMode {
return DEFAULT_MODE;
}
-/** 同步读(主列表)。无存量值时从置顶段旧值粗略迁移(card→list)。 */
+/**
+ * 同步读(主列表)。优先级:显式设置 > 从置顶段旧值迁移 > 按安装新旧给默认。
+ *
+ * 最后一档是兼容性要求(2026-08-12 用户裁决):新用户默认列表视图,**老用户升级
+ * 后保持文字视图**——包括从没动过显示模式、localStorage 里没有 cardMode 的那批人
+ * (他们靠 sidebarInstallVintage 的使用痕迹识别)。
+ */
export function getSidebarMainViewMode(): SidebarMainViewMode {
if (mainMemoryValue !== null) return mainMemoryValue;
try {
@@ -68,6 +78,8 @@ export function getSidebarMainViewMode(): SidebarMainViewMode {
// 到主列表 list(宽行)。不回写 storage——迁移是纯读取推导,用户首次显式切换才落盘。
const legacy = parseMode(localStorage.getItem(STORAGE_KEY));
if (legacy) return (mainMemoryValue = legacy === 'text' ? 'text' : 'list');
+ // 没有任何显示模式痕迹:老安装沿用旧版观感(文字版),新安装用新默认(列表)。
+ if (getSidebarInstallVintage() === 'legacy') return (mainMemoryValue = 'text');
} catch {
// localStorage 不可用——退回默认(不落定内存,留待后续写入)。
}
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index f19634d561..863e4b8e2e 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -53,7 +53,7 @@
|---|---|---|
| 按项目分组 | **开** | 有项目的任务收进项目行;关闭则平铺、行尾带项目小标签 |
| 按设备分组 | **开** | 最外层按设备切段,分组头带在线状态、可折叠;**仅有远程设备连接时该选项才出现**(与顶部设备下拉同一出现条件);远程断开时选项消失、效果一并解除 |
-| 对话归为一组 | **关** | 无项目任务收进「对话」组(归属分类名,按 task-and-conversation-naming §2.3);关闭则散排。组头右侧有与项目行等位的新建入口 |
+| 对话归为一组 | **开** | 无项目任务收进「对话」组(归属分类名,按 task-and-conversation-naming §2.3);关闭则散排。组头右侧有与项目行等位的新建入口。(2026-08-12 用户裁决改默认开,原定稿为关) |
层级方向固定:设备 → 项目/对话组 → 任务。全关 = 纯平铺。
@@ -73,8 +73,31 @@
禁用该入口并复用远程写保护文案(被控端才是真正的创建方)。不按设备分组时没有归属
歧义,沿用原有的作用域推断(仅当作用域唯一指向一台远程机器时继承它)。
-**默认组合(定稿)**:按项目分组 + 按设备分组开、对话不归组——即项目行与
-散排对话按活动时间混排,这与手机版现状(#1303)一致。
+**默认组合(2026-08-12 用户裁决,推翻早前的「对话不归组」定稿)**:
+按项目分组 + 按设备分组 + 对话归为一组,三层都开。
+
+## 3.0 升级兼容性:老用户看到的样子尽量不变
+
+本版的硬要求是**老用户升级后左侧任务列表尽量不变**,新默认只作用于新用户。
+逐项账目:
+
+| 项 | 旧版 | 新默认 | 老用户升级后 |
+|---|---|---|---|
+| 按项目分组 | 有该设置,默认开 | 开 | 沿用旧值,无变化 |
+| 排序 | 有该设置,默认最近活动 | 按时间(即最近活动) | 沿用旧值;仅已删的「最早优先」回退默认 |
+| 任务信息 | 固定只显示时间 | 只显示时间 | 无变化 |
+| 按设备分组 | 无此功能 | 开 | **老新一致**(用户裁决:分组不分老新) |
+| 对话归为一组 | 对话是固定独立段 | 开 | **老新一致**(同上) |
+| 显示模式 | 整侧栏一份 `sidebar.cardMode`,默认文字版 | 列表版 | **按安装新旧分叉**:老装文字版,新装列表版 |
+
+显示模式是唯一分叉项。判定顺序:显式设过主列表模式 → 从 `cardMode` 迁移
+(text→文字,card/list→列表)→ 都没有时看安装新旧。最后一档解决「从没动过显示
+模式的老用户」——他们 `cardMode` 为空,与全新安装在 localStorage 上无法直接区分,
+由 `sidebarInstallVintage` 按一组**旧版使用痕迹**(打开过会话、折叠过分组、置顶
+拖拽等 key)判定,并把结论一次性固化,避免新用户用一阵后默认值悄悄漂移。
+
+对话段的形态变化(固定独立段 → 混排/可归组)靠配置回不去:旧的 `DialogueSection`
+固定段与 `DateGroupedSessionsSection` 已删除,这是本次重设计的核心,不提供回退。
### 3.2 排序方式 —— 单选