Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

Add IRL production WebXR-lifecycle and tap-raycast specs

nirholas633bc7ba3d27
diff --git a/tasks/irl-production/04-webxr-session-lifecycle.md b/tasks/irl-production/04-webxr-session-lifecycle.md
new file mode 100644
index 000000000..6fa67c679
--- /dev/null
+++ b/tasks/irl-production/04-webxr-session-lifecycle.md
@@ -0,0 +1,53 @@
+# Task 04 — WebXR session lifecycle and camera contention
+
+**Phase:** 1 (AR correctness) · **Effort:** M · **Files:** `src/irl.js`, `src/ar/webxr.js`, `pages/irl.html`
+
+## Why
+On WebXR-capable devices (mainly Android Chrome) the "Place on floor" flow starts
+an immersive session that owns the camera and a separate animation loop, while the
+gyro+GPS path owns `getUserMedia` and the RAF tick. If these two overlap — double
+camera acquisition, RAF not paused/resumed, overlay left interactive — the user
+hits a black screen, a dangling camera track, or dead taps.
+
+## Read first (verify before fixing)
+- `enterFloorAnchor()` / XR start + the `WebXRSession` shim — `src/irl.js:~1475-1610`
+- `enableAR()` / `disableAR()` camera ownership — `src/irl.js:279-396`
+- The single RAF owner (`xrViewer._rafId`, `startTick`) — `src/irl.js:~1502-1513`, `tick()` end
+- XR overlay markup + z-index/pointer-events — `pages/irl.html` `#irl-xr-overlay`, `#irl-xr-error`
+- `src/ar/webxr.js` session start/end + clear-color restore
+
+## Scope — confirm, then fix
+
+1. **AR↔XR transition guard.** Entering the floor-anchor flow calls `disableAR()` to
+ release `getUserMedia`; a fast tap on Camera AR during the async XR startup can
+ re-acquire the camera and collide. Add a single `_arTransitioning` guard that
+ blocks both `enableAR()` and the XR entry until the prior op fully settles
+ (camera tracks stopped, session started/ended). Make teardown deterministic.
+
+2. **RAF pause/resume correctness.** Confirm the IRL `tick()` RAF is cancelled while
+ the XR animation loop runs and is restarted exactly once on session end (no
+ double-tick, no frozen scene). Verify `xrViewer._rafId` is the sole handle.
+
+3. **Overlay tap absorption.** Ensure `#irl-xr-overlay` is hidden immediately on
+ session end and that its hit areas never sit above the canvas while AR/gyro mode
+ is active. Add a guard in the tap handler to early-return when the overlay is
+ visible.
+
+4. **Clear color / background restore.** `WebXRSession` restores an opaque clear
+ color on exit; IRL must re-assert the transparent AR clear color and `groundShadow`
+ visibility so passthrough resumes correctly.
+
+5. **Unsupported path stays clean.** iOS Safari (no `immersive-ar`) must never reveal
+ the floor-anchor button or hit any XR code — confirm the support gate and that
+ failures route to the designed "use Pin here instead" state, not a toast.
+
+## Out of scope
+Pin persistence schema (shipped); gyro/GPS math (tasks 01–03).
+
+## Definition of done
+- [ ] Rapidly toggling Camera AR ↔ Place on floor never double-acquires the camera,
+ black-screens, or leaves a dangling track (manual, Android Chrome).
+- [ ] Scene resumes live (not frozen) after exiting an XR session; single RAF.
+- [ ] No dead taps after XR exit; overlay fully dismissed.
+- [ ] iOS Safari never sees or touches XR code.
+- [ ] esbuild clean; `npm test` green; changelog entry if user-visible.
diff --git a/tasks/irl-production/05-tap-raycast-accuracy.md b/tasks/irl-production/05-tap-raycast-accuracy.md
new file mode 100644
index 000000000..a739d5cf7
--- /dev/null
+++ b/tasks/irl-production/05-tap-raycast-accuracy.md
@@ -0,0 +1,47 @@
+# Task 05 — Tap / raycast accuracy
+
+**Phase:** 1 (AR correctness) · **Effort:** S · **Files:** `src/irl.js`
+
+## Why
+Inspecting an agent is the primary interaction. If taps miss — because the agent is
+near the camera near-plane, off-center while gyro-locked, or behind a label hit-box
+— the product feels broken. Tapping must reliably select the agent the user is
+pointing at.
+
+## Read first (verify before fixing)
+- Tap handler + raycaster setup — `src/irl.js:573-588` and the pointerup tap logic
+- Camera near plane (`0.05`) — `src/irl.js:249`
+- Tap-to-place raycast vs the y=0 `rayPlane` — `src/irl.js:240-246`, place handler
+- Floating label hit areas — `pages/irl.html` `.irl-agent-label` + `updateLabels()` in `src/irl.js`
+- Nearest-agent proximity focus (if present) — search `AWARE_RADIUS` / awareness code
+
+## Scope — confirm, then fix
+
+1. **Near-plane clipping on close agents.** With `near = 0.05`, an agent held very
+ close (common one-handed AR) can fall inside the clip cone and miss the ray.
+ Verify behavior; if real, lower `near` to ~0.01 (check for depth-fighting) or
+ clamp placement/selection so agents never sit inside the near cone.
+
+2. **Raycast frame correctness while gyro-locked.** The raycaster must use the live
+ camera position/orientation. In the local gyro-lock regime the camera sits at the
+ captured pivot (not origin) — confirm NDC→ray uses `camera` directly (it should,
+ via `setFromCamera`) and that edge-of-screen taps resolve to the correct world ray.
+
+3. **Label vs mesh tap priority.** A tap on a floating name label and a tap on the
+ mesh should both select the same agent, with the label taking priority where they
+ overlap. Ensure label hit-boxes don't swallow taps meant for a different nearer
+ agent.
+
+4. **Nearest-agent tolerance.** Add a small angular/Screen-space tolerance so a tap
+ *near* an agent selects it (fat-finger friendly), picking the nearest candidate
+ when several are close. Avoid selecting agents the user can't see (behind camera).
+
+## Out of scope
+The inspect card content/API (shipped); placement of objects (shipped).
+
+## Definition of done
+- [ ] Tapping an agent — centered, edge-of-screen, close, or far — reliably opens its
+ card (manual, real device; document a quick hit-rate check).
+- [ ] No accidental selection of off-screen/behind-camera agents.
+- [ ] Any pure picking helper (screen-space distance, candidate ranking) unit-tested.
+- [ ] esbuild clean; `npm test` green; changelog entry if the win is user-visible.