🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(sidebar): sub-group topics inside a project group by device, time or status (#20811)
Arvin Xu671dcad635fd
diff --git a/locales/en-US/project.json b/locales/en-US/project.jsonindex 9a6ce7aae5f..b031dba2ce2 100644--- a/locales/en-US/project.json+++ b/locales/en-US/project.json@@ -213,6 +213,11 @@"topics.status.scheduled": "Scheduled","topics.status.unread": "New results","topics.status.waitingForHuman": "Needs your input",+ "topics.subGroup.byDevice": "By device",+ "topics.subGroup.byStatus": "By status",+ "topics.subGroup.byTime": "By time",+ "topics.subGroup.none": "No grouping",+ "topics.subGroup.title": "Group topics","topics.title": "Topics","topics.viewProject": "View project"}diff --git a/locales/en-US/topic.json b/locales/en-US/topic.jsonindex 66da00e2714..d16d13241c8 100644--- a/locales/en-US/topic.json+++ b/locales/en-US/topic.json@@ -85,6 +85,7 @@"forkSuccess": "Forked to a new topic","forkTitle": "{{title}} (Branch)","groupTitle.byAgent.unknown": "Unknown agent",+ "groupTitle.byDevice.unknown": "Unknown device","groupTitle.byProject.noProject": "No directory","groupTitle.byStatus.active": "Active","groupTitle.byStatus.archived": "Archived",diff --git a/locales/zh-CN/project.json b/locales/zh-CN/project.jsonindex eb641efcc1e..b8aa5bfdc50 100644--- a/locales/zh-CN/project.json+++ b/locales/zh-CN/project.json@@ -213,6 +213,11 @@"topics.status.scheduled": "已安排","topics.status.unread": "有新结果","topics.status.waitingForHuman": "等待你处理",+ "topics.subGroup.byDevice": "按设备",+ "topics.subGroup.byStatus": "按状态",+ "topics.subGroup.byTime": "按时间",+ "topics.subGroup.none": "不分组",+ "topics.subGroup.title": "话题分组","topics.title": "话题","topics.viewProject": "查看项目"}diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.jsonindex 71453e0f9c6..4e2ba09e1c0 100644--- a/locales/zh-CN/topic.json+++ b/locales/zh-CN/topic.json@@ -85,6 +85,7 @@"forkSuccess": "已创建新会话","forkTitle": "{{title}} 的分支","groupTitle.byAgent.unknown": "未知 Agent",+ "groupTitle.byDevice.unknown": "未知设备","groupTitle.byProject.noProject": "无目录","groupTitle.byStatus.active": "活跃","groupTitle.byStatus.archived": "已归档",diff --git a/packages/locales/src/default/project.ts b/packages/locales/src/default/project.tsindex 1a3c2c5cffe..5f59e44e511 100644--- a/packages/locales/src/default/project.ts+++ b/packages/locales/src/default/project.ts@@ -55,6 +55,11 @@ export default {'topics.status.completed': 'Completed','topics.status.archived': 'Archived','topics.status.unread': 'New results',+ 'topics.subGroup.title': 'Group topics',+ 'topics.subGroup.none': 'No grouping',+ 'topics.subGroup.byDevice': 'By device',+ 'topics.subGroup.byTime': 'By time',+ 'topics.subGroup.byStatus': 'By status','settings.addDirectory': 'Add folder','settings.addDirectoryDescription':'Select an environment and a connected device, then enter the full path of an existing folder. Files stay on that device.',diff --git a/packages/locales/src/default/topic.ts b/packages/locales/src/default/topic.tsindex 4e1f60e4a5f..7f5b7fe683f 100644--- a/packages/locales/src/default/topic.ts+++ b/packages/locales/src/default/topic.ts@@ -108,6 +108,7 @@ export default {'filter.sortBy.createdAt': 'Created time','filter.sortBy.updatedAt': 'Updated time','groupTitle.byAgent.unknown': 'Unknown agent',+ 'groupTitle.byDevice.unknown': 'Unknown device','groupTitle.byProject.noProject': 'No directory','groupTitle.byStatus.active': 'Active','groupTitle.byStatus.archived': 'Archived',diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsxindex ff49d96c8f2..24fad3dc6ec 100644--- a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx@@ -26,9 +26,29 @@ const directoryRows = vi.hoisted(projectId: string;projectAvatar: string;deviceId?: string;+ deviceName?: string;path?: string;}>,);+const subGroupModeMock = vi.hoisted(() => ({ value: 'none' as string }));+const updateSystemStatusMock = vi.hoisted(() => vi.fn());+vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (state: object) => unknown) =>+ selector({+ status: { projectTopicSubGroupModeByGroup: { 'project-id:prj-1': subGroupModeMock.value } },+ updateSystemStatus: updateSystemStatusMock,+ }),+}));++vi.mock('@/store/device', () => ({+ deviceSelectors: { deviceList: (s: { devices: unknown[] }) => s.devices },+ useDeviceStore: (selector: (state: object) => unknown) =>+ selector({+ devices: [{ deviceId: 'device-2', friendlyName: 'Studio Linux' }],+ useFetchDevices: () => ({}),+ }),+}));+vi.mock('@/store/projectWorkingDirectory', () => ({useProjectDirectoryStore: (selector: (state: unknown) => unknown) =>selector({@@ -160,6 +180,102 @@ describe('Project topic group item', () => {routeParamsMock.aid = 'agent-1';agentStoreStateMock.activeAgentId = 'agent-1';activeWorkspaceSlugMock.value = 'lobehub';+ subGroupModeMock.value = 'none';+ });++ it('keeps the sub-group menu when the newest project topic has no working directory', () => {+ // Without a directory the add-topic actions can't render; the grouping+ // choice must not disappear with them.+ render(+ <AccordionRoot>+ <GroupItem+ expanded+ group={{+ children: [{ id: 't1', title: 'Conversation only' }] as any,+ id: 'project-id:prj-1',+ title: 'LobeHub',+ }}+ />+ </AccordionRoot>,+ );++ expect(screen.queryByRole('button', { name: 'directories.start' })).toBeNull();+ expect(screen.getByRole('button', { name: 'topics.subGroup.title' })).toBeTruthy();+ });++ it('picks a sub-group mode from the row grouping button and remembers it per group', async () => {+ updateSystemStatusMock.mockReset();+ render(+ <AccordionRoot>+ <GroupItem+ expanded+ group={{+ children: [{ id: 't1', title: 'Topic' }] as any,+ id: 'project-id:prj-1',+ title: 'LobeHub',+ }}+ />+ </AccordionRoot>,+ );++ fireEvent.click(screen.getByRole('button', { name: 'topics.subGroup.title' }));+ fireEvent.click(await screen.findByText('topics.subGroup.byDevice'));++ expect(updateSystemStatusMock).toHaveBeenCalledWith({+ projectTopicSubGroupModeByGroup: { 'project-id:prj-1': 'byDevice' },+ });+ });++ it('sections a project group by device when that mode is picked', () => {+ subGroupModeMock.value = 'byDevice';+ directoryRows.push(+ {+ deviceId: 'device-1',+ deviceName: 'MacBook',+ id: 'binding-mac',+ path: '/Users/me/project',+ projectAvatar: '',+ projectId: 'prj-1',+ projectName: 'LobeHub',+ projectSlug: 'lobehub',+ },+ {+ deviceId: 'device-2',+ id: 'binding-linux',+ path: '/home/me/project',+ projectAvatar: '',+ projectId: 'prj-1',+ projectName: 'LobeHub',+ projectSlug: 'lobehub',+ },+ );++ render(+ <AccordionRoot defaultValue={['project-id:prj-1']}>+ <GroupItem+ expanded+ group={{+ children: [+ { id: 't1', projectWorkingDirectoryId: 'binding-linux', title: 'Linux topic' },+ { id: 't2', title: 'Loose topic' },+ { id: 't3', projectWorkingDirectoryId: 'binding-mac', title: 'Mac topic' },+ ] as any,+ id: 'project-id:prj-1',+ title: 'LobeHub',+ }}+ />+ </AccordionRoot>,+ );++ const order = ['Studio Linux', 'Linux topic', 'MacBook', 'Mac topic'];+ const text = document.body.textContent ?? '';+ order.reduce((from, label) => {+ const at = text.indexOf(label, from);+ expect(at, label).toBeGreaterThanOrEqual(from);+ return at;+ }, 0);+ expect(text.indexOf('groupTitle.byDevice.unknown')).toBeLessThan(text.indexOf('Loose topic'));+ expect(text.indexOf('Mac topic')).toBeLessThan(text.indexOf('groupTitle.byDevice.unknown'));});it('opens the new-topic composer for the project directory without creating a topic', async () => {diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsxindex 46625798e3a..c1370f57059 100644--- a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx@@ -7,11 +7,20 @@ import {accordionStyles,AccordionTrigger,ActionIcon,+ type DropdownItem,+ DropdownMenu,Text,} from '@lobehub/ui/base-ui';import { createStaticStyles, cssVar, cx } from 'antd-style';import isEqual from 'fast-deep-equal';-import { FolderClosedIcon, FolderOpenIcon, type LucideIcon, PlusIcon } from 'lucide-react';+import {+ FolderClosedIcon,+ FolderOpenIcon,+ ListTreeIcon,+ LucideCheck,+ type LucideIcon,+ PlusIcon,+} from 'lucide-react';import { memo, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -30,13 +39,16 @@ import { useQueryRoute } from '@/hooks/useQueryRoute';import { useAgentStore } from '@/store/agent';import { useChatStore } from '@/store/chat';import { operationSelectors } from '@/store/chat/selectors';+import { useGlobalStore } from '@/store/global';+import { type ProjectTopicSubGroupMode } from '@/store/global/initialState';+import { systemStatusSelectors } from '@/store/global/selectors';import { useProjectDirectories, useProjectDirectoryStore } from '@/store/projectWorkingDirectory';import { getTopicWorkingDirectorySourcePath } from '@/utils/client/topic';import { buildPrefixedAgentRoutePath, parseAgentPathname } from '../../../utils/agentPathname';-import TopicItem from '../../List/Item';import { useTopicListScope } from '../../TopicListScope';import { type GroupItemComponentProps } from '../GroupedAccordion';+import ProjectTopicList from './ProjectTopicList';import {getProjectTopicStatusCounts,hasProjectTopicStatusCounts,@@ -45,6 +57,7 @@ import {const PROJECT_GROUP_PREFIX = 'project:';const PROJECT_ID_GROUP_PREFIX = 'project-id:';+const SUB_GROUP_MODES: ProjectTopicSubGroupMode[] = ['none', 'byDevice', 'byTime', 'byStatus'];const styles = createStaticStyles(({ css }) => ({statusBadge: css`@@ -90,11 +103,11 @@ const styles = createStaticStyles(({ css }) => ({max-width 150ms ${cssVar.motionEaseOut},opacity 150ms ${cssVar.motionEaseOut};- /* Holds the "more" menu plus the start "+" (2 × 24px), not a single icon */+ /* Holds the grouping menu, the "more" menu and the start "+" (3 × 24px) */&:focus-within,.accordion-header:hover & {pointer-events: auto;- max-width: 48px;+ max-width: 72px;opacity: 1;}`,@@ -262,6 +275,25 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, expanded }) => {const needsPlainStart = !!projectId && projectDirectories.length > 1;const { t: tProject } = useTranslation('project');+ const subGroupMode = useGlobalStore(systemStatusSelectors.projectTopicSubGroupMode(id));+ const updateSystemStatus = useGlobalStore((s) => s.updateSystemStatus);+ const subGroupMenuItems = useMemo<DropdownItem[]>(+ () => [+ {+ children: SUB_GROUP_MODES.map((mode) => ({+ icon: subGroupMode === mode ? <Icon icon={LucideCheck} /> : <div />,+ key: `sub-group-${mode}`,+ label: tProject(`topics.subGroup.${mode}`),+ onClick: () => updateSystemStatus({ projectTopicSubGroupModeByGroup: { [id]: mode } }),+ })),+ key: 'sub-group',+ label: tProject('topics.subGroup.title'),+ type: 'group',+ },+ ],+ [id, subGroupMode, tProject, updateSystemStatus],+ );+const statusCounts = useChatStore((s) => getProjectTopicStatusCounts(children, operationSelectors.visiblyRunningTopicIds(s)),isEqual,@@ -272,44 +304,52 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, expanded }) => {const hasCollapsedUnread = !expanded && unreadCount > 0;const hasCollapsedIndicators = hasCollapsedStatus || hasCollapsedUnread;const ProjectFolderIcon = expanded ? FolderOpenIcon : FolderClosedIcon;- const action =- canAddTopic || hasCollapsedIndicators ? (- <Flexbox horizontal align={'center'} gap={4}>- {hasCollapsedStatus && <CollapsedStatusBadges counts={statusCounts} />}- {hasCollapsedUnread && <CollapsedUnreadDot count={unreadCount} />}- {canAddTopic && (- <span className={hasCollapsedIndicators ? styles.addTopicAction : undefined}>- {needsPlainStart ? (- <>- <AgentDirectoryActions- hideStartAction- agentId={currentAgentId!}- path={workingDirectory!}- topics={children}- onLegacyStart={handleAddTopic}- />- <ActionIcon- icon={PlusIcon}- size={'small'}- title={tProject('directories.start')}- onClick={(e) => {- e.stopPropagation();- handleStartPlain();- }}- />- </>- ) : (- <AgentDirectoryActions- agentId={currentAgentId!}- path={workingDirectory!}- topics={children}- onLegacyStart={handleAddTopic}- />- )}- </span>+ // Sub-grouping is its own row action: it needs no directory, so it stays+ // available even when the directory actions below can't render.+ const action = (+ <Flexbox horizontal align={'center'} gap={4}>+ {hasCollapsedStatus && <CollapsedStatusBadges counts={statusCounts} />}+ {hasCollapsedUnread && <CollapsedUnreadDot count={unreadCount} />}+ <span className={hasCollapsedIndicators ? styles.addTopicAction : undefined}>+ <DropdownMenu items={subGroupMenuItems}>+ <ActionIcon+ active={subGroupMode !== 'none'}+ icon={ListTreeIcon}+ size={'small'}+ title={tProject('topics.subGroup.title')}+ onClick={(e) => e.stopPropagation()}+ />+ </DropdownMenu>+ {!canAddTopic ? null : needsPlainStart ? (+ <>+ <AgentDirectoryActions+ hideStartAction+ agentId={currentAgentId!}+ path={workingDirectory!}+ topics={children}+ onLegacyStart={handleAddTopic}+ />+ <ActionIcon+ icon={PlusIcon}+ size={'small'}+ title={tProject('directories.start')}+ onClick={(e) => {+ e.stopPropagation();+ handleStartPlain();+ }}+ />+ </>+ ) : (+ <AgentDirectoryActions+ agentId={currentAgentId!}+ path={workingDirectory!}+ topics={children}+ onLegacyStart={handleAddTopic}+ />)}- </Flexbox>- ) : undefined;+ </span>+ </Flexbox>+ );return (<AccordionItem value={id}>@@ -367,34 +407,19 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, expanded }) => {</Text></Flexbox></AccordionTrigger>- {action && (- <div- className={cx(- 'accordion-action',- accordionStyles.action,- accordionStyles.actionBorderless,- hasCollapsedIndicators && accordionStyles.actionAlwaysVisible,- )}- >- {action}- </div>- )}+ <div+ className={cx(+ 'accordion-action',+ accordionStyles.action,+ accordionStyles.actionBorderless,+ hasCollapsedIndicators && accordionStyles.actionAlwaysVisible,+ )}+ >+ {action}+ </div></AccordionHeader><AccordionPanel contentStyle={{ padding: 0 }}>- <Flexbox gap={1} paddingBlock={1}>- {children.map((topic) => (- <TopicItem- fav={topic.favorite}- id={topic.id}- key={topic.id}- metadata={topic.metadata}- runStartedAt={topic.runStartedAt}- status={topic.status}- title={topic.title}- userId={topic.userId}- />- ))}- </Flexbox>+ <ProjectTopicList groupId={id} topics={children} /></AccordionPanel></AccordionItem>);diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/ProjectTopicList.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/ProjectTopicList.tsxnew file mode 100644index 00000000000..266eb6876e5--- /dev/null+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/ProjectTopicList.tsx@@ -0,0 +1,163 @@+import { Center, Flexbox, Icon } from '@lobehub/ui';+import { Text } from '@lobehub/ui/base-ui';+import { cssVar } from 'antd-style';+import isEqual from 'fast-deep-equal';+import { LaptopIcon } from 'lucide-react';+import { memo, useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++import {+ type ExecutionStatusVisual,+ TOPIC_GROUP_VISUALS,+ TOPIC_STATUS_VISUALS,+} from '@/components/ExecutionStatus';+import { projectDirectoryDeviceName } from '@/features/ChatInput/ControlBar/projectDeviceTargets';+import { useChatStore } from '@/store/chat';+import { operationSelectors } from '@/store/chat/selectors';+import { deviceSelectors, useDeviceStore } from '@/store/device';+import { useGlobalStore } from '@/store/global';+import { systemStatusSelectors } from '@/store/global/selectors';+import { useProjectDirectories } from '@/store/projectWorkingDirectory';+import { useUserStore } from '@/store/user';+import { preferenceSelectors } from '@/store/user/selectors';+import { type ChatTopic, type GroupedTopic } from '@/types/topic';++import TopicItem from '../../List/Item';+import { formatTimeGroupId } from '../ByTimeMode/timeGroupTitle';+import {+ DEVICE_SUB_GROUP_PREFIX,+ groupProjectTopics,+ UNKNOWN_DEVICE_SUB_GROUP_ID,+} from './subGroups';++const STATUS_ICON: Record<string, ExecutionStatusVisual> = {+ ...TOPIC_STATUS_VISUALS,+ ...TOPIC_GROUP_VISUALS,+};++const renderTopic = (topic: ChatTopic) => (+ <TopicItem+ fav={topic.favorite}+ id={topic.id}+ key={topic.id}+ metadata={topic.metadata}+ runStartedAt={topic.runStartedAt}+ status={topic.status}+ title={topic.title}+ userId={topic.userId}+ />+);++interface ProjectTopicListProps {+ /** The byProject group id — the sub-group mode is remembered per group. */+ groupId: string;+ topics: ChatTopic[];+}++/**+ * Topics of one byProject sidebar group, optionally sectioned by device, time+ * or status (picked from the group's "more" menu).+ */+const ProjectTopicList = memo<ProjectTopicListProps>(({ groupId, topics }) => {+ const { t } = useTranslation('topic');+ const mode = useGlobalStore(systemStatusSelectors.projectTopicSubGroupMode(groupId));+ const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);+ const field = topicSortBy === 'createdAt' ? 'createdAt' : 'updatedAt';++ useDeviceStore((s) => s.useFetchDevices)(mode === 'byDevice');+ const devices = useDeviceStore(deviceSelectors.deviceList);+ const directories = useProjectDirectories();++ // A joined id string, not the Set itself: the selector must return something+ // comparable or every operation write would re-render the list.+ const runningIdsKey = useChatStore((s) => {+ if (mode !== 'byStatus') return '';+ const running = operationSelectors.visiblyRunningTopicIds(s);+ return topics+ .filter((topic) => running.has(topic.id))+ .map((topic) => topic.id)+ .join(',');+ });++ const resolveDeviceId = useCallback(+ (topic: ChatTopic) =>+ (topic.projectWorkingDirectoryId &&+ directories.find((directory) => directory.id === topic.projectWorkingDirectoryId)+ ?.deviceId) ||+ topic.metadata?.boundDeviceId,+ [directories],+ );++ const groups = useMemo(+ () =>+ groupProjectTopics(topics, mode, {+ field,+ loadingTopicIds: runningIdsKey ? new Set(runningIdsKey.split(',')) : undefined,+ resolveDeviceId,+ }),+ [topics, mode, field, runningIdsKey, resolveDeviceId],+ );++ const getTitle = useCallback(+ (group: GroupedTopic) => {+ if (mode === 'byStatus') return t(`groupTitle.byStatus.${group.id}` as any);+ if (mode === 'byTime')+ return formatTimeGroupId(group.id) ?? t(`groupTitle.byTime.${group.id}` as any);+ if (group.id === UNKNOWN_DEVICE_SUB_GROUP_ID) return t('groupTitle.byDevice.unknown');++ const deviceId = group.id.slice(DEVICE_SUB_GROUP_PREFIX.length);+ const directory = directories.find((item) => item.deviceId === deviceId);+ if (directory) return projectDirectoryDeviceName(directory, devices);+ const device = devices.find((item) => item.deviceId === deviceId);+ return device?.friendlyName || device?.hostname || deviceId;+ },+ [mode, t, directories, devices],+ );++ if (!groups) {+ return (+ <Flexbox gap={1} paddingBlock={1}>+ {topics.map(renderTopic)}+ </Flexbox>+ );+ }++ return (+ <Flexbox gap={4} paddingBlock={1}>+ {groups.map((group) => {+ const icon =+ mode === 'byStatus'+ ? STATUS_ICON[group.id]+ : mode === 'byDevice'+ ? { color: cssVar.colorTextTertiary, icon: LaptopIcon }+ : undefined;+ return (+ <Flexbox gap={1} key={group.id}>+ <Flexbox+ horizontal+ align="center"+ gap={6}+ height={24}+ paddingInline={'12px 8px'}+ style={{ overflow: 'hidden' }}+ >+ {icon && (+ <Center flex={'none'} height={16} width={16}>+ <Icon color={icon.color} icon={icon.icon} size={{ size: 12 }} />+ </Center>+ )}+ <Text ellipsis fontSize={12} type={'secondary'} weight={500}>+ {getTitle(group)}+ </Text>+ </Flexbox>+ {group.children.map(renderTopic)}+ </Flexbox>+ );+ })}+ </Flexbox>+ );+}, isEqual);++ProjectTopicList.displayName = 'ProjectTopicList';++export default ProjectTopicList;diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.test.ts b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.test.tsnew file mode 100644index 00000000000..8398e276b29--- /dev/null+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.test.ts@@ -0,0 +1,83 @@+import { describe, expect, it } from 'vitest';++import { type ChatTopic } from '@/types/topic';++import { groupProjectTopics, UNKNOWN_DEVICE_SUB_GROUP_ID } from './subGroups';++const createTopic = (id: string, overrides: Partial<ChatTopic> = {}): ChatTopic =>+ ({+ createdAt: 0,+ favorite: false,+ id,+ title: id,+ updatedAt: 0,+ ...overrides,+ }) as ChatTopic;++const directoryDevices: Record<string, string> = { 'dir-a': 'mac', 'dir-b': 'linux' };+const resolveDeviceId = (topic: ChatTopic) =>+ (topic.projectWorkingDirectoryId && directoryDevices[topic.projectWorkingDirectoryId]) ||+ topic.metadata?.boundDeviceId;++const ids = (groups: ReturnType<typeof groupProjectTopics>) =>+ groups?.map((group) => [group.id, group.children.map((topic) => topic.id)]);++describe('groupProjectTopics', () => {+ it('keeps the plain list for none', () => {+ expect(+ groupProjectTopics([createTopic('a')], 'none', { field: 'updatedAt', resolveDeviceId }),+ ).toBeUndefined();+ });++ it('sections by device in sidebar order, with unresolved machines last', () => {+ const groups = groupProjectTopics(+ [+ createTopic('t1', { projectWorkingDirectoryId: 'dir-b' }),+ createTopic('t2'),+ createTopic('t3', { projectWorkingDirectoryId: 'dir-a' }),+ createTopic('t4', { metadata: { boundDeviceId: 'linux' } }),+ ],+ 'byDevice',+ { field: 'updatedAt', resolveDeviceId },+ );++ expect(ids(groups)).toEqual([+ ['device:linux', ['t1', 't4']],+ ['device:mac', ['t3']],+ [UNKNOWN_DEVICE_SUB_GROUP_ID, ['t2']],+ ]);+ });++ it('sections by status, counting client-side streaming as running', () => {+ const groups = groupProjectTopics(+ [+ createTopic('done', { status: 'completed' }),+ createTopic('streaming'),+ createTopic('failed', { status: 'failed' }),+ ],+ 'byStatus',+ { field: 'updatedAt', loadingTopicIds: new Set(['streaming']), resolveDeviceId },+ );++ expect(ids(groups)).toEqual([+ ['pending', ['failed']],+ ['running', ['streaming']],+ ['completed', ['done']],+ ]);+ });++ it('sections by time on the configured sort field', () => {+ const now = Date.now();+ const groups = groupProjectTopics(+ [+ createTopic('old-update', { createdAt: now, updatedAt: now - 400 * 86_400_000 }),+ createTopic('fresh-update', { createdAt: now - 400 * 86_400_000, updatedAt: now }),+ ],+ 'byTime',+ { field: 'updatedAt', resolveDeviceId },+ );++ expect(groups?.[0]).toMatchObject({ id: 'today' });+ expect(groups?.[0].children.map((topic) => topic.id)).toEqual(['fresh-update']);+ });+});diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.ts b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.tsnew file mode 100644index 00000000000..883df93dfaf--- /dev/null+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/subGroups.ts@@ -0,0 +1,54 @@+import { type ProjectTopicSubGroupMode } from '@/store/global/initialState';+import { type ChatTopic, type GroupedTopic } from '@/types/topic';+import {+ groupTopicsByStatus,+ groupTopicsByTime,+ groupTopicsByUpdatedTime,+} from '@/utils/client/topic';++export const DEVICE_SUB_GROUP_PREFIX = 'device:';+export const UNKNOWN_DEVICE_SUB_GROUP_ID = 'device-unknown';++interface GroupProjectTopicsOptions {+ field: 'createdAt' | 'updatedAt';+ loadingTopicIds?: ReadonlySet<string>;+ /** The machine a topic runs on — its project directory's device, else its pinned device. */+ resolveDeviceId: (topic: ChatTopic) => string | undefined;+}++/**+ * Section the topics of one byProject sidebar group. Returns `undefined` for+ * `none`, so the caller keeps the plain list.+ *+ * Device sections keep the incoming (sidebar-sorted) topic order, so the machine+ * with the most recent topic comes first; topics whose machine can't be resolved+ * (path-only or conversation-only rows) trail in their own section.+ */+export const groupProjectTopics = (+ topics: ChatTopic[],+ mode: ProjectTopicSubGroupMode,+ { field, loadingTopicIds, resolveDeviceId }: GroupProjectTopicsOptions,+): GroupedTopic[] | undefined => {+ if (mode === 'byTime')+ return field === 'updatedAt' ? groupTopicsByUpdatedTime(topics) : groupTopicsByTime(topics);+ if (mode === 'byStatus') return groupTopicsByStatus(topics, field, loadingTopicIds);+ if (mode !== 'byDevice') return undefined;++ const groups = new Map<string, ChatTopic[]>();+ const unknown: ChatTopic[] = [];+ for (const topic of topics) {+ const deviceId = resolveDeviceId(topic);+ if (!deviceId) {+ unknown.push(topic);+ continue;+ }+ const id = `${DEVICE_SUB_GROUP_PREFIX}${deviceId}`;+ const existing = groups.get(id);+ if (existing) existing.push(topic);+ else groups.set(id, [topic]);+ }++ const result: GroupedTopic[] = Array.from(groups, ([id, children]) => ({ children, id }));+ if (unknown.length) result.push({ children: unknown, id: UNKNOWN_DEVICE_SUB_GROUP_ID });+ return result;+};diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsxindex 5a47c064da5..c106c7cfe23 100644--- a/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx@@ -6,22 +6,22 @@ import {AccordionTrigger,Text,} from '@lobehub/ui/base-ui';-import dayjs from 'dayjs';import isEqual from 'fast-deep-equal';import { memo, useMemo } from 'react';import { useTranslation } from 'react-i18next';import TopicItem from '../../List/Item';import { type GroupItemComponentProps } from '../GroupedAccordion';--const preformat = (id: string) =>- id.startsWith('20') ? (id.includes('-') ? dayjs(id).format('MMMM') : id) : undefined;+import { formatTimeGroupId } from './timeGroupTitle';const GroupItem = memo<GroupItemComponentProps>(({ group }) => {const { t } = useTranslation('topic');const { id, title, children } = group;- const timeTitle = useMemo(() => preformat(id) ?? t(`groupTitle.byTime.${id}` as any), [id, t]);+ const timeTitle = useMemo(+ () => formatTimeGroupId(id) ?? t(`groupTitle.byTime.${id}` as any),+ [id, t],+ );return (<AccordionItem value={id}>diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/timeGroupTitle.ts b/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/timeGroupTitle.tsnew file mode 100644index 00000000000..18deb0ae232--- /dev/null+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByTimeMode/timeGroupTitle.ts@@ -0,0 +1,8 @@+import dayjs from 'dayjs';++/**+ * Month (`2026-03`) and year (`2025`) bucket ids format themselves; the fixed+ * buckets (`today`, `week`, …) return `undefined` for the caller to translate.+ */+export const formatTimeGroupId = (id: string) =>+ id.startsWith('20') ? (id.includes('-') ? dayjs(id).format('MMMM') : id) : undefined;diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.tsindex 338af647664..a8b30d3ddb2 100644--- a/src/store/global/initialState.ts+++ b/src/store/global/initialState.ts@@ -143,6 +143,9 @@ export const MODEL_DETAIL_PANEL_EXPANDABLE_KEYS = [export type TaskViewMode = 'kanban' | 'list';+/** How topics inside one byProject sidebar group are sectioned. */+export type ProjectTopicSubGroupMode = 'none' | 'byDevice' | 'byTime' | 'byStatus';+export const DEFAULT_HOME_SIDEBAR_EXPANDED_KEYS = ['recents', 'agent', 'private'];export interface SystemStatus {@@ -300,6 +303,11 @@ export interface SystemStatus {* number of private agents (ungrouped) to display in the Private sidebar bucket*/privateAgentPageSize?: number;+ /**+ * Per byProject group (keyed by the group id, e.g. `project-id:<id>`): how its+ * topics are sectioned. Absent means `none`.+ */+ projectTopicSubGroupModeByGroup?: Record<string, ProjectTopicSubGroupMode>;readNotificationSlugs?: string[];/*** number of recent items to displaydiff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.tsindex 85fe268e812..d6040619500 100644--- a/src/store/global/selectors/systemStatus.ts+++ b/src/store/global/selectors/systemStatus.ts@@ -3,6 +3,7 @@ import { type TopicGroupMode } from '@/types/topic';import type {GlobalState,ModelDetailPanelExpandedKey,+ ProjectTopicSubGroupMode,SystemStatus,WorkspaceOverridableField,} from '../initialState';@@ -90,6 +91,11 @@ const collapsedTopicGroupKeys =(s: GlobalState): string[] | undefined =>s.status.collapsedTopicGroupKeysByMode?.[mode];+const projectTopicSubGroupMode =+ (groupId: string) =>+ (s: GlobalState): ProjectTopicSubGroupMode =>+ s.status.projectTopicSubGroupModeByGroup?.[groupId] ?? 'none';+const agentSidebarSections =(agentId: string | undefined) =>(s: GlobalState): Record<string, boolean> | undefined =>@@ -550,6 +556,7 @@ export const systemStatusSelectors = {verifyReportPanelWidth,tokenDisplayFormatShort,collapsedTopicGroupKeys,+ projectTopicSubGroupMode,topicPageSize,videoPanelWidth,videoTopicViewMode,