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(desktop): preserve viewed teammate and smooth section collapse

zqchris8501ab41b4c1
diff --git a/apps/desktop/scripts/fixtures/teammates-section/teammates-fixture.tsx b/apps/desktop/scripts/fixtures/teammates-section/teammates-fixture.tsx
index 8033a6c79a..982cb01b83 100644
--- a/apps/desktop/scripts/fixtures/teammates-section/teammates-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/teammates-section/teammates-fixture.tsx
@@ -1,10 +1,8 @@
-import { Route, Routes } from 'react-router-dom';
-import { AppFrame, mountPage } from '../../ui-page/harness';
+import { AppFrame, ctx, mountPage } from '../../ui-page/harness';
import { TeammatesSection } from '../../../src/renderer/features/bots/TeammatesSection';
+// The production sidebar lives in the shell, outside child route elements.
mountPage({
- route: '/bots/mate-6',
- render: () => <Routes><Route path="/bots/:botId" element={
- <AppFrame header={false} sidebar={<TeammatesSection />} />
- } /></Routes>,
+ route: ctx.data.route as string,
+ render: () => <AppFrame header={false} sidebar={<TeammatesSection />} />,
});
diff --git a/apps/desktop/scripts/fixtures/teammates-section/ui-page.mjs b/apps/desktop/scripts/fixtures/teammates-section/ui-page.mjs
index 80cc6f3a0a..2623db6c43 100644
--- a/apps/desktop/scripts/fixtures/teammates-section/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/teammates-section/ui-page.mjs
@@ -17,7 +17,7 @@ export default {
stubs: {
'src/renderer/contexts/AuthContext': { partial: 'export const useAuth=()=>({dataOwnerId:"ui-fixture"});' },
'src/renderer/features/bots/botStore': { partial: `export const useBotProfiles=()=>${data}.profiles; export const useBotUnreadCounts=()=>({});` },
- 'src/renderer/features/bots/useRemoteBots': 'export const useRemoteBots=()=>[];',
+ 'src/renderer/features/bots/useRemoteBots': `export const useRemoteBots=()=>${data}.remoteBots;`,
'src/renderer/features/bots/companionCloudStore': { partial: 'const snapshot={enabled:false,actors:[],demotedBotIds:[]}; export const useCompanionCloud=()=>snapshot;' },
'src/renderer/features/bots/botGroupStore': { partial: 'export const useBotGroupList=()=>({groups:[],loaded:true});' },
'src/renderer/features/device-link/useDeviceLinkDeviceList': 'export const useDeviceLinkDeviceList=()=>[];',
@@ -25,12 +25,33 @@ export default {
'src/renderer/features/bots/BotCreateMenu': 'export const BotCreateMenu=()=>null;',
'src/renderer/features/bots/BotDeleteDialog': 'export const BotDeleteDialog=()=>null;',
},
- cases: { default: { about: 'Six chats with the sixth selected; five-row preview, expand, shrink and avatar strip', data: { profiles } } },
+ cases: Object.fromEntries([
+ ['default', '/bots/mate-6'],
+ ['session', '/bots/mate-6/session/session-6'],
+ ['history', '/bots/mate-6/history/session-6'],
+ ['direct', '/bots/mate-6/direct/thread-6'],
+ ['remote', '/bots/remote/remote-device/mate-6'],
+ ['merged-cindy', '/bots/remote/remote-device/cindy-default'],
+ ].map(([name, route]) => {
+ const merged = name === 'merged-cindy';
+ const localProfiles = merged
+ ? profiles.map((bot, index) => index === 5 ? { ...bot, id: 'cindy-default', name: 'Cindy', templateId: 'cindy' } : bot)
+ : name === 'remote' ? profiles.slice(0, 5) : profiles;
+ const remoteBots = name === 'remote' || merged ? [{
+ id: merged ? 'cindy-default' : 'mate-6', name: merged ? 'Cindy' : 'Reviewer',
+ deviceId: 'remote-device', deviceName: 'Studio', online: true, avatar: '', avatarColor: 'violet',
+ preview: 'Ready', activityAt: 595, sessionId: 'remote-session',
+ }] : [];
+ return [name, {
+ about: `Shell-mounted sidebar on ${name} route; selected sixth row and reversible collapse`,
+ data: { profiles: localProfiles, remoteBots, route },
+ }];
+ })),
async check(page, ui) {
const rows = page.getByText('Ready', { exact: true });
assert.equal(await rows.count(), 5);
assert.equal(await page.getByText('Translator', { exact: true }).count(), 0);
- await page.getByText('Reviewer', { exact: true }).waitFor();
+ await page.locator('[aria-current="page"]').waitFor();
const showAllLabel = await ui.t('ccAgent.sidebar.showAllSessions', { count: 6 });
const showAll = () => page.getByRole('button', { name: showAllLabel, exact: true });
await showAll().click();
@@ -42,7 +63,7 @@ export default {
await showAll().click();
const header = page.getByRole('button', { name: await ui.t('bots.title'), exact: true });
await header.click();
- await rows.first().waitFor({ state: 'hidden' });
+ await rows.first().waitFor({ state: 'detached' });
await ui.capture('avatars');
await header.click();
assert.equal(await rows.count(), 5, 'reopening the section restores its compact preview');
diff --git a/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx b/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx
index a56296e1dd..8d731c6944 100644
--- a/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx
+++ b/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx
@@ -15,13 +15,14 @@ import {
Settings,
Trash2,
} from 'lucide-react';
-import { matchPath, useLocation, useNavigate, useParams } from 'react-router-dom';
+import { matchPath, useLocation, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { cn } from '@/lib/utils';
import { useAuth } from '@/contexts/AuthContext';
import { Tip } from '@/components/ui/tooltip';
import { SectionCollapse } from '@/features/cc-agent/sidebar/SectionCollapse';
+import { useCollapsibleShowAll } from '@/features/cc-agent/sidebar/hooks/useCollapsibleShowAll';
import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
import { getDataOwnerGeneration, isDataOwnerGenerationCurrent } from '@/contexts/dataOwnerGeneration';
import type { BotGroupSummary } from '../../../shared/botGroupChat';
@@ -124,21 +125,28 @@ export function TeammatesSection() {
const navigate = useNavigate();
const { pathname } = useLocation();
const { dataOwnerId } = useAuth();
- const { botId, deviceId, groupId } = useParams();
- // The registered sidebar slot can sit outside the group's route context.
+ // The sidebar lives in the shell, outside the child route's params context.
+ const remoteRoute = matchPath('/bots/remote/:deviceId/:botId', pathname);
+ const localRoute = [
+ '/bots/:botId',
+ '/bots/:botId/session/:sessionId',
+ '/bots/:botId/history/:sessionId',
+ '/bots/:botId/direct/:threadId',
+ ].map(pattern => matchPath(pattern, pathname)).find(Boolean);
+ const botId = remoteRoute?.params.botId ?? localRoute?.params.botId;
+ const deviceId = remoteRoute?.params.deviceId;
const selectedGroupId = matchPath('/bots/groups/:groupId', pathname)?.params.groupId;
const [collapsed, setCollapsed] = useState(() => readTeammatesSectionCollapsed(dataOwnerId));
- const [showAllChats, setShowAllChats] = useState(false);
+ const [showAllChats, setShowAllChats] = useCollapsibleShowAll(collapsed);
const avatarRowRef = useRef<HTMLDivElement>(null);
const avatarCapacity = useAvatarRowCapacity(avatarRowRef, collapsed);
useEffect(() => {
setCollapsed(readTeammatesSectionCollapsed(dataOwnerId));
setShowAllChats(false);
- }, [dataOwnerId]);
+ }, [dataOwnerId, setShowAllChats]);
const toggleCollapsed = () => {
const next = !collapsed;
setCollapsed(next);
- setShowAllChats(false);
writeTeammatesSectionCollapsed(dataOwnerId, next);
};
const cloud = useCompanionCloud();
@@ -437,7 +445,7 @@ export function TeammatesSection() {
const renderGroupRow = (group: BotGroupSummary) => (
<BotGroupSidebarRow key={'group:' + group.id} group={group} bots={bots}
- islandActivity={islandActivity} now={now} selected={group.id === groupId}
+ islandActivity={islandActivity} now={now} selected={group.id === selectedGroupId}
onOpenGroup={id => navigate('/bots/groups/' + encodeURIComponent(id))}
onContextMenu={event => {
event.preventDefault(); event.stopPropagation();
@@ -519,7 +527,7 @@ export function TeammatesSection() {
: 'deviceId' in entry.bot ? remoteBotKey(entry.bot) : entry.bot.id;
const name = entry.kind === 'group' ? entry.group.name
: entry.kind === 'cindy' ? currentCindy?.bot.name ?? '' : entry.bot.name;
- const selected = entry.kind === 'group' ? entry.group.id === groupId
+ const selected = entry.kind === 'group' ? entry.group.id === selectedGroupId
: entry.kind === 'cindy' ? Boolean(routeCindy)
: 'deviceId' in entry.bot ? entry.bot.id === botId && entry.bot.deviceId === deviceId
: !deviceId && entry.bot.id === botId;
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/teammatesSection.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/teammatesSection.test.tsx
index 88f5284e0b..374eb6b3f9 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/teammatesSection.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/teammatesSection.test.tsx
@@ -72,8 +72,9 @@ vi.mock('@/hooks/useSessionRunningStatus', () => ({
vi.mock('react-router-dom', async importOriginal => ({
...await importOriginal<typeof import('react-router-dom')>(),
useNavigate: () => mocks.navigate,
- useLocation: () => ({ pathname: '/bots', search: '', hash: '' }),
- useParams: () => mocks.params,
+ useLocation: () => ({ pathname: mocks.params.deviceId
+ ? `/bots/remote/${mocks.params.deviceId}/${mocks.params.botId}`
+ : mocks.params.botId ? `/bots/${mocks.params.botId}` : '/bots', search: '', hash: '' }),
}));
vi.mock('../botStore', () => ({
useBotProfiles: () => mocks.profiles,
@@ -395,6 +396,25 @@ describe('teammate host labels', () => {
describe('TeammatesSection header', () => {
const header = () => screen.getByRole('button', { name: 'bots.title' });
+ // #6444: six rows used to shrink to five before SectionCollapse could animate.
+ // Existing tests cover the avatar end state, not the closing interval. Unit tier:
+ // render the real section with six entries and advance fake time (no real wait).
+ it('keeps the full list mounted until the section collapse finishes', () => {
+ vi.useFakeTimers();
+ mocks.profiles = Array.from({ length: 6 }, (_, index) => bot({
+ id: `mate-${index}`, name: `Mate ${index}`, lastMessagePreview: 'Ready',
+ }));
+ render(<TeammatesSection />);
+ fireEvent.click(screen.getByRole('button', { name: 'ccAgent.sidebar.showAllSessions:{"count":6}' }));
+ expect(screen.getAllByText('Ready')).toHaveLength(6);
+ fireEvent.click(header());
+ expect(screen.getAllByText('Ready')).toHaveLength(6);
+ act(() => vi.advanceTimersByTime(200));
+ expect(screen.queryByText('Ready')).toBeNull();
+ fireEvent.click(header());
+ expect(screen.getAllByText('Ready')).toHaveLength(5);
+ });
+
it('starts expanded and collapses into a row of avatars that is remembered per account', async () => {
mocks.profiles = [
bot({ id: 'bot-1', name: 'PR steward', lastMessagePreview: 'Two checks are still red' }),