@riddledc/riddle-proof 0.5.37 → 0.5.39

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/dist/index.cjs CHANGED
@@ -41,7 +41,7 @@ function currentDistDir() {
41
41
  }
42
42
  function createWorkflowStatePath() {
43
43
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.TZ]/g, "").slice(0, 14);
44
- return `/tmp/riddle-proof-state-${stamp}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}.json`;
44
+ return `/tmp/riddle-proof-state-${stamp}-${(0, import_node_crypto2.randomUUID)().slice(0, 8)}.json`;
45
45
  }
46
46
  function argsPathForStatePath(statePath) {
47
47
  const base = import_node_path.default.basename(statePath);
@@ -759,12 +759,12 @@ function summarizeState(state) {
759
759
  state: selected
760
760
  };
761
761
  }
762
- var import_node_fs, import_node_crypto, import_node_path, import_node_url, import_meta, WORKFLOW_STAGE_ORDER, CHECKPOINT_CONTRACT_VERSION, BUNDLED_RIDDLE_PROOF_DIR, RIDDLE_PROOF_DIR_CANDIDATES, VISUAL_FIRST_MODES, CHECKPOINT_CONTRACT_SPECS;
762
+ var import_node_fs, import_node_crypto2, import_node_path, import_node_url, import_meta, WORKFLOW_STAGE_ORDER, CHECKPOINT_CONTRACT_VERSION, BUNDLED_RIDDLE_PROOF_DIR, RIDDLE_PROOF_DIR_CANDIDATES, VISUAL_FIRST_MODES, CHECKPOINT_CONTRACT_SPECS;
763
763
  var init_proof_run_core = __esm({
764
764
  "src/proof-run-core.ts"() {
765
765
  "use strict";
766
766
  import_node_fs = require("fs");
767
- import_node_crypto = require("crypto");
767
+ import_node_crypto2 = require("crypto");
768
768
  import_node_path = __toESM(require("path"), 1);
769
769
  import_node_url = require("url");
770
770
  import_meta = {};
@@ -2735,6 +2735,8 @@ __export(index_exports, {
2735
2735
  DEFAULT_DIAGNOSTIC_HISTORY_LIMIT: () => DEFAULT_DIAGNOSTIC_HISTORY_LIMIT,
2736
2736
  DEFAULT_DIAGNOSTIC_STRING_LIMIT: () => DEFAULT_DIAGNOSTIC_STRING_LIMIT,
2737
2737
  RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION: () => RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION,
2738
+ RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION: () => RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
2739
+ RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION: () => RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
2738
2740
  RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION: () => RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION,
2739
2741
  RIDDLE_PROOF_PLAYABILITY_VERSION: () => RIDDLE_PROOF_PLAYABILITY_VERSION,
2740
2742
  RIDDLE_PROOF_RUN_STATE_VERSION: () => RIDDLE_PROOF_RUN_STATE_VERSION,
@@ -2746,6 +2748,8 @@ __export(index_exports, {
2746
2748
  applyPrLifecycleState: () => applyPrLifecycleState,
2747
2749
  applyTerminalMetadata: () => applyTerminalMetadata,
2748
2750
  assessPlayabilityEvidence: () => assessPlayabilityEvidence,
2751
+ authorPacketPayloadFromCheckpointResponse: () => authorPacketPayloadFromCheckpointResponse,
2752
+ buildAuthorCheckpointPacket: () => buildAuthorCheckpointPacket,
2749
2753
  buildVisualProofSession: () => buildVisualProofSession,
2750
2754
  compactRecord: () => compactRecord,
2751
2755
  compareVisualProofSessionFingerprint: () => compareVisualProofSessionFingerprint,
@@ -2759,6 +2763,7 @@ __export(index_exports, {
2759
2763
  isSuccessfulStatus: () => isSuccessfulStatus,
2760
2764
  isTerminalStatus: () => isTerminalStatus,
2761
2765
  nonEmptyString: () => nonEmptyString,
2766
+ normalizeCheckpointResponse: () => normalizeCheckpointResponse,
2762
2767
  normalizeIntegrationContext: () => normalizeIntegrationContext,
2763
2768
  normalizePrLifecycleState: () => normalizePrLifecycleState,
2764
2769
  normalizeRunParams: () => normalizeRunParams,
@@ -2980,6 +2985,7 @@ function createRunResult(input) {
2980
2985
  merge_recommendation: state.merge_recommendation,
2981
2986
  finalized: state.finalized,
2982
2987
  blocker: state.blocker,
2988
+ checkpoint_packet: state.checkpoint_packet,
2983
2989
  proof_session: state.proof_session,
2984
2990
  evidence_bundle: input.evidence_bundle,
2985
2991
  raw: input.raw
@@ -3108,6 +3114,8 @@ function createRunState(input) {
3108
3114
  request: normalizeRunParams(input.request),
3109
3115
  iterations: input.iterations ?? 0,
3110
3116
  last_checkpoint: input.last_checkpoint ?? null,
3117
+ checkpoint_packet: input.checkpoint_packet,
3118
+ checkpoint_history: input.checkpoint_history,
3111
3119
  events: input.events ? [...input.events] : []
3112
3120
  });
3113
3121
  }
@@ -3181,6 +3189,7 @@ function createRunStatusSnapshot(state, at = timestamp()) {
3181
3189
  elapsed_ms: elapsedMs(state.created_at, at),
3182
3190
  stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
3183
3191
  blocker: state.blocker,
3192
+ checkpoint_packet: state.checkpoint_packet,
3184
3193
  latest_event: latestEvent
3185
3194
  });
3186
3195
  }
@@ -3208,6 +3217,178 @@ function applyPrLifecycleState(state, input, at = timestamp()) {
3208
3217
  return state;
3209
3218
  }
3210
3219
 
3220
+ // src/checkpoint.ts
3221
+ var import_node_crypto = __toESM(require("crypto"), 1);
3222
+ var RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION = "riddle-proof.checkpoint.v1";
3223
+ var RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION = "riddle-proof.checkpoint_response.v1";
3224
+ function timestamp2() {
3225
+ return (/* @__PURE__ */ new Date()).toISOString();
3226
+ }
3227
+ function jsonCloneRecord(value) {
3228
+ const record = recordValue(value);
3229
+ if (!record) return void 0;
3230
+ try {
3231
+ return JSON.parse(JSON.stringify(record));
3232
+ } catch {
3233
+ return { ...record };
3234
+ }
3235
+ }
3236
+ function compactText(value, limit = 1600) {
3237
+ const text = nonEmptyString(value);
3238
+ if (!text) return void 0;
3239
+ return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
3240
+ }
3241
+ function responseSchemaForAuthorPacket() {
3242
+ return {
3243
+ type: "object",
3244
+ required: ["version", "run_id", "checkpoint", "decision", "summary", "payload", "created_at"],
3245
+ additionalProperties: false,
3246
+ properties: {
3247
+ version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
3248
+ run_id: { type: "string" },
3249
+ checkpoint: { type: "string" },
3250
+ resume_token: { type: "string" },
3251
+ decision: {
3252
+ type: "string",
3253
+ enum: ["author_packet", "needs_recon", "blocked", "human_review"]
3254
+ },
3255
+ summary: { type: "string" },
3256
+ payload: {
3257
+ type: "object",
3258
+ description: "For decision=author_packet, provide the proof packet itself or {author_packet:{...}} with proof_plan and capture_script."
3259
+ },
3260
+ reasons: { type: "array", items: { type: "string" } },
3261
+ continue_with_stage: { type: "string", enum: ["author", "recon"] },
3262
+ source: {
3263
+ type: "object",
3264
+ properties: {
3265
+ kind: { type: "string" },
3266
+ session_id: { type: "string" },
3267
+ user_id: { type: "string" }
3268
+ }
3269
+ },
3270
+ created_at: { type: "string" }
3271
+ }
3272
+ };
3273
+ }
3274
+ function resumeTokenFor(input) {
3275
+ const hash = import_node_crypto.default.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
3276
+ return `rpchk_${hash}`;
3277
+ }
3278
+ function artifactsFromState(state) {
3279
+ const artifacts = [];
3280
+ for (const role of ["before", "prod", "after"]) {
3281
+ const url = nonEmptyString(state?.[`${role}_cdn`]);
3282
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
3283
+ }
3284
+ const authorRequest = recordValue(state?.author_request);
3285
+ const latestAttempt = recordValue(authorRequest?.latest_attempt);
3286
+ const observations = recordValue(latestAttempt?.observations);
3287
+ for (const [label, observation] of Object.entries(observations || {})) {
3288
+ const record = recordValue(observation);
3289
+ const url = nonEmptyString(record?.url);
3290
+ if (url && !artifacts.some((artifact) => artifact.url === url)) {
3291
+ artifacts.push({
3292
+ role: label === "before" || label === "prod" ? label : "json",
3293
+ url,
3294
+ name: `${label}-observation`,
3295
+ summary: compactText(record?.reason, 240)
3296
+ });
3297
+ }
3298
+ }
3299
+ return artifacts.slice(0, 16);
3300
+ }
3301
+ function buildAuthorCheckpointPacket(input) {
3302
+ const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
3303
+ const stage = "author";
3304
+ const runId = input.runState.run_id || "unknown";
3305
+ const fullState = input.fullRiddleState || {};
3306
+ const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
3307
+ const authorRequest = recordValue(fullState.author_request) || recordValue(fullState.proof_plan_request) || recordValue(decisionDetails?.authorRequest) || {};
3308
+ const fallbackDefaults = recordValue(authorRequest.fallback_defaults) || {};
3309
+ const reconResults = recordValue(fullState.recon_results);
3310
+ const checkpointContract = recordValue(input.engineResult.checkpointContract);
3311
+ const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.author_summary) || "Author checkpoint needs a supervising proof packet.";
3312
+ return {
3313
+ version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
3314
+ run_id: runId,
3315
+ state_path: input.runState.state_path,
3316
+ stage,
3317
+ checkpoint,
3318
+ kind: "author_proof",
3319
+ summary,
3320
+ question: "Author the proof packet for this Riddle Proof run. Return a CheckpointResponse with decision=author_packet and payload containing proof_plan and capture_script.",
3321
+ change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
3322
+ context: input.request.context,
3323
+ artifacts: artifactsFromState(fullState),
3324
+ state_excerpt: compactRecord({
3325
+ repo: input.request.repo || fullState.repo,
3326
+ branch: input.request.branch || fullState.branch,
3327
+ verification_mode: input.request.verification_mode || fullState.verification_mode,
3328
+ reference: input.request.reference || fullState.reference,
3329
+ server_path: fullState.server_path,
3330
+ wait_for_selector: fullState.wait_for_selector,
3331
+ author_summary: fullState.author_summary,
3332
+ author_request: jsonCloneRecord(authorRequest),
3333
+ recon_baseline_understanding: jsonCloneRecord(fullState.recon_baseline_understanding),
3334
+ fallback_defaults: jsonCloneRecord(fallbackDefaults)
3335
+ }),
3336
+ evidence_excerpt: compactRecord({
3337
+ recon_results: jsonCloneRecord(reconResults),
3338
+ checkpoint_contract: jsonCloneRecord(checkpointContract)
3339
+ }),
3340
+ allowed_decisions: ["author_packet", "needs_recon", "blocked", "human_review"],
3341
+ response_schema: responseSchemaForAuthorPacket(),
3342
+ routing_hint: {
3343
+ suggested_role: "proof_author",
3344
+ visibility: input.visibility || "quiet",
3345
+ urgency: "normal",
3346
+ can_auto_answer: input.visibility !== "manual"
3347
+ },
3348
+ resume_token: resumeTokenFor({
3349
+ runId,
3350
+ statePath: input.engineResult.state_path || input.request.engine_state_path || null,
3351
+ checkpoint,
3352
+ stage
3353
+ }),
3354
+ created_at: input.created_at || timestamp2()
3355
+ };
3356
+ }
3357
+ function normalizeCheckpointResponse(value) {
3358
+ const record = recordValue(value);
3359
+ if (!record) return null;
3360
+ const version = nonEmptyString(record.version);
3361
+ const runId = nonEmptyString(record.run_id);
3362
+ const checkpoint = nonEmptyString(record.checkpoint);
3363
+ const decision = nonEmptyString(record.decision);
3364
+ const summary = nonEmptyString(record.summary);
3365
+ if (version !== RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION || !runId || !checkpoint || !decision || !summary) {
3366
+ return null;
3367
+ }
3368
+ return compactRecord({
3369
+ version: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
3370
+ run_id: runId,
3371
+ checkpoint,
3372
+ resume_token: nonEmptyString(record.resume_token),
3373
+ decision,
3374
+ summary,
3375
+ payload: jsonCloneRecord(record.payload),
3376
+ reasons: Array.isArray(record.reasons) ? record.reasons.filter((item) => typeof item === "string") : void 0,
3377
+ continue_with_stage: nonEmptyString(record.continue_with_stage),
3378
+ source: jsonCloneRecord(record.source),
3379
+ created_at: nonEmptyString(record.created_at) || timestamp2()
3380
+ });
3381
+ }
3382
+ function authorPacketPayloadFromCheckpointResponse(response) {
3383
+ if (response.decision !== "author_packet") return null;
3384
+ const payload = recordValue(response.payload);
3385
+ if (!payload) return null;
3386
+ const nested = recordValue(payload.author_packet);
3387
+ const candidate = nested || payload;
3388
+ if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
3389
+ return candidate;
3390
+ }
3391
+
3211
3392
  // src/runner.ts
3212
3393
  function errorDetails(error) {
3213
3394
  if (error instanceof Error) {
@@ -3694,7 +3875,7 @@ async function runRiddleProof(input) {
3694
3875
  var import_node_child_process2 = require("child_process");
3695
3876
  var import_node_fs3 = require("fs");
3696
3877
  var import_node_path3 = __toESM(require("path"), 1);
3697
- var import_node_crypto2 = __toESM(require("crypto"), 1);
3878
+ var import_node_crypto3 = __toESM(require("crypto"), 1);
3698
3879
  init_proof_run_core();
3699
3880
  var DEFAULT_MAX_ITERATIONS = 12;
3700
3881
  var DEFAULT_STAGE_ITERATION_LIMITS = {
@@ -3707,12 +3888,12 @@ var DEFAULT_STAGE_ITERATION_LIMITS = {
3707
3888
  ship: 2,
3708
3889
  notify: 2
3709
3890
  };
3710
- function timestamp2() {
3891
+ function timestamp3() {
3711
3892
  return (/* @__PURE__ */ new Date()).toISOString();
3712
3893
  }
3713
3894
  function createHarnessStatePath(stateDir) {
3714
- const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
3715
- return import_node_path3.default.join(stateDir, `riddle-proof-run-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
3895
+ const stamp = timestamp3().replace(/\D/g, "").slice(0, 14) || "unknown";
3896
+ return import_node_path3.default.join(stateDir, `riddle-proof-run-${stamp}-${import_node_crypto3.default.randomUUID().slice(0, 8)}.json`);
3716
3897
  }
3717
3898
  function createEngineStatePath(state, config) {
3718
3899
  const existing = nonEmptyString(state.request.engine_state_path);
@@ -3727,8 +3908,8 @@ function createEngineStatePath(state, config) {
3727
3908
  return import_node_path3.default.join(dir, `${base}.engine-state.json`);
3728
3909
  }
3729
3910
  const stateDir = config?.stateDir || "/tmp";
3730
- const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
3731
- return import_node_path3.default.join(stateDir, `riddle-proof-state-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
3911
+ const stamp = timestamp3().replace(/\D/g, "").slice(0, 14) || "unknown";
3912
+ return import_node_path3.default.join(stateDir, `riddle-proof-state-${stamp}-${import_node_crypto3.default.randomUUID().slice(0, 8)}.json`);
3732
3913
  }
3733
3914
  function ensureParent(filePath) {
3734
3915
  (0, import_node_fs3.mkdirSync)(import_node_path3.default.dirname(filePath), { recursive: true });
@@ -4069,6 +4250,150 @@ function blockerResult(state, result, blocker) {
4069
4250
  }
4070
4251
  });
4071
4252
  }
4253
+ function checkpointAwaitingResult(state, result, visibility) {
4254
+ const packet = buildAuthorCheckpointPacket({
4255
+ request: state.request,
4256
+ runState: state,
4257
+ engineResult: result,
4258
+ fullRiddleState: fullRiddleState(result, state),
4259
+ visibility
4260
+ });
4261
+ const at = timestamp3();
4262
+ state.checkpoint_packet = packet;
4263
+ state.checkpoint_history = [
4264
+ ...state.checkpoint_history || [],
4265
+ { ts: at, packet }
4266
+ ].slice(-25);
4267
+ appendRunEvent(state, {
4268
+ ts: at,
4269
+ kind: "checkpoint.packet.created",
4270
+ checkpoint: packet.checkpoint,
4271
+ stage: packet.stage,
4272
+ summary: packet.summary,
4273
+ details: compactRecord({
4274
+ kind: packet.kind,
4275
+ routing_hint: packet.routing_hint,
4276
+ resume_token: packet.resume_token
4277
+ })
4278
+ });
4279
+ setRunStatus(state, "awaiting_checkpoint", at);
4280
+ persist(state);
4281
+ return createRunResult({
4282
+ state,
4283
+ status: "awaiting_checkpoint",
4284
+ last_summary: packet.summary,
4285
+ raw: {
4286
+ engine_state_path: result.state_path || state.request.engine_state_path || null,
4287
+ last_result: result,
4288
+ checkpoint_packet: packet
4289
+ }
4290
+ });
4291
+ }
4292
+ function appendCheckpointResponse(state, response, input = {}) {
4293
+ const at = timestamp3();
4294
+ state.checkpoint_history = [
4295
+ ...state.checkpoint_history || [],
4296
+ { ts: at, response }
4297
+ ].slice(-25);
4298
+ if (input.clear_packet !== false) {
4299
+ state.checkpoint_packet = void 0;
4300
+ }
4301
+ appendRunEvent(state, {
4302
+ ts: at,
4303
+ kind: "checkpoint.response.accepted",
4304
+ checkpoint: response.checkpoint,
4305
+ stage: state.current_stage || "author",
4306
+ summary: input.summary || response.summary,
4307
+ details: compactRecord({
4308
+ decision: response.decision,
4309
+ resume_token: response.resume_token,
4310
+ source: response.source
4311
+ })
4312
+ });
4313
+ setRunStatus(state, "running", at);
4314
+ persist(state);
4315
+ }
4316
+ function checkpointResponseContinuation(state, value) {
4317
+ if (!value) return {};
4318
+ const packet = state.checkpoint_packet;
4319
+ const response = normalizeCheckpointResponse(value);
4320
+ if (!response) {
4321
+ return {
4322
+ blocker: {
4323
+ code: "checkpoint_response_invalid",
4324
+ checkpoint: packet?.checkpoint || state.last_checkpoint || null,
4325
+ message: "Checkpoint response was not a valid riddle-proof.checkpoint_response.v1 object.",
4326
+ details: { checkpoint_packet: packet || null }
4327
+ }
4328
+ };
4329
+ }
4330
+ if (!packet) {
4331
+ return {
4332
+ blocker: {
4333
+ code: "checkpoint_response_without_packet",
4334
+ checkpoint: response.checkpoint,
4335
+ message: "A checkpoint response was supplied, but the run state has no pending checkpoint packet.",
4336
+ details: { response }
4337
+ }
4338
+ };
4339
+ }
4340
+ if (response.run_id !== packet.run_id || response.checkpoint !== packet.checkpoint) {
4341
+ return {
4342
+ blocker: {
4343
+ code: "checkpoint_response_mismatch",
4344
+ checkpoint: packet.checkpoint,
4345
+ message: "Checkpoint response does not match the pending checkpoint packet.",
4346
+ details: {
4347
+ expected: { run_id: packet.run_id, checkpoint: packet.checkpoint },
4348
+ actual: { run_id: response.run_id, checkpoint: response.checkpoint }
4349
+ }
4350
+ }
4351
+ };
4352
+ }
4353
+ if (packet.resume_token && response.resume_token !== packet.resume_token) {
4354
+ return {
4355
+ blocker: {
4356
+ code: "checkpoint_response_resume_token_mismatch",
4357
+ checkpoint: packet.checkpoint,
4358
+ 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 }
4360
+ }
4361
+ };
4362
+ }
4363
+ const base = {
4364
+ action: "run",
4365
+ state_path: state.request.engine_state_path || packet.state_path || "",
4366
+ continue_from_checkpoint: true
4367
+ };
4368
+ if (response.decision === "author_packet") {
4369
+ const payload = authorPacketPayloadFromCheckpointResponse(response);
4370
+ if (!payload) {
4371
+ return {
4372
+ blocker: {
4373
+ code: "checkpoint_author_packet_missing",
4374
+ checkpoint: packet.checkpoint,
4375
+ message: "Checkpoint response decision=author_packet did not include a proof_plan and capture_script payload.",
4376
+ details: { response }
4377
+ }
4378
+ };
4379
+ }
4380
+ appendCheckpointResponse(state, response);
4381
+ return { next: { ...base, author_packet_json: jsonParam(payload) } };
4382
+ }
4383
+ if (response.decision === "needs_recon") {
4384
+ appendCheckpointResponse(state, response);
4385
+ return { next: { ...base, advance_stage: "recon" } };
4386
+ }
4387
+ appendCheckpointResponse(state, response, { clear_packet: false });
4388
+ return {
4389
+ blocker: {
4390
+ code: `checkpoint_response_${response.decision}`,
4391
+ checkpoint: packet.checkpoint,
4392
+ message: response.summary || `Checkpoint response stopped the run with decision=${response.decision}.`,
4393
+ details: { response }
4394
+ }
4395
+ };
4396
+ }
4072
4397
  function disabledAdapterPayload(action, context) {
4073
4398
  return {
4074
4399
  ok: false,
@@ -4317,6 +4642,9 @@ async function routeCheckpoint(request, state, result, agent, input) {
4317
4642
  const continueStage = checkpointContinueStage2(result);
4318
4643
  const checkpointContinuesToAuthor = continueStage === "author";
4319
4644
  if (checkpoint === "author_supervisor_judgment" || checkpoint === "verify_capture_retry" || checkpoint === "verify_agent_retry" && checkpointContinuesToAuthor) {
4645
+ if (input.checkpoint_mode === "yield") {
4646
+ return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
4647
+ }
4320
4648
  const packet = await agent.authorProofPacket(context);
4321
4649
  const blocker = requirePayload("author_packet", packet, state, result);
4322
4650
  if (blocker) return { blocker };
@@ -4418,6 +4746,10 @@ async function runRiddleProofEngineHarness(input) {
4418
4746
  const state = loadRunState(input);
4419
4747
  state.request = normalizeRunParams({ ...state.request, ...input.request });
4420
4748
  state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
4749
+ const checkpointContinuation = checkpointResponseContinuation(state, input.checkpoint_response);
4750
+ if (checkpointContinuation.blocker) {
4751
+ return blockerResult(state, null, checkpointContinuation.blocker);
4752
+ }
4421
4753
  const request = state.request;
4422
4754
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
4423
4755
  const maxIterations = Math.max(
@@ -4439,6 +4771,8 @@ async function runRiddleProofEngineHarness(input) {
4439
4771
  engine_state_path: request.engine_state_path || null,
4440
4772
  max_iterations: maxIterations,
4441
4773
  ship_mode: effectiveShipMode(request, input.config),
4774
+ checkpoint_mode: input.checkpoint_mode || "auto",
4775
+ checkpoint_visibility: input.checkpoint_visibility || null,
4442
4776
  leave_draft: request.leave_draft || false
4443
4777
  }
4444
4778
  });
@@ -4453,7 +4787,7 @@ async function runRiddleProofEngineHarness(input) {
4453
4787
  message
4454
4788
  });
4455
4789
  }
4456
- let nextParams = input.resume_params || initialRunParams(request, input, state);
4790
+ let nextParams = input.resume_params || checkpointContinuation.next || initialRunParams(request, input, state);
4457
4791
  let lastResult = null;
4458
4792
  const stageIterations = {};
4459
4793
  for (let index = 0; index < maxIterations; index += 1) {
@@ -4474,7 +4808,7 @@ async function runRiddleProofEngineHarness(input) {
4474
4808
  branch: state.branch || null
4475
4809
  }
4476
4810
  });
4477
- const engineCallStartedAt = timestamp2();
4811
+ const engineCallStartedAt = timestamp3();
4478
4812
  const engineCallStartedMs = Date.now();
4479
4813
  recordEvent(state, {
4480
4814
  kind: "engine.call",
@@ -4499,7 +4833,7 @@ async function runRiddleProofEngineHarness(input) {
4499
4833
  details: {
4500
4834
  duration_ms: Date.now() - engineCallStartedMs,
4501
4835
  started_at: engineCallStartedAt,
4502
- finished_at: timestamp2()
4836
+ finished_at: timestamp3()
4503
4837
  }
4504
4838
  });
4505
4839
  return blockerResult(state, lastResult, {
@@ -4537,7 +4871,7 @@ async function runRiddleProofEngineHarness(input) {
4537
4871
  checkpoint: result.checkpoint || null,
4538
4872
  duration_ms: engineCallDurationMs,
4539
4873
  started_at: engineCallStartedAt,
4540
- finished_at: timestamp2()
4874
+ finished_at: timestamp3()
4541
4875
  }
4542
4876
  });
4543
4877
  const stageLimit = DEFAULT_STAGE_ITERATION_LIMITS[resultStage];
@@ -4721,7 +5055,7 @@ function appendCaptureDiagnostic(state, input, historyLimit = DEFAULT_DIAGNOSTIC
4721
5055
  }
4722
5056
 
4723
5057
  // src/proof-session.ts
4724
- var import_node_crypto3 = require("crypto");
5058
+ var import_node_crypto4 = require("crypto");
4725
5059
  var RIDDLE_PROOF_VISUAL_SESSION_VERSION = "riddle-proof.visual-session.v1";
4726
5060
  var RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION = "riddle-proof.visual-session.fingerprint.v1";
4727
5061
  function trim(value) {
@@ -4731,7 +5065,7 @@ function trim(value) {
4731
5065
  function hashString(value) {
4732
5066
  const text = trim(value);
4733
5067
  if (!text) return void 0;
4734
- return (0, import_node_crypto3.createHash)("sha256").update(text).digest("hex");
5068
+ return (0, import_node_crypto4.createHash)("sha256").update(text).digest("hex");
4735
5069
  }
4736
5070
  function stableJson(value) {
4737
5071
  if (value === void 0) return "null";
@@ -4764,14 +5098,14 @@ function visualSessionFingerprintBasis(input) {
4764
5098
  }
4765
5099
  function visualSessionFingerprint(input) {
4766
5100
  const basis = input.version === RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION ? input : visualSessionFingerprintBasis(input);
4767
- return (0, import_node_crypto3.createHash)("sha256").update(stableJson(basis)).digest("hex");
5101
+ return (0, import_node_crypto4.createHash)("sha256").update(stableJson(basis)).digest("hex");
4768
5102
  }
4769
5103
  function buildVisualProofSession(input) {
4770
5104
  const basis = visualSessionFingerprintBasis(input);
4771
5105
  const fingerprint = visualSessionFingerprint(basis);
4772
5106
  const session = {
4773
5107
  version: RIDDLE_PROOF_VISUAL_SESSION_VERSION,
4774
- session_id: `rps_${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:.TZ]/g, "").slice(0, 14)}_${(0, import_node_crypto3.randomUUID)().slice(0, 8)}`,
5108
+ session_id: `rps_${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:.TZ]/g, "").slice(0, 14)}_${(0, import_node_crypto4.randomUUID)().slice(0, 8)}`,
4775
5109
  run_id: trim(input.run_id),
4776
5110
  parent_session_id: input.parent?.session_id || null,
4777
5111
  parent_fingerprint: input.parent?.fingerprint || null,
@@ -5191,6 +5525,8 @@ function parseJson(value) {
5191
5525
  DEFAULT_DIAGNOSTIC_HISTORY_LIMIT,
5192
5526
  DEFAULT_DIAGNOSTIC_STRING_LIMIT,
5193
5527
  RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION,
5528
+ RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
5529
+ RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
5194
5530
  RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION,
5195
5531
  RIDDLE_PROOF_PLAYABILITY_VERSION,
5196
5532
  RIDDLE_PROOF_RUN_STATE_VERSION,
@@ -5202,6 +5538,8 @@ function parseJson(value) {
5202
5538
  applyPrLifecycleState,
5203
5539
  applyTerminalMetadata,
5204
5540
  assessPlayabilityEvidence,
5541
+ authorPacketPayloadFromCheckpointResponse,
5542
+ buildAuthorCheckpointPacket,
5205
5543
  buildVisualProofSession,
5206
5544
  compactRecord,
5207
5545
  compareVisualProofSessionFingerprint,
@@ -5215,6 +5553,7 @@ function parseJson(value) {
5215
5553
  isSuccessfulStatus,
5216
5554
  isTerminalStatus,
5217
5555
  nonEmptyString,
5556
+ normalizeCheckpointResponse,
5218
5557
  normalizeIntegrationContext,
5219
5558
  normalizePrLifecycleState,
5220
5559
  normalizeRunParams,
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, 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, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, 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
5
  export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.cjs';
5
- export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.cjs';
6
+ export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofCheckpointMode, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.cjs';
6
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';
7
8
  export { BuildVisualProofSessionInput, RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION, RIDDLE_PROOF_VISUAL_SESSION_VERSION, VisualProofSessionMismatch, buildVisualProofSession, compareVisualProofSessionFingerprint, parseVisualProofSession, visualSessionFingerprint, visualSessionFingerprintBasis } from './proof-session.cjs';
8
9
  export { AssessPlayabilityOptions, RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION, RIDDLE_PROOF_PLAYABILITY_VERSION, RiddleProofPlayabilityAssessment, RiddleProofPlayabilityEvidence, assessPlayabilityEvidence, extractPlayabilityEvidence, isRiddleProofPlayabilityMode } from './playability.cjs';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, PreflightAdapter, PreflightAdapterInput, PreflightAdapterResult, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofArtifactRole, RiddleProofAssessment, RiddleProofBlocker, 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, RiddleProofCheckpointVisibility, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofPrLifecycleState, RiddleProofPrLifecycleStatus, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, 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
5
  export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.js';
5
- export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.js';
6
+ export { RiddleProofAgentAdapter, RiddleProofAgentPayload, RiddleProofCheckpointMode, RiddleProofEngine, RiddleProofEngineHarnessConfig, RiddleProofEngineHarnessContext, RiddleProofEngineResult, RiddleProofShipMode, RiddleProofWorkflowParams, RunRiddleProofEngineHarnessInput, createDisabledRiddleProofAgentAdapter, readRiddleProofRunStatus, runRiddleProofEngineHarness } from './engine-harness.js';
6
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';
7
8
  export { BuildVisualProofSessionInput, RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION, RIDDLE_PROOF_VISUAL_SESSION_VERSION, VisualProofSessionMismatch, buildVisualProofSession, compareVisualProofSessionFingerprint, parseVisualProofSession, visualSessionFingerprint, visualSessionFingerprintBasis } from './proof-session.js';
8
9
  export { AssessPlayabilityOptions, RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION, RIDDLE_PROOF_PLAYABILITY_VERSION, RiddleProofPlayabilityAssessment, RiddleProofPlayabilityEvidence, assessPlayabilityEvidence, extractPlayabilityEvidence, isRiddleProofPlayabilityMode } from './playability.js';