@ikijs/mcp 0.14.0 → 0.16.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/cli.js CHANGED
@@ -1214,14 +1214,14 @@ function formatMeasureReport(result) {
1214
1214
 
1215
1215
  // src/compose.ts
1216
1216
  var CANVAS = 1100;
1217
- var EYE_W = 128;
1218
- var IRIS_W = Math.round(EYE_W * 0.5625);
1217
+ var EYE_W = 98;
1218
+ var IRIS_W = 50;
1219
1219
  var EYEWHITE_SRC = "eyewhite.png";
1220
1220
  var EYE_LASH_LUMA = 120;
1221
1221
  var LASH_KEEP_FRACTION = 0.5;
1222
1222
  var TRIM_THRESHOLD = 12;
1223
1223
  var STRAY_SPECK_FRACTION = 0.01;
1224
- var NOSE_TIP_AT = 0.86;
1224
+ var NOSE_TIP_AT = 0.66;
1225
1225
  var DEFAULT_LAYOUT = {
1226
1226
  // Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
1227
1227
  // without them still composes (head-only character).
@@ -1229,19 +1229,20 @@ var DEFAULT_LAYOUT = {
1229
1229
  // The torso, cut off by the canvas bottom, so the character is not a
1230
1230
  // floating head. It rides its own `bodyDeformer`, which only breathes.
1231
1231
  body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
1232
- face: { src: "face.png", cx: 550, cy: 475, w: 400 },
1232
+ // The face is drawn without a neck, so its box is the skull and centres
1233
+ // above the eye row (bob's skull at 437 against his eyes' 475).
1234
+ face: { src: "face.png", cx: 550, cy: 437, w: 400 },
1233
1235
  // The cheek blush, one part for both cheeks: blush_R (screen left) takes it
1234
1236
  // as drawn and blush_L mirrors it, like the eyewhite. It draws over the face
1235
- // and under the nose. Its box sits below each eye, centred just outside the
1236
- // eye's centre and above the nose tip. Tuned on the hero's face at its
1237
- // default placement, which narrows fast below the eye row: a 96-wide box at
1238
- // row 552 ran up to 24 px past the cheek's drawn outline (inside the ears),
1239
- // and this one, for a 2:1 blush, stays inside it by 1 px at its lower outer
1240
- // corner. OPTIONAL, and decoration: a parts dir without it composes, and
1241
- // nothing reports it missing.
1242
- blush_L: { src: "blush.png", cx: 662, cy: 530, w: 56, optional: true, mirror: true },
1237
+ // and under the nose. Its box sits below each eye, centred 5 px outside the
1238
+ // eye's centre and 55 px under its row, above the nose tip: on bob's face,
1239
+ // which narrows fast below the eye row, a 2:1 blush there stays on the
1240
+ // cheek through the turn, where one 26 px further out reached the ears.
1241
+ // OPTIONAL, and decoration: a parts dir without it composes, and nothing
1242
+ // reports it missing.
1243
+ blush_L: { src: "blush.png", cx: 641, cy: 530, w: 56, optional: true, mirror: true },
1243
1244
  // prettier-ignore
1244
- blush_R: { src: "blush.png", cx: 438, cy: 530, w: 56, optional: true, mirror: false },
1245
+ blush_R: { src: "blush.png", cx: 459, cy: 530, w: 56, optional: true, mirror: false },
1245
1246
  // prettier-ignore
1246
1247
  // The nose, drawn on its own (the face is drawn without one): the auto-rig
1247
1248
  // leads the head turn with it and keys the other features' slide on its
@@ -1249,8 +1250,8 @@ var DEFAULT_LAYOUT = {
1249
1250
  // width of its dense core, and it has no `cy`: its row comes from the tip
1250
1251
  // rule (NOSE_TIP_AT), between the eyes and the mouth, so it follows them
1251
1252
  // when they are retuned. OPTIONAL: a parts dir without it composes.
1252
- nose: { src: "nose.png", cx: 550, w: 40, optional: true },
1253
- mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
1253
+ nose: { src: "nose.png", cx: 550, w: 20, optional: true },
1254
+ mouth: { src: "mouth.png", cx: 550, cy: 594, w: 76 },
1254
1255
  // Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
1255
1256
  // auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
1256
1257
  // its top edge (not center) lines up with the closed mouth's top edge since
@@ -1259,34 +1260,37 @@ var DEFAULT_LAYOUT = {
1259
1260
  mouth_open: {
1260
1261
  src: "mouth_open.png",
1261
1262
  cx: 550,
1262
- cy: 621,
1263
- w: 68,
1263
+ cy: 596,
1264
+ w: 76,
1264
1265
  optional: true
1265
1266
  },
1266
1267
  // eye_* (sclera) and lash_* share the eyewhite's cropped frame via noTrim (so
1267
1268
  // they are NOT re-bboxed independently): the upper lash stays anchored ABOVE
1268
1269
  // the sclera center, so on blink it folds DOWN over the eye like the sample
1269
1270
  // model instead of the whole eye shrinking in place. Same cx/cy/w.
1270
- eye_L: { src: "eyewhite_sclera.png", cx: 657, cy: 475, w: EYE_W, mirror: true, noTrim: true },
1271
+ eye_L: { src: "eyewhite_sclera.png", cx: 636, cy: 475, w: EYE_W, mirror: true, noTrim: true },
1271
1272
  // prettier-ignore
1272
- eye_R: { src: "eyewhite_sclera.png", cx: 443, cy: 475, w: EYE_W, mirror: false, noTrim: true },
1273
+ eye_R: { src: "eyewhite_sclera.png", cx: 464, cy: 475, w: EYE_W, mirror: false, noTrim: true },
1273
1274
  // prettier-ignore
1274
- iris_L: { src: "iris.png", cx: 653, cy: 475, w: IRIS_W, mirror: false },
1275
- iris_R: { src: "iris.png", cx: 447, cy: 475, w: IRIS_W, mirror: false },
1275
+ // A little under the white's centre and toward the nose, as bob's sits.
1276
+ iris_L: { src: "iris.png", cx: 631, cy: 480, w: IRIS_W, mirror: false },
1277
+ iris_R: { src: "iris.png", cx: 469, cy: 480, w: IRIS_W, mirror: false },
1276
1278
  lash_L: {
1277
1279
  src: "eyewhite_lash.png",
1278
- cx: 657,
1280
+ cx: 636,
1279
1281
  cy: 475,
1280
1282
  w: EYE_W,
1281
1283
  mirror: true,
1282
1284
  noTrim: true
1283
1285
  },
1284
- lash_R: { src: "eyewhite_lash.png", cx: 443, cy: 475, w: EYE_W, mirror: false, noTrim: true },
1286
+ lash_R: { src: "eyewhite_lash.png", cx: 464, cy: 475, w: EYE_W, mirror: false, noTrim: true },
1285
1287
  // prettier-ignore
1286
- brow_L: { src: "brow.png", cx: 645, cy: 405, w: 135, mirror: false },
1287
- brow_R: { src: "brow.png", cx: 455, cy: 405, w: 135, mirror: true },
1288
+ brow_L: { src: "brow.png", cx: 645, cy: 405, w: 105, mirror: false },
1289
+ brow_R: { src: "brow.png", cx: 455, cy: 405, w: 105, mirror: true },
1288
1290
  hair_front: { src: "hair_front.png", cx: 550, cy: 425, w: 660 }
1289
1291
  };
1292
+ var LOWER_LASH = { lash_lower_L: "eye_L", lash_lower_R: "eye_R" };
1293
+ var LOWER_LASH_SRC = "eyewhite_lash_lower.png";
1290
1294
  var ORDER = [
1291
1295
  "hair_back",
1292
1296
  "body",
@@ -1300,6 +1304,8 @@ var ORDER = [
1300
1304
  "eye_R",
1301
1305
  "iris_L",
1302
1306
  "iris_R",
1307
+ "lash_lower_L",
1308
+ "lash_lower_R",
1303
1309
  "lash_L",
1304
1310
  "lash_R",
1305
1311
  "brow_L",
@@ -1312,9 +1318,24 @@ var PART_FILES = [
1312
1318
  ),
1313
1319
  EYEWHITE_SRC
1314
1320
  ];
1321
+ var FACE_FEATURES = [
1322
+ "blush_L",
1323
+ "blush_R",
1324
+ "mouth",
1325
+ "mouth_open",
1326
+ "eye_L",
1327
+ "eye_R",
1328
+ "iris_L",
1329
+ "iris_R",
1330
+ "lash_L",
1331
+ "lash_R",
1332
+ "brow_L",
1333
+ "brow_R"
1334
+ ];
1315
1335
  function resolveLayout(overrides) {
1316
1336
  const resolved = { ...DEFAULT_LAYOUT };
1317
1337
  if (overrides === void 0) return resolved;
1338
+ const sets = /* @__PURE__ */ new Map();
1318
1339
  for (const [role, override] of Object.entries(overrides)) {
1319
1340
  if (!Object.prototype.hasOwnProperty.call(DEFAULT_LAYOUT, role)) {
1320
1341
  throw new AutoRigInputError(
@@ -1343,9 +1364,30 @@ function resolveLayout(overrides) {
1343
1364
  }
1344
1365
  set[field] = value;
1345
1366
  }
1346
- const key = role;
1347
- if (key === "nose") resolved.nose = { ...resolved.nose, ...set };
1348
- else resolved[key] = { ...resolved[key], ...set };
1367
+ sets.set(role, set);
1368
+ }
1369
+ const face = { ...resolved.face, ...sets.get("face") };
1370
+ resolved.face = face;
1371
+ const base = DEFAULT_LAYOUT.face;
1372
+ const scale = face.w / base.w;
1373
+ const x = (cx) => face.cx + (cx - base.cx) * scale;
1374
+ const w = (width) => Math.max(1, Math.round(width * scale));
1375
+ for (const role of FACE_FEATURES) {
1376
+ const d = DEFAULT_LAYOUT[role];
1377
+ const cy = face.cy + (d.cy - base.cy) * scale;
1378
+ resolved[role] = { ...d, cx: x(d.cx), cy, w: w(d.w), ...sets.get(role) };
1379
+ }
1380
+ const nose = DEFAULT_LAYOUT.nose;
1381
+ resolved.nose = {
1382
+ ...nose,
1383
+ cx: x(nose.cx),
1384
+ w: w(nose.w),
1385
+ ...sets.get("nose")
1386
+ };
1387
+ for (const [role, set] of sets) {
1388
+ if (role === "face" || role === "nose") continue;
1389
+ if (FACE_FEATURES.includes(role)) continue;
1390
+ resolved[role] = { ...resolved[role], ...set };
1349
1391
  }
1350
1392
  return resolved;
1351
1393
  }
@@ -1377,6 +1419,10 @@ async function coreAndBoundsOf(png) {
1377
1419
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
1378
1420
  };
1379
1421
  }
1422
+ async function hasCoverage(png) {
1423
+ const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1424
+ return (0, import_editor5.detectAlphaBbox)(data, info.width, info.height) !== null;
1425
+ }
1380
1426
  async function noseSizingOf(png) {
1381
1427
  const { core, bounds } = await coreAndBoundsOf(png);
1382
1428
  if (core === null) return { box: bounds, whole: true };
@@ -1657,13 +1703,18 @@ async function prepEyeSplit(partsDir) {
1657
1703
  const detached = detachedAboveWhite(data, W, H);
1658
1704
  const sclera = Buffer.from(data);
1659
1705
  const lash = Buffer.from(data);
1706
+ const lashLower = Buffer.from(data);
1707
+ let lowerInk = false;
1660
1708
  for (let y = 0; y < H; y++) {
1661
1709
  for (let x = 0; x < W; x++) {
1662
1710
  const i = (y * W + x) * 4;
1663
1711
  const isDark = data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
1664
- if (isDark) sclera[i] = sclera[i + 1] = sclera[i + 2] = 255;
1712
+ const upper = y <= lashCutoffY;
1713
+ if (isDark && upper) sclera[i] = sclera[i + 1] = sclera[i + 2] = 255;
1665
1714
  if (detached[y * W + x]) sclera[i + 3] = 0;
1666
- if (!(isDark && y <= lashCutoffY)) lash[i + 3] = 0;
1715
+ if (!(isDark && upper)) lash[i + 3] = 0;
1716
+ if (isDark && !upper) lowerInk = true;
1717
+ else lashLower[i + 3] = 0;
1667
1718
  }
1668
1719
  }
1669
1720
  const region = {
@@ -1674,7 +1725,8 @@ async function prepEyeSplit(partsDir) {
1674
1725
  };
1675
1726
  return {
1676
1727
  sclera: await cropToBuffer(sclera, W, H, region),
1677
- lash: await cropToBuffer(lash, W, H, region)
1728
+ lash: await cropToBuffer(lash, W, H, region),
1729
+ lashLower: lowerInk ? await cropToBuffer(lashLower, W, H, region) : null
1678
1730
  };
1679
1731
  }
1680
1732
  async function composeLayersFromParts(input) {
@@ -1693,11 +1745,20 @@ async function composeLayersFromParts(input) {
1693
1745
  ["eyewhite_sclera.png", split.sclera],
1694
1746
  ["eyewhite_lash.png", split.lash]
1695
1747
  ]);
1748
+ if (split.lashLower !== null) {
1749
+ splitSources.set(LOWER_LASH_SRC, split.lashLower);
1750
+ }
1696
1751
  const placed = [];
1697
1752
  const skipped = [];
1698
1753
  let noseSpeck;
1699
1754
  for (const role of ORDER) {
1700
- const cfg = layout[role];
1755
+ const lower = role === "lash_lower_L" || role === "lash_lower_R";
1756
+ const key = lower ? LOWER_LASH[role] : role;
1757
+ if (lower && split.lashLower === null) {
1758
+ skipped.push(role);
1759
+ continue;
1760
+ }
1761
+ const cfg = lower ? { ...layout[key], src: LOWER_LASH_SRC } : layout[key];
1701
1762
  const inMemory = splitSources.get(cfg.src);
1702
1763
  const part = await partBuffer(
1703
1764
  role,
@@ -1707,19 +1768,19 @@ async function composeLayersFromParts(input) {
1707
1768
  // The split halves are cut from eyewhite.png, the file a caller names.
1708
1769
  mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
1709
1770
  );
1710
- if (part === null) {
1771
+ if (part === null || lower && !await hasCoverage(part.buf)) {
1711
1772
  skipped.push(role);
1712
1773
  continue;
1713
1774
  }
1714
1775
  let left;
1715
1776
  let top;
1716
- if (role === "nose") {
1777
+ if (key === "nose") {
1717
1778
  noseSpeck = part.nose?.speck;
1718
1779
  const { core, bounds } = await coreAndBoundsOf(part.buf);
1719
1780
  const box = part.nose?.whole ? bounds : core ?? bounds;
1720
1781
  ({ left, top } = nosePlacement(layout, box, part.w, part.h));
1721
1782
  } else {
1722
- ({ left, top } = placement(role, layout[role], part.w, part.h));
1783
+ ({ left, top } = placement(key, layout[key], part.w, part.h));
1723
1784
  }
1724
1785
  if (role === "lash_L" || role === "lash_R") {
1725
1786
  const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
@@ -1778,7 +1839,7 @@ async function composeLayersFromParts(input) {
1778
1839
 
1779
1840
  // src/server.ts
1780
1841
  function createIkiMcpServer() {
1781
- const server = new import_mcp.McpServer({ name: "iki", version: "0.14.0" });
1842
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.16.0" });
1782
1843
  server.registerTool(
1783
1844
  "validate_iki",
1784
1845
  {
@@ -1898,7 +1959,7 @@ function createIkiMcpServer() {
1898
1959
  server.registerTool(
1899
1960
  "compose_layers_from_parts",
1900
1961
  {
1901
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink.",
1962
+ description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
1902
1963
  inputSchema: {
1903
1964
  partsDir: import_zod.z.string().describe(
1904
1965
  "Directory of the source part PNGs (resolved against cwd)."
@@ -1915,7 +1976,7 @@ function createIkiMcpServer() {
1915
1976
  h: import_zod.z.number()
1916
1977
  }).partial()
1917
1978
  ).optional().describe(
1918
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, blush_L, blush_R, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected."
1979
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, blush_L, blush_R, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame."
1919
1980
  ),
1920
1981
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
1921
1982
  "Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), and blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."