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(tasks): split NVIDIA NIM plan into per-task prompt files

nirholas9cb392909a68
diff --git a/tasks/nvidia-nim/00-key-setup.md b/tasks/nvidia-nim/00-key-setup.md
new file mode 100644
index 000000000..e9c73c15c
--- /dev/null
+++ b/tasks/nvidia-nim/00-key-setup.md
@@ -0,0 +1,35 @@
+# Task T0.1: Verify NVIDIA_API_KEY in Codespace and Vercel prod
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+This is the entry-point task of the NVIDIA NIM integration plan — nothing else starts
+until it's done.
+
+**Dependencies:** none.
+
+## Steps
+
+1. Check `/workspaces/three.ws/.env` for `NVIDIA_API_KEY` (an `nvapi-…` key from the
+ free NVIDIA Developer Program at build.nvidia.com). If absent, **STOP and ask the
+ user to paste one** — do not proceed key-less and do not fabricate anything.
+2. Smoke-test the key live: POST `https://integrate.api.nvidia.com/v1/chat/completions`
+ with model `meta/llama-3.3-70b-instruct`, a trivial one-word user message, and
+ `max_tokens: 10`. Expect HTTP 200 with a completion.
+3. Verify the key exists in Vercel **prod and preview** via the **Vercel REST API** —
+ NOT `vercel env pull` (returns empty strings for sensitive values) and NOT the CLI
+ `vercel env add` (writes empty secrets under the plugin wrapper). If it must be
+ written to Vercel, use the REST API.
+4. Note the free-tier credit balance / rate-limit headers you observe, if any.
+
+## Done when
+
+- A live 200 from the key in this Codespace, AND
+- The key is confirmed present (non-empty) in Vercel prod.
+
+## Before you finish (mandatory bookkeeping)
+
+In `tasks/nvidia-nim/PLAN.md`: tick the T0.1 checkbox and append a dated Worklog entry
+(what you verified, credit/rate-limit observations, anything surprising). Commit the
+plan file with **explicit path staging** (concurrent agents share this worktree — never
+`git add -A`), re-checking `git status` and `git diff --staged` immediately before the
+commit. Never put the API key itself in any committed file.
diff --git a/tasks/nvidia-nim/01-probe-trellis.md b/tasks/nvidia-nim/01-probe-trellis.md
new file mode 100644
index 000000000..8fda67dce
--- /dev/null
+++ b/tasks/nvidia-nim/01-probe-trellis.md
@@ -0,0 +1,55 @@
+# Task T0.2: Probe the hosted TRELLIS API and commit a reproducible recipe
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T0.1 (NVIDIA_API_KEY live in `.env`).
+
+## Goal
+
+Discover, empirically, the exact hosted invocation protocol for **Microsoft TRELLIS on
+NVIDIA NIM** (https://build.nvidia.com/microsoft/trellis,
+https://docs.api.nvidia.com/nim/reference/microsoft-trellis) so the provider module
+(task T1.1) is built against observed behavior, not guessed schema. Public docs are
+thin — real probes with the real key are the point of this task.
+
+## Determine, with real API calls
+
+1. **Invoke URL + auth headers** (expected: NVCF-style, `ai.api.nvidia.com` or
+ `api.nvcf.nvidia.com` function invoke; auth `Bearer nvapi-…`).
+2. **Text→3D request schema** — prompt, seed, any quality/format params, which model
+ variants are hosted (base:text / large:text / large:image).
+3. **Image→3D request schema** — inline base64 image limit, and the NVCF asset-upload
+ handshake (create asset → upload to presigned URL → reference asset id in the
+ payload) for images above that limit.
+4. **Response shape** — where the base64 GLB artifact lives, and the 202-then-poll
+ protocol: poll URL, `NVCF-POLL-SECONDS` header behavior, status codes, terminal
+ states.
+5. **Observed latency** per variant and any rate-limit / credit headers.
+
+## Method
+
+- Probe with a one-word prompt and a tiny test image (a few KB, generated locally —
+ no third-party content).
+- Decode one returned GLB to disk and confirm it actually parses (npx gltf-validator,
+ or a small node script with three.js GLTFLoader). Delete scratch files afterwards —
+ no scratch output committed, repo root stays clean.
+- If the hosted free tier turns out NOT to serve TRELLIS invocations (deploy-only),
+ document that explicitly with the evidence — it changes Phase 1 scope and the plan
+ must know.
+
+## Deliverable
+
+`tasks/nvidia-nim/probes/trellis.md` containing: exact curl/node transcripts (key
+redacted as `$NVIDIA_API_KEY`), full request/response schemas, size/rate limits,
+latencies, gotchas, and a step-by-step reproducible recipe: request → poll → valid GLB.
+
+## Done when
+
+The probe file is committed and a teammate could produce a valid GLB following only it.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T0.2 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit the
+plan + probe file with explicit path staging (re-check `git status` / `git diff
+--staged` first — concurrent agents share this worktree).
diff --git a/tasks/nvidia-nim/02-probe-flux-tts-embeddings.md b/tasks/nvidia-nim/02-probe-flux-tts-embeddings.md
new file mode 100644
index 000000000..5a877911b
--- /dev/null
+++ b/tasks/nvidia-nim/02-probe-flux-tts-embeddings.md
@@ -0,0 +1,51 @@
+# Task T0.3: Probe NIM FLUX, TTS, and embeddings endpoints
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T0.1 (NVIDIA_API_KEY live in `.env`).
+
+## Goal
+
+Probe three more NIM model families with real API calls and commit transcripts (key
+redacted) under `tasks/nvidia-nim/probes/`, so Phases 1–3 build against observed
+behavior. For anything that turns out NOT to be invocable on the hosted free tier
+(some NIM models are deploy-only), say so explicitly in the probe file with evidence —
+that directly changes downstream scope.
+
+## 1. FLUX text→image → `probes/flux.md`
+
+- Models: black-forest-labs `flux.1-schnell` and/or `flux.1-dev` on build.nvidia.com.
+- Determine: invoke URL, request schema (prompt / steps / size / seed), response shape
+ (base64 image field), latency, rate-limit headers.
+- Produce one real image and confirm it decodes as a valid PNG/JPEG. Delete scratch files.
+
+## 2. TTS → `probes/tts.md`
+
+- Models: `nvidia/magpie-tts-multilingual` (and check what Riva TTS NIMs are currently
+ hosted for API invocation).
+- Determine: REST or gRPC-only? URL, voices, languages, audio formats,
+ streaming-or-not, request schema.
+- Produce one real audio file and verify duration > 0. Delete scratch files.
+- This decides Phase 2 feasibility — if hosted TTS is gRPC-only, document what a REST
+ caller would need (NVCF gRPC proxy? client lib?) and the realistic effort.
+
+## 3. Embeddings + reranker → `probes/embeddings.md`
+
+- Models: `nvidia/llama-3.2-nv-embedqa-1b-v2` / `nvidia/nv-embedqa-e5-v5`, plus the
+ rerankqa model.
+- These are OpenAI-compatible at `https://integrate.api.nvidia.com/v1/embeddings` but
+ require the extra `input_type: "query" | "passage"` body field — confirm.
+- Record: exact model ids, output dimensions, max batch size, max token/input length,
+ reranker request/response shape, latency, rate limits.
+
+## Done when
+
+All three probe files are committed with working recipes (or explicit, evidenced
+"not invocable on free tier" findings).
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T0.3 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit the
+plan + probe files with explicit path staging (re-check `git status` / `git diff
+--staged` first — concurrent agents share this worktree).
diff --git a/tasks/nvidia-nim/10-trellis-provider.md b/tasks/nvidia-nim/10-trellis-provider.md
new file mode 100644
index 000000000..3bdfb2386
--- /dev/null
+++ b/tasks/nvidia-nim/10-trellis-provider.md
@@ -0,0 +1,56 @@
+# Task T1.1: Build api/_providers/nvidia.js — the TRELLIS generation provider
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it — especially: no mocks, no stubs, no TODOs, real
+APIs only. Then read `tasks/nvidia-nim/PLAN.md` and `tasks/nvidia-nim/probes/trellis.md`
+(the empirically-verified API recipe — build against it, not against guesses).
+
+**Dependencies:** T0.2 (TRELLIS probe committed).
+
+## Goal
+
+A new generation provider `api/_providers/nvidia.js` giving `/forge` a **free** TRELLIS
+lane (text→3D and image→3D, GLB output) using the platform `NVIDIA_API_KEY`.
+
+## Contract
+
+Study `api/_providers/replicate.js` and `api/_providers/meshy.js` first and match the
+established provider shape exactly:
+
+- A factory (platform-keyed; key via `api/_lib/env.js` — add an accessor there if one
+ doesn't exist).
+- Submit functions for text→3D and image→3D returning a task id.
+- A poll function returning normalized status.
+- The same normalized error codes the other providers throw:
+ `provider_unreachable` / `invalid_key` / `insufficient_credits` / `rate_limited` /
+ `provider_error`, with proper `status` fields.
+
+## Specifics
+
+1. Implement the NVCF 202-then-poll protocol exactly as documented in the probe file.
+2. Image inputs arrive as R2 **https URLs** — fetch them server-side, then either inline
+ base64 (when under the probed size limit) or run the NVCF asset-upload handshake
+ (create asset → upload → reference asset id).
+3. TRELLIS returns the GLB as **base64** — decode and persist to R2 using the existing
+ persist helper (find it via the Vertex inline-PNG persist added 2026-06-11 in
+ `api/_mcp3d/`), and return a public URL like the other providers do.
+4. Timeouts on every fetch (`AbortSignal.timeout`); a hung upstream must not stall a
+ serverless function.
+5. The free tier is rate-limited — surface 429s as `rate_limited` so callers can route.
+
+## Done when
+
+- The module is contract-complete with zero placeholders, syntax-checks, and existing
+ provider tests still pass.
+- A live script run in this Codespace (text→3D, draft quality, real key) produces a
+ **real R2-hosted GLB** that loads. Put any helper script in `scripts/`, never the
+ repo root; delete it if it's one-off.
+
+## Before you finish (mandatory bookkeeping)
+
+Run the self-review protocol from CLAUDE.md against your diff. Tick T1.1 in
+`tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry (include observed end-to-end
+latency), and commit with explicit path staging (re-check `git status` / `git diff
+--staged` first — concurrent agents share this worktree). Beware: `npx vercel build`
+clobbers `api/*.js` in place — never run it, and check `head -1` of changed api/ files
+for `__defProp`/`createRequire` before committing.
diff --git a/tasks/nvidia-nim/11-register-backend.md b/tasks/nvidia-nim/11-register-backend.md
new file mode 100644
index 000000000..14605dcf1
--- /dev/null
+++ b/tasks/nvidia-nim/11-register-backend.md
@@ -0,0 +1,40 @@
+# Task T1.2: Register the NVIDIA backend in forge-tiers + make it the draft-tier default
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T1.1 (`api/_providers/nvidia.js` exists and is live-verified).
+
+## Goal
+
+Wire the new provider into the forge backend registry so the `/forge` UI and API can
+actually use it — free lane first, per platform policy.
+
+## Steps
+
+1. In `api/_lib/forge-tiers.js` `BACKENDS`: add the `nvidia` entry — provider `nvidia`,
+ paths `text-to-3d` + `image-to-3d`, `byok: false`,
+ `requiresEnv: ['NVIDIA_API_KEY']`, an **honest** `baseEta` from the latencies in
+ `tasks/nvidia-nim/probes/trellis.md`, a credits estimate, and zero vendor cost notes.
+2. Wire it through `resolveBackendId` / wherever the default backend per path+tier is
+ chosen so **NIM is the default for the draft tier** (free first), while
+ Replicate / Meshy / Tripo remain selectable. Check `api/_lib/regen-provider.js`,
+ `api/forge.js`, and the catalog endpoint the `/forge` UI reads.
+3. Trace the FULL path — UI catalog → submit → poll → gallery — and wire every
+ connection. The backend must appear in the UI with correct pricing/ETA; a backend
+ that exists but is unreachable from the UI is half-built (CLAUDE.md: eliminate dead
+ paths).
+4. Run the forge-related test suites.
+
+## Done when
+
+- `/forge` catalog (local dev, `npm run dev`) lists the NVIDIA backend with correct
+ metadata.
+- A draft-tier submit routes to it end-to-end.
+- Existing backends are unaffected (tests green).
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T1.2 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging (re-check `git status` / `git diff --staged` first — concurrent
+agents share this worktree).
diff --git a/tasks/nvidia-nim/12-flux-lane.md b/tasks/nvidia-nim/12-flux-lane.md
new file mode 100644
index 000000000..ef48916ea
--- /dev/null
+++ b/tasks/nvidia-nim/12-flux-lane.md
@@ -0,0 +1,36 @@
+# Task T1.3: Add a free NIM FLUX lane to text-to-image
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` and
+`tasks/nvidia-nim/probes/flux.md` (the verified API recipe).
+
+**Dependencies:** T0.3 (FLUX probe committed).
+
+## Goal
+
+Text→3D is two stages (text→image → TRELLIS). The image stage currently runs
+Vertex Imagen → Replicate FLUX (both paid). Add **NIM FLUX as the FIRST lane** — free
+before paid, per platform policy — so the entire text→3D chain can run free.
+
+## Steps
+
+1. In `api/_mcp3d/text-to-image.js`: the module already has a Vertex→Replicate fallback
+ structure (rebuilt 2026-06-11). Add NIM FLUX as the first lane, falling through to
+ Vertex then Replicate on any failure, exactly in the existing pattern.
+2. Reuse the existing R2 persist helper for the base64 PNG output (same one Vertex's
+ inline data-URI path uses).
+3. Per-attempt timeouts; a hung lane hands off, it doesn't stall.
+4. Extend `tests/api/text-to-image.test.js` for the new ordering: NIM serves → other
+ lanes untouched; NIM fails → falls through to Vertex → Replicate.
+
+## Done when
+
+- Tests pass.
+- A live local run generates a real image via NIM with the fallback chain intact
+ (force-fail NIM once to watch it degrade correctly).
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T1.3 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging (re-check `git status` / `git diff --staged` first — concurrent
+agents share this worktree).
diff --git a/tasks/nvidia-nim/13-tests.md b/tasks/nvidia-nim/13-tests.md
new file mode 100644
index 000000000..453f337b7
--- /dev/null
+++ b/tasks/nvidia-nim/13-tests.md
@@ -0,0 +1,41 @@
+# Task T1.4: Test suite for the NVIDIA provider + backend registration
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T1.1, T1.2, T1.3.
+
+## Goal
+
+`tests/api/providers-nvidia.test.js`, mirroring the structure and rigor of
+`tests/api/providers-replicate.test.js` (mocked fetch, no live calls in tests).
+
+## Coverage required
+
+1. Submit — text→3D and image→3D request construction against the probed schema.
+2. The 202-then-poll loop: pending → succeeded; pending → failed; poll timeout.
+3. Asset-upload branch selection by image size (inline base64 under the limit, NVCF
+ asset handshake over it).
+4. Base64-GLB decode + R2 persist call (persist helper mocked; assert it receives the
+ decoded bytes and the provider returns the public URL).
+5. Every normalized error mapping: 401/403 → `invalid_key`, 402 → `insufficient_credits`,
+ 429 → `rate_limited`, 5xx → `provider_error`, network throw → `provider_unreachable`.
+6. Forge-tiers registration: the `nvidia` backend resolves for both paths, draft-tier
+ default selection picks it when `NVIDIA_API_KEY` is set, and is skipped cleanly when
+ the env var is absent.
+
+No third-party token/coin addresses in fixtures — if a mint-like string is ever needed,
+use `$THREE` or a clearly-synthetic placeholder (CLAUDE.md).
+
+## Done when
+
+- New suite green.
+- Full `npm test` shows **no NEW failures** (6 pre-existing MCP-auth 401-vs-402 failures
+ on clean main are known; fresh clones also need `data/_generated` + the
+ solana-agent-sdk built first).
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T1.4 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging (re-check `git status` / `git diff --staged` first — concurrent
+agents share this worktree).
diff --git a/tasks/nvidia-nim/14-deploy-smoke-changelog.md b/tasks/nvidia-nim/14-deploy-smoke-changelog.md
new file mode 100644
index 000000000..d1314577b
--- /dev/null
+++ b/tasks/nvidia-nim/14-deploy-smoke-changelog.md
@@ -0,0 +1,39 @@
+# Task T1.5: Ship the free 3D lane — deploy, prod smoke test, changelog
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T1.1–T1.4 all done, AND `NVIDIA_API_KEY` confirmed in Vercel prod
+(T0.1). Do not start otherwise.
+
+## Steps
+
+1. **Changelog:** append a holder-readable entry to `data/changelog.json` — free,
+ faster default 3D drafts on /forge; plain language, no commit jargon; tags
+ `feature`, `improvement`; `link: "/forge"`. Run `npm run build:pages` — it validates
+ the entry and fails the build if malformed.
+2. **Commit & push:** explicit path staging only; re-check `git status` and
+ `git diff --staged` immediately before committing (concurrent agents). Before
+ committing anything under `api/`, check `head -1` of each changed file for
+ `__defProp`/`createRequire` (the `npx vercel build` clobber trap; recover with
+ `git restore -- api/ public/`). Push to BOTH remotes per CLAUDE.md (`threeD` may 403
+ — surface it, don't retry-loop; `threews` is canonical and feeds Vercel).
+3. **Watch the production build** (~20 min historically). If it fails, diagnose and fix
+ — do not report done with a red deploy.
+4. **Prod smoke test on three.ws/forge:**
+ - Text→3D, draft tier: submit a prompt → poll → GLB loads in the viewer.
+ - Image→3D: submit a real photo → poll → GLB loads.
+ - Zero console errors; network tab shows the `nvidia` backend serving.
+ - Force nothing, fake nothing — if it doesn't work, it isn't done.
+5. After deploy verification, run `npm run changelog:push` if Telegram creds are
+ present locally (skip silently if not).
+
+## Done when
+
+A first-time visitor gets a draft GLB from a prompt AND from a photo on **production**
+three.ws/forge via the free NIM lane, zero console errors.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T1.5 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry with observed prod
+latencies and the deployment id, and commit the plan update.
diff --git a/tasks/nvidia-nim/20-tts-lane.md b/tasks/nvidia-nim/20-tts-lane.md
new file mode 100644
index 000000000..0e932d7d6
--- /dev/null
+++ b/tasks/nvidia-nim/20-tts-lane.md
@@ -0,0 +1,44 @@
+# Task T2.1: Free TTS lane — bring avatar speech back without the dead OpenAI key
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` and
+`tasks/nvidia-nim/probes/tts.md` (the verified API recipe — it decides this task's
+shape).
+
+**Dependencies:** T0.3 (TTS probe committed).
+
+## Context
+
+`api/tts/speak.js` is hard-wired to `OPENAI_API_KEY`, which is over quota in prod —
+avatar speech is **dead right now**. Platform policy (api/_lib/llm.js doctrine): free
+lane first, paid backstop, never a hard fail with a free lane available.
+
+## Steps
+
+1. **Decision gate:** if the probe found hosted REST TTS (Magpie/Riva), proceed. If it
+ found gRPC-only, evaluate the realistic effort honestly, record the decision and
+ reasoning in the PLAN.md Worklog FIRST, and only build if it's sane — otherwise mark
+ T2.1 `[!]` blocked with the findings and stop.
+2. Restructure `api/tts/speak.js` to the free-first pattern: NIM TTS as the first lane,
+ OpenAI as the paid backstop. Per-attempt timeouts. Fail over only **before** any
+ audio bytes have been streamed to the client.
+3. Map the existing voice names (`nova`, etc. — see the `VOICES` set in the file) to the
+ nearest NIM voices so every existing caller keeps working unchanged.
+4. Keep the `x-tts-voice` / `x-tts-model` response headers truthful about what actually
+ served.
+5. Update the MCP twin `packages/avatar-agent-mcp/src/tools/speak.js` with the same
+ chain — same policy, both surfaces.
+6. Tests for the failover ordering (NIM serves → OpenAI never called; NIM fails → OpenAI
+ backstop; both fail → clean 502).
+
+## Done when
+
+- A local run produces audible audio via NIM with OpenAI never called.
+- The chain degrades correctly when NIM is forced to fail.
+- Tests green.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T2.1 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging (re-check `git status` / `git diff --staged` first — concurrent
+agents share this worktree).
diff --git a/tasks/nvidia-nim/21-tts-verify.md b/tasks/nvidia-nim/21-tts-verify.md
new file mode 100644
index 000000000..256c11d50
--- /dev/null
+++ b/tasks/nvidia-nim/21-tts-verify.md
@@ -0,0 +1,30 @@
+# Task T2.2: Deploy + verify avatar speech on every surface, changelog
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T2.1.
+
+## Steps
+
+1. **Changelog:** append a holder-readable entry to `data/changelog.json` — avatar
+ speech is back, in holder language (no commit jargon); tag `fix`. Validate with
+ `npm run build:pages`.
+2. **Commit & push** (explicit paths, both remotes per CLAUDE.md, api/-clobber check
+ on changed api/ files first). Watch the production build through to green.
+3. **Find every surface** that calls `/api/tts/speak`: grep the frontends (`src/`,
+ `public/`, widget embed code, MCP tools) — don't assume you know them all.
+4. **Verify each one in prod** actually plays audio (real browser, real click). List
+ every surface checked in the Worklog. Zero console errors from the speech path.
+5. Run `npm run changelog:push` if Telegram creds are present locally (skip silently
+ if not).
+
+## Done when
+
+Every speech surface on production plays audio via the free lane, and the Worklog lists
+them individually.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T2.2 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit the
+plan update with explicit path staging.
diff --git a/tasks/nvidia-nim/30-embeddings-multiprovider.md b/tasks/nvidia-nim/30-embeddings-multiprovider.md
new file mode 100644
index 000000000..64a3e9722
--- /dev/null
+++ b/tasks/nvidia-nim/30-embeddings-multiprovider.md
@@ -0,0 +1,52 @@
+# Task T3.1: Multi-provider embeddings with vector-space tagging
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` and
+`tasks/nvidia-nim/probes/embeddings.md` (verified model ids, dimensions, limits).
+
+**Dependencies:** T0.3 (embeddings probe committed).
+
+## Context
+
+`api/_lib/embeddings.js` is OpenAI-only and the prod OpenAI key is over quota — widget
+knowledge retrieval (RAG) is **silently broken**. NIM serves free retrieval embeddings
+(OpenAI-compatible at `integrate.api.nvidia.com/v1/embeddings`, plus the required
+`input_type: "query" | "passage"` field).
+
+## The trap that shapes this whole task
+
+**Embeddings from different providers are different vector spaces — they must NEVER mix
+at query time.** A query embedded with model A compared against passages embedded with
+model B returns garbage similarity scores that look plausible. This is worse than an
+error.
+
+## Steps
+
+1. Rework `api/_lib/embeddings.js`: NIM as the free primary embedder (`input_type:
+ passage` for ingest, `query` for search), OpenAI as backstop — but provider choice is
+ **per document set**, not per call (see below).
+2. Find the storage schema for widget knowledge vectors (start from
+ `api/widgets/[id]/_knowledge.js` and the ingest path). Add an embedder tag (model id
+ + dimension) to every stored vector / document set. Existing untagged rows are
+ OpenAI — encode that assumption explicitly in the migration default.
+3. Query-time rule: embed the query with THE SAME provider/model the document set was
+ embedded with. A set tagged OpenAI queries via OpenAI (if available) or is flagged
+ needs-reembed — never silently cross spaces.
+4. New ingests use the free NIM lane by default.
+5. Update `embeddingsConfigured()` semantics so feature gates stay truthful about what
+ can actually serve.
+6. Tests: tagging on ingest, same-space query routing, cross-space refusal, fallback
+ behavior.
+
+## Done when
+
+- New ingests embed free via NIM.
+- Existing OpenAI-embedded sets still query correctly (against OpenAI when available)
+ or are cleanly flagged for re-embed.
+- Nothing can mix vector spaces. Tests green.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T3.1 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry (include the
+schema change you made), and commit with explicit path staging (re-check `git status` /
+`git diff --staged` first — concurrent agents share this worktree).
diff --git a/tasks/nvidia-nim/31-reembed-migration.md b/tasks/nvidia-nim/31-reembed-migration.md
new file mode 100644
index 000000000..559faaa6f
--- /dev/null
+++ b/tasks/nvidia-nim/31-reembed-migration.md
@@ -0,0 +1,44 @@
+# Task T3.2: Re-embed migration for stored widget knowledge
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T3.1 deployed to prod (the tagging schema must be live before
+migrating prod data).
+
+## Goal
+
+`scripts/reembed-widget-knowledge.mjs` — migrate all stored widget knowledge chunks
+from the dead OpenAI embedding space to the free NIM embedder, safely.
+
+## Requirements
+
+1. **Batch re-embed** every stored chunk with the NIM embedder, respecting free-tier
+ rate limits (throttle; back off on 429).
+2. **Resume-safe and idempotent:** track the embedder tag per row; a re-run skips
+ already-migrated rows; a crash mid-run loses nothing.
+3. **Atomic per document set:** switch a set's tag only when every chunk in it is
+ re-embedded, so retrieval never sees a half-migrated set (T3.1's same-space rule
+ makes a half-set unqueryable otherwise).
+4. **`--dry-run` mode required** — prints counts and cost/time estimates, writes
+ nothing.
+5. Optional, if it earns its keep: add the NIM reranker as a post-retrieval stage in
+ widget knowledge search. Measure on a real widget's corpus — does it improve top-3
+ relevance? Keep it only if yes; record the measurement in the Worklog either way.
+
+## Execution
+
+Dry-run first, record the counts. Then run for real against prod data (T3.1 must be
+deployed). Record migrated counts, duration, and any rate-limit incidents in the
+Worklog.
+
+## Done when
+
+Every stored set is tagged NIM (or explicitly skipped with a reason), retrieval works
+end-to-end on migrated sets, and the script is committed in `scripts/` (repo root stays
+clean).
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T3.2 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry with the
+migration numbers, and commit with explicit path staging.
diff --git a/tasks/nvidia-nim/32-rag-verify.md b/tasks/nvidia-nim/32-rag-verify.md
new file mode 100644
index 000000000..98db01220
--- /dev/null
+++ b/tasks/nvidia-nim/32-rag-verify.md
@@ -0,0 +1,28 @@
+# Task T3.3: End-to-end RAG verification in prod + changelog
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** T3.2 (migration run against prod).
+
+## Steps
+
+1. **End-to-end prod verification:** pick (or create) a widget with ingested knowledge.
+ Ask it a question only its corpus can answer. Confirm the SSE reply is grounded in
+ that corpus, and confirm (logs/instrumentation) the query embedding was served by the
+ free NIM lane. Test the empty case too: a widget with no knowledge degrades
+ gracefully, no errors.
+2. **Changelog:** holder-readable entry in `data/changelog.json` (fix: widgets answer
+ from their knowledge again); validate with `npm run build:pages`.
+3. **Commit & push** (explicit paths, both remotes per CLAUDE.md). Watch the deploy
+ through to green. `npm run changelog:push` if Telegram creds present (skip silently
+ if not).
+
+## Done when
+
+A real widget on production answers from its knowledge with embeddings served free.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T3.3 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit the
+plan update with explicit path staging.
diff --git a/tasks/nvidia-nim/40-vision-lane.md b/tasks/nvidia-nim/40-vision-lane.md
new file mode 100644
index 000000000..aeb026f0e
--- /dev/null
+++ b/tasks/nvidia-nim/40-vision-lane.md
@@ -0,0 +1,41 @@
+# Task T4.1: Shared vision helper + three consumers
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** Phases 1–3 shipped (do not start before).
+
+## Goal
+
+Free image understanding via NIM vision models, as a shared helper plus three concrete
+consumers — a helper with no consumers is decoration (CLAUDE.md: wire every connection).
+
+## Steps
+
+1. **Probe first:** determine which vision models are actually invocable on the hosted
+ free tier (nemotron nano VL, llama vision — check build.nvidia.com), request schema
+ (image input encoding), limits. Commit `tasks/nvidia-nim/probes/vision.md` with
+ transcripts (key redacted).
+2. **Shared helper** in `api/_lib/` following the `llm.js` free-first doctrine: NIM
+ vision lane(s) first, any paid vision-capable backstop after, normalized errors,
+ timeouts, spend tracking via `recordEvent` like `llmComplete` does.
+3. **Consumer 1 — /forge input validation:** before an image→3D submit burns a
+ generation, check the photo is usable (single clear subject, not a screenshot of
+ text, etc.); warn the user with a designed, actionable message. Degrades to
+ no-validation when vision is unavailable — never blocks generation on a vision
+ outage.
+4. **Consumer 2 — fact-checker:** image evidence support (describe/extract from an
+ image URL in a claim).
+5. **Consumer 3 — avatar gallery alt text:** backfill + on-create alt text for gallery
+ items (accessibility is not optional — CLAUDE.md).
+6. Tests for the helper chain and each consumer's degraded path. Changelog entry
+ (holder language). Deploy + verify per the standard ship checklist.
+
+## Done when
+
+All three consumers work in prod on the free lane and degrade gracefully without it.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T4.1 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging.
diff --git a/tasks/nvidia-nim/41-moderation-prefilter.md b/tasks/nvidia-nim/41-moderation-prefilter.md
new file mode 100644
index 000000000..e3eafc1a5
--- /dev/null
+++ b/tasks/nvidia-nim/41-moderation-prefilter.md
@@ -0,0 +1,43 @@
+# Task T4.2: Free moderation pre-filter for anonymous chat (fail-open)
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** Phases 1–3 shipped (do not start before).
+
+## Goal
+
+Run our own content moderation on anonymous chat traffic using free NIM safety models,
+instead of inheriting third-party moderation gates.
+
+## Steps
+
+1. **Probe first:** NemoGuard / Llama Guard hosted on NIM — invocable on the free tier?
+ Request/response schema, categories, latency (it sits on the hot path — measure).
+ Commit `tasks/nvidia-nim/probes/moderation.md`.
+2. **Pre-moderation pass for ANONYMOUS surfaces only** (signed-in users are already
+ rate-limited and attributable): the anon path in `api/chat.js`, widget chat
+ (`api/widgets/[id]/[action].js`), and `api/chat/proxy.js`.
+3. **Fail-open is non-negotiable:** a moderation outage must never block chat — it's a
+ filter, not a gate. Timeout small (the probe's latency number + margin), and on any
+ error proceed un-moderated.
+4. **Config-flagged** (env var) so it can be disabled instantly in prod without a
+ deploy.
+5. A blocked message gets a designed, non-preachy refusal in the normal reply format —
+ not an HTTP error.
+6. **Second-order effect to evaluate:** `openai/gpt-oss-120b:free` was demoted in
+ `api/_lib/chat-models.js` because OpenRouter moderation-gates it (403 "requires
+ moderation"). If we pre-moderate ourselves, that route may be safely re-promotable —
+ test it, and update the catalog + its comments if so.
+7. Tests: block path, allow path, outage fail-open, flag-off bypass. Changelog entry.
+ Deploy + verify.
+
+## Done when
+
+Anonymous chat runs behind the free pre-filter in prod, fail-open verified (force a
+moderation failure and watch chat keep working), kill-switch flag verified.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T4.2 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry (include the
+gpt-oss re-promotion decision), and commit with explicit path staging.
diff --git a/tasks/nvidia-nim/42-audio2face-spike.md b/tasks/nvidia-nim/42-audio2face-spike.md
new file mode 100644
index 000000000..c25ad7bee
--- /dev/null
+++ b/tasks/nvidia-nim/42-audio2face-spike.md
@@ -0,0 +1,44 @@
+# Task T4.3: Audio2Face-3D feasibility spike (research only)
+
+You are a senior engineer working in the **three.ws** repo (`/workspaces/three.ws`).
+Read `CLAUDE.md` first and obey it, then read `tasks/nvidia-nim/PLAN.md` for context.
+
+**Dependencies:** Phases 1–3 shipped (do not start before).
+
+## Goal
+
+**Research only — no integration, no code in api/ or src/.** Decide whether NVIDIA
+Audio2Face-3D (blendshape lip-sync from audio — real facial animation for the talking
+avatars) is worth a real integration task.
+
+## Questions to answer
+
+1. **Invocability:** is Audio2Face-3D callable on the hosted NIM free tier, or
+ self-host/NVCF-deploy only? It's gRPC-based
+ (https://github.com/NVIDIA/Audio2Face-3D) — what exactly would a Vercel-function or
+ worker caller need (gRPC client lib, NVCF proxy, persistent connection)? Probe
+ whatever is probeable with the real key.
+2. **Output mapping:** what does it emit (ARKit blendshapes? its own facial pose set?
+ visemes?) and how does that map onto OUR avatar rigs — inspect the GLB rigs the
+ platform actually serves (morph target names, bone naming) and check compatibility
+ concretely, not theoretically.
+3. **Architecture fit:** where would it run (realtime per-utterance vs pre-baked per
+ TTS clip), what latency is acceptable for the talking-avatar widgets, and does the
+ existing TTS pipeline (Phase 2) hand it audio in a usable form?
+4. **Effort estimate:** honest task breakdown with sizes if it's a go.
+
+## Deliverable
+
+`tasks/nvidia-nim/probes/audio2face.md` with findings, transcripts of any live probes
+(key redacted), a clear **go / no-go recommendation**, and — if go — a task breakdown
+appended to `tasks/nvidia-nim/PLAN.md` as new Phase 5 checklist items plus matching
+task files in this folder.
+
+## Done when
+
+A reader can make the go/no-go call from the probe file alone, with evidence.
+
+## Before you finish (mandatory bookkeeping)
+
+Tick T4.3 in `tasks/nvidia-nim/PLAN.md`, append a dated Worklog entry, and commit with
+explicit path staging.
diff --git a/tasks/nvidia-nim/PLAN.md b/tasks/nvidia-nim/PLAN.md
index 14b86e5a7..5302c1f9c 100644
--- a/tasks/nvidia-nim/PLAN.md
+++ b/tasks/nvidia-nim/PLAN.md
@@ -15,10 +15,10 @@ The chat-side free-first failover already shipped 2026-06-11 (`api/_lib/llm.js`,
## How to use this document (read this first, every session)
1. Read `CLAUDE.md`, then this file top to bottom.
-2. Find the first unchecked task whose dependencies are checked. Work it using its
- **Prompt** verbatim (each prompt is self-contained — paste it to a fresh agent and it
- has everything it needs).
-3. **Before ending any session:** update the checkbox, append a dated entry to the
+2. Find the first unchecked task whose dependencies are checked. Open its task file
+ (linked in the checklist below) and **paste the entire file as the prompt** to a
+ fresh agent — every task file is fully self-contained.
+3. **Before ending any session:** update the checkbox here, append a dated entry to the
Worklog at the bottom (what was done, what was verified, what surprised you), and
commit THIS FILE plus your changes — stage explicit paths only (concurrent agents
share this worktree), and push to both remotes per CLAUDE.md.
@@ -33,30 +33,30 @@ Status legend: `[ ]` not started · `[~]` in progress (note who/when in Worklog)
## Checklist (current state at a glance)
### Phase 0 — Key + live API probes
-- [ ] **T0.1** NVIDIA_API_KEY available in Codespace `.env` and verified in Vercel prod
-- [ ] **T0.2** TRELLIS hosted API probed; schema + transcript committed to `probes/trellis.md`
-- [ ] **T0.3** FLUX, Magpie TTS, and embeddings endpoints probed; transcripts committed
+- [ ] **T0.1** [00-key-setup.md](00-key-setup.md) — NVIDIA_API_KEY in Codespace `.env` and verified in Vercel prod
+- [ ] **T0.2** [01-probe-trellis.md](01-probe-trellis.md) — TRELLIS hosted API probed; recipe committed to `probes/trellis.md`
+- [ ] **T0.3** [02-probe-flux-tts-embeddings.md](02-probe-flux-tts-embeddings.md) — FLUX, TTS, embeddings probed; transcripts committed
### Phase 1 — Free 3D lane in /forge (top priority)
-- [ ] **T1.1** `api/_providers/nvidia.js` — TRELLIS provider (submit / poll / GLB→R2)
-- [ ] **T1.2** Backend registered in `api/_lib/forge-tiers.js` + catalog; draft-tier default decided
-- [ ] **T1.3** NIM FLUX lane in `api/_mcp3d/text-to-image.js`
-- [ ] **T1.4** Unit tests (mirror `tests/api/providers-replicate.test.js`)
-- [ ] **T1.5** Deployed + prod smoke test (text→3D and image→3D return a loading GLB) + changelog entry
+- [ ] **T1.1** [10-trellis-provider.md](10-trellis-provider.md) — `api/_providers/nvidia.js` (submit / poll / GLB→R2)
+- [ ] **T1.2** [11-register-backend.md](11-register-backend.md) — backend in `forge-tiers.js`; draft-tier default
+- [ ] **T1.3** [12-flux-lane.md](12-flux-lane.md) — NIM FLUX lane in `api/_mcp3d/text-to-image.js`
+- [ ] **T1.4** [13-tests.md](13-tests.md) — `tests/api/providers-nvidia.test.js` + registration coverage
+- [ ] **T1.5** [14-deploy-smoke-changelog.md](14-deploy-smoke-changelog.md) — deploy + prod smoke + changelog
### Phase 2 — Speech back online
-- [ ] **T2.1** Free TTS lane in `api/tts/speak.js` (NIM first, OpenAI backstop)
-- [ ] **T2.2** Avatar speech surfaces verified in prod + changelog entry
+- [ ] **T2.1** [20-tts-lane.md](20-tts-lane.md) — free TTS lane in `api/tts/speak.js` (NIM first, OpenAI backstop)
+- [ ] **T2.2** [21-tts-verify.md](21-tts-verify.md) — every speech surface verified in prod + changelog
### Phase 3 — Widget RAG back online
-- [ ] **T3.1** `api/_lib/embeddings.js` multi-provider with vector-space tagging
-- [ ] **T3.2** Re-embed migration for stored widget knowledge (+ optional reranker)
-- [ ] **T3.3** Retrieval verified end-to-end in prod + changelog entry
+- [ ] **T3.1** [30-embeddings-multiprovider.md](30-embeddings-multiprovider.md) — multi-provider embeddings, vector-space tagging
+- [ ] **T3.2** [31-reembed-migration.md](31-reembed-migration.md) — re-embed migration script + run (+ optional reranker)
+- [ ] **T3.3** [32-rag-verify.md](32-rag-verify.md) — RAG verified end-to-end in prod + changelog
### Phase 4 — Expansion lanes (after 1–3)
-- [ ] **T4.1** Vision lane (forge input validation, fact-checker images, gallery alt text)
-- [ ] **T4.2** NemoGuard/Llama Guard moderation pre-filter for anonymous chat
-- [ ] **T4.3** Audio2Face-3D feasibility spike (research only — no integration commitment)
+- [ ] **T4.1** [40-vision-lane.md](40-vision-lane.md) — vision helper + forge validation, fact-checker, alt text
+- [ ] **T4.2** [41-moderation-prefilter.md](41-moderation-prefilter.md) — fail-open moderation for anonymous chat
+- [ ] **T4.3** [42-audio2face-spike.md](42-audio2face-spike.md) — Audio2Face-3D go/no-go spike (research only)
---
@@ -67,7 +67,7 @@ Status legend: `[ ]` not started · `[~]` in progress (note who/when in Worklog)
- Codespace: must be present in `/workspaces/three.ws/.env` for live probes/tests.
- Vercel prod/preview: verify via the **REST API**, not `vercel env pull` (pull returns
empty strings for sensitive values) and not `vercel env add` (the CLI plugin wrapper
- writes empty secrets — use the REST API to write, per `docs/` ops notes).
+ writes empty secrets — use the REST API to write).
- Free-tier reality: credit-metered, rate-limited, no SLA. Fine for fallback lanes and
async generation jobs; never make it the *only* lane on a hot path.
- Chat-side NIM endpoints already live in code: `https://integrate.api.nvidia.com/v1`
@@ -78,270 +78,6 @@ Status legend: `[ ]` not started · `[~]` in progress (note who/when in Worklog)
---
-## Phase 0 — Key + live API probes
-
-### T0.1 — Key in place
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md and tasks/nvidia-nim/PLAN.md first): verify
-> `NVIDIA_API_KEY` is usable. (1) Check `.env` for NVIDIA_API_KEY; if absent, STOP and ask
-> the user to paste one (from build.nvidia.com) — do not proceed key-less. (2) Smoke-test
-> it: POST https://integrate.api.nvidia.com/v1/chat/completions with model
-> `meta/llama-3.3-70b-instruct`, a trivial message, max_tokens 10 — expect 200. (3) Verify
-> the key exists in Vercel prod + preview via the Vercel REST API (NOT `vercel env pull`,
-> which returns empty for secrets; NOT CLI `env add`, which writes empty values — if it
-> must be written, use the REST API). (4) Record results in the PLAN.md Worklog, tick
-> T0.1, commit the plan file (explicit path staging).
-
-**Done when:** live 200 from the key in the Codespace AND confirmed present in Vercel prod.
-
-### T0.2 — Probe TRELLIS
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md and tasks/nvidia-nim/PLAN.md first; requires
-> T0.1): discover the exact hosted invocation protocol for Microsoft TRELLIS on NVIDIA
-> NIM (https://build.nvidia.com/microsoft/trellis, https://docs.api.nvidia.com/nim/reference/microsoft-trellis).
-> Using NVIDIA_API_KEY from .env, determine empirically: (1) invoke URL + auth headers;
-> (2) text→3D request schema (prompt, seed, any quality params); (3) image→3D request
-> schema — inline base64 limit, and the NVCF asset-upload handshake (create-asset →
-> upload → reference asset id) for larger images; (4) response shape — base64 GLB
-> artifact field, and the 202/poll protocol (poll URL, NVCF-POLL-SECONDS header, status
-> codes); (5) observed latency per variant and any rate-limit headers. Run real probes
-> with a tiny test image and a one-word prompt; decode one GLB to disk and confirm it
-> parses (npx gltf-validator or three.js GLTFLoader in a node script — delete scratch
-> files after). Write everything — exact curl/node transcripts (key redacted), schemas,
-> limits, gotchas — to tasks/nvidia-nim/probes/trellis.md. Update PLAN.md Worklog, tick
-> T0.2, commit both files.
-
-**Done when:** `probes/trellis.md` contains a reproducible recipe: request → poll → valid GLB.
-
-### T0.3 — Probe FLUX, TTS, embeddings
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md and tasks/nvidia-nim/PLAN.md first; requires
-> T0.1): probe three more NIM endpoints with NVIDIA_API_KEY from .env and commit
-> transcripts (key redacted) under tasks/nvidia-nim/probes/: (1) **FLUX text→image**
-> (black-forest-labs flux.1-schnell and/or flux.1-dev on build.nvidia.com) — invoke URL,
-> request schema (prompt/steps/size), base64 image output → probes/flux.md. (2) **TTS**
-> (magpie-tts-multilingual; also check current Riva TTS NIM hosted offerings) — REST or
-> gRPC? URL, voices, languages, audio formats, streaming or not; produce one real audio
-> file and listen-check duration > 0 → probes/tts.md. (3) **Embeddings + reranker**
-> (llama-3.2-nv-embedqa / nv-embedqa-e5-v5, and the rerankqa model) — these are
-> OpenAI-compatible at integrate.api.nvidia.com/v1/embeddings but need the extra
-> `input_type: query|passage` body field; record model ids, dimensions, max batch and
-> token limits → probes/embeddings.md. For anything not actually invocable on the hosted
-> free tier (some NIM models are deploy-only), say so explicitly in the probe file — that
-> directly changes Phases 2–3 scope. Update PLAN.md Worklog, tick T0.3, commit.
-
-**Done when:** all three probe files committed with working (or explicitly-impossible) recipes.
-
----
-
-## Phase 1 — Free 3D lane in /forge
-
-### T1.1 — TRELLIS provider module
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md, and
-> tasks/nvidia-nim/probes/trellis.md first; requires T0.2): build
-> `api/_providers/nvidia.js`, a TRELLIS generation provider matching the established
-> provider contract — study `api/_providers/replicate.js` and `api/_providers/meshy.js`
-> for the shape: a factory (platform-keyed, key from env via `api/_lib/env.js` — add an
-> accessor if needed), submit functions for text→3D and image→3D returning a task id,
-> a poll function returning normalized status, and the same normalized error codes
-> (provider_unreachable / invalid_key / insufficient_credits / rate_limited /
-> provider_error). Specifics: (1) implement the NVCF 202/poll protocol from the probe
-> file; (2) image inputs arrive as R2 https URLs — fetch, and either inline base64
-> (under the probed limit) or run the NVCF asset-upload handshake; (3) TRELLIS returns
-> the GLB as base64 — decode and persist to R2 using the existing persist helper (find
-> it via the Vertex inline-PNG persist added 2026-06-11 in api/_mcp3d/), and return a
-> public URL like the other providers do; (4) timeouts on every fetch; free tier is
-> rate-limited — surface 429s as rate_limited so callers can route. No mocks, no stubs,
-> no TODOs. Syntax-check, run existing provider tests to ensure nothing broke. Update
-> PLAN.md Worklog, tick T1.1, commit (explicit paths).
-
-**Done when:** module exists, contract-complete, and a live Codespace script run
-(text→3D, draft quality) produces a real R2-hosted GLB.
-
-### T1.2 — Register the backend
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T1.1):
-> register the NVIDIA backend in `api/_lib/forge-tiers.js` BACKENDS — provider `nvidia`,
-> paths text-to-3d + image-to-3d, `byok: false`, `requiresEnv: ['NVIDIA_API_KEY']`,
-> honest baseEta from the probe latencies, credits estimate, and free/zero vendor cost
-> notes. Wire it through `resolveBackendId` / wherever the default backend per path+tier
-> is chosen so that **NIM is the default for the draft tier** (free lane first, per
-> platform policy) while Replicate/Meshy/Tripo stay selectable; check
-> `api/_lib/regen-provider.js`, `api/forge.js`, and the catalog endpoint the /forge UI
-> reads so the new backend appears with correct pricing/ETA in the UI. Trace the FULL
-> path (UI catalog → submit → poll → gallery) and wire every connection. Run the forge
-> test suites. Update PLAN.md Worklog, tick T1.2, commit.
-
-**Done when:** /forge catalog (local dev) lists the NVIDIA backend, draft-tier submits
-route to it, and existing backends are unaffected.
-
-### T1.3 — FLUX text→image lane
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md, probes/flux.md;
-> requires T0.3): add a NIM FLUX lane to `api/_mcp3d/text-to-image.js`. That module
-> already has a Vertex-Imagen → Replicate-FLUX fallback structure (rebuilt 2026-06-11) —
-> add NIM FLUX as the FIRST lane (free before paid, per platform policy), falling
-> through to Vertex then Replicate on failure, reusing the existing R2 persist for the
-> base64 PNG output. Keep per-attempt timeouts. Extend the existing
-> tests/api/text-to-image.test.js coverage for the new ordering (NIM serves → others
-> untouched; NIM fails → falls through). Update PLAN.md Worklog, tick T1.3, commit.
-
-**Done when:** tests pass and a live local run generates an image via NIM with the
-fallback chain intact.
-
-### T1.4 — Tests
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T1.1–T1.3):
-> write `tests/api/providers-nvidia.test.js` mirroring providers-replicate.test.js:
-> mocked-fetch coverage of submit (text + image paths), the 202/poll loop, asset-upload
-> branch selection by image size, base64-GLB persist call, and every normalized error
-> mapping (401/402/429/5xx/network). Also cover the forge-tiers registration (backend
-> resolvable, draft-tier default). Run the full forge + provider + llm test suites.
-> Update PLAN.md Worklog, tick T1.4, commit.
-
-**Done when:** new suite green; full `npm test` shows no NEW failures (6 pre-existing
-MCP-auth failures on clean main are known — see memory/repo notes).
-
-### T1.5 — Deploy + prod smoke + changelog
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T1.1–T1.4
-> AND NVIDIA_API_KEY confirmed in Vercel prod from T0.1): ship the free 3D lane. (1) Add
-> a holder-readable entry to data/changelog.json (free, faster default 3D drafts on
-> /forge; tags: feature, improvement; link: /forge) and run `npm run build:pages` to
-> validate. (2) Commit (explicit paths) and push to BOTH remotes per CLAUDE.md. (3) Watch
-> the Vercel production build (~20 min; beware the `npx vercel build` api/-clobber trap —
-> never run it locally and commit). (4) Prod smoke: submit text→3D draft on three.ws/forge
-> → poll → GLB loads in viewer; submit image→3D with a real photo → GLB loads; confirm
-> zero console errors and the network tab shows the nvidia backend. (5) Record results +
-> latencies in PLAN.md Worklog, tick T1.5, commit the plan update.
-
-**Done when:** a first-time visitor gets a draft GLB from a prompt AND from a photo on
-production three.ws/forge via the free NIM lane.
-
----
-
-## Phase 2 — Speech back online
-
-### T2.1 — Free TTS lane
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md, probes/tts.md;
-> requires T0.3): `api/tts/speak.js` is hard-wired to OPENAI_API_KEY (over quota in prod
-> → speech is dead). Restructure it to the platform free-first pattern: NIM TTS
-> (magpie/Riva per the probe — if the probe found hosted REST, use it; if gRPC-only,
-> evaluate the effort honestly and record the decision in the Worklog before building)
-> as the first lane, OpenAI as the paid backstop, per-attempt timeouts, fail over before
-> any audio bytes are streamed. Map the existing voice names (`nova` etc.) to nearest
-> NIM voices so existing callers keep working; keep response headers
-> (x-tts-voice/x-tts-model) accurate about what actually served. Update the MCP twin in
-> packages/avatar-agent-mcp/src/tools/speak.js with the same chain. Tests for the
-> failover ordering. Update PLAN.md Worklog, tick T2.1, commit.
-
-**Done when:** local run produces audible audio via NIM with OpenAI never called; chain
-falls back correctly when NIM is forced to fail.
-
-### T2.2 — Verify + changelog
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T2.1):
-> deploy (changelog entry: "avatar speech is back" in holder language, tags: fix), push
-> both remotes, then verify on prod: every surface that calls /api/tts/speak (find them:
-> grep the frontends) actually plays audio. Record surfaces checked in the Worklog, tick
-> T2.2, commit.
-
----
-
-## Phase 3 — Widget RAG back online
-
-### T3.1 — Multi-provider embeddings
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md, probes/embeddings.md;
-> requires T0.3): `api/_lib/embeddings.js` is OpenAI-only (dead quota → widget knowledge
-> retrieval silently broken). Rework it: NVIDIA NIM retrieval embeddings as the free
-> primary (with `input_type: passage` for ingest and `query` for search), OpenAI as
-> backstop. CRITICAL: embeddings from different providers are different vector spaces —
-> never mix at query time. Tag every stored vector with its embedder (model id +
-> dimension); find the storage schema (widget knowledge tables — see
-> api/widgets/[id]/_knowledge.js and the ingest path) and add the column/backfill
-> assumption that existing rows are OpenAI. At query time, embed the query with THE SAME
-> provider the document set was embedded with; only use the free lane for sets ingested
-> with it. Update `embeddingsConfigured()` semantics so feature gates stay truthful.
-> Tests. Update PLAN.md Worklog, tick T3.1, commit.
-
-**Done when:** new ingests embed free via NIM; existing OpenAI-embedded sets still query
-correctly (against OpenAI if available) or are flagged for re-embed; nothing mixes spaces.
-
-### T3.2 — Re-embed migration
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T3.1):
-> write `scripts/reembed-widget-knowledge.mjs`: batch re-embed all stored widget
-> knowledge chunks with the NIM embedder (respect free-tier rate limits — throttle,
-> resume-safe by tracking embedder tag per row, idempotent re-runs), switching each
-> document set's tag atomically so retrieval never sees a half-migrated set. Optionally
-> add the NIM reranker as a post-retrieval quality stage in the widget knowledge search
-> (measure: does it improve top-3 relevance on a real widget's corpus?). Dry-run mode
-> required. Run against prod data only after T3.1 is deployed; record counts in the
-> Worklog, tick T3.2, commit.
-
-### T3.3 — Verify + changelog
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md; requires T3.2):
-> end-to-end prod verification: a widget with ingested knowledge answers a question
-> grounded in that knowledge (check the SSE reply quotes the corpus), with embeddings
-> served by the free lane. Changelog entry (fix: widget knowledge answers again), push
-> both remotes, tick T3.3, commit.
-
----
-
-## Phase 4 — Expansion lanes (do not start before Phases 1–3 ship)
-
-### T4.1 — Vision lane
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md): add a shared
-> vision-completion helper to api/_lib/ (NIM vision models — nemotron nano VL or llama
-> vision per what's hosted; probe first, commit probes/vision.md) following the llm.js
-> free-first pattern, then wire three consumers: (1) /forge image→3D input validation
-> (reject/warn on unusable photos before burning a generation); (2) fact-checker image
-> evidence; (3) avatar gallery alt-text backfill. Each consumer degrades gracefully when
-> vision is unavailable. Tests + changelog + Worklog + tick.
-
-### T4.2 — Moderation pre-filter
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md): probe NemoGuard /
-> Llama Guard hosted on NIM (probes/moderation.md), then add an optional pre-moderation
-> pass for ANONYMOUS chat surfaces (api/chat.js anon path, widget chat, chat/proxy) —
-> free, fast, fail-open (a moderation outage must never block chat; it's a filter, not a
-> gate). Config-flagged so it can be disabled instantly. This also re-opens the
-> moderation-gated gpt-oss free OpenRouter route if we pre-moderate ourselves — evaluate
-> and note in chat-models.js if so. Tests + Worklog + tick.
-
-### T4.3 — Audio2Face-3D spike
-
-**Prompt:**
-> In /workspaces/three.ws (read CLAUDE.md, tasks/nvidia-nim/PLAN.md): research-only
-> spike, NO integration: determine whether NVIDIA Audio2Face-3D (blendshape lip-sync
-> from audio) is invocable on the hosted free tier (it's gRPC/NVCF — github.com/NVIDIA/Audio2Face-3D),
-> what its outputs map to on our avatar rigs (ARKit blendshapes? viseme set?), and what
-> a real integration would cost in effort. Deliverable: tasks/nvidia-nim/probes/audio2face.md
-> with a go/no-go recommendation and, if go, a task breakdown appended to this plan.
-> Worklog + tick.
-
----
-
## Standing risks & traps (read before every task)
- **Concurrent agents share this worktree.** Stage explicit paths only; re-check
@@ -354,6 +90,8 @@ correctly (against OpenAI if available) or are flagged for re-embed; nothing mix
REST API only.
- **Push to BOTH remotes** (`threeD`, `threews`); never pull/fetch from `threeD`.
The `threeD` mirror may 403 (gh account lacks write) — surface it, don't retry-loop.
+ Push with the gh credential helper if the embedded PAT fails:
+ `git -c credential.helper= -c credential.helper='!gh auth git-credential' push <url> main`.
- **Free tier ≠ infinite.** Credit-metered + rate-limited. Always leave the paid/other
lanes in the chain as backstops; never delete a working lane to "simplify".
- **$THREE is the only coin.** Applies to test fixtures and probe files too.
@@ -362,6 +100,8 @@ correctly (against OpenAI if available) or are flagged for re-embed; nothing mix
## Worklog (append-only; newest at top)
+- **2026-06-11** — Plan split into one self-contained prompt file per task
+ (00–42, linked in the checklist); paste a whole task file to a fresh agent to run it.
- **2026-06-11** — Plan created. Context: chat-side free-first failover (Groq → OpenRouter
multi-key → NVIDIA → paid backstop) shipped across llm.js, chat-models.js, api/chat.js,
brain/chat, widgets, agent-trade, tx/explain (uncommitted in worktree at time of