Skip to content

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

fix(office): never trap the player against an agent in a corner

rubenluetke10-beepc6bd0164e538
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
index 48fd3bedb4..dac45b32bd 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
@@ -11,7 +11,7 @@ import type { FigureDrive } from "../figures/FigureRig";
import { ToyFigure } from "./ToyFigure";
import type { ToyLook } from "./toyFigureModel";
import { findPath, isWalkable, nearestWalkable, type NavGrid } from "./officeNav";
-import { applySeparation, clearOfBodies, separation, stepMover, turnToward } from "./officeMotion";
+import { applySeparation, separation, stepClearOfBodies, stepMover, turnToward } from "./officeMotion";
import { officeSession, player, sameSelection, useOfficeStore, type Selection } from "./officeStore";
import { agentPositions, bodiesExcept } from "./walkerRegistry";
import { OFFICE_FIGURE_HEIGHT_M } from "./OfficeAgents";
@@ -42,14 +42,6 @@ export function ownsKeyboard(target: EventTarget | null): boolean {
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || !!target.closest("[role='dialog']");
}
-/** Would stepping to `next` bring the character closer to any agent than it is now at `from`? */
-function closerToAnyone(next: { x: number; z: number }, from: { x: number; z: number }): boolean {
- for (const p of bodiesExcept(null, null)) {
- if (Math.hypot(next.x - p.x, next.z - p.z) < Math.hypot(from.x - p.x, from.z - p.z)) return true;
- }
- return false;
-}
-
/** Pressed movement keys, tracked on the window while the office is awake. */
function useMoveKeys(enabled: boolean, onInteract: () => void) {
const pressed = useRef(new Set<string>());
@@ -157,8 +149,7 @@ export function OfficePlayer({ layout, grid, look, name, awake, reduced }: {
const nx = player.x + dx * step, nz = player.z + dz * step;
// Slide along walls and around people: full move, else each axis alone.
// Moving away from someone you already touch is always allowed, so nobody gets stuck.
- const free = (p: { x: number; z: number }) => isWalkable(grid, p)
- && (clearOfBodies(p, bodiesExcept(null, null)) || !closerToAnyone(p, player));
+ const free = (p: { x: number; z: number }) => isWalkable(grid, p) && stepClearOfBodies(p, player, bodiesExcept(null, null));
if (free({ x: nx, z: nz })) { player.x = nx; player.z = nz; moved = step; }
else if (free({ x: nx, z: player.z })) { player.x = nx; moved = Math.abs(dx * step); }
else if (free({ x: player.x, z: nz })) { player.z = nz; moved = Math.abs(dz * step); }
diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeMotion.test.ts b/jarvis/ui/web/frontend/src/components/society/office/officeMotion.test.ts
index 258025c235..51389b6467 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/officeMotion.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/officeMotion.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { BODY_SPACING, WALK_SPEED, applySeparation, clearOfBodies, separation, stepMover, stepMoverAvoiding, turnToward, type Mover, wrapAngle } from "./officeMotion";
+import { BODY_SPACING, WALK_SPEED, applySeparation, clearOfBodies, separation, stepClearOfBodies, stepMover, stepMoverAvoiding, turnToward, type Mover, wrapAngle } from "./officeMotion";
describe("office motion", () => {
it("turns the short way and clamps the step", () => {
@@ -70,6 +70,16 @@ describe("separation", () => {
expect(clearOfBodies({ x: 0, z: 0 }, [{ x: BODY_SPACING / 2, z: 0 }])).toBe(false);
expect(clearOfBodies({ x: 0, z: 0 }, [{ x: BODY_SPACING * 2, z: 0 }])).toBe(true);
});
+ it("lets a figure pinned against someone step away even when others stand far off in that direction", () => {
+ // Touching a colleague to the west; the rest of the office lies south-east, beyond the step.
+ const from = { x: 0, z: 0 };
+ const others = [{ x: -0.4, z: 0 }, { x: 5, z: 5 }, { x: 8, z: -2 }];
+ expect(stepClearOfBodies({ x: 0.03, z: 0 }, from, others)).toBe(true);
+ expect(stepClearOfBodies({ x: 0, z: 0.03 }, from, others)).toBe(true);
+ // Never deeper into the one already touched, never into someone new.
+ expect(stepClearOfBodies({ x: -0.03, z: 0 }, from, others)).toBe(false);
+ expect(stepClearOfBodies({ x: 0.03, z: 0 }, from, [{ x: 0.5, z: 0 }])).toBe(false);
+ });
it("keeps two walkers crossing head-on apart", () => {
const a = { x: 0, z: -3, heading: 0, path: [{ x: 0, z: 3 }] };
const b = { x: 0.02, z: 3, heading: Math.PI, path: [{ x: 0.02, z: -3 }] };
diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeMotion.ts b/jarvis/ui/web/frontend/src/components/society/office/officeMotion.ts
index 63083469f2..d7957693bc 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/officeMotion.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/officeMotion.ts
@@ -93,6 +93,22 @@ export function clearOfBodies(p: Point, others: Iterable<Point>, spacing = BODY_
return true;
}
+/**
+ * May a figure step from `from` to `next` among `others`? Yes when the step
+ * keeps the spacing from everyone, or when every body it would touch there is
+ * one it already touches and the step does not bring it closer. Only touching
+ * bodies count: a far-away figure must never veto the way out of a crowd,
+ * or someone pinned in a corner could not move at all.
+ */
+export function stepClearOfBodies(next: Point, from: Point, others: Iterable<Point>, spacing = BODY_SPACING): boolean {
+ for (const o of others) {
+ const after = Math.hypot(next.x - o.x, next.z - o.z);
+ if (after >= spacing) continue;
+ if (after < Math.hypot(from.x - o.x, from.z - o.z)) return false;
+ }
+ return true;
+}
+
/**
* Nudge a mover sideways out of others' way, only onto walkable ground.
* Called after `stepMover`; the path pulls it back on the next frames.