Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve Bot tab menu identity in detached sidebar
nothingyuancando7a91e2e17fe5
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.tsindex 74d2b70f7e..c510b14979 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts@@ -91,7 +91,7 @@ describe('right-sidebar-window IPC', () => {.rejects.toThrow(/command.focusTab/);});- it('forwards the optional device-link origin and Pi-only Subagents eligibility', () => {+ it('forwards the optional device-link origin, Subagents eligibility and Bot identity', () => {const controller = makeController();const { mainWebContents } = registerController(controller);const setContextCall = (ipcMain.on as ReturnType<typeof vi.fn>).mock.calls.find(@@ -110,6 +110,7 @@ describe('right-sidebar-window IPC', () => {remoteHostId: null,deviceLinkDeviceId: 'device-1',subagentsAvailable: true,+ botOwner: { botId: 'bot-1', canonical: false },available: true,},);@@ -120,6 +121,7 @@ describe('right-sidebar-window IPC', () => {remoteHostId: null,deviceLinkDeviceId: 'device-1',subagentsAvailable: true,+ botOwner: { botId: 'bot-1', canonical: false },available: true,});});diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/resolveHostContext.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/resolveHostContext.test.tsindex 4679a95e93..68aac0bcd1 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/resolveHostContext.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/resolveHostContext.test.ts@@ -35,6 +35,17 @@ describe('resolveHostContext mappers', () => {).toBe(false);});+ it('passes a linked Bot owner for pinned local sessions without exposing profiles', () => {+ expect(contextFromLocalSessionRow({+ id: 'bot-main', workingDir: '/repo', remoteHostId: null, agentKind: 'codex',+ botId: 'bot-1', botRole: 'canonical',+ }).botOwner).toEqual({ botId: 'bot-1', canonical: true });+ expect(contextFromLocalSessionRow({+ id: 'bot-history', workingDir: '/repo', remoteHostId: null, agentKind: 'codex',+ botId: 'bot-1', botRole: 'history',+ }).botOwner).toEqual({ botId: 'bot-1', canonical: false });+ });+it('fills device-link context from the main mirror list', () => {expect(contextFromDeviceLinkMirror('device-9', {diff --git a/apps/desktop/src/main/right-sidebar-window/ipc.ts b/apps/desktop/src/main/right-sidebar-window/ipc.tsindex 764efec8d5..eb5bb142f5 100644--- a/apps/desktop/src/main/right-sidebar-window/ipc.ts+++ b/apps/desktop/src/main/right-sidebar-window/ipc.ts@@ -70,6 +70,13 @@ function parseContext(raw: unknown): RsbWindowContext {'deviceLinkDeviceId',MAX_CONTEXT_SESSION_ID_LENGTH,);+ const botOwner = r.botOwner === undefined || r.botOwner === null+ ? r.botOwner+ : requireObject(r.botOwner, 'botOwner');+ if (botOwner && (typeof botOwner.botId !== 'string' || !botOwner.botId ||+ botOwner.botId.length > MAX_CONTEXT_SESSION_ID_LENGTH || typeof botOwner.canonical !== 'boolean')) {+ throwIpcError('INVALID_PARAMS', 'botOwner must contain a valid botId and canonical flag');+ }return {sessionId: nullableString(r.sessionId, 'sessionId', MAX_CONTEXT_SESSION_ID_LENGTH),workdir: nullableString(r.workdir, 'workdir', MAX_CONTEXT_PATH_LENGTH),@@ -78,6 +85,9 @@ function parseContext(raw: unknown): RsbWindowContext {...(r.subagentsAvailable === undefined? {}: { subagentsAvailable: r.subagentsAvailable }),+ ...(botOwner === undefined ? {} : { botOwner: botOwner === null ? null : {+ botId: botOwner.botId as string, canonical: botOwner.canonical as boolean,+ } }),available: r.available,};}diff --git a/apps/desktop/src/main/right-sidebar-window/resolveHostContext.ts b/apps/desktop/src/main/right-sidebar-window/resolveHostContext.tsindex bc9f8c13f5..2328314d6f 100644--- a/apps/desktop/src/main/right-sidebar-window/resolveHostContext.ts+++ b/apps/desktop/src/main/right-sidebar-window/resolveHostContext.ts@@ -13,7 +13,7 @@ import {MAX_CACHED_TEXT_CHARS,} from '../device-link/mirrorCacheStore.js';import { getDbClient } from '../localDb/client/current.js';-import { sessions } from '../localDb/schema.js';+import { botSessionLinks, sessions } from '../localDb/schema.js';import type { RsbWindowContext } from '../../shared/rightSidebarWindow.js';export function contextFromLocalSessionRow(row: {@@ -21,6 +21,8 @@ export function contextFromLocalSessionRow(row: {workingDir: string | null;remoteHostId: string | null;agentKind: string;+ botId?: string | null;+ botRole?: string | null;}): RsbWindowContext {return {sessionId: row.id,@@ -29,6 +31,7 @@ export function contextFromLocalSessionRow(row: {deviceLinkDeviceId: null,available: true,subagentsAvailable: row.agentKind === 'pi' && !row.remoteHostId,+ ...(row.botId ? { botOwner: { botId: row.botId, canonical: row.botRole === 'canonical' } } : {}),};}@@ -80,8 +83,11 @@ async function readLocalSessionContext(sessionId: string): Promise<RsbWindowContremoteHostId: sessions.remoteHostId,agentKind: sessions.agentKind,status: sessions.status,+ botId: botSessionLinks.botId,+ botRole: botSessionLinks.role,}).from(sessions)+ .leftJoin(botSessionLinks, eq(botSessionLinks.sessionId, sessions.id)).where(eq(sessions.id, sessionId)).limit(1);const row = rows[0];diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsxindex b2b5916dec..3cca8a8c00 100644--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx@@ -123,8 +123,8 @@ import { requestSessionSwitch } from '@/features/cc-agent/lib/sessionSwitchCommaimport { makeFolderPickerNewMakerRouteState } from '@/features/cc-agent/lib/newMakerRouteState';import { makeGenericNewMakerRouteState } from '@/features/cc-agent/lib/genericNewMakerRouteState';import { resolveSessionRoute } from '@/lib/orcaSessionIdentity';-import { ensureBotProfilesLoaded, getBotProfiles } from '@/features/bots/botStore';-import { botRouteForOwnedSession, createSessionEntryNavigator, remoteBotRouteForSession, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';+import { canonicalBotSessionId, ensureBotProfilesLoaded, getBotProfiles, useBotProfiles } from '@/features/bots/botStore';+import { botRouteForOwnedSession, createSessionEntryNavigator, findBotProfileForSession, remoteBotRouteForSession, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';import { readRemoteBots } from '@/features/bots/useRemoteBots';import { useSessionEntryLocationCommits } from '@/features/bots/useSessionEntryLocationCommits';import { islandEntryRouteState, requestIslandEntryAlertDisposal } from '@/features/bots/islandEntryAlert';@@ -317,6 +317,12 @@ export function MainLayout() {// 当前 cc-agent session id —— 由 CCAgentSessionView 的路由主实例(ownsRoute=true)经 outlet context// 推上来,Shell 据此从 module-level store 拉对应桶的 tab 列表持久化数据。null = 不在聊天会话内。const [rightSidebarSessionId, setRightSidebarSessionId] = useState<string | null>(null);+ const sidebarBotProfiles = useBotProfiles();+ const sidebarBot = rightSidebarSessionId+ ? findBotProfileForSession(sidebarBotProfiles, rightSidebarSessionId) : undefined;+ const sidebarBotOwner = sidebarBot && rightSidebarSessionId+ ? { botId: sidebarBot.id, canonical: canonicalBotSessionId(sidebarBot) === rightSidebarSessionId }+ : null;const [rightSidebarSubagentsAvailable, setRightSidebarSubagentsAvailable] = useState<boolean | undefined>(undefined);@@ -1042,12 +1048,15 @@ export function MainLayout() {remoteHostId: rightSidebarWorkdirInfo.remoteHostId,deviceLinkDeviceId: rightSidebarWorkdirInfo.deviceLinkDeviceId,subagentsAvailable: rightSidebarSubagentsAvailable,+ botOwner: sidebarBotOwner,available: rightSidebarAvailable,});}, [rightSidebarSessionId,rightSidebarWorkdirInfo,rightSidebarSubagentsAvailable,+ sidebarBot?.id,+ sidebarBotOwner?.canonical,rightSidebarAvailable,]);diff --git a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsxindex f0a6da31e7..dba256fd3f 100644--- a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx@@ -29,6 +29,7 @@ import { useTranslation } from 'react-i18next';import { PanelRight } from 'lucide-react';import { RightSidebarShell } from '@/features/right-sidebar/RightSidebarShell';+import { DetachedBotMenuOwnerContext } from '@/features/right-sidebar/botMenuOwnerContext';import { ToastContainer } from '@/components/ui/toast';import { useDeviceLinkRemoteProjects } from '@/features/device-link/useDeviceLinkRemoteProjects';import { onRequestRightSidebarVisibility } from '@/features/right-sidebar/lib/sidebarCommands';@@ -58,6 +59,7 @@ interface SidebarWindowContext {remoteHostId: string | null;deviceLinkDeviceId?: string | null;subagentsAvailable?: boolean;+ botOwner?: { botId: string; canonical: boolean } | null;available: boolean;}@@ -316,15 +318,20 @@ export function SidebarWindowLayout() {时 Shell 自渲染空白,叠一层"跟随主窗口会话"占位文案;窗口不自动关(避免主窗路由抖动导致窗口闪没)。 */}<div className="relative flex flex-1 flex-col overflow-hidden">- <RightSidebarShell- sessionId={sessionId}- workdir={ctx?.workdir ?? ''}- remoteHostId={ctx?.remoteHostId ?? null}- deviceLinkDeviceId={ctx?.deviceLinkDeviceId}- subagentsAvailable={ctx?.subagentsAvailable}- shellVisible={windowVisible}- isMac={isMac}- />+ <DetachedBotMenuOwnerContext.Provider value={sessionId && ctx?.botOwner+ ? { sessionId, botId: ctx.botOwner.botId,+ canonical: ctx.botOwner.canonical && !ctx.remoteHostId && !ctx.deviceLinkDeviceId }+ : null}>+ <RightSidebarShell+ sessionId={sessionId}+ workdir={ctx?.workdir ?? ''}+ remoteHostId={ctx?.remoteHostId ?? null}+ deviceLinkDeviceId={ctx?.deviceLinkDeviceId}+ subagentsAvailable={ctx?.subagentsAvailable}+ shellVisible={windowVisible}+ isMac={isMac}+ />+ </DetachedBotMenuOwnerContext.Provider>{(!windowVisible || !sessionId) && (<div className="absolute inset-0 z-10 flex items-center justify-center bg-[var(--panel-bg)]"><span className="text-13 text-[var(--text-tertiary)]">diff --git a/apps/desktop/src/renderer/features/right-sidebar/AddTabDropdown.tsx b/apps/desktop/src/renderer/features/right-sidebar/AddTabDropdown.tsxindex b7225e091c..dfe4307b64 100644--- a/apps/desktop/src/renderer/features/right-sidebar/AddTabDropdown.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/AddTabDropdown.tsx@@ -8,7 +8,7 @@* Phase 1 menu meta 硬编码;Phase 2 改从 TabKindRegistry 汇总。*/-import { useEffect } from 'react';+import { useContext, useEffect } from 'react';import { useTranslation } from 'react-i18next';import {Bot,@@ -40,6 +40,7 @@ import {} from '@/components/ui/dropdown-menu';import { canonicalBotSessionId, useBotProfiles } from '@/features/bots/botStore';import { findBotProfileForSession } from '@/features/bots/botSessionOwners';+import { DetachedBotMenuOwnerContext } from './botMenuOwnerContext';import { sessionsStore } from '@/lib/sessionsStore';import { openBotWorkbenchTab } from './lib/openBotWorkbenchTab';import type { TabGroupId } from './tabGroups';@@ -169,16 +170,17 @@ export function AddTabDropdown({.sort((a, b) => a.title.localeCompare(b.title) || a.instanceId.localeCompare(b.instanceId));const bots = useBotProfiles();const bot = sessionId ? findBotProfileForSession(bots, sessionId) : undefined;- const isBotSession = Boolean(bot);+ const detachedOwner = useContext(DetachedBotMenuOwnerContext);+ const linkedOwner = detachedOwner?.sessionId === sessionId ? detachedOwner : null;+ const isBotSession = Boolean(bot || linkedOwner);// 工作台只属于本机伙伴的主任务(渠道 / 历史 / 群专线任务与远端任务都没有)。const sessionRow = sessionId ? sessionsStore.findById(sessionId) : null;const workbenchBotId =- bot &&sessionId &&- canonicalBotSessionId(bot) === sessionId &&+ (bot ? canonicalBotSessionId(bot) === sessionId : linkedOwner?.canonical) &&!sessionRow?.remoteHostId &&!sessionRow?.deviceLinkDeviceId- ? bot.id+ ? bot?.id ?? linkedOwner?.botId ?? null: null;// 跟随:Radix Popper 负责摆位与视口碰撞。打开期间用 rAF 轮询 anchor —— 从布局中// 消失(关掉最后一个 tab 面板收起)直接关闭,避免菜单悬空残留在旧坐标。diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/AddTabDropdown.test.tsx b/apps/desktop/src/renderer/features/right-sidebar/__tests__/AddTabDropdown.test.tsxindex aed583aeef..ac3786b714 100644--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/AddTabDropdown.test.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/AddTabDropdown.test.tsx@@ -4,6 +4,7 @@ import { cleanup, fireEvent, render, screen } from '@testing-library/react';import { afterEach, beforeEach, expect, it, vi } from 'vitest';import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';import { AddTabDropdown } from '../AddTabDropdown';+import { DetachedBotMenuOwnerContext } from '../botMenuOwnerContext';import { __resetGlobalTabsForTest } from '../globalTabs';import { __resetTabGroupsForTest } from '../tabGroups';@@ -11,6 +12,7 @@ const m = vi.hoisted(() => ({ghosts: [] as unknown[],open: vi.fn(async () => undefined),rows: new Map<string, { remoteHostId?: string | null; deviceLinkDeviceId?: string | null }>(),+ profiles: [] as Array<{ id: string; sessions: Array<{ id: string; role: string }> }>,}));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));// Radix 浮层在 jsdom 里不需要真的开合:菜单摊平成按钮,只验证有哪些项、点了做什么。@@ -25,15 +27,7 @@ vi.mock('@/components/ui/dropdown-menu', () => ({),}));vi.mock('@/features/bots/botStore', () => ({- useBotProfiles: () => [- {- id: 'bot-1',- sessions: [- { id: 'bot-main', role: 'canonical' },- { id: 'bot-history', role: 'history' },- ],- },- ],+ useBotProfiles: () => m.profiles,canonicalBotSessionId: (bot: { sessions: Array<{ id: string; role: string }> }) =>bot.sessions.find((session) => session.role === 'canonical')?.id,}));@@ -41,10 +35,16 @@ vi.mock('@/lib/sessionsStore', () => ({ sessionsStore: { findById: (id: string)vi.mock('../lib/openBotWorkbenchTab', () => ({ openBotWorkbenchTab: m.open }));vi.mock('@/cindy-brain/useInstalledGhosts', () => ({ useInstalledGhosts: () => m.ghosts }));-function renderMenu(sessionId: string, onSelect = vi.fn()) {+function renderMenu(+ sessionId: string,+ onSelect = vi.fn(),+ detachedOwner: { sessionId: string; botId: string; canonical: boolean } | null = null,+) {const anchorRef = createRef<HTMLElement>();render(- <AddTabDropdown open={false} anchorRef={anchorRef} sessionId={sessionId} onClose={vi.fn()} onSelect={onSelect} />,+ <DetachedBotMenuOwnerContext.Provider value={detachedOwner}>+ <AddTabDropdown open={false} anchorRef={anchorRef} sessionId={sessionId} onClose={vi.fn()} onSelect={onSelect} />+ </DetachedBotMenuOwnerContext.Provider>,);return onSelect;}@@ -52,6 +52,9 @@ function renderMenu(sessionId: string, onSelect = vi.fn()) {beforeEach(() => {vi.clearAllMocks();m.rows = new Map();+ m.profiles = [{ id: 'bot-1', sessions: [+ { id: 'bot-main', role: 'canonical' }, { id: 'bot-history', role: 'history' },+ ] }];m.ghosts = [];window.localStorage.clear();__resetGlobalTabsForTest();@@ -67,6 +70,32 @@ it('offers the workbench in a local teammate main task and reopens it with the texpect(onSelect).not.toHaveBeenCalled();});+it('uses the linked identity in a detached window without Bot profiles', () => {+ m.profiles = [];+ renderMenu('bot-main', vi.fn(), { sessionId: 'bot-main', botId: 'bot-1', canonical: true });+ expect(screen.getByText('bots.workbench.title')).toBeTruthy();+ for (const kind of ['review', 'subagents', 'backgroundTasks', 'terminal']) {+ expect(screen.queryByText(`rightSidebar.tabs.kinds.${kind}`)).toBeNull();+ }+ fireEvent.click(screen.getByText('bots.workbench.title'));+ expect(m.open).toHaveBeenCalledWith('bot-main', 'bot-1');+});++it('does not reuse a detached owner after switching to another session', () => {+ m.profiles = [];+ renderMenu('task-1', vi.fn(), { sessionId: 'bot-main', botId: 'bot-1', canonical: true });+ expect(screen.queryByText('bots.workbench.title')).toBeNull();+ expect(screen.getByText('rightSidebar.tabs.kinds.review')).toBeTruthy();+});++it('filters a detached Bot history task without offering the canonical workbench', () => {+ m.profiles = [];+ renderMenu('bot-history', vi.fn(), { sessionId: 'bot-history', botId: 'bot-1', canonical: false });+ expect(screen.queryByText('bots.workbench.title')).toBeNull();+ expect(screen.queryByText('rightSidebar.tabs.kinds.review')).toBeNull();+ expect(screen.getByText('rightSidebar.tabs.kinds.fileBrowser')).toBeTruthy();+});+it('keeps the other entries on the generic add path', () => {const onSelect = renderMenu('bot-main');fireEvent.click(screen.getByText('rightSidebar.tabs.kinds.fileBrowser'));diff --git a/apps/desktop/src/renderer/features/right-sidebar/botMenuOwnerContext.ts b/apps/desktop/src/renderer/features/right-sidebar/botMenuOwnerContext.tsnew file mode 100644index 0000000000..db4dbea3d6--- /dev/null+++ b/apps/desktop/src/renderer/features/right-sidebar/botMenuOwnerContext.ts@@ -0,0 +1,8 @@+import { createContext } from 'react';++/** Detached sidebar receives only the linked identity, not the full Bot profile list. */+export const DetachedBotMenuOwnerContext = createContext<{+ sessionId: string;+ botId: string;+ canonical: boolean;+} | null>(null);diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex 12360ea642..c56682b608 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -1996,6 +1996,7 @@ interface ElectronAPI {remoteHostId: string | null;deviceLinkDeviceId?: string | null;subagentsAvailable?: boolean;+ botOwner?: { botId: string; canonical: boolean } | null;available: boolean;} | null>;/** 子窗口根组件挂载握手。 */@@ -2016,6 +2017,7 @@ interface ElectronAPI {remoteHostId: string | null;deviceLinkDeviceId?: string | null;subagentsAvailable?: boolean;+ botOwner?: { botId: string; canonical: boolean } | null;available: boolean;}) => void;onStateChanged: (@@ -2033,6 +2035,7 @@ interface ElectronAPI {remoteHostId: string | null;deviceLinkDeviceId?: string | null;subagentsAvailable?: boolean;+ botOwner?: { botId: string; canonical: boolean } | null;available: boolean;}) => void,) => () => void;diff --git a/apps/desktop/src/shared/rightSidebarWindow.ts b/apps/desktop/src/shared/rightSidebarWindow.tsindex f2acf6f2cb..a68eed6797 100644--- a/apps/desktop/src/shared/rightSidebarWindow.ts+++ b/apps/desktop/src/shared/rightSidebarWindow.ts@@ -33,6 +33,8 @@ export interface RsbWindowContext {deviceLinkDeviceId?: string | null;/** Pi is the only harness that exposes the Subagents sidebar surface. */subagentsAvailable?: boolean;+ /** Only the linked Bot identity needed by the detached add-tab menu. Absent on older senders. */+ botOwner?: { botId: string; canonical: boolean } | null;/** 当前主窗视图是否有侧边栏语义(设置页等无会话视图为 false,子窗口显示占位空态)。 */available: boolean;}