@rig-c/review 2.7.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/PARTS_VIEW.md +103 -66
- package/docs/REVIEW_PACKAGE.md +32 -17
- package/docs/STABILITY.md +85 -4
- package/docs/WORKFLOWS.md +1 -1
- package/package.json +3 -3
- package/src/build.ts +10 -2
- package/src/cli.ts +4 -5
- package/src/correction-handoff.ts +27 -4
- package/src/feedback-export.ts +1 -1
- package/src/front.ts +2 -1
- package/src/handoff.ts +1 -1
- package/src/interview-project.ts +173 -10
- package/src/job-act.ts +101 -33
- package/src/job-api.ts +194 -13
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +203 -19
- package/src/job-front.ts +270 -34
- package/src/job-host.ts +123 -1
- package/src/job-session.ts +227 -47
- package/src/job-source.ts +88 -16
- package/src/manifest.ts +9 -0
- package/src/open-workspace-launch.ts +2 -2
- package/src/open.ts +2 -1
- package/src/parts-comment-crops.ts +126 -31
- package/src/parts-comment.ts +321 -28
- package/src/parts-view.ts +485 -89
- package/src/stage-comment.ts +9 -1
- package/src/stage-parts.ts +5 -1
- package/src/versions.ts +7 -7
- package/web/catalog-en.ts +37 -1
- package/web/catalog-ko.ts +37 -1
- package/web/job-session.ts +830 -161
- package/web/parts-page.ts +217 -0
- package/web/parts-render.ts +26 -19
- package/web/parts-viewport-provider.ts +13 -1
- package/web/parts.css +13 -1
- package/web/parts.html +4 -38
- package/web/parts.ts +644 -267
- package/web/stage-comments.ts +77 -23
- package/web/styles.css +10 -2
- package/web/viewport-controller.ts +13 -4
package/src/job-session.ts
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
-
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
-
JOB_API_SCHEMA,
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_RECORD_READER_ID, jobStillByteLimit, JOB_CAPABILITIES, JOB_CAPABILITIES_V3, JOB_ENABLED_ACT_KINDS,
|
|
5
|
+
type ActV3, type AgentRequestV3, type EventV3, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
|
|
6
|
+
type JobDisplayPublication, type JobDisplayPublicationV3, type JobDisplayReceipt, type JobEvent, type JobFetchActRequest, type JobFetchActRequestV3,
|
|
7
|
+
type JobNextValue, type JobPendingAsk, type JobPublication, type JobPublicationMode, type JobReviewerBinding,
|
|
8
|
+
type NextValueV3, type PendingAskV3, type PublicationV3, type RecordPublicationReader, type RecordSubject, type StatusV3,
|
|
7
9
|
} from './job-contract.ts';
|
|
8
|
-
import { bindJobAsk, finalizeJobAct, parseUISubmission, prepareJobStill } from './job-act.ts';
|
|
9
|
-
import { jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
10
|
+
import { bindJobAsk, bindJobRecordAsk, finalizeJobAct, parseUISubmission, prepareJobRecordAct, prepareJobStill } from './job-act.ts';
|
|
11
|
+
import { jobApiSchemaForMode, jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
10
12
|
import {
|
|
11
|
-
assertJobRoot, assertJobSourceCurrent, captureJobRoot, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot,
|
|
12
|
-
type JobPublicationReader, type JobRetainedSource, type JobRootIdentity,
|
|
13
|
+
assertJobRoot, assertJobSourceCurrent, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot, verifyJobRecordSourceFresh,
|
|
14
|
+
type JobPublicationReader, type JobRetainedSource, type JobRetainedSourceV3, type JobRootIdentity,
|
|
13
15
|
} from './job-source.ts';
|
|
14
16
|
import { JobError, JobStore, type JobSnapshotOwner, type StoredJob } from './job-store.ts';
|
|
15
17
|
import { canonicalStatePath } from './state-dir.ts';
|
|
18
|
+
import { loadReview } from './manifest.ts';
|
|
19
|
+
import { loadPartsView } from './parts-view.ts';
|
|
20
|
+
import { validateStoredPartsComment } from './parts-comment-crops.ts';
|
|
21
|
+
|
|
22
|
+
export type { JobDisplayPublicationV3 } from './job-contract.ts';
|
|
23
|
+
|
|
24
|
+
type JobEventPayload =
|
|
25
|
+
| { readonly type: 'published'; readonly publication: JobPublication | PublicationV3 }
|
|
26
|
+
| { readonly type: 'pending'; readonly ask: JobPendingAsk | PendingAskV3 }
|
|
27
|
+
| { readonly type: 'act'; readonly act: JobAct | ActV3 }
|
|
28
|
+
| { readonly type: 'closed'; readonly reason: string };
|
|
16
29
|
|
|
17
30
|
interface StoredPublication {
|
|
18
|
-
publication: JobPublication;
|
|
19
|
-
retained:
|
|
31
|
+
publication: JobPublication | PublicationV3;
|
|
32
|
+
retained: JobRetainedSourceV3;
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
interface Replay {
|
|
@@ -36,9 +49,9 @@ interface JobData {
|
|
|
36
49
|
generation: number;
|
|
37
50
|
head: string | null;
|
|
38
51
|
publications: Record<string, StoredPublication>;
|
|
39
|
-
asks: Record<string, JobPendingAsk>;
|
|
40
|
-
acts: Record<string, JobAct>;
|
|
41
|
-
events: JobEvent[];
|
|
52
|
+
asks: Record<string, JobPendingAsk | PendingAskV3>;
|
|
53
|
+
acts: Record<string, JobAct | ActV3>;
|
|
54
|
+
events: (JobEvent | EventV3)[];
|
|
42
55
|
replays: Record<string, Replay>;
|
|
43
56
|
pages: Record<string, JobDisplayReceipt>;
|
|
44
57
|
}
|
|
@@ -50,7 +63,10 @@ export interface JobSessionOptions {
|
|
|
50
63
|
readonly stateDir: string;
|
|
51
64
|
readonly fingerprint: string;
|
|
52
65
|
readonly reviewer: JobReviewerBinding;
|
|
66
|
+
readonly publicationMode?: JobPublicationMode;
|
|
53
67
|
readonly readPublished?: JobPublicationReader;
|
|
68
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
69
|
+
readonly recordReaderId?: typeof JOB_RECORD_READER_ID | (string & {});
|
|
54
70
|
readonly partsEnumerator?: JobPartsEnumerator;
|
|
55
71
|
/** Deterministic boundary hook for disposable concurrency controls only. */
|
|
56
72
|
readonly afterSnapshot?: () => void | Promise<void>;
|
|
@@ -74,6 +90,8 @@ function within(root: string, path: string): boolean {
|
|
|
74
90
|
*/
|
|
75
91
|
export class JobSession {
|
|
76
92
|
readonly jobId: string;
|
|
93
|
+
readonly publicationMode: JobPublicationMode;
|
|
94
|
+
readonly apiSchema: typeof JOB_API_SCHEMA | typeof JOB_API_V3_SCHEMA;
|
|
77
95
|
private readonly store: JobStore<JobData>;
|
|
78
96
|
private readonly listeners = new Set<() => void>();
|
|
79
97
|
private operations = 0;
|
|
@@ -88,6 +106,16 @@ export class JobSession {
|
|
|
88
106
|
}
|
|
89
107
|
|
|
90
108
|
constructor(private readonly options: JobSessionOptions, readonlyTarget?: { readonly jobId: string }) {
|
|
109
|
+
if (options.publicationMode !== undefined &&
|
|
110
|
+
options.publicationMode !== 'package-only' &&
|
|
111
|
+
options.publicationMode !== 'record-and-package') {
|
|
112
|
+
throw new JobError('JOB_REQUEST_INVALID');
|
|
113
|
+
}
|
|
114
|
+
if (options.readRecordPublished !== undefined && typeof options.readRecordPublished !== 'function') {
|
|
115
|
+
throw new JobError('JOB_REQUEST_INVALID');
|
|
116
|
+
}
|
|
117
|
+
this.publicationMode = options.publicationMode ?? (options.readRecordPublished ? 'record-and-package' : 'package-only');
|
|
118
|
+
this.apiSchema = jobApiSchemaForMode(this.publicationMode);
|
|
91
119
|
const root = captureJobRoot(options.root), state = canonicalStatePath(options.stateDir);
|
|
92
120
|
if (within(root.path, state)) {
|
|
93
121
|
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Job state must be outside the designated work root');
|
|
@@ -184,7 +212,7 @@ export class JobSession {
|
|
|
184
212
|
if (role === 'ui' && !current.active) throw new JobError('JOB_CLOSED');
|
|
185
213
|
}
|
|
186
214
|
|
|
187
|
-
status():
|
|
215
|
+
status(): StatusV3 {
|
|
188
216
|
const current = this.current(), data = current.data;
|
|
189
217
|
return {
|
|
190
218
|
jobId: this.jobId, generation: data.generation, status: current.active ? 'active' : 'closed',
|
|
@@ -226,6 +254,14 @@ export class JobSession {
|
|
|
226
254
|
}
|
|
227
255
|
|
|
228
256
|
retainedSource(publicationId: string): JobRetainedSource {
|
|
257
|
+
const retained = this.retainedSourceV3(publicationId);
|
|
258
|
+
if (isRetainedRecordSource(retained)) {
|
|
259
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Record publication has no package manifest');
|
|
260
|
+
}
|
|
261
|
+
return retained;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
retainedSourceV3(publicationId: string): JobRetainedSourceV3 {
|
|
229
265
|
const current = this.current();
|
|
230
266
|
if (!current.active) throw new JobError('JOB_CLOSED');
|
|
231
267
|
const stored = current.data.publications[publicationId];
|
|
@@ -233,7 +269,7 @@ export class JobSession {
|
|
|
233
269
|
return stored.retained;
|
|
234
270
|
}
|
|
235
271
|
|
|
236
|
-
displayPublication(publicationId: string):
|
|
272
|
+
displayPublication(publicationId: string): JobDisplayPublicationV3 {
|
|
237
273
|
const current = this.current();
|
|
238
274
|
if (!current.active) throw new JobError('JOB_CLOSED');
|
|
239
275
|
const stored = current.data.publications[publicationId];
|
|
@@ -244,8 +280,8 @@ export class JobSession {
|
|
|
244
280
|
|
|
245
281
|
/** Internal front seam. A count covers preparation and the entire file stream. */
|
|
246
282
|
async readPublicationResponse(publicationId: string,
|
|
247
|
-
read: (retained:
|
|
248
|
-
const retained = this.
|
|
283
|
+
read: (retained: JobRetainedSourceV3) => Promise<Response>): Promise<Response> {
|
|
284
|
+
const retained = this.retainedSourceV3(publicationId);
|
|
249
285
|
const readId = this.store.beginSnapshotRead(this.jobId, publicationId,
|
|
250
286
|
jobSnapshotHash(retained.seals), retained.snapshotRoot);
|
|
251
287
|
this.operations++;
|
|
@@ -334,17 +370,18 @@ export class JobSession {
|
|
|
334
370
|
assertJobRoot(current.data.root);
|
|
335
371
|
}
|
|
336
372
|
|
|
337
|
-
private event(data: JobData, value:
|
|
338
|
-
const event = { ...value, cursor: randomUUID(), jobId: this.jobId, generation: data.generation }
|
|
373
|
+
private event(data: JobData, value: JobEventPayload): EventV3 {
|
|
374
|
+
const event: EventV3 = { ...value, cursor: randomUUID(), jobId: this.jobId, generation: data.generation };
|
|
339
375
|
if (Buffer.byteLength(JSON.stringify(event)) > maximumEventBytes) {
|
|
340
376
|
throw new JobError('JOB_BODY_LIMIT', 'Job event exceeds its delivery bound');
|
|
341
377
|
}
|
|
342
378
|
data.events.push(event);
|
|
379
|
+
return event;
|
|
343
380
|
}
|
|
344
381
|
|
|
345
382
|
private notify(): void { for (const listener of this.listeners) listener(); }
|
|
346
383
|
|
|
347
|
-
async execute(input: JobAgentRequest | JobFetchActRequest, signal: AbortSignal): Promise<unknown> {
|
|
384
|
+
async execute(input: JobAgentRequest | AgentRequestV3 | JobFetchActRequest | JobFetchActRequestV3, signal: AbortSignal): Promise<unknown> {
|
|
348
385
|
if (input.jobId !== this.jobId) throw new JobError('JOB_UNKNOWN');
|
|
349
386
|
if (input.verb === 'next') return this.next(input.after, input.waitMs, signal);
|
|
350
387
|
if (input.verb === 'fetch-act') {
|
|
@@ -380,8 +417,17 @@ export class JobSession {
|
|
|
380
417
|
}, fresh => {
|
|
381
418
|
this.active(fresh, input.expectedGeneration);
|
|
382
419
|
fresh.data.generation++;
|
|
383
|
-
|
|
384
|
-
|
|
420
|
+
const event: JobEvent = {
|
|
421
|
+
type: 'closed',
|
|
422
|
+
reason: input.reason,
|
|
423
|
+
cursor: randomUUID(),
|
|
424
|
+
jobId: this.jobId,
|
|
425
|
+
generation: fresh.data.generation,
|
|
426
|
+
};
|
|
427
|
+
if (Buffer.byteLength(JSON.stringify(event)) > maximumEventBytes) {
|
|
428
|
+
throw new JobError('JOB_BODY_LIMIT', 'Job event exceeds its delivery bound');
|
|
429
|
+
}
|
|
430
|
+
fresh.data.events.push(event);
|
|
385
431
|
const value = {status: 'closed', cursor: event.cursor};
|
|
386
432
|
return {generation: fresh.data.generation, event, replayKey: key, replay: {digest, value}};
|
|
387
433
|
});
|
|
@@ -390,14 +436,48 @@ export class JobSession {
|
|
|
390
436
|
return closure.replay.value;
|
|
391
437
|
} finally { this.finishOperation(); }
|
|
392
438
|
}
|
|
393
|
-
let candidate:
|
|
439
|
+
let candidate: JobRetainedSourceV3 | null = null;
|
|
394
440
|
this.operations++;
|
|
395
441
|
try {
|
|
396
442
|
if (input.verb === 'publish') {
|
|
397
|
-
candidate =
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
443
|
+
candidate = input.schema === JOB_API_V3_SCHEMA
|
|
444
|
+
? await prepareJobSource({
|
|
445
|
+
root: current.data.root,
|
|
446
|
+
stateRoot: this.store.root,
|
|
447
|
+
fingerprint: current.data.fingerprint,
|
|
448
|
+
request: input,
|
|
449
|
+
readPublished: this.options.readPublished,
|
|
450
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
451
|
+
partsEnumerator: this.options.partsEnumerator,
|
|
452
|
+
afterSnapshot: this.options.afterSnapshot,
|
|
453
|
+
afterDirectorySync: this.options.afterDirectorySync,
|
|
454
|
+
})
|
|
455
|
+
: await prepareJobSource({
|
|
456
|
+
root: current.data.root,
|
|
457
|
+
stateRoot: this.store.root,
|
|
458
|
+
fingerprint: current.data.fingerprint,
|
|
459
|
+
request: input,
|
|
460
|
+
readPublished: this.options.readPublished,
|
|
461
|
+
partsEnumerator: this.options.partsEnumerator,
|
|
462
|
+
afterSnapshot: this.options.afterSnapshot,
|
|
463
|
+
afterDirectorySync: this.options.afterDirectorySync,
|
|
464
|
+
});
|
|
465
|
+
} else if (input.verb === 'ask') {
|
|
466
|
+
if (current.data.head === input.publicationId) {
|
|
467
|
+
const stored = current.data.publications[input.publicationId];
|
|
468
|
+
if (stored && isRetainedRecordSource(stored.retained)) {
|
|
469
|
+
bindJobRecordAsk(input.subject, stored.retained);
|
|
470
|
+
if (!this.options.readRecordPublished) {
|
|
471
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Record publication requires a trusted record reader');
|
|
472
|
+
}
|
|
473
|
+
await verifyJobRecordSourceFresh({
|
|
474
|
+
retained: stored.retained,
|
|
475
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
476
|
+
phase: 'ask',
|
|
477
|
+
subject: input.subject as RecordSubject,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
401
481
|
}
|
|
402
482
|
if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
|
|
403
483
|
current = this.current();
|
|
@@ -410,9 +490,18 @@ export class JobSession {
|
|
|
410
490
|
switch (input.verb) {
|
|
411
491
|
case 'publish': {
|
|
412
492
|
assertJobSourceCurrent(candidate!);
|
|
413
|
-
|
|
493
|
+
if (isRetainedRecordSource(candidate!)) {
|
|
494
|
+
assertRetainedSnapshotIntact(
|
|
495
|
+
candidate!.snapshotRoot,
|
|
496
|
+
candidate!.seals,
|
|
497
|
+
candidate!.snapshotIdentity,
|
|
498
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
const publication: JobPublication | PublicationV3 = {
|
|
414
502
|
publicationId: randomUUID(), instanceKey: candidate!.instanceKey, generation: data.generation,
|
|
415
503
|
source: candidate!.source, label: candidate!.label, previousPublicationId: data.head, visual: candidate!.visual,
|
|
504
|
+
...(!isRetainedRecordSource(candidate!) && candidate!.interview !== undefined ? { interview: candidate!.interview } : {}),
|
|
416
505
|
};
|
|
417
506
|
for (const ask of Object.values(data.asks)) {
|
|
418
507
|
if (ask.status === 'pending') data.asks[ask.askId] = { ...ask, status: 'superseded' };
|
|
@@ -421,7 +510,7 @@ export class JobSession {
|
|
|
421
510
|
snapshot = {publicationId: publication.publicationId, snapshotHash: jobSnapshotHash(candidate!.seals),
|
|
422
511
|
snapshotRoot: candidate!.snapshotRoot, ...candidate!.snapshotIdentity!};
|
|
423
512
|
data.head = publication.publicationId;
|
|
424
|
-
this.event(data, { type: 'published', publication }
|
|
513
|
+
this.event(data, { type: 'published', publication });
|
|
425
514
|
result = publication;
|
|
426
515
|
break;
|
|
427
516
|
}
|
|
@@ -429,10 +518,31 @@ export class JobSession {
|
|
|
429
518
|
if (data.head !== input.publicationId) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
430
519
|
const retained = data.publications[input.publicationId].retained;
|
|
431
520
|
assertJobSourceCurrent(retained);
|
|
432
|
-
|
|
433
|
-
|
|
521
|
+
if (isRetainedRecordSource(retained)) {
|
|
522
|
+
assertRetainedSnapshotIntact(
|
|
523
|
+
retained.snapshotRoot,
|
|
524
|
+
retained.seals,
|
|
525
|
+
retained.snapshotIdentity,
|
|
526
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
const ask: JobPendingAsk | PendingAskV3 = isRetainedRecordSource(retained)
|
|
530
|
+
? {
|
|
531
|
+
askId: randomUUID(),
|
|
532
|
+
publicationId: input.publicationId,
|
|
533
|
+
subject: input.subject,
|
|
534
|
+
source: bindJobRecordAsk(input.subject, retained),
|
|
535
|
+
status: 'pending',
|
|
536
|
+
}
|
|
537
|
+
: {
|
|
538
|
+
askId: randomUUID(),
|
|
539
|
+
publicationId: input.publicationId,
|
|
540
|
+
subject: input.subject,
|
|
541
|
+
source: bindJobAsk(input.subject, retained),
|
|
542
|
+
status: 'pending',
|
|
543
|
+
};
|
|
434
544
|
data.asks[ask.askId] = ask;
|
|
435
|
-
this.event(data, { type: 'pending', ask }
|
|
545
|
+
this.event(data, { type: 'pending', ask });
|
|
436
546
|
result = ask;
|
|
437
547
|
break;
|
|
438
548
|
}
|
|
@@ -492,12 +602,68 @@ export class JobSession {
|
|
|
492
602
|
return receipt!;
|
|
493
603
|
}
|
|
494
604
|
|
|
495
|
-
async commitUIAct(raw: unknown): Promise<
|
|
496
|
-
const
|
|
605
|
+
async commitUIAct(raw: unknown): Promise<ActV3> {
|
|
606
|
+
const parsed = parseUISubmission(raw, this.publicationMode);
|
|
607
|
+
const input = parsed.kind === 'parts-verdict' ? {...parsed, value: structuredClone(parsed.value)} : parsed;
|
|
608
|
+
const digest = requestDigest(input), key = `ui:${input.pageId}:${input.submissionId}`;
|
|
497
609
|
const current = this.current();
|
|
498
610
|
const previous = this.replay(current.data, key, digest);
|
|
499
|
-
if (previous) return previous.value as
|
|
500
|
-
|
|
611
|
+
if (previous) return previous.value as ActV3;
|
|
612
|
+
if (current.active && input.expectedGeneration <= current.data.generation) {
|
|
613
|
+
const page = current.data.pages[input.pageId];
|
|
614
|
+
if (page && page.publicationId === input.publicationId && sameCapability(input.displayedNonce, page.displayedNonce) &&
|
|
615
|
+
current.data.head === input.publicationId) {
|
|
616
|
+
const ask = current.data.asks[input.askId];
|
|
617
|
+
const stored = current.data.publications[input.publicationId];
|
|
618
|
+
if (ask && stored && isRetainedRecordSource(stored.retained)) {
|
|
619
|
+
prepareJobRecordAct({
|
|
620
|
+
jobId: this.jobId,
|
|
621
|
+
submission: input,
|
|
622
|
+
ask,
|
|
623
|
+
retained: stored.retained,
|
|
624
|
+
reviewer: current.data.reviewer,
|
|
625
|
+
});
|
|
626
|
+
if (!this.options.readRecordPublished) {
|
|
627
|
+
throw new JobError('JOB_ACT_SOURCE_STALE', 'Record publication requires a trusted record reader');
|
|
628
|
+
}
|
|
629
|
+
await verifyJobRecordSourceFresh({
|
|
630
|
+
retained: stored.retained,
|
|
631
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
632
|
+
phase: 'finalize',
|
|
633
|
+
subject: ask.subject as RecordSubject,
|
|
634
|
+
});
|
|
635
|
+
} else if (ask && stored && input.kind === 'parts-verdict') {
|
|
636
|
+
assertJobSourceCurrent(stored.retained);
|
|
637
|
+
const candidate = finalizeJobAct({jobId: this.jobId, submission: input, ask,
|
|
638
|
+
retained: stored.retained, reviewer: current.data.reviewer});
|
|
639
|
+
if (candidate.schema === JOB_PARTS_VERDICT_ACT_SCHEMA && candidate.value.issues.length) {
|
|
640
|
+
await this.readPublicationResponse(input.publicationId, async retained => {
|
|
641
|
+
if (isRetainedRecordSource(retained) || !retained.source.parts) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
642
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals,
|
|
643
|
+
retained.snapshotIdentity, 'JOB_ACT_SOURCE_STALE');
|
|
644
|
+
try {
|
|
645
|
+
const review = await loadReview(retained.manifestPath);
|
|
646
|
+
const painting = review.handoff?.source;
|
|
647
|
+
const sealedPainting = painting && retained.seals.some(file =>
|
|
648
|
+
file.path === relative(retained.snapshotRoot, painting).split(sep).join('/')) ? painting : undefined;
|
|
649
|
+
const pkg = await loadPartsView(dirname(join(retained.snapshotRoot, retained.source.parts.manifest.path)),
|
|
650
|
+
{painting: sealedPainting, paintingRoot: retained.snapshotRoot});
|
|
651
|
+
for (const issue of candidate.value.issues) {
|
|
652
|
+
await validateStoredPartsComment(pkg, issue, false, {sourceHash: retained.source.sourceHash});
|
|
653
|
+
}
|
|
654
|
+
} catch (error) {
|
|
655
|
+
if (error instanceof JobError) throw error;
|
|
656
|
+
throw new JobError('JOB_ACT_INVALID');
|
|
657
|
+
}
|
|
658
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals,
|
|
659
|
+
retained.snapshotIdentity, 'JOB_ACT_SOURCE_STALE');
|
|
660
|
+
return new Response(null, {status: 204});
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
let act: ActV3;
|
|
501
667
|
this.store.update(this.jobId, null, fresh => {
|
|
502
668
|
// UI captures an observed generation. Unrelated asks may advance it while
|
|
503
669
|
// this same ask/source/publication/nonce stays valid. Agent mutation CAS
|
|
@@ -513,15 +679,23 @@ export class JobSession {
|
|
|
513
679
|
if (!ask) throw new JobError('JOB_ASK_INVALID');
|
|
514
680
|
const retained = fresh.data.publications[input.publicationId].retained;
|
|
515
681
|
assertJobSourceCurrent(retained);
|
|
516
|
-
|
|
517
|
-
|
|
682
|
+
if (isRetainedRecordSource(retained) || input.kind === 'parts-verdict') {
|
|
683
|
+
assertRetainedSnapshotIntact(
|
|
684
|
+
retained.snapshotRoot,
|
|
685
|
+
retained.seals,
|
|
686
|
+
retained.snapshotIdentity,
|
|
687
|
+
'JOB_ACT_SOURCE_STALE',
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
const captured = !isRetainedRecordSource(retained) && ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review' ?
|
|
691
|
+
prepareJobStill(input, ask as JobPendingAsk, retained) : undefined;
|
|
518
692
|
act = finalizeJobAct({ jobId: this.jobId, submission: input, ask, retained, reviewer: fresh.data.reviewer,
|
|
519
693
|
still: captured?.still });
|
|
520
694
|
fresh.data.generation++;
|
|
521
695
|
fresh.data.acts[act.actId] = act;
|
|
522
696
|
fresh.data.asks[ask.askId] = { ...ask, status: 'answered' };
|
|
523
697
|
fresh.data.replays[key] = { digest, value: act };
|
|
524
|
-
this.event(fresh.data, { type: 'act', act }
|
|
698
|
+
this.event(fresh.data, { type: 'act', act });
|
|
525
699
|
return { data: fresh.data, ...(captured ? {still: {
|
|
526
700
|
actId: act.actId, pageId: input.pageId, submissionId: input.submissionId,
|
|
527
701
|
sha256: captured.still.sha256, binding: JSON.stringify(captured.binding),
|
|
@@ -530,18 +704,18 @@ export class JobSession {
|
|
|
530
704
|
}, fresh => {
|
|
531
705
|
const raced = this.replay(fresh.data, key, digest);
|
|
532
706
|
if (!raced) return false;
|
|
533
|
-
act = raced.value as
|
|
707
|
+
act = raced.value as ActV3;
|
|
534
708
|
return true;
|
|
535
709
|
});
|
|
536
710
|
this.notify();
|
|
537
711
|
return act!;
|
|
538
712
|
}
|
|
539
713
|
|
|
540
|
-
private events(after: string | null): JobNextValue {
|
|
714
|
+
private events(after: string | null): JobNextValue | NextValueV3 {
|
|
541
715
|
const current = this.current(), events = current.data.events;
|
|
542
716
|
const index = after === null ? -1 : events.findIndex(event => event.cursor === after);
|
|
543
717
|
if (after !== null && index < 0) throw new JobError('JOB_CURSOR_INVALID');
|
|
544
|
-
const batch:
|
|
718
|
+
const batch: EventV3[] = [];
|
|
545
719
|
let size = 0;
|
|
546
720
|
for (const event of events.slice(index + 1, index + 65)) {
|
|
547
721
|
const bytes = Buffer.byteLength(JSON.stringify(event));
|
|
@@ -550,11 +724,17 @@ export class JobSession {
|
|
|
550
724
|
size += bytes;
|
|
551
725
|
batch.push(event);
|
|
552
726
|
}
|
|
553
|
-
|
|
554
|
-
|
|
727
|
+
const cursor = batch.at(-1)?.cursor ?? after;
|
|
728
|
+
const status = batch.length ? 'events' : current.active ? 'timeout' : 'closed';
|
|
729
|
+
return {
|
|
730
|
+
capabilities: this.publicationMode === 'record-and-package' ? JOB_CAPABILITIES_V3 : JOB_CAPABILITIES,
|
|
731
|
+
events: batch,
|
|
732
|
+
cursor,
|
|
733
|
+
status,
|
|
734
|
+
};
|
|
555
735
|
}
|
|
556
736
|
|
|
557
|
-
private async next(after: string | null, waitMs: number, signal: AbortSignal): Promise<JobNextValue> {
|
|
737
|
+
private async next(after: string | null, waitMs: number, signal: AbortSignal): Promise<JobNextValue | NextValueV3> {
|
|
558
738
|
if (waitMs < 0 || waitMs > jobWaitLimitMs || !Number.isSafeInteger(waitMs)) throw new JobError('JOB_REQUEST_INVALID');
|
|
559
739
|
if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
|
|
560
740
|
const ready = this.events(after);
|
|
@@ -571,11 +751,11 @@ export class JobSession {
|
|
|
571
751
|
return this.events(after);
|
|
572
752
|
}
|
|
573
753
|
|
|
574
|
-
async *subscribe(input: { readonly jobId: string; readonly after: string | null; readonly signal: AbortSignal }): AsyncIterable<
|
|
754
|
+
async *subscribe(input: { readonly jobId: string; readonly after: string | null; readonly signal: AbortSignal }): AsyncIterable<EventV3> {
|
|
575
755
|
if (input.jobId !== this.jobId) throw new JobError('JOB_UNKNOWN');
|
|
576
756
|
let after = input.after;
|
|
577
757
|
while (!input.signal.aborted) {
|
|
578
|
-
let value: JobNextValue;
|
|
758
|
+
let value: JobNextValue | NextValueV3;
|
|
579
759
|
try { value = await this.next(after, jobWaitLimitMs, input.signal); }
|
|
580
760
|
catch (error) {
|
|
581
761
|
if (input.signal.aborted && error instanceof JobError && error.code === 'JOB_REQUEST_INVALID') return;
|