Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): add sidebar restore entry for plugin panels
DavidShen9f675d622b4d
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.tsindex f14612e90d..c8eb688065 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts@@ -1615,7 +1615,7 @@ describe('FORGE_GUIDE', () => {'撑满内容区','在独立窗口中打开','minimize',- '最小化为浮动气泡',+ '最小化面板',// 2026-07-25 skill 槽:随包捆绑 Agent Skills,声明一致性 + 全局作用域披露。// 卡槽总数标记随 ios-simulator 槽合入更新为十八个。'十八个卡槽',diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.tsindex 9aece04ba2..bcecc6b768 100644--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@ -1436,7 +1436,8 @@ my-ghost/// top/bottom 暂未支持(排期中)// panel.systemButtons(可选,仅停靠形态):标准头系统按钮开关,缺省全开、// 声明 false 逐个关闭。当前一批:maximize(撑满内容区)、detach(在独立- // 窗口中打开)、minimize(最小化为浮动气泡)。标题条本体恒由主机绘制、+ // 窗口中打开)、minimize(最小化面板;恢复入口由用户偏好决定为浮动气泡或+ // 左侧栏)。标题条本体恒由主机绘制、// 关不掉;未知键拒装;position:"tab" 时声明本字段拒装"settingsHtml": "settings.html", // 可选:设置页「自定义设置区」自绘界面(见 §4.8;声明了用户填的凭证时仍必填,用于长期管理/替换/清除;调用前缺失时主机也会在统一 Setup 卡内联收单,见 §4.7)"settingsHeight": 360 // 可选:固定高度 px(160–800);缺省 = 随内容自适应(矮内容真收矮,高至 800);内容会动态增减时才声明,避免抖动@@ -3848,9 +3849,9 @@ const opened = await cindy.iosSimulator.request({自己持久化(见 §4.6 的偏好存储);- 停靠形态的**标题条(标准头)由主机绘制**:标题(\`panel.title\`)+ 一批系统按钮(当前:「撑满内容区」、「在独立窗口中打开」——用户可把你的面板抽进- 自己的 OS 窗口,关窗/合并即回停靠原位——以及「最小化为浮动气泡」——用户- 可把面板收成一枚可拖动的圆形气泡悬浮在主窗最上层,点击气泡即回停靠原位,- 气泡位置与最小化状态重启保留;三者面板代码全程零感知;后续新增的系统按钮+ 自己的 OS 窗口,关窗/合并即回停靠原位——以及「最小化面板」——用户选择的+ 恢复入口可能是一枚悬浮在主窗最上层的可拖动圆形气泡,也可能是左侧栏入口;+ 最小化状态重启保留;三者面板代码全程零感知;后续新增的系统按钮也长在这里)。你的 panel.html 只画标题条以下的部分,**不要自己再画一条标题栏**。不想要某颗系统按钮时在身份卡声明\`"systemButtons": { "maximize": false, "detach": false, "minimize": false }\`diff --git a/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts b/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.tsindex 6705e21749..74fccc6c3d 100644--- a/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts@@ -363,7 +363,7 @@ describe('setDetached', () => {});describe('native minimize', () => {- it('routes native minimize to the renderer bubble action', () => {+ it('routes native minimize to the renderer panel-minimize action', () => {const h = makeHarness(new Set(['a']));h.controller.setDetached('a', true);const win = h.created[0].win;diff --git a/apps/desktop/src/main/ghost-panel-window/controller.ts b/apps/desktop/src/main/ghost-panel-window/controller.tsindex 273e5abce8..3460675ace 100644--- a/apps/desktop/src/main/ghost-panel-window/controller.ts+++ b/apps/desktop/src/main/ghost-panel-window/controller.ts@@ -339,7 +339,7 @@ export class GhostPanelWindowsController {});win.on('minimize', () => {if (slot.destroyingWindow || this.disposed) return;- // 原生标题栏(macOS 黄灯)与系统级最小化入口也必须复用 Ghost 气泡语义。+ // 原生标题栏(macOS 黄灯)与系统级最小化入口也必须复用插件面板最小化语义。// 先恢复,避免在 renderer 完成 setDetached(false) 前短暂留在 Dock/任务栏。if (win.isMinimized()) win.restore();this.deps.sendToWindow(win, GHOST_PANEL_WINDOW_MINIMIZE_REQUESTED_CHANNEL, undefined);diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.tsindex eefb1ec5c9..e271726131 100644--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts@@ -49,7 +49,7 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不it('SidebarTopNav 不再渲染 MachineSwitcherMenu(2026-08-13 并入段头标题)', () => {expect(topNavSource).not.toContain("from '@/features/cc-agent/sidebar/MachineSwitcherMenu'");expect(topNavSource).not.toContain('<MachineSwitcherMenu />');- // 搜索行仍在(顶部导航收敛为 新建 / 自动任务 / 插件 / 搜索 四行)。+ // 搜索行仍在;最小化面板存在且选用侧栏模式时,恢复入口插在插件与搜索之间。expect(topNavSource).toContain('<SidebarInlineSearch');});@@ -67,7 +67,7 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不expect(topNavSource).toContain("const showPinned = section !== 'scrollable'");expect(topNavSource).toContain("const showScrollable = section !== 'pinned'");- // Shell:接管时只画固定段,否则整块五行(插件页等无长列表的视图)。+ // Shell:接管时只画固定段,否则整块常驻行(插件页等无长列表的视图)。expect(sidebarShellSource).toContain("<SidebarTopNav section={ownsTopNavScrollableRows ? 'pinned' : 'all'} />",);@@ -115,6 +115,25 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不expect(featureContextSource).toContain('export function useOwnsTopNavScrollableRows');});+ it('插件面板恢复入口在展开态和 rail 态都位于插件与搜索之间', () => {+ const expandedPluginsIdx = topNavSource.indexOf('{pluginsRow}');+ const expandedRestoreIdx = topNavSource.indexOf('{restoreRow}', expandedPluginsIdx);+ const expandedSearchIdx = topNavSource.indexOf('{searchRow}', expandedRestoreIdx);+ expect(expandedPluginsIdx).toBeGreaterThanOrEqual(0);+ expect(expandedRestoreIdx).toBeGreaterThan(expandedPluginsIdx);+ expect(expandedSearchIdx).toBeGreaterThan(expandedRestoreIdx);++ const railPluginsIdx = sidebarUpperSource.indexOf("label={t('sidebar.tabs.plugins')}");+ const railRestoreIdx = sidebarUpperSource.indexOf(+ '<GhostPanelRestoreEntry',+ railPluginsIdx,+ );+ const railSearchIdx = sidebarUpperSource.indexOf('<ConversationSearchBox', railRestoreIdx);+ expect(railPluginsIdx).toBeGreaterThanOrEqual(0);+ expect(railRestoreIdx).toBeGreaterThan(railPluginsIdx);+ expect(railSearchIdx).toBeGreaterThan(railRestoreIdx);+ });+// 2026-08-12 用户反馈:滚动后首行紧贴固定的「新建」被硬切、露出半截字。it('滚动后顶部渐隐,未滚动时不加 mask(避免裁掉首行 hover 胶囊 / 焦点环)', () => {// 按需启用:与右栏 TabBar 的 side-aware fade 同一取舍(常开 mask 会裁 border)。diff --git a/apps/desktop/src/renderer/cindy-brain/GhostPanelBubbleLayer.tsx b/apps/desktop/src/renderer/cindy-brain/GhostPanelBubbleLayer.tsxindex 5b550e73de..a845475491 100644--- a/apps/desktop/src/renderer/cindy-brain/GhostPanelBubbleLayer.tsx+++ b/apps/desktop/src/renderer/cindy-brain/GhostPanelBubbleLayer.tsx@@ -7,7 +7,7 @@* 独立窗」的插件,就渲染**一枚**幽灵球(lucide Ghost 脸 + 数量角标),* 不再按数量分形态。点球纵向展开各插件自己的气泡(向下,空间不够则* 向上),点谁恢复谁的面板;点球或空白处收拢。全部面板都开着(没有- * 最小化的)整层消失 —— 幽灵球只在有面板可恢复时在场。+ * 最小化的)整层消失 —— 幽灵球只在有面板可恢复且用户选择气泡入口时在场。* - 子气泡脸 = 插件图标(InstalledGhost.iconDataUrl,主窗拿不到* cindy-ghost://,data URL 直接 <img>;缺图标兜底 lucide Ghost);* - 定位用 left/top 而非 transform(2026-07-31 Lizi 实测:草稿页气泡拖@@ -36,11 +36,11 @@ import { createPortal } from 'react-dom';import { Ghost } from 'lucide-react';import { useTranslation } from 'react-i18next';-import { ghostPanelKind, type GhostManifest } from '../../shared/ghost';+import type { GhostManifest } from '../../shared/ghost';import { WINDOW_NO_DRAG_STYLE } from '../components/layout/windowDrag';-import { restoreGhostPanel, useGhostPanelBubbleState } from '../lib/ghostPanelBubbleState';-import { isGhostPanelKindDetached, useGhostPanelWindowsState } from '../lib/ghostPanelWindowState';-import { useInstalledGhosts } from './useInstalledGhosts';+import { restoreGhostPanel } from '../lib/ghostPanelBubbleState';+import { useGhostPanelRestoreMode } from '../hooks/useGhostPanelRestoreMode';+import { useMinimizedGhostPanels } from './useMinimizedGhostPanels';const BUBBLE_SIZE = 48;const EDGE_MARGIN = 12;@@ -301,7 +301,7 @@ function Bubble({ manifest, iconDataUrl, pos, registerEl }: BubbleProps): ReactN);}-/** 幽灵球:被最小化面板的唯一入口(Ghost 脸 + 数量角标),点击切换展开。 */+/** 幽灵球:气泡模式下被最小化面板的聚合入口(Ghost 脸 + 数量角标)。 */function StackBubble({count,pos,@@ -364,10 +364,8 @@ function StackBubble({/** 气泡层:没有最小化面板时不渲染;窗口缩放防抖重渲以重算 clamp/默认位。 */export function GhostPanelBubbleLayer(): ReactNode {- const ghosts = useInstalledGhosts();- const bubbles = useGhostPanelBubbleState();- // 订阅抽离状态:detach 期间气泡隐藏,合并回来自动复现。- useGhostPanelWindowsState();+ const { mode } = useGhostPanelRestoreMode();+ const minimized = useMinimizedGhostPanels();// 展开态(纯运行时,不落盘;落盘会让"重启后自动摊开一排"变成惊吓)。const [expanded, setExpanded] = useState(false);const [stackPos, setStackPos] = useState<{ x: number; y: number } | null>(() => loadStackPos());@@ -388,15 +386,7 @@ export function GhostPanelBubbleLayer(): ReactNode {};}, []);- const minimized = ghosts.filter(- (g) =>- g.enabled !== false &&- g.manifest.panel !== undefined &&- g.manifest.panel.position !== 'tab' &&- bubbles[g.manifest.id]?.minimized === true &&- !isGhostPanelKindDetached(ghostPanelKind(g.manifest.id)),- );- const empty = minimized.length === 0;+ const empty = mode !== 'bubble' || minimized.length === 0;// 整层退场(全部面板都开着)时收拢,防下次出现直接摊开一排。useEffect(() => {diff --git a/apps/desktop/src/renderer/cindy-brain/GhostPanelRestoreEntry.tsx b/apps/desktop/src/renderer/cindy-brain/GhostPanelRestoreEntry.tsxnew file mode 100644index 0000000000..26aa2382e2--- /dev/null+++ b/apps/desktop/src/renderer/cindy-brain/GhostPanelRestoreEntry.tsx@@ -0,0 +1,134 @@+import { useState, type ReactNode } from 'react';+import { Ghost } from 'lucide-react';+import { useTranslation } from 'react-i18next';++import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from '@/components/ui/dropdown-menu';+import { useGhostPanelRestoreMode } from '@/hooks/useGhostPanelRestoreMode';+import { cn } from '@/lib/utils';+import type { InstalledGhost } from '../../shared/ghost';+import { restoreGhostPanel } from '../lib/ghostPanelBubbleState';+import { useMinimizedGhostPanels } from './useMinimizedGhostPanels';++function panelName(ghost: InstalledGhost): string {+ return ghost.manifest.panel?.title ?? ghost.manifest.name;+}++function GhostEntryIcon({ ghost, size }: { ghost?: InstalledGhost; size: number }): ReactNode {+ const [broken, setBroken] = useState(false);+ if (ghost?.iconDataUrl && !broken) {+ return (+ <img+ src={ghost.iconDataUrl}+ alt=""+ draggable={false}+ className="shrink-0 rounded-full object-cover"+ style={{ width: size, height: size }}+ onError={() => setBroken(true)}+ />+ );+ }+ return <Ghost size={size} strokeWidth={1.8} className="shrink-0" aria-hidden />;+}++export function GhostPanelRestoreEntry({+ variant,+ className,+}: {+ variant: 'row' | 'rail';+ className?: string;+}): ReactNode {+ const { t } = useTranslation();+ const { mode } = useGhostPanelRestoreMode();+ const minimized = useMinimizedGhostPanels();+ if (mode !== 'sidebar' || minimized.length === 0) return null;++ const single = minimized.length === 1 ? minimized[0] : null;+ const label = single+ ? t('ghostPanelRestore.single', { name: panelName(single) })+ : t('ghostPanelRestore.multiple', { count: minimized.length });+ const content = (+ <>+ <GhostEntryIcon ghost={single ?? undefined} size={variant === 'rail' ? 18 : 15} />+ {variant === 'row' ? (+ <>+ <span className="min-w-0 flex-1 truncate leading-none">{label}</span>+ {minimized.length > 1 ? (+ <span+ aria-hidden+ className="flex h-4 min-w-4 items-center justify-center rounded-full bg-[var(--surface-chip)] px-1 text-10 font-medium leading-none text-[var(--text-secondary)]"+ >+ {minimized.length}+ </span>+ ) : null}+ </>+ ) : minimized.length > 1 ? (+ <span+ aria-hidden+ className="absolute right-1 top-1 flex h-4 min-w-4 items-center justify-center rounded-full border border-[var(--text-tertiary)] bg-[var(--surface-chip)] px-1 text-10 font-medium leading-none text-[var(--text-secondary)]"+ >+ {minimized.length}+ </span>+ ) : null}+ </>+ );++ if (single) {+ return (+ <button+ type="button"+ data-testid="ghost-panel-restore-entry"+ aria-label={label}+ title={label}+ onClick={() => restoreGhostPanel(single.manifest.id)}+ className={className}+ >+ {content}+ </button>+ );+ }++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <button+ type="button"+ data-testid="ghost-panel-restore-entry"+ aria-label={label}+ title={label}+ className={cn('relative', className)}+ >+ {content}+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent+ side="right"+ align="start"+ sideOffset={6}+ className={cn(+ 'min-w-[200px] max-w-[320px] rounded-xl p-1',+ 'border border-[var(--cmd-palette-border)] bg-[var(--cmd-palette-bg)]',+ 'shadow-[var(--shadow-menu)]',+ )}+ >+ {minimized.map((ghost) => {+ const name = panelName(ghost);+ return (+ <DropdownMenuItem+ key={ghost.manifest.id}+ onSelect={() => restoreGhostPanel(ghost.manifest.id)}+ className="gap-2.5 text-[var(--msg-assistant-text)] focus:bg-[var(--cmd-palette-item-hover)]"+ >+ <GhostEntryIcon ghost={ghost} size={18} />+ <span className="min-w-0 flex-1 truncate">{name}</span>+ </DropdownMenuItem>+ );+ })}+ </DropdownMenuContent>+ </DropdownMenu>+ );+}diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelBubbleLayer.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelBubbleLayer.test.tsxindex 240986bfd6..6c890fefaf 100644--- a/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelBubbleLayer.test.tsx+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelBubbleLayer.test.tsx@@ -2,7 +2,7 @@// GhostPanelBubbleLayer:幽灵球单形态(≥1 个最小化即一枚球)/ 展开点子气泡// 恢复(先缩没后还原)/ 拖后吞点击 / left-top 定位 / detach 隐藏。import { afterEach, describe, expect, it, vi } from 'vitest';-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';import type { GhostManifest, InstalledGhost } from '../../../shared/ghost';import {@@ -14,6 +14,10 @@ import {__resetGhostPanelWindowsStateForTest,__setGhostPanelWindowsStateForTest,} from '../../lib/ghostPanelWindowState';+import {+ __resetGhostPanelRestoreModeForTest,+ setGhostPanelRestoreMode,+} from '../../hooks/useGhostPanelRestoreMode';import { __resetInstalledGhostsStoreForTest } from '../useInstalledGhosts';import { GhostPanelBubbleLayer } from '../GhostPanelBubbleLayer';@@ -56,9 +60,11 @@ function stubGhostsBridge(ghosts: InstalledGhost[]): void {afterEach(() => {cleanup();__resetGhostPanelBubbleStateForTest();+ __resetGhostPanelRestoreModeForTest();__resetGhostPanelWindowsStateForTest();__resetInstalledGhostsStoreForTest();window.localStorage.removeItem('xdt:ghostPanelBubbleStack:v1');+ window.localStorage.removeItem('ghostPanel.restoreMode');delete (window as unknown as { electronAPI?: unknown }).electronAPI;});@@ -81,6 +87,14 @@ describe('GhostPanelBubbleLayer', () => {expect(screen.queryByTestId('ghost-panel-bubble-stack')).toBeNull();});+ it('选择侧栏恢复入口时不渲染浮动幽灵球', () => {+ stubGhostsBridge([ghost('a')]);+ minimizeGhostPanel('a');+ setGhostPanelRestoreMode('sidebar');+ render(<GhostPanelBubbleLayer />);+ expect(screen.queryByTestId('ghost-panel-bubble-stack')).toBeNull();+ });+it('点球展开子气泡(aria 带面板名);点子气泡先播缩没退场,到点恢复;最后一个恢复后整层卸载', async () => {stubGhostsBridge([ghost('a')]);minimizeGhostPanel('a');@@ -107,7 +121,7 @@ describe('GhostPanelBubbleLayer', () => {__setGhostPanelWindowsStateForTest({ a: { detached: true, lastOpen: true, open: true } });const { rerender } = render(<GhostPanelBubbleLayer />);expect(screen.queryByTestId('ghost-panel-bubble-stack')).toBeNull();- __setGhostPanelWindowsStateForTest({});+ act(() => __setGhostPanelWindowsStateForTest({}));rerender(<GhostPanelBubbleLayer />);expect(screen.getByTestId('ghost-panel-bubble-stack')).toBeTruthy();});diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelRestoreEntry.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelRestoreEntry.test.tsxnew file mode 100644index 0000000000..0a01311c20--- /dev/null+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/GhostPanelRestoreEntry.test.tsx@@ -0,0 +1,98 @@+// @vitest-environment jsdom++import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, describe, expect, it, vi } from 'vitest';++import type { GhostManifest, InstalledGhost } from '../../../shared/ghost';+import {+ __resetGhostPanelRestoreModeForTest,+ setGhostPanelRestoreMode,+} from '../../hooks/useGhostPanelRestoreMode';+import {+ __resetGhostPanelBubbleStateForTest,+ getGhostPanelBubbleState,+ minimizeGhostPanel,+} from '../../lib/ghostPanelBubbleState';+import { __resetGhostPanelWindowsStateForTest } from '../../lib/ghostPanelWindowState';+import { GhostPanelRestoreEntry } from '../GhostPanelRestoreEntry';+import { __resetInstalledGhostsStoreForTest } from '../useInstalledGhosts';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string, args?: Record<string, unknown>) =>+ args ? `${key}:${JSON.stringify(args)}` : key,+ }),+}));++function ghost(id: string): InstalledGhost {+ const manifest: GhostManifest = {+ schemaVersion: 2,+ id,+ name: `${id} 插件`,+ version: '1.0.0',+ kind: 'chip',+ entry: 'main.js',+ slots: ['panel'],+ panel: { title: `${id} 面板`, html: 'panel.html' },+ };+ return {+ manifest,+ dir: `/fake/${id}`,+ enabled: true,+ approval: { state: 'approved', revision: '00000000-0000-4000-8000-000000000001' },+ };+}++function stubGhostsBridge(ghosts: InstalledGhost[]): void {+ (window as unknown as { electronAPI: unknown }).electronAPI = {+ ghosts: {+ listSync: () => ({ ghosts }),+ onChanged: () => () => undefined,+ },+ };+}++afterEach(() => {+ cleanup();+ __resetGhostPanelBubbleStateForTest();+ __resetGhostPanelRestoreModeForTest();+ __resetGhostPanelWindowsStateForTest();+ __resetInstalledGhostsStoreForTest();+ window.localStorage.removeItem('ghostPanel.restoreMode');+ delete (window as unknown as { electronAPI?: unknown }).electronAPI;+});++describe('GhostPanelRestoreEntry', () => {+ it('气泡模式或没有最小化面板时不占侧栏位置', () => {+ stubGhostsBridge([ghost('a')]);+ minimizeGhostPanel('a');+ const view = render(<GhostPanelRestoreEntry variant="row" />);+ expect(screen.queryByTestId('ghost-panel-restore-entry')).toBeNull();++ act(() => setGhostPanelRestoreMode('sidebar'));+ expect(screen.getByTestId('ghost-panel-restore-entry')).toBeTruthy();++ act(() => {+ fireEvent.click(screen.getByTestId('ghost-panel-restore-entry'));+ });+ expect(getGhostPanelBubbleState().a?.minimized).not.toBe(true);+ expect(screen.queryByTestId('ghost-panel-restore-entry')).toBeNull();+ view.unmount();+ });++ it('多个面板显示聚合入口并从菜单恢复指定面板', () => {+ stubGhostsBridge([ghost('a'), ghost('b')]);+ minimizeGhostPanel('a');+ minimizeGhostPanel('b');+ setGhostPanelRestoreMode('sidebar');+ render(<GhostPanelRestoreEntry variant="row" />);++ const trigger = screen.getByTestId('ghost-panel-restore-entry');+ expect(trigger.textContent).toContain('2');+ fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false });+ fireEvent.click(screen.getByText('a 面板'));++ expect(getGhostPanelBubbleState().a?.minimized).not.toBe(true);+ expect(getGhostPanelBubbleState().b?.minimized).toBe(true);+ });+});diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/useMinimizedGhostPanels.test.ts b/apps/desktop/src/renderer/cindy-brain/__tests__/useMinimizedGhostPanels.test.tsnew file mode 100644index 0000000000..ac6a51ee52--- /dev/null+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/useMinimizedGhostPanels.test.ts@@ -0,0 +1,56 @@+import { describe, expect, it } from 'vitest';++import type { GhostManifest, InstalledGhost } from '../../../shared/ghost';+import { selectMinimizedGhostPanels } from '../useMinimizedGhostPanels';++function ghost(+ id: string,+ options: { enabled?: boolean; panel?: boolean; position?: 'left' | 'tab' } = {},+): InstalledGhost {+ const manifest: GhostManifest = {+ schemaVersion: 2,+ id,+ name: id,+ version: '1.0.0',+ kind: 'chip',+ entry: 'main.js',+ slots: options.panel === false ? [] : ['panel'],+ ...(options.panel === false+ ? {}+ : { panel: { html: 'panel.html', position: options.position ?? 'left' } }),+ };+ return {+ manifest,+ dir: `/fake/${id}`,+ enabled: options.enabled ?? true,+ approval: { state: 'approved', revision: '00000000-0000-4000-8000-000000000001' },+ };+}++describe('selectMinimizedGhostPanels', () => {+ it('只返回启用、停靠、已最小化且未抽离的插件面板', () => {+ const ghosts = [+ ghost('ready'),+ ghost('open'),+ ghost('disabled', { enabled: false }),+ ghost('tab', { position: 'tab' }),+ ghost('tool', { panel: false }),+ ghost('detached'),+ ];++ expect(+ selectMinimizedGhostPanels(+ ghosts,+ {+ ready: { minimized: true },+ open: { minimized: false },+ disabled: { minimized: true },+ tab: { minimized: true },+ tool: { minimized: true },+ detached: { minimized: true },+ },+ { detached: { detached: true, open: true, lastOpen: true } },+ ).map((item) => item.manifest.id),+ ).toEqual(['ready']);+ });+});diff --git a/apps/desktop/src/renderer/cindy-brain/useMinimizedGhostPanels.ts b/apps/desktop/src/renderer/cindy-brain/useMinimizedGhostPanels.tsnew file mode 100644index 0000000000..8ffd57f784--- /dev/null+++ b/apps/desktop/src/renderer/cindy-brain/useMinimizedGhostPanels.ts@@ -0,0 +1,39 @@+import { useMemo } from 'react';++import type { InstalledGhost } from '../../shared/ghost';+import type { GhostPanelWindowsState } from '../../shared/ghostPanelWindow';+import {+ useGhostPanelBubbleState,+ type GhostPanelBubbleMap,+} from '../lib/ghostPanelBubbleState';+import { useGhostPanelWindowsState } from '../lib/ghostPanelWindowState';+import { useInstalledGhosts } from './useInstalledGhosts';++/**+ * 两种恢复入口共享的唯一筛选器。只有已装、启用、停靠形态、已最小化且未抽离到+ * 独立窗口的插件面板才允许出现在恢复入口中。+ */+export function selectMinimizedGhostPanels(+ ghosts: readonly InstalledGhost[],+ bubbles: GhostPanelBubbleMap,+ windows: GhostPanelWindowsState,+): InstalledGhost[] {+ return ghosts.filter(+ (ghost) =>+ ghost.enabled !== false &&+ ghost.manifest.panel !== undefined &&+ ghost.manifest.panel.position !== 'tab' &&+ bubbles[ghost.manifest.id]?.minimized === true &&+ windows[ghost.manifest.id]?.detached !== true,+ );+}++export function useMinimizedGhostPanels(): InstalledGhost[] {+ const ghosts = useInstalledGhosts();+ const bubbles = useGhostPanelBubbleState();+ const windows = useGhostPanelWindowsState();+ return useMemo(+ () => selectMinimizedGhostPanels(ghosts, bubbles, windows),+ [bubbles, ghosts, windows],+ );+}diff --git a/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsxindex 97e94d86fa..6ee94dc942 100644--- a/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx@@ -68,14 +68,14 @@ export function GhostPanelWindowLayout() {// 与资源用量窗口一致,隐藏时重挂载 chrome,确保再次显示从干净状态开始�?const [windowChromeRevision, setWindowChromeRevision] = useState(0);- const minimizeToBubble = async (): Promise<void> => {+ const minimizePanel = async (): Promise<void> => {if (!ghostId || !minimizeEnabled) return;minimizeGhostPanel(ghostId);try {await window.electronAPI.ghostPanelWindow.setDetached(ghostId, false);} catch (err) {restoreGhostPanel(ghostId);- log.warn('minimize ghost panel to bubble failed', err);+ log.warn('minimize ghost panel failed', err);}};@@ -132,7 +132,7 @@ export function GhostPanelWindowLayout() {useEffect(() => {if (!minimizeEnabled) return;return window.electronAPI.ghostPanelWindow.onMinimizeRequested(() => {- void minimizeToBubble();+ void minimizePanel();});}, [ghostId, minimizeEnabled, window.electronAPI.ghostPanelWindow]);@@ -189,7 +189,7 @@ export function GhostPanelWindowLayout() {><WindowControlskey={windowChromeRevision}- onMinimize={minimizeToBubble}+ onMinimize={minimizePanel}showMinimize={minimizeEnabled}onClose={disableAndClose}/>diff --git a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsxindex f52c749718..3b81c97093 100644--- a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx+++ b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx@@ -283,7 +283,7 @@ describe('reusable auxiliary window chrome', () => {);});- it('minimizes a detached plugin window into the main-window Ghost bubble', async () => {+ it('minimizes a detached plugin window through the main-window restore flow', async () => {render(<GhostPanelWindowLayout />);fireEvent.click(screen.getByRole('button', { name: 'titleBar.minimize' }));diff --git a/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx b/apps/desktop/src/renderer/components/settings/AppearanceSection.tsxindex 57ff34c6ba..a79bd613eb 100644--- a/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx+++ b/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx@@ -29,6 +29,10 @@ import {type SidebarMainViewMode,type SidebarViewMode,} from '@/hooks/useSidebarCardMode';+import {+ useGhostPanelRestoreMode,+ type GhostPanelRestoreMode,+} from '@/hooks/useGhostPanelRestoreMode';import { getThemeFamilies, resolveFamilyVariant, type ThemeFamily } from '@/themes/families';import { buildCopyFromTheme, onLocalThemesChange, refreshLocalThemes } from '@/themes/local-themes';import { toast } from '@/lib/toast';@@ -317,6 +321,8 @@ export function AppearanceSection() {} = useFontSettings();const { mode: sidebarViewMode, setMode: setSidebarViewMode } = useSidebarCardMode();const { mode: sidebarMainViewMode, setMode: setSidebarMainViewMode } = useSidebarMainViewMode();+ const { mode: ghostPanelRestoreMode, setMode: setGhostPanelRestoreMode } =+ useGhostPanelRestoreMode();const { t } = useTranslation();const [localThemesVersion, setLocalThemesVersion] = useState(0);const [uiSizeInput, setUiSizeInput] = useState(String(uiSize));@@ -894,6 +900,49 @@ export function AppearanceSection() {))}</div></div>++ <div className="flex items-center justify-between gap-3">+ <div className="flex min-w-0 flex-col gap-1">+ <p+ className="text-13 font-medium text-[var(--settings-section-sublabel)]"+ style={{ letterSpacing: '0.12px' }}+ >+ {t('settings.appearance.ghostPanelRestore.label')}+ </p>+ <p className="text-12 leading-[1.4] text-[var(--settings-section-sublabel)] opacity-70">+ {t('settings.appearance.ghostPanelRestore.hint')}+ </p>+ </div>++ <div+ role="radiogroup"+ aria-label={t('settings.appearance.ghostPanelRestore.aria')}+ className="flex shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5"+ >+ {(+ [+ { value: 'bubble', labelKey: 'settings.appearance.ghostPanelRestore.bubble' },+ { value: 'sidebar', labelKey: 'settings.appearance.ghostPanelRestore.sidebar' },+ ] as Array<{ value: GhostPanelRestoreMode; labelKey: string }>+ ).map((option) => (+ <button+ key={option.value}+ type="button"+ role="radio"+ aria-checked={ghostPanelRestoreMode === option.value}+ onClick={() => setGhostPanelRestoreMode(option.value)}+ className={cn(+ 'rounded-full px-2.5 py-1 text-xs transition-colors',+ ghostPanelRestoreMode === option.value+ ? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]'+ : 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',+ )}+ >+ {t(option.labelKey)}+ </button>+ ))}+ </div>+ </div></div><LayoutResetControl />diff --git a/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx b/apps/desktop/src/renderer/components/sidebar/Sidebar.tsxindex 1383463c24..b3e43fb634 100644--- a/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx+++ b/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx@@ -218,7 +218,7 @@ export function Sidebar({rail(收窄)态放不下,隐藏——rail 自身承担入口;展开后回归。完全隐藏态 w-0 自然裁掉。 */}{/* 任务列表页把「新建」以外的行搬进自己的列表滚动区(向上滚一起滚走,- 对齐 Codex);此时这里只渲染固定的「新建」。其它视图仍整块渲染五行。 */}+ 对齐 Codex);此时这里只渲染固定的「新建」。其它视图仍整块渲染常驻行。 */}{!isRail && <SidebarTopNav section={ownsTopNavScrollableRows ? 'pinned' : 'all'} />}{/* Upper: feature-injected content slot.diff --git a/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx b/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsxindex fd8609347a..026fc91acf 100644--- a/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx+++ b/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx@@ -1,7 +1,8 @@/*** SidebarTopNav —— 侧栏顶部常驻动作/导航列表(取代原 HorizontalTabbar)。* ---------------------------------------------------------------------------- * 一条同级、等权的列表行,按顺序:新建 / 自动任务 / Plugins / 搜索。+ * 一条同级、等权的列表行,按顺序:新建 / 自动任务 / Plugins /+ * 最小化插件面板恢复入口(按需) / 搜索。* - 新建 / 自动任务:项目(cc-agent)视图的动作 —— 在任意视图点击都跳回项目视图并执行。* - Plugins:主视图切换(navigateToView),命中当前视图时高亮。* - 搜索(SidebarInlineSearch):静息态与其余行同款「🔍 搜索」;hover / 聚焦@@ -26,6 +27,7 @@ import { useTranslation } from 'react-i18next';import { cn } from '@/lib/utils';import { AttentionDot } from '@/components/sidebar/AttentionDot';import { useAnyGhostUnread } from '@/cindy-brain/ghostUnreadStore';+import { GhostPanelRestoreEntry } from '@/cindy-brain/GhostPanelRestoreEntry';import { useActiveMainView } from '@/hooks/useActiveMainView';import { SidebarInlineSearch } from '@/features/cc-agent/sidebar/SidebarInlineSearch';import { useConversationSearchContext } from '@/features/cc-agent/sidebar/conversationSearchContext';@@ -43,10 +45,10 @@ const ROW_ACTIVE_CLASS =/*** 渲染范围。任务列表页把「新建」以外的行搬进列表滚动区(向上滚时一起滚走,* 对齐 Codex;2026-08-12 用户裁决),因此本组件要能分两段渲染:- * - 'all'(默认):五行全渲染。非 cc-agent 视图(插件页 / Skill 页等)沿用,+ * - 'all'(默认):常驻行全渲染。非 cc-agent 视图(插件页 / Skill 页等)沿用,* 那些页的侧栏没有长列表,不存在滚动需求。* - 'pinned':只渲染「新建」——Shell 顶部固定段。- * - 'scrollable':渲染其余行(自动任务 / 插件 / 搜索 / 远程机器),由 cc-agent+ * - 'scrollable':渲染其余行(自动任务 / 插件 / 按需恢复入口 / 搜索),由 cc-agent* 的侧栏滚动容器在列表最上方绘制。*/export type SidebarTopNavSection = 'all' | 'pinned' | 'scrollable';@@ -124,6 +126,9 @@ export function SidebarTopNav({{hasGhostUnread && <AttentionDot size={6} className="ml-auto mr-0.5" />}</button>) : null;+ const restoreRow = showScrollable ? (+ <GhostPanelRestoreEntry variant="row" className={ROW_CLASS} />+ ) : null;const searchRow = showScrollable ? (<SidebarInlineSearchsearch={search}@@ -141,6 +146,7 @@ export function SidebarTopNav({<div className="flex flex-col gap-0.5 pr-3 pl-3">{automationsRow}{pluginsRow}+ {restoreRow}</div><divclassName={cn(@@ -180,6 +186,7 @@ export function SidebarTopNav({)}{automationsRow}{pluginsRow}+ {restoreRow}{searchRow}</div>);diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsxindex ccf06adc13..45558e2fca 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx@@ -94,6 +94,7 @@ import { useBackgroundActivitySessionIds } from '@/lib/sessionBackgroundActivityimport { useAttachedSessionIds } from '@/hooks/useAttachedSessionIds';import { useActiveMainView } from '@/hooks/useActiveMainView';import { useAnyGhostUnread } from '@/cindy-brain/ghostUnreadStore';+import { GhostPanelRestoreEntry } from '@/cindy-brain/GhostPanelRestoreEntry';import { getNotificationsEnabled } from '@/hooks/useNotificationSettings';import { getFeishuNotificationsEnabled } from '@/hooks/useFeishuNotificationSettings';import { getAgentIslandEnabled, isAgentIslandSupported } from '@/hooks/useAgentIslandSettings';@@ -1348,7 +1349,7 @@ function ExpandedView({[projectUniverse.projects, hiddenProjectKeys, localPlatform],);- // 内联会话搜索:输入行在 SidebarTopNav 的第 4 行,状态经 ConversationSearchProvider 共享;+ // 内联会话搜索:输入行在 SidebarTopNav 末行,状态经 ConversationSearchProvider 共享;// query 非空时同一份顶部导航 sticky 钉住,结果替换下方列表,不再用 overlay 盖输入框。const { search, openSignal } = useConversationSearchContext();const gcProjectKeys = useMemo(@@ -3650,6 +3651,10 @@ function CollapsedView({showDot={hasGhostUnread}onClick={() => navigateToView('plugins')}/>+ <GhostPanelRestoreEntry+ variant="rail"+ className={SIDEBAR_RAIL_ICON_BUTTON_CLASS}+ /><ConversationSearchBoxnavigate={navigate}allKnownProjects={allSearchProjects}diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsxindex 528d41bcff..e6a158d2eb 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx@@ -1,9 +1,9 @@/**- * SidebarInlineSearch —— SidebarTopNav 顶部导航列表的「搜索」行(排在技能之后,第 4 行)。+ * SidebarInlineSearch —— SidebarTopNav 顶部导航列表末尾的「搜索」行。* ---------------------------------------------------------------------------* 渲染为一条裸行(无外层 padding),融入 SidebarTopNav 的 gap-0.5 列表,与 新建/自动任务/- * 技能 同款。两态一体、图标位置恒定:- * - 静息态(未 hover / 未聚焦 / 无查询):与 新建 / 自动化 / 技能 等导航行完全一致+ * 插件等入口同款。两态一体、图标位置恒定:+ * - 静息态(未 hover / 未聚焦 / 无查询):与 新建 / 自动化 / 插件 等导航行完全一致* 的「🔍 搜索」行(透明底、无边框、foreground 文字)。* - 展开态(hover / 聚焦 / 有查询 / 选项菜单打开):同一容器就地变成搜索框——* 补上 Board 边框 + elevated 底,文字行换成真实输入框,右侧浮现排序 / 筛选两颗@@ -104,8 +104,8 @@ export function SidebarInlineSearch({};return (- // 常驻外壳:作为 SidebarTopNav 列表的第 4 行(技能之后)。静息=导航行样式(透明、无边框,- // 与 新建/自动任务/技能 同款);展开=搜索框(elevated + Board 边框)。h-8 / pl-3 / gap-2.5 /+ // 常驻外壳:作为 SidebarTopNav 列表末行。静息=导航行样式(透明、无边框,+ // 与 新建/自动任务/插件等入口同款);展开=搜索框(elevated + Board 边框)。h-8 / pl-3 / gap-2.5 /// 图标 18px 两态一致;border 恒在、静息时透明 → 展开时搜索图标不位移。<div// 标记「搜索界面内部」:Provider 的 outside-pointerdown 监听据此判定——本行内点击不收起搜索,diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/conversationSearchContext.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/conversationSearchContext.tsxindex e5098fae52..c68d525dc8 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/conversationSearchContext.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/conversationSearchContext.tsx@@ -1,7 +1,8 @@/*** ConversationSearchContext —— 展开侧栏「内联会话搜索」的共享状态。* ---------------------------------------------------------------------------- * 搜索输入行现在是 SidebarTopNav 顶部导航列表的第 4 行(新建 / 自动任务 / 技能 / 搜索),+ * 搜索输入行位于 SidebarTopNav 顶部导航列表末尾(新建 / 自动任务 / 插件 /+ * 按需恢复入口 / 搜索),* 结果由下方功能槽(CCAgentSidebarUpper.ExpandedView)替换列表渲染——两者* 是 Sidebar 外壳下的兄弟子树,不在同一组件内。这里用一个 Provider 在两者的共同祖先* (Sidebar 外壳)处**只实例化一次** useConversationSearch,经 context 同时供:diff --git a/apps/desktop/src/renderer/features/feature-context.tsx b/apps/desktop/src/renderer/features/feature-context.tsxindex 05697af7ca..e905be2096 100644--- a/apps/desktop/src/renderer/features/feature-context.tsx+++ b/apps/desktop/src/renderer/features/feature-context.tsx@@ -55,9 +55,9 @@ interface FeatureSidebarSlotContextValue {sidebarEnabled: boolean;/*** 当前 Feature 是否自行在其滚动区里渲染顶部导航的「可滚动段」(自动任务 / 插件 /- * 搜索 / 远程机器)。true 时 Shell 顶部只保留固定的「新建」行,其余交给 Feature+ * 按需恢复入口 / 搜索)。true 时 Shell 顶部只保留固定的「新建」行,其余交给 Feature* ——任务列表页据此让这些行随列表一起滚走(2026-08-12 用户裁决,对齐 Codex)。- * 默认 false:没有长列表的视图(插件页等)仍由 Shell 整块渲染五行。+ * 默认 false:没有长列表的视图(插件页等)仍由 Shell 整块渲染常驻行。*/ownsTopNavScrollableRows: boolean;/** 内部 setter,Feature 经 useOwnTopNavScrollableRows 声明。 */diff --git a/apps/desktop/src/renderer/hooks/__tests__/useGhostPanelRestoreMode.test.tsx b/apps/desktop/src/renderer/hooks/__tests__/useGhostPanelRestoreMode.test.tsxnew file mode 100644index 0000000000..f216002cdc--- /dev/null+++ b/apps/desktop/src/renderer/hooks/__tests__/useGhostPanelRestoreMode.test.tsx@@ -0,0 +1,60 @@+// @vitest-environment jsdom++import { act, cleanup, renderHook } from '@testing-library/react';+import { afterEach, describe, expect, it } from 'vitest';++import {+ __resetGhostPanelRestoreModeForTest,+ getGhostPanelRestoreMode,+ setGhostPanelRestoreMode,+ useGhostPanelRestoreMode,+} from '../useGhostPanelRestoreMode';++afterEach(() => {+ cleanup();+ window.localStorage.removeItem('ghostPanel.restoreMode');+ __resetGhostPanelRestoreModeForTest();+});++describe('useGhostPanelRestoreMode', () => {+ it('默认沿用浮动气泡且不写默认值快照', () => {+ expect(getGhostPanelRestoreMode()).toBe('bubble');+ expect(window.localStorage.getItem('ghostPanel.restoreMode')).toBeNull();+ });++ it('切换到侧栏会持久化并通知同窗口消费者', () => {+ const first = renderHook(() => useGhostPanelRestoreMode());+ const second = renderHook(() => useGhostPanelRestoreMode());++ act(() => first.result.current.setMode('sidebar'));++ expect(first.result.current.mode).toBe('sidebar');+ expect(second.result.current.mode).toBe('sidebar');+ expect(window.localStorage.getItem('ghostPanel.restoreMode')).toBe('sidebar');+ });++ it('切回默认气泡会删除 override', () => {+ setGhostPanelRestoreMode('sidebar');+ expect(window.localStorage.getItem('ghostPanel.restoreMode')).toBe('sidebar');++ setGhostPanelRestoreMode('bubble');++ expect(getGhostPanelRestoreMode()).toBe('bubble');+ expect(window.localStorage.getItem('ghostPanel.restoreMode')).toBeNull();+ });++ it('接收其他窗口的偏好变更', () => {+ const view = renderHook(() => useGhostPanelRestoreMode());++ act(() => {+ window.dispatchEvent(+ new StorageEvent('storage', {+ key: 'ghostPanel.restoreMode',+ newValue: 'sidebar',+ }),+ );+ });++ expect(view.result.current.mode).toBe('sidebar');+ });+});diff --git a/apps/desktop/src/renderer/hooks/useGhostPanelRestoreMode.ts b/apps/desktop/src/renderer/hooks/useGhostPanelRestoreMode.tsnew file mode 100644index 0000000000..c4e5ef4128--- /dev/null+++ b/apps/desktop/src/renderer/hooks/useGhostPanelRestoreMode.ts@@ -0,0 +1,103 @@+/**+ * useGhostPanelRestoreMode —— 最小化插件面板的恢复入口偏好。+ *+ * 两种入口严格互斥:+ * - bubble:主窗口浮动幽灵球(历史默认);+ * - sidebar:左侧栏“恢复插件面板”入口。+ *+ * 默认值只存在于代码中,localStorage 仅保存 sidebar override。这样老用户升级后+ * 继续看到原有幽灵球,未来调整默认值时也不会被无意义的默认快照卡住。+ */++import { useCallback, useEffect, useState } from 'react';++export type GhostPanelRestoreMode = 'bubble' | 'sidebar';++const STORAGE_KEY = 'ghostPanel.restoreMode';+const DEFAULT_MODE: GhostPanelRestoreMode = 'bubble';++let memoryValue: GhostPanelRestoreMode | null = null;+const listeners = new Set<() => void>();+let storageSubscribed = false;++function parseMode(raw: string | null): GhostPanelRestoreMode | null {+ return raw === 'bubble' || raw === 'sidebar' ? raw : null;+}++function notifyListeners(): void {+ listeners.forEach((listener) => listener());+}++function onStorage(event: StorageEvent): void {+ if (event.key !== STORAGE_KEY) return;+ memoryValue = parseMode(event.newValue) ?? DEFAULT_MODE;+ notifyListeners();+}++function subscribe(listener: () => void): () => void {+ listeners.add(listener);+ if (!storageSubscribed) {+ window.addEventListener('storage', onStorage);+ storageSubscribed = true;+ }+ return () => {+ listeners.delete(listener);+ if (listeners.size === 0 && storageSubscribed) {+ window.removeEventListener('storage', onStorage);+ storageSubscribed = false;+ }+ };+}++export function getGhostPanelRestoreMode(): GhostPanelRestoreMode {+ if (memoryValue !== null) return memoryValue;+ try {+ const parsed = parseMode(window.localStorage.getItem(STORAGE_KEY));+ if (parsed === DEFAULT_MODE) {+ window.localStorage.removeItem(STORAGE_KEY);+ return (memoryValue = DEFAULT_MODE);+ }+ if (parsed) return (memoryValue = parsed);+ } catch {+ // localStorage 不可用时保留代码默认值,后续显式设置仍可在内存中即时生效。+ }+ return DEFAULT_MODE;+}++export function setGhostPanelRestoreMode(next: GhostPanelRestoreMode): void {+ memoryValue = next;+ try {+ if (next === DEFAULT_MODE) window.localStorage.removeItem(STORAGE_KEY);+ else window.localStorage.setItem(STORAGE_KEY, next);+ } catch {+ // 持久化失败不拦当前窗口交互。+ }+ notifyListeners();+}++export function useGhostPanelRestoreMode(): {+ mode: GhostPanelRestoreMode;+ setMode: (next: GhostPanelRestoreMode) => void;+} {+ const [mode, setModeState] = useState<GhostPanelRestoreMode>(getGhostPanelRestoreMode);+ const setMode = useCallback((next: GhostPanelRestoreMode) => {+ setGhostPanelRestoreMode(next);+ }, []);++ useEffect(() => {+ const sync = () => setModeState(getGhostPanelRestoreMode());+ return subscribe(sync);+ }, []);++ return { mode, setMode };+}++/** 仅测试用。 */+export function __resetGhostPanelRestoreModeForTest(): void {+ memoryValue = null;+ listeners.clear();+ if (storageSubscribed) {+ window.removeEventListener('storage', onStorage);+ storageSubscribed = false;+ }+}diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex fb36c20c5e..1a472f35a1 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -473,6 +473,13 @@"hint": "Display style for the main sidebar list (below Pinned): Text is a compact single row; List is a two-line row with a preview.","aria": "Switch session list style"},+ "ghostPanelRestore": {+ "label": "Plugin panel restore entry",+ "hint": "Choose where minimized plugin panels can be restored.",+ "aria": "Choose the plugin panel restore entry",+ "bubble": "Floating bubble",+ "sidebar": "Sidebar"+ },"layout": {"label": "Panel layout","hint": "Panel positions and widths persist across restarts. Restore the default arrangement if the layout becomes difficult to use.",@@ -4545,7 +4552,7 @@"maximizeAria": "Maximize panel","restoreAria": "Restore panel size","detachAria": "Open in a new window",- "minimizeAria": "Minimize to floating bubble",+ "minimizeAria": "Minimize panel","closeAria": "Close panel and disable plugin"},"ghostPanel": {@@ -4564,6 +4571,10 @@"stackExpandAria": "{{count}} plugin panels minimized. Click to expand","stackCollapseAria": "Collapse the plugin panel list"},+ "ghostPanelRestore": {+ "single": "Restore {{name}}",+ "multiple": "Restore plugin panels ({{count}})"+ },"rightSidebar": {"ariaLabel": "Right sidebar","panelError": {diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 20fa236f5a..c0f2e174f0 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -473,6 +473,13 @@"hint": "サイドバーのメインリスト(ピン留め以外)の表示形式。テキストはコンパクトな 1 行、リストはプレビュー付きの 2 行です。","aria": "セッションリストの表示を切り替える"},+ "ghostPanelRestore": {+ "label": "プラグインパネルの復元場所",+ "hint": "最小化したプラグインパネルを復元する場所を選択します。",+ "aria": "プラグインパネルの復元場所を選択",+ "bubble": "フローティングバブル",+ "sidebar": "サイドバー"+ },"layout": {"label": "パネルレイアウト","hint": "パネルの位置と幅は次回起動時も保持されます。使いにくい配置になった場合は、初期レイアウトに戻せます。",@@ -4543,7 +4550,7 @@"maximizeAria": "パネルを最大化","restoreAria": "パネルのサイズを元に戻す","detachAria": "新しいウィンドウで開く",- "minimizeAria": "フローティングバブルに最小化",+ "minimizeAria": "パネルを最小化","closeAria": "パネルを閉じてプラグインを無効化"},"ghostPanel": {@@ -4562,6 +4569,10 @@"stackExpandAria": "{{count}} 個のプラグインパネルを最小化中。クリックで展開","stackCollapseAria": "プラグインパネルの一覧を畳む"},+ "ghostPanelRestore": {+ "single": "{{name}}を復元",+ "multiple": "プラグインパネルを復元({{count}})"+ },"rightSidebar": {"ariaLabel": "右サイドバー","panelError": {diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 509ced144a..3bf60f250d 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -473,6 +473,13 @@"hint": "사이드바 기본 목록(고정 제외)의 표시 형식입니다. 텍스트는 간결한 한 줄, 목록은 미리보기가 있는 두 줄입니다.","aria": "세션 목록 표시 방식 전환"},+ "ghostPanelRestore": {+ "label": "플러그인 패널 복원 위치",+ "hint": "최소화한 플러그인 패널을 어디에서 복원할지 선택합니다.",+ "aria": "플러그인 패널 복원 위치 선택",+ "bubble": "플로팅 버블",+ "sidebar": "사이드바"+ },"layout": {"label": "패널 레이아웃","hint": "패널 위치와 너비는 다음 실행에도 유지됩니다. 사용하기 어려운 배치가 되면 기본 레이아웃으로 복원할 수 있습니다.",@@ -4543,7 +4550,7 @@"maximizeAria": "패널 최대화","restoreAria": "패널 크기 복원","detachAria": "새 창에서 열기",- "minimizeAria": "플로팅 버블로 최소화",+ "minimizeAria": "패널 최소화","closeAria": "패널 닫기 및 플러그인 비활성화"},"ghostPanel": {@@ -4562,6 +4569,10 @@"stackExpandAria": "플러그인 패널 {{count}}개가 최소화됨. 클릭하여 펼치기","stackCollapseAria": "플러그인 패널 목록 접기"},+ "ghostPanelRestore": {+ "single": "{{name}} 복원",+ "multiple": "플러그인 패널 복원({{count}})"+ },"rightSidebar": {"ariaLabel": "오른쪽 사이드바","panelError": {diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 1870007117..aed1f210df 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -473,6 +473,13 @@"hint": "侧边栏主列表(置顶以外)的显示形态:文字为紧凑单行,列表为带预览的两行。","aria": "切换任务列表显示方式"},+ "ghostPanelRestore": {+ "label": "插件面板恢复入口",+ "hint": "选择最小化插件面板后从哪里恢复。",+ "aria": "选择插件面板恢复入口",+ "bubble": "浮动气泡",+ "sidebar": "侧边栏"+ },"layout": {"label": "面板布局","hint": "面板位置和宽度会保留到下次启动。如果布局变得难以使用,可以恢复默认排列。",@@ -4543,7 +4550,7 @@"maximizeAria": "撑满内容区","restoreAria": "还原面板大小","detachAria": "在独立窗口中打开",- "minimizeAria": "最小化为浮动气泡",+ "minimizeAria": "最小化面板","closeAria": "关闭面板并停用插件"},"ghostPanel": {@@ -4562,6 +4569,10 @@"stackExpandAria": "已收起 {{count}} 个插件面板,点击展开","stackCollapseAria": "收拢插件面板列表"},+ "ghostPanelRestore": {+ "single": "恢复 {{name}}",+ "multiple": "恢复插件面板({{count}})"+ },"rightSidebar": {"ariaLabel": "右侧边栏","panelError": {diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 11cd79adf7..2957fc4d5a 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -473,6 +473,13 @@"hint": "側邊欄主列表(置頂以外)的顯示形態:文字為緊湊單行,列表為帶預覽的兩行。","aria": "切換任務列表顯示方式"},+ "ghostPanelRestore": {+ "label": "插件面板恢復入口",+ "hint": "選擇最小化插件面板後從哪裡恢復。",+ "aria": "選擇插件面板恢復入口",+ "bubble": "浮動氣泡",+ "sidebar": "側邊欄"+ },"layout": {"label": "面板佈局","hint": "面板位置和寬度會保留到下次啟動。如果佈局變得難以使用,可以恢復預設排列。",@@ -4543,7 +4550,7 @@"maximizeAria": "撐滿內容區","restoreAria": "還原面板大小","detachAria": "在獨立視窗中開啟",- "minimizeAria": "最小化為浮動氣泡",+ "minimizeAria": "最小化面板","closeAria": "關閉面板並停用插件"},"ghostPanel": {@@ -4562,6 +4569,10 @@"stackExpandAria": "已收起 {{count}} 個插件面板,點選展開","stackCollapseAria": "收攏插件面板列表"},+ "ghostPanelRestore": {+ "single": "恢復 {{name}}",+ "multiple": "恢復插件面板({{count}})"+ },"rightSidebar": {"ariaLabel": "右側邊欄","panelError": {diff --git a/apps/desktop/src/renderer/layout/LayoutRoot.tsx b/apps/desktop/src/renderer/layout/LayoutRoot.tsxindex 5f477a16cc..d9e4e9adc2 100644--- a/apps/desktop/src/renderer/layout/LayoutRoot.tsx+++ b/apps/desktop/src/renderer/layout/LayoutRoot.tsx@@ -34,7 +34,7 @@ import { PaneWidthProvider, useContentAvailableWidth } from './paneWidths';* 持久化;双击缝 = 两侧份额均分。非 chat 面板的像素宽 = **在场份额** × 可用宽* (经 PaneWidthContext 下发,面板消费);chat-main 弹性吸收剩余(flex-1)。* - **在场份额(active share)**:树上的 fraction 是"全体 pane"的账本,而不渲染的- * pane(未安装残留 / 已抽离 / 已最小化成气泡)那份地方实际被弹性的 chat 吸收 ——+ * pane(未安装残留 / 已抽离 / 已最小化)那份地方实际被弹性的 chat 吸收 ——* 账本与画面脱钩后,像素换算与拖缝余量全都失真。引擎因此一律按* `share = fraction / Σ在场 fraction` 计算(见 activeSplitLedger),隐藏面板的* fraction 一字不动(位置与宽度记忆保留,重装/合并/恢复即原位复活,@@ -59,7 +59,7 @@ const NON_CHAT_FLOOR_PX = 120;/*** pane 是否在本窗口渲染:未注册 kind(未安装/停用的插件残留)、已抽离进- * 独立窗口、以及已最小化为浮动气泡的面板都不渲染 —— 树数据一律保留,+ * 独立窗口、以及已最小化的面板都不渲染 —— 树数据一律保留,* 重装/合并/恢复即原位复活(architecture-invariants「已抽离的面板允许保留* 在存档中但不渲染」)。*/diff --git a/apps/desktop/src/renderer/lib/ghostPanelBubbleState.ts b/apps/desktop/src/renderer/lib/ghostPanelBubbleState.tsindex 60271123c9..44c6763682 100644--- a/apps/desktop/src/renderer/lib/ghostPanelBubbleState.ts+++ b/apps/desktop/src/renderer/lib/ghostPanelBubbleState.ts@@ -1,5 +1,5 @@/**- * ghostPanelBubbleState —— 插件停靠面板「最小化为浮动气泡」的 renderer 端状态。+ * ghostPanelBubbleState —— 插件停靠面板的最小化状态(历史命名沿用 bubble)。** 纯视图态,renderer 自有(localStorage 持久化,重启保留),不经 main:* 与 maximize(会话态)/ detach(main 持久化)三分天下——气泡既要重启保留diff --git a/apps/desktop/src/renderer/panels/PanelChrome.tsx b/apps/desktop/src/renderer/panels/PanelChrome.tsxindex 5ad6c1f92a..c31b0593a5 100644--- a/apps/desktop/src/renderer/panels/PanelChrome.tsx+++ b/apps/desktop/src/renderer/panels/PanelChrome.tsx@@ -20,8 +20,8 @@ import { usePanelMaximize } from '../layout/panelMaximize';** 右端系统按钮(一批,由引擎统一长出,面板作者无感;身份卡* panel.systemButtons 可逐个关闭):- * - 「最小化为浮动气泡」(minimize):传 onMinimize 即得,点击把面板收成- * 可拖动的圆形气泡(状态在 renderer/lib/ghostPanelBubbleState.ts);+ * - 「最小化面板」(minimize):传 onMinimize 即得,点击隐藏停靠面板;恢复入口由+ * 用户偏好决定为浮动气泡或左侧栏(状态在 renderer/lib/ghostPanelBubbleState.ts);* - 「独立窗口」(detach):传 onDetach 即得,点击把面板抽进自己的 OS 窗口* (状态机在 main 的 ghost-panel-window/controller.ts);* - 「撑满内容区」(maximize):传 panelKind 即得,状态在 LayoutRoot 的@@ -45,7 +45,7 @@ export interface PanelChromeProps {panelKind?: string;/** 传入即长出「独立窗口」系统按钮(排在撑满按钮左侧),点击回调归调用方。 */onDetach?: () => void;- /** 传入即长出「最小化为浮动气泡」系统按钮(排在独立窗口按钮左侧)。 */+ /** 传入即长出「最小化面板」系统按钮(排在独立窗口按钮左侧)。 */onMinimize?: () => void;/** 传入即长出「关闭」系统按钮(恒排最右);二次确认等语义归调用方。 */onClose?: () => void;diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex 5bd8a41548..75f3bb346e 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -405,7 +405,8 @@ export interface GhostPanelDecl {/*** 标准头系统按钮开关(2026-07-25):缺省全开,声明 false 逐个关闭。* 当前一批:maximize =「撑满内容区」、detach =「在独立窗口中打开」、- * minimize =「最小化为浮动气泡」。标准头本体(标题条)恒由主机绘制、+ * minimize =「最小化面板」(恢复入口由用户偏好决定为浮动气泡或左侧栏)。+ * 标准头本体(标题条)恒由主机绘制、* 不可关——可配置的只是系统按钮;'tab' 形态没有标准头,声明本字段拒装。* 未知键按规则 9 收词明确拒绝,新按钮上线时在这里扩键。*/diff --git a/apps/desktop/src/shared/ghostPanelWindow.ts b/apps/desktop/src/shared/ghostPanelWindow.tsindex cb31952653..014e8e2991 100644--- a/apps/desktop/src/shared/ghostPanelWindow.ts+++ b/apps/desktop/src/shared/ghostPanelWindow.ts@@ -31,7 +31,7 @@ export const GHOST_PANEL_WINDOW_VISIBILITY_CHANGED_CHANNEL ='ghost-panel-window:visibility-changed';export const GHOST_PANEL_WINDOW_CLOSE_REQUESTED_CHANNEL ='ghost-panel-window:close-requested';-/** main → renderer(send):原生窗口最小化也统一收进主窗口 Ghost 气泡。 */+/** main → renderer(send):原生窗口最小化也统一进入插件面板的最小化状态。 */export const GHOST_PANEL_WINDOW_MINIMIZE_REQUESTED_CHANNEL ='ghost-panel-window:minimize-requested';export const GHOST_PANEL_WINDOW_CLOSE_REQUEST_RESOLVED_CHANNEL =