@riddledc/riddle-proof 0.7.225 → 0.7.227

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.
Files changed (139) hide show
  1. package/dist/adapters/codex-exec-agent.cjs +893 -0
  2. package/dist/adapters/codex-exec-agent.d.cts +3 -0
  3. package/dist/adapters/codex-exec-agent.d.ts +3 -0
  4. package/dist/adapters/codex-exec-agent.js +13 -0
  5. package/dist/adapters/codex.cjs +893 -0
  6. package/dist/adapters/codex.d.cts +3 -0
  7. package/dist/adapters/codex.d.ts +3 -0
  8. package/dist/adapters/codex.js +13 -0
  9. package/dist/adapters/local-agent.cjs +893 -0
  10. package/dist/adapters/local-agent.d.cts +3 -0
  11. package/dist/adapters/local-agent.d.ts +3 -0
  12. package/dist/adapters/local-agent.js +13 -0
  13. package/dist/adapters/openclaw.cjs +213 -0
  14. package/dist/adapters/openclaw.d.cts +2 -0
  15. package/dist/adapters/openclaw.d.ts +2 -0
  16. package/dist/adapters/openclaw.js +17 -0
  17. package/dist/advanced/engine-harness.cjs +5701 -0
  18. package/dist/advanced/engine-harness.d.cts +2 -0
  19. package/dist/advanced/engine-harness.d.ts +2 -0
  20. package/dist/advanced/engine-harness.js +16 -0
  21. package/dist/advanced/index.cjs +6242 -0
  22. package/dist/advanced/index.d.cts +5 -0
  23. package/dist/advanced/index.d.ts +5 -0
  24. package/dist/advanced/index.js +23 -0
  25. package/dist/advanced/proof-run-core.cjs +1085 -0
  26. package/dist/advanced/proof-run-core.d.cts +1 -0
  27. package/dist/advanced/proof-run-core.d.ts +1 -0
  28. package/dist/advanced/proof-run-core.js +59 -0
  29. package/dist/advanced/proof-run-engine.cjs +2905 -0
  30. package/dist/advanced/proof-run-engine.d.cts +2 -0
  31. package/dist/advanced/proof-run-engine.d.ts +2 -0
  32. package/dist/advanced/proof-run-engine.js +10 -0
  33. package/dist/advanced/runner.cjs +833 -0
  34. package/dist/advanced/runner.d.cts +2 -0
  35. package/dist/advanced/runner.d.ts +2 -0
  36. package/dist/advanced/runner.js +12 -0
  37. package/dist/app-contract/index.cjs +24 -0
  38. package/dist/app-contract/index.d.cts +1 -0
  39. package/dist/app-contract/index.d.ts +1 -0
  40. package/dist/app-contract/index.js +2 -0
  41. package/dist/basic-gameplay.js +1 -0
  42. package/dist/checkpoint.js +1 -0
  43. package/dist/chunk-BHL4JSGM.js +1900 -0
  44. package/dist/chunk-BTN76IGW.js +115 -0
  45. package/dist/{chunk-TGHTM66Z.js → chunk-COERZX63.js} +10 -2
  46. package/dist/{chunk-4DRRIJDX.js → chunk-IWLQQ5S5.js} +27 -4
  47. package/dist/chunk-MLKGABMK.js +9 -0
  48. package/dist/chunk-OFSECTSC.js +0 -0
  49. package/dist/{chunk-GBVEQQIM.js → chunk-TJ63IE65.js} +36 -1
  50. package/dist/chunk-VZD5LH7U.js +4138 -0
  51. package/dist/cli/index.cjs +18 -0
  52. package/dist/cli/index.d.cts +2 -0
  53. package/dist/cli/index.d.ts +2 -0
  54. package/dist/cli/index.js +12 -0
  55. package/dist/cli.cjs +19 -2
  56. package/dist/cli.d.cts +1 -0
  57. package/dist/cli.d.ts +1 -0
  58. package/dist/cli.js +8 -4139
  59. package/dist/codex-exec-agent.d.cts +1 -1
  60. package/dist/codex-exec-agent.d.ts +1 -1
  61. package/dist/codex-exec-agent.js +1 -0
  62. package/dist/diagnostics.js +1 -0
  63. package/dist/engine-harness-CMACHP6A.d.ts +96 -0
  64. package/dist/engine-harness-LBfqbFSe.d.cts +96 -0
  65. package/dist/engine-harness.cjs +19 -2
  66. package/dist/engine-harness.d.cts +2 -79
  67. package/dist/engine-harness.d.ts +2 -79
  68. package/dist/engine-harness.js +3 -2
  69. package/dist/index.cjs +19 -2
  70. package/dist/index.d.cts +2 -2
  71. package/dist/index.d.ts +2 -2
  72. package/dist/index.js +4 -3
  73. package/dist/local-agent.d.cts +1 -1
  74. package/dist/local-agent.d.ts +1 -1
  75. package/dist/local-agent.js +1 -0
  76. package/dist/openclaw.js +8 -107
  77. package/dist/playability.js +1 -0
  78. package/dist/profile/index.cjs +9403 -0
  79. package/dist/profile/index.d.cts +2 -0
  80. package/dist/profile/index.d.ts +2 -0
  81. package/dist/profile/index.js +53 -0
  82. package/dist/profile.js +1 -0
  83. package/dist/proof-run-core-CE0jx7wL.d.cts +359 -0
  84. package/dist/proof-run-core-CE0jx7wL.d.ts +359 -0
  85. package/dist/proof-run-core.d.cts +1 -322
  86. package/dist/proof-run-core.d.ts +1 -322
  87. package/dist/proof-run-core.js +2 -1
  88. package/dist/proof-run-engine-CSSc0mNn.d.ts +764 -0
  89. package/dist/proof-run-engine-HSRpUeBi.d.cts +764 -0
  90. package/dist/proof-run-engine.cjs +4 -0
  91. package/dist/proof-run-engine.d.cts +2 -757
  92. package/dist/proof-run-engine.d.ts +2 -757
  93. package/dist/proof-run-engine.js +5 -1881
  94. package/dist/proof-session.js +1 -0
  95. package/dist/result.js +1 -0
  96. package/dist/riddle-client.js +1 -0
  97. package/dist/run-card.js +1 -0
  98. package/dist/runner-4LJ5z0D-.d.cts +29 -0
  99. package/dist/runner-BdQpOkZD.d.ts +29 -0
  100. package/dist/runner.d.cts +2 -22
  101. package/dist/runner.d.ts +2 -22
  102. package/dist/runner.js +3 -2
  103. package/dist/runtime/index.cjs +528 -0
  104. package/dist/runtime/index.d.cts +1 -0
  105. package/dist/runtime/index.d.ts +1 -0
  106. package/dist/runtime/index.js +37 -0
  107. package/dist/runtime/riddle-client.cjs +528 -0
  108. package/dist/runtime/riddle-client.d.cts +1 -0
  109. package/dist/runtime/riddle-client.d.ts +1 -0
  110. package/dist/runtime/riddle-client.js +37 -0
  111. package/dist/spec/checkpoint.cjs +807 -0
  112. package/dist/spec/checkpoint.d.cts +2 -0
  113. package/dist/spec/checkpoint.d.ts +2 -0
  114. package/dist/spec/checkpoint.js +34 -0
  115. package/dist/spec/index.cjs +1510 -0
  116. package/dist/spec/index.d.cts +5 -0
  117. package/dist/spec/index.d.ts +5 -0
  118. package/dist/spec/index.js +80 -0
  119. package/dist/spec/result.cjs +259 -0
  120. package/dist/spec/result.d.cts +2 -0
  121. package/dist/spec/result.d.ts +2 -0
  122. package/dist/spec/result.js +21 -0
  123. package/dist/spec/run-card.cjs +287 -0
  124. package/dist/spec/run-card.d.cts +2 -0
  125. package/dist/spec/run-card.d.ts +2 -0
  126. package/dist/spec/run-card.js +11 -0
  127. package/dist/spec/state.cjs +541 -0
  128. package/dist/spec/state.d.cts +2 -0
  129. package/dist/spec/state.d.ts +2 -0
  130. package/dist/spec/state.js +28 -0
  131. package/dist/spec/types.cjs +18 -0
  132. package/dist/spec/types.d.cts +1 -0
  133. package/dist/spec/types.d.ts +1 -0
  134. package/dist/spec/types.js +1 -0
  135. package/dist/state.js +1 -0
  136. package/package.json +95 -2
  137. package/runtime/lib/verify.py +53 -3
  138. package/runtime/pipelines/riddle-proof-setup.lobster +45 -41
  139. package/runtime/tests/recon_verify_smoke.py +41 -0
@@ -0,0 +1,541 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/spec/state.ts
31
+ var state_exports = {};
32
+ __export(state_exports, {
33
+ RIDDLE_PROOF_RUN_STATE_VERSION: () => RIDDLE_PROOF_RUN_STATE_VERSION,
34
+ appendRunEvent: () => appendRunEvent,
35
+ appendStageHeartbeat: () => appendStageHeartbeat,
36
+ applyPrLifecycleState: () => applyPrLifecycleState,
37
+ createRunState: () => createRunState,
38
+ createRunStatusSnapshot: () => createRunStatusSnapshot,
39
+ normalizeIntegrationContext: () => normalizeIntegrationContext,
40
+ normalizePrLifecycleState: () => normalizePrLifecycleState,
41
+ normalizeRunParams: () => normalizeRunParams,
42
+ setRunStatus: () => setRunStatus
43
+ });
44
+ module.exports = __toCommonJS(state_exports);
45
+
46
+ // src/result.ts
47
+ function isTerminalStatus(status) {
48
+ return status === "blocked" || status === "failed" || status === "ready_to_ship" || status === "shipped" || status === "completed";
49
+ }
50
+ function compactRecord(input) {
51
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0 && value !== null && value !== ""));
52
+ }
53
+ function nonEmptyString(value) {
54
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
55
+ }
56
+ function recordValue(value) {
57
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
58
+ }
59
+
60
+ // src/checkpoint.ts
61
+ var import_node_crypto = __toESM(require("crypto"), 1);
62
+ function statePathsForRunState(state, engineStatePath) {
63
+ return compactRecord({
64
+ wrapper_state_path: state.state_path || state.request.harness_state_path || null,
65
+ engine_state_path: engineStatePath || state.request.engine_state_path || null,
66
+ resume_state_path: engineStatePath || state.request.engine_state_path || null
67
+ });
68
+ }
69
+
70
+ // src/run-card.ts
71
+ var RIDDLE_PROOF_RUN_CARD_VERSION = "riddle-proof.run-card.v1";
72
+ function elapsedMs(start, end) {
73
+ const startMs = start ? Date.parse(start) : NaN;
74
+ const endMs = end ? Date.parse(end) : NaN;
75
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
76
+ return Math.max(0, endMs - startMs);
77
+ }
78
+ function jsonCloneRecord(value) {
79
+ const record = recordValue(value);
80
+ if (!record) return void 0;
81
+ try {
82
+ return JSON.parse(JSON.stringify(record));
83
+ } catch {
84
+ return { ...record };
85
+ }
86
+ }
87
+ function compactText(value, limit = 600) {
88
+ const text = nonEmptyString(value);
89
+ if (!text) return void 0;
90
+ return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
91
+ }
92
+ function numericValue(value) {
93
+ const number = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
94
+ return Number.isFinite(number) ? number : void 0;
95
+ }
96
+ function eventDetails(event) {
97
+ return recordValue(recordValue(event)?.details) || {};
98
+ }
99
+ function collectRunnerMetrics(details) {
100
+ const metrics = [];
101
+ const adapterDetails = recordValue(details.adapter_details);
102
+ const direct = recordValue(adapterDetails?.runner_metrics);
103
+ if (direct) metrics.push(direct);
104
+ const attempts = Array.isArray(adapterDetails?.attempt_summaries) ? adapterDetails.attempt_summaries : [];
105
+ for (const attempt of attempts) {
106
+ const attemptMetrics = recordValue(recordValue(attempt)?.runner_metrics);
107
+ if (attemptMetrics) metrics.push(attemptMetrics);
108
+ }
109
+ return metrics;
110
+ }
111
+ function observabilityFrom(state) {
112
+ const engineEvents = state.events.filter((event) => event.kind === "engine.result").map((event) => ({ event, details: eventDetails(event) }));
113
+ const agentEvents = state.events.filter((event) => event.kind.startsWith("agent.")).map((event) => ({ event, details: eventDetails(event) })).filter(({ details }) => numericValue(details.duration_ms) !== void 0);
114
+ const retryEvents = state.events.filter((event) => /retry|recovery/i.test(event.kind) || /retry|recovery/i.test(event.summary || "")).slice(-8);
115
+ const runnerMetrics = agentEvents.flatMap(({ details }) => collectRunnerMetrics(details));
116
+ const promptChars = runnerMetrics.map((metrics) => numericValue(metrics.prompt_chars)).filter((value) => value !== void 0);
117
+ const sum = (values) => values.reduce((total, value) => total + (value ?? 0), 0);
118
+ const recentEngineTimings = engineEvents.slice(-8).map(({ event, details }) => compactRecord({
119
+ checkpoint: event.checkpoint || null,
120
+ stage: event.stage || null,
121
+ duration_ms: numericValue(details.duration_ms),
122
+ ok: details.ok ?? null
123
+ }));
124
+ const recentAgentTimings = agentEvents.slice(-8).map(({ event, details }) => {
125
+ const metrics = collectRunnerMetrics(details);
126
+ const localPromptChars = metrics.map((item) => numericValue(item.prompt_chars)).filter((value) => value !== void 0);
127
+ return compactRecord({
128
+ kind: event.kind,
129
+ checkpoint: event.checkpoint || null,
130
+ stage: event.stage || null,
131
+ duration_ms: numericValue(details.duration_ms),
132
+ prompt_chars: localPromptChars.length ? Math.max(...localPromptChars) : void 0,
133
+ attempt_count: numericValue(recordValue(details.adapter_details)?.attempt_count)
134
+ });
135
+ });
136
+ return compactRecord({
137
+ engine_call_count: engineEvents.length,
138
+ agent_call_count: agentEvents.length,
139
+ engine_total_ms: sum(engineEvents.map(({ details }) => numericValue(details.duration_ms))),
140
+ agent_total_ms: sum(agentEvents.map(({ details }) => numericValue(details.duration_ms))),
141
+ max_agent_prompt_chars: promptChars.length ? Math.max(...promptChars) : void 0,
142
+ total_agent_prompt_chars: promptChars.length ? sum(promptChars) : void 0,
143
+ recent_engine_timings: recentEngineTimings.length ? recentEngineTimings : void 0,
144
+ recent_agent_timings: recentAgentTimings.length ? recentAgentTimings : void 0,
145
+ retry_event_count: retryEvents.length,
146
+ recent_retry_reasons: retryEvents.length ? retryEvents.map((event) => compactRecord({
147
+ kind: event.kind,
148
+ checkpoint: event.checkpoint || null,
149
+ stage: event.stage || null,
150
+ summary: compactText(event.summary, 240)
151
+ })) : void 0
152
+ });
153
+ }
154
+ function visualDeltaFrom(input) {
155
+ const fullState = input.fullRiddleState || {};
156
+ const bundle = recordValue(fullState.evidence_bundle);
157
+ const after = recordValue(bundle?.after);
158
+ const afterDelta = recordValue(after?.visual_delta);
159
+ if (afterDelta && Object.keys(afterDelta).length) return afterDelta;
160
+ const requestDelta = recordValue(recordValue(fullState.proof_assessment_request)?.visual_delta);
161
+ if (requestDelta && Object.keys(requestDelta).length) return requestDelta;
162
+ const packetDelta = recordValue(input.runState.checkpoint_packet?.evidence_excerpt?.visual_delta);
163
+ return packetDelta && Object.keys(packetDelta).length ? packetDelta : void 0;
164
+ }
165
+ function artifactsFrom(input) {
166
+ const packetArtifacts = input.runState.checkpoint_packet?.artifacts;
167
+ if (packetArtifacts?.length) return packetArtifacts.slice(0, 12);
168
+ const fullState = input.fullRiddleState || {};
169
+ const artifacts = [];
170
+ for (const role of ["before", "prod", "after"]) {
171
+ const url = nonEmptyString(fullState[`${role}_cdn`]) || nonEmptyString(input.runState[`${role}_artifact_url`]);
172
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
173
+ }
174
+ return artifacts.length ? artifacts : void 0;
175
+ }
176
+ function viewportMatrixFrom(input) {
177
+ const fullState = input.fullRiddleState || {};
178
+ const bundle = recordValue(fullState.evidence_bundle);
179
+ const fromBundle = recordValue(bundle?.viewport_matrix);
180
+ if (fromBundle && Object.keys(fromBundle).length) return jsonCloneRecord(fromBundle);
181
+ const fromRequest = recordValue(recordValue(fullState.proof_assessment_request)?.viewport_matrix);
182
+ if (fromRequest && Object.keys(fromRequest).length) return jsonCloneRecord(fromRequest);
183
+ const fromState = recordValue(fullState.viewport_matrix_status) || recordValue(input.runState.viewport_matrix_status);
184
+ return fromState && Object.keys(fromState).length ? jsonCloneRecord(fromState) : void 0;
185
+ }
186
+ function ownerFor(state) {
187
+ if (state.status === "awaiting_checkpoint") {
188
+ const role = nonEmptyString(state.checkpoint_packet?.routing_hint?.suggested_role);
189
+ return role || "supervising_agent";
190
+ }
191
+ if (state.status === "running") return "engine";
192
+ if (state.status === "blocked" || state.status === "failed") return "human_or_operator";
193
+ return "none";
194
+ }
195
+ function actionFor(state) {
196
+ if (state.status === "awaiting_checkpoint") return state.checkpoint_packet?.question || "Answer the pending checkpoint.";
197
+ if (state.status === "running") return "Continue the current Riddle Proof stage.";
198
+ if (state.status === "blocked" || state.status === "failed") return state.blocker?.message || "Inspect the blocker and decide whether a new run or infrastructure repair is needed.";
199
+ if (state.status === "ready_to_ship") return "Ship is held by policy; review PR/ship policy before advancing.";
200
+ return "No next action; run is terminal.";
201
+ }
202
+ function evidenceIssueCode(input) {
203
+ const packetIssue = nonEmptyString(input.runState.checkpoint_packet?.evidence_excerpt?.evidence_issue_code);
204
+ if (packetIssue) return packetIssue;
205
+ const assessmentIssue = nonEmptyString(recordValue(input.fullRiddleState?.proof_assessment)?.evidence_issue_code);
206
+ if (assessmentIssue) return assessmentIssue;
207
+ const delta = visualDeltaFrom(input);
208
+ const status = nonEmptyString(delta?.status);
209
+ if (status === "unmeasured") {
210
+ const reason = `${nonEmptyString(delta?.reason) || ""}
211
+ ${input.runState.blocker?.message || ""}`.toLowerCase();
212
+ return reason.includes("fetch") || reason.includes("allowlist") || reason.includes("registered domain") || reason.includes("high risk") || reason.includes("comparator") ? "comparator_fetch_blocked" : "visual_delta_unmeasured";
213
+ }
214
+ if (status === "measured" && delta?.passed === false) return "semantic_proof_failed";
215
+ return void 0;
216
+ }
217
+ function createRiddleProofRunCard(state, input = {}) {
218
+ const at = input.at || (/* @__PURE__ */ new Date()).toISOString();
219
+ const fullState = input.fullRiddleState || {};
220
+ const packet = state.checkpoint_packet;
221
+ const latestEvent = state.events[state.events.length - 1];
222
+ const bundle = recordValue(fullState.evidence_bundle);
223
+ const artifactContract = jsonCloneRecord(packet?.artifact_contract) || jsonCloneRecord(recordValue(fullState.proof_assessment_request)?.artifact_contract) || jsonCloneRecord(recordValue(bundle?.artifact_contract)) || jsonCloneRecord(state.proof_contract?.artifact_contract);
224
+ const required = jsonCloneRecord(recordValue(artifactContract)?.required);
225
+ const statePaths = input.state_paths || state.state_paths || statePathsForRunState(state);
226
+ const visualDelta = visualDeltaFrom({ fullRiddleState: fullState, runState: state });
227
+ const artifacts = artifactsFrom({ fullRiddleState: fullState, runState: state });
228
+ const viewportMatrix = viewportMatrixFrom({ fullRiddleState: fullState, runState: state });
229
+ return {
230
+ version: RIDDLE_PROOF_RUN_CARD_VERSION,
231
+ run_id: state.run_id || "unknown",
232
+ status: state.status,
233
+ goal: compactRecord({
234
+ repo: state.request.repo || nonEmptyString(fullState.repo),
235
+ branch: state.request.branch || nonEmptyString(fullState.branch),
236
+ change_request: state.request.change_request || nonEmptyString(fullState.change_request),
237
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
238
+ success_criteria: state.request.success_criteria
239
+ }),
240
+ durable_state: compactRecord({
241
+ ...statePaths,
242
+ worktree_path: state.worktree_path || nonEmptyString(fullState.after_worktree) || null,
243
+ branch: state.branch || nonEmptyString(fullState.branch) || null
244
+ }),
245
+ current_phase: compactRecord({
246
+ stage: state.current_stage ?? null,
247
+ checkpoint: state.last_checkpoint ?? packet?.checkpoint ?? null,
248
+ latest_event: latestEvent?.kind ?? null,
249
+ elapsed_ms: elapsedMs(state.created_at, at),
250
+ stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
251
+ iterations: state.iterations
252
+ }),
253
+ owner_next_action: compactRecord({
254
+ owner: ownerFor(state),
255
+ action: actionFor(state),
256
+ checkpoint_kind: packet?.kind || null,
257
+ allowed_decisions: packet?.allowed_decisions,
258
+ retryable: state.status === "running" || state.status === "awaiting_checkpoint",
259
+ reason: state.blocker?.code || packet?.summary || latestEvent?.summary || null
260
+ }),
261
+ evidence_contract: compactRecord({
262
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
263
+ required,
264
+ artifact_contract: artifactContract,
265
+ proof_plan: compactText(state.proof_contract?.proof_plan || fullState.proof_plan, 600),
266
+ stop_condition: compactText(state.proof_contract?.stop_condition, 400)
267
+ }),
268
+ latest_evidence: compactRecord({
269
+ before_url: nonEmptyString(fullState.before_cdn) || state.before_artifact_url || null,
270
+ prod_url: nonEmptyString(fullState.prod_cdn) || state.prod_artifact_url || null,
271
+ after_url: nonEmptyString(fullState.after_cdn) || state.after_artifact_url || null,
272
+ visual_delta: visualDelta || null,
273
+ evidence_issue_code: evidenceIssueCode({ fullRiddleState: fullState, runState: state }) || null,
274
+ proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
275
+ viewport_matrix: viewportMatrix,
276
+ artifacts
277
+ }),
278
+ observability: observabilityFrom(state),
279
+ stop_condition: compactRecord({
280
+ status: state.status,
281
+ terminal: isTerminalStatus(state.status),
282
+ blocker_code: state.blocker?.code || null,
283
+ blocker_message: state.blocker?.message || null,
284
+ proof_decision: state.proof_decision,
285
+ merge_recommendation: state.merge_recommendation,
286
+ monitor_should_continue: !isTerminalStatus(state.status)
287
+ }),
288
+ updated_at: state.updated_at
289
+ };
290
+ }
291
+
292
+ // src/state.ts
293
+ var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
294
+ function timestamp() {
295
+ return (/* @__PURE__ */ new Date()).toISOString();
296
+ }
297
+ function createRunId(createdAt) {
298
+ const stamp = createdAt.replace(/\D/g, "").slice(0, 14) || "unknown";
299
+ const entropy = Math.random().toString(36).slice(2, 8) || "run";
300
+ return `rp_${stamp}_${entropy}`;
301
+ }
302
+ function elapsedMs2(start, end) {
303
+ const startMs = start ? Date.parse(start) : NaN;
304
+ const endMs = end ? Date.parse(end) : NaN;
305
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
306
+ return Math.max(0, endMs - startMs);
307
+ }
308
+ function normalizePrStatus(value) {
309
+ const status = nonEmptyString(value)?.toLowerCase();
310
+ if (status === "merged") return "merged";
311
+ if (status === "open") return "open";
312
+ if (status === "closed") return "closed";
313
+ if (status === "not_found" || status === "not-found") return "not_found";
314
+ if (status === "unavailable") return "unavailable";
315
+ return status || "unknown";
316
+ }
317
+ function normalizePrLifecycleState(input, checkedAt = timestamp()) {
318
+ const value = recordValue(input);
319
+ if (!value) return void 0;
320
+ const cleanup = recordValue(value.cleanup);
321
+ const mergeCommit = nonEmptyString(value.merge_commit) || nonEmptyString(value.mergeCommit) || nonEmptyString(recordValue(value.mergeCommit)?.oid);
322
+ return compactRecord({
323
+ status: normalizePrStatus(value.status || value.state),
324
+ pr_url: nonEmptyString(value.pr_url) || nonEmptyString(value.prUrl) || nonEmptyString(value.url),
325
+ pr_number: nonEmptyString(value.pr_number) || nonEmptyString(value.prNumber) || (typeof value.number === "number" ? String(value.number) : void 0),
326
+ repo: nonEmptyString(value.repo) || nonEmptyString(value.repository),
327
+ head_branch: nonEmptyString(value.head_branch) || nonEmptyString(value.headBranch) || nonEmptyString(value.headRefName),
328
+ base_branch: nonEmptyString(value.base_branch) || nonEmptyString(value.baseBranch) || nonEmptyString(value.baseRefName),
329
+ merge_commit: mergeCommit,
330
+ merged_at: nonEmptyString(value.merged_at) || nonEmptyString(value.mergedAt),
331
+ closed_at: nonEmptyString(value.closed_at) || nonEmptyString(value.closedAt),
332
+ checked_at: nonEmptyString(value.checked_at) || nonEmptyString(value.checkedAt) || checkedAt,
333
+ source: nonEmptyString(value.source),
334
+ next_action: nonEmptyString(value.next_action) || nonEmptyString(value.nextAction),
335
+ cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
336
+ });
337
+ }
338
+ function normalizeIntegrationContext(input, fallbackSource) {
339
+ const value = recordValue(input);
340
+ if (!value) {
341
+ return fallbackSource ? { source: fallbackSource } : void 0;
342
+ }
343
+ const metadata = recordValue(value.metadata);
344
+ return compactRecord({
345
+ source: nonEmptyString(value.source) || fallbackSource,
346
+ channel_id: nonEmptyString(value.channel_id),
347
+ thread_id: nonEmptyString(value.thread_id),
348
+ message_id: nonEmptyString(value.message_id),
349
+ source_url: nonEmptyString(value.source_url),
350
+ metadata: metadata && Object.keys(metadata).length ? metadata : void 0
351
+ });
352
+ }
353
+ function normalizeRunParams(input) {
354
+ return compactRecord({
355
+ repo: input.repo,
356
+ branch: input.branch,
357
+ change_request: input.change_request,
358
+ commit_message: input.commit_message,
359
+ prod_url: input.prod_url,
360
+ capture_script: input.capture_script,
361
+ success_criteria: input.success_criteria,
362
+ assertions: input.assertions,
363
+ verification_mode: input.verification_mode,
364
+ resume_session: input.resume_session,
365
+ target_image_url: input.target_image_url,
366
+ target_image_hash: input.target_image_hash,
367
+ viewport_matrix: input.viewport_matrix,
368
+ deterministic_setup: input.deterministic_setup,
369
+ reference: input.reference,
370
+ base_branch: input.base_branch,
371
+ before_ref: input.before_ref,
372
+ allow_static_preview_fallback: input.allow_static_preview_fallback,
373
+ context: input.context,
374
+ reviewer: input.reviewer,
375
+ mode: input.mode,
376
+ implementation_mode: input.implementation_mode,
377
+ require_diff: input.require_diff,
378
+ allow_code_changes: input.allow_code_changes,
379
+ build_command: input.build_command,
380
+ build_output: input.build_output,
381
+ server_image: input.server_image,
382
+ server_command: input.server_command,
383
+ server_port: input.server_port,
384
+ server_path: input.server_path,
385
+ use_auth: input.use_auth,
386
+ auth_localStorage_json: input.auth_localStorage_json,
387
+ auth_cookies_json: input.auth_cookies_json,
388
+ auth_headers_json: input.auth_headers_json,
389
+ color_scheme: input.color_scheme,
390
+ wait_for_selector: input.wait_for_selector,
391
+ ship_mode: input.ship_mode,
392
+ leave_draft: input.leave_draft,
393
+ engine_state_path: input.engine_state_path,
394
+ harness_state_path: input.harness_state_path,
395
+ riddle_engine_module_url: input.riddle_engine_module_url,
396
+ max_iterations: input.max_iterations,
397
+ auto_approve: input.auto_approve,
398
+ dry_run: input.dry_run,
399
+ integration_context: normalizeIntegrationContext(input.integration_context)
400
+ });
401
+ }
402
+ function createRunState(input) {
403
+ const createdAt = input.created_at || timestamp();
404
+ return compactRecord({
405
+ version: RIDDLE_PROOF_RUN_STATE_VERSION,
406
+ run_id: input.run_id || createRunId(createdAt),
407
+ state_path: input.state_path,
408
+ worktree_path: input.worktree_path,
409
+ branch: input.branch || input.request.branch,
410
+ current_stage: input.current_stage ?? null,
411
+ stage_started_at: input.stage_started_at ?? null,
412
+ status: input.status || "running",
413
+ created_at: createdAt,
414
+ updated_at: input.updated_at || createdAt,
415
+ request: normalizeRunParams(input.request),
416
+ iterations: input.iterations ?? 0,
417
+ last_checkpoint: input.last_checkpoint ?? null,
418
+ checkpoint_packet: input.checkpoint_packet,
419
+ checkpoint_summary: input.checkpoint_summary,
420
+ state_paths: input.state_paths,
421
+ proof_contract: input.proof_contract,
422
+ run_card: input.run_card,
423
+ checkpoint_history: input.checkpoint_history,
424
+ events: input.events ? [...input.events] : []
425
+ });
426
+ }
427
+ function appendRunEvent(state, input) {
428
+ const event = {
429
+ ts: input.ts || timestamp(),
430
+ kind: input.kind,
431
+ checkpoint: input.checkpoint,
432
+ stage: input.stage,
433
+ summary: input.summary,
434
+ details: input.details
435
+ };
436
+ state.events.push(compactRecord({
437
+ ts: event.ts,
438
+ kind: event.kind,
439
+ checkpoint: event.checkpoint,
440
+ stage: event.stage,
441
+ summary: event.summary,
442
+ details: event.details
443
+ }));
444
+ if (input.checkpoint !== void 0) state.last_checkpoint = input.checkpoint;
445
+ if (input.stage !== void 0) {
446
+ if (state.current_stage !== input.stage) state.stage_started_at = event.ts;
447
+ state.current_stage = input.stage;
448
+ }
449
+ state.updated_at = event.ts;
450
+ return state;
451
+ }
452
+ function appendStageHeartbeat(state, input) {
453
+ const at = input.ts || timestamp();
454
+ return appendRunEvent(state, {
455
+ ts: at,
456
+ kind: "stage.heartbeat",
457
+ checkpoint: input.checkpoint || `${input.stage}_heartbeat`,
458
+ stage: input.stage,
459
+ summary: input.summary || `${input.stage} stage is active.`,
460
+ details: compactRecord({
461
+ elapsed_ms: elapsedMs2(state.created_at, at),
462
+ stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
463
+ wait_reason: input.wait_reason,
464
+ blocker: input.blocker,
465
+ ...input.details
466
+ })
467
+ });
468
+ }
469
+ function createRunStatusSnapshot(state, at = timestamp()) {
470
+ const latestEvent = state.events[state.events.length - 1];
471
+ const runId = state.run_id || "unknown";
472
+ return compactRecord({
473
+ run_id: runId,
474
+ status: state.status,
475
+ is_terminal: isTerminalStatus(state.status),
476
+ monitor_should_continue: !isTerminalStatus(state.status),
477
+ current_stage: state.current_stage ?? null,
478
+ state_path: state.state_path ?? null,
479
+ worktree_path: state.worktree_path ?? null,
480
+ branch: state.branch ?? null,
481
+ pr_url: state.pr_url ?? null,
482
+ pr_branch: state.pr_branch ?? null,
483
+ pr_state: state.pr_state,
484
+ ci_status: state.ci_status,
485
+ ship_commit: state.ship_commit,
486
+ ship_remote_head: state.ship_remote_head,
487
+ merge_commit: state.merge_commit,
488
+ merged_at: state.merged_at,
489
+ proof_comment_url: state.proof_comment_url,
490
+ cleanup_report: state.cleanup_report,
491
+ iterations: state.iterations,
492
+ last_checkpoint: state.last_checkpoint ?? null,
493
+ updated_at: state.updated_at,
494
+ elapsed_ms: elapsedMs2(state.created_at, at),
495
+ stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
496
+ blocker: state.blocker,
497
+ checkpoint_packet: state.checkpoint_packet,
498
+ checkpoint_summary: state.checkpoint_summary,
499
+ state_paths: state.state_paths,
500
+ proof_contract: state.proof_contract,
501
+ run_card: state.run_card || createRiddleProofRunCard(state, { at }),
502
+ viewport_matrix_status: state.viewport_matrix_status,
503
+ latest_event: latestEvent
504
+ });
505
+ }
506
+ function setRunStatus(state, status, at = timestamp()) {
507
+ state.status = status;
508
+ state.ok = status !== "blocked" && status !== "failed";
509
+ state.updated_at = at;
510
+ return state;
511
+ }
512
+ function applyPrLifecycleState(state, input, at = timestamp()) {
513
+ const prState = normalizePrLifecycleState(input, at);
514
+ if (!prState) return state;
515
+ state.pr_state = prState;
516
+ if (prState.pr_url) state.pr_url = prState.pr_url;
517
+ if (prState.head_branch) state.pr_branch = prState.head_branch;
518
+ if (prState.merge_commit) state.merge_commit = prState.merge_commit;
519
+ if (prState.merged_at) state.merged_at = prState.merged_at;
520
+ if (prState.cleanup) state.cleanup_report = prState.cleanup;
521
+ if (prState.status === "merged") {
522
+ state.finalized = true;
523
+ state.status = "completed";
524
+ state.ok = true;
525
+ }
526
+ state.updated_at = at;
527
+ return state;
528
+ }
529
+ // Annotate the CommonJS export names for ESM import in node:
530
+ 0 && (module.exports = {
531
+ RIDDLE_PROOF_RUN_STATE_VERSION,
532
+ appendRunEvent,
533
+ appendStageHeartbeat,
534
+ applyPrLifecycleState,
535
+ createRunState,
536
+ createRunStatusSnapshot,
537
+ normalizeIntegrationContext,
538
+ normalizePrLifecycleState,
539
+ normalizeRunParams,
540
+ setRunStatus
541
+ });
@@ -0,0 +1,2 @@
1
+ export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, appendStageHeartbeat, applyPrLifecycleState, createRunState, createRunStatusSnapshot, normalizeIntegrationContext, normalizePrLifecycleState, normalizeRunParams, setRunStatus } from '../state.cjs';
2
+ import '../types.cjs';
@@ -0,0 +1,2 @@
1
+ export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, appendStageHeartbeat, applyPrLifecycleState, createRunState, createRunStatusSnapshot, normalizeIntegrationContext, normalizePrLifecycleState, normalizeRunParams, setRunStatus } from '../state.js';
2
+ import '../types.js';
@@ -0,0 +1,28 @@
1
+ import {
2
+ RIDDLE_PROOF_RUN_STATE_VERSION,
3
+ appendRunEvent,
4
+ appendStageHeartbeat,
5
+ applyPrLifecycleState,
6
+ createRunState,
7
+ createRunStatusSnapshot,
8
+ normalizeIntegrationContext,
9
+ normalizePrLifecycleState,
10
+ normalizeRunParams,
11
+ setRunStatus
12
+ } from "../chunk-OHJQRDST.js";
13
+ import "../chunk-Y2KTBACQ.js";
14
+ import "../chunk-2CFVREFI.js";
15
+ import "../chunk-VY4Y5U57.js";
16
+ import "../chunk-MLKGABMK.js";
17
+ export {
18
+ RIDDLE_PROOF_RUN_STATE_VERSION,
19
+ appendRunEvent,
20
+ appendStageHeartbeat,
21
+ applyPrLifecycleState,
22
+ createRunState,
23
+ createRunStatusSnapshot,
24
+ normalizeIntegrationContext,
25
+ normalizePrLifecycleState,
26
+ normalizeRunParams,
27
+ setRunStatus
28
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/spec/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1 @@
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, RiddleProofRunCard, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatePaths, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofViewportCapture, RiddleProofViewportMatrixStatus, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from '../types.cjs';
@@ -0,0 +1 @@
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, RiddleProofRunCard, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofRunStatusSnapshot, RiddleProofStage, RiddleProofStatePaths, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, RiddleProofViewportCapture, RiddleProofViewportMatrixStatus, RiddleProofVisualSession, RiddleProofVisualSessionFingerprintBasis, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from '../types.js';
@@ -0,0 +1 @@
1
+ import "../chunk-6F4PWJZI.js";
package/dist/state.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  import "./chunk-Y2KTBACQ.js";
14
14
  import "./chunk-2CFVREFI.js";
15
15
  import "./chunk-VY4Y5U57.js";
16
+ import "./chunk-MLKGABMK.js";
16
17
  export {
17
18
  RIDDLE_PROOF_RUN_STATE_VERSION,
18
19
  appendRunEvent,