rig-review 2.7.1 → 3.7.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/DESIGN.md +1 -1
- package/docs/REVIEW_PACKAGE.md +29 -13
- package/docs/STABILITY.md +81 -5
- package/docs/WORKFLOWS.md +2 -2
- package/package.json +3 -3
- package/skills/rig-review/SKILL.md +1 -1
- package/src/build.ts +10 -2
- package/src/front.ts +2 -1
- package/src/interview-project.ts +173 -10
- package/src/job-act.ts +59 -11
- package/src/job-api.ts +194 -13
- package/src/job-contract.ts +118 -8
- package/src/job-front.ts +165 -26
- package/src/job-host.ts +118 -1
- package/src/job-session.ts +193 -46
- package/src/job-source.ts +88 -16
- package/src/open-workspace-launch.ts +2 -2
- package/src/open.ts +2 -1
- package/src/versions.ts +7 -7
- package/web/catalog-en.ts +2 -1
- package/web/catalog-ko.ts +2 -1
- package/web/job-session.ts +483 -84
package/src/job-session.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
2
|
import { isAbsolute, relative, sep } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
-
JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_CAPABILITIES,
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_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';
|
|
16
18
|
|
|
19
|
+
export type { JobDisplayPublicationV3 } from './job-contract.ts';
|
|
20
|
+
|
|
21
|
+
type JobEventPayload =
|
|
22
|
+
| { readonly type: 'published'; readonly publication: JobPublication | PublicationV3 }
|
|
23
|
+
| { readonly type: 'pending'; readonly ask: JobPendingAsk | PendingAskV3 }
|
|
24
|
+
| { readonly type: 'act'; readonly act: JobAct | ActV3 }
|
|
25
|
+
| { readonly type: 'closed'; readonly reason: string };
|
|
26
|
+
|
|
17
27
|
interface StoredPublication {
|
|
18
|
-
publication: JobPublication;
|
|
19
|
-
retained:
|
|
28
|
+
publication: JobPublication | PublicationV3;
|
|
29
|
+
retained: JobRetainedSourceV3;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
interface Replay {
|
|
@@ -36,9 +46,9 @@ interface JobData {
|
|
|
36
46
|
generation: number;
|
|
37
47
|
head: string | null;
|
|
38
48
|
publications: Record<string, StoredPublication>;
|
|
39
|
-
asks: Record<string, JobPendingAsk>;
|
|
40
|
-
acts: Record<string, JobAct>;
|
|
41
|
-
events: JobEvent[];
|
|
49
|
+
asks: Record<string, JobPendingAsk | PendingAskV3>;
|
|
50
|
+
acts: Record<string, JobAct | ActV3>;
|
|
51
|
+
events: (JobEvent | EventV3)[];
|
|
42
52
|
replays: Record<string, Replay>;
|
|
43
53
|
pages: Record<string, JobDisplayReceipt>;
|
|
44
54
|
}
|
|
@@ -50,7 +60,10 @@ export interface JobSessionOptions {
|
|
|
50
60
|
readonly stateDir: string;
|
|
51
61
|
readonly fingerprint: string;
|
|
52
62
|
readonly reviewer: JobReviewerBinding;
|
|
63
|
+
readonly publicationMode?: JobPublicationMode;
|
|
53
64
|
readonly readPublished?: JobPublicationReader;
|
|
65
|
+
readonly readRecordPublished?: RecordPublicationReader;
|
|
66
|
+
readonly recordReaderId?: typeof JOB_RECORD_READER_ID | (string & {});
|
|
54
67
|
readonly partsEnumerator?: JobPartsEnumerator;
|
|
55
68
|
/** Deterministic boundary hook for disposable concurrency controls only. */
|
|
56
69
|
readonly afterSnapshot?: () => void | Promise<void>;
|
|
@@ -74,6 +87,8 @@ function within(root: string, path: string): boolean {
|
|
|
74
87
|
*/
|
|
75
88
|
export class JobSession {
|
|
76
89
|
readonly jobId: string;
|
|
90
|
+
readonly publicationMode: JobPublicationMode;
|
|
91
|
+
readonly apiSchema: typeof JOB_API_SCHEMA | typeof JOB_API_V3_SCHEMA;
|
|
77
92
|
private readonly store: JobStore<JobData>;
|
|
78
93
|
private readonly listeners = new Set<() => void>();
|
|
79
94
|
private operations = 0;
|
|
@@ -88,6 +103,16 @@ export class JobSession {
|
|
|
88
103
|
}
|
|
89
104
|
|
|
90
105
|
constructor(private readonly options: JobSessionOptions, readonlyTarget?: { readonly jobId: string }) {
|
|
106
|
+
if (options.publicationMode !== undefined &&
|
|
107
|
+
options.publicationMode !== 'package-only' &&
|
|
108
|
+
options.publicationMode !== 'record-and-package') {
|
|
109
|
+
throw new JobError('JOB_REQUEST_INVALID');
|
|
110
|
+
}
|
|
111
|
+
if (options.readRecordPublished !== undefined && typeof options.readRecordPublished !== 'function') {
|
|
112
|
+
throw new JobError('JOB_REQUEST_INVALID');
|
|
113
|
+
}
|
|
114
|
+
this.publicationMode = options.publicationMode ?? (options.readRecordPublished ? 'record-and-package' : 'package-only');
|
|
115
|
+
this.apiSchema = jobApiSchemaForMode(this.publicationMode);
|
|
91
116
|
const root = captureJobRoot(options.root), state = canonicalStatePath(options.stateDir);
|
|
92
117
|
if (within(root.path, state)) {
|
|
93
118
|
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Job state must be outside the designated work root');
|
|
@@ -184,7 +209,7 @@ export class JobSession {
|
|
|
184
209
|
if (role === 'ui' && !current.active) throw new JobError('JOB_CLOSED');
|
|
185
210
|
}
|
|
186
211
|
|
|
187
|
-
status():
|
|
212
|
+
status(): StatusV3 {
|
|
188
213
|
const current = this.current(), data = current.data;
|
|
189
214
|
return {
|
|
190
215
|
jobId: this.jobId, generation: data.generation, status: current.active ? 'active' : 'closed',
|
|
@@ -226,6 +251,14 @@ export class JobSession {
|
|
|
226
251
|
}
|
|
227
252
|
|
|
228
253
|
retainedSource(publicationId: string): JobRetainedSource {
|
|
254
|
+
const retained = this.retainedSourceV3(publicationId);
|
|
255
|
+
if (isRetainedRecordSource(retained)) {
|
|
256
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Record publication has no package manifest');
|
|
257
|
+
}
|
|
258
|
+
return retained;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
retainedSourceV3(publicationId: string): JobRetainedSourceV3 {
|
|
229
262
|
const current = this.current();
|
|
230
263
|
if (!current.active) throw new JobError('JOB_CLOSED');
|
|
231
264
|
const stored = current.data.publications[publicationId];
|
|
@@ -233,7 +266,7 @@ export class JobSession {
|
|
|
233
266
|
return stored.retained;
|
|
234
267
|
}
|
|
235
268
|
|
|
236
|
-
displayPublication(publicationId: string):
|
|
269
|
+
displayPublication(publicationId: string): JobDisplayPublicationV3 {
|
|
237
270
|
const current = this.current();
|
|
238
271
|
if (!current.active) throw new JobError('JOB_CLOSED');
|
|
239
272
|
const stored = current.data.publications[publicationId];
|
|
@@ -244,8 +277,8 @@ export class JobSession {
|
|
|
244
277
|
|
|
245
278
|
/** Internal front seam. A count covers preparation and the entire file stream. */
|
|
246
279
|
async readPublicationResponse(publicationId: string,
|
|
247
|
-
read: (retained:
|
|
248
|
-
const retained = this.
|
|
280
|
+
read: (retained: JobRetainedSourceV3) => Promise<Response>): Promise<Response> {
|
|
281
|
+
const retained = this.retainedSourceV3(publicationId);
|
|
249
282
|
const readId = this.store.beginSnapshotRead(this.jobId, publicationId,
|
|
250
283
|
jobSnapshotHash(retained.seals), retained.snapshotRoot);
|
|
251
284
|
this.operations++;
|
|
@@ -334,17 +367,18 @@ export class JobSession {
|
|
|
334
367
|
assertJobRoot(current.data.root);
|
|
335
368
|
}
|
|
336
369
|
|
|
337
|
-
private event(data: JobData, value:
|
|
338
|
-
const event = { ...value, cursor: randomUUID(), jobId: this.jobId, generation: data.generation }
|
|
370
|
+
private event(data: JobData, value: JobEventPayload): EventV3 {
|
|
371
|
+
const event: EventV3 = { ...value, cursor: randomUUID(), jobId: this.jobId, generation: data.generation };
|
|
339
372
|
if (Buffer.byteLength(JSON.stringify(event)) > maximumEventBytes) {
|
|
340
373
|
throw new JobError('JOB_BODY_LIMIT', 'Job event exceeds its delivery bound');
|
|
341
374
|
}
|
|
342
375
|
data.events.push(event);
|
|
376
|
+
return event;
|
|
343
377
|
}
|
|
344
378
|
|
|
345
379
|
private notify(): void { for (const listener of this.listeners) listener(); }
|
|
346
380
|
|
|
347
|
-
async execute(input: JobAgentRequest | JobFetchActRequest, signal: AbortSignal): Promise<unknown> {
|
|
381
|
+
async execute(input: JobAgentRequest | AgentRequestV3 | JobFetchActRequest | JobFetchActRequestV3, signal: AbortSignal): Promise<unknown> {
|
|
348
382
|
if (input.jobId !== this.jobId) throw new JobError('JOB_UNKNOWN');
|
|
349
383
|
if (input.verb === 'next') return this.next(input.after, input.waitMs, signal);
|
|
350
384
|
if (input.verb === 'fetch-act') {
|
|
@@ -380,8 +414,17 @@ export class JobSession {
|
|
|
380
414
|
}, fresh => {
|
|
381
415
|
this.active(fresh, input.expectedGeneration);
|
|
382
416
|
fresh.data.generation++;
|
|
383
|
-
|
|
384
|
-
|
|
417
|
+
const event: JobEvent = {
|
|
418
|
+
type: 'closed',
|
|
419
|
+
reason: input.reason,
|
|
420
|
+
cursor: randomUUID(),
|
|
421
|
+
jobId: this.jobId,
|
|
422
|
+
generation: fresh.data.generation,
|
|
423
|
+
};
|
|
424
|
+
if (Buffer.byteLength(JSON.stringify(event)) > maximumEventBytes) {
|
|
425
|
+
throw new JobError('JOB_BODY_LIMIT', 'Job event exceeds its delivery bound');
|
|
426
|
+
}
|
|
427
|
+
fresh.data.events.push(event);
|
|
385
428
|
const value = {status: 'closed', cursor: event.cursor};
|
|
386
429
|
return {generation: fresh.data.generation, event, replayKey: key, replay: {digest, value}};
|
|
387
430
|
});
|
|
@@ -390,14 +433,48 @@ export class JobSession {
|
|
|
390
433
|
return closure.replay.value;
|
|
391
434
|
} finally { this.finishOperation(); }
|
|
392
435
|
}
|
|
393
|
-
let candidate:
|
|
436
|
+
let candidate: JobRetainedSourceV3 | null = null;
|
|
394
437
|
this.operations++;
|
|
395
438
|
try {
|
|
396
439
|
if (input.verb === 'publish') {
|
|
397
|
-
candidate =
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
440
|
+
candidate = input.schema === JOB_API_V3_SCHEMA
|
|
441
|
+
? await prepareJobSource({
|
|
442
|
+
root: current.data.root,
|
|
443
|
+
stateRoot: this.store.root,
|
|
444
|
+
fingerprint: current.data.fingerprint,
|
|
445
|
+
request: input,
|
|
446
|
+
readPublished: this.options.readPublished,
|
|
447
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
448
|
+
partsEnumerator: this.options.partsEnumerator,
|
|
449
|
+
afterSnapshot: this.options.afterSnapshot,
|
|
450
|
+
afterDirectorySync: this.options.afterDirectorySync,
|
|
451
|
+
})
|
|
452
|
+
: await prepareJobSource({
|
|
453
|
+
root: current.data.root,
|
|
454
|
+
stateRoot: this.store.root,
|
|
455
|
+
fingerprint: current.data.fingerprint,
|
|
456
|
+
request: input,
|
|
457
|
+
readPublished: this.options.readPublished,
|
|
458
|
+
partsEnumerator: this.options.partsEnumerator,
|
|
459
|
+
afterSnapshot: this.options.afterSnapshot,
|
|
460
|
+
afterDirectorySync: this.options.afterDirectorySync,
|
|
461
|
+
});
|
|
462
|
+
} else if (input.verb === 'ask') {
|
|
463
|
+
if (current.data.head === input.publicationId) {
|
|
464
|
+
const stored = current.data.publications[input.publicationId];
|
|
465
|
+
if (stored && isRetainedRecordSource(stored.retained)) {
|
|
466
|
+
bindJobRecordAsk(input.subject, stored.retained);
|
|
467
|
+
if (!this.options.readRecordPublished) {
|
|
468
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Record publication requires a trusted record reader');
|
|
469
|
+
}
|
|
470
|
+
await verifyJobRecordSourceFresh({
|
|
471
|
+
retained: stored.retained,
|
|
472
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
473
|
+
phase: 'ask',
|
|
474
|
+
subject: input.subject as RecordSubject,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
401
478
|
}
|
|
402
479
|
if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
|
|
403
480
|
current = this.current();
|
|
@@ -410,9 +487,18 @@ export class JobSession {
|
|
|
410
487
|
switch (input.verb) {
|
|
411
488
|
case 'publish': {
|
|
412
489
|
assertJobSourceCurrent(candidate!);
|
|
413
|
-
|
|
490
|
+
if (isRetainedRecordSource(candidate!)) {
|
|
491
|
+
assertRetainedSnapshotIntact(
|
|
492
|
+
candidate!.snapshotRoot,
|
|
493
|
+
candidate!.seals,
|
|
494
|
+
candidate!.snapshotIdentity,
|
|
495
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
const publication: JobPublication | PublicationV3 = {
|
|
414
499
|
publicationId: randomUUID(), instanceKey: candidate!.instanceKey, generation: data.generation,
|
|
415
500
|
source: candidate!.source, label: candidate!.label, previousPublicationId: data.head, visual: candidate!.visual,
|
|
501
|
+
...(!isRetainedRecordSource(candidate!) && candidate!.interview !== undefined ? { interview: candidate!.interview } : {}),
|
|
416
502
|
};
|
|
417
503
|
for (const ask of Object.values(data.asks)) {
|
|
418
504
|
if (ask.status === 'pending') data.asks[ask.askId] = { ...ask, status: 'superseded' };
|
|
@@ -421,7 +507,7 @@ export class JobSession {
|
|
|
421
507
|
snapshot = {publicationId: publication.publicationId, snapshotHash: jobSnapshotHash(candidate!.seals),
|
|
422
508
|
snapshotRoot: candidate!.snapshotRoot, ...candidate!.snapshotIdentity!};
|
|
423
509
|
data.head = publication.publicationId;
|
|
424
|
-
this.event(data, { type: 'published', publication }
|
|
510
|
+
this.event(data, { type: 'published', publication });
|
|
425
511
|
result = publication;
|
|
426
512
|
break;
|
|
427
513
|
}
|
|
@@ -429,10 +515,31 @@ export class JobSession {
|
|
|
429
515
|
if (data.head !== input.publicationId) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
430
516
|
const retained = data.publications[input.publicationId].retained;
|
|
431
517
|
assertJobSourceCurrent(retained);
|
|
432
|
-
|
|
433
|
-
|
|
518
|
+
if (isRetainedRecordSource(retained)) {
|
|
519
|
+
assertRetainedSnapshotIntact(
|
|
520
|
+
retained.snapshotRoot,
|
|
521
|
+
retained.seals,
|
|
522
|
+
retained.snapshotIdentity,
|
|
523
|
+
'JOB_SOURCE_UNRETAINABLE',
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
const ask: JobPendingAsk | PendingAskV3 = isRetainedRecordSource(retained)
|
|
527
|
+
? {
|
|
528
|
+
askId: randomUUID(),
|
|
529
|
+
publicationId: input.publicationId,
|
|
530
|
+
subject: input.subject,
|
|
531
|
+
source: bindJobRecordAsk(input.subject, retained),
|
|
532
|
+
status: 'pending',
|
|
533
|
+
}
|
|
534
|
+
: {
|
|
535
|
+
askId: randomUUID(),
|
|
536
|
+
publicationId: input.publicationId,
|
|
537
|
+
subject: input.subject,
|
|
538
|
+
source: bindJobAsk(input.subject, retained),
|
|
539
|
+
status: 'pending',
|
|
540
|
+
};
|
|
434
541
|
data.asks[ask.askId] = ask;
|
|
435
|
-
this.event(data, { type: 'pending', ask }
|
|
542
|
+
this.event(data, { type: 'pending', ask });
|
|
436
543
|
result = ask;
|
|
437
544
|
break;
|
|
438
545
|
}
|
|
@@ -492,12 +599,38 @@ export class JobSession {
|
|
|
492
599
|
return receipt!;
|
|
493
600
|
}
|
|
494
601
|
|
|
495
|
-
async commitUIAct(raw: unknown): Promise<
|
|
496
|
-
const input = parseUISubmission(raw), digest = requestDigest(input), key = `ui:${input.pageId}:${input.submissionId}`;
|
|
602
|
+
async commitUIAct(raw: unknown): Promise<ActV3> {
|
|
603
|
+
const input = parseUISubmission(raw, this.publicationMode), digest = requestDigest(input), key = `ui:${input.pageId}:${input.submissionId}`;
|
|
497
604
|
const current = this.current();
|
|
498
605
|
const previous = this.replay(current.data, key, digest);
|
|
499
|
-
if (previous) return previous.value as
|
|
500
|
-
|
|
606
|
+
if (previous) return previous.value as ActV3;
|
|
607
|
+
if (current.active && input.expectedGeneration <= current.data.generation) {
|
|
608
|
+
const page = current.data.pages[input.pageId];
|
|
609
|
+
if (page && page.publicationId === input.publicationId && sameCapability(input.displayedNonce, page.displayedNonce) &&
|
|
610
|
+
current.data.head === input.publicationId) {
|
|
611
|
+
const ask = current.data.asks[input.askId];
|
|
612
|
+
const stored = current.data.publications[input.publicationId];
|
|
613
|
+
if (ask && stored && isRetainedRecordSource(stored.retained)) {
|
|
614
|
+
prepareJobRecordAct({
|
|
615
|
+
jobId: this.jobId,
|
|
616
|
+
submission: input,
|
|
617
|
+
ask,
|
|
618
|
+
retained: stored.retained,
|
|
619
|
+
reviewer: current.data.reviewer,
|
|
620
|
+
});
|
|
621
|
+
if (!this.options.readRecordPublished) {
|
|
622
|
+
throw new JobError('JOB_ACT_SOURCE_STALE', 'Record publication requires a trusted record reader');
|
|
623
|
+
}
|
|
624
|
+
await verifyJobRecordSourceFresh({
|
|
625
|
+
retained: stored.retained,
|
|
626
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
627
|
+
phase: 'finalize',
|
|
628
|
+
subject: ask.subject as RecordSubject,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
let act: ActV3;
|
|
501
634
|
this.store.update(this.jobId, null, fresh => {
|
|
502
635
|
// UI captures an observed generation. Unrelated asks may advance it while
|
|
503
636
|
// this same ask/source/publication/nonce stays valid. Agent mutation CAS
|
|
@@ -513,15 +646,23 @@ export class JobSession {
|
|
|
513
646
|
if (!ask) throw new JobError('JOB_ASK_INVALID');
|
|
514
647
|
const retained = fresh.data.publications[input.publicationId].retained;
|
|
515
648
|
assertJobSourceCurrent(retained);
|
|
516
|
-
|
|
517
|
-
|
|
649
|
+
if (isRetainedRecordSource(retained)) {
|
|
650
|
+
assertRetainedSnapshotIntact(
|
|
651
|
+
retained.snapshotRoot,
|
|
652
|
+
retained.seals,
|
|
653
|
+
retained.snapshotIdentity,
|
|
654
|
+
'JOB_ACT_SOURCE_STALE',
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const captured = !isRetainedRecordSource(retained) && ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review' ?
|
|
658
|
+
prepareJobStill(input, ask as JobPendingAsk, retained) : undefined;
|
|
518
659
|
act = finalizeJobAct({ jobId: this.jobId, submission: input, ask, retained, reviewer: fresh.data.reviewer,
|
|
519
660
|
still: captured?.still });
|
|
520
661
|
fresh.data.generation++;
|
|
521
662
|
fresh.data.acts[act.actId] = act;
|
|
522
663
|
fresh.data.asks[ask.askId] = { ...ask, status: 'answered' };
|
|
523
664
|
fresh.data.replays[key] = { digest, value: act };
|
|
524
|
-
this.event(fresh.data, { type: 'act', act }
|
|
665
|
+
this.event(fresh.data, { type: 'act', act });
|
|
525
666
|
return { data: fresh.data, ...(captured ? {still: {
|
|
526
667
|
actId: act.actId, pageId: input.pageId, submissionId: input.submissionId,
|
|
527
668
|
sha256: captured.still.sha256, binding: JSON.stringify(captured.binding),
|
|
@@ -530,18 +671,18 @@ export class JobSession {
|
|
|
530
671
|
}, fresh => {
|
|
531
672
|
const raced = this.replay(fresh.data, key, digest);
|
|
532
673
|
if (!raced) return false;
|
|
533
|
-
act = raced.value as
|
|
674
|
+
act = raced.value as ActV3;
|
|
534
675
|
return true;
|
|
535
676
|
});
|
|
536
677
|
this.notify();
|
|
537
678
|
return act!;
|
|
538
679
|
}
|
|
539
680
|
|
|
540
|
-
private events(after: string | null): JobNextValue {
|
|
681
|
+
private events(after: string | null): JobNextValue | NextValueV3 {
|
|
541
682
|
const current = this.current(), events = current.data.events;
|
|
542
683
|
const index = after === null ? -1 : events.findIndex(event => event.cursor === after);
|
|
543
684
|
if (after !== null && index < 0) throw new JobError('JOB_CURSOR_INVALID');
|
|
544
|
-
const batch:
|
|
685
|
+
const batch: EventV3[] = [];
|
|
545
686
|
let size = 0;
|
|
546
687
|
for (const event of events.slice(index + 1, index + 65)) {
|
|
547
688
|
const bytes = Buffer.byteLength(JSON.stringify(event));
|
|
@@ -550,11 +691,17 @@ export class JobSession {
|
|
|
550
691
|
size += bytes;
|
|
551
692
|
batch.push(event);
|
|
552
693
|
}
|
|
553
|
-
|
|
554
|
-
|
|
694
|
+
const cursor = batch.at(-1)?.cursor ?? after;
|
|
695
|
+
const status = batch.length ? 'events' : current.active ? 'timeout' : 'closed';
|
|
696
|
+
return {
|
|
697
|
+
capabilities: this.publicationMode === 'record-and-package' ? JOB_CAPABILITIES_V3 : JOB_CAPABILITIES,
|
|
698
|
+
events: batch,
|
|
699
|
+
cursor,
|
|
700
|
+
status,
|
|
701
|
+
};
|
|
555
702
|
}
|
|
556
703
|
|
|
557
|
-
private async next(after: string | null, waitMs: number, signal: AbortSignal): Promise<JobNextValue> {
|
|
704
|
+
private async next(after: string | null, waitMs: number, signal: AbortSignal): Promise<JobNextValue | NextValueV3> {
|
|
558
705
|
if (waitMs < 0 || waitMs > jobWaitLimitMs || !Number.isSafeInteger(waitMs)) throw new JobError('JOB_REQUEST_INVALID');
|
|
559
706
|
if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
|
|
560
707
|
const ready = this.events(after);
|
|
@@ -571,11 +718,11 @@ export class JobSession {
|
|
|
571
718
|
return this.events(after);
|
|
572
719
|
}
|
|
573
720
|
|
|
574
|
-
async *subscribe(input: { readonly jobId: string; readonly after: string | null; readonly signal: AbortSignal }): AsyncIterable<
|
|
721
|
+
async *subscribe(input: { readonly jobId: string; readonly after: string | null; readonly signal: AbortSignal }): AsyncIterable<EventV3> {
|
|
575
722
|
if (input.jobId !== this.jobId) throw new JobError('JOB_UNKNOWN');
|
|
576
723
|
let after = input.after;
|
|
577
724
|
while (!input.signal.aborted) {
|
|
578
|
-
let value: JobNextValue;
|
|
725
|
+
let value: JobNextValue | NextValueV3;
|
|
579
726
|
try { value = await this.next(after, jobWaitLimitMs, input.signal); }
|
|
580
727
|
catch (error) {
|
|
581
728
|
if (input.signal.aborted && error instanceof JobError && error.code === 'JOB_REQUEST_INVALID') return;
|
package/src/job-source.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
JOB_PARTS_ENUMERATOR_RANGE,
|
|
9
9
|
} from './job-contract.ts';
|
|
10
10
|
import type {
|
|
11
|
-
JobFileIdentity, JobImageSetInput, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
11
|
+
JobFileIdentity, JobImageSetInput, JobInterviewDiagnostics, JobInterviewRecord, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
12
12
|
JobSelector, JobSourceBinding, JobSubject,
|
|
13
13
|
OptionContext, OptionSource, PackageResultV3, PlanContext, PlanSource, ProjectRecord, PublishRequestV3,
|
|
14
14
|
RecordFreeze, RecordOptionResult, RecordPlanResult, RecordPublicationReader, RecordPublishedContext,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
jobPath,
|
|
31
31
|
jobSha,
|
|
32
32
|
jobText,
|
|
33
|
+
parseJobInterviewDiagnostics,
|
|
33
34
|
parseRecordFreeze,
|
|
34
35
|
parseRecordPublishedContext,
|
|
35
36
|
parseRecordResult,
|
|
@@ -82,6 +83,7 @@ export interface JobRetainedSource {
|
|
|
82
83
|
readonly visual: { readonly status: 'available' } | { readonly status: 'unavailable'; readonly code: string };
|
|
83
84
|
readonly subjects: readonly JobSubject[];
|
|
84
85
|
readonly questions: readonly InterviewQuestion[];
|
|
86
|
+
readonly interview?: JobInterviewDiagnostics | null;
|
|
85
87
|
readonly partIds: readonly string[];
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -100,6 +102,7 @@ export interface JobRetainedRecordSource {
|
|
|
100
102
|
readonly visual: { readonly status: 'unavailable'; readonly code: 'MODEL_UNAVAILABLE' };
|
|
101
103
|
readonly subjects: readonly RecordSubject[];
|
|
102
104
|
readonly questions: readonly InterviewQuestion[];
|
|
105
|
+
readonly interview?: undefined;
|
|
103
106
|
readonly partIds: readonly [];
|
|
104
107
|
readonly context: RecordPublishedContext;
|
|
105
108
|
}
|
|
@@ -335,22 +338,52 @@ async function prepareParts(root: string, snapshotRoot: string, claimed: JobPart
|
|
|
335
338
|
return {identity: {enumeratorVersion: version, manifest: {path: manifestPath, sha256: jobHash(manifestBytes)}, images}, bytes};
|
|
336
339
|
}
|
|
337
340
|
|
|
338
|
-
function collectQuestionFiles(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
function collectQuestionFiles(
|
|
342
|
+
root: string,
|
|
343
|
+
questions: readonly InterviewQuestion[],
|
|
344
|
+
records: readonly JobInterviewRecord[] = [],
|
|
345
|
+
): { readonly required: JobFileIdentity[]; readonly optional: JobFileIdentity[] } {
|
|
346
|
+
const required: JobFileIdentity[] = [];
|
|
347
|
+
const optional: JobFileIdentity[] = [];
|
|
348
|
+
function visit(value: unknown, isOptional: boolean): void {
|
|
349
|
+
if (Array.isArray(value)) { value.forEach(item => visit(item, isOptional)); return; }
|
|
342
350
|
if (value === null || typeof value !== 'object') return;
|
|
343
351
|
const entry = value as Record<string, unknown>;
|
|
344
352
|
if (typeof entry.path === 'string' && typeof entry.sha256 === 'string') {
|
|
345
|
-
|
|
353
|
+
if (!isOptional) {
|
|
354
|
+
required.push({ path: jobPath(entry.path), sha256: jobSha(entry.sha256) });
|
|
355
|
+
} else {
|
|
356
|
+
try {
|
|
357
|
+
const path = jobPath(entry.path);
|
|
358
|
+
const sha256 = jobSha(entry.sha256);
|
|
359
|
+
if (jobHash(sourceBytes(root, path)) === sha256) {
|
|
360
|
+
optional.push({ path, sha256 });
|
|
361
|
+
}
|
|
362
|
+
} catch {
|
|
363
|
+
// Historical non-editable context file is missing or changed; its stale diagnostic is already recorded.
|
|
364
|
+
}
|
|
365
|
+
}
|
|
346
366
|
}
|
|
347
|
-
Object.values(entry).forEach(visit);
|
|
367
|
+
Object.values(entry).forEach(item => visit(item, isOptional));
|
|
348
368
|
}
|
|
349
369
|
for (const question of questions) {
|
|
350
|
-
|
|
351
|
-
visit(JSON.parse(sourceBytes(root, question.ref.path).toString('utf8')));
|
|
370
|
+
required.push(question.ref, ...question.images.map(image => image.ref));
|
|
371
|
+
visit(JSON.parse(sourceBytes(root, question.ref.path).toString('utf8')), !question.editable);
|
|
352
372
|
}
|
|
353
|
-
|
|
373
|
+
for (const row of records) {
|
|
374
|
+
if (row.observedSet) {
|
|
375
|
+
try {
|
|
376
|
+
const path = jobPath(row.observedSet.path);
|
|
377
|
+
const sha256 = jobSha(row.observedSet.sha256);
|
|
378
|
+
if (jobHash(sourceBytes(root, path)) === sha256) {
|
|
379
|
+
optional.push({ path, sha256 });
|
|
380
|
+
}
|
|
381
|
+
} catch {
|
|
382
|
+
// Unreadable or non-retained option set stays unsealed.
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return { required, optional };
|
|
354
387
|
}
|
|
355
388
|
|
|
356
389
|
function isOptionIdentifier(value: unknown): value is string {
|
|
@@ -590,6 +623,7 @@ async function readRecordPublishedPhase(
|
|
|
590
623
|
readRecordPublished: RecordPublicationReader,
|
|
591
624
|
input: RecordReaderInput,
|
|
592
625
|
phase: 'publish' | 'ask' | 'finalize',
|
|
626
|
+
assertCurrentBeforeGenericRefusal?: () => void,
|
|
593
627
|
): Promise<RecordPublishedContext> {
|
|
594
628
|
let raw: unknown;
|
|
595
629
|
try {
|
|
@@ -609,6 +643,9 @@ async function readRecordPublishedPhase(
|
|
|
609
643
|
...(input.parts !== undefined ? { parts: input.parts } : {}),
|
|
610
644
|
});
|
|
611
645
|
} catch (error) {
|
|
646
|
+
if (extractReaderToken(error) === null) {
|
|
647
|
+
assertCurrentBeforeGenericRefusal?.();
|
|
648
|
+
}
|
|
612
649
|
throw mapRecordReaderError(error, phase);
|
|
613
650
|
}
|
|
614
651
|
return parseRecordPublishedContext(raw, input.result, input.record);
|
|
@@ -816,7 +853,9 @@ export async function prepareJobRecordSource(options: {
|
|
|
816
853
|
options.readRecordPublished,
|
|
817
854
|
{ root: root.path, record, result, phase: 'inventory' },
|
|
818
855
|
'publish',
|
|
856
|
+
() => assertRecord(root, record),
|
|
819
857
|
);
|
|
858
|
+
assertRecord(root, record);
|
|
820
859
|
if (inventory.files.length > maxSourceFiles) {
|
|
821
860
|
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
822
861
|
}
|
|
@@ -859,12 +898,15 @@ export async function prepareJobRecordSource(options: {
|
|
|
859
898
|
}
|
|
860
899
|
options.afterDirectorySync?.(directory);
|
|
861
900
|
}
|
|
901
|
+
assertJobSourceCurrent({ root, record, seals });
|
|
862
902
|
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
863
903
|
const retainedContext = await readRecordPublishedPhase(
|
|
864
904
|
options.readRecordPublished,
|
|
865
905
|
{ root: snapshotRoot, record, result, phase: 'retained', parts: inventory.parts },
|
|
866
906
|
'publish',
|
|
907
|
+
() => assertJobSourceCurrent({ root, record, seals }),
|
|
867
908
|
);
|
|
909
|
+
assertJobSourceCurrent({ root, record, seals });
|
|
868
910
|
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
869
911
|
assertEqualRecordContexts(inventory, retainedContext);
|
|
870
912
|
const decoded = decodeRetainedRecordProject(snapshotRoot, seals, result, retainedContext);
|
|
@@ -936,7 +978,9 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
936
978
|
options.readRecordPublished,
|
|
937
979
|
{ root: retained.root.path, record: retained.record, result: retained.result, phase: 'inventory' },
|
|
938
980
|
phase,
|
|
981
|
+
() => assertJobSourceCurrent(retained),
|
|
939
982
|
);
|
|
983
|
+
assertJobSourceCurrent(retained);
|
|
940
984
|
if (requestDigest(inventory.parts) !== requestDigest(retained.context.parts)) {
|
|
941
985
|
throw new JobError(phase === 'finalize' ? 'JOB_ACT_SOURCE_STALE' : 'JOB_SOURCE_MISMATCH');
|
|
942
986
|
}
|
|
@@ -956,7 +1000,9 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
956
1000
|
parts: retained.context.parts,
|
|
957
1001
|
},
|
|
958
1002
|
phase,
|
|
1003
|
+
() => assertJobSourceCurrent(retained),
|
|
959
1004
|
);
|
|
1005
|
+
assertJobSourceCurrent(retained);
|
|
960
1006
|
assertRetainedSnapshotIntact(
|
|
961
1007
|
retained.snapshotRoot,
|
|
962
1008
|
retained.seals,
|
|
@@ -1105,9 +1151,6 @@ export async function prepareJobSource(options: {
|
|
|
1105
1151
|
catch { throw new JobError('JOB_RECORD_INCOMPLETE'); }
|
|
1106
1152
|
if (record.path === 'project.json') {
|
|
1107
1153
|
project = readProject(root.path);
|
|
1108
|
-
// #555 owns API@2 diagnostic carriage. Refuse before publication lookup
|
|
1109
|
-
// or snapshot writes when this reader's retained records need it.
|
|
1110
|
-
if (project.sceneAnswers || project.diagnostics.length) throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
1111
1154
|
}
|
|
1112
1155
|
} else {
|
|
1113
1156
|
try { lstatSync(join(root.path, 'project.json')); throw new JobError('JOB_FREEZE_REQUIRED'); }
|
|
@@ -1143,7 +1186,15 @@ export async function prepareJobSource(options: {
|
|
|
1143
1186
|
add(rootRelative(root.path, review.handoff.source), review.handoff.record.source.sha256);
|
|
1144
1187
|
}
|
|
1145
1188
|
if (record) add(record.path, record.sha256);
|
|
1146
|
-
|
|
1189
|
+
const questionFiles = collectQuestionFiles(
|
|
1190
|
+
root.path,
|
|
1191
|
+
project?.questions ?? [],
|
|
1192
|
+
project?.interview.records ?? [],
|
|
1193
|
+
);
|
|
1194
|
+
for (const file of [...declared, ...questionFiles.required]) add(file.path, file.sha256);
|
|
1195
|
+
for (const file of questionFiles.optional) {
|
|
1196
|
+
if (!wanted.has(file.path)) add(file.path, file.sha256);
|
|
1197
|
+
}
|
|
1147
1198
|
if (wanted.size > maxSourceFiles) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
1148
1199
|
const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
|
|
1149
1200
|
const seals: JobFileIdentity[] = [];
|
|
@@ -1213,6 +1264,22 @@ export async function prepareJobSource(options: {
|
|
|
1213
1264
|
packageSourceHash: modelSource.sourceHash, record, imageSet: imageSet.imageSet}))};
|
|
1214
1265
|
}
|
|
1215
1266
|
const boundReview = { ...review, sourceHash: source.sourceHash };
|
|
1267
|
+
const sealedByPath = new Map(seals.map(seal => [seal.path, seal.sha256]));
|
|
1268
|
+
const retainedInterview = project
|
|
1269
|
+
? parseJobInterviewDiagnostics(
|
|
1270
|
+
{
|
|
1271
|
+
...project.interview,
|
|
1272
|
+
records: project.interview.records.map(row => ({
|
|
1273
|
+
...row,
|
|
1274
|
+
observedSet:
|
|
1275
|
+
row.observedSet && sealedByPath.get(row.observedSet.path) === row.observedSet.sha256
|
|
1276
|
+
? row.observedSet
|
|
1277
|
+
: null,
|
|
1278
|
+
})),
|
|
1279
|
+
},
|
|
1280
|
+
'JOB_RECORD_INCOMPLETE',
|
|
1281
|
+
) ?? null
|
|
1282
|
+
: null;
|
|
1216
1283
|
const prepared: JobRetainedSource = {
|
|
1217
1284
|
root, record, seals, snapshotRoot, snapshotIdentity,
|
|
1218
1285
|
manifestPath: retained.manifestPath,
|
|
@@ -1224,9 +1291,14 @@ export async function prepareJobSource(options: {
|
|
|
1224
1291
|
{ status: 'unavailable', code: 'MODEL_UNAVAILABLE' },
|
|
1225
1292
|
subjects: context.subjects,
|
|
1226
1293
|
questions: (project?.questions ?? []).map(question => {
|
|
1227
|
-
const { answer, ...fields } = question;
|
|
1228
|
-
return
|
|
1294
|
+
const { answer, partsUnavailable, ...fields } = question;
|
|
1295
|
+
return {
|
|
1296
|
+
...fields,
|
|
1297
|
+
...(partsUnavailable === undefined ? {} : { partsUnavailable }),
|
|
1298
|
+
...(answer === undefined ? {} : { answer: JSON.parse(JSON.stringify(answer)) as Record<string, unknown> }),
|
|
1299
|
+
};
|
|
1229
1300
|
}),
|
|
1301
|
+
interview: retainedInterview,
|
|
1230
1302
|
partIds: context.partIds,
|
|
1231
1303
|
};
|
|
1232
1304
|
await options.afterSnapshot?.();
|
|
@@ -2,7 +2,7 @@ import {spawn} from 'node:child_process';
|
|
|
2
2
|
import {randomUUID} from 'node:crypto';
|
|
3
3
|
import {open, readFile, unlink} from 'node:fs/promises';
|
|
4
4
|
import {join} from 'node:path';
|
|
5
|
-
import {appRoot} from './build.ts';
|
|
5
|
+
import {appRoot, playBuildConditions} from './build.ts';
|
|
6
6
|
import {frontPort} from './front.ts';
|
|
7
7
|
import {acquireClaim, defaultStateDir, openFingerprint, prepareOpenTarget, readOpenStatus, releaseClaim,
|
|
8
8
|
type OpenInputs, type OpenOptions} from './open.ts';
|
|
@@ -61,7 +61,7 @@ export async function openWorkspace(inputs: readonly OpenInputs[], options: Open
|
|
|
61
61
|
const logPath = join(directory, nonce + '.log');
|
|
62
62
|
const log = await open(logPath, 'a', 0o600);
|
|
63
63
|
try {
|
|
64
|
-
child = spawn(process.execPath, [join(appRoot, 'src/open-workspace-worker.ts'), request],
|
|
64
|
+
child = spawn(process.execPath, [...playBuildConditions().map(c => `--conditions=${c}`), join(appRoot, 'src/open-workspace-worker.ts'), request],
|
|
65
65
|
{cwd: directory, detached: true, stdio: ['ignore', log.fd, log.fd], env: process.env});
|
|
66
66
|
child.unref();
|
|
67
67
|
} finally {await log.close();}
|