@rig-c/review 2.4.2 → 2.4.4

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.
@@ -1001,13 +1001,15 @@ the compiled sliders available through the Turn Pad and the attachment sets
1001
1001
  loaded through Play. Independent depth control is unavailable on this surface.
1002
1002
 
1003
1003
  A manifest may declare `direction` as the literal package-relative path to a
1004
- retained Create `rig-create/direction@1` document (up to 256 KiB). Preserve the
1005
- document's model path relative to the Review package root. Review requires that
1006
- path and SHA-256 to match the inspected compiled model and includes the direction
1007
- file in the package source hash. The panel shows authored camera keys and timing
1008
- read-only while that inspected model is on stage. Create remains responsible
1009
- for validating project history and citations. Viewport pan and zoom affect only
1010
- inspection. Authored camera playback and camera Apply are unavailable.
1004
+ retained Create `rig-create/direction@1` or `rig-create/direction@2` document
1005
+ (up to 256 KiB). A `direction@2` scene reference is accepted but not inspected.
1006
+ Preserve the document's model path relative to the Review package root. Review
1007
+ requires that path and SHA-256 to match the inspected compiled model and
1008
+ includes the direction file in the package source hash. The panel shows authored
1009
+ camera keys and timing read-only while that inspected model is on stage. Create
1010
+ remains responsible for validating project history and citations. Viewport pan
1011
+ and zoom affect only inspection. Authored camera playback and camera Apply are
1012
+ unavailable.
1011
1013
 
1012
1014
  The optional `sets` manifest path names a package-local Play attachment-set
1013
1015
  sidecar for the inspected single-package build. Review includes it in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/review",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "type": "module",
5
5
  "description": "Local human rig inspection and structured feedback export",
6
6
  "license": "MIT",
@@ -18,10 +18,15 @@ export interface DirectionInspection {
18
18
  timing: { time: number; source_time: number; easing: string }[];
19
19
  }
20
20
 
21
- /** Read the inspection subset of Create's direction@1. Create validates project history and citations. */
21
+ /**
22
+ * Read the inspection subset of Create's rig-create/direction@1 or rig-create/direction@2.
23
+ * A direction@2 scene reference is accepted but not inspected.
24
+ * Create validates scene, project history and citations.
25
+ */
22
26
  export function readDirectionInspection(value: unknown, file: Binding, model: Binding | null): DirectionInspection {
23
27
  const doc = object(value, 'direction');
24
- if (doc.schema !== 'rig-create/direction@1') throw new Error('DIRECTION_SCHEMA: expected rig-create/direction@1');
28
+ if (doc.schema !== 'rig-create/direction@1' && doc.schema !== 'rig-create/direction@2')
29
+ throw new Error('DIRECTION_SCHEMA: expected rig-create/direction@1 or rig-create/direction@2');
25
30
  const rig = object(doc.rig, 'direction.rig');
26
31
  const binding = object(rig.model, 'direction.rig.model');
27
32
  const path = packagePath(binding.path, 'direction.rig.model.path');
@@ -344,8 +344,6 @@ export class JobSession {
344
344
  current = this.current();
345
345
  let result: unknown;
346
346
  this.store.update(this.jobId, current.revision, fresh => {
347
- const raced = this.replay(fresh.data, key, digest);
348
- if (raced) { result = raced.value; return { data: fresh.data }; }
349
347
  this.active(fresh, input.expectedGeneration);
350
348
  const data = fresh.data;
351
349
  let snapshot: JobSnapshotOwner | undefined;
@@ -382,6 +380,11 @@ export class JobSession {
382
380
  }
383
381
  data.replays[key] = { digest, value: result };
384
382
  return { data, ...(snapshot ? {snapshot} : {}) };
383
+ }, fresh => {
384
+ const raced = this.replay(fresh.data, key, digest);
385
+ if (!raced) return false;
386
+ result = raced.value;
387
+ return true;
385
388
  });
386
389
  this.notify();
387
390
  return result;
@@ -416,7 +419,7 @@ export class JobSession {
416
419
  const previous = this.replay(current.data, key, digest);
417
420
  if (previous) return previous.value as JobAct;
418
421
  let act: JobAct;
419
- this.store.update(this.jobId, current.revision, fresh => {
422
+ this.store.update(this.jobId, null, fresh => {
420
423
  // UI captures an observed generation. Unrelated asks may advance it while
421
424
  // this same ask/source/publication/nonce stays valid. Agent mutation CAS
422
425
  // remains global. Future UI generations cannot describe a displayed state.
@@ -438,6 +441,11 @@ export class JobSession {
438
441
  fresh.data.replays[key] = { digest, value: act };
439
442
  this.event(fresh.data, { type: 'act', act } as Omit<JobEvent, 'cursor' | 'jobId' | 'generation'>);
440
443
  return { data: fresh.data };
444
+ }, fresh => {
445
+ const raced = this.replay(fresh.data, key, digest);
446
+ if (!raced) return false;
447
+ act = raced.value as JobAct;
448
+ return true;
441
449
  });
442
450
  this.notify();
443
451
  return act!;
package/src/job-store.ts CHANGED
@@ -199,16 +199,19 @@ export class JobStore<Data> {
199
199
 
200
200
  /** Re-read under the write transaction. A callback failure rolls everything
201
201
  * back. A successful callback publishes its complete data and replay receipt
202
- * together. Closing releases the active-root slot in the same commit.
202
+ * together. A durable replay returns before CAS without rewriting the row.
203
+ * A null revision delegates freshness to the UI's in-transaction predicates.
204
+ * Closing releases the active-root slot in the same commit.
203
205
  */
204
- update(jobId: string, expectedRevision: number, operation: (current: StoredJob<Data>) => {
206
+ update(jobId: string, expectedRevision: number | null, operation: (current: StoredJob<Data>) => {
205
207
  readonly data: Data;
206
208
  readonly active?: boolean;
207
209
  readonly snapshot?: JobSnapshotOwner;
208
- }): StoredJob<Data> {
210
+ }, replay?: (current: StoredJob<Data>) => boolean): StoredJob<Data> {
209
211
  return this.transaction(() => {
210
212
  const current = this.get(jobId);
211
- if (current.revision !== expectedRevision) throw new JobError('JOB_GENERATION_STALE');
213
+ if (replay?.(current)) return current;
214
+ if (expectedRevision !== null && current.revision !== expectedRevision) throw new JobError('JOB_GENERATION_STALE');
212
215
  const next = operation(current);
213
216
  const active = next.active ?? current.active;
214
217
  const document = encode(next.data);
package/src/parts-view.ts CHANGED
@@ -104,11 +104,14 @@ export async function insideRoot(root: string, path: string, code: string, what:
104
104
  return real;
105
105
  }
106
106
 
107
- async function hashFile(abs: string): Promise<LocalFile> {
108
- const bytes = await readFile(abs);
107
+ function hashBytes(abs: string, bytes: Buffer): LocalFile {
109
108
  return { abs, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') };
110
109
  }
111
110
 
111
+ async function hashFile(abs: string): Promise<LocalFile> {
112
+ return hashBytes(abs, await readFile(abs));
113
+ }
114
+
112
115
  /** A part name is a file stem under `parts/`: no separators, no traversal. */
113
116
  function partFileName(name: string): string {
114
117
  if (!name || name === '.' || name === '..' || /[/\\\x00-\x1f]/.test(name)) refuse('PARTS_NAME_INVALID', `part name ${JSON.stringify(name)} is not a file name under parts/`);
@@ -230,8 +233,13 @@ export function checkReadings(doc: unknown, names: ReadonlySet<string>): Produce
230
233
  return labelled ? rows : checkFlags(doc, names).map(f => ({...f, classification:'unclassified' as const, ...(f.kind === 'check' ? {line:JSON.stringify(f.entry)} : {})}));
231
234
  }
232
235
 
233
- async function readJson(abs: string, what: string): Promise<unknown> {
234
- try { return JSON.parse(await readFile(abs, 'utf8')); } catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
236
+ function parseJson(bytes: Buffer, what: string): unknown {
237
+ try { return JSON.parse(bytes.toString('utf8')); } catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
238
+ }
239
+
240
+ async function readJsonBytes(abs: string, what: string): Promise<{ bytes: Buffer; value: unknown }> {
241
+ try { const bytes = await readFile(abs); return { bytes, value: JSON.parse(bytes.toString('utf8')) }; }
242
+ catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
235
243
  }
236
244
 
237
245
  /**
@@ -239,8 +247,9 @@ async function readJson(abs: string, what: string): Promise<unknown> {
239
247
  * writes `mesh_report.json` beside `parts.json` in `rig/`, and `check` writes `check/check.json` beside `rig/`.
240
248
  * `rigDir` is that `rig/` directory (parts mode) or null (atlas mode: explicit paths only, or `buildRoot`'s files).
241
249
  */
242
- async function producerFlags(rigDir: string | null, buildRoot: string | null, names: ReadonlySet<string>, options: PartsViewOptions): Promise<{ flags: ProducerFlag[]; readings: ProducerFlag[]; files: LocalFile[]; notes: string[] }> {
250
+ async function producerFlags(rigDir: string | null, buildRoot: string | null, names: ReadonlySet<string>, options: PartsViewOptions): Promise<{ flags: ProducerFlag[]; readings: ProducerFlag[]; files: LocalFile[]; notes: string[]; meshReport: unknown }> {
243
251
  const flags: ProducerFlag[] = [], readings: ProducerFlag[] = [], files: LocalFile[] = [], notes: string[] = [];
252
+ let meshReport: unknown = null;
244
253
  // A discovered file must resolve inside the directory it was discovered in; a path given on the command line is the user's own choice.
245
254
  const pick = async (explicit: string | undefined, candidates: ([string, string] | null)[], what: string): Promise<string | null> => {
246
255
  if (explicit !== undefined) return realpath(resolve(explicit));
@@ -248,12 +257,12 @@ async function producerFlags(rigDir: string | null, buildRoot: string | null, na
248
257
  return found ? insideRoot(found[0], found[1], 'PARTS_FLAGS_OUTSIDE', what) : null;
249
258
  };
250
259
  const mesh = await pick(options.meshReport, [rigDir ? [rigDir, join(rigDir, 'mesh_report.json')] : null, buildRoot ? [buildRoot, join(buildRoot, 'rig', 'mesh_report.json')] : null], 'mesh_report.json');
251
- if (mesh) { files.push(await hashFile(mesh)); flags.push(...meshReportFlags(await readJson(mesh, 'mesh_report.json'), names)); }
260
+ if (mesh) { const bytes = await readFile(mesh); files.push(hashBytes(mesh, bytes)); meshReport = parseJson(bytes, 'mesh_report.json'); flags.push(...meshReportFlags(meshReport, names)); }
252
261
  else notes.push('mesh_report.json');
253
262
  const check = await pick(options.check, [rigDir ? [dirname(rigDir), join(dirname(rigDir), 'check', 'check.json')] : null, buildRoot ? [buildRoot, join(buildRoot, 'check', 'check.json')] : null], 'check/check.json');
254
- if (check) { files.push(await hashFile(check)); const doc = await readJson(check, 'check.json'); flags.push(...checkFlags(doc, names)); readings.push(...checkReadings(doc, names)); }
263
+ if (check) { const bytes = await readFile(check); files.push(hashBytes(check, bytes)); const doc = parseJson(bytes, 'check.json'); flags.push(...checkFlags(doc, names)); readings.push(...checkReadings(doc, names)); }
255
264
  else notes.push('check.json');
256
- return { flags, readings, files, notes };
265
+ return { flags, readings, files, notes, meshReport };
257
266
  }
258
267
 
259
268
  /** Exact attachment identity and UV-derived geometry; never reconstruct through weights. */
@@ -322,12 +331,13 @@ async function locateMeshRasters(rig: unknown, root: string, items: ViewItem[],
322
331
 
323
332
  async function loadPartsMode(root: string, options: PartsViewOptions): Promise<PartsViewPackage> {
324
333
  const partsJson = await insideRoot(root, join(root, 'parts.json'), 'PARTS_FILE_OUTSIDE', 'parts.json');
325
- const doc = record(await readJson(partsJson, 'parts.json'));
334
+ const { bytes: partsBytes, value: partsRaw } = await readJsonBytes(partsJson, 'parts.json');
335
+ const doc = record(partsRaw);
326
336
  const list = doc?.parts;
327
337
  if (!doc || !Array.isArray(list)) return refuse('PARTS_JSON_MALFORMED', 'parts.json has no parts[] array');
328
338
  const size = doc.rig_size;
329
339
  const rigSize: [number, number] | null = Array.isArray(size) && size.length === 2 && finite(size[0], 1) && finite(size[1], 1) ? [size[0], size[1]] : null;
330
- const items: ViewItem[] = [], imagePaths: string[] = [], files: LocalFile[] = [await hashFile(partsJson)];
340
+ const items: ViewItem[] = [], imagePaths: string[] = [], files: LocalFile[] = [hashBytes(partsJson, partsBytes)];
331
341
  const seen = new Set<string>();
332
342
  for (const [index, raw] of list.entries()) {
333
343
  const p = record(raw);
@@ -337,7 +347,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
337
347
  seen.add(part.name);
338
348
  const abs = join(root, 'parts', partFileName(part.name));
339
349
  if (!existsSync(abs)) refuse('PARTS_IMAGE_MISSING', `parts/${part.name}.png is named in parts.json and is not on disk`);
340
- // Hashed and served by its real path, so a link swapped after load cannot redirect what the page is shown.
350
+ // Resolved to its current real path inside root before hashing; full path-replacement pinning stays tracked in #479.
341
351
  const real = await insideRoot(root, abs, 'PARTS_IMAGE_OUTSIDE', `parts/${part.name}.png`);
342
352
  files.push(await hashFile(real));
343
353
  imagePaths.push(real);
@@ -368,7 +378,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
368
378
  assertOriginalPaintingSize(png!.width,png!.height,rigSize,doc.scale_rig_per_source);
369
379
  const file={abs:abs!,bytes:bytes!.length,sha256:createHash('sha256').update(bytes!).digest('hex')};painting={...file,width:png!.width,height:png!.height};files.push(file);
370
380
  }
371
- const { flags, readings, files: flagFiles, notes } = await producerFlags(root, null, seen, options);
381
+ const { flags, readings, files: flagFiles, notes, meshReport } = await producerFlags(root, null, seen, options);
372
382
  const protectedPaths = [join(root, 'rig.json'), join(root, 'config.json'), join(root, 'review.json'), join(root, 'report.json')];
373
383
  if (basename(root) === 'rig') protectedPaths.push(...['parts.json', 'config.json', 'review.json', 'report.json'].map(name => join(dirname(root), name)));
374
384
  if (options.rig !== undefined) protectedPaths.push(resolve(options.rig));
@@ -381,7 +391,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
381
391
  let rig: unknown;
382
392
  try { rig = JSON.parse(rigBytes.toString('utf8')); }
383
393
  catch (e) { return refuse('PARTS_MESH_MALFORMED', `rig.json: ${e instanceof Error ? e.message : String(e)}`); }
384
- readPartMeshes(rig, items, report ? await readJson(report.abs, 'mesh_report.json') : null);
394
+ readPartMeshes(rig, items, report ? meshReport : null);
385
395
  await locateMeshRasters(rig, dirname(rigPath), items, imagePaths, files);
386
396
  // Bind exactly the bytes parsed above, even if the path is replaced during raster checks.
387
397
  files.push({ abs: rigPath, bytes: rigBytes.length, sha256: createHash('sha256').update(rigBytes).digest('hex') });
@@ -402,10 +412,11 @@ export async function loadPartsAtlas(p: ReviewPackage, options: PartsViewOptions
402
412
  const modelPath = p.manifest.model;
403
413
  if (!modelPath) return refuse('PARTS_VIEW_NO_ATLAS', `The inspected package holds no compiled model with pages`);
404
414
  const modelAbs = await safeFile(p.root, modelPath);
405
- const model = record(JSON.parse(await readFile(modelAbs, 'utf8')));
415
+ const modelBytes = await readFile(modelAbs);
416
+ const model = record(JSON.parse(modelBytes.toString('utf8')));
406
417
  const pagesRaw = model?.pages;
407
418
  if (!Array.isArray(pagesRaw)) return refuse('PARTS_VIEW_NO_ATLAS', `${modelPath} declares no pages`);
408
- const pages: ViewPage[] = [], pagePaths: string[] = [], items: ViewItem[] = [], files: LocalFile[] = [await hashFile(modelAbs)];
419
+ const pages: ViewPage[] = [], pagePaths: string[] = [], items: ViewItem[] = [], files: LocalFile[] = [hashBytes(modelAbs, modelBytes)];
409
420
  const names = new Set<string>();
410
421
  for (const raw of pagesRaw) {
411
422
  const page = record(raw);