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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat: add api-sweep script for comprehensive API endpoint liveness check
nirholas811118790249
diff --git a/api/_lib/fonts/IBMPlexMono-Regular.ttf b/api/_lib/fonts/IBMPlexMono-Regular.ttfnew file mode 100644index 000000000..4254c37f2Binary files /dev/null and b/api/_lib/fonts/IBMPlexMono-Regular.ttf differdiff --git a/api/_lib/fonts/IBMPlexSans-Regular.ttf b/api/_lib/fonts/IBMPlexSans-Regular.ttfnew file mode 100644index 000000000..bd6817d52Binary files /dev/null and b/api/_lib/fonts/IBMPlexSans-Regular.ttf differdiff --git a/api/_lib/fonts/IBMPlexSans-SemiBold.ttf b/api/_lib/fonts/IBMPlexSans-SemiBold.ttfnew file mode 100644index 000000000..09ec8cdaeBinary files /dev/null and b/api/_lib/fonts/IBMPlexSans-SemiBold.ttf differdiff --git a/api/auth/[action].js b/api/auth/[action].jsindex d5add9492..76428fe0c 100644--- a/api/auth/[action].js+++ b/api/auth/[action].js@@ -13,7 +13,7 @@ import { randomToken, randomDigits, sha256 } from '../_lib/crypto.js';import { cors, json, method, readJson, wrap, error, rateLimited } from '../_lib/http.js';import { requireCsrf } from '../_lib/csrf.js';import { limits, clientIp } from '../_lib/rate-limit.js';-import { verifyBypassToken } from './captcha.js';+import captcha, { verifyBypassToken } from './captcha.js';import { parse, loginBody, registerBody, usernameRegisterBody, username as usernameValidator, displayName, email, password, bio as bioValidator, profileLocation, httpUrl } from '../_lib/validate.js';import { sendPasswordResetEmail, sendVerificationEmail } from '../_lib/email.js';import { referralCodeCandidates, normalizeReferralCode } from '../_lib/referrals.js';@@ -400,6 +400,10 @@ const DISPATCH = {'reset-password': handleResetPassword,'verify-email': handleVerifyEmail,'resend-verification': handleResendVerification,+ // The /api/auth/([^/]+) route matches before filesystem routing, so the+ // standalone captcha handler must be dispatched here or it is unreachable+ // and rate-limited users can never solve the login captcha.+ captcha,};export default wrap(async (req, res) => {diff --git a/api/page-og.js b/api/page-og.jsindex 2b9a6055a..95b41e4ef 100644--- a/api/page-og.js+++ b/api/page-og.js@@ -14,10 +14,28 @@// LinkedIn, and iMessage — none of which render image/svg+xml OG cards — all// show the preview.import { ImageResponse } from '@vercel/og';+import { readFileSync } from 'node:fs';const WIDTH = 1200;const HEIGHT = 630;+// IBM Plex faces for the light "carbon" variant (?v=carbon). Vendored TTFs+// (OFL-licensed) under api/_lib/fonts/ — loaded once per process, and only+// when a carbon card is actually requested, so the default dark card pays+// nothing. Satori can't consume woff2, hence TTF here rather than reusing+// the woff2 set under pages/ibm/fonts/.+let plexFonts = null;+function loadPlexFonts() {+ if (plexFonts) return plexFonts;+ const font = (file) => readFileSync(new URL(`./_lib/fonts/${file}`, import.meta.url));+ plexFonts = [+ { name: 'IBM Plex Sans', data: font('IBMPlexSans-Regular.ttf'), weight: 400, style: 'normal' },+ { name: 'IBM Plex Sans', data: font('IBMPlexSans-SemiBold.ttf'), weight: 600, style: 'normal' },+ { name: 'IBM Plex Mono', data: font('IBMPlexMono-Regular.ttf'), weight: 400, style: 'normal' },+ ];+ return plexFonts;+}+// Per-section identity. Each catalog section gets a distinct accent so a page's// share card reads as part of its family at a glance. Falls back to the brand// violet for anything unmapped.@@ -208,10 +226,184 @@ function card({ title, desc, section, route, accent }) {};}-function imageResponse(node) {+// Light Carbon-styled card (?v=carbon) for surfaces shared into the IBM+// ecosystem (IBM Community posts, watsonx content). IBM Plex type, IBM blue+// (#0f62fe), Carbon gray text ramp, sharp geometry — deliberately NO IBM logo+// or trademark: the only IBM reference is the factual "Built on IBM+// watsonx.ai" line, the framing docs/ibm.md permits.+function carbonCard({ title, desc, section, route }) {+ const blue = '#0f62fe';+ return {+ type: 'div',+ props: {+ style: {+ width: '100%',+ height: '100%',+ display: 'flex',+ flexDirection: 'column',+ justifyContent: 'space-between',+ padding: '64px 76px 58px',+ background: '#ffffff',+ color: '#161616',+ fontFamily: '"IBM Plex Sans"',+ },+ children: [+ // top rule — Carbon's signature blue bar+ {+ type: 'div',+ props: {+ style: { position: 'absolute', top: 0, left: 0, right: 0, height: 10, display: 'flex', background: blue },+ },+ },+ // geometric accent, top-right: quarter-circle + solid/outlined squares+ {+ type: 'div',+ props: {+ style: { position: 'absolute', top: 74, right: 76, display: 'flex', alignItems: 'flex-start' },+ children: [+ {+ type: 'div',+ props: {+ style: {+ width: 72,+ height: 72,+ background: '#d0e2ff',+ borderRadius: '0 0 0 72px',+ marginRight: 16,+ },+ },+ },+ { type: 'div', props: { style: { width: 72, height: 72, background: blue, marginRight: 16 } } },+ { type: 'div', props: { style: { width: 72, height: 72, border: `3px solid ${blue}` } } },+ ],+ },+ },+ // top row: wordmark + section tag+ {+ type: 'div',+ props: {+ style: { display: 'flex', alignItems: 'center' },+ children: [+ {+ type: 'div',+ props: {+ style: { display: 'flex', alignItems: 'baseline' },+ children: [+ {+ type: 'div',+ props: {+ style: { fontSize: 30, fontWeight: 600, letterSpacing: -0.5, color: '#161616' },+ children: 'three.ws',+ },+ },+ {+ type: 'div',+ props: {+ style: { fontSize: 30, fontWeight: 600, color: blue, marginLeft: 3 },+ children: '.',+ },+ },+ ],+ },+ },+ {+ type: 'div',+ props: {+ style: {+ display: 'flex',+ fontSize: 20,+ fontWeight: 600,+ color: '#0043ce',+ padding: '6px 14px',+ marginLeft: 26,+ borderRadius: 4,+ background: '#d0e2ff',+ },+ children: section.label,+ },+ },+ ],+ },+ },+ // middle: title + description, Plex gray ramp+ {+ type: 'div',+ props: {+ style: { display: 'flex', flexDirection: 'column', maxWidth: 980 },+ children: [+ {+ type: 'div',+ props: {+ style: {+ fontSize: title.length > 22 ? 68 : 84,+ fontWeight: 600,+ letterSpacing: -1.5,+ lineHeight: 1.06,+ color: '#161616',+ },+ children: title,+ },+ },+ desc+ ? {+ type: 'div',+ props: {+ style: {+ fontSize: 30,+ fontWeight: 400,+ lineHeight: 1.35,+ marginTop: 24,+ color: '#525252',+ },+ children: desc,+ },+ }+ : { type: 'div', props: { children: '' } },+ ],+ },+ },+ // bottom: route + factual watsonx line+ {+ type: 'div',+ props: {+ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' },+ children: [+ {+ type: 'div',+ props: {+ style: {+ display: 'flex',+ alignItems: 'center',+ fontSize: 23,+ fontFamily: '"IBM Plex Mono"',+ color: '#525252',+ },+ children: [+ { type: 'div', props: { style: { width: 12, height: 12, background: blue, marginRight: 14 } } },+ { type: 'div', props: { children: `three.ws${route}` } },+ ],+ },+ },+ {+ type: 'div',+ props: {+ style: { fontSize: 23, fontWeight: 600, color: blue },+ children: 'Built on IBM watsonx.ai',+ },+ },+ ],+ },+ },+ ],+ },+ };+}++function imageResponse(node, fonts) {return new ImageResponse(node, {width: WIDTH,height: HEIGHT,+ ...(fonts ? { fonts } : {}),headers: {'cache-control': 'public, max-age=3600, s-maxage=604800, stale-while-revalidate=86400',},@@ -240,12 +432,17 @@ export default async function handler(req, res) {const accent = section.accent;const title = clamp(url.searchParams.get('t') || 'three.ws', 60);const desc = clamp(url.searchParams.get('d') || '', 140);+ const variant = String(url.searchParams.get('v') || '').toLowerCase();let route = (url.searchParams.get('p') || '/').trim();if (!route.startsWith('/')) route = `/${route}`;route = clamp(route, 42);try {- await sendImage(res, imageResponse(card({ title, desc, section, route, accent })));+ if (variant === 'carbon') {+ await sendImage(res, imageResponse(carbonCard({ title, desc, section, route }), loadPlexFonts()));+ } else {+ await sendImage(res, imageResponse(card({ title, desc, section, route, accent })));+ }} catch (err) {// Never fail open to a broken-image box — render the coin-agnostic brand// card so the preview still looks intentional.diff --git a/examples/monicas-apartment/index.html b/examples/monicas-apartment/index.htmlnew file mode 100644index 000000000..72b000e3d--- /dev/null+++ b/examples/monicas-apartment/index.html@@ -0,0 +1,783 @@+<!DOCTYPE html>+<html lang="en">+<head>+<meta charset="utf-8" />+<meta name="viewport" content="width=device-width, initial-scale=1" />+<title>Monica's Apartment - a first-person Three.js scene</title>+<style>+ html, body { margin: 0; height: 100%; overflow: hidden; background: #120d16; }+ #app { position: fixed; inset: 0; }+ canvas { display: block; }++ #overlay {+ position: fixed; inset: 0; display: flex; flex-direction: column;+ align-items: center; justify-content: center; gap: 14px;+ background: radial-gradient(ellipse at center, rgba(30,18,36,.82), rgba(10,6,14,.94));+ color: #f3e9d6; font-family: Georgia, 'Times New Roman', serif;+ cursor: pointer; z-index: 10; text-align: center;+ transition: opacity .45s ease;+ }+ #overlay.hidden { opacity: 0; pointer-events: none; }+ #overlay h1 { font-size: clamp(28px, 5vw, 52px); font-weight: normal; margin: 0; letter-spacing: .04em; }+ #overlay h1 em { color: #e8b84b; font-style: normal; }+ #overlay p { margin: 0; font-size: 15px; opacity: .8; font-family: system-ui, sans-serif; }+ #overlay .enter {+ margin-top: 10px; padding: 12px 34px; border: 1px solid #e8b84b; border-radius: 999px;+ font-family: system-ui, sans-serif; font-size: 14px; letter-spacing: .12em;+ text-transform: uppercase; color: #e8b84b; background: rgba(232,184,75,.08);+ transition: background .2s ease, transform .2s ease;+ }+ #overlay:hover .enter { background: rgba(232,184,75,.2); transform: translateY(-1px); }++ #crosshair {+ position: fixed; left: 50%; top: 50%; width: 5px; height: 5px; border-radius: 50%;+ background: rgba(255, 240, 210, .85); transform: translate(-50%, -50%);+ z-index: 5; pointer-events: none; opacity: 0; transition: opacity .3s;+ box-shadow: 0 0 6px rgba(0,0,0,.6);+ }+ body.playing #crosshair { opacity: 1; }++ #hud {+ position: fixed; left: 16px; bottom: 14px; z-index: 5; pointer-events: none;+ color: rgba(243,233,214,.55); font: 12px/1.5 system-ui, sans-serif;+ opacity: 0; transition: opacity .3s;+ }+ body.playing #hud { opacity: 1; }+</style>+</head>+<body>+<div id="app"></div>+<div id="crosshair"></div>+<div id="hud">WASD move · mouse look · shift run · esc release</div>+<div id="overlay">+ <h1>The One With the <em>Purple Door</em></h1>+ <p>Monica's apartment, rebuilt in Three.js. First-person, fully walkable.</p>+ <div class="enter">Click to step inside</div>+</div>++<script type="importmap">+{ "imports": { "three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js" } }+</script>++<script type="module">+import * as THREE from 'three';++/* ------------------------------------------------------------------ */+/* Renderer / scene / camera */+/* ------------------------------------------------------------------ */++const app = document.getElementById('app');+const renderer = new THREE.WebGLRenderer({ antialias: true });+renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));+renderer.setSize(window.innerWidth, window.innerHeight);+renderer.shadowMap.enabled = true;+renderer.shadowMap.type = THREE.PCFSoftShadowMap;+renderer.outputColorSpace = THREE.SRGBColorSpace;+renderer.toneMapping = THREE.ACESFilmicToneMapping;+renderer.toneMappingExposure = 1.18;+app.appendChild(renderer.domElement);++const scene = new THREE.Scene();+scene.background = new THREE.Color(0x0b0918);+scene.fog = new THREE.Fog(0x0b0918, 22, 45);++const camera = new THREE.PerspectiveCamera(72, window.innerWidth / window.innerHeight, 0.05, 120);++// yaw/pitch rig for first-person look+const pitchRig = new THREE.Object3D();+pitchRig.add(camera);+const yawRig = new THREE.Object3D();+yawRig.add(pitchRig);+yawRig.position.set(0, 1.62, 3.1);+yawRig.rotation.y = Math.PI; // face the kitchen and the big window+scene.add(yawRig);++/* ------------------------------------------------------------------ */+/* Room dimensions */+/* ------------------------------------------------------------------ */++const W = 10, D = 8, H = 3.05; // interior: x in [-5,5], z in [-4,4]+const HX = W / 2, HZ = D / 2;++/* ------------------------------------------------------------------ */+/* Procedural textures */+/* ------------------------------------------------------------------ */++function canvasTexture(w, h, draw, repeatX = 1, repeatY = 1) {+ const c = document.createElement('canvas');+ c.width = w; c.height = h;+ draw(c.getContext('2d'), w, h);+ const t = new THREE.CanvasTexture(c);+ t.colorSpace = THREE.SRGBColorSpace;+ t.wrapS = t.wrapT = THREE.RepeatWrapping;+ t.repeat.set(repeatX, repeatY);+ t.anisotropy = 8;+ return t;+}++// seedable PRNG so the scene is identical every load+let seed = 1913;+function rand() { seed = (seed * 16807) % 2147483647; return (seed - 1) / 2147483646; }++const woodFloorTex = canvasTexture(512, 512, (g, w, h) => {+ g.fillStyle = '#8a5a33'; g.fillRect(0, 0, w, h);+ const plankH = h / 8;+ for (let r = 0; r < 8; r++) {+ for (let cx = -1; cx < 4; cx++) {+ const off = (r % 2) * (w / 6);+ const x = cx * (w / 3) + off, y = r * plankH;+ const l = 18 + rand() * 22;+ g.fillStyle = `rgb(${120 + l}, ${72 + l * 0.62}, ${36 + l * 0.35})`;+ g.fillRect(x, y, w / 3 - 2, plankH - 2);+ // grain+ g.strokeStyle = 'rgba(70,40,16,0.25)'; g.lineWidth = 1;+ for (let k = 0; k < 5; k++) {+ g.beginPath();+ const gy = y + rand() * plankH;+ g.moveTo(x, gy); g.bezierCurveTo(x + 40, gy + rand() * 4 - 2, x + 90, gy + rand() * 4 - 2, x + w / 3, gy);+ g.stroke();+ }+ }+ }+ g.fillStyle = 'rgba(40,22,8,0.55)';+ for (let r = 0; r <= 8; r++) g.fillRect(0, r * plankH - 1, w, 2);+}, 3.2, 2.6);++const rugTex = canvasTexture(512, 384, (g, w, h) => {+ g.fillStyle = '#7d1f1c'; g.fillRect(0, 0, w, h); // deep red field+ g.strokeStyle = '#d8b46a'; g.lineWidth = 10; g.strokeRect(14, 14, w - 28, h - 28);+ g.strokeStyle = '#3a5a45'; g.lineWidth = 4; g.strokeRect(30, 30, w - 60, h - 60);+ // medallion+ g.fillStyle = '#d8b46a';+ g.beginPath(); g.ellipse(w / 2, h / 2, 74, 52, 0, 0, Math.PI * 2); g.fill();+ g.fillStyle = '#7d1f1c';+ g.beginPath(); g.ellipse(w / 2, h / 2, 52, 34, 0, 0, Math.PI * 2); g.fill();+ g.fillStyle = '#e9d9a8';+ g.beginPath(); g.ellipse(w / 2, h / 2, 16, 11, 0, 0, Math.PI * 2); g.fill();+ // scattered motifs+ g.fillStyle = 'rgba(216,180,106,0.8)';+ for (let i = 0; i < 46; i++) {+ const x = 50 + rand() * (w - 100), y = 50 + rand() * (h - 100);+ if (Math.hypot(x - w / 2, y - h / 2) < 105) continue;+ g.fillRect(x, y, 7, 7);+ }+});++const cityTex = canvasTexture(1024, 512, (g, w, h) => {+ const grad = g.createLinearGradient(0, 0, 0, h);+ grad.addColorStop(0, '#0a0a24'); grad.addColorStop(0.65, '#1d1436'); grad.addColorStop(1, '#3a2140');+ g.fillStyle = grad; g.fillRect(0, 0, w, h);+ // stars+ g.fillStyle = 'rgba(255,255,255,0.7)';+ for (let i = 0; i < 90; i++) g.fillRect(rand() * w, rand() * h * 0.45, 1.4, 1.4);+ // two rows of buildings+ for (const [base, tone] of [[0.32, '#0d0b1a'], [0.18, '#151228']]) {+ let x = 0;+ while (x < w) {+ const bw = 40 + rand() * 80;+ const bh = h * (base + rand() * 0.42);+ g.fillStyle = tone; g.fillRect(x, h - bh, bw, bh);+ // lit windows+ for (let wx = x + 6; wx < x + bw - 8; wx += 12) {+ for (let wy = h - bh + 8; wy < h - 12; wy += 16) {+ if (rand() < 0.42) {+ g.fillStyle = rand() < 0.82 ? 'rgba(255,196,110,0.92)' : 'rgba(160,200,255,0.85)';+ g.fillRect(wx, wy, 6, 8);+ }+ }+ }+ x += bw + 4 + rand() * 26;+ }+ }+});++/* ------------------------------------------------------------------ */+/* Materials */+/* ------------------------------------------------------------------ */++const M = {+ wall: new THREE.MeshStandardMaterial({ color: 0x8e6ba1, roughness: 0.95 }), // Monica purple+ wallDeep: new THREE.MeshStandardMaterial({ color: 0x7c5a91, roughness: 0.95 }),+ ceiling: new THREE.MeshStandardMaterial({ color: 0xf0e4cf, roughness: 0.9 }),+ floor: new THREE.MeshStandardMaterial({ map: woodFloorTex, roughness: 0.55 }),+ trim: new THREE.MeshStandardMaterial({ color: 0xe8dcc0, roughness: 0.8 }),+ cabinet: new THREE.MeshStandardMaterial({ color: 0x2f8f86, roughness: 0.6 }), // teal kitchen+ counter: new THREE.MeshStandardMaterial({ color: 0xd9cdb2, roughness: 0.35 }),+ appliance: new THREE.MeshStandardMaterial({ color: 0xf2efe6, roughness: 0.35, metalness: 0.1 }),+ steel: new THREE.MeshStandardMaterial({ color: 0x9aa0a6, roughness: 0.35, metalness: 0.8 }),+ woodDark: new THREE.MeshStandardMaterial({ color: 0x5a3a22, roughness: 0.6 }),+ woodMid: new THREE.MeshStandardMaterial({ color: 0x8a5c34, roughness: 0.6 }),+ doorPurple:new THREE.MeshStandardMaterial({ color: 0x6b4a86, roughness: 0.7 }),+ doorWood: new THREE.MeshStandardMaterial({ color: 0xcfbfa2, roughness: 0.75 }),+ frameYellow:new THREE.MeshStandardMaterial({ color: 0xe8b84b, roughness: 0.5 }),+ sofa: new THREE.MeshStandardMaterial({ color: 0xb5806a, roughness: 0.95 }), // dusty rose-tan+ sofaDeep: new THREE.MeshStandardMaterial({ color: 0xa06f5c, roughness: 0.95 }),+ chairGreen:new THREE.MeshStandardMaterial({ color: 0x5d7a4a, roughness: 0.95 }),+ chairGold: new THREE.MeshStandardMaterial({ color: 0xb98c3a, roughness: 0.95 }),+ rug: new THREE.MeshStandardMaterial({ map: rugTex, roughness: 1 }),+ black: new THREE.MeshStandardMaterial({ color: 0x1c1a1a, roughness: 0.6 }),+ tvScreen: new THREE.MeshStandardMaterial({ color: 0x101418, roughness: 0.2, metalness: 0.4 }),+ lampShade: new THREE.MeshStandardMaterial({ color: 0xffdfa0, emissive: 0xffb75e, emissiveIntensity: 1.6, roughness: 1, side: THREE.DoubleSide }),+ glass: new THREE.MeshStandardMaterial({ color: 0xbcd4e8, transparent: true, opacity: 0.07, roughness: 0.1, metalness: 0.2 }),+ plant: new THREE.MeshStandardMaterial({ color: 0x3f6b35, roughness: 1 }),+ pot: new THREE.MeshStandardMaterial({ color: 0xa8552f, roughness: 0.9 }),+ curtain: new THREE.MeshStandardMaterial({ color: 0xd8c49a, roughness: 1, side: THREE.DoubleSide }),+ railing: new THREE.MeshStandardMaterial({ color: 0x22201f, roughness: 0.5, metalness: 0.6 }),+};++/* ------------------------------------------------------------------ */+/* Collision */+/* ------------------------------------------------------------------ */++const colliders = [];+const PLAYER_R = 0.28;+function addCollider(minX, maxX, minZ, maxZ) { colliders.push({ minX, maxX, minZ, maxZ }); }++/* ------------------------------------------------------------------ */+/* Helpers */+/* ------------------------------------------------------------------ */++function box(w, h, d, mat, x, y, z, { shadow = true, collide = false, ry = 0, parent = scene } = {}) {+ const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);+ m.position.set(x, y, z);+ m.rotation.y = ry;+ m.castShadow = shadow; m.receiveShadow = true;+ parent.add(m);+ if (collide && parent === scene) {+ const hw = (Math.abs(Math.cos(ry)) * w + Math.abs(Math.sin(ry)) * d) / 2;+ const hd = (Math.abs(Math.sin(ry)) * w + Math.abs(Math.cos(ry)) * d) / 2;+ addCollider(x - hw, x + hw, z - hd, z + hd);+ }+ return m;+}++/* ------------------------------------------------------------------ */+/* Shell: floor, ceiling, walls with window + door openings */+/* ------------------------------------------------------------------ */++{+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(W, D), M.floor);+ floor.rotation.x = -Math.PI / 2;+ floor.receiveShadow = true;+ scene.add(floor);++ const ceil = new THREE.Mesh(new THREE.PlaneGeometry(W, D), M.ceiling);+ ceil.rotation.x = Math.PI / 2;+ ceil.position.y = H;+ scene.add(ceil);+}++const WT = 0.18; // wall thickness++// North wall (z = -HZ): big living-room window x in [0.8, 4.2], y in [0.75, 2.75]+// plus a small kitchen window x in [-3.6, -2.6], y in [1.25, 2.25]+function wallWithOpenings(axis, at, from, to, openings) {+ // vertical wall built from segments; openings: [{a0,a1,y0,y1}] along the wall axis+ const segs = [];+ let cursor = from;+ const sorted = [...openings].sort((a, b) => a.a0 - b.a0);+ for (const o of sorted) { segs.push({ a0: cursor, a1: o.a0, full: true }); cursor = o.a1; }+ segs.push({ a0: cursor, a1: to, full: true });+ const parts = [];+ for (const s of segs) if (s.a1 - s.a0 > 0.01) parts.push({ a0: s.a0, a1: s.a1, y0: 0, y1: H });+ for (const o of sorted) {+ if (o.y0 > 0.01) parts.push({ a0: o.a0, a1: o.a1, y0: 0, y1: o.y0 });+ if (o.y1 < H - 0.01) parts.push({ a0: o.a0, a1: o.a1, y0: o.y1, y1: H });+ }+ for (const p of parts) {+ const len = p.a1 - p.a0, ht = p.y1 - p.y0;+ const mid = (p.a0 + p.a1) / 2, ymid = (p.y0 + p.y1) / 2;+ if (axis === 'x') box(len, ht, WT, M.wall, mid, ymid, at, { shadow: false });+ else box(WT, ht, len, M.wall, at, ymid, mid, { shadow: false });+ }+ if (axis === 'x') addCollider(from, to, at - WT, at + WT);+ else addCollider(at - WT, at + WT, from, to);+}++wallWithOpenings('x', -HZ, -HX, HX, [+ { a0: 0.8, a1: 4.2, y0: 0.75, y1: 2.75 },+ { a0: -3.6, a1: -2.6, y0: 1.25, y1: 2.25 },+]);+wallWithOpenings('x', HZ, -HX, HX, []); // south wall (solid)+wallWithOpenings('z', -HX, -HZ, HZ, []); // west wall (bedroom doors are set dressing)+wallWithOpenings('z', HX, -HZ, HZ, []); // east wall (front door is set dressing)++// baseboards + crown+for (const [z] of [[-HZ + WT / 2 + 0.02], [HZ - WT / 2 - 0.02]]) {+ box(W, 0.12, 0.03, M.trim, 0, 0.06, z, { shadow: false });+ box(W, 0.09, 0.03, M.trim, 0, H - 0.045, z, { shadow: false });+}+for (const [x] of [[-HX + WT / 2 + 0.02], [HX - WT / 2 - 0.02]]) {+ box(0.03, 0.12, D, M.trim, x, 0.06, 0, { shadow: false });+ box(0.03, 0.09, D, M.trim, x, H - 0.045, 0, { shadow: false });+}++/* ------------------------------------------------------------------ */+/* Big window: frame, mullions, glass, curtains */+/* ------------------------------------------------------------------ */++function pane(x0, x1, y0, y1, z) {+ // frame+ const fw = 0.07;+ box(x1 - x0 + fw * 2, fw, WT + 0.06, M.woodDark, (x0 + x1) / 2, y1 + fw / 2, z, { shadow: false });+ box(x1 - x0 + fw * 2, fw, WT + 0.06, M.woodDark, (x0 + x1) / 2, y0 - fw / 2, z, { shadow: false });+ box(fw, y1 - y0, WT + 0.06, M.woodDark, x0 - fw / 2, (y0 + y1) / 2, z, { shadow: false });+ box(fw, y1 - y0, WT + 0.06, M.woodDark, x1 + fw / 2, (y0 + y1) / 2, z, { shadow: false });+ // mullions: 4 cols x 3 rows+ const cols = 4, rows = 3;+ for (let i = 1; i < cols; i++)+ box(0.035, y1 - y0, 0.05, M.woodDark, x0 + (x1 - x0) * i / cols, (y0 + y1) / 2, z, { shadow: false });+ for (let j = 1; j < rows; j++)+ box(x1 - x0, 0.035, 0.05, M.woodDark, (x0 + x1) / 2, y0 + (y1 - y0) * j / rows, z, { shadow: false });+ // glass+ const g = new THREE.Mesh(new THREE.PlaneGeometry(x1 - x0, y1 - y0), M.glass);+ g.position.set((x0 + x1) / 2, (y0 + y1) / 2, z);+ scene.add(g);+ // sill+ box(x1 - x0 + 0.3, 0.05, 0.28, M.trim, (x0 + x1) / 2, y0 - 0.025, z + 0.1, { shadow: false });+}++pane(0.8, 4.2, 0.75, 2.75, -HZ);+pane(-3.6, -2.6, 1.25, 2.25, -HZ);++// curtains flanking the big window+for (const cx of [0.62, 4.38]) {+ const cur = new THREE.Mesh(new THREE.PlaneGeometry(0.5, 2.35, 8, 1), M.curtain);+ const pos = cur.geometry.attributes.position;+ for (let i = 0; i < pos.count; i++) pos.setZ(i, Math.sin(pos.getX(i) * 22) * 0.05);+ pos.needsUpdate = true;+ cur.geometry.computeVertexNormals();+ cur.position.set(cx, 1.72, -HZ + WT / 2 + 0.12);+ scene.add(cur);+}+box(3.9, 0.05, 0.05, M.woodDark, 2.5, 2.94, -HZ + WT / 2 + 0.12, { shadow: false }); // curtain rod++/* ------------------------------------------------------------------ */+/* Outside: balcony, fire-escape railing, skyline, moon */+/* ------------------------------------------------------------------ */++{+ const balc = box(4.4, 0.08, 1.6, M.black, 2.5, 0.71, -HZ - 0.9, { shadow: false });+ balc.receiveShadow = true;+ // railing+ for (let i = 0; i <= 10; i++)+ box(0.035, 1.0, 0.035, M.railing, 0.4 + i * 0.42, 1.25, -HZ - 1.65, { shadow: false });+ box(4.4, 0.05, 0.05, M.railing, 2.5, 1.78, -HZ - 1.65, { shadow: false });+ for (const zz of [-HZ - 1.3, -HZ - 0.95]) {+ box(0.035, 1.0, 0.7, M.railing, 0.35, 1.25, zz + 0.35 - 0.35, { shadow: false });+ }+ // side rails+ box(0.04, 0.05, 1.55, M.railing, 0.35, 1.78, -HZ - 0.9, { shadow: false });+ box(0.04, 0.05, 1.55, M.railing, 4.65, 1.78, -HZ - 0.9, { shadow: false });+ // fire-escape ladder hint+ for (let i = 0; i < 6; i++)+ box(0.5, 0.035, 0.035, M.railing, 4.35, 0.4 + i * 0.5, -HZ - 1.55, { shadow: false });++ // skyline: big unlit backdrop+ const city = new THREE.Mesh(new THREE.PlaneGeometry(60, 30), new THREE.MeshBasicMaterial({ map: cityTex }));+ city.position.set(0, 7, -HZ - 22);+ scene.add(city);++ const moon = new THREE.Mesh(new THREE.CircleGeometry(1.1, 32),+ new THREE.MeshBasicMaterial({ color: 0xfff4d6 }));+ moon.position.set(-7, 13.5, -HZ - 21.5);+ scene.add(moon);+ const glow = new THREE.Mesh(new THREE.CircleGeometry(1.9, 32),+ new THREE.MeshBasicMaterial({ color: 0xfff4d6, transparent: true, opacity: 0.16 }));+ glow.position.set(-7, 13.5, -HZ - 21.6);+ scene.add(glow);+}++/* ------------------------------------------------------------------ */+/* Doors (set dressing on solid walls) */+/* ------------------------------------------------------------------ */++function door(axis, at, along, mat, { frameMat = M.trim, peephole = false } = {}) {+ const dw = 0.95, dh = 2.08, t = 0.06;+ const fx = 0.09;+ if (axis === 'z') { // on west/east wall, door faces +/- x+ const dir = at < 0 ? 1 : -1;+ const x = at + dir * (WT / 2 + t / 2);+ box(t, dh, dw, mat, x, dh / 2, along, { shadow: false });+ box(t + 0.02, dh + fx, fx, frameMat, x, (dh + fx) / 2 - fx / 2 + 0.04, along - dw / 2 - fx / 2, { shadow: false });+ box(t + 0.02, dh + fx, fx, frameMat, x, (dh + fx) / 2 - fx / 2 + 0.04, along + dw / 2 + fx / 2, { shadow: false });+ box(t + 0.02, fx, dw + fx * 2, frameMat, x, dh + fx / 2, along, { shadow: false });+ // knob+ box(0.05, 0.05, 0.05, M.frameYellow, x + dir * 0.05, 1.02, along + dw / 2 - 0.14, { shadow: false });+ if (peephole) {+ // the iconic yellow frame around the peephole+ const yf = new THREE.Mesh(new THREE.TorusGeometry(0.11, 0.022, 10, 4), M.frameYellow);+ yf.rotation.y = Math.PI / 2;+ yf.rotation.z = Math.PI / 4;+ yf.position.set(x + dir * (t / 2 + 0.015), 1.62, along);+ scene.add(yf);+ const ph = new THREE.Mesh(new THREE.CircleGeometry(0.018, 12), M.black);+ ph.rotation.y = dir > 0 ? Math.PI / 2 : -Math.PI / 2;+ ph.position.set(x + dir * (t / 2 + 0.016), 1.62, along);+ scene.add(ph);+ }+ }+}++door('z', HX, 0.9, M.doorPurple, { peephole: true }); // front door, east wall+door('z', HX, -1.8, M.doorWood); // bathroom+door('z', -HX, -1.9, M.doorWood); // Monica's room+door('z', -HX, 1.2, M.doorWood); // Rachel's room++/* ------------------------------------------------------------------ */+/* Kitchen (north-west) */+/* ------------------------------------------------------------------ */++{+ const backZ = -HZ + WT / 2;+ // base cabinets along north wall, x -4.9 .. -1.5+ box(3.4, 0.82, 0.62, M.cabinet, -3.2, 0.41, backZ + 0.31, { collide: true });+ box(3.5, 0.06, 0.7, M.counter, -3.2, 0.87, backZ + 0.35);+ // cabinet door lines+ for (let i = 0; i < 5; i++)+ box(0.56, 0.6, 0.02, M.counter.clone(), -4.7 + i * 0.68, 0.45, backZ + 0.63, { shadow: false })+ .material.color.set(0x257a72);+ // sink under the kitchen window+ box(0.7, 0.02, 0.44, M.steel, -3.1, 0.885, backZ + 0.33, { shadow: false });+ const faucet = new THREE.Mesh(new THREE.TorusGeometry(0.09, 0.016, 8, 16, Math.PI), M.steel);+ faucet.position.set(-3.1, 0.98, backZ + 0.16); faucet.rotation.z = 0; scene.add(faucet);+ // upper cabinets (skip the window span)+ box(1.1, 0.75, 0.36, M.cabinet, -4.35, 2.15, backZ + 0.18, { shadow: false });+ box(1.1, 0.75, 0.36, M.cabinet, -1.95, 2.15, backZ + 0.18, { shadow: false });+ // fridge, west wall+ box(0.8, 1.85, 0.75, M.appliance, -HX + WT / 2 + 0.38, 0.925, -2.9, { collide: true });+ box(0.7, 0.03, 0.03, M.steel, -HX + WT / 2 + 0.74, 1.35, -2.9, { shadow: false, ry: Math.PI / 2 });+ // stove, in the counter run+ box(0.76, 0.86, 0.66, M.appliance, -1.55, 0.43, backZ + 0.33, { collide: true });+ for (let i = 0; i < 4; i++) {+ const b = new THREE.Mesh(new THREE.CylinderGeometry(0.09, 0.09, 0.012, 16), M.black);+ b.position.set(-1.73 + (i % 2) * 0.36, 0.905, backZ + 0.18 + Math.floor(i / 2) * 0.3);+ scene.add(b);+ }+ // open shelves with dishes on west wall+ for (let s = 0; s < 2; s++) {+ box(0.9, 0.03, 0.26, M.woodMid, -HX + WT / 2 + 0.14, 1.6 + s * 0.42, -1.4, { shadow: false, ry: 0 });+ for (let p = 0; p < 3; p++) {+ const plate = new THREE.Mesh(new THREE.CylinderGeometry(0.085, 0.085, 0.09, 14), M.appliance);+ plate.position.set(-HX + WT / 2 + 0.14, 1.67 + s * 0.42, -1.68 + p * 0.28);+ scene.add(plate);+ }+ }+}++/* ------------------------------------------------------------------ */+/* Dining table + mismatched chairs */+/* ------------------------------------------------------------------ */++function chair(x, z, ry, seatMat) {+ const g = new THREE.Group();+ g.position.set(x, 0, z); g.rotation.y = ry;+ scene.add(g);+ box(0.42, 0.05, 0.42, seatMat, 0, 0.45, 0, { parent: g });+ box(0.42, 0.5, 0.05, seatMat, 0, 0.72, -0.19, { parent: g });+ for (const [lx, lz] of [[-0.17, -0.17], [0.17, -0.17], [-0.17, 0.17], [0.17, 0.17]])+ box(0.045, 0.45, 0.045, M.woodDark, lx, 0.225, lz, { parent: g });+ addCollider(x - 0.24, x + 0.24, z - 0.24, z + 0.24);+}++{+ const tx = -2.7, tz = -1.5;+ const top = new THREE.Mesh(new THREE.CylinderGeometry(0.78, 0.78, 0.06, 28), M.woodMid);+ top.position.set(tx, 0.74, tz); top.castShadow = true; top.receiveShadow = true;+ scene.add(top);+ const leg = new THREE.Mesh(new THREE.CylinderGeometry(0.09, 0.13, 0.72, 12), M.woodDark);+ leg.position.set(tx, 0.37, tz); leg.castShadow = true;+ scene.add(leg);+ const foot = new THREE.Mesh(new THREE.CylinderGeometry(0.34, 0.38, 0.05, 20), M.woodDark);+ foot.position.set(tx, 0.03, tz); scene.add(foot);+ addCollider(tx - 0.8, tx + 0.8, tz - 0.8, tz + 0.8);++ // the famous mismatched chairs+ chair(tx, tz - 1.06, Math.PI, M.chairGreen);+ chair(tx + 1.06, tz, -Math.PI / 2, M.chairGold);+ chair(tx, tz + 1.06, 0, M.doorPurple);+ chair(tx - 1.06, tz, Math.PI / 2, M.sofa);++ // fruit bowl+ const bowl = new THREE.Mesh(new THREE.SphereGeometry(0.16, 18, 10, 0, Math.PI * 2, 0, Math.PI / 2), M.cabinet);+ bowl.rotation.x = Math.PI; bowl.position.set(tx, 0.83, tz); scene.add(bowl);+ for (let i = 0; i < 4; i++) {+ const fruit = new THREE.Mesh(new THREE.SphereGeometry(0.05, 10, 8),+ new THREE.MeshStandardMaterial({ color: [0xd8442c, 0xe0a02c, 0x89a02c, 0xd8442c][i], roughness: 0.6 }));+ fruit.position.set(tx - 0.06 + (i % 2) * 0.12, 0.85, tz - 0.05 + Math.floor(i / 2) * 0.1);+ scene.add(fruit);+ }+}++/* ------------------------------------------------------------------ */+/* Living room */+/* ------------------------------------------------------------------ */++{+ // rug+ const rug = new THREE.Mesh(new THREE.PlaneGeometry(3.6, 2.6), M.rug);+ rug.rotation.x = -Math.PI / 2;+ rug.position.set(1.6, 0.012, 0.9);+ rug.receiveShadow = true;+ scene.add(rug);++ // sofa (facing south, back to the window)+ const sg = new THREE.Group(); sg.position.set(1.6, 0, -0.45); scene.add(sg);+ box(2.1, 0.42, 0.9, M.sofaDeep, 0, 0.21, 0, { parent: sg });+ box(2.1, 0.62, 0.24, M.sofa, 0, 0.72, -0.33, { parent: sg });+ box(0.26, 0.62, 0.9, M.sofa, -1.05 - 0.02, 0.52, 0, { parent: sg });+ box(0.26, 0.62, 0.9, M.sofa, 1.05 + 0.02, 0.52, 0, { parent: sg });+ for (let i = 0; i < 3; i++) box(0.62, 0.16, 0.62, M.sofa, -0.66 + i * 0.66, 0.5, 0.06, { parent: sg });+ // throw pillows+ box(0.34, 0.3, 0.12, M.chairGold, -0.72, 0.72, -0.16, { parent: sg, ry: 0.2 });+ box(0.34, 0.3, 0.12, M.chairGreen, 0.72, 0.72, -0.16, { parent: sg, ry: -0.15 });+ addCollider(1.6 - 1.2, 1.6 + 1.2, -0.45 - 0.5, -0.45 + 0.5);++ // coffee table with books + mug+ box(1.15, 0.07, 0.6, M.woodMid, 1.6, 0.36, 0.95, { collide: true });+ for (const [lx, lz] of [[-0.5, -0.22], [0.5, -0.22], [-0.5, 0.22], [0.5, 0.22]])+ box(0.05, 0.33, 0.05, M.woodDark, 1.6 + lx, 0.165, 0.95 + lz);+ box(0.28, 0.035, 0.2, M.chairGreen, 1.42, 0.41, 0.9, { ry: 0.25, shadow: false });+ box(0.26, 0.03, 0.18, M.doorPurple, 1.44, 0.44, 0.9, { ry: 0.12, shadow: false });+ const mug = new THREE.Mesh(new THREE.CylinderGeometry(0.045, 0.04, 0.1, 14), M.frameYellow);+ mug.position.set(1.95, 0.445, 1.0); scene.add(mug);++ // green armchair (west of rug, angled toward the sofa)+ const ag = new THREE.Group(); ag.position.set(-0.45, 0, 0.95); ag.rotation.y = Math.PI / 2.6; scene.add(ag);+ box(0.85, 0.4, 0.8, M.chairGreen, 0, 0.2, 0, { parent: ag });+ box(0.85, 0.65, 0.22, M.chairGreen, 0, 0.66, -0.29, { parent: ag });+ box(0.2, 0.55, 0.8, M.chairGreen, -0.52, 0.47, 0, { parent: ag });+ box(0.2, 0.55, 0.8, M.chairGreen, 0.52, 0.47, 0, { parent: ag });+ box(0.6, 0.14, 0.56, M.chairGreen, 0, 0.47, 0.05, { parent: ag });+ addCollider(-1.05, 0.15, 0.35, 1.55);++ // gold armchair + ottoman (east of rug)+ const gg = new THREE.Group(); gg.position.set(3.6, 0, 0.9); gg.rotation.y = -Math.PI / 2.4; scene.add(gg);+ box(0.85, 0.4, 0.8, M.chairGold, 0, 0.2, 0, { parent: gg });+ box(0.85, 0.65, 0.22, M.chairGold, 0, 0.66, -0.29, { parent: gg });+ box(0.2, 0.55, 0.8, M.chairGold, -0.52, 0.47, 0, { parent: gg });+ box(0.2, 0.55, 0.8, M.chairGold, 0.52, 0.47, 0, { parent: gg });+ box(0.6, 0.14, 0.56, M.chairGold, 0, 0.47, 0.05, { parent: gg });+ addCollider(3.0, 4.2, 0.3, 1.5);+ box(0.55, 0.3, 0.45, M.chairGold, 2.9, 0.15, 1.7, { collide: true, ry: 0.3 });++ // TV on cabinet against the south wall+ box(1.5, 0.55, 0.5, M.woodDark, 1.6, 0.275, HZ - WT / 2 - 0.34, { collide: true });+ box(0.95, 0.72, 0.45, M.black, 1.6, 0.91, HZ - WT / 2 - 0.33);+ box(0.8, 0.58, 0.02, M.tvScreen, 1.6, 0.92, HZ - WT / 2 - 0.57, { shadow: false });+ // VHS stack+ box(0.24, 0.05, 0.16, M.doorPurple, 1.05, 0.58, HZ - WT / 2 - 0.3, { shadow: false });+ box(0.24, 0.05, 0.16, M.chairGreen, 1.05, 0.63, HZ - WT / 2 - 0.31, { shadow: false, ry: 0.15 });++ // bookshelf on the south wall+ const bx = -1.4, bz = HZ - WT / 2 - 0.19;+ box(1.3, 2.0, 0.34, M.woodMid, bx, 1.0, bz, { collide: true });+ for (let s = 0; s < 4; s++) {+ box(1.2, 0.03, 0.3, M.woodDark, bx, 0.35 + s * 0.48, bz - 0.01, { shadow: false });+ let cx2 = bx - 0.55;+ while (cx2 < bx + 0.5) {+ const bw2 = 0.05 + rand() * 0.05, bh2 = 0.25 + rand() * 0.14;+ const bookMat = new THREE.MeshStandardMaterial({+ color: new THREE.Color().setHSL(rand(), 0.45 + rand() * 0.3, 0.32 + rand() * 0.2), roughness: 0.9 });+ box(bw2, bh2, 0.22, bookMat, cx2 + bw2 / 2, 0.37 + s * 0.48 + bh2 / 2, bz - 0.02, { shadow: false });+ cx2 += bw2 + 0.012;+ }+ }++ // side table + lamp by the sofa+ box(0.45, 0.55, 0.45, M.woodDark, 3.15, 0.275, -0.6, { collide: true });+ const stemS = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.03, 0.35, 10), M.frameYellow);+ stemS.position.set(3.15, 0.73, -0.6); scene.add(stemS);+ const shadeS = new THREE.Mesh(new THREE.CylinderGeometry(0.11, 0.16, 0.2, 16, 1, true), M.lampShade);+ shadeS.position.set(3.15, 0.98, -0.6); scene.add(shadeS);++ // floor lamp near the green chair+ const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.022, 0.03, 1.45, 10), M.black);+ stem.position.set(-0.5, 0.73, 2.5); scene.add(stem);+ const base = new THREE.Mesh(new THREE.CylinderGeometry(0.16, 0.18, 0.04, 16), M.black);+ base.position.set(-0.5, 0.02, 2.5); scene.add(base);+ const shade = new THREE.Mesh(new THREE.CylinderGeometry(0.14, 0.2, 0.28, 16, 1, true), M.lampShade);+ shade.position.set(-0.5, 1.56, 2.5); scene.add(shade);+ addCollider(-0.68, -0.32, 2.32, 2.68);+}++/* ------------------------------------------------------------------ */+/* Set dressing: frames, plants, console table */+/* ------------------------------------------------------------------ */++{+ // picture frames on the purple walls+ const frames = [+ { x: -HX + WT / 2 + 0.02, z: -0.35, ry: Math.PI / 2, w: 0.4, h: 0.5, c: 0xc8b370 },+ { x: -HX + WT / 2 + 0.02, z: 0.25, ry: Math.PI / 2, w: 0.3, h: 0.38, c: 0x7d1f1c },+ { x: -0.2, z: HZ - WT / 2 - 0.02, ry: Math.PI, w: 0.5, h: 0.4, c: 0x3a5a45 },+ { x: 3.4, z: HZ - WT / 2 - 0.02, ry: Math.PI, w: 0.34, h: 0.44, c: 0x30506a },+ { x: HX - WT / 2 - 0.02, z: -0.6, ry: -Math.PI / 2, w: 0.42, h: 0.34, c: 0xa06f5c },+ ];+ for (const f of frames) {+ const g = new THREE.Group();+ g.position.set(f.x, 1.65, f.z); g.rotation.y = f.ry; scene.add(g);+ box(f.w + 0.06, f.h + 0.06, 0.03, M.frameYellow, 0, 0, 0, { parent: g, shadow: false });+ const art = new THREE.Mesh(new THREE.PlaneGeometry(f.w, f.h),+ new THREE.MeshStandardMaterial({ color: f.c, roughness: 1 }));+ art.position.z = 0.017; g.add(art);+ }++ // plants+ function plant(x, z, s = 1) {+ const potM = new THREE.Mesh(new THREE.CylinderGeometry(0.16 * s, 0.12 * s, 0.28 * s, 12), M.pot);+ potM.position.set(x, 0.14 * s, z); potM.castShadow = true; scene.add(potM);+ for (let i = 0; i < 5; i++) {+ const leaf = new THREE.Mesh(new THREE.ConeGeometry(0.08 * s, 0.55 * s, 6), M.plant);+ leaf.position.set(x + (rand() - 0.5) * 0.18 * s, 0.28 * s + 0.24 * s, z + (rand() - 0.5) * 0.18 * s);+ leaf.rotation.set((rand() - 0.5) * 0.5, 0, (rand() - 0.5) * 0.5);+ leaf.castShadow = true; scene.add(leaf);+ }+ addCollider(x - 0.2 * s, x + 0.2 * s, z - 0.2 * s, z + 0.2 * s);+ }+ plant(4.55, -3.3, 1.3); // by the window+ plant(-4.5, 3.4, 1.0); // near Rachel's door++ // console table beside the front door+ box(0.8, 0.75, 0.32, M.woodDark, HX - WT / 2 - 0.2, 0.375, 2.1, { collide: true, ry: Math.PI / 2 });+ const bowl2 = new THREE.Mesh(new THREE.SphereGeometry(0.1, 14, 8, 0, Math.PI * 2, 0, Math.PI / 2), M.frameYellow);+ bowl2.rotation.x = Math.PI; bowl2.position.set(HX - WT / 2 - 0.2, 0.79, 2.1); scene.add(bowl2);+}++/* ------------------------------------------------------------------ */+/* Warm lighting */+/* ------------------------------------------------------------------ */++{+ scene.add(new THREE.AmbientLight(0xffd9ab, 0.22));+ const hemi = new THREE.HemisphereLight(0xffe3b8, 0x3a2a20, 0.5);+ scene.add(hemi);++ // pendant over the dining table (main shadow light)+ const pendant = new THREE.PointLight(0xffc281, 42, 14, 2);+ pendant.position.set(-2.7, 2.35, -1.5);+ pendant.castShadow = true;+ pendant.shadow.mapSize.set(1024, 1024);+ pendant.shadow.bias = -0.004;+ scene.add(pendant);+ // pendant fixture+ const cord = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.55, 6), M.black);+ cord.position.set(-2.7, H - 0.28, -1.5); scene.add(cord);+ const shade = new THREE.Mesh(new THREE.ConeGeometry(0.24, 0.2, 18, 1, true), M.lampShade);+ shade.position.set(-2.7, 2.45, -1.5); scene.add(shade);++ // floor lamp light+ const fl = new THREE.PointLight(0xffb46e, 26, 10, 2);+ fl.position.set(-0.5, 1.6, 2.5);+ fl.castShadow = true;+ fl.shadow.mapSize.set(1024, 1024);+ fl.shadow.bias = -0.004;+ scene.add(fl);++ // side-table lamp+ const sl = new THREE.PointLight(0xffb46e, 12, 7, 2);+ sl.position.set(3.15, 1.05, -0.6);+ scene.add(sl);++ // kitchen warm fill+ const kl = new THREE.PointLight(0xffcf96, 18, 9, 2);+ kl.position.set(-3.2, 2.5, -2.6);+ scene.add(kl);++ // cool moonlight through the big window+ const moonlight = new THREE.DirectionalLight(0x8fa8e8, 0.35);+ moonlight.position.set(2.5, 6, -12);+ moonlight.target.position.set(2.0, 0, 0.5);+ scene.add(moonlight, moonlight.target);++ // TV-side gentle fill so the south end isn't dead+ const tvFill = new THREE.PointLight(0xffc9a0, 8, 8, 2);+ tvFill.position.set(1.6, 2.2, 2.6);+ scene.add(tvFill);+}++/* ------------------------------------------------------------------ */+/* First-person controls + collision */+/* ------------------------------------------------------------------ */++const overlay = document.getElementById('overlay');+const keys = {};+let playing = false;++overlay.addEventListener('click', () => renderer.domElement.requestPointerLock());+document.addEventListener('pointerlockchange', () => {+ playing = document.pointerLockElement === renderer.domElement;+ overlay.classList.toggle('hidden', playing);+ document.body.classList.toggle('playing', playing);+});+document.addEventListener('mousemove', (e) => {+ if (!playing) return;+ yawRig.rotation.y -= e.movementX * 0.0022;+ pitchRig.rotation.x = THREE.MathUtils.clamp(pitchRig.rotation.x - e.movementY * 0.0022, -1.35, 1.35);+});+document.addEventListener('keydown', (e) => { keys[e.code] = true; });+document.addEventListener('keyup', (e) => { keys[e.code] = false; });++function blocked(x, z) {+ if (x < -HX + WT + PLAYER_R || x > HX - WT - PLAYER_R) return true;+ if (z < -HZ + WT + PLAYER_R || z > HZ - WT - PLAYER_R) return true;+ for (const c of colliders) {+ if (x > c.minX - PLAYER_R && x < c.maxX + PLAYER_R &&+ z > c.minZ - PLAYER_R && z < c.maxZ + PLAYER_R) return true;+ }+ return false;+}++const clock = new THREE.Clock();+let bobT = 0;++function tick() {+ const dt = Math.min(clock.getDelta(), 0.05);++ if (playing) {+ const run = keys['ShiftLeft'] || keys['ShiftRight'];+ const speed = (run ? 3.6 : 2.0) * dt;+ let mx = 0, mz = 0;+ if (keys['KeyW'] || keys['ArrowUp']) mz -= 1;+ if (keys['KeyS'] || keys['ArrowDown']) mz += 1;+ if (keys['KeyA'] || keys['ArrowLeft']) mx -= 1;+ if (keys['KeyD'] || keys['ArrowRight']) mx += 1;+ if (mx || mz) {+ const len = Math.hypot(mx, mz); mx /= len; mz /= len;+ const sin = Math.sin(yawRig.rotation.y), cos = Math.cos(yawRig.rotation.y);+ const dx = (mx * cos + mz * sin) * speed;+ const dz = (mz * cos - mx * sin) * speed;+ // axis-separated so we slide along furniture+ if (!blocked(yawRig.position.x + dx, yawRig.position.z)) yawRig.position.x += dx;+ if (!blocked(yawRig.position.x, yawRig.position.z + dz)) yawRig.position.z += dz;+ bobT += dt * (run ? 11 : 7.5);+ camera.position.y = Math.sin(bobT) * 0.026;+ } else {+ camera.position.y *= 0.9;+ }+ }++ renderer.render(scene, camera);+ requestAnimationFrame(tick);+}+tick();++window.addEventListener('resize', () => {+ camera.aspect = window.innerWidth / window.innerHeight;+ camera.updateProjectionMatrix();+ renderer.setSize(window.innerWidth, window.innerHeight);+});++// headless-verification hook: position the camera and report readiness+window.__scene = {+ ready: true,+ snap(x, y, z, yaw, pitch = 0) {+ yawRig.position.set(x, y, z);+ yawRig.rotation.y = yaw;+ pitchRig.rotation.x = pitch;+ renderer.render(scene, camera);+ },+};+</script>+</body>+</html>diff --git a/package-lock.json b/package-lock.jsonindex 1a4eb680f..6062e8816 100644--- a/package-lock.json+++ b/package-lock.json@@ -212,7 +212,7 @@"agent-payments-sdk": {"name": "@three-ws/agent-payments","version": "3.2.0",- "license": "ISC",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@bonfida/spl-name-service": "0.1.67","@coral-xyz/anchor": "^0.31.1",@@ -416,7 +416,7 @@"agent-ui-sdk": {"name": "@three-ws/agent-ui","version": "0.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","engines": {"node": ">=18"},@@ -427,7 +427,7 @@"avatar-sdk": {"name": "@three-ws/avatar","version": "0.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","engines": {"node": ">=18"},@@ -1145,7 +1145,7 @@"mcp-bridge": {"name": "@three-ws/mcp-bridge","version": "1.0.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@solana/kit": "^6.9.0",@@ -1214,7 +1214,7 @@"mcp-server": {"name": "@three-ws/mcp-server","version": "1.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@bonfida/spl-name-service": "0.1.67","@coinbase/x402": "^2.1.0",@@ -52082,7 +52082,7 @@"packages/activity-mcp": {"name": "@three-ws/activity-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52097,7 +52097,7 @@"packages/agenc-mcp": {"name": "@three-ws/agenc-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52112,7 +52112,7 @@"packages/agent-sniper": {"name": "@three-ws/agent-sniper","version": "0.1.2",- "license": "MIT",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@nirholas/pump-sdk": "^1.30.0",@@ -52189,7 +52189,7 @@"packages/agentcore-payments-mcp": {"name": "@three-ws/agentcore-payments-mcp","version": "0.1.2",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52204,7 +52204,7 @@"packages/agora-mcp": {"name": "@three-ws/agora-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@solana/web3.js": "^1.98.0",@@ -52222,7 +52222,7 @@"packages/alerts-mcp": {"name": "@three-ws/alerts-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52237,7 +52237,7 @@"packages/alibaba-cloud-mcp": {"name": "@three-ws/alibaba-cloud-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0"},@@ -52251,7 +52251,7 @@"packages/audio-mcp": {"name": "@three-ws/audio-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52266,7 +52266,7 @@"packages/autopilot-mcp": {"name": "@three-ws/autopilot-mcp","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52281,7 +52281,7 @@"packages/avatar-agent-mcp": {"name": "@three-ws/avatar-agent","version": "1.2.2",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@gltf-transform/core": "^4.3.0","@gltf-transform/extensions": "^4.3.0",@@ -52310,7 +52310,7 @@"packages/avatar-cli": {"name": "@three-ws/avatar-cli","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@three-ws/avatar-schema": "^0.2.0"},@@ -52324,7 +52324,7 @@"packages/avatar-schema": {"name": "@three-ws/avatar-schema","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"ajv": "^8.20.0","ajv-formats": "^3.0.1"@@ -52336,7 +52336,7 @@"packages/billing-mcp": {"name": "@three-ws/billing-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52351,7 +52351,7 @@"packages/brain-mcp": {"name": "@three-ws/brain-mcp","version": "0.1.2",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52366,7 +52366,7 @@"packages/clash-mcp": {"name": "@three-ws/clash-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","bs58": "^6.0.0",@@ -52383,7 +52383,7 @@"packages/copy-mcp": {"name": "@three-ws/copy-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52398,7 +52398,7 @@"packages/defi-utils": {"name": "@three-ws/defi-utils","version": "0.1.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"bs58": "^6.0.0"},@@ -52409,7 +52409,7 @@"packages/ibm-watsonx-mcp": {"name": "@three-ws/ibm-watsonx-mcp","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0"},@@ -52423,7 +52423,7 @@"packages/ibm-x402-mcp": {"name": "@three-ws/ibm-x402-mcp","version": "1.1.2",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@x402/core": "^2.13.0",@@ -52443,7 +52443,7 @@"packages/intel-mcp": {"name": "@three-ws/intel-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52458,7 +52458,7 @@"packages/kol-mcp": {"name": "@three-ws/kol-mcp","version": "0.1.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52473,7 +52473,7 @@"packages/loom-mcp": {"name": "@three-ws/loom-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52488,7 +52488,7 @@"packages/marketplace-mcp": {"name": "@three-ws/marketplace-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52503,7 +52503,7 @@"packages/naming-mcp": {"name": "@three-ws/naming-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@three-ws/tool-sdk": "file:../tool-sdk",@@ -52519,7 +52519,7 @@"packages/notifications-mcp": {"name": "@three-ws/notifications-mcp","version": "0.1.2",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52534,7 +52534,7 @@"packages/portfolio-mcp": {"name": "@three-ws/portfolio-mcp","version": "0.1.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@solana/spl-token": "^0.4.14",@@ -52552,7 +52552,7 @@"packages/provenance-mcp": {"name": "@three-ws/provenance-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","ethers": "^6.16.0",@@ -52568,7 +52568,7 @@"packages/pumpfun-mcp": {"name": "@three-ws/pumpfun-mcp","version": "0.2.3",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0"},@@ -52582,7 +52582,7 @@"packages/scene-mcp": {"name": "@three-ws/scene-mcp","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52597,7 +52597,7 @@"packages/signals-mcp": {"name": "@three-ws/signals-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52612,7 +52612,7 @@"packages/three-token-mcp": {"name": "@three-ws/three-token-mcp","version": "1.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@solana/spl-token": "^0.4.14",@@ -52630,7 +52630,7 @@"packages/threews-avatar-mcp": {"name": "@three-ws/avatar-mcp","version": "0.3.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0"},@@ -52648,7 +52648,7 @@"packages/tool-sdk": {"name": "@three-ws/tool-sdk","version": "0.1.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"zod": "^3.23.8","zod-to-json-schema": "^3.25.2"@@ -52660,7 +52660,7 @@"packages/tutor-mcp": {"name": "@three-ws/tutor-mcp","version": "0.1.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52675,7 +52675,7 @@"packages/vanity-mcp": {"name": "@three-ws/vanity-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52690,7 +52690,7 @@"packages/viewer-presets": {"name": "@three-ws/viewer-presets","version": "0.3.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","engines": {"node": ">=18"},@@ -52706,7 +52706,7 @@"packages/vision-mcp": {"name": "@three-ws/vision-mcp","version": "0.1.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","zod": "^3.23.8"@@ -52721,7 +52721,7 @@"packages/x402-mcp": {"name": "@three-ws/x402-mcp","version": "0.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@modelcontextprotocol/sdk": "^1.29.0","@solana/kit": "^6.9.0",@@ -52743,7 +52743,7 @@"page-agent-sdk": {"name": "@three-ws/page-agent","version": "0.2.0",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","engines": {"node": ">=18"},@@ -52769,7 +52769,7 @@"solana-agent-sdk": {"name": "@three-ws/solana-agent","version": "0.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"@coral-xyz/anchor": "^0.32.1","@noble/ciphers": "^1.3.0",@@ -52823,7 +52823,7 @@"tour-sdk": {"name": "@three-ws/tour","version": "0.5.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","bin": {"tour-build-curriculum": "bin/tour-build-curriculum.mjs"},@@ -53325,7 +53325,7 @@"walk-sdk": {"name": "@three-ws/walk","version": "0.2.1",- "license": "Apache-2.0",+ "license": "SEE LICENSE IN LICENSE","engines": {"node": ">=18"},diff --git a/scripts/api-sweep.mjs b/scripts/api-sweep.mjsnew file mode 100644index 000000000..8f7413e7b--- /dev/null+++ b/scripts/api-sweep.mjs@@ -0,0 +1,187 @@+#!/usr/bin/env node+/**+ * api-sweep.mjs - live liveness sweep of the entire API surface.+ *+ * The browser page audit only exercises the API endpoints that pages happen to+ * call on load. This script closes the rest of the gap: it enumerates every+ * handler file under api/ (the deployed route surface), issues a single+ * read-only GET against the live target, and classifies the result:+ *+ * error - HTTP 5xx, or unreachable after a retry (the endpoint is broken)+ * warn - HTTP 404 for a handler that exists on disk (route-table drift:+ * the code shipped but no route serves it)+ * ok - anything else. 401/403 (auth required), 402 (x402 payment+ * required), 405 (POST-only), 400 (missing params) all prove the+ * handler is alive and answering.+ *+ * Safety: strictly GET, and side-effectful-on-GET surfaces are excluded+ * (cron endpoints run real jobs when hit; webhooks/oauth callbacks are not+ * ours to poke). Dynamic [param] handlers are skipped and counted, never+ * guessed. Every exclusion is listed in the report - no silent gaps.+ *+ * Usage:+ * node scripts/api-sweep.mjs # against https://three.ws+ * BASE_URL=http://localhost:3000 node scripts/api-sweep.mjs+ * node scripts/api-sweep.mjs --concurrency 24+ * node scripts/api-sweep.mjs --strict # exit 1 on any error+ */+import { readdirSync, statSync, writeFileSync, mkdirSync } from 'node:fs';+import { resolve, dirname, relative } from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const BASE_URL = (process.env.BASE_URL || 'https://three.ws').replace(/\/$/, '');+const argv = process.argv.slice(2);+const flag = (n) => argv.includes(`--${n}`);+const opt = (n, fb) => {+ const i = argv.indexOf(`--${n}`);+ return i !== -1 && argv[i + 1] ? argv[i + 1] : fb;+};+const STRICT = flag('strict');+const CONCURRENCY = Math.max(1, Number(opt('concurrency', 16)) || 16);+const TIMEOUT_MS = 20000;++// GET on these does real work or belongs to a third party. Never probed.+const SIDE_EFFECT = [+ /^\/api\/cron\//,+ /webhook/i,+ /callback/i,+ /oauth/i,+ /logout/i,+ /unsubscribe/i,+ /\/telegram\//i,+];++function enumerateRoutes() {+ const routes = [];+ const dynamic = [];+ const walk = (dir) => {+ for (const e of readdirSync(dir)) {+ const full = resolve(dir, e);+ const st = statSync(full);+ if (st.isDirectory()) {+ // _lib / _providers / _mcp helpers are imports, not routes.+ if (e.startsWith('_') || e === 'node_modules') continue;+ walk(full);+ continue;+ }+ if (!/\.(js|mjs)$/.test(e)) continue;+ // Underscore-prefixed files are shared helpers, not routes.+ if (e.startsWith('_')) continue;+ const rel = '/' + relative(ROOT, full).replace(/\.(js|mjs)$/, '');+ const route = rel.replace(/\/index$/, '') || '/api';+ if (/\[.+\]/.test(route)) {+ dynamic.push(route);+ continue;+ }+ routes.push(route);+ }+ };+ walk(resolve(ROOT, 'api'));+ const excluded = routes.filter((r) => SIDE_EFFECT.some((re) => re.test(r)));+ const probed = routes.filter((r) => !SIDE_EFFECT.some((re) => re.test(r)));+ return { probed: [...new Set(probed)].sort(), excluded, dynamic };+}++async function probe(route, attempt = 1) {+ const ctrl = new AbortController();+ const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);+ try {+ const res = await fetch(`${BASE_URL}${route}`, {+ method: 'GET',+ redirect: 'manual',+ signal: ctrl.signal,+ headers: { 'user-agent': 'three.ws-api-sweep/1.0 (internal audit)' },+ });+ clearTimeout(timer);+ const status = res.status;+ const body = await res.text().catch(() => '');+ if (status >= 500) {+ return { route, status, verdict: 'error', note: `HTTP ${status} ${body.slice(0, 160)}` };+ }+ if (status === 404) {+ // Only two 404 shapes mean the handler is unreachable: the server's+ // route fall-through, and a dispatcher missing the action entry. A+ // handler answering 404 for a missing param/resource is alive.+ if (/No API route matches|unknown action/i.test(body)) {+ return { route, status, verdict: 'warn', note: `unreachable handler: ${body.slice(0, 120)}` };+ }+ }+ return { route, status, verdict: 'ok' };+ } catch (e) {+ clearTimeout(timer);+ if (attempt < 2) return probe(route, attempt + 1);+ return { route, status: null, verdict: 'error', note: `unreachable: ${e.name || e.message}` };+ }+}++async function main() {+ const { probed, excluded, dynamic } = enumerateRoutes();+ console.log(`API sweep -> ${BASE_URL}`);+ console.log(` probing ${probed.length} GET route(s) · concurrency ${CONCURRENCY}`);+ console.log(` excluded ${excluded.length} side-effect route(s), skipped ${dynamic.length} dynamic [param] route(s)\n`);++ const queue = [...probed];+ const results = [];+ let done = 0;+ const worker = async () => {+ while (queue.length) {+ const r = await probe(queue.shift());+ results.push(r);+ done++;+ if (r.verdict !== 'ok') {+ console.log(` ${r.verdict === 'error' ? '🔴' : '🟡'} ${r.route} ${r.note || ''}`);+ } else if (done % 200 === 0) {+ console.log(` ... ${done}/${probed.length}`);+ }+ }+ };+ await Promise.all(Array.from({ length: CONCURRENCY }, worker));++ const errors = results.filter((r) => r.verdict === 'error').sort((a, b) => a.route.localeCompare(b.route));+ const warns = results.filter((r) => r.verdict === 'warn').sort((a, b) => a.route.localeCompare(b.route));+ const statusCounts = {};+ for (const r of results) statusCounts[r.status ?? 'net-fail'] = (statusCounts[r.status ?? 'net-fail'] || 0) + 1;++ mkdirSync(resolve(ROOT, 'reports'), { recursive: true });+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');+ const jsonPath = resolve(ROOT, `reports/api-sweep-${stamp}.json`);+ const mdPath = resolve(ROOT, `reports/api-sweep-${stamp}.md`);+ writeFileSync(+ jsonPath,+ JSON.stringify({ baseUrl: BASE_URL, generatedAt: stamp, statusCounts, errors, warns, excluded, dynamic, total: results.length }, null, 2),+ );+ const lines = [+ `# API sweep - ${BASE_URL}`,+ '',+ `- Probed: ${results.length} routes · Errors: ${errors.length} · Route-drift 404s: ${warns.length}`,+ `- Status distribution: ${Object.entries(statusCounts).sort().map(([s, n]) => `${s}: ${n}`).join(' · ')}`,+ `- Excluded (side-effect on GET): ${excluded.length} · Skipped dynamic [param]: ${dynamic.length}`,+ '',+ ];+ if (errors.length) {+ lines.push('## Broken (5xx / unreachable)', '');+ for (const r of errors) lines.push(`- 🔴 \`${r.route}\` ${r.note}`);+ lines.push('');+ }+ if (warns.length) {+ lines.push('## Handler exists on disk but the route 404s (route-table drift)', '');+ for (const r of warns) lines.push(`- 🟡 \`${r.route}\``);+ lines.push('');+ }+ if (excluded.length) {+ lines.push('## Excluded from probing (GET has side effects)', '');+ for (const r of excluded) lines.push(`- \`${r}\``);+ lines.push('');+ }+ writeFileSync(mdPath, lines.join('\n'));++ console.log(`\n ${errors.length} error · ${warns.length} route-drift 404 · ${results.length - errors.length - warns.length} ok`);+ console.log(` Report: ${mdPath.replace(ROOT + '/', '')}`);+ if (STRICT && errors.length) process.exit(1);+}++main().catch((e) => {+ console.error(e);+ process.exit(1);+});diff --git a/scripts/page-audit.mjs b/scripts/page-audit.mjsindex cf4ed207f..dd91f6162 100644--- a/scripts/page-audit.mjs+++ b/scripts/page-audit.mjs@@ -299,7 +299,63 @@ function inPageAudit() {});}- return { title: document.title, hasHorizontalScroll: docW > vw + 2, findings };+ // Blank-render detection: the page "loaded" but nothing meaningful painted.+ // A 3D canvas, iframe, or video counts as content; otherwise we require some+ // visible text or a reasonable number of visible elements.+ const visibleText = (document.body?.innerText || '').replace(/\s+/g, ' ').trim();+ const hasMedia = !!document.querySelector('canvas, iframe, video');+ let visibleEls = 0;+ for (const el of document.querySelectorAll('body *')) {+ const r = el.getBoundingClientRect();+ if (r.width > 4 && r.height > 4) visibleEls++;+ if (visibleEls > 12) break;+ }+ if (!hasMedia && visibleText.length < 40 && visibleEls <= 12) {+ findings.push({+ type: 'blank-page',+ severity: 'error',+ detail: `page rendered ~nothing: ${visibleText.length} chars of visible text, ${visibleEls} visible elements, no canvas/iframe/video`,+ });+ }++ // Visible failure text: error banners and raw exception text a user would see.+ const ERROR_TEXT =+ /something went wrong|an error occurred|unexpected error|failed to (load|fetch|initialize)|cannot read propert|is not a function|is not defined|internal server error|\bTypeError\b|\bReferenceError\b/i;+ const seenBanners = new Set();+ for (const el of document.querySelectorAll('body *')) {+ if (el.children.length > 3) continue;+ // Docs and articles legitimately print error strings in code samples.+ if (el.closest('pre, code, script, style, table, article')) continue;+ const t = (el.innerText || '').trim();+ if (!t || t.length > 400 || !ERROR_TEXT.test(t)) continue;+ const r = el.getBoundingClientRect();+ if (r.width === 0 || r.height === 0) continue;+ const st = getComputedStyle(el);+ if (st.display === 'none' || st.visibility === 'hidden') continue;+ const key = t.slice(0, 120);+ if (seenBanners.has(key)) continue;+ seenBanners.add(key);+ findings.push({ type: 'error-banner', severity: 'error', detail: `visible error text: "${key}"` });+ if (seenBanners.size >= 5) break;+ }++ // Same-origin links, for crawl discovery of routes missing from the manifest.+ const links = new Set();+ for (const a of document.querySelectorAll('a[href]')) {+ try {+ const u = new URL(a.getAttribute('href'), location.href);+ if (u.origin !== location.origin) continue;+ const p = u.pathname.replace(/\/$/, '') || '/';+ links.add(p);+ } catch {}+ }++ return {+ title: document.title,+ hasHorizontalScroll: docW > vw + 2,+ findings,+ links: [...links].slice(0, 400),+ };}// ── Per-route audit ───────────────────────────────────────────────────────────@@ -362,20 +418,76 @@ async function auditRoute(ctx, route, viewport) {}let title = '';+ let links = [];try {const r = await page.evaluate(inPageAudit);title = r.title;+ links = r.links || [];for (const f of r.findings) {// Tap-target noise is only meaningful on the mobile pass.if (f.type === 'tap-target' && viewport !== 'mobile') continue;- push(f.type, f.severity, f.detail);+ // Content-heavy prose surfaces mention error strings legitimately;+ // keep the signal but do not fail the page on it.+ const sev =+ f.type === 'error-banner' && /^\/(docs|blog|news|changelog|specs)(\/|$)/.test(route)+ ? 'info'+ : f.severity;+ push(f.type, sev, f.detail);}} catch {/* page torn down mid-eval */}+ // A screenshot for every page with an error-severity finding, so the report+ // shows what a user would have seen.+ let screenshot = null;+ if (findings.some((f) => f.severity === 'error')) {+ try {+ const dir = resolve(ROOT, 'reports/screens');+ mkdirSync(dir, { recursive: true });+ const safe = route.replace(/[^a-z0-9]+/gi, '_').replace(/^_|_$/g, '') || 'root';+ screenshot = `reports/screens/${safe}-${viewport}.png`;+ await page.screenshot({ path: resolve(ROOT, screenshot), fullPage: false });+ } catch {+ screenshot = null;+ }+ }+await page.close();- return { route, viewport, title, navStatus, findings };+ return { route, viewport, title, navStatus, findings, links, screenshot };+}++// ── Crawl discovery ───────────────────────────────────────────────────────────+// Links collected on audited pages that point at same-origin HTML routes we+// were NOT going to visit. These are exactly the pages past audits missed:+// reachable by users, absent from the manifest. Deep dynamic families+// (/u/<id>, /coin/<mint>, ...) are sampled, never exhaustively crawled, and+// anything sampled out is reported rather than silently dropped.+function pickDiscovered(links, known) {+ const candidates = [];+ for (const p of links) {+ if (!p.startsWith('/') || known.has(p)) continue;+ if (!isHtmlRoute(p)) continue;+ if (/^\/(api|assets|cdn|static|models|textures|_)/.test(p)) continue;+ candidates.push(p);+ }+ candidates.sort();+ const perFamily = new Map();+ const audit = [];+ const dropped = [];+ for (const p of candidates) {+ const fam = p.split('/').slice(0, 2).join('/');+ const depth = p.split('/').filter(Boolean).length;+ const cap = depth >= 2 ? 3 : Infinity;+ const n = perFamily.get(fam) || 0;+ if (n >= cap || audit.length >= 150) {+ dropped.push(p);+ continue;+ }+ perFamily.set(fam, n + 1);+ audit.push(p);+ }+ return { audit, dropped };}// ── Worker pool ───────────────────────────────────────────────────────────────@@ -425,6 +537,7 @@ function writeReport(allResults, meta) {if (!byRoute.has(r.route)) byRoute.set(r.route, { route: r.route, viewports: {}, findings: [] });const entry = byRoute.get(r.route);entry.viewports[r.viewport] = { title: r.title, navStatus: r.navStatus };+ if (r.screenshot) entry.screenshot = entry.screenshot || r.screenshot;for (const f of r.findings) entry.findings.push({ ...f, viewport: r.viewport });}@@ -462,6 +575,21 @@ function writeReport(allResults, meta) {`- **Totals: ${totals.error} error · ${totals.warn} warn · ${totals.info} info**`,);lines.push('');+ if (meta.discovered?.length) {+ lines.push('## Crawl-discovered routes (linked on the site, missing from data/pages.json)');+ lines.push('');+ lines.push('These were audited this run, but add them to the manifest so every future');+ lines.push('audit, the sitemap, and llms.txt see them:');+ lines.push('');+ for (const d of meta.discovered) lines.push(`- \`${d}\``);+ lines.push('');+ }+ if (meta.droppedDiscoveries?.length) {+ lines.push(+ `*Crawl sampled out ${meta.droppedDiscoveries.length} additional dynamic route(s) (families capped at 3): ${meta.droppedDiscoveries.slice(0, 15).map((d) => `\`${d}\``).join(', ')}${meta.droppedDiscoveries.length > 15 ? ', ...' : ''}*`,+ );+ lines.push('');+ }lines.push('## Pages by severity');lines.push('');lines.push('| Route | err | warn | info |');@@ -485,6 +613,7 @@ function writeReport(allResults, meta) {.map(([v, d]) => `${v}: HTTP ${d.navStatus ?? '?'}`).join(' · ');lines.push(`*${navs}*`);+ if (p.screenshot) lines.push(`*screenshot: ${p.screenshot}*`);lines.push('');for (const f of p.findings) {const icon = f.severity === 'error' ? '🔴' : f.severity === 'warn' ? '🟡' : '⚪';@@ -526,6 +655,10 @@ async function main() {console.log(` routes: ${routes.length}\n`);const allResults = [];+ const knownRoutes = new Set(routes);+ const discovered = [];+ let droppedDiscoveries = [];+ let firstViewport = true;for (const viewport of viewports) {const ctxOpts = {...(viewport === 'mobile' ? devices['iPhone 13'] : { viewport: { width: 1440, height: 900 } }),@@ -535,13 +668,38 @@ async function main() {};const ctx = await browser.newContext(ctxOpts);console.log(`── ${viewport} ──`);- await runPool(ctx, routes, viewport, (r) => {+ const onResult = (r) => {const e = r.findings.filter((f) => f.severity === 'error').length;const w = r.findings.filter((f) => f.severity === 'warn').length;const tag = e ? '🔴' : w ? '🟡' : '✓ ';process.stdout.write(` ${tag} ${r.route} (${e}e/${w}w)\n`);allResults.push(r);- });+ };+ await runPool(ctx, routes, viewport, onResult);+ // After the first pass, audit every crawl-discovered route the manifest+ // missed. They join `routes` so later viewports cover them too.+ if (firstViewport && !explicitRoutes.length) {+ const linkSet = new Set(allResults.flatMap((r) => r.links || []));+ const picked = pickDiscovered(linkSet, knownRoutes);+ droppedDiscoveries = picked.dropped;+ if (picked.audit.length) {+ console.log(+ ` ── crawl: ${picked.audit.length} linked route(s) missing from the manifest, auditing them too ──`,+ );+ for (const d of picked.audit) {+ routes.push(d);+ knownRoutes.add(d);+ discovered.push(d);+ }+ await runPool(ctx, picked.audit, viewport, onResult);+ }+ if (picked.dropped.length) {+ console.log(+ ` ── crawl: ${picked.dropped.length} more discovered route(s) sampled out (dynamic families capped at 3) ──`,+ );+ }+ firstViewport = false;+ }await ctx.close();}await browser.close();@@ -550,6 +708,8 @@ async function main() {baseUrl: BASE_URL,authed,viewports,+ discovered,+ droppedDiscoveries,});console.log('\n── Summary ──');