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。

fix(plugins): 插件任务页打开时露到全局页签前面

Dash5cc672bef4d8
diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
index a150e1acd3..229cd566e1 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
@@ -76,6 +76,7 @@ import {
isGlobalTabId,
removeGlobalTab,
setActiveGlobalTabId,
+ subscribeRevealSessionTab,
useActiveGlobalTabId,
useGlobalTabs,
} from './globalTabs';
@@ -679,6 +680,23 @@ export function RightSidebarShell({
[activeGlobalTabId, groupId, pinnedTabs, sessionId, soloMode],
);
+ // 程序打开的任务页签(插件任务页)要露出来:与用户点选同口径离开本组的全局页签。
+ const revealContextRef = useRef({ activeGlobalTabId, inGroup, pinnedTabs });
+ revealContextRef.current = { activeGlobalTabId, inGroup, pinnedTabs };
+ useEffect(() => {
+ if (soloMode || !sessionId) return undefined;
+ return subscribeRevealSessionTab((targetSessionId, tabId) => {
+ if (targetSessionId !== sessionId) return;
+ const context = revealContextRef.current;
+ if (!context.inGroup(tabId)) return;
+ setGroupActiveTabId(groupId, sessionId, tabId);
+ const activeGlobal = context.activeGlobalTabId;
+ if (activeGlobal && context.pinnedTabs.some((tab) => tab.id === activeGlobal)) {
+ setActiveGlobalTabId(null);
+ }
+ });
+ }, [groupId, sessionId, soloMode]);
+
// 主窗:已弹出的页签窗口(同任务或只有全局页签的),右键菜单「移到窗口 …」的目标。
// 标签用窗口里第一个页签的标题(插件的 TabPillTitle 组件,不是字符串)。
const popoutWindows = useMemo<PopoutWindowOption[] | undefined>(() => {
diff --git a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
index cb950db055..07f808df70 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
@@ -546,6 +546,24 @@ export function setActiveGlobalTabId(tabId: string | null): void {
notify();
}
+type RevealSessionTabListener = (sessionId: string, tabId: string) => void;
+const revealListeners = new Set<RevealSessionTabListener>();
+
+/**
+ * 程序替某任务打开的任务页签(插件任务页)要露出来:全局激活位优先于任务激活位,
+ * 只写任务桶会被前排的全局页签挡住。只有正在显示该任务、且页签归本组的 Shell 响应。
+ */
+export function requestRevealSessionTab(sessionId: string, tabId: string): void {
+ for (const listener of revealListeners) listener(sessionId, tabId);
+}
+
+export function subscribeRevealSessionTab(listener: RevealSessionTabListener): () => void {
+ revealListeners.add(listener);
+ return () => {
+ revealListeners.delete(listener);
+ };
+}
+
export function subscribeGlobalTabs(cb: () => void): () => void {
getGlobalTabsSnapshot();
subscribers.add(cb);
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.ts
index abaf1ea645..11bdcaad53 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
@@ -1,11 +1,13 @@
// @vitest-environment jsdom
// - 生产入口与可观察结果:openPluginTaskTab 对真实 store 的写入(任务桶里的页签、激活页签、可见性请求)。
-// - Bug / 规则依据:同一任务里每个插件实例至多一个任务页;不同任务各有自己的一份。
+// - Bug / 规则依据:同一任务里每个插件实例至多一个任务页;不同任务各有自己的一份;
+// 全局页签在前时,打开的任务页要请求露出(实机:全局「模拟器」挡住了刚开的任务页)。
// - 现有覆盖缺口:新入口。最小失败输入:同一插件在同一任务里连开两次。
// - tier:unit。
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { _resetStore, addTab, ensureHydrated, getBucket } from '../../store';
import { routeSidebarCommand } from '../detachedSidebarRouting';
+import { subscribeRevealSessionTab } from '../../globalTabs';
import { openPluginTaskTab } from '../openPluginTaskTab';
import { _resetSidebarCommandsForTests, onRequestRightSidebarVisibility } from '../sidebarCommands';
@@ -40,6 +42,8 @@ const taskTabs = (sessionId: string) =>
describe('openPluginTaskTab', () => {
it('keeps one task page per plugin per task, refocusing it instead of adding another', async () => {
+ const reveal = vi.fn();
+ const stop = subscribeRevealSessionTab(reveal);
await openPluginTaskTab('task-1', 'sim', { userInitiated: false });
await ensureHydrated('task-1');
const files = await addTab('task-1', 'file-browser');
@@ -48,7 +52,9 @@ describe('openPluginTaskTab', () => {
expect(taskTabs('task-1')).toEqual([{ instanceId: 'sim' }]);
const simTab = getBucket('task-1').tabs.find((tab) => tab.kind === 'plugin-task')!;
expect(getBucket('task-1').activeTabId).toBe(simTab.id);
+ expect(reveal.mock.calls).toEqual([['task-1', simTab.id], ['task-1', simTab.id]]);
expect(visibility).toHaveBeenLastCalledWith('open', { sessionId: 'task-1', userInitiated: false });
+ stop();
});
it('gives every task its own page, and every plugin its own tab within a task', async () => {
diff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts b/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts
index 55de33f05c..8fcd8724cc 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/openPluginTaskTab.ts
@@ -1,3 +1,4 @@
+import { requestRevealSessionTab } from '../globalTabs';
import { addTab, ensureHydrated, getBucket, setActiveTab } from '../store';
import type { PluginTaskTabState } from '../plugins/plugin-task';
import { routeSidebarCommand } from './detachedSidebarRouting';
@@ -26,11 +27,14 @@ export async function openPluginTaskTab(
tab.kind === 'plugin-task' &&
(tab.state as PluginTaskTabState | null)?.instanceId === instanceId,
);
+ let tabId = existing?.id;
if (existing) {
if (bucket.activeTabId !== existing.id) await setActiveTab(sessionId, existing.id);
} else {
- await addTab(sessionId, 'plugin-task', { instanceId } satisfies PluginTaskTabState);
+ tabId = (await addTab(sessionId, 'plugin-task', { instanceId } satisfies PluginTaskTabState))
+ .id;
}
+ if (tabId) requestRevealSessionTab(sessionId, tabId);
}
if (route === 'attached' || route === 'routed') {
requestRightSidebarVisibility('open', { sessionId, userInitiated });