@ikijs/mcp 0.32.0 → 0.33.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
@@ -41,6 +41,7 @@ __export(index_exports, {
41
41
  describeIkiAt: () => describeIkiAt,
42
42
  describeRigPlan: () => describeRigPlan,
43
43
  formatFoldReport: () => formatFoldReport,
44
+ formatHairSideReport: () => formatHairSideReport,
44
45
  formatMeasureReport: () => formatMeasureReport,
45
46
  formatNodReport: () => formatNodReport,
46
47
  formatPhysicsReport: () => formatPhysicsReport,
@@ -3737,7 +3738,7 @@ async function autoRigFromLayers(input) {
3737
3738
  var import_node_fs7 = __toESM(require("fs"));
3738
3739
  var import_node_path10 = __toESM(require("path"));
3739
3740
  var import_sharp4 = __toESM(require("sharp"));
3740
- var import_editor12 = require("@ikijs/editor");
3741
+ var import_editor13 = require("@ikijs/editor");
3741
3742
 
3742
3743
  // src/trim.ts
3743
3744
  var import_editor4 = require("@ikijs/editor");
@@ -3880,8 +3881,184 @@ function capWarning(arm, g, body) {
3880
3881
  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).`;
3881
3882
  }
3882
3883
 
3883
- // src/measure-forearm-pose.ts
3884
+ // src/measure-hair-side.ts
3884
3885
  var import_editor6 = require("@ikijs/editor");
3886
+ var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
3887
+ var VISIBLE_MIN_PX = 3;
3888
+ var LEAN_HH = 0.12;
3889
+ var TWO_LOCKS_RUN = 0.25;
3890
+ var TWO_LOCKS_GAP = 0.1;
3891
+ function covers(runs, x) {
3892
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3893
+ if (x >= runs[i] && x < runs[i + 1]) return true;
3894
+ }
3895
+ return false;
3896
+ }
3897
+ function runsAt(layer, y) {
3898
+ return layer?.rowRuns?.[y - layer.bbox.y] ?? [];
3899
+ }
3900
+ function opaqueRows(layer) {
3901
+ const runs = layer.rowRuns ?? [];
3902
+ const top = runs.findIndex((r) => r.length > 0);
3903
+ if (top < 0) return void 0;
3904
+ let bottom = runs.length - 1;
3905
+ while (runs[bottom].length === 0) bottom--;
3906
+ return { top: layer.bbox.y + top, bottom: layer.bbox.y + bottom };
3907
+ }
3908
+ async function hairSideWarnings(absDir, layers) {
3909
+ const present = LOCK_ROLES.filter((r) => layers[r] !== void 0);
3910
+ if (present.length === 0) return [];
3911
+ const warnings = [];
3912
+ if (layers.hair_front === void 0) {
3913
+ for (const role of present) {
3914
+ warnings.push(
3915
+ `${role}: needs hair_front \u2014 the rig refuses a lock without the bangs its root hides under. Remove hair_side.png and recompose (free), or draw hair_front.png. Billed.`
3916
+ );
3917
+ }
3918
+ return warnings;
3919
+ }
3920
+ const ref = layers.hair_front;
3921
+ let mismatched = false;
3922
+ for (const r of [...present, "hair_back", "face"]) {
3923
+ const stats = layers[r];
3924
+ if (stats === void 0) continue;
3925
+ if (stats.canvasW !== ref.canvasW || stats.canvasH !== ref.canvasH) {
3926
+ mismatched = true;
3927
+ warnings.push(
3928
+ `${r}: its canvas ${stats.canvasW}x${stats.canvasH} differs from hair_front's ${ref.canvasW}x${ref.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
3929
+ );
3930
+ }
3931
+ }
3932
+ if (mismatched) return warnings;
3933
+ const measurer = (0, import_editor6.createLayerSetMeasurer)({
3934
+ width: ref.canvasW,
3935
+ height: ref.canvasH
3936
+ });
3937
+ const read = (role) => layers[role] === void 0 ? void 0 : measured(measurer, absDir, role);
3938
+ const front = await read("hair_front");
3939
+ const back = await read("hair_back");
3940
+ const face = await read("face");
3941
+ const axisX = face ? face.bbox.x + face.bbox.w / 2 : ref.canvasW / 2;
3942
+ const locks = /* @__PURE__ */ new Map();
3943
+ for (const role of present) {
3944
+ const lock = await measured(measurer, absDir, role);
3945
+ locks.set(role, lock);
3946
+ const side = lock.bbox.x + lock.bbox.w / 2 < axisX ? -1 : 1;
3947
+ const eyeRole = ["eye_L", "eye_R"].find(
3948
+ (r) => layers[r] !== void 0 && (layers[r].bboxCx < axisX ? -1 : 1) === side
3949
+ );
3950
+ const eye = eyeRole === void 0 ? void 0 : layers[eyeRole];
3951
+ const root = rootWarning(role, lock, front);
3952
+ if (root !== void 0) warnings.push(root);
3953
+ if (eyeRole !== void 0 && eye !== void 0) {
3954
+ const w = eyeCornerWarning(role, lock, side, eyeRole, eye);
3955
+ if (w !== void 0) warnings.push(w);
3956
+ }
3957
+ const rowEye = eye ?? layers.eye_L ?? layers.eye_R;
3958
+ if (face !== void 0 && rowEye !== void 0) {
3959
+ const w = leanWarning(role, lock, side, face, back, rowEye);
3960
+ if (w !== void 0) warnings.push(w);
3961
+ }
3962
+ }
3963
+ if (drawsTwoLocks(locks.get("hair_side_R") ?? locks.get(present[0]))) {
3964
+ warnings.push(
3965
+ `hair_side.png draws two locks \u2014 draw ONE lock, the screen-left one; the composer mirrors it into hair_side_L. Billed.`
3966
+ );
3967
+ }
3968
+ return warnings;
3969
+ }
3970
+ function rootWarning(role, lock, front) {
3971
+ const y = opaqueRows(lock)?.top;
3972
+ if (y === void 0) return void 0;
3973
+ const frontRuns = runsAt(front, y);
3974
+ const lockRuns = runsAt(lock, y);
3975
+ let shown = 0;
3976
+ for (let i = 0; i + 1 < lockRuns.length; i += 2) {
3977
+ let stretch = 0;
3978
+ for (let x = lockRuns[i]; x <= lockRuns[i + 1]; x++) {
3979
+ if (x < lockRuns[i + 1] && !covers(frontRuns, x)) {
3980
+ stretch++;
3981
+ continue;
3982
+ }
3983
+ if (stretch >= VISIBLE_MIN_PX) shown += stretch;
3984
+ stretch = 0;
3985
+ }
3986
+ }
3987
+ if (shown === 0) return void 0;
3988
+ return `${role}: its top row (canvas y ${y}) shows past hair_front on ${shown} px \u2014 the root is visible at rest. Move it under the bangs \u2014 up (layout.${role}.cy) or toward the face (layout.${role}.cx) (free), or regenerate hair_side.png with a longer hidden root. Billed.`;
3989
+ }
3990
+ function eyeCornerWarning(role, lock, side, eyeRole, eye) {
3991
+ const row = Math.floor(eye.bboxCy);
3992
+ const corner = side < 0 ? eye.marginLeft : eye.marginLeft + eye.w - 1;
3993
+ const runs = runsAt(lock, row);
3994
+ let overlap = 0;
3995
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3996
+ if (corner < runs[i] || corner >= runs[i + 1]) continue;
3997
+ overlap = side < 0 ? runs[i + 1] - corner : corner - runs[i] + 1;
3998
+ }
3999
+ if (overlap < VISIBLE_MIN_PX) return void 0;
4000
+ return `${role}: covers ${eyeRole}'s outer corner at rest (canvas x ${corner}, y ${row}) by ${overlap} px \u2014 the eye's outer tail may only slide under it on the turn. Move layout.${role}.cx ${overlap} px ${side < 0 ? "left" : "right"}, outward (free), or regenerate it narrower. Billed.`;
4001
+ }
4002
+ function leanWarning(role, lock, side, face, back, eye) {
4003
+ const faceRows = opaqueRows(face);
4004
+ const lockRows = opaqueRows(lock);
4005
+ if (faceRows === void 0 || lockRows === void 0) return void 0;
4006
+ const faceBottom = faceRows.bottom;
4007
+ const lean = Math.round(LEAN_HH * (faceBottom - Math.floor(eye.bboxCy)));
4008
+ if (lean < 1) return void 0;
4009
+ const bare = /* @__PURE__ */ new Set();
4010
+ const rows = /* @__PURE__ */ new Set();
4011
+ for (let y = lockRows.top; y <= Math.min(lockRows.bottom, faceBottom); y++) {
4012
+ const runs = runsAt(lock, y);
4013
+ if (runs.length === 0) continue;
4014
+ const from = side < 0 ? runs[0] : runs[runs.length - 2];
4015
+ const to = side < 0 ? runs[1] : runs[runs.length - 1];
4016
+ const start = side < 0 ? from : Math.max(from, to - lean);
4017
+ const end = side < 0 ? Math.min(to, from + lean) : to;
4018
+ const faceRuns = runsAt(face, y);
4019
+ const backRuns = runsAt(back, y);
4020
+ for (let x = start; x < end; x++) {
4021
+ if (covers(faceRuns, x) || covers(backRuns, x)) continue;
4022
+ bare.add(x);
4023
+ rows.add(y);
4024
+ }
4025
+ }
4026
+ if (bare.size === 0) return void 0;
4027
+ const cols = [...bare].sort((a, b) => a - b);
4028
+ const ys = [...rows].sort((a, b) => a - b);
4029
+ const where = `leaves bare pixels spanning columns ${cols[0]}\u2013${cols[cols.length - 1]}, rows ${ys[0]}\u2013${ys[ys.length - 1]}`;
4030
+ const lead = `${role}: when the head turns away from it the lock leans inward about ${lean} px and ${where}, where`;
4031
+ if (back === void 0) {
4032
+ return `${lead} the face is not painted \u2014 draw hair_back.png behind the locks. Billed.`;
4033
+ }
4034
+ return `${lead} neither hair_back nor the face is painted \u2014 widen hair_back there (layout.hair_back.w) (free), or regenerate it fuller behind the locks. Billed.`;
4035
+ }
4036
+ function drawsTwoLocks(lock) {
4037
+ const w = lock.bbox.w;
4038
+ const col = new Array(w).fill(false);
4039
+ for (const runs of lock.rowRuns ?? []) {
4040
+ for (let i = 0; i + 1 < runs.length; i += 2) {
4041
+ for (let x = runs[i]; x < runs[i + 1]; x++) col[x - lock.bbox.x] = true;
4042
+ }
4043
+ }
4044
+ const big = [];
4045
+ let start = -1;
4046
+ for (let x = 0; x <= w; x++) {
4047
+ if (x < w && col[x]) {
4048
+ if (start < 0) start = x;
4049
+ } else if (start >= 0) {
4050
+ if (x - start >= TWO_LOCKS_RUN * w) big.push([start, x]);
4051
+ start = -1;
4052
+ }
4053
+ }
4054
+ for (let i = 1; i < big.length; i++) {
4055
+ if (big[i][0] - big[i - 1][1] >= TWO_LOCKS_GAP * w) return true;
4056
+ }
4057
+ return false;
4058
+ }
4059
+
4060
+ // src/measure-forearm-pose.ts
4061
+ var import_editor7 = require("@ikijs/editor");
3885
4062
  var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
3886
4063
  var ARM_OF = {
3887
4064
  forearm_pose_L: "arm_L",
@@ -3915,7 +4092,7 @@ async function forearmPoseWarnings(absDir, layers) {
3915
4092
  continue;
3916
4093
  }
3917
4094
  if (layers.body === void 0) continue;
3918
- const measurer = (0, import_editor6.createLayerSetMeasurer)({
4095
+ const measurer = (0, import_editor7.createLayerSetMeasurer)({
3919
4096
  width: stats.canvasW,
3920
4097
  height: stats.canvasH
3921
4098
  });
@@ -3923,12 +4100,12 @@ async function forearmPoseWarnings(absDir, layers) {
3923
4100
  let armLayer;
3924
4101
  try {
3925
4102
  armLayer = await measured(measurer, absDir, arm);
3926
- a = (0, import_editor6.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
4103
+ a = (0, import_editor7.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
3927
4104
  } catch (err) {
3928
- if (err instanceof import_editor6.LayerGeometryError) continue;
4105
+ if (err instanceof import_editor7.LayerGeometryError) continue;
3929
4106
  throw err;
3930
4107
  }
3931
- const b = (0, import_editor6.forearmPoseGeometry)(await measured(measurer, absDir, pose));
4108
+ const b = (0, import_editor7.forearmPoseGeometry)(await measured(measurer, absDir, pose));
3932
4109
  warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
3933
4110
  }
3934
4111
  return warnings;
@@ -3968,11 +4145,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3968
4145
 
3969
4146
  // src/measure-lips.ts
3970
4147
  var import_node_path7 = __toESM(require("path"));
3971
- var import_editor8 = require("@ikijs/editor");
4148
+ var import_editor9 = require("@ikijs/editor");
3972
4149
 
3973
4150
  // src/compose-lips.ts
3974
4151
  var import_sharp2 = __toESM(require("sharp"));
3975
- var import_editor7 = require("@ikijs/editor");
4152
+ var import_editor8 = require("@ikijs/editor");
3976
4153
  var KEYED_SRC = "mouth_keyed.png";
3977
4154
  var INTERIOR_SRC = "mouth_interior.png";
3978
4155
  var KEY_CANDIDATE = 0.5;
@@ -4070,7 +4247,7 @@ function keyGreen(rgba, W, H) {
4070
4247
  let candidates = 0;
4071
4248
  for (let p = 0; p < n; p++) {
4072
4249
  const i = p * 4;
4073
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4250
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
4074
4251
  const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
4075
4252
  if (excess < KEY_CANDIDATE) continue;
4076
4253
  candidates++;
@@ -4097,7 +4274,7 @@ function keyGreen(rgba, W, H) {
4097
4274
  const dg = rgba[i + 1] - G[1];
4098
4275
  const db = rgba[i + 2] - G[2];
4099
4276
  const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
4100
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) {
4277
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) {
4101
4278
  if (green) out[i + 3] = 0;
4102
4279
  } else if (green) {
4103
4280
  fill[p] = 1;
@@ -4273,7 +4450,7 @@ async function prepInterior(rgba, W, H) {
4273
4450
  for (let y = box2.y; y < box2.y + box2.h; y++) {
4274
4451
  for (let x = box2.x; x < box2.x + box2.w; x++) {
4275
4452
  const i = (y * cw + x) * 4;
4276
- if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4453
+ if (crop[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
4277
4454
  count++;
4278
4455
  for (let c = 0; c < 3; c++) all[c] += crop[i + c];
4279
4456
  if (luma(crop, i) < CAVITY_LUMA) {
@@ -4296,7 +4473,7 @@ function enclosedHole(frame, w, h) {
4296
4473
  const stack = new Int32Array(n);
4297
4474
  let depth = 0;
4298
4475
  const seed = (p) => {
4299
- if (!outside[p] && alpha(p) < import_editor7.ALPHA_OPAQUE) {
4476
+ if (!outside[p] && alpha(p) < import_editor8.ALPHA_OPAQUE) {
4300
4477
  outside[p] = 1;
4301
4478
  stack[depth++] = p;
4302
4479
  }
@@ -4319,7 +4496,7 @@ function enclosedHole(frame, w, h) {
4319
4496
  }
4320
4497
  const mask = new Uint8Array(n);
4321
4498
  for (let p = 0; p < n; p++) {
4322
- if (alpha(p) < import_editor7.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4499
+ if (alpha(p) < import_editor8.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4323
4500
  }
4324
4501
  const { label, sizes, boxes } = components(mask, w, h);
4325
4502
  const main = largest(sizes);
@@ -4346,7 +4523,7 @@ function enclosedHole(frame, w, h) {
4346
4523
  return { label, main, box: box2 };
4347
4524
  }
4348
4525
  function measureLips(layers, w, h) {
4349
- const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
4526
+ const measurer = (0, import_editor8.createLayerSetMeasurer)({ width: w, height: h });
4350
4527
  return new Map(
4351
4528
  Object.entries(layers).map(([role, rgba]) => [
4352
4529
  role,
@@ -4364,8 +4541,8 @@ function assertFoldContract(layers, w, h) {
4364
4541
  }
4365
4542
  byRole.set(role, layer);
4366
4543
  }
4367
- const opening = (0, import_editor7.mouthOpening)(byRole);
4368
- const runs = (0, import_editor7.columnRuns)(byRole.get("mouth_inner"));
4544
+ const opening = (0, import_editor8.mouthOpening)(byRole);
4545
+ const runs = (0, import_editor8.columnRuns)(byRole.get("mouth_inner"));
4369
4546
  for (let col = opening.x0; col <= opening.x1; col++) {
4370
4547
  const c = opening.at(col);
4371
4548
  const why = !runs.has(col) ? "has no interior run" : c.Tu > c.T ? `has a gap between the line and the interior (Tu ${c.Tu} > T ${c.T})` : c.T > c.lineTop || c.lineH <= 0 ? `has no line above the interior (T ${c.T}, line top ${c.lineTop})` : c.Bl < c.Bb ? `has a gap between the interior and the skin (Bl ${c.Bl} < Bb ${c.Bb})` : null;
@@ -4395,18 +4572,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
4395
4572
  }
4396
4573
  const centre = Math.round((hb.x0 + hb.x1) / 2);
4397
4574
  let stroke = 0;
4398
- while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor7.ALPHA_OPAQUE)
4575
+ while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor8.ALPHA_OPAQUE)
4399
4576
  stroke++;
4400
4577
  const bandCap = BAND_CAP * Math.max(1, stroke);
4401
4578
  const skinRow = new Int32Array(w).fill(-1);
4402
4579
  const inM = new Uint8Array(n);
4403
4580
  for (let x = hb.x0; x <= hb.x1; x++) {
4404
4581
  let y = bot[x];
4405
- while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor7.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4582
+ while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor8.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4406
4583
  y++;
4407
4584
  for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
4408
4585
  let r = y;
4409
- while (r < h && alpha(r * w + x) < import_editor7.ALPHA_OPAQUE) r++;
4586
+ while (r < h && alpha(r * w + x) < import_editor8.ALPHA_OPAQUE) r++;
4410
4587
  if (r < h) {
4411
4588
  skinRow[x] = r;
4412
4589
  inM[r * w + x] = 1;
@@ -4416,7 +4593,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4416
4593
  for (let y = 0; y < h; y++) {
4417
4594
  for (let x = 0; x < w; x++) {
4418
4595
  const p = y * w + x;
4419
- if (inM[p] || alpha(p) < import_editor7.ALPHA_OPAQUE) continue;
4596
+ if (inM[p] || alpha(p) < import_editor8.ALPHA_OPAQUE) continue;
4420
4597
  if (top[x] >= 0 && y < top[x]) continue;
4421
4598
  if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
4422
4599
  }
@@ -4426,7 +4603,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4426
4603
  if (x < 0 || x >= w) continue;
4427
4604
  let first = 0;
4428
4605
  while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
4429
- if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor7.ALPHA_OPAQUE)
4606
+ if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor8.ALPHA_OPAQUE)
4430
4607
  wall[x] = 1;
4431
4608
  }
4432
4609
  const gx = hb.x0 - 1;
@@ -4453,7 +4630,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4453
4630
  if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
4454
4631
  if (!grown[p]) {
4455
4632
  const a = alpha(p);
4456
- if (a >= import_editor7.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4633
+ if (a >= import_editor8.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4457
4634
  inner.set(interior.cavity, p * 4);
4458
4635
  inner[p * 4 + 3] = 255 - a;
4459
4636
  }
@@ -4518,7 +4695,7 @@ async function restShiftOf(layers, width, height) {
4518
4695
  }
4519
4696
  byRole.set(role, layer);
4520
4697
  }
4521
- return (0, import_editor7.mouthRestShift)(byRole);
4698
+ return (0, import_editor8.mouthRestShift)(byRole);
4522
4699
  }
4523
4700
  async function closedLips(upper, lower, shift, left, top) {
4524
4701
  const shut = async (png, role) => {
@@ -4568,7 +4745,7 @@ async function closedLips(upper, lower, shift, left, top) {
4568
4745
  }
4569
4746
 
4570
4747
  // src/measure-lips.ts
4571
- var isLipLayerRole = (role) => import_editor8.LIP_ROLES.includes(role) || (0, import_editor8.isLipInsideRole)(role);
4748
+ var isLipLayerRole = (role) => import_editor9.LIP_ROLES.includes(role) || (0, import_editor9.isLipInsideRole)(role);
4572
4749
  var MIN_OPENING_ROWS = 8;
4573
4750
  var MIN_LINE_ROWS = 2;
4574
4751
  var GREEN_EXCESS = 40;
@@ -4576,8 +4753,8 @@ var INTERIOR_GAP_FRACTION = 0.05;
4576
4753
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
4577
4754
  async function lipWarnings(absDir, layers) {
4578
4755
  const warnings = [];
4579
- const present = import_editor8.LIP_ROLES.filter((role) => layers[role] !== void 0);
4580
- const inside = import_editor8.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4756
+ const present = import_editor9.LIP_ROLES.filter((role) => layers[role] !== void 0);
4757
+ const inside = import_editor9.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4581
4758
  if (present.length === 0) {
4582
4759
  if (inside.length > 0) {
4583
4760
  warnings.push(
@@ -4594,8 +4771,8 @@ async function lipWarnings(absDir, layers) {
4594
4771
  `${present.join("/")}: the lip set cannot be mixed with ${legacy.join("/")} \u2014 auto_rig_from_layers refuses it. Remove one route: compose again with only mouth_keyed.png + mouth_interior.png, or without them.`
4595
4772
  );
4596
4773
  }
4597
- if (present.length < import_editor8.LIP_ROLES.length) {
4598
- const missing = import_editor8.LIP_ROLES.filter((role) => layers[role] === void 0);
4774
+ if (present.length < import_editor9.LIP_ROLES.length) {
4775
+ const missing = import_editor9.LIP_ROLES.filter((role) => layers[role] === void 0);
4599
4776
  warnings.push(
4600
4777
  `${present.join("/")}: partial lip set, missing ${missing.join("/")} \u2014 auto_rig_from_layers refuses it. Compose mouth_keyed.png + mouth_interior.png together, which cuts all three.`
4601
4778
  );
@@ -4626,18 +4803,18 @@ async function lipWarnings(absDir, layers) {
4626
4803
  );
4627
4804
  }
4628
4805
  }
4629
- const measurer = (0, import_editor8.createLayerSetMeasurer)({
4806
+ const measurer = (0, import_editor9.createLayerSetMeasurer)({
4630
4807
  width: inner.canvasW,
4631
4808
  height: inner.canvasH
4632
4809
  });
4633
4810
  const set = /* @__PURE__ */ new Map();
4634
4811
  const green = [];
4635
- for (const role of import_editor8.LIP_ROLES) {
4812
+ for (const role of import_editor9.LIP_ROLES) {
4636
4813
  const fileName = `${role}.png`;
4637
4814
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
4638
4815
  set.set(role, measurer.add({ role, fileName, rgba }));
4639
4816
  for (let i = 0; i < rgba.length; i += 4) {
4640
- if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4817
+ if (rgba[i + 3] >= import_editor9.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4641
4818
  green.push(role);
4642
4819
  break;
4643
4820
  }
@@ -4645,15 +4822,15 @@ async function lipWarnings(absDir, layers) {
4645
4822
  }
4646
4823
  let opening;
4647
4824
  try {
4648
- opening = (0, import_editor8.mouthOpening)(set);
4825
+ opening = (0, import_editor9.mouthOpening)(set);
4649
4826
  } catch (err) {
4650
- if (err instanceof import_editor8.LayerGeometryError) {
4827
+ if (err instanceof import_editor9.LayerGeometryError) {
4651
4828
  warnings.push(err.message);
4652
4829
  return { warnings };
4653
4830
  }
4654
4831
  throw err;
4655
4832
  }
4656
- const innerRuns = (0, import_editor8.columnRuns)(set.get("mouth_inner"));
4833
+ const innerRuns = (0, import_editor9.columnRuns)(set.get("mouth_inner"));
4657
4834
  const noInterior = [];
4658
4835
  const gap = [];
4659
4836
  const noLine = [];
@@ -4739,8 +4916,8 @@ async function lipWarnings(absDir, layers) {
4739
4916
 
4740
4917
  // src/measure-turn.ts
4741
4918
  var import_node_path8 = __toESM(require("path"));
4742
- var import_editor9 = require("@ikijs/editor");
4743
4919
  var import_editor10 = require("@ikijs/editor");
4920
+ var import_editor11 = require("@ikijs/editor");
4744
4921
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
4745
4922
  var IRIS_V_MIN = 0.18;
4746
4923
  var IRIS_V_MAX = 0.95;
@@ -4890,7 +5067,7 @@ async function measureTurnImage(filePath, iris) {
4890
5067
  let transparent = false;
4891
5068
  if (hasAlpha) {
4892
5069
  for (let i = 0; i < n; i++) {
4893
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) {
5070
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) {
4894
5071
  transparent = true;
4895
5072
  break;
4896
5073
  }
@@ -4901,7 +5078,7 @@ async function measureTurnImage(filePath, iris) {
4901
5078
  const fg = new Uint8Array(n);
4902
5079
  const value = new Float32Array(n);
4903
5080
  for (let i = 0; i < n; i++) {
4904
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) continue;
5081
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) continue;
4905
5082
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
4906
5083
  if (maskMode === "alpha") {
4907
5084
  fg[i] = 1;
@@ -4967,12 +5144,12 @@ async function measureTurnImage(filePath, iris) {
4967
5144
  }
4968
5145
  const [irisL, irisR] = best.pair;
4969
5146
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
4970
- const { left, right } = (0, import_editor9.foregroundSpan)(
5147
+ const { left, right } = (0, import_editor10.foregroundSpan)(
4971
5148
  fg,
4972
5149
  width,
4973
5150
  height,
4974
- eyeRow - import_editor9.HEAD_BAND,
4975
- eyeRow + import_editor9.HEAD_BAND
5151
+ eyeRow - import_editor10.HEAD_BAND,
5152
+ eyeRow + import_editor10.HEAD_BAND
4976
5153
  );
4977
5154
  if (right <= left) {
4978
5155
  throw new AutoRigInputError(
@@ -4996,7 +5173,7 @@ async function measureTurnImage(filePath, iris) {
4996
5173
  left,
4997
5174
  right,
4998
5175
  cx: (left + right) / 2,
4999
- half: (0, import_editor9.headHalfOf)({ left, right })
5176
+ half: (0, import_editor10.headHalfOf)({ left, right })
5000
5177
  },
5001
5178
  pairCx: (irisL.cx + irisR.cx) / 2,
5002
5179
  eyeGap: irisR.cx - irisL.cx
@@ -5187,7 +5364,7 @@ function noseSpeckWarning({ core, part }, source) {
5187
5364
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
5188
5365
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
5189
5366
  ];
5190
- return `nose: ${found} \u2014 under ${import_editor10.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
5367
+ return `nose: ${found} \u2014 under ${import_editor11.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
5191
5368
  }
5192
5369
  async function lashOffSclera(eyePath, lashPath) {
5193
5370
  const eye = await decodePng(eyePath);
@@ -5268,6 +5445,7 @@ async function measureDir(absDir, noseSpeck) {
5268
5445
  warnings.push(...await forearmPoseWarnings(absDir, layers));
5269
5446
  const lip = await lipWarnings(absDir, layers);
5270
5447
  warnings.push(...lip.warnings);
5448
+ warnings.push(...await hairSideWarnings(absDir, layers));
5271
5449
  for (const side of ["L", "R"]) {
5272
5450
  const eye = layers[`eye_${side}`];
5273
5451
  const iris = layers[`iris_${side}`];
@@ -5324,10 +5502,10 @@ async function measureDir(absDir, noseSpeck) {
5324
5502
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
5325
5503
  } else if (layers.nose !== void 0) {
5326
5504
  const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
5327
- const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
5505
+ const core = (0, import_editor11.denseCoreOf)(nose.rgba, nose.width, nose.height);
5328
5506
  if (core !== null) {
5329
5507
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
5330
- if ((0, import_editor10.isSpeckCore)(core, crop))
5508
+ if ((0, import_editor11.isSpeckCore)(core, crop))
5331
5509
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
5332
5510
  }
5333
5511
  }
@@ -5398,12 +5576,12 @@ function formatMeasureReport(result) {
5398
5576
 
5399
5577
  // src/compose-arms.ts
5400
5578
  var import_sharp3 = __toESM(require("sharp"));
5401
- var import_editor11 = require("@ikijs/editor");
5579
+ var import_editor12 = require("@ikijs/editor");
5402
5580
  var ARM_WIDTH = 0.4;
5403
5581
  var SHOULDER_DROP = 0.12;
5404
5582
  async function armPlacement(role, cfg, part, body) {
5405
5583
  const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5406
- const layer = (0, import_editor11.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5584
+ const layer = (0, import_editor12.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5407
5585
  role,
5408
5586
  fileName: "arm.png",
5409
5587
  rgba: data
@@ -5415,9 +5593,9 @@ async function armPlacement(role, cfg, part, body) {
5415
5593
  }
5416
5594
  let g;
5417
5595
  try {
5418
- g = (0, import_editor11.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5596
+ g = (0, import_editor12.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5419
5597
  } catch (err) {
5420
- if (err instanceof import_editor11.LayerGeometryError) {
5598
+ if (err instanceof import_editor12.LayerGeometryError) {
5421
5599
  throw new AutoRigInputError(`layout.${role}: ${err.message}`);
5422
5600
  }
5423
5601
  throw err;
@@ -5444,7 +5622,7 @@ async function armPlacement(role, cfg, part, body) {
5444
5622
  }
5445
5623
  async function poseGeometryOf(role, png, size, when) {
5446
5624
  const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5447
- const layer = (0, import_editor11.createLayerSetMeasurer)({
5625
+ const layer = (0, import_editor12.createLayerSetMeasurer)({
5448
5626
  width: size.w,
5449
5627
  height: size.h
5450
5628
  }).add({ role, fileName: "forearm_pose.png", rgba: data });
@@ -5453,7 +5631,7 @@ async function poseGeometryOf(role, png, size, when) {
5453
5631
  `layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
5454
5632
  );
5455
5633
  }
5456
- return (0, import_editor11.forearmPoseGeometry)(layer);
5634
+ return (0, import_editor12.forearmPoseGeometry)(layer);
5457
5635
  }
5458
5636
  async function forearmPoseWidth(role, trimmed, elbowRun) {
5459
5637
  const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
@@ -5570,6 +5748,23 @@ var DEFAULT_LAYOUT = {
5570
5748
  // prettier-ignore
5571
5749
  brow_L: { src: "brow.png", cx: 645, cy: 405, w: 105, mirror: false },
5572
5750
  brow_R: { src: "brow.png", cx: 455, cy: 405, w: 105, mirror: true },
5751
+ // The front side locks, one part for both: hair_side_R (screen left) takes
5752
+ // hair_side.png as drawn and hair_side_L mirrors it, like the blush. They
5753
+ // draw over the face, brows and lashes and under the bangs. Mint's tuned
5754
+ // placement (cy 545 at mint's face cy 431, carried to the default face:
5755
+ // 437 + 114 = 551), tuned per character through `layout.hair_side_*`: the
5756
+ // lock's root top lies above the brow row (405) so the bangs' temple hides it
5757
+ // (for a 1:5 lock, whose height follows the image's aspect: w 90 is 450 tall,
5758
+ // so cy 551 puts the top at 326), and the lock runs from the temple over the
5759
+ // front of the ear and down along the cheek's edge, the ear's rim and lobe
5760
+ // showing beside it. Its box overlaps the eye's by about 15 px at the
5761
+ // default face, fine only because a drawn lock's root tapers (the measure's "covers
5762
+ // the eye's outer corner" check catches a lock that does not).
5763
+ // OPTIONAL: a parts dir without it composes.
5764
+ hair_side_L: { src: "hair_side.png", cx: 715, cy: 551, w: 90, optional: true, mirror: true },
5765
+ // prettier-ignore
5766
+ hair_side_R: { src: "hair_side.png", cx: 385, cy: 551, w: 90, optional: true, mirror: false },
5767
+ // prettier-ignore
5573
5768
  hair_front: { src: "hair_front.png", cx: 550, cy: 425, w: 660 },
5574
5769
  // The pose forearms, one drawing for both: forearm_pose_R (screen left)
5575
5770
  // takes forearm_pose.png as drawn and forearm_pose_L mirrors it, like the
@@ -5608,6 +5803,8 @@ var ORDER = [
5608
5803
  "lash_R",
5609
5804
  "brow_L",
5610
5805
  "brow_R",
5806
+ "hair_side_L",
5807
+ "hair_side_R",
5611
5808
  "hair_front",
5612
5809
  "forearm_pose_L",
5613
5810
  "forearm_pose_R"
@@ -5632,7 +5829,9 @@ var FACE_FEATURES = [
5632
5829
  "lash_L",
5633
5830
  "lash_R",
5634
5831
  "brow_L",
5635
- "brow_R"
5832
+ "brow_R",
5833
+ "hair_side_L",
5834
+ "hair_side_R"
5636
5835
  ];
5637
5836
  function resolveLayout(overrides, canvas) {
5638
5837
  const resolved = { ...DEFAULT_LAYOUT };
@@ -5730,18 +5929,18 @@ function keyWhiteToAlpha(rgba) {
5730
5929
  async function coreAndBoundsOf(png) {
5731
5930
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5732
5931
  return {
5733
- core: (0, import_editor10.denseCoreOf)(data, info.width, info.height),
5932
+ core: (0, import_editor11.denseCoreOf)(data, info.width, info.height),
5734
5933
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
5735
5934
  };
5736
5935
  }
5737
5936
  async function hasCoverage(png) {
5738
5937
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5739
- return (0, import_editor12.detectAlphaBbox)(data, info.width, info.height) !== null;
5938
+ return (0, import_editor13.detectAlphaBbox)(data, info.width, info.height) !== null;
5740
5939
  }
5741
5940
  async function noseSizingOf(png) {
5742
5941
  const { core, bounds } = await coreAndBoundsOf(png);
5743
5942
  if (core === null) return { box: bounds, whole: true };
5744
- if ((0, import_editor10.isSpeckCore)(core, bounds)) {
5943
+ if ((0, import_editor11.isSpeckCore)(core, bounds)) {
5745
5944
  return {
5746
5945
  box: bounds,
5747
5946
  whole: true,
@@ -5863,7 +6062,7 @@ function detachedAboveWhite(rgba, W, H) {
5863
6062
  for (let p = 0; p < n; p++) {
5864
6063
  const alpha = rgba[p * 4 + 3];
5865
6064
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
5866
- ink[p] = alpha >= import_editor12.ALPHA_OPAQUE ? 2 : 1;
6065
+ ink[p] = alpha >= import_editor13.ALPHA_OPAQUE ? 2 : 1;
5867
6066
  }
5868
6067
  const label = new Int32Array(n).fill(-1);
5869
6068
  const stack = new Int32Array(n);
@@ -5968,7 +6167,7 @@ async function prepEyeSplit(partsDir) {
5968
6167
  const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
5969
6168
  const detached = detachedAboveWhite(data, W, H);
5970
6169
  const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
5971
- const isLight = (i) => data[i + 3] >= import_editor12.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
6170
+ const isLight = (i) => data[i + 3] >= import_editor13.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
5972
6171
  const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
5973
6172
  const whiteTop = new Int32Array(W).fill(-1);
5974
6173
  for (let x = 0; x < W; x++) {
@@ -6138,7 +6337,7 @@ async function composeLayersFromParts(input) {
6138
6337
  lip_lower: split2.lower,
6139
6338
  lip_upper: split2.upper
6140
6339
  }[role];
6141
- if ((0, import_editor12.isLipInsideRole)(role) && !await hasCoverage(buf)) {
6340
+ if ((0, import_editor13.isLipInsideRole)(role) && !await hasCoverage(buf)) {
6142
6341
  skipped.push(role);
6143
6342
  continue;
6144
6343
  }
@@ -6333,7 +6532,7 @@ async function composeLayersFromParts(input) {
6333
6532
  });
6334
6533
  }
6335
6534
  const restInput = (role, buf) => {
6336
- if (role === "mouth_inner" || (0, import_editor12.isLipInsideRole)(role)) return null;
6535
+ if (role === "mouth_inner" || (0, import_editor13.isLipInsideRole)(role)) return null;
6337
6536
  if (closed === void 0) return buf;
6338
6537
  if (role === "lip_upper") return closed.upper;
6339
6538
  if (role === "lip_lower") return closed.lower;
@@ -6416,6 +6615,40 @@ function pxText(px2) {
6416
6615
  return (Math.floor(px2 * 10) / 10).toFixed(1);
6417
6616
  }
6418
6617
 
6618
+ // src/hair-side-report.ts
6619
+ function signedPx(px2) {
6620
+ const s = px2.toFixed(1);
6621
+ if (s === "-0.0") return "+0.0";
6622
+ return s.startsWith("-") ? s : `+${s}`;
6623
+ }
6624
+ function formatHairSideReport(hairSide, canvas) {
6625
+ if (hairSide === void 0) return [];
6626
+ return [hairSide.left, hairSide.right].flatMap(
6627
+ (room) => room === void 0 ? [] : roomLines(room, canvas)
6628
+ );
6629
+ }
6630
+ function roomLines(room, canvas) {
6631
+ const { role, cover, tail, unavailable } = room;
6632
+ if (unavailable !== void 0) {
6633
+ return [`HAIRSIDE ${role}: unavailable \u2014 ${unavailable}`];
6634
+ }
6635
+ const lines = [];
6636
+ if (cover !== void 0) {
6637
+ const row = Math.floor(canvas.height / 2 - cover.y);
6638
+ lines.push(
6639
+ `HAIRSIDE cover ${role}: the lock's outer edge ${signedPx(cover.px)} model px outside the head's edge at ParamAngleX=${cover.deg}, ${signedPx(cover.rest)} at rest (least over the rows it covers at rest, at model y ${cover.y.toFixed(1)}, row ${row} model px from the top; negative: the turn bares cheek the lock hides at rest)`
6640
+ );
6641
+ }
6642
+ if (tail !== void 0) {
6643
+ const lash = tail.lashToLock === void 0 ? "" : ` / lash ${signedPx(tail.lashToLock)} model px`;
6644
+ lines.push(
6645
+ `HAIRSIDE tail ${role}: eye ${signedPx(tail.eyeToLock)} model px${lash} from the lock's face-side edge at ParamAngleX=${tail.deg} (negative: under the lock, intended), corner ${signedPx(tail.eyeToPlate)} model px from the head's edge (positive: inside it; negative: past it)`
6646
+ );
6647
+ }
6648
+ if (lines.length === 0) lines.push(`HAIRSIDE ${role}: no cover or tail row`);
6649
+ return lines;
6650
+ }
6651
+
6419
6652
  // src/server.ts
6420
6653
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
6421
6654
  var import_zod = require("zod");
@@ -6427,7 +6660,7 @@ function formatPatchReports(reports) {
6427
6660
  });
6428
6661
  }
6429
6662
  function createIkiMcpServer() {
6430
- const server = new import_mcp.McpServer({ name: "iki", version: "0.32.0" });
6663
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.33.1" });
6431
6664
  server.registerTool(
6432
6665
  "validate_iki",
6433
6666
  {
@@ -6519,7 +6752,7 @@ function createIkiMcpServer() {
6519
6752
  server.registerTool(
6520
6753
  "auto_rig_from_layers",
6521
6754
  {
6522
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6755
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, hair_side_L/hair_side_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, a side lock needs hair_front, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6523
6756
  inputSchema: {
6524
6757
  layers: import_zod.z.array(
6525
6758
  import_zod.z.object({
@@ -6596,7 +6829,8 @@ function createIkiMcpServer() {
6596
6829
  formatRigPlanReport(r.rigPlan),
6597
6830
  ...formatPatchReports(r.patches ?? []),
6598
6831
  ...formatFoldReport(r.folds, r.canvas),
6599
- ...formatPhysicsReport(r.physics)
6832
+ ...formatPhysicsReport(r.physics),
6833
+ ...formatHairSideReport(r.turn?.hairSide, r.canvas)
6600
6834
  ].join("\n") : `INVALID: ${r.error}`;
6601
6835
  return { content: [{ type: "text", text }], structuredContent: r };
6602
6836
  } catch (err) {
@@ -6612,7 +6846,7 @@ function createIkiMcpServer() {
6612
6846
  server.registerTool(
6613
6847
  "compose_layers_from_parts",
6614
6848
  {
6615
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6849
+ description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6616
6850
  inputSchema: {
6617
6851
  partsDir: import_zod.z.string().describe(
6618
6852
  "Directory of the source part PNGs (resolved against cwd)."
@@ -6629,10 +6863,10 @@ function createIkiMcpServer() {
6629
6863
  h: import_zod.z.number()
6630
6864
  }).partial()
6631
6865
  ).optional().describe(
6632
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6866
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_side_L, hair_side_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows, side locks \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6633
6867
  ),
6634
6868
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
6635
- "Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
6869
+ "Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), hair_side.png as the front side lock on the screen LEFT (hanging, its root at the image's top), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
6636
6870
  ),
6637
6871
  canvasHeight: import_zod.z.number().optional().describe(
6638
6872
  "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."
@@ -6660,7 +6894,7 @@ function createIkiMcpServer() {
6660
6894
  server.registerTool(
6661
6895
  "measure_layers",
6662
6896
  {
6663
- description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6897
+ description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6664
6898
  inputSchema: {
6665
6899
  layersDir: import_zod.z.string().describe(
6666
6900
  "Directory of role-named layer PNGs (resolved against cwd)."
@@ -6822,6 +7056,7 @@ function createIkiMcpServer() {
6822
7056
  describeIkiAt,
6823
7057
  describeRigPlan,
6824
7058
  formatFoldReport,
7059
+ formatHairSideReport,
6825
7060
  formatMeasureReport,
6826
7061
  formatNodReport,
6827
7062
  formatPhysicsReport,