@riddledc/riddle-proof 0.5.44 → 0.5.46

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 (45) hide show
  1. package/README.md +17 -0
  2. package/dist/checkpoint.cjs +366 -0
  3. package/dist/checkpoint.d.cts +44 -1
  4. package/dist/checkpoint.d.ts +44 -1
  5. package/dist/checkpoint.js +8 -2
  6. package/dist/{chunk-W7VTDN4T.js → chunk-DUFDZJOF.js} +1 -0
  7. package/dist/{chunk-7S7O3NKF.js → chunk-JTNMEH57.js} +6 -1
  8. package/dist/{chunk-MRSYJMF4.js → chunk-L26NTZOU.js} +2 -2
  9. package/dist/chunk-NOBFZDZG.js +754 -0
  10. package/dist/chunk-PLSGW2GI.js +161 -0
  11. package/dist/chunk-R6SCWJCI.js +656 -0
  12. package/dist/{chunk-MJD37CLH.js → chunk-X3AQ2WUM.js} +201 -18
  13. package/dist/cli.cjs +6129 -0
  14. package/dist/cli.d.cts +1 -0
  15. package/dist/cli.d.ts +1 -0
  16. package/dist/cli.js +160 -0
  17. package/dist/codex-exec-agent.cjs +790 -0
  18. package/dist/codex-exec-agent.d.cts +91 -0
  19. package/dist/codex-exec-agent.d.ts +91 -0
  20. package/dist/codex-exec-agent.js +10 -0
  21. package/dist/engine-harness.cjs +1013 -323
  22. package/dist/engine-harness.js +5 -4
  23. package/dist/index.cjs +1702 -247
  24. package/dist/index.d.cts +4 -2
  25. package/dist/index.d.ts +4 -2
  26. package/dist/index.js +37 -17
  27. package/dist/openclaw.js +4 -2
  28. package/dist/proof-run-engine.d.cts +3 -3
  29. package/dist/proof-run-engine.d.ts +3 -3
  30. package/dist/result.cjs +1 -0
  31. package/dist/result.js +1 -1
  32. package/dist/run-card.cjs +212 -0
  33. package/dist/run-card.d.cts +10 -0
  34. package/dist/run-card.d.ts +10 -0
  35. package/dist/run-card.js +10 -0
  36. package/dist/runner.cjs +2 -0
  37. package/dist/runner.js +5 -3
  38. package/dist/state.cjs +174 -5
  39. package/dist/state.d.cts +2 -1
  40. package/dist/state.d.ts +2 -1
  41. package/dist/state.js +4 -2
  42. package/dist/types.d.cts +64 -2
  43. package/dist/types.d.ts +64 -2
  44. package/package.json +15 -2
  45. package/dist/chunk-RI25RGQP.js +0 -293
@@ -1,293 +0,0 @@
1
- import {
2
- compactRecord,
3
- nonEmptyString,
4
- recordValue
5
- } from "./chunk-W7VTDN4T.js";
6
-
7
- // src/checkpoint.ts
8
- import crypto from "crypto";
9
- var RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION = "riddle-proof.checkpoint.v1";
10
- var RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION = "riddle-proof.checkpoint_response.v1";
11
- function timestamp() {
12
- return (/* @__PURE__ */ new Date()).toISOString();
13
- }
14
- function jsonCloneRecord(value) {
15
- const record = recordValue(value);
16
- if (!record) return void 0;
17
- try {
18
- return JSON.parse(JSON.stringify(record));
19
- } catch {
20
- return { ...record };
21
- }
22
- }
23
- function jsonCloneValue(value) {
24
- if (value === void 0 || value === null) return void 0;
25
- try {
26
- return JSON.parse(JSON.stringify(value));
27
- } catch {
28
- return value;
29
- }
30
- }
31
- function stableJson(value) {
32
- if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
33
- const record = recordValue(value);
34
- if (record) {
35
- return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableJson(record[key])}`).join(",")}}`;
36
- }
37
- return JSON.stringify(value);
38
- }
39
- function compactText(value, limit = 1600) {
40
- const text = nonEmptyString(value);
41
- if (!text) return void 0;
42
- return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
43
- }
44
- function statePathsForRunState(state, engineStatePath) {
45
- return compactRecord({
46
- wrapper_state_path: state.state_path || state.request.harness_state_path || null,
47
- engine_state_path: engineStatePath || state.request.engine_state_path || null,
48
- resume_state_path: engineStatePath || state.request.engine_state_path || null
49
- });
50
- }
51
- function responseSchemaForAuthorPacket() {
52
- return {
53
- type: "object",
54
- required: ["version", "run_id", "checkpoint", "decision", "summary", "payload", "created_at"],
55
- additionalProperties: false,
56
- properties: {
57
- version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
58
- run_id: { type: "string" },
59
- checkpoint: { type: "string" },
60
- resume_token: { type: "string" },
61
- decision: {
62
- type: "string",
63
- enum: ["author_packet", "needs_recon", "blocked", "human_review"]
64
- },
65
- summary: { type: "string" },
66
- payload: {
67
- type: "object",
68
- description: "For decision=author_packet, provide the proof packet itself or {author_packet:{...}} with proof_plan and capture_script."
69
- },
70
- reasons: { type: "array", items: { type: "string" } },
71
- continue_with_stage: { type: "string", enum: ["author", "recon"] },
72
- source: {
73
- type: "object",
74
- properties: {
75
- kind: { type: "string" },
76
- session_id: { type: "string" },
77
- user_id: { type: "string" }
78
- }
79
- },
80
- created_at: { type: "string" }
81
- }
82
- };
83
- }
84
- function resumeTokenFor(input) {
85
- const hash = crypto.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
86
- return `rpchk_${hash}`;
87
- }
88
- function artifactsFromState(state) {
89
- const artifacts = [];
90
- for (const role of ["before", "prod", "after"]) {
91
- const url = nonEmptyString(state?.[`${role}_cdn`]);
92
- if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
93
- }
94
- const authorRequest = recordValue(state?.author_request);
95
- const latestAttempt = recordValue(authorRequest?.latest_attempt);
96
- const observations = recordValue(latestAttempt?.observations);
97
- for (const [label, observation] of Object.entries(observations || {})) {
98
- const record = recordValue(observation);
99
- const url = nonEmptyString(record?.url);
100
- if (url && !artifacts.some((artifact) => artifact.url === url)) {
101
- artifacts.push({
102
- role: label === "before" || label === "prod" ? label : "json",
103
- url,
104
- name: `${label}-observation`,
105
- summary: compactText(record?.reason, 240)
106
- });
107
- }
108
- }
109
- return artifacts.slice(0, 16);
110
- }
111
- function buildAuthorCheckpointPacket(input) {
112
- const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
113
- const stage = "author";
114
- const runId = input.runState.run_id || "unknown";
115
- const fullState = input.fullRiddleState || {};
116
- const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
117
- const authorRequest = recordValue(fullState.author_request) || recordValue(fullState.proof_plan_request) || recordValue(decisionDetails?.authorRequest) || {};
118
- const fallbackDefaults = recordValue(authorRequest.fallback_defaults) || {};
119
- const reconResults = recordValue(fullState.recon_results);
120
- const checkpointContract = recordValue(input.engineResult.checkpointContract);
121
- const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.author_summary) || "Author checkpoint needs a supervising proof packet.";
122
- return {
123
- version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
124
- run_id: runId,
125
- state_path: input.runState.state_path,
126
- stage,
127
- checkpoint,
128
- kind: "author_proof",
129
- summary,
130
- question: "Author the proof packet for this Riddle Proof run. Return a CheckpointResponse with decision=author_packet and payload containing proof_plan and capture_script.",
131
- change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
132
- context: input.request.context,
133
- artifacts: artifactsFromState(fullState),
134
- state_excerpt: compactRecord({
135
- repo: input.request.repo || fullState.repo,
136
- branch: input.request.branch || fullState.branch,
137
- verification_mode: input.request.verification_mode || fullState.verification_mode,
138
- reference: input.request.reference || fullState.reference,
139
- server_path: fullState.server_path,
140
- wait_for_selector: fullState.wait_for_selector,
141
- author_summary: fullState.author_summary,
142
- author_request: jsonCloneRecord(authorRequest),
143
- recon_baseline_understanding: jsonCloneRecord(fullState.recon_baseline_understanding),
144
- fallback_defaults: jsonCloneRecord(fallbackDefaults)
145
- }),
146
- evidence_excerpt: compactRecord({
147
- recon_results: jsonCloneRecord(reconResults),
148
- checkpoint_contract: jsonCloneRecord(checkpointContract)
149
- }),
150
- allowed_decisions: ["author_packet", "needs_recon", "blocked", "human_review"],
151
- response_schema: responseSchemaForAuthorPacket(),
152
- routing_hint: {
153
- suggested_role: "proof_author",
154
- visibility: input.visibility || "quiet",
155
- urgency: "normal",
156
- can_auto_answer: input.visibility !== "manual"
157
- },
158
- resume_token: resumeTokenFor({
159
- runId,
160
- statePath: input.engineResult.state_path || input.request.engine_state_path || null,
161
- checkpoint,
162
- stage
163
- }),
164
- created_at: input.created_at || timestamp()
165
- };
166
- }
167
- function normalizeCheckpointResponse(value) {
168
- const record = recordValue(value);
169
- if (!record) return null;
170
- const version = nonEmptyString(record.version);
171
- const runId = nonEmptyString(record.run_id);
172
- const checkpoint = nonEmptyString(record.checkpoint);
173
- const decision = nonEmptyString(record.decision);
174
- const summary = nonEmptyString(record.summary);
175
- if (version !== RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION || !runId || !checkpoint || !decision || !summary) {
176
- return null;
177
- }
178
- return compactRecord({
179
- version: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
180
- run_id: runId,
181
- checkpoint,
182
- resume_token: nonEmptyString(record.resume_token),
183
- decision,
184
- summary,
185
- payload: jsonCloneRecord(record.payload),
186
- reasons: Array.isArray(record.reasons) ? record.reasons.filter((item) => typeof item === "string") : void 0,
187
- continue_with_stage: nonEmptyString(record.continue_with_stage),
188
- source: jsonCloneRecord(record.source),
189
- created_at: nonEmptyString(record.created_at) || timestamp()
190
- });
191
- }
192
- function checkpointSummaryFromState(state, engineStatePath) {
193
- const history = state.checkpoint_history || [];
194
- const packets = history.filter((entry) => entry.packet);
195
- const responses = history.filter((entry) => entry.response);
196
- const duplicateResponses = (state.events || []).filter((event) => event.kind === "checkpoint.response.duplicate");
197
- const latestPacketEntry = [...history].reverse().find((entry) => entry.packet);
198
- const latestResponseEntry = [...history].reverse().find((entry) => entry.response);
199
- const latestPacket = state.checkpoint_packet || latestPacketEntry?.packet;
200
- const latestResponse = latestResponseEntry?.response;
201
- const latestResumeToken = latestPacket?.resume_token || null;
202
- const latestResponseToken = latestResponse?.resume_token || null;
203
- const tokenMatches = latestResumeToken && latestResponseToken ? latestResumeToken === latestResponseToken : latestResumeToken || latestResponseToken ? false : null;
204
- return compactRecord({
205
- pending: Boolean(state.checkpoint_packet),
206
- packet_count: packets.length,
207
- response_count: responses.length,
208
- duplicate_response_count: duplicateResponses.length,
209
- latest_checkpoint: state.checkpoint_packet?.checkpoint || latestResponse?.checkpoint || state.last_checkpoint || null,
210
- latest_stage: state.checkpoint_packet?.stage || latestResponse?.continue_with_stage || state.current_stage || null,
211
- latest_kind: state.checkpoint_packet?.kind || latestPacket?.kind || null,
212
- latest_decision: latestResponse?.decision || null,
213
- latest_packet_summary: latestPacket?.summary || null,
214
- latest_response_summary: latestResponse?.summary || null,
215
- latest_resume_token: latestResumeToken,
216
- latest_response_token: latestResponseToken,
217
- token_matches: tokenMatches,
218
- last_packet_at: latestPacketEntry?.ts || null,
219
- last_response_at: latestResponseEntry?.ts || null,
220
- state_paths: statePathsForRunState(state, engineStatePath)
221
- });
222
- }
223
- function isDuplicateCheckpointResponse(state, response) {
224
- const identity = checkpointResponseIdentity(response);
225
- return (state.checkpoint_history || []).some((entry) => entry.response ? checkpointResponseIdentity(entry.response) === identity : false);
226
- }
227
- function checkpointResponseIdentity(response) {
228
- const logicalResponse = compactRecord({
229
- run_id: response.run_id,
230
- checkpoint: response.checkpoint,
231
- resume_token: response.resume_token,
232
- decision: response.decision,
233
- summary: response.summary,
234
- payload: response.payload,
235
- reasons: response.reasons,
236
- continue_with_stage: response.continue_with_stage,
237
- source: response.source
238
- });
239
- return crypto.createHash("sha256").update(stableJson(logicalResponse)).digest("hex").slice(0, 24);
240
- }
241
- function authorPacketPayloadFromCheckpointResponse(response) {
242
- if (response.decision !== "author_packet") return null;
243
- const payload = recordValue(response.payload);
244
- if (!payload) return null;
245
- const nested = recordValue(payload.author_packet);
246
- const candidate = nested || payload;
247
- if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
248
- return candidate;
249
- }
250
- function proofContractFromAuthorCheckpointResponse(response, packet, payload) {
251
- const refinedInputs = recordValue(payload.refined_inputs) || {};
252
- return compactRecord({
253
- version: "riddle-proof.proof-contract.v1",
254
- checkpoint: packet.checkpoint,
255
- source_response: compactRecord({
256
- run_id: response.run_id,
257
- checkpoint: response.checkpoint,
258
- resume_token: response.resume_token,
259
- decision: response.decision,
260
- summary: response.summary,
261
- created_at: response.created_at
262
- }),
263
- proof_plan: nonEmptyString(payload.proof_plan),
264
- capture_script: nonEmptyString(payload.capture_script),
265
- artifact_contract: jsonCloneRecord(payload.artifact_contract),
266
- assertions: jsonCloneValue(payload.assertions),
267
- baseline_understanding: jsonCloneRecord(payload.baseline_understanding) || jsonCloneRecord(payload.recon_baseline_understanding) || jsonCloneRecord(packet.state_excerpt?.recon_baseline_understanding),
268
- route_assumptions: compactRecord({
269
- server_path: nonEmptyString(refinedInputs.server_path) || nonEmptyString(payload.server_path) || nonEmptyString(packet.state_excerpt?.server_path),
270
- wait_for_selector: nonEmptyString(refinedInputs.wait_for_selector) || nonEmptyString(payload.wait_for_selector) || nonEmptyString(packet.state_excerpt?.wait_for_selector),
271
- reference: nonEmptyString(refinedInputs.reference) || nonEmptyString(payload.reference),
272
- expected_path: nonEmptyString(payload.expected_path) || nonEmptyString(refinedInputs.expected_path)
273
- }),
274
- stop_condition: nonEmptyString(payload.stop_condition),
275
- rationale: jsonCloneValue(payload.rationale),
276
- verdict_dimensions: jsonCloneRecord(payload.verdict_dimensions),
277
- payload: jsonCloneRecord(payload),
278
- created_at: timestamp()
279
- });
280
- }
281
-
282
- export {
283
- RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
284
- RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
285
- statePathsForRunState,
286
- buildAuthorCheckpointPacket,
287
- normalizeCheckpointResponse,
288
- checkpointSummaryFromState,
289
- isDuplicateCheckpointResponse,
290
- checkpointResponseIdentity,
291
- authorPacketPayloadFromCheckpointResponse,
292
- proofContractFromAuthorCheckpointResponse
293
- };