@rig-c/review 2.9.0 → 2.10.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.
@@ -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,3 +1,4 @@
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';
@@ -8,7 +9,7 @@ import {
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
+ JobCheckpointEvidence, JobFileIdentity, JobImageSetInput, JobInterviewDiagnostics, JobInterviewRecord, JobModelSourceBinding, JobPartsEnumerator, JobPartsFileReference, JobPartsIdentity, JobPlanIdentity, JobPublishRequest,
12
13
  JobSelector, JobSourceBinding, JobSubject,
13
14
  OptionContext, OptionSource, PackageResultV3, PlanContext, PlanSource, ProjectRecord, PublishRequestV3,
14
15
  RecordFreeze, RecordOptionResult, RecordPlanResult, RecordPublicationReader, RecordPublishedContext,
@@ -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[];
@@ -859,6 +863,7 @@ export async function prepareJobRecordSource(options: {
859
863
  if (inventory.files.length > maxSourceFiles) {
860
864
  throw new JobError('JOB_SOURCE_UNRETAINABLE');
861
865
  }
866
+ checkpointEvidenceMetadata(root.path, inventory.checkpointEvidence);
862
867
  const snapshotRoot = join(options.stateRoot, 'snapshots', randomUUID());
863
868
  const seals: JobFileIdentity[] = [];
864
869
  let snapshotIdentity: { dev: number; ino: number } | null = null;
@@ -910,6 +915,7 @@ export async function prepareJobRecordSource(options: {
910
915
  assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity, 'JOB_SOURCE_UNRETAINABLE');
911
916
  assertEqualRecordContexts(inventory, retainedContext);
912
917
  const decoded = decodeRetainedRecordProject(snapshotRoot, seals, result, retainedContext);
918
+ checkpointEvidenceMetadata(snapshotRoot, retainedContext.checkpointEvidence);
913
919
  const source = parseRecordSource(
914
920
  result.kind === 'option-set'
915
921
  ? buildRecordSource({
@@ -1052,6 +1058,14 @@ export async function verifyJobRecordSourceFresh(options: {
1052
1058
  return freshSource;
1053
1059
  }
1054
1060
 
1061
+ /** Preserve the existing composite preimage, conditionally appending the declaration. */
1062
+ function packageSourceDigest(packageSourceHash: string, record: JobFileIdentity | null,
1063
+ source: Pick<JobModelSourceBinding, 'selector' | 'plan' | 'parts'>, files: readonly JobFileIdentity[],
1064
+ evidence: {readonly checkpointEvidence?: readonly JobCheckpointEvidence[]}): string {
1065
+ return jobHash(JSON.stringify({schema: 'rig-review-job-source/2', packageSourceHash, record,
1066
+ selector: source.selector, plan: source.plan, parts: source.parts, files, ...evidence}));
1067
+ }
1068
+
1055
1069
  export async function prepareJobSource(options: {
1056
1070
  readonly root: JobRootIdentity;
1057
1071
  readonly stateRoot: string;
@@ -1168,6 +1182,10 @@ export async function prepareJobSource(options: {
1168
1182
  }
1169
1183
  if (requestDigest(context.selector) !== requestDigest(request.result.selector)) throw new JobError('JOB_SOURCE_MISMATCH');
1170
1184
  const declared = publishedIdentities(context);
1185
+ const evidence = checkpointEvidenceFields(context, context.plan, context.subjects, declared);
1186
+ if (evidence.checkpointEvidence && context.imageSet !== undefined) throw new JobError(
1187
+ 'JOB_SOURCE_MISMATCH', 'CHECKPOINT_EVIDENCE_INVALID');
1188
+ checkpointEvidenceMetadata(root.path, evidence.checkpointEvidence);
1171
1189
  let review: Awaited<ReturnType<typeof loadReview>>;
1172
1190
  try {
1173
1191
  const target = checkedPath(root.path, request.result.path, lstatSync(join(root.path, request.result.path)).isDirectory());
@@ -1243,11 +1261,10 @@ export async function prepareJobSource(options: {
1243
1261
  const originalIdentity = (file: { path: string; sha256: string } | null): JobFileIdentity | null => file && ({
1244
1262
  path: rootRelative(root.path, resolve(review.root, file.path)), sha256: file.sha256,
1245
1263
  });
1246
- const modelSource: JobModelSourceBinding = {
1247
- sourceHash: project || context.plan || context.parts ? jobHash(JSON.stringify({
1248
- schema: 'rig-review-job-source/2', packageSourceHash: review.sourceHash,
1249
- record, selector: context.selector, plan: context.plan, parts: parts.identity, files: seals,
1250
- })) : review.sourceHash,
1264
+ checkpointEvidenceMetadata(snapshotRoot, evidence.checkpointEvidence);
1265
+ const modelSource: Omit<JobModelSourceBinding, 'checkpointEvidence'> = {
1266
+ sourceHash: project || context.plan || context.parts ? packageSourceDigest(review.sourceHash, record,
1267
+ {selector: context.selector, plan: context.plan, parts: parts.identity}, seals, evidence) : review.sourceHash,
1251
1268
  projectHash: project?.hash ?? null,
1252
1269
  package: { id: review.manifest.id, revision: review.manifest.revision },
1253
1270
  selector: context.selector,
@@ -1255,7 +1272,7 @@ export async function prepareJobSource(options: {
1255
1272
  direction: originalIdentity(review.direction?.file ?? null),
1256
1273
  optionSet: null, appliedResult: null, plan: context.plan, parts: parts.identity,
1257
1274
  };
1258
- let source: JobSourceBinding = modelSource;
1275
+ let source: JobSourceBinding = {...modelSource, ...evidence};
1259
1276
  if (imageSet) {
1260
1277
  if (modelSource.model || modelSource.selector) throw new JobError('JOB_IMAGE_SET_INVALID');
1261
1278
  const {model, selector, ...common} = modelSource;
@@ -1282,6 +1299,7 @@ export async function prepareJobSource(options: {
1282
1299
  : null;
1283
1300
  const prepared: JobRetainedSource = {
1284
1301
  root, record, seals, snapshotRoot, snapshotIdentity,
1302
+ ...(evidence.checkpointEvidence ? {checkpointEvidencePackageHash: review.sourceHash} : {}),
1285
1303
  manifestPath: retained.manifestPath,
1286
1304
  source,
1287
1305
  instanceKey: openKey({ mode: 'single', p: boundReview, inputs: { input: review.manifestPath },
@@ -1303,6 +1321,7 @@ export async function prepareJobSource(options: {
1303
1321
  };
1304
1322
  await options.afterSnapshot?.();
1305
1323
  assertJobSourceCurrent(prepared);
1324
+ if (source.checkpointEvidence) assertRetainedSnapshotIntact(snapshotRoot, seals, snapshotIdentity);
1306
1325
  return prepared;
1307
1326
  } catch (error) {
1308
1327
  if (snapshotIdentity) await removeOwnedJobSnapshot(options.stateRoot, {snapshotRoot, ...snapshotIdentity});
@@ -1310,3 +1329,29 @@ export async function prepareJobSource(options: {
1310
1329
  throw new JobError('JOB_SOURCE_MISMATCH');
1311
1330
  }
1312
1331
  }
1332
+
1333
+ /** Authenticate the optional extension without opening live files or reclaimed snapshots. */
1334
+ export function assertStoredCheckpointEvidence(retained: JobRetainedSourceV3): void {
1335
+ if (!retained.source || typeof retained.source !== 'object' || Array.isArray(retained.source)) {
1336
+ throw new JobError('JOB_SOURCE_MISMATCH');
1337
+ }
1338
+ const hasEvidence = 'checkpointEvidence' in retained.source;
1339
+ if (isRetainedRecordSource(retained)) {
1340
+ const parsed = parseRecordSource(retained.source);
1341
+ if (!hasEvidence && !('checkpointEvidence' in retained.context)) return;
1342
+ const context = parseRecordPublishedContext(retained.context, retained.result, retained.record);
1343
+ if (requestDigest(parsed.checkpointEvidence ?? null) !== requestDigest(context.checkpointEvidence ?? null) ||
1344
+ requestDigest(parsed.subjects) !== requestDigest(retained.subjects) ||
1345
+ requestDigest(parsed.files) !== requestDigest(retained.seals)) throw new JobError('JOB_SOURCE_MISMATCH');
1346
+ return;
1347
+ }
1348
+ if (!hasEvidence && !('checkpointEvidencePackageHash' in retained)) return;
1349
+ const source = retained.source;
1350
+ if (!hasEvidence || source.subject === 'image-set' || !retained.record) throw new JobError('JOB_SOURCE_MISMATCH');
1351
+ const evidence = checkpointEvidenceFields(source, source.plan, retained.subjects, retained.seals);
1352
+ const packageSourceHash = jobSha(retained.checkpointEvidencePackageHash);
1353
+ const expected = packageSourceDigest(packageSourceHash, retained.record, source, retained.seals, evidence);
1354
+ if (expected !== source.sourceHash || requestDigest(evidence.checkpointEvidence) !== requestDigest(source.checkpointEvidence)) {
1355
+ throw new JobError('JOB_SOURCE_MISMATCH');
1356
+ }
1357
+ }
package/web/catalog-en.ts CHANGED
@@ -3374,6 +3374,15 @@ export const enCatalog: Readonly<Record<string, string>> = {
3374
3374
  "JOB_ACT_SOURCE_STALE": "JOB_ACT_SOURCE_STALE",
3375
3375
  "JOB_ACT_UNKNOWN": "JOB_ACT_UNKNOWN",
3376
3376
  "JOB_AGENT_ISOLATION_HOLE": "JOB_AGENT_ISOLATION_HOLE",
3377
+ "job.checkpointEvidence": "Checkpoint evidence",
3378
+ "job.checkpointTable": "Classification table",
3379
+ "job.checkpointRoutes": "Routes",
3380
+ "job.checkpointRecommendation": "Recommendation",
3381
+ "job.checkpointRouteMapping": "Pass selects route (i), accepting the openings. Fail plus your words selects (ii) or (iii).",
3382
+ "CHECKPOINT_EVIDENCE_INVALID": "CHECKPOINT_EVIDENCE_INVALID",
3383
+ "CHECKPOINT_EVIDENCE_HASH_MISMATCH": "CHECKPOINT_EVIDENCE_HASH_MISMATCH",
3384
+ "CHECKPOINT_EVIDENCE_PNG_INVALID": "CHECKPOINT_EVIDENCE_PNG_INVALID",
3385
+ "CHECKPOINT_EVIDENCE_TABLE_INVALID": "CHECKPOINT_EVIDENCE_TABLE_INVALID",
3377
3386
  "job.imageSetTitle": "Image comparison",
3378
3387
  "job.imageSetDigest": "Image set SHA-256",
3379
3388
  "job.imageNote": "Optional image note",
package/web/catalog-ko.ts CHANGED
@@ -3374,6 +3374,15 @@ export const koCatalog: Readonly<Record<string, string>> = {
3374
3374
  "JOB_ACT_SOURCE_STALE": "JOB_ACT_SOURCE_STALE",
3375
3375
  "JOB_ACT_UNKNOWN": "JOB_ACT_UNKNOWN",
3376
3376
  "JOB_AGENT_ISOLATION_HOLE": "JOB_AGENT_ISOLATION_HOLE",
3377
+ "job.checkpointEvidence": "체크포인트 근거",
3378
+ "job.checkpointTable": "분류 표",
3379
+ "job.checkpointRoutes": "경로",
3380
+ "job.checkpointRecommendation": "권고",
3381
+ "job.checkpointRouteMapping": "통과는 열린 부분을 수용하는 경로 (i)를 선택합니다. 실패와 소유자가 작성한 말은 (ii) 또는 (iii)를 선택합니다.",
3382
+ "CHECKPOINT_EVIDENCE_INVALID": "CHECKPOINT_EVIDENCE_INVALID",
3383
+ "CHECKPOINT_EVIDENCE_HASH_MISMATCH": "CHECKPOINT_EVIDENCE_HASH_MISMATCH",
3384
+ "CHECKPOINT_EVIDENCE_PNG_INVALID": "CHECKPOINT_EVIDENCE_PNG_INVALID",
3385
+ "CHECKPOINT_EVIDENCE_TABLE_INVALID": "CHECKPOINT_EVIDENCE_TABLE_INVALID",
3377
3386
  "job.imageSetTitle": "이미지 비교",
3378
3387
  "job.imageSetDigest": "이미지 세트 SHA-256",
3379
3388
  "job.imageNote": "이미지 메모 (선택)",