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.

docs: rewrite root CLAUDE.md and fix stale claims in agent instruction files

Claude536cb0e7bf70
diff --git a/.github/skills/3d-viewer/SKILL.md b/.github/skills/3d-viewer/SKILL.md
index 1035b0e1f..b7476abed 100644
--- a/.github/skills/3d-viewer/SKILL.md
+++ b/.github/skills/3d-viewer/SKILL.md
@@ -1,68 +1,105 @@
---
name: 3d-viewer
-description: "Full project workflow for the 3D Agent viewer app. Use when: developing features, debugging rendering, modifying UI, understanding architecture, running dev server, or making any code changes to this glTF/GLB viewer project."
-argument-hint: "Describe what you want to do with the 3D viewer app"
+description: "Full project workflow for the 3D Agent platform. Use when: developing features, debugging, modifying UI, understanding architecture, running dev server, or making code changes anywhere in the repo (viewer, agent runtime, API, contracts)."
+argument-hint: "Describe what you want to do"
---
# 3D Agent — Project Workflow
## Overview
-3D Agent is a browser-based glTF 2.0 / GLB viewer built with Three.js. Users drag-and-drop 3D model files to preview them with interactive controls for lighting, animation, and display. Deployed at [3dagent.vercel.app](https://3dagent.vercel.app/).
+**3D Agent** started as a glTF 2.0 / GLB viewer and grew into a full embodied-agent platform. Live at [3dagent.vercel.app](https://3dagent.vercel.app/). Read [/CLAUDE.md](../../../CLAUDE.md) first — this skill is an index; the CLAUDE.md files are the source of truth.
-## Architecture
+## Two halves
-```
-index.html → Entry point, loads app.js
-src/app.js → App class: dropzone, file loading, URL params, orchestrates Viewer + Validator
-src/viewer.js → Viewer class: Three.js scene, camera, lighting, dat.gui controls, animation
-src/validator.js → Validator class: gltf-validator integration, report rendering
-src/environments.js → HDR/EXR environment map presets
-src/components/ → JSX components (vhtml): footer, validator-toggle, validator-report, validator-table
-style.css → Global styles + dat.gui dark theme overrides
-public/avatars/ → Default 3D model assets
-```
+- **Viewer half** — pure three.js. GLB loading, lighting, animations, validation, dat.gui.
+- **Agent half** — persona (`agent-identity.js`), memory (`agent-memory.js`), skills (`agent-skills.js`), avatar emotion (`agent-avatar.js`), LLM runtime (`runtime/`), wallet identity (`erc8004/`), protocol bus (`agent-protocol.js`).
+
+The viewer never imports the agent half. The agent layer wraps the viewer through `runtime/scene.js` (`SceneController`).
-## Key Classes
+## Where code lives
-| Class | File | Responsibility |
-|-------|------|----------------|
-| `App` | `src/app.js` | File drop handling, URL param parsing, error UI, lifecycle |
-| `Viewer` | `src/viewer.js` | Three.js scene setup, model loading, GUI panels, animation playback |
-| `Validator` | `src/validator.js` | glTF validation, report generation, lightbox display |
+| Area | Path | Scoped doc |
+|---|---|---|
+| Browser app (viewer + agent) | `src/` | [src/CLAUDE.md](../../../src/CLAUDE.md) |
+| Vercel serverless API | `api/` | [api/CLAUDE.md](../../../api/CLAUDE.md) |
+| ERC-8004 Solidity registries | `contracts/` | [contracts/CLAUDE.md](../../../contracts/CLAUDE.md) |
+| Format specs | `specs/` | — |
+| Priority-stack build prompts | `prompts/` | [prompts/INDEX.md](../../../prompts/INDEX.md) |
+| User-facing docs | `docs/` | — |
+| Static pages / assets | `public/` | — |
+| SDK package | `sdk/` | — |
-## Tech Stack
+Top-level HTML entries: `index.html`, `features.html`, `embed.html`, `agent-home.html`, `agent-embed.html`. Additional routes are rewritten by the `vercel-rewrites` middleware in [vite.config.js](../../../vite.config.js) and mirrored in [vercel.json](../../../vercel.json).
-- **Three.js** v0.176 — WebGL rendering, GLTFLoader, DRACOLoader, KTX2Loader, OrbitControls
-- **dat.gui** — Interactive control panels
-- **simple-dropzone** — Drag-and-drop file input
-- **vhtml** — JSX-like component rendering
-- **gltf-validator** — KhronosGroup glTF 2.0 validation
-- **Vite** — Dev server and build tool
-- **Vercel** — Deployment
+## Tech stack
+
+- **three.js** r176 — WebGL2 rendering + `GLTFLoader`, `DRACOLoader`, `KTX2Loader`, `MeshoptDecoder`, `OrbitControls`
+- **dat.gui** + **tweakpane** — control panels
+- **simple-dropzone** — file drops
+- **vhtml** — JSX → HTML string rendering (no virtual DOM)
+- **gltf-validator** — KhronosGroup validation
+- **Vite 7** — dev server + build (two targets: `app` and `lib`)
+- **vite-plugin-pwa** — service worker + manifest
+- **ethers v6**, **viem**, **@privy-io/js-sdk-core** — wallet + on-chain
+- **Neon Postgres**, **Upstash Redis**, **Cloudflare R2**, **Vercel** — backend
+- **Foundry** + **OpenZeppelin** (contracts)
## Commands
```bash
-npm install # Install dependencies
-npm run dev # Start dev server on port 3000
-npm run build # Production build with Vite
-npm run clean # Remove dist/
-npm run deploy # Build + deploy to Vercel
+npm install
+npm run dev # app dev server on :3000
+npm run dev:lib # library build watch
+npm run build # app → dist/
+npm run build:lib # web component → dist-lib/
+npm run build:all # both
+npm run deploy # build + vercel --prod
+npx prettier --write <file>
+node --check <file.js>
```
+No automated test suite (`npm test` exits 0). Verify with `node --check`, `npm run build`, and manual smoke at `localhost:3000`.
+
## Conventions
-- Components use **vhtml JSX** syntax (not React)
-- URL params: `?model=`, `?preset=`, `?cameraPosition=x,y,z`, `?kiosk=true`
-- Styles in a single `style.css` file (no CSS modules)
-- Code formatted with Prettier (tabs, single quotes, 100 print width)
+- ESM only (no CommonJS in `src/` or `api/`)
+- Prettier: **tabs**, 4-wide, single quotes, 100-col print width
+- No TypeScript in the main app (JSDoc for public APIs); `sdk/` may use TS
+- Components are **vhtml JSX**, not React — `.jsx` files, `jsxFactory: 'vhtml'`
+- URL hash params live in `src/app.js`: `model`, `widget`, `agent`, `kiosk`, `brain`, `proxyURL`, `preset`, `cameraPosition`, `register`
+- Tool result shape: `{ ok: true, ... }` or `{ ok: false, error: 'msg' }`
+- Naming: CamelCase classes, camelCase methods, UPPER_CASE constants, `_underscore` private
+
+## Priority stack — before you start
+
+The order of work is fixed in [prompts/INDEX.md](../../../prompts/INDEX.md):
+
+1. Wallet auth (SIWE / Privy)
+2. Selfie → agent
+3. Edit avatars
+4. View + embed
+5. Portable embed (Claude.ai / LobeHub)
+6. On-chain deployment (ERC-8004)
+
+If a task isn't in a band, ask first. Side lanes (`pretext/`, `scalability/`, `widget-studio/` polish, CLI, AR, screenshot export) are explicitly deprioritized.
+
+## Where to change what
+
+- Rendering / GUI / display toggles → `src/viewer.js` and `src/viewer/*.js` (see [3d-features](../3d-features/SKILL.md))
+- Validation → `src/validator.js` + `src/components/validator-*.jsx` (see [model-validation](../model-validation/SKILL.md))
+- Build / deploy / Vercel routes → see [build-deploy](../build-deploy/SKILL.md)
+- Agent persona / memory / skills → `src/agent-*.js`, `src/runtime/`, `src/skills/`, `src/memory/` — read [src/CLAUDE.md](../../../src/CLAUDE.md)
+- Auth / avatars / OAuth / MCP / rate-limit / R2 → `api/` — read [api/CLAUDE.md](../../../api/CLAUDE.md)
+- ERC-8004 registries → `contracts/` — read [contracts/CLAUDE.md](../../../contracts/CLAUDE.md)
+- Top-level routing / URL hash params → `src/app.js` (don't create a new routing layer)
-## When Making Changes
+## Ground rules
-1. Check the architecture map above to find the right file
-2. `src/viewer.js` for anything Three.js / rendering / GUI controls
-3. `src/validator.js` for validation logic or report display
-4. `src/app.js` for file loading, URL params, or top-level orchestration
-5. `src/components/` for UI templates (vhtml JSX, not React)
-6. Run `npm run dev` to test changes at `http://localhost:3000`
+- One task, one PR. Note unrelated bugs in the report — don't fix them inline.
+- Edit existing files before creating new ones. No new top-level `.md` files unless asked.
+- No new runtime deps without approval.
+- `node --check` every modified JS. `npm run build` before reporting done. Report both outputs.
+- Respect `Files off-limits` in prompt files — parallel work may touch them.
+- Never `forge script --broadcast` without explicit user approval. Deployed contract addresses are immutable.
+- Report what changed, what you skipped, what broke, and any surprises.
diff --git a/.github/skills/build-deploy/SKILL.md b/.github/skills/build-deploy/SKILL.md
index 9e9942096..3087fd71e 100644
--- a/.github/skills/build-deploy/SKILL.md
+++ b/.github/skills/build-deploy/SKILL.md
@@ -28,9 +28,15 @@ argument-hint: "Describe the build or deploy task"
## Vite Configuration
-- Entry: `index.html` (default Vite behavior)
+**Config**: [`vite.config.js`](../../../vite.config.js)
+
+- Two build targets switched via `TARGET` env var:
+ - `TARGET=app` (default) → multi-page app in `dist/` (entries: `index.html`, `features.html`, `embed.html`, `agent-home.html`, `agent-embed.html`)
+ - `TARGET=lib` → self-contained `<agent-3d>` web component in `dist-lib/` (ESM + UMD, three.js bundled)
+- JSX configured for vhtml: `jsxFactory: 'vhtml'`, `jsxFragment: '"div"'`
+- Dev server has a `vercel-rewrites` middleware that mirrors Vercel routing for `/login`, `/register`, `/dashboard`, `/studio`, `/widgets`, `/docs/widgets`, `/agent`, `/agent/:id`, `/agent/:id/embed`
+- `vite-plugin-pwa` emits the service worker + manifest
- Static assets: `public/` folder copied to build output
-- No custom `vite.config.js` — uses Vite defaults with `staticFiles` in package.json
## Vercel Deployment
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 000000000..56beb7811
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,161 @@
+# CLAUDE.md
+
+Root guidance for agents working in this repo. Read this first. Then read the scoped CLAUDE.md closest to the code you're touching.
+
+---
+
+## What this repo is
+
+**3D Agent** is a browser-native glTF/GLB viewer that grew a full embodied-agent platform on top of it. Two halves, one codebase:
+
+- **Viewer** — client-side three.js app that renders glTF 2.0 / GLB with Draco, KTX2, Meshopt. 100% in-browser.
+- **Agent platform** — persona + memory + skills + wallet identity + ERC-8004 on-chain registration. LLM brain in `src/runtime/`, embodied rendering in `src/agent-avatar.js`, protocol bus in `src/agent-protocol.js`.
+
+Live at <https://3dagent.vercel.app>. Backend is Vercel serverless (`api/`) + Neon Postgres + Cloudflare R2 + Upstash Redis. Contracts are Foundry / Solidity 0.8.24.
+
+---
+
+## Directory map — where things live
+
+| Path | What it is | Scoped doc |
+|---|---|---|
+| [src/](src/) | Browser app — viewer + agent runtime + web component | [src/CLAUDE.md](src/CLAUDE.md) |
+| [api/](api/) | Vercel serverless endpoints (auth, avatars, OAuth, MCP, agents) | [api/CLAUDE.md](api/CLAUDE.md) |
+| [contracts/](contracts/) | Foundry project — ERC-8004 registries (Solidity) | [contracts/CLAUDE.md](contracts/CLAUDE.md) |
+| [specs/](specs/) | Format specs: `AGENT_MANIFEST.md`, `SKILL_SPEC.md`, `EMBED_SPEC.md`, `MEMORY_SPEC.md` | — |
+| [docs/](docs/) | User-facing docs: `ARCHITECTURE.md`, `API.md`, `DEPLOYMENT.md`, `DEVELOPMENT.md`, `WIDGETS.md`, `MCP.md` | — |
+| [prompts/](prompts/) | Build prompts organized by priority band — see [prompts/INDEX.md](prompts/INDEX.md) | — |
+| [public/](public/) | Static assets, separate HTML pages (`login.html`, `dashboard/`, `studio/`, `widgets-gallery/`) | — |
+| [sdk/](sdk/) | `@3dagent/sdk` — public TS client (separate npm package) | — |
+| [scripts/](scripts/) | One-off node scripts (schema apply, icon gen, animation fetchers) | — |
+| [.github/skills/](.github/skills/) | GitHub Copilot `SKILL.md` bundles (viewer, features, validation, deploy) | — |
+| [.github/prompts/](.github/prompts/) | Copilot prompt library for one-shot features | — |
+
+Top-level HTML entry points: `index.html` (app), `features.html`, `embed.html`, `agent-home.html`, `agent-embed.html`. Additional routes served from `public/` — wiring is in [vite.config.js](vite.config.js) `vercel-rewrites` plugin, mirrored in [vercel.json](vercel.json).
+
+---
+
+## Current priorities (don't freelance)
+
+Work follows the six-band priority stack in [prompts/INDEX.md](prompts/INDEX.md):
+
+1. **Wallet auth** (SIWE / Privy / WalletConnect)
+2. **Selfie → agent** (photo → rigged avatar)
+3. **Edit avatars** (material, mesh, regenerate)
+4. **View + embed** polish
+5. **Portable embed** (Claude.ai artifact + LobeHub plugin)
+6. **On-chain deployment** (ERC-8004)
+
+If the task isn't in a band or isn't listed in INDEX.md, **ask before doing it.** Bands 1 and 2 block most downstream work — don't start band 4+ if band 1 is broken.
+
+Side lanes explicitly deprioritized: `pretext/`, `scalability/`, `widget-studio/` polish, CLI tool, AR quick-look, screenshot export. Don't open those without direction.
+
+---
+
+## Commands
+
+```bash
+npm install # install deps
+npm run dev # Vite dev server on :3000 (app build)
+npm run dev:lib # library build watch (dist-lib/agent-3d.js)
+npm run build # production build → dist/
+npm run build:lib # library build → dist-lib/
+npm run build:all # both
+npm run deploy # build + vercel --prod
+npx prettier --write <file> # format (tabs, 4-wide, single quotes, 100 cols)
+node --check <file.js> # syntax check — run this on every JS you modify
+
+# Contracts (cd contracts/)
+forge build && forge test # always before a deploy
+forge script script/Deploy.s.sol --rpc-url base_sepolia # dry-run
+```
+
+No test suite is configured (`npm test` exits 0). Verification = `node --check` + `npm run build` + manual smoke at `localhost:3000`. Say so explicitly when you can't browser-test a UI change — don't claim a UI works just because the build passed.
+
+---
+
+## Conventions
+
+| Topic | Rule |
+|---|---|
+| Modules | **ESM only.** No CommonJS in `src/` or `api/`. |
+| Formatting | Prettier: **tabs**, 4-wide, single quotes, 100-col print width, `bracketSpacing`. Run `npx prettier --write` before committing. |
+| Typing | **No TypeScript** in the main app. JSDoc for public APIs. (SDK in `sdk/` may use TS — check locally.) |
+| Templating | **vhtml JSX** — string-based, no virtual DOM. Files end in `.jsx`. `jsxFactory: 'vhtml'`. |
+| Naming | CamelCase classes, camelCase methods, UPPER_CASE constants, `_underscore` for private. |
+| State | Classes over factories where there's state. `EventTarget` for buses. |
+| SQL | Always tagged-template via `sql\`...\`` from [api/_lib/db.js](api/_lib/db.js). Never concat. |
+| HTTP responses | Use `json()` / `error()` / `wrap()` from [api/_lib/http.js](api/_lib/http.js). Never `res.end(JSON.stringify(...))`. |
+| Auth | Use `getSessionUser` / `authenticateBearer` from [api/_lib/auth.js](api/_lib/auth.js). Never hand-roll JWT. |
+| Tool result shape | `{ ok: true, ... }` or `{ ok: false, error: 'msg' }`. |
+| Errors | `error(res, status, code, message)` — OAuth-style string codes. See `api/CLAUDE.md`. |
+
+---
+
+## Ground rules for agents
+
+1. **One task, one PR.** If you notice an unrelated bug, write it in your report; don't fix it.
+2. **Edit existing files before creating new ones.** No new top-level docs (`README.md`, `CLAUDE.md`, design docs) unless the task explicitly asks for them.
+3. **No new runtime deps** unless the task says so. The bundle is a user-facing concern.
+4. **Cite exact paths + line numbers** when referencing code. Don't invent APIs — read the file first.
+5. **Trust but verify** — `node --check` and `npm run build` any modified JS. Report both outputs.
+6. **Files off-limits per task** — respect `Files off-limits` sections in `prompts/*/` if present. Parallel tasks may be editing them.
+7. **On-chain = immutable.** Any change to contract ABI, storage layout, or deployed address requires explicit user approval. See [contracts/CLAUDE.md](contracts/CLAUDE.md).
+8. **Never `forge script --broadcast`** without approval.
+9. **Secrets live in `.env.local` / Vercel**, never in code. See [.env.example](.env.example) for the full list.
+10. **Reporting block at the end of every task:** files changed, commands run + their output, what you skipped, unrelated bugs observed.
+
+---
+
+## Architectural invariants — don't violate these
+
+- **Viewer doesn't know about agents.** The agent layer wraps the viewer via `runtime/scene.js` (`SceneController`). Never import agent code from `viewer.js`.
+- **All cross-module agent events flow through [src/agent-protocol.js](src/agent-protocol.js).** Don't add direct module-to-module coupling; emit typed events (`ACTION_TYPES`).
+- **The Empathy Layer is a continuous weighted blend**, not an emotion FSM. See [src/CLAUDE.md](src/CLAUDE.md) for the decay + stimulus rules.
+- **Manifest `_baseURI`** must end with `/` for relative resolution to work.
+- **Skills default to `owned-only` trust** — manifest `author` must match `ownerAddress`. Mismatch → skill load throws.
+- **Avatar `.glb` uploads must be verified via `headObject()`** before registering in the `avatars` table (blocks R2-bypass attacks).
+- **MCP endpoints emit to `usage_events`** and respect `hasScope()`. Adding a tool without those = rejected.
+- **`window.VIEWER` is a debug global only.** Never rely on it in production code paths — use closures / DI.
+
+---
+
+## Anti-patterns (these will get reverted)
+
+- `res.end(JSON.stringify(...))` — use `json(res, ...)`.
+- Instantiating a new Postgres `Pool` / `neon()` — import `sql` from `api/_lib/db.js`.
+- Hand-rolled JWT extraction — use `authenticateBearer()`.
+- String-concat SQL — tagged templates only.
+- Inline CORS — use `cors(req, res, ...)`.
+- Missing rate-limit on a public endpoint — use `limits.*` presets.
+- Adding a discrete "emotion state" to the avatar — break the continuous blend.
+- New top-level markdown file (README, design doc, "PLAN.md") without user asking.
+- Adding TypeScript to the main app.
+- Importing agent modules from the viewer half.
+- Writing a new routing layer instead of extending the URL-hash params in [src/app.js](src/app.js).
+- Long multi-paragraph comments / docstrings explaining *what* code does. Keep it tight.
+
+---
+
+## Common gotchas
+
+- **`@avaturn/sdk` resolution warning at build time** — pre-existing, ignore.
+- **`npm run dev` port 3000** — if taken, kill the other process; don't silently change the port.
+- **SpeechRecognition** silently no-ops if unavailable — check `window.SpeechRecognition || window.webkitSpeechRecognition`.
+- **Morph traversal runs every frame, every mesh.** Cheap on Mixamo avatars, expensive on scene-scale models.
+- **`memory.recall()` is substring search** — no embeddings yet. Don't assume semantic.
+- **`protocol.emit()` has no rate limit** — a runaway skill loop will cascade. Guard in the handler.
+- **ERC-8004 addresses are CREATE2-deterministic** — same bytes on every chain. Check `REGISTRY_DEPLOYMENTS` in [src/erc8004/abi.js](src/erc8004/abi.js) before hardcoding anything.
+- **Contract ABIs are hand-maintained ethers v6 human-readable strings** in `src/erc8004/abi.js`. No codegen. Sol change → abi.js edit.
+
+---
+
+## If you're stuck
+
+- Unknown API — check `api/CLAUDE.md` and `api/_lib/` exports.
+- Unknown viewer/agent pattern — check `src/CLAUDE.md` and [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
+- Unknown on-chain behavior — check `contracts/CLAUDE.md` and [specs/AGENT_MANIFEST.md](specs/AGENT_MANIFEST.md).
+- Unknown skill shape — check [specs/SKILL_SPEC.md](specs/SKILL_SPEC.md).
+- Unknown embed attribute — check [specs/EMBED_SPEC.md](specs/EMBED_SPEC.md).
+- Which prompt to run next — check [prompts/INDEX.md](prompts/INDEX.md).
+- Can't find something — `rg`/Grep first, then ask. Don't invent it.
diff --git a/src/CLAUDE.md b/src/CLAUDE.md
index c98b5d5c1..a8d676a82 100644
--- a/src/CLAUDE.md
+++ b/src/CLAUDE.md
@@ -135,7 +135,7 @@ Z-rotation = `(curiosity*12 + empathy*9 + concern*4)` degrees. X-rotation (lean)
- **SpeechRecognition** silently noops if unavailable. Check `window.SpeechRecognition || window.webkitSpeechRecognition` before relying.
- **Morph traversal** iterates every mesh every frame. Cheap on Mixamo avatars, expensive on scene-scale models — don't add per-vertex work.
- **Skill `owned-only` trust** compares `manifest.author` with `ownerAddress` from element attr or backend. Mismatch → skill load throws.
-- **`viewer.js` is large (~11k lines).** [prompts/scalability/03-module-split.md](../prompts/scalability/03-module-split.md) is the planned refactor. Don't start it ad-hoc.
+- **[viewer.js](viewer.js) is the biggest file in `src/` (~1.2k lines).** Further module split is tracked in [prompts/scalability/03-module-split.md](../prompts/scalability/03-module-split.md). Don't start that refactor ad-hoc.
- **`memory.recall()` is substring search.** No embeddings yet.
- **No rate limit on `protocol.emit()`.** A runaway skill loop will cascade.