Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 设备分组按本段重排,草稿进对应设备,被拒设备不参与
Dash629014819c0c
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.tsindex 596b6436e1..57cf9e249a 100644--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts@@ -369,6 +369,7 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不);expect(projectsSectionSource).toContain('hasRemoteDevices={deviceGroupingAvailable}');expect(projectsSectionSource).not.toContain('hasRemoteMachines');+ expect(sidebarUpperSource).toContain("if (device.status === 'rejected') continue;");});// (侧边栏重设计 D 期:按日期分组段已删除,其 MachineSwitcherMenu / 空态 /diff --git a/apps/desktop/src/renderer/__tests__/mainListModel.test.ts b/apps/desktop/src/renderer/__tests__/mainListModel.test.tsindex 4895c290d8..7dd3d300a6 100644--- a/apps/desktop/src/renderer/__tests__/mainListModel.test.ts+++ b/apps/desktop/src/renderer/__tests__/mainListModel.test.ts@@ -11,6 +11,7 @@ import type { ProjectNode } from '../features/cc-agent/lib/projectGrouping';import {buildMainListEntries,sessionPriorityRank,+ splitEntriesByDevice,type MainListEntry,} from '../features/cc-agent/lib/mainListModel';@@ -212,3 +213,56 @@ describe('buildMainListEntries — 排序口径', () => {expect(labels(entries)).toEqual(['p:beta', 'p:alpha', 's:newest-dlg']);});});++describe('splitEntriesByDevice — 拆段后按本段重排', () => {+ it('re-sorts each device section by its own activity after splitting a dialogue group', () => {+ const localOld = session({+ updatedAt: '2026-08-01T00:00:00Z',+ title: 'local-old',+ });+ const remoteNew = session({+ updatedAt: '2026-08-13T00:00:00Z',+ title: 'remote-new',+ deviceLinkDeviceId: 'dev-a',+ });+ const localProject = project('local-proj', [+ session({+ updatedAt: '2026-08-10T00:00:00Z',+ title: 'local-proj',+ workingDir: '/local',+ workspaceKind: 'project',+ }),+ ]);+ const entries = buildMainListEntries({+ projects: [localProject],+ dialogues: [localOld, remoteNew],+ groupBy: 'project',+ groupDialogue: true,+ sortBy: 'recency',+ manualProjectOrder: [],+ });+ const sections = splitEntriesByDevice(entries, ['dev-a'], { sortBy: 'recency' });+ const local = sections.find((section) => section.deviceId === null);+ expect(local && labels(local.entries)).toEqual(['p:local-proj', 'dlg-group']);+ });++ it('places unclassified drafts into the owning device section', () => {+ const remoteDraft = session({+ updatedAt: '2026-08-13T00:00:00Z',+ title: 'remote-draft',+ deviceLinkDeviceId: 'dev-a',+ });+ const entries = buildMainListEntries({+ projects: [],+ dialogues: [],+ unclassified: [remoteDraft],+ groupBy: 'project',+ groupDialogue: true,+ sortBy: 'recency',+ manualProjectOrder: [],+ });+ const sections = splitEntriesByDevice(entries, ['dev-a'], { sortBy: 'recency' });+ expect(sections.map((section) => section.deviceId)).toEqual(['dev-a']);+ expect(labels(sections[0].entries)).toEqual(['s:remote-draft']);+ });+});diff --git a/apps/desktop/src/renderer/__tests__/projectsSidebarSection.test.ts b/apps/desktop/src/renderer/__tests__/projectsSidebarSection.test.tsindex 0feb4a9259..317626d48d 100644--- a/apps/desktop/src/renderer/__tests__/projectsSidebarSection.test.ts+++ b/apps/desktop/src/renderer/__tests__/projectsSidebarSection.test.ts@@ -128,8 +128,9 @@ describe('Projects sidebar section', () => {// 切段会把前 N 名之外的设备连段头一起藏掉。it('device grouping splits the full list first, then collapses per section', () => {expect(projectsSectionSource).toContain(- 'return splitEntriesByDevice(mixedEntries, [...(remoteDeviceIndex?.keys() ?? [])])',+ 'return splitEntriesByDevice(mixedEntries, [...(remoteDeviceIndex?.keys() ?? [])], {',);+ expect(projectsSectionSource).toContain('unclassified: deviceGroupingActive && !unclassifiedHidden ? unclassified : []');// 每段独立折叠视图 + 段内作用域的「显示全部」(复核 P2:共用一个标志会让// 点任一段全段展开)。expect(projectsSectionSource).toMatch(diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsxindex 1391526035..fc58cbf202 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx@@ -1137,6 +1137,7 @@ function ExpandedView({const remoteDeviceIndex = useMemo(() => {const index = new Map<string, { name: string; online: boolean }>();for (const device of switcherDevices) {+ if (device.status === 'rejected') continue;index.set(device.deviceId, {name: device.name,online: device.status === 'connected',diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts b/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.tsindex 180628cebe..d1e5458d2f 100644--- a/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts+++ b/apps/desktop/src/renderer/features/cc-agent/lib/mainListModel.ts@@ -112,6 +112,8 @@ export interface BuildMainListEntriesInput {projects: readonly ProjectNode[];/** 无项目归属(workspaceKind dialogue)的可见会话。 */dialogues: readonly Session[];+ /** 未绑定目录的草稿。按设备分组时随条目进对应设备段。 */+ unclassified?: readonly Session[];/** 'project' = 项目行;'flat' = 项目内会话平铺为顶层条目。 */groupBy: 'project' | 'flat';/** true = 散排对话收进单个「对话组」条目。 */@@ -125,6 +127,7 @@ export interface BuildMainListEntriesInput {export function buildMainListEntries({projects,dialogues,+ unclassified = [],groupBy,groupDialogue,sortBy,@@ -158,6 +161,17 @@ export function buildMainListEntries({for (const session of dialogues) entries.push({ kind: 'session', session });}+ for (const session of unclassified) entries.push({ kind: 'session', session });++ return sortMainListEntries(entries, sortBy, manualProjectOrder, ctx);+}++function sortMainListEntries(+ entries: readonly MainListEntry[],+ sortBy: FilterSortBy,+ manualProjectOrder: readonly string[],+ ctx: MainListPriorityContext,+): MainListEntry[] {if (sortBy === 'manual') {// 手动:项目行按 manualProjectOrder;不在序的新项目由 normalize 追加到已排// 序列之后(沿用重设计前的既有语义;rank 兜底的 MAX_SAFE_INTEGER 只是防御,@@ -220,13 +234,18 @@ function entryDeviceId(entry: MainListEntry): string | null {* 把有序顶层条目切成设备段(E 期「按设备分组」):* - 段顺序:本机在前,远程设备按 deviceOrder(设备切换栏同序);* 不在 deviceOrder 里的设备(断线缓存等)按段内最新活动排在其后。- * - 段内保持入参 entries 的相对顺序(排序口径不变,只是切段)。+ * - 段内按当前 sortBy 重排(跨设备对话组拆开后,不能再沿用整组位置)。* - 「对话归为一组」开启时,跨设备的对话组会被拆成每设备一组——调用方无需* 预切分,这里对 dialogue-group 条目按成员设备拆分。*/export function splitEntriesByDevice(entries: readonly MainListEntry[],deviceOrder: readonly string[],+ options: {+ sortBy?: FilterSortBy;+ manualProjectOrder?: readonly string[];+ priorityContext?: MainListPriorityContext;+ } = {},): MainListDeviceSection[] {// 先把跨设备对话组拆开(组内成员可能来自不同设备)。const flattened: MainListEntry[] = [];@@ -260,14 +279,20 @@ export function splitEntriesByDevice(for (const id of orderedIds) {const sectionEntries = sections.get(id);if (sectionEntries && sectionEntries.length > 0) {- result.push({ deviceId: id, entries: sectionEntries });+ result.push({+ deviceId: id,+ entries: sortSectionEntries(sectionEntries, options),+ });sections.delete(id);}}// 不在 deviceOrder 的残余设备(断线缓存):按段内最新活动追加。const rest = [...sections.entries()].filter(([, sectionEntries]) => sectionEntries.length > 0)- .map(([deviceId, sectionEntries]) => ({ deviceId, entries: sectionEntries }))+ .map(([deviceId, sectionEntries]) => ({+ deviceId,+ entries: sortSectionEntries(sectionEntries, options),+ })).sort((a, b) =>Math.max(...b.entries.map(entryActivityMs)) - Math.max(...a.entries.map(entryActivityMs)),@@ -275,3 +300,20 @@ export function splitEntriesByDevice(result.push(...rest);return result;}++function sortSectionEntries(+ entries: readonly MainListEntry[],+ options: {+ sortBy?: FilterSortBy;+ manualProjectOrder?: readonly string[];+ priorityContext?: MainListPriorityContext;+ },+): MainListEntry[] {+ if (!options.sortBy) return [...entries];+ return sortMainListEntries(+ entries,+ options.sortBy,+ options.manualProjectOrder ?? [],+ options.priorityContext ?? EMPTY_PRIORITY_CONTEXT,+ );+}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 bc1eeaa8d3..63d0358fdf 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@@ -316,6 +316,7 @@ export function ProjectsSection({};for (const project of projects) for (const session of project.sessions) considerRemote(session);for (const session of dialogues) considerRemote(session);+ for (const session of unclassified) considerRemote(session);return {runningSessionIds: running,attentionSessionIds: attention,@@ -329,16 +330,37 @@ export function ProjectsSection({attentionKinds,projects,dialogues,+ unclassified,remoteActivityRevision,]);+ // E 期「按设备分组」:有远程设备连接 + 开关开 → 按设备切段(本机在前,+ // 远程按设备切换栏顺序);其余情况单段直渲。切段后按当前排序重排本段。+ // manual 一并排除(2026-08-13 复核 P1):manual 与设备分组不叠加是渲染层+ // 定稿,但此前生效判定没跟着排除——机器标签被藏、批量折叠键按逐设备派生、+ // 折叠状态机进入 collapse-devices 却没有可见效果,全是"派生态以为在设备+ // 分组、渲染实际是单段"的错位。生效判定必须与实际渲染模式同一份。+ // 范围收窄到单台机器时同样退场(2026-08-13 用户定稿):只有一台无段可切,+ // 唯一的段头还会和范围标题重复报同一个设备名;整理菜单的选项行同步隐藏+ // (deviceGroupingAvailable),偏好照旧不改写、范围放宽自动恢复。+ const hasRemoteDevices = (remoteDeviceIndex?.size ?? 0) > 0;+ const selectedMachineId = useEffectiveSelectedMachineId();+ const singleMachineScope = selectedMachineId !== MACHINE_ALL && selectedMachineId.length === 1;+ const deviceGroupingAvailable = hasRemoteDevices && !singleMachineScope;+ const deviceGroupingActive =+ deviceGroupingAvailable && filter.groupDevice && filter.sortBy !== 'manual';+ // F-PJ-10:未分类区在 projects 为具体多选状态时不渲染(spec 验收第 14 条)+ const unclassifiedHidden = filter.projects !== 'all';+// 混排模型(D 期):项目行 / 散排对话 / 对话组统一为顶层条目并按同一口径排序。// 这有意推翻旧「Dialogue 固定段在 Projects 之后」的裁决(mainListModel.ts 文件头)。+ // 设备分组开启时,未分类草稿并进混排再按设备切段;单段路径仍走顶部独立段。const mixedEntries = useMemo(() =>buildMainListEntries({projects,dialogues,+ unclassified: deviceGroupingActive && !unclassifiedHidden ? unclassified : [],groupBy: filter.groupBy,groupDialogue: filter.groupDialogue,sortBy: filter.sortBy,@@ -348,6 +370,9 @@ export function ProjectsSection({[projects,dialogues,+ unclassified,+ unclassifiedHidden,+ deviceGroupingActive,filter.groupBy,filter.groupDialogue,filter.sortBy,@@ -399,28 +424,25 @@ export function ProjectsSection({).map((entry) => entry.project);- // E 期「按设备分组」:有远程设备连接 + 开关开 → 按设备切段(本机在前,- // 远程按设备切换栏顺序);其余情况单段直渲。段内顺序保持混排口径不变。- // manual 一并排除(2026-08-13 复核 P1):manual 与设备分组不叠加是渲染层- // 定稿,但此前生效判定没跟着排除——机器标签被藏、批量折叠键按逐设备派生、- // 折叠状态机进入 collapse-devices 却没有可见效果,全是"派生态以为在设备- // 分组、渲染实际是单段"的错位。生效判定必须与实际渲染模式同一份。- // 范围收窄到单台机器时同样退场(2026-08-13 用户定稿):只有一台无段可切,- // 唯一的段头还会和范围标题重复报同一个设备名;整理菜单的选项行同步隐藏- // (deviceGroupingAvailable),偏好照旧不改写、范围放宽自动恢复。- const hasRemoteDevices = (remoteDeviceIndex?.size ?? 0) > 0;- const selectedMachineId = useEffectiveSelectedMachineId();- const singleMachineScope = selectedMachineId !== MACHINE_ALL && selectedMachineId.length === 1;- const deviceGroupingAvailable = hasRemoteDevices && !singleMachineScope;- const deviceGroupingActive =- deviceGroupingAvailable && filter.groupDevice && filter.sortBy !== 'manual';const deviceSections = useMemo<MainListDeviceSection[]>(() => {if (!deviceGroupingActive) return [{ deviceId: null, entries: [...visibleMixedEntries] }];// 设备分组:对**全量**条目先切段,折叠上限在渲染时每段独立应用(2026-08-13// review P1:此前先全局折叠再切段,排在前 N 名之外的设备连段头一起消失,// 看起来像"这台设备没有任务"——设备是最外层层级,折叠只能发生在段内)。- return splitEntriesByDevice(mixedEntries, [...(remoteDeviceIndex?.keys() ?? [])]);- }, [deviceGroupingActive, visibleMixedEntries, mixedEntries, remoteDeviceIndex]);+ return splitEntriesByDevice(mixedEntries, [...(remoteDeviceIndex?.keys() ?? [])], {+ sortBy: filter.sortBy,+ manualProjectOrder: filter.manualProjectOrder,+ priorityContext,+ });+ }, [+ deviceGroupingActive,+ visibleMixedEntries,+ mixedEntries,+ remoteDeviceIndex,+ filter.sortBy,+ filter.manualProjectOrder,+ priorityContext,+ ]);// 设备段折叠(E 期):本机段 key 'local'。const [collapsedDevices, setCollapsedDevices] = useState<ReadonlySet<string>>(new Set());// 「对话」组折叠:与项目行折叠同级的分组状态(用户裁决:对话组的折叠交互与@@ -551,9 +573,6 @@ export function ProjectsSection({dialogues.length > 0 ||filter.isFilterActive;- // F-PJ-10:未分类区在 projects 为具体多选状态时不渲染(spec 验收第 14 条)- const unclassifiedHidden = filter.projects !== 'all';-const renderProjectNode = (project: ProjectNodeData): ReactNode => (<ProjectNodekey={project.projectKey}@@ -694,24 +713,26 @@ export function ProjectsSection({/>{hasMainListContent ? (<div className="relative flex flex-col gap-1 pt-1 pr-0 pl-3">- <UnclassifiedSection- sessions={unclassified}- hidden={unclassifiedHidden}- activeSessionId={activeSessionId}- runningSessionIds={runningSessionIds}- attachedSessionIds={attachedSessionIds}- notifications={notifications}- scheduleSessionIndex={scheduleSessionIndex}- selectedSessionIds={selectedSessionIds}- onSessionClick={onSessionClick}- onAction={onAction}- onRename={onRename}- onTogglePin={onTogglePin}- onMoveSession={onMoveSession}- projectOptions={projectOptions}- onScheduleAction={onScheduleAction}- sessionVariant={mainSessionVariant}- />+ {!deviceGroupingActive ? (+ <UnclassifiedSection+ sessions={unclassified}+ hidden={unclassifiedHidden}+ activeSessionId={activeSessionId}+ runningSessionIds={runningSessionIds}+ attachedSessionIds={attachedSessionIds}+ notifications={notifications}+ scheduleSessionIndex={scheduleSessionIndex}+ selectedSessionIds={selectedSessionIds}+ onSessionClick={onSessionClick}+ onAction={onAction}+ onRename={onRename}+ onTogglePin={onTogglePin}+ onMoveSession={onMoveSession}+ projectOptions={projectOptions}+ onScheduleAction={onScheduleAction}+ sessionVariant={mainSessionVariant}+ />+ ) : null}{/* 混排渲染(D / E 期):- manual 排序:模型保证项目行连续在前 → 项目段整体走 SortableList 可拖,其后是散排对话 / 对话组。折叠+溢出时禁用拖拽(PR #246 review 同款),