@ikijs/mcp 0.7.0 → 0.8.1

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-GDLPXXJ3.mjs";
4
+ } from "./chunk-LIWK4PQV.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,57 @@ 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 motion
103
+ * (hair_front's silhouette hold, a turn group's grid for the face and
104
+ * its features, the body's own turn translate; `hair_back` holds the
105
+ * outline and lands where it rests, and a role outside that table is
106
+ * refused) and take the outermost LANDING, not just the outermost
107
+ * REST pixel. */
108
+ headEdges?: {
109
+ left: {
110
+ role: string;
111
+ x: number;
112
+ }[];
113
+ right: {
114
+ role: string;
115
+ x: number;
116
+ }[];
117
+ };
118
+ /** What the turn solve settled on — the cues the rig reaches and the
119
+ * defaulted targets it had to cut down. Absent for a layer set with no
120
+ * nose, which solves no turn at all. */
121
+ turn?: TurnSolveReport;
79
122
  } | {
80
123
  ok: false;
81
124
  error: string;
82
125
  };
126
+
83
127
  /**
84
128
  * Decode role-named PNG file paths, auto-rig a model from them, atlas + embed
85
129
  * the textures (Node sharp), validate, and write the renderable `.iki` to disk.
86
130
  * Returns the output path + summary stats (the multi-MB model is never inlined).
87
131
  *
132
+ * The head turn is fitted to `input.turnTargets`, on the head half-width this
133
+ * measures off the layers themselves; what the solve settled on comes back in
134
+ * `turn`. The face layer alone also gets its per-row painted half-widths
135
+ * (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
136
+ * radius: the generator reads no other role's, so measuring any other layer's
137
+ * would only hand it bytes it discards.
138
+ *
88
139
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
89
140
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
90
141
  * model math is reused from @ikijs/editor.
@@ -340,6 +391,122 @@ type ComposeResult = {
340
391
  */
341
392
  declare function composeLayersFromParts(input: ComposeInput): Promise<ComposeResult>;
342
393
 
394
+ /**
395
+ * Measure the head-turn cues in a PAIR of images of the same character — one
396
+ * facing front, one turned — and report them as three ratios. It is how a
397
+ * rigged turn gets compared to a reference turn without either image being
398
+ * registered to the other: every number below is a front→turned CHANGE,
399
+ * divided by something measured in the same image. That cancels crop and
400
+ * position, not SCALE: the head span is sampled over a FIXED ±HEAD_BAND row
401
+ * band, so a pair at different resolutions — or a character redrawn larger or
402
+ * smaller between the two shots — would read as a turn that never happened.
403
+ * The pair MUST already share framing and head size; this only checks it, it
404
+ * does not correct for it. The check is a yaw does not change iris HEIGHT, so
405
+ * a front/turned pair whose mean iris height differs is refused rather than
406
+ * measured (see `measureTurnReference`).
407
+ *
408
+ * farEyeRatio how much the far eye narrows, over what it already was at
409
+ * rest (a resting asymmetry in the art is divided out)
410
+ * eyeShift how far the eye pair slides across the head, in units of
411
+ * the FRONT head half-width (hh); negative = toward the
412
+ * image's left
413
+ * silhouetteRatio how much the head narrows, turned over front
414
+ *
415
+ * Read-only over two files; it edits nothing. Ported from the measurement
416
+ * script this repo's turn work ran by hand, so the numbers a rig is tuned
417
+ * against come out of the server every agent already has.
418
+ *
419
+ * `sharp` must stay confined to @ikijs/mcp; the decode and the debug-overlay
420
+ * encode both go through ./node-images, this package's single image boundary.
421
+ */
422
+ /**
423
+ * Hue/saturation window that selects the iris. Anime irises are a saturated
424
+ * colour on a face that is not, which is what makes them findable at all; the
425
+ * default window is violet-to-blue because that is what the characters this was
426
+ * tuned on have. A character with, say, amber eyes passes its own window.
427
+ */
428
+ interface IrisColor {
429
+ /** Inclusive hue bounds in degrees (0..360). */
430
+ hueMin: number;
431
+ hueMax: number;
432
+ /** Minimum HSV saturation (0..1) — separates the iris from the skin. */
433
+ satMin: number;
434
+ }
435
+ /** Connected blob of iris-coloured pixels, in image px. */
436
+ interface IrisBlob {
437
+ x0: number;
438
+ y0: number;
439
+ x1: number;
440
+ y1: number;
441
+ w: number;
442
+ h: number;
443
+ area: number;
444
+ cx: number;
445
+ cy: number;
446
+ }
447
+ /** One image's measurement. `irisL`/`irisR` are ordered by x in the IMAGE. */
448
+ interface TurnImageMeasure {
449
+ file: string;
450
+ width: number;
451
+ height: number;
452
+ maskMode: "alpha" | "keyed";
453
+ irisL: IrisBlob;
454
+ irisR: IrisBlob;
455
+ /** Mean row of the two iris centres. */
456
+ eyeRow: number;
457
+ /** Head silhouette span at the eye row. */
458
+ head: {
459
+ left: number;
460
+ right: number;
461
+ cx: number;
462
+ half: number;
463
+ };
464
+ /** Mean column of the two iris centres. */
465
+ pairCx: number;
466
+ eyeGap: number;
467
+ }
468
+ interface TurnMeasurement {
469
+ front: TurnImageMeasure;
470
+ turned: TurnImageMeasure;
471
+ /** Turned far/near iris width over the same ratio at rest. */
472
+ farEyeRatio: number;
473
+ /** Front→turned slide of the eye pair across the head, in FRONT hh units. */
474
+ eyeShift: number;
475
+ /** Head half-width, turned over front. */
476
+ silhouetteRatio: number;
477
+ /** -1 = the head turned toward the image's left, +1 = toward its right. */
478
+ turnSign: -1 | 1;
479
+ /** Debug overlays written, when `debugDir` was given. */
480
+ debug?: string[];
481
+ }
482
+ type MeasureTurnResult = ({
483
+ ok: true;
484
+ } & TurnMeasurement) | {
485
+ ok: false;
486
+ error: string;
487
+ };
488
+ interface MeasureTurnInput {
489
+ /** Front-facing image (relative paths resolve against cwd). */
490
+ front: string;
491
+ /** The same character turned. */
492
+ turned: string;
493
+ /** Iris colour window override, merged over the violet default. */
494
+ iris?: Partial<IrisColor>;
495
+ /** Existing directory to write `<name>.debug.png` overlays into. */
496
+ debugDir?: string;
497
+ }
498
+ /**
499
+ * Measure a front/turned image pair and report the three turn ratios plus both
500
+ * raw per-image measurements.
501
+ *
502
+ * Error boundary: ONLY AutoRigInputError (caller input / filesystem) →
503
+ * `{ ok:false }`, matching measureLayers; any other throw propagates.
504
+ */
505
+ declare function measureTurnReference(input: MeasureTurnInput): Promise<MeasureTurnResult>;
506
+ /** Render a measurement as plain text: the three ratios with the raw numbers
507
+ * behind each, then one block per image. */
508
+ declare function formatTurnReport(result: TurnMeasurement): string;
509
+
343
510
  declare function createIkiMcpServer(): McpServer;
344
511
 
345
- 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 };
512
+ 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,57 @@ 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 motion
103
+ * (hair_front's silhouette hold, a turn group's grid for the face and
104
+ * its features, the body's own turn translate; `hair_back` holds the
105
+ * outline and lands where it rests, and a role outside that table is
106
+ * refused) and take the outermost LANDING, not just the outermost
107
+ * REST pixel. */
108
+ headEdges?: {
109
+ left: {
110
+ role: string;
111
+ x: number;
112
+ }[];
113
+ right: {
114
+ role: string;
115
+ x: number;
116
+ }[];
117
+ };
118
+ /** What the turn solve settled on — the cues the rig reaches and the
119
+ * defaulted targets it had to cut down. Absent for a layer set with no
120
+ * nose, which solves no turn at all. */
121
+ turn?: TurnSolveReport;
79
122
  } | {
80
123
  ok: false;
81
124
  error: string;
82
125
  };
126
+
83
127
  /**
84
128
  * Decode role-named PNG file paths, auto-rig a model from them, atlas + embed
85
129
  * the textures (Node sharp), validate, and write the renderable `.iki` to disk.
86
130
  * Returns the output path + summary stats (the multi-MB model is never inlined).
87
131
  *
132
+ * The head turn is fitted to `input.turnTargets`, on the head half-width this
133
+ * measures off the layers themselves; what the solve settled on comes back in
134
+ * `turn`. The face layer alone also gets its per-row painted half-widths
135
+ * (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
136
+ * radius: the generator reads no other role's, so measuring any other layer's
137
+ * would only hand it bytes it discards.
138
+ *
88
139
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
89
140
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
90
141
  * model math is reused from @ikijs/editor.
@@ -340,6 +391,122 @@ type ComposeResult = {
340
391
  */
341
392
  declare function composeLayersFromParts(input: ComposeInput): Promise<ComposeResult>;
342
393
 
394
+ /**
395
+ * Measure the head-turn cues in a PAIR of images of the same character — one
396
+ * facing front, one turned — and report them as three ratios. It is how a
397
+ * rigged turn gets compared to a reference turn without either image being
398
+ * registered to the other: every number below is a front→turned CHANGE,
399
+ * divided by something measured in the same image. That cancels crop and
400
+ * position, not SCALE: the head span is sampled over a FIXED ±HEAD_BAND row
401
+ * band, so a pair at different resolutions — or a character redrawn larger or
402
+ * smaller between the two shots — would read as a turn that never happened.
403
+ * The pair MUST already share framing and head size; this only checks it, it
404
+ * does not correct for it. The check is a yaw does not change iris HEIGHT, so
405
+ * a front/turned pair whose mean iris height differs is refused rather than
406
+ * measured (see `measureTurnReference`).
407
+ *
408
+ * farEyeRatio how much the far eye narrows, over what it already was at
409
+ * rest (a resting asymmetry in the art is divided out)
410
+ * eyeShift how far the eye pair slides across the head, in units of
411
+ * the FRONT head half-width (hh); negative = toward the
412
+ * image's left
413
+ * silhouetteRatio how much the head narrows, turned over front
414
+ *
415
+ * Read-only over two files; it edits nothing. Ported from the measurement
416
+ * script this repo's turn work ran by hand, so the numbers a rig is tuned
417
+ * against come out of the server every agent already has.
418
+ *
419
+ * `sharp` must stay confined to @ikijs/mcp; the decode and the debug-overlay
420
+ * encode both go through ./node-images, this package's single image boundary.
421
+ */
422
+ /**
423
+ * Hue/saturation window that selects the iris. Anime irises are a saturated
424
+ * colour on a face that is not, which is what makes them findable at all; the
425
+ * default window is violet-to-blue because that is what the characters this was
426
+ * tuned on have. A character with, say, amber eyes passes its own window.
427
+ */
428
+ interface IrisColor {
429
+ /** Inclusive hue bounds in degrees (0..360). */
430
+ hueMin: number;
431
+ hueMax: number;
432
+ /** Minimum HSV saturation (0..1) — separates the iris from the skin. */
433
+ satMin: number;
434
+ }
435
+ /** Connected blob of iris-coloured pixels, in image px. */
436
+ interface IrisBlob {
437
+ x0: number;
438
+ y0: number;
439
+ x1: number;
440
+ y1: number;
441
+ w: number;
442
+ h: number;
443
+ area: number;
444
+ cx: number;
445
+ cy: number;
446
+ }
447
+ /** One image's measurement. `irisL`/`irisR` are ordered by x in the IMAGE. */
448
+ interface TurnImageMeasure {
449
+ file: string;
450
+ width: number;
451
+ height: number;
452
+ maskMode: "alpha" | "keyed";
453
+ irisL: IrisBlob;
454
+ irisR: IrisBlob;
455
+ /** Mean row of the two iris centres. */
456
+ eyeRow: number;
457
+ /** Head silhouette span at the eye row. */
458
+ head: {
459
+ left: number;
460
+ right: number;
461
+ cx: number;
462
+ half: number;
463
+ };
464
+ /** Mean column of the two iris centres. */
465
+ pairCx: number;
466
+ eyeGap: number;
467
+ }
468
+ interface TurnMeasurement {
469
+ front: TurnImageMeasure;
470
+ turned: TurnImageMeasure;
471
+ /** Turned far/near iris width over the same ratio at rest. */
472
+ farEyeRatio: number;
473
+ /** Front→turned slide of the eye pair across the head, in FRONT hh units. */
474
+ eyeShift: number;
475
+ /** Head half-width, turned over front. */
476
+ silhouetteRatio: number;
477
+ /** -1 = the head turned toward the image's left, +1 = toward its right. */
478
+ turnSign: -1 | 1;
479
+ /** Debug overlays written, when `debugDir` was given. */
480
+ debug?: string[];
481
+ }
482
+ type MeasureTurnResult = ({
483
+ ok: true;
484
+ } & TurnMeasurement) | {
485
+ ok: false;
486
+ error: string;
487
+ };
488
+ interface MeasureTurnInput {
489
+ /** Front-facing image (relative paths resolve against cwd). */
490
+ front: string;
491
+ /** The same character turned. */
492
+ turned: string;
493
+ /** Iris colour window override, merged over the violet default. */
494
+ iris?: Partial<IrisColor>;
495
+ /** Existing directory to write `<name>.debug.png` overlays into. */
496
+ debugDir?: string;
497
+ }
498
+ /**
499
+ * Measure a front/turned image pair and report the three turn ratios plus both
500
+ * raw per-image measurements.
501
+ *
502
+ * Error boundary: ONLY AutoRigInputError (caller input / filesystem) →
503
+ * `{ ok:false }`, matching measureLayers; any other throw propagates.
504
+ */
505
+ declare function measureTurnReference(input: MeasureTurnInput): Promise<MeasureTurnResult>;
506
+ /** Render a measurement as plain text: the three ratios with the raw numbers
507
+ * behind each, then one block per image. */
508
+ declare function formatTurnReport(result: TurnMeasurement): string;
509
+
343
510
  declare function createIkiMcpServer(): McpServer;
344
511
 
345
- 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 };
512
+ 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 };