@rig-c/review 4.9.1 → 4.11.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.
Files changed (51) hide show
  1. package/docs/DESIGN.md +5 -5
  2. package/docs/PANELS.md +3 -1
  3. package/docs/REVIEW_PACKAGE.md +143 -30
  4. package/docs/STABILITY.md +110 -3
  5. package/package.json +2 -2
  6. package/src/chest-landmarks.ts +9 -4
  7. package/src/cloth-recipe.ts +27 -7
  8. package/src/compare-html.ts +1 -1
  9. package/src/feedback-export.ts +2 -2
  10. package/src/feedback-validation.ts +11 -6
  11. package/src/frame-clock.ts +20 -4
  12. package/src/job-act.ts +60 -71
  13. package/src/job-api.ts +302 -46
  14. package/src/job-checkpoint-evidence.ts +17 -0
  15. package/src/job-cli.ts +3 -2
  16. package/src/job-contract.ts +107 -7
  17. package/src/job-front.ts +48 -12
  18. package/src/job-host.ts +7 -1
  19. package/src/job-session.ts +136 -26
  20. package/src/job-source.ts +133 -21
  21. package/src/job-store.ts +7 -4
  22. package/src/manifest.ts +59 -7
  23. package/src/open-workspace-state.ts +6 -1
  24. package/src/open.ts +3 -3
  25. package/src/rebuild.ts +42 -10
  26. package/src/session.ts +9 -4
  27. package/src/stage-comment.ts +2 -1
  28. package/web/catalog-en.ts +31 -6
  29. package/web/catalog-ko.ts +79 -54
  30. package/web/chest-editor.ts +236 -31
  31. package/web/cloth-panel.ts +1 -1
  32. package/web/compare.css +2 -2
  33. package/web/environment-world.ts +9 -0
  34. package/web/i18n.ts +1 -3
  35. package/web/inspection-persistence.ts +19 -6
  36. package/web/interview-panel.ts +13 -80
  37. package/web/job-rig-screen.ts +65 -37
  38. package/web/job-session.ts +204 -64
  39. package/web/label-placement.ts +25 -8
  40. package/web/main.ts +350 -114
  41. package/web/part-selection.ts +2 -1
  42. package/web/parts-viewport-provider.ts +21 -8
  43. package/web/rebuild-client.ts +3 -5
  44. package/web/rig-host.ts +5 -4
  45. package/web/rig-overlays.ts +3 -2
  46. package/web/rig-viewport-provider.ts +10 -6
  47. package/web/stage-comments.ts +24 -21
  48. package/web/styles.css +23 -51
  49. package/web/viewport-controller.ts +4 -0
  50. package/web/workspace-layout.ts +4 -4
  51. package/web/workspace-ui.ts +8 -6
package/src/job-api.ts CHANGED
@@ -1,20 +1,21 @@
1
- import {checkpointEvidenceFields} from './job-checkpoint-evidence.ts';
1
+ import {checkpointEvidenceFields, planPictureFields} from './job-checkpoint-evidence.ts';
2
2
  import {previousDraftFields} from './job-previous-draft.ts';
3
3
  import { createHash, timingSafeEqual } from 'node:crypto';
4
4
  import {
5
5
  JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ENABLED_ACT_KINDS, JOB_PARTS_ENUMERATOR_RANGE,
6
6
  JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RECORD_SIGNOFF_STAGES, JOB_RECORD_ACT_SCHEMA, JOB_RECORD_INSTANCE_SCHEMA, JOB_RECORD_SOURCE_SCHEMA,
7
7
  JOB_RESERVED_ACT_KINDS,
8
- JOB_MESH_EDITS_ACT_SCHEMA,
8
+ JOB_MESH_EDITS_ACT_SCHEMA, JOB_CHEST_LANDMARKS_ACT_SCHEMA,
9
9
  type AgentRequestV3, type FetchActRequestV3, type JobAgentRequest, type JobApiSchema,
10
10
  type JobCheckpointEvidence, type JobDisplayAcknowledgment, type JobErrorCode, type JobFetchActRequest, type JobFileIdentity,
11
- type JobHostPorts, type JobHumanAuthority, type JobInterviewDiagnostic, type JobInterviewDiagnostics,
11
+ type JobHostPorts, type JobHumanAuthority, type JobInterviewDiagnostic, type JobInterviewDiagnostics, type JobProgressRequestV3,
12
12
  type JobInterviewJson, type JobInterviewRecord, type JobPlanIdentity, type JobPublicationMode,
13
13
  type JobAct, type JobMeshEdit, type JobMeshEditsAct, type JobMeshEditValue,
14
- type JobPublishRequest, type JobResult, type JobSelector, type JobSha256, type JobSubject,
14
+ type JobChestLandmarkEdit, type JobChestLandmarksAct, type JobChestLandmarkValue, type JobPublishedChestLandmark,
15
+ type JobPublishRequest, type JobResult, type JobSelector, type JobSha256, type JobSourceBinding, type JobSubject,
15
16
  type OptionContext, type OptionSource, type PlanContext, type PlanSource, type ProjectRecord,
16
17
  type PublishRequestV3, type PublishResultV3, type RecordAct, type RecordFreeze,
17
- type RecordOptionResult, type RecordPartsIdentity, type RecordPicksSubject, type RecordPlanResult, type RecordPlanSubject,
18
+ type RecordOptionResult, type RecordOptionSetBinding, type RecordOptionSetRef, type RecordPartsIdentity, type RecordPicksSubject, type RecordPlanResult, type RecordPlanSubject,
18
19
  type RecordResult, type RecordSignoffStage, type RecordSource, type RecordSubject,
19
20
  jobCaptureBodyLimit, jobRawActMediaType,
20
21
  } from './job-contract.ts';
@@ -31,6 +32,7 @@ import {parseJobPartsIdentity} from './job-source.ts';
31
32
  import {parseControlPart, parseControlView} from './control.ts';
32
33
  import {canonicalJson} from './canonical-json.ts';
33
34
  import {MESH_EDIT_MAX_OPS, type Vec} from './mesh-edit.ts';
35
+ import {parseBustSpec} from './chest-landmarks.ts';
34
36
 
35
37
  export type {
36
38
  JobInterviewJson,
@@ -43,6 +45,7 @@ export const jobBodyLimit = 256 * 1024;
43
45
  export const jobWaitLimitMs = 30_000;
44
46
  /** Subjects one `ask-batch` request may list (#963). */
45
47
  export const jobAskBatchLimit = 64;
48
+ const jobProgressBodyLimit = 1024;
46
49
  const requestDeadlineMs = 10_000;
47
50
 
48
51
  export function jobHash(value: string | Uint8Array): string {
@@ -201,15 +204,18 @@ export function parseRecordFreeze(value: unknown): RecordFreeze {
201
204
  }
202
205
 
203
206
  export function parsePublishResultV3(value: unknown): PublishResultV3 {
204
- const item = jobObject(value, ['kind', 'path', 'selector', 'questionId', 'setId']);
207
+ const item = jobObject(value, ['kind', 'path', 'selector', 'questionId', 'setId', 'sets']);
205
208
  switch (item.kind) {
206
209
  case 'package':
207
210
  jobObject(item, ['kind', 'path', 'selector']);
208
211
  if (!('selector' in item) || item.selector === undefined) throw new JobError('JOB_REQUEST_INVALID');
209
212
  return { kind: 'package', path: jobPath(item.path), selector: parseJobSelector(item.selector) };
210
- case 'option-set':
211
- jobObject(item, ['kind', 'questionId', 'setId']);
212
- return { kind: 'option-set', questionId: jobId(item.questionId), setId: jobId(item.setId) };
213
+ case 'option-set': {
214
+ jobObject(item, ['kind', 'questionId', 'setId', 'sets']);
215
+ const first = { questionId: jobId(item.questionId), setId: jobId(item.setId) };
216
+ if (!('sets' in item)) return { kind: 'option-set', ...first };
217
+ return { kind: 'option-set', ...first, sets: parseOptionSetRefs(item.sets, first) };
218
+ }
213
219
  case 'plan':
214
220
  jobObject(item, ['kind']);
215
221
  return { kind: 'plan' };
@@ -217,6 +223,28 @@ export function parsePublishResultV3(value: unknown): PublishResultV3 {
217
223
  throw new JobError('JOB_REQUEST_INVALID');
218
224
  }
219
225
 
226
+ /** #1004: 2–64 distinct sets, `sets[0]` equal to the result's own `questionId`/`setId`. One set never uses `sets`,
227
+ * so a one-set publication keeps a single encoding. A set named twice refuses `JOB_OPTION_SET_DUPLICATE`. */
228
+ function parseOptionSetRefs(value: unknown, first: RecordOptionSetRef): readonly RecordOptionSetRef[] {
229
+ if (!Array.isArray(value) || value.length < 2 || value.length > jobAskBatchLimit) throw new JobError('JOB_REQUEST_INVALID');
230
+ const seen = new Set<string>();
231
+ const sets = value.map(raw => {
232
+ const row = exactObject(raw, ['questionId', 'setId'], 'JOB_REQUEST_INVALID');
233
+ const ref = { questionId: jobId(row.questionId), setId: jobId(row.setId) };
234
+ const key = JSON.stringify([ref.questionId, ref.setId]);
235
+ if (seen.has(key)) throw new JobError('JOB_OPTION_SET_DUPLICATE', `set ${ref.questionId}/${ref.setId} is named twice`);
236
+ seen.add(key);
237
+ return ref;
238
+ });
239
+ if (sets[0]!.questionId !== first.questionId || sets[0]!.setId !== first.setId) throw new JobError('JOB_REQUEST_INVALID');
240
+ return sets;
241
+ }
242
+
243
+ /** The sets a record option-set result publishes, in order. */
244
+ export function optionSetRefs(result: RecordOptionResult): readonly RecordOptionSetRef[] {
245
+ return result.sets ?? [{ questionId: result.questionId, setId: result.setId }];
246
+ }
247
+
220
248
  export function parseRecordResult(value: unknown): RecordResult {
221
249
  const result = parsePublishResultV3(value);
222
250
  if (result.kind === 'package') throw new JobError('JOB_REQUEST_INVALID');
@@ -283,7 +311,7 @@ export function parseJobRequest(
283
311
  ): JobAgentRequest | JobFetchActRequest | AgentRequestV3 | FetchActRequestV3 {
284
312
  const item = jobObject(value, [
285
313
  'schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey',
286
- 'result', 'freeze', 'publicationId', 'subject', 'subjects', 'after', 'waitMs', 'reason', 'actId',
314
+ 'result', 'freeze', 'publicationId', 'subject', 'subjects', 'after', 'waitMs', 'reason', 'actId', 'seq', 'phase', 'text', 'step',
287
315
  ]);
288
316
  const targetSchema = mode === 'package-only' || mode === 'record-and-package'
289
317
  ? jobApiSchemaForMode(mode)
@@ -299,6 +327,9 @@ export function parseJobRequest(
299
327
  jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'actId']);
300
328
  return { ...base, verb: 'fetch-act', actId: jobId(item.actId) };
301
329
  }
330
+ if (item.verb === 'progress') {
331
+ return { ...base, verb: 'progress', ...parseJobProgress(item) };
332
+ }
302
333
  const mutation = { ...base, expectedGeneration: jobInteger(item.expectedGeneration), idempotencyKey: jobId(item.idempotencyKey) };
303
334
  switch (item.verb) {
304
335
  case 'publish': {
@@ -392,6 +423,24 @@ export function parseJobRequest(
392
423
  throw new JobError('JOB_REQUEST_INVALID');
393
424
  }
394
425
 
426
+ function parseJobProgress(item: Record<string, unknown>): Omit<JobProgressRequestV3, 'schema' | 'jobId' | 'requestId' | 'verb'> {
427
+ jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'seq', 'phase', 'text', 'step']);
428
+ const seq = jobInteger(item.seq), phase = item.phase;
429
+ if (seq < 1 || (phase !== 'ingest' && phase !== 'build' && phase !== 'measure' && phase !== 'publish' && phase !== 'other')) {
430
+ throw new JobError('JOB_REQUEST_INVALID');
431
+ }
432
+ let text: string | undefined;
433
+ if (Object.hasOwn(item, 'text')) {
434
+ text = item.text === '' ? '' : jobText(item.text, 120);
435
+ if (/[\u0085\u2028\u2029]/u.test(text)) throw new JobError('JOB_REQUEST_INVALID');
436
+ }
437
+ if (!Object.hasOwn(item, 'step')) return { seq, phase, ...(text !== undefined ? { text } : {}) };
438
+ const step = jobObject(item.step, ['i', 'n']);
439
+ const n = jobInteger(step.n, 1000), i = jobInteger(step.i, n);
440
+ if (i < 1) throw new JobError('JOB_REQUEST_INVALID');
441
+ return { seq, phase, ...(text !== undefined ? { text } : {}), step: { i, n } };
442
+ }
443
+
395
444
  /** The single V3 `ask` subject parser; `ask-batch` parses each listed subject through it. */
396
445
  function parseAskSubjectV3(value: unknown): JobSubject | RecordSubject {
397
446
  const isReopenSubject =
@@ -644,21 +693,32 @@ function parsePlanSubjects(
644
693
  });
645
694
  }
646
695
 
696
+ /** One `interview-picks` subject per published set, in set order. Two subjects for one set refuse by name. */
647
697
  function parseOptionSubjects(
648
698
  rawSubjects: unknown,
649
699
  selection: RecordOptionResult,
650
700
  code: JobErrorCode,
651
- ): readonly [RecordPicksSubject] {
652
- if (!Array.isArray(rawSubjects) || rawSubjects.length !== 1) {
701
+ ): readonly RecordPicksSubject[] {
702
+ const sets = optionSetRefs(selection);
703
+ if (!Array.isArray(rawSubjects) || rawSubjects.length > jobAskBatchLimit) {
653
704
  throw new JobError(code);
654
705
  }
655
- const parsed = asCode(() => parseRecordSubject(rawSubjects[0]), code);
656
- if (parsed.kind !== 'interview-picks' ||
657
- parsed.questionId !== selection.questionId ||
658
- parsed.setId !== selection.setId) {
706
+ const seen = new Set<string>();
707
+ const subjects = rawSubjects.map(raw => {
708
+ const parsed = asCode(() => parseRecordSubject(raw), code);
709
+ if (parsed.kind !== 'interview-picks') throw new JobError(code);
710
+ const key = JSON.stringify([parsed.questionId, parsed.setId]);
711
+ if (seen.has(key)) {
712
+ throw new JobError('JOB_OPTION_SET_DUPLICATE', `two subjects for set ${parsed.questionId}/${parsed.setId}`);
713
+ }
714
+ seen.add(key);
715
+ return { kind: 'interview-picks' as const, questionId: parsed.questionId, setId: parsed.setId };
716
+ });
717
+ if (subjects.length !== sets.length ||
718
+ subjects.some((subject, index) => subject.questionId !== sets[index]!.questionId || subject.setId !== sets[index]!.setId)) {
659
719
  throw new JobError(code);
660
720
  }
661
- return [{ kind: 'interview-picks', questionId: parsed.questionId, setId: parsed.setId }];
721
+ return subjects;
662
722
  }
663
723
 
664
724
  export function parseRecordPartsIdentity(
@@ -679,11 +739,12 @@ type ParsedRecordPayload =
679
739
  readonly inputs: readonly JobFileIdentity[];
680
740
  readonly files: readonly JobFileIdentity[];
681
741
  readonly plan: null;
682
- readonly subjects: readonly [RecordPicksSubject];
742
+ readonly subjects: readonly RecordPicksSubject[];
683
743
  }
684
744
  | {
685
745
  readonly kind: 'plan';
686
746
  readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
747
+ readonly planPicture?: JobFileIdentity;
687
748
  readonly inputs: readonly JobFileIdentity[];
688
749
  readonly files: readonly JobFileIdentity[];
689
750
  readonly plan: JobPlanIdentity;
@@ -701,14 +762,15 @@ function parseRecordClosureAndSubjects(
701
762
  ): ParsedRecordPayload {
702
763
  const { inputs, files } = parseFileClosure(rawInputs, rawFiles, checkedRecord, 'JOB_SOURCE_MISMATCH');
703
764
  if (selection.kind === 'option-set') {
704
- if (rawPlan !== null || 'checkpointEvidence' in evidenceHolder) throw new JobError('JOB_SOURCE_MISMATCH');
765
+ if (rawPlan !== null || 'checkpointEvidence' in evidenceHolder || 'planPicture' in evidenceHolder) throw new JobError('JOB_SOURCE_MISMATCH');
705
766
  const subjects = parseOptionSubjects(rawSubjects, selection, 'JOB_SOURCE_MISMATCH');
706
767
  return { kind: 'option-set', inputs, files, plan: null, subjects };
707
768
  }
708
769
  if (rawPlan === null) throw new JobError('JOB_SOURCE_MISMATCH');
709
770
  const { plan, stepIds } = parsePlanIdentity(rawPlan, 'JOB_SOURCE_MISMATCH');
710
771
  const subjects = parsePlanSubjects(rawSubjects, stepIds, 'JOB_SOURCE_MISMATCH');
711
- return { kind: 'plan', inputs, files, plan, subjects, ...checkpointEvidenceFields(evidenceHolder, plan, subjects, files) };
772
+ return { kind: 'plan', inputs, files, plan, subjects, ...checkpointEvidenceFields(evidenceHolder, plan, subjects, files),
773
+ ...planPictureFields(evidenceHolder, plan, files) };
712
774
  }
713
775
 
714
776
  export function parseRecordPublishedContext(
@@ -734,7 +796,7 @@ export function parseRecordPublishedContext(
734
796
  const selection = parseRecordResult(result);
735
797
  const checkedRecord = record === undefined ? undefined : parseProjectRecord(record, 'JOB_SOURCE_MISMATCH');
736
798
  if (value && typeof value === 'object') previousDraftFields(value, null);
737
- const item = exactObject(value, ['label', 'parts', 'inputs', 'files', 'plan', 'subjects'], 'JOB_SOURCE_MISMATCH', ['checkpointEvidence']);
799
+ const item = exactObject(value, ['label', 'parts', 'inputs', 'files', 'plan', 'subjects'], 'JOB_SOURCE_MISMATCH', ['checkpointEvidence', 'planPicture']);
738
800
  const label = asCode(() => jobText(item.label), 'JOB_SOURCE_MISMATCH');
739
801
  const parts = parseRecordPartsIdentity(item.parts, 'JOB_SOURCE_MISMATCH');
740
802
  const body = parseRecordClosureAndSubjects(
@@ -750,7 +812,8 @@ export function parseRecordPublishedContext(
750
812
  return { label, parts, inputs: body.inputs, files: body.files, plan: null, subjects: body.subjects };
751
813
  }
752
814
  return { label, parts, inputs: body.inputs, files: body.files, plan: body.plan, subjects: body.subjects,
753
- ...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}) };
815
+ ...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
816
+ ...(body.planPicture ? {planPicture: body.planPicture} : {}) };
754
817
  }
755
818
 
756
819
  export function assertEqualRecordContexts(
@@ -761,7 +824,10 @@ export function assertEqualRecordContexts(
761
824
  if (ctx.plan === null) {
762
825
  const first = Array.isArray(ctx.subjects) ? ctx.subjects[0] : undefined;
763
826
  if (!first || first.kind !== 'interview-picks') throw new JobError('JOB_SOURCE_MISMATCH');
764
- return { kind: 'option-set', questionId: first.questionId, setId: first.setId };
827
+ if (ctx.subjects.length < 2) return { kind: 'option-set', questionId: first.questionId, setId: first.setId };
828
+ // Several sets: the subjects name them; parseOptionSubjects still refuses a set named twice.
829
+ return { kind: 'option-set', questionId: first.questionId, setId: first.setId,
830
+ sets: ctx.subjects.map(subject => ({ questionId: subject.questionId, setId: subject.setId })) };
765
831
  }
766
832
  return { kind: 'plan' };
767
833
  };
@@ -775,6 +841,7 @@ export function assertEqualRecordContexts(
775
841
 
776
842
  export interface RecordSourceDigestInput {
777
843
  readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
844
+ readonly planPicture?: JobFileIdentity;
778
845
  readonly schema?: typeof JOB_RECORD_SOURCE_SCHEMA;
779
846
  readonly sourceHash?: JobSha256;
780
847
  readonly projectHash?: JobSha256;
@@ -787,6 +854,7 @@ export interface RecordSourceDigestInput {
787
854
  readonly plan: JobPlanIdentity | null;
788
855
  readonly subjects: readonly RecordSubject[];
789
856
  readonly files: readonly JobFileIdentity[];
857
+ readonly optionSets?: readonly RecordOptionSetBinding[];
790
858
  }
791
859
 
792
860
  export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInput): string {
@@ -806,6 +874,8 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
806
874
  'subjects',
807
875
  'files',
808
876
  'checkpointEvidence',
877
+ 'optionSets',
878
+ 'planPicture',
809
879
  ]),
810
880
  'JOB_SOURCE_MISMATCH',
811
881
  );
@@ -829,7 +899,7 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
829
899
  const { inputs, files, byPath } = parseFileClosure(item.inputs, item.files, record, 'JOB_SOURCE_MISMATCH');
830
900
 
831
901
  if (selection.kind === 'option-set') {
832
- if ('checkpointEvidence' in item || item.plan !== null || item.optionSet === null || item.optionSetFile === null) {
902
+ if ('checkpointEvidence' in item || 'planPicture' in item || item.plan !== null || item.optionSet === null || item.optionSetFile === null) {
833
903
  throw new JobError('JOB_SOURCE_MISMATCH');
834
904
  }
835
905
  const rawOptionSet = exactObject(item.optionSet, ['id', 'sha256'], 'JOB_SOURCE_MISMATCH');
@@ -845,19 +915,24 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
845
915
  throw new JobError('JOB_SOURCE_MISMATCH');
846
916
  }
847
917
  const subjects = parseOptionSubjects(item.subjects, selection, 'JOB_SOURCE_MISMATCH');
918
+ const optionSets = parseOptionSetBindings(item.optionSets, selection, optionSetFile, byPath);
919
+ // One set keeps the original payload bytes; several sets add `sets` to the selection and `optionSets` last.
848
920
  return JSON.stringify({
849
921
  schema: JOB_RECORD_SOURCE_SCHEMA,
850
922
  record: { path: 'project.json', sha256: record.sha256 },
851
- selection: { kind: 'option-set', questionId: selection.questionId, setId: selection.setId },
923
+ selection: { kind: 'option-set', questionId: selection.questionId, setId: selection.setId,
924
+ ...(selection.sets ? { sets: selection.sets.map(set => ({ questionId: set.questionId, setId: set.setId })) } : {}) },
852
925
  inputs,
853
926
  optionSet,
854
927
  optionSetFile,
855
928
  plan: null,
856
929
  subjects,
857
930
  files,
931
+ ...(optionSets ? { optionSets } : {}),
858
932
  });
859
933
  }
860
934
 
935
+ if (item.optionSets !== undefined) throw new JobError('JOB_SOURCE_MISMATCH');
861
936
  if (item.optionSet !== null || item.optionSetFile !== null || item.plan === null) {
862
937
  throw new JobError('JOB_SOURCE_MISMATCH');
863
938
  }
@@ -874,6 +949,38 @@ export function serializeRecordSourceDigestPayload(input: RecordSourceDigestInpu
874
949
  subjects,
875
950
  files,
876
951
  ...checkpointEvidenceFields(item, plan, subjects, files),
952
+ // #983: last, and only when present, so a record without it keeps its source hash.
953
+ ...planPictureFields(item, plan, files),
954
+ });
955
+ }
956
+
957
+ /** #1004: the per-set bindings of a several-set publication. Absent for one set; row 0 repeats the singular fields. */
958
+ function parseOptionSetBindings(
959
+ value: unknown,
960
+ selection: RecordOptionResult,
961
+ first: JobFileIdentity,
962
+ byPath: ReadonlyMap<string, string>,
963
+ ): readonly RecordOptionSetBinding[] | undefined {
964
+ if (!selection.sets) {
965
+ if (value !== undefined) throw new JobError('JOB_SOURCE_MISMATCH');
966
+ return undefined;
967
+ }
968
+ const sets = selection.sets;
969
+ if (!Array.isArray(value) || value.length !== sets.length) throw new JobError('JOB_SOURCE_MISMATCH');
970
+ const paths = new Set<string>();
971
+ return value.map((raw, index) => {
972
+ const row = exactObject(raw, ['questionId', 'setId', 'optionSet', 'optionSetFile'], 'JOB_SOURCE_MISMATCH');
973
+ const rawSet = exactObject(row.optionSet, ['id', 'sha256'], 'JOB_SOURCE_MISMATCH');
974
+ const file = parseFileRow(row.optionSetFile, 'JOB_SOURCE_MISMATCH');
975
+ const set = sets[index]!;
976
+ if (row.questionId !== set.questionId || row.setId !== set.setId || rawSet.id !== set.setId ||
977
+ rawSet.sha256 !== file.sha256 || file.path === 'project.json' || byPath.get(file.path) !== file.sha256 ||
978
+ paths.has(file.path) || (index === 0 && (file.path !== first.path || file.sha256 !== first.sha256))) {
979
+ throw new JobError('JOB_SOURCE_MISMATCH');
980
+ }
981
+ paths.add(file.path);
982
+ return { questionId: set.questionId, setId: set.setId, optionSet: { id: set.setId, sha256: file.sha256 },
983
+ optionSetFile: { path: file.path, sha256: file.sha256 } };
877
984
  });
878
985
  }
879
986
 
@@ -898,11 +1005,14 @@ function assembleRecordSource(
898
1005
  selection: RecordResult,
899
1006
  body: ParsedRecordPayload,
900
1007
  rawOptionSetFile?: unknown,
1008
+ rawOptionSets?: unknown,
901
1009
  ): OptionSource | PlanSource {
902
1010
  if (selection.kind === 'option-set') {
903
1011
  if (body.kind !== 'option-set' || !rawOptionSetFile) throw new JobError('JOB_SOURCE_MISMATCH');
904
1012
  const optionSetFile = parseFileRow(rawOptionSetFile, 'JOB_SOURCE_MISMATCH');
905
1013
  const optionSet = { id: selection.setId, sha256: optionSetFile.sha256 };
1014
+ const optionSets = selection.sets === undefined && rawOptionSets === undefined ? undefined
1015
+ : parseOptionSetBindings(rawOptionSets, selection, optionSetFile, new Map(body.files.map(file => [file.path, file.sha256])));
906
1016
  const sourceHash = recordSourceDigest({
907
1017
  record,
908
1018
  selection,
@@ -912,6 +1022,7 @@ function assembleRecordSource(
912
1022
  plan: null,
913
1023
  subjects: body.subjects,
914
1024
  files: body.files,
1025
+ ...(optionSets ? { optionSets } : {}),
915
1026
  });
916
1027
  return {
917
1028
  sourceHash,
@@ -920,13 +1031,16 @@ function assembleRecordSource(
920
1031
  inputs: body.inputs,
921
1032
  files: body.files,
922
1033
  subject: 'option-set',
923
- selection: { kind: 'option-set', questionId: selection.questionId, setId: selection.setId },
1034
+ selection: { kind: 'option-set', questionId: selection.questionId, setId: selection.setId,
1035
+ ...(selection.sets ? { sets: selection.sets.map(set => ({ questionId: set.questionId, setId: set.setId })) } : {}) },
924
1036
  optionSet,
925
1037
  optionSetFile,
926
1038
  plan: null,
927
1039
  subjects: body.subjects,
1040
+ ...(optionSets ? { optionSets } : {}),
928
1041
  };
929
1042
  }
1043
+ if (rawOptionSets !== undefined) throw new JobError('JOB_SOURCE_MISMATCH');
930
1044
  if (body.kind !== 'plan' || (rawOptionSetFile !== undefined && rawOptionSetFile !== null)) {
931
1045
  throw new JobError('JOB_SOURCE_MISMATCH');
932
1046
  }
@@ -940,6 +1054,7 @@ function assembleRecordSource(
940
1054
  subjects: body.subjects,
941
1055
  files: body.files,
942
1056
  ...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
1057
+ ...(body.planPicture ? {planPicture: body.planPicture} : {}),
943
1058
  });
944
1059
  return {
945
1060
  sourceHash,
@@ -948,6 +1063,7 @@ function assembleRecordSource(
948
1063
  inputs: body.inputs,
949
1064
  files: body.files,
950
1065
  ...(body.checkpointEvidence ? {checkpointEvidence: body.checkpointEvidence} : {}),
1066
+ ...(body.planPicture ? {planPicture: body.planPicture} : {}),
951
1067
  subject: 'plan',
952
1068
  selection: { kind: 'plan' },
953
1069
  optionSet: null,
@@ -962,6 +1078,8 @@ export function buildRecordSource(input: {
962
1078
  readonly selection: RecordOptionResult;
963
1079
  readonly context: OptionContext;
964
1080
  readonly optionSetFile: JobFileIdentity;
1081
+ /** #1004: one sealed file per published set, in set order; required exactly when `selection.sets` is present. */
1082
+ readonly optionSetFiles?: readonly JobFileIdentity[];
965
1083
  }): OptionSource;
966
1084
  export function buildRecordSource(input: {
967
1085
  readonly record: ProjectRecord;
@@ -974,6 +1092,7 @@ export function buildRecordSource(input: {
974
1092
  readonly selection: RecordResult;
975
1093
  readonly context: OptionContext | PlanContext;
976
1094
  readonly optionSetFile?: JobFileIdentity | null;
1095
+ readonly optionSetFiles?: readonly JobFileIdentity[];
977
1096
  }): OptionSource | PlanSource {
978
1097
  const record = parseProjectRecord(input.record, 'JOB_SOURCE_MISMATCH');
979
1098
  const selection = asCode(() => parseRecordResult(input.selection), 'JOB_SOURCE_MISMATCH');
@@ -994,8 +1113,15 @@ export function buildRecordSource(input: {
994
1113
  plan: context.plan,
995
1114
  subjects: context.subjects,
996
1115
  ...(context.checkpointEvidence ? {checkpointEvidence: context.checkpointEvidence} : {}),
1116
+ ...(context.planPicture ? {planPicture: context.planPicture} : {}),
997
1117
  };
998
- return assembleRecordSource(record, selection, body, input.optionSetFile);
1118
+ const sets = selection.kind === 'option-set' ? selection.sets : undefined;
1119
+ if ((sets === undefined) !== (input.optionSetFiles === undefined)) throw new JobError('JOB_SOURCE_MISMATCH');
1120
+ const optionSets = sets && input.optionSetFiles!.length === sets.length
1121
+ ? sets.map((set, index) => ({ questionId: set.questionId, setId: set.setId,
1122
+ optionSet: { id: set.setId, sha256: input.optionSetFiles![index]!.sha256 }, optionSetFile: input.optionSetFiles![index]! }))
1123
+ : sets ? [] : undefined;
1124
+ return assembleRecordSource(record, selection, body, input.optionSetFile, optionSets);
999
1125
  }
1000
1126
 
1001
1127
  export function parseRecordSource(value: unknown): RecordSource {
@@ -1015,7 +1141,7 @@ export function parseRecordSource(value: unknown): RecordSource {
1015
1141
  'subjects',
1016
1142
  ],
1017
1143
  'JOB_SOURCE_MISMATCH',
1018
- ['checkpointEvidence'],
1144
+ ['checkpointEvidence', 'optionSets', 'planPicture'],
1019
1145
  );
1020
1146
  const record = parseProjectRecord(item.record, 'JOB_SOURCE_MISMATCH');
1021
1147
  const projectHash = asCode(() => jobSha(item.projectHash), 'JOB_SOURCE_MISMATCH');
@@ -1034,7 +1160,7 @@ export function parseRecordSource(value: unknown): RecordSource {
1034
1160
  );
1035
1161
  if (selection.kind === 'option-set') {
1036
1162
  const rawOptionSet = exactObject(item.optionSet, ['id', 'sha256'], 'JOB_SOURCE_MISMATCH');
1037
- const built = assembleRecordSource(record, selection, body, item.optionSetFile) as OptionSource;
1163
+ const built = assembleRecordSource(record, selection, body, item.optionSetFile, item.optionSets) as OptionSource;
1038
1164
  if (rawOptionSet.id !== built.optionSet.id ||
1039
1165
  rawOptionSet.sha256 !== built.optionSet.sha256 ||
1040
1166
  sourceHash !== built.sourceHash) {
@@ -1042,7 +1168,7 @@ export function parseRecordSource(value: unknown): RecordSource {
1042
1168
  }
1043
1169
  return built;
1044
1170
  }
1045
- if (item.optionSet !== null || item.optionSetFile !== null) {
1171
+ if (item.optionSet !== null || item.optionSetFile !== null || 'optionSets' in item) {
1046
1172
  throw new JobError('JOB_SOURCE_MISMATCH');
1047
1173
  }
1048
1174
  const built = assembleRecordSource(record, selection, body, null) as PlanSource;
@@ -1060,10 +1186,8 @@ export function validateRecordAskSubject(subject: unknown, source: RecordSource)
1060
1186
  const checkedSource = parseRecordSource(source);
1061
1187
  const parsed = parseRecordSubject(subject);
1062
1188
  if (checkedSource.subject === 'option-set') {
1063
- const expected = checkedSource.subjects[0];
1064
1189
  if (parsed.kind !== 'interview-picks' ||
1065
- parsed.questionId !== expected.questionId ||
1066
- parsed.setId !== expected.setId) {
1190
+ !checkedSource.subjects.some(expected => parsed.questionId === expected.questionId && parsed.setId === expected.setId)) {
1067
1191
  throw new JobError('JOB_ASK_INVALID');
1068
1192
  }
1069
1193
  return parsed;
@@ -1102,6 +1226,52 @@ function parseActWords(value: unknown, code: JobErrorCode): string {
1102
1226
  return value;
1103
1227
  }
1104
1228
 
1229
+ /** #1004: an act's source names that act's own set. At K >= 2 the singular `selection` (`questionId`/`setId`, with
1230
+ * `sets` kept), `optionSet` and `optionSetFile` are re-pointed to the act's `optionSets` row; `subjects`, `optionSets`
1231
+ * and `sourceHash` stay the publication's. One set is returned unchanged. */
1232
+ export function recordActSource(source: RecordSource, set: RecordOptionSetRef): RecordSource {
1233
+ if (source.subject !== 'option-set' || !source.optionSets) return source;
1234
+ const row = source.optionSets.find(item => item.questionId === set.questionId && item.setId === set.setId);
1235
+ if (!row) throw new JobError('JOB_ACT_INVALID', `act set ${set.questionId}/${set.setId} is not published`);
1236
+ return {
1237
+ ...source,
1238
+ selection: { kind: 'option-set', questionId: row.questionId, setId: row.setId, sets: source.selection.sets! },
1239
+ optionSet: { id: row.optionSet.id, sha256: row.optionSet.sha256 },
1240
+ optionSetFile: { path: row.optionSetFile.path, sha256: row.optionSetFile.sha256 },
1241
+ };
1242
+ }
1243
+
1244
+ /** The inverse for a received act at K >= 2: check that the per-act singular fields agree with the act's own
1245
+ * `optionSets` row, then put set 0 back so the publication source (and its `sourceHash`) can be re-derived. */
1246
+ function publicationFormOfActSource(raw: unknown): { readonly raw: unknown; readonly set?: RecordOptionSetRef } {
1247
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return { raw };
1248
+ const item = raw as Record<string, unknown>;
1249
+ const selection = item.selection as Record<string, unknown> | null | undefined;
1250
+ const rows = item.optionSets;
1251
+ if (item.subject !== 'option-set' || !Array.isArray(rows) || rows.length < 2 || !selection || typeof selection !== 'object' ||
1252
+ typeof selection.questionId !== 'string' || typeof selection.setId !== 'string') return { raw };
1253
+ const set = { questionId: selection.questionId, setId: selection.setId };
1254
+ const named = `${set.questionId}/${set.setId}`;
1255
+ const row = rows.find(entry => entry && typeof entry === 'object' &&
1256
+ (entry as RecordOptionSetBinding).questionId === set.questionId && (entry as RecordOptionSetBinding).setId === set.setId) as
1257
+ RecordOptionSetBinding | undefined;
1258
+ if (!row) throw new JobError('JOB_ACT_INVALID', `act set ${named} is not published`);
1259
+ const optionSet = item.optionSet as { id?: unknown; sha256?: unknown } | null;
1260
+ const file = item.optionSetFile as { path?: unknown; sha256?: unknown } | null;
1261
+ if (!optionSet || optionSet.id !== set.setId || optionSet.sha256 !== row.optionSet?.sha256) {
1262
+ throw new JobError('JOB_ACT_INVALID', `act optionSet does not name set ${named}`);
1263
+ }
1264
+ if (!file || file.path !== row.optionSetFile?.path || file.sha256 !== row.optionSetFile?.sha256) {
1265
+ throw new JobError('JOB_ACT_INVALID', `act optionSetFile is not the file of set ${named}`);
1266
+ }
1267
+ const first = rows[0] as RecordOptionSetBinding;
1268
+ return {
1269
+ set,
1270
+ raw: { ...item, selection: { ...selection, questionId: first.questionId, setId: first.setId },
1271
+ optionSet: first.optionSet, optionSetFile: first.optionSetFile },
1272
+ };
1273
+ }
1274
+
1105
1275
  export function parseRecordAct(value: unknown): RecordAct {
1106
1276
  const item = exactObject(
1107
1277
  value,
@@ -1116,14 +1286,19 @@ export function parseRecordAct(value: unknown): RecordAct {
1116
1286
  const authority = parseHumanAuthority(item.authority, 'JOB_ACT_INVALID');
1117
1287
  const at = asCode(() => jobText(item.at, 128), 'JOB_ACT_INVALID');
1118
1288
  if (Number.isNaN(Date.parse(at))) throw new JobError('JOB_ACT_INVALID');
1119
- const source = asCode(() => parseRecordSource(item.source), 'JOB_ACT_INVALID');
1289
+ const received = publicationFormOfActSource(item.source);
1290
+ const published = asCode(() => parseRecordSource(received.raw), 'JOB_ACT_INVALID');
1291
+ const source = received.set ? recordActSource(published, received.set) : published;
1120
1292
 
1121
1293
  switch (item.kind) {
1122
1294
  case 'interview-picks': {
1123
1295
  if (source.subject !== 'option-set') throw new JobError('JOB_ACT_INVALID');
1124
1296
  const rawValue = exactObject(item.value, ['questionId', 'selections', 'note'], 'JOB_ACT_INVALID');
1125
1297
  const questionId = asCode(() => jobId(rawValue.questionId), 'JOB_ACT_INVALID');
1126
- if (questionId !== source.selection.questionId || !Array.isArray(rawValue.selections) ||
1298
+ if (received.set && questionId !== received.set.questionId) {
1299
+ throw new JobError('JOB_ACT_INVALID', `value.questionId ${questionId} is not the act set ${received.set.questionId}/${received.set.setId}`);
1300
+ }
1301
+ if (!optionSetRefs(source.selection).some(set => set.questionId === questionId) || !Array.isArray(rawValue.selections) ||
1127
1302
  rawValue.selections.length > maxRecordFiles) {
1128
1303
  throw new JobError('JOB_ACT_INVALID');
1129
1304
  }
@@ -1425,6 +1600,10 @@ function commentsSource(raw: unknown): Exclude<SourceV3, OptionSource> {
1425
1600
  return structuredClone(item) as unknown as Exclude<SourceV3, OptionSource>;
1426
1601
  }
1427
1602
 
1603
+ export function isRigDraftVerdictSource(source: JobSourceBinding): boolean {
1604
+ return source.selector?.kind === 'draft' && !!source.model && !!source.projectHash && source.direction === null;
1605
+ }
1606
+
1428
1607
  /** Public @6 decoder. The UI finalizers write checkpoint, parts, rig/post verdict and signoff acts at @6 (#713). */
1429
1608
  export function parseCommentsAct(raw: unknown): JobCommentsAct {
1430
1609
  return decodeCommentsAct(raw, JOB_COMMENTS_ACT_SCHEMA) as JobCommentsAct;
@@ -1440,6 +1619,10 @@ export function parseMeshEditsAct(raw: unknown): JobMeshEditsAct {
1440
1619
  return decodeCommentsAct(raw, JOB_MESH_EDITS_ACT_SCHEMA) as JobMeshEditsAct;
1441
1620
  }
1442
1621
 
1622
+ export function parseChestLandmarksAct(raw: unknown): JobChestLandmarksAct {
1623
+ return decodeCommentsAct(raw, JOB_CHEST_LANDMARKS_ACT_SCHEMA) as JobChestLandmarksAct;
1624
+ }
1625
+
1443
1626
  export function meshEditDigest(edit: JobMeshEditValue): JobSha256 {
1444
1627
  return jobHash(canonicalJson(edit));
1445
1628
  }
@@ -1527,6 +1710,63 @@ export function parseMeshEdits(raw: unknown): readonly JobMeshEdit[] {
1527
1710
  }, 'JOB_ACT_INVALID');
1528
1711
  }
1529
1712
 
1713
+ function parseChestLandmarkValue(raw: unknown, code: JobErrorCode): JobChestLandmarkValue;
1714
+ function parseChestLandmarkValue(raw: unknown, code: JobErrorCode, published: true): JobPublishedChestLandmark;
1715
+ function parseChestLandmarkValue(raw: unknown, code: JobErrorCode, published = false): JobChestLandmarkValue | JobPublishedChestLandmark {
1716
+ const value = exactObject(raw, ['slot', 'skin', 'attachment', 'basis', 'source', 'bust'], code);
1717
+ if (value.basis !== 'setup') throw new JobError(code);
1718
+ const source = exactObject(value.source, published ? ['hash', 'frame', 'configHash'] : ['hash', 'frame'], code);
1719
+ const frame = exactObject(source.frame, ['width', 'height'], code);
1720
+ const width = meshNumber(frame.width), height = meshNumber(frame.height);
1721
+ if (width <= 0 || height <= 0) throw new JobError(code);
1722
+ const bust = parseBustSpec(value.bust, 'bust', true);
1723
+ for (const point of [bust.apex_r, bust.apex_l, bust.cleavage]) {
1724
+ if (point && (point[0] < 0 || point[0] > width || point[1] < 0 || point[1] > height)) throw new JobError(code);
1725
+ }
1726
+ return {
1727
+ slot: jobText(value.slot), skin: jobText(value.skin), attachment: jobText(value.attachment), basis: 'setup',
1728
+ source: {hash: jobSha(source.hash), frame: {width, height}, ...(published ? {configHash: jobSha(source.configHash)} : {})}, bust,
1729
+ };
1730
+ }
1731
+
1732
+ export function chestLandmarkIdentity(edit: JobChestLandmarkValue): string {
1733
+ return JSON.stringify([edit.skin, edit.slot, edit.attachment]);
1734
+ }
1735
+
1736
+ /** The seed and act use the same bounds and identity order. The act wraps each row in a digest. */
1737
+ function readChestLandmarkRows<Row>(raw: unknown, code: JobErrorCode,
1738
+ read: (item: unknown) => {edit: JobChestLandmarkValue; row: Row}): readonly Row[] {
1739
+ return asCode(() => {
1740
+ if (!Array.isArray(raw) || raw.length < 1 || raw.length > 4) throw new JobError(code);
1741
+ const seen = new Set<string>();
1742
+ let previousOrder: string | undefined;
1743
+ return Array.from(raw, item => {
1744
+ const {edit, row} = read(item);
1745
+ const key = chestLandmarkIdentity(edit), order = [edit.skin, edit.slot, edit.attachment].join('/');
1746
+ if (seen.has(key) || (previousOrder !== undefined && order < previousOrder)) throw new JobError(code);
1747
+ seen.add(key);
1748
+ previousOrder = order;
1749
+ return row;
1750
+ });
1751
+ }, code);
1752
+ }
1753
+
1754
+ export function parsePublishedChestLandmarks(raw: unknown): readonly JobPublishedChestLandmark[] {
1755
+ return readChestLandmarkRows(raw, 'JOB_SOURCE_MISMATCH', item => {
1756
+ const edit = parseChestLandmarkValue(item, 'JOB_SOURCE_MISMATCH', true);
1757
+ return {edit, row: edit};
1758
+ });
1759
+ }
1760
+
1761
+ export function parseChestLandmarkEdits(raw: unknown): readonly JobChestLandmarkEdit[] {
1762
+ return readChestLandmarkRows(raw, 'JOB_ACT_INVALID', item => {
1763
+ const {edit: value, sha256} = commentsObject(item, ['edit', 'sha256']);
1764
+ const edit = parseChestLandmarkValue(value, 'JOB_ACT_INVALID');
1765
+ if (jobSha(sha256) !== requestDigest(value)) throw new JobError('JOB_ACT_INVALID');
1766
+ return {edit, row: structuredClone(item) as unknown as JobChestLandmarkEdit};
1767
+ });
1768
+ }
1769
+
1530
1770
  /** Write @7 when a comment carries context, otherwise keep the @6 envelope. */
1531
1771
  export function commentsActForEmission(act: JobCommentsAct | JobContextCommentsAct): JobCommentsAct | JobContextCommentsAct {
1532
1772
  const value = act.value as {comments: readonly JobContextComment[]};
@@ -1546,8 +1786,9 @@ export function meshEditsActForEmission(act: JobCommentsAct | (Extract<JobCommen
1546
1786
  return parseMeshEditsAct({...act, schema: JOB_MESH_EDITS_ACT_SCHEMA}) as Extract<JobAct, {schema: typeof JOB_MESH_EDITS_ACT_SCHEMA}>;
1547
1787
  }
1548
1788
 
1549
- function decodeCommentsAct(raw: unknown, schema: JobCommentsAct['schema'] | JobContextCommentsAct['schema'] | JobMeshEditsAct['schema']):
1550
- JobCommentsAct | JobContextCommentsAct | JobMeshEditsAct {
1789
+ type CommentsWireAct = JobCommentsAct | JobContextCommentsAct | JobMeshEditsAct | JobChestLandmarksAct;
1790
+
1791
+ function decodeCommentsAct(raw: unknown, schema: CommentsWireAct['schema']): CommentsWireAct {
1551
1792
  return asCode(() => {
1552
1793
  const item = commentsObject(raw, ['schema', 'actId', 'jobId', 'askId', 'publicationId', 'kind', 'authority', 'at', 'source', 'value'], ['still']);
1553
1794
  if (item.schema !== schema) throw new JobError('JOB_ACT_INVALID');
@@ -1562,8 +1803,10 @@ function decodeCommentsAct(raw: unknown, schema: JobCommentsAct['schema'] | JobC
1562
1803
  };
1563
1804
  const keys = typeof item.kind === 'string' && Object.hasOwn(fields, item.kind) ? fields[item.kind] : undefined;
1564
1805
  if (!keys) throw new JobError('JOB_ACT_INVALID');
1565
- const at8 = schema === JOB_MESH_EDITS_ACT_SCHEMA;
1566
- const value = commentsObject(item.value, keys, at8 && item.kind === 'review-verdict' ? ['meshEdits'] : []);
1806
+ const at9 = schema === JOB_CHEST_LANDMARKS_ACT_SCHEMA;
1807
+ const supportsMesh = schema === JOB_MESH_EDITS_ACT_SCHEMA || at9;
1808
+ const value = commentsObject(item.value, at9 ? [...keys, 'chestLandmarks'] : keys,
1809
+ supportsMesh && item.kind === 'review-verdict' ? ['meshEdits'] : []);
1567
1810
  const comments = schema === JOB_COMMENTS_ACT_SCHEMA ? parseComments(value.comments, source) : decodeComments(value.comments, source, true);
1568
1811
  if (comments.some(comment => comment.anchor && 'side' in comment.anchor)) throw new JobError('JOB_ACT_INVALID');
1569
1812
  if ((comments as readonly JobContextComment[]).some(comment => comment.context?.subject &&
@@ -1579,7 +1822,7 @@ function decodeCommentsAct(raw: unknown, schema: JobCommentsAct['schema'] | JobC
1579
1822
  if ((value.verdict === 'approved') !== (issues === 0)) throw new JobError('JOB_ACT_INVALID');
1580
1823
  } else if (item.kind === 'review-verdict') {
1581
1824
  if ('record' in source || typeof value.verdict !== 'string' || !['pending', 'approved', 'changes-requested'].includes(value.verdict)) throw new JobError('JOB_ACT_INVALID');
1582
- if (!source.model || (value.stage === 'rig-review' ? source.selector?.kind !== 'rig' : value.stage !== 'direction-review' || source.selector?.kind !== 'post' || !source.direction)) throw new JobError('JOB_ACT_INVALID');
1825
+ if (!source.model || (value.stage === 'rig-review' ? source.selector?.kind !== 'rig' && !isRigDraftVerdictSource(source) : value.stage !== 'direction-review' || source.selector?.kind !== 'post' || !source.direction)) throw new JobError('JOB_ACT_INVALID');
1583
1826
  } else {
1584
1827
  const stage = jobId(value.stage);
1585
1828
  if (item.kind === 'signoff' && value.decision !== 'approved') throw new JobError('JOB_ACT_INVALID');
@@ -1590,12 +1833,17 @@ function decodeCommentsAct(raw: unknown, schema: JobCommentsAct['schema'] | JobC
1590
1833
  if ('record' in source) validateRecordAskSubject(item.kind === 'checkpoint' ? {kind: item.kind, checkpointId: value.checkpointId} :
1591
1834
  {kind: item.kind, stage: value.stage}, source);
1592
1835
  const rig = item.kind === 'review-verdict' && value.stage === 'rig-review';
1836
+ let chestLandmarks: readonly JobChestLandmarkEdit[] | undefined;
1837
+ if (at9) {
1838
+ if (!rig || value.verdict !== 'changes-requested') throw new JobError('JOB_ACT_INVALID');
1839
+ chestLandmarks = parseChestLandmarkEdits(value.chestLandmarks);
1840
+ }
1593
1841
  let meshEdits: readonly JobMeshEdit[] | undefined;
1594
- if (at8 && Object.hasOwn(value, 'meshEdits')) {
1842
+ if (supportsMesh && Object.hasOwn(value, 'meshEdits')) {
1595
1843
  if (!rig || value.verdict !== 'changes-requested') throw new JobError('JOB_ACT_INVALID');
1596
1844
  meshEdits = parseMeshEdits(value.meshEdits);
1597
1845
  }
1598
- if (at8 && item.kind === 'review-verdict' && value.verdict === 'changes-requested' && !comments.length && !meshEdits) {
1846
+ if (supportsMesh && item.kind === 'review-verdict' && value.verdict === 'changes-requested' && !comments.length && !meshEdits && !chestLandmarks) {
1599
1847
  throw new JobError('JOB_ACT_INVALID');
1600
1848
  }
1601
1849
  if (rig) {
@@ -1604,12 +1852,12 @@ function decodeCommentsAct(raw: unknown, schema: JobCommentsAct['schema'] | JobC
1604
1852
  (still.frame === 'setup' ? 'animation' in still : typeof still.frame !== 'number' || !Number.isFinite(still.frame) ||
1605
1853
  still.frame < 0 || typeof still.animation !== 'string' || !still.animation)) throw new JobError('JOB_ACT_INVALID');
1606
1854
  } else if ('still' in item) throw new JobError('JOB_ACT_INVALID');
1607
- return {...structuredClone(item), source, value: {...value, comments, ...(meshEdits ? {meshEdits} : {})}} as unknown as
1608
- JobCommentsAct | JobContextCommentsAct | JobMeshEditsAct;
1855
+ return {...structuredClone(item), source, value: {...value, comments, ...(meshEdits ? {meshEdits} : {}),
1856
+ ...(chestLandmarks ? {chestLandmarks} : {})}} as unknown as CommentsWireAct;
1609
1857
  }, 'JOB_ACT_INVALID');
1610
1858
  }
1611
1859
 
1612
- export async function jobBody(request: Request, maximum = jobBodyLimit): Promise<unknown> {
1860
+ export async function jobBody(request: Request, maximum = jobBodyLimit, validateSize?: (value: unknown, size: number) => void): Promise<unknown> {
1613
1861
  if (!/^application\/json(?:\s*;|$)/i.test(request.headers.get('content-type') ?? '')) {
1614
1862
  throw new JobError('JOB_REQUEST_INVALID');
1615
1863
  }
@@ -1634,6 +1882,7 @@ export async function jobBody(request: Request, maximum = jobBodyLimit): Promise
1634
1882
  chunks.push(value);
1635
1883
  }
1636
1884
  const value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks)));
1885
+ validateSize?.(value, size);
1637
1886
  if (value?.value != null && Object.hasOwn(value.value, 'meshEdits') &&
1638
1887
  Buffer.byteLength(canonicalJson(value.value.meshEdits)) > jobBodyLimit) {
1639
1888
  throw new JobError('JOB_BODY_LIMIT');
@@ -1703,7 +1952,11 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
1703
1952
  {headers: {...responseHeaders, 'Content-Type': 'image/png'}});
1704
1953
  }
1705
1954
  gate(request, base + '/api', false);
1706
- const body = await jobBody(request);
1955
+ const body = await jobBody(request, jobBodyLimit, (value, size) => {
1956
+ if (size > jobProgressBodyLimit && (value as { verb?: unknown } | null)?.verb === 'progress') {
1957
+ throw new JobError('JOB_REQUEST_INVALID');
1958
+ }
1959
+ });
1707
1960
  const mode: JobPublicationMode =
1708
1961
  session.publicationMode === 'record-and-package' &&
1709
1962
  body !== null &&
@@ -1738,6 +1991,9 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
1738
1991
  }
1739
1992
  },
1740
1993
  subscribeJob: input => session.subscribe(input),
1994
+ ...(session.apiSchema === JOB_API_V3_SCHEMA ? {
1995
+ subscribeJobPage: (input: Parameters<JobHostPorts['subscribeJob']>[0]) => session.subscribe(input, true),
1996
+ } : {}),
1741
1997
  async readPublication(job, publication) {
1742
1998
  try {
1743
1999
  if (job !== session.jobId) throw new JobError('JOB_UNKNOWN');