@ikijs/mcp 0.18.0 → 0.19.1

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);
@@ -416,11 +416,11 @@ var STANDARD_PARAMETER_INFO = [
416
416
  },
417
417
  {
418
418
  id: import_format.StandardParameter.ElbowLeft,
419
- description: "Left elbow, degrees; positive bends the forearm the way positive ArmLeft raises the arm."
419
+ description: "Left elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the right)."
420
420
  },
421
421
  {
422
422
  id: import_format.StandardParameter.ElbowRight,
423
- description: "Right elbow, degrees; positive bends the forearm the way positive ArmRight raises the arm."
423
+ description: "Right elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the left)."
424
424
  }
425
425
  ];
426
426
  function listStandardParameters() {
@@ -440,9 +440,13 @@ async function renderAtlasPage(crops, quantizeColors) {
440
440
  const layout = (0, import_editor2.packAtlas)(
441
441
  crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
442
442
  );
443
- 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
+ );
444
448
  throw new AutoRigInputError(
445
- `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})`
446
450
  );
447
451
  }
448
452
  const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
@@ -630,18 +634,89 @@ async function autoRigFromLayers(input) {
630
634
 
631
635
  // src/compose.ts
632
636
  var import_node_fs3 = __toESM(require("fs"));
633
- var import_node_path5 = __toESM(require("path"));
634
- var import_sharp2 = __toESM(require("sharp"));
635
- 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");
636
640
 
637
641
  // src/measure.ts
638
642
  var import_node_fs2 = __toESM(require("fs"));
639
- var import_node_path4 = __toESM(require("path"));
643
+ var import_node_path5 = __toESM(require("path"));
640
644
 
641
- // src/measure-turn.ts
645
+ // src/measure-arms.ts
642
646
  var import_node_path3 = __toESM(require("path"));
643
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"));
644
718
  var import_editor4 = require("@ikijs/editor");
719
+ var import_editor5 = require("@ikijs/editor");
645
720
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
646
721
  var IRIS_V_MIN = 0.18;
647
722
  var IRIS_V_MAX = 0.95;
@@ -791,7 +866,7 @@ async function measureTurnImage(filePath, iris) {
791
866
  let transparent = false;
792
867
  if (hasAlpha) {
793
868
  for (let i = 0; i < n; i++) {
794
- if (rgba[i * 4 + 3] < import_editor3.ALPHA_OPAQUE) {
869
+ if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) {
795
870
  transparent = true;
796
871
  break;
797
872
  }
@@ -802,7 +877,7 @@ async function measureTurnImage(filePath, iris) {
802
877
  const fg = new Uint8Array(n);
803
878
  const value = new Float32Array(n);
804
879
  for (let i = 0; i < n; i++) {
805
- if (rgba[i * 4 + 3] < import_editor3.ALPHA_OPAQUE) continue;
880
+ if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) continue;
806
881
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
807
882
  if (maskMode === "alpha") {
808
883
  fg[i] = 1;
@@ -868,12 +943,12 @@ async function measureTurnImage(filePath, iris) {
868
943
  }
869
944
  const [irisL, irisR] = best.pair;
870
945
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
871
- const { left, right } = (0, import_editor3.foregroundSpan)(
946
+ const { left, right } = (0, import_editor4.foregroundSpan)(
872
947
  fg,
873
948
  width,
874
949
  height,
875
- eyeRow - import_editor3.HEAD_BAND,
876
- eyeRow + import_editor3.HEAD_BAND
950
+ eyeRow - import_editor4.HEAD_BAND,
951
+ eyeRow + import_editor4.HEAD_BAND
877
952
  );
878
953
  if (right <= left) {
879
954
  throw new AutoRigInputError(
@@ -897,7 +972,7 @@ async function measureTurnImage(filePath, iris) {
897
972
  left,
898
973
  right,
899
974
  cx: (left + right) / 2,
900
- half: (0, import_editor3.headHalfOf)({ left, right })
975
+ half: (0, import_editor4.headHalfOf)({ left, right })
901
976
  },
902
977
  pairCx: (irisL.cx + irisR.cx) / 2,
903
978
  eyeGap: irisR.cx - irisL.cx
@@ -912,9 +987,9 @@ function overlaySvg(m) {
912
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>";
913
988
  }
914
989
  async function writeOverlay(debugDir, label, m) {
915
- const outPath = import_node_path3.default.join(
990
+ const outPath = import_node_path4.default.join(
916
991
  debugDir,
917
- `${label}-${import_node_path3.default.basename(m.file, ".png")}.debug.png`
992
+ `${label}-${import_node_path4.default.basename(m.file, ".png")}.debug.png`
918
993
  );
919
994
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
920
995
  return outPath;
@@ -1079,6 +1154,7 @@ async function layerStats(filePath) {
1079
1154
  };
1080
1155
  }
1081
1156
  var pct = (v) => `${(v * 100).toFixed(0)}%`;
1157
+ var isArm = (role) => ARM_ROLES.includes(role);
1082
1158
  function noseSpeckWarning({ core, part }, source) {
1083
1159
  const [found, consequence] = source === "compose" ? [
1084
1160
  `the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
@@ -1087,7 +1163,7 @@ function noseSpeckWarning({ core, part }, source) {
1087
1163
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
1088
1164
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
1089
1165
  ];
1090
- 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.`;
1091
1167
  }
1092
1168
  async function lashOffSclera(eyePath, lashPath) {
1093
1169
  const eye = await decodePng(eyePath);
@@ -1105,7 +1181,7 @@ async function lashOffSclera(eyePath, lashPath) {
1105
1181
  return { opaque, off };
1106
1182
  }
1107
1183
  async function measureDir(absDir, noseSpeck) {
1108
- 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();
1109
1185
  if (files.length === 0) {
1110
1186
  throw new AutoRigInputError(`no role layers in ${absDir}`);
1111
1187
  }
@@ -1117,8 +1193,8 @@ async function measureDir(absDir, noseSpeck) {
1117
1193
  const layers = {};
1118
1194
  const empty = [];
1119
1195
  for (const f of files) {
1120
- const role = import_node_path4.default.basename(f, ".png");
1121
- 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));
1122
1198
  if (!m) {
1123
1199
  empty.push(role);
1124
1200
  continue;
@@ -1132,8 +1208,13 @@ async function measureDir(absDir, noseSpeck) {
1132
1208
  ["left", m.edgeLeft, m.h, m.marginLeft],
1133
1209
  ["right", m.edgeRight, m.h, m.marginRight]
1134
1210
  ];
1135
- if (role !== "body")
1211
+ if (role !== "body") {
1136
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
+ }
1137
1218
  for (const [side, v, span, margin] of edges) {
1138
1219
  if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
1139
1220
  const remedy = margin === 0 ? (
@@ -1145,7 +1226,7 @@ async function measureDir(absDir, noseSpeck) {
1145
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.`
1146
1227
  ) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
1147
1228
  warnings.push(
1148
- `${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}`
1149
1230
  );
1150
1231
  }
1151
1232
  }
@@ -1154,10 +1235,11 @@ async function measureDir(absDir, noseSpeck) {
1154
1235
  if (role === "body") continue;
1155
1236
  if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
1156
1237
  warnings.push(
1157
- `${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.`
1158
1239
  );
1159
1240
  }
1160
1241
  }
1242
+ warnings.push(...await armWarnings(absDir, layers));
1161
1243
  for (const side of ["L", "R"]) {
1162
1244
  const eye = layers[`eye_${side}`];
1163
1245
  const iris = layers[`iris_${side}`];
@@ -1186,8 +1268,8 @@ async function measureDir(absDir, noseSpeck) {
1186
1268
  }
1187
1269
  if (lash) {
1188
1270
  const { opaque, off } = await lashOffSclera(
1189
- import_node_path4.default.join(absDir, `eye_${side}.png`),
1190
- 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`)
1191
1273
  );
1192
1274
  const dTop = lash.marginTop - eye.marginTop;
1193
1275
  const faults = [
@@ -1213,11 +1295,11 @@ async function measureDir(absDir, noseSpeck) {
1213
1295
  if (noseSpeck !== void 0) {
1214
1296
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
1215
1297
  } else if (layers.nose !== void 0) {
1216
- const nose = await decodePng(import_node_path4.default.join(absDir, "nose.png"));
1217
- 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);
1218
1300
  if (core !== null) {
1219
1301
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
1220
- if ((0, import_editor4.isSpeckCore)(core, crop))
1302
+ if ((0, import_editor5.isSpeckCore)(core, crop))
1221
1303
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
1222
1304
  }
1223
1305
  }
@@ -1274,8 +1356,54 @@ function formatMeasureReport(result) {
1274
1356
  return lines.join("\n");
1275
1357
  }
1276
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
+
1277
1402
  // src/compose.ts
1278
1403
  var CANVAS = 1100;
1404
+ function canvasName(canvas) {
1405
+ return canvas.width === canvas.height ? `${canvas.width}` : `${canvas.width}x${canvas.height}`;
1406
+ }
1279
1407
  var EYE_W = 98;
1280
1408
  var IRIS_W = 50;
1281
1409
  var EYEWHITE_SRC = "eyewhite.png";
@@ -1288,9 +1416,17 @@ var DEFAULT_LAYOUT = {
1288
1416
  // Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
1289
1417
  // without them still composes (head-only character).
1290
1418
  hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
1291
- // The torso, cut off by the canvas bottom, so the character is not a
1292
- // floating head. It rides the rig's `bodyWarp`, which the head hangs from.
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.
1293
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 },
1294
1430
  // The face is drawn without a neck, so its box is the skull and centres
1295
1431
  // above the eye row (bob's skull at 437 against his eyes' 475).
1296
1432
  face: { src: "face.png", cx: 550, cy: 437, w: 400 },
@@ -1355,6 +1491,8 @@ var LOWER_LASH_SRC = "eyewhite_lash_lower.png";
1355
1491
  var ORDER = [
1356
1492
  "hair_back",
1357
1493
  "body",
1494
+ "arm_L",
1495
+ "arm_R",
1358
1496
  "face",
1359
1497
  "blush_L",
1360
1498
  "blush_R",
@@ -1393,7 +1531,7 @@ var FACE_FEATURES = [
1393
1531
  "brow_L",
1394
1532
  "brow_R"
1395
1533
  ];
1396
- function resolveLayout(overrides) {
1534
+ function resolveLayout(overrides, canvas) {
1397
1535
  const resolved = { ...DEFAULT_LAYOUT };
1398
1536
  if (overrides === void 0) return resolved;
1399
1537
  const sets = /* @__PURE__ */ new Map();
@@ -1418,9 +1556,10 @@ function resolveLayout(overrides) {
1418
1556
  for (const field of ["w", "h"]) {
1419
1557
  const value = override[field];
1420
1558
  if (value === void 0) continue;
1421
- 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) {
1422
1561
  throw new AutoRigInputError(
1423
- `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)}`
1424
1563
  );
1425
1564
  }
1426
1565
  set[field] = value;
@@ -1448,10 +1587,22 @@ function resolveLayout(overrides) {
1448
1587
  for (const [role, set] of sets) {
1449
1588
  if (role === "face" || role === "nose") continue;
1450
1589
  if (FACE_FEATURES.includes(role)) continue;
1451
- resolved[role] = { ...resolved[role], ...set };
1590
+ mergeRole(resolved, role, set);
1452
1591
  }
1453
1592
  return resolved;
1454
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
+ }
1455
1606
  function resolveMirrorParts(names) {
1456
1607
  const mirrored = /* @__PURE__ */ new Set();
1457
1608
  for (const [i, name] of (names ?? []).entries()) {
@@ -1474,20 +1625,20 @@ function keyWhiteToAlpha(rgba) {
1474
1625
  return keyed;
1475
1626
  }
1476
1627
  async function coreAndBoundsOf(png) {
1477
- 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 });
1478
1629
  return {
1479
- core: (0, import_editor4.denseCoreOf)(data, info.width, info.height),
1630
+ core: (0, import_editor5.denseCoreOf)(data, info.width, info.height),
1480
1631
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
1481
1632
  };
1482
1633
  }
1483
1634
  async function hasCoverage(png) {
1484
- const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1485
- 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;
1486
1637
  }
1487
1638
  async function noseSizingOf(png) {
1488
1639
  const { core, bounds } = await coreAndBoundsOf(png);
1489
1640
  if (core === null) return { box: bounds, whole: true };
1490
- if ((0, import_editor4.isSpeckCore)(core, bounds)) {
1641
+ if ((0, import_editor5.isSpeckCore)(core, bounds)) {
1491
1642
  return {
1492
1643
  box: bounds,
1493
1644
  whole: true,
@@ -1499,12 +1650,12 @@ async function noseSizingOf(png) {
1499
1650
  }
1500
1651
  return { box: core, whole: false };
1501
1652
  }
1502
- async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1653
+ async function partBuffer(role, cfg, partsDir, inMemory, flipSource, canvas) {
1503
1654
  let img;
1504
1655
  if (inMemory !== void 0) {
1505
- img = (0, import_sharp2.default)(inMemory);
1656
+ img = (0, import_sharp3.default)(inMemory);
1506
1657
  } else {
1507
- const srcPath = import_node_path5.default.join(partsDir, cfg.src);
1658
+ const srcPath = import_node_path6.default.join(partsDir, cfg.src);
1508
1659
  if (!import_node_fs3.default.existsSync(srcPath)) {
1509
1660
  if (cfg.optional) return null;
1510
1661
  throw new AutoRigInputError(
@@ -1512,14 +1663,14 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1512
1663
  );
1513
1664
  }
1514
1665
  const png = await decodePng(srcPath);
1515
- 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), {
1516
1667
  raw: { width: png.width, height: png.height, channels: 4 }
1517
1668
  });
1518
1669
  }
1519
1670
  if (!cfg.noTrim) {
1520
1671
  const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1521
1672
  const { width: keptW, height: keptH } = kept.info;
1522
- img = (0, import_sharp2.default)(kept.data, {
1673
+ img = (0, import_sharp3.default)(kept.data, {
1523
1674
  raw: { width: keptW, height: keptH, channels: 4 }
1524
1675
  });
1525
1676
  const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
@@ -1532,13 +1683,13 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1532
1683
  const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
1533
1684
  const width = Math.round(trimmedW * cfg.w / sized.w);
1534
1685
  const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
1535
- if (width > CANVAS || height > CANVAS) {
1536
- 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";
1537
1688
  throw new AutoRigInputError(
1538
- `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`
1539
1690
  );
1540
1691
  }
1541
- 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 });
1542
1693
  return {
1543
1694
  buf: resized.data,
1544
1695
  w: resized.info.width,
@@ -1546,20 +1697,20 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1546
1697
  nose
1547
1698
  };
1548
1699
  }
1549
- function assertOnCanvas(source, w, h, left, top) {
1550
- 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) {
1551
1702
  throw new AutoRigInputError(
1552
- `${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`
1553
1704
  );
1554
1705
  }
1555
1706
  }
1556
- function placement(role, cfg, w, h) {
1707
+ function placement(role, cfg, w, h, canvas) {
1557
1708
  const left = Math.round(cfg.cx - w / 2);
1558
1709
  const top = Math.round(cfg.cy - h / 2);
1559
- assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
1710
+ assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
1560
1711
  return { left, top };
1561
1712
  }
1562
- function nosePlacement(layout, box, w, h) {
1713
+ function nosePlacement(layout, box, w, h, canvas) {
1563
1714
  const { cx, cy } = layout.nose;
1564
1715
  const left = Math.round(cx - (box.x + box.w / 2));
1565
1716
  let top;
@@ -1577,15 +1728,16 @@ function nosePlacement(layout, box, w, h) {
1577
1728
  w,
1578
1729
  h,
1579
1730
  left,
1580
- top
1731
+ top,
1732
+ canvas
1581
1733
  );
1582
1734
  return { left, top };
1583
1735
  }
1584
- function blankCanvas() {
1585
- return (0, import_sharp2.default)({
1736
+ function blankCanvas(canvas) {
1737
+ return (0, import_sharp3.default)({
1586
1738
  create: {
1587
- width: CANVAS,
1588
- height: CANVAS,
1739
+ width: canvas.width,
1740
+ height: canvas.height,
1589
1741
  channels: 4,
1590
1742
  background: { r: 0, g: 0, b: 0, alpha: 0 }
1591
1743
  }
@@ -1617,15 +1769,15 @@ function boxWithoutStraySpecks(rgba, W, H) {
1617
1769
  while (depth > 0) {
1618
1770
  const p = stack[--depth];
1619
1771
  size++;
1620
- if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
1621
- const px = p % W;
1622
- const py = (p - px) / W;
1623
- 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);
1624
1776
  setTop = Math.min(setTop, py);
1625
- setRight = Math.max(setRight, px);
1777
+ setRight = Math.max(setRight, px2);
1626
1778
  setBottom = Math.max(setBottom, py);
1627
1779
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
1628
- 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++) {
1629
1781
  const q = y * W + x;
1630
1782
  if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
1631
1783
  visited[q] = 1;
@@ -1658,15 +1810,15 @@ function detachedAboveWhite(rgba, W, H) {
1658
1810
  for (let p = 0; p < n; p++) {
1659
1811
  const alpha = rgba[p * 4 + 3];
1660
1812
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
1661
- ink[p] = alpha >= import_editor5.ALPHA_OPAQUE ? 2 : 1;
1813
+ ink[p] = alpha >= import_editor7.ALPHA_OPAQUE ? 2 : 1;
1662
1814
  }
1663
1815
  const label = new Int32Array(n).fill(-1);
1664
1816
  const stack = new Int32Array(n);
1665
1817
  const near = (p, visit) => {
1666
- const px = p % W;
1667
- const py = (p - px) / W;
1818
+ const px2 = p % W;
1819
+ const py = (p - px2) / W;
1668
1820
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
1669
- 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++) {
1670
1822
  visit(y * W + x);
1671
1823
  }
1672
1824
  }
@@ -1738,7 +1890,7 @@ function detachedAboveWhite(rgba, W, H) {
1738
1890
  return detached;
1739
1891
  }
1740
1892
  async function prepEyeSplit(partsDir) {
1741
- const srcPath = import_node_path5.default.join(partsDir, EYEWHITE_SRC);
1893
+ const srcPath = import_node_path6.default.join(partsDir, EYEWHITE_SRC);
1742
1894
  if (!import_node_fs3.default.existsSync(srcPath)) {
1743
1895
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
1744
1896
  }
@@ -1799,7 +1951,11 @@ async function composeLayersFromParts(input) {
1799
1951
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
1800
1952
  );
1801
1953
  }
1802
- const layout = resolveLayout(input.layout);
1954
+ const canvas = {
1955
+ width: CANVAS,
1956
+ height: resolveCanvasHeight(input.canvasHeight)
1957
+ };
1958
+ const layout = resolveLayout(input.layout, canvas);
1803
1959
  const mirrored = resolveMirrorParts(input.mirrorParts);
1804
1960
  const split = await prepEyeSplit(partsDir);
1805
1961
  const splitSources = /* @__PURE__ */ new Map([
@@ -1819,6 +1975,44 @@ async function composeLayersFromParts(input) {
1819
1975
  skipped.push(role);
1820
1976
  continue;
1821
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
+ }
1822
2016
  const cfg = lower ? { ...layout[key], src: LOWER_LASH_SRC } : layout[key];
1823
2017
  const inMemory = splitSources.get(cfg.src);
1824
2018
  const part = await partBuffer(
@@ -1827,7 +2021,8 @@ async function composeLayersFromParts(input) {
1827
2021
  partsDir,
1828
2022
  inMemory,
1829
2023
  // The split halves are cut from eyewhite.png, the file a caller names.
1830
- mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
2024
+ mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC),
2025
+ canvas
1831
2026
  );
1832
2027
  if (part === null || lower && !await hasCoverage(part.buf)) {
1833
2028
  skipped.push(role);
@@ -1839,9 +2034,9 @@ async function composeLayersFromParts(input) {
1839
2034
  noseSpeck = part.nose?.speck;
1840
2035
  const { core, bounds } = await coreAndBoundsOf(part.buf);
1841
2036
  const box = part.nose?.whole ? bounds : core ?? bounds;
1842
- ({ left, top } = nosePlacement(layout, box, part.w, part.h));
2037
+ ({ left, top } = nosePlacement(layout, box, part.w, part.h, canvas));
1843
2038
  } else {
1844
- ({ left, top } = placement(key, layout[key], part.w, part.h));
2039
+ ({ left, top } = placement(key, layout[key], part.w, part.h, canvas));
1845
2040
  }
1846
2041
  if (role === "lash_L" || role === "lash_R") {
1847
2042
  const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
@@ -1854,14 +2049,15 @@ async function composeLayersFromParts(input) {
1854
2049
  }
1855
2050
  placed.push({ role, part, left, top });
1856
2051
  }
1857
- for (const role of skipped) {
1858
- 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 });
1859
2055
  }
1860
2056
  const layers = [];
1861
2057
  const preview = [];
1862
2058
  for (const { role, part, left, top } of placed) {
1863
- const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
1864
- 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`);
1865
2061
  writeFileAtomic(outPath, layer);
1866
2062
  layers.push({
1867
2063
  role,
@@ -1873,15 +2069,15 @@ async function composeLayersFromParts(input) {
1873
2069
  });
1874
2070
  preview.push({ input: part.buf, left, top });
1875
2071
  }
1876
- const previewPng = await (0, import_sharp2.default)({
2072
+ const previewPng = await (0, import_sharp3.default)({
1877
2073
  create: {
1878
- width: CANVAS,
1879
- height: CANVAS,
2074
+ width: canvas.width,
2075
+ height: canvas.height,
1880
2076
  channels: 4,
1881
2077
  background: { r: 245, g: 245, b: 248, alpha: 1 }
1882
2078
  }
1883
2079
  }).composite(preview).png().toBuffer();
1884
- const previewPath = import_node_path5.default.join(outDir, "preview.png");
2080
+ const previewPath = import_node_path6.default.join(outDir, "preview.png");
1885
2081
  writeFileAtomic(previewPath, previewPng);
1886
2082
  return {
1887
2083
  ok: true,
@@ -1902,7 +2098,7 @@ async function composeLayersFromParts(input) {
1902
2098
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1903
2099
  var import_zod = require("zod");
1904
2100
  function createIkiMcpServer() {
1905
- const server = new import_mcp.McpServer({ name: "iki", version: "0.18.0" });
2101
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.19.1" });
1906
2102
  server.registerTool(
1907
2103
  "validate_iki",
1908
2104
  {
@@ -2022,13 +2218,13 @@ function createIkiMcpServer() {
2022
2218
  server.registerTool(
2023
2219
  "compose_layers_from_parts",
2024
2220
  {
2025
- 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`.",
2026
2222
  inputSchema: {
2027
2223
  partsDir: import_zod.z.string().describe(
2028
2224
  "Directory of the source part PNGs (resolved against cwd)."
2029
2225
  ),
2030
2226
  outDir: import_zod.z.string().describe(
2031
- "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."
2032
2228
  ),
2033
2229
  layout: import_zod.z.record(
2034
2230
  import_zod.z.string(),
@@ -2039,10 +2235,13 @@ function createIkiMcpServer() {
2039
2235
  h: import_zod.z.number()
2040
2236
  }).partial()
2041
2237
  ).optional().describe(
2042
- "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."
2043
2239
  ),
2044
2240
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
2045
- "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."
2046
2245
  )
2047
2246
  }
2048
2247
  },
@@ -2067,7 +2266,7 @@ function createIkiMcpServer() {
2067
2266
  server.registerTool(
2068
2267
  "measure_layers",
2069
2268
  {
2070
- 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.",
2071
2270
  inputSchema: {
2072
2271
  layersDir: import_zod.z.string().describe(
2073
2272
  "Directory of role-named layer PNGs (resolved against cwd)."