Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 伙伴列表仅显示远程设备名并保留运行状态 (#4585)
Chris Zhang55cd6502c46a
diff --git a/apps/desktop/src/renderer/features/bots/BotConnectionStatus.tsx b/apps/desktop/src/renderer/features/bots/BotConnectionStatus.tsxindex cd979ecdcf..c9f9aa9d29 100644--- a/apps/desktop/src/renderer/features/bots/BotConnectionStatus.tsx+++ b/apps/desktop/src/renderer/features/bots/BotConnectionStatus.tsx@@ -4,20 +4,38 @@ import { cn } from '@/lib/utils';export function BotConnectionStatus({online = true,deviceName,+ activityLabel,+ inline = false,+ className,}: {online?: boolean;deviceName?: string;+ activityLabel?: string;+ inline?: boolean;+ className?: string;}) {const { t } = useTranslation();- const label = `${t(online ? 'bots.remote.online' : 'bots.remote.offline')} · ${deviceName || t('bots.remote.thisDevice')}`;+ const status = online && activityLabel?.trim()+ ? activityLabel.trim()+ : t(online ? 'bots.remote.online' : 'bots.remote.offline');+ const name = deviceName?.trim();+ const label = name ? `${status} · ${name}` : status;+ if (inline) {+ return (+ <span title={label} className={cn('min-w-0 truncate text-11 leading-normal', className)}>+ {label}+ </span>+ );+ }return (<span- role="img"- aria-label={label}+ aria-hidden="true"title={label}className={cn('absolute bottom-0 right-0 h-2.5 w-2.5 rounded-full border-2 border-sidebar',- online ? 'bg-[var(--remote-status-ready)]' : 'bg-[var(--text-tertiary)]',+ !online ? 'bg-[var(--text-tertiary)]'+ : activityLabel ? 'bg-[var(--warning-accent)]'+ : 'bg-[var(--remote-status-ready)]',)}/>);diff --git a/apps/desktop/src/renderer/features/bots/BotsSidebar.tsx b/apps/desktop/src/renderer/features/bots/BotsSidebar.tsxindex 02a837c2d4..5c46c1865b 100644--- a/apps/desktop/src/renderer/features/bots/BotsSidebar.tsx+++ b/apps/desktop/src/renderer/features/bots/BotsSidebar.tsx@@ -32,6 +32,7 @@ import { sendSessionEventNotification } from '@/lib/sessionEventNotification';import { useSidebarCollapsedState, useRegisterSidebarUpper } from '../feature-context';import { SidebarIconButton } from '@/components/sidebar/SidebarIconButton';import { useRemoteBots } from './useRemoteBots';+import { useDeviceLinkDeviceList } from '@/features/device-link/useDeviceLinkDeviceList';import { remoteBotKey, isRemoteBotUnread } from './remoteBotRoster';import { BotConnectionStatus } from './BotConnectionStatus';import { BotAvatar } from './BotAvatar';@@ -44,7 +45,7 @@ import {formatBotUnreadBadge,} from './botListDisplay';import { subscribeBotReadState } from './botReadState';-import { partitionBotRoster } from './botRosterDisplay';+import { botDeviceLabel, partitionBotRoster } from './botRosterDisplay';import {canonicalBotSessionId,duplicateBotProfile,@@ -75,6 +76,12 @@ function BotsSidebarContent() {const { pathname } = useLocation();const { botId, sessionId, deviceId } = useParams();const remoteBots = useRemoteBots();+ const devices = useDeviceLinkDeviceList();+ const self = devices?.find((device) => device.isSelf);+ const rosterDevices = [+ ...(self ? [self] : []),+ ...remoteBots.map((bot) => ({ deviceId: bot.deviceId, name: bot.deviceName })),+ ];const bots = useBotProfiles();const unreadByBotId = useBotUnreadCounts();const rosterBots = bots.filter((bot) => bot.status !== 'archived');@@ -118,14 +125,14 @@ function BotsSidebarContent() {完成、失败、待回复都没有系统通知。*/const islandActivity = useAgentIslandActivityMap();- const isBotWorking = (bot: BotProfile): boolean => {+ const botRunningActivity = (bot: BotProfile) => {// 委派干活发生在子任务,不在主任务。只看 canonical 的话,目标伙伴侧栏会一直是// 静默的,发起方却在等 —— 这正是「目标侧执行过程黑洞」在列表上的样子。const canonicalSessionId = canonicalBotSessionId(bot);- if (canonicalSessionId && islandActivity.get(canonicalSessionId)?.phase === 'running') {- return true;- }- return bot.sessions.some((session) => islandActivity.get(session.id)?.phase === 'running');+ const canonicalActivity = canonicalSessionId ? islandActivity.get(canonicalSessionId) : undefined;+ if (canonicalActivity?.phase === 'running') return canonicalActivity;+ return bot.sessions.map((session) => islandActivity.get(session.id))+ .find((activity) => activity?.phase === 'running');};const roster = partitionBotRoster(rosterBots, { query, showHidden });const showSearch = rosterBots.length + remoteBots.length >= 8 || query.trim().length > 0;@@ -320,13 +327,15 @@ function BotsSidebarContent() {}).map((bot) => {if ('deviceId' in bot) {const selected = bot.id === botId && bot.deviceId === deviceId;+ const deviceName = botDeviceLabel({ deviceId: bot.deviceId, name: bot.deviceName }, rosterDevices);return (<button key={remoteBotKey(bot)} type="button" aria-current={selected ? 'page' : undefined}onClick={() => navigate(`/bots/remote/${encodeURIComponent(bot.deviceId)}/${encodeURIComponent(bot.id)}`)}className={cn('flex w-full min-w-0 items-center gap-2.5 rounded-xl px-2.5 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring', selected ? 'bg-sidebar-item-active text-sidebar-item-active-foreground' : 'text-[var(--sidebar-nav-text)] hover:bg-sidebar-item-hover')}>- <span className="relative shrink-0"><BotAvatar bot={bot} size="md" /><BotConnectionStatus online={bot.online} deviceName={bot.deviceName} /></span>+ <span className="relative shrink-0"><BotAvatar bot={bot} size="md" /><BotConnectionStatus online={bot.online} deviceName={deviceName} /></span><span className="flex min-w-0 flex-1 flex-col gap-0.5"><span className="truncate text-14 leading-5">{bot.name}</span>+ <BotConnectionStatus inline online={bot.online} deviceName={deviceName} className={selected ? 'opacity-70' : 'text-[var(--text-secondary)]'} /><span className="truncate text-12 leading-4 text-[var(--sidebar-list-muted)]">{bot.preview || bot.description || t('bots.list.startChat')}</span></span>{!selected && isRemoteBotUnread(bot) ? <span aria-label={t('bots.list.unread', { count: 1 })} className="size-[7px] shrink-0 rounded-full bg-[var(--bot-unread-bg)]" /> : null}@@ -340,9 +349,10 @@ function BotsSidebarContent() {// TA 正在回话时,第二行临时让位给「正在输入…」——聊天列表里这一行// 回答的是「TA 现在怎么样」,进行中比上一句说过什么更要紧。回合一// 结束就落回最新消息预览,不留痕。- const typing = isBotWorking(bot);+ const activity = botRunningActivity(bot);+ const typing = Boolean(activity);const subtitleText = typing- ? t('bots.list.typing')+ ? activity?.compactDetail?.trim() || t('bots.list.typing'): subtitle.kind === 'placeholder'? t('bots.list.startChat'): subtitle.text;@@ -392,9 +402,8 @@ function BotsSidebarContent() {}}className="flex min-w-0 flex-1 items-center gap-2.5 rounded-xl px-2.5 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring">- {/* 40px。28px 会让两行式行高塌成一行的观感——头像撑不住两行文字,- 整行读起来像一条被拉高的单行列表。 */}- <span className="relative shrink-0"><BotAvatar bot={bot} size="md" /><BotConnectionStatus /></span>+ {/* Keep the existing avatar size alongside identity and message preview. */}+ <span className="relative shrink-0"><BotAvatar bot={bot} size="md" /><BotConnectionStatus activityLabel={typing ? subtitleText : undefined} /></span><span className="flex min-w-0 flex-1 flex-col gap-0.5"><span className="flex items-baseline gap-2">{bot.pinnedAt ? (@@ -423,6 +432,7 @@ function BotsSidebarContent() {/>) : null}</span>+ {!typing && <BotConnectionStatus inline className={selected ? 'opacity-70' : 'text-[var(--text-secondary)]'} />}<span className="flex min-w-0 items-center gap-2">{/* 未读只强调名字与数字,预览保持次级,避免整行同时争抢注意力。 */}<spandiff --git a/apps/desktop/src/renderer/features/bots/__tests__/botRosterDisplay.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botRosterDisplay.test.tsindex 38dcfc2562..798974876e 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botRosterDisplay.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/botRosterDisplay.test.ts@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';import type { BotProfile } from '../botStore';import {botRosterActivityAt,+ botDeviceLabel,filterBotRoster,partitionBotRoster,sortBotRoster,@@ -42,6 +43,12 @@ function bot(}describe('Hermes-style Bot roster display', () => {+ it('distinguishes missing and duplicate host names by their actual device IDs', () => {+ const device = { deviceId: 'mac-1', name: ' Studio ' };+ expect(botDeviceLabel(device, [device, device])).toBe('Studio');+ expect(botDeviceLabel(device, [device, { deviceId: 'mac-2', name: 'studio' }])).toBe('Studio (mac-1)');+ expect(botDeviceLabel({ deviceId: 'mac-2', name: ' ' }, [])).toBe('mac-2');+ });it('sorts pinned Bots first and keeps recency ordering inside both groups', () => {const rows = sortBotRoster([bot('recent', { lastMessageAt: 90 }),diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botsSidebar.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botsSidebar.test.tsxindex 8bf4af8606..f6a0f8fcac 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botsSidebar.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botsSidebar.test.tsx@@ -1,7 +1,7 @@// @vitest-environment jsdomimport { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';-import type { ReactNode } from 'react';+import { cloneElement, type ReactElement, type ReactNode } from 'react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';vi.mock('@/hooks/useProviderOnboarding', () => ({@@ -20,6 +20,8 @@ vi.mock('react-i18next', () => ({const mocks = vi.hoisted(() => ({navigate: vi.fn(),profiles: [] as unknown[],+ remoteBots: [] as import('../remoteBotRoster').RemoteBot[],+ devices: [] as Array<{ deviceId: string; name: string; isSelf: boolean }>,health: new Map<string, string>(),unread: {} as Record<string, number>,groupMessages: new Map<string, unknown[]>(),@@ -31,10 +33,13 @@ const mocks = vi.hoisted(() => ({duplicateBotProfile: vi.fn(async () => ({ id: 'copy' })),registered: { node: null as ReactNode },/** 灵动岛活动镜像:sessionId -> phase。侧栏据此显示「正在输入…」。 */- islandActivity: new Map<string, { sessionId: string; phase: string }>(),+ islandActivity: new Map<string, { sessionId: string; phase: string; compactDetail?: string }>(),}));-vi.mock('../useRemoteBots', () => ({ useRemoteBots: () => [] }));+vi.mock('../useRemoteBots', () => ({ useRemoteBots: () => mocks.remoteBots }));+vi.mock('@/features/device-link/useDeviceLinkDeviceList', () => ({+ useDeviceLinkDeviceList: () => mocks.devices,+}));vi.mock('@/state/agentIslandActivity', () => ({useAgentIslandActivityMap: () => mocks.islandActivity,@@ -76,6 +81,7 @@ vi.mock('../BotDeleteDialog', () => ({}));import { BotsSidebar } from '../BotsSidebar';+import { BotConnectionStatus } from '../BotConnectionStatus';import { MainViewHistoryContext, type MainViewHistory } from '@/contexts/MainViewHistoryContext';import { markBotRead, resetBotReadStateForTests } from '../botReadState';@@ -132,6 +138,8 @@ beforeEach(() => {mocks.pathname = '/bots';mocks.collapsed = false;mocks.profiles = [];+ mocks.remoteBots = [];+ mocks.devices = [];mocks.registered.node = null;mocks.islandActivity = new Map();Object.defineProperty(window, 'electronAPI', {@@ -158,6 +166,95 @@ afterEach(() => {vi.useRealTimers();});+describe('teammate host labels', () => {+ it('shows only the remote device for same-name teammates and preserves remote routing', async () => {+ mocks.profiles = [bot({ id: 'local-bot', name: 'Cindy', lastMessagePreview: 'Local preview' })];+ mocks.devices = [{ deviceId: 'local-device', name: 'MBP-M5', isSelf: true }];+ mocks.remoteBots = [{ id: 'remote-bot', deviceId: 'remote-device', deviceName: 'Mac-Studio',+ name: 'Cindy', avatar: '🤖', avatarColor: 'violet', description: '', preview: 'Remote preview',+ activityAt: 1, sessionId: 'remote-session', online: true }];+ const view = await renderSidebar();+ expect(screen.getByText('bots.remote.online')).toBeTruthy();+ expect(view.container.innerHTML).not.toContain('MBP-M5');+ expect(screen.queryByRole('img', { name: /bots.remote.online/ })).toBeNull();+ expect(screen.getByText('bots.remote.online · Mac-Studio')).toBeTruthy();+ expect(screen.getByText('Local preview')).toBeTruthy();+ const remoteRow = screen.getByText('Remote preview').closest('button')!;+ fireEvent.click(remoteRow);+ expect(mocks.navigate).toHaveBeenCalledWith('/bots/remote/remote-device/remote-bot');++ mocks.remoteBots = mocks.remoteBots.map((bot) => ({ ...bot, online: false, deviceName: ' ' }));+ view.rerender(cloneElement(mocks.registered.node as ReactElement));+ expect(screen.getByText('bots.remote.offline · remote-device')).toBeTruthy();+ expect(screen.queryByText('bots.remote.offline · bots.remote.thisDevice')).toBeNull();+ });++ it('keeps local status free of device labels before and after directory updates', async () => {+ mocks.profiles = [bot({ id: 'local-bot', name: 'Cindy' })];+ const view = await renderSidebar();+ expect(screen.getByText('bots.remote.online')).toBeTruthy();+ expect(view.container.innerHTML).not.toContain('bots.remote.thisDevice');+ expect(view.container.textContent).not.toContain(' · ');+ mocks.devices = [{ deviceId: 'local-device', name: 'Renamed Mac', isSelf: true }];+ view.rerender(cloneElement(mocks.registered.node as ReactElement));+ expect(screen.getByText('bots.remote.online')).toBeTruthy();+ expect(view.container.innerHTML).not.toContain('Renamed Mac');+ expect(view.container.textContent).not.toContain(' · ');+ });++ it('disambiguates remote devices and updates their names without exposing the local host', async () => {+ mocks.profiles = [bot({ id: 'local-bot', name: 'Cindy' })];+ mocks.devices = [{ deviceId: 'local-device', name: 'Shared Mac', isSelf: true }];+ mocks.remoteBots = ['host-a', 'host-b'].map((deviceId) => ({+ id: 'remote-bot', deviceId, deviceName: 'Shared Mac', name: 'Cindy',+ avatar: '🤖', avatarColor: 'violet', description: '', preview: '',+ activityAt: 1, sessionId: 'remote-session', online: true,+ }));+ const view = await renderSidebar();+ expect(screen.getByText('bots.remote.online · Shared Mac (host-a)')).toBeTruthy();+ expect(screen.getByText('bots.remote.online · Shared Mac (host-b)')).toBeTruthy();+ expect(view.container.innerHTML).not.toContain('local-device');+ mocks.remoteBots = mocks.remoteBots.map((entry) => ({ ...entry, deviceName: entry.deviceId === 'host-a' ? 'Studio' : 'Mini' }));+ view.rerender(cloneElement(mocks.registered.node as ReactElement));+ expect(screen.getByText('bots.remote.online · Studio')).toBeTruthy();+ expect(screen.getByText('bots.remote.online · Mini')).toBeTruthy();+ });++ it.each(['Thinking', 'Generating'])('preserves %s while hiding the local host and idle status', async (compactDetail) => {+ mocks.profiles = [bot({ id: 'local-bot', name: 'Cindy', lastMessagePreview: 'Previous reply' })];+ mocks.devices = [{ deviceId: 'local-device', name: 'MBP-M5', isSelf: true }];+ mocks.islandActivity.set('local-bot-chat', { sessionId: 'local-bot-chat', phase: 'running', compactDetail });+ const view = await renderSidebar();+ expect(screen.getByText(compactDetail)).toBeTruthy();+ expect(screen.queryByText('bots.remote.online')).toBeNull();+ expect(view.container.innerHTML).not.toContain('MBP-M5');+ expect(view.container.innerHTML).not.toContain('bots.remote.thisDevice');+ expect(view.container.textContent).not.toContain(' · ');+ expect(screen.queryByText('Previous reply')).toBeNull();+ mocks.islandActivity.clear();+ view.rerender(cloneElement(mocks.registered.node as ReactElement));+ expect(screen.queryByText(compactDetail)).toBeNull();+ expect(screen.getByText('bots.remote.online')).toBeTruthy();+ expect(screen.getByText('Previous reply')).toBeTruthy();+ });++ it('retains delegated work and the existing typing fallback when detail is absent', async () => {+ mocks.profiles = [{ ...bot({ id: 'local-bot', name: 'Cindy' }), sessions: [+ { id: 'local-bot-chat', kind: 'chat' }, { id: 'delegated', kind: 'task' },+ ] }];+ mocks.islandActivity.set('delegated', { sessionId: 'delegated', phase: 'running', compactDetail: ' ' });+ await renderSidebar();+ expect(screen.getByText('bots.list.typing')).toBeTruthy();+ expect(screen.queryByText('bots.remote.online')).toBeNull();+ });++ it('keeps offline status without a device name or a dangling separator', () => {+ render(<BotConnectionStatus inline online={false} deviceName=" " activityLabel="Thinking" />);+ expect(screen.getByText('bots.remote.offline').getAttribute('title')).toBe('bots.remote.offline');+ });++});+describe('BotsSidebar rail return', () => {it.each(['/plugins', '/settings', '/bots-other'])('hides the retained return entry on %s', async (path) => {mocks.collapsed = true;diff --git a/apps/desktop/src/renderer/features/bots/botRosterDisplay.ts b/apps/desktop/src/renderer/features/bots/botRosterDisplay.tsindex c8bf5e8174..9be2629479 100644--- a/apps/desktop/src/renderer/features/bots/botRosterDisplay.ts+++ b/apps/desktop/src/renderer/features/bots/botRosterDisplay.ts@@ -1,5 +1,19 @@import type { BotProfile } from './botStore';+/** Keep unnamed and identically named hosts distinguishable without changing routing IDs. */+export function botDeviceLabel(+ device: { deviceId: string; name: string },+ devices: readonly { deviceId: string; name: string }[],+): string {+ const name = device.name.trim();+ if (!name) return device.deviceId;+ const duplicate = devices.some(+ (other) => other.deviceId !== device.deviceId+ && other.name.trim().toLocaleLowerCase() === name.toLocaleLowerCase(),+ );+ return duplicate ? `${name} (${device.deviceId})` : name;+}+function finiteTimestamp(value: unknown): number {return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;}diff --git a/docs/assets/teammate-device-labels/teammate-device-dark.png b/docs/assets/teammate-device-labels/teammate-device-dark.pngnew file mode 100644index 0000000000..34328f9c39Binary files /dev/null and b/docs/assets/teammate-device-labels/teammate-device-dark.png differdiff --git a/docs/assets/teammate-device-labels/teammate-device-light.png b/docs/assets/teammate-device-labels/teammate-device-light.pngnew file mode 100644index 0000000000..7815990d82Binary files /dev/null and b/docs/assets/teammate-device-labels/teammate-device-light.png differ