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): 存档确认等待期间保持任务行隐藏

Dash4cfd10a4fe55
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index fa6475a4af..5adec59383 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -871,16 +871,14 @@ interface ExpandedProps {
/** rail 未分类隐藏态的空列表(引用稳定,免得 lampScope 发布 effect 空转)。 */
const EMPTY_SESSION_LIST: Session[] = [];
-/** State for the delete/archive confirm dialog. */
+/** State for the controlled delete confirmation. Archive awaits confirmDialog. */
interface ConfirmState {
open: boolean;
sessionId: string;
- action: 'delete' | 'archive';
+ action: 'delete';
/** P1: 会话 worktree 有未提交更改 → 确认文案追加警告(打开前预检)。 */
dirtyWorktree: boolean;
- /** 归档会暂停的 active 自动化名称(仅 archive;为空则不提示)。 */
- scheduleNames?: readonly string[];
- /** Owned shared task to close before the confirmed archive/delete. */
+ /** Owned shared task to close before the confirmed delete. */
sharedTaskId?: string;
}
@@ -889,7 +887,6 @@ const CONFIRM_INITIAL: ConfirmState = {
sessionId: '',
action: 'delete',
dirtyWorktree: false,
- scheduleNames: undefined,
sharedTaskId: undefined,
};
@@ -953,7 +950,7 @@ function ExpandedView({
},
[t],
);
- // 批量菜单走全局确认弹窗,与单条操作的 inline ConfirmDialog 解耦。
+ // 归档和批量菜单共用可等待的确认弹窗;删除保留受控 ConfirmDialog。
const { confirm: confirmDialog } = useConfirmDialog();
const handleScheduleDeleted = useCallback(
async ({ disposition, affectedSessionIds }: DeletedScheduleGeneratedSessionResult) => {
@@ -3205,7 +3202,7 @@ function ExpandedView({
// (WorktreeManager.removeWorktreeForSession),renderer 这层负责的是「别拿
// 明显过期的结论免掉确认」。
//
- // 远程列表行已经乐观换桶;预检失败或需要确认时由执行层恢复,详情尚未跳离。
+ // 远程列表行已经乐观换桶;确认期间保持叠加层,取消或拦截才恢复。
const preflight = await resolveWorktreeRemovalPreflight(
sessionId,
session?.deviceLinkDeviceId,
@@ -3216,15 +3213,16 @@ function ExpandedView({
// (greptile review)。'unknown' 时不摆 dirty 警告文案 —— 那会谎称有改动,
// 走的是普通归档确认。
if (preflight !== 'clean' || scheduleNames.length > 0) {
- setConfirm({
- open: true,
- sessionId,
- action: 'archive',
- dirtyWorktree: preflight === 'dirty',
- scheduleNames,
- sharedTaskId,
+ const confirmed = await confirmDialog({
+ title: t('ccAgent.sidebar.confirmArchive.title'),
+ description: archiveConfirmDescription(t, {
+ dirtyWorktree: preflight === 'dirty',
+ scheduleNames,
+ }),
+ confirmText: t('ccAgent.sidebar.confirmArchive.confirm'),
+ cancelText: t('ccAgent.sidebar.confirmArchive.cancel'),
});
- return false;
+ if (!confirmed || !isCurrent()) return false;
}
// 重定向判定用 viewedSessionId:files 路由下归档「正在浏览的会话」也要
// 跳离失效的文件视图(codex review;正常路由下两者恒等)。经 ref 读:它随
@@ -3259,6 +3257,7 @@ function ExpandedView({
[
closeOwnedSharedTask,
archiveBlockedByRunning,
+ confirmDialog,
runSessionAction,
unarchiveSession,
t,
@@ -3273,18 +3272,14 @@ function ExpandedView({
setConfirm(CONFIRM_INITIAL);
return;
}
- if (action === 'archive' && archiveBlockedByRunning(sessionId, session?.deviceLinkDeviceId)) {
- setConfirm(CONFIRM_INITIAL);
- return;
- }
if (!(await closeOwnedSharedTask(sharedTaskId))) {
return;
}
// 重定向判定统一用 viewedSessionId(files 路由下 = 被浏览文件的会话,
- // 正常路由下与 activeSessionId 恒等):从面板删除/归档正在浏览的会话时
+ // 正常路由下与 activeSessionId 恒等):从面板删除正在浏览的会话时
// 也要跳离失效的 /cc-agent/files/:id(codex review)。
const deleteRedirectRoute =
- action === 'delete' && sessionId === viewedSessionId
+ sessionId === viewedSessionId
? await resolveSessionRemovalRedirect(new Set([sessionId]), sessionId)
: null;
await runSessionAction(sessionId, action, {
@@ -3292,7 +3287,7 @@ function ExpandedView({
deleteRedirectRoute,
});
setConfirm(CONFIRM_INITIAL);
- }, [closeOwnedSharedTask, archiveBlockedByRunning, viewedSessionId, confirm, resolveSessionRemovalRedirect, runSessionAction, sessionsById, t]);
+ }, [closeOwnedSharedTask, viewedSessionId, confirm, resolveSessionRemovalRedirect, runSessionAction, sessionsById, t]);
const handleCancelConfirm = useCallback(() => {
setConfirm(CONFIRM_INITIAL);
@@ -3940,38 +3935,21 @@ function ExpandedView({
}}
/>
- {/* Delete / Archive confirm dialog */}
+ {/* Delete confirm dialog */}
<ConfirmDialog
open={confirm.open}
onOpenChange={(open) => {
if (!open) handleCancelConfirm();
}}
- title={
- confirm.action === 'delete'
- ? t('ccAgent.sidebar.confirmDelete.title')
- : t('ccAgent.sidebar.confirmArchive.title')
- }
+ title={t('ccAgent.sidebar.confirmDelete.title')}
description={
- confirm.action === 'delete'
- ? t('ccAgent.sidebar.confirmDelete.description') +
- (confirm.dirtyWorktree
- ? ' ' + t('ccAgent.sidebar.confirmDelete.dirtyWorktreeWarning')
- : '')
- : archiveConfirmDescription(t, {
- dirtyWorktree: confirm.dirtyWorktree,
- scheduleNames: confirm.scheduleNames ?? [],
- })
- }
- confirmText={
- confirm.action === 'delete'
- ? t('ccAgent.sidebar.confirmDelete.confirm')
- : t('ccAgent.sidebar.confirmArchive.confirm')
- }
- cancelText={
- confirm.action === 'delete'
- ? t('ccAgent.sidebar.confirmDelete.cancel')
- : t('ccAgent.sidebar.confirmArchive.cancel')
+ t('ccAgent.sidebar.confirmDelete.description') +
+ (confirm.dirtyWorktree
+ ? ' ' + t('ccAgent.sidebar.confirmDelete.dirtyWorktreeWarning')
+ : '')
}
+ confirmText={t('ccAgent.sidebar.confirmDelete.confirm')}
+ cancelText={t('ccAgent.sidebar.confirmDelete.cancel')}
onConfirm={handleConfirm}
onCancel={handleCancelConfirm}
/>
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/sharedTaskArchiveGuard.test.ts b/apps/desktop/src/renderer/features/cc-agent/__tests__/sharedTaskArchiveGuard.test.ts
index 65a74b26b4..a87c303a8b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/sharedTaskArchiveGuard.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/sharedTaskArchiveGuard.test.ts
@@ -30,6 +30,7 @@ function harness(result: unknown, reject = false, sharedTaskId: string | undefin
const session = { id: 'task', deviceLinkDeviceId: 'device-1' };
const archiveBlockedByRunning = vi.fn(() => false);
const preflight = vi.fn(async () => 'clean');
+ const confirmDialog = vi.fn(async () => true);
const bindings = {
window: { electronAPI: { sharedTask: { account }, binding: { resolveSession: async () => ({ attached: false }) } } },
toast, t: (key: string) => key, sharedTaskErrorKey: () => 'sharedTask.retry',
@@ -37,7 +38,7 @@ function harness(result: unknown, reject = false, sharedTaskId: string | undefin
runningSessionIds: new Set(), attachedSessionIdsRef: { current: new Set() },
loadActiveBoundScheduleNames: async () => new Map(),
isRemoteSessionWriteBlocked: () => false, resolveWorktreeRemovalPreflight: preflight,
- archiveBlockedByRunning,
+ archiveBlockedByRunning, confirmDialog, archiveConfirmDescription: () => 'description',
viewedSessionIdRef: { current: 'other' }, viewedSessionId: 'other',
resolveSessionRemovalRedirect: vi.fn(), unarchiveSession: vi.fn(),
runSessionAction: async (id: string, action: string, options: { prepareArchive?: (isCurrent: () => boolean) => Promise<boolean> }) => {
@@ -48,7 +49,7 @@ function harness(result: unknown, reject = false, sharedTaskId: string | undefin
};
const closeOwnedSharedTask = callback('closeOwnedSharedTask', bindings);
return {
- account, runSessionAction, toast, setConfirm, archiveBlockedByRunning, preflight,
+ account, runSessionAction, toast, setConfirm, archiveBlockedByRunning, preflight, confirmDialog,
archive: () => callback('handleActionClick', { ...bindings, closeOwnedSharedTask })('task', 'archive', sharedTaskId),
confirm: (action: string) => callback('handleConfirm', { ...bindings, closeOwnedSharedTask,
confirm: { sessionId: 'task', action, sharedTaskId },
@@ -64,12 +65,14 @@ describe('sidebar shared-task archive/delete guard', () => {
const archive = h.archive();
await vi.waitFor(() => expect(h.preflight).toHaveBeenCalled());
if (preflight === 'clean') h.archiveBlockedByRunning.mockReturnValue(true);
+ else h.confirmDialog.mockImplementationOnce(async () => {
+ h.archiveBlockedByRunning.mockReturnValue(true);
+ return true;
+ });
pending.resolve(preflight);
await archive;
if (preflight !== 'clean') {
- expect(h.setConfirm).toHaveBeenCalledWith(expect.objectContaining({ open: true, sharedTaskId: 'share' }));
- h.archiveBlockedByRunning.mockReturnValue(true);
- await h.confirm('archive');
+ expect(h.confirmDialog).toHaveBeenCalledOnce();
}
expect(h.archiveBlockedByRunning).toHaveBeenLastCalledWith('task', 'device-1');
expect(h.account).not.toHaveBeenCalled();
@@ -85,8 +88,11 @@ describe('sidebar shared-task archive/delete guard', () => {
});
it.each(['archive', 'confirmed-archive', 'delete'])('blocks %s on a resolved close failure', async (action) => {
const h = harness({ closed: [], failed: [{ sharedTaskId: 'share' }] });
- if (action === 'archive') await h.archive();
- else await h.confirm(action === 'delete' ? 'delete' : 'archive');
+ if (action === 'delete') await h.confirm('delete');
+ else {
+ if (action === 'confirmed-archive') h.preflight.mockResolvedValueOnce('dirty');
+ await h.archive();
+ }
expect(h.runSessionAction).not.toHaveBeenCalled();
expect(h.setConfirm).not.toHaveBeenCalled();
expect(h.toast.error).toHaveBeenCalledWith('sharedTask.closeFailedToast');
@@ -124,6 +130,10 @@ function deferred<T>() {
}
describe('archive preserves the current task until preflight and confirmation finish', () => {
+ // Unit regression, PR #6863 r4353787032: existing cases checked selection
+ // and final state but missed the visible row while confirmation was pending.
+ // Execute each production handler with a held decision; dirty/unknown and
+ // schedule-bound inputs must stay hidden until cancel or a confirmed write.
const entrypoints = [
{ name: 'sidebar', file: 'CCAgentSidebarUpper.tsx', handler: 'handleActionClick' },
{ name: 'header', file: 'SessionContentHeader.tsx', handler: 'handleArchive' },
@@ -144,6 +154,7 @@ describe('archive preserves the current task until preflight and confirmation fi
const runSessionAction = vi.fn((..._args: unknown[]) => leaveTask());
const setConfirm = vi.fn();
const confirmDialog = vi.fn(() => decision.promise);
+ const archiveConfirmDescription = vi.fn(() => 'description');
const resolvePreflight = vi.fn(() => preflight.promise);
const bindings = {
window: { electronAPI: { binding: { resolveSession: async () => ({ attached: false }) } } },
@@ -154,7 +165,7 @@ describe('archive preserves the current task until preflight and confirmation fi
resolveWorktreeRemovalPreflight: resolvePreflight,
loadActiveBoundScheduleNames: async () =>
new Map(scheduleNames.length > 0 ? [['task', scheduleNames]] : []),
- archiveConfirmDescription: () => 'description',
+ archiveConfirmDescription,
viewedSessionIdRef: { current: 'task' }, viewedSessionId: 'task',
resolveSessionRemovalRedirect: vi.fn(), unarchiveSession: vi.fn(),
runSessionAction: async (id: string, action: string, options: { prepareArchive?: (isCurrent: () => boolean) => Promise<boolean> }) => {
@@ -174,19 +185,10 @@ describe('archive preserves the current task until preflight and confirmation fi
confirmDialog,
};
return {
- preflight, resolvePreflight, decision, runSessionAction, beginRemoteArchive, setConfirm, confirmDialog,
+ preflight, resolvePreflight, decision, runSessionAction, beginRemoteArchive, confirmDialog, archiveConfirmDescription,
selected: () => selectedTask, visible: () => rowVisible,
archive: () => callback(entry.handler, bindings, entrySource)('task', 'archive'),
- finish: async (confirmed: boolean) => {
- if (entry.name === 'sidebar') {
- if (confirmed) {
- const saving = callback('handleConfirm', bindings)();
- // Radix closes the dialog immediately after the confirm click.
- callback('handleCancelConfirm', bindings)();
- await saving;
- } else callback('handleCancelConfirm', bindings)();
- } else decision.resolve(confirmed);
- },
+ finish: async (confirmed: boolean) => { decision.resolve(confirmed); },
};
}
@@ -205,9 +207,10 @@ describe('archive preserves the current task until preflight and confirmation fi
h.preflight.resolve(preflight);
if (preflight !== 'clean') {
await vi.waitFor(() => {
- expect(entry.name === 'sidebar' ? h.setConfirm : h.confirmDialog).toHaveBeenCalled();
+ expect(h.confirmDialog).toHaveBeenCalled();
});
expect(h.selected()).toBe('task');
+ expect(h.visible()).toBe(false);
expect(h.runSessionAction).not.toHaveBeenCalled();
await h.finish(false);
}
@@ -228,9 +231,10 @@ describe('archive preserves the current task until preflight and confirmation fi
const pending = h.archive();
h.preflight.resolve(preflight);
await vi.waitFor(() => {
- expect(entry.name === 'sidebar' ? h.setConfirm : h.confirmDialog).toHaveBeenCalled();
+ expect(h.confirmDialog).toHaveBeenCalled();
});
expect(h.selected()).toBe('task');
+ expect(h.visible()).toBe(false);
expect(h.runSessionAction).not.toHaveBeenCalled();
await h.finish(true);
await pending;
@@ -245,11 +249,11 @@ describe('archive preserves the current task until preflight and confirmation fi
const pending = h.archive();
h.preflight.resolve('clean');
await vi.waitFor(() => {
- expect(entry.name === 'sidebar' ? h.setConfirm : h.confirmDialog).toHaveBeenCalled();
+ expect(h.confirmDialog).toHaveBeenCalled();
});
- if (entry.name === 'sidebar') {
- expect(h.setConfirm).toHaveBeenCalledWith(expect.objectContaining({ scheduleNames: ['Daily report'] }));
- }
+ expect(h.archiveConfirmDescription).toHaveBeenCalledWith(expect.anything(),
+ expect.objectContaining({ scheduleNames: ['Daily report'] }));
+ expect(h.visible()).toBe(false);
expect(h.runSessionAction).not.toHaveBeenCalled();
await h.finish(false);
await pending;
diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/useSessionLifecycleActions.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/useSessionLifecycleActions.ts
index ab5aa3f8d0..61ebb9b384 100644
--- a/apps/desktop/src/renderer/features/cc-agent/hooks/useSessionLifecycleActions.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/useSessionLifecycleActions.ts
@@ -7,9 +7,8 @@
*
* 本 hook 封装乐观补丁、预检、写库与收尾。前置检查(IM 接管拦截)和确认弹窗
* 由调用方通过 prepareArchive 提供;运行态判据由本 hook 统一提供,
- * 调用方在关闭共享前复用,执行层在异步等待后复核。两处的确认交互形态不同
- * (sidebar 是受控 ConfirmDialog + 行内两步确认,header 是 imperative
- * confirmDialog),强行收进来反而耦合。
+ * 调用方在关闭共享前复用,执行层在异步等待后复核。归档入口共用可等待的
+ * confirmDialog,确认文案与是否需要确认仍由各入口按预检结果决定。
*
* activeSessionId 表示调用方原先浏览的会话;归档跳转前还会读取实时路由,
* 防止预检或确认期间切换任务后,旧操作把新页面带走。
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index 8a8b62e482..edfef5ee81 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -44,7 +44,9 @@ Cindy 的产品形态不止本地桌面单机。同一个功能可能运行在
桌面与手机的远程任务列表在点击存档后立即乐观移走任务行,不能等待远程预检或写入
返回才更新。既有的运行态、接管、worktree 与自动化确认仍在真正写入前执行;取消、
-拦截或失败恢复列表,迟到的预检不能覆盖用户后续的恢复操作。预检期间保留任务内容,
+拦截或失败恢复列表,迟到的预检不能覆盖用户后续的恢复操作。展示必要确认框时仍保持
+任务行隐藏,不能把“已经打开确认框”当成取消;桌面归档入口等待同一个异步确认结果。
+预检期间保留任务内容,
不提前清理消息或草稿;手机只从列表投影隐藏行,保留详情元数据和此前重命名、置顶的
在途写入,确认后才取代这些写入并真正移除行。取消时解除隐藏,不拿旧快照覆盖期间
已经保存的元数据。详情页在确认通过后再退出。手机详情菜单先收起,关闭动画结束后