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(sidebar): 窗口清空任务页签后解绑任务、详情页打开侧栏时展开右侧栏、页签标题按实际视图取

Dash48aff3dd5641
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.ts
index 2fbb765a8f..5442b56668 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
@@ -377,6 +377,30 @@ describe('SidebarTabWindowsController', () => {
});
});
+ // 测试价值
+ // - 生产入口与可观察结果:任务页签合并回侧栏后,窗口只剩全局页签时 getAssignment 的 sessionId
+ // 为 null,另一任务的页签可以搬进这扇窗,而不是被旧任务绑定挡在门外新开一扇。
+ // - Bug / 规则依据:review「最后一个任务页签离开后窗口仍绑旧任务」。
+ // - 现有覆盖缺口:多页签用例只在窗口持有任务页签时断言指派。
+ // - 最小失败输入:任务页签 + 全局页签同窗,合并回任务页签后再 open 另一任务页签。
+ // - tier:unit(mock deps)。
+ it('unbinds the window from its task once the last task tab leaves', () => {
+ 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-g', null), targetWindowId: 'w1' });
+ expect(h.controller.getAssignment(h.wc(win))).toMatchObject({ sessionId: 's1' });
+
+ h.controller.mergeBack(h.wc(win), 'tab-a', null);
+ expect(h.controller.getAssignment(h.wc(win))).toMatchObject({ sessionId: null });
+
+ h.controller.open({ ...request('tab-x', 's2'), targetWindowId: 'w1' });
+ expect(h.created).toHaveLength(1);
+ expect(h.controller.getAssignment(h.wc(win))).toMatchObject({ sessionId: 's2' });
+ });
+
// 测试价值
// - 生产入口与可观察结果:open({position}) → 首次展示前经 positionWindow 把窗口放到松手点,
// 且只在 show 之前调一次;搬进已有窗口不改位置。
diff --git a/apps/desktop/src/main/sidebar-tab-window/controller.ts b/apps/desktop/src/main/sidebar-tab-window/controller.ts
index 7781f140ab..e9b3c4bc1c 100644
--- a/apps/desktop/src/main/sidebar-tab-window/controller.ts
+++ b/apps/desktop/src/main/sidebar-tab-window/controller.ts
@@ -226,6 +226,11 @@ export class SidebarTabWindowsController {
slot.assignment.tabs = slot.assignment.tabs.filter((tab) => tab.tabId !== tabId);
if (this.tabToWindow.get(tabId) === slot.assignment.windowId) this.tabToWindow.delete(tabId);
slot.adoptedSnapshots.delete(tabId);
+ // 最后一个任务页签离开后,窗口只剩全局页签:解除任务绑定,它才能再接别的任务的页签,
+ // 窗内「+」也不会继续往旧任务里建页签。
+ if (!slot.assignment.tabs.some((tab) => tab.sessionId !== null)) {
+ slot.assignment = { ...slot.assignment, sessionId: null };
+ }
return ref;
}
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
index 9cc601897d..01c3ceb64e 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
@@ -65,8 +65,9 @@ import {
setActiveGlobalTabId,
useGlobalTabs,
} from '@/features/right-sidebar/globalTabs';
+import { requestRightSidebarVisibility } from '@/features/right-sidebar/lib/sidebarCommands';
import { resetPluginPlacementAndReturn } from '@/features/right-sidebar/pluginPlacement';
-import { useTabGroupAssignments } from '@/features/right-sidebar/tabGroups';
+import { getTabGroup, useTabGroupAssignments } from '@/features/right-sidebar/tabGroups';
import { useInstalledGhosts } from '@/cindy-brain/useInstalledGhosts';
import { installedGhostStoragePart } from '../../../shared/pluginIdentity';
import { ghostPluginSummary } from './lib/ghostPluginDetailModel';
@@ -985,8 +986,14 @@ export function DetailsSection({
<button
type="button"
onClick={() => {
- const tab = addGlobalPluginTab(detail.id, { ghost: installedGhost, view: 'panel' });
- if (tab) setActiveGlobalTabId(tab.id);
+ const tab = addGlobalPluginTab(detail.id, {
+ ghost: installedGhost,
+ view: 'panel',
+ });
+ if (!tab) return;
+ setActiveGlobalTabId(tab.id);
+ // 落在右侧组时右侧栏可能是收起的:展开,否则用户点了没有任何反馈。
+ if (getTabGroup(tab.id) === 'right') requestRightSidebarVisibility('open');
}}
className={placementActionClass}
>
diff --git a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
index c42ed84aa3..ade323cb0a 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/globalTabs.ts
@@ -402,10 +402,16 @@ export function resetPluginPlacement(instanceId: string, ghost?: InstalledGhost)
});
}
-/** 页签标题:停靠面板用 panel.title,整页视图用 mainView.title,都没有就用插件名。 */
-export function globalTabTitleForGhost(ghost: InstalledGhost): string {
+/**
+ * 页签标题,按页签实际承载的页面取:panel 用 panel.title,main 用 mainView.title,缺省回落到
+ * 另一个声明再回落插件名。不传 view 时按插件声明推导(有停靠面板 → panel,与升级前一致)。
+ */
+export function globalTabTitleForGhost(ghost: InstalledGhost, view?: PluginViewKind): string {
const { manifest } = ghost;
- return manifest.panel?.title ?? manifest.mainView?.title ?? manifest.name;
+ const resolved = view ?? effectivePluginView(undefined, ghost);
+ const first = resolved === 'main' ? manifest.mainView?.title : manifest.panel?.title;
+ const second = resolved === 'main' ? manifest.panel?.title : manifest.mainView?.title;
+ return first ?? second ?? manifest.name;
}
export function findGlobalTabByInstance(instanceId: string): TabState | null {
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/plugin-view/index.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/plugin-view/index.tsx
index 49c2b4e881..105526d9e3 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/plugin-view/index.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/plugin-view/index.tsx
@@ -37,7 +37,13 @@ function useInstalledGhostByInstance(instanceId: string): InstalledGhost | undef
function PluginViewTabPillTitle({ state, t }: { state: PluginViewTabState; t: TFunction }) {
const ghost = useInstalledGhostByInstance(state.instanceId);
- return <>{ghost ? globalTabTitleForGhost(ghost) : t('rightSidebar.tabs.kinds.pluginView')}</>;
+ return (
+ <>
+ {ghost
+ ? globalTabTitleForGhost(ghost, effectivePluginView(state, ghost))
+ : t('rightSidebar.tabs.kinds.pluginView')}
+ </>
+ );
}
function PluginViewTabPillIcon({ state }: { state: PluginViewTabState }) {