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
docs(structure): record the shared utilities and server surfaces added this cycle
nirholas345c57e854a7
diff --git a/STRUCTURE.md b/STRUCTURE.mdindex 8d986f875..35ac923f1 100644--- a/STRUCTURE.md+++ b/STRUCTURE.md@@ -214,7 +214,7 @@ bottom.| Clip Director (content engine) | [pages/clip-director.html](pages/clip-director.html) + [src/clip-director-page.js](src/clip-director-page.js) `→ /clip-director`, brain [api/_lib/clip-director.js](api/_lib/clip-director.js), endpoint [api/clip-director.js](api/clip-director.js) | Live | Turns one real closed trade (`agent_sniper_positions`) into the optimal shareable card per surface (X / Telegram / Feed): honest hook, the real number, an avatar gesture mapped to a real animation clip, CTA, and alt text, plus an on-chain proof link. Losses get an honest card too. Free-first `llmComplete` with a deterministic same-shape fallback. Doc: [docs/clip-director.md](docs/clip-director.md). || Atlas (site-wide Cmd+K search + route map) | Palette [public/atlas.js](public/atlas.js) `-> /atlas.js`, ranking [public/atlas/score.js](public/atlas/score.js), map page [pages/atlas.html](pages/atlas.html) + [src/atlas-page.js](src/atlas-page.js) `-> /atlas`, index [scripts/build-atlas-index.mjs](scripts/build-atlas-index.mjs) `-> public/atlas-index.json`, task catalog [data/atlas-intents.json](data/atlas-intents.json), coverage [scripts/inject-atlas.mjs](scripts/inject-atlas.mjs) | Live | **Discovery layer for 650+ routes.** Cmd+K (or `/`) opens a search over every page in `data/pages.json` plus a curated set of TASKS that answer with ordered steps rather than one link, because "which page starts the get-paid flow" is a harder question than "where is /x402-revenue". Zero-dependency single file so it runs identically on 250+ standalone HTML entry points; the index is fetched on first open, not page load. Every task step target is resolved against the real route table at build time, so an onboarding path cannot dead-end on a 404. Injected by a Vite `three-ws-atlas` plugin plus a post-build `dist/` walk (same belt-and-suspenders as [scripts/inject-tour-boot.mjs](scripts/inject-tour-boot.mjs), for the same plugin-ordering reason). Embeds and the nav/footer fragments are excluded. Doc: [docs/atlas.md](docs/atlas.md). Tests: [tests/atlas.test.js](tests/atlas.test.js). || Internationalization (i18n) | Runtime [src/i18n.js](src/i18n.js) `→ /i18n.js`; catalogs [public/locales/](public/locales) (`en` + 84 locales, `manifest.json`, `localized-pages.json`); pipeline [scripts/i18n-annotate.mjs](scripts/i18n-annotate.mjs) · [i18n-extract.mjs](scripts/i18n-extract.mjs) · [i18n-translate.mjs](scripts/i18n-translate.mjs) (Vertex Gemini, glossary-locked) · [i18n-backfill.mjs](scripts/i18n-backfill.mjs) (re-translates copy that was baked to English during a backend outage); hreflang in [api/sitemap/[type].js](api/sitemap/%5Btype%5D.js) | Live (85 languages) | LobeHub-model client-side copy swap. `npm run i18n:annotate` auto-injects `data-i18n*` into static HTML (byte-surgical), `i18n:extract` builds `en.json`, `i18n:translate` fans it out to every locale via Vertex with brand/protocol terms masked. `i18n:backfill` finds keys whose value is still byte-identical to English (the silent failure mode: a baked fallback is present, so every later run skips it) and re-translates them. Runtime auto-detects locale, mounts a floating `<lang-switcher>`, and injects hreflang. Doc: [docs/i18n.md](docs/i18n.md). Tests: [tests/i18n.test.js](tests/i18n.test.js), [tests/i18n-annotate.test.js](tests/i18n-annotate.test.js), [tests/i18n-backfill.test.js](tests/i18n-backfill.test.js). |-| Shared utilities (import instead of hand-rolling) | Frontend [src/shared/markdown.js](src/shared/markdown.js) · [src/shared/toast.js](src/shared/toast.js) · [src/shared/fuzzy.js](src/shared/fuzzy.js) · `timeAgo`/`toEpochMs` in [src/shared/coin-format.js](src/shared/coin-format.js); backend [api/_lib/resilience.js](api/_lib/resilience.js) · [api/_lib/mem-cache.js](api/_lib/mem-cache.js) · [api/_lib/pool.js](api/_lib/pool.js) · [api/_lib/csv.js](api/_lib/csv.js); ops [scripts/check-cron-drift.mjs](scripts/check-cron-drift.mjs) | Live · doc [docs/shared-utilities.md](docs/shared-utilities.md) | Thin layers over vetted packages, each replacing a family of hand-rolled copies that had drifted. `markdown.js` = `marked` + `DOMPurify`, the single sanitized path for model/user text reaching `innerHTML` (the concierge SDK carries its own copy at [concierge-sdk/src/markdown.js](concierge-sdk/src/markdown.js) because it ships as an independent bundle). `toast.js` = one aria-live region with a real queue. `fuzzy.js` = `@leeoniya/ufuzzy` ranking + typo tolerance + match ranges for both command palettes. `resilience.js` = `cockatiel` circuit breakers **and** jittered retry (`withRetry`, `parseRetryAfter`, `isRetryableError`). `mem-cache.js` = `lru-cache` with true recency eviction and single-flight `cached()`. `pool.js` = `p-limit` bounded concurrency. `csv.js` = RFC 4180 quoting **plus** spreadsheet formula-injection neutralization. `check-cron-drift.mjs` = `cron-parser` validation of vercel.json's 101 crons against live Cloud Scheduler. Tests: [tests/shared-markdown.test.js](tests/shared-markdown.test.js), [tests/fuzzy.test.js](tests/fuzzy.test.js), [tests/csv.test.js](tests/csv.test.js), [tests/resilience-shared.test.js](tests/resilience-shared.test.js) |+| Shared utilities (import instead of hand-rolling) | Frontend [src/shared/markdown.js](src/shared/markdown.js) · [src/shared/toast.js](src/shared/toast.js) · [src/shared/fuzzy.js](src/shared/fuzzy.js) · `timeAgo`/`toEpochMs` in [src/shared/coin-format.js](src/shared/coin-format.js); backend [api/_lib/resilience.js](api/_lib/resilience.js) · [api/_lib/mem-cache.js](api/_lib/mem-cache.js) · [api/_lib/pool.js](api/_lib/pool.js) · [api/_lib/csv.js](api/_lib/csv.js); ops [scripts/check-cron-drift.mjs](scripts/check-cron-drift.mjs) | Live · doc [docs/shared-utilities.md](docs/shared-utilities.md) | Thin layers over vetted packages, each replacing a family of hand-rolled copies that had drifted. `markdown.js` = `marked` + `DOMPurify`, the single sanitized path for model/user text reaching `innerHTML` (the concierge SDK carries its own copy at [concierge-sdk/src/markdown.js](concierge-sdk/src/markdown.js) because it ships as an independent bundle). `toast.js` = one aria-live region with a real queue. `fuzzy.js` = `@leeoniya/ufuzzy` ranking + typo tolerance + match ranges for both command palettes. `resilience.js` = `cockatiel` circuit breakers **and** jittered retry (`withRetry`, `parseRetryAfter`, `isRetryableError`). `mem-cache.js` = `lru-cache` with true recency eviction and single-flight `cached()`. `pool.js` = `p-limit` bounded concurrency. `csv.js` = RFC 4180 quoting **plus** spreadsheet formula-injection neutralization. `check-cron-drift.mjs` = `cron-parser` validation of every cron declared in vercel.json against live Cloud Scheduler, sharing its job-id derivation with [scripts/create-gcp-scheduler.mjs](scripts/create-gcp-scheduler.mjs) so the two can never disagree. Tests: [tests/shared-markdown.test.js](tests/shared-markdown.test.js), [tests/fuzzy.test.js](tests/fuzzy.test.js), [tests/csv.test.js](tests/csv.test.js), [tests/resilience-shared.test.js](tests/resilience-shared.test.js) || X post archive + engagement analysis (internal) | Snapshots [data/x-archive/](data/x-archive), schema [api/_lib/migrations/20260814120000_x_account_archive.sql](api/_lib/migrations/20260814120000_x_account_archive.sql), normalization + analysis [scripts/x-archive-lib.mjs](scripts/x-archive-lib.mjs), commands [scripts/x-archive-import.mjs](scripts/x-archive-import.mjs) · [scripts/x-archive-refresh.mjs](scripts/x-archive-refresh.mjs) · [scripts/x-archive-analyze.mjs](scripts/x-archive-analyze.mjs), report [docs/x-archive/](docs/x-archive) | Internal · doc [docs/x-archive.md](docs/x-archive.md) | Every post our own X accounts published, kept as raw snapshot files and indexed into `x_account_posts` / `x_account_post_snapshots` so engagement is a measured time series rather than a memory. `npm run x:archive:analyze` regenerates a report ranking posts by engagement and by engagement *rate*, and scores every measurable signal (media, mentions, length, subject, hour) as lift against the corpus median. Two scraper defects are handled rather than inherited: a profile scrape returns reposts of other accounts with `isRetweet: false` (authorship is read from the permalink instead), and X renders like counts lazily so real posts arrive at "0 likes" (those are archived, named, and excluded from the medians until `npm run x:archive:refresh` replaces them with exact X API counters). Distinct from `x_posts`, which is what platform users publish through [api/x/post.js](api/x/post.js). Tests: [tests/x-archive.test.js](tests/x-archive.test.js) || Interactive 3D history timeline | [pages/timeline.html](pages/timeline.html) `→ /timeline`, [src/timeline.js](src/timeline.js), data [data/timeline.json](data/timeline.json) | Live | three.ws's public history (launches, partnerships, listings, press, product ships) as an explorable 3D scene: 60+ milestones as glowing markers along a curved path, 360° free-orbit or a marker-to-marker Walk mode with a guide beacon (reuses the shared `AnimationManager` + default rig from [src/walk.js](src/walk.js)'s pattern), a synced bottom scrubber, category filters, and a detail panel linking to the original source where one exists (IBM Community, NVIDIA Developer Forums, Yahoo Finance, Phemex, CoinGecko, HackerNoon). Real accessible HTML-list fallback for no-WebGL or fetch-failure. |diff --git a/public/oracle-coin.js b/public/oracle-coin.jsindex bc27a3a98..95d15c7bf 100644--- a/public/oracle-coin.js+++ b/public/oracle-coin.js@@ -123,7 +123,67 @@const rs = (d.reasons || []).map((r) => r.text).filter(Boolean);if (!rs.length) return '';const body = rs.slice(0, 2).map((t) => t.replace(/\.$/, '')).join('; ');- return `<div class="coin-take"><span class="ct-q">“</span><span><b>${esc(lead)} at ${c.score}</b> — ${esc(body)}.</span></div>`;+ // A resolved coin gets its result first. Pitching a launch in the present+ // tense ("a prime setup at 100") next to a chart that already died is what+ // made a correct call read as a broken one: the call was about the first 90+ // seconds, the chart is about everything since, and only one of them was on+ // the page. The reasons still follow, because why the engine said it stays+ // the interesting part once you know how it ended.+ const past = outcomeSentence(d.outcome);+ return `<div class="coin-take"><span class="ct-q">“</span><span>${past+ ? `<b>${esc(past)}</b> Oracle called it ${esc(String(lead).toLowerCase())} at ${c.score} from ${esc(body)}.`+ : `<b>${esc(lead)} at ${c.score}</b> from ${esc(body)}.`}</span></div>`;+ }++ // One plain sentence for what the market did after the call. Mirrors+ // outcomeStripHtml() in api/oracle-share.js (buildless file, no imports).+ function outcomeSentence(out) {+ if (!out) return '';+ const ath = out.ath_multiple != null ? Number(out.ath_multiple) : null;+ const peak = ath > 0 ? `peaked at ${ath.toFixed(1)}x` : null;+ if (out.graduated) return peak ? `It graduated, ${peak}.` : 'It graduated.';+ if (out.rugged) return peak ? `It ran to ${ath.toFixed(1)}x and then rugged.` : 'It rugged.';+ if (peak) return `It has ${peak} so far.`;+ return '';+ }++ // The dial's two honesty lines, mirroring verdictOddsHtml()/outcomeStripHtml()+ // in api/oracle-share.js. The server renders both for any coin it already had a+ // verdict for; these fill them in for a lazy-scored launch and refresh them+ // once the live read lands.+ function oddsHtml(c) {+ if (!c || c.hit_rate == null || !c.hit_rate_n) return '';+ const rate = Math.round(Number(c.hit_rate) * 100);+ const base = Math.round(Number(c.base_rate || 0) * 100);+ const lift = c.hit_rate_lift != null ? Number(c.hit_rate_lift).toFixed(1) : null;+ const lead = leadTime(c.scored_at, c.coin_first_seen_at);+ return `<p class="oc-odds">+ <b>${rate}%</b> of calls in the ${esc(c.hit_rate_band || '')} band have won<span class="oc-odds-n"> (n=${Number(c.hit_rate_n).toLocaleString('en-US')})</span>${lift ? `, <b>${esc(lift)}x</b> the ${base}% a random launch wins` : ''}.+ <span class="oc-odds-sub">Scored ${lead ? `${lead} after this coin surfaced` : 'at launch'}, from the first ~90s of trading. It ranks the odds of a 3x run or graduation, not the odds of a safe hold.</span>+ </p>`;+ }++ function leadTime(scoredAt, firstSeen) {+ if (!scoredAt || !firstSeen) return null;+ const secs = Math.round((new Date(scoredAt).getTime() - new Date(firstSeen).getTime()) / 1000);+ if (!Number.isFinite(secs) || secs < 0) return null;+ return secs < 90 ? `${secs}s` : `${Math.round(secs / 60)}m`;+ }++ function sinceHtml(out) {+ if (!out) return '';+ const ath = out.ath_multiple != null ? Number(out.ath_multiple) : null;+ const mc = out.last_market_cap_usd != null ? Number(out.last_market_cap_usd) : null;+ if (!out.graduated && !out.rugged && !(ath > 0)) return '';+ const verdict = out.graduated+ ? '<span class="chip sm">graduated ✓</span>'+ : out.rugged ? '<span class="chip flag">rugged ✕</span>' : '<span class="chip">still live</span>';+ return `<div class="oc-since ${out.rugged && !out.graduated ? 'bad' : out.graduated ? 'good' : ''}">+ <span class="oc-since-lbl">Since the call</span>+ ${ath > 0 ? `<span class="chip" title="Peak market cap versus its market cap when Oracle scored it">peak <b>${ath.toFixed(1)}x</b></span>` : ''}+ ${verdict}+ ${mc != null ? `<span class="chip" title="Market cap now">now <b>${fmtUsd(mc)}</b></span>` : ''}+ </div>`;}function structurePanel(st) {@@ -940,12 +1000,16 @@// Patch the server-rendered hero dial + pillars once a live verdict arrives.// For a fresh launch the SSR hero shows a "reading" state; this fills it in the// moment /api/oracle/coin returns a score, so the top of the page never lies.- function updateHero(c) {+ function updateHero(c, outcome) {const dial = $('#ocDial');if (dial && c.score != null) {dial.className = `dial t-${c.tier || 'watch'}`;dial.innerHTML = `<b>${c.score}</b><div class="tierpill tp-${esc(c.tier || 'watch')}">${esc(c.tier || 'watch')} conviction</div>`;}+ const odds = $('#ocOdds');+ if (odds) { const h = oddsHtml(c); if (h) odds.innerHTML = h; }+ const since = $('#ocSince');+ if (since) { const h = sinceHtml(outcome); if (h) since.innerHTML = h; }const p = c.pillars || {};const set = (kind, val) => {const el = $(`#ocPillars .pil.${kind}`);@@ -1013,7 +1077,7 @@if (!col) return;const c = data.conviction;document.title = `${c.symbol ? `$${c.symbol}` : mint.slice(0, 8)} — ${c.score}/100 ${c.tier || ''} conviction · Oracle · three.ws`;- updateHero(c);+ updateHero(c, data.outcome);const reasons = (data.reasons || []).map((r) => `<div class="reason"><span class="rdot ${esc(r.pillar)}"></span><span>${esc(r.text)}</span></div>`).join('') || '<div class="state" style="padding:20px 0">No breakdown available.</div>';const narr = data.narrative;const whos = (data.whos_in || []).map(whoRow).join('') || '<div class="state" style="padding:20px 0">No wallet footprint recorded yet.</div>';diff --git a/server/README.md b/server/README.mdindex ff081af81..859f75985 100644--- a/server/README.md+++ b/server/README.md@@ -101,12 +101,21 @@ frontend changes.## Crons-The 76 schedules in `vercel.json` are mirrored to Cloud Scheduler jobs-(us-central1) by [`scripts/create-gcp-scheduler.mjs`](../scripts/create-gcp-scheduler.mjs).-Each job calls its `/api/cron/*` path with `Authorization: Bearer $CRON_SECRET`-— the same header contract the handlers already validate. The script is-idempotent (create-or-update) and creates jobs **paused** unless `--resume`-is passed; see its header comment for the double-fire safety rules.+The schedules declared in `vercel.json`'s `crons` array are mirrored to Cloud+Scheduler jobs (us-central1) by+[`scripts/create-gcp-scheduler.mjs`](../scripts/create-gcp-scheduler.mjs). Each+job calls its `/api/cron/*` path with `Authorization: Bearer $CRON_SECRET`, the+same header contract the handlers already validate.++The script is idempotent (create-or-update) and **config only**: it writes+schedule, target, method, deadline and header, and never changes whether an+existing job is running. Jobs it creates start ENABLED, because a declared cron+that is created paused never fires and nothing in the config would show it. The+blanket run-state levers are explicit: `--pause` stops every job, `--resume`+restarts every job.++Verify the mirror with `npm run check:cron-drift` (declared vs. live schedules+and run state) and the handlers behind it with `npm run audit:cron-liveness`.## Env