@riddledc/riddle-proof 0.5.2 → 0.5.3
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/{chunk-5GZZZ6JA.js → chunk-MLJJIKTP.js} +51 -2
- package/dist/engine-harness.cjs +179 -27
- package/dist/engine-harness.js +1 -1
- package/dist/index.cjs +179 -27
- package/dist/index.js +1 -1
- package/dist/proof-run-engine.cjs +127 -24
- package/dist/proof-run-engine.d.cts +3 -3
- package/dist/proof-run-engine.d.ts +3 -3
- package/dist/proof-run-engine.js +127 -24
- package/package.json +1 -1
- package/runtime/lib/preflight.py +13 -0
|
@@ -34,6 +34,22 @@ function createHarnessStatePath(stateDir) {
|
|
|
34
34
|
const stamp = timestamp().replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
35
35
|
return path.join(stateDir, `riddle-proof-run-${stamp}-${crypto.randomUUID().slice(0, 8)}.json`);
|
|
36
36
|
}
|
|
37
|
+
function createEngineStatePath(state, config) {
|
|
38
|
+
const existing = nonEmptyString(state.request.engine_state_path);
|
|
39
|
+
if (existing) return existing;
|
|
40
|
+
const harnessStatePath = nonEmptyString(state.state_path);
|
|
41
|
+
if (harnessStatePath) {
|
|
42
|
+
const dir = path.dirname(harnessStatePath);
|
|
43
|
+
const base = path.basename(harnessStatePath);
|
|
44
|
+
if (base.startsWith("riddle-proof-run-")) {
|
|
45
|
+
return path.join(dir, base.replace("riddle-proof-run-", "riddle-proof-state-"));
|
|
46
|
+
}
|
|
47
|
+
return path.join(dir, `${base}.engine-state.json`);
|
|
48
|
+
}
|
|
49
|
+
const stateDir = config?.stateDir || "/tmp";
|
|
50
|
+
const stamp = timestamp().replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
51
|
+
return path.join(stateDir, `riddle-proof-state-${stamp}-${crypto.randomUUID().slice(0, 8)}.json`);
|
|
52
|
+
}
|
|
37
53
|
function ensureParent(filePath) {
|
|
38
54
|
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
39
55
|
}
|
|
@@ -76,6 +92,18 @@ function heartbeat(state, input) {
|
|
|
76
92
|
function jsonParam(payload) {
|
|
77
93
|
return JSON.stringify(payload);
|
|
78
94
|
}
|
|
95
|
+
function redactedWorkflowParams(params) {
|
|
96
|
+
const secretKeys = /* @__PURE__ */ new Set([
|
|
97
|
+
"auth_localStorage_json",
|
|
98
|
+
"auth_cookies_json",
|
|
99
|
+
"auth_headers_json"
|
|
100
|
+
]);
|
|
101
|
+
const output = {};
|
|
102
|
+
for (const [key, value] of Object.entries(params)) {
|
|
103
|
+
output[key] = secretKeys.has(key) && value ? "[redacted]" : value;
|
|
104
|
+
}
|
|
105
|
+
return output;
|
|
106
|
+
}
|
|
79
107
|
function engineStatePath(result, state) {
|
|
80
108
|
return nonEmptyString(result.state_path) || nonEmptyString(state.request.engine_state_path);
|
|
81
109
|
}
|
|
@@ -582,6 +610,7 @@ function readRiddleProofRunStatus(state_path) {
|
|
|
582
610
|
async function runRiddleProofEngineHarness(input) {
|
|
583
611
|
const state = loadRunState(input);
|
|
584
612
|
state.request = normalizeRunParams({ ...state.request, ...input.request });
|
|
613
|
+
state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
|
|
585
614
|
const request = state.request;
|
|
586
615
|
const agent = input.agent || createDisabledRiddleProofAgentAdapter();
|
|
587
616
|
const maxIterations = Math.max(
|
|
@@ -637,24 +666,41 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
637
666
|
branch: state.branch || null
|
|
638
667
|
}
|
|
639
668
|
});
|
|
669
|
+
const engineCallStartedAt = timestamp();
|
|
670
|
+
const engineCallStartedMs = Date.now();
|
|
640
671
|
recordEvent(state, {
|
|
641
672
|
kind: "engine.call",
|
|
642
673
|
checkpoint: "engine_call",
|
|
643
674
|
stage,
|
|
644
675
|
summary: "Calling Riddle Proof engine.",
|
|
645
|
-
details: {
|
|
676
|
+
details: {
|
|
677
|
+
params: redactedWorkflowParams(nextParams),
|
|
678
|
+
started_at: engineCallStartedAt
|
|
679
|
+
}
|
|
646
680
|
});
|
|
647
681
|
let result;
|
|
648
682
|
try {
|
|
649
683
|
result = await engine.execute(nextParams);
|
|
650
684
|
} catch (error) {
|
|
651
685
|
const message = error instanceof Error ? error.message : String(error);
|
|
686
|
+
recordEvent(state, {
|
|
687
|
+
kind: "engine.exception",
|
|
688
|
+
checkpoint: "engine_call_failed",
|
|
689
|
+
stage,
|
|
690
|
+
summary: message,
|
|
691
|
+
details: {
|
|
692
|
+
duration_ms: Date.now() - engineCallStartedMs,
|
|
693
|
+
started_at: engineCallStartedAt,
|
|
694
|
+
finished_at: timestamp()
|
|
695
|
+
}
|
|
696
|
+
});
|
|
652
697
|
return blockerResult(state, lastResult, {
|
|
653
698
|
code: "riddle_engine_exception",
|
|
654
699
|
checkpoint: "engine_call_failed",
|
|
655
700
|
message
|
|
656
701
|
});
|
|
657
702
|
}
|
|
703
|
+
const engineCallDurationMs = Date.now() - engineCallStartedMs;
|
|
658
704
|
lastResult = result;
|
|
659
705
|
const engineState = engineStatePath(result, state);
|
|
660
706
|
if (engineState) state.request.engine_state_path = engineState;
|
|
@@ -679,7 +725,10 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
679
725
|
details: {
|
|
680
726
|
ok: result.ok ?? null,
|
|
681
727
|
engine_state_path: engineState || null,
|
|
682
|
-
checkpoint: result.checkpoint || null
|
|
728
|
+
checkpoint: result.checkpoint || null,
|
|
729
|
+
duration_ms: engineCallDurationMs,
|
|
730
|
+
started_at: engineCallStartedAt,
|
|
731
|
+
finished_at: timestamp()
|
|
683
732
|
}
|
|
684
733
|
});
|
|
685
734
|
const routed = await routeCheckpoint(request, state, result, agent, input);
|
package/dist/engine-harness.cjs
CHANGED
|
@@ -947,6 +947,87 @@ function updateState(statePath, mutate) {
|
|
|
947
947
|
writeState(statePath, state);
|
|
948
948
|
return state;
|
|
949
949
|
}
|
|
950
|
+
function nowIso() {
|
|
951
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
952
|
+
}
|
|
953
|
+
function appendRuntimeEventToState(state, event) {
|
|
954
|
+
const events = Array.isArray(state.runtime_events) ? state.runtime_events : [];
|
|
955
|
+
state.runtime_events = [...events, event].slice(-RUNTIME_EVENT_LIMIT);
|
|
956
|
+
state.runtime_updated_at = event.ts;
|
|
957
|
+
}
|
|
958
|
+
function beginRuntimeStep(statePath, action, step, workflowPath) {
|
|
959
|
+
const timer = {
|
|
960
|
+
startedAt: nowIso(),
|
|
961
|
+
startedMs: Date.now()
|
|
962
|
+
};
|
|
963
|
+
updateState(statePath, (state) => {
|
|
964
|
+
const current = {
|
|
965
|
+
step,
|
|
966
|
+
action,
|
|
967
|
+
status: "running",
|
|
968
|
+
started_at: timer.startedAt,
|
|
969
|
+
workflow_file: import_node_path2.default.basename(workflowPath)
|
|
970
|
+
};
|
|
971
|
+
state.current_runtime_step = current;
|
|
972
|
+
appendRuntimeEventToState(state, {
|
|
973
|
+
ts: timer.startedAt,
|
|
974
|
+
kind: "workflow.step.started",
|
|
975
|
+
step,
|
|
976
|
+
action,
|
|
977
|
+
summary: `Started ${step} workflow step.`,
|
|
978
|
+
details: {
|
|
979
|
+
workflow_file: import_node_path2.default.basename(workflowPath)
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
});
|
|
983
|
+
return timer;
|
|
984
|
+
}
|
|
985
|
+
function finishRuntimeStep(statePath, action, result, timer) {
|
|
986
|
+
const finishedAt = nowIso();
|
|
987
|
+
const durationMs = Date.now() - timer.startedMs;
|
|
988
|
+
const summary = result.haltedForApproval ? `${result.step} halted for approval.` : result.ok ? `Finished ${result.step} workflow step.` : `${result.step} workflow step failed.`;
|
|
989
|
+
updateState(statePath, (state) => {
|
|
990
|
+
const completed = {
|
|
991
|
+
step: result.step,
|
|
992
|
+
action,
|
|
993
|
+
status: result.haltedForApproval ? "approval_required" : result.ok ? "completed" : "failed",
|
|
994
|
+
started_at: timer.startedAt,
|
|
995
|
+
finished_at: finishedAt,
|
|
996
|
+
duration_ms: durationMs,
|
|
997
|
+
ok: result.ok,
|
|
998
|
+
halted_for_approval: result.haltedForApproval || false,
|
|
999
|
+
auto_approved: result.autoApproved || false,
|
|
1000
|
+
error: result.error || null
|
|
1001
|
+
};
|
|
1002
|
+
state.current_runtime_step = null;
|
|
1003
|
+
state.last_runtime_step = completed;
|
|
1004
|
+
appendRuntimeEventToState(state, {
|
|
1005
|
+
ts: finishedAt,
|
|
1006
|
+
kind: "workflow.step.finished",
|
|
1007
|
+
step: result.step,
|
|
1008
|
+
action,
|
|
1009
|
+
summary,
|
|
1010
|
+
details: completed
|
|
1011
|
+
});
|
|
1012
|
+
});
|
|
1013
|
+
return {
|
|
1014
|
+
...result,
|
|
1015
|
+
started_at: timer.startedAt,
|
|
1016
|
+
finished_at: finishedAt,
|
|
1017
|
+
duration_ms: durationMs
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
function executedStep(res, extra = {}) {
|
|
1021
|
+
const output = {
|
|
1022
|
+
step: res.step,
|
|
1023
|
+
ok: res.ok,
|
|
1024
|
+
haltedForApproval: res.haltedForApproval || false,
|
|
1025
|
+
autoApproved: res.autoApproved || false,
|
|
1026
|
+
...extra
|
|
1027
|
+
};
|
|
1028
|
+
if (typeof res.duration_ms === "number") output.duration_ms = res.duration_ms;
|
|
1029
|
+
return output;
|
|
1030
|
+
}
|
|
950
1031
|
function hasSupervisorProofAssessment(state) {
|
|
951
1032
|
const proofAssessment = state?.proof_assessment || {};
|
|
952
1033
|
const source = String(proofAssessment?.source || state?.proof_assessment_source || "").trim().toLowerCase();
|
|
@@ -1409,53 +1490,74 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
|
|
|
1409
1490
|
const lobsterPrefix = process.env.RIDDLE_PROOF_LOBSTER_SCRIPT ? [process.env.RIDDLE_PROOF_LOBSTER_SCRIPT] : [];
|
|
1410
1491
|
const runOne = (step) => {
|
|
1411
1492
|
const args = step === "setup" ? buildSetupArgs(params, config) : {};
|
|
1493
|
+
const stepWorkflowFile = workflowFile(config.riddleProofDir, step);
|
|
1494
|
+
const timer = beginRuntimeStep(config.statePath, action, step, stepWorkflowFile);
|
|
1412
1495
|
let output;
|
|
1413
1496
|
try {
|
|
1414
1497
|
output = JSON.parse(
|
|
1415
|
-
(0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "run", "--file",
|
|
1498
|
+
(0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "run", "--file", stepWorkflowFile, "--args-json", JSON.stringify(args)], {
|
|
1416
1499
|
encoding: "utf-8",
|
|
1417
1500
|
env
|
|
1418
1501
|
})
|
|
1419
1502
|
);
|
|
1420
1503
|
} catch (error) {
|
|
1421
|
-
return {
|
|
1504
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1422
1505
|
ok: false,
|
|
1423
1506
|
step,
|
|
1424
1507
|
error: error?.message || String(error),
|
|
1425
1508
|
stdout: String(error?.stdout || ""),
|
|
1426
1509
|
stderr: String(error?.stderr || "")
|
|
1427
|
-
};
|
|
1510
|
+
}, timer);
|
|
1428
1511
|
}
|
|
1429
1512
|
if (output?.status === "needs_approval") {
|
|
1430
1513
|
if (!params.auto_approve) {
|
|
1431
|
-
return {
|
|
1514
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1432
1515
|
ok: false,
|
|
1433
1516
|
haltedForApproval: true,
|
|
1434
1517
|
step,
|
|
1435
1518
|
approval: output.requiresApproval || null,
|
|
1436
1519
|
raw: output
|
|
1437
|
-
};
|
|
1520
|
+
}, timer);
|
|
1438
1521
|
}
|
|
1439
1522
|
const token = output?.requiresApproval?.resumeToken;
|
|
1440
|
-
if (!token)
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1523
|
+
if (!token) {
|
|
1524
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1525
|
+
ok: false,
|
|
1526
|
+
step,
|
|
1527
|
+
error: `${step} requested approval without a resume token.`,
|
|
1528
|
+
raw: output
|
|
1529
|
+
}, timer);
|
|
1530
|
+
}
|
|
1531
|
+
let resumed;
|
|
1532
|
+
try {
|
|
1533
|
+
resumed = JSON.parse(
|
|
1534
|
+
(0, import_node_child_process.execFileSync)(lobsterCommand, [...lobsterPrefix, "resume", "--token", token, "--approve", "yes"], {
|
|
1535
|
+
encoding: "utf-8",
|
|
1536
|
+
env
|
|
1537
|
+
})
|
|
1538
|
+
);
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1541
|
+
ok: false,
|
|
1542
|
+
step,
|
|
1543
|
+
autoApproved: true,
|
|
1544
|
+
error: error?.message || String(error),
|
|
1545
|
+
stdout: String(error?.stdout || ""),
|
|
1546
|
+
stderr: String(error?.stderr || "")
|
|
1547
|
+
}, timer);
|
|
1548
|
+
}
|
|
1549
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1448
1550
|
ok: resumed?.ok !== false,
|
|
1449
1551
|
step,
|
|
1450
1552
|
autoApproved: true,
|
|
1451
1553
|
raw: resumed
|
|
1452
|
-
};
|
|
1554
|
+
}, timer);
|
|
1453
1555
|
}
|
|
1454
|
-
return {
|
|
1556
|
+
return finishRuntimeStep(config.statePath, action, {
|
|
1455
1557
|
ok: output?.ok !== false,
|
|
1456
1558
|
step,
|
|
1457
1559
|
raw: output
|
|
1458
|
-
};
|
|
1560
|
+
}, timer);
|
|
1459
1561
|
};
|
|
1460
1562
|
let effectiveAdvanceStage = params.advance_stage || null;
|
|
1461
1563
|
const recordAttempt = (stage, status, summary, extra = {}) => {
|
|
@@ -1581,7 +1683,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
|
|
|
1581
1683
|
let state = readState(config.statePath);
|
|
1582
1684
|
if (!state || !state.workspace_ready || params.advance_stage === "setup") {
|
|
1583
1685
|
const setupRes = runOne("setup");
|
|
1584
|
-
executed.push(
|
|
1686
|
+
executed.push(executedStep(setupRes));
|
|
1585
1687
|
if (!setupRes.ok || setupRes.haltedForApproval) {
|
|
1586
1688
|
return failedRun("setup", setupRes.haltedForApproval ? "setup halted for approval" : "setup failed", setupRes, {
|
|
1587
1689
|
checkpoint: "setup_blocked"
|
|
@@ -1791,7 +1893,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
|
|
|
1791
1893
|
}
|
|
1792
1894
|
if (!state?.recon_results || state?.stage === "setup" || state?.stage === "preflight" || ["needs_agent_decision", "needs_supervisor_judgment"].includes(state?.recon_status || "") || requestedStage === "recon") {
|
|
1793
1895
|
const reconRes = runOne("recon");
|
|
1794
|
-
executed.push(
|
|
1896
|
+
executed.push(executedStep(reconRes));
|
|
1795
1897
|
if (!reconRes.ok || reconRes.haltedForApproval) {
|
|
1796
1898
|
return failedRun("recon", reconRes.haltedForApproval ? "recon halted for approval" : "recon failed", reconRes, {
|
|
1797
1899
|
checkpoint: "recon_failed",
|
|
@@ -1839,7 +1941,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
|
|
|
1839
1941
|
state = readState(config.statePath);
|
|
1840
1942
|
if (!authorReady(state) || effectiveAdvanceStage === "author") {
|
|
1841
1943
|
const authorRes = runOne("author");
|
|
1842
|
-
executed.push(
|
|
1944
|
+
executed.push(executedStep(authorRes));
|
|
1843
1945
|
if (!authorRes.ok || authorRes.haltedForApproval) {
|
|
1844
1946
|
return failedRun("author", authorRes.haltedForApproval ? "author halted for approval" : "author failed", authorRes, {
|
|
1845
1947
|
checkpoint: "author_failed",
|
|
@@ -1954,7 +2056,7 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
|
|
|
1954
2056
|
}
|
|
1955
2057
|
if (effectiveAdvanceStage === "implement") {
|
|
1956
2058
|
const implementRes = runOne("implement");
|
|
1957
|
-
executed.push(
|
|
2059
|
+
executed.push(executedStep(implementRes));
|
|
1958
2060
|
if (implementRes.haltedForApproval) {
|
|
1959
2061
|
return failedRun("implement", "implement halted for approval", implementRes, {
|
|
1960
2062
|
checkpoint: "implement_blocked",
|
|
@@ -2044,7 +2146,7 @@ ${implementRes.stderr || ""}`;
|
|
|
2044
2146
|
let verifyRes = { ok: true, step: "verify", reusedEvidence: canReuseVerifyEvidence };
|
|
2045
2147
|
if (!canReuseVerifyEvidence) {
|
|
2046
2148
|
verifyRes = runOne("verify");
|
|
2047
|
-
executed.push(
|
|
2149
|
+
executed.push(executedStep(verifyRes));
|
|
2048
2150
|
if (!verifyRes.ok || verifyRes.haltedForApproval) {
|
|
2049
2151
|
return failedRun("verify", verifyRes.haltedForApproval ? "verify halted for approval" : "verify failed", verifyRes, {
|
|
2050
2152
|
checkpoint: "verify_failed",
|
|
@@ -2053,7 +2155,7 @@ ${implementRes.stderr || ""}`;
|
|
|
2053
2155
|
});
|
|
2054
2156
|
}
|
|
2055
2157
|
} else {
|
|
2056
|
-
executed.push(
|
|
2158
|
+
executed.push(executedStep(verifyRes, { reusedEvidence: true }));
|
|
2057
2159
|
}
|
|
2058
2160
|
state = readState(config.statePath);
|
|
2059
2161
|
const verifyStatus = state?.verify_status || ((state?.after_cdn || "").trim() ? "evidence_captured" : "capture_incomplete");
|
|
@@ -2190,7 +2292,7 @@ ${implementRes.stderr || ""}`;
|
|
|
2190
2292
|
details: { ...verifyDetails, shipGate }
|
|
2191
2293
|
});
|
|
2192
2294
|
const shipRes = runOne("ship");
|
|
2193
|
-
executed.push(
|
|
2295
|
+
executed.push(executedStep(shipRes));
|
|
2194
2296
|
if (!shipRes.ok || shipRes.haltedForApproval) {
|
|
2195
2297
|
const shipNextAction = shipRes?.error && String(shipRes.error).includes("temporary proof branch") ? "product bug: ship resolved a temporary proof branch; resolve the PR head branch before retrying ship" : "inspect the ship error, confirm the PR head branch and verified commit, then retry ship";
|
|
2196
2298
|
return failedRun("ship", shipRes.haltedForApproval ? "ship halted for approval" : "ship failed", shipRes, {
|
|
@@ -2369,7 +2471,7 @@ ${implementRes.stderr || ""}`;
|
|
|
2369
2471
|
return shipGateBlocked(state, executed, { shipAssessment: shipAssessment.raw });
|
|
2370
2472
|
}
|
|
2371
2473
|
const shipRes = runOne("ship");
|
|
2372
|
-
executed.push(
|
|
2474
|
+
executed.push(executedStep(shipRes));
|
|
2373
2475
|
if (!shipRes.ok || shipRes.haltedForApproval) {
|
|
2374
2476
|
return failedRun("ship", shipRes.haltedForApproval ? "ship halted for approval" : "ship failed", shipRes, {
|
|
2375
2477
|
checkpoint: "ship_failed",
|
|
@@ -2495,7 +2597,7 @@ function createRiddleProofEngine(pluginConfig = {}) {
|
|
|
2495
2597
|
}
|
|
2496
2598
|
};
|
|
2497
2599
|
}
|
|
2498
|
-
var import_node_child_process, import_node_fs2, import_node_path2;
|
|
2600
|
+
var import_node_child_process, import_node_fs2, import_node_path2, RUNTIME_EVENT_LIMIT;
|
|
2499
2601
|
var init_proof_run_engine = __esm({
|
|
2500
2602
|
"src/proof-run-engine.ts"() {
|
|
2501
2603
|
"use strict";
|
|
@@ -2503,6 +2605,7 @@ var init_proof_run_engine = __esm({
|
|
|
2503
2605
|
import_node_fs2 = require("fs");
|
|
2504
2606
|
import_node_path2 = __toESM(require("path"), 1);
|
|
2505
2607
|
init_proof_run_core();
|
|
2608
|
+
RUNTIME_EVENT_LIMIT = 100;
|
|
2506
2609
|
}
|
|
2507
2610
|
});
|
|
2508
2611
|
|
|
@@ -2901,6 +3004,22 @@ function createHarnessStatePath(stateDir) {
|
|
|
2901
3004
|
const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
2902
3005
|
return import_node_path3.default.join(stateDir, `riddle-proof-run-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
|
|
2903
3006
|
}
|
|
3007
|
+
function createEngineStatePath(state, config) {
|
|
3008
|
+
const existing = nonEmptyString(state.request.engine_state_path);
|
|
3009
|
+
if (existing) return existing;
|
|
3010
|
+
const harnessStatePath = nonEmptyString(state.state_path);
|
|
3011
|
+
if (harnessStatePath) {
|
|
3012
|
+
const dir = import_node_path3.default.dirname(harnessStatePath);
|
|
3013
|
+
const base = import_node_path3.default.basename(harnessStatePath);
|
|
3014
|
+
if (base.startsWith("riddle-proof-run-")) {
|
|
3015
|
+
return import_node_path3.default.join(dir, base.replace("riddle-proof-run-", "riddle-proof-state-"));
|
|
3016
|
+
}
|
|
3017
|
+
return import_node_path3.default.join(dir, `${base}.engine-state.json`);
|
|
3018
|
+
}
|
|
3019
|
+
const stateDir = config?.stateDir || "/tmp";
|
|
3020
|
+
const stamp = timestamp2().replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
3021
|
+
return import_node_path3.default.join(stateDir, `riddle-proof-state-${stamp}-${import_node_crypto2.default.randomUUID().slice(0, 8)}.json`);
|
|
3022
|
+
}
|
|
2904
3023
|
function ensureParent(filePath) {
|
|
2905
3024
|
(0, import_node_fs3.mkdirSync)(import_node_path3.default.dirname(filePath), { recursive: true });
|
|
2906
3025
|
}
|
|
@@ -2943,6 +3062,18 @@ function heartbeat(state, input) {
|
|
|
2943
3062
|
function jsonParam(payload) {
|
|
2944
3063
|
return JSON.stringify(payload);
|
|
2945
3064
|
}
|
|
3065
|
+
function redactedWorkflowParams(params) {
|
|
3066
|
+
const secretKeys = /* @__PURE__ */ new Set([
|
|
3067
|
+
"auth_localStorage_json",
|
|
3068
|
+
"auth_cookies_json",
|
|
3069
|
+
"auth_headers_json"
|
|
3070
|
+
]);
|
|
3071
|
+
const output = {};
|
|
3072
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3073
|
+
output[key] = secretKeys.has(key) && value ? "[redacted]" : value;
|
|
3074
|
+
}
|
|
3075
|
+
return output;
|
|
3076
|
+
}
|
|
2946
3077
|
function engineStatePath(result, state) {
|
|
2947
3078
|
return nonEmptyString(result.state_path) || nonEmptyString(state.request.engine_state_path);
|
|
2948
3079
|
}
|
|
@@ -3449,6 +3580,7 @@ function readRiddleProofRunStatus(state_path) {
|
|
|
3449
3580
|
async function runRiddleProofEngineHarness(input) {
|
|
3450
3581
|
const state = loadRunState(input);
|
|
3451
3582
|
state.request = normalizeRunParams({ ...state.request, ...input.request });
|
|
3583
|
+
state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
|
|
3452
3584
|
const request = state.request;
|
|
3453
3585
|
const agent = input.agent || createDisabledRiddleProofAgentAdapter();
|
|
3454
3586
|
const maxIterations = Math.max(
|
|
@@ -3504,24 +3636,41 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
3504
3636
|
branch: state.branch || null
|
|
3505
3637
|
}
|
|
3506
3638
|
});
|
|
3639
|
+
const engineCallStartedAt = timestamp2();
|
|
3640
|
+
const engineCallStartedMs = Date.now();
|
|
3507
3641
|
recordEvent(state, {
|
|
3508
3642
|
kind: "engine.call",
|
|
3509
3643
|
checkpoint: "engine_call",
|
|
3510
3644
|
stage,
|
|
3511
3645
|
summary: "Calling Riddle Proof engine.",
|
|
3512
|
-
details: {
|
|
3646
|
+
details: {
|
|
3647
|
+
params: redactedWorkflowParams(nextParams),
|
|
3648
|
+
started_at: engineCallStartedAt
|
|
3649
|
+
}
|
|
3513
3650
|
});
|
|
3514
3651
|
let result;
|
|
3515
3652
|
try {
|
|
3516
3653
|
result = await engine.execute(nextParams);
|
|
3517
3654
|
} catch (error) {
|
|
3518
3655
|
const message = error instanceof Error ? error.message : String(error);
|
|
3656
|
+
recordEvent(state, {
|
|
3657
|
+
kind: "engine.exception",
|
|
3658
|
+
checkpoint: "engine_call_failed",
|
|
3659
|
+
stage,
|
|
3660
|
+
summary: message,
|
|
3661
|
+
details: {
|
|
3662
|
+
duration_ms: Date.now() - engineCallStartedMs,
|
|
3663
|
+
started_at: engineCallStartedAt,
|
|
3664
|
+
finished_at: timestamp2()
|
|
3665
|
+
}
|
|
3666
|
+
});
|
|
3519
3667
|
return blockerResult(state, lastResult, {
|
|
3520
3668
|
code: "riddle_engine_exception",
|
|
3521
3669
|
checkpoint: "engine_call_failed",
|
|
3522
3670
|
message
|
|
3523
3671
|
});
|
|
3524
3672
|
}
|
|
3673
|
+
const engineCallDurationMs = Date.now() - engineCallStartedMs;
|
|
3525
3674
|
lastResult = result;
|
|
3526
3675
|
const engineState = engineStatePath(result, state);
|
|
3527
3676
|
if (engineState) state.request.engine_state_path = engineState;
|
|
@@ -3546,7 +3695,10 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
3546
3695
|
details: {
|
|
3547
3696
|
ok: result.ok ?? null,
|
|
3548
3697
|
engine_state_path: engineState || null,
|
|
3549
|
-
checkpoint: result.checkpoint || null
|
|
3698
|
+
checkpoint: result.checkpoint || null,
|
|
3699
|
+
duration_ms: engineCallDurationMs,
|
|
3700
|
+
started_at: engineCallStartedAt,
|
|
3701
|
+
finished_at: timestamp2()
|
|
3550
3702
|
}
|
|
3551
3703
|
});
|
|
3552
3704
|
const routed = await routeCheckpoint(request, state, result, agent, input);
|
package/dist/engine-harness.js
CHANGED