Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ui): glide an outlined cursor onto browser clicks

rubenluetke10-beep3194ba611689
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentBrowserPreview.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentBrowserPreview.tsx
index c8efe04fdd..683e7de680 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentBrowserPreview.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentBrowserPreview.tsx
@@ -10,7 +10,7 @@ import { BrandedSelect } from "@/components/ui/select";
import type { SocietyAgent } from "../data";
import { useBrowserInstallStatus } from "../cardData";
import { useBrowserView } from "./useBrowserView";
-import { BrowserPointer } from "./BrowserPointer";
+import { AgentCursor } from "./AgentCursor";
import "./agentCard.css";
export function AgentBrowserPreview({ agent }: { agent: SocietyAgent }) {
@@ -92,7 +92,7 @@ export function AgentBrowserPreview({ agent }: { agent: SocietyAgent }) {
control("key", { key: [...modifiers, e.key].join("+") });
}
}} />
- <BrowserPointer pointer={state.ready && state.connected && !state.manual ? state.pointer : undefined} />
+ <AgentCursor pointer={state.ready && state.connected && !state.manual ? state.pointer : undefined} />
{!state.ready && <div className="absolute inset-0 grid place-items-center bg-muted p-3 text-center text-xs text-muted-foreground">
{install.data?.detail || status}
{install.data?.running && <span>{install.data.percent}%</span>}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.test.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.test.tsx
new file mode 100644
index 0000000000..e0de9c63f0
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.test.tsx
@@ -0,0 +1,83 @@
+import { act, cleanup, render, screen } from "@testing-library/react";
+import { afterEach, expect, test, vi } from "vitest";
+import { AgentCursor } from "./AgentCursor";
+import { easeOutCubic, glideDurationMs } from "./agentCursorMotion";
+import type { BrowserPointerState } from "./browserPointerState";
+
+afterEach(() => {
+ cleanup();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+function installFrame() {
+ let now = 5000;
+ const frames: FrameRequestCallback[] = [];
+ vi.spyOn(performance, "now").mockImplementation(() => now);
+ vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
+ frames.push(callback);
+ return frames.length;
+ });
+ vi.stubGlobal("cancelAnimationFrame", () => {});
+ vi.stubGlobal("ResizeObserver", class {
+ observe() {}
+ disconnect() {}
+ });
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(640);
+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(480);
+ return {
+ frames,
+ at(time: number) { now = time; },
+ };
+}
+
+const here = (over: Partial<BrowserPointerState> = {}): BrowserPointerState => ({
+ x: 100, y: 200, width: 1280, height: 800, click_id: 1, click_x: 100, click_y: 200, ...over,
+});
+
+test("the arrow sits on the pictured point and marks a click that is already there", () => {
+ installFrame();
+ render(<AgentCursor pointer={here()} />);
+ const arrow = screen.getByTestId("browser-agent-pointer");
+ expect(arrow.style.transform).toBe("translate3d(50px, 140px, 0)");
+ expect(screen.getAllByTestId("browser-click-mark")).toHaveLength(1);
+ expect(arrow.querySelector("path")?.getAttribute("fill")).toBe("#FFFFFF");
+ expect(arrow.querySelector("path")?.getAttribute("stroke")).toBe("#0A0A0A");
+});
+
+test("the arrow glides to the next click and only then presses", () => {
+ const clock = installFrame();
+ const { rerender } = render(<AgentCursor pointer={here()} />);
+ rerender(<AgentCursor pointer={here({ x: 600, click_id: 2, click_x: 600 })} />);
+ const arrow = screen.getByTestId("browser-agent-pointer");
+ expect(arrow.dataset.x).toBe("100");
+ expect(screen.getAllByTestId("browser-click-mark")).toHaveLength(1);
+ const duration = glideDurationMs(250);
+ act(() => { clock.frames.at(-1)?.(5000 + duration / 2); });
+ expect(Number(arrow.dataset.x)).toBeCloseTo(100 + 500 * easeOutCubic(0.5), 1);
+ act(() => { clock.frames.at(-1)?.(5000 + duration); });
+ expect(Number(arrow.dataset.x)).toBeCloseTo(600, 1);
+ expect(screen.getAllByTestId("browser-click-mark")).toHaveLength(2);
+});
+
+test("reduced motion puts the arrow on the button without a glide", () => {
+ installFrame();
+ vi.stubGlobal("matchMedia", (query: string) => ({
+ matches: query.includes("reduce"),
+ media: query,
+ addEventListener() {},
+ removeEventListener() {},
+ dispatchEvent() { return false; },
+ }));
+ const { rerender } = render(<AgentCursor pointer={here()} />);
+ rerender(<AgentCursor pointer={here({ x: 600, click_id: 2, click_x: 600 })} />);
+ expect(screen.getByTestId("browser-agent-pointer").dataset.x).toBe("600");
+ expect(screen.getAllByTestId("browser-click-mark")).toHaveLength(2);
+});
+
+test("the arrow leaves when the agent is no longer driving", () => {
+ installFrame();
+ const { rerender } = render(<AgentCursor pointer={here()} />);
+ rerender(<AgentCursor />);
+ expect(screen.queryByTestId("browser-agent-pointer")).toBeNull();
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.tsx
new file mode 100644
index 0000000000..240fed84cf
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentCursor.tsx
@@ -0,0 +1,201 @@
+import { useLayoutEffect, useRef, useState } from "react";
+import "./agentCursor.css";
+import {
+ aimCursor,
+ beginCursor,
+ projectFramePoint,
+ stepCursor,
+ type CursorClick,
+ type CursorMotion,
+} from "./agentCursorMotion";
+import type { BrowserPointerState } from "./browserPointerState";
+
+/** Hotspot of the arrow tip, in the SVG's own pixels. */
+const TIP_X = 7.2;
+const TIP_Y = 2.4;
+
+interface ViewBox {
+ hostW: number;
+ hostH: number;
+ frameW: number;
+ frameH: number;
+}
+
+interface Mark {
+ id: number;
+ x: number;
+ y: number;
+}
+
+function reducedMotion(): boolean {
+ return typeof window.matchMedia === "function"
+ && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
+}
+
+function px(value: number): string {
+ return String(Math.round(value * 100) / 100);
+}
+
+/**
+ * Arrow drawn over the live browser. The agent reports the point it clicked;
+ * the arrow eases there from wherever it already is, then presses.
+ */
+export function AgentCursor({ pointer }: { pointer?: BrowserPointerState }) {
+ const hostRef = useRef<HTMLDivElement>(null);
+ const cursorRef = useRef<HTMLDivElement>(null);
+ const motionRef = useRef<CursorMotion | null>(null);
+ const viewRef = useRef<ViewBox>({ hostW: 0, hostH: 0, frameW: 0, frameH: 0 });
+ const loopRef = useRef(0);
+ const loopingRef = useRef(false);
+ const aliveRef = useRef(true);
+ const timersRef = useRef<number[]>([]);
+ const tickRef = useRef<(now: number) => void>(() => {});
+ const [marks, setMarks] = useState<Mark[]>([]);
+ const [pressId, setPressId] = useState(0);
+
+ const writeCursor = () => {
+ const node = cursorRef.current;
+ const motion = motionRef.current;
+ if (!node || !motion) return;
+ const view = viewRef.current;
+ const point = projectFramePoint(motion.x, motion.y, view.frameW, view.frameH, view.hostW, view.hostH);
+ node.style.transform = `translate3d(${px(point.x)}px, ${px(point.y)}px, 0)`;
+ node.dataset.x = String(motion.x);
+ node.dataset.y = String(motion.y);
+ };
+
+ const showClick = (click: CursorClick) => {
+ if (!aliveRef.current || click.id <= 0) return;
+ const view = viewRef.current;
+ const point = projectFramePoint(click.x, click.y, view.frameW, view.frameH, view.hostW, view.hostH);
+ setPressId(click.id);
+ setMarks((current) => (
+ current.some((mark) => mark.id === click.id)
+ ? current
+ : [...current.slice(-3), { id: click.id, x: point.x, y: point.y }]
+ ));
+ const drop = window.setTimeout(() => {
+ if (!aliveRef.current) return;
+ setMarks((current) => current.filter((mark) => mark.id !== click.id));
+ }, 480);
+ timersRef.current.push(drop);
+ };
+
+ tickRef.current = (now: number) => {
+ const motion = motionRef.current;
+ if (!aliveRef.current || !motion) {
+ loopingRef.current = false;
+ return;
+ }
+ const stepped = stepCursor(motion, now);
+ motionRef.current = stepped.motion;
+ writeCursor();
+ if (stepped.arrivedClick) showClick(stepped.arrivedClick);
+ if (stepped.moving && aliveRef.current) {
+ loopRef.current = requestAnimationFrame((time) => tickRef.current(time));
+ } else {
+ loopingRef.current = false;
+ }
+ };
+
+ useLayoutEffect(() => {
+ aliveRef.current = true;
+ const host = hostRef.current;
+ if (!host) return;
+ const measure = () => {
+ viewRef.current.hostW = host.clientWidth;
+ viewRef.current.hostH = host.clientHeight;
+ writeCursor();
+ };
+ measure();
+ if (typeof ResizeObserver === "undefined") {
+ return () => { aliveRef.current = false; };
+ }
+ const observer = new ResizeObserver(measure);
+ observer.observe(host);
+ return () => {
+ aliveRef.current = false;
+ observer.disconnect();
+ cancelAnimationFrame(loopRef.current);
+ loopingRef.current = false;
+ for (const timer of timersRef.current) window.clearTimeout(timer);
+ };
+ }, []);
+
+ useLayoutEffect(() => {
+ if (!pointer) {
+ motionRef.current = null;
+ cancelAnimationFrame(loopRef.current);
+ loopingRef.current = false;
+ return;
+ }
+ viewRef.current.frameW = pointer.width;
+ viewRef.current.frameH = pointer.height;
+ const now = performance.now();
+ if (!motionRef.current) motionRef.current = beginCursor(pointer.x, pointer.y, now);
+ const view = viewRef.current;
+ const scale = projectFramePoint(0, 0, view.frameW, view.frameH, view.hostW, view.hostH).scale;
+ const distance = Math.hypot(
+ (pointer.x - motionRef.current.x) * scale,
+ (pointer.y - motionRef.current.y) * scale,
+ );
+ const aimed = aimCursor(motionRef.current, {
+ x: pointer.x,
+ y: pointer.y,
+ clickId: pointer.click_id,
+ clickX: pointer.click_x,
+ clickY: pointer.click_y,
+ }, distance, now, reducedMotion());
+ motionRef.current = aimed.motion;
+ if (aimed.releaseClick) showClick(aimed.releaseClick);
+ if (aimed.changed) {
+ const stepped = stepCursor(aimed.motion, now);
+ motionRef.current = stepped.motion;
+ if (stepped.arrivedClick) showClick(stepped.arrivedClick);
+ if (stepped.moving && !loopingRef.current) {
+ loopingRef.current = true;
+ loopRef.current = requestAnimationFrame((time) => tickRef.current(time));
+ }
+ }
+ writeCursor();
+ }, [pointer]);
+
+ return (
+ <div ref={hostRef} className="agent-cursor-layer" aria-hidden="true" data-testid="browser-pointer-layer">
+ {marks.map((mark) => (
+ <span
+ key={mark.id}
+ className="agent-cursor-click"
+ style={{ transform: `translate3d(${px(mark.x)}px, ${px(mark.y)}px, 0)` }}
+ data-testid="browser-click-mark"
+ >
+ <span className="agent-cursor-dot" />
+ <span className="agent-cursor-ring" />
+ </span>
+ ))}
+ {pointer && (
+ <div ref={cursorRef} className="agent-cursor" data-testid="browser-agent-pointer">
+ <div className="agent-cursor-shift" style={{ transform: `translate(${-TIP_X}px, ${-TIP_Y}px)` }}>
+ <div
+ key={pressId}
+ className="agent-cursor-art"
+ data-pressing={pressId > 0 ? "true" : "false"}
+ style={{ transformOrigin: `${TIP_X}px ${TIP_Y}px` }}
+ >
+ <svg className="agent-cursor-arrow" width="34" height="42" viewBox="0 0 34 42" fill="none">
+ <path
+ d="M7.2 2.4 L4.6 28.8 L11.2 24.2 L15.4 39.2 L20.2 36.6 L16.2 22.2 L31.2 21.2 Z"
+ fill="#FFFFFF"
+ stroke="#0A0A0A"
+ strokeWidth="1.9"
+ strokeLinejoin="round"
+ strokeLinecap="round"
+ />
+ </svg>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.test.tsx b/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.test.tsx
deleted file mode 100644
index 7fa1f2333d..0000000000
--- a/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.test.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { afterEach, expect, test, vi } from "vitest";
-import { cleanup, render, screen } from "@testing-library/react";
-import { BrowserPointer } from "./BrowserPointer";
-
-afterEach(() => { cleanup(); vi.restoreAllMocks(); });
-
-test("cursor uses frame coordinates with letterboxing and preserves a single click pulse", () => {
- vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(640);
- vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(480);
- const pointer = { x: 100, y: 200, width: 1280, height: 800, click_id: 1, click_x: 100, click_y: 200 };
- const { rerender } = render(<BrowserPointer pointer={pointer} />);
- expect(screen.getByTestId("browser-agent-pointer").style.left).toBe("50px");
- expect(screen.getByTestId("browser-agent-pointer").style.top).toBe("140px");
- const click = screen.getByTestId("browser-click-mark");
- rerender(<BrowserPointer pointer={{ ...pointer, x: 200 }} />);
- expect(screen.getByTestId("browser-click-mark")).toBe(click);
- rerender(<BrowserPointer />);
- expect(screen.queryByTestId("browser-agent-pointer")).toBeNull();
-});
diff --git a/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.tsx b/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.tsx
deleted file mode 100644
index ae34eeb2d7..0000000000
--- a/jarvis/ui/web/frontend/src/components/society/card/BrowserPointer.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-import { useLayoutEffect, useRef, useState } from "react";
-import "./browserPointer.css";
-
-export interface BrowserPointerState {
- x: number;
- y: number;
- width: number;
- height: number;
- click_id: number;
- click_x: number;
- click_y: number;
-}
-
-/** A new vector mark driven by actual agent mouse events, never the OS cursor. */
-export function BrowserPointer({ pointer }: { pointer?: BrowserPointerState }) {
- const host = useRef<HTMLDivElement>(null);
- const [size, setSize] = useState({ width: 0, height: 0 });
- useLayoutEffect(() => {
- const el = host.current;
- if (!el) return;
- const measure = () => setSize({ width: el.clientWidth, height: el.clientHeight });
- measure();
- if (typeof ResizeObserver === "undefined") return;
- const observer = new ResizeObserver(measure);
- observer.observe(el);
- return () => observer.disconnect();
- }, []);
- const scale = pointer ? Math.min(size.width / pointer.width, size.height / pointer.height) : 0;
- const point = (x: number, y: number) => ({
- left: (size.width - pointer!.width * scale) / 2 + x * scale,
- top: (size.height - pointer!.height * scale) / 2 + y * scale,
- });
- return <div ref={host} className="jarvis-browser-pointer-layer" aria-hidden="true" data-testid="browser-pointer-layer">
- {pointer && scale > 0 && <>
- {pointer.click_id > 0 && <span key={pointer.click_id} className="jarvis-browser-click"
- style={point(pointer.click_x, pointer.click_y)} data-testid="browser-click-mark" />}
- <span className="jarvis-browser-pointer" style={point(pointer.x, pointer.y)} data-testid="browser-agent-pointer">
- <svg width="24" height="30" viewBox="0 0 24 30" fill="none">
- <path d="M3 3L20 15L12 17L8 25L3 3Z"
- fill="var(--browser-pointer-fill)" stroke="var(--browser-pointer-edge)" strokeWidth="2" strokeLinejoin="round" />
- <path d="M12 17L17 25" stroke="var(--browser-pointer-edge)" strokeWidth="5" strokeLinecap="round" />
- <path d="M12 17L17 25" stroke="var(--browser-pointer-fill)" strokeWidth="2.5" strokeLinecap="round" />
- </svg>
- <span className="jarvis-browser-pointer-label"><span className="jarvis-browser-pointer-dot" />Jarvis</span>
- </span>
- </>}
- </div>;
-}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/agentCursor.css b/jarvis/ui/web/frontend/src/components/society/card/agentCursor.css
new file mode 100644
index 0000000000..ffb94d5257
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/agentCursor.css
@@ -0,0 +1,80 @@
+.agent-cursor-layer {
+ position: absolute;
+ inset: 0;
+ overflow: hidden;
+ pointer-events: none;
+}
+
+.agent-cursor,
+.agent-cursor-click {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 0;
+ height: 0;
+ pointer-events: none;
+}
+
+.agent-cursor {
+ z-index: 2;
+ animation: agent-cursor-in 90ms ease-out;
+ will-change: transform;
+}
+
+.agent-cursor-click {
+ z-index: 1;
+}
+
+.agent-cursor-art {
+ filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
+}
+
+.agent-cursor-art[data-pressing="true"] {
+ animation: agent-cursor-press 110ms ease-out;
+}
+
+.agent-cursor-arrow {
+ display: block;
+ overflow: visible;
+}
+
+.agent-cursor-dot {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 8px;
+ height: 8px;
+ margin: -4px 0 0 -4px;
+ border-radius: 50%;
+ background: #0a0a0a;
+ box-shadow: 0 0 0 1.5px #ffffff;
+}
+
+.agent-cursor-ring {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 22px;
+ height: 22px;
+ margin: -11px 0 0 -11px;
+ border: 2px solid #0a0a0a;
+ border-radius: 50%;
+ box-shadow: 0 0 0 1.5px #ffffff;
+ animation: agent-cursor-ring 420ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
+}
+
+@keyframes agent-cursor-in {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+@keyframes agent-cursor-press {
+ 0% { transform: scale(1); }
+ 45% { transform: scale(0.9); }
+ 100% { transform: scale(1); }
+}
+
+@keyframes agent-cursor-ring {
+ from { transform: scale(0.45); opacity: 0.95; }
+ to { transform: scale(1.85); opacity: 0; }
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.test.ts b/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.test.ts
new file mode 100644
index 0000000000..85fed88e14
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.test.ts
@@ -0,0 +1,81 @@
+import { describe, expect, test } from "vitest";
+import {
+ aimCursor,
+ beginCursor,
+ easeOutCubic,
+ glideDurationMs,
+ projectFramePoint,
+ stepCursor,
+} from "./agentCursorMotion";
+
+describe("agent cursor motion", () => {
+ test("keeps a short hop visible and a long move quick", () => {
+ expect(glideDurationMs(0)).toBe(0);
+ expect(glideDurationMs(40)).toBe(130);
+ expect(glideDurationMs(250)).toBe(180);
+ expect(glideDurationMs(2000)).toBe(340);
+ });
+
+ test("eases out so the arrow is still moving as it arrives", () => {
+ expect(easeOutCubic(0)).toBe(0);
+ expect(easeOutCubic(1)).toBe(1);
+ expect(easeOutCubic(0.5)).toBeCloseTo(0.875, 5);
+ });
+
+ test("places a page point inside the letterboxed picture", () => {
+ const point = projectFramePoint(100, 200, 1280, 800, 640, 480);
+ expect(point.scale).toBe(0.5);
+ expect(point.x).toBe(50);
+ expect(point.y).toBe(140);
+ });
+
+ test("a new target starts from where the arrow is, not from the old destination", () => {
+ const parked = { ...beginCursor(100, 80, 1000), x: 140, y: 90, toX: 180, toY: 90 };
+ const aimed = aimCursor(parked, {
+ x: 400, y: 90, clickId: 2, clickX: 400, clickY: 90,
+ }, 200, 1500, false);
+ expect(aimed.motion.fromX).toBe(140);
+ expect(aimed.motion.x).toBe(140);
+ expect(aimed.motion.toX).toBe(400);
+ expect(aimed.motion.duration).toBe(glideDurationMs(200));
+ const halfway = stepCursor(aimed.motion, 1500 + aimed.motion.duration / 2);
+ expect(halfway.motion.x).toBeCloseTo(140 + (400 - 140) * 0.875, 4);
+ expect(halfway.arrivedClick).toBeNull();
+ expect(halfway.moving).toBe(true);
+ const landed = stepCursor(halfway.motion, 1500 + aimed.motion.duration);
+ expect(landed.motion.x).toBeCloseTo(400, 4);
+ expect(landed.arrivedClick?.id).toBe(2);
+ expect(landed.moving).toBe(false);
+ });
+
+ test("a second report of the same point does not restart the glide", () => {
+ const moving = aimCursor(beginCursor(10, 10, 0), {
+ x: 80, y: 10, clickId: 0, clickX: 0, clickY: 0,
+ }, 70, 20, false).motion;
+ const again = aimCursor(moving, {
+ x: 80, y: 10, clickId: 0, clickX: 0, clickY: 0,
+ }, 70, 40, false);
+ expect(again.changed).toBe(false);
+ expect(again.motion.start).toBe(20);
+ });
+
+ test("reduced motion puts the arrow on the button immediately", () => {
+ const aimed = aimCursor(beginCursor(0, 0, 0), {
+ x: 300, y: 40, clickId: 1, clickX: 300, clickY: 40,
+ }, 300, 10, true);
+ expect(aimed.motion.x).toBe(300);
+ expect(aimed.motion.duration).toBe(0);
+ expect(stepCursor(aimed.motion, 10).arrivedClick?.id).toBe(1);
+ });
+
+ test("leaving a click early still marks that click", () => {
+ const pressing = aimCursor(beginCursor(0, 0, 0), {
+ x: 50, y: 20, clickId: 4, clickX: 50, clickY: 20,
+ }, 80, 5, false).motion;
+ const left = aimCursor(pressing, {
+ x: 180, y: 20, clickId: 4, clickX: 50, clickY: 20,
+ }, 90, 12, false);
+ expect(left.releaseClick?.id).toBe(4);
+ expect(left.motion.pendingClick).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.ts b/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.ts
new file mode 100644
index 0000000000..35d142a255
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/agentCursorMotion.ts
@@ -0,0 +1,167 @@
+/**
+ * Travel time for the agent cursor.
+ *
+ * A short hop stays on screen long enough to see (never a one-frame jump)
+ * and a move across the whole picture still lands within about a third of
+ * a second. The ease settles onto the button instead of stopping dead.
+ */
+export const GLIDE_MIN_MS = 130;
+export const GLIDE_MAX_MS = 340;
+
+export interface CursorClick {
+ id: number;
+ x: number;
+ y: number;
+}
+
+export interface CursorMotion {
+ x: number;
+ y: number;
+ fromX: number;
+ fromY: number;
+ toX: number;
+ toY: number;
+ start: number;
+ duration: number;
+ clickId: number;
+ pendingClick: CursorClick | null;
+}
+
+export interface CursorTarget {
+ x: number;
+ y: number;
+ clickId: number;
+ clickX: number;
+ clickY: number;
+}
+
+export interface AimResult {
+ motion: CursorMotion;
+ changed: boolean;
+ releaseClick: CursorClick | null;
+}
+
+export function glideDurationMs(distancePx: number): number {
+ if (!Number.isFinite(distancePx) || distancePx < 1) return 0;
+ return Math.min(GLIDE_MAX_MS, Math.max(GLIDE_MIN_MS, 110 + distancePx * 0.28));
+}
+
+export function easeOutCubic(t: number): number {
+ const clamped = Math.min(1, Math.max(0, t));
+ const remaining = 1 - clamped;
+ return 1 - remaining * remaining * remaining;
+}
+
+export function projectFramePoint(
+ frameX: number,
+ frameY: number,
+ frameW: number,
+ frameH: number,
+ hostW: number,
+ hostH: number,
+): { x: number; y: number; scale: number } {
+ if (frameW <= 0 || frameH <= 0 || hostW <= 0 || hostH <= 0) {
+ return { x: frameX, y: frameY, scale: 1 };
+ }
+ const scale = Math.min(hostW / frameW, hostH / frameH);
+ return {
+ x: (hostW - frameW * scale) / 2 + frameX * scale,
+ y: (hostH - frameH * scale) / 2 + frameY * scale,
+ scale,
+ };
+}
+
+export function beginCursor(x: number, y: number, now: number): CursorMotion {
+ return {
+ x,
+ y,
+ fromX: x,
+ fromY: y,
+ toX: x,
+ toY: y,
+ start: now,
+ duration: 0,
+ clickId: 0,
+ pendingClick: null,
+ };
+}
+
+function close(a: number, b: number): boolean {
+ return Math.abs(a - b) < 0.5;
+}
+
+export function aimCursor(
+ motion: CursorMotion,
+ target: CursorTarget,
+ distancePx: number,
+ now: number,
+ reducedMotion: boolean,
+): AimResult {
+ const samePoint = close(motion.toX, target.x) && close(motion.toY, target.y);
+ const sameClick = motion.clickId === target.clickId;
+ if (samePoint && sameClick) return { motion, changed: false, releaseClick: null };
+
+ let releaseClick: CursorClick | null = null;
+ let pending = motion.pendingClick;
+ if (!samePoint && pending) {
+ const headingToClick = close(target.x, pending.x) && close(target.y, pending.y);
+ if (!headingToClick) {
+ releaseClick = pending;
+ pending = null;
+ }
+ }
+
+ let next: CursorMotion = { ...motion, clickId: target.clickId, pendingClick: pending };
+ if (!samePoint) {
+ const duration = reducedMotion ? 0 : glideDurationMs(distancePx);
+ const snap = reducedMotion || duration === 0;
+ next = {
+ ...next,
+ fromX: motion.x,
+ fromY: motion.y,
+ toX: target.x,
+ toY: target.y,
+ start: now,
+ duration,
+ x: snap ? target.x : motion.x,
+ y: snap ? target.y : motion.y,
+ };
+ }
+ if (!sameClick && target.clickId > motion.clickId && target.clickId > 0) {
+ next = {
+ ...next,
+ pendingClick: { id: target.clickId, x: target.clickX, y: target.clickY },
+ };
+ }
+ return { motion: next, changed: true, releaseClick };
+}
+
+export function hasArrived(x: number, y: number, targetX: number, targetY: number): boolean {
+ const dx = x - targetX;
+ const dy = y - targetY;
+ return dx * dx + dy * dy <= 2.5 * 2.5;
+}
+
+export function stepCursor(motion: CursorMotion, now: number): {
+ motion: CursorMotion;
+ arrivedClick: CursorClick | null;
+ moving: boolean;
+} {
+ const t = motion.duration <= 0
+ ? 1
+ : Math.min(1, Math.max(0, (now - motion.start) / motion.duration));
+ const eased = easeOutCubic(t);
+ const x = motion.fromX + (motion.toX - motion.fromX) * eased;
+ const y = motion.fromY + (motion.toY - motion.fromY) * eased;
+ let pending = motion.pendingClick;
+ let arrivedClick: CursorClick | null = null;
+ if (pending && hasArrived(x, y, pending.x, pending.y)) {
+ arrivedClick = pending;
+ pending = null;
+ }
+ return {
+ motion: { ...motion, x, y, pendingClick: pending },
+ arrivedClick,
+ moving: t < 1,
+ };
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/browserPointer.css b/jarvis/ui/web/frontend/src/components/society/card/browserPointer.css
deleted file mode 100644
index d1b98517ea..0000000000
--- a/jarvis/ui/web/frontend/src/components/society/card/browserPointer.css
+++ /dev/null
@@ -1,55 +0,0 @@
-.jarvis-browser-pointer-layer {
- --browser-pointer-fill: hsl(var(--primary));
- --browser-pointer-edge: hsl(var(--background));
- position: absolute;
- inset: 0;
- pointer-events: none;
- overflow: hidden;
-}
-.jarvis-browser-pointer {
- position: absolute;
- width: 24px;
- height: 30px;
- transform: translate(-3px, -3px);
- filter: drop-shadow(0 2px 3px #0008);
- transition: left 80ms ease-out, top 80ms ease-out;
-}
-.jarvis-browser-pointer-label {
- position: absolute;
- left: 22px;
- top: 22px;
- display: flex;
- align-items: center;
- gap: 4px;
- padding: 2px 7px;
- border: 1px solid hsl(var(--border));
- border-radius: 999px;
- color: hsl(var(--foreground));
- background: hsl(var(--background));
- font: 600 10px/14px system-ui, sans-serif;
- white-space: nowrap;
-}
-.jarvis-browser-pointer-dot {
- width: 5px;
- height: 5px;
- border-radius: 50%;
- background: var(--browser-pointer-fill);
-}
-.jarvis-browser-click {
- position: absolute;
- width: 24px;
- height: 24px;
- margin: -12px;
- border: 2px solid var(--browser-pointer-fill);
- border-radius: 50%;
- box-shadow: 0 0 0 1px var(--browser-pointer-edge);
- animation: jarvis-browser-click 500ms ease-out forwards;
-}
-@keyframes jarvis-browser-click {
- from { transform: scale(.45); opacity: .95; }
- to { transform: scale(1.8); opacity: 0; }
-}
-@media (prefers-reduced-motion: reduce) {
- .jarvis-browser-pointer { transition: none; }
- .jarvis-browser-click { animation-duration: 120ms; }
-}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/browserPointerState.ts b/jarvis/ui/web/frontend/src/components/society/card/browserPointerState.ts
new file mode 100644
index 0000000000..45f7903442
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/browserPointerState.ts
@@ -0,0 +1,10 @@
+/** Mouse position reported by the agent browser, in the page's own pixels. */
+export interface BrowserPointerState {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+ click_id: number;
+ click_x: number;
+ click_y: number;
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/useBrowserView.ts b/jarvis/ui/web/frontend/src/components/society/card/useBrowserView.ts
index c4782837ca..e83bf47c70 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/useBrowserView.ts
+++ b/jarvis/ui/web/frontend/src/components/society/card/useBrowserView.ts
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { mintWsTicket } from "@/lib/ws";
import { jitteredDelay, requestConnect } from "@/lib/connectBudget";
-import type { BrowserPointerState } from "./BrowserPointer";
+import type { BrowserPointerState } from "./browserPointerState";
export interface BrowserViewState {
connected: boolean;