@ikijs/mcp 0.38.2 → 0.39.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
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CUSTOM_GATE_LIMITS: () => CUSTOM_GATE_LIMITS,
34
+ PLUGIN_ENV: () => PLUGIN_ENV,
34
35
  SWEEP_PRESETS: () => SWEEP_PRESETS,
35
36
  autoRigFromLayers: () => autoRigFromLayers,
36
37
  checkCustomGate: () => checkCustomGate,
@@ -59,6 +60,7 @@ __export(index_exports, {
59
60
  measureTurnReference: () => measureTurnReference,
60
61
  probeRig: () => probeRig,
61
62
  renderPoses: () => renderPoses,
63
+ toolGenerator: () => toolGenerator,
62
64
  validateIki: () => validateIki,
63
65
  viewIllustrationGrid: () => viewIllustrationGrid
64
66
  });
@@ -68,11 +70,32 @@ module.exports = __toCommonJS(index_exports);
68
70
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
69
71
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
70
72
 
73
+ // src/generator.ts
74
+ var import_editor = require("@ikijs/editor");
75
+ var import_format = require("@ikijs/format");
76
+ var PLUGIN_ENV = "IKI_PLUGIN";
77
+ function toolGenerator(env = process.env) {
78
+ const generator = {
79
+ tool: `@ikijs/mcp@${"0.39.1"}`,
80
+ rigger: `@ikijs/editor@${import_editor.EDITOR_VERSION}`
81
+ };
82
+ const plugin = env[PLUGIN_ENV];
83
+ if (plugin === void 0 || plugin === "") return generator;
84
+ try {
85
+ return (0, import_format.parseIkiGenerator)({ ...generator, plugin });
86
+ } catch (e) {
87
+ if (!(e instanceof import_format.IkiFormatError)) throw e;
88
+ throw new import_format.IkiFormatError(
89
+ `the ${PLUGIN_ENV} environment variable is no label for a model: ${e.message}`
90
+ );
91
+ }
92
+ }
93
+
71
94
  // src/tools.ts
72
95
  var import_node_fs6 = require("fs");
73
96
  var import_node_path5 = __toESM(require("path"));
74
- var import_format11 = require("@ikijs/format");
75
- var import_editor4 = require("@ikijs/editor");
97
+ var import_format12 = require("@ikijs/format");
98
+ var import_editor5 = require("@ikijs/editor");
76
99
 
77
100
  // ../engine/src/math.ts
78
101
  function clamp(value, min, max) {
@@ -503,7 +526,7 @@ function occlusionAmount(occlusion, value) {
503
526
  }
504
527
 
505
528
  // ../engine/src/idle-motion.ts
506
- var import_format = require("@ikijs/format");
529
+ var import_format2 = require("@ikijs/format");
507
530
 
508
531
  // ../engine/src/frame-clock.ts
509
532
  var MAX_DT_MS = 100;
@@ -644,6 +667,9 @@ var Spring = class {
644
667
  }
645
668
  }
646
669
  };
670
+ function eyeSpring() {
671
+ return new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
672
+ }
647
673
  var IdleMotion = class {
648
674
  /**
649
675
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -669,8 +695,8 @@ var IdleMotion = class {
669
695
  // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
670
696
  // first retarget. A host target, while set, replaces the pick as what the
671
697
  // eyes and head chase; the schedule keeps picking underneath it.
672
- eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
673
- eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
698
+ eyeX = eyeSpring();
699
+ eyeY = eyeSpring();
674
700
  gazeTargetX = 0;
675
701
  gazeTargetY = 0;
676
702
  nextGazeRetargetMs;
@@ -688,18 +714,18 @@ var IdleMotion = class {
688
714
  constructor(sink, options) {
689
715
  this.sink = sink;
690
716
  this.rng = options?.rng ?? Math.random;
691
- this.brows = [import_format.StandardParameter.BrowLeftY, import_format.StandardParameter.BrowRightY].map((id) => options?.parameters?.find((p) => p.id === id)).filter((p) => p !== void 0).map((p) => ({ id: p.id, rest: clamp(p.default, p.min, p.max) }));
717
+ this.brows = [import_format2.StandardParameter.BrowLeftY, import_format2.StandardParameter.BrowRightY].map((id) => options?.parameters?.find((p) => p.id === id)).filter((p) => p !== void 0).map((p) => ({ id: p.id, rest: clamp(p.default, p.min, p.max) }));
692
718
  this.drivenParameterIds = [
693
- import_format.StandardParameter.EyeOpenLeft,
694
- import_format.StandardParameter.EyeOpenRight,
719
+ import_format2.StandardParameter.EyeOpenLeft,
720
+ import_format2.StandardParameter.EyeOpenRight,
695
721
  ...this.brows.map((b) => b.id),
696
- import_format.StandardParameter.Breath,
697
- import_format.StandardParameter.EyeballX,
698
- import_format.StandardParameter.EyeballY,
699
- import_format.StandardParameter.AngleX,
700
- import_format.StandardParameter.AngleY,
701
- import_format.StandardParameter.AngleZ,
702
- import_format.StandardParameter.AmbientSway
722
+ import_format2.StandardParameter.Breath,
723
+ import_format2.StandardParameter.EyeballX,
724
+ import_format2.StandardParameter.EyeballY,
725
+ import_format2.StandardParameter.AngleX,
726
+ import_format2.StandardParameter.AngleY,
727
+ import_format2.StandardParameter.AngleZ,
728
+ import_format2.StandardParameter.AmbientSway
703
729
  ];
704
730
  this.nextBlinkAtMs = lerp(
705
731
  BLINK_INTERVAL_MIN_MS,
@@ -738,21 +764,21 @@ var IdleMotion = class {
738
764
  this.prevNowMs = nowMs;
739
765
  this.clockMs += dt;
740
766
  const eyeVal = this.advanceBlink();
741
- this.sink(import_format.StandardParameter.EyeOpenLeft, eyeVal);
742
- this.sink(import_format.StandardParameter.EyeOpenRight, eyeVal);
767
+ this.sink(import_format2.StandardParameter.EyeOpenLeft, eyeVal);
768
+ this.sink(import_format2.StandardParameter.EyeOpenRight, eyeVal);
743
769
  for (const { id, rest } of this.brows) {
744
770
  this.sink(id, rest + BROW_BLINK_DIP * (eyeVal - 1));
745
771
  }
746
772
  const breath = this.advanceBreath();
747
773
  this.advanceGaze(dt);
748
- this.sink(import_format.StandardParameter.Breath, breath);
749
- this.sink(import_format.StandardParameter.EyeballX, this.eyeX.value);
750
- this.sink(import_format.StandardParameter.EyeballY, this.eyeY.value);
774
+ this.sink(import_format2.StandardParameter.Breath, breath);
775
+ this.sink(import_format2.StandardParameter.EyeballX, this.eyeX.value);
776
+ this.sink(import_format2.StandardParameter.EyeballY, this.eyeY.value);
751
777
  this.advanceHead(dt, breath);
752
- this.sink(import_format.StandardParameter.AngleX, this.headX.value);
753
- this.sink(import_format.StandardParameter.AngleY, this.headY.value);
754
- this.sink(import_format.StandardParameter.AngleZ, this.headZ.value);
755
- this.sink(import_format.StandardParameter.AmbientSway, this.ambientSway());
778
+ this.sink(import_format2.StandardParameter.AngleX, this.headX.value);
779
+ this.sink(import_format2.StandardParameter.AngleY, this.headY.value);
780
+ this.sink(import_format2.StandardParameter.AngleZ, this.headZ.value);
781
+ this.sink(import_format2.StandardParameter.AmbientSway, this.ambientSway());
756
782
  }
757
783
  /**
758
784
  * Hold the gaze on (`x`, `y`), in EyeballX/Y units (+ is the viewer's right
@@ -782,16 +808,16 @@ var IdleMotion = class {
782
808
  // Private helpers
783
809
  // ---------------------------------------------------------------------------
784
810
  emitRestingPose() {
785
- this.sink(import_format.StandardParameter.EyeOpenLeft, 1);
786
- this.sink(import_format.StandardParameter.EyeOpenRight, 1);
811
+ this.sink(import_format2.StandardParameter.EyeOpenLeft, 1);
812
+ this.sink(import_format2.StandardParameter.EyeOpenRight, 1);
787
813
  for (const { id, rest } of this.brows) this.sink(id, rest);
788
- this.sink(import_format.StandardParameter.Breath, 0);
789
- this.sink(import_format.StandardParameter.EyeballX, 0);
790
- this.sink(import_format.StandardParameter.EyeballY, 0);
791
- this.sink(import_format.StandardParameter.AngleX, 0);
792
- this.sink(import_format.StandardParameter.AngleY, 0);
793
- this.sink(import_format.StandardParameter.AngleZ, 0);
794
- this.sink(import_format.StandardParameter.AmbientSway, 0);
814
+ this.sink(import_format2.StandardParameter.Breath, 0);
815
+ this.sink(import_format2.StandardParameter.EyeballX, 0);
816
+ this.sink(import_format2.StandardParameter.EyeballY, 0);
817
+ this.sink(import_format2.StandardParameter.AngleX, 0);
818
+ this.sink(import_format2.StandardParameter.AngleY, 0);
819
+ this.sink(import_format2.StandardParameter.AngleZ, 0);
820
+ this.sink(import_format2.StandardParameter.AmbientSway, 0);
795
821
  }
796
822
  /** Returns the current eye-open value (0..1) and advances blink state. */
797
823
  advanceBlink() {
@@ -878,7 +904,7 @@ var IdleMotion = class {
878
904
  };
879
905
 
880
906
  // ../engine/src/physics-motion.ts
881
- var import_format2 = require("@ikijs/format");
907
+ var import_format3 = require("@ikijs/format");
882
908
  function signedNormalized(value, param) {
883
909
  const rest = clamp(param.default, param.min, param.max);
884
910
  const den = Math.max(Math.abs(param.max - rest), Math.abs(rest - param.min));
@@ -906,7 +932,7 @@ var PhysicsMotion = class {
906
932
  constructor(rigs, params, read, sink) {
907
933
  this.rigs = rigs;
908
934
  this.inputs = rigs.map(
909
- (rig) => (0, import_format2.physicsInputs)(rig).map(({ parameter, weight, mode }) => ({
935
+ (rig) => (0, import_format3.physicsInputs)(rig).map(({ parameter, weight, mode }) => ({
910
936
  parameter,
911
937
  weight,
912
938
  lag: mode === "lag"
@@ -1163,25 +1189,25 @@ var HairChainMotion = class {
1163
1189
  };
1164
1190
 
1165
1191
  // ../engine/src/iki-motion.ts
1166
- var import_format5 = require("@ikijs/format");
1192
+ var import_format6 = require("@ikijs/format");
1167
1193
 
1168
1194
  // ../engine/src/clip-player.ts
1169
- var import_format3 = require("@ikijs/format");
1195
+ var import_format4 = require("@ikijs/format");
1170
1196
 
1171
1197
  // ../engine/src/expression-player.ts
1172
- var import_format4 = require("@ikijs/format");
1198
+ var import_format5 = require("@ikijs/format");
1173
1199
 
1174
1200
  // ../engine/src/iki-motion.ts
1175
1201
  var HEAD_AND_GAZE = /* @__PURE__ */ new Set([
1176
- import_format5.StandardParameter.AngleX,
1177
- import_format5.StandardParameter.AngleY,
1178
- import_format5.StandardParameter.AngleZ,
1179
- import_format5.StandardParameter.EyeballX,
1180
- import_format5.StandardParameter.EyeballY
1202
+ import_format6.StandardParameter.AngleX,
1203
+ import_format6.StandardParameter.AngleY,
1204
+ import_format6.StandardParameter.AngleZ,
1205
+ import_format6.StandardParameter.EyeballX,
1206
+ import_format6.StandardParameter.EyeballY
1181
1207
  ]);
1182
1208
 
1183
1209
  // ../engine/src/folds.ts
1184
- var import_format6 = require("@ikijs/format");
1210
+ var import_format7 = require("@ikijs/format");
1185
1211
 
1186
1212
  // ../engine/src/land.ts
1187
1213
  var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
@@ -1264,19 +1290,19 @@ function landParts(model, values, partIds) {
1264
1290
  var FLIP = 0;
1265
1291
  var COLLAPSE = 0.1;
1266
1292
  var ANGLES = [
1267
- import_format6.StandardParameter.AngleX,
1268
- import_format6.StandardParameter.AngleY,
1269
- import_format6.StandardParameter.AngleZ,
1270
- import_format6.StandardParameter.BodyAngleX,
1271
- import_format6.StandardParameter.BodyAngleY,
1272
- import_format6.StandardParameter.BodyAngleZ
1293
+ import_format7.StandardParameter.AngleX,
1294
+ import_format7.StandardParameter.AngleY,
1295
+ import_format7.StandardParameter.AngleZ,
1296
+ import_format7.StandardParameter.BodyAngleX,
1297
+ import_format7.StandardParameter.BodyAngleY,
1298
+ import_format7.StandardParameter.BodyAngleZ
1273
1299
  ];
1274
1300
  var CROSSES = [
1275
- [import_format6.StandardParameter.EyeOpenLeft],
1276
- [import_format6.StandardParameter.EyeOpenRight],
1277
- [import_format6.StandardParameter.MouthOpen],
1278
- [import_format6.StandardParameter.ArmLeft, import_format6.StandardParameter.ArmRight],
1279
- [import_format6.StandardParameter.ElbowLeft, import_format6.StandardParameter.ElbowRight]
1301
+ [import_format7.StandardParameter.EyeOpenLeft],
1302
+ [import_format7.StandardParameter.EyeOpenRight],
1303
+ [import_format7.StandardParameter.MouthOpen],
1304
+ [import_format7.StandardParameter.ArmLeft, import_format7.StandardParameter.ArmRight],
1305
+ [import_format7.StandardParameter.ElbowLeft, import_format7.StandardParameter.ElbowRight]
1280
1306
  ];
1281
1307
  function foldPoses(model) {
1282
1308
  const byId = new Map(
@@ -1494,7 +1520,7 @@ function classify(worst) {
1494
1520
  }
1495
1521
 
1496
1522
  // ../engine/src/physics-check.ts
1497
- var import_format7 = require("@ikijs/format");
1523
+ var import_format8 = require("@ikijs/format");
1498
1524
 
1499
1525
  // ../engine/src/physics-runs.ts
1500
1526
  var FRAME_MS = FIXED_DT_S * 1e3 * (1 + 1e-9);
@@ -1674,7 +1700,7 @@ function checkPhysics(model) {
1674
1700
  };
1675
1701
  const param = (id) => model.parameters.find((p) => p.id === id);
1676
1702
  const springs = (model.physics ?? []).map((rig) => {
1677
- const inputs = (0, import_format7.physicsInputs)(rig).map((i) => param(i.parameter));
1703
+ const inputs = (0, import_format8.physicsInputs)(rig).map((i) => param(i.parameter));
1678
1704
  const ids = inputs.map((p) => p.id);
1679
1705
  const output = param(rig.output.parameter);
1680
1706
  const ranged = inputs.flatMap((input) => {
@@ -2106,11 +2132,11 @@ function checkBakes(model, reports) {
2106
2132
  }
2107
2133
 
2108
2134
  // src/custom-gate.ts
2109
- var import_editor3 = require("@ikijs/editor");
2110
- var import_format9 = require("@ikijs/format");
2135
+ var import_editor4 = require("@ikijs/editor");
2136
+ var import_format10 = require("@ikijs/format");
2111
2137
 
2112
2138
  // src/fold-report.ts
2113
- var import_editor = require("@ikijs/editor");
2139
+ var import_editor2 = require("@ikijs/editor");
2114
2140
  function checkModelFolds(model, extraValues = []) {
2115
2141
  const declared = new Set(model.parameters.map((p) => p.id));
2116
2142
  return checkFolds(model, {
@@ -2120,7 +2146,7 @@ function checkModelFolds(model, extraValues = []) {
2120
2146
  // are shut-mouth poses too.
2121
2147
  expected: (target2, _pose, value) => {
2122
2148
  if (target2.kind !== "part") return false;
2123
- const shutBy = import_editor.SHUT_BY.get(target2.id);
2149
+ const shutBy = import_editor2.SHUT_BY.get(target2.id);
2124
2150
  return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
2125
2151
  }
2126
2152
  });
@@ -2130,7 +2156,7 @@ function formatFoldReport(report, canvas) {
2130
2156
  const closures = report.targets.flatMap((t) => {
2131
2157
  if (t.expected === void 0) return [];
2132
2158
  if (t.expected.ratio >= report.thresholds.collapse) return [];
2133
- const shutBy = import_editor.SHUT_BY.get(t.target.id);
2159
+ const shutBy = import_editor2.SHUT_BY.get(t.target.id);
2134
2160
  const at = shutBy === void 0 ? "" : ` at ${shutBy}=0`;
2135
2161
  return [`${t.target.id} ${ratioText(t.expected.ratio)}${at}`];
2136
2162
  });
@@ -2158,11 +2184,11 @@ function ratioText(ratio) {
2158
2184
 
2159
2185
  // src/probe.ts
2160
2186
  var import_node_fs2 = require("fs");
2161
- var import_format8 = require("@ikijs/format");
2187
+ var import_format9 = require("@ikijs/format");
2162
2188
 
2163
2189
  // src/node-images.ts
2164
2190
  var import_sharp = __toESM(require("sharp"));
2165
- var import_editor2 = require("@ikijs/editor");
2191
+ var import_editor3 = require("@ikijs/editor");
2166
2192
  async function decodePng(filePath) {
2167
2193
  try {
2168
2194
  const pipeline = (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS });
@@ -2186,7 +2212,7 @@ async function decodePng(filePath) {
2186
2212
  }
2187
2213
  }
2188
2214
  function detectAlphaBbox(rgba, width, height) {
2189
- const bbox = (0, import_editor2.detectAlphaBbox)(rgba, width, height);
2215
+ const bbox = (0, import_editor3.detectAlphaBbox)(rgba, width, height);
2190
2216
  if (bbox === null) {
2191
2217
  throw new AutoRigInputError("layer is empty after alpha threshold");
2192
2218
  }
@@ -2434,7 +2460,7 @@ async function probeRig(input) {
2434
2460
  "model path",
2435
2461
  input.modelPath
2436
2462
  );
2437
- const model = (0, import_format8.loadIkiModel)((0, import_node_fs2.readFileSync)(modelFile, "utf8"));
2463
+ const model = (0, import_format9.loadIkiModel)((0, import_node_fs2.readFileSync)(modelFile, "utf8"));
2438
2464
  if (!Array.isArray(input.queries) || input.queries.length === 0) {
2439
2465
  throw new AutoRigInputError("queries must be a non-empty list");
2440
2466
  }
@@ -2457,7 +2483,7 @@ async function probeRig(input) {
2457
2483
  lines: results.map(summarize)
2458
2484
  };
2459
2485
  } catch (e) {
2460
- if (e instanceof AutoRigInputError || e instanceof import_format8.IkiFormatError) {
2486
+ if (e instanceof AutoRigInputError || e instanceof import_format9.IkiFormatError) {
2461
2487
  return { ok: false, error: e.message };
2462
2488
  }
2463
2489
  throw e;
@@ -2650,9 +2676,9 @@ function checkCustomGate(model, parts, paints, options = {}) {
2650
2676
  const px2 = (twin) => Math.max(1, Math.round(twin * scale2));
2651
2677
  const cache = /* @__PURE__ */ new Map();
2652
2678
  const turnParam = model.parameters.find(
2653
- (p) => p.id === import_format9.StandardParameter.AngleX
2679
+ (p) => p.id === import_format10.StandardParameter.AngleX
2654
2680
  );
2655
- const turns = (pose) => turnParam !== void 0 && (pose.values[import_format9.StandardParameter.AngleX] ?? turnParam.default) !== turnParam.default;
2681
+ const turns = (pose) => turnParam !== void 0 && (pose.values[import_format10.StandardParameter.AngleX] ?? turnParam.default) !== turnParam.default;
2656
2682
  const bakedOf = (id) => {
2657
2683
  const part = model.parts.find((p) => p.id === id);
2658
2684
  return new Map(
@@ -2681,7 +2707,7 @@ function checkCustomGate(model, parts, paints, options = {}) {
2681
2707
  const all = new Map(poseSets.flat().map((p) => [p.name, p]));
2682
2708
  const reports = parts.map((part, n) => {
2683
2709
  const poses = poseSets[n];
2684
- const roleParts = (0, import_editor3.partIdsOfRole)(part.anchor).filter(
2710
+ const roleParts = (0, import_editor4.partIdsOfRole)(part.anchor).filter(
2685
2711
  (id) => model.parts.some((p) => p.id === id)
2686
2712
  );
2687
2713
  const anchorId = roleParts.find(
@@ -2765,7 +2791,7 @@ function checkCustomGate(model, parts, paints, options = {}) {
2765
2791
  const coverParts = [];
2766
2792
  if (occlusion !== void 0) {
2767
2793
  for (const role of part.occludedBy ?? []) {
2768
- for (const id of (0, import_editor3.partIdsOfRole)(role)) {
2794
+ for (const id of (0, import_editor4.partIdsOfRole)(role)) {
2769
2795
  const o = model.parts.find((p) => p.id === id);
2770
2796
  if (o === void 0 || !occlusion.by.includes(id)) continue;
2771
2797
  const steady = o.color[3] === 1 && (o.transform.opacity ?? 1) >= 1 && !(o.bindings ?? []).some((b) => b.channel === "opacity");
@@ -2825,7 +2851,7 @@ function checkCustomGate(model, parts, paints, options = {}) {
2825
2851
  const moved = [];
2826
2852
  for (let i = 0; i < posed.length; i += 2)
2827
2853
  moved.push([posed[i], posed[i + 1]]);
2828
- keep(worstOf.rigid, (0, import_editor3.rigidResidual)(restPoints, moved), pose.name);
2854
+ keep(worstOf.rigid, (0, import_editor4.rigidResidual)(restPoints, moved), pose.name);
2829
2855
  };
2830
2856
  for (const pose of poses) {
2831
2857
  const hiding = occlusion !== void 0 && hiddenAt(keyOf(pose.values));
@@ -3128,7 +3154,7 @@ function formatCustomGate(report) {
3128
3154
  // src/render-poses.ts
3129
3155
  var import_node_fs5 = require("fs");
3130
3156
  var import_node_path4 = __toESM(require("path"));
3131
- var import_format10 = require("@ikijs/format");
3157
+ var import_format11 = require("@ikijs/format");
3132
3158
 
3133
3159
  // src/render-browser.ts
3134
3160
  var import_node_child_process = require("child_process");
@@ -4063,9 +4089,9 @@ function planRenders(model, requested, sweep, sweeps) {
4063
4089
  }
4064
4090
  const bodyAngles = Object.fromEntries(
4065
4091
  [
4066
- import_format10.StandardParameter.BodyAngleX,
4067
- import_format10.StandardParameter.BodyAngleY,
4068
- import_format10.StandardParameter.BodyAngleZ
4092
+ import_format11.StandardParameter.BodyAngleX,
4093
+ import_format11.StandardParameter.BodyAngleY,
4094
+ import_format11.StandardParameter.BodyAngleZ
4069
4095
  ].filter((id) => model.parameters.some((p) => p.id === id)).map((id) => [id, -10])
4070
4096
  );
4071
4097
  const poses = [
@@ -4151,7 +4177,7 @@ function planRenders(model, requested, sweep, sweeps) {
4151
4177
  whole("full-elbow-r-45", { ParamElbowR: 45 }),
4152
4178
  whole("full-elbow-r-90", { ParamElbowR: 90 })
4153
4179
  );
4154
- if (model.parameters.some((p) => p.id === import_format10.StandardParameter.ArmPoseRight)) {
4180
+ if (model.parameters.some((p) => p.id === import_format11.StandardParameter.ArmPoseRight)) {
4155
4181
  poses.push(
4156
4182
  whole("full-pose-l", { ParamArmPoseL: 1 }),
4157
4183
  whole("full-pose-r", { ParamArmPoseR: 1 }),
@@ -4327,7 +4353,7 @@ async function renderPoses(input) {
4327
4353
  input.modelPath
4328
4354
  );
4329
4355
  const outDir = resolveOutputDir(input.outDir);
4330
- const model = (0, import_format10.loadIkiModel)((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
4356
+ const model = (0, import_format11.loadIkiModel)((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
4331
4357
  const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
4332
4358
  const drawn = input.hideParts ? withoutParts(model, input.hideParts) : model;
4333
4359
  const browser = findBrowser();
@@ -4420,7 +4446,7 @@ async function renderPoses(input) {
4420
4446
  sweeps
4421
4447
  };
4422
4448
  } catch (error) {
4423
- if (error instanceof AutoRigInputError || error instanceof import_format10.IkiFormatError) {
4449
+ if (error instanceof AutoRigInputError || error instanceof import_format11.IkiFormatError) {
4424
4450
  return { ok: false, error: error.message };
4425
4451
  }
4426
4452
  throw error;
@@ -4430,10 +4456,10 @@ async function renderPoses(input) {
4430
4456
  // src/tools.ts
4431
4457
  function coerceModel(model) {
4432
4458
  try {
4433
- const parsed = typeof model === "string" ? (0, import_format11.loadIkiModel)(model) : (0, import_format11.parseIkiModel)(model);
4459
+ const parsed = typeof model === "string" ? (0, import_format12.loadIkiModel)(model) : (0, import_format12.parseIkiModel)(model);
4434
4460
  return { ok: true, model: parsed };
4435
4461
  } catch (e) {
4436
- if (e instanceof import_format11.IkiFormatError) return { ok: false, error: e.message };
4462
+ if (e instanceof import_format12.IkiFormatError) return { ok: false, error: e.message };
4437
4463
  throw e;
4438
4464
  }
4439
4465
  }
@@ -4530,6 +4556,7 @@ function describeIki(model) {
4530
4556
  motions,
4531
4557
  bustScale
4532
4558
  };
4559
+ if (m.generator !== void 0) summary.generator = m.generator;
4533
4560
  const face = m.parts.find((p) => p.id === "face");
4534
4561
  if (face !== void 0) summary.faceWidth = face.width;
4535
4562
  return { ok: true, summary };
@@ -4550,123 +4577,123 @@ function describeIkiAt(modelPath) {
4550
4577
  }
4551
4578
  var STANDARD_PARAMETER_INFO = [
4552
4579
  {
4553
- id: import_format11.StandardParameter.MouthOpen,
4580
+ id: import_format12.StandardParameter.MouthOpen,
4554
4581
  description: "Mouth open amount for lip-sync (0 closed .. 1 open)."
4555
4582
  },
4556
4583
  {
4557
- id: import_format11.StandardParameter.MouthForm,
4584
+ id: import_format12.StandardParameter.MouthForm,
4558
4585
  description: "Mouth form / smile (-1 .. 1)."
4559
4586
  },
4560
4587
  {
4561
- id: import_format11.StandardParameter.EyeOpenLeft,
4588
+ id: import_format12.StandardParameter.EyeOpenLeft,
4562
4589
  description: "Left eye open (0 closed .. 1 open). Drive with the right eye for a blink."
4563
4590
  },
4564
4591
  {
4565
- id: import_format11.StandardParameter.EyeOpenRight,
4592
+ id: import_format12.StandardParameter.EyeOpenRight,
4566
4593
  description: "Right eye open (0 closed .. 1 open)."
4567
4594
  },
4568
4595
  {
4569
- id: import_format11.StandardParameter.EyeballX,
4596
+ id: import_format12.StandardParameter.EyeballX,
4570
4597
  description: "Eyeball gaze, horizontal (-1 .. 1)."
4571
4598
  },
4572
4599
  {
4573
- id: import_format11.StandardParameter.EyeballY,
4600
+ id: import_format12.StandardParameter.EyeballY,
4574
4601
  description: "Eyeball gaze, vertical (-1 .. 1)."
4575
4602
  },
4576
4603
  {
4577
- id: import_format11.StandardParameter.AngleX,
4604
+ id: import_format12.StandardParameter.AngleX,
4578
4605
  description: "Head angle, horizontal degrees."
4579
4606
  },
4580
4607
  {
4581
- id: import_format11.StandardParameter.AngleY,
4608
+ id: import_format12.StandardParameter.AngleY,
4582
4609
  description: "Head angle, vertical degrees."
4583
4610
  },
4584
4611
  {
4585
- id: import_format11.StandardParameter.AngleZ,
4612
+ id: import_format12.StandardParameter.AngleZ,
4586
4613
  description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
4587
4614
  },
4588
4615
  {
4589
- id: import_format11.StandardParameter.BodyAngleX,
4616
+ id: import_format12.StandardParameter.BodyAngleX,
4590
4617
  description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
4591
4618
  },
4592
4619
  {
4593
- id: import_format11.StandardParameter.BodyAngleY,
4620
+ id: import_format12.StandardParameter.BodyAngleY,
4594
4621
  description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
4595
4622
  },
4596
4623
  {
4597
- id: import_format11.StandardParameter.BodyAngleZ,
4624
+ id: import_format12.StandardParameter.BodyAngleZ,
4598
4625
  description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
4599
4626
  },
4600
4627
  {
4601
- id: import_format11.StandardParameter.Breath,
4628
+ id: import_format12.StandardParameter.Breath,
4602
4629
  description: "Idle breath (0 .. 1), cycled by the host."
4603
4630
  },
4604
4631
  {
4605
- id: import_format11.StandardParameter.AmbientSway,
4632
+ id: import_format12.StandardParameter.AmbientSway,
4606
4633
  description: "Ambient sway (-1 .. 1): a slow zero-mean drift the idle writes for physics rigs to follow (the auto-rig's hair in idle). Not a wind: no bias. Stays procedural under a declared Idle group, as Breath does."
4607
4634
  },
4608
4635
  {
4609
- id: import_format11.StandardParameter.BrowLeftY,
4636
+ id: import_format12.StandardParameter.BrowLeftY,
4610
4637
  description: "Left brow raise/lower (-1 .. 1)."
4611
4638
  },
4612
4639
  {
4613
- id: import_format11.StandardParameter.BrowRightY,
4640
+ id: import_format12.StandardParameter.BrowRightY,
4614
4641
  description: "Right brow raise/lower (-1 .. 1)."
4615
4642
  },
4616
4643
  {
4617
- id: import_format11.StandardParameter.BrowLeftAngle,
4644
+ id: import_format12.StandardParameter.BrowLeftAngle,
4618
4645
  description: "Left brow tilt/angle (-1 .. 1)."
4619
4646
  },
4620
4647
  {
4621
- id: import_format11.StandardParameter.BrowRightAngle,
4648
+ id: import_format12.StandardParameter.BrowRightAngle,
4622
4649
  description: "Right brow tilt/angle (-1 .. 1)."
4623
4650
  },
4624
4651
  {
4625
- id: import_format11.StandardParameter.Cheek,
4652
+ id: import_format12.StandardParameter.Cheek,
4626
4653
  description: "Cheek blush strength (0 .. 1), raised by an expression."
4627
4654
  },
4628
4655
  {
4629
- id: import_format11.StandardParameter.HairSwayX,
4656
+ id: import_format12.StandardParameter.HairSwayX,
4630
4657
  description: "Front hair's horizontal sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
4631
4658
  },
4632
4659
  {
4633
- id: import_format11.StandardParameter.HairSwayZ,
4660
+ id: import_format12.StandardParameter.HairSwayZ,
4634
4661
  description: "Front hair's sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
4635
4662
  },
4636
4663
  {
4637
- id: import_format11.StandardParameter.HairBackSway,
4664
+ id: import_format12.StandardParameter.HairBackSway,
4638
4665
  description: "Back hair's sway driver behind the head turn, tilt and ambient drift, one spring slower than the front hair's so the two swing out of phase. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
4639
4666
  },
4640
4667
  {
4641
- id: import_format11.StandardParameter.ArmLeft,
4668
+ id: import_format12.StandardParameter.ArmLeft,
4642
4669
  description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
4643
4670
  },
4644
4671
  {
4645
- id: import_format11.StandardParameter.ArmRight,
4672
+ id: import_format12.StandardParameter.ArmRight,
4646
4673
  description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
4647
4674
  },
4648
4675
  {
4649
- id: import_format11.StandardParameter.ElbowLeft,
4676
+ id: import_format12.StandardParameter.ElbowLeft,
4650
4677
  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)."
4651
4678
  },
4652
4679
  {
4653
- id: import_format11.StandardParameter.ElbowRight,
4680
+ id: import_format12.StandardParameter.ElbowRight,
4654
4681
  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)."
4655
4682
  },
4656
4683
  {
4657
- id: import_format11.StandardParameter.ArmPoseLeft,
4684
+ id: import_format12.StandardParameter.ArmPoseLeft,
4658
4685
  description: "Left pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
4659
4686
  },
4660
4687
  {
4661
- id: import_format11.StandardParameter.ArmPoseRight,
4688
+ id: import_format12.StandardParameter.ArmPoseRight,
4662
4689
  description: "Right pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
4663
4690
  },
4664
4691
  {
4665
- id: import_format11.StandardParameter.ArmPoseAngleLeft,
4692
+ id: import_format12.StandardParameter.ArmPoseAngleLeft,
4666
4693
  description: "Left pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the right)."
4667
4694
  },
4668
4695
  {
4669
- id: import_format11.StandardParameter.ArmPoseAngleRight,
4696
+ id: import_format12.StandardParameter.ArmPoseAngleRight,
4670
4697
  description: "Right pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the left)."
4671
4698
  }
4672
4699
  ];
@@ -4674,10 +4701,10 @@ function listStandardParameters() {
4674
4701
  return STANDARD_PARAMETER_INFO.map((p) => ({ ...p }));
4675
4702
  }
4676
4703
  function describeRigPlan() {
4677
- return { fields: [...import_editor4.RIG_PLAN_FIELDS] };
4704
+ return { fields: [...import_editor5.RIG_PLAN_FIELDS] };
4678
4705
  }
4679
4706
  function formatRigPlanReport(r) {
4680
- const fields = import_editor4.RIG_PLAN_FIELDS.map((f) => {
4707
+ const fields = import_editor5.RIG_PLAN_FIELDS.map((f) => {
4681
4708
  const value = `${f.path}=${r.effective[f.path]}`;
4682
4709
  const clamp2 = r.clamped.find((c) => c.field === f.path);
4683
4710
  if (clamp2 !== void 0) {
@@ -4700,7 +4727,7 @@ function expectInput(label, fn) {
4700
4727
  }
4701
4728
  var LOSSLESS_PAGE_ROLE = "nose";
4702
4729
  async function renderAtlasPage(crops, quantizeColors) {
4703
- const layout = (0, import_editor4.packAtlas)(
4730
+ const layout = (0, import_editor5.packAtlas)(
4704
4731
  crops.map((c) => ({ id: c.id, width: c.width, height: c.height })),
4705
4732
  void 0,
4706
4733
  MAX_ATLAS_SIDE
@@ -4719,6 +4746,14 @@ async function renderAtlasPage(crops, quantizeColors) {
4719
4746
  }
4720
4747
  async function autoRigFromLayers(input) {
4721
4748
  try {
4749
+ if (input.generator !== void 0) {
4750
+ try {
4751
+ (0, import_format12.parseIkiGenerator)(input.generator);
4752
+ } catch (e) {
4753
+ if (e instanceof import_format12.IkiFormatError) throw new AutoRigInputError(e.message);
4754
+ throw e;
4755
+ }
4756
+ }
4722
4757
  const layers = input.layers;
4723
4758
  if (!Array.isArray(layers) || layers.length === 0) {
4724
4759
  throw new AutoRigInputError("layers must be a non-empty array");
@@ -4749,7 +4784,7 @@ async function autoRigFromLayers(input) {
4749
4784
  );
4750
4785
  }
4751
4786
  if (input.style !== void 0) {
4752
- throw new AutoRigInputError((0, import_editor4.styleRemovedMessage)("style"));
4787
+ throw new AutoRigInputError((0, import_editor5.styleRemovedMessage)("style"));
4753
4788
  }
4754
4789
  const turnTargets = input.turnTargets;
4755
4790
  if (turnTargets !== void 0) {
@@ -4771,7 +4806,7 @@ async function autoRigFromLayers(input) {
4771
4806
  );
4772
4807
  const rolePairs = expectInput(
4773
4808
  "role parsing",
4774
- () => (0, import_editor4.parseLayerRoles)(resolvedLayers.map((r) => r.fileName))
4809
+ () => (0, import_editor5.parseLayerRoles)(resolvedLayers.map((r) => r.fileName))
4775
4810
  );
4776
4811
  const roleByFileName = new Map(rolePairs.map((p) => [p.fileName, p.role]));
4777
4812
  let canvasW = 0;
@@ -4805,7 +4840,7 @@ async function autoRigFromLayers(input) {
4805
4840
  `canvas ${canvasW}x${canvasH} exceeds ${MAX_CANVAS_DIM}`
4806
4841
  );
4807
4842
  }
4808
- measurer = (0, import_editor4.createLayerSetMeasurer)({ width: canvasW, height: canvasH });
4843
+ measurer = (0, import_editor5.createLayerSetMeasurer)({ width: canvasW, height: canvasH });
4809
4844
  } else if (png.width !== canvasW || png.height !== canvasH) {
4810
4845
  throw new AutoRigInputError(
4811
4846
  `layer "${fileName}" size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
@@ -4849,7 +4884,7 @@ async function autoRigFromLayers(input) {
4849
4884
  `${at}.path size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
4850
4885
  );
4851
4886
  }
4852
- const bbox = (0, import_editor4.detectAlphaBbox)(png.rgba, png.width, png.height);
4887
+ const bbox = (0, import_editor5.detectAlphaBbox)(png.rgba, png.width, png.height);
4853
4888
  if (bbox === null) {
4854
4889
  throw new AutoRigInputError(
4855
4890
  `${at}.path "${import_node_path5.default.basename(resolved)}": layer is empty after alpha threshold`
@@ -4876,7 +4911,7 @@ async function autoRigFromLayers(input) {
4876
4911
  let bakeReports;
4877
4912
  let model;
4878
4913
  try {
4879
- model = (0, import_editor4.generateIkiFromLayerSet)(
4914
+ model = (0, import_editor5.generateIkiFromLayerSet)(
4880
4915
  measurement.layers,
4881
4916
  { width: canvasW, height: canvasH },
4882
4917
  {
@@ -4916,12 +4951,12 @@ async function autoRigFromLayers(input) {
4916
4951
  }
4917
4952
  );
4918
4953
  } catch (e) {
4919
- if (!(e instanceof import_editor4.TurnTargetError || e instanceof import_editor4.LayerGeometryError || e instanceof import_editor4.PatchError || e instanceof import_editor4.RigPlanError || e instanceof import_editor4.CustomPartError || e instanceof import_editor4.BakeError)) {
4954
+ if (!(e instanceof import_editor5.TurnTargetError || e instanceof import_editor5.LayerGeometryError || e instanceof import_editor5.PatchError || e instanceof import_editor5.RigPlanError || e instanceof import_editor5.CustomPartError || e instanceof import_editor5.BakeError)) {
4920
4955
  throw e;
4921
4956
  }
4922
4957
  throw new AutoRigInputError(e.message);
4923
4958
  }
4924
- const doc = new import_editor4.EditorDocument(model);
4959
+ const doc = new import_editor5.EditorDocument(model);
4925
4960
  const losslessCrop = quantizeColors === void 0 ? void 0 : crops.find((c) => c.id === LOSSLESS_PAGE_ROLE);
4926
4961
  const pages = losslessCrop === void 0 ? [await renderAtlasPage(crops, quantizeColors)] : [
4927
4962
  await renderAtlasPage(
@@ -4944,11 +4979,11 @@ async function autoRigFromLayers(input) {
4944
4979
  if (placement3 === void 0) {
4945
4980
  throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
4946
4981
  }
4947
- const uv = (0, import_editor4.uvRectFor)(placement3, {
4982
+ const uv = (0, import_editor5.uvRectFor)(placement3, {
4948
4983
  width: layout.pageWidth,
4949
4984
  height: layout.pageHeight
4950
4985
  });
4951
- return (0, import_editor4.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
4986
+ return (0, import_editor5.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
4952
4987
  })
4953
4988
  );
4954
4989
  if (customPage !== void 0) {
@@ -4959,7 +4994,7 @@ async function autoRigFromLayers(input) {
4959
4994
  );
4960
4995
  return {
4961
4996
  partId: crop.id,
4962
- uv: (0, import_editor4.uvRectFor)(placement3, {
4997
+ uv: (0, import_editor5.uvRectFor)(placement3, {
4963
4998
  width: customPage.layout.pageWidth,
4964
4999
  height: customPage.layout.pageHeight
4965
5000
  })
@@ -4976,7 +5011,7 @@ async function autoRigFromLayers(input) {
4976
5011
  patched = structuredClone(patched);
4977
5012
  patched.textures = allPages.map((p) => ({ source: p.dataUri }));
4978
5013
  if (losslessCrop !== void 0) {
4979
- for (const partId of (0, import_editor4.partIdsOfRole)(losslessCrop.id)) {
5014
+ for (const partId of (0, import_editor5.partIdsOfRole)(losslessCrop.id)) {
4980
5015
  patched.parts.find((p) => p.id === partId).texture.index = 1;
4981
5016
  }
4982
5017
  }
@@ -4984,7 +5019,9 @@ async function autoRigFromLayers(input) {
4984
5019
  patched.parts.find((p) => p.id === crop.id).texture.index = pages.length;
4985
5020
  }
4986
5021
  }
4987
- const finalModel = (0, import_format11.parseIkiModel)(patched);
5022
+ const finalModel = (0, import_format12.parseIkiModel)(
5023
+ input.generator === void 0 ? patched : { ...patched, generator: input.generator }
5024
+ );
4988
5025
  const bakes = bakeReports === void 0 ? void 0 : checkBakes(finalModel, bakeReports);
4989
5026
  writeFileAtomic(outPath, JSON.stringify(finalModel));
4990
5027
  const folds = checkModelFolds(finalModel);
@@ -5055,10 +5092,10 @@ async function autoRigFromLayers(input) {
5055
5092
  var import_node_fs8 = __toESM(require("fs"));
5056
5093
  var import_node_path10 = __toESM(require("path"));
5057
5094
  var import_sharp4 = __toESM(require("sharp"));
5058
- var import_editor14 = require("@ikijs/editor");
5095
+ var import_editor15 = require("@ikijs/editor");
5059
5096
 
5060
5097
  // src/trim.ts
5061
- var import_editor5 = require("@ikijs/editor");
5098
+ var import_editor6 = require("@ikijs/editor");
5062
5099
  var TRIM_THRESHOLD = 12;
5063
5100
  var STRAY_SPECK_FRACTION = 0.01;
5064
5101
  function luma(rgba, i) {
@@ -5087,7 +5124,7 @@ function boxWithoutStraySpecks(rgba, W, H) {
5087
5124
  while (depth > 0) {
5088
5125
  const p = stack[--depth];
5089
5126
  size++;
5090
- if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
5127
+ if (rgba[p * 4 + 3] >= import_editor6.ALPHA_OPAQUE) opaque = true;
5091
5128
  const px2 = p % W;
5092
5129
  const py = (p - px2) / W;
5093
5130
  setLeft = Math.min(setLeft, px2);
@@ -5129,7 +5166,9 @@ var import_node_path9 = __toESM(require("path"));
5129
5166
 
5130
5167
  // src/measure-arms.ts
5131
5168
  var import_node_path6 = __toESM(require("path"));
5132
- var import_editor6 = require("@ikijs/editor");
5169
+ var import_editor7 = require("@ikijs/editor");
5170
+ var UPPER_BODY = 0.35;
5171
+ var NARROW_ROW = 0.6;
5133
5172
  var ARM_ROLES = ["arm_L", "arm_R"];
5134
5173
  var CAP_OVERLAP = 0.5;
5135
5174
  var px = (v) => `${Number(v.toFixed(1))}`;
@@ -5158,7 +5197,7 @@ async function armWarnings(absDir, layers) {
5158
5197
  continue;
5159
5198
  }
5160
5199
  if (set === void 0) {
5161
- const measurer = (0, import_editor6.createLayerSetMeasurer)({
5200
+ const measurer = (0, import_editor7.createLayerSetMeasurer)({
5162
5201
  width: body.canvasW,
5163
5202
  height: body.canvasH
5164
5203
  });
@@ -5166,12 +5205,12 @@ async function armWarnings(absDir, layers) {
5166
5205
  }
5167
5206
  let g;
5168
5207
  try {
5169
- g = (0, import_editor6.armGeometry)(
5208
+ g = (0, import_editor7.armGeometry)(
5170
5209
  await measured(set.measurer, absDir, arm),
5171
5210
  set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
5172
5211
  );
5173
5212
  } catch (err) {
5174
- if (err instanceof import_editor6.LayerGeometryError) {
5213
+ if (err instanceof import_editor7.LayerGeometryError) {
5175
5214
  warnings.push(
5176
5215
  `${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
5177
5216
  );
@@ -5195,11 +5234,24 @@ function capWarning(arm, g, body) {
5195
5234
  const overlap = g.shoulderRadius - g.side * (pivotX - edge);
5196
5235
  const need = CAP_OVERLAP * g.shoulderRadius;
5197
5236
  if (overlap >= need) return void 0;
5237
+ const crop = row - body.bbox.y;
5238
+ const width = (r) => r === void 0 || r.length === 0 ? 0 : r[r.length - 1] - r[0];
5239
+ const here = width(runs);
5240
+ let below = 0;
5241
+ let belowRow = row;
5242
+ const end = Math.ceil(UPPER_BODY * body.bbox.h);
5243
+ for (let k = crop + 1; k < end; k++) {
5244
+ const w = width(body.rowRuns?.[k]);
5245
+ if (w > below) [below, belowRow] = [w, body.bbox.y + k];
5246
+ }
5247
+ if (here < NARROW_ROW * below) {
5248
+ 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), and the body is ${here} px wide there against ${below} px at y=${belowRow}. Read the shoulder line off preview.png: if that row is the neck, move layout.${arm}.cy down by the px the shoulder line lies under y=${row} (free) \u2014 not its cx, which hangs the arm from the neck; if it is the shoulders over a wider garment, move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
5249
+ }
5198
5250
  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).`;
5199
5251
  }
5200
5252
 
5201
5253
  // src/measure-hair-side.ts
5202
- var import_editor7 = require("@ikijs/editor");
5254
+ var import_editor8 = require("@ikijs/editor");
5203
5255
  var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
5204
5256
  var VISIBLE_MIN_PX = 3;
5205
5257
  var LEAN_HH = 0.12;
@@ -5247,7 +5299,7 @@ async function hairSideWarnings(absDir, layers, inPlace = false) {
5247
5299
  }
5248
5300
  }
5249
5301
  if (mismatched) return warnings;
5250
- const measurer = (0, import_editor7.createLayerSetMeasurer)({
5302
+ const measurer = (0, import_editor8.createLayerSetMeasurer)({
5251
5303
  width: ref.canvasW,
5252
5304
  height: ref.canvasH
5253
5305
  });
@@ -5386,7 +5438,7 @@ function drawsTwoLocks(lock) {
5386
5438
  }
5387
5439
 
5388
5440
  // src/measure-forearm-pose.ts
5389
- var import_editor8 = require("@ikijs/editor");
5441
+ var import_editor9 = require("@ikijs/editor");
5390
5442
  var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
5391
5443
  var ARM_OF = {
5392
5444
  forearm_pose_L: "arm_L",
@@ -5420,7 +5472,7 @@ async function forearmPoseWarnings(absDir, layers) {
5420
5472
  continue;
5421
5473
  }
5422
5474
  if (layers.body === void 0) continue;
5423
- const measurer = (0, import_editor8.createLayerSetMeasurer)({
5475
+ const measurer = (0, import_editor9.createLayerSetMeasurer)({
5424
5476
  width: stats.canvasW,
5425
5477
  height: stats.canvasH
5426
5478
  });
@@ -5428,12 +5480,12 @@ async function forearmPoseWarnings(absDir, layers) {
5428
5480
  let armLayer;
5429
5481
  try {
5430
5482
  armLayer = await measured(measurer, absDir, arm);
5431
- a = (0, import_editor8.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
5483
+ a = (0, import_editor9.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
5432
5484
  } catch (err) {
5433
- if (err instanceof import_editor8.LayerGeometryError) continue;
5485
+ if (err instanceof import_editor9.LayerGeometryError) continue;
5434
5486
  throw err;
5435
5487
  }
5436
- const b = (0, import_editor8.forearmPoseGeometry)(await measured(measurer, absDir, pose));
5488
+ const b = (0, import_editor9.forearmPoseGeometry)(await measured(measurer, absDir, pose));
5437
5489
  warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
5438
5490
  }
5439
5491
  return warnings;
@@ -5473,11 +5525,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
5473
5525
 
5474
5526
  // src/measure-lips.ts
5475
5527
  var import_node_path7 = __toESM(require("path"));
5476
- var import_editor10 = require("@ikijs/editor");
5528
+ var import_editor11 = require("@ikijs/editor");
5477
5529
 
5478
5530
  // src/compose-lips.ts
5479
5531
  var import_sharp2 = __toESM(require("sharp"));
5480
- var import_editor9 = require("@ikijs/editor");
5532
+ var import_editor10 = require("@ikijs/editor");
5481
5533
  var KEYED_SRC = "mouth_keyed.png";
5482
5534
  var INTERIOR_SRC = "mouth_interior.png";
5483
5535
  var KEY_CANDIDATE = 0.5;
@@ -5575,7 +5627,7 @@ function keyGreen(rgba, W, H) {
5575
5627
  let candidates = 0;
5576
5628
  for (let p = 0; p < n; p++) {
5577
5629
  const i = p * 4;
5578
- if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
5630
+ if (rgba[i + 3] < import_editor10.ALPHA_OPAQUE) continue;
5579
5631
  const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
5580
5632
  if (excess < KEY_CANDIDATE) continue;
5581
5633
  candidates++;
@@ -5602,7 +5654,7 @@ function keyGreen(rgba, W, H) {
5602
5654
  const dg = rgba[i + 1] - G[1];
5603
5655
  const db = rgba[i + 2] - G[2];
5604
5656
  const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
5605
- if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) {
5657
+ if (rgba[i + 3] < import_editor10.ALPHA_OPAQUE) {
5606
5658
  if (green) out[i + 3] = 0;
5607
5659
  } else if (green) {
5608
5660
  fill[p] = 1;
@@ -5657,6 +5709,15 @@ function keyGreen(rgba, W, H) {
5657
5709
  }
5658
5710
  return out;
5659
5711
  }
5712
+ var SPILL_REACH = 3;
5713
+ function despill(rgba, only) {
5714
+ for (let i = 0; i < rgba.length; i += 4) {
5715
+ if (only !== void 0 && !only[i >> 2]) continue;
5716
+ const cap = Math.max(rgba[i], rgba[i + 2]);
5717
+ if (rgba[i + 1] > cap) rgba[i + 1] = cap;
5718
+ }
5719
+ return rgba;
5720
+ }
5660
5721
  var GROUND_TOLERANCE = 4;
5661
5722
  var GROUND_LIGHT = 200;
5662
5723
  var GROUND_MIN = 238;
@@ -5778,7 +5839,7 @@ async function prepInterior(rgba, W, H) {
5778
5839
  for (let y = box3.y; y < box3.y + box3.h; y++) {
5779
5840
  for (let x = box3.x; x < box3.x + box3.w; x++) {
5780
5841
  const i = (y * cw + x) * 4;
5781
- if (crop[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
5842
+ if (crop[i + 3] < import_editor10.ALPHA_OPAQUE) continue;
5782
5843
  count2++;
5783
5844
  for (let c = 0; c < 3; c++) all[c] += crop[i + c];
5784
5845
  if (luma(crop, i) < CAVITY_LUMA) {
@@ -5801,7 +5862,7 @@ function enclosedHole(frame, w, h) {
5801
5862
  const stack = new Int32Array(n);
5802
5863
  let depth = 0;
5803
5864
  const seed = (p) => {
5804
- if (!outside[p] && alpha(p) < import_editor9.ALPHA_OPAQUE) {
5865
+ if (!outside[p] && alpha(p) < import_editor10.ALPHA_OPAQUE) {
5805
5866
  outside[p] = 1;
5806
5867
  stack[depth++] = p;
5807
5868
  }
@@ -5824,7 +5885,7 @@ function enclosedHole(frame, w, h) {
5824
5885
  }
5825
5886
  const mask = new Uint8Array(n);
5826
5887
  for (let p = 0; p < n; p++) {
5827
- if (alpha(p) < import_editor9.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
5888
+ if (alpha(p) < import_editor10.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
5828
5889
  }
5829
5890
  const { label, sizes, boxes } = components(mask, w, h);
5830
5891
  const main = largest(sizes);
@@ -5851,7 +5912,7 @@ function enclosedHole(frame, w, h) {
5851
5912
  return { label, main, box: box3 };
5852
5913
  }
5853
5914
  function measureLips(layers, w, h) {
5854
- const measurer = (0, import_editor9.createLayerSetMeasurer)({ width: w, height: h });
5915
+ const measurer = (0, import_editor10.createLayerSetMeasurer)({ width: w, height: h });
5855
5916
  return new Map(
5856
5917
  Object.entries(layers).map(([role, rgba]) => [
5857
5918
  role,
@@ -5869,8 +5930,8 @@ function assertFoldContract(layers, w, h) {
5869
5930
  }
5870
5931
  byRole.set(role, layer);
5871
5932
  }
5872
- const opening = (0, import_editor9.mouthOpening)(byRole);
5873
- const runs = (0, import_editor9.columnRuns)(byRole.get("mouth_inner"));
5933
+ const opening = (0, import_editor10.mouthOpening)(byRole);
5934
+ const runs = (0, import_editor10.columnRuns)(byRole.get("mouth_inner"));
5874
5935
  for (let col = opening.x0; col <= opening.x1; col++) {
5875
5936
  const c = opening.at(col);
5876
5937
  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;
@@ -5889,6 +5950,21 @@ async function splitLipSet(keyedPng, w, h, interior) {
5889
5950
  const alpha = (p) => frame[p * 4 + 3];
5890
5951
  const { label, main, box: hb } = enclosedHole(frame, w, h);
5891
5952
  const holeW = hb.x1 - hb.x0 + 1;
5953
+ const near = new Uint8Array(n);
5954
+ for (let y = Math.max(0, hb.y0 - SPILL_REACH); y <= Math.min(h - 1, hb.y1 + SPILL_REACH); y++) {
5955
+ for (let x = Math.max(0, hb.x0 - SPILL_REACH); x <= Math.min(w - 1, hb.x1 + SPILL_REACH); x++) {
5956
+ if (label[y * w + x] !== main) continue;
5957
+ for (let dy = -SPILL_REACH; dy <= SPILL_REACH; dy++) {
5958
+ const yy = y + dy;
5959
+ if (yy < 0 || yy >= h) continue;
5960
+ for (let dx = -SPILL_REACH; dx <= SPILL_REACH; dx++) {
5961
+ const xx = x + dx;
5962
+ if (xx >= 0 && xx < w) near[yy * w + xx] = 1;
5963
+ }
5964
+ }
5965
+ }
5966
+ }
5967
+ const paint = despill(Buffer.from(frame), near);
5892
5968
  const top = new Int32Array(w).fill(-1);
5893
5969
  const bot = new Int32Array(w).fill(-1);
5894
5970
  for (let y = 0; y < h; y++) {
@@ -5900,18 +5976,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
5900
5976
  }
5901
5977
  const centre = Math.round((hb.x0 + hb.x1) / 2);
5902
5978
  let stroke = 0;
5903
- while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor9.ALPHA_OPAQUE)
5979
+ while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor10.ALPHA_OPAQUE)
5904
5980
  stroke++;
5905
5981
  const bandCap = BAND_CAP * Math.max(1, stroke);
5906
5982
  const skinRow = new Int32Array(w).fill(-1);
5907
5983
  const inM = new Uint8Array(n);
5908
5984
  for (let x = hb.x0; x <= hb.x1; x++) {
5909
5985
  let y = bot[x];
5910
- while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor9.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
5986
+ while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor10.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
5911
5987
  y++;
5912
5988
  for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
5913
5989
  let r = y;
5914
- while (r < h && alpha(r * w + x) < import_editor9.ALPHA_OPAQUE) r++;
5990
+ while (r < h && alpha(r * w + x) < import_editor10.ALPHA_OPAQUE) r++;
5915
5991
  if (r < h) {
5916
5992
  skinRow[x] = r;
5917
5993
  inM[r * w + x] = 1;
@@ -5921,7 +5997,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5921
5997
  for (let y = 0; y < h; y++) {
5922
5998
  for (let x = 0; x < w; x++) {
5923
5999
  const p = y * w + x;
5924
- if (inM[p] || alpha(p) < import_editor9.ALPHA_OPAQUE) continue;
6000
+ if (inM[p] || alpha(p) < import_editor10.ALPHA_OPAQUE) continue;
5925
6001
  if (top[x] >= 0 && y < top[x]) continue;
5926
6002
  if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
5927
6003
  }
@@ -5931,7 +6007,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5931
6007
  if (x < 0 || x >= w) continue;
5932
6008
  let first = 0;
5933
6009
  while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
5934
- if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor9.ALPHA_OPAQUE)
6010
+ if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor10.ALPHA_OPAQUE)
5935
6011
  wall[x] = 1;
5936
6012
  }
5937
6013
  const gx = hb.x0 - 1;
@@ -5948,7 +6024,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5948
6024
  const inner = Buffer.alloc(n * 4);
5949
6025
  const tongue = Buffer.alloc(n * 4);
5950
6026
  const teeth = Buffer.alloc(n * 4);
5951
- const copy = (to, p) => frame.copy(to, p * 4, p * 4, p * 4 + 4);
6027
+ const copy = (to, p) => paint.copy(to, p * 4, p * 4, p * 4 + 4);
5952
6028
  for (let y = 0; y < h; y++) {
5953
6029
  for (let x = 0; x < w; x++) {
5954
6030
  const p = y * w + x;
@@ -5958,7 +6034,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5958
6034
  if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
5959
6035
  if (!grown[p]) {
5960
6036
  const a = alpha(p);
5961
- if (a >= import_editor9.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
6037
+ if (a >= import_editor10.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
5962
6038
  inner.set(interior.cavity, p * 4);
5963
6039
  inner[p * 4 + 3] = 255 - a;
5964
6040
  }
@@ -5974,7 +6050,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5974
6050
  }
5975
6051
  if ((inM[p] || wall[x]) && !faintUpper(p, x, y)) {
5976
6052
  const a = alpha(p) / 255;
5977
- for (let c = 0; c < 3; c++) out[c] += (frame[p * 4 + c] - out[c]) * a;
6053
+ for (let c = 0; c < 3; c++) out[c] += (paint[p * 4 + c] - out[c]) * a;
5978
6054
  }
5979
6055
  inner[p * 4] = Math.round(out[0]);
5980
6056
  inner[p * 4 + 1] = Math.round(out[1]);
@@ -6023,7 +6099,7 @@ async function restShiftOf(layers, width, height) {
6023
6099
  }
6024
6100
  byRole.set(role, layer);
6025
6101
  }
6026
- return (0, import_editor9.mouthRestShift)(byRole);
6102
+ return (0, import_editor10.mouthRestShift)(byRole);
6027
6103
  }
6028
6104
  async function closedLips(upper, lower, shift, left, top) {
6029
6105
  const shut = async (png, role) => {
@@ -6073,16 +6149,18 @@ async function closedLips(upper, lower, shift, left, top) {
6073
6149
  }
6074
6150
 
6075
6151
  // src/measure-lips.ts
6076
- var isLipLayerRole = (role) => import_editor10.LIP_ROLES.includes(role) || (0, import_editor10.isLipInsideRole)(role);
6152
+ var isLipLayerRole = (role) => import_editor11.LIP_ROLES.includes(role) || (0, import_editor11.isLipInsideRole)(role);
6077
6153
  var MIN_OPENING_ROWS = 8;
6078
6154
  var MIN_LINE_ROWS = 2;
6079
- var GREEN_EXCESS = 40;
6155
+ var GREEN_EXCESS = 16;
6156
+ var KEY_GREEN_EXCESS = 40;
6157
+ var EDGE_REACH = 3;
6080
6158
  var INTERIOR_GAP_FRACTION = 0.05;
6081
6159
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
6082
6160
  async function lipWarnings(absDir, layers, inPlace = false) {
6083
6161
  const warnings = [];
6084
- const present = import_editor10.LIP_ROLES.filter((role) => layers[role] !== void 0);
6085
- const inside = import_editor10.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
6162
+ const present = import_editor11.LIP_ROLES.filter((role) => layers[role] !== void 0);
6163
+ const inside = import_editor11.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
6086
6164
  if (present.length === 0) {
6087
6165
  if (inside.length > 0) {
6088
6166
  warnings.push(
@@ -6099,8 +6177,8 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6099
6177
  `${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.`
6100
6178
  );
6101
6179
  }
6102
- if (present.length < import_editor10.LIP_ROLES.length) {
6103
- const missing = import_editor10.LIP_ROLES.filter((role) => layers[role] === void 0);
6180
+ if (present.length < import_editor11.LIP_ROLES.length) {
6181
+ const missing = import_editor11.LIP_ROLES.filter((role) => layers[role] === void 0);
6104
6182
  warnings.push(
6105
6183
  `${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.`
6106
6184
  );
@@ -6131,34 +6209,66 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6131
6209
  );
6132
6210
  }
6133
6211
  }
6134
- const measurer = (0, import_editor10.createLayerSetMeasurer)({
6212
+ const measurer = (0, import_editor11.createLayerSetMeasurer)({
6135
6213
  width: inner.canvasW,
6136
6214
  height: inner.canvasH
6137
6215
  });
6138
6216
  const set = /* @__PURE__ */ new Map();
6139
6217
  const green = [];
6140
- for (const role of import_editor10.LIP_ROLES) {
6218
+ const pixels = /* @__PURE__ */ new Map();
6219
+ for (const role of import_editor11.LIP_ROLES) {
6141
6220
  const fileName = `${role}.png`;
6142
6221
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
6143
6222
  set.set(role, measurer.add({ role, fileName, rgba }));
6223
+ pixels.set(role, rgba);
6144
6224
  for (let i = 0; i < rgba.length; i += 4) {
6145
- if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
6225
+ if (rgba[i + 3] >= import_editor11.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > KEY_GREEN_EXCESS) {
6146
6226
  green.push(role);
6147
6227
  break;
6148
6228
  }
6149
6229
  }
6150
6230
  }
6231
+ {
6232
+ const W = inner.canvasW;
6233
+ const H = inner.canvasH;
6234
+ const cavity2 = pixels.get("mouth_inner");
6235
+ const edge = new Uint8Array(W * H);
6236
+ for (let p = 0; p < W * H; p++) {
6237
+ if (cavity2[p * 4 + 3] < 128) continue;
6238
+ const x = p % W;
6239
+ const y = (p - x) / W;
6240
+ for (let dy = -EDGE_REACH; dy <= EDGE_REACH; dy++) {
6241
+ const yy = y + dy;
6242
+ if (yy < 0 || yy >= H) continue;
6243
+ for (let dx = -EDGE_REACH; dx <= EDGE_REACH; dx++) {
6244
+ const xx = x + dx;
6245
+ if (xx >= 0 && xx < W) edge[yy * W + xx] = 1;
6246
+ }
6247
+ }
6248
+ }
6249
+ for (const role of ["lip_upper", "lip_lower"]) {
6250
+ if (green.includes(role)) continue;
6251
+ const rgba = pixels.get(role);
6252
+ for (let p = 0; p < W * H; p++) {
6253
+ const i = p * 4;
6254
+ if (edge[p] && (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) * rgba[i + 3] / 255 > GREEN_EXCESS) {
6255
+ green.push(role);
6256
+ break;
6257
+ }
6258
+ }
6259
+ }
6260
+ }
6151
6261
  let opening;
6152
6262
  try {
6153
- opening = (0, import_editor10.mouthOpening)(set);
6263
+ opening = (0, import_editor11.mouthOpening)(set);
6154
6264
  } catch (err) {
6155
- if (err instanceof import_editor10.LayerGeometryError) {
6265
+ if (err instanceof import_editor11.LayerGeometryError) {
6156
6266
  warnings.push(err.message);
6157
6267
  return { warnings };
6158
6268
  }
6159
6269
  throw err;
6160
6270
  }
6161
- const innerRuns = (0, import_editor10.columnRuns)(set.get("mouth_inner"));
6271
+ const innerRuns = (0, import_editor11.columnRuns)(set.get("mouth_inner"));
6162
6272
  const noInterior = [];
6163
6273
  const gap = [];
6164
6274
  const noLine = [];
@@ -6225,7 +6335,11 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6225
6335
  }
6226
6336
  if (!inPlace && green.length > 0) {
6227
6337
  warnings.push(
6228
- `${green.join("/")}: opaque green left (key green, g exceeds r and b by over ${GREEN_EXCESS}) \u2014 it shows as a green fringe on the lips. Regenerate mouth_keyed.png with the green only inside the opening, or mouth_interior.png without green in it. Billed.`
6338
+ `${green.join("/")}: green left (key green: g over r and b by more than ${KEY_GREEN_EXCESS} in an opaque pixel, or by more than ${GREEN_EXCESS} at the pixel's alpha on the opening's edge) \u2014 it shows as a green fringe on the lips. ${recompose(
6339
+ "mouth_keyed.png",
6340
+ // mouth_inner's fill is the interior's own paint, which the composer keeps as drawn.
6341
+ green.includes("mouth_inner") ? "with the green only inside the opening, or mouth_interior.png without green in it" : "with the green only inside the opening"
6342
+ )}`
6229
6343
  );
6230
6344
  }
6231
6345
  if (!inPlace && area > 0 && hollow > INTERIOR_GAP_FRACTION * area) {
@@ -6244,8 +6358,8 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6244
6358
 
6245
6359
  // src/measure-turn.ts
6246
6360
  var import_node_path8 = __toESM(require("path"));
6247
- var import_editor11 = require("@ikijs/editor");
6248
6361
  var import_editor12 = require("@ikijs/editor");
6362
+ var import_editor13 = require("@ikijs/editor");
6249
6363
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
6250
6364
  var IRIS_V_MIN = 0.18;
6251
6365
  var IRIS_V_MAX = 0.95;
@@ -6395,7 +6509,7 @@ async function measureTurnImage(filePath, iris) {
6395
6509
  let transparent = false;
6396
6510
  if (hasAlpha) {
6397
6511
  for (let i = 0; i < n; i++) {
6398
- if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) {
6512
+ if (rgba[i * 4 + 3] < import_editor12.ALPHA_OPAQUE) {
6399
6513
  transparent = true;
6400
6514
  break;
6401
6515
  }
@@ -6406,7 +6520,7 @@ async function measureTurnImage(filePath, iris) {
6406
6520
  const fg = new Uint8Array(n);
6407
6521
  const value = new Float32Array(n);
6408
6522
  for (let i = 0; i < n; i++) {
6409
- if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) continue;
6523
+ if (rgba[i * 4 + 3] < import_editor12.ALPHA_OPAQUE) continue;
6410
6524
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
6411
6525
  if (maskMode === "alpha") {
6412
6526
  fg[i] = 1;
@@ -6472,12 +6586,12 @@ async function measureTurnImage(filePath, iris) {
6472
6586
  }
6473
6587
  const [irisL, irisR] = best.pair;
6474
6588
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
6475
- const { left, right } = (0, import_editor11.foregroundSpan)(
6589
+ const { left, right } = (0, import_editor12.foregroundSpan)(
6476
6590
  fg,
6477
6591
  width,
6478
6592
  height,
6479
- eyeRow - import_editor11.HEAD_BAND,
6480
- eyeRow + import_editor11.HEAD_BAND
6593
+ eyeRow - import_editor12.HEAD_BAND,
6594
+ eyeRow + import_editor12.HEAD_BAND
6481
6595
  );
6482
6596
  if (right <= left) {
6483
6597
  throw new AutoRigInputError(
@@ -6501,7 +6615,7 @@ async function measureTurnImage(filePath, iris) {
6501
6615
  left,
6502
6616
  right,
6503
6617
  cx: (left + right) / 2,
6504
- half: (0, import_editor11.headHalfOf)({ left, right })
6618
+ half: (0, import_editor12.headHalfOf)({ left, right })
6505
6619
  },
6506
6620
  pairCx: (irisL.cx + irisR.cx) / 2,
6507
6621
  eyeGap: irisR.cx - irisL.cx
@@ -6692,7 +6806,7 @@ function noseSpeckWarning({ core, part }, source) {
6692
6806
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
6693
6807
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
6694
6808
  ];
6695
- return `nose: ${found} \u2014 under ${import_editor12.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.`;
6809
+ return `nose: ${found} \u2014 under ${import_editor13.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.`;
6696
6810
  }
6697
6811
  async function lashOffSclera(eyePath, lashPath) {
6698
6812
  const eye2 = await decodePng(eyePath);
@@ -6830,10 +6944,10 @@ async function measureDir(absDir, noseSpeck, { inPlace = false } = {}) {
6830
6944
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
6831
6945
  } else if (!inPlace && layers.nose !== void 0) {
6832
6946
  const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
6833
- const core = (0, import_editor12.denseCoreOf)(nose.rgba, nose.width, nose.height);
6947
+ const core = (0, import_editor13.denseCoreOf)(nose.rgba, nose.width, nose.height);
6834
6948
  if (core !== null) {
6835
6949
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
6836
- if ((0, import_editor12.isSpeckCore)(core, crop))
6950
+ if ((0, import_editor13.isSpeckCore)(core, crop))
6837
6951
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
6838
6952
  }
6839
6953
  }
@@ -6903,12 +7017,12 @@ function formatMeasureReport(result) {
6903
7017
 
6904
7018
  // src/compose-arms.ts
6905
7019
  var import_sharp3 = __toESM(require("sharp"));
6906
- var import_editor13 = require("@ikijs/editor");
7020
+ var import_editor14 = require("@ikijs/editor");
6907
7021
  var ARM_WIDTH = 0.4;
6908
7022
  var SHOULDER_DROP = 0.12;
6909
7023
  async function armPlacement(role, cfg, part, body) {
6910
7024
  const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
6911
- const layer = (0, import_editor13.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
7025
+ const layer = (0, import_editor14.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
6912
7026
  role,
6913
7027
  fileName: "arm.png",
6914
7028
  rgba: data
@@ -6920,9 +7034,9 @@ async function armPlacement(role, cfg, part, body) {
6920
7034
  }
6921
7035
  let g;
6922
7036
  try {
6923
- g = (0, import_editor13.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
7037
+ g = (0, import_editor14.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
6924
7038
  } catch (err) {
6925
- if (err instanceof import_editor13.LayerGeometryError) {
7039
+ if (err instanceof import_editor14.LayerGeometryError) {
6926
7040
  throw new AutoRigInputError(`layout.${role}: ${err.message}`);
6927
7041
  }
6928
7042
  throw err;
@@ -6949,7 +7063,7 @@ async function armPlacement(role, cfg, part, body) {
6949
7063
  }
6950
7064
  async function poseGeometryOf(role, png, size, when) {
6951
7065
  const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
6952
- const layer = (0, import_editor13.createLayerSetMeasurer)({
7066
+ const layer = (0, import_editor14.createLayerSetMeasurer)({
6953
7067
  width: size.w,
6954
7068
  height: size.h
6955
7069
  }).add({ role, fileName: "forearm_pose.png", rgba: data });
@@ -6958,7 +7072,7 @@ async function poseGeometryOf(role, png, size, when) {
6958
7072
  `layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
6959
7073
  );
6960
7074
  }
6961
- return (0, import_editor13.forearmPoseGeometry)(layer);
7075
+ return (0, import_editor14.forearmPoseGeometry)(layer);
6962
7076
  }
6963
7077
  async function forearmPoseWidth(role, trimmed, elbowRun) {
6964
7078
  const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
@@ -7256,18 +7370,18 @@ function keyWhiteToAlpha(rgba) {
7256
7370
  async function coreAndBoundsOf(png) {
7257
7371
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
7258
7372
  return {
7259
- core: (0, import_editor12.denseCoreOf)(data, info.width, info.height),
7373
+ core: (0, import_editor13.denseCoreOf)(data, info.width, info.height),
7260
7374
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
7261
7375
  };
7262
7376
  }
7263
7377
  async function hasCoverage(png) {
7264
7378
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
7265
- return (0, import_editor14.detectAlphaBbox)(data, info.width, info.height) !== null;
7379
+ return (0, import_editor15.detectAlphaBbox)(data, info.width, info.height) !== null;
7266
7380
  }
7267
7381
  async function noseSizingOf(png) {
7268
7382
  const { core, bounds: bounds2 } = await coreAndBoundsOf(png);
7269
7383
  if (core === null) return { box: bounds2, whole: true };
7270
- if ((0, import_editor12.isSpeckCore)(core, bounds2)) {
7384
+ if ((0, import_editor13.isSpeckCore)(core, bounds2)) {
7271
7385
  return {
7272
7386
  box: bounds2,
7273
7387
  whole: true,
@@ -7389,7 +7503,7 @@ function detachedAboveWhite(rgba, W, H) {
7389
7503
  for (let p = 0; p < n; p++) {
7390
7504
  const alpha = rgba[p * 4 + 3];
7391
7505
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
7392
- ink[p] = alpha >= import_editor14.ALPHA_OPAQUE ? 2 : 1;
7506
+ ink[p] = alpha >= import_editor15.ALPHA_OPAQUE ? 2 : 1;
7393
7507
  }
7394
7508
  const label = new Int32Array(n).fill(-1);
7395
7509
  const stack = new Int32Array(n);
@@ -7494,7 +7608,7 @@ async function prepEyeSplit(partsDir) {
7494
7608
  const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
7495
7609
  const detached = detachedAboveWhite(data, W, H);
7496
7610
  const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
7497
- const isLight = (i) => data[i + 3] >= import_editor14.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
7611
+ const isLight = (i) => data[i + 3] >= import_editor15.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
7498
7612
  const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
7499
7613
  const whiteTop = new Int32Array(W).fill(-1);
7500
7614
  for (let x = 0; x < W; x++) {
@@ -7675,7 +7789,7 @@ async function composeLayersFromParts(input) {
7675
7789
  lip_lower: split2.lower,
7676
7790
  lip_upper: split2.upper
7677
7791
  }[role];
7678
- if ((0, import_editor14.isLipInsideRole)(role) && !await hasCoverage(buf)) {
7792
+ if ((0, import_editor15.isLipInsideRole)(role) && !await hasCoverage(buf)) {
7679
7793
  skipped.push(role);
7680
7794
  continue;
7681
7795
  }
@@ -7870,7 +7984,7 @@ async function composeLayersFromParts(input) {
7870
7984
  });
7871
7985
  }
7872
7986
  const restInput = (role, buf) => {
7873
- if (role === "mouth_inner" || (0, import_editor14.isLipInsideRole)(role)) return null;
7987
+ if (role === "mouth_inner" || (0, import_editor15.isLipInsideRole)(role)) return null;
7874
7988
  if (closed === void 0) return buf;
7875
7989
  if (role === "lip_upper") return closed.upper;
7876
7990
  if (role === "lip_lower") return closed.lower;
@@ -11062,7 +11176,7 @@ function cutFeatures(ctx, lipSet = false) {
11062
11176
  }
11063
11177
 
11064
11178
  // src/illustration-landmarks.ts
11065
- var import_editor15 = require("@ikijs/editor");
11179
+ var import_editor16 = require("@ikijs/editor");
11066
11180
  var DEFAULT_BROW_HALF_WIDTH = 8;
11067
11181
  var DEFAULT_BROW_TAIL_HALF_WIDTH = 5;
11068
11182
  var KEYS = {
@@ -11216,11 +11330,11 @@ function brow(path12, v, canvas) {
11216
11330
  tailHalfWidth: o.tailHalfWidth === void 0 ? DEFAULT_BROW_TAIL_HALF_WIDTH : positive(`${path12}.tailHalfWidth`, o.tailHalfWidth)
11217
11331
  };
11218
11332
  }
11219
- var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor15.partIdsOfRole)(r)));
11333
+ var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor16.partIdsOfRole)(r)));
11220
11334
  function isReservedId(id) {
11221
11335
  if (YIELDED_PART_IDS.has(id)) return true;
11222
11336
  try {
11223
- (0, import_editor15.partIdsOfRole)(id);
11337
+ (0, import_editor16.partIdsOfRole)(id);
11224
11338
  return true;
11225
11339
  } catch {
11226
11340
  return false;
@@ -12574,6 +12688,7 @@ function formatCutReport(r) {
12574
12688
  // src/server.ts
12575
12689
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
12576
12690
  var import_zod = require("zod");
12691
+ var import_format13 = require("@ikijs/format");
12577
12692
  function formatPatchReports(reports) {
12578
12693
  return reports.map((r) => {
12579
12694
  const at = Object.keys(r.at).sort().map((p) => `${p}=${r.at[p]}`).join(" ");
@@ -12595,7 +12710,7 @@ function formatBakeChecks(bakes) {
12595
12710
  );
12596
12711
  }
12597
12712
  function createIkiMcpServer() {
12598
- const server = new import_mcp.McpServer({ name: "iki", version: "0.38.2" });
12713
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.39.1" });
12599
12714
  server.registerTool(
12600
12715
  "validate_iki",
12601
12716
  {
@@ -12622,7 +12737,7 @@ function createIkiMcpServer() {
12622
12737
  server.registerTool(
12623
12738
  "describe_iki",
12624
12739
  {
12625
- description: "Summarizes a valid model's canvas/params/parts/deformers and its expressions and motion clips (with the descriptions a host picks them by); returns an error for an invalid model. It is also the patch writer's view of a rigged model: each part's rest box in model px and in bust-render px, each part's warp stops, each warp2d's stops, and faceWidth, which is what an auto_rig_from_layers `patches` op is aimed with. Pass exactly one of model or modelPath; prefer modelPath for a written rig so a large model never crosses your context.",
12740
+ description: "Summarizes a valid model's canvas/params/parts/deformers and its expressions and motion clips (with the descriptions a host picks them by), and its `generator` (what wrote it: tool, rigger and plugin, each name@version) when it records one; returns an error for an invalid model. It is also the patch writer's view of a rigged model: each part's rest box in model px and in bust-render px, each part's warp stops, each warp2d's stops, and faceWidth, which is what an auto_rig_from_layers `patches` op is aimed with. Pass exactly one of model or modelPath; prefer modelPath for a written rig so a large model never crosses your context.",
12626
12741
  inputSchema: {
12627
12742
  model: import_zod.z.unknown().optional().describe("Raw .iki model JSON (object or JSON string)"),
12628
12743
  modelPath: import_zod.z.string().optional().describe(
@@ -12687,7 +12802,7 @@ function createIkiMcpServer() {
12687
12802
  server.registerTool(
12688
12803
  "auto_rig_from_layers",
12689
12804
  {
12690
- 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. `customParts` adds parts the rig has no role for (a twin tail, a hairpin), each from a canvas-sized PNG of its own, as an unrigged mesh on `headDeformer` after its `after` role's parts; it needs @ikijs/mcp 0.34.0, and an older server drops the field and returns no `customParts`. A part can declare `occlusion` (hidden where named roles' paint covers it, by an amount keyed on a parameter; it needs 0.35.0, and an older server refuses the key as `INVALID: customParts[i]\u2026`); its `CUSTOM <id>:` line then ends `, hidden by <id>,<id>\u2026 on <parameter> at <value>:<amount> <value>:<amount>\u2026`, and the result's part carries `occlusion` (`by` as the part ids written, `parameter`, `stops`). The result's `customParts` (`parts`: `id`, rest `box`, `mesh`, `order`, atlas `page`) is present whenever the input was passed, `[]` included, and one `CUSTOM <id>: \u2026` line per part follows the `HAIRSIDE` lines. `bakes` (see its field) moves the custom parts with a parameter and needs `customParts`; each part and parameter it moves then prints one `BAKE <part> <param>: <n> vertices, stops <values>, error <px> px` line after the `CUSTOM` lines (the result's `customParts.bakes`: `part`, `param`, `vertices`, `stops`, `errorPx`), the written model having been landed through the engine, and a stop off by 0.1 px or more comes back as `INVALID: BAKE ERROR <part> <param>=<value>: \u2026`, and a part the bake moves at rest as `INVALID: BAKE ERROR <part> at rest: \u2026`, with nothing written (the rig and the engine disagree: report it as a bug in the packages). Whenever `customParts` was passed, the written model is also measured per custom part (the result's `customParts.gate`: `ok`, `limits`, `parts`, `failed`) and the text ends with its lines, `CUSTOM <id> FOLDS|TIE|SLIDE|EXPOSED|RIGID|TIP: \u2026` then `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, \u2026>`, always the last line: a part's least triangle area ratio, its tie's displacement against the anchor where the head does not turn and where it does, the hidden art showing, how far a rigid part bends and where its free end lands, each in px and face widths with its worst pose; `TIP` never fails the gate and the other lines do. The model is written either way; from 0.34.0 on `customParts` always carries `gate` (a gate that throws still writes the file and ends the text `CUSTOM GATE FAIL: gate error: <message>`), so a result without `customParts` is from an older server and was never gated. The custom layers are not role layers: they are left out of the head's width and turn measurements, and an empty or wrong-size one, or an entry the rig refuses, comes back as `INVALID: customParts[i]\u2026` with nothing written. A missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error.",
12805
+ 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. `customParts` adds parts the rig has no role for (a twin tail, a hairpin), each from a canvas-sized PNG of its own, as an unrigged mesh on `headDeformer` after its `after` role's parts; it needs @ikijs/mcp 0.34.0, and an older server drops the field and returns no `customParts`. A part can declare `occlusion` (hidden where named roles' paint covers it, by an amount keyed on a parameter; it needs 0.35.0, and an older server refuses the key as `INVALID: customParts[i]\u2026`); its `CUSTOM <id>:` line then ends `, hidden by <id>,<id>\u2026 on <parameter> at <value>:<amount> <value>:<amount>\u2026`, and the result's part carries `occlusion` (`by` as the part ids written, `parameter`, `stops`). The result's `customParts` (`parts`: `id`, rest `box`, `mesh`, `order`, atlas `page`) is present whenever the input was passed, `[]` included, and one `CUSTOM <id>: \u2026` line per part follows the `HAIRSIDE` lines. `bakes` (see its field) moves the custom parts with a parameter and needs `customParts`; each part and parameter it moves then prints one `BAKE <part> <param>: <n> vertices, stops <values>, error <px> px` line after the `CUSTOM` lines (the result's `customParts.bakes`: `part`, `param`, `vertices`, `stops`, `errorPx`), the written model having been landed through the engine, and a stop off by 0.1 px or more comes back as `INVALID: BAKE ERROR <part> <param>=<value>: \u2026`, and a part the bake moves at rest as `INVALID: BAKE ERROR <part> at rest: \u2026`, with nothing written (the rig and the engine disagree: report it as a bug in the packages). Whenever `customParts` was passed, the written model is also measured per custom part (the result's `customParts.gate`: `ok`, `limits`, `parts`, `failed`) and the text ends with its lines, `CUSTOM <id> FOLDS|TIE|SLIDE|EXPOSED|RIGID|TIP: \u2026` then `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, \u2026>`, always the last line: a part's least triangle area ratio, its tie's displacement against the anchor where the head does not turn and where it does, the hidden art showing, how far a rigid part bends and where its free end lands, each in px and face widths with its worst pose; `TIP` never fails the gate and the other lines do. The model is written either way; from 0.34.0 on `customParts` always carries `gate` (a gate that throws still writes the file and ends the text `CUSTOM GATE FAIL: gate error: <message>`), so a result without `customParts` is from an older server and was never gated. The custom layers are not role layers: they are left out of the head's width and turn measurements, and an empty or wrong-size one, or an entry the rig refuses, comes back as `INVALID: customParts[i]\u2026` with nothing written. A missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error. The written model records what made it as `generator`: this server and the auto-rigger, each name@version, and the plugin named in the server's IKI_PLUGIN environment variable, if any; it is no input.",
12691
12806
  inputSchema: {
12692
12807
  layers: import_zod.z.array(
12693
12808
  import_zod.z.object({
@@ -12831,8 +12946,19 @@ function createIkiMcpServer() {
12831
12946
  },
12832
12947
  async (args) => {
12833
12948
  try {
12949
+ let generator;
12950
+ try {
12951
+ generator = toolGenerator();
12952
+ } catch (e) {
12953
+ if (!(e instanceof import_format13.IkiFormatError)) throw e;
12954
+ return {
12955
+ content: [{ type: "text", text: `INVALID: ${e.message}` }],
12956
+ structuredContent: { ok: false, error: e.message }
12957
+ };
12958
+ }
12834
12959
  const r = await autoRigFromLayers({
12835
12960
  ...args,
12961
+ generator,
12836
12962
  // `.length(2)` makes each region span a pair, which its inferred
12837
12963
  // `number[]` cannot say.
12838
12964
  patches: args.patches,
@@ -12866,7 +12992,7 @@ function createIkiMcpServer() {
12866
12992
  server.registerTool(
12867
12993
  "compose_layers_from_parts",
12868
12994
  {
12869
- 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`.",
12995
+ 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 (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when its pivot row is much narrower than the body below it), 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`.",
12870
12996
  inputSchema: {
12871
12997
  partsDir: import_zod.z.string().describe(
12872
12998
  "Directory of the source part PNGs (resolved against cwd)."
@@ -12914,7 +13040,7 @@ function createIkiMcpServer() {
12914
13040
  server.registerTool(
12915
13041
  "measure_layers",
12916
13042
  {
12917
- 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.",
13043
+ 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 (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when that row is much narrower than the body below it), 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.",
12918
13044
  inputSchema: {
12919
13045
  layersDir: import_zod.z.string().describe(
12920
13046
  "Directory of role-named layer PNGs (resolved against cwd)."
@@ -13247,6 +13373,7 @@ crop ${r.crop.x},${r.crop.y} ${r.crop.w}x${r.crop.h} on the ${r.canvas.width}x${
13247
13373
  // Annotate the CommonJS export names for ESM import in node:
13248
13374
  0 && (module.exports = {
13249
13375
  CUSTOM_GATE_LIMITS,
13376
+ PLUGIN_ENV,
13250
13377
  SWEEP_PRESETS,
13251
13378
  autoRigFromLayers,
13252
13379
  checkCustomGate,
@@ -13275,6 +13402,7 @@ crop ${r.crop.x},${r.crop.y} ${r.crop.w}x${r.crop.h} on the ${r.canvas.width}x${
13275
13402
  measureTurnReference,
13276
13403
  probeRig,
13277
13404
  renderPoses,
13405
+ toolGenerator,
13278
13406
  validateIki,
13279
13407
  viewIllustrationGrid
13280
13408
  });