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): making an agent takes you to the foundry to watch it walk out

rubenluetke10-beepc42ee4b546a7
diff --git a/jarvis/ui/web/frontend/src/components/society/world/FoundryDrawer.tsx b/jarvis/ui/web/frontend/src/components/society/world/FoundryDrawer.tsx
index 5ad8ee5da8..aee70028a8 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/FoundryDrawer.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/FoundryDrawer.tsx
@@ -66,15 +66,13 @@ export function FoundryDrawer({
[agents],
);
- const created = useCallback(
- (agentId: string) => {
- setCreating(false);
- // Get out of the way — the new figure is walking out of the portal now.
- onClose();
- onSelectAgent?.(agentId);
- },
- [onClose, onSelectAgent],
- );
+ const created = useCallback(() => {
+ setCreating(false);
+ // Get out of the way — the new figure is walking out of the portal now,
+ // and the island has already swung its camera to the works. Opening its
+ // card here would cover the one thing worth watching.
+ onClose();
+ }, [onClose]);
return (
<>
diff --git a/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx b/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
index fa64670f57..d05801f9ed 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/WorldStage.tsx
@@ -49,7 +49,8 @@ import { WorldCameraRig } from "./WorldCameraRig";
import { WorldComposer } from "./WorldComposer";
import { WorldHud } from "./WorldHud";
import { WorldKitProvider } from "./WorldKit";
-import { isKitPlace, type KitPlace, type PlaceId } from "./islandLayout";
+import { foundryWalkOut, isKitPlace, type KitPlace, type PlaceId } from "./islandLayout";
+import { FOCUS_GRACE_MS, useSpawnStore } from "./spawnStore";
/** Only kit hubs open a drawer; other places are scenery. */
function asHub(place: PlaceId): KitPlace | null {
@@ -77,6 +78,9 @@ export interface WorldStageProps {
const CAMERA_START = cameraOffset();
+/** Zoom step the island snaps to when it shows a newborn leaving the foundry. */
+const SPAWN_ZOOM = 1;
+
export function WorldStage({ topRight, onOpenLedger, onSelectAgent, onSelectPlace }: WorldStageProps) {
const t = useT();
const ready = useLocaleChunk("society");
@@ -98,6 +102,20 @@ export function WorldStage({ topRight, onOpenLedger, onSelectAgent, onSelectPlac
const [memoryOpen, setMemoryOpen] = useState(false);
useWorldControls(hostRef, webgl);
+
+ // An agent created in this window: look at the foundry, so its maker sees
+ // the figure come out instead of it happening on a mountain off screen.
+ // The frame holds the portal and the whole conveyor, so the walk reads.
+ const focusRequestedMs = useSpawnStore((s) => s.focusRequestedMs);
+ useEffect(() => {
+ if (focusRequestedMs === 0) return;
+ useSpawnStore.getState().clearFocus();
+ if (Date.now() - focusRequestedMs > FOCUS_GRACE_MS) return; // stale request
+ const walk = foundryWalkOut();
+ useCameraStore
+ .getState()
+ .focusOn((walk.from[0] + walk.to[0]) / 2, (walk.from[1] + walk.to[1]) / 2, SPAWN_ZOOM);
+ }, [focusRequestedMs]);
// The viewer's turned buildings go into the island before the first frame.
useEffect(syncBuildingPoses, []);
diff --git a/jarvis/ui/web/frontend/src/components/society/world/cameraStore.ts b/jarvis/ui/web/frontend/src/components/society/world/cameraStore.ts
index 0f64655646..572112d9fe 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/cameraStore.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/cameraStore.ts
@@ -20,6 +20,8 @@ export interface CameraState {
aspect: number;
panBy: (dx: number, dz: number) => void;
jumpTo: (x: number, z: number) => void;
+ /** Look at a spot at a chosen zoom — the world's "show me this". */
+ focusOn: (x: number, z: number, zoom: ZoomLevel) => void;
zoomStep: (direction: 1 | -1) => void;
setDragging: (dragging: boolean) => void;
setAspect: (aspect: number) => void;
@@ -60,6 +62,7 @@ export const useCameraStore = create<CameraState>((set, get) => ({
set({ target: clampTarget(x + dx, z + dz) });
},
jumpTo: (x, z) => set({ target: clampTarget(x, z) }),
+ focusOn: (x, z, zoom) => set({ target: clampTarget(x, z), zoom }),
zoomStep: (direction) => set((s) => ({ zoom: stepZoom(s.zoom, direction) })),
setDragging: (dragging) => set({ dragging }),
setAspect: (aspect) => set({ aspect }),
diff --git a/jarvis/ui/web/frontend/src/components/society/world/foundry.test.ts b/jarvis/ui/web/frontend/src/components/society/world/foundry.test.ts
index 596a09de66..d3ee8ac767 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/foundry.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/foundry.test.ts
@@ -9,10 +9,15 @@ import { beforeEach, describe, expect, it } from "vitest";
import {
FOUNDRY_PORTAL_M,
FOUNDRY_RAMP_END_M,
+ LEVEL_Y,
+ SUMMIT_LEVEL,
+ SUMMIT_TILE,
buildIsland,
+ findPath,
foundryWalkOut,
isWalkable,
kitPose,
+ tileIndex,
worldToTile,
} from "./islandLayout";
import { CAMERA_YAW_DEG } from "./worldCamera";
@@ -21,6 +26,7 @@ import { ENTRANCE_REPLAY_MS, FRESH_ENTRANCE_MS, useSpawnStore } from "./spawnSto
const NOW = Date.UTC(2026, 8, 2, 12, 0, 0);
function resetStore(): void {
+ useSpawnStore.setState({ focusRequestedMs: 0 });
try {
sessionStorage.clear();
} catch {
@@ -53,6 +59,34 @@ describe("foundryWalkOut", () => {
expect(off).toBeLessThan(Math.PI / 6);
});
+ it("stands on the mountain's summit terrace", () => {
+ const { map } = buildIsland();
+ const [tx, tz] = worldToTile(...([kitPose("foundry").x, kitPose("foundry").z] as [number, number]));
+ expect([tx, tz]).toEqual([SUMMIT_TILE[0], SUMMIT_TILE[1]]);
+ expect(map.level[tileIndex(map, tx, tz)]).toBe(SUMMIT_LEVEL);
+ // High above the village plateau: this is the island's backdrop, not a
+ // building on the square.
+ expect(LEVEL_Y[SUMMIT_LEVEL]).toBeGreaterThan(10);
+ });
+
+ it("is reachable on foot from the village square", () => {
+ // The whole point of the mountain road: a new agent walks the climb down
+ // into the village, and anyone can walk back up. A break anywhere in the
+ // graded legs would strand the works on its own terrace.
+ const { map, content } = buildIsland();
+ const path = findPath(map, content.places.market.standTile, content.places.foundry.standTile);
+ expect(path, "no road from the square to the foundry").not.toBeNull();
+ // And the climb never asks for more than a single step at a time.
+ for (let i = 1; i < (path ?? []).length; i++) {
+ const [ax, az] = (path ?? [])[i - 1];
+ const [bx, bz] = (path ?? [])[i];
+ const rise = Math.abs(
+ map.level[tileIndex(map, bx, bz)] - map.level[tileIndex(map, ax, az)],
+ );
+ expect(rise, `step ${i}`).toBeLessThanOrEqual(1);
+ }
+ });
+
it("sets the figure down on ground it may stand on", () => {
const { map } = buildIsland();
const [tx, tz] = worldToTile(...foundryWalkOut().to);
@@ -106,6 +140,32 @@ describe("spawn entrances", () => {
expect(useSpawnStore.getState().portalOpenedMs).toBe(0);
});
+ it("asks the island to look at the foundry when the agent is made here", () => {
+ // A row created in this window is one the viewer chose to make: the stage
+ // swings to the works so they see it happen. A row that merely turned up
+ // fresh from somewhere else does not move anyone's camera.
+ useSpawnStore.getState().announce("scout");
+ expect(useSpawnStore.getState().focusRequestedMs).toBeGreaterThan(0);
+ useSpawnStore.getState().clearFocus();
+ expect(useSpawnStore.getState().focusRequestedMs).toBe(0);
+ useSpawnStore.getState().claim("stranger", NOW, NOW);
+ expect(useSpawnStore.getState().focusRequestedMs).toBe(0);
+ });
+
+ it("frames the whole conveyor when it looks at the foundry", () => {
+ // The camera aims at the middle of the walk, so the portal the figure
+ // steps out of and the ramp foot it lands on are both in shot.
+ const walk = foundryWalkOut();
+ const mid: [number, number] = [
+ (walk.from[0] + walk.to[0]) / 2,
+ (walk.from[1] + walk.to[1]) / 2,
+ ];
+ const pose = kitPose("foundry");
+ const ahead = Math.hypot(mid[0] - pose.x, mid[1] - pose.z);
+ expect(ahead).toBeGreaterThan(FOUNDRY_PORTAL_M);
+ expect(ahead).toBeLessThan(FOUNDRY_RAMP_END_M);
+ });
+
it("opens the portal for the building to react to", () => {
useSpawnStore.getState().claim("scout", NOW, NOW);
expect(useSpawnStore.getState().portalOpenedMs).toBe(NOW);
diff --git a/jarvis/ui/web/frontend/src/components/society/world/spawnStore.ts b/jarvis/ui/web/frontend/src/components/society/world/spawnStore.ts
index b894c48d91..e1578308d2 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/spawnStore.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/spawnStore.ts
@@ -24,6 +24,13 @@
*
* `portalOpenedMs` is what the building itself listens to: the portal flares
* and the forecourt lights up for a few seconds after any entrance.
+ *
+ * `focusRequestedMs` is the other half of "you made this one": when the agent
+ * was created in THIS window, the island swings its camera to the foundry so
+ * the maker actually watches the figure come out, instead of it happening on a
+ * mountain they are not looking at. It expires — a request nobody consumed
+ * (the world was not mounted, the viewer was reading the ledger) must not
+ * yank the camera minutes later.
*/
import { create } from "zustand";
@@ -31,6 +38,8 @@ import { create } from "zustand";
export const FRESH_ENTRANCE_MS = 60_000;
/** How long the portal keeps glowing after a figure came through (ms). */
export const PORTAL_FLARE_MS = 4_200;
+/** A camera request older than this is stale and is ignored. */
+export const FOCUS_GRACE_MS = 20_000;
/**
* A claimed entrance stays claimable this long, so a remount of the walker
* (a rebuilt canvas, a re-rendered subtree) resumes the walk instead of
@@ -76,19 +85,25 @@ interface SpawnState {
announced: Set<string>;
/** What this window decided per agent: when it walked out, or 0 for never. */
seen: Decisions;
+ /** When this window last asked the island to look at the foundry; 0 = never. */
+ focusRequestedMs: number;
announce: (agentId: string) => void;
+ clearFocus: () => void;
claim: (agentId: string, createdMs: number, now?: number) => boolean;
}
export const useSpawnStore = create<SpawnState>((set, get) => ({
portalOpenedMs: 0,
+ focusRequestedMs: 0,
announced: new Set<string>(),
seen: typeof sessionStorage === "undefined" ? (new Map() as Decisions) : readSeen(),
announce: (agentId) => {
const announced = new Set(get().announced);
announced.add(agentId);
- set({ announced });
+ // Made here, so watch it happen: the stage swings to the works.
+ set({ announced, focusRequestedMs: Date.now() });
},
+ clearFocus: () => set({ focusRequestedMs: 0 }),
claim: (agentId, createdMs, now = Date.now()) => {
const { seen, announced } = get();
const decided = seen.get(agentId);
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
index ad6125e9f6..d52376568c 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
@@ -39,9 +39,12 @@ export function SocietyView() {
);
const activeCount = agents.filter((a) => a.state === "working" || a.state === "waiting").length;
- const onCreated = useCallback((agentId: string) => {
+ const onCreated = useCallback(() => {
setCreating(false);
- setOpenAgentId(agentId);
+ // The card does NOT open on top of the island: a brand-new agent is
+ // walking out of the foundry right now, and its card would cover exactly
+ // that. It holds nothing new anyway — the maker just typed all of it. The
+ // rail lists the newcomer; a click on it, or on the figure, opens it.
}, []);
// A figure clicked on the island opens its card, like a row in the rail