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