@ikijs/mcp 0.37.0 → 0.37.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-4B6MEVAP.mjs";
4
+ } from "./chunk-N6KPV7FC.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/index.js CHANGED
@@ -554,19 +554,33 @@ var BLINK_CLOSE_MS = 60;
554
554
  var BLINK_HOLD_MS = 20;
555
555
  var BLINK_OPEN_MS = 100;
556
556
  var BLINK_DURATION_MS = BLINK_CLOSE_MS + BLINK_HOLD_MS + BLINK_OPEN_MS;
557
- var BREATH_PERIOD_MS = 3500;
558
- var GAZE_RADIUS = 0.3;
559
- var GAZE_RETARGET_MIN_MS = 1200;
560
- var GAZE_RETARGET_MAX_MS = 3e3;
561
- var GAZE_EASE_RATE = 1e-3;
562
- var SWAY_X_AMP_A_DEG = 2.2;
563
- var SWAY_X_PERIOD_A_MS = 6100;
564
- var SWAY_X_AMP_B_DEG = 1.3;
565
- var SWAY_X_PERIOD_B_MS = 9700;
566
- var SWAY_Y_AMP_DEG = 1.6;
567
- var SWAY_Y_PERIOD_MS = 7300;
568
- var SWAY_Z_AMP_DEG = 1.1;
569
- var SWAY_Z_PERIOD_MS = 11300;
557
+ var DOUBLE_BLINK_P = 0.18;
558
+ var DOUBLE_BLINK_GAP_MS = 70;
559
+ var BROW_BLINK_DIP = 0.06;
560
+ var BREATH_IN_END = 0.4;
561
+ var BREATH_OUT_END = 0.88;
562
+ var BREATH_PERIOD_MIN_MS = 3200;
563
+ var BREATH_PERIOD_MAX_MS = 4600;
564
+ var BREATH_PITCH_DEG = 1;
565
+ var GAZE_RETARGET_MIN_MS = 800;
566
+ var GAZE_RETARGET_MAX_MS = 3300;
567
+ var GAZE_EYE_CONTACT_P = 0.4;
568
+ var GAZE_X_MAX = 0.8;
569
+ var GAZE_Y_MAX = 0.5;
570
+ var EYE_SPRING_OMEGA = 16;
571
+ var EYE_SPRING_ZETA = 0.9;
572
+ var HEAD_FOLLOW_X_DEG = 10;
573
+ var HEAD_FOLLOW_Y_DEG = 10;
574
+ var HEAD_NOISE_AMP_X_DEG = 6;
575
+ var HEAD_NOISE_AMP_Y_DEG = 4;
576
+ var HEAD_NOISE_AMP_Z_DEG = 4;
577
+ var HEAD_NOISE_RATE_X_HZ = 0.18;
578
+ var HEAD_NOISE_RATE_Y_HZ = 0.15;
579
+ var HEAD_NOISE_RATE_Z_HZ = 0.12;
580
+ var HEAD_SPRING_OMEGA = 7.4;
581
+ var HEAD_SPRING_ZETA = 0.72;
582
+ var HEAD_NOISE_EASE_IN_MS = 4e3;
583
+ var SPRING_SUBSTEP_MS = 8;
570
584
  var AMBIENT_AMP_A = 0.6;
571
585
  var AMBIENT_PERIOD_A_MS = 2900;
572
586
  var AMBIENT_AMP_B = 0.4;
@@ -582,11 +596,51 @@ function blinkEnvelope(phase) {
582
596
  }
583
597
  return 1;
584
598
  }
585
- function randomInDisk(rng, radius) {
586
- const r = Math.sqrt(rng()) * radius;
587
- const theta = rng() * 2 * Math.PI;
588
- return [r * Math.cos(theta), r * Math.sin(theta)];
599
+ function breathEnvelope(phase) {
600
+ if (phase < BREATH_IN_END) return smoothstep(phase / BREATH_IN_END);
601
+ return 1 - smoothstep((phase - BREATH_IN_END) / (BREATH_OUT_END - BREATH_IN_END));
602
+ }
603
+ function drawSeed(rng) {
604
+ return Math.floor(rng() * 4294967296) | 0;
605
+ }
606
+ function latticeValue(seed, i) {
607
+ let h = Math.imul(i, 668265261) ^ seed;
608
+ h = Math.imul(h ^ h >>> 15, 739982445);
609
+ h = Math.imul(h ^ h >>> 12, 695872825);
610
+ h ^= h >>> 15;
611
+ return (h >>> 0) / 2147483648 - 1;
612
+ }
613
+ function valueNoise(seed, x) {
614
+ const i = Math.floor(x);
615
+ return lerp(
616
+ latticeValue(seed, i),
617
+ latticeValue(seed, i + 1),
618
+ smoothstep(x - i)
619
+ );
620
+ }
621
+ function fbm(seed, x) {
622
+ return (valueNoise(seed, x) + 0.5 * valueNoise(seed ^ 1540483477, 2 * x)) / 1.5;
589
623
  }
624
+ var Spring = class {
625
+ constructor(omega, zeta) {
626
+ this.omega = omega;
627
+ this.zeta = zeta;
628
+ }
629
+ omega;
630
+ zeta;
631
+ value = 0;
632
+ velocity = 0;
633
+ /** Advance `dtMs` toward `target` by semi-implicit Euler in short slices. */
634
+ step(target2, dtMs) {
635
+ const slices = Math.ceil(dtMs / SPRING_SUBSTEP_MS);
636
+ const h = dtMs / slices / 1e3;
637
+ for (let s = 0; s < slices; s++) {
638
+ const accel = this.omega * this.omega * (target2 - this.value) - 2 * this.zeta * this.omega * this.velocity;
639
+ this.velocity += accel * h;
640
+ this.value += this.velocity * h;
641
+ }
642
+ }
643
+ };
590
644
  var IdleMotion = class {
591
645
  /**
592
646
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -594,19 +648,11 @@ var IdleMotion = class {
594
648
  * stops driving — keep in step with those two methods; the test suite
595
649
  * pins this list to the actual emissions.
596
650
  */
597
- drivenParameterIds = [
598
- import_format.StandardParameter.EyeOpenLeft,
599
- import_format.StandardParameter.EyeOpenRight,
600
- import_format.StandardParameter.Breath,
601
- import_format.StandardParameter.EyeballX,
602
- import_format.StandardParameter.EyeballY,
603
- import_format.StandardParameter.AngleX,
604
- import_format.StandardParameter.AngleY,
605
- import_format.StandardParameter.AngleZ,
606
- import_format.StandardParameter.AmbientSway
607
- ];
651
+ drivenParameterIds;
608
652
  sink;
609
653
  rng;
654
+ /** The declared brow Y ids the blink dip writes, with their resting values. */
655
+ brows;
610
656
  // Internal clock: advances by clamped dt, NOT by raw wall-clock jumps.
611
657
  // This is the only clock blink/breath/gaze scheduling reads.
612
658
  clockMs = 0;
@@ -615,15 +661,43 @@ var IdleMotion = class {
615
661
  nextBlinkAtMs;
616
662
  blinkStartMs = -1;
617
663
  // -1 means not currently blinking
618
- // Gaze state
619
- gazeCurrentX = 0;
620
- gazeCurrentY = 0;
664
+ // Whether the blink scheduled (or running) is the second of a pair.
665
+ blinkIsSecond = false;
666
+ // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
667
+ // first retarget. A host target, while set, replaces the pick as what the
668
+ // eyes and head chase; the schedule keeps picking underneath it.
669
+ eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
670
+ eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
621
671
  gazeTargetX = 0;
622
672
  gazeTargetY = 0;
623
673
  nextGazeRetargetMs;
674
+ hostGaze = void 0;
675
+ // Breath state: the current cycle's start and length on the internal clock.
676
+ breathStartMs = 0;
677
+ breathPeriodMs;
678
+ // Head state: one noise seed and one spring per axis (X turn, Y nod, Z roll).
679
+ headSeedX;
680
+ headSeedY;
681
+ headSeedZ;
682
+ headX = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
683
+ headY = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
684
+ headZ = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
624
685
  constructor(sink, options) {
625
686
  this.sink = sink;
626
687
  this.rng = options?.rng ?? Math.random;
688
+ this.brows = [import_format.StandardParameter.BrowLeftY, import_format.StandardParameter.BrowRightY].map((id) => options?.parameters?.find((p) => p.id === id)).filter((p) => p !== void 0).map((p) => ({ id: p.id, rest: clamp(p.default, p.min, p.max) }));
689
+ this.drivenParameterIds = [
690
+ import_format.StandardParameter.EyeOpenLeft,
691
+ import_format.StandardParameter.EyeOpenRight,
692
+ ...this.brows.map((b) => b.id),
693
+ import_format.StandardParameter.Breath,
694
+ import_format.StandardParameter.EyeballX,
695
+ import_format.StandardParameter.EyeballY,
696
+ import_format.StandardParameter.AngleX,
697
+ import_format.StandardParameter.AngleY,
698
+ import_format.StandardParameter.AngleZ,
699
+ import_format.StandardParameter.AmbientSway
700
+ ];
627
701
  this.nextBlinkAtMs = lerp(
628
702
  BLINK_INTERVAL_MIN_MS,
629
703
  BLINK_INTERVAL_MAX_MS,
@@ -634,6 +708,10 @@ var IdleMotion = class {
634
708
  GAZE_RETARGET_MAX_MS,
635
709
  this.rng()
636
710
  );
711
+ this.headSeedX = drawSeed(this.rng);
712
+ this.headSeedY = drawSeed(this.rng);
713
+ this.headSeedZ = drawSeed(this.rng);
714
+ this.breathPeriodMs = this.drawBreathPeriod();
637
715
  }
638
716
  /**
639
717
  * Advance the idle animation to the given wall-clock timestamp (milliseconds).
@@ -659,23 +737,52 @@ var IdleMotion = class {
659
737
  const eyeVal = this.advanceBlink();
660
738
  this.sink(import_format.StandardParameter.EyeOpenLeft, eyeVal);
661
739
  this.sink(import_format.StandardParameter.EyeOpenRight, eyeVal);
740
+ for (const { id, rest } of this.brows) {
741
+ this.sink(id, rest + BROW_BLINK_DIP * (eyeVal - 1));
742
+ }
662
743
  const breath = this.advanceBreath();
663
744
  this.advanceGaze(dt);
664
745
  this.sink(import_format.StandardParameter.Breath, breath);
665
- this.sink(import_format.StandardParameter.EyeballX, this.gazeCurrentX);
666
- this.sink(import_format.StandardParameter.EyeballY, this.gazeCurrentY);
667
- this.sink(import_format.StandardParameter.AngleX, this.swayX());
668
- this.sink(import_format.StandardParameter.AngleY, this.swayY());
669
- this.sink(import_format.StandardParameter.AngleZ, this.swayZ());
746
+ this.sink(import_format.StandardParameter.EyeballX, this.eyeX.value);
747
+ this.sink(import_format.StandardParameter.EyeballY, this.eyeY.value);
748
+ this.advanceHead(dt, breath);
749
+ this.sink(import_format.StandardParameter.AngleX, this.headX.value);
750
+ this.sink(import_format.StandardParameter.AngleY, this.headY.value);
751
+ this.sink(import_format.StandardParameter.AngleZ, this.headZ.value);
670
752
  this.sink(import_format.StandardParameter.AmbientSway, this.ambientSway());
671
753
  }
754
+ /**
755
+ * Hold the gaze on (`x`, `y`), in EyeballX/Y units (+ is the viewer's right
756
+ * and up), until {@link clearGazeTarget}: the eyes chase it on their stiff
757
+ * springs and the head follows it on the turn and nod, as it follows a
758
+ * scheduled pick. Each value is clamped to [-1, 1], so the follow can reach
759
+ * past the scheduled picks' ±0.8 / ±0.5 box. A pair with a non-finite value
760
+ * is ignored and changes nothing, the same boundary rule as
761
+ * ParameterStore.set.
762
+ *
763
+ * The scheduled retargets keep running and drawing from the rng while a host
764
+ * target is set, so the rng sequence does not depend on host calls.
765
+ */
766
+ setGazeTarget(x, y) {
767
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return;
768
+ this.hostGaze = { x: clamp(x, -1, 1), y: clamp(y, -1, 1) };
769
+ }
770
+ /**
771
+ * Drop the host target: the eyes and head turn back to the current
772
+ * scheduled pick at once (a pointer leaving does not leave the eyes frozen
773
+ * until the next retarget), and later picks drive them as before.
774
+ */
775
+ clearGazeTarget() {
776
+ this.hostGaze = void 0;
777
+ }
672
778
  // ---------------------------------------------------------------------------
673
779
  // Private helpers
674
780
  // ---------------------------------------------------------------------------
675
781
  emitRestingPose() {
676
782
  this.sink(import_format.StandardParameter.EyeOpenLeft, 1);
677
783
  this.sink(import_format.StandardParameter.EyeOpenRight, 1);
678
- this.sink(import_format.StandardParameter.Breath, 0.5);
784
+ for (const { id, rest } of this.brows) this.sink(id, rest);
785
+ this.sink(import_format.StandardParameter.Breath, 0);
679
786
  this.sink(import_format.StandardParameter.EyeballX, 0);
680
787
  this.sink(import_format.StandardParameter.EyeballY, 0);
681
788
  this.sink(import_format.StandardParameter.AngleX, 0);
@@ -690,7 +797,8 @@ var IdleMotion = class {
690
797
  const phase = (clockMs - this.blinkStartMs) / BLINK_DURATION_MS;
691
798
  if (phase >= 1) {
692
799
  this.blinkStartMs = -1;
693
- this.nextBlinkAtMs = clockMs + lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng());
800
+ this.blinkIsSecond = !this.blinkIsSecond && this.rng() < DOUBLE_BLINK_P;
801
+ this.nextBlinkAtMs = clockMs + (this.blinkIsSecond ? DOUBLE_BLINK_GAP_MS : lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng()));
694
802
  return 1;
695
803
  }
696
804
  return blinkEnvelope(phase);
@@ -701,38 +809,68 @@ var IdleMotion = class {
701
809
  }
702
810
  return 1;
703
811
  }
812
+ /**
813
+ * Returns the breath value (0..1), starting the next cycle, with a freshly
814
+ * drawn length, once the current one has run out. One clamped dt (≤ 100 ms)
815
+ * is far shorter than any cycle, so a step crosses at most one boundary.
816
+ */
704
817
  advanceBreath() {
705
- return 0.5 + 0.5 * Math.sin(2 * Math.PI * this.clockMs / BREATH_PERIOD_MS);
706
- }
707
- /** Horizontal head sway in degrees, pure function of the internal clock. */
708
- swayX() {
709
- const t = 2 * Math.PI * this.clockMs;
710
- return SWAY_X_AMP_A_DEG * Math.sin(t / SWAY_X_PERIOD_A_MS) + SWAY_X_AMP_B_DEG * Math.sin(t / SWAY_X_PERIOD_B_MS);
818
+ if (this.clockMs - this.breathStartMs >= this.breathPeriodMs) {
819
+ this.breathStartMs += this.breathPeriodMs;
820
+ this.breathPeriodMs = this.drawBreathPeriod();
821
+ }
822
+ return breathEnvelope(
823
+ (this.clockMs - this.breathStartMs) / this.breathPeriodMs
824
+ );
711
825
  }
712
- /** Vertical head sway in degrees, pure function of the internal clock. */
713
- swayY() {
714
- return SWAY_Y_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Y_PERIOD_MS);
826
+ drawBreathPeriod() {
827
+ return lerp(BREATH_PERIOD_MIN_MS, BREATH_PERIOD_MAX_MS, this.rng());
715
828
  }
716
- /** Head roll sway in degrees, pure function of the internal clock. */
717
- swayZ() {
718
- return SWAY_Z_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Z_PERIOD_MS);
829
+ /**
830
+ * Step each head spring toward its axis noise at the internal clock, plus,
831
+ * on the turn and nod, the gaze target scaled to degrees, and on the nod the
832
+ * breath's lift. Only the noise fades in: the scheduled pick starts at
833
+ * (0, 0), so it has no start value to lurch to, and its first jump is no
834
+ * larger than any later one; the breath starts empty, at 0.
835
+ */
836
+ advanceHead(dt, breath) {
837
+ const seconds = this.clockMs / 1e3;
838
+ const easeIn = smoothstep(this.clockMs / HEAD_NOISE_EASE_IN_MS);
839
+ this.headX.step(
840
+ easeIn * HEAD_NOISE_AMP_X_DEG * fbm(this.headSeedX, seconds * HEAD_NOISE_RATE_X_HZ) + HEAD_FOLLOW_X_DEG * (this.hostGaze?.x ?? this.gazeTargetX),
841
+ dt
842
+ );
843
+ this.headY.step(
844
+ easeIn * HEAD_NOISE_AMP_Y_DEG * fbm(this.headSeedY, seconds * HEAD_NOISE_RATE_Y_HZ) + HEAD_FOLLOW_Y_DEG * (this.hostGaze?.y ?? this.gazeTargetY) + BREATH_PITCH_DEG * breath,
845
+ dt
846
+ );
847
+ this.headZ.step(
848
+ easeIn * HEAD_NOISE_AMP_Z_DEG * fbm(this.headSeedZ, seconds * HEAD_NOISE_RATE_Z_HZ),
849
+ dt
850
+ );
719
851
  }
720
852
  /** Ambient sway (-1..1), pure function of the internal clock. */
721
853
  ambientSway() {
722
854
  const t = 2 * Math.PI * this.clockMs;
723
855
  return AMBIENT_AMP_A * Math.sin(t / AMBIENT_PERIOD_A_MS) + AMBIENT_AMP_B * Math.sin(t / AMBIENT_PERIOD_B_MS);
724
856
  }
725
- /** Ease gaze current toward target; pick a new target on the internal clock. */
857
+ /**
858
+ * Step the eye springs toward the gaze target, the host's while set, else
859
+ * the scheduled pick; retarget on the internal clock either way.
860
+ */
726
861
  advanceGaze(dt) {
727
862
  if (this.clockMs >= this.nextGazeRetargetMs) {
728
- const [tx, ty] = randomInDisk(this.rng, GAZE_RADIUS);
729
- this.gazeTargetX = tx;
730
- this.gazeTargetY = ty;
863
+ if (this.rng() < GAZE_EYE_CONTACT_P) {
864
+ this.gazeTargetX = 0;
865
+ this.gazeTargetY = 0;
866
+ } else {
867
+ this.gazeTargetX = lerp(-GAZE_X_MAX, GAZE_X_MAX, this.rng());
868
+ this.gazeTargetY = lerp(-GAZE_Y_MAX, GAZE_Y_MAX, this.rng());
869
+ }
731
870
  this.nextGazeRetargetMs = this.clockMs + lerp(GAZE_RETARGET_MIN_MS, GAZE_RETARGET_MAX_MS, this.rng());
732
871
  }
733
- const factor = 1 - Math.pow(1 - GAZE_EASE_RATE, dt);
734
- this.gazeCurrentX = lerp(this.gazeCurrentX, this.gazeTargetX, factor);
735
- this.gazeCurrentY = lerp(this.gazeCurrentY, this.gazeTargetY, factor);
872
+ this.eyeX.step(this.hostGaze?.x ?? this.gazeTargetX, dt);
873
+ this.eyeY.step(this.hostGaze?.y ?? this.gazeTargetY, dt);
736
874
  }
737
875
  };
738
876
 
@@ -1448,7 +1586,8 @@ function stepRun(model, rigs, chains, values) {
1448
1586
  function idleRun(model) {
1449
1587
  const store = new ParameterStore(model.parameters);
1450
1588
  const idle = new IdleMotion((id, v) => store.set(id, v), {
1451
- rng: lcg(IDLE_SEED)
1589
+ rng: lcg(IDLE_SEED),
1590
+ parameters: model.parameters
1452
1591
  });
1453
1592
  return run(
1454
1593
  model,
@@ -7844,7 +7983,7 @@ function formatBakeChecks(bakes) {
7844
7983
  );
7845
7984
  }
7846
7985
  function createIkiMcpServer() {
7847
- const server = new import_mcp.McpServer({ name: "iki", version: "0.37.0" });
7986
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.37.1" });
7848
7987
  server.registerTool(
7849
7988
  "validate_iki",
7850
7989
  {
@@ -8020,7 +8159,7 @@ function createIkiMcpServer() {
8020
8159
  "At least one, `value` strictly ascending and inside the parameter's range. The amount is linear between stops and held before the first and after the last."
8021
8160
  )
8022
8161
  }).passthrough().optional().describe(
8023
- "Hide the part where the named roles' paint covers it, by an amount keyed on a parameter: `{ by, parameter, stops: [{ value, amount }] }`. Cover is where a role's drawn alpha at that pose is at least 0.5, a hard edge; a role that fades (`mouth_open`, a blush, a pose forearm) covers only while drawn at half strength or more. Use the stops as a short switch starting a degree or more past the idle sway, the hiding's progress coming from the part's baked motion. Needs @ikijs/mcp 0.35.0; an older server refuses the key as an unknown key (`INVALID: customParts[i]\u2026`). An unknown key, a bad stop or a part the key cannot be written for comes back as `INVALID: customParts[i].occlusion\u2026` with nothing written."
8162
+ "Hide the part where the named roles' paint covers it, by an amount keyed on a parameter: `{ by, parameter, stops: [{ value, amount }] }`. Cover is where a role's drawn alpha at that pose is at least 0.5, a hard edge; a role that fades (`mouth_open`, a blush, a pose forearm) covers only while drawn at half strength or more. Use the stops as a short switch starting a degree or more off rest (so the rest pose never sits on it; the idle turns the head through the switch), the hiding's progress coming from the part's baked motion. Needs @ikijs/mcp 0.35.0; an older server refuses the key as an unknown key (`INVALID: customParts[i]\u2026`). An unknown key, a bad stop or a part the key cannot be written for comes back as `INVALID: customParts[i].occlusion\u2026` with nothing written."
8024
8163
  )
8025
8164
  }).passthrough()
8026
8165
  ).optional().describe(