@ikijs/mcp 0.17.2 → 0.19.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 +11 -10
- package/dist/{chunk-CUINYKRG.mjs → chunk-E6DLZPCX.mjs} +326 -83
- package/dist/chunk-E6DLZPCX.mjs.map +1 -0
- package/dist/cli.js +330 -101
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +330 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-CUINYKRG.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -22,29 +22,30 @@ The `model` input for `validate_iki` and `describe_iki` accepts either a plain J
|
|
|
22
22
|
|
|
23
23
|
Turns a set of role-named, full-canvas transparent PNG layers into a renderable, validated `.iki` model with the textures atlased and embedded as a base64 `data:image/png` URI. Under `quantizeColors` a `nose` layer is the exception: the palette rims a soft-shaded nose's feather, so the nose is atlased alone on a second, lossless page. The written model declares the head motions Nod, Shake and Tilt and up to six default expressions (smile, laugh, angry, sad, surprised, shy; `shy` needs a blush, `angry` and `sad` need brows), each with a description a host picks by; with a `blush_L`/`blush_R` layer it also declares `ParamCheek`, which fades the blush from faint at rest to as drawn.
|
|
24
24
|
|
|
25
|
-
- **`layers`** — array of `{ path, fileName? }`. `path` is a PNG file path (resolved against the server's working directory); the role is derived from `fileName ?? basename(path)`. Required roles: `face`, `eye_L`, `eye_R`, `mouth`. Optional roles include `iris_L`/`iris_R`, `brow_L`/`brow_R`, `hair_front`/`hair_back`, `lash_L`/`lash_R`, `lash_lower_L`/`lash_lower_R`, etc. All layers must share the same canvas size (taken from the first layer).
|
|
25
|
+
- **`layers`** — array of `{ path, fileName? }`. `path` is a PNG file path (resolved against the server's working directory); the role is derived from `fileName ?? basename(path)`. Required roles: `face`, `eye_L`, `eye_R`, `mouth`. Optional roles include `iris_L`/`iris_R`, `brow_L`/`brow_R`, `hair_front`/`hair_back`, `lash_L`/`lash_R`, `lash_lower_L`/`lash_lower_R`, `body`, `arm_L`/`arm_R`, etc. An arm — the whole arm drawn hanging, its shoulder at the top — needs the `body` (it hangs from the body's shoulder) and becomes an upper arm and a forearm sharing its crop, on `ParamArmL/R` (the shoulder) and `ParamElbowL/R`. All layers must share the same canvas size (taken from the first layer).
|
|
26
26
|
- **`outputPath`** — optional `.iki` output path (resolved against the working directory; the parent directory must already exist, and the path must end in `.iki`). Defaults to `auto-rigged-model.iki`.
|
|
27
27
|
- **`turnTargets`** — optional head-turn cues to fit the rig to, in the units `measure_turn_reference` reports off a front/turned reference pair: `eyeShift` (plus `noseShift` and `mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width — a **magnitude**, since the rig turns both ways and the sign is the turn's own business; `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest; `silhouetteRatio` the head's half-width turned over at rest. An omitted field leaves that part of the turn at the profile the rig defaults to. An `eyeShift` you pass is fitted by the turn's amount and _clamped_ when it runs past the room the art leaves the far eye — the face plate's edge, or the bangs' side strand over the far iris — since that room is a fact about these layers, not about the reference. Any other target you **do** pass that it cannot reach is refused, because that number is a measurement rather than a preference. A layer set without a `nose` still turns its head, on the profile, but fits no target: `turnTargets` is then inert and the result carries no `turn`.
|
|
28
28
|
- **`style`** — optional per-character tuning from the profile the rig defaults to: `turn` (the whole head turn, the eyes' foreshortening with it, 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` (how far the features lead the face plate, 0..3), `hairFollow` (the front hair's share of the face's turn, 0..2, profile 1), `outlineFollow` (its outer edge's share where it draws the head's outline, 0..2, profile 0: the outline holds), `blink` (how far the upper lid comes down over the eye's height, 0.1..1, profile 0.6) and `sway` (the hair sway amplitude, 0..5). A value out of range, or a knob not named here, is refused.
|
|
29
|
-
- **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: the turn (`eyeShift`, passed or the profile's own) where the face plate's edge or the strand cut it short, and a profile `noseShift` / `mouthShift` past its room. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the art left no room to — always so for a fringe spanning the face — and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `turn` is absent without a `nose` layer. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (unknown/missing role, empty layer, mismatched sizes, bad path,
|
|
29
|
+
- **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: the turn (`eyeShift`, passed or the profile's own) where the face plate's edge or the strand cut it short, and a profile `noseShift` / `mouthShift` past its room. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the art left no room to — always so for a fringe spanning the face — and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `turn` is absent without a `nose` layer. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (unknown/missing role, an arm without a `body`, empty layer, mismatched sizes, bad path, an atlas page over 4096 px on a side, or an atlas over 12 MiB; art the rig cannot build on, such as a body's hips with no room under its pivots for a row line or for the body's motion, or an arm too short to hang an elbow under its shoulder; a `turnTargets` field that is unknown or that this layer set cannot reach — any passed field other than an `eyeShift` past the art's room; a `style` knob out of range or unknown; the message names the field and the attainable range) returns `{ ok: false, error }` with a `INVALID: …` text — not a protocol error. An argument the tool's input schema refuses — a `turnTargets` or `style` that is not an object, or one of their named fields that is not a number — never reaches the tool: the MCP SDK answers with an `isError` result whose text is `MCP error -32602: Input validation error: …`, and no `structuredContent`.
|
|
30
30
|
|
|
31
31
|
The decode/atlas pipeline runs in Node via `sharp` (a native dependency confined to this package); it mirrors the browser editor app's import flow and reuses the pure `@ikijs/editor` model + atlas math, so both paths produce the same rig.
|
|
32
32
|
|
|
33
33
|
### `compose_layers_from_parts`
|
|
34
34
|
|
|
35
|
-
Composes a directory of AI-generated part PNGs into canvas-aligned, role-named layer PNGs ready for `auto_rig_from_layers`, on a
|
|
35
|
+
Composes a directory of AI-generated part PNGs into canvas-aligned, role-named layer PNGs ready for `auto_rig_from_layers`, on a canvas 1100 px wide and `canvasHeight` tall (1100 by default) with a built-in default layout tuned for the character-generation skill's standard front-facing framing. It ports the composer that shipped as a script (`compose.cjs`) in the Claude Code plugin.
|
|
36
36
|
|
|
37
|
-
- **`partsDir`** — directory of the source part PNGs (resolved against the server's working directory). Required sources: `face.png`, `eyewhite.png` (split into the sclera, the upper lash and the lower lid — `lash_lower_L`/`lash_lower_R`, the dark line and lashes of the eye's lower part, which draw over the iris and are placed on the sclera's frame by the `eye_*` layout, so they have no layout key of their own; an eyewhite with no dark lower lid writes none and lists them in `skipped`. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera — the iris's clip — while dark strokes there stay lash ink), `iris.png`, `mouth.png`, `brow.png`, `hair_front.png`. Optional: `hair_back.png`, `body.png`, `mouth_open.png`, `blush.png`, `nose.png` — a parts dir without them still composes, minus those roles. One `blush.png` makes both cheeks' blush: `blush_R` takes it as drawn and `blush_L` mirrored. It is decoration, so the report does not flag a set without it. The nose is what the auto-rig leads the head turn with, and a face supplied alongside it must be drawn without one, or the painted nose stays on the face plate while the real one moves. Each part but the eye pair is cropped to its drawing before it is sized and placed. A faint speck detached from the drawing, one that never reaches alpha 128 and covers under 1 % of the part's pixels (residue a background removal leaves), is cut out with the margin it widened, so it cannot pull the part off its centre. A detached stroke that reaches alpha 128 is kept.
|
|
38
|
-
- **`outDir`** — an existing directory (resolved against the working directory, confined to it exactly like `auto_rig_from_layers`'s `outputPath`; the tool never creates directories) to write the role layer PNGs and a flattened `preview.png` into. Reusing a directory across runs is intentional — a role this run skips
|
|
39
|
-
- **`layout`** — optional per-role override merged over the built-in defaults, e.g. `{ "eye_L": { "cx": 660 } }`, so a character can be retuned by re-running compose rather than editing a script. Each of `cx`, `cy`, `w`, `h` is optional; `w`
|
|
40
|
-
- **`mirrorParts`** — optional list of part files to flip left-right as they are read, e.g. `["eyewhite.png"]`. Which way a part faces is fixed by the layout, and "left eye" cannot pin it down — it reads as the viewer's left or the character's — so in image terms: `eyewhite.png` is read as the eye on the screen left, lash wing (outer corner) at the image's left end and lash-free tear duct at its right; `brow.png` as the brow on the screen right, thick head at the image's left end and tail at its right; `blush.png` as the blush on the screen left, outer end (toward the face's edge) at the image's left end and inner end at its right. A part drawn the other way round is fixed here for free instead of regenerated. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame.
|
|
41
|
-
-
|
|
37
|
+
- **`partsDir`** — directory of the source part PNGs (resolved against the server's working directory). Required sources: `face.png`, `eyewhite.png` (split into the sclera, the upper lash and the lower lid — `lash_lower_L`/`lash_lower_R`, the dark line and lashes of the eye's lower part, which draw over the iris and are placed on the sclera's frame by the `eye_*` layout, so they have no layout key of their own; an eyewhite with no dark lower lid writes none and lists them in `skipped`. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera — the iris's clip — while dark strokes there stay lash ink), `iris.png`, `mouth.png`, `brow.png`, `hair_front.png`. Optional: `hair_back.png`, `body.png`, `mouth_open.png`, `blush.png`, `nose.png` — a parts dir without them still composes, minus those roles. One `blush.png` makes both cheeks' blush: `blush_R` takes it as drawn and `blush_L` mirrored. It is decoration, so the report does not flag a set without it. One `arm.png` — the arm on the screen left, drawn hanging with its shoulder at the top — makes both arms of a full body: `arm_R` takes it as drawn and `arm_L` mirrored, and each is hung on the body's shoulder (see `layout`). The arms are opt-in: a parts dir without `arm.png` composes as a bust does, and `skipped` never lists them. An `arm.png` needs a `body.png`. The nose is what the auto-rig leads the head turn with, and a face supplied alongside it must be drawn without one, or the painted nose stays on the face plate while the real one moves. Each part but the eye pair is cropped to its drawing before it is sized and placed. A faint speck detached from the drawing, one that never reaches alpha 128 and covers under 1 % of the part's pixels (residue a background removal leaves), is cut out with the margin it widened, so it cannot pull the part off its centre. A detached stroke that reaches alpha 128 is kept.
|
|
38
|
+
- **`outDir`** — an existing directory (resolved against the working directory, confined to it exactly like `auto_rig_from_layers`'s `outputPath`; the tool never creates directories) to write the role layer PNGs and a flattened `preview.png` into. Reusing a directory across runs is intentional — a role this run does not write (one it skips, e.g. composing a head-only set that omits `body`, or an arm once `arm.png` is gone) has its stale `<role>.png` from an earlier run deleted, so the directory always holds exactly this run's roles.
|
|
39
|
+
- **`layout`** — optional per-role override merged over the built-in defaults, e.g. `{ "eye_L": { "cx": 660 } }`, so a character can be retuned by re-running compose rather than editing a script. Each of `cx`, `cy`, `w`, `h` is optional; `w` must be an integer in 1..1100 (the canvas width) and `h` in 1..`canvasHeight` (the canvas height). The defaults of the face's features — blush, nose, mouth, `mouth_open`, eyes, irises, lashes, brows — are proportions of the face: an override of `face.cx`, `face.cy` or `face.w` carries them with it (scaled by the width; `face.h` stretches the face alone), while a feature's own override names canvas px. Omitting `h` keeps the part's own aspect ratio, which is what every role wants until one does not: a generated eyewhite often comes back flatter than its reference, and stretching a flat white lens costs nothing where regenerating it is billed and unreliable. The nose is sized and placed by its dense core — its pixels at alpha ≥ 128, the drawing a viewer reads inside a soft nose's feather — rather than its whole part, which for a shaded-bump nose is mostly feather: `w` (default 20) and `h` size the core, `cx` (default 550) centres it, and a set `cy` centres its rows. By default its `cy` is unset, and the core's bottom row (the tip) lands 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. A nose with no pixel at alpha ≥ 128 is sized and placed whole, and so is one whose core is a speck of its trimmed part — under a quarter of its width or height, such as a lone nostril mark or highlight, which sized to `w` would blow the whole nose up — and the report warns of the speck. Set `h` on a sclera and its lash together — they share one frame, and the blink fold tears if they diverge, so a pair set to land on different frames is rejected. `arm_L` and `arm_R` have no `cx`/`cy`/`w` defaults; each is derived from the placed body. An unset `w` is 0.4 of the body's width. An unset `cx` or `cy` hangs the arm's shoulder pivot — the one `auto_rig_from_layers` turns it about, read off the resized arm by the rig's own rule — on the body box's shoulder corner on that axis: its left edge for `arm_R`, its right edge for `arm_L`, 0.12 of its height under its top. On a torso widest at its shoulders, the shoulder cap's centre then sits on the torso's edge. A set one centres the arm as for every other role. Both values are provisional.
|
|
40
|
+
- **`mirrorParts`** — optional list of part files to flip left-right as they are read, e.g. `["eyewhite.png"]`. Which way a part faces is fixed by the layout, and "left eye" cannot pin it down — it reads as the viewer's left or the character's — so in image terms: `eyewhite.png` is read as the eye on the screen left, lash wing (outer corner) at the image's left end and lash-free tear duct at its right; `brow.png` as the brow on the screen right, thick head at the image's left end and tail at its right; `blush.png` as the blush on the screen left, outer end (toward the face's edge) at the image's left end and inner end at its right; `arm.png` as the arm on the screen left (the character's right), hanging, its shoulder at the image's top. A part drawn the other way round is fixed here for free instead of regenerated. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame.
|
|
41
|
+
- **`canvasHeight`** — optional height of the canvas in px: an even integer in 1100..4096, default 1100, a square bust canvas — and at 1100 every output is byte-identical to leaving it out. The width stays 1100. The canvas grows downward: every default and every override keeps its canvas px from the top-left, so the head lands where it does on a bust and a full body gets room below. An odd height is refused, since model space is centred on the canvas and it would put the head on a half pixel. It is checked before any part decodes.
|
|
42
|
+
- **Result** — on success the text is the written layer paths (one per line) followed by the same geometry report `measure_layers` returns — except that when the composer found the core of the nose's source part a speck, its nose check reports that verdict instead of what the composed file shows, so a speck that resampling erased from the layer is warned about here and not by `measure_layers`. `structuredContent` is `{ ok: true, outDir, layers, skipped, preview, measure }`. Invalid input (a missing required part, a `canvasHeight` that is odd or outside 1100..4096, an unknown `layout` role, an out-of-range `w` or `h`, a lash placed on a different frame from its sclera's, an `arm.png` without a `body.png`, an arm too short for the rig to hang an elbow under its shoulder, a `mirrorParts` entry that is not a part file, a part that lands entirely off-canvas, a non-existent `outDir`) returns `{ ok: false, error }` with `INVALID: …` text.
|
|
42
43
|
|
|
43
44
|
### `measure_layers`
|
|
44
45
|
|
|
45
|
-
Reports the same read-only geometry checks `compose_layers_from_parts` returns inline (iris size/offset relative to the sclera, eye aspect, an eye drawn facing the other way, cropped or flat-cut edges, a nose whose dense core is a speck of its crop, missing optional roles), over an already-composed layers directory — for re-checking a layers dir without recomposing it. Its nose check reads the composed file against its crop, which is what `auto_rig_from_layers` acts on: a speck core there is one the rig does not turn or tilt the nose about. The composer's inline report does the same unless it found the source part's core a speck, which it reports instead, so a speck that resampling erased from the layer shows there and not here.
|
|
46
|
+
Reports the same read-only geometry checks `compose_layers_from_parts` returns inline (iris size/offset relative to the sclera, eye aspect, an eye drawn facing the other way, cropped or flat-cut edges, a nose whose dense core is a speck of its crop, missing optional roles, and for a full body: a body whose feet the bottom of a canvas taller than wide cuts off, an arm without a body, and an arm whose shoulder cap — the one `auto_rig_from_layers` turns it about, read by the rig's own rule — does not reach half its radius under the torso's edge on its shoulder pivot's row), over an already-composed layers directory — for re-checking a layers dir without recomposing it. Its nose check reads the composed file against its crop, which is what `auto_rig_from_layers` acts on: a speck core there is one the rig does not turn or tilt the nose about. The composer's inline report does the same unless it found the source part's core a speck, which it reports instead, so a speck that resampling erased from the layer shows there and not here.
|
|
46
47
|
|
|
47
|
-
- **`layersDir`** — directory of role-named layer PNGs (resolved against the working directory).
|
|
48
|
+
- **`layersDir`** — directory of role-named layer PNGs (resolved against the working directory). Every `preview*.png` in it is skipped.
|
|
48
49
|
- **Result** — the text is the report: a per-layer size/bbox-centre/mass-centre/margins table, then the checks that fired. `structuredContent` is `{ ok: true, layersDir, layers, empty, warnings, passed }`. A missing or non-directory `layersDir` returns `{ ok: false, error }` with `INVALID: …` text.
|
|
49
50
|
|
|
50
51
|
### `measure_turn_reference`
|