Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(chat): clear superseded thinking state
v_wyxgwang0501494151d9
diff --git a/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx b/apps/desktop/src/features/chat/transcript/AssistantTurn.tsxindex ccee9888d..8e99645cb 100644--- a/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx+++ b/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx@@ -345,16 +345,10 @@ export const AssistantTurn = memo(function AssistantTurn({timingsRef.current = turnDelegationTimings;const { process, responses } = summary;const segments = useMemo(() => segmentTurnProcess(process), [process]);- // While the turn runs, its latest process chunk stays open; earlier chunks- // have settled, and untouched chunks close on completion.- const lastProcessIndex = useMemo(- () =>- segments.reduce(- (last, segment, index) => (segment.kind === "process" ? index : last),- -1,- ),- [segments],- );+ // The live tail is the turn's actual last part. A process chunk opens and+ // reports live state only while it owns that part, so a superseded thinking+ // chunk cannot keep a false "Thinking" header once a Bash call or a separate+ // streamed answer takes over the turn.const activePart = isActive ? entry.parts.at(-1) : undefined;const partContext = { isActive, activePart, runtimeActivity, turnDelegationStatuses, turnDelegationTimings };@@ -368,17 +362,19 @@ export const AssistantTurn = memo(function AssistantTurn({aria-label={t("chat.assistantMessage")}><div className="message-col">- {segments.map((segment, index) => {+ {segments.map((segment) => {if (segment.kind === "run") {return <StandaloneRunRow key={`run-${segment.key}`} segment={segment} />;}+ const ownsActiveTail =+ activePart !== undefined && segment.parts.includes(activePart);return (<TurnProcesskey={`process-${segment.key}`}turnId={segment.key}processParts={segment.parts}- turnParts={segment.parts}- isActive={isActive && index === lastProcessIndex}+ turnParts={entry.parts}+ isActive={isActive && ownsActiveTail}delegationStatuses={turnDelegationStatuses}><AssistantTurnParts parts={segment.parts} {...partContext} />diff --git a/apps/desktop/src/lib/turn-process.ts b/apps/desktop/src/lib/turn-process.tsindex 7f22a11e0..6dbdfb13c 100644--- a/apps/desktop/src/lib/turn-process.ts+++ b/apps/desktop/src/lib/turn-process.ts@@ -122,8 +122,9 @@ export function projectTurnProcess(entry: AssistantTurnEntry) {** `hideThinking` is `!showThinking`: completed reasoning rows and excerpts are* hidden, while the live reasoning indicator still counts as a visible step so- * a thinking-only process keeps its indicator. Bash and run aliases are always- * counted: they render as standalone rows inside the process.+ * a thinking-only process keeps its indicator. The helper counts exactly the+ * parts it is given; Bash and run aliases are segmented out before rendering+ * and never reach a process chunk, so they are never counted here.*/export function visibleProcessSteps(parts: readonly AssistantTurnPart[],diff --git a/scripts/e2e/transcript-disclosure-anchor.tsx b/scripts/e2e/transcript-disclosure-anchor.tsxindex 7a659ccb1..3aeed2de3 100644--- a/scripts/e2e/transcript-disclosure-anchor.tsx+++ b/scripts/e2e/transcript-disclosure-anchor.tsx@@ -33,15 +33,15 @@ function message(/** A tool row whose opened body is far taller than its own header. */function toolRowMessage(id: string): UiMessage {return message(id, "tool", "done", {- toolName: "Bash",+ // A non-run tool so the row stays inside the process disclosure; a Bash row+ // is standalone and would not own the process's live tail.+ toolName: "Read",toolCallId: `call-${id}`,toolStatus: "success",- toolArgs: { command: "printf 'step'" },+ toolArgs: { path: "src/example.ts" },toolResult: {details: {- stdout: Array.from({ length: 80 }, (_value, index) => `step ${index}`).join(- "\n",- ),+ stdout: Array.from({ length: 80 }, (_value, index) => `step ${index}`).join("\n"),exitCode: 0,},},@@ -270,7 +270,6 @@ globalThis.transcriptDisclosureProbe = async () => {message("process-user", "user", "Inspect"),message("progress", "assistant", Array.from({ length: 50 }, (_, i) => `Progress paragraph ${i}.`).join("\n\n")),toolRowMessage("process-tool"),- message("final", "assistant", "Finished."),];const processContainer = document.createElement("div");processContainer.style.height = "600px";diff --git a/scripts/e2e/transcript-long-history.tsx b/scripts/e2e/transcript-long-history.tsxindex b239c2dde..0a5d6d74d 100644--- a/scripts/e2e/transcript-long-history.tsx+++ b/scripts/e2e/transcript-long-history.tsx@@ -28,8 +28,10 @@ const row = (id: string, role: UiMessage["role"], content: string, extra: Partiaid, role, content, createdAt, status: "complete", ...extra,});const tool = (id: string): UiMessage => row(id, "tool", "Synthetic result", {- toolName: "Bash", toolCallId: id, toolStatus: "success",- toolArgs: { command: `printf ${id}` }, toolResult: { details: { stdout: "Synthetic result", exitCode: 0 } },+ // A non-run tool so the fixture forms ordinary activity groups. A Bash row is+ // standalone and would not join a group.+ toolName: "Read", toolCallId: id, toolStatus: "success",+ toolArgs: { path: `${id}.ts` }, toolResult: { details: { content: "Synthetic result" } },});function session(id: string, messages: UiMessage[]): FixtureSession {const reads = { count: 0 };diff --git a/scripts/e2e/transcript-render.tsx b/scripts/e2e/transcript-render.tsxindex 29add30d6..afb2f1031 100644--- a/scripts/e2e/transcript-render.tsx+++ b/scripts/e2e/transcript-render.tsx@@ -309,15 +309,18 @@ globalThis.transcriptRenderProbe = async () => {};try {const groups = 100;+ // The render-count regression needs ordinary activity groups. A Bash row is+ // standalone and bypasses ActivityGroup, so this fixture uses Read rows; the+ // standalone Bash row is exercised separately below.let messages = [message("user", "user", "Inspect the workspace")];for (let index = 0; index < groups; index++) {messages.push(message(`tool-${index}`, "tool", "done", {- toolName: "Bash",+ toolName: "Read",toolCallId: `call-${index}`,toolStatus: "success",- toolArgs: { command: `printf step-${index}` },- toolResult: { details: { stdout: "done", exitCode: 0 } },+ toolArgs: { path: `file-${index}.ts` },+ toolResult: `contents of file-${index}.ts`,}),);messages.push(@@ -351,7 +354,7 @@ globalThis.transcriptRenderProbe = async () => {messages = [...messages];messages[1] = {...messages[1],- toolArgs: { command: "printf changed-command" },+ toolArgs: { path: "changed-file.ts" },};render(messages);assert(@@ -359,10 +362,42 @@ globalThis.transcriptRenderProbe = async () => {"changed tool group did not render exactly once",);assert(- container.textContent?.includes("changed-command"),+ container.textContent?.includes("changed-file.ts"),"changed tool row not visible",);+ // A standalone Bash row is not an activity group: it updates through its own+ // rendered command, outside every process disclosure.+ const bashMessages = (command: string): UiMessage[] => [+ message("bash-user", "user", "Run"),+ message("bash-row", "tool", "", {+ toolName: "Bash",+ toolCallId: "bash-call",+ toolStatus: "success",+ toolArgs: { command },+ toolResult: { details: { stdout: "ok", exitCode: 0 } },+ }),+ ];+ render(bashMessages("printf before"));+ const bashRow = container.querySelector<HTMLElement>('[data-message-id="bash-row"]');+ assert(bashRow, "the standalone Bash row did not render");+ assert(+ bashRow.closest(".turn-process") === null,+ "the Bash row must render outside every process disclosure",+ );+ assert(container.textContent?.includes("printf before"), "the Bash command did not render");+ globalThis.__activityGroupRenders = [];+ render(bashMessages("printf after"));+ assert(+ container.textContent?.includes("printf after") &&+ !container.textContent?.includes("printf before"),+ "the Bash row did not update its rendered command",+ );+ assert(+ globalThis.__activityGroupRenders.length === 0,+ "a standalone Bash row must not render an activity group",+ );+// Keep Task's own message stable: a later lifecycle result must still// update its terminal status and timing (#238), unlike unrelated text.const start = Date.now() - 12_000;diff --git a/scripts/e2e/turn-process.tsx b/scripts/e2e/turn-process.tsxindex ad59ce92d..81ac6af8d 100644--- a/scripts/e2e/turn-process.tsx+++ b/scripts/e2e/turn-process.tsx@@ -205,6 +205,69 @@ export async function turnProcessProbe() {"an untouched process chunk collapses on completion",);+ // A streaming thinking chunk superseded by a later Bash row must not keep a+ // false Thinking header: the real tail is the Bash row.+ const supersededThought = message("thought-before-bash", "assistant", "", {+ thinking: "Reasoning before a command",+ status: "streaming",+ });+ const bashLive = run("bash-live", "pnpm test");+ const thinkingLabel = i18n.t("chat.thinkingFor", { time: "" });+ render([supersededThought, bashLive], true, null, "thinking-to-bash");+ check(+ row("bash-live")?.closest(".turn-process") === null &&+ visible(row("bash-live")),+ "a Bash row that supersedes thinking stays standalone and visible",+ );+ check(+ !processHeaders().some((header) =>+ header+ .querySelector(".tool-activity-label")+ ?.textContent?.startsWith(thinkingLabel),+ ),+ "a superseded thinking chunk does not keep a Thinking header",+ );+ setSettings({ showThinking: false });+ render([supersededThought, bashLive], true, null, "thinking-to-bash-hidden");+ check(+ container.querySelectorAll(".turn-process").length === 0 &&+ visible(row("bash-live")),+ "hidden superseded thinking leaves no empty process and keeps the Bash row",+ );+ setSettings();++ // A separate streamed answer supersedes the thinking chunk the same way.+ const supersededThought2 = message("thought-before-answer", "assistant", "", {+ thinking: "Reasoning before an answer",+ status: "streaming",+ });+ const separateAnswer = message("stream-answer", "assistant", "Answer text", {+ status: "streaming",+ });+ render([supersededThought2, separateAnswer], true, null, "thinking-to-answer");+ check(+ Boolean(row("stream-answer")) &&+ row("stream-answer")?.closest(".turn-process") === null,+ "a separate streamed answer stays outside the process",+ );+ check(+ !processHeaders().some((header) =>+ header+ .querySelector(".tool-activity-label")+ ?.textContent?.startsWith(thinkingLabel),+ ),+ "a separate streamed answer clears the Thinking header",+ );+ setSettings({ showThinking: false });+ render([supersededThought2, separateAnswer], true, null, "thinking-to-answer-hidden");+ check(+ container.querySelectorAll(".turn-process").length === 0 &&+ !container.querySelector(".thinking") &&+ Boolean(row("stream-answer")),+ "hidden thinking superseded by a separate answer leaves no empty process",+ );+ setSettings();+// Show thinking off: the live indicator stays, completed reasoning leaves// nothing behind, and stored reasoning is never deleted.const liveThought = message("live-thought", "assistant", "", {