Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): 补齐任务页路由、安装入口与截图校验
Dash4f984ad62ac7
diff --git a/apps/desktop/src/main/cindy-brain/GhostManager.ts b/apps/desktop/src/main/cindy-brain/GhostManager.tsindex cdf5e5fba9..40841027dc 100644--- a/apps/desktop/src/main/cindy-brain/GhostManager.ts+++ b/apps/desktop/src/main/cindy-brain/GhostManager.ts@@ -3533,6 +3533,14 @@ export class GhostManager {},};}+ if (v.manifest.taskView && !zip.file(`${prefix}${v.manifest.taskView.html}`)) {+ return {+ rejection: {+ code: 'file-invalid',+ reason: `清单声明了 taskView.html,但压缩包内缺少 ${v.manifest.taskView.html}`,+ },+ };+ }let localizedManifest = withGhostResolvedLocale(v.manifest, locale);const localeResources: Record<string, GhostManifestLocaleResource> = {};if (v.manifest.locales !== undefined) {diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.tsindex c21acc5b4c..2b3771e46a 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts@@ -3447,21 +3447,23 @@ describe('GhostManager · install', () => {await expectRejection(await manager.install(cindy), 'file-invalid');});- it('main-view 清单声明的 HTML 不在包内 → inspect/install 都拒绝', async () => {+ // 安装入口与 Forge 必须同样拒绝缺失页面;原先只覆盖 main-view,task-view 会漏装。+ it.each(['main-view', 'task-view'] as const)('%s 清单声明的 HTML 不在包内 → inspect/install 都拒绝', async (slot) => {+ const field = slot === 'main-view' ? 'mainView' : 'taskView';const manifest = {...goodManifest(),minCindyVersion: '1.2.3',- slots: ['tool', 'main-view'],- mainView: { html: 'ui/main-view.html' },+ slots: ['tool', slot],+ [field]: { html: `ui/${slot}.html` },};- const cindy = await makeCindy('missing-main-view.cindy', manifest, {+ const cindy = await makeCindy(`missing-${slot}.cindy`, manifest, {'main.js': '// browser entry',});expect(await manager.inspect(cindy)).toMatchObject({rejection: {code: 'file-invalid',- reason: expect.stringContaining('ui/main-view.html'),+ reason: expect.stringContaining(`ui/${slot}.html`),},});await expectRejection(await manager.install(cindy), 'file-invalid');diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.tsindex 07559f2f2a..dc067627da 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostModelImages.test.ts@@ -9,6 +9,7 @@ import {const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13]).toString('base64');const JPEG = Buffer.from([0xff, 0xd8, 0xff, 0xe0, 1, 2, 3]).toString('base64');const SVG = Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"></svg>').toString('base64');+const VALID_PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAAEElEQVQImWNgYGD4D8UQBgAd9AP9JAD7OgAAAABJRU5ErkJggg==', 'base64');describe('normalizeGhostModelImages', () => {it('keeps PNG and JPEG with the format sniffed from the bytes, not the claimed type', () => {@@ -28,12 +29,17 @@ describe('normalizeGhostModelImages', () => {});describe('fitGhostModelImages', () => {+ // 小于预算的损坏图片也不能进入模型请求;此前只有文件头便被原样返回。+ it('omits a truncated PNG even when it fits the budget', async () => {+ expect(await fitGhostModelImages([{ data: PNG, mimeType: 'image/png' }], vi.fn()))+ .toEqual({ images: [], omitted: 1 });+ });it('passes small images through untouched and shares the budget between images', async () => {const compress = vi.fn();- const small = { data: Buffer.alloc(100, 1).toString('base64'), mimeType: 'image/png' };+ const small = { data: VALID_PNG.toString('base64'), mimeType: 'image/png' };expect(await fitGhostModelImages([small], compress, 1000)).toEqual({ images: [small], omitted: 0 });expect(compress).not.toHaveBeenCalled();- const big = { data: Buffer.alloc(800, 1).toString('base64'), mimeType: 'image/png' };+ const big = { data: Buffer.concat([VALID_PNG, Buffer.alloc(800)]).toString('base64'), mimeType: 'image/png' };compress.mockResolvedValue({ buffer: Buffer.alloc(400), mime: 'image/webp' });const fitted = await fitGhostModelImages([small, big], compress, 1000);expect(compress).toHaveBeenCalledWith(expect.any(Buffer), 'image/png', { targetBytes: 500 });@@ -41,7 +47,7 @@ describe('fitGhostModelImages', () => {});it('leaves out an image that cannot be made small enough, and counts it', async () => {- const big = { data: Buffer.alloc(2000, 1).toString('base64'), mimeType: 'image/jpeg' };+ const big = { data: Buffer.concat([VALID_PNG, Buffer.alloc(2000)]).toString('base64'), mimeType: 'image/png' };expect(await fitGhostModelImages([big], vi.fn().mockResolvedValue(null), 1000)).toEqual({ images: [], omitted: 1 });expect(await fitGhostModelImages([big], vi.fn().mockResolvedValue({ buffer: Buffer.alloc(1500), mime: 'image/webp' }), 1000)).toEqual({ images: [], omitted: 1 });diff --git a/apps/desktop/src/main/cindy-brain/ghostModelImages.ts b/apps/desktop/src/main/cindy-brain/ghostModelImages.tsindex 9d3c61f28d..2848aea5dc 100644--- a/apps/desktop/src/main/cindy-brain/ghostModelImages.ts+++ b/apps/desktop/src/main/cindy-brain/ghostModelImages.ts@@ -13,6 +13,7 @@*/import type { GhostModelImage } from '../../shared/ghost.js';import { sniffMediaMime } from '../cindy-media/sniffMediaMime.js';+import { isDecodableInlineImage } from '../mcp-integrations/inlineImageCompressor.js';export const GHOST_MODEL_IMAGE_MAX_COUNT = 2;/** Decoded bytes per image before re-encoding. */@@ -75,6 +76,10 @@ export async function fitGhostModelImages(let omitted = 0;for (const image of images) {const buffer = Buffer.from(image.data, 'base64');+ if (!(await isDecodableInlineImage(buffer))) {+ omitted++;+ continue;+ }if (buffer.byteLength <= share) {out.push(image);continue;diff --git a/apps/desktop/src/main/mcp-integrations/inlineImageCompressor.ts b/apps/desktop/src/main/mcp-integrations/inlineImageCompressor.tsindex 151e267925..95665c05b4 100644--- a/apps/desktop/src/main/mcp-integrations/inlineImageCompressor.ts+++ b/apps/desktop/src/main/mcp-integrations/inlineImageCompressor.ts@@ -51,6 +51,18 @@ const LADDER: ReadonlyArray<{ maxEdgePx: number; webpQuality: number }> = [const TIMEOUT_MS = 5_000;+/** Decode untrusted plugin images even when their bytes already fit inline. */+export async function isDecodableInlineImage(buffer: Buffer): Promise<boolean> {+ const sharp = loadSharp();+ if (!sharp) return false;+ try {+ await sharp(buffer, { failOn: 'warning' }).resize(1, 1).raw().toBuffer();+ return true;+ } catch {+ return false;+ }+}+/*** CompressInlineImageFn 实现。返回压缩后的 { buffer, mime },或 null 表示* "按原样内联"(已达标 / 不可解码 / sharp 缺失 / 超时)。永不 throw。diff --git a/apps/desktop/src/main/sidebar-tab-window/__tests__/controller.test.ts b/apps/desktop/src/main/sidebar-tab-window/__tests__/controller.test.tsindex 726a0fee20..10150045ca 100644--- a/apps/desktop/src/main/sidebar-tab-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/sidebar-tab-window/__tests__/controller.test.ts@@ -225,6 +225,21 @@ describe('SidebarTabWindowsController', () => {expect(win.focus).toHaveBeenCalledTimes(2);});+ // focus 的对外结果包括选中具体页签;后台插件请求不能抢原生窗口焦点。+ it('sends the target tab selection to its host without native focus for background requests', () => {+ const h = makeHarness();+ h.controller.open(request('tab-a'));+ const win = h.created[0];+ h.controller.markRendererReady(h.wc(win));+ h.controller.markPresentationReady(h.wc(win));+ h.controller.open({ ...request('tab-b'), targetWindowId: h.controller.getState()['tab-a'].windowId });+ win.focus.mockClear(); win.show.mockClear();+ h.controller.focus('tab-a', { userInitiated: false });+ expect(h.sends.at(-1)).toMatchObject({ channel: SIDEBAR_TAB_WINDOW_ASSIGNED_CHANNEL, payload: { revealTabId: 'tab-a' } });+ expect(win.focus).not.toHaveBeenCalled();+ expect(win.show).not.toHaveBeenCalled();+ });+it('returns the tab to the sidebar with its snapshot on merge-back and destroys the window', () => {const h = makeHarness();h.controller.open(request('tab-a'));diff --git a/apps/desktop/src/main/sidebar-tab-window/__tests__/ipc.test.ts b/apps/desktop/src/main/sidebar-tab-window/__tests__/ipc.test.tsindex 789850ccb3..a259f49c5f 100644--- a/apps/desktop/src/main/sidebar-tab-window/__tests__/ipc.test.ts+++ b/apps/desktop/src/main/sidebar-tab-window/__tests__/ipc.test.ts@@ -91,6 +91,18 @@ function register(controller: ReturnType<typeof makeController>) {}describe('sidebar-tab-window IPC', () => {+ // 扩展已有 focus 请求时保留旧调用默认,并拒绝不合法的后台手势标记。+ it('validates optional focus intent and preserves legacy foreground requests', async () => {+ const controller = makeController();+ register(controller);+ const focus = handlers().get(MAKER_INVOKE.SIDEBAR_TAB_WINDOW_FOCUS)!;+ await call(focus, { sender: mainSender }, 'tab-a');+ expect(controller.focus).toHaveBeenLastCalledWith('tab-a', { userInitiated: true });+ await call(focus, { sender: mainSender }, 'tab-a', { userInitiated: false });+ expect(controller.focus).toHaveBeenLastCalledWith('tab-a', { userInitiated: false });+ await expect(call(focus, { sender: mainSender }, 'tab-a', { userInitiated: 'false' })).rejects.toThrow(/INVALID_PARAMS/);+ expect(controller.focus).toHaveBeenCalledTimes(2);+ });it('only the main window may pop a tab out, and the payload must be well-formed', async () => {const controller = makeController();register(controller);diff --git a/apps/desktop/src/main/sidebar-tab-window/controller.ts b/apps/desktop/src/main/sidebar-tab-window/controller.tsindex 8b99e16894..46bac355da 100644--- a/apps/desktop/src/main/sidebar-tab-window/controller.ts+++ b/apps/desktop/src/main/sidebar-tab-window/controller.ts@@ -256,10 +256,12 @@ export class SidebarTabWindowsController {}/** 聚焦已弹出页签的窗口;未弹出 / 仍在等首份内容时 no-op。 */- focus(tabId: string): void {+ focus(tabId: string, options: { userInitiated?: boolean } = {}): void {const slot = this.slotForTab(tabId);if (!slot || slot.win.isDestroyed()) return;if (!slot.visible) return;+ this.deliverAssignment(slot, tabId);+ if (options.userInitiated === false) return;if (slot.win.isMinimized()) slot.win.restore();slot.win.show();slot.win.focus();@@ -517,7 +519,7 @@ export class SidebarTabWindowsController {return slot;}- private deliverAssignment(slot: WindowSlot): void {+ private deliverAssignment(slot: WindowSlot, revealTabId?: string): void {if (!slot.assignment || slot.win.isDestroyed()) return;// 壳还没挂上:等 renderer-ready 时再送(它会主动 getAssignment / 收推送)。if (!slot.rendererReady) return;@@ -525,6 +527,7 @@ export class SidebarTabWindowsController {const payload: SidebarTabWindowAssignmentPayload = {...slot.assignment,handoff: slot.handoff,+ ...(revealTabId ? { revealTabId } : {}),};this.deps.sendToWindow(slot.win, SIDEBAR_TAB_WINDOW_ASSIGNED_CHANNEL, payload);}diff --git a/apps/desktop/src/main/sidebar-tab-window/ipc.ts b/apps/desktop/src/main/sidebar-tab-window/ipc.tsindex effed6f429..20a735d5e2 100644--- a/apps/desktop/src/main/sidebar-tab-window/ipc.ts+++ b/apps/desktop/src/main/sidebar-tab-window/ipc.ts@@ -174,10 +174,14 @@ export function registerSidebarTabWindowIpc(opts: {}});- ipcMain.handle(MAKER_INVOKE.SIDEBAR_TAB_WINDOW_FOCUS, (event, tabId: unknown) => {+ ipcMain.handle(MAKER_INVOKE.SIDEBAR_TAB_WINDOW_FOCUS, (event, tabId: unknown, options?: unknown) => {assertTrustedAppRendererEvent(event);const id = requireId(tabId, 'tabId');- controller.focus(id);+ const opts = options === undefined ? {} : requireObject(options, 'options');+ if (opts.userInitiated !== undefined && typeof opts.userInitiated !== 'boolean') {+ throwIpcError('INVALID_PARAMS', 'userInitiated must be a boolean');+ }+ controller.focus(id, { userInitiated: opts.userInitiated !== false });});ipcMain.handle(MAKER_INVOKE.SIDEBAR_TAB_WINDOW_RETURN_TAB, (event, tabId: unknown) => {diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.tsindex da3b8b9213..d1c8cd41e8 100644--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@ -2068,8 +2068,8 @@ contextBridge.exposeInMainWorld('electronAPI', {/** 把页签弹出到独立窗口;已弹出则聚焦。 */open: (request: SidebarTabWindowOpenRequest): Promise<void> =>ipcRenderer.invoke('maker:sidebar-tab-window:open', request),- focus: (tabId: string): Promise<void> =>- ipcRenderer.invoke('maker:sidebar-tab-window:focus', tabId),+ focus: (tabId: string, options?: { userInitiated?: boolean }): Promise<void> =>+ ipcRenderer.invoke('maker:sidebar-tab-window:focus', tabId, options),/** 页签已在侧边栏关闭:销毁其弹出窗口,不交回。 */closeForTab: (tabId: string): Promise<void> =>ipcRenderer.invoke('maker:sidebar-tab-window:close-for-tab', tabId),diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.tsindex af458bba49..ddd5885955 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts@@ -2,12 +2,22 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';import { makerChatStore } from '@/lib/makerChatStore';import { clearSessionAttention, getSessionAttentionKind } from '@/lib/sessionAttentionStore';+import { openPluginTaskTab } from '@/features/right-sidebar/lib/openPluginTaskTab';+import { openUrlInSidebarBrowser } from '@/features/right-sidebar/lib/openInSidebarBrowser';vi.mock('@/lib/sessionsBus', () => ({ emitPatch: vi.fn() }));+const windowRole = vi.hoisted(() => ({ secondary: false, sidebar: false }));+vi.mock('@/lib/secondaryWindow', () => ({ isSecondaryWindow: () => windowRole.secondary }));+vi.mock('@/lib/sidebarWindow', () => ({ isSidebarWindow: () => windowRole.sidebar }));+vi.mock('@/features/right-sidebar/lib/openPluginTaskTab', () => ({ openPluginTaskTab: vi.fn(async () => {}) }));+vi.mock('@/features/right-sidebar/lib/openInSidebarBrowser', () => ({ openUrlInSidebarBrowser: vi.fn(async () => {}) }));+vi.mock('@/lib/toast', () => ({ toast: { info: vi.fn() } }));const sessionId = 'make-ingress';let created: (payload: unknown, ownerStamp?: unknown) => void;let remote: (payload: unknown) => void;+let taskView: typeof created;+let preview: typeof created;let leave: (() => void) | undefined;function message(status: string, overrides: Record<string, unknown> = {}) {@@ -30,10 +40,16 @@ function message(status: string, overrides: Record<string, unknown> = {}) {}beforeEach(() => {+ vi.clearAllMocks();+ windowRole.secondary = false; windowRole.sidebar = false;setDataOwnerGeneration('make-owner', 1);const subscribe = () => () => {};vi.stubGlobal('window', {electronAPI: {+ ghosts: {+ onTaskViewOpen: (cb: typeof created) => { taskView = cb; return () => {}; },+ onPreviewOpen: (cb: typeof created) => { preview = cb; return () => {}; },+ },maker: {onEvent: subscribe,onStatusChanged: subscribe,@@ -72,6 +88,16 @@ afterEach(() => {});describe('Make result dots at the real message ingress', () => {+ // 同一主进程广播只允许一个 renderer 落页签;原有消息点测试不覆盖插件开页。+ // 最小失败输入:副任务窗口收到 taskView/preview 广播(unit,无真实窗口)。+ it.each(['primary', 'secondary', 'sidebar'] as const)('routes plugin page broadcasts only in the primary renderer: %s', async (role) => {+ windowRole.secondary = role === 'secondary'; windowRole.sidebar = role === 'sidebar';+ taskView({ instanceId: 'sim', sessionId });+ preview({ name: 'Simulator', url: 'http://127.0.0.1:5000', sessionId });+ await Promise.resolve();+ expect(openPluginTaskTab).toHaveBeenCalledTimes(role === 'primary' ? 1 : 0);+ expect(openUrlInSidebarBrowser).toHaveBeenCalledTimes(role === 'primary' ? 1 : 0);+ });it.each(['local', 'remote'])('updates %s dots without mounting the card or running an Agent',(origin) => {diff --git a/apps/desktop/src/renderer/components/layout/SidebarTabWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/SidebarTabWindowLayout.tsxindex 8f16054fa8..e5845ed104 100644--- a/apps/desktop/src/renderer/components/layout/SidebarTabWindowLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/SidebarTabWindowLayout.tsx@@ -50,6 +50,7 @@ import {isGlobalTabId,removeGlobalTab,useGlobalTabs,+ requestRevealSessionTab,} from '@/features/right-sidebar/globalTabs';import { WindowControls } from '@/components/title-bar/WindowControls';import { ChromeIconButton } from '@/components/title-bar/ChromeIconButton';@@ -129,6 +130,9 @@ export function SidebarTabWindowLayout() {}for (const id of [...seenRef.current]) if (!nextIds.has(id)) seenRef.current.delete(id);setAssignment(next);+ if (next.sessionId && next.revealTabId && nextIds.has(next.revealTabId)) {+ requestRevealSessionTab(next.sessionId, next.revealTabId);+ }}, []);// mount:订阅指派推送 + 主动拉一次(重载 / 推送早于订阅)+ renderer-ready 握手。diff --git a/apps/desktop/src/renderer/features/bots/BotHistorySessionView.tsx b/apps/desktop/src/renderer/features/bots/BotHistorySessionView.tsxindex 2791485496..0fe9808a69 100644--- a/apps/desktop/src/renderer/features/bots/BotHistorySessionView.tsx+++ b/apps/desktop/src/renderer/features/bots/BotHistorySessionView.tsx@@ -6,6 +6,7 @@ import { CCAgentSessionView } from '@/features/cc-agent/CCAgentSessionView';import type { BotChatIdentity } from './BotSessionContentHeader';import { readIslandEntryRouteState, requestIslandEntryAlertDisposal } from './islandEntryAlert';import { useBotIslandVisibleSession } from './useBotIslandVisibleSession';+import { useBotPluginFocusedSession } from './useBotPluginFocusedSession';import { remoteProjectsStore } from '@/features/device-link/remoteProjectsStore';import { getDataOwnerGeneration, isDataOwnerGenerationCurrent } from '@/contexts/dataOwnerGeneration';import type { Session } from '@/lib/ccAgent.types';@@ -31,6 +32,7 @@ function BotHistorySessionGateView() {const { t } = useTranslation();const { botId, sessionId, deviceId } = useParams();const [allowed, setAllowed] = useState<boolean | null>(null);+ useBotPluginFocusedSession(allowed === true && !deviceId ? sessionId ?? null : null);useBotIslandVisibleSession(allowed === true ? sessionId ?? null : null);// 灵动岛点进来的那张卡,只在本门禁确认并显示了这段历史后才处置;被重定向走则保留。const islandEntryId = readIslandEntryRouteState(useLocation().state);diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsxindex 8e0fab100e..4d2d2ec16d 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botIslandVisibility.test.tsx@@ -202,15 +202,15 @@ describe('history ownership gate disposes the clicked island card', () => {});});-describe('chat as the task in front for plugins', () => {+describe.each([BotSessionView, BotHistorySessionView])('validated task in front for plugins', (View) => {// A companion chat is where someone uses the simulator; plugins were told "no task"// there, so "open in the current task" failed. Report it once ownership is proven.it('reports the validated chat, never an unowned route, and clears it on leave', async () => {mocks.supported = false;- const view = render(<BotSessionView />);+ const view = render(<View />);await waitFor(() => expect(focus).toHaveBeenLastCalledWith('chat-a'));mocks.params = { botId: 'bot-b', sessionId: 'not-owned' };- view.rerender(<BotSessionView />);+ view.rerender(<View />);await act(async () => {});expect(focus).not.toHaveBeenCalledWith('not-owned');expect(focus).toHaveBeenLastCalledWith(null);diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsxindex 229cd566e1..4210a1e3df 100644--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx@@ -681,13 +681,17 @@ export function RightSidebarShell({);// 程序打开的任务页签(插件任务页)要露出来:与用户点选同口径离开本组的全局页签。- const revealContextRef = useRef({ activeGlobalTabId, inGroup, pinnedTabs });- revealContextRef.current = { activeGlobalTabId, inGroup, pinnedTabs };+ const revealContextRef = useRef({ activeGlobalTabId, inGroup, pinnedTabs, hostedTabIds });+ revealContextRef.current = { activeGlobalTabId, inGroup, pinnedTabs, hostedTabIds };useEffect(() => {- if (soloMode || !sessionId) return undefined;+ if (!sessionId) return undefined;return subscribeRevealSessionTab((targetSessionId, tabId) => {if (targetSessionId !== sessionId) return;const context = revealContextRef.current;+ if (soloMode) {+ if (context.hostedTabIds?.has(tabId)) setHostedActiveTabId(tabId);+ return;+ }if (!context.inGroup(tabId)) return;setGroupActiveTabId(groupId, sessionId, tabId);const activeGlobal = context.activeGlobalTabId;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.tsindex 7322073bc8..6b2265fbb1 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@@ -93,6 +93,7 @@ import {__resetGlobalTabsForTest,addGlobalPluginTab,getActiveGlobalTabId,+ requestRevealSessionTab,} from '../globalTabs';import { __resetTabGroupsForTest, getTabGroup } from '../tabGroups';import { toast } from '@/lib/toast';@@ -1669,6 +1670,29 @@ describe('RightSidebarShell empty state', () => {// - 现有覆盖缺口:相邻用例只覆盖可用性过滤(subagents / retired),没有跨窗口归属。// - 最小失败输入:两页签会话 + 镜像标记 active 页签已弹出。// - tier:unit(jsdom,进程内 store 与镜像,无 IPC)。+ // 独立窗口多页签时,main 转来的 reveal 必须改变窗口内部激活位,不写主窗的任务桶。+ it('selects only hosted tabs when a popped-out window receives a reveal request', async () => {+ tabsIpc.list.mockResolvedValueOnce({+ tabs: [+ { id: 'tab-files', kind: 'file-browser', state: null },+ { id: 'tab-web', kind: 'web-browser', state: null },+ ],+ activeTabId: 'tab-files',+ });+ const selected = vi.fn();+ render(createElement(RightSidebarShell, {+ sessionId: 's1', workdir: '/tmp/repo', remoteHostId: null, isMac: true,+ hostedTabIds: new Set(['tab-files', 'tab-web']), onActiveTabChange: selected,+ }));+ await waitFor(() => expect(selected).toHaveBeenLastCalledWith('tab-web'));+ tabsIpc.setActive.mockClear();+ act(() => requestRevealSessionTab('s1', 'tab-files'));+ await waitFor(() => expect(selected).toHaveBeenLastCalledWith('tab-files'));+ act(() => requestRevealSessionTab('s1', 'foreign-tab'));+ expect(selected).toHaveBeenLastCalledWith('tab-files');+ expect(tabsIpc.setActive).not.toHaveBeenCalled();+ });+it('hides popped-out tabs from the sidebar and keeps the solo window on its own tab', async () => {registerTabKind({kind: 'terminal',diff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/__tests__/openPluginTaskTab.test.ts b/apps/desktop/src/renderer/features/right-sidebar/lib/__tests__/openPluginTaskTab.test.tsindex 11bdcaad53..7f6589683d 100644--- a/apps/desktop/src/renderer/features/right-sidebar/lib/__tests__/openPluginTaskTab.test.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/__tests__/openPluginTaskTab.test.ts@@ -10,6 +10,7 @@ import { routeSidebarCommand } from '../detachedSidebarRouting';import { subscribeRevealSessionTab } from '../../globalTabs';import { openPluginTaskTab } from '../openPluginTaskTab';import { _resetSidebarCommandsForTests, onRequestRightSidebarVisibility } from '../sidebarCommands';+import { __resetSidebarTabWindowsStateForTest, __setSidebarTabWindowsStateForTest } from '@/lib/sidebarTabWindowState';vi.mock('../detachedSidebarRouting', () => ({ routeSidebarCommand: vi.fn(async () => 'attached') }));@@ -29,6 +30,7 @@ const ipc = {const visibility = vi.fn();beforeEach(() => {+ __resetSidebarTabWindowsStateForTest();_resetStore(); _resetSidebarCommandsForTests();rows.clear(); active.clear(); localStorage.clear(); vi.clearAllMocks();vi.mocked(routeSidebarCommand).mockResolvedValue('attached');@@ -41,6 +43,17 @@ const taskTabs = (sessionId: string) =>getBucket(sessionId).tabs.filter((tab) => tab.kind === 'plugin-task').map((tab) => tab.state);describe('openPluginTaskTab', () => {+ // 弹出窗口自己的激活位与主窗任务桶不同;即使桶已激活目标也必须送选中请求。+ it('reveals an existing popped-out tab without stealing native focus', async () => {+ await openPluginTaskTab('task-1', 'sim');+ const tab = getBucket('task-1').tabs[0];+ __setSidebarTabWindowsStateForTest({ [tab.id]: { windowId: 'window-1', sessionId: 'task-1', open: true } });+ const focus = vi.fn(async () => {});+ window.electronAPI.sidebarTabWindow = { focus } as unknown as Window['electronAPI']['sidebarTabWindow'];+ await openPluginTaskTab('task-1', 'sim', { userInitiated: false });+ expect(focus).toHaveBeenCalledWith(tab.id, { userInitiated: false });+ expect(taskTabs('task-1')).toEqual([{ instanceId: 'sim' }]);+ });it('keeps one task page per plugin per task, refocusing it instead of adding another', async () => {const reveal = vi.fn();const stop = subscribeRevealSessionTab(reveal);diff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts b/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.tsindex 8fcd8724cc..e8a3e6aebe 100644--- a/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts@@ -29,7 +29,7 @@ export async function openPluginTaskTab();let tabId = existing?.id;if (existing) {- if (bucket.activeTabId !== existing.id) await setActiveTab(sessionId, existing.id);+ await setActiveTab(sessionId, existing.id, { userInitiated });} else {tabId = (await addTab(sessionId, 'plugin-task', { instanceId } satisfies PluginTaskTabState)).id;diff --git a/apps/desktop/src/renderer/features/right-sidebar/store.ts b/apps/desktop/src/renderer/features/right-sidebar/store.tsindex 24ae69d347..a149ad168c 100644--- a/apps/desktop/src/renderer/features/right-sidebar/store.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/store.ts@@ -1262,15 +1262,17 @@ export async function closeAllTabs(sessionId: string): Promise<void> {}/** 切换激活 tab —— 同 id 即 noop。失败回滚。 */-export async function setActiveTab(sessionId: string, tabId: string | null): Promise<void> {+export async function setActiveTab(sessionId: string, tabId: string | null, options?: { userInitiated?: boolean }): Promise<void> {const prev = getBucket(sessionId);- if (tabId === prev.activeTabId) return;// 目标页签活在弹出的独立窗口里:侧边栏没有它的 body 可切,「激活它」= 把那扇// 窗口叫到前台(用户点单例入口 / agent focus 都走这里)。if (tabId !== null && !isSidebarTabWindow() && isTabPoppedOut(tabId)) {- await window.electronAPI?.sidebarTabWindow?.focus(tabId);+ const focus = window.electronAPI?.sidebarTabWindow?.focus;+ if (options) await focus?.(tabId, options);+ else await focus?.(tabId);return;}+ if (tabId === prev.activeTabId) return;// closeTab 已把关闭中的 tab 从 bucket 乐观移除:若此时用户点击该 tab(或// 并发命令调 setActiveTab),activeTabId 会指向 tabs 里不存在的 id —— sidebar// 无法渲染对应 body;close 落库后 DB 里也没有 active row。提前守门,拒绝激活diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex ba899a552b..6f65a99617 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -230,6 +230,7 @@ import { toast } from '@/lib/toast';import { openUrlInSidebarBrowser } from '@/features/right-sidebar/lib/openInSidebarBrowser';import { openPluginTaskTab } from '@/features/right-sidebar/lib/openPluginTaskTab';import { isSidebarWindow } from '@/lib/sidebarWindow';+import { isSecondaryWindow } from '@/lib/secondaryWindow';import {extractUsageLimitRecoveryHint,type UsageLimitRecoveryHint,@@ -9784,7 +9785,7 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {window.electronAPI.ghosts,(raw: unknown, ownerStamp?: unknown) => {if (!isCurrentLocalLiveIngress(ownerStamp)) return;- if (isSidebarWindow()) return;+ if (isSidebarWindow() || isSecondaryWindow()) return;const p = raw as {name?: string;iconDataUrl?: string;@@ -9814,7 +9815,7 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {window.electronAPI.ghosts?.onTaskViewOpen?.(cb),(raw: unknown, ownerStamp?: unknown) => {if (!isCurrentLocalLiveIngress(ownerStamp)) return;- if (isSidebarWindow()) return;+ if (isSidebarWindow() || isSecondaryWindow()) return;const p = raw as { instanceId?: unknown; sessionId?: unknown } | null;if (!p || typeof p.instanceId !== 'string' || typeof p.sessionId !== 'string') return;void openPluginTaskTab(p.sessionId, p.instanceId, { userInitiated: false }).catch(() => {diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex 269fcfab89..298b5460c3 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -2074,7 +2074,7 @@ interface ElectronAPI {open?: (request: import('../shared/sidebarTabWindow').SidebarTabWindowOpenRequest,) => Promise<void>;- focus: (tabId: string) => Promise<void>;+ focus: (tabId: string, options?: { userInitiated?: boolean }) => Promise<void>;closeForTab: (tabId: string) => Promise<void>;/** 主窗口:把弹在独立窗口里的全局页签交回侧栏(任务页签不支持)。 */returnTab?: (tabId: string) => Promise<boolean>;diff --git a/apps/desktop/src/shared/sidebarTabWindow.ts b/apps/desktop/src/shared/sidebarTabWindow.tsindex f0e8819ce5..4f19344ab9 100644--- a/apps/desktop/src/shared/sidebarTabWindow.ts+++ b/apps/desktop/src/shared/sidebarTabWindow.ts@@ -38,6 +38,8 @@ export interface SidebarTabWindowAssignment {/** 下发给弹出窗口的指派:附不可持久化会话的整桶内存快照(仅 device-link 远程会话非空)。 */export interface SidebarTabWindowAssignmentPayload extends SidebarTabWindowAssignment {handoff: RsbWindowTabSnapshot | null;+ /** 本次指派要求选中的已承载页签;只发给它的窗口,不持久化。 */+ revealTabId?: string;}/** 主窗 → main 的弹出 / 搬入请求。 */