@riddledc/riddle-proof 0.5.47 → 0.5.49

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.
@@ -1747,9 +1747,27 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1747
1747
  }
1748
1748
  return "inspect the ship gate details, repair the missing invariant, then resume the run";
1749
1749
  };
1750
+ const shipGateRecoveryStage = (shipGate) => {
1751
+ const reasons = shipGate.reasons || [];
1752
+ if (reasons.some((reason) => reason.includes("before_cdn") || reason.includes("prod_cdn") || reason.includes("prod_url"))) {
1753
+ return "recon";
1754
+ }
1755
+ if (reasons.some((reason) => reason.includes("implementation"))) {
1756
+ return "implement";
1757
+ }
1758
+ if (reasons.some((reason) => reason.includes("after_cdn") || reason.includes("verify_status") || reason.includes("visual_delta"))) {
1759
+ return "verify";
1760
+ }
1761
+ if (reasons.some((reason) => reason.includes("proof_assessment"))) {
1762
+ return "verify";
1763
+ }
1764
+ return "verify";
1765
+ };
1750
1766
  const shipGateBlocked = (state, executed, details = {}) => {
1751
1767
  const shipGate = validateShipGate(state);
1752
1768
  const nextAction = primaryShipGateNextAction(shipGate);
1769
+ const recoveryStage = shipGateRecoveryStage(shipGate);
1770
+ const advanceOptions = Array.from(/* @__PURE__ */ new Set([recoveryStage, "verify", "author", "implement", "recon", "ship"]));
1753
1771
  return checkpoint(
1754
1772
  "verify",
1755
1773
  "ship_gate_blocked",
@@ -1757,12 +1775,13 @@ async function executeWorkflow(params, pluginConfig, resolvedConfig) {
1757
1775
  {
1758
1776
  ok: false,
1759
1777
  nextActions: ["inspect_ship_gate", "advance_run_to_verify", "supply_proof_assessment_json", "return_to_recon_if_baseline_is_missing"],
1760
- advanceOptions: ["verify", "author", "implement", "recon"],
1761
- recommendedAdvanceStage: "verify",
1762
- continueWithStage: "verify",
1778
+ advanceOptions,
1779
+ recommendedAdvanceStage: recoveryStage,
1780
+ continueWithStage: recoveryStage,
1763
1781
  blocking: true,
1764
- details: { ...details, shipGate, next_action: nextAction, executed },
1782
+ details: { ...details, shipGate, next_action: nextAction, recovery_stage: recoveryStage, executed },
1765
1783
  nextAction,
1784
+ recoveryStage,
1766
1785
  shipGate,
1767
1786
  verifyStatus: state?.verify_status || null,
1768
1787
  mergeRecommendation: state?.merge_recommendation || null,
@@ -3635,6 +3654,68 @@ function compactText2(value, limit = 600) {
3635
3654
  if (!text) return void 0;
3636
3655
  return text.length <= limit ? text : `${text.slice(0, limit - 20).trimEnd()}...`;
3637
3656
  }
3657
+ function numericValue(value) {
3658
+ const number = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
3659
+ return Number.isFinite(number) ? number : void 0;
3660
+ }
3661
+ function eventDetails(event) {
3662
+ return recordValue(recordValue(event)?.details) || {};
3663
+ }
3664
+ function collectRunnerMetrics(details) {
3665
+ const metrics = [];
3666
+ const adapterDetails = recordValue(details.adapter_details);
3667
+ const direct = recordValue(adapterDetails?.runner_metrics);
3668
+ if (direct) metrics.push(direct);
3669
+ const attempts = Array.isArray(adapterDetails?.attempt_summaries) ? adapterDetails.attempt_summaries : [];
3670
+ for (const attempt of attempts) {
3671
+ const attemptMetrics = recordValue(recordValue(attempt)?.runner_metrics);
3672
+ if (attemptMetrics) metrics.push(attemptMetrics);
3673
+ }
3674
+ return metrics;
3675
+ }
3676
+ function observabilityFrom(state) {
3677
+ const engineEvents = state.events.filter((event) => event.kind === "engine.result").map((event) => ({ event, details: eventDetails(event) }));
3678
+ const agentEvents = state.events.filter((event) => event.kind.startsWith("agent.")).map((event) => ({ event, details: eventDetails(event) })).filter(({ details }) => numericValue(details.duration_ms) !== void 0);
3679
+ const retryEvents = state.events.filter((event) => /retry|recovery/i.test(event.kind) || /retry|recovery/i.test(event.summary || "")).slice(-8);
3680
+ const runnerMetrics = agentEvents.flatMap(({ details }) => collectRunnerMetrics(details));
3681
+ const promptChars = runnerMetrics.map((metrics) => numericValue(metrics.prompt_chars)).filter((value) => value !== void 0);
3682
+ const sum = (values) => values.reduce((total, value) => total + (value ?? 0), 0);
3683
+ const recentEngineTimings = engineEvents.slice(-8).map(({ event, details }) => compactRecord({
3684
+ checkpoint: event.checkpoint || null,
3685
+ stage: event.stage || null,
3686
+ duration_ms: numericValue(details.duration_ms),
3687
+ ok: details.ok ?? null
3688
+ }));
3689
+ const recentAgentTimings = agentEvents.slice(-8).map(({ event, details }) => {
3690
+ const metrics = collectRunnerMetrics(details);
3691
+ const localPromptChars = metrics.map((item) => numericValue(item.prompt_chars)).filter((value) => value !== void 0);
3692
+ return compactRecord({
3693
+ kind: event.kind,
3694
+ checkpoint: event.checkpoint || null,
3695
+ stage: event.stage || null,
3696
+ duration_ms: numericValue(details.duration_ms),
3697
+ prompt_chars: localPromptChars.length ? Math.max(...localPromptChars) : void 0,
3698
+ attempt_count: numericValue(recordValue(details.adapter_details)?.attempt_count)
3699
+ });
3700
+ });
3701
+ return compactRecord({
3702
+ engine_call_count: engineEvents.length,
3703
+ agent_call_count: agentEvents.length,
3704
+ engine_total_ms: sum(engineEvents.map(({ details }) => numericValue(details.duration_ms))),
3705
+ agent_total_ms: sum(agentEvents.map(({ details }) => numericValue(details.duration_ms))),
3706
+ max_agent_prompt_chars: promptChars.length ? Math.max(...promptChars) : void 0,
3707
+ total_agent_prompt_chars: promptChars.length ? sum(promptChars) : void 0,
3708
+ recent_engine_timings: recentEngineTimings.length ? recentEngineTimings : void 0,
3709
+ recent_agent_timings: recentAgentTimings.length ? recentAgentTimings : void 0,
3710
+ retry_event_count: retryEvents.length,
3711
+ recent_retry_reasons: retryEvents.length ? retryEvents.map((event) => compactRecord({
3712
+ kind: event.kind,
3713
+ checkpoint: event.checkpoint || null,
3714
+ stage: event.stage || null,
3715
+ summary: compactText2(event.summary, 240)
3716
+ })) : void 0
3717
+ });
3718
+ }
3638
3719
  function visualDeltaFrom(input) {
3639
3720
  const fullState = input.fullRiddleState || {};
3640
3721
  const bundle = recordValue(fullState.evidence_bundle);
@@ -3747,6 +3828,7 @@ function createRiddleProofRunCard(state, input = {}) {
3747
3828
  proof_evidence_present: fullState.proof_evidence_present === true || Boolean(bundle?.proof_evidence || bundle?.proof_evidence_sample),
3748
3829
  artifacts
3749
3830
  }),
3831
+ observability: observabilityFrom(state),
3750
3832
  stop_condition: compactRecord({
3751
3833
  status: state.status,
3752
3834
  terminal: isTerminalStatus(state.status),
@@ -4184,6 +4266,20 @@ function checkpointContinueStage2(result) {
4184
4266
  const resume = recordValue(result.checkpointContract?.resume);
4185
4267
  return nonEmptyString(resume?.continue_with_stage);
4186
4268
  }
4269
+ function checkpointRecommendedStage(result) {
4270
+ const resumeStage = checkpointContinueStage2(result);
4271
+ if (resumeStage) return resumeStage;
4272
+ return nonEmptyString(result.checkpointContract?.recommended_advance_stage) || nonEmptyString(result.decisionRequest?.continue_with_stage) || nonEmptyString(result.decisionRequest?.recommended_advance_stage) || nonEmptyString(recordValue(result.decisionRequest)?.continueWithStage) || nonEmptyString(recordValue(result.decisionRequest)?.recommendedAdvanceStage);
4273
+ }
4274
+ function stageCheckpointContinuation(result) {
4275
+ const stage = checkpointRecommendedStage(result);
4276
+ if (!stage) return null;
4277
+ return {
4278
+ action: "run",
4279
+ state_path: String(result.state_path || ""),
4280
+ advance_stage: stage
4281
+ };
4282
+ }
4187
4283
  function recommendedContinuation(result) {
4188
4284
  const continueStage = checkpointContinueStage2(result);
4189
4285
  if (!continueStage) return null;
@@ -4226,6 +4322,18 @@ function defaultStageForProofCheckpointDecision(decision) {
4226
4322
  if (decision === "needs_richer_proof") return "author";
4227
4323
  return null;
4228
4324
  }
4325
+ function checkpointContractFromPacket(packet) {
4326
+ return recordValue(packet.evidence_excerpt?.checkpoint_contract) || recordValue(recordValue(packet.state_excerpt?.stage_decision_request)?.checkpoint_contract) || null;
4327
+ }
4328
+ function stageFromCheckpointResponse(response, packet) {
4329
+ if (response.decision === "needs_recon") return "recon";
4330
+ if (response.decision === "needs_implementation") return "implement";
4331
+ const payload = recordValue(response.payload) || {};
4332
+ const contract = checkpointContractFromPacket(packet);
4333
+ const resume = recordValue(contract?.resume);
4334
+ const stage = response.continue_with_stage || nonEmptyString(payload.continue_with_stage) || nonEmptyString(payload.recommended_stage) || nonEmptyString(resume?.continue_with_stage) || (response.decision === "retry_stage" ? packet.stage : "");
4335
+ return stage ? stage : null;
4336
+ }
4229
4337
  function proofAssessmentPayloadFromCheckpointResponse(response) {
4230
4338
  if (![
4231
4339
  "ready_to_ship",
@@ -4328,6 +4436,13 @@ function visualDeltaEvidenceRecoveryAssessment(state, payload, blocker) {
4328
4436
  blockers: [...blockers, blocker]
4329
4437
  };
4330
4438
  }
4439
+ function isRecoverableStageCheckpoint(checkpoint) {
4440
+ return [
4441
+ "ship_gate_blocked",
4442
+ "verify_required",
4443
+ "verify_supervisor_judgment_required"
4444
+ ].includes(checkpoint);
4445
+ }
4331
4446
  function contextFor(request, state, result) {
4332
4447
  return {
4333
4448
  request,
@@ -4674,6 +4789,18 @@ function checkpointResponseContinuation(state, value) {
4674
4789
  };
4675
4790
  }
4676
4791
  }
4792
+ if (response.decision === "continue_stage" || response.decision === "retry_stage" || response.decision === "needs_implementation") {
4793
+ const stage = stageFromCheckpointResponse(response, packet);
4794
+ if (stage) {
4795
+ appendCheckpointResponse(state, response);
4796
+ return {
4797
+ next: {
4798
+ ...base,
4799
+ advance_stage: stage
4800
+ }
4801
+ };
4802
+ }
4803
+ }
4677
4804
  appendCheckpointResponse(state, response, { clear_packet: false });
4678
4805
  return {
4679
4806
  blocker: {
@@ -4756,7 +4883,10 @@ async function handleImplementation(request, state, result, agent) {
4756
4883
  worktree_path: workdir || null
4757
4884
  }
4758
4885
  });
4886
+ const implementationStartedAt = timestamp3();
4887
+ const implementationStartedMs = Date.now();
4759
4888
  const implementation = await agent.implementChange({ ...context, workdir });
4889
+ const implementationDurationMs = Date.now() - implementationStartedMs;
4760
4890
  if (implementation.blocker || implementation.ok === false) {
4761
4891
  recordEvent(state, {
4762
4892
  kind: "agent.implementation.blocked",
@@ -4765,6 +4895,8 @@ async function handleImplementation(request, state, result, agent) {
4765
4895
  summary: implementation.summary || implementation.blocker?.message || "Implementation adapter reported a blocker.",
4766
4896
  details: compactRecord({
4767
4897
  worktree_path: workdir || null,
4898
+ started_at: implementationStartedAt,
4899
+ duration_ms: implementationDurationMs,
4768
4900
  changed_files: implementation.changedFiles || [],
4769
4901
  tests_run: implementation.testsRun || [],
4770
4902
  implementation_notes: implementation.implementationNotes || null,
@@ -4790,24 +4922,32 @@ async function handleImplementation(request, state, result, agent) {
4790
4922
  summary: implementation.summary || "Implementation adapter returned without leaving a detectable git diff.",
4791
4923
  details: compactRecord({
4792
4924
  worktree_path: workdir || null,
4925
+ started_at: implementationStartedAt,
4926
+ duration_ms: implementationDurationMs,
4793
4927
  changed_files: implementation.changedFiles || [],
4794
4928
  tests_run: implementation.testsRun || [],
4795
4929
  implementation_notes: implementation.implementationNotes || null,
4796
4930
  adapter_details: implementation.details || null
4797
4931
  })
4798
4932
  });
4799
- return {
4800
- blocker: {
4801
- code: "implementation_diff_missing",
4933
+ recordEvent(state, {
4934
+ kind: "agent.implementation.retry_requested",
4935
+ checkpoint: result.checkpoint || null,
4936
+ stage: "implement",
4937
+ summary: "Implementation adapter left no detectable diff; retrying the implement checkpoint inside the bounded loop.",
4938
+ details: compactRecord({
4939
+ worktree_path: workdir || null,
4802
4940
  checkpoint: result.checkpoint || null,
4803
- message: "The implementation adapter returned, but the after worktree has no detectable git diff. The harness will not advance to verify.",
4804
- details: compactRecord({
4805
- worktree_path: workdir || null,
4806
- changed_files: implementation.changedFiles || [],
4807
- tests_run: implementation.testsRun || [],
4808
- implementation_notes: implementation.implementationNotes || null,
4809
- adapter_details: implementation.details || null
4810
- })
4941
+ next_stage: "implement",
4942
+ previous_duration_ms: implementationDurationMs
4943
+ })
4944
+ });
4945
+ return {
4946
+ next: {
4947
+ action: "run",
4948
+ state_path: String(result.state_path || ""),
4949
+ advance_stage: "implement",
4950
+ implementation_notes: implementation.implementationNotes || implementation.summary || "Implementation adapter returned without a detectable git diff; retry the implement checkpoint."
4811
4951
  }
4812
4952
  };
4813
4953
  }
@@ -4818,6 +4958,8 @@ async function handleImplementation(request, state, result, agent) {
4818
4958
  summary: implementation.summary || "Implementation adapter reported code changes.",
4819
4959
  details: {
4820
4960
  worktree_path: workdir || null,
4961
+ started_at: implementationStartedAt,
4962
+ duration_ms: implementationDurationMs,
4821
4963
  diffDetected,
4822
4964
  changed_files: implementation.changedFiles || [],
4823
4965
  tests_run: implementation.testsRun || [],
@@ -4843,16 +4985,32 @@ async function routeCheckpoint(request, state, result, agent, input) {
4843
4985
  terminal: terminalResult(state, "completed", result, result.summary || "Riddle Proof engine completed.")
4844
4986
  };
4845
4987
  }
4988
+ if (isRecoverableStageCheckpoint(checkpoint) && !input.dry_run && !request.dry_run) {
4989
+ if (input.checkpoint_mode === "yield") {
4990
+ return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
4991
+ }
4992
+ const next = stageCheckpointContinuation(result);
4993
+ if (next) {
4994
+ recordEvent(state, {
4995
+ kind: "checkpoint.recovery_continuation",
4996
+ checkpoint,
4997
+ stage: stageFromCheckpoint2(result),
4998
+ summary: `Routing recoverable checkpoint ${checkpoint} back to ${next.advance_stage}.`,
4999
+ details: {
5000
+ next,
5001
+ checkpointContract: result.checkpointContract || null
5002
+ }
5003
+ });
5004
+ return { next };
5005
+ }
5006
+ }
4846
5007
  const failureBlocker = engineFailureBlocker(result, checkpoint);
4847
5008
  if (failureBlocker) {
4848
5009
  return { blocker: failureBlocker };
4849
5010
  }
4850
5011
  if ([
4851
5012
  "recon_human_escalation",
4852
- "verify_human_escalation",
4853
- "ship_gate_blocked",
4854
- "verify_required",
4855
- "verify_supervisor_judgment_required"
5013
+ "verify_human_escalation"
4856
5014
  ].includes(checkpoint) && result.ok === false) {
4857
5015
  return {
4858
5016
  blocker: {
@@ -4918,15 +5076,44 @@ async function routeCheckpoint(request, state, result, agent, input) {
4918
5076
  if (input.checkpoint_mode === "yield") {
4919
5077
  return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
4920
5078
  }
5079
+ const startedAt = timestamp3();
5080
+ const startedMs = Date.now();
5081
+ recordEvent(state, {
5082
+ kind: "agent.recon_assessment.started",
5083
+ checkpoint,
5084
+ stage: "recon",
5085
+ summary: "Recon assessment agent started.",
5086
+ details: { started_at: startedAt }
5087
+ });
4921
5088
  const assessment = await agent.assessRecon(context);
5089
+ const durationMs = Date.now() - startedMs;
4922
5090
  const blocker = requirePayload("recon_assessment", assessment, state, result);
4923
- if (blocker) return { blocker };
5091
+ if (blocker) {
5092
+ recordEvent(state, {
5093
+ kind: "agent.recon_assessment.blocked",
5094
+ checkpoint,
5095
+ stage: "recon",
5096
+ summary: blocker.message,
5097
+ details: compactRecord({
5098
+ started_at: startedAt,
5099
+ duration_ms: durationMs,
5100
+ blocker,
5101
+ adapter_details: assessment.details || null
5102
+ })
5103
+ });
5104
+ return { blocker };
5105
+ }
4924
5106
  recordEvent(state, {
4925
5107
  kind: "agent.recon_assessment.completed",
4926
5108
  checkpoint,
4927
5109
  stage: "recon",
4928
5110
  summary: assessment.summary,
4929
- details: { payload: assessment.payload }
5111
+ details: compactRecord({
5112
+ payload: assessment.payload,
5113
+ started_at: startedAt,
5114
+ duration_ms: durationMs,
5115
+ adapter_details: assessment.details || null
5116
+ })
4930
5117
  });
4931
5118
  return {
4932
5119
  next: { ...baseContinuation(result), recon_assessment_json: jsonParam(assessment.payload) }
@@ -4938,15 +5125,44 @@ async function routeCheckpoint(request, state, result, agent, input) {
4938
5125
  if (input.checkpoint_mode === "yield") {
4939
5126
  return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
4940
5127
  }
5128
+ const startedAt = timestamp3();
5129
+ const startedMs = Date.now();
5130
+ recordEvent(state, {
5131
+ kind: "agent.author_packet.started",
5132
+ checkpoint,
5133
+ stage: "author",
5134
+ summary: "Proof authoring agent started.",
5135
+ details: { started_at: startedAt }
5136
+ });
4941
5137
  const packet = await agent.authorProofPacket(context);
5138
+ const durationMs = Date.now() - startedMs;
4942
5139
  const blocker = requirePayload("author_packet", packet, state, result);
4943
- if (blocker) return { blocker };
5140
+ if (blocker) {
5141
+ recordEvent(state, {
5142
+ kind: "agent.author_packet.blocked",
5143
+ checkpoint,
5144
+ stage: "author",
5145
+ summary: blocker.message,
5146
+ details: compactRecord({
5147
+ started_at: startedAt,
5148
+ duration_ms: durationMs,
5149
+ blocker,
5150
+ adapter_details: packet.details || null
5151
+ })
5152
+ });
5153
+ return { blocker };
5154
+ }
4944
5155
  recordEvent(state, {
4945
5156
  kind: "agent.author_packet.completed",
4946
5157
  checkpoint,
4947
5158
  stage: "author",
4948
5159
  summary: packet.summary,
4949
- details: { payload: packet.payload }
5160
+ details: compactRecord({
5161
+ payload: packet.payload,
5162
+ started_at: startedAt,
5163
+ duration_ms: durationMs,
5164
+ adapter_details: packet.details || null
5165
+ })
4950
5166
  });
4951
5167
  return {
4952
5168
  next: { ...baseContinuation(result), author_packet_json: jsonParam(packet.payload) }
@@ -4969,9 +5185,31 @@ async function routeCheckpoint(request, state, result, agent, input) {
4969
5185
  if (input.checkpoint_mode === "yield") {
4970
5186
  return { terminal: checkpointAwaitingResult(state, result, input.checkpoint_visibility) };
4971
5187
  }
5188
+ const startedAt = timestamp3();
5189
+ const startedMs = Date.now();
5190
+ recordEvent(state, {
5191
+ kind: "agent.proof_assessment.started",
5192
+ checkpoint,
5193
+ stage: "verify",
5194
+ summary: "Proof assessment agent started.",
5195
+ details: { started_at: startedAt }
5196
+ });
4972
5197
  const assessment = await agent.assessProof(context);
5198
+ const durationMs = Date.now() - startedMs;
4973
5199
  const blocker = requirePayload("proof_assessment", assessment, state, result);
4974
5200
  if (blocker) {
5201
+ recordEvent(state, {
5202
+ kind: "agent.proof_assessment.blocked",
5203
+ checkpoint,
5204
+ stage: "verify",
5205
+ summary: blocker.message,
5206
+ details: compactRecord({
5207
+ started_at: startedAt,
5208
+ duration_ms: durationMs,
5209
+ blocker,
5210
+ adapter_details: assessment.details || null
5211
+ })
5212
+ });
4975
5213
  if (blocker.code === "main_agent_proof_review_required") {
4976
5214
  recordEvent(state, {
4977
5215
  kind: "checkpoint.packet.requested",
@@ -4990,7 +5228,12 @@ async function routeCheckpoint(request, state, result, agent, input) {
4990
5228
  checkpoint,
4991
5229
  stage: "verify",
4992
5230
  summary: assessment.summary,
4993
- details: { payload }
5231
+ details: compactRecord({
5232
+ payload,
5233
+ started_at: startedAt,
5234
+ duration_ms: durationMs,
5235
+ adapter_details: assessment.details || null
5236
+ })
4994
5237
  });
4995
5238
  const visualBlocker = proofAssessmentVisualBlocker({
4996
5239
  ...context.fullRiddleState || {},
@@ -5011,7 +5254,8 @@ async function routeCheckpoint(request, state, result, agent, input) {
5011
5254
  recovery_stage: "verify",
5012
5255
  evidence_issue_code: recoveryAssessment.evidence_issue_code || null,
5013
5256
  visual_delta: recoveryAssessment.visual_delta || null,
5014
- proof_assessment: recoveryAssessment
5257
+ proof_assessment: recoveryAssessment,
5258
+ agent_duration_ms: durationMs
5015
5259
  })
5016
5260
  });
5017
5261
  return { next: proofAssessmentContinuation(result, recoveryAssessment) };
@@ -2,10 +2,10 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-ALP5KOS2.js";
5
+ } from "./chunk-722PW3X3.js";
6
6
  import "./chunk-4ASMX4R6.js";
7
- import "./chunk-JOXTKWX6.js";
8
- import "./chunk-PLSGW2GI.js";
7
+ import "./chunk-U7Q3RB5D.js";
8
+ import "./chunk-CI2F66EE.js";
9
9
  import "./chunk-R6SCWJCI.js";
10
10
  import "./chunk-DUFDZJOF.js";
11
11
  export {