@rig-c/review 4.6.0 → 4.8.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/docs/REVIEW_PACKAGE.md +243 -28
- package/docs/STABILITY.md +88 -12
- package/package.json +1 -1
- package/src/canonical-json.ts +14 -0
- package/src/feedback-export.ts +2 -2
- package/src/interview-project.ts +27 -19
- package/src/interview-scene.ts +18 -11
- package/src/job-act.ts +99 -12
- package/src/job-api.ts +185 -38
- package/src/job-checkpoint-evidence.ts +19 -6
- package/src/job-cli.ts +12 -6
- package/src/job-contract.ts +91 -15
- package/src/job-front.ts +100 -78
- package/src/job-host.ts +9 -2
- package/src/job-previous-draft.ts +37 -0
- package/src/job-session.ts +76 -41
- package/src/job-source.ts +196 -35
- package/src/manifest.ts +43 -14
- package/src/mesh-edit.ts +7 -1
- package/src/parts-comment-crops.ts +15 -3
- package/src/parts-comparison.ts +21 -8
- package/src/parts-view.ts +23 -8
- package/web/catalog-en.ts +10 -0
- package/web/catalog-ko.ts +10 -0
- package/web/job-rig-screen.ts +63 -21
- package/web/job-session.ts +54 -26
- package/web/main.ts +158 -50
- package/web/mesh-editor.ts +123 -13
- package/web/part-selection.ts +1 -1
- package/web/parts-viewport-provider.ts +46 -11
- package/web/rig-host.ts +5 -3
- package/web/stage-comments.ts +77 -14
- package/web/styles.css +2 -0
- package/web/workspace-layout.ts +10 -0
- package/web/workspace-ui.ts +2 -2
- package/src/create-pin-gate.ts +0 -3
package/src/job-source.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {resolvePartsPaintingInRig} from './parts-view.ts';
|
|
2
|
-
import {checkpointEvidenceFields, checkpointEvidenceMetadata} from './job-checkpoint-evidence.ts';
|
|
2
|
+
import {checkpointEvidenceFields, checkpointEvidenceMetadata, readCheckpointEvidenceBytes} from './job-checkpoint-evidence.ts';
|
|
3
|
+
import {previousDraftFields} from './job-previous-draft.ts';
|
|
3
4
|
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { type Dirent, lstatSync, readdirSync, realpathSync, type Stats } from 'node:fs';
|
|
5
6
|
import { mkdir, open, rm, writeFile } from 'node:fs/promises';
|
|
@@ -11,19 +12,21 @@ import {
|
|
|
11
12
|
} from './job-contract.ts';
|
|
12
13
|
import type {
|
|
13
14
|
JobCheckpointEvidence, JobFileIdentity, JobInterviewDiagnostics, JobInterviewRecord, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
14
|
-
JobSelector, JobSourceBinding, JobSubject, JobPlanTextProjection, JobPlanTextStep,
|
|
15
|
+
JobPreviousDraft, JobSelector, JobSourceBinding, JobSubject, JobPlanTextProjection, JobPlanTextStep,
|
|
15
16
|
OptionContext, OptionSource, PackageResultV3, PlanContext, PlanSource, ProjectRecord, PublishRequestV3,
|
|
16
17
|
RecordFreeze, RecordOptionResult, RecordPlanResult, RecordPublicationReader, RecordPublishedContext,
|
|
17
18
|
RecordReaderInput, RecordResult, RecordSource, RecordSubject,
|
|
18
19
|
} from './job-contract.ts';
|
|
19
|
-
import { checkedPath, jsonObject, readProject, readRegular, type InterviewQuestion, type InterviewSet } from './interview-project.ts';
|
|
20
|
-
import {
|
|
20
|
+
import { checkedPath, inspectSceneQuestion, jsonObject, readProject, readRegular, type InterviewQuestion, type InterviewSet } from './interview-project.ts';
|
|
21
|
+
import { acceptedRigReview } from './interview-scene.ts';
|
|
22
|
+
import { BUILD_MODEL_PATH, loadJobReview, loadReview } from './manifest.ts';
|
|
21
23
|
import { HandoffError } from './handoff.ts';
|
|
22
24
|
import { openKey } from './open.ts';
|
|
23
25
|
import { assertReviewUnchanged } from './reference.ts';
|
|
24
26
|
import {
|
|
25
27
|
assertEqualRecordContexts,
|
|
26
28
|
assertJobApiSchema,
|
|
29
|
+
atSubject,
|
|
27
30
|
buildRecordSource,
|
|
28
31
|
isRecordSource,
|
|
29
32
|
jobHash,
|
|
@@ -58,6 +61,7 @@ export interface JobRootIdentity {
|
|
|
58
61
|
*/
|
|
59
62
|
export interface JobPublishedContext {
|
|
60
63
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
64
|
+
readonly previousDraft?: JobPreviousDraft;
|
|
61
65
|
readonly selector: JobSelector | null;
|
|
62
66
|
readonly plan: JobPlanIdentity | null;
|
|
63
67
|
readonly parts: JobPartsIdentity | null;
|
|
@@ -85,7 +89,7 @@ export type JobPublicationReader = (input: {
|
|
|
85
89
|
}) => Promise<JobPublishedContext>;
|
|
86
90
|
|
|
87
91
|
export interface JobRetainedSource {
|
|
88
|
-
/** Private base preimage for
|
|
92
|
+
/** Private base preimage for optional declarations. Keeps its historical key. */
|
|
89
93
|
readonly checkpointEvidencePackageHash?: string;
|
|
90
94
|
readonly root: JobRootIdentity;
|
|
91
95
|
readonly record: JobFileIdentity | null;
|
|
@@ -186,12 +190,23 @@ function rootRelative(root: string, absolute: string): string {
|
|
|
186
190
|
|
|
187
191
|
function sourceBytes(root: string, path: string): Buffer {
|
|
188
192
|
const file = checkedPath(root, jobPath(path));
|
|
189
|
-
const before = lstatSync(file)
|
|
193
|
+
const before = lstatSync(file);
|
|
194
|
+
const bytes = readRegular(file, maxFileBytes), after = lstatSync(file);
|
|
190
195
|
if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size ||
|
|
191
196
|
before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
192
197
|
return bytes;
|
|
193
198
|
}
|
|
194
199
|
|
|
200
|
+
/** Read and hash the exact bytes the caller will consume, including on a cache hit at the front. */
|
|
201
|
+
export function readPreviousDraftBytes(root: string, file: JobFileIdentity, operand: 'current' | 'previous' | 'diff'): Buffer {
|
|
202
|
+
const limit = operand === 'diff' ? 1024 * 1024 : maxFileBytes;
|
|
203
|
+
return readCheckpointEvidenceBytes(root, file, limit, failure => {
|
|
204
|
+
if (failure === 'limit') return new JobError('JOB_SOURCE_UNRETAINABLE', `PREVIOUS_DRAFT_LIMIT operand=${operand}`);
|
|
205
|
+
return new JobError('JOB_SOURCE_MISMATCH', failure === 'hash' ? `PREVIOUS_DRAFT_HASH_MISMATCH operand=${operand}`
|
|
206
|
+
: `PREVIOUS_DRAFT_MISSING operand=${operand} path=${JSON.stringify(file.path)}`);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
195
210
|
function assertRecord(root: JobRootIdentity, record: JobFileIdentity | null): void {
|
|
196
211
|
assertJobRoot(root);
|
|
197
212
|
if (record) {
|
|
@@ -221,15 +236,16 @@ export function assertJobSourceCurrent(
|
|
|
221
236
|
}
|
|
222
237
|
|
|
223
238
|
function publishedIdentities(context: JobPublishedContext): JobFileIdentity[] {
|
|
224
|
-
const files =
|
|
239
|
+
const files = context.files;
|
|
240
|
+
if (!Array.isArray(files)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
225
241
|
const ids = new Set<string>();
|
|
226
242
|
for (const step of context.plan?.steps ?? []) {
|
|
227
243
|
if (ids.has(jobId(step.id))) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
228
244
|
ids.add(step.id);
|
|
229
245
|
jobSha(step.hash);
|
|
230
246
|
}
|
|
231
|
-
|
|
232
|
-
|
|
247
|
+
try { return Array.from(files, file => ({path: jobPath(file?.path), sha256: jobSha(file?.sha256)})); }
|
|
248
|
+
catch { throw new JobError('JOB_SOURCE_MISMATCH'); }
|
|
233
249
|
}
|
|
234
250
|
|
|
235
251
|
function referenceRow(raw: unknown, row: number, hashed: boolean): JobPartsFileReference & { sha256?: string } {
|
|
@@ -247,7 +263,7 @@ function referenceRow(raw: unknown, row: number, hashed: boolean): JobPartsFileR
|
|
|
247
263
|
}
|
|
248
264
|
|
|
249
265
|
/** Reuse the official-reference PNG admission and decoded-size bound for generic sidecar operands. */
|
|
250
|
-
function assertPartsReferencePng(data: Buffer, detail: string):
|
|
266
|
+
function assertPartsReferencePng(data: Buffer, detail: string): {width: number; height: number} {
|
|
251
267
|
if (data.length < 33 || !data.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex')) ||
|
|
252
268
|
data.readUInt32BE(8) !== 13 || data.toString('ascii', 12, 16) !== 'IHDR') {
|
|
253
269
|
throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_PNG_INVALID ${detail}`);
|
|
@@ -259,6 +275,60 @@ function assertPartsReferencePng(data: Buffer, detail: string): void {
|
|
|
259
275
|
}
|
|
260
276
|
try { PNG.sync.read(data); }
|
|
261
277
|
catch { throw new JobError('JOB_SOURCE_MISMATCH', `PARTS_REFERENCE_PNG_INVALID ${detail}`); }
|
|
278
|
+
return {width, height};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** The caller has already bounded and sealed the bytes. Parts owns the document's internal shape. */
|
|
282
|
+
function assertPreviousDraftDiff(bytes: Buffer, composites: JobPreviousDraft['composites']): void {
|
|
283
|
+
const invalid = () => new JobError('JOB_SOURCE_MISMATCH', 'PREVIOUS_DRAFT_DIFF_INVALID');
|
|
284
|
+
let document: ReturnType<typeof jsonObject>;
|
|
285
|
+
try { document = jsonObject(bytes); }
|
|
286
|
+
catch { throw invalid(); }
|
|
287
|
+
if (document.schema !== 'rig-parts-draft-diff/1') throw invalid();
|
|
288
|
+
const missing = new Set([composites.current.sha256, composites.previous.sha256]);
|
|
289
|
+
const pending: unknown[] = [document];
|
|
290
|
+
while (pending.length && missing.size) {
|
|
291
|
+
const value = pending.pop();
|
|
292
|
+
if (typeof value === 'string') missing.delete(value);
|
|
293
|
+
else if (value !== null && typeof value === 'object') {
|
|
294
|
+
for (const child of Object.values(value)) pending.push(child);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (missing.size) throw invalid();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function admitPreviousDraftAssets(root: string, declaration: JobPreviousDraft, manifestBytes: Buffer | undefined): Map<string, Buffer> {
|
|
301
|
+
const size = manifestBytes && jsonObject(manifestBytes).rig_size;
|
|
302
|
+
if (!Array.isArray(size) || size.length !== 2 || !size.every(n => Number.isSafeInteger(n) && n > 0)) {
|
|
303
|
+
throw new JobError('JOB_SOURCE_MISMATCH', 'PREVIOUS_DRAFT_INVALID');
|
|
304
|
+
}
|
|
305
|
+
const admitted = new Map<string, Buffer>();
|
|
306
|
+
for (const operand of ['current', 'previous'] as const) {
|
|
307
|
+
const file = declaration.composites[operand], detail = `operand=${operand}`;
|
|
308
|
+
const bytes = readPreviousDraftBytes(root, file, operand);
|
|
309
|
+
let dimensions: ReturnType<typeof assertPartsReferencePng>;
|
|
310
|
+
try {
|
|
311
|
+
// Parts writes noninterlaced RGBA8. pngjs uses bounded inflate for that encoding.
|
|
312
|
+
if (bytes[24] !== 8 || bytes[25] !== 6 || bytes[28] !== 0) throw new Error('format');
|
|
313
|
+
dimensions = assertPartsReferencePng(bytes, detail);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if (error instanceof JobError && error.code === 'JOB_SOURCE_UNRETAINABLE') {
|
|
316
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `PREVIOUS_DRAFT_LIMIT ${detail}`);
|
|
317
|
+
}
|
|
318
|
+
throw new JobError('JOB_SOURCE_MISMATCH', `PREVIOUS_DRAFT_PNG_INVALID ${detail}`);
|
|
319
|
+
}
|
|
320
|
+
if (dimensions.width !== size[0] || dimensions.height !== size[1]) {
|
|
321
|
+
throw new JobError('JOB_SOURCE_MISMATCH',
|
|
322
|
+
`PREVIOUS_DRAFT_SIZE ${detail} expected=${size.join('x')} received=${dimensions.width}x${dimensions.height}`);
|
|
323
|
+
}
|
|
324
|
+
admitted.set(file.path, bytes);
|
|
325
|
+
}
|
|
326
|
+
if (declaration.diff) {
|
|
327
|
+
const bytes = readPreviousDraftBytes(root, declaration.diff, 'diff');
|
|
328
|
+
assertPreviousDraftDiff(bytes, declaration.composites);
|
|
329
|
+
admitted.set(declaration.diff.path, bytes);
|
|
330
|
+
}
|
|
331
|
+
return admitted;
|
|
262
332
|
}
|
|
263
333
|
|
|
264
334
|
function partsIdentityHeader(value: unknown): {raw: Record<string, unknown>; version: string} {
|
|
@@ -562,15 +632,13 @@ function validateOptionSetStructure(
|
|
|
562
632
|
return raw as unknown as InterviewSet;
|
|
563
633
|
}
|
|
564
634
|
|
|
565
|
-
|
|
635
|
+
function assertRetainedSnapshotRoot(
|
|
566
636
|
snapshotRoot: string,
|
|
567
|
-
|
|
568
|
-
snapshotIdentity?: { readonly dev: number; readonly ino: number },
|
|
637
|
+
snapshotIdentity: JobRetainedSourceV3['snapshotIdentity'],
|
|
569
638
|
refusalCode: 'JOB_SOURCE_UNRETAINABLE' | 'JOB_ACT_SOURCE_STALE' = 'JOB_SOURCE_UNRETAINABLE',
|
|
570
639
|
): void {
|
|
571
|
-
let rootInfo: Stats;
|
|
572
640
|
try {
|
|
573
|
-
rootInfo = lstatSync(snapshotRoot);
|
|
641
|
+
const rootInfo = lstatSync(snapshotRoot);
|
|
574
642
|
if (!rootInfo.isDirectory() || realpathSync(snapshotRoot) !== snapshotRoot || (rootInfo.mode & 0o077) !== 0) {
|
|
575
643
|
throw new Error('Invalid snapshot directory');
|
|
576
644
|
}
|
|
@@ -580,6 +648,15 @@ export function assertRetainedSnapshotIntact(
|
|
|
580
648
|
} catch {
|
|
581
649
|
throw new JobError(refusalCode);
|
|
582
650
|
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export function assertRetainedSnapshotIntact(
|
|
654
|
+
snapshotRoot: string,
|
|
655
|
+
seals: readonly JobFileIdentity[],
|
|
656
|
+
snapshotIdentity?: { readonly dev: number; readonly ino: number },
|
|
657
|
+
refusalCode: 'JOB_SOURCE_UNRETAINABLE' | 'JOB_ACT_SOURCE_STALE' = 'JOB_SOURCE_UNRETAINABLE',
|
|
658
|
+
): void {
|
|
659
|
+
assertRetainedSnapshotRoot(snapshotRoot, snapshotIdentity, refusalCode);
|
|
583
660
|
const expectedFiles = new Map<string, string>();
|
|
584
661
|
const expectedDirs = new Set<string>(['']);
|
|
585
662
|
for (const seal of seals) {
|
|
@@ -721,7 +798,9 @@ function readProjectRecordBytes(root: string, record: ProjectRecord, allowLegacy
|
|
|
721
798
|
throw new JobError(allowLegacySchema ? 'JOB_SOURCE_UNRETAINABLE' : 'JOB_RECORD_MOVED');
|
|
722
799
|
}
|
|
723
800
|
if (!stat.isFile()) throw new JobError(allowLegacySchema ? 'JOB_SOURCE_UNRETAINABLE' : 'JOB_RECORD_MOVED');
|
|
724
|
-
if (stat.size > maxProjectBytes)
|
|
801
|
+
if (stat.size > maxProjectBytes) {
|
|
802
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `project record bytes ${stat.size} exceed the ${maxProjectBytes}-byte limit`);
|
|
803
|
+
}
|
|
725
804
|
let bytes: Buffer;
|
|
726
805
|
try {
|
|
727
806
|
bytes = sourceBytes(root, record.path);
|
|
@@ -755,7 +834,10 @@ function readClosureFileBytes(root: string, file: JobFileIdentity): Buffer {
|
|
|
755
834
|
} catch {
|
|
756
835
|
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
757
836
|
}
|
|
758
|
-
if (!stat.isFile()
|
|
837
|
+
if (!stat.isFile()) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
838
|
+
if (stat.size > maxFileBytes) {
|
|
839
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `retained source file bytes ${stat.size} exceed the ${maxFileBytes}-byte limit`);
|
|
840
|
+
}
|
|
759
841
|
let bytes: Buffer;
|
|
760
842
|
try {
|
|
761
843
|
bytes = sourceBytes(root, file.path);
|
|
@@ -767,6 +849,53 @@ function readClosureFileBytes(root: string, file: JobFileIdentity): Buffer {
|
|
|
767
849
|
return bytes;
|
|
768
850
|
}
|
|
769
851
|
|
|
852
|
+
/** Optional picture for a record question. Resolve it anew from sealed inputs after a host restart. */
|
|
853
|
+
export async function loadRetainedRecordRig(retained: JobRetainedRecordSource) {
|
|
854
|
+
const {source, snapshotRoot} = retained;
|
|
855
|
+
if (source.subject !== 'option-set' || !retained.questions.some(question => question.set.stage === 'post-interview')) return null;
|
|
856
|
+
try {
|
|
857
|
+
assertRetainedSnapshotRoot(snapshotRoot, retained.snapshotIdentity);
|
|
858
|
+
const seals = new Map(retained.seals.map(({path, sha256}) => [path, sha256]));
|
|
859
|
+
const published = new Map(source.files.map(({path, sha256}) => [path, sha256]));
|
|
860
|
+
const isBound = (path: string, hash: string) => seals.get(path) === hash && published.get(path) === hash;
|
|
861
|
+
const {record, optionSetFile} = source;
|
|
862
|
+
if (record.sha256 !== source.projectHash || !isBound(record.path, record.sha256) ||
|
|
863
|
+
!isBound(optionSetFile.path, optionSetFile.sha256)) return null;
|
|
864
|
+
const set = jsonObject(readClosureFileBytes(snapshotRoot, optionSetFile));
|
|
865
|
+
const context = asPlainObject(set.context);
|
|
866
|
+
if (set.stage !== 'post-interview' || context?.kind !== 'rig') return null;
|
|
867
|
+
const version = context.rig_version;
|
|
868
|
+
if (typeof version !== 'number' || !Number.isSafeInteger(version) || version < 1 ||
|
|
869
|
+
typeof set.drafted_at !== 'string' || typeof context.signoff_at !== 'string') return null;
|
|
870
|
+
const drafted = Date.parse(set.drafted_at), signed = Date.parse(context.signoff_at), now = Date.now();
|
|
871
|
+
if (!(signed <= drafted && drafted <= now)) return null;
|
|
872
|
+
const {project} = readProjectRecordBytes(snapshotRoot, record);
|
|
873
|
+
const accepted = acceptedRigReview(project, version, now);
|
|
874
|
+
if (!accepted || accepted.acceptance.signoff.at !== context.signoff_at || !Array.isArray(accepted.pkg.files)) return null;
|
|
875
|
+
const config = jobObject(accepted.pkg.config, ['path', 'sha256']);
|
|
876
|
+
jobPath(config.path);
|
|
877
|
+
jobSha(config.sha256);
|
|
878
|
+
|
|
879
|
+
const packageCheck = 'out/check';
|
|
880
|
+
const check = `derived/review/v${version}/${packageCheck}`;
|
|
881
|
+
const build = `${packageCheck}/${posix.dirname(BUILD_MODEL_PATH)}/`;
|
|
882
|
+
const sealedPlayback = new Map<string, string>();
|
|
883
|
+
for (const value of accepted.pkg.files) {
|
|
884
|
+
const row = asPlainObject(value);
|
|
885
|
+
if (!row || typeof row.path !== 'string') return null;
|
|
886
|
+
if (!row.path.startsWith(build)) continue;
|
|
887
|
+
const path = jobPath(row.path.slice(packageCheck.length + 1)), sha256 = jobSha(row.sha256);
|
|
888
|
+
if (sealedPlayback.has(path) || !isBound(`${check}/${path}`, sha256)) return null;
|
|
889
|
+
sealedPlayback.set(path, sha256);
|
|
890
|
+
}
|
|
891
|
+
if (!sealedPlayback.has(BUILD_MODEL_PATH)) return null;
|
|
892
|
+
return await loadReview(checkedPath(snapshotRoot, check, true), {handoff: false, sealedPlayback});
|
|
893
|
+
} catch {
|
|
894
|
+
// Picture failures leave the sealed questionnaire available to answer.
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
770
899
|
/** Delivery-only projection through the existing retained record reader. */
|
|
771
900
|
export function projectRetainedPlanText(retained: JobRetainedSourceV3): JobPlanTextProjection | undefined {
|
|
772
901
|
const {source, record} = retained;
|
|
@@ -913,7 +1042,17 @@ function decodeRetainedRecordProject(
|
|
|
913
1042
|
const set = validateOptionSetStructure(rawSet, questionId, setId, matches[0]!.allowedStages);
|
|
914
1043
|
const images: InterviewQuestion['images'] = [];
|
|
915
1044
|
const ctx = asPlainObject(rawSet.context);
|
|
916
|
-
if (ctx
|
|
1045
|
+
if (ctx?.kind === 'scene') {
|
|
1046
|
+
try {
|
|
1047
|
+
const scene = inspectSceneQuestion(project, ctx, set, Date.now(), ref => {
|
|
1048
|
+
if (sealMap.get(ref.path) !== ref.sha256) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1049
|
+
return jsonObject(readClosureFileBytes(snapshotRoot, ref));
|
|
1050
|
+
});
|
|
1051
|
+
if (scene.images.every(({ref}) => sealMap.get(ref.path) === ref.sha256)) images.push(...scene.images);
|
|
1052
|
+
} catch {
|
|
1053
|
+
// A record can still be answered when its bound scene cannot be displayed.
|
|
1054
|
+
}
|
|
1055
|
+
} else if (ctx && ctx.kind !== 'rig' && Array.isArray(ctx.files)) {
|
|
917
1056
|
for (const rawFile of ctx.files) {
|
|
918
1057
|
const fileObj = asPlainObject(rawFile);
|
|
919
1058
|
if (!fileObj || typeof fileObj.path !== 'string' || typeof fileObj.sha256 !== 'string') {
|
|
@@ -959,6 +1098,9 @@ function decodeRetainedRecordProject(
|
|
|
959
1098
|
editable: true,
|
|
960
1099
|
images,
|
|
961
1100
|
hasParts: hasBoundParts,
|
|
1101
|
+
...(ctx?.kind === 'scene' && images.length ? {scenePicture: true as const} : {}),
|
|
1102
|
+
...(set.stage === 'post-interview' && !images.length && (ctx?.kind === 'rig' || ctx?.kind === 'scene')
|
|
1103
|
+
? {missingPicture: ctx.kind} : {}),
|
|
962
1104
|
}],
|
|
963
1105
|
optionSetFile: ref,
|
|
964
1106
|
};
|
|
@@ -1010,7 +1152,7 @@ export async function prepareJobRecordSource(options: {
|
|
|
1010
1152
|
);
|
|
1011
1153
|
assertRecord(root, record);
|
|
1012
1154
|
if (inventory.files.length > maxSourceFiles) {
|
|
1013
|
-
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
1155
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `retained source files ${inventory.files.length} exceed the ${maxSourceFiles}-file limit`);
|
|
1014
1156
|
}
|
|
1015
1157
|
checkpointEvidenceMetadata(root.path, inventory.checkpointEvidence);
|
|
1016
1158
|
const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
|
|
@@ -1026,7 +1168,9 @@ export async function prepareJobRecordSource(options: {
|
|
|
1026
1168
|
for (const file of inventory.files) {
|
|
1027
1169
|
const bytes = readClosureFileBytes(root.path, file);
|
|
1028
1170
|
retainedBytes += bytes.length;
|
|
1029
|
-
if (retainedBytes > maxSourceBytes)
|
|
1171
|
+
if (retainedBytes > maxSourceBytes) {
|
|
1172
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `retained source bytes ${retainedBytes} exceed the ${maxSourceBytes}-byte limit`);
|
|
1173
|
+
}
|
|
1030
1174
|
const destination = join(snapshotRoot, file.path);
|
|
1031
1175
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
1032
1176
|
const handle = await open(destination, 'wx', 0o600);
|
|
@@ -1116,6 +1260,8 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
1116
1260
|
readonly readRecordPublished?: RecordPublicationReader;
|
|
1117
1261
|
readonly phase?: 'ask' | 'finalize';
|
|
1118
1262
|
readonly subject?: RecordSubject;
|
|
1263
|
+
/** `ask-batch`: every subject is validated against this one fresh read, refusing under its request index. */
|
|
1264
|
+
readonly subjects?: readonly RecordSubject[];
|
|
1119
1265
|
}): Promise<RecordSource> {
|
|
1120
1266
|
const { retained } = options;
|
|
1121
1267
|
const phase = options.phase ?? 'ask';
|
|
@@ -1203,6 +1349,7 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
1203
1349
|
throw error;
|
|
1204
1350
|
}
|
|
1205
1351
|
}
|
|
1352
|
+
options.subjects?.forEach((subject, index) => atSubject(index, () => validateRecordAskSubject(subject, freshSource)));
|
|
1206
1353
|
assertJobSourceCurrent(retained);
|
|
1207
1354
|
return freshSource;
|
|
1208
1355
|
}
|
|
@@ -1210,7 +1357,7 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
1210
1357
|
/** Preserve the existing composite preimage, conditionally appending the declaration. */
|
|
1211
1358
|
function packageSourceDigest(packageSourceHash: string, record: JobFileIdentity | null,
|
|
1212
1359
|
source: Pick<JobModelSourceBinding, 'selector' | 'plan' | 'parts'>, files: readonly JobFileIdentity[],
|
|
1213
|
-
evidence:
|
|
1360
|
+
evidence: Pick<JobModelSourceBinding, 'checkpointEvidence' | 'previousDraft'>): string {
|
|
1214
1361
|
return jobHash(JSON.stringify({schema: 'rig-review-job-source/2', packageSourceHash, record,
|
|
1215
1362
|
selector: source.selector, plan: source.plan, parts: source.parts, files, ...evidence}));
|
|
1216
1363
|
}
|
|
@@ -1269,6 +1416,7 @@ export async function prepareJobSource(options: {
|
|
|
1269
1416
|
if ('kind' in options.request.result) {
|
|
1270
1417
|
assertJobApiSchema(options.request.schema, JOB_API_V3_SCHEMA);
|
|
1271
1418
|
if (options.request.result.kind !== 'package') {
|
|
1419
|
+
// The record reader owns both context reads. The package reader is never invoked here.
|
|
1272
1420
|
return prepareJobRecordSource({
|
|
1273
1421
|
root: options.root,
|
|
1274
1422
|
stateRoot: options.stateRoot,
|
|
@@ -1331,6 +1479,7 @@ export async function prepareJobSource(options: {
|
|
|
1331
1479
|
}
|
|
1332
1480
|
if (requestDigest(context.selector) !== requestDigest(request.result.selector)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1333
1481
|
const declared = publishedIdentities(context);
|
|
1482
|
+
const previous = previousDraftFields(context, context.selector, declared);
|
|
1334
1483
|
const evidence = checkpointEvidenceFields(context, context.plan, context.subjects, declared);
|
|
1335
1484
|
checkpointEvidenceMetadata(root.path, evidence.checkpointEvidence);
|
|
1336
1485
|
let review: Awaited<ReturnType<typeof loadJobReview>>;
|
|
@@ -1363,7 +1512,9 @@ export async function prepareJobSource(options: {
|
|
|
1363
1512
|
for (const file of questionFiles.optional) {
|
|
1364
1513
|
if (!wanted.has(file.path)) add(file.path, file.sha256);
|
|
1365
1514
|
}
|
|
1366
|
-
if (wanted.size > maxSourceFiles)
|
|
1515
|
+
if (wanted.size > maxSourceFiles) {
|
|
1516
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `retained source files ${wanted.size} exceed the ${maxSourceFiles}-file limit`);
|
|
1517
|
+
}
|
|
1367
1518
|
const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
|
|
1368
1519
|
const seals: JobFileIdentity[] = [];
|
|
1369
1520
|
let snapshotIdentity: {dev: number; ino: number} | null = null;
|
|
@@ -1373,14 +1524,18 @@ export async function prepareJobSource(options: {
|
|
|
1373
1524
|
const info = lstatSync(snapshotRoot);
|
|
1374
1525
|
snapshotIdentity = {dev: info.dev, ino: info.ino};
|
|
1375
1526
|
const parts = await prepareParts(root.path, snapshotRoot, context.parts, declared, options.partsEnumerator);
|
|
1527
|
+
const previousAssets = previous.previousDraft && admitPreviousDraftAssets(root.path, previous.previousDraft,
|
|
1528
|
+
parts.identity ? parts.bytes.get(parts.identity.manifest.path) : undefined);
|
|
1376
1529
|
for (const [path, bytes] of parts.bytes) add(path, jobHash(bytes));
|
|
1377
1530
|
if (wanted.size > maxSourceFiles) throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PARTS_REFERENCE_LIMIT');
|
|
1378
1531
|
let size = 0;
|
|
1379
1532
|
const directories = new Set([snapshotRoot, dirname(snapshotRoot), options.stateRoot]);
|
|
1380
1533
|
for (const [path, expected] of [...wanted].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
1381
|
-
const bytes = parts.bytes.get(path) ?? sourceBytes(root.path, path), sha256 = jobHash(bytes);
|
|
1534
|
+
const bytes = previousAssets?.get(path) ?? parts.bytes.get(path) ?? sourceBytes(root.path, path), sha256 = jobHash(bytes);
|
|
1382
1535
|
size += bytes.length;
|
|
1383
|
-
if (size > maxSourceBytes)
|
|
1536
|
+
if (size > maxSourceBytes) {
|
|
1537
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', `retained source bytes ${size} exceed the ${maxSourceBytes}-byte limit`);
|
|
1538
|
+
}
|
|
1384
1539
|
if (expected && sha256 !== expected) throw new JobError(path === record?.path ? 'JOB_RECORD_MOVED' : 'JOB_SOURCE_MISMATCH');
|
|
1385
1540
|
const destination = join(snapshotRoot, path);
|
|
1386
1541
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
@@ -1412,9 +1567,9 @@ export async function prepareJobSource(options: {
|
|
|
1412
1567
|
path: rootRelative(root.path, resolve(review.root, file.path)), sha256: file.sha256,
|
|
1413
1568
|
});
|
|
1414
1569
|
checkpointEvidenceMetadata(snapshotRoot, evidence.checkpointEvidence);
|
|
1415
|
-
const modelSource:
|
|
1570
|
+
const modelSource: JobModelSourceBinding = {
|
|
1416
1571
|
sourceHash: project || context.plan || context.parts ? packageSourceDigest(review.sourceHash, record,
|
|
1417
|
-
{selector: context.selector, plan: context.plan, parts: parts.identity}, seals, evidence) : review.sourceHash,
|
|
1572
|
+
{selector: context.selector, plan: context.plan, parts: parts.identity}, seals, {...evidence, ...previous}) : review.sourceHash,
|
|
1418
1573
|
projectHash: project?.hash ?? null,
|
|
1419
1574
|
package: { id: review.manifest.id, revision: review.manifest.revision },
|
|
1420
1575
|
selector: context.selector,
|
|
@@ -1422,7 +1577,7 @@ export async function prepareJobSource(options: {
|
|
|
1422
1577
|
direction: originalIdentity(review.direction?.file ?? null),
|
|
1423
1578
|
optionSet: null, appliedResult: null, plan: context.plan, parts: parts.identity,
|
|
1424
1579
|
};
|
|
1425
|
-
|
|
1580
|
+
const source: JobSourceBinding = {...modelSource, ...evidence, ...previous};
|
|
1426
1581
|
const boundReview = { ...review, sourceHash: source.sourceHash };
|
|
1427
1582
|
const sealedByPath = new Map(seals.map(seal => [seal.path, seal.sha256]));
|
|
1428
1583
|
const retainedInterview = project
|
|
@@ -1442,7 +1597,7 @@ export async function prepareJobSource(options: {
|
|
|
1442
1597
|
: null;
|
|
1443
1598
|
const prepared: JobRetainedSource = {
|
|
1444
1599
|
root, record, seals, snapshotRoot, snapshotIdentity,
|
|
1445
|
-
...(
|
|
1600
|
+
...(source.checkpointEvidence || source.previousDraft ? {checkpointEvidencePackageHash: review.sourceHash} : {}),
|
|
1446
1601
|
manifestPath: retained.manifestPath,
|
|
1447
1602
|
source,
|
|
1448
1603
|
instanceKey: openKey({ mode: 'single', p: boundReview, inputs: { input: review.manifestPath },
|
|
@@ -1464,7 +1619,7 @@ export async function prepareJobSource(options: {
|
|
|
1464
1619
|
};
|
|
1465
1620
|
await options.afterSnapshot?.();
|
|
1466
1621
|
assertJobSourceCurrent(prepared);
|
|
1467
|
-
if (source.checkpointEvidence) assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity);
|
|
1622
|
+
if (source.checkpointEvidence || source.previousDraft) assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity);
|
|
1468
1623
|
return prepared;
|
|
1469
1624
|
} catch (error) {
|
|
1470
1625
|
if (snapshotIdentity) await removeOwnedJobSnapshot(options.stateRoot, {snapshotRoot, ...snapshotIdentity});
|
|
@@ -1473,7 +1628,7 @@ export async function prepareJobSource(options: {
|
|
|
1473
1628
|
}
|
|
1474
1629
|
}
|
|
1475
1630
|
|
|
1476
|
-
/** Authenticate
|
|
1631
|
+
/** Authenticate optional declarations without opening live files or reclaimed snapshots. */
|
|
1477
1632
|
export function assertStoredCheckpointEvidence(retained: JobRetainedSourceV3): void {
|
|
1478
1633
|
if (!retained.source || typeof retained.source !== 'object' || Array.isArray(retained.source)) {
|
|
1479
1634
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
@@ -1481,20 +1636,26 @@ export function assertStoredCheckpointEvidence(retained: JobRetainedSourceV3): v
|
|
|
1481
1636
|
const hasEvidence = 'checkpointEvidence' in retained.source;
|
|
1482
1637
|
if (isRetainedRecordSource(retained)) {
|
|
1483
1638
|
const parsed = parseRecordSource(retained.source);
|
|
1484
|
-
if (!hasEvidence && !('checkpointEvidence' in retained.context)) return;
|
|
1639
|
+
if (!hasEvidence && !('checkpointEvidence' in retained.context) && !('previousDraft' in retained.context)) return;
|
|
1485
1640
|
const context = parseRecordPublishedContext(retained.context, retained.result, retained.record);
|
|
1486
1641
|
if (requestDigest(parsed.checkpointEvidence ?? null) !== requestDigest(context.checkpointEvidence ?? null) ||
|
|
1487
1642
|
requestDigest(parsed.subjects) !== requestDigest(retained.subjects) ||
|
|
1488
1643
|
requestDigest(parsed.files) !== requestDigest(retained.seals)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1489
1644
|
return;
|
|
1490
1645
|
}
|
|
1491
|
-
if (!hasEvidence && !('checkpointEvidencePackageHash' in retained)) return;
|
|
1492
1646
|
const source = retained.source;
|
|
1493
|
-
|
|
1647
|
+
const hasPreviousDraft = 'previousDraft' in source;
|
|
1648
|
+
if (!hasEvidence && !hasPreviousDraft && !('checkpointEvidencePackageHash' in retained)) return;
|
|
1649
|
+
if (!(hasEvidence || hasPreviousDraft) || !retained.record || (hasPreviousDraft && !source.parts)) {
|
|
1650
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1651
|
+
}
|
|
1494
1652
|
const evidence = checkpointEvidenceFields(source, source.plan, retained.subjects, retained.seals);
|
|
1653
|
+
const previous = previousDraftFields(source, source.selector, retained.seals);
|
|
1495
1654
|
const packageSourceHash = jobSha(retained.checkpointEvidencePackageHash);
|
|
1496
|
-
const expected = packageSourceDigest(packageSourceHash, retained.record, source, retained.seals, evidence);
|
|
1497
|
-
if (expected !== source.sourceHash ||
|
|
1655
|
+
const expected = packageSourceDigest(packageSourceHash, retained.record, source, retained.seals, {...evidence, ...previous});
|
|
1656
|
+
if (expected !== source.sourceHash ||
|
|
1657
|
+
requestDigest(evidence.checkpointEvidence ?? null) !== requestDigest(source.checkpointEvidence ?? null) ||
|
|
1658
|
+
requestDigest(previous.previousDraft ?? null) !== requestDigest(source.previousDraft ?? null)) {
|
|
1498
1659
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1499
1660
|
}
|
|
1500
1661
|
}
|
package/src/manifest.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { createReadStream } from 'node:fs';
|
|
|
12
12
|
import { basename, dirname, isAbsolute, relative, resolve, posix } from 'node:path';
|
|
13
13
|
import { isBuildRoot, parseHandoffDeclaration, resolveHandoff, type Handoff, type HandoffDeclaration, type HandoffFlags, type HandoffRecord } from './handoff.ts';
|
|
14
14
|
import { parsePanelComposition, type JobPanelComposition } from './job-contract.ts';
|
|
15
|
+
import { checkedPath } from './interview-project.ts';
|
|
15
16
|
export { isPanelComponent, parsePanelComposition } from './job-contract.ts';
|
|
16
17
|
|
|
17
18
|
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
@@ -102,28 +103,52 @@ export function parseManifest(input: unknown): ReviewManifest {
|
|
|
102
103
|
for(const c of manifest.checkpoints) if(c.axis){const a=manifest.axes.find(a=>a.id===c.axis!.id);if(!a)fail(`checkpoint ${c.id}.axis`,'declared axis id');if(c.axis.value<a.min||c.axis.value>a.max)fail(`checkpoint ${c.id}.axis.value`,`number in [${a.min}, ${a.max}]`);}
|
|
103
104
|
return manifest;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
export const BUILD_MODEL_PATH = 'build/skeleton.model.json';
|
|
107
|
+
interface ReviewLoadOptions {
|
|
108
|
+
/** Explicit producer flags take precedence over discovery. False disables producer lookup. */
|
|
109
|
+
handoff?: HandoffFlags | false;
|
|
110
|
+
cwd?: string;
|
|
111
|
+
handoffStarts?: readonly string[];
|
|
112
|
+
/** Load only the adapter's build model and its sealed page images. */
|
|
113
|
+
sealedPlayback?: ReadonlyMap<string, string>;
|
|
114
|
+
}
|
|
115
|
+
export async function loadReview(input: string, options: ReviewLoadOptions = {}): Promise<ReviewPackage> {
|
|
116
|
+
const {sealedPlayback}=options;
|
|
107
117
|
const inputPath=await realpath(resolve(input));const directory=(await stat(inputPath)).isDirectory();
|
|
108
|
-
if(directory
|
|
118
|
+
if(sealedPlayback&&(!directory||options.handoff!==false||inputPath!==resolve(input)))fail('sealed playback','literal folder with handoff disabled');
|
|
119
|
+
if(directory&&!sealedPlayback){try{await stat(resolve(inputPath,'review.json'));return loadReview(resolve(inputPath,'review.json'),options);}catch(e){if((e as NodeJS.ErrnoException).code!=='ENOENT')throw e;}
|
|
109
120
|
// #149: a rig-parts build root without a model of its own opens as its check package, exactly as opening check/ does.
|
|
110
121
|
const check=await buildCheckPackage(inputPath);if(check)return loadReview(check,options);}
|
|
111
122
|
const manifestPath=inputPath;const root=directory?inputPath:await realpath(dirname(inputPath));
|
|
112
|
-
const manifest=directory?await folderManifest(root):parseManifest(JSON.parse(await readFile(manifestPath,'utf8')));
|
|
123
|
+
const manifest=directory?await folderManifest(root,!!sealedPlayback):parseManifest(JSON.parse(await readFile(manifestPath,'utf8')));
|
|
124
|
+
const assetFile=async(path:string):Promise<string>=>{
|
|
125
|
+
if(sealedPlayback&&!sealedPlayback.has(path))fail(path,'sealed playback file');
|
|
126
|
+
const literal=sealedPlayback?checkedPath(root,path):undefined;
|
|
127
|
+
const full=await safeFile(root,path);
|
|
128
|
+
if(literal!==undefined&&full!==literal)fail(path,'file without symlinks');
|
|
129
|
+
return full;
|
|
130
|
+
};
|
|
113
131
|
const files = new Set([...(directory?[]:[relative(root,manifestPath)]),...manifest.references.map(v=>v.path),...manifest.authoring.map(v=>v.path),...manifest.audio.clips.map(v=>v.path)]);
|
|
114
132
|
if(manifest.direction)files.add(manifest.direction);
|
|
115
133
|
if(manifest.sets)files.add(manifest.sets);
|
|
116
134
|
const rootFile=async(name:string):Promise<string|undefined>=>{try{await safeFile(root,name);return name;}catch(e){if((e as NodeJS.ErrnoException).code==='ENOENT')return undefined;throw e;}};
|
|
117
135
|
const authoringPath=(name:string):string|undefined=>{const paths=manifest.authoring.filter(v=>posix.basename(v.path)===name);return paths.length===1?paths[0].path:undefined;};
|
|
118
136
|
const rigPath=manifest.model??await rootFile('skeleton.json')??authoringPath('skeleton.json')??await rootFile('skeleton.skel')??authoringPath('skeleton.skel');
|
|
119
|
-
const motionPath=manifest.motion??await rootFile('motion.json')??authoringPath('motion.json');
|
|
137
|
+
const motionPath=sealedPlayback?undefined:manifest.motion??await rootFile('motion.json')??authoringPath('motion.json');
|
|
120
138
|
if(rigPath)files.add(rigPath);if(motionPath)files.add(motionPath);
|
|
121
139
|
let modelBytesHash:string|null=null;
|
|
122
140
|
if(manifest.model) {
|
|
123
|
-
files.add(manifest.model); const bytes=await readFile(await
|
|
141
|
+
files.add(manifest.model); const bytes=await readFile(await assetFile(manifest.model));modelBytesHash=createHash('sha256').update(bytes).digest('hex');
|
|
142
|
+
if(sealedPlayback&&modelBytesHash!==sealedPlayback.get(manifest.model))fail(manifest.model,'sealed playback hash');
|
|
143
|
+
const model = object(JSON.parse(bytes.toString('utf8')),'model');
|
|
124
144
|
if(model.spec !== 'rigc-compiled/3') fail('model.spec','rigc-compiled/3, produced by a gated rigc build');
|
|
125
145
|
if(!Array.isArray(model.pages)) fail('model.pages','array');
|
|
126
|
-
for(const page of model.pages) {
|
|
146
|
+
for(const page of model.pages) {
|
|
147
|
+
const p = object(page,'model.pages[]'); const name = string(p.name,'model.pages[].name');
|
|
148
|
+
if(isAbsolute(name)||/[:\\%?#\x00-\x1f]/.test(name)||name.split('/').some(v=>!v))fail('model.pages[].name','literal relative model page path');
|
|
149
|
+
if(sealedPlayback&&!/\.(png|jpe?g|webp)$/i.test(packagePath(name,'model.pages[].name')))fail('model.pages[].name','literal build page image');
|
|
150
|
+
files.add(packagePath(posix.join(posix.dirname(manifest.model),name),'model page resolved inside package'));
|
|
151
|
+
}
|
|
127
152
|
}
|
|
128
153
|
for(const r of manifest.references.filter(r=>r.type==='pose')) {
|
|
129
154
|
const pose=object(JSON.parse(await readFile(await safeFile(root,r.path),'utf8')),`pose ${r.id}`);
|
|
@@ -135,7 +160,8 @@ export async function loadReview(input: string, options: { handoff?: HandoffFlag
|
|
|
135
160
|
}
|
|
136
161
|
const reportPath=files.has('report.json')?'report.json':authoringPath('report.json');let report:ReportSeeds|null=null;let modelMetadata:Record<string,unknown>|null=null;let directionInput:unknown;
|
|
137
162
|
// The handoff files are hashed beside the package: their record joins the reviewed identity (and so the session file).
|
|
138
|
-
const {handoff,reason:handoffReason}=
|
|
163
|
+
const {handoff,reason:handoffReason}=options.handoff===false?{handoff:null,reason:null}:
|
|
164
|
+
await resolveHandoff(root,manifest.producer,options.handoff,{starts:options.handoffStarts??[options.cwd??process.cwd()]});
|
|
139
165
|
// #329: the source painting the handoff knows is the first reference, outside the package's own files.
|
|
140
166
|
const painting=sourcePainting(manifest,handoff,directory);
|
|
141
167
|
let scene:SceneInspection|undefined;
|
|
@@ -155,8 +181,9 @@ export async function loadReview(input: string, options: { handoff?: HandoffFlag
|
|
|
155
181
|
for(const path of sceneBytes.keys())files.add(path);
|
|
156
182
|
}
|
|
157
183
|
const hash = createHash('sha256');hash.update(JSON.stringify(manifest));hash.update('\0');const fileHashes=new Map<string,string>();
|
|
158
|
-
for(const p of [...files].sort()) { const full=await
|
|
184
|
+
for(const p of [...files].sort()) { const full=await assetFile(p); const before=await stat(full); hash.update(p);hash.update('\0');hash.update(String(before.size));hash.update('\0'); const fileHash=createHash('sha256');const metadataChunks:Buffer[]=[];const isDirection=p===manifest.direction;let bytesRead=0;
|
|
159
185
|
if(isDirection&&before.size>DIRECTION_MAX_BYTES)throw new Error('DIRECTION_SIZE: direction exceeds 256 KiB');for await(const chunk of createReadStream(full)){hash.update(chunk);fileHash.update(chunk);if(isDirection&&(bytesRead+=chunk.length)>DIRECTION_MAX_BYTES)throw new Error('DIRECTION_SIZE: direction exceeds 256 KiB');if(p===reportPath||p===manifest.model||isDirection)metadataChunks.push(chunk);}fileHashes.set(p,fileHash.digest('hex'));if(sceneBytes.has(p)&&createHash('sha256').update(sceneBytes.get(p)!).digest('hex')!==fileHashes.get(p))throw new Error('SCENE_SOURCE_MISMATCH: '+p); const after=await stat(full); if(before.size!==after.size||before.mtimeMs!==after.mtimeMs) throw new Error(`Asset ${p} changed while hashing; retry with stable package inputs`);
|
|
186
|
+
if(sealedPlayback&&fileHashes.get(p)!==sealedPlayback.get(p))fail(p,'sealed playback hash');
|
|
160
187
|
// The parser and package hash consume the same bytes, never two file reads.
|
|
161
188
|
if(p===manifest.model){if(fileHashes.get(p)!==modelBytesHash)throw new Error(`Model ${p} changed while hashing; retry with stable package inputs`);modelMetadata=object(JSON.parse(Buffer.concat(metadataChunks).toString('utf8')),'model');}
|
|
162
189
|
if(isDirection)directionInput=JSON.parse(Buffer.concat(metadataChunks).toString('utf8'));
|
|
@@ -164,7 +191,7 @@ export async function loadReview(input: string, options: { handoff?: HandoffFlag
|
|
|
164
191
|
}
|
|
165
192
|
if(painting){hash.update(SOURCE_PAINTING_ID);hash.update('\0');hash.update(painting.sha256);hash.update('\0');}
|
|
166
193
|
// #192: the root is `check/` whether the folder or its review.json was opened, so the build root is kept either way.
|
|
167
|
-
const buildRoot
|
|
194
|
+
const buildRoot=!sealedPlayback&&basename(root)==='check'&&await isBuildRoot(dirname(root))?dirname(root):undefined;
|
|
168
195
|
const reviewedSource:ReviewedSource={packageRevision:manifest.revision,...await toolVersions(),rig:rigPath?{path:rigPath,sha256:fileHashes.get(rigPath)!}:null,motion:motionPath?{path:motionPath,sha256:fileHashes.get(motionPath)!}:null,...(handoff?{handoff:handoff.record}:{})};
|
|
169
196
|
const direction=manifest.direction?readDirectionInspection(directionInput,{path:manifest.direction,sha256:fileHashes.get(manifest.direction)!},reviewedSource.rig):undefined;
|
|
170
197
|
const feedbackCatalog:FeedbackCatalog={rig:manifest.id,bones:modelNames(modelMetadata,'bones'),slots:modelNames(modelMetadata,'slots'),animations:modelAnimations(modelMetadata),clock:report?.clock??null,clockAnimation:report?.animation??null,...(discoverTurnDials(modelMetadata).length?{turnDials:discoverTurnDials(modelMetadata)}:{})};
|
|
@@ -199,7 +226,7 @@ export function loadJobReview(input: string, root: string): Promise<ReviewPackag
|
|
|
199
226
|
* adapter model paths itself (a folder that does keeps opening as before). Fixed names, no search.
|
|
200
227
|
*/
|
|
201
228
|
export async function buildCheckPackage(dir:string):Promise<string|null>{
|
|
202
|
-
for(const candidate of ['skeleton.model.json',
|
|
229
|
+
for(const candidate of ['skeleton.model.json',BUILD_MODEL_PATH]){try{await lstat(resolve(dir,candidate));return null;}catch(e){if(!['ENOENT','ENOTDIR'].includes((e as NodeJS.ErrnoException).code??''))throw e;}}
|
|
203
230
|
return await isBuildRoot(dir)?resolve(dir,'check'):null;
|
|
204
231
|
}
|
|
205
232
|
/** Same text for every command; `root` lets the open launcher name the refused input. */
|
|
@@ -207,13 +234,15 @@ export class UnrecognizedOutputError extends Error {
|
|
|
207
234
|
constructor(readonly root:string){super('Output folder: no recognized skeleton.*, build/skeleton.model.json, rig-parts build root (check/build/skeleton.model.json), motion.json, report.json, source video, pose sequence or contact strip');}
|
|
208
235
|
}
|
|
209
236
|
/** An adapter over an existing output directory; never writes a manifest there. */
|
|
210
|
-
async function folderManifest(root:string):Promise<ReviewManifest>{
|
|
237
|
+
async function folderManifest(root:string,playbackOnly=false):Promise<ReviewManifest>{
|
|
211
238
|
const entries=(await readdir(root,{withFileTypes:true})).filter(v=>v.isFile()||v.isSymbolicLink()).map(v=>v.name).sort();
|
|
239
|
+
if(playbackOnly&&entries.length)fail('output folder','build playback without top-level files');
|
|
212
240
|
const has=(name:string)=>entries.includes(name);const references:Reference[]=[];
|
|
213
|
-
|
|
241
|
+
// Sealed playback validates the fixed model through assetFile before any lookup.
|
|
242
|
+
let model:string|undefined=playbackOnly?BUILD_MODEL_PATH:undefined;
|
|
214
243
|
// These are named layouts, not a recursive search. Check existence separately
|
|
215
244
|
// so an existing broken symlink is refused rather than treated as absent.
|
|
216
|
-
for(const candidate of ['skeleton.model.json',
|
|
245
|
+
for(const candidate of playbackOnly?[]:['skeleton.model.json',BUILD_MODEL_PATH]){
|
|
217
246
|
try{await lstat(resolve(root,candidate));}catch(e){if((e as NodeJS.ErrnoException).code==='ENOENT')continue;throw e;}
|
|
218
247
|
await safeFile(root,candidate);model=candidate;break;
|
|
219
248
|
}
|
package/src/mesh-edit.ts
CHANGED
|
@@ -269,6 +269,12 @@ export function meshEditDocument(session: MeshEditSession): MeshEditDocument {
|
|
|
269
269
|
ops: session.ops(),
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
|
+
|
|
273
|
+
/** Live act payload uses the same delta as the standalone export, with its source geometry bound. */
|
|
274
|
+
export function meshEditActValue(session: MeshEditSession, frame: {width: number; height: number}) {
|
|
275
|
+
const {schema, units, preview, source, ...edit} = meshEditDocument(session);
|
|
276
|
+
return {...edit, source: {...source, frame: {...frame}, positions: session.source.vertices.map(([x, y]): Vec => [x, y])}};
|
|
277
|
+
}
|
|
272
278
|
/**
|
|
273
279
|
* The delta's bytes: what Download JSON saves and what Apply · Rebuild (#135) writes as the producer's
|
|
274
280
|
* `mesh-edit.json`, so the binding's `file.sha256` and the applied record's `deltaSha256` name the same bytes.
|
|
@@ -310,7 +316,7 @@ export function draftOps(draft: MeshEditDraft, source: MeshSource): MeshOp[] | n
|
|
|
310
316
|
const entry = draft.entries[draftKey(source)]; if (!entry || entry.hash !== source.hash) return null;
|
|
311
317
|
try { applyMeshOps(source, entry.ops); return entry.ops; } catch { return null; }
|
|
312
318
|
}
|
|
313
|
-
export function writeMeshDraft(draft: MeshEditDraft, source: MeshSource, ops: readonly MeshOp[]): string {
|
|
319
|
+
export function writeMeshDraft(draft: MeshEditDraft, source: Pick<MeshSource, 'slot' | 'skin' | 'attachment' | 'hash'>, ops: readonly MeshOp[]): string {
|
|
314
320
|
const entries = { ...draft.entries }; const key = draftKey(source);
|
|
315
321
|
if (ops.length) entries[key] = { hash: source.hash, ops: ops.map(op => structuredClone(op)) }; else delete entries[key];
|
|
316
322
|
return Object.keys(entries).length ? JSON.stringify({ schema: MESH_EDIT_DRAFT_SCHEMA, entries }) : '';
|