@riddledc/riddle-proof 0.5.45 → 0.5.47

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 (49) hide show
  1. package/README.md +22 -0
  2. package/dist/checkpoint.cjs +204 -1
  3. package/dist/checkpoint.d.cts +16 -1
  4. package/dist/checkpoint.d.ts +16 -1
  5. package/dist/checkpoint.js +4 -2
  6. package/dist/{chunk-CHRYLX6N.js → chunk-ALP5KOS2.js} +128 -15
  7. package/dist/{chunk-W7VTDN4T.js → chunk-DUFDZJOF.js} +1 -0
  8. package/dist/chunk-JFQXAJH2.js +0 -0
  9. package/dist/{chunk-7S7O3NKF.js → chunk-JOXTKWX6.js} +6 -1
  10. package/dist/{chunk-MRSYJMF4.js → chunk-N3ZNBRIG.js} +2 -2
  11. package/dist/chunk-NOBFZDZG.js +754 -0
  12. package/dist/chunk-PLSGW2GI.js +161 -0
  13. package/dist/{chunk-LXE5YUYY.js → chunk-R6SCWJCI.js} +204 -2
  14. package/dist/cli.cjs +6134 -0
  15. package/dist/cli.d.cts +1 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +166 -0
  18. package/dist/codex-exec-agent.cjs +790 -0
  19. package/dist/codex-exec-agent.d.cts +91 -0
  20. package/dist/codex-exec-agent.d.ts +91 -0
  21. package/dist/codex-exec-agent.js +10 -0
  22. package/dist/engine-harness.cjs +740 -279
  23. package/dist/engine-harness.js +5 -4
  24. package/dist/index.cjs +1475 -247
  25. package/dist/index.d.cts +4 -2
  26. package/dist/index.d.ts +4 -2
  27. package/dist/index.js +45 -25
  28. package/dist/local-agent.cjs +792 -0
  29. package/dist/local-agent.d.cts +3 -0
  30. package/dist/local-agent.d.ts +3 -0
  31. package/dist/local-agent.js +11 -0
  32. package/dist/openclaw.js +4 -2
  33. package/dist/proof-run-engine.d.cts +3 -3
  34. package/dist/proof-run-engine.d.ts +3 -3
  35. package/dist/result.cjs +1 -0
  36. package/dist/result.js +1 -1
  37. package/dist/run-card.cjs +212 -0
  38. package/dist/run-card.d.cts +10 -0
  39. package/dist/run-card.d.ts +10 -0
  40. package/dist/run-card.js +10 -0
  41. package/dist/runner.cjs +2 -0
  42. package/dist/runner.js +5 -3
  43. package/dist/state.cjs +174 -5
  44. package/dist/state.d.cts +2 -1
  45. package/dist/state.d.ts +2 -1
  46. package/dist/state.js +4 -2
  47. package/dist/types.d.cts +63 -2
  48. package/dist/types.d.ts +63 -2
  49. package/package.json +20 -2
@@ -0,0 +1,161 @@
1
+ import {
2
+ statePathsForRunState
3
+ } from "./chunk-R6SCWJCI.js";
4
+ import {
5
+ compactRecord,
6
+ isTerminalStatus,
7
+ nonEmptyString,
8
+ recordValue
9
+ } from "./chunk-DUFDZJOF.js";
10
+
11
+ // src/run-card.ts
12
+ var RIDDLE_PROOF_RUN_CARD_VERSION = "riddle-proof.run-card.v1";
13
+ function elapsedMs(start, end) {
14
+ const startMs = start ? Date.parse(start) : NaN;
15
+ const endMs = end ? Date.parse(end) : NaN;
16
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
17
+ return Math.max(0, endMs - startMs);
18
+ }
19
+ function jsonCloneRecord(value) {
20
+ const record = recordValue(value);
21
+ if (!record) return void 0;
22
+ try {
23
+ return JSON.parse(JSON.stringify(record));
24
+ } catch {
25
+ return { ...record };
26
+ }
27
+ }
28
+ function compactText(value, limit = 600) {
29
+ const text = nonEmptyString(value);
30
+ if (!text) return void 0;
31
+ return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
32
+ }
33
+ function visualDeltaFrom(input) {
34
+ const fullState = input.fullRiddleState || {};
35
+ const bundle = recordValue(fullState.evidence_bundle);
36
+ const after = recordValue(bundle?.after);
37
+ const afterDelta = recordValue(after?.visual_delta);
38
+ if (afterDelta && Object.keys(afterDelta).length) return afterDelta;
39
+ const requestDelta = recordValue(recordValue(fullState.proof_assessment_request)?.visual_delta);
40
+ if (requestDelta && Object.keys(requestDelta).length) return requestDelta;
41
+ const packetDelta = recordValue(input.runState.checkpoint_packet?.evidence_excerpt?.visual_delta);
42
+ return packetDelta && Object.keys(packetDelta).length ? packetDelta : void 0;
43
+ }
44
+ function artifactsFrom(input) {
45
+ const packetArtifacts = input.runState.checkpoint_packet?.artifacts;
46
+ if (packetArtifacts?.length) return packetArtifacts.slice(0, 12);
47
+ const fullState = input.fullRiddleState || {};
48
+ const artifacts = [];
49
+ for (const role of ["before", "prod", "after"]) {
50
+ const url = nonEmptyString(fullState[`${role}_cdn`]) || nonEmptyString(input.runState[`${role}_artifact_url`]);
51
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
52
+ }
53
+ return artifacts.length ? artifacts : void 0;
54
+ }
55
+ function ownerFor(state) {
56
+ if (state.status === "awaiting_checkpoint") {
57
+ const role = nonEmptyString(state.checkpoint_packet?.routing_hint?.suggested_role);
58
+ return role || "supervising_agent";
59
+ }
60
+ if (state.status === "running") return "engine";
61
+ if (state.status === "blocked" || state.status === "failed") return "human_or_operator";
62
+ return "none";
63
+ }
64
+ function actionFor(state) {
65
+ if (state.status === "awaiting_checkpoint") return state.checkpoint_packet?.question || "Answer the pending checkpoint.";
66
+ if (state.status === "running") return "Continue the current Riddle Proof stage.";
67
+ 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.";
68
+ if (state.status === "ready_to_ship") return "Ship is held by policy; review PR/ship policy before advancing.";
69
+ return "No next action; run is terminal.";
70
+ }
71
+ function evidenceIssueCode(input) {
72
+ const packetIssue = nonEmptyString(input.runState.checkpoint_packet?.evidence_excerpt?.evidence_issue_code);
73
+ if (packetIssue) return packetIssue;
74
+ const assessmentIssue = nonEmptyString(recordValue(input.fullRiddleState?.proof_assessment)?.evidence_issue_code);
75
+ if (assessmentIssue) return assessmentIssue;
76
+ const delta = visualDeltaFrom(input);
77
+ const status = nonEmptyString(delta?.status);
78
+ if (status === "unmeasured") {
79
+ const reason = `${nonEmptyString(delta?.reason) || ""}
80
+ ${input.runState.blocker?.message || ""}`.toLowerCase();
81
+ return reason.includes("fetch") || reason.includes("allowlist") || reason.includes("registered domain") || reason.includes("high risk") || reason.includes("comparator") ? "comparator_fetch_blocked" : "visual_delta_unmeasured";
82
+ }
83
+ if (status === "measured" && delta?.passed === false) return "semantic_proof_failed";
84
+ return void 0;
85
+ }
86
+ function createRiddleProofRunCard(state, input = {}) {
87
+ const at = input.at || (/* @__PURE__ */ new Date()).toISOString();
88
+ const fullState = input.fullRiddleState || {};
89
+ const packet = state.checkpoint_packet;
90
+ const latestEvent = state.events[state.events.length - 1];
91
+ const bundle = recordValue(fullState.evidence_bundle);
92
+ 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);
93
+ const required = jsonCloneRecord(recordValue(artifactContract)?.required);
94
+ const statePaths = input.state_paths || state.state_paths || statePathsForRunState(state);
95
+ const visualDelta = visualDeltaFrom({ fullRiddleState: fullState, runState: state });
96
+ const artifacts = artifactsFrom({ fullRiddleState: fullState, runState: state });
97
+ return {
98
+ version: RIDDLE_PROOF_RUN_CARD_VERSION,
99
+ run_id: state.run_id || "unknown",
100
+ status: state.status,
101
+ goal: compactRecord({
102
+ repo: state.request.repo || nonEmptyString(fullState.repo),
103
+ branch: state.request.branch || nonEmptyString(fullState.branch),
104
+ change_request: state.request.change_request || nonEmptyString(fullState.change_request),
105
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
106
+ success_criteria: state.request.success_criteria
107
+ }),
108
+ durable_state: compactRecord({
109
+ ...statePaths,
110
+ worktree_path: state.worktree_path || nonEmptyString(fullState.after_worktree) || null,
111
+ branch: state.branch || nonEmptyString(fullState.branch) || null
112
+ }),
113
+ current_phase: compactRecord({
114
+ stage: state.current_stage ?? null,
115
+ checkpoint: state.last_checkpoint ?? packet?.checkpoint ?? null,
116
+ latest_event: latestEvent?.kind ?? null,
117
+ elapsed_ms: elapsedMs(state.created_at, at),
118
+ stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
119
+ iterations: state.iterations
120
+ }),
121
+ owner_next_action: compactRecord({
122
+ owner: ownerFor(state),
123
+ action: actionFor(state),
124
+ checkpoint_kind: packet?.kind || null,
125
+ allowed_decisions: packet?.allowed_decisions,
126
+ retryable: state.status === "running" || state.status === "awaiting_checkpoint",
127
+ reason: state.blocker?.code || packet?.summary || latestEvent?.summary || null
128
+ }),
129
+ evidence_contract: compactRecord({
130
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
131
+ required,
132
+ artifact_contract: artifactContract,
133
+ proof_plan: compactText(state.proof_contract?.proof_plan || fullState.proof_plan, 600),
134
+ stop_condition: compactText(state.proof_contract?.stop_condition, 400)
135
+ }),
136
+ latest_evidence: compactRecord({
137
+ before_url: nonEmptyString(fullState.before_cdn) || state.before_artifact_url || null,
138
+ prod_url: nonEmptyString(fullState.prod_cdn) || state.prod_artifact_url || null,
139
+ after_url: nonEmptyString(fullState.after_cdn) || state.after_artifact_url || null,
140
+ visual_delta: visualDelta || null,
141
+ evidence_issue_code: evidenceIssueCode({ fullRiddleState: fullState, runState: state }) || null,
142
+ proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
143
+ artifacts
144
+ }),
145
+ stop_condition: compactRecord({
146
+ status: state.status,
147
+ terminal: isTerminalStatus(state.status),
148
+ blocker_code: state.blocker?.code || null,
149
+ blocker_message: state.blocker?.message || null,
150
+ proof_decision: state.proof_decision,
151
+ merge_recommendation: state.merge_recommendation,
152
+ monitor_should_continue: !isTerminalStatus(state.status)
153
+ }),
154
+ updated_at: state.updated_at
155
+ };
156
+ }
157
+
158
+ export {
159
+ RIDDLE_PROOF_RUN_CARD_VERSION,
160
+ createRiddleProofRunCard
161
+ };
@@ -2,7 +2,7 @@ import {
2
2
  compactRecord,
3
3
  nonEmptyString,
4
4
  recordValue
5
- } from "./chunk-W7VTDN4T.js";
5
+ } from "./chunk-DUFDZJOF.js";
6
6
 
7
7
  // src/checkpoint.ts
8
8
  import crypto from "crypto";
@@ -122,6 +122,102 @@ function responseSchemaForProofAssessmentPacket() {
122
122
  }
123
123
  };
124
124
  }
125
+ function responseSchemaForReconPacket() {
126
+ return {
127
+ type: "object",
128
+ required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
129
+ additionalProperties: false,
130
+ properties: {
131
+ version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
132
+ run_id: { type: "string" },
133
+ checkpoint: { type: "string" },
134
+ resume_token: { type: "string" },
135
+ decision: {
136
+ type: "string",
137
+ enum: ["ready_for_author", "retry_recon", "recon_stuck", "needs_recon", "blocked", "human_review"]
138
+ },
139
+ summary: { type: "string" },
140
+ payload: {
141
+ type: "object",
142
+ description: "Optional recon assessment details such as baseline_understanding, refined_inputs, reasons, or diagnostic blocker context."
143
+ },
144
+ reasons: { type: "array", items: { type: "string" } },
145
+ continue_with_stage: { type: "string", enum: ["recon", "author"] },
146
+ source: {
147
+ type: "object",
148
+ properties: {
149
+ kind: { type: "string" },
150
+ session_id: { type: "string" },
151
+ user_id: { type: "string" }
152
+ }
153
+ },
154
+ created_at: { type: "string" }
155
+ }
156
+ };
157
+ }
158
+ function responseSchemaForImplementationPacket() {
159
+ return {
160
+ type: "object",
161
+ required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
162
+ additionalProperties: false,
163
+ properties: {
164
+ version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
165
+ run_id: { type: "string" },
166
+ checkpoint: { type: "string" },
167
+ resume_token: { type: "string" },
168
+ decision: {
169
+ type: "string",
170
+ enum: ["implementation_complete", "needs_author", "needs_recon", "blocked", "human_review"]
171
+ },
172
+ summary: { type: "string" },
173
+ payload: {
174
+ type: "object",
175
+ description: "Implementation details such as changed_files, tests_run, and implementation_notes. The changed worktree must contain a real git diff before verify can advance."
176
+ },
177
+ reasons: { type: "array", items: { type: "string" } },
178
+ continue_with_stage: { type: "string", enum: ["implement", "verify", "author", "recon"] },
179
+ source: {
180
+ type: "object",
181
+ properties: {
182
+ kind: { type: "string" },
183
+ session_id: { type: "string" },
184
+ user_id: { type: "string" }
185
+ }
186
+ },
187
+ created_at: { type: "string" }
188
+ }
189
+ };
190
+ }
191
+ function responseSchemaForAdvancePacket(stage) {
192
+ return {
193
+ type: "object",
194
+ required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
195
+ additionalProperties: false,
196
+ properties: {
197
+ version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
198
+ run_id: { type: "string" },
199
+ checkpoint: { type: "string" },
200
+ resume_token: { type: "string" },
201
+ decision: {
202
+ type: "string",
203
+ enum: ["continue_stage", "retry_stage", "needs_recon", "needs_implementation", "blocked", "human_review"]
204
+ },
205
+ summary: { type: "string" },
206
+ payload: { type: "object" },
207
+ reasons: { type: "array", items: { type: "string" } },
208
+ continue_with_stage: { type: "string", enum: ["recon", "author", "implement", "verify", "ship", stage] },
209
+ source: {
210
+ type: "object",
211
+ properties: {
212
+ kind: { type: "string" },
213
+ session_id: { type: "string" },
214
+ user_id: { type: "string" }
215
+ }
216
+ },
217
+ created_at: { type: "string" }
218
+ }
219
+ };
220
+ }
125
221
  function resumeTokenFor(input) {
126
222
  const hash = crypto.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
127
223
  return `rpchk_${hash}`;
@@ -149,6 +245,106 @@ function artifactsFromState(state) {
149
245
  }
150
246
  return artifacts.slice(0, 16);
151
247
  }
248
+ function stageFromCheckpoint(checkpoint) {
249
+ if (checkpoint.startsWith("recon_")) return "recon";
250
+ if (checkpoint.startsWith("author_")) return "author";
251
+ if (checkpoint.startsWith("implement_")) return "implement";
252
+ if (checkpoint.startsWith("verify_")) return "verify";
253
+ if (checkpoint.startsWith("ship_")) return "ship";
254
+ if (checkpoint.startsWith("pr_sync_")) return "notify";
255
+ if (checkpoint.includes("capture")) return "prove";
256
+ return "setup";
257
+ }
258
+ function allowedDecisionsForStage(stage, checkpoint) {
259
+ if (stage === "recon") return ["ready_for_author", "retry_recon", "recon_stuck", "blocked", "human_review"];
260
+ if (stage === "implement") return ["implementation_complete", "needs_author", "needs_recon", "blocked", "human_review"];
261
+ if (stage === "ship") return ["continue_stage", "needs_implementation", "needs_recon", "blocked", "human_review"];
262
+ if (checkpoint === "awaiting_stage_advance") return ["continue_stage", "retry_stage", "blocked", "human_review"];
263
+ return ["continue_stage", "needs_recon", "needs_implementation", "blocked", "human_review"];
264
+ }
265
+ function packetKindForStage(stage, checkpoint) {
266
+ if (stage === "recon") return "assess_recon";
267
+ if (stage === "implement") return "implement_change";
268
+ if (checkpoint.includes("human")) return "human_review";
269
+ return "advance_decision";
270
+ }
271
+ function responseSchemaForStage(stage, checkpoint) {
272
+ if (stage === "recon") return responseSchemaForReconPacket();
273
+ if (stage === "implement") return responseSchemaForImplementationPacket();
274
+ return responseSchemaForAdvancePacket(stage);
275
+ }
276
+ function questionForStage(stage, checkpoint) {
277
+ if (stage === "recon") {
278
+ return "Assess the baseline/recon evidence. Return ready_for_author only when the baseline is trustworthy; otherwise choose retry_recon, recon_stuck, blocked, or human_review.";
279
+ }
280
+ if (stage === "implement") {
281
+ return "Implement the requested change in the after worktree, leave a real git diff, then return implementation_complete with changed_files/tests_run/implementation_notes. Choose blocked or human_review if implementation cannot honestly advance.";
282
+ }
283
+ if (stage === "ship") {
284
+ return "Assess whether the ship gate can continue. Return continue_stage only if proof, PR, and policy gates are satisfied; otherwise route to the appropriate earlier stage or block with a concrete reason.";
285
+ }
286
+ return "Choose the next Riddle Proof stage for this durable run, or block with a concrete reason if the run cannot honestly advance.";
287
+ }
288
+ function buildStageCheckpointPacket(input) {
289
+ const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "stage_checkpoint";
290
+ const stage = nonEmptyString(input.engineResult.stage) || stageFromCheckpoint(checkpoint);
291
+ const runId = input.runState.run_id || "unknown";
292
+ const fullState = input.fullRiddleState || {};
293
+ const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
294
+ const checkpointContract = recordValue(input.engineResult.checkpointContract);
295
+ const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.stage_summary) || `${stage} checkpoint needs a supervising decision.`;
296
+ const kind = packetKindForStage(stage, checkpoint);
297
+ return {
298
+ version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
299
+ run_id: runId,
300
+ state_path: input.runState.state_path,
301
+ stage,
302
+ checkpoint,
303
+ kind,
304
+ summary,
305
+ question: questionForStage(stage, checkpoint),
306
+ change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
307
+ context: input.request.context,
308
+ artifacts: artifactsFromState(fullState),
309
+ state_excerpt: compactRecord({
310
+ repo: input.request.repo || fullState.repo,
311
+ branch: input.request.branch || fullState.branch,
312
+ after_worktree: fullState.after_worktree || input.runState.worktree_path,
313
+ verification_mode: input.request.verification_mode || fullState.verification_mode,
314
+ reference: input.request.reference || fullState.reference,
315
+ server_path: fullState.server_path,
316
+ wait_for_selector: fullState.wait_for_selector,
317
+ recon_status: fullState.recon_status,
318
+ author_status: fullState.author_status,
319
+ implementation_status: fullState.implementation_status,
320
+ verify_status: fullState.verify_status,
321
+ stage_decision_request: jsonCloneRecord(fullState.stage_decision_request)
322
+ }),
323
+ evidence_excerpt: compactRecord({
324
+ before_cdn: fullState.before_cdn || null,
325
+ prod_cdn: fullState.prod_cdn || null,
326
+ after_cdn: fullState.after_cdn || null,
327
+ recon_results: jsonCloneRecord(fullState.recon_results),
328
+ checkpoint_contract: jsonCloneRecord(checkpointContract),
329
+ decision_details: jsonCloneRecord(decisionDetails)
330
+ }),
331
+ allowed_decisions: allowedDecisionsForStage(stage, checkpoint),
332
+ response_schema: responseSchemaForStage(stage, checkpoint),
333
+ routing_hint: {
334
+ suggested_role: stage === "implement" ? "builder_agent" : checkpoint.includes("human") ? "human" : "main_agent",
335
+ visibility: input.visibility || "quiet",
336
+ urgency: stage === "ship" ? "high" : "normal",
337
+ can_auto_answer: input.visibility !== "manual"
338
+ },
339
+ resume_token: resumeTokenFor({
340
+ runId,
341
+ statePath: input.engineResult.state_path || input.request.engine_state_path || null,
342
+ checkpoint,
343
+ stage
344
+ }),
345
+ created_at: input.created_at || timestamp()
346
+ };
347
+ }
152
348
  function buildAuthorCheckpointPacket(input) {
153
349
  const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
154
350
  const stage = "author";
@@ -321,7 +517,12 @@ function buildCheckpointPacketForEngineResult(input) {
321
517
  if (checkpoint === "verify_supervisor_judgment" || checkpoint === "verify_supervisor_judgment_required" || checkpoint === "verify_human_escalation") {
322
518
  return buildProofAssessmentCheckpointPacket(input);
323
519
  }
324
- return buildAuthorCheckpointPacket(input);
520
+ const resume = recordValue(input.engineResult.checkpointContract?.resume);
521
+ const continueStage = nonEmptyString(resume?.continue_with_stage);
522
+ if (checkpoint === "author_supervisor_judgment" || checkpoint === "verify_capture_retry" || checkpoint === "verify_agent_retry" && continueStage === "author") {
523
+ return buildAuthorCheckpointPacket(input);
524
+ }
525
+ return buildStageCheckpointPacket(input);
325
526
  }
326
527
  function normalizeCheckpointResponse(value) {
327
528
  const record = recordValue(value);
@@ -442,6 +643,7 @@ export {
442
643
  RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
443
644
  RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
444
645
  statePathsForRunState,
646
+ buildStageCheckpointPacket,
445
647
  buildAuthorCheckpointPacket,
446
648
  buildProofAssessmentCheckpointPacket,
447
649
  buildCheckpointPacketForEngineResult,