@ikijs/mcp 0.11.0 → 0.11.2

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
@@ -272,6 +272,10 @@ function denseCoreOf(rgba, width, height) {
272
272
  if (maxX < 0) return null;
273
273
  return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
274
274
  }
275
+ var SPECK_CORE_FRACTION = 0.25;
276
+ function isSpeckCore(core, part) {
277
+ return core.w < SPECK_CORE_FRACTION * part.w || core.h < SPECK_CORE_FRACTION * part.h;
278
+ }
275
279
  function rgbToHsv(r, g, b) {
276
280
  r /= 255;
277
281
  g /= 255;
@@ -919,7 +923,7 @@ async function autoRigFromLayers(input) {
919
923
  layer.rowHalfWidths = rowHalfWidths;
920
924
  } else if (role === "nose") {
921
925
  const core = denseCoreOf(png.rgba, canvasW, canvasH);
922
- if (core !== null) layer.denseCore = core;
926
+ if (core !== null && !isSpeckCore(core, bbox)) layer.denseCore = core;
923
927
  }
924
928
  layerInputs.push(layer);
925
929
  crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
@@ -1191,6 +1195,16 @@ async function layerStats(filePath) {
1191
1195
  };
1192
1196
  }
1193
1197
  var pct = (v) => `${(v * 100).toFixed(0)}%`;
1198
+ function noseSpeckWarning({ core, part }, source) {
1199
+ const [found, consequence] = source === "compose" ? [
1200
+ `the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
1201
+ `compose_layers_from_parts sized and placed the whole part instead \u2014 layout.nose's w and h now size it, feather included`
1202
+ ] : [
1203
+ `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
1204
+ `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
1205
+ ];
1206
+ return `nose: ${found} \u2014 under ${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.`;
1207
+ }
1194
1208
  async function lashOffSclera(eyePath, lashPath) {
1195
1209
  const eye = await decodePng(eyePath);
1196
1210
  const lash = await decodePng(lashPath);
@@ -1206,7 +1220,7 @@ async function lashOffSclera(eyePath, lashPath) {
1206
1220
  }
1207
1221
  return { opaque, off };
1208
1222
  }
1209
- async function measureDir(absDir) {
1223
+ async function measureDir(absDir, noseSpeck) {
1210
1224
  const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
1211
1225
  if (files.length === 0) {
1212
1226
  throw new AutoRigInputError(`no role layers in ${absDir}`);
@@ -1312,6 +1326,17 @@ async function measureDir(absDir) {
1312
1326
  }
1313
1327
  }
1314
1328
  }
1329
+ if (noseSpeck !== void 0) {
1330
+ warnings.push(noseSpeckWarning(noseSpeck, "compose"));
1331
+ } else if (layers.nose !== void 0) {
1332
+ const nose = await decodePng(import_node_path4.default.join(absDir, "nose.png"));
1333
+ const core = denseCoreOf(nose.rgba, nose.width, nose.height);
1334
+ if (core !== null) {
1335
+ const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
1336
+ if (isSpeckCore(core, crop))
1337
+ warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
1338
+ }
1339
+ }
1315
1340
  for (const [role, why] of [
1316
1341
  ["body", "without it the character reads as a floating head on head-turn"],
1317
1342
  ["hair_back", "without it the silhouette is flat behind the face"],
@@ -1507,15 +1532,28 @@ function keyWhiteToAlpha(rgba) {
1507
1532
  }
1508
1533
  return keyed;
1509
1534
  }
1510
- async function coreOf(png) {
1535
+ async function coreAndBoundsOf(png) {
1511
1536
  const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1512
- return denseCoreOf(data, info.width, info.height) ?? {
1513
- x: 0,
1514
- y: 0,
1515
- w: info.width,
1516
- h: info.height
1537
+ return {
1538
+ core: denseCoreOf(data, info.width, info.height),
1539
+ bounds: { x: 0, y: 0, w: info.width, h: info.height }
1517
1540
  };
1518
1541
  }
1542
+ async function noseSizingOf(png) {
1543
+ const { core, bounds } = await coreAndBoundsOf(png);
1544
+ if (core === null) return { box: bounds, whole: true };
1545
+ if (isSpeckCore(core, bounds)) {
1546
+ return {
1547
+ box: bounds,
1548
+ whole: true,
1549
+ speck: {
1550
+ core: { w: core.w, h: core.h },
1551
+ part: { w: bounds.w, h: bounds.h }
1552
+ }
1553
+ };
1554
+ }
1555
+ return { box: core, whole: false };
1556
+ }
1519
1557
  async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1520
1558
  let img;
1521
1559
  if (inMemory !== void 0) {
@@ -1537,7 +1575,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1537
1575
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
1538
1576
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
1539
1577
  const { width: trimmedW, height: trimmedH } = trimmed.info;
1540
- const sized = role === "nose" ? await coreOf(trimmed.data) : { x: 0, y: 0, w: trimmedW, h: trimmedH };
1578
+ const nose = role === "nose" ? await noseSizingOf(trimmed.data) : void 0;
1579
+ const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
1541
1580
  const width = Math.round(trimmedW * cfg.w / sized.w);
1542
1581
  const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
1543
1582
  if (width > CANVAS || height > CANVAS) {
@@ -1550,7 +1589,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1550
1589
  return {
1551
1590
  buf: resized.data,
1552
1591
  w: resized.info.width,
1553
- h: resized.info.height
1592
+ h: resized.info.height,
1593
+ nose
1554
1594
  };
1555
1595
  }
1556
1596
  function assertOnCanvas(source, w, h, left, top) {
@@ -1566,18 +1606,18 @@ function placement(role, cfg, w, h) {
1566
1606
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
1567
1607
  return { left, top };
1568
1608
  }
1569
- function nosePlacement(layout, core, w, h) {
1609
+ function nosePlacement(layout, box, w, h) {
1570
1610
  const { cx, cy } = layout.nose;
1571
- const left = Math.round(cx - (core.x + core.w / 2));
1611
+ const left = Math.round(cx - (box.x + box.w / 2));
1572
1612
  let top;
1573
1613
  if (cy !== void 0) {
1574
- top = Math.round(cy - (core.y + core.h / 2));
1614
+ top = Math.round(cy - (box.y + box.h / 2));
1575
1615
  } else {
1576
1616
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
1577
1617
  const tipRow = Math.round(
1578
1618
  eyeRow + NOSE_TIP_AT * (layout.mouth.cy - eyeRow)
1579
1619
  );
1580
- top = tipRow - (core.y + core.h - 1);
1620
+ top = tipRow - (box.y + box.h - 1);
1581
1621
  }
1582
1622
  assertOnCanvas(
1583
1623
  cy !== void 0 ? "layout.nose.cx/cy" : "layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/mouth.cy)",
@@ -1662,6 +1702,7 @@ async function composeLayersFromParts(input) {
1662
1702
  ]);
1663
1703
  const placed = [];
1664
1704
  const skipped = [];
1705
+ let noseSpeck;
1665
1706
  for (const role of ORDER) {
1666
1707
  const cfg = layout[role];
1667
1708
  const inMemory = splitSources.get(cfg.src);
@@ -1677,7 +1718,16 @@ async function composeLayersFromParts(input) {
1677
1718
  skipped.push(role);
1678
1719
  continue;
1679
1720
  }
1680
- const { left, top } = role === "nose" ? nosePlacement(layout, await coreOf(part.buf), part.w, part.h) : placement(role, layout[role], part.w, part.h);
1721
+ let left;
1722
+ let top;
1723
+ if (role === "nose") {
1724
+ noseSpeck = part.nose?.speck;
1725
+ const { core, bounds } = await coreAndBoundsOf(part.buf);
1726
+ const box = part.nose?.whole ? bounds : core ?? bounds;
1727
+ ({ left, top } = nosePlacement(layout, box, part.w, part.h));
1728
+ } else {
1729
+ ({ left, top } = placement(role, layout[role], part.w, part.h));
1730
+ }
1681
1731
  if (role === "lash_L" || role === "lash_R") {
1682
1732
  const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
1683
1733
  const eye = placed.find((p) => p.role === eyeRole);
@@ -1724,7 +1774,7 @@ async function composeLayersFromParts(input) {
1724
1774
  layers,
1725
1775
  skipped,
1726
1776
  preview: previewPath,
1727
- measure: await measureDir(outDir)
1777
+ measure: await measureDir(outDir, noseSpeck)
1728
1778
  };
1729
1779
  } catch (err) {
1730
1780
  if (err instanceof AutoRigInputError)
@@ -1735,7 +1785,7 @@ async function composeLayersFromParts(input) {
1735
1785
 
1736
1786
  // src/server.ts
1737
1787
  function createIkiMcpServer() {
1738
- const server = new import_mcp.McpServer({ name: "iki", version: "0.11.0" });
1788
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.11.2" });
1739
1789
  server.registerTool(
1740
1790
  "validate_iki",
1741
1791
  {
@@ -1823,7 +1873,7 @@ function createIkiMcpServer() {
1823
1873
  noseShift: import_zod.z.number().optional(),
1824
1874
  mouthShift: import_zod.z.number().optional()
1825
1875
  }).optional().describe(
1826
- "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do, and so is a passed `eyeShift` past the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference."
1876
+ "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do, and so is a passed `eyeShift` past the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference \u2014 except a passed `silhouetteRatio` when no ratio in its whole accepted range renders on this layer set: that refusal reads `\u2026 is unreachable for this layer set, and so is every silhouetteRatio in [0.5, 1.5]` and names no range, so leave the field out, since a defaulted one clamps."
1827
1877
  )
1828
1878
  }
1829
1879
  },
@@ -1845,7 +1895,7 @@ function createIkiMcpServer() {
1845
1895
  server.registerTool(
1846
1896
  "compose_layers_from_parts",
1847
1897
  {
1848
- 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, nose are optional \u2014 without a nose layer the rig does not slide the features on the head turn.",
1898
+ 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, nose are optional \u2014 without a nose layer the rig does not slide the features on the head turn. 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.",
1849
1899
  inputSchema: {
1850
1900
  partsDir: import_zod.z.string().describe(
1851
1901
  "Directory of the source part PNGs (resolved against cwd)."
@@ -1862,7 +1912,7 @@ function createIkiMcpServer() {
1862
1912
  h: import_zod.z.number()
1863
1913
  }).partial()
1864
1914
  ).optional().describe(
1865
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, 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. 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."
1915
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, 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."
1866
1916
  ),
1867
1917
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
1868
1918
  "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) and brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail 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."
@@ -1890,7 +1940,7 @@ function createIkiMcpServer() {
1890
1940
  server.registerTool(
1891
1941
  "measure_layers",
1892
1942
  {
1893
- 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, missing optional roles). Use to re-check a layers dir without recomposing.",
1943
+ description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles). Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
1894
1944
  inputSchema: {
1895
1945
  layersDir: import_zod.z.string().describe(
1896
1946
  "Directory of role-named layer PNGs (resolved against cwd)."