@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/index.d.mts CHANGED
@@ -203,6 +203,13 @@ declare const DEFAULT_LAYOUT: {
203
203
  cy: number;
204
204
  w: number;
205
205
  };
206
+ nose: {
207
+ src: string;
208
+ cx: number;
209
+ cy: number;
210
+ w: number;
211
+ optional: true;
212
+ };
206
213
  mouth: {
207
214
  src: string;
208
215
  cx: number;
@@ -284,8 +291,6 @@ declare const DEFAULT_LAYOUT: {
284
291
  };
285
292
  };
286
293
  type Role = keyof typeof DEFAULT_LAYOUT;
287
- /** A written layer's role: a placed part, or the nose cut out of the face. */
288
- type LayerRole = Role | "nose";
289
294
  /** Per-role placement overrides; anything omitted keeps the default above. */
290
295
  type LayoutOverride = Partial<Record<Role, {
291
296
  cx?: number;
@@ -306,7 +311,7 @@ interface ComposeInput {
306
311
  layout?: LayoutOverride;
307
312
  }
308
313
  interface ComposedLayer {
309
- role: LayerRole;
314
+ role: Role;
310
315
  path: string;
311
316
  /** Size of the placed part itself (the file is always CANVAS x CANVAS). */
312
317
  width: number;
@@ -318,9 +323,8 @@ type ComposeResult = {
318
323
  ok: true;
319
324
  outDir: string;
320
325
  layers: ComposedLayer[];
321
- /** Roles whose optional part was absent from the parts dir — and `nose`
322
- * when the face had no drawn nose to cut. */
323
- skipped: LayerRole[];
326
+ /** Roles whose optional part was absent from the parts dir. */
327
+ skipped: Role[];
324
328
  preview: string;
325
329
  measure: MeasureReport;
326
330
  } | {
package/dist/index.d.ts CHANGED
@@ -203,6 +203,13 @@ declare const DEFAULT_LAYOUT: {
203
203
  cy: number;
204
204
  w: number;
205
205
  };
206
+ nose: {
207
+ src: string;
208
+ cx: number;
209
+ cy: number;
210
+ w: number;
211
+ optional: true;
212
+ };
206
213
  mouth: {
207
214
  src: string;
208
215
  cx: number;
@@ -284,8 +291,6 @@ declare const DEFAULT_LAYOUT: {
284
291
  };
285
292
  };
286
293
  type Role = keyof typeof DEFAULT_LAYOUT;
287
- /** A written layer's role: a placed part, or the nose cut out of the face. */
288
- type LayerRole = Role | "nose";
289
294
  /** Per-role placement overrides; anything omitted keeps the default above. */
290
295
  type LayoutOverride = Partial<Record<Role, {
291
296
  cx?: number;
@@ -306,7 +311,7 @@ interface ComposeInput {
306
311
  layout?: LayoutOverride;
307
312
  }
308
313
  interface ComposedLayer {
309
- role: LayerRole;
314
+ role: Role;
310
315
  path: string;
311
316
  /** Size of the placed part itself (the file is always CANVAS x CANVAS). */
312
317
  width: number;
@@ -318,9 +323,8 @@ type ComposeResult = {
318
323
  ok: true;
319
324
  outDir: string;
320
325
  layers: ComposedLayer[];
321
- /** Roles whose optional part was absent from the parts dir — and `nose`
322
- * when the face had no drawn nose to cut. */
323
- skipped: LayerRole[];
326
+ /** Roles whose optional part was absent from the parts dir. */
327
+ skipped: Role[];
324
328
  preview: string;
325
329
  measure: MeasureReport;
326
330
  } | {
package/dist/index.js CHANGED
@@ -708,7 +708,11 @@ async function measureDir(absDir) {
708
708
  }
709
709
  for (const [role, why] of [
710
710
  ["body", "without it the character reads as a floating head on head-turn"],
711
- ["hair_back", "without it the silhouette is flat behind the face"]
711
+ ["hair_back", "without it the silhouette is flat behind the face"],
712
+ [
713
+ "nose",
714
+ "without it nothing on the face slides on the head turn \u2014 the features stay on the plate"
715
+ ]
712
716
  ]) {
713
717
  if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
714
718
  }
@@ -762,13 +766,6 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
762
766
  var EYEWHITE_SRC = "eyewhite.png";
763
767
  var EYE_LASH_LUMA = 120;
764
768
  var LASH_KEEP_FRACTION = 0.5;
765
- var NOSE_INK_TOL = 20;
766
- var NOSE_INK_LOW = 8;
767
- var NOSE_GROW = 2;
768
- var NOSE_MIN_PIXELS = 12;
769
- var NOSE_MAX_CUT_FRACTION = 0.25;
770
- var NOSE_ROW_MIN_PIXELS = 8;
771
- var NOSE_FILL_REACH = 8;
772
769
  var DEFAULT_LAYOUT = {
773
770
  // Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
774
771
  // without them still composes (head-only character).
@@ -778,6 +775,11 @@ var DEFAULT_LAYOUT = {
778
775
  // not a floating head.
779
776
  body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
780
777
  face: { src: "face.png", cx: 550, cy: 475, w: 400 },
778
+ // The nose, drawn on its own (the face is drawn without one): the auto-rig
779
+ // leads the head turn with it and keys the other features' slide on its
780
+ // presence, so without it the features stay on the face plate. Sits between
781
+ // the eyes and above the mouth. OPTIONAL: a parts dir without it composes.
782
+ nose: { src: "nose.png", cx: 550, cy: 586, w: 40, optional: true },
781
783
  mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
782
784
  // Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
783
785
  // auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
@@ -819,6 +821,7 @@ var ORDER = [
819
821
  "hair_back",
820
822
  "body",
821
823
  "face",
824
+ "nose",
822
825
  "mouth",
823
826
  "mouth_open",
824
827
  "eye_L",
@@ -980,164 +983,6 @@ async function prepEyeSplit(partsDir) {
980
983
  lash: await cropToBuffer(lash, W, H, region)
981
984
  };
982
985
  }
983
- function cutNose(rgba, box) {
984
- const W = CANVAS;
985
- const x0 = Math.max(0, box.x0);
986
- const y0 = Math.max(0, box.y0);
987
- const x1 = Math.min(W, box.x1);
988
- const y1 = Math.min(W, box.y1);
989
- if (x1 - x0 < 4 || y1 - y0 < 4) return null;
990
- const bw = x1 - x0;
991
- const bh = y1 - y0;
992
- const at = (x, y) => (y * W + x) * 4;
993
- const median = (v) => v.sort((a, b) => a - b)[v.length >> 1];
994
- const all = [[], [], []];
995
- const rows = [];
996
- for (let y = y0; y < y1; y++) {
997
- const row = [[], [], []];
998
- for (let x = x0; x < x1; x++) {
999
- const i = at(x, y);
1000
- if (rgba[i + 3] === 0) continue;
1001
- for (let c = 0; c < 3; c++) {
1002
- row[c].push(rgba[i + c]);
1003
- all[c].push(rgba[i + c]);
1004
- }
1005
- }
1006
- rows.push(row);
1007
- }
1008
- const opaqueCount = all[0].length;
1009
- if (opaqueCount === 0) return null;
1010
- const skin = all.map(median);
1011
- const skinRow = rows.map(
1012
- (row) => row[0].length < NOSE_ROW_MIN_PIXELS ? skin : row.map(median)
1013
- );
1014
- const distAt = (i, y) => {
1015
- const ref = skinRow[y - y0];
1016
- return Math.max(
1017
- Math.abs(rgba[i] - ref[0]),
1018
- Math.abs(rgba[i + 1] - ref[1]),
1019
- Math.abs(rgba[i + 2] - ref[2])
1020
- );
1021
- };
1022
- const dist = new Uint8Array(bw * bh);
1023
- const ink = new Uint8Array(bw * bh);
1024
- const queue = [];
1025
- let inkCount = 0;
1026
- for (let y = y0; y < y1; y++) {
1027
- for (let x = x0; x < x1; x++) {
1028
- const i = at(x, y);
1029
- if (rgba[i + 3] === 0) continue;
1030
- const d = distAt(i, y);
1031
- const k = (y - y0) * bw + (x - x0);
1032
- dist[k] = d;
1033
- if (d > NOSE_INK_TOL) {
1034
- ink[k] = 1;
1035
- queue.push(k);
1036
- inkCount++;
1037
- }
1038
- }
1039
- }
1040
- if (inkCount < NOSE_MIN_PIXELS) return null;
1041
- while (queue.length > 0) {
1042
- const k = queue.pop();
1043
- const kx = k % bw;
1044
- const ky = (k - kx) / bw;
1045
- for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
1046
- for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
1047
- const nx = kx + dx;
1048
- const ny = ky + dy;
1049
- if (nx < 0 || nx >= bw || ny < 0 || ny >= bh) continue;
1050
- const n = ny * bw + nx;
1051
- if (ink[n] === 0 && dist[n] > NOSE_INK_LOW) {
1052
- ink[n] = 1;
1053
- queue.push(n);
1054
- }
1055
- }
1056
- }
1057
- }
1058
- const cut = new Uint8Array(bw * bh);
1059
- for (let y = 0; y < bh; y++) {
1060
- for (let x = 0; x < bw; x++) {
1061
- if (ink[y * bw + x] === 0) continue;
1062
- for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
1063
- for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
1064
- const yy = y + dy;
1065
- const xx = x + dx;
1066
- if (yy >= 0 && yy < bh && xx >= 0 && xx < bw) cut[yy * bw + xx] = 1;
1067
- }
1068
- }
1069
- }
1070
- }
1071
- let cutCount = 0;
1072
- for (let y = 0; y < bh; y++) {
1073
- for (let x = 0; x < bw; x++) {
1074
- if (cut[y * bw + x] === 0) continue;
1075
- const a = rgba[at(x0 + x, y0 + y) + 3];
1076
- if (a === 0) continue;
1077
- if (a < 255) return null;
1078
- cutCount++;
1079
- }
1080
- }
1081
- if (cutCount > NOSE_MAX_CUT_FRACTION * opaqueCount) return null;
1082
- const face = Buffer.from(rgba);
1083
- const nose = Buffer.from(rgba);
1084
- for (let i = 3; i < nose.length; i += 4) nose[i] = 0;
1085
- let minX = W;
1086
- let minY = W;
1087
- let maxX = -1;
1088
- let maxY = -1;
1089
- for (let y = 0; y < bh; y++) {
1090
- const cy = y0 + y;
1091
- let x = 0;
1092
- while (x < bw) {
1093
- if (cut[y * bw + x] === 0) {
1094
- x++;
1095
- continue;
1096
- }
1097
- const start = x;
1098
- while (x < bw && cut[y * bw + x] === 1) x++;
1099
- const end = x;
1100
- const skinAt = (bx) => {
1101
- for (let step = 0; step < NOSE_FILL_REACH && bx >= 0 && bx < bw; step++) {
1102
- const i = at(x0 + bx, cy);
1103
- if (rgba[i + 3] > 0 && cut[y * bw + bx] === 0) {
1104
- if (distAt(i, cy) <= NOSE_INK_TOL / 2) return i;
1105
- }
1106
- bx += bx < start ? -1 : 1;
1107
- }
1108
- return -1;
1109
- };
1110
- const l = skinAt(start - 1);
1111
- const r = skinAt(end);
1112
- for (let k = start; k < end; k++) {
1113
- const cx = x0 + k;
1114
- const i = at(cx, cy);
1115
- if (rgba[i + 3] === 0) continue;
1116
- const t = (k - start + 1) / (end - start + 1);
1117
- for (let c = 0; c < 3; c++) {
1118
- const rowSkin = skinRow[y];
1119
- const lc = l >= 0 ? rgba[l + c] : r >= 0 ? rgba[r + c] : rowSkin[c];
1120
- const rc = r >= 0 ? rgba[r + c] : l >= 0 ? rgba[l + c] : rowSkin[c];
1121
- face[i + c] = Math.round(lc * (1 - t) + rc * t);
1122
- }
1123
- nose[i] = rgba[i];
1124
- nose[i + 1] = rgba[i + 1];
1125
- nose[i + 2] = rgba[i + 2];
1126
- nose[i + 3] = rgba[i + 3];
1127
- if (cx < minX) minX = cx;
1128
- if (cx > maxX) maxX = cx;
1129
- if (cy < minY) minY = cy;
1130
- if (cy > maxY) maxY = cy;
1131
- }
1132
- }
1133
- }
1134
- if (maxX < 0) return null;
1135
- return {
1136
- face,
1137
- nose,
1138
- bbox: { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 }
1139
- };
1140
- }
1141
986
  async function composeLayersFromParts(input) {
1142
987
  try {
1143
988
  const outDir = resolveOutputDir(input.outDir);
@@ -1156,7 +1001,6 @@ async function composeLayersFromParts(input) {
1156
1001
  const layers = [];
1157
1002
  const skipped = [];
1158
1003
  const preview = [];
1159
- let faceRaw;
1160
1004
  for (const role of ORDER) {
1161
1005
  const cfg = layout[role];
1162
1006
  const part = await partBuffer(
@@ -1171,15 +1015,9 @@ async function composeLayersFromParts(input) {
1171
1015
  continue;
1172
1016
  }
1173
1017
  const { left, top } = placement(role, cfg, part.w, part.h);
1174
- const composed = blankCanvas().composite([
1175
- { input: part.buf, left, top }
1176
- ]);
1018
+ const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
1177
1019
  const outPath = import_node_path4.default.join(outDir, `${role}.png`);
1178
- if (role === "face") {
1179
- faceRaw = await composed.raw().toBuffer();
1180
- } else {
1181
- writeFileAtomic(outPath, await composed.png().toBuffer());
1182
- }
1020
+ writeFileAtomic(outPath, layer);
1183
1021
  layers.push({
1184
1022
  role,
1185
1023
  path: outPath,
@@ -1190,48 +1028,6 @@ async function composeLayersFromParts(input) {
1190
1028
  });
1191
1029
  preview.push({ input: part.buf, left, top });
1192
1030
  }
1193
- const placed = (role) => layers.find((l) => l.role === role);
1194
- const eyeL = placed("eye_L");
1195
- const eyeR = placed("eye_R");
1196
- const mouth = placed("mouth");
1197
- const noseCut = cutNose(faceRaw, {
1198
- x0: eyeR.left + eyeR.width,
1199
- x1: eyeL.left,
1200
- y0: Math.round(
1201
- (eyeL.top + eyeL.height / 2 + eyeR.top + eyeR.height / 2) / 2
1202
- ),
1203
- y1: mouth.top - 2
1204
- });
1205
- const rawCanvas = {
1206
- raw: { width: CANVAS, height: CANVAS, channels: 4 }
1207
- };
1208
- const facePath = import_node_path4.default.join(outDir, "face.png");
1209
- const nosePath = import_node_path4.default.join(outDir, "nose.png");
1210
- if (noseCut === null) {
1211
- writeFileAtomic(
1212
- facePath,
1213
- await (0, import_sharp2.default)(faceRaw, rawCanvas).png().toBuffer()
1214
- );
1215
- import_node_fs3.default.rmSync(nosePath, { force: true });
1216
- skipped.push("nose");
1217
- } else {
1218
- writeFileAtomic(
1219
- facePath,
1220
- await (0, import_sharp2.default)(noseCut.face, rawCanvas).png().toBuffer()
1221
- );
1222
- writeFileAtomic(
1223
- nosePath,
1224
- await (0, import_sharp2.default)(noseCut.nose, rawCanvas).png().toBuffer()
1225
- );
1226
- layers.splice(layers.findIndex((l) => l.role === "face") + 1, 0, {
1227
- role: "nose",
1228
- path: nosePath,
1229
- width: noseCut.bbox.w,
1230
- height: noseCut.bbox.h,
1231
- left: noseCut.bbox.x,
1232
- top: noseCut.bbox.y
1233
- });
1234
- }
1235
1031
  const previewPng = await (0, import_sharp2.default)({
1236
1032
  create: {
1237
1033
  width: CANVAS,
@@ -1261,7 +1057,7 @@ async function composeLayersFromParts(input) {
1261
1057
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1262
1058
  var import_zod = require("zod");
1263
1059
  function createIkiMcpServer() {
1264
- const server = new import_mcp.McpServer({ name: "iki", version: "0.6.0" });
1060
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.7.0" });
1265
1061
  server.registerTool(
1266
1062
  "validate_iki",
1267
1063
  {
@@ -1362,7 +1158,7 @@ function createIkiMcpServer() {
1362
1158
  server.registerTool(
1363
1159
  "compose_layers_from_parts",
1364
1160
  {
1365
- 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).",
1161
+ 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.",
1366
1162
  inputSchema: {
1367
1163
  partsDir: import_zod.z.string().describe(
1368
1164
  "Directory of the source part PNGs (resolved against cwd)."
@@ -1379,7 +1175,7 @@ function createIkiMcpServer() {
1379
1175
  h: import_zod.z.number()
1380
1176
  }).partial()
1381
1177
  ).optional().describe(
1382
- "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)."
1178
+ "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)."
1383
1179
  )
1384
1180
  }
1385
1181
  },