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(garment-forge): correct the worker README against the code and pin the Python taxonomy mirror with a test
nirholasf63dc8ba9fd8
diff --git a/prompts/swarm-100/worker-garment-forge.md b/prompts/swarm-100/worker-garment-forge.mddeleted file mode 100644index 2893e1395..000000000--- a/prompts/swarm-100/worker-garment-forge.md+++ /dev/null@@ -1,98 +0,0 @@-# Worker audit: workers/garment-forge--How to run: paste this file's repo path into a fresh Claude Code chat in this-repository and say "run this work order". This file is fully self-contained:-it depends on no other prompt file anywhere. If neighboring files in-prompts/swarm-100/ are gone, that work is done; if present, ignore them.-Every claim below rots; step 0 re-measures, and what you measure wins.--## Operating clause (binding)--- Read CLAUDE.md first. Its rules override everything, including this file.-- Finish 100% in this session. Never end the turn with a question, an option- list, or an unexecuted plan. A judgment call goes in one line of the final- report; it never becomes a question that halts work.-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real- funds or any irreversible on-chain write, git push or a production deploy,- committing content that references a crypto project other than $THREE, and- destroying unrecoverable data.-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no- commented-out code. Real APIs and real integrations only.-- The em-dash and en-dash characters are banned in everything you write.-- Concurrent agents share this worktree: stage explicit paths only (never a- bare add-everything), and commit finished work promptly.-- Before committing, run: npm run check:rules -- --paths <files you touched>.- It must exit 0.--## Step 0: re-derive the current state--1. Read workers/garment-forge/README.md and its build config (cloudbuild.yaml,- Dockerfile, package.json; whichever exist).-2. Is it deployed?-- export PATH="$HOME/google-cloud-sdk/bin:$PATH"- gcloud run services list --project aerial-vehicle-466722-p5 --region us-central1 | grep -i "garment-forge" || echo "not deployed as its own service"--3. If deployed: which commit is the running revision built from, and does main- contain fixes it has not picked up? A fix in main can sit undeployed for- days; never call a bug unfixed without checking the running revision.-4. Logs, last 24h, if deployed:-- gcloud logging read 'resource.type="cloud_run_revision" resource.labels.service_name="<service name from step 2>"' --freshness=24h --limit 100 --project aerial-vehicle-466722-p5--## Task: bring this worker to verified-healthy--1. README accuracy: what it does, how to run it, its inputs and outputs. Fix- every stale claim; a README that lies fails the audit.-2. Build it the way its own config says. The build must succeed from a clean- checkout of this worktree. Model workers that need weights stage them from- gs://three-ws-model-weights (staging weights is part of the job, not a- blocker).-3. Run its tests; add a smoke test if it has none that proves its core path.-4. If deployed: last 24h of logs free of unhandled errors; fix root causes in- code and commit. Redeploying is owner-gated: prepare everything so the- deploy is one command and say so in the report.-5. If not deployed by design: its README must state how and where it runs, and- that path must be verified locally.--## Definition of done--- [ ] Build succeeds from this worktree with the worker's own config.-- [ ] Tests pass, including at least one core-path smoke test.-- [ ] README verified accurate against the code.-- [ ] If deployed: running revision identified, 24h logs clean or root causes- fixed and committed (deploy itself flagged for the owner).-- [ ] npm run check:rules -- --paths <touched files> exits 0.--## Never blocked--| Blocker | Resolution (act, do not ask) |-|---|---|-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |-| Playwright browser missing | npx playwright install chromium |-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |--## Close out (required)--1. Verify every Definition of done line with the actual command output in- front of you. Never claim a line you did not verify.-2. Commit with explicit paths and a subject that describes the diff (house- style: type(scope): what changed and why a reader cares).-3. Delete this prompt file in that same commit:-- git rm prompts/swarm-100/worker-garment-forge.md-- The shrinking directory is this campaign's only progress ledger; there is- no progress log to update.-4. Final report: what step 0 measured, what changed (file list), evidence per- Definition of done line, and any one-line judgment calls. No trailing- questions, no unexecuted plans.--If a line genuinely cannot pass inside this session (an external party must-respond, or an owner-gated action is the final step), finish everything else,-leave this file in place, and state exactly which line remains and who owns-it. Never delete this file on a partial.diff --git a/tests/garment-forge-taxonomy-parity.test.js b/tests/garment-forge-taxonomy-parity.test.jsnew file mode 100644index 000000000..4ddf467e0--- /dev/null+++ b/tests/garment-forge-taxonomy-parity.test.js@@ -0,0 +1,149 @@+/**+ * garment-forge's Python mirror must equal the JS taxonomy it was copied from.+ *+ * Two gates decide whether a garment is usable, and they run in different+ * languages on different machines:+ *+ * PUBLISH workers/garment-forge/{canonical_bones,garment_glb}.py, in the+ * worker container, decides which slots exist, which regions a+ * manifest may occlude, and what coverage is acceptable.+ * WEAR src/garment-taxonomy.js + src/glb-canonicalize.js, in the+ * browser, decides the same things for attachGarment().+ *+ * The Python side is a hand-copied mirror with no import to keep it honest, so+ * a slot added, a region renamed, or a threshold nudged on the JS side leaves+ * the worker silently publishing manifests the runtime then refuses (or worse,+ * accepts while occluding the wrong body regions). Nothing catches that until+ * a catalog piece renders wrong on someone's avatar.+ *+ * This test is the missing link: it parses the Python literals as text (the+ * worker image has no Node, and the repo has no Python at test time, so text+ * is the only shared ground) and asserts value-for-value equality.+ *+ * When this fails, fix the PYTHON side: the JS files are the sources of truth+ * named in canonical_bones.py's own docstring.+ */++import { readFileSync } from 'node:fs';+import { describe, it, expect } from 'vitest';+import { CANONICAL_BONES } from '../src/glb-canonicalize.js';+import {+ GARMENT_SLOTS,+ BODY_REGIONS,+ REGION_BONES,+ SLOT_OCCLUDABLE,+ MIN_BIND_COVERAGE,+} from '../src/garment-taxonomy.js';+import { GARMENT_SPEC_URI } from '../src/garment-catalog.js';++const pySource = (name) => readFileSync(+ new URL(`../workers/garment-forge/${name}`, import.meta.url), 'utf8');++const BONES_PY = pySource('canonical_bones.py');+const GLB_PY = pySource('garment_glb.py');++/** Python source with `#` comments removed, so literals spanning commented+ * lines (SLOT_OCCLUDABLE carries a paragraph mid-dict) parse cleanly. String+ * literals here never contain `#`, so a naive strip is exact. */+function uncommented(source) {+ return source.split('\n').map((line) => line.replace(/#.*$/, '')).join('\n');+}++/** Body of `NAME = (...)` or `NAME = {...}`, brackets included. */+function literalOf(source, name, open, close) {+ const start = uncommented(source).indexOf(`\n${name} = ${open}`);+ expect(start, `${name} not found in the Python mirror`).toBeGreaterThan(-1);+ const text = uncommented(source).slice(start);+ let depth = 0;+ for (let i = text.indexOf(open); i < text.length; i += 1) {+ if (text[i] === open) depth += 1;+ else if (text[i] === close) {+ depth -= 1;+ if (depth === 0) return text.slice(text.indexOf(open), i + 1);+ }+ }+ throw new Error(`unterminated ${name} literal in the Python mirror`);+}++/** Strings of a flat Python tuple, in order. */+function pyTuple(source, name) {+ return [...literalOf(source, name, '(', ')').matchAll(/"([^"]*)"/g)].map((m) => m[1]);+}++/** Python `{"key": ("a", "b"), ...}` as a plain object of string arrays. */+function pyDictOfTuples(source, name) {+ const body = literalOf(source, name, '{', '}');+ const out = {};+ for (const entry of body.matchAll(/"([^"]+)"\s*:\s*\(([^)]*)\)/g)) {+ out[entry[1]] = [...entry[2].matchAll(/"([^"]*)"/g)].map((m) => m[1]);+ }+ return out;+}++/** Bare `NAME = <number>` assignment. */+function pyNumber(source, name) {+ const match = uncommented(source).match(new RegExp(`\\n${name} = (-?[0-9.]+)`));+ expect(match, `${name} not found in the Python mirror`).not.toBeNull();+ return Number(match[1]);+}++/** Bare `NAME = "<string>"` assignment. */+function pyString(source, name) {+ const match = uncommented(source).match(new RegExp(`\\n${name} = "([^"]*)"`));+ expect(match, `${name} not found in the Python mirror`).not.toBeNull();+ return match[1];+}++describe('garment-forge Python mirror matches the JS taxonomy', () => {+ it('mirrors CANONICAL_BONES in the same order', () => {+ expect(pyTuple(BONES_PY, 'CANONICAL_BONES')).toEqual([...CANONICAL_BONES]);+ });++ it('mirrors GARMENT_SLOTS in the same order', () => {+ expect(pyTuple(BONES_PY, 'GARMENT_SLOTS')).toEqual([...GARMENT_SLOTS]);+ });++ it('mirrors BODY_REGIONS in the same order', () => {+ expect(pyTuple(BONES_PY, 'BODY_REGIONS')).toEqual([...BODY_REGIONS]);+ });++ it('mirrors REGION_BONES region for region', () => {+ const py = pyDictOfTuples(BONES_PY, 'REGION_BONES');+ expect(Object.keys(py)).toEqual(Object.keys(REGION_BONES));+ for (const region of Object.keys(REGION_BONES)) {+ expect(py[region], `REGION_BONES.${region}`).toEqual([...REGION_BONES[region]]);+ }+ });++ it('mirrors SLOT_OCCLUDABLE slot for slot', () => {+ // The publish gate and the wear gate disagreeing here is the dangerous+ // case: the forge would stamp an `occludes` the closet then applies to+ // a different set of regions, deleting body parts under the garment.+ const py = pyDictOfTuples(GLB_PY, 'SLOT_OCCLUDABLE');+ expect(Object.keys(py).sort()).toEqual(Object.keys(SLOT_OCCLUDABLE).sort());+ for (const slot of Object.keys(SLOT_OCCLUDABLE)) {+ expect(py[slot], `SLOT_OCCLUDABLE.${slot}`).toEqual([...SLOT_OCCLUDABLE[slot]]);+ }+ });++ it('mirrors MIN_BIND_COVERAGE, the number both gates compare against', () => {+ expect(pyNumber(BONES_PY, 'MIN_BIND_COVERAGE')).toBe(MIN_BIND_COVERAGE);+ });++ it('stamps the spec URI the catalog consumer validates against', () => {+ expect(pyString(GLB_PY, 'SPEC_URI')).toBe(GARMENT_SPEC_URI);+ });++ it('declares every slot it can occlude for, and only real regions', () => {+ const py = pyDictOfTuples(GLB_PY, 'SLOT_OCCLUDABLE');+ for (const slot of pyTuple(BONES_PY, 'GARMENT_SLOTS')) {+ expect(py[slot], `no SLOT_OCCLUDABLE entry for slot ${slot}`).toBeDefined();+ }+ const regions = new Set(pyTuple(BONES_PY, 'BODY_REGIONS'));+ for (const [slot, allowed] of Object.entries(py)) {+ for (const region of allowed) {+ expect(regions.has(region), `${slot} may occlude unknown region ${region}`).toBe(true);+ }+ }+ });+});diff --git a/workers/garment-forge/README.md b/workers/garment-forge/README.mdindex 54e249649..df8e8103b 100644--- a/workers/garment-forge/README.md+++ b/workers/garment-forge/README.md@@ -121,14 +121,17 @@ POST /generate { prompt, slot, tier?, yaw_deg?, job_id? }→ 202 { job_id, status: "queued" }GET /jobs/:id → { job_id, status, stage, glb_url?, manifest_url?, thumb_url?,coverage?, occludes?, bones?, error?, updated_at }-GET /health → { ok, refbody_loaded, mesh_backends, rig_url, active_jobs }+GET /health → { ok, pipeline, refbody_loaded, mesh_backends, rig_url,+ active_jobs }+POST /sweep → { redriving, job_ids } (orphan recovery, see below)````slot` is one of `top, bottom, footwear, outerwear, hair, headwear, glasses,accessory`. `stage` walks `image → mesh → compose → rig → extract → validate→ publish` so pollers can show real progress. Job state is durable in GCS-(`garments/jobs/<id>.json`), so polls survive instance restarts and the-service scales to zero.+(`garment-jobs/<id>.json` in `GCS_BUCKET`, not the public catalog bucket), so+a POST and a later poll that land on different instances still see one record+and a reclaimed instance never takes a job with it.Example:@@ -162,11 +165,25 @@ gcloud builds submit --config workers/garment-forge/cloudbuild.yaml \```The build stages the reference body out of `public/avatars/` (the repo keeps-one copy), runs `test_garment_glb.py` as a build gate, and deploys the-`garment-forge` Cloud Run service (CPU only, scale-to-zero, runtime SA-`avatar-reconstruction-sa@`, `API_KEY` from the `avatar-reconstruction-key`-secret). The cloudbuild config pins the `three-ws-build@` service account,-as every build in this project must.+one copy), runs all three Python suites as build gates (see **Local tests**),+and deploys the `garment-forge` Cloud Run service: CPU only (4 vCPU, 16 GiB),+runtime SA `avatar-reconstruction-sa@`, `API_KEY` from the+`avatar-reconstruction-key` secret. The cloudbuild config pins the+`three-ws-build@` service account, as every build in this project must.++Three deploy settings are load-bearing and explained inline in+[cloudbuild.yaml](cloudbuild.yaml); do not "simplify" them away:++- **`--min-instances=1`, not scale-to-zero.** Jobs run as post-202 background+ work, so a scale-to-zero reclaim would kill a pipeline mid-flight. The+ durable queue below is the backstop for the reclaim windows that remain+ (deploys, crashes), not a licence to let the service idle away.+- **`--no-cpu-throttling`.** Throttled CPU starves a running job the moment+ pollers go quiet.+- **`--memory=16Gi`.** 8 GiB OOMed in production on 2026-08-07 (`8645 MiB+ used`, container killed on signal 9, taking the in-flight job with it). The+ ceiling has to cover `MAX_CONCURRENT`=2 pipelines at peak; 16 GiB is the+ most Cloud Run allows at `--cpu=4`.One-time infra the service depends on (already applied):@@ -213,11 +230,34 @@ what a stale record becomes.## Local tests (no GPU, no network)+All three run on a bare checkout and again inside `docker build`, so a+regression cannot ship. They need only the pinned `requirements.txt`; the+reference-image suite stubs the GCS/auth packages it does not touch when they+are absent, so real modules always win inside the container.+```bash-python3 workers/garment-forge/test_garment_glb.py # pure glTF pipeline-python3 workers/garment-forge/test_job_queue.py # durable-queue policy+python3 workers/garment-forge/test_garment_glb.py # 50 checks+python3 workers/garment-forge/test_job_queue.py # 22 checks+python3 workers/garment-forge/test_reference_image.py # 21 checks```+- **`test_garment_glb.py`** covers the pure glTF pipeline: canonicalization,+ placement math and the size envelope, composition, body-strip + buffer+ repack, coverage/occludes derivation, and each of the 6 manifest validation+ rules failing for its own reason.+- **`test_job_queue.py`** covers the durable-queue policy: who may claim a+ job, who may never be stolen, and what a stale record becomes.+- **`test_reference_image.py`** covers the Vertex re-roll: an empty draw is+ re-rolled, a refused prompt fails immediately with its block reason.++One more gate lives on the JS side and runs in `npm test`:+[tests/garment-forge-taxonomy-parity.test.js](../../tests/garment-forge-taxonomy-parity.test.js)+parses this worker's Python literals and asserts they still equal+`src/garment-taxonomy.js` and `src/glb-canonicalize.js`. The Python copies are+hand-mirrored across a language boundary with nothing importing anything, so+without it a slot or threshold changed on the runtime side would leave the+forge publishing manifests the closet refuses.+## Catalog quality audit`npm run audit:garments` sweeps the LIVE catalog: consumer validation, sha256,@@ -238,11 +278,6 @@ node scripts/audit-garments.mjs --avatars a.glb,b.glb # pick your own rigsBaseline 2026-07-27: 23 entries, all binding at 1.00 coverage on all fourrigs, 0 hard failures.-33 checks over the pure glTF pipeline: canonicalization, placement math,-composition, body-strip + buffer repack, coverage/occludes derivation, and-each of the 6 manifest validation rules failing for its own reason. The same-suite runs inside `docker build`, so a regression cannot ship.-## Environment| Var | Default | Meaning |@@ -261,6 +296,15 @@ suite runs inside `docker build`, so a regression cannot ship.| `GARMENT_YAW_DEG` | `0` | yaw applied to generator output before placement || `MESH_TIMEOUT_S` / `RIG_TIMEOUT_S` | `1200` / `600` | per-stage poll ceilings || `MAX_CONCURRENT` | `2` | parallel jobs per instance |+| `JOB_STALE_S` | `2700` | a record not advanced in this long lost its instance |+| `JOB_MAX_ATTEMPTS` | `3` | re-drives before a job is declared terminally failed |++Only the rows marked `(required)` or `(secret)` are set by+[cloudbuild.yaml](cloudbuild.yaml) plus `VERTEX_IMAGEN_*`, `VERTEX_IMAGE_SIZE`+and `MAX_CONCURRENT`; everything else runs on the default shown here. Setting+one on the live service is a config-only+`gcloud run services update garment-forge --region us-central1+--update-env-vars K=V` (never `--set-env-vars`, which replaces the whole set).## Provenance and licensingdiff --git a/workers/garment-forge/canonical_bones.py b/workers/garment-forge/canonical_bones.pyindex aaa5722dc..c0469fb9c 100644--- a/workers/garment-forge/canonical_bones.py+++ b/workers/garment-forge/canonical_bones.py@@ -5,9 +5,15 @@ CANONICAL_BONES / REGION_BONES / BODY_REGIONS / GARMENT_SLOTS are copiedverbatim from their JS sources of truth:- CANONICAL_BONES src/glb-canonicalize.js- - REGION_BONES / BODY_REGIONS src/avatar-garment.js- - GARMENT_SLOTS src/avatar-garment.js- - MIN_BIND_COVERAGE src/avatar-garment.js+ - REGION_BONES / BODY_REGIONS src/garment-taxonomy.js+ - GARMENT_SLOTS src/garment-taxonomy.js+ - MIN_BIND_COVERAGE src/garment-taxonomy.js++(src/avatar-garment.js only re-exports the four taxonomy constants for its+own consumers; edit them in src/garment-taxonomy.js.) Nothing imports across+the language boundary, so the copies are held together by+tests/garment-forge-taxonomy-parity.test.js, which parses these literals and+compares them value for value. If it fails, THIS file is the side to fix.canonicalize_bone_name() is deliberately a SUBSET of the JS canonicalizer:this worker controls its whole pipeline, and the only skeleton that ever