rig-review 4.9.1 → 4.10.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/src/job-act.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import {
3
- JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_API_V3_SCHEMA, JOB_RECORD_ACT_KINDS, JOB_RECORD_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
3
+ JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_CHEST_LANDMARKS_ACT_SCHEMA, JOB_API_V3_SCHEMA, JOB_RECORD_ACT_KINDS, JOB_RECORD_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
4
4
  type ActV3, type JobAct, type JobComment, type JobCommentsAct, type JobApiSchema, type JobPendingAsk, type JobPublicationMode, type JobReviewerBinding,
5
5
  type JobSourceBinding, type JobSubject, type JobUISubmission, type JobRigCapture, type JobRigStill,
6
6
  type JobMeshEdit, type PendingAskV3, type RecordAct, type RecordSource, type RecordSubject, type SourceV3, type UISubmissionV3,
7
7
  type JobCommentContext, type JobContextComment,
8
+ type JobChestLandmarkEdit,
8
9
  } from './job-contract.ts';
9
10
  import { parsePartsIssue, type PartsIssue } from './parts-comment.ts';
10
11
  import {
11
- isRecordSource, jobHash, jobId, jobInteger, jobObject,
12
- commentsActForEmission, meshEditsActForEmission, parseCommentsAct, parseMeshEdits, parseRecordAct, parseRecordSource, requestDigest, validateRecordAskSubject,
12
+ isRecordSource, isRigDraftVerdictSource, parseJobSelector, jobHash, jobId, jobInteger, jobObject,
13
+ commentsActForEmission, meshEditsActForEmission, parseCommentsAct, parseMeshEdits, parseRecordAct, parseRecordSource, recordActSource, requestDigest, validateRecordAskSubject,
14
+ chestLandmarkIdentity, parseChestLandmarkEdits, parseChestLandmarksAct,
13
15
  } from './job-api.ts';
14
16
  import { checkpointNoteComments, feedbackItemComments, noteComments, partsIssueComments } from './feedback-export.ts';
15
17
  import { hasStageComment, parseStageComment } from './stage-comment.ts';
@@ -17,6 +19,8 @@ import type { Feedback } from './session.ts';
17
19
  import { validatePicks } from './interview-picks.ts';
18
20
  import {
19
21
  isRetainedRecordSource,
22
+ readJobEditMesh,
23
+ readJobEditModel,
20
24
  type JobRetainedRecordSource,
21
25
  type JobRetainedSource,
22
26
  type JobRetainedSourceV3,
@@ -24,8 +28,8 @@ import {
24
28
  import { JobError } from './job-store.ts';
25
29
  import { checkedPath, readRegular } from './interview-project.ts';
26
30
  import {validatePngBytes} from './comment-crops.ts';
27
- import {applyMeshOps, attachmentHashText, MESH_EDIT_CODES} from './mesh-edit.ts';
28
- import {readStoredSetupMesh} from './setup-mesh.ts';
31
+ import {applyMeshOps} from './mesh-edit.ts';
32
+ import {deriveBust} from './chest-landmarks.ts';
29
33
 
30
34
  function words(value: unknown): string {
31
35
  if (typeof value !== 'string' || value.length > 10_000) throw new JobError('JOB_ACT_INVALID');
@@ -52,36 +56,14 @@ function rigVerdictFeedbackComments(feedback: readonly Feedback[], subject: NonN
52
56
  });
53
57
  }
54
58
 
55
- function hasMeshSubmission(kind: unknown, value: unknown): boolean {
56
- if (value === null || typeof value !== 'object' || !Object.hasOwn(value, 'meshEdits')) return false;
57
- const {stage, verdict} = value as {stage?: unknown; verdict?: unknown};
58
- if (kind !== 'review-verdict' || stage !== 'rig-review' || verdict !== 'changes-requested') {
59
- throw new JobError('JOB_ACT_INVALID');
60
- }
61
- return true;
62
- }
63
-
64
- function validateRetainedMeshEdits(retained: JobRetainedSource, edits: readonly JobMeshEdit[]): void {
65
- const binding = retained.source.model;
66
- if (!binding) throw new JobError('JOB_ACT_SOURCE_STALE');
67
- let model: {stage?: {width?: number; height?: number}};
68
- try {
69
- const bytes = readRegular(checkedPath(retained.snapshotRoot, binding.path), 64 * 1024 * 1024);
70
- if (jobHash(bytes) !== binding.sha256) throw new Error('model hash differs');
71
- model = JSON.parse(bytes.toString('utf8'));
72
- } catch {
73
- throw new JobError('JOB_ACT_SOURCE_STALE');
74
- }
59
+ function validateRetainedMeshEdits(model: ReturnType<typeof readJobEditModel>, edits: readonly JobMeshEdit[]): void {
75
60
  for (const {edit} of edits) {
76
- const read = readStoredSetupMesh(model, edit.slot, edit, MESH_EDIT_CODES);
77
- if (!read.ok || jobHash(attachmentHashText(read.mesh.entry)) !== edit.source.hash) throw new JobError('JOB_ACT_SOURCE_STALE');
78
- const {mesh} = read;
79
- const {frame, positions, vertexCount, triangleCount, hullLength, hash} = edit.source;
61
+ const mesh = readJobEditMesh(model, edit, 'JOB_ACT_SOURCE_STALE', 'JOB_ACT_INVALID');
62
+ const {positions, vertexCount, triangleCount, hullLength, hash} = edit.source;
80
63
  const uvs = mesh.entry.uvs;
81
- if (mesh.linked || !Array.isArray(uvs) || uvs.length !== vertexCount * 2 ||
64
+ if (!Array.isArray(uvs) || uvs.length !== vertexCount * 2 ||
82
65
  mesh.vertices.length !== vertexCount || positions.length !== vertexCount ||
83
- mesh.triangles.length !== triangleCount * 3 || mesh.hull !== hullLength ||
84
- model.stage?.width !== frame.width || model.stage?.height !== frame.height) {
66
+ mesh.triangles.length !== triangleCount * 3 || mesh.hull !== hullLength) {
85
67
  throw new JobError('JOB_ACT_INVALID');
86
68
  }
87
69
  try {
@@ -93,6 +75,20 @@ function validateRetainedMeshEdits(retained: JobRetainedSource, edits: readonly
93
75
  }
94
76
  }
95
77
 
78
+ function validateRetainedChestLandmarks(retained: JobRetainedSource, model: ReturnType<typeof readJobEditModel>,
79
+ edits: readonly JobChestLandmarkEdit[]): void {
80
+ const seeds = new Set(retained.chestLandmarks?.map(chestLandmarkIdentity));
81
+ for (const {edit} of edits) {
82
+ readJobEditMesh(model, edit, 'JOB_ACT_SOURCE_STALE', 'JOB_ACT_INVALID');
83
+ if (!seeds.has(chestLandmarkIdentity(edit))) throw new JobError('JOB_ACT_INVALID');
84
+ const {cleavage} = edit.bust;
85
+ if (cleavage) {
86
+ const {refusal} = deriveBust({...edit.bust, cleavage});
87
+ if (refusal) throw new JobError('JOB_ACT_INVALID', refusal);
88
+ }
89
+ }
90
+ }
91
+
96
92
  function generalComments(value: unknown): JobComment[] {
97
93
  if (value === undefined) return [];
98
94
  if (!Array.isArray(value)) throw new JobError('JOB_ACT_INVALID');
@@ -126,10 +122,12 @@ export function bindJobRecordAsk(subject: unknown, retained: JobRetainedRecordSo
126
122
  const question = retained.questions.find(
127
123
  item => item.editable && item.set.question === parsedSubject.questionId && item.set.id === parsedSubject.setId,
128
124
  );
125
+ // #1004: each set is bound by its own `optionSets` row; one set keeps the singular fields.
126
+ const bound = source.optionSets?.find(row => row.questionId === parsedSubject.questionId && row.setId === parsedSubject.setId) ?? source;
129
127
  if (
130
128
  !question ||
131
- question.ref.path !== source.optionSetFile.path ||
132
- question.ref.sha256 !== source.optionSet.sha256
129
+ question.ref.path !== bound.optionSetFile.path ||
130
+ question.ref.sha256 !== bound.optionSet.sha256
133
131
  ) {
134
132
  throw new JobError('JOB_ASK_INVALID');
135
133
  }
@@ -151,13 +149,8 @@ export function bindJobRecordAsk(subject: unknown, retained: JobRetainedRecordSo
151
149
  }
152
150
  return source;
153
151
  }
154
- case 'reopen': {
155
- if (source.subject !== 'plan') {
156
- throw new JobError('JOB_ASK_INVALID');
157
- }
158
- return source;
159
- }
160
152
  }
153
+ throw new JobError('JOB_ASK_INVALID');
161
154
  }
162
155
 
163
156
  export function bindJobAsk(subject: JobSubject, retained: JobRetainedSource): JobSourceBinding;
@@ -186,6 +179,14 @@ export function bindJobAsk(subject: JobSubject | RecordSubject, retained: JobRet
186
179
  source.selector.id !== subject.draftId || !retained.partIds.length) throw new JobError('JOB_ASK_INVALID');
187
180
  return source;
188
181
  case 'review-verdict':
182
+ if (source.selector?.kind === 'draft') {
183
+ try { parseJobSelector(source.selector); }
184
+ catch { throw new JobError('JOB_ASK_INVALID', subject.stage); }
185
+ if (subject.stage !== 'rig-review' || !declared || !isRigDraftVerdictSource(source)) {
186
+ throw new JobError('JOB_ASK_INVALID', subject.stage);
187
+ }
188
+ return source;
189
+ }
189
190
  if (subject.stage === 'image-review' || !source.model || (subject.stage === 'rig-review' ? source.selector?.kind !== 'rig' :
190
191
  source.selector?.kind !== 'post' || !source.direction)) throw new JobError('JOB_ASK_INVALID');
191
192
  return source;
@@ -422,7 +423,8 @@ export function prepareJobRecordAct(options: {
422
423
  return parseRecordAct({
423
424
  ...envelope,
424
425
  kind: 'interview-picks',
425
- source: boundSource,
426
+ // #1004: the act's singular set fields name this ask's set.
427
+ source: recordActSource(boundSource, askSubject),
426
428
  value: { questionId: askSubject.questionId, selections, note },
427
429
  });
428
430
  }
@@ -472,27 +474,8 @@ export function prepareJobRecordAct(options: {
472
474
  },
473
475
  });
474
476
  }
475
- case 'reopen': {
476
- if (boundSource.subject !== 'plan') throw new JobError('JOB_ACT_SOURCE_STALE');
477
- const value = actObject(submission.value, ['stage', 'words']);
478
- if (
479
- !('stage' in value) ||
480
- !('words' in value) ||
481
- value.stage !== askSubject.stage
482
- ) {
483
- throw new JobError('JOB_ACT_INVALID');
484
- }
485
- return parseRecordAct({
486
- ...envelope,
487
- kind: 'reopen',
488
- source: boundSource,
489
- value: {
490
- stage: askSubject.stage,
491
- words: words(value.words),
492
- },
493
- });
494
- }
495
477
  }
478
+ throw new JobError('JOB_ACT_INVALID');
496
479
  }
497
480
 
498
481
  /** Only the authenticated UI host invokes this adapter. All source and authority
@@ -536,9 +519,12 @@ export function finalizeJobAct(options: {
536
519
  readonly actId?: string;
537
520
  readonly at?: string;
538
521
  }): ActV3 {
539
- const meshSubmission = hasMeshSubmission(options.submission.kind, options.submission.value);
540
- if (meshSubmission && (isRetainedRecordSource(options.retained) ||
541
- options.ask.subject.kind !== 'review-verdict' || options.ask.subject.stage !== 'rig-review')) {
522
+ const {kind, value} = options.submission;
523
+ const meshSubmission = !!value && typeof value === 'object' && Object.hasOwn(value, 'meshEdits');
524
+ const chestSubmission = !!value && typeof value === 'object' && Object.hasOwn(value, 'chestLandmarks');
525
+ if ((meshSubmission || chestSubmission) && (kind !== 'review-verdict' ||
526
+ (value as {stage?: unknown}).stage !== 'rig-review' || (value as {verdict?: unknown}).verdict !== 'changes-requested' ||
527
+ isRetainedRecordSource(options.retained) || options.ask.subject.kind !== 'review-verdict' || options.ask.subject.stage !== 'rig-review')) {
542
528
  throw new JobError('JOB_ACT_INVALID');
543
529
  }
544
530
  if (isRetainedRecordSource(options.retained)) {
@@ -553,7 +539,6 @@ export function finalizeJobAct(options: {
553
539
  at: options.at,
554
540
  });
555
541
  }
556
- if ((options.submission.kind as string) === 'reopen') throw new JobError('JOB_ACT_INVALID');
557
542
  const { submission, ask, retained, reviewer } = options as {
558
543
  readonly jobId: string;
559
544
  readonly submission: JobUISubmission;
@@ -658,19 +643,21 @@ export function finalizeJobAct(options: {
658
643
  }
659
644
  case 'review-verdict': {
660
645
  const value = jobObject(submission.value, ['stage', 'verdict', 'words',
661
- ...(ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review' ? ['feedback', 'general', 'meshEdits'] : [])]);
646
+ ...(ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review' ? ['feedback', 'general', 'meshEdits', 'chestLandmarks'] : [])]);
662
647
  if (ask.subject.kind !== 'review-verdict' || ask.subject.stage === 'image-review' || value.stage !== ask.subject.stage) throw new JobError('JOB_ACT_INVALID');
663
648
  if (ask.subject.stage === 'rig-review') {
664
649
  const verdict = choice(value.verdict, ['pending', 'approved', 'changes-requested'] as const);
665
- let meshEdits: readonly JobMeshEdit[] | undefined;
666
- if (meshSubmission) {
667
- meshEdits = parseMeshEdits(value.meshEdits);
668
- validateRetainedMeshEdits(retained, meshEdits);
650
+ const meshEdits = meshSubmission ? parseMeshEdits(value.meshEdits) : undefined;
651
+ const chestLandmarks = chestSubmission ? parseChestLandmarkEdits(value.chestLandmarks) : undefined;
652
+ if (meshEdits || chestLandmarks) {
653
+ const model = readJobEditModel(retained.snapshotRoot, source.model, 'JOB_ACT_SOURCE_STALE');
654
+ if (meshEdits) validateRetainedMeshEdits(model, meshEdits);
655
+ if (chestLandmarks) validateRetainedChestLandmarks(retained, model, chestLandmarks);
669
656
  }
670
657
  if (!options.still) throw new JobError('JOB_STILL_CAPTURE_FAILED');
671
658
  const note = words(value.words);
672
659
  if (value.feedback !== undefined && !Array.isArray(value.feedback)) throw new JobError('JOB_ACT_INVALID');
673
- const selector = source.selector as Extract<NonNullable<JobSourceBinding['selector']>, {kind: 'rig'}>;
660
+ const selector = source.selector as Extract<NonNullable<JobSourceBinding['selector']>, {kind: 'rig' | 'draft'}>;
674
661
  let verdictComments: readonly JobContextComment[];
675
662
  try {
676
663
  verdictComments = value.feedback === undefined ? noteComments(note) : rigVerdictFeedbackComments(value.feedback as Feedback[],
@@ -680,6 +667,8 @@ export function finalizeJobAct(options: {
680
667
  source: {...source, model: source.model!, selector},
681
668
  value: {stage: 'rig-review' as const, verdict, comments: [...verdictComments, ...generalComments(value.general)]},
682
669
  still: options.still};
670
+ if (chestLandmarks) return parseChestLandmarksAct({...act, schema: JOB_CHEST_LANDMARKS_ACT_SCHEMA,
671
+ value: {...act.value, ...(meshEdits ? {meshEdits} : {}), chestLandmarks}});
683
672
  if (meshEdits) return meshEditsActForEmission({...act, value: {...act.value, meshEdits}});
684
673
  if (verdictComments.some(comment => Object.hasOwn(comment, 'context'))) return commentsActForEmission(act);
685
674
  return commentsAct(act);