rig-parts 2.68.0 → 2.69.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 +1 -0
- package/cli.ts +58 -4
- package/docs/AUTHORING.md +97 -3
- package/docs/STABILITY.md +81 -17
- package/package.json +2 -1
- package/src/build.ts +2 -0
- package/src/check.ts +96 -11
- package/src/editedparts.ts +57 -21
- package/src/parts.ts +27 -21
- package/src/partscheck.ts +13 -23
- package/src/partsfiles.ts +62 -0
- package/src/replacementrecord.ts +172 -0
- package/src/replaceparts.ts +564 -0
- package/src/rig.ts +1 -1
- package/src/runstamp.ts +24 -3
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
/** Post-assemble edits of a recorded parts set, with byte-bound lineage. */
|
|
2
|
+
import { lstatSync, mkdirSync, mkdtempSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { measureRecomposite, recomposite, recompositeRecord, type PlacedPart } from './assemble.ts';
|
|
5
|
+
import { CUT_MATERIAL_SOURCES } from './cutmaterial.ts';
|
|
6
|
+
import { readMaterialSources, writeMaterialSources } from './cutmaterialio.ts';
|
|
7
|
+
import { alphaSupport } from './depthmaps.ts';
|
|
8
|
+
import { depthReading, depthSheetProblems, extendDepthSilhouette, readSourceDepth } from './depthsheets.ts';
|
|
9
|
+
import { decodeEditedPart, editedPartReceiptProblem, editedPixelChanged, editedPixelCounts, removedOpaqueRegions, type EditedPartReceipt } from './editedparts.ts';
|
|
10
|
+
import { foldName, PartsError, refuseIfAny, type Problem } from './errors.ts';
|
|
11
|
+
import { CORE_ALPHA, OPAQUE_ALPHA_ABOVE } from './layers.ts';
|
|
12
|
+
import { declaredPartsFiles, depthImageReference, partImageReference, readParts, sourceStateMapReference, VISIBILITY_KEYS, type PartRecord, type PartsFile } from './parts.ts';
|
|
13
|
+
import { checkPartsStage } from './partscheck.ts';
|
|
14
|
+
import { partsSha256, readRegularFile, withinPartsPath, type PartsInventoryRow } from './partsfiles.ts';
|
|
15
|
+
import { receiptObject } from './receiptproducer.ts';
|
|
16
|
+
import { captureReplacementTree, digestReplacementInventory, readBoundReplacementFile, readReplacementRecord, replacementRecordPath,
|
|
17
|
+
REPLACEMENT_HISTORICAL_FIELDS, REPLACEMENT_RECORD_PATH, REPLACEMENT_RECORD_SPEC, type ReplacementRecord, type ReplacementRow } from './replacementrecord.ts';
|
|
18
|
+
import { opaqueCount } from './rig.ts';
|
|
19
|
+
import { decodePngBytes, encodePngBytes } from './raster/png.ts';
|
|
20
|
+
import { newRaster, type Raster } from './raster/types.ts';
|
|
21
|
+
import { SOURCE_COVER_FILE } from './sourcecover.ts';
|
|
22
|
+
import { encodeSourceStateMap, readSourceStateMap, SOURCE_STATE, sourceStateCounts } from './sourcestates.ts';
|
|
23
|
+
|
|
24
|
+
type Inventory = ReadonlyMap<string, PartsInventoryRow>;
|
|
25
|
+
type Box = [number, number, number, number];
|
|
26
|
+
interface Edit { box: unknown; receipt: EditedPartReceipt; bytes: Uint8Array; image: Raster }
|
|
27
|
+
type PendingEdit = Pick<Edit, 'box' | 'receipt'> & Partial<Pick<Edit, 'bytes' | 'image'>>;
|
|
28
|
+
interface PreparedEdit extends Edit {
|
|
29
|
+
part: PartRecord;
|
|
30
|
+
old: Raster;
|
|
31
|
+
changed: Uint8Array;
|
|
32
|
+
sourceStates?: Uint8Array;
|
|
33
|
+
row: ReplacementRow;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fail(code: string, object: string, detail: string): never {
|
|
37
|
+
throw new PartsError([{ code, object, detail }]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function lstatIfPresent(path: string): ReturnType<typeof lstatSync> | undefined {
|
|
41
|
+
try { return lstatSync(path); }
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Pin an existing path to its real parent and refuse a linked leaf. */
|
|
49
|
+
function inputPath(path: string, directory: boolean): string {
|
|
50
|
+
const full = resolve(path);
|
|
51
|
+
const object = directory ? '--parts' : '--edits';
|
|
52
|
+
const stat = lstatIfPresent(full);
|
|
53
|
+
if (stat === undefined || !(directory ? stat.isDirectory() : stat.isFile())) {
|
|
54
|
+
fail('REPLACE_PART_INPUT', object, `requires a readable regular ${directory ? 'directory' : 'file'}`);
|
|
55
|
+
}
|
|
56
|
+
return realpathSync(full);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function prospectivePath(path: string): string {
|
|
60
|
+
const stat = lstatIfPresent(path);
|
|
61
|
+
if (stat !== undefined) {
|
|
62
|
+
if (!stat.isDirectory()) fail('REPLACE_PART_OUTPUT', '--out', 'requires regular directory ancestors');
|
|
63
|
+
return realpathSync(path);
|
|
64
|
+
}
|
|
65
|
+
return join(prospectivePath(dirname(path)), basename(path));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function scopedEditPath(root: string, path: string, file: boolean): string {
|
|
69
|
+
if (isAbsolute(path) || /[\\\0]/.test(path) || /^[A-Za-z]:/.test(path)) throw new Error('requires a scoped relative path');
|
|
70
|
+
let current = root;
|
|
71
|
+
for (const segment of path.split('/')) {
|
|
72
|
+
if (segment === '.' || segment === '') continue;
|
|
73
|
+
if (segment === '..') throw new Error('requires a path inside the edits directory');
|
|
74
|
+
current = join(current, segment);
|
|
75
|
+
const stat = lstatIfPresent(current);
|
|
76
|
+
if (stat === undefined || stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) throw new Error('requires a regular path without symlinks');
|
|
77
|
+
}
|
|
78
|
+
const stat = lstatIfPresent(current);
|
|
79
|
+
if (stat === undefined || !(file ? stat.isFile() : stat.isDirectory())) throw new Error(`requires a regular ${file ? 'file' : 'directory'}`);
|
|
80
|
+
return current;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function loadEdits(path: string): { grid: unknown; edits: PendingEdit[]; problems: Problem[] } {
|
|
84
|
+
let raw: unknown;
|
|
85
|
+
try { raw = JSON.parse(readRegularFile(path).toString('utf8')); }
|
|
86
|
+
catch { return fail('REPLACE_PART_RECEIPT', '--edits', 'requires a readable JSON edits file'); }
|
|
87
|
+
if (!receiptObject(raw) || Object.keys(raw).sort().join(',') !== 'dir,edits,rig_size' || typeof raw.dir !== 'string' ||
|
|
88
|
+
raw.dir.trim() === '' || !Array.isArray(raw.edits) || raw.edits.length === 0) {
|
|
89
|
+
return fail('REPLACE_PART_RECEIPT', '--edits', 'requires rig_size, a relative dir, and a nonempty edits array');
|
|
90
|
+
}
|
|
91
|
+
let home: string;
|
|
92
|
+
try { home = scopedEditPath(dirname(path), raw.dir, false); }
|
|
93
|
+
catch { return fail('REPLACE_PART_RECEIPT', '--edits dir', 'requires a regular directory inside the edits file directory, without symlinks'); }
|
|
94
|
+
const edits: PendingEdit[] = [], problems: Problem[] = [], seen = new Set<string>();
|
|
95
|
+
for (const [index, row] of raw.edits.entries()) {
|
|
96
|
+
const receipt = receiptObject(row) ? row.receipt : undefined;
|
|
97
|
+
const label = receiptObject(receipt) && typeof receipt.part === 'string' ? receipt.part : `edits[${index}]`;
|
|
98
|
+
const reject = (detail: string): void => { problems.push(receiptProblem(label, detail)); };
|
|
99
|
+
const invalid = editedPartReceiptProblem(receipt);
|
|
100
|
+
if (!receiptObject(row) || Object.keys(row).some(key => key !== 'box' && key !== 'receipt') || invalid !== undefined) {
|
|
101
|
+
reject(invalid ?? 'unexpected edit row field');
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const valid = receipt as EditedPartReceipt;
|
|
105
|
+
if (seen.has(valid.part)) { reject('duplicate receipt'); continue; }
|
|
106
|
+
seen.add(valid.part);
|
|
107
|
+
const pending: PendingEdit = { box: row.box, receipt: valid };
|
|
108
|
+
edits.push(pending);
|
|
109
|
+
if (valid.sha256 === valid.from_sha256) { reject('replacement and source sha256 are identical'); continue; }
|
|
110
|
+
let bytes: Uint8Array;
|
|
111
|
+
try { bytes = readRegularFile(scopedEditPath(home, valid.file, true)); }
|
|
112
|
+
catch { reject(`file ${JSON.stringify(valid.file)} is unreadable or outside dir`); continue; }
|
|
113
|
+
const decoded = decodeEditedPart(bytes, valid);
|
|
114
|
+
if ('kind' in decoded) { reject(decoded.detail); continue; }
|
|
115
|
+
pending.image = decoded.image;
|
|
116
|
+
pending.bytes = bytes;
|
|
117
|
+
}
|
|
118
|
+
return { grid: raw.rig_size, edits, problems };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function receiptProblem(part: string, detail: string): Problem {
|
|
122
|
+
return { code: 'REPLACE_PART_RECEIPT', object: `part "${part}"`,
|
|
123
|
+
detail: `found ${detail} — required one valid receipt binding the part and both PNG SHA-256 values` };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function prepareEdits(file: PartsFile, inventory: Inventory, edits: ReturnType<typeof loadEdits>, images: ReadonlyMap<string, Raster>): Map<string, PreparedEdit> {
|
|
127
|
+
const prepared = new Map<string, PreparedEdit>();
|
|
128
|
+
for (const edit of edits.edits) {
|
|
129
|
+
const part = file.parts.find(p => p.name === edit.receipt.part);
|
|
130
|
+
if (part === undefined) {
|
|
131
|
+
edits.problems.push({ code: 'REPLACE_PART_UNKNOWN', object: `part "${edit.receipt.part}"`,
|
|
132
|
+
detail: 'found no source entry — required a named source part' });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const path = partImageReference(part).path;
|
|
136
|
+
const actual = inventory.get(path)?.sha256;
|
|
137
|
+
if (actual !== edit.receipt.from_sha256) edits.problems.push(receiptProblem(part.name, `source PNG sha256 ${actual ?? 'missing'}, receipt from_sha256 ${edit.receipt.from_sha256}`));
|
|
138
|
+
const old = images.get(part.name)!;
|
|
139
|
+
const { image, bytes } = edit, box: Box = [part.x, part.y, part.w, part.h];
|
|
140
|
+
const same = (a: unknown, b: number[]): boolean => Array.isArray(a) && a.length === b.length && b.every((n, i) => a[i] === n);
|
|
141
|
+
if ((image !== undefined && (image.width !== old.width || image.height !== old.height)) ||
|
|
142
|
+
!same(edit.box, box) || !same(edits.grid, file.rig_size)) {
|
|
143
|
+
edits.problems.push({ code: 'REPLACE_PART_GRID', object: `part "${part.name}"`,
|
|
144
|
+
detail: `found PNG ${image === undefined ? 'unavailable' : `${image.width}x${image.height}`}, box ${JSON.stringify(edit.box) ?? 'absent'}, rig ${JSON.stringify(edits.grid)} — required PNG ${part.w}x${part.h}, box ${JSON.stringify(box)}, rig ${JSON.stringify(file.rig_size)}` });
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (image === undefined || bytes === undefined) continue;
|
|
148
|
+
const counts = editedPixelCounts(), removed = new Uint8Array(part.w * part.h), changed = new Uint8Array(removed.length);
|
|
149
|
+
for (let p = 0; p < changed.length; p++) if (editedPixelChanged(old, image, p, counts, removed)) changed[p] = 1;
|
|
150
|
+
if (counts.removed_opaque_px > 0) counts.removed_opaque_regions = removedOpaqueRegions(removed, part.w, part.h);
|
|
151
|
+
prepared.set(part.name, { ...edit, part, image, bytes, old, changed, row: { part: part.name, receipt: edit.receipt, ...counts } });
|
|
152
|
+
}
|
|
153
|
+
refuseIfAny(edits.problems);
|
|
154
|
+
return prepared;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function neighbourProblem(part: string, neighbour: string, dependency: string, state: 'changed' | 'unverifiable', location: string): Problem {
|
|
158
|
+
return { code: 'REPLACE_PART_NEIGHBOUR', object: `part "${part}", neighbour "${neighbour}"`,
|
|
159
|
+
detail: `found ${dependency} ${state} at ${location} — required unchanged retained derivation` };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function firstChanged(edit: PreparedEdit, box?: Box): string | undefined {
|
|
163
|
+
for (let p = 0; p < edit.changed.length; p++) {
|
|
164
|
+
if (!edit.changed[p] || Math.max(edit.old.data[p * 4 + 3], edit.image.data[p * 4 + 3]) === 0) continue;
|
|
165
|
+
const x = edit.part.x + p % edit.part.w, y = edit.part.y + Math.floor(p / edit.part.w);
|
|
166
|
+
if (box === undefined || (x >= box[0] && y >= box[1] && x < box[0] + box[2] && y < box[1] + box[3])) return `(${x}, ${y})`;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function overlapChange(back: PartRecord, backImage: Raster, front: PreparedEdit): { at: string; state: 'changed' | 'unverifiable' } | undefined {
|
|
172
|
+
const oldEvidence = back.source_overlaps?.find(row => row.front === front.part.name);
|
|
173
|
+
const x0 = Math.max(back.x, front.part.x), y0 = Math.max(back.y, front.part.y);
|
|
174
|
+
const x1 = Math.min(back.x + back.w, front.part.x + front.part.w), y1 = Math.min(back.y + back.h, front.part.y + front.part.h);
|
|
175
|
+
for (let y = y0; y < y1; y++) for (let x = x0; x < x1; x++) {
|
|
176
|
+
const b = (y - back.y) * back.w + x - back.x, f = (y - front.part.y) * front.part.w + x - front.part.x;
|
|
177
|
+
if (backImage.data[b * 4 + 3] <= OPAQUE_ALPHA_ABOVE || !front.changed[f]) continue;
|
|
178
|
+
const before = front.old.data[f * 4 + 3] > OPAQUE_ALPHA_ABOVE;
|
|
179
|
+
const after = front.image.data[f * 4 + 3] > OPAQUE_ALPHA_ABOVE;
|
|
180
|
+
if (before !== after) return { at: `(${x}, ${y})`, state: 'changed' };
|
|
181
|
+
if (before && (front.sourceStates?.[f] !== SOURCE_STATE.unrecorded || oldEvidence === undefined || oldEvidence.native_samples !== undefined)) {
|
|
182
|
+
return { at: `(${x}, ${y})`, state: 'unverifiable' };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function guardNeighbours(file: PartsFile, images: ReadonlyMap<string, Raster>, edits: ReadonlyMap<string, PreparedEdit>): void {
|
|
189
|
+
const problems: Problem[] = [];
|
|
190
|
+
for (const [i, part] of file.parts.entries()) {
|
|
191
|
+
const edit = edits.get(part.name);
|
|
192
|
+
if (edit === undefined || edit.row.changed_px === 0) continue;
|
|
193
|
+
// A retained back row owns the overlap census, including its declared empty list.
|
|
194
|
+
for (const back of file.parts.slice(0, i)) {
|
|
195
|
+
if (back.source_overlaps === undefined || edits.get(back.name)?.row.changed_px) continue;
|
|
196
|
+
const impact = overlapChange(back, images.get(back.name)!, edit);
|
|
197
|
+
if (impact !== undefined) problems.push(neighbourProblem(part.name, back.name, 'source overlap', impact.state, impact.at));
|
|
198
|
+
}
|
|
199
|
+
const at = firstChanged(edit);
|
|
200
|
+
if (at === undefined) continue;
|
|
201
|
+
const lineage = (p: PartRecord): string => p.cut_from ?? p.limb?.of ?? p.name;
|
|
202
|
+
for (const other of file.parts) {
|
|
203
|
+
if (other.name === part.name || edits.get(other.name)?.row.changed_px) continue;
|
|
204
|
+
const cut = (lineage(part) === lineage(other) && (part.cut_from !== undefined || other.cut_from !== undefined)) ||
|
|
205
|
+
file.cut_ownership?.some(row => (row.from === lineage(part) && row.into === other.name) ||
|
|
206
|
+
(row.from === lineage(other) && row.into === part.name));
|
|
207
|
+
if (cut) problems.push(neighbourProblem(part.name, other.name, 'cut ownership', 'unverifiable', at));
|
|
208
|
+
if (other.fringe_pushed_back?.some(r => r.part === part.name)) {
|
|
209
|
+
// The aggregate names a holder at an originally cleared fringe texel.
|
|
210
|
+
// Newly supported texels could not have held that original fringe.
|
|
211
|
+
const lostSupport = edit.changed.some((changed, p) => changed !== 0 &&
|
|
212
|
+
edit.old.data[p * 4 + 3] >= CORE_ALPHA && edit.image.data[p * 4 + 3] < CORE_ALPHA);
|
|
213
|
+
if (lostSupport) problems.push(neighbourProblem(part.name, other.name, 'fringe holder', 'unverifiable', at));
|
|
214
|
+
}
|
|
215
|
+
if (part.limb === undefined || other.limb === undefined || part.limb.of !== other.limb.of) continue;
|
|
216
|
+
const capAt = [part.limb.cap, other.limb.cap].flatMap(cap => cap === undefined ? [] : [firstChanged(edit, cap.box)]).find(where => where !== undefined);
|
|
217
|
+
if (capAt !== undefined || part.limb.hybrid !== undefined || part.limb.band !== undefined ||
|
|
218
|
+
other.limb.hybrid !== undefined || other.limb.band !== undefined) {
|
|
219
|
+
problems.push(neighbourProblem(part.name, other.name, 'limb cap or band', 'unverifiable', capAt ?? at));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const alt of file.alternates ?? []) {
|
|
223
|
+
if (alt.parts !== undefined && !alt.hides?.includes(part.name) && !alt.records.some(p => p.name === part.name)) {
|
|
224
|
+
problems.push(neighbourProblem(part.name, alt.name, 'alternate recomposite with inherited base art', 'unverifiable', at));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
refuseIfAny(problems);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function readArt(root: string, inventory: Inventory, part: PartRecord, set?: string): Raster {
|
|
232
|
+
const path = partImageReference(part, set).path;
|
|
233
|
+
let image: Raster;
|
|
234
|
+
try { image = decodePngBytes(readBoundReplacementFile(root, inventory, path), path); }
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (error instanceof PartsError) throw error;
|
|
237
|
+
return fail('REPLACE_PART_INPUT', path, 'requires a decodable source PNG');
|
|
238
|
+
}
|
|
239
|
+
const opaque = opaqueCount(image);
|
|
240
|
+
if (image.width !== part.w || image.height !== part.h || opaque !== part.opaque_px) {
|
|
241
|
+
fail('REPLACE_PART_INPUT', path, `PNG ${image.width}x${image.height} with ${opaque} opaque pixels does not match parts.json's ${part.w}x${part.h} box and ${part.opaque_px} opaque pixels`);
|
|
242
|
+
}
|
|
243
|
+
return image;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function sourceStates(part: PartRecord, target: PartRecord, edit: PreparedEdit, writes: Map<string, Uint8Array>): void {
|
|
247
|
+
if (part.source_state_map === undefined || edit.sourceStates === undefined) {
|
|
248
|
+
delete target.source_visibility;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const codes = edit.sourceStates.slice();
|
|
252
|
+
let changedSourceMembership = false;
|
|
253
|
+
for (let p = 0; p < codes.length; p++) if (edit.changed[p]) {
|
|
254
|
+
if (codes[p] !== SOURCE_STATE.none) changedSourceMembership = true;
|
|
255
|
+
codes[p] = edit.image.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE ? SOURCE_STATE.unrecorded : SOURCE_STATE.none;
|
|
256
|
+
}
|
|
257
|
+
const { bytes, sha256 } = encodeSourceStateMap(codes, part.w, part.h);
|
|
258
|
+
target.source_visibility = {
|
|
259
|
+
source_layers: changedSourceMembership ? [] : part.source_visibility!.source_layers,
|
|
260
|
+
...sourceStateCounts(codes),
|
|
261
|
+
};
|
|
262
|
+
target.source_state_map = { ...part.source_state_map, sha256 };
|
|
263
|
+
if (sha256 !== part.source_state_map.sha256) writes.set(sourceStateMapReference(part.source_state_map).path, bytes);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function numericDepthBinding(report: unknown, edit: PreparedEdit, sha: string): boolean {
|
|
267
|
+
return receiptObject(report) && report.spec === 'rig-parts-depth-report/1' && report.alpha === 128 &&
|
|
268
|
+
Array.isArray(report.parts) && report.parts.some(row => receiptObject(row) && row.part === edit.part.name && row.sheetSha256 === sha &&
|
|
269
|
+
edit.part.depth?.sources.some(source => source.sha256 === row.mapSha256));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function rederiveDepth(root: string, inventory: Inventory, edit: PreparedEdit, target: PartRecord, writes: Map<string, Uint8Array>, report: unknown, prior?: ReplacementRecord): void {
|
|
273
|
+
const ref = edit.part.depth;
|
|
274
|
+
if (ref === undefined) return;
|
|
275
|
+
const path = depthImageReference(ref).path;
|
|
276
|
+
const source = readSourceDepth(join(root, path), edit.old, null);
|
|
277
|
+
if (source.sha256 !== inventory.get(path)?.sha256) fail('REPLACE_PART_INPUT', path, 'depth sheet changed after reading the source inventory');
|
|
278
|
+
const previous = prior?.replaced.find(row => row.part === edit.part.name)?.depth;
|
|
279
|
+
const registered = previous?.sha256 === source.sha256 && previous.support !== undefined ? previous.support === 'alpha-at-least-128' :
|
|
280
|
+
numericDepthBinding(report, edit, source.sha256) || ref.sources.every(s => s.image.toLowerCase().endsWith('.json'));
|
|
281
|
+
const support = registered ? 'alpha-at-least-128' : 'alpha-nonzero';
|
|
282
|
+
const mask = (image: Raster): Uint8Array => registered ? alphaSupport(image) :
|
|
283
|
+
Uint8Array.from({ length: edit.changed.length }, (_, p) => Number(image.data[p * 4 + 3] > 0));
|
|
284
|
+
const oldSupport = mask(edit.old), newSupport = mask(edit.image);
|
|
285
|
+
let sheet = source.pixels, hash = source.sha256;
|
|
286
|
+
const reseeded = oldSupport.some((value, p) => value !== newSupport[p]);
|
|
287
|
+
if (reseeded) {
|
|
288
|
+
const seeds = newRaster(edit.part.w, edit.part.h);
|
|
289
|
+
let surviving = 0;
|
|
290
|
+
for (let p = 0; p < oldSupport.length; p++) if (oldSupport[p] && newSupport[p]) {
|
|
291
|
+
seeds.data[p * 4 + 3] = 255;
|
|
292
|
+
surviving++;
|
|
293
|
+
}
|
|
294
|
+
if (surviving === 0) fail('REPLACE_PART_DEPTH_SUPPORT', `part "${edit.part.name}"`,
|
|
295
|
+
'found zero surviving depth seeds — required shared old and new depth support');
|
|
296
|
+
sheet = extendDepthSilhouette(source.pixels, seeds);
|
|
297
|
+
refuseIfAny(depthSheetProblems(sheet, [edit.part.w, edit.part.h], path));
|
|
298
|
+
if (sheet.data.some((pixel, i) => pixel !== source.pixels.data[i])) {
|
|
299
|
+
const bytes = encodePngBytes(sheet);
|
|
300
|
+
hash = partsSha256(bytes);
|
|
301
|
+
writes.set(path, bytes);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Transported source readings describe the original input sheet. A registered
|
|
305
|
+
// map's one reading is of the emitted sheet and must follow the changed art.
|
|
306
|
+
const reading = depthReading(sheet, edit.image, registered ? ref.sources[0].reading.orderingMedian : null);
|
|
307
|
+
if (registered) target.depth = { ...ref, sources: ref.sources.map((s, i) => i === 0 ? { ...s, reading } : s) };
|
|
308
|
+
edit.row.depth = { from_sha256: source.sha256, sha256: hash, reseeded, support, reading };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function deriveManifest(root: string, inventory: Inventory, file: PartsFile, images: ReadonlyMap<string, Raster>, edits: ReadonlyMap<string, PreparedEdit>, writes: Map<string, Uint8Array>, prior?: ReplacementRecord): PartsFile {
|
|
312
|
+
const optionalReport = 'depth-report.json';
|
|
313
|
+
let depthReport: unknown;
|
|
314
|
+
if (inventory.has(optionalReport) && [...edits.values()].some(edit => edit.part.depth !== undefined)) {
|
|
315
|
+
const bytes = readBoundReplacementFile(root, inventory, optionalReport);
|
|
316
|
+
try { depthReport = JSON.parse(bytes.toString('utf8')); }
|
|
317
|
+
catch { /* An unrecognized report supplies no producer binding. */ }
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const parts = file.parts.map(part => {
|
|
321
|
+
const edit = edits.get(part.name);
|
|
322
|
+
if (edit === undefined) return part;
|
|
323
|
+
const target = { ...part };
|
|
324
|
+
writes.set(partImageReference(part).path, edit.bytes);
|
|
325
|
+
if (edit.row.changed_px > 0) {
|
|
326
|
+
target.assembly_opaque_px ??= part.opaque_px;
|
|
327
|
+
target.opaque_px = opaqueCount(edit.image);
|
|
328
|
+
const historical = Object.fromEntries(REPLACEMENT_HISTORICAL_FIELDS.flatMap(key => part[key] === undefined ? [] : [[key, part[key]]]));
|
|
329
|
+
if (Object.keys(historical).length > 0) edit.row.historical = historical;
|
|
330
|
+
for (const key of VISIBILITY_KEYS) delete target[key];
|
|
331
|
+
delete target.painting_extension_px;
|
|
332
|
+
// depth-apply still consumes authored-unit declarations here. The original
|
|
333
|
+
// value census remains scoped by assembly_opaque_px in this case.
|
|
334
|
+
if (target.provenance?.depth === undefined) delete target.provenance;
|
|
335
|
+
delete target.taken_layers;
|
|
336
|
+
delete target.fringe_pushed_back;
|
|
337
|
+
delete target.source_overlaps;
|
|
338
|
+
sourceStates(part, target, edit, writes);
|
|
339
|
+
}
|
|
340
|
+
rederiveDepth(root, inventory, edit, target, writes, depthReport, prior);
|
|
341
|
+
return target;
|
|
342
|
+
});
|
|
343
|
+
const result: PartsFile = { ...file, parts };
|
|
344
|
+
if (file.recomposite !== undefined && [...edits.values()].some(edit => firstChanged(edit) !== undefined)) {
|
|
345
|
+
if (file.painting_in_rig === undefined) {
|
|
346
|
+
if (file.scene !== undefined) fail('REPLACE_PART_INPUT', 'scene recomposite', 'requires a bound painting_in_rig to preserve the declared figure comparison');
|
|
347
|
+
delete result.recomposite;
|
|
348
|
+
} else {
|
|
349
|
+
const [w, h] = file.rig_size, path = file.painting_in_rig.path;
|
|
350
|
+
const painting = decodePngBytes(readBoundReplacementFile(root, inventory, path), path);
|
|
351
|
+
const inside = file.scene === undefined ? null : readFigure(root, inventory, file.scene.figure_mask, file.scene.figure_px, w, h);
|
|
352
|
+
const placed: PlacedPart[] = parts.map(record => ({ record, image: edits.get(record.name)?.image ?? images.get(record.name)! }));
|
|
353
|
+
result.recomposite = recompositeRecord(measureRecomposite(recomposite(placed, w, h), painting, placed, inside));
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function readFigure(root: string, inventory: Inventory, path: string, expected: number, w: number, h: number): Uint8Array {
|
|
360
|
+
const raster = decodePngBytes(readBoundReplacementFile(root, inventory, path), path);
|
|
361
|
+
if (raster.width !== w || raster.height !== h) fail('REPLACE_PART_INPUT', path, `requires a scene mask on the recorded ${w}x${h} rig grid`);
|
|
362
|
+
const mask = new Uint8Array(w * h);
|
|
363
|
+
let white = 0;
|
|
364
|
+
for (let p = 0; p < mask.length; p++) {
|
|
365
|
+
const [r, g, b, a] = raster.data.subarray(p * 4, p * 4 + 4);
|
|
366
|
+
if ((r !== 0 && r !== 255) || g !== r || b !== r || a !== 255) fail('REPLACE_PART_INPUT', path, 'requires the recorded opaque binary scene mask');
|
|
367
|
+
if (r === 255) { mask[p] = 1; white++; }
|
|
368
|
+
}
|
|
369
|
+
if (white !== expected) fail('REPLACE_PART_INPUT', path, `found ${white} figure pixels — required the recorded ${expected}`);
|
|
370
|
+
return mask;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function outputPlan(file: PartsFile, result: PartsFile, inventory: Inventory, writes: ReadonlyMap<string, Uint8Array>, previous?: ReplacementRecord): Set<string> {
|
|
374
|
+
// Include only files with a verified role in the current parts set. Source
|
|
375
|
+
// cover is a projection-input measurement, independent of final part pixels.
|
|
376
|
+
const declared = declaredPartsFiles(result).map(reference => reference.path);
|
|
377
|
+
const keep = new Set(declared);
|
|
378
|
+
for (const path of declared) if (!inventory.has(path)) fail('REPLACE_PART_INPUT', path, 'declared asset is absent from the source inventory');
|
|
379
|
+
if (inventory.has(SOURCE_COVER_FILE)) keep.add(SOURCE_COVER_FILE);
|
|
380
|
+
if (file.replacement_record !== undefined) keep.add(file.replacement_record);
|
|
381
|
+
for (const path of previous?.copied ?? []) if (REPLACEMENT_RECORD_PATH.test(path)) keep.add(path);
|
|
382
|
+
for (const path of writes.keys()) keep.add(path);
|
|
383
|
+
return keep;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function refuseChangedAliases(file: PartsFile, writes: ReadonlyMap<string, Uint8Array>): void {
|
|
387
|
+
const owners = new Map<string, string[]>();
|
|
388
|
+
const append = (path: string, who: string): void => {
|
|
389
|
+
const key = foldName(path);
|
|
390
|
+
const seen = owners.get(key) ?? [];
|
|
391
|
+
seen.push(who);
|
|
392
|
+
owners.set(key, seen);
|
|
393
|
+
};
|
|
394
|
+
const visit = (p: PartRecord, set?: string): void => {
|
|
395
|
+
const label = set === undefined ? p.name : `${set}/${p.name}`;
|
|
396
|
+
append(partImageReference(p, set).path, label);
|
|
397
|
+
if (p.depth !== undefined) append(depthImageReference(p.depth).path, label + ' depth');
|
|
398
|
+
if (p.source_state_map !== undefined) append(sourceStateMapReference(p.source_state_map).path, label + ' source state map');
|
|
399
|
+
};
|
|
400
|
+
for (const p of file.parts) visit(p);
|
|
401
|
+
for (const alt of file.alternates ?? []) for (const p of alt.records) visit(p, alt.name);
|
|
402
|
+
const problems: Problem[] = [];
|
|
403
|
+
for (const path of writes.keys()) {
|
|
404
|
+
const refs = owners.get(foldName(path)) ?? [];
|
|
405
|
+
if (refs.length > 1) problems.push(neighbourProblem(refs[0], refs[1], 'shared asset binding', 'unverifiable', path));
|
|
406
|
+
}
|
|
407
|
+
refuseIfAny(problems);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function verifyRecord(root: string, parts: PartsFile, inventory: Inventory): ReplacementRecord | undefined {
|
|
411
|
+
const pointer = parts.replacement_record;
|
|
412
|
+
if (pointer === undefined) return undefined;
|
|
413
|
+
if (!REPLACEMENT_RECORD_PATH.test(pointer) || !inventory.has(pointer)) {
|
|
414
|
+
fail('REPLACE_PART_RECORD', 'parts.json replacement_record', 'requires a path to an existing replacement record inside the set');
|
|
415
|
+
}
|
|
416
|
+
const manifest = readBoundReplacementFile(root, inventory, 'parts.json');
|
|
417
|
+
if (JSON.stringify(JSON.parse(manifest.toString('utf8'))) !== JSON.stringify(parts)) {
|
|
418
|
+
fail('REPLACE_PART_RECORD', 'parts.json', 'manifest changed after it was read');
|
|
419
|
+
}
|
|
420
|
+
const record = readReplacementRecord(readBoundReplacementFile(root, inventory, pointer));
|
|
421
|
+
const problems: Problem[] = [];
|
|
422
|
+
const reject = (object: string, detail: string): void => { problems.push({ code: 'REPLACE_PART_RECORD', object, detail }); };
|
|
423
|
+
if (pointer !== replacementRecordPath(record.source_sha256)) reject(pointer, 'filename must equal the recorded source sha256');
|
|
424
|
+
if (record.rig_size.some((n, i) => n !== parts.rig_size[i])) reject(pointer, 'record grid must match the manifest grid');
|
|
425
|
+
const actual = digestReplacementInventory(inventory, pointer);
|
|
426
|
+
if (actual !== record.result_sha256) reject(pointer, `result sha256 is ${actual}; record requires ${record.result_sha256}`);
|
|
427
|
+
const retained = [...record.copied, ...record.rederived].sort();
|
|
428
|
+
const output = [...inventory.keys()].filter(path => path !== pointer).sort();
|
|
429
|
+
if (retained.length !== output.length || retained.some((path, i) => output[i] !== path) || !record.rederived.includes('parts.json')) {
|
|
430
|
+
reject(pointer, 'copied and rederived must classify every emitted file except this record, including rederived parts.json');
|
|
431
|
+
}
|
|
432
|
+
if (record.omitted.some(path => inventory.has(path))) reject(pointer, 'omitted paths must be absent from the emitted set');
|
|
433
|
+
for (const row of record.replaced) {
|
|
434
|
+
const part = parts.parts.find(p => p.name === row.part);
|
|
435
|
+
if (part === undefined) { reject(row.part, 'receipt names no part in parts.json'); continue; }
|
|
436
|
+
const path = partImageReference(part).path;
|
|
437
|
+
if (!record.rederived.includes(path) || inventory.get(path)?.sha256 !== row.receipt.sha256) {
|
|
438
|
+
reject(path, 'replacement PNG must be rederived and match its receipt sha256');
|
|
439
|
+
} else {
|
|
440
|
+
const art = readArt(root, inventory, part);
|
|
441
|
+
if (part.source_state_map !== undefined) readSourceStateMap(join(root, 'parts'), part, art);
|
|
442
|
+
}
|
|
443
|
+
if (row.changed_counted_px > part.opaque_px || row.changed_excluded_px > part.w * part.h - part.opaque_px ||
|
|
444
|
+
(row.changed_px > 0 && part.assembly_opaque_px === undefined) ||
|
|
445
|
+
row.removed_opaque_regions?.some(({ box: [x, y, w, h] }) => x + w > part.w || y + h > part.h)) {
|
|
446
|
+
reject(path, 'replacement change counts, region boxes or assembly scope disagree with the manifest');
|
|
447
|
+
}
|
|
448
|
+
if (part.depth === undefined ? row.depth !== undefined : row.depth === undefined ||
|
|
449
|
+
inventory.get(depthImageReference(part.depth).path)?.sha256 !== row.depth.sha256) {
|
|
450
|
+
reject(path, 'scalar depth presence and bytes must match the replacement record');
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
refuseIfAny(problems);
|
|
454
|
+
return record;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** The directory is the parts root holding parts.json, as in --parts. */
|
|
458
|
+
export function verifyReplacementRecord(partsDir: string, parts: PartsFile): void {
|
|
459
|
+
const home = resolve(partsDir);
|
|
460
|
+
if (parts.replacement_record === undefined) {
|
|
461
|
+
if (lstatIfPresent(join(home, '.parts-replacements')) !== undefined) {
|
|
462
|
+
fail('REPLACE_PART_RECORD', 'parts.json replacement_record', 'the set has a replacement lineage directory without an active record pointer');
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
verifyRecord(home, parts, captureReplacementTree(home));
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function stageFile(home: string, path: string, bytes: Uint8Array): void {
|
|
470
|
+
const destination = join(home, path);
|
|
471
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
472
|
+
writeFileSync(destination, bytes, { flag: 'wx' });
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export function replaceParts(input: { parts: string; sourceSha256?: string; edits: string; out: string }): ReplacementRecord {
|
|
476
|
+
const source = inputPath(input.parts, true), editsPath = inputPath(input.edits, false);
|
|
477
|
+
const out = prospectivePath(resolve(input.out));
|
|
478
|
+
if (lstatIfPresent(out) !== undefined || withinPartsPath(source, out) || withinPartsPath(out, source) || withinPartsPath(out, editsPath)) {
|
|
479
|
+
fail('REPLACE_PART_OUTPUT', '--out', 'requires an absent directory disjoint from the source parts and edits');
|
|
480
|
+
}
|
|
481
|
+
const inventory = captureReplacementTree(source), sourceHash = digestReplacementInventory(inventory);
|
|
482
|
+
if (input.sourceSha256 !== undefined && input.sourceSha256 !== sourceHash) {
|
|
483
|
+
fail('REPLACE_PART_SOURCE_HASH', 'recorded set', `found sha256 ${sourceHash} — required sha256 ${input.sourceSha256}`);
|
|
484
|
+
}
|
|
485
|
+
const file = readParts(join(source, 'parts.json'));
|
|
486
|
+
if (JSON.stringify(file) !== JSON.stringify(JSON.parse(readBoundReplacementFile(source, inventory, 'parts.json').toString('utf8')))) {
|
|
487
|
+
fail('REPLACE_PART_INPUT', 'parts.json', 'manifest changed while reading the source inventory');
|
|
488
|
+
}
|
|
489
|
+
const previous = verifyRecord(source, file, inventory);
|
|
490
|
+
if (previous === undefined && [...inventory.keys()].some(path => REPLACEMENT_RECORD_PATH.test(path))) {
|
|
491
|
+
fail('REPLACE_PART_RECORD', 'parts.json replacement_record', 'the source has replacement lineage files without an active record pointer');
|
|
492
|
+
}
|
|
493
|
+
const pointer = replacementRecordPath(sourceHash);
|
|
494
|
+
if (inventory.has(pointer)) fail('REPLACE_PART_OUTPUT', pointer, 'a new record path must be absent from the source tree');
|
|
495
|
+
|
|
496
|
+
const requested = loadEdits(editsPath);
|
|
497
|
+
const images = new Map(file.parts.map(part => [part.name, readArt(source, inventory, part)]));
|
|
498
|
+
const edits = prepareEdits(file, inventory, requested, images);
|
|
499
|
+
for (const edit of edits.values()) {
|
|
500
|
+
if (edit.part.source_state_map !== undefined) edit.sourceStates = readSourceStateMap(join(source, 'parts'), edit.part, edit.old);
|
|
501
|
+
}
|
|
502
|
+
guardNeighbours(file, images, edits);
|
|
503
|
+
const writes = new Map<string, Uint8Array>();
|
|
504
|
+
const result = deriveManifest(source, inventory, file, images, edits, writes, previous);
|
|
505
|
+
refuseChangedAliases(file, writes);
|
|
506
|
+
result.replacement_record = pointer;
|
|
507
|
+
writes.set('parts.json', Buffer.from(JSON.stringify(result, null, 2) + '\n'));
|
|
508
|
+
|
|
509
|
+
const keep = outputPlan(file, result, inventory, writes, previous);
|
|
510
|
+
const material = inventory.has(CUT_MATERIAL_SOURCES) ? readMaterialSources(source, file) : null;
|
|
511
|
+
// Copy policy is closed. In particular derived config, old reports and
|
|
512
|
+
// diagnostic images never occupy live reader names in the output.
|
|
513
|
+
const newPaths = new Set(writes.keys());
|
|
514
|
+
if (material !== null) {
|
|
515
|
+
keep.add(CUT_MATERIAL_SOURCES);
|
|
516
|
+
newPaths.add(CUT_MATERIAL_SOURCES);
|
|
517
|
+
}
|
|
518
|
+
const copied = [...keep].filter(path => !newPaths.has(path)).sort();
|
|
519
|
+
const rederived = [...newPaths].sort();
|
|
520
|
+
const omitted = [...inventory.keys()].filter(path => !keep.has(path)).sort();
|
|
521
|
+
|
|
522
|
+
const parent = dirname(out);
|
|
523
|
+
mkdirSync(parent, { recursive: true });
|
|
524
|
+
if (realpathSync(parent) !== parent) fail('REPLACE_PART_OUTPUT', '--out', 'destination parent changed or became a symlink');
|
|
525
|
+
const scratch = mkdtempSync(join(parent, '.replace-parts-'));
|
|
526
|
+
try {
|
|
527
|
+
const stage = join(scratch, 'parts-set'), stagedFiles = new Map<string, PartsInventoryRow>();
|
|
528
|
+
const emit = (path: string, bytes: Uint8Array): void => {
|
|
529
|
+
stageFile(stage, path, bytes);
|
|
530
|
+
stagedFiles.set(path, { path, bytes: bytes.length, sha256: partsSha256(bytes) });
|
|
531
|
+
};
|
|
532
|
+
for (const path of copied) emit(path, readBoundReplacementFile(source, inventory, path));
|
|
533
|
+
for (const [path, bytes] of writes) emit(path, bytes);
|
|
534
|
+
if (material !== null) {
|
|
535
|
+
writeMaterialSources(join(stage, 'parts.json'), join(stage, 'parts'), result, material);
|
|
536
|
+
const bytes = readRegularFile(join(stage, CUT_MATERIAL_SOURCES));
|
|
537
|
+
stagedFiles.set(CUT_MATERIAL_SOURCES, { path: CUT_MATERIAL_SOURCES, bytes: bytes.length, sha256: partsSha256(bytes) });
|
|
538
|
+
readMaterialSources(stage, result);
|
|
539
|
+
}
|
|
540
|
+
const record: ReplacementRecord = { spec: REPLACEMENT_RECORD_SPEC, source_sha256: sourceHash,
|
|
541
|
+
result_sha256: digestReplacementInventory(stagedFiles), rig_size: file.rig_size,
|
|
542
|
+
replaced: [...edits.values()].map(edit => edit.row), copied, rederived, omitted };
|
|
543
|
+
stageFile(stage, pointer, Buffer.from(JSON.stringify(record, null, 2) + '\n'));
|
|
544
|
+
const staged = readParts(join(stage, 'parts.json'));
|
|
545
|
+
verifyReplacementRecord(stage, staged);
|
|
546
|
+
const checked = checkPartsStage(stage, join(scratch, 'report'), () => {});
|
|
547
|
+
if (checked.exit_code !== 0) refuseIfAny(checked.refusals.map(({ code, object, detail }) => ({ code, object, detail })));
|
|
548
|
+
if (digestReplacementInventory(captureReplacementTree(source)) !== sourceHash) {
|
|
549
|
+
fail('REPLACE_PART_INPUT', '--parts', 'source tree changed during replacement; no output was published');
|
|
550
|
+
}
|
|
551
|
+
if (realpathSync(parent) !== parent || lstatIfPresent(out) !== undefined) fail('REPLACE_PART_OUTPUT', '--out', 'destination changed before publication');
|
|
552
|
+
try { renameSync(stage, out); }
|
|
553
|
+
catch (error) {
|
|
554
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
555
|
+
if (code === 'EEXIST' || code === 'ENOTEMPTY' || code === 'ENOTDIR' || code === 'EISDIR') {
|
|
556
|
+
fail('REPLACE_PART_OUTPUT', '--out', 'destination became occupied before publication');
|
|
557
|
+
}
|
|
558
|
+
throw error;
|
|
559
|
+
}
|
|
560
|
+
return record;
|
|
561
|
+
} finally {
|
|
562
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
563
|
+
}
|
|
564
|
+
}
|
package/src/rig.ts
CHANGED
|
@@ -1355,7 +1355,7 @@ function alphaCount(img: Raster, y0: number, y1: number): number {
|
|
|
1355
1355
|
}
|
|
1356
1356
|
|
|
1357
1357
|
/** Pixels with alpha strictly above `OPAQUE_ALPHA_ABOVE` (8) in `img`, the count `parts.json` records as `opaque_px`. */
|
|
1358
|
-
function opaqueCount(img: Raster): number {
|
|
1358
|
+
export function opaqueCount(img: Raster): number {
|
|
1359
1359
|
let n = 0;
|
|
1360
1360
|
for (let i = 3; i < img.data.length; i += 4) if (img.data[i] > OPAQUE_ALPHA_ABOVE) n++;
|
|
1361
1361
|
return n;
|
package/src/runstamp.ts
CHANGED
|
@@ -75,6 +75,7 @@ export interface RunStamp {
|
|
|
75
75
|
started_at: string;
|
|
76
76
|
finished_at: string;
|
|
77
77
|
config: RunStampFileEntry;
|
|
78
|
+
parts_input?: RunStampFileEntry;
|
|
78
79
|
inputs?: RunStampInputEntry[];
|
|
79
80
|
outputs: RunStampFileEntry[];
|
|
80
81
|
}
|
|
@@ -86,6 +87,8 @@ export interface RunStampInput {
|
|
|
86
87
|
finishedAt: string;
|
|
87
88
|
outDir: string;
|
|
88
89
|
configPath: string;
|
|
90
|
+
/** The parts directory as supplied to the stage and its pre-stage digest. */
|
|
91
|
+
partsInput?: RunStampFileEntry;
|
|
89
92
|
inputs?: RunStampAssembleInputs;
|
|
90
93
|
outputPaths: readonly string[];
|
|
91
94
|
}
|
|
@@ -245,6 +248,12 @@ export function buildRunStamp(input: RunStampInput): RunStamp {
|
|
|
245
248
|
path: relativeToOutRoot(input.outDir, input.configPath),
|
|
246
249
|
sha256: sha256OnDisk(input.configPath),
|
|
247
250
|
},
|
|
251
|
+
...(input.command !== 'rig' || input.partsInput === undefined ? {} : {
|
|
252
|
+
parts_input: {
|
|
253
|
+
path: relativeToOutRoot(input.outDir, input.partsInput.path) || '.',
|
|
254
|
+
sha256: input.partsInput.sha256,
|
|
255
|
+
},
|
|
256
|
+
}),
|
|
248
257
|
...(inputs === undefined ? {} : { inputs }),
|
|
249
258
|
outputs,
|
|
250
259
|
};
|
|
@@ -284,7 +293,7 @@ interface RunRecordFields {
|
|
|
284
293
|
export type BuildRunInputRole = RunStampInputRole | 'requirements' | 'environment' | 'wind-band' | `alt[${number}].${RunStampInputRole}`;
|
|
285
294
|
|
|
286
295
|
export type RunRecord =
|
|
287
|
-
| (RunRecordFields & { spec: typeof RUN_RECORD_SPEC; command: 'check' })
|
|
296
|
+
| (RunRecordFields & { spec: typeof RUN_RECORD_SPEC; command: 'check'; parts_input?: RunStampFileEntry })
|
|
288
297
|
| (RunRecordFields & { spec: typeof BUILD_RUN_RECORD_SPEC; command: 'build'; config: RunStampFileEntry; inputs: RunStampInputEntry<BuildRunInputRole>[] });
|
|
289
298
|
|
|
290
299
|
/** One command's flags as its parser takes them: the flag-table order, which values are paths, and values that hold paths inside them. */
|
|
@@ -405,7 +414,7 @@ interface BuildRunInputs extends RunStampAssembleInputs {
|
|
|
405
414
|
}
|
|
406
415
|
|
|
407
416
|
export type RunRecordInput = RunRecordInputFields & (
|
|
408
|
-
| { command: 'check' }
|
|
417
|
+
| { command: 'check'; partsInput?: RunStampFileEntry }
|
|
409
418
|
| { command: 'build'; configPath: string; inputs: BuildRunInputs }
|
|
410
419
|
);
|
|
411
420
|
|
|
@@ -436,7 +445,19 @@ export function buildRunRecord(input: RunRecordInput): RunRecord {
|
|
|
436
445
|
outputs: paths.map((p) => ({ path: p, sha256: sha256OnDisk(join(input.outDir, ...p.split('/'))) })),
|
|
437
446
|
argv: [...input.argv],
|
|
438
447
|
};
|
|
439
|
-
if (input.command === 'check') return {
|
|
448
|
+
if (input.command === 'check') return {
|
|
449
|
+
spec: RUN_RECORD_SPEC,
|
|
450
|
+
package: pkg,
|
|
451
|
+
command: 'check',
|
|
452
|
+
...times,
|
|
453
|
+
...(input.partsInput === undefined ? {} : {
|
|
454
|
+
parts_input: {
|
|
455
|
+
path: recordedConfigPath(input.outDir, input.partsInput.path) || '.',
|
|
456
|
+
sha256: input.partsInput.sha256,
|
|
457
|
+
},
|
|
458
|
+
}),
|
|
459
|
+
...tail,
|
|
460
|
+
};
|
|
440
461
|
return {
|
|
441
462
|
spec: BUILD_RUN_RECORD_SPEC,
|
|
442
463
|
package: pkg,
|