@probelabs/visor 0.1.106 → 0.1.107

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 (450) hide show
  1. package/README.md +65 -2
  2. package/action.yml +1 -1
  3. package/defaults/code-refiner.yaml +114 -0
  4. package/defaults/{.visor.yaml → code-review.yaml} +35 -226
  5. package/defaults/override.yaml +52 -0
  6. package/defaults/task-refinement.yaml +620 -0
  7. package/defaults/visor.tests.yaml +674 -0
  8. package/defaults/visor.yaml +482 -0
  9. package/dist/663.index.js +2 -3
  10. package/dist/80.index.js +2 -3
  11. package/dist/action-cli-bridge.d.ts +11 -82
  12. package/dist/action-cli-bridge.d.ts.map +1 -1
  13. package/dist/ai-review-service.d.ts +15 -0
  14. package/dist/ai-review-service.d.ts.map +1 -1
  15. package/dist/check-execution-engine.d.ts +19 -331
  16. package/dist/check-execution-engine.d.ts.map +1 -1
  17. package/dist/cli-main.d.ts.map +1 -1
  18. package/dist/cli.d.ts +0 -1
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/config.d.ts +16 -0
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/cron-scheduler.d.ts +3 -3
  23. package/dist/cron-scheduler.d.ts.map +1 -1
  24. package/dist/debug-visualizer/ws-server.d.ts.map +1 -1
  25. package/dist/defaults/code-refiner.yaml +114 -0
  26. package/dist/defaults/{.visor.yaml → code-review.yaml} +35 -226
  27. package/dist/defaults/override.yaml +52 -0
  28. package/dist/defaults/task-refinement.yaml +620 -0
  29. package/dist/defaults/visor.tests.yaml +674 -0
  30. package/dist/defaults/visor.yaml +482 -0
  31. package/dist/docs/DEPLOYMENT.md +118 -0
  32. package/dist/docs/GITHUB_CHECKS.md +280 -0
  33. package/dist/docs/NPM_USAGE.md +208 -0
  34. package/dist/docs/action-reference.md +19 -0
  35. package/dist/docs/advanced-ai.md +178 -0
  36. package/dist/docs/ai-configuration.md +468 -0
  37. package/dist/docs/author-permissions.md +610 -0
  38. package/dist/docs/ci-cli-mode.md +34 -0
  39. package/dist/docs/claude-code.md +74 -0
  40. package/dist/docs/command-provider.md +559 -0
  41. package/dist/docs/commands.md +8 -0
  42. package/dist/docs/configuration.md +303 -0
  43. package/dist/docs/custom-tools.md +424 -0
  44. package/dist/docs/dashboards/README.md +23 -0
  45. package/dist/docs/dashboards/grafana-visor-diagrams.json +20 -0
  46. package/dist/docs/dashboards/grafana-visor-overview.json +33 -0
  47. package/dist/docs/debug-visualizer-progress.md +572 -0
  48. package/dist/docs/debug-visualizer-rfc.md +691 -0
  49. package/dist/docs/debug-visualizer.md +114 -0
  50. package/dist/docs/debugging.md +636 -0
  51. package/dist/docs/default-output-schema.md +28 -0
  52. package/dist/docs/dependencies.md +369 -0
  53. package/dist/docs/dev-playbook.md +9 -0
  54. package/dist/docs/engine-state-machine-plan.md +333 -0
  55. package/dist/docs/event-driven-github-integration-rfc.md +743 -0
  56. package/dist/docs/event-triggers.md +292 -0
  57. package/dist/docs/execution-statistics-rfc.md +290 -0
  58. package/dist/docs/fact-validator-gap-analysis.md +178 -0
  59. package/dist/docs/fact-validator-implementation-plan.md +1235 -0
  60. package/dist/docs/fail-if.md +95 -0
  61. package/dist/docs/failure-conditions-implementation.md +271 -0
  62. package/dist/docs/failure-conditions-schema.md +173 -0
  63. package/dist/docs/failure-routing-rfc.md +193 -0
  64. package/dist/docs/failure-routing.md +507 -0
  65. package/dist/docs/foreach-dependency-propagation.md +473 -0
  66. package/dist/docs/github-ops.md +89 -0
  67. package/dist/docs/goto-forward-run-plan.md +113 -0
  68. package/dist/docs/guides/criticality-modes.md +332 -0
  69. package/dist/docs/guides/fault-management-and-contracts.md +738 -0
  70. package/dist/docs/guides/workflow-style-guide.md +224 -0
  71. package/dist/docs/http.md +299 -0
  72. package/dist/docs/human-input-provider.md +372 -0
  73. package/dist/docs/limits.md +64 -0
  74. package/dist/docs/liquid-templates.md +347 -0
  75. package/dist/docs/loop-routing-refactor.md +89 -0
  76. package/dist/docs/mcp-provider.md +557 -0
  77. package/dist/docs/mcp.md +124 -0
  78. package/dist/docs/memory.md +903 -0
  79. package/dist/docs/observability.md +12 -0
  80. package/dist/docs/output-formats.md +20 -0
  81. package/dist/docs/output-formatting.md +29 -0
  82. package/dist/docs/output-history.md +383 -0
  83. package/dist/docs/performance.md +6 -0
  84. package/dist/docs/pluggable.md +124 -0
  85. package/dist/docs/proposals/snapshot-scope-execution.md +236 -0
  86. package/dist/docs/recipes.md +21 -0
  87. package/dist/docs/roadmap/criticality-implementation-tasks.md +92 -0
  88. package/dist/docs/schema-next-pr.md +10 -0
  89. package/dist/docs/schema-templates.md +68 -0
  90. package/dist/docs/script.md +34 -0
  91. package/dist/docs/sdk.md +222 -0
  92. package/dist/docs/security.md +7 -0
  93. package/dist/docs/suppressions.md +89 -0
  94. package/dist/docs/tag-filtering.md +258 -0
  95. package/dist/docs/telemetry-setup.md +119 -0
  96. package/dist/docs/telemetry-tracing-rfc.md +275 -0
  97. package/dist/docs/test-framework-rfc.md +680 -0
  98. package/dist/docs/testing/assertions.md +85 -0
  99. package/dist/docs/testing/ci.md +44 -0
  100. package/dist/docs/testing/cli.md +41 -0
  101. package/dist/docs/testing/cookbook.md +172 -0
  102. package/dist/docs/testing/dsl-reference.md +199 -0
  103. package/dist/docs/testing/fixtures-and-mocks.md +91 -0
  104. package/dist/docs/testing/flows.md +92 -0
  105. package/dist/docs/testing/getting-started.md +93 -0
  106. package/dist/docs/testing/troubleshooting.md +55 -0
  107. package/dist/docs/timeouts.md +50 -0
  108. package/dist/docs/troubleshooting.md +7 -0
  109. package/dist/docs/visor-sdk-rfc.md +186 -0
  110. package/dist/docs/workflows.md +569 -0
  111. package/dist/engine/on-finish/orchestrator.d.ts +19 -0
  112. package/dist/engine/on-finish/orchestrator.d.ts.map +1 -0
  113. package/dist/engine/on-finish/utils.d.ts +44 -0
  114. package/dist/engine/on-finish/utils.d.ts.map +1 -0
  115. package/dist/event-bus/event-bus.d.ts +13 -0
  116. package/dist/event-bus/event-bus.d.ts.map +1 -0
  117. package/dist/event-bus/types.d.ts +57 -0
  118. package/dist/event-bus/types.d.ts.map +1 -0
  119. package/dist/examples/.claude/agents/code-reviewer.md +69 -0
  120. package/dist/examples/.mcp.json +34 -0
  121. package/dist/examples/CALCULATOR-SDK.md +364 -0
  122. package/dist/examples/README.md +384 -0
  123. package/dist/examples/ai-retry-fallback-config.yaml +180 -0
  124. package/dist/examples/ai-with-bash.yaml +126 -0
  125. package/dist/examples/ai-with-mcp.yaml +82 -0
  126. package/dist/examples/basic-human-input.yaml +15 -0
  127. package/dist/examples/bedrock-config.yaml +77 -0
  128. package/dist/examples/calculator-config.yaml +133 -0
  129. package/dist/examples/calculator-json-output-guide.md +311 -0
  130. package/dist/examples/calculator-sdk-automated.ts +340 -0
  131. package/dist/examples/calculator-sdk-example.ts +275 -0
  132. package/dist/examples/calculator-sdk-json.ts +331 -0
  133. package/dist/examples/calculator-sdk-real.ts +374 -0
  134. package/dist/examples/calculator-sdk-test.ts +148 -0
  135. package/dist/examples/claude-code-config.yaml +191 -0
  136. package/dist/examples/cron-webhook-config.yaml +215 -0
  137. package/dist/examples/custom-template.liquid +57 -0
  138. package/dist/examples/custom-tools-example.yaml +281 -0
  139. package/dist/examples/enhanced-config.yaml +165 -0
  140. package/dist/examples/environments/visor.base.yaml +92 -0
  141. package/dist/examples/environments/visor.dev.yaml +33 -0
  142. package/dist/examples/environments/visor.prod.yaml +95 -0
  143. package/dist/examples/environments/visor.staging.yaml +46 -0
  144. package/dist/examples/fact-validator.yaml +361 -0
  145. package/dist/examples/fail-if-simple.yaml +90 -0
  146. package/dist/examples/failure-conditions-advanced.yaml +136 -0
  147. package/dist/examples/failure-conditions-basic.yaml +48 -0
  148. package/dist/examples/failure-conditions-github-style.yaml +119 -0
  149. package/dist/examples/failure-conditions-migration.yaml +74 -0
  150. package/dist/examples/for-loop-example.yaml +176 -0
  151. package/dist/examples/forEach-example.yaml +120 -0
  152. package/dist/examples/github-workflow-with-tags.yml +163 -0
  153. package/dist/examples/http-integration-config.yaml +240 -0
  154. package/dist/examples/https-server-config.yaml +209 -0
  155. package/dist/examples/human-input-example.yaml +63 -0
  156. package/dist/examples/if-conditions.yaml +173 -0
  157. package/dist/examples/jira-simple-example.yaml +56 -0
  158. package/dist/examples/jira-single-issue-workflow.yaml +166 -0
  159. package/dist/examples/jira-workflow-mcp.yaml +182 -0
  160. package/dist/examples/mcp/analyzer.py +119 -0
  161. package/dist/examples/mcp-provider-example.yaml +301 -0
  162. package/dist/examples/memory-counter.yaml +99 -0
  163. package/dist/examples/memory-error-collection.yaml +104 -0
  164. package/dist/examples/memory-exec-js.yaml +247 -0
  165. package/dist/examples/memory-namespace-isolation.yaml +184 -0
  166. package/dist/examples/memory-retry-counter.yaml +65 -0
  167. package/dist/examples/memory-state-machine.yaml +170 -0
  168. package/dist/examples/outputs-raw-basic.yaml +26 -0
  169. package/dist/examples/project-with-tools.yaml +174 -0
  170. package/dist/examples/prompts/architecture-analysis.liquid +116 -0
  171. package/dist/examples/prompts/security-comprehensive.liquid +107 -0
  172. package/dist/examples/quick-start-tags.yaml +53 -0
  173. package/dist/examples/routing-basic.yaml +35 -0
  174. package/dist/examples/routing-dynamic-js.yaml +46 -0
  175. package/dist/examples/routing-foreach.yaml +34 -0
  176. package/dist/examples/routing-goto-event.yaml +34 -0
  177. package/dist/examples/routing-on-success.yaml +25 -0
  178. package/dist/examples/run-calculator-demo.sh +71 -0
  179. package/dist/examples/sdk-basic.mjs +10 -0
  180. package/dist/examples/sdk-cjs.cjs +10 -0
  181. package/dist/examples/sdk-comprehensive.mjs +175 -0
  182. package/dist/examples/sdk-manual-config.mjs +65 -0
  183. package/dist/examples/sdk-typescript.js +81 -0
  184. package/dist/examples/sdk-typescript.ts +92 -0
  185. package/dist/examples/session-reuse-config.yaml +151 -0
  186. package/dist/examples/templates/security-report.liquid +137 -0
  187. package/dist/examples/tools-library.yaml +281 -0
  188. package/dist/examples/transform-example.yaml +199 -0
  189. package/dist/examples/visor-with-tags.yaml +198 -0
  190. package/dist/examples/webhook-pipeline-config.yaml +218 -0
  191. package/dist/examples/workflows/calculator-workflow.yaml +163 -0
  192. package/dist/examples/workflows/code-quality.yaml +222 -0
  193. package/dist/examples/workflows/quick-pr-check.yaml +90 -0
  194. package/dist/examples/workflows/workflow-composition-example.yaml +130 -0
  195. package/dist/failure-condition-evaluator.d.ts +1 -0
  196. package/dist/failure-condition-evaluator.d.ts.map +1 -1
  197. package/dist/frontends/github-frontend.d.ts +38 -0
  198. package/dist/frontends/github-frontend.d.ts.map +1 -0
  199. package/dist/frontends/host.d.ts +43 -0
  200. package/dist/frontends/host.d.ts.map +1 -0
  201. package/dist/frontends/ndjson-sink.d.ts +12 -0
  202. package/dist/frontends/ndjson-sink.d.ts.map +1 -0
  203. package/dist/generated/config-schema.d.ts +564 -22
  204. package/dist/generated/config-schema.d.ts.map +1 -1
  205. package/dist/generated/config-schema.json +612 -24
  206. package/dist/github-check-service.d.ts +4 -6
  207. package/dist/github-check-service.d.ts.map +1 -1
  208. package/dist/github-comments.d.ts +0 -4
  209. package/dist/github-comments.d.ts.map +1 -1
  210. package/dist/index.d.ts.map +1 -1
  211. package/dist/index.js +70335 -62514
  212. package/dist/liquid-extensions.d.ts.map +1 -1
  213. package/dist/logger.d.ts +1 -0
  214. package/dist/logger.d.ts.map +1 -1
  215. package/dist/memory-store.d.ts +6 -0
  216. package/dist/memory-store.d.ts.map +1 -1
  217. package/dist/output/assistant-json/template.liquid +0 -0
  218. package/dist/output/traces/run-2025-11-21T11-50-46-505Z.ndjson +138 -0
  219. package/dist/output/traces/run-2025-11-21T11-51-33-674Z.ndjson +839 -0
  220. package/dist/output-formatters.d.ts +1 -1
  221. package/dist/output-formatters.d.ts.map +1 -1
  222. package/dist/providers/ai-check-provider.d.ts.map +1 -1
  223. package/dist/providers/check-provider-registry.d.ts +6 -0
  224. package/dist/providers/check-provider-registry.d.ts.map +1 -1
  225. package/dist/providers/check-provider.interface.d.ts +34 -1
  226. package/dist/providers/check-provider.interface.d.ts.map +1 -1
  227. package/dist/providers/claude-code-check-provider.d.ts.map +1 -1
  228. package/dist/providers/command-check-provider.d.ts +1 -1
  229. package/dist/providers/command-check-provider.d.ts.map +1 -1
  230. package/dist/providers/custom-tool-executor.d.ts +61 -0
  231. package/dist/providers/custom-tool-executor.d.ts.map +1 -0
  232. package/dist/providers/github-ops-provider.d.ts.map +1 -1
  233. package/dist/providers/http-client-provider.d.ts +1 -4
  234. package/dist/providers/http-client-provider.d.ts.map +1 -1
  235. package/dist/providers/human-input-check-provider.d.ts +3 -0
  236. package/dist/providers/human-input-check-provider.d.ts.map +1 -1
  237. package/dist/providers/index.d.ts +1 -0
  238. package/dist/providers/index.d.ts.map +1 -1
  239. package/dist/providers/log-check-provider.d.ts +2 -5
  240. package/dist/providers/log-check-provider.d.ts.map +1 -1
  241. package/dist/providers/mcp-check-provider.d.ts +9 -3
  242. package/dist/providers/mcp-check-provider.d.ts.map +1 -1
  243. package/dist/providers/memory-check-provider.d.ts +2 -8
  244. package/dist/providers/memory-check-provider.d.ts.map +1 -1
  245. package/dist/providers/script-check-provider.d.ts +25 -0
  246. package/dist/providers/script-check-provider.d.ts.map +1 -0
  247. package/dist/providers/workflow-check-provider.d.ts +56 -0
  248. package/dist/providers/workflow-check-provider.d.ts.map +1 -0
  249. package/dist/reviewer.d.ts +2 -1
  250. package/dist/reviewer.d.ts.map +1 -1
  251. package/dist/sdk/chunk-37ZSCMFC.mjs +482 -0
  252. package/dist/sdk/chunk-37ZSCMFC.mjs.map +1 -0
  253. package/dist/sdk/chunk-6Y4YTKCF.mjs +197 -0
  254. package/dist/sdk/chunk-6Y4YTKCF.mjs.map +1 -0
  255. package/dist/sdk/chunk-CNX7V5JK.mjs +89 -0
  256. package/dist/sdk/chunk-CNX7V5JK.mjs.map +1 -0
  257. package/dist/sdk/chunk-IEO6CFLG.mjs +1215 -0
  258. package/dist/sdk/chunk-IEO6CFLG.mjs.map +1 -0
  259. package/dist/sdk/chunk-JEHPDJIF.mjs +223 -0
  260. package/dist/sdk/chunk-JEHPDJIF.mjs.map +1 -0
  261. package/dist/sdk/chunk-O5EZDNYL.mjs +274 -0
  262. package/dist/sdk/chunk-O5EZDNYL.mjs.map +1 -0
  263. package/dist/sdk/{chunk-TUTOLSFV.mjs → chunk-OOZITMRU.mjs} +1 -1
  264. package/dist/sdk/chunk-OOZITMRU.mjs.map +1 -0
  265. package/dist/sdk/chunk-OWUVOILT.mjs +557 -0
  266. package/dist/sdk/chunk-OWUVOILT.mjs.map +1 -0
  267. package/dist/sdk/chunk-OZJ263FM.mjs +986 -0
  268. package/dist/sdk/chunk-OZJ263FM.mjs.map +1 -0
  269. package/dist/sdk/chunk-PTL3K3PN.mjs +3128 -0
  270. package/dist/sdk/chunk-PTL3K3PN.mjs.map +1 -0
  271. package/dist/sdk/chunk-S2RUE2RG.mjs +145 -0
  272. package/dist/sdk/chunk-S2RUE2RG.mjs.map +1 -0
  273. package/dist/sdk/chunk-VMPLF6FT.mjs +127 -0
  274. package/dist/sdk/chunk-VMPLF6FT.mjs.map +1 -0
  275. package/dist/sdk/chunk-YSN4G6CI.mjs +146 -0
  276. package/dist/sdk/chunk-YSN4G6CI.mjs.map +1 -0
  277. package/dist/sdk/chunk-ZYAUYXSW.mjs +206 -0
  278. package/dist/sdk/chunk-ZYAUYXSW.mjs.map +1 -0
  279. package/dist/sdk/config-M4ZNO6NU.mjs +14 -0
  280. package/dist/sdk/config-merger-PX3WIT57.mjs +10 -0
  281. package/dist/sdk/event-bus-5BEVPQ6T.mjs +35 -0
  282. package/dist/sdk/event-bus-5BEVPQ6T.mjs.map +1 -0
  283. package/dist/sdk/failure-condition-evaluator-NBO5YRXW.mjs +16 -0
  284. package/dist/sdk/git-repository-analyzer-HJC4MYW4.mjs +458 -0
  285. package/dist/sdk/git-repository-analyzer-HJC4MYW4.mjs.map +1 -0
  286. package/dist/sdk/github-frontend-4AWRJT7D.mjs +1242 -0
  287. package/dist/sdk/github-frontend-4AWRJT7D.mjs.map +1 -0
  288. package/dist/sdk/host-7GBC3S7L.mjs +49 -0
  289. package/dist/sdk/host-7GBC3S7L.mjs.map +1 -0
  290. package/dist/sdk/{liquid-extensions-KVL4MKRH.mjs → liquid-extensions-C7EG3YKH.mjs} +7 -2
  291. package/dist/sdk/memory-store-GJACZC2A.mjs +11 -0
  292. package/dist/sdk/metrics-7PP3EJUH.mjs +29 -0
  293. package/dist/sdk/ndjson-sink-B4V4NTAQ.mjs +44 -0
  294. package/dist/sdk/ndjson-sink-B4V4NTAQ.mjs.map +1 -0
  295. package/dist/sdk/renderer-schema-6RF26VUS.mjs +50 -0
  296. package/dist/sdk/renderer-schema-6RF26VUS.mjs.map +1 -0
  297. package/dist/sdk/routing-RP56JTV2.mjs +23 -0
  298. package/dist/sdk/routing-RP56JTV2.mjs.map +1 -0
  299. package/dist/sdk/sdk.d.mts +326 -21
  300. package/dist/sdk/sdk.d.ts +326 -21
  301. package/dist/sdk/sdk.js +21403 -16366
  302. package/dist/sdk/sdk.js.map +1 -1
  303. package/dist/sdk/sdk.mjs +13510 -2096
  304. package/dist/sdk/sdk.mjs.map +1 -1
  305. package/dist/sdk/session-registry-N5FFYFTM.mjs +10 -0
  306. package/dist/sdk/session-registry-N5FFYFTM.mjs.map +1 -0
  307. package/dist/sdk/trace-helpers-VP6QYVBX.mjs +23 -0
  308. package/dist/sdk/trace-helpers-VP6QYVBX.mjs.map +1 -0
  309. package/dist/sdk/{tracer-init-WC75N5NW.mjs → tracer-init-WP4X46IF.mjs} +2 -2
  310. package/dist/sdk/tracer-init-WP4X46IF.mjs.map +1 -0
  311. package/dist/sdk/workflow-registry-2YIIXQCK.mjs +11 -0
  312. package/dist/sdk/workflow-registry-2YIIXQCK.mjs.map +1 -0
  313. package/dist/sdk.d.ts.map +1 -1
  314. package/dist/snapshot-store.d.ts +59 -0
  315. package/dist/snapshot-store.d.ts.map +1 -0
  316. package/dist/state-machine/context/build-engine-context.d.ts +9 -0
  317. package/dist/state-machine/context/build-engine-context.d.ts.map +1 -0
  318. package/dist/state-machine/dispatch/dependency-gating.d.ts +12 -0
  319. package/dist/state-machine/dispatch/dependency-gating.d.ts.map +1 -0
  320. package/dist/state-machine/dispatch/execution-invoker.d.ts +14 -0
  321. package/dist/state-machine/dispatch/execution-invoker.d.ts.map +1 -0
  322. package/dist/state-machine/dispatch/foreach-processor.d.ts +8 -0
  323. package/dist/state-machine/dispatch/foreach-processor.d.ts.map +1 -0
  324. package/dist/state-machine/dispatch/history-snapshot.d.ts +8 -0
  325. package/dist/state-machine/dispatch/history-snapshot.d.ts.map +1 -0
  326. package/dist/state-machine/dispatch/renderer-schema.d.ts +8 -0
  327. package/dist/state-machine/dispatch/renderer-schema.d.ts.map +1 -0
  328. package/dist/state-machine/dispatch/stats-manager.d.ts +15 -0
  329. package/dist/state-machine/dispatch/stats-manager.d.ts.map +1 -0
  330. package/dist/state-machine/dispatch/template-renderer.d.ts +7 -0
  331. package/dist/state-machine/dispatch/template-renderer.d.ts.map +1 -0
  332. package/dist/state-machine/execution/summary.d.ts +8 -0
  333. package/dist/state-machine/execution/summary.d.ts.map +1 -0
  334. package/dist/state-machine/runner.d.ts +73 -0
  335. package/dist/state-machine/runner.d.ts.map +1 -0
  336. package/dist/state-machine/states/check-running.d.ts +14 -0
  337. package/dist/state-machine/states/check-running.d.ts.map +1 -0
  338. package/dist/state-machine/states/completed.d.ts +12 -0
  339. package/dist/state-machine/states/completed.d.ts.map +1 -0
  340. package/dist/state-machine/states/error.d.ts +11 -0
  341. package/dist/state-machine/states/error.d.ts.map +1 -0
  342. package/dist/state-machine/states/init.d.ts +11 -0
  343. package/dist/state-machine/states/init.d.ts.map +1 -0
  344. package/dist/state-machine/states/level-dispatch.d.ts +17 -0
  345. package/dist/state-machine/states/level-dispatch.d.ts.map +1 -0
  346. package/dist/state-machine/states/plan-ready.d.ts +12 -0
  347. package/dist/state-machine/states/plan-ready.d.ts.map +1 -0
  348. package/dist/state-machine/states/routing.d.ts +52 -0
  349. package/dist/state-machine/states/routing.d.ts.map +1 -0
  350. package/dist/state-machine/states/wave-planning.d.ts +14 -0
  351. package/dist/state-machine/states/wave-planning.d.ts.map +1 -0
  352. package/dist/state-machine/workflow-projection.d.ts +47 -0
  353. package/dist/state-machine/workflow-projection.d.ts.map +1 -0
  354. package/dist/state-machine-execution-engine.d.ts +147 -0
  355. package/dist/state-machine-execution-engine.d.ts.map +1 -0
  356. package/dist/telemetry/opentelemetry.d.ts.map +1 -1
  357. package/dist/test-runner/assertions.d.ts +59 -0
  358. package/dist/test-runner/assertions.d.ts.map +1 -0
  359. package/dist/test-runner/core/environment.d.ts +8 -0
  360. package/dist/test-runner/core/environment.d.ts.map +1 -0
  361. package/dist/test-runner/core/fixture.d.ts +3 -0
  362. package/dist/test-runner/core/fixture.d.ts.map +1 -0
  363. package/dist/test-runner/core/flow-stage.d.ts +32 -0
  364. package/dist/test-runner/core/flow-stage.d.ts.map +1 -0
  365. package/dist/test-runner/core/mocks.d.ts +8 -0
  366. package/dist/test-runner/core/mocks.d.ts.map +1 -0
  367. package/dist/test-runner/core/test-execution-wrapper.d.ts +18 -0
  368. package/dist/test-runner/core/test-execution-wrapper.d.ts.map +1 -0
  369. package/dist/test-runner/evaluators.d.ts +12 -0
  370. package/dist/test-runner/evaluators.d.ts.map +1 -0
  371. package/dist/test-runner/fixture-loader.d.ts +30 -0
  372. package/dist/test-runner/fixture-loader.d.ts.map +1 -0
  373. package/dist/test-runner/index.d.ts +120 -0
  374. package/dist/test-runner/index.d.ts.map +1 -0
  375. package/dist/test-runner/recorders/github-recorder.d.ts +23 -0
  376. package/dist/test-runner/recorders/github-recorder.d.ts.map +1 -0
  377. package/dist/test-runner/recorders/global-recorder.d.ts +4 -0
  378. package/dist/test-runner/recorders/global-recorder.d.ts.map +1 -0
  379. package/dist/test-runner/utils/selectors.d.ts +2 -0
  380. package/dist/test-runner/utils/selectors.d.ts.map +1 -0
  381. package/dist/test-runner/validator.d.ts +8 -0
  382. package/dist/test-runner/validator.d.ts.map +1 -0
  383. package/dist/traces/run-2025-11-21T11-50-46-505Z.ndjson +138 -0
  384. package/dist/traces/run-2025-11-21T11-51-33-674Z.ndjson +839 -0
  385. package/dist/types/cli.d.ts +4 -1
  386. package/dist/types/cli.d.ts.map +1 -1
  387. package/dist/types/config.d.ts +278 -5
  388. package/dist/types/config.d.ts.map +1 -1
  389. package/dist/types/engine.d.ts +172 -0
  390. package/dist/types/engine.d.ts.map +1 -0
  391. package/dist/types/execution.d.ts +73 -0
  392. package/dist/types/execution.d.ts.map +1 -0
  393. package/dist/types/github.d.ts +51 -0
  394. package/dist/types/github.d.ts.map +1 -0
  395. package/dist/types/workflow.d.ts +237 -0
  396. package/dist/types/workflow.d.ts.map +1 -0
  397. package/dist/utils/command-executor.d.ts +43 -0
  398. package/dist/utils/command-executor.d.ts.map +1 -0
  399. package/dist/utils/comment-metadata.d.ts +21 -0
  400. package/dist/utils/comment-metadata.d.ts.map +1 -0
  401. package/dist/utils/config-loader.d.ts.map +1 -1
  402. package/dist/utils/config-merger.d.ts.map +1 -1
  403. package/dist/utils/env-exposure.d.ts +3 -0
  404. package/dist/utils/env-exposure.d.ts.map +1 -0
  405. package/dist/utils/file-exclusion.d.ts.map +1 -1
  406. package/dist/utils/interactive-prompt.d.ts +1 -1
  407. package/dist/utils/interactive-prompt.d.ts.map +1 -1
  408. package/dist/utils/sandbox.d.ts.map +1 -1
  409. package/dist/utils/script-memory-ops.d.ts +21 -0
  410. package/dist/utils/script-memory-ops.d.ts.map +1 -0
  411. package/dist/utils/template-context.d.ts +7 -0
  412. package/dist/utils/template-context.d.ts.map +1 -0
  413. package/dist/webhook-server.d.ts +3 -3
  414. package/dist/webhook-server.d.ts.map +1 -1
  415. package/dist/workflow-executor.d.ts +81 -0
  416. package/dist/workflow-executor.d.ts.map +1 -0
  417. package/dist/workflow-registry.d.ts +79 -0
  418. package/dist/workflow-registry.d.ts.map +1 -0
  419. package/package.json +10 -5
  420. package/dist/output/traces/run-2025-10-22T18-22-56-873Z.ndjson +0 -218
  421. package/dist/sdk/check-execution-engine-2YYKUUSH.mjs +0 -11
  422. package/dist/sdk/check-execution-engine-6QJXYYON.mjs +0 -11
  423. package/dist/sdk/check-execution-engine-PJZ4ZOKG.mjs +0 -11
  424. package/dist/sdk/chunk-33QVZ2D4.mjs +0 -316
  425. package/dist/sdk/chunk-33QVZ2D4.mjs.map +0 -1
  426. package/dist/sdk/chunk-B5QBV2QJ.mjs +0 -752
  427. package/dist/sdk/chunk-B5QBV2QJ.mjs.map +0 -1
  428. package/dist/sdk/chunk-BVFNRCHT.mjs +0 -14129
  429. package/dist/sdk/chunk-BVFNRCHT.mjs.map +0 -1
  430. package/dist/sdk/chunk-KWZW23FG.mjs +0 -14129
  431. package/dist/sdk/chunk-KWZW23FG.mjs.map +0 -1
  432. package/dist/sdk/chunk-O4RP4BRH.mjs +0 -14092
  433. package/dist/sdk/chunk-O4RP4BRH.mjs.map +0 -1
  434. package/dist/sdk/chunk-TUTOLSFV.mjs.map +0 -1
  435. package/dist/sdk/chunk-U5D2LY66.mjs +0 -245
  436. package/dist/sdk/chunk-U5D2LY66.mjs.map +0 -1
  437. package/dist/sdk/chunk-U7X54EMV.mjs +0 -331
  438. package/dist/sdk/chunk-U7X54EMV.mjs.map +0 -1
  439. package/dist/sdk/config-merger-TWUBWFC2.mjs +0 -8
  440. package/dist/sdk/mermaid-telemetry-SN6A2TKW.mjs +0 -61
  441. package/dist/sdk/mermaid-telemetry-SN6A2TKW.mjs.map +0 -1
  442. package/dist/sdk/mermaid-telemetry-YCTIG76M.mjs +0 -61
  443. package/dist/sdk/mermaid-telemetry-YCTIG76M.mjs.map +0 -1
  444. package/dist/traces/run-2025-10-22T18-22-56-873Z.ndjson +0 -218
  445. /package/dist/sdk/{check-execution-engine-2YYKUUSH.mjs.map → config-M4ZNO6NU.mjs.map} +0 -0
  446. /package/dist/sdk/{check-execution-engine-6QJXYYON.mjs.map → config-merger-PX3WIT57.mjs.map} +0 -0
  447. /package/dist/sdk/{check-execution-engine-PJZ4ZOKG.mjs.map → failure-condition-evaluator-NBO5YRXW.mjs.map} +0 -0
  448. /package/dist/sdk/{config-merger-TWUBWFC2.mjs.map → liquid-extensions-C7EG3YKH.mjs.map} +0 -0
  449. /package/dist/sdk/{liquid-extensions-KVL4MKRH.mjs.map → memory-store-GJACZC2A.mjs.map} +0 -0
  450. /package/dist/sdk/{tracer-init-WC75N5NW.mjs.map → metrics-7PP3EJUH.mjs.map} +0 -0
@@ -0,0 +1,1215 @@
1
+ import {
2
+ FailureConditionEvaluator,
3
+ compileAndRun,
4
+ createSecureSandbox,
5
+ init_failure_condition_evaluator,
6
+ init_sandbox
7
+ } from "./chunk-OZJ263FM.mjs";
8
+ import {
9
+ MemoryStore,
10
+ init_memory_store
11
+ } from "./chunk-37ZSCMFC.mjs";
12
+ import {
13
+ init_logger,
14
+ logger
15
+ } from "./chunk-VMPLF6FT.mjs";
16
+ import {
17
+ __esm,
18
+ __export,
19
+ __require,
20
+ __toCommonJS
21
+ } from "./chunk-WMJKH4XE.mjs";
22
+
23
+ // src/snapshot-store.ts
24
+ var snapshot_store_exports = {};
25
+ __export(snapshot_store_exports, {
26
+ ContextView: () => ContextView,
27
+ ExecutionJournal: () => ExecutionJournal
28
+ });
29
+ var ExecutionJournal, ContextView;
30
+ var init_snapshot_store = __esm({
31
+ "src/snapshot-store.ts"() {
32
+ "use strict";
33
+ ExecutionJournal = class {
34
+ commit = 0;
35
+ entries = [];
36
+ beginSnapshot() {
37
+ return this.commit;
38
+ }
39
+ commitEntry(entry) {
40
+ const committed = {
41
+ sessionId: entry.sessionId,
42
+ scope: entry.scope,
43
+ checkId: entry.checkId,
44
+ result: entry.result,
45
+ event: entry.event,
46
+ commitId: ++this.commit
47
+ };
48
+ this.entries.push(committed);
49
+ return committed;
50
+ }
51
+ readVisible(sessionId, commitMax, event) {
52
+ return this.entries.filter(
53
+ (e) => e.sessionId === sessionId && e.commitId <= commitMax && (event ? e.event === event : true)
54
+ );
55
+ }
56
+ // Lightweight helpers for debugging/metrics
57
+ size() {
58
+ return this.entries.length;
59
+ }
60
+ };
61
+ ContextView = class {
62
+ constructor(journal, sessionId, snapshotId, scope, event) {
63
+ this.journal = journal;
64
+ this.sessionId = sessionId;
65
+ this.snapshotId = snapshotId;
66
+ this.scope = scope;
67
+ this.event = event;
68
+ }
69
+ /** Return the nearest result for a check in this scope (exact item → ancestor → latest). */
70
+ get(checkId) {
71
+ const visible = this.journal.readVisible(this.sessionId, this.snapshotId, this.event).filter((e) => e.checkId === checkId);
72
+ if (visible.length === 0) return void 0;
73
+ const exactMatches = visible.filter((e) => this.sameScope(e.scope, this.scope));
74
+ if (exactMatches.length > 0) {
75
+ return exactMatches[exactMatches.length - 1].result;
76
+ }
77
+ let best;
78
+ for (const e of visible) {
79
+ const dist = this.ancestorDistance(e.scope, this.scope);
80
+ if (dist >= 0 && (best === void 0 || dist < best.dist)) {
81
+ best = { entry: e, dist };
82
+ }
83
+ }
84
+ if (best) return best.entry.result;
85
+ return visible[visible.length - 1]?.result;
86
+ }
87
+ /** Return an aggregate (raw) result – the shallowest scope for this check. */
88
+ getRaw(checkId) {
89
+ const visible = this.journal.readVisible(this.sessionId, this.snapshotId, this.event).filter((e) => e.checkId === checkId);
90
+ if (visible.length === 0) return void 0;
91
+ let shallow = visible[0];
92
+ for (const e of visible) {
93
+ if (e.scope.length < shallow.scope.length) shallow = e;
94
+ }
95
+ return shallow.result;
96
+ }
97
+ /** All results for a check up to this snapshot. */
98
+ getHistory(checkId) {
99
+ return this.journal.readVisible(this.sessionId, this.snapshotId, this.event).filter((e) => e.checkId === checkId).map((e) => e.result);
100
+ }
101
+ sameScope(a, b) {
102
+ if (a.length !== b.length) return false;
103
+ for (let i = 0; i < a.length; i++) {
104
+ if (a[i].check !== b[i].check || a[i].index !== b[i].index) return false;
105
+ }
106
+ return true;
107
+ }
108
+ // distance from ancestor to current; -1 if not ancestor
109
+ ancestorDistance(ancestor, current) {
110
+ if (ancestor.length > current.length) return -1;
111
+ if (ancestor.length === 0 && current.length > 0) return -1;
112
+ for (let i = 0; i < ancestor.length; i++) {
113
+ if (ancestor[i].check !== current[i].check || ancestor[i].index !== current[i].index)
114
+ return -1;
115
+ }
116
+ return current.length - ancestor.length;
117
+ }
118
+ };
119
+ }
120
+ });
121
+
122
+ // src/state-machine/states/routing.ts
123
+ function hasMapFanoutDependents(context, checkId) {
124
+ const checks = context.config.checks || {};
125
+ const reduceProviders = /* @__PURE__ */ new Set(["log", "memory", "script", "workflow", "noop"]);
126
+ for (const [cid, cfg] of Object.entries(checks)) {
127
+ if (cid === checkId) continue;
128
+ const rawDeps = cfg.depends_on || [];
129
+ const depList = Array.isArray(rawDeps) ? rawDeps : [rawDeps];
130
+ let depends = false;
131
+ for (const dep of depList) {
132
+ if (typeof dep !== "string") continue;
133
+ if (dep.includes("|")) {
134
+ const opts = dep.split("|").map((s) => s.trim()).filter(Boolean);
135
+ if (opts.includes(checkId)) {
136
+ depends = true;
137
+ break;
138
+ }
139
+ } else if (dep === checkId) {
140
+ depends = true;
141
+ break;
142
+ }
143
+ }
144
+ if (!depends) continue;
145
+ const explicit = cfg.fanout;
146
+ if (explicit === "map") return true;
147
+ if (explicit === "reduce") continue;
148
+ const providerType = context.checks[cid]?.providerType || checks[cid]?.type || "";
149
+ const inferred = reduceProviders.has(providerType) ? "reduce" : "map";
150
+ if (inferred === "map") return true;
151
+ }
152
+ return false;
153
+ }
154
+ function classifyFailure(result) {
155
+ const issues = result?.issues || [];
156
+ if (!issues || issues.length === 0) return "none";
157
+ let hasLogical = false;
158
+ let hasExecution = false;
159
+ for (const iss of issues) {
160
+ const id = String(iss.ruleId || "");
161
+ const msg = String(iss.message || "");
162
+ if (id.endsWith("_fail_if") || id.includes("contract/guarantee_failed") || id.includes("contract/schema_validation_failed"))
163
+ hasLogical = true;
164
+ if (id.includes("/execution_error") || msg.includes("Command execution failed"))
165
+ hasExecution = true;
166
+ if (id.includes("forEach/execution_error") || msg.includes("sandbox_runner_error"))
167
+ hasExecution = true;
168
+ }
169
+ if (hasLogical && !hasExecution) return "logical";
170
+ if (hasExecution && !hasLogical) return "execution";
171
+ return hasExecution ? "execution" : "logical";
172
+ }
173
+ function getCriticality(context, checkId) {
174
+ const cfg = context.config.checks?.[checkId];
175
+ return cfg && cfg.criticality || "policy";
176
+ }
177
+ function createMemoryHelpers() {
178
+ const memoryStore = MemoryStore.getInstance();
179
+ return {
180
+ get: (key, ns) => memoryStore.get(key, ns),
181
+ has: (key, ns) => memoryStore.has(key, ns),
182
+ getAll: (ns) => memoryStore.getAll(ns),
183
+ set: (key, value, ns) => {
184
+ const nsName = ns || memoryStore.getDefaultNamespace();
185
+ const data = memoryStore["data"];
186
+ if (!data.has(nsName)) data.set(nsName, /* @__PURE__ */ new Map());
187
+ data.get(nsName).set(key, value);
188
+ },
189
+ clear: (ns) => {
190
+ const data = memoryStore["data"];
191
+ if (ns) data.delete(ns);
192
+ else data.clear();
193
+ },
194
+ increment: (key, amount = 1, ns) => {
195
+ const nsName = ns || memoryStore.getDefaultNamespace();
196
+ const data = memoryStore["data"];
197
+ if (!data.has(nsName)) data.set(nsName, /* @__PURE__ */ new Map());
198
+ const nsMap = data.get(nsName);
199
+ const current = nsMap.get(key);
200
+ const numCurrent = typeof current === "number" ? current : 0;
201
+ const newValue = numCurrent + amount;
202
+ nsMap.set(key, newValue);
203
+ return newValue;
204
+ }
205
+ };
206
+ }
207
+ async function handleRouting(context, state, transition, emitEvent, routingContext) {
208
+ const { checkId, scope, result, checkConfig, success } = routingContext;
209
+ logger.info(`[Routing] Evaluating routing for check: ${checkId}, success: ${success}`);
210
+ const failIfTriggered = await evaluateFailIf(checkId, result, checkConfig, context, state);
211
+ if (failIfTriggered) {
212
+ if (context.debug) {
213
+ logger.info(`[Routing] fail_if triggered for ${checkId}`);
214
+ }
215
+ await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);
216
+ } else if (success) {
217
+ await processOnSuccess(checkId, scope, result, checkConfig, context, state, emitEvent);
218
+ } else {
219
+ await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);
220
+ }
221
+ const shouldProcessOnFinishHere = !!checkConfig.on_finish && (checkConfig.forEach !== true || !hasMapFanoutDependents(context, checkId));
222
+ if (checkConfig.on_finish) {
223
+ logger.info(
224
+ `[Routing] on_finish decision for ${checkId}: forEach=${!!checkConfig.forEach}, processHere=${shouldProcessOnFinishHere}`
225
+ );
226
+ }
227
+ if (shouldProcessOnFinishHere) {
228
+ await processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent);
229
+ }
230
+ transition("WavePlanning");
231
+ }
232
+ async function processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent) {
233
+ const onFinish = checkConfig.on_finish;
234
+ if (!onFinish) {
235
+ return;
236
+ }
237
+ logger.info(`Processing on_finish for ${checkId}`);
238
+ let queuedForward = false;
239
+ if (onFinish.run && onFinish.run.length > 0) {
240
+ const currentCheckIsForEach = checkConfig.forEach === true;
241
+ const forEachItems = currentCheckIsForEach ? result.forEachItems : void 0;
242
+ const hasForEachItems = Array.isArray(forEachItems) && forEachItems.length > 0;
243
+ for (const targetCheck of onFinish.run) {
244
+ if (checkLoopBudget(context, state, "on_finish", "run")) {
245
+ const errorIssue = {
246
+ file: "system",
247
+ line: 0,
248
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
249
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,
250
+ severity: "error",
251
+ category: "logic"
252
+ };
253
+ result.issues = [...result.issues || [], errorIssue];
254
+ return;
255
+ }
256
+ const targetConfig = context.config.checks?.[targetCheck];
257
+ const fanoutMode = targetConfig?.fanout || "reduce";
258
+ if (context.debug) {
259
+ logger.info(
260
+ `[Routing] on_finish.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`
261
+ );
262
+ }
263
+ if (fanoutMode === "map" && hasForEachItems) {
264
+ for (let itemIndex = 0; itemIndex < forEachItems.length; itemIndex++) {
265
+ state.routingLoopCount++;
266
+ const itemScope = [
267
+ { check: checkId, index: itemIndex }
268
+ ];
269
+ emitEvent({
270
+ type: "ForwardRunRequested",
271
+ target: targetCheck,
272
+ scope: itemScope,
273
+ origin: "run"
274
+ });
275
+ queuedForward = true;
276
+ }
277
+ } else {
278
+ state.routingLoopCount++;
279
+ emitEvent({
280
+ type: "ForwardRunRequested",
281
+ target: targetCheck,
282
+ scope: [],
283
+ origin: "run"
284
+ });
285
+ queuedForward = true;
286
+ }
287
+ }
288
+ }
289
+ if (onFinish.run_js) {
290
+ const dynamicTargets = await evaluateRunJs(
291
+ onFinish.run_js,
292
+ checkId,
293
+ checkConfig,
294
+ result,
295
+ context,
296
+ state
297
+ );
298
+ for (const targetCheck of dynamicTargets) {
299
+ if (checkLoopBudget(context, state, "on_finish", "run")) {
300
+ const errorIssue = {
301
+ file: "system",
302
+ line: 0,
303
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
304
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,
305
+ severity: "error",
306
+ category: "logic"
307
+ };
308
+ result.issues = [...result.issues || [], errorIssue];
309
+ return;
310
+ }
311
+ if (context.debug) {
312
+ logger.info(`[Routing] on_finish.run_js: scheduling ${targetCheck}`);
313
+ }
314
+ state.routingLoopCount++;
315
+ emitEvent({
316
+ type: "ForwardRunRequested",
317
+ target: targetCheck,
318
+ scope,
319
+ origin: "run_js"
320
+ });
321
+ queuedForward = true;
322
+ }
323
+ }
324
+ const finishTransTarget = await evaluateTransitions(
325
+ onFinish.transitions,
326
+ checkId,
327
+ checkConfig,
328
+ result,
329
+ context,
330
+ state
331
+ );
332
+ if (finishTransTarget !== void 0) {
333
+ if (finishTransTarget) {
334
+ if (checkLoopBudget(context, state, "on_finish", "goto")) {
335
+ const errorIssue = {
336
+ file: "system",
337
+ line: 0,
338
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
339
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,
340
+ severity: "error",
341
+ category: "logic"
342
+ };
343
+ result.issues = [...result.issues || [], errorIssue];
344
+ return;
345
+ }
346
+ state.routingLoopCount++;
347
+ emitEvent({
348
+ type: "ForwardRunRequested",
349
+ target: finishTransTarget.to,
350
+ scope,
351
+ origin: "goto_js",
352
+ gotoEvent: finishTransTarget.goto_event
353
+ });
354
+ }
355
+ return;
356
+ }
357
+ const gotoTarget = await evaluateGoto(
358
+ onFinish.goto_js,
359
+ onFinish.goto,
360
+ checkId,
361
+ checkConfig,
362
+ result,
363
+ context,
364
+ state
365
+ );
366
+ if (gotoTarget) {
367
+ if (checkLoopBudget(context, state, "on_finish", "goto")) {
368
+ const errorIssue = {
369
+ file: "system",
370
+ line: 0,
371
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
372
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,
373
+ severity: "error",
374
+ category: "logic"
375
+ };
376
+ result.issues = [...result.issues || [], errorIssue];
377
+ return;
378
+ }
379
+ if (context.debug) {
380
+ logger.info(`[Routing] on_finish.goto: ${gotoTarget}`);
381
+ }
382
+ state.routingLoopCount++;
383
+ emitEvent({
384
+ type: "ForwardRunRequested",
385
+ target: gotoTarget,
386
+ scope,
387
+ origin: "goto_js"
388
+ });
389
+ state.flags.forwardRunRequested = true;
390
+ }
391
+ if (queuedForward) {
392
+ const guardKey = `waveRetry:on_finish:${checkId}:wave:${state.wave}`;
393
+ if (!state.forwardRunGuards?.has(guardKey)) {
394
+ state.forwardRunGuards?.add(guardKey);
395
+ emitEvent({ type: "WaveRetry", reason: "on_finish" });
396
+ }
397
+ }
398
+ }
399
+ async function evaluateFailIf(checkId, result, checkConfig, context, state) {
400
+ const config = context.config;
401
+ const globalFailIf = config.fail_if;
402
+ const checkFailIf = checkConfig.fail_if;
403
+ if (!globalFailIf && !checkFailIf) {
404
+ return false;
405
+ }
406
+ const evaluator = new FailureConditionEvaluator();
407
+ const outputsRecord = {};
408
+ for (const [key] of state.stats.entries()) {
409
+ try {
410
+ const snapshotId = context.journal.beginSnapshot();
411
+ const contextView = new (init_snapshot_store(), __toCommonJS(snapshot_store_exports)).ContextView(
412
+ context.journal,
413
+ context.sessionId,
414
+ snapshotId,
415
+ [],
416
+ context.event
417
+ );
418
+ const journalResult = contextView.get(key);
419
+ if (journalResult) {
420
+ outputsRecord[key] = journalResult;
421
+ }
422
+ } catch {
423
+ outputsRecord[key] = { issues: [] };
424
+ }
425
+ }
426
+ const checkSchema = typeof checkConfig.schema === "object" ? "custom" : checkConfig.schema || "";
427
+ const checkGroup = checkConfig.group || "";
428
+ if (globalFailIf) {
429
+ try {
430
+ const failed = await evaluator.evaluateSimpleCondition(
431
+ checkId,
432
+ checkSchema,
433
+ checkGroup,
434
+ result,
435
+ globalFailIf,
436
+ outputsRecord
437
+ );
438
+ if (failed) {
439
+ logger.warn(`[Routing] Global fail_if triggered for ${checkId}: ${globalFailIf}`);
440
+ const failIssue = {
441
+ file: "system",
442
+ line: 0,
443
+ ruleId: "global_fail_if",
444
+ message: `Global failure condition met: ${globalFailIf}`,
445
+ severity: "error",
446
+ category: "logic"
447
+ };
448
+ result.issues = [...result.issues || [], failIssue];
449
+ }
450
+ } catch (error) {
451
+ const msg = error instanceof Error ? error.message : String(error);
452
+ logger.error(`[Routing] Error evaluating global fail_if: ${msg}`);
453
+ }
454
+ }
455
+ if (checkFailIf) {
456
+ try {
457
+ const failed = await evaluator.evaluateSimpleCondition(
458
+ checkId,
459
+ checkSchema,
460
+ checkGroup,
461
+ result,
462
+ checkFailIf,
463
+ outputsRecord
464
+ );
465
+ if (failed) {
466
+ logger.warn(`[Routing] Check fail_if triggered for ${checkId}: ${checkFailIf}`);
467
+ const failIssue = {
468
+ file: "system",
469
+ line: 0,
470
+ ruleId: `${checkId}_fail_if`,
471
+ message: `Check failure condition met: ${checkFailIf}`,
472
+ severity: "error",
473
+ category: "logic"
474
+ };
475
+ result.issues = [...result.issues || [], failIssue];
476
+ return true;
477
+ }
478
+ } catch (error) {
479
+ const msg = error instanceof Error ? error.message : String(error);
480
+ logger.error(`[Routing] Error evaluating check fail_if: ${msg}`);
481
+ }
482
+ }
483
+ return false;
484
+ }
485
+ function checkLoopBudget(context, state, origin, action) {
486
+ const maxLoops = context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS;
487
+ if (state.routingLoopCount >= maxLoops) {
488
+ const msg = `Routing loop budget exceeded (max_loops=${maxLoops}) during ${origin} ${action}`;
489
+ logger.error(`[Routing] ${msg}`);
490
+ return true;
491
+ }
492
+ return false;
493
+ }
494
+ async function processOnSuccess(checkId, scope, result, checkConfig, context, state, emitEvent) {
495
+ const onSuccess = checkConfig.on_success;
496
+ if (!onSuccess) {
497
+ return;
498
+ }
499
+ if (context.debug) {
500
+ logger.info(`[Routing] Processing on_success for ${checkId}`);
501
+ }
502
+ if (onSuccess.run && onSuccess.run.length > 0) {
503
+ const resForEachItems = result && result.forEachItems || void 0;
504
+ const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;
505
+ for (const targetCheck of onSuccess.run) {
506
+ if (checkLoopBudget(context, state, "on_success", "run")) {
507
+ const errorIssue = {
508
+ file: "system",
509
+ line: 0,
510
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
511
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success run`,
512
+ severity: "error",
513
+ category: "logic"
514
+ };
515
+ result.issues = [...result.issues || [], errorIssue];
516
+ return;
517
+ }
518
+ const targetConfig = context.config.checks?.[targetCheck];
519
+ const fanoutMode = targetConfig?.fanout || "reduce";
520
+ if (context.debug) {
521
+ logger.info(
522
+ `[Routing] on_success.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`
523
+ );
524
+ }
525
+ if (fanoutMode === "map" && hasForEachItems) {
526
+ for (let itemIndex = 0; itemIndex < resForEachItems.length; itemIndex++) {
527
+ state.routingLoopCount++;
528
+ const itemScope = [
529
+ { check: checkId, index: itemIndex }
530
+ ];
531
+ emitEvent({
532
+ type: "ForwardRunRequested",
533
+ target: targetCheck,
534
+ scope: itemScope,
535
+ origin: "run"
536
+ });
537
+ }
538
+ } else {
539
+ state.routingLoopCount++;
540
+ emitEvent({
541
+ type: "ForwardRunRequested",
542
+ target: targetCheck,
543
+ scope,
544
+ origin: "run"
545
+ });
546
+ }
547
+ }
548
+ }
549
+ if (onSuccess.run_js) {
550
+ const dynamicTargets = await evaluateRunJs(
551
+ onSuccess.run_js,
552
+ checkId,
553
+ checkConfig,
554
+ result,
555
+ context,
556
+ state
557
+ );
558
+ for (const targetCheck of dynamicTargets) {
559
+ if (checkLoopBudget(context, state, "on_success", "run")) {
560
+ const errorIssue = {
561
+ file: "system",
562
+ line: 0,
563
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
564
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success run`,
565
+ severity: "error",
566
+ category: "logic"
567
+ };
568
+ result.issues = [...result.issues || [], errorIssue];
569
+ return;
570
+ }
571
+ if (context.debug) {
572
+ logger.info(`[Routing] on_success.run_js: scheduling ${targetCheck}`);
573
+ }
574
+ state.routingLoopCount++;
575
+ emitEvent({
576
+ type: "ForwardRunRequested",
577
+ target: targetCheck,
578
+ scope,
579
+ origin: "run_js"
580
+ });
581
+ }
582
+ }
583
+ const successTransTarget = await evaluateTransitions(
584
+ onSuccess.transitions,
585
+ checkId,
586
+ checkConfig,
587
+ result,
588
+ context,
589
+ state
590
+ );
591
+ if (successTransTarget !== void 0) {
592
+ if (successTransTarget) {
593
+ if (checkLoopBudget(context, state, "on_success", "goto")) {
594
+ const errorIssue = {
595
+ file: "system",
596
+ line: 0,
597
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
598
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success goto`,
599
+ severity: "error",
600
+ category: "logic"
601
+ };
602
+ result.issues = [...result.issues || [], errorIssue];
603
+ return;
604
+ }
605
+ state.routingLoopCount++;
606
+ emitEvent({
607
+ type: "ForwardRunRequested",
608
+ target: successTransTarget.to,
609
+ scope,
610
+ origin: "goto_js",
611
+ gotoEvent: successTransTarget.goto_event
612
+ });
613
+ state.flags.forwardRunRequested = true;
614
+ }
615
+ return;
616
+ }
617
+ const gotoTarget = await evaluateGoto(
618
+ onSuccess.goto_js,
619
+ onSuccess.goto,
620
+ checkId,
621
+ checkConfig,
622
+ result,
623
+ context,
624
+ state
625
+ );
626
+ if (gotoTarget) {
627
+ if (checkLoopBudget(context, state, "on_success", "goto")) {
628
+ const errorIssue = {
629
+ file: "system",
630
+ line: 0,
631
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
632
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success goto`,
633
+ severity: "error",
634
+ category: "logic"
635
+ };
636
+ result.issues = [...result.issues || [], errorIssue];
637
+ return;
638
+ }
639
+ if (context.debug) {
640
+ logger.info(`[Routing] on_success.goto: ${gotoTarget}`);
641
+ }
642
+ state.routingLoopCount++;
643
+ emitEvent({
644
+ type: "ForwardRunRequested",
645
+ target: gotoTarget,
646
+ gotoEvent: onSuccess.goto_event,
647
+ scope,
648
+ origin: "goto_js"
649
+ });
650
+ state.flags.forwardRunRequested = true;
651
+ }
652
+ }
653
+ async function processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent) {
654
+ const defaults = context.config.routing?.defaults?.on_fail || {};
655
+ const onFail = checkConfig.on_fail ? { ...defaults, ...checkConfig.on_fail } : void 0;
656
+ if (!onFail) {
657
+ return;
658
+ }
659
+ if (context.debug) {
660
+ logger.info(`[Routing] Processing on_fail for ${checkId}`);
661
+ }
662
+ if (onFail.run && onFail.run.length > 0) {
663
+ const resForEachItems = result && result.forEachItems || void 0;
664
+ const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;
665
+ for (const targetCheck of onFail.run) {
666
+ if (checkLoopBudget(context, state, "on_fail", "run")) {
667
+ const errorIssue = {
668
+ file: "system",
669
+ line: 0,
670
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
671
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,
672
+ severity: "error",
673
+ category: "logic"
674
+ };
675
+ result.issues = [...result.issues || [], errorIssue];
676
+ return;
677
+ }
678
+ const targetConfig = context.config.checks?.[targetCheck];
679
+ const fanoutMode = targetConfig?.fanout || "reduce";
680
+ if (context.debug) {
681
+ logger.info(
682
+ `[Routing] on_fail.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`
683
+ );
684
+ }
685
+ if (hasForEachItems) {
686
+ for (let itemIndex = 0; itemIndex < resForEachItems.length; itemIndex++) {
687
+ const itemOut = resForEachItems[itemIndex];
688
+ if (itemOut && typeof itemOut === "object" && itemOut.__failed !== true && fanoutMode !== "map") {
689
+ continue;
690
+ }
691
+ state.routingLoopCount++;
692
+ const itemScope = [
693
+ { check: checkId, index: itemIndex }
694
+ ];
695
+ emitEvent({
696
+ type: "ForwardRunRequested",
697
+ target: targetCheck,
698
+ scope: itemScope,
699
+ origin: "run"
700
+ });
701
+ }
702
+ } else {
703
+ state.routingLoopCount++;
704
+ emitEvent({
705
+ type: "ForwardRunRequested",
706
+ target: targetCheck,
707
+ scope,
708
+ origin: "run"
709
+ });
710
+ }
711
+ }
712
+ }
713
+ if (onFail.run_js) {
714
+ const dynamicTargets = await evaluateRunJs(
715
+ onFail.run_js,
716
+ checkId,
717
+ checkConfig,
718
+ result,
719
+ context,
720
+ state
721
+ );
722
+ for (const targetCheck of dynamicTargets) {
723
+ if (checkLoopBudget(context, state, "on_fail", "run")) {
724
+ const errorIssue = {
725
+ file: "system",
726
+ line: 0,
727
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
728
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,
729
+ severity: "error",
730
+ category: "logic"
731
+ };
732
+ result.issues = [...result.issues || [], errorIssue];
733
+ return;
734
+ }
735
+ if (context.debug) {
736
+ logger.info(`[Routing] on_fail.run_js: scheduling ${targetCheck}`);
737
+ }
738
+ state.routingLoopCount++;
739
+ emitEvent({
740
+ type: "ForwardRunRequested",
741
+ target: targetCheck,
742
+ scope,
743
+ origin: "run_js"
744
+ });
745
+ }
746
+ }
747
+ if (onFail.retry && typeof onFail.retry.max === "number" && onFail.retry.max > 0) {
748
+ const crit = getCriticality(context, checkId);
749
+ const failureKind = classifyFailure(result);
750
+ if ((crit === "external" || crit === "internal") && failureKind === "logical") {
751
+ if (context.debug) {
752
+ logger.info(
753
+ `[Routing] on_fail.retry suppressed for ${checkId} (criticality=${crit}, failure=logical)`
754
+ );
755
+ }
756
+ } else {
757
+ const max = Math.max(0, onFail.retry.max || 0);
758
+ if (!state.retryAttempts) state.retryAttempts = /* @__PURE__ */ new Map();
759
+ const attemptsMap = state.retryAttempts;
760
+ const makeKey = (sc) => {
761
+ const keyScope = sc && sc.length > 0 ? JSON.stringify(sc) : "root";
762
+ return `${checkId}::${keyScope}`;
763
+ };
764
+ const scheduleRetryForScope = (sc) => {
765
+ const key = makeKey(sc);
766
+ const used = attemptsMap.get(key) || 0;
767
+ if (used >= max) return;
768
+ attemptsMap.set(key, used + 1);
769
+ state.routingLoopCount++;
770
+ emitEvent({
771
+ type: "ForwardRunRequested",
772
+ target: checkId,
773
+ scope: sc || [],
774
+ origin: "run"
775
+ });
776
+ };
777
+ const resForEachItems = result && result.forEachItems || void 0;
778
+ const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;
779
+ if (hasForEachItems) {
780
+ for (let i = 0; i < resForEachItems.length; i++) {
781
+ const itemOut = resForEachItems[i];
782
+ if (itemOut && typeof itemOut === "object" && itemOut.__failed === true) {
783
+ const sc = [{ check: checkId, index: i }];
784
+ scheduleRetryForScope(sc);
785
+ }
786
+ }
787
+ } else {
788
+ scheduleRetryForScope(scope);
789
+ }
790
+ }
791
+ }
792
+ const failTransTarget = await evaluateTransitions(
793
+ onFail.transitions,
794
+ checkId,
795
+ checkConfig,
796
+ result,
797
+ context,
798
+ state
799
+ );
800
+ if (failTransTarget !== void 0) {
801
+ if (failTransTarget) {
802
+ if (checkLoopBudget(context, state, "on_fail", "goto")) {
803
+ const errorIssue = {
804
+ file: "system",
805
+ line: 0,
806
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
807
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_fail goto`,
808
+ severity: "error",
809
+ category: "logic"
810
+ };
811
+ result.issues = [...result.issues || [], errorIssue];
812
+ return;
813
+ }
814
+ state.routingLoopCount++;
815
+ emitEvent({
816
+ type: "ForwardRunRequested",
817
+ target: failTransTarget.to,
818
+ scope,
819
+ origin: "goto_js",
820
+ gotoEvent: failTransTarget.goto_event
821
+ });
822
+ state.flags.forwardRunRequested = true;
823
+ }
824
+ return;
825
+ }
826
+ const gotoTarget = await evaluateGoto(
827
+ onFail.goto_js,
828
+ onFail.goto,
829
+ checkId,
830
+ checkConfig,
831
+ result,
832
+ context,
833
+ state
834
+ );
835
+ if (gotoTarget) {
836
+ if (checkLoopBudget(context, state, "on_fail", "goto")) {
837
+ const errorIssue = {
838
+ file: "system",
839
+ line: 0,
840
+ ruleId: `${checkId}/routing/loop_budget_exceeded`,
841
+ message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail goto`,
842
+ severity: "error",
843
+ category: "logic"
844
+ };
845
+ result.issues = [...result.issues || [], errorIssue];
846
+ return;
847
+ }
848
+ if (context.debug) {
849
+ logger.info(`[Routing] on_fail.goto: ${gotoTarget}`);
850
+ }
851
+ state.routingLoopCount++;
852
+ emitEvent({
853
+ type: "ForwardRunRequested",
854
+ target: gotoTarget,
855
+ gotoEvent: onFail.goto_event,
856
+ scope,
857
+ origin: "goto_js"
858
+ });
859
+ state.flags.forwardRunRequested = true;
860
+ }
861
+ }
862
+ async function evaluateRunJs(runJs, checkId, checkConfig, result, context, _state) {
863
+ try {
864
+ const sandbox = createSecureSandbox();
865
+ const snapshotId = context.journal.beginSnapshot();
866
+ const contextView = new (init_snapshot_store(), __toCommonJS(snapshot_store_exports)).ContextView(
867
+ context.journal,
868
+ context.sessionId,
869
+ snapshotId,
870
+ [],
871
+ context.event
872
+ );
873
+ const outputsRecord = {};
874
+ const outputsHistory = {};
875
+ const allEntries = context.journal.readVisible(context.sessionId, snapshotId, context.event);
876
+ const uniqueCheckIds = new Set(allEntries.map((e) => e.checkId));
877
+ for (const checkIdFromJournal of uniqueCheckIds) {
878
+ try {
879
+ const journalResult = contextView.get(checkIdFromJournal);
880
+ if (journalResult) {
881
+ outputsRecord[checkIdFromJournal] = journalResult.output !== void 0 ? journalResult.output : journalResult;
882
+ }
883
+ } catch {
884
+ outputsRecord[checkIdFromJournal] = { issues: [] };
885
+ }
886
+ try {
887
+ const history = contextView.getHistory(checkIdFromJournal);
888
+ if (history && history.length > 0) {
889
+ outputsHistory[checkIdFromJournal] = history.map(
890
+ (r) => r.output !== void 0 ? r.output : r
891
+ );
892
+ }
893
+ } catch {
894
+ }
895
+ }
896
+ outputsRecord.history = outputsHistory;
897
+ let forEachMeta = void 0;
898
+ try {
899
+ const hist = outputsHistory[checkId] || [];
900
+ const lastArr = hist.slice().reverse().find((x) => Array.isArray(x));
901
+ if (checkConfig.forEach === true && Array.isArray(lastArr)) {
902
+ forEachMeta = {
903
+ is_parent: true,
904
+ last_wave_size: lastArr.length,
905
+ last_items: lastArr
906
+ };
907
+ }
908
+ } catch {
909
+ }
910
+ const scopeObj = {
911
+ step: {
912
+ id: checkId,
913
+ tags: checkConfig.tags || [],
914
+ group: checkConfig.group
915
+ },
916
+ outputs: outputsRecord,
917
+ outputs_history: outputsHistory,
918
+ output: result?.output,
919
+ memory: createMemoryHelpers(),
920
+ event: {
921
+ name: context.event || "manual"
922
+ },
923
+ forEach: forEachMeta
924
+ };
925
+ const code = `
926
+ const step = scope.step;
927
+ const outputs = scope.outputs;
928
+ const outputs_history = scope.outputs_history;
929
+ const output = scope.output;
930
+ const memory = scope.memory;
931
+ const event = scope.event;
932
+ const forEach = scope.forEach;
933
+ const log = (...args) => console.log('\u{1F50D} Debug:', ...args);
934
+ const __fn = () => {
935
+ ${runJs}
936
+ };
937
+ const __res = __fn();
938
+ return Array.isArray(__res) ? __res.filter(x => typeof x === 'string' && x) : [];
939
+ `;
940
+ try {
941
+ const evalResult = compileAndRun(
942
+ sandbox,
943
+ code,
944
+ { scope: scopeObj },
945
+ { injectLog: false, wrapFunction: false }
946
+ );
947
+ return Array.isArray(evalResult) ? evalResult.filter(Boolean) : [];
948
+ } catch (_e) {
949
+ try {
950
+ const vm = __require("vm");
951
+ const context2 = vm.createContext({ scope: scopeObj, console: { log: () => {
952
+ } } });
953
+ const src = `(() => { ${runJs}
954
+ })()`;
955
+ const val = new vm.Script(src).runInContext(context2, { timeout: 100 });
956
+ return Array.isArray(val) ? val.filter((x) => typeof x === "string" && x) : [];
957
+ } catch (_vmErr) {
958
+ return [];
959
+ }
960
+ }
961
+ } catch (error) {
962
+ const msg = error instanceof Error ? error.message : String(error);
963
+ logger.error(`[Routing] Error evaluating run_js: ${msg}`);
964
+ return [];
965
+ }
966
+ }
967
+ async function evaluateGoto(gotoJs, gotoStatic, checkId, checkConfig, result, context, _state) {
968
+ if (gotoJs) {
969
+ try {
970
+ const sandbox = createSecureSandbox();
971
+ const snapshotId = context.journal.beginSnapshot();
972
+ const contextView = new (init_snapshot_store(), __toCommonJS(snapshot_store_exports)).ContextView(
973
+ context.journal,
974
+ context.sessionId,
975
+ snapshotId,
976
+ [],
977
+ void 0
978
+ );
979
+ const outputsRecord = {};
980
+ const outputsHistory = {};
981
+ const allEntries = context.journal.readVisible(context.sessionId, snapshotId, void 0);
982
+ const uniqueCheckIds = new Set(allEntries.map((e) => e.checkId));
983
+ for (const checkIdFromJournal of uniqueCheckIds) {
984
+ try {
985
+ const journalResult = contextView.get(checkIdFromJournal);
986
+ if (journalResult) {
987
+ outputsRecord[checkIdFromJournal] = journalResult.output !== void 0 ? journalResult.output : journalResult;
988
+ }
989
+ } catch {
990
+ outputsRecord[checkIdFromJournal] = { issues: [] };
991
+ }
992
+ try {
993
+ const history = contextView.getHistory(checkIdFromJournal);
994
+ if (history && history.length > 0) {
995
+ outputsHistory[checkIdFromJournal] = history.map(
996
+ (r) => r.output !== void 0 ? r.output : r
997
+ );
998
+ }
999
+ } catch {
1000
+ }
1001
+ }
1002
+ outputsRecord.history = outputsHistory;
1003
+ let forEachMeta = void 0;
1004
+ try {
1005
+ const hist = outputsHistory[checkId] || [];
1006
+ const lastArr = hist.slice().reverse().find((x) => Array.isArray(x));
1007
+ if (checkConfig.forEach === true && Array.isArray(lastArr)) {
1008
+ forEachMeta = {
1009
+ is_parent: true,
1010
+ last_wave_size: lastArr.length,
1011
+ last_items: lastArr
1012
+ };
1013
+ }
1014
+ } catch {
1015
+ }
1016
+ const scopeObj = {
1017
+ step: {
1018
+ id: checkId,
1019
+ tags: checkConfig.tags || [],
1020
+ group: checkConfig.group
1021
+ },
1022
+ outputs: outputsRecord,
1023
+ outputs_history: outputsHistory,
1024
+ output: result?.output,
1025
+ memory: createMemoryHelpers(),
1026
+ event: {
1027
+ name: context.event || "manual"
1028
+ },
1029
+ forEach: forEachMeta
1030
+ };
1031
+ if (context.debug) {
1032
+ logger.info(
1033
+ `[Routing] evaluateGoto: checkId=${checkId}, outputs_history keys=${Object.keys(outputsHistory).join(",")}`
1034
+ );
1035
+ for (const [key, values] of Object.entries(outputsHistory)) {
1036
+ logger.info(`[Routing] ${key}: ${values.length} items`);
1037
+ }
1038
+ }
1039
+ const code = `
1040
+ const step = scope.step;
1041
+ const outputs = scope.outputs;
1042
+ const outputs_history = scope.outputs_history;
1043
+ const output = scope.output;
1044
+ const memory = scope.memory;
1045
+ const event = scope.event;
1046
+ const forEach = scope.forEach;
1047
+ const log = (...args) => console.log('\u{1F50D} Debug:', ...args);
1048
+ ${gotoJs}
1049
+ `;
1050
+ try {
1051
+ const evalResult = compileAndRun(
1052
+ sandbox,
1053
+ code,
1054
+ { scope: scopeObj },
1055
+ { injectLog: false, wrapFunction: true }
1056
+ );
1057
+ if (context.debug) {
1058
+ logger.info(`[Routing] evaluateGoto result: ${evalResult}`);
1059
+ }
1060
+ if (typeof evalResult === "string" && evalResult) {
1061
+ return evalResult;
1062
+ }
1063
+ } catch (_e) {
1064
+ try {
1065
+ const vm = __require("vm");
1066
+ const contextObj = {
1067
+ step: scopeObj.step,
1068
+ outputs: scopeObj.outputs,
1069
+ outputs_history: scopeObj.outputs_history,
1070
+ output: scopeObj.output,
1071
+ memory: scopeObj.memory,
1072
+ event: scopeObj.event,
1073
+ forEach: scopeObj.forEach
1074
+ };
1075
+ const vmctx = vm.createContext(contextObj);
1076
+ const src = `(() => { ${gotoJs}
1077
+ })()`;
1078
+ const res = new vm.Script(src).runInContext(vmctx, { timeout: 100 });
1079
+ if (typeof res === "string" && res) return res;
1080
+ } catch (_vmErr) {
1081
+ }
1082
+ }
1083
+ } catch (error) {
1084
+ const msg = error instanceof Error ? error.message : String(error);
1085
+ logger.error(`[Routing] Error evaluating goto_js: ${msg}`);
1086
+ if (gotoStatic) {
1087
+ logger.info(`[Routing] Falling back to static goto: ${gotoStatic}`);
1088
+ return gotoStatic;
1089
+ }
1090
+ }
1091
+ }
1092
+ return gotoStatic || null;
1093
+ }
1094
+ async function evaluateTransitions(transitions, checkId, checkConfig, result, context, _state) {
1095
+ if (!transitions || transitions.length === 0) return void 0;
1096
+ try {
1097
+ const sandbox = createSecureSandbox();
1098
+ const snapshotId = context.journal.beginSnapshot();
1099
+ const ContextView2 = (init_snapshot_store(), __toCommonJS(snapshot_store_exports)).ContextView;
1100
+ const view = new ContextView2(context.journal, context.sessionId, snapshotId, [], void 0);
1101
+ const outputsRecord = {};
1102
+ const outputsHistory = {};
1103
+ const allEntries = context.journal.readVisible(context.sessionId, snapshotId, void 0);
1104
+ const uniqueCheckIds = new Set(allEntries.map((e) => e.checkId));
1105
+ for (const cid of uniqueCheckIds) {
1106
+ try {
1107
+ const jr = view.get(cid);
1108
+ if (jr) outputsRecord[cid] = jr.output !== void 0 ? jr.output : jr;
1109
+ } catch {
1110
+ }
1111
+ try {
1112
+ const hist = view.getHistory(cid);
1113
+ if (hist && hist.length > 0) {
1114
+ outputsHistory[cid] = hist.map((r) => r.output !== void 0 ? r.output : r);
1115
+ }
1116
+ } catch {
1117
+ }
1118
+ }
1119
+ outputsRecord.history = outputsHistory;
1120
+ const scopeObj = {
1121
+ step: { id: checkId, tags: checkConfig.tags || [], group: checkConfig.group },
1122
+ outputs: outputsRecord,
1123
+ outputs_history: outputsHistory,
1124
+ output: result?.output,
1125
+ memory: createMemoryHelpers(),
1126
+ event: { name: context.event || "manual" }
1127
+ };
1128
+ for (const rule of transitions) {
1129
+ const helpers = `
1130
+ const any = (arr, pred) => Array.isArray(arr) && arr.some(x => pred(x));
1131
+ const all = (arr, pred) => Array.isArray(arr) && arr.every(x => pred(x));
1132
+ const none = (arr, pred) => Array.isArray(arr) && !arr.some(x => pred(x));
1133
+ const count = (arr, pred) => Array.isArray(arr) ? arr.filter(x => pred(x)).length : 0;
1134
+ `;
1135
+ const code = `
1136
+ ${helpers}
1137
+ const step = scope.step;
1138
+ const outputs = scope.outputs;
1139
+ const outputs_history = scope.outputs_history;
1140
+ const output = scope.output;
1141
+ const memory = scope.memory;
1142
+ const event = scope.event;
1143
+ const __eval = () => { return (${rule.when}); };
1144
+ return __eval();
1145
+ `;
1146
+ let matched;
1147
+ try {
1148
+ matched = compileAndRun(
1149
+ sandbox,
1150
+ code,
1151
+ { scope: scopeObj },
1152
+ { injectLog: false, wrapFunction: false }
1153
+ );
1154
+ } catch (_e) {
1155
+ try {
1156
+ const vm = __require("vm");
1157
+ const helpersFns = {
1158
+ any: (arr, pred) => Array.isArray(arr) && arr.some(pred),
1159
+ all: (arr, pred) => Array.isArray(arr) && arr.every(pred),
1160
+ none: (arr, pred) => Array.isArray(arr) && !arr.some(pred),
1161
+ count: (arr, pred) => Array.isArray(arr) ? arr.filter(pred).length : 0
1162
+ };
1163
+ const context2 = vm.createContext({
1164
+ step: scopeObj.step,
1165
+ outputs: scopeObj.outputs,
1166
+ outputs_history: scopeObj.outputs_history,
1167
+ output: scopeObj.output,
1168
+ memory: scopeObj.memory,
1169
+ event: scopeObj.event,
1170
+ ...helpersFns
1171
+ });
1172
+ const res = new vm.Script(`(${rule.when})`).runInContext(context2, { timeout: 50 });
1173
+ matched = !!res;
1174
+ } catch (_vmErr) {
1175
+ matched = false;
1176
+ }
1177
+ }
1178
+ if (matched) {
1179
+ if (rule.to === null) return null;
1180
+ if (typeof rule.to === "string" && rule.to.length > 0) {
1181
+ return { to: rule.to, goto_event: rule.goto_event };
1182
+ }
1183
+ return null;
1184
+ }
1185
+ }
1186
+ return void 0;
1187
+ } catch (err) {
1188
+ logger.error(
1189
+ `[Routing] Error evaluating transitions: ${err instanceof Error ? err.message : String(err)}`
1190
+ );
1191
+ return void 0;
1192
+ }
1193
+ }
1194
+ var DEFAULT_MAX_LOOPS;
1195
+ var init_routing = __esm({
1196
+ "src/state-machine/states/routing.ts"() {
1197
+ init_logger();
1198
+ init_failure_condition_evaluator();
1199
+ init_sandbox();
1200
+ init_memory_store();
1201
+ DEFAULT_MAX_LOOPS = 10;
1202
+ }
1203
+ });
1204
+
1205
+ export {
1206
+ ExecutionJournal,
1207
+ snapshot_store_exports,
1208
+ init_snapshot_store,
1209
+ handleRouting,
1210
+ checkLoopBudget,
1211
+ evaluateGoto,
1212
+ evaluateTransitions,
1213
+ init_routing
1214
+ };
1215
+ //# sourceMappingURL=chunk-IEO6CFLG.mjs.map