@ikijs/mcp 0.12.0 → 0.13.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/README.md +2 -2
- package/dist/{chunk-RMB5YVBU.mjs → chunk-4EW6OSEC.mjs} +113 -8
- package/dist/chunk-4EW6OSEC.mjs.map +1 -0
- package/dist/cli.js +112 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +112 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-RMB5YVBU.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -570,6 +570,7 @@ async function autoRigFromLayers(input) {
|
|
|
570
570
|
var import_node_fs3 = __toESM(require("fs"));
|
|
571
571
|
var import_node_path5 = __toESM(require("path"));
|
|
572
572
|
var import_sharp2 = __toESM(require("sharp"));
|
|
573
|
+
var import_editor5 = require("@ikijs/editor");
|
|
573
574
|
|
|
574
575
|
// src/measure.ts
|
|
575
576
|
var import_node_fs2 = __toESM(require("fs"));
|
|
@@ -1163,7 +1164,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1163
1164
|
["hair_back", "without it the silhouette is flat behind the face"],
|
|
1164
1165
|
[
|
|
1165
1166
|
"nose",
|
|
1166
|
-
"without it
|
|
1167
|
+
"without it the head still turns on the Live2D profile, but there is no nose to lead it, and no turn fit to the art (`turnTargets` is inert, no `turn` report)"
|
|
1167
1168
|
]
|
|
1168
1169
|
]) {
|
|
1169
1170
|
if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
|
|
@@ -1227,6 +1228,19 @@ var DEFAULT_LAYOUT = {
|
|
|
1227
1228
|
// floating head. It rides its own `bodyDeformer`, which only breathes.
|
|
1228
1229
|
body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
|
|
1229
1230
|
face: { src: "face.png", cx: 550, cy: 475, w: 400 },
|
|
1231
|
+
// The cheek blush, one part for both cheeks: blush_R (screen left) takes it
|
|
1232
|
+
// as drawn and blush_L mirrors it, like the eyewhite. It draws over the face
|
|
1233
|
+
// and under the nose. Its box sits below each eye, centred just outside the
|
|
1234
|
+
// eye's centre and above the nose tip. Tuned on the hero's face at its
|
|
1235
|
+
// default placement, which narrows fast below the eye row: a 96-wide box at
|
|
1236
|
+
// row 552 ran up to 24 px past the cheek's drawn outline (inside the ears),
|
|
1237
|
+
// and this one, for a 2:1 blush, stays inside it by 1 px at its lower outer
|
|
1238
|
+
// corner. OPTIONAL, and decoration: a parts dir without it composes, and
|
|
1239
|
+
// nothing reports it missing.
|
|
1240
|
+
blush_L: { src: "blush.png", cx: 662, cy: 530, w: 56, optional: true, mirror: true },
|
|
1241
|
+
// prettier-ignore
|
|
1242
|
+
blush_R: { src: "blush.png", cx: 438, cy: 530, w: 56, optional: true, mirror: false },
|
|
1243
|
+
// prettier-ignore
|
|
1230
1244
|
// The nose, drawn on its own (the face is drawn without one): the auto-rig
|
|
1231
1245
|
// leads the head turn with it and keys the other features' slide on its
|
|
1232
1246
|
// presence, so without it the features stay on the face plate. `w` is the
|
|
@@ -1275,6 +1289,8 @@ var ORDER = [
|
|
|
1275
1289
|
"hair_back",
|
|
1276
1290
|
"body",
|
|
1277
1291
|
"face",
|
|
1292
|
+
"blush_L",
|
|
1293
|
+
"blush_R",
|
|
1278
1294
|
"nose",
|
|
1279
1295
|
"mouth",
|
|
1280
1296
|
"mouth_open",
|
|
@@ -1458,6 +1474,94 @@ function blankCanvas() {
|
|
|
1458
1474
|
}
|
|
1459
1475
|
});
|
|
1460
1476
|
}
|
|
1477
|
+
function luma(rgba, i) {
|
|
1478
|
+
return 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2];
|
|
1479
|
+
}
|
|
1480
|
+
function detachedAboveWhite(rgba, W, H) {
|
|
1481
|
+
const n = W * H;
|
|
1482
|
+
const ink = new Uint8Array(n);
|
|
1483
|
+
for (let p = 0; p < n; p++) {
|
|
1484
|
+
const alpha = rgba[p * 4 + 3];
|
|
1485
|
+
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
1486
|
+
ink[p] = alpha >= import_editor5.ALPHA_OPAQUE ? 2 : 1;
|
|
1487
|
+
}
|
|
1488
|
+
const label = new Int32Array(n).fill(-1);
|
|
1489
|
+
const stack = new Int32Array(n);
|
|
1490
|
+
const near = (p, visit) => {
|
|
1491
|
+
const px = p % W;
|
|
1492
|
+
const py = (p - px) / W;
|
|
1493
|
+
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1494
|
+
for (let x = Math.max(0, px - 1); x <= Math.min(W - 1, px + 1); x++) {
|
|
1495
|
+
visit(y * W + x);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
const sizes = [];
|
|
1500
|
+
const fill = (start) => {
|
|
1501
|
+
const id = sizes.length;
|
|
1502
|
+
let size = 0;
|
|
1503
|
+
let depth = 0;
|
|
1504
|
+
label[start] = id;
|
|
1505
|
+
stack[depth++] = start;
|
|
1506
|
+
while (depth > 0) {
|
|
1507
|
+
const p = stack[--depth];
|
|
1508
|
+
size++;
|
|
1509
|
+
near(p, (q) => {
|
|
1510
|
+
if (ink[q] === ink[start] && label[q] === -1) {
|
|
1511
|
+
label[q] = id;
|
|
1512
|
+
stack[depth++] = q;
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
sizes.push(size);
|
|
1517
|
+
};
|
|
1518
|
+
for (let p = 0; p < n; p++) if (ink[p] === 2 && label[p] === -1) fill(p);
|
|
1519
|
+
const paintedSets = sizes.length;
|
|
1520
|
+
let head = 0;
|
|
1521
|
+
let tail = 0;
|
|
1522
|
+
for (let p = 0; p < n; p++) if (ink[p] === 2) stack[tail++] = p;
|
|
1523
|
+
while (head < tail) {
|
|
1524
|
+
const p = stack[head++];
|
|
1525
|
+
near(p, (q) => {
|
|
1526
|
+
if (ink[q] === 1 && label[q] === -1 && rgba[q * 4 + 3] <= rgba[p * 4 + 3]) {
|
|
1527
|
+
label[q] = label[p];
|
|
1528
|
+
stack[tail++] = q;
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
for (let p = 0; p < n; p++) if (ink[p] === 1 && label[p] === -1) fill(p);
|
|
1533
|
+
const detached = new Uint8Array(n);
|
|
1534
|
+
if (paintedSets === 0 || sizes.length < 2) return detached;
|
|
1535
|
+
let white = 0;
|
|
1536
|
+
for (let id = 1; id < paintedSets; id++) {
|
|
1537
|
+
if (sizes[id] > sizes[white]) white = id;
|
|
1538
|
+
}
|
|
1539
|
+
const own = (p) => ink[p] === 2 || label[p] >= paintedSets;
|
|
1540
|
+
const whiteTop = new Int32Array(W).fill(-1);
|
|
1541
|
+
for (let p = 0; p < n; p++) {
|
|
1542
|
+
const x = p % W;
|
|
1543
|
+
if (label[p] === white && own(p) && whiteTop[x] === -1)
|
|
1544
|
+
whiteTop[x] = (p - x) / W;
|
|
1545
|
+
}
|
|
1546
|
+
let first = 0;
|
|
1547
|
+
while (whiteTop[first] === -1) first++;
|
|
1548
|
+
let last = W - 1;
|
|
1549
|
+
while (whiteTop[last] === -1) last--;
|
|
1550
|
+
whiteTop.fill(whiteTop[first], 0, first);
|
|
1551
|
+
whiteTop.fill(whiteTop[last], last + 1);
|
|
1552
|
+
const above = new Uint8Array(sizes.length).fill(1);
|
|
1553
|
+
for (let p = 0; p < n; p++) {
|
|
1554
|
+
const id = label[p];
|
|
1555
|
+
if (id === -1 || id === white || !own(p)) continue;
|
|
1556
|
+
const x = p % W;
|
|
1557
|
+
if ((p - x) / W >= whiteTop[x]) above[id] = 0;
|
|
1558
|
+
}
|
|
1559
|
+
for (let p = 0; p < n; p++) {
|
|
1560
|
+
const id = label[p];
|
|
1561
|
+
if (id !== -1 && id !== white && above[id]) detached[p] = 1;
|
|
1562
|
+
}
|
|
1563
|
+
return detached;
|
|
1564
|
+
}
|
|
1461
1565
|
async function prepEyeSplit(partsDir) {
|
|
1462
1566
|
const srcPath = import_node_path5.default.join(partsDir, EYEWHITE_SRC);
|
|
1463
1567
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
@@ -1482,14 +1586,15 @@ async function prepEyeSplit(partsDir) {
|
|
|
1482
1586
|
throw new AutoRigInputError(`eyewhite is fully transparent: ${srcPath}`);
|
|
1483
1587
|
}
|
|
1484
1588
|
const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
|
|
1589
|
+
const detached = detachedAboveWhite(data, W, H);
|
|
1485
1590
|
const sclera = Buffer.from(data);
|
|
1486
1591
|
const lash = Buffer.from(data);
|
|
1487
1592
|
for (let y = 0; y < H; y++) {
|
|
1488
1593
|
for (let x = 0; x < W; x++) {
|
|
1489
1594
|
const i = (y * W + x) * 4;
|
|
1490
|
-
const
|
|
1491
|
-
const isDark = data[i + 3] > 0 && lum < EYE_LASH_LUMA;
|
|
1595
|
+
const isDark = data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
|
|
1492
1596
|
if (isDark) sclera[i] = sclera[i + 1] = sclera[i + 2] = 255;
|
|
1597
|
+
if (detached[y * W + x]) sclera[i + 3] = 0;
|
|
1493
1598
|
if (!(isDark && y <= lashCutoffY)) lash[i + 3] = 0;
|
|
1494
1599
|
}
|
|
1495
1600
|
}
|
|
@@ -1605,7 +1710,7 @@ async function composeLayersFromParts(input) {
|
|
|
1605
1710
|
|
|
1606
1711
|
// src/server.ts
|
|
1607
1712
|
function createIkiMcpServer() {
|
|
1608
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1713
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.13.0" });
|
|
1609
1714
|
server.registerTool(
|
|
1610
1715
|
"validate_iki",
|
|
1611
1716
|
{
|
|
@@ -1725,7 +1830,7 @@ function createIkiMcpServer() {
|
|
|
1725
1830
|
server.registerTool(
|
|
1726
1831
|
"compose_layers_from_parts",
|
|
1727
1832
|
{
|
|
1728
|
-
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
|
|
1833
|
+
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, blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's Live2D 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). 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.",
|
|
1729
1834
|
inputSchema: {
|
|
1730
1835
|
partsDir: import_zod.z.string().describe(
|
|
1731
1836
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
@@ -1742,10 +1847,10 @@ function createIkiMcpServer() {
|
|
|
1742
1847
|
h: import_zod.z.number()
|
|
1743
1848
|
}).partial()
|
|
1744
1849
|
).optional().describe(
|
|
1745
|
-
"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. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. 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."
|
|
1850
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, blush_L, blush_R, 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. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. 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."
|
|
1746
1851
|
),
|
|
1747
1852
|
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
1748
|
-
"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)
|
|
1853
|
+
"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), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), and blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end 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."
|
|
1749
1854
|
)
|
|
1750
1855
|
}
|
|
1751
1856
|
},
|