@ikijs/mcp 0.6.0 → 0.8.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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createIkiMcpServer
4
- } from "./chunk-JTK6HWKT.mjs";
4
+ } from "./chunk-JPWDKP43.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { TurnTargets, TurnSolveReport } from '@ikijs/editor';
2
+ export { TurnSolveReport } from '@ikijs/editor';
1
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
4
 
3
5
  type ValidateResult = {
@@ -66,7 +68,14 @@ interface AutoRigInput {
66
68
  /** Palette-quantize the atlas PNG to this many colours (integer, 2..256).
67
69
  * Omitted = lossless. See renderAtlasToDataUri for the size/quality trade. */
68
70
  quantizeColors?: number;
71
+ /** Head-turn cues to fit the rig to, as `measure_turn_reference` reports
72
+ * them. */
73
+ turnTargets?: AutoRigTurnTargets;
69
74
  }
75
+ /** The turn cues a caller may pass, which is every one but `headHalfWidth`:
76
+ * the pixels the shift fractions are fractions of are measured off the layers
77
+ * themselves, not accepted from the caller. */
78
+ type AutoRigTurnTargets = Omit<TurnTargets, "headHalfWidth">;
70
79
  type AutoRigResult = {
71
80
  ok: true;
72
81
  path: string;
@@ -76,15 +85,52 @@ type AutoRigResult = {
76
85
  };
77
86
  partCount: number;
78
87
  atlasBytes: number;
88
+ /** The head's half-width at the eye row, measured off the layers.
89
+ * Absent when the opaque (alpha >= 128) union has no span there — a
90
+ * layer set painted translucent below that threshold — in which case
91
+ * the face plate stands in for it, same as a span that measures
92
+ * narrower than the plate. */
93
+ headHalfWidth?: number;
94
+ /** Whether the measured value was handed to the generator; the
95
+ * face-half fallback applies otherwise, which is what happens when it
96
+ * is no wider than the face plate, or absent entirely. */
97
+ headHalfWidthApplied: boolean;
98
+ /** Every role with an opaque pixel in the same eye-row band as
99
+ * `headHalfWidth`, per side, each with its own rest x there (canvas px)
100
+ * — present only when `headHalfWidthApplied` is true, since the
101
+ * fallback path has no measured edge to report at all. Passed to the
102
+ * generator so it can land each candidate through its OWN deformation
103
+ * (hair_front's, the back hair's, a faceWarp/body role's, or — for
104
+ * anything else — rigid with the head) and take the outermost
105
+ * LANDING, not just the outermost REST pixel. */
106
+ headEdges?: {
107
+ left: {
108
+ role: string;
109
+ x: number;
110
+ }[];
111
+ right: {
112
+ role: string;
113
+ x: number;
114
+ }[];
115
+ };
116
+ /** What the turn solve settled on — the cues the rig reaches and the
117
+ * defaulted targets it had to cut down. Absent for a layer set with no
118
+ * nose, which solves no turn at all. */
119
+ turn?: TurnSolveReport;
79
120
  } | {
80
121
  ok: false;
81
122
  error: string;
82
123
  };
124
+
83
125
  /**
84
126
  * Decode role-named PNG file paths, auto-rig a model from them, atlas + embed
85
127
  * the textures (Node sharp), validate, and write the renderable `.iki` to disk.
86
128
  * Returns the output path + summary stats (the multi-MB model is never inlined).
87
129
  *
130
+ * The head turn is fitted to `input.turnTargets`, on the head half-width this
131
+ * measures off the layers themselves; what the solve settled on comes back in
132
+ * `turn`.
133
+ *
88
134
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
89
135
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
90
136
  * model math is reused from @ikijs/editor.
@@ -203,6 +249,13 @@ declare const DEFAULT_LAYOUT: {
203
249
  cy: number;
204
250
  w: number;
205
251
  };
252
+ nose: {
253
+ src: string;
254
+ cx: number;
255
+ cy: number;
256
+ w: number;
257
+ optional: true;
258
+ };
206
259
  mouth: {
207
260
  src: string;
208
261
  cx: number;
@@ -284,8 +337,6 @@ declare const DEFAULT_LAYOUT: {
284
337
  };
285
338
  };
286
339
  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
340
  /** Per-role placement overrides; anything omitted keeps the default above. */
290
341
  type LayoutOverride = Partial<Record<Role, {
291
342
  cx?: number;
@@ -306,7 +357,7 @@ interface ComposeInput {
306
357
  layout?: LayoutOverride;
307
358
  }
308
359
  interface ComposedLayer {
309
- role: LayerRole;
360
+ role: Role;
310
361
  path: string;
311
362
  /** Size of the placed part itself (the file is always CANVAS x CANVAS). */
312
363
  width: number;
@@ -318,9 +369,8 @@ type ComposeResult = {
318
369
  ok: true;
319
370
  outDir: string;
320
371
  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[];
372
+ /** Roles whose optional part was absent from the parts dir. */
373
+ skipped: Role[];
324
374
  preview: string;
325
375
  measure: MeasureReport;
326
376
  } | {
@@ -336,6 +386,122 @@ type ComposeResult = {
336
386
  */
337
387
  declare function composeLayersFromParts(input: ComposeInput): Promise<ComposeResult>;
338
388
 
389
+ /**
390
+ * Measure the head-turn cues in a PAIR of images of the same character — one
391
+ * facing front, one turned — and report them as three ratios. It is how a
392
+ * rigged turn gets compared to a reference turn without either image being
393
+ * registered to the other: every number below is a front→turned CHANGE,
394
+ * divided by something measured in the same image. That cancels crop and
395
+ * position, not SCALE: the head span is sampled over a FIXED ±HEAD_BAND row
396
+ * band, so a pair at different resolutions — or a character redrawn larger or
397
+ * smaller between the two shots — would read as a turn that never happened.
398
+ * The pair MUST already share framing and head size; this only checks it, it
399
+ * does not correct for it. The check is a yaw does not change iris HEIGHT, so
400
+ * a front/turned pair whose mean iris height differs is refused rather than
401
+ * measured (see `measureTurnReference`).
402
+ *
403
+ * farEyeRatio how much the far eye narrows, over what it already was at
404
+ * rest (a resting asymmetry in the art is divided out)
405
+ * eyeShift how far the eye pair slides across the head, in units of
406
+ * the FRONT head half-width (hh); negative = toward the
407
+ * image's left
408
+ * silhouetteRatio how much the head narrows, turned over front
409
+ *
410
+ * Read-only over two files; it edits nothing. Ported from the measurement
411
+ * script this repo's turn work ran by hand, so the numbers a rig is tuned
412
+ * against come out of the server every agent already has.
413
+ *
414
+ * `sharp` must stay confined to @ikijs/mcp; the decode and the debug-overlay
415
+ * encode both go through ./node-images, this package's single image boundary.
416
+ */
417
+ /**
418
+ * Hue/saturation window that selects the iris. Anime irises are a saturated
419
+ * colour on a face that is not, which is what makes them findable at all; the
420
+ * default window is violet-to-blue because that is what the characters this was
421
+ * tuned on have. A character with, say, amber eyes passes its own window.
422
+ */
423
+ interface IrisColor {
424
+ /** Inclusive hue bounds in degrees (0..360). */
425
+ hueMin: number;
426
+ hueMax: number;
427
+ /** Minimum HSV saturation (0..1) — separates the iris from the skin. */
428
+ satMin: number;
429
+ }
430
+ /** Connected blob of iris-coloured pixels, in image px. */
431
+ interface IrisBlob {
432
+ x0: number;
433
+ y0: number;
434
+ x1: number;
435
+ y1: number;
436
+ w: number;
437
+ h: number;
438
+ area: number;
439
+ cx: number;
440
+ cy: number;
441
+ }
442
+ /** One image's measurement. `irisL`/`irisR` are ordered by x in the IMAGE. */
443
+ interface TurnImageMeasure {
444
+ file: string;
445
+ width: number;
446
+ height: number;
447
+ maskMode: "alpha" | "keyed";
448
+ irisL: IrisBlob;
449
+ irisR: IrisBlob;
450
+ /** Mean row of the two iris centres. */
451
+ eyeRow: number;
452
+ /** Head silhouette span at the eye row. */
453
+ head: {
454
+ left: number;
455
+ right: number;
456
+ cx: number;
457
+ half: number;
458
+ };
459
+ /** Mean column of the two iris centres. */
460
+ pairCx: number;
461
+ eyeGap: number;
462
+ }
463
+ interface TurnMeasurement {
464
+ front: TurnImageMeasure;
465
+ turned: TurnImageMeasure;
466
+ /** Turned far/near iris width over the same ratio at rest. */
467
+ farEyeRatio: number;
468
+ /** Front→turned slide of the eye pair across the head, in FRONT hh units. */
469
+ eyeShift: number;
470
+ /** Head half-width, turned over front. */
471
+ silhouetteRatio: number;
472
+ /** -1 = the head turned toward the image's left, +1 = toward its right. */
473
+ turnSign: -1 | 1;
474
+ /** Debug overlays written, when `debugDir` was given. */
475
+ debug?: string[];
476
+ }
477
+ type MeasureTurnResult = ({
478
+ ok: true;
479
+ } & TurnMeasurement) | {
480
+ ok: false;
481
+ error: string;
482
+ };
483
+ interface MeasureTurnInput {
484
+ /** Front-facing image (relative paths resolve against cwd). */
485
+ front: string;
486
+ /** The same character turned. */
487
+ turned: string;
488
+ /** Iris colour window override, merged over the violet default. */
489
+ iris?: Partial<IrisColor>;
490
+ /** Existing directory to write `<name>.debug.png` overlays into. */
491
+ debugDir?: string;
492
+ }
493
+ /**
494
+ * Measure a front/turned image pair and report the three turn ratios plus both
495
+ * raw per-image measurements.
496
+ *
497
+ * Error boundary: ONLY AutoRigInputError (caller input / filesystem) →
498
+ * `{ ok:false }`, matching measureLayers; any other throw propagates.
499
+ */
500
+ declare function measureTurnReference(input: MeasureTurnInput): Promise<MeasureTurnResult>;
501
+ /** Render a measurement as plain text: the three ratios with the raw numbers
502
+ * behind each, then one block per image. */
503
+ declare function formatTurnReport(result: TurnMeasurement): string;
504
+
339
505
  declare function createIkiMcpServer(): McpServer;
340
506
 
341
- export { type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type ComposeInput, type ComposeResult, type DeformerSummary, type DescribeResult, type IkiSummary, type LayoutOverride, type MeasureInput, type MeasureResult, type StandardParameterInfo, type ValidateResult, autoRigFromLayers, composeLayersFromParts, createIkiMcpServer, describeIki, formatMeasureReport, listStandardParameters, measureLayers, validateIki };
507
+ export { type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type AutoRigTurnTargets, type ComposeInput, type ComposeResult, type DeformerSummary, type DescribeResult, type IkiSummary, type IrisBlob, type IrisColor, type LayoutOverride, type MeasureInput, type MeasureResult, type MeasureTurnInput, type MeasureTurnResult, type StandardParameterInfo, type TurnImageMeasure, type TurnMeasurement, type ValidateResult, autoRigFromLayers, composeLayersFromParts, createIkiMcpServer, describeIki, formatMeasureReport, formatTurnReport, listStandardParameters, measureLayers, measureTurnReference, validateIki };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { TurnTargets, TurnSolveReport } from '@ikijs/editor';
2
+ export { TurnSolveReport } from '@ikijs/editor';
1
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
4
 
3
5
  type ValidateResult = {
@@ -66,7 +68,14 @@ interface AutoRigInput {
66
68
  /** Palette-quantize the atlas PNG to this many colours (integer, 2..256).
67
69
  * Omitted = lossless. See renderAtlasToDataUri for the size/quality trade. */
68
70
  quantizeColors?: number;
71
+ /** Head-turn cues to fit the rig to, as `measure_turn_reference` reports
72
+ * them. */
73
+ turnTargets?: AutoRigTurnTargets;
69
74
  }
75
+ /** The turn cues a caller may pass, which is every one but `headHalfWidth`:
76
+ * the pixels the shift fractions are fractions of are measured off the layers
77
+ * themselves, not accepted from the caller. */
78
+ type AutoRigTurnTargets = Omit<TurnTargets, "headHalfWidth">;
70
79
  type AutoRigResult = {
71
80
  ok: true;
72
81
  path: string;
@@ -76,15 +85,52 @@ type AutoRigResult = {
76
85
  };
77
86
  partCount: number;
78
87
  atlasBytes: number;
88
+ /** The head's half-width at the eye row, measured off the layers.
89
+ * Absent when the opaque (alpha >= 128) union has no span there — a
90
+ * layer set painted translucent below that threshold — in which case
91
+ * the face plate stands in for it, same as a span that measures
92
+ * narrower than the plate. */
93
+ headHalfWidth?: number;
94
+ /** Whether the measured value was handed to the generator; the
95
+ * face-half fallback applies otherwise, which is what happens when it
96
+ * is no wider than the face plate, or absent entirely. */
97
+ headHalfWidthApplied: boolean;
98
+ /** Every role with an opaque pixel in the same eye-row band as
99
+ * `headHalfWidth`, per side, each with its own rest x there (canvas px)
100
+ * — present only when `headHalfWidthApplied` is true, since the
101
+ * fallback path has no measured edge to report at all. Passed to the
102
+ * generator so it can land each candidate through its OWN deformation
103
+ * (hair_front's, the back hair's, a faceWarp/body role's, or — for
104
+ * anything else — rigid with the head) and take the outermost
105
+ * LANDING, not just the outermost REST pixel. */
106
+ headEdges?: {
107
+ left: {
108
+ role: string;
109
+ x: number;
110
+ }[];
111
+ right: {
112
+ role: string;
113
+ x: number;
114
+ }[];
115
+ };
116
+ /** What the turn solve settled on — the cues the rig reaches and the
117
+ * defaulted targets it had to cut down. Absent for a layer set with no
118
+ * nose, which solves no turn at all. */
119
+ turn?: TurnSolveReport;
79
120
  } | {
80
121
  ok: false;
81
122
  error: string;
82
123
  };
124
+
83
125
  /**
84
126
  * Decode role-named PNG file paths, auto-rig a model from them, atlas + embed
85
127
  * the textures (Node sharp), validate, and write the renderable `.iki` to disk.
86
128
  * Returns the output path + summary stats (the multi-MB model is never inlined).
87
129
  *
130
+ * The head turn is fitted to `input.turnTargets`, on the head half-width this
131
+ * measures off the layers themselves; what the solve settled on comes back in
132
+ * `turn`.
133
+ *
88
134
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
89
135
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
90
136
  * model math is reused from @ikijs/editor.
@@ -203,6 +249,13 @@ declare const DEFAULT_LAYOUT: {
203
249
  cy: number;
204
250
  w: number;
205
251
  };
252
+ nose: {
253
+ src: string;
254
+ cx: number;
255
+ cy: number;
256
+ w: number;
257
+ optional: true;
258
+ };
206
259
  mouth: {
207
260
  src: string;
208
261
  cx: number;
@@ -284,8 +337,6 @@ declare const DEFAULT_LAYOUT: {
284
337
  };
285
338
  };
286
339
  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
340
  /** Per-role placement overrides; anything omitted keeps the default above. */
290
341
  type LayoutOverride = Partial<Record<Role, {
291
342
  cx?: number;
@@ -306,7 +357,7 @@ interface ComposeInput {
306
357
  layout?: LayoutOverride;
307
358
  }
308
359
  interface ComposedLayer {
309
- role: LayerRole;
360
+ role: Role;
310
361
  path: string;
311
362
  /** Size of the placed part itself (the file is always CANVAS x CANVAS). */
312
363
  width: number;
@@ -318,9 +369,8 @@ type ComposeResult = {
318
369
  ok: true;
319
370
  outDir: string;
320
371
  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[];
372
+ /** Roles whose optional part was absent from the parts dir. */
373
+ skipped: Role[];
324
374
  preview: string;
325
375
  measure: MeasureReport;
326
376
  } | {
@@ -336,6 +386,122 @@ type ComposeResult = {
336
386
  */
337
387
  declare function composeLayersFromParts(input: ComposeInput): Promise<ComposeResult>;
338
388
 
389
+ /**
390
+ * Measure the head-turn cues in a PAIR of images of the same character — one
391
+ * facing front, one turned — and report them as three ratios. It is how a
392
+ * rigged turn gets compared to a reference turn without either image being
393
+ * registered to the other: every number below is a front→turned CHANGE,
394
+ * divided by something measured in the same image. That cancels crop and
395
+ * position, not SCALE: the head span is sampled over a FIXED ±HEAD_BAND row
396
+ * band, so a pair at different resolutions — or a character redrawn larger or
397
+ * smaller between the two shots — would read as a turn that never happened.
398
+ * The pair MUST already share framing and head size; this only checks it, it
399
+ * does not correct for it. The check is a yaw does not change iris HEIGHT, so
400
+ * a front/turned pair whose mean iris height differs is refused rather than
401
+ * measured (see `measureTurnReference`).
402
+ *
403
+ * farEyeRatio how much the far eye narrows, over what it already was at
404
+ * rest (a resting asymmetry in the art is divided out)
405
+ * eyeShift how far the eye pair slides across the head, in units of
406
+ * the FRONT head half-width (hh); negative = toward the
407
+ * image's left
408
+ * silhouetteRatio how much the head narrows, turned over front
409
+ *
410
+ * Read-only over two files; it edits nothing. Ported from the measurement
411
+ * script this repo's turn work ran by hand, so the numbers a rig is tuned
412
+ * against come out of the server every agent already has.
413
+ *
414
+ * `sharp` must stay confined to @ikijs/mcp; the decode and the debug-overlay
415
+ * encode both go through ./node-images, this package's single image boundary.
416
+ */
417
+ /**
418
+ * Hue/saturation window that selects the iris. Anime irises are a saturated
419
+ * colour on a face that is not, which is what makes them findable at all; the
420
+ * default window is violet-to-blue because that is what the characters this was
421
+ * tuned on have. A character with, say, amber eyes passes its own window.
422
+ */
423
+ interface IrisColor {
424
+ /** Inclusive hue bounds in degrees (0..360). */
425
+ hueMin: number;
426
+ hueMax: number;
427
+ /** Minimum HSV saturation (0..1) — separates the iris from the skin. */
428
+ satMin: number;
429
+ }
430
+ /** Connected blob of iris-coloured pixels, in image px. */
431
+ interface IrisBlob {
432
+ x0: number;
433
+ y0: number;
434
+ x1: number;
435
+ y1: number;
436
+ w: number;
437
+ h: number;
438
+ area: number;
439
+ cx: number;
440
+ cy: number;
441
+ }
442
+ /** One image's measurement. `irisL`/`irisR` are ordered by x in the IMAGE. */
443
+ interface TurnImageMeasure {
444
+ file: string;
445
+ width: number;
446
+ height: number;
447
+ maskMode: "alpha" | "keyed";
448
+ irisL: IrisBlob;
449
+ irisR: IrisBlob;
450
+ /** Mean row of the two iris centres. */
451
+ eyeRow: number;
452
+ /** Head silhouette span at the eye row. */
453
+ head: {
454
+ left: number;
455
+ right: number;
456
+ cx: number;
457
+ half: number;
458
+ };
459
+ /** Mean column of the two iris centres. */
460
+ pairCx: number;
461
+ eyeGap: number;
462
+ }
463
+ interface TurnMeasurement {
464
+ front: TurnImageMeasure;
465
+ turned: TurnImageMeasure;
466
+ /** Turned far/near iris width over the same ratio at rest. */
467
+ farEyeRatio: number;
468
+ /** Front→turned slide of the eye pair across the head, in FRONT hh units. */
469
+ eyeShift: number;
470
+ /** Head half-width, turned over front. */
471
+ silhouetteRatio: number;
472
+ /** -1 = the head turned toward the image's left, +1 = toward its right. */
473
+ turnSign: -1 | 1;
474
+ /** Debug overlays written, when `debugDir` was given. */
475
+ debug?: string[];
476
+ }
477
+ type MeasureTurnResult = ({
478
+ ok: true;
479
+ } & TurnMeasurement) | {
480
+ ok: false;
481
+ error: string;
482
+ };
483
+ interface MeasureTurnInput {
484
+ /** Front-facing image (relative paths resolve against cwd). */
485
+ front: string;
486
+ /** The same character turned. */
487
+ turned: string;
488
+ /** Iris colour window override, merged over the violet default. */
489
+ iris?: Partial<IrisColor>;
490
+ /** Existing directory to write `<name>.debug.png` overlays into. */
491
+ debugDir?: string;
492
+ }
493
+ /**
494
+ * Measure a front/turned image pair and report the three turn ratios plus both
495
+ * raw per-image measurements.
496
+ *
497
+ * Error boundary: ONLY AutoRigInputError (caller input / filesystem) →
498
+ * `{ ok:false }`, matching measureLayers; any other throw propagates.
499
+ */
500
+ declare function measureTurnReference(input: MeasureTurnInput): Promise<MeasureTurnResult>;
501
+ /** Render a measurement as plain text: the three ratios with the raw numbers
502
+ * behind each, then one block per image. */
503
+ declare function formatTurnReport(result: TurnMeasurement): string;
504
+
339
505
  declare function createIkiMcpServer(): McpServer;
340
506
 
341
- export { type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type ComposeInput, type ComposeResult, type DeformerSummary, type DescribeResult, type IkiSummary, type LayoutOverride, type MeasureInput, type MeasureResult, type StandardParameterInfo, type ValidateResult, autoRigFromLayers, composeLayersFromParts, createIkiMcpServer, describeIki, formatMeasureReport, listStandardParameters, measureLayers, validateIki };
507
+ export { type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type AutoRigTurnTargets, type ComposeInput, type ComposeResult, type DeformerSummary, type DescribeResult, type IkiSummary, type IrisBlob, type IrisColor, type LayoutOverride, type MeasureInput, type MeasureResult, type MeasureTurnInput, type MeasureTurnResult, type StandardParameterInfo, type TurnImageMeasure, type TurnMeasurement, type ValidateResult, autoRigFromLayers, composeLayersFromParts, createIkiMcpServer, describeIki, formatMeasureReport, formatTurnReport, listStandardParameters, measureLayers, measureTurnReference, validateIki };