@riddledc/riddle-proof 0.4.2 → 0.4.4

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.
@@ -5,7 +5,7 @@ import {
5
5
  createRunStatusSnapshot,
6
6
  normalizeRunParams,
7
7
  setRunStatus
8
- } from "./chunk-3XJJ4JOB.js";
8
+ } from "./chunk-SIQG3N6F.js";
9
9
  import {
10
10
  applyTerminalMetadata,
11
11
  compactRecord,
@@ -13,7 +13,7 @@ import {
13
13
  nonEmptyString,
14
14
  normalizeTerminalMetadata,
15
15
  recordValue
16
- } from "./chunk-5DC6YXN4.js";
16
+ } from "./chunk-TMMKRKY5.js";
17
17
 
18
18
  // src/engine-harness.ts
19
19
  import { execFileSync } from "child_process";
@@ -127,10 +127,12 @@ function stageFromCheckpoint(result) {
127
127
  if (checkpoint.startsWith("implement_")) return "implement";
128
128
  if (checkpoint.startsWith("verify_")) return "verify";
129
129
  if (checkpoint.startsWith("ship_")) return "ship";
130
+ if (checkpoint.startsWith("pr_sync_")) return "notify";
130
131
  if (checkpoint.includes("capture")) return "prove";
131
132
  return "setup";
132
133
  }
133
134
  function stageFromWorkflowParams(params) {
135
+ if (params.action === "sync") return "notify";
134
136
  const stage = nonEmptyString(params.advance_stage);
135
137
  if (stage) return stage;
136
138
  if (params.ship_after_verify) return "ship";
@@ -437,6 +439,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
437
439
  terminal: terminalResult(state, "shipped", result, result.summary || "Riddle Proof shipped.")
438
440
  };
439
441
  }
442
+ if (checkpoint.startsWith("pr_sync_")) {
443
+ const fullState = context.fullRiddleState || {};
444
+ const prState = recordValue(result.pr_state) || recordValue(result.prState) || recordValue(fullState.pr_state) || {};
445
+ const prStatus = nonEmptyString(prState.status);
446
+ const status = prStatus === "merged" ? "completed" : prStatus === "open" ? "shipped" : result.ok === false ? "blocked" : "completed";
447
+ return {
448
+ terminal: terminalResult(
449
+ state,
450
+ status,
451
+ result,
452
+ result.summary || "Riddle Proof PR lifecycle sync completed.",
453
+ { pr_sync: true }
454
+ )
455
+ };
456
+ }
440
457
  if (checkpoint === "verify_ship_ready") {
441
458
  const shipMode = effectiveShipMode(request, input.config);
442
459
  if (shipMode === "ship") {
@@ -3,10 +3,10 @@ import {
3
3
  appendStageHeartbeat,
4
4
  createRunState,
5
5
  setRunStatus
6
- } from "./chunk-3XJJ4JOB.js";
6
+ } from "./chunk-SIQG3N6F.js";
7
7
  import {
8
8
  createRunResult
9
- } from "./chunk-5DC6YXN4.js";
9
+ } from "./chunk-TMMKRKY5.js";
10
10
 
11
11
  // src/runner.ts
12
12
  function errorDetails(error) {
@@ -2,7 +2,7 @@ import {
2
2
  compactRecord,
3
3
  nonEmptyString,
4
4
  recordValue
5
- } from "./chunk-5DC6YXN4.js";
5
+ } from "./chunk-TMMKRKY5.js";
6
6
 
7
7
  // src/state.ts
8
8
  var RIDDLE_PROOF_RUN_STATE_VERSION = "riddle-proof.run-state.v1";
@@ -20,6 +20,36 @@ function elapsedMs(start, end) {
20
20
  if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return void 0;
21
21
  return Math.max(0, endMs - startMs);
22
22
  }
23
+ function normalizePrStatus(value) {
24
+ const status = nonEmptyString(value)?.toLowerCase();
25
+ if (status === "merged") return "merged";
26
+ if (status === "open") return "open";
27
+ if (status === "closed") return "closed";
28
+ if (status === "not_found" || status === "not-found") return "not_found";
29
+ if (status === "unavailable") return "unavailable";
30
+ return status || "unknown";
31
+ }
32
+ function normalizePrLifecycleState(input, checkedAt = timestamp()) {
33
+ const value = recordValue(input);
34
+ if (!value) return void 0;
35
+ const cleanup = recordValue(value.cleanup);
36
+ const mergeCommit = nonEmptyString(value.merge_commit) || nonEmptyString(value.mergeCommit) || nonEmptyString(recordValue(value.mergeCommit)?.oid);
37
+ return compactRecord({
38
+ status: normalizePrStatus(value.status || value.state),
39
+ pr_url: nonEmptyString(value.pr_url) || nonEmptyString(value.prUrl) || nonEmptyString(value.url),
40
+ pr_number: nonEmptyString(value.pr_number) || nonEmptyString(value.prNumber) || (typeof value.number === "number" ? String(value.number) : void 0),
41
+ repo: nonEmptyString(value.repo) || nonEmptyString(value.repository),
42
+ head_branch: nonEmptyString(value.head_branch) || nonEmptyString(value.headBranch) || nonEmptyString(value.headRefName),
43
+ base_branch: nonEmptyString(value.base_branch) || nonEmptyString(value.baseBranch) || nonEmptyString(value.baseRefName),
44
+ merge_commit: mergeCommit,
45
+ merged_at: nonEmptyString(value.merged_at) || nonEmptyString(value.mergedAt),
46
+ closed_at: nonEmptyString(value.closed_at) || nonEmptyString(value.closedAt),
47
+ checked_at: nonEmptyString(value.checked_at) || nonEmptyString(value.checkedAt) || checkedAt,
48
+ source: nonEmptyString(value.source),
49
+ next_action: nonEmptyString(value.next_action) || nonEmptyString(value.nextAction),
50
+ cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
51
+ });
52
+ }
23
53
  function normalizeIntegrationContext(input, fallbackSource) {
24
54
  const value = recordValue(input);
25
55
  if (!value) {
@@ -143,6 +173,16 @@ function createRunStatusSnapshot(state, at = timestamp()) {
143
173
  state_path: state.state_path ?? null,
144
174
  worktree_path: state.worktree_path ?? null,
145
175
  branch: state.branch ?? null,
176
+ pr_url: state.pr_url ?? null,
177
+ pr_branch: state.pr_branch ?? null,
178
+ pr_state: state.pr_state,
179
+ ci_status: state.ci_status,
180
+ ship_commit: state.ship_commit,
181
+ ship_remote_head: state.ship_remote_head,
182
+ merge_commit: state.merge_commit,
183
+ merged_at: state.merged_at,
184
+ proof_comment_url: state.proof_comment_url,
185
+ cleanup_report: state.cleanup_report,
146
186
  iterations: state.iterations,
147
187
  last_checkpoint: state.last_checkpoint ?? null,
148
188
  updated_at: state.updated_at,
@@ -158,14 +198,33 @@ function setRunStatus(state, status, at = timestamp()) {
158
198
  state.updated_at = at;
159
199
  return state;
160
200
  }
201
+ function applyPrLifecycleState(state, input, at = timestamp()) {
202
+ const prState = normalizePrLifecycleState(input, at);
203
+ if (!prState) return state;
204
+ state.pr_state = prState;
205
+ if (prState.pr_url) state.pr_url = prState.pr_url;
206
+ if (prState.head_branch) state.pr_branch = prState.head_branch;
207
+ if (prState.merge_commit) state.merge_commit = prState.merge_commit;
208
+ if (prState.merged_at) state.merged_at = prState.merged_at;
209
+ if (prState.cleanup) state.cleanup_report = prState.cleanup;
210
+ if (prState.status === "merged") {
211
+ state.finalized = true;
212
+ state.status = "completed";
213
+ state.ok = true;
214
+ }
215
+ state.updated_at = at;
216
+ return state;
217
+ }
161
218
 
162
219
  export {
163
220
  RIDDLE_PROOF_RUN_STATE_VERSION,
221
+ normalizePrLifecycleState,
164
222
  normalizeIntegrationContext,
165
223
  normalizeRunParams,
166
224
  createRunState,
167
225
  appendRunEvent,
168
226
  appendStageHeartbeat,
169
227
  createRunStatusSnapshot,
170
- setRunStatus
228
+ setRunStatus,
229
+ applyPrLifecycleState
171
230
  };
@@ -0,0 +1,219 @@
1
+ // src/result.ts
2
+ function isTerminalStatus(status) {
3
+ return status === "blocked" || status === "failed" || status === "ready_to_ship" || status === "shipped" || status === "completed";
4
+ }
5
+ function isSuccessfulStatus(status) {
6
+ return status !== "blocked" && status !== "failed";
7
+ }
8
+ function compactRecord(input) {
9
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0 && value !== null && value !== ""));
10
+ }
11
+ function nonEmptyString(value) {
12
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
13
+ }
14
+ function recordValue(value) {
15
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
16
+ }
17
+ function firstNonEmptyString(...values) {
18
+ for (const value of values) {
19
+ const normalized = nonEmptyString(value);
20
+ if (normalized) return normalized;
21
+ }
22
+ return void 0;
23
+ }
24
+ function firstBoolean(...values) {
25
+ for (const value of values) {
26
+ if (typeof value === "boolean") return value;
27
+ }
28
+ return void 0;
29
+ }
30
+ function normalizePrStatus(value) {
31
+ const status = nonEmptyString(value)?.toLowerCase();
32
+ if (status === "merged") return "merged";
33
+ if (status === "open") return "open";
34
+ if (status === "closed") return "closed";
35
+ if (status === "not_found" || status === "not-found") return "not_found";
36
+ if (status === "unavailable") return "unavailable";
37
+ return status || "unknown";
38
+ }
39
+ function normalizePrLifecycleStateInput(input) {
40
+ if (!input) return void 0;
41
+ const cleanup = recordValue(input.cleanup);
42
+ const mergeCommit = nonEmptyString(input.merge_commit) || nonEmptyString(input.mergeCommit) || nonEmptyString(recordValue(input.mergeCommit)?.oid);
43
+ return compactRecord({
44
+ status: normalizePrStatus(input.status || input.state),
45
+ pr_url: nonEmptyString(input.pr_url) || nonEmptyString(input.prUrl) || nonEmptyString(input.url),
46
+ pr_number: nonEmptyString(input.pr_number) || nonEmptyString(input.prNumber) || (typeof input.number === "number" ? String(input.number) : void 0),
47
+ repo: nonEmptyString(input.repo) || nonEmptyString(input.repository),
48
+ head_branch: nonEmptyString(input.head_branch) || nonEmptyString(input.headBranch) || nonEmptyString(input.headRefName),
49
+ base_branch: nonEmptyString(input.base_branch) || nonEmptyString(input.baseBranch) || nonEmptyString(input.baseRefName),
50
+ merge_commit: mergeCommit,
51
+ merged_at: nonEmptyString(input.merged_at) || nonEmptyString(input.mergedAt),
52
+ closed_at: nonEmptyString(input.closed_at) || nonEmptyString(input.closedAt),
53
+ checked_at: nonEmptyString(input.checked_at) || nonEmptyString(input.checkedAt),
54
+ source: nonEmptyString(input.source),
55
+ next_action: nonEmptyString(input.next_action) || nonEmptyString(input.nextAction),
56
+ cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
57
+ });
58
+ }
59
+ function normalizeTerminalMetadata(input) {
60
+ const riddleState = recordValue(input.riddleState) || {};
61
+ const result = recordValue(input.engineResult) || {};
62
+ const contract = recordValue(result.checkpointContract) || {};
63
+ const details = recordValue(input.checkpointDetails) || recordValue(contract.details) || {};
64
+ const shipReport = recordValue(riddleState.ship_report) || recordValue(result.ship_report) || recordValue(result.shipReport) || recordValue(details.ship_report) || recordValue(details.shipReport) || {};
65
+ const markedReady = firstBoolean(
66
+ riddleState.marked_ready,
67
+ result.marked_ready,
68
+ result.markedReady,
69
+ details.marked_ready,
70
+ details.markedReady,
71
+ shipReport.marked_ready
72
+ );
73
+ const leftDraft = firstBoolean(
74
+ riddleState.left_draft,
75
+ result.left_draft,
76
+ result.leftDraft,
77
+ details.left_draft,
78
+ details.leftDraft,
79
+ shipReport.left_draft
80
+ );
81
+ const finalized = firstBoolean(riddleState.finalized, result.finalized, details.finalized);
82
+ const prState = normalizePrLifecycleStateInput(
83
+ recordValue(riddleState.pr_state) || recordValue(riddleState.prState) || recordValue(result.pr_state) || recordValue(result.prState) || recordValue(details.pr_state) || recordValue(details.prState) || recordValue(shipReport.pr_state) || recordValue(shipReport.prState)
84
+ );
85
+ const cleanupReport = recordValue(riddleState.cleanup_report) || recordValue(riddleState.cleanupReport) || recordValue(result.cleanup_report) || recordValue(result.cleanupReport) || recordValue(details.cleanup_report) || recordValue(details.cleanupReport) || recordValue(prState?.cleanup);
86
+ return compactRecord({
87
+ pr_url: firstNonEmptyString(riddleState.pr_url, result.pr_url, result.prUrl, details.pr_url, details.prUrl, shipReport.pr_url),
88
+ pr_branch: firstNonEmptyString(
89
+ riddleState.pr_branch,
90
+ riddleState.target_branch,
91
+ result.pr_branch,
92
+ result.prBranch,
93
+ details.pr_branch,
94
+ details.prBranch,
95
+ shipReport.pr_branch,
96
+ shipReport.branch,
97
+ prState?.head_branch
98
+ ),
99
+ pr_state: prState,
100
+ marked_ready: markedReady,
101
+ left_draft: leftDraft,
102
+ ci_status: firstNonEmptyString(riddleState.ci_status, result.ci_status, result.ciStatus, details.ci_status, details.ciStatus, shipReport.ci_status),
103
+ ship_commit: firstNonEmptyString(riddleState.ship_commit, result.ship_commit, result.shipCommit, details.ship_commit, details.shipCommit, shipReport.shipped_commit, shipReport.ship_commit),
104
+ ship_remote_head: firstNonEmptyString(riddleState.ship_remote_head, result.ship_remote_head, result.shipRemoteHead, details.ship_remote_head, details.shipRemoteHead, shipReport.ship_remote_head),
105
+ merge_commit: firstNonEmptyString(riddleState.merge_commit, riddleState.mergeCommit, result.merge_commit, result.mergeCommit, details.merge_commit, details.mergeCommit, prState?.merge_commit),
106
+ merged_at: firstNonEmptyString(riddleState.merged_at, riddleState.mergedAt, result.merged_at, result.mergedAt, details.merged_at, details.mergedAt, prState?.merged_at),
107
+ proof_comment_url: firstNonEmptyString(riddleState.proof_comment_url, result.proof_comment_url, result.proofCommentUrl, details.proof_comment_url, details.proofCommentUrl, shipReport.proof_comment_url),
108
+ before_artifact_url: firstNonEmptyString(riddleState.before_artifact_url, riddleState.before_cdn, result.before_artifact_url, result.beforeArtifactUrl, details.before_artifact_url, details.beforeArtifactUrl, shipReport.before_artifact_url),
109
+ prod_artifact_url: firstNonEmptyString(riddleState.prod_artifact_url, riddleState.prod_cdn, result.prod_artifact_url, result.prodArtifactUrl, details.prod_artifact_url, details.prodArtifactUrl, shipReport.prod_artifact_url),
110
+ after_artifact_url: firstNonEmptyString(riddleState.after_artifact_url, riddleState.after_cdn, result.after_artifact_url, result.afterArtifactUrl, details.after_artifact_url, details.afterArtifactUrl, shipReport.after_artifact_url),
111
+ ship_report: Object.keys(shipReport).length ? shipReport : void 0,
112
+ cleanup_report: cleanupReport,
113
+ notification: recordValue(riddleState.notification) || recordValue(riddleState.discord_notification) || recordValue(result.notification) || recordValue(result.discord_notification),
114
+ proof_decision: nonEmptyString(riddleState.proof_decision) || nonEmptyString(result.proof_decision),
115
+ merge_recommendation: nonEmptyString(riddleState.merge_recommendation) || nonEmptyString(result.merge_recommendation),
116
+ finalized: typeof finalized === "boolean" ? finalized : void 0
117
+ });
118
+ }
119
+ function applyTerminalMetadata(state, metadata) {
120
+ if (metadata.pr_state) {
121
+ state.pr_state = metadata.pr_state;
122
+ if (metadata.pr_state.pr_url) state.pr_url = metadata.pr_state.pr_url;
123
+ if (metadata.pr_state.head_branch) state.pr_branch = metadata.pr_state.head_branch;
124
+ if (metadata.pr_state.merge_commit) state.merge_commit = metadata.pr_state.merge_commit;
125
+ if (metadata.pr_state.merged_at) state.merged_at = metadata.pr_state.merged_at;
126
+ if (metadata.pr_state.cleanup) state.cleanup_report = metadata.pr_state.cleanup;
127
+ if (metadata.pr_state.status === "merged") state.finalized = true;
128
+ }
129
+ const prUrl = nonEmptyString(metadata.pr_url);
130
+ if (prUrl) state.pr_url = prUrl;
131
+ const prBranch = nonEmptyString(metadata.pr_branch);
132
+ if (prBranch) state.pr_branch = prBranch;
133
+ if (typeof metadata.marked_ready === "boolean") state.marked_ready = metadata.marked_ready;
134
+ if (typeof metadata.left_draft === "boolean") state.left_draft = metadata.left_draft;
135
+ const ciStatus = nonEmptyString(metadata.ci_status);
136
+ if (ciStatus) state.ci_status = ciStatus;
137
+ const shipCommit = nonEmptyString(metadata.ship_commit);
138
+ if (shipCommit) state.ship_commit = shipCommit;
139
+ const shipRemoteHead = nonEmptyString(metadata.ship_remote_head);
140
+ if (shipRemoteHead) state.ship_remote_head = shipRemoteHead;
141
+ const mergeCommit = nonEmptyString(metadata.merge_commit);
142
+ if (mergeCommit) state.merge_commit = mergeCommit;
143
+ const mergedAt = nonEmptyString(metadata.merged_at);
144
+ if (mergedAt) state.merged_at = mergedAt;
145
+ const proofCommentUrl = nonEmptyString(metadata.proof_comment_url);
146
+ if (proofCommentUrl) state.proof_comment_url = proofCommentUrl;
147
+ const beforeArtifactUrl = nonEmptyString(metadata.before_artifact_url);
148
+ if (beforeArtifactUrl) state.before_artifact_url = beforeArtifactUrl;
149
+ const prodArtifactUrl = nonEmptyString(metadata.prod_artifact_url);
150
+ if (prodArtifactUrl) state.prod_artifact_url = prodArtifactUrl;
151
+ const afterArtifactUrl = nonEmptyString(metadata.after_artifact_url);
152
+ if (afterArtifactUrl) state.after_artifact_url = afterArtifactUrl;
153
+ const shipReport = recordValue(metadata.ship_report);
154
+ if (shipReport) state.ship_report = shipReport;
155
+ const cleanupReport = recordValue(metadata.cleanup_report);
156
+ if (cleanupReport) state.cleanup_report = cleanupReport;
157
+ const notification = recordValue(metadata.notification);
158
+ if (notification) state.notification = notification;
159
+ const proofDecision = nonEmptyString(metadata.proof_decision);
160
+ if (proofDecision) state.proof_decision = proofDecision;
161
+ const mergeRecommendation = nonEmptyString(metadata.merge_recommendation);
162
+ if (mergeRecommendation) state.merge_recommendation = mergeRecommendation;
163
+ if (typeof metadata.finalized === "boolean") state.finalized = metadata.finalized;
164
+ return state;
165
+ }
166
+ function createRunResult(input) {
167
+ const status = input.status || input.state.status;
168
+ const ok = isSuccessfulStatus(status);
169
+ const state = input.metadata ? applyTerminalMetadata(input.state, input.metadata) : input.state;
170
+ state.status = status;
171
+ state.ok = ok;
172
+ return compactRecord({
173
+ ok,
174
+ status,
175
+ run_id: state.run_id,
176
+ state_path: input.state_path ?? state.state_path ?? null,
177
+ worktree_path: state.worktree_path ?? null,
178
+ branch: state.branch ?? null,
179
+ current_stage: state.current_stage ?? null,
180
+ iterations: state.iterations,
181
+ last_checkpoint: state.last_checkpoint ?? null,
182
+ last_summary: input.last_summary ?? null,
183
+ event_count: state.events.length,
184
+ pr_url: state.pr_url,
185
+ pr_branch: state.pr_branch,
186
+ pr_state: state.pr_state,
187
+ marked_ready: state.marked_ready,
188
+ left_draft: state.left_draft,
189
+ ci_status: state.ci_status,
190
+ ship_commit: state.ship_commit,
191
+ ship_remote_head: state.ship_remote_head,
192
+ merge_commit: state.merge_commit,
193
+ merged_at: state.merged_at,
194
+ proof_comment_url: state.proof_comment_url,
195
+ before_artifact_url: state.before_artifact_url,
196
+ prod_artifact_url: state.prod_artifact_url,
197
+ after_artifact_url: state.after_artifact_url,
198
+ ship_report: state.ship_report,
199
+ cleanup_report: state.cleanup_report,
200
+ notification: state.notification,
201
+ proof_decision: state.proof_decision,
202
+ merge_recommendation: state.merge_recommendation,
203
+ finalized: state.finalized,
204
+ blocker: state.blocker,
205
+ evidence_bundle: input.evidence_bundle,
206
+ raw: input.raw
207
+ });
208
+ }
209
+
210
+ export {
211
+ isTerminalStatus,
212
+ isSuccessfulStatus,
213
+ compactRecord,
214
+ nonEmptyString,
215
+ recordValue,
216
+ normalizeTerminalMetadata,
217
+ applyTerminalMetadata,
218
+ createRunResult
219
+ };
@@ -53,16 +53,102 @@ function nonEmptyString(value) {
53
53
  function recordValue(value) {
54
54
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
55
55
  }
56
+ function firstNonEmptyString(...values) {
57
+ for (const value of values) {
58
+ const normalized = nonEmptyString(value);
59
+ if (normalized) return normalized;
60
+ }
61
+ return void 0;
62
+ }
63
+ function firstBoolean(...values) {
64
+ for (const value of values) {
65
+ if (typeof value === "boolean") return value;
66
+ }
67
+ return void 0;
68
+ }
69
+ function normalizePrStatus(value) {
70
+ const status = nonEmptyString(value)?.toLowerCase();
71
+ if (status === "merged") return "merged";
72
+ if (status === "open") return "open";
73
+ if (status === "closed") return "closed";
74
+ if (status === "not_found" || status === "not-found") return "not_found";
75
+ if (status === "unavailable") return "unavailable";
76
+ return status || "unknown";
77
+ }
78
+ function normalizePrLifecycleStateInput(input) {
79
+ if (!input) return void 0;
80
+ const cleanup = recordValue(input.cleanup);
81
+ const mergeCommit = nonEmptyString(input.merge_commit) || nonEmptyString(input.mergeCommit) || nonEmptyString(recordValue(input.mergeCommit)?.oid);
82
+ return compactRecord({
83
+ status: normalizePrStatus(input.status || input.state),
84
+ pr_url: nonEmptyString(input.pr_url) || nonEmptyString(input.prUrl) || nonEmptyString(input.url),
85
+ pr_number: nonEmptyString(input.pr_number) || nonEmptyString(input.prNumber) || (typeof input.number === "number" ? String(input.number) : void 0),
86
+ repo: nonEmptyString(input.repo) || nonEmptyString(input.repository),
87
+ head_branch: nonEmptyString(input.head_branch) || nonEmptyString(input.headBranch) || nonEmptyString(input.headRefName),
88
+ base_branch: nonEmptyString(input.base_branch) || nonEmptyString(input.baseBranch) || nonEmptyString(input.baseRefName),
89
+ merge_commit: mergeCommit,
90
+ merged_at: nonEmptyString(input.merged_at) || nonEmptyString(input.mergedAt),
91
+ closed_at: nonEmptyString(input.closed_at) || nonEmptyString(input.closedAt),
92
+ checked_at: nonEmptyString(input.checked_at) || nonEmptyString(input.checkedAt),
93
+ source: nonEmptyString(input.source),
94
+ next_action: nonEmptyString(input.next_action) || nonEmptyString(input.nextAction),
95
+ cleanup: cleanup && Object.keys(cleanup).length ? cleanup : void 0
96
+ });
97
+ }
56
98
  function normalizeTerminalMetadata(input) {
57
99
  const riddleState = recordValue(input.riddleState) || {};
58
100
  const result = recordValue(input.engineResult) || {};
59
101
  const contract = recordValue(result.checkpointContract) || {};
60
102
  const details = recordValue(input.checkpointDetails) || recordValue(contract.details) || {};
61
- const markedReady = riddleState.marked_ready ?? result.marked_ready ?? result.markedReady ?? details.marked_ready ?? details.markedReady;
62
- const finalized = riddleState.finalized ?? result.finalized ?? details.finalized;
103
+ const shipReport = recordValue(riddleState.ship_report) || recordValue(result.ship_report) || recordValue(result.shipReport) || recordValue(details.ship_report) || recordValue(details.shipReport) || {};
104
+ const markedReady = firstBoolean(
105
+ riddleState.marked_ready,
106
+ result.marked_ready,
107
+ result.markedReady,
108
+ details.marked_ready,
109
+ details.markedReady,
110
+ shipReport.marked_ready
111
+ );
112
+ const leftDraft = firstBoolean(
113
+ riddleState.left_draft,
114
+ result.left_draft,
115
+ result.leftDraft,
116
+ details.left_draft,
117
+ details.leftDraft,
118
+ shipReport.left_draft
119
+ );
120
+ const finalized = firstBoolean(riddleState.finalized, result.finalized, details.finalized);
121
+ const prState = normalizePrLifecycleStateInput(
122
+ recordValue(riddleState.pr_state) || recordValue(riddleState.prState) || recordValue(result.pr_state) || recordValue(result.prState) || recordValue(details.pr_state) || recordValue(details.prState) || recordValue(shipReport.pr_state) || recordValue(shipReport.prState)
123
+ );
124
+ const cleanupReport = recordValue(riddleState.cleanup_report) || recordValue(riddleState.cleanupReport) || recordValue(result.cleanup_report) || recordValue(result.cleanupReport) || recordValue(details.cleanup_report) || recordValue(details.cleanupReport) || recordValue(prState?.cleanup);
63
125
  return compactRecord({
64
- pr_url: nonEmptyString(riddleState.pr_url) || nonEmptyString(result.pr_url) || nonEmptyString(result.prUrl) || nonEmptyString(details.pr_url) || nonEmptyString(details.prUrl),
65
- marked_ready: typeof markedReady === "boolean" ? markedReady : void 0,
126
+ pr_url: firstNonEmptyString(riddleState.pr_url, result.pr_url, result.prUrl, details.pr_url, details.prUrl, shipReport.pr_url),
127
+ pr_branch: firstNonEmptyString(
128
+ riddleState.pr_branch,
129
+ riddleState.target_branch,
130
+ result.pr_branch,
131
+ result.prBranch,
132
+ details.pr_branch,
133
+ details.prBranch,
134
+ shipReport.pr_branch,
135
+ shipReport.branch,
136
+ prState?.head_branch
137
+ ),
138
+ pr_state: prState,
139
+ marked_ready: markedReady,
140
+ left_draft: leftDraft,
141
+ ci_status: firstNonEmptyString(riddleState.ci_status, result.ci_status, result.ciStatus, details.ci_status, details.ciStatus, shipReport.ci_status),
142
+ ship_commit: firstNonEmptyString(riddleState.ship_commit, result.ship_commit, result.shipCommit, details.ship_commit, details.shipCommit, shipReport.shipped_commit, shipReport.ship_commit),
143
+ ship_remote_head: firstNonEmptyString(riddleState.ship_remote_head, result.ship_remote_head, result.shipRemoteHead, details.ship_remote_head, details.shipRemoteHead, shipReport.ship_remote_head),
144
+ merge_commit: firstNonEmptyString(riddleState.merge_commit, riddleState.mergeCommit, result.merge_commit, result.mergeCommit, details.merge_commit, details.mergeCommit, prState?.merge_commit),
145
+ merged_at: firstNonEmptyString(riddleState.merged_at, riddleState.mergedAt, result.merged_at, result.mergedAt, details.merged_at, details.mergedAt, prState?.merged_at),
146
+ proof_comment_url: firstNonEmptyString(riddleState.proof_comment_url, result.proof_comment_url, result.proofCommentUrl, details.proof_comment_url, details.proofCommentUrl, shipReport.proof_comment_url),
147
+ before_artifact_url: firstNonEmptyString(riddleState.before_artifact_url, riddleState.before_cdn, result.before_artifact_url, result.beforeArtifactUrl, details.before_artifact_url, details.beforeArtifactUrl, shipReport.before_artifact_url),
148
+ prod_artifact_url: firstNonEmptyString(riddleState.prod_artifact_url, riddleState.prod_cdn, result.prod_artifact_url, result.prodArtifactUrl, details.prod_artifact_url, details.prodArtifactUrl, shipReport.prod_artifact_url),
149
+ after_artifact_url: firstNonEmptyString(riddleState.after_artifact_url, riddleState.after_cdn, result.after_artifact_url, result.afterArtifactUrl, details.after_artifact_url, details.afterArtifactUrl, shipReport.after_artifact_url),
150
+ ship_report: Object.keys(shipReport).length ? shipReport : void 0,
151
+ cleanup_report: cleanupReport,
66
152
  notification: recordValue(riddleState.notification) || recordValue(riddleState.discord_notification) || recordValue(result.notification) || recordValue(result.discord_notification),
67
153
  proof_decision: nonEmptyString(riddleState.proof_decision) || nonEmptyString(result.proof_decision),
68
154
  merge_recommendation: nonEmptyString(riddleState.merge_recommendation) || nonEmptyString(result.merge_recommendation),
@@ -70,9 +156,43 @@ function normalizeTerminalMetadata(input) {
70
156
  });
71
157
  }
72
158
  function applyTerminalMetadata(state, metadata) {
159
+ if (metadata.pr_state) {
160
+ state.pr_state = metadata.pr_state;
161
+ if (metadata.pr_state.pr_url) state.pr_url = metadata.pr_state.pr_url;
162
+ if (metadata.pr_state.head_branch) state.pr_branch = metadata.pr_state.head_branch;
163
+ if (metadata.pr_state.merge_commit) state.merge_commit = metadata.pr_state.merge_commit;
164
+ if (metadata.pr_state.merged_at) state.merged_at = metadata.pr_state.merged_at;
165
+ if (metadata.pr_state.cleanup) state.cleanup_report = metadata.pr_state.cleanup;
166
+ if (metadata.pr_state.status === "merged") state.finalized = true;
167
+ }
73
168
  const prUrl = nonEmptyString(metadata.pr_url);
74
169
  if (prUrl) state.pr_url = prUrl;
170
+ const prBranch = nonEmptyString(metadata.pr_branch);
171
+ if (prBranch) state.pr_branch = prBranch;
75
172
  if (typeof metadata.marked_ready === "boolean") state.marked_ready = metadata.marked_ready;
173
+ if (typeof metadata.left_draft === "boolean") state.left_draft = metadata.left_draft;
174
+ const ciStatus = nonEmptyString(metadata.ci_status);
175
+ if (ciStatus) state.ci_status = ciStatus;
176
+ const shipCommit = nonEmptyString(metadata.ship_commit);
177
+ if (shipCommit) state.ship_commit = shipCommit;
178
+ const shipRemoteHead = nonEmptyString(metadata.ship_remote_head);
179
+ if (shipRemoteHead) state.ship_remote_head = shipRemoteHead;
180
+ const mergeCommit = nonEmptyString(metadata.merge_commit);
181
+ if (mergeCommit) state.merge_commit = mergeCommit;
182
+ const mergedAt = nonEmptyString(metadata.merged_at);
183
+ if (mergedAt) state.merged_at = mergedAt;
184
+ const proofCommentUrl = nonEmptyString(metadata.proof_comment_url);
185
+ if (proofCommentUrl) state.proof_comment_url = proofCommentUrl;
186
+ const beforeArtifactUrl = nonEmptyString(metadata.before_artifact_url);
187
+ if (beforeArtifactUrl) state.before_artifact_url = beforeArtifactUrl;
188
+ const prodArtifactUrl = nonEmptyString(metadata.prod_artifact_url);
189
+ if (prodArtifactUrl) state.prod_artifact_url = prodArtifactUrl;
190
+ const afterArtifactUrl = nonEmptyString(metadata.after_artifact_url);
191
+ if (afterArtifactUrl) state.after_artifact_url = afterArtifactUrl;
192
+ const shipReport = recordValue(metadata.ship_report);
193
+ if (shipReport) state.ship_report = shipReport;
194
+ const cleanupReport = recordValue(metadata.cleanup_report);
195
+ if (cleanupReport) state.cleanup_report = cleanupReport;
76
196
  const notification = recordValue(metadata.notification);
77
197
  if (notification) state.notification = notification;
78
198
  const proofDecision = nonEmptyString(metadata.proof_decision);
@@ -101,7 +221,21 @@ function createRunResult(input) {
101
221
  last_summary: input.last_summary ?? null,
102
222
  event_count: state.events.length,
103
223
  pr_url: state.pr_url,
224
+ pr_branch: state.pr_branch,
225
+ pr_state: state.pr_state,
104
226
  marked_ready: state.marked_ready,
227
+ left_draft: state.left_draft,
228
+ ci_status: state.ci_status,
229
+ ship_commit: state.ship_commit,
230
+ ship_remote_head: state.ship_remote_head,
231
+ merge_commit: state.merge_commit,
232
+ merged_at: state.merged_at,
233
+ proof_comment_url: state.proof_comment_url,
234
+ before_artifact_url: state.before_artifact_url,
235
+ prod_artifact_url: state.prod_artifact_url,
236
+ after_artifact_url: state.after_artifact_url,
237
+ ship_report: state.ship_report,
238
+ cleanup_report: state.cleanup_report,
105
239
  notification: state.notification,
106
240
  proof_decision: state.proof_decision,
107
241
  merge_recommendation: state.merge_recommendation,
@@ -251,6 +385,16 @@ function createRunStatusSnapshot(state, at = timestamp()) {
251
385
  state_path: state.state_path ?? null,
252
386
  worktree_path: state.worktree_path ?? null,
253
387
  branch: state.branch ?? null,
388
+ pr_url: state.pr_url ?? null,
389
+ pr_branch: state.pr_branch ?? null,
390
+ pr_state: state.pr_state,
391
+ ci_status: state.ci_status,
392
+ ship_commit: state.ship_commit,
393
+ ship_remote_head: state.ship_remote_head,
394
+ merge_commit: state.merge_commit,
395
+ merged_at: state.merged_at,
396
+ proof_comment_url: state.proof_comment_url,
397
+ cleanup_report: state.cleanup_report,
254
398
  iterations: state.iterations,
255
399
  last_checkpoint: state.last_checkpoint ?? null,
256
400
  updated_at: state.updated_at,
@@ -368,10 +512,12 @@ function stageFromCheckpoint(result) {
368
512
  if (checkpoint.startsWith("implement_")) return "implement";
369
513
  if (checkpoint.startsWith("verify_")) return "verify";
370
514
  if (checkpoint.startsWith("ship_")) return "ship";
515
+ if (checkpoint.startsWith("pr_sync_")) return "notify";
371
516
  if (checkpoint.includes("capture")) return "prove";
372
517
  return "setup";
373
518
  }
374
519
  function stageFromWorkflowParams(params) {
520
+ if (params.action === "sync") return "notify";
375
521
  const stage = nonEmptyString(params.advance_stage);
376
522
  if (stage) return stage;
377
523
  if (params.ship_after_verify) return "ship";
@@ -678,6 +824,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
678
824
  terminal: terminalResult(state, "shipped", result, result.summary || "Riddle Proof shipped.")
679
825
  };
680
826
  }
827
+ if (checkpoint.startsWith("pr_sync_")) {
828
+ const fullState = context.fullRiddleState || {};
829
+ const prState = recordValue(result.pr_state) || recordValue(result.prState) || recordValue(fullState.pr_state) || {};
830
+ const prStatus = nonEmptyString(prState.status);
831
+ const status = prStatus === "merged" ? "completed" : prStatus === "open" ? "shipped" : result.ok === false ? "blocked" : "completed";
832
+ return {
833
+ terminal: terminalResult(
834
+ state,
835
+ status,
836
+ result,
837
+ result.summary || "Riddle Proof PR lifecycle sync completed.",
838
+ { pr_sync: true }
839
+ )
840
+ };
841
+ }
681
842
  if (checkpoint === "verify_ship_ready") {
682
843
  const shipMode = effectiveShipMode(request, input.config);
683
844
  if (shipMode === "ship") {
@@ -2,9 +2,9 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-7DED7LM3.js";
6
- import "./chunk-3XJJ4JOB.js";
7
- import "./chunk-5DC6YXN4.js";
5
+ } from "./chunk-75XY5SVT.js";
6
+ import "./chunk-SIQG3N6F.js";
7
+ import "./chunk-TMMKRKY5.js";
8
8
  export {
9
9
  createDisabledRiddleProofAgentAdapter,
10
10
  readRiddleProofRunStatus,