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(transcript): keep a live turn running when it is not the tail entry
yu.xia6a0855bbd7a4
diff --git a/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx b/apps/desktop/src/features/chat/transcript/AssistantTurn.tsxindex 4ad175139..5c85a3700 100644--- a/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx+++ b/apps/desktop/src/features/chat/transcript/AssistantTurn.tsx@@ -175,17 +175,23 @@ type TranscriptHistoryProps = {entries: TranscriptEntry[];isRunning: boolean;liveDelegations?: ReadonlyMap<string, true>;+ /** The running session's live turn, when it renders inside the history list (#1949). */+ liveTurnId?: string;};/*** Keep the completed transcript out of the streaming reconciliation path.* The projection is still rebuilt for correctness, but React can now bail out- * before walking every historical row when only the active tail changed.+ * before walking every historical row when only the active tail changed. A+ * live turn that is not the tail entry still renders active via `liveTurnId`;+ * its streaming rows rebuild the projection anyway, so the bail-out only ever+ * skips settled rows.*/export const TranscriptHistory = memo(function TranscriptHistory({entries,isRunning,liveDelegations,+ liveTurnId,}: TranscriptHistoryProps) {return (<>@@ -194,7 +200,7 @@ export const TranscriptHistory = memo(function TranscriptHistory({key={transcriptEntryKey(entry)}entry={entry}isRunning={isRunning}- isActive={false}+ isActive={entry.kind === "assistant-turn" && entry.id === liveTurnId}delegationsLive={entry.kind === "assistant-turn" && liveDelegations?.has(entry.id)}/>))}@@ -204,6 +210,7 @@ export const TranscriptHistory = memo(function TranscriptHistory({if (previous.isRunning !== next.isRunning ||previous.liveDelegations !== next.liveDelegations ||+ previous.liveTurnId !== next.liveTurnId ||previous.entries.length !== next.entries.length) {return false;diff --git a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsxindex 73b1ac57b..bd71a0f76 100644--- a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx+++ b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx@@ -28,6 +28,7 @@ import {import { TranscriptHistory, TranscriptTail } from "./AssistantTurn";import { collectLiveDelegationEntries } from "../../../lib/live-delegation-entries";import { reuseReadonlyMap } from "../../../lib/assistant-turns";+import { liveHistoryTurnId } from "../../../lib/turn-process";import { useTranscriptScroll } from "./hooks/useTranscriptScroll";import { useTranscriptContinuation } from "../../../hooks/use-transcript-continuation";import type { TranscriptSearchTarget } from "../../../lib/transcript-reading";@@ -219,6 +220,13 @@ function TranscriptBody({const liveDelegationsRef = useRef(rawLiveDelegations);const liveDelegations = reuseReadonlyMap(liveDelegationsRef.current, rawLiveDelegations);liveDelegationsRef.current = liveDelegations;+ // The running turn is not always the tail entry: a steering message or a+ // system row can render after it, and the history list defaults every entry+ // to inactive. Row state identifies the live turn instead (#1949).+ const liveTurnId = useMemo(+ () => (transcriptRunning ? liveHistoryTurnId(historyEntries, tailEntry) : undefined),+ [historyEntries, tailEntry, transcriptRunning],+ );const hasSpecializedActivity = specializedActivity !== undefined;// Existing output does not mean the turn has finished: a text stream can// pause, and completed tool rows can outlive their activity. Keep one tail@@ -467,7 +475,7 @@ function TranscriptBody({// view, which is exactly the jitter this avoids.<div className="transcript-hydration-spacer" aria-hidden />) : null}- <TranscriptHistory entries={historyEntries} isRunning={isRunning} liveDelegations={liveDelegations} />+ <TranscriptHistory entries={historyEntries} isRunning={isRunning} liveDelegations={liveDelegations} liveTurnId={liveTurnId} />{tailEntry ? (<TranscriptTailentry={tailEntry}diff --git a/apps/desktop/src/lib/turn-process.ts b/apps/desktop/src/lib/turn-process.tsindex 0060724dd..ba2f31049 100644--- a/apps/desktop/src/lib/turn-process.ts+++ b/apps/desktop/src/lib/turn-process.ts@@ -3,6 +3,7 @@ import type {AssistantActivityItem,AssistantTurnEntry,AssistantTurnPart,+ TranscriptEntry,} from "./assistant-turns";import { isStandaloneRunActivity } from "./assistant-turns";import type { TranscriptDisplayMode } from "./transcript-display-mode";@@ -245,13 +246,42 @@ export function turnProcessPhase({);if (stopped) return { kind: "stopped" };if (isActive) return { kind: "running", phase: activity?.phase };- const unsettled = parts.some((part) =>+ if (turnHasStreamingRows(parts)) return { kind: "unsettled" };+ return { kind: "completed" };+}++/** A row of the turn is still streaming, so the turn has unsettled live work. */+export function turnHasStreamingRows(+ parts: readonly AssistantTurnPart[],+): boolean {+ return parts.some((part) =>part.kind === "message"? part.message.status === "streaming": part.items.some((item) => item.message.status === "streaming"),);- if (unsettled) return { kind: "unsettled" };- return { kind: "completed" };+}++/**+ * The turn a running transcript is driving, when that turn is not the tail+ * entry. Tail position alone cannot identify it: a steering message or a+ * system row may render after the live turn (#1949), while the history list+ * renders every entry as inactive. The last assistant-turn with streaming+ * rows is the running one; an earlier turn with stuck rows is a crash or a+ * lost host, which `turnProcessPhase` keeps reading as unsettled (#1923).+ * A tail assistant-turn reports its own active state, so it yields no+ * history id, and a turn whose rows all settled yields none either: without+ * a streaming row the turn may genuinely have finished.+ */+export function liveHistoryTurnId(+ entries: readonly TranscriptEntry[],+ tailEntry?: TranscriptEntry | null,+): string | undefined {+ if (tailEntry?.kind === "assistant-turn") return undefined;+ let live: AssistantTurnEntry | undefined;+ for (const entry of entries) {+ if (entry.kind === "assistant-turn") live = entry;+ }+ return live && turnHasStreamingRows(live.parts) ? live.id : undefined;}/**diff --git a/apps/desktop/test/transcript-live-turn.test.mjs b/apps/desktop/test/transcript-live-turn.test.mjsnew file mode 100644index 000000000..38ca4b263--- /dev/null+++ b/apps/desktop/test/transcript-live-turn.test.mjs@@ -0,0 +1,29 @@+import assert from "node:assert/strict";+import test from "node:test";+import { readTranscriptModule } from "./helpers/source-contracts.mjs";++const [transcript, assistantTurn] = await Promise.all([+ readTranscriptModule("ChatTranscript.tsx"),+ readTranscriptModule("AssistantTurn.tsx"),+]);++test("the history list keeps a non-tail live turn active", () => {+ // A steering message or system row can render after the running turn, so+ // tail position cannot decide liveness (#1949): the transcript resolves the+ // live turn from row state, and only while the live tail is in view, so the+ // reading window keeps #1900's semantics and hung rows keep #1965's+ // unsettled reading.+ assert.match(transcript, /liveTurnId = useMemo\(/);+ assert.match(+ transcript,+ /transcriptRunning \? liveHistoryTurnId\(historyEntries, tailEntry\) : undefined/,+ );+ assert.match(transcript, /liveTurnId=\{liveTurnId\}/);+ assert.match(+ assistantTurn,+ /isActive=\{entry\.kind === "assistant-turn" && entry\.id === liveTurnId\}/,+ );+ // The bail-out comparator must hear the same signal, or a settled list would+ // keep a turn that just went live frozen in its inactive rendering.+ assert.match(assistantTurn, /previous\.liveTurnId !== next\.liveTurnId/);+});diff --git a/apps/desktop/test/turn-process.test.mjs b/apps/desktop/test/turn-process.test.mjsindex 5688ce5bc..37aaf5e21 100644--- a/apps/desktop/test/turn-process.test.mjs+++ b/apps/desktop/test/turn-process.test.mjs@@ -10,6 +10,8 @@ const {segmentTurnProcess,turnProcessTiming,turnProcessPhase,+ turnHasStreamingRows,+ liveHistoryTurnId,} = await import("../src/lib/turn-process.ts");const { cachedActivitySummary, cachedVisibleProcessSteps } = await import("../src/lib/transcript-activity-summary.ts"@@ -645,3 +647,83 @@ test("settings writes validate the thinking preference without changing other pr/thinkingDisplayMode is invalid/,);});++test("the last assistant-turn with streaming rows is the live turn when it is not the tail", () => {+ // A steering message renders after the live turn, so the tail entry is not+ // the turn; the history list must not read the running turn as inactive (#1949).+ const steered = buildTranscriptEntries([+ message("user", "user", "Inspect"),+ message("intro", "assistant", "Checking", { status: "complete" }),+ tool("read", "Read", { status: "streaming" }),+ message("steer", "user", "also check the config"),+ ]);+ const steeredTail = steered.entries.at(-1);+ const steeredHistory = steered.entries.slice(0, -1);+ assert.equal(steeredTail.kind, "message");+ assert.equal(steeredTail.message.id, "steer");+ const steeredTurn = steeredHistory.find((entry) => entry.kind === "assistant-turn");+ assert.equal(steeredTurn.kind, "assistant-turn");+ assert.equal(liveHistoryTurnId(steeredHistory, steeredTail), steeredTurn.id);+ // Marked live, the same rows read as work in progress, not as an outcome.+ assert.deepEqual(+ turnProcessPhase({ parts: steeredTurn.parts, isActive: true, failed: false }),+ { kind: "running", phase: undefined },+ );++ // When the tail entry is the turn itself, the tail already renders active.+ const settled = buildTranscriptEntries([+ message("u2", "user", "go"),+ message("a2", "assistant", "done", { status: "complete" }),+ ]);+ assert.equal(+ liveHistoryTurnId(settled.entries.slice(0, -1), settled.entries.at(-1)),+ undefined,+ );++ // Settled rows behind a trailing message do not claim liveness: the turn+ // may genuinely have finished.+ const finished = buildTranscriptEntries([+ message("u3", "user", "go"),+ message("a3", "assistant", "done", { status: "complete" }),+ message("steer3", "user", "one more"),+ ]);+ assert.equal(+ liveHistoryTurnId(finished.entries.slice(0, -1), finished.entries.at(-1)),+ undefined,+ );++ // An earlier turn stuck at streaming is not the live one when a later turn+ // exists: it is a crash or lost host, which reads as unsettled (#1923).+ const crashedThenNew = buildTranscriptEntries([+ message("u4", "user", "go"),+ message("a4", "assistant", "", { status: "streaming" }),+ message("u5", "user", "retry"),+ message("a5", "assistant", "recovered", { status: "complete" }),+ message("steer5", "user", "and now"),+ ]);+ assert.equal(+ liveHistoryTurnId(crashedThenNew.entries.slice(0, -1), crashedThenNew.entries.at(-1)),+ undefined,+ );+});++test("turnHasStreamingRows reads both message and activity rows", () => {+ assert.equal(+ turnHasStreamingRows([+ { kind: "message", message: message("m", "assistant", "", { status: "streaming" }) },+ ]),+ true,+ );+ assert.equal(+ turnHasStreamingRows([+ { kind: "activity", items: [{ kind: "tool", message: tool("t", "Bash", { status: "streaming" }) }] },+ ]),+ true,+ );+ assert.equal(+ turnHasStreamingRows([+ { kind: "message", message: message("m2", "assistant", "done") },+ ]),+ false,+ );+});diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 4607d91fe..1eede4ffd 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -909,7 +909,10 @@ of it, and a long turn collapses in one gesture. The answer, assistant errors,stopped trailing partial text and pending action cards remain outside, reachablewithout expanding the process. An untouched process closes on completion, leavingthe final answer; with no final text, the process header and those surfaces-remain.+remain. Liveness follows the turn's rows, not the transcript's tail position:+while the session runs, a turn whose rows are still streaming stays open and+reads as running even when a steering message or system row renders after it,+and an idle turn whose rows never settled reads as an unknown outcome instead.Within the process, the `Transcript display` mode decides the grouping.`fully-folded` (the default; absent or unknown values use it) forms ordinarydiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex f3e3e63b8..9536b8cc7 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -68,6 +68,26 @@- **Status:** Automated browser regression; the interruption assertion failswithout explicit cancellation of the browser-owned smooth navigation.+### E2E-TRANSCRIPT-live-turn-not-tail-stays-running++- **Preconditions:** Real transcript projection with the production+ `ChatTranscript`; a running session whose turn has streaming rows, and a+ steering message or system row rendered after that turn.+- **Steps:** While the turn's tool or reasoning rows stream, append a steering+ user message so the turn is no longer the tail entry. Observe the process+ header, the disclosure state, and the turn menu. Then settle the rows;+ separately stop the session mid-turn with rows left streaming.+- **Expected:** The non-tail live turn keeps a running process header with its+ activity marker, its process stays open, and copy/regenerate stay gated on+ completion; the settled turn then reads completed. In a stopped or idle+ transcript the same stuck rows read as an unknown outcome instead (#1923),+ and a reading window over older history never claims live status (#1900).+- **Coverage:** `node --test apps/desktop/test/turn-process.test.mjs` and+ `apps/desktop/test/transcript-live-turn.test.mjs` pin the liveness selection,+ the phase reading, and the wiring contract. Full Electron journey Draft.+- **Specs:** `04-ux/08-component-spec.md` §turn-process; **Milestone:** Maintenance.+- **Status:** Unit and source-contract regression; visual Electron scenario Draft.+### E2E model discovery membership- **Entry:** `node scripts/e2e-model-discovery-state.mjs` after building Host,diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex 98a63a26a..8175407a9 100644--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@ -1077,7 +1077,9 @@ SESSIONS [msg+][↕]每个回合只渲染一个顶层过程披露,只有 Bash 调用的回合也一样;任何命令行都不是该披露的同级,长回合可以用一次操作收起。末尾回答、助手错误、中止后的末尾部分文字和待处理操作卡留在披露之外,无需展开过程即可访问。未操作的过程在完成时收起,只剩最终回答;没有最终-文字时,过程标题和这些操作面仍会保留。+文字时,过程标题和这些操作面仍会保留。回合的活跃性跟随其行状态而非转录的尾部位置:会话+运行期间,行仍在流式输出的回合即使后面渲染了 steering 消息或系统行,也保持展开并显示为+执行中;行始终未结算的空闲回合则显示为结果未知。在披露内部,`过程显示`模式决定活动如何分组。`fully-folded`(默认;缺失或未知值使用它)把普通助手进度段落之间的连续工具、搜索或思考片段组为普通活动组,`Bash`/run 别名