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(society): rendered headshots in the rail, and the island's own strings

rubenluetke10-beepd015c3a69a01
diff --git a/jarvis/ui/web/frontend/src/components/society/AgentSwatch.tsx b/jarvis/ui/web/frontend/src/components/society/AgentSwatch.tsx
index f9c2198f76..0e41fe2dc1 100644
--- a/jarvis/ui/web/frontend/src/components/society/AgentSwatch.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/AgentSwatch.tsx
@@ -1,13 +1,45 @@
/**
- * The flat stand-in for an agent's face wherever a 3D canvas would be
- * wasteful — roster rows, card headers, chips. Skin over the primary
- * garment, the accent as a ring: the same colours the figure wears, so a
- * row and its character read as one agent.
+ * An agent's face wherever a 3D canvas would be wasteful — roster rows, card
+ * headers, chips. A rendered headshot of the agent's own figure when the
+ * look has a built base (faceCrop.ts); until it arrives, and for a row with
+ * no figure, the flat stand-in: skin over the primary garment with the
+ * accent as a ring, the same colours the figure wears.
*/
+import { useEffect, useState } from "react";
+
import { cn } from "@/lib/utils";
import type { SocietyAgent } from "./data";
-import { resolvePalette } from "./figures/figureRecipe";
+import { faceCrop } from "./figures/faceCrop";
+import { recipeKey, resolvePalette, type FigureRecipe } from "./figures/figureRecipe";
+
+const crops = new Map<string, string>();
+
+function useFaceCrop(figure: FigureRecipe | null): string | null {
+ const key = figure ? recipeKey(figure) : "";
+ const [url, setUrl] = useState<string | null>(() => (key ? (crops.get(key) ?? null) : null));
+ useEffect(() => {
+ if (!figure || !key) {
+ setUrl(null);
+ return;
+ }
+ const cached = crops.get(key);
+ if (cached) {
+ setUrl(cached);
+ return;
+ }
+ let live = true;
+ void faceCrop(figure).then((data) => {
+ if (!live) return;
+ if (data) crops.set(key, data);
+ setUrl(data);
+ });
+ return () => {
+ live = false;
+ };
+ }, [figure, key]);
+ return url;
+}
export function AgentSwatch({
agent,
@@ -21,6 +53,7 @@ export function AgentSwatch({
const palette = resolvePalette(agent.figure);
const primary = agent.figure ? palette.primary : agent.palette.primary;
const accent = agent.figure ? palette.accent : agent.palette.accent;
+ const crop = useFaceCrop(agent.figure);
return (
<span
aria-hidden
@@ -32,16 +65,26 @@ export function AgentSwatch({
boxShadow: `inset 0 0 0 2px ${accent}55`,
}}
>
- <span
- className="rounded-full"
- style={{
- width: size * 0.42,
- height: size * 0.42,
- marginBottom: size * 0.12,
- background: palette.skin,
- boxShadow: `0 ${-size * 0.12}px 0 0 ${palette.hair}`,
- }}
- />
+ {crop ? (
+ <img
+ src={crop}
+ alt=""
+ draggable={false}
+ className="absolute inset-0 h-full w-full object-cover"
+ style={{ imageRendering: size <= 40 ? "auto" : "pixelated" }}
+ />
+ ) : (
+ <span
+ className="rounded-full"
+ style={{
+ width: size * 0.42,
+ height: size * 0.42,
+ marginBottom: size * 0.12,
+ background: palette.skin,
+ boxShadow: `0 ${-size * 0.12}px 0 0 ${palette.hair}`,
+ }}
+ />
+ )}
</span>
);
}
diff --git a/jarvis/ui/web/frontend/src/components/society/figures/faceCrop.ts b/jarvis/ui/web/frontend/src/components/society/figures/faceCrop.ts
new file mode 100644
index 0000000000..7455906ee5
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/figures/faceCrop.ts
@@ -0,0 +1,122 @@
+/**
+ * A rendered headshot per look — the face the roster rail, chat avatars and
+ * nameplates show instead of a colour circle (character-pipeline.md §9.1).
+ *
+ * One hidden renderer serves every crop in turn: a 96×96 frame of the
+ * assembled figure's head, read back as a PNG data URL and cached by the
+ * recipe's key. The renderer is created on the first request and its
+ * context is handed back (`forceContextLoss` + `dispose`) after a few idle
+ * seconds — the page has sixteen contexts in total (AP-32) and a headshot
+ * queue must never hold one open. Loads go through one GLTFLoader cache of
+ * its own; drei's cache belongs to React trees.
+ */
+import * as THREE from "three";
+import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
+
+import { assembleFigure, type LoadedGltf } from "./assembleFigure";
+import { recipeKey, resolvePalette, type FigureRecipe } from "./figureRecipe";
+import { figureAssetFor, partAssetsFor } from "./figureRegistry";
+
+const SIZE = 96;
+const IDLE_RELEASE_MS = 4000;
+
+const crops = new Map<string, Promise<string | null>>();
+const gltfs = new Map<string, Promise<LoadedGltf>>();
+let loader: GLTFLoader | null = null;
+let stage: { renderer: THREE.WebGLRenderer; scene: THREE.Scene; camera: THREE.PerspectiveCamera } | null = null;
+let releaseTimer = 0;
+
+function loadGltf(url: string): Promise<LoadedGltf> {
+ let pending = gltfs.get(url);
+ if (!pending) {
+ loader ??= new GLTFLoader();
+ pending = loader.loadAsync(url) as unknown as Promise<LoadedGltf>;
+ gltfs.set(url, pending);
+ }
+ return pending;
+}
+
+function acquireStage() {
+ window.clearTimeout(releaseTimer);
+ if (stage) return stage;
+ const canvas = document.createElement("canvas");
+ canvas.width = SIZE;
+ canvas.height = SIZE;
+ const renderer = new THREE.WebGLRenderer({
+ canvas,
+ alpha: true,
+ antialias: false,
+ preserveDrawingBuffer: true,
+ powerPreference: "low-power",
+ });
+ renderer.setPixelRatio(1);
+ renderer.setSize(SIZE, SIZE, false);
+ renderer.setClearColor(0x000000, 0);
+ const scene = new THREE.Scene();
+ scene.add(new THREE.HemisphereLight(0xffffff, 0x8fa0b3, 1.15));
+ const key = new THREE.DirectionalLight(0xffffff, 1.9);
+ key.position.set(2.2, 4.5, 3.2);
+ scene.add(key);
+ const fill = new THREE.DirectionalLight(0xffffff, 0.45);
+ fill.position.set(-3, 2, -2);
+ scene.add(fill);
+ const camera = new THREE.PerspectiveCamera(24, 1, 0.05, 20);
+ stage = { renderer, scene, camera };
+ return stage;
+}
+
+function scheduleRelease() {
+ window.clearTimeout(releaseTimer);
+ releaseTimer = window.setTimeout(() => {
+ if (!stage) return;
+ // Hand the context back: dispose() alone keeps it (useWebglSurface's lesson).
+ stage.renderer.forceContextLoss();
+ stage.renderer.dispose();
+ stage = null;
+ }, IDLE_RELEASE_MS);
+}
+
+async function renderCrop(recipe: FigureRecipe): Promise<string | null> {
+ const asset = figureAssetFor(recipe);
+ if (!asset) return null;
+ const parts = partAssetsFor(recipe);
+ const [base, ...partGltfs] = await Promise.all([loadGltf(asset.url), ...parts.map((p) => loadGltf(p.url))]);
+ const height = recipe.heightM ?? asset.defaultHeightM;
+ const figure = assembleFigure(base, resolvePalette(recipe), height, partGltfs);
+ if (!figure) return null;
+ const { renderer, scene, camera } = acquireStage();
+ try {
+ // Turn the figure three-quarters toward the light, frame the head.
+ figure.root.rotation.y = -0.35;
+ scene.add(figure.root);
+ figure.actions.idle?.play();
+ figure.mixer.update(0.4);
+ const headY = height * 0.8;
+ camera.position.set(0.12, headY + height * 0.02, height * 0.62);
+ camera.lookAt(0, headY, 0);
+ camera.updateProjectionMatrix();
+ renderer.render(scene, camera);
+ return renderer.domElement.toDataURL("image/png");
+ } finally {
+ scene.remove(figure.root);
+ figure.dispose();
+ scheduleRelease();
+ }
+}
+
+/** The headshot for a look, cached; null when the recipe has no built base or WebGL is absent. */
+export function faceCrop(recipe: FigureRecipe | null): Promise<string | null> {
+ if (!recipe || typeof document === "undefined") return Promise.resolve(null);
+ const key = recipeKey(recipe);
+ let pending = crops.get(key);
+ if (!pending) {
+ pending = renderCrop(recipe).catch((error: unknown) => {
+ // A crop that cannot be drawn falls back to the colour swatch, out loud.
+ console.warn("[society] face crop failed:", error);
+ crops.delete(key);
+ return null;
+ });
+ crops.set(key, pending);
+ }
+ return pending;
+}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index b54693db73..635ef1ff1e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -5094,6 +5094,21 @@
"mode_pipeline": "Stimme rein und raus"
},
"society": {
+ "world": {
+ "minimap_label": "Inselkarte",
+ "mode_world": "Die Insel",
+ "hud_agents": "{0} Agenten",
+ "hud_active": "{0} aktiv",
+ "sample_badge": "Beispieldaten",
+ "reduced_motion_note": "Reduzierte Bewegung: Die Insel hält still.",
+ "controls_hint": "Ziehen zum Verschieben · Scrollen zum Zoomen · Pfeiltasten zum Bewegen",
+ "zoom_label": "Zoom",
+ "zoom_in": "Vergrößern",
+ "zoom_out": "Verkleinern",
+ "webgl_missing_title": "Die Insel braucht WebGL",
+ "webgl_missing_body": "Dieses Fenster kann gerade kein 3D zeichnen. Das Register zeigt dieselben Agenten als Tabelle.",
+ "open_ledger": "Register öffnen"
+ },
"style": {
"modern": "Modern",
"fantasy": "Fantasy",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 6d158f4be0..6e74ee5575 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -5094,6 +5094,21 @@
"mode_pipeline": "voice in and out"
},
"society": {
+ "world": {
+ "minimap_label": "Island map",
+ "mode_world": "The island",
+ "hud_agents": "{0} agents",
+ "hud_active": "{0} active",
+ "sample_badge": "Sample data",
+ "reduced_motion_note": "Motion reduced: the island holds still.",
+ "controls_hint": "Drag to pan · Scroll to zoom · Arrow keys to move",
+ "zoom_label": "Zoom",
+ "zoom_in": "Zoom in",
+ "zoom_out": "Zoom out",
+ "webgl_missing_title": "The island needs WebGL",
+ "webgl_missing_body": "This window cannot draw 3D right now. The ledger shows the same agents as a table.",
+ "open_ledger": "Open the ledger"
+ },
"style": {
"modern": "Modern",
"fantasy": "Fantasy",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 985ed54fe7..3eb150f227 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -5094,6 +5094,21 @@
"mode_pipeline": "voz de entrada y salida"
},
"society": {
+ "world": {
+ "minimap_label": "Mapa de la isla",
+ "mode_world": "La isla",
+ "hud_agents": "{0} agentes",
+ "hud_active": "{0} activos",
+ "sample_badge": "Datos de ejemplo",
+ "reduced_motion_note": "Movimiento reducido: la isla se queda quieta.",
+ "controls_hint": "Arrastra para desplazar · Rueda para acercar · Flechas para mover",
+ "zoom_label": "Zoom",
+ "zoom_in": "Acercar",
+ "zoom_out": "Alejar",
+ "webgl_missing_title": "La isla necesita WebGL",
+ "webgl_missing_body": "Esta ventana no puede dibujar 3D ahora. El registro muestra los mismos agentes como tabla.",
+ "open_ledger": "Abrir el registro"
+ },
"style": {
"modern": "Moderno",
"fantasy": "Fantasía",