@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.
package/dist/cli.js CHANGED
@@ -608,6 +608,9 @@ var Spring = class {
608
608
  }
609
609
  }
610
610
  };
611
+ function eyeSpring() {
612
+ return new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
613
+ }
611
614
  var IdleMotion = class {
612
615
  /**
613
616
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -633,8 +636,8 @@ var IdleMotion = class {
633
636
  // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
634
637
  // first retarget. A host target, while set, replaces the pick as what the
635
638
  // eyes and head chase; the schedule keeps picking underneath it.
636
- eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
637
- eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
639
+ eyeX = eyeSpring();
640
+ eyeY = eyeSpring();
638
641
  gazeTargetX = 0;
639
642
  gazeTargetY = 0;
640
643
  nextGazeRetargetMs;
@@ -5105,6 +5108,8 @@ var import_node_path9 = __toESM(require("path"));
5105
5108
  // src/measure-arms.ts
5106
5109
  var import_node_path6 = __toESM(require("path"));
5107
5110
  var import_editor6 = require("@ikijs/editor");
5111
+ var UPPER_BODY = 0.35;
5112
+ var NARROW_ROW = 0.6;
5108
5113
  var ARM_ROLES = ["arm_L", "arm_R"];
5109
5114
  var CAP_OVERLAP = 0.5;
5110
5115
  var px = (v) => `${Number(v.toFixed(1))}`;
@@ -5170,6 +5175,19 @@ function capWarning(arm, g, body) {
5170
5175
  const overlap = g.shoulderRadius - g.side * (pivotX - edge);
5171
5176
  const need = CAP_OVERLAP * g.shoulderRadius;
5172
5177
  if (overlap >= need) return void 0;
5178
+ const crop = row - body.bbox.y;
5179
+ const width = (r) => r === void 0 || r.length === 0 ? 0 : r[r.length - 1] - r[0];
5180
+ const here = width(runs);
5181
+ let below = 0;
5182
+ let belowRow = row;
5183
+ const end = Math.ceil(UPPER_BODY * body.bbox.h);
5184
+ for (let k = crop + 1; k < end; k++) {
5185
+ const w = width(body.rowRuns?.[k]);
5186
+ if (w > below) [below, belowRow] = [w, body.bbox.y + k];
5187
+ }
5188
+ if (here < NARROW_ROW * below) {
5189
+ 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).`;
5190
+ }
5173
5191
  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).`;
5174
5192
  }
5175
5193
 
@@ -5632,6 +5650,15 @@ function keyGreen(rgba, W, H) {
5632
5650
  }
5633
5651
  return out;
5634
5652
  }
5653
+ var SPILL_REACH = 3;
5654
+ function despill(rgba, only) {
5655
+ for (let i = 0; i < rgba.length; i += 4) {
5656
+ if (only !== void 0 && !only[i >> 2]) continue;
5657
+ const cap = Math.max(rgba[i], rgba[i + 2]);
5658
+ if (rgba[i + 1] > cap) rgba[i + 1] = cap;
5659
+ }
5660
+ return rgba;
5661
+ }
5635
5662
  var GROUND_TOLERANCE = 4;
5636
5663
  var GROUND_LIGHT = 200;
5637
5664
  var GROUND_MIN = 238;
@@ -5864,6 +5891,21 @@ async function splitLipSet(keyedPng, w, h, interior) {
5864
5891
  const alpha = (p) => frame[p * 4 + 3];
5865
5892
  const { label, main: main2, box: hb } = enclosedHole(frame, w, h);
5866
5893
  const holeW = hb.x1 - hb.x0 + 1;
5894
+ const near = new Uint8Array(n);
5895
+ for (let y = Math.max(0, hb.y0 - SPILL_REACH); y <= Math.min(h - 1, hb.y1 + SPILL_REACH); y++) {
5896
+ for (let x = Math.max(0, hb.x0 - SPILL_REACH); x <= Math.min(w - 1, hb.x1 + SPILL_REACH); x++) {
5897
+ if (label[y * w + x] !== main2) continue;
5898
+ for (let dy = -SPILL_REACH; dy <= SPILL_REACH; dy++) {
5899
+ const yy = y + dy;
5900
+ if (yy < 0 || yy >= h) continue;
5901
+ for (let dx = -SPILL_REACH; dx <= SPILL_REACH; dx++) {
5902
+ const xx = x + dx;
5903
+ if (xx >= 0 && xx < w) near[yy * w + xx] = 1;
5904
+ }
5905
+ }
5906
+ }
5907
+ }
5908
+ const paint = despill(Buffer.from(frame), near);
5867
5909
  const top = new Int32Array(w).fill(-1);
5868
5910
  const bot = new Int32Array(w).fill(-1);
5869
5911
  for (let y = 0; y < h; y++) {
@@ -5923,7 +5965,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5923
5965
  const inner = Buffer.alloc(n * 4);
5924
5966
  const tongue = Buffer.alloc(n * 4);
5925
5967
  const teeth = Buffer.alloc(n * 4);
5926
- const copy = (to, p) => frame.copy(to, p * 4, p * 4, p * 4 + 4);
5968
+ const copy = (to, p) => paint.copy(to, p * 4, p * 4, p * 4 + 4);
5927
5969
  for (let y = 0; y < h; y++) {
5928
5970
  for (let x = 0; x < w; x++) {
5929
5971
  const p = y * w + x;
@@ -5949,7 +5991,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5949
5991
  }
5950
5992
  if ((inM[p] || wall[x]) && !faintUpper(p, x, y)) {
5951
5993
  const a = alpha(p) / 255;
5952
- for (let c = 0; c < 3; c++) out[c] += (frame[p * 4 + c] - out[c]) * a;
5994
+ for (let c = 0; c < 3; c++) out[c] += (paint[p * 4 + c] - out[c]) * a;
5953
5995
  }
5954
5996
  inner[p * 4] = Math.round(out[0]);
5955
5997
  inner[p * 4 + 1] = Math.round(out[1]);
@@ -6051,7 +6093,9 @@ async function closedLips(upper, lower, shift, left, top) {
6051
6093
  var isLipLayerRole = (role) => import_editor10.LIP_ROLES.includes(role) || (0, import_editor10.isLipInsideRole)(role);
6052
6094
  var MIN_OPENING_ROWS = 8;
6053
6095
  var MIN_LINE_ROWS = 2;
6054
- var GREEN_EXCESS = 40;
6096
+ var GREEN_EXCESS = 16;
6097
+ var KEY_GREEN_EXCESS = 40;
6098
+ var EDGE_REACH = 3;
6055
6099
  var INTERIOR_GAP_FRACTION = 0.05;
6056
6100
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
6057
6101
  async function lipWarnings(absDir, layers, inPlace = false) {
@@ -6112,17 +6156,49 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6112
6156
  });
6113
6157
  const set = /* @__PURE__ */ new Map();
6114
6158
  const green = [];
6159
+ const pixels = /* @__PURE__ */ new Map();
6115
6160
  for (const role of import_editor10.LIP_ROLES) {
6116
6161
  const fileName = `${role}.png`;
6117
6162
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
6118
6163
  set.set(role, measurer.add({ role, fileName, rgba }));
6164
+ pixels.set(role, rgba);
6119
6165
  for (let i = 0; i < rgba.length; i += 4) {
6120
- if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
6166
+ if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > KEY_GREEN_EXCESS) {
6121
6167
  green.push(role);
6122
6168
  break;
6123
6169
  }
6124
6170
  }
6125
6171
  }
6172
+ {
6173
+ const W = inner.canvasW;
6174
+ const H = inner.canvasH;
6175
+ const cavity2 = pixels.get("mouth_inner");
6176
+ const edge = new Uint8Array(W * H);
6177
+ for (let p = 0; p < W * H; p++) {
6178
+ if (cavity2[p * 4 + 3] < 128) continue;
6179
+ const x = p % W;
6180
+ const y = (p - x) / W;
6181
+ for (let dy = -EDGE_REACH; dy <= EDGE_REACH; dy++) {
6182
+ const yy = y + dy;
6183
+ if (yy < 0 || yy >= H) continue;
6184
+ for (let dx = -EDGE_REACH; dx <= EDGE_REACH; dx++) {
6185
+ const xx = x + dx;
6186
+ if (xx >= 0 && xx < W) edge[yy * W + xx] = 1;
6187
+ }
6188
+ }
6189
+ }
6190
+ for (const role of ["lip_upper", "lip_lower"]) {
6191
+ if (green.includes(role)) continue;
6192
+ const rgba = pixels.get(role);
6193
+ for (let p = 0; p < W * H; p++) {
6194
+ const i = p * 4;
6195
+ if (edge[p] && (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) * rgba[i + 3] / 255 > GREEN_EXCESS) {
6196
+ green.push(role);
6197
+ break;
6198
+ }
6199
+ }
6200
+ }
6201
+ }
6126
6202
  let opening;
6127
6203
  try {
6128
6204
  opening = (0, import_editor10.mouthOpening)(set);
@@ -6200,7 +6276,11 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6200
6276
  }
6201
6277
  if (!inPlace && green.length > 0) {
6202
6278
  warnings.push(
6203
- `${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.`
6279
+ `${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(
6280
+ "mouth_keyed.png",
6281
+ // mouth_inner's fill is the interior's own paint, which the composer keeps as drawn.
6282
+ 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"
6283
+ )}`
6204
6284
  );
6205
6285
  }
6206
6286
  if (!inPlace && area > 0 && hollow > INTERIOR_GAP_FRACTION * area) {
@@ -7918,7 +7998,7 @@ var import_format12 = require("@ikijs/format");
7918
7998
  var PLUGIN_ENV = "IKI_PLUGIN";
7919
7999
  function toolGenerator(env = process.env) {
7920
8000
  const generator = {
7921
- tool: `@ikijs/mcp@${"0.39.0"}`,
8001
+ tool: `@ikijs/mcp@${"0.39.1"}`,
7922
8002
  rigger: `@ikijs/editor@${import_editor15.EDITOR_VERSION}`
7923
8003
  };
7924
8004
  const plugin = env[PLUGIN_ENV];
@@ -12589,7 +12669,7 @@ function formatBakeChecks(bakes) {
12589
12669
  );
12590
12670
  }
12591
12671
  function createIkiMcpServer() {
12592
- const server = new import_mcp.McpServer({ name: "iki", version: "0.39.0" });
12672
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.39.1" });
12593
12673
  server.registerTool(
12594
12674
  "validate_iki",
12595
12675
  {
@@ -12871,7 +12951,7 @@ function createIkiMcpServer() {
12871
12951
  server.registerTool(
12872
12952
  "compose_layers_from_parts",
12873
12953
  {
12874
- 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`.",
12954
+ 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`.",
12875
12955
  inputSchema: {
12876
12956
  partsDir: import_zod.z.string().describe(
12877
12957
  "Directory of the source part PNGs (resolved against cwd)."
@@ -12919,7 +12999,7 @@ function createIkiMcpServer() {
12919
12999
  server.registerTool(
12920
13000
  "measure_layers",
12921
13001
  {
12922
- 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.",
13002
+ 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.",
12923
13003
  inputSchema: {
12924
13004
  layersDir: import_zod.z.string().describe(
12925
13005
  "Directory of role-named layer PNGs (resolved against cwd)."