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.

feat(wiki): draw the memory map as a solar system

Harald31780964955e
diff --git a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.pin.test.tsx b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.pin.test.tsx
index 9bf0f51c73..34fbad1218 100644
--- a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.pin.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.pin.test.tsx
@@ -58,7 +58,39 @@ describe("WikiGraph3D hub pin", () => {
expect(nodes[0]).toMatchObject({
x: 0, y: 0, z: 0, fx: 0, fy: 0, fz: 0,
});
- expect(nodes[1]).toMatchObject({ x: 100, y: 0, z: 0 });
+ // The neighbour is seated on a shell, not left where the pin translated it.
+ expect(Math.hypot(nodes[1].x ?? 0, nodes[1].z ?? 0)).toBeGreaterThan(50);
+ expect(nodes[1].fx).toBeUndefined();
+ });
+
+ it("seats a neighbour of the sun closer in than an isolated page", () => {
+ const nodes = [
+ node("me", { x: 0, y: 0, z: 0 }),
+ node("spotify", { x: 1, y: 0, z: 0 }),
+ node("lost", { x: 2, y: 0, z: 0 }),
+ ];
+ const links = [
+ { source: "me", target: "spotify", context: "plays", broken: false },
+ ];
+
+ render(
+ <WikiGraph3D
+ graphData={{ nodes, links }}
+ width={400}
+ height={300}
+ pivotSlug="me"
+ onNodeClick={vi.fn()}
+ resetSignal={0}
+ nodeLabel={() => ""}
+ linkLabel={() => ""}
+ />,
+ );
+
+ const inner = Math.hypot(nodes[1].x ?? 0, nodes[1].z ?? 0);
+ const outer = Math.hypot(nodes[2].x ?? 0, nodes[2].z ?? 0);
+ expect(inner).toBeGreaterThan(50);
+ expect(inner).toBeLessThan(110);
+ expect(outer).toBeGreaterThan(inner + 80);
});
it("leaves every page free when the vault has no hub", () => {
diff --git a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx
index 0c3c8c0810..b5ec6d7019 100644
--- a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx
+++ b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph3D.tsx
@@ -29,7 +29,7 @@ import {
} from "react";
import ForceGraph3D from "react-force-graph-3d";
import type { ForceGraphMethods, NodeObject } from "react-force-graph-3d";
-import type { Object3D } from "three";
+import type { Object3D, Scene } from "three";
import SpriteText from "three-spritetext";
import {
@@ -44,11 +44,22 @@ import {
CENTRING_STRENGTH,
createCentringForce,
createLivelinessForce,
+ createOrbitalForce,
+ createShellForce,
type LivelyNode,
} from "@/lib/graphForces";
import { carryOverPositions, pinPivotAtOrigin } from "@/lib/graphContinuity";
+import {
+ hopsFromHub,
+ occupiedShells,
+ seatAllOnShells,
+ shellRadius,
+ snapToShell,
+} from "@/lib/orbitalLayout";
import type { Vec3 } from "@/lib/graphCamera";
import { useGraphOrbit, type GraphCameraApi } from "@/hooks/useGraphOrbit";
+import { useThemeValue } from "@/hooks/useTheme";
+import { buildSunObject, sunPalette, syncSystemDecor } from "@/components/wiki/wikiSystem";
/** The hub is nailed here; the camera looks here. Never a live, moving node. */
const PINNED_ORIGIN: Vec3 = { x: 0, y: 0, z: 0 };
@@ -56,6 +67,9 @@ const PINNED_ORIGIN: Vec3 = { x: 0, y: 0, z: 0 };
/** Sphere radius in graph units for a node whose size score is 1.0. */
const NODE_REL_SIZE = 3;
+/** The sun is larger than any planet so the eye lands on it first. */
+const SUN_SIZE_SCORE = 3.4;
+
/**
* Above this many nodes, only hubs and the selection get a text sprite.
* Below it every node is labelled, the way the flat map does it.
@@ -77,7 +91,7 @@ const HUB_BACKLINKS = 2;
const AMBIENT_PARTICLE_LINKS = 90;
/** Colours for the focus state. Everything not near the pointer recedes. */
-const LINK_REST = "rgba(106, 169, 255, 0.5)";
+const LINK_REST = "rgba(106, 169, 255, 0.42)";
const LINK_FOCUS = "#9ecbff";
const LINK_FADED = "rgba(106, 169, 255, 0.06)";
const NODE_FADED = "#2c3340";
@@ -120,6 +134,9 @@ export function WikiGraph3D({
const graphRef = useRef<ForceGraphMethods<RenderNode, RenderEdge> | undefined>(
undefined,
);
+ const theme = useThemeValue();
+ const themeRef = useRef(theme);
+ themeRef.current = theme;
// Read through a ref for the same reason the flat map does: swapping the
// accessor functions makes the library re-ingest its whole accessor set, and
@@ -196,6 +213,24 @@ export function WikiGraph3D({
pivotSlugRef.current = pivotSlug;
/** The live pivot node object (set below, once the data is known). */
const pivotNodeRef = useRef<Partial<Vec3> | null>(null);
+
+ const hops = useMemo(() => {
+ if (!pivotSlug) return new Map<string, number>();
+ return hopsFromHub(
+ graphData.nodes.map((node) => node.id),
+ graphData.links,
+ pivotSlug,
+ );
+ }, [graphData, pivotSlug]);
+ const hopsRef = useRef(hops);
+ hopsRef.current = hops;
+ const shells = useMemo(
+ () => (pivotSlug ? occupiedShells(hops, pivotSlug) : []),
+ [hops, pivotSlug],
+ );
+ const shellsRef = useRef(shells);
+ shellsRef.current = shells;
+ const decorKeyRef = useRef("");
const reducedMotion = useMemo(
() =>
typeof window.matchMedia === "function" &&
@@ -219,26 +254,57 @@ export function WikiGraph3D({
if (!ref) return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const anyRef = ref as any;
+ const solar = Boolean(pivotSlugRef.current);
const charge = anyRef.d3Force?.("charge");
if (charge && typeof charge.strength === "function") {
- charge.strength(-420);
- // Same reach as the flat map's. A larger radius keeps pushing a node
- // that is already outside the cluster, which is how a single unlinked
- // page ends up a long way from everything and drags the camera with it.
- if (typeof charge.distanceMax === "function") charge.distanceMax(220);
+ // Softer when the sun is holding the system: a hard charge shoves
+ // planets off their shell and the map collapses back into a hairball.
+ charge.strength(solar ? -160 : -420);
+ if (typeof charge.distanceMax === "function") {
+ charge.distanceMax(solar ? 140 : 220);
+ }
}
const link = anyRef.d3Force?.("link");
if (link && typeof link.distance === "function") {
- link.distance(85);
- // Slacker than the flat map's 0.85: in three dimensions a stiff link
- // pulls the cluster back into the ball the repulsion just opened. A hub
- // with fifty children would otherwise drag them all into its own pixel.
- if (typeof link.strength === "function") link.strength(0.16);
+ if (solar) {
+ // Spokes from the sun are slack — they name a relationship, they do
+ // not haul the planet onto a rail. Planet-to-planet links stay tighter
+ // so moons keep their host.
+ link.distance((edge: RenderEdge) =>
+ endpointId(edge.source) === pivotSlugRef.current ||
+ endpointId(edge.target) === pivotSlugRef.current
+ ? 96
+ : 58,
+ );
+ if (typeof link.strength === "function") {
+ link.strength((edge: RenderEdge) =>
+ endpointId(edge.source) === pivotSlugRef.current ||
+ endpointId(edge.target) === pivotSlugRef.current
+ ? 0.04
+ : 0.2,
+ );
+ }
+ } else {
+ link.distance(85);
+ if (typeof link.strength === "function") link.strength(0.16);
+ }
}
// Bounds the world. Without it a single unlinked page drifts until it is
// out of everyone's reach, and `zoomToFit` — which frames every node —
// renders the entire vault as a marble in an empty room.
anyRef.d3Force?.("centreGravity", createCentringForce(CENTRING_STRENGTH));
+ if (solar) {
+ anyRef.d3Force?.(
+ "shell",
+ createShellForce({
+ radiusOf: (node) => {
+ if (node.id === pivotSlugRef.current) return null;
+ const hop = hopsRef.current.get(String(node.id ?? ""));
+ return shellRadius(hop ?? Number.POSITIVE_INFINITY);
+ },
+ }),
+ );
+ }
// Every page but the pivot keeps moving on its own — a bob and a small
// loop, each with its own rhythm — so the map is not a rigid body turning
// (maintainer, 2026-08-18). The pivot is read through a ref at tick time,
@@ -250,16 +316,28 @@ 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 };
},
+ // Quieter on the solar map: the Kepler turn already gives life,
+ // and a tall wave reads as noise around a sun.
+ amplitude: solar ? 4.2 : undefined,
+ breath: solar ? 0.022 : undefined,
+ wobble: solar ? 2.1 : undefined,
}),
);
+ if (solar) {
+ anyRef.d3Force?.(
+ "orbit",
+ createOrbitalForce({
+ now: () => performance.now(),
+ isPinned: (node: LivelyNode) => node.id === pivotSlugRef.current,
+ }),
+ );
+ }
}
forcesConfiguredRef.current = true;
}, [reducedMotion]);
@@ -318,6 +396,7 @@ export function WikiGraph3D({
);
const nodeVal = useCallback((node: NodeObject<RenderNode>): number => {
+ if (node.id === pivotSlugRef.current) return SUN_SIZE_SCORE ** 3;
const score = nodeSizeScore(
(node as RenderNode).backlinkCount ?? 0,
node.id === highlightRef.current,
@@ -330,6 +409,9 @@ export function WikiGraph3D({
const nodeColor = useCallback(
(node: NodeObject<RenderNode>) => {
+ if (node.id === pivotSlugRef.current) {
+ return `#${sunPalette(themeRef.current).core.toString(16).padStart(6, "0")}`;
+ }
const own = (node as RenderNode).colour ?? NODE_COLOUR.entity ?? "#8b95a7";
return isNearHover(String(node.id ?? "")) ? own : NODE_FADED;
},
@@ -337,7 +419,11 @@ export function WikiGraph3D({
);
const nodeThreeObject = useCallback(
- (node: NodeObject<RenderNode>): SpriteText | null => {
+ (node: NodeObject<RenderNode>): Object3D | SpriteText | null => {
+ if (node.id === pivotSlugRef.current) {
+ const title = (node as RenderNode).title || String(node.id ?? "");
+ return buildSunObject(title, themeRef.current, NODE_REL_SIZE * SUN_SIZE_SCORE);
+ }
const rendered = node as RenderNode;
const isActive = node.id === highlightRef.current;
const backlinks = rendered.backlinkCount ?? 0;
@@ -361,20 +447,45 @@ export function WikiGraph3D({
[labelEverything],
);
+ const extendNodeObject = useCallback(
+ (node: NodeObject<RenderNode>): boolean => node.id !== pivotSlugRef.current,
+ [],
+ );
+
+ const spokeFromSun = useCallback(
+ (link: RenderEdge): boolean => {
+ const hub = pivotSlugRef.current;
+ if (!hub) return false;
+ return endpointId(link.source) === hub || endpointId(link.target) === hub;
+ },
+ [],
+ );
+
const linkColor = useCallback(
(link: RenderEdge) => {
if (hoverId !== null) {
if (!touchesHover(link)) return LINK_FADED;
return link.broken ? BROKEN_EDGE_COLOUR : LINK_FOCUS;
}
- return link.broken ? BROKEN_EDGE_COLOUR : LINK_REST;
+ if (link.broken) return BROKEN_EDGE_COLOUR;
+ // Spokes from the sun read as light, not cables — the railroad the
+ // last cut accidentally drew.
+ if (spokeFromSun(link)) {
+ return themeRef.current === "dark"
+ ? "rgba(255, 214, 10, 0.16)"
+ : "rgba(168, 107, 0, 0.22)";
+ }
+ return LINK_REST;
},
- [hoverId, touchesHover],
+ [hoverId, spokeFromSun, touchesHover],
);
const linkWidth = useCallback(
- (link: RenderEdge) => (touchesHover(link) ? 1.4 : 0.4),
- [touchesHover],
+ (link: RenderEdge) => {
+ if (touchesHover(link)) return 1.4;
+ return spokeFromSun(link) ? 0.18 : 0.38;
+ },
+ [spokeFromSun, touchesHover],
);
// Light travelling from source to target: direction you can read at a
@@ -383,9 +494,10 @@ export function WikiGraph3D({
const linkParticles = useCallback(
(link: RenderEdge) => {
if (hoverId !== null) return touchesHover(link) ? 4 : 0;
+ if (spokeFromSun(link) && !link.broken) return 1;
return ambientParticleLinks.has(link) ? 2 : 0;
},
- [ambientParticleLinks, hoverId, touchesHover],
+ [ambientParticleLinks, hoverId, spokeFromSun, touchesHover],
);
const handleNodeHover = useCallback((node: NodeObject<RenderNode> | null) => {
@@ -396,8 +508,8 @@ export function WikiGraph3D({
// claiming a destination would be the wrong story; the rose colour carries
// it instead — the same signal the flat map's dashes carry.
const linkArrowLength = useCallback(
- (link: RenderEdge) => (link.broken ? 0 : 3.5),
- [],
+ (link: RenderEdge) => (link.broken || spokeFromSun(link) ? 0 : 3.5),
+ [spokeFromSun],
);
const linkArrowColor = useCallback(
@@ -412,8 +524,11 @@ export function WikiGraph3D({
// 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 seededSystemRef = useRef(false);
const data = useMemo(() => {
const previous = previousNodesRef.current;
+ const firstGeneration = previous.length === 0;
+ const previousIds = new Set(previous.map((node) => node.id));
if (previous !== graphData.nodes) {
const pivot = previous.find((n) => n.id === pivotSlug);
carryOverPositions(previous, graphData.nodes, graphData.links, pivot ?? {});
@@ -423,8 +538,25 @@ export function WikiGraph3D({
// page sits at the origin and stays there. The rest of the cloud is
// translated with it so the layout they already have is not torn up.
pinPivotAtOrigin(graphData.nodes, pivotSlug);
+ if (pivotSlug && graphData.nodes.length > 0) {
+ if (firstGeneration || !seededSystemRef.current) {
+ // Build the sky once. A 2D circle-seed (the flat map's first paint)
+ // is overwritten so the 3D view is a system, not a disc.
+ seatAllOnShells(graphData.nodes, graphData.links, pivotSlug);
+ pinPivotAtOrigin(graphData.nodes, pivotSlug);
+ seededSystemRef.current = true;
+ } else {
+ for (const node of graphData.nodes) {
+ if (node.id === pivotSlug || previousIds.has(node.id)) continue;
+ snapToShell(
+ node,
+ hops.get(node.id) ?? Number.POSITIVE_INFINITY,
+ );
+ }
+ }
+ }
return graphData;
- }, [graphData, pivotSlug]);
+ }, [graphData, hops, pivotSlug]);
const holdHub = useCallback((node: NodeObject<RenderNode>): void => {
if (node.id !== pivotSlugRef.current) return;
@@ -465,7 +597,7 @@ export function WikiGraph3D({
nodeThreeObject={
nodeThreeObject as unknown as (node: NodeObject<RenderNode>) => Object3D
}
- nodeThreeObjectExtend
+ nodeThreeObjectExtend={extendNodeObject}
linkLabel={linkLabel}
linkColor={linkColor}
linkOpacity={0.6}
@@ -476,7 +608,13 @@ export function WikiGraph3D({
linkDirectionalParticles={linkParticles}
linkDirectionalParticleSpeed={0.006}
linkDirectionalParticleWidth={1.3}
- linkDirectionalParticleColor={() => PARTICLE_COLOUR}
+ linkDirectionalParticleColor={(link: RenderEdge) =>
+ spokeFromSun(link)
+ ? themeRef.current === "dark"
+ ? "#ffe680"
+ : "#a86b00"
+ : PARTICLE_COLOUR
+ }
onNodeClick={handleNodeClick}
onNodeHover={handleNodeHover}
onNodeDrag={holdHub}
@@ -498,7 +636,17 @@ export function WikiGraph3D({
d3VelocityDecay={0.6}
d3AlphaDecay={0.04}
warmupTicks={40}
- onEngineTick={configureForces}
+ onEngineTick={() => {
+ configureForces();
+ if (!pivotSlugRef.current) return;
+ const graph = graphRef.current as unknown as { scene?: () => Scene };
+ const scene = graph.scene?.();
+ if (!scene) return;
+ const key = `${themeRef.current}:${shellsRef.current.join(",")}`;
+ if (decorKeyRef.current === key) return;
+ syncSystemDecor(scene, themeRef.current, shellsRef.current);
+ decorKeyRef.current = key;
+ }}
onEngineStop={reframe}
/>
<div
diff --git a/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.test.ts b/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.test.ts
new file mode 100644
index 0000000000..34c8b51d09
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.test.ts
@@ -0,0 +1,14 @@
+import { describe, expect, it } from "vitest";
+
+import { sunPalette } from "@/components/wiki/wikiSystem";
+
+describe("sunPalette", () => {
+ it("uses signal-yellow on dark and gold on light — never the same hex", () => {
+ const dark = sunPalette("dark");
+ const light = sunPalette("light");
+ expect(dark.core).toBe(0xffd60a);
+ expect(light.core).toBe(0xa86b00);
+ expect(dark.core).not.toBe(light.core);
+ expect(dark.ringOpacity).toBeLessThan(light.ringOpacity);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.ts b/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.ts
new file mode 100644
index 0000000000..2de352805d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/wiki/wikiSystem.ts
@@ -0,0 +1,189 @@
+/**
+ * The sun, its corona, the dust rings and the light they throw.
+ *
+ * Colours come from a per-appearance table — signal-yellow on dark, gold on
+ * light — never one hex on both grounds (CLOUD.md frontend theming).
+ */
+import {
+ AdditiveBlending,
+ BufferGeometry,
+ CanvasTexture,
+ Group,
+ Line,
+ LineBasicMaterial,
+ Mesh,
+ MeshBasicMaterial,
+ NormalBlending,
+ PointLight,
+ SphereGeometry,
+ Sprite,
+ SpriteMaterial,
+ Vector3,
+ type Scene,
+ type Texture,
+} from "three";
+import SpriteText from "three-spritetext";
+
+import type { Theme } from "@/hooks/useTheme";
+
+export interface SunPalette {
+ core: number;
+ glowRgb: string;
+ light: number;
+ ring: number;
+ ringOpacity: number;
+ lightIntensity: number;
+ coronaScale: number;
+}
+
+const PALETTE: Record<Theme, SunPalette> = {
+ dark: {
+ core: 0xffd60a,
+ glowRgb: "255, 214, 10",
+ light: 0xffe680,
+ ring: 0xffe08a,
+ ringOpacity: 0.11,
+ lightIntensity: 2.1,
+ coronaScale: 6.4,
+ },
+ light: {
+ core: 0xa86b00,
+ glowRgb: "168, 107, 0",
+ light: 0xc49214,
+ ring: 0x8a5a00,
+ ringOpacity: 0.2,
+ lightIntensity: 1.15,
+ coronaScale: 5.2,
+ },
+};
+
+export function sunPalette(theme: Theme): SunPalette {
+ return PALETTE[theme];
+}
+
+const SUN_LIGHT_NAME = "wiki-sun-light";
+const SUN_RING_NAME = "wiki-orbit-ring";
+
+let glowCache: { theme: Theme; texture: Texture } | null = null;
+
+function coronaTexture(theme: Theme, glowRgb: string): Texture | null {
+ if (glowCache?.theme === theme) return glowCache.texture;
+ if (typeof document === "undefined") return null;
+ const canvas = document.createElement("canvas");
+ canvas.width = 128;
+ canvas.height = 128;
+ const ctx = canvas.getContext("2d");
+ if (!ctx) return null;
+ const gradient = ctx.createRadialGradient(64, 64, 6, 64, 64, 64);
+ gradient.addColorStop(0, `rgba(255, 248, 220, 0.95)`);
+ gradient.addColorStop(0.22, `rgba(${glowRgb}, 0.55)`);
+ gradient.addColorStop(0.55, `rgba(${glowRgb}, 0.16)`);
+ gradient.addColorStop(1, `rgba(${glowRgb}, 0)`);
+ ctx.fillStyle = gradient;
+ ctx.fillRect(0, 0, 128, 128);
+ const texture = new CanvasTexture(canvas);
+ texture.needsUpdate = true;
+ glowCache = { theme, texture };
+ return texture;
+}
+
+/** The sun that replaces the hub's default sphere — core, corona, label. */
+export function buildSunObject(
+ title: string,
+ theme: Theme,
+ radius: number,
+): Group {
+ const palette = sunPalette(theme);
+ const group = new Group();
+ group.name = "wiki-sun";
+
+ const core = new Mesh(
+ new SphereGeometry(radius, 28, 28),
+ new MeshBasicMaterial({ color: palette.core }),
+ );
+ group.add(core);
+
+ const glowMap = coronaTexture(theme, palette.glowRgb);
+ if (glowMap) {
+ const corona = new Sprite(
+ new SpriteMaterial({
+ map: glowMap,
+ color: palette.core,
+ transparent: true,
+ depthWrite: false,
+ blending: theme === "dark" ? AdditiveBlending : NormalBlending,
+ opacity: theme === "dark" ? 0.95 : 0.7,
+ }),
+ );
+ const span = radius * palette.coronaScale;
+ corona.scale.set(span, span, 1);
+ group.add(corona);
+ }
+
+ if (title) {
+ const label = new SpriteText(title);
+ label.color = theme === "dark" ? "#fff3c4" : "#5a3a00";
+ label.textHeight = 5.8;
+ label.position.set(0, -(radius + 5), 0);
+ group.add(label);
+ }
+
+ return group;
+}
+
+function makeRing(radius: number, tilt: number, palette: SunPalette): Line {
+ const points: Vector3[] = [];
+ const steps = 160;
+ for (let i = 0; i <= steps; i++) {
+ const angle = (i / steps) * Math.PI * 2;
+ points.push(new Vector3(Math.cos(angle) * radius, 0, Math.sin(angle) * radius));
+ }
+ const line = new Line(
+ new BufferGeometry().setFromPoints(points),
+ new LineBasicMaterial({
+ color: palette.ring,
+ transparent: true,
+ opacity: palette.ringOpacity,
+ depthWrite: false,
+ }),
+ );
+ line.name = SUN_RING_NAME;
+ line.rotation.x = tilt;
+ line.rotation.z = tilt * 0.35;
+ return line;
+}
+
+/**
+ * Keep the scene's sun-light and dust rings in step with the theme and the
+ * shells that currently have pages on them. Named objects are replaced, never
+ * stacked, so a data refresh does not leave a trail of rings behind.
+ */
+export function syncSystemDecor(
+ scene: Scene,
+ theme: Theme,
+ shells: readonly number[],
+): void {
+ const palette = sunPalette(theme);
+
+ const stale: Array<Line | PointLight> = [];
+ scene.traverse((obj) => {
+ if (obj.name === SUN_LIGHT_NAME || obj.name === SUN_RING_NAME) {
+ stale.push(obj as Line | PointLight);
+ }
+ });
+ for (const obj of stale) {
+ obj.removeFromParent();
+ }
+
+ const light = new PointLight(palette.light, palette.lightIntensity, 520, 2);
+ light.name = SUN_LIGHT_NAME;
+ light.position.set(0, 0, 0);
+ scene.add(light);
+
+ // At most three rings — one per occupied band, nearest first. A ring per
+ // page would be the railroad the seating is designed not to be.
+ const tilts = [0.14, -0.09, 0.2];
+ shells.slice(0, 3).forEach((radius, i) => {
+ scene.add(makeRing(radius, tilts[i] ?? 0.1, palette));
+ });
+}
diff --git a/jarvis/ui/web/frontend/src/lib/graphForces.test.ts b/jarvis/ui/web/frontend/src/lib/graphForces.test.ts
index 8afdc29ad4..114a87865b 100644
--- a/jarvis/ui/web/frontend/src/lib/graphForces.test.ts
+++ b/jarvis/ui/web/frontend/src/lib/graphForces.test.ts
@@ -10,6 +10,9 @@ import {
LIVELINESS_BREATH,
LIVELINESS_WOBBLE,
createLivelinessForce,
+ createOrbitalForce,
+ createShellForce,
+ orbitPeriodMs,
rhythmSeed,
type LivelyNode,
} from "@/lib/graphForces";
@@ -133,3 +136,84 @@ describe("createLivelinessForce", () => {
expect(rhythmSeed(undefined)).toBeLessThanOrEqual(1);
});
});
+
+describe("createShellForce", () => {
+ it("pulls a page that drifted inward back out, and leaves the sun alone", () => {
+ const nodes: LivelyNode[] = [
+ { id: "me", x: 0, y: 0, z: 0, vx: 0, vz: 0 },
+ { id: "spotify", x: 20, y: 0, z: 0, vx: 0, vz: 0 },
+ ];
+ const force = createShellForce({
+ radiusOf: (n) => (n.id === "me" ? null : 80),
+ strength: 0.5,
+ });
+ force.initialize(nodes);
+ force(1);
+ expect(nodes[0].vx).toBe(0);
+ expect(nodes[1].vx).toBeGreaterThan(0);
+ });
+});
+
+describe("createOrbitalForce", () => {
+ it("never moves the sun", () => {
+ const nodes: LivelyNode[] = [
+ { id: "me", x: 0, y: 0, z: 0 },
+ { id: "spotify", x: 72, y: 0, z: 0 },
+ ];
+ let t = 0;
+ const force = createOrbitalForce({
+ now: () => t,
+ isPinned: (n) => n.id === "me",
+ });
+ force.initialize(nodes);
+ t = 4_000;
+ force(0);
+ expect(nodes[0]).toMatchObject({ x: 0, y: 0, z: 0 });
+ });
+
+ it("turns a page a quarter of its own period, and turns an inner page further", () => {
+ const inner: LivelyNode = { id: "close", x: 72, y: 0, z: 0 };
+ const outer: LivelyNode = { id: "far", x: 216, y: 0, z: 0 };
+ let t = 0;
+ const force = createOrbitalForce({
+ now: () => t,
+ isPinned: () => false,
+ direction: 1,
+ });
+ force.initialize([inner, outer]);
+ const quarter = orbitPeriodMs(72) / 4;
+ // The force caps a single step, so walk there in 80 ms bites.
+ for (let step = 80; step <= quarter; step += 80) {
+ t = step;
+ force(0);
+ }
+ const innerAngle = Math.atan2(inner.z ?? 0, inner.x ?? 0);
+ const outerAngle = Math.atan2(outer.z ?? 0, outer.x ?? 0);
+ expect(innerAngle).toBeGreaterThan(1.2);
+ expect(innerAngle).toBeLessThan(2.0);
+ expect(Math.abs(innerAngle)).toBeGreaterThan(Math.abs(outerAngle) + 0.4);
+ expect(Math.hypot(inner.x ?? 0, inner.z ?? 0)).toBeCloseTo(72, 5);
+ });
+
+ it("rotates a liveliness offset with the page so the two stay composed", () => {
+ const node: LivelyNode = {
+ id: "spotify",
+ x: 72,
+ y: 0,
+ z: 0,
+ __lively: { x: 4, y: 1, z: 0 },
+ };
+ let t = 0;
+ const force = createOrbitalForce({
+ now: () => t,
+ isPinned: () => false,
+ });
+ force.initialize([node]);
+ t = 80;
+ force(0);
+ const posAngle = Math.atan2(node.z ?? 0, node.x ?? 0);
+ const liveAngle = Math.atan2(node.__lively!.z, node.__lively!.x);
+ expect(liveAngle).toBeCloseTo(posAngle, 5);
+ });
+});
+
diff --git a/jarvis/ui/web/frontend/src/lib/graphForces.ts b/jarvis/ui/web/frontend/src/lib/graphForces.ts
index 431b01379a..ea81948781 100644
--- a/jarvis/ui/web/frontend/src/lib/graphForces.ts
+++ b/jarvis/ui/web/frontend/src/lib/graphForces.ts
@@ -255,3 +255,150 @@ export function createLivelinessForce(options: LivelinessOptions): LivelinessFor
return force;
}
+
+// ----------------------------------------------------------------------
+// Shell + Kepler — the solar-system layer on top of the layout
+// ----------------------------------------------------------------------
+
+export interface ShellNode extends SimNode {
+ id?: string | number;
+}
+
+export interface ShellForce {
+ (alpha: number): void;
+ initialize: (nodes: ShellNode[]) => void;
+}
+
+export interface ShellForceOptions {
+ /** Preferred horizontal radius. `null` skips the node (the sun). */
+ radiusOf: (node: ShellNode) => number | null;
+ /** Pull per unit of radial error. Soft — a belt, not a rail. */
+ strength?: number;
+}
+
+/**
+ * Floor so the pull still holds after d3's alpha has gone cold. The engine
+ * keeps ticking for the liveliness / orbit, and without a rest strength the
+ * pages would slowly walk off their band.
+ */
+const SHELL_ALPHA_FLOOR = 0.18;
+
+/** Soft enough that the wave and the wobble still read; strong enough to hold a belt. */
+export const SHELL_STRENGTH = 0.07;
+
+/**
+ * Ease each page toward its shell radius in the horizontal plane.
+ *
+ * Only the distance from the sun is constrained. Angle, height and the
+ * liveliness offset are left alone — that is what keeps this from becoming
+ * a set of railroad tracks.
+ */
+export function createShellForce(options: ShellForceOptions): ShellForce {
+ const strength = options.strength ?? SHELL_STRENGTH;
+ let nodes: ShellNode[] = [];
+
+ const force = ((alpha: number): void => {
+ const k = strength * Math.max(alpha, SHELL_ALPHA_FLOOR);
+ if (k === 0) return;
+ for (const node of nodes) {
+ const target = options.radiusOf(node);
+ if (target === null) continue;
+ const x = node.x ?? 0;
+ const z = node.z ?? 0;
+ const reach = Math.hypot(x, z);
+ if (reach < 1e-6) continue;
+ const pull = ((reach - target) / reach) * k;
+ node.vx = (node.vx ?? 0) - x * pull;
+ node.vz = (node.vz ?? 0) - z * pull;
+ }
+ }) as ShellForce;
+
+ force.initialize = (next: ShellNode[]): void => {
+ nodes = next ?? [];
+ };
+
+ return force;
+}
+
+export interface OrbitalForce {
+ (alpha: number): void;
+ initialize: (nodes: LivelyNode[]) => void;
+}
+
+export interface OrbitalForceOptions {
+ now: () => number;
+ isPinned: (node: LivelyNode) => boolean;
+ /** Sign of the turn in the XZ plane. +1 is +atan2. */
+ direction?: number;
+}
+
+/**
+ * Period at the reference radius. Inner pages go faster (Kepler: T ∝ r^1.5),
+ * so a neighbour of the sun laps the kuiper belt instead of the whole sky
+ * turning as one rigid body — the thing that made the last cut feel cheap.
+ */
+export const ORBIT_REFERENCE_RADIUS = 72;
+export const ORBIT_REFERENCE_PERIOD_MS = 36_000;
+
+/** Opposite the camera's clockwise turn, so the planets actually sweep past. */
+export const PLANET_ORBIT_DIRECTION = 1;
+
+/** Cap a stalled frame so a tab-switch does not jump a page a quarter-turn. */
+const ORBIT_MAX_STEP_MS = 100;
+
+export function orbitPeriodMs(radius: number): number {
+ const r = Math.max(radius, 1);
+ return ORBIT_REFERENCE_PERIOD_MS * (r / ORBIT_REFERENCE_RADIUS) ** 1.5;
+}
+
+/**
+ * Walk each page around the sun at its own speed.
+ *
+ * Applied as a rotation of the current position (and of the liveliness
+ * offset, so the two stay composed). The hub is left alone.
+ */
+export function createOrbitalForce(options: OrbitalForceOptions): OrbitalForce {
+ const direction = options.direction ?? PLANET_ORBIT_DIRECTION;
+ let nodes: LivelyNode[] = [];
+ let last = options.now();
+
+ const force = ((_alpha: number): void => {
+ const now = options.now();
+ const elapsed = Math.min(Math.max(now - last, 0), ORBIT_MAX_STEP_MS);
+ last = now;
+ if (elapsed === 0) return;
+
+ for (const node of nodes) {
+ if (options.isPinned(node)) continue;
+ const x = node.x ?? 0;
+ const z = node.z ?? 0;
+ const reach = Math.hypot(x, z);
+ if (reach < 1e-6) continue;
+
+ const angle = direction * (elapsed / orbitPeriodMs(reach)) * Math.PI * 2;
+ const cos = Math.cos(angle);
+ const sin = Math.sin(angle);
+ node.x = x * cos - z * sin;
+ node.z = x * sin + z * cos;
+
+ const vx = node.vx ?? 0;
+ const vz = node.vz ?? 0;
+ node.vx = vx * cos - vz * sin;
+ node.vz = vx * sin + vz * cos;
+
+ const lively = node.__lively;
+ if (lively) {
+ const lx = lively.x;
+ const lz = lively.z;
+ lively.x = lx * cos - lz * sin;
+ lively.z = lx * sin + lz * cos;
+ }
+ }
+ }) as OrbitalForce;
+
+ force.initialize = (next: LivelyNode[]): void => {
+ nodes = next ?? [];
+ };
+
+ return force;
+}
diff --git a/jarvis/ui/web/frontend/src/lib/orbitalLayout.test.ts b/jarvis/ui/web/frontend/src/lib/orbitalLayout.test.ts
new file mode 100644
index 0000000000..fb5642ad71
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/orbitalLayout.test.ts
@@ -0,0 +1,109 @@
+/**
+ * The memory map seats like a solar system: neighbours of the sun close in,
+ * strangers out, the same vault always the same sky.
+ */
+import { describe, expect, it } from "vitest";
+
+import {
+ hopsFromHub,
+ occupiedShells,
+ orbitPose,
+ seatAllOnShells,
+ shellRadius,
+ snapToShell,
+ KUIPER_RADIUS,
+ SHELL_RADIUS,
+} from "@/lib/orbitalLayout";
+
+describe("hopsFromHub", () => {
+ it("counts wikilink hops from the sun and sends isolates to infinity", () => {
+ const hops = hopsFromHub(
+ ["me", "spotify", "album", "stray"],
+ [
+ { source: "me", target: "spotify" },
+ { source: "spotify", target: "album" },
+ ],
+ "me",
+ );
+ expect(hops.get("me")).toBe(0);
+ expect(hops.get("spotify")).toBe(1);
+ expect(hops.get("album")).toBe(2);
+ expect(hops.get("stray")).toBe(Number.POSITIVE_INFINITY);
+ });
+
+ it("treats a missing hub as a sky of isolates", () => {
+ const hops = hopsFromHub(["a", "b"], [{ source: "a", target: "b" }], "me");
+ expect(hops.get("a")).toBe(Number.POSITIVE_INFINITY);
+ expect(hops.get("b")).toBe(Number.POSITIVE_INFINITY);
+ });
+});
+
+describe("shellRadius", () => {
+ it("puts the sun at the origin and isolates in the kuiper belt", () => {
+ expect(shellRadius(0)).toBe(0);
+ expect(shellRadius(1)).toBe(SHELL_RADIUS[1]);
+ expect(shellRadius(2)).toBe(SHELL_RADIUS[2]);
+ expect(shellRadius(Number.POSITIVE_INFINITY)).toBe(KUIPER_RADIUS);
+ expect(shellRadius(99)).toBe(KUIPER_RADIUS);
+ });
+});
+
+describe("orbitPose / seatAllOnShells", () => {
+ it("gives a page the same seat every time", () => {
+ expect(orbitPose("spotify", 1, 0, 3)).toEqual(orbitPose("spotify", 1, 0, 3));
+ });
+
+ it("sits direct neighbours closer in than a stranger", () => {
+ const nodes: Array<{ id: string; x?: number; y?: number; z?: number }> = [
+ { id: "me" },
+ { id: "spotify" },
+ { id: "calendar" },
+ { id: "lost" },
+ ];
+ const seated = seatAllOnShells(
+ nodes,
+ [
+ { source: "me", target: "spotify" },
+ { source: "me", target: "calendar" },
+ ],
+ "me",
+ );
+ expect(seated).toBe(3);
+ expect(nodes[0]).toMatchObject({ x: 0, y: 0, z: 0 });
+ const inner = Math.hypot(nodes[1].x ?? 0, nodes[1].z ?? 0);
+ const alsoInner = Math.hypot(nodes[2].x ?? 0, nodes[2].z ?? 0);
+ const outer = Math.hypot(nodes[3].x ?? 0, nodes[3].z ?? 0);
+ expect(inner).toBeGreaterThan(50);
+ expect(inner).toBeLessThan(100);
+ expect(alsoInner).toBeGreaterThan(50);
+ expect(alsoInner).toBeLessThan(100);
+ expect(outer).toBeGreaterThan(inner + 80);
+ });
+
+ it("keeps two neighbours off one spot", () => {
+ const a = orbitPose("one", 1, 0, 2);
+ const b = orbitPose("two", 1, 1, 2);
+ expect(Math.hypot(a.x - b.x, a.z - b.z)).toBeGreaterThan(40);
+ });
+});
+
+describe("snapToShell / occupiedShells", () => {
+ it("keeps the angle and only changes how far out the page sits", () => {
+ const node = { id: "spotify", x: 10, y: 4, z: 0 };
+ snapToShell(node, 1);
+ const angle = Math.atan2(node.z ?? 0, node.x ?? 0);
+ expect(angle).toBeCloseTo(0, 5);
+ expect(Math.hypot(node.x ?? 0, node.z ?? 0)).toBeGreaterThan(50);
+ expect(node.y).toBe(4);
+ });
+
+ it("names each band that actually has a page on it", () => {
+ const hops = new Map<string, number>([
+ ["me", 0],
+ ["a", 1],
+ ["b", 1],
+ ["c", Number.POSITIVE_INFINITY],
+ ]);
+ expect(occupiedShells(hops, "me")).toEqual([SHELL_RADIUS[1], KUIPER_RADIUS]);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/orbitalLayout.ts b/jarvis/ui/web/frontend/src/lib/orbitalLayout.ts
new file mode 100644
index 0000000000..482386c793
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/orbitalLayout.ts
@@ -0,0 +1,191 @@
+/**
+ * Seat a memory map like a solar system.
+ *
+ * The hub is the sun (already pinned at the origin). Every other page sits on
+ * a SHELL whose radius is how many wikilinks it is from that sun — neighbours
+ * close in, strangers out in the kuiper belt. Angles and a little eccentricity
+ * come from the page id, so the same vault always draws the same sky and two
+ * neighbours never land on one spot.
+ *
+ * This is a seating, not a track. Nothing here locks a page to a circle; the
+ * shell and orbital forces (graphForces) keep them near their band while they
+ * still breathe and wobble. Rigid rails are the thing the maintainer asked
+ * us not to build.
+ */
+
+import { rhythmSeed } from "@/lib/graphForces";
+
+export interface OrbitalNode {
+ id: string;
+ x?: number;
+ y?: number;
+ z?: number;
+}
+
+export interface OrbitalLink {
+ source: string | { id: string };
+ target: string | { id: string };
+}
+
+/** Graph units. Index is hop-count from the hub; 0 is the sun itself. */
+export const SHELL_RADIUS = [0, 72, 128, 184, 236] as const;
+
+/** Isolated pages sit out here, like a comet that never fell in. */
+export const KUIPER_RADIUS = 280;
+
+function idOf(endpoint: string | { id: string }): string {
+ return typeof endpoint === "string" ? endpoint : endpoint.id;
+}
+
+/** Hop-count from the hub. Unreachable pages are `Infinity`. The hub is 0. */
+export function hopsFromHub(
+ nodeIds: readonly string[],
+ links: readonly OrbitalLink[],
+ hubId: string,
+): Map<string, number> {
+ const hops = new Map<string, number>();
+ const known = new Set(nodeIds);
+ if (!known.has(hubId)) {
+ for (const id of nodeIds) hops.set(id, Number.POSITIVE_INFINITY);
+ return hops;
+ }
+
+ const adj = new Map<string, string[]>();
+ for (const id of nodeIds) adj.set(id, []);
+ for (const link of links) {
+ const a = idOf(link.source);
+ const b = idOf(link.target);
+ if (!known.has(a) || !known.has(b) || a === b) continue;
+ adj.get(a)!.push(b);
+ adj.get(b)!.push(a);
+ }
+
+ hops.set(hubId, 0);
+ const queue = [hubId];
+ for (let i = 0; i < queue.length; i++) {
+ const here = queue[i];
+ const nextHop = (hops.get(here) ?? 0) + 1;
+ for (const neighbour of adj.get(here) ?? []) {
+ if (hops.has(neighbour)) continue;
+ hops.set(neighbour, nextHop);
+ queue.push(neighbour);
+ }
+ }
+ for (const id of nodeIds) {
+ if (!hops.has(id)) hops.set(id, Number.POSITIVE_INFINITY);
+ }
+ return hops;
+}
+
+/** The shell a page of this hop belongs on. */
+export function shellRadius(hop: number): number {
+ if (hop === 0) return 0;
+ if (!Number.isFinite(hop) || hop >= SHELL_RADIUS.length) return KUIPER_RADIUS;
+ return SHELL_RADIUS[hop] ?? KUIPER_RADIUS;
+}
+
+/** The distinct shell radii we actually have pages on — used to draw dust rings. */
+export function occupiedShells(
+ hops: ReadonlyMap<string, number>,
+ hubId: string,
+): number[] {
+ const seen = new Set<number>();
+ for (const [id, hop] of hops) {
+ if (id === hubId) continue;
+ seen.add(shellRadius(hop));
+ }
+ return [...seen].sort((a, b) => a - b);
+}
+
+export interface OrbitPose {
+ x: number;
+ y: number;
+ z: number;
+}
+
+/**
+ * Where one page sits on its shell. Pure: the same (id, hop, index, count)
+ * always produces the same point.
+ *
+ * Radius is jittered so the band is a belt, not a wire. Inclination is small
+ * so the system has volume without standing on its end.
+ */
+export function orbitPose(
+ id: string,
+ hop: number,
+ index: number,
+ count: number,
+): OrbitPose {
+ const seed = rhythmSeed(id);
+ const seedB = rhythmSeed(`${id}\0`);
+ const radius = shellRadius(hop) * (0.88 + seed * 0.24);
+ const spread = Math.max(1, count);
+ const theta = (Math.PI * 2 * index) / spread + (seed - 0.5) * 0.8;
+ const lift = Math.sin((seedB - 0.5) * 0.55) * radius * 0.38;
+ return {
+ x: Math.cos(theta) * radius,
+ y: lift,
+ z: Math.sin(theta) * radius,
+ };
+}
+
+/** Pull a placed page onto its shell, keeping the angle it already has. */
+export function snapToShell(node: OrbitalNode, hop: number): void {
+ const seed = rhythmSeed(node.id);
+ const target = shellRadius(hop) * (0.88 + seed * 0.24);
+ const x = node.x ?? 0;
+ const z = node.z ?? 0;
+ const reach = Math.hypot(x, z);
+ if (reach < 1e-6) {
+ const pose = orbitPose(node.id, hop, 0, 1);
+ node.x = pose.x;
+ node.y = pose.y;
+ node.z = pose.z;
+ return;
+ }
+ const scale = target / reach;
+ node.x = x * scale;
+ node.z = z * scale;
+ if (!Number.isFinite(node.y)) node.y = 0;
+}
+
+/**
+ * Place every page but the hub onto its shell. The hub is left at the origin.
+ *
+ * @returns how many pages were seated
+ */
+export function seatAllOnShells(
+ nodes: OrbitalNode[],
+ links: readonly OrbitalLink[],
+ hubId: string,
+): number {
+ const hops = hopsFromHub(
+ nodes.map((node) => node.id),
+ links,
+ hubId,
+ );
+ const buckets = new Map<number, OrbitalNode[]>();
+ for (const node of nodes) {
+ if (node.id === hubId) {
+ node.x = 0;
+ node.y = 0;
+ node.z = 0;
+ continue;
+ }
+ const hop = hops.get(node.id) ?? Number.POSITIVE_INFINITY;
+ const bucket = buckets.get(hop) ?? [];
+ bucket.push(node);
+ buckets.set(hop, bucket);
+ }
+ let seated = 0;
+ for (const [hop, bucket] of buckets) {
+ bucket.forEach((node, index) => {
+ const pose = orbitPose(node.id, hop, index, bucket.length);
+ node.x = pose.x;
+ node.y = pose.y;
+ node.z = pose.z;
+ seated += 1;
+ });
+ }
+ return seated;
+}