@ikijs/mcp 0.11.0 → 0.11.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/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createIkiMcpServer
4
- } from "./chunk-LOOIWB2J.mjs";
4
+ } from "./chunk-4AE4D6SE.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/index.d.mts CHANGED
@@ -136,8 +136,10 @@ type AutoRigResult = {
136
136
  /** The nose's dense core, canvas px — its pixels at alpha >= 128, not
137
137
  * grown — the box handed to the generator as the nose layer's
138
138
  * `denseCore` and, there, its turn landmark. Absent without a `nose`
139
- * layer, or when the nose has no pixel at that threshold (painted
140
- * wholly translucent). */
139
+ * layer, when the nose has no pixel at that threshold (painted wholly
140
+ * translucent), or when its core is a speck of its crop
141
+ * (`isSpeckCore`: a lone nostril mark or highlight); the crop stands
142
+ * in for it in both cases. */
141
143
  noseCore?: {
142
144
  x: number;
143
145
  y: number;
@@ -172,7 +174,9 @@ type AutoRigResult = {
172
174
  * hair detail the iris may cross, and is skipped. The nose layer alone also
173
175
  * gets its dense core measured (`LayerInput.denseCore`, returned as
174
176
  * `noseCore`), so a shaded nose is fitted and tilted by the drawing inside its
175
- * feather rather than by the feather itself. Under `quantizeColors` that nose
177
+ * feather rather than by the feather itself — unless that core is a speck of
178
+ * the nose's crop (`isSpeckCore`), which is not handed over: the crop stands
179
+ * in, as it does for a nose with no core. Under `quantizeColors` that nose
176
180
  * is atlased alone on a second, lossless page, which the palette would
177
181
  * otherwise rim; `atlasBytes` sums both pages.
178
182
  *
package/dist/index.d.ts CHANGED
@@ -136,8 +136,10 @@ type AutoRigResult = {
136
136
  /** The nose's dense core, canvas px — its pixels at alpha >= 128, not
137
137
  * grown — the box handed to the generator as the nose layer's
138
138
  * `denseCore` and, there, its turn landmark. Absent without a `nose`
139
- * layer, or when the nose has no pixel at that threshold (painted
140
- * wholly translucent). */
139
+ * layer, when the nose has no pixel at that threshold (painted wholly
140
+ * translucent), or when its core is a speck of its crop
141
+ * (`isSpeckCore`: a lone nostril mark or highlight); the crop stands
142
+ * in for it in both cases. */
141
143
  noseCore?: {
142
144
  x: number;
143
145
  y: number;
@@ -172,7 +174,9 @@ type AutoRigResult = {
172
174
  * hair detail the iris may cross, and is skipped. The nose layer alone also
173
175
  * gets its dense core measured (`LayerInput.denseCore`, returned as
174
176
  * `noseCore`), so a shaded nose is fitted and tilted by the drawing inside its
175
- * feather rather than by the feather itself. Under `quantizeColors` that nose
177
+ * feather rather than by the feather itself — unless that core is a speck of
178
+ * the nose's crop (`isSpeckCore`), which is not handed over: the crop stands
179
+ * in, as it does for a nose with no core. Under `quantizeColors` that nose
176
180
  * is atlased alone on a second, lossless page, which the palette would
177
181
  * otherwise rim; `atlasBytes` sums both pages.
178
182
  *
package/dist/index.js CHANGED
@@ -288,6 +288,10 @@ function denseCoreOf(rgba, width, height) {
288
288
  if (maxX < 0) return null;
289
289
  return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
290
290
  }
291
+ var SPECK_CORE_FRACTION = 0.25;
292
+ function isSpeckCore(core, part) {
293
+ return core.w < SPECK_CORE_FRACTION * part.w || core.h < SPECK_CORE_FRACTION * part.h;
294
+ }
291
295
  function rgbToHsv(r, g, b) {
292
296
  r /= 255;
293
297
  g /= 255;
@@ -935,7 +939,7 @@ async function autoRigFromLayers(input) {
935
939
  layer.rowHalfWidths = rowHalfWidths;
936
940
  } else if (role === "nose") {
937
941
  const core = denseCoreOf(png.rgba, canvasW, canvasH);
938
- if (core !== null) layer.denseCore = core;
942
+ if (core !== null && !isSpeckCore(core, bbox)) layer.denseCore = core;
939
943
  }
940
944
  layerInputs.push(layer);
941
945
  crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
@@ -1207,6 +1211,16 @@ async function layerStats(filePath) {
1207
1211
  };
1208
1212
  }
1209
1213
  var pct = (v) => `${(v * 100).toFixed(0)}%`;
1214
+ function noseSpeckWarning({ core, part }, source) {
1215
+ const [found, consequence] = source === "compose" ? [
1216
+ `the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
1217
+ `compose_layers_from_parts sized and placed the whole part instead \u2014 layout.nose's w and h now size it, feather included`
1218
+ ] : [
1219
+ `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
1220
+ `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
1221
+ ];
1222
+ 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.`;
1223
+ }
1210
1224
  async function lashOffSclera(eyePath, lashPath) {
1211
1225
  const eye = await decodePng(eyePath);
1212
1226
  const lash = await decodePng(lashPath);
@@ -1222,7 +1236,7 @@ async function lashOffSclera(eyePath, lashPath) {
1222
1236
  }
1223
1237
  return { opaque, off };
1224
1238
  }
1225
- async function measureDir(absDir) {
1239
+ async function measureDir(absDir, noseSpeck) {
1226
1240
  const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
1227
1241
  if (files.length === 0) {
1228
1242
  throw new AutoRigInputError(`no role layers in ${absDir}`);
@@ -1328,6 +1342,17 @@ async function measureDir(absDir) {
1328
1342
  }
1329
1343
  }
1330
1344
  }
1345
+ if (noseSpeck !== void 0) {
1346
+ warnings.push(noseSpeckWarning(noseSpeck, "compose"));
1347
+ } else if (layers.nose !== void 0) {
1348
+ const nose = await decodePng(import_node_path4.default.join(absDir, "nose.png"));
1349
+ const core = denseCoreOf(nose.rgba, nose.width, nose.height);
1350
+ if (core !== null) {
1351
+ const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
1352
+ if (isSpeckCore(core, crop))
1353
+ warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
1354
+ }
1355
+ }
1331
1356
  for (const [role, why] of [
1332
1357
  ["body", "without it the character reads as a floating head on head-turn"],
1333
1358
  ["hair_back", "without it the silhouette is flat behind the face"],
@@ -1523,15 +1548,28 @@ function keyWhiteToAlpha(rgba) {
1523
1548
  }
1524
1549
  return keyed;
1525
1550
  }
1526
- async function coreOf(png) {
1551
+ async function coreAndBoundsOf(png) {
1527
1552
  const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
1528
- return denseCoreOf(data, info.width, info.height) ?? {
1529
- x: 0,
1530
- y: 0,
1531
- w: info.width,
1532
- h: info.height
1553
+ return {
1554
+ core: denseCoreOf(data, info.width, info.height),
1555
+ bounds: { x: 0, y: 0, w: info.width, h: info.height }
1533
1556
  };
1534
1557
  }
1558
+ async function noseSizingOf(png) {
1559
+ const { core, bounds } = await coreAndBoundsOf(png);
1560
+ if (core === null) return { box: bounds, whole: true };
1561
+ if (isSpeckCore(core, bounds)) {
1562
+ return {
1563
+ box: bounds,
1564
+ whole: true,
1565
+ speck: {
1566
+ core: { w: core.w, h: core.h },
1567
+ part: { w: bounds.w, h: bounds.h }
1568
+ }
1569
+ };
1570
+ }
1571
+ return { box: core, whole: false };
1572
+ }
1535
1573
  async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1536
1574
  let img;
1537
1575
  if (inMemory !== void 0) {
@@ -1553,7 +1591,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1553
1591
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
1554
1592
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
1555
1593
  const { width: trimmedW, height: trimmedH } = trimmed.info;
1556
- const sized = role === "nose" ? await coreOf(trimmed.data) : { x: 0, y: 0, w: trimmedW, h: trimmedH };
1594
+ const nose = role === "nose" ? await noseSizingOf(trimmed.data) : void 0;
1595
+ const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
1557
1596
  const width = Math.round(trimmedW * cfg.w / sized.w);
1558
1597
  const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
1559
1598
  if (width > CANVAS || height > CANVAS) {
@@ -1566,7 +1605,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1566
1605
  return {
1567
1606
  buf: resized.data,
1568
1607
  w: resized.info.width,
1569
- h: resized.info.height
1608
+ h: resized.info.height,
1609
+ nose
1570
1610
  };
1571
1611
  }
1572
1612
  function assertOnCanvas(source, w, h, left, top) {
@@ -1582,18 +1622,18 @@ function placement(role, cfg, w, h) {
1582
1622
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
1583
1623
  return { left, top };
1584
1624
  }
1585
- function nosePlacement(layout, core, w, h) {
1625
+ function nosePlacement(layout, box, w, h) {
1586
1626
  const { cx, cy } = layout.nose;
1587
- const left = Math.round(cx - (core.x + core.w / 2));
1627
+ const left = Math.round(cx - (box.x + box.w / 2));
1588
1628
  let top;
1589
1629
  if (cy !== void 0) {
1590
- top = Math.round(cy - (core.y + core.h / 2));
1630
+ top = Math.round(cy - (box.y + box.h / 2));
1591
1631
  } else {
1592
1632
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
1593
1633
  const tipRow = Math.round(
1594
1634
  eyeRow + NOSE_TIP_AT * (layout.mouth.cy - eyeRow)
1595
1635
  );
1596
- top = tipRow - (core.y + core.h - 1);
1636
+ top = tipRow - (box.y + box.h - 1);
1597
1637
  }
1598
1638
  assertOnCanvas(
1599
1639
  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)",
@@ -1678,6 +1718,7 @@ async function composeLayersFromParts(input) {
1678
1718
  ]);
1679
1719
  const placed = [];
1680
1720
  const skipped = [];
1721
+ let noseSpeck;
1681
1722
  for (const role of ORDER) {
1682
1723
  const cfg = layout[role];
1683
1724
  const inMemory = splitSources.get(cfg.src);
@@ -1693,7 +1734,16 @@ async function composeLayersFromParts(input) {
1693
1734
  skipped.push(role);
1694
1735
  continue;
1695
1736
  }
1696
- const { left, top } = role === "nose" ? nosePlacement(layout, await coreOf(part.buf), part.w, part.h) : placement(role, layout[role], part.w, part.h);
1737
+ let left;
1738
+ let top;
1739
+ if (role === "nose") {
1740
+ noseSpeck = part.nose?.speck;
1741
+ const { core, bounds } = await coreAndBoundsOf(part.buf);
1742
+ const box = part.nose?.whole ? bounds : core ?? bounds;
1743
+ ({ left, top } = nosePlacement(layout, box, part.w, part.h));
1744
+ } else {
1745
+ ({ left, top } = placement(role, layout[role], part.w, part.h));
1746
+ }
1697
1747
  if (role === "lash_L" || role === "lash_R") {
1698
1748
  const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
1699
1749
  const eye = placed.find((p) => p.role === eyeRole);
@@ -1740,7 +1790,7 @@ async function composeLayersFromParts(input) {
1740
1790
  layers,
1741
1791
  skipped,
1742
1792
  preview: previewPath,
1743
- measure: await measureDir(outDir)
1793
+ measure: await measureDir(outDir, noseSpeck)
1744
1794
  };
1745
1795
  } catch (err) {
1746
1796
  if (err instanceof AutoRigInputError)
@@ -1753,7 +1803,7 @@ async function composeLayersFromParts(input) {
1753
1803
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1754
1804
  var import_zod = require("zod");
1755
1805
  function createIkiMcpServer() {
1756
- const server = new import_mcp.McpServer({ name: "iki", version: "0.11.0" });
1806
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.11.1" });
1757
1807
  server.registerTool(
1758
1808
  "validate_iki",
1759
1809
  {
@@ -1841,7 +1891,7 @@ function createIkiMcpServer() {
1841
1891
  noseShift: import_zod.z.number().optional(),
1842
1892
  mouthShift: import_zod.z.number().optional()
1843
1893
  }).optional().describe(
1844
- "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."
1894
+ "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."
1845
1895
  )
1846
1896
  }
1847
1897
  },
@@ -1863,7 +1913,7 @@ function createIkiMcpServer() {
1863
1913
  server.registerTool(
1864
1914
  "compose_layers_from_parts",
1865
1915
  {
1866
- 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.",
1916
+ 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.",
1867
1917
  inputSchema: {
1868
1918
  partsDir: import_zod.z.string().describe(
1869
1919
  "Directory of the source part PNGs (resolved against cwd)."
@@ -1880,7 +1930,7 @@ function createIkiMcpServer() {
1880
1930
  h: import_zod.z.number()
1881
1931
  }).partial()
1882
1932
  ).optional().describe(
1883
- "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."
1933
+ "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."
1884
1934
  ),
1885
1935
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
1886
1936
  "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."
@@ -1908,7 +1958,7 @@ function createIkiMcpServer() {
1908
1958
  server.registerTool(
1909
1959
  "measure_layers",
1910
1960
  {
1911
- 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.",
1961
+ 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.",
1912
1962
  inputSchema: {
1913
1963
  layersDir: import_zod.z.string().describe(
1914
1964
  "Directory of role-named layer PNGs (resolved against cwd)."