Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 隔离侧栏预热上下文
DavidShenffd673c4044e
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.tsindex 0055b452f4..18537af09b 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts@@ -656,16 +656,20 @@ describe('setContext / routeCommand', () => {return { command: { type: 'open-terminal' as const, sessionId }, allowOpen };}- it('caches context; forwards only when window alive', () => {+ it('keeps live context out of a hidden prewarm and exposes it after opening', () => {const h = makeHarness();- h.controller.setContext(ctx);- expect(h.sends).toHaveLength(0);- expect(h.controller.getContext()).toEqual(ctx);-h.controller.prewarm();const win = h.windows[0];markReady(h.controller, win);+ h.controller.setContext(ctx);+ expect(h.sends.filter((entry) => entry.channel === 'ctx-channel')).toEqual([]);+ expect(h.controller.getContext()).toBeNull();+h.controller.open();+ expect(h.controller.getContext()).toEqual(ctx);+ h.controller.refreshContext(win.webContents as unknown as WebContents);+ expect(h.sends.at(-1)).toEqual({ channel: 'ctx-channel', payload: ctx });+h.controller.setContext({ ...ctx, sessionId: 's2' });expect(h.sends.at(-1)).toEqual({channel: 'ctx-channel',diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.tsindex aec0ebce0e..698e7c3c91 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts@@ -176,6 +176,7 @@ describe('sidebarWindowPreload 椤跺眰濂戠害', () => {'fileBrowser', 'terminal', 'gitReview', 'processMonitor', 'rsbNativePopup','openExternal', 'openFileInBrowser', 'openPath', 'showItemInFolder','copyMediaToClipboard', 'openMediaWithDefaultApp', 'saveMediaAs',+ 'cacheMediaForSession', 'readImageBytes', 'readCachedImageAsBase64','getFilePath', 'cacheImageFromBuffer', 'maker', 'localDb', 'ghosts',]));expect(fileBrowserKeys).toEqual(expect.arrayContaining([@@ -210,7 +211,6 @@ describe('sidebarWindowPreload 椤跺眰濂戠害', () => {'updater', 'chat', 'session','resourceUsageWindow', 'ghostPanelWindow','pluginMarket', 'deepLink', 'gitContext',- 'cacheMediaForSession','safeStorageStore', 'safeStorageRead', 'safeStorageRemove',];for (const key of forbidden) {diff --git a/apps/desktop/src/main/right-sidebar-window/controller.ts b/apps/desktop/src/main/right-sidebar-window/controller.tsindex aa06c56cf8..1c8cc7b58f 100644--- a/apps/desktop/src/main/right-sidebar-window/controller.ts+++ b/apps/desktop/src/main/right-sidebar-window/controller.ts@@ -337,14 +337,16 @@ export class RsbWindowController {if (sessionId !== ctx.sessionId) this.deferredCommands.delete(sessionId);}}- if (this.winRef && !this.winRef.isDestroyed()) {+ if (this.visible && this.winRef && !this.winRef.isDestroyed()) {this.deps.sendToWindow(this.winRef, this.deps.contextChannel, ctx);}this.flushDeferredCommandsToDetachedHost();}getContext(): RsbWindowContext | null {- return this.lastContext;+ // 隐藏预热只准备 renderer 壳,不注入当前任务上下文。真实显示后由+ // visibility-changed → refreshContext 交付最新缓存,避免后台 hydrate 会话面板。+ return this.visible ? this.lastContext : null;}/** main 原子裁决 command ownership;renderer 只在 attached 结果下写本地 store。 */diff --git a/apps/desktop/src/preload/sidebarWindowPreload.ts b/apps/desktop/src/preload/sidebarWindowPreload.tsindex 0348f39f6c..b1568c016f 100644--- a/apps/desktop/src/preload/sidebarWindowPreload.ts+++ b/apps/desktop/src/preload/sidebarWindowPreload.ts@@ -245,6 +245,16 @@ contextBridge.exposeInMainWorld('electronAPI', {openMediaWithDefaultApp: (params: unknown): Promise<void> =>ipcRenderer.invoke('media:open-with-default-app', params),saveMediaAs: (params: unknown): Promise<unknown> => ipcRenderer.invoke('media:save-as', params),+ cacheMediaForSession: (params: {+ url: string;+ sessionId: string;+ }): Promise<unknown> => ipcRenderer.invoke('media:cache-for-session', params),+ readImageBytes: (params: { url: string }): Promise<{ base64: string; mimeType: string }> =>+ ipcRenderer.invoke('media:read-image-bytes', params),+ readCachedImageAsBase64: (+ params: { url: string },+ ): Promise<{ base64: string; mimeType: string }> =>+ ipcRenderer.invoke('image-cache:read-base64', params),getFilePath: (file: File): string => {try {return webUtils.getPathForFile(file);diff --git a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsxindex 91581a06c0..d20df8987e 100644--- a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx@@ -257,7 +257,7 @@ export function SidebarWindowLayout() {</div>)}</div>- <GhostMediaLightboxHost />+ <GhostMediaLightboxHost sessionId={sessionId ?? undefined} /></div>);}diff --git a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsxindex 4429377dcf..0c20c582e5 100644--- a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx+++ b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx@@ -11,6 +11,7 @@ const mocks = vi.hoisted(() => ({ghostMinimizeListener: null as (() => void) | null,ghostMinimizeEnabled: true,sidebarShellVisible: undefined as boolean | undefined,+ sidebarLightboxSessionId: undefined as string | undefined,minimizeGhostPanel: vi.fn(),restoreGhostPanel: vi.fn(),}));@@ -60,7 +61,12 @@ vi.mock('@/cindy-brain/ghostPanels', () => ({ensureGhostPanelsRegistered: vi.fn(),useGhostPanelsSync: vi.fn(),}));-vi.mock('@/cindy-brain/GhostMediaLightboxHost', () => ({ GhostMediaLightboxHost: () => null }));+vi.mock('@/cindy-brain/GhostMediaLightboxHost', () => ({+ GhostMediaLightboxHost: ({ sessionId }: { sessionId?: string }) => {+ mocks.sidebarLightboxSessionId = sessionId;+ return null;+ },+}));vi.mock('@/cindy-brain/ghostPanelBody', () => ({GhostChipPanelBody: () => null,GhostPanelError: () => null,@@ -128,6 +134,7 @@ describe('reusable auxiliary window chrome', () => {mocks.ghostMinimizeListener = null;mocks.ghostMinimizeEnabled = true;mocks.sidebarShellVisible = undefined;+ mocks.sidebarLightboxSessionId = undefined;Object.defineProperty(window, 'electronAPI', {configurable: true,value: {@@ -276,6 +283,21 @@ describe('reusable auxiliary window chrome', () => {expect(mocks.sidebarShellVisible).toBe(false);});+ it('passes the active sidebar session to the media lightbox host', async () => {+ window.electronAPI.rightSidebarWindow.getContext = vi.fn(() =>+ Promise.resolve({+ sessionId: 'session-a',+ workdir: '/workdir',+ remoteHostId: null,+ available: true,+ }),+ );++ render(<SidebarWindowLayout />);++ await waitFor(() => expect(mocks.sidebarLightboxSessionId).toBe('session-a'));+ });+it('respects a plugin manifest that disables minimize in the detached window', async () => {mocks.ghostMinimizeEnabled = false;