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): preserve follow intent across immediate project switches
new-Beginner69fba162eb93
diff --git a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.tsindex 4d9d838ca..8f6b8404f 100644--- a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts+++ b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts@@ -714,12 +714,16 @@ export function useTranscriptScroll({releaseDisclosureAnchor();pinnedRef.current = true;setShowJump(false);+ // Persist the explicit follow intent before smooth scrolling yields. A+ // session/project switch can hide or unmount this pane before its native+ // scroll event; leaving the old bookmark would restore history on return.+ rememberReadingPosition();scrollToBottom(window.matchMedia("(prefers-reduced-motion: reduce)").matches? "auto": "smooth",);- }, [cancelReadingPosition, releaseDisclosureAnchor, scrollToBottom]);+ }, [cancelReadingPosition, releaseDisclosureAnchor, rememberReadingPosition, scrollToBottom]);// D269: history progression follows the visible top boundary, not only a// native scroll event. A tail page can collapse to less than one viewport,diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 56d24b67d..9bd47e602 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -742,7 +742,12 @@ may be retained while exactly one workspace supplies the visible shell context.- Sending a new prompt, retrying, or regenerating always re-pins follow mode and jumps to the bottom before the turn continues, even if the user had scrolled up- "Scroll to bottom" floating button appears as soon as manual upward scrollingreleases follow mode-- Click "Scroll to bottom" button: resumes auto-scroll and snaps to bottom+- Click "Scroll to bottom" button: resumes auto-scroll and snaps to bottom.+ Record the pinned bookmark synchronously, before any smooth-scroll event:+ immediately switching sessions or projects must preserve this follow intent+ even if the original pane is hidden or unmounted before scrolling finishes.+ Returning follows the latest output rather than restoring the old reading+ offset. Manual upward reading without that click still retains its position.- Stream completion: if user was auto-scrolling, keep at bottom; if manual, stay at position- An asynchronously completed diagram height update follows the same rule:ResizeObserver keeps a pinned transcript at the bottom, while a user who hasdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 0b6ed5423..d1652cfae 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -2166,7 +2166,11 @@ identify the platform validation still needed.running turn with tool output, and the real Composer and SessionPane.- **Steps**: Restore a bookmark during selection revalidation; append liveoutput; switch away and reveal the running pane; inspect an unread history- range and an explicit search at the tail; settle and abort the turn.+ range and an explicit search at the tail; settle and abort the turn. While+ reading above the live tail, click return-to-latest and switch away in the+ same task, before a native smooth-scroll event. Return first with the pane+ retained, then repeat while a project switch actually unmounts the pane and+ output continues in the background.- **Expected**: The restored live tail keeps a running process header whileStop is available. Content updates and pane reveal do not falsely showFinished. The restored range and scroll offset remain owned by the reader.@@ -2175,9 +2179,13 @@ identify the platform validation still needed.An empty restored range stays historical, an ordinary empty canonical rangeshows the initial wait, and a restored navigation-parent copy with the samemessage id keeps the running presentation.+ Return-to-latest synchronously records a pinned bookmark; both a retained+ reveal and a fresh project remount follow the newest output without a second+ click. The running header and Stop control stay consistent. Readers who did+ not choose return-to-latest keep their existing historical reading position.- **Automation**: `node scripts/e2e-transcript-reading-position.mjs`(`transcriptLiveTailProbe`).-- **Specs linked**: `04-ux/09-interaction-patterns.md` §2.4+- **Specs linked**: `04-ux/09-interaction-patterns.md` §2.3 / §2.4- **Acceptance**: C (session switching and running status)- **Status**: Automated isolated Electron regressiondiff --git a/scripts/e2e-transcript-reading-position.mjs b/scripts/e2e-transcript-reading-position.mjsindex edafd6c81..18f9da409 100644--- a/scripts/e2e-transcript-reading-position.mjs+++ b/scripts/e2e-transcript-reading-position.mjs@@ -62,7 +62,9 @@ app.whenReady().then(async () => {const child = spawn(electronBinary, [join(temp, "main.cjs")], { env, stdio: ["ignore", "pipe", "pipe"] });let output = "";for (const stream of [child.stdout, child.stderr]) stream.on("data", (data) => { output += data; });- const timer = setTimeout(() => child.kill("SIGKILL"), 45_000);+ // Four renderer probes share this process; slower hidden Windows frames can+ // exceed the old single-probe budget even when every assertion passes.+ const timer = setTimeout(() => child.kill("SIGKILL"), 90_000);let code;try { code = await new Promise((resolve, reject) => {child.once("error", reject); child.once("close", resolve);diff --git a/scripts/e2e/transcript-live-tail.tsx b/scripts/e2e/transcript-live-tail.tsxindex 614e56fce..7e755c3fd 100644--- a/scripts/e2e/transcript-live-tail.tsx+++ b/scripts/e2e/transcript-live-tail.tsx@@ -8,6 +8,7 @@ import { SessionPane } from "../../apps/desktop/src/components/SessionPane";import { Composer } from "../../apps/desktop/src/components/Composer";import { useAppStore } from "../../apps/desktop/src/stores/app-store";import type { AppState } from "../../apps/desktop/src/stores/app-state";+import { getTranscriptReadingPosition } from "../../apps/desktop/src/lib/transcript-reading-position";const frame = () => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));function assert(condition: unknown, label: string): asserts condition {@@ -22,9 +23,10 @@ async function until(predicate: () => boolean, label: string) {}function Surface() {const active = useAppStore((state) => state.activeSessionId);+ const retained = useAppStore((state) => state.retainedSessionIds);return <><div className="session-panes">- {["live-tail", "other-tail"].map((id) => <SessionPane key={id} sessionId={id} visible={id === active} />)}+ {retained.map((id) => <SessionPane key={id} sessionId={id} visible={id === active} />)}</div><Composer /></>;@@ -67,6 +69,51 @@ globalThis.transcriptLiveTailProbe = async () => {await frame();assert(activeLabel(), "ordinary live process must be running");assert(stop(), "the running composer must offer Stop");+ const canonicalScroller = host.querySelector<HTMLElement>('[data-session-pane="live-tail"] .thread-scroll')!;+ canonicalScroller.style.flex = "0 0 120px";+ const atBottom = () => Math.abs(canonicalScroller.scrollHeight - canonicalScroller.clientHeight - canonicalScroller.scrollTop) < 2;+ await until(() => canonicalScroller.scrollHeight > canonicalScroller.clientHeight + 200 && atBottom(),+ "the initial running pane overflows and follows latest");+ canonicalScroller.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -500 }));+ canonicalScroller.scrollTop = 160;+ canonicalScroller.dispatchEvent(new Event("scroll", { bubbles: true }));+ await frame();+ assert(getTranscriptReadingPosition("live-tail")?.pinned === false,+ `reading history must record an unpinned bookmark: ${JSON.stringify(getTranscriptReadingPosition("live-tail"))}`);+ const jump = host.querySelector<HTMLButtonElement>('[data-session-pane="live-tail"] .jump-latest-btn')!;+ assert(jump, "history reading offers return to latest");+ // Do not yield to a native scroll event between the click and hiding the+ // pane. A smooth scroll has not reached the bottom when navigation wins.+ flushSync(() => jump.click());+ assert(getTranscriptReadingPosition("live-tail")?.pinned === true,+ "return to latest must synchronously replace the old reading bookmark");+ set({ activeSessionId: "other-tail", messages: [], isRunning: false,+ retainedTranscripts: { "live-tail": messages, "other-tail": [] } });+ set({ activeSessionId: "live-tail", messages, isRunning: true });+ await until(atBottom, "an immediate retained return stays pinned");+ assert(!host.querySelector('[data-session-pane="live-tail"] .jump-latest-btn'),+ "retained reveal must not resurrect the old unpinned bookmark");+ // A project switch drops the original DOM entirely. Its bookmark must+ // still preserve the explicit follow intent across the fresh mount.+ canonicalScroller.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -500 }));+ canonicalScroller.scrollTop = 160;+ canonicalScroller.dispatchEvent(new Event("scroll", { bubbles: true }));+ await frame();+ flushSync(() => host.querySelector<HTMLButtonElement>('[data-session-pane="live-tail"] .jump-latest-btn')!.click());+ set({ activeSessionId: "other-tail", messages: [], isRunning: false,+ retainedSessionIds: ["other-tail"], retainedTranscripts: { "other-tail": [] } });+ await frame();+ assert(!host.querySelector('[data-session-pane="live-tail"]'), "project switch must unmount the original pane");+ messages = [user, tool, { ...answer, content: "Output while the project was hidden." }];+ set({ activeSessionId: "live-tail", messages, isRunning: true,+ retainedSessionIds: ["live-tail", "other-tail"] });+ await until(() => {+ const current = host.querySelector<HTMLElement>('[data-session-pane="live-tail"] .thread-scroll');+ return Boolean(current && Math.abs(current.scrollHeight - current.clientHeight - current.scrollTop) < 2);+ }, "a project return follows output produced while hidden");+ assert(activeLabel() && stop(), "project return must remain visibly running");+ assert(!host.querySelector('[data-session-pane="live-tail"] .jump-latest-btn'),+ "remount must not require a second return-to-latest click");set({ messages: [], selectingSessionId: undefined });await frame();assert(host.querySelector('[data-session-pane="live-tail"] [data-testid="working-indicator"]'),@@ -160,7 +207,8 @@ globalThis.transcriptLiveTailProbe = async () => {} }] });await frame();assert(label()?.textContent === i18n.t("chat.processFailed"), "failure retains its failed status");- return { ok: true, restoredLiveStatus: true, retainedSessionStatus: true, historicalIsolation: true };+ return { ok: true, restoredLiveStatus: true, retainedSessionStatus: true,+ historicalIsolation: true, returnToLatestRetention: true, projectReturnFollow: true };} catch (error) {return { ok: false, error: error instanceof Error ? error.stack : String(error), label: label()?.textContent, stop: Boolean(stop()) };} finally {