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): compare restored live tails by nonempty message identity
Seraph-x0c8b038cb42a
diff --git a/apps/desktop/src/hooks/use-transcript-view.ts b/apps/desktop/src/hooks/use-transcript-view.tsindex f15508956..a354b45fc 100644--- a/apps/desktop/src/hooks/use-transcript-view.ts+++ b/apps/desktop/src/hooks/use-transcript-view.ts@@ -1,5 +1,5 @@import { useMemo } from "react";-import { EMPTY_TRANSCRIPT, transcriptViewMessages } from "../lib/transcript-reading";+import { EMPTY_TRANSCRIPT, isTranscriptAtLiveTail, transcriptViewMessages } from "../lib/transcript-reading";import { useAppStore } from "../stores/app-store";/** Main transcript and subagent details consume the same renderer reading range. */@@ -19,9 +19,7 @@ export function useTranscriptView(sessionId: string) {focus: view?.focus ?? null,parentMessage: view?.parentMessage,historical: Boolean(view?.focus || view?.restored),- // A restored range keeps reading ownership after joining live output.- // Only the canonical tail can carry this session's running presentation.- liveTail: !view?.focus && !view?.hasMoreAfter && messages.at(-1) === live.at(-1),+ liveTail: isTranscriptAtLiveTail(live, messages, view),loading: Boolean(view?.loading),};}diff --git a/apps/desktop/src/lib/transcript-reading.ts b/apps/desktop/src/lib/transcript-reading.tsindex 4c38899e1..fa72dac0c 100644--- a/apps/desktop/src/lib/transcript-reading.ts+++ b/apps/desktop/src/lib/transcript-reading.ts@@ -33,6 +33,19 @@ export const TRANSCRIPT_PAGE_SIZE = 100;export const TRANSCRIPT_SEARCH_PAGE_SIZE = 60;export const TRANSCRIPT_CONTENT_LIMIT = 64 * 1024;+/** Reading ownership is independent of whether its range reaches live output. */+export function isTranscriptAtLiveTail(+ live: readonly UiMessage[],+ messages: readonly UiMessage[],+ view?: TranscriptView,+): boolean {+ if (view?.focus || view?.hasMoreAfter) return false;+ // The canonical surface must show first-event waits even before it has rows.+ if (!view) return true;+ const tailId = live.at(-1)?.id;+ return Boolean(tailId) && messages.at(-1)?.id === tailId;+}+export function transcriptViewFromSession(session: SessionDetail,focus: TranscriptSearchTarget | null = null,diff --git a/apps/desktop/test/transcript-reading.test.mjs b/apps/desktop/test/transcript-reading.test.mjsindex e9c1cfc24..bb9926e5f 100644--- a/apps/desktop/test/transcript-reading.test.mjs+++ b/apps/desktop/test/transcript-reading.test.mjs@@ -6,7 +6,7 @@ register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));const { createTranscriptReadingRuntime } = await import("../src/stores/runtime/transcript-reading-runtime.ts");-const { transcriptViewMessages, transcriptViewFromSession } = await import("../src/lib/transcript-reading.ts");+const { isTranscriptAtLiveTail, transcriptViewMessages, transcriptViewFromSession } = await import("../src/lib/transcript-reading.ts");const { getSessionMessageSnapshot } = await import("../src/lib/session-transcript-updates.ts");const { mergeLiveSessionMessages, upsertLiveSessionMessage, projectMessageEnd, removeLiveSessionMessage } = await import("../src/lib/session-transcript.ts");const { buildTranscriptEntries } = await import("../src/lib/assistant-turns.ts");@@ -73,6 +73,36 @@ function reader(read, overrides = {}) {};}+test("a canonical empty transcript can present its first-event wait, while empty reading ranges cannot", () => {+ assert.equal(isTranscriptAtLiveTail([], []), true);+ const view = { ...transcriptViewFromSession(page([], { hasMoreAfter: false }).session), restored: true };+ assert.equal(isTranscriptAtLiveTail([], transcriptViewMessages([], view), view), false);+ assert.equal(isTranscriptAtLiveTail([message("tail")], [], view), false);+ const disconnected = { ...view, messages: [message("old")] };+ assert.equal(isTranscriptAtLiveTail([], transcriptViewMessages([], disconnected), disconnected), false);+ const unidentified = [message("")];+ assert.equal(isTranscriptAtLiveTail(unidentified, unidentified, view), false);+});++test("live-tail identity survives a restored navigation parent's object copy", () => {+ const live = [message("tail", "live")];+ const copied = { ...live[0] };+ const view = { ...transcriptViewFromSession(page([copied], { hasMoreAfter: false }).session),+ restored: true, parentMessage: copied };+ const visible = transcriptViewMessages(live, view);+ assert.notEqual(visible.at(-1), live.at(-1), "exercise the real navigation-parent projection");+ assert.equal(isTranscriptAtLiveTail(live, visible, view), true);+ assert.equal(isTranscriptAtLiveTail(live, [{ ...copied }], view), true, "copied rows keep their wire identity");+});++test("unread gaps, explicit search and different tail identities remain historical", () => {+ const live = [message("tail")];+ const view = transcriptViewFromSession(page(live, { hasMoreAfter: false }).session);+ assert.equal(isTranscriptAtLiveTail(live, live, { ...view, hasMoreAfter: true }), false);+ assert.equal(isTranscriptAtLiveTail(live, live, { ...view, focus: { ...target("tail"), requestId: 1 } }), false);+ assert.equal(isTranscriptAtLiveTail(live, [message("other")], view), false);+});+test("a search jump keeps complete focused text without changing live/model input", async () => {const calls = [];const content = `${"prefix ".repeat(15_000)}needle`;diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 10af5a7b6..1ffd8965f 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -764,6 +764,9 @@ may be retained while exactly one workspace supplies the visible shell context.Keeping its reading bookmark does not mean the turn has finished. Rejoininglive output preserves the viewport rather than acting like a new turn.Explicit search, unread later pages, and disjoint snapshots remain historical.+ Reading ranges require a non-empty canonical message identity, compared by+ message id across history object copies. The ordinary canonical surface still+ shows the first-event wait before its first message arrives.### 2.5 Turn outcome closurediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 094fef49c..8973c5ec4 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -2116,6 +2116,9 @@ identify the platform validation still needed.Finished. The restored range and scroll offset remain owned by the reader.Another session, unread pages, and explicit search do not inherit livestatus. Terminal completion and abort show Finished and Stopped respectively.+ An empty restored range stays historical, an ordinary empty canonical range+ shows the initial wait, and a restored navigation-parent copy with the same+ message id keeps the running presentation.- **Automation**: `node scripts/e2e-transcript-reading-position.mjs`(`transcriptLiveTailProbe`).- **Specs linked**: `04-ux/09-interaction-patterns.md` §2.4diff --git a/scripts/e2e/transcript-live-tail.tsx b/scripts/e2e/transcript-live-tail.tsxindex 74b9b8451..614e56fce 100644--- a/scripts/e2e/transcript-live-tail.tsx+++ b/scripts/e2e/transcript-live-tail.tsx@@ -67,6 +67,19 @@ globalThis.transcriptLiveTailProbe = async () => {await frame();assert(activeLabel(), "ordinary live process must be running");assert(stop(), "the running composer must offer Stop");+ set({ messages: [], selectingSessionId: undefined });+ await frame();+ assert(host.querySelector('[data-session-pane="live-tail"] [data-testid="working-indicator"]'),+ "an empty canonical transcript still shows the initial model wait");+ set({ transcriptViews: { "live-tail": {+ messages: [], messageStart: 0, hasMoreBefore: false, hasMoreAfter: false,+ focus: null, restored: true, loading: null,+ } } });+ await frame();+ assert(!host.querySelector('[data-session-pane="live-tail"] .transcript-runtime-status > *'),+ "an empty restored range cannot prove it reaches a canonical live tail");+ set({ messages, transcriptViews: {}, selectingSessionId: "live-tail" });+ await frame();const bookmark = { pinned: false, messageId: user.id, offset: 0, scrollTop: 0, windowSize: 60 };// Public restore action used by a retained pane during selection revalidation.await useAppStore.getState().restoreTranscriptReading("live-tail", bookmark, new AbortController().signal);@@ -129,6 +142,13 @@ globalThis.transcriptLiveTailProbe = async () => {] } } });await frame();assert(!activeLabel(), "a disjoint range must not claim the canonical live turn");+ const copiedTool = { ...tool };+ set({ messages: [tool], transcriptViews: { "live-tail": {+ ...view, messages: [copiedTool], parentMessage: copiedTool,+ } } });+ await frame();+ assert(activeLabel(), "a restored canonical message keeps its identity across history object copies");+ set({ messages });set({ transcriptViews: { "live-tail": view }, runningSessions: {}, isRunning: false });await frame();assert(label()?.textContent === i18n.t("chat.processCompleted") && !activeLabel(), "only settled run state shows Finished");