@ikijs/mcp 0.39.0 → 0.39.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.
@@ -571,6 +571,9 @@ var Spring = class {
571
571
  }
572
572
  }
573
573
  };
574
+ function eyeSpring() {
575
+ return new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
576
+ }
574
577
  var IdleMotion = class {
575
578
  /**
576
579
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -596,8 +599,8 @@ var IdleMotion = class {
596
599
  // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
597
600
  // first retarget. A host target, while set, replaces the pick as what the
598
601
  // eyes and head chase; the schedule keeps picking underneath it.
599
- eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
600
- eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
602
+ eyeX = eyeSpring();
603
+ eyeY = eyeSpring();
601
604
  gazeTargetX = 0;
602
605
  gazeTargetY = 0;
603
606
  nextGazeRetargetMs;
@@ -5405,6 +5408,8 @@ import {
5405
5408
  armGeometry,
5406
5409
  createLayerSetMeasurer as createLayerSetMeasurer2
5407
5410
  } from "@ikijs/editor";
5411
+ var UPPER_BODY = 0.35;
5412
+ var NARROW_ROW = 0.6;
5408
5413
  var ARM_ROLES = ["arm_L", "arm_R"];
5409
5414
  var CAP_OVERLAP = 0.5;
5410
5415
  var px = (v) => `${Number(v.toFixed(1))}`;
@@ -5470,6 +5475,19 @@ function capWarning(arm, g, body) {
5470
5475
  const overlap = g.shoulderRadius - g.side * (pivotX - edge);
5471
5476
  const need = CAP_OVERLAP * g.shoulderRadius;
5472
5477
  if (overlap >= need) return void 0;
5478
+ const crop = row - body.bbox.y;
5479
+ const width = (r) => r === void 0 || r.length === 0 ? 0 : r[r.length - 1] - r[0];
5480
+ const here = width(runs);
5481
+ let below = 0;
5482
+ let belowRow = row;
5483
+ const end = Math.ceil(UPPER_BODY * body.bbox.h);
5484
+ for (let k = crop + 1; k < end; k++) {
5485
+ const w = width(body.rowRuns?.[k]);
5486
+ if (w > below) [below, belowRow] = [w, body.bbox.y + k];
5487
+ }
5488
+ if (here < NARROW_ROW * below) {
5489
+ return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px), and the body is ${here} px wide there against ${below} px at y=${belowRow}. Read the shoulder line off preview.png: if that row is the neck, move layout.${arm}.cy down by the px the shoulder line lies under y=${row} (free) \u2014 not its cx, which hangs the arm from the neck; if it is the shoulders over a wider garment, move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
5490
+ }
5473
5491
  return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px) \u2014 a gap opens beside the shoulder once the arm raises. Move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
5474
5492
  }
5475
5493
 
@@ -6022,6 +6040,15 @@ function keyGreen(rgba, W, H) {
6022
6040
  }
6023
6041
  return out;
6024
6042
  }
6043
+ var SPILL_REACH = 3;
6044
+ function despill(rgba, only) {
6045
+ for (let i = 0; i < rgba.length; i += 4) {
6046
+ if (only !== void 0 && !only[i >> 2]) continue;
6047
+ const cap = Math.max(rgba[i], rgba[i + 2]);
6048
+ if (rgba[i + 1] > cap) rgba[i + 1] = cap;
6049
+ }
6050
+ return rgba;
6051
+ }
6025
6052
  var GROUND_TOLERANCE = 4;
6026
6053
  var GROUND_LIGHT = 200;
6027
6054
  var GROUND_MIN = 238;
@@ -6254,6 +6281,21 @@ async function splitLipSet(keyedPng, w, h, interior) {
6254
6281
  const alpha = (p) => frame[p * 4 + 3];
6255
6282
  const { label, main, box: hb } = enclosedHole(frame, w, h);
6256
6283
  const holeW = hb.x1 - hb.x0 + 1;
6284
+ const near = new Uint8Array(n);
6285
+ for (let y = Math.max(0, hb.y0 - SPILL_REACH); y <= Math.min(h - 1, hb.y1 + SPILL_REACH); y++) {
6286
+ for (let x = Math.max(0, hb.x0 - SPILL_REACH); x <= Math.min(w - 1, hb.x1 + SPILL_REACH); x++) {
6287
+ if (label[y * w + x] !== main) continue;
6288
+ for (let dy = -SPILL_REACH; dy <= SPILL_REACH; dy++) {
6289
+ const yy = y + dy;
6290
+ if (yy < 0 || yy >= h) continue;
6291
+ for (let dx = -SPILL_REACH; dx <= SPILL_REACH; dx++) {
6292
+ const xx = x + dx;
6293
+ if (xx >= 0 && xx < w) near[yy * w + xx] = 1;
6294
+ }
6295
+ }
6296
+ }
6297
+ }
6298
+ const paint = despill(Buffer.from(frame), near);
6257
6299
  const top = new Int32Array(w).fill(-1);
6258
6300
  const bot = new Int32Array(w).fill(-1);
6259
6301
  for (let y = 0; y < h; y++) {
@@ -6313,7 +6355,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
6313
6355
  const inner = Buffer.alloc(n * 4);
6314
6356
  const tongue = Buffer.alloc(n * 4);
6315
6357
  const teeth = Buffer.alloc(n * 4);
6316
- const copy = (to, p) => frame.copy(to, p * 4, p * 4, p * 4 + 4);
6358
+ const copy = (to, p) => paint.copy(to, p * 4, p * 4, p * 4 + 4);
6317
6359
  for (let y = 0; y < h; y++) {
6318
6360
  for (let x = 0; x < w; x++) {
6319
6361
  const p = y * w + x;
@@ -6339,7 +6381,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
6339
6381
  }
6340
6382
  if ((inM[p] || wall[x]) && !faintUpper(p, x, y)) {
6341
6383
  const a = alpha(p) / 255;
6342
- for (let c = 0; c < 3; c++) out[c] += (frame[p * 4 + c] - out[c]) * a;
6384
+ for (let c = 0; c < 3; c++) out[c] += (paint[p * 4 + c] - out[c]) * a;
6343
6385
  }
6344
6386
  inner[p * 4] = Math.round(out[0]);
6345
6387
  inner[p * 4 + 1] = Math.round(out[1]);
@@ -6441,7 +6483,9 @@ async function closedLips(upper, lower, shift, left, top) {
6441
6483
  var isLipLayerRole = (role) => LIP_ROLES.includes(role) || isLipInsideRole(role);
6442
6484
  var MIN_OPENING_ROWS = 8;
6443
6485
  var MIN_LINE_ROWS = 2;
6444
- var GREEN_EXCESS = 40;
6486
+ var GREEN_EXCESS = 16;
6487
+ var KEY_GREEN_EXCESS = 40;
6488
+ var EDGE_REACH = 3;
6445
6489
  var INTERIOR_GAP_FRACTION = 0.05;
6446
6490
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
6447
6491
  async function lipWarnings(absDir, layers, inPlace = false) {
@@ -6502,17 +6546,49 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6502
6546
  });
6503
6547
  const set = /* @__PURE__ */ new Map();
6504
6548
  const green = [];
6549
+ const pixels = /* @__PURE__ */ new Map();
6505
6550
  for (const role of LIP_ROLES) {
6506
6551
  const fileName = `${role}.png`;
6507
6552
  const { rgba } = await decodePng(path8.join(absDir, fileName));
6508
6553
  set.set(role, measurer.add({ role, fileName, rgba }));
6554
+ pixels.set(role, rgba);
6509
6555
  for (let i = 0; i < rgba.length; i += 4) {
6510
- if (rgba[i + 3] >= ALPHA_OPAQUE4 && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
6556
+ if (rgba[i + 3] >= ALPHA_OPAQUE4 && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > KEY_GREEN_EXCESS) {
6511
6557
  green.push(role);
6512
6558
  break;
6513
6559
  }
6514
6560
  }
6515
6561
  }
6562
+ {
6563
+ const W = inner.canvasW;
6564
+ const H = inner.canvasH;
6565
+ const cavity2 = pixels.get("mouth_inner");
6566
+ const edge = new Uint8Array(W * H);
6567
+ for (let p = 0; p < W * H; p++) {
6568
+ if (cavity2[p * 4 + 3] < 128) continue;
6569
+ const x = p % W;
6570
+ const y = (p - x) / W;
6571
+ for (let dy = -EDGE_REACH; dy <= EDGE_REACH; dy++) {
6572
+ const yy = y + dy;
6573
+ if (yy < 0 || yy >= H) continue;
6574
+ for (let dx = -EDGE_REACH; dx <= EDGE_REACH; dx++) {
6575
+ const xx = x + dx;
6576
+ if (xx >= 0 && xx < W) edge[yy * W + xx] = 1;
6577
+ }
6578
+ }
6579
+ }
6580
+ for (const role of ["lip_upper", "lip_lower"]) {
6581
+ if (green.includes(role)) continue;
6582
+ const rgba = pixels.get(role);
6583
+ for (let p = 0; p < W * H; p++) {
6584
+ const i = p * 4;
6585
+ if (edge[p] && (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) * rgba[i + 3] / 255 > GREEN_EXCESS) {
6586
+ green.push(role);
6587
+ break;
6588
+ }
6589
+ }
6590
+ }
6591
+ }
6516
6592
  let opening;
6517
6593
  try {
6518
6594
  opening = mouthOpening2(set);
@@ -6590,7 +6666,11 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6590
6666
  }
6591
6667
  if (!inPlace && green.length > 0) {
6592
6668
  warnings.push(
6593
- `${green.join("/")}: opaque green left (key green, g exceeds r and b by over ${GREEN_EXCESS}) \u2014 it shows as a green fringe on the lips. Regenerate mouth_keyed.png with the green only inside the opening, or mouth_interior.png without green in it. Billed.`
6669
+ `${green.join("/")}: green left (key green: g over r and b by more than ${KEY_GREEN_EXCESS} in an opaque pixel, or by more than ${GREEN_EXCESS} at the pixel's alpha on the opening's edge) \u2014 it shows as a green fringe on the lips. ${recompose(
6670
+ "mouth_keyed.png",
6671
+ // mouth_inner's fill is the interior's own paint, which the composer keeps as drawn.
6672
+ green.includes("mouth_inner") ? "with the green only inside the opening, or mouth_interior.png without green in it" : "with the green only inside the opening"
6673
+ )}`
6594
6674
  );
6595
6675
  }
6596
6676
  if (!inPlace && area > 0 && hollow > INTERIOR_GAP_FRACTION * area) {
@@ -7974,7 +8054,7 @@ import {
7974
8054
  var PLUGIN_ENV = "IKI_PLUGIN";
7975
8055
  function toolGenerator(env = process.env) {
7976
8056
  const generator = {
7977
- tool: `@ikijs/mcp@${"0.39.0"}`,
8057
+ tool: `@ikijs/mcp@${"0.39.1"}`,
7978
8058
  rigger: `@ikijs/editor@${EDITOR_VERSION}`
7979
8059
  };
7980
8060
  const plugin = env[PLUGIN_ENV];
@@ -12648,7 +12728,7 @@ function formatBakeChecks(bakes) {
12648
12728
  );
12649
12729
  }
12650
12730
  function createIkiMcpServer() {
12651
- const server = new McpServer({ name: "iki", version: "0.39.0" });
12731
+ const server = new McpServer({ name: "iki", version: "0.39.1" });
12652
12732
  server.registerTool(
12653
12733
  "validate_iki",
12654
12734
  {
@@ -12930,7 +13010,7 @@ function createIkiMcpServer() {
12930
13010
  server.registerTool(
12931
13011
  "compose_layers_from_parts",
12932
13012
  {
12933
- 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, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_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). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. 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`.",
13013
+ 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, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_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). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when its pivot row is much narrower than the body below it), and a pose forearm without its arm or off its arm's elbow in pivot, width or length. 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`.",
12934
13014
  inputSchema: {
12935
13015
  partsDir: z.string().describe(
12936
13016
  "Directory of the source part PNGs (resolved against cwd)."
@@ -12978,7 +13058,7 @@ function createIkiMcpServer() {
12978
13058
  server.registerTool(
12979
13059
  "measure_layers",
12980
13060
  {
12981
- 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, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. 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.",
13061
+ 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, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when that row is much narrower than the body below it), a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. 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.",
12982
13062
  inputSchema: {
12983
13063
  layersDir: z.string().describe(
12984
13064
  "Directory of role-named layer PNGs (resolved against cwd)."
@@ -13344,4 +13424,4 @@ export {
13344
13424
  formatCutReport,
13345
13425
  createIkiMcpServer
13346
13426
  };
13347
- //# sourceMappingURL=chunk-KLZ6EOMG.mjs.map
13427
+ //# sourceMappingURL=chunk-3XQLLYUF.mjs.map