@riddledc/riddle-proof 0.5.1 → 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.
@@ -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
  }
@@ -341,7 +369,11 @@ async function resolveEngine(input) {
341
369
  if (input.engine) return input.engine;
342
370
  const moduleUrl = input.config?.riddleEngineModuleUrl;
343
371
  if (!moduleUrl) {
344
- throw new Error("No riddle engine adapter or riddleEngineModuleUrl is configured.");
372
+ const mod2 = await import("./proof-run-engine.js");
373
+ return mod2.createRiddleProofEngine({
374
+ riddleProofDir: input.config?.riddleProofDir,
375
+ defaultReviewer: input.config?.defaultReviewer
376
+ });
345
377
  }
346
378
  const mod = await import(moduleUrl);
347
379
  if (typeof mod.createRiddleProofEngine !== "function") {
@@ -578,6 +610,7 @@ function readRiddleProofRunStatus(state_path) {
578
610
  async function runRiddleProofEngineHarness(input) {
579
611
  const state = loadRunState(input);
580
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);
581
614
  const request = state.request;
582
615
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
583
616
  const maxIterations = Math.max(
@@ -633,24 +666,41 @@ async function runRiddleProofEngineHarness(input) {
633
666
  branch: state.branch || null
634
667
  }
635
668
  });
669
+ const engineCallStartedAt = timestamp();
670
+ const engineCallStartedMs = Date.now();
636
671
  recordEvent(state, {
637
672
  kind: "engine.call",
638
673
  checkpoint: "engine_call",
639
674
  stage,
640
675
  summary: "Calling Riddle Proof engine.",
641
- details: { params: nextParams }
676
+ details: {
677
+ params: redactedWorkflowParams(nextParams),
678
+ started_at: engineCallStartedAt
679
+ }
642
680
  });
643
681
  let result;
644
682
  try {
645
683
  result = await engine.execute(nextParams);
646
684
  } catch (error) {
647
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
+ });
648
697
  return blockerResult(state, lastResult, {
649
698
  code: "riddle_engine_exception",
650
699
  checkpoint: "engine_call_failed",
651
700
  message
652
701
  });
653
702
  }
703
+ const engineCallDurationMs = Date.now() - engineCallStartedMs;
654
704
  lastResult = result;
655
705
  const engineState = engineStatePath(result, state);
656
706
  if (engineState) state.request.engine_state_path = engineState;
@@ -675,7 +725,10 @@ async function runRiddleProofEngineHarness(input) {
675
725
  details: {
676
726
  ok: result.ok ?? null,
677
727
  engine_state_path: engineState || null,
678
- checkpoint: result.checkpoint || null
728
+ checkpoint: result.checkpoint || null,
729
+ duration_ms: engineCallDurationMs,
730
+ started_at: engineCallStartedAt,
731
+ finished_at: timestamp()
679
732
  }
680
733
  });
681
734
  const routed = await routeCheckpoint(request, state, result, agent, input);