@ikijs/mcp 0.9.0 → 0.10.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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createIkiMcpServer
4
- } from "./chunk-R6LYJVYC.mjs";
4
+ } from "./chunk-OCIICRUA.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/index.d.mts CHANGED
@@ -380,6 +380,13 @@ interface ComposeInput {
380
380
  */
381
381
  outDir: string;
382
382
  layout?: LayoutOverride;
383
+ /**
384
+ * Part files to flip left-right as they are read, e.g. `["eyewhite.png"]`
385
+ * for an eye drawn facing the other way. It flips the SOURCE, so every role
386
+ * cut from it flips together — the eye pair's sclera and lash stay in one
387
+ * frame, which a per-role flag would leave to the caller to keep in sync.
388
+ */
389
+ mirrorParts?: string[];
383
390
  }
384
391
  interface ComposedLayer {
385
392
  role: Role;
package/dist/index.d.ts CHANGED
@@ -380,6 +380,13 @@ interface ComposeInput {
380
380
  */
381
381
  outDir: string;
382
382
  layout?: LayoutOverride;
383
+ /**
384
+ * Part files to flip left-right as they are read, e.g. `["eyewhite.png"]`
385
+ * for an eye drawn facing the other way. It flips the SOURCE, so every role
386
+ * cut from it flips together — the eye pair's sclera and lash stay in one
387
+ * frame, which a per-role flag would leave to the caller to keep in sync.
388
+ */
389
+ mirrorParts?: string[];
383
390
  }
384
391
  interface ComposedLayer {
385
392
  role: Role;
package/dist/index.js CHANGED
@@ -1078,7 +1078,8 @@ var EYE_ASPECT_MIN = 0.5;
1078
1078
  var IRIS_OFFSET_MAX_X = 3;
1079
1079
  var IRIS_OFFSET_MAX_Y = 10;
1080
1080
  var EDGE_SOLID_MAX = 0.5;
1081
- var LASH_CENTRE_TOL_FRAC = 0.03;
1081
+ var LASH_STRAY_TOL_FRAC = 0.02;
1082
+ var EYE_FACING_TOL_FRAC = 0.02;
1082
1083
  var EDGE_RUN_MIN_PX = 40;
1083
1084
  var FLAT_CUT_MAX_FRAC = 0.1;
1084
1085
  var FLAT_CUT_MIN_PX = 40;
@@ -1159,6 +1160,21 @@ async function layerStats(filePath) {
1159
1160
  };
1160
1161
  }
1161
1162
  var pct = (v) => `${(v * 100).toFixed(0)}%`;
1163
+ async function lashOffSclera(eyePath, lashPath) {
1164
+ const eye = await decodePng(eyePath);
1165
+ const lash = await decodePng(lashPath);
1166
+ let opaque = 0;
1167
+ let off = 0;
1168
+ for (let y = 0; y < lash.height; y++) {
1169
+ for (let x = 0; x < lash.width; x++) {
1170
+ if (lash.rgba[(y * lash.width + x) * 4 + 3] < 128) continue;
1171
+ opaque++;
1172
+ const onEye = x < eye.width && y < eye.height;
1173
+ if (!onEye || eye.rgba[(y * eye.width + x) * 4 + 3] <= 8) off++;
1174
+ }
1175
+ }
1176
+ return { opaque, off };
1177
+ }
1162
1178
  async function measureDir(absDir) {
1163
1179
  const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
1164
1180
  if (files.length === 0) {
@@ -1240,12 +1256,28 @@ async function measureDir(absDir) {
1240
1256
  }
1241
1257
  }
1242
1258
  if (lash) {
1243
- const dx = lash.bboxCx - eye.bboxCx;
1259
+ const { opaque, off } = await lashOffSclera(
1260
+ import_node_path4.default.join(absDir, `eye_${side}.png`),
1261
+ import_node_path4.default.join(absDir, `lash_${side}.png`)
1262
+ );
1244
1263
  const dTop = lash.marginTop - eye.marginTop;
1245
- if (Math.abs(dx) > eye.w * LASH_CENTRE_TOL_FRAC || Math.abs(dTop) > 0.5) {
1264
+ const faults = [
1265
+ ...off > opaque * LASH_STRAY_TOL_FRAC ? [`${off} of its ${opaque} opaque px lie off eye_${side}'s sclera`] : [],
1266
+ ...Math.abs(dTop) > 0.5 ? [`its top edge is ${dTop.toFixed(1)} px off the sclera's`] : []
1267
+ ];
1268
+ if (faults.length > 0) {
1246
1269
  warnings.push(
1247
- `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.`
1270
+ `lash_${side}: ${faults.join(" and ")} \u2014 they are split from one source and MUST share cx/cy/w/h in layout, or the blink fold tears. Retune to match.`
1248
1271
  );
1272
+ } else {
1273
+ const bareLeft = lash.marginLeft - eye.marginLeft;
1274
+ const bareRight = lash.marginRight - eye.marginRight;
1275
+ const [bareOuter, bareInner] = side === "R" ? [bareLeft, bareRight] : [bareRight, bareLeft];
1276
+ if ((bareOuter - bareInner) / eye.w > EYE_FACING_TOL_FRAC) {
1277
+ warnings.push(
1278
+ `eye_${side}: its lash stops ${pct(bareOuter / eye.w)} of the eye width short of the outer corner and ${pct(bareInner / eye.w)} short of the nose side \u2014 the eyewhite is drawn facing the other way, lash wing at the inner corner. 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. Free fix: compose again with mirrorParts: ["eyewhite.png"] \u2014 no regeneration.`
1279
+ );
1280
+ }
1249
1281
  }
1250
1282
  }
1251
1283
  }
@@ -1377,6 +1409,12 @@ var ORDER = [
1377
1409
  "brow_R",
1378
1410
  "hair_front"
1379
1411
  ];
1412
+ var PART_FILES = [
1413
+ ...new Set(
1414
+ Object.values(DEFAULT_LAYOUT).map((cfg) => cfg.src).filter((src) => !src.startsWith("eyewhite_"))
1415
+ ),
1416
+ EYEWHITE_SRC
1417
+ ];
1380
1418
  function resolveLayout(overrides) {
1381
1419
  const resolved = { ...DEFAULT_LAYOUT };
1382
1420
  if (overrides === void 0) return resolved;
@@ -1412,6 +1450,18 @@ function resolveLayout(overrides) {
1412
1450
  }
1413
1451
  return resolved;
1414
1452
  }
1453
+ function resolveMirrorParts(names) {
1454
+ const mirrored = /* @__PURE__ */ new Set();
1455
+ for (const [i, name] of (names ?? []).entries()) {
1456
+ if (!PART_FILES.includes(name)) {
1457
+ throw new AutoRigInputError(
1458
+ `mirrorParts[${i}]: unknown part ${JSON.stringify(name)} \u2014 expected one of ${PART_FILES.join(", ")}`
1459
+ );
1460
+ }
1461
+ mirrored.add(name);
1462
+ }
1463
+ return mirrored;
1464
+ }
1415
1465
  function keyWhiteToAlpha(rgba) {
1416
1466
  const keyed = Buffer.from(rgba);
1417
1467
  for (let i = 0; i < keyed.length; i += 4) {
@@ -1421,7 +1471,7 @@ function keyWhiteToAlpha(rgba) {
1421
1471
  }
1422
1472
  return keyed;
1423
1473
  }
1424
- async function partBuffer(role, cfg, partsDir, inMemory) {
1474
+ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
1425
1475
  let img;
1426
1476
  if (inMemory !== void 0) {
1427
1477
  img = (0, import_sharp2.default)(inMemory);
@@ -1439,7 +1489,7 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
1439
1489
  });
1440
1490
  }
1441
1491
  if (!cfg.noTrim) img = img.trim({ threshold: 12 });
1442
- if (cfg.mirror) img = img.flop();
1492
+ if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
1443
1493
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
1444
1494
  if (cfg.h === void 0) {
1445
1495
  const scaledH = Math.round(
@@ -1536,28 +1586,47 @@ async function composeLayersFromParts(input) {
1536
1586
  );
1537
1587
  }
1538
1588
  const layout = resolveLayout(input.layout);
1589
+ const mirrored = resolveMirrorParts(input.mirrorParts);
1539
1590
  const split = await prepEyeSplit(partsDir);
1540
1591
  const splitSources = /* @__PURE__ */ new Map([
1541
1592
  ["eyewhite_sclera.png", split.sclera],
1542
1593
  ["eyewhite_lash.png", split.lash]
1543
1594
  ]);
1544
- const layers = [];
1595
+ const placed = [];
1545
1596
  const skipped = [];
1546
- const preview = [];
1547
1597
  for (const role of ORDER) {
1548
1598
  const cfg = layout[role];
1599
+ const inMemory = splitSources.get(cfg.src);
1549
1600
  const part = await partBuffer(
1550
1601
  role,
1551
1602
  cfg,
1552
1603
  partsDir,
1553
- splitSources.get(cfg.src)
1604
+ inMemory,
1605
+ // The split halves are cut from eyewhite.png, the file a caller names.
1606
+ mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
1554
1607
  );
1555
1608
  if (part === null) {
1556
1609
  skipped.push(role);
1557
- import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
1558
1610
  continue;
1559
1611
  }
1560
1612
  const { left, top } = placement(role, cfg, part.w, part.h);
1613
+ if (role === "lash_L" || role === "lash_R") {
1614
+ const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
1615
+ const eye = placed.find((p) => p.role === eyeRole);
1616
+ if (eye !== void 0 && (eye.left !== left || eye.top !== top || eye.part.w !== part.w || eye.part.h !== part.h)) {
1617
+ throw new AutoRigInputError(
1618
+ `layout.${role} places the lash at ${part.w}x${part.h} (${left},${top}), but layout.${eyeRole} places its sclera at ${eye.part.w}x${eye.part.h} (${eye.left},${eye.top}) \u2014 they are cut from one eyewhite into one frame, and the blink fold tears where they part. Set cx/cy/w/h the same on both.`
1619
+ );
1620
+ }
1621
+ }
1622
+ placed.push({ role, part, left, top });
1623
+ }
1624
+ for (const role of skipped) {
1625
+ import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
1626
+ }
1627
+ const layers = [];
1628
+ const preview = [];
1629
+ for (const { role, part, left, top } of placed) {
1561
1630
  const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
1562
1631
  const outPath = import_node_path5.default.join(outDir, `${role}.png`);
1563
1632
  writeFileAtomic(outPath, layer);
@@ -1600,7 +1669,7 @@ async function composeLayersFromParts(input) {
1600
1669
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1601
1670
  var import_zod = require("zod");
1602
1671
  function createIkiMcpServer() {
1603
- const server = new import_mcp.McpServer({ name: "iki", version: "0.9.0" });
1672
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.10.0" });
1604
1673
  server.registerTool(
1605
1674
  "validate_iki",
1606
1675
  {
@@ -1727,7 +1796,10 @@ function createIkiMcpServer() {
1727
1796
  h: import_zod.z.number()
1728
1797
  }).partial()
1729
1798
  ).optional().describe(
1730
- "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 (set it on a sclera and its lash together, or the blink fold tears)."
1799
+ "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. 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."
1800
+ ),
1801
+ mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
1802
+ "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."
1731
1803
  )
1732
1804
  }
1733
1805
  },