@riddledc/riddle-proof 0.5.38 → 0.5.39

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.
@@ -0,0 +1,185 @@
1
+ import {
2
+ compactRecord,
3
+ nonEmptyString,
4
+ recordValue
5
+ } from "./chunk-Z7QUCDPT.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 compactText(value, limit = 1600) {
24
+ const text = nonEmptyString(value);
25
+ if (!text) return void 0;
26
+ return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
27
+ }
28
+ function responseSchemaForAuthorPacket() {
29
+ return {
30
+ type: "object",
31
+ required: ["version", "run_id", "checkpoint", "decision", "summary", "payload", "created_at"],
32
+ additionalProperties: false,
33
+ properties: {
34
+ version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
35
+ run_id: { type: "string" },
36
+ checkpoint: { type: "string" },
37
+ resume_token: { type: "string" },
38
+ decision: {
39
+ type: "string",
40
+ enum: ["author_packet", "needs_recon", "blocked", "human_review"]
41
+ },
42
+ summary: { type: "string" },
43
+ payload: {
44
+ type: "object",
45
+ description: "For decision=author_packet, provide the proof packet itself or {author_packet:{...}} with proof_plan and capture_script."
46
+ },
47
+ reasons: { type: "array", items: { type: "string" } },
48
+ continue_with_stage: { type: "string", enum: ["author", "recon"] },
49
+ source: {
50
+ type: "object",
51
+ properties: {
52
+ kind: { type: "string" },
53
+ session_id: { type: "string" },
54
+ user_id: { type: "string" }
55
+ }
56
+ },
57
+ created_at: { type: "string" }
58
+ }
59
+ };
60
+ }
61
+ function resumeTokenFor(input) {
62
+ const hash = crypto.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
63
+ return `rpchk_${hash}`;
64
+ }
65
+ function artifactsFromState(state) {
66
+ const artifacts = [];
67
+ for (const role of ["before", "prod", "after"]) {
68
+ const url = nonEmptyString(state?.[`${role}_cdn`]);
69
+ if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
70
+ }
71
+ const authorRequest = recordValue(state?.author_request);
72
+ const latestAttempt = recordValue(authorRequest?.latest_attempt);
73
+ const observations = recordValue(latestAttempt?.observations);
74
+ for (const [label, observation] of Object.entries(observations || {})) {
75
+ const record = recordValue(observation);
76
+ const url = nonEmptyString(record?.url);
77
+ if (url && !artifacts.some((artifact) => artifact.url === url)) {
78
+ artifacts.push({
79
+ role: label === "before" || label === "prod" ? label : "json",
80
+ url,
81
+ name: `${label}-observation`,
82
+ summary: compactText(record?.reason, 240)
83
+ });
84
+ }
85
+ }
86
+ return artifacts.slice(0, 16);
87
+ }
88
+ function buildAuthorCheckpointPacket(input) {
89
+ const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
90
+ const stage = "author";
91
+ const runId = input.runState.run_id || "unknown";
92
+ const fullState = input.fullRiddleState || {};
93
+ const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
94
+ const authorRequest = recordValue(fullState.author_request) || recordValue(fullState.proof_plan_request) || recordValue(decisionDetails?.authorRequest) || {};
95
+ const fallbackDefaults = recordValue(authorRequest.fallback_defaults) || {};
96
+ const reconResults = recordValue(fullState.recon_results);
97
+ const checkpointContract = recordValue(input.engineResult.checkpointContract);
98
+ const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.author_summary) || "Author checkpoint needs a supervising proof packet.";
99
+ return {
100
+ version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
101
+ run_id: runId,
102
+ state_path: input.runState.state_path,
103
+ stage,
104
+ checkpoint,
105
+ kind: "author_proof",
106
+ summary,
107
+ 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.",
108
+ change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
109
+ context: input.request.context,
110
+ artifacts: artifactsFromState(fullState),
111
+ state_excerpt: compactRecord({
112
+ repo: input.request.repo || fullState.repo,
113
+ branch: input.request.branch || fullState.branch,
114
+ verification_mode: input.request.verification_mode || fullState.verification_mode,
115
+ reference: input.request.reference || fullState.reference,
116
+ server_path: fullState.server_path,
117
+ wait_for_selector: fullState.wait_for_selector,
118
+ author_summary: fullState.author_summary,
119
+ author_request: jsonCloneRecord(authorRequest),
120
+ recon_baseline_understanding: jsonCloneRecord(fullState.recon_baseline_understanding),
121
+ fallback_defaults: jsonCloneRecord(fallbackDefaults)
122
+ }),
123
+ evidence_excerpt: compactRecord({
124
+ recon_results: jsonCloneRecord(reconResults),
125
+ checkpoint_contract: jsonCloneRecord(checkpointContract)
126
+ }),
127
+ allowed_decisions: ["author_packet", "needs_recon", "blocked", "human_review"],
128
+ response_schema: responseSchemaForAuthorPacket(),
129
+ routing_hint: {
130
+ suggested_role: "proof_author",
131
+ visibility: input.visibility || "quiet",
132
+ urgency: "normal",
133
+ can_auto_answer: input.visibility !== "manual"
134
+ },
135
+ resume_token: resumeTokenFor({
136
+ runId,
137
+ statePath: input.engineResult.state_path || input.request.engine_state_path || null,
138
+ checkpoint,
139
+ stage
140
+ }),
141
+ created_at: input.created_at || timestamp()
142
+ };
143
+ }
144
+ function normalizeCheckpointResponse(value) {
145
+ const record = recordValue(value);
146
+ if (!record) return null;
147
+ const version = nonEmptyString(record.version);
148
+ const runId = nonEmptyString(record.run_id);
149
+ const checkpoint = nonEmptyString(record.checkpoint);
150
+ const decision = nonEmptyString(record.decision);
151
+ const summary = nonEmptyString(record.summary);
152
+ if (version !== RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION || !runId || !checkpoint || !decision || !summary) {
153
+ return null;
154
+ }
155
+ return compactRecord({
156
+ version: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
157
+ run_id: runId,
158
+ checkpoint,
159
+ resume_token: nonEmptyString(record.resume_token),
160
+ decision,
161
+ summary,
162
+ payload: jsonCloneRecord(record.payload),
163
+ reasons: Array.isArray(record.reasons) ? record.reasons.filter((item) => typeof item === "string") : void 0,
164
+ continue_with_stage: nonEmptyString(record.continue_with_stage),
165
+ source: jsonCloneRecord(record.source),
166
+ created_at: nonEmptyString(record.created_at) || timestamp()
167
+ });
168
+ }
169
+ function authorPacketPayloadFromCheckpointResponse(response) {
170
+ if (response.decision !== "author_packet") return null;
171
+ const payload = recordValue(response.payload);
172
+ if (!payload) return null;
173
+ const nested = recordValue(payload.author_packet);
174
+ const candidate = nested || payload;
175
+ if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
176
+ return candidate;
177
+ }
178
+
179
+ export {
180
+ RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
181
+ RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
182
+ buildAuthorCheckpointPacket,
183
+ normalizeCheckpointResponse,
184
+ authorPacketPayloadFromCheckpointResponse
185
+ };
@@ -3,7 +3,7 @@ import {
3
3
  isTerminalStatus,
4
4
  nonEmptyString,
5
5
  recordValue
6
- } from "./chunk-J2MERROF.js";
6
+ } from "./chunk-Z7QUCDPT.js";
7
7
 
8
8
  // src/state.ts
9
9
  var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
@@ -127,6 +127,8 @@ function createRunState(input) {
127
127
  request: normalizeRunParams(input.request),
128
128
  iterations: input.iterations ?? 0,
129
129
  last_checkpoint: input.last_checkpoint ?? null,
130
+ checkpoint_packet: input.checkpoint_packet,
131
+ checkpoint_history: input.checkpoint_history,
130
132
  events: input.events ? [...input.events] : []
131
133
  });
132
134
  }
@@ -200,6 +202,7 @@ function createRunStatusSnapshot(state, at = timestamp()) {
200
202
  elapsed_ms: elapsedMs(state.created_at, at),
201
203
  stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
202
204
  blocker: state.blocker,
205
+ checkpoint_packet: state.checkpoint_packet,
203
206
  latest_event: latestEvent
204
207
  });
205
208
  }
@@ -202,6 +202,7 @@ function createRunResult(input) {
202
202
  merge_recommendation: state.merge_recommendation,
203
203
  finalized: state.finalized,
204
204
  blocker: state.blocker,
205
+ checkpoint_packet: state.checkpoint_packet,
205
206
  proof_session: state.proof_session,
206
207
  evidence_bundle: input.evidence_bundle,
207
208
  raw: input.raw