Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: address review — 插件面板按数据归属失效,不跨账号复用 webview
Chris3270cf8e0989
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPluginViewModel.test.ts b/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPluginViewModel.test.tsindex 53651856aa..08f2667248 100644--- a/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPluginViewModel.test.ts+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPluginViewModel.test.ts@@ -10,7 +10,9 @@ import type { PluginMarketItem } from '../../../shared/pluginMarket';import {filterGhostPluginItems,ghostFallbackIconKind,+ ghostPanelOwnerKey,marketPresentationForInstalledGhost,+ nextOpenPanelIdForOwner,sortGhostPluginItemsByRecentUse,toGhostPluginDetail,toGhostPluginListItem,@@ -273,3 +275,30 @@ describe('ghostPluginViewModel', () => {expect(detail).not.toHaveProperty('manifest');});});++describe('plugin panel owner isolation', () => {+ it('gives each data owner its own panel host key and stays stable within one', () => {+ const cloudA = ghostPanelOwnerKey('cloud', 'owner-a');+ const cloudB = ghostPanelOwnerKey('cloud', 'owner-b');+ const local = ghostPanelOwnerKey('local', null);++ // 账号 A 与 B 即便装了同 id / 同版本 / 同入口的插件,宿主 key 也必须不同——+ // 否则 React 复用同一 webview 实例,A 的 DOM 与内存态会留在 B 面前。+ expect(new Set([cloudA, cloudB, local]).size).toBe(3);+ // 同一身份内稳定,不会无谓重挂面板。+ expect(ghostPanelOwnerKey('cloud', 'owner-a')).toBe(cloudA);+ });++ it('closes an open panel when the data owner changes, keeps it otherwise', () => {+ const a = ghostPanelOwnerKey('cloud', 'owner-a');+ const b = ghostPanelOwnerKey('cloud', 'owner-b');++ // A 打开着面板 → 切到 B:必须关掉,不许因为 B 也装了同 id 的插件就留着。+ expect(nextOpenPanelIdForOwner(a, b, 'ghost-shared')).toBeNull();+ // 云 → 本地同样算换身份。+ expect(nextOpenPanelIdForOwner(a, ghostPanelOwnerKey('local', null), 'ghost-shared')).toBeNull();+ // 身份没变则原样保留(别把用户正在用的面板关掉)。+ expect(nextOpenPanelIdForOwner(a, a, 'ghost-shared')).toBe('ghost-shared');+ expect(nextOpenPanelIdForOwner(a, a, null)).toBeNull();+ });+});diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsxindex a8f69934f1..ba449d6d3f 100644--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx@@ -77,8 +77,10 @@ import {toGhostPluginDetail,toGhostPluginListItem,filterGhostPluginItems,+ ghostPanelOwnerKey,ghostPrimaryAction,marketPresentationForInstalledGhost,+ nextOpenPanelIdForOwner,sortGhostPluginItemsByRecentUse,type GhostPluginListItem,} from './lib/ghostPluginViewModel';@@ -573,6 +575,23 @@ export function GhostPluginPage() {useEffect(() => {if (openPanelId && !openPanelGhost) setOpenPanelId(null);}, [openPanelGhost, openPanelId]);+ /**+ * 账号 / 本地云模式切换必须关掉在开的面板。+ *+ * 光靠上面那条「解析不到就关」不够:两个账号装了**同 id、同版本、同入口**的+ * 插件时,openPanelGhost 在新身份下照样解析得到,面板宿主不会重挂载,于是+ * 账号 A 的 webview DOM、内存态与交互(表单、登录态、已加载数据)原样留在+ * 账号 B 面前。这里按 owner 键显式清空;首帧不清,免得把 ?panel= 深链刚设上的+ * 目标一并抹掉(那条 effect 排在本条之前)。+ */+ const panelOwnerKey = ghostPanelOwnerKey(mode, dataOwnerId);+ const panelOwnerKeyRef = useRef(panelOwnerKey);+ useEffect(() => {+ const previous = panelOwnerKeyRef.current;+ if (previous === panelOwnerKey) return;+ panelOwnerKeyRef.current = panelOwnerKey;+ setOpenPanelId((current) => nextOpenPanelIdForOwner(previous, panelOwnerKey, current));+ }, [panelOwnerKey]);const panelStatus = useMemo(() => {if (!selectedDetail || selectedDetail.panelMinWidth === null) return null;@@ -1096,7 +1115,13 @@ export function GhostPluginPage() {// 面板收束:aside 只挂在插件页语境里(列表/详情/市场详情共用),// 路由离开本页组件整体卸载 → webview 一并回收,绝不残留到别的界面。const panelAside = openPanelGhost ? (- <GhostPagePanelHost ghost={openPanelGhost} onClose={() => setOpenPanelId(null)} />+ // key 纳入 owner 代际:双保险。即便将来某条路径漏了上面的清空,换身份也会+ // 强制卸载重建宿主(webview 连同它的 DOM/内存态一起丢),不会跨账号复用。+ <GhostPagePanelHost+ key={`${panelOwnerKey}:${openPanelGhost.manifest.id}`}+ ghost={openPanelGhost}+ onClose={() => setOpenPanelId(null)}+ />) : null;if (marketDetail) {diff --git a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.tsindex e407b17668..d51d3e536b 100644--- a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts@@ -225,3 +225,30 @@ export function toGhostPluginDetail(installDir: ghost.dir,};}++/**+ * 插件页内面板宿主的数据归属键。+ *+ * 面板承载的是 webview,里面可能存着账号 A 的登录态、表单、已加载数据。+ * 两个账号装了**同 id、同版本、同入口**的插件时,只按 ghostId 做宿主 key+ * 会让 React 复用同一实例——切到账号 B 后 A 的 DOM 与内存态原样留着。+ * 所以 key 必须含 owner 代际:换身份即卸载重建。+ */+export function ghostPanelOwnerKey(+ mode: 'signed-out' | 'local' | 'cloud',+ dataOwnerId: string | null,+): string {+ return `${mode}:${dataOwnerId ?? ''}`;+}++/**+ * owner 变化时在开的面板应保留还是关闭。+ * 返回下一个 openPanelId:身份变了一律关(返回 null),没变则原样保留。+ */+export function nextOpenPanelIdForOwner(+ previousOwnerKey: string,+ nextOwnerKey: string,+ currentOpenPanelId: string | null,+): string | null {+ return previousOwnerKey === nextOwnerKey ? currentOpenPanelId : null;+}