Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 单机范围下保留按设备分组 (#5485)
Dashcd3921a43c88
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.tsindex a1dc5be937..1b1538b046 100644--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts@@ -443,15 +443,16 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不});it('项目视图:范围判定走 effective 选择 hook,不再有旧 hasRemoteMachines 结构', () => {- // 单机范围下设备分组退场(2026-08-13 用户定稿)——生效与选项可见共用- // deviceGroupingAvailable,由 effective 机器选择派生。+ // 单机范围下设备分组照常保留(2026-10-05 用户定稿,推翻 2026-08-13「单机范围退场」)+ // ——生效与选项可见共用 deviceGroupingAvailable,只看有无远程设备。expect(projectsSectionSource).toContain('useEffectiveSelectedMachineId');- expect(projectsSectionSource).toContain(- 'const singleMachineScope = selectedMachineId !== MACHINE_ALL && selectedMachineId.length === 1',- );- expect(projectsSectionSource).toContain(- 'const deviceGroupingAvailable = hasRemoteDevices && !singleMachineScope',+ expect(projectsSectionSource).not.toContain('singleMachineScope');+ expect(projectsSectionSource).toContain('const deviceGroupingAvailable = hasRemoteDevices;');+ expect(sidebarUpperSource).toContain(+ 'const deviceGroupingAvailable = (remoteDeviceIndex?.size ?? 0) > 0;',);+ // 读取中 / 失败的远程设备空段头不算已有内容,不能遮掉整屏加载与失败提示。+ expect(sidebarUpperSource).toContain('hasSettledOnlineDeviceSection(');expect(projectsSectionSource).toContain('hasRemoteDevices={deviceGroupingAvailable}');expect(projectsSectionSource).not.toContain('hasRemoteMachines');expect(sidebarUpperSource).toContain("if (device.status === 'rejected') continue;");diff --git a/apps/desktop/src/renderer/__tests__/mainListModel.test.ts b/apps/desktop/src/renderer/__tests__/mainListModel.test.tsindex 2bc472f8c7..b3f52c79ef 100644--- a/apps/desktop/src/renderer/__tests__/mainListModel.test.ts+++ b/apps/desktop/src/renderer/__tests__/mainListModel.test.ts@@ -19,6 +19,7 @@ import {sortSessionsForMainList,partitionCindyMakeSessions,onlineDeviceSectionIds,+ hasSettledOnlineDeviceSection,splitEntriesByDevice,type MainListEntry,} from '../features/cc-agent/lib/mainListModel';@@ -1095,6 +1096,22 @@ describe('splitEntriesByDevice — 拆段后按本段重排', () => {expect(onlineDeviceSectionIds(devices, ['local', 'a'])).toEqual([null, 'a']);});+ it('does not count empty sections of remote devices still loading or failed', () => {+ const devices = new Map([+ ['a', { online: true }],+ ['b', { online: true }],+ ]);+ // 单机范围选中一台正在首次读取 / 读取失败的远程设备:空段头不能遮掉整屏提示。+ expect(hasSettledOnlineDeviceSection(devices, ['a'], new Set(['a']))).toBe(false);+ expect(hasSettledOnlineDeviceSection(devices, ['a', 'b'], new Set(['a', 'b']))).toBe(false);+ // 读取就绪后,在线空段照常算作已有内容。+ expect(hasSettledOnlineDeviceSection(devices, ['a'], new Set())).toBe(true);+ expect(hasSettledOnlineDeviceSection(devices, ['a', 'b'], new Set(['a']))).toBe(true);+ // 本机段不受远程读取状态影响。+ expect(hasSettledOnlineDeviceSection(devices, ['local'], new Set(['a']))).toBe(true);+ expect(hasSettledOnlineDeviceSection(devices, 'all', new Set(['a', 'b']))).toBe(true);+ });+it('keeps offline tasks and avoids duplicating populated online device sections', () => {const entries: MainListEntry[] = ['online', 'offline'].map((deviceLinkDeviceId) => ({kind: 'session',diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsxindex a7be9828d8..d6cb525507 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx@@ -173,7 +173,7 @@ import {import { PinnedSection, type PinnedSidebarEntry } from './sidebar/sections/PinnedSection';import { ProjectNode as ProjectNodeView } from './sidebar/sections/ProjectNode';import { compareDialogueSessions, type DialogueSortBy } from './sidebar/sections/DialogueSection';-import { onlineDeviceSectionIds } from './lib/mainListModel';+import { hasSettledOnlineDeviceSection } from './lib/mainListModel';import { sidebarPriorityContext } from './lib/sidebarPriorityContext';import {holdSidebarViewedPriority,@@ -1914,16 +1914,23 @@ function ExpandedView({);// D 期:按日期分组已删除(visibleDateSessions 随 DateGroupedSessionsSection 一并下线)。- // 与 ProjectsSection.deviceGroupingAvailable 同一门控:范围收窄到单台机器时- // 「按设备分组」选项隐藏。占位分支也要挂范围标题,不能各写一份。- const deviceGroupingAvailable =- (remoteDeviceIndex?.size ?? 0) > 0 &&- !(selectedMachineId !== MACHINE_ALL && selectedMachineId.length === 1);-+ // 与 ProjectsSection.deviceGroupingAvailable 同一门控:有远程设备即可用,+ // 范围收窄到单台机器时也保留。占位分支也要挂范围标题,不能各写一份。+ const deviceGroupingAvailable = (remoteDeviceIndex?.size ?? 0) > 0;++ const unsettledRemoteDeviceIds = new Set(+ [...remoteSessionBootstrapLoadingDevices, ...remoteSessionBootstrapFailures].map(+ (device) => device.deviceId,+ ),+ );const hasVisibleSidebarContent =(deviceGroupingAvailable &&filter.groupDevice &&- onlineDeviceSectionIds(remoteDeviceIndex, selectedMachineId).length > 0) ||+ hasSettledOnlineDeviceSection(+ remoteDeviceIndex,+ selectedMachineId,+ unsettledRemoteDeviceIds,+ )) ||visiblePinnedEntries.length > 0 ||visibleUnclassified.length > 0 ||visibleProjectsWithVendor.length > 0 ||@@ -3829,8 +3836,7 @@ function ExpandedView({filter={filter}allKnownProjects={visibleProjectUniverse}dialogueCount={allGroups.dialogues.length}- // 与段头实例同一门控:范围收窄到单台机器时「按设备分组」选项隐藏- // (2026-08-13 用户定稿,详见 ProjectsSection.deviceGroupingAvailable)。+ // 与段头实例同一门控(详见 ProjectsSection.deviceGroupingAvailable)。hasRemoteDevices={deviceGroupingAvailable}contextMenuPos={organizeMenuPos}onContextMenuOpenChange={(open) => {diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts b/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.tsindex 8dd455bce1..df98851c7e 100644--- a/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts+++ b/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts@@ -515,6 +515,21 @@ export function onlineDeviceSectionIds(return ids;}+/**+ * 在线设备空段能否算作「侧栏已有内容」:本机段恒算;远程段只在其任务快照已就绪时算。+ * 首次读取中 / 失败的远程设备只有一个空段头,不能遮掉整屏的加载或失败提示+ * (单机范围选中一台正在加载的远程设备时尤其如此)。+ */+export function hasSettledOnlineDeviceSection(+ devices: ReadonlyMap<string, { online: boolean }> | null | undefined,+ selection: MachineSelection,+ unsettledDeviceIds: ReadonlySet<string>,+): boolean {+ return onlineDeviceSectionIds(devices, selection).some(+ (id) => id === null || !unsettledDeviceIds.has(id),+ );+}+function entryDeviceId(entry: MainListEntry): string | null {if (entry.kind === 'project') return entry.project.deviceLinkDeviceId ?? null;if (entry.kind === 'session') return entry.session.deviceLinkDeviceId ?? null;diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsxindex 3cf6db0719..feb82fa611 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx@@ -50,7 +50,6 @@ import { cn } from '@/lib/utils';import { Tip } from '@/components/ui/tooltip';import { useEffectiveSelectedMachineId } from '@/features/device-link/useMachineSwitcher';import { useRemoteDevices } from '@/features/device-link/remoteProjectsStore';-import { MACHINE_ALL } from '@/features/device-link/selectedMachineStore';import {projectOrderWriteLedger,resolveDisplayedProjectOrder,@@ -572,13 +571,11 @@ export function ProjectsSection({// E 期「按设备分组」:有远程设备连接 + 开关开 → 按设备切段(本机在前,// 远程按设备切换栏顺序);其余情况单段直渲。切段后按当前排序重排本段。// 自定义项目顺序可以和设备分组叠加:每段内项目行按全局序的子集排,段内可拖。- // 范围收窄到单台机器时同样退场(2026-08-13 用户定稿):只有一台无段可切,- // 唯一的段头还会和范围标题重复报同一个设备名;整理菜单的选项行同步隐藏- // (deviceGroupingAvailable),偏好照旧不改写、范围放宽自动恢复。+ // 范围收窄到单台机器时照常保留分组与整理菜单选项(2026-10-05 用户定稿,推翻+ // 2026-08-13「单机范围退场」):单段也挂设备段头,与多机范围同一套 UI。const hasRemoteDevices = (remoteDeviceIndex?.size ?? 0) > 0;const selectedMachineId = useEffectiveSelectedMachineId();- const singleMachineScope = selectedMachineId !== MACHINE_ALL && selectedMachineId.length === 1;- const deviceGroupingAvailable = hasRemoteDevices && !singleMachineScope;+ const deviceGroupingAvailable = hasRemoteDevices;const deviceGroupingActive = deviceGroupingAvailable && filter.groupDevice;// F-PJ-10:未分类区在 projects 为具体多选状态时不渲染(spec 验收第 14 条)const unclassifiedHidden = filter.projects !== 'all';diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.mdindex cfc4c7ab89..717f620c69 100644--- a/docs/product-rules/sidebar-redesign-plan.md+++ b/docs/product-rules/sidebar-redesign-plan.md@@ -89,7 +89,7 @@|---|---|---|| 按项目 | **开** | 有项目的任务收进项目行;关闭则平铺、行尾带项目小标签 || 按对话 | **开** | 无项目任务收进「对话」组(归属分类名,按 task-and-conversation-naming §2.3);关闭则散排。组头右侧有与项目行等位的新建入口。(2026-08-12 用户裁决改默认开,原定稿为关) |-| 按设备 | **开** | 最外层按设备切段,分组头带在线状态、可折叠;**仅有远程设备连接时该选项才出现**;远程断开时选项消失、效果一并解除——**只解除生效,不改写偏好**(生效 = 有远程设备 ∧ 偏好开,两者分离;断线再重连后按原偏好自动恢复分组。2026-08-13 复查补记:早期原型在断开时直接把偏好写成关,是错误做法,勿照抄)。**范围收窄到单台机器时同样退场**(2026-08-13 用户定稿):只有一台无段可切,唯一的段头还会与范围标题重复报同一个设备名;选项行同步隐藏、偏好不改写,范围放宽自动恢复 |+| 按设备 | **开** | 最外层按设备切段,分组头带在线状态、可折叠;**仅有远程设备连接时该选项才出现**;远程断开时选项消失、效果一并解除——**只解除生效,不改写偏好**(生效 = 有远程设备 ∧ 偏好开,两者分离;断线再重连后按原偏好自动恢复分组。2026-08-13 复查补记:早期原型在断开时直接把偏好写成关,是错误做法,勿照抄)。**范围收窄到单台机器时照常保留**(2026-10-05 用户定稿,推翻 2026-08-13「单机范围退场」):选项行照常可见,偏好开时仍按设备切段、挂该设备的段头,与多机范围同一套 UI |层级方向固定:设备 → 项目/对话组 → 任务。全关 = 纯平铺。