@riddledc/riddle-proof 0.5.38 → 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.
- package/dist/checkpoint.cjs +318 -0
- package/dist/checkpoint.d.cts +26 -0
- package/dist/checkpoint.d.ts +26 -0
- package/dist/checkpoint.js +23 -0
- package/dist/chunk-5LVCGDSD.js +269 -0
- package/dist/{chunk-OASB3CYU.js → chunk-7S7O3NKF.js} +10 -1
- package/dist/{chunk-GN7HSZ6G.js → chunk-COFOLRUW.js} +193 -4
- package/dist/{chunk-MQ2BHHLX.js → chunk-MRSYJMF4.js} +2 -2
- package/dist/{chunk-J2MERROF.js → chunk-W7VTDN4T.js} +4 -0
- package/dist/engine-harness.cjs +459 -14
- package/dist/engine-harness.d.cts +6 -2
- package/dist/engine-harness.d.ts +6 -2
- package/dist/engine-harness.js +4 -3
- package/dist/index.cjs +481 -18
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +33 -13
- package/dist/openclaw.js +2 -2
- package/dist/proof-run-engine.d.cts +3 -3
- package/dist/proof-run-engine.d.ts +3 -3
- package/dist/result.cjs +4 -0
- package/dist/result.js +1 -1
- package/dist/runner.cjs +9 -0
- package/dist/runner.js +3 -3
- package/dist/state.cjs +9 -0
- package/dist/state.d.cts +10 -1
- package/dist/state.d.ts +10 -1
- package/dist/state.js +2 -2
- package/dist/types.d.cts +117 -2
- package/dist/types.d.ts +117 -2
- package/package.json +7 -2
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
isTerminalStatus,
|
|
4
4
|
nonEmptyString,
|
|
5
5
|
recordValue
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-W7VTDN4T.js";
|
|
7
7
|
|
|
8
8
|
// src/state.ts
|
|
9
9
|
var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
|
|
@@ -127,6 +127,11 @@ function createRunState(input) {
|
|
|
127
127
|
request: normalizeRunParams(input.request),
|
|
128
128
|
iterations: input.iterations ?? 0,
|
|
129
129
|
last_checkpoint: input.last_checkpoint ?? null,
|
|
130
|
+
checkpoint_packet: input.checkpoint_packet,
|
|
131
|
+
checkpoint_summary: input.checkpoint_summary,
|
|
132
|
+
state_paths: input.state_paths,
|
|
133
|
+
proof_contract: input.proof_contract,
|
|
134
|
+
checkpoint_history: input.checkpoint_history,
|
|
130
135
|
events: input.events ? [...input.events] : []
|
|
131
136
|
});
|
|
132
137
|
}
|
|
@@ -200,6 +205,10 @@ function createRunStatusSnapshot(state, at = timestamp()) {
|
|
|
200
205
|
elapsed_ms: elapsedMs(state.created_at, at),
|
|
201
206
|
stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
|
|
202
207
|
blocker: state.blocker,
|
|
208
|
+
checkpoint_packet: state.checkpoint_packet,
|
|
209
|
+
checkpoint_summary: state.checkpoint_summary,
|
|
210
|
+
state_paths: state.state_paths,
|
|
211
|
+
proof_contract: state.proof_contract,
|
|
203
212
|
latest_event: latestEvent
|
|
204
213
|
});
|
|
205
214
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authorPacketPayloadFromCheckpointResponse,
|
|
3
|
+
buildAuthorCheckpointPacket,
|
|
4
|
+
checkpointSummaryFromState,
|
|
5
|
+
isDuplicateCheckpointResponse,
|
|
6
|
+
normalizeCheckpointResponse,
|
|
7
|
+
proofContractFromAuthorCheckpointResponse,
|
|
8
|
+
statePathsForRunState
|
|
9
|
+
} from "./chunk-5LVCGDSD.js";
|
|
1
10
|
import {
|
|
2
11
|
appendRunEvent,
|
|
3
12
|
appendStageHeartbeat,
|
|
@@ -5,7 +14,7 @@ import {
|
|
|
5
14
|
createRunStatusSnapshot,
|
|
6
15
|
normalizeRunParams,
|
|
7
16
|
setRunStatus
|
|
8
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7S7O3NKF.js";
|
|
9
18
|
import {
|
|
10
19
|
applyTerminalMetadata,
|
|
11
20
|
compactRecord,
|
|
@@ -13,7 +22,7 @@ import {
|
|
|
13
22
|
nonEmptyString,
|
|
14
23
|
normalizeTerminalMetadata,
|
|
15
24
|
recordValue
|
|
16
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-W7VTDN4T.js";
|
|
17
26
|
import {
|
|
18
27
|
visualDeltaShipGateReason
|
|
19
28
|
} from "./chunk-4YCWZVBN.js";
|
|
@@ -103,6 +112,8 @@ function shouldPreserveFinalizedRunState(filePath, incoming) {
|
|
|
103
112
|
return !(existing.status === "ready_to_ship" && incoming.status === "shipped");
|
|
104
113
|
}
|
|
105
114
|
function persist(state) {
|
|
115
|
+
state.state_paths = statePathsForRunState(state);
|
|
116
|
+
state.checkpoint_summary = checkpointSummaryFromState(state);
|
|
106
117
|
if (!state.state_path) return;
|
|
107
118
|
if (shouldPreserveFinalizedRunState(state.state_path, state)) return;
|
|
108
119
|
writeJson(state.state_path, state);
|
|
@@ -359,6 +370,10 @@ function engineFailureBlocker(result, checkpoint) {
|
|
|
359
370
|
};
|
|
360
371
|
}
|
|
361
372
|
function terminalResult(state, status, result, summary, raw = {}) {
|
|
373
|
+
if (result) {
|
|
374
|
+
const terminalStage = stageFromCheckpoint(result);
|
|
375
|
+
if (terminalStage !== "setup") state.current_stage = terminalStage;
|
|
376
|
+
}
|
|
362
377
|
setRunStatus(state, status);
|
|
363
378
|
if (isProtectedFinalStatus(status)) state.finalized = true;
|
|
364
379
|
const metadata = normalizeTerminalMetadata({
|
|
@@ -381,10 +396,12 @@ function terminalResult(state, status, result, summary, raw = {}) {
|
|
|
381
396
|
}
|
|
382
397
|
function blockerResult(state, result, blocker) {
|
|
383
398
|
state.blocker = blocker;
|
|
399
|
+
const blockerStage = nonEmptyString(recordValue(blocker.details)?.stage);
|
|
400
|
+
const stage = blockerStage || stageFromCheckpoint(result || { checkpoint: blocker.checkpoint || void 0 });
|
|
384
401
|
recordEvent(state, {
|
|
385
402
|
kind: "run.blocked",
|
|
386
403
|
checkpoint: blocker.checkpoint || result?.checkpoint || null,
|
|
387
|
-
stage
|
|
404
|
+
stage,
|
|
388
405
|
summary: blocker.message,
|
|
389
406
|
details: {
|
|
390
407
|
code: blocker.code,
|
|
@@ -403,6 +420,169 @@ function blockerResult(state, result, blocker) {
|
|
|
403
420
|
}
|
|
404
421
|
});
|
|
405
422
|
}
|
|
423
|
+
function checkpointAwaitingResult(state, result, visibility) {
|
|
424
|
+
const packet = buildAuthorCheckpointPacket({
|
|
425
|
+
request: state.request,
|
|
426
|
+
runState: state,
|
|
427
|
+
engineResult: result,
|
|
428
|
+
fullRiddleState: fullRiddleState(result, state),
|
|
429
|
+
visibility
|
|
430
|
+
});
|
|
431
|
+
const at = timestamp();
|
|
432
|
+
state.checkpoint_packet = packet;
|
|
433
|
+
state.checkpoint_history = [
|
|
434
|
+
...state.checkpoint_history || [],
|
|
435
|
+
{ ts: at, packet }
|
|
436
|
+
].slice(-25);
|
|
437
|
+
appendRunEvent(state, {
|
|
438
|
+
ts: at,
|
|
439
|
+
kind: "checkpoint.packet.created",
|
|
440
|
+
checkpoint: packet.checkpoint,
|
|
441
|
+
stage: packet.stage,
|
|
442
|
+
summary: packet.summary,
|
|
443
|
+
details: compactRecord({
|
|
444
|
+
kind: packet.kind,
|
|
445
|
+
routing_hint: packet.routing_hint,
|
|
446
|
+
resume_token: packet.resume_token
|
|
447
|
+
})
|
|
448
|
+
});
|
|
449
|
+
setRunStatus(state, "awaiting_checkpoint", at);
|
|
450
|
+
persist(state);
|
|
451
|
+
return createRunResult({
|
|
452
|
+
state,
|
|
453
|
+
status: "awaiting_checkpoint",
|
|
454
|
+
last_summary: packet.summary,
|
|
455
|
+
raw: {
|
|
456
|
+
engine_state_path: result.state_path || state.request.engine_state_path || null,
|
|
457
|
+
last_result: result,
|
|
458
|
+
checkpoint_packet: packet
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
function appendCheckpointResponse(state, response, input = {}) {
|
|
463
|
+
const at = timestamp();
|
|
464
|
+
state.checkpoint_history = [
|
|
465
|
+
...state.checkpoint_history || [],
|
|
466
|
+
{ ts: at, response }
|
|
467
|
+
].slice(-25);
|
|
468
|
+
if (input.clear_packet !== false) {
|
|
469
|
+
state.checkpoint_packet = void 0;
|
|
470
|
+
}
|
|
471
|
+
appendRunEvent(state, {
|
|
472
|
+
ts: at,
|
|
473
|
+
kind: "checkpoint.response.accepted",
|
|
474
|
+
checkpoint: response.checkpoint,
|
|
475
|
+
stage: state.current_stage || "author",
|
|
476
|
+
summary: input.summary || response.summary,
|
|
477
|
+
details: compactRecord({
|
|
478
|
+
decision: response.decision,
|
|
479
|
+
resume_token: response.resume_token,
|
|
480
|
+
source: response.source
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
setRunStatus(state, "running", at);
|
|
484
|
+
persist(state);
|
|
485
|
+
}
|
|
486
|
+
function checkpointResponseContinuation(state, value) {
|
|
487
|
+
if (!value) return {};
|
|
488
|
+
const packet = state.checkpoint_packet;
|
|
489
|
+
const response = normalizeCheckpointResponse(value);
|
|
490
|
+
if (!response) {
|
|
491
|
+
return {
|
|
492
|
+
blocker: {
|
|
493
|
+
code: "checkpoint_response_invalid",
|
|
494
|
+
checkpoint: packet?.checkpoint || state.last_checkpoint || null,
|
|
495
|
+
message: "Checkpoint response was not a valid riddle-proof.checkpoint_response.v1 object.",
|
|
496
|
+
details: { checkpoint_packet: packet || null, checkpoint_summary: checkpointSummaryFromState(state) }
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if (!packet) {
|
|
501
|
+
if (isDuplicateCheckpointResponse(state, response)) {
|
|
502
|
+
return {
|
|
503
|
+
blocker: {
|
|
504
|
+
code: "checkpoint_response_duplicate",
|
|
505
|
+
checkpoint: response.checkpoint,
|
|
506
|
+
message: "Checkpoint response was already accepted and there is no pending checkpoint packet to resume.",
|
|
507
|
+
details: {
|
|
508
|
+
response,
|
|
509
|
+
checkpoint_summary: checkpointSummaryFromState(state)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
return {
|
|
515
|
+
blocker: {
|
|
516
|
+
code: "checkpoint_response_without_packet",
|
|
517
|
+
checkpoint: response.checkpoint,
|
|
518
|
+
message: "A checkpoint response was supplied, but the run state has no pending checkpoint packet.",
|
|
519
|
+
details: { response, checkpoint_summary: checkpointSummaryFromState(state) }
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
if (response.run_id !== packet.run_id || response.checkpoint !== packet.checkpoint) {
|
|
524
|
+
return {
|
|
525
|
+
blocker: {
|
|
526
|
+
code: "checkpoint_response_mismatch",
|
|
527
|
+
checkpoint: packet.checkpoint,
|
|
528
|
+
message: "Checkpoint response does not match the pending checkpoint packet.",
|
|
529
|
+
details: {
|
|
530
|
+
stage: packet.stage,
|
|
531
|
+
expected: { run_id: packet.run_id, checkpoint: packet.checkpoint },
|
|
532
|
+
actual: { run_id: response.run_id, checkpoint: response.checkpoint }
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
if (packet.resume_token && response.resume_token !== packet.resume_token) {
|
|
538
|
+
return {
|
|
539
|
+
blocker: {
|
|
540
|
+
code: "checkpoint_response_resume_token_mismatch",
|
|
541
|
+
checkpoint: packet.checkpoint,
|
|
542
|
+
message: "Checkpoint response resume_token does not match the pending checkpoint packet.",
|
|
543
|
+
details: {
|
|
544
|
+
stage: packet.stage,
|
|
545
|
+
expected_resume_token: packet.resume_token,
|
|
546
|
+
actual_resume_token: response.resume_token || null
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const base = {
|
|
552
|
+
action: "run",
|
|
553
|
+
state_path: state.request.engine_state_path || packet.state_path || "",
|
|
554
|
+
continue_from_checkpoint: true
|
|
555
|
+
};
|
|
556
|
+
if (response.decision === "author_packet") {
|
|
557
|
+
const payload = authorPacketPayloadFromCheckpointResponse(response);
|
|
558
|
+
if (!payload) {
|
|
559
|
+
return {
|
|
560
|
+
blocker: {
|
|
561
|
+
code: "checkpoint_author_packet_missing",
|
|
562
|
+
checkpoint: packet.checkpoint,
|
|
563
|
+
message: "Checkpoint response decision=author_packet did not include a proof_plan and capture_script payload.",
|
|
564
|
+
details: { stage: packet.stage, response }
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
state.proof_contract = proofContractFromAuthorCheckpointResponse(response, packet, payload);
|
|
569
|
+
appendCheckpointResponse(state, response);
|
|
570
|
+
return { next: { ...base, author_packet_json: jsonParam(payload) } };
|
|
571
|
+
}
|
|
572
|
+
if (response.decision === "needs_recon") {
|
|
573
|
+
appendCheckpointResponse(state, response);
|
|
574
|
+
return { next: { ...base, advance_stage: "recon" } };
|
|
575
|
+
}
|
|
576
|
+
appendCheckpointResponse(state, response, { clear_packet: false });
|
|
577
|
+
return {
|
|
578
|
+
blocker: {
|
|
579
|
+
code: `checkpoint_response_${response.decision}`,
|
|
580
|
+
checkpoint: packet.checkpoint,
|
|
581
|
+
message: response.summary || `Checkpoint response stopped the run with decision=${response.decision}.`,
|
|
582
|
+
details: { stage: packet.stage, response }
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
}
|
|
406
586
|
function disabledAdapterPayload(action, context) {
|
|
407
587
|
return {
|
|
408
588
|
ok: false,
|
|
@@ -651,6 +831,9 @@ async function routeCheckpoint(request, state, result, agent, input) {
|
|
|
651
831
|
const continueStage = checkpointContinueStage(result);
|
|
652
832
|
const checkpointContinuesToAuthor = continueStage === "author";
|
|
653
833
|
if (checkpoint === "author_supervisor_judgment" || checkpoint === "verify_capture_retry" || checkpoint === "verify_agent_retry" && checkpointContinuesToAuthor) {
|
|
834
|
+
if (input.checkpoint_mode === "yield") {
|
|
835
|
+
return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
|
|
836
|
+
}
|
|
654
837
|
const packet = await agent.authorProofPacket(context);
|
|
655
838
|
const blocker = requirePayload("author_packet", packet, state, result);
|
|
656
839
|
if (blocker) return { blocker };
|
|
@@ -752,6 +935,10 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
752
935
|
const state = loadRunState(input);
|
|
753
936
|
state.request = normalizeRunParams({ ...state.request, ...input.request });
|
|
754
937
|
state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
|
|
938
|
+
const checkpointContinuation = checkpointResponseContinuation(state, input.checkpoint_response);
|
|
939
|
+
if (checkpointContinuation.blocker) {
|
|
940
|
+
return blockerResult(state, null, checkpointContinuation.blocker);
|
|
941
|
+
}
|
|
755
942
|
const request = state.request;
|
|
756
943
|
const agent = input.agent || createDisabledRiddleProofAgentAdapter();
|
|
757
944
|
const maxIterations = Math.max(
|
|
@@ -773,6 +960,8 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
773
960
|
engine_state_path: request.engine_state_path || null,
|
|
774
961
|
max_iterations: maxIterations,
|
|
775
962
|
ship_mode: effectiveShipMode(request, input.config),
|
|
963
|
+
checkpoint_mode: input.checkpoint_mode || "auto",
|
|
964
|
+
checkpoint_visibility: input.checkpoint_visibility || null,
|
|
776
965
|
leave_draft: request.leave_draft || false
|
|
777
966
|
}
|
|
778
967
|
});
|
|
@@ -787,7 +976,7 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
787
976
|
message
|
|
788
977
|
});
|
|
789
978
|
}
|
|
790
|
-
let nextParams = input.resume_params || initialRunParams(request, input, state);
|
|
979
|
+
let nextParams = input.resume_params || checkpointContinuation.next || initialRunParams(request, input, state);
|
|
791
980
|
let lastResult = null;
|
|
792
981
|
const stageIterations = {};
|
|
793
982
|
for (let index = 0; index < maxIterations; index += 1) {
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
appendStageHeartbeat,
|
|
4
4
|
createRunState,
|
|
5
5
|
setRunStatus
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7S7O3NKF.js";
|
|
7
7
|
import {
|
|
8
8
|
createRunResult
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-W7VTDN4T.js";
|
|
10
10
|
|
|
11
11
|
// src/runner.ts
|
|
12
12
|
function errorDetails(error) {
|
|
@@ -202,6 +202,10 @@ function createRunResult(input) {
|
|
|
202
202
|
merge_recommendation: state.merge_recommendation,
|
|
203
203
|
finalized: state.finalized,
|
|
204
204
|
blocker: state.blocker,
|
|
205
|
+
checkpoint_packet: state.checkpoint_packet,
|
|
206
|
+
checkpoint_summary: state.checkpoint_summary,
|
|
207
|
+
state_paths: state.state_paths,
|
|
208
|
+
proof_contract: state.proof_contract,
|
|
205
209
|
proof_session: state.proof_session,
|
|
206
210
|
evidence_bundle: input.evidence_bundle,
|
|
207
211
|
raw: input.raw
|