rig-parts 2.75.0 → 2.76.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/cli.ts CHANGED
@@ -59,7 +59,7 @@ import { decodePngBytes, readPng, writePng } from './src/raster/png.ts';
59
59
  import { REQUIREMENTS_SENTENCE } from './src/requirements.ts';
60
60
  import { replacementTreeDigest } from './src/replacementrecord.ts';
61
61
  import { clearComposeSeams, readComposeSeamRequest, verifyComposeSeams } from './src/compose-seams.ts';
62
- import { type ComposeInput, composeStage, IMAGE_SEP, PLATE, PROVENANCES, refusePreviewLoopSeam, SCENE_CAMERA_REPORT_SPEC, SCENE_REPORT_FILE, SCENE_REPORT_SPEC, SCENE_SPEC } from './src/scene.ts';
62
+ import { clearComposeRefusal, type ComposeInput, composeStage, IMAGE_SEP, isComposePreviewWithLoopSeam, PLATE, PROVENANCES, SCENE_CAMERA_REPORT_SPEC, SCENE_REPORT_FILE, SCENE_REPORT_SPEC, SCENE_SPEC } from './src/scene.ts';
63
63
  import { buildSheet, defaultCaption, type Tile, tilesFrom } from './src/sheet.ts';
64
64
  import { loadComparison, requiredProblems, structureLines } from './src/structure.ts';
65
65
  import { type ArgvTable, assembleOutputFiles, bindAssembleWrapperInputs, buildAllocationOutputFiles, BUILD_RUN_FILE, type BuildWrapperRole, CHECK_RUN_FILE, clearComposeRun, clearRunRecord, clearRunStamp, readPackageIdentity, realWhereItExists, recordArgv, rigOutputFiles, RUN_STAMP_FILE, RUN_STAMP_SPEC, type RunStampFileEntry, type RunStampInputEntry, writeRunRecord, writeRunStamp } from './src/runstamp.ts';
@@ -1693,8 +1693,7 @@ function cmdRig(args: string[]): number {
1693
1693
  * version ({@link rigcRunnerAt}, issue #337), and every refusal quoting it says so.
1694
1694
  */
1695
1695
  /** Read the command's required and optional `--flag value` pairs, and collect its bare switches in `on` when supplied. A string is a usage error. */
1696
- function flags(args: string[], command: Command, required: readonly string[], on?: Set<string>): Map<string, string> | string {
1697
- const got = new Map<string, string>();
1696
+ function flags(args: string[], command: Command, required: readonly string[], on?: Set<string>, got = new Map<string, string>()): Map<string, string> | string {
1698
1697
  const switches: readonly string[] = TAKES[command].switches;
1699
1698
  for (let i = 0; i < args.length; i++) {
1700
1699
  const flag = args[i];
@@ -2722,7 +2721,11 @@ function cmdBuild(args: string[]): number {
2722
2721
 
2723
2722
  function cmdCompose(args: string[]): number {
2724
2723
  const on = new Set<string>();
2725
- const f = flags(args, 'compose', [], on);
2724
+ // Keep an output that was parsed before a later syntax error so this invocation clears its stale refusal.
2725
+ const values = new Map<string, string>();
2726
+ const f = flags(args, 'compose', [], on, values);
2727
+ const out = values.get('--out');
2728
+ if (out !== undefined) clearComposeRefusal(out);
2726
2729
  if (typeof f === 'string') return usage(f);
2727
2730
  const seamRequest = f.get('--motion-seams');
2728
2731
  const verifySeams = f.get('--verify-motion-seams');
@@ -2736,13 +2739,14 @@ function cmdCompose(args: string[]): number {
2736
2739
  return printRefusal(err);
2737
2740
  }
2738
2741
  }
2739
- for (const required of ['--scene', '--out']) if (!f.has(required)) return usage(`compose needs ${required} <value>`);
2742
+ const scene = f.get('--scene');
2743
+ if (scene === undefined) return usage('compose needs --scene <value>');
2744
+ if (out === undefined) return usage('compose needs --out <value>');
2740
2745
  const profile = f.get('--output-profile');
2741
2746
  if (profile !== undefined && profile !== 'preview') return usage(`--output-profile ${JSON.stringify(profile)}; preview is required when this flag is given`);
2742
2747
  const outputProfile = profile ?? (on.has('--no-extremes') ? 'no-extremes' : undefined);
2743
2748
  const loopSeam = parseLoopSeamFlags(f);
2744
2749
  if (typeof loopSeam === 'string') return usage(loopSeam);
2745
- const out = f.get('--out') as string;
2746
2750
  clearComposeRun(out);
2747
2751
  clearComposeSeams(out);
2748
2752
  let input: ComposeInput;
@@ -2752,16 +2756,19 @@ function cmdCompose(args: string[]): number {
2752
2756
  const accept = f.get('--accept');
2753
2757
  const motionSeams = seamRequest === undefined ? undefined : readComposeSeamRequest(seamRequest);
2754
2758
  input = {
2755
- scene: f.get('--scene') as string, out, ...(size === undefined ? {} : { pageSize: size }),
2759
+ scene, out, ...(size === undefined ? {} : { pageSize: size }),
2756
2760
  ...(req === undefined ? {} : { requirements: req }), ...(accept === undefined ? {} : { accept: accept.split(',') }),
2757
2761
  ...(loopSeam === undefined ? {} : { loopSeam }),
2758
2762
  ...(motionSeams === undefined ? {} : { motionSeams }),
2759
2763
  ...(outputProfile === undefined ? {} : { outputProfile }),
2760
2764
  };
2761
- refusePreviewLoopSeam(input);
2762
2765
  } catch (err) {
2763
2766
  return printRefusal(err);
2764
2767
  }
2768
+ if (isComposePreviewWithLoopSeam(input)) {
2769
+ const r = composeStage(input, printRefusal, console.log);
2770
+ return r.stoppedAt === null ? EXIT_OK : EXIT_REFUSED;
2771
+ }
2765
2772
  let bin: string;
2766
2773
  try {
2767
2774
  bin = findRigc(import.meta.dir, process.env.PATH ?? '');
package/docs/AUTHORING.md CHANGED
@@ -7734,9 +7734,16 @@ certify visible cloth movement.
7734
7734
  one of the links identified by the hang-bone walk is unmeasured when the larger of
7735
7735
  its unrounded root and tip travels is below **0.5 rig px**. Its row retains both travels, the ratio,
7736
7736
  the world reading and `travel_floor_rig_px: 0.5`, with `unmeasured` giving
7737
- "below half a rig pixel: the motion does not show on the art's own grid". If every
7738
- row is unmeasured the line is SKIP and retains those rows. In a mixed line the
7739
- measured rows decide PASS or FAIL.
7737
+ "below half a rig pixel: the motion does not show on the art's own grid" and
7738
+ `unmeasured_reason: "below_travel_floor"` (issue #1696; the other unmeasured row
7739
+ reasons are `declared_not_swinging`, `limb_segment`, `hybrid_band`,
7740
+ `no_attachment` and `empty_half`). When `measured_driver` names a bone (neither
7741
+ `"none"` nor `"unavailable"`), a `below_travel_floor` row indicates planned
7742
+ motion that does not show on the art's grid. If every row is unmeasured the line
7743
+ is SKIP and retains those rows, with `bar_outcomes.TIP_OVER_ROOT.reason` set to
7744
+ `"below-travel-floor"` when every unmeasured row is `below_travel_floor` and
7745
+ `"no-reading"` for any other reason or mix. In a mixed line with at least one
7746
+ measured row, the measured rows decide PASS or FAIL.
7740
7747
 
7741
7748
  Half a rig pixel is the art-grid threshold fixed before measurement, taking one
7742
7749
  rig pixel as the grid unit. The larger-travel operand was amended after measuring
@@ -8980,6 +8987,63 @@ byte changes its input entry's hash. If multiple entries reference one physical
8980
8987
  each reference changes. Missing scene, build and plate files retain their named
8981
8988
  `SCENE_FILE`, `SCENE_BUILD_PRESENT` and `SCENE_PLATE_PRESENT` refusals.
8982
8989
 
8990
+ #### Compose refusal report (issue #1690)
8991
+
8992
+ `compose` writes `<out>/compose-refusal.json` with spec
8993
+ `rig-compose-refusal/1` when a scene or its inputs cause a compose, check, or
8994
+ motion-seams stage refusal. The report covers refusals about the scene and its inputs,
8995
+ not about the invocation or the environment.
8996
+
8997
+ The fixed top-level key order is `spec`, `parts_version`, `scene`, `stage`,
8998
+ `count`, and `findings`. The contract is `spec`, `stage`, `count`, `scene`,
8999
+ and each finding's `code`, `object` and `data`. `detail` is the console
9000
+ sentence for a reader. It may be reworded in any release, and a consumer
9001
+ must not parse it.
9002
+
9003
+ The `scene` entry is `{path, sha256}`. It records the path as supplied and the
9004
+ SHA-256 of the scene file's bytes. An unreadable scene file is reported as a
9005
+ finding and has a null hash. The closed set of `stage` values for
9006
+ `rig-compose-refusal/1` is `"compose"`, `"check"`, and `"motion-seams"`.
9007
+ Adding a stage after 2.76.0 is a breaking change. A consumer treats an
9008
+ unknown stage as an unknown refusal. `count` counts the findings in emission
9009
+ order, each with keys `code`, `object`, `detail`, and `data`.
9010
+
9011
+ | Code | `data` |
9012
+ | --- | --- |
9013
+ | `SCENE_WITH_IDLE_DURATION` | `{idle_period, clip_period, search: {limit, result}}`. Periods are in seconds. The limit is 10000 copies of each period. The result is `{found: {idle_repeats, with_idle}}`, `{none: "limit"}`, or `{none: "non_finite"}`. |
9014
+
9015
+ `data` is null for every code not in the table. Adding a `data` shape for
9016
+ another code later is additive. Changing a listed shape is breaking. A
9017
+ consumer treats an unknown code as an unknown refusal, not as an error in
9018
+ the report.
9019
+
9020
+ At `stage: "check"`, the composed `rig/` is present. `scene.json` is present
9021
+ for a scene without a camera. For a camera scene, `scene.json` is present
9022
+ only if the check's packed build bound to the camera audit before the
9023
+ check refused. Otherwise it is absent. `compose-run.json` is absent.
9024
+
9025
+ At `stage: "motion-seams"`, `rig/`, `check/`, and `scene.json` retain the
9026
+ outputs of the completed check. Each finding's `object` is the console's
9027
+ object; for `COMPOSE_MOTION_SEAMS_ANIMATION` and
9028
+ `COMPOSE_MOTION_SEAMS_SAMPLE` it is the requested take.
9029
+ `compose-run.json` is absent.
9030
+
9031
+ Read the end state from disk. A present `compose-run.json` means the run is
9032
+ green. A present `compose-refusal.json` means the run was refused and
9033
+ `stage` tells where. For an invocation that reaches compose and stops
9034
+ normally without either report, `check/check.json` says `PASS: false` or
9035
+ `scene.json` names a character with an `accepted` bar. Accepting a failing
9036
+ character exits 1 and leaves no green `compose-run.json`, because an
9037
+ accepted failing bar never makes the scene green (issue #203). When neither
9038
+ report nor `check/check.json` is present, possible causes include CLI usage
9039
+ refusals, Core discovery refusal, a malformed motion-seams request refused
9040
+ before an output directory is created, and a crash that is not a refusal.
9041
+ Consumers must never infer a failed check from receipt absence alone.
9042
+
9043
+ The two report files are mutually exclusive. A refusal following a green
9044
+ run in the same output directory leaves only `compose-refusal.json` of the
9045
+ pair. A subsequent green run leaves only `compose-run.json` of the pair.
9046
+
8983
9047
 
8984
9048
  ### Declared requirements (`--requirements`)
8985
9049
 
@@ -11270,8 +11334,8 @@ Internal `SeamSupport.drawings` never enters check JSON. Named requirement
11270
11334
  | `SEAM_OVER_MOTION.required.pairs[].open_frames` | `SEAM_OVER_MOTION.required.pairs[].open_frames`; `characters.*.SEAM_OVER_MOTION.required.pairs[].open_frames` | 'pair' | evidence | [p.a, p.b] | [check.ts:5321](../src/check.ts#L5321) |
11271
11335
  | `SEAM_OVER_MOTION.roots.unmeasured` | `SEAM_OVER_MOTION.roots.unmeasured`; `characters.*.SEAM_OVER_MOTION.roots.unmeasured` | 'part' | evidence | [root.part] | [check.ts:5995](../src/check.ts#L5995) |
11272
11336
  | `SEAM_OVER_MOTION.rows` | `SEAM_OVER_MOTION.rows`; `characters.*.SEAM_OVER_MOTION.rows` | 'pair'; unique ? 'pair' : 'rig' | finding when motionSeamFinding(want.root !== undefined, p.status, p.banded, opens.length); otherwise evidence; finding when motionSeamFinding(rootNames.has(r.pair), r.status, r.banded, r.opens.length); otherwise evidence | [want.a, want.b]; unique ? [pair.a, pair.b] : [] | [check.ts:5952](../src/check.ts#L5952), [check.ts:6028](../src/check.ts#L6028) |
11273
- | `SEAM_OVER_MOTION.rows[].cells` | `SEAM_OVER_MOTION.rows[].cells`; `characters.*.SEAM_OVER_MOTION.rows[].cells` | 'pair' | evidence | [want.a, want.b]; subjects | [check.ts:5965](../src/check.ts#L5965), [check.ts:12487](../src/check.ts#L12487) |
11274
- | `SEAM_OVER_MOTION.rows[].joint_contact.reasons` | `SEAM_OVER_MOTION.rows[].joint_contact.reasons`; `characters.*.SEAM_OVER_MOTION.rows[].joint_contact.reasons` | 'pair' | evidence | [want.a, want.b]; subjects | [check.ts:5955](../src/check.ts#L5955), [check.ts:12478](../src/check.ts#L12478) |
11337
+ | `SEAM_OVER_MOTION.rows[].cells` | `SEAM_OVER_MOTION.rows[].cells`; `characters.*.SEAM_OVER_MOTION.rows[].cells` | 'pair' | evidence | [want.a, want.b]; subjects | [check.ts:5965](../src/check.ts#L5965), [check.ts:12505](../src/check.ts#L12505) |
11338
+ | `SEAM_OVER_MOTION.rows[].joint_contact.reasons` | `SEAM_OVER_MOTION.rows[].joint_contact.reasons`; `characters.*.SEAM_OVER_MOTION.rows[].joint_contact.reasons` | 'pair' | evidence | [want.a, want.b]; subjects | [check.ts:5955](../src/check.ts#L5955), [check.ts:12496](../src/check.ts#L12496) |
11275
11339
  | `SEAM_OVER_MOTION.rows[].pose_at_worst.joints` | `SEAM_OVER_MOTION.rows[].pose_at_worst.joints`; `characters.*.SEAM_OVER_MOTION.rows[].pose_at_worst.joints` | 'rig' | evidence | [] | [motionseampose.ts:53](../src/motionseampose.ts#L53) |
11276
11340
  | `SEAM_OVER_MOTION.worlds.*.rows` | `SEAM_OVER_MOTION.worlds.*.rows`; `characters.*.SEAM_OVER_MOTION.worlds.*.rows` | 'pair' | evidence | [want.a, want.b] | [check.ts:5949](../src/check.ts#L5949) |
11277
11341
  | `SEAM_OVER_RANGE.joints` | `SEAM_OVER_RANGE.joints`; `characters.*.SEAM_OVER_RANGE.joints` | 'part' | evidence; finding when poses.some(p => p.status === 'FAIL'); otherwise evidence | [j.part] | [check.ts:4983](../src/check.ts#L4983), [check.ts:5029](../src/check.ts#L5029) |
@@ -11281,30 +11345,30 @@ Internal `SeamSupport.drawings` never enters check JSON. Named requirement
11281
11345
  | `SETUP_SEAM_TRANSMISSION.rows` | `SETUP_SEAM_TRANSMISSION.rows` | 'pair' | evidence | [under, over] | [coincide.ts:453](../src/coincide.ts#L453) |
11282
11346
  | `SOURCE_EXPOSURE.rows` | `SOURCE_EXPOSURE.rows` | 'part' | finding when declared !== undefined && r.px > declared.max_px; otherwise evidence | [r.part] | [sourceexposure.ts:292](../src/sourceexposure.ts#L292) |
11283
11347
  | `SOURCE_EXPOSURE.unmeasured` | `SOURCE_EXPOSURE.unmeasured` | part when the supplied mapping resolves a piece; otherwise rig | finding when declared !== undefined; otherwise evidence | resolved piece for u.slot; otherwise [] | [sourceexposure.ts:293](../src/sourceexposure.ts#L293) |
11284
- | `STILL_REGIONS_DARK.*.crossing` | `STILL_REGIONS_DARK.*.crossing`; `characters.*.STILL_REGIONS_DARK.*.crossing` | part when the supplied mapping resolves a piece; otherwise rig | finding | resolved piece for sl.name; otherwise [] | [check.ts:10144](../src/check.ts#L10144) |
11285
- | `STILL_REGIONS_DARK.*.still_slots` | `STILL_REGIONS_DARK.*.still_slots`; `characters.*.STILL_REGIONS_DARK.*.still_slots` | part when the supplied mapping resolves a piece; otherwise rig | evidence; finding when r.max > tolerance; otherwise evidence | resolved piece for slot; otherwise [] | [check.ts:10130](../src/check.ts#L10130), [check.ts:10135](../src/check.ts#L10135) |
11348
+ | `STILL_REGIONS_DARK.*.crossing` | `STILL_REGIONS_DARK.*.crossing`; `characters.*.STILL_REGIONS_DARK.*.crossing` | part when the supplied mapping resolves a piece; otherwise rig | finding | resolved piece for sl.name; otherwise [] | [check.ts:10162](../src/check.ts#L10162) |
11349
+ | `STILL_REGIONS_DARK.*.still_slots` | `STILL_REGIONS_DARK.*.still_slots`; `characters.*.STILL_REGIONS_DARK.*.still_slots` | part when the supplied mapping resolves a piece; otherwise rig | evidence; finding when r.max > tolerance; otherwise evidence | resolved piece for slot; otherwise [] | [check.ts:10148](../src/check.ts#L10148), [check.ts:10153](../src/check.ts#L10153) |
11286
11350
  | `STRESS_OFF_CHAIN.not_read` | `STRESS_OFF_CHAIN.not_read`; `characters.*.STRESS_OFF_CHAIN.not_read` | 'part' | evidence | [r.part] | [check.ts:4574](../src/check.ts#L4574) |
11287
11351
  | `STRESS_OFF_CHAIN.per_part` | `STRESS_OFF_CHAIN.per_part`; `characters.*.STRESS_OFF_CHAIN.per_part` | 'part' | finding when poses.some(p => typeof p.reading === 'number' && p.reading > STRESS_RIGID); otherwise evidence | [r.part] | [check.ts:4562](../src/check.ts#L4562) |
11288
11352
  | `STRESS_OFF_CHAIN.per_part[].off_chain` | `STRESS_OFF_CHAIN.per_part[].off_chain`; `characters.*.STRESS_OFF_CHAIN.per_part[].off_chain` | 'part' | evidence | [r.part] | [check.ts:4562](../src/check.ts#L4562) |
11289
11353
  | `STRESS_OFF_CHAIN.per_part[].poses` | `STRESS_OFF_CHAIN.per_part[].poses`; `characters.*.STRESS_OFF_CHAIN.per_part[].poses` | 'part' | evidence; finding when shown > STRESS_RIGID; otherwise evidence | [r.part] | [check.ts:4530](../src/check.ts#L4530), [check.ts:4548](../src/check.ts#L4548) |
11290
- | `TEXTURE_STRETCH.per_mesh` | `TEXTURE_STRETCH.per_mesh` | part when the supplied mapping resolves a piece; otherwise rig | evidence; finding when exceeds; otherwise evidence | resolved piece for m.slot; otherwise [] | [check.ts:11340](../src/check.ts#L11340), [check.ts:11347](../src/check.ts#L11347) |
11291
- | `TIP_OVER_ROOT.parts` | `TIP_OVER_ROOT.parts`; `characters.*.TIP_OVER_ROOT.parts` | 'part' | evidence; finding when !ok && !(!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR); otherwise evidence | [p.name] | [check.ts:9383](../src/check.ts#L9383), [check.ts:9394](../src/check.ts#L9394), [check.ts:9420](../src/check.ts#L9420), [check.ts:9431](../src/check.ts#L9431) |
11354
+ | `TEXTURE_STRETCH.per_mesh` | `TEXTURE_STRETCH.per_mesh` | part when the supplied mapping resolves a piece; otherwise rig | evidence; finding when exceeds; otherwise evidence | resolved piece for m.slot; otherwise [] | [check.ts:11358](../src/check.ts#L11358), [check.ts:11365](../src/check.ts#L11365) |
11355
+ | `TIP_OVER_ROOT.parts` | `TIP_OVER_ROOT.parts`; `characters.*.TIP_OVER_ROOT.parts` | 'part' | evidence; finding when !ok && !(!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR); otherwise evidence | [p.name] | [check.ts:9396](../src/check.ts#L9396), [check.ts:9409](../src/check.ts#L9409), [check.ts:9436](../src/check.ts#L9436), [check.ts:9447](../src/check.ts#L9447) |
11292
11356
  | `WIND_BAND.pairs` | `WIND_BAND.pairs` | 'pair' | finding when !holdsAll; otherwise evidence | [p.a, p.b] | [check.ts:7129](../src/check.ts#L7129) |
11293
11357
  | `WIND_BAND.pairs[].steps` | `WIND_BAND.pairs[].steps` | 'pair' | finding when !s.holds; otherwise evidence | [p.a, p.b] | [check.ts:7140](../src/check.ts#L7140) |
11294
11358
  | `figure_openings.openings` | `figure_openings.openings` | 'pair' | finding | [ps.under, ps.above] | [check.ts:6446](../src/check.ts#L6446) |
11295
- | `loop_physics` | `loop_physics` | 'rig' | evidence | [] | [check.ts:8332](../src/check.ts#L8332) |
11296
- | `requirements.lines.* (bone)` | `requirements.lines.*` | 'rig' | finding when line.status === 'FAIL'; otherwise evidence | [] | [check.ts:8694](../src/check.ts#L8694) |
11297
- | `requirements.lines.* (seam)` | `requirements.lines.*` | 'pair' | finding when line.status === 'FAIL'; otherwise evidence | [r.part, r.neighbour] | [check.ts:8694](../src/check.ts#L8694) |
11298
- | `requirements.lines.* (stretch)` | `requirements.lines.*` | part when the supplied mapping resolves a piece; otherwise rig | finding when line.status === 'FAIL'; otherwise evidence | resolved piece for r.slot; otherwise [] | [check.ts:8694](../src/check.ts#L8694) |
11359
+ | `loop_physics` | `loop_physics` | 'rig' | evidence | [] | [check.ts:8336](../src/check.ts#L8336) |
11360
+ | `requirements.lines.* (bone)` | `requirements.lines.*` | 'rig' | finding when line.status === 'FAIL'; otherwise evidence | [] | [check.ts:8698](../src/check.ts#L8698) |
11361
+ | `requirements.lines.* (seam)` | `requirements.lines.*` | 'pair' | finding when line.status === 'FAIL'; otherwise evidence | [r.part, r.neighbour] | [check.ts:8698](../src/check.ts#L8698) |
11362
+ | `requirements.lines.* (stretch)` | `requirements.lines.*` | part when the supplied mapping resolves a piece; otherwise rig | finding when line.status === 'FAIL'; otherwise evidence | resolved piece for r.slot; otherwise [] | [check.ts:8698](../src/check.ts#L8698) |
11299
11363
  | `seam_cells.frames` | `frames` | 'pair' | evidence | [p.a, p.b] | [check.ts:5318](../src/check.ts#L5318) |
11300
- | `seam_cells.frames[].cells` | `frames[].cells` | part when the supplied mapping resolves a piece; otherwise rig | evidence | resolved piece for cell.setupTop ?? ''; otherwise []; resolved piece for setupTop ?? ''; otherwise [] | [check.ts:5278](../src/check.ts#L5278), [check.ts:12452](../src/check.ts#L12452) |
11364
+ | `seam_cells.frames[].cells` | `frames[].cells` | part when the supplied mapping resolves a piece; otherwise rig | evidence | resolved piece for cell.setupTop ?? ''; otherwise []; resolved piece for setupTop ?? ''; otherwise [] | [check.ts:5278](../src/check.ts#L5278), [check.ts:12470](../src/check.ts#L12470) |
11301
11365
  | `seam_pairs` | `seam_pairs`; `seam_scope.whole_pairs`; `sets.*.seam_pairs`; `sets.*.seam_scope.whole_pairs`; `characters.*.seam_pairs`; `characters.*.seam_scope.whole_pairs` | subjects.length === 0 ? 'rig' : subjects.length === 1 ? 'part' : 'pair' | evidence | subjects | [check.ts:2909](../src/check.ts#L2909) |
11302
11366
  | `seam_scope.changes` | `seam_scope.changes`; `sets.*.seam_scope.changes`; `characters.*.seam_scope.changes` | 'rig' | evidence | [] | [check.ts:2387](../src/check.ts#L2387) |
11303
11367
  | `seam_scope.domain.states` | `seam_scope.domain.states`; `sets.*.seam_scope.domain.states`; `characters.*.seam_scope.domain.states` | 'rig' | evidence | [] | [check.ts:2472](../src/check.ts#L2472) |
11304
- | `seam_scope.pairs` | `seam_scope.pairs`; `sets.*.seam_scope.pairs`; `characters.*.seam_scope.pairs` | subjects.length === 0 ? 'rig' : subjects.length === 1 ? 'part' : 'pair' | evidence | subjects | [check.ts:8130](../src/check.ts#L8130) |
11368
+ | `seam_scope.pairs` | `seam_scope.pairs`; `sets.*.seam_scope.pairs`; `characters.*.seam_scope.pairs` | subjects.length === 0 ? 'rig' : subjects.length === 1 ? 'part' : 'pair' | evidence | subjects | [check.ts:8134](../src/check.ts#L8134) |
11305
11369
  | `seam_scope.population.pairs` | `seam_scope.population.pairs`; `sets.*.seam_scope.population.pairs`; `characters.*.seam_scope.population.pairs` | 'pair' | evidence | row.parts | [check.ts:2843](../src/check.ts#L2843) |
11306
11370
  | `seam_scope.population.single_art` | `seam_scope.population.single_art`; `sets.*.seam_scope.population.single_art`; `characters.*.seam_scope.population.single_art` | 'part' | evidence | [row.part] | [check.ts:2844](../src/check.ts#L2844) |
11307
- | `slider_stretch.rows` | `slider_stretch.rows` | 'rig' | finding when row.status === 'FAIL'; otherwise evidence | [] | [check.ts:11283](../src/check.ts#L11283) |
11371
+ | `slider_stretch.rows` | `slider_stretch.rows` | 'rig' | finding when row.status === 'FAIL'; otherwise evidence | [] | [check.ts:11301](../src/check.ts#L11301) |
11308
11372
 
11309
11373
  | Serialized type path | Reason for schema exclusion |
11310
11374
  | --- | --- |
package/docs/STABILITY.md CHANGED
@@ -1607,7 +1607,7 @@ pairs and the unmeasured render rows. [Motion seam coverage](AUTHORING.md#motion
1607
1607
  | `BREATH_VISIBLE` | Idle breath signal on eligible torso or planted-foot regions | `no-idle`, `no-parts`, `no-eligible-region`, `no-reading` (eligible region outside frame) |
1608
1608
  | `BLINK_NO_HOLE` | Closed-eye coverage vs open eye and idle | `no-idle`, `no-parts`, `no-eye-parts`, `no-blink-track`, `no-reading` (incompatible grids or eye outside frame) |
1609
1609
  | `CHAIN_LAG` | Phase lag for comparable idle parent and child rotation tracks | `no-idle`, `no-comparable-tracks` |
1610
- | `TIP_OVER_ROOT` | Hem or sleeve tip excursion relative to root | `no-idle`, `no-parts`, `no-swing-parts`, `no-reading` (all eligible parts unread) |
1610
+ | `TIP_OVER_ROOT` | Hem or sleeve tip excursion relative to root | `no-idle`, `no-parts`, `no-swing-parts`, `below-travel-floor` (all eligible parts unmeasured and every row is `below_travel_floor`), `no-reading` (all eligible parts unmeasured, any other reason or mix) |
1611
1611
  | `STILL_REGIONS_DARK` | Face and planted foot movement in idle | `no-idle`, `no-parts`, `no-eligible-region`, `no-reading` (missing geometry or neither region readable) |
1612
1612
  | `TEXTURE_STRETCH` | Idle change to skinned triangle edges, including rejected zero-length rest edges even when no stretch ratio is available | `no-idle`, `no-reading` (missing geometry), `no-meshes`, `no-visible-meshes` |
1613
1613
  | `ANIMATIONS_DO_NOT_FOLD` | Undeclared folds across authored animations and unmatched fold exceptions | `no-animation` |
@@ -1631,6 +1631,28 @@ pairs and the unmeasured render rows. [Motion seam coverage](AUTHORING.md#motion
1631
1631
  | No required block, root SKIP | SKIP with `no-animation` or `no-complete-root-reading` |
1632
1632
  | Neither root nor required gate present | SKIP with `no-root-gate` |
1633
1633
 
1634
+ Every `TIP_OVER_ROOT.parts[]` row that carries `unmeasured` (including under
1635
+ `characters.<id>.TIP_OVER_ROOT.parts[]`) also carries `unmeasured_reason`
1636
+ (issue #1696), naming the exact `tipLine` branch that left the part unmeasured:
1637
+
1638
+ | `unmeasured_reason` | Meaning |
1639
+ | --- | --- |
1640
+ | `declared_not_swinging` | Declared in the scene requirements file's `not_swinging` or forwarded from a character build's `check/check.json` (`declared_not_swinging`). |
1641
+ | `limb_segment` | A rigid `config.limbs` segment part (`limb` without `limb.band`). |
1642
+ | `hybrid_band` | A `config.limbs` hybrid joint band (`limb.band` present). |
1643
+ | `no_attachment` | The part's slot shows no attachment on idle frame 0. |
1644
+ | `empty_half` | The slot shows an attachment on idle frame 0, and the root or tip half of the part's box holds no art drawn by that attachment. |
1645
+ | `below_travel_floor` | A non-rigid link part whose `max(root, tip)` carrier-frame travel is below `travel_floor_rig_px` (`0.5` rig px). |
1646
+
1647
+ When `TIP_OVER_ROOT` measures no part (`status: "SKIP"`) on a rig with at least
1648
+ one swinging part, the block retains `parts` alongside `reason` so every
1649
+ unmeasured row's `unmeasured_reason` is readable without parsing prose;
1650
+ `bar_outcomes.TIP_OVER_ROOT` records `SKIP` with `reason: "below-travel-floor"`
1651
+ when every unmeasured row is `below_travel_floor`, and keeps `no-reading` on any
1652
+ other unmeasured reason or mix. A `below_travel_floor` row with a named
1653
+ `measured_driver` (a bone name, not `"none"` or `"unavailable"`) means planned
1654
+ motion that does not show on the art's grid.
1655
+
1634
1656
  Version-aware consumers read the declared outcomes on the known spec.
1635
1657
  Compose reads `bar_outcomes` on a report that declares this spec (issue
1636
1658
  #1373); on a report without it, and in the remesh/retune input-check
@@ -2044,9 +2066,10 @@ in the package.
2044
2066
 
2045
2067
  ## rig-c
2046
2068
 
2047
- `dependencies` takes `@rig-c/core` `3.12.0` exactly. Core supplies the idle
2048
- render's `--loop-seam-bar` and `--loop-seam-cap` support and the `poseSlider`
2049
- reading used for independent dial samples. Bun 1.4 or later
2069
+ `dependencies` takes `@rig-c/core` `3.13.0` exactly. Core supplies the idle
2070
+ render's `--loop-seam-bar` and `--loop-seam-cap` support, `render --frames-at`
2071
+ frame selection for the keyed loop check, and the `poseSlider` reading used for
2072
+ independent dial samples. Bun 1.4 or later
2050
2073
  is the declared floor (`engines.bun` `>=1.4.0`; older 1.4 releases are not tested in
2051
2074
  CI, which runs `latest`, and compatibility with an older 1.4 release is handled when
2052
2075
  reported as an issue). What this package relies on in rig-c, every import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-parts",
3
- "version": "2.75.0",
3
+ "version": "2.76.0",
4
4
  "description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "ag-psd": "^31.0.2",
81
- "@rig-c/core": "3.12.0"
81
+ "@rig-c/core": "3.13.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@esotericsoftware/spine-core": "4.3.13",
package/src/check.ts CHANGED
@@ -3529,7 +3529,7 @@ export type CheckBarId = ReturnType<typeof checkBarIds>[number];
3529
3529
  export interface CheckBarSkipReasons {
3530
3530
  BREATH_VISIBLE?: 'no-eligible-region' | 'no-reading';
3531
3531
  BLINK_NO_HOLE?: 'no-eye-parts' | 'no-blink-track' | 'no-reading';
3532
- TIP_OVER_ROOT?: 'no-swing-parts' | 'no-reading';
3532
+ TIP_OVER_ROOT?: 'no-swing-parts' | 'below-travel-floor' | 'no-reading';
3533
3533
  STILL_REGIONS_DARK?: 'no-eligible-region' | 'no-reading';
3534
3534
  TEXTURE_STRETCH?: 'no-reading' | 'no-meshes' | 'no-visible-meshes';
3535
3535
  }
@@ -7567,25 +7567,29 @@ export function runCheck(
7567
7567
  }
7568
7568
  loop = maxRgbDiff(idle.frames[0].image, last.image);
7569
7569
  loopSet = idle;
7570
- // The keyed loop (issue #183): with a physics constraint, the same rig and motion with every one left out, built
7571
- // the same way and rendered the same way, is what frame 0 and the frame at the duration are read from.
7570
+ // The keyed loop (issues #183, #1704): with a physics constraint, the same rig and motion with every one left out,
7571
+ // built the same way and rendered at frames 0 and last.index only, is what frame 0 and the frame at the duration
7572
+ // are read from.
7572
7573
  if (stripped !== null) {
7573
7574
  loopPhysics = stripped.physics;
7574
7575
  const what = 'the idle with its physics constraint(s) left out';
7575
- const lr = rigc(['render', '--candidate', keyedBuild(what), '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--out', join(loopDir, 'frames')]);
7576
- if (lr.status !== 0) refuseIfAny(rigcFailed(`render --animation idle (${what})`, lr, lr.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
7576
+ const selected = last.index === 0 ? [0] : [0, last.index];
7577
+ const framesAt = selected.join(',');
7578
+ const lr = rigc(['render', '--candidate', keyedBuild(what), '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--frames-at', framesAt, '--out', join(loopDir, 'frames')]);
7579
+ if (lr.status !== 0) refuseIfAny(rigcFailed(`render --animation idle --frames-at ${framesAt} (${what})`, lr, lr.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
7577
7580
  const kept = readFrameSet(join(loopDir, 'frames'));
7581
+ const keptFirst = kept.frames[0];
7578
7582
  const keptLast = kept.frames[kept.frames.length - 1];
7579
- if (kept.stride !== 1 || kept.written !== kept.sampled || keptLast.index !== last.index) {
7583
+ if (kept.stride !== 1 || kept.sampled !== idle.sampled || kept.written !== selected.length || keptFirst?.index !== 0 || keptLast?.index !== last.index) {
7580
7584
  refuseIfAny([
7581
7585
  {
7582
7586
  code: 'CHECK_LOOP_LAST_FRAME_AT_DURATION',
7583
- object: `idle frame ${keptLast.name} (${what})`,
7587
+ object: `idle frame ${keptLast?.name ?? last.name} (${what})`,
7584
7588
  detail: `rigc sampled ${kept.sampled} frame(s), wrote ${kept.written} at stride ${kept.stride}; the idle as written ends at ${last.name}, and the loop compares frame 0 with that frame`,
7585
7589
  },
7586
7590
  ]);
7587
7591
  }
7588
- loop = maxRgbDiff(kept.frames[0].image, keptLast.image);
7592
+ loop = maxRgbDiff(keptFirst.image, keptLast.image);
7589
7593
  loopSet = kept;
7590
7594
  }
7591
7595
  if (!previewIdle) {
@@ -9122,6 +9126,15 @@ function torsoProblem(ps: readonly PartRecord[], tr: Exclude<TorsoBreath, { skip
9122
9126
  };
9123
9127
  }
9124
9128
 
9129
+ /** Typed per-row reason recorded alongside `unmeasured` in `TIP_OVER_ROOT.parts[]` (issue #1696). */
9130
+ export type TipUnmeasuredReason =
9131
+ | 'declared_not_swinging'
9132
+ | 'limb_segment'
9133
+ | 'hybrid_band'
9134
+ | 'no_attachment'
9135
+ | 'empty_half'
9136
+ | 'below_travel_floor';
9137
+
9125
9138
  /** The scene file's exceptions to `TIP_OVER_ROOT` (issues #231, #245), and the file they were read from, which a refusal names. */
9126
9139
  export interface TipExceptions {
9127
9140
  path: string;
@@ -9374,11 +9387,11 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
9374
9387
  }
9375
9388
  const rows: Array<Record<string, unknown>> = [];
9376
9389
  let measured = 0;
9377
- let belowGrid = 0;
9378
9390
  let failed = false;
9379
9391
  for (const p of swing) {
9380
9392
  if (excepted.not_swinging.includes(p.name)) {
9381
9393
  const fromBuild = excepted.forwardedFrom?.not_swinging?.[p.name];
9394
+ const unmeasuredReason: TipUnmeasuredReason = 'declared_not_swinging';
9382
9395
  rows.push({
9383
9396
  ...checkRow('TIP_OVER_ROOT.parts', 'part', false, [p.name]),
9384
9397
  part: p.name,
@@ -9386,12 +9399,14 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
9386
9399
  unmeasured: fromBuild !== undefined
9387
9400
  ? `declared not swinging by build "${fromBuild}" check/check.json (not_swinging), so it is not held to the bar`
9388
9401
  : "declared not swinging by the scene file's not_swinging, so it is not held to the bar",
9402
+ unmeasured_reason: unmeasuredReason,
9389
9403
  });
9390
9404
  continue;
9391
9405
  }
9392
9406
  // Issue #349: a limb segment is rigid on its one bone and turns at its joint; it does not hang, so no tip trails a root.
9393
9407
  if (p.limb !== undefined) {
9394
- rows.push({ ...checkRow('TIP_OVER_ROOT.parts', 'part', false, [p.name]), part: p.name, unmeasured: p.limb.band !== undefined ? `a hybrid joint band (config.limbs.${p.limb.name}): it bends between adjacent carriers, does not hang, and is not held to the tip-over-root bar` : `a limb segment (config.limbs.${p.limb.name}), rigid on its one bone "${p.limb.bone}": it turns at its joint and does not hang, so it is not held to the bar` });
9408
+ const unmeasuredReason: TipUnmeasuredReason = p.limb.band !== undefined ? 'hybrid_band' : 'limb_segment';
9409
+ rows.push({ ...checkRow('TIP_OVER_ROOT.parts', 'part', false, [p.name]), part: p.name, unmeasured: p.limb.band !== undefined ? `a hybrid joint band (config.limbs.${p.limb.name}): it bends between adjacent carriers, does not hang, and is not held to the tip-over-root bar` : `a limb segment (config.limbs.${p.limb.name}), rigid on its one bone "${p.limb.bone}": it turns at its joint and does not hang, so it is not held to the bar`, unmeasured_reason: unmeasuredReason });
9395
9410
  continue;
9396
9411
  }
9397
9412
  const rises = excepted.rises.includes(p.name);
@@ -9417,7 +9432,8 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
9417
9432
  };
9418
9433
  if (w.root === null || w.tip === null || c.root === null || c.tip === null) {
9419
9434
  const half = w.root === null || c.root === null ? rootHalf : tipHalf;
9420
- rows.push({ ...checkRow('TIP_OVER_ROOT.parts', 'part', false, [p.name]), part: p.name, ...said, unmeasured: shown[0] === null ? 'its slot shows no attachment on idle frame 0' : `on idle frame 0 the ${half} half of its box holds no art its attachment draws` });
9435
+ const unmeasuredReason: TipUnmeasuredReason = shown[0] === null ? 'no_attachment' : 'empty_half';
9436
+ rows.push({ ...checkRow('TIP_OVER_ROOT.parts', 'part', false, [p.name]), part: p.name, ...said, unmeasured: shown[0] === null ? 'its slot shows no attachment on idle frame 0' : `on idle frame 0 the ${half} half of its box holds no art its attachment draws`, unmeasured_reason: unmeasuredReason });
9421
9437
  continue;
9422
9438
  }
9423
9439
  // Issue #987: a half that does not move against its carrier, read at the line's precision, is 0 and not the
@@ -9431,11 +9447,12 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
9431
9447
  rows.push({ ...checkRow('TIP_OVER_ROOT.parts', 'part', !ok && !(!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR), [p.name]), part: p.name, ...said, hang_from: hang, root_rig_px: round3(t.root), tip_rig_px: round3(t.tip), ratio, world_root_rig_px: round3(w.root), world_tip_rig_px: round3(w.tip), world_ratio: worldRatio });
9432
9448
  // Structural 0 / 0 stays a failure before the link-only magnitude policy (issue #994).
9433
9449
  if (!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR) {
9434
- belowGrid++;
9435
9450
  const excitation = carrierExcitation(inp.rig, idleGeo, hangFound);
9451
+ const unmeasuredReason: TipUnmeasuredReason = 'below_travel_floor';
9436
9452
  rows[rows.length - 1] = { ...rows[rows.length - 1], travel_floor_rig_px: TIP_TRAVEL_FLOOR,
9437
9453
  measured_driver: excitation === null ? 'unavailable' : excitation.driver ?? 'none',
9438
- unmeasured: "below half a rig pixel: the motion does not show on the art's own grid" };
9454
+ unmeasured: "below half a rig pixel: the motion does not show on the art's own grid",
9455
+ unmeasured_reason: unmeasuredReason };
9439
9456
  continue;
9440
9457
  }
9441
9458
  measured++;
@@ -9508,8 +9525,9 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
9508
9525
  const travel = r.travel_floor_rig_px === undefined ? '' : `; root ${String(r.root_rig_px)} rig px, tip ${String(r.tip_rig_px)} rig px, floor ${String(r.travel_floor_rig_px)} rig px; measured driver ${String(r.measured_driver)}`;
9509
9526
  return `${String(r.part)}: ${String(r.unmeasured)}${travel}`;
9510
9527
  });
9511
- return { ...skipped(`none of ${quoteParts(swing)} could be measured: ${reasons.join('; ')}`, 'no-reading'),
9512
- ...(belowGrid === 0 ? { ...declared, ...forwardedBlock } : figures) };
9528
+ const skipCode = rows.length > 0 && rows.every((r) => r.unmeasured_reason === 'below_travel_floor') ? 'below-travel-floor' : 'no-reading';
9529
+ return { ...skipped(`none of ${quoteParts(swing)} could be measured: ${reasons.join('; ')}`, skipCode),
9530
+ ...figures };
9513
9531
  }
9514
9532
  return { status: failed ? 'FAIL' : 'PASS', ...figures };
9515
9533
  }
@@ -12714,7 +12732,13 @@ const SILENT_SKIP_REASONS = new Set<CheckBarSkipReason>([
12714
12732
  function aggregateCharacterBarOutcome(outcomes: readonly CheckBarOutcome[]): CheckBarOutcome {
12715
12733
  if (outcomes.some(o => o.status === 'FAIL')) return { status: 'FAIL' };
12716
12734
  if (outcomes.some(o => o.status === 'PASS')) return { status: 'PASS' };
12717
- const loud = outcomes.find((o): o is Extract<CheckBarOutcome, { status: 'SKIP' }> => o.status === 'SKIP' && !SILENT_SKIP_REASONS.has(o.reason));
12735
+ const skips = outcomes.filter((o): o is Extract<CheckBarOutcome, { status: 'SKIP' }> => o.status === 'SKIP');
12736
+ if (skips.some(o => o.reason === 'no-reading') && skips.some(o => o.reason === 'below-travel-floor')) {
12737
+ return { status: 'SKIP', reason: 'no-reading' };
12738
+ }
12739
+ const reading = skips.find(o => o.reason === 'below-travel-floor' || o.reason === 'no-reading');
12740
+ if (reading !== undefined) return reading;
12741
+ const loud = skips.find(o => !SILENT_SKIP_REASONS.has(o.reason));
12718
12742
  if (loud !== undefined) return loud;
12719
12743
  return outcomes[0];
12720
12744
  }
package/src/scene.ts CHANGED
@@ -111,6 +111,7 @@ import { dirname, join, resolve } from 'node:path';
111
111
  import { documentPageLookup, readModel, type ModelPageRegion } from '@rig-c/core/core';
112
112
  import { CandidateAtlasError, CandidatePairError, CoreInputError, loadCandidate, PoserChoiceError, projector, renderFrame, SpineRuntimeError, throughPoser, type Piece, type Quad, type Viewport } from '@rig-c/core/render-shared';
113
113
  import { deformSliderCombinationProblem, type RigStop } from '@rig-c/core/rig';
114
+ import partsPackage from '../package.json' with { type: 'json' };
114
115
  import { checkStage, gateThroughRigc, type Log } from './build.ts';
115
116
  import { ACCEPTABLE_BARS, barsNotMet, CHECK_SPEC, type CheckReport, COMPOSE_PREVIEW_LOOP_SEAM_DETAIL, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, IDLE_FPS, LOOP_SEAM_BAR_UNMET, type LoopSeamRequest, MOTION_SEAM_LINE, type PackMode, parsePageSize, requirementsNotPass, type RigcRunner } from './check.ts';
116
117
  import { COMPOSE_SEAMS_CORE, COMPOSE_SEAMS_DIR, COMPOSE_SEAMS_OFF, type ComposeSeamRequest, writeComposeSeams } from './compose-seams.ts';
@@ -147,6 +148,9 @@ export const SCENE_CAMERA_REPORT_SPEC = 'spine-parts-scene-report/2';
147
148
  /** The file `compose` writes beside `rig/` and `check/`. */
148
149
  export const SCENE_REPORT_FILE = 'scene.json';
149
150
 
151
+ export const COMPOSE_REFUSAL_SPEC = 'rig-compose-refusal/1';
152
+ export const COMPOSE_REFUSAL_FILE = 'compose-refusal.json';
153
+
150
154
  /** Between a character's id and a name it owns. */
151
155
  export const PREFIX_SEP = ':';
152
156
 
@@ -164,7 +168,7 @@ export const PROVENANCES = ['observed', 'generated', 'unknown'] as const;
164
168
  export type Provenance = (typeof PROVENANCES)[number];
165
169
 
166
170
  /** Every path `compose` writes under `--out`, relative — and so every path it clears first. */
167
- export const COMPOSE_OWNS: readonly string[] = ['rig', 'check', SCENE_REPORT_FILE, COMPOSE_RUN_FILE, COMPOSE_SEAMS_DIR];
171
+ export const COMPOSE_OWNS: readonly string[] = ['rig', 'check', SCENE_REPORT_FILE, COMPOSE_RUN_FILE, COMPOSE_REFUSAL_FILE, COMPOSE_SEAMS_DIR];
168
172
 
169
173
  /** `<id>:<name>`. */
170
174
  export function prefixed(id: string, name: string): string {
@@ -290,14 +294,31 @@ export function acceptProblems(names: readonly string[], where: string): Problem
290
294
  * names is {@link composeScene}'s, which has the builds.
291
295
  */
292
296
  export function loadScene(path: string): SceneFile {
297
+ return parseScene(readSceneSource(path));
298
+ }
299
+
300
+ type SceneSource = { at: string; bytes: Buffer; sha256: string } | { problem: Problem };
301
+
302
+ function readSceneSource(path: string): SceneSource {
293
303
  const at = resolve(path);
294
- if (!existsSync(at) || !statSync(at).isFile()) refuseIfAny([{ code: 'SCENE_FILE', object: at, detail: `no such file; a ${SCENE_SPEC} file is required` }]);
304
+ if (!existsSync(at) || !statSync(at).isFile()) {
305
+ return { problem: { code: 'SCENE_FILE', object: at, detail: `no such file; a ${SCENE_SPEC} file is required` } };
306
+ }
307
+ let bytes: Buffer;
308
+ try {
309
+ bytes = readFileSync(at);
310
+ } catch (err) {
311
+ return { problem: { code: 'SCENE_FILE', object: at, detail: `${(err as Error).message}; a JSON object is required` } };
312
+ }
313
+ return { at, bytes, sha256: createHash('sha256').update(bytes).digest('hex') };
314
+ }
315
+
316
+ function parseScene(source: SceneSource): SceneFile {
317
+ if ('problem' in source) throw new PartsError([source.problem]);
318
+ const { at, bytes, sha256 } = source;
295
319
  let raw: unknown;
296
- let sha256 = '';
297
320
  try {
298
- const bytes = readFileSync(at);
299
321
  raw = JSON.parse(bytes.toString('utf8'));
300
- sha256 = createHash('sha256').update(bytes).digest('hex');
301
322
  } catch (err) {
302
323
  refuseIfAny([{ code: 'SCENE_FILE', object: at, detail: `${(err as Error).message}; a JSON object is required` }]);
303
324
  }
@@ -615,40 +636,55 @@ function animationsOf(motion: MotionSpec): Record<string, SceneAnimation> {
615
636
  /** Maximum copies of each source searched for a diagnostic hint. Acceptance compares the declared counts directly. */
616
637
  const WITH_IDLE_DIAGNOSTIC_COPY_LIMIT = 10_000;
617
638
 
639
+ type IdleRepeatSearchResult = { found: { idle_repeats: number; with_idle: number } } | { none: 'limit' | 'non_finite' };
640
+
641
+ interface WithIdleDurationData {
642
+ idle_period: number;
643
+ clip_period: number;
644
+ search: { limit: typeof WITH_IDLE_DIAGNOSTIC_COPY_LIMIT; result: IdleRepeatSearchResult };
645
+ }
646
+
618
647
  function compareRepeatDurations(left: number, right: number): -1 | 0 | 1 {
619
648
  return left === right ? 0 : left < right ? -1 : 1;
620
649
  }
621
650
 
622
- function idleRepeatAdvice(name: string, idlePeriod: number, clipPeriod: number, scenePeriodMatchesIdle: boolean): string {
623
- if (Number.isFinite(idlePeriod) && idlePeriod > 0 && Number.isFinite(clipPeriod) && clipPeriod > 0) {
624
- let idleCount = 1;
625
- let clipCount = 1;
626
- while (idleCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT && clipCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT) {
627
- const idleDuration = idleCount * idlePeriod;
628
- const clipDuration = clipCount * clipPeriod;
629
- if (!Number.isFinite(idleDuration) || !Number.isFinite(clipDuration)) break;
630
- // Only the smaller product can catch the other, so the first match has the least idle count and then clip count.
631
- const order = compareRepeatDurations(idleDuration, clipDuration);
632
- if (order === 0) {
633
- const clipField = `with_idle.${name}: ${clipCount}`;
634
- const unknownScenePeriod = "Cannot name a scene.repeats count because the scene's own period is not declared.";
635
- if (idleCount === 1) {
636
- const sceneAdvice = scenePeriodMatchesIdle
637
- ? `Omit scene.repeats.idle and keep scene.animations.idle.duration: ${idleDuration} (camera terminal key ${idleDuration} s).`
638
- : unknownScenePeriod;
639
- return `Omit idle_repeats and write ${clipField} (${idleDuration} s). ${sceneAdvice}`;
640
- }
641
- if (scenePeriodMatchesIdle) {
642
- return `Write idle_repeats: ${idleCount}, ${clipField}, scene.repeats.idle: ${idleCount}, and scene.animations.idle.duration: ${idleDuration} ` +
643
- `(composed camera terminal key ${idleDuration} s, authored terminal key stays at ${idlePeriod} s).`;
644
- }
645
- return `Write idle_repeats: ${idleCount} and ${clipField} (${idleDuration} s). ${unknownScenePeriod}`;
646
- }
647
- if (order < 0) idleCount++;
648
- else clipCount++;
649
- }
650
- }
651
- const limit = String(WITH_IDLE_DIAGNOSTIC_COPY_LIMIT).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
651
+ function searchIdleRepeats(idlePeriod: number, clipPeriod: number): IdleRepeatSearchResult {
652
+ if (!(Number.isFinite(idlePeriod) && idlePeriod > 0 && Number.isFinite(clipPeriod) && clipPeriod > 0)) return { none: 'non_finite' };
653
+ let idleCount = 1;
654
+ let clipCount = 1;
655
+ while (idleCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT && clipCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT) {
656
+ const idleDuration = idleCount * idlePeriod;
657
+ const clipDuration = clipCount * clipPeriod;
658
+ if (!Number.isFinite(idleDuration) || !Number.isFinite(clipDuration)) return { none: 'non_finite' };
659
+ // Only the smaller product can catch the other, so the first match has the least idle count and then clip count.
660
+ const order = compareRepeatDurations(idleDuration, clipDuration);
661
+ if (order === 0) return { found: { idle_repeats: idleCount, with_idle: clipCount } };
662
+ if (order < 0) idleCount++;
663
+ else clipCount++;
664
+ }
665
+ return { none: 'limit' };
666
+ }
667
+
668
+ function idleRepeatAdvice(name: string, data: WithIdleDurationData, scenePeriodMatchesIdle: boolean): string {
669
+ const { idle_period: idlePeriod, clip_period: clipPeriod, search } = data;
670
+ if ('found' in search.result) {
671
+ const { idle_repeats: idleCount, with_idle: clipCount } = search.result.found;
672
+ const idleDuration = idleCount * idlePeriod;
673
+ const clipField = `with_idle.${name}: ${clipCount}`;
674
+ const unknownScenePeriod = "Cannot name a scene.repeats count because the scene's own period is not declared.";
675
+ if (idleCount === 1) {
676
+ const sceneAdvice = scenePeriodMatchesIdle
677
+ ? `Omit scene.repeats.idle and keep scene.animations.idle.duration: ${idleDuration} (camera terminal key ${idleDuration} s).`
678
+ : unknownScenePeriod;
679
+ return `Omit idle_repeats and write ${clipField} (${idleDuration} s). ${sceneAdvice}`;
680
+ }
681
+ if (scenePeriodMatchesIdle) {
682
+ return `Write idle_repeats: ${idleCount}, ${clipField}, scene.repeats.idle: ${idleCount}, and scene.animations.idle.duration: ${idleDuration} ` +
683
+ `(composed camera terminal key ${idleDuration} s, authored terminal key stays at ${idlePeriod} s).`;
684
+ }
685
+ return `Write idle_repeats: ${idleCount} and ${clipField} (${idleDuration} s). ${unknownScenePeriod}`;
686
+ }
687
+ const limit = String(search.limit).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
652
688
  return `No pair within ${limit} copies of each for source idle ${idlePeriod} s and source clip ${clipPeriod} s. ` +
653
689
  'Retime the clip at its source in motion.animations_from, change the source idle\'s motion.duration, or declare false.';
654
690
  }
@@ -1845,8 +1881,18 @@ export function composeScene(
1845
1881
  if (!Number.isFinite(foldedDuration) || foldedDuration <= 0 || compareRepeatDurations(idleDuration, foldedDuration) !== 0) {
1846
1882
  const idleField = c.idle_repeats === undefined ? `character ${show(c.id)}'s source idle` : `${character}.idle_repeats: ${c.idle_repeats} (implies ${c.idle_repeats * sourceIdle} s)`;
1847
1883
  const sceneField = clip === undefined ? '' : ` ${sceneIdleClock} declares ${clip.duration} s.`;
1848
- const advice = idleRepeatAdvice(name, sourceIdle, period, sceneIdleRepeat === undefined && clip?.duration === sourceIdle);
1849
- fail('SCENE_WITH_IDLE_DURATION', object, `character ${show(c.id)} clip ${show(name)} at ${count} × ${period} s implies ${foldedDuration} s. The played idle is ${idleDuration} s with ${idleField}.${sceneField} ${advice}`);
1884
+ const data: WithIdleDurationData = {
1885
+ idle_period: sourceIdle,
1886
+ clip_period: period,
1887
+ search: { limit: WITH_IDLE_DIAGNOSTIC_COPY_LIMIT, result: searchIdleRepeats(sourceIdle, period) },
1888
+ };
1889
+ const advice = idleRepeatAdvice(name, data, sceneIdleRepeat === undefined && clip?.duration === sourceIdle);
1890
+ const problem: Problem & { data: WithIdleDurationData } = {
1891
+ code: 'SCENE_WITH_IDLE_DURATION', object,
1892
+ detail: `character ${show(c.id)} clip ${show(name)} at ${count} × ${period} s implies ${foldedDuration} s. The played idle is ${idleDuration} s with ${idleField}.${sceneField} ${advice}`,
1893
+ data,
1894
+ };
1895
+ problems.push(problem);
1850
1896
  continue;
1851
1897
  }
1852
1898
  clips.set(name, source);
@@ -2634,8 +2680,7 @@ export function unprefixedNames(rig: RigSpec, motion: MotionSpec, ids: readonly
2634
2680
  // the stage
2635
2681
  // ---------------------------------------------------------------------------
2636
2682
 
2637
- function readSceneComposition(scenePath: string, mode: PackMode, accept: readonly string[], checkBuilds: boolean, requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void) {
2638
- const scene = loadScene(scenePath);
2683
+ function readSceneComposition(scene: SceneFile, mode: PackMode, accept: readonly string[], checkBuilds: boolean, requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void) {
2639
2684
  const problems: Problem[] = acceptProblems(accept, '--accept');
2640
2685
  const builds = scene.characters.map((c) => readCharacterBuild(c, problems, accept, checkBuilds));
2641
2686
  let plate: PlateImage | null = null;
@@ -2684,13 +2729,14 @@ function readSceneComposition(scenePath: string, mode: PackMode, accept: readonl
2684
2729
  }
2685
2730
  }
2686
2731
  const composed = composeScene(scene, builds, plate, problems, mode, req, plateLayers, verifyRepeatSource);
2687
- return { scene, builds, plate, plateLayers, composed };
2732
+ return { builds, plate, plateLayers, composed };
2688
2733
  }
2689
2734
 
2690
2735
  /** Read the declared composition before character checks. The diagnostic gates its own scratch candidate. */
2691
2736
  export function readSceneForClipStretch(scenePath: string, mode: PackMode):
2692
2737
  Pick<ComposedScene, 'rig' | 'motion' | 'images'> & { explicitlyPlayed: ReadonlySet<string> } {
2693
- const { scene, composed: { rig, motion, images } } = readSceneComposition(scenePath, mode, [], false);
2738
+ const scene = loadScene(scenePath);
2739
+ const { composed: { rig, motion, images } } = readSceneComposition(scene, mode, [], false);
2694
2740
  const explicitlyPlayed = new Set([...Object.keys(scene.animations ?? {}), ...Object.keys(scene.camera?.tracks ?? {})]);
2695
2741
  for (const character of scene.characters) {
2696
2742
  for (const clip of Object.keys(character.with_idle ?? {})) explicitlyPlayed.add(prefixed(character.id, clip));
@@ -2704,7 +2750,11 @@ export function readSceneForClipStretch(scenePath: string, mode: PackMode):
2704
2750
  * then compose the scene and bind the inputs in the run record.
2705
2751
  */
2706
2752
  export function composeFromFiles(scenePath: string, requirementsPath?: string, mode: PackMode = { pageEdges: DEFAULT_PAGE_EDGES, packShape: DEFAULT_PACK_SHAPE }, accept: readonly string[] = [], verifyRepeatSource?: (build: CharacterBuild, object: string) => void): ComposedScene & { runRecord: ComposeRun } {
2707
- const { scene, builds, plate, plateLayers, composed } = readSceneComposition(scenePath, mode, accept, true, requirementsPath, verifyRepeatSource);
2753
+ return composeLoadedScene(loadScene(scenePath), scenePath, mode, accept, requirementsPath, verifyRepeatSource);
2754
+ }
2755
+
2756
+ function composeLoadedScene(scene: SceneFile, scenePath: string, mode: PackMode, accept: readonly string[], requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void): ComposedScene & { runRecord: ComposeRun } {
2757
+ const { builds, plate, plateLayers, composed } = readSceneComposition(scene, mode, accept, true, requirementsPath, verifyRepeatSource);
2708
2758
  const runRecord: ComposeRun = {
2709
2759
  spec: COMPOSE_RUN_SPEC,
2710
2760
  scene: { path: scenePath, sha256: scene.sha256 },
@@ -2746,23 +2796,25 @@ export interface ComposeRunners {
2746
2796
  scratch: string;
2747
2797
  }
2748
2798
 
2749
- export type ComposeStage = 'compose' | 'check';
2799
+ export type ComposeStage = 'compose' | 'check' | 'motion-seams';
2750
2800
 
2751
2801
  export interface ComposeResult {
2752
- stoppedAt: ComposeStage | 'motion-seams' | null;
2802
+ stoppedAt: ComposeStage | null;
2753
2803
  composed: ComposedScene | null;
2754
2804
  check: CheckReport | null;
2755
2805
  }
2756
2806
 
2757
- /** Refuse before resolving rigc in the CLI, and before the gate for direct stage callers. */
2758
- export function refusePreviewLoopSeam(input: ComposeInput): void {
2759
- if (input.outputProfile !== 'preview' || input.loopSeam === undefined) return;
2760
- for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
2761
- throw new PartsError([{
2762
- code: 'COMPOSE_PREVIEW_REQUIRED_CHECK',
2763
- object: '--loop-seam-bar',
2764
- detail: COMPOSE_PREVIEW_LOOP_SEAM_DETAIL,
2765
- }]);
2807
+ type ComposePreviewWithLoopSeam = ComposeInput & { outputProfile: 'preview'; loopSeam: LoopSeamRequest };
2808
+ type PreviewRefusalPrinter = (err: PartsError) => void;
2809
+
2810
+ /** This combination refuses before the CLI needs to resolve rigc. */
2811
+ export function isComposePreviewWithLoopSeam(input: ComposeInput): input is ComposePreviewWithLoopSeam {
2812
+ return input.outputProfile === 'preview' && input.loopSeam !== undefined;
2813
+ }
2814
+
2815
+ /** Clear prior refusal evidence before prevalidation or a new stage run. */
2816
+ export function clearComposeRefusal(out: string): void {
2817
+ rmSync(join(out, COMPOSE_REFUSAL_FILE), { force: true });
2766
2818
  }
2767
2819
 
2768
2820
  /**
@@ -2775,30 +2827,62 @@ export function refusePreviewLoopSeam(input: ComposeInput): void {
2775
2827
  * `build` prints its stages. The paths {@link COMPOSE_OWNS} names are cleared
2776
2828
  * first. A crash that is not a refusal is rethrown.
2777
2829
  */
2778
- export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log): ComposeResult {
2830
+ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log): ComposeResult;
2831
+ /** CLI preview preflight uses its own refusal printer and needs no rigc runners. */
2832
+ export function composeStage(input: ComposePreviewWithLoopSeam, run: PreviewRefusalPrinter, log: Log): ComposeResult;
2833
+ export function composeStage(input: ComposeInput, run: ComposeRunners | PreviewRefusalPrinter, log: Log): ComposeResult {
2779
2834
  // Clear before even option validation: a refused rerun cannot retain an earlier receipt.
2780
2835
  clearComposeRun(input.out);
2836
+ clearComposeRefusal(input.out);
2781
2837
  const prefix = (stage: ComposeStage): Log => (line) => log(`[${stage}] ${line}`);
2782
2838
  const say = prefix('compose');
2783
- const refused = (stage: ComposeStage, err: unknown, composed: ComposedScene | null = null): ComposeResult => {
2839
+ // Keep the bytes read for parsing, including when parsing or a later gate refuses.
2840
+ let source: SceneSource | undefined;
2841
+ const readSource = (): SceneSource => source ??= readSceneSource(input.scene);
2842
+ const refused = (stage: ComposeStage, err: unknown, composed: ComposedScene | null = null, print?: PreviewRefusalPrinter): ComposeResult => {
2784
2843
  if (!(err instanceof PartsError)) throw err;
2785
- const p = prefix(stage);
2786
- for (const x of err.problems) {
2787
- if (x.code === LOOP_SEAM_BAR_UNMET) log(x.detail);
2788
- else p(failLine(x));
2844
+ const read = readSource();
2845
+ // A preflight refusal can precede the read. Keep it first and explain a missing digest in the same finding stream.
2846
+ const refusal = 'problem' in read && !err.problems.includes(read.problem)
2847
+ ? new PartsError([...err.problems, read.problem])
2848
+ : err;
2849
+ const count = refusal.problems.length;
2850
+ writeFileSync(join(input.out, COMPOSE_REFUSAL_FILE), rigJsonText({
2851
+ spec: COMPOSE_REFUSAL_SPEC,
2852
+ parts_version: partsPackage.version,
2853
+ scene: { path: input.scene, sha256: 'problem' in read ? null : read.sha256 },
2854
+ stage,
2855
+ count,
2856
+ findings: refusal.problems.map(problem => ({
2857
+ code: problem.code,
2858
+ object: problem.object,
2859
+ detail: problem.detail,
2860
+ data: problem.code === 'SCENE_WITH_IDLE_DURATION' && 'data' in problem ? problem.data ?? null : null,
2861
+ })),
2862
+ }));
2863
+ if (stage === 'motion-seams') {
2864
+ for (const problem of refusal.problems) say(failLine(problem));
2865
+ log('compose: stopped at motion-seams; the composed rig and its check were written');
2866
+ } else if (print !== undefined) print(refusal);
2867
+ else {
2868
+ const p = prefix(stage);
2869
+ for (const x of refusal.problems) {
2870
+ if (x.code === LOOP_SEAM_BAR_UNMET) log(x.detail);
2871
+ else p(failLine(x));
2872
+ }
2873
+ p(`refused: ${count} problem(s)`);
2874
+ log(`compose: stopped at ${stage}; nothing ${stage === 'compose' ? 'was written' : 'after the check was written'}`);
2789
2875
  }
2790
- p(`refused: ${err.problems.length} problem(s)`);
2791
- log(`compose: stopped at ${stage}; nothing ${stage === 'compose' ? 'was written' : 'after the check was written'}`);
2792
2876
  return { stoppedAt: stage, composed, check: null };
2793
2877
  };
2794
2878
  const pageSize = parsePageSize(input.pageSize);
2795
- try {
2796
- refusePreviewLoopSeam(input);
2797
- } catch (err) {
2798
- return refused('compose', err);
2799
- }
2800
2879
  mkdirSync(input.out, { recursive: true });
2801
2880
  for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
2881
+ if (isComposePreviewWithLoopSeam(input)) {
2882
+ const err = new PartsError([{ code: 'COMPOSE_PREVIEW_REQUIRED_CHECK', object: '--loop-seam-bar', detail: COMPOSE_PREVIEW_LOOP_SEAM_DETAIL }]);
2883
+ return refused('compose', err, null, typeof run === 'function' ? run : undefined);
2884
+ }
2885
+ if (typeof run === 'function') throw new Error('composeStage requires rigc runners for this input');
2802
2886
  if (input.motionSeams !== undefined) {
2803
2887
  const version = run.rig(['--version']);
2804
2888
  const found = version.out.trim().split('\n')[0];
@@ -2813,7 +2897,7 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
2813
2897
  log(`rig-parts compose: ${input.scene} -> ${input.out}, page edges ${mode.pageEdges}, pack shape ${mode.packShape}`);
2814
2898
  let composed: ReturnType<typeof composeFromFiles>;
2815
2899
  try {
2816
- composed = composeFromFiles(input.scene, input.requirements, mode, input.accept ?? [], (b, object) => {
2900
+ composed = composeLoadedScene(parseScene(readSource()), input.scene, mode, input.accept ?? [], input.requirements, (b, object) => {
2817
2901
  if (b.repeatSource === undefined) throw new Error(`${object}: missing source gate inputs`);
2818
2902
  const [source] = gateThroughRigc(b.images, b.repeatSource, run.rig, run.scratch, null, build => {
2819
2903
  refuseIfAny(sceneRepeatSourceLoopProblems(readFileSync(join(build, 'skeleton.model.json'), 'utf8'), object));
@@ -3001,10 +3085,7 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
3001
3085
  const { animation, fps, frame_count, verdict } = writeComposeSeams(input.out, request, report, frameView);
3002
3086
  say(` bound motion seams: ${verdict.status} — ${show(animation)} at ${fps} fps, ${frame_count} frame(s), ${verdict.measured} measured, ${verdict.skipped} skipped, ${verdict.failing_frames} failing pair/frame(s); wrote ${join(input.out, COMPOSE_SEAMS_DIR, 'report.json')}`);
3003
3087
  } catch (err) {
3004
- if (!(err instanceof PartsError)) throw err;
3005
- for (const problem of err.problems) say(failLine(problem));
3006
- log('compose: stopped at motion-seams; the composed rig and its check were written');
3007
- return { stoppedAt: 'motion-seams', composed, check: report };
3088
+ return { ...refused('motion-seams', err, composed), check: report };
3008
3089
  }
3009
3090
  }
3010
3091
  // Issue #203: a character taken with an accepted failing bar never makes the scene green, even when the composed