@probelabs/visor 0.1.124 → 0.1.126

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.
Files changed (195) hide show
  1. package/dist/config.d.ts.map +1 -1
  2. package/dist/docs/DEPLOYMENT.md +117 -11
  3. package/dist/docs/GITHUB_CHECKS.md +18 -4
  4. package/dist/docs/NPM_USAGE.md +112 -39
  5. package/dist/docs/action-reference.md +63 -9
  6. package/dist/docs/advanced-ai.md +58 -51
  7. package/dist/docs/ai-configuration.md +99 -11
  8. package/dist/docs/ai-custom-tools-usage.md +70 -33
  9. package/dist/docs/ai-custom-tools.md +50 -27
  10. package/dist/docs/architecture.md +1232 -0
  11. package/dist/docs/bot-transports-rfc.md +13 -3
  12. package/dist/docs/ci-cli-mode.md +116 -8
  13. package/dist/docs/claude-code.md +111 -41
  14. package/dist/docs/command-provider.md +37 -15
  15. package/dist/docs/commands.md +252 -6
  16. package/dist/docs/configuration.md +138 -4
  17. package/dist/docs/contributing.md +737 -0
  18. package/dist/docs/custom-tools.md +39 -8
  19. package/dist/docs/dashboards/README.md +33 -19
  20. package/dist/docs/debug-visualizer-progress.md +14 -13
  21. package/dist/docs/debug-visualizer-rfc.md +14 -13
  22. package/dist/docs/debug-visualizer.md +30 -5
  23. package/dist/docs/debugging.md +73 -8
  24. package/dist/docs/default-output-schema.md +24 -20
  25. package/dist/docs/dependencies.md +75 -21
  26. package/dist/docs/dev-playbook.md +85 -9
  27. package/dist/docs/engine-pause-resume-rfc.md +11 -11
  28. package/dist/docs/engine-state-machine-plan.md +10 -3
  29. package/dist/docs/event-driven-github-integration-rfc.md +20 -11
  30. package/dist/docs/event-triggers.md +95 -6
  31. package/dist/docs/execution-statistics-rfc.md +16 -4
  32. package/dist/docs/fact-validator-gap-analysis.md +12 -1
  33. package/dist/docs/fact-validator-implementation-plan.md +19 -11
  34. package/dist/docs/fail-if.md +116 -11
  35. package/dist/docs/failure-conditions-implementation.md +40 -6
  36. package/dist/docs/failure-conditions-schema.md +243 -87
  37. package/dist/docs/failure-routing-rfc.md +43 -18
  38. package/dist/docs/failure-routing.md +80 -23
  39. package/dist/docs/faq.md +836 -0
  40. package/dist/docs/foreach-dependency-propagation.md +32 -15
  41. package/dist/docs/github-ops.md +6 -5
  42. package/dist/docs/glossary.md +322 -0
  43. package/dist/docs/goto-forward-run-plan.md +23 -10
  44. package/dist/docs/guides/criticality-modes.md +15 -13
  45. package/dist/docs/guides/fault-management-and-contracts.md +8 -5
  46. package/dist/docs/guides/workflow-style-guide.md +17 -8
  47. package/dist/docs/http.md +102 -3
  48. package/dist/docs/human-input-provider.md +20 -36
  49. package/dist/docs/index.md +206 -0
  50. package/dist/docs/lifecycle-hooks.md +322 -2
  51. package/dist/docs/limits.md +20 -5
  52. package/dist/docs/liquid-templates.md +86 -14
  53. package/dist/docs/loop-routing-refactor.md +4 -2
  54. package/dist/docs/mcp-provider.md +53 -19
  55. package/dist/docs/mcp.md +27 -1
  56. package/dist/docs/memory.md +7 -2
  57. package/dist/docs/migration.md +596 -0
  58. package/dist/docs/observability.md +227 -6
  59. package/dist/docs/output-formats.md +388 -9
  60. package/dist/docs/output-history.md +36 -6
  61. package/dist/docs/performance.md +510 -4
  62. package/dist/docs/pluggable.md +95 -4
  63. package/dist/docs/proposals/snapshot-scope-execution.md +6 -5
  64. package/dist/docs/providers/git-checkout.md +16 -14
  65. package/dist/docs/providers/noop.md +696 -0
  66. package/dist/docs/recipes.md +8 -9
  67. package/dist/docs/rfc/git-checkout-step.md +3 -1
  68. package/dist/docs/rfc/on_init-hook.md +18 -5
  69. package/dist/docs/rfc/workspace-isolation.md +16 -0
  70. package/dist/docs/roadmap/criticality-implementation-tasks.md +27 -27
  71. package/dist/docs/router-patterns.md +155 -43
  72. package/dist/docs/schema-templates.md +51 -15
  73. package/dist/docs/script.md +162 -13
  74. package/dist/docs/sdk.md +46 -12
  75. package/dist/docs/security.md +464 -5
  76. package/dist/docs/slack-integration.md +481 -0
  77. package/dist/docs/tag-filtering.md +60 -20
  78. package/dist/docs/telemetry-setup.md +157 -46
  79. package/dist/docs/test-framework-rfc.md +37 -36
  80. package/dist/docs/testing/assertions.md +92 -4
  81. package/dist/docs/testing/ci.md +56 -7
  82. package/dist/docs/testing/cli.md +57 -15
  83. package/dist/docs/testing/cookbook.md +53 -20
  84. package/dist/docs/testing/dsl-reference.md +110 -9
  85. package/dist/docs/testing/fixtures-and-mocks.md +28 -3
  86. package/dist/docs/testing/flows.md +59 -4
  87. package/dist/docs/testing/getting-started.md +14 -13
  88. package/dist/docs/testing/troubleshooting.md +39 -2
  89. package/dist/docs/timeouts.md +174 -18
  90. package/dist/docs/troubleshooting.md +176 -6
  91. package/dist/docs/workflow-creation-guide.md +101 -3
  92. package/dist/docs/workflows.md +138 -41
  93. package/dist/examples/README.md +169 -4
  94. package/dist/examples/ai-custom-tools-simple.yaml +2 -3
  95. package/dist/examples/cron-webhook-config.yaml +15 -0
  96. package/dist/examples/forEach-example.yaml +6 -0
  97. package/dist/examples/git-checkout-basic.yaml +4 -0
  98. package/dist/examples/git-checkout-compare.yaml +6 -0
  99. package/dist/examples/git-checkout-cross-repo.yaml +7 -0
  100. package/dist/examples/http-integration-config.yaml +30 -0
  101. package/dist/examples/https-server-config.yaml +15 -0
  102. package/dist/examples/mcp-provider-example.yaml +10 -10
  103. package/dist/examples/transform-example.yaml +3 -0
  104. package/dist/examples/webhook-pipeline-config.yaml +18 -0
  105. package/dist/examples/workflows/workflow-composition-example.yaml +4 -0
  106. package/dist/frontends/slack-frontend.d.ts +2 -0
  107. package/dist/frontends/slack-frontend.d.ts.map +1 -1
  108. package/dist/generated/config-schema.d.ts +11 -7
  109. package/dist/generated/config-schema.d.ts.map +1 -1
  110. package/dist/generated/config-schema.json +11 -7
  111. package/dist/index.js +3127 -974
  112. package/dist/output/traces/{run-2026-01-28T16-15-24-569Z.ndjson → run-2026-01-31T16-37-22-321Z.ndjson} +84 -84
  113. package/dist/output/traces/{run-2026-01-28T16-16-09-757Z.ndjson → run-2026-01-31T16-38-06-031Z.ndjson} +1013 -1013
  114. package/dist/providers/ai-check-provider.d.ts +9 -2
  115. package/dist/providers/ai-check-provider.d.ts.map +1 -1
  116. package/dist/providers/command-check-provider.d.ts.map +1 -1
  117. package/dist/providers/mcp-custom-sse-server.d.ts +17 -1
  118. package/dist/providers/mcp-custom-sse-server.d.ts.map +1 -1
  119. package/dist/providers/workflow-check-provider.d.ts.map +1 -1
  120. package/dist/providers/workflow-tool-executor.d.ts +68 -0
  121. package/dist/providers/workflow-tool-executor.d.ts.map +1 -0
  122. package/dist/sdk/{check-provider-registry-AQ3JETBG.mjs → check-provider-registry-3KI5RKXT.mjs} +6 -5
  123. package/dist/sdk/check-provider-registry-IYILYY35.mjs +28 -0
  124. package/dist/sdk/chunk-2CPMMNIX.mjs +1459 -0
  125. package/dist/sdk/chunk-2CPMMNIX.mjs.map +1 -0
  126. package/dist/sdk/chunk-5LI6T4O3.mjs +3600 -0
  127. package/dist/sdk/chunk-5LI6T4O3.mjs.map +1 -0
  128. package/dist/sdk/{chunk-YLQ4UN62.mjs → chunk-A4PGHURG.mjs} +6838 -6257
  129. package/dist/sdk/chunk-A4PGHURG.mjs.map +1 -0
  130. package/dist/sdk/chunk-EXFGO4FX.mjs +147 -0
  131. package/dist/sdk/chunk-EXFGO4FX.mjs.map +1 -0
  132. package/dist/sdk/chunk-PJ7K5UFC.mjs +17732 -0
  133. package/dist/sdk/chunk-PJ7K5UFC.mjs.map +1 -0
  134. package/dist/sdk/{chunk-BHZ4CKUS.mjs → chunk-PXFIALUH.mjs} +77 -8
  135. package/dist/sdk/chunk-PXFIALUH.mjs.map +1 -0
  136. package/dist/sdk/{chunk-PVITVJ6J.mjs → chunk-RTKJXNZS.mjs} +32 -9
  137. package/dist/sdk/chunk-RTKJXNZS.mjs.map +1 -0
  138. package/dist/sdk/chunk-VW2GBXQT.mjs +606 -0
  139. package/dist/sdk/chunk-VW2GBXQT.mjs.map +1 -0
  140. package/dist/sdk/{config-RQQPMLRD.mjs → config-5AUYQFHE.mjs} +2 -2
  141. package/dist/sdk/config-6CUVEH7H.mjs +16 -0
  142. package/dist/sdk/config-6CUVEH7H.mjs.map +1 -0
  143. package/dist/sdk/{github-frontend-6Q4BISZX.mjs → github-frontend-BZ4N3BFZ.mjs} +7 -3
  144. package/dist/sdk/github-frontend-BZ4N3BFZ.mjs.map +1 -0
  145. package/dist/sdk/host-4MT3EW2I.mjs +52 -0
  146. package/dist/sdk/{host-P5NQICP7.mjs → host-NYWXLIFC.mjs} +2 -2
  147. package/dist/sdk/host-NYWXLIFC.mjs.map +1 -0
  148. package/dist/sdk/{routing-DEY2AIXM.mjs → routing-6R42GXUO.mjs} +2 -2
  149. package/dist/sdk/routing-6R42GXUO.mjs.map +1 -0
  150. package/dist/sdk/routing-7FXPULTO.mjs +24 -0
  151. package/dist/sdk/routing-7FXPULTO.mjs.map +1 -0
  152. package/dist/sdk/sdk.d.mts +3 -1
  153. package/dist/sdk/sdk.d.ts +3 -1
  154. package/dist/sdk/sdk.js +12163 -11204
  155. package/dist/sdk/sdk.js.map +1 -1
  156. package/dist/sdk/sdk.mjs +14 -10
  157. package/dist/sdk/sdk.mjs.map +1 -1
  158. package/dist/sdk/slack-frontend-JUT3TYVC.mjs +821 -0
  159. package/dist/sdk/slack-frontend-JUT3TYVC.mjs.map +1 -0
  160. package/dist/sdk/workflow-check-provider-H3CUOLUD.mjs +28 -0
  161. package/dist/sdk/workflow-check-provider-H3CUOLUD.mjs.map +1 -0
  162. package/dist/sdk/workflow-check-provider-YUNNF4KC.mjs +28 -0
  163. package/dist/sdk/workflow-check-provider-YUNNF4KC.mjs.map +1 -0
  164. package/dist/sdk/workflow-registry-KFWSDSLM.mjs +12 -0
  165. package/dist/sdk/workflow-registry-KFWSDSLM.mjs.map +1 -0
  166. package/dist/slack/socket-runner.d.ts +2 -0
  167. package/dist/slack/socket-runner.d.ts.map +1 -1
  168. package/dist/state-machine/context/workflow-inputs.d.ts +20 -0
  169. package/dist/state-machine/context/workflow-inputs.d.ts.map +1 -0
  170. package/dist/state-machine/dispatch/execution-invoker.d.ts.map +1 -1
  171. package/dist/state-machine/dispatch/foreach-processor.d.ts.map +1 -1
  172. package/dist/state-machine/dispatch/stats-manager.d.ts.map +1 -1
  173. package/dist/state-machine/states/level-dispatch.d.ts.map +1 -1
  174. package/dist/state-machine/states/routing.d.ts +2 -1
  175. package/dist/state-machine/states/routing.d.ts.map +1 -1
  176. package/dist/traces/{run-2026-01-28T16-15-24-569Z.ndjson → run-2026-01-31T16-37-22-321Z.ndjson} +84 -84
  177. package/dist/traces/{run-2026-01-28T16-16-09-757Z.ndjson → run-2026-01-31T16-38-06-031Z.ndjson} +1013 -1013
  178. package/dist/types/config.d.ts +3 -1
  179. package/dist/types/config.d.ts.map +1 -1
  180. package/dist/utils/human-id.d.ts +12 -0
  181. package/dist/utils/human-id.d.ts.map +1 -0
  182. package/dist/utils/worktree-manager.d.ts +3 -0
  183. package/dist/utils/worktree-manager.d.ts.map +1 -1
  184. package/dist/workflow-executor.d.ts.map +1 -1
  185. package/dist/workflow-registry.d.ts +1 -0
  186. package/dist/workflow-registry.d.ts.map +1 -1
  187. package/package.json +2 -2
  188. package/dist/sdk/chunk-BHZ4CKUS.mjs.map +0 -1
  189. package/dist/sdk/chunk-PVITVJ6J.mjs.map +0 -1
  190. package/dist/sdk/chunk-YLQ4UN62.mjs.map +0 -1
  191. package/dist/sdk/github-frontend-6Q4BISZX.mjs.map +0 -1
  192. /package/dist/sdk/{check-provider-registry-AQ3JETBG.mjs.map → check-provider-registry-3KI5RKXT.mjs.map} +0 -0
  193. /package/dist/sdk/{config-RQQPMLRD.mjs.map → check-provider-registry-IYILYY35.mjs.map} +0 -0
  194. /package/dist/sdk/{routing-DEY2AIXM.mjs.map → config-5AUYQFHE.mjs.map} +0 -0
  195. /package/dist/sdk/{host-P5NQICP7.mjs.map → host-4MT3EW2I.mjs.map} +0 -0
@@ -236,10 +236,33 @@ function recordRoutingEvent(args) {
236
236
  async function handleRouting(context, state, transition, emitEvent, routingContext) {
237
237
  const { checkId, scope, result, checkConfig, success } = routingContext;
238
238
  logger.info(`[Routing] Evaluating routing for check: ${checkId}, success: ${success}`);
239
- const failIfTriggered = await evaluateFailIf(checkId, result, checkConfig, context, state);
240
- if (failIfTriggered) {
239
+ const failureResult = await evaluateFailIf(checkId, result, checkConfig, context, state);
240
+ if (failureResult.haltExecution) {
241
+ logger.error(
242
+ `[Routing] HALTING EXECUTION due to critical failure in ${checkId}: ${failureResult.haltMessage}`
243
+ );
244
+ const haltIssue = {
245
+ file: "system",
246
+ line: 0,
247
+ ruleId: `${checkId}_halt_execution`,
248
+ message: `Execution halted: ${failureResult.haltMessage || "Critical failure condition met"}`,
249
+ severity: "error",
250
+ category: "logic"
251
+ };
252
+ result.issues = [...result.issues || [], haltIssue];
253
+ emitEvent({
254
+ type: "Shutdown",
255
+ error: {
256
+ message: failureResult.haltMessage || `Execution halted by check ${checkId}`,
257
+ name: "HaltExecution"
258
+ }
259
+ });
260
+ transition("Error");
261
+ return true;
262
+ }
263
+ if (failureResult.failed) {
241
264
  if (context.debug) {
242
- logger.info(`[Routing] fail_if triggered for ${checkId}`);
265
+ logger.info(`[Routing] fail_if/failure_conditions triggered for ${checkId}`);
243
266
  }
244
267
  await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);
245
268
  } else if (success) {
@@ -257,6 +280,7 @@ async function handleRouting(context, state, transition, emitEvent, routingConte
257
280
  await processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent);
258
281
  }
259
282
  transition("WavePlanning");
283
+ return false;
260
284
  }
261
285
  async function processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent) {
262
286
  const onFinish = checkConfig.on_finish;
@@ -470,8 +494,10 @@ async function evaluateFailIf(checkId, result, checkConfig, context, state) {
470
494
  const config = context.config;
471
495
  const globalFailIf = config.fail_if;
472
496
  const checkFailIf = checkConfig.fail_if;
473
- if (!globalFailIf && !checkFailIf) {
474
- return false;
497
+ const globalFailureConditions = config.failure_conditions;
498
+ const checkFailureConditions = checkConfig.failure_conditions;
499
+ if (!globalFailIf && !checkFailIf && !globalFailureConditions && !checkFailureConditions) {
500
+ return { failed: false, haltExecution: false };
475
501
  }
476
502
  const evaluator = new FailureConditionEvaluator();
477
503
  const outputsRecord = {};
@@ -495,6 +521,9 @@ async function evaluateFailIf(checkId, result, checkConfig, context, state) {
495
521
  }
496
522
  const checkSchema = typeof checkConfig.schema === "object" ? "custom" : checkConfig.schema || "";
497
523
  const checkGroup = checkConfig.group || "";
524
+ let anyFailed = false;
525
+ let shouldHalt = false;
526
+ let haltMessage;
498
527
  if (globalFailIf) {
499
528
  try {
500
529
  const failed = await evaluator.evaluateSimpleCondition(
@@ -543,14 +572,54 @@ async function evaluateFailIf(checkId, result, checkConfig, context, state) {
543
572
  category: "logic"
544
573
  };
545
574
  result.issues = [...result.issues || [], failIssue];
546
- return true;
575
+ anyFailed = true;
547
576
  }
548
577
  } catch (error) {
549
578
  const msg = error instanceof Error ? error.message : String(error);
550
579
  logger.error(`[Routing] Error evaluating check fail_if: ${msg}`);
551
580
  }
552
581
  }
553
- return false;
582
+ if (globalFailureConditions || checkFailureConditions) {
583
+ try {
584
+ const conditionResults = await evaluator.evaluateConditions(
585
+ checkId,
586
+ checkSchema,
587
+ checkGroup,
588
+ result,
589
+ globalFailureConditions,
590
+ checkFailureConditions,
591
+ outputsRecord
592
+ );
593
+ for (const condResult of conditionResults) {
594
+ if (condResult.failed) {
595
+ logger.warn(
596
+ `[Routing] Failure condition '${condResult.conditionName}' triggered for ${checkId}: ${condResult.expression}`
597
+ );
598
+ const failIssue = {
599
+ file: "system",
600
+ line: 0,
601
+ ruleId: `${checkId}_${condResult.conditionName}`,
602
+ message: condResult.message || `Failure condition met: ${condResult.expression}`,
603
+ severity: condResult.severity || "error",
604
+ category: "logic"
605
+ };
606
+ result.issues = [...result.issues || [], failIssue];
607
+ anyFailed = true;
608
+ if (condResult.haltExecution) {
609
+ shouldHalt = true;
610
+ haltMessage = condResult.message || `Execution halted: condition '${condResult.conditionName}' triggered`;
611
+ logger.error(
612
+ `[Routing] HALT EXECUTION triggered by '${condResult.conditionName}' for ${checkId}`
613
+ );
614
+ }
615
+ }
616
+ }
617
+ } catch (error) {
618
+ const msg = error instanceof Error ? error.message : String(error);
619
+ logger.error(`[Routing] Error evaluating failure_conditions: ${msg}`);
620
+ }
621
+ }
622
+ return { failed: anyFailed, haltExecution: shouldHalt, haltMessage };
554
623
  }
555
624
  function checkLoopBudget(context, state, origin, action) {
556
625
  const maxLoops = context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS;
@@ -1386,4 +1455,4 @@ export {
1386
1455
  evaluateTransitions,
1387
1456
  init_routing
1388
1457
  };
1389
- //# sourceMappingURL=chunk-BHZ4CKUS.mjs.map
1458
+ //# sourceMappingURL=chunk-PXFIALUH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/snapshot-store.ts","../../src/state-machine/states/routing.ts"],"sourcesContent":["/*\n * Internal snapshot store for incremental adoption of snapshot+scope execution.\n * Phase 0: journal only — no behavior change, used for future visibility work.\n */\n\nimport type { ReviewSummary } from './reviewer';\nimport type { EventTrigger } from './types/config';\n\nexport type ScopePath = Array<{ check: string; index: number }>;\n\nexport interface JournalEntry {\n commitId: number;\n sessionId: string;\n scope: ScopePath;\n checkId: string;\n event: EventTrigger | undefined;\n result: ReviewSummary & { output?: unknown; content?: string };\n}\n\nexport class ExecutionJournal {\n private commit = 0;\n private entries: JournalEntry[] = [];\n\n beginSnapshot(): number {\n return this.commit;\n }\n\n commitEntry(entry: {\n sessionId: string;\n scope: ScopePath;\n checkId: string;\n result: ReviewSummary & { output?: unknown; content?: string };\n event?: EventTrigger;\n }): JournalEntry {\n const committed: JournalEntry = {\n sessionId: entry.sessionId,\n scope: entry.scope,\n checkId: entry.checkId,\n result: entry.result,\n event: entry.event,\n commitId: ++this.commit,\n };\n this.entries.push(committed);\n return committed;\n }\n\n readVisible(sessionId: string, commitMax: number, event?: EventTrigger): JournalEntry[] {\n return this.entries.filter(\n e =>\n e.sessionId === sessionId && e.commitId <= commitMax && (event ? e.event === event : true)\n );\n }\n\n // Lightweight helpers for debugging/metrics\n size(): number {\n return this.entries.length;\n }\n}\n\nexport class ContextView {\n constructor(\n private journal: ExecutionJournal,\n private sessionId: string,\n private snapshotId: number,\n private scope: ScopePath,\n private event?: EventTrigger\n ) {}\n\n /** Return the nearest result for a check in this scope (exact item → ancestor → latest). */\n get(checkId: string): (ReviewSummary & { output?: unknown; content?: string }) | undefined {\n const visible = this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId);\n if (visible.length === 0) return undefined;\n\n // exact scope match: prefer the most recent commit for this scope\n const exactMatches = visible.filter(e => this.sameScope(e.scope, this.scope));\n if (exactMatches.length > 0) {\n return exactMatches[exactMatches.length - 1].result;\n }\n\n // nearest ancestor (shortest distance)\n let best: { entry: JournalEntry; dist: number } | undefined;\n for (const e of visible) {\n const dist = this.ancestorDistance(e.scope, this.scope);\n if (dist >= 0 && (best === undefined || dist < best.dist)) {\n best = { entry: e, dist };\n }\n }\n if (best) return best.entry.result;\n\n // fallback to latest committed result\n return visible[visible.length - 1]?.result;\n }\n\n /** Return an aggregate (raw) result – the shallowest scope for this check. */\n getRaw(checkId: string): (ReviewSummary & { output?: unknown; content?: string }) | undefined {\n const visible = this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId);\n if (visible.length === 0) return undefined;\n let shallow = visible[0];\n for (const e of visible) {\n if (e.scope.length < shallow.scope.length) shallow = e;\n }\n return shallow.result;\n }\n\n /** All results for a check up to this snapshot. */\n getHistory(checkId: string): Array<ReviewSummary & { output?: unknown; content?: string }> {\n return this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId)\n .map(e => e.result);\n }\n\n private sameScope(a: ScopePath, b: ScopePath): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i].check !== b[i].check || a[i].index !== b[i].index) return false;\n }\n return true;\n }\n\n // distance from ancestor to current; -1 if not ancestor\n private ancestorDistance(ancestor: ScopePath, current: ScopePath): number {\n if (ancestor.length > current.length) return -1;\n // Treat root scope ([]) as non-ancestor for unrelated branches\n if (ancestor.length === 0 && current.length > 0) return -1;\n for (let i = 0; i < ancestor.length; i++) {\n if (ancestor[i].check !== current[i].check || ancestor[i].index !== current[i].index)\n return -1;\n }\n return current.length - ancestor.length;\n }\n}\n","/**\n * Routing State Handler\n *\n * Responsibilities:\n * - Evaluate fail_if conditions after check execution\n * - Process on_success, on_fail, on_finish triggers\n * - Enqueue ForwardRunRequested events for goto\n * - Enqueue WaveRetry events for routing loops\n * - Transition back to WavePlanning or Completed\n *\n * M2: Core routing logic implementation\n */\n\nimport type { EngineContext, RunState, EngineState, EngineEvent } from '../../types/engine';\nimport type { ReviewSummary, ReviewIssue } from '../../reviewer';\nimport type { CheckConfig, OnFailConfig, TransitionRule } from '../../types/config';\nimport { logger } from '../../logger';\nimport { addEvent } from '../../telemetry/trace-helpers';\nimport { FailureConditionEvaluator } from '../../failure-condition-evaluator';\nimport { createSecureSandbox, compileAndRun } from '../../utils/sandbox';\nimport { MemoryStore } from '../../memory-store';\n\n/**\n * Check if any configured check depends (directly or via OR dependency) on the\n * given `checkId`. Used to decide whether a forEach parent has downstream\n * dependents, in which case its on_finish should defer to the LevelDispatch\n * post-children hook.\n */\n// hasDependents helper removed (unused)\n\n/**\n * Check if any dependent of `checkId` would execute with map fanout.\n * Used to decide whether a forEach parent's on_finish should be deferred to\n * the LevelDispatch post-children hook (only necessary when map-fanout children\n * will run per item).\n */\nfunction hasMapFanoutDependents(context: EngineContext, checkId: string): boolean {\n const checks = context.config.checks || {};\n const reduceProviders = new Set(['log', 'memory', 'script', 'workflow', 'noop']);\n\n for (const [cid, cfg] of Object.entries(checks)) {\n if (cid === checkId) continue;\n const rawDeps = (cfg as any).depends_on || [];\n const depList = Array.isArray(rawDeps) ? rawDeps : [rawDeps];\n // Does this check depend on our target?\n let depends = false;\n for (const dep of depList) {\n if (typeof dep !== 'string') continue;\n if (dep.includes('|')) {\n const opts = dep\n .split('|')\n .map(s => s.trim())\n .filter(Boolean);\n if (opts.includes(checkId)) {\n depends = true;\n break;\n }\n } else if (dep === checkId) {\n depends = true;\n break;\n }\n }\n if (!depends) continue;\n\n // Determine this dependent's fanout mode\n const explicit = (cfg as any).fanout as 'map' | 'reduce' | undefined;\n if (explicit === 'map') return true;\n if (explicit === 'reduce') continue;\n\n // Infer default based on provider type\n const providerType = context.checks[cid]?.providerType || (checks as any)[cid]?.type || '';\n const inferred: 'map' | 'reduce' = reduceProviders.has(providerType) ? 'reduce' : 'map';\n if (inferred === 'map') return true;\n }\n return false;\n}\n\n/** Classify failure type to inform retry policy mapping */\nfunction classifyFailure(result: ReviewSummary): 'none' | 'logical' | 'execution' {\n const issues = result?.issues || [];\n if (!issues || issues.length === 0) return 'none';\n // Heuristics:\n // - logical: fail_if, contract/guarantee_failed, explicit ruleIds ending with _fail_if\n // - execution: provider/command errors, forEach/execution_error, sandbox_runner_error\n let hasLogical = false;\n let hasExecution = false;\n for (const iss of issues) {\n const id = String((iss as any).ruleId || '');\n const msg = String((iss as any).message || '');\n if (\n id.endsWith('_fail_if') ||\n id.includes('contract/guarantee_failed') ||\n id.includes('contract/schema_validation_failed')\n )\n hasLogical = true;\n if (id.includes('/execution_error') || msg.includes('Command execution failed'))\n hasExecution = true;\n if (id.includes('forEach/execution_error') || msg.includes('sandbox_runner_error'))\n hasExecution = true;\n }\n if (hasLogical && !hasExecution) return 'logical';\n if (hasExecution && !hasLogical) return 'execution';\n // Mixed or unknown: treat as execution to avoid suppressing retries unexpectedly\n return hasExecution ? 'execution' : 'logical';\n}\n\nfunction getCriticality(context: EngineContext, checkId: string): CheckConfig['criticality'] {\n const cfg = context.config.checks?.[checkId];\n return (cfg && (cfg as any).criticality) || 'policy';\n}\n\n/**\n * Context for a check that just completed and needs routing evaluation\n */\ninterface RoutingContext {\n checkId: string;\n scope: Array<{ check: string; index: number }>;\n result: ReviewSummary;\n checkConfig: CheckConfig;\n success: boolean; // true if no fatal issues\n}\n\n/**\n * Create memory helpers for sandbox context\n */\nfunction createMemoryHelpers() {\n const memoryStore = MemoryStore.getInstance();\n return {\n get: (key: string, ns?: string) => memoryStore.get(key, ns),\n has: (key: string, ns?: string) => memoryStore.has(key, ns),\n getAll: (ns?: string) => memoryStore.getAll(ns),\n set: (key: string, value: unknown, ns?: string) => {\n const nsName = ns || memoryStore.getDefaultNamespace();\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (!data.has(nsName)) data.set(nsName, new Map());\n data.get(nsName)!.set(key, value);\n },\n clear: (ns?: string) => {\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (ns) data.delete(ns);\n else data.clear();\n },\n increment: (key: string, amount = 1, ns?: string) => {\n const nsName = ns || memoryStore.getDefaultNamespace();\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (!data.has(nsName)) data.set(nsName, new Map());\n const nsMap = data.get(nsName)!;\n const current = nsMap.get(key);\n const numCurrent = typeof current === 'number' ? current : 0;\n const newValue = numCurrent + amount;\n nsMap.set(key, newValue);\n return newValue;\n },\n };\n}\n\nfunction getHistoryLimit(): number | undefined {\n const raw = process.env.VISOR_TEST_HISTORY_LIMIT || process.env.VISOR_OUTPUT_HISTORY_LIMIT;\n if (!raw) return undefined;\n const n = parseInt(raw, 10);\n return Number.isFinite(n) && n > 0 ? n : undefined;\n}\n\ntype RoutingTrigger = 'on_success' | 'on_fail' | 'on_finish';\ntype RoutingAction = 'run' | 'goto' | 'retry';\ntype RoutingSource = 'run' | 'run_js' | 'goto' | 'goto_js' | 'transitions' | 'retry';\n\nfunction formatScopeLabel(scope: Array<{ check: string; index: number }> | undefined): string {\n if (!scope || scope.length === 0) return '';\n return scope.map(item => `${item.check}:${item.index}`).join('|');\n}\n\nfunction recordRoutingEvent(args: {\n checkId: string;\n trigger: RoutingTrigger;\n action: RoutingAction;\n target?: string;\n source?: RoutingSource;\n scope?: Array<{ check: string; index: number }>;\n gotoEvent?: string;\n}): void {\n const attrs: Record<string, unknown> = {\n check_id: args.checkId,\n trigger: args.trigger,\n action: args.action,\n };\n if (args.target) attrs.target = args.target;\n if (args.source) attrs.source = args.source;\n const scopeLabel = formatScopeLabel(args.scope);\n if (scopeLabel) attrs.scope = scopeLabel;\n if (args.gotoEvent) attrs.goto_event = args.gotoEvent;\n addEvent('visor.routing', attrs);\n}\n\n/**\n * Handle routing state - evaluate conditions and decide next actions\n * @returns true if execution was halted (caller should stop processing)\n */\nexport async function handleRouting(\n context: EngineContext,\n state: RunState,\n transition: (newState: EngineState) => void,\n emitEvent: (event: EngineEvent) => void,\n routingContext: RoutingContext\n): Promise<boolean> {\n const { checkId, scope, result, checkConfig, success } = routingContext;\n\n // Always log routing entry for debugging E2E expectations\n logger.info(`[Routing] Evaluating routing for check: ${checkId}, success: ${success}`);\n\n // Step 1: Evaluate fail_if and failure_conditions\n const failureResult = await evaluateFailIf(checkId, result, checkConfig, context, state);\n\n // Step 1.5: Check if we need to halt execution immediately\n if (failureResult.haltExecution) {\n logger.error(\n `[Routing] HALTING EXECUTION due to critical failure in ${checkId}: ${failureResult.haltMessage}`\n );\n\n // Add halt issue to result for reporting\n const haltIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_halt_execution`,\n message: `Execution halted: ${failureResult.haltMessage || 'Critical failure condition met'}`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), haltIssue];\n\n // Emit Shutdown event to stop the workflow\n emitEvent({\n type: 'Shutdown',\n error: {\n message: failureResult.haltMessage || `Execution halted by check ${checkId}`,\n name: 'HaltExecution',\n },\n });\n\n // Transition to Error state\n transition('Error');\n return true; // Signal that execution was halted\n }\n\n if (failureResult.failed) {\n if (context.debug) {\n logger.info(`[Routing] fail_if/failure_conditions triggered for ${checkId}`);\n }\n\n // Treat as failure for routing purposes\n await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);\n } else if (success) {\n // Step 2: Process on_success routing\n await processOnSuccess(checkId, scope, result, checkConfig, context, state, emitEvent);\n } else {\n // Step 3: Process on_fail routing\n await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);\n }\n\n // Step 4: on_finish\n // Process on_finish here for:\n // - non-forEach checks\n // - forEach parents that do NOT have map-fanout dependents\n // (reduce-only dependents don't need the post-children barrier)\n const shouldProcessOnFinishHere =\n !!checkConfig.on_finish &&\n (checkConfig.forEach !== true || !hasMapFanoutDependents(context, checkId));\n if (checkConfig.on_finish) {\n logger.info(\n `[Routing] on_finish decision for ${checkId}: forEach=${!!checkConfig.forEach}, processHere=${shouldProcessOnFinishHere}`\n );\n }\n if (shouldProcessOnFinishHere) {\n await processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent);\n }\n\n // Transition back to WavePlanning to process queued events\n transition('WavePlanning');\n return false; // Execution continues normally\n}\n\n/**\n * Process on_finish routing\n */\nasync function processOnFinish(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n const onFinish = checkConfig.on_finish;\n\n if (!onFinish) {\n return; // No on_finish configuration\n }\n\n // Log at info level so it's visible in test output\n logger.info(`Processing on_finish for ${checkId}`);\n let queuedForward = false;\n // Process on_finish.run\n if (onFinish.run && onFinish.run.length > 0) {\n // Check if current check is a forEach parent with items\n const currentCheckIsForEach = checkConfig.forEach === true;\n const forEachItems = currentCheckIsForEach ? (result as any).forEachItems : undefined;\n const hasForEachItems = Array.isArray(forEachItems) && forEachItems.length > 0;\n\n for (const targetCheck of onFinish.run) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_finish', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_finish.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`\n );\n }\n\n // If current check has forEach items and target is map fanout, emit one event per item\n if (fanoutMode === 'map' && hasForEachItems) {\n // Map fanout: emit one ForwardRunRequested per forEach item\n for (let itemIndex = 0; itemIndex < forEachItems!.length; itemIndex++) {\n // Increment loop count for each item\n state.routingLoopCount++;\n\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n });\n queuedForward = true;\n }\n } else {\n // Reduce fanout (or no forEach context): emit with empty scope once\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: [],\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: [],\n origin: 'run',\n });\n queuedForward = true;\n }\n }\n }\n\n // Process on_finish.run_js\n if (onFinish.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onFinish.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const targetCheck of dynamicTargets) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_finish', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_finish.run_js: scheduling ${targetCheck}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n });\n queuedForward = true;\n }\n }\n\n // Declarative transitions (override goto/goto_js when present)\n const finishTransTarget = await evaluateTransitions(\n onFinish.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (finishTransTarget !== undefined) {\n if (finishTransTarget) {\n if (checkLoopBudget(context, state, 'on_finish', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'goto',\n target: finishTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: finishTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: finishTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: finishTransTarget.goto_event,\n });\n }\n return; // transitions override goto/goto_js\n }\n\n // Process on_finish.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onFinish.goto_js,\n onFinish.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_finish', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_finish.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'goto',\n target: gotoTarget,\n source: onFinish.goto_js ? 'goto_js' : 'goto',\n scope,\n });\n // Enqueue forward run event\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n\n // If we scheduled any forward-run targets via on_finish, request a wave retry so\n // dependent checks (with if conditions) can re-evaluate after the forward-run completes.\n // Guard: only enqueue once per originating check per wave to avoid loops.\n if (queuedForward) {\n const guardKey = `waveRetry:on_finish:${checkId}:wave:${state.wave}`;\n if (!(state as any).forwardRunGuards?.has(guardKey)) {\n (state as any).forwardRunGuards?.add(guardKey);\n emitEvent({ type: 'WaveRetry', reason: 'on_finish' });\n }\n }\n}\n\n/**\n * Result of evaluating failure conditions\n */\ninterface FailureEvaluationResult {\n /** Whether any failure condition was triggered */\n failed: boolean;\n /** Whether execution should halt immediately */\n haltExecution: boolean;\n /** Message describing the halt reason (if haltExecution is true) */\n haltMessage?: string;\n}\n\n/**\n * Evaluate fail_if and failure_conditions for a check\n */\n// Returns { failed, haltExecution } to indicate if check failed and if execution should halt.\n// Global fail_if records an issue for summary/reporting but MUST NOT gate routing.\n// failure_conditions with halt_execution: true will trigger workflow halt.\nasync function evaluateFailIf(\n checkId: string,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState\n): Promise<FailureEvaluationResult> {\n const config = context.config;\n\n // Check for fail_if at global or check level\n const globalFailIf = config.fail_if;\n const checkFailIf = checkConfig.fail_if;\n const globalFailureConditions = config.failure_conditions;\n const checkFailureConditions = checkConfig.failure_conditions;\n\n if (!globalFailIf && !checkFailIf && !globalFailureConditions && !checkFailureConditions) {\n return { failed: false, haltExecution: false }; // No failure conditions\n }\n\n const evaluator = new FailureConditionEvaluator();\n\n // Build outputs record from state\n const outputsRecord: Record<string, ReviewSummary> = {};\n for (const [key] of state.stats.entries()) {\n // Try to get the actual result from context.journal if available\n try {\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n context.event\n );\n const journalResult = contextView.get(key);\n if (journalResult) {\n outputsRecord[key] = journalResult as ReviewSummary;\n }\n } catch {\n // Fallback to empty result\n outputsRecord[key] = { issues: [] };\n }\n }\n\n const checkSchema = typeof checkConfig.schema === 'object' ? 'custom' : checkConfig.schema || '';\n const checkGroup = checkConfig.group || '';\n\n let anyFailed = false;\n let shouldHalt = false;\n let haltMessage: string | undefined;\n\n // Evaluate global fail_if (non-gating)\n if (globalFailIf) {\n try {\n const failed = await evaluator.evaluateSimpleCondition(\n checkId,\n checkSchema,\n checkGroup,\n result,\n globalFailIf,\n outputsRecord\n );\n\n if (failed) {\n logger.warn(`[Routing] Global fail_if triggered for ${checkId}: ${globalFailIf}`);\n\n // Add fail_if issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: 'global_fail_if',\n message: `Global failure condition met: ${globalFailIf}`,\n severity: 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n // IMPORTANT: do not gate routing on global fail_if\n // This condition contributes to overall run status but should not\n // block dependents from executing when the producing check succeeded.\n // Continue evaluating check-level fail_if below.\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating global fail_if: ${msg}`);\n }\n }\n\n // Evaluate check-specific fail_if\n if (checkFailIf) {\n try {\n const failed = await evaluator.evaluateSimpleCondition(\n checkId,\n checkSchema,\n checkGroup,\n result,\n checkFailIf,\n outputsRecord\n );\n\n if (failed) {\n logger.warn(`[Routing] Check fail_if triggered for ${checkId}: ${checkFailIf}`);\n\n // Add fail_if issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_fail_if`,\n message: `Check failure condition met: ${checkFailIf}`,\n severity: 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n anyFailed = true;\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating check fail_if: ${msg}`);\n }\n }\n\n // Evaluate failure_conditions (both global and check-level)\n // These support halt_execution: true\n if (globalFailureConditions || checkFailureConditions) {\n try {\n const conditionResults = await evaluator.evaluateConditions(\n checkId,\n checkSchema,\n checkGroup,\n result,\n globalFailureConditions,\n checkFailureConditions,\n outputsRecord\n );\n\n // Check for triggered conditions\n for (const condResult of conditionResults) {\n if (condResult.failed) {\n logger.warn(\n `[Routing] Failure condition '${condResult.conditionName}' triggered for ${checkId}: ${condResult.expression}`\n );\n\n // Add issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_${condResult.conditionName}`,\n message: condResult.message || `Failure condition met: ${condResult.expression}`,\n severity: condResult.severity || 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n anyFailed = true;\n\n // Check if this condition requires halting execution\n if (condResult.haltExecution) {\n shouldHalt = true;\n haltMessage =\n condResult.message ||\n `Execution halted: condition '${condResult.conditionName}' triggered`;\n logger.error(\n `[Routing] HALT EXECUTION triggered by '${condResult.conditionName}' for ${checkId}`\n );\n }\n }\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating failure_conditions: ${msg}`);\n }\n }\n\n return { failed: anyFailed, haltExecution: shouldHalt, haltMessage };\n}\n\n/**\n * Check if routing loop budget is exceeded\n */\nexport function checkLoopBudget(\n context: EngineContext,\n state: RunState,\n origin: 'on_success' | 'on_fail' | 'on_finish',\n action: 'run' | 'goto'\n): boolean {\n const maxLoops = context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS;\n\n if (state.routingLoopCount >= maxLoops) {\n const msg = `Routing loop budget exceeded (max_loops=${maxLoops}) during ${origin} ${action}`;\n logger.error(`[Routing] ${msg}`);\n return true; // Budget exceeded\n }\n\n return false; // Budget OK\n}\n\n/**\n * Process on_success routing\n */\nasync function processOnSuccess(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n const onSuccess = checkConfig.on_success;\n\n if (!onSuccess) {\n return; // No on_success configuration\n }\n\n if (context.debug) {\n logger.info(`[Routing] Processing on_success for ${checkId}`);\n }\n\n // Process on_success.run\n if (onSuccess.run && onSuccess.run.length > 0) {\n // Detect forEach context based on the actual result (aggregated map execution)\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n for (const targetCheck of onSuccess.run) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_success', 'run')) {\n // Add error issue to result\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return; // Stop processing\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_success.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`\n );\n }\n\n // If current check has forEach items and target is map fanout, emit one event per item\n if (fanoutMode === 'map' && hasForEachItems) {\n // Map fanout: emit one ForwardRunRequested per forEach item\n for (let itemIndex = 0; itemIndex < resForEachItems!.length; itemIndex++) {\n // Increment loop count for each item\n state.routingLoopCount++;\n\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n });\n }\n } else {\n // Reduce fanout (or no forEach context): emit with empty scope once\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run',\n });\n }\n }\n }\n\n // Process on_success.run_js\n if (onSuccess.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onSuccess.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const targetCheck of dynamicTargets) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_success', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_success.run_js: scheduling ${targetCheck}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n });\n }\n }\n\n // Declarative transitions for on_success (override goto/goto_js when present)\n const successTransTarget = await evaluateTransitions(\n onSuccess.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (successTransTarget !== undefined) {\n if (successTransTarget) {\n if (checkLoopBudget(context, state, 'on_success', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'goto',\n target: successTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: successTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: successTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: successTransTarget.goto_event,\n });\n state.flags.forwardRunRequested = true;\n }\n return;\n }\n\n // Process on_success.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onSuccess.goto_js,\n onSuccess.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_success', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_success.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'goto',\n target: gotoTarget,\n source: onSuccess.goto_js ? 'goto_js' : 'goto',\n scope,\n gotoEvent: onSuccess.goto_event,\n });\n // Enqueue forward run event with optional event override\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n gotoEvent: onSuccess.goto_event,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n}\n\n/**\n * Process on_fail routing\n */\nasync function processOnFail(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n // Merge defaults with check-specific on_fail\n const defaults = context.config.routing?.defaults?.on_fail || {};\n const onFail: OnFailConfig | undefined = checkConfig.on_fail\n ? { ...defaults, ...checkConfig.on_fail }\n : undefined;\n\n if (!onFail) {\n return; // No on_fail configuration\n }\n\n if (context.debug) {\n logger.info(`[Routing] Processing on_fail for ${checkId}`);\n }\n\n // Process on_fail.run\n if (onFail.run && onFail.run.length > 0) {\n // Detect forEach context based on the actual aggregated result\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n for (const targetCheck of onFail.run) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_fail', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_fail.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`\n );\n }\n\n // If current check ran in forEach context, schedule remediation per item\n if (hasForEachItems) {\n for (let itemIndex = 0; itemIndex < resForEachItems!.length; itemIndex++) {\n const itemOut = resForEachItems![itemIndex] as any;\n // Only remediate failed iterations if __failed is present; otherwise run for all\n if (\n itemOut &&\n typeof itemOut === 'object' &&\n itemOut.__failed !== true &&\n fanoutMode !== 'map'\n ) {\n // For reduce targets, skip successful iterations to avoid redundant runs\n continue;\n }\n\n state.routingLoopCount++;\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n sourceCheck: checkId, // The failed check that triggered on_fail.run\n });\n }\n } else {\n // No forEach context: preserve current scope (if any)\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run',\n sourceCheck: checkId, // The failed check that triggered on_fail.run\n });\n }\n }\n }\n\n // Process on_fail.run_js\n if (onFail.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onFail.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const targetCheck of dynamicTargets) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_fail', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_fail.run_js: scheduling ${targetCheck}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n sourceCheck: checkId, // The failed check that triggered on_fail.run_js\n });\n }\n }\n\n // Process on_fail.retry (schedule retry of the current check)\n if (onFail.retry && typeof onFail.retry.max === 'number' && onFail.retry.max > 0) {\n // Criticality mapping: for 'external' and 'internal', avoid automatic\n // retries for logical failures (fail_if/guarantee violations).\n const crit = getCriticality(context, checkId);\n const failureKind = classifyFailure(result);\n if ((crit === 'external' || crit === 'internal') && failureKind === 'logical') {\n if (context.debug) {\n logger.info(\n `[Routing] on_fail.retry suppressed for ${checkId} (criticality=${crit}, failure=logical)`\n );\n }\n // Skip retry scheduling\n } else {\n const max = Math.max(0, onFail.retry.max || 0);\n // Initialize retry attempt map on state\n if (!(state as any).retryAttempts) (state as any).retryAttempts = new Map<string, number>();\n const attemptsMap: Map<string, number> = (state as any).retryAttempts;\n\n const makeKey = (sc: Array<{ check: string; index: number }> | undefined) => {\n const keyScope = sc && sc.length > 0 ? JSON.stringify(sc) : 'root';\n return `${checkId}::${keyScope}`;\n };\n\n const scheduleRetryForScope = (sc: Array<{ check: string; index: number }> | undefined) => {\n const key = makeKey(sc);\n const used = attemptsMap.get(key) || 0;\n if (used >= max) return; // budget exhausted\n attemptsMap.set(key, used + 1);\n\n // Increment loop count and schedule forward run for the same check\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'retry',\n source: 'retry',\n scope: sc || [],\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: checkId,\n scope: sc || [],\n origin: 'run',\n });\n };\n\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n if (hasForEachItems) {\n for (let i = 0; i < resForEachItems!.length; i++) {\n const itemOut = resForEachItems![i] as any;\n // Only retry failed iterations (marked by __failed)\n if (itemOut && typeof itemOut === 'object' && itemOut.__failed === true) {\n const sc: Array<{ check: string; index: number }> = [{ check: checkId, index: i }];\n scheduleRetryForScope(sc);\n }\n }\n } else {\n scheduleRetryForScope(scope);\n }\n\n // Note: backoff.delay_ms and mode are intentionally not awaited here; the\n // state-machine processes retries as subsequent waves. If needed later, we\n // can insert a timed wait in the orchestrator layer.\n }\n }\n\n // Declarative transitions for on_fail (override goto/goto_js when present)\n const failTransTarget = await evaluateTransitions(\n onFail.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (failTransTarget !== undefined) {\n if (failTransTarget) {\n if (checkLoopBudget(context, state, 'on_fail', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_fail goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'goto',\n target: failTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: failTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: failTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: failTransTarget.goto_event,\n });\n state.flags.forwardRunRequested = true;\n }\n return;\n }\n\n // Process on_fail.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onFail.goto_js,\n onFail.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_fail', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_fail.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'goto',\n target: gotoTarget,\n source: onFail.goto_js ? 'goto_js' : 'goto',\n scope,\n gotoEvent: onFail.goto_event,\n });\n // Enqueue forward run event with optional event override\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n gotoEvent: onFail.goto_event,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n}\n\n/**\n * Evaluate run_js expression to get dynamic check targets\n */\nasync function evaluateRunJs(\n runJs: string,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<string[]> {\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n context.event\n );\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n\n // Get all visible journal entries to build complete history\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, context.event);\n const uniqueCheckIds = new Set(allEntries.map(e => e.checkId));\n\n for (const checkIdFromJournal of uniqueCheckIds) {\n try {\n // Get current output for this check\n const journalResult = contextView.get(checkIdFromJournal);\n if (journalResult) {\n // Prefer the output field if present, otherwise use the full result\n outputsRecord[checkIdFromJournal] =\n journalResult.output !== undefined ? journalResult.output : journalResult;\n }\n } catch {\n outputsRecord[checkIdFromJournal] = { issues: [] };\n }\n\n // Build history for this check\n try {\n const history = contextView.getHistory(checkIdFromJournal);\n if (history && history.length > 0) {\n const trimmed =\n historyLimit && history.length > historyLimit\n ? history.slice(history.length - historyLimit)\n : history;\n // Extract outputs from history (prefer output field if available)\n outputsHistory[checkIdFromJournal] = trimmed.map((r: any) =>\n r.output !== undefined ? r.output : r\n );\n }\n } catch {\n // Ignore history errors\n }\n }\n\n // Add history as a property on outputs object for convenient access\n outputsRecord.history = outputsHistory;\n\n // Compute minimal forEach metadata for run_js parity\n let forEachMeta: any = undefined;\n try {\n const hist = outputsHistory[checkId] || [];\n const lastArr = (hist as any[])\n .slice()\n .reverse()\n .find((x: any) => Array.isArray(x));\n if (checkConfig.forEach === true && Array.isArray(lastArr)) {\n forEachMeta = {\n is_parent: true,\n last_wave_size: lastArr.length,\n last_items: lastArr,\n };\n }\n } catch {}\n\n const scopeObj: any = {\n step: {\n id: checkId,\n tags: checkConfig.tags || [],\n group: checkConfig.group,\n },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: {\n name: context.event || 'manual',\n },\n forEach: forEachMeta,\n };\n\n const code = `\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const forEach = scope.forEach;\n const log = (...args) => console.log('🔍 Debug:', ...args);\n const __fn = () => {\n ${runJs}\n };\n const __res = __fn();\n return Array.isArray(__res) ? __res.filter(x => typeof x === 'string' && x) : [];\n `;\n\n try {\n const evalResult = compileAndRun<string[]>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: false }\n );\n return Array.isArray(evalResult) ? evalResult.filter(Boolean) : [];\n } catch (_e) {\n // Fallback to VM for modern syntax used inside run_js\n try {\n const vm = require('node:vm');\n const context = vm.createContext({ scope: scopeObj, console: { log: () => {} } });\n const src = `(() => { ${runJs}\\n })()`;\n const val = new vm.Script(src).runInContext(context, { timeout: 100 });\n return Array.isArray(val) ? val.filter((x: any) => typeof x === 'string' && x) : [];\n } catch (_vmErr) {\n return [];\n }\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating run_js: ${msg}`);\n return [];\n }\n}\n\n/**\n * Evaluate goto_js or return static goto target\n */\nexport async function evaluateGoto(\n gotoJs: string | undefined,\n gotoStatic: string | undefined,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<string | null> {\n // Evaluate goto_js first\n if (gotoJs) {\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history from the full session snapshot.\n // Do not filter by event here — on_finish (especially forEach post-children) may\n // need to see results committed under different event triggers within the same run.\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n undefined\n );\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n\n // Get all visible journal entries to build complete history\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, undefined);\n const uniqueCheckIds = new Set(allEntries.map(e => e.checkId));\n\n for (const checkIdFromJournal of uniqueCheckIds) {\n try {\n // Get current output for this check\n const journalResult = contextView.get(checkIdFromJournal);\n if (journalResult) {\n // Prefer the output field if present, otherwise use the full result\n outputsRecord[checkIdFromJournal] =\n journalResult.output !== undefined ? journalResult.output : journalResult;\n }\n } catch {\n outputsRecord[checkIdFromJournal] = { issues: [] };\n }\n\n // Build history for this check\n try {\n const history = contextView.getHistory(checkIdFromJournal);\n if (history && history.length > 0) {\n const trimmed =\n historyLimit && history.length > historyLimit\n ? history.slice(history.length - historyLimit)\n : history;\n // Extract outputs from history (prefer output field if available)\n outputsHistory[checkIdFromJournal] = trimmed.map((r: any) =>\n r.output !== undefined ? r.output : r\n );\n }\n } catch {\n // Ignore history errors\n }\n }\n\n // Add history as a property on outputs object for convenient access\n outputsRecord.history = outputsHistory;\n\n // Compute minimal forEach metadata for convenience in goto_js\n // - last_wave_size: number of items in the latest root-scope array output\n // - last_items: the latest array output itself (if available)\n let forEachMeta: any = undefined;\n try {\n const hist = outputsHistory[checkId] || [];\n const lastArr = (hist as any[])\n .slice()\n .reverse()\n .find((x: any) => Array.isArray(x));\n if (checkConfig.forEach === true && Array.isArray(lastArr)) {\n forEachMeta = {\n is_parent: true,\n last_wave_size: lastArr.length,\n last_items: lastArr,\n };\n }\n } catch {}\n\n const scopeObj: any = {\n step: {\n id: checkId,\n tags: checkConfig.tags || [],\n group: checkConfig.group,\n },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: {\n name: context.event || 'manual',\n },\n forEach: forEachMeta,\n };\n\n // Debug: Log outputs_history\n if (context.debug) {\n logger.info(\n `[Routing] evaluateGoto: checkId=${checkId}, outputs_history keys=${Object.keys(outputsHistory).join(',')}`\n );\n for (const [key, values] of Object.entries(outputsHistory)) {\n logger.info(`[Routing] ${key}: ${values.length} items`);\n }\n }\n\n const code = `\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const forEach = scope.forEach;\n const log = (...args) => console.log('🔍 Debug:', ...args);\n ${gotoJs}\n `;\n\n try {\n const evalResult = compileAndRun<string | null>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: true }\n );\n\n if (context.debug) {\n logger.info(`[Routing] evaluateGoto result: ${evalResult}`);\n }\n\n if (typeof evalResult === 'string' && evalResult) {\n return evalResult;\n }\n } catch (_e) {\n // Fallback to VM for modern syntax in goto_js\n try {\n const vm = require('node:vm');\n const contextObj = {\n step: scopeObj.step,\n outputs: scopeObj.outputs,\n outputs_history: scopeObj.outputs_history,\n output: scopeObj.output,\n memory: scopeObj.memory,\n event: scopeObj.event,\n forEach: (scopeObj as any).forEach,\n };\n const vmctx = vm.createContext(contextObj);\n const src = `(() => { ${gotoJs}\\n })()`;\n const res = new vm.Script(src).runInContext(vmctx, { timeout: 100 });\n if (typeof res === 'string' && res) return res;\n } catch (_vmErr) {\n // ignore; fall through to static goto\n }\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating goto_js: ${msg}`);\n\n // Fall back to static goto if available\n if (gotoStatic) {\n logger.info(`[Routing] Falling back to static goto: ${gotoStatic}`);\n return gotoStatic;\n }\n }\n }\n\n // Return static goto\n return gotoStatic || null;\n}\n// Default values (used only when config is absent)\nconst DEFAULT_MAX_LOOPS = 10;\n\n/**\n * Evaluate declarative transitions. Returns:\n * - { to, goto_event } when a rule matches,\n * - null (explicit) when a rule matches with to=null,\n * - undefined when no rule matched or transitions is empty.\n */\nexport async function evaluateTransitions(\n transitions: TransitionRule[] | undefined,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<\n { to: string; goto_event?: import('../../types/config').EventTrigger } | null | undefined\n> {\n if (!transitions || transitions.length === 0) return undefined;\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history from the full session snapshot\n const snapshotId = context.journal.beginSnapshot();\n const ContextView = (require('../../snapshot-store') as any).ContextView;\n const view = new ContextView(context.journal, context.sessionId, snapshotId, [], undefined);\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, undefined);\n const uniqueCheckIds = new Set(allEntries.map((e: any) => e.checkId));\n for (const cid of uniqueCheckIds) {\n try {\n const jr = view.get(cid);\n if (jr) outputsRecord[cid] = jr.output !== undefined ? jr.output : jr;\n } catch {}\n try {\n const hist = view.getHistory(cid);\n if (hist && hist.length > 0) {\n const trimmed =\n historyLimit && hist.length > historyLimit\n ? hist.slice(hist.length - historyLimit)\n : hist;\n outputsHistory[cid] = trimmed.map((r: any) => (r.output !== undefined ? r.output : r));\n }\n } catch {}\n }\n outputsRecord.history = outputsHistory;\n\n const scopeObj: any = {\n step: { id: checkId, tags: checkConfig.tags || [], group: checkConfig.group },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: { name: context.event || 'manual' },\n };\n\n for (const rule of transitions) {\n const helpers = `\n const any = (arr, pred) => Array.isArray(arr) && arr.some(x => pred(x));\n const all = (arr, pred) => Array.isArray(arr) && arr.every(x => pred(x));\n const none = (arr, pred) => Array.isArray(arr) && !arr.some(x => pred(x));\n const count = (arr, pred) => Array.isArray(arr) ? arr.filter(x => pred(x)).length : 0;\n `;\n // Mirror the variable exposure pattern used in goto_js/run_js so that\n // `when:` expressions can reference `outputs`, `outputs_history`, `event`, etc.\n const code = `\n ${helpers}\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const __eval = () => { return (${rule.when}); };\n return __eval();\n `;\n let matched: boolean | undefined;\n try {\n matched = compileAndRun<boolean>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: false }\n );\n } catch (_e) {\n // Fallback: Node VM for modern syntax like optional chaining and ??\n try {\n const vm = require('node:vm');\n const helpersFns = {\n any: (arr: any[], pred: (x: any) => boolean) => Array.isArray(arr) && arr.some(pred),\n all: (arr: any[], pred: (x: any) => boolean) => Array.isArray(arr) && arr.every(pred),\n none: (arr: any[], pred: (x: any) => boolean) => Array.isArray(arr) && !arr.some(pred),\n count: (arr: any[], pred: (x: any) => boolean) =>\n Array.isArray(arr) ? arr.filter(pred).length : 0,\n };\n const context = vm.createContext({\n step: scopeObj.step,\n outputs: scopeObj.outputs,\n outputs_history: scopeObj.outputs_history,\n output: scopeObj.output,\n memory: scopeObj.memory,\n event: scopeObj.event,\n ...helpersFns,\n });\n const res = new vm.Script(`(${rule.when})`).runInContext(context, { timeout: 50 });\n matched = !!res;\n } catch (_vmErr) {\n matched = false;\n }\n }\n if (matched) {\n if (rule.to === null) return null;\n if (typeof rule.to === 'string' && rule.to.length > 0) {\n return { to: rule.to, goto_event: (rule as any).goto_event };\n }\n return null;\n }\n }\n return undefined;\n } catch (err) {\n logger.error(\n `[Routing] Error evaluating transitions: ${err instanceof Error ? err.message : String(err)}`\n );\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmBa,kBAwCA;AA3Db;AAAA;AAAA;AAmBO,IAAM,mBAAN,MAAuB;AAAA,MACpB,SAAS;AAAA,MACT,UAA0B,CAAC;AAAA,MAEnC,gBAAwB;AACtB,eAAO,KAAK;AAAA,MACd;AAAA,MAEA,YAAY,OAMK;AACf,cAAM,YAA0B;AAAA,UAC9B,WAAW,MAAM;AAAA,UACjB,OAAO,MAAM;AAAA,UACb,SAAS,MAAM;AAAA,UACf,QAAQ,MAAM;AAAA,UACd,OAAO,MAAM;AAAA,UACb,UAAU,EAAE,KAAK;AAAA,QACnB;AACA,aAAK,QAAQ,KAAK,SAAS;AAC3B,eAAO;AAAA,MACT;AAAA,MAEA,YAAY,WAAmB,WAAmB,OAAsC;AACtF,eAAO,KAAK,QAAQ;AAAA,UAClB,OACE,EAAE,cAAc,aAAa,EAAE,YAAY,cAAc,QAAQ,EAAE,UAAU,QAAQ;AAAA,QACzF;AAAA,MACF;AAAA;AAAA,MAGA,OAAe;AACb,eAAO,KAAK,QAAQ;AAAA,MACtB;AAAA,IACF;AAEO,IAAM,cAAN,MAAkB;AAAA,MACvB,YACU,SACA,WACA,YACA,OACA,OACR;AALQ;AACA;AACA;AACA;AACA;AAAA,MACP;AAAA;AAAA,MAGH,IAAI,SAAuF;AACzF,cAAM,UAAU,KAAK,QAClB,YAAY,KAAK,WAAW,KAAK,YAAY,KAAK,KAAK,EACvD,OAAO,OAAK,EAAE,YAAY,OAAO;AACpC,YAAI,QAAQ,WAAW,EAAG,QAAO;AAGjC,cAAM,eAAe,QAAQ,OAAO,OAAK,KAAK,UAAU,EAAE,OAAO,KAAK,KAAK,CAAC;AAC5E,YAAI,aAAa,SAAS,GAAG;AAC3B,iBAAO,aAAa,aAAa,S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AAA,YAChB,GAAG;AAAA,UACL,CAAC;AACD,gBAAM,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,IAAI,GAAG,EAAE,aAAaA,UAAS,EAAE,SAAS,GAAG,CAAC;AACjF,oBAAU,CAAC,CAAC;AAAA,QACd,SAAS,QAAQ;AACf,oBAAU;AAAA,QACZ;AAAA,MACF;AACA,UAAI,SAAS;AACX,YAAI,KAAK,OAAO,KAAM,QAAO;AAC7B,YAAI,OAAO,KAAK,OAAO,YAAY,KAAK,GAAG,SAAS,GAAG;AACrD,iBAAO,EAAE,IAAI,KAAK,IAAI,YAAa,KAAa,WAAW;AAAA,QAC7D;AACA,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,2CAA2C,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,IAC7F;AACA,WAAO;AAAA,EACT;AACF;AA1wDA,IA0oDM;AA1oDN;AAAA;AAgBA;AACA;AACA;AACA;AACA;AAsnDA,IAAM,oBAAoB;AAAA;AAAA;","names":["context","ContextView"]}
@@ -862,7 +862,7 @@ var init_config_schema = __esm({
862
862
  },
863
863
  timeout: {
864
864
  type: "number",
865
- description: "Timeout in seconds for command execution (default: 60)"
865
+ description: "Timeout in milliseconds for command execution (default: 60000, i.e., 60 seconds)"
866
866
  },
867
867
  depends_on: {
868
868
  anyOf: [
@@ -1116,7 +1116,7 @@ var init_config_schema = __esm({
1116
1116
  description: "Arguments/inputs for the workflow"
1117
1117
  },
1118
1118
  overrides: {
1119
- $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156%3E%3E",
1119
+ $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182%3E%3E",
1120
1120
  description: "Override specific step configurations in the workflow"
1121
1121
  },
1122
1122
  output_mapping: {
@@ -1132,7 +1132,7 @@ var init_config_schema = __esm({
1132
1132
  description: "Config file path - alternative to workflow ID (loads a Visor config file as workflow)"
1133
1133
  },
1134
1134
  workflow_overrides: {
1135
- $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156%3E%3E",
1135
+ $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182%3E%3E",
1136
1136
  description: "Alias for overrides - workflow step overrides (backward compatibility)"
1137
1137
  },
1138
1138
  ref: {
@@ -1762,7 +1762,7 @@ var init_config_schema = __esm({
1762
1762
  description: "Custom output name (defaults to workflow name)"
1763
1763
  },
1764
1764
  overrides: {
1765
- $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156%3E%3E",
1765
+ $ref: "#/definitions/Record%3Cstring%2CPartial%3Cinterface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182%3E%3E",
1766
1766
  description: "Step overrides"
1767
1767
  },
1768
1768
  output_mapping: {
@@ -1777,13 +1777,13 @@ var init_config_schema = __esm({
1777
1777
  "^x-": {}
1778
1778
  }
1779
1779
  },
1780
- "Record<string,Partial<interface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156>>": {
1780
+ "Record<string,Partial<interface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182>>": {
1781
1781
  type: "object",
1782
1782
  additionalProperties: {
1783
- $ref: "#/definitions/Partial%3Cinterface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156%3E"
1783
+ $ref: "#/definitions/Partial%3Cinterface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182%3E"
1784
1784
  }
1785
1785
  },
1786
- "Partial<interface-src_types_config.ts-11359-23556-src_types_config.ts-0-41156>": {
1786
+ "Partial<interface-src_types_config.ts-11359-23582-src_types_config.ts-0-41182>": {
1787
1787
  type: "object",
1788
1788
  additionalProperties: false
1789
1789
  },
@@ -2768,14 +2768,37 @@ var init_config = __esm({
2768
2768
  * Convert a workflow definition file to a visor config
2769
2769
  * When a workflow YAML is run standalone, register the workflow and use its tests as checks
2770
2770
  */
2771
- async convertWorkflowToConfig(workflowData, _basePath) {
2771
+ async convertWorkflowToConfig(workflowData, basePath) {
2772
2772
  const { WorkflowRegistry } = await import("./workflow-registry-6LZKCWHP.mjs");
2773
2773
  const registry = WorkflowRegistry.getInstance();
2774
2774
  const workflowId = workflowData.id;
2775
2775
  logger.info(`Detected standalone workflow file: ${workflowId}`);
2776
+ if (workflowData.imports && Array.isArray(workflowData.imports)) {
2777
+ for (const source of workflowData.imports) {
2778
+ try {
2779
+ const results = await registry.import(source, { basePath, validate: true });
2780
+ for (const result2 of results) {
2781
+ if (!result2.valid && result2.errors) {
2782
+ const errors = result2.errors.map((e) => ` ${e.path}: ${e.message}`).join("\n");
2783
+ throw new Error(`Failed to import workflow from '${source}':
2784
+ ${errors}`);
2785
+ }
2786
+ }
2787
+ logger.info(`Imported workflows from: ${source}`);
2788
+ } catch (err) {
2789
+ const errMsg = err instanceof Error ? err.message : String(err);
2790
+ if (errMsg.includes("already exists")) {
2791
+ logger.debug(`Workflow from '${source}' already imported, skipping`);
2792
+ } else {
2793
+ throw err;
2794
+ }
2795
+ }
2796
+ }
2797
+ }
2776
2798
  const tests = workflowData.tests || {};
2777
2799
  const workflowDefinition = { ...workflowData };
2778
2800
  delete workflowDefinition.tests;
2801
+ delete workflowDefinition.imports;
2779
2802
  const result = registry.register(workflowDefinition, "standalone", { override: true });
2780
2803
  if (!result.valid && result.errors) {
2781
2804
  const errors = result.errors.map((e) => ` ${e.path}: ${e.message}`).join("\n");
@@ -3565,4 +3588,4 @@ export {
3565
3588
  config_exports,
3566
3589
  init_config
3567
3590
  };
3568
- //# sourceMappingURL=chunk-PVITVJ6J.mjs.map
3591
+ //# sourceMappingURL=chunk-RTKJXNZS.mjs.map