@riddledc/riddle-proof 0.5.8 → 0.5.10

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.
@@ -27,6 +27,17 @@ import {
27
27
  } from "fs";
28
28
  import path from "path";
29
29
  import crypto from "crypto";
30
+ var DEFAULT_MAX_ITERATIONS = 12;
31
+ var DEFAULT_STAGE_ITERATION_LIMITS = {
32
+ setup: 2,
33
+ recon: 4,
34
+ author: 3,
35
+ implement: 3,
36
+ prove: 3,
37
+ verify: 4,
38
+ ship: 2,
39
+ notify: 2
40
+ };
30
41
  function timestamp() {
31
42
  return (/* @__PURE__ */ new Date()).toISOString();
32
43
  }
@@ -254,17 +265,9 @@ function proofAssessmentRequestsShip(payload) {
254
265
  const continueStage = String(payload.continue_with_stage || "");
255
266
  return decision === "ready_to_ship" || recommendedStage === "ship" || continueStage === "ship";
256
267
  }
257
- function proofAssessmentContinuation(request, result, payload, config) {
268
+ function proofAssessmentContinuation(result, payload) {
258
269
  const proof_assessment_json = jsonParam(payload);
259
- if (effectiveShipMode(request, config) === "ship" || !proofAssessmentRequestsShip(payload)) {
260
- return { ...baseContinuation(result), proof_assessment_json };
261
- }
262
- return {
263
- action: "run",
264
- state_path: String(result.state_path || ""),
265
- advance_stage: "verify",
266
- proof_assessment_json
267
- };
270
+ return { ...baseContinuation(result), proof_assessment_json };
268
271
  }
269
272
  function contextFor(request, state, result) {
270
273
  return {
@@ -588,7 +591,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
588
591
  summary: assessment.summary,
589
592
  details: { payload }
590
593
  });
591
- return { next: proofAssessmentContinuation(request, result, payload, input.config) };
594
+ if (effectiveShipMode(request, input.config) !== "ship" && proofAssessmentRequestsShip(payload)) {
595
+ return {
596
+ terminal: terminalResult(
597
+ state,
598
+ "ready_to_ship",
599
+ result,
600
+ assessment.summary || result.summary || "Riddle Proof is ready to ship.",
601
+ {
602
+ ship_held: true,
603
+ proof_assessment: payload
604
+ }
605
+ )
606
+ };
607
+ }
608
+ return { next: proofAssessmentContinuation(result, payload) };
592
609
  }
593
610
  if (checkpoint === "verify_agent_retry") {
594
611
  const next = recommendedContinuation(result);
@@ -633,7 +650,7 @@ async function runRiddleProofEngineHarness(input) {
633
650
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
634
651
  const maxIterations = Math.max(
635
652
  1,
636
- Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? 8)
653
+ Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? DEFAULT_MAX_ITERATIONS)
637
654
  );
638
655
  state.status = "running";
639
656
  state.ok = void 0;
@@ -666,6 +683,7 @@ async function runRiddleProofEngineHarness(input) {
666
683
  }
667
684
  let nextParams = input.resume_params || initialRunParams(request, input, state);
668
685
  let lastResult = null;
686
+ const stageIterations = {};
669
687
  for (let index = 0; index < maxIterations; index += 1) {
670
688
  if (request.leave_draft && nextParams.leave_draft === void 0) {
671
689
  nextParams = { ...nextParams, leave_draft: true };
@@ -724,6 +742,7 @@ async function runRiddleProofEngineHarness(input) {
724
742
  if (engineState) state.request.engine_state_path = engineState;
725
743
  state.last_checkpoint = result.checkpoint || state.last_checkpoint || null;
726
744
  const resultStage = stageFromCheckpoint(result);
745
+ stageIterations[resultStage] = (stageIterations[resultStage] || 0) + 1;
727
746
  heartbeat(state, {
728
747
  stage: resultStage,
729
748
  summary: `${resultStage} stage is active.`,
@@ -749,6 +768,22 @@ async function runRiddleProofEngineHarness(input) {
749
768
  finished_at: timestamp()
750
769
  }
751
770
  });
771
+ const stageLimit = DEFAULT_STAGE_ITERATION_LIMITS[resultStage];
772
+ if (stageLimit && stageIterations[resultStage] > stageLimit) {
773
+ return blockerResult(state, result, {
774
+ code: "stage_iteration_limit_reached",
775
+ checkpoint: result.checkpoint || null,
776
+ message: `The harness exceeded the ${resultStage} stage iteration limit before the proof was ready or shipped.`,
777
+ details: {
778
+ stage: resultStage,
779
+ stage_iterations: stageIterations[resultStage],
780
+ stage_iteration_limit: stageLimit,
781
+ max_iterations: maxIterations,
782
+ lastCheckpoint: result.checkpoint || null,
783
+ lastSummary: result.summary || null
784
+ }
785
+ });
786
+ }
752
787
  const routed = await routeCheckpoint(request, state, result, agent, input);
753
788
  if (routed.terminal) return routed.terminal;
754
789
  if (routed.blocker) return blockerResult(state, result, routed.blocker);
@@ -2997,6 +2997,17 @@ function setRunStatus(state, status, at = timestamp()) {
2997
2997
  }
2998
2998
 
2999
2999
  // src/engine-harness.ts
3000
+ var DEFAULT_MAX_ITERATIONS = 12;
3001
+ var DEFAULT_STAGE_ITERATION_LIMITS = {
3002
+ setup: 2,
3003
+ recon: 4,
3004
+ author: 3,
3005
+ implement: 3,
3006
+ prove: 3,
3007
+ verify: 4,
3008
+ ship: 2,
3009
+ notify: 2
3010
+ };
3000
3011
  function timestamp2() {
3001
3012
  return (/* @__PURE__ */ new Date()).toISOString();
3002
3013
  }
@@ -3224,17 +3235,9 @@ function proofAssessmentRequestsShip(payload) {
3224
3235
  const continueStage = String(payload.continue_with_stage || "");
3225
3236
  return decision === "ready_to_ship" || recommendedStage === "ship" || continueStage === "ship";
3226
3237
  }
3227
- function proofAssessmentContinuation(request, result, payload, config) {
3238
+ function proofAssessmentContinuation(result, payload) {
3228
3239
  const proof_assessment_json = jsonParam(payload);
3229
- if (effectiveShipMode(request, config) === "ship" || !proofAssessmentRequestsShip(payload)) {
3230
- return { ...baseContinuation(result), proof_assessment_json };
3231
- }
3232
- return {
3233
- action: "run",
3234
- state_path: String(result.state_path || ""),
3235
- advance_stage: "verify",
3236
- proof_assessment_json
3237
- };
3240
+ return { ...baseContinuation(result), proof_assessment_json };
3238
3241
  }
3239
3242
  function contextFor(request, state, result) {
3240
3243
  return {
@@ -3558,7 +3561,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
3558
3561
  summary: assessment.summary,
3559
3562
  details: { payload }
3560
3563
  });
3561
- return { next: proofAssessmentContinuation(request, result, payload, input.config) };
3564
+ if (effectiveShipMode(request, input.config) !== "ship" && proofAssessmentRequestsShip(payload)) {
3565
+ return {
3566
+ terminal: terminalResult(
3567
+ state,
3568
+ "ready_to_ship",
3569
+ result,
3570
+ assessment.summary || result.summary || "Riddle Proof is ready to ship.",
3571
+ {
3572
+ ship_held: true,
3573
+ proof_assessment: payload
3574
+ }
3575
+ )
3576
+ };
3577
+ }
3578
+ return { next: proofAssessmentContinuation(result, payload) };
3562
3579
  }
3563
3580
  if (checkpoint === "verify_agent_retry") {
3564
3581
  const next = recommendedContinuation(result);
@@ -3603,7 +3620,7 @@ async function runRiddleProofEngineHarness(input) {
3603
3620
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
3604
3621
  const maxIterations = Math.max(
3605
3622
  1,
3606
- Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? 8)
3623
+ Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? DEFAULT_MAX_ITERATIONS)
3607
3624
  );
3608
3625
  state.status = "running";
3609
3626
  state.ok = void 0;
@@ -3636,6 +3653,7 @@ async function runRiddleProofEngineHarness(input) {
3636
3653
  }
3637
3654
  let nextParams = input.resume_params || initialRunParams(request, input, state);
3638
3655
  let lastResult = null;
3656
+ const stageIterations = {};
3639
3657
  for (let index = 0; index < maxIterations; index += 1) {
3640
3658
  if (request.leave_draft && nextParams.leave_draft === void 0) {
3641
3659
  nextParams = { ...nextParams, leave_draft: true };
@@ -3694,6 +3712,7 @@ async function runRiddleProofEngineHarness(input) {
3694
3712
  if (engineState) state.request.engine_state_path = engineState;
3695
3713
  state.last_checkpoint = result.checkpoint || state.last_checkpoint || null;
3696
3714
  const resultStage = stageFromCheckpoint(result);
3715
+ stageIterations[resultStage] = (stageIterations[resultStage] || 0) + 1;
3697
3716
  heartbeat(state, {
3698
3717
  stage: resultStage,
3699
3718
  summary: `${resultStage} stage is active.`,
@@ -3719,6 +3738,22 @@ async function runRiddleProofEngineHarness(input) {
3719
3738
  finished_at: timestamp2()
3720
3739
  }
3721
3740
  });
3741
+ const stageLimit = DEFAULT_STAGE_ITERATION_LIMITS[resultStage];
3742
+ if (stageLimit && stageIterations[resultStage] > stageLimit) {
3743
+ return blockerResult(state, result, {
3744
+ code: "stage_iteration_limit_reached",
3745
+ checkpoint: result.checkpoint || null,
3746
+ message: `The harness exceeded the ${resultStage} stage iteration limit before the proof was ready or shipped.`,
3747
+ details: {
3748
+ stage: resultStage,
3749
+ stage_iterations: stageIterations[resultStage],
3750
+ stage_iteration_limit: stageLimit,
3751
+ max_iterations: maxIterations,
3752
+ lastCheckpoint: result.checkpoint || null,
3753
+ lastSummary: result.summary || null
3754
+ }
3755
+ });
3756
+ }
3722
3757
  const routed = await routeCheckpoint(request, state, result, agent, input);
3723
3758
  if (routed.terminal) return routed.terminal;
3724
3759
  if (routed.blocker) return blockerResult(state, result, routed.blocker);
@@ -2,7 +2,7 @@ import {
2
2
  createDisabledRiddleProofAgentAdapter,
3
3
  readRiddleProofRunStatus,
4
4
  runRiddleProofEngineHarness
5
- } from "./chunk-GC7C2NRA.js";
5
+ } from "./chunk-7KP34QRG.js";
6
6
  import "./chunk-GVPCSXN7.js";
7
7
  import "./chunk-TMMKRKY5.js";
8
8
  export {
package/dist/index.cjs CHANGED
@@ -3556,6 +3556,17 @@ var import_node_child_process2 = require("child_process");
3556
3556
  var import_node_fs3 = require("fs");
3557
3557
  var import_node_path3 = __toESM(require("path"), 1);
3558
3558
  var import_node_crypto2 = __toESM(require("crypto"), 1);
3559
+ var DEFAULT_MAX_ITERATIONS = 12;
3560
+ var DEFAULT_STAGE_ITERATION_LIMITS = {
3561
+ setup: 2,
3562
+ recon: 4,
3563
+ author: 3,
3564
+ implement: 3,
3565
+ prove: 3,
3566
+ verify: 4,
3567
+ ship: 2,
3568
+ notify: 2
3569
+ };
3559
3570
  function timestamp2() {
3560
3571
  return (/* @__PURE__ */ new Date()).toISOString();
3561
3572
  }
@@ -3783,17 +3794,9 @@ function proofAssessmentRequestsShip(payload) {
3783
3794
  const continueStage = String(payload.continue_with_stage || "");
3784
3795
  return decision === "ready_to_ship" || recommendedStage === "ship" || continueStage === "ship";
3785
3796
  }
3786
- function proofAssessmentContinuation(request, result, payload, config) {
3797
+ function proofAssessmentContinuation(result, payload) {
3787
3798
  const proof_assessment_json = jsonParam(payload);
3788
- if (effectiveShipMode(request, config) === "ship" || !proofAssessmentRequestsShip(payload)) {
3789
- return { ...baseContinuation(result), proof_assessment_json };
3790
- }
3791
- return {
3792
- action: "run",
3793
- state_path: String(result.state_path || ""),
3794
- advance_stage: "verify",
3795
- proof_assessment_json
3796
- };
3799
+ return { ...baseContinuation(result), proof_assessment_json };
3797
3800
  }
3798
3801
  function contextFor(request, state, result) {
3799
3802
  return {
@@ -4117,7 +4120,21 @@ async function routeCheckpoint(request, state, result, agent, input) {
4117
4120
  summary: assessment.summary,
4118
4121
  details: { payload }
4119
4122
  });
4120
- return { next: proofAssessmentContinuation(request, result, payload, input.config) };
4123
+ if (effectiveShipMode(request, input.config) !== "ship" && proofAssessmentRequestsShip(payload)) {
4124
+ return {
4125
+ terminal: terminalResult(
4126
+ state,
4127
+ "ready_to_ship",
4128
+ result,
4129
+ assessment.summary || result.summary || "Riddle Proof is ready to ship.",
4130
+ {
4131
+ ship_held: true,
4132
+ proof_assessment: payload
4133
+ }
4134
+ )
4135
+ };
4136
+ }
4137
+ return { next: proofAssessmentContinuation(result, payload) };
4121
4138
  }
4122
4139
  if (checkpoint === "verify_agent_retry") {
4123
4140
  const next = recommendedContinuation(result);
@@ -4162,7 +4179,7 @@ async function runRiddleProofEngineHarness(input) {
4162
4179
  const agent = input.agent || createDisabledRiddleProofAgentAdapter();
4163
4180
  const maxIterations = Math.max(
4164
4181
  1,
4165
- Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? 8)
4182
+ Math.trunc(input.max_iterations ?? request.max_iterations ?? input.config?.defaultMaxIterations ?? DEFAULT_MAX_ITERATIONS)
4166
4183
  );
4167
4184
  state.status = "running";
4168
4185
  state.ok = void 0;
@@ -4195,6 +4212,7 @@ async function runRiddleProofEngineHarness(input) {
4195
4212
  }
4196
4213
  let nextParams = input.resume_params || initialRunParams(request, input, state);
4197
4214
  let lastResult = null;
4215
+ const stageIterations = {};
4198
4216
  for (let index = 0; index < maxIterations; index += 1) {
4199
4217
  if (request.leave_draft && nextParams.leave_draft === void 0) {
4200
4218
  nextParams = { ...nextParams, leave_draft: true };
@@ -4253,6 +4271,7 @@ async function runRiddleProofEngineHarness(input) {
4253
4271
  if (engineState) state.request.engine_state_path = engineState;
4254
4272
  state.last_checkpoint = result.checkpoint || state.last_checkpoint || null;
4255
4273
  const resultStage = stageFromCheckpoint(result);
4274
+ stageIterations[resultStage] = (stageIterations[resultStage] || 0) + 1;
4256
4275
  heartbeat(state, {
4257
4276
  stage: resultStage,
4258
4277
  summary: `${resultStage} stage is active.`,
@@ -4278,6 +4297,22 @@ async function runRiddleProofEngineHarness(input) {
4278
4297
  finished_at: timestamp2()
4279
4298
  }
4280
4299
  });
4300
+ const stageLimit = DEFAULT_STAGE_ITERATION_LIMITS[resultStage];
4301
+ if (stageLimit && stageIterations[resultStage] > stageLimit) {
4302
+ return blockerResult(state, result, {
4303
+ code: "stage_iteration_limit_reached",
4304
+ checkpoint: result.checkpoint || null,
4305
+ message: `The harness exceeded the ${resultStage} stage iteration limit before the proof was ready or shipped.`,
4306
+ details: {
4307
+ stage: resultStage,
4308
+ stage_iterations: stageIterations[resultStage],
4309
+ stage_iteration_limit: stageLimit,
4310
+ max_iterations: maxIterations,
4311
+ lastCheckpoint: result.checkpoint || null,
4312
+ lastSummary: result.summary || null
4313
+ }
4314
+ });
4315
+ }
4281
4316
  const routed = await routeCheckpoint(request, state, result, agent, input);
4282
4317
  if (routed.terminal) return routed.terminal;
4283
4318
  if (routed.blocker) return blockerResult(state, result, routed.blocker);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  createDisabledRiddleProofAgentAdapter,
14
14
  readRiddleProofRunStatus,
15
15
  runRiddleProofEngineHarness
16
- } from "./chunk-GC7C2NRA.js";
16
+ } from "./chunk-7KP34QRG.js";
17
17
  import {
18
18
  runRiddleProof
19
19
  } from "./chunk-VSEKLCNU.js";
@@ -262,7 +262,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
262
262
  blocking?: boolean;
263
263
  details?: Record<string, unknown>;
264
264
  ok: boolean;
265
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
265
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
266
266
  state_path: string;
267
267
  stage: any;
268
268
  summary: string;
@@ -342,7 +342,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
342
342
  continueWithStage?: WorkflowStage | null;
343
343
  blocking?: boolean;
344
344
  details?: Record<string, unknown>;
345
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
345
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
346
346
  state_path: string;
347
347
  stage: any;
348
348
  checkpoint: string;
@@ -589,7 +589,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
589
589
  error?: undefined;
590
590
  } | {
591
591
  ok: boolean;
592
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
592
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
593
593
  state_path: string;
594
594
  stage: any;
595
595
  summary: string;
@@ -262,7 +262,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
262
262
  blocking?: boolean;
263
263
  details?: Record<string, unknown>;
264
264
  ok: boolean;
265
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
265
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
266
266
  state_path: string;
267
267
  stage: any;
268
268
  summary: string;
@@ -342,7 +342,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
342
342
  continueWithStage?: WorkflowStage | null;
343
343
  blocking?: boolean;
344
344
  details?: Record<string, unknown>;
345
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
345
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
346
346
  state_path: string;
347
347
  stage: any;
348
348
  checkpoint: string;
@@ -589,7 +589,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
589
589
  error?: undefined;
590
590
  } | {
591
591
  ok: boolean;
592
- action: "ship" | "setup" | "recon" | "author" | "implement" | "verify" | "run";
592
+ action: "setup" | "recon" | "author" | "implement" | "verify" | "ship" | "run";
593
593
  state_path: string;
594
594
  stage: any;
595
595
  summary: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riddledc/riddle-proof",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Reusable Riddle Proof contracts and helpers for evidence-backed agent changes.",
5
5
  "license": "MIT",
6
6
  "author": "RiddleDC",