@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.
- package/README.md +22 -0
- package/dist/checkpoint.cjs +204 -1
- package/dist/checkpoint.d.cts +16 -1
- package/dist/checkpoint.d.ts +16 -1
- package/dist/checkpoint.js +4 -2
- package/dist/{chunk-CHRYLX6N.js → chunk-ALP5KOS2.js} +128 -15
- package/dist/{chunk-W7VTDN4T.js → chunk-DUFDZJOF.js} +1 -0
- package/dist/chunk-JFQXAJH2.js +0 -0
- package/dist/{chunk-7S7O3NKF.js → chunk-JOXTKWX6.js} +6 -1
- package/dist/{chunk-MRSYJMF4.js → chunk-N3ZNBRIG.js} +2 -2
- package/dist/chunk-NOBFZDZG.js +754 -0
- package/dist/chunk-PLSGW2GI.js +161 -0
- package/dist/{chunk-LXE5YUYY.js → chunk-R6SCWJCI.js} +204 -2
- package/dist/cli.cjs +6134 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +166 -0
- package/dist/codex-exec-agent.cjs +790 -0
- package/dist/codex-exec-agent.d.cts +91 -0
- package/dist/codex-exec-agent.d.ts +91 -0
- package/dist/codex-exec-agent.js +10 -0
- package/dist/engine-harness.cjs +740 -279
- package/dist/engine-harness.js +5 -4
- package/dist/index.cjs +1475 -247
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +45 -25
- package/dist/local-agent.cjs +792 -0
- package/dist/local-agent.d.cts +3 -0
- package/dist/local-agent.d.ts +3 -0
- package/dist/local-agent.js +11 -0
- package/dist/openclaw.js +4 -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/run-card.cjs +212 -0
- package/dist/run-card.d.cts +10 -0
- package/dist/run-card.d.ts +10 -0
- package/dist/run-card.js +10 -0
- package/dist/runner.cjs +2 -0
- package/dist/runner.js +5 -3
- package/dist/state.cjs +174 -5
- package/dist/state.d.cts +2 -1
- package/dist/state.d.ts +2 -1
- package/dist/state.js +4 -2
- package/dist/types.d.cts +63 -2
- package/dist/types.d.ts +63 -2
- package/package.json +20 -2
package/dist/index.cjs
CHANGED
|
@@ -2761,6 +2761,7 @@ __export(index_exports, {
|
|
|
2761
2761
|
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION: () => RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
2762
2762
|
RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION: () => RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION,
|
|
2763
2763
|
RIDDLE_PROOF_PLAYABILITY_VERSION: () => RIDDLE_PROOF_PLAYABILITY_VERSION,
|
|
2764
|
+
RIDDLE_PROOF_RUN_CARD_VERSION: () => RIDDLE_PROOF_RUN_CARD_VERSION,
|
|
2764
2765
|
RIDDLE_PROOF_RUN_STATE_VERSION: () => RIDDLE_PROOF_RUN_STATE_VERSION,
|
|
2765
2766
|
RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION: () => RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION,
|
|
2766
2767
|
RIDDLE_PROOF_VISUAL_SESSION_VERSION: () => RIDDLE_PROOF_VISUAL_SESSION_VERSION,
|
|
@@ -2774,13 +2775,19 @@ __export(index_exports, {
|
|
|
2774
2775
|
buildAuthorCheckpointPacket: () => buildAuthorCheckpointPacket,
|
|
2775
2776
|
buildCheckpointPacketForEngineResult: () => buildCheckpointPacketForEngineResult,
|
|
2776
2777
|
buildProofAssessmentCheckpointPacket: () => buildProofAssessmentCheckpointPacket,
|
|
2778
|
+
buildStageCheckpointPacket: () => buildStageCheckpointPacket,
|
|
2777
2779
|
buildVisualProofSession: () => buildVisualProofSession,
|
|
2778
2780
|
checkpointResponseIdentity: () => checkpointResponseIdentity,
|
|
2779
2781
|
checkpointSummaryFromState: () => checkpointSummaryFromState,
|
|
2780
2782
|
compactRecord: () => compactRecord,
|
|
2781
2783
|
compareVisualProofSessionFingerprint: () => compareVisualProofSessionFingerprint,
|
|
2782
2784
|
createCaptureDiagnostic: () => createCaptureDiagnostic,
|
|
2785
|
+
createCodexExecAgentAdapter: () => createCodexExecAgentAdapter,
|
|
2786
|
+
createCodexExecJsonRunner: () => createCodexExecJsonRunner,
|
|
2783
2787
|
createDisabledRiddleProofAgentAdapter: () => createDisabledRiddleProofAgentAdapter,
|
|
2788
|
+
createLocalAgentAdapter: () => createCodexExecAgentAdapter,
|
|
2789
|
+
createLocalAgentJsonRunner: () => createCodexExecJsonRunner,
|
|
2790
|
+
createRiddleProofRunCard: () => createRiddleProofRunCard,
|
|
2784
2791
|
createRunResult: () => createRunResult,
|
|
2785
2792
|
createRunState: () => createRunState,
|
|
2786
2793
|
createRunStatusSnapshot: () => createRunStatusSnapshot,
|
|
@@ -2800,6 +2807,8 @@ __export(index_exports, {
|
|
|
2800
2807
|
readRiddleProofRunStatus: () => readRiddleProofRunStatus,
|
|
2801
2808
|
recordValue: () => recordValue,
|
|
2802
2809
|
redactForProofDiagnostics: () => redactForProofDiagnostics,
|
|
2810
|
+
runCodexExecAgentDoctor: () => runCodexExecAgentDoctor,
|
|
2811
|
+
runLocalAgentDoctor: () => runCodexExecAgentDoctor,
|
|
2803
2812
|
runRiddleProof: () => runRiddleProof,
|
|
2804
2813
|
runRiddleProofEngineHarness: () => runRiddleProofEngineHarness,
|
|
2805
2814
|
setRunStatus: () => setRunStatus,
|
|
@@ -3018,248 +3027,18 @@ function createRunResult(input) {
|
|
|
3018
3027
|
checkpoint_summary: state.checkpoint_summary,
|
|
3019
3028
|
state_paths: state.state_paths,
|
|
3020
3029
|
proof_contract: state.proof_contract,
|
|
3030
|
+
run_card: state.run_card,
|
|
3021
3031
|
proof_session: state.proof_session,
|
|
3022
3032
|
evidence_bundle: input.evidence_bundle,
|
|
3023
3033
|
raw: input.raw
|
|
3024
3034
|
});
|
|
3025
3035
|
}
|
|
3026
3036
|
|
|
3027
|
-
// src/state.ts
|
|
3028
|
-
var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
|
|
3029
|
-
function timestamp() {
|
|
3030
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3031
|
-
}
|
|
3032
|
-
function createRunId(createdAt) {
|
|
3033
|
-
const stamp = createdAt.replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
3034
|
-
const entropy = Math.random().toString(36).slice(2, 8) || "run";
|
|
3035
|
-
return `rp_${stamp}_${entropy}`;
|
|
3036
|
-
}
|
|
3037
|
-
function elapsedMs(start, end) {
|
|
3038
|
-
const startMs = start ? Date.parse(start) : NaN;
|
|
3039
|
-
const endMs = end ? Date.parse(end) : NaN;
|
|
3040
|
-
if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
|
|
3041
|
-
return Math.max(0, endMs - startMs);
|
|
3042
|
-
}
|
|
3043
|
-
function normalizePrStatus2(value) {
|
|
3044
|
-
const status = nonEmptyString(value)?.toLowerCase();
|
|
3045
|
-
if (status === "merged") return "merged";
|
|
3046
|
-
if (status === "open") return "open";
|
|
3047
|
-
if (status === "closed") return "closed";
|
|
3048
|
-
if (status === "not_found" || status === "not-found") return "not_found";
|
|
3049
|
-
if (status === "unavailable") return "unavailable";
|
|
3050
|
-
return status || "unknown";
|
|
3051
|
-
}
|
|
3052
|
-
function normalizePrLifecycleState(input, checkedAt = timestamp()) {
|
|
3053
|
-
const value = recordValue(input);
|
|
3054
|
-
if (!value) return void 0;
|
|
3055
|
-
const cleanup = recordValue(value.cleanup);
|
|
3056
|
-
const mergeCommit = nonEmptyString(value.merge_commit) || nonEmptyString(value.mergeCommit) || nonEmptyString(recordValue(value.mergeCommit)?.oid);
|
|
3057
|
-
return compactRecord({
|
|
3058
|
-
status: normalizePrStatus2(value.status || value.state),
|
|
3059
|
-
pr_url: nonEmptyString(value.pr_url) || nonEmptyString(value.prUrl) || nonEmptyString(value.url),
|
|
3060
|
-
pr_number: nonEmptyString(value.pr_number) || nonEmptyString(value.prNumber) || (typeof value.number === "number" ? String(value.number) : void 0),
|
|
3061
|
-
repo: nonEmptyString(value.repo) || nonEmptyString(value.repository),
|
|
3062
|
-
head_branch: nonEmptyString(value.head_branch) || nonEmptyString(value.headBranch) || nonEmptyString(value.headRefName),
|
|
3063
|
-
base_branch: nonEmptyString(value.base_branch) || nonEmptyString(value.baseBranch) || nonEmptyString(value.baseRefName),
|
|
3064
|
-
merge_commit: mergeCommit,
|
|
3065
|
-
merged_at: nonEmptyString(value.merged_at) || nonEmptyString(value.mergedAt),
|
|
3066
|
-
closed_at: nonEmptyString(value.closed_at) || nonEmptyString(value.closedAt),
|
|
3067
|
-
checked_at: nonEmptyString(value.checked_at) || nonEmptyString(value.checkedAt) || checkedAt,
|
|
3068
|
-
source: nonEmptyString(value.source),
|
|
3069
|
-
next_action: nonEmptyString(value.next_action) || nonEmptyString(value.nextAction),
|
|
3070
|
-
cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
|
|
3071
|
-
});
|
|
3072
|
-
}
|
|
3073
|
-
function normalizeIntegrationContext(input, fallbackSource) {
|
|
3074
|
-
const value = recordValue(input);
|
|
3075
|
-
if (!value) {
|
|
3076
|
-
return fallbackSource ? { source: fallbackSource } : void 0;
|
|
3077
|
-
}
|
|
3078
|
-
const metadata = recordValue(value.metadata);
|
|
3079
|
-
return compactRecord({
|
|
3080
|
-
source: nonEmptyString(value.source) || fallbackSource,
|
|
3081
|
-
channel_id: nonEmptyString(value.channel_id),
|
|
3082
|
-
thread_id: nonEmptyString(value.thread_id),
|
|
3083
|
-
message_id: nonEmptyString(value.message_id),
|
|
3084
|
-
source_url: nonEmptyString(value.source_url),
|
|
3085
|
-
metadata: metadata && Object.keys(metadata).length ? metadata : void 0
|
|
3086
|
-
});
|
|
3087
|
-
}
|
|
3088
|
-
function normalizeRunParams(input) {
|
|
3089
|
-
return compactRecord({
|
|
3090
|
-
repo: input.repo,
|
|
3091
|
-
branch: input.branch,
|
|
3092
|
-
change_request: input.change_request,
|
|
3093
|
-
commit_message: input.commit_message,
|
|
3094
|
-
prod_url: input.prod_url,
|
|
3095
|
-
capture_script: input.capture_script,
|
|
3096
|
-
success_criteria: input.success_criteria,
|
|
3097
|
-
assertions: input.assertions,
|
|
3098
|
-
verification_mode: input.verification_mode,
|
|
3099
|
-
resume_session: input.resume_session,
|
|
3100
|
-
target_image_url: input.target_image_url,
|
|
3101
|
-
target_image_hash: input.target_image_hash,
|
|
3102
|
-
viewport_matrix: input.viewport_matrix,
|
|
3103
|
-
deterministic_setup: input.deterministic_setup,
|
|
3104
|
-
reference: input.reference,
|
|
3105
|
-
base_branch: input.base_branch,
|
|
3106
|
-
before_ref: input.before_ref,
|
|
3107
|
-
allow_static_preview_fallback: input.allow_static_preview_fallback,
|
|
3108
|
-
context: input.context,
|
|
3109
|
-
reviewer: input.reviewer,
|
|
3110
|
-
mode: input.mode,
|
|
3111
|
-
build_command: input.build_command,
|
|
3112
|
-
build_output: input.build_output,
|
|
3113
|
-
server_image: input.server_image,
|
|
3114
|
-
server_command: input.server_command,
|
|
3115
|
-
server_port: input.server_port,
|
|
3116
|
-
server_path: input.server_path,
|
|
3117
|
-
use_auth: input.use_auth,
|
|
3118
|
-
auth_localStorage_json: input.auth_localStorage_json,
|
|
3119
|
-
auth_cookies_json: input.auth_cookies_json,
|
|
3120
|
-
auth_headers_json: input.auth_headers_json,
|
|
3121
|
-
color_scheme: input.color_scheme,
|
|
3122
|
-
wait_for_selector: input.wait_for_selector,
|
|
3123
|
-
ship_mode: input.ship_mode,
|
|
3124
|
-
leave_draft: input.leave_draft,
|
|
3125
|
-
engine_state_path: input.engine_state_path,
|
|
3126
|
-
harness_state_path: input.harness_state_path,
|
|
3127
|
-
max_iterations: input.max_iterations,
|
|
3128
|
-
auto_approve: input.auto_approve,
|
|
3129
|
-
dry_run: input.dry_run,
|
|
3130
|
-
integration_context: normalizeIntegrationContext(input.integration_context)
|
|
3131
|
-
});
|
|
3132
|
-
}
|
|
3133
|
-
function createRunState(input) {
|
|
3134
|
-
const createdAt = input.created_at || timestamp();
|
|
3135
|
-
return compactRecord({
|
|
3136
|
-
version: RIDDLE_PROOF_RUN_STATE_VERSION,
|
|
3137
|
-
run_id: input.run_id || createRunId(createdAt),
|
|
3138
|
-
state_path: input.state_path,
|
|
3139
|
-
worktree_path: input.worktree_path,
|
|
3140
|
-
branch: input.branch || input.request.branch,
|
|
3141
|
-
current_stage: input.current_stage ?? null,
|
|
3142
|
-
stage_started_at: input.stage_started_at ?? null,
|
|
3143
|
-
status: input.status || "running",
|
|
3144
|
-
created_at: createdAt,
|
|
3145
|
-
updated_at: input.updated_at || createdAt,
|
|
3146
|
-
request: normalizeRunParams(input.request),
|
|
3147
|
-
iterations: input.iterations ?? 0,
|
|
3148
|
-
last_checkpoint: input.last_checkpoint ?? null,
|
|
3149
|
-
checkpoint_packet: input.checkpoint_packet,
|
|
3150
|
-
checkpoint_summary: input.checkpoint_summary,
|
|
3151
|
-
state_paths: input.state_paths,
|
|
3152
|
-
proof_contract: input.proof_contract,
|
|
3153
|
-
checkpoint_history: input.checkpoint_history,
|
|
3154
|
-
events: input.events ? [...input.events] : []
|
|
3155
|
-
});
|
|
3156
|
-
}
|
|
3157
|
-
function appendRunEvent(state, input) {
|
|
3158
|
-
const event = {
|
|
3159
|
-
ts: input.ts || timestamp(),
|
|
3160
|
-
kind: input.kind,
|
|
3161
|
-
checkpoint: input.checkpoint,
|
|
3162
|
-
stage: input.stage,
|
|
3163
|
-
summary: input.summary,
|
|
3164
|
-
details: input.details
|
|
3165
|
-
};
|
|
3166
|
-
state.events.push(compactRecord({
|
|
3167
|
-
ts: event.ts,
|
|
3168
|
-
kind: event.kind,
|
|
3169
|
-
checkpoint: event.checkpoint,
|
|
3170
|
-
stage: event.stage,
|
|
3171
|
-
summary: event.summary,
|
|
3172
|
-
details: event.details
|
|
3173
|
-
}));
|
|
3174
|
-
if (input.checkpoint !== void 0) state.last_checkpoint = input.checkpoint;
|
|
3175
|
-
if (input.stage !== void 0) {
|
|
3176
|
-
if (state.current_stage !== input.stage) state.stage_started_at = event.ts;
|
|
3177
|
-
state.current_stage = input.stage;
|
|
3178
|
-
}
|
|
3179
|
-
state.updated_at = event.ts;
|
|
3180
|
-
return state;
|
|
3181
|
-
}
|
|
3182
|
-
function appendStageHeartbeat(state, input) {
|
|
3183
|
-
const at = input.ts || timestamp();
|
|
3184
|
-
return appendRunEvent(state, {
|
|
3185
|
-
ts: at,
|
|
3186
|
-
kind: "stage.heartbeat",
|
|
3187
|
-
checkpoint: input.checkpoint || `${input.stage}_heartbeat`,
|
|
3188
|
-
stage: input.stage,
|
|
3189
|
-
summary: input.summary || `${input.stage} stage is active.`,
|
|
3190
|
-
details: compactRecord({
|
|
3191
|
-
elapsed_ms: elapsedMs(state.created_at, at),
|
|
3192
|
-
stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
|
|
3193
|
-
wait_reason: input.wait_reason,
|
|
3194
|
-
blocker: input.blocker,
|
|
3195
|
-
...input.details
|
|
3196
|
-
})
|
|
3197
|
-
});
|
|
3198
|
-
}
|
|
3199
|
-
function createRunStatusSnapshot(state, at = timestamp()) {
|
|
3200
|
-
const latestEvent = state.events[state.events.length - 1];
|
|
3201
|
-
const runId = state.run_id || "unknown";
|
|
3202
|
-
return compactRecord({
|
|
3203
|
-
run_id: runId,
|
|
3204
|
-
status: state.status,
|
|
3205
|
-
is_terminal: isTerminalStatus(state.status),
|
|
3206
|
-
monitor_should_continue: !isTerminalStatus(state.status),
|
|
3207
|
-
current_stage: state.current_stage ?? null,
|
|
3208
|
-
state_path: state.state_path ?? null,
|
|
3209
|
-
worktree_path: state.worktree_path ?? null,
|
|
3210
|
-
branch: state.branch ?? null,
|
|
3211
|
-
pr_url: state.pr_url ?? null,
|
|
3212
|
-
pr_branch: state.pr_branch ?? null,
|
|
3213
|
-
pr_state: state.pr_state,
|
|
3214
|
-
ci_status: state.ci_status,
|
|
3215
|
-
ship_commit: state.ship_commit,
|
|
3216
|
-
ship_remote_head: state.ship_remote_head,
|
|
3217
|
-
merge_commit: state.merge_commit,
|
|
3218
|
-
merged_at: state.merged_at,
|
|
3219
|
-
proof_comment_url: state.proof_comment_url,
|
|
3220
|
-
cleanup_report: state.cleanup_report,
|
|
3221
|
-
iterations: state.iterations,
|
|
3222
|
-
last_checkpoint: state.last_checkpoint ?? null,
|
|
3223
|
-
updated_at: state.updated_at,
|
|
3224
|
-
elapsed_ms: elapsedMs(state.created_at, at),
|
|
3225
|
-
stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
|
|
3226
|
-
blocker: state.blocker,
|
|
3227
|
-
checkpoint_packet: state.checkpoint_packet,
|
|
3228
|
-
checkpoint_summary: state.checkpoint_summary,
|
|
3229
|
-
state_paths: state.state_paths,
|
|
3230
|
-
proof_contract: state.proof_contract,
|
|
3231
|
-
latest_event: latestEvent
|
|
3232
|
-
});
|
|
3233
|
-
}
|
|
3234
|
-
function setRunStatus(state, status, at = timestamp()) {
|
|
3235
|
-
state.status = status;
|
|
3236
|
-
state.ok = status !== "blocked" && status !== "failed";
|
|
3237
|
-
state.updated_at = at;
|
|
3238
|
-
return state;
|
|
3239
|
-
}
|
|
3240
|
-
function applyPrLifecycleState(state, input, at = timestamp()) {
|
|
3241
|
-
const prState = normalizePrLifecycleState(input, at);
|
|
3242
|
-
if (!prState) return state;
|
|
3243
|
-
state.pr_state = prState;
|
|
3244
|
-
if (prState.pr_url) state.pr_url = prState.pr_url;
|
|
3245
|
-
if (prState.head_branch) state.pr_branch = prState.head_branch;
|
|
3246
|
-
if (prState.merge_commit) state.merge_commit = prState.merge_commit;
|
|
3247
|
-
if (prState.merged_at) state.merged_at = prState.merged_at;
|
|
3248
|
-
if (prState.cleanup) state.cleanup_report = prState.cleanup;
|
|
3249
|
-
if (prState.status === "merged") {
|
|
3250
|
-
state.finalized = true;
|
|
3251
|
-
state.status = "completed";
|
|
3252
|
-
state.ok = true;
|
|
3253
|
-
}
|
|
3254
|
-
state.updated_at = at;
|
|
3255
|
-
return state;
|
|
3256
|
-
}
|
|
3257
|
-
|
|
3258
3037
|
// src/checkpoint.ts
|
|
3259
3038
|
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
3260
3039
|
var RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION = "riddle-proof.checkpoint.v1";
|
|
3261
3040
|
var RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION = "riddle-proof.checkpoint_response.v1";
|
|
3262
|
-
function
|
|
3041
|
+
function timestamp() {
|
|
3263
3042
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3264
3043
|
}
|
|
3265
3044
|
function jsonCloneRecord(value) {
|
|
@@ -3373,6 +3152,102 @@ function responseSchemaForProofAssessmentPacket() {
|
|
|
3373
3152
|
}
|
|
3374
3153
|
};
|
|
3375
3154
|
}
|
|
3155
|
+
function responseSchemaForReconPacket() {
|
|
3156
|
+
return {
|
|
3157
|
+
type: "object",
|
|
3158
|
+
required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
|
|
3159
|
+
additionalProperties: false,
|
|
3160
|
+
properties: {
|
|
3161
|
+
version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
|
|
3162
|
+
run_id: { type: "string" },
|
|
3163
|
+
checkpoint: { type: "string" },
|
|
3164
|
+
resume_token: { type: "string" },
|
|
3165
|
+
decision: {
|
|
3166
|
+
type: "string",
|
|
3167
|
+
enum: ["ready_for_author", "retry_recon", "recon_stuck", "needs_recon", "blocked", "human_review"]
|
|
3168
|
+
},
|
|
3169
|
+
summary: { type: "string" },
|
|
3170
|
+
payload: {
|
|
3171
|
+
type: "object",
|
|
3172
|
+
description: "Optional recon assessment details such as baseline_understanding, refined_inputs, reasons, or diagnostic blocker context."
|
|
3173
|
+
},
|
|
3174
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
3175
|
+
continue_with_stage: { type: "string", enum: ["recon", "author"] },
|
|
3176
|
+
source: {
|
|
3177
|
+
type: "object",
|
|
3178
|
+
properties: {
|
|
3179
|
+
kind: { type: "string" },
|
|
3180
|
+
session_id: { type: "string" },
|
|
3181
|
+
user_id: { type: "string" }
|
|
3182
|
+
}
|
|
3183
|
+
},
|
|
3184
|
+
created_at: { type: "string" }
|
|
3185
|
+
}
|
|
3186
|
+
};
|
|
3187
|
+
}
|
|
3188
|
+
function responseSchemaForImplementationPacket() {
|
|
3189
|
+
return {
|
|
3190
|
+
type: "object",
|
|
3191
|
+
required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
|
|
3192
|
+
additionalProperties: false,
|
|
3193
|
+
properties: {
|
|
3194
|
+
version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
|
|
3195
|
+
run_id: { type: "string" },
|
|
3196
|
+
checkpoint: { type: "string" },
|
|
3197
|
+
resume_token: { type: "string" },
|
|
3198
|
+
decision: {
|
|
3199
|
+
type: "string",
|
|
3200
|
+
enum: ["implementation_complete", "needs_author", "needs_recon", "blocked", "human_review"]
|
|
3201
|
+
},
|
|
3202
|
+
summary: { type: "string" },
|
|
3203
|
+
payload: {
|
|
3204
|
+
type: "object",
|
|
3205
|
+
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."
|
|
3206
|
+
},
|
|
3207
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
3208
|
+
continue_with_stage: { type: "string", enum: ["implement", "verify", "author", "recon"] },
|
|
3209
|
+
source: {
|
|
3210
|
+
type: "object",
|
|
3211
|
+
properties: {
|
|
3212
|
+
kind: { type: "string" },
|
|
3213
|
+
session_id: { type: "string" },
|
|
3214
|
+
user_id: { type: "string" }
|
|
3215
|
+
}
|
|
3216
|
+
},
|
|
3217
|
+
created_at: { type: "string" }
|
|
3218
|
+
}
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
function responseSchemaForAdvancePacket(stage) {
|
|
3222
|
+
return {
|
|
3223
|
+
type: "object",
|
|
3224
|
+
required: ["version", "run_id", "checkpoint", "decision", "summary", "created_at"],
|
|
3225
|
+
additionalProperties: false,
|
|
3226
|
+
properties: {
|
|
3227
|
+
version: { const: RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION },
|
|
3228
|
+
run_id: { type: "string" },
|
|
3229
|
+
checkpoint: { type: "string" },
|
|
3230
|
+
resume_token: { type: "string" },
|
|
3231
|
+
decision: {
|
|
3232
|
+
type: "string",
|
|
3233
|
+
enum: ["continue_stage", "retry_stage", "needs_recon", "needs_implementation", "blocked", "human_review"]
|
|
3234
|
+
},
|
|
3235
|
+
summary: { type: "string" },
|
|
3236
|
+
payload: { type: "object" },
|
|
3237
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
3238
|
+
continue_with_stage: { type: "string", enum: ["recon", "author", "implement", "verify", "ship", stage] },
|
|
3239
|
+
source: {
|
|
3240
|
+
type: "object",
|
|
3241
|
+
properties: {
|
|
3242
|
+
kind: { type: "string" },
|
|
3243
|
+
session_id: { type: "string" },
|
|
3244
|
+
user_id: { type: "string" }
|
|
3245
|
+
}
|
|
3246
|
+
},
|
|
3247
|
+
created_at: { type: "string" }
|
|
3248
|
+
}
|
|
3249
|
+
};
|
|
3250
|
+
}
|
|
3376
3251
|
function resumeTokenFor(input) {
|
|
3377
3252
|
const hash = import_node_crypto.default.createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 24);
|
|
3378
3253
|
return `rpchk_${hash}`;
|
|
@@ -3400,6 +3275,106 @@ function artifactsFromState(state) {
|
|
|
3400
3275
|
}
|
|
3401
3276
|
return artifacts.slice(0, 16);
|
|
3402
3277
|
}
|
|
3278
|
+
function stageFromCheckpoint(checkpoint) {
|
|
3279
|
+
if (checkpoint.startsWith("recon_")) return "recon";
|
|
3280
|
+
if (checkpoint.startsWith("author_")) return "author";
|
|
3281
|
+
if (checkpoint.startsWith("implement_")) return "implement";
|
|
3282
|
+
if (checkpoint.startsWith("verify_")) return "verify";
|
|
3283
|
+
if (checkpoint.startsWith("ship_")) return "ship";
|
|
3284
|
+
if (checkpoint.startsWith("pr_sync_")) return "notify";
|
|
3285
|
+
if (checkpoint.includes("capture")) return "prove";
|
|
3286
|
+
return "setup";
|
|
3287
|
+
}
|
|
3288
|
+
function allowedDecisionsForStage(stage, checkpoint) {
|
|
3289
|
+
if (stage === "recon") return ["ready_for_author", "retry_recon", "recon_stuck", "blocked", "human_review"];
|
|
3290
|
+
if (stage === "implement") return ["implementation_complete", "needs_author", "needs_recon", "blocked", "human_review"];
|
|
3291
|
+
if (stage === "ship") return ["continue_stage", "needs_implementation", "needs_recon", "blocked", "human_review"];
|
|
3292
|
+
if (checkpoint === "awaiting_stage_advance") return ["continue_stage", "retry_stage", "blocked", "human_review"];
|
|
3293
|
+
return ["continue_stage", "needs_recon", "needs_implementation", "blocked", "human_review"];
|
|
3294
|
+
}
|
|
3295
|
+
function packetKindForStage(stage, checkpoint) {
|
|
3296
|
+
if (stage === "recon") return "assess_recon";
|
|
3297
|
+
if (stage === "implement") return "implement_change";
|
|
3298
|
+
if (checkpoint.includes("human")) return "human_review";
|
|
3299
|
+
return "advance_decision";
|
|
3300
|
+
}
|
|
3301
|
+
function responseSchemaForStage(stage, checkpoint) {
|
|
3302
|
+
if (stage === "recon") return responseSchemaForReconPacket();
|
|
3303
|
+
if (stage === "implement") return responseSchemaForImplementationPacket();
|
|
3304
|
+
return responseSchemaForAdvancePacket(stage);
|
|
3305
|
+
}
|
|
3306
|
+
function questionForStage(stage, checkpoint) {
|
|
3307
|
+
if (stage === "recon") {
|
|
3308
|
+
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.";
|
|
3309
|
+
}
|
|
3310
|
+
if (stage === "implement") {
|
|
3311
|
+
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.";
|
|
3312
|
+
}
|
|
3313
|
+
if (stage === "ship") {
|
|
3314
|
+
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.";
|
|
3315
|
+
}
|
|
3316
|
+
return "Choose the next Riddle Proof stage for this durable run, or block with a concrete reason if the run cannot honestly advance.";
|
|
3317
|
+
}
|
|
3318
|
+
function buildStageCheckpointPacket(input) {
|
|
3319
|
+
const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "stage_checkpoint";
|
|
3320
|
+
const stage = nonEmptyString(input.engineResult.stage) || stageFromCheckpoint(checkpoint);
|
|
3321
|
+
const runId = input.runState.run_id || "unknown";
|
|
3322
|
+
const fullState = input.fullRiddleState || {};
|
|
3323
|
+
const decisionDetails = recordValue(input.engineResult.decisionRequest?.details);
|
|
3324
|
+
const checkpointContract = recordValue(input.engineResult.checkpointContract);
|
|
3325
|
+
const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.stage_summary) || `${stage} checkpoint needs a supervising decision.`;
|
|
3326
|
+
const kind = packetKindForStage(stage, checkpoint);
|
|
3327
|
+
return {
|
|
3328
|
+
version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
3329
|
+
run_id: runId,
|
|
3330
|
+
state_path: input.runState.state_path,
|
|
3331
|
+
stage,
|
|
3332
|
+
checkpoint,
|
|
3333
|
+
kind,
|
|
3334
|
+
summary,
|
|
3335
|
+
question: questionForStage(stage, checkpoint),
|
|
3336
|
+
change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
|
|
3337
|
+
context: input.request.context,
|
|
3338
|
+
artifacts: artifactsFromState(fullState),
|
|
3339
|
+
state_excerpt: compactRecord({
|
|
3340
|
+
repo: input.request.repo || fullState.repo,
|
|
3341
|
+
branch: input.request.branch || fullState.branch,
|
|
3342
|
+
after_worktree: fullState.after_worktree || input.runState.worktree_path,
|
|
3343
|
+
verification_mode: input.request.verification_mode || fullState.verification_mode,
|
|
3344
|
+
reference: input.request.reference || fullState.reference,
|
|
3345
|
+
server_path: fullState.server_path,
|
|
3346
|
+
wait_for_selector: fullState.wait_for_selector,
|
|
3347
|
+
recon_status: fullState.recon_status,
|
|
3348
|
+
author_status: fullState.author_status,
|
|
3349
|
+
implementation_status: fullState.implementation_status,
|
|
3350
|
+
verify_status: fullState.verify_status,
|
|
3351
|
+
stage_decision_request: jsonCloneRecord(fullState.stage_decision_request)
|
|
3352
|
+
}),
|
|
3353
|
+
evidence_excerpt: compactRecord({
|
|
3354
|
+
before_cdn: fullState.before_cdn || null,
|
|
3355
|
+
prod_cdn: fullState.prod_cdn || null,
|
|
3356
|
+
after_cdn: fullState.after_cdn || null,
|
|
3357
|
+
recon_results: jsonCloneRecord(fullState.recon_results),
|
|
3358
|
+
checkpoint_contract: jsonCloneRecord(checkpointContract),
|
|
3359
|
+
decision_details: jsonCloneRecord(decisionDetails)
|
|
3360
|
+
}),
|
|
3361
|
+
allowed_decisions: allowedDecisionsForStage(stage, checkpoint),
|
|
3362
|
+
response_schema: responseSchemaForStage(stage, checkpoint),
|
|
3363
|
+
routing_hint: {
|
|
3364
|
+
suggested_role: stage === "implement" ? "builder_agent" : checkpoint.includes("human") ? "human" : "main_agent",
|
|
3365
|
+
visibility: input.visibility || "quiet",
|
|
3366
|
+
urgency: stage === "ship" ? "high" : "normal",
|
|
3367
|
+
can_auto_answer: input.visibility !== "manual"
|
|
3368
|
+
},
|
|
3369
|
+
resume_token: resumeTokenFor({
|
|
3370
|
+
runId,
|
|
3371
|
+
statePath: input.engineResult.state_path || input.request.engine_state_path || null,
|
|
3372
|
+
checkpoint,
|
|
3373
|
+
stage
|
|
3374
|
+
}),
|
|
3375
|
+
created_at: input.created_at || timestamp()
|
|
3376
|
+
};
|
|
3377
|
+
}
|
|
3403
3378
|
function buildAuthorCheckpointPacket(input) {
|
|
3404
3379
|
const checkpoint = nonEmptyString(input.engineResult.checkpoint) || "author_supervisor_judgment";
|
|
3405
3380
|
const stage = "author";
|
|
@@ -3453,7 +3428,7 @@ function buildAuthorCheckpointPacket(input) {
|
|
|
3453
3428
|
checkpoint,
|
|
3454
3429
|
stage
|
|
3455
3430
|
}),
|
|
3456
|
-
created_at: input.created_at ||
|
|
3431
|
+
created_at: input.created_at || timestamp()
|
|
3457
3432
|
};
|
|
3458
3433
|
}
|
|
3459
3434
|
function visualDeltaFromState(fullState) {
|
|
@@ -3502,16 +3477,16 @@ function buildProofAssessmentCheckpointPacket(input) {
|
|
|
3502
3477
|
const visualDelta = visualDeltaFromState(fullState);
|
|
3503
3478
|
const verificationMode = nonEmptyString(input.request.verification_mode) || nonEmptyString(fullState.verification_mode) || nonEmptyString(bundle?.verification_mode) || "proof";
|
|
3504
3479
|
const visualDeltaRequired = requiredSignals?.visual_delta === true || verificationModeRequiresVisualDelta(verificationMode);
|
|
3505
|
-
const
|
|
3480
|
+
const evidenceIssueCode2 = visualDeltaIssueCode(visualDelta, visualDeltaRequired);
|
|
3506
3481
|
const summary = nonEmptyString(input.engineResult.summary) || nonEmptyString(fullState.verify_summary) || "Verify captured evidence and needs a supervising proof assessment.";
|
|
3507
|
-
const recoveryHint =
|
|
3482
|
+
const recoveryHint = evidenceIssueCode2 ? "Required visual_delta evidence is incomplete. Keep this same run in verify/evidence recovery with decision=revise_capture and continue_with_stage=verify unless the evidence proves an implementation or recon problem." : "Assess whether the current artifacts prove the requested change, then choose the next stage.";
|
|
3508
3483
|
return {
|
|
3509
3484
|
version: RIDDLE_PROOF_CHECKPOINT_PACKET_VERSION,
|
|
3510
3485
|
run_id: runId,
|
|
3511
3486
|
state_path: input.runState.state_path,
|
|
3512
3487
|
stage,
|
|
3513
3488
|
checkpoint,
|
|
3514
|
-
kind:
|
|
3489
|
+
kind: evidenceIssueCode2 ? "recover_evidence" : "assess_proof",
|
|
3515
3490
|
summary,
|
|
3516
3491
|
question: `Assess the current Riddle Proof evidence. ${recoveryHint} Return a CheckpointResponse using one allowed decision.`,
|
|
3517
3492
|
change_request: input.request.change_request || nonEmptyString(fullState.change_request) || "",
|
|
@@ -3536,7 +3511,7 @@ function buildProofAssessmentCheckpointPacket(input) {
|
|
|
3536
3511
|
visual_delta_required: visualDeltaRequired,
|
|
3537
3512
|
visual_delta_ready: visualDelta?.status === "measured" && visualDelta?.passed === true,
|
|
3538
3513
|
visual_delta: jsonCloneRecord(visualDelta),
|
|
3539
|
-
evidence_issue_code:
|
|
3514
|
+
evidence_issue_code: evidenceIssueCode2,
|
|
3540
3515
|
proof_assessment_request: jsonCloneRecord(proofAssessmentRequest),
|
|
3541
3516
|
verify_decision_request: jsonCloneRecord(fullState.verify_decision_request),
|
|
3542
3517
|
checkpoint_contract: jsonCloneRecord(input.engineResult.checkpointContract)
|
|
@@ -3553,9 +3528,9 @@ function buildProofAssessmentCheckpointPacket(input) {
|
|
|
3553
3528
|
],
|
|
3554
3529
|
response_schema: responseSchemaForProofAssessmentPacket(),
|
|
3555
3530
|
routing_hint: {
|
|
3556
|
-
suggested_role:
|
|
3531
|
+
suggested_role: evidenceIssueCode2 ? "proof_judge" : "proof_judge",
|
|
3557
3532
|
visibility: input.visibility || "quiet",
|
|
3558
|
-
urgency:
|
|
3533
|
+
urgency: evidenceIssueCode2 ? "high" : "normal",
|
|
3559
3534
|
can_auto_answer: input.visibility !== "manual"
|
|
3560
3535
|
},
|
|
3561
3536
|
resume_token: resumeTokenFor({
|
|
@@ -3564,7 +3539,7 @@ function buildProofAssessmentCheckpointPacket(input) {
|
|
|
3564
3539
|
checkpoint,
|
|
3565
3540
|
stage
|
|
3566
3541
|
}),
|
|
3567
|
-
created_at: input.created_at ||
|
|
3542
|
+
created_at: input.created_at || timestamp()
|
|
3568
3543
|
};
|
|
3569
3544
|
}
|
|
3570
3545
|
function buildCheckpointPacketForEngineResult(input) {
|
|
@@ -3572,7 +3547,12 @@ function buildCheckpointPacketForEngineResult(input) {
|
|
|
3572
3547
|
if (checkpoint === "verify_supervisor_judgment" || checkpoint === "verify_supervisor_judgment_required" || checkpoint === "verify_human_escalation") {
|
|
3573
3548
|
return buildProofAssessmentCheckpointPacket(input);
|
|
3574
3549
|
}
|
|
3575
|
-
|
|
3550
|
+
const resume = recordValue(input.engineResult.checkpointContract?.resume);
|
|
3551
|
+
const continueStage = nonEmptyString(resume?.continue_with_stage);
|
|
3552
|
+
if (checkpoint === "author_supervisor_judgment" || checkpoint === "verify_capture_retry" || checkpoint === "verify_agent_retry" && continueStage === "author") {
|
|
3553
|
+
return buildAuthorCheckpointPacket(input);
|
|
3554
|
+
}
|
|
3555
|
+
return buildStageCheckpointPacket(input);
|
|
3576
3556
|
}
|
|
3577
3557
|
function normalizeCheckpointResponse(value) {
|
|
3578
3558
|
const record = recordValue(value);
|
|
@@ -3596,7 +3576,7 @@ function normalizeCheckpointResponse(value) {
|
|
|
3596
3576
|
reasons: Array.isArray(record.reasons) ? record.reasons.filter((item) => typeof item === "string") : void 0,
|
|
3597
3577
|
continue_with_stage: nonEmptyString(record.continue_with_stage),
|
|
3598
3578
|
source: jsonCloneRecord(record.source),
|
|
3599
|
-
created_at: nonEmptyString(record.created_at) ||
|
|
3579
|
+
created_at: nonEmptyString(record.created_at) || timestamp()
|
|
3600
3580
|
});
|
|
3601
3581
|
}
|
|
3602
3582
|
function checkpointSummaryFromState(state, engineStatePath2) {
|
|
@@ -3685,9 +3665,389 @@ function proofContractFromAuthorCheckpointResponse(response, packet, payload) {
|
|
|
3685
3665
|
rationale: jsonCloneValue(payload.rationale),
|
|
3686
3666
|
verdict_dimensions: jsonCloneRecord(payload.verdict_dimensions),
|
|
3687
3667
|
payload: jsonCloneRecord(payload),
|
|
3688
|
-
created_at:
|
|
3668
|
+
created_at: timestamp()
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
// src/run-card.ts
|
|
3673
|
+
var RIDDLE_PROOF_RUN_CARD_VERSION = "riddle-proof.run-card.v1";
|
|
3674
|
+
function elapsedMs(start, end) {
|
|
3675
|
+
const startMs = start ? Date.parse(start) : NaN;
|
|
3676
|
+
const endMs = end ? Date.parse(end) : NaN;
|
|
3677
|
+
if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
|
|
3678
|
+
return Math.max(0, endMs - startMs);
|
|
3679
|
+
}
|
|
3680
|
+
function jsonCloneRecord2(value) {
|
|
3681
|
+
const record = recordValue(value);
|
|
3682
|
+
if (!record) return void 0;
|
|
3683
|
+
try {
|
|
3684
|
+
return JSON.parse(JSON.stringify(record));
|
|
3685
|
+
} catch {
|
|
3686
|
+
return { ...record };
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
function compactText2(value, limit = 600) {
|
|
3690
|
+
const text = nonEmptyString(value);
|
|
3691
|
+
if (!text) return void 0;
|
|
3692
|
+
return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
|
|
3693
|
+
}
|
|
3694
|
+
function visualDeltaFrom(input) {
|
|
3695
|
+
const fullState = input.fullRiddleState || {};
|
|
3696
|
+
const bundle = recordValue(fullState.evidence_bundle);
|
|
3697
|
+
const after = recordValue(bundle?.after);
|
|
3698
|
+
const afterDelta = recordValue(after?.visual_delta);
|
|
3699
|
+
if (afterDelta && Object.keys(afterDelta).length) return afterDelta;
|
|
3700
|
+
const requestDelta = recordValue(recordValue(fullState.proof_assessment_request)?.visual_delta);
|
|
3701
|
+
if (requestDelta && Object.keys(requestDelta).length) return requestDelta;
|
|
3702
|
+
const packetDelta = recordValue(input.runState.checkpoint_packet?.evidence_excerpt?.visual_delta);
|
|
3703
|
+
return packetDelta && Object.keys(packetDelta).length ? packetDelta : void 0;
|
|
3704
|
+
}
|
|
3705
|
+
function artifactsFrom(input) {
|
|
3706
|
+
const packetArtifacts = input.runState.checkpoint_packet?.artifacts;
|
|
3707
|
+
if (packetArtifacts?.length) return packetArtifacts.slice(0, 12);
|
|
3708
|
+
const fullState = input.fullRiddleState || {};
|
|
3709
|
+
const artifacts = [];
|
|
3710
|
+
for (const role of ["before", "prod", "after"]) {
|
|
3711
|
+
const url = nonEmptyString(fullState[`${role}_cdn`]) || nonEmptyString(input.runState[`${role}_artifact_url`]);
|
|
3712
|
+
if (url) artifacts.push({ role, url, name: `${role}.png`, mime_type: "image/png" });
|
|
3713
|
+
}
|
|
3714
|
+
return artifacts.length ? artifacts : void 0;
|
|
3715
|
+
}
|
|
3716
|
+
function ownerFor(state) {
|
|
3717
|
+
if (state.status === "awaiting_checkpoint") {
|
|
3718
|
+
const role = nonEmptyString(state.checkpoint_packet?.routing_hint?.suggested_role);
|
|
3719
|
+
return role || "supervising_agent";
|
|
3720
|
+
}
|
|
3721
|
+
if (state.status === "running") return "engine";
|
|
3722
|
+
if (state.status === "blocked" || state.status === "failed") return "human_or_operator";
|
|
3723
|
+
return "none";
|
|
3724
|
+
}
|
|
3725
|
+
function actionFor(state) {
|
|
3726
|
+
if (state.status === "awaiting_checkpoint") return state.checkpoint_packet?.question || "Answer the pending checkpoint.";
|
|
3727
|
+
if (state.status === "running") return "Continue the current Riddle Proof stage.";
|
|
3728
|
+
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.";
|
|
3729
|
+
if (state.status === "ready_to_ship") return "Ship is held by policy; review PR/ship policy before advancing.";
|
|
3730
|
+
return "No next action; run is terminal.";
|
|
3731
|
+
}
|
|
3732
|
+
function evidenceIssueCode(input) {
|
|
3733
|
+
const packetIssue = nonEmptyString(input.runState.checkpoint_packet?.evidence_excerpt?.evidence_issue_code);
|
|
3734
|
+
if (packetIssue) return packetIssue;
|
|
3735
|
+
const assessmentIssue = nonEmptyString(recordValue(input.fullRiddleState?.proof_assessment)?.evidence_issue_code);
|
|
3736
|
+
if (assessmentIssue) return assessmentIssue;
|
|
3737
|
+
const delta = visualDeltaFrom(input);
|
|
3738
|
+
const status = nonEmptyString(delta?.status);
|
|
3739
|
+
if (status === "unmeasured") {
|
|
3740
|
+
const reason = `${nonEmptyString(delta?.reason) || ""}
|
|
3741
|
+
${input.runState.blocker?.message || ""}`.toLowerCase();
|
|
3742
|
+
return reason.includes("fetch") || reason.includes("allowlist") || reason.includes("registered domain") || reason.includes("high risk") || reason.includes("comparator") ? "comparator_fetch_blocked" : "visual_delta_unmeasured";
|
|
3743
|
+
}
|
|
3744
|
+
if (status === "measured" && delta?.passed === false) return "semantic_proof_failed";
|
|
3745
|
+
return void 0;
|
|
3746
|
+
}
|
|
3747
|
+
function createRiddleProofRunCard(state, input = {}) {
|
|
3748
|
+
const at = input.at || (/* @__PURE__ */ new Date()).toISOString();
|
|
3749
|
+
const fullState = input.fullRiddleState || {};
|
|
3750
|
+
const packet = state.checkpoint_packet;
|
|
3751
|
+
const latestEvent = state.events[state.events.length - 1];
|
|
3752
|
+
const bundle = recordValue(fullState.evidence_bundle);
|
|
3753
|
+
const artifactContract = jsonCloneRecord2(packet?.artifact_contract) || jsonCloneRecord2(recordValue(fullState.proof_assessment_request)?.artifact_contract) || jsonCloneRecord2(recordValue(bundle?.artifact_contract)) || jsonCloneRecord2(state.proof_contract?.artifact_contract);
|
|
3754
|
+
const required = jsonCloneRecord2(recordValue(artifactContract)?.required);
|
|
3755
|
+
const statePaths = input.state_paths || state.state_paths || statePathsForRunState(state);
|
|
3756
|
+
const visualDelta = visualDeltaFrom({ fullRiddleState: fullState, runState: state });
|
|
3757
|
+
const artifacts = artifactsFrom({ fullRiddleState: fullState, runState: state });
|
|
3758
|
+
return {
|
|
3759
|
+
version: RIDDLE_PROOF_RUN_CARD_VERSION,
|
|
3760
|
+
run_id: state.run_id || "unknown",
|
|
3761
|
+
status: state.status,
|
|
3762
|
+
goal: compactRecord({
|
|
3763
|
+
repo: state.request.repo || nonEmptyString(fullState.repo),
|
|
3764
|
+
branch: state.request.branch || nonEmptyString(fullState.branch),
|
|
3765
|
+
change_request: state.request.change_request || nonEmptyString(fullState.change_request),
|
|
3766
|
+
verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
|
|
3767
|
+
success_criteria: state.request.success_criteria
|
|
3768
|
+
}),
|
|
3769
|
+
durable_state: compactRecord({
|
|
3770
|
+
...statePaths,
|
|
3771
|
+
worktree_path: state.worktree_path || nonEmptyString(fullState.after_worktree) || null,
|
|
3772
|
+
branch: state.branch || nonEmptyString(fullState.branch) || null
|
|
3773
|
+
}),
|
|
3774
|
+
current_phase: compactRecord({
|
|
3775
|
+
stage: state.current_stage ?? null,
|
|
3776
|
+
checkpoint: state.last_checkpoint ?? packet?.checkpoint ?? null,
|
|
3777
|
+
latest_event: latestEvent?.kind ?? null,
|
|
3778
|
+
elapsed_ms: elapsedMs(state.created_at, at),
|
|
3779
|
+
stage_elapsed_ms: elapsedMs(state.stage_started_at, at),
|
|
3780
|
+
iterations: state.iterations
|
|
3781
|
+
}),
|
|
3782
|
+
owner_next_action: compactRecord({
|
|
3783
|
+
owner: ownerFor(state),
|
|
3784
|
+
action: actionFor(state),
|
|
3785
|
+
checkpoint_kind: packet?.kind || null,
|
|
3786
|
+
allowed_decisions: packet?.allowed_decisions,
|
|
3787
|
+
retryable: state.status === "running" || state.status === "awaiting_checkpoint",
|
|
3788
|
+
reason: state.blocker?.code || packet?.summary || latestEvent?.summary || null
|
|
3789
|
+
}),
|
|
3790
|
+
evidence_contract: compactRecord({
|
|
3791
|
+
verification_mode: state.request.verification_mode || nonEmptyString(fullState.verification_mode),
|
|
3792
|
+
required,
|
|
3793
|
+
artifact_contract: artifactContract,
|
|
3794
|
+
proof_plan: compactText2(state.proof_contract?.proof_plan || fullState.proof_plan, 600),
|
|
3795
|
+
stop_condition: compactText2(state.proof_contract?.stop_condition, 400)
|
|
3796
|
+
}),
|
|
3797
|
+
latest_evidence: compactRecord({
|
|
3798
|
+
before_url: nonEmptyString(fullState.before_cdn) || state.before_artifact_url || null,
|
|
3799
|
+
prod_url: nonEmptyString(fullState.prod_cdn) || state.prod_artifact_url || null,
|
|
3800
|
+
after_url: nonEmptyString(fullState.after_cdn) || state.after_artifact_url || null,
|
|
3801
|
+
visual_delta: visualDelta || null,
|
|
3802
|
+
evidence_issue_code: evidenceIssueCode({ fullRiddleState: fullState, runState: state }) || null,
|
|
3803
|
+
proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
|
|
3804
|
+
artifacts
|
|
3805
|
+
}),
|
|
3806
|
+
stop_condition: compactRecord({
|
|
3807
|
+
status: state.status,
|
|
3808
|
+
terminal: isTerminalStatus(state.status),
|
|
3809
|
+
blocker_code: state.blocker?.code || null,
|
|
3810
|
+
blocker_message: state.blocker?.message || null,
|
|
3811
|
+
proof_decision: state.proof_decision,
|
|
3812
|
+
merge_recommendation: state.merge_recommendation,
|
|
3813
|
+
monitor_should_continue: !isTerminalStatus(state.status)
|
|
3814
|
+
}),
|
|
3815
|
+
updated_at: state.updated_at
|
|
3816
|
+
};
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
// src/state.ts
|
|
3820
|
+
var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
|
|
3821
|
+
function timestamp2() {
|
|
3822
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3823
|
+
}
|
|
3824
|
+
function createRunId(createdAt) {
|
|
3825
|
+
const stamp = createdAt.replace(/\D/g, "").slice(0, 14) || "unknown";
|
|
3826
|
+
const entropy = Math.random().toString(36).slice(2, 8) || "run";
|
|
3827
|
+
return `rp_${stamp}_${entropy}`;
|
|
3828
|
+
}
|
|
3829
|
+
function elapsedMs2(start, end) {
|
|
3830
|
+
const startMs = start ? Date.parse(start) : NaN;
|
|
3831
|
+
const endMs = end ? Date.parse(end) : NaN;
|
|
3832
|
+
if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
|
|
3833
|
+
return Math.max(0, endMs - startMs);
|
|
3834
|
+
}
|
|
3835
|
+
function normalizePrStatus2(value) {
|
|
3836
|
+
const status = nonEmptyString(value)?.toLowerCase();
|
|
3837
|
+
if (status === "merged") return "merged";
|
|
3838
|
+
if (status === "open") return "open";
|
|
3839
|
+
if (status === "closed") return "closed";
|
|
3840
|
+
if (status === "not_found" || status === "not-found") return "not_found";
|
|
3841
|
+
if (status === "unavailable") return "unavailable";
|
|
3842
|
+
return status || "unknown";
|
|
3843
|
+
}
|
|
3844
|
+
function normalizePrLifecycleState(input, checkedAt = timestamp2()) {
|
|
3845
|
+
const value = recordValue(input);
|
|
3846
|
+
if (!value) return void 0;
|
|
3847
|
+
const cleanup = recordValue(value.cleanup);
|
|
3848
|
+
const mergeCommit = nonEmptyString(value.merge_commit) || nonEmptyString(value.mergeCommit) || nonEmptyString(recordValue(value.mergeCommit)?.oid);
|
|
3849
|
+
return compactRecord({
|
|
3850
|
+
status: normalizePrStatus2(value.status || value.state),
|
|
3851
|
+
pr_url: nonEmptyString(value.pr_url) || nonEmptyString(value.prUrl) || nonEmptyString(value.url),
|
|
3852
|
+
pr_number: nonEmptyString(value.pr_number) || nonEmptyString(value.prNumber) || (typeof value.number === "number" ? String(value.number) : void 0),
|
|
3853
|
+
repo: nonEmptyString(value.repo) || nonEmptyString(value.repository),
|
|
3854
|
+
head_branch: nonEmptyString(value.head_branch) || nonEmptyString(value.headBranch) || nonEmptyString(value.headRefName),
|
|
3855
|
+
base_branch: nonEmptyString(value.base_branch) || nonEmptyString(value.baseBranch) || nonEmptyString(value.baseRefName),
|
|
3856
|
+
merge_commit: mergeCommit,
|
|
3857
|
+
merged_at: nonEmptyString(value.merged_at) || nonEmptyString(value.mergedAt),
|
|
3858
|
+
closed_at: nonEmptyString(value.closed_at) || nonEmptyString(value.closedAt),
|
|
3859
|
+
checked_at: nonEmptyString(value.checked_at) || nonEmptyString(value.checkedAt) || checkedAt,
|
|
3860
|
+
source: nonEmptyString(value.source),
|
|
3861
|
+
next_action: nonEmptyString(value.next_action) || nonEmptyString(value.nextAction),
|
|
3862
|
+
cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
function normalizeIntegrationContext(input, fallbackSource) {
|
|
3866
|
+
const value = recordValue(input);
|
|
3867
|
+
if (!value) {
|
|
3868
|
+
return fallbackSource ? { source: fallbackSource } : void 0;
|
|
3869
|
+
}
|
|
3870
|
+
const metadata = recordValue(value.metadata);
|
|
3871
|
+
return compactRecord({
|
|
3872
|
+
source: nonEmptyString(value.source) || fallbackSource,
|
|
3873
|
+
channel_id: nonEmptyString(value.channel_id),
|
|
3874
|
+
thread_id: nonEmptyString(value.thread_id),
|
|
3875
|
+
message_id: nonEmptyString(value.message_id),
|
|
3876
|
+
source_url: nonEmptyString(value.source_url),
|
|
3877
|
+
metadata: metadata && Object.keys(metadata).length ? metadata : void 0
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
function normalizeRunParams(input) {
|
|
3881
|
+
return compactRecord({
|
|
3882
|
+
repo: input.repo,
|
|
3883
|
+
branch: input.branch,
|
|
3884
|
+
change_request: input.change_request,
|
|
3885
|
+
commit_message: input.commit_message,
|
|
3886
|
+
prod_url: input.prod_url,
|
|
3887
|
+
capture_script: input.capture_script,
|
|
3888
|
+
success_criteria: input.success_criteria,
|
|
3889
|
+
assertions: input.assertions,
|
|
3890
|
+
verification_mode: input.verification_mode,
|
|
3891
|
+
resume_session: input.resume_session,
|
|
3892
|
+
target_image_url: input.target_image_url,
|
|
3893
|
+
target_image_hash: input.target_image_hash,
|
|
3894
|
+
viewport_matrix: input.viewport_matrix,
|
|
3895
|
+
deterministic_setup: input.deterministic_setup,
|
|
3896
|
+
reference: input.reference,
|
|
3897
|
+
base_branch: input.base_branch,
|
|
3898
|
+
before_ref: input.before_ref,
|
|
3899
|
+
allow_static_preview_fallback: input.allow_static_preview_fallback,
|
|
3900
|
+
context: input.context,
|
|
3901
|
+
reviewer: input.reviewer,
|
|
3902
|
+
mode: input.mode,
|
|
3903
|
+
build_command: input.build_command,
|
|
3904
|
+
build_output: input.build_output,
|
|
3905
|
+
server_image: input.server_image,
|
|
3906
|
+
server_command: input.server_command,
|
|
3907
|
+
server_port: input.server_port,
|
|
3908
|
+
server_path: input.server_path,
|
|
3909
|
+
use_auth: input.use_auth,
|
|
3910
|
+
auth_localStorage_json: input.auth_localStorage_json,
|
|
3911
|
+
auth_cookies_json: input.auth_cookies_json,
|
|
3912
|
+
auth_headers_json: input.auth_headers_json,
|
|
3913
|
+
color_scheme: input.color_scheme,
|
|
3914
|
+
wait_for_selector: input.wait_for_selector,
|
|
3915
|
+
ship_mode: input.ship_mode,
|
|
3916
|
+
leave_draft: input.leave_draft,
|
|
3917
|
+
engine_state_path: input.engine_state_path,
|
|
3918
|
+
harness_state_path: input.harness_state_path,
|
|
3919
|
+
max_iterations: input.max_iterations,
|
|
3920
|
+
auto_approve: input.auto_approve,
|
|
3921
|
+
dry_run: input.dry_run,
|
|
3922
|
+
integration_context: normalizeIntegrationContext(input.integration_context)
|
|
3923
|
+
});
|
|
3924
|
+
}
|
|
3925
|
+
function createRunState(input) {
|
|
3926
|
+
const createdAt = input.created_at || timestamp2();
|
|
3927
|
+
return compactRecord({
|
|
3928
|
+
version: RIDDLE_PROOF_RUN_STATE_VERSION,
|
|
3929
|
+
run_id: input.run_id || createRunId(createdAt),
|
|
3930
|
+
state_path: input.state_path,
|
|
3931
|
+
worktree_path: input.worktree_path,
|
|
3932
|
+
branch: input.branch || input.request.branch,
|
|
3933
|
+
current_stage: input.current_stage ?? null,
|
|
3934
|
+
stage_started_at: input.stage_started_at ?? null,
|
|
3935
|
+
status: input.status || "running",
|
|
3936
|
+
created_at: createdAt,
|
|
3937
|
+
updated_at: input.updated_at || createdAt,
|
|
3938
|
+
request: normalizeRunParams(input.request),
|
|
3939
|
+
iterations: input.iterations ?? 0,
|
|
3940
|
+
last_checkpoint: input.last_checkpoint ?? null,
|
|
3941
|
+
checkpoint_packet: input.checkpoint_packet,
|
|
3942
|
+
checkpoint_summary: input.checkpoint_summary,
|
|
3943
|
+
state_paths: input.state_paths,
|
|
3944
|
+
proof_contract: input.proof_contract,
|
|
3945
|
+
run_card: input.run_card,
|
|
3946
|
+
checkpoint_history: input.checkpoint_history,
|
|
3947
|
+
events: input.events ? [...input.events] : []
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
function appendRunEvent(state, input) {
|
|
3951
|
+
const event = {
|
|
3952
|
+
ts: input.ts || timestamp2(),
|
|
3953
|
+
kind: input.kind,
|
|
3954
|
+
checkpoint: input.checkpoint,
|
|
3955
|
+
stage: input.stage,
|
|
3956
|
+
summary: input.summary,
|
|
3957
|
+
details: input.details
|
|
3958
|
+
};
|
|
3959
|
+
state.events.push(compactRecord({
|
|
3960
|
+
ts: event.ts,
|
|
3961
|
+
kind: event.kind,
|
|
3962
|
+
checkpoint: event.checkpoint,
|
|
3963
|
+
stage: event.stage,
|
|
3964
|
+
summary: event.summary,
|
|
3965
|
+
details: event.details
|
|
3966
|
+
}));
|
|
3967
|
+
if (input.checkpoint !== void 0) state.last_checkpoint = input.checkpoint;
|
|
3968
|
+
if (input.stage !== void 0) {
|
|
3969
|
+
if (state.current_stage !== input.stage) state.stage_started_at = event.ts;
|
|
3970
|
+
state.current_stage = input.stage;
|
|
3971
|
+
}
|
|
3972
|
+
state.updated_at = event.ts;
|
|
3973
|
+
return state;
|
|
3974
|
+
}
|
|
3975
|
+
function appendStageHeartbeat(state, input) {
|
|
3976
|
+
const at = input.ts || timestamp2();
|
|
3977
|
+
return appendRunEvent(state, {
|
|
3978
|
+
ts: at,
|
|
3979
|
+
kind: "stage.heartbeat",
|
|
3980
|
+
checkpoint: input.checkpoint || `${input.stage}_heartbeat`,
|
|
3981
|
+
stage: input.stage,
|
|
3982
|
+
summary: input.summary || `${input.stage} stage is active.`,
|
|
3983
|
+
details: compactRecord({
|
|
3984
|
+
elapsed_ms: elapsedMs2(state.created_at, at),
|
|
3985
|
+
stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
|
|
3986
|
+
wait_reason: input.wait_reason,
|
|
3987
|
+
blocker: input.blocker,
|
|
3988
|
+
...input.details
|
|
3989
|
+
})
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
function createRunStatusSnapshot(state, at = timestamp2()) {
|
|
3993
|
+
const latestEvent = state.events[state.events.length - 1];
|
|
3994
|
+
const runId = state.run_id || "unknown";
|
|
3995
|
+
return compactRecord({
|
|
3996
|
+
run_id: runId,
|
|
3997
|
+
status: state.status,
|
|
3998
|
+
is_terminal: isTerminalStatus(state.status),
|
|
3999
|
+
monitor_should_continue: !isTerminalStatus(state.status),
|
|
4000
|
+
current_stage: state.current_stage ?? null,
|
|
4001
|
+
state_path: state.state_path ?? null,
|
|
4002
|
+
worktree_path: state.worktree_path ?? null,
|
|
4003
|
+
branch: state.branch ?? null,
|
|
4004
|
+
pr_url: state.pr_url ?? null,
|
|
4005
|
+
pr_branch: state.pr_branch ?? null,
|
|
4006
|
+
pr_state: state.pr_state,
|
|
4007
|
+
ci_status: state.ci_status,
|
|
4008
|
+
ship_commit: state.ship_commit,
|
|
4009
|
+
ship_remote_head: state.ship_remote_head,
|
|
4010
|
+
merge_commit: state.merge_commit,
|
|
4011
|
+
merged_at: state.merged_at,
|
|
4012
|
+
proof_comment_url: state.proof_comment_url,
|
|
4013
|
+
cleanup_report: state.cleanup_report,
|
|
4014
|
+
iterations: state.iterations,
|
|
4015
|
+
last_checkpoint: state.last_checkpoint ?? null,
|
|
4016
|
+
updated_at: state.updated_at,
|
|
4017
|
+
elapsed_ms: elapsedMs2(state.created_at, at),
|
|
4018
|
+
stage_elapsed_ms: elapsedMs2(state.stage_started_at, at),
|
|
4019
|
+
blocker: state.blocker,
|
|
4020
|
+
checkpoint_packet: state.checkpoint_packet,
|
|
4021
|
+
checkpoint_summary: state.checkpoint_summary,
|
|
4022
|
+
state_paths: state.state_paths,
|
|
4023
|
+
proof_contract: state.proof_contract,
|
|
4024
|
+
run_card: state.run_card || createRiddleProofRunCard(state, { at }),
|
|
4025
|
+
latest_event: latestEvent
|
|
3689
4026
|
});
|
|
3690
4027
|
}
|
|
4028
|
+
function setRunStatus(state, status, at = timestamp2()) {
|
|
4029
|
+
state.status = status;
|
|
4030
|
+
state.ok = status !== "blocked" && status !== "failed";
|
|
4031
|
+
state.updated_at = at;
|
|
4032
|
+
return state;
|
|
4033
|
+
}
|
|
4034
|
+
function applyPrLifecycleState(state, input, at = timestamp2()) {
|
|
4035
|
+
const prState = normalizePrLifecycleState(input, at);
|
|
4036
|
+
if (!prState) return state;
|
|
4037
|
+
state.pr_state = prState;
|
|
4038
|
+
if (prState.pr_url) state.pr_url = prState.pr_url;
|
|
4039
|
+
if (prState.head_branch) state.pr_branch = prState.head_branch;
|
|
4040
|
+
if (prState.merge_commit) state.merge_commit = prState.merge_commit;
|
|
4041
|
+
if (prState.merged_at) state.merged_at = prState.merged_at;
|
|
4042
|
+
if (prState.cleanup) state.cleanup_report = prState.cleanup;
|
|
4043
|
+
if (prState.status === "merged") {
|
|
4044
|
+
state.finalized = true;
|
|
4045
|
+
state.status = "completed";
|
|
4046
|
+
state.ok = true;
|
|
4047
|
+
}
|
|
4048
|
+
state.updated_at = at;
|
|
4049
|
+
return state;
|
|
4050
|
+
}
|
|
3691
4051
|
|
|
3692
4052
|
// src/runner.ts
|
|
3693
4053
|
function errorDetails(error) {
|
|
@@ -4252,6 +4612,10 @@ function shouldPreserveFinalizedRunState(filePath, incoming) {
|
|
|
4252
4612
|
function persist(state) {
|
|
4253
4613
|
state.state_paths = statePathsForRunState(state);
|
|
4254
4614
|
state.checkpoint_summary = checkpointSummaryFromState(state);
|
|
4615
|
+
state.run_card = createRiddleProofRunCard(state, {
|
|
4616
|
+
fullRiddleState: readJson(state.request.engine_state_path),
|
|
4617
|
+
state_paths: state.state_paths
|
|
4618
|
+
});
|
|
4255
4619
|
if (!state.state_path) return;
|
|
4256
4620
|
if (shouldPreserveFinalizedRunState(state.state_path, state)) return;
|
|
4257
4621
|
writeJson(state.state_path, state);
|
|
@@ -4331,7 +4695,7 @@ function removeEmptyToolArtifacts(workdir) {
|
|
|
4331
4695
|
}
|
|
4332
4696
|
return [];
|
|
4333
4697
|
}
|
|
4334
|
-
function
|
|
4698
|
+
function stageFromCheckpoint2(result) {
|
|
4335
4699
|
const explicitStage = nonEmptyString(result.stage);
|
|
4336
4700
|
if (explicitStage) return explicitStage;
|
|
4337
4701
|
const checkpoint = String(result.checkpoint || "");
|
|
@@ -4476,6 +4840,41 @@ function proofAssessmentPayloadFromCheckpointResponse(response) {
|
|
|
4476
4840
|
checkpoint_response_created_at: response.created_at
|
|
4477
4841
|
});
|
|
4478
4842
|
}
|
|
4843
|
+
function reconAssessmentPayloadFromCheckpointResponse(response) {
|
|
4844
|
+
if (![
|
|
4845
|
+
"ready_for_author",
|
|
4846
|
+
"retry_recon",
|
|
4847
|
+
"recon_stuck",
|
|
4848
|
+
"needs_recon"
|
|
4849
|
+
].includes(response.decision)) {
|
|
4850
|
+
return null;
|
|
4851
|
+
}
|
|
4852
|
+
const payload = recordValue(response.payload) || {};
|
|
4853
|
+
const decision = response.decision === "needs_recon" ? "retry_recon" : response.decision;
|
|
4854
|
+
const continueStage = response.continue_with_stage || nonEmptyString(payload.continue_with_stage) || (decision === "ready_for_author" ? "author" : "recon");
|
|
4855
|
+
return compactRecord({
|
|
4856
|
+
...payload,
|
|
4857
|
+
decision,
|
|
4858
|
+
summary: response.summary,
|
|
4859
|
+
continue_with_stage: continueStage,
|
|
4860
|
+
escalation_target: nonEmptyString(payload.escalation_target) || (decision === "recon_stuck" ? "human" : "agent"),
|
|
4861
|
+
reasons: Array.isArray(response.reasons) ? response.reasons : Array.isArray(payload.reasons) ? payload.reasons : [],
|
|
4862
|
+
source: "supervising_agent",
|
|
4863
|
+
checkpoint_response_source: response.source || null,
|
|
4864
|
+
checkpoint_response_created_at: response.created_at
|
|
4865
|
+
});
|
|
4866
|
+
}
|
|
4867
|
+
function implementationNotesFromCheckpointResponse(response) {
|
|
4868
|
+
const payload = recordValue(response.payload) || {};
|
|
4869
|
+
const notes = nonEmptyString(payload.implementation_notes) || nonEmptyString(payload.implementationNotes) || nonEmptyString(payload.summary) || response.summary;
|
|
4870
|
+
const changedFiles = Array.isArray(payload.changed_files) ? payload.changed_files.filter((item) => typeof item === "string") : [];
|
|
4871
|
+
const testsRun = Array.isArray(payload.tests_run) ? payload.tests_run.filter((item) => typeof item === "string") : [];
|
|
4872
|
+
return [
|
|
4873
|
+
notes,
|
|
4874
|
+
changedFiles.length ? `changed_files=${changedFiles.join(", ")}` : "",
|
|
4875
|
+
testsRun.length ? `tests_run=${testsRun.join(", ")}` : ""
|
|
4876
|
+
].filter(Boolean).join("\n");
|
|
4877
|
+
}
|
|
4479
4878
|
function proofAssessmentVisualBlocker(state, payload) {
|
|
4480
4879
|
if (!proofAssessmentRequestsShip(payload)) return null;
|
|
4481
4880
|
const source = nonEmptyString(payload.source) || "supervising_agent";
|
|
@@ -4564,7 +4963,7 @@ function engineFailureBlocker(result, checkpoint) {
|
|
|
4564
4963
|
}
|
|
4565
4964
|
function terminalResult(state, status, result, summary, raw = {}) {
|
|
4566
4965
|
if (result) {
|
|
4567
|
-
const terminalStage =
|
|
4966
|
+
const terminalStage = stageFromCheckpoint2(result);
|
|
4568
4967
|
if (terminalStage !== "setup") state.current_stage = terminalStage;
|
|
4569
4968
|
}
|
|
4570
4969
|
setRunStatus(state, status);
|
|
@@ -4590,7 +4989,7 @@ function terminalResult(state, status, result, summary, raw = {}) {
|
|
|
4590
4989
|
function blockerResult(state, result, blocker) {
|
|
4591
4990
|
state.blocker = blocker;
|
|
4592
4991
|
const blockerStage = nonEmptyString(recordValue(blocker.details)?.stage);
|
|
4593
|
-
const stage = blockerStage ||
|
|
4992
|
+
const stage = blockerStage || stageFromCheckpoint2(result || { checkpoint: blocker.checkpoint || void 0 });
|
|
4594
4993
|
recordEvent(state, {
|
|
4595
4994
|
kind: "run.blocked",
|
|
4596
4995
|
checkpoint: blocker.checkpoint || result?.checkpoint || null,
|
|
@@ -4777,6 +5176,67 @@ function checkpointResponseContinuation(state, value) {
|
|
|
4777
5176
|
appendCheckpointResponse(state, response);
|
|
4778
5177
|
return { next: { ...base, author_packet_json: jsonParam(payload) } };
|
|
4779
5178
|
}
|
|
5179
|
+
if (packet.kind === "assess_recon" || packet.stage === "recon") {
|
|
5180
|
+
const assessment = reconAssessmentPayloadFromCheckpointResponse(response);
|
|
5181
|
+
if (assessment) {
|
|
5182
|
+
appendCheckpointResponse(state, response);
|
|
5183
|
+
return { next: { ...base, recon_assessment_json: jsonParam(assessment) } };
|
|
5184
|
+
}
|
|
5185
|
+
if (response.decision === "blocked" || response.decision === "human_review") {
|
|
5186
|
+
appendCheckpointResponse(state, response, { clear_packet: false });
|
|
5187
|
+
return {
|
|
5188
|
+
blocker: {
|
|
5189
|
+
code: `checkpoint_response_${response.decision}`,
|
|
5190
|
+
checkpoint: packet.checkpoint,
|
|
5191
|
+
message: response.summary || `Checkpoint response stopped recon with decision=${response.decision}.`,
|
|
5192
|
+
details: { stage: packet.stage, response }
|
|
5193
|
+
}
|
|
5194
|
+
};
|
|
5195
|
+
}
|
|
5196
|
+
}
|
|
5197
|
+
if (packet.kind === "implement_change" || packet.stage === "implement") {
|
|
5198
|
+
if (response.decision === "implementation_complete") {
|
|
5199
|
+
const workdir = nonEmptyString(packet.state_excerpt?.after_worktree) || state.worktree_path;
|
|
5200
|
+
if (workdir) state.worktree_path = workdir;
|
|
5201
|
+
if (!hasGitDiff(workdir)) {
|
|
5202
|
+
return {
|
|
5203
|
+
blocker: {
|
|
5204
|
+
code: "implementation_diff_missing",
|
|
5205
|
+
checkpoint: packet.checkpoint,
|
|
5206
|
+
message: "Checkpoint response claimed implementation_complete, but the after worktree has no detectable git diff.",
|
|
5207
|
+
details: { stage: packet.stage, worktree_path: workdir || null, response }
|
|
5208
|
+
}
|
|
5209
|
+
};
|
|
5210
|
+
}
|
|
5211
|
+
appendCheckpointResponse(state, response);
|
|
5212
|
+
return {
|
|
5213
|
+
next: {
|
|
5214
|
+
...base,
|
|
5215
|
+
advance_stage: "implement",
|
|
5216
|
+
implementation_notes: implementationNotesFromCheckpointResponse(response)
|
|
5217
|
+
}
|
|
5218
|
+
};
|
|
5219
|
+
}
|
|
5220
|
+
if (response.decision === "needs_author") {
|
|
5221
|
+
appendCheckpointResponse(state, response);
|
|
5222
|
+
return { next: { ...base, advance_stage: "author" } };
|
|
5223
|
+
}
|
|
5224
|
+
if (response.decision === "needs_recon") {
|
|
5225
|
+
appendCheckpointResponse(state, response);
|
|
5226
|
+
return { next: { ...base, advance_stage: "recon" } };
|
|
5227
|
+
}
|
|
5228
|
+
if (response.decision === "blocked" || response.decision === "human_review") {
|
|
5229
|
+
appendCheckpointResponse(state, response, { clear_packet: false });
|
|
5230
|
+
return {
|
|
5231
|
+
blocker: {
|
|
5232
|
+
code: `checkpoint_response_${response.decision}`,
|
|
5233
|
+
checkpoint: packet.checkpoint,
|
|
5234
|
+
message: response.summary || `Checkpoint response stopped implementation with decision=${response.decision}.`,
|
|
5235
|
+
details: { stage: packet.stage, response }
|
|
5236
|
+
}
|
|
5237
|
+
};
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
4780
5240
|
if (response.decision === "needs_recon") {
|
|
4781
5241
|
appendCheckpointResponse(state, response);
|
|
4782
5242
|
if (packet.kind === "assess_proof" || packet.kind === "recover_evidence" || packet.stage === "verify") {
|
|
@@ -5044,6 +5504,9 @@ async function routeCheckpoint(request, state, result, agent, input) {
|
|
|
5044
5504
|
};
|
|
5045
5505
|
}
|
|
5046
5506
|
if (checkpoint === "recon_supervisor_judgment") {
|
|
5507
|
+
if (input.checkpoint_mode === "yield") {
|
|
5508
|
+
return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
|
|
5509
|
+
}
|
|
5047
5510
|
const assessment = await agent.assessRecon(context);
|
|
5048
5511
|
const blocker = requirePayload("recon_assessment", assessment, state, result);
|
|
5049
5512
|
if (blocker) return { blocker };
|
|
@@ -5079,6 +5542,13 @@ async function routeCheckpoint(request, state, result, agent, input) {
|
|
|
5079
5542
|
};
|
|
5080
5543
|
}
|
|
5081
5544
|
if (checkpoint === "implement_changes_missing" || checkpoint === "implement_required" || checkpoint === "verify_agent_retry" && continueStage === "implement") {
|
|
5545
|
+
if (input.checkpoint_mode === "yield") {
|
|
5546
|
+
const fullState = context.fullRiddleState || {};
|
|
5547
|
+
state.worktree_path = workdirFromState(fullState) || state.worktree_path;
|
|
5548
|
+
state.branch = nonEmptyString(fullState.branch) || state.branch;
|
|
5549
|
+
persist(state);
|
|
5550
|
+
return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
|
|
5551
|
+
}
|
|
5082
5552
|
return handleImplementation(request, state, result, agent);
|
|
5083
5553
|
}
|
|
5084
5554
|
if (checkpoint === "implement_review") {
|
|
@@ -5291,7 +5761,7 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
5291
5761
|
const engineState = engineStatePath(result, state);
|
|
5292
5762
|
if (engineState) state.request.engine_state_path = engineState;
|
|
5293
5763
|
state.last_checkpoint = result.checkpoint || state.last_checkpoint || null;
|
|
5294
|
-
const resultStage =
|
|
5764
|
+
const resultStage = stageFromCheckpoint2(result);
|
|
5295
5765
|
stageIterations[resultStage] = (stageIterations[resultStage] || 0) + 1;
|
|
5296
5766
|
heartbeat(state, {
|
|
5297
5767
|
stage: resultStage,
|
|
@@ -5358,6 +5828,755 @@ async function runRiddleProofEngineHarness(input) {
|
|
|
5358
5828
|
});
|
|
5359
5829
|
}
|
|
5360
5830
|
|
|
5831
|
+
// src/codex-exec-agent.ts
|
|
5832
|
+
var import_node_child_process3 = require("child_process");
|
|
5833
|
+
var import_node_fs4 = require("fs");
|
|
5834
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
5835
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
5836
|
+
var REFINED_INPUTS_SCHEMA = {
|
|
5837
|
+
type: "object",
|
|
5838
|
+
additionalProperties: false,
|
|
5839
|
+
required: ["server_path", "wait_for_selector", "reference"],
|
|
5840
|
+
properties: {
|
|
5841
|
+
server_path: { type: ["string", "null"] },
|
|
5842
|
+
wait_for_selector: { type: ["string", "null"] },
|
|
5843
|
+
reference: { enum: ["before", "prod", "both", null] }
|
|
5844
|
+
}
|
|
5845
|
+
};
|
|
5846
|
+
var BASELINE_UNDERSTANDING_SCHEMA = {
|
|
5847
|
+
type: "object",
|
|
5848
|
+
additionalProperties: false,
|
|
5849
|
+
required: [
|
|
5850
|
+
"reference",
|
|
5851
|
+
"target_route",
|
|
5852
|
+
"before_evidence_url",
|
|
5853
|
+
"visible_before_state",
|
|
5854
|
+
"relevant_elements",
|
|
5855
|
+
"requested_change",
|
|
5856
|
+
"proof_focus",
|
|
5857
|
+
"stop_condition",
|
|
5858
|
+
"quality_risks"
|
|
5859
|
+
],
|
|
5860
|
+
properties: {
|
|
5861
|
+
reference: { type: "string", enum: ["before", "prod", "both", "unknown"] },
|
|
5862
|
+
target_route: { type: "string" },
|
|
5863
|
+
before_evidence_url: { type: "string" },
|
|
5864
|
+
visible_before_state: { type: "string" },
|
|
5865
|
+
relevant_elements: { type: "array", items: { type: "string" } },
|
|
5866
|
+
requested_change: { type: "string" },
|
|
5867
|
+
proof_focus: { type: "string" },
|
|
5868
|
+
stop_condition: { type: "string" },
|
|
5869
|
+
quality_risks: { type: "array", items: { type: "string" } }
|
|
5870
|
+
}
|
|
5871
|
+
};
|
|
5872
|
+
var RECON_SCHEMA = {
|
|
5873
|
+
type: "object",
|
|
5874
|
+
additionalProperties: false,
|
|
5875
|
+
required: [
|
|
5876
|
+
"decision",
|
|
5877
|
+
"summary",
|
|
5878
|
+
"baseline_understanding",
|
|
5879
|
+
"continue_with_stage",
|
|
5880
|
+
"escalation_target",
|
|
5881
|
+
"refined_inputs",
|
|
5882
|
+
"reasons",
|
|
5883
|
+
"source"
|
|
5884
|
+
],
|
|
5885
|
+
properties: {
|
|
5886
|
+
decision: { type: "string", enum: ["retry_recon", "ready_for_author", "recon_stuck"] },
|
|
5887
|
+
summary: { type: "string" },
|
|
5888
|
+
baseline_understanding: BASELINE_UNDERSTANDING_SCHEMA,
|
|
5889
|
+
continue_with_stage: { type: "string", enum: ["recon", "author"] },
|
|
5890
|
+
escalation_target: { type: "string", enum: ["agent", "human"] },
|
|
5891
|
+
refined_inputs: REFINED_INPUTS_SCHEMA,
|
|
5892
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
5893
|
+
source: { type: "string", enum: ["supervising_agent"] }
|
|
5894
|
+
}
|
|
5895
|
+
};
|
|
5896
|
+
var AUTHOR_SCHEMA = {
|
|
5897
|
+
type: "object",
|
|
5898
|
+
additionalProperties: false,
|
|
5899
|
+
required: [
|
|
5900
|
+
"proof_plan",
|
|
5901
|
+
"capture_script",
|
|
5902
|
+
"baseline_understanding_used",
|
|
5903
|
+
"refined_inputs",
|
|
5904
|
+
"rationale",
|
|
5905
|
+
"confidence",
|
|
5906
|
+
"summary"
|
|
5907
|
+
],
|
|
5908
|
+
properties: {
|
|
5909
|
+
proof_plan: { type: "string" },
|
|
5910
|
+
capture_script: { type: "string" },
|
|
5911
|
+
baseline_understanding_used: BASELINE_UNDERSTANDING_SCHEMA,
|
|
5912
|
+
refined_inputs: REFINED_INPUTS_SCHEMA,
|
|
5913
|
+
rationale: { type: "array", items: { type: "string" } },
|
|
5914
|
+
confidence: { type: "string", enum: ["low", "medium", "high"] },
|
|
5915
|
+
summary: { type: "string" }
|
|
5916
|
+
}
|
|
5917
|
+
};
|
|
5918
|
+
var IMPLEMENT_SCHEMA = {
|
|
5919
|
+
type: "object",
|
|
5920
|
+
additionalProperties: false,
|
|
5921
|
+
required: ["summary", "implementation_notes", "changed_files", "tests_run", "blockers"],
|
|
5922
|
+
properties: {
|
|
5923
|
+
summary: { type: "string" },
|
|
5924
|
+
implementation_notes: { type: "string" },
|
|
5925
|
+
changed_files: { type: "array", items: { type: "string" } },
|
|
5926
|
+
tests_run: { type: "array", items: { type: "string" } },
|
|
5927
|
+
blockers: { type: "array", items: { type: "string" } }
|
|
5928
|
+
}
|
|
5929
|
+
};
|
|
5930
|
+
var PROOF_SCHEMA = {
|
|
5931
|
+
type: "object",
|
|
5932
|
+
additionalProperties: false,
|
|
5933
|
+
required: [
|
|
5934
|
+
"decision",
|
|
5935
|
+
"summary",
|
|
5936
|
+
"recommended_stage",
|
|
5937
|
+
"continue_with_stage",
|
|
5938
|
+
"escalation_target",
|
|
5939
|
+
"reasons",
|
|
5940
|
+
"source"
|
|
5941
|
+
],
|
|
5942
|
+
properties: {
|
|
5943
|
+
decision: {
|
|
5944
|
+
type: "string",
|
|
5945
|
+
enum: [
|
|
5946
|
+
"ready_to_ship",
|
|
5947
|
+
"needs_richer_proof",
|
|
5948
|
+
"revise_capture",
|
|
5949
|
+
"needs_recon",
|
|
5950
|
+
"needs_implementation"
|
|
5951
|
+
]
|
|
5952
|
+
},
|
|
5953
|
+
summary: { type: "string" },
|
|
5954
|
+
recommended_stage: { type: "string", enum: ["ship", "author", "implement", "recon", "verify"] },
|
|
5955
|
+
continue_with_stage: { type: "string", enum: ["ship", "author", "implement", "recon", "verify"] },
|
|
5956
|
+
escalation_target: { type: "string", enum: ["agent", "human"] },
|
|
5957
|
+
reasons: { type: "array", items: { type: "string" } },
|
|
5958
|
+
source: { type: "string", enum: ["supervising_agent"] }
|
|
5959
|
+
}
|
|
5960
|
+
};
|
|
5961
|
+
var PROMPT_STRING_LIMIT = 2e3;
|
|
5962
|
+
var PROMPT_ARRAY_LIMIT = 12;
|
|
5963
|
+
var PROMPT_OBJECT_KEY_LIMIT = 70;
|
|
5964
|
+
var PROMPT_BLOCK_LIMIT = 12e4;
|
|
5965
|
+
var PROMPT_KEY_PRIORITY = [
|
|
5966
|
+
"ok",
|
|
5967
|
+
"status",
|
|
5968
|
+
"stage",
|
|
5969
|
+
"checkpoint",
|
|
5970
|
+
"summary",
|
|
5971
|
+
"state_path",
|
|
5972
|
+
"repo",
|
|
5973
|
+
"branch",
|
|
5974
|
+
"change_request",
|
|
5975
|
+
"context",
|
|
5976
|
+
"success_criteria",
|
|
5977
|
+
"verification_mode",
|
|
5978
|
+
"reference",
|
|
5979
|
+
"server_path",
|
|
5980
|
+
"wait_for_selector",
|
|
5981
|
+
"before_cdn",
|
|
5982
|
+
"prod_cdn",
|
|
5983
|
+
"after_cdn",
|
|
5984
|
+
"before_baseline",
|
|
5985
|
+
"prod_baseline",
|
|
5986
|
+
"recon_assessment",
|
|
5987
|
+
"baseline_understanding",
|
|
5988
|
+
"supervisor_author_packet",
|
|
5989
|
+
"proof_plan",
|
|
5990
|
+
"capture_script",
|
|
5991
|
+
"implementation_status",
|
|
5992
|
+
"implementation_summary",
|
|
5993
|
+
"implementation_notes",
|
|
5994
|
+
"changed_files",
|
|
5995
|
+
"verify_status",
|
|
5996
|
+
"verify_summary",
|
|
5997
|
+
"proof_assessment",
|
|
5998
|
+
"proof_assessment_request",
|
|
5999
|
+
"semantic_context",
|
|
6000
|
+
"visual_delta",
|
|
6001
|
+
"proof_evidence_present",
|
|
6002
|
+
"proof_evidence_sample",
|
|
6003
|
+
"artifacts",
|
|
6004
|
+
"assertions",
|
|
6005
|
+
"checkpointContract",
|
|
6006
|
+
"shipGate",
|
|
6007
|
+
"last_error",
|
|
6008
|
+
"errors",
|
|
6009
|
+
"events"
|
|
6010
|
+
];
|
|
6011
|
+
var PROMPT_PRIORITY_INDEX = new Map(PROMPT_KEY_PRIORITY.map((key, index) => [key, index]));
|
|
6012
|
+
function truncatePromptString(value, limit = PROMPT_STRING_LIMIT) {
|
|
6013
|
+
if (value.length <= limit) return value;
|
|
6014
|
+
return `${value.slice(0, limit)}
|
|
6015
|
+
...[truncated ${value.length - limit} chars]`;
|
|
6016
|
+
}
|
|
6017
|
+
function compactPromptValue(value, depth = 0, key = "") {
|
|
6018
|
+
if (value === null || typeof value === "boolean" || typeof value === "number") return value;
|
|
6019
|
+
if (typeof value === "string") {
|
|
6020
|
+
const lowerKey = key.toLowerCase();
|
|
6021
|
+
const looksLikeUrl = /^https?:\/\//.test(value);
|
|
6022
|
+
if (!looksLikeUrl && (lowerKey.includes("base64") || lowerKey.includes("data_url") || lowerKey.includes("screenshot_blob"))) {
|
|
6023
|
+
return `[omitted ${value.length} chars from ${key || "large artifact"}]`;
|
|
6024
|
+
}
|
|
6025
|
+
const limit = looksLikeUrl ? 1e3 : depth <= 1 ? PROMPT_STRING_LIMIT : 1200;
|
|
6026
|
+
return truncatePromptString(value, limit);
|
|
6027
|
+
}
|
|
6028
|
+
if (Array.isArray(value)) {
|
|
6029
|
+
const lowerKey = key.toLowerCase();
|
|
6030
|
+
const items = lowerKey.includes("event") || lowerKey.includes("histor") || lowerKey.includes("retry") ? value.slice(-PROMPT_ARRAY_LIMIT) : value.slice(0, PROMPT_ARRAY_LIMIT);
|
|
6031
|
+
const compacted = items.map((item) => compactPromptValue(item, depth + 1, key));
|
|
6032
|
+
if (value.length > items.length) {
|
|
6033
|
+
const omitted = value.length - items.length;
|
|
6034
|
+
return lowerKey.includes("event") || lowerKey.includes("histor") || lowerKey.includes("retry") ? [{ omittedEarlierItems: omitted }, ...compacted] : [...compacted, { omittedItems: omitted }];
|
|
6035
|
+
}
|
|
6036
|
+
return compacted;
|
|
6037
|
+
}
|
|
6038
|
+
if (!value || typeof value !== "object") return String(value);
|
|
6039
|
+
const entries = Object.entries(value).sort(([left], [right]) => {
|
|
6040
|
+
const leftPriority = PROMPT_PRIORITY_INDEX.get(left) ?? 1e3;
|
|
6041
|
+
const rightPriority = PROMPT_PRIORITY_INDEX.get(right) ?? 1e3;
|
|
6042
|
+
if (leftPriority !== rightPriority) return leftPriority - rightPriority;
|
|
6043
|
+
return left.localeCompare(right);
|
|
6044
|
+
});
|
|
6045
|
+
const result = {};
|
|
6046
|
+
for (const [entryKey, entryValue] of entries.slice(0, PROMPT_OBJECT_KEY_LIMIT)) {
|
|
6047
|
+
result[entryKey] = compactPromptValue(entryValue, depth + 1, entryKey);
|
|
6048
|
+
}
|
|
6049
|
+
if (entries.length > PROMPT_OBJECT_KEY_LIMIT) {
|
|
6050
|
+
result.__omitted_keys = entries.length - PROMPT_OBJECT_KEY_LIMIT;
|
|
6051
|
+
}
|
|
6052
|
+
return result;
|
|
6053
|
+
}
|
|
6054
|
+
function jsonBlock(label, value) {
|
|
6055
|
+
let json = JSON.stringify(compactPromptValue(value), null, 2);
|
|
6056
|
+
if (json.length > PROMPT_BLOCK_LIMIT) {
|
|
6057
|
+
json = `${json.slice(0, PROMPT_BLOCK_LIMIT)}
|
|
6058
|
+
...[truncated ${json.length - PROMPT_BLOCK_LIMIT} chars from compacted ${label}]`;
|
|
6059
|
+
}
|
|
6060
|
+
return `${label}:
|
|
6061
|
+
${json}`;
|
|
6062
|
+
}
|
|
6063
|
+
function resolveWorkdir(context, fallback = "/tmp") {
|
|
6064
|
+
const after = typeof context.fullRiddleState?.after_worktree === "string" ? context.fullRiddleState.after_worktree.trim() : "";
|
|
6065
|
+
return after || fallback;
|
|
6066
|
+
}
|
|
6067
|
+
function basePrompt(context, role) {
|
|
6068
|
+
return [
|
|
6069
|
+
role,
|
|
6070
|
+
"",
|
|
6071
|
+
"You are the supervising Codex worker inside the Riddle Proof harness.",
|
|
6072
|
+
"Return only JSON matching the provided output schema.",
|
|
6073
|
+
"Do not ask the human to manually continue. If blocked, encode the blocker in the JSON fields allowed by the schema.",
|
|
6074
|
+
"Large raw artifacts are summarized before this prompt. Use preserved state summaries, URLs, file paths, and proof evidence samples instead of expecting full raw logs or binary artifacts inline.",
|
|
6075
|
+
"",
|
|
6076
|
+
jsonBlock("Original request", context.request),
|
|
6077
|
+
jsonBlock("Riddle checkpoint result", context.engineResult),
|
|
6078
|
+
jsonBlock("Full riddle state", context.fullRiddleState || {})
|
|
6079
|
+
].join("\n");
|
|
6080
|
+
}
|
|
6081
|
+
function schemaRequiredKeys(schema) {
|
|
6082
|
+
const required = schema?.required;
|
|
6083
|
+
return Array.isArray(required) ? required.filter((key) => typeof key === "string" && key.length > 0) : [];
|
|
6084
|
+
}
|
|
6085
|
+
function isSchemaShapedObject(value, schema) {
|
|
6086
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
6087
|
+
const required = schemaRequiredKeys(schema);
|
|
6088
|
+
return required.every((key) => Object.prototype.hasOwnProperty.call(value, key));
|
|
6089
|
+
}
|
|
6090
|
+
function parseJsonCandidate(raw, schema) {
|
|
6091
|
+
try {
|
|
6092
|
+
const parsed = JSON.parse(raw);
|
|
6093
|
+
return isSchemaShapedObject(parsed, schema) ? parsed : null;
|
|
6094
|
+
} catch {
|
|
6095
|
+
return null;
|
|
6096
|
+
}
|
|
6097
|
+
}
|
|
6098
|
+
function extractJsonObjectCandidates(raw) {
|
|
6099
|
+
const candidates = [];
|
|
6100
|
+
let depth = 0;
|
|
6101
|
+
let start = -1;
|
|
6102
|
+
let inString = false;
|
|
6103
|
+
let escaped = false;
|
|
6104
|
+
for (let index = 0; index < raw.length; index += 1) {
|
|
6105
|
+
const char = raw[index];
|
|
6106
|
+
if (inString) {
|
|
6107
|
+
if (escaped) {
|
|
6108
|
+
escaped = false;
|
|
6109
|
+
} else if (char === "\\") {
|
|
6110
|
+
escaped = true;
|
|
6111
|
+
} else if (char === '"') {
|
|
6112
|
+
inString = false;
|
|
6113
|
+
}
|
|
6114
|
+
continue;
|
|
6115
|
+
}
|
|
6116
|
+
if (char === '"') {
|
|
6117
|
+
inString = true;
|
|
6118
|
+
continue;
|
|
6119
|
+
}
|
|
6120
|
+
if (char === "{") {
|
|
6121
|
+
if (depth === 0) start = index;
|
|
6122
|
+
depth += 1;
|
|
6123
|
+
continue;
|
|
6124
|
+
}
|
|
6125
|
+
if (char === "}" && depth > 0) {
|
|
6126
|
+
depth -= 1;
|
|
6127
|
+
if (depth === 0 && start >= 0) {
|
|
6128
|
+
candidates.push(raw.slice(start, index + 1));
|
|
6129
|
+
start = -1;
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
return candidates;
|
|
6134
|
+
}
|
|
6135
|
+
function parseJsonObject(raw, schema) {
|
|
6136
|
+
const trimmed = raw.trim();
|
|
6137
|
+
if (!trimmed) return null;
|
|
6138
|
+
const whole = parseJsonCandidate(trimmed, schema);
|
|
6139
|
+
if (whole) return whole;
|
|
6140
|
+
const lines = trimmed.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
6141
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
6142
|
+
const parsed = parseJsonCandidate(lines[index], schema);
|
|
6143
|
+
if (parsed) return parsed;
|
|
6144
|
+
}
|
|
6145
|
+
const candidates = extractJsonObjectCandidates(trimmed);
|
|
6146
|
+
for (let index = candidates.length - 1; index >= 0; index -= 1) {
|
|
6147
|
+
const parsed = parseJsonCandidate(candidates[index], schema);
|
|
6148
|
+
if (parsed) return parsed;
|
|
6149
|
+
}
|
|
6150
|
+
return null;
|
|
6151
|
+
}
|
|
6152
|
+
function isHarnessVerificationOnlyBlocker(blocker) {
|
|
6153
|
+
const text = blocker.toLowerCase();
|
|
6154
|
+
return (text.includes("erofs") || text.includes("read-only file system")) && text.includes("node_modules") && (text.includes(".vite-temp") || text.includes("vite.config"));
|
|
6155
|
+
}
|
|
6156
|
+
function createCodexExecJsonRunner(config = {}) {
|
|
6157
|
+
return (request) => {
|
|
6158
|
+
if (!request.workdir || !(0, import_node_fs4.existsSync)(request.workdir)) {
|
|
6159
|
+
return {
|
|
6160
|
+
ok: false,
|
|
6161
|
+
blocker: {
|
|
6162
|
+
code: "codex_workdir_missing",
|
|
6163
|
+
message: `Codex workdir does not exist for ${request.purpose}.`,
|
|
6164
|
+
details: { workdir: request.workdir }
|
|
6165
|
+
}
|
|
6166
|
+
};
|
|
6167
|
+
}
|
|
6168
|
+
const tmpDir = (0, import_node_fs4.mkdtempSync)(import_node_path4.default.join(import_node_os.default.tmpdir(), "riddle-proof-codex-"));
|
|
6169
|
+
const schemaPath = import_node_path4.default.join(tmpDir, "schema.json");
|
|
6170
|
+
const lastMessagePath = import_node_path4.default.join(tmpDir, "last-message.json");
|
|
6171
|
+
(0, import_node_fs4.writeFileSync)(schemaPath, JSON.stringify(request.schema, null, 2));
|
|
6172
|
+
const args = [
|
|
6173
|
+
"exec",
|
|
6174
|
+
"--json",
|
|
6175
|
+
"--output-schema",
|
|
6176
|
+
schemaPath,
|
|
6177
|
+
"--output-last-message",
|
|
6178
|
+
lastMessagePath,
|
|
6179
|
+
"--cd",
|
|
6180
|
+
request.workdir,
|
|
6181
|
+
"--sandbox",
|
|
6182
|
+
config.codexSandbox || "workspace-write",
|
|
6183
|
+
"--skip-git-repo-check"
|
|
6184
|
+
];
|
|
6185
|
+
if (config.codexFullAuto !== false) args.push("--full-auto");
|
|
6186
|
+
if (config.codexModel) args.push("-m", config.codexModel);
|
|
6187
|
+
args.push("-");
|
|
6188
|
+
const env = { ...process.env };
|
|
6189
|
+
if (config.codexHome) env.CODEX_HOME = config.codexHome;
|
|
6190
|
+
delete env.OPENAI_API_KEY;
|
|
6191
|
+
try {
|
|
6192
|
+
const proc = (0, import_node_child_process3.spawnSync)(config.codexCommand || "codex", args, {
|
|
6193
|
+
input: request.prompt,
|
|
6194
|
+
encoding: "utf-8",
|
|
6195
|
+
timeout: Number(config.codexTimeoutMs || 6e5),
|
|
6196
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
6197
|
+
env
|
|
6198
|
+
});
|
|
6199
|
+
if (proc.error) {
|
|
6200
|
+
const timedOut = proc.error.code === "ETIMEDOUT";
|
|
6201
|
+
return {
|
|
6202
|
+
ok: false,
|
|
6203
|
+
stdout: proc.stdout || "",
|
|
6204
|
+
stderr: proc.stderr || "",
|
|
6205
|
+
blocker: {
|
|
6206
|
+
code: timedOut ? "codex_timeout" : "codex_exec_error",
|
|
6207
|
+
message: timedOut ? `Codex timed out during ${request.purpose}.` : `Codex failed to start or complete ${request.purpose}.`,
|
|
6208
|
+
details: { error: proc.error.message }
|
|
6209
|
+
}
|
|
6210
|
+
};
|
|
6211
|
+
}
|
|
6212
|
+
if (proc.status !== 0) {
|
|
6213
|
+
return {
|
|
6214
|
+
ok: false,
|
|
6215
|
+
stdout: proc.stdout || "",
|
|
6216
|
+
stderr: proc.stderr || "",
|
|
6217
|
+
blocker: {
|
|
6218
|
+
code: "codex_nonzero_exit",
|
|
6219
|
+
message: `Codex exited with status ${proc.status} during ${request.purpose}.`,
|
|
6220
|
+
details: { stdout: proc.stdout || "", stderr: proc.stderr || "" }
|
|
6221
|
+
}
|
|
6222
|
+
};
|
|
6223
|
+
}
|
|
6224
|
+
const finalText = (0, import_node_fs4.existsSync)(lastMessagePath) ? (0, import_node_fs4.readFileSync)(lastMessagePath, "utf-8") : String(proc.stdout || "");
|
|
6225
|
+
const parsed = parseJsonObject(finalText, request.schema);
|
|
6226
|
+
if (!parsed) {
|
|
6227
|
+
return {
|
|
6228
|
+
ok: false,
|
|
6229
|
+
stdout: proc.stdout || "",
|
|
6230
|
+
stderr: proc.stderr || "",
|
|
6231
|
+
blocker: {
|
|
6232
|
+
code: "codex_invalid_json",
|
|
6233
|
+
message: `Codex completed ${request.purpose}, but did not return valid JSON.`,
|
|
6234
|
+
details: { finalText, stdout: proc.stdout || "", stderr: proc.stderr || "" }
|
|
6235
|
+
}
|
|
6236
|
+
};
|
|
6237
|
+
}
|
|
6238
|
+
return {
|
|
6239
|
+
ok: true,
|
|
6240
|
+
json: parsed,
|
|
6241
|
+
stdout: proc.stdout || "",
|
|
6242
|
+
stderr: proc.stderr || ""
|
|
6243
|
+
};
|
|
6244
|
+
} finally {
|
|
6245
|
+
(0, import_node_fs4.rmSync)(tmpDir, { recursive: true, force: true });
|
|
6246
|
+
}
|
|
6247
|
+
};
|
|
6248
|
+
}
|
|
6249
|
+
async function callRunner(runner, request) {
|
|
6250
|
+
return runner(request);
|
|
6251
|
+
}
|
|
6252
|
+
function payloadOrBlocker(raw, checkpoint) {
|
|
6253
|
+
if (!raw.ok || !raw.json) {
|
|
6254
|
+
const blocker = raw.blocker || {
|
|
6255
|
+
code: "codex_runner_failed",
|
|
6256
|
+
message: "Codex runner failed without a detailed blocker.",
|
|
6257
|
+
details: { stdout: raw.stdout || "", stderr: raw.stderr || "" }
|
|
6258
|
+
};
|
|
6259
|
+
return {
|
|
6260
|
+
ok: false,
|
|
6261
|
+
blocker: {
|
|
6262
|
+
...blocker,
|
|
6263
|
+
checkpoint
|
|
6264
|
+
}
|
|
6265
|
+
};
|
|
6266
|
+
}
|
|
6267
|
+
return {
|
|
6268
|
+
ok: true,
|
|
6269
|
+
payload: raw.json,
|
|
6270
|
+
summary: typeof raw.json.summary === "string" ? raw.json.summary : void 0
|
|
6271
|
+
};
|
|
6272
|
+
}
|
|
6273
|
+
function stringArray(value) {
|
|
6274
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
6275
|
+
}
|
|
6276
|
+
function parseGitStatusPaths2(status) {
|
|
6277
|
+
return status.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean).map((line) => {
|
|
6278
|
+
let item = line.length > 3 ? line.slice(3) : line;
|
|
6279
|
+
if (item.includes(" -> ")) item = item.split(" -> ").pop() || item;
|
|
6280
|
+
return item.trim();
|
|
6281
|
+
}).filter(Boolean);
|
|
6282
|
+
}
|
|
6283
|
+
function isToolNoisePath2(filePath) {
|
|
6284
|
+
return filePath === ".codex" || filePath.startsWith(".codex/") || filePath === ".oc-smoke" || filePath.startsWith(".oc-smoke/");
|
|
6285
|
+
}
|
|
6286
|
+
function hasGitDiff2(workdir) {
|
|
6287
|
+
try {
|
|
6288
|
+
const status = git(["status", "--porcelain"], workdir);
|
|
6289
|
+
return parseGitStatusPaths2(status).some((filePath) => !isToolNoisePath2(filePath));
|
|
6290
|
+
} catch {
|
|
6291
|
+
return false;
|
|
6292
|
+
}
|
|
6293
|
+
}
|
|
6294
|
+
function buildImplementationPrompt(context, extraLines = []) {
|
|
6295
|
+
return [
|
|
6296
|
+
basePrompt(context, "Implement the requested code change in the after worktree."),
|
|
6297
|
+
"Make the code changes directly in this repository.",
|
|
6298
|
+
"Use the recon-approved baseline understanding in the state to decide exactly what prior UI/state is being changed.",
|
|
6299
|
+
"Run focused checks when practical.",
|
|
6300
|
+
"If a focused check is blocked only by the harness sandbox writing Vite temp config into a shared/symlinked node_modules path (for example EROFS on node_modules/.vite-temp/vite.config...), do not treat that as an implementation blocker when the requested git diff exists. Record it in tests_run or implementation_notes instead so the harness can advance to its own verify stage.",
|
|
6301
|
+
"Leave a real git diff in the after worktree. Do not commit or push.",
|
|
6302
|
+
"Before you return success, run git status --short and git diff --name-only in this repository and verify they show the intended change.",
|
|
6303
|
+
"Do not return success with empty changed_files or a clean git status. If you cannot create the requested diff, explain why in blockers instead.",
|
|
6304
|
+
"changed_files should match the real git diff as closely as practical.",
|
|
6305
|
+
"Return changed_files, implementation_notes, tests_run, and blockers if any.",
|
|
6306
|
+
"Use empty arrays for tests_run or blockers when none apply.",
|
|
6307
|
+
...extraLines
|
|
6308
|
+
].join("\n");
|
|
6309
|
+
}
|
|
6310
|
+
function createCodexExecAgentAdapter(config = {}, runner = createCodexExecJsonRunner(config)) {
|
|
6311
|
+
return {
|
|
6312
|
+
async assessRecon(context) {
|
|
6313
|
+
const raw = await callRunner(runner, {
|
|
6314
|
+
purpose: "recon assessment",
|
|
6315
|
+
workdir: resolveWorkdir(context),
|
|
6316
|
+
schema: RECON_SCHEMA,
|
|
6317
|
+
prompt: [
|
|
6318
|
+
basePrompt(context, "Judge the latest recon packet."),
|
|
6319
|
+
"Decide whether recon should retry, continue to author, or escalate to the human.",
|
|
6320
|
+
"This is the first intelligent before-evidence gate. It runs before proof authoring and before any code edits.",
|
|
6321
|
+
"Prefer ready_for_author only when the baseline evidence is trustworthy for the requested change.",
|
|
6322
|
+
"Do not approve recon just because telemetry_ready is true or a screenshot URL exists.",
|
|
6323
|
+
"Inspect the baseline evidence in the state: screenshot URLs, structured pageState details, visible_text_sample, headings, buttons, links, canvas_count, large_visible_elements, observed_path, and route candidates.",
|
|
6324
|
+
"Fill baseline_understanding with concrete observations about what the before/prod evidence shows, what exact user request it anchors, what proof should focus on, and what stop condition would satisfy the request.",
|
|
6325
|
+
"If you cannot write a specific baseline_understanding from the current evidence, choose retry_recon or recon_stuck; do not choose ready_for_author.",
|
|
6326
|
+
"Reject blank, banner-only, app-shell-only, loading-only, generic landing, source-import path, or wrong-feature baselines; retry recon with a better server_path or selector instead.",
|
|
6327
|
+
"Your summary must say what is visibly present in the approved baseline or why the current baseline is not good enough.",
|
|
6328
|
+
"Always include refined_inputs; use null values for server_path, wait_for_selector, or reference when no refinement is needed."
|
|
6329
|
+
].join("\n")
|
|
6330
|
+
});
|
|
6331
|
+
return payloadOrBlocker(raw, context.checkpoint);
|
|
6332
|
+
},
|
|
6333
|
+
async authorProofPacket(context) {
|
|
6334
|
+
const raw = await callRunner(runner, {
|
|
6335
|
+
purpose: "proof packet authoring",
|
|
6336
|
+
workdir: resolveWorkdir(context),
|
|
6337
|
+
schema: AUTHOR_SCHEMA,
|
|
6338
|
+
prompt: [
|
|
6339
|
+
basePrompt(context, "Author the proof packet."),
|
|
6340
|
+
"Write a proof_plan and capture_script that will verify the exact user-facing change.",
|
|
6341
|
+
"Use recon_assessment.baseline_understanding as the source of truth. Do not author a proof plan unless it names the observed before state and the requested delta from that state.",
|
|
6342
|
+
"Use the recon-approved route and baseline context; make the plan name the concrete target, expected before state, expected after state, and stop condition.",
|
|
6343
|
+
"Choose the evidence modality from verification_mode and success_criteria: screenshots for visual/UI proof, interactions plus screenshots for interaction proof, structured metrics/logs/JSON/audio analysis for non-visual proof.",
|
|
6344
|
+
"For playable/gameplay proof, treat screenshots as supporting artifacts only: start the game, send keyboard or pointer input, measure state before/after, measure non-HUD canvas/playfield pixel deltas across time, and return playability evidence with version riddle-proof.playability.v1.",
|
|
6345
|
+
"For structured proof, collect meaningful measurements inside page.evaluate and set window.__riddleProofEvidence in that browser page context to a JSON-serializable object. Screenshots are optional supporting context for data/audio/log/metric/custom modes.",
|
|
6346
|
+
"Do not assign globalThis.__riddleProofEvidence, window.__riddleProofEvidence, or self.__riddleProofEvidence outside page.evaluate; the Riddle worker context may not expose those globals safely.",
|
|
6347
|
+
"Do not call Playwright page.* APIs inside page.evaluate; page.evaluate runs in the browser page, while page.waitForFunction, page.waitForSelector, page.click, and saveScreenshot belong in the outer capture script.",
|
|
6348
|
+
"When page.evaluate needs data from the outer Playwright script, pass exactly one serializable argument object; do not pass multiple positional arguments.",
|
|
6349
|
+
"When setting Playwright wait timeouts, use the correct signature: await page.waitForFunction(fn, undefined, { timeout: 60000 }). Do not write page.waitForFunction(fn, { timeout: 60000 }); that passes the object as the page argument and leaves the default timeout in place.",
|
|
6350
|
+
"For audio/data/metric proof, return and persist the same evidence object: const evidence = await page.evaluate(async () => { /* browser measurements */ window.__riddleProofEvidence = { ... }; return window.__riddleProofEvidence; }); Then assert evidence fields before saving screenshots.",
|
|
6351
|
+
"If a capture attempt errors or proof_evidence is absent, revise the capture_script to make structured evidence easier to collect; do not only add more screenshots for non-visual proof.",
|
|
6352
|
+
"When checking visible copy, normalize text before exact matching: const normalizedText = (document.body?.innerText || '').replace(/\\s+/g, ' ').trim(); Avoid raw innerText.includes(exact sentence) because browser line wrapping can split copy.",
|
|
6353
|
+
"Prefer success-oriented evidence booleans such as newCopyVisible: true and oldCopyAbsent: true. If a positive assertion is false while screenshots/text samples look right, fix the capture script instead of leaving contradictory proof evidence.",
|
|
6354
|
+
"Include a short matchedSnippet or normalizedTextSample when proofing copy so assertion mismatches are diagnosable.",
|
|
6355
|
+
"For visual/UI proof, include saveScreenshot('after-proof') exactly once.",
|
|
6356
|
+
"Avoid generic proof language. The packet should be specific enough that verify can tell whether the requested change actually happened.",
|
|
6357
|
+
"Echo the baseline understanding you used in baseline_understanding_used so later stages can detect drift.",
|
|
6358
|
+
"Use refined_inputs for server_path, wait_for_selector, or reference when useful; use null values when no refinement is needed."
|
|
6359
|
+
].join("\n")
|
|
6360
|
+
});
|
|
6361
|
+
return payloadOrBlocker(raw, context.checkpoint);
|
|
6362
|
+
},
|
|
6363
|
+
async implementChange(context) {
|
|
6364
|
+
if (!context.workdir || !(0, import_node_fs4.existsSync)(context.workdir)) {
|
|
6365
|
+
return {
|
|
6366
|
+
ok: false,
|
|
6367
|
+
blocker: {
|
|
6368
|
+
code: "implementation_workdir_missing",
|
|
6369
|
+
checkpoint: context.checkpoint,
|
|
6370
|
+
message: "The Riddle Proof state does not include an after worktree that exists on disk.",
|
|
6371
|
+
details: { workdir: context.workdir || null }
|
|
6372
|
+
}
|
|
6373
|
+
};
|
|
6374
|
+
}
|
|
6375
|
+
const workdir = context.workdir;
|
|
6376
|
+
const attemptSummaries = [];
|
|
6377
|
+
const runImplementationAttempt = async (purpose, extraLines = []) => {
|
|
6378
|
+
const raw = await callRunner(runner, {
|
|
6379
|
+
purpose,
|
|
6380
|
+
workdir,
|
|
6381
|
+
schema: IMPLEMENT_SCHEMA,
|
|
6382
|
+
prompt: buildImplementationPrompt(context, extraLines)
|
|
6383
|
+
});
|
|
6384
|
+
if (!raw.ok || !raw.json) {
|
|
6385
|
+
return {
|
|
6386
|
+
ok: false,
|
|
6387
|
+
payload: payloadOrBlocker(raw, context.checkpoint)
|
|
6388
|
+
};
|
|
6389
|
+
}
|
|
6390
|
+
const changedFiles = stringArray(raw.json.changed_files);
|
|
6391
|
+
const blockers = stringArray(raw.json.blockers);
|
|
6392
|
+
const testsRun = stringArray(raw.json.tests_run);
|
|
6393
|
+
const softVerificationBlockers = changedFiles.length ? blockers.filter(isHarnessVerificationOnlyBlocker) : [];
|
|
6394
|
+
const hardBlockers = blockers.filter((item) => !softVerificationBlockers.includes(item));
|
|
6395
|
+
const implementationNotesRaw = typeof raw.json.implementation_notes === "string" ? raw.json.implementation_notes : "";
|
|
6396
|
+
const summary = typeof raw.json.summary === "string" ? raw.json.summary : "";
|
|
6397
|
+
const implementationNotes = [
|
|
6398
|
+
implementationNotesRaw,
|
|
6399
|
+
...softVerificationBlockers.map((item) => `Harness verification note: ${item}`)
|
|
6400
|
+
].filter(Boolean).join("\n");
|
|
6401
|
+
const agentDetails = {
|
|
6402
|
+
agent_purpose: purpose,
|
|
6403
|
+
agent_summary: summary,
|
|
6404
|
+
agent_changed_files: changedFiles,
|
|
6405
|
+
agent_tests_run: testsRun,
|
|
6406
|
+
agent_blockers: blockers
|
|
6407
|
+
};
|
|
6408
|
+
attemptSummaries.push({
|
|
6409
|
+
purpose,
|
|
6410
|
+
summary,
|
|
6411
|
+
changed_files: changedFiles,
|
|
6412
|
+
tests_run: testsRun,
|
|
6413
|
+
blockers
|
|
6414
|
+
});
|
|
6415
|
+
if (hardBlockers.length) {
|
|
6416
|
+
return {
|
|
6417
|
+
ok: false,
|
|
6418
|
+
payload: {
|
|
6419
|
+
ok: false,
|
|
6420
|
+
blocker: {
|
|
6421
|
+
code: "codex_implementation_blocked",
|
|
6422
|
+
checkpoint: context.checkpoint,
|
|
6423
|
+
message: summary || "Codex reported implementation blockers.",
|
|
6424
|
+
details: {
|
|
6425
|
+
blockers: hardBlockers,
|
|
6426
|
+
changedFiles,
|
|
6427
|
+
testsRun,
|
|
6428
|
+
implementationNotes: implementationNotesRaw,
|
|
6429
|
+
...agentDetails
|
|
6430
|
+
}
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
};
|
|
6434
|
+
}
|
|
6435
|
+
return {
|
|
6436
|
+
ok: true,
|
|
6437
|
+
summary,
|
|
6438
|
+
changedFiles,
|
|
6439
|
+
testsRun,
|
|
6440
|
+
implementationNotes,
|
|
6441
|
+
implementationNotesRaw,
|
|
6442
|
+
softVerificationBlockers,
|
|
6443
|
+
hardBlockers,
|
|
6444
|
+
agentDetails
|
|
6445
|
+
};
|
|
6446
|
+
};
|
|
6447
|
+
let attempt = await runImplementationAttempt("implementation");
|
|
6448
|
+
if (!attempt.ok) return attempt.payload;
|
|
6449
|
+
let diffDetected = hasGitDiff2(workdir);
|
|
6450
|
+
if (!diffDetected) {
|
|
6451
|
+
attempt = await runImplementationAttempt("implementation retry", [
|
|
6452
|
+
"The previous implementation attempt returned without a detectable git diff in this repository.",
|
|
6453
|
+
`Previous summary: ${attempt.summary || "(none)"}`,
|
|
6454
|
+
`Previous changed_files: ${JSON.stringify(attempt.changedFiles)}`,
|
|
6455
|
+
"Before you return success this time, run git status --short and git diff --name-only. If they are still empty, do not return success; either keep editing or explain the blocker."
|
|
6456
|
+
]);
|
|
6457
|
+
if (!attempt.ok) return attempt.payload;
|
|
6458
|
+
diffDetected = hasGitDiff2(workdir);
|
|
6459
|
+
}
|
|
6460
|
+
return {
|
|
6461
|
+
ok: true,
|
|
6462
|
+
summary: attempt.summary || void 0,
|
|
6463
|
+
implementationNotes: attempt.implementationNotes || void 0,
|
|
6464
|
+
changedFiles: attempt.changedFiles,
|
|
6465
|
+
testsRun: attempt.testsRun,
|
|
6466
|
+
details: {
|
|
6467
|
+
...attempt.agentDetails,
|
|
6468
|
+
implementation_notes: attempt.implementationNotes || attempt.implementationNotesRaw || "",
|
|
6469
|
+
soft_verification_blockers: attempt.softVerificationBlockers,
|
|
6470
|
+
hard_blocker_count: attempt.hardBlockers.length,
|
|
6471
|
+
retry_attempted: attemptSummaries.length > 1,
|
|
6472
|
+
attempt_count: attemptSummaries.length,
|
|
6473
|
+
attempt_summaries: attemptSummaries,
|
|
6474
|
+
post_agent_diff_detected: diffDetected
|
|
6475
|
+
}
|
|
6476
|
+
};
|
|
6477
|
+
},
|
|
6478
|
+
async assessProof(context) {
|
|
6479
|
+
const raw = await callRunner(runner, {
|
|
6480
|
+
purpose: "proof assessment",
|
|
6481
|
+
workdir: resolveWorkdir(context),
|
|
6482
|
+
schema: PROOF_SCHEMA,
|
|
6483
|
+
prompt: [
|
|
6484
|
+
basePrompt(context, "Judge the proof bundle."),
|
|
6485
|
+
"Decide whether the evidence is ready_to_ship or which internal stage should run next.",
|
|
6486
|
+
"Only use ready_to_ship when the before/prod and after evidence actually prove the requested change.",
|
|
6487
|
+
"Do not assume screenshots are required for every verification_mode. For data/audio/log/metric/custom proof, inspect the structured evidence bundle, proof_evidence_sample, artifacts, assertions, and success criteria directly.",
|
|
6488
|
+
"Use semantic_context.route, headings, buttons, and text anchors to ground route/content judgment before calling screenshot evidence wrong-route or unrelated.",
|
|
6489
|
+
"If structured proof evidence contains failed positive assertions, such as newCopyVisible: false or hasExpectedText: false, do not choose ready_to_ship until the evidence is reconciled or a richer proof is produced.",
|
|
6490
|
+
"For visual/UI proof, screenshots and route/page-state quality still matter, but capture success alone is not proof.",
|
|
6491
|
+
"For playable/gameplay proof, do not choose ready_to_ship unless playability evidence shows accepted input, state/time progression, and playfield/canvas pixel motion; a static generated scene is not playable proof.",
|
|
6492
|
+
"For visual/UI polish, reject changes that are technically different but not legible to a reviewer. If visual_delta.status is measured and visual_delta.passed is false, choose needs_implementation when the visible result is wrong, or needs_richer_proof only when non-visual proof artifacts are insufficient.",
|
|
6493
|
+
"If required visual_delta is unmeasured, missing, or not_applicable, choose revise_capture with recommended_stage=verify and continue_with_stage=verify so the same run stays in evidence/comparison recovery; do not choose ready_to_ship or generic needs_richer_proof for that missing metric.",
|
|
6494
|
+
"Do not ship if the baseline is blank, shell-only, generic, or unrelated to the requested feature.",
|
|
6495
|
+
"Your summary must name the concrete change, the target that was tested, what changed between baseline and after evidence, and why the stop condition is satisfied."
|
|
6496
|
+
].join("\n")
|
|
6497
|
+
});
|
|
6498
|
+
return payloadOrBlocker(raw, context.checkpoint);
|
|
6499
|
+
}
|
|
6500
|
+
};
|
|
6501
|
+
}
|
|
6502
|
+
function git(args, workdir) {
|
|
6503
|
+
return (0, import_node_child_process3.execFileSync)("git", args, {
|
|
6504
|
+
cwd: workdir,
|
|
6505
|
+
encoding: "utf-8",
|
|
6506
|
+
timeout: 1e4
|
|
6507
|
+
});
|
|
6508
|
+
}
|
|
6509
|
+
async function runCodexExecAgentDoctor(config = {}, runner = createCodexExecJsonRunner(config)) {
|
|
6510
|
+
const workdir = (0, import_node_fs4.mkdtempSync)(import_node_path4.default.join(import_node_os.default.tmpdir(), "riddle-proof-codex-doctor-"));
|
|
6511
|
+
const targetPath = import_node_path4.default.join(workdir, "target.txt");
|
|
6512
|
+
(0, import_node_fs4.writeFileSync)(targetPath, "color=red\n");
|
|
6513
|
+
try {
|
|
6514
|
+
git(["init", "-b", "main"], workdir);
|
|
6515
|
+
git(["config", "user.email", "doctor@example.com"], workdir);
|
|
6516
|
+
git(["config", "user.name", "Riddle Proof Doctor"], workdir);
|
|
6517
|
+
git(["add", "target.txt"], workdir);
|
|
6518
|
+
git(["commit", "-m", "initial doctor fixture"], workdir);
|
|
6519
|
+
} catch (error) {
|
|
6520
|
+
return {
|
|
6521
|
+
ok: false,
|
|
6522
|
+
status: "blocked",
|
|
6523
|
+
blocker: {
|
|
6524
|
+
code: "doctor_git_setup_failed",
|
|
6525
|
+
message: "Could not create the temporary doctor git fixture.",
|
|
6526
|
+
details: { error: error instanceof Error ? error.message : String(error), workdir }
|
|
6527
|
+
}
|
|
6528
|
+
};
|
|
6529
|
+
}
|
|
6530
|
+
const raw = await callRunner(runner, {
|
|
6531
|
+
purpose: "codex exec doctor implementation",
|
|
6532
|
+
workdir,
|
|
6533
|
+
schema: IMPLEMENT_SCHEMA,
|
|
6534
|
+
prompt: [
|
|
6535
|
+
"You are running a Riddle Proof Codex exec doctor check.",
|
|
6536
|
+
"In this temporary git repository, edit target.txt so it says exactly: color=blue",
|
|
6537
|
+
"Do not commit. Leave a git diff.",
|
|
6538
|
+
"Return JSON matching the schema with changed_files containing target.txt.",
|
|
6539
|
+
"Use empty arrays for tests_run and blockers."
|
|
6540
|
+
].join("\n")
|
|
6541
|
+
});
|
|
6542
|
+
if (!raw.ok || !raw.json) {
|
|
6543
|
+
return {
|
|
6544
|
+
ok: false,
|
|
6545
|
+
status: "blocked",
|
|
6546
|
+
blocker: {
|
|
6547
|
+
...raw.blocker || {
|
|
6548
|
+
code: "doctor_codex_failed",
|
|
6549
|
+
message: "Codex doctor runner failed.",
|
|
6550
|
+
details: { stdout: raw.stdout || "", stderr: raw.stderr || "" }
|
|
6551
|
+
},
|
|
6552
|
+
details: {
|
|
6553
|
+
...raw.blocker?.details || {},
|
|
6554
|
+
workdir
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
};
|
|
6558
|
+
}
|
|
6559
|
+
const content = (0, import_node_fs4.readFileSync)(targetPath, "utf-8");
|
|
6560
|
+
const status = git(["status", "--porcelain"], workdir);
|
|
6561
|
+
const changedFiles = stringArray(raw.json.changed_files);
|
|
6562
|
+
const ok = content.trim() === "color=blue" && status.includes("target.txt");
|
|
6563
|
+
return {
|
|
6564
|
+
ok,
|
|
6565
|
+
status: ok ? "passed" : "blocked",
|
|
6566
|
+
workdir,
|
|
6567
|
+
changedFiles,
|
|
6568
|
+
implementationSummary: raw.json.summary || null,
|
|
6569
|
+
implementationNotes: raw.json.implementation_notes || null,
|
|
6570
|
+
gitStatus: status,
|
|
6571
|
+
targetContent: content,
|
|
6572
|
+
blocker: ok ? null : {
|
|
6573
|
+
code: "doctor_diff_missing_or_wrong",
|
|
6574
|
+
message: "Codex doctor completed, but target.txt was not changed to color=blue with a git diff.",
|
|
6575
|
+
details: { workdir, changedFiles, gitStatus: status, targetContent: content }
|
|
6576
|
+
}
|
|
6577
|
+
};
|
|
6578
|
+
}
|
|
6579
|
+
|
|
5361
6580
|
// src/diagnostics.ts
|
|
5362
6581
|
var RIDDLE_PROOF_CAPTURE_DIAGNOSTIC_VERSION = "riddle-proof.capture-diagnostic.v1";
|
|
5363
6582
|
var DEFAULT_DIAGNOSTIC_STRING_LIMIT = 2e3;
|
|
@@ -5975,6 +7194,7 @@ function parseJson(value) {
|
|
|
5975
7194
|
RIDDLE_PROOF_CHECKPOINT_RESPONSE_VERSION,
|
|
5976
7195
|
RIDDLE_PROOF_PLAYABILITY_ASSESSMENT_VERSION,
|
|
5977
7196
|
RIDDLE_PROOF_PLAYABILITY_VERSION,
|
|
7197
|
+
RIDDLE_PROOF_RUN_CARD_VERSION,
|
|
5978
7198
|
RIDDLE_PROOF_RUN_STATE_VERSION,
|
|
5979
7199
|
RIDDLE_PROOF_VISUAL_SESSION_FINGERPRINT_VERSION,
|
|
5980
7200
|
RIDDLE_PROOF_VISUAL_SESSION_VERSION,
|
|
@@ -5988,13 +7208,19 @@ function parseJson(value) {
|
|
|
5988
7208
|
buildAuthorCheckpointPacket,
|
|
5989
7209
|
buildCheckpointPacketForEngineResult,
|
|
5990
7210
|
buildProofAssessmentCheckpointPacket,
|
|
7211
|
+
buildStageCheckpointPacket,
|
|
5991
7212
|
buildVisualProofSession,
|
|
5992
7213
|
checkpointResponseIdentity,
|
|
5993
7214
|
checkpointSummaryFromState,
|
|
5994
7215
|
compactRecord,
|
|
5995
7216
|
compareVisualProofSessionFingerprint,
|
|
5996
7217
|
createCaptureDiagnostic,
|
|
7218
|
+
createCodexExecAgentAdapter,
|
|
7219
|
+
createCodexExecJsonRunner,
|
|
5997
7220
|
createDisabledRiddleProofAgentAdapter,
|
|
7221
|
+
createLocalAgentAdapter,
|
|
7222
|
+
createLocalAgentJsonRunner,
|
|
7223
|
+
createRiddleProofRunCard,
|
|
5998
7224
|
createRunResult,
|
|
5999
7225
|
createRunState,
|
|
6000
7226
|
createRunStatusSnapshot,
|
|
@@ -6014,6 +7240,8 @@ function parseJson(value) {
|
|
|
6014
7240
|
readRiddleProofRunStatus,
|
|
6015
7241
|
recordValue,
|
|
6016
7242
|
redactForProofDiagnostics,
|
|
7243
|
+
runCodexExecAgentDoctor,
|
|
7244
|
+
runLocalAgentDoctor,
|
|
6017
7245
|
runRiddleProof,
|
|
6018
7246
|
runRiddleProofEngineHarness,
|
|
6019
7247
|
setRunStatus,
|