@ikijs/mcp 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -535,6 +535,7 @@ var EYE_ASPECT_MIN = 0.5;
535
535
  var IRIS_OFFSET_MAX_X = 3;
536
536
  var IRIS_OFFSET_MAX_Y = 10;
537
537
  var EDGE_SOLID_MAX = 0.5;
538
+ var LASH_CENTRE_TOL_FRAC = 0.03;
538
539
  var EDGE_RUN_MIN_PX = 40;
539
540
  var FLAT_CUT_MAX_FRAC = 0.1;
540
541
  var FLAT_CUT_MIN_PX = 40;
@@ -639,15 +640,24 @@ async function measureDir(absDir) {
639
640
  const warnings = [];
640
641
  for (const [role, m] of Object.entries(layers)) {
641
642
  const edges = [
642
- ["top", m.edgeTop, m.w],
643
- ["left", m.edgeLeft, m.h],
644
- ["right", m.edgeRight, m.h]
643
+ ["top", m.edgeTop, m.w, m.marginTop],
644
+ ["left", m.edgeLeft, m.h, m.marginLeft],
645
+ ["right", m.edgeRight, m.h, m.marginRight]
645
646
  ];
646
- if (role !== "body") edges.push(["bottom", m.edgeBottom, m.w]);
647
- for (const [side, v, span] of edges) {
647
+ if (role !== "body")
648
+ edges.push(["bottom", m.edgeBottom, m.w, m.marginBottom]);
649
+ for (const [side, v, span, margin] of edges) {
648
650
  if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
651
+ const remedy = margin === 0 ? (
652
+ // margin 0 is consistent with a clipped placement AND with art
653
+ // already cropped flush that happens to sit on the boundary, and
654
+ // the flattened layer cannot separate them — so name the free
655
+ // move rather than the cause. If moving it inward leaves the
656
+ // edge opaque, the drawing is the one at fault.
657
+ `it sits flush against the canvas ${side}, which a clipped placement and already-cropped art both produce. Move it inward first \u2014 retune layout.${role}.cx/cy/w, free \u2014 and remeasure; regenerate only if the edge is still opaque with margin to spare.`
658
+ ) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
649
659
  warnings.push(
650
- `${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns. Regenerate with empty margin on that side.`
660
+ `${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns. Cause: ${remedy}`
651
661
  );
652
662
  }
653
663
  }
@@ -668,7 +678,7 @@ async function measureDir(absDir) {
668
678
  const aspect = eye.h / eye.w;
669
679
  if (aspect < EYE_ASPECT_MIN) {
670
680
  warnings.push(
671
- `eye_${side}: sclera aspect h/w=${aspect.toFixed(2)} is flatter than ${EYE_ASPECT_MIN} \u2014 a round iris cannot sit inside it. Regenerate the eyewhite taller, not the iris smaller.`
681
+ `eye_${side}: sclera aspect h/w=${aspect.toFixed(2)} is flatter than ${EYE_ASPECT_MIN} \u2014 a round iris cannot sit inside it. Free fix first: set layout.eye_${side}.h and layout.lash_${side}.h to ${Math.ceil(eye.w * EYE_ASPECT_MIN)} (both, or the fold tears) \u2014 stretching a flat white lens is invisible. Regenerate the eyewhite taller only if that distorts the lash.`
672
682
  );
673
683
  }
674
684
  if (iris) {
@@ -689,7 +699,7 @@ async function measureDir(absDir) {
689
699
  if (lash) {
690
700
  const dx = lash.bboxCx - eye.bboxCx;
691
701
  const dTop = lash.marginTop - eye.marginTop;
692
- if (Math.abs(dx) > 0.5 || Math.abs(dTop) > 0.5) {
702
+ if (Math.abs(dx) > eye.w * LASH_CENTRE_TOL_FRAC || Math.abs(dTop) > 0.5) {
693
703
  warnings.push(
694
704
  `lash_${side}: centre is ${dx.toFixed(1)} px and top edge ${dTop.toFixed(1)} px off eye_${side}. They are split from one source and MUST share cx/cy/w in layout, or the blink fold tears. Retune to match.`
695
705
  );
@@ -835,13 +845,15 @@ function resolveLayout(overrides) {
835
845
  }
836
846
  next[field] = value;
837
847
  }
838
- if (override.w !== void 0) {
839
- if (!Number.isInteger(override.w) || override.w < 1 || override.w > CANVAS) {
848
+ for (const field of ["w", "h"]) {
849
+ const value = override[field];
850
+ if (value === void 0) continue;
851
+ if (!Number.isInteger(value) || value < 1 || value > CANVAS) {
840
852
  throw new AutoRigInputError(
841
- `layout.${role}.w must be an integer in 1..${CANVAS}, got ${String(override.w)}`
853
+ `layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
842
854
  );
843
855
  }
844
- next.w = override.w;
856
+ next[field] = value;
845
857
  }
846
858
  resolved[role] = next;
847
859
  }
@@ -876,15 +888,19 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
876
888
  if (!cfg.noTrim) img = img.trim({ threshold: 12 });
877
889
  if (cfg.mirror) img = img.flop();
878
890
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
879
- const scaledH = Math.round(
880
- trimmed.info.height * cfg.w / trimmed.info.width
881
- );
882
- if (scaledH > CANVAS) {
883
- throw new AutoRigInputError(
884
- `layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
891
+ if (cfg.h === void 0) {
892
+ const scaledH = Math.round(
893
+ trimmed.info.height * cfg.w / trimmed.info.width
885
894
  );
895
+ if (scaledH > CANVAS) {
896
+ throw new AutoRigInputError(
897
+ `layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
898
+ );
899
+ }
886
900
  }
887
- const resized = await (0, import_sharp2.default)(trimmed.data).resize({ width: cfg.w }).png().toBuffer({ resolveWithObject: true });
901
+ const resized = await (0, import_sharp2.default)(trimmed.data).resize(
902
+ cfg.h === void 0 ? { width: cfg.w } : { width: cfg.w, height: cfg.h, fit: "fill" }
903
+ ).png().toBuffer({ resolveWithObject: true });
888
904
  return {
889
905
  buf: resized.data,
890
906
  w: resized.info.width,
@@ -1031,7 +1047,7 @@ async function composeLayersFromParts(input) {
1031
1047
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1032
1048
  var import_zod = require("zod");
1033
1049
  function createIkiMcpServer() {
1034
- const server = new import_mcp.McpServer({ name: "iki", version: "0.4.0" });
1050
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.5.0" });
1035
1051
  server.registerTool(
1036
1052
  "validate_iki",
1037
1053
  {
@@ -1142,9 +1158,14 @@ function createIkiMcpServer() {
1142
1158
  ),
1143
1159
  layout: import_zod.z.record(
1144
1160
  import_zod.z.string(),
1145
- import_zod.z.object({ cx: import_zod.z.number(), cy: import_zod.z.number(), w: import_zod.z.number() }).partial()
1161
+ import_zod.z.object({
1162
+ cx: import_zod.z.number(),
1163
+ cy: import_zod.z.number(),
1164
+ w: import_zod.z.number(),
1165
+ h: import_zod.z.number()
1166
+ }).partial()
1146
1167
  ).optional().describe(
1147
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`; `w` is 1..1100."
1168
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch (set it on a sclera and its lash together, or the blink fold tears)."
1148
1169
  )
1149
1170
  }
1150
1171
  },