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): respect control keys and nested scroll ownership
Seraph-x5fac167743a0
diff --git a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.tsindex 063c8d203..26179b162 100644--- a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts+++ b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts@@ -36,7 +36,7 @@ import {TRANSCRIPT_SCROLL_ROUNDING_TOLERANCE_PX,type ScrollInputType,} from "../../../../lib/transcript-scroll";-import { readScrollInputContext } from "../../../../lib/scroll-input";+import { readScrollInputContext, stopSmoothScroll } from "../../../../lib/scroll-input";import { useDisclosureAnchor } from "../../../../hooks/use-disclosure-anchor";import type { TranscriptSearchTarget } from "../../../../lib/transcript-reading";import { useTranscriptSearchFocus } from "../../../../hooks/use-transcript-search-focus";@@ -195,8 +195,7 @@ export function useTranscriptScroll({// Minimap / jump navigation runs in the browser, independently of our// follow rAF. Real input must retire that animation at its current offset// before its queued frames can overwrite the reader's next movement.- const scroller = scrollRef.current;- if (scroller) scroller.scrollTo({ top: scroller.scrollTop, behavior: "instant" });+ stopSmoothScroll(scrollRef.current);cancelReadingPosition();lastScrollGestureAtRef.current = performance.now();// Real input takes the viewport back from a held disclosure position.diff --git a/apps/desktop/src/hooks/use-follow-scroll.ts b/apps/desktop/src/hooks/use-follow-scroll.tsindex ac2e1b95c..0f56decfe 100644--- a/apps/desktop/src/hooks/use-follow-scroll.ts+++ b/apps/desktop/src/hooks/use-follow-scroll.ts@@ -14,7 +14,7 @@ import {TRANSCRIPT_SCROLL_ROUNDING_TOLERANCE_PX,type ScrollInputType,} from "../lib/transcript-scroll";-import { readScrollInputContext } from "../lib/scroll-input";+import { readScrollInputContext, stopSmoothScroll } from "../lib/scroll-input";import type { DisclosureAnchorNotifier } from "../lib/disclosure-anchor-context";import { useDisclosureAnchor } from "./use-disclosure-anchor";@@ -92,6 +92,7 @@ export function useFollowScroll(): FollowScroll {contentRef.current,);if (!isScrollGestureInput(event.type as ScrollInputType, input)) return;+ stopSmoothScroll(scrollRef.current);lastScrollGestureAtRef.current = performance.now();releaseDisclosureAnchor();},diff --git a/apps/desktop/src/lib/scroll-input.ts b/apps/desktop/src/lib/scroll-input.tsindex 71ee82a4b..df347dca3 100644--- a/apps/desktop/src/lib/scroll-input.ts+++ b/apps/desktop/src/lib/scroll-input.ts@@ -22,7 +22,14 @@ const CONTROL_SELECTOR = ["[role='radio']",].join(", ");-const EDITABLE_SELECTOR = "input, textarea, [contenteditable='true']";+const EDITABLE_SELECTOR = "input, textarea, select, [contenteditable='true']";+const SPACE_ACTIVATION_SELECTOR =+ "button, summary, [role='button'], [role='checkbox'], [role='switch'], [role='radio']";++/** Retire browser-owned navigation only after input ownership is established. */+export function stopSmoothScroll(scroller: HTMLElement | null): void {+ if (scroller) scroller.scrollTo({ top: scroller.scrollTop, behavior: "instant" });+}/*** Reads what one DOM input event means for `owner`, a marked scroll container@@ -54,6 +61,8 @@ export function readScrollInputContext(context.editable =target instanceof Element &&target.closest(EDITABLE_SELECTOR) !== null;+ context.controlOwnsKey = event.key === " " && target instanceof Element &&+ target.closest(SPACE_ACTIVATION_SELECTOR) !== null;return context;}if (event.type === "pointerdown") {diff --git a/apps/desktop/src/lib/transcript-scroll.ts b/apps/desktop/src/lib/transcript-scroll.tsindex dc8db730f..93a988fd7 100644--- a/apps/desktop/src/lib/transcript-scroll.ts+++ b/apps/desktop/src/lib/transcript-scroll.ts@@ -147,8 +147,10 @@ export type ScrollInputType =export type ScrollInputContext = {/** Pressed key, for a `keydown`. */key?: string;- /** The key event came from a text field, which owns its own key input. */+ /** The key event came from a field/select that owns its own key input. */editable?: boolean;+ /** The focused control consumes this key as activation or selection. */+ controlOwnsKey?: boolean;/*** A nearer, scrollable owner sits between the event target and this one, so* that owner consumes the input (`overscroll-behavior: contain` keeps it@@ -196,7 +198,7 @@ export function isScrollGestureInput(if (context.nestedOwner) return false;if (type === "pointerdown") return context.pointerOnScrollSurface === true;if (type === "keydown") {- if (context.editable) return false;+ if (context.editable || context.controlOwnsKey) return false;return context.key !== undefined && SCROLL_GESTURE_KEYS.has(context.key);}return true;diff --git a/apps/desktop/test/disclosure-anchor.test.mjs b/apps/desktop/test/disclosure-anchor.test.mjsindex bc60c31d0..8f381e4b2 100644--- a/apps/desktop/test/disclosure-anchor.test.mjs+++ b/apps/desktop/test/disclosure-anchor.test.mjs@@ -177,6 +177,7 @@ test("a scroll key is a gesture, and Space stays a button activation", () => {assert.equal(isScrollGestureInput("keydown", { key: "PageDown" }), true);assert.equal(isScrollGestureInput("keydown", { key: "Home" }), true);assert.equal(isScrollGestureInput("keydown", { key: " " }), true);+ assert.equal(isScrollGestureInput("keydown", { key: " ", controlOwnsKey: true }), false);assert.equal(SCROLL_GESTURE_KEYS.has("ArrowDown"), true);assert.equal(isScrollGestureInput("keydown", { key: "a" }), false);assert.equal(isScrollGestureInput("keydown", {}), false);diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 4951cd640..4607d91fe 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -858,6 +858,11 @@ reading surface of the workstation.collapses when the draft clears, indicator rows mount or unmount — arere-baselined and never cancel follow, so a pinned send stays at the latestturn even when the bottom reserve changes mid-turn+- Transcript and delegated scrollers cancel browser-owned smooth navigation+ only for input they own. Button Space activation, select keys and input+ consumed by a nested scroller do not request ancestor cancellation. Normal+ turn-completion prompt navigation retains its smooth motion when follow is+ released after starting it (interaction patterns §2.2).- The tail runtime status owns one reserved lane. The transcript reserves theheight of a single `Working…` / planning / run-activity row for the wholerunning turn, so the status appearing between two tool rows, or clearing whendiff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 7216555bc..82754eea9 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -775,6 +775,10 @@ may be retained while exactly one workspace supplies the visible shell context.navigation at its current offset. A previous minimap or jump navigation mustnot resume after the reader takes over; nested-scroll input and ordinary rowcontrols do not cancel the transcript's navigation.+ Space on a button activates that button, and selection keys inside a select+ belong to the select. The same ownership and cancellation rules apply to+ delegated transcript scrollers. Releasing follow after a completed turn's+ prompt navigation does not cancel that newly started navigation.- 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 modediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 683785816..1c6f1b18e 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -37,6 +37,13 @@- **Expected:** Input stops the old browser animation at the current offset;later frames cannot move the reader toward its stale destination. Streaming,disclosure anchoring, pinned follow, and long-history work budgets still pass.+- Repeat owned wheel, scroll-key, scrollbar-surface and touch inputs in the+ main and delegated scrollers. Observe real browser calls to distinguish+ application cancellation from Chromium's own pointer behavior. Button Space,+ button presses, select arrows and nested wheel input must not request an+ ancestor cancellation. Button Space must allow the original navigation to+ finish. `e2e-transcript-turn-completion.mjs` also verifies normal completed-turn+ prompt navigation and a reader's manually retained position.- **Coverage:** `node scripts/e2e-transcript-disclosure-anchor.mjs` and`node scripts/e2e-transcript-render.mjs`.- **Specs:** Interaction patterns §2.2. **Milestone:** Maintenance.diff --git a/scripts/e2e/scroll-input-ownership.ts b/scripts/e2e/scroll-input-ownership.tsnew file mode 100644index 000000000..1a89dc412--- /dev/null+++ b/scripts/e2e/scroll-input-ownership.ts@@ -0,0 +1,71 @@+function assert(value: unknown, message: string): asserts value {+ if (!value) throw new Error(message);+}++/** Exercise the real owner's listeners; synthetic inputs have no default move. */+export function probeScrollInputOwnership(scroller: HTMLElement) {+ const controls = document.createElement("div");+ controls.style.cssText = "position:absolute;width:100px;height:100px";+ const button = document.createElement("button");+ button.textContent = "Fixture control";+ const select = document.createElement("select");+ select.append(document.createElement("option"));+ const nested = document.createElement("div");+ nested.dataset.scrollOwner = "fixture-nested";+ nested.style.cssText = "height:20px;overflow:auto";+ const filler = document.createElement("div");+ filler.style.height = "100px";+ nested.append(filler);+ controls.append(button, select, nested);+ scroller.append(controls);+ const checks: string[] = [];+ const nativeScrollTo = scroller.scrollTo;+ const executeScrollTo = nativeScrollTo.bind(scroller);+ let observingInput = false;+ let cancellations = 0;+ // Observe the browser boundary while still executing every real scroll.+ // Chromium may itself abort an animation on pointer input; that is distinct+ // from the application wrongly attributing a control's input to this owner.+ scroller.scrollTo = (options?: ScrollToOptions | number, y?: number) => {+ if (observingInput && typeof options === "object" && options.behavior === "instant") cancellations++;+ if (typeof options === "number") executeScrollTo(options, y ?? 0);+ else executeScrollTo(options ?? {});+ };+ try {+ const cases = [+ { name: "wheel", target: scroller, event: () => new WheelEvent("wheel", { bubbles: true, deltaY: -1 }), interrupts: true },+ { name: "scroll key", target: scroller, event: () => new KeyboardEvent("keydown", { bubbles: true, key: "PageUp" }), interrupts: true },+ { name: "scroll surface press", target: scroller, event: () => new PointerEvent("pointerdown", { bubbles: true }), interrupts: true },+ { name: "touch start", target: scroller, event: () => new Event("touchstart", { bubbles: true }), interrupts: true },+ { name: "touch move", target: scroller, event: () => new Event("touchmove", { bubbles: true }), interrupts: true },+ { name: "button Space", target: button, event: () => new KeyboardEvent("keydown", { bubbles: true, key: " " }), interrupts: false },+ { name: "button press", target: button, event: () => new PointerEvent("pointerdown", { bubbles: true }), interrupts: false },+ { name: "select ArrowDown", target: select, event: () => new KeyboardEvent("keydown", { bubbles: true, key: "ArrowDown" }), interrupts: false },+ { name: "nested wheel", target: nested, event: () => new WheelEvent("wheel", { bubbles: true, deltaY: -1 }), interrupts: false },+ ];+ for (const scenario of cases) {+ // Explicit reader input releases any held disclosure before navigation.+ scroller.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -1 }));+ scroller.scrollTo({ top: 120, behavior: "instant" });+ scroller.dispatchEvent(new Event("scroll", { bubbles: true }));+ const top = scroller.scrollTop;+ assert(top > 1, `${scenario.name}: fixture has no scroll range`);+ scroller.scrollTo({ top: 0, behavior: "smooth" });+ cancellations = 0;+ observingInput = true;+ scenario.target.dispatchEvent(scenario.event());+ observingInput = false;+ assert(scenario.interrupts ? cancellations === 1 : cancellations === 0,+ `${scenario.name}: application requested ${cancellations} cancellations`);+ if (scenario.interrupts) {+ assert(Math.abs(scroller.scrollTop - top) < 2,+ `${scenario.name}: cancellation changed the reader's current offset`);+ }+ checks.push(scenario.name);+ }+ return checks;+ } finally {+ scroller.scrollTo = nativeScrollTo;+ controls.remove();+ }+}diff --git a/scripts/e2e/transcript-disclosure-anchor.tsx b/scripts/e2e/transcript-disclosure-anchor.tsxindex 34fcb8a74..9a4fecddd 100644--- a/scripts/e2e/transcript-disclosure-anchor.tsx+++ b/scripts/e2e/transcript-disclosure-anchor.tsx@@ -10,6 +10,7 @@ import { DisclosureAnchorContext } from "../../apps/desktop/src/lib/disclosure-aimport { useTranscriptScroll } from "../../apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll";import { ToolRow } from "../../apps/desktop/src/features/chat/transcript/ToolRow";import { useFollowScroll } from "../../apps/desktop/src/hooks/use-follow-scroll";+import { probeScrollInputOwnership } from "./scroll-input-ownership";declare global {var transcriptDisclosureProbe: () => Promise<unknown>;@@ -700,10 +701,48 @@ globalThis.transcriptDisclosureProbe = async () => {assert(Math.abs(interruptScroller.scrollTop - interruptedTop) < 2,`interrupted navigation moved the reader: ${interruptedTop} -> ${interruptScroller.scrollTop}`);}+ const interruptionResult = { interruptedTop, finalTop: interruptScroller.scrollTop };+ // Space activates a focused disclosure button; it does not scroll its+ // ancestor. A synthetic key has no default activation, isolating ownership.+ interruptScroller.scrollTo({ top: 0, behavior: "smooth" });+ interruptTitle.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true }));+ const controlDeadline = performance.now() + 5000;+ while (interruptScroller.scrollTop > 1 && performance.now() < controlDeadline) {+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));+ }+ assert(interruptScroller.scrollTop <= 1,+ `button Space cancelled transcript navigation at ${interruptScroller.scrollTop}`);+ const nestedInterruption = mount(<FollowFixture tool={toolRowMessage("interrupt-dock")} />);+ const nestedScroller = nestedInterruption.querySelector<HTMLElement>(".subagent-run-rows")!;+ const nestedContent = nestedInterruption.querySelector<HTMLElement>("[data-layout-content]")!;+ const nestedTitle = nestedInterruption.querySelector<HTMLElement>(".tool-row-header")!;+ await waitForLayout({ label: "nested interruption mount", scroller: nestedScroller,+ content: nestedContent, title: nestedTitle,+ expected: () => nestedTitle.isConnected, direction: "initial" });+ await waitForLayout({ label: "nested interruption disclosure", scroller: nestedScroller,+ content: nestedContent, title: nestedTitle,+ expected: () => nestedTitle.getAttribute("aria-expanded") === "true", direction: "grow",+ trigger: () => nestedTitle.click() });+ const nestedTop = nestedScroller.scrollTop;+ assert(nestedTop > 0, "nested fixture has no scroll range");+ nestedScroller.scrollTo({ top: 0, behavior: "smooth" });+ nestedScroller.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -1 }));+ for (let frame = 0; frame < 6; frame++) {+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));+ assert(Math.abs(nestedScroller.scrollTop - nestedTop) < 2,+ `interrupted nested navigation moved the reader: ${nestedTop} -> ${nestedScroller.scrollTop}`);+ }+ const nestedInterruptionResult = { interruptedTop: nestedTop, finalTop: nestedScroller.scrollTop };+ const inputOwnership = {+ transcript: probeScrollInputOwnership(interruptScroller),+ nested: probeScrollInputOwnership(nestedScroller),+ };assert(renderErrors.length === 0, `React render errors: ${renderErrors.map(String).join("; ")}`);return {ok: true,- interruption: { interruptedTop, finalTop: interruptScroller.scrollTop },+ inputOwnership,+ interruption: interruptionResult,+ nestedInterruption: nestedInterruptionResult,process: { before: processBefore, collapsed: processCollapsed, expanded: processExpanded },rapid: { before: rapidBefore, expanded: rapidExpanded },transcript: { before, expanded, collapsed },