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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(wiki): the memory map moves smoothly — no lurches, no snaps, one wave instead of noise
Haraldc3f7e14ab3e2
diff --git a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsxindex baba778ecc..0e5e959773 100644--- a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx+++ b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx@@ -46,6 +46,7 @@ import {createLivelinessForce,type LivelyNode,} from "@/lib/graphForces";+import { carryOverPositions } from "@/lib/graphContinuity";import type { Vec3 } from "@/lib/graphCamera";import { useGraphOrbit, type GraphCameraApi } from "@/hooks/useGraphOrbit";@@ -190,6 +191,8 @@ export function WikiGraph3D({}, [graphData]);const pivotSlugRef = useRef(pivotSlug);pivotSlugRef.current = pivotSlug;+ /** The live pivot node object (set below, once the data is known). */+ const pivotNodeRef = useRef<Partial<Vec3> | null>(null);const reducedMotion = useMemo(() =>typeof window.matchMedia === "function" &&@@ -244,6 +247,14 @@ export function WikiGraph3D({createLivelinessForce({now: () => performance.now(),isPinned: (node: LivelyNode) => node.id === pivotSlugRef.current,+ // The network breathes from the pivot page, wherever the layout+ // has it this tick; from the origin when the vault has no pivot.+ centre: () => {+ const pivot = pivotNodeRef.current;+ return pivot && Number.isFinite(pivot.x)+ ? { x: pivot.x ?? 0, y: pivot.y ?? 0, z: pivot.z ?? 0 }+ : { x: 0, y: 0, z: 0 };+ },}),);}@@ -263,6 +274,7 @@ export function WikiGraph3D({() => (pivotSlug ? (graphData.nodes.find((n) => n.id === pivotSlug) ?? null) : null),[graphData.nodes, pivotSlug],);+ pivotNodeRef.current = pivotNode as Partial<Vec3> | null;useGraphOrbit({graphRef: graphRef as RefObject<GraphCameraApi | undefined>,@@ -389,7 +401,22 @@ export function WikiGraph3D({[],);- const data = useMemo(() => graphData, [graphData]);+ // New data must not explode the map. The renderer seeds every node that+ // arrives without a position from scratch, so before a new generation+ // reaches it, pages that were on the map keep the place (and the+ // liveliness offset) their previous object had, and a NEW page is seated+ // next to the pages it links to. Same objects the simulation integrates,+ // mutated once per generation, before the renderer sees them.+ const previousNodesRef = useRef<RenderNode[]>([]);+ const data = useMemo(() => {+ const previous = previousNodesRef.current;+ if (previous !== graphData.nodes) {+ const pivot = previous.find((n) => n.id === pivotSlugRef.current);+ carryOverPositions(previous, graphData.nodes, graphData.links, pivot ?? {});+ previousNodesRef.current = graphData.nodes;+ }+ return graphData;+ }, [graphData]);return (// The renderer paints into its own canvas; this wrapper is what the cameradiff --git a/jarvis/ui/web/frontend/src/hooks/useGraphOrbit.ts b/jarvis/ui/web/frontend/src/hooks/useGraphOrbit.tsindex 25d8b02e7d..a5b8a8160e 100644--- a/jarvis/ui/web/frontend/src/hooks/useGraphOrbit.ts+++ b/jarvis/ui/web/frontend/src/hooks/useGraphOrbit.ts@@ -9,10 +9,16 @@* The motion is ONE thing: a steady clockwise turn around a fixed pivot, seen* from a raised camera so the turn reads as a rotation about a point rather* than nodes sliding sideways (maintainer decision 2026-08-18: "always- * rotates around a fixed point, clockwise"). No rise and fall on top — a- * bobbing camera made the pivot itself look like it was drifting. It is- * still ambient, not animation: a full turn takes well over a minute, and- * you can read a label while it moves.+ * rotates around a fixed point, clockwise"), with a slow nod on top. It is+ * ambient, not animation: a full turn takes about a minute, and you can read+ * a label while it moves.+ *+ * And it is CONTINUOUS. Nothing in here ever sets the camera somewhere else+ * in one go once it is running: a re-frame (new data, a settled layout, the+ * Center button, a resize) only moves the target, and every frame the loop+ * eases distance and centre a little toward it. The first cut tweened the+ * camera on every re-frame and parked the drift around the tween — five+ * lurches after each data change, and a step in height on every resume.** Three things stop it, and all three matter:* - The user touching the map. Nothing is more irritating than a view that@@ -27,6 +33,8 @@import { useCallback, useEffect, useRef, type RefObject } from "react";import {+ approach,+ approachPoint,framingAround,framingFor,orbitDistance,@@ -77,6 +85,17 @@ const SWING_MS = 61_000;/** How long after the user's last touch the drift picks back up. */const RESUME_AFTER_MS = 3_500;+/**+ * How quickly the camera glides to a new framing. Re-framing used to be a+ * 700 ms tween with the drift parked around it, and it happened five times+ * after every data change; each one was a visible lurch (maintainer,+ * 2026-08-18: "it teleports, it snaps"). Now a re-frame only sets a TARGET+ * distance and centre, and the drift loop eases toward them every frame with+ * these time constants — the turn never stops, the height never jumps.+ */+const DISTANCE_TAU_MS = 1_600;+const CENTRE_TAU_MS = 900;+/** Share of the frame the network fills once framed. */const FILL = 0.94;@@ -110,6 +129,8 @@ export function useGraphOrbit({azimuth: 0,elevation: BASE_ELEVATION,});+ /** Where a re-frame wants the camera; the loop glides there. */+ const targetRef = useRef<{ centre: Vec3; distance: number } | null>(null);const pausedUntilRef = useRef(0);const resyncRef = useRef(false);// Read once per mount rather than per frame; the array identity changes on@@ -123,8 +144,12 @@ export function useGraphOrbit({/** The height the swing oscillates around — ours, or the user's after a drag. */const baseElevationRef = useRef(BASE_ELEVATION);- /** Point the camera at the middle of the network, far enough back to see it. */- const frame = useCallback((transitionMs = 700): void => {+ /**+ * Decide where the camera should stand: the middle of the network and how+ * far back. Only the FIRST framing places the camera; every later one just+ * moves the target, and the drift loop glides there.+ */+ const frame = useCallback((): void => {const graph = graphRef.current;if (!graph) return;const framing = pivotRef.current@@ -139,29 +164,14 @@ export function useGraphOrbit({camera?.aspect ?? 1,FILL,);- centreRef.current = framing.centre;- // Keep whatever angle the camera is already at — re-framing is about how- // far back you stand, not about turning the map back to the front.- const current = camera?.position- ? orbitFrom(framing.centre, camera.position)- : null;- baseElevationRef.current = BASE_ELEVATION;- orbitRef.current = {- distance,- azimuth: current?.azimuth ?? 0,- elevation: BASE_ELEVATION,- };- graph.cameraPosition(- orbitPoint(framing.centre, orbitRef.current),- framing.centre,- transitionMs,- );- // Our own move must not be mistaken for the user's, but the transition- // does need to finish before the drift starts nudging the camera again.- pausedUntilRef.current = Math.max(- pausedUntilRef.current,- performance.now() + transitionMs + 60,- );+ targetRef.current = { centre: framing.centre, distance };++ if (orbitRef.current.distance === 0) {+ // Nothing on screen yet: stand there at once, and start the turn.+ centreRef.current = framing.centre;+ orbitRef.current = { distance, azimuth: 0, elevation: BASE_ELEVATION };+ graph.cameraPosition(orbitPoint(framing.centre, orbitRef.current), framing.centre, 0);+ }}, [graphRef]);useEffect(() => {@@ -218,35 +228,41 @@ export function useGraphOrbit({const graph = graphRef.current;if (!graph || orbitRef.current.distance === 0) return;+ const swing = Math.sin(swingPhaseRef.current) * ELEVATION_SWING;if (resyncRef.current) {// Carry on from wherever the user left the camera — their angle,// their height, how far out they zoomed — instead of yanking it back// to our own. The pivot stays ours: the turn continues around the- // same point, just from where they parked the view.+ // same point, just from where they parked the view. Their zoom+ // becomes the new target too, so the glide does not creep back.const camera = graph.camera();if (camera?.position) {const seen = orbitFrom(centreRef.current, camera.position);if (seen.distance > 0) {orbitRef.current = seen;- baseElevationRef.current = seen.elevation;+ // Take the swing back out so the resting height is theirs and the+ // swing continues from where it is — no step on resume.+ baseElevationRef.current = clampElevation(seen.elevation - swing);+ if (targetRef.current) targetRef.current = { ...targetRef.current, distance: seen.distance };}}resyncRef.current = false;}- // The pivot node keeps moving while the layout settles (and again after- // new data); following it each frame is what makes the turn stay- // centred on the page rather than on where it was when we framed.+ // Where the turn is centred: the pivot page, read live because the+ // layout keeps moving it (settling, new data), else the framed middle.+ // Eased, never set — a re-frame or a settling pivot glides the view.const pivotNode = pivotRef.current;- if (pivotNode && Number.isFinite(pivotNode.x)) {- centreRef.current = {- x: pivotNode.x ?? 0,- y: pivotNode.y ?? 0,- z: pivotNode.z ?? 0,- };- }+ const wanted: Vec3 =+ pivotNode && Number.isFinite(pivotNode.x)+ ? { x: pivotNode.x ?? 0, y: pivotNode.y ?? 0, z: pivotNode.z ?? 0 }+ : (targetRef.current?.centre ?? centreRef.current);+ centreRef.current = approachPoint(centreRef.current, wanted, elapsed, CENTRE_TAU_MS);const orbit = orbitRef.current;+ if (targetRef.current) {+ orbit.distance = approach(orbit.distance, targetRef.current.distance, elapsed, DISTANCE_TAU_MS);+ }orbit.azimuth = stepAzimuth(orbit.azimuth, elapsed, REVOLUTION_MS);swingPhaseRef.current += (elapsed / SWING_MS) * Math.PI * 2;orbit.elevation = clampElevation(diff --git a/jarvis/ui/web/frontend/src/lib/graphCamera.test.ts b/jarvis/ui/web/frontend/src/lib/graphCamera.test.tsindex 2a04c5a795..3ce0288e35 100644--- a/jarvis/ui/web/frontend/src/lib/graphCamera.test.ts+++ b/jarvis/ui/web/frontend/src/lib/graphCamera.test.ts@@ -11,6 +11,7 @@ import { describe, expect, it } from "vitest";import {framingAround,ORBIT_DIRECTION,+ approach,framingFor,orbitDistance,orbitFrom,@@ -213,3 +214,34 @@ describe("the ambient drift", () => {}});});++describe("approach", () => {+ it("closes the same share of the gap per unit of time, whatever the frame rate", () => {+ // Sixty small steps and one big step of the same total time land in the+ // same place — the easing does not depend on how often it is called.+ let fine = 0;+ for (let i = 0; i < 60; i++) fine = approach(fine, 100, 1000 / 60, 800);+ const coarse = approach(0, 100, 1000, 800);+ expect(fine).toBeCloseTo(coarse, 6);+ // …and after one time constant about 63 % of the way.+ expect(approach(0, 100, 800, 800)).toBeCloseTo(63.2, 0);+ });++ it("never overshoots and never jumps", () => {+ let value = 0;+ let previous = 0;+ for (let i = 0; i < 200; i++) {+ value = approach(value, 100, 16, 800);+ expect(value).toBeGreaterThanOrEqual(previous);+ expect(value).toBeLessThanOrEqual(100);+ // One 60 fps step closes at most ~2 % of the gap.+ expect(value - previous).toBeLessThan(2.1);+ previous = value;+ }+ });++ it("snaps only when there is nothing to ease from", () => {+ expect(approach(Number.NaN, 5, 16, 800)).toBe(5);+ expect(approach(3, 5, 0, 800)).toBe(3);+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/graphCamera.ts b/jarvis/ui/web/frontend/src/lib/graphCamera.tsindex 1de6076fa3..f1ac3e62ab 100644--- a/jarvis/ui/web/frontend/src/lib/graphCamera.ts+++ b/jarvis/ui/web/frontend/src/lib/graphCamera.ts@@ -257,3 +257,27 @@ function normalise(v: Vec3): Vec3 {const length = Math.sqrt(dot(v, v)) || 1;return { x: v.x / length, y: v.y / length, z: v.z / length };}++/**+ * Move `current` toward `target` the way a damped thing does: the same share+ * of the remaining gap per unit of time, whatever the frame rate. `tauMs` is+ * the time constant — after one tau, 63 % of the gap is closed; after three,+ * 95 %. This is what lets a re-frame change where the camera should stand+ * without the camera ever jumping there: the drift loop eases toward the new+ * value every frame, and the motion stays continuous.+ */+export function approach(current: number, target: number, elapsedMs: number, tauMs: number): number {+ if (!Number.isFinite(current)) return target;+ if (tauMs <= 0 || elapsedMs <= 0) return current;+ const share = 1 - Math.exp(-elapsedMs / tauMs);+ return current + (target - current) * share;+}++/** `approach`, for a point. */+export function approachPoint(current: Vec3, target: Vec3, elapsedMs: number, tauMs: number): Vec3 {+ return {+ x: approach(current.x, target.x, elapsedMs, tauMs),+ y: approach(current.y, target.y, elapsedMs, tauMs),+ z: approach(current.z, target.z, elapsedMs, tauMs),+ };+}diff --git a/jarvis/ui/web/frontend/src/lib/graphContinuity.test.ts b/jarvis/ui/web/frontend/src/lib/graphContinuity.test.tsnew file mode 100644index 0000000000..a1ba167a00--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/graphContinuity.test.ts@@ -0,0 +1,62 @@+/**+ * New data must not explode the map: pages keep their place, newcomers land+ * next to the pages they link to.+ */+import { describe, expect, it } from "vitest";++import { carryOverPositions, type ContinuityNode } from "@/lib/graphContinuity";++describe("carryOverPositions", () => {+ it("keeps every page that was already placed exactly where it was", () => {+ const previous: ContinuityNode[] = [+ { id: "me", x: 1, y: 2, z: 3, vx: 0.1, vy: 0, vz: -0.1, __lively: { x: 0, y: 4, z: 0 } },+ { id: "a", x: 80, y: 0, z: -20 },+ ];+ const next: ContinuityNode[] = [{ id: "me" }, { id: "a" }];+ const result = carryOverPositions(previous, next, []);+ expect(result).toEqual({ kept: 2, seated: 0 });+ expect(next[0]).toMatchObject({ x: 1, y: 2, z: 3, vx: 0.1, vy: 0, vz: -0.1, __lively: { x: 0, y: 4, z: 0 } });+ expect(next[1]).toMatchObject({ x: 80, y: 0, z: -20 });+ });++ it("seats a newcomer between the pages it links to, not at the origin", () => {+ const previous: ContinuityNode[] = [+ { id: "a", x: 100, y: 0, z: 0 },+ { id: "b", x: 100, y: 0, z: 100 },+ ];+ const next: ContinuityNode[] = [{ id: "a" }, { id: "b" }, { id: "new" }];+ const result = carryOverPositions(previous, next, [+ { source: "new", target: "a" },+ { source: "b", target: "new" },+ ]);+ expect(result).toEqual({ kept: 2, seated: 1 });+ const seated = next[2];+ // The middle of a and b is (100, 0, 50); a small scatter on top.+ expect(Math.abs(seated.x! - 100)).toBeLessThan(20);+ expect(Math.abs(seated.z! - 50)).toBeLessThan(20);+ expect(seated.vx).toBe(0);+ });++ it("seats an unlinked newcomer near the fallback point", () => {+ const next: ContinuityNode[] = [{ id: "x" }, { id: "lonely" }];+ carryOverPositions([{ id: "x", x: 500, y: 0, z: 0 }], next, [], { x: 10, y: 20, z: 30 });+ next.shift();+ expect(Math.abs(next[0].x! - 10)).toBeLessThan(20);+ expect(Math.abs(next[0].y! - 20)).toBeLessThan(20);+ expect(Math.abs(next[0].z! - 30)).toBeLessThan(20);+ });++ it("leaves a page that already carries a position alone", () => {+ const next: ContinuityNode[] = [{ id: "a", x: 7, y: 8, z: 9 }];+ const result = carryOverPositions([{ id: "b", x: 0, y: 0, z: 0 }], next, []);+ expect(result).toEqual({ kept: 0, seated: 0 });+ expect(next[0]).toMatchObject({ x: 7, y: 8, z: 9 });+ });++ it("does nothing on the first generation, so the layout still spreads it", () => {+ const next: ContinuityNode[] = [{ id: "a" }, { id: "b" }];+ const result = carryOverPositions([], next, [{ source: "a", target: "b" }]);+ expect(result).toEqual({ kept: 0, seated: 0 });+ expect(next[0].x).toBeUndefined();+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/graphContinuity.ts b/jarvis/ui/web/frontend/src/lib/graphContinuity.tsnew file mode 100644index 0000000000..c1c2e8ab30--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/graphContinuity.ts@@ -0,0 +1,123 @@+/**+ * Keep a force layout's pages where they are when the data behind it changes.+ *+ * The renderer starts every new data generation from scratch: nodes that+ * arrive without a position are scattered by d3's phyllotaxis and the whole+ * network explodes and re-settles — a "complete snap" on a map that was+ * calm a moment ago. On the deck that happens every time the assistant+ * writes a wiki page (the graph is refetched, and the payload builds fresh+ * node objects). So before a new generation reaches the renderer, this+ * copies each page's position and velocity over from the previous+ * generation's object with the same id, and drops a NEW page next to the+ * pages it links to — where it belongs — instead of at the origin. The+ * simulation then only has to settle the newcomer; everything else stays.+ *+ * Pure: it mutates the node objects it is handed (which are the objects the+ * simulation will integrate over) and touches nothing else.+ */++export interface ContinuityNode {+ id: string;+ x?: number;+ y?: number;+ z?: number;+ vx?: number;+ vy?: number;+ vz?: number;+ /** The liveliness force's applied offset — travels with the position. */+ __lively?: { x: number; y: number; z: number };+}++export interface ContinuityLink {+ source: string | { id: string };+ target: string | { id: string };+}++/** How far from its neighbours' middle a newcomer lands, graph units. */+const NEWCOMER_SPREAD = 18;++function idOf(endpoint: string | { id: string }): string {+ return typeof endpoint === "string" ? endpoint : endpoint.id;+}++/** A small deterministic scatter so two newcomers do not land on one spot. */+function scatter(id: string, axis: number): number {+ let h = 2166136261 ^ axis;+ for (let i = 0; i < id.length; i++) {+ h ^= id.charCodeAt(i);+ h = Math.imul(h, 16777619);+ }+ return ((h >>> 0) / 4294967295 - 0.5) * 2 * NEWCOMER_SPREAD;+}++/**+ * Carry positions from `previous` onto `next` (matched by id) and seat+ * newcomers next to their neighbours.+ *+ * @returns how many pages kept their place, and how many were seated anew+ */+export function carryOverPositions(+ previous: readonly ContinuityNode[],+ next: ContinuityNode[],+ links: readonly ContinuityLink[],+ fallback: { x?: number; y?: number; z?: number } = {},+): { kept: number; seated: number } {+ // The very first generation is the simulation's to spread — d3's spiral+ // seeding is what the layout was tuned against.+ if (previous.length === 0) return { kept: 0, seated: 0 };++ const before = new Map(previous.map((node) => [node.id, node]));+ let kept = 0;+ const newcomers: ContinuityNode[] = [];++ for (const node of next) {+ const was = before.get(node.id);+ if (was && Number.isFinite(was.x) && Number.isFinite(was.y)) {+ node.x = was.x;+ node.y = was.y;+ node.z = was.z ?? 0;+ node.vx = was.vx ?? 0;+ node.vy = was.vy ?? 0;+ node.vz = was.vz ?? 0;+ if (was.__lively) node.__lively = { ...was.__lively };+ kept += 1;+ } else if (!Number.isFinite(node.x)) {+ newcomers.push(node);+ }+ }+ if (newcomers.length === 0) return { kept, seated: 0 };++ // Newcomers sit at the middle of their already-placed neighbours.+ const placed = new Map(next.filter((n) => Number.isFinite(n.x)).map((n) => [n.id, n]));+ const neighbours = new Map<string, ContinuityNode[]>();+ for (const link of links) {+ const a = idOf(link.source);+ const b = idOf(link.target);+ const pa = placed.get(a);+ const pb = placed.get(b);+ if (pb) (neighbours.get(a) ?? neighbours.set(a, []).get(a)!).push(pb);+ if (pa) (neighbours.get(b) ?? neighbours.set(b, []).get(b)!).push(pa);+ }++ const fx = fallback.x ?? 0;+ const fy = fallback.y ?? 0;+ const fz = fallback.z ?? 0;+ for (const node of newcomers) {+ const near = neighbours.get(node.id) ?? [];+ let x = fx;+ let y = fy;+ let z = fz;+ if (near.length > 0) {+ x = near.reduce((s, n) => s + (n.x ?? 0), 0) / near.length;+ y = near.reduce((s, n) => s + (n.y ?? 0), 0) / near.length;+ z = near.reduce((s, n) => s + (n.z ?? 0), 0) / near.length;+ }+ node.x = x + scatter(node.id, 1);+ node.y = y + scatter(node.id, 2);+ node.z = z + scatter(node.id, 3);+ node.vx = 0;+ node.vy = 0;+ node.vz = 0;+ }+ return { kept, seated: newcomers.length };+}diff --git a/jarvis/ui/web/frontend/src/lib/graphForces.test.ts b/jarvis/ui/web/frontend/src/lib/graphForces.test.tsindex e601a8237f..8afdc29ad4 100644--- a/jarvis/ui/web/frontend/src/lib/graphForces.test.ts+++ b/jarvis/ui/web/frontend/src/lib/graphForces.test.ts@@ -1,12 +1,14 @@/**- * The liveliness force: every page but the pivot moves on its own, and the- * motion is a bounded, periodic offset on top of the layout — never a drift.+ * The liveliness force: every page but the pivot moves — together, as a+ * wave, a breath and a small wobble — and the motion is a bounded, smooth,+ * periodic offset on top of the layout, never a drift and never a jump.*/import { describe, expect, it } from "vitest";import {LIVELINESS_AMPLITUDE,- LIVELINESS_SWAY,+ LIVELINESS_BREATH,+ LIVELINESS_WOBBLE,createLivelinessForce,rhythmSeed,type LivelyNode,@@ -17,61 +19,111 @@ function scene(): LivelyNode[] {{ id: "me", x: 0, y: 0, z: 0 },{ id: "projects/nova", x: 80, y: 5, z: -20 },{ id: "people/alex", x: -60, y: -10, z: 40 },+ // Two neighbours standing close together — the wave must carry them+ // almost as one.+ { id: "notes/a", x: 100, y: 0, z: 100 },+ { id: "notes/b", x: 110, y: 0, z: 104 },];}-function run(nodes: LivelyNode[], times: number[]): void {+const BASES: Record<string, { x: number; y: number; z: number }> = {+ "projects/nova": { x: 80, y: 5, z: -20 },+ "people/alex": { x: -60, y: -10, z: 40 },+ "notes/a": { x: 100, y: 0, z: 100 },+ "notes/b": { x: 110, y: 0, z: 104 },+};++function makeForce(nodes: LivelyNode[]) {let t = 0;- const force = createLivelinessForce({ now: () => t, isPinned: (n) => n.id === "me" });+ const force = createLivelinessForce({+ now: () => t,+ isPinned: (n) => n.id === "me",+ centre: () => nodes[0],+ });force.initialize(nodes);- for (const time of times) {- t = time;- force(0); // alpha is ignored on purpose- }+ return { tick: (time: number) => { t = time; force(0); } };+}++/** The most an offset may reach: wave + breath share of the distance out. */+function bound(base: { x: number; y: number; z: number }, axis: "x" | "y" | "z"): number {+ const dist = Math.abs(base[axis]);+ const breath = dist * LIVELINESS_BREATH;+ return axis === "y" ? LIVELINESS_AMPLITUDE + breath : breath + LIVELINESS_WOBBLE;}describe("createLivelinessForce", () => {it("never moves the pivot", () => {const nodes = scene();- run(nodes, [0, 300, 900, 1500, 4000, 9000]);+ const { tick } = makeForce(nodes);+ for (const t of [0, 300, 900, 1500, 4000, 9000]) tick(t);expect(nodes[0]).toMatchObject({ x: 0, y: 0, z: 0 });});- it("moves every other page, each with its own rhythm", () => {+ it("moves every other page", () => {+ const nodes = scene();+ const { tick } = makeForce(nodes);+ tick(0);+ tick(1300);+ for (const node of nodes.slice(1)) {+ const base = BASES[String(node.id)];+ expect(Math.abs(node.y! - base.y)).toBeGreaterThan(0.5);+ }+ });++ it("carries close neighbours almost together — a wave, not noise", () => {const nodes = scene();- run(nodes, [0, 700]);- const a = nodes[1];- const b = nodes[2];- expect(a.y).not.toBe(5);- expect(b.y).not.toBe(-10);- // Different pages, different phase: they are not in step.- expect(a.y! - 5).not.toBeCloseTo(b.y! + 10, 3);+ const { tick } = makeForce(nodes);+ let maxGap = 0;+ for (let t = 0; t < 12_000; t += 100) {+ tick(t);+ const a = nodes[3].y! - BASES["notes/a"].y;+ const b = nodes[4].y! - BASES["notes/b"].y;+ maxGap = Math.max(maxGap, Math.abs(a - b));+ }+ // Independent rhythms would put them a full amplitude apart at times.+ expect(maxGap).toBeLessThan(LIVELINESS_AMPLITUDE * 0.75);});it("stays a bounded offset on top of the layout — no drift over time", () => {const nodes = scene();- const times = Array.from({ length: 400 }, (_, i) => i * 37);- run(nodes, times);+ const { tick } = makeForce(nodes);+ for (let i = 0; i < 600; i++) tick(i * 37);for (const node of nodes.slice(1)) {- const base = node.id === "projects/nova" ? { x: 80, y: 5, z: -20 } : { x: -60, y: -10, z: 40 };- expect(Math.abs(node.y! - base.y)).toBeLessThanOrEqual(LIVELINESS_AMPLITUDE + 1e-9);- expect(Math.abs(node.x! - base.x)).toBeLessThanOrEqual(LIVELINESS_SWAY + 1e-9);- expect(Math.abs(node.z! - base.z)).toBeLessThanOrEqual(LIVELINESS_SWAY + 1e-9);+ const base = BASES[String(node.id)];+ for (const axis of ["x", "y", "z"] as const) {+ expect(Math.abs(node[axis]! - base[axis])).toBeLessThanOrEqual(bound(base, axis) + 1e-6);+ }+ }+ });++ it("moves smoothly at 60 fps — no tick jumps a page", () => {+ const nodes = scene();+ const { tick } = makeForce(nodes);+ tick(0);+ let maxStep = 0;+ let previous = nodes.map((n) => ({ x: n.x!, y: n.y!, z: n.z! }));+ for (let t = 16; t < 20_000; t += 16) {+ tick(t);+ nodes.forEach((n, i) => {+ const step = Math.hypot(n.x! - previous[i].x, n.y! - previous[i].y, n.z! - previous[i].z);+ maxStep = Math.max(maxStep, step);+ });+ previous = nodes.map((n) => ({ x: n.x!, y: n.y!, z: n.z! }));}+ // A node radius is 3–8 units; a frame must never move a page a visible jolt.+ expect(maxStep).toBeLessThan(0.5);});it("composes with a layout that keeps moving the node underneath", () => {const nodes = scene();- let t = 0;- const force = createLivelinessForce({ now: () => t, isPinned: () => false });- force.initialize(nodes);- force(1);+ const { tick } = makeForce(nodes);+ tick(0);// The layout shoves the node 100 units over between ticks…nodes[1].x = (nodes[1].x ?? 0) + 100;- t = 500;- force(1);+ tick(500);// …and the force keeps only its own small offset on top of the new place.- expect(Math.abs(nodes[1].x! - 180)).toBeLessThanOrEqual(LIVELINESS_SWAY + 1e-9);+ const base = { x: 180, y: 5, z: -20 };+ expect(Math.abs(nodes[1].x! - base.x)).toBeLessThanOrEqual(bound(base, "x") + 1e-6);});it("gives a page the same rhythm every time", () => {diff --git a/jarvis/ui/web/frontend/src/lib/graphForces.ts b/jarvis/ui/web/frontend/src/lib/graphForces.tsindex 512245f5c3..431b01379a 100644--- a/jarvis/ui/web/frontend/src/lib/graphForces.ts+++ b/jarvis/ui/web/frontend/src/lib/graphForces.ts@@ -78,7 +78,7 @@ export function createCentringForce(strength: number): CentringForce {export const CENTRING_STRENGTH = 0.04;// -----------------------------------------------------------------------// Liveliness — every page but the pivot keeps moving on its own+// Liveliness — every page but the pivot keeps moving, together// ----------------------------------------------------------------------/**@@ -102,41 +102,45 @@ export interface LivelinessOptions {now: () => number;/** True for the node that must not move — the pivot the map turns around. */isPinned: (node: LivelyNode) => boolean;- /** Peak vertical displacement, graph units. */+ /**+ * Where the network breathes from — the pivot's position when there is+ * one, else the origin. Read every tick, so a moving pivot is followed.+ */+ centre?: () => Vec3Like;+ /** Peak height of the wave, graph units. */amplitude?: number;- /** Radius of the small horizontal loop each node adds to its bob. */- sway?: number;- /** Shortest and longest full bob, milliseconds — each node gets its own. */- periodMs?: [number, number];+ /** One full wave cycle at a fixed point, milliseconds. */+ wavePeriodMs?: number;+ /** Distance between two crests, graph units. */+ wavelength?: number;+ /** Peak in-and-out of the breathing, as a share of the distance from centre. */+ breath?: number;+ /** One full breath, milliseconds. */+ breathPeriodMs?: number;+ /** Peak of each page's own small drift, graph units. */+ wobble?: number;}-/** Bob height, in graph units. Link distance is 85, a node radius 3–8. */-export const LIVELINESS_AMPLITUDE = 9;-/** Radius of the sideways loop. */-export const LIVELINESS_SWAY = 3;-/** One full bob takes between these — brisk, and never the same for two pages. */-export const LIVELINESS_PERIOD_MS: [number, number] = [2_600, 4_600];--/** A small, stable hash of a node id — the same page always gets the same rhythm. */-export function rhythmSeed(id: string | number | undefined): number {- const text = String(id ?? "");- let h = 2166136261;- for (let i = 0; i < text.length; i++) {- h ^= text.charCodeAt(i);- h = Math.imul(h, 16777619);- }- return (h >>> 0) / 4294967295; // 0..1+interface Vec3Like {+ x?: number;+ y?: number;+ z?: number;}/*** The motion, on top of whatever the layout does.*- * The maintainer's ask (2026-08-18): the pages must not turn as one rigid- * body around the pivot — every page but the pivot should move on its own,- * up and down, quickly enough not to be boring. So each node gets a bob in- * `y` and a small loop in `x`/`z`, with a period and a phase of its own,- * derived from its id so a page keeps its rhythm across re-renders and two- * neighbours never move in step.+ * Three layers, all slow sinusoids, so nothing ever jumps:+ * - a WAVE rolls through the network: every page bobs up and down, and+ * its phase depends on where it stands, so neighbours move almost+ * together and a crest travels across the map — a thing to follow with+ * the eye rather than noise to be annoyed by;+ * - the whole network BREATHES: pages ease a little away from the pivot+ * and back, together;+ * - each page adds a small WOBBLE of its own, so no two move exactly alike.+ *+ * The first cut gave every page an independent rhythm; the maintainer read+ * that as random and jerky (2026-08-18). Coherence is what makes it calm.** It is applied as a DELTA: the force remembers the offset it applied last* tick and swaps it for this tick's, so it composes with the layout at any@@ -146,27 +150,97 @@ export function rhythmSeed(id: string | number | undefined): number {* left exactly where the layout puts it, so the point the map turns around* stays a point.*/+export const LIVELINESS_AMPLITUDE = 10;+export const LIVELINESS_WAVE_PERIOD_MS = 5_200;+export const LIVELINESS_WAVELENGTH = 240;+export const LIVELINESS_BREATH = 0.035;+export const LIVELINESS_BREATH_PERIOD_MS = 9_000;+export const LIVELINESS_WOBBLE = 1.6;++/** A small, stable hash of a node id — the same page always gets the same rhythm. */+export function rhythmSeed(id: string | number | undefined): number {+ const text = String(id ?? "");+ let h = 2166136261;+ for (let i = 0; i < text.length; i++) {+ h ^= text.charCodeAt(i);+ h = Math.imul(h, 16777619);+ }+ return (h >>> 0) / 4294967295; // 0..1+}++/** The wave travels along this direction in the horizontal plane. */+const WAVE_DIR = { x: Math.cos(0.6), z: Math.sin(0.6) };++/**+ * The offset the force wants for one node at time `t`, given the node's+ * layout position `base` (its position minus the current offset). Pure, so+ * the shape of the motion is testable on its own.+ */+export function livelyOffset(+ base: Vec3Like,+ seed: number,+ t: number,+ centre: Vec3Like,+ options: Required<Pick<LivelinessOptions, "amplitude" | "wavePeriodMs" | "wavelength" | "breath" | "breathPeriodMs" | "wobble">>,+): { x: number; y: number; z: number } {+ const bx = base.x ?? 0;+ const by = base.y ?? 0;+ const bz = base.z ?? 0;+ const cx = centre.x ?? 0;+ const cy = centre.y ?? 0;+ const cz = centre.z ?? 0;++ // The wave: phase from position along the travel direction, plus a small+ // personal offset so the crest is not a ruler-straight line.+ const along = (bx - cx) * WAVE_DIR.x + (bz - cz) * WAVE_DIR.z;+ const wavePhase =+ (t / options.wavePeriodMs) * Math.PI * 2 -+ (along / options.wavelength) * Math.PI * 2 ++ (seed - 0.5) * 0.9;+ const wave = Math.sin(wavePhase) * options.amplitude;++ // The breath: radial, shared by all, scaled by how far out the page sits.+ const dx = bx - cx;+ const dy = by - cy;+ const dz = bz - cz;+ const breathScale = Math.sin((t / options.breathPeriodMs) * Math.PI * 2) * options.breath;++ // The wobble: a slow personal loop, its period from the seed (7–11 s).+ const wobblePeriod = 7_000 + seed * 4_000;+ const wobbleAngle = (t / wobblePeriod) * Math.PI * 2 + seed * Math.PI * 2;++ return {+ x: dx * breathScale + Math.cos(wobbleAngle) * options.wobble,+ y: wave + dy * breathScale,+ z: dz * breathScale + Math.sin(wobbleAngle) * options.wobble,+ };+}+export function createLivelinessForce(options: LivelinessOptions): LivelinessForce {- const amplitude = options.amplitude ?? LIVELINESS_AMPLITUDE;- const sway = options.sway ?? LIVELINESS_SWAY;- const [minPeriod, maxPeriod] = options.periodMs ?? LIVELINESS_PERIOD_MS;+ const shape = {+ amplitude: options.amplitude ?? LIVELINESS_AMPLITUDE,+ wavePeriodMs: options.wavePeriodMs ?? LIVELINESS_WAVE_PERIOD_MS,+ wavelength: options.wavelength ?? LIVELINESS_WAVELENGTH,+ breath: options.breath ?? LIVELINESS_BREATH,+ breathPeriodMs: options.breathPeriodMs ?? LIVELINESS_BREATH_PERIOD_MS,+ wobble: options.wobble ?? LIVELINESS_WOBBLE,+ };+ const centreOf = options.centre ?? (() => ({ x: 0, y: 0, z: 0 }));let nodes: LivelyNode[] = [];const force = ((_alpha: number): void => {const t = options.now();+ const centre = centreOf();for (const node of nodes) {const previous = node.__lively ?? { x: 0, y: 0, z: 0 };let next = { x: 0, y: 0, z: 0 };if (!options.isPinned(node)) {- const seed = rhythmSeed(node.id);- const period = minPeriod + (maxPeriod - minPeriod) * seed;- const phase = seed * Math.PI * 2;- const angle = (t / period) * Math.PI * 2 + phase;- next = {- x: Math.cos(angle * 0.5) * sway,- y: Math.sin(angle) * amplitude,- z: Math.sin(angle * 0.5) * sway,+ const base = {+ x: (node.x ?? 0) - previous.x,+ y: (node.y ?? 0) - previous.y,+ z: (node.z ?? 0) - previous.z,};+ next = livelyOffset(base, rhythmSeed(node.id), t, centre, shape);}node.x = (node.x ?? 0) + (next.x - previous.x);node.y = (node.y ?? 0) + (next.y - previous.y);