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 complete dialogue actions and menu focus

DavidShen681210f90bf7
diff --git a/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx b/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
index dacf883e33..8c511e4092 100644
--- a/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/botGroupLampRendering.test.tsx
@@ -14,6 +14,7 @@ import {
import { ProjectsSection, type ProjectsSectionProps } from '../features/cc-agent/sidebar/sections/ProjectsSection';
import { useConversationSearch } from '../features/cc-agent/sidebar/ConversationSearchBox';
import { SidebarInlineSearch } from '../features/cc-agent/sidebar/SidebarInlineSearch';
+import { ConfirmDialogProvider, useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
vi.mock('@/components/ui/tooltip', () => ({ Tip: ({ children }: { children: ReactNode }) => children }));
@@ -93,7 +94,7 @@ function activity(phase: typeof phases[number]) {
// not right-click headers. Minimal regression input: one grouped dialogue and a
// bubbling, cancelable contextmenu event. Reuse this unit fixture to cover both
// device layouts, shared Bot/Make headers and the real ProjectNode menu.
-// Standalone: 6.16s including pnpm (Vitest 4.25s, 2.36s collection); reuses
+// Standalone: 6.47s including pnpm (Vitest 5.01s, 2.68s collection); reuses
// the existing component fixture without another jsdom file or module resets.
describe('Sidebar group context menus', () => {
// Issue #6575 P1 / DESIGN §14.2: the actual header is distinct from Radix's
@@ -142,8 +143,64 @@ describe('Sidebar group context menus', () => {
expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'ccAgent.search.placeholder' }));
});
+ // #6641 / DESIGN §14.2: no-op/notification-only actions have no next focus
+ // owner; a real confirmation or search input must keep its own focus.
+ it('returns focus after an archive action opens no follow-up dialog', async () => {
+ const p = props(false);
+ p.bots = [];
+ p.dialogues = [{ id: 'running', title: 'Running', status: 'active', workspaceKind: 'dialogue' } as Session];
+ p.runningSessionIds = new Set(['running']);
+ render(<ProjectsSection {...p} />);
+ const header = screen.getByText('ccAgent.sidebar.dialogues').closest<HTMLElement>('[role="button"]')!;
+ header.focus();
+ fireEvent.keyDown(header, { key: 'ContextMenu' });
+ fireEvent.click(within(await screen.findByRole('menu')).getByText('ccAgent.sidebar.projectAction.archivedAll'));
+ await act(async () => { await new Promise<void>((resolve) => setTimeout(resolve, 0)); });
+ expect(p.onArchiveAllDialogues).toHaveBeenCalledWith(p.dialogues);
+ expect(screen.queryByRole('alertdialog')).toBeNull();
+ expect(document.activeElement).toBe(header);
+ });
+
+ it('keeps focus in the confirmation opened by an archive action', async () => {
+ const p = props(false);
+ p.bots = [];
+ p.dialogues = [{ id: 'dialogue', title: 'Dialogue task', status: 'active', workspaceKind: 'dialogue' } as Session];
+ function SidebarWithConfirmation() {
+ const { confirm } = useConfirmDialog();
+ return <ProjectsSection {...p} onArchiveAllDialogues={() => {
+ void confirm({ title: 'Archive sessions', description: 'Archive this group?', cancelText: 'Keep sessions' });
+ }} />;
+ }
+ render(<ConfirmDialogProvider><SidebarWithConfirmation /></ConfirmDialogProvider>);
+ const header = screen.getByText('ccAgent.sidebar.dialogues').closest<HTMLElement>('[role="button"]')!;
+ header.focus();
+ fireEvent.keyDown(header, { key: 'ContextMenu' });
+ fireEvent.click(within(await screen.findByRole('menu')).getByText('ccAgent.sidebar.projectAction.archivedAll'));
+ await act(async () => { await new Promise<void>((resolve) => setTimeout(resolve, 0)); });
+ expect(document.activeElement).toBe(within(screen.getByRole('alertdialog')).getByRole('button', { name: 'Keep sessions' }));
+ });
+
+ it('preserves focus on an outside input when the menu is dismissed', async () => {
+ const p = props(false);
+ p.bots = [];
+ p.dialogues = [{ id: 'dialogue', title: 'Dialogue task', status: 'active', workspaceKind: 'dialogue' } as Session];
+ render(<><ProjectsSection {...p} /><input aria-label="Outside search" /></>);
+ const outside = screen.getByRole('textbox', { name: 'Outside search' });
+ const header = screen.getByText('ccAgent.sidebar.dialogues').closest<HTMLElement>('[role="button"]')!;
+ header.focus();
+ fireEvent.keyDown(header, { key: 'ContextMenu' });
+ await screen.findByRole('menu');
+ fireEvent.pointerDown(outside, { pointerType: 'mouse', button: 0 });
+ outside.focus();
+ await act(async () => { await new Promise<void>((resolve) => setTimeout(resolve, 0)); });
+ expect(screen.queryByRole('menu')).toBeNull();
+ expect(document.activeElement).toBe(outside);
+ });
+
// The dedicated menu must act on the full group, including folded rows, and
// never expose project actions or silently archive a local subset of a mixed group.
+ // #6641: pinned rows are absent from the visible list but remain searchable,
+ // participate in remote guards and stay within their owning device section.
it.each(['active', 'archived'] as const)('offers scoped search and bulk %s actions for local dialogues', async (status) => {
const p = props(false);
p.bots = [];
@@ -152,20 +209,54 @@ describe('Sidebar group context menus', () => {
id, title: id, status, workspaceKind: 'dialogue', pinnedAt: null,
createdAt: '2026-09-03', updatedAt: '2026-09-03',
} as Session));
+ const pinned = { ...p.dialogues[0], id: 'pinned', pinnedAt: '2026-10-21' };
+ const make: Session = { ...p.dialogues[0], id: 'make', source: 'cindy-make' };
+ p.dialogueActionSessions = [...p.dialogues, pinned, make];
render(<ProjectsSection {...p} />);
const header = screen.getByText('ccAgent.sidebar.dialogues').closest('[role="button"]')!;
expect(screen.queryByTestId('row-folded')).toBeNull();
+ expect(screen.queryByTestId('row-pinned')).toBeNull();
fireEvent.contextMenu(header);
let menu = await screen.findByRole('menu');
expect(within(menu).getAllByRole('menuitem')).toHaveLength(2);
fireEvent.click(within(menu).getByText('ccAgent.sidebar.dialogueAction.search'));
- expect(p.onSearchDialogues).toHaveBeenCalledWith(p.dialogues);
+ expect(p.onSearchDialogues).toHaveBeenCalledWith([...p.dialogues, pinned]);
fireEvent.contextMenu(header);
menu = await screen.findByRole('menu');
fireEvent.click(within(menu).getByText(status === 'archived'
? 'ccAgent.sidebar.dialogueAction.restoreAll'
: 'ccAgent.sidebar.projectAction.archivedAll'));
- expect(p.onArchiveAllDialogues).toHaveBeenCalledWith(p.dialogues);
+ expect(p.onArchiveAllDialogues).toHaveBeenCalledWith([...p.dialogues, pinned]);
+ });
+
+ it('disables bulk actions when the only remote member is pinned', async () => {
+ const p = props(false);
+ p.bots = [];
+ p.dialogues = [{ id: 'local', title: 'Local', status: 'active', workspaceKind: 'dialogue' } as Session];
+ const remotePinned = { ...p.dialogues[0], id: 'pinned-remote', pinnedAt: '2026-10-21', deviceLinkDeviceId: 'remote' };
+ p.dialogueActionSessions = [...p.dialogues, remotePinned];
+ render(<ProjectsSection {...p} />);
+ fireEvent.contextMenu(screen.getByText('ccAgent.sidebar.dialogues').closest('[role="button"]')!);
+ const menu = await screen.findByRole('menu');
+ const archive = within(menu).getByRole('menuitem', { name: /ccAgent.sidebar.projectAction.archivedAll/ });
+ expect(archive.getAttribute('aria-disabled')).toBe('true');
+ fireEvent.click(archive);
+ expect(p.onArchiveAllDialogues).not.toHaveBeenCalled();
+ fireEvent.click(within(menu).getByText('ccAgent.sidebar.dialogueAction.search'));
+ expect(p.onSearchDialogues).toHaveBeenCalledWith([...p.dialogues, remotePinned]);
+ });
+
+ it('keeps pinned members within their own device section for group actions', async () => {
+ const p = props(true);
+ p.bots = [];
+ p.dialogues = [{ id: 'local', title: 'Local', status: 'active', workspaceKind: 'dialogue' } as Session];
+ const localPinned = { ...p.dialogues[0], id: 'pinned-local', pinnedAt: '2026-10-21' };
+ const remotePinned = { ...localPinned, id: 'pinned-remote', deviceLinkDeviceId: 'remote' };
+ p.dialogueActionSessions = [...p.dialogues, localPinned, remotePinned];
+ render(<ProjectsSection {...p} />);
+ fireEvent.contextMenu(screen.getByText('ccAgent.sidebar.dialogues').closest('[role="button"]')!);
+ fireEvent.click(within(await screen.findByRole('menu')).getByText('ccAgent.sidebar.projectAction.archivedAll'));
+ expect(p.onArchiveAllDialogues).toHaveBeenCalledWith([...p.dialogues, localPinned]);
});
it.each([false, true])('disables bulk actions when a dialogue group contains remote tasks, mixed %s', async (mixed) => {
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 9f10a8b6ed..3d04c6e6fe 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -1915,6 +1915,14 @@ function ExpandedView({
if (filter.projectsAsSet === null) return sessions;
return filter.projectsAsSet.has(DIALOGUE_FILTER_KEY) ? sessions : [];
}, [groups.dialogues, vendorPredicate, filter.projectsAsSet]);
+ // Group actions include pinned members, while the rendered tree stays deduplicated.
+ const dialogueActionSessions = useMemo(
+ () =>
+ vendorPredicate
+ ? groupsWithPinnedProjects.dialogues.filter(vendorPredicate)
+ : groupsWithPinnedProjects.dialogues,
+ [groupsWithPinnedProjects.dialogues, vendorPredicate],
+ );
// 对话段排序状态提升到此处:DialogueSection(展开态)受控消费,rail 对话
// 面板按同一排序渲染——否则折叠后面板的前 N 条/折叠溢出与展开态刚排好的
@@ -3847,6 +3855,7 @@ function ExpandedView({
unclassified={visibleUnclassified}
projects={visibleProjectsWithVendor}
dialogues={visibleDialogues}
+ dialogueActionSessions={dialogueActionSessions}
bots={groups.bots}
onOpenBot={(botId) => navigate(`/bots/${botId}`)}
allKnownProjects={visibleProjectUniverse}
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 e209f18a68..c4787e0036 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
@@ -195,6 +195,8 @@ export interface ProjectsSectionProps {
* 与项目行按同一口径混排;「对话归为一组」开启时收进对话组行。
*/
dialogues: Session[];
+ /** Full dialogue membership, including pinned rows, for group menu actions. */
+ dialogueActionSessions?: readonly Session[];
/**
* 按伙伴分的组(与项目行并列混排)。
*
@@ -294,6 +296,7 @@ export function ProjectsSection({
unclassified,
projects,
dialogues,
+ dialogueActionSessions = dialogues,
bots = [],
onOpenBot,
allKnownProjects,
@@ -1059,6 +1062,14 @@ export function ProjectsSection({
targetDeviceOffline;
// The settings dialog creates on this computer; never expose it on a remote-only group.
const canCreateMake = entry.sessions.some((session) => !session.deviceLinkDeviceId);
+ const actionSessions = isMake
+ ? entry.sessions
+ : dialogueActionSessions.filter(
+ (session) =>
+ !isCindyMakeFamilySource(session.source) &&
+ (dialogueDeviceTarget === undefined ||
+ (session.deviceLinkDeviceId ?? null) === (dialogueDeviceTarget?.deviceId ?? null)),
+ );
return (
<SessionGroupNode
key={`${entry.kind}:${dialogueGroupKey}`}
@@ -1069,10 +1080,10 @@ export function ProjectsSection({
headerMenu={
isMake ? undefined : (
<DialogueGroupMenu
- sessions={entry.sessions}
+ sessions={actionSessions}
statusFilter={filter.status}
- onSearch={() => onSearchDialogues(entry.sessions)}
- onArchiveAll={() => onArchiveAllDialogues(entry.sessions)}
+ onSearch={() => onSearchDialogues(actionSessions)}
+ onArchiveAll={() => onArchiveAllDialogues(actionSessions)}
/>
)
}
@@ -1624,10 +1635,12 @@ export function SessionGroupNode({
onEscapeKeyDown={() => { restoreHeaderFocusOnClose.current = true; }}
onCloseAutoFocus={(event) => {
// The Radix trigger only anchors the right-click coordinates.
- // Escape returns to the visible header; menu actions keep their
- // search/dialog focus, and outside clicks keep the clicked target.
+ // Return to the header if an action only showed a toast. Preserve
+ // focus already claimed by search, a dialog or an outside target.
event.preventDefault();
- if (restoreHeaderFocusOnClose.current) headerRef.current?.focus();
+ if (restoreHeaderFocusOnClose.current || document.activeElement === document.body) {
+ headerRef.current?.focus();
+ }
restoreHeaderFocusOnClose.current = false;
}}
onContextMenu={(event) => { event.preventDefault(); event.stopPropagation(); }}
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 803f5bae16..45ca4cf4a7 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -12657,19 +12657,19 @@
"dialogueAction": {
"search": "Search This Chat Group",
"restoreAll": "Restore All",
- "remoteBulkUnavailable": "Bulk actions are not yet supported for groups containing remote tasks"
+ "remoteBulkUnavailable": "Bulk actions are not yet supported for groups containing remote sessions"
},
"dialogueArchiveAll": {
- "description": "Archive all {{count}} tasks in this chat group? Archived tasks will be removed from the list.",
- "descriptionWithSkip": "Archive {{count}} tasks in this chat group? {{skip}} tasks will be skipped. Archived tasks will be removed from the list.",
- "allPinnedOrRunning": "All tasks in this chat group are pinned or running. No tasks can be archived.",
- "allPinned": "All tasks in this chat group are pinned and will be kept.",
- "allRunning": "All tasks in this chat group are running. Stop them before archiving.",
- "empty": "No tasks in this chat group can be archived"
+ "description": "Archive all {{count}} sessions in this chat group? Archived sessions will be removed from the list.",
+ "descriptionWithSkip": "Archive {{count}} sessions in this chat group? {{skip}} will be skipped. Archived sessions will be removed from the list.",
+ "allPinnedOrRunning": "All sessions in this chat group are pinned or running. No sessions can be archived.",
+ "allPinned": "All sessions in this chat group are pinned and will be kept.",
+ "allRunning": "All sessions in this chat group are running. Stop them before archiving.",
+ "empty": "No sessions in this chat group can be archived"
},
"dialogueRestoreAll": {
- "description": "Restore {{count}} archived tasks in this chat group? They will move from Archived to Active.",
- "empty": "No archived tasks in this chat group can be restored"
+ "description": "Restore {{count}} archived sessions in this chat group? They will move from Archived to Active.",
+ "empty": "No archived sessions in this chat group can be restored"
},
"archiveAll": {
"title": "Archive all sessions",
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index 0b74a78de0..25a56288aa 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -80,11 +80,14 @@
推翻早前的 hover 自动展开);按钮配色与段头其余按钮同源,hover 只出 tooltip。
右键「对话」组头打开专属精简菜单,不冒泡触发全局显示设置:只提供「在对话中搜索」和
-「全部归档」,已归档视图将后者替换为「全部恢复」。范围为当前组的完整成员,不受组内
-折叠条数影响,不混入项目、伙伴或 Cindy Make 任务。归档跳过运行中和已置顶的任务,并
-显示数量与确认提示;含 device-link 远程任务的组(包括本机与远程混合组)暂时禁用批量
+「全部归档」,已归档视图将后者替换为「全部恢复」。范围为当前组的完整成员,含已置顶任务,
+不受组内折叠条数影响;按设备分组时只含所属设备,不混入项目、伙伴或 Cindy Make 任务。
+归档跳过运行中和已置顶的任务,并显示数量与确认提示;含 device-link 远程任务的组
+(包括本机与远程混合组)暂时禁用批量
归档/恢复并显示原因,搜索仍可用。复用菜单与批量生命周期;项目行、伙伴与 Cindy Make
-分组保留各自既有行为。
+分组保留各自既有行为。Esc 关闭菜单或操作仅显示提示时,焦点返回组头;搜索框、确认弹窗或
+外部点击目标已取得焦点时保留其焦点。实现见 `ProjectsSection.tsx`,回归见
+`botGroupLampRendering.test.tsx` 与 `sessionGroupArchive.test.tsx`。
菜单**不带自身标题行**(2026-08-12 用户裁决,节约高度;与远程机器菜单同规)——
触发按钮的 tooltip 已经说明这是什么。菜单高度按 Radix 给出的可用空间收口并允许