@ikijs/mcp 0.31.1 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2236,6 +2236,83 @@ function pop(v) {
2236
2236
  }
2237
2237
  return most / mean;
2238
2238
  }
2239
+ var NOD_TURNS = [-30, 0, 30];
2240
+ var NOD_PARTS = [
2241
+ "face",
2242
+ "eye_L",
2243
+ "eye_R",
2244
+ "iris_L",
2245
+ "iris_R",
2246
+ "nose",
2247
+ "lip_upper",
2248
+ "mouth"
2249
+ ];
2250
+ var NOD_ENDS = [0, -LADDER_MIN, LADDER_MAX - LADDER_MIN];
2251
+ function checkNod(model) {
2252
+ const face = model.parts.find((p) => p.id === "face");
2253
+ if (!face) return { unavailable: "no face part" };
2254
+ const hasEyes = ["eye_L", "eye_R"].every(
2255
+ (id) => model.parts.some((p) => p.id === id)
2256
+ );
2257
+ if (!hasEyes) return { unavailable: "no eye_L and eye_R parts" };
2258
+ const fw = face.width;
2259
+ const ladders = NOD_TURNS.map(
2260
+ (x) => Array.from(
2261
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2262
+ (_, i) => landParts(
2263
+ model,
2264
+ { ParamAngleX: x, ParamAngleY: LADDER_MIN + i },
2265
+ NOD_PARTS
2266
+ )
2267
+ )
2268
+ );
2269
+ const has = (id) => ladders[0][0].has(id);
2270
+ const boxes = (id) => ladders.map((ladder) => ladder.map((l) => box(l.get(id), fw)));
2271
+ const spread = (v) => Math.max(...v) - Math.min(...v);
2272
+ const ranges = (values) => {
2273
+ const [m30, zero, p30] = NOD_TURNS.map(
2274
+ (_, b) => spread(
2275
+ Array.from(
2276
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2277
+ (_2, i) => values(b, i)
2278
+ )
2279
+ )
2280
+ );
2281
+ return { m30, zero, p30 };
2282
+ };
2283
+ const gap = (l, r) => {
2284
+ const bl = boxes(l);
2285
+ const br = boxes(r);
2286
+ return ranges((b, i) => br[b][i].x - bl[b][i].x);
2287
+ };
2288
+ const nod = [{ id: "eyes", range: gap("eye_L", "eye_R") }];
2289
+ if (has("iris_L") && has("iris_R")) {
2290
+ nod.push({ id: "irises", range: gap("iris_L", "iris_R") });
2291
+ }
2292
+ const mouthId = has("lip_upper") ? "lip_upper" : has("mouth") ? "mouth" : null;
2293
+ if (mouthId) {
2294
+ const bm = boxes(mouthId);
2295
+ nod.push({ id: "mouth", range: ranges((b, i) => bm[b][i].width) });
2296
+ }
2297
+ const corner = ["eye_L", "eye_R", "nose"].filter(has).map((id) => {
2298
+ const b = boxes(id);
2299
+ const at = (t, j) => b[t][NOD_ENDS[j]];
2300
+ const residual = (t, j) => {
2301
+ const r = (axis) => at(t, j)[axis] - at(t, 1)[axis] - at(1, j)[axis] + at(1, 1)[axis];
2302
+ return Math.max(Math.abs(r("x")), Math.abs(r("y")));
2303
+ };
2304
+ return {
2305
+ id,
2306
+ residual: {
2307
+ mm: residual(0, 0),
2308
+ mp: residual(0, 2),
2309
+ pm: residual(2, 0),
2310
+ pp: residual(2, 2)
2311
+ }
2312
+ };
2313
+ });
2314
+ return { unit: "fw", faceWidth: fw, nod, corner };
2315
+ }
2239
2316
  function checkSweep(model) {
2240
2317
  const face = model.parts.find((p) => p.id === "face");
2241
2318
  if (!face) return { preset: "turn", unavailable: "no face part" };
@@ -2305,6 +2382,19 @@ function formatSweepReport(report) {
2305
2382
  `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2306
2383
  ];
2307
2384
  }
2385
+ function formatNodReport(report) {
2386
+ if ("unavailable" in report) {
2387
+ return [`SWEEP nod: unavailable \u2014 ${report.unavailable}`];
2388
+ }
2389
+ return [
2390
+ ...report.nod.map(
2391
+ ({ id, range: r }) => `SWEEP nod ${id}: ${id === "mouth" ? "width" : "gap"} range X -30 ${fw3(r.m30)} / 0 ${fw3(r.zero)} / +30 ${fw3(r.p30)} fw`
2392
+ ),
2393
+ ...report.corner.map(
2394
+ ({ id, residual: r }) => `SWEEP corner ${id}: residual (-30,-30) ${fw3(r.mm)} / (-30,+30) ${fw3(r.mp)} / (+30,-30) ${fw3(r.pm)} / (+30,+30) ${fw3(r.pp)} fw`
2395
+ )
2396
+ ];
2397
+ }
2308
2398
 
2309
2399
  // src/sweep.ts
2310
2400
  var import_node_fs3 = __toESM(require("fs"));
@@ -2312,6 +2402,8 @@ var import_node_path3 = __toESM(require("path"));
2312
2402
  var SWEEP_CLOCK_HZ = 60;
2313
2403
  var SWEEP_FPS = 30;
2314
2404
  var SWEEP_DURATION_S = 3;
2405
+ var BOX_DURATION_S = 6;
2406
+ var SWEEP_PRESETS = ["turn", "turn-nod"];
2315
2407
  var SWEEP_WARMUP_S = 0.5;
2316
2408
  var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2317
2409
  var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
@@ -2319,16 +2411,75 @@ var SHEET_MAX_SIDE = 2e3;
2319
2411
  var SHEET_MARGIN = 8;
2320
2412
  var SHEET_LABEL_BAND = 24;
2321
2413
  var KYMOGRAPH_BAND = 3;
2322
- var SWEEP_PARAMETER = "ParamAngleX";
2323
- var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2324
2414
  var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2325
- var FRAMES = STEPS / CAPTURE_EVERY;
2326
2415
  var LEG_FROM_S = 0.75;
2327
2416
  var LEG_TO_S = 2.25;
2328
2417
  var AMPLITUDE_DEG = 30;
2418
+ var BOX_CORNERS = [
2419
+ [0, 0],
2420
+ [0, -30],
2421
+ [-30, -30],
2422
+ [-30, 30],
2423
+ [30, 30],
2424
+ [30, -30],
2425
+ [0, -30],
2426
+ [0, 0]
2427
+ ];
2428
+ var BOX_SPEED_DEG_S = 50;
2429
+ var BOX_SHEET_STOPS = [
2430
+ [-30, 30],
2431
+ [0, 30],
2432
+ [30, 30],
2433
+ [-30, 0],
2434
+ [0, 0],
2435
+ [30, 0],
2436
+ [-30, -30],
2437
+ [0, -30],
2438
+ [30, -30]
2439
+ ];
2329
2440
  function turnTheta(t) {
2330
2441
  return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2331
2442
  }
2443
+ function boxAngles(t) {
2444
+ let start = 0;
2445
+ for (let i = 0; i + 1 < BOX_CORNERS.length; i++) {
2446
+ const [fx, fy] = BOX_CORNERS[i];
2447
+ const [tx, ty] = BOX_CORNERS[i + 1];
2448
+ const len = Math.max(Math.abs(tx - fx), Math.abs(ty - fy));
2449
+ const dur = len / BOX_SPEED_DEG_S;
2450
+ if (t < start + dur) {
2451
+ const u = (t - start) / dur;
2452
+ const e = (1 - Math.cos(Math.PI * u)) / 2;
2453
+ return { x: fx + (tx - fx) * e, y: fy + (ty - fy) * e };
2454
+ }
2455
+ start += dur;
2456
+ }
2457
+ return { x: 0, y: 0 };
2458
+ }
2459
+ function sweepDurationS(preset) {
2460
+ return preset === "turn" ? SWEEP_DURATION_S : BOX_DURATION_S;
2461
+ }
2462
+ function schedule(preset) {
2463
+ const durationS = sweepDurationS(preset);
2464
+ const n = SWEEP_CLOCK_HZ * durationS;
2465
+ if (preset === "turn") {
2466
+ return {
2467
+ parameters: ["ParamAngleX"],
2468
+ steps: Array.from({ length: n }, (_, j) => ({
2469
+ ParamAngleX: turnTheta(j / SWEEP_CLOCK_HZ)
2470
+ })),
2471
+ durationS
2472
+ };
2473
+ }
2474
+ return {
2475
+ parameters: ["ParamAngleX", "ParamAngleY"],
2476
+ steps: Array.from({ length: n }, (_, j) => {
2477
+ const { x, y } = boxAngles(j / SWEEP_CLOCK_HZ);
2478
+ return { ParamAngleX: x, ParamAngleY: y };
2479
+ }),
2480
+ durationS
2481
+ };
2482
+ }
2332
2483
  function eyeRowModelPx(model) {
2333
2484
  const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2334
2485
  const l = landed.get("eye_L");
@@ -2353,35 +2504,44 @@ function physicsOutputIds(model) {
2353
2504
  }
2354
2505
  return [...ids];
2355
2506
  }
2356
- function sheetFrames(thetas) {
2507
+ function turnSheetFrames(steps, frames) {
2357
2508
  const onLeg = [];
2358
- for (let k = 0; k < FRAMES; k++) {
2509
+ for (let k = 0; k < frames; k++) {
2359
2510
  const t = k / SWEEP_FPS;
2360
2511
  if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2361
2512
  }
2513
+ const x = (k) => steps[CAPTURE_EVERY * k].ParamAngleX;
2362
2514
  const picked = [];
2363
2515
  for (const target2 of SHEET_THETAS) {
2364
2516
  let best = onLeg[0];
2365
2517
  for (const k of onLeg) {
2366
- if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2367
- best = k;
2368
- }
2518
+ if (Math.abs(x(k) - target2) < Math.abs(x(best) - target2)) best = k;
2369
2519
  }
2370
2520
  if (!picked.includes(best)) picked.push(best);
2371
2521
  }
2372
2522
  return picked.sort((a, b) => a - b);
2373
2523
  }
2374
- function sheetLabel(theta, t) {
2375
- const rounded = Math.round(theta * 10) / 10 + 0;
2524
+ function boxSheetFrames(steps, frames) {
2525
+ return BOX_SHEET_STOPS.map(([sx, sy]) => {
2526
+ const miss = (k) => {
2527
+ const s = steps[CAPTURE_EVERY * k];
2528
+ return Math.abs(s.ParamAngleX - sx) + Math.abs(s.ParamAngleY - sy);
2529
+ };
2530
+ let best = 0;
2531
+ for (let k = 1; k < frames; k++) {
2532
+ if (miss(k) < miss(best)) best = k;
2533
+ }
2534
+ return best;
2535
+ });
2536
+ }
2537
+ function signedDeg(angle) {
2538
+ const rounded = Math.round(angle * 10) / 10 + 0;
2376
2539
  const deg = rounded.toFixed(1);
2377
- const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2378
- return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2540
+ return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2379
2541
  }
2380
- function sweepSpec(model, crop) {
2381
- const thetas = Array.from(
2382
- { length: STEPS },
2383
- (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2384
- );
2542
+ function sweepSpec(model, preset, crop) {
2543
+ const { parameters, steps, durationS } = schedule(preset);
2544
+ const frameCount = durationS * SWEEP_FPS;
2385
2545
  const dw = crop ? crop.dw : BUST_SIZE;
2386
2546
  const dh = crop ? crop.dh : BUST_SIZE;
2387
2547
  const m = SHEET_MARGIN;
@@ -2391,29 +2551,38 @@ function sweepSpec(model, crop) {
2391
2551
  (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2392
2552
  (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2393
2553
  );
2394
- const frames = sheetFrames(thetas);
2554
+ const frames = preset === "turn" ? turnSheetFrames(steps, frameCount) : boxSheetFrames(steps, frameCount);
2555
+ const labelOf = (k) => {
2556
+ const s = steps[CAPTURE_EVERY * k];
2557
+ const t = (k / SWEEP_FPS).toFixed(2);
2558
+ return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
2559
+ };
2395
2560
  const { width: W, height: H } = model.canvas;
2396
- const yModel = eyeRowModelPx(model);
2397
- let row = Math.round(dh / 2);
2398
- let at = "middle";
2399
- if (yModel !== void 0) {
2400
- const y0 = bustPadY(W, H);
2401
- const s = BUST_SIZE / W;
2402
- const eyeRow = Math.round(
2403
- crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2404
- );
2405
- if (eyeRow >= 1 && eyeRow <= dh - 2) {
2406
- row = eyeRow;
2407
- at = "eye row";
2561
+ let kymograph;
2562
+ if (preset === "turn") {
2563
+ const yModel = eyeRowModelPx(model);
2564
+ let row = Math.round(dh / 2);
2565
+ let at = "middle";
2566
+ if (yModel !== void 0) {
2567
+ const y0 = bustPadY(W, H);
2568
+ const s = BUST_SIZE / W;
2569
+ const eyeRow = Math.round(
2570
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2571
+ );
2572
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2573
+ row = eyeRow;
2574
+ at = "eye row";
2575
+ }
2408
2576
  }
2577
+ kymograph = { row, band: KYMOGRAPH_BAND, at };
2409
2578
  }
2410
2579
  return {
2411
- parameter: SWEEP_PARAMETER,
2580
+ parameters,
2412
2581
  frameMs: SWEEP_FRAME_MS,
2413
2582
  warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2414
- thetas,
2583
+ steps,
2415
2584
  captureEvery: CAPTURE_EVERY,
2416
- frames: FRAMES,
2585
+ frames: frameCount,
2417
2586
  frame: { width: dw, height: dh },
2418
2587
  physicsOutputs: physicsOutputIds(model),
2419
2588
  sheet: {
@@ -2424,11 +2593,9 @@ function sweepSpec(model, crop) {
2424
2593
  },
2425
2594
  margin: m,
2426
2595
  labelBand: b,
2427
- labels: frames.map(
2428
- (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2429
- )
2596
+ labels: frames.map(labelOf)
2430
2597
  },
2431
- kymograph: { row, band: KYMOGRAPH_BAND, at },
2598
+ kymograph,
2432
2599
  crop
2433
2600
  };
2434
2601
  }
@@ -2438,7 +2605,7 @@ function flipbookHtml(manifest) {
2438
2605
  <html lang="en">
2439
2606
  <head>
2440
2607
  <meta charset="utf-8">
2441
- <title>turn sweep</title>
2608
+ <title>${manifest.preset} sweep</title>
2442
2609
  <style>
2443
2610
  body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2444
2611
  .row { display: flex; gap: 16px; align-items: flex-start; }
@@ -2471,13 +2638,18 @@ img { max-width: 48vw; height: auto; background: #444; }
2471
2638
  var playing = true;
2472
2639
  scrub.max = String(n - 1);
2473
2640
  if (b) { bi.style.display = "block"; }
2641
+ function short(id) {
2642
+ return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
2643
+ }
2474
2644
  function show(k) {
2475
2645
  i = k;
2476
2646
  var f = m.frames[k];
2477
2647
  a.src = f.file;
2478
2648
  if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2479
2649
  scrub.value = String(k);
2480
- readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2650
+ readout.textContent = "frame " + k + m.parameters.map(function (id) {
2651
+ return " " + short(id) + " " + f.values[id].toFixed(1) + "\\u00b0";
2652
+ }).join("") + " t " + f.t.toFixed(2) + " s";
2481
2653
  }
2482
2654
  play.addEventListener("click", function () {
2483
2655
  playing = !playing;
@@ -2496,7 +2668,14 @@ img { max-width: 48vw; height: auto; background: #444; }
2496
2668
  </html>
2497
2669
  `;
2498
2670
  }
2499
- function prepareSweepDir(outDir, name) {
2671
+ var STALE_FILE = /^f\d{3}\.png$/;
2672
+ var STALE_NAMES = [
2673
+ "kymograph.png",
2674
+ "sheet.png",
2675
+ "manifest.json",
2676
+ "index.html"
2677
+ ];
2678
+ function prepareSweepDir(outDir, name, label) {
2500
2679
  const dir = import_node_path3.default.join(outDir, name);
2501
2680
  try {
2502
2681
  import_node_fs3.default.mkdirSync(dir);
@@ -2507,13 +2686,19 @@ function prepareSweepDir(outDir, name) {
2507
2686
  }
2508
2687
  const stat = import_node_fs3.default.lstatSync(dir);
2509
2688
  if (stat.isSymbolicLink()) {
2510
- throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2689
+ throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
2511
2690
  }
2512
2691
  if (!stat.isDirectory()) {
2513
- throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2692
+ throw new AutoRigInputError(`${label}.name names ${dir}, not a directory`);
2693
+ }
2694
+ return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2695
+ }
2696
+ function clearSweepDir(real) {
2697
+ for (const entry of import_node_fs3.default.readdirSync(real)) {
2698
+ if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
2699
+ import_node_fs3.default.rmSync(import_node_path3.default.join(real, entry));
2700
+ }
2514
2701
  }
2515
- const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2516
- return real;
2517
2702
  }
2518
2703
 
2519
2704
  // src/render-poses.ts
@@ -2526,7 +2711,7 @@ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2526
2711
  function bustPadY(width, height) {
2527
2712
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2528
2713
  }
2529
- function planRenders(model, requested, sweep) {
2714
+ function planRenders(model, requested, sweep, sweeps) {
2530
2715
  const { width: W, height: H } = model.canvas;
2531
2716
  const fullBody = H > W;
2532
2717
  const canvas = fullBody ? {
@@ -2581,12 +2766,37 @@ function planRenders(model, requested, sweep) {
2581
2766
  dh
2582
2767
  };
2583
2768
  };
2584
- if (sweep && !SWEEP_NAME.test(sweep.name)) {
2585
- throw new AutoRigInputError(
2586
- `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2587
- );
2769
+ if (sweeps && sweeps.length === 0) {
2770
+ throw new AutoRigInputError("sweeps is empty");
2588
2771
  }
2589
- const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2772
+ const asked = [
2773
+ ...sweep ? [{ label: "sweep", entry: sweep }] : [],
2774
+ ...(sweeps ?? []).map((entry, i) => ({ label: `sweeps[${i}]`, entry }))
2775
+ ];
2776
+ asked.forEach(({ label, entry }, i) => {
2777
+ if (!SWEEP_NAME.test(entry.name)) {
2778
+ throw new AutoRigInputError(
2779
+ `${label}.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(entry.name)}`
2780
+ );
2781
+ }
2782
+ const sameName = asked.findIndex(
2783
+ (a) => a.entry.name.toLowerCase() === entry.name.toLowerCase()
2784
+ );
2785
+ if (sameName < i) {
2786
+ throw new AutoRigInputError(
2787
+ `${label}.name ${JSON.stringify(entry.name)} repeats ${asked[sameName].label}.name ${JSON.stringify(asked[sameName].entry.name)} (ignoring case: one directory on a case-insensitive disk)`
2788
+ );
2789
+ }
2790
+ const samePreset = asked.findIndex((a) => a.entry.preset === entry.preset);
2791
+ if (samePreset < i) {
2792
+ throw new AutoRigInputError(
2793
+ `${label}.preset ${JSON.stringify(entry.preset)} repeats ${asked[samePreset].label}.preset (the same frames twice)`
2794
+ );
2795
+ }
2796
+ });
2797
+ const cropOf = (entry, label) => entry.crop ? toRenderCrop(entry.crop, `${label}.crop`) : squareCrop;
2798
+ const sweepCrop = sweep ? cropOf(sweep, "sweep") : void 0;
2799
+ const sweepsCrops = sweeps?.map((entry, i) => cropOf(entry, `sweeps[${i}]`));
2590
2800
  if (requested) {
2591
2801
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2592
2802
  const poses2 = requested.map((pose, i) => {
@@ -2598,7 +2808,7 @@ function planRenders(model, requested, sweep) {
2598
2808
  crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2599
2809
  };
2600
2810
  });
2601
- return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2811
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop, sweepsCrops };
2602
2812
  }
2603
2813
  const bodyAngles = Object.fromEntries(
2604
2814
  [
@@ -2706,7 +2916,7 @@ function planRenders(model, requested, sweep) {
2706
2916
  );
2707
2917
  }
2708
2918
  }
2709
- return { canvas, view, fullBody, mouth, poses, sweepCrop };
2919
+ return { canvas, view, fullBody, mouth, poses, sweepCrop, sweepsCrops };
2710
2920
  }
2711
2921
  function checkRequest(requested, i) {
2712
2922
  const { name, values } = requested[i];
@@ -2746,8 +2956,8 @@ function readPageScript() {
2746
2956
  );
2747
2957
  }
2748
2958
  }
2749
- async function captureSweep(evaluate, model, plan, requested, dir, report) {
2750
- const spec = sweepSpec(model, plan.sweepCrop);
2959
+ async function captureSweep(evaluate, model, requested, crop, dir, report, nod) {
2960
+ const spec = sweepSpec(model, requested.preset, crop);
2751
2961
  await evaluate(
2752
2962
  `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2753
2963
  CAPTURE_MS
@@ -2772,12 +2982,12 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2772
2982
  i: k,
2773
2983
  file,
2774
2984
  t: k / SWEEP_FPS,
2775
- theta: spec.thetas[spec.captureEvery * k],
2776
2985
  values
2777
2986
  });
2778
2987
  }
2779
2988
  const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2780
2989
  for (const [what, url] of Object.entries(end)) {
2990
+ if (url === void 0) continue;
2781
2991
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2782
2992
  throw new Error(
2783
2993
  `sweep ${requested.name} ${what}: the page returned no PNG`
@@ -2785,26 +2995,29 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2785
2995
  }
2786
2996
  }
2787
2997
  const sheet = import_node_path4.default.join(dir, "sheet.png");
2788
- const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2789
2998
  writeFileAtomic(
2790
2999
  sheet,
2791
3000
  Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2792
3001
  );
2793
- writeFileAtomic(
2794
- kymograph,
2795
- Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2796
- );
3002
+ let kymograph;
3003
+ if (end.kymograph !== void 0) {
3004
+ kymograph = import_node_path4.default.join(dir, "kymograph.png");
3005
+ writeFileAtomic(
3006
+ kymograph,
3007
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
3008
+ );
3009
+ }
2797
3010
  const manifest = {
2798
- version: 1,
3011
+ version: 2,
2799
3012
  preset: requested.preset,
2800
- parameter: spec.parameter,
3013
+ parameters: spec.parameters,
2801
3014
  fps: SWEEP_FPS,
2802
3015
  clockHz: SWEEP_CLOCK_HZ,
2803
3016
  warmupS: SWEEP_WARMUP_S,
2804
- durationS: SWEEP_DURATION_S,
3017
+ durationS: sweepDurationS(requested.preset),
2805
3018
  crop: requested.crop ?? null,
2806
3019
  frame: spec.frame,
2807
- kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
3020
+ kymographRow: spec.kymograph ? { row: spec.kymograph.row, at: spec.kymograph.at } : null,
2808
3021
  sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2809
3022
  physicsOutputs: spec.physicsOutputs,
2810
3023
  frames
@@ -2821,9 +3034,10 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2821
3034
  frames: spec.frames,
2822
3035
  manifest: manifestPath,
2823
3036
  sheet,
2824
- kymograph,
3037
+ ...kymograph ? { kymograph } : {},
2825
3038
  flipbook,
2826
- report
3039
+ report,
3040
+ nod
2827
3041
  };
2828
3042
  }
2829
3043
  async function renderPoses(input) {
@@ -2836,7 +3050,7 @@ async function renderPoses(input) {
2836
3050
  );
2837
3051
  const outDir = resolveOutputDir(input.outDir);
2838
3052
  const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2839
- const plan = planRenders(model, input.poses, input.sweep);
3053
+ const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
2840
3054
  const browser = findBrowser();
2841
3055
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2842
3056
  const pageScript = readPageScript();
@@ -2845,9 +3059,16 @@ async function renderPoses(input) {
2845
3059
  input.poses?.map((p) => p.values)
2846
3060
  );
2847
3061
  const physics = checkPhysics(model);
2848
- const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2849
- const sweepReport = input.sweep ? checkSweep(model) : void 0;
2850
- const { failedTextures, poses, sweep } = await withBrowser(
3062
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name, "sweep") : void 0;
3063
+ const sweepsDirs = input.sweeps?.map(
3064
+ (s, i) => prepareSweepDir(outDir, s.name, `sweeps[${i}]`)
3065
+ );
3066
+ for (const d of [sweepDir, ...sweepsDirs ?? []]) {
3067
+ if (d) clearSweepDir(d);
3068
+ }
3069
+ const sweepReport = input.sweep || input.sweeps ? checkSweep(model) : void 0;
3070
+ const nodReport = input.sweep || input.sweeps ? checkNod(model) : void 0;
3071
+ const { failedTextures, poses, sweep, sweeps } = await withBrowser(
2851
3072
  browser,
2852
3073
  async (evaluate) => {
2853
3074
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2871,15 +3092,38 @@ async function renderPoses(input) {
2871
3092
  );
2872
3093
  written.push({ name: pose.name, path: file });
2873
3094
  }
2874
- const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
3095
+ const sweep2 = input.sweep && sweepDir && sweepReport && nodReport ? await captureSweep(
2875
3096
  evaluate,
2876
3097
  model,
2877
- plan,
2878
3098
  input.sweep,
3099
+ plan.sweepCrop,
2879
3100
  sweepDir,
2880
- sweepReport
3101
+ sweepReport,
3102
+ nodReport
2881
3103
  ) : void 0;
2882
- return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
3104
+ let sweeps2;
3105
+ if (input.sweeps && sweepsDirs && sweepReport && nodReport) {
3106
+ sweeps2 = [];
3107
+ for (const [i, requested] of input.sweeps.entries()) {
3108
+ sweeps2.push(
3109
+ await captureSweep(
3110
+ evaluate,
3111
+ model,
3112
+ requested,
3113
+ plan.sweepsCrops?.[i],
3114
+ sweepsDirs[i],
3115
+ sweepReport,
3116
+ nodReport
3117
+ )
3118
+ );
3119
+ }
3120
+ }
3121
+ return {
3122
+ failedTextures: loaded.failedTextures,
3123
+ poses: written,
3124
+ sweep: sweep2,
3125
+ sweeps: sweeps2
3126
+ };
2883
3127
  }
2884
3128
  );
2885
3129
  return {
@@ -2893,7 +3137,8 @@ async function renderPoses(input) {
2893
3137
  modelCanvas: model.canvas,
2894
3138
  folds,
2895
3139
  physics,
2896
- sweep
3140
+ sweep,
3141
+ sweeps
2897
3142
  };
2898
3143
  } catch (error) {
2899
3144
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -3464,7 +3709,7 @@ async function autoRigFromLayers(input) {
3464
3709
  var import_node_fs7 = __toESM(require("fs"));
3465
3710
  var import_node_path10 = __toESM(require("path"));
3466
3711
  var import_sharp4 = __toESM(require("sharp"));
3467
- var import_editor12 = require("@ikijs/editor");
3712
+ var import_editor13 = require("@ikijs/editor");
3468
3713
 
3469
3714
  // src/trim.ts
3470
3715
  var import_editor4 = require("@ikijs/editor");
@@ -3607,8 +3852,184 @@ function capWarning(arm, g, body) {
3607
3852
  return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px) \u2014 a gap opens beside the shoulder once the arm raises. Move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
3608
3853
  }
3609
3854
 
3610
- // src/measure-forearm-pose.ts
3855
+ // src/measure-hair-side.ts
3611
3856
  var import_editor6 = require("@ikijs/editor");
3857
+ var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
3858
+ var VISIBLE_MIN_PX = 3;
3859
+ var LEAN_HH = 0.12;
3860
+ var TWO_LOCKS_RUN = 0.25;
3861
+ var TWO_LOCKS_GAP = 0.1;
3862
+ function covers(runs, x) {
3863
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3864
+ if (x >= runs[i] && x < runs[i + 1]) return true;
3865
+ }
3866
+ return false;
3867
+ }
3868
+ function runsAt(layer, y) {
3869
+ return layer?.rowRuns?.[y - layer.bbox.y] ?? [];
3870
+ }
3871
+ function opaqueRows(layer) {
3872
+ const runs = layer.rowRuns ?? [];
3873
+ const top = runs.findIndex((r) => r.length > 0);
3874
+ if (top < 0) return void 0;
3875
+ let bottom = runs.length - 1;
3876
+ while (runs[bottom].length === 0) bottom--;
3877
+ return { top: layer.bbox.y + top, bottom: layer.bbox.y + bottom };
3878
+ }
3879
+ async function hairSideWarnings(absDir, layers) {
3880
+ const present = LOCK_ROLES.filter((r) => layers[r] !== void 0);
3881
+ if (present.length === 0) return [];
3882
+ const warnings = [];
3883
+ if (layers.hair_front === void 0) {
3884
+ for (const role of present) {
3885
+ warnings.push(
3886
+ `${role}: needs hair_front \u2014 the rig refuses a lock without the bangs its root hides under. Remove hair_side.png and recompose (free), or draw hair_front.png. Billed.`
3887
+ );
3888
+ }
3889
+ return warnings;
3890
+ }
3891
+ const ref = layers.hair_front;
3892
+ let mismatched = false;
3893
+ for (const r of [...present, "hair_back", "face"]) {
3894
+ const stats = layers[r];
3895
+ if (stats === void 0) continue;
3896
+ if (stats.canvasW !== ref.canvasW || stats.canvasH !== ref.canvasH) {
3897
+ mismatched = true;
3898
+ warnings.push(
3899
+ `${r}: its canvas ${stats.canvasW}x${stats.canvasH} differs from hair_front's ${ref.canvasW}x${ref.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
3900
+ );
3901
+ }
3902
+ }
3903
+ if (mismatched) return warnings;
3904
+ const measurer = (0, import_editor6.createLayerSetMeasurer)({
3905
+ width: ref.canvasW,
3906
+ height: ref.canvasH
3907
+ });
3908
+ const read = (role) => layers[role] === void 0 ? void 0 : measured(measurer, absDir, role);
3909
+ const front = await read("hair_front");
3910
+ const back = await read("hair_back");
3911
+ const face = await read("face");
3912
+ const axisX = face ? face.bbox.x + face.bbox.w / 2 : ref.canvasW / 2;
3913
+ const locks = /* @__PURE__ */ new Map();
3914
+ for (const role of present) {
3915
+ const lock = await measured(measurer, absDir, role);
3916
+ locks.set(role, lock);
3917
+ const side = lock.bbox.x + lock.bbox.w / 2 < axisX ? -1 : 1;
3918
+ const eyeRole = ["eye_L", "eye_R"].find(
3919
+ (r) => layers[r] !== void 0 && (layers[r].bboxCx < axisX ? -1 : 1) === side
3920
+ );
3921
+ const eye = eyeRole === void 0 ? void 0 : layers[eyeRole];
3922
+ const root = rootWarning(role, lock, front);
3923
+ if (root !== void 0) warnings.push(root);
3924
+ if (eyeRole !== void 0 && eye !== void 0) {
3925
+ const w = eyeCornerWarning(role, lock, side, eyeRole, eye);
3926
+ if (w !== void 0) warnings.push(w);
3927
+ }
3928
+ const rowEye = eye ?? layers.eye_L ?? layers.eye_R;
3929
+ if (face !== void 0 && rowEye !== void 0) {
3930
+ const w = leanWarning(role, lock, side, face, back, rowEye);
3931
+ if (w !== void 0) warnings.push(w);
3932
+ }
3933
+ }
3934
+ if (drawsTwoLocks(locks.get("hair_side_R") ?? locks.get(present[0]))) {
3935
+ warnings.push(
3936
+ `hair_side.png draws two locks \u2014 draw ONE lock, the screen-left one; the composer mirrors it into hair_side_L. Billed.`
3937
+ );
3938
+ }
3939
+ return warnings;
3940
+ }
3941
+ function rootWarning(role, lock, front) {
3942
+ const y = opaqueRows(lock)?.top;
3943
+ if (y === void 0) return void 0;
3944
+ const frontRuns = runsAt(front, y);
3945
+ const lockRuns = runsAt(lock, y);
3946
+ let shown = 0;
3947
+ for (let i = 0; i + 1 < lockRuns.length; i += 2) {
3948
+ let stretch = 0;
3949
+ for (let x = lockRuns[i]; x <= lockRuns[i + 1]; x++) {
3950
+ if (x < lockRuns[i + 1] && !covers(frontRuns, x)) {
3951
+ stretch++;
3952
+ continue;
3953
+ }
3954
+ if (stretch >= VISIBLE_MIN_PX) shown += stretch;
3955
+ stretch = 0;
3956
+ }
3957
+ }
3958
+ if (shown === 0) return void 0;
3959
+ return `${role}: its top row (canvas y ${y}) shows past hair_front on ${shown} px \u2014 the root is visible at rest. Move it under the bangs \u2014 up (layout.${role}.cy) or toward the face (layout.${role}.cx) (free), or regenerate hair_side.png with a longer hidden root. Billed.`;
3960
+ }
3961
+ function eyeCornerWarning(role, lock, side, eyeRole, eye) {
3962
+ const row = Math.floor(eye.bboxCy);
3963
+ const corner = side < 0 ? eye.marginLeft : eye.marginLeft + eye.w - 1;
3964
+ const runs = runsAt(lock, row);
3965
+ let overlap = 0;
3966
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3967
+ if (corner < runs[i] || corner >= runs[i + 1]) continue;
3968
+ overlap = side < 0 ? runs[i + 1] - corner : corner - runs[i] + 1;
3969
+ }
3970
+ if (overlap < VISIBLE_MIN_PX) return void 0;
3971
+ return `${role}: covers ${eyeRole}'s outer corner at rest (canvas x ${corner}, y ${row}) by ${overlap} px \u2014 the eye's outer tail may only slide under it on the turn. Move layout.${role}.cx ${overlap} px ${side < 0 ? "left" : "right"}, outward (free), or regenerate it narrower. Billed.`;
3972
+ }
3973
+ function leanWarning(role, lock, side, face, back, eye) {
3974
+ const faceRows = opaqueRows(face);
3975
+ const lockRows = opaqueRows(lock);
3976
+ if (faceRows === void 0 || lockRows === void 0) return void 0;
3977
+ const faceBottom = faceRows.bottom;
3978
+ const lean = Math.round(LEAN_HH * (faceBottom - Math.floor(eye.bboxCy)));
3979
+ if (lean < 1) return void 0;
3980
+ const bare = /* @__PURE__ */ new Set();
3981
+ const rows = /* @__PURE__ */ new Set();
3982
+ for (let y = lockRows.top; y <= Math.min(lockRows.bottom, faceBottom); y++) {
3983
+ const runs = runsAt(lock, y);
3984
+ if (runs.length === 0) continue;
3985
+ const from = side < 0 ? runs[0] : runs[runs.length - 2];
3986
+ const to = side < 0 ? runs[1] : runs[runs.length - 1];
3987
+ const start = side < 0 ? from : Math.max(from, to - lean);
3988
+ const end = side < 0 ? Math.min(to, from + lean) : to;
3989
+ const faceRuns = runsAt(face, y);
3990
+ const backRuns = runsAt(back, y);
3991
+ for (let x = start; x < end; x++) {
3992
+ if (covers(faceRuns, x) || covers(backRuns, x)) continue;
3993
+ bare.add(x);
3994
+ rows.add(y);
3995
+ }
3996
+ }
3997
+ if (bare.size === 0) return void 0;
3998
+ const cols = [...bare].sort((a, b) => a - b);
3999
+ const ys = [...rows].sort((a, b) => a - b);
4000
+ const where = `leaves bare pixels spanning columns ${cols[0]}\u2013${cols[cols.length - 1]}, rows ${ys[0]}\u2013${ys[ys.length - 1]}`;
4001
+ const lead = `${role}: when the head turns away from it the lock leans inward about ${lean} px and ${where}, where`;
4002
+ if (back === void 0) {
4003
+ return `${lead} the face is not painted \u2014 draw hair_back.png behind the locks. Billed.`;
4004
+ }
4005
+ return `${lead} neither hair_back nor the face is painted \u2014 widen hair_back there (layout.hair_back.w) (free), or regenerate it fuller behind the locks. Billed.`;
4006
+ }
4007
+ function drawsTwoLocks(lock) {
4008
+ const w = lock.bbox.w;
4009
+ const col = new Array(w).fill(false);
4010
+ for (const runs of lock.rowRuns ?? []) {
4011
+ for (let i = 0; i + 1 < runs.length; i += 2) {
4012
+ for (let x = runs[i]; x < runs[i + 1]; x++) col[x - lock.bbox.x] = true;
4013
+ }
4014
+ }
4015
+ const big = [];
4016
+ let start = -1;
4017
+ for (let x = 0; x <= w; x++) {
4018
+ if (x < w && col[x]) {
4019
+ if (start < 0) start = x;
4020
+ } else if (start >= 0) {
4021
+ if (x - start >= TWO_LOCKS_RUN * w) big.push([start, x]);
4022
+ start = -1;
4023
+ }
4024
+ }
4025
+ for (let i = 1; i < big.length; i++) {
4026
+ if (big[i][0] - big[i - 1][1] >= TWO_LOCKS_GAP * w) return true;
4027
+ }
4028
+ return false;
4029
+ }
4030
+
4031
+ // src/measure-forearm-pose.ts
4032
+ var import_editor7 = require("@ikijs/editor");
3612
4033
  var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
3613
4034
  var ARM_OF = {
3614
4035
  forearm_pose_L: "arm_L",
@@ -3642,7 +4063,7 @@ async function forearmPoseWarnings(absDir, layers) {
3642
4063
  continue;
3643
4064
  }
3644
4065
  if (layers.body === void 0) continue;
3645
- const measurer = (0, import_editor6.createLayerSetMeasurer)({
4066
+ const measurer = (0, import_editor7.createLayerSetMeasurer)({
3646
4067
  width: stats.canvasW,
3647
4068
  height: stats.canvasH
3648
4069
  });
@@ -3650,12 +4071,12 @@ async function forearmPoseWarnings(absDir, layers) {
3650
4071
  let armLayer;
3651
4072
  try {
3652
4073
  armLayer = await measured(measurer, absDir, arm);
3653
- a = (0, import_editor6.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
4074
+ a = (0, import_editor7.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
3654
4075
  } catch (err) {
3655
- if (err instanceof import_editor6.LayerGeometryError) continue;
4076
+ if (err instanceof import_editor7.LayerGeometryError) continue;
3656
4077
  throw err;
3657
4078
  }
3658
- const b = (0, import_editor6.forearmPoseGeometry)(await measured(measurer, absDir, pose));
4079
+ const b = (0, import_editor7.forearmPoseGeometry)(await measured(measurer, absDir, pose));
3659
4080
  warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
3660
4081
  }
3661
4082
  return warnings;
@@ -3695,11 +4116,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3695
4116
 
3696
4117
  // src/measure-lips.ts
3697
4118
  var import_node_path7 = __toESM(require("path"));
3698
- var import_editor8 = require("@ikijs/editor");
4119
+ var import_editor9 = require("@ikijs/editor");
3699
4120
 
3700
4121
  // src/compose-lips.ts
3701
4122
  var import_sharp2 = __toESM(require("sharp"));
3702
- var import_editor7 = require("@ikijs/editor");
4123
+ var import_editor8 = require("@ikijs/editor");
3703
4124
  var KEYED_SRC = "mouth_keyed.png";
3704
4125
  var INTERIOR_SRC = "mouth_interior.png";
3705
4126
  var KEY_CANDIDATE = 0.5;
@@ -3797,7 +4218,7 @@ function keyGreen(rgba, W, H) {
3797
4218
  let candidates = 0;
3798
4219
  for (let p = 0; p < n; p++) {
3799
4220
  const i = p * 4;
3800
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4221
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
3801
4222
  const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
3802
4223
  if (excess < KEY_CANDIDATE) continue;
3803
4224
  candidates++;
@@ -3824,7 +4245,7 @@ function keyGreen(rgba, W, H) {
3824
4245
  const dg = rgba[i + 1] - G[1];
3825
4246
  const db = rgba[i + 2] - G[2];
3826
4247
  const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
3827
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) {
4248
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) {
3828
4249
  if (green) out[i + 3] = 0;
3829
4250
  } else if (green) {
3830
4251
  fill[p] = 1;
@@ -4000,7 +4421,7 @@ async function prepInterior(rgba, W, H) {
4000
4421
  for (let y = box2.y; y < box2.y + box2.h; y++) {
4001
4422
  for (let x = box2.x; x < box2.x + box2.w; x++) {
4002
4423
  const i = (y * cw + x) * 4;
4003
- if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4424
+ if (crop[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
4004
4425
  count++;
4005
4426
  for (let c = 0; c < 3; c++) all[c] += crop[i + c];
4006
4427
  if (luma(crop, i) < CAVITY_LUMA) {
@@ -4023,7 +4444,7 @@ function enclosedHole(frame, w, h) {
4023
4444
  const stack = new Int32Array(n);
4024
4445
  let depth = 0;
4025
4446
  const seed = (p) => {
4026
- if (!outside[p] && alpha(p) < import_editor7.ALPHA_OPAQUE) {
4447
+ if (!outside[p] && alpha(p) < import_editor8.ALPHA_OPAQUE) {
4027
4448
  outside[p] = 1;
4028
4449
  stack[depth++] = p;
4029
4450
  }
@@ -4046,7 +4467,7 @@ function enclosedHole(frame, w, h) {
4046
4467
  }
4047
4468
  const mask = new Uint8Array(n);
4048
4469
  for (let p = 0; p < n; p++) {
4049
- if (alpha(p) < import_editor7.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4470
+ if (alpha(p) < import_editor8.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4050
4471
  }
4051
4472
  const { label, sizes, boxes } = components(mask, w, h);
4052
4473
  const main2 = largest(sizes);
@@ -4073,7 +4494,7 @@ function enclosedHole(frame, w, h) {
4073
4494
  return { label, main: main2, box: box2 };
4074
4495
  }
4075
4496
  function measureLips(layers, w, h) {
4076
- const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
4497
+ const measurer = (0, import_editor8.createLayerSetMeasurer)({ width: w, height: h });
4077
4498
  return new Map(
4078
4499
  Object.entries(layers).map(([role, rgba]) => [
4079
4500
  role,
@@ -4091,8 +4512,8 @@ function assertFoldContract(layers, w, h) {
4091
4512
  }
4092
4513
  byRole.set(role, layer);
4093
4514
  }
4094
- const opening = (0, import_editor7.mouthOpening)(byRole);
4095
- const runs = (0, import_editor7.columnRuns)(byRole.get("mouth_inner"));
4515
+ const opening = (0, import_editor8.mouthOpening)(byRole);
4516
+ const runs = (0, import_editor8.columnRuns)(byRole.get("mouth_inner"));
4096
4517
  for (let col = opening.x0; col <= opening.x1; col++) {
4097
4518
  const c = opening.at(col);
4098
4519
  const why = !runs.has(col) ? "has no interior run" : c.Tu > c.T ? `has a gap between the line and the interior (Tu ${c.Tu} > T ${c.T})` : c.T > c.lineTop || c.lineH <= 0 ? `has no line above the interior (T ${c.T}, line top ${c.lineTop})` : c.Bl < c.Bb ? `has a gap between the interior and the skin (Bl ${c.Bl} < Bb ${c.Bb})` : null;
@@ -4122,18 +4543,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
4122
4543
  }
4123
4544
  const centre = Math.round((hb.x0 + hb.x1) / 2);
4124
4545
  let stroke = 0;
4125
- while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor7.ALPHA_OPAQUE)
4546
+ while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor8.ALPHA_OPAQUE)
4126
4547
  stroke++;
4127
4548
  const bandCap = BAND_CAP * Math.max(1, stroke);
4128
4549
  const skinRow = new Int32Array(w).fill(-1);
4129
4550
  const inM = new Uint8Array(n);
4130
4551
  for (let x = hb.x0; x <= hb.x1; x++) {
4131
4552
  let y = bot[x];
4132
- while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor7.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4553
+ while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor8.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4133
4554
  y++;
4134
4555
  for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
4135
4556
  let r = y;
4136
- while (r < h && alpha(r * w + x) < import_editor7.ALPHA_OPAQUE) r++;
4557
+ while (r < h && alpha(r * w + x) < import_editor8.ALPHA_OPAQUE) r++;
4137
4558
  if (r < h) {
4138
4559
  skinRow[x] = r;
4139
4560
  inM[r * w + x] = 1;
@@ -4143,7 +4564,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4143
4564
  for (let y = 0; y < h; y++) {
4144
4565
  for (let x = 0; x < w; x++) {
4145
4566
  const p = y * w + x;
4146
- if (inM[p] || alpha(p) < import_editor7.ALPHA_OPAQUE) continue;
4567
+ if (inM[p] || alpha(p) < import_editor8.ALPHA_OPAQUE) continue;
4147
4568
  if (top[x] >= 0 && y < top[x]) continue;
4148
4569
  if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
4149
4570
  }
@@ -4153,7 +4574,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4153
4574
  if (x < 0 || x >= w) continue;
4154
4575
  let first = 0;
4155
4576
  while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
4156
- if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor7.ALPHA_OPAQUE)
4577
+ if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor8.ALPHA_OPAQUE)
4157
4578
  wall[x] = 1;
4158
4579
  }
4159
4580
  const gx = hb.x0 - 1;
@@ -4180,7 +4601,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4180
4601
  if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
4181
4602
  if (!grown[p]) {
4182
4603
  const a = alpha(p);
4183
- if (a >= import_editor7.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4604
+ if (a >= import_editor8.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4184
4605
  inner.set(interior.cavity, p * 4);
4185
4606
  inner[p * 4 + 3] = 255 - a;
4186
4607
  }
@@ -4245,7 +4666,7 @@ async function restShiftOf(layers, width, height) {
4245
4666
  }
4246
4667
  byRole.set(role, layer);
4247
4668
  }
4248
- return (0, import_editor7.mouthRestShift)(byRole);
4669
+ return (0, import_editor8.mouthRestShift)(byRole);
4249
4670
  }
4250
4671
  async function closedLips(upper, lower, shift, left, top) {
4251
4672
  const shut = async (png, role) => {
@@ -4295,7 +4716,7 @@ async function closedLips(upper, lower, shift, left, top) {
4295
4716
  }
4296
4717
 
4297
4718
  // src/measure-lips.ts
4298
- var isLipLayerRole = (role) => import_editor8.LIP_ROLES.includes(role) || (0, import_editor8.isLipInsideRole)(role);
4719
+ var isLipLayerRole = (role) => import_editor9.LIP_ROLES.includes(role) || (0, import_editor9.isLipInsideRole)(role);
4299
4720
  var MIN_OPENING_ROWS = 8;
4300
4721
  var MIN_LINE_ROWS = 2;
4301
4722
  var GREEN_EXCESS = 40;
@@ -4303,8 +4724,8 @@ var INTERIOR_GAP_FRACTION = 0.05;
4303
4724
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
4304
4725
  async function lipWarnings(absDir, layers) {
4305
4726
  const warnings = [];
4306
- const present = import_editor8.LIP_ROLES.filter((role) => layers[role] !== void 0);
4307
- const inside = import_editor8.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4727
+ const present = import_editor9.LIP_ROLES.filter((role) => layers[role] !== void 0);
4728
+ const inside = import_editor9.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4308
4729
  if (present.length === 0) {
4309
4730
  if (inside.length > 0) {
4310
4731
  warnings.push(
@@ -4321,8 +4742,8 @@ async function lipWarnings(absDir, layers) {
4321
4742
  `${present.join("/")}: the lip set cannot be mixed with ${legacy.join("/")} \u2014 auto_rig_from_layers refuses it. Remove one route: compose again with only mouth_keyed.png + mouth_interior.png, or without them.`
4322
4743
  );
4323
4744
  }
4324
- if (present.length < import_editor8.LIP_ROLES.length) {
4325
- const missing = import_editor8.LIP_ROLES.filter((role) => layers[role] === void 0);
4745
+ if (present.length < import_editor9.LIP_ROLES.length) {
4746
+ const missing = import_editor9.LIP_ROLES.filter((role) => layers[role] === void 0);
4326
4747
  warnings.push(
4327
4748
  `${present.join("/")}: partial lip set, missing ${missing.join("/")} \u2014 auto_rig_from_layers refuses it. Compose mouth_keyed.png + mouth_interior.png together, which cuts all three.`
4328
4749
  );
@@ -4353,18 +4774,18 @@ async function lipWarnings(absDir, layers) {
4353
4774
  );
4354
4775
  }
4355
4776
  }
4356
- const measurer = (0, import_editor8.createLayerSetMeasurer)({
4777
+ const measurer = (0, import_editor9.createLayerSetMeasurer)({
4357
4778
  width: inner.canvasW,
4358
4779
  height: inner.canvasH
4359
4780
  });
4360
4781
  const set = /* @__PURE__ */ new Map();
4361
4782
  const green = [];
4362
- for (const role of import_editor8.LIP_ROLES) {
4783
+ for (const role of import_editor9.LIP_ROLES) {
4363
4784
  const fileName = `${role}.png`;
4364
4785
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
4365
4786
  set.set(role, measurer.add({ role, fileName, rgba }));
4366
4787
  for (let i = 0; i < rgba.length; i += 4) {
4367
- if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4788
+ if (rgba[i + 3] >= import_editor9.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4368
4789
  green.push(role);
4369
4790
  break;
4370
4791
  }
@@ -4372,15 +4793,15 @@ async function lipWarnings(absDir, layers) {
4372
4793
  }
4373
4794
  let opening;
4374
4795
  try {
4375
- opening = (0, import_editor8.mouthOpening)(set);
4796
+ opening = (0, import_editor9.mouthOpening)(set);
4376
4797
  } catch (err) {
4377
- if (err instanceof import_editor8.LayerGeometryError) {
4798
+ if (err instanceof import_editor9.LayerGeometryError) {
4378
4799
  warnings.push(err.message);
4379
4800
  return { warnings };
4380
4801
  }
4381
4802
  throw err;
4382
4803
  }
4383
- const innerRuns = (0, import_editor8.columnRuns)(set.get("mouth_inner"));
4804
+ const innerRuns = (0, import_editor9.columnRuns)(set.get("mouth_inner"));
4384
4805
  const noInterior = [];
4385
4806
  const gap = [];
4386
4807
  const noLine = [];
@@ -4466,8 +4887,8 @@ async function lipWarnings(absDir, layers) {
4466
4887
 
4467
4888
  // src/measure-turn.ts
4468
4889
  var import_node_path8 = __toESM(require("path"));
4469
- var import_editor9 = require("@ikijs/editor");
4470
4890
  var import_editor10 = require("@ikijs/editor");
4891
+ var import_editor11 = require("@ikijs/editor");
4471
4892
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
4472
4893
  var IRIS_V_MIN = 0.18;
4473
4894
  var IRIS_V_MAX = 0.95;
@@ -4617,7 +5038,7 @@ async function measureTurnImage(filePath, iris) {
4617
5038
  let transparent = false;
4618
5039
  if (hasAlpha) {
4619
5040
  for (let i = 0; i < n; i++) {
4620
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) {
5041
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) {
4621
5042
  transparent = true;
4622
5043
  break;
4623
5044
  }
@@ -4628,7 +5049,7 @@ async function measureTurnImage(filePath, iris) {
4628
5049
  const fg = new Uint8Array(n);
4629
5050
  const value = new Float32Array(n);
4630
5051
  for (let i = 0; i < n; i++) {
4631
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) continue;
5052
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) continue;
4632
5053
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
4633
5054
  if (maskMode === "alpha") {
4634
5055
  fg[i] = 1;
@@ -4694,12 +5115,12 @@ async function measureTurnImage(filePath, iris) {
4694
5115
  }
4695
5116
  const [irisL, irisR] = best.pair;
4696
5117
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
4697
- const { left, right } = (0, import_editor9.foregroundSpan)(
5118
+ const { left, right } = (0, import_editor10.foregroundSpan)(
4698
5119
  fg,
4699
5120
  width,
4700
5121
  height,
4701
- eyeRow - import_editor9.HEAD_BAND,
4702
- eyeRow + import_editor9.HEAD_BAND
5122
+ eyeRow - import_editor10.HEAD_BAND,
5123
+ eyeRow + import_editor10.HEAD_BAND
4703
5124
  );
4704
5125
  if (right <= left) {
4705
5126
  throw new AutoRigInputError(
@@ -4723,7 +5144,7 @@ async function measureTurnImage(filePath, iris) {
4723
5144
  left,
4724
5145
  right,
4725
5146
  cx: (left + right) / 2,
4726
- half: (0, import_editor9.headHalfOf)({ left, right })
5147
+ half: (0, import_editor10.headHalfOf)({ left, right })
4727
5148
  },
4728
5149
  pairCx: (irisL.cx + irisR.cx) / 2,
4729
5150
  eyeGap: irisR.cx - irisL.cx
@@ -4914,7 +5335,7 @@ function noseSpeckWarning({ core, part }, source) {
4914
5335
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
4915
5336
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
4916
5337
  ];
4917
- return `nose: ${found} \u2014 under ${import_editor10.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
5338
+ return `nose: ${found} \u2014 under ${import_editor11.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
4918
5339
  }
4919
5340
  async function lashOffSclera(eyePath, lashPath) {
4920
5341
  const eye = await decodePng(eyePath);
@@ -4995,6 +5416,7 @@ async function measureDir(absDir, noseSpeck) {
4995
5416
  warnings.push(...await forearmPoseWarnings(absDir, layers));
4996
5417
  const lip = await lipWarnings(absDir, layers);
4997
5418
  warnings.push(...lip.warnings);
5419
+ warnings.push(...await hairSideWarnings(absDir, layers));
4998
5420
  for (const side of ["L", "R"]) {
4999
5421
  const eye = layers[`eye_${side}`];
5000
5422
  const iris = layers[`iris_${side}`];
@@ -5051,10 +5473,10 @@ async function measureDir(absDir, noseSpeck) {
5051
5473
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
5052
5474
  } else if (layers.nose !== void 0) {
5053
5475
  const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
5054
- const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
5476
+ const core = (0, import_editor11.denseCoreOf)(nose.rgba, nose.width, nose.height);
5055
5477
  if (core !== null) {
5056
5478
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
5057
- if ((0, import_editor10.isSpeckCore)(core, crop))
5479
+ if ((0, import_editor11.isSpeckCore)(core, crop))
5058
5480
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
5059
5481
  }
5060
5482
  }
@@ -5125,12 +5547,12 @@ function formatMeasureReport(result) {
5125
5547
 
5126
5548
  // src/compose-arms.ts
5127
5549
  var import_sharp3 = __toESM(require("sharp"));
5128
- var import_editor11 = require("@ikijs/editor");
5550
+ var import_editor12 = require("@ikijs/editor");
5129
5551
  var ARM_WIDTH = 0.4;
5130
5552
  var SHOULDER_DROP = 0.12;
5131
5553
  async function armPlacement(role, cfg, part, body) {
5132
5554
  const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5133
- const layer = (0, import_editor11.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5555
+ const layer = (0, import_editor12.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5134
5556
  role,
5135
5557
  fileName: "arm.png",
5136
5558
  rgba: data
@@ -5142,9 +5564,9 @@ async function armPlacement(role, cfg, part, body) {
5142
5564
  }
5143
5565
  let g;
5144
5566
  try {
5145
- g = (0, import_editor11.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5567
+ g = (0, import_editor12.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5146
5568
  } catch (err) {
5147
- if (err instanceof import_editor11.LayerGeometryError) {
5569
+ if (err instanceof import_editor12.LayerGeometryError) {
5148
5570
  throw new AutoRigInputError(`layout.${role}: ${err.message}`);
5149
5571
  }
5150
5572
  throw err;
@@ -5171,7 +5593,7 @@ async function armPlacement(role, cfg, part, body) {
5171
5593
  }
5172
5594
  async function poseGeometryOf(role, png, size, when) {
5173
5595
  const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5174
- const layer = (0, import_editor11.createLayerSetMeasurer)({
5596
+ const layer = (0, import_editor12.createLayerSetMeasurer)({
5175
5597
  width: size.w,
5176
5598
  height: size.h
5177
5599
  }).add({ role, fileName: "forearm_pose.png", rgba: data });
@@ -5180,7 +5602,7 @@ async function poseGeometryOf(role, png, size, when) {
5180
5602
  `layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
5181
5603
  );
5182
5604
  }
5183
- return (0, import_editor11.forearmPoseGeometry)(layer);
5605
+ return (0, import_editor12.forearmPoseGeometry)(layer);
5184
5606
  }
5185
5607
  async function forearmPoseWidth(role, trimmed, elbowRun) {
5186
5608
  const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
@@ -5297,6 +5719,23 @@ var DEFAULT_LAYOUT = {
5297
5719
  // prettier-ignore
5298
5720
  brow_L: { src: "brow.png", cx: 645, cy: 405, w: 105, mirror: false },
5299
5721
  brow_R: { src: "brow.png", cx: 455, cy: 405, w: 105, mirror: true },
5722
+ // The front side locks, one part for both: hair_side_R (screen left) takes
5723
+ // hair_side.png as drawn and hair_side_L mirrors it, like the blush. They
5724
+ // draw over the face, brows and lashes and under the bangs. Mint's tuned
5725
+ // placement (cy 545 at mint's face cy 431, carried to the default face:
5726
+ // 437 + 114 = 551), tuned per character through `layout.hair_side_*`: the
5727
+ // lock's root top lies above the brow row (405) so the bangs' temple hides it
5728
+ // (for a 1:5 lock, whose height follows the image's aspect: w 90 is 450 tall,
5729
+ // so cy 551 puts the top at 326), and the lock runs from the temple over the
5730
+ // front of the ear and down along the cheek's edge, the ear's rim and lobe
5731
+ // showing beside it. Its box overlaps the eye's by about 15 px at the
5732
+ // default face, fine only because a drawn lock's root tapers (the measure's "covers
5733
+ // the eye's outer corner" check catches a lock that does not).
5734
+ // OPTIONAL: a parts dir without it composes.
5735
+ hair_side_L: { src: "hair_side.png", cx: 715, cy: 551, w: 90, optional: true, mirror: true },
5736
+ // prettier-ignore
5737
+ hair_side_R: { src: "hair_side.png", cx: 385, cy: 551, w: 90, optional: true, mirror: false },
5738
+ // prettier-ignore
5300
5739
  hair_front: { src: "hair_front.png", cx: 550, cy: 425, w: 660 },
5301
5740
  // The pose forearms, one drawing for both: forearm_pose_R (screen left)
5302
5741
  // takes forearm_pose.png as drawn and forearm_pose_L mirrors it, like the
@@ -5335,6 +5774,8 @@ var ORDER = [
5335
5774
  "lash_R",
5336
5775
  "brow_L",
5337
5776
  "brow_R",
5777
+ "hair_side_L",
5778
+ "hair_side_R",
5338
5779
  "hair_front",
5339
5780
  "forearm_pose_L",
5340
5781
  "forearm_pose_R"
@@ -5359,7 +5800,9 @@ var FACE_FEATURES = [
5359
5800
  "lash_L",
5360
5801
  "lash_R",
5361
5802
  "brow_L",
5362
- "brow_R"
5803
+ "brow_R",
5804
+ "hair_side_L",
5805
+ "hair_side_R"
5363
5806
  ];
5364
5807
  function resolveLayout(overrides, canvas) {
5365
5808
  const resolved = { ...DEFAULT_LAYOUT };
@@ -5457,18 +5900,18 @@ function keyWhiteToAlpha(rgba) {
5457
5900
  async function coreAndBoundsOf(png) {
5458
5901
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5459
5902
  return {
5460
- core: (0, import_editor10.denseCoreOf)(data, info.width, info.height),
5903
+ core: (0, import_editor11.denseCoreOf)(data, info.width, info.height),
5461
5904
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
5462
5905
  };
5463
5906
  }
5464
5907
  async function hasCoverage(png) {
5465
5908
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5466
- return (0, import_editor12.detectAlphaBbox)(data, info.width, info.height) !== null;
5909
+ return (0, import_editor13.detectAlphaBbox)(data, info.width, info.height) !== null;
5467
5910
  }
5468
5911
  async function noseSizingOf(png) {
5469
5912
  const { core, bounds } = await coreAndBoundsOf(png);
5470
5913
  if (core === null) return { box: bounds, whole: true };
5471
- if ((0, import_editor10.isSpeckCore)(core, bounds)) {
5914
+ if ((0, import_editor11.isSpeckCore)(core, bounds)) {
5472
5915
  return {
5473
5916
  box: bounds,
5474
5917
  whole: true,
@@ -5590,7 +6033,7 @@ function detachedAboveWhite(rgba, W, H) {
5590
6033
  for (let p = 0; p < n; p++) {
5591
6034
  const alpha = rgba[p * 4 + 3];
5592
6035
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
5593
- ink[p] = alpha >= import_editor12.ALPHA_OPAQUE ? 2 : 1;
6036
+ ink[p] = alpha >= import_editor13.ALPHA_OPAQUE ? 2 : 1;
5594
6037
  }
5595
6038
  const label = new Int32Array(n).fill(-1);
5596
6039
  const stack = new Int32Array(n);
@@ -5695,7 +6138,7 @@ async function prepEyeSplit(partsDir) {
5695
6138
  const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
5696
6139
  const detached = detachedAboveWhite(data, W, H);
5697
6140
  const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
5698
- const isLight = (i) => data[i + 3] >= import_editor12.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
6141
+ const isLight = (i) => data[i + 3] >= import_editor13.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
5699
6142
  const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
5700
6143
  const whiteTop = new Int32Array(W).fill(-1);
5701
6144
  for (let x = 0; x < W; x++) {
@@ -5865,7 +6308,7 @@ async function composeLayersFromParts(input) {
5865
6308
  lip_lower: split2.lower,
5866
6309
  lip_upper: split2.upper
5867
6310
  }[role];
5868
- if ((0, import_editor12.isLipInsideRole)(role) && !await hasCoverage(buf)) {
6311
+ if ((0, import_editor13.isLipInsideRole)(role) && !await hasCoverage(buf)) {
5869
6312
  skipped.push(role);
5870
6313
  continue;
5871
6314
  }
@@ -6060,7 +6503,7 @@ async function composeLayersFromParts(input) {
6060
6503
  });
6061
6504
  }
6062
6505
  const restInput = (role, buf) => {
6063
- if (role === "mouth_inner" || (0, import_editor12.isLipInsideRole)(role)) return null;
6506
+ if (role === "mouth_inner" || (0, import_editor13.isLipInsideRole)(role)) return null;
6064
6507
  if (closed === void 0) return buf;
6065
6508
  if (role === "lip_upper") return closed.upper;
6066
6509
  if (role === "lip_lower") return closed.lower;
@@ -6127,6 +6570,40 @@ async function composeLayersFromParts(input) {
6127
6570
  }
6128
6571
  }
6129
6572
 
6573
+ // src/hair-side-report.ts
6574
+ function signedPx(px2) {
6575
+ const s = px2.toFixed(1);
6576
+ if (s === "-0.0") return "+0.0";
6577
+ return s.startsWith("-") ? s : `+${s}`;
6578
+ }
6579
+ function formatHairSideReport(hairSide, canvas) {
6580
+ if (hairSide === void 0) return [];
6581
+ return [hairSide.left, hairSide.right].flatMap(
6582
+ (room) => room === void 0 ? [] : roomLines(room, canvas)
6583
+ );
6584
+ }
6585
+ function roomLines(room, canvas) {
6586
+ const { role, cover, tail, unavailable } = room;
6587
+ if (unavailable !== void 0) {
6588
+ return [`HAIRSIDE ${role}: unavailable \u2014 ${unavailable}`];
6589
+ }
6590
+ const lines = [];
6591
+ if (cover !== void 0) {
6592
+ const row = Math.floor(canvas.height / 2 - cover.y);
6593
+ lines.push(
6594
+ `HAIRSIDE cover ${role}: the lock's outer edge ${signedPx(cover.px)} model px outside the head's edge at ParamAngleX=${cover.deg}, ${signedPx(cover.rest)} at rest (least over the rows it covers at rest, at model y ${cover.y.toFixed(1)}, row ${row} model px from the top; negative: the turn bares cheek the lock hides at rest)`
6595
+ );
6596
+ }
6597
+ if (tail !== void 0) {
6598
+ const lash = tail.lashToLock === void 0 ? "" : ` / lash ${signedPx(tail.lashToLock)} model px`;
6599
+ lines.push(
6600
+ `HAIRSIDE tail ${role}: eye ${signedPx(tail.eyeToLock)} model px${lash} from the lock's face-side edge at ParamAngleX=${tail.deg} (negative: under the lock, intended), corner ${signedPx(tail.eyeToPlate)} model px from the head's edge (positive: inside it; negative: past it)`
6601
+ );
6602
+ }
6603
+ if (lines.length === 0) lines.push(`HAIRSIDE ${role}: no cover or tail row`);
6604
+ return lines;
6605
+ }
6606
+
6130
6607
  // src/physics-report.ts
6131
6608
  function formatPhysicsReport(report) {
6132
6609
  if (report.targets.length === 0) return ["PHYSICS: no rigs"];
@@ -6152,7 +6629,7 @@ function formatPatchReports(reports) {
6152
6629
  });
6153
6630
  }
6154
6631
  function createIkiMcpServer() {
6155
- const server = new import_mcp.McpServer({ name: "iki", version: "0.31.1" });
6632
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.33.0" });
6156
6633
  server.registerTool(
6157
6634
  "validate_iki",
6158
6635
  {
@@ -6244,7 +6721,7 @@ function createIkiMcpServer() {
6244
6721
  server.registerTool(
6245
6722
  "auto_rig_from_layers",
6246
6723
  {
6247
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6724
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, hair_side_L/hair_side_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, a side lock needs hair_front, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6248
6725
  inputSchema: {
6249
6726
  layers: import_zod.z.array(
6250
6727
  import_zod.z.object({
@@ -6321,7 +6798,8 @@ function createIkiMcpServer() {
6321
6798
  formatRigPlanReport(r.rigPlan),
6322
6799
  ...formatPatchReports(r.patches ?? []),
6323
6800
  ...formatFoldReport(r.folds, r.canvas),
6324
- ...formatPhysicsReport(r.physics)
6801
+ ...formatPhysicsReport(r.physics),
6802
+ ...formatHairSideReport(r.turn?.hairSide, r.canvas)
6325
6803
  ].join("\n") : `INVALID: ${r.error}`;
6326
6804
  return { content: [{ type: "text", text }], structuredContent: r };
6327
6805
  } catch (err) {
@@ -6337,7 +6815,7 @@ function createIkiMcpServer() {
6337
6815
  server.registerTool(
6338
6816
  "compose_layers_from_parts",
6339
6817
  {
6340
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6818
+ description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6341
6819
  inputSchema: {
6342
6820
  partsDir: import_zod.z.string().describe(
6343
6821
  "Directory of the source part PNGs (resolved against cwd)."
@@ -6354,10 +6832,10 @@ function createIkiMcpServer() {
6354
6832
  h: import_zod.z.number()
6355
6833
  }).partial()
6356
6834
  ).optional().describe(
6357
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6835
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_side_L, hair_side_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows, side locks \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6358
6836
  ),
6359
6837
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
6360
- "Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
6838
+ "Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), hair_side.png as the front side lock on the screen LEFT (hanging, its root at the image's top), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
6361
6839
  ),
6362
6840
  canvasHeight: import_zod.z.number().optional().describe(
6363
6841
  "The canvas's height in px: an even integer in 1100..4096, default 1100 (a square bust canvas; at 1100 every output is byte-identical to leaving it out). The width stays 1100. The canvas grows downward: every default and every override keeps its canvas px from the top-left, so the head lands where it does on a bust and a full body gets room below. An odd height is refused \u2014 model space is centred on the canvas, so it would put the head on a half pixel \u2014 and it is checked before any part decodes."
@@ -6385,7 +6863,7 @@ function createIkiMcpServer() {
6385
6863
  server.registerTool(
6386
6864
  "measure_layers",
6387
6865
  {
6388
- description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6866
+ description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6389
6867
  inputSchema: {
6390
6868
  layersDir: import_zod.z.string().describe(
6391
6869
  "Directory of role-named layer PNGs (resolved against cwd)."
@@ -6450,7 +6928,7 @@ function createIkiMcpServer() {
6450
6928
  server.registerTool(
6451
6929
  "render_poses",
6452
6930
  {
6453
- description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6931
+ description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines (and, with `sweeps`, the turn-and-nod box). Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6454
6932
  inputSchema: {
6455
6933
  modelPath: import_zod.z.string().describe(
6456
6934
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6482,7 +6960,21 @@ function createIkiMcpServer() {
6482
6960
  h: import_zod.z.number()
6483
6961
  }).optional()
6484
6962
  }).optional().describe(
6485
- "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`."
6963
+ "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`. `sweeps` renders more sweeps beside this one. The `SWEEP nod` and `SWEEP corner` lines follow the `SWEEP turn` ones."
6964
+ ),
6965
+ sweeps: import_zod.z.array(
6966
+ import_zod.z.object({
6967
+ name: import_zod.z.string(),
6968
+ preset: import_zod.z.enum(SWEEP_PRESETS),
6969
+ crop: import_zod.z.object({
6970
+ x: import_zod.z.number(),
6971
+ y: import_zod.z.number(),
6972
+ w: import_zod.z.number(),
6973
+ h: import_zod.z.number()
6974
+ }).optional()
6975
+ })
6976
+ ).optional().describe(
6977
+ "More sweeps rendered after `sweep`, each `{ name, preset, crop? }` into its own `<outDir>/<name>/` (files and `crop` as `sweep`'s). Names are distinct from `sweep`'s and from each other's ignoring case, and presets are distinct (at most one of each). `turn` is `sweep`'s. `turn-nod` is the box (0,0) -> (0,-30) -> (-30,-30) -> (-30,+30) -> (+30,+30) -> (+30,-30) -> (0,-30) -> (0,0) of `ParamAngleX` x `ParamAngleY`, each leg eased, 6 s, 180 frames; its `sheet.png` is a 3 x 3 grid BY ANGLE (columns AngleX -30/0/+30, rows AngleY +30/0/-30, rest in the centre, cells labelled X, Y and t) and it has no kymograph. `manifest.json` is version 2 (`parameters`, and per frame `t` and `values`). A sweep dir's earlier frames, sheet, kymograph, manifest and flipbook are cleared first. An empty list, a repeated name or preset, or a bad crop comes back as `INVALID: sweeps...`. A server before 0.32.0 strips `sweeps` and renders the rest. The `SWEEP nod` lines (the eye-pair and iris-pair gap range and the mouth width range along the nod at each turn, in face widths) and `SWEEP corner` lines (the additivity residual per landmark at the four corners, the rest term included; 0 on an additive rig) print once per call whenever `sweep` or `sweeps` was asked for, report-only like `FOLD` and `PHYSICS`."
6486
6978
  )
6487
6979
  }
6488
6980
  },
@@ -6491,16 +6983,21 @@ function createIkiMcpServer() {
6491
6983
  const r = await renderPoses(args);
6492
6984
  const text = r.ok ? [
6493
6985
  ...r.poses.map((p) => p.path),
6494
- ...r.sweep ? [
6495
- r.sweep.dir,
6496
- r.sweep.sheet,
6497
- r.sweep.kymograph,
6498
- r.sweep.flipbook,
6499
- r.sweep.manifest
6500
- ] : [],
6986
+ ...[...r.sweep ? [r.sweep] : [], ...r.sweeps ?? []].flatMap(
6987
+ (w) => [
6988
+ w.dir,
6989
+ w.sheet,
6990
+ ...w.kymograph ? [w.kymograph] : [],
6991
+ w.flipbook,
6992
+ w.manifest
6993
+ ]
6994
+ ),
6501
6995
  ...formatFoldReport(r.folds, r.modelCanvas),
6502
6996
  ...formatPhysicsReport(r.physics),
6503
- ...r.sweep ? formatSweepReport(r.sweep.report) : []
6997
+ ...r.sweep ?? r.sweeps?.[0] ? [
6998
+ ...formatSweepReport((r.sweep ?? r.sweeps[0]).report),
6999
+ ...formatNodReport((r.sweep ?? r.sweeps[0]).nod)
7000
+ ] : []
6504
7001
  ].join("\n") : `INVALID: ${r.error}`;
6505
7002
  return { content: [{ type: "text", text }], structuredContent: r };
6506
7003
  } catch (err) {