@riddledc/riddle-proof 0.7.226 → 0.8.1

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 (132) 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-QUAZAMOM.js → chunk-IWLQQ5S5.js} +12 -2
  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.d.cts +1 -0
  56. package/dist/cli.d.ts +1 -0
  57. package/dist/cli.js +8 -4139
  58. package/dist/codex-exec-agent.d.cts +1 -1
  59. package/dist/codex-exec-agent.d.ts +1 -1
  60. package/dist/codex-exec-agent.js +1 -0
  61. package/dist/diagnostics.js +1 -0
  62. package/dist/engine-harness-CMACHP6A.d.ts +96 -0
  63. package/dist/engine-harness-LBfqbFSe.d.cts +96 -0
  64. package/dist/engine-harness.d.cts +2 -79
  65. package/dist/engine-harness.d.ts +2 -79
  66. package/dist/engine-harness.js +3 -2
  67. package/dist/index.d.cts +2 -2
  68. package/dist/index.d.ts +2 -2
  69. package/dist/index.js +4 -3
  70. package/dist/local-agent.d.cts +1 -1
  71. package/dist/local-agent.d.ts +1 -1
  72. package/dist/local-agent.js +1 -0
  73. package/dist/openclaw.js +8 -107
  74. package/dist/playability.js +1 -0
  75. package/dist/profile/index.cjs +9403 -0
  76. package/dist/profile/index.d.cts +2 -0
  77. package/dist/profile/index.d.ts +2 -0
  78. package/dist/profile/index.js +53 -0
  79. package/dist/profile.js +1 -0
  80. package/dist/proof-run-core-CE0jx7wL.d.cts +359 -0
  81. package/dist/proof-run-core-CE0jx7wL.d.ts +359 -0
  82. package/dist/proof-run-core.d.cts +1 -322
  83. package/dist/proof-run-core.d.ts +1 -322
  84. package/dist/proof-run-core.js +2 -1
  85. package/dist/proof-run-engine-CSSc0mNn.d.ts +764 -0
  86. package/dist/proof-run-engine-HSRpUeBi.d.cts +764 -0
  87. package/dist/proof-run-engine.d.cts +2 -757
  88. package/dist/proof-run-engine.d.ts +2 -757
  89. package/dist/proof-run-engine.js +5 -1885
  90. package/dist/proof-session.js +1 -0
  91. package/dist/result.js +1 -0
  92. package/dist/riddle-client.js +1 -0
  93. package/dist/run-card.js +1 -0
  94. package/dist/runner-4LJ5z0D-.d.cts +29 -0
  95. package/dist/runner-BdQpOkZD.d.ts +29 -0
  96. package/dist/runner.d.cts +2 -22
  97. package/dist/runner.d.ts +2 -22
  98. package/dist/runner.js +3 -2
  99. package/dist/runtime/index.cjs +528 -0
  100. package/dist/runtime/index.d.cts +1 -0
  101. package/dist/runtime/index.d.ts +1 -0
  102. package/dist/runtime/index.js +37 -0
  103. package/dist/runtime/riddle-client.cjs +528 -0
  104. package/dist/runtime/riddle-client.d.cts +1 -0
  105. package/dist/runtime/riddle-client.d.ts +1 -0
  106. package/dist/runtime/riddle-client.js +37 -0
  107. package/dist/spec/checkpoint.cjs +807 -0
  108. package/dist/spec/checkpoint.d.cts +2 -0
  109. package/dist/spec/checkpoint.d.ts +2 -0
  110. package/dist/spec/checkpoint.js +34 -0
  111. package/dist/spec/index.cjs +1510 -0
  112. package/dist/spec/index.d.cts +5 -0
  113. package/dist/spec/index.d.ts +5 -0
  114. package/dist/spec/index.js +80 -0
  115. package/dist/spec/result.cjs +259 -0
  116. package/dist/spec/result.d.cts +2 -0
  117. package/dist/spec/result.d.ts +2 -0
  118. package/dist/spec/result.js +21 -0
  119. package/dist/spec/run-card.cjs +287 -0
  120. package/dist/spec/run-card.d.cts +2 -0
  121. package/dist/spec/run-card.d.ts +2 -0
  122. package/dist/spec/run-card.js +11 -0
  123. package/dist/spec/state.cjs +541 -0
  124. package/dist/spec/state.d.cts +2 -0
  125. package/dist/spec/state.d.ts +2 -0
  126. package/dist/spec/state.js +28 -0
  127. package/dist/spec/types.cjs +18 -0
  128. package/dist/spec/types.d.cts +1 -0
  129. package/dist/spec/types.d.ts +1 -0
  130. package/dist/spec/types.js +1 -0
  131. package/dist/state.js +1 -0
  132. package/package.json +95 -2
@@ -0,0 +1,833 @@
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/advanced/runner.ts
31
+ var runner_exports = {};
32
+ __export(runner_exports, {
33
+ runRiddleProof: () => runRiddleProof
34
+ });
35
+ module.exports = __toCommonJS(runner_exports);
36
+
37
+ // src/result.ts
38
+ function isSuccessfulStatus(status) {
39
+ return status !== "blocked" && status !== "failed";
40
+ }
41
+ function compactRecord(input) {
42
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0 && value !== null && value !== ""));
43
+ }
44
+ function nonEmptyString(value) {
45
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
46
+ }
47
+ function recordValue(value) {
48
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
49
+ }
50
+ function applyTerminalMetadata(state, metadata) {
51
+ if (metadata.pr_state) {
52
+ state.pr_state = metadata.pr_state;
53
+ if (metadata.pr_state.pr_url) state.pr_url = metadata.pr_state.pr_url;
54
+ if (metadata.pr_state.head_branch) state.pr_branch = metadata.pr_state.head_branch;
55
+ if (metadata.pr_state.merge_commit) state.merge_commit = metadata.pr_state.merge_commit;
56
+ if (metadata.pr_state.merged_at) state.merged_at = metadata.pr_state.merged_at;
57
+ if (metadata.pr_state.cleanup) state.cleanup_report = metadata.pr_state.cleanup;
58
+ if (metadata.pr_state.status === "merged") state.finalized = true;
59
+ }
60
+ const prUrl = nonEmptyString(metadata.pr_url);
61
+ if (prUrl) state.pr_url = prUrl;
62
+ const prBranch = nonEmptyString(metadata.pr_branch);
63
+ if (prBranch) state.pr_branch = prBranch;
64
+ if (typeof metadata.marked_ready === "boolean") state.marked_ready = metadata.marked_ready;
65
+ if (typeof metadata.left_draft === "boolean") state.left_draft = metadata.left_draft;
66
+ const ciStatus = nonEmptyString(metadata.ci_status);
67
+ if (ciStatus) state.ci_status = ciStatus;
68
+ const shipCommit = nonEmptyString(metadata.ship_commit);
69
+ if (shipCommit) state.ship_commit = shipCommit;
70
+ const shipRemoteHead = nonEmptyString(metadata.ship_remote_head);
71
+ if (shipRemoteHead) state.ship_remote_head = shipRemoteHead;
72
+ const mergeCommit = nonEmptyString(metadata.merge_commit);
73
+ if (mergeCommit) state.merge_commit = mergeCommit;
74
+ const mergedAt = nonEmptyString(metadata.merged_at);
75
+ if (mergedAt) state.merged_at = mergedAt;
76
+ const proofCommentUrl = nonEmptyString(metadata.proof_comment_url);
77
+ if (proofCommentUrl) state.proof_comment_url = proofCommentUrl;
78
+ const beforeArtifactUrl = nonEmptyString(metadata.before_artifact_url);
79
+ if (beforeArtifactUrl) state.before_artifact_url = beforeArtifactUrl;
80
+ const prodArtifactUrl = nonEmptyString(metadata.prod_artifact_url);
81
+ if (prodArtifactUrl) state.prod_artifact_url = prodArtifactUrl;
82
+ const afterArtifactUrl = nonEmptyString(metadata.after_artifact_url);
83
+ if (afterArtifactUrl) state.after_artifact_url = afterArtifactUrl;
84
+ const shipReport = recordValue(metadata.ship_report);
85
+ if (shipReport) state.ship_report = shipReport;
86
+ const cleanupReport = recordValue(metadata.cleanup_report);
87
+ if (cleanupReport) state.cleanup_report = cleanupReport;
88
+ const notification = recordValue(metadata.notification);
89
+ if (notification) state.notification = notification;
90
+ const proofDecision = nonEmptyString(metadata.proof_decision);
91
+ if (proofDecision) state.proof_decision = proofDecision;
92
+ const mergeRecommendation = nonEmptyString(metadata.merge_recommendation);
93
+ if (mergeRecommendation) state.merge_recommendation = mergeRecommendation;
94
+ if (typeof metadata.finalized === "boolean") state.finalized = metadata.finalized;
95
+ return state;
96
+ }
97
+ function createRunResult(input) {
98
+ const status = input.status || input.state.status;
99
+ const ok = isSuccessfulStatus(status);
100
+ const state = input.metadata ? applyTerminalMetadata(input.state, input.metadata) : input.state;
101
+ state.status = status;
102
+ state.ok = ok;
103
+ return compactRecord({
104
+ ok,
105
+ status,
106
+ run_id: state.run_id,
107
+ state_path: input.state_path ?? state.state_path ?? null,
108
+ worktree_path: state.worktree_path ?? null,
109
+ branch: state.branch ?? null,
110
+ current_stage: state.current_stage ?? null,
111
+ iterations: state.iterations,
112
+ last_checkpoint: state.last_checkpoint ?? null,
113
+ last_summary: input.last_summary ?? null,
114
+ event_count: state.events.length,
115
+ pr_url: state.pr_url,
116
+ pr_branch: state.pr_branch,
117
+ pr_state: state.pr_state,
118
+ marked_ready: state.marked_ready,
119
+ left_draft: state.left_draft,
120
+ ci_status: state.ci_status,
121
+ ship_commit: state.ship_commit,
122
+ ship_remote_head: state.ship_remote_head,
123
+ merge_commit: state.merge_commit,
124
+ merged_at: state.merged_at,
125
+ proof_comment_url: state.proof_comment_url,
126
+ before_artifact_url: state.before_artifact_url,
127
+ prod_artifact_url: state.prod_artifact_url,
128
+ after_artifact_url: state.after_artifact_url,
129
+ ship_report: state.ship_report,
130
+ cleanup_report: state.cleanup_report,
131
+ notification: state.notification,
132
+ proof_decision: state.proof_decision,
133
+ merge_recommendation: state.merge_recommendation,
134
+ finalized: state.finalized,
135
+ blocker: state.blocker,
136
+ checkpoint_packet: state.checkpoint_packet,
137
+ checkpoint_summary: state.checkpoint_summary,
138
+ state_paths: state.state_paths,
139
+ proof_contract: state.proof_contract,
140
+ run_card: state.run_card,
141
+ proof_session: state.proof_session,
142
+ viewport_matrix_status: state.viewport_matrix_status,
143
+ evidence_bundle: input.evidence_bundle,
144
+ raw: input.raw
145
+ });
146
+ }
147
+
148
+ // src/state.ts
149
+ var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
150
+ function timestamp() {
151
+ return (/* @__PURE__ */ new Date()).toISOString();
152
+ }
153
+ function createRunId(createdAt) {
154
+ const stamp = createdAt.replace(/\D/g, "").slice(0, 14) || "unknown";
155
+ const entropy = Math.random().toString(36).slice(2, 8) || "run";
156
+ return `rp_${stamp}_${entropy}`;
157
+ }
158
+ function elapsedMs(start, end) {
159
+ const startMs = start ? Date.parse(start) : NaN;
160
+ const endMs = end ? Date.parse(end) : NaN;
161
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
162
+ return Math.max(0, endMs - startMs);
163
+ }
164
+ function normalizeIntegrationContext(input, fallbackSource) {
165
+ const value = recordValue(input);
166
+ if (!value) {
167
+ return fallbackSource ? { source: fallbackSource } : void 0;
168
+ }
169
+ const metadata = recordValue(value.metadata);
170
+ return compactRecord({
171
+ source: nonEmptyString(value.source) || fallbackSource,
172
+ channel_id: nonEmptyString(value.channel_id),
173
+ thread_id: nonEmptyString(value.thread_id),
174
+ message_id: nonEmptyString(value.message_id),
175
+ source_url: nonEmptyString(value.source_url),
176
+ metadata: metadata && Object.keys(metadata).length ? metadata : void 0
177
+ });
178
+ }
179
+ function normalizeRunParams(input) {
180
+ return compactRecord({
181
+ repo: input.repo,
182
+ branch: input.branch,
183
+ change_request: input.change_request,
184
+ commit_message: input.commit_message,
185
+ prod_url: input.prod_url,
186
+ capture_script: input.capture_script,
187
+ success_criteria: input.success_criteria,
188
+ assertions: input.assertions,
189
+ verification_mode: input.verification_mode,
190
+ resume_session: input.resume_session,
191
+ target_image_url: input.target_image_url,
192
+ target_image_hash: input.target_image_hash,
193
+ viewport_matrix: input.viewport_matrix,
194
+ deterministic_setup: input.deterministic_setup,
195
+ reference: input.reference,
196
+ base_branch: input.base_branch,
197
+ before_ref: input.before_ref,
198
+ allow_static_preview_fallback: input.allow_static_preview_fallback,
199
+ context: input.context,
200
+ reviewer: input.reviewer,
201
+ mode: input.mode,
202
+ implementation_mode: input.implementation_mode,
203
+ require_diff: input.require_diff,
204
+ allow_code_changes: input.allow_code_changes,
205
+ build_command: input.build_command,
206
+ build_output: input.build_output,
207
+ server_image: input.server_image,
208
+ server_command: input.server_command,
209
+ server_port: input.server_port,
210
+ server_path: input.server_path,
211
+ use_auth: input.use_auth,
212
+ auth_localStorage_json: input.auth_localStorage_json,
213
+ auth_cookies_json: input.auth_cookies_json,
214
+ auth_headers_json: input.auth_headers_json,
215
+ color_scheme: input.color_scheme,
216
+ wait_for_selector: input.wait_for_selector,
217
+ ship_mode: input.ship_mode,
218
+ leave_draft: input.leave_draft,
219
+ engine_state_path: input.engine_state_path,
220
+ harness_state_path: input.harness_state_path,
221
+ riddle_engine_module_url: input.riddle_engine_module_url,
222
+ max_iterations: input.max_iterations,
223
+ auto_approve: input.auto_approve,
224
+ dry_run: input.dry_run,
225
+ integration_context: normalizeIntegrationContext(input.integration_context)
226
+ });
227
+ }
228
+ function createRunState(input) {
229
+ const createdAt = input.created_at || timestamp();
230
+ return compactRecord({
231
+ version: RIDDLE_PROOF_RUN_STATE_VERSION,
232
+ run_id: input.run_id || createRunId(createdAt),
233
+ state_path: input.state_path,
234
+ worktree_path: input.worktree_path,
235
+ branch: input.branch || input.request.branch,
236
+ current_stage: input.current_stage ?? null,
237
+ stage_started_at: input.stage_started_at ?? null,
238
+ status: input.status || "running",
239
+ created_at: createdAt,
240
+ updated_at: input.updated_at || createdAt,
241
+ request: normalizeRunParams(input.request),
242
+ iterations: input.iterations ?? 0,
243
+ last_checkpoint: input.last_checkpoint ?? null,
244
+ checkpoint_packet: input.checkpoint_packet,
245
+ checkpoint_summary: input.checkpoint_summary,
246
+ state_paths: input.state_paths,
247
+ proof_contract: input.proof_contract,
248
+ run_card: input.run_card,
249
+ checkpoint_history: input.checkpoint_history,
250
+ events: input.events ? [...input.events] : []
251
+ });
252
+ }
253
+ function appendRunEvent(state, input) {
254
+ const event = {
255
+ ts: input.ts || timestamp(),
256
+ kind: input.kind,
257
+ checkpoint: input.checkpoint,
258
+ stage: input.stage,
259
+ summary: input.summary,
260
+ details: input.details
261
+ };
262
+ state.events.push(compactRecord({
263
+ ts: event.ts,
264
+ kind: event.kind,
265
+ checkpoint: event.checkpoint,
266
+ stage: event.stage,
267
+ summary: event.summary,
268
+ details: event.details
269
+ }));
270
+ if (input.checkpoint !== void 0) state.last_checkpoint = input.checkpoint;
271
+ if (input.stage !== void 0) {
272
+ if (state.current_stage !== input.stage) state.stage_started_at = event.ts;
273
+ state.current_stage = input.stage;
274
+ }
275
+ state.updated_at = event.ts;
276
+ return state;
277
+ }
278
+ function appendStageHeartbeat(state, input) {
279
+ const at = input.ts || timestamp();
280
+ return appendRunEvent(state, {
281
+ ts: at,
282
+ kind: "stage.heartbeat",
283
+ checkpoint: input.checkpoint || `${input.stage}_heartbeat`,
284
+ stage: input.stage,
285
+ summary: input.summary || `${input.stage} stage is active.`,
286
+ details: compactRecord({
287
+ elapsed_ms: elapsedMs(state.created_at, at),
288
+ stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
289
+ wait_reason: input.wait_reason,
290
+ blocker: input.blocker,
291
+ ...input.details
292
+ })
293
+ });
294
+ }
295
+ function setRunStatus(state, status, at = timestamp()) {
296
+ state.status = status;
297
+ state.ok = status !== "blocked" && status !== "failed";
298
+ state.updated_at = at;
299
+ return state;
300
+ }
301
+
302
+ // src/proof-run-core.ts
303
+ var import_node_fs = require("fs");
304
+ var import_node_crypto = require("crypto");
305
+ var import_node_path = __toESM(require("path"), 1);
306
+ var import_node_url = require("url");
307
+ var import_meta = {};
308
+ function normalizedMode(value) {
309
+ return typeof value === "string" ? value.trim().toLowerCase() : "";
310
+ }
311
+ function noImplementationModeInput(value) {
312
+ return value && typeof value === "object" ? value : {};
313
+ }
314
+ function noImplementationModeFor(params, state) {
315
+ const input = noImplementationModeInput(params);
316
+ const stateInput = noImplementationModeInput(state);
317
+ const mode = normalizedMode(input.mode ?? input.workflow_mode ?? stateInput.mode ?? stateInput.workflow_mode);
318
+ const implementationMode = normalizedMode(input.implementation_mode ?? stateInput.implementation_mode);
319
+ const requireDiff = input.require_diff ?? stateInput.require_diff;
320
+ const allowCodeChanges = input.allow_code_changes ?? stateInput.allow_code_changes;
321
+ return mode === "audit" || mode === "profile" || implementationMode === "none" || requireDiff === false || allowCodeChanges === false;
322
+ }
323
+ function currentDistDir() {
324
+ const meta = typeof import_meta === "object" ? import_meta : {};
325
+ if (typeof meta.url === "string" && meta.url) {
326
+ return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(meta.url));
327
+ }
328
+ if (typeof __dirname === "string") return __dirname;
329
+ return process.cwd();
330
+ }
331
+ var BUNDLED_RIDDLE_PROOF_DIR = import_node_path.default.resolve(
332
+ currentDistDir(),
333
+ "..",
334
+ "runtime"
335
+ );
336
+
337
+ // src/runner.ts
338
+ function errorDetails(error) {
339
+ if (error instanceof Error) {
340
+ return {
341
+ name: error.name,
342
+ message: error.message
343
+ };
344
+ }
345
+ return { message: String(error) };
346
+ }
347
+ function adapterBlocker(code, message, checkpoint, details) {
348
+ return {
349
+ code,
350
+ message,
351
+ checkpoint,
352
+ details
353
+ };
354
+ }
355
+ function blockRun(input) {
356
+ input.state.blocker = input.blocker;
357
+ appendRunEvent(input.state, {
358
+ kind: "run.blocked",
359
+ checkpoint: input.blocker.checkpoint,
360
+ stage: input.stage,
361
+ summary: input.blocker.message,
362
+ details: {
363
+ code: input.blocker.code,
364
+ ...input.blocker.details
365
+ }
366
+ });
367
+ setRunStatus(input.state, "blocked");
368
+ return createRunResult({
369
+ state: input.state,
370
+ status: "blocked",
371
+ last_summary: input.blocker.message,
372
+ evidence_bundle: input.evidence_bundle,
373
+ raw: input.raw
374
+ });
375
+ }
376
+ function shouldIterate(assessment) {
377
+ const nextStage = assessment.continue_with_stage || assessment.recommended_stage;
378
+ return nextStage === "implement" || nextStage === "author";
379
+ }
380
+ async function notifyIfConfigured(input) {
381
+ if (!input.notification) return input.result;
382
+ try {
383
+ const notification = await input.notification.notify({
384
+ state: input.state,
385
+ result: input.result
386
+ });
387
+ input.state.notification = notification;
388
+ appendRunEvent(input.state, {
389
+ kind: "notification.completed",
390
+ checkpoint: "notification_completed",
391
+ stage: "notify",
392
+ summary: "Integration notification completed."
393
+ });
394
+ } catch (error) {
395
+ appendRunEvent(input.state, {
396
+ kind: "notification.failed",
397
+ checkpoint: "notification_failed",
398
+ stage: "notify",
399
+ summary: "Integration notification failed.",
400
+ details: errorDetails(error)
401
+ });
402
+ }
403
+ return createRunResult({
404
+ state: input.state,
405
+ status: input.state.status,
406
+ last_summary: input.result.last_summary,
407
+ evidence_bundle: input.result.evidence_bundle,
408
+ raw: input.result.raw
409
+ });
410
+ }
411
+ async function runRiddleProof(input) {
412
+ const state = input.state || createRunState({
413
+ request: input.request,
414
+ state_path: input.state_path,
415
+ worktree_path: input.workdir
416
+ });
417
+ const adapters = input.adapters || {};
418
+ const maxIterations = Math.max(1, Math.trunc(input.max_iterations ?? 1));
419
+ appendRunEvent(state, {
420
+ kind: "run.started",
421
+ checkpoint: "run_started",
422
+ stage: "setup",
423
+ summary: "Riddle Proof run started.",
424
+ details: {
425
+ run_id: state.run_id,
426
+ state_path: state.state_path,
427
+ worktree_path: state.worktree_path,
428
+ branch: state.branch,
429
+ max_iterations: maxIterations,
430
+ ship_mode: state.request.ship_mode || "none"
431
+ }
432
+ });
433
+ appendStageHeartbeat(state, {
434
+ stage: "setup",
435
+ summary: "Setup stage is active.",
436
+ details: {
437
+ run_id: state.run_id,
438
+ state_path: state.state_path,
439
+ worktree_path: state.worktree_path,
440
+ branch: state.branch
441
+ }
442
+ });
443
+ let workdir = input.workdir;
444
+ let evidenceContext;
445
+ if (adapters.preflight) {
446
+ appendRunEvent(state, {
447
+ kind: "preflight.started",
448
+ checkpoint: "preflight_started",
449
+ stage: "preflight",
450
+ summary: "Riddle Proof preflight adapter started."
451
+ });
452
+ try {
453
+ const preflight = await adapters.preflight.preflight({ request: state.request, state });
454
+ if (!preflight.ok) {
455
+ return blockRun({
456
+ state,
457
+ stage: "preflight",
458
+ blocker: adapterBlocker(
459
+ "preflight_failed",
460
+ "The preflight adapter found blocking tool or model configuration issues.",
461
+ "preflight_failed",
462
+ {
463
+ blockers: preflight.blockers,
464
+ warnings: preflight.warnings,
465
+ degraded_capabilities: preflight.degraded_capabilities
466
+ }
467
+ ),
468
+ raw: { preflight }
469
+ });
470
+ }
471
+ appendRunEvent(state, {
472
+ kind: "preflight.completed",
473
+ checkpoint: "preflight_completed",
474
+ stage: "preflight",
475
+ summary: "Riddle Proof preflight adapter completed.",
476
+ details: {
477
+ warnings: preflight.warnings,
478
+ degraded_capabilities: preflight.degraded_capabilities
479
+ }
480
+ });
481
+ } catch (error) {
482
+ return blockRun({
483
+ state,
484
+ stage: "preflight",
485
+ blocker: adapterBlocker("preflight_exception", "The preflight adapter threw an exception.", "preflight_failed", errorDetails(error))
486
+ });
487
+ }
488
+ }
489
+ if (adapters.setup) {
490
+ appendRunEvent(state, {
491
+ kind: "setup.started",
492
+ checkpoint: "setup_started",
493
+ stage: "setup",
494
+ summary: "Riddle Proof setup adapter started."
495
+ });
496
+ try {
497
+ const setup = await adapters.setup.setup({ request: state.request, state });
498
+ if (!setup.ok) {
499
+ return blockRun({
500
+ state,
501
+ stage: "setup",
502
+ blocker: adapterBlocker(
503
+ "setup_failed",
504
+ "The setup adapter did not complete successfully.",
505
+ "setup_failed",
506
+ { blockers: setup.blockers }
507
+ ),
508
+ raw: { setup }
509
+ });
510
+ }
511
+ workdir = setup.worktree_path || setup.workdir || workdir;
512
+ state.worktree_path = setup.worktree_path || setup.workdir || state.worktree_path;
513
+ state.branch = setup.branch || state.branch;
514
+ evidenceContext = setup.evidence_context;
515
+ appendRunEvent(state, {
516
+ kind: "setup.completed",
517
+ checkpoint: "setup_completed",
518
+ stage: "setup",
519
+ summary: "Riddle Proof setup adapter completed.",
520
+ details: {
521
+ has_workdir: Boolean(workdir),
522
+ worktree_path: state.worktree_path,
523
+ branch: state.branch,
524
+ cleanup_policy: setup.cleanup_policy,
525
+ has_evidence_context: Boolean(evidenceContext)
526
+ }
527
+ });
528
+ } catch (error) {
529
+ return blockRun({
530
+ state,
531
+ stage: "setup",
532
+ blocker: adapterBlocker("setup_exception", "The setup adapter threw an exception.", "setup_failed", errorDetails(error))
533
+ });
534
+ }
535
+ }
536
+ const changeRequest = state.request.change_request?.trim();
537
+ const noImplementationMode = noImplementationModeFor(state.request);
538
+ if (!changeRequest) {
539
+ return blockRun({
540
+ state,
541
+ stage: "setup",
542
+ blocker: adapterBlocker("change_request_required", "A change request is required before implementation.", "request_invalid")
543
+ });
544
+ }
545
+ if (!noImplementationMode && !workdir) {
546
+ return blockRun({
547
+ state,
548
+ stage: "setup",
549
+ blocker: adapterBlocker("workdir_not_configured", "A workdir or setup adapter result is required before implementation.", "setup_required")
550
+ });
551
+ }
552
+ if (!noImplementationMode && !adapters.implementation) {
553
+ return blockRun({
554
+ state,
555
+ stage: "implement",
556
+ blocker: adapterBlocker("implementation_adapter_not_configured", "An implementation adapter is required to change code.", "implementation_required")
557
+ });
558
+ }
559
+ if (!adapters.proof) {
560
+ return blockRun({
561
+ state,
562
+ stage: "prove",
563
+ blocker: adapterBlocker("proof_adapter_not_configured", "A proof adapter is required to capture evidence.", "proof_required")
564
+ });
565
+ }
566
+ if (!adapters.judge) {
567
+ return blockRun({
568
+ state,
569
+ stage: "verify",
570
+ blocker: adapterBlocker("judge_adapter_not_configured", "A judge adapter is required to assess proof.", "judge_required")
571
+ });
572
+ }
573
+ let implementation;
574
+ let evidenceBundle;
575
+ let assessment;
576
+ for (let attempt = 0; attempt < maxIterations; attempt += 1) {
577
+ state.iterations += 1;
578
+ if (noImplementationMode) {
579
+ state.implementation_status = "not_required";
580
+ appendRunEvent(state, {
581
+ kind: "implementation.skipped",
582
+ checkpoint: "implementation_not_required",
583
+ stage: "implement",
584
+ summary: "Implementation stage skipped because audit/no-diff mode disables code changes.",
585
+ details: { iteration: state.iterations }
586
+ });
587
+ } else {
588
+ appendStageHeartbeat(state, {
589
+ stage: "implement",
590
+ summary: "Implementation stage is active.",
591
+ details: { iteration: state.iterations }
592
+ });
593
+ appendRunEvent(state, {
594
+ kind: "implementation.started",
595
+ checkpoint: "implementation_started",
596
+ stage: "implement",
597
+ summary: "Implementation adapter started.",
598
+ details: { iteration: state.iterations }
599
+ });
600
+ try {
601
+ implementation = await adapters.implementation.implement({
602
+ workdir,
603
+ change_request: changeRequest,
604
+ evidence_context: evidenceContext,
605
+ state
606
+ });
607
+ } catch (error) {
608
+ return blockRun({
609
+ state,
610
+ stage: "implement",
611
+ blocker: adapterBlocker("implementation_exception", "The implementation adapter threw an exception.", "implementation_failed", errorDetails(error)),
612
+ evidence_bundle: evidenceBundle
613
+ });
614
+ }
615
+ if (!implementation.ok) {
616
+ return blockRun({
617
+ state,
618
+ stage: "implement",
619
+ blocker: adapterBlocker(
620
+ "implementation_failed",
621
+ "The implementation adapter did not complete successfully.",
622
+ "implementation_failed",
623
+ { blockers: implementation.blockers }
624
+ ),
625
+ evidence_bundle: evidenceBundle,
626
+ raw: { implementation }
627
+ });
628
+ }
629
+ appendRunEvent(state, {
630
+ kind: "implementation.completed",
631
+ checkpoint: "implementation_completed",
632
+ stage: "implement",
633
+ summary: "Implementation adapter completed.",
634
+ details: {
635
+ changed_files: implementation.changed_files,
636
+ tests_run: implementation.tests_run
637
+ }
638
+ });
639
+ }
640
+ appendStageHeartbeat(state, {
641
+ stage: "prove",
642
+ summary: "Proof capture stage is active.",
643
+ details: {
644
+ verification_mode: state.request.verification_mode
645
+ }
646
+ });
647
+ appendRunEvent(state, {
648
+ kind: "proof.started",
649
+ checkpoint: "proof_started",
650
+ stage: "prove",
651
+ summary: "Proof adapter started."
652
+ });
653
+ try {
654
+ const proof = await adapters.proof.prove({
655
+ state,
656
+ implementation,
657
+ evidence_context: evidenceContext
658
+ });
659
+ if (!proof.ok || !proof.evidence_bundle) {
660
+ return blockRun({
661
+ state,
662
+ stage: "prove",
663
+ blocker: adapterBlocker(
664
+ "proof_failed",
665
+ "The proof adapter did not produce a usable evidence bundle.",
666
+ "proof_failed",
667
+ { blockers: proof.blockers }
668
+ ),
669
+ raw: { proof }
670
+ });
671
+ }
672
+ evidenceBundle = proof.evidence_bundle;
673
+ appendRunEvent(state, {
674
+ kind: "proof.completed",
675
+ checkpoint: "proof_completed",
676
+ stage: "prove",
677
+ summary: "Proof adapter completed.",
678
+ details: {
679
+ verification_mode: evidenceBundle.verification_mode,
680
+ artifact_count: evidenceBundle.artifacts?.length ?? 0
681
+ }
682
+ });
683
+ } catch (error) {
684
+ return blockRun({
685
+ state,
686
+ stage: "prove",
687
+ blocker: adapterBlocker("proof_exception", "The proof adapter threw an exception.", "proof_failed", errorDetails(error))
688
+ });
689
+ }
690
+ appendRunEvent(state, {
691
+ kind: "judge.started",
692
+ checkpoint: "judge_started",
693
+ stage: "verify",
694
+ summary: "Judge adapter started."
695
+ });
696
+ appendStageHeartbeat(state, {
697
+ stage: "verify",
698
+ summary: "Verification stage is active.",
699
+ details: {
700
+ verification_mode: evidenceBundle.verification_mode
701
+ }
702
+ });
703
+ try {
704
+ assessment = await adapters.judge.assessProof({ state, evidence_bundle: evidenceBundle });
705
+ state.proof_decision = assessment.decision;
706
+ appendRunEvent(state, {
707
+ kind: "judge.completed",
708
+ checkpoint: "judge_completed",
709
+ stage: "verify",
710
+ summary: assessment.summary,
711
+ details: {
712
+ decision: assessment.decision,
713
+ recommended_stage: assessment.recommended_stage,
714
+ continue_with_stage: assessment.continue_with_stage,
715
+ reasons: assessment.reasons
716
+ }
717
+ });
718
+ } catch (error) {
719
+ return blockRun({
720
+ state,
721
+ stage: "verify",
722
+ blocker: adapterBlocker("judge_exception", "The judge adapter threw an exception.", "judge_failed", errorDetails(error)),
723
+ evidence_bundle: evidenceBundle
724
+ });
725
+ }
726
+ if (assessment.decision === "ready_to_ship") break;
727
+ if (attempt + 1 < maxIterations && shouldIterate(assessment)) {
728
+ evidenceContext = evidenceBundle;
729
+ appendRunEvent(state, {
730
+ kind: "run.iterating",
731
+ checkpoint: "iteration_requested",
732
+ stage: "implement",
733
+ summary: "Judge requested another implementation iteration.",
734
+ details: {
735
+ decision: assessment.decision,
736
+ next_iteration: state.iterations + 1
737
+ }
738
+ });
739
+ continue;
740
+ }
741
+ return blockRun({
742
+ state,
743
+ stage: "verify",
744
+ blocker: adapterBlocker(
745
+ "proof_not_ready",
746
+ assessment.summary || "Proof is not ready to ship.",
747
+ "judge_completed",
748
+ {
749
+ decision: assessment.decision,
750
+ recommended_stage: assessment.recommended_stage,
751
+ continue_with_stage: assessment.continue_with_stage,
752
+ reasons: assessment.reasons
753
+ }
754
+ ),
755
+ evidence_bundle: evidenceBundle,
756
+ raw: { assessment }
757
+ });
758
+ }
759
+ if (!assessment || !evidenceBundle) {
760
+ return blockRun({
761
+ state,
762
+ stage: "verify",
763
+ blocker: adapterBlocker("runner_incomplete", "The runner ended without proof assessment.", "runner_incomplete")
764
+ });
765
+ }
766
+ if (state.request.ship_mode !== "ship") {
767
+ setRunStatus(state, "ready_to_ship");
768
+ const result2 = createRunResult({
769
+ state,
770
+ status: "ready_to_ship",
771
+ last_summary: assessment.summary,
772
+ evidence_bundle: evidenceBundle,
773
+ raw: { implementation, assessment }
774
+ });
775
+ return notifyIfConfigured({ state, result: result2, notification: adapters.notification });
776
+ }
777
+ if (!adapters.ship) {
778
+ return blockRun({
779
+ state,
780
+ stage: "ship",
781
+ blocker: adapterBlocker("ship_adapter_not_configured", "A ship adapter is required when ship_mode is ship.", "ship_required"),
782
+ evidence_bundle: evidenceBundle,
783
+ raw: { implementation, assessment }
784
+ });
785
+ }
786
+ appendRunEvent(state, {
787
+ kind: "ship.started",
788
+ checkpoint: "ship_started",
789
+ stage: "ship",
790
+ summary: "Ship adapter started."
791
+ });
792
+ appendStageHeartbeat(state, {
793
+ stage: "ship",
794
+ summary: "Ship stage is active."
795
+ });
796
+ let metadata;
797
+ try {
798
+ metadata = await adapters.ship.ship({ state, assessment });
799
+ } catch (error) {
800
+ return blockRun({
801
+ state,
802
+ stage: "ship",
803
+ blocker: adapterBlocker("ship_exception", "The ship adapter threw an exception.", "ship_failed", errorDetails(error)),
804
+ evidence_bundle: evidenceBundle,
805
+ raw: { implementation, assessment }
806
+ });
807
+ }
808
+ appendRunEvent(state, {
809
+ kind: "ship.completed",
810
+ checkpoint: "ship_completed",
811
+ stage: "ship",
812
+ summary: "Ship adapter completed.",
813
+ details: {
814
+ pr_url: metadata.pr_url,
815
+ marked_ready: metadata.marked_ready,
816
+ finalized: metadata.finalized
817
+ }
818
+ });
819
+ setRunStatus(state, "shipped");
820
+ const result = createRunResult({
821
+ state,
822
+ status: "shipped",
823
+ last_summary: "Riddle Proof shipped.",
824
+ metadata,
825
+ evidence_bundle: evidenceBundle,
826
+ raw: { implementation, assessment }
827
+ });
828
+ return notifyIfConfigured({ state, result, notification: adapters.notification });
829
+ }
830
+ // Annotate the CommonJS export names for ESM import in node:
831
+ 0 && (module.exports = {
832
+ runRiddleProof
833
+ });