Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(sidebar): 升级迁移时按旧布局树里停靠面板相对聊天区的边放置页签组
Dash508179ef5ecc
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/globalTabs.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/globalTabs.test.tsindex b929e61caf..77af2a665b 100644--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/globalTabs.test.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/globalTabs.test.ts@@ -259,4 +259,41 @@ describe('globalTabs', () => {reconcileGlobalPluginTabs(ghosts);expect(getGlobalTabs()).toHaveLength(2);});++ // 测试价值+ // - 生产入口与可观察结果:reconcileGlobalPluginTabs 读布局树里旧的 `ghost:<id>` 位置;可观察的是+ // 用户把停靠面板拖到聊天区右侧后,升级首次对齐落在右侧组而不是插件声明的默认左侧,没有旧位置的照默认边。+ // - Bug / 规则依据:PR #6468 review「迁移时保留用户自定义的面板位置」;存量插件兼容红线。+ // - 现有覆盖缺口:其余用例都没有布局桥,只覆盖默认边。+ // - 最小失败输入:默认布局(right-tabs 在聊天右侧)里插入 ghost:p0 到右侧,另一个插件不在树里。+ it('keeps a legacy docked panel on the side the user had moved it to', () => {+ const layout = {+ schemaVersion: 1,+ sidebar: { type: 'pane', id: 's', panelKind: 'session-list', edge: 'left' },+ content: {+ type: 'split',+ id: 'root',+ direction: 'row',+ children: [+ { fraction: 0.5, node: { type: 'pane', id: 'c', panelKind: 'chat-main' } },+ { fraction: 0.2, node: { type: 'pane', id: 'g', panelKind: 'ghost:p0' } },+ { fraction: 0.3, node: { type: 'pane', id: 'r', panelKind: 'right-tabs' } },+ ],+ },+ float: [],+ };+ const win = window as unknown as { electronAPI?: unknown };+ win.electronAPI = { layout: { getStateSync: () => ({ layout }) } };+ try {+ const ghosts = ['p0', 'p1'].map((id) => ({+ manifest: { id, name: id, panel: { html: 'p.html' } },+ enabled: true,+ })) as unknown as import('../../../../shared/ghost').InstalledGhost[];+ reconcileGlobalPluginTabs(ghosts);+ expect(getTabGroup('g_p0')).toBe('right');+ expect(getTabGroup('g_p1')).toBe('left');+ } finally {+ delete win.electronAPI;+ }+ });});diff --git a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.tsindex ff5e2f2593..cb950db055 100644--- a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts@@ -22,7 +22,8 @@import { useSyncExternalStore } from 'react';-import type { InstalledGhost } from '../../../shared/ghost';+import { ghostPanelKind, type InstalledGhost } from '../../../shared/ghost';+import { paneEdgeRelativeToChat, type Layout } from '../../../shared/layoutTree';import { installedGhostStoragePart } from '../../../shared/pluginIdentity';import { getDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';import { createLogger } from '@/lib/logger';@@ -459,6 +460,16 @@ function legacyMinimizedInstanceIds(): Set<string> {return out;}+/** 升级前该插件停靠面板在布局树里相对聊天区的边;树里没有 / 读不到返回 null。 */+function legacyPanelEdge(instanceId: string): TabGroupId | null {+ try {+ const layout = window.electronAPI?.layout?.getStateSync().layout as Layout | undefined;+ return layout ? paneEdgeRelativeToChat(layout, ghostPanelKind(instanceId)) : null;+ } catch {+ return null;+ }+}+/*** 与已装清单对齐(启动 + ghosts:changed):* - 已启用、声明停靠面板、未被用户关掉的插件 → 自动加页签(存量插件兼容:@@ -489,7 +500,8 @@ export function reconcileGlobalPluginTabs(ghosts: readonly InstalledGhost[]): vodismissed = [...dismissed, instanceId];continue;}- setTabGroup(tabId, defaultGroupForGhost(ghost, 'panel'));+ // 用户在旧布局里把它拖到过别处的,按旧位置迁(相对聊天区的那一边),没有再取默认边。+ setTabGroup(tabId, legacyPanelEdge(instanceId) ?? defaultGroupForGhost(ghost, 'panel'));placed = [...placed, instanceId];}// 自动出现的是停靠面板:显式记 panel,之后即使同时有 mainView 入口也不串页面。diff --git a/apps/desktop/src/shared/__tests__/layoutTree.test.ts b/apps/desktop/src/shared/__tests__/layoutTree.test.tsindex faac3bce37..f63b849329 100644--- a/apps/desktop/src/shared/__tests__/layoutTree.test.ts+++ b/apps/desktop/src/shared/__tests__/layoutTree.test.ts@@ -10,6 +10,7 @@ import {insertRootSplitPane,LAYOUT_SCHEMA_VERSION,MAX_TREE_DEPTH,+ paneEdgeRelativeToChat,removeRootSplitPaneByKind,setPaneCollapsed,setSplitChildFraction,@@ -645,3 +646,40 @@ describe('findSplitChildByPanelKind', () => {expect(findSplitChildByPanelKind(layout, 'session-list')).toBeNull();});});++// 测试价值+// - 生产入口与可观察结果:paneEdgeRelativeToChat;可观察的是升级前停靠在布局树里的 `ghost:<id>`+// 相对聊天区的边(左 / 右 / 上 / 下),以及树里没有该面板时返回 null。+// - Bug / 规则依据:PR #6468 review「存量停靠面板被用户拖到别处,升级后不能被重置」。+// - 现有覆盖缺口:新增函数。+// - 最小失败输入:chat 右侧插入的面板、chat 左侧插入的面板、chat 所在列里上 / 下的面板。+// - tier:unit(纯函数)。+describe('paneEdgeRelativeToChat', () => {+ it('derives the side of a legacy docked panel relative to chat-main', () => {+ const base = createDefaultLayout();+ const left = insertRootSplitPane(base, { id: 'g1', panelKind: 'ghost:a' }, { index: 0 });+ const right = insertRootSplitPane(base, { id: 'g2', panelKind: 'ghost:b' }, { index: 2 });+ expect(paneEdgeRelativeToChat(left.layout, 'ghost:a')).toBe('left');+ expect(paneEdgeRelativeToChat(right.layout, 'ghost:b')).toBe('right');+ expect(paneEdgeRelativeToChat(base, 'right-tabs')).toBe('right');+ expect(paneEdgeRelativeToChat(base, 'ghost:missing')).toBeNull();++ // 面板在聊天所在列的上 / 下:最近公共分割是纵向。+ const column = makeLayout((l) => {+ const root = l.content as SplitNode;+ const chat = root.children[0].node;+ root.children[0].node = {+ type: 'split',+ id: 'col',+ direction: 'column',+ children: [+ { fraction: 0.2, node: { type: 'pane', id: 'gt', panelKind: 'ghost:top' } },+ { fraction: 0.6, node: chat },+ { fraction: 0.2, node: { type: 'pane', id: 'gb', panelKind: 'ghost:bottom' } },+ ],+ };+ });+ expect(paneEdgeRelativeToChat(column, 'ghost:top')).toBe('top');+ expect(paneEdgeRelativeToChat(column, 'ghost:bottom')).toBe('bottom');+ });+});diff --git a/apps/desktop/src/shared/layoutTree.ts b/apps/desktop/src/shared/layoutTree.tsindex 7765eefe66..7f04c269ef 100644--- a/apps/desktop/src/shared/layoutTree.ts+++ b/apps/desktop/src/shared/layoutTree.ts@@ -517,6 +517,37 @@ export function isTabGroupId(value: unknown): value is TabGroupId {return typeof value === 'string' && (TAB_GROUP_IDS as readonly string[]).includes(value);}+/**+ * 某个 pane 相对聊天区(chat-main)在哪一边:取两者最近公共分割的方向与先后。+ * 用于把升级前停靠在布局树里的插件面板(`ghost:<id>`)迁成对应边的页签组。+ * 找不到 pane / chat-main,或两者不在同一棵分割树里,返回 null。+ */+export function paneEdgeRelativeToChat(layout: Layout, kind: PanelKind): TabGroupId | null {+ const pathTo = (+ node: LayoutNode,+ target: PanelKind,+ ): { split: SplitNode; index: number }[] | null => {+ if (node.type === 'pane') return node.panelKind === target ? [] : null;+ for (let i = 0; i < node.children.length; i++) {+ const rest = pathTo(node.children[i].node, target);+ if (rest) return [{ split: node, index: i }, ...rest];+ }+ return null;+ };+ const toPane = pathTo(layout.content, kind);+ const toChat = pathTo(layout.content, 'chat-main');+ if (!toPane || !toChat) return null;+ for (let depth = 0; depth < Math.min(toPane.length, toChat.length); depth++) {+ const a = toPane[depth];+ const b = toChat[depth];+ if (a.index === b.index) continue;+ const before = a.index < b.index;+ if (a.split.direction === 'row') return before ? 'left' : 'right';+ return before ? 'top' : 'bottom';+ }+ return null;+}+/** 页签组对应的 panelKind:右侧组 = `right-tabs`,其余 = `tab-group:<id>`。 */export function tabGroupPanelKind(groupId: TabGroupId): PanelKind {return groupId === 'right' ? 'right-tabs' : `${TAB_GROUP_KIND_PREFIX}${groupId}`;