@riddledc/riddle-proof 0.4.3 → 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-AHQIV5QN.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-VFO5WY5X.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-AHQIV5QN.js";
6
+ } from "./chunk-SIQG3N6F.js";
7
7
  import {
8
8
  createRunResult
9
- } from "./chunk-VFO5WY5X.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-VFO5WY5X.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
  };
@@ -27,6 +27,35 @@ function firstBoolean(...values) {
27
27
  }
28
28
  return void 0;
29
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
+ }
30
59
  function normalizeTerminalMetadata(input) {
31
60
  const riddleState = recordValue(input.riddleState) || {};
32
61
  const result = recordValue(input.engineResult) || {};
@@ -50,6 +79,10 @@ function normalizeTerminalMetadata(input) {
50
79
  shipReport.left_draft
51
80
  );
52
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);
53
86
  return compactRecord({
54
87
  pr_url: firstNonEmptyString(riddleState.pr_url, result.pr_url, result.prUrl, details.pr_url, details.prUrl, shipReport.pr_url),
55
88
  pr_branch: firstNonEmptyString(
@@ -60,18 +93,23 @@ function normalizeTerminalMetadata(input) {
60
93
  details.pr_branch,
61
94
  details.prBranch,
62
95
  shipReport.pr_branch,
63
- shipReport.branch
96
+ shipReport.branch,
97
+ prState?.head_branch
64
98
  ),
99
+ pr_state: prState,
65
100
  marked_ready: markedReady,
66
101
  left_draft: leftDraft,
67
102
  ci_status: firstNonEmptyString(riddleState.ci_status, result.ci_status, result.ciStatus, details.ci_status, details.ciStatus, shipReport.ci_status),
68
103
  ship_commit: firstNonEmptyString(riddleState.ship_commit, result.ship_commit, result.shipCommit, details.ship_commit, details.shipCommit, shipReport.shipped_commit, shipReport.ship_commit),
69
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),
70
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),
71
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),
72
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),
73
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),
74
111
  ship_report: Object.keys(shipReport).length ? shipReport : void 0,
112
+ cleanup_report: cleanupReport,
75
113
  notification: recordValue(riddleState.notification) || recordValue(riddleState.discord_notification) || recordValue(result.notification) || recordValue(result.discord_notification),
76
114
  proof_decision: nonEmptyString(riddleState.proof_decision) || nonEmptyString(result.proof_decision),
77
115
  merge_recommendation: nonEmptyString(riddleState.merge_recommendation) || nonEmptyString(result.merge_recommendation),
@@ -79,6 +117,15 @@ function normalizeTerminalMetadata(input) {
79
117
  });
80
118
  }
81
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
+ }
82
129
  const prUrl = nonEmptyString(metadata.pr_url);
83
130
  if (prUrl) state.pr_url = prUrl;
84
131
  const prBranch = nonEmptyString(metadata.pr_branch);
@@ -91,6 +138,10 @@ function applyTerminalMetadata(state, metadata) {
91
138
  if (shipCommit) state.ship_commit = shipCommit;
92
139
  const shipRemoteHead = nonEmptyString(metadata.ship_remote_head);
93
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;
94
145
  const proofCommentUrl = nonEmptyString(metadata.proof_comment_url);
95
146
  if (proofCommentUrl) state.proof_comment_url = proofCommentUrl;
96
147
  const beforeArtifactUrl = nonEmptyString(metadata.before_artifact_url);
@@ -101,6 +152,8 @@ function applyTerminalMetadata(state, metadata) {
101
152
  if (afterArtifactUrl) state.after_artifact_url = afterArtifactUrl;
102
153
  const shipReport = recordValue(metadata.ship_report);
103
154
  if (shipReport) state.ship_report = shipReport;
155
+ const cleanupReport = recordValue(metadata.cleanup_report);
156
+ if (cleanupReport) state.cleanup_report = cleanupReport;
104
157
  const notification = recordValue(metadata.notification);
105
158
  if (notification) state.notification = notification;
106
159
  const proofDecision = nonEmptyString(metadata.proof_decision);
@@ -130,16 +183,20 @@ function createRunResult(input) {
130
183
  event_count: state.events.length,
131
184
  pr_url: state.pr_url,
132
185
  pr_branch: state.pr_branch,
186
+ pr_state: state.pr_state,
133
187
  marked_ready: state.marked_ready,
134
188
  left_draft: state.left_draft,
135
189
  ci_status: state.ci_status,
136
190
  ship_commit: state.ship_commit,
137
191
  ship_remote_head: state.ship_remote_head,
192
+ merge_commit: state.merge_commit,
193
+ merged_at: state.merged_at,
138
194
  proof_comment_url: state.proof_comment_url,
139
195
  before_artifact_url: state.before_artifact_url,
140
196
  prod_artifact_url: state.prod_artifact_url,
141
197
  after_artifact_url: state.after_artifact_url,
142
198
  ship_report: state.ship_report,
199
+ cleanup_report: state.cleanup_report,
143
200
  notification: state.notification,
144
201
  proof_decision: state.proof_decision,
145
202
  merge_recommendation: state.merge_recommendation,
@@ -66,6 +66,35 @@ function firstBoolean(...values) {
66
66
  }
67
67
  return void 0;
68
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
+ }
69
98
  function normalizeTerminalMetadata(input) {
70
99
  const riddleState = recordValue(input.riddleState) || {};
71
100
  const result = recordValue(input.engineResult) || {};
@@ -89,6 +118,10 @@ function normalizeTerminalMetadata(input) {
89
118
  shipReport.left_draft
90
119
  );
91
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);
92
125
  return compactRecord({
93
126
  pr_url: firstNonEmptyString(riddleState.pr_url, result.pr_url, result.prUrl, details.pr_url, details.prUrl, shipReport.pr_url),
94
127
  pr_branch: firstNonEmptyString(
@@ -99,18 +132,23 @@ function normalizeTerminalMetadata(input) {
99
132
  details.pr_branch,
100
133
  details.prBranch,
101
134
  shipReport.pr_branch,
102
- shipReport.branch
135
+ shipReport.branch,
136
+ prState?.head_branch
103
137
  ),
138
+ pr_state: prState,
104
139
  marked_ready: markedReady,
105
140
  left_draft: leftDraft,
106
141
  ci_status: firstNonEmptyString(riddleState.ci_status, result.ci_status, result.ciStatus, details.ci_status, details.ciStatus, shipReport.ci_status),
107
142
  ship_commit: firstNonEmptyString(riddleState.ship_commit, result.ship_commit, result.shipCommit, details.ship_commit, details.shipCommit, shipReport.shipped_commit, shipReport.ship_commit),
108
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),
109
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),
110
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),
111
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),
112
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),
113
150
  ship_report: Object.keys(shipReport).length ? shipReport : void 0,
151
+ cleanup_report: cleanupReport,
114
152
  notification: recordValue(riddleState.notification) || recordValue(riddleState.discord_notification) || recordValue(result.notification) || recordValue(result.discord_notification),
115
153
  proof_decision: nonEmptyString(riddleState.proof_decision) || nonEmptyString(result.proof_decision),
116
154
  merge_recommendation: nonEmptyString(riddleState.merge_recommendation) || nonEmptyString(result.merge_recommendation),
@@ -118,6 +156,15 @@ function normalizeTerminalMetadata(input) {
118
156
  });
119
157
  }
120
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
+ }
121
168
  const prUrl = nonEmptyString(metadata.pr_url);
122
169
  if (prUrl) state.pr_url = prUrl;
123
170
  const prBranch = nonEmptyString(metadata.pr_branch);
@@ -130,6 +177,10 @@ function applyTerminalMetadata(state, metadata) {
130
177
  if (shipCommit) state.ship_commit = shipCommit;
131
178
  const shipRemoteHead = nonEmptyString(metadata.ship_remote_head);
132
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;
133
184
  const proofCommentUrl = nonEmptyString(metadata.proof_comment_url);
134
185
  if (proofCommentUrl) state.proof_comment_url = proofCommentUrl;
135
186
  const beforeArtifactUrl = nonEmptyString(metadata.before_artifact_url);
@@ -140,6 +191,8 @@ function applyTerminalMetadata(state, metadata) {
140
191
  if (afterArtifactUrl) state.after_artifact_url = afterArtifactUrl;
141
192
  const shipReport = recordValue(metadata.ship_report);
142
193
  if (shipReport) state.ship_report = shipReport;
194
+ const cleanupReport = recordValue(metadata.cleanup_report);
195
+ if (cleanupReport) state.cleanup_report = cleanupReport;
143
196
  const notification = recordValue(metadata.notification);
144
197
  if (notification) state.notification = notification;
145
198
  const proofDecision = nonEmptyString(metadata.proof_decision);
@@ -169,16 +222,20 @@ function createRunResult(input) {
169
222
  event_count: state.events.length,
170
223
  pr_url: state.pr_url,
171
224
  pr_branch: state.pr_branch,
225
+ pr_state: state.pr_state,
172
226
  marked_ready: state.marked_ready,
173
227
  left_draft: state.left_draft,
174
228
  ci_status: state.ci_status,
175
229
  ship_commit: state.ship_commit,
176
230
  ship_remote_head: state.ship_remote_head,
231
+ merge_commit: state.merge_commit,
232
+ merged_at: state.merged_at,
177
233
  proof_comment_url: state.proof_comment_url,
178
234
  before_artifact_url: state.before_artifact_url,
179
235
  prod_artifact_url: state.prod_artifact_url,
180
236
  after_artifact_url: state.after_artifact_url,
181
237
  ship_report: state.ship_report,
238
+ cleanup_report: state.cleanup_report,
182
239
  notification: state.notification,
183
240
  proof_decision: state.proof_decision,
184
241
  merge_recommendation: state.merge_recommendation,
@@ -328,6 +385,16 @@ function createRunStatusSnapshot(state, at = timestamp()) {
328
385
  state_path: state.state_path ?? null,
329
386
  worktree_path: state.worktree_path ?? null,
330
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,
331
398
  iterations: state.iterations,
332
399
  last_checkpoint: state.last_checkpoint ?? null,
333
400
  updated_at: state.updated_at,
@@ -445,10 +512,12 @@ function stageFromCheckpoint(result) {
445
512
  if (checkpoint.startsWith("implement_")) return "implement";
446
513
  if (checkpoint.startsWith("verify_")) return "verify";
447
514
  if (checkpoint.startsWith("ship_")) return "ship";
515
+ if (checkpoint.startsWith("pr_sync_")) return "notify";
448
516
  if (checkpoint.includes("capture")) return "prove";
449
517
  return "setup";
450
518
  }
451
519
  function stageFromWorkflowParams(params) {
520
+ if (params.action === "sync") return "notify";
452
521
  const stage = nonEmptyString(params.advance_stage);
453
522
  if (stage) return stage;
454
523
  if (params.ship_after_verify) return "ship";
@@ -755,6 +824,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
755
824
  terminal: terminalResult(state, "shipped", result, result.summary || "Riddle Proof shipped.")
756
825
  };
757
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
+ }
758
842
  if (checkpoint === "verify_ship_ready") {
759
843
  const shipMode = effectiveShipMode(request, input.config);
760
844
  if (shipMode === "ship") {
@@ -2,9 +2,9 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-YWJENUSI.js";
6
- import "./chunk-AHQIV5QN.js";
7
- import "./chunk-VFO5WY5X.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,