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): 钉住面板粘性激活连带展开收着的右侧栏

Lizi6f064482e87c
diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
index 8b3f328095..1c49f30ab7 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
@@ -64,6 +64,8 @@ import type { TabKindHostContext, TabKindId, TabState } from './types';
import './plugins';
import { initRsbBrowserBridge } from './lib/rsbBrowserBridge';
import { initPopupRouter, setPopupFallbackSession } from './lib/popupRouter';
+import { requestRightSidebarVisibility } from './lib/sidebarCommands';
+import { readPanelCollapsed } from '@/layout/collapsePrefs';
const log = createLogger('rightSidebar.shell');
/**
@@ -229,6 +231,11 @@ export function RightSidebarShell({
// "有 pill 无内容"的空面板。
// 3) 粘性激活:上一会话正看着某钉住面板 → 切会话后把同一面板带到前台
// (每个 sessionId 只做一次,用户随后在本会话内的切换不被打扰)。
+ // 「带到前台」包括把收着的侧栏打开:目标会话侧栏收着(新会话默认收)时,
+ // 只激活 tab 用户什么都看不见,钉住的"跨对话保留"承诺就断了。仅在
+ // 上一会话侧栏是展开的(用户确实正看着)时才请求展开;上一会话本来就
+ // 收着 → 用户没在看面板,切会话不弹窗打扰。detached 形态下该请求走
+ // userInitiated:false 语义,不会把子窗口抢到前台。
// 插件被停用时 kind 未注册 → 跳过补挂;已存在的页签保留(落 Placeholder,
// 与"停用隐藏、重启用复活"的既有语义一致)。
const stickyAppliedSessionRef = useRef<string | null>(null);
@@ -265,12 +272,21 @@ export function RightSidebarShell({
if (cancelled) return;
// 3) 粘性激活 + 空激活位兜底
const applySticky = stickyAppliedSessionRef.current !== sessionId;
+ const prevSessionId = stickyAppliedSessionRef.current;
stickyAppliedSessionRef.current = sessionId;
const now = getBucket(sessionId);
let target: string | null = null;
const stickyKind = applySticky ? getLastFocusedPinnedGhostKind() : null;
if (stickyKind) {
target = now.tabs.find((t) => t.kind === stickyKind)?.id ?? null;
+ if (
+ target !== null &&
+ prevSessionId !== null && // 首帧(启动进第一个会话)不算"切换",不弹
+ !readPanelCollapsed('right-tabs', { sessionId: prevSessionId }, true) &&
+ readPanelCollapsed('right-tabs', { sessionId }, true)
+ ) {
+ requestRightSidebarVisibility('open', { sessionId, userInitiated: false });
+ }
}
if (!target && now.activeTabId === null && now.tabs.length > 0) {
target = now.tabs[0].id;
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
index 8eeeb3fbc7..620c346e6b 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
@@ -40,6 +40,8 @@ import {
type SidebarVisibilityRequestOptions,
} from '../lib/sidebarCommands';
import { _resetStore, closeTab, getBucket } from '../store';
+import { setGhostTabPinned, setLastFocusedPinnedGhostKind } from '../lib/pinnedGhostTabs';
+import { writePanelCollapsed } from '@/layout/collapsePrefs';
import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';
interface RightSidebarTabsIpcStub {
@@ -873,3 +875,137 @@ describe('RightSidebarShell 跨 session popup 归属', () => {
expect(requests).toHaveLength(0);
});
});
+
+describe('RightSidebarShell 钉住面板粘性展开(切会话把收着的侧栏打开)', () => {
+ let tabsIpc: RightSidebarTabsIpcStub;
+ let requests: Array<{
+ visibility: SidebarVisibilityRequest;
+ opts: SidebarVisibilityRequestOptions;
+ }>;
+ let unsubVisibility: () => void;
+
+ const GHOST_KIND = 'ghost:pr-signoff';
+
+ beforeEach(() => {
+ Object.defineProperty(HTMLElement.prototype, 'scrollTo', {
+ configurable: true,
+ value: vi.fn(),
+ });
+ localStorage.clear();
+ _resetStore();
+ _resetRsbBrowserBridgeForTests();
+ _resetPopupRouterForTests();
+ _resetSidebarCommandsForTests();
+ setLastFocusedPinnedGhostKind(null);
+ rsbBrowserCommandListeners = [];
+ rsbBrowserPopupListeners = [];
+ eagerSpawnAndReport.mockClear();
+ eagerSpawnAndReport.mockImplementation(async () => undefined);
+ requests = [];
+ unsubVisibility = onRequestRightSidebarVisibility((visibility, opts) => {
+ requests.push({ visibility, opts });
+ });
+ setGhostTabPinned('pr-signoff', true); // 无条目 = 不算钉住,先钉上
+ tabsIpc = makeRightSidebarTabsIpc();
+ // 两个会话都带同一块钉住面板页签(补挂在真环境由注册表驱动,单测无插件
+ // 注册,直接让存档里就有)。
+ tabsIpc.list.mockImplementation(async () => ({
+ tabs: [{ id: 'tab-ghost', kind: GHOST_KIND, state: null }],
+ activeTabId: 'tab-ghost',
+ }));
+ installElectronApi(tabsIpc);
+ });
+
+ afterEach(() => {
+ unsubVisibility();
+ setLastFocusedPinnedGhostKind(null);
+ _resetSidebarCommandsForTests();
+ _resetStore();
+ _resetRsbBrowserBridgeForTests();
+ _resetPopupRouterForTests();
+ localStorage.clear();
+ delete (window as unknown as { electronAPI?: unknown }).electronAPI;
+ });
+
+ function renderShell(sessionId: string): ReturnType<typeof render> {
+ return render(
+ createElement(RightSidebarShell, {
+ sessionId,
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ isMac: true,
+ unifiedTopbar: true,
+ }),
+ );
+ }
+
+ function rerenderShell(view: ReturnType<typeof render>, sessionId: string): void {
+ view.rerender(
+ createElement(RightSidebarShell, {
+ sessionId,
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ isMac: true,
+ unifiedTopbar: true,
+ }),
+ );
+ }
+
+ it('上一会话正看着钉住面板且侧栏展开 → 切会话请求展开收着的侧栏', async () => {
+ writePanelCollapsed('right-tabs', { sessionId: 's1' }, false); // s1 侧栏展开
+ // s2 无存档 = 默认收着
+
+ const view = renderShell('s1');
+ await waitFor(() => expect(getBucket('s1').tabs).toHaveLength(1));
+ setLastFocusedPinnedGhostKind(GHOST_KIND); // 用户正看着钉住面板
+
+ rerenderShell(view, 's2');
+ await waitFor(() => expect(requests.length).toBeGreaterThan(0));
+ expect(requests[0].visibility).toBe('open');
+ expect(requests[0].opts.sessionId).toBe('s2');
+ // 程序自发的跟随,不是用户手势:detached 形态下不得抢前台。
+ expect(requests[0].opts.userInitiated).toBe(false);
+ });
+
+ it('上一会话侧栏本来就收着 → 不弹', async () => {
+ writePanelCollapsed('right-tabs', { sessionId: 's1' }, true); // s1 也收着
+
+ const view = renderShell('s1');
+ await waitFor(() => expect(getBucket('s1').tabs).toHaveLength(1));
+ setLastFocusedPinnedGhostKind(GHOST_KIND);
+
+ rerenderShell(view, 's2');
+ await waitFor(() => expect(getBucket('s2').tabs).toHaveLength(1));
+ await act(async () => {
+ await Promise.resolve();
+ });
+ expect(requests).toHaveLength(0);
+ });
+
+ it('没有粘性焦点(用户没在看面板) → 不弹', async () => {
+ writePanelCollapsed('right-tabs', { sessionId: 's1' }, false);
+
+ const view = renderShell('s1');
+ await waitFor(() => expect(getBucket('s1').tabs).toHaveLength(1));
+ // 不设粘性焦点
+
+ rerenderShell(view, 's2');
+ await waitFor(() => expect(getBucket('s2').tabs).toHaveLength(1));
+ await act(async () => {
+ await Promise.resolve();
+ });
+ expect(requests).toHaveLength(0);
+ });
+
+ it('首帧(启动进第一个会话)不算切换 → 不弹', async () => {
+ writePanelCollapsed('right-tabs', { sessionId: 's1' }, true);
+ setLastFocusedPinnedGhostKind(GHOST_KIND);
+
+ renderShell('s1');
+ await waitFor(() => expect(getBucket('s1').tabs).toHaveLength(1));
+ await act(async () => {
+ await Promise.resolve();
+ });
+ expect(requests).toHaveLength(0);
+ });
+});