Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 新装不再被 owner claim 建账误判为老安装
Dash79e391c0835b
diff --git a/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts b/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.tsindex 2ff416468f..f5a3b9d6ba 100644--- a/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts+++ b/apps/desktop/src/renderer/__tests__/sidebarUpgradeDefaults.test.ts@@ -133,6 +133,47 @@ describe('sidebarInstallVintage:老安装识别', () => {expect(getSidebarInstallVintage()).toBe('legacy');});+ // 2026-08-13 review P1:claim key 由 sidebarOwnerStorage 在任何首次 owner-scoped+ // 读取时建账写入——全新安装首帧 useSidebarFilter(父组件)先跑,首次读显示模式+ // (子组件)在后。按「存在即痕迹」判会把所有新装误判成老装。+ it('新装首帧建账写入的 claim key(捕获值全 null)不构成旧版痕迹', () => {+ localStorage.setItem(+ vintageTesting.OWNER_CLAIM_KEY,+ JSON.stringify({+ version: 1,+ ownerId: 'owner-1',+ legacy: {+ schemaVersion: 1,+ values: {+ 'cc-agent.sidebar.filter.projects': null,+ 'cc-agent.sidebar.pinnedSessionOrder': null,+ },+ },+ }),+ );+ expect(getSidebarInstallVintage()).toBe('fresh');+ });++ it('claim 信封捕获到非空旧数据 = 老安装', () => {+ localStorage.setItem(+ vintageTesting.OWNER_CLAIM_KEY,+ JSON.stringify({+ version: 1,+ ownerId: 'owner-1',+ legacy: {+ schemaVersion: 1,+ values: { 'cc-agent.sidebar.filter.projects': '["/repo"]' },+ },+ }),+ );+ expect(getSidebarInstallVintage()).toBe('legacy');+ });++ it('bare 字符串形态的 claim(未发布中间版本的占位)= 老安装', () => {+ localStorage.setItem(vintageTesting.OWNER_CLAIM_KEY, 'owner-1');+ expect(getSidebarInstallVintage()).toBe('legacy');+ });+it('其它以痕迹键为前缀但非 owner-scoped 的键不误判', () => {localStorage.setItem('cc-agent.sidebar.collapsedProjectsSomethingElse', 'x');expect(getSidebarInstallVintage()).toBe('fresh');diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts b/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.tsindex 24cf58b696..1eccbe312d 100644--- a/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts+++ b/apps/desktop/src/renderer/features/cc-agent/lib/sidebarInstallVintage.ts@@ -30,26 +30,55 @@ 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 后缀(sidebarOwnerStorage 的格式是* `<base>.owner.<ownerId>`),故除全等外再做该前缀匹配。+ *+ * ⚠️ identityOwnerClaim **不在**本表(2026-08-13 review 修正):它由+ * sidebarOwnerStorage 在**任何**首次 owner-scoped 读取时建账写入——全新安装+ * 首帧 useSidebarFilter 就会触发,且发生在首次读显示模式之前。按「存在即痕迹」+ * 判会把所有新装都误判成老装,恰好打穿唯一的新老分叉(新装列表视图)。它只在+ * 信封里**捕获到非空旧数据**时才构成旧版证据,见 claimEnvelopeCapturedLegacyData。*/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;+/** sidebarOwnerStorage 的建账 key(格式见该模块;这里只读不写)。 */+const OWNER_CLAIM_KEY = 'cc-agent.sidebar.identityOwnerClaim.v1';++/**+ * claim 信封是否捕获到了非空旧数据。三种取值的判定:+ * - envelope JSON 且 legacy.values 有任一非 null → 建账那一刻裸根键还有真实+ * 旧数据 = 老安装;全 null = 建账时一无所有 = 新装建的账,不算痕迹。+ * - bare 字符串(非 JSON):未发布中间版本写的占位——能出现就说明装过旧版本,+ * 算老安装。+ * - 解析异常 → 不算痕迹(证据不明时倾向 fresh:误给新默认的代价是显示密度+ * 差异,一键可改;误判成 legacy 则新装永远拿不到新默认)。+ */+function claimEnvelopeCapturedLegacyData(raw: string): boolean {+ try {+ const parsed: unknown = JSON.parse(raw);+ if (typeof parsed !== 'object' || parsed === null) return true; // bare 标记经 JSON.parse 成功仅当是字面量,视同旧版占位+ const values = (parsed as { legacy?: { values?: Record<string, unknown> } }).legacy?.values;+ if (values == null || typeof values !== 'object') return false;+ return Object.values(values).some((value) => value != null);+ } catch {+ // 非 JSON = bare ownerId 字符串(未发布中间版本的占位)→ 装过旧版本。+ return true;+ }+}+export type SidebarInstallVintage = 'legacy' | 'fresh';/** 模块级缓存:同一次运行内判定只做一遍(读 localStorage 的 key 遍历不必重复)。 */@@ -75,6 +104,13 @@ function hasLegacyUsageTrace(storage: Storage): boolean {return true;}}+ // claim key 单独判(不看存在、只看内容),原因见 LEGACY_USAGE_KEYS 头注。+ try {+ const claim = storage.getItem(OWNER_CLAIM_KEY);+ if (claim != null && claimEnvelopeCapturedLegacyData(claim)) return true;+ } catch {+ // 读不到按无痕迹处理。+ }return false;}@@ -107,6 +143,7 @@ export function getSidebarInstallVintage(): SidebarInstallVintage {export const __testing = {INSTALL_VINTAGE_KEY,LEGACY_USAGE_KEYS,+ OWNER_CLAIM_KEY,resetMemo(): void {memoized = null;},