@rig-c/parts 2.38.0 → 2.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/AUTHORING.md CHANGED
@@ -8654,25 +8654,43 @@ Internal `SeamSupport.drawings` never enters check JSON. Named requirement
8654
8654
 
8655
8655
  Import `configFileReferences` and, for annotations, `ConfigFileReference` from
8656
8656
  `@rig-c/parts/src/config.ts` (issue #1134). Pass the JSON-parsed config object before
8657
- loading it. Each result exposes `at`, the dotted field path, `value`, the path
8658
- as declared, and `set(next)`, which writes back to that field. Enumeration
8657
+ loading it. Each result exposes `at`, the dotted field path, `value`, the file
8658
+ path, and `set(next)`, which writes back to that field. Enumeration
8659
8659
  leaves the object unchanged, skips absent, empty and non-string fields, and
8660
8660
  excludes built-in skeleton names. It performs no validation or file reads;
8661
8661
  use the normal loader for diagnostics.
8662
8662
 
8663
8663
  ```ts
8664
8664
  import { configFileReferences } from '@rig-c/parts/src/config.ts';
8665
- import { dirname, resolve } from 'node:path';
8665
+ import { dirname, relative, resolve } from 'node:path';
8666
8666
 
8667
8667
  for (const reference of configFileReferences(raw)) {
8668
- reference.set(resolve(dirname(sourceConfig), reference.value));
8668
+ const target = resolve(dirname(sourceConfig), reference.value);
8669
+ reference.set(relative(dirname(destinationConfig), target).replaceAll('\\', '/'));
8669
8670
  }
8670
8671
  ```
8671
8672
 
8672
- Here `sourceConfig` is the absolute original config filename and `raw` is its
8673
- JSON-parsed object. Serialize that object at the destination after copying any
8674
- referenced files; callers that copy files can instead set their new relative
8675
- paths. The enumerator derives membership from the loader's own declarations.
8673
+ Here `sourceConfig` and `destinationConfig` are absolute config filenames and
8674
+ `raw` is the source's JSON-parsed object. Serialize it at `destinationConfig`;
8675
+ the relative paths keep pointing to the original files. Callers that copy files
8676
+ can instead set paths to the copies, relative to the destination config.
8677
+
8678
+ The declared fields are `requirements`, `motion.animations_from`, non-built-in
8679
+ `generation.control.skeleton`, each `assemble.occluders[i].image` and optional
8680
+ `plate`, and `assemble.edited_parts.receipts[i].file`. Each edited receipt's
8681
+ value joins its shared `dir` and its `file` with POSIX path semantics; the
8682
+ directory itself is not a reference. Its setter uses normalized POSIX segments,
8683
+ independent of the cwd, and reads the live `dir` on each call. When the target is
8684
+ representable under that directory, `dir` and every sibling receipt remain
8685
+ byte-for-byte unchanged. Otherwise it rebases `dir` to the normalized lexical
8686
+ common prefix with the target (`.` for an empty prefix), rewriting sibling files
8687
+ to preserve their original config-relative targets. This also applies to setters
8688
+ from the same enumeration after a rebase; enumerate again to read updated values.
8689
+ Invalid directories and invalid sibling fields remain for the loader to diagnose.
8690
+ Keep edited targets config-relative: an absolute
8691
+ target, including Windows absolute forms, is preserved as an absolute `file`
8692
+ and refused by the loader's existing `CONFIG_FIELD_TYPE`. This does not change
8693
+ the edited-parts reader or its refusals.
8676
8694
 
8677
8695
  `checkFileReferences(raw, configFile, requirements?)` and `CheckFileReference`
8678
8696
  are exported from the same `@rig-c/parts/src/config.ts` subpath (issue #1138).
package/docs/STABILITY.md CHANGED
@@ -137,9 +137,26 @@ Each reference has `at: string` (a dotted config field), `value: string`
137
137
  on the supplied object. Enumeration itself does not mutate, validate, read files,
138
138
  or resolve paths. Empty and non-string values are omitted; invalid fields remain
139
139
  for the loader to diagnose. Built-in control skeleton names are excluded.
140
- The loader's file-field declarations determine membership; no separate list is
141
- maintained. Resolve `value` against the source config directory when relocating.
142
- Existing deep package paths remain available.
140
+ Declared references are `requirements`, `motion.animations_from`, non-built-in
141
+ `generation.control.skeleton`, each `assemble.occluders[i].image` and optional
142
+ `plate`, then each `assemble.edited_parts.receipts[i].file` (issue #1281).
143
+ An edited receipt's `value` is `posix.join(dir, file)`, relative to the config;
144
+ there is no `edited_parts.dir` reference. Its `set(next)` takes a config-relative
145
+ path and derives `file` from normalized POSIX segments without resolving either
146
+ operand against the process cwd. If the target is representable under the current
147
+ `dir`, that directory and every sibling receipt remain byte-for-byte unchanged.
148
+ Otherwise, `dir` becomes its normalized lexical common prefix with the target
149
+ (`.` for an empty prefix), and sibling files are rewritten to preserve their
150
+ original config-relative targets. Setters read the live directory, including
151
+ after another setter from the same enumeration rebases it. Invalid directories
152
+ and invalid sibling fields remain for the existing loader diagnostics.
153
+ Absolute targets, including Windows absolute forms, remain absolute in `file`
154
+ and are refused by the existing `CONFIG_FIELD_TYPE` check at the next load.
155
+ When relocating a config, resolve each source value, then pass its path relative
156
+ to the destination config directory for edited receipts. Other setters retain
157
+ their existing path contract. Enumeration follows the loader and assemble reader
158
+ declarations; it adds no file reads or validation. Existing deep package paths
159
+ remain available.
143
160
 
144
161
  The same subpath exports `checkFileReferences(raw: unknown, configFile: string,
145
162
  requirements?: RequirementsFile): CheckFileReference[]` and the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/parts",
3
- "version": "2.38.0",
3
+ "version": "2.38.1",
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
  "bin": {
package/src/config.ts CHANGED
@@ -95,7 +95,7 @@ import type { DepthConfig } from './depthsheets.ts';
95
95
  * the field is a non-empty string.
96
96
  */
97
97
  import { existsSync, readFileSync, statSync } from 'node:fs';
98
- import { dirname, isAbsolute, relative, resolve } from 'node:path';
98
+ import { dirname, isAbsolute, posix, relative, resolve } from 'node:path';
99
99
  import { RIG_BONE_INHERIT, RIG_SKIN_CONSTRAINT_KEYS, type RigBoneInherit, type RigConstraint, type RigSkinConstraintKey, type RigStop } from '@rig-c/core/rig';
100
100
  import { pyRound } from './round.ts';
101
101
  import { motionSeamProblems, type MotionSeamDeclaration } from './motionseams.ts';
@@ -1481,7 +1481,30 @@ export interface ConfigFileReference {
1481
1481
  set: (value: string) => void;
1482
1482
  }
1483
1483
 
1484
- /** Enumerate the same file fields that the loader resolves, preserving invalid fields for its diagnostics. */
1484
+ /** Normalized POSIX segments; neither operand is resolved against the cwd. */
1485
+ function editedPathSegments(path: string): string[] {
1486
+ return posix.normalize(path).split('/').filter(p => p !== '' && p !== '.');
1487
+ }
1488
+
1489
+ function editedPathPrefix(from: readonly string[], to: readonly string[]): number {
1490
+ let common = 0;
1491
+ while (common < from.length && common < to.length && from[common] === to[common]) common++;
1492
+ return common;
1493
+ }
1494
+
1495
+ /** Same absolute forms the relative-only loader refuses, including Windows forms. */
1496
+ function editedPathAbsolute(path: string): boolean {
1497
+ return isAbsolute(path) || /^(?:[\\/]|[A-Za-z]:[\\/])/.test(path);
1498
+ }
1499
+
1500
+ /** Relative segments for a target representable under dir, including rebased siblings. */
1501
+ function relativeEditedFile(dir: string, next: string): string {
1502
+ const from = editedPathSegments(dir), to = editedPathSegments(next);
1503
+ const common = editedPathPrefix(from, to);
1504
+ return [...from.slice(common).map(() => '..'), ...to.slice(common)].join('/');
1505
+ }
1506
+
1507
+ /** Enumerate loader and assemble file references, preserving invalid fields for their diagnostics. */
1485
1508
  export function configFileReferences(raw: unknown): ConfigFileReference[] {
1486
1509
  const out: ConfigFileReference[] = [];
1487
1510
  for (const field of Object.values(CONFIG_FILE_FIELDS)) {
@@ -1506,6 +1529,36 @@ export function configFileReferences(raw: unknown): ConfigFileReference[] {
1506
1529
  out.push({ at: `assemble.occluders[${i}].plate`, value: entry.plate, set: (next) => { entry.plate = next; } });
1507
1530
  }
1508
1531
  });
1532
+ // Issue #1281: receipt files cover this directory without declaring a directory input.
1533
+ const edited = isPlainObject(assemble) ? assemble.edited_parts : undefined;
1534
+ if (isPlainObject(edited) && typeof edited.dir === 'string' && edited.dir !== '' && Array.isArray(edited.receipts)) {
1535
+ const enumerationDir = edited.dir, receipts = edited.receipts;
1536
+ receipts.forEach((entry: unknown, i: number) => {
1537
+ if (!isPlainObject(entry) || typeof entry.file !== 'string' || entry.file === '') return;
1538
+ out.push({ at: `assemble.edited_parts.receipts[${i}].file`, value: posix.join(enumerationDir, entry.file), set: (next) => {
1539
+ // Preserve invalid absolute targets for the existing relative-only loader refusal.
1540
+ if (editedPathAbsolute(next)) { entry.file = next; return; }
1541
+ // A previous setter from this enumeration may have rebased the shared dir.
1542
+ const liveDir = edited.dir;
1543
+ if (typeof liveDir !== 'string' || liveDir.trim() === '' || editedPathAbsolute(liveDir)) {
1544
+ entry.file = next;
1545
+ return; // Do not repair invalid dirs or hide their existing loader diagnostics.
1546
+ }
1547
+ let dir: string = liveDir;
1548
+ const from = editedPathSegments(dir), to = editedPathSegments(next);
1549
+ if (from.filter(p => p === '..').length > to.filter(p => p === '..').length) {
1550
+ const rebased = from.slice(0, editedPathPrefix(from, to)).join('/') || '.';
1551
+ for (const sibling of receipts) {
1552
+ if (!isPlainObject(sibling) || typeof sibling.file !== 'string' || sibling.file.trim() === '' || editedPathAbsolute(sibling.file)) continue;
1553
+ sibling.file = relativeEditedFile(rebased, posix.join(dir, sibling.file));
1554
+ }
1555
+ edited.dir = rebased;
1556
+ dir = rebased;
1557
+ }
1558
+ entry.file = relativeEditedFile(dir, next);
1559
+ } });
1560
+ });
1561
+ }
1509
1562
  return out;
1510
1563
  }
1511
1564
 
@@ -5,7 +5,7 @@
5
5
  import { createHash } from 'node:crypto';
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
7
7
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
8
- import { loadConfigAndAnimations, parseConfig } from './config.ts';
8
+ import { configFileReferences, loadConfigAndAnimations, parseConfig } from './config.ts';
9
9
  import { depthReading, readSourceDepth } from './depthsheets.ts';
10
10
  import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
11
11
  import { depthImageReference, partImageReference, readParts } from './parts.ts';
@@ -13,7 +13,6 @@ import { readPartSet } from './propose.ts';
13
13
  import { decodePngBytes, encodePngBytes } from './raster/png.ts';
14
14
  import { resize } from './raster/resize.ts';
15
15
  import { connectedComponents } from './raster/components.ts';
16
- import { isSkeletonName } from './skeleton.ts';
17
16
  import { newRaster, type Raster } from './raster/types.ts';
18
17
 
19
18
  type Obj = Record<string, unknown>;
@@ -165,11 +164,9 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
165
164
  if (group.unitDepths !== undefined) target.unitDepths = group.unitDepths;
166
165
  }
167
166
  // Keep relative paths portable when relocating the output directory with its inputs.
168
- const motion = raw.motion as Obj | undefined;
169
- if (typeof motion?.animations_from === 'string') motion.animations_from = relative(resolve(input.out), resolve(dirname(input.rigConfig), motion.animations_from));
170
- const control = (raw.generation as Obj | undefined)?.control as Obj | undefined;
171
- if (typeof control?.skeleton === 'string' && !isSkeletonName(control.skeleton)) control.skeleton = relative(resolve(input.out), resolve(dirname(input.rigConfig), control.skeleton));
172
- if (typeof raw.requirements === 'string') raw.requirements = relative(resolve(input.out), resolve(dirname(input.rigConfig), raw.requirements));
167
+ for (const ref of configFileReferences(raw)) {
168
+ ref.set(relative(resolve(input.out), resolve(dirname(input.rigConfig), ref.value)));
169
+ }
173
170
  parseConfig(raw);
174
171
  const writes = new Map<string, Uint8Array>(), rows: Obj[] = [], recs = rawParts.parts as Obj[];
175
172
  // Retain auxiliary art (including alternate sets) and diagnostics byte-for-byte.
package/src/meshdraft.ts CHANGED
@@ -60,7 +60,7 @@
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, resolve } from 'node:path';
63
+ import { dirname, isAbsolute, join, relative, 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';
@@ -728,13 +728,17 @@ export function relativeConfigPaths(_configDir: string, o: Json): RelativeConfig
728
728
 
729
729
  /**
730
730
  * A config the stage builds, written as `<dir>/config.json`: `text` (the author's config at `configPath`) with
731
- * `meshes.<part>` replaced for every part in `meshes`, and each of its {@link relativeConfigPaths} made absolute, so
732
- * it resolves to the file the author's config names. `remesh` (issue #495) builds through the same door.
731
+ * `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
734
  */
734
735
  export function scratchConfig(configPath: string, text: string, dir: string, meshes: ReadonlyMap<string, unknown>): string {
735
736
  const configDir = dirname(resolve(configPath));
736
737
  const o = JSON.parse(text) as Json;
737
- for (const r of relativeConfigPaths(configDir, o)) r.set(resolve(configDir, r.value));
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
+ }
738
742
  o.meshes = { ...(o.meshes as Json), ...Object.fromEntries(meshes) };
739
743
  mkdirSync(dir, { recursive: true });
740
744
  writeFileSync(join(dir, 'config.json'), `${JSON.stringify(o, null, 2)}\n`);