@riddledc/riddle-proof 0.5.37 → 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.
- package/README.md +12 -8
- package/dist/checkpoint.cjs +230 -0
- package/dist/checkpoint.d.cts +22 -0
- package/dist/checkpoint.d.ts +22 -0
- package/dist/checkpoint.js +15 -0
- package/dist/{chunk-GN7HSZ6G.js → chunk-ORRP7CXT.js} +161 -3
- package/dist/{chunk-MQ2BHHLX.js → chunk-RDTMR7XR.js} +2 -2
- package/dist/chunk-UQPTCP4D.js +185 -0
- package/dist/{chunk-OASB3CYU.js → chunk-Z3BWCHFV.js} +4 -1
- package/dist/{chunk-J2MERROF.js → chunk-Z7QUCDPT.js} +1 -0
- package/dist/engine-harness.cjs +342 -13
- package/dist/engine-harness.d.cts +6 -2
- package/dist/engine-harness.d.ts +6 -2
- package/dist/engine-harness.js +4 -3
- package/dist/index.cjs +356 -17
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +25 -13
- package/dist/openclaw.js +2 -2
- package/dist/proof-run-engine.d.cts +3 -3
- package/dist/proof-run-engine.d.ts +3 -3
- package/dist/result.cjs +1 -0
- package/dist/result.js +1 -1
- package/dist/runner.cjs +3 -0
- package/dist/runner.js +3 -3
- package/dist/state.cjs +3 -0
- package/dist/state.d.cts +7 -1
- package/dist/state.d.ts +7 -1
- package/dist/state.js +2 -2
- package/dist/types.d.cts +63 -2
- package/dist/types.d.ts +63 -2
- package/lib/workspace-core.mjs +32 -1
- package/package.json +7 -2
- package/runtime/lib/setup.py +55 -9
package/README.md
CHANGED
|
@@ -82,21 +82,25 @@ updates Discord, OpenClaw, GitHub, or another integration.
|
|
|
82
82
|
|
|
83
83
|
The packaged proof-run setup uses isolated git worktrees for before and after
|
|
84
84
|
states. By default those worktrees now live under
|
|
85
|
-
`/tmp/.riddle-proof-worktrees`, with dependency caches under
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
`/var/tmp/riddle-proof/.riddle-proof-worktrees`, with dependency caches under
|
|
86
|
+
the matching disk-backed scratch root. This keeps repeated `node_modules` cache
|
|
87
|
+
materialization off tmpfs `/tmp` and away from EFS or other shared workspace
|
|
88
|
+
filesystems.
|
|
89
89
|
|
|
90
90
|
Set `RIDDLE_PROOF_WORKTREE_ROOT` to choose an explicit location. Set
|
|
91
91
|
`RIDDLE_PROOF_USE_WORKSPACE_WORKTREE_ROOT=1` to keep the previous behavior of
|
|
92
|
-
placing proof worktrees next to the active repository.
|
|
92
|
+
placing proof worktrees next to the active repository. Set
|
|
93
|
+
`RIDDLE_PROOF_SCRATCH_ROOT` to choose the scratch parent, or
|
|
94
|
+
`RIDDLE_PROOF_USE_TMP_SCRATCH=1` to force tmp-backed scratch for a short-lived
|
|
95
|
+
test.
|
|
93
96
|
|
|
94
97
|
When local scratch storage is low, setup prunes stale
|
|
95
98
|
`riddle-proof-*` worktrees from the scratch root before creating the next run.
|
|
96
99
|
This preserves the dependency cache for speed while avoiding old failed runs
|
|
97
|
-
filling
|
|
98
|
-
|
|
99
|
-
`
|
|
100
|
+
filling the scratch disk. Setup also records scratch disk snapshots in the run
|
|
101
|
+
state so disk blockers are visible during proof inspection. Set
|
|
102
|
+
`RIDDLE_PROOF_KEEP_SCRATCH_WORKTREES=1` to disable that cleanup for debugging,
|
|
103
|
+
or tune the low-space threshold with `RIDDLE_PROOF_MIN_SCRATCH_FREE_MB`.
|
|
100
104
|
|
|
101
105
|
## Capture Diagnostics
|
|
102
106
|
|
|
@@ -0,0 +1,230 @@
|
|
|
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/checkpoint.ts
|
|
31
|
+
var checkpoint_exports = {};
|
|
32
|
+
__export(checkpoint_exports, {
|
|
33
|
+
RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION: () => RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
34
|
+
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION: () => RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
35
|
+
authorPacketPayloadFromCheckpointResponse: () => authorPacketPayloadFromCheckpointResponse,
|
|
36
|
+
buildAuthorCheckpointPacket: () => buildAuthorCheckpointPacket,
|
|
37
|
+
normalizeCheckpointResponse: () => normalizeCheckpointResponse
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(checkpoint_exports);
|
|
40
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
41
|
+
|
|
42
|
+
// src/result.ts
|
|
43
|
+
function compactRecord(input) {
|
|
44
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0 && value !== null && value !== ""));
|
|
45
|
+
}
|
|
46
|
+
function nonEmptyString(value) {
|
|
47
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
48
|
+
}
|
|
49
|
+
function recordValue(value) {
|
|
50
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/checkpoint.ts
|
|
54
|
+
var RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION = "riddle-proof.checkpoint.v1";
|
|
55
|
+
var RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION = "riddle-proof.checkpoint_response.v1";
|
|
56
|
+
function timestamp() {
|
|
57
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
58
|
+
}
|
|
59
|
+
function jsonCloneRecord(value) {
|
|
60
|
+
const record = recordValue(value);
|
|
61
|
+
if (!record) return void 0;
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(JSON.stringify(record));
|
|
64
|
+
} catch {
|
|
65
|
+
return { ...record };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function compactText(value, limit = 1600) {
|
|
69
|
+
const text = nonEmptyString(value);
|
|
70
|
+
if (!text) return void 0;
|
|
71
|
+
return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
|
|
72
|
+
}
|
|
73
|
+
function responseSchemaForAuthorPacket() {
|
|
74
|
+
return {
|
|
75
|
+
type: "object",
|
|
76
|
+
required: ["version", "run_id", "checkpoint", "decision", "summary", "payload", "created_at"],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
properties: {
|
|
79
|
+
version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
|
|
80
|
+
run_id: { type: "string" },
|
|
81
|
+
checkpoint: { type: "string" },
|
|
82
|
+
resume_token: { type: "string" },
|
|
83
|
+
decision: {
|
|
84
|
+
type: "string",
|
|
85
|
+
enum: ["author_packet", "needs_recon", "blocked", "human_review"]
|
|
86
|
+
},
|
|
87
|
+
summary: { type: "string" },
|
|
88
|
+
payload: {
|
|
89
|
+
type: "object",
|
|
90
|
+
description: "For decision=author_packet, provide the proof packet itself or {author_packet:{...}} with proof_plan and capture_script."
|
|
91
|
+
},
|
|
92
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
93
|
+
continue_with_stage: { type: "string", enum: ["author", "recon"] },
|
|
94
|
+
source: {
|
|
95
|
+
type: "object",
|
|
96
|
+
properties: {
|
|
97
|
+
kind: { type: "string" },
|
|
98
|
+
session_id: { type: "string" },
|
|
99
|
+
user_id: { type: "string" }
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
created_at: { type: "string" }
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function resumeTokenFor(input) {
|
|
107
|
+
const hash = import_node_crypto.default.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
|
|
108
|
+
return `rpchk_${hash}`;
|
|
109
|
+
}
|
|
110
|
+
function artifactsFromState(state) {
|
|
111
|
+
const artifacts = [];
|
|
112
|
+
for (const role of ["before", "prod", "after"]) {
|
|
113
|
+
const url = nonEmptyString(state?.[`${role}_cdn`]);
|
|
114
|
+
if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
|
|
115
|
+
}
|
|
116
|
+
const authorRequest = recordValue(state?.author_request);
|
|
117
|
+
const latestAttempt = recordValue(authorRequest?.latest_attempt);
|
|
118
|
+
const observations = recordValue(latestAttempt?.observations);
|
|
119
|
+
for (const [label, observation] of Object.entries(observations || {})) {
|
|
120
|
+
const record = recordValue(observation);
|
|
121
|
+
const url = nonEmptyString(record?.url);
|
|
122
|
+
if (url && !artifacts.some((artifact) => artifact.url === url)) {
|
|
123
|
+
artifacts.push({
|
|
124
|
+
role: label === "before" || label === "prod" ? label : "json",
|
|
125
|
+
url,
|
|
126
|
+
name: `${label}-observation`,
|
|
127
|
+
summary: compactText(record?.reason, 240)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return artifacts.slice(0, 16);
|
|
132
|
+
}
|
|
133
|
+
function buildAuthorCheckpointPacket(input) {
|
|
134
|
+
const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
|
|
135
|
+
const stage = "author";
|
|
136
|
+
const runId = input.runState.run_id || "unknown";
|
|
137
|
+
const fullState = input.fullRiddleState || {};
|
|
138
|
+
const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
|
|
139
|
+
const authorRequest = recordValue(fullState.author_request) || recordValue(fullState.proof_plan_request) || recordValue(decisionDetails?.authorRequest) || {};
|
|
140
|
+
const fallbackDefaults = recordValue(authorRequest.fallback_defaults) || {};
|
|
141
|
+
const reconResults = recordValue(fullState.recon_results);
|
|
142
|
+
const checkpointContract = recordValue(input.engineResult.checkpointContract);
|
|
143
|
+
const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.author_summary) || "Author checkpoint needs a supervising proof packet.";
|
|
144
|
+
return {
|
|
145
|
+
version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
146
|
+
run_id: runId,
|
|
147
|
+
state_path: input.runState.state_path,
|
|
148
|
+
stage,
|
|
149
|
+
checkpoint,
|
|
150
|
+
kind: "author_proof",
|
|
151
|
+
summary,
|
|
152
|
+
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.",
|
|
153
|
+
change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
|
|
154
|
+
context: input.request.context,
|
|
155
|
+
artifacts: artifactsFromState(fullState),
|
|
156
|
+
state_excerpt: compactRecord({
|
|
157
|
+
repo: input.request.repo || fullState.repo,
|
|
158
|
+
branch: input.request.branch || fullState.branch,
|
|
159
|
+
verification_mode: input.request.verification_mode || fullState.verification_mode,
|
|
160
|
+
reference: input.request.reference || fullState.reference,
|
|
161
|
+
server_path: fullState.server_path,
|
|
162
|
+
wait_for_selector: fullState.wait_for_selector,
|
|
163
|
+
author_summary: fullState.author_summary,
|
|
164
|
+
author_request: jsonCloneRecord(authorRequest),
|
|
165
|
+
recon_baseline_understanding: jsonCloneRecord(fullState.recon_baseline_understanding),
|
|
166
|
+
fallback_defaults: jsonCloneRecord(fallbackDefaults)
|
|
167
|
+
}),
|
|
168
|
+
evidence_excerpt: compactRecord({
|
|
169
|
+
recon_results: jsonCloneRecord(reconResults),
|
|
170
|
+
checkpoint_contract: jsonCloneRecord(checkpointContract)
|
|
171
|
+
}),
|
|
172
|
+
allowed_decisions: ["author_packet", "needs_recon", "blocked", "human_review"],
|
|
173
|
+
response_schema: responseSchemaForAuthorPacket(),
|
|
174
|
+
routing_hint: {
|
|
175
|
+
suggested_role: "proof_author",
|
|
176
|
+
visibility: input.visibility || "quiet",
|
|
177
|
+
urgency: "normal",
|
|
178
|
+
can_auto_answer: input.visibility !== "manual"
|
|
179
|
+
},
|
|
180
|
+
resume_token: resumeTokenFor({
|
|
181
|
+
runId,
|
|
182
|
+
statePath: input.engineResult.state_path || input.request.engine_state_path || null,
|
|
183
|
+
checkpoint,
|
|
184
|
+
stage
|
|
185
|
+
}),
|
|
186
|
+
created_at: input.created_at || timestamp()
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function normalizeCheckpointResponse(value) {
|
|
190
|
+
const record = recordValue(value);
|
|
191
|
+
if (!record) return null;
|
|
192
|
+
const version = nonEmptyString(record.version);
|
|
193
|
+
const runId = nonEmptyString(record.run_id);
|
|
194
|
+
const checkpoint = nonEmptyString(record.checkpoint);
|
|
195
|
+
const decision = nonEmptyString(record.decision);
|
|
196
|
+
const summary = nonEmptyString(record.summary);
|
|
197
|
+
if (version !== RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION || !runId || !checkpoint || !decision || !summary) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
return compactRecord({
|
|
201
|
+
version: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
202
|
+
run_id: runId,
|
|
203
|
+
checkpoint,
|
|
204
|
+
resume_token: nonEmptyString(record.resume_token),
|
|
205
|
+
decision,
|
|
206
|
+
summary,
|
|
207
|
+
payload: jsonCloneRecord(record.payload),
|
|
208
|
+
reasons: Array.isArray(record.reasons) ? record.reasons.filter((item) => typeof item === "string") : void 0,
|
|
209
|
+
continue_with_stage: nonEmptyString(record.continue_with_stage),
|
|
210
|
+
source: jsonCloneRecord(record.source),
|
|
211
|
+
created_at: nonEmptyString(record.created_at) || timestamp()
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function authorPacketPayloadFromCheckpointResponse(response) {
|
|
215
|
+
if (response.decision !== "author_packet") return null;
|
|
216
|
+
const payload = recordValue(response.payload);
|
|
217
|
+
if (!payload) return null;
|
|
218
|
+
const nested = recordValue(payload.author_packet);
|
|
219
|
+
const candidate = nested || payload;
|
|
220
|
+
if (!nonEmptyString(candidate.proof_plan) || !nonEmptyString(candidate.capture_script)) return null;
|
|
221
|
+
return candidate;
|
|
222
|
+
}
|
|
223
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
+
0 && (module.exports = {
|
|
225
|
+
RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
226
|
+
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
227
|
+
authorPacketPayloadFromCheckpointResponse,
|
|
228
|
+
buildAuthorCheckpointPacket,
|
|
229
|
+
normalizeCheckpointResponse
|
|
230
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RiddleProofCheckpointResponse, RiddleProofRunParams, RiddleProofRunState, RiddleProofCheckpointPacket } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
declare const RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION: "riddle-proof.checkpoint.v1";
|
|
4
|
+
declare const RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION: "riddle-proof.checkpoint_response.v1";
|
|
5
|
+
declare function buildAuthorCheckpointPacket(input: {
|
|
6
|
+
request: RiddleProofRunParams;
|
|
7
|
+
runState: RiddleProofRunState;
|
|
8
|
+
engineResult: {
|
|
9
|
+
state_path?: string | null;
|
|
10
|
+
checkpoint?: string | null;
|
|
11
|
+
checkpointContract?: Record<string, unknown> | null;
|
|
12
|
+
decisionRequest?: Record<string, unknown> | null;
|
|
13
|
+
summary?: string;
|
|
14
|
+
};
|
|
15
|
+
fullRiddleState?: Record<string, unknown> | null;
|
|
16
|
+
visibility?: "liveblog" | "quiet" | "terminal_only" | "manual" | string;
|
|
17
|
+
created_at?: string;
|
|
18
|
+
}): RiddleProofCheckpointPacket;
|
|
19
|
+
declare function normalizeCheckpointResponse(value: unknown): RiddleProofCheckpointResponse | null;
|
|
20
|
+
declare function authorPacketPayloadFromCheckpointResponse(response: RiddleProofCheckpointResponse): Record<string, unknown> | null;
|
|
21
|
+
|
|
22
|
+
export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, normalizeCheckpointResponse };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RiddleProofCheckpointResponse, RiddleProofRunParams, RiddleProofRunState, RiddleProofCheckpointPacket } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare const RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION: "riddle-proof.checkpoint.v1";
|
|
4
|
+
declare const RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION: "riddle-proof.checkpoint_response.v1";
|
|
5
|
+
declare function buildAuthorCheckpointPacket(input: {
|
|
6
|
+
request: RiddleProofRunParams;
|
|
7
|
+
runState: RiddleProofRunState;
|
|
8
|
+
engineResult: {
|
|
9
|
+
state_path?: string | null;
|
|
10
|
+
checkpoint?: string | null;
|
|
11
|
+
checkpointContract?: Record<string, unknown> | null;
|
|
12
|
+
decisionRequest?: Record<string, unknown> | null;
|
|
13
|
+
summary?: string;
|
|
14
|
+
};
|
|
15
|
+
fullRiddleState?: Record<string, unknown> | null;
|
|
16
|
+
visibility?: "liveblog" | "quiet" | "terminal_only" | "manual" | string;
|
|
17
|
+
created_at?: string;
|
|
18
|
+
}): RiddleProofCheckpointPacket;
|
|
19
|
+
declare function normalizeCheckpointResponse(value: unknown): RiddleProofCheckpointResponse | null;
|
|
20
|
+
declare function authorPacketPayloadFromCheckpointResponse(response: RiddleProofCheckpointResponse): Record<string, unknown> | null;
|
|
21
|
+
|
|
22
|
+
export { RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION, RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION, authorPacketPayloadFromCheckpointResponse, buildAuthorCheckpointPacket, normalizeCheckpointResponse };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
3
|
+
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
4
|
+
authorPacketPayloadFromCheckpointResponse,
|
|
5
|
+
buildAuthorCheckpointPacket,
|
|
6
|
+
normalizeCheckpointResponse
|
|
7
|
+
} from "./chunk-UQPTCP4D.js";
|
|
8
|
+
import "./chunk-Z7QUCDPT.js";
|
|
9
|
+
export {
|
|
10
|
+
RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
11
|
+
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
12
|
+
authorPacketPayloadFromCheckpointResponse,
|
|
13
|
+
buildAuthorCheckpointPacket,
|
|
14
|
+
normalizeCheckpointResponse
|
|
15
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authorPacketPayloadFromCheckpointResponse,
|
|
3
|
+
buildAuthorCheckpointPacket,
|
|
4
|
+
normalizeCheckpointResponse
|
|
5
|
+
} from "./chunk-UQPTCP4D.js";
|
|
1
6
|
import {
|
|
2
7
|
appendRunEvent,
|
|
3
8
|
appendStageHeartbeat,
|
|
@@ -5,7 +10,7 @@ import {
|
|
|
5
10
|
createRunStatusSnapshot,
|
|
6
11
|
normalizeRunParams,
|
|
7
12
|
setRunStatus
|
|
8
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-Z3BWCHFV.js";
|
|
9
14
|
import {
|
|
10
15
|
applyTerminalMetadata,
|
|
11
16
|
compactRecord,
|
|
@@ -13,7 +18,7 @@ import {
|
|
|
13
18
|
nonEmptyString,
|
|
14
19
|
normalizeTerminalMetadata,
|
|
15
20
|
recordValue
|
|
16
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-Z7QUCDPT.js";
|
|
17
22
|
import {
|
|
18
23
|
visualDeltaShipGateReason
|
|
19
24
|
} from "./chunk-4YCWZVBN.js";
|
|
@@ -403,6 +408,150 @@ function blockerResult(state, result, blocker) {
|
|
|
403
408
|
}
|
|
404
409
|
});
|
|
405
410
|
}
|
|
411
|
+
function checkpointAwaitingResult(state, result, visibility) {
|
|
412
|
+
const packet = buildAuthorCheckpointPacket({
|
|
413
|
+
request: state.request,
|
|
414
|
+
runState: state,
|
|
415
|
+
engineResult: result,
|
|
416
|
+
fullRiddleState: fullRiddleState(result, state),
|
|
417
|
+
visibility
|
|
418
|
+
});
|
|
419
|
+
const at = timestamp();
|
|
420
|
+
state.checkpoint_packet = packet;
|
|
421
|
+
state.checkpoint_history = [
|
|
422
|
+
...state.checkpoint_history || [],
|
|
423
|
+
{ ts: at, packet }
|
|
424
|
+
].slice(-25);
|
|
425
|
+
appendRunEvent(state, {
|
|
426
|
+
ts: at,
|
|
427
|
+
kind: "checkpoint.packet.created",
|
|
428
|
+
checkpoint: packet.checkpoint,
|
|
429
|
+
stage: packet.stage,
|
|
430
|
+
summary: packet.summary,
|
|
431
|
+
details: compactRecord({
|
|
432
|
+
kind: packet.kind,
|
|
433
|
+
routing_hint: packet.routing_hint,
|
|
434
|
+
resume_token: packet.resume_token
|
|
435
|
+
})
|
|
436
|
+
});
|
|
437
|
+
setRunStatus(state, "awaiting_checkpoint", at);
|
|
438
|
+
persist(state);
|
|
439
|
+
return createRunResult({
|
|
440
|
+
state,
|
|
441
|
+
status: "awaiting_checkpoint",
|
|
442
|
+
last_summary: packet.summary,
|
|
443
|
+
raw: {
|
|
444
|
+
engine_state_path: result.state_path || state.request.engine_state_path || null,
|
|
445
|
+
last_result: result,
|
|
446
|
+
checkpoint_packet: packet
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function appendCheckpointResponse(state, response, input = {}) {
|
|
451
|
+
const at = timestamp();
|
|
452
|
+
state.checkpoint_history = [
|
|
453
|
+
...state.checkpoint_history || [],
|
|
454
|
+
{ ts: at, response }
|
|
455
|
+
].slice(-25);
|
|
456
|
+
if (input.clear_packet !== false) {
|
|
457
|
+
state.checkpoint_packet = void 0;
|
|
458
|
+
}
|
|
459
|
+
appendRunEvent(state, {
|
|
460
|
+
ts: at,
|
|
461
|
+
kind: "checkpoint.response.accepted",
|
|
462
|
+
checkpoint: response.checkpoint,
|
|
463
|
+
stage: state.current_stage || "author",
|
|
464
|
+
summary: input.summary || response.summary,
|
|
465
|
+
details: compactRecord({
|
|
466
|
+
decision: response.decision,
|
|
467
|
+
resume_token: response.resume_token,
|
|
468
|
+
source: response.source
|
|
469
|
+
})
|
|
470
|
+
});
|
|
471
|
+
setRunStatus(state, "running", at);
|
|
472
|
+
persist(state);
|
|
473
|
+
}
|
|
474
|
+
function checkpointResponseContinuation(state, value) {
|
|
475
|
+
if (!value) return {};
|
|
476
|
+
const packet = state.checkpoint_packet;
|
|
477
|
+
const response = normalizeCheckpointResponse(value);
|
|
478
|
+
if (!response) {
|
|
479
|
+
return {
|
|
480
|
+
blocker: {
|
|
481
|
+
code: "checkpoint_response_invalid",
|
|
482
|
+
checkpoint: packet?.checkpoint || state.last_checkpoint || null,
|
|
483
|
+
message: "Checkpoint response was not a valid riddle-proof.checkpoint_response.v1 object.",
|
|
484
|
+
details: { checkpoint_packet: packet || null }
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (!packet) {
|
|
489
|
+
return {
|
|
490
|
+
blocker: {
|
|
491
|
+
code: "checkpoint_response_without_packet",
|
|
492
|
+
checkpoint: response.checkpoint,
|
|
493
|
+
message: "A checkpoint response was supplied, but the run state has no pending checkpoint packet.",
|
|
494
|
+
details: { response }
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
if (response.run_id !== packet.run_id || response.checkpoint !== packet.checkpoint) {
|
|
499
|
+
return {
|
|
500
|
+
blocker: {
|
|
501
|
+
code: "checkpoint_response_mismatch",
|
|
502
|
+
checkpoint: packet.checkpoint,
|
|
503
|
+
message: "Checkpoint response does not match the pending checkpoint packet.",
|
|
504
|
+
details: {
|
|
505
|
+
expected: { run_id: packet.run_id, checkpoint: packet.checkpoint },
|
|
506
|
+
actual: { run_id: response.run_id, checkpoint: response.checkpoint }
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (packet.resume_token && response.resume_token !== packet.resume_token) {
|
|
512
|
+
return {
|
|
513
|
+
blocker: {
|
|
514
|
+
code: "checkpoint_response_resume_token_mismatch",
|
|
515
|
+
checkpoint: packet.checkpoint,
|
|
516
|
+
message: "Checkpoint response resume_token does not match the pending checkpoint packet.",
|
|
517
|
+
details: { expected_resume_token: packet.resume_token, actual_resume_token: response.resume_token || null }
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const base = {
|
|
522
|
+
action: "run",
|
|
523
|
+
state_path: state.request.engine_state_path || packet.state_path || "",
|
|
524
|
+
continue_from_checkpoint: true
|
|
525
|
+
};
|
|
526
|
+
if (response.decision === "author_packet") {
|
|
527
|
+
const payload = authorPacketPayloadFromCheckpointResponse(response);
|
|
528
|
+
if (!payload) {
|
|
529
|
+
return {
|
|
530
|
+
blocker: {
|
|
531
|
+
code: "checkpoint_author_packet_missing",
|
|
532
|
+
checkpoint: packet.checkpoint,
|
|
533
|
+
message: "Checkpoint response decision=author_packet did not include a proof_plan and capture_script payload.",
|
|
534
|
+
details: { response }
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
appendCheckpointResponse(state, response);
|
|
539
|
+
return { next: { ...base, author_packet_json: jsonParam(payload) } };
|
|
540
|
+
}
|
|
541
|
+
if (response.decision === "needs_recon") {
|
|
542
|
+
appendCheckpointResponse(state, response);
|
|
543
|
+
return { next: { ...base, advance_stage: "recon" } };
|
|
544
|
+
}
|
|
545
|
+
appendCheckpointResponse(state, response, { clear_packet: false });
|
|
546
|
+
return {
|
|
547
|
+
blocker: {
|
|
548
|
+
code: `checkpoint_response_${response.decision}`,
|
|
549
|
+
checkpoint: packet.checkpoint,
|
|
550
|
+
message: response.summary || `Checkpoint response stopped the run with decision=${response.decision}.`,
|
|
551
|
+
details: { response }
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
406
555
|
function disabledAdapterPayload(action, context) {
|
|
407
556
|
return {
|
|
408
557
|
ok: false,
|
|
@@ -651,6 +800,9 @@ async function routeCheckpoint(request, state, result, agent, input) {
|
|
|
651
800
|
const continueStage = checkpointContinueStage(result);
|
|
652
801
|
const checkpointContinuesToAuthor = continueStage === "author";
|
|
653
802
|
if (checkpoint === "author_supervisor_judgment" || checkpoint === "verify_capture_retry" || checkpoint === "verify_agent_retry" && checkpointContinuesToAuthor) {
|
|
803
|
+
if (input.checkpoint_mode === "yield") {
|
|
804
|
+
return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
|
|
805
|
+
}
|
|
654
806
|
const packet = await agent.authorProofPacket(context);
|
|
655
807
|
const blocker = requirePayload("author_packet", packet, state, result);
|
|
656
808
|
if (blocker) return { blocker };
|
|
@@ -752,6 +904,10 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
752
904
|
const state = loadRunState(input);
|
|
753
905
|
state.request = normalizeRunParams({ ...state.request, ...input.request });
|
|
754
906
|
state.request.engine_state_path = nonEmptyString(input.resume_params?.state_path) || nonEmptyString(state.request.engine_state_path) || createEngineStatePath(state, input.config);
|
|
907
|
+
const checkpointContinuation = checkpointResponseContinuation(state, input.checkpoint_response);
|
|
908
|
+
if (checkpointContinuation.blocker) {
|
|
909
|
+
return blockerResult(state, null, checkpointContinuation.blocker);
|
|
910
|
+
}
|
|
755
911
|
const request = state.request;
|
|
756
912
|
const agent = input.agent || createDisabledRiddleProofAgentAdapter();
|
|
757
913
|
const maxIterations = Math.max(
|
|
@@ -773,6 +929,8 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
773
929
|
engine_state_path: request.engine_state_path || null,
|
|
774
930
|
max_iterations: maxIterations,
|
|
775
931
|
ship_mode: effectiveShipMode(request, input.config),
|
|
932
|
+
checkpoint_mode: input.checkpoint_mode || "auto",
|
|
933
|
+
checkpoint_visibility: input.checkpoint_visibility || null,
|
|
776
934
|
leave_draft: request.leave_draft || false
|
|
777
935
|
}
|
|
778
936
|
});
|
|
@@ -787,7 +945,7 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
787
945
|
message
|
|
788
946
|
});
|
|
789
947
|
}
|
|
790
|
-
let nextParams = input.resume_params || initialRunParams(request, input, state);
|
|
948
|
+
let nextParams = input.resume_params || checkpointContinuation.next || initialRunParams(request, input, state);
|
|
791
949
|
let lastResult = null;
|
|
792
950
|
const stageIterations = {};
|
|
793
951
|
for (let index = 0; index < maxIterations; index += 1) {
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
appendStageHeartbeat,
|
|
4
4
|
createRunState,
|
|
5
5
|
setRunStatus
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z3BWCHFV.js";
|
|
7
7
|
import {
|
|
8
8
|
createRunResult
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-Z7QUCDPT.js";
|
|
10
10
|
|
|
11
11
|
// src/runner.ts
|
|
12
12
|
function errorDetails(error) {
|