@rig-c/review 4.6.0 → 4.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/REVIEW_PACKAGE.md +235 -16
- package/docs/STABILITY.md +62 -4
- package/package.json +1 -1
- package/src/canonical-json.ts +14 -0
- package/src/create-pin-gate.ts +1 -1
- package/src/feedback-export.ts +2 -2
- package/src/interview-project.ts +27 -19
- package/src/interview-scene.ts +18 -11
- package/src/job-act.ts +85 -9
- package/src/job-api.ts +182 -31
- package/src/job-checkpoint-evidence.ts +19 -6
- package/src/job-cli.ts +6 -6
- package/src/job-contract.ts +85 -14
- package/src/job-front.ts +100 -78
- package/src/job-host.ts +9 -2
- package/src/job-previous-draft.ts +37 -0
- package/src/job-session.ts +74 -40
- package/src/job-source.ts +196 -35
- package/src/manifest.ts +43 -14
- package/src/mesh-edit.ts +7 -1
- package/src/parts-comment-crops.ts +15 -3
- package/src/parts-comparison.ts +21 -8
- package/src/parts-view.ts +23 -8
- package/web/catalog-en.ts +10 -0
- package/web/catalog-ko.ts +10 -0
- package/web/job-rig-screen.ts +65 -21
- package/web/job-session.ts +54 -26
- package/web/main.ts +158 -50
- package/web/mesh-editor.ts +124 -13
- package/web/part-selection.ts +1 -1
- package/web/parts-viewport-provider.ts +45 -8
- package/web/rig-host.ts +5 -3
- package/web/stage-comments.ts +77 -14
- package/web/styles.css +2 -0
- package/web/workspace-layout.ts +10 -0
- package/web/workspace-ui.ts +2 -2
package/src/job-session.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
2
|
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
-
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ACT_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_RECORD_READER_ID, jobStillByteLimit, jobActDeliveryLimit, JOB_CAPABILITIES, JOB_CAPABILITIES_V3, JOB_ENABLED_ACT_KINDS,
|
|
4
|
+
JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_ACT_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_MESH_EDITS_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_RECORD_READER_ID, jobStillByteLimit, jobActDeliveryLimit, JOB_CAPABILITIES, JOB_CAPABILITIES_V3, JOB_ENABLED_ACT_KINDS,
|
|
5
5
|
type ActV3, type AgentRequestV3, type EventV3, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
|
|
6
6
|
type JobDisplayPublication, type JobDisplayPublicationV3, type JobDisplayReceipt, type JobEvent, type JobFetchActRequest, type JobFetchActRequestV3,
|
|
7
7
|
type JobNextValue, type JobPendingAsk, type JobPublication, type JobPublicationMode, type JobReviewerBinding,
|
|
8
|
-
type NextValueV3, type PendingAskV3, type PublicationV3, type RecordPublicationReader, type RecordSubject, type StatusV3,
|
|
8
|
+
type JobSubject, type NextValueV3, type PendingAskV3, type PublicationV3, type RecordPublicationReader, type RecordSubject, type StatusV3,
|
|
9
9
|
} from './job-contract.ts';
|
|
10
10
|
import { bindJobAsk, bindJobRecordAsk, finalizeJobAct, parseUISubmission, prepareJobRecordAct, prepareJobStill } from './job-act.ts';
|
|
11
|
-
import { isRecordSource, parseRecordSource, parseCommentsAct, jobApiSchemaForMode, jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
11
|
+
import { atSubject, isRecordSource, parseRecordSource, parseCommentsAct, parseMeshEditsAct, jobApiSchemaForMode, jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
12
12
|
import {
|
|
13
13
|
assertStoredCheckpointEvidence, assertJobRoot, assertJobSourceCurrent, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, loadRetainedJobReview, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot, verifyJobRecordSourceFresh,
|
|
14
14
|
type JobPublicationReader, type JobRetainedSource, type JobRetainedSourceV3, type JobRootIdentity,
|
|
@@ -80,7 +80,7 @@ function assertStoredSchemas(data: JobData): void {
|
|
|
80
80
|
assertStoredEvidence(data);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/** Check
|
|
83
|
+
/** Check optional evidence declarations and their durable copies, including committed replay values. */
|
|
84
84
|
function assertStoredEvidence(data: JobData): void {
|
|
85
85
|
for (const stored of Object.values(data.publications)) {
|
|
86
86
|
assertStoredCheckpointEvidence(stored.retained);
|
|
@@ -93,7 +93,16 @@ function assertStoredEvidence(data: JobData): void {
|
|
|
93
93
|
if (event.type === 'pending') assertStoredEvidenceCopy(event.ask, data);
|
|
94
94
|
if (event.type === 'act') assertStoredEvidenceCopy(event.act, data);
|
|
95
95
|
}
|
|
96
|
-
for (const replay of Object.values(data.replays))
|
|
96
|
+
for (const replay of Object.values(data.replays)) {
|
|
97
|
+
// An ask-batch receipt wraps its asks; each one is a durable copy like a single ask's receipt.
|
|
98
|
+
const asks = (replay.value as {asks?: unknown} | null)?.asks;
|
|
99
|
+
if (Array.isArray(asks)) for (const ask of asks) assertStoredEvidenceCopy(ask, data);
|
|
100
|
+
else assertStoredEvidenceCopy(replay.value, data);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hasStoredEvidence(source: object | undefined): boolean {
|
|
105
|
+
return !!source && ('checkpointEvidence' in source || 'previousDraft' in source);
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
function assertStoredEvidenceCopy(value: unknown, data: JobData): void {
|
|
@@ -101,12 +110,16 @@ function assertStoredEvidenceCopy(value: unknown, data: JobData): void {
|
|
|
101
110
|
const copy = value as {publicationId: string; source: JobPublication['source'] | PublicationV3['source']};
|
|
102
111
|
const stored = data.publications[copy.publicationId];
|
|
103
112
|
const bound = stored?.retained.source;
|
|
104
|
-
if (!('source' in value) && !(bound
|
|
113
|
+
if (!('source' in value) && !hasStoredEvidence(bound)) return;
|
|
105
114
|
if (!copy.source || typeof copy.source !== 'object' || Array.isArray(copy.source)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
106
|
-
if (!(
|
|
115
|
+
if (!hasStoredEvidence(copy.source) && !hasStoredEvidence(bound)) return;
|
|
116
|
+
const copyDraft = 'previousDraft' in copy.source ? copy.source.previousDraft : undefined;
|
|
117
|
+
const boundDraft = bound && 'previousDraft' in bound ? bound.previousDraft : undefined;
|
|
107
118
|
if (!bound || copy.source.sourceHash !== bound.sourceHash ||
|
|
119
|
+
('previousDraft' in copy.source) !== ('previousDraft' in bound) ||
|
|
120
|
+
requestDigest(copyDraft ?? null) !== requestDigest(boundDraft ?? null) ||
|
|
108
121
|
requestDigest(copy.source.checkpointEvidence ?? null) !== requestDigest(bound.checkpointEvidence ?? null) ||
|
|
109
|
-
requestDigest(copy.source.plan) !== requestDigest(bound.plan)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
122
|
+
!('plan' in copy.source) || requestDigest(copy.source.plan) !== requestDigest(bound.plan)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
110
123
|
if (isRecordSource(copy.source)) parseRecordSource(copy.source);
|
|
111
124
|
}
|
|
112
125
|
|
|
@@ -412,6 +425,27 @@ export class JobSession {
|
|
|
412
425
|
return event;
|
|
413
426
|
}
|
|
414
427
|
|
|
428
|
+
/** The committed head's retained source, re-checked against the work root and its sealed snapshot. */
|
|
429
|
+
private headRetained(data: JobData, publicationId: string): JobRetainedSourceV3 {
|
|
430
|
+
if (data.head !== publicationId) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
431
|
+
const retained = data.publications[publicationId].retained;
|
|
432
|
+
assertJobSourceCurrent(retained);
|
|
433
|
+
if (isRetainedRecordSource(retained) || hasStoredEvidence(retained.source)) {
|
|
434
|
+
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals, retained.snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
435
|
+
}
|
|
436
|
+
return retained;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Bind one subject to the retained source, store its pending ask and write its `pending` event. */
|
|
440
|
+
private addAsk(data: JobData, publicationId: string, subject: JobSubject | RecordSubject, retained: JobRetainedSourceV3): JobPendingAsk | PendingAskV3 {
|
|
441
|
+
const ask: JobPendingAsk | PendingAskV3 = isRetainedRecordSource(retained)
|
|
442
|
+
? { askId: randomUUID(), publicationId, subject, source: bindJobRecordAsk(subject, retained), status: 'pending' }
|
|
443
|
+
: { askId: randomUUID(), publicationId, subject, source: bindJobAsk(subject, retained), status: 'pending' };
|
|
444
|
+
data.asks[ask.askId] = ask;
|
|
445
|
+
this.event(data, { type: 'pending', ask });
|
|
446
|
+
return ask;
|
|
447
|
+
}
|
|
448
|
+
|
|
415
449
|
private notify(): void { for (const listener of this.listeners) listener(); }
|
|
416
450
|
|
|
417
451
|
async execute(input: JobAgentRequest | AgentRequestV3 | JobFetchActRequest | JobFetchActRequestV3, signal: AbortSignal): Promise<unknown> {
|
|
@@ -511,6 +545,21 @@ export class JobSession {
|
|
|
511
545
|
});
|
|
512
546
|
}
|
|
513
547
|
}
|
|
548
|
+
} else if (input.verb === 'ask-batch') {
|
|
549
|
+
// One freshness read for the whole batch; every subject binds and validates against it (#963).
|
|
550
|
+
if (current.data.head !== input.publicationId) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
551
|
+
const retained = current.data.publications[input.publicationId].retained;
|
|
552
|
+
if (!isRetainedRecordSource(retained)) throw new JobError('JOB_REQUEST_INVALID', 'ask-batch requires a record publication');
|
|
553
|
+
input.subjects.forEach((subject, index) => atSubject(index, () => bindJobRecordAsk(subject, retained)));
|
|
554
|
+
if (!this.options.readRecordPublished) {
|
|
555
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'Record publication requires a trusted record reader');
|
|
556
|
+
}
|
|
557
|
+
await verifyJobRecordSourceFresh({
|
|
558
|
+
retained,
|
|
559
|
+
readRecordPublished: this.options.readRecordPublished,
|
|
560
|
+
phase: 'ask',
|
|
561
|
+
subjects: input.subjects as readonly RecordSubject[],
|
|
562
|
+
});
|
|
514
563
|
}
|
|
515
564
|
if (signal.aborted) throw new JobError('JOB_REQUEST_INVALID', 'Request cancelled');
|
|
516
565
|
current = this.current();
|
|
@@ -523,7 +572,7 @@ export class JobSession {
|
|
|
523
572
|
switch (input.verb) {
|
|
524
573
|
case 'publish': {
|
|
525
574
|
assertJobSourceCurrent(candidate!);
|
|
526
|
-
if (isRetainedRecordSource(candidate!) || candidate!.source
|
|
575
|
+
if (isRetainedRecordSource(candidate!) || hasStoredEvidence(candidate!.source)) {
|
|
527
576
|
assertRetainedSnapshotIntact(
|
|
528
577
|
candidate!.snapshotRoot,
|
|
529
578
|
candidate!.seals,
|
|
@@ -548,35 +597,17 @@ export class JobSession {
|
|
|
548
597
|
break;
|
|
549
598
|
}
|
|
550
599
|
case 'ask': {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
const ask: JobPendingAsk | PendingAskV3 = isRetainedRecordSource(retained)
|
|
563
|
-
? {
|
|
564
|
-
askId: randomUUID(),
|
|
565
|
-
publicationId: input.publicationId,
|
|
566
|
-
subject: input.subject,
|
|
567
|
-
source: bindJobRecordAsk(input.subject, retained),
|
|
568
|
-
status: 'pending',
|
|
569
|
-
}
|
|
570
|
-
: {
|
|
571
|
-
askId: randomUUID(),
|
|
572
|
-
publicationId: input.publicationId,
|
|
573
|
-
subject: input.subject,
|
|
574
|
-
source: bindJobAsk(input.subject, retained),
|
|
575
|
-
status: 'pending',
|
|
576
|
-
};
|
|
577
|
-
data.asks[ask.askId] = ask;
|
|
578
|
-
this.event(data, { type: 'pending', ask });
|
|
579
|
-
result = ask;
|
|
600
|
+
result = this.addAsk(data, input.publicationId, input.subject, this.headRetained(data, input.publicationId));
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
case 'ask-batch': {
|
|
604
|
+
// One head/source/snapshot re-check, then every ask under its own generation and pending event.
|
|
605
|
+
const retained = this.headRetained(data, input.publicationId);
|
|
606
|
+
const asks = input.subjects.map((subject, index) => {
|
|
607
|
+
if (index > 0) data.generation++;
|
|
608
|
+
return atSubject(index, () => this.addAsk(data, input.publicationId, subject, retained));
|
|
609
|
+
});
|
|
610
|
+
result = { asks };
|
|
580
611
|
break;
|
|
581
612
|
}
|
|
582
613
|
}
|
|
@@ -607,6 +638,7 @@ export class JobSession {
|
|
|
607
638
|
if (!storedAct) throw new JobError('JOB_ACT_UNKNOWN');
|
|
608
639
|
// Validation must not replace the stored representation or reorder its keys.
|
|
609
640
|
if ((storedAct as {schema: string}).schema === JOB_COMMENTS_ACT_SCHEMA) parseCommentsAct(storedAct);
|
|
641
|
+
if (storedAct.schema === JOB_MESH_EDITS_ACT_SCHEMA) parseMeshEditsAct(storedAct);
|
|
610
642
|
const still = 'still' in storedAct ? storedAct.still : undefined;
|
|
611
643
|
const actBytes = Buffer.from(JSON.stringify(storedAct));
|
|
612
644
|
if (storedAct.schema !== JOB_RIG_REVIEW_ACT_SCHEMA && !still) {
|
|
@@ -699,7 +731,9 @@ export class JobSession {
|
|
|
699
731
|
const pkg = await loadPartsView(dirname(join(retained.snapshotRoot, retained.source.parts.manifest.path)),
|
|
700
732
|
{painting: sealedPainting, paintingRoot: retained.snapshotRoot});
|
|
701
733
|
for (const issue of issues) {
|
|
702
|
-
await validateStoredPartsComment(pkg, issue, false, {
|
|
734
|
+
await validateStoredPartsComment(pkg, issue, false, {
|
|
735
|
+
sourceHash: retained.source.sourceHash, previousDraft: retained.source.previousDraft,
|
|
736
|
+
});
|
|
703
737
|
}
|
|
704
738
|
} catch (error) {
|
|
705
739
|
if (error instanceof JobError) throw error;
|
|
@@ -729,7 +763,7 @@ export class JobSession {
|
|
|
729
763
|
if (!ask) throw new JobError('JOB_ASK_INVALID');
|
|
730
764
|
const retained = fresh.data.publications[input.publicationId].retained;
|
|
731
765
|
assertJobSourceCurrent(retained);
|
|
732
|
-
if (isRetainedRecordSource(retained) || retained.source
|
|
766
|
+
if (isRetainedRecordSource(retained) || hasStoredEvidence(retained.source) || input.kind === 'parts-verdict') {
|
|
733
767
|
assertRetainedSnapshotIntact(
|
|
734
768
|
retained.snapshotRoot,
|
|
735
769
|
retained.seals,
|