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): advance history for a gesture at the near-top band
vastsa1bd427ea96d7
diff --git a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.tsindex 14a24d04b..ab17de47f 100644--- a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts+++ b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts@@ -333,12 +333,20 @@ export function useTranscriptScroll({const handleScroll = useCallback(() => {const el = scrollRef.current;if (!el) return;- if (paneVisibleRef.current && transcriptHasLayout(el)) {- lastLaidOutScrollTopRef.current = el.scrollTop;- }+ // A real gesture is never stale noise: the reader's own input took the+ // scroller to the near-top band, and this event is the last one that+ // position produces. Suppressing history continuation here would strand an+ // overflowing transcript at the top until some other scroll event or the+ // minimap control arrived (D269). Only an offset this event did not produce+ // — a collapsed box, or a pinned scroller still about to be restored to the+ // bottom — is read as "not at the top".+ const gesturing = isRecentScrollGesture(+ performance.now(),+ lastScrollGestureAtRef.current,+ );if (paneVisibleRef.current &&- isHistoryRevealPosition(el, pinnedRef.current)+ isHistoryRevealPosition(el, pinnedRef.current && !gesturing)) {reachTop();}@@ -358,10 +366,8 @@ export function useTranscriptScroll({// device pixel ratio leaves behind on programmatic corrections; anything a// gesture produced is compared exactly, so a one-pixel scroll still// unpins.- const gesturing = isRecentScrollGesture(- performance.now(),- lastScrollGestureAtRef.current,- );+ // `gesturing` was read above, before the history-reveal question: a real+ // gesture is what makes a near-top offset the reader's own position.const transition = reduceTranscriptScroll({previousScrollTop: lastScrollTopRef.current,scrollTop: el.scrollTop,diff --git a/apps/desktop/src/lib/transcript-scroll.ts b/apps/desktop/src/lib/transcript-scroll.tsindex 2aa5f82d1..dc8db730f 100644--- a/apps/desktop/src/lib/transcript-scroll.ts+++ b/apps/desktop/src/lib/transcript-scroll.ts@@ -39,7 +39,9 @@ export function transcriptHasLayout(* user is reading the top". A pinned overflowing transcript is at (or about* to be restored to) the bottom; a stale zero offset there must not page the* conversation back to its start. An underfilled pinned tail still advances:- * it does not overflow, so the top boundary is genuinely in view.+ * it does not overflow, so the top boundary is genuinely in view. Callers pass+ * `pinned` only for an offset their own event did not produce: a real gesture+ * is the reader's position, not stale noise, and must still continue history.*/export function isHistoryRevealPosition(geometry: TranscriptScrollerGeometry,diff --git a/apps/desktop/test/session-switch-performance.test.mjs b/apps/desktop/test/session-switch-performance.test.mjsindex f42298c39..4e52bab77 100644--- a/apps/desktop/test/session-switch-performance.test.mjs+++ b/apps/desktop/test/session-switch-performance.test.mjs@@ -48,7 +48,10 @@ test("session reads use a bounded tail and load older pages on demand", () => {// The near-top band is one named constant shared by the scroll check and the// D269 boundary observer, so the two triggers cannot drift apart.assert.match(transcript, /HISTORY_REVEAL_THRESHOLD_PX/);- assert.match(transcript, /isHistoryRevealPosition\(el, pinnedRef\.current\)/);+ assert.match(+ transcript,+ /isHistoryRevealPosition\(el, pinnedRef\.current && !gesturing\)/,+ );// Paging is wired per retained pane (ADR 0137), so each pane requests its own// older pages rather than the surface requesting them for whichever session// happens to be active.diff --git a/apps/desktop/test/transcript-disclosure-reading.test.mjs b/apps/desktop/test/transcript-disclosure-reading.test.mjsindex 2d531c281..15ac5f40a 100644--- a/apps/desktop/test/transcript-disclosure-reading.test.mjs+++ b/apps/desktop/test/transcript-disclosure-reading.test.mjs@@ -127,13 +127,15 @@ test("real input, a new turn and every navigation drop the held position", () =>test("follow records the position the scroller actually reached", () => {// The intended target minus a fractional device pixel ratio was enough to// make the next scroll event look like the reader scrolling up.+ // The auto follow may also record the last laid-out offset beside it, so the+ // guarded body may be a block; the assignment still has to live in one place.assert.match(transcript,- /if \(behavior === "auto"\) lastScrollTopRef\.current = el\.scrollTop;/,+ /if \(behavior === "auto"\) \{?\s*lastScrollTopRef\.current = el\.scrollTop;/,);assert.equal(transcript.match(- /if \(behavior === "auto"\) lastScrollTopRef\.current = el\.scrollTop;/g,+ /if \(behavior === "auto"\) \{?\s*lastScrollTopRef\.current = el\.scrollTop;/g,)?.length,1,);diff --git a/apps/desktop/test/transcript-scroll.test.mjs b/apps/desktop/test/transcript-scroll.test.mjsindex 3bf6ff6c2..ddb41246e 100644--- a/apps/desktop/test/transcript-scroll.test.mjs+++ b/apps/desktop/test/transcript-scroll.test.mjs@@ -161,3 +161,50 @@ test("an unpinned transcript at the top reveals earlier history", () => {false,);});++test("a one-pixel overflow is not a pinned overflowing transcript", () => {+ // The overflow test is deliberately slack by one pixel: a fractional layout+ // can leave a single pixel that no scroll event can retire, and a pinned+ // transcript there is genuinely at its own top.+ assert.equal(+ isHistoryRevealPosition(+ { scrollTop: 0, scrollHeight: 801, clientHeight: 800 },+ true,+ ),+ true,+ );+ assert.equal(+ isHistoryRevealPosition(+ { scrollTop: 0, scrollHeight: 802, clientHeight: 800 },+ true,+ ),+ false,+ );+});++test("a pinned overflowing transcript is suppressed anywhere in the band", () => {+ // The suppression is about the offset being stale, not about it being zero:+ // the caller passes `pinned` only for an offset its own event did not produce.+ assert.equal(+ isHistoryRevealPosition(+ {+ scrollTop: HISTORY_REVEAL_THRESHOLD_PX,+ scrollHeight: 900,+ clientHeight: 800,+ },+ true,+ ),+ false,+ );+ assert.equal(+ isHistoryRevealPosition(+ {+ scrollTop: HISTORY_REVEAL_THRESHOLD_PX + 1,+ scrollHeight: 900,+ clientHeight: 800,+ },+ true,+ ),+ false,+ );+});diff --git a/apps/desktop/test/transcript-window.test.mjs b/apps/desktop/test/transcript-window.test.mjsindex c37b5e810..0953380f4 100644--- a/apps/desktop/test/transcript-window.test.mjs+++ b/apps/desktop/test/transcript-window.test.mjs@@ -210,7 +210,7 @@ test("the transcript bounds mounted history and escalates at the top", () => {// older page once the window already covers it.assert.match(transcript,- /isHistoryRevealPosition\(el, pinnedRef\.current\)/,+ /isHistoryRevealPosition\(el, pinnedRef\.current && !gesturing\)/,);const reachTop = transcript.match(/const reachTop = useCallback\(\(\) => \{([\s\S]*?)\n \}, \[loadOlder, windowSize\]\);/,diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 7bf5aeb57..896c13959 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -304,8 +304,10 @@ may be retained while exactly one workspace supplies the visible shell context.activation no longer resets manual-scroll state for a revisit (ADR 0137).History continuation (D269) does not page earlier rows from a collapsedscroller or from a pinned overflowing transcript whose `scrollTop` has been- reset to 0; an empty first paint does not spend the first-commit hydration- gate, so a later long page still re-bottoms behind the settle veil.+ reset to 0; a real gesture in the near-top band still continues history. An+ empty first paint does not spend the first-commit hydration gate, so a later+ long page is still bounded and re-bottomed in the layout phase, before the+ browser paints it.- Selecting a project-scoped conversation activates its project as part of thestore-owned selection transaction. Selecting a Temporary conversation clearsthe visible workspace. Project-scoped new-session actions pass their targetdiff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.mdindex 1ee8a1119..0f6a3e6cb 100644--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md@@ -246,8 +246,9 @@偏移,而仍然固定在底部的面板重新锚定到底部;对于重新访问,激活不再重置手动滚动状态(ADR 0137)。历史续接(D269)不会把塌缩的滚动容器、或 `scrollTop` 被重置为 0 的已钉住溢出记录当成「在顶部」- 去翻更早的页;空的首帧不会消耗首次提交的水合门闩,因此随后到达的- 长记录仍会在骨架帷幕后面重新吸底。+ 去翻更早的页;落在近顶部带内的真实手势仍会继续载入历史。空的首帧+ 不会消耗首次提交的水合门闩,因此随后到达的长记录仍会被限制挂载,+ 并在布局阶段、浏览器绘制之前重新吸底。- 选择项目范围的对话会激活其项目作为商店自有精选交易。选择临时对话将清除可见的工作空间。项目范围内的新会话操作通过了目标