@rig-c/parts 2.41.0 → 2.43.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/src/checkrow.ts CHANGED
@@ -9,6 +9,35 @@ export const CHECK_ROW_PATHS = {
9
9
  'ART_JOINT_DISTANCE.joints': ['ART_JOINT_DISTANCE.joints'],
10
10
  'BOUNDARY_COLOUR_STEP.over': ['BOUNDARY_COLOUR_STEP.over'],
11
11
  'BOUNDARY_COLOUR_STEP.unmeasured': ['BOUNDARY_COLOUR_STEP.unmeasured'],
12
+ 'BEHIND_PART_SEAMS.turn.pairs': ['BEHIND_PART_SEAMS.turn.pairs'],
13
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames': ['BEHIND_PART_SEAMS.turn.pairs[].frames'],
14
+ 'BEHIND_PART_SEAMS.turn.unmeasured': ['BEHIND_PART_SEAMS.turn.unmeasured'],
15
+ 'BEHIND_PART_SEAMS.pairs': ['BEHIND_PART_SEAMS.pairs'],
16
+ 'BEHIND_PART_SEAMS.pairs[].setup': ['BEHIND_PART_SEAMS.pairs[].setup'],
17
+ 'BEHIND_PART_SEAMS.pairs[].frames': ['BEHIND_PART_SEAMS.pairs[].frames'],
18
+ 'BEHIND_PART_SEAMS.samples': [
19
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.samples',
20
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].motion_opened.samples',
21
+ 'BEHIND_PART_SEAMS.pairs[].setup.motion_opened.samples', 'BEHIND_PART_SEAMS.pairs[].setup.standing.samples',
22
+ 'BEHIND_PART_SEAMS.pairs[].frames[].motion_opened.samples', 'BEHIND_PART_SEAMS.pairs[].frames[].standing.samples',
23
+ ],
24
+ 'BEHIND_PART_SEAMS.contributors': [
25
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.samples[].contributors',
26
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].motion_opened.samples[].contributors',
27
+ 'BEHIND_PART_SEAMS.pairs[].setup.motion_opened.samples[].contributors', 'BEHIND_PART_SEAMS.pairs[].setup.standing.samples[].contributors',
28
+ 'BEHIND_PART_SEAMS.pairs[].frames[].motion_opened.samples[].contributors', 'BEHIND_PART_SEAMS.pairs[].frames[].standing.samples[].contributors',
29
+ ],
30
+ 'BEHIND_PART_SEAMS.hits': [
31
+ 'BEHIND_PART_SEAMS.pairs[].motion_opened.frames', 'BEHIND_PART_SEAMS.pairs[].standing.frames',
32
+ 'BEHIND_PART_SEAMS.pairs[].motion_opened.worst', 'BEHIND_PART_SEAMS.pairs[].standing.worst',
33
+ ],
34
+ 'BEHIND_PART_SEAMS.spans': ['BEHIND_PART_SEAMS.pairs[].motion_opened.spans', 'BEHIND_PART_SEAMS.pairs[].standing.spans'],
35
+ 'BEHIND_PART_SEAMS.unread_corridors': [
36
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.unread_corridors',
37
+ 'BEHIND_PART_SEAMS.pairs[].setup.standing.unread_corridors',
38
+ 'BEHIND_PART_SEAMS.pairs[].frames[].standing.unread_corridors',
39
+ ],
40
+ 'BEHIND_PART_SEAMS.unmeasured': ['BEHIND_PART_SEAMS.unmeasured'],
12
41
  'CLOTH_SETTLES.rows': ['CLOTH_SETTLES.rows'],
13
42
  'CUT_JOINT_MATERIAL.rows': ['CUT_JOINT_MATERIAL.rows'],
14
43
  'FEET_STAY_LEVEL.feet': ['FEET_STAY_LEVEL.feet'],
@@ -0,0 +1,25 @@
1
+ /** Config writers relocate edited directories once, without rewriting authored receipt files. */
2
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
3
+ import { configFileReferences } from './config.ts';
4
+
5
+ function object(value: unknown): value is Record<string, unknown> {
6
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
7
+ }
8
+
9
+ /** Preserve the public reference inventory while giving writers canonical edited-part paths. */
10
+ export function relocateConfigReferences(raw: unknown, configDir: string, out: string, mode: 'relative' | 'absolute'): void {
11
+ const refs = configFileReferences(raw);
12
+ const assemble = object(raw) ? raw.assemble : undefined;
13
+ const edited = object(assemble) ? assemble.edited_parts : undefined;
14
+ // Do not repair invalid dirs or replace the loader's existing relative-only refusals.
15
+ if (object(edited) && typeof edited.dir === 'string' && edited.dir.trim() !== '' &&
16
+ !isAbsolute(edited.dir) && !/^(?:[\\/]|[A-Za-z]:[\\/])/.test(edited.dir)) {
17
+ edited.dir = relative(resolve(out), resolve(configDir, edited.dir)).split(sep).join('/') || '.';
18
+ }
19
+ for (const ref of refs) {
20
+ if (ref.at.startsWith('assemble.edited_parts.receipts[')) continue;
21
+ if (mode === 'absolute' && isAbsolute(ref.value)) continue;
22
+ const target = resolve(configDir, ref.value);
23
+ ref.set(mode === 'relative' ? relative(resolve(out), target) : target);
24
+ }
25
+ }
@@ -11,14 +11,16 @@
11
11
  import type { PlanProposal } from './assemble.ts';
12
12
  import type { HeadBoxProposal } from './headbox.ts';
13
13
  import type { CharacterConfig } from './config.ts';
14
+ import type { EditedPartReceipt } from './editedparts.ts';
14
15
  import type { Proposal, PROPOSAL_CONFIG_SECTIONS } from './propose.ts';
15
16
  import { PartsError } from './errors.ts';
16
- import { parseProposalSections } from './config.ts';
17
+ import { parseConfig, parseProposalSections } from './config.ts';
17
18
  import type { ConfigEdit } from './meshdraft.ts';
18
19
 
19
20
  export type ConfigJson = null | boolean | number | string | ConfigJson[] | ConfigObject;
20
21
  export interface ConfigObject { [key: string]: ConfigJson }
21
22
  export type ConfigWritePatch =
23
+ | { kind: 'edited-part-receipt'; receipt: EditedPartReceipt }
22
24
  | { kind: 'neck-unit'; config: CharacterConfig }
23
25
  | { kind: 'head-box'; head_box: HeadBoxProposal['head_box'] }
24
26
  | { kind: 'assemble-plan'; plan: PlanProposal['plan']; extend_below_crop: PlanProposal['extend_below_crop'] }
@@ -93,6 +95,22 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch): Conf
93
95
  const config = clone(before, 'config') as ConfigObject;
94
96
  const edits: ConfigEdit[] = [];
95
97
  switch (patch.kind) {
98
+ case 'edited-part-receipt': {
99
+ const checked = parseConfig(before);
100
+ const spec = checked.assemble.edited_parts;
101
+ if (spec === undefined) throw new PartsError([{ code: 'EDITED_PART_BLOCK', object: 'config.assemble.edited_parts', detail: 'has no assemble.edited_parts; declare {dir, receipts: []} before recording an edited part' }]);
102
+ const { part, file, sha256, from_sha256, editor } = patch.receipt;
103
+ if (!checked.assemble.plan.some(([name]) => name === part)) throw new PartsError([{ code: 'ASSEMBLE_EDITED_PART_UNKNOWN', object: part, detail: 'is not in assemble.plan; an existing plan part is required' }]);
104
+ const found = spec.receipts.findIndex(row => row.part === part);
105
+ const index = found === -1 ? spec.receipts.length : found;
106
+ const value = clone({ part, file, sha256, from_sha256, editor }, 'receipt');
107
+ const receipts = ((config.assemble as ConfigObject).edited_parts as ConfigObject).receipts as ConfigJson[];
108
+ if (found !== -1 && equal(receipts[index], value)) return { config, changes: [], edits: [] };
109
+ receipts[index] = value;
110
+ // This patch owns one row, never the ledger or the whole assemble block.
111
+ return { config, changes: [{ path: `assemble.edited_parts.receipts[${index}]`, kind: found === -1 ? 'added' : 'replaced' }],
112
+ edits: [{ path: ['assemble', 'edited_parts', 'receipts', index], value, insert: found === -1 }] };
113
+ }
96
114
  case 'neck-unit': {
97
115
  const values = { bones: patch.config.bones, meshes: patch.config.meshes, regions: patch.config.regions, turn: patch.config.turn };
98
116
  for (const [key, value] of Object.entries(values)) {
@@ -211,7 +229,7 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch): Conf
211
229
  }
212
230
  return { config, changes: added, edits };
213
231
  }
214
- default: return refuse('write-config', 'has no supported operation; head-box, assemble-plan, proposal or proposal-missing is required');
232
+ default: return refuse('write-config', 'has no supported operation; edited-part-receipt, neck-unit, head-box, assemble-plan, proposal or proposal-missing is required');
215
233
  }
216
234
  return { config, changes: changes(before, config), edits };
217
235
  }
@@ -5,7 +5,8 @@
5
5
  import { createHash } from 'node:crypto';
6
6
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
7
7
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
8
- import { configFileReferences, loadConfigAndAnimations, parseConfig } from './config.ts';
8
+ import { loadConfigAndAnimations, parseConfig } from './config.ts';
9
+ import { relocateConfigReferences } from './configrelocation.ts';
9
10
  import { depthReading, readSourceDepth } from './depthsheets.ts';
10
11
  import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
11
12
  import { depthImageReference, partImageReference, readParts } from './parts.ts';
@@ -229,9 +230,7 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
229
230
  if (group.unitDepths !== undefined) target.unitDepths = group.unitDepths;
230
231
  }
231
232
  // Keep relative paths portable when relocating the output directory with its inputs.
232
- for (const ref of configFileReferences(raw)) {
233
- ref.set(relative(resolve(input.out), resolve(dirname(input.rigConfig), ref.value)));
234
- }
233
+ relocateConfigReferences(raw, dirname(input.rigConfig), input.out, 'relative');
235
234
  parseConfig(raw);
236
235
  const warnings: string[] = [];
237
236
  const writes = new Map<string, Uint8Array>(), rows: Obj[] = [], recs = rawParts.parts as Obj[];
package/src/meshdraft.ts CHANGED
@@ -60,14 +60,15 @@
60
60
  * but the process is injected, exactly as `src/check.ts` and `src/build.ts` take it.
61
61
  */
62
62
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
63
- import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
63
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
64
64
  import type { AlphaMask, MeasureRow, MeshQualityReport, MotionSchedule } from '@rig-c/core/mesh';
65
65
  import { compareMeshesInMotion, type MotionComparisonInput } from '@rig-c/core/meshcompare';
66
66
  import { MeshReductionError } from '@rig-c/core/mesh';
67
67
  import { explicitFrameId, idleSchedule } from './automotion.ts';
68
68
  import { checkStage, gateThroughRigc, type Log, RIGC_MODEL_DOCUMENT, rigStage } from './build.ts';
69
- import { BARS, type CheckReport, type PackShape, type PageEdges, type RigcRunner } from './check.ts';
69
+ import { BARS, type CheckReport, type PackShape, type PageEdges, parsePageSize, type RigcRunner } from './check.ts';
70
70
  import { type CharacterConfig, configFileReferences, type ConfigFileReference, type ContourMeshSpec, type LatticeMeshSpec, loadConfigAndAnimations, type Segment } from './config.ts';
71
+ import { relocateConfigReferences } from './configrelocation.ts';
71
72
  import { PartsError, type Problem, problemLine } from './errors.ts';
72
73
  import { IDLE_FPS } from './motion.ts';
73
74
  import { type ContourBridges, FAINT_ALPHA } from './contour.ts';
@@ -729,16 +730,13 @@ export function relativeConfigPaths(_configDir: string, o: Json): RelativeConfig
729
730
  /**
730
731
  * A config the stage builds, written as `<dir>/config.json`: `text` (the author's config at `configPath`) with
731
732
  * `meshes.<part>` replaced for every part in `meshes`, and each of its {@link relativeConfigPaths} rebased to
732
- * the file the author's config names. Edited receipt files stay relative to the destination config directory;
733
- * other references become absolute. `remesh` (issue #495) builds through the same door.
733
+ * the file the author's config names. Edited directories become relative to the destination config directory,
734
+ * with receipt files unchanged; other references become absolute. `remesh` (issue #495) builds through the same door.
734
735
  */
735
736
  export function scratchConfig(configPath: string, text: string, dir: string, meshes: ReadonlyMap<string, unknown>): string {
736
737
  const configDir = dirname(resolve(configPath));
737
738
  const o = JSON.parse(text) as Json;
738
- for (const r of relativeConfigPaths(configDir, o)) {
739
- const target = resolve(configDir, r.value);
740
- r.set(r.at.startsWith('assemble.edited_parts.receipts[') ? relative(resolve(dir), target).replaceAll('\\', '/') : target);
741
- }
739
+ relocateConfigReferences(o, configDir, dir, 'absolute');
742
740
  o.meshes = { ...(o.meshes as Json), ...Object.fromEntries(meshes) };
743
741
  mkdirSync(dir, { recursive: true });
744
742
  writeFileSync(join(dir, 'config.json'), `${JSON.stringify(o, null, 2)}\n`);
@@ -758,6 +756,7 @@ export interface MeshDraftInput {
758
756
  idleKeys?: IdleKeys;
759
757
  pageEdges?: PageEdges;
760
758
  packShape?: PackShape;
759
+ pageSize?: number;
761
760
  /** `--more-triangles` ({@link MORE_TRIANGLES_FLAG}): reading 5 is reported, not a line. Absent or false: it is a line. */
762
761
  moreTriangles?: boolean;
763
762
  }
@@ -848,6 +847,7 @@ function attachmentOf(rig: RigSpec, part: string): MeshAttachment {
848
847
  * PASS, and returns the rows.
849
848
  */
850
849
  export function meshDraftStage(input: MeshDraftInput, rigc: RigcRunner, checkBin: string, scratch: string, log: Log): MeshDraftResult {
850
+ const pageSize = parsePageSize(input.pageSize);
851
851
  const text = readFileSync(input.config, 'utf8');
852
852
  const { config: cfg, animations } = loadConfigAndAnimations(input.config);
853
853
  const raw = JSON.parse(text) as Json;
@@ -868,9 +868,9 @@ export function meshDraftStage(input: MeshDraftInput, rigc: RigcRunner, checkBin
868
868
  const rigDir = join(scratch, name, 'rig');
869
869
  const at = configWith(name, meshes);
870
870
  try {
871
- rigStage({ config: at, parts: input.parts, out: rigDir, ...(input.idleKeys === undefined ? {} : { idleKeys: input.idleKeys }), ...(input.pageEdges === undefined ? {} : { pageEdges: input.pageEdges }), ...(input.packShape === undefined ? {} : { packShape: input.packShape }) }, rigc, join(scratch, name, 'gate'), (l) => log(`[${name}:rig] ${l}`));
871
+ rigStage({ config: at, parts: input.parts, out: rigDir, ...(input.idleKeys === undefined ? {} : { idleKeys: input.idleKeys }), ...(input.pageEdges === undefined ? {} : { pageEdges: input.pageEdges }), ...(input.packShape === undefined ? {} : { packShape: input.packShape }), ...(pageSize === undefined ? {} : { pageSize }) }, rigc, join(scratch, name, 'gate'), (l) => log(`[${name}:rig] ${l}`));
872
872
  if (!check) return { rigDir };
873
- const report = checkStage({ rig: rigDir, parts: input.parts, out: join(scratch, name, 'check'), seamPairs: true, ...(input.requirements === undefined ? {} : { requirements: input.requirements }), ...(input.pageEdges === undefined ? {} : { pageEdges: input.pageEdges }), ...(input.packShape === undefined ? {} : { packShape: input.packShape }) }, rigc, checkBin, (l) => log(`[${name}:check] ${l}`));
873
+ const report = checkStage({ rig: rigDir, parts: input.parts, out: join(scratch, name, 'check'), seamPairs: true, ...(input.requirements === undefined ? {} : { requirements: input.requirements }), ...(input.pageEdges === undefined ? {} : { pageEdges: input.pageEdges }), ...(input.packShape === undefined ? {} : { packShape: input.packShape }), ...(pageSize === undefined ? {} : { pageSize }) }, rigc, checkBin, (l) => log(`[${name}:check] ${l}`));
874
874
  return { rigDir, report };
875
875
  } catch (err) {
876
876
  if (!(err instanceof PartsError)) throw err;
package/src/remesh.ts CHANGED
@@ -65,7 +65,7 @@ import { createHash } from 'node:crypto';
65
65
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
66
66
  import { dirname, join, relative, resolve, sep } from 'node:path';
67
67
  import { checkStage, gateThroughRigc, type Log, RIGC_MODEL_DOCUMENT, rigStage } from './build.ts';
68
- import { barsNotMet, type CheckReport, checkStatuses, type CheckStatus, checkSummaryLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackShape, type PageEdges, rigcRanClause, type RigcRunner } from './check.ts';
68
+ import { barsNotMet, type CheckReport, checkStatuses, type CheckStatus, checkSummaryLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackMode, type PackShape, type PageEdges, parsePageSize, rigcRanClause, type RigcRunner } from './check.ts';
69
69
  import { loadConfigAndAnimations } from './config.ts';
70
70
  import { PartsError, type Problem, problemLine, refuseIfAny } from './errors.ts';
71
71
  import { jsonValueSpan, scratchConfig } from './meshdraft.ts';
@@ -113,6 +113,7 @@ export interface RemeshInput {
113
113
  idleKeys?: IdleKeys;
114
114
  pageEdges?: PageEdges;
115
115
  packShape?: PackShape;
116
+ pageSize?: number;
116
117
  requirements?: string;
117
118
  /** Issue #617: a {@link INPUT_CHECK_FILE} an earlier run wrote over this input; its check is reused when it is bound to this run's input. */
118
119
  inputCheck?: string;
@@ -520,7 +521,7 @@ export const INPUT_CHECK_FILE = 'input-check.json';
520
521
  */
521
522
  export interface InputCheckBinding {
522
523
  versions: { parts: string; rigc: string };
523
- options: { page_edges: PageEdges; pack_shape: PackShape; requirements: { path: string; sha256: string } | null };
524
+ options: { page_edges: PageEdges; pack_shape: PackShape; page_size?: number; requirements: { path: string; sha256: string } | null };
524
525
  rig: { dir: string; files: HashRow[] };
525
526
  parts: { dir: string; files: HashRow[] };
526
527
  }
@@ -540,7 +541,7 @@ export function rigcVersionText(rigc: RigcRunner, op: 'remesh' | 'retune'): stri
540
541
  }
541
542
 
542
543
  /** The binding of this run's input: what the input's `check` would read now ({@link InputCheckBinding}). */
543
- export function inputCheckBinding(rigAt: string, tree: FileTree, partsDir: string, requirements: string | undefined, pageEdges: PageEdges, packShape: PackShape, versions: { parts: string; rigc: string }): InputCheckBinding {
544
+ export function inputCheckBinding(rigAt: string, tree: FileTree, partsDir: string, requirements: string | undefined, pageEdges: PageEdges, packShape: PackShape, versions: { parts: string; rigc: string }, pageSize?: number): InputCheckBinding {
544
545
  const partsAt = resolve(partsDir);
545
546
  const partsTree: FileTree = new Map();
546
547
  const json = join(partsAt, 'parts.json');
@@ -555,7 +556,7 @@ export function inputCheckBinding(rigAt: string, tree: FileTree, partsDir: strin
555
556
  }
556
557
  return {
557
558
  versions: { parts: versions.parts, rigc: versions.rigc },
558
- options: { page_edges: pageEdges, pack_shape: packShape, requirements: req },
559
+ options: { page_edges: pageEdges, pack_shape: packShape, ...(pageSize === undefined ? {} : { page_size: pageSize }), requirements: req },
559
560
  rig: { dir: resolve(rigAt), files: hashRows(tree) },
560
561
  parts: { dir: partsAt, files: hashRows(new Map([...partsTree].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))) },
561
562
  };
@@ -604,7 +605,8 @@ export function readInputCheck(path: string, op: 'remesh' | 'retune'): InputChec
604
605
  field('versions', isRecord(v) && typeof v.parts === 'string' && typeof v.rigc === 'string', '{ parts, rigc } as strings');
605
606
  const o = raw.options;
606
607
  const req = isRecord(o) ? o.requirements : undefined;
607
- field('options', isRecord(o) && typeof o.page_edges === 'string' && typeof o.pack_shape === 'string' && (req === null || (isRecord(req) && typeof req.path === 'string' && typeof req.sha256 === 'string')), '{ page_edges, pack_shape, requirements: null or { path, sha256 } }');
608
+ const psOk = isRecord(o) && (!Object.hasOwn(o, 'page_size') || o.page_size === undefined || (typeof o.page_size === 'number' && Number.isSafeInteger(o.page_size) && o.page_size >= 1));
609
+ field('options', isRecord(o) && typeof o.page_edges === 'string' && typeof o.pack_shape === 'string' && psOk && (req === null || (isRecord(req) && typeof req.path === 'string' && typeof req.sha256 === 'string')), '{ page_edges, pack_shape, page_size?: integer >= 1, requirements: null or { path, sha256 } }');
608
610
  for (const k of ['rig', 'parts'] as const) {
609
611
  const t = raw[k];
610
612
  field(k, isRecord(t) && typeof t.dir === 'string' && isRows(t.files), '{ dir, files: [{ path, bytes, sha256 }] }');
@@ -642,6 +644,7 @@ export function inputCheckBoundProblems(recorded: InputCheckBinding, now: InputC
642
644
  if (recorded.versions.rigc !== now.versions.rigc) moved('versions.rigc', recorded.versions.rigc, now.versions.rigc, 'the check was measured under another rigc');
643
645
  if (recorded.options.page_edges !== now.options.page_edges) moved('options.page_edges', recorded.options.page_edges, now.options.page_edges, 'the check packed its pages another way');
644
646
  if (recorded.options.pack_shape !== now.options.pack_shape) moved('options.pack_shape', recorded.options.pack_shape, now.options.pack_shape, 'the check packed its pages another way');
647
+ if (recorded.options.page_size !== now.options.page_size) moved('options.page_size', recorded.options.page_size ?? 'absent', now.options.page_size ?? 'absent', 'the check packed its pages another way');
645
648
  const ra = recorded.options.requirements;
646
649
  const rb = now.options.requirements;
647
650
  if (ra === null || rb === null) {
@@ -686,10 +689,11 @@ export function inputCheckOf(
686
689
  partsVersion: string,
687
690
  rigc: RigcRunner,
688
691
  op: 'remesh' | 'retune',
692
+ pageSize?: number,
689
693
  ): { binding: InputCheckBinding | null; reused: CheckSide | null } {
690
694
  if (req.inputCheck === undefined && req.recordInputCheck !== true) return { binding: null, reused: null };
691
695
  const recorded = req.inputCheck === undefined ? null : readInputCheck(req.inputCheck, op);
692
- const binding = inputCheckBinding(rigAt, tree, req.parts, req.requirements, pageEdges, packShape, { parts: partsVersion, rigc: rigcVersionText(rigc, op) });
696
+ const binding = inputCheckBinding(rigAt, tree, req.parts, req.requirements, pageEdges, packShape, { parts: partsVersion, rigc: rigcVersionText(rigc, op) }, pageSize);
693
697
  if (recorded === null) return { binding, reused: null };
694
698
  refuseIfAny(inputCheckBoundProblems(recorded, binding, req.inputCheck as string, op));
695
699
  return { binding, reused: canonicalSide(recorded.check) };
@@ -703,7 +707,7 @@ export function inputCheckOf(
703
707
  */
704
708
  export function inputCheckMovedProblems(first: InputCheckBinding, req: { requirements?: string; parts: string }, rigAt: string, op: 'remesh' | 'retune'): Problem[] {
705
709
  const code = REVISION_CODES[op].inputCheckMoved;
706
- const second = inputCheckBinding(rigAt, readTree(rigAt), req.parts, req.requirements, first.options.page_edges, first.options.pack_shape, first.versions);
710
+ const second = inputCheckBinding(rigAt, readTree(rigAt), req.parts, req.requirements, first.options.page_edges, first.options.pack_shape, first.versions, first.options.page_size);
707
711
  const out: Problem[] = [];
708
712
  const row = (r: HashRow | undefined): string => (r === undefined ? 'absent' : `${r.bytes} bytes sha256 ${r.sha256}`);
709
713
  const moved = (object: string, before: string, after: string): void => {
@@ -909,6 +913,8 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
909
913
  const idleKeys = input.idleKeys ?? DEFAULT_IDLE_KEYS;
910
914
  const pageEdges = input.pageEdges ?? DEFAULT_PAGE_EDGES;
911
915
  const packShape = input.packShape ?? DEFAULT_PACK_SHAPE;
916
+ const pageSize = parsePageSize(input.pageSize);
917
+ const mode: PackMode = { pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }) };
912
918
  // 1. The input, the out and the request.
913
919
  const outAt = resolve(input.out);
914
920
  const rigAt = resolve(input.rig);
@@ -918,7 +924,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
918
924
  const tree = readTree(rigAt);
919
925
  refuseIfAny(inputTreeProblems(tree, input.rig));
920
926
  if ((input.mesh === undefined) === (input.delta === undefined)) throw new Error('remeshStage: exactly one of mesh, delta is required');
921
- const recorded = inputCheckOf(input, rigAt, tree, pageEdges, packShape, versions.parts, rigc, 'remesh');
927
+ const recorded = inputCheckOf(input, rigAt, tree, pageEdges, packShape, versions.parts, rigc, 'remesh', pageSize);
922
928
  const meshReq = input.mesh === undefined ? null : readMeshRequest(input.mesh);
923
929
  const deltaReq = input.delta === undefined ? null : readDeltaRequest(input.delta);
924
930
  const configText = readFileSync(input.config, 'utf8');
@@ -941,7 +947,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
941
947
  const auto = 'auto' in meshReq.entry;
942
948
  const build = (name: string, config: string): Built => {
943
949
  const out = join(scratch, name, 'rig');
944
- rigStage({ config, parts: input.parts, out, idleKeys, pageEdges, packShape }, rigc, join(scratch, name, 'gate'), (l) => log(`[${name}:rig] ${l}`));
950
+ rigStage({ config, parts: input.parts, out, idleKeys, pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }) }, rigc, join(scratch, name, 'gate'), (l) => log(`[${name}:rig] ${l}`));
945
951
  return readBuilt(out, part);
946
952
  };
947
953
  // 3. The baseline.
@@ -978,7 +984,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
978
984
  refuseIfAny(deltaSourceProblems(doc, part, inAtt, deltaPath));
979
985
  log(`rig-parts remesh: ${part} of ${input.rig}, ${tree.size} file(s); the request is a mesh edit of ${doc.ops.length} op(s), the baseline is the input itself`);
980
986
  let model = null as string | null;
981
- const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate-input'), { pageEdges, packShape }, (dir) => {
987
+ const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate-input'), mode, (dir) => {
982
988
  const p = join(dir, RIGC_MODEL_DOCUMENT);
983
989
  model = existsSync(p) ? readFileSync(p, 'utf8') : null;
984
990
  });
@@ -1015,7 +1021,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
1015
1021
  log(` ${part}: v=${before.vertices} t=${before.triangles} hull=${before.hull} -> v=${after.vertices} t=${after.triangles} hull=${after.hull}`);
1016
1022
  log(` preserved: ${identical.filter((p) => p !== PROVENANCE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside skins.default.${part}.${part}; mesh_report.json identical but the "${part}" row`);
1017
1023
  // 7. The gate and check.
1018
- const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
1024
+ const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), mode);
1019
1025
  for (const g of gate) {
1020
1026
  log(` rigc ${g.label}, the revision: exit ${g.status}`);
1021
1027
  for (const l of g.lines) log(` ${l.trim()}`);
@@ -1027,7 +1033,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
1027
1033
  writeFileSync(join(staged, k), b);
1028
1034
  }
1029
1035
  const checkOf = (rig: string, name: string): CheckReport =>
1030
- checkStage({ rig, parts: input.parts, out: join(scratch, name), pageEdges, packShape, ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, rigc, checkBin, (l) => log(`[${name}] ${l}`));
1036
+ checkStage({ rig, parts: input.parts, out: join(scratch, name), pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }), ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, rigc, checkBin, (l) => log(`[${name}] ${l}`));
1031
1037
  if (recorded.reused !== null) log(inputCheckReusedLine(input.inputCheck as string, recorded.binding as InputCheckBinding));
1032
1038
  let inSide: CheckSide;
1033
1039
  if (recorded.reused !== null) inSide = recorded.reused;
@@ -2,6 +2,8 @@ import { setupPaintingProblems, type SetupPainting } from './setuppainting.ts';
2
2
  import { jointMaterialProblems, type JointMaterial } from './cutmaterial.ts';
3
3
  import { fixedSkeletonProblems, type FixedSkeleton } from './artjoints.ts';
4
4
  import { boundaryColourProblems, type BoundaryColour } from './boundarycolour.ts';
5
+ import { behindSeamsProblems, type BehindSeams } from './behindseams.ts';
6
+ import { motionSeamProblems, type MotionSeamDeclaration } from './motionseams.ts';
5
7
  /**
6
8
  * What a scene requires of a rig's motion, declared in a file `check` is given
7
9
  * (`--requirements`, issue #93, increment 2 of #87) and measured from the
@@ -209,8 +211,12 @@ export interface RequirementsFile {
209
211
  pinholes?: PinholesDeclaration;
210
212
  /** Issue #941: `check`'s background bar over every declared seam pair and every frame, only under `required: true`; absent when the file does not declare it. */
211
213
  seam_over_motion?: SeamOverMotionDeclaration;
214
+ /** Issue #1269: motion coverage without a distance bar; absence and an explicit empty inventory stay distinct. */
215
+ motion_seams?: MotionSeamDeclaration[];
212
216
  /** Issue #942: the boundary colour-step bar against the rig's own pieces, measured by `check` only when declared. */
213
217
  boundary_colour?: BoundaryColour;
218
+ /** Issue #1314: required behind-part seam readings when declared; an absent threshold is unmeasured, never defaulted. */
219
+ behind_seams?: BehindSeams;
214
220
  }
215
221
 
216
222
  /**
@@ -329,7 +335,8 @@ const EXCEPTION_ABSENT: Record<ExceptionList, string> = {
329
335
  * a name used twice, and a `contact` against its own bone and point or an
330
336
  * `aim` at a point of its own bone (issue #540: each reads 0 by construction,
331
337
  * or no line at all). Resolving the names against the rig is
332
- * {@link resolveRequirements}'s.
338
+ * {@link resolveRequirements}'s. Optional `motion_seams` declares motion coverage
339
+ * without a distance bar; its part names resolve through the same rig and parts readers.
333
340
  */
334
341
  export function readRequirements(path: string): RequirementsFile {
335
342
  const at = resolve(path);
@@ -353,10 +360,19 @@ export function readRequirements(path: string): RequirementsFile {
353
360
  problems.push({ code: 'REQUIREMENTS_SELF_TARGET', object: `${label} field "target"`, detail });
354
361
  };
355
362
  if (raw.spec !== REQUIREMENTS_SPEC) field(`${at} field "spec"`, `is ${JSON.stringify(raw.spec)}; ${JSON.stringify(REQUIREMENTS_SPEC)} is required`);
356
- for (const k of Object.keys(raw)) if (!['spec', 'fps', 'targets', 'requirements', ...EXCEPTION_LISTS, 'may_fold', 'fixed_skeleton', 'cut_material', 'setup_painting', 'pinholes', 'seam_over_motion', 'boundary_colour'].includes(k) && !freeKey(k, raw[k])) field(`${at} field "${k}"`, 'is not a field this format reads (spec, fps, targets, requirements, not_planted, not_swinging, rises, rests, may_fold, fixed_skeleton, cut_material, setup_painting, pinholes, seam_over_motion, boundary_colour; note or *_note as a string; x-<name> as a record)');
363
+ for (const k of Object.keys(raw)) if (!['spec', 'fps', 'targets', 'requirements', ...EXCEPTION_LISTS, 'may_fold', 'fixed_skeleton', 'cut_material', 'setup_painting', 'pinholes', 'seam_over_motion', 'motion_seams', 'boundary_colour', 'behind_seams'].includes(k) && !freeKey(k, raw[k])) field(`${at} field "${k}"`, 'is not a field this format reads (spec, fps, targets, requirements, not_planted, not_swinging, rises, rests, may_fold, fixed_skeleton, cut_material, setup_painting, pinholes, seam_over_motion, motion_seams, boundary_colour, behind_seams; note or *_note as a string; x-<name> as a record)');
364
+ if ('motion_seams' in raw) {
365
+ // Shape uses the shared reader; actual names resolve against the rig and parts below.
366
+ const names = new Set<string>();
367
+ if (Array.isArray(raw.motion_seams)) for (const row of raw.motion_seams) if (isRecord(row)) {
368
+ for (const name of [row.part, row.neighbour]) if (typeof name === 'string') names.add(name);
369
+ }
370
+ problems.push(...motionSeamProblems(raw.motion_seams, names, `${at} motion_seams`, 'REQUIREMENTS_FIELD'));
371
+ }
357
372
  if ('pinholes' in raw) problems.push(...pinholesProblems(raw.pinholes, `${at} pinholes`));
358
373
  if ('seam_over_motion' in raw) problems.push(...seamOverMotionProblems(raw.seam_over_motion, `${at} seam_over_motion`));
359
374
  if ('boundary_colour' in raw) problems.push(...boundaryColourProblems(raw.boundary_colour, `${at} boundary_colour`));
375
+ if ('behind_seams' in raw) problems.push(...behindSeamsProblems(raw.behind_seams, `${at} behind_seams`));
360
376
  if ('setup_painting' in raw) problems.push(...setupPaintingProblems(raw.setup_painting, `${at} setup_painting`));
361
377
  if ('cut_material' in raw) problems.push(...jointMaterialProblems(raw.cut_material, `${at} cut_material`));
362
378
  if ('fixed_skeleton' in raw) problems.push(...fixedSkeletonProblems(raw.fixed_skeleton, `${at} fixed_skeleton`));
@@ -545,7 +561,7 @@ export function readRequirements(path: string): RequirementsFile {
545
561
  }
546
562
  const fps = finite(raw.fps) ? raw.fps : undefined;
547
563
  refuseIfAny(problems);
548
- return { path: at, fps, targets, requirements, not_planted: lists.not_planted, not_swinging: lists.not_swinging, rises: lists.rises, rests: lists.rests, may_fold: mayFold, ...(raw.fixed_skeleton === undefined ? {} : { fixed_skeleton: raw.fixed_skeleton as FixedSkeleton }), ...(raw.cut_material === undefined ? {} : { cut_material: raw.cut_material as JointMaterial[] }), ...(raw.setup_painting === undefined ? {} : { setup_painting: raw.setup_painting as SetupPainting }), ...(raw.pinholes === undefined ? {} : { pinholes: { required: (raw.pinholes as PinholesDeclaration).required } }), ...(raw.seam_over_motion === undefined ? {} : { seam_over_motion: { required: (raw.seam_over_motion as SeamOverMotionDeclaration).required } }), ...(raw.boundary_colour === undefined ? {} : { boundary_colour: { max_step_excess: (raw.boundary_colour as BoundaryColour).max_step_excess } }) };
564
+ return { path: at, fps, targets, requirements, not_planted: lists.not_planted, not_swinging: lists.not_swinging, rises: lists.rises, rests: lists.rests, may_fold: mayFold, ...(raw.motion_seams === undefined ? {} : { motion_seams: raw.motion_seams as MotionSeamDeclaration[] }), ...(raw.fixed_skeleton === undefined ? {} : { fixed_skeleton: raw.fixed_skeleton as FixedSkeleton }), ...(raw.cut_material === undefined ? {} : { cut_material: raw.cut_material as JointMaterial[] }), ...(raw.setup_painting === undefined ? {} : { setup_painting: raw.setup_painting as SetupPainting }), ...(raw.pinholes === undefined ? {} : { pinholes: { required: (raw.pinholes as PinholesDeclaration).required } }), ...(raw.seam_over_motion === undefined ? {} : { seam_over_motion: { required: (raw.seam_over_motion as SeamOverMotionDeclaration).required } }), ...(raw.boundary_colour === undefined ? {} : { boundary_colour: { max_step_excess: (raw.boundary_colour as BoundaryColour).max_step_excess } }), ...(raw.behind_seams === undefined ? {} : { behind_seams: raw.behind_seams as BehindSeams }) };
549
565
  }
550
566
 
551
567
  // ---------------------------------------------------------------------------
@@ -623,6 +639,10 @@ export function resolveRequirements(file: RequirementsFile, rig: Record<string,
623
639
  const target = (object: string, t: TargetRef): void => {
624
640
  if ('bone' in t) bone(`${object} target`, t.bone);
625
641
  };
642
+ if (file.motion_seams !== undefined) {
643
+ const slots = new Set((Array.isArray(rig.slots) ? rig.slots : []).filter(isRecord).map(s => s.name).filter((name): name is string => typeof name === 'string'));
644
+ problems.push(...motionSeamProblems(file.motion_seams, slots, 'requirements.motion_seams', 'REQUIREMENTS_RESOLVES'));
645
+ }
626
646
  for (const j of file.fixed_skeleton?.joints ?? []) bone(`fixed_skeleton joint "${j.name}"`, j.bone);
627
647
  for (const r of file.requirements) {
628
648
  const object = `requirement "${r.name}" (${r.kind})`;
@@ -1263,11 +1283,17 @@ export function seamPairs(part: PlacedArt, neighbour: PlacedArt): SeamPair[] {
1263
1283
  * (`REQUIREMENTS_SEAM`, quoting why there is none); a part `parts.json` does not
1264
1284
  * list is unresolved (`REQUIREMENTS_RESOLVES`); and two parts whose art does
1265
1285
  * not meet at the setup pose share no seam (`REQUIREMENTS_SEAM`). `art` is
1266
- * asked only for parts `parts.json` lists.
1286
+ * asked only for parts `parts.json` lists. Bar-free `motion_seams` names also
1287
+ * resolve here against parts.json, without reading distance art or requiring adjacency.
1267
1288
  */
1268
1289
  export function resolveSeams(file: RequirementsFile, partNames: readonly string[] | null, noParts: string | null, art: (part: string) => PlacedArt): Map<string, SeamPair[]> {
1269
1290
  const problems: Problem[] = [];
1270
1291
  const out = new Map<string, SeamPair[]>();
1292
+ if (file.motion_seams !== undefined) {
1293
+ if (partNames === null && file.motion_seams.length > 0) {
1294
+ problems.push({ code: 'REQUIREMENTS_SEAM', object: 'requirements.motion_seams', detail: `requires parts.json to resolve the declared part names; none was read: ${noParts ?? 'no parts.json'}` });
1295
+ } else problems.push(...motionSeamProblems(file.motion_seams, new Set(partNames ?? []), 'requirements.motion_seams', 'REQUIREMENTS_RESOLVES'));
1296
+ }
1271
1297
  const cache = new Map<string, PlacedArt>();
1272
1298
  const artOf = (n: string): PlacedArt => {
1273
1299
  const hit = cache.get(n);
package/src/retune.ts CHANGED
@@ -38,7 +38,7 @@
38
38
  import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
39
39
  import { dirname, join, resolve, sep } from 'node:path';
40
40
  import { checkStage, gateThroughRigc, type Log, rigStage } from './build.ts';
41
- import { type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackShape, type PageEdges, rigcRanClause, type RigcRunner } from './check.ts';
41
+ import { type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackMode, type PackShape, type PageEdges, parsePageSize, rigcRanClause, type RigcRunner } from './check.ts';
42
42
  import { PartsError, type Problem, problemLine, refuseIfAny } from './errors.ts';
43
43
  import { type CheckSide, carryProvenance, type ParentProvenance, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, INPUT_CHECK_FILE, type InputCheckBinding, inputCheckHashes, inputCheckMovedProblems, inputCheckOf, inputCheckReusedLine, inputCheckText, inputTreeProblems, perturbed, pngsOf, readTree, sha256, textsOf } from './remesh.ts';
44
44
  import { DEFAULT_IDLE_KEYS, type IdleKeys, rigJsonText } from './rig.ts';
@@ -71,6 +71,7 @@ export interface RetuneInput {
71
71
  idleKeys?: IdleKeys;
72
72
  pageEdges?: PageEdges;
73
73
  packShape?: PackShape;
74
+ pageSize?: number;
74
75
  requirements?: string;
75
76
  /** Issue #617: a recorded input check (`input-check.json`, as `remesh` writes it) reused when it is bound to this run's input. */
76
77
  inputCheck?: string;
@@ -343,6 +344,8 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
343
344
  const idleKeys = input.idleKeys ?? DEFAULT_IDLE_KEYS;
344
345
  const pageEdges = input.pageEdges ?? DEFAULT_PAGE_EDGES;
345
346
  const packShape = input.packShape ?? DEFAULT_PACK_SHAPE;
347
+ const pageSize = parsePageSize(input.pageSize);
348
+ const mode: PackMode = { pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }) };
346
349
  // 1. The input and the out.
347
350
  const outAt = resolve(input.out);
348
351
  const rigAt = resolve(input.rig);
@@ -351,13 +354,13 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
351
354
  if (outAt.startsWith(`${rigAt}${sep}`)) throw new PartsError([{ code: 'RETUNE_OUT_FRESH', object: input.out, detail: `is inside the input ${input.rig}; a revision is written beside the input, never into it` }]);
352
355
  const tree = readTree(rigAt);
353
356
  refuseIfAny(inputTreeProblems(tree, input.rig, 'retune', RETUNE_SPLICED));
354
- const recorded = inputCheckOf(input, rigAt, tree, pageEdges, packShape, versions.parts, rigc, 'retune');
357
+ const recorded = inputCheckOf(input, rigAt, tree, pageEdges, packShape, versions.parts, rigc, 'retune', pageSize);
355
358
  const inFiles = rigFiles(tree);
356
359
  // 2. The rebuild.
357
360
  log(`rig-parts retune: ${input.rig}, ${tree.size} file(s); the rebuild is the config as written`);
358
361
  const rebuiltAt = join(scratch, 'rebuild', 'rig');
359
362
  try {
360
- rigStage({ config: input.config, parts: input.parts, out: rebuiltAt, idleKeys, pageEdges, packShape }, rigc, join(scratch, 'rebuild', 'gate'), (l) => log(`[rebuild:rig] ${l}`));
363
+ rigStage({ config: input.config, parts: input.parts, out: rebuiltAt, idleKeys, pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }) }, rigc, join(scratch, 'rebuild', 'gate'), (l) => log(`[rebuild:rig] ${l}`));
361
364
  } catch (err) {
362
365
  if (!(err instanceof PartsError)) throw err;
363
366
  throw new PartsError(err.problems.map((p) => ({ code: 'RETUNE_CONFIG_REFUSED', object: `${input.config} as written`, detail: `the rig stage refuses it, nothing is written: ${problemLine(p)}` })));
@@ -379,7 +382,7 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
379
382
  log(` idle: ${changed.idle.tracks_changed} track(s) changed, duration ${changed.idle.duration[0]} -> ${changed.idle.duration[1]}`);
380
383
  log(` preserved: ${identical.filter((p) => p !== RETUNE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside constraints and invariants.detached; motion.json identical outside animations.idle`);
381
384
  // 6. The gate and check.
382
- const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
385
+ const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), mode);
383
386
  for (const g of gate) {
384
387
  log(` rigc ${g.label}, the revision: exit ${g.status}`);
385
388
  for (const l of g.lines) log(` ${l.trim()}`);
@@ -391,7 +394,7 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
391
394
  writeFileSync(join(staged, k), b);
392
395
  }
393
396
  const checkOf = (rig: string, name: string): CheckReport =>
394
- checkStage({ rig, parts: input.parts, out: join(scratch, name), pageEdges, packShape, ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, rigc, checkBin, (l) => log(`[${name}] ${l}`));
397
+ checkStage({ rig, parts: input.parts, out: join(scratch, name), pageEdges, packShape, ...(pageSize === undefined ? {} : { pageSize }), ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, rigc, checkBin, (l) => log(`[${name}] ${l}`));
395
398
  if (recorded.reused !== null) log(inputCheckReusedLine(input.inputCheck as string, recorded.binding as InputCheckBinding));
396
399
  let inSide: CheckSide;
397
400
  if (recorded.reused !== null) inSide = recorded.reused;
package/src/runstamp.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { basename, join, relative, resolve, sep } from 'node:path';
4
4
  import { type AssembleResult, FIGURE_MASK_FILE } from './assemble.ts';
5
5
  import { ERROR_MAP_FILE } from './build.ts';
@@ -16,8 +16,10 @@ import { SUPPORT_DOMAINS_FILE } from './supportdomains.ts';
16
16
 
17
17
  export const RUN_STAMP_SPEC = 'rig-run/1' as const;
18
18
  export const RUN_STAMP_FILE = 'run.json' as const;
19
+ export const RUN_STAMP_INPUT_ROLES = ['source', 'full', 'head'] as const;
19
20
 
20
21
  export type RunStampCommand = 'rig' | 'assemble';
22
+ export type RunStampInputRole = (typeof RUN_STAMP_INPUT_ROLES)[number];
21
23
 
22
24
  export interface RunStampPackage {
23
25
  name: string;
@@ -29,6 +31,19 @@ export interface RunStampFileEntry {
29
31
  sha256: string;
30
32
  }
31
33
 
34
+ export interface RunStampInputEntry {
35
+ role: RunStampInputRole;
36
+ path: string;
37
+ sha256: string;
38
+ }
39
+
40
+ export interface RunStampAssembleInputs {
41
+ cwd?: string;
42
+ source: string;
43
+ full: string;
44
+ head?: string | null;
45
+ }
46
+
32
47
  export interface RunStamp {
33
48
  spec: typeof RUN_STAMP_SPEC;
34
49
  package: RunStampPackage;
@@ -36,6 +51,7 @@ export interface RunStamp {
36
51
  started_at: string;
37
52
  finished_at: string;
38
53
  config: RunStampFileEntry;
54
+ inputs?: RunStampInputEntry[];
39
55
  outputs: RunStampFileEntry[];
40
56
  }
41
57
 
@@ -46,6 +62,7 @@ export interface RunStampInput {
46
62
  finishedAt: string;
47
63
  outDir: string;
48
64
  configPath: string;
65
+ inputs?: RunStampAssembleInputs;
49
66
  outputPaths: readonly string[];
50
67
  }
51
68
 
@@ -59,6 +76,40 @@ function relativeToOutRoot(outDir: string, targetPath: string): string {
59
76
  return relative(realOut, realTarget).split(sep).join('/');
60
77
  }
61
78
 
79
+ function relativeToCwd(cwd: string, targetPath: string): string {
80
+ const rel = relative(resolve(cwd), resolve(cwd, targetPath)).split(sep).join('/');
81
+ return rel === '' ? '.' : rel;
82
+ }
83
+
84
+ function inputSha256OnDisk(cwd: string, targetPath: string): string {
85
+ const resolved = resolve(cwd, targetPath);
86
+ const filePath = statSync(resolved).isDirectory() ? join(resolved, 'layers.json') : resolved;
87
+ return sha256OnDisk(filePath);
88
+ }
89
+
90
+ /**
91
+ * Build the ordered `inputs` list (`source`, `full`, and `head` when given) for an `assemble` run stamp:
92
+ * each entry records `role`, `path` relative to `cwd`, and `sha256` of the file or of `<dir>/layers.json`.
93
+ */
94
+ export function buildAssembleInputs(inputs: RunStampAssembleInputs): RunStampInputEntry[] {
95
+ const cwd = inputs.cwd ?? process.cwd();
96
+ const raw: ReadonlyArray<readonly [RunStampInputRole, string | null | undefined]> = [
97
+ ['source', inputs.source],
98
+ ['full', inputs.full],
99
+ ['head', inputs.head],
100
+ ];
101
+ const entries: RunStampInputEntry[] = [];
102
+ for (const [role, given] of raw) {
103
+ if (given === undefined || given === null) continue;
104
+ entries.push({
105
+ role,
106
+ path: relativeToCwd(cwd, given),
107
+ sha256: inputSha256OnDisk(cwd, given),
108
+ });
109
+ }
110
+ return entries;
111
+ }
112
+
62
113
  function sortCodeUnits(paths: readonly string[]): string[] {
63
114
  return [...new Set(paths.filter((p) => p !== RUN_STAMP_FILE))].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
64
115
  }
@@ -158,6 +209,7 @@ export function buildRunStamp(input: RunStampInput): RunStamp {
158
209
  path: rel,
159
210
  sha256: sha256OnDisk(join(input.outDir, ...rel.split('/'))),
160
211
  }));
212
+ const inputs = input.inputs === undefined ? undefined : buildAssembleInputs(input.inputs);
161
213
  return {
162
214
  spec: RUN_STAMP_SPEC,
163
215
  package: {
@@ -171,6 +223,7 @@ export function buildRunStamp(input: RunStampInput): RunStamp {
171
223
  path: relativeToOutRoot(input.outDir, input.configPath),
172
224
  sha256: sha256OnDisk(input.configPath),
173
225
  },
226
+ ...(inputs === undefined ? {} : { inputs }),
174
227
  outputs,
175
228
  };
176
229
  }
package/src/turn.ts CHANGED
@@ -1624,6 +1624,11 @@ function buildDepth25DTurnGroup(
1624
1624
  if (problems.length > startProblems) return;
1625
1625
 
1626
1626
  const primarySurface = (group.useEyeLandmarksForZRef ? surfaceSheets.get('face') : undefined) ?? [...surfaceSheets.values()][0];
1627
+ // Units already use this anchor. Surfaces must share it too: subtracting
1628
+ // each sheet's own eye sample or median erases their relative placement.
1629
+ if (primarySurface !== undefined) {
1630
+ for (const sheet of surfaceSheets.values()) sheet.zRef = primarySurface.zRef;
1631
+ }
1627
1632
  const pivot = pyRound(group.pivot, 4);
1628
1633
  const counter = group.counter;
1629
1634
  const rearDepth = pyRound(-counter * pivot, 4);