# Item `compositor`: offline portrait CLI ## Delivered (all inside the allowed paths) - `bin/render.cjs`: CLI `node bin/render.cjs [--root DIR] input.json output.png`. Writes the PNG and the `output.json` record beside it. Exit codes: 0 ok, 2 for validation, catalog, selector or missing-file errors (`render: E_CODE: …`, nothing written), 64 for usage, 1 for internal errors. - `src/compositor/catalog.cjs`: loads `catalog/*.json` (`kekborn-assets@1`) in file-name order. Validates `id/slot/path/tier?/category?/rarity?/requiresEyes?`, checks for unique IDs and that paths stay inside the root, and confirms every `requiresEyes` target exists. Gives tier/category filtering with ID-sorted candidate lists. - `src/compositor/select.cjs`: input validation. Seed = SHA-256(UTF-8 wallet ‖ UTF-8 artSeed). Default picks use labelled, rarity-weighted draws. Explicit full IDs work for genetics.skin/eyes and traits.expression/background/banner. requiresEyes is resolved before eyes are picked, and `E_INCOMPATIBLE` flags explicit choices that conflict. Stack order follows the brief, with procedural banner-arms and rail-arms entries. - `src/compositor/index.cjs`: `renderPortrait(input,{root,raster?,heraldry?})`. Checks that every file exists and is 2048×2560 before painting. Calls `buildArms(seedBytes,{root})`, composites the arms at (1500,340,240,288) and (974,2404,100,120), decodes layers into one reused scratch buffer, runs `finish` once, then `encodePNG`. Builds the record: input, lowercase seed hex, ordered layers with id/path/sha256/placement/source, procedural entries with the arms image hash, arms choices, part paths and hashes, both placements, and pngSha256. - `test/compositor/fixtures.cjs`, `test/compositor/render.test.cjs`: 10 tests that run against a private fixture root in the OS temp dir. The root holds 24 catalog assets across 2 catalog files, full-canvas PNGs, a stub heraldry module and a shim to the real raster module. - `docs/render.md`: input, seed and draw rules, catalog format, stack, requiresEyes, arms contract, record format, exit codes. ## Checks run - `node --test test/compositor/render.test.cjs`: **10 pass, 0 fail** (about 7 s). The tests cover: - known seed vectors, including non-ASCII and case-sensitive input - draws that are stable and roughly uniform - CLI end to end: PNG decodes at 2048×2560, the record hashes match the files, stack order is right, the tier frame, crown and category robe are picked, the arms colour shows in the banner reserve - usage and input errors (exit 64/2, no output written) - explicit selectors, plus wrong-slot, tier-filtered and unknown IDs - tier/category filtering, optional headwear, missing required frame - side-eye: forced eyes, explicit incompatible eyes rejected, default draws stay compatible - unknown ID and missing layer, heraldry part, heraldry module, bad catalog schema and wrong-size layer, all through the CLI - a spy raster checking one reused decode buffer, composite rects equal to the recorded placements, arms rects, and that `finish` runs once, after the last composite and before `encode`, with the seed bytes - two independent CLI processes on separate fixture roots give byte-identical PNG and JSON, and a different artSeed gives a different PNG - `node --test test/raster/core.test.cjs`: 8 pass. That module is unchanged. - `node bin/render.cjs test/scratch/in.json test/scratch/o.png` on the real checkout fails cleanly with exit 2: `E_MISSING_FILE: Heraldry module not found at …/src/heraldry/index.cjs`. This is expected: heraldry and the catalog have not been merged yet. ## Integration limits and remaining defects - Nothing was rendered against the real library. `src/heraldry/index.cjs` and `catalog/*.json` come from other items of this wave and are missing from this checkout. The CLI was only exercised on fixtures. - Assumptions other items must match: - slot names: `background, banner, prop-rear, attire-back, skin, eyes, expression, attire-front, accessory, headwear, regalia, prop-front, frame`. Records with any other slot are ignored. - tier and category values in lowercase (tiers common…legendary, categories scholar/antiquary/knight/artisan/seer/council). - every layer is a full-canvas 2048×2560 PNG. - `buildArms` returns a raster image, and `usedLayers` is a list of root-relative paths (or objects with `path`) to existing files. - Headwear and regalia are skipped when no asset fits the tier (Common may have none). Background, banner, skin, eyes, expression and frame are required. - Rarity weights (8/4/2/1/1) are my own choice; the brief left them open. Change them in `WEIGHTS` in `select.cjs`.