rig-review 0.19.0 → 0.21.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 CHANGED
@@ -11,8 +11,8 @@ The app provides one inspection workspace for setup geometry and motion, compile
11
11
  [Play](https://github.com/rig-c/play) → **Adapter** (consumer integration).
12
12
 
13
13
  Review is the human inspection and source-bound feedback gate in this delivery
14
- flow. It inspects the upstream build without replacing Core's compiler gate or
15
- authoring motion. Review itself uses the published Play runtime for previews;
14
+ flow. It inspects the upstream build without replacing Core's compiler gate, and
15
+ its motion edits are data the installed producer builds in scratch. Review itself uses the published Play runtime for previews;
16
16
  the chain describes delivery and feedback responsibilities, not runtime import
17
17
  order. Adapter denotes downstream consumer integration, without depending on the
18
18
  published adapters (`@rig-c/pixi`, `@rig-c/phaser`, `@rig-c/three`) or changing
@@ -1,6 +1,6 @@
1
1
  # Read-only animation inspection
2
2
 
3
- Animate → Transport offers a timeline, a stored-curve view and a bone tree for the current compiled build. These are inspection controls: no key authoring, motion.json writes, producer operations or output/patch schema changes. Two-build comparison is outside this feature.
3
+ Animate → Transport offers a timeline, a stored-curve view and a bone tree for the current compiled build. The bone value tracks of `motion.animations_from` are editable (#235): an edit is a pending op, and Apply builds it through the installed producer into scratch. The package's files are never written. Two-build comparison is outside this feature.
4
4
 
5
5
  The timeline lists bone groups followed by slot groups, one lane per stored timeline, with a mark per key including simultaneous keys. Key times remain exact seconds. Clicking a mark seeks through the existing transport; transport movement updates its playhead. No FPS is inferred. A selected bone filters its direct bone tracks; a selected slot filters that slot's tracks. Whole rig clears the filter.
6
6
 
package/docs/DESIGN.md CHANGED
@@ -30,7 +30,7 @@ Edits reach the producer as data (issue #102): every edit card states its edit a
30
30
 
31
31
  Physics tuning (#103) edits only what the handoff config declares: a constraint row is resolved by `name` (and kind) against the config, never by index alone, and every op records both the index (its pointer) and the name, which the server checks (`EDIT_PATCH_NAME_MISMATCH`). Rows the rig stage adds (the `turn` twins) have no config field and are shown not editable with the reason. An Apply reloads under the world it was pressed in so before and after are seen under one wind, gust and jolt state; review judges no value (a mass of 0 is rigc's `A23` to refuse). A build whose check FAILed may be loaded and looked at, but a review written on it is not submitted (`EDIT_SUBMIT_UNCHECKED`). Published Play 1.14.0 supplies the six-field live preview (#206): strength, damping, inertia, wind, gravity and mix use its public set/read/clear methods; mass and component toggles still require Apply. Slider input updates the pending override; the label distinguishes it from the last evaluated effective values. The next evaluation uses the patch; a paused page explicitly re-poses the held time without seeking. Clear removes overrides while preserving pending ops and integrated history, and authored values resume at the next evaluation; it does not undo the old trajectory. Apply and model replacement clear the preview. It is labelled "preview — Apply decides" and is never recorded as applied state. Play replays the current standing patch, not historical edits: backward seek recomputes with today's patch, and a newly opened track's first authored pose precedes its pending patch. The readout's BEFORE for the inspected build is that build's own check: once the baseline reproduces, `rig-parts check` runs on the baseline output (byte-identical to the inspected rig) in the background, and its summary is stored beside the baseline record.
32
32
 
33
- The producer writes motion in scratch; review never authors keys. Idle tracks (#104) edit the idle the producer keys, never the package's motion.json: every edit is a config patch op at `/motion/tracks/<i>/…` or `/motion/blink/…`, and the producer (`retune` on parts 1.44.0+, else `rig --config`; then `check`) writes the keys. The panel offers only what the producer accepts where its rule is closed — a period is `motion.duration / n` (rig-parts `periodFits`: the duration over the period within 1e-9 of a whole number) — and pre-checks the pending idle under the producer's own names and words (`CONFIG_PERIOD_DIVIDES_DURATION`, `CONFIG_BONE_PROPERTY_KEYED_ONCE`, `CONFIG_NAME_RESOLVES`, `RIG_BLINK_INSIDE_IDLE`), so a refusal before Apply is the producer's line, and the producer judges again on Apply. The preview (decision on #104: allowed) drives the edited bones through play's `adjust` with the producer's sine `v(t) = base + amp·sin(2π(t/period − phase))` on the bone the inspected idle keys (`<bone>_ctl` under ctl keys, read off the handoff rig, never guessed: a property the idle does not key yet is refused by name, `IDLE_PREVIEW_TARGET_UNKNOWN`); it uses Play 1.14.0's `BoneAdjust` context `trackTime` through both composed adjustments, with no displayed player clock or seek-compensation re-pose. Bit-exact seek/continuous equivalence requires the unchanged patch, animation, environment, reset and step partition. It is labelled "preview — Apply decides", is cleared on Apply and Reset, and is never recorded or submitted. Blink edits are eased keys and are not previewed.
33
+ The producer writes motion in scratch; review never writes a source key. A timeline edit (#235) is a list of ops on a scratch copy of `motion.animations_from`, built by the installed producer. Idle tracks (#104) edit the idle the producer keys, never the package's motion.json: every edit is a config patch op at `/motion/tracks/<i>/…` or `/motion/blink/…`, and the producer (`retune` on parts 1.44.0+, else `rig --config`; then `check`) writes the keys. The panel offers only what the producer accepts where its rule is closed — a period is `motion.duration / n` (rig-parts `periodFits`: the duration over the period within 1e-9 of a whole number) — and pre-checks the pending idle under the producer's own names and words (`CONFIG_PERIOD_DIVIDES_DURATION`, `CONFIG_BONE_PROPERTY_KEYED_ONCE`, `CONFIG_NAME_RESOLVES`, `RIG_BLINK_INSIDE_IDLE`), so a refusal before Apply is the producer's line, and the producer judges again on Apply. The preview (decision on #104: allowed) drives the edited bones through play's `adjust` with the producer's sine `v(t) = base + amp·sin(2π(t/period − phase))` on the bone the inspected idle keys (`<bone>_ctl` under ctl keys, read off the handoff rig, never guessed: a property the idle does not key yet is refused by name, `IDLE_PREVIEW_TARGET_UNKNOWN`); it uses Play 1.14.0's `BoneAdjust` context `trackTime` through both composed adjustments, with no displayed player clock or seek-compensation re-pose. Bit-exact seek/continuous equivalence requires the unchanged patch, animation, environment, reset and step partition. It is labelled "preview — Apply decides", is cleared on Apply and Reset, and is never recorded or submitted. Blink edits are eased keys and are not previewed.
34
34
 
35
35
  The Mesh panel (#106) edits one part's `meshes.<part>` entry as the producer's config loader reads it and rebuilds that part with `remesh --mesh`; it is a mesh-density and region editor for the producer's own parameters, not a mesher — review triangulates nothing, and the only geometry it writes is region points (whole rig px) and circle centres. The submitted patch is exactly one op, `replace /meshes/<part>`, so nothing else in the config can move with it. It offers the modes whose fields it draws (grid, contour); `influence` waits until the producer documents it in `remesh`. Its pre-check is the config loader's rules in the loader's names; what the rig stage measures (the keep-radius floor, bridges, heat sources, the remesh rules) is the producer's to say, and comes back verbatim. After a build, three counts must agree — `remesh.json`'s after-count, the revision model's triangles and what the overlay draws — and the panel names each, so an overlay still drawing the old mesh is visible as a disagreement, not hidden.
36
36
 
package/docs/PANELS.md CHANGED
@@ -227,9 +227,9 @@ serving use per-port origins and keep them separate.
227
227
 
228
228
  ## Inspect animation keys
229
229
 
230
- Animate → **Transport** opens the read-only Timeline, Curves and Bone tree views of the build currently on stage. The timeline preserves every stored bone/slot track and key time; click a key to seek, or scrub the transport to move its playhead. Bone selection filters its direct tracks. Tree, Parts and stage selections stay synchronized; enable **Bone points** to pick a bone on stage. Selecting a bone highlights all directly attached Parts rows without inventing a selected slot.
230
+ Animate keeps its timeline in a panel of its own beside the other blocks, with Timeline, Curves and Bone tree views of the build currently on stage. Bone value tracks of `motion.animations_from` are editable: an edit is a pending op, previewed on the stage, and **Apply · Rebuild** builds it through the installed producer into scratch. Other tracks say why they are read-only, and compare mode is read-only (`ANIMATION_COMPARE_READ_ONLY`). The timeline preserves every stored bone/slot track and key time; click a key to seek, or scrub the transport to move its playhead. Bone selection filters its direct tracks. Tree, Parts and stage selections stay synchronized; enable **Bone points** to pick a bone on stage. Selecting a bone highlights all directly attached Parts rows without inventing a selected slot.
231
231
 
232
- Curves show the compiled skeleton’s exact linear, stepped or cubic Bézier segments and stored handles. The separately labeled **Runtime evaluation** cursor/readout uses Play’s ten-piece Float32 interpolation, which can differ from the cubic. Its local value includes setup rotation/translation and scale multiplication, in stored timeline order, before constraints and previews. Rotation is unwrapped local degrees. **Inspect time** accepts exact seconds; frame labels require the existing explicit clock. These views author no keys and change no package, motion, patch or review format. See [animation inspection](ANIMATION_INSPECTION.md) for the numeric validation and reproduction commands.
232
+ Curves show the compiled skeleton’s exact linear, stepped or cubic Bézier segments and stored handles. On an editable bone value track, **Segment** picks the outgoing key, **Mode** switches between linear, stepped and cubic Bézier, and dragging the two handles on the plot edits the segment’s `[cx1, cy1, cx2, cy2]` (`set_key_curve` / `set_key_ease` ops, coalesced on the same key and previewed live on the stage before **Apply · Rebuild**). The separately labeled **Runtime evaluation** cursor/readout uses Play’s ten-piece Float32 interpolation, which can differ from the cubic. Its local value includes setup rotation/translation and scale multiplication, in stored timeline order, before constraints and previews. Rotation is unwrapped local degrees. **Inspect time** accepts exact seconds; frame labels require the existing explicit clock. Nothing is written into the package. See [animation inspection](ANIMATION_INSPECTION.md) for the numeric validation and reproduction commands.
233
233
 
234
234
  ## Inspect a part
235
235
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-review",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "description": "Local human rig inspection and structured feedback export",
6
6
  "license": "MIT",
@@ -6,6 +6,7 @@ import {
6
6
  } from './animation-inspection.ts';
7
7
 
8
8
  export const MOTION_SPEC_VERSION = 'rigc-motion/1';
9
+ export const MAX_ANIMATION_OPS = 200;
9
10
 
10
11
  export type EasingTuple = readonly [number, number, number, number];
11
12
 
@@ -382,9 +383,11 @@ export interface AnimationEditGate {
382
383
  editable: boolean;
383
384
  code:
384
385
  | 'OK'
386
+ | 'ANIMATION_SOURCE_LOADING'
385
387
  | 'ANIMATION_IDLE_GOVERNED_BY_TURN_PAD'
386
388
  | 'ANIMATION_SOURCE_MISSING'
387
- | 'ANIMATION_NOT_IN_SOURCE';
389
+ | 'ANIMATION_NOT_IN_SOURCE'
390
+ | 'ANIMATION_COMPARE_READ_ONLY';
388
391
  reason: string | null;
389
392
  note: string | null;
390
393
  }
@@ -1039,6 +1042,7 @@ export function applyAnimationOp(
1039
1042
  text: string,
1040
1043
  op: AnimationSourceOp,
1041
1044
  baseText?: string,
1045
+ fallbackEasings?: Readonly<Record<string, EasingTuple>>,
1042
1046
  ): AppliedAnimationOpsResult {
1043
1047
  const { doc, classification, keys } = resolveEditableTrack(text, op.animation, op.track);
1044
1048
  const channels = classification.channels;
@@ -1217,7 +1221,10 @@ export function applyAnimationOp(
1217
1221
  if (op.ease === 'stepped') {
1218
1222
  throw new Error('ANIMATION_EASING_STEPPED_USE_CURVE: "stepped" is a curve mode; use curve: "stepped"');
1219
1223
  }
1220
- const easings = isRecord(doc.easings) ? doc.easings : {};
1224
+ const easings = {
1225
+ ...(fallbackEasings ?? {}),
1226
+ ...(isRecord(doc.easings) ? doc.easings : {}),
1227
+ };
1221
1228
  if (!Array.isArray(easings[op.ease])) {
1222
1229
  throw new Error(`ANIMATION_EASING_UNKNOWN: unknown easing "${op.ease}"`);
1223
1230
  }
@@ -1267,7 +1274,10 @@ export function applyAnimationOp(
1267
1274
  if (op.ease === 'stepped') {
1268
1275
  throw new Error('ANIMATION_EASING_STEPPED_USE_CURVE: "stepped" is a curve mode; use curve: "stepped"');
1269
1276
  }
1270
- const easings = isRecord(doc.easings) ? doc.easings : {};
1277
+ const easings = {
1278
+ ...(fallbackEasings ?? {}),
1279
+ ...(isRecord(doc.easings) ? doc.easings : {}),
1280
+ };
1271
1281
  if (!Array.isArray(easings[op.ease])) {
1272
1282
  throw new Error(`ANIMATION_EASING_UNKNOWN: unknown easing "${op.ease}"`);
1273
1283
  }
@@ -1397,14 +1407,251 @@ export function applyAnimationOps(
1397
1407
  text: string,
1398
1408
  ops: readonly AnimationSourceOp[],
1399
1409
  ): AppliedAnimationOpsResult {
1400
- let current = text;
1410
+ const builder = new AnimationOpBuilder(text);
1401
1411
  const allSpans: { start: number; end: number }[] = [];
1402
1412
  for (const op of ops) {
1403
- const res = applyAnimationOp(current, op, text);
1404
- current = res.text;
1413
+ const res = builder.apply(op);
1405
1414
  allSpans.push(...res.changedSpans);
1406
1415
  }
1407
- return { text: current, changedSpans: allSpans };
1416
+ return { text: builder.text, changedSpans: builder.dirty ? allSpans : [] };
1417
+ }
1418
+
1419
+ /** Canonical serialized form of an `AnimationSourceOp[]` list for deterministic hashing. */
1420
+ export function animationOpsText(ops: readonly AnimationSourceOp[]): string {
1421
+ return JSON.stringify(ops);
1422
+ }
1423
+
1424
+ /** Validate and normalize one `AnimationSourceOp` from an untrusted request or applied record. */
1425
+ export function parseAnimationSourceOp(value: unknown, field = 'op'): AnimationSourceOp {
1426
+ if (!isRecord(value) || typeof value.op !== 'string') {
1427
+ throw new Error(`${field}: expected an animation op object`);
1428
+ }
1429
+ const checkBase = () => {
1430
+ if (typeof value.animation !== 'string' || !value.animation) {
1431
+ throw new Error(`${field}.animation: expected non-empty string`);
1432
+ }
1433
+ if (!Number.isSafeInteger(value.track) || (value.track as number) < 0) {
1434
+ throw new Error(`${field}.track: expected non-negative integer`);
1435
+ }
1436
+ };
1437
+ const checkKey = () => {
1438
+ if (!Number.isSafeInteger(value.key) || (value.key as number) < 0) {
1439
+ throw new Error(`${field}.key: expected non-negative integer`);
1440
+ }
1441
+ };
1442
+ const keys = Object.keys(value).sort().join(',');
1443
+
1444
+ if (value.op === 'set_key_time') {
1445
+ if (keys !== 'animation,key,op,time,track') {
1446
+ throw new Error(`${field}: set_key_time expects {op, animation, track, key, time}`);
1447
+ }
1448
+ checkBase();
1449
+ checkKey();
1450
+ if (typeof value.time !== 'number' || !Number.isFinite(value.time) || value.time < 0) {
1451
+ throw new Error(`${field}.time: expected finite number >= 0`);
1452
+ }
1453
+ return {
1454
+ op: 'set_key_time',
1455
+ animation: value.animation as string,
1456
+ track: value.track as number,
1457
+ key: value.key as number,
1458
+ time: value.time,
1459
+ };
1460
+ }
1461
+
1462
+ if (value.op === 'set_key_value') {
1463
+ if (keys !== 'animation,key,op,track,value' && keys !== 'animation,channel,key,op,track,value') {
1464
+ throw new Error(`${field}: set_key_value expects {op, animation, track, key, channel?, value}`);
1465
+ }
1466
+ checkBase();
1467
+ checkKey();
1468
+ if (value.channel !== undefined) {
1469
+ if (!Number.isSafeInteger(value.channel) || (value.channel as number) < 0) {
1470
+ throw new Error(`${field}.channel: expected non-negative integer`);
1471
+ }
1472
+ if (typeof value.value !== 'number' || !Number.isFinite(value.value)) {
1473
+ throw new Error(`${field}.value: expected finite number when channel is given`);
1474
+ }
1475
+ return {
1476
+ op: 'set_key_value',
1477
+ animation: value.animation as string,
1478
+ track: value.track as number,
1479
+ key: value.key as number,
1480
+ channel: value.channel as number,
1481
+ value: value.value,
1482
+ };
1483
+ }
1484
+ if (
1485
+ !Array.isArray(value.value) ||
1486
+ value.value.length === 0 ||
1487
+ !value.value.every((n) => typeof n === 'number' && Number.isFinite(n))
1488
+ ) {
1489
+ throw new Error(`${field}.value: expected non-empty array of finite numbers`);
1490
+ }
1491
+ return {
1492
+ op: 'set_key_value',
1493
+ animation: value.animation as string,
1494
+ track: value.track as number,
1495
+ key: value.key as number,
1496
+ value: [...(value.value as number[])],
1497
+ };
1498
+ }
1499
+
1500
+ if (value.op === 'set_key_curve') {
1501
+ if (keys !== 'animation,curve,key,op,track') {
1502
+ throw new Error(`${field}: set_key_curve expects {op, animation, track, key, curve}`);
1503
+ }
1504
+ checkBase();
1505
+ checkKey();
1506
+ const c = value.curve;
1507
+ if (
1508
+ c !== null &&
1509
+ c !== 'stepped' &&
1510
+ (!Array.isArray(c) || c.length === 0 || !c.every((n) => typeof n === 'number' && Number.isFinite(n)))
1511
+ ) {
1512
+ throw new Error(`${field}.curve: expected "stepped", null, or array of finite numbers`);
1513
+ }
1514
+ return {
1515
+ op: 'set_key_curve',
1516
+ animation: value.animation as string,
1517
+ track: value.track as number,
1518
+ key: value.key as number,
1519
+ curve: Array.isArray(c) ? [...(c as number[])] : (c as 'stepped' | null),
1520
+ };
1521
+ }
1522
+
1523
+ if (value.op === 'set_key_ease') {
1524
+ if (keys !== 'animation,ease,key,op,track') {
1525
+ throw new Error(`${field}: set_key_ease expects {op, animation, track, key, ease}`);
1526
+ }
1527
+ checkBase();
1528
+ checkKey();
1529
+ if (value.ease !== null && (typeof value.ease !== 'string' || !value.ease)) {
1530
+ throw new Error(`${field}.ease: expected non-empty string or null`);
1531
+ }
1532
+ return {
1533
+ op: 'set_key_ease',
1534
+ animation: value.animation as string,
1535
+ track: value.track as number,
1536
+ key: value.key as number,
1537
+ ease: value.ease as string | null,
1538
+ };
1539
+ }
1540
+
1541
+ if (value.op === 'insert_key') {
1542
+ const allowed = new Set(['op', 'animation', 'track', 'time', 'value', 'curve', 'ease']);
1543
+ if (
1544
+ !Object.keys(value).every((k) => allowed.has(k)) ||
1545
+ !Object.hasOwn(value, 'time') ||
1546
+ !Object.hasOwn(value, 'value')
1547
+ ) {
1548
+ throw new Error(`${field}: insert_key expects {op, animation, track, time, value, curve?, ease?}`);
1549
+ }
1550
+ checkBase();
1551
+ if (typeof value.time !== 'number' || !Number.isFinite(value.time) || value.time < 0) {
1552
+ throw new Error(`${field}.time: expected finite number >= 0`);
1553
+ }
1554
+ if (
1555
+ !Array.isArray(value.value) ||
1556
+ value.value.length === 0 ||
1557
+ !value.value.every((n) => typeof n === 'number' && Number.isFinite(n))
1558
+ ) {
1559
+ throw new Error(`${field}.value: expected non-empty array of finite numbers`);
1560
+ }
1561
+ if (value.curve !== undefined) {
1562
+ const c = value.curve;
1563
+ if (
1564
+ c !== 'stepped' &&
1565
+ (!Array.isArray(c) || c.length === 0 || !c.every((n) => typeof n === 'number' && Number.isFinite(n)))
1566
+ ) {
1567
+ throw new Error(`${field}.curve: expected "stepped" or array of finite numbers`);
1568
+ }
1569
+ }
1570
+ if (value.ease !== undefined && (typeof value.ease !== 'string' || !value.ease)) {
1571
+ throw new Error(`${field}.ease: expected non-empty string`);
1572
+ }
1573
+ return {
1574
+ op: 'insert_key',
1575
+ animation: value.animation as string,
1576
+ track: value.track as number,
1577
+ time: value.time,
1578
+ value: [...(value.value as number[])],
1579
+ ...(value.curve !== undefined
1580
+ ? { curve: Array.isArray(value.curve) ? [...(value.curve as number[])] : 'stepped' }
1581
+ : {}),
1582
+ ...(value.ease !== undefined ? { ease: value.ease as string } : {}),
1583
+ };
1584
+ }
1585
+
1586
+ if (value.op === 'delete_key') {
1587
+ if (keys !== 'animation,key,op,track') {
1588
+ throw new Error(`${field}: delete_key expects {op, animation, track, key}`);
1589
+ }
1590
+ checkBase();
1591
+ checkKey();
1592
+ return {
1593
+ op: 'delete_key',
1594
+ animation: value.animation as string,
1595
+ track: value.track as number,
1596
+ key: value.key as number,
1597
+ };
1598
+ }
1599
+
1600
+ throw new Error(`${field}.op: unknown operation "${String(value.op)}"`);
1601
+ }
1602
+
1603
+ function coalesceSetKeyValueOp(
1604
+ textBefore: string,
1605
+ prevOp: Extract<AnimationSourceOp, { op: 'set_key_value' }>,
1606
+ nextOp: Extract<AnimationSourceOp, { op: 'set_key_value' }>,
1607
+ ): Extract<AnimationSourceOp, { op: 'set_key_value' }> {
1608
+ if (nextOp.channel === undefined || prevOp.channel === nextOp.channel) {
1609
+ return nextOp;
1610
+ }
1611
+ const { classification, keys } = resolveEditableTrack(
1612
+ textBefore,
1613
+ nextOp.animation,
1614
+ nextOp.track,
1615
+ );
1616
+ const channels = classification.channels;
1617
+ const baseKey = keys[nextOp.key];
1618
+ if (!baseKey) return nextOp;
1619
+ const merged = [...baseKey.v];
1620
+ if (prevOp.channel !== undefined) {
1621
+ if (
1622
+ Number.isInteger(prevOp.channel) &&
1623
+ prevOp.channel >= 0 &&
1624
+ prevOp.channel < channels &&
1625
+ typeof prevOp.value === 'number' &&
1626
+ Number.isFinite(prevOp.value)
1627
+ ) {
1628
+ merged[prevOp.channel] = cleanMotionNumber(prevOp.value);
1629
+ }
1630
+ } else if (Array.isArray(prevOp.value) && prevOp.value.length === channels) {
1631
+ for (let c = 0; c < channels; c++) {
1632
+ const v = prevOp.value[c];
1633
+ if (typeof v === 'number' && Number.isFinite(v)) {
1634
+ merged[c] = cleanMotionNumber(v);
1635
+ }
1636
+ }
1637
+ }
1638
+ if (
1639
+ !Number.isInteger(nextOp.channel) ||
1640
+ nextOp.channel < 0 ||
1641
+ nextOp.channel >= channels ||
1642
+ typeof nextOp.value !== 'number' ||
1643
+ !Number.isFinite(nextOp.value)
1644
+ ) {
1645
+ return nextOp;
1646
+ }
1647
+ merged[nextOp.channel] = cleanMotionNumber(nextOp.value);
1648
+ return {
1649
+ op: 'set_key_value',
1650
+ animation: nextOp.animation,
1651
+ track: nextOp.track,
1652
+ key: nextOp.key,
1653
+ value: merged,
1654
+ };
1408
1655
  }
1409
1656
 
1410
1657
  /**
@@ -1414,11 +1661,13 @@ export function applyAnimationOps(
1414
1661
  */
1415
1662
  export class AnimationOpBuilder {
1416
1663
  readonly baseText: string;
1664
+ readonly fallbackEasings?: Readonly<Record<string, EasingTuple>>;
1417
1665
  private currentText: string;
1418
1666
  private readonly history: Array<{ op: AnimationSourceOp; textBefore: string }> = [];
1419
1667
 
1420
- constructor(baseText: string) {
1668
+ constructor(baseText: string, fallbackEasings?: Readonly<Record<string, EasingTuple>>) {
1421
1669
  this.baseText = baseText;
1670
+ this.fallbackEasings = fallbackEasings;
1422
1671
  this.currentText = baseText;
1423
1672
  }
1424
1673
 
@@ -1435,12 +1684,157 @@ export class AnimationOpBuilder {
1435
1684
  }
1436
1685
 
1437
1686
  apply(op: AnimationSourceOp): AppliedAnimationOpsResult {
1438
- const res = applyAnimationOp(this.currentText, op, this.baseText);
1687
+ const last = this.history.at(-1);
1688
+ const sameKeyTarget =
1689
+ last !== undefined &&
1690
+ last.op.animation === op.animation &&
1691
+ last.op.track === op.track &&
1692
+ 'key' in last.op &&
1693
+ 'key' in op &&
1694
+ last.op.key === op.key;
1695
+
1696
+ if (
1697
+ sameKeyTarget &&
1698
+ ((op.op === 'set_key_time' && last.op.op === 'set_key_time') ||
1699
+ (op.op === 'set_key_value' && last.op.op === 'set_key_value') ||
1700
+ ((op.op === 'set_key_curve' || op.op === 'set_key_ease') &&
1701
+ (last.op.op === 'set_key_curve' || last.op.op === 'set_key_ease')))
1702
+ ) {
1703
+ const replayFrom = last.textBefore;
1704
+ const coalescedOp =
1705
+ op.op === 'set_key_value' && last.op.op === 'set_key_value'
1706
+ ? coalesceSetKeyValueOp(replayFrom, last.op, op)
1707
+ : op;
1708
+ const res = applyAnimationOp(replayFrom, coalescedOp, this.baseText, this.fallbackEasings);
1709
+ this.history.pop();
1710
+ if (res.text === this.baseText) {
1711
+ this.history.length = 0;
1712
+ this.currentText = this.baseText;
1713
+ return { text: this.baseText, changedSpans: [] };
1714
+ }
1715
+ if (res.text === replayFrom) {
1716
+ this.currentText = replayFrom;
1717
+ return { text: replayFrom, changedSpans: [] };
1718
+ }
1719
+ this.history.push({ op: coalescedOp, textBefore: replayFrom });
1720
+ this.currentText = res.text;
1721
+ return res;
1722
+ }
1723
+
1724
+ const res = applyAnimationOp(this.currentText, op, this.baseText, this.fallbackEasings);
1725
+ if (res.text === this.baseText) {
1726
+ this.history.length = 0;
1727
+ this.currentText = this.baseText;
1728
+ return { text: this.baseText, changedSpans: [] };
1729
+ }
1730
+ if (res.text === this.currentText) {
1731
+ return { text: this.currentText, changedSpans: [] };
1732
+ }
1733
+ if (this.history.length >= MAX_ANIMATION_OPS) {
1734
+ throw new Error(
1735
+ `ANIMATION_OPS_TOO_MANY: pending operations cannot exceed MAX_ANIMATION_OPS (${MAX_ANIMATION_OPS})`,
1736
+ );
1737
+ }
1439
1738
  this.history.push({ op, textBefore: this.currentText });
1440
1739
  this.currentText = res.text;
1441
1740
  return res;
1442
1741
  }
1443
1742
 
1743
+ /**
1744
+ * Move a selection of `(track, key)` pairs in `animation` by `deltaTime` seconds
1745
+ * atomically. When `deltaTime > 0`, keys on the same track are moved from right to left
1746
+ * so an earlier key does not collide with its not-yet-moved right neighbor; when
1747
+ * `deltaTime < 0`, from left to right. Refuses with `ANIMATION_OPS_TOO_MANY` (restoring
1748
+ * the builder's prior state) if the move would exceed `MAX_ANIMATION_OPS`.
1749
+ */
1750
+ moveSelection(
1751
+ animation: string,
1752
+ selections: ReadonlyArray<{ track: number; key: number }>,
1753
+ deltaTime: number,
1754
+ ): AppliedAnimationOpsResult {
1755
+ if (!Number.isFinite(deltaTime)) {
1756
+ throw new Error(`ANIMATION_KEY_TIME_INVALID: deltaTime must be finite, got ${String(deltaTime)}`);
1757
+ }
1758
+ if (selections.length === 0 || deltaTime === 0) {
1759
+ return { text: this.currentText, changedSpans: [] };
1760
+ }
1761
+ const byTrack = new Map<number, number[]>();
1762
+ for (const sel of selections) {
1763
+ let arr = byTrack.get(sel.track);
1764
+ if (!arr) {
1765
+ arr = [];
1766
+ byTrack.set(sel.track, arr);
1767
+ }
1768
+ if (!arr.includes(sel.key)) arr.push(sel.key);
1769
+ }
1770
+ const totalSelected = [...byTrack.values()].reduce((acc, a) => acc + a.length, 0);
1771
+ if (totalSelected > MAX_ANIMATION_OPS) {
1772
+ throw new Error(
1773
+ `ANIMATION_OPS_TOO_MANY: selection move of ${totalSelected} keys exceeds MAX_ANIMATION_OPS (${MAX_ANIMATION_OPS})`,
1774
+ );
1775
+ }
1776
+ const savedText = this.currentText;
1777
+ const savedHistory = this.history.map((h) => ({ ...h }));
1778
+ const changedSpans: { start: number; end: number }[] = [];
1779
+ try {
1780
+ const sortedTracks = [...byTrack.keys()].sort((a, b) => a - b);
1781
+ const targetTimes = new Map<string, number>();
1782
+ for (const track of sortedTracks) {
1783
+ const { keys } = resolveEditableTrack(this.currentText, animation, track);
1784
+ for (const key of byTrack.get(track)!) {
1785
+ const k = keys[key];
1786
+ if (!k) {
1787
+ throw new Error(`ANIMATION_KEY_OUT_OF_RANGE: key index ${key} out of [0, ${keys.length - 1}]`);
1788
+ }
1789
+ targetTimes.set(`${track}:${key}`, cleanMotionNumber(k.t + deltaTime));
1790
+ }
1791
+ }
1792
+
1793
+ // Coalesce with a trailing batch of set_key_time ops on the same selection
1794
+ let suffixStart = this.history.length;
1795
+ while (suffixStart > 0) {
1796
+ const prev = this.history[suffixStart - 1]!.op;
1797
+ if (
1798
+ prev.op === 'set_key_time' &&
1799
+ prev.animation === animation &&
1800
+ targetTimes.has(`${prev.track}:${prev.key}`)
1801
+ ) {
1802
+ suffixStart--;
1803
+ } else {
1804
+ break;
1805
+ }
1806
+ }
1807
+ if (suffixStart < this.history.length) {
1808
+ this.currentText = this.history[suffixStart]!.textBefore;
1809
+ this.history.length = suffixStart;
1810
+ }
1811
+
1812
+ for (const track of sortedTracks) {
1813
+ const { keys } = resolveEditableTrack(this.currentText, animation, track);
1814
+ const keyIndices = [...byTrack.get(track)!].sort((a, b) => {
1815
+ const shiftA = targetTimes.get(`${track}:${a}`)! - keys[a]!.t;
1816
+ return shiftA >= 0 ? b - a : a - b;
1817
+ });
1818
+ for (const key of keyIndices) {
1819
+ const res = this.apply({
1820
+ op: 'set_key_time',
1821
+ animation,
1822
+ track,
1823
+ key,
1824
+ time: targetTimes.get(`${track}:${key}`)!,
1825
+ });
1826
+ changedSpans.push(...res.changedSpans);
1827
+ }
1828
+ }
1829
+ return { text: this.currentText, changedSpans };
1830
+ } catch (err) {
1831
+ this.currentText = savedText;
1832
+ this.history.length = 0;
1833
+ this.history.push(...savedHistory);
1834
+ throw err;
1835
+ }
1836
+ }
1837
+
1444
1838
  undo(): boolean {
1445
1839
  const last = this.history.pop();
1446
1840
  if (!last) return false;
@@ -1459,10 +1853,21 @@ export class AnimationOpBuilder {
1459
1853
  // Pending-preview adapter into src/animation-inspection.ts (Correction 7)
1460
1854
  // ---------------------------------------------------------------------------
1461
1855
 
1856
+ const KEY_TIME_GRID = 360000;
1857
+
1462
1858
  function f32(n: number): number {
1463
1859
  return Math.fround(n);
1464
1860
  }
1465
1861
 
1862
+ /**
1863
+ * Match `@rig-c/core/src/compile.ts` `keyTime(n)`: snap times within 5e-7 of the
1864
+ * 1/360000s grid before Float32 rounding so preview keys match compiled keys.
1865
+ */
1866
+ export function compiledKeyTime(n: number): number {
1867
+ const grid = Math.round(n * KEY_TIME_GRID) / KEY_TIME_GRID;
1868
+ return f32(Math.abs(n - grid) <= 5e-7 ? grid : n);
1869
+ }
1870
+
1466
1871
  function resolveKeyCurveForInspection(
1467
1872
  key: { t: number; v: readonly number[]; ease?: string; curve?: readonly number[] | 'stepped' },
1468
1873
  nextKey: { t: number; v: readonly number[] } | undefined,
@@ -1470,7 +1875,7 @@ function resolveKeyCurveForInspection(
1470
1875
  ): number[] | 'stepped' | undefined {
1471
1876
  if (!nextKey) return undefined;
1472
1877
  if (key.curve !== undefined) {
1473
- return key.curve === 'stepped' ? 'stepped' : [...key.curve];
1878
+ return key.curve === 'stepped' ? 'stepped' : key.curve.map(f32);
1474
1879
  }
1475
1880
  if (key.ease === undefined) return undefined;
1476
1881
  if (key.ease === 'stepped') return 'stepped';
@@ -1486,10 +1891,10 @@ function resolveKeyCurveForInspection(
1486
1891
  const v1 = key.v[c]!;
1487
1892
  const dv = nextKey.v[c]! - v1;
1488
1893
  out.push(
1489
- cleanMotionNumber(key.t + dt * hx1),
1490
- cleanMotionNumber(v1 + dv * hy1),
1491
- cleanMotionNumber(key.t + dt * hx2),
1492
- cleanMotionNumber(v1 + dv * hy2),
1894
+ f32(key.t + dt * hx1),
1895
+ f32(v1 + dv * hy1),
1896
+ f32(key.t + dt * hx2),
1897
+ f32(v1 + dv * hy2),
1493
1898
  );
1494
1899
  }
1495
1900
  return out;
@@ -1519,9 +1924,9 @@ export function draftTrackToInspectionTrack(
1519
1924
  throw new Error(`ANIMATION_TRACK_READ_ONLY: unsupported bone property "${track.property}"`);
1520
1925
  }
1521
1926
  const storedKeys: StoredKey[] = track.keys.map((k, idx) => {
1522
- const entry: StoredKey = { time: k.t };
1927
+ const entry: StoredKey = { time: compiledKeyTime(k.t) };
1523
1928
  channelSpec.forEach((ch, c) => {
1524
- entry[ch.field] = k.v[c]!;
1929
+ entry[ch.field] = f32(k.v[c]!);
1525
1930
  });
1526
1931
  const curve = resolveKeyCurveForInspection(k, track.keys[idx + 1], easings);
1527
1932
  if (curve !== undefined) {
@@ -1546,6 +1951,7 @@ export function draftTrackToInspectionTrack(
1546
1951
  export function overlayDraftOnInspection(
1547
1952
  inspection: AnimationInspection,
1548
1953
  draftMotionText: string,
1954
+ fallbackEasings?: Readonly<Record<string, EasingTuple>>,
1549
1955
  ): AnimationInspection {
1550
1956
  const doc = JSON.parse(draftMotionText) as Record<string, unknown>;
1551
1957
  if (!isRecord(doc.animations)) return inspection;
@@ -1553,9 +1959,13 @@ export function overlayDraftOnInspection(
1553
1959
  if (!isRecord(anim) || !Array.isArray(anim.tracks)) return inspection;
1554
1960
  const rawTracks = anim.tracks as unknown[];
1555
1961
 
1556
- const easings = isRecord(doc.easings)
1557
- ? (doc.easings as Readonly<Record<string, EasingTuple>>)
1558
- : undefined;
1962
+ const easings: Readonly<Record<string, EasingTuple>> | undefined =
1963
+ isRecord(doc.easings) || fallbackEasings
1964
+ ? {
1965
+ ...(fallbackEasings ?? {}),
1966
+ ...(isRecord(doc.easings) ? (doc.easings as Readonly<Record<string, EasingTuple>>) : {}),
1967
+ }
1968
+ : undefined;
1559
1969
  const classifications = classifyAnimationTracks(doc, inspection.name);
1560
1970
  const replacementByKey = new Map<string, InspectionTrack>();
1561
1971