Skip to content

Commit dd70530

Browse files
committed
Show the plan if it is from an active, not yet completed turn
1 parent 2946527 commit dd70530

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

apps/array/src/renderer/features/sessions/components/SessionView.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box, ContextMenu, Flex } from "@radix-ui/themes";
55
import {
66
type AcpMessage,
77
isJsonRpcNotification,
8-
isJsonRpcRequest,
8+
isJsonRpcResponse,
99
} from "@shared/types/session-events";
1010
import { useCallback, useMemo, useState } from "react";
1111
import { useHotkeys } from "react-hotkeys-hook";
@@ -58,28 +58,38 @@ export function SessionView({
5858
]);
5959

6060
const latestPlan = useMemo((): Plan | null => {
61-
// Find the index of the last user prompt - only show plans after that
62-
let lastPromptIndex = -1;
61+
let planIndex = -1;
62+
let plan: Plan | null = null;
63+
let responseIndex = -1;
64+
65+
// Find the most recent plan and response in one pass
6366
for (let i = events.length - 1; i >= 0; i--) {
6467
const msg = events[i].message;
65-
if (isJsonRpcRequest(msg) && msg.method === "session/prompt") {
66-
lastPromptIndex = i;
67-
break;
68+
69+
if (responseIndex === -1 && isJsonRpcResponse(msg)) {
70+
responseIndex = i;
6871
}
69-
}
7072

71-
// Search for plans only after the last user prompt
72-
for (let i = events.length - 1; i > lastPromptIndex; i--) {
73-
const msg = events[i].message;
74-
if (isJsonRpcNotification(msg) && msg.method === "session/update") {
73+
if (
74+
planIndex === -1 &&
75+
isJsonRpcNotification(msg) &&
76+
msg.method === "session/update"
77+
) {
7578
const update = (msg.params as { update?: { sessionUpdate?: string } })
7679
?.update;
7780
if (update?.sessionUpdate === "plan") {
78-
return update as Plan;
81+
planIndex = i;
82+
plan = update as Plan;
7983
}
8084
}
85+
86+
if (planIndex !== -1 && responseIndex !== -1) break;
8187
}
82-
return null;
88+
89+
// Plan is stale if the most recent response came after it (turn completed)
90+
if (responseIndex > planIndex) return null;
91+
92+
return plan;
8393
}, [events]);
8494

8595
const handleSubmit = useCallback(

0 commit comments

Comments
 (0)