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。

feat(desktop): 对话组新建落在所属设备上

Dashfd9364ca5442
diff --git a/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts b/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
index 1edf0436b0..782cee62a4 100644
--- a/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
+++ b/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
@@ -137,9 +137,10 @@ describe('Mixed main list (sidebar-redesign D 期)', () => {
'resolveDialogueDeviceTarget(selectedMachineId, switcherDevices, deviceListSettled)',
);
expect(handler).toContain("selectedDialogueDeviceResolution.status === 'pending'");
- expect(handler).toContain(
- 'state: makeDialogueNewMakerRouteState(selectedDialogueDeviceResolution.target)',
- );
+ // 无显式目标时仍走作用域推断(pending 守卫 + resolution.target);显式目标见下一条。
+ expect(handler).toContain('if (deviceTarget === undefined)');
+ expect(handler).toContain('target = selectedDialogueDeviceResolution.target;');
+ expect(handler).toContain('state: makeDialogueNewMakerRouteState(target)');
expect(handler).not.toContain('resetDraftWorkspaceTargets');
expect(handler).not.toContain('patchNewMakerDraft');
expect(newMakerDraftRouteSource).toContain('readNewMakerDialogueTargetRequest(location.state)');
@@ -160,6 +161,27 @@ describe('Mixed main list (sidebar-redesign D 期)', () => {
expect(sidebarSource).toContain('isCreateDialogueDisabled={dialogueCreatePending}');
});
+ // 2026-08-12 用户裁决:按设备分组时,某个设备段下「对话」组的新建必须落在该设备上,
+ // 不再按当前机器作用域猜(作用域可能是「所有」或另一台设备)。
+ it('creates the dialogue on the device that owns the group when grouping by device', () => {
+ // 设备段把自己的设备作为创建目标传下去:本机段 null,远程段 {deviceId, deviceName}。
+ expect(projectsSectionSource).toMatch(
+ /renderNonProjectEntry\(\s*entry,\s*key,\s*section\.deviceId\s*\?\s*\{ deviceId: section\.deviceId, deviceName: name \}\s*:\s*null,\s*\)/,
+ );
+ // 不按设备分组的两条渲染路径不传目标 → 上层沿用作用域推断。
+ expect(projectsSectionSource).toContain('renderNonProjectEntry(entry, DIALOGUE_GROUP_ALL_KEY)');
+ expect(projectsSectionSource).toContain(
+ 'onCreateDialogue={() => onCreateDialogue(dialogueDeviceTarget)}',
+ );
+ // 目标设备离线 → 禁用新建并复用远程写保护文案(被控端才是真正的创建方)。
+ expect(projectsSectionSource).toContain("t('ccAgent.remoteSession.actionsUnavailable')");
+ expect(projectsSectionSource).toMatch(/const targetDeviceOffline = Boolean\(/);
+ // 显式目标不受作用域解析 pending 影响(目标已定,无需等设备目录 settle)。
+ expect(projectsSectionSource).toContain(
+ 'dialogueDeviceTarget === undefined ? isCreateDialogueDisabled : false',
+ );
+ });
+
it('allows the shared create route to send a standalone dialogue without picking a project', () => {
// 产品决策:新建入口、对话段 +、项目行内 + 都进同一个创建页;差异只在默认
// workingDir。workingDir 为空时直接创建 dialogue,不再强制弹项目 picker。
diff --git a/apps/desktop/src/renderer/__tests__/newMakerGenericCreatePreservesDraft.test.ts b/apps/desktop/src/renderer/__tests__/newMakerGenericCreatePreservesDraft.test.ts
index e93906ece3..3b9415db6f 100644
--- a/apps/desktop/src/renderer/__tests__/newMakerGenericCreatePreservesDraft.test.ts
+++ b/apps/desktop/src/renderer/__tests__/newMakerGenericCreatePreservesDraft.test.ts
@@ -59,9 +59,10 @@ describe('通用「新建」保留 newMakerDraft 选择', () => {
it('显式「新建对话」入口仍清空 workingDir,但由创建页集中迁移目标', () => {
const block = extractHandlerBlock(sidebarUpperSource, 'handleCreateDialogue');
- expect(block).toContain(
- 'makeDialogueNewMakerRouteState(selectedDialogueDeviceResolution.target)',
- );
+ // 2026-08-12 起 handler 接受可选的显式设备目标(按设备分组时对话组给出所属设备);
+ // 未给时仍按当前机器作用域推断,route state 由统一的 target 变量组装。
+ expect(block).toContain('state: makeDialogueNewMakerRouteState(target)');
+ expect(block).toContain('target = selectedDialogueDeviceResolution.target;');
expect(block).toContain("selectedDialogueDeviceResolution.status === 'pending'");
expect(block).not.toContain('resetDraftWorkspaceTargets');
expect(draftRouteSource).toMatch(
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index aba80b0c0b..3ba2568fa0 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -247,7 +247,7 @@ import {
useDeleteScheduleWithSessions,
type DeletedScheduleGeneratedSessionResult,
} from '@/features/scheduler/hooks/useDeleteScheduleWithSessions';
-import { resolveDialogueDeviceTarget } from './lib/dialogueCreateTarget';
+import { resolveDialogueDeviceTarget, type DialogueDeviceTarget } from './lib/dialogueCreateTarget';
import { makeDialogueNewMakerRouteState } from './lib/newMakerRouteState';
const log = createLogger('CCAgentSidebarUpper');
@@ -2057,16 +2057,32 @@ function ExpandedView({
t,
]);
- const handleCreateDialogue = useCallback(() => {
- // 冷启动时 effective selection 会刻意保留持久化的唯一远端选择,但设备目录可能尚未
- // settle、switcherDevices 仍为空。此时不能把“尚未解析”当成“确认缺失”并回落本机;
- // 展开态段头与折叠 rail 面板共用这个 handler,因此在目标可判定前统一不创建。
- if (selectedDialogueDeviceResolution.status === 'pending') return;
- handleClearSelection();
- navigate('/cc-agent/new', {
- state: makeDialogueNewMakerRouteState(selectedDialogueDeviceResolution.target),
- });
- }, [handleClearSelection, navigate, selectedDialogueDeviceResolution]);
+ /**
+ * 新建对话。目标设备两种来源:
+ * - 调用方给出显式目标(`deviceTarget` 传了值):按设备分组时对话组隶属于某个
+ * 设备段,组头的新建就该落在该设备上(null = 本机段),不再看当前机器作用域
+ * (2026-08-12 用户裁决)。目标已确定,也就不受作用域解析的 pending 影响。
+ * - 未给(undefined):沿用作用域推断——仅当作用域唯一指向一台远程机器时继承它。
+ */
+ const handleCreateDialogue = useCallback(
+ (deviceTarget?: DialogueDeviceTarget | null) => {
+ let target: DialogueDeviceTarget | null;
+ if (deviceTarget === undefined) {
+ // 冷启动时 effective selection 会刻意保留持久化的唯一远端选择,但设备目录可能尚未
+ // settle、switcherDevices 仍为空。此时不能把“尚未解析”当成“确认缺失”并回落本机;
+ // 展开态段头与折叠 rail 面板共用这个 handler,因此在目标可判定前统一不创建。
+ if (selectedDialogueDeviceResolution.status === 'pending') return;
+ target = selectedDialogueDeviceResolution.target;
+ } else {
+ target = deviceTarget;
+ }
+ handleClearSelection();
+ navigate('/cc-agent/new', {
+ state: makeDialogueNewMakerRouteState(target),
+ });
+ },
+ [handleClearSelection, navigate, selectedDialogueDeviceResolution],
+ );
const handleLinkCodexProject = useCallback(
async (project: ProjectNode) => {
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.tsx
index 070471739e..fc5960d839 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
@@ -59,6 +59,7 @@ import {
type MainListEntry,
} from '../../lib/mainListModel';
import { buildSessionSourceLabelMap } from '../../lib/sessionSourceLabel';
+import type { DialogueDeviceTarget } from '../../lib/dialogueCreateTarget';
import { SidebarFilterPopover } from '../SidebarFilterPopover';
import { SectionCollapse } from '../SectionCollapse';
import { SessionEntryList } from '../SessionEntryList';
@@ -158,8 +159,13 @@ export interface ProjectsSectionProps {
* null / 空数组 = 没有远程设备连接 → 设备分组选项隐藏、不切段。
*/
remoteDeviceIndex?: ReadonlyMap<string, { name: string; online: boolean }> | null;
- /** 「对话」组行右侧的新建入口(与项目行 SquarePen 等位):新建不绑项目的对话任务。 */
- onCreateDialogue: () => void;
+ /**
+ * 「对话」组行右侧的新建入口(与项目行 SquarePen 等位):新建不绑项目的对话任务。
+ * 按设备分组时对话组隶属于某个设备段,这里显式给出该段的设备作为创建目标
+ * (null = 本机段),不再让上层按当前机器作用域猜(2026-08-12 用户裁决);
+ * 不分组时不传,沿用上层的作用域推断。
+ */
+ onCreateDialogue: (deviceTarget?: DialogueDeviceTarget | null) => void;
/** 对话设备解析在途时禁用新建(与旧对话段 createDisabled 同语义)。 */
isCreateDialogueDisabled?: boolean;
}
@@ -481,7 +487,13 @@ export function ProjectsSection({
// 散排对话行 / 「对话」组行。散排行带来源标签(hover);对话组行 = 可折叠的
// 分组头 + 组内会话(折叠上限与对话段旧口径一致)。dialogueGroupKey 标识
// 该组属于哪个段(设备段 key / 单一列表 DIALOGUE_GROUP_ALL_KEY),折叠独立。
- const renderNonProjectEntry = (entry: MainListEntry, dialogueGroupKey: string): ReactNode => {
+ // dialogueDeviceTarget:按设备分组时该段的设备(null = 本机段),组头新建即落在
+ // 这台设备上;不分组时传 undefined,由上层按当前机器作用域推断。
+ const renderNonProjectEntry = (
+ entry: MainListEntry,
+ dialogueGroupKey: string,
+ dialogueDeviceTarget?: DialogueDeviceTarget | null,
+ ): ReactNode => {
if (entry.kind === 'session') {
return (
<SessionEntryList
@@ -507,14 +519,26 @@ export function ProjectsSection({
}
if (entry.kind === 'dialogue-group') {
const isCollapsed = collapsedDialogueGroups.has(dialogueGroupKey);
+ // 目标设备离线时不能在它上面新建(被控端才是真正的创建方)——与远程项目行的
+ // 新建同款保护(isDeviceLinkWriteBlocked / actionsUnavailable 文案)。
+ const targetDeviceOffline = Boolean(
+ dialogueDeviceTarget && !remoteDeviceIndex?.get(dialogueDeviceTarget.deviceId)?.online,
+ );
+ // 显式目标下不看作用域解析的 pending:目标已定,无需等设备目录 settle。
+ const createDisabled =
+ (dialogueDeviceTarget === undefined ? isCreateDialogueDisabled : false) ||
+ targetDeviceOffline;
return (
<DialogueGroupNode
key={`dialogue-group:${dialogueGroupKey}`}
sessions={entry.sessions}
collapsed={isCollapsed}
onToggle={() => setDialogueCollapsed([dialogueGroupKey], !isCollapsed)}
- onCreateDialogue={onCreateDialogue}
- isCreateDisabled={isCreateDialogueDisabled}
+ onCreateDialogue={() => onCreateDialogue(dialogueDeviceTarget)}
+ isCreateDisabled={createDisabled}
+ createDisabledReason={
+ targetDeviceOffline ? t('ccAgent.remoteSession.actionsUnavailable') : undefined
+ }
parentSectionCollapsed={isSectionCollapsed}
disableSessionCollapse={disableSessionCollapse}
activeSessionId={activeSessionId}
@@ -719,7 +743,14 @@ export function ProjectsSection({
{section.entries.map((entry) =>
entry.kind === 'project'
? renderProjectNode(entry.project)
- : renderNonProjectEntry(entry, key),
+ : // 本机段 → null(强制本机);远程段 → 该设备。
+ renderNonProjectEntry(
+ entry,
+ key,
+ section.deviceId
+ ? { deviceId: section.deviceId, deviceName: name }
+ : null,
+ ),
)}
</div>
</SectionCollapse>
@@ -770,6 +801,7 @@ function DialogueGroupNode({
onToggle,
onCreateDialogue,
isCreateDisabled,
+ createDisabledReason,
parentSectionCollapsed,
disableSessionCollapse,
activeSessionId,
@@ -790,9 +822,14 @@ function DialogueGroupNode({
sessions: Session[];
collapsed: boolean;
onToggle: () => void;
- /** 组头右侧的新建入口(与项目行 SquarePen 等位):新建不绑项目的对话任务。 */
+ /**
+ * 组头右侧的新建入口(与项目行 SquarePen 等位):新建不绑项目的对话任务。
+ * 目标设备由父层按所在设备段决定(闭包传入),本组件不关心。
+ */
onCreateDialogue: () => void;
isCreateDisabled: boolean;
+ /** 禁用原因(目标设备离线),有值时替换按钮 tooltip / aria——与远程项目行同款。 */
+ createDisabledReason?: string;
parentSectionCollapsed: boolean;
disableSessionCollapse: boolean;
activeSessionId?: string;
@@ -857,10 +894,10 @@ function DialogueGroupNode({
'opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100',
)}
>
- <Tip text={t('ccAgent.sidebar.newDialogue')}>
+ <Tip text={createDisabledReason ?? t('ccAgent.sidebar.newDialogue')}>
<button
type="button"
- aria-label={t('ccAgent.sidebar.newDialogue')}
+ aria-label={createDisabledReason ?? t('ccAgent.sidebar.newDialogue')}
disabled={isCreateDisabled}
onClick={(e) => {
e.stopPropagation();
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index 20be2e6aa7..9f9f07b6c1 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -45,7 +45,7 @@
|---|---|---|
| 按项目分组 | **开** | 有项目的任务收进项目行;关闭则平铺、行尾带项目小标签 |
| 按设备分组 | **开** | 最外层按设备切段,分组头带在线状态、可折叠;**仅有远程设备连接时该选项才出现**(与顶部设备下拉同一出现条件);远程断开时选项消失、效果一并解除 |
-| 对话归为一组 | **关** | 无项目任务收进「对话」组(归属分类名,按 task-and-conversation-naming §2.3);关闭则散排 |
+| 对话归为一组 | **关** | 无项目任务收进「对话」组(归属分类名,按 task-and-conversation-naming §2.3);关闭则散排。组头右侧有与项目行等位的新建入口 |
层级方向固定:设备 → 项目/对话组 → 任务。全关 = 纯平铺。
@@ -59,6 +59,12 @@
行内重复标注只是挤占项目名宽度。远程图标保留(表达「远程 + 连接状态」,
不重复归属信息)。置顶区不受分组影响,照常显示。
+**对话组的新建落在哪台设备**(2026-08-12 用户裁决):按设备分组时,对话组隶属于
+某个设备段,组头的新建就在**该段的设备**上创建(本机段 = 本机),不再看当前机器
+作用域——作用域可能是「所有」或另一台设备,按它猜会把任务建错地方。目标设备离线时
+禁用该入口并复用远程写保护文案(被控端才是真正的创建方)。不按设备分组时没有归属
+歧义,沿用原有的作用域推断(仅当作用域唯一指向一台远程机器时继承它)。
+
**默认组合(定稿)**:按项目分组 + 按设备分组开、对话不归组——即项目行与
散排对话按活动时间混排,这与手机版现状(#1303)一致。