Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 修复计划胶囊交互与完成态残留 (#1392)
DavidShenXD45fc5a0552a9
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.tsindex d390d45bf0..b4ae2f3bac 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts@@ -464,6 +464,48 @@ describe('makerChatStore text delta batching', () => {});});+ it('refreshes the plan update timestamp when update_plan completes in place', () => {+ const startedAt = 1_700_000_000_000;+ vi.setSystemTime(startedAt);+ onEvent?.({+ sessionId: SESSION_ID,+ event: {+ type: 'tool_use',+ source: 'codex',+ data: {+ toolUseId: 'plan-1',+ toolName: 'update_plan',+ input: { plan: [{ step: 'Finish work', status: 'in_progress' }] },+ },+ },+ persistId: 'plan-message-1',+ });++ vi.setSystemTime(startedAt + 5_000);+ onEvent?.({+ sessionId: SESSION_ID,+ event: {+ type: 'tool_use',+ source: 'codex',+ data: {+ toolUseId: 'plan-1',+ toolName: 'update_plan',+ input: { plan: [{ step: 'Finish work', status: 'completed' }] },+ },+ },+ persistId: 'plan-message-1',+ });++ const messages = makerChatStore.getSnapshot(SESSION_ID).messages;+ expect(messages).toHaveLength(1);+ expect(messages[0]).toMatchObject({+ clientId: 'plan-message-1',+ createdAt: new Date(startedAt).toISOString(),+ planUpdatedAtMs: startedAt + 5_000,+ toolInput: { plan: [{ step: 'Finish work', status: 'completed' }] },+ });+ });+it('flushes pending text before a permission interaction request on the separate IPC channel', () => {const snapshots: Array<{ roles: string[]; pendingPermission: string | null }> = [];const unsubscribe = makerChatStore.subscribe(SESSION_ID, () => {diff --git a/apps/desktop/src/renderer/__tests__/planReviewDoneRace.test.ts b/apps/desktop/src/renderer/__tests__/planReviewDoneRace.test.tsindex b0c52818c6..d8a5797de9 100644--- a/apps/desktop/src/renderer/__tests__/planReviewDoneRace.test.ts+++ b/apps/desktop/src/renderer/__tests__/planReviewDoneRace.test.ts@@ -234,6 +234,7 @@ describe('plan_review 与 done 的时序', () => {afterEach(() => {makerChatStore.__teardownGlobalListeners();makerChatStore.purgeSession(SESSION_ID);+ vi.restoreAllMocks();});it('codex:done 使用携带的权威快照收口最新结构化计划', () => {@@ -269,12 +270,22 @@ describe('plan_review 与 done 的时序', () => {});it('codex:成功完成但缺少最终 plan 快照时收口计划卡片', () => {+ const startedAtMs = 1_700_000_000_000;+ const completedAtMs = startedAtMs + 5_000;+ const now = vi.spyOn(Date, 'now').mockReturnValue(startedAtMs);makerChatStore.setSessionRuntime(SESSION_ID, { agentKind: 'codex' });emitPlanUpdate('codex', ['in_progress', 'pending']);+ now.mockReturnValue(completedAtMs);emitDone('codex', undefined, 'turn-1', 'completed');expect(latestPlanStatuses()).toEqual(['completed', 'completed']);+ const completedPlan = makerChatStore+ .getSnapshot(SESSION_ID)+ .messages.findLast(+ (message) => message.role === 'tool_use' && message.toolName === 'update_plan',+ );+ expect(completedPlan).toMatchObject({ planUpdatedAtMs: completedAtMs });});it('claude:done 不改 Codex update_plan 展示状态', () => {diff --git a/apps/desktop/src/renderer/components/chat/TodoListCard.tsx b/apps/desktop/src/renderer/components/chat/TodoListCard.tsxindex 90810cc57f..678b335d14 100644--- a/apps/desktop/src/renderer/components/chat/TodoListCard.tsx+++ b/apps/desktop/src/renderer/components/chat/TodoListCard.tsx@@ -5,7 +5,7 @@** 交互与形态 1:1 对齐 Codex IDE 扩展:* - 收起态:居中小胶囊 `[进度 icon] Step N / M`,不占整行宽度;- * - 鼠标悬停(或点击/Enter)时,完整清单以浮层形式向上展开;移开即收起。+ * - 鼠标悬停时临时展开,移开即收起;点击/Enter 后固定展开,再次触发立即收起。* 浮层绝对定位(bottom-full),不改变 composer overlay 的实测高度,* 消息流不会因 hover 抖动。* - 浮层行:completed 灰(check 圆圈),in_progress 高亮(虚线圆圈 + 旋转),@@ -30,6 +30,8 @@ import { Spinner } from '@/components/ui/spinner';export type TodoItem = MessageRenderTodoItem;+type FlyoutOpenMode = 'closed' | 'hover' | 'pinned';+// ---------------------------------------------------------------------------// Component// ---------------------------------------------------------------------------@@ -48,10 +50,9 @@ export function TodoListCard({}) {const { t } = useTranslation();const flyoutId = useId();- const [hovered, setHovered] = useState(false);- const [pinnedOpen, setPinnedOpen] = useState(false);+ const [openMode, setOpenMode] = useState<FlyoutOpenMode>('closed');const [renderFlyout, setRenderFlyout] = useState(false);- const revealed = hovered || pinnedOpen;+ const revealed = openMode !== 'closed';useEffect(() => {if (revealed) setRenderFlyout(true);@@ -65,7 +66,11 @@ export function TodoListCard({const activeIndex = todos.findIndex((todo) => todo.status === 'in_progress');const pendingIndex = todos.findIndex((todo) => todo.status === 'pending');const currentIndex =- activeIndex >= 0 ? activeIndex : pendingIndex >= 0 ? pendingIndex : Math.min(completed, total - 1);+ activeIndex >= 0+ ? activeIndex+ : pendingIndex >= 0+ ? pendingIndex+ : Math.min(completed, total - 1);const currentStep = allDone ? total : currentIndex + 1;const hasActive = todos.some((todo) => todo.status === 'in_progress');const flyoutMaxWidth =@@ -77,18 +82,18 @@ export function TodoListCard({<div className="flex w-full justify-center"><divclassName="relative inline-flex items-center justify-center"- onMouseEnter={() => setHovered(true)}- onMouseLeave={() => setHovered(false)}+ onMouseEnter={() => {+ setOpenMode((current) => (current === 'closed' ? 'hover' : current));+ }}+ onMouseLeave={() => {+ setOpenMode((current) => (current === 'hover' ? 'closed' : current));+ }}>{/* Collapsed pill — `[icon] Step N / M`,点击/Enter 也可切换浮层(键盘可达)。 */}<buttontype="button"- onClick={(event) => {- if (event.detail === 0) {- setPinnedOpen((prev) => !prev);- return;- }- setPinnedOpen((prev) => !prev);+ onClick={() => {+ setOpenMode((current) => (current === 'pinned' ? 'closed' : 'pinned'));}}aria-controls={flyoutId}aria-expanded={revealed}@@ -102,7 +107,11 @@ export function TodoListCard({)}>{allDone ? (- <CircleCheck size={14} strokeWidth={2} className="shrink-0 text-[var(--msg-tool-card-text)]" />+ <CircleCheck+ size={14}+ strokeWidth={2}+ className="shrink-0 text-[var(--msg-tool-card-text)]"+ />) : (<Spinnericon={CircleDashed}@@ -120,17 +129,16 @@ export function TodoListCard({{/* Hover flyout — 完整清单向上浮出;绝对定位不占布局高度,消息流不抖动。 */}{renderFlyout && (<>- <div className="absolute bottom-full left-1/2 h-2 min-w-full -translate-x-1/2" aria-hidden="true" />+ <div+ className="absolute bottom-full left-1/2 h-2 min-w-full -translate-x-1/2"+ aria-hidden="true"+ /><divid={flyoutId}className={cn('absolute bottom-full left-1/2 z-10 mb-2 -translate-x-1/2','w-max',flyoutMaxWidth === null && 'min-w-[220px] max-w-[min(420px,calc(100vw-32px))]',- 'origin-bottom overflow-hidden rounded-[12px]',- 'border border-[var(--msg-tool-card-border)]',- 'bg-[var(--msg-tool-card-bg)]',- revealed ? 'animate-float-in' : 'animate-float-out',)}style={flyoutMaxWidth === null@@ -140,49 +148,70 @@ export function TodoListCard({maxWidth: `min(420px, ${flyoutMaxWidth}, calc(100vw - 32px))`,}}- onAnimationEnd={() => {- if (!revealed) setRenderFlyout(false);- }}>- <div className="flex max-h-[280px] flex-col gap-[2px] overflow-y-auto px-[14px] py-[10px]">- {todos.map((todo, i) => (- <div- key={i}- className={cn(- 'flex h-[30px] items-center gap-[10px]',- todo.status === 'in_progress' && animated && 'animate-pulse',- )}- >- {/* Icon */}- {todo.status === 'completed' && (- <CircleCheck size={18} strokeWidth={1.5} className="shrink-0 text-[var(--msg-tool-card-chevron)]" />- )}- {todo.status === 'in_progress' && (- <Spinner- icon={CircleDashed}- size={18}- strokeWidth={1.5}- spinning={animated}- className="text-[var(--msg-tool-card-text)]"- />- )}- {todo.status === 'pending' && (- <Circle size={18} strokeWidth={1.5} className="shrink-0 text-[var(--msg-tool-card-text)]" />- )}-- {/* Text — 对齐 Codex:completed 置灰,in_progress 高亮,pending 正常。 */}- <span+ <div+ aria-hidden={!revealed}+ className={cn(+ 'w-full origin-bottom overflow-hidden rounded-[12px]',+ 'border border-[var(--msg-tool-card-border)]',+ 'bg-[var(--msg-tool-card-bg)]',+ revealed ? 'animate-float-in' : 'animate-float-out',+ )}+ onAnimationEnd={() => {+ if (!revealed) setRenderFlyout(false);+ }}+ >+ <div className="flex max-h-[280px] flex-col gap-[2px] overflow-y-auto px-[14px] py-[10px]">+ {todos.map((todo, i) => (+ <div+ key={i}className={cn(- 'mt-px truncate text-13',- todo.status === 'completed' && 'font-normal text-[var(--msg-tool-card-chevron)]',- todo.status === 'in_progress' && 'font-semibold text-[var(--msg-tool-card-text)]',- todo.status === 'pending' && 'font-normal text-[var(--msg-tool-card-text)]',+ 'flex h-[30px] items-center gap-[10px]',+ todo.status === 'in_progress' && animated && 'animate-pulse',)}>- {todo.content}- </span>- </div>- ))}+ {/* Icon */}+ {todo.status === 'completed' && (+ <CircleCheck+ size={18}+ strokeWidth={1.5}+ className="shrink-0 text-[var(--msg-tool-card-chevron)]"+ />+ )}+ {todo.status === 'in_progress' && (+ <Spinner+ icon={CircleDashed}+ size={18}+ strokeWidth={1.5}+ spinning={animated}+ className="text-[var(--msg-tool-card-text)]"+ />+ )}+ {todo.status === 'pending' && (+ <Circle+ size={18}+ strokeWidth={1.5}+ className="shrink-0 text-[var(--msg-tool-card-text)]"+ />+ )}++ {/* Text — 对齐 Codex:completed 置灰,in_progress 高亮,pending 正常。 */}+ <span+ className={cn(+ 'mt-px truncate text-13',+ todo.status === 'completed' &&+ 'font-normal text-[var(--msg-tool-card-chevron)]',+ todo.status === 'in_progress' &&+ 'font-semibold text-[var(--msg-tool-card-text)]',+ todo.status === 'pending' &&+ 'font-normal text-[var(--msg-tool-card-text)]',+ )}+ >+ {todo.content}+ </span>+ </div>+ ))}+ </div></div></div></>diff --git a/apps/desktop/src/renderer/components/chat/__tests__/TodoListCard.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/TodoListCard.test.tsxnew file mode 100644index 0000000000..bc91a04733--- /dev/null+++ b/apps/desktop/src/renderer/components/chat/__tests__/TodoListCard.test.tsx@@ -0,0 +1,107 @@+// @vitest-environment jsdom++import { cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, describe, expect, it, vi } from 'vitest';++import { TodoListCard } from '../TodoListCard';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (_key: string, values: { current: number; total: number }) =>+ `Step ${values.current} / ${values.total}`,+ }),+}));++const TODOS = [+ { content: 'Inspect interaction state', status: 'in_progress' as const },+ { content: 'Verify toggle behavior', status: 'pending' as const },+];++afterEach(cleanup);++describe('TodoListCard flyout interaction', () => {+ it('opens transiently on hover and closes when the pointer leaves', () => {+ render(<TodoListCard todos={TODOS} animated={false} />);++ const trigger = screen.getByRole('button', { name: 'Step 1 / 2' });+ const hoverRegion = trigger.parentElement as HTMLElement;++ expect(trigger.getAttribute('aria-expanded')).toBe('false');++ fireEvent.mouseEnter(hoverRegion);+ expect(trigger.getAttribute('aria-expanded')).toBe('true');++ fireEvent.mouseLeave(hoverRegion);+ expect(trigger.getAttribute('aria-expanded')).toBe('false');+ });++ it('pins the hover flyout on click and closes it immediately on the second click', () => {+ render(<TodoListCard todos={TODOS} animated={false} />);++ const trigger = screen.getByRole('button', { name: 'Step 1 / 2' });+ const hoverRegion = trigger.parentElement as HTMLElement;++ fireEvent.mouseEnter(hoverRegion);+ fireEvent.click(trigger);+ fireEvent.mouseLeave(hoverRegion);+ expect(trigger.getAttribute('aria-expanded')).toBe('true');++ fireEvent.mouseEnter(hoverRegion);+ fireEvent.click(trigger);+ expect(trigger.getAttribute('aria-expanded')).toBe('false');++ fireEvent.mouseLeave(hoverRegion);+ fireEvent.mouseEnter(hoverRegion);+ expect(trigger.getAttribute('aria-expanded')).toBe('true');+ });++ it('toggles the pinned flyout for keyboard-generated clicks', () => {+ render(<TodoListCard todos={TODOS} animated={false} />);++ const trigger = screen.getByRole('button', { name: 'Step 1 / 2' });++ fireEvent.click(trigger, { detail: 0 });+ expect(trigger.getAttribute('aria-expanded')).toBe('true');++ fireEvent.click(trigger, { detail: 0 });+ expect(trigger.getAttribute('aria-expanded')).toBe('false');+ });++ it('keeps centering and entrance animation transforms on separate elements', () => {+ render(<TodoListCard todos={TODOS} animated={false} />);++ const trigger = screen.getByRole('button', { name: 'Step 1 / 2' });+ const hoverRegion = trigger.parentElement as HTMLElement;++ fireEvent.mouseEnter(hoverRegion);++ const flyoutId = trigger.getAttribute('aria-controls') as string;+ const positioner = document.getElementById(flyoutId) as HTMLElement;+ const animatedContent = positioner.firstElementChild as HTMLElement;++ expect(positioner.classList.contains('-translate-x-1/2')).toBe(true);+ expect(positioner.className).not.toContain('animate-float-');+ expect(animatedContent.classList.contains('animate-float-in')).toBe(true);+ expect(animatedContent.classList.contains('-translate-x-1/2')).toBe(false);+ });++ it('hides the flyout from assistive technology while its exit animation remains mounted', () => {+ render(<TodoListCard todos={TODOS} animated={false} />);++ const trigger = screen.getByRole('button', { name: 'Step 1 / 2' });+ const hoverRegion = trigger.parentElement as HTMLElement;++ fireEvent.mouseEnter(hoverRegion);++ const flyoutId = trigger.getAttribute('aria-controls') as string;+ const positioner = document.getElementById(flyoutId) as HTMLElement;+ const animatedContent = positioner.firstElementChild as HTMLElement;++ expect(animatedContent.getAttribute('aria-hidden')).toBe('false');++ fireEvent.mouseLeave(hoverRegion);++ expect(document.getElementById(flyoutId)).toBe(positioner);+ expect(animatedContent.getAttribute('aria-hidden')).toBe('true');+ });+});diff --git a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsxindex cb430c3151..0c42977356 100644--- a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx+++ b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx@@ -18,11 +18,13 @@ import type { ChatMessage } from '@/lib/makerChatStore';const COMPLETED_PLAN_VISIBLE_MS = 2_000;export function PinnedPlanPanel({+ sessionId,messages,animated,width,visible = true,}: {+ sessionId: string | null;messages: readonly ChatMessage[];/** 会话仍在流式时进行中项呼吸/旋转;停止后冻结。 */animated: boolean;@@ -33,30 +35,77 @@ export function PinnedPlanPanel({}): React.ReactElement | null {const insertion = useMemo(() => findLatestMessageTodoInsertion(messages), [messages]);const allDone = Boolean(- insertion- && insertion.todos.length > 0- && insertion.todos.every((todo) => todo.status === 'completed'),+ insertion &&+ insertion.todos.length > 0 &&+ insertion.todos.every((todo) => todo.status === 'completed'),+ );+ const completedAtMs = insertion?.updatedAtMs ?? Date.parse(insertion?.createdAt ?? '');+ const persistedCompletionDeadlineMs =+ allDone && Number.isFinite(completedAtMs)+ ? completedAtMs + COMPLETED_PLAN_VISIBLE_MS+ : null;+ const [fallbackCompletionVisibility, setFallbackCompletionVisibility] = useState<{+ identity: string;+ deadlineMs: number;+ } | null>(null);+ const completionIdentity = insertion ? `${sessionId ?? 'unknown'}:${insertion.key}` : null;+ const completionDeadlineMs =+ persistedCompletionDeadlineMs ??+ (allDone && fallbackCompletionVisibility?.identity === completionIdentity+ ? fallbackCompletionVisibility.deadlineMs+ : null);+ const completedPlanExpired = Boolean(+ completionDeadlineMs !== null && completionDeadlineMs <= Date.now(),);const [hiddenInsertionKey, setHiddenInsertionKey] = useState<string | null>(null);useEffect(() => {if (!insertion || !allDone) {setHiddenInsertionKey(null);+ setFallbackCompletionVisibility(null);+ return;+ }++ if (completionDeadlineMs === null) {+ setHiddenInsertionKey(null);+ setFallbackCompletionVisibility({+ identity: completionIdentity ?? insertion.key,+ deadlineMs: Date.now() + COMPLETED_PLAN_VISIBLE_MS,+ });+ return;+ }++ const remainingMs = Math.max(0, completionDeadlineMs - Date.now());+ if (remainingMs === 0) {+ setHiddenInsertionKey(insertion.key);return;}+ setHiddenInsertionKey(null);const timer = window.setTimeout(() => {setHiddenInsertionKey(insertion.key);- }, COMPLETED_PLAN_VISIBLE_MS);+ }, remainingMs);return () => window.clearTimeout(timer);- }, [allDone, insertion?.key]);+ }, [allDone, completionDeadlineMs, completionIdentity, insertion?.key]);- if (!visible || !insertion || insertion.todos.length === 0 || hiddenInsertionKey === insertion.key) return null;+ if (+ !visible ||+ !insertion ||+ insertion.todos.length === 0 ||+ completedPlanExpired ||+ hiddenInsertionKey === insertion.key+ )+ return null;return (<div className="mb-1.5 max-w-full" style={{ width }}>{/* key 按 plan session 锚定:新计划重挂载,浮层/进度从头开始。 */}- <TodoListCard key={insertion.key} todos={insertion.todos} animated={animated} maxWidth={width} />+ <TodoListCard+ key={insertion.key}+ todos={insertion.todos}+ animated={animated}+ maxWidth={width}+ /></div>);}diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsxindex 01fb5191e5..d1d347908b 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx@@ -14,7 +14,11 @@ vi.mock('@/components/chat/TodoListCard', () => ({const T0 = 1_700_000_000_000;-function planMessage(status: 'pending' | 'in_progress' | 'completed'): ChatMessage {+function planMessage(+ status: 'pending' | 'in_progress' | 'completed',+ createdAtMs: number | null = T0,+ planUpdatedAtMs?: number,+): ChatMessage {return {clientId: 'plan-1',role: 'tool_use',@@ -22,7 +26,8 @@ function planMessage(status: 'pending' | 'in_progress' | 'completed'): ChatMessatoolName: 'update_plan',toolUseId: 'plan:turn-1',toolInput: { plan: [{ step: 'Finish work', status }] },- createdAt: new Date(T0).toISOString(),+ ...(createdAtMs === null ? {} : { createdAt: new Date(createdAtMs).toISOString() }),+ ...(planUpdatedAtMs === undefined ? {} : { planUpdatedAtMs }),};}@@ -38,7 +43,14 @@ afterEach(() => {describe('PinnedPlanPanel completed plan lifetime', () => {it('keeps a completed plan visible for 2 seconds, then hides it', () => {- render(<PinnedPlanPanel messages={[planMessage('completed')]} animated={false} width={400} />);+ render(+ <PinnedPlanPanel+ sessionId="completed-lifetime"+ messages={[planMessage('completed')]}+ animated={false}+ width={400}+ />,+ );expect(screen.queryByTestId('plan-pill')).not.toBeNull();act(() => vi.advanceTimersByTime(1_999));@@ -48,7 +60,14 @@ describe('PinnedPlanPanel completed plan lifetime', () => {});it('does not hide a plan that is still running', () => {- render(<PinnedPlanPanel messages={[planMessage('in_progress')]} animated width={400} />);+ render(+ <PinnedPlanPanel+ sessionId="running-plan"+ messages={[planMessage('in_progress')]}+ animated+ width={400}+ />,+ );act(() => vi.advanceTimersByTime(10_000));expect(screen.queryByTestId('plan-pill')).not.toBeNull();@@ -57,30 +76,127 @@ describe('PinnedPlanPanel completed plan lifetime', () => {it('stays hidden after an interaction card temporarily hides the panel', () => {const completed = planMessage('completed');const view = render(- <PinnedPlanPanel messages={[completed]} animated={false} width={400} visible />,+ <PinnedPlanPanel+ sessionId="interaction-hidden"+ messages={[completed]}+ animated={false}+ width={400}+ visible+ />,);act(() => vi.advanceTimersByTime(2_000));expect(screen.queryByTestId('plan-pill')).toBeNull();view.rerender(- <PinnedPlanPanel messages={[completed]} animated={false} width={400} visible={false} />,+ <PinnedPlanPanel+ sessionId="interaction-hidden"+ messages={[completed]}+ animated={false}+ width={400}+ visible={false}+ />,);view.rerender(- <PinnedPlanPanel messages={[completed]} animated={false} width={400} visible />,+ <PinnedPlanPanel+ sessionId="interaction-hidden"+ messages={[completed]}+ animated={false}+ width={400}+ visible+ />,);expect(screen.queryByTestId('plan-pill')).toBeNull();});it('starts a fresh 2-second wait when a running plan completes', () => {const running = planMessage('in_progress');- const view = render(<PinnedPlanPanel messages={[running]} animated width={400} />);+ const view = render(+ <PinnedPlanPanel sessionId="running-completes" messages={[running]} animated width={400} />,+ );act(() => vi.advanceTimersByTime(5_000));- view.rerender(<PinnedPlanPanel messages={[planMessage('completed')]} animated={false} width={400} />);+ view.rerender(+ <PinnedPlanPanel+ sessionId="running-completes"+ messages={[planMessage('completed', T0, T0 + 5_000)]}+ animated={false}+ width={400}+ />,+ );act(() => vi.advanceTimersByTime(1_999));expect(screen.queryByTestId('plan-pill')).not.toBeNull();act(() => vi.advanceTimersByTime(1));expect(screen.queryByTestId('plan-pill')).toBeNull();});++ it('does not restart the completion lifetime after the session view remounts', () => {+ const completed = planMessage('completed');+ const view = render(+ <PinnedPlanPanel+ sessionId="session-remount"+ messages={[completed]}+ animated={false}+ width={400}+ />,+ );++ act(() => vi.advanceTimersByTime(1_000));+ view.unmount();++ render(+ <PinnedPlanPanel+ sessionId="session-remount"+ messages={[completed]}+ animated={false}+ width={400}+ />,+ );+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(999));+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(1));+ expect(screen.queryByTestId('plan-pill')).toBeNull();++ cleanup();+ render(+ <PinnedPlanPanel+ sessionId="session-remount"+ messages={[completed]}+ animated={false}+ width={400}+ />,+ );+ expect(screen.queryByTestId('plan-pill')).toBeNull();+ });++ it('keeps an already-expired historical completion hidden without retaining session state', () => {+ vi.setSystemTime(T0 + 10_000);++ render(+ <PinnedPlanPanel+ sessionId="historical-completion"+ messages={[planMessage('completed')]}+ animated={false}+ width={400}+ />,+ );++ expect(screen.queryByTestId('plan-pill')).toBeNull();+ });++ it('falls back to a component-local lifetime when the completion timestamp is missing', () => {+ render(+ <PinnedPlanPanel+ sessionId="missing-completion-timestamp"+ messages={[planMessage('completed', null)]}+ animated={false}+ width={400}+ />,+ );++ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(2_000));+ expect(screen.queryByTestId('plan-pill')).toBeNull();+ });});diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex aa805cdb7c..12a6e9d1d8 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -3528,6 +3528,7 @@ export function CCAgentSessionView({胶囊的悬停浮层向上展开,会盖住交互卡内容(条件集与下方 ternary的静默判定保持一致)。 */}<PinnedPlanPanel+ sessionId={sessionId ?? null}messages={messages}animated={isStreaming}width={inputWidth}diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 742616c525..e268e268f8 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -271,6 +271,12 @@ export interface ChatMessage {toolUseId?: string;toolName?: string;toolInput?: unknown;+ /**+ * Renderer-local timestamp for the latest in-place `update_plan` payload.+ * `createdAt` remains the persisted message creation time and must not be+ * rewritten because it also participates in message ordering.+ */+ planUpdatedAtMs?: number;/*** 产生这条消息的模型 raw id(读自 agentMeta.model)。对 subagent 子消息而言* 即子代理实际跑的模型(如 'claude-haiku-4-5-20251001')。仅 SDK 带 model 的@@ -2618,6 +2624,7 @@ export function handleStreamEvent(...messages[existingUpdatableToolIdx],content: formatToolUseSummary(toolName, input),toolInput: input,+ ...(toolName === 'update_plan' ? { planUpdatedAtMs: Date.now() } : {}),};return {...finalized,@@ -2636,6 +2643,7 @@ export function handleStreamEvent(toolUseId,toolName,toolInput: input,+ ...(toolName === 'update_plan' ? { planUpdatedAtMs: Date.now() } : {}),isStreaming: false,createdAt: new Date().toISOString(),// subagent-model-chip: 透传 SDK model / parent_tool_use_id,让@@ -2737,6 +2745,7 @@ export function handleStreamEvent(terminalData?.plan,terminalTurnId,terminalTurnStatus,+ Date.now(),).messages: cleanedMessages;diff --git a/packages/maker-shared/src/__tests__/planCompletion.test.ts b/packages/maker-shared/src/__tests__/planCompletion.test.tsindex 7b79e294d9..5ab51042f0 100644--- a/packages/maker-shared/src/__tests__/planCompletion.test.ts+++ b/packages/maker-shared/src/__tests__/planCompletion.test.ts@@ -90,6 +90,7 @@ describe('applyCodexPlanSnapshotOnDone', () => {});it('marks the matching plan complete when a successful turn has no final snapshot', () => {+ const completedAtMs = 1_700_000_005_000;const message = planMessage('plan:done', [{ step: 'Inspect', status: 'in_progress' },{ step: 'Patch', status: 'pending' },@@ -99,11 +100,13 @@ describe('applyCodexPlanSnapshotOnDone', () => {null,'done','completed',+ completedAtMs,);expect(result.changed).toBe(true);expect(result.toolUseId).toBe('plan:done');expect(result.messages[0]).toMatchObject({+ planUpdatedAtMs: completedAtMs,toolInput: {plan: [{ step: 'Inspect', status: 'completed' },diff --git a/packages/maker-shared/src/messageRender.ts b/packages/maker-shared/src/messageRender.tsindex 89c0d8314f..c21fdff712 100644--- a/packages/maker-shared/src/messageRender.ts+++ b/packages/maker-shared/src/messageRender.ts@@ -11,6 +11,8 @@ export interface MessageRenderSourceMessageLike {role?: string | null;content?: unknown;createdAt?: string;+ /** Renderer-local time of the latest in-place plan payload update. */+ planUpdatedAtMs?: number;toolName?: string | null;toolInput?: unknown;/** SDK tool-use id — used to link a Task/collab tool-call to its live `agent_task_update`. */@@ -187,6 +189,7 @@ export interface MessageRenderTodoInsertion {key: string;todos: MessageRenderTodoItem[];createdAt?: string;+ updatedAtMs?: number;source: MessageRenderTodoSource;}@@ -467,6 +470,7 @@ export function findMessageTodoInsertions<TMessage extends MessageRenderSourceMekey: `${keyPrefix}-${sourceClientId(first)}`,todos: session.todos,createdAt: messages[session.lastIndex]?.createdAt,+ updatedAtMs: messages[session.lastIndex]?.planUpdatedAtMs,source: session.source,});}@@ -537,6 +541,7 @@ export function applyCodexPlanSnapshotOnDone<snapshot: unknown,turnId?: string | null,terminalStatus?: unknown,+ planUpdatedAtMs?: number,): CodexPlanSnapshotApplyResult<TMessage> {const authoritativeSnapshot = Array.isArray(snapshot) ? snapshot : null;const hasAuthoritativeSnapshot = authoritativeSnapshot !== null;@@ -584,6 +589,9 @@ export function applyCodexPlanSnapshotOnDone<const next = [...messages];next[index] = {...message,+ ...(typeof planUpdatedAtMs === 'number' && Number.isFinite(planUpdatedAtMs)+ ? { planUpdatedAtMs }+ : {}),...(message.toolInput !== undefined? { toolInput: { ...input, plan: nextSnapshot } }: {}),