@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,3 @@
1
+ export { CodexExecAgentConfig as LocalAgentConfig, CodexJsonRequest as LocalAgentJsonRequest, CodexJsonResult as LocalAgentJsonResult, CodexJsonRunner as LocalAgentJsonRunner, createCodexExecAgentAdapter as createLocalAgentAdapter, createCodexExecJsonRunner as createLocalAgentJsonRunner, runCodexExecAgentDoctor as runLocalAgentDoctor } from './codex-exec-agent.cjs';
2
+ import './engine-harness.cjs';
3
+ import './types.cjs';
@@ -0,0 +1,3 @@
1
+ export { CodexExecAgentConfig as LocalAgentConfig, CodexJsonRequest as LocalAgentJsonRequest, CodexJsonResult as LocalAgentJsonResult, CodexJsonRunner as LocalAgentJsonRunner, createCodexExecAgentAdapter as createLocalAgentAdapter, createCodexExecJsonRunner as createLocalAgentJsonRunner, runCodexExecAgentDoctor as runLocalAgentDoctor } from './codex-exec-agent.js';
2
+ import './engine-harness.js';
3
+ import './types.js';
@@ -0,0 +1,11 @@
1
+ import "./chunk-JFQXAJH2.js";
2
+ import {
3
+ createCodexExecAgentAdapter,
4
+ createCodexExecJsonRunner,
5
+ runCodexExecAgentDoctor
6
+ } from "./chunk-NOBFZDZG.js";
7
+ export {
8
+ createCodexExecAgentAdapter as createLocalAgentAdapter,
9
+ createCodexExecJsonRunner as createLocalAgentJsonRunner,
10
+ runCodexExecAgentDoctor as runLocalAgentDoctor
11
+ };
package/dist/openclaw.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  normalizeIntegrationContext,
3
3
  normalizeRunParams
4
- } from "./chunk-7S7O3NKF.js";
4
+ } from "./chunk-JOXTKWX6.js";
5
+ import "./chunk-PLSGW2GI.js";
6
+ import "./chunk-R6SCWJCI.js";
5
7
  import {
6
8
  compactRecord
7
- } from "./chunk-W7VTDN4T.js";
9
+ } from "./chunk-DUFDZJOF.js";
8
10
 
9
11
  // src/openclaw.ts
10
12
  function parseOpenClawAssertions(value) {
@@ -277,7 +277,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
277
277
  blocking?: boolean;
278
278
  details?: Record<string, unknown>;
279
279
  ok: boolean;
280
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
280
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
281
281
  state_path: string;
282
282
  stage: any;
283
283
  summary: string;
@@ -362,7 +362,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
362
362
  continueWithStage?: WorkflowStage | null;
363
363
  blocking?: boolean;
364
364
  details?: Record<string, unknown>;
365
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
365
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
366
366
  state_path: string;
367
367
  stage: any;
368
368
  checkpoint: string;
@@ -624,7 +624,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
624
624
  error?: undefined;
625
625
  } | {
626
626
  ok: boolean;
627
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
627
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
628
628
  state_path: string;
629
629
  stage: any;
630
630
  summary: string;
@@ -277,7 +277,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
277
277
  blocking?: boolean;
278
278
  details?: Record<string, unknown>;
279
279
  ok: boolean;
280
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
280
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
281
281
  state_path: string;
282
282
  stage: any;
283
283
  summary: string;
@@ -362,7 +362,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
362
362
  continueWithStage?: WorkflowStage | null;
363
363
  blocking?: boolean;
364
364
  details?: Record<string, unknown>;
365
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
365
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
366
366
  state_path: string;
367
367
  stage: any;
368
368
  checkpoint: string;
@@ -624,7 +624,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
624
624
  error?: undefined;
625
625
  } | {
626
626
  ok: boolean;
627
- action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
627
+ action: "run" | "ship" | "setup" | "recon" | "author" | "implement" | "verify";
628
628
  state_path: string;
629
629
  stage: any;
630
630
  summary: string;
package/dist/result.cjs CHANGED
@@ -237,6 +237,7 @@ function createRunResult(input) {
237
237
  checkpoint_summary: state.checkpoint_summary,
238
238
  state_paths: state.state_paths,
239
239
  proof_contract: state.proof_contract,
240
+ run_card: state.run_card,
240
241
  proof_session: state.proof_session,
241
242
  evidence_bundle: input.evidence_bundle,
242
243
  raw: input.raw
package/dist/result.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  nonEmptyString,
8
8
  normalizeTerminalMetadata,
9
9
  recordValue
10
- } from "./chunk-W7VTDN4T.js";
10
+ } from "./chunk-DUFDZJOF.js";
11
11
  export {
12
12
  applyTerminalMetadata,
13
13
  compactRecord,
@@ -0,0 +1,212 @@
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/run-card.ts
31
+ var run_card_exports = {};
32
+ __export(run_card_exports, {
33
+ RIDDLE_PROOF_RUN_CARD_VERSION: () => RIDDLE_PROOF_RUN_CARD_VERSION,
34
+ createRiddleProofRunCard: () => createRiddleProofRunCard
35
+ });
36
+ module.exports = __toCommonJS(run_card_exports);
37
+
38
+ // src/result.ts
39
+ function isTerminalStatus(status) {
40
+ return status === "blocked" || status === "failed" || status === "ready_to_ship" || status === "shipped" || status === "completed";
41
+ }
42
+ function compactRecord(input) {
43
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0 && value !== null && value !== ""));
44
+ }
45
+ function nonEmptyString(value) {
46
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
47
+ }
48
+ function recordValue(value) {
49
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
50
+ }
51
+
52
+ // src/checkpoint.ts
53
+ var import_node_crypto = __toESM(require("crypto"), 1);
54
+ function statePathsForRunState(state, engineStatePath) {
55
+ return compactRecord({
56
+ wrapper_state_path: state.state_path || state.request.harness_state_path || null,
57
+ engine_state_path: engineStatePath || state.request.engine_state_path || null,
58
+ resume_state_path: engineStatePath || state.request.engine_state_path || null
59
+ });
60
+ }
61
+
62
+ // src/run-card.ts
63
+ var RIDDLE_PROOF_RUN_CARD_VERSION = "riddle-proof.run-card.v1";
64
+ function elapsedMs(start, end) {
65
+ const startMs = start ? Date.parse(start) : NaN;
66
+ const endMs = end ? Date.parse(end) : NaN;
67
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
68
+ return Math.max(0, endMs - startMs);
69
+ }
70
+ function jsonCloneRecord(value) {
71
+ const record = recordValue(value);
72
+ if (!record) return void 0;
73
+ try {
74
+ return JSON.parse(JSON.stringify(record));
75
+ } catch {
76
+ return { ...record };
77
+ }
78
+ }
79
+ function compactText(value, limit = 600) {
80
+ const text = nonEmptyString(value);
81
+ if (!text) return void 0;
82
+ return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
83
+ }
84
+ function visualDeltaFrom(input) {
85
+ const fullState = input.fullRiddleState || {};
86
+ const bundle = recordValue(fullState.evidence_bundle);
87
+ const after = recordValue(bundle?.after);
88
+ const afterDelta = recordValue(after?.visual_delta);
89
+ if (afterDelta && Object.keys(afterDelta).length) return afterDelta;
90
+ const requestDelta = recordValue(recordValue(fullState.proof_assessment_request)?.visual_delta);
91
+ if (requestDelta && Object.keys(requestDelta).length) return requestDelta;
92
+ const packetDelta = recordValue(input.runState.checkpoint_packet?.evidence_excerpt?.visual_delta);
93
+ return packetDelta && Object.keys(packetDelta).length ? packetDelta : void 0;
94
+ }
95
+ function artifactsFrom(input) {
96
+ const packetArtifacts = input.runState.checkpoint_packet?.artifacts;
97
+ if (packetArtifacts?.length) return packetArtifacts.slice(0, 12);
98
+ const fullState = input.fullRiddleState || {};
99
+ const artifacts = [];
100
+ for (const role of ["before", "prod", "after"]) {
101
+ const url = nonEmptyString(fullState[`${role}_cdn`]) || nonEmptyString(input.runState[`${role}_artifact_url`]);
102
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
103
+ }
104
+ return artifacts.length ? artifacts : void 0;
105
+ }
106
+ function ownerFor(state) {
107
+ if (state.status === "awaiting_checkpoint") {
108
+ const role = nonEmptyString(state.checkpoint_packet?.routing_hint?.suggested_role);
109
+ return role || "supervising_agent";
110
+ }
111
+ if (state.status === "running") return "engine";
112
+ if (state.status === "blocked" || state.status === "failed") return "human_or_operator";
113
+ return "none";
114
+ }
115
+ function actionFor(state) {
116
+ if (state.status === "awaiting_checkpoint") return state.checkpoint_packet?.question || "Answer the pending checkpoint.";
117
+ if (state.status === "running") return "Continue the current Riddle Proof stage.";
118
+ 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.";
119
+ if (state.status === "ready_to_ship") return "Ship is held by policy; review PR/ship policy before advancing.";
120
+ return "No next action; run is terminal.";
121
+ }
122
+ function evidenceIssueCode(input) {
123
+ const packetIssue = nonEmptyString(input.runState.checkpoint_packet?.evidence_excerpt?.evidence_issue_code);
124
+ if (packetIssue) return packetIssue;
125
+ const assessmentIssue = nonEmptyString(recordValue(input.fullRiddleState?.proof_assessment)?.evidence_issue_code);
126
+ if (assessmentIssue) return assessmentIssue;
127
+ const delta = visualDeltaFrom(input);
128
+ const status = nonEmptyString(delta?.status);
129
+ if (status === "unmeasured") {
130
+ const reason = `${nonEmptyString(delta?.reason) || ""}
131
+ ${input.runState.blocker?.message || ""}`.toLowerCase();
132
+ return reason.includes("fetch") || reason.includes("allowlist") || reason.includes("registered domain") || reason.includes("high risk") || reason.includes("comparator") ? "comparator_fetch_blocked" : "visual_delta_unmeasured";
133
+ }
134
+ if (status === "measured" && delta?.passed === false) return "semantic_proof_failed";
135
+ return void 0;
136
+ }
137
+ function createRiddleProofRunCard(state, input = {}) {
138
+ const at = input.at || (/* @__PURE__ */ new Date()).toISOString();
139
+ const fullState = input.fullRiddleState || {};
140
+ const packet = state.checkpoint_packet;
141
+ const latestEvent = state.events[state.events.length - 1];
142
+ const bundle = recordValue(fullState.evidence_bundle);
143
+ 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);
144
+ const required = jsonCloneRecord(recordValue(artifactContract)?.required);
145
+ const statePaths = input.state_paths || state.state_paths || statePathsForRunState(state);
146
+ const visualDelta = visualDeltaFrom({ fullRiddleState: fullState, runState: state });
147
+ const artifacts = artifactsFrom({ fullRiddleState: fullState, runState: state });
148
+ return {
149
+ version: RIDDLE_PROOF_RUN_CARD_VERSION,
150
+ run_id: state.run_id || "unknown",
151
+ status: state.status,
152
+ goal: compactRecord({
153
+ repo: state.request.repo || nonEmptyString(fullState.repo),
154
+ branch: state.request.branch || nonEmptyString(fullState.branch),
155
+ change_request: state.request.change_request || nonEmptyString(fullState.change_request),
156
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
157
+ success_criteria: state.request.success_criteria
158
+ }),
159
+ durable_state: compactRecord({
160
+ ...statePaths,
161
+ worktree_path: state.worktree_path || nonEmptyString(fullState.after_worktree) || null,
162
+ branch: state.branch || nonEmptyString(fullState.branch) || null
163
+ }),
164
+ current_phase: compactRecord({
165
+ stage: state.current_stage ?? null,
166
+ checkpoint: state.last_checkpoint ?? packet?.checkpoint ?? null,
167
+ latest_event: latestEvent?.kind ?? null,
168
+ elapsed_ms: elapsedMs(state.created_at, at),
169
+ stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
170
+ iterations: state.iterations
171
+ }),
172
+ owner_next_action: compactRecord({
173
+ owner: ownerFor(state),
174
+ action: actionFor(state),
175
+ checkpoint_kind: packet?.kind || null,
176
+ allowed_decisions: packet?.allowed_decisions,
177
+ retryable: state.status === "running" || state.status === "awaiting_checkpoint",
178
+ reason: state.blocker?.code || packet?.summary || latestEvent?.summary || null
179
+ }),
180
+ evidence_contract: compactRecord({
181
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
182
+ required,
183
+ artifact_contract: artifactContract,
184
+ proof_plan: compactText(state.proof_contract?.proof_plan || fullState.proof_plan, 600),
185
+ stop_condition: compactText(state.proof_contract?.stop_condition, 400)
186
+ }),
187
+ latest_evidence: compactRecord({
188
+ before_url: nonEmptyString(fullState.before_cdn) || state.before_artifact_url || null,
189
+ prod_url: nonEmptyString(fullState.prod_cdn) || state.prod_artifact_url || null,
190
+ after_url: nonEmptyString(fullState.after_cdn) || state.after_artifact_url || null,
191
+ visual_delta: visualDelta || null,
192
+ evidence_issue_code: evidenceIssueCode({ fullRiddleState: fullState, runState: state }) || null,
193
+ proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
194
+ artifacts
195
+ }),
196
+ stop_condition: compactRecord({
197
+ status: state.status,
198
+ terminal: isTerminalStatus(state.status),
199
+ blocker_code: state.blocker?.code || null,
200
+ blocker_message: state.blocker?.message || null,
201
+ proof_decision: state.proof_decision,
202
+ merge_recommendation: state.merge_recommendation,
203
+ monitor_should_continue: !isTerminalStatus(state.status)
204
+ }),
205
+ updated_at: state.updated_at
206
+ };
207
+ }
208
+ // Annotate the CommonJS export names for ESM import in node:
209
+ 0 && (module.exports = {
210
+ RIDDLE_PROOF_RUN_CARD_VERSION,
211
+ createRiddleProofRunCard
212
+ });
@@ -0,0 +1,10 @@
1
+ import { RiddleProofRunState, RiddleProofStatePaths, RiddleProofRunCard } from './types.cjs';
2
+
3
+ declare const RIDDLE_PROOF_RUN_CARD_VERSION: "riddle-proof.run-card.v1";
4
+ declare function createRiddleProofRunCard(state: RiddleProofRunState, input?: {
5
+ fullRiddleState?: Record<string, unknown> | null;
6
+ state_paths?: RiddleProofStatePaths;
7
+ at?: string;
8
+ }): RiddleProofRunCard;
9
+
10
+ export { RIDDLE_PROOF_RUN_CARD_VERSION, createRiddleProofRunCard };
@@ -0,0 +1,10 @@
1
+ import { RiddleProofRunState, RiddleProofStatePaths, RiddleProofRunCard } from './types.js';
2
+
3
+ declare const RIDDLE_PROOF_RUN_CARD_VERSION: "riddle-proof.run-card.v1";
4
+ declare function createRiddleProofRunCard(state: RiddleProofRunState, input?: {
5
+ fullRiddleState?: Record<string, unknown> | null;
6
+ state_paths?: RiddleProofStatePaths;
7
+ at?: string;
8
+ }): RiddleProofRunCard;
9
+
10
+ export { RIDDLE_PROOF_RUN_CARD_VERSION, createRiddleProofRunCard };
@@ -0,0 +1,10 @@
1
+ import {
2
+ RIDDLE_PROOF_RUN_CARD_VERSION,
3
+ createRiddleProofRunCard
4
+ } from "./chunk-PLSGW2GI.js";
5
+ import "./chunk-R6SCWJCI.js";
6
+ import "./chunk-DUFDZJOF.js";
7
+ export {
8
+ RIDDLE_PROOF_RUN_CARD_VERSION,
9
+ createRiddleProofRunCard
10
+ };
package/dist/runner.cjs CHANGED
@@ -127,6 +127,7 @@ function createRunResult(input) {
127
127
  checkpoint_summary: state.checkpoint_summary,
128
128
  state_paths: state.state_paths,
129
129
  proof_contract: state.proof_contract,
130
+ run_card: state.run_card,
130
131
  proof_session: state.proof_session,
131
132
  evidence_bundle: input.evidence_bundle,
132
133
  raw: input.raw
@@ -229,6 +230,7 @@ function createRunState(input) {
229
230
  checkpoint_summary: input.checkpoint_summary,
230
231
  state_paths: input.state_paths,
231
232
  proof_contract: input.proof_contract,
233
+ run_card: input.run_card,
232
234
  checkpoint_history: input.checkpoint_history,
233
235
  events: input.events ? [...input.events] : []
234
236
  });
package/dist/runner.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  runRiddleProof
3
- } from "./chunk-MRSYJMF4.js";
4
- import "./chunk-7S7O3NKF.js";
5
- import "./chunk-W7VTDN4T.js";
3
+ } from "./chunk-N3ZNBRIG.js";
4
+ import "./chunk-JOXTKWX6.js";
5
+ import "./chunk-PLSGW2GI.js";
6
+ import "./chunk-R6SCWJCI.js";
7
+ import "./chunk-DUFDZJOF.js";
6
8
  export {
7
9
  runRiddleProof
8
10
  };
package/dist/state.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/state.ts
@@ -47,6 +57,163 @@ function recordValue(value) {
47
57
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
48
58
  }
49
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 visualDeltaFrom(input) {
93
+ const fullState = input.fullRiddleState || {};
94
+ const bundle = recordValue(fullState.evidence_bundle);
95
+ const after = recordValue(bundle?.after);
96
+ const afterDelta = recordValue(after?.visual_delta);
97
+ if (afterDelta && Object.keys(afterDelta).length) return afterDelta;
98
+ const requestDelta = recordValue(recordValue(fullState.proof_assessment_request)?.visual_delta);
99
+ if (requestDelta && Object.keys(requestDelta).length) return requestDelta;
100
+ const packetDelta = recordValue(input.runState.checkpoint_packet?.evidence_excerpt?.visual_delta);
101
+ return packetDelta && Object.keys(packetDelta).length ? packetDelta : void 0;
102
+ }
103
+ function artifactsFrom(input) {
104
+ const packetArtifacts = input.runState.checkpoint_packet?.artifacts;
105
+ if (packetArtifacts?.length) return packetArtifacts.slice(0, 12);
106
+ const fullState = input.fullRiddleState || {};
107
+ const artifacts = [];
108
+ for (const role of ["before", "prod", "after"]) {
109
+ const url = nonEmptyString(fullState[`${role}_cdn`]) || nonEmptyString(input.runState[`${role}_artifact_url`]);
110
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
111
+ }
112
+ return artifacts.length ? artifacts : void 0;
113
+ }
114
+ function ownerFor(state) {
115
+ if (state.status === "awaiting_checkpoint") {
116
+ const role = nonEmptyString(state.checkpoint_packet?.routing_hint?.suggested_role);
117
+ return role || "supervising_agent";
118
+ }
119
+ if (state.status === "running") return "engine";
120
+ if (state.status === "blocked" || state.status === "failed") return "human_or_operator";
121
+ return "none";
122
+ }
123
+ function actionFor(state) {
124
+ if (state.status === "awaiting_checkpoint") return state.checkpoint_packet?.question || "Answer the pending checkpoint.";
125
+ if (state.status === "running") return "Continue the current Riddle Proof stage.";
126
+ 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.";
127
+ if (state.status === "ready_to_ship") return "Ship is held by policy; review PR/ship policy before advancing.";
128
+ return "No next action; run is terminal.";
129
+ }
130
+ function evidenceIssueCode(input) {
131
+ const packetIssue = nonEmptyString(input.runState.checkpoint_packet?.evidence_excerpt?.evidence_issue_code);
132
+ if (packetIssue) return packetIssue;
133
+ const assessmentIssue = nonEmptyString(recordValue(input.fullRiddleState?.proof_assessment)?.evidence_issue_code);
134
+ if (assessmentIssue) return assessmentIssue;
135
+ const delta = visualDeltaFrom(input);
136
+ const status = nonEmptyString(delta?.status);
137
+ if (status === "unmeasured") {
138
+ const reason = `${nonEmptyString(delta?.reason) || ""}
139
+ ${input.runState.blocker?.message || ""}`.toLowerCase();
140
+ return reason.includes("fetch") || reason.includes("allowlist") || reason.includes("registered domain") || reason.includes("high risk") || reason.includes("comparator") ? "comparator_fetch_blocked" : "visual_delta_unmeasured";
141
+ }
142
+ if (status === "measured" && delta?.passed === false) return "semantic_proof_failed";
143
+ return void 0;
144
+ }
145
+ function createRiddleProofRunCard(state, input = {}) {
146
+ const at = input.at || (/* @__PURE__ */ new Date()).toISOString();
147
+ const fullState = input.fullRiddleState || {};
148
+ const packet = state.checkpoint_packet;
149
+ const latestEvent = state.events[state.events.length - 1];
150
+ const bundle = recordValue(fullState.evidence_bundle);
151
+ 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);
152
+ const required = jsonCloneRecord(recordValue(artifactContract)?.required);
153
+ const statePaths = input.state_paths || state.state_paths || statePathsForRunState(state);
154
+ const visualDelta = visualDeltaFrom({ fullRiddleState: fullState, runState: state });
155
+ const artifacts = artifactsFrom({ fullRiddleState: fullState, runState: state });
156
+ return {
157
+ version: RIDDLE_PROOF_RUN_CARD_VERSION,
158
+ run_id: state.run_id || "unknown",
159
+ status: state.status,
160
+ goal: compactRecord({
161
+ repo: state.request.repo || nonEmptyString(fullState.repo),
162
+ branch: state.request.branch || nonEmptyString(fullState.branch),
163
+ change_request: state.request.change_request || nonEmptyString(fullState.change_request),
164
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
165
+ success_criteria: state.request.success_criteria
166
+ }),
167
+ durable_state: compactRecord({
168
+ ...statePaths,
169
+ worktree_path: state.worktree_path || nonEmptyString(fullState.after_worktree) || null,
170
+ branch: state.branch || nonEmptyString(fullState.branch) || null
171
+ }),
172
+ current_phase: compactRecord({
173
+ stage: state.current_stage ?? null,
174
+ checkpoint: state.last_checkpoint ?? packet?.checkpoint ?? null,
175
+ latest_event: latestEvent?.kind ?? null,
176
+ elapsed_ms: elapsedMs(state.created_at, at),
177
+ stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
178
+ iterations: state.iterations
179
+ }),
180
+ owner_next_action: compactRecord({
181
+ owner: ownerFor(state),
182
+ action: actionFor(state),
183
+ checkpoint_kind: packet?.kind || null,
184
+ allowed_decisions: packet?.allowed_decisions,
185
+ retryable: state.status === "running" || state.status === "awaiting_checkpoint",
186
+ reason: state.blocker?.code || packet?.summary || latestEvent?.summary || null
187
+ }),
188
+ evidence_contract: compactRecord({
189
+ verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
190
+ required,
191
+ artifact_contract: artifactContract,
192
+ proof_plan: compactText(state.proof_contract?.proof_plan || fullState.proof_plan, 600),
193
+ stop_condition: compactText(state.proof_contract?.stop_condition, 400)
194
+ }),
195
+ latest_evidence: compactRecord({
196
+ before_url: nonEmptyString(fullState.before_cdn) || state.before_artifact_url || null,
197
+ prod_url: nonEmptyString(fullState.prod_cdn) || state.prod_artifact_url || null,
198
+ after_url: nonEmptyString(fullState.after_cdn) || state.after_artifact_url || null,
199
+ visual_delta: visualDelta || null,
200
+ evidence_issue_code: evidenceIssueCode({ fullRiddleState: fullState, runState: state }) || null,
201
+ proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
202
+ artifacts
203
+ }),
204
+ stop_condition: compactRecord({
205
+ status: state.status,
206
+ terminal: isTerminalStatus(state.status),
207
+ blocker_code: state.blocker?.code || null,
208
+ blocker_message: state.blocker?.message || null,
209
+ proof_decision: state.proof_decision,
210
+ merge_recommendation: state.merge_recommendation,
211
+ monitor_should_continue: !isTerminalStatus(state.status)
212
+ }),
213
+ updated_at: state.updated_at
214
+ };
215
+ }
216
+
50
217
  // src/state.ts
51
218
  var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
52
219
  function timestamp() {
@@ -57,7 +224,7 @@ function createRunId(createdAt) {
57
224
  const entropy = Math.random().toString(36).slice(2, 8) || "run";
58
225
  return `rp_${stamp}_${entropy}`;
59
226
  }
60
- function elapsedMs(start, end) {
227
+ function elapsedMs2(start, end) {
61
228
  const startMs = start ? Date.parse(start) : NaN;
62
229
  const endMs = end ? Date.parse(end) : NaN;
63
230
  if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
@@ -173,6 +340,7 @@ function createRunState(input) {
173
340
  checkpoint_summary: input.checkpoint_summary,
174
341
  state_paths: input.state_paths,
175
342
  proof_contract: input.proof_contract,
343
+ run_card: input.run_card,
176
344
  checkpoint_history: input.checkpoint_history,
177
345
  events: input.events ? [...input.events] : []
178
346
  });
@@ -211,8 +379,8 @@ function appendStageHeartbeat(state, input) {
211
379
  stage: input.stage,
212
380
  summary: input.summary || `${input.stage} stage is active.`,
213
381
  details: compactRecord({
214
- elapsed_ms: elapsedMs(state.created_at, at),
215
- stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
382
+ elapsed_ms: elapsedMs2(state.created_at, at),
383
+ stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
216
384
  wait_reason: input.wait_reason,
217
385
  blocker: input.blocker,
218
386
  ...input.details
@@ -244,13 +412,14 @@ function createRunStatusSnapshot(state, at = timestamp()) {
244
412
  iterations: state.iterations,
245
413
  last_checkpoint: state.last_checkpoint ?? null,
246
414
  updated_at: state.updated_at,
247
- elapsed_ms: elapsedMs(state.created_at, at),
248
- stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
415
+ elapsed_ms: elapsedMs2(state.created_at, at),
416
+ stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
249
417
  blocker: state.blocker,
250
418
  checkpoint_packet: state.checkpoint_packet,
251
419
  checkpoint_summary: state.checkpoint_summary,
252
420
  state_paths: state.state_paths,
253
421
  proof_contract: state.proof_contract,
422
+ run_card: state.run_card || createRiddleProofRunCard(state, { at }),
254
423
  latest_event: latestEvent
255
424
  });
256
425
  }
package/dist/state.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { RiddleProofRunParams, RiddleProofStatus, RiddleProofStage, RiddleProofCheckpointPacket, RiddleProofCheckpointSummary, RiddleProofStatePaths, RiddleProofProofContract, RiddleProofCheckpointResponse, RiddleProofEvent, RiddleProofRunState, RiddleProofPrLifecycleState, RiddleProofRunStatusSnapshot, IntegrationContext } from './types.cjs';
1
+ import { RiddleProofRunParams, RiddleProofStatus, RiddleProofStage, RiddleProofCheckpointPacket, RiddleProofCheckpointSummary, RiddleProofStatePaths, RiddleProofProofContract, RiddleProofRunCard, RiddleProofCheckpointResponse, RiddleProofEvent, RiddleProofRunState, RiddleProofPrLifecycleState, RiddleProofRunStatusSnapshot, IntegrationContext } from './types.cjs';
2
2
 
3
3
  declare const RIDDLE_PROOF_RUN_STATE_VERSION: "riddle-proof.run-state.v1";
4
4
  interface CreateRunStateInput {
@@ -18,6 +18,7 @@ interface CreateRunStateInput {
18
18
  checkpoint_summary?: RiddleProofCheckpointSummary;
19
19
  state_paths?: RiddleProofStatePaths;
20
20
  proof_contract?: RiddleProofProofContract;
21
+ run_card?: RiddleProofRunCard;
21
22
  checkpoint_history?: Array<{
22
23
  ts: string;
23
24
  packet?: RiddleProofCheckpointPacket;
package/dist/state.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RiddleProofRunParams, RiddleProofStatus, RiddleProofStage, RiddleProofCheckpointPacket, RiddleProofCheckpointSummary, RiddleProofStatePaths, RiddleProofProofContract, RiddleProofCheckpointResponse, RiddleProofEvent, RiddleProofRunState, RiddleProofPrLifecycleState, RiddleProofRunStatusSnapshot, IntegrationContext } from './types.js';
1
+ import { RiddleProofRunParams, RiddleProofStatus, RiddleProofStage, RiddleProofCheckpointPacket, RiddleProofCheckpointSummary, RiddleProofStatePaths, RiddleProofProofContract, RiddleProofRunCard, RiddleProofCheckpointResponse, RiddleProofEvent, RiddleProofRunState, RiddleProofPrLifecycleState, RiddleProofRunStatusSnapshot, IntegrationContext } from './types.js';
2
2
 
3
3
  declare const RIDDLE_PROOF_RUN_STATE_VERSION: "riddle-proof.run-state.v1";
4
4
  interface CreateRunStateInput {
@@ -18,6 +18,7 @@ interface CreateRunStateInput {
18
18
  checkpoint_summary?: RiddleProofCheckpointSummary;
19
19
  state_paths?: RiddleProofStatePaths;
20
20
  proof_contract?: RiddleProofProofContract;
21
+ run_card?: RiddleProofRunCard;
21
22
  checkpoint_history?: Array<{
22
23
  ts: string;
23
24
  packet?: RiddleProofCheckpointPacket;