@ikijs/mcp 0.6.0 → 0.7.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.js CHANGED
@@ -694,7 +694,11 @@ async function measureDir(absDir) {
694
694
  }
695
695
  for (const [role, why] of [
696
696
  ["body", "without it the character reads as a floating head on head-turn"],
697
- ["hair_back", "without it the silhouette is flat behind the face"]
697
+ ["hair_back", "without it the silhouette is flat behind the face"],
698
+ [
699
+ "nose",
700
+ "without it nothing on the face slides on the head turn \u2014 the features stay on the plate"
701
+ ]
698
702
  ]) {
699
703
  if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
700
704
  }
@@ -748,13 +752,6 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
748
752
  var EYEWHITE_SRC = "eyewhite.png";
749
753
  var EYE_LASH_LUMA = 120;
750
754
  var LASH_KEEP_FRACTION = 0.5;
751
- var NOSE_INK_TOL = 20;
752
- var NOSE_INK_LOW = 8;
753
- var NOSE_GROW = 2;
754
- var NOSE_MIN_PIXELS = 12;
755
- var NOSE_MAX_CUT_FRACTION = 0.25;
756
- var NOSE_ROW_MIN_PIXELS = 8;
757
- var NOSE_FILL_REACH = 8;
758
755
  var DEFAULT_LAYOUT = {
759
756
  // Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
760
757
  // without them still composes (head-only character).
@@ -764,6 +761,11 @@ var DEFAULT_LAYOUT = {
764
761
  // not a floating head.
765
762
  body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
766
763
  face: { src: "face.png", cx: 550, cy: 475, w: 400 },
764
+ // The nose, drawn on its own (the face is drawn without one): the auto-rig
765
+ // leads the head turn with it and keys the other features' slide on its
766
+ // presence, so without it the features stay on the face plate. Sits between
767
+ // the eyes and above the mouth. OPTIONAL: a parts dir without it composes.
768
+ nose: { src: "nose.png", cx: 550, cy: 586, w: 40, optional: true },
767
769
  mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
768
770
  // Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
769
771
  // auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
@@ -805,6 +807,7 @@ var ORDER = [
805
807
  "hair_back",
806
808
  "body",
807
809
  "face",
810
+ "nose",
808
811
  "mouth",
809
812
  "mouth_open",
810
813
  "eye_L",
@@ -966,164 +969,6 @@ async function prepEyeSplit(partsDir) {
966
969
  lash: await cropToBuffer(lash, W, H, region)
967
970
  };
968
971
  }
969
- function cutNose(rgba, box) {
970
- const W = CANVAS;
971
- const x0 = Math.max(0, box.x0);
972
- const y0 = Math.max(0, box.y0);
973
- const x1 = Math.min(W, box.x1);
974
- const y1 = Math.min(W, box.y1);
975
- if (x1 - x0 < 4 || y1 - y0 < 4) return null;
976
- const bw = x1 - x0;
977
- const bh = y1 - y0;
978
- const at = (x, y) => (y * W + x) * 4;
979
- const median = (v) => v.sort((a, b) => a - b)[v.length >> 1];
980
- const all = [[], [], []];
981
- const rows = [];
982
- for (let y = y0; y < y1; y++) {
983
- const row = [[], [], []];
984
- for (let x = x0; x < x1; x++) {
985
- const i = at(x, y);
986
- if (rgba[i + 3] === 0) continue;
987
- for (let c = 0; c < 3; c++) {
988
- row[c].push(rgba[i + c]);
989
- all[c].push(rgba[i + c]);
990
- }
991
- }
992
- rows.push(row);
993
- }
994
- const opaqueCount = all[0].length;
995
- if (opaqueCount === 0) return null;
996
- const skin = all.map(median);
997
- const skinRow = rows.map(
998
- (row) => row[0].length < NOSE_ROW_MIN_PIXELS ? skin : row.map(median)
999
- );
1000
- const distAt = (i, y) => {
1001
- const ref = skinRow[y - y0];
1002
- return Math.max(
1003
- Math.abs(rgba[i] - ref[0]),
1004
- Math.abs(rgba[i + 1] - ref[1]),
1005
- Math.abs(rgba[i + 2] - ref[2])
1006
- );
1007
- };
1008
- const dist = new Uint8Array(bw * bh);
1009
- const ink = new Uint8Array(bw * bh);
1010
- const queue = [];
1011
- let inkCount = 0;
1012
- for (let y = y0; y < y1; y++) {
1013
- for (let x = x0; x < x1; x++) {
1014
- const i = at(x, y);
1015
- if (rgba[i + 3] === 0) continue;
1016
- const d = distAt(i, y);
1017
- const k = (y - y0) * bw + (x - x0);
1018
- dist[k] = d;
1019
- if (d > NOSE_INK_TOL) {
1020
- ink[k] = 1;
1021
- queue.push(k);
1022
- inkCount++;
1023
- }
1024
- }
1025
- }
1026
- if (inkCount < NOSE_MIN_PIXELS) return null;
1027
- while (queue.length > 0) {
1028
- const k = queue.pop();
1029
- const kx = k % bw;
1030
- const ky = (k - kx) / bw;
1031
- for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
1032
- for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
1033
- const nx = kx + dx;
1034
- const ny = ky + dy;
1035
- if (nx < 0 || nx >= bw || ny < 0 || ny >= bh) continue;
1036
- const n = ny * bw + nx;
1037
- if (ink[n] === 0 && dist[n] > NOSE_INK_LOW) {
1038
- ink[n] = 1;
1039
- queue.push(n);
1040
- }
1041
- }
1042
- }
1043
- }
1044
- const cut = new Uint8Array(bw * bh);
1045
- for (let y = 0; y < bh; y++) {
1046
- for (let x = 0; x < bw; x++) {
1047
- if (ink[y * bw + x] === 0) continue;
1048
- for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
1049
- for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
1050
- const yy = y + dy;
1051
- const xx = x + dx;
1052
- if (yy >= 0 && yy < bh && xx >= 0 && xx < bw) cut[yy * bw + xx] = 1;
1053
- }
1054
- }
1055
- }
1056
- }
1057
- let cutCount = 0;
1058
- for (let y = 0; y < bh; y++) {
1059
- for (let x = 0; x < bw; x++) {
1060
- if (cut[y * bw + x] === 0) continue;
1061
- const a = rgba[at(x0 + x, y0 + y) + 3];
1062
- if (a === 0) continue;
1063
- if (a < 255) return null;
1064
- cutCount++;
1065
- }
1066
- }
1067
- if (cutCount > NOSE_MAX_CUT_FRACTION * opaqueCount) return null;
1068
- const face = Buffer.from(rgba);
1069
- const nose = Buffer.from(rgba);
1070
- for (let i = 3; i < nose.length; i += 4) nose[i] = 0;
1071
- let minX = W;
1072
- let minY = W;
1073
- let maxX = -1;
1074
- let maxY = -1;
1075
- for (let y = 0; y < bh; y++) {
1076
- const cy = y0 + y;
1077
- let x = 0;
1078
- while (x < bw) {
1079
- if (cut[y * bw + x] === 0) {
1080
- x++;
1081
- continue;
1082
- }
1083
- const start = x;
1084
- while (x < bw && cut[y * bw + x] === 1) x++;
1085
- const end = x;
1086
- const skinAt = (bx) => {
1087
- for (let step = 0; step < NOSE_FILL_REACH && bx >= 0 && bx < bw; step++) {
1088
- const i = at(x0 + bx, cy);
1089
- if (rgba[i + 3] > 0 && cut[y * bw + bx] === 0) {
1090
- if (distAt(i, cy) <= NOSE_INK_TOL / 2) return i;
1091
- }
1092
- bx += bx < start ? -1 : 1;
1093
- }
1094
- return -1;
1095
- };
1096
- const l = skinAt(start - 1);
1097
- const r = skinAt(end);
1098
- for (let k = start; k < end; k++) {
1099
- const cx = x0 + k;
1100
- const i = at(cx, cy);
1101
- if (rgba[i + 3] === 0) continue;
1102
- const t = (k - start + 1) / (end - start + 1);
1103
- for (let c = 0; c < 3; c++) {
1104
- const rowSkin = skinRow[y];
1105
- const lc = l >= 0 ? rgba[l + c] : r >= 0 ? rgba[r + c] : rowSkin[c];
1106
- const rc = r >= 0 ? rgba[r + c] : l >= 0 ? rgba[l + c] : rowSkin[c];
1107
- face[i + c] = Math.round(lc * (1 - t) + rc * t);
1108
- }
1109
- nose[i] = rgba[i];
1110
- nose[i + 1] = rgba[i + 1];
1111
- nose[i + 2] = rgba[i + 2];
1112
- nose[i + 3] = rgba[i + 3];
1113
- if (cx < minX) minX = cx;
1114
- if (cx > maxX) maxX = cx;
1115
- if (cy < minY) minY = cy;
1116
- if (cy > maxY) maxY = cy;
1117
- }
1118
- }
1119
- }
1120
- if (maxX < 0) return null;
1121
- return {
1122
- face,
1123
- nose,
1124
- bbox: { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 }
1125
- };
1126
- }
1127
972
  async function composeLayersFromParts(input) {
1128
973
  try {
1129
974
  const outDir = resolveOutputDir(input.outDir);
@@ -1142,7 +987,6 @@ async function composeLayersFromParts(input) {
1142
987
  const layers = [];
1143
988
  const skipped = [];
1144
989
  const preview = [];
1145
- let faceRaw;
1146
990
  for (const role of ORDER) {
1147
991
  const cfg = layout[role];
1148
992
  const part = await partBuffer(
@@ -1157,15 +1001,9 @@ async function composeLayersFromParts(input) {
1157
1001
  continue;
1158
1002
  }
1159
1003
  const { left, top } = placement(role, cfg, part.w, part.h);
1160
- const composed = blankCanvas().composite([
1161
- { input: part.buf, left, top }
1162
- ]);
1004
+ const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
1163
1005
  const outPath = import_node_path4.default.join(outDir, `${role}.png`);
1164
- if (role === "face") {
1165
- faceRaw = await composed.raw().toBuffer();
1166
- } else {
1167
- writeFileAtomic(outPath, await composed.png().toBuffer());
1168
- }
1006
+ writeFileAtomic(outPath, layer);
1169
1007
  layers.push({
1170
1008
  role,
1171
1009
  path: outPath,
@@ -1176,48 +1014,6 @@ async function composeLayersFromParts(input) {
1176
1014
  });
1177
1015
  preview.push({ input: part.buf, left, top });
1178
1016
  }
1179
- const placed = (role) => layers.find((l) => l.role === role);
1180
- const eyeL = placed("eye_L");
1181
- const eyeR = placed("eye_R");
1182
- const mouth = placed("mouth");
1183
- const noseCut = cutNose(faceRaw, {
1184
- x0: eyeR.left + eyeR.width,
1185
- x1: eyeL.left,
1186
- y0: Math.round(
1187
- (eyeL.top + eyeL.height / 2 + eyeR.top + eyeR.height / 2) / 2
1188
- ),
1189
- y1: mouth.top - 2
1190
- });
1191
- const rawCanvas = {
1192
- raw: { width: CANVAS, height: CANVAS, channels: 4 }
1193
- };
1194
- const facePath = import_node_path4.default.join(outDir, "face.png");
1195
- const nosePath = import_node_path4.default.join(outDir, "nose.png");
1196
- if (noseCut === null) {
1197
- writeFileAtomic(
1198
- facePath,
1199
- await (0, import_sharp2.default)(faceRaw, rawCanvas).png().toBuffer()
1200
- );
1201
- import_node_fs3.default.rmSync(nosePath, { force: true });
1202
- skipped.push("nose");
1203
- } else {
1204
- writeFileAtomic(
1205
- facePath,
1206
- await (0, import_sharp2.default)(noseCut.face, rawCanvas).png().toBuffer()
1207
- );
1208
- writeFileAtomic(
1209
- nosePath,
1210
- await (0, import_sharp2.default)(noseCut.nose, rawCanvas).png().toBuffer()
1211
- );
1212
- layers.splice(layers.findIndex((l) => l.role === "face") + 1, 0, {
1213
- role: "nose",
1214
- path: nosePath,
1215
- width: noseCut.bbox.w,
1216
- height: noseCut.bbox.h,
1217
- left: noseCut.bbox.x,
1218
- top: noseCut.bbox.y
1219
- });
1220
- }
1221
1017
  const previewPng = await (0, import_sharp2.default)({
1222
1018
  create: {
1223
1019
  width: CANVAS,
@@ -1245,7 +1041,7 @@ async function composeLayersFromParts(input) {
1245
1041
 
1246
1042
  // src/server.ts
1247
1043
  function createIkiMcpServer() {
1248
- const server = new import_mcp.McpServer({ name: "iki", version: "0.6.0" });
1044
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.7.0" });
1249
1045
  server.registerTool(
1250
1046
  "validate_iki",
1251
1047
  {
@@ -1346,7 +1142,7 @@ function createIkiMcpServer() {
1346
1142
  server.registerTool(
1347
1143
  "compose_layers_from_parts",
1348
1144
  {
1349
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, the nose cut out of the face so the rig can lead the turn with it, 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 are optional; nose.png is cut from face.png when it has a drawn nose (reported under `skipped` otherwise).",
1145
+ 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.",
1350
1146
  inputSchema: {
1351
1147
  partsDir: import_zod.z.string().describe(
1352
1148
  "Directory of the source part PNGs (resolved against cwd)."
@@ -1363,7 +1159,7 @@ function createIkiMcpServer() {
1363
1159
  h: import_zod.z.number()
1364
1160
  }).partial()
1365
1161
  ).optional().describe(
1366
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, 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)."
1162
+ "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)."
1367
1163
  )
1368
1164
  }
1369
1165
  },