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): scope plan streaming to its owning turn

Kafeifei312852449327
diff --git a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
index 9a355f5f7c..7eb98d1c22 100644
--- a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
@@ -20,7 +20,7 @@
*/
import { useEffect, useMemo, useRef, useState } from 'react';
-import { findLatestMessageTodoInsertion } from '@cindy/maker-shared/message-render';
+import { getLatestMessageTodoState } from '@cindy/maker-shared/message-render';
import { TodoListCard } from '@/components/chat/TodoListCard';
import type { ChatMessage } from '@/lib/makerChatStore';
@@ -51,10 +51,23 @@ export function PinnedPlanPanel({
streaming?: boolean;
className?: string;
}): React.ReactElement | null {
- const insertion = useMemo(
- () => findLatestMessageTodoInsertion(messages, { taskHistoryMayBeIncomplete }),
+ const todoState = useMemo(
+ () => getLatestMessageTodoState(messages, { taskHistoryMayBeIncomplete }),
[messages, taskHistoryMayBeIncomplete],
);
+ const insertion = todoState.insertion;
+ // `streaming` is session-wide, but a legacy plan can outlive its turn. Only
+ // suppress the legacy all-done fallback while the latest normal user turn
+ // still owns this plan; steer rows do not start a new turn.
+ const latestNormalUserIndex = useMemo(() => {
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
+ const message = messages[index];
+ if (message.role === 'user' && message.delivery !== 'steer') return index;
+ }
+ return -1;
+ }, [messages]);
+ const planBelongsToLatestTurn =
+ todoState.latestInsertionIndex < 0 || latestNormalUserIndex <= todoState.latestInsertionIndex;
const allDone = Boolean(
insertion &&
insertion.todos.length > 0 &&
@@ -70,7 +83,7 @@ export function PinnedPlanPanel({
const codexPlanAlive =
insertion?.source === 'codex' &&
insertion.sealed !== true &&
- (streaming || insertion.turnFailed === true);
+ ((streaming && planBelongsToLatestTurn) || insertion.turnFailed === true);
// 退场 = host 盖了终态章(权威),或计划自己勾完了(没有章的旧数据兜底)。
const retired =
Boolean(insertion) && (insertion?.sealed === true || (allDone && !codexPlanAlive));
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.tsx
index ed8f308238..9cd3d1ad67 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
@@ -583,6 +583,58 @@ describe('PinnedPlanPanel terminal seal', () => {
expect(screen.queryByTestId('plan-pill')).toBeNull();
});
+ it('does not revive an old unsealed all-done plan when a later turn starts streaming', () => {
+ const oldCompletedPlan = planMessage('completed', T0, T0);
+ vi.setSystemTime(T0 + 10_000);
+ const view = render(
+ <PinnedPlanPanel
+ sessionId="old-plan-new-turn"
+ messages={[oldCompletedPlan]}
+ animated={false}
+ streaming={false}
+ width={400}
+ />,
+ );
+ expect(screen.queryByTestId('plan-pill')).toBeNull();
+
+ view.rerender(
+ <PinnedPlanPanel
+ sessionId="old-plan-new-turn"
+ messages={[
+ oldCompletedPlan,
+ {
+ clientId: 'new-turn-user',
+ role: 'user',
+ content: 'Start the next turn',
+ createdAt: new Date(T0 + 10_000).toISOString(),
+ delivery: 'turn',
+ },
+ ]}
+ animated
+ streaming
+ width={400}
+ />,
+ );
+
+ expect(screen.queryByTestId('plan-pill')).toBeNull();
+ });
+
+ it('keeps a current-turn unsealed all-done codex plan visible while streaming', () => {
+ const currentPlan = planMessage('completed', T0, T0);
+ render(
+ <PinnedPlanPanel
+ sessionId="current-plan-streaming"
+ messages={[currentPlan]}
+ animated
+ streaming
+ width={400}
+ />,
+ );
+
+ act(() => vi.advanceTimersByTime(4_000));
+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();
+ });
+
it('keeps the all-done fallback for TodoWrite plans even while streaming', () => {
// TodoWrite / Task 计划永远不会被盖章,全勾完兜底是它们唯一的退场路径,
// 流式与否都不该被"等章"逻辑挡住。