@rig-c/review 2.9.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/REVIEW_PACKAGE.md +194 -3
- package/package.json +1 -1
- package/src/job-api.ts +23 -9
- package/src/job-checkpoint-evidence.ts +113 -0
- package/src/job-contract.ts +97 -1
- package/src/job-front.ts +28 -7
- package/src/job-host.ts +2 -0
- package/src/job-session.ts +37 -5
- package/src/job-source.ts +136 -14
- package/web/catalog-en.ts +27 -0
- package/web/catalog-ko.ts +27 -0
- package/web/job-session.ts +410 -66
- package/web/parts.ts +6 -1
- package/web/stage-comments.ts +3 -3
- package/web/styles.css +35 -3
package/src/job-front.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import {checkpointEvidenceMetadata, readCheckpointEvidenceBytes} from './job-checkpoint-evidence.ts';
|
|
1
2
|
/** Disjoint live-job routes. The backend receives the original authenticated Request. */
|
|
2
3
|
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, type JobErrorCode, type JobHostPorts, type JobId, type JobPublicationMode, type JobResult, type JobReviewerBinding } from './job-contract.ts';
|
|
3
4
|
import { createJobHostPorts, jobBody, jobHash, jobId, jobObject, jobPartsEnumeratorVersion } from './job-api.ts';
|
|
4
5
|
import { JobSession } from './job-session.ts';
|
|
5
|
-
import { assertJobRoot, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, type JobRootIdentity } from './job-source.ts';
|
|
6
|
+
import { assertJobRoot, assertRetainedSnapshotIntact, captureJobRoot, planTextMetadata, isRetainedRecordSource, type JobRootIdentity } from './job-source.ts';
|
|
6
7
|
import type { JobWorkerOptions } from './job-worker.ts';
|
|
7
8
|
import { JobError, JobStore } from './job-store.ts';
|
|
8
9
|
import { loadReview, safeFile, packagePath, type ReviewPackage } from './manifest.ts';
|
|
@@ -28,8 +29,8 @@ interface CropFailureDiagnostic {
|
|
|
28
29
|
expected: string | number[];
|
|
29
30
|
received: string | number[];
|
|
30
31
|
}
|
|
31
|
-
function failure(code: string, status: number, diagnostic?: CropFailureDiagnostic): Response {
|
|
32
|
-
return Response.json({ ok: false, error: { code, message
|
|
32
|
+
function failure(code: string, status: number, diagnostic?: CropFailureDiagnostic, message = code): Response {
|
|
33
|
+
return Response.json({ ok: false, error: { code, message, ...(diagnostic ? {diagnostic} : {}) } }, { status, headers });
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/** Explain an existing rejection without returning body text, filesystem paths or PNG bytes. */
|
|
@@ -264,18 +265,32 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
264
265
|
if (key !== display.publication.instanceKey) return failure('JOB_DISPLAY_MISMATCH', 409);
|
|
265
266
|
if (crop && session.status().publication?.publicationId !== publicationId)
|
|
266
267
|
return failure('JOB_ACT_SOURCE_STALE', 409);
|
|
267
|
-
const json = (value: unknown) =>
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
const json = (value: Record<string, unknown>) => {
|
|
269
|
+
const payload = path === 'api/review' ? planTextMetadata(retained, value) : value;
|
|
270
|
+
const body = JSON.stringify(payload);
|
|
271
|
+
return new Response(request.method === 'HEAD' ? null : body, {
|
|
272
|
+
headers: {...headers, 'Content-Type': 'application/json'},
|
|
273
|
+
});
|
|
274
|
+
};
|
|
270
275
|
const sealedFile = async (relativePath: string) => {
|
|
271
276
|
const seal = retained.seals.find(file => file.path === relativePath);
|
|
272
277
|
if (!seal) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
273
278
|
const file = await safeFile(retained.snapshotRoot, relativePath);
|
|
274
279
|
return serveReference(request, file, seal.sha256, headers);
|
|
275
280
|
};
|
|
281
|
+
const evidenceRoute = /^api\/checkpoint-evidence\/([A-Za-z0-9][A-Za-z0-9._-]*)\/(table|tiles\/(0|[1-9]\d*))$/.exec(path);
|
|
282
|
+
if (evidenceRoute) {
|
|
283
|
+
const packet = retained.source.checkpointEvidence?.find(item => item.checkpointId === evidenceRoute[1]);
|
|
284
|
+
const isTable = evidenceRoute[2] === 'table';
|
|
285
|
+
const member = isTable ? packet?.table : packet?.tiles[Number(evidenceRoute[3])];
|
|
286
|
+
if (!member) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
287
|
+
readCheckpointEvidenceBytes(retained.snapshotRoot, member, isTable ? 256 * 1024 : 8 * 1024 * 1024);
|
|
288
|
+
return await sealedFile(member.path);
|
|
289
|
+
}
|
|
276
290
|
if (isRetainedRecordSource(retained)) {
|
|
277
291
|
if (path === 'api/review') {
|
|
278
292
|
return json({
|
|
293
|
+
...checkpointEvidenceMetadata(retained.snapshotRoot, retained.source.checkpointEvidence),
|
|
279
294
|
recordSource: retained.source,
|
|
280
295
|
sourceHash: retained.source.sourceHash,
|
|
281
296
|
assetsBase: display.routes.assetsBase,
|
|
@@ -338,8 +353,12 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
338
353
|
}
|
|
339
354
|
const {review, parts} = await pending;
|
|
340
355
|
await assertReviewUnchanged(review);
|
|
356
|
+
if (retained.checkpointEvidencePackageHash !== undefined && retained.checkpointEvidencePackageHash !== review.sourceHash) {
|
|
357
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
358
|
+
}
|
|
341
359
|
if (path === 'api/review') {
|
|
342
360
|
return json({
|
|
361
|
+
...checkpointEvidenceMetadata(retained.snapshotRoot, retained.source.checkpointEvidence),
|
|
343
362
|
manifest: review.manifest,
|
|
344
363
|
sourceHash: retained.source.sourceHash,
|
|
345
364
|
reviewedSource: review.reviewedSource,
|
|
@@ -427,7 +446,9 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
427
446
|
const code = error instanceof JobError ? error.code :
|
|
428
447
|
error instanceof Error && error.message.startsWith('PARTS_COMMENT_STALE_SOURCE:')
|
|
429
448
|
? 'PARTS_COMMENT_STALE_SOURCE' : 'JOB_SOURCE_MISMATCH';
|
|
430
|
-
|
|
449
|
+
const message = error instanceof JobError && /^(CHECKPOINT_EVIDENCE|PLAN_TEXT)_[A-Z_]+$/.test(error.message)
|
|
450
|
+
? error.message : undefined;
|
|
451
|
+
return failure(code, errorStatus[code as JobErrorCode] ?? 409, undefined, message);
|
|
431
452
|
}
|
|
432
453
|
};
|
|
433
454
|
}
|
package/src/job-host.ts
CHANGED
|
@@ -208,3 +208,5 @@ export type {
|
|
|
208
208
|
|
|
209
209
|
export {assertJobImageSetCapability} from './job-image-set.ts';
|
|
210
210
|
export type {JobCapabilities, JobImageSetInput, JobImageSet, JobImageSourceBinding, JobModelSourceBinding, JobModelReviewValue, JobImageReviewValue} from './job-contract.ts';
|
|
211
|
+
|
|
212
|
+
export type {JobCheckpointEvidence, JobCheckpointTable} from './job-contract.ts';
|
package/src/job-session.ts
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
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 { jobApiSchemaForMode, jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
11
|
+
import { isRecordSource, parseRecordSource, jobApiSchemaForMode, jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
|
|
12
12
|
import {
|
|
13
|
-
assertJobRoot, assertJobSourceCurrent, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot, verifyJobRecordSourceFresh,
|
|
13
|
+
assertStoredCheckpointEvidence, assertJobRoot, assertJobSourceCurrent, assertRetainedSnapshotIntact, captureJobRoot, isRetainedRecordSource, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot, verifyJobRecordSourceFresh,
|
|
14
14
|
type JobPublicationReader, type JobRetainedSource, type JobRetainedSourceV3, type JobRootIdentity,
|
|
15
15
|
} from './job-source.ts';
|
|
16
16
|
import { JobError, JobStore, type JobSnapshotOwner, type StoredJob } from './job-store.ts';
|
|
@@ -77,6 +77,37 @@ function assertStoredSchemas(data: JobData): void {
|
|
|
77
77
|
if (data.apiSchema !== JOB_API_SCHEMA || data.actSchema !== JOB_ACT_SCHEMA) {
|
|
78
78
|
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'JOB_STORED_SCHEMA_MISMATCH');
|
|
79
79
|
}
|
|
80
|
+
assertStoredEvidence(data);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Check only the new extension and its durable copies, including committed replay values. */
|
|
84
|
+
function assertStoredEvidence(data: JobData): void {
|
|
85
|
+
for (const stored of Object.values(data.publications)) {
|
|
86
|
+
assertStoredCheckpointEvidence(stored.retained);
|
|
87
|
+
assertStoredEvidenceCopy(stored.publication, data);
|
|
88
|
+
}
|
|
89
|
+
for (const ask of Object.values(data.asks)) assertStoredEvidenceCopy(ask, data);
|
|
90
|
+
for (const act of Object.values(data.acts)) assertStoredEvidenceCopy(act, data);
|
|
91
|
+
for (const event of data.events) {
|
|
92
|
+
if (event.type === 'published') assertStoredEvidenceCopy(event.publication, data);
|
|
93
|
+
if (event.type === 'pending') assertStoredEvidenceCopy(event.ask, data);
|
|
94
|
+
if (event.type === 'act') assertStoredEvidenceCopy(event.act, data);
|
|
95
|
+
}
|
|
96
|
+
for (const replay of Object.values(data.replays)) assertStoredEvidenceCopy(replay.value, data);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function assertStoredEvidenceCopy(value: unknown, data: JobData): void {
|
|
100
|
+
if (!value || typeof value !== 'object') return;
|
|
101
|
+
const copy = value as {publicationId: string; source: JobPublication['source'] | PublicationV3['source']};
|
|
102
|
+
const stored = data.publications[copy.publicationId];
|
|
103
|
+
const bound = stored?.retained.source;
|
|
104
|
+
if (!('source' in value) && !(bound && 'checkpointEvidence' in bound)) return;
|
|
105
|
+
if (!copy.source || typeof copy.source !== 'object' || Array.isArray(copy.source)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
106
|
+
if (!('checkpointEvidence' in copy.source) && !(bound && 'checkpointEvidence' in bound)) return;
|
|
107
|
+
if (!bound || copy.source.sourceHash !== bound.sourceHash ||
|
|
108
|
+
requestDigest(copy.source.checkpointEvidence ?? null) !== requestDigest(bound.checkpointEvidence ?? null) ||
|
|
109
|
+
requestDigest(copy.source.plan) !== requestDigest(bound.plan)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
110
|
+
if (isRecordSource(copy.source)) parseRecordSource(copy.source);
|
|
80
111
|
}
|
|
81
112
|
|
|
82
113
|
function within(root: string, path: string): boolean {
|
|
@@ -359,6 +390,7 @@ export class JobSession {
|
|
|
359
390
|
}
|
|
360
391
|
|
|
361
392
|
private replay(data: JobData, key: string, digest: string): Replay | null {
|
|
393
|
+
assertStoredSchemas(data);
|
|
362
394
|
const previous = data.replays[key];
|
|
363
395
|
if (previous && previous.digest !== digest) throw new JobError('JOB_IDEMPOTENCY_CONFLICT');
|
|
364
396
|
return previous ?? null;
|
|
@@ -490,7 +522,7 @@ export class JobSession {
|
|
|
490
522
|
switch (input.verb) {
|
|
491
523
|
case 'publish': {
|
|
492
524
|
assertJobSourceCurrent(candidate!);
|
|
493
|
-
if (isRetainedRecordSource(candidate!)) {
|
|
525
|
+
if (isRetainedRecordSource(candidate!) || candidate!.source.checkpointEvidence) {
|
|
494
526
|
assertRetainedSnapshotIntact(
|
|
495
527
|
candidate!.snapshotRoot,
|
|
496
528
|
candidate!.seals,
|
|
@@ -518,7 +550,7 @@ export class JobSession {
|
|
|
518
550
|
if (data.head !== input.publicationId) throw new JobError('JOB_ACT_SOURCE_STALE');
|
|
519
551
|
const retained = data.publications[input.publicationId].retained;
|
|
520
552
|
assertJobSourceCurrent(retained);
|
|
521
|
-
if (isRetainedRecordSource(retained)) {
|
|
553
|
+
if (isRetainedRecordSource(retained) || retained.source.checkpointEvidence) {
|
|
522
554
|
assertRetainedSnapshotIntact(
|
|
523
555
|
retained.snapshotRoot,
|
|
524
556
|
retained.seals,
|
|
@@ -679,7 +711,7 @@ export class JobSession {
|
|
|
679
711
|
if (!ask) throw new JobError('JOB_ASK_INVALID');
|
|
680
712
|
const retained = fresh.data.publications[input.publicationId].retained;
|
|
681
713
|
assertJobSourceCurrent(retained);
|
|
682
|
-
if (isRetainedRecordSource(retained) || input.kind === 'parts-verdict') {
|
|
714
|
+
if (isRetainedRecordSource(retained) || retained.source.checkpointEvidence || input.kind === 'parts-verdict') {
|
|
683
715
|
assertRetainedSnapshotIntact(
|
|
684
716
|
retained.snapshotRoot,
|
|
685
717
|
retained.seals,
|
package/src/job-source.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import {checkpointEvidenceFields, checkpointEvidenceMetadata} from './job-checkpoint-evidence.ts';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { type Dirent, lstatSync, readdirSync, realpathSync, type Stats } from 'node:fs';
|
|
3
4
|
import { mkdir, open, rm, writeFile } from 'node:fs/promises';
|
|
4
5
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
5
6
|
import { PNG } from 'pngjs';
|
|
6
7
|
import {
|
|
7
|
-
JOB_API_V3_SCHEMA,
|
|
8
|
+
JOB_API_V3_SCHEMA, JOB_PLAN_TEXT_FIELDS, JOB_PLAN_TEXT_SCHEMA,
|
|
8
9
|
JOB_PARTS_ENUMERATOR_RANGE,
|
|
9
10
|
} from './job-contract.ts';
|
|
10
11
|
import type {
|
|
11
|
-
JobFileIdentity, JobImageSetInput, JobInterviewDiagnostics, JobInterviewRecord, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
12
|
-
JobSelector, JobSourceBinding, JobSubject,
|
|
12
|
+
JobCheckpointEvidence, JobFileIdentity, JobImageSetInput, JobInterviewDiagnostics, JobInterviewRecord, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
|
|
13
|
+
JobSelector, JobSourceBinding, JobSubject, JobPlanTextProjection, JobPlanTextStep,
|
|
13
14
|
OptionContext, OptionSource, PackageResultV3, PlanContext, PlanSource, ProjectRecord, PublishRequestV3,
|
|
14
15
|
RecordFreeze, RecordOptionResult, RecordPlanResult, RecordPublicationReader, RecordPublishedContext,
|
|
15
16
|
RecordReaderInput, RecordResult, RecordSource, RecordSubject,
|
|
@@ -55,6 +56,7 @@ export interface JobRootIdentity {
|
|
|
55
56
|
* referenced-image enumeration belongs to the public Parts #1163 surface.
|
|
56
57
|
*/
|
|
57
58
|
export interface JobPublishedContext {
|
|
59
|
+
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
58
60
|
readonly imageSet?: JobImageSetInput;
|
|
59
61
|
readonly selector: JobSelector | null;
|
|
60
62
|
readonly plan: JobPlanIdentity | null;
|
|
@@ -71,6 +73,8 @@ export type JobPublicationReader = (input: {
|
|
|
71
73
|
}) => Promise<JobPublishedContext>;
|
|
72
74
|
|
|
73
75
|
export interface JobRetainedSource {
|
|
76
|
+
/** Private base preimage for evidence-aware durable validation, absent historically. */
|
|
77
|
+
readonly checkpointEvidencePackageHash?: string;
|
|
74
78
|
readonly root: JobRootIdentity;
|
|
75
79
|
readonly record: JobFileIdentity | null;
|
|
76
80
|
readonly seals: readonly JobFileIdentity[];
|
|
@@ -651,7 +655,7 @@ async function readRecordPublishedPhase(
|
|
|
651
655
|
return parseRecordPublishedContext(raw, input.result, input.record);
|
|
652
656
|
}
|
|
653
657
|
|
|
654
|
-
function readProjectRecordBytes(root: string, record: ProjectRecord): {
|
|
658
|
+
function readProjectRecordBytes(root: string, record: ProjectRecord, allowLegacySchema = false): {
|
|
655
659
|
readonly bytes: Buffer;
|
|
656
660
|
readonly project: Record<string, unknown>;
|
|
657
661
|
} {
|
|
@@ -659,15 +663,15 @@ function readProjectRecordBytes(root: string, record: ProjectRecord): {
|
|
|
659
663
|
try {
|
|
660
664
|
stat = lstatSync(join(root, record.path));
|
|
661
665
|
} catch {
|
|
662
|
-
throw new JobError('JOB_RECORD_MOVED');
|
|
666
|
+
throw new JobError(allowLegacySchema ? 'JOB_SOURCE_UNRETAINABLE' : 'JOB_RECORD_MOVED');
|
|
663
667
|
}
|
|
664
|
-
if (!stat.isFile()) throw new JobError('JOB_RECORD_MOVED');
|
|
668
|
+
if (!stat.isFile()) throw new JobError(allowLegacySchema ? 'JOB_SOURCE_UNRETAINABLE' : 'JOB_RECORD_MOVED');
|
|
665
669
|
if (stat.size > maxProjectBytes) throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
666
670
|
let bytes: Buffer;
|
|
667
671
|
try {
|
|
668
672
|
bytes = sourceBytes(root, record.path);
|
|
669
673
|
} catch {
|
|
670
|
-
throw new JobError('JOB_RECORD_MOVED');
|
|
674
|
+
throw new JobError(allowLegacySchema ? 'JOB_SOURCE_UNRETAINABLE' : 'JOB_RECORD_MOVED');
|
|
671
675
|
}
|
|
672
676
|
if (jobHash(bytes) !== record.sha256) throw new JobError('JOB_RECORD_MOVED');
|
|
673
677
|
let project: Record<string, unknown>;
|
|
@@ -676,7 +680,7 @@ function readProjectRecordBytes(root: string, record: ProjectRecord): {
|
|
|
676
680
|
} catch {
|
|
677
681
|
throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
678
682
|
}
|
|
679
|
-
if (project.schema !== 'rig-create/project@0') throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
683
|
+
if (!allowLegacySchema && project.schema !== 'rig-create/project@0') throw new JobError('JOB_RECORD_INCOMPLETE');
|
|
680
684
|
return { bytes, project };
|
|
681
685
|
}
|
|
682
686
|
|
|
@@ -708,6 +712,83 @@ function readClosureFileBytes(root: string, file: JobFileIdentity): Buffer {
|
|
|
708
712
|
return bytes;
|
|
709
713
|
}
|
|
710
714
|
|
|
715
|
+
/** Delivery-only projection through the existing retained record reader. */
|
|
716
|
+
export function projectRetainedPlanText(retained: JobRetainedSourceV3): JobPlanTextProjection | undefined {
|
|
717
|
+
const {source, record} = retained;
|
|
718
|
+
const plan = source.plan;
|
|
719
|
+
if (!plan) return undefined;
|
|
720
|
+
let identity: {path: 'project.json'; sha256: string} | null = null;
|
|
721
|
+
const unavailable = (reason: Extract<JobPlanTextProjection, {status:'unavailable'}>['reason']): JobPlanTextProjection =>
|
|
722
|
+
({schema:JOB_PLAN_TEXT_SCHEMA, record:identity, status:'unavailable', reason});
|
|
723
|
+
if (!record || !source.projectHash) return unavailable('PLAN_TEXT_RECORD_UNAVAILABLE');
|
|
724
|
+
if (record.path !== 'project.json') return unavailable('PLAN_TEXT_RECORD_UNSUPPORTED');
|
|
725
|
+
const seals = retained.seals.filter(file => file.path === record.path);
|
|
726
|
+
if (record.sha256 !== source.projectHash || seals.length !== 1 || seals[0]!.sha256 !== record.sha256 ||
|
|
727
|
+
isRetainedRecordSource(retained) && (!retained.source.files.some(file => file.path === record.path && file.sha256 === record.sha256) ||
|
|
728
|
+
retained.source.record.path !== record.path || retained.source.record.sha256 !== record.sha256)) {
|
|
729
|
+
throw new JobError('JOB_SOURCE_MISMATCH', 'PLAN_TEXT_RECORD_MISMATCH');
|
|
730
|
+
}
|
|
731
|
+
identity = {path:'project.json', sha256:record.sha256};
|
|
732
|
+
let project: Record<string, unknown>;
|
|
733
|
+
try {project = readProjectRecordBytes(retained.snapshotRoot, identity, true).project;}
|
|
734
|
+
catch (error) {
|
|
735
|
+
if (error instanceof JobError && error.code === 'JOB_RECORD_MOVED')
|
|
736
|
+
throw new JobError('JOB_SOURCE_MISMATCH', 'PLAN_TEXT_RECORD_HASH_MISMATCH');
|
|
737
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PLAN_TEXT_RECORD_UNAVAILABLE');
|
|
738
|
+
}
|
|
739
|
+
if (project.schema !== 'rig-create/project@0') return unavailable('PLAN_TEXT_RECORD_UNSUPPORTED');
|
|
740
|
+
if (!Object.hasOwn(project, 'plan')) return unavailable('PLAN_TEXT_STEPS_ABSENT');
|
|
741
|
+
const rawPlan = asPlainObject(project.plan);
|
|
742
|
+
if (!rawPlan) return unavailable('PLAN_TEXT_STEPS_INVALID');
|
|
743
|
+
if (!Object.hasOwn(rawPlan, 'steps')) return unavailable('PLAN_TEXT_STEPS_ABSENT');
|
|
744
|
+
const rawSteps = rawPlan.steps;
|
|
745
|
+
if (!Array.isArray(rawSteps)) return unavailable('PLAN_TEXT_STEPS_INVALID');
|
|
746
|
+
if (plan.steps.length > 4096) return unavailable('PLAN_TEXT_LIMIT');
|
|
747
|
+
if (isRetainedRecordSource(retained) && (rawSteps.length !== plan.steps.length ||
|
|
748
|
+
rawSteps.some((raw, index) => asPlainObject(raw)?.id !== plan.steps[index]?.id)))
|
|
749
|
+
return unavailable('PLAN_TEXT_MAPPING_UNAVAILABLE');
|
|
750
|
+
const wanted = new Set(plan.steps.map(step => step.id));
|
|
751
|
+
const matched = new Map<string, Record<string, unknown> | null>();
|
|
752
|
+
for (const raw of rawSteps) {
|
|
753
|
+
const step = asPlainObject(raw);
|
|
754
|
+
if (typeof step?.id === 'string' && wanted.has(step.id))
|
|
755
|
+
matched.set(step.id, matched.has(step.id) ? null : step);
|
|
756
|
+
}
|
|
757
|
+
if (plan.steps.some(step => !matched.get(step.id))) return unavailable('PLAN_TEXT_MAPPING_UNAVAILABLE');
|
|
758
|
+
const steps = plan.steps.map<JobPlanTextStep>(step => {
|
|
759
|
+
const raw = matched.get(step.id)!;
|
|
760
|
+
const fields: Omit<JobPlanTextStep, 'id' | 'hash' | 'issues'> = {};
|
|
761
|
+
const issues: JobPlanTextStep['issues'] = [];
|
|
762
|
+
for (const field of JOB_PLAN_TEXT_FIELDS) {
|
|
763
|
+
const value = raw[field];
|
|
764
|
+
if (!Object.hasOwn(raw, field)) issues.push({field, reason:'absent'});
|
|
765
|
+
else if (field === 'rests_on') {
|
|
766
|
+
if (!Array.isArray(value) || value.some(item => typeof item !== 'string')) issues.push({field, reason:'invalid'});
|
|
767
|
+
else if (value.length > 4096) issues.push({field, reason:'limit'});
|
|
768
|
+
else fields.rests_on = value;
|
|
769
|
+
} else if (typeof value === 'string') fields[field] = value;
|
|
770
|
+
else issues.push({field, reason:'invalid'});
|
|
771
|
+
}
|
|
772
|
+
return {id:step.id, hash:step.hash, ...fields, issues};
|
|
773
|
+
});
|
|
774
|
+
const projection: JobPlanTextProjection = {schema:JOB_PLAN_TEXT_SCHEMA, record:identity, status:'projected', steps};
|
|
775
|
+
return Buffer.byteLength(JSON.stringify(projection)) > 512 * 1024 ? unavailable('PLAN_TEXT_LIMIT') : projection;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/** Keep the normal owner metadata budget, including the small fallback itself. */
|
|
779
|
+
export function planTextMetadata(retained: JobRetainedSourceV3, metadata: Record<string, unknown>): Record<string, unknown> {
|
|
780
|
+
const projection = projectRetainedPlanText(retained);
|
|
781
|
+
if (!projection) return metadata;
|
|
782
|
+
let result = {...metadata, planText:projection};
|
|
783
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 2 * 1024 * 1024) {
|
|
784
|
+
result = {...metadata, planText:{schema:JOB_PLAN_TEXT_SCHEMA, record:projection.record,
|
|
785
|
+
status:'unavailable', reason:'PLAN_TEXT_LIMIT'}};
|
|
786
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 2 * 1024 * 1024)
|
|
787
|
+
throw new JobError('JOB_BODY_LIMIT', 'PLAN_TEXT_LIMIT');
|
|
788
|
+
}
|
|
789
|
+
return result;
|
|
790
|
+
}
|
|
791
|
+
|
|
711
792
|
function decodeRetainedRecordProject(
|
|
712
793
|
snapshotRoot: string,
|
|
713
794
|
seals: readonly JobFileIdentity[],
|
|
@@ -859,6 +940,7 @@ export async function prepareJobRecordSource(options: {
|
|
|
859
940
|
if (inventory.files.length > maxSourceFiles) {
|
|
860
941
|
throw new JobError('JOB_SOURCE_UNRETAINABLE');
|
|
861
942
|
}
|
|
943
|
+
checkpointEvidenceMetadata(root.path, inventory.checkpointEvidence);
|
|
862
944
|
const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
|
|
863
945
|
const seals: JobFileIdentity[] = [];
|
|
864
946
|
let snapshotIdentity: { dev: number; ino: number } | null = null;
|
|
@@ -910,6 +992,7 @@ export async function prepareJobRecordSource(options: {
|
|
|
910
992
|
assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
|
|
911
993
|
assertEqualRecordContexts(inventory, retainedContext);
|
|
912
994
|
const decoded = decodeRetainedRecordProject(snapshotRoot, seals, result, retainedContext);
|
|
995
|
+
checkpointEvidenceMetadata(snapshotRoot, retainedContext.checkpointEvidence);
|
|
913
996
|
const source = parseRecordSource(
|
|
914
997
|
result.kind === 'option-set'
|
|
915
998
|
? buildRecordSource({
|
|
@@ -1052,6 +1135,14 @@ export async function verifyJobRecordSourceFresh(options: {
|
|
|
1052
1135
|
return freshSource;
|
|
1053
1136
|
}
|
|
1054
1137
|
|
|
1138
|
+
/** Preserve the existing composite preimage, conditionally appending the declaration. */
|
|
1139
|
+
function packageSourceDigest(packageSourceHash: string, record: JobFileIdentity | null,
|
|
1140
|
+
source: Pick<JobModelSourceBinding, 'selector' | 'plan' | 'parts'>, files: readonly JobFileIdentity[],
|
|
1141
|
+
evidence: {readonly checkpointEvidence?: readonly JobCheckpointEvidence[]}): string {
|
|
1142
|
+
return jobHash(JSON.stringify({schema: 'rig-review-job-source/2', packageSourceHash, record,
|
|
1143
|
+
selector: source.selector, plan: source.plan, parts: source.parts, files, ...evidence}));
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1055
1146
|
export async function prepareJobSource(options: {
|
|
1056
1147
|
readonly root: JobRootIdentity;
|
|
1057
1148
|
readonly stateRoot: string;
|
|
@@ -1168,6 +1259,10 @@ export async function prepareJobSource(options: {
|
|
|
1168
1259
|
}
|
|
1169
1260
|
if (requestDigest(context.selector) !== requestDigest(request.result.selector)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1170
1261
|
const declared = publishedIdentities(context);
|
|
1262
|
+
const evidence = checkpointEvidenceFields(context, context.plan, context.subjects, declared);
|
|
1263
|
+
if (evidence.checkpointEvidence && context.imageSet !== undefined) throw new JobError(
|
|
1264
|
+
'JOB_SOURCE_MISMATCH', 'CHECKPOINT_EVIDENCE_INVALID');
|
|
1265
|
+
checkpointEvidenceMetadata(root.path, evidence.checkpointEvidence);
|
|
1171
1266
|
let review: Awaited<ReturnType<typeof loadReview>>;
|
|
1172
1267
|
try {
|
|
1173
1268
|
const target = checkedPath(root.path, request.result.path, lstatSync(join(root.path, request.result.path)).isDirectory());
|
|
@@ -1243,11 +1338,10 @@ export async function prepareJobSource(options: {
|
|
|
1243
1338
|
const originalIdentity = (file: { path: string; sha256: string } | null): JobFileIdentity | null => file && ({
|
|
1244
1339
|
path: rootRelative(root.path, resolve(review.root, file.path)), sha256: file.sha256,
|
|
1245
1340
|
});
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
})) : review.sourceHash,
|
|
1341
|
+
checkpointEvidenceMetadata(snapshotRoot, evidence.checkpointEvidence);
|
|
1342
|
+
const modelSource: Omit<JobModelSourceBinding, 'checkpointEvidence'> = {
|
|
1343
|
+
sourceHash: project || context.plan || context.parts ? packageSourceDigest(review.sourceHash, record,
|
|
1344
|
+
{selector: context.selector, plan: context.plan, parts: parts.identity}, seals, evidence) : review.sourceHash,
|
|
1251
1345
|
projectHash: project?.hash ?? null,
|
|
1252
1346
|
package: { id: review.manifest.id, revision: review.manifest.revision },
|
|
1253
1347
|
selector: context.selector,
|
|
@@ -1255,7 +1349,7 @@ export async function prepareJobSource(options: {
|
|
|
1255
1349
|
direction: originalIdentity(review.direction?.file ?? null),
|
|
1256
1350
|
optionSet: null, appliedResult: null, plan: context.plan, parts: parts.identity,
|
|
1257
1351
|
};
|
|
1258
|
-
let source: JobSourceBinding = modelSource;
|
|
1352
|
+
let source: JobSourceBinding = {...modelSource, ...evidence};
|
|
1259
1353
|
if (imageSet) {
|
|
1260
1354
|
if (modelSource.model || modelSource.selector) throw new JobError('JOB_IMAGE_SET_INVALID');
|
|
1261
1355
|
const {model, selector, ...common} = modelSource;
|
|
@@ -1282,6 +1376,7 @@ export async function prepareJobSource(options: {
|
|
|
1282
1376
|
: null;
|
|
1283
1377
|
const prepared: JobRetainedSource = {
|
|
1284
1378
|
root, record, seals, snapshotRoot, snapshotIdentity,
|
|
1379
|
+
...(evidence.checkpointEvidence ? {checkpointEvidencePackageHash: review.sourceHash} : {}),
|
|
1285
1380
|
manifestPath: retained.manifestPath,
|
|
1286
1381
|
source,
|
|
1287
1382
|
instanceKey: openKey({ mode: 'single', p: boundReview, inputs: { input: review.manifestPath },
|
|
@@ -1303,6 +1398,7 @@ export async function prepareJobSource(options: {
|
|
|
1303
1398
|
};
|
|
1304
1399
|
await options.afterSnapshot?.();
|
|
1305
1400
|
assertJobSourceCurrent(prepared);
|
|
1401
|
+
if (source.checkpointEvidence) assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity);
|
|
1306
1402
|
return prepared;
|
|
1307
1403
|
} catch (error) {
|
|
1308
1404
|
if (snapshotIdentity) await removeOwnedJobSnapshot(options.stateRoot, {snapshotRoot, ...snapshotIdentity});
|
|
@@ -1310,3 +1406,29 @@ export async function prepareJobSource(options: {
|
|
|
1310
1406
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1311
1407
|
}
|
|
1312
1408
|
}
|
|
1409
|
+
|
|
1410
|
+
/** Authenticate the optional extension without opening live files or reclaimed snapshots. */
|
|
1411
|
+
export function assertStoredCheckpointEvidence(retained: JobRetainedSourceV3): void {
|
|
1412
|
+
if (!retained.source || typeof retained.source !== 'object' || Array.isArray(retained.source)) {
|
|
1413
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1414
|
+
}
|
|
1415
|
+
const hasEvidence = 'checkpointEvidence' in retained.source;
|
|
1416
|
+
if (isRetainedRecordSource(retained)) {
|
|
1417
|
+
const parsed = parseRecordSource(retained.source);
|
|
1418
|
+
if (!hasEvidence && !('checkpointEvidence' in retained.context)) return;
|
|
1419
|
+
const context = parseRecordPublishedContext(retained.context, retained.result, retained.record);
|
|
1420
|
+
if (requestDigest(parsed.checkpointEvidence ?? null) !== requestDigest(context.checkpointEvidence ?? null) ||
|
|
1421
|
+
requestDigest(parsed.subjects) !== requestDigest(retained.subjects) ||
|
|
1422
|
+
requestDigest(parsed.files) !== requestDigest(retained.seals)) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
if (!hasEvidence && !('checkpointEvidencePackageHash' in retained)) return;
|
|
1426
|
+
const source = retained.source;
|
|
1427
|
+
if (!hasEvidence || source.subject === 'image-set' || !retained.record) throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1428
|
+
const evidence = checkpointEvidenceFields(source, source.plan, retained.subjects, retained.seals);
|
|
1429
|
+
const packageSourceHash = jobSha(retained.checkpointEvidencePackageHash);
|
|
1430
|
+
const expected = packageSourceDigest(packageSourceHash, retained.record, source, retained.seals, evidence);
|
|
1431
|
+
if (expected !== source.sourceHash || requestDigest(evidence.checkpointEvidence) !== requestDigest(source.checkpointEvidence)) {
|
|
1432
|
+
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
1433
|
+
}
|
|
1434
|
+
}
|
package/web/catalog-en.ts
CHANGED
|
@@ -89,6 +89,24 @@ export const enCatalog: Readonly<Record<string, string>> = {
|
|
|
89
89
|
"interview.other": "Describe your choice",
|
|
90
90
|
"interview.otherPending": "Other stays pending until a tailored set is offered and explicitly picked.",
|
|
91
91
|
"interview.autoPending": "Auto stays pending until the agent records the covered decision.",
|
|
92
|
+
"job.plan.does": "Does",
|
|
93
|
+
"job.plan.produces": "Produces",
|
|
94
|
+
"job.plan.bar": "Bar",
|
|
95
|
+
"job.plan.rests_on": "Rests on",
|
|
96
|
+
"job.plan.noText": "Step text is not available; showing ids and hashes.",
|
|
97
|
+
"job.plan.field.absent": "Not supplied in this record.",
|
|
98
|
+
"job.plan.field.invalid": "The supplied field has an unsupported type.",
|
|
99
|
+
"job.plan.field.limit": "The supplied field exceeds the display limit.",
|
|
100
|
+
"PLAN_TEXT_RECORD_UNAVAILABLE": "The retained project record is unavailable.",
|
|
101
|
+
"PLAN_TEXT_RECORD_UNSUPPORTED": "This retained record has no supported project text.",
|
|
102
|
+
"PLAN_TEXT_STEPS_ABSENT": "The record supplies no plan steps.",
|
|
103
|
+
"PLAN_TEXT_STEPS_INVALID": "The record has an unsupported plan step list.",
|
|
104
|
+
"PLAN_TEXT_MAPPING_UNAVAILABLE": "Record steps cannot be matched to the displayed plan.",
|
|
105
|
+
"PLAN_TEXT_LIMIT": "Plan text exceeds the display delivery limit.",
|
|
106
|
+
"PLAN_TEXT_METADATA_INVALID": "Plan text metadata is invalid.",
|
|
107
|
+
"PLAN_TEXT_SOURCE_MISMATCH": "Plan text belongs to a different displayed source.",
|
|
108
|
+
"PLAN_TEXT_RECORD_MISMATCH": "The retained plan record binding differs from the displayed source.",
|
|
109
|
+
"PLAN_TEXT_RECORD_HASH_MISMATCH": "The retained plan record bytes differ from their seal.",
|
|
92
110
|
"interview.recommended": "AI recommendation",
|
|
93
111
|
"interview.note": "Note (optional)",
|
|
94
112
|
"interview.save": "Save explicit picks",
|
|
@@ -3374,6 +3392,15 @@ export const enCatalog: Readonly<Record<string, string>> = {
|
|
|
3374
3392
|
"JOB_ACT_SOURCE_STALE": "JOB_ACT_SOURCE_STALE",
|
|
3375
3393
|
"JOB_ACT_UNKNOWN": "JOB_ACT_UNKNOWN",
|
|
3376
3394
|
"JOB_AGENT_ISOLATION_HOLE": "JOB_AGENT_ISOLATION_HOLE",
|
|
3395
|
+
"job.checkpointEvidence": "Checkpoint evidence",
|
|
3396
|
+
"job.checkpointTable": "Classification table",
|
|
3397
|
+
"job.checkpointRoutes": "Routes",
|
|
3398
|
+
"job.checkpointRecommendation": "Recommendation",
|
|
3399
|
+
"job.checkpointRouteMapping": "Pass selects route (i), accepting the openings. Fail plus your words selects (ii) or (iii).",
|
|
3400
|
+
"CHECKPOINT_EVIDENCE_INVALID": "CHECKPOINT_EVIDENCE_INVALID",
|
|
3401
|
+
"CHECKPOINT_EVIDENCE_HASH_MISMATCH": "CHECKPOINT_EVIDENCE_HASH_MISMATCH",
|
|
3402
|
+
"CHECKPOINT_EVIDENCE_PNG_INVALID": "CHECKPOINT_EVIDENCE_PNG_INVALID",
|
|
3403
|
+
"CHECKPOINT_EVIDENCE_TABLE_INVALID": "CHECKPOINT_EVIDENCE_TABLE_INVALID",
|
|
3377
3404
|
"job.imageSetTitle": "Image comparison",
|
|
3378
3405
|
"job.imageSetDigest": "Image set SHA-256",
|
|
3379
3406
|
"job.imageNote": "Optional image note",
|
package/web/catalog-ko.ts
CHANGED
|
@@ -89,6 +89,24 @@ export const koCatalog: Readonly<Record<string, string>> = {
|
|
|
89
89
|
"interview.other": "원하는 선택을 설명하세요",
|
|
90
90
|
"interview.otherPending": "맞춤 세트가 제시되고 직접 선택할 때까지 기타 응답은 보류됩니다.",
|
|
91
91
|
"interview.autoPending": "에이전트가 해당 결정을 기록할 때까지 자동 위임은 보류됩니다.",
|
|
92
|
+
"job.plan.does": "할 일",
|
|
93
|
+
"job.plan.produces": "산출물",
|
|
94
|
+
"job.plan.bar": "기준",
|
|
95
|
+
"job.plan.rests_on": "근거 답변",
|
|
96
|
+
"job.plan.noText": "단계 설명을 읽을 수 없어 ID와 해시만 표시합니다.",
|
|
97
|
+
"job.plan.field.absent": "이 기록에 제공되지 않았습니다.",
|
|
98
|
+
"job.plan.field.invalid": "제공된 필드의 형식을 지원하지 않습니다.",
|
|
99
|
+
"job.plan.field.limit": "제공된 필드가 표시 한도를 초과합니다.",
|
|
100
|
+
"PLAN_TEXT_RECORD_UNAVAILABLE": "보존된 프로젝트 기록을 읽을 수 없습니다.",
|
|
101
|
+
"PLAN_TEXT_RECORD_UNSUPPORTED": "이 보존 기록의 프로젝트 설명 형식을 지원하지 않습니다.",
|
|
102
|
+
"PLAN_TEXT_STEPS_ABSENT": "기록에 계획 단계가 제공되지 않았습니다.",
|
|
103
|
+
"PLAN_TEXT_STEPS_INVALID": "기록의 계획 단계 목록 형식을 지원하지 않습니다.",
|
|
104
|
+
"PLAN_TEXT_MAPPING_UNAVAILABLE": "기록의 단계를 표시된 계획과 연결할 수 없습니다.",
|
|
105
|
+
"PLAN_TEXT_LIMIT": "계획 설명이 표시 전달 한도를 초과합니다.",
|
|
106
|
+
"PLAN_TEXT_METADATA_INVALID": "계획 설명 메타데이터가 올바르지 않습니다.",
|
|
107
|
+
"PLAN_TEXT_SOURCE_MISMATCH": "계획 설명이 표시된 원본과 일치하지 않습니다.",
|
|
108
|
+
"PLAN_TEXT_RECORD_MISMATCH": "보존된 계획 기록의 연결이 표시된 원본과 다릅니다.",
|
|
109
|
+
"PLAN_TEXT_RECORD_HASH_MISMATCH": "보존된 계획 기록의 바이트가 봉인 해시와 다릅니다.",
|
|
92
110
|
"interview.recommended": "AI 추천",
|
|
93
111
|
"interview.note": "메모 (선택 사항)",
|
|
94
112
|
"interview.save": "선택 기록 저장",
|
|
@@ -3374,6 +3392,15 @@ export const koCatalog: Readonly<Record<string, string>> = {
|
|
|
3374
3392
|
"JOB_ACT_SOURCE_STALE": "JOB_ACT_SOURCE_STALE",
|
|
3375
3393
|
"JOB_ACT_UNKNOWN": "JOB_ACT_UNKNOWN",
|
|
3376
3394
|
"JOB_AGENT_ISOLATION_HOLE": "JOB_AGENT_ISOLATION_HOLE",
|
|
3395
|
+
"job.checkpointEvidence": "체크포인트 근거",
|
|
3396
|
+
"job.checkpointTable": "분류 표",
|
|
3397
|
+
"job.checkpointRoutes": "경로",
|
|
3398
|
+
"job.checkpointRecommendation": "권고",
|
|
3399
|
+
"job.checkpointRouteMapping": "통과는 열린 부분을 수용하는 경로 (i)를 선택합니다. 실패와 소유자가 작성한 말은 (ii) 또는 (iii)를 선택합니다.",
|
|
3400
|
+
"CHECKPOINT_EVIDENCE_INVALID": "CHECKPOINT_EVIDENCE_INVALID",
|
|
3401
|
+
"CHECKPOINT_EVIDENCE_HASH_MISMATCH": "CHECKPOINT_EVIDENCE_HASH_MISMATCH",
|
|
3402
|
+
"CHECKPOINT_EVIDENCE_PNG_INVALID": "CHECKPOINT_EVIDENCE_PNG_INVALID",
|
|
3403
|
+
"CHECKPOINT_EVIDENCE_TABLE_INVALID": "CHECKPOINT_EVIDENCE_TABLE_INVALID",
|
|
3377
3404
|
"job.imageSetTitle": "이미지 비교",
|
|
3378
3405
|
"job.imageSetDigest": "이미지 세트 SHA-256",
|
|
3379
3406
|
"job.imageNote": "이미지 메모 (선택)",
|