rig-review 2.12.0 → 2.13.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 (89) hide show
  1. package/docs/DESIGN.md +82 -71
  2. package/docs/PANELS.md +20 -12
  3. package/docs/PARTS_VIEW.md +31 -11
  4. package/docs/REVIEW_PACKAGE.md +99 -9
  5. package/docs/STABILITY.md +74 -3
  6. package/docs/WORKFLOWS.md +40 -12
  7. package/package.json +2 -1
  8. package/skills/rig-review/SKILL.md +29 -1
  9. package/src/build.ts +10 -2
  10. package/src/cli.ts +14 -12
  11. package/src/compare-html.ts +22 -24
  12. package/src/compare-server.ts +1 -1
  13. package/src/create-pin-gate.ts +3 -0
  14. package/src/feedback-export.ts +49 -1
  15. package/src/front.ts +10 -16
  16. package/src/interview-routes.ts +1 -1
  17. package/src/job-act.ts +39 -21
  18. package/src/job-api.ts +102 -11
  19. package/src/job-contract.ts +44 -4
  20. package/src/job-front.ts +15 -7
  21. package/src/job-host.ts +4 -3
  22. package/src/job-hub.ts +4 -4
  23. package/src/job-session.ts +5 -2
  24. package/src/job-source.ts +42 -13
  25. package/src/joined-project.ts +61 -4
  26. package/src/open-workspace.ts +12 -12
  27. package/src/open.ts +17 -9
  28. package/src/parts-comment.ts +31 -1
  29. package/src/parts-server.ts +19 -7
  30. package/src/parts-view.ts +71 -20
  31. package/src/server.ts +30 -21
  32. package/src/stage-comment.ts +11 -1
  33. package/src/stage-parts.ts +18 -10
  34. package/web/animation-inspection.ts +1 -1
  35. package/web/bones-panel.ts +1 -3
  36. package/web/catalog-en.ts +76 -12
  37. package/web/catalog-ko.ts +76 -12
  38. package/web/cloth-panel.ts +1 -2
  39. package/web/compare.css +3 -9
  40. package/web/compare.html +3 -3
  41. package/web/compare.ts +69 -64
  42. package/web/cuts-panel.ts +1 -3
  43. package/web/density-strip-panel.ts +1 -2
  44. package/web/i18n.ts +13 -1
  45. package/web/idle-panel.ts +1 -2
  46. package/web/index.html +1 -5
  47. package/web/inspection-persistence.ts +2 -1
  48. package/web/inspector-blocks.ts +144 -39
  49. package/web/instance-access.ts +24 -5
  50. package/web/interview-panel.ts +224 -175
  51. package/web/job-hub.ts +50 -69
  52. package/web/job-rig-capture.ts +103 -10
  53. package/web/job-rig-screen.ts +317 -0
  54. package/web/job-session.ts +927 -1365
  55. package/web/main.ts +535 -129
  56. package/web/mesh-panel.ts +1 -2
  57. package/web/owner-workspace.ts +88 -109
  58. package/web/part-selection.ts +47 -6
  59. package/web/part-thumbnails.ts +20 -6
  60. package/web/parts-viewport-provider.ts +166 -9
  61. package/web/physics-panel.ts +1 -2
  62. package/web/readings-panel.ts +1 -2
  63. package/web/requirements-panel.ts +1 -3
  64. package/web/retained-frame-stage.ts +105 -0
  65. package/web/retarget-panel.ts +2 -3
  66. package/web/rig-fields-panel.ts +1 -2
  67. package/web/rig-host.ts +62 -0
  68. package/web/rig-viewport-provider.ts +63 -16
  69. package/web/stage-comments.ts +29 -26
  70. package/web/styles.css +127 -43
  71. package/web/view-controls.ts +201 -12
  72. package/web/viewport-controller.ts +97 -26
  73. package/web/viewport-pair.ts +2 -1
  74. package/web/workspace-preferences.ts +5 -4
  75. package/web/workspace-ui.ts +152 -19
  76. package/src/interview-server.ts +0 -54
  77. package/web/interview.css +0 -28
  78. package/web/interview.html +0 -17
  79. package/web/interview.ts +0 -40
  80. package/web/job-hub.css +0 -14
  81. package/web/job-hub.html +0 -5
  82. package/web/owner-workspace.css +0 -14
  83. package/web/owner-workspace.html +0 -5
  84. package/web/parts-flags.ts +0 -48
  85. package/web/parts-page.ts +0 -217
  86. package/web/parts.css +0 -116
  87. package/web/parts.html +0 -15
  88. package/web/parts.ts +0 -986
  89. package/web/stage-nav.ts +0 -136
@@ -0,0 +1,317 @@
1
+ import {formFor, jobCheckpointContext, jobPublicationRoutes, prepareJobForms, prepareJobInspection, type JobForm, type JobFormDependencies, type JobPreparedInspection} from './job-session.ts';
2
+ import {commentPartsIssues,type PartsIssue} from '../src/parts-comment.ts';
3
+ import type {PartsSubjectData} from './parts-viewport-provider.ts';
4
+ /** Card I (#709): a rig publication of a live job opens the one review screen (`main.ts`) instead of the job
5
+ * window. The job stays the transport: same asks, act kinds, still, displayed-ack and submission idempotency.
6
+ * Rig verdicts use the act bar; supported approval and interview asks use the shared ask dialog. */
7
+ import type {ActV3, DisplayPublicationV3, JobResult, JobUISubmission, PendingAskV3, SourceV3, UISubmissionV3} from '../src/job-contract.ts';
8
+ import type {Feedback, ReviewSession} from '../src/session.ts';
9
+ import type {ReviewManifest, ReviewedSource} from '../src/manifest.ts';
10
+ import {checkpointNoteComments, feedbackItemComments, projectComments} from '../src/stage-comment.ts';
11
+ import {copyJobRigViewport, createJobRigSubmission, freezeJobRigCapture, jobRigDrawState, presentJobRigStage, recordJobRigDraw} from './job-rig-capture.ts';
12
+ import {setRigHost, rigHost, type RigHost, type RigHostScreen, type RigHostCommit, type RigHostNavigation} from './rig-host.ts';
13
+ import type {InstanceAccess} from './instance-access.ts';
14
+
15
+ /** A model publication of a rig version or a package: not a draft, direction, image set or record. */
16
+ export function jobRigScreenSubject(source: SourceV3): boolean {
17
+ if ('record' in source || source.subject === 'image-set') return false;
18
+ if(source.selector?.kind==='draft'&&source.parts)return true;
19
+ return !!source.model && !source.direction && (source.selector === null || source.selector.kind === 'rig');
20
+ }
21
+ /** The asks the rig screen's act bar answers: the rig verdict and checkpoints the package declares. */
22
+ export function jobRigScreenAnswers(ask: Pick<PendingAskV3, 'subject'>, checkpoints: ReadonlySet<string>): boolean {
23
+ const subject = ask.subject;
24
+ return subject.kind === 'review-verdict' ? subject.stage === 'rig-review' :
25
+ subject.kind === 'checkpoint' && checkpoints.has(subject.checkpointId);
26
+ }
27
+ export function jobRigScreenRoute(display: DisplayPublicationV3, pending: readonly PendingAskV3[],
28
+ checkpoints: ReadonlySet<string>): boolean {
29
+ const id = display.publication.publicationId;
30
+ if('selector' in display.publication.source&&display.publication.source.selector?.kind==='draft'&&display.publication.source.parts)return true;
31
+ return jobRigScreenSubject(display.publication.source) && pending.every(ask => {
32
+ if (ask.publicationId !== id || ask.status !== 'pending') return true;
33
+ if (ask.subject.kind === 'checkpoint') {
34
+ try {
35
+ prepareJobForms(display, [ask], () => jobCheckpointContext(ask, []));
36
+ return true;
37
+ } catch {return false;}
38
+ }
39
+ return jobRigScreenAnswers(ask, checkpoints) || ask.subject.kind === 'signoff' || ask.subject.kind === 'interview-picks';
40
+ });
41
+ }
42
+
43
+ export type JobRigScreenDecision =
44
+ | {readonly ask: PendingAskV3; readonly kind: 'checkpoint'; readonly value: Extract<JobUISubmission, {kind: 'checkpoint'}>['value']}
45
+ | {readonly ask: PendingAskV3; readonly kind: 'review-verdict'; readonly value: {stage: 'rig-review'; verdict: 'approved' | 'changes-requested'; words: string; feedback?: readonly Feedback[]}};
46
+ /** The act bar's decisions as the pending asks' values. `words` is the comments' projection (act@6's), or empty;
47
+ * a decision still pending is not sent, so a pending ask is never answered with "pending". Checkpoints go first. */
48
+ export function jobRigScreenDecisions(session: Pick<ReviewSession, 'status' | 'checkpoints' | 'feedback'>,
49
+ pending: readonly PendingAskV3[], publicationId: string): JobRigScreenDecision[] {
50
+ const open = pending.filter(ask => ask.publicationId === publicationId && ask.status === 'pending');
51
+ const decisions: JobRigScreenDecision[] = [];
52
+ for (const ask of open) {
53
+ if (ask.subject.kind !== 'checkpoint') continue;
54
+ const {checkpointId} = ask.subject, entry = session.checkpoints[checkpointId];
55
+ if (!entry || entry.outcome === 'pending') continue;
56
+ const planStepId = ('planStepId' in ask.subject ? ask.subject.planStepId : undefined) ?? checkpointId;
57
+ decisions.push({ask, kind: 'checkpoint', value: {checkpointId, outcome: entry.outcome,
58
+ words: entry.note.trim() ? projectComments(checkpointNoteComments({checkpointId, planStepId, note: entry.note})) : ''}});
59
+ }
60
+ const verdict = open.find(ask => ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review');
61
+ if (verdict && session.status !== 'pending') {
62
+ decisions.push({ask: verdict, kind: 'review-verdict', value: {stage: 'rig-review', verdict: session.status,
63
+ words: session.feedback.length ? projectComments(feedbackItemComments(session.feedback)) : '',
64
+ ...(session.feedback.length ? {feedback: structuredClone(session.feedback)} : {})}});
65
+ }
66
+ return decisions;
67
+ }
68
+
69
+ interface ReviewJson {manifest: ReviewManifest; reviewedSource: ReviewedSource; sourceHash: string}
70
+ export interface JobRigScreenPrepared {readonly jobRigScreen: true; readonly display: DisplayPublicationV3; readonly entry: string;
71
+ readonly modals?: {inspection:JobPreparedInspection;forms:Map<string,JobForm>}; readonly review?: ReviewJson; readonly record?: {inspection:JobPreparedInspection;forms:Map<string,JobForm>;picture:JobRigScreenPrepared|null}; readonly parts?:PartsSubjectData; readonly checkpoints: ReadonlySet<string>}
72
+ export function isJobRigScreen(value: unknown): value is JobRigScreenPrepared {
73
+ return !!value && typeof value === 'object' && (value as {jobRigScreen?: unknown}).jobRigScreen === true;
74
+ }
75
+
76
+ export function createJobRigScreen(options: {
77
+ host: HTMLElement;
78
+ pageId: string;
79
+ access: {readonly capability: string | null; headers(init?: HeadersInit): Headers};
80
+ window: {state(): {readonly pending: readonly (PendingAskV3 & {readonly act?:ActV3})[]; readonly receipt: {readonly displayedNonce: string} | null;
81
+ readonly generation: number; readonly preparing: boolean; readonly closed: boolean}; submit(input: UISubmissionV3): Promise<JobResult<ActV3>>};
82
+ routes(display: DisplayPublicationV3): {entry: string; api(path: string): string};
83
+ readPublication?(publicationId:string,signal:AbortSignal):Promise<JobResult<DisplayPublicationV3>>;
84
+ formDependencies?:JobFormDependencies;
85
+ refusal(error: unknown, fallback?: string): string;
86
+ translate(key: string,values?:readonly (string|number)[]): string;
87
+ /** Imports the rig composition once the host is set. */
88
+ load(): Promise<unknown>;
89
+ }) {
90
+ let mounted: JobRigScreenPrepared | null = null, screen: RigHostScreen | null = null, drawGeneration = 0;
91
+ let transition:{rollback():Promise<void>;finalize():void}|null=null;
92
+ const attempts = new Map<string, {key: string; submissionId: string; rig: ReturnType<typeof createJobRigSubmission>; commit: Omit<RigHostCommit, 'at'>}>();
93
+ async function prepare(display: DisplayPublicationV3, signal: AbortSignal, backdropOnly=false): Promise<JobRigScreenPrepared | null> {
94
+ if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
95
+ const source = display.publication.source;
96
+ if ('record' in source) {
97
+ if (!options.formDependencies) throw new Error('JOB_PANEL_UNAVAILABLE');
98
+ const inspection = await prepareJobInspection(display, signal);
99
+ try {
100
+ const forms = prepareJobForms(display, options.window.state().pending, ask => formFor(ask, inspection, options.formDependencies!));
101
+ let previous = display.publication.previousPublicationId, picture:JobRigScreenPrepared|null = null;
102
+ const jobId=jobPublicationRoutes(display,location.origin).jobId;
103
+ const seen = new Set([display.publication.publicationId]);
104
+ let generation = display.publication.generation;
105
+ while (previous) {
106
+ if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
107
+ if (seen.has(previous) || !options.readPublication) throw new Error('JOB_DISPLAY_MISMATCH');
108
+ seen.add(previous);
109
+ const result = await options.readPublication(previous, signal);
110
+ if (!result.ok) throw new Error(result.error.code);
111
+ if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
112
+ const candidate = result.value;
113
+ if(jobPublicationRoutes(candidate,location.origin).jobId!==jobId)throw new Error('JOB_DISPLAY_MISMATCH');
114
+ if (candidate.publication.publicationId !== previous || candidate.publication.generation >= generation) throw new Error('JOB_DISPLAY_MISMATCH');
115
+ generation = candidate.publication.generation;
116
+ if (jobRigScreenSubject(candidate.publication.source)) {picture = await prepare(candidate, signal, true);break;}
117
+ previous = candidate.publication.previousPublicationId;
118
+ }
119
+ if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
120
+ return {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints:new Set(),record:{inspection,forms,picture}};
121
+ } catch(error) {inspection.dispose();throw error;}
122
+ }
123
+ if (!jobRigScreenSubject(source) || source.subject === 'image-set') return null;
124
+ const routes = options.routes(display);
125
+ const response = await fetch(routes.api('review'), {signal});
126
+ if (!response.ok) throw new Error('JOB_VISUAL_UNAVAILABLE');
127
+ const review = await response.json() as ReviewJson;
128
+ if (!review.manifest || !review.reviewedSource || review.sourceHash !== source.sourceHash ||
129
+ review.manifest.id !== source.package.id || review.manifest.revision !== source.package.revision ||
130
+ (review.reviewedSource.rig?.sha256 ?? null) !== (source.model?.sha256 ?? null)) throw new Error('JOB_DISPLAY_MISMATCH');
131
+ const checkpoints = new Set(review.manifest.checkpoints.map(item => item.id));
132
+ if (!backdropOnly && !jobRigScreenRoute(display, options.window.state().pending, checkpoints)) return null;
133
+ let parts:PartsSubjectData|undefined;
134
+ if(source.selector?.kind==='draft'&&source.parts){
135
+ const response=await fetch(routes.api('stage-parts'),{signal});if(!response.ok)throw new Error('JOB_VISUAL_UNAVAILABLE');
136
+ parts=await response.json() as PartsSubjectData;
137
+ if(parts.sourceHash!==source.sourceHash||parts.mode!=='parts')throw new Error('JOB_DISPLAY_MISMATCH');
138
+ }
139
+ let modals:JobRigScreenPrepared['modals'];
140
+ const asks=options.window.state().pending.filter(ask=>ask.publicationId===display.publication.publicationId&&ask.subject.kind!=='parts-verdict'&&!(ask.subject.kind==='review-verdict'&&ask.subject.stage==='rig-review'));
141
+ if(!backdropOnly&&options.formDependencies){
142
+ const inspection=await prepareJobInspection(display,signal,true);
143
+ try{modals={inspection,forms:prepareJobForms(display,asks,ask=>formFor(ask,inspection,options.formDependencies!))};}
144
+ catch(error){inspection.dispose();throw error;}
145
+ }
146
+ return {jobRigScreen: true, display, entry: routes.entry, review, checkpoints,...parts?{parts}:{},...modals?{modals}:{}};
147
+ }
148
+ function still(ask: PendingAskV3, prepared: JobRigScreenPrepared) {
149
+ screen?.redraw();
150
+ const stage = screen?.stage();
151
+ if (!stage) throw new Error('JOB_STILL_CAPTURE_FAILED');
152
+ const publication = prepared.display.publication;
153
+ const source = {pageId: options.pageId, publicationId: publication.publicationId, instanceKey: publication.instanceKey,
154
+ sourceHash: publication.source.sourceHash};
155
+ // The canonical pixels are on the pane only while the still is bound and copied, then the screen's own view returns.
156
+ const presentation = presentJobRigStage(stage);
157
+ try {
158
+ presentation.canvas.style.position = 'absolute';
159
+ presentation.canvas.style.pointerEvents = 'none';
160
+ const bound = {...stage, source, presentation};
161
+ const draw = recordJobRigDraw(jobRigDrawState(bound), ++drawGeneration);
162
+ return freezeJobRigCapture(draw, jobRigDrawState(bound), ask.askId, () => copyJobRigViewport(presentation));
163
+ } finally {presentation.canvas.remove();}
164
+ }
165
+ async function submit(session: ReviewSession, committed: (commit: RigHostCommit) => void | Promise<void>): Promise<string> {
166
+ const prepared = mounted, state = options.window.state();
167
+ if (!prepared || !state.receipt || state.preparing) throw new Error('JOB_ACT_SOURCE_STALE');
168
+ if (state.closed) throw new Error('JOB_CLOSED');
169
+ if (!options.access.capability) throw new Error('JOB_CAPABILITY_REQUIRED');
170
+ const decisions = jobRigScreenDecisions(session, state.pending.filter(ask=>!prepared.modals?.forms.has(ask.askId)), prepared.display.publication.publicationId);
171
+ if (!decisions.length) throw new Error('JOB_ACT_NOTHING_TO_SUBMIT');
172
+ for (const decision of decisions) {
173
+ const key = JSON.stringify(decision.value);
174
+ let attempt = attempts.get(decision.ask.askId);
175
+ if (!attempt || attempt.key !== key) attempts.set(decision.ask.askId, attempt = {key, submissionId: crypto.randomUUID(), rig: createJobRigSubmission(),
176
+ commit: decision.kind === 'checkpoint' ? {checkpoints: {[decision.value.checkpointId]: structuredClone(session.checkpoints[decision.value.checkpointId]!)}} :
177
+ {review: {status: decision.value.verdict, feedback: structuredClone(session.feedback)}}});
178
+ const latest = options.window.state();
179
+ if (!latest.receipt) throw new Error('JOB_ACT_SOURCE_STALE');
180
+ const input = {kind: decision.kind, publicationId: decision.ask.publicationId, askId: decision.ask.askId, pageId: options.pageId,
181
+ displayedNonce: latest.receipt.displayedNonce, expectedGeneration: latest.generation, submissionId: attempt.submissionId,
182
+ value: decision.value} as JobUISubmission;
183
+ const ask = decision.ask, current = attempt;
184
+ const frozen = decision.kind === 'review-verdict' ? await current.rig.prepare(input, () => still(ask, prepared)) : input;
185
+ const result = await options.window.submit(frozen);
186
+ if (!result.ok) throw new Error(result.error.code);
187
+ attempts.delete(ask.askId);
188
+ await committed({...current.commit, at: result.value.at});
189
+ }
190
+ return options.translate('job.saved');
191
+ }
192
+ const partsAttempts=new Map<string,{key:string;submissionId:string}>();
193
+ /** One parts verdict act. A pending signoff remains independent and is never synthesized here. */
194
+ async function submitParts(issues:readonly PartsIssue[]):Promise<string>{
195
+ const prepared=mounted,state=options.window.state();
196
+ if(!prepared?.parts||!state.receipt||state.preparing)throw new Error('JOB_ACT_SOURCE_STALE');
197
+ if(state.closed)throw new Error('JOB_CLOSED');
198
+ const ask=state.pending.find(ask=>ask.publicationId===prepared.display.publication.publicationId&&ask.status==='pending'&&ask.subject.kind==='parts-verdict');
199
+ if(!ask)throw new Error('JOB_ACT_NOTHING_TO_SUBMIT');
200
+ const value={verdict:issues.length?'changes-requested' as const:'approved' as const,issues:structuredClone(issues),words:''},key=JSON.stringify(value);
201
+ let attempt=partsAttempts.get(ask.askId);if(!attempt||attempt.key!==key){attempt={key,submissionId:crypto.randomUUID()};partsAttempts.set(ask.askId,attempt);}
202
+ const result=await options.window.submit({kind:'parts-verdict',publicationId:ask.publicationId,askId:ask.askId,pageId:options.pageId,displayedNonce:state.receipt.displayedNonce,expectedGeneration:state.generation,submissionId:attempt.submissionId,value});
203
+ if(!result.ok)throw new Error(result.error.code);
204
+ partsAttempts.delete(ask.askId);return options.translate('job.saved');
205
+ }
206
+ const pendingSubjects=()=>options.window.state().pending.filter(ask=>ask.publicationId===mounted?.display.publication.publicationId&&ask.status==='pending').map(ask=>ask.subject);
207
+ function host(prepared: JobRigScreenPrepared, ready: {resolve(): void; reject(error: unknown): void}, navigation?:RigHostNavigation): RigHost {
208
+ const base = new URL(prepared.entry).pathname;
209
+ const access: InstanceAccess = {base, key: prepared.display.publication.instanceKey, capability: options.access.capability,
210
+ route: path => {if (!path.startsWith('/') || path.startsWith('//')) throw new Error('Instance route must be app-absolute'); return base + path.slice(1);},
211
+ headers: init => options.access.headers(init)};
212
+ const review = prepared.review;
213
+ if(prepared.record){
214
+ const record=prepared.record,backdrop=record.picture?host(record.picture,ready):null;
215
+ return {...(backdrop?.subject?{subject:backdrop.subject}:{}),access:{...(backdrop?.access??access),capability:null,
216
+ headers:init=>{const headers=options.access.headers(init);headers.delete('X-Review-Capability');return headers;}},
217
+ ownerActAccess:{capability:options.access.capability},
218
+ record:{label:prepared.display.publication.label,sourceHash:prepared.display.publication.source.sourceHash,hasPicture:!!record.picture},pendingSubjects,
219
+ read:(path,method)=>method==='GET'&&backdrop?backdrop.read(path,method):Promise.reject(new Error('JOB_REVIEW_READ_ONLY')),
220
+ submit:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
221
+ submitParts:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
222
+ attach:value=>{screen=value;screen.pendingSubjects?.(pendingSubjects());refreshRecordForms();},
223
+ displayed:()=>ready.resolve(),failed:error=>ready.reject(error)};
224
+ }
225
+ if(!review)throw new Error('JOB_DISPLAY_MISMATCH');
226
+ return {access,pendingSubjects,navigation,
227
+ reviewState(issues,sending) {
228
+ if(sending)return options.translate('job.parts.sending');
229
+ const kind=prepared.parts?'parts-verdict':'review-verdict';
230
+ const ask=options.window.state().pending.filter(ask=>ask.publicationId===prepared.display.publication.publicationId&&
231
+ ask.subject.kind===kind&&(ask.subject.kind!=='review-verdict'||ask.subject.stage==='rig-review')).at(-1);
232
+ const act=ask?.status==='answered'?ask.act:undefined;
233
+ const verdict=act?.kind===kind&&(act.kind==='parts-verdict'||act.kind==='review-verdict')?act.value.verdict:null;
234
+ return verdict==='changes-requested'?options.translate('job.parts.sent'):verdict==='approved'?options.translate('job.review.approved'):
235
+ options.translate('job.parts.reviewing',[issues]);
236
+ },...prepared.parts?{subject:'parts' as const,submitParts}: {},
237
+ read(path, method) {
238
+ if (method !== 'GET') return prepared.parts?undefined:Promise.reject(new Error('JOB_REVIEW_READ_ONLY'));
239
+ if(prepared.parts){
240
+ if(path==='/api/review')return Promise.resolve({subject:'parts',parts:structuredClone(prepared.parts)});
241
+ if(path==='/api/access')return Promise.resolve({capabilityRequired:true,control:false});
242
+ if(path==='/api/session'){const act=options.window.state().pending.filter(ask=>ask.publicationId===prepared.display.publication.publicationId&&ask.subject.kind==='parts-verdict').at(-1)?.act;return Promise.resolve({subject:'parts',issues:act?.kind==='parts-verdict'&&act.schema==='rig-review/act@6'?commentPartsIssues(act.value.comments):act?.kind==='parts-verdict'&&act.schema==='rig-review/act@5'?act.value.issues:[]});}
243
+ return undefined;
244
+ }
245
+ if (path === '/api/review') return Promise.resolve(structuredClone(review));
246
+ if (path === '/api/access') return Promise.resolve({capabilityRequired: true, control: false});
247
+ if (path === '/api/session') return Promise.resolve({schema: 'rig-review-session/1', id: review.manifest.id, revision: review.manifest.revision,
248
+ sourceHash: review.sourceHash, reviewedSource: structuredClone(review.reviewedSource), status: 'pending', checkpoints: {}, feedback: [],
249
+ feedbackWarnings: [], updatedAt: null} satisfies ReviewSession);
250
+ return Promise.reject(new Error('JOB_REVIEW_READ_ONLY'));
251
+ },
252
+ submit: (session, committed) => submit(session, committed).catch(error => {throw new Error(options.refusal(error, 'JOB_ACT_INVALID'));}),
253
+ attach: value => {screen = value;screen.pendingSubjects?.(pendingSubjects());refreshRecordForms();},
254
+ displayed: () => ready.resolve(),
255
+ failed: error => ready.reject(error)};
256
+ }
257
+ /** Pending and completed forms keep the same source-bound builder and receipt gates. */
258
+ function refreshRecordForms():void {
259
+ const record=mounted?.record??mounted?.modals,deps=options.formDependencies;if(!record||!deps)return;
260
+ const state=options.window.state(),display=record.inspection.display;
261
+ const next=prepareJobForms(display,state.pending.filter(ask=>ask.subject.kind!=='parts-verdict'&&!(ask.subject.kind==='review-verdict'&&ask.subject.stage==='rig-review')),ask=>record.forms.get(ask.askId)??formFor(ask,record.inspection,deps));
262
+ for(const [id,entry]of next)record.forms.set(id,entry);
263
+ for(const [id,entry]of record.forms){const ask=state.pending.find(ask=>ask.askId===id);entry.fieldset.disabled=entry.submitting||ask?.status!=='pending'||state.preparing||state.closed||!state.receipt||!options.access.capability;}
264
+ screen?.recordForms?.([...record.forms.values()].map(entry=>entry.form));
265
+ }
266
+ return {
267
+ prepare,
268
+ mounted: () => mounted,
269
+ report:(error:unknown,fallback?:string)=>screen?.message(options.refusal(error,fallback),true),
270
+ commit(prepared: JobRigScreenPrepared) {
271
+ const previous=mounted;mounted=prepared;
272
+ return {async rollback(){try{await transition?.rollback();}finally{transition=null;mounted=previous;}},finalize(){try{transition?.finalize();}finally{transition=null;if(previous!==prepared){const modal=previous?.record??previous?.modals;for(const entry of modal?.forms.values()??[])entry.dispose?.();modal?.inspection.dispose();}}}};
273
+ },
274
+ /** The rig composition draws first; the job acknowledges the display after. */
275
+ async painted(prepared: JobRigScreenPrepared, signal: AbortSignal): Promise<void> {
276
+ let ready!: {resolve(): void; reject(error: unknown): void};
277
+ const shown = new Promise<void>((resolve, reject) => {ready = {resolve, reject};});
278
+ const previous=screen,previousNodes=[...options.host.childNodes??[]],previousHost=rigHost();
279
+ const navigation=previousHost?.record||prepared.record?undefined:previous?.navigation?.();previous?.suspend?.();
280
+ const previousTitle=document.title,previousUrl=typeof location==='undefined'?null:location.href;
281
+ const previousReady=document.body?.getAttribute('data-ready')??null,previousInert=document.body?.inert;
282
+ let candidate:{dispose?():void}|undefined,finished=false,recovery:Promise<void>|null=null;
283
+ const rollback=():Promise<void>=>{
284
+ if(finished)return recovery??Promise.resolve();finished=true;
285
+ if(candidate?.dispose)candidate.dispose();else if(screen!==previous)screen?.dispose?.();screen=previous;
286
+ options.host.replaceChildren(...previousNodes);setRigHost(previousHost);document.title=previousTitle;
287
+ if(previousUrl)history.replaceState(null,'',previousUrl);
288
+ if(document.body){if(previousReady===null)document.body.removeAttribute('data-ready');else document.body.setAttribute('data-ready',previousReady);document.body.inert=previousInert??false;}
289
+ recovery=Promise.resolve(previous?.resume?.());return recovery;
290
+ };
291
+ transition={rollback,finalize(){if(finished)return;finished=true;previous?.dispose?.();}};
292
+ try {
293
+ setRigHost(host(prepared, ready,navigation));
294
+ const app = document.createElement('div');app.id = 'app';
295
+ options.host.classList.remove('job-window');options.host.replaceChildren(app);document.body?.removeAttribute('data-ready');
296
+ const loaded=await options.load();
297
+ if(loaded&&typeof loaded==='object')candidate=loaded as {dispose?():void};
298
+ await shown;
299
+ if (signal.aborted) throw new Error('JOB_PRELOAD_CANCELLED');
300
+ }catch(error){await rollback();throw error;}
301
+ },
302
+ /** A newly pending ask the screen cannot answer, or a later publication, reloads into the job window's route. */
303
+ changed(state: {readonly pending: readonly PendingAskV3[]; readonly closed: boolean; readonly preparing?:boolean; readonly error?:string|null; readonly previousLabel?:string|null; readonly displayed?:DisplayPublicationV3|null}): void {
304
+ if (!mounted) return;
305
+ if(mounted.record){refreshRecordForms();if(state.closed)screen?.message(options.translate('job.closed'),true);return;}
306
+ if (!jobRigScreenRoute(mounted.display, state.pending, mounted.checkpoints)) {location.reload(); return;}
307
+ screen?.pendingSubjects?.(pendingSubjects());
308
+ refreshRecordForms();
309
+ if(state.error)screen?.message(options.translate('job.failed')+' · '+options.refusal(state.error),true);
310
+ else if (state.closed) screen?.message(options.translate('job.closed'), true);
311
+ else if(!state.preparing&&state.displayed?.publication.publicationId===mounted.display.publication.publicationId){
312
+ const label=state.previousLabel?options.translate('job.updated',[state.previousLabel,mounted.display.publication.label]):mounted.display.publication.label;
313
+ screen?.message(label+(screen.incompatible?.()?' · '+options.translate('job.incompatible'):''));
314
+ }
315
+ },
316
+ };
317
+ }