@ikijs/mcp 0.17.2 → 0.19.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/index.js CHANGED
@@ -58,10 +58,10 @@ var import_node_path = __toESM(require("path"));
58
58
  var MAX_LAYERS = 64;
59
59
  var MAX_LAYER_DIM = 4096;
60
60
  var MAX_CANVAS_DIM = 4096;
61
- var MAX_ATLAS_AREA = 4096 * 4096;
61
+ var MAX_ATLAS_SIDE = 4096;
62
62
  var MAX_INPUT_PIXELS = 4096 * 4096;
63
- var MAX_TOTAL_PIXELS = 64 * 1024 * 1024;
64
- var MAX_OUTPUT_BYTES = 5 * 1024 * 1024;
63
+ var MAX_TOTAL_PIXELS = 128 * 1024 * 1024;
64
+ var MAX_OUTPUT_BYTES = 12 * 1024 * 1024;
65
65
  var AutoRigInputError = class extends Error {
66
66
  constructor(message) {
67
67
  super(message);
@@ -362,6 +362,18 @@ var STANDARD_PARAMETER_INFO = [
362
362
  id: import_format.StandardParameter.AngleZ,
363
363
  description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
364
364
  },
365
+ {
366
+ id: import_format.StandardParameter.BodyAngleX,
367
+ description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
368
+ },
369
+ {
370
+ id: import_format.StandardParameter.BodyAngleY,
371
+ description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
372
+ },
373
+ {
374
+ id: import_format.StandardParameter.BodyAngleZ,
375
+ description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
376
+ },
365
377
  {
366
378
  id: import_format.StandardParameter.Breath,
367
379
  description: "Idle breath (0 .. 1), cycled by the host."
@@ -393,6 +405,22 @@ var STANDARD_PARAMETER_INFO = [
393
405
  {
394
406
  id: import_format.StandardParameter.HairSwayZ,
395
407
  description: "Hair-sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
408
+ },
409
+ {
410
+ id: import_format.StandardParameter.ArmLeft,
411
+ description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
412
+ },
413
+ {
414
+ id: import_format.StandardParameter.ArmRight,
415
+ description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
416
+ },
417
+ {
418
+ id: import_format.StandardParameter.ElbowLeft,
419
+ description: "Left elbow, degrees; positive bends the forearm the way positive ArmLeft raises the arm."
420
+ },
421
+ {
422
+ id: import_format.StandardParameter.ElbowRight,
423
+ description: "Right elbow, degrees; positive bends the forearm the way positive ArmRight raises the arm."
396
424
  }
397
425
  ];
398
426
  function listStandardParameters() {
@@ -412,9 +440,13 @@ async function renderAtlasPage(crops, quantizeColors) {
412
440
  const layout = (0, import_editor2.packAtlas)(
413
441
  crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
414
442
  );
415
- if (layout.pageWidth * layout.pageHeight > MAX_ATLAS_AREA) {
443
+ const over = layout.pageWidth > MAX_ATLAS_SIDE ? { side: "width", crop: "widest" } : layout.pageHeight > MAX_ATLAS_SIDE ? { side: "height", crop: "tallest" } : void 0;
444
+ if (over !== void 0) {
445
+ const crop = layout.placements.reduce(
446
+ (a, b) => b[over.side] > a[over.side] ? b : a
447
+ );
416
448
  throw new AutoRigInputError(
417
- `atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max area ${MAX_ATLAS_AREA}`
449
+ `atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max side ${MAX_ATLAS_SIDE} (its ${over.crop} crop: "${crop.id}" ${crop.width}x${crop.height})`
418
450
  );
419
451
  }
420
452
  const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
@@ -533,7 +565,9 @@ async function autoRigFromLayers(input) {
533
565
  }
534
566
  );
535
567
  } catch (e) {
536
- if (!(e instanceof import_editor2.TurnTargetError)) throw e;
568
+ if (!(e instanceof import_editor2.TurnTargetError || e instanceof import_editor2.LayerGeometryError)) {
569
+ throw e;
570
+ }
537
571
  throw new AutoRigInputError(e.message);
538
572
  }
539
573
  const doc = new import_editor2.EditorDocument(model);
@@ -552,18 +586,16 @@ async function autoRigFromLayers(input) {
552
586
  );
553
587
  }
554
588
  const partTextureAssignments = pages.flatMap(
555
- ({ crops: pageCrops, layout }) => pageCrops.map((crop) => {
589
+ ({ crops: pageCrops, layout }) => pageCrops.flatMap((crop) => {
556
590
  const placement2 = layout.placements.find((p) => p.id === crop.id);
557
591
  if (placement2 === void 0) {
558
592
  throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
559
593
  }
560
- return {
561
- partId: crop.id,
562
- uv: (0, import_editor2.uvRectFor)(placement2, {
563
- width: layout.pageWidth,
564
- height: layout.pageHeight
565
- })
566
- };
594
+ const uv = (0, import_editor2.uvRectFor)(placement2, {
595
+ width: layout.pageWidth,
596
+ height: layout.pageHeight
597
+ });
598
+ return (0, import_editor2.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
567
599
  })
568
600
  );
569
601
  doc.applyAtlas({
@@ -574,7 +606,9 @@ async function autoRigFromLayers(input) {
574
606
  if (losslessCrop !== void 0) {
575
607
  patched = structuredClone(patched);
576
608
  patched.textures = pages.map((p) => ({ source: p.dataUri }));
577
- patched.parts.find((p) => p.id === losslessCrop.id).texture.index = 1;
609
+ for (const partId of (0, import_editor2.partIdsOfRole)(losslessCrop.id)) {
610
+ patched.parts.find((p) => p.id === partId).texture.index = 1;
611
+ }
578
612
  }
579
613
  const finalModel = (0, import_format.parseIkiModel)(patched);
580
614
  writeFileAtomic(outPath, JSON.stringify(finalModel));
@@ -600,18 +634,89 @@ async function autoRigFromLayers(input) {
600
634
 
601
635
  // src/compose.ts
602
636
  var import_node_fs3 = __toESM(require("fs"));
603
- var import_node_path5 = __toESM(require("path"));
604
- var import_sharp2 = __toESM(require("sharp"));
605
- var import_editor5 = require("@ikijs/editor");
637
+ var import_node_path6 = __toESM(require("path"));
638
+ var import_sharp3 = __toESM(require("sharp"));
639
+ var import_editor7 = require("@ikijs/editor");
606
640
 
607
641
  // src/measure.ts
608
642
  var import_node_fs2 = __toESM(require("fs"));
609
- var import_node_path4 = __toESM(require("path"));
643
+ var import_node_path5 = __toESM(require("path"));
610
644
 
611
- // src/measure-turn.ts
645
+ // src/measure-arms.ts
612
646
  var import_node_path3 = __toESM(require("path"));
613
647
  var import_editor3 = require("@ikijs/editor");
648
+ var ARM_ROLES = ["arm_L", "arm_R"];
649
+ var CAP_OVERLAP = 0.5;
650
+ var px = (v) => `${Number(v.toFixed(1))}`;
651
+ async function measured(measurer, absDir, role) {
652
+ const fileName = `${role}.png`;
653
+ const { rgba } = await decodePng(import_node_path3.default.join(absDir, fileName));
654
+ return measurer.add({ role, fileName, rgba });
655
+ }
656
+ async function armWarnings(absDir, layers) {
657
+ const warnings = [];
658
+ const body = layers.body;
659
+ let set;
660
+ for (const arm of ARM_ROLES) {
661
+ const stats = layers[arm];
662
+ if (stats === void 0) continue;
663
+ if (body === void 0) {
664
+ warnings.push(
665
+ `${arm}: no body layer \u2014 an arm hangs from the body's shoulder, and auto_rig_from_layers refuses it.`
666
+ );
667
+ continue;
668
+ }
669
+ if (stats.canvasW !== body.canvasW || stats.canvasH !== body.canvasH) {
670
+ warnings.push(
671
+ `${arm}: its canvas ${stats.canvasW}x${stats.canvasH} differs from body's ${body.canvasW}x${body.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
672
+ );
673
+ continue;
674
+ }
675
+ if (set === void 0) {
676
+ const measurer = (0, import_editor3.createLayerSetMeasurer)({
677
+ width: body.canvasW,
678
+ height: body.canvasH
679
+ });
680
+ set = { measurer, body: await measured(measurer, absDir, "body") };
681
+ }
682
+ let g;
683
+ try {
684
+ g = (0, import_editor3.armGeometry)(
685
+ await measured(set.measurer, absDir, arm),
686
+ set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
687
+ );
688
+ } catch (err) {
689
+ if (err instanceof import_editor3.LayerGeometryError) {
690
+ warnings.push(
691
+ `${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
692
+ );
693
+ continue;
694
+ }
695
+ throw err;
696
+ }
697
+ const cap = capWarning(arm, g, set.body);
698
+ if (cap !== void 0) warnings.push(cap);
699
+ }
700
+ return warnings;
701
+ }
702
+ function capWarning(arm, g, body) {
703
+ const pivotX = g.shoulder.x + body.canvasW / 2;
704
+ const row = Math.floor(body.canvasH / 2 - g.shoulder.y);
705
+ const runs = body.rowRuns?.[row - body.bbox.y] ?? [];
706
+ if (runs.length === 0) {
707
+ return `${arm}: the body has no paint on its shoulder pivot's row (y=${row}) \u2014 the torso shows a gap beside the shoulder once the arm raises. Retune layout.${arm}.cy onto the shoulder (free).`;
708
+ }
709
+ const edge = g.side === 1 ? runs[runs.length - 1] : runs[0];
710
+ const overlap = g.shoulderRadius - g.side * (pivotX - edge);
711
+ const need = CAP_OVERLAP * g.shoulderRadius;
712
+ if (overlap >= need) return void 0;
713
+ 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).`;
714
+ }
715
+
716
+ // src/measure-turn.ts
717
+ var import_node_path4 = __toESM(require("path"));
614
718
  var import_editor4 = require("@ikijs/editor");
719
+ var import_editor5 = require("@ikijs/editor");
615
720
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
616
721
  var IRIS_V_MIN = 0.18;
617
722
  var IRIS_V_MAX = 0.95;
@@ -761,7 +866,7 @@ async function measureTurnImage(filePath, iris) {
761
866
  let transparent = false;
762
867
  if (hasAlpha) {
763
868
  for (let i = 0; i < n; i++) {
764
- if (rgba[i * 4 + 3] < import_editor3.ALPHA_OPAQUE) {
869
+ if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) {
765
870
  transparent = true;
766
871
  break;
767
872
  }
@@ -772,7 +877,7 @@ async function measureTurnImage(filePath, iris) {
772
877
  const fg = new Uint8Array(n);
773
878
  const value = new Float32Array(n);
774
879
  for (let i = 0; i < n; i++) {
775
- if (rgba[i * 4 + 3] < import_editor3.ALPHA_OPAQUE) continue;
880
+ if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) continue;
776
881
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
777
882
  if (maskMode === "alpha") {
778
883
  fg[i] = 1;
@@ -838,12 +943,12 @@ async function measureTurnImage(filePath, iris) {
838
943
  }
839
944
  const [irisL, irisR] = best.pair;
840
945
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
841
- const { left, right } = (0, import_editor3.foregroundSpan)(
946
+ const { left, right } = (0, import_editor4.foregroundSpan)(
842
947
  fg,
843
948
  width,
844
949
  height,
845
- eyeRow - import_editor3.HEAD_BAND,
846
- eyeRow + import_editor3.HEAD_BAND
950
+ eyeRow - import_editor4.HEAD_BAND,
951
+ eyeRow + import_editor4.HEAD_BAND
847
952
  );
848
953
  if (right <= left) {
849
954
  throw new AutoRigInputError(
@@ -867,7 +972,7 @@ async function measureTurnImage(filePath, iris) {
867
972
  left,
868
973
  right,
869
974
  cx: (left + right) / 2,
870
- half: (0, import_editor3.headHalfOf)({ left, right })
975
+ half: (0, import_editor4.headHalfOf)({ left, right })
871
976
  },
872
977
  pairCx: (irisL.cx + irisR.cx) / 2,
873
978
  eyeGap: irisR.cx - irisL.cx
@@ -882,9 +987,9 @@ function overlaySvg(m) {
882
987
  return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
883
988
  }
884
989
  async function writeOverlay(debugDir, label, m) {
885
- const outPath = import_node_path3.default.join(
990
+ const outPath = import_node_path4.default.join(
886
991
  debugDir,
887
- `${label}-${import_node_path3.default.basename(m.file, ".png")}.debug.png`
992
+ `${label}-${import_node_path4.default.basename(m.file, ".png")}.debug.png`
888
993
  );
889
994
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
890
995
  return outPath;
@@ -1049,6 +1154,7 @@ async function layerStats(filePath) {
1049
1154
  };
1050
1155
  }
1051
1156
  var pct = (v) => `${(v * 100).toFixed(0)}%`;
1157
+ var isArm = (role) => ARM_ROLES.includes(role);
1052
1158
  function noseSpeckWarning({ core, part }, source) {
1053
1159
  const [found, consequence] = source === "compose" ? [
1054
1160
  `the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
@@ -1057,7 +1163,7 @@ function noseSpeckWarning({ core, part }, source) {
1057
1163
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
1058
1164
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
1059
1165
  ];
1060
- return `nose: ${found} \u2014 under ${import_editor4.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.`;
1166
+ return `nose: ${found} \u2014 under ${import_editor5.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.`;
1061
1167
  }
1062
1168
  async function lashOffSclera(eyePath, lashPath) {
1063
1169
  const eye = await decodePng(eyePath);
@@ -1075,7 +1181,7 @@ async function lashOffSclera(eyePath, lashPath) {
1075
1181
  return { opaque, off };
1076
1182
  }
1077
1183
  async function measureDir(absDir, noseSpeck) {
1078
- const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
1184
+ const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
1079
1185
  if (files.length === 0) {
1080
1186
  throw new AutoRigInputError(`no role layers in ${absDir}`);
1081
1187
  }
@@ -1087,8 +1193,8 @@ async function measureDir(absDir, noseSpeck) {
1087
1193
  const layers = {};
1088
1194
  const empty = [];
1089
1195
  for (const f of files) {
1090
- const role = import_node_path4.default.basename(f, ".png");
1091
- const m = await layerStats(import_node_path4.default.join(absDir, f));
1196
+ const role = import_node_path5.default.basename(f, ".png");
1197
+ const m = await layerStats(import_node_path5.default.join(absDir, f));
1092
1198
  if (!m) {
1093
1199
  empty.push(role);
1094
1200
  continue;
@@ -1102,8 +1208,13 @@ async function measureDir(absDir, noseSpeck) {
1102
1208
  ["left", m.edgeLeft, m.h, m.marginLeft],
1103
1209
  ["right", m.edgeRight, m.h, m.marginRight]
1104
1210
  ];
1105
- if (role !== "body")
1211
+ if (role !== "body") {
1106
1212
  edges.push(["bottom", m.edgeBottom, m.w, m.marginBottom]);
1213
+ } else if (m.canvasH > m.canvasW && m.marginBottom === 0) {
1214
+ warnings.push(
1215
+ `body: its bottom row is the canvas's last \u2014 on a tall canvas that cuts the feet off. Free fix: raise canvasHeight (the canvas grows downward, nothing else moves) and remeasure; regenerate body.png only if the drawing itself stops short of the soles.`
1216
+ );
1217
+ }
1107
1218
  for (const [side, v, span, margin] of edges) {
1108
1219
  if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
1109
1220
  const remedy = margin === 0 ? (
@@ -1115,7 +1226,7 @@ async function measureDir(absDir, noseSpeck) {
1115
1226
  `it sits flush against the canvas ${side}, which a clipped placement and already-cropped art both produce. Move it inward first \u2014 retune layout.${role}.cx/cy/w, free \u2014 and remeasure; regenerate only if the edge is still opaque with margin to spare.`
1116
1227
  ) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
1117
1228
  warnings.push(
1118
- `${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns. Cause: ${remedy}`
1229
+ `${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam ${isArm(role) ? "once the arm raises" : "once the head turns"}. Cause: ${remedy}`
1119
1230
  );
1120
1231
  }
1121
1232
  }
@@ -1124,10 +1235,11 @@ async function measureDir(absDir, noseSpeck) {
1124
1235
  if (role === "body") continue;
1125
1236
  if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
1126
1237
  warnings.push(
1127
- `${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. It hides while the head faces front and opens into a seam on turn. Regenerate this part with the whole subject inside the frame.`
1238
+ `${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. ` + (isArm(role) ? `It hides at rest and opens into a seam once the arm raises. ` : `It hides while the head faces front and opens into a seam on turn. `) + `Regenerate this part with the whole subject inside the frame.`
1128
1239
  );
1129
1240
  }
1130
1241
  }
1242
+ warnings.push(...await armWarnings(absDir, layers));
1131
1243
  for (const side of ["L", "R"]) {
1132
1244
  const eye = layers[`eye_${side}`];
1133
1245
  const iris = layers[`iris_${side}`];
@@ -1156,8 +1268,8 @@ async function measureDir(absDir, noseSpeck) {
1156
1268
  }
1157
1269
  if (lash) {
1158
1270
  const { opaque, off } = await lashOffSclera(
1159
- import_node_path4.default.join(absDir, `eye_${side}.png`),
1160
- import_node_path4.default.join(absDir, `lash_${side}.png`)
1271
+ import_node_path5.default.join(absDir, `eye_${side}.png`),
1272
+ import_node_path5.default.join(absDir, `lash_${side}.png`)
1161
1273
  );
1162
1274
  const dTop = lash.marginTop - eye.marginTop;
1163
1275
  const faults = [
@@ -1183,11 +1295,11 @@ async function measureDir(absDir, noseSpeck) {
1183
1295
  if (noseSpeck !== void 0) {
1184
1296
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
1185
1297
  } else if (layers.nose !== void 0) {
1186
- const nose = await decodePng(import_node_path4.default.join(absDir, "nose.png"));
1187
- const core = (0, import_editor4.denseCoreOf)(nose.rgba, nose.width, nose.height);
1298
+ const nose = await decodePng(import_node_path5.default.join(absDir, "nose.png"));
1299
+ const core = (0, import_editor5.denseCoreOf)(nose.rgba, nose.width, nose.height);
1188
1300
  if (core !== null) {
1189
1301
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
1190
- if ((0, import_editor4.isSpeckCore)(core, crop))
1302
+ if ((0, import_editor5.isSpeckCore)(core, crop))
1191
1303
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
1192
1304
  }
1193
1305
  }
@@ -1244,8 +1356,54 @@ function formatMeasureReport(result) {
1244
1356
  return lines.join("\n");
1245
1357
  }
1246
1358
 
1359
+ // src/compose-arms.ts
1360
+ var import_sharp2 = __toESM(require("sharp"));
1361
+ var import_editor6 = require("@ikijs/editor");
1362
+ var ARM_WIDTH = 0.4;
1363
+ var SHOULDER_DROP = 0.12;
1364
+ async function armPlacement(role, cfg, part, body) {
1365
+ const { data } = await (0, import_sharp2.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1366
+ const layer = (0, import_editor6.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
1367
+ role,
1368
+ fileName: "arm.png",
1369
+ rgba: data
1370
+ });
1371
+ if (layer === null) {
1372
+ throw new AutoRigInputError(
1373
+ `layout.${role}: arm.png is empty after alpha threshold once resized`
1374
+ );
1375
+ }
1376
+ let shoulder;
1377
+ try {
1378
+ ({ shoulder } = (0, import_editor6.armGeometry)(
1379
+ layer,
1380
+ role === "arm_R" ? Infinity : -Infinity
1381
+ ));
1382
+ } catch (err) {
1383
+ if (err instanceof import_editor6.LayerGeometryError) {
1384
+ throw new AutoRigInputError(`layout.${role}: ${err.message}`);
1385
+ }
1386
+ throw err;
1387
+ }
1388
+ const pivotX = shoulder.x + part.w / 2;
1389
+ const pivotY = part.h / 2 - shoulder.y;
1390
+ const cornerX = role === "arm_R" ? body.left : body.left + body.w;
1391
+ const cornerY = body.top + SHOULDER_DROP * body.h;
1392
+ return {
1393
+ left: Math.round(
1394
+ cfg.cx === void 0 ? cornerX - pivotX : cfg.cx - part.w / 2
1395
+ ),
1396
+ top: Math.round(
1397
+ cfg.cy === void 0 ? cornerY - pivotY : cfg.cy - part.h / 2
1398
+ )
1399
+ };
1400
+ }
1401
+
1247
1402
  // src/compose.ts
1248
1403
  var CANVAS = 1100;
1404
+ function canvasName(canvas) {
1405
+ return canvas.width === canvas.height ? `${canvas.width}` : `${canvas.width}x${canvas.height}`;
1406
+ }
1249
1407
  var EYE_W = 98;
1250
1408
  var IRIS_W = 50;
1251
1409
  var EYEWHITE_SRC = "eyewhite.png";
@@ -1258,9 +1416,17 @@ var DEFAULT_LAYOUT = {
1258
1416
  // Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
1259
1417
  // without them still composes (head-only character).
1260
1418
  hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
1261
- // The torso, cut off by the canvas bottom, so the character is not a
1262
- // floating head. It rides its own `bodyDeformer`, which only breathes.
1419
+ // The bust's torso, cut off by a square canvas's bottom, so the character is
1420
+ // not a floating head; a full body on a tall canvas sets `layout.body`
1421
+ // itself. It rides the rig's `bodyWarp`, which the head hangs from.
1263
1422
  body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
1423
+ // The arms, one part for both: arm_R (screen left) takes arm.png as drawn
1424
+ // and arm_L mirrors it, like the blush. They draw over the body and under
1425
+ // the face. They have no cx/cy/w defaults: each is derived from the placed
1426
+ // body (ArmLayout). OPTIONAL and opt-in: a parts dir without arm.png
1427
+ // composes as a bust does, and `skipped` never lists them.
1428
+ arm_L: { src: "arm.png", optional: true, mirror: true },
1429
+ arm_R: { src: "arm.png", optional: true, mirror: false },
1264
1430
  // The face is drawn without a neck, so its box is the skull and centres
1265
1431
  // above the eye row (bob's skull at 437 against his eyes' 475).
1266
1432
  face: { src: "face.png", cx: 550, cy: 437, w: 400 },
@@ -1325,6 +1491,8 @@ var LOWER_LASH_SRC = "eyewhite_lash_lower.png";
1325
1491
  var ORDER = [
1326
1492
  "hair_back",
1327
1493
  "body",
1494
+ "arm_L",
1495
+ "arm_R",
1328
1496
  "face",
1329
1497
  "blush_L",
1330
1498
  "blush_R",
@@ -1363,7 +1531,7 @@ var FACE_FEATURES = [
1363
1531
  "brow_L",
1364
1532
  "brow_R"
1365
1533
  ];
1366
- function resolveLayout(overrides) {
1534
+ function resolveLayout(overrides, canvas) {
1367
1535
  const resolved = { ...DEFAULT_LAYOUT };
1368
1536
  if (overrides === void 0) return resolved;
1369
1537
  const sets = /* @__PURE__ */ new Map();
@@ -1388,9 +1556,10 @@ function resolveLayout(overrides) {
1388
1556
  for (const field of ["w", "h"]) {
1389
1557
  const value = override[field];
1390
1558
  if (value === void 0) continue;
1391
- if (!Number.isInteger(value) || value < 1 || value > CANVAS) {
1559
+ const max = field === "w" ? canvas.width : canvas.height;
1560
+ if (!Number.isInteger(value) || value < 1 || value > max) {
1392
1561
  throw new AutoRigInputError(
1393
- `layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
1562
+ `layout.${role}.${field} must be an integer in 1..${max}, got ${String(value)}`
1394
1563
  );
1395
1564
  }
1396
1565
  set[field] = value;
@@ -1418,10 +1587,22 @@ function resolveLayout(overrides) {
1418
1587
  for (const [role, set] of sets) {
1419
1588
  if (role === "face" || role === "nose") continue;
1420
1589
  if (FACE_FEATURES.includes(role)) continue;
1421
- resolved[role] = { ...resolved[role], ...set };
1590
+ mergeRole(resolved, role, set);
1422
1591
  }
1423
1592
  return resolved;
1424
1593
  }
1594
+ function mergeRole(resolved, role, set) {
1595
+ resolved[role] = { ...resolved[role], ...set };
1596
+ }
1597
+ function resolveCanvasHeight(value) {
1598
+ if (value === void 0) return CANVAS;
1599
+ if (!Number.isInteger(value) || value % 2 !== 0 || value < CANVAS || value > MAX_CANVAS_DIM) {
1600
+ throw new AutoRigInputError(
1601
+ `canvasHeight must be an even integer in ${CANVAS}..${MAX_CANVAS_DIM}, got ${String(value)}`
1602
+ );
1603
+ }
1604
+ return value;
1605
+ }
1425
1606
  function resolveMirrorParts(names) {
1426
1607
  const mirrored = /* @__PURE__ */ new Set();
1427
1608
  for (const [i, name] of (names ?? []).entries()) {
@@ -1444,20 +1625,20 @@ function keyWhiteToAlpha(rgba) {
1444
1625
  return keyed;
1445
1626
  }
1446
1627
  async function coreAndBoundsOf(png) {
1447
- const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1628
+ const { data, info } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1448
1629
  return {
1449
- core: (0, import_editor4.denseCoreOf)(data, info.width, info.height),
1630
+ core: (0, import_editor5.denseCoreOf)(data, info.width, info.height),
1450
1631
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
1451
1632
  };
1452
1633
  }
1453
1634
  async function hasCoverage(png) {
1454
- const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1455
- return (0, import_editor5.detectAlphaBbox)(data, info.width, info.height) !== null;
1635
+ const { data, info } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1636
+ return (0, import_editor7.detectAlphaBbox)(data, info.width, info.height) !== null;
1456
1637
  }
1457
1638
  async function noseSizingOf(png) {
1458
1639
  const { core, bounds } = await coreAndBoundsOf(png);
1459
1640
  if (core === null) return { box: bounds, whole: true };
1460
- if ((0, import_editor4.isSpeckCore)(core, bounds)) {
1641
+ if ((0, import_editor5.isSpeckCore)(core, bounds)) {
1461
1642
  return {
1462
1643
  box: bounds,
1463
1644
  whole: true,
@@ -1469,12 +1650,12 @@ async function noseSizingOf(png) {
1469
1650
  }
1470
1651
  return { box: core, whole: false };
1471
1652
  }
1472
- async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1653
+ async function partBuffer(role, cfg, partsDir, inMemory, flipSource, canvas) {
1473
1654
  let img;
1474
1655
  if (inMemory !== void 0) {
1475
- img = (0, import_sharp2.default)(inMemory);
1656
+ img = (0, import_sharp3.default)(inMemory);
1476
1657
  } else {
1477
- const srcPath = import_node_path5.default.join(partsDir, cfg.src);
1658
+ const srcPath = import_node_path6.default.join(partsDir, cfg.src);
1478
1659
  if (!import_node_fs3.default.existsSync(srcPath)) {
1479
1660
  if (cfg.optional) return null;
1480
1661
  throw new AutoRigInputError(
@@ -1482,14 +1663,14 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1482
1663
  );
1483
1664
  }
1484
1665
  const png = await decodePng(srcPath);
1485
- img = (0, import_sharp2.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
1666
+ img = (0, import_sharp3.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
1486
1667
  raw: { width: png.width, height: png.height, channels: 4 }
1487
1668
  });
1488
1669
  }
1489
1670
  if (!cfg.noTrim) {
1490
1671
  const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1491
1672
  const { width: keptW, height: keptH } = kept.info;
1492
- img = (0, import_sharp2.default)(kept.data, {
1673
+ img = (0, import_sharp3.default)(kept.data, {
1493
1674
  raw: { width: keptW, height: keptH, channels: 4 }
1494
1675
  });
1495
1676
  const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
@@ -1502,13 +1683,13 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1502
1683
  const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
1503
1684
  const width = Math.round(trimmedW * cfg.w / sized.w);
1504
1685
  const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
1505
- if (width > CANVAS || height > CANVAS) {
1506
- const field = width > CANVAS || cfg.h === void 0 ? "w" : "h";
1686
+ if (width > canvas.width || height > canvas.height) {
1687
+ const field = width > canvas.width || cfg.h === void 0 ? "w" : "h";
1507
1688
  throw new AutoRigInputError(
1508
- `layout.${role}.${field}: resized part ${width}x${height} exceeds the ${CANVAS} canvas`
1689
+ `layout.${role}.${field}: resized part ${width}x${height} exceeds the ${canvasName(canvas)} canvas`
1509
1690
  );
1510
1691
  }
1511
- const resized = await (0, import_sharp2.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
1692
+ const resized = await (0, import_sharp3.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
1512
1693
  return {
1513
1694
  buf: resized.data,
1514
1695
  w: resized.info.width,
@@ -1516,20 +1697,20 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1516
1697
  nose
1517
1698
  };
1518
1699
  }
1519
- function assertOnCanvas(source, w, h, left, top) {
1520
- if (left + w <= 0 || top + h <= 0 || left >= CANVAS || top >= CANVAS) {
1700
+ function assertOnCanvas(source, w, h, left, top, canvas) {
1701
+ if (left + w <= 0 || top + h <= 0 || left >= canvas.width || top >= canvas.height) {
1521
1702
  throw new AutoRigInputError(
1522
- `${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${CANVAS} canvas`
1703
+ `${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${canvasName(canvas)} canvas`
1523
1704
  );
1524
1705
  }
1525
1706
  }
1526
- function placement(role, cfg, w, h) {
1707
+ function placement(role, cfg, w, h, canvas) {
1527
1708
  const left = Math.round(cfg.cx - w / 2);
1528
1709
  const top = Math.round(cfg.cy - h / 2);
1529
- assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
1710
+ assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
1530
1711
  return { left, top };
1531
1712
  }
1532
- function nosePlacement(layout, box, w, h) {
1713
+ function nosePlacement(layout, box, w, h, canvas) {
1533
1714
  const { cx, cy } = layout.nose;
1534
1715
  const left = Math.round(cx - (box.x + box.w / 2));
1535
1716
  let top;
@@ -1547,15 +1728,16 @@ function nosePlacement(layout, box, w, h) {
1547
1728
  w,
1548
1729
  h,
1549
1730
  left,
1550
- top
1731
+ top,
1732
+ canvas
1551
1733
  );
1552
1734
  return { left, top };
1553
1735
  }
1554
- function blankCanvas() {
1555
- return (0, import_sharp2.default)({
1736
+ function blankCanvas(canvas) {
1737
+ return (0, import_sharp3.default)({
1556
1738
  create: {
1557
- width: CANVAS,
1558
- height: CANVAS,
1739
+ width: canvas.width,
1740
+ height: canvas.height,
1559
1741
  channels: 4,
1560
1742
  background: { r: 0, g: 0, b: 0, alpha: 0 }
1561
1743
  }
@@ -1587,15 +1769,15 @@ function boxWithoutStraySpecks(rgba, W, H) {
1587
1769
  while (depth > 0) {
1588
1770
  const p = stack[--depth];
1589
1771
  size++;
1590
- if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
1591
- const px = p % W;
1592
- const py = (p - px) / W;
1593
- setLeft = Math.min(setLeft, px);
1772
+ if (rgba[p * 4 + 3] >= import_editor7.ALPHA_OPAQUE) opaque = true;
1773
+ const px2 = p % W;
1774
+ const py = (p - px2) / W;
1775
+ setLeft = Math.min(setLeft, px2);
1594
1776
  setTop = Math.min(setTop, py);
1595
- setRight = Math.max(setRight, px);
1777
+ setRight = Math.max(setRight, px2);
1596
1778
  setBottom = Math.max(setBottom, py);
1597
1779
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
1598
- for (let x = Math.max(0, px - 1); x <= Math.min(W - 1, px + 1); x++) {
1780
+ for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
1599
1781
  const q = y * W + x;
1600
1782
  if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
1601
1783
  visited[q] = 1;
@@ -1628,15 +1810,15 @@ function detachedAboveWhite(rgba, W, H) {
1628
1810
  for (let p = 0; p < n; p++) {
1629
1811
  const alpha = rgba[p * 4 + 3];
1630
1812
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
1631
- ink[p] = alpha >= import_editor5.ALPHA_OPAQUE ? 2 : 1;
1813
+ ink[p] = alpha >= import_editor7.ALPHA_OPAQUE ? 2 : 1;
1632
1814
  }
1633
1815
  const label = new Int32Array(n).fill(-1);
1634
1816
  const stack = new Int32Array(n);
1635
1817
  const near = (p, visit) => {
1636
- const px = p % W;
1637
- const py = (p - px) / W;
1818
+ const px2 = p % W;
1819
+ const py = (p - px2) / W;
1638
1820
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
1639
- for (let x = Math.max(0, px - 1); x <= Math.min(W - 1, px + 1); x++) {
1821
+ for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
1640
1822
  visit(y * W + x);
1641
1823
  }
1642
1824
  }
@@ -1708,7 +1890,7 @@ function detachedAboveWhite(rgba, W, H) {
1708
1890
  return detached;
1709
1891
  }
1710
1892
  async function prepEyeSplit(partsDir) {
1711
- const srcPath = import_node_path5.default.join(partsDir, EYEWHITE_SRC);
1893
+ const srcPath = import_node_path6.default.join(partsDir, EYEWHITE_SRC);
1712
1894
  if (!import_node_fs3.default.existsSync(srcPath)) {
1713
1895
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
1714
1896
  }
@@ -1769,7 +1951,11 @@ async function composeLayersFromParts(input) {
1769
1951
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
1770
1952
  );
1771
1953
  }
1772
- const layout = resolveLayout(input.layout);
1954
+ const canvas = {
1955
+ width: CANVAS,
1956
+ height: resolveCanvasHeight(input.canvasHeight)
1957
+ };
1958
+ const layout = resolveLayout(input.layout, canvas);
1773
1959
  const mirrored = resolveMirrorParts(input.mirrorParts);
1774
1960
  const split = await prepEyeSplit(partsDir);
1775
1961
  const splitSources = /* @__PURE__ */ new Map([
@@ -1789,6 +1975,44 @@ async function composeLayersFromParts(input) {
1789
1975
  skipped.push(role);
1790
1976
  continue;
1791
1977
  }
1978
+ if (key === "arm_L" || key === "arm_R") {
1979
+ const arm = layout[key];
1980
+ if (!import_node_fs3.default.existsSync(import_node_path6.default.join(partsDir, arm.src))) continue;
1981
+ const body = placed.find((p) => p.role === "body");
1982
+ if (body === void 0) {
1983
+ throw new AutoRigInputError(
1984
+ "arm.png: an arm needs body.png \u2014 the composer hangs each arm on the body's shoulder, and auto_rig_from_layers hangs it from the body"
1985
+ );
1986
+ }
1987
+ const w = arm.w ?? Math.max(1, Math.round(ARM_WIDTH * body.part.w));
1988
+ const part2 = await partBuffer(
1989
+ role,
1990
+ { ...arm, w },
1991
+ partsDir,
1992
+ void 0,
1993
+ mirrored.has(arm.src),
1994
+ canvas
1995
+ );
1996
+ const { left: left2, top: top2 } = await armPlacement(key, arm, part2, {
1997
+ left: body.left,
1998
+ top: body.top,
1999
+ w: body.part.w,
2000
+ h: body.part.h
2001
+ });
2002
+ const unset = ["cx", "cy"].filter(
2003
+ (field) => arm[field] === void 0
2004
+ );
2005
+ assertOnCanvas(
2006
+ unset.length === 0 ? `layout.${key}.cx/cy` : `layout.${key}.cx/cy (${unset.join("/")} unset: its shoulder pivot hangs on the shoulder corner of layout.body's box)`,
2007
+ part2.w,
2008
+ part2.h,
2009
+ left2,
2010
+ top2,
2011
+ canvas
2012
+ );
2013
+ placed.push({ role, part: part2, left: left2, top: top2 });
2014
+ continue;
2015
+ }
1792
2016
  const cfg = lower ? { ...layout[key], src: LOWER_LASH_SRC } : layout[key];
1793
2017
  const inMemory = splitSources.get(cfg.src);
1794
2018
  const part = await partBuffer(
@@ -1797,7 +2021,8 @@ async function composeLayersFromParts(input) {
1797
2021
  partsDir,
1798
2022
  inMemory,
1799
2023
  // The split halves are cut from eyewhite.png, the file a caller names.
1800
- mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
2024
+ mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC),
2025
+ canvas
1801
2026
  );
1802
2027
  if (part === null || lower && !await hasCoverage(part.buf)) {
1803
2028
  skipped.push(role);
@@ -1809,9 +2034,9 @@ async function composeLayersFromParts(input) {
1809
2034
  noseSpeck = part.nose?.speck;
1810
2035
  const { core, bounds } = await coreAndBoundsOf(part.buf);
1811
2036
  const box = part.nose?.whole ? bounds : core ?? bounds;
1812
- ({ left, top } = nosePlacement(layout, box, part.w, part.h));
2037
+ ({ left, top } = nosePlacement(layout, box, part.w, part.h, canvas));
1813
2038
  } else {
1814
- ({ left, top } = placement(key, layout[key], part.w, part.h));
2039
+ ({ left, top } = placement(key, layout[key], part.w, part.h, canvas));
1815
2040
  }
1816
2041
  if (role === "lash_L" || role === "lash_R") {
1817
2042
  const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
@@ -1824,14 +2049,15 @@ async function composeLayersFromParts(input) {
1824
2049
  }
1825
2050
  placed.push({ role, part, left, top });
1826
2051
  }
1827
- for (const role of skipped) {
1828
- import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
2052
+ for (const role of ORDER) {
2053
+ if (placed.some((p) => p.role === role)) continue;
2054
+ import_node_fs3.default.rmSync(import_node_path6.default.join(outDir, `${role}.png`), { force: true });
1829
2055
  }
1830
2056
  const layers = [];
1831
2057
  const preview = [];
1832
2058
  for (const { role, part, left, top } of placed) {
1833
- const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
1834
- const outPath = import_node_path5.default.join(outDir, `${role}.png`);
2059
+ const layer = await blankCanvas(canvas).composite([{ input: part.buf, left, top }]).png().toBuffer();
2060
+ const outPath = import_node_path6.default.join(outDir, `${role}.png`);
1835
2061
  writeFileAtomic(outPath, layer);
1836
2062
  layers.push({
1837
2063
  role,
@@ -1843,15 +2069,15 @@ async function composeLayersFromParts(input) {
1843
2069
  });
1844
2070
  preview.push({ input: part.buf, left, top });
1845
2071
  }
1846
- const previewPng = await (0, import_sharp2.default)({
2072
+ const previewPng = await (0, import_sharp3.default)({
1847
2073
  create: {
1848
- width: CANVAS,
1849
- height: CANVAS,
2074
+ width: canvas.width,
2075
+ height: canvas.height,
1850
2076
  channels: 4,
1851
2077
  background: { r: 245, g: 245, b: 248, alpha: 1 }
1852
2078
  }
1853
2079
  }).composite(preview).png().toBuffer();
1854
- const previewPath = import_node_path5.default.join(outDir, "preview.png");
2080
+ const previewPath = import_node_path6.default.join(outDir, "preview.png");
1855
2081
  writeFileAtomic(previewPath, previewPng);
1856
2082
  return {
1857
2083
  ok: true,
@@ -1872,7 +2098,7 @@ async function composeLayersFromParts(input) {
1872
2098
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1873
2099
  var import_zod = require("zod");
1874
2100
  function createIkiMcpServer() {
1875
- const server = new import_mcp.McpServer({ name: "iki", version: "0.17.2" });
2101
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.19.0" });
1876
2102
  server.registerTool(
1877
2103
  "validate_iki",
1878
2104
  {
@@ -1937,7 +2163,7 @@ function createIkiMcpServer() {
1937
2163
  server.registerTool(
1938
2164
  "auto_rig_from_layers",
1939
2165
  {
1940
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, etc. optional) 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.",
2166
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, etc. optional; an arm needs the body) 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.",
1941
2167
  inputSchema: {
1942
2168
  layers: import_zod.z.array(
1943
2169
  import_zod.z.object({
@@ -1992,13 +2218,13 @@ function createIkiMcpServer() {
1992
2218
  server.registerTool(
1993
2219
  "compose_layers_from_parts",
1994
2220
  {
1995
- 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, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, 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). 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`.",
2221
+ 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, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, 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`). 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, and an arm whose shoulder cap does not reach under the torso's edge. 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`.",
1996
2222
  inputSchema: {
1997
2223
  partsDir: import_zod.z.string().describe(
1998
2224
  "Directory of the source part PNGs (resolved against cwd)."
1999
2225
  ),
2000
2226
  outDir: import_zod.z.string().describe(
2001
- "Existing directory to write the role layer PNGs + preview.png into (resolved against cwd; must already exist; confined to the working directory). Reused across runs: a role this run skips has its stale PNG from an earlier run deleted."
2227
+ "Existing directory to write the role layer PNGs + preview.png into (resolved against cwd; must already exist; confined to the working directory). Reused across runs: a role this run does not write \u2014 one it skips, or an arm once arm.png is gone \u2014 has its stale PNG from an earlier run deleted."
2002
2228
  ),
2003
2229
  layout: import_zod.z.record(
2004
2230
  import_zod.z.string(),
@@ -2009,10 +2235,13 @@ function createIkiMcpServer() {
2009
2235
  h: import_zod.z.number()
2010
2236
  }).partial()
2011
2237
  ).optional().describe(
2012
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, blush_L, blush_R, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; 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, 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."
2238
+ "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, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \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, 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. 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."
2013
2239
  ),
2014
2240
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
2015
- "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), and 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); 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."
2241
+ "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), and arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top); 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."
2242
+ ),
2243
+ canvasHeight: import_zod.z.number().optional().describe(
2244
+ "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."
2016
2245
  )
2017
2246
  }
2018
2247
  },
@@ -2037,7 +2266,7 @@ function createIkiMcpServer() {
2037
2266
  server.registerTool(
2038
2267
  "measure_layers",
2039
2268
  {
2040
- 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). 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.",
2269
+ 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). 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.",
2041
2270
  inputSchema: {
2042
2271
  layersDir: import_zod.z.string().describe(
2043
2272
  "Directory of role-named layer PNGs (resolved against cwd)."