rig-parts 2.56.0 → 2.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -134
- package/cli.ts +61 -10
- package/docs/AUTHORING.md +125 -16
- package/docs/STABILITY.md +169 -9
- package/package.json +2 -2
- package/src/build.ts +31 -9
- package/src/bustlandmarks.ts +118 -22
- package/src/check.ts +9 -9
- package/src/config.ts +134 -3
- package/src/configrelocation.ts +3 -0
- package/src/depthworkflow.ts +7 -1
- package/src/outputpaths.ts +107 -0
- package/src/rig.ts +57 -6
- package/src/runstamp.ts +222 -31
- package/src/turn.ts +287 -12
- package/src/turnoverlap.ts +23 -0
package/src/bustlandmarks.ts
CHANGED
|
@@ -19,6 +19,14 @@ import { type PartsFile, readParts } from './parts.ts';
|
|
|
19
19
|
* not imported; its grammar for the act is its own, and this reader refuses by
|
|
20
20
|
* name what it cannot use.
|
|
21
21
|
*
|
|
22
|
+
* Issue #1539: the comment-only act (`rig-review/act@10`, kind `comments`) is read
|
|
23
|
+
* too. Its rows sit in the one `value.carriers[]` entry of kind `chest-landmarks`,
|
|
24
|
+
* whose `chestLandmarks` rows are act@9's rows unchanged and go through the same
|
|
25
|
+
* row reader and checks. That carrier's `file` (`{path, sha256}`) must equal the
|
|
26
|
+
* envelope's `source.model`, the binding Review writes; the reader holds it to
|
|
27
|
+
* that and records it in the provenance record. Carriers of another kind (the
|
|
28
|
+
* mesh edits) are not this command's and are not read.
|
|
29
|
+
*
|
|
22
30
|
* The row's `sha256` is recomputed and a mismatch is refused: sha256 (lowercase
|
|
23
31
|
* hex) of `JSON.stringify` of the row's raw `edit` with object keys sorted
|
|
24
32
|
* recursively (`Object.keys(v).sort()`) and array order kept. That rule is a
|
|
@@ -35,8 +43,16 @@ import { type PartsFile, readParts } from './parts.ts';
|
|
|
35
43
|
* staged; a failure removes the temporaries and leaves earlier files as they were.
|
|
36
44
|
*/
|
|
37
45
|
|
|
38
|
-
/** The act schema this command reads; another act version is refused by name. */
|
|
46
|
+
/** The chest-landmarks act schema this command reads; another act version is refused by name. */
|
|
39
47
|
export const BUST_LANDMARKS_ACT_SCHEMA = 'rig-review/act@9';
|
|
48
|
+
/** Issue #1539: the comment-only act schema, read for its one `chest-landmarks` carrier. */
|
|
49
|
+
export const BUST_LANDMARKS_COMMENT_ACT_SCHEMA = 'rig-review/act@10';
|
|
50
|
+
/** The two act schemas, as every refusal of the act names them. */
|
|
51
|
+
const ACCEPTED_ACTS = `${BUST_LANDMARKS_ACT_SCHEMA} or ${BUST_LANDMARKS_COMMENT_ACT_SCHEMA}`;
|
|
52
|
+
/** The act schemas a provenance record may name. */
|
|
53
|
+
type ActSchema = typeof BUST_LANDMARKS_ACT_SCHEMA | typeof BUST_LANDMARKS_COMMENT_ACT_SCHEMA;
|
|
54
|
+
/** A model file as Review names one: a path and its sha256. */
|
|
55
|
+
export interface ModelFile { path: string; sha256: string }
|
|
40
56
|
/** The provenance record's spec. */
|
|
41
57
|
export const BUST_LANDMARKS_PROVENANCE_SPEC = 'rig-parts-bust-landmarks-provenance/1';
|
|
42
58
|
/** The provenance record is written beside `--out` under this suffix, as `depth-bind` writes `<map>.binding.json`. */
|
|
@@ -69,7 +85,9 @@ export interface BustLandmarksFile {
|
|
|
69
85
|
/** The provenance record written beside the landmarks file. Fixed key order, no clock. */
|
|
70
86
|
export interface BustLandmarksProvenance {
|
|
71
87
|
spec: typeof BUST_LANDMARKS_PROVENANCE_SPEC;
|
|
72
|
-
|
|
88
|
+
/** `carrier_file` (issue #1539) is present exactly when `schema` is the comment-only act: the chest carrier's `file`,
|
|
89
|
+
* which equals the act's `source.model`. A chest-landmarks act's record has none, so its bytes are as before. */
|
|
90
|
+
act: { schema: ActSchema; act_id: string; file_sha256: string; carrier_file?: ModelFile };
|
|
73
91
|
row_sha256: string;
|
|
74
92
|
slot: string;
|
|
75
93
|
source: { hash: string; frame: { width: number; height: number } };
|
|
@@ -83,6 +101,8 @@ export interface BustLandmarksProvenance {
|
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
interface ChestRow {
|
|
104
|
+
/** Where the act holds the rows: `value.chestLandmarks`, or `value.carriers[k].chestLandmarks` in a comment-only act. */
|
|
105
|
+
base: string;
|
|
86
106
|
index: number;
|
|
87
107
|
slot: string;
|
|
88
108
|
skin: string;
|
|
@@ -116,9 +136,9 @@ const sha256 = (bytes: Uint8Array | string): string => createHash('sha256').upda
|
|
|
116
136
|
const isPoint = (v: unknown): v is Point => Array.isArray(v) && v.length === 2 && v.every(n => typeof n === 'number' && Number.isFinite(n));
|
|
117
137
|
const isName = (v: unknown): v is string => typeof v === 'string' && v.length > 0;
|
|
118
138
|
|
|
119
|
-
/** Read one
|
|
120
|
-
function readRow(raw: unknown, index: number, problems: Problem[]): ChestRow | null {
|
|
121
|
-
const at =
|
|
139
|
+
/** Read one `<base>[i]` row; every problem it has is pushed, and null returned when any is. */
|
|
140
|
+
function readRow(raw: unknown, index: number, problems: Problem[], base: string): ChestRow | null {
|
|
141
|
+
const at = `${base}[${index}]`;
|
|
122
142
|
const before = problems.length;
|
|
123
143
|
const fail = (object: string, detail: string): void => { problems.push({ code: 'BUST_LANDMARKS_ROW', object, detail }); };
|
|
124
144
|
if (!isObject(raw)) {
|
|
@@ -178,52 +198,118 @@ function readRow(raw: unknown, index: number, problems: Problem[]): ChestRow | n
|
|
|
178
198
|
const landmarks: BustLandmarksFile = { apex_r: [...(bust.apex_r as Point)], apex_l: [...(bust.apex_l as Point)] };
|
|
179
199
|
if (Object.hasOwn(bust, 'cleavage')) landmarks.cleavage = [...(bust.cleavage as Point)];
|
|
180
200
|
return {
|
|
181
|
-
index, slot: edit.slot as string, skin: edit.skin as string, attachment: edit.attachment as string,
|
|
201
|
+
base, index, slot: edit.slot as string, skin: edit.skin as string, attachment: edit.attachment as string,
|
|
182
202
|
hash: source.hash as string, frame, landmarks, shape, sha256: digest as string,
|
|
183
203
|
};
|
|
184
204
|
}
|
|
185
205
|
|
|
206
|
+
/** A `{path, sha256}` model file, or null when the value is not one. */
|
|
207
|
+
const modelFile = (v: unknown): ModelFile | null =>
|
|
208
|
+
isObject(v) && isName(v.path) && typeof v.sha256 === 'string' && SHA256_PATTERN.test(v.sha256) ? { path: v.path, sha256: v.sha256 } : null;
|
|
209
|
+
|
|
210
|
+
/** The act as read: its schema and id, the rows, and with a comment-only act the chest carrier's `file`. */
|
|
211
|
+
interface ReadAct { schema: ActSchema; actId: string; rows: ChestRow[]; carrierFile?: ModelFile }
|
|
212
|
+
|
|
186
213
|
/** Read the act's envelope and rows: every problem pushed, the rows that read returned. */
|
|
187
|
-
function readAct(bytes: Buffer | string, path: string, problems: Problem[]):
|
|
214
|
+
function readAct(bytes: Buffer | string, path: string, problems: Problem[]): ReadAct | null {
|
|
188
215
|
if (typeof bytes === 'string') {
|
|
189
|
-
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `is not readable (${bytes}); a ${
|
|
216
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `is not readable (${bytes}); a ${ACCEPTED_ACTS} JSON file is required` });
|
|
190
217
|
return null;
|
|
191
218
|
}
|
|
192
219
|
let raw: unknown;
|
|
193
220
|
try { raw = JSON.parse(bytes.toString('utf8')); }
|
|
194
221
|
catch (error) {
|
|
195
|
-
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `does not parse as JSON (${error instanceof Error ? error.message : String(error)}); a ${
|
|
222
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `does not parse as JSON (${error instanceof Error ? error.message : String(error)}); a ${ACCEPTED_ACTS} JSON file is required` });
|
|
196
223
|
return null;
|
|
197
224
|
}
|
|
198
225
|
if (!isObject(raw)) {
|
|
199
|
-
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `is ${show(raw)}; a ${
|
|
226
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: path, detail: `is ${show(raw)}; a ${ACCEPTED_ACTS} act object is required` });
|
|
200
227
|
return null;
|
|
201
228
|
}
|
|
202
229
|
const before = problems.length;
|
|
203
|
-
|
|
230
|
+
const schema = raw.schema;
|
|
231
|
+
if (schema !== BUST_LANDMARKS_ACT_SCHEMA && schema !== BUST_LANDMARKS_COMMENT_ACT_SCHEMA) {
|
|
232
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path} schema`, detail: `is ${show(schema)}; "${BUST_LANDMARKS_ACT_SCHEMA}" (the chest-landmarks act) or "${BUST_LANDMARKS_COMMENT_ACT_SCHEMA}" (the comment-only act with a chest-landmarks carrier) is required` });
|
|
233
|
+
}
|
|
204
234
|
if (!isName(raw.actId)) problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path} actId`, detail: `is ${show(raw.actId)}; a non-empty act id is required` });
|
|
205
235
|
const value = raw.value;
|
|
206
|
-
|
|
236
|
+
let base = 'value.chestLandmarks';
|
|
237
|
+
let list: unknown = isObject(value) ? value.chestLandmarks : undefined;
|
|
238
|
+
let carrierFile: ModelFile | undefined;
|
|
239
|
+
if (schema === BUST_LANDMARKS_COMMENT_ACT_SCHEMA) {
|
|
240
|
+
const carrier = chestCarrier(raw, path, problems);
|
|
241
|
+
if (carrier === null) return null;
|
|
242
|
+
base = `value.carriers[${carrier.index}].chestLandmarks`;
|
|
243
|
+
list = carrier.rows;
|
|
244
|
+
carrierFile = carrier.file ?? undefined;
|
|
245
|
+
}
|
|
207
246
|
if (!Array.isArray(list) || list.length === 0) {
|
|
208
|
-
problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path}
|
|
247
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path} ${base}`, detail: `is ${Array.isArray(list) ? 'an empty list' : show(list)}; one chest-landmarks row is required` });
|
|
209
248
|
return null;
|
|
210
249
|
}
|
|
211
|
-
const rows = list.map((item, index) => readRow(item, index, problems)).filter((row): row is ChestRow => row !== null);
|
|
212
|
-
|
|
250
|
+
const rows = list.map((item, index) => readRow(item, index, problems, base)).filter((row): row is ChestRow => row !== null);
|
|
251
|
+
if (problems.length > before || carrierFile === undefined && schema === BUST_LANDMARKS_COMMENT_ACT_SCHEMA) return null;
|
|
252
|
+
return { schema: schema as ActSchema, actId: raw.actId as string, rows, ...(carrierFile === undefined ? {} : { carrierFile }) };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Issue #1539: the one `chest-landmarks` carrier of a comment-only act, its rows and its `file` bound to the act's
|
|
257
|
+
* `source.model`. None is `BUST_LANDMARKS_NO_CHEST_CARRIER`; a `file` that is missing, malformed or not the model
|
|
258
|
+
* the act is bound to is `BUST_LANDMARKS_CARRIER_FILE` (`file` null then, the rows still read so every problem is
|
|
259
|
+
* named at once). Other carriers (mesh edits) are not read.
|
|
260
|
+
*/
|
|
261
|
+
function chestCarrier(raw: Record<string, unknown>, path: string, problems: Problem[]): { index: number; rows: unknown; file: ModelFile | null } | null {
|
|
262
|
+
const value = raw.value;
|
|
263
|
+
const carriers = isObject(value) ? value.carriers : undefined;
|
|
264
|
+
if (carriers !== undefined && !Array.isArray(carriers)) {
|
|
265
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path} value.carriers`, detail: `is ${show(carriers)}; a list of carriers is required` });
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
const list = carriers ?? [];
|
|
269
|
+
const chest = list.flatMap((c: unknown, index) => isObject(c) && c.kind === 'chest-landmarks' ? [{ index, carrier: c }] : []);
|
|
270
|
+
if (chest.length === 0) {
|
|
271
|
+
const found = !isObject(value) ? `value is ${show(value)}` : carriers === undefined ? 'has no carriers'
|
|
272
|
+
: `has ${list.length === 0 ? 'an empty carrier list' : `carriers of kind ${list.map((c: unknown) => show(isObject(c) ? c.kind : c)).join(', ')}`} and none of kind "chest-landmarks"`;
|
|
273
|
+
problems.push({
|
|
274
|
+
code: 'BUST_LANDMARKS_NO_CHEST_CARRIER', object: `${path} value.carriers`,
|
|
275
|
+
detail: `act ${show(raw.actId)} (${BUST_LANDMARKS_COMMENT_ACT_SCHEMA}) ${found}; one value.carriers[] entry of kind "chest-landmarks", with chestLandmarks rows and a file equal to source.model, is required: the comment-only act carries the chest points only there (a mesh-edits carrier is not this command's)`,
|
|
276
|
+
});
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (chest.length > 1) {
|
|
280
|
+
problems.push({ code: 'BUST_LANDMARKS_ACT', object: `${path} value.carriers`, detail: `has ${chest.length} carriers of kind "chest-landmarks" (value.carriers[${chest.map(c => c.index).join('], [')}]); one is required, as Review writes each carrier kind at most once` });
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const { index, carrier } = chest[0];
|
|
284
|
+
const at = `${path} value.carriers[${index}].file`;
|
|
285
|
+
const file = modelFile(carrier.file);
|
|
286
|
+
const model = isObject(raw.source) ? modelFile(raw.source.model) : null;
|
|
287
|
+
const before = problems.length;
|
|
288
|
+
if (file === null) problems.push({ code: 'BUST_LANDMARKS_CARRIER_FILE', object: at, detail: `is ${show(carrier.file)}; {path, sha256}, a non-empty path and 64 lowercase hex digits, is required: the model file the points were placed on` });
|
|
289
|
+
if (model === null) {
|
|
290
|
+
const found = isObject(raw.source) ? raw.source.model : raw.source;
|
|
291
|
+
problems.push({ code: 'BUST_LANDMARKS_CARRIER_FILE', object: `${path} source.model`, detail: `is ${show(found)}; {path, sha256}, a non-empty path and 64 lowercase hex digits, is required: the chest carrier's file is bound to the model the act was made on` });
|
|
292
|
+
}
|
|
293
|
+
if (file !== null && model !== null && (file.path !== model.path || file.sha256 !== model.sha256)) {
|
|
294
|
+
const differs = [file.path === model.path ? '' : 'path', file.sha256 === model.sha256 ? '' : 'sha256'].filter(Boolean).join(' and ');
|
|
295
|
+
problems.push({ code: 'BUST_LANDMARKS_CARRIER_FILE', object: at, detail: `is ${show(file)}; source.model ${show(model)} is required (the ${differs} differ${differs.includes(' and ') ? '' : 's'}): the points were placed on another model file than the one the act is bound to` });
|
|
296
|
+
}
|
|
297
|
+
return { index, rows: carrier.chestLandmarks, file: problems.length > before ? null : file };
|
|
213
298
|
}
|
|
214
299
|
|
|
215
300
|
/** One chest row: the landmarks file names no part, and `propose` drafts one chest carrier, so one row is required. */
|
|
216
301
|
function oneRow(rows: readonly ChestRow[], problems: Problem[]): ChestRow | null {
|
|
217
302
|
if (rows.length === 1) return rows[0];
|
|
303
|
+
const base = rows[0]?.base ?? 'value.chestLandmarks';
|
|
218
304
|
const bySlot = new Map<string, number[]>();
|
|
219
305
|
for (const row of rows) bySlot.set(row.slot, [...(bySlot.get(row.slot) ?? []), row.index]);
|
|
220
306
|
for (const [slot, indices] of bySlot) {
|
|
221
307
|
if (indices.length > 1) {
|
|
222
|
-
problems.push({ code: 'BUST_LANDMARKS_PART_ROWS', object: `slot "${slot}"`, detail: `has ${indices.length} rows (
|
|
308
|
+
problems.push({ code: 'BUST_LANDMARKS_PART_ROWS', object: `slot "${slot}"`, detail: `has ${indices.length} rows (${base}[${indices.join('], [')}]); one row per part is required` });
|
|
223
309
|
}
|
|
224
310
|
}
|
|
225
311
|
if (bySlot.size > 1) {
|
|
226
|
-
problems.push({ code: 'BUST_LANDMARKS_ROWS', object:
|
|
312
|
+
problems.push({ code: 'BUST_LANDMARKS_ROWS', object: base, detail: `names ${bySlot.size} parts (${[...bySlot.keys()].map(s => `"${s}"`).join(', ')}); one chest row is required, because propose drafts one chest carrier and the landmarks file names no part` });
|
|
227
313
|
}
|
|
228
314
|
return null;
|
|
229
315
|
}
|
|
@@ -278,7 +364,7 @@ export function bustPointsMoved(act: { apex_r: readonly number[]; apex_l: readon
|
|
|
278
364
|
}
|
|
279
365
|
|
|
280
366
|
function checkRow(row: ChestRow, parts: PartsFile | null, config: CharacterConfig | null, writeConfig: boolean, problems: Problem[]): { fields: ShapeField[]; pending: PendingBustShape['fields']; moved: boolean } {
|
|
281
|
-
const at =
|
|
367
|
+
const at = `${row.base}[${row.index}]`;
|
|
282
368
|
if (parts !== null) {
|
|
283
369
|
const [width, height] = parts.rig_size;
|
|
284
370
|
if (row.frame.width !== width || row.frame.height !== height) {
|
|
@@ -458,7 +544,10 @@ export function planBustLandmarks(input: { act: string; parts: string; config: s
|
|
|
458
544
|
const text = bustLandmarksText(row.landmarks);
|
|
459
545
|
const provenance: BustLandmarksProvenance = {
|
|
460
546
|
spec: BUST_LANDMARKS_PROVENANCE_SPEC,
|
|
461
|
-
act: {
|
|
547
|
+
act: {
|
|
548
|
+
schema: act.schema, act_id: act.actId, file_sha256: sha256(actBytes),
|
|
549
|
+
...(act.carrierFile === undefined ? {} : { carrier_file: { path: act.carrierFile.path, sha256: act.carrierFile.sha256 } }),
|
|
550
|
+
},
|
|
462
551
|
row_sha256: row.sha256,
|
|
463
552
|
slot: row.slot,
|
|
464
553
|
source: { hash: row.hash, frame: { width: row.frame.width, height: row.frame.height } },
|
|
@@ -605,8 +694,12 @@ export function readBustSidecar(landmarksPath: string, landmarksBytes: Uint8Arra
|
|
|
605
694
|
if (raw.spec !== BUST_LANDMARKS_PROVENANCE_SPEC) fail(`${path} spec`, `is ${show(raw.spec)}; "${BUST_LANDMARKS_PROVENANCE_SPEC}" is required`);
|
|
606
695
|
const hex = (v: unknown): v is string => typeof v === 'string' && SHA256_PATTERN.test(v);
|
|
607
696
|
const act = raw.act;
|
|
608
|
-
|
|
609
|
-
|
|
697
|
+
// Issue #1539: a comment-only act's record carries the chest carrier's file; a chest-landmarks act's carries none.
|
|
698
|
+
const comment = isObject(act) && act.schema === BUST_LANDMARKS_COMMENT_ACT_SCHEMA;
|
|
699
|
+
const carrierFile = isObject(act) ? act.carrier_file : undefined;
|
|
700
|
+
if (!isObject(act) || (act.schema !== BUST_LANDMARKS_ACT_SCHEMA && !comment) || !isName(act.act_id) || !hex(act.file_sha256)
|
|
701
|
+
|| (comment ? modelFile(carrierFile) === null : Object.hasOwn(act, 'carrier_file'))) {
|
|
702
|
+
fail(`${path} act`, `is ${show(act)}; {schema: "${BUST_LANDMARKS_ACT_SCHEMA}", act_id, file_sha256}, or {schema: "${BUST_LANDMARKS_COMMENT_ACT_SCHEMA}", act_id, file_sha256, carrier_file: {path, sha256}}, is required`);
|
|
610
703
|
}
|
|
611
704
|
if (!hex(raw.row_sha256)) fail(`${path} row_sha256`, `is ${show(raw.row_sha256)}; 64 lowercase hex digits are required`);
|
|
612
705
|
if (!isName(raw.slot)) fail(`${path} slot`, `is ${show(raw.slot)}; the chest carrier's part name is required`);
|
|
@@ -643,7 +736,10 @@ export function readBustSidecar(landmarksPath: string, landmarksBytes: Uint8Arra
|
|
|
643
736
|
const a = act as Record<string, unknown>, src = source as Record<string, unknown>, f = frame as Record<string, unknown>;
|
|
644
737
|
const provenance: BustLandmarksProvenance = {
|
|
645
738
|
spec: BUST_LANDMARKS_PROVENANCE_SPEC,
|
|
646
|
-
act: {
|
|
739
|
+
act: {
|
|
740
|
+
schema: a.schema as ActSchema, act_id: a.act_id as string, file_sha256: a.file_sha256 as string,
|
|
741
|
+
...(comment ? { carrier_file: modelFile(carrierFile) as ModelFile } : {}),
|
|
742
|
+
},
|
|
647
743
|
row_sha256: raw.row_sha256 as string,
|
|
648
744
|
slot: raw.slot as string,
|
|
649
745
|
source: { hash: src.hash as string, frame: { width: f.width as number, height: f.height as number } },
|
package/src/check.ts
CHANGED
|
@@ -99,7 +99,7 @@ import { createRequire } from 'node:module';
|
|
|
99
99
|
import type { Candidate, Piece, Viewport as RootCoverageViewport } from '@rig-c/core/render-shared';
|
|
100
100
|
import { fillHoles } from './raster/morph.ts';
|
|
101
101
|
import { closeSync, copyFileSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
102
|
-
import { diagnosticSegment, diagnosticSiblings, unsafeSegmentReason } from './outputpaths.ts';
|
|
102
|
+
import { argvPathFromOut, diagnosticSegment, diagnosticSiblings, unsafeSegmentReason } from './outputpaths.ts';
|
|
103
103
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
104
104
|
import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig, figureSilhouette } from './assemble.ts';
|
|
105
105
|
import { type BoneTransform, computeExactFrameTransforms, cropToSpineY, normaliseDegrees, toBoneLocal } from './coords.ts';
|
|
@@ -6828,7 +6828,7 @@ function renderExtremes(build: string, out: string, animations: readonly string[
|
|
|
6828
6828
|
* MEASURABLE is a problem. Without it nothing here reads, writes or prints
|
|
6829
6829
|
* anything it did not before.
|
|
6830
6830
|
*/
|
|
6831
|
-
export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false, environment?: string,
|
|
6831
|
+
export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false, environment?: string, _requirementsAs: string | undefined = requirements, config?: InputFileRecord, windBand?: string, noExtremes = false, supportSource?: string, supportFigure?: Mask, assemblyRules?: AssemblyRules): CheckReport {
|
|
6832
6832
|
const pageSize = parsePageSize(mode.pageSize);
|
|
6833
6833
|
let inp: CheckInputs;
|
|
6834
6834
|
let reqFile: RequirementsFile | null = null;
|
|
@@ -6868,7 +6868,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
6868
6868
|
if (got !== null && wb !== null) take(() => resolveWindBand(wb, got));
|
|
6869
6869
|
refuseIfAny(refused);
|
|
6870
6870
|
}
|
|
6871
|
-
reqRecord = requirementsFileRecord(requirements,
|
|
6871
|
+
reqRecord = requirementsFileRecord(requirements, argvPathFromOut(requirements, outDir, process.cwd()));
|
|
6872
6872
|
inp = got as CheckInputs;
|
|
6873
6873
|
const file = reqFile as RequirementsFile;
|
|
6874
6874
|
const ready = inp;
|
|
@@ -7006,7 +7006,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7006
7006
|
let windBandRead: WindBandLine | null = null;
|
|
7007
7007
|
if (wb !== null) {
|
|
7008
7008
|
try {
|
|
7009
|
-
windBandRead = measureWindBand(wb, buildDir, windBandDir, animationNames, rigc);
|
|
7009
|
+
windBandRead = { ...measureWindBand(wb, buildDir, windBandDir, animationNames, rigc), path: argvPathFromOut(wb.path, outDir, process.cwd()) };
|
|
7010
7010
|
} catch (err) {
|
|
7011
7011
|
rmSync(windBandDir, { recursive: true, force: true });
|
|
7012
7012
|
for (const p of [join(out, 'gate_spine-html.txt'), buildReportPath]) rmSync(p, { force: true });
|
|
@@ -7755,11 +7755,12 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7755
7755
|
const skipped: { loop?: string; seam?: string } = {};
|
|
7756
7756
|
if (inp.noIdle !== null) skipped.loop = inp.noIdle;
|
|
7757
7757
|
if (inp.noParts !== null) skipped.seam = inp.noParts;
|
|
7758
|
+
const recordedEnv: CheckEnvironment | null = env === null ? null : { ...env, path: argvPathFromOut(env.path, outDir, process.cwd()) };
|
|
7758
7759
|
const readings: Omit<CheckFigures, 'spec' | 'bar_outcomes' | 'build' | 'PASS'> = {
|
|
7759
7760
|
gate_spine_html_green: htmlGreen,
|
|
7760
7761
|
rigc_entry: rigcEntry,
|
|
7761
7762
|
pack_mode: { page_edges: mode.pageEdges, pack_shape: mode.packShape, ...(pageSize === undefined ? {} : { page_size: pageSize }) },
|
|
7762
|
-
...(
|
|
7763
|
+
...(recordedEnv === null ? {} : { environment: recordedEnv }),
|
|
7763
7764
|
loop_max_diff: loop === null ? null : loop.max,
|
|
7764
7765
|
...(loopPhysics === null ? {} : { loop_physics: loopPhysics.map(row => ({ ...row, ...checkRow('loop_physics', 'rig', false, []) })) }),
|
|
7765
7766
|
seam_mean: seam === null ? null : round3(seam.mean),
|
|
@@ -7921,10 +7922,9 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7921
7922
|
export const REQUIREMENTS_DIR = 'requirements';
|
|
7922
7923
|
|
|
7923
7924
|
/**
|
|
7924
|
-
* Issue #556: the requirements file a check read, first in `check.json`'s
|
|
7925
|
-
* `requirements` block —
|
|
7926
|
-
*
|
|
7927
|
-
* bytes do not move with the directory the build ran in), the sha256 of the
|
|
7925
|
+
* Issue #556, #1554: the requirements file a check read, first in `check.json`'s
|
|
7926
|
+
* `requirements` block — `path` relative to `check`'s `--out` directory by
|
|
7927
|
+
* {@link argvPathFromOut} (`<out>/check` under `build`), the sha256 of the
|
|
7928
7928
|
* bytes read, and the file's top-level keys in its order, so a reader sees
|
|
7929
7929
|
* what the file asked (a `not_swinging`, a `may_fold`) without opening it.
|
|
7930
7930
|
*/
|
package/src/config.ts
CHANGED
|
@@ -633,8 +633,8 @@ export function contourRegionsOf(spec: ContourSpec): ContourRegionSpec[] {
|
|
|
633
633
|
* are decided exactly on that grid.
|
|
634
634
|
*/
|
|
635
635
|
export type ContourRegionSpec =
|
|
636
|
-
| { name: string; shape: 'circle'; cx: number; cy: number; r: number; spacing: number; band: number; bone: string }
|
|
637
|
-
| { name: string; shape: 'polygon'; points: Point[]; spacing: number; band: number; bone: string };
|
|
636
|
+
| { name: string; shape: 'circle'; cx: number; cy: number; r: number; spacing: number; band: number; bone: string; cover?: string }
|
|
637
|
+
| { name: string; shape: 'polygon'; points: Point[]; spacing: number; band: number; bone: string; cover?: string };
|
|
638
638
|
|
|
639
639
|
/**
|
|
640
640
|
* One mesh in the automatic mode (issue #126, item 2): the contour mesh over
|
|
@@ -2169,6 +2169,7 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
2169
2169
|
}
|
|
2170
2170
|
const meshParts = isPlainObject(t.meshes) ? new Set(Object.keys(t.meshes).filter((k) => !isRecordKey(k))) : new Set<string>();
|
|
2171
2171
|
if ('turn' in t) checkTurn(c, t.turn, attached, names.bones, hasAltFace, parts, declaredSliders, meshParts, t.meshes, names.chains, names.parents);
|
|
2172
|
+
checkContourBandCovers(c, t.meshes, t.turn, attached, names.bones, names.chains, names.parents);
|
|
2172
2173
|
if ('scene' in t) checkScene(c, t.scene);
|
|
2173
2174
|
if ('cloth' in t) checkCloth(c, t.cloth);
|
|
2174
2175
|
if ('requirements' in t && c.string('config.requirements', t.requirements) && base !== null) checkRequirementsFile(c, configFilePath('requirements', base, t.requirements) as string);
|
|
@@ -3874,7 +3875,7 @@ function checkContour(c: Check, at: string, v: Json, bones: Set<string>): void {
|
|
|
3874
3875
|
const rat = `${at}.regions[${i}]`;
|
|
3875
3876
|
const shape = typeof rv === 'object' && rv !== null && !Array.isArray(rv) ? (rv as Record<string, Json>).shape : undefined;
|
|
3876
3877
|
const own = shape === 'circle' ? ['cx', 'cy', 'r'] : shape === 'polygon' ? ['points'] : [];
|
|
3877
|
-
const r = c.object(rat, rv, ['name', 'shape', 'bone', 'spacing', 'band', ...own], []);
|
|
3878
|
+
const r = c.object(rat, rv, ['name', 'shape', 'bone', 'spacing', 'band', ...own], ['cover']);
|
|
3878
3879
|
if (r === null) return;
|
|
3879
3880
|
if ('shape' in r && own.length === 0) c.fail('CONFIG_FIELD_TYPE', `${rat}.shape`, `is ${show(r.shape)}; "circle" (with cx, cy, r) or "polygon" (with points) is required`);
|
|
3880
3881
|
if ('name' in r && c.string(`${rat}.name`, r.name)) {
|
|
@@ -3884,6 +3885,9 @@ function checkContour(c: Check, at: string, v: Json, bones: Set<string>): void {
|
|
|
3884
3885
|
if ('bone' in r && (typeof r.bone !== 'string' || !bones.has(r.bone))) {
|
|
3885
3886
|
c.fail('CONFIG_NAME_RESOLVES', `${rat}.bone`, `is ${show(r.bone)}; a bone config.bones declares is required — the region's control bone`);
|
|
3886
3887
|
}
|
|
3888
|
+
if ('cover' in r && (typeof r.cover !== 'string' || r.cover.length === 0)) {
|
|
3889
|
+
c.fail('CONFIG_FIELD_TYPE', `${rat}.cover`, `is ${show(r.cover)}; a non-empty part name is required`);
|
|
3890
|
+
}
|
|
3887
3891
|
if ('spacing' in r) c.number(`${rat}.spacing`, r.spacing, 'positive');
|
|
3888
3892
|
if ('band' in r) onGrid(`${rat}.band`, r.band, 'non-negative');
|
|
3889
3893
|
if (shape === 'circle') {
|
|
@@ -5786,6 +5790,133 @@ function checkTurn(
|
|
|
5786
5790
|
}
|
|
5787
5791
|
}
|
|
5788
5792
|
|
|
5793
|
+
/**
|
|
5794
|
+
* Issue #1548: `meshes.<part>.contour.regions[i].cover` names the `"surface"` part in the
|
|
5795
|
+
* other 2.5D turn group whose extended depth sheet supplies the region's other-group depth.
|
|
5796
|
+
* Refuses (`CONFIG_TURN_BAND_COVER`) when `part` is not a 2.5D turn surface, when the region's
|
|
5797
|
+
* bone is not in the other turn group (where `cover` would read nothing), when `cover` is not
|
|
5798
|
+
* an attached part, when `cover` lacks role `"surface"` in that other group, or when two regions
|
|
5799
|
+
* on one mesh share a bone with disagreeing `cover` declarations.
|
|
5800
|
+
*/
|
|
5801
|
+
function checkContourBandCovers(
|
|
5802
|
+
c: Check,
|
|
5803
|
+
rawMeshes: Json,
|
|
5804
|
+
rawTurn: Json,
|
|
5805
|
+
attached: ReadonlySet<string>,
|
|
5806
|
+
bones: ReadonlySet<string>,
|
|
5807
|
+
chains: ReadonlyMap<string, number>,
|
|
5808
|
+
parents: ReadonlyMap<string, string>,
|
|
5809
|
+
): void {
|
|
5810
|
+
if (!isPlainObject(rawMeshes)) return;
|
|
5811
|
+
const turnObj = isPlainObject(rawTurn) ? rawTurn : null;
|
|
5812
|
+
const headRoles = turnObj !== null && isPlainObject(turnObj.roles) ? turnObj.roles : null;
|
|
5813
|
+
const bodyObj = turnObj !== null && isPlainObject(turnObj.body) ? turnObj.body : null;
|
|
5814
|
+
const bodyRoles = bodyObj !== null && isPlainObject(bodyObj.roles) ? bodyObj.roles : null;
|
|
5815
|
+
const bodyRoot =
|
|
5816
|
+
bodyObj !== null && typeof bodyObj.bone === 'string' && bones.has(bodyObj.bone)
|
|
5817
|
+
? bodyObj.bone
|
|
5818
|
+
: bones.has('chest')
|
|
5819
|
+
? 'chest'
|
|
5820
|
+
: 'hip';
|
|
5821
|
+
const descends = (bone: string, root: string): boolean => {
|
|
5822
|
+
if (!bones.has(bone) || !bones.has(root)) return false;
|
|
5823
|
+
const seen = new Set<string>();
|
|
5824
|
+
for (let cur: string | undefined = bone; cur !== undefined && !seen.has(cur); cur = parents.get(cur)) {
|
|
5825
|
+
if (cur === root) return true;
|
|
5826
|
+
seen.add(cur);
|
|
5827
|
+
}
|
|
5828
|
+
return false;
|
|
5829
|
+
};
|
|
5830
|
+
const groupOf = (bone: string): 'head' | 'body' | null =>
|
|
5831
|
+
descends(bone, 'head') ? 'head' : !descends(bodyRoot, 'head') && descends(bone, bodyRoot) ? 'body' : null;
|
|
5832
|
+
|
|
5833
|
+
for (const [part, spec] of Object.entries(rawMeshes)) {
|
|
5834
|
+
if (isRecordKey(part) || !isPlainObject(spec) || !isPlainObject(spec.contour) || !Array.isArray(spec.contour.regions)) continue;
|
|
5835
|
+
const headSurface = headRoles?.[part] === 'surface';
|
|
5836
|
+
const bodySurface = bodyRoles?.[part] === 'surface';
|
|
5837
|
+
const segGroups = new Set<'head' | 'body'>();
|
|
5838
|
+
if (Array.isArray(spec.segments)) {
|
|
5839
|
+
for (const s of spec.segments) {
|
|
5840
|
+
if (typeof s === 'string') {
|
|
5841
|
+
const count = chains.get(s);
|
|
5842
|
+
const list = count !== undefined ? Array.from({ length: count }, (_, k) => `${s}${k}`) : [s];
|
|
5843
|
+
for (const b of list) {
|
|
5844
|
+
const g = groupOf(b);
|
|
5845
|
+
if (g !== null) segGroups.add(g);
|
|
5846
|
+
}
|
|
5847
|
+
} else if (Array.isArray(s) && typeof s[0] === 'string') {
|
|
5848
|
+
const g = groupOf(s[0]);
|
|
5849
|
+
if (g !== null) segGroups.add(g);
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5852
|
+
}
|
|
5853
|
+
const coverByBone = new Map<string, string | null>();
|
|
5854
|
+
spec.contour.regions.forEach((rv, i) => {
|
|
5855
|
+
if (!isPlainObject(rv)) return;
|
|
5856
|
+
const bone = typeof rv.bone === 'string' ? rv.bone : null;
|
|
5857
|
+
const hasCover = 'cover' in rv;
|
|
5858
|
+
if (bone !== null && bones.has(bone)) {
|
|
5859
|
+
const curCover = hasCover && typeof rv.cover === 'string' && rv.cover.length > 0 ? rv.cover : null;
|
|
5860
|
+
const prev = coverByBone.get(bone);
|
|
5861
|
+
if (prev !== undefined && prev !== curCover) {
|
|
5862
|
+
c.fail(
|
|
5863
|
+
'CONFIG_TURN_BAND_COVER',
|
|
5864
|
+
`config.meshes.${part}.contour.regions[${i}].cover`,
|
|
5865
|
+
`disagrees with an earlier contour region on bone "${bone}" (${prev === null ? 'absent' : `"${prev}"`} vs ${curCover === null ? 'absent' : `"${curCover}"`}); regions sharing a control bone on one mesh must agree on cover`,
|
|
5866
|
+
);
|
|
5867
|
+
} else if (prev === undefined) {
|
|
5868
|
+
coverByBone.set(bone, curCover);
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
if (!hasCover || typeof rv.cover !== 'string' || rv.cover.length === 0) return;
|
|
5872
|
+
const cover = rv.cover;
|
|
5873
|
+
const at = `config.meshes.${part}.contour.regions[${i}].cover`;
|
|
5874
|
+
const regName = typeof rv.name === 'string' ? rv.name : String(i);
|
|
5875
|
+
if (!headSurface && !bodySurface) {
|
|
5876
|
+
c.fail(
|
|
5877
|
+
'CONFIG_TURN_BAND_COVER',
|
|
5878
|
+
at,
|
|
5879
|
+
`is "${cover}" on region "${regName}" of "${part}", which has no 2.5D turn "surface" role; cover reads a depth sheet only on a turn "surface" part`,
|
|
5880
|
+
);
|
|
5881
|
+
return;
|
|
5882
|
+
}
|
|
5883
|
+
if (bone === null || !bones.has(bone)) return;
|
|
5884
|
+
const regGroup = groupOf(bone);
|
|
5885
|
+
const inOtherGroup =
|
|
5886
|
+
headSurface && !bodySurface
|
|
5887
|
+
? regGroup === 'body'
|
|
5888
|
+
: bodySurface && !headSurface
|
|
5889
|
+
? regGroup === 'head'
|
|
5890
|
+
: regGroup !== null && segGroups.size === 1 && !segGroups.has(regGroup);
|
|
5891
|
+
if (!inOtherGroup || regGroup === null) {
|
|
5892
|
+
c.fail(
|
|
5893
|
+
'CONFIG_TURN_BAND_COVER',
|
|
5894
|
+
at,
|
|
5895
|
+
`is "${cover}" on region "${regName}" (bone "${bone}"), which is ${regGroup === null ? 'outside both 2.5D turn subtrees' : `in "${part}"'s own ${regGroup} turn group`}, so cover would read nothing; bind the region to a bone in the other turn group or remove cover`,
|
|
5896
|
+
);
|
|
5897
|
+
return;
|
|
5898
|
+
}
|
|
5899
|
+
const otherRoles = regGroup === 'head' ? headRoles : bodyRoles;
|
|
5900
|
+
const otherPath = regGroup === 'head' ? 'config.turn.roles' : 'config.turn.body.roles';
|
|
5901
|
+
if (!attached.has(cover)) {
|
|
5902
|
+
c.fail(
|
|
5903
|
+
'CONFIG_TURN_BAND_COVER',
|
|
5904
|
+
at,
|
|
5905
|
+
`names "${cover}", which config.meshes and config.regions do not attach; a declared part with role "surface" in ${otherPath} is required`,
|
|
5906
|
+
);
|
|
5907
|
+
return;
|
|
5908
|
+
}
|
|
5909
|
+
if (otherRoles?.[cover] !== 'surface') {
|
|
5910
|
+
c.fail(
|
|
5911
|
+
'CONFIG_TURN_BAND_COVER',
|
|
5912
|
+
at,
|
|
5913
|
+
`names "${cover}", which has role ${otherRoles === null || !(cover in otherRoles) ? 'none' : show(otherRoles[cover])} in ${otherPath}; role "surface" in the ${regGroup} turn group is required`,
|
|
5914
|
+
);
|
|
5915
|
+
}
|
|
5916
|
+
});
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5919
|
+
|
|
5789
5920
|
/** #773: all scalar units and user polarity are authored, never inferred. */
|
|
5790
5921
|
function checkDepthConfig(c: Check, raw: Json): void {
|
|
5791
5922
|
const d = c.object('config.depth', raw, [], ['zScale', 'full', 'head']);
|
package/src/configrelocation.ts
CHANGED
|
@@ -34,6 +34,9 @@ function relocateAssemblyFiles(raw: unknown, relocate: (value: string) => string
|
|
|
34
34
|
fields(take, ['run_dir', 'st_input']);
|
|
35
35
|
fields(take.reference, ['painting']);
|
|
36
36
|
}
|
|
37
|
+
if (object(raw.assemble.editor_receipts)) {
|
|
38
|
+
for (const receipt of entries(raw.assemble.editor_receipts.receipts)) fields(receipt, ['file']);
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
if (object(raw.limbs)) {
|
|
39
42
|
for (const limb of Object.values(raw.limbs).filter(object)) {
|
package/src/depthworkflow.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { PartsError, type Problem } from './errors.ts';
|
|
|
10
10
|
import { loadConfigAndAnimations, parseConfig } from './config.ts';
|
|
11
11
|
import { relocateConfigReferences } from './configrelocation.ts';
|
|
12
12
|
import { depthReading, readSourceDepth } from './depthsheets.ts';
|
|
13
|
+
import { readEditorReceipts } from './editreceipt.ts';
|
|
13
14
|
import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
|
|
14
15
|
import { depthImageReference, partImageReference, readParts } from './parts.ts';
|
|
15
16
|
import { readPartSet } from './propose.ts';
|
|
@@ -243,6 +244,8 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
|
|
|
243
244
|
const rawParts = object(readJson(join(input.parts, 'parts.json')), 'parts.json'), file = readParts(join(input.parts, 'parts.json'));
|
|
244
245
|
for (const p of file.parts) if (Object.hasOwn(recipe.parts, p.name) && applied(recipe.parts[p.name].group) && p.provenance?.depth?.kind === 'authored-unit') fail('DEPTH_AUTHORED_UNIT_CONFLICT', `part "${p.name}"`, 'has provenance.depth.kind "authored-unit"; a transported scalar reference cannot coexist with authored unit depth — retain the unit declaration or supply an explicitly reassembled scalar-compatible input; no automatic transition is made');
|
|
245
246
|
const { config } = loadConfigAndAnimations(input.rigConfig);
|
|
247
|
+
const receiptProblems = readEditorReceipts(config.assemble.editor_receipts, input.rigConfig).problems;
|
|
248
|
+
if (receiptProblems.length) throw new PartsError(receiptProblems);
|
|
246
249
|
refuseStaleAssembly(input.rigConfig, file, config);
|
|
247
250
|
const raw = object(readJson(input.rigConfig), 'rig config'), turn = object(raw.turn, 'config.turn');
|
|
248
251
|
// A group left out must not turn: the rig builds a group's turn from its config block, not from its sheets.
|
|
@@ -263,7 +266,10 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
|
|
|
263
266
|
}
|
|
264
267
|
// Keep relative paths portable when relocating the output directory with its inputs.
|
|
265
268
|
relocateConfigReferences(raw, dirname(input.rigConfig), input.out, 'relative');
|
|
266
|
-
|
|
269
|
+
const relocatedConfig = parseConfig(raw), outConfig = join(input.out, 'config.json');
|
|
270
|
+
const relocatedReceiptProblems = readEditorReceipts(relocatedConfig.assemble.editor_receipts, outConfig).problems;
|
|
271
|
+
if (relocatedReceiptProblems.length) throw new PartsError(relocatedReceiptProblems);
|
|
272
|
+
refuseStaleAssembly(outConfig, file, relocatedConfig);
|
|
267
273
|
const warnings: string[] = [];
|
|
268
274
|
const writes = new Map<string, Uint8Array>(), rows: Obj[] = [], recs = rawParts.parts as Obj[];
|
|
269
275
|
// Retain auxiliary art (including alternate sets) and diagnostics byte-for-byte.
|
package/src/outputpaths.ts
CHANGED
|
@@ -1,5 +1,112 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, realpathSync } from 'node:fs';
|
|
2
|
+
import nodePath, { resolve } from 'node:path';
|
|
1
3
|
import { PartsError } from './errors.ts';
|
|
2
4
|
|
|
5
|
+
/** `node:path`, or its `win32`/`posix` twin a control passes in. */
|
|
6
|
+
export type PlatformPath = typeof nodePath.posix;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A directory through its links when it or an ancestor exists: the deepest existing prefix is resolved by
|
|
10
|
+
* `realpathSync` and any not-yet-created trailing segments are appended, so rebasing before `mkdirSync` agrees with
|
|
11
|
+
* rebasing after it. As given when only the filesystem root exists (nothing on disk to resolve).
|
|
12
|
+
*/
|
|
13
|
+
export function realWhereItExists(path: string): string {
|
|
14
|
+
if (nodePath.sep === '\\' && path.startsWith('/')) return path;
|
|
15
|
+
if (nodePath.dirname(path) === path) return path;
|
|
16
|
+
if (existsSync(path)) return realpathSync(path);
|
|
17
|
+
const missing: string[] = [];
|
|
18
|
+
let cur = path;
|
|
19
|
+
for (;;) {
|
|
20
|
+
const parent = nodePath.dirname(cur);
|
|
21
|
+
if (parent === cur) return path;
|
|
22
|
+
missing.push(nodePath.basename(cur));
|
|
23
|
+
cur = parent;
|
|
24
|
+
if (nodePath.dirname(cur) === cur) return path;
|
|
25
|
+
if (existsSync(cur)) {
|
|
26
|
+
let resolved = realpathSync(cur);
|
|
27
|
+
for (let i = missing.length - 1; i >= 0; i--) resolved = nodePath.join(resolved, missing[i]);
|
|
28
|
+
return resolved;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A path as spelled: no link resolved. */
|
|
34
|
+
function asSpelled(path: string): string {
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The link rule a path is rebased to `--out` by, chosen by `api`'s platform: the rule its `..` follows when a replay
|
|
40
|
+
* runs from the `--out` directory. On POSIX `..` is the physical parent, and the working directory is reported by its
|
|
41
|
+
* real path, so both ends are resolved through their links ({@link realWhereItExists}). On Windows `..` is textual:
|
|
42
|
+
* measured (issue #1551, Bun 1.4.4 on Windows build 26100), a process started in a directory spelled through a
|
|
43
|
+
* junction reports that spelling as `process.cwd()` and resolves `..` against it, while `realpathSync` and
|
|
44
|
+
* `realpathSync.native` both resolve the junction; resolving the ends there climbed one level too many from the
|
|
45
|
+
* `--out` the run was given. So on Windows a path is rebased as spelled, from `--out` as the run was given it.
|
|
46
|
+
*/
|
|
47
|
+
export function linkRuleFor(api: PlatformPath): (path: string) => string {
|
|
48
|
+
return api.sep === '\\' ? asSpelled : realWhereItExists;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `path` relative to `outDir` in `api`'s separators, with `outDir` and `path`'s directory resolved through their
|
|
53
|
+
* links by `real` and `path`'s own last segment kept: the rule {@link recordedConfigPath}, {@link argvPathFromOut}
|
|
54
|
+
* and {@link recordedInputPath} share, rig-c core's `relativeToOut` (core issue #1770).
|
|
55
|
+
*/
|
|
56
|
+
export function relativeKeepingName(outDir: string, path: string, real: (path: string) => string, api: PlatformPath): string {
|
|
57
|
+
const absolute = api.resolve(path);
|
|
58
|
+
return api.relative(real(api.resolve(outDir)), api.join(real(api.dirname(absolute)), api.basename(absolute)));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `config.path` in a `rig-run/2` record: relative to the real `--out` directory, the config's directory resolved through
|
|
63
|
+
* its links and the file's own name kept, `/`-separated. A config given through a link is recorded by the link's name,
|
|
64
|
+
* as rig-c core's render-run.json records an input (core issue #1770), so a replay reads what the link names then.
|
|
65
|
+
* `rig-run/1`'s `config.path` still resolves the file itself and is unchanged.
|
|
66
|
+
* The links are resolved by {@link linkRuleFor}'s rule, so on Windows the path is relative to `--out` as spelled.
|
|
67
|
+
* `real` and `api` are the resolution and path rules used, for the control.
|
|
68
|
+
*/
|
|
69
|
+
export function recordedConfigPath(outDir: string, configPath: string, real?: (path: string) => string, api: PlatformPath = nodePath): string {
|
|
70
|
+
return relativeKeepingName(outDir, configPath, real ?? linkRuleFor(api), api).split(api.sep).join('/');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* One path argument written relative to the `--out` directory, with `/` separators: both taken from `cwd`, the
|
|
75
|
+
* `--out` directory and the argument's directory resolved through their links, the argument's own last segment kept
|
|
76
|
+
* (a linked file keeps its own name), as {@link recordedConfigPath} records `config.path`. `.` when it is the directory
|
|
77
|
+
* itself. Written as given when it cannot be expressed relative to `--out` (another Windows drive).
|
|
78
|
+
*
|
|
79
|
+
* Measured (issue #1544): with `--out` given through a linked directory (`/var` -> `/private/var` on macOS) and the
|
|
80
|
+
* argument relative to a working directory the process reports by its real path, plain path arithmetic climbed out
|
|
81
|
+
* through the link and named a path that, replayed from the `--out` directory, did not exist. `real` is the link
|
|
82
|
+
* resolution used, {@link linkRuleFor} the platform's by default (on Windows, as spelled: issue #1551); the control
|
|
83
|
+
* passes the other platform's rule to plant the wrong arithmetic.
|
|
84
|
+
*/
|
|
85
|
+
export function argvPathFromOut(given: string, out: string, cwd: string, api: PlatformPath = nodePath, real: (path: string) => string = linkRuleFor(api)): string {
|
|
86
|
+
const rel = relativeKeepingName(api.resolve(cwd, out), api.resolve(cwd, given), real, api);
|
|
87
|
+
if (api.isAbsolute(rel)) return given;
|
|
88
|
+
return rel === '' ? '.' : rel.split(api.sep).join('/');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* One `assemble` input (`source`, `full`, `head`) recorded relative to `--out` by {@link argvPathFromOut} (issue
|
|
93
|
+
* #1554): when `isDirectory` is true (a See-through directory run), records the hashed manifest `<given>/layers.json`
|
|
94
|
+
* rather than the directory itself so the recorded `path` names the exact file `sha256` digests.
|
|
95
|
+
*/
|
|
96
|
+
export function recordedInputPath(given: string, out: string, cwd: string, isDirectory = false, api: PlatformPath = nodePath, real: (path: string) => string = linkRuleFor(api)): string {
|
|
97
|
+
return argvPathFromOut(isDirectory ? api.join(given, 'layers.json') : given, out, cwd, api, real);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Make an output directory and its parents, from its resolved path. Bun on Windows refuses
|
|
102
|
+
* `mkdirSync('.', { recursive: true })` with EEXIST when `.` exists (windows-latest, Bun 1.4.5, issue #1541), so an
|
|
103
|
+
* `--out .` given from the directory it names reached that refusal; the resolved path is made on every platform.
|
|
104
|
+
* `mkdir` is the call made, for the control that plants the unresolved one.
|
|
105
|
+
*/
|
|
106
|
+
export function makeOutDir(dir: string, mkdir: (path: string, options: { recursive: true }) => unknown = mkdirSync): void {
|
|
107
|
+
mkdir(resolve(dir), { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
|
|
3
110
|
/**
|
|
4
111
|
* Filesystem spelling for a diagnostic name. See STABILITY's "Diagnostic path
|
|
5
112
|
* segments" for the single public definition. Encode code units, not UTF-8:
|