@riddledc/riddle-proof 0.5.39 → 0.5.40

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.
@@ -2946,6 +2946,9 @@ function createRunResult(input) {
2946
2946
  finalized: state.finalized,
2947
2947
  blocker: state.blocker,
2948
2948
  checkpoint_packet: state.checkpoint_packet,
2949
+ checkpoint_summary: state.checkpoint_summary,
2950
+ state_paths: state.state_paths,
2951
+ proof_contract: state.proof_contract,
2949
2952
  proof_session: state.proof_session,
2950
2953
  evidence_bundle: input.evidence_bundle,
2951
2954
  raw: input.raw
@@ -3045,6 +3048,9 @@ function createRunState(input) {
3045
3048
  iterations: input.iterations ?? 0,
3046
3049
  last_checkpoint: input.last_checkpoint ?? null,
3047
3050
  checkpoint_packet: input.checkpoint_packet,
3051
+ checkpoint_summary: input.checkpoint_summary,
3052
+ state_paths: input.state_paths,
3053
+ proof_contract: input.proof_contract,
3048
3054
  checkpoint_history: input.checkpoint_history,
3049
3055
  events: input.events ? [...input.events] : []
3050
3056
  });
@@ -3120,6 +3126,9 @@ function createRunStatusSnapshot(state, at = timestamp()) {
3120
3126
  stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
3121
3127
  blocker: state.blocker,
3122
3128
  checkpoint_packet: state.checkpoint_packet,
3129
+ checkpoint_summary: state.checkpoint_summary,
3130
+ state_paths: state.state_paths,
3131
+ proof_contract: state.proof_contract,
3123
3132
  latest_event: latestEvent
3124
3133
  });
3125
3134
  }
@@ -3146,11 +3155,26 @@ function jsonCloneRecord(value) {
3146
3155
  return { ...record };
3147
3156
  }
3148
3157
  }
3158
+ function jsonCloneValue(value) {
3159
+ if (value === void 0 || value === null) return void 0;
3160
+ try {
3161
+ return JSON.parse(JSON.stringify(value));
3162
+ } catch {
3163
+ return value;
3164
+ }
3165
+ }
3149
3166
  function compactText(value, limit = 1600) {
3150
3167
  const text = nonEmptyString(value);
3151
3168
  if (!text) return void 0;
3152
3169
  return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
3153
3170
  }
3171
+ function statePathsForRunState(state, engineStatePath2) {
3172
+ return compactRecord({
3173
+ wrapper_state_path: state.state_path || state.request.harness_state_path || null,
3174
+ engine_state_path: engineStatePath2 || state.request.engine_state_path || null,
3175
+ resume_state_path: engineStatePath2 || state.request.engine_state_path || null
3176
+ });
3177
+ }
3154
3178
  function responseSchemaForAuthorPacket() {
3155
3179
  return {
3156
3180
  type: "object",
@@ -3292,6 +3316,40 @@ function normalizeCheckpointResponse(value) {
3292
3316
  created_at: nonEmptyString(record.created_at) || timestamp2()
3293
3317
  });
3294
3318
  }
3319
+ function checkpointSummaryFromState(state, engineStatePath2) {
3320
+ const history = state.checkpoint_history || [];
3321
+ const packets = history.filter((entry) => entry.packet);
3322
+ const responses = history.filter((entry) => entry.response);
3323
+ const latestPacketEntry = [...history].reverse().find((entry) => entry.packet);
3324
+ const latestResponseEntry = [...history].reverse().find((entry) => entry.response);
3325
+ const latestPacket = state.checkpoint_packet || latestPacketEntry?.packet;
3326
+ const latestResponse = latestResponseEntry?.response;
3327
+ const latestResumeToken = latestPacket?.resume_token || null;
3328
+ const latestResponseToken = latestResponse?.resume_token || null;
3329
+ const tokenMatches = latestResumeToken && latestResponseToken ? latestResumeToken === latestResponseToken : latestResumeToken || latestResponseToken ? false : null;
3330
+ return compactRecord({
3331
+ pending: Boolean(state.checkpoint_packet),
3332
+ packet_count: packets.length,
3333
+ response_count: responses.length,
3334
+ latest_checkpoint: state.checkpoint_packet?.checkpoint || latestResponse?.checkpoint || state.last_checkpoint || null,
3335
+ latest_stage: state.checkpoint_packet?.stage || latestResponse?.continue_with_stage || state.current_stage || null,
3336
+ latest_kind: state.checkpoint_packet?.kind || latestPacket?.kind || null,
3337
+ latest_decision: latestResponse?.decision || null,
3338
+ latest_packet_summary: latestPacket?.summary || null,
3339
+ latest_response_summary: latestResponse?.summary || null,
3340
+ latest_resume_token: latestResumeToken,
3341
+ latest_response_token: latestResponseToken,
3342
+ token_matches: tokenMatches,
3343
+ last_packet_at: latestPacketEntry?.ts || null,
3344
+ last_response_at: latestResponseEntry?.ts || null,
3345
+ state_paths: statePathsForRunState(state, engineStatePath2)
3346
+ });
3347
+ }
3348
+ function isDuplicateCheckpointResponse(state, response) {
3349
+ const latestResponse = [...state.checkpoint_history || []].reverse().find((entry) => entry.response)?.response;
3350
+ if (!latestResponse) return false;
3351
+ return latestResponse.run_id === response.run_id && latestResponse.checkpoint === response.checkpoint && latestResponse.resume_token === response.resume_token && latestResponse.decision === response.decision;
3352
+ }
3295
3353
  function authorPacketPayloadFromCheckpointResponse(response) {
3296
3354
  if (response.decision !== "author_packet") return null;
3297
3355
  const payload = recordValue(response.payload);
@@ -3301,6 +3359,37 @@ function authorPacketPayloadFromCheckpointResponse(response) {
3301
3359
  if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
3302
3360
  return candidate;
3303
3361
  }
3362
+ function proofContractFromAuthorCheckpointResponse(response, packet, payload) {
3363
+ const refinedInputs = recordValue(payload.refined_inputs) || {};
3364
+ return compactRecord({
3365
+ version: "riddle-proof.proof-contract.v1",
3366
+ checkpoint: packet.checkpoint,
3367
+ source_response: compactRecord({
3368
+ run_id: response.run_id,
3369
+ checkpoint: response.checkpoint,
3370
+ resume_token: response.resume_token,
3371
+ decision: response.decision,
3372
+ summary: response.summary,
3373
+ created_at: response.created_at
3374
+ }),
3375
+ proof_plan: nonEmptyString(payload.proof_plan),
3376
+ capture_script: nonEmptyString(payload.capture_script),
3377
+ artifact_contract: jsonCloneRecord(payload.artifact_contract),
3378
+ assertions: jsonCloneValue(payload.assertions),
3379
+ baseline_understanding: jsonCloneRecord(payload.baseline_understanding) || jsonCloneRecord(payload.recon_baseline_understanding) || jsonCloneRecord(packet.state_excerpt?.recon_baseline_understanding),
3380
+ route_assumptions: compactRecord({
3381
+ server_path: nonEmptyString(refinedInputs.server_path) || nonEmptyString(payload.server_path) || nonEmptyString(packet.state_excerpt?.server_path),
3382
+ wait_for_selector: nonEmptyString(refinedInputs.wait_for_selector) || nonEmptyString(payload.wait_for_selector) || nonEmptyString(packet.state_excerpt?.wait_for_selector),
3383
+ reference: nonEmptyString(refinedInputs.reference) || nonEmptyString(payload.reference),
3384
+ expected_path: nonEmptyString(payload.expected_path) || nonEmptyString(refinedInputs.expected_path)
3385
+ }),
3386
+ stop_condition: nonEmptyString(payload.stop_condition),
3387
+ rationale: jsonCloneValue(payload.rationale),
3388
+ verdict_dimensions: jsonCloneRecord(payload.verdict_dimensions),
3389
+ payload: jsonCloneRecord(payload),
3390
+ created_at: timestamp2()
3391
+ });
3392
+ }
3304
3393
 
3305
3394
  // src/engine-harness.ts
3306
3395
  init_proof_run_core();
@@ -3377,6 +3466,8 @@ function shouldPreserveFinalizedRunState(filePath, incoming) {
3377
3466
  return !(existing.status === "ready_to_ship" && incoming.status === "shipped");
3378
3467
  }
3379
3468
  function persist(state) {
3469
+ state.state_paths = statePathsForRunState(state);
3470
+ state.checkpoint_summary = checkpointSummaryFromState(state);
3380
3471
  if (!state.state_path) return;
3381
3472
  if (shouldPreserveFinalizedRunState(state.state_path, state)) return;
3382
3473
  writeJson(state.state_path, state);
@@ -3633,6 +3724,10 @@ function engineFailureBlocker(result, checkpoint) {
3633
3724
  };
3634
3725
  }
3635
3726
  function terminalResult(state, status, result, summary, raw = {}) {
3727
+ if (result) {
3728
+ const terminalStage = stageFromCheckpoint(result);
3729
+ if (terminalStage !== "setup") state.current_stage = terminalStage;
3730
+ }
3636
3731
  setRunStatus(state, status);
3637
3732
  if (isProtectedFinalStatus(status)) state.finalized = true;
3638
3733
  const metadata = normalizeTerminalMetadata({
@@ -3655,10 +3750,12 @@ function terminalResult(state, status, result, summary, raw = {}) {
3655
3750
  }
3656
3751
  function blockerResult(state, result, blocker) {
3657
3752
  state.blocker = blocker;
3753
+ const blockerStage = nonEmptyString(recordValue(blocker.details)?.stage);
3754
+ const stage = blockerStage || stageFromCheckpoint(result || { checkpoint: blocker.checkpoint || void 0 });
3658
3755
  recordEvent(state, {
3659
3756
  kind: "run.blocked",
3660
3757
  checkpoint: blocker.checkpoint || result?.checkpoint || null,
3661
- stage: stageFromCheckpoint(result || {}),
3758
+ stage,
3662
3759
  summary: blocker.message,
3663
3760
  details: {
3664
3761
  code: blocker.code,
@@ -3750,17 +3847,30 @@ function checkpointResponseContinuation(state, value) {
3750
3847
  code: "checkpoint_response_invalid",
3751
3848
  checkpoint: packet?.checkpoint || state.last_checkpoint || null,
3752
3849
  message: "Checkpoint response was not a valid riddle-proof.checkpoint_response.v1 object.",
3753
- details: { checkpoint_packet: packet || null }
3850
+ details: { checkpoint_packet: packet || null, checkpoint_summary: checkpointSummaryFromState(state) }
3754
3851
  }
3755
3852
  };
3756
3853
  }
3757
3854
  if (!packet) {
3855
+ if (isDuplicateCheckpointResponse(state, response)) {
3856
+ return {
3857
+ blocker: {
3858
+ code: "checkpoint_response_duplicate",
3859
+ checkpoint: response.checkpoint,
3860
+ message: "Checkpoint response was already accepted and there is no pending checkpoint packet to resume.",
3861
+ details: {
3862
+ response,
3863
+ checkpoint_summary: checkpointSummaryFromState(state)
3864
+ }
3865
+ }
3866
+ };
3867
+ }
3758
3868
  return {
3759
3869
  blocker: {
3760
3870
  code: "checkpoint_response_without_packet",
3761
3871
  checkpoint: response.checkpoint,
3762
3872
  message: "A checkpoint response was supplied, but the run state has no pending checkpoint packet.",
3763
- details: { response }
3873
+ details: { response, checkpoint_summary: checkpointSummaryFromState(state) }
3764
3874
  }
3765
3875
  };
3766
3876
  }
@@ -3771,6 +3881,7 @@ function checkpointResponseContinuation(state, value) {
3771
3881
  checkpoint: packet.checkpoint,
3772
3882
  message: "Checkpoint response does not match the pending checkpoint packet.",
3773
3883
  details: {
3884
+ stage: packet.stage,
3774
3885
  expected: { run_id: packet.run_id, checkpoint: packet.checkpoint },
3775
3886
  actual: { run_id: response.run_id, checkpoint: response.checkpoint }
3776
3887
  }
@@ -3783,7 +3894,11 @@ function checkpointResponseContinuation(state, value) {
3783
3894
  code: "checkpoint_response_resume_token_mismatch",
3784
3895
  checkpoint: packet.checkpoint,
3785
3896
  message: "Checkpoint response resume_token does not match the pending checkpoint packet.",
3786
- details: { expected_resume_token: packet.resume_token, actual_resume_token: response.resume_token || null }
3897
+ details: {
3898
+ stage: packet.stage,
3899
+ expected_resume_token: packet.resume_token,
3900
+ actual_resume_token: response.resume_token || null
3901
+ }
3787
3902
  }
3788
3903
  };
3789
3904
  }
@@ -3800,10 +3915,11 @@ function checkpointResponseContinuation(state, value) {
3800
3915
  code: "checkpoint_author_packet_missing",
3801
3916
  checkpoint: packet.checkpoint,
3802
3917
  message: "Checkpoint response decision=author_packet did not include a proof_plan and capture_script payload.",
3803
- details: { response }
3918
+ details: { stage: packet.stage, response }
3804
3919
  }
3805
3920
  };
3806
3921
  }
3922
+ state.proof_contract = proofContractFromAuthorCheckpointResponse(response, packet, payload);
3807
3923
  appendCheckpointResponse(state, response);
3808
3924
  return { next: { ...base, author_packet_json: jsonParam(payload) } };
3809
3925
  }
@@ -3817,7 +3933,7 @@ function checkpointResponseContinuation(state, value) {
3817
3933
  code: `checkpoint_response_${response.decision}`,
3818
3934
  checkpoint: packet.checkpoint,
3819
3935
  message: response.summary || `Checkpoint response stopped the run with decision=${response.decision}.`,
3820
- details: { response }
3936
+ details: { stage: packet.stage, response }
3821
3937
  }
3822
3938
  };
3823
3939
  }
@@ -2,10 +2,10 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-ORRP7CXT.js";
6
- import "./chunk-UQPTCP4D.js";
7
- import "./chunk-Z3BWCHFV.js";
8
- import "./chunk-Z7QUCDPT.js";
5
+ } from "./chunk-COFOLRUW.js";
6
+ import "./chunk-5LVCGDSD.js";
7
+ import "./chunk-7S7O3NKF.js";
8
+ import "./chunk-W7VTDN4T.js";
9
9
  import "./chunk-4YCWZVBN.js";
10
10
  export {
11
11
  createDisabledRiddleProofAgentAdapter,
package/dist/index.cjs CHANGED
@@ -2751,6 +2751,7 @@ __export(index_exports, {
2751
2751
  authorPacketPayloadFromCheckpointResponse: () => authorPacketPayloadFromCheckpointResponse,
2752
2752
  buildAuthorCheckpointPacket: () => buildAuthorCheckpointPacket,
2753
2753
  buildVisualProofSession: () => buildVisualProofSession,
2754
+ checkpointSummaryFromState: () => checkpointSummaryFromState,
2754
2755
  compactRecord: () => compactRecord,
2755
2756
  compareVisualProofSessionFingerprint: () => compareVisualProofSessionFingerprint,
2756
2757
  createCaptureDiagnostic: () => createCaptureDiagnostic,
@@ -2759,6 +2760,7 @@ __export(index_exports, {
2759
2760
  createRunState: () => createRunState,
2760
2761
  createRunStatusSnapshot: () => createRunStatusSnapshot,
2761
2762
  extractPlayabilityEvidence: () => extractPlayabilityEvidence,
2763
+ isDuplicateCheckpointResponse: () => isDuplicateCheckpointResponse,
2762
2764
  isRiddleProofPlayabilityMode: () => isRiddleProofPlayabilityMode,
2763
2765
  isSuccessfulStatus: () => isSuccessfulStatus,
2764
2766
  isTerminalStatus: () => isTerminalStatus,
@@ -2769,12 +2771,14 @@ __export(index_exports, {
2769
2771
  normalizeRunParams: () => normalizeRunParams,
2770
2772
  normalizeTerminalMetadata: () => normalizeTerminalMetadata,
2771
2773
  parseVisualProofSession: () => parseVisualProofSession,
2774
+ proofContractFromAuthorCheckpointResponse: () => proofContractFromAuthorCheckpointResponse,
2772
2775
  readRiddleProofRunStatus: () => readRiddleProofRunStatus,
2773
2776
  recordValue: () => recordValue,
2774
2777
  redactForProofDiagnostics: () => redactForProofDiagnostics,
2775
2778
  runRiddleProof: () => runRiddleProof,
2776
2779
  runRiddleProofEngineHarness: () => runRiddleProofEngineHarness,
2777
2780
  setRunStatus: () => setRunStatus,
2781
+ statePathsForRunState: () => statePathsForRunState,
2778
2782
  summarizeCaptureArtifacts: () => summarizeCaptureArtifacts,
2779
2783
  visualSessionFingerprint: () => visualSessionFingerprint,
2780
2784
  visualSessionFingerprintBasis: () => visualSessionFingerprintBasis
@@ -2986,6 +2990,9 @@ function createRunResult(input) {
2986
2990
  finalized: state.finalized,
2987
2991
  blocker: state.blocker,
2988
2992
  checkpoint_packet: state.checkpoint_packet,
2993
+ checkpoint_summary: state.checkpoint_summary,
2994
+ state_paths: state.state_paths,
2995
+ proof_contract: state.proof_contract,
2989
2996
  proof_session: state.proof_session,
2990
2997
  evidence_bundle: input.evidence_bundle,
2991
2998
  raw: input.raw
@@ -3115,6 +3122,9 @@ function createRunState(input) {
3115
3122
  iterations: input.iterations ?? 0,
3116
3123
  last_checkpoint: input.last_checkpoint ?? null,
3117
3124
  checkpoint_packet: input.checkpoint_packet,
3125
+ checkpoint_summary: input.checkpoint_summary,
3126
+ state_paths: input.state_paths,
3127
+ proof_contract: input.proof_contract,
3118
3128
  checkpoint_history: input.checkpoint_history,
3119
3129
  events: input.events ? [...input.events] : []
3120
3130
  });
@@ -3190,6 +3200,9 @@ function createRunStatusSnapshot(state, at = timestamp()) {
3190
3200
  stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
3191
3201
  blocker: state.blocker,
3192
3202
  checkpoint_packet: state.checkpoint_packet,
3203
+ checkpoint_summary: state.checkpoint_summary,
3204
+ state_paths: state.state_paths,
3205
+ proof_contract: state.proof_contract,
3193
3206
  latest_event: latestEvent
3194
3207
  });
3195
3208
  }
@@ -3233,11 +3246,26 @@ function jsonCloneRecord(value) {
3233
3246
  return { ...record };
3234
3247
  }
3235
3248
  }
3249
+ function jsonCloneValue(value) {
3250
+ if (value === void 0 || value === null) return void 0;
3251
+ try {
3252
+ return JSON.parse(JSON.stringify(value));
3253
+ } catch {
3254
+ return value;
3255
+ }
3256
+ }
3236
3257
  function compactText(value, limit = 1600) {
3237
3258
  const text = nonEmptyString(value);
3238
3259
  if (!text) return void 0;
3239
3260
  return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
3240
3261
  }
3262
+ function statePathsForRunState(state, engineStatePath2) {
3263
+ return compactRecord({
3264
+ wrapper_state_path: state.state_path || state.request.harness_state_path || null,
3265
+ engine_state_path: engineStatePath2 || state.request.engine_state_path || null,
3266
+ resume_state_path: engineStatePath2 || state.request.engine_state_path || null
3267
+ });
3268
+ }
3241
3269
  function responseSchemaForAuthorPacket() {
3242
3270
  return {
3243
3271
  type: "object",
@@ -3379,6 +3407,40 @@ function normalizeCheckpointResponse(value) {
3379
3407
  created_at: nonEmptyString(record.created_at) || timestamp2()
3380
3408
  });
3381
3409
  }
3410
+ function checkpointSummaryFromState(state, engineStatePath2) {
3411
+ const history = state.checkpoint_history || [];
3412
+ const packets = history.filter((entry) => entry.packet);
3413
+ const responses = history.filter((entry) => entry.response);
3414
+ const latestPacketEntry = [...history].reverse().find((entry) => entry.packet);
3415
+ const latestResponseEntry = [...history].reverse().find((entry) => entry.response);
3416
+ const latestPacket = state.checkpoint_packet || latestPacketEntry?.packet;
3417
+ const latestResponse = latestResponseEntry?.response;
3418
+ const latestResumeToken = latestPacket?.resume_token || null;
3419
+ const latestResponseToken = latestResponse?.resume_token || null;
3420
+ const tokenMatches = latestResumeToken && latestResponseToken ? latestResumeToken === latestResponseToken : latestResumeToken || latestResponseToken ? false : null;
3421
+ return compactRecord({
3422
+ pending: Boolean(state.checkpoint_packet),
3423
+ packet_count: packets.length,
3424
+ response_count: responses.length,
3425
+ latest_checkpoint: state.checkpoint_packet?.checkpoint || latestResponse?.checkpoint || state.last_checkpoint || null,
3426
+ latest_stage: state.checkpoint_packet?.stage || latestResponse?.continue_with_stage || state.current_stage || null,
3427
+ latest_kind: state.checkpoint_packet?.kind || latestPacket?.kind || null,
3428
+ latest_decision: latestResponse?.decision || null,
3429
+ latest_packet_summary: latestPacket?.summary || null,
3430
+ latest_response_summary: latestResponse?.summary || null,
3431
+ latest_resume_token: latestResumeToken,
3432
+ latest_response_token: latestResponseToken,
3433
+ token_matches: tokenMatches,
3434
+ last_packet_at: latestPacketEntry?.ts || null,
3435
+ last_response_at: latestResponseEntry?.ts || null,
3436
+ state_paths: statePathsForRunState(state, engineStatePath2)
3437
+ });
3438
+ }
3439
+ function isDuplicateCheckpointResponse(state, response) {
3440
+ const latestResponse = [...state.checkpoint_history || []].reverse().find((entry) => entry.response)?.response;
3441
+ if (!latestResponse) return false;
3442
+ return latestResponse.run_id === response.run_id && latestResponse.checkpoint === response.checkpoint && latestResponse.resume_token === response.resume_token && latestResponse.decision === response.decision;
3443
+ }
3382
3444
  function authorPacketPayloadFromCheckpointResponse(response) {
3383
3445
  if (response.decision !== "author_packet") return null;
3384
3446
  const payload = recordValue(response.payload);
@@ -3388,6 +3450,37 @@ function authorPacketPayloadFromCheckpointResponse(response) {
3388
3450
  if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
3389
3451
  return candidate;
3390
3452
  }
3453
+ function proofContractFromAuthorCheckpointResponse(response, packet, payload) {
3454
+ const refinedInputs = recordValue(payload.refined_inputs) || {};
3455
+ return compactRecord({
3456
+ version: "riddle-proof.proof-contract.v1",
3457
+ checkpoint: packet.checkpoint,
3458
+ source_response: compactRecord({
3459
+ run_id: response.run_id,
3460
+ checkpoint: response.checkpoint,
3461
+ resume_token: response.resume_token,
3462
+ decision: response.decision,
3463
+ summary: response.summary,
3464
+ created_at: response.created_at
3465
+ }),
3466
+ proof_plan: nonEmptyString(payload.proof_plan),
3467
+ capture_script: nonEmptyString(payload.capture_script),
3468
+ artifact_contract: jsonCloneRecord(payload.artifact_contract),
3469
+ assertions: jsonCloneValue(payload.assertions),
3470
+ baseline_understanding: jsonCloneRecord(payload.baseline_understanding) || jsonCloneRecord(payload.recon_baseline_understanding) || jsonCloneRecord(packet.state_excerpt?.recon_baseline_understanding),
3471
+ route_assumptions: compactRecord({
3472
+ server_path: nonEmptyString(refinedInputs.server_path) || nonEmptyString(payload.server_path) || nonEmptyString(packet.state_excerpt?.server_path),
3473
+ wait_for_selector: nonEmptyString(refinedInputs.wait_for_selector) || nonEmptyString(payload.wait_for_selector) || nonEmptyString(packet.state_excerpt?.wait_for_selector),
3474
+ reference: nonEmptyString(refinedInputs.reference) || nonEmptyString(payload.reference),
3475
+ expected_path: nonEmptyString(payload.expected_path) || nonEmptyString(refinedInputs.expected_path)
3476
+ }),
3477
+ stop_condition: nonEmptyString(payload.stop_condition),
3478
+ rationale: jsonCloneValue(payload.rationale),
3479
+ verdict_dimensions: jsonCloneRecord(payload.verdict_dimensions),
3480
+ payload: jsonCloneRecord(payload),
3481
+ created_at: timestamp2()
3482
+ });
3483
+ }
3391
3484
 
3392
3485
  // src/runner.ts
3393
3486
  function errorDetails(error) {
@@ -3950,6 +4043,8 @@ function shouldPreserveFinalizedRunState(filePath, incoming) {
3950
4043
  return !(existing.status === "ready_to_ship" && incoming.status === "shipped");
3951
4044
  }
3952
4045
  function persist(state) {
4046
+ state.state_paths = statePathsForRunState(state);
4047
+ state.checkpoint_summary = checkpointSummaryFromState(state);
3953
4048
  if (!state.state_path) return;
3954
4049
  if (shouldPreserveFinalizedRunState(state.state_path, state)) return;
3955
4050
  writeJson(state.state_path, state);
@@ -4206,6 +4301,10 @@ function engineFailureBlocker(result, checkpoint) {
4206
4301
  };
4207
4302
  }
4208
4303
  function terminalResult(state, status, result, summary, raw = {}) {
4304
+ if (result) {
4305
+ const terminalStage = stageFromCheckpoint(result);
4306
+ if (terminalStage !== "setup") state.current_stage = terminalStage;
4307
+ }
4209
4308
  setRunStatus(state, status);
4210
4309
  if (isProtectedFinalStatus(status)) state.finalized = true;
4211
4310
  const metadata = normalizeTerminalMetadata({
@@ -4228,10 +4327,12 @@ function terminalResult(state, status, result, summary, raw = {}) {
4228
4327
  }
4229
4328
  function blockerResult(state, result, blocker) {
4230
4329
  state.blocker = blocker;
4330
+ const blockerStage = nonEmptyString(recordValue(blocker.details)?.stage);
4331
+ const stage = blockerStage || stageFromCheckpoint(result || { checkpoint: blocker.checkpoint || void 0 });
4231
4332
  recordEvent(state, {
4232
4333
  kind: "run.blocked",
4233
4334
  checkpoint: blocker.checkpoint || result?.checkpoint || null,
4234
- stage: stageFromCheckpoint(result || {}),
4335
+ stage,
4235
4336
  summary: blocker.message,
4236
4337
  details: {
4237
4338
  code: blocker.code,
@@ -4323,17 +4424,30 @@ function checkpointResponseContinuation(state, value) {
4323
4424
  code: "checkpoint_response_invalid",
4324
4425
  checkpoint: packet?.checkpoint || state.last_checkpoint || null,
4325
4426
  message: "Checkpoint response was not a valid riddle-proof.checkpoint_response.v1 object.",
4326
- details: { checkpoint_packet: packet || null }
4427
+ details: { checkpoint_packet: packet || null, checkpoint_summary: checkpointSummaryFromState(state) }
4327
4428
  }
4328
4429
  };
4329
4430
  }
4330
4431
  if (!packet) {
4432
+ if (isDuplicateCheckpointResponse(state, response)) {
4433
+ return {
4434
+ blocker: {
4435
+ code: "checkpoint_response_duplicate",
4436
+ checkpoint: response.checkpoint,
4437
+ message: "Checkpoint response was already accepted and there is no pending checkpoint packet to resume.",
4438
+ details: {
4439
+ response,
4440
+ checkpoint_summary: checkpointSummaryFromState(state)
4441
+ }
4442
+ }
4443
+ };
4444
+ }
4331
4445
  return {
4332
4446
  blocker: {
4333
4447
  code: "checkpoint_response_without_packet",
4334
4448
  checkpoint: response.checkpoint,
4335
4449
  message: "A checkpoint response was supplied, but the run state has no pending checkpoint packet.",
4336
- details: { response }
4450
+ details: { response, checkpoint_summary: checkpointSummaryFromState(state) }
4337
4451
  }
4338
4452
  };
4339
4453
  }
@@ -4344,6 +4458,7 @@ function checkpointResponseContinuation(state, value) {
4344
4458
  checkpoint: packet.checkpoint,
4345
4459
  message: "Checkpoint response does not match the pending checkpoint packet.",
4346
4460
  details: {
4461
+ stage: packet.stage,
4347
4462
  expected: { run_id: packet.run_id, checkpoint: packet.checkpoint },
4348
4463
  actual: { run_id: response.run_id, checkpoint: response.checkpoint }
4349
4464
  }
@@ -4356,7 +4471,11 @@ function checkpointResponseContinuation(state, value) {
4356
4471
  code: "checkpoint_response_resume_token_mismatch",
4357
4472
  checkpoint: packet.checkpoint,
4358
4473
  message: "Checkpoint response resume_token does not match the pending checkpoint packet.",
4359
- details: { expected_resume_token: packet.resume_token, actual_resume_token: response.resume_token || null }
4474
+ details: {
4475
+ stage: packet.stage,
4476
+ expected_resume_token: packet.resume_token,
4477
+ actual_resume_token: response.resume_token || null
4478
+ }
4360
4479
  }
4361
4480
  };
4362
4481
  }
@@ -4373,10 +4492,11 @@ function checkpointResponseContinuation(state, value) {
4373
4492
  code: "checkpoint_author_packet_missing",
4374
4493
  checkpoint: packet.checkpoint,
4375
4494
  message: "Checkpoint response decision=author_packet did not include a proof_plan and capture_script payload.",
4376
- details: { response }
4495
+ details: { stage: packet.stage, response }
4377
4496
  }
4378
4497
  };
4379
4498
  }
4499
+ state.proof_contract = proofContractFromAuthorCheckpointResponse(response, packet, payload);
4380
4500
  appendCheckpointResponse(state, response);
4381
4501
  return { next: { ...base, author_packet_json: jsonParam(payload) } };
4382
4502
  }
@@ -4390,7 +4510,7 @@ function checkpointResponseContinuation(state, value) {
4390
4510
  code: `checkpoint_response_${response.decision}`,
4391
4511
  checkpoint: packet.checkpoint,
4392
4512
  message: response.summary || `Checkpoint response stopped the run with decision=${response.decision}.`,
4393
- details: { response }
4513
+ details: { stage: packet.stage, response }
4394
4514
  }
4395
4515
  };
4396
4516
  }
@@ -5541,6 +5661,7 @@ function parseJson(value) {
5541
5661
  authorPacketPayloadFromCheckpointResponse,
5542
5662
  buildAuthorCheckpointPacket,
5543
5663
  buildVisualProofSession,
5664
+ checkpointSummaryFromState,
5544
5665
  compactRecord,
5545
5666
  compareVisualProofSessionFingerprint,
5546
5667
  createCaptureDiagnostic,
@@ -5549,6 +5670,7 @@ function parseJson(value) {
5549
5670
  createRunState,
5550
5671
  createRunStatusSnapshot,
5551
5672
  extractPlayabilityEvidence,
5673
+ isDuplicateCheckpointResponse,
5552
5674
  isRiddleProofPlayabilityMode,
5553
5675
  isSuccessfulStatus,
5554
5676
  isTerminalStatus,
@@ -5559,12 +5681,14 @@ function parseJson(value) {
5559
5681
  normalizeRunParams,
5560
5682
  normalizeTerminalMetadata,
5561
5683
  parseVisualProofSession,
5684
+ proofContractFromAuthorCheckpointResponse,
5562
5685
  readRiddleProofRunStatus,
5563
5686
  recordValue,
5564
5687
  redactForProofDiagnostics,
5565
5688
  runRiddleProof,
5566
5689
  runRiddleProofEngineHarness,
5567
5690
  setRunStatus,
5691
+ statePathsForRunState,
5568
5692
  summarizeCaptureArtifacts,
5569
5693
  visualSessionFingerprint,
5570
5694
  visualSessionFingerprintBasis
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, RiddleProofCheckpointArtifact, RiddleProofCheckpointPacket, RiddleProofCheckpointResponse, RiddleProofCheckpointRole, RiddleProofCheckpointRoutingHint, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.cjs';
1
+ export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, RiddleProofCheckpointArtifact, RiddleProofCheckpointPacket, RiddleProofCheckpointResponse, RiddleProofCheckpointRole, RiddleProofCheckpointRoutingHint, RiddleProofCheckpointSummary, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofProofContract, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatePaths, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.cjs';
2
2
  export { TerminalMetadataInput, applyTerminalMetadata, compactRecord, createRunResult, isSuccessfulStatus, isTerminalStatus, nonEmptyString, normalizeTerminalMetadata, recordValue } from './result.cjs';
3
3
  export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, appendStageHeartbeat, applyPrLifecycleState, createRunState, createRunStatusSnapshot, normalizeIntegrationContext, normalizePrLifecycleState, normalizeRunParams, setRunStatus } from './state.cjs';
4
- export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, normalizeCheckpointResponse } from './checkpoint.cjs';
4
+ export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, checkpointSummaryFromState, isDuplicateCheckpointResponse, normalizeCheckpointResponse, proofContractFromAuthorCheckpointResponse, statePathsForRunState } from './checkpoint.cjs';
5
5
  export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.cjs';
6
6
  export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofCheckpointMode, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.cjs';
7
7
  export { CreateCaptureDiagnosticInput, DEFAULT_DIAGNOSTIC_ARRAY_LIMIT, DEFAULT_DIAGNOSTIC_HISTORY_LIMIT, DEFAULT_DIAGNOSTIC_STRING_LIMIT, RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION, RiddleProofArtifactSummary, RiddleProofCaptureArtifactSummary, RiddleProofCaptureDiagnostic, RiddleProofDiagnosticRedactionOptions, appendCaptureDiagnostic, createCaptureDiagnostic, redactForProofDiagnostics, summarizeCaptureArtifacts } from './diagnostics.cjs';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, RiddleProofCheckpointArtifact, RiddleProofCheckpointPacket, RiddleProofCheckpointResponse, RiddleProofCheckpointRole, RiddleProofCheckpointRoutingHint, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.js';
1
+ export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, RiddleProofCheckpointArtifact, RiddleProofCheckpointPacket, RiddleProofCheckpointResponse, RiddleProofCheckpointRole, RiddleProofCheckpointRoutingHint, RiddleProofCheckpointSummary, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofProofContract, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatePaths, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.js';
2
2
  export { TerminalMetadataInput, applyTerminalMetadata, compactRecord, createRunResult, isSuccessfulStatus, isTerminalStatus, nonEmptyString, normalizeTerminalMetadata, recordValue } from './result.js';
3
3
  export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, appendStageHeartbeat, applyPrLifecycleState, createRunState, createRunStatusSnapshot, normalizeIntegrationContext, normalizePrLifecycleState, normalizeRunParams, setRunStatus } from './state.js';
4
- export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, normalizeCheckpointResponse } from './checkpoint.js';
4
+ export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, checkpointSummaryFromState, isDuplicateCheckpointResponse, normalizeCheckpointResponse, proofContractFromAuthorCheckpointResponse, statePathsForRunState } from './checkpoint.js';
5
5
  export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.js';
6
6
  export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofCheckpointMode, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.js';
7
7
  export { CreateCaptureDiagnosticInput, DEFAULT_DIAGNOSTIC_ARRAY_LIMIT, DEFAULT_DIAGNOSTIC_HISTORY_LIMIT, DEFAULT_DIAGNOSTIC_STRING_LIMIT, RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION, RiddleProofArtifactSummary, RiddleProofCaptureArtifactSummary, RiddleProofCaptureDiagnostic, RiddleProofDiagnosticRedactionOptions, appendCaptureDiagnostic, createCaptureDiagnostic, redactForProofDiagnostics, summarizeCaptureArtifacts } from './diagnostics.js';
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-ODORKNSO.js";
10
10
  import {
11
11
  runRiddleProof
12
- } from "./chunk-RDTMR7XR.js";
12
+ } from "./chunk-MRSYJMF4.js";
13
13
  import "./chunk-6F4PWJZI.js";
14
14
  import {
15
15
  DEFAULT_DIAGNOSTIC_ARRAY_LIMIT,
@@ -25,14 +25,18 @@ import {
25
25
  createDisabledRiddleProofAgentAdapter,
26
26
  readRiddleProofRunStatus,
27
27
  runRiddleProofEngineHarness
28
- } from "./chunk-ORRP7CXT.js";
28
+ } from "./chunk-COFOLRUW.js";
29
29
  import {
30
30
  RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
31
31
  RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
32
32
  authorPacketPayloadFromCheckpointResponse,
33
33
  buildAuthorCheckpointPacket,
34
- normalizeCheckpointResponse
35
- } from "./chunk-UQPTCP4D.js";
34
+ checkpointSummaryFromState,
35
+ isDuplicateCheckpointResponse,
36
+ normalizeCheckpointResponse,
37
+ proofContractFromAuthorCheckpointResponse,
38
+ statePathsForRunState
39
+ } from "./chunk-5LVCGDSD.js";
36
40
  import {
37
41
  RIDDLE_PROOF_RUN_STATE_VERSION,
38
42
  appendRunEvent,
@@ -44,7 +48,7 @@ import {
44
48
  normalizePrLifecycleState,
45
49
  normalizeRunParams,
46
50
  setRunStatus
47
- } from "./chunk-Z3BWCHFV.js";
51
+ } from "./chunk-7S7O3NKF.js";
48
52
  import {
49
53
  applyTerminalMetadata,
50
54
  compactRecord,
@@ -54,7 +58,7 @@ import {
54
58
  nonEmptyString,
55
59
  normalizeTerminalMetadata,
56
60
  recordValue
57
- } from "./chunk-Z7QUCDPT.js";
61
+ } from "./chunk-W7VTDN4T.js";
58
62
  import {
59
63
  RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION,
60
64
  RIDDLE_PROOF_PLAYABILITY_VERSION,
@@ -84,6 +88,7 @@ export {
84
88
  authorPacketPayloadFromCheckpointResponse,
85
89
  buildAuthorCheckpointPacket,
86
90
  buildVisualProofSession,
91
+ checkpointSummaryFromState,
87
92
  compactRecord,
88
93
  compareVisualProofSessionFingerprint,
89
94
  createCaptureDiagnostic,
@@ -92,6 +97,7 @@ export {
92
97
  createRunState,
93
98
  createRunStatusSnapshot,
94
99
  extractPlayabilityEvidence,
100
+ isDuplicateCheckpointResponse,
95
101
  isRiddleProofPlayabilityMode,
96
102
  isSuccessfulStatus,
97
103
  isTerminalStatus,
@@ -102,12 +108,14 @@ export {
102
108
  normalizeRunParams,
103
109
  normalizeTerminalMetadata,
104
110
  parseVisualProofSession,
111
+ proofContractFromAuthorCheckpointResponse,
105
112
  readRiddleProofRunStatus,
106
113
  recordValue,
107
114
  redactForProofDiagnostics,
108
115
  runRiddleProof,
109
116
  runRiddleProofEngineHarness,
110
117
  setRunStatus,
118
+ statePathsForRunState,
111
119
  summarizeCaptureArtifacts,
112
120
  visualSessionFingerprint,
113
121
  visualSessionFingerprintBasis