graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(native): sidecar wheel scrolls by script — Kuri's mouseWheel dispatch fails on some pages
justrachcfdb83087ee2
diff --git a/apps/native/app/api/browser/route.ts b/apps/native/app/api/browser/route.tsindex e920dbc4..0b88762d 100644--- a/apps/native/app/api/browser/route.ts+++ b/apps/native/app/api/browser/route.ts@@ -1,6 +1,6 @@import { NextRequest } from "next/server";import { matchRef, parseSnapshotRefs, type PinElement } from "@/lib/browser/annotations";-import { hoverExpression, inspectExpression, mapExpression } from "@/lib/browser/inspect-script";+import { hoverExpression, inspectExpression, mapExpression, scrollExpression } from "@/lib/browser/inspect-script";import { ensureKuri, kuriAddress, kuriJson, kuriState, q, stopKuri } from "@/lib/browser/kuri-supervisor";import { normalizeUrl } from "@/lib/browser/url";@@ -238,9 +238,8 @@ async function handle(chat: string, method: string, params: Record<string, unknoawait kuriJson(`/mouse/up${q({ tab_id: tab.id, x, y, button })}`);break;case "wheel":- await kuriJson(- `/mouse/wheel${q({ tab_id: tab.id, x, y, deltaX: Math.round(num(params.deltaX)), deltaY: Math.round(num(params.deltaY)) })}`,- );+ // Not /mouse/wheel: see scrollExpression.+ await evaluate<string>(tab, scrollExpression(x, y, num(params.deltaX), num(params.deltaY)));break;case "key": {const key = String(params.key ?? "");diff --git a/apps/native/lib/browser/inspect-script.ts b/apps/native/lib/browser/inspect-script.tsindex 8c480416..cf125b95 100644--- a/apps/native/lib/browser/inspect-script.ts+++ b/apps/native/lib/browser/inspect-script.ts@@ -141,6 +141,33 @@ export function mapExpression(): string {return compact(MAP_SOURCE);}+/** Scroll the innermost scrollable box under a point, else the page.+ * Kuri's `/mouse/wheel` (CDP `Input.dispatchMouseEvent` mouseWheel) fails+ * on some pages, and a wheel that does nothing is the fastest way to make+ * the pane feel broken; scrolling by script never fails. */+const SCROLL_SOURCE = String.raw`(function (x, y, dx, dy) {+ var el = document.elementFromPoint(x, y);+ while (el && el !== document.body && el !== document.documentElement) {+ var s = getComputedStyle(el);+ if (/(auto|scroll)/.test(s.overflowY + s.overflowX) && (el.scrollHeight > el.clientHeight + 1 || el.scrollWidth > el.clientWidth + 1)) {+ var before = el.scrollTop + el.scrollLeft;+ el.scrollBy(dx, dy);+ if (el.scrollTop + el.scrollLeft !== before) return "box";+ }+ el = el.parentElement;+ }+ window.scrollBy(dx, dy);+ return "page";+})(__X__, __Y__, __DX__, __DY__)`;++export function scrollExpression(x: number, y: number, dx: number, dy: number): string {+ return compact(SCROLL_SOURCE)+ .replace("__X__", String(Math.round(x)))+ .replace("__Y__", String(Math.round(y)))+ .replace("__DX__", String(Math.round(dx)))+ .replace("__DY__", String(Math.round(dy)));+}+/** The same lookup, rect only: what hover needs at ten calls a second. */export const HOVER_SOURCE = String.raw`(function (x, y) {var el = document.elementFromPoint(x, y);diff --git a/plans/2026-09-03-browser-sidecar.md b/plans/2026-09-03-browser-sidecar.mdindex 91232ef3..faab1ae1 100644--- a/plans/2026-09-03-browser-sidecar.md+++ b/plans/2026-09-03-browser-sidecar.md@@ -52,7 +52,17 @@ and hit-tests it in the pane. Hover and pin are local and instant; themap refreshes 350 ms after a scroll settles, every 2.5 s, and onnavigation. Pins are stored in page coordinates against the map's scrolloffset, so they stay on their element when the page scrolls, and the-wheel is forwarded in both modes. The injected overlay stays the right+wheel is forwarded in both modes. Forwarded as a script `scrollBy` on the+innermost scrollable box under the pointer, not as Kuri's `/mouse/wheel`:+that CDP `mouseWheel` dispatch fails outright on some pages (Hacker News+among them), and a wheel that does nothing reads as a broken pane.++Two Kuri facts this surfaced: it segfaults in `CdpClient.send` when two+HTTP connections drive one tab at once (the route now serializes requests+per chat, and a dead Kuri is respawned with the tab put back on its last+address), and its Chrome can outlive it (the supervisor reaps the private+profile's processes on stop, on unexpected exit, and before a spawn). Both+are worth fixing in Kuri itself. The injected overlay stays the rightanswer for a *headed* Chrome window the user clicks in directly; that isa later step.