@probelabs/visor 0.1.174-ee → 0.1.175

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 (91) hide show
  1. package/README.md +3 -2
  2. package/dist/cli-main.d.ts.map +1 -1
  3. package/dist/docs/guides/tdd-assistant-workflows.md +519 -0
  4. package/dist/docs/testing/dsl-reference.md +93 -0
  5. package/dist/examples/lifecycle-hooks.tests.yaml +62 -0
  6. package/dist/generated/config-schema.d.ts +28 -7
  7. package/dist/generated/config-schema.d.ts.map +1 -1
  8. package/dist/generated/config-schema.json +31 -7
  9. package/dist/index.js +352 -1864
  10. package/dist/output/traces/run-2026-03-09T18-49-07-663Z.ndjson +138 -0
  11. package/dist/output/traces/run-2026-03-09T18-49-46-345Z.ndjson +2296 -0
  12. package/dist/providers/ai-check-provider.d.ts.map +1 -1
  13. package/dist/providers/mcp-custom-sse-server.d.ts +4 -0
  14. package/dist/providers/mcp-custom-sse-server.d.ts.map +1 -1
  15. package/dist/sdk/a2a-frontend-ORLAU5GK.mjs +1658 -0
  16. package/dist/sdk/a2a-frontend-ORLAU5GK.mjs.map +1 -0
  17. package/dist/sdk/{check-provider-registry-53C2ZIXJ.mjs → check-provider-registry-7JPPJHVM.mjs} +3 -3
  18. package/dist/sdk/{check-provider-registry-UPQNHHFF.mjs → check-provider-registry-O36CQEGD.mjs} +3 -3
  19. package/dist/sdk/check-provider-registry-QCDV3SI6.mjs +30 -0
  20. package/dist/sdk/chunk-4FGX4SA6.mjs +516 -0
  21. package/dist/sdk/chunk-4FGX4SA6.mjs.map +1 -0
  22. package/dist/sdk/{chunk-2PL2YH3B.mjs → chunk-FZPCP444.mjs} +153 -14
  23. package/dist/sdk/chunk-FZPCP444.mjs.map +1 -0
  24. package/dist/sdk/chunk-HNK5ZJ2L.mjs +739 -0
  25. package/dist/sdk/chunk-HNK5ZJ2L.mjs.map +1 -0
  26. package/dist/sdk/{chunk-W4KCJM6J.mjs → chunk-MLXGCLZJ.mjs} +29 -8
  27. package/dist/sdk/chunk-MLXGCLZJ.mjs.map +1 -0
  28. package/dist/sdk/chunk-QAO73GUX.mjs +1502 -0
  29. package/dist/sdk/chunk-QAO73GUX.mjs.map +1 -0
  30. package/dist/sdk/{chunk-GKSSG5IM.mjs → chunk-TAK5HLAR.mjs} +155 -16
  31. package/dist/sdk/chunk-TAK5HLAR.mjs.map +1 -0
  32. package/dist/sdk/chunk-YVVOG7RP.mjs +45155 -0
  33. package/dist/sdk/chunk-YVVOG7RP.mjs.map +1 -0
  34. package/dist/sdk/{config-BVL3KFMB.mjs → config-4JMBJKWS.mjs} +2 -2
  35. package/dist/sdk/failure-condition-evaluator-RM5JJS4Q.mjs +18 -0
  36. package/dist/sdk/github-frontend-O5IAWXL5.mjs +1386 -0
  37. package/dist/sdk/github-frontend-O5IAWXL5.mjs.map +1 -0
  38. package/dist/sdk/{host-LRWIKURZ.mjs → host-WTJBWO4T.mjs} +3 -3
  39. package/dist/sdk/routing-AWOHU2WP.mjs +26 -0
  40. package/dist/sdk/{schedule-tool-5KDBDCFO.mjs → schedule-tool-DF5WUVYV.mjs} +3 -3
  41. package/dist/sdk/schedule-tool-L5G2BRIG.mjs +36 -0
  42. package/dist/sdk/{schedule-tool-UMDRCNO5.mjs → schedule-tool-XVSYLH4Z.mjs} +3 -3
  43. package/dist/sdk/{schedule-tool-handler-5EPTHBLS.mjs → schedule-tool-handler-CFMFHDUL.mjs} +3 -3
  44. package/dist/sdk/schedule-tool-handler-CFMFHDUL.mjs.map +1 -0
  45. package/dist/sdk/{schedule-tool-handler-MUF5V36L.mjs → schedule-tool-handler-JGWA4N3C.mjs} +3 -3
  46. package/dist/sdk/schedule-tool-handler-JGWA4N3C.mjs.map +1 -0
  47. package/dist/sdk/schedule-tool-handler-UJ4RFTW2.mjs +40 -0
  48. package/dist/sdk/schedule-tool-handler-UJ4RFTW2.mjs.map +1 -0
  49. package/dist/sdk/sdk.d.mts +9 -1
  50. package/dist/sdk/sdk.d.ts +9 -1
  51. package/dist/sdk/sdk.js +453 -1667
  52. package/dist/sdk/sdk.js.map +1 -1
  53. package/dist/sdk/sdk.mjs +5 -5
  54. package/dist/sdk/trace-helpers-4ERTVCZG.mjs +29 -0
  55. package/dist/sdk/trace-helpers-4ERTVCZG.mjs.map +1 -0
  56. package/dist/sdk/{workflow-check-provider-EWMZEEES.mjs → workflow-check-provider-ETM452BO.mjs} +3 -3
  57. package/dist/sdk/workflow-check-provider-ETM452BO.mjs.map +1 -0
  58. package/dist/sdk/workflow-check-provider-I3XLJP6V.mjs +30 -0
  59. package/dist/sdk/workflow-check-provider-I3XLJP6V.mjs.map +1 -0
  60. package/dist/sdk/{workflow-check-provider-RQUCBAYY.mjs → workflow-check-provider-Z6U7FZAF.mjs} +3 -3
  61. package/dist/sdk/workflow-check-provider-Z6U7FZAF.mjs.map +1 -0
  62. package/dist/test-runner/conversation-sugar.d.ts.map +1 -1
  63. package/dist/test-runner/index.d.ts +19 -0
  64. package/dist/test-runner/index.d.ts.map +1 -1
  65. package/dist/test-runner/validator.d.ts.map +1 -1
  66. package/dist/traces/run-2026-03-09T18-49-07-663Z.ndjson +138 -0
  67. package/dist/traces/run-2026-03-09T18-49-46-345Z.ndjson +2296 -0
  68. package/dist/types/config.d.ts +9 -1
  69. package/dist/types/config.d.ts.map +1 -1
  70. package/package.json +1 -1
  71. package/dist/sdk/chunk-2PL2YH3B.mjs.map +0 -1
  72. package/dist/sdk/chunk-GKSSG5IM.mjs.map +0 -1
  73. package/dist/sdk/chunk-W4KCJM6J.mjs.map +0 -1
  74. package/dist/sdk/knex-store-QCEW4I4R.mjs +0 -527
  75. package/dist/sdk/knex-store-QCEW4I4R.mjs.map +0 -1
  76. package/dist/sdk/loader-Q7K76ZIY.mjs +0 -89
  77. package/dist/sdk/loader-Q7K76ZIY.mjs.map +0 -1
  78. package/dist/sdk/opa-policy-engine-QCSSIMUF.mjs +0 -655
  79. package/dist/sdk/opa-policy-engine-QCSSIMUF.mjs.map +0 -1
  80. package/dist/sdk/validator-XTZJZZJH.mjs +0 -134
  81. package/dist/sdk/validator-XTZJZZJH.mjs.map +0 -1
  82. /package/dist/sdk/{check-provider-registry-53C2ZIXJ.mjs.map → check-provider-registry-7JPPJHVM.mjs.map} +0 -0
  83. /package/dist/sdk/{check-provider-registry-UPQNHHFF.mjs.map → check-provider-registry-O36CQEGD.mjs.map} +0 -0
  84. /package/dist/sdk/{config-BVL3KFMB.mjs.map → check-provider-registry-QCDV3SI6.mjs.map} +0 -0
  85. /package/dist/sdk/{schedule-tool-5KDBDCFO.mjs.map → config-4JMBJKWS.mjs.map} +0 -0
  86. /package/dist/sdk/{schedule-tool-UMDRCNO5.mjs.map → failure-condition-evaluator-RM5JJS4Q.mjs.map} +0 -0
  87. /package/dist/sdk/{host-LRWIKURZ.mjs.map → host-WTJBWO4T.mjs.map} +0 -0
  88. /package/dist/sdk/{schedule-tool-handler-5EPTHBLS.mjs.map → routing-AWOHU2WP.mjs.map} +0 -0
  89. /package/dist/sdk/{schedule-tool-handler-MUF5V36L.mjs.map → schedule-tool-DF5WUVYV.mjs.map} +0 -0
  90. /package/dist/sdk/{workflow-check-provider-EWMZEEES.mjs.map → schedule-tool-L5G2BRIG.mjs.map} +0 -0
  91. /package/dist/sdk/{workflow-check-provider-RQUCBAYY.mjs.map → schedule-tool-XVSYLH4Z.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/snapshot-store.ts","../../src/state-machine/states/routing.ts"],"sourcesContent":["/*\n * Internal snapshot store for incremental adoption of snapshot+scope execution.\n * Phase 0: journal only — no behavior change, used for future visibility work.\n */\n\nimport type { ReviewSummary } from './reviewer';\nimport type { EventTrigger } from './types/config';\n\nexport type ScopePath = Array<{ check: string; index: number }>;\n\nexport interface JournalEntry {\n commitId: number;\n sessionId: string;\n scope: ScopePath;\n checkId: string;\n event: EventTrigger | undefined;\n result: ReviewSummary & { output?: unknown; content?: string };\n}\n\nexport class ExecutionJournal {\n private commit = 0;\n private entries: JournalEntry[] = [];\n\n beginSnapshot(): number {\n return this.commit;\n }\n\n commitEntry(entry: {\n sessionId: string;\n scope: ScopePath;\n checkId: string;\n result: ReviewSummary & { output?: unknown; content?: string };\n event?: EventTrigger;\n }): JournalEntry {\n const committed: JournalEntry = {\n sessionId: entry.sessionId,\n scope: entry.scope,\n checkId: entry.checkId,\n result: entry.result,\n event: entry.event,\n commitId: ++this.commit,\n };\n this.entries.push(committed);\n return committed;\n }\n\n readVisible(sessionId: string, commitMax: number, event?: EventTrigger): JournalEntry[] {\n return this.entries.filter(\n e =>\n e.sessionId === sessionId && e.commitId <= commitMax && (event ? e.event === event : true)\n );\n }\n\n // Lightweight helpers for debugging/metrics\n size(): number {\n return this.entries.length;\n }\n}\n\nexport class ContextView {\n constructor(\n private journal: ExecutionJournal,\n private sessionId: string,\n private snapshotId: number,\n private scope: ScopePath,\n private event?: EventTrigger\n ) {}\n\n /** Return the nearest result for a check in this scope (exact item → ancestor → latest). */\n get(checkId: string): (ReviewSummary & { output?: unknown; content?: string }) | undefined {\n const visible = this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId);\n if (visible.length === 0) return undefined;\n\n // exact scope match: prefer the most recent commit for this scope\n const exactMatches = visible.filter(e => this.sameScope(e.scope, this.scope));\n if (exactMatches.length > 0) {\n return exactMatches[exactMatches.length - 1].result;\n }\n\n // nearest ancestor (shortest distance)\n let best: { entry: JournalEntry; dist: number } | undefined;\n for (const e of visible) {\n const dist = this.ancestorDistance(e.scope, this.scope);\n if (dist >= 0 && (best === undefined || dist < best.dist)) {\n best = { entry: e, dist };\n }\n }\n if (best) return best.entry.result;\n\n // fallback to latest committed result\n return visible[visible.length - 1]?.result;\n }\n\n /** Return an aggregate (raw) result – the shallowest scope for this check. */\n getRaw(checkId: string): (ReviewSummary & { output?: unknown; content?: string }) | undefined {\n const visible = this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId);\n if (visible.length === 0) return undefined;\n let shallow = visible[0];\n for (const e of visible) {\n if (e.scope.length < shallow.scope.length) shallow = e;\n }\n return shallow.result;\n }\n\n /** All results for a check up to this snapshot. */\n getHistory(checkId: string): Array<ReviewSummary & { output?: unknown; content?: string }> {\n return this.journal\n .readVisible(this.sessionId, this.snapshotId, this.event)\n .filter(e => e.checkId === checkId)\n .map(e => e.result);\n }\n\n private sameScope(a: ScopePath, b: ScopePath): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i].check !== b[i].check || a[i].index !== b[i].index) return false;\n }\n return true;\n }\n\n // distance from ancestor to current; -1 if not ancestor\n private ancestorDistance(ancestor: ScopePath, current: ScopePath): number {\n if (ancestor.length > current.length) return -1;\n // Treat root scope ([]) as non-ancestor for unrelated branches\n if (ancestor.length === 0 && current.length > 0) return -1;\n for (let i = 0; i < ancestor.length; i++) {\n if (ancestor[i].check !== current[i].check || ancestor[i].index !== current[i].index)\n return -1;\n }\n return current.length - ancestor.length;\n }\n}\n","/**\n * Routing State Handler\n *\n * Responsibilities:\n * - Evaluate fail_if conditions after check execution\n * - Process on_success, on_fail, on_finish triggers\n * - Enqueue ForwardRunRequested events for goto\n * - Enqueue WaveRetry events for routing loops\n * - Transition back to WavePlanning or Completed\n *\n * M2: Core routing logic implementation\n */\n\nimport type { EngineContext, RunState, EngineState, EngineEvent } from '../../types/engine';\nimport type { ReviewSummary, ReviewIssue } from '../../reviewer';\nimport type {\n CheckConfig,\n OnFailConfig,\n TransitionRule,\n OnSuccessRunItem,\n OnInitStepInvocation,\n OnInitWorkflowInvocation,\n} from '../../types/config';\nimport { logger } from '../../logger';\nimport { addEvent } from '../../telemetry/trace-helpers';\nimport { FailureConditionEvaluator } from '../../failure-condition-evaluator';\nimport { createSecureSandbox, compileAndRun } from '../../utils/sandbox';\nimport { MemoryStore } from '../../memory-store';\nimport { createExtendedLiquid } from '../../liquid-extensions';\n\n/**\n * Render Liquid template expressions in 'with' arguments for on_success.run.\n * This is called during routing, where we have access to the step's output.\n */\nasync function renderRouteArgs(\n args: Record<string, unknown> | undefined,\n output: unknown,\n dependencyResults: Record<string, unknown>,\n context: EngineContext\n): Promise<Record<string, unknown> | undefined> {\n if (!args || Object.keys(args).length === 0) {\n return args;\n }\n\n const liquid = createExtendedLiquid();\n const renderedArgs: Record<string, unknown> = {};\n\n // Build template context with output (current step) and outputs (all dependencies)\n const templateContext = {\n output: output, // Output of the step that triggered routing\n outputs: dependencyResults, // All dependency outputs\n env: process.env,\n inputs: (context.executionContext as any)?.workflowInputs || {},\n };\n\n for (const [key, value] of Object.entries(args)) {\n if (typeof value === 'string' && value.includes('{{')) {\n try {\n renderedArgs[key] = await liquid.parseAndRender(value, templateContext);\n } catch (error) {\n logger.warn(`[Routing] Failed to render template for arg ${key}: ${error}`);\n renderedArgs[key] = value;\n }\n } else {\n renderedArgs[key] = value;\n }\n }\n\n return renderedArgs;\n}\n\n/**\n * Helper to extract target name and args from an OnSuccessRunItem.\n * OnSuccessRunItem can be:\n * - string: plain step name\n * - OnInitStepInvocation: { step: string, with?: Record<string, unknown> }\n * - OnInitWorkflowInvocation: { workflow: string, with?: Record<string, unknown> }\n */\nfunction parseRunItem(item: OnSuccessRunItem): {\n target: string;\n args?: Record<string, unknown>;\n} {\n if (typeof item === 'string') {\n return { target: item };\n }\n if ('step' in item) {\n const stepItem = item as OnInitStepInvocation;\n return { target: stepItem.step, args: stepItem.with };\n }\n if ('workflow' in item) {\n const workflowItem = item as OnInitWorkflowInvocation;\n return { target: workflowItem.workflow, args: workflowItem.with };\n }\n // Fallback - shouldn't happen with proper typing\n return { target: String(item) };\n}\n\n/**\n * Check if any configured check depends (directly or via OR dependency) on the\n * given `checkId`. Used to decide whether a forEach parent has downstream\n * dependents, in which case its on_finish should defer to the LevelDispatch\n * post-children hook.\n */\n// hasDependents helper removed (unused)\n\n/**\n * Check if any dependent of `checkId` would execute with map fanout.\n * Used to decide whether a forEach parent's on_finish should be deferred to\n * the LevelDispatch post-children hook (only necessary when map-fanout children\n * will run per item).\n */\nfunction hasMapFanoutDependents(context: EngineContext, checkId: string): boolean {\n const checks = context.config.checks || {};\n const reduceProviders = new Set(['log', 'memory', 'script', 'workflow', 'noop']);\n\n for (const [cid, cfg] of Object.entries(checks)) {\n if (cid === checkId) continue;\n const rawDeps = (cfg as any).depends_on || [];\n const depList = Array.isArray(rawDeps) ? rawDeps : [rawDeps];\n // Does this check depend on our target?\n let depends = false;\n for (const dep of depList) {\n if (typeof dep !== 'string') continue;\n if (dep.includes('|')) {\n const opts = dep\n .split('|')\n .map(s => s.trim())\n .filter(Boolean);\n if (opts.includes(checkId)) {\n depends = true;\n break;\n }\n } else if (dep === checkId) {\n depends = true;\n break;\n }\n }\n if (!depends) continue;\n\n // Determine this dependent's fanout mode\n const explicit = (cfg as any).fanout as 'map' | 'reduce' | undefined;\n if (explicit === 'map') return true;\n if (explicit === 'reduce') continue;\n\n // Infer default based on provider type\n const providerType = context.checks[cid]?.providerType || (checks as any)[cid]?.type || '';\n const inferred: 'map' | 'reduce' = reduceProviders.has(providerType) ? 'reduce' : 'map';\n if (inferred === 'map') return true;\n }\n return false;\n}\n\n/** Classify failure type to inform retry policy mapping */\nfunction classifyFailure(result: ReviewSummary): 'none' | 'logical' | 'execution' {\n const issues = result?.issues || [];\n if (!issues || issues.length === 0) return 'none';\n // Heuristics:\n // - logical: fail_if, contract/guarantee_failed, explicit ruleIds ending with _fail_if\n // - execution: provider/command errors, timeouts, forEach/execution_error, sandbox_runner_error\n let hasLogical = false;\n let hasExecution = false;\n for (const iss of issues) {\n const id = String((iss as any).ruleId || '');\n const msg = String((iss as any).message || '');\n const msgLower = msg.toLowerCase();\n if (\n id.endsWith('_fail_if') ||\n id.includes('contract/guarantee_failed') ||\n id.includes('contract/schema_validation_failed')\n )\n hasLogical = true;\n if (\n id.endsWith('/error') ||\n id.includes('/execution_error') ||\n id.includes('timeout') ||\n msgLower.includes('timed out') ||\n msg.includes('Command execution failed')\n )\n hasExecution = true;\n if (id.includes('forEach/execution_error') || msg.includes('sandbox_runner_error'))\n hasExecution = true;\n }\n if (hasLogical && !hasExecution) return 'logical';\n if (hasExecution && !hasLogical) return 'execution';\n // Mixed or unknown: treat as execution to avoid suppressing retries unexpectedly\n return hasExecution ? 'execution' : 'logical';\n}\n\nfunction getCriticality(context: EngineContext, checkId: string): CheckConfig['criticality'] {\n const cfg = context.config.checks?.[checkId];\n return (cfg && (cfg as any).criticality) || 'policy';\n}\n\n/**\n * Context for a check that just completed and needs routing evaluation\n */\ninterface RoutingContext {\n checkId: string;\n scope: Array<{ check: string; index: number }>;\n result: ReviewSummary;\n checkConfig: CheckConfig;\n success: boolean; // true if no fatal issues\n}\n\n/**\n * Create memory helpers for sandbox context\n */\nfunction createMemoryHelpers() {\n const memoryStore = MemoryStore.getInstance();\n return {\n get: (key: string, ns?: string) => memoryStore.get(key, ns),\n has: (key: string, ns?: string) => memoryStore.has(key, ns),\n getAll: (ns?: string) => memoryStore.getAll(ns),\n set: (key: string, value: unknown, ns?: string) => {\n const nsName = ns || memoryStore.getDefaultNamespace();\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (!data.has(nsName)) data.set(nsName, new Map());\n data.get(nsName)!.set(key, value);\n },\n clear: (ns?: string) => {\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (ns) data.delete(ns);\n else data.clear();\n },\n increment: (key: string, amount = 1, ns?: string) => {\n const nsName = ns || memoryStore.getDefaultNamespace();\n const data: Map<string, Map<string, unknown>> = (memoryStore as any)['data'];\n if (!data.has(nsName)) data.set(nsName, new Map());\n const nsMap = data.get(nsName)!;\n const current = nsMap.get(key);\n const numCurrent = typeof current === 'number' ? current : 0;\n const newValue = numCurrent + amount;\n nsMap.set(key, newValue);\n return newValue;\n },\n };\n}\n\nfunction getHistoryLimit(): number | undefined {\n const raw = process.env.VISOR_TEST_HISTORY_LIMIT || process.env.VISOR_OUTPUT_HISTORY_LIMIT;\n if (!raw) return undefined;\n const n = parseInt(raw, 10);\n return Number.isFinite(n) && n > 0 ? n : undefined;\n}\n\ntype RoutingTrigger = 'on_success' | 'on_fail' | 'on_finish';\ntype RoutingAction = 'run' | 'goto' | 'retry';\ntype RoutingSource = 'run' | 'run_js' | 'goto' | 'goto_js' | 'transitions' | 'retry';\n\nfunction formatScopeLabel(scope: Array<{ check: string; index: number }> | undefined): string {\n if (!scope || scope.length === 0) return '';\n return scope.map(item => `${item.check}:${item.index}`).join('|');\n}\n\nfunction recordRoutingEvent(args: {\n checkId: string;\n trigger: RoutingTrigger;\n action: RoutingAction;\n target?: string;\n source?: RoutingSource;\n scope?: Array<{ check: string; index: number }>;\n gotoEvent?: string;\n}): void {\n const attrs: Record<string, unknown> = {\n check_id: args.checkId,\n trigger: args.trigger,\n action: args.action,\n };\n if (args.target) attrs.target = args.target;\n if (args.source) attrs.source = args.source;\n const scopeLabel = formatScopeLabel(args.scope);\n if (scopeLabel) attrs.scope = scopeLabel;\n if (args.gotoEvent) attrs.goto_event = args.gotoEvent;\n addEvent('visor.routing', attrs);\n}\n\n/**\n * Handle routing state - evaluate conditions and decide next actions\n * @returns true if execution was halted (caller should stop processing)\n */\nexport async function handleRouting(\n context: EngineContext,\n state: RunState,\n transition: (newState: EngineState) => void,\n emitEvent: (event: EngineEvent) => void,\n routingContext: RoutingContext\n): Promise<boolean> {\n const { checkId, scope, result, checkConfig, success } = routingContext;\n\n // Always log routing entry for debugging E2E expectations\n logger.info(`[Routing] Evaluating routing for check: ${checkId}, success: ${success}`);\n\n // Step 1: Evaluate fail_if and failure_conditions\n const failureResult = await evaluateFailIf(checkId, result, checkConfig, context, state);\n\n // Step 1.5: Check if we need to halt execution immediately\n if (failureResult.haltExecution) {\n logger.error(\n `[Routing] HALTING EXECUTION due to critical failure in ${checkId}: ${failureResult.haltMessage}`\n );\n\n // Add halt issue to result for reporting\n const haltIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_halt_execution`,\n message: `Execution halted: ${failureResult.haltMessage || 'Critical failure condition met'}`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), haltIssue];\n\n // Emit Shutdown event to stop the workflow\n emitEvent({\n type: 'Shutdown',\n error: {\n message: failureResult.haltMessage || `Execution halted by check ${checkId}`,\n name: 'HaltExecution',\n },\n });\n\n // Transition to Error state\n transition('Error');\n return true; // Signal that execution was halted\n }\n\n if (failureResult.failed) {\n if (context.debug) {\n logger.info(`[Routing] fail_if/failure_conditions triggered for ${checkId}`);\n }\n\n // Treat as failure for routing purposes\n await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);\n } else if (success) {\n // Step 2: Process on_success routing\n await processOnSuccess(checkId, scope, result, checkConfig, context, state, emitEvent);\n } else {\n // Step 3: Process on_fail routing\n await processOnFail(checkId, scope, result, checkConfig, context, state, emitEvent);\n }\n\n // Step 4: on_finish\n // Process on_finish here for:\n // - non-forEach checks\n // - forEach parents that do NOT have map-fanout dependents\n // (reduce-only dependents don't need the post-children barrier)\n const shouldProcessOnFinishHere =\n !!checkConfig.on_finish &&\n (checkConfig.forEach !== true || !hasMapFanoutDependents(context, checkId));\n if (checkConfig.on_finish) {\n logger.info(\n `[Routing] on_finish decision for ${checkId}: forEach=${!!checkConfig.forEach}, processHere=${shouldProcessOnFinishHere}`\n );\n }\n if (shouldProcessOnFinishHere) {\n await processOnFinish(checkId, scope, result, checkConfig, context, state, emitEvent);\n }\n\n // Transition back to WavePlanning to process queued events\n transition('WavePlanning');\n return false; // Execution continues normally\n}\n\n/**\n * Process on_finish routing\n */\nasync function processOnFinish(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n const onFinish = checkConfig.on_finish;\n\n if (!onFinish) {\n return; // No on_finish configuration\n }\n\n // Log at info level so it's visible in test output\n logger.info(`Processing on_finish for ${checkId}`);\n let queuedForward = false;\n // Process on_finish.run\n if (onFinish.run && onFinish.run.length > 0) {\n // Check if current check is a forEach parent with items\n const currentCheckIsForEach = checkConfig.forEach === true;\n const forEachItems = currentCheckIsForEach ? (result as any).forEachItems : undefined;\n const hasForEachItems = Array.isArray(forEachItems) && forEachItems.length > 0;\n\n for (const targetCheck of onFinish.run) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_finish', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_finish.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`\n );\n }\n\n // If current check has forEach items and target is map fanout, emit one event per item\n if (fanoutMode === 'map' && hasForEachItems) {\n // Map fanout: emit one ForwardRunRequested per forEach item\n for (let itemIndex = 0; itemIndex < forEachItems!.length; itemIndex++) {\n // Increment loop count for each item\n state.routingLoopCount++;\n\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n });\n queuedForward = true;\n }\n } else {\n // Reduce fanout (or no forEach context): emit with empty scope once\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: [],\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: [],\n origin: 'run',\n });\n queuedForward = true;\n }\n }\n }\n\n // Process on_finish.run_js\n if (onFinish.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onFinish.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const runItem of dynamicTargets) {\n // Parse the run item to extract target and optional args\n const { target: targetCheck, args: runArgs } = parseRunItem(runItem);\n\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_finish', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(\n `[Routing] on_finish.run_js: scheduling ${targetCheck}${runArgs ? ', args=' + JSON.stringify(runArgs) : ''}`\n );\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n args: runArgs,\n });\n queuedForward = true;\n }\n }\n\n // Declarative transitions (override goto/goto_js when present)\n const finishTransTarget = await evaluateTransitions(\n onFinish.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (finishTransTarget !== undefined) {\n if (finishTransTarget) {\n if (checkLoopBudget(context, state, 'on_finish', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'goto',\n target: finishTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: finishTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: finishTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: finishTransTarget.goto_event,\n });\n }\n return; // transitions override goto/goto_js\n }\n\n // Process on_finish.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onFinish.goto_js,\n onFinish.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_finish', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_finish goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_finish.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_finish',\n action: 'goto',\n target: gotoTarget,\n source: onFinish.goto_js ? 'goto_js' : 'goto',\n scope,\n });\n // Enqueue forward run event\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n\n // If we scheduled any forward-run targets via on_finish, request a wave retry so\n // dependent checks (with if conditions) can re-evaluate after the forward-run completes.\n // Guard: only enqueue once per originating check per wave to avoid loops.\n if (queuedForward) {\n const guardKey = `waveRetry:on_finish:${checkId}:wave:${state.wave}`;\n if (!(state as any).forwardRunGuards?.has(guardKey)) {\n (state as any).forwardRunGuards?.add(guardKey);\n emitEvent({ type: 'WaveRetry', reason: 'on_finish' });\n }\n }\n}\n\n/**\n * Result of evaluating failure conditions\n */\ninterface FailureEvaluationResult {\n /** Whether any failure condition was triggered */\n failed: boolean;\n /** Whether execution should halt immediately */\n haltExecution: boolean;\n /** Message describing the halt reason (if haltExecution is true) */\n haltMessage?: string;\n}\n\n/**\n * Evaluate fail_if and failure_conditions for a check\n */\n// Returns { failed, haltExecution } to indicate if check failed and if execution should halt.\n// Global fail_if records an issue for summary/reporting but MUST NOT gate routing.\n// failure_conditions with halt_execution: true will trigger workflow halt.\nasync function evaluateFailIf(\n checkId: string,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState\n): Promise<FailureEvaluationResult> {\n const config = context.config;\n\n // Check for fail_if at global or check level\n const globalFailIf = config.fail_if;\n const checkFailIf = checkConfig.fail_if;\n const globalFailureConditions = config.failure_conditions;\n const checkFailureConditions = checkConfig.failure_conditions;\n\n if (!globalFailIf && !checkFailIf && !globalFailureConditions && !checkFailureConditions) {\n return { failed: false, haltExecution: false }; // No failure conditions\n }\n\n const evaluator = new FailureConditionEvaluator();\n\n // Build outputs record from state\n const outputsRecord: Record<string, ReviewSummary> = {};\n for (const [key] of state.stats.entries()) {\n // Try to get the actual result from context.journal if available\n try {\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n context.event\n );\n const journalResult = contextView.get(key);\n if (journalResult) {\n outputsRecord[key] = journalResult as ReviewSummary;\n }\n } catch {\n // Fallback to empty result\n outputsRecord[key] = { issues: [] };\n }\n }\n\n const checkSchema = typeof checkConfig.schema === 'object' ? 'custom' : checkConfig.schema || '';\n const checkGroup = checkConfig.group || '';\n\n let anyFailed = false;\n let shouldHalt = false;\n let haltMessage: string | undefined;\n\n // Evaluate global fail_if (non-gating)\n if (globalFailIf) {\n try {\n const failed = await evaluator.evaluateSimpleCondition(\n checkId,\n checkSchema,\n checkGroup,\n result,\n globalFailIf,\n outputsRecord\n );\n\n if (failed) {\n logger.warn(`[Routing] Global fail_if triggered for ${checkId}: ${globalFailIf}`);\n\n // Add fail_if issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: 'global_fail_if',\n message: `Global failure condition met: ${globalFailIf}`,\n severity: 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n // IMPORTANT: do not gate routing on global fail_if\n // This condition contributes to overall run status but should not\n // block dependents from executing when the producing check succeeded.\n // Continue evaluating check-level fail_if below.\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating global fail_if: ${msg}`);\n }\n }\n\n // Evaluate check-specific fail_if\n if (checkFailIf) {\n try {\n const failed = await evaluator.evaluateSimpleCondition(\n checkId,\n checkSchema,\n checkGroup,\n result,\n checkFailIf,\n outputsRecord\n );\n\n if (failed) {\n logger.warn(`[Routing] Check fail_if triggered for ${checkId}: ${checkFailIf}`);\n\n // Add fail_if issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_fail_if`,\n message: `Check failure condition met: ${checkFailIf}`,\n severity: 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n anyFailed = true;\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating check fail_if: ${msg}`);\n }\n }\n\n // Evaluate failure_conditions (both global and check-level)\n // These support halt_execution: true\n if (globalFailureConditions || checkFailureConditions) {\n try {\n const conditionResults = await evaluator.evaluateConditions(\n checkId,\n checkSchema,\n checkGroup,\n result,\n globalFailureConditions,\n checkFailureConditions,\n outputsRecord\n );\n\n // Check for triggered conditions\n for (const condResult of conditionResults) {\n if (condResult.failed) {\n logger.warn(\n `[Routing] Failure condition '${condResult.conditionName}' triggered for ${checkId}: ${condResult.expression}`\n );\n\n // Add issue to result\n const failIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}_${condResult.conditionName}`,\n message: condResult.message || `Failure condition met: ${condResult.expression}`,\n severity: condResult.severity || 'error',\n category: 'logic',\n };\n\n result.issues = [...(result.issues || []), failIssue];\n anyFailed = true;\n\n // Check if this condition requires halting execution\n if (condResult.haltExecution) {\n shouldHalt = true;\n haltMessage =\n condResult.message ||\n `Execution halted: condition '${condResult.conditionName}' triggered`;\n logger.error(\n `[Routing] HALT EXECUTION triggered by '${condResult.conditionName}' for ${checkId}`\n );\n }\n }\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating failure_conditions: ${msg}`);\n }\n }\n\n return { failed: anyFailed, haltExecution: shouldHalt, haltMessage };\n}\n\n/**\n * Check if routing loop budget is exceeded\n */\nexport function checkLoopBudget(\n context: EngineContext,\n state: RunState,\n origin: 'on_success' | 'on_fail' | 'on_finish',\n action: 'run' | 'goto'\n): boolean {\n const maxLoops = context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS;\n\n if (state.routingLoopCount >= maxLoops) {\n const msg = `Routing loop budget exceeded (max_loops=${maxLoops}) during ${origin} ${action}`;\n logger.error(`[Routing] ${msg}`);\n return true; // Budget exceeded\n }\n\n return false; // Budget OK\n}\n\n/**\n * Process on_success routing\n */\nasync function processOnSuccess(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n const onSuccess = checkConfig.on_success;\n\n if (!onSuccess) {\n return; // No on_success configuration\n }\n\n if (context.debug) {\n logger.info(`[Routing] Processing on_success for ${checkId}`);\n }\n\n // Process on_success.run\n if (onSuccess.run && onSuccess.run.length > 0) {\n // Detect forEach context based on the actual result (aggregated map execution)\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n // Get the step's output for template rendering\n const stepOutput = (result as any)?.output;\n\n // Build dependency results from journal for template context\n const depResults: Record<string, unknown> = {};\n try {\n const snapshotId = context.journal.beginSnapshot();\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, context.event);\n for (const entry of allEntries) {\n if (entry.checkId && entry.result) {\n const r = entry.result as ReviewSummary & { output?: unknown };\n depResults[entry.checkId] = r.output !== undefined ? r.output : r;\n }\n }\n } catch (e) {\n logger.warn(`[Routing] Failed to build dependency results for template rendering: ${e}`);\n }\n\n for (const runItem of onSuccess.run) {\n // Parse the run item to extract target and optional args\n const { target: targetCheck, args: rawArgs } = parseRunItem(runItem);\n\n // Render Liquid templates in args if present\n const runArgs = rawArgs\n ? await renderRouteArgs(rawArgs, stepOutput, depResults, context)\n : undefined;\n\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_success', 'run')) {\n // Add error issue to result\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return; // Stop processing\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_success.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}${runArgs ? ', args=' + JSON.stringify(runArgs) : ''}`\n );\n }\n\n // If current check has forEach items and target is map fanout, emit one event per item\n if (fanoutMode === 'map' && hasForEachItems) {\n // Map fanout: emit one ForwardRunRequested per forEach item\n for (let itemIndex = 0; itemIndex < resForEachItems!.length; itemIndex++) {\n // Increment loop count for each item\n state.routingLoopCount++;\n\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n args: runArgs,\n });\n }\n } else {\n // Reduce fanout (or no forEach context): emit with empty scope once\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run',\n args: runArgs,\n });\n }\n }\n }\n\n // Process on_success.run_js\n if (onSuccess.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onSuccess.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const runItem of dynamicTargets) {\n // Parse the run item to extract target and optional args\n const { target: targetCheck, args: runArgs } = parseRunItem(runItem);\n\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_success', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(\n `[Routing] on_success.run_js: scheduling ${targetCheck}${runArgs ? ', args=' + JSON.stringify(runArgs) : ''}`\n );\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n args: runArgs,\n });\n }\n }\n\n // Declarative transitions for on_success (override goto/goto_js when present)\n const successTransTarget = await evaluateTransitions(\n onSuccess.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (successTransTarget !== undefined) {\n if (successTransTarget) {\n if (checkLoopBudget(context, state, 'on_success', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_success goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'goto',\n target: successTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: successTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: successTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: successTransTarget.goto_event,\n });\n state.flags.forwardRunRequested = true;\n }\n return;\n }\n\n // Process on_success.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onSuccess.goto_js,\n onSuccess.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_success', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_success goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_success.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_success',\n action: 'goto',\n target: gotoTarget,\n source: onSuccess.goto_js ? 'goto_js' : 'goto',\n scope,\n gotoEvent: onSuccess.goto_event,\n });\n // Enqueue forward run event with optional event override\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n gotoEvent: onSuccess.goto_event,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n}\n\n/**\n * Process on_fail routing\n */\nasync function processOnFail(\n checkId: string,\n scope: Array<{ check: string; index: number }>,\n result: ReviewSummary,\n checkConfig: CheckConfig,\n context: EngineContext,\n state: RunState,\n emitEvent: (event: EngineEvent) => void\n): Promise<void> {\n // Merge defaults with check-specific on_fail\n const defaults = context.config.routing?.defaults?.on_fail || {};\n const onFail: OnFailConfig | undefined = checkConfig.on_fail\n ? { ...defaults, ...checkConfig.on_fail }\n : undefined;\n\n if (!onFail) {\n return; // No on_fail configuration\n }\n\n if (context.debug) {\n logger.info(`[Routing] Processing on_fail for ${checkId}`);\n }\n\n // Process on_fail.run\n if (onFail.run && onFail.run.length > 0) {\n // Detect forEach context based on the actual aggregated result\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n for (const targetCheck of onFail.run) {\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_fail', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n // Handle fanout: check if target has fanout configuration\n const targetConfig = context.config.checks?.[targetCheck];\n const fanoutMode = targetConfig?.fanout || 'reduce'; // default to reduce\n\n if (context.debug) {\n logger.info(\n `[Routing] on_fail.run: scheduling ${targetCheck} with fanout=${fanoutMode}, hasForEachItems=${hasForEachItems}`\n );\n }\n\n // If current check ran in forEach context, schedule remediation per item\n if (hasForEachItems) {\n for (let itemIndex = 0; itemIndex < resForEachItems!.length; itemIndex++) {\n const itemOut = resForEachItems![itemIndex] as any;\n // Only remediate failed iterations if __failed is present; otherwise run for all\n if (\n itemOut &&\n typeof itemOut === 'object' &&\n itemOut.__failed !== true &&\n fanoutMode !== 'map'\n ) {\n // For reduce targets, skip successful iterations to avoid redundant runs\n continue;\n }\n\n state.routingLoopCount++;\n const itemScope: Array<{ check: string; index: number }> = [\n { check: checkId, index: itemIndex },\n ];\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope: itemScope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope: itemScope,\n origin: 'run',\n sourceCheck: checkId, // The failed check that triggered on_fail.run\n });\n }\n } else {\n // No forEach context: preserve current scope (if any)\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run',\n sourceCheck: checkId, // The failed check that triggered on_fail.run\n });\n }\n }\n }\n\n // Process on_fail.run_js\n if (onFail.run_js) {\n const dynamicTargets = await evaluateRunJs(\n onFail.run_js,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n for (const runItem of dynamicTargets) {\n // Parse the run item to extract target and optional args\n const { target: targetCheck, args: runArgs } = parseRunItem(runItem);\n\n // Check loop budget before scheduling\n if (checkLoopBudget(context, state, 'on_fail', 'run')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail run`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(\n `[Routing] on_fail.run_js: scheduling ${targetCheck}${runArgs ? ', args=' + JSON.stringify(runArgs) : ''}`\n );\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'run',\n target: targetCheck,\n source: 'run_js',\n scope,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: targetCheck,\n scope,\n origin: 'run_js',\n sourceCheck: checkId, // The failed check that triggered on_fail.run_js\n args: runArgs,\n });\n }\n }\n\n // Process on_fail.retry (schedule retry of the current check)\n if (onFail.retry && typeof onFail.retry.max === 'number' && onFail.retry.max > 0) {\n // Criticality mapping: for 'external' and 'internal', avoid automatic\n // retries for logical failures (fail_if/guarantee violations).\n const crit = getCriticality(context, checkId);\n const failureKind = classifyFailure(result);\n if ((crit === 'external' || crit === 'internal') && failureKind === 'logical') {\n if (context.debug) {\n logger.info(\n `[Routing] on_fail.retry suppressed for ${checkId} (criticality=${crit}, failure=logical)`\n );\n }\n // Skip retry scheduling\n } else {\n const max = Math.max(0, onFail.retry.max || 0);\n // Initialize retry attempt map on state\n if (!(state as any).retryAttempts) (state as any).retryAttempts = new Map<string, number>();\n const attemptsMap: Map<string, number> = (state as any).retryAttempts;\n\n const makeKey = (sc: Array<{ check: string; index: number }> | undefined) => {\n const keyScope = sc && sc.length > 0 ? JSON.stringify(sc) : 'root';\n return `${checkId}::${keyScope}`;\n };\n\n const scheduleRetryForScope = (sc: Array<{ check: string; index: number }> | undefined) => {\n const key = makeKey(sc);\n const used = attemptsMap.get(key) || 0;\n if (used >= max) return; // budget exhausted\n attemptsMap.set(key, used + 1);\n\n // Increment loop count and schedule forward run for the same check\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'retry',\n source: 'retry',\n scope: sc || [],\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: checkId,\n scope: sc || [],\n origin: 'run',\n });\n };\n\n const resForEachItems: any[] | undefined =\n (result && (result as any).forEachItems) || undefined;\n const hasForEachItems = Array.isArray(resForEachItems) && resForEachItems.length > 0;\n\n if (hasForEachItems) {\n for (let i = 0; i < resForEachItems!.length; i++) {\n const itemOut = resForEachItems![i] as any;\n // Only retry failed iterations (marked by __failed)\n if (itemOut && typeof itemOut === 'object' && itemOut.__failed === true) {\n const sc: Array<{ check: string; index: number }> = [{ check: checkId, index: i }];\n scheduleRetryForScope(sc);\n }\n }\n } else {\n scheduleRetryForScope(scope);\n }\n\n // Note: backoff.delay_ms and mode are intentionally not awaited here; the\n // state-machine processes retries as subsequent waves. If needed later, we\n // can insert a timed wait in the orchestrator layer.\n }\n }\n\n // Declarative transitions for on_fail (override goto/goto_js when present)\n const failTransTarget = await evaluateTransitions(\n onFail.transitions,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n if (failTransTarget !== undefined) {\n if (failTransTarget) {\n if (checkLoopBudget(context, state, 'on_fail', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? DEFAULT_MAX_LOOPS}) during on_fail goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n state.routingLoopCount++;\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'goto',\n target: failTransTarget.to,\n source: 'transitions',\n scope,\n gotoEvent: failTransTarget.goto_event,\n });\n emitEvent({\n type: 'ForwardRunRequested',\n target: failTransTarget.to,\n scope,\n origin: 'goto_js',\n gotoEvent: failTransTarget.goto_event,\n });\n state.flags.forwardRunRequested = true;\n }\n return;\n }\n\n // Process on_fail.goto / goto_js\n const gotoTarget = await evaluateGoto(\n onFail.goto_js,\n onFail.goto,\n checkId,\n checkConfig,\n result,\n context,\n state\n );\n\n if (gotoTarget) {\n // Check loop budget before scheduling goto\n if (checkLoopBudget(context, state, 'on_fail', 'goto')) {\n const errorIssue: ReviewIssue = {\n file: 'system',\n line: 0,\n ruleId: `${checkId}/routing/loop_budget_exceeded`,\n message: `Routing loop budget exceeded (max_loops=${context.config.routing?.max_loops ?? 10}) during on_fail goto`,\n severity: 'error',\n category: 'logic',\n };\n result.issues = [...(result.issues || []), errorIssue];\n return;\n }\n\n if (context.debug) {\n logger.info(`[Routing] on_fail.goto: ${gotoTarget}`);\n }\n\n // Increment loop count\n state.routingLoopCount++;\n\n recordRoutingEvent({\n checkId,\n trigger: 'on_fail',\n action: 'goto',\n target: gotoTarget,\n source: onFail.goto_js ? 'goto_js' : 'goto',\n scope,\n gotoEvent: onFail.goto_event,\n });\n // Enqueue forward run event with optional event override\n emitEvent({\n type: 'ForwardRunRequested',\n target: gotoTarget,\n gotoEvent: onFail.goto_event,\n scope,\n origin: 'goto_js',\n });\n\n // Mark that we've seen a forward run\n state.flags.forwardRunRequested = true;\n }\n}\n\n/**\n * Evaluate run_js expression to get dynamic check targets\n */\n/**\n * Validate that an item is a valid OnSuccessRunItem (string or object with step/workflow)\n */\nfunction isValidRunItem(item: unknown): item is OnSuccessRunItem {\n if (typeof item === 'string' && item) return true;\n if (typeof item === 'object' && item !== null) {\n const obj = item as Record<string, unknown>;\n if (typeof obj.step === 'string' && obj.step) return true;\n if (typeof obj.workflow === 'string' && obj.workflow) return true;\n }\n return false;\n}\n\nasync function evaluateRunJs(\n runJs: string,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<OnSuccessRunItem[]> {\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n context.event\n );\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n\n // Get all visible journal entries to build complete history\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, context.event);\n const uniqueCheckIds = new Set(allEntries.map(e => e.checkId));\n\n for (const checkIdFromJournal of uniqueCheckIds) {\n try {\n // Get current output for this check\n const journalResult = contextView.get(checkIdFromJournal);\n if (journalResult) {\n // Prefer the output field if present, otherwise use the full result\n outputsRecord[checkIdFromJournal] =\n journalResult.output !== undefined ? journalResult.output : journalResult;\n }\n } catch {\n outputsRecord[checkIdFromJournal] = { issues: [] };\n }\n\n // Build history for this check\n try {\n const history = contextView.getHistory(checkIdFromJournal);\n if (history && history.length > 0) {\n const trimmed =\n historyLimit && history.length > historyLimit\n ? history.slice(history.length - historyLimit)\n : history;\n // Extract outputs from history (prefer output field if available)\n outputsHistory[checkIdFromJournal] = trimmed.map((r: any) =>\n r.output !== undefined ? r.output : r\n );\n }\n } catch {\n // Ignore history errors\n }\n }\n\n // Add history as a property on outputs object for convenient access\n outputsRecord.history = outputsHistory;\n\n // Compute minimal forEach metadata for run_js parity\n let forEachMeta: any = undefined;\n try {\n const hist = outputsHistory[checkId] || [];\n const lastArr = (hist as any[])\n .slice()\n .reverse()\n .find((x: any) => Array.isArray(x));\n if (checkConfig.forEach === true && Array.isArray(lastArr)) {\n forEachMeta = {\n is_parent: true,\n last_wave_size: lastArr.length,\n last_items: lastArr,\n };\n }\n } catch {}\n\n const scopeObj: any = {\n step: {\n id: checkId,\n tags: checkConfig.tags || [],\n group: checkConfig.group,\n },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: {\n name: context.event || 'manual',\n },\n forEach: forEachMeta,\n };\n\n const code = `\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const forEach = scope.forEach;\n const log = (...args) => console.log('🔍 Debug:', ...args);\n const __fn = () => {\n ${runJs}\n };\n const __res = __fn();\n // Return as-is; validation happens after sandbox execution\n return Array.isArray(__res) ? __res : [];\n `;\n\n try {\n const evalResult = compileAndRun<unknown[]>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: false }\n );\n // Filter to valid run items (strings or objects with step/workflow)\n return Array.isArray(evalResult) ? evalResult.filter(isValidRunItem) : [];\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error in run_js sandbox evaluation: ${msg}`);\n return [];\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating run_js: ${msg}`);\n return [];\n }\n}\n\n/**\n * Evaluate goto_js or return static goto target\n */\nexport async function evaluateGoto(\n gotoJs: string | undefined,\n gotoStatic: string | undefined,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<string | null> {\n // Evaluate goto_js first\n if (gotoJs) {\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history from the full session snapshot.\n // Do not filter by event here — on_finish (especially forEach post-children) may\n // need to see results committed under different event triggers within the same run.\n const snapshotId = context.journal.beginSnapshot();\n const contextView = new (require('../../snapshot-store').ContextView)(\n context.journal,\n context.sessionId,\n snapshotId,\n [],\n undefined\n );\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n\n // Get all visible journal entries to build complete history\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, undefined);\n const uniqueCheckIds = new Set(allEntries.map(e => e.checkId));\n\n for (const checkIdFromJournal of uniqueCheckIds) {\n try {\n // Get current output for this check\n const journalResult = contextView.get(checkIdFromJournal);\n if (journalResult) {\n // Prefer the output field if present, otherwise use the full result\n outputsRecord[checkIdFromJournal] =\n journalResult.output !== undefined ? journalResult.output : journalResult;\n }\n } catch {\n outputsRecord[checkIdFromJournal] = { issues: [] };\n }\n\n // Build history for this check\n try {\n const history = contextView.getHistory(checkIdFromJournal);\n if (history && history.length > 0) {\n const trimmed =\n historyLimit && history.length > historyLimit\n ? history.slice(history.length - historyLimit)\n : history;\n // Extract outputs from history (prefer output field if available)\n outputsHistory[checkIdFromJournal] = trimmed.map((r: any) =>\n r.output !== undefined ? r.output : r\n );\n }\n } catch {\n // Ignore history errors\n }\n }\n\n // Add history as a property on outputs object for convenient access\n outputsRecord.history = outputsHistory;\n\n // Compute minimal forEach metadata for convenience in goto_js\n // - last_wave_size: number of items in the latest root-scope array output\n // - last_items: the latest array output itself (if available)\n let forEachMeta: any = undefined;\n try {\n const hist = outputsHistory[checkId] || [];\n const lastArr = (hist as any[])\n .slice()\n .reverse()\n .find((x: any) => Array.isArray(x));\n if (checkConfig.forEach === true && Array.isArray(lastArr)) {\n forEachMeta = {\n is_parent: true,\n last_wave_size: lastArr.length,\n last_items: lastArr,\n };\n }\n } catch {}\n\n const scopeObj: any = {\n step: {\n id: checkId,\n tags: checkConfig.tags || [],\n group: checkConfig.group,\n },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: {\n name: context.event || 'manual',\n },\n forEach: forEachMeta,\n };\n\n // Debug: Log outputs_history\n if (context.debug) {\n logger.info(\n `[Routing] evaluateGoto: checkId=${checkId}, outputs_history keys=${Object.keys(outputsHistory).join(',')}`\n );\n for (const [key, values] of Object.entries(outputsHistory)) {\n logger.info(`[Routing] ${key}: ${values.length} items`);\n }\n }\n\n const code = `\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const forEach = scope.forEach;\n const log = (...args) => console.log('🔍 Debug:', ...args);\n ${gotoJs}\n `;\n\n try {\n const evalResult = compileAndRun<string | null>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: true }\n );\n\n if (context.debug) {\n logger.info(`[Routing] evaluateGoto result: ${evalResult}`);\n }\n\n if (typeof evalResult === 'string' && evalResult) {\n return evalResult;\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error in goto_js sandbox evaluation: ${msg}`);\n // Fall through to static goto\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.error(`[Routing] Error evaluating goto_js: ${msg}`);\n\n // Fall back to static goto if available\n if (gotoStatic) {\n logger.info(`[Routing] Falling back to static goto: ${gotoStatic}`);\n return gotoStatic;\n }\n }\n }\n\n // Return static goto\n return gotoStatic || null;\n}\n// Default values (used only when config is absent)\nconst DEFAULT_MAX_LOOPS = 10;\n\n/**\n * Evaluate declarative transitions. Returns:\n * - { to, goto_event } when a rule matches,\n * - null (explicit) when a rule matches with to=null,\n * - undefined when no rule matched or transitions is empty.\n */\nexport async function evaluateTransitions(\n transitions: TransitionRule[] | undefined,\n checkId: string,\n checkConfig: CheckConfig,\n result: ReviewSummary,\n context: EngineContext,\n _state: RunState\n): Promise<\n { to: string; goto_event?: import('../../types/config').EventTrigger } | null | undefined\n> {\n if (!transitions || transitions.length === 0) return undefined;\n try {\n const sandbox = createSecureSandbox();\n const historyLimit = getHistoryLimit();\n\n // Build outputs record and outputs_history from the full session snapshot\n const snapshotId = context.journal.beginSnapshot();\n const ContextView = (require('../../snapshot-store') as any).ContextView;\n const view = new ContextView(context.journal, context.sessionId, snapshotId, [], undefined);\n\n const outputsRecord: Record<string, any> = {};\n const outputsHistory: Record<string, any[]> = {};\n const allEntries = context.journal.readVisible(context.sessionId, snapshotId, undefined);\n const uniqueCheckIds = new Set(allEntries.map((e: any) => e.checkId));\n for (const cid of uniqueCheckIds) {\n try {\n const jr = view.get(cid);\n if (jr) outputsRecord[cid] = jr.output !== undefined ? jr.output : jr;\n } catch {}\n try {\n const hist = view.getHistory(cid);\n if (hist && hist.length > 0) {\n const trimmed =\n historyLimit && hist.length > historyLimit\n ? hist.slice(hist.length - historyLimit)\n : hist;\n outputsHistory[cid] = trimmed.map((r: any) => (r.output !== undefined ? r.output : r));\n }\n } catch {}\n }\n outputsRecord.history = outputsHistory;\n\n const scopeObj: any = {\n step: { id: checkId, tags: checkConfig.tags || [], group: checkConfig.group },\n outputs: outputsRecord,\n outputs_history: outputsHistory,\n output: (result as any)?.output,\n memory: createMemoryHelpers(),\n event: { name: context.event || 'manual' },\n };\n\n for (const rule of transitions) {\n const helpers = `\n const any = (arr, pred) => Array.isArray(arr) && arr.some(x => pred(x));\n const all = (arr, pred) => Array.isArray(arr) && arr.every(x => pred(x));\n const none = (arr, pred) => Array.isArray(arr) && !arr.some(x => pred(x));\n const count = (arr, pred) => Array.isArray(arr) ? arr.filter(x => pred(x)).length : 0;\n `;\n // Mirror the variable exposure pattern used in goto_js/run_js so that\n // `when:` expressions can reference `outputs`, `outputs_history`, `event`, etc.\n const code = `\n ${helpers}\n const step = scope.step;\n const outputs = scope.outputs;\n const outputs_history = scope.outputs_history;\n const output = scope.output;\n const memory = scope.memory;\n const event = scope.event;\n const __eval = () => { return (${rule.when}); };\n return __eval();\n `;\n let matched: boolean | undefined;\n try {\n matched = compileAndRun<boolean>(\n sandbox,\n code,\n { scope: scopeObj },\n { injectLog: false, wrapFunction: false }\n );\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n logger.warn(`[Routing] Error evaluating transition 'when' clause: ${msg}`);\n matched = false;\n }\n if (matched) {\n if (rule.to === null) return null;\n if (typeof rule.to === 'string' && rule.to.length > 0) {\n return { to: rule.to, goto_event: (rule as any).goto_event };\n }\n return null;\n }\n }\n return undefined;\n } catch (err) {\n logger.error(\n `[Routing] Error evaluating transitions: ${err instanceof Error ? err.message : String(err)}`\n );\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmBa,kBAwCA;AA3Db;AAAA;AAAA;AAmBO,IAAM,mBAAN,MAAuB;AAAA,MACpB,SAAS;AAAA,MACT,UAA0B,CAAC;AAAA,MAEnC,gBAAwB;AACtB,eAAO,KAAK;AAAA,MACd;AAAA,MAEA,YAAY,OAMK;AACf,cAAM,YAA0B;AAAA,UAC9B,WAAW,MAAM;AAAA,UACjB,OAAO,MAAM;AAAA,UACb,SAAS,MAAM;AAAA,UACf,QAAQ,MAAM;AAAA,UACd,OAAO,MAAM;AAAA,UACb,UAAU,EAAE,KAAK;AAAA,QACnB;AACA,aAAK,QAAQ,KAAK,SAAS;AAC3B,eAAO;AAAA,MACT;AAAA,MAEA,YAAY,WAAmB,WAAmB,OAAsC;AACtF,eAAO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} from "./chunk-W4KCJM6J.mjs";
46
+ } from "./chunk-MLXGCLZJ.mjs";
47
47
  import {
48
48
  ExecutionJournal,
49
49
  checkLoopBudget,
@@ -4006,7 +4006,7 @@ async function executeWorkflowAsTool(workflowId, args, context2, argsOverrides)
4006
4006
  ...args,
4007
4007
  ...argsOverrides
4008
4008
  };
4009
- const { WorkflowCheckProvider: WorkflowCheckProvider2 } = await import("./workflow-check-provider-RQUCBAYY.mjs");
4009
+ const { WorkflowCheckProvider: WorkflowCheckProvider2 } = await import("./workflow-check-provider-Z6U7FZAF.mjs");
4010
4010
  const provider = new WorkflowCheckProvider2();
4011
4011
  const checkConfig = {
4012
4012
  type: "workflow",
@@ -13348,7 +13348,7 @@ var init_state_machine_execution_engine = __esm({
13348
13348
  try {
13349
13349
  const map = options?.webhookContext?.webhookData;
13350
13350
  if (map) {
13351
- const { CheckProviderRegistry: CheckProviderRegistry2 } = await import("./check-provider-registry-53C2ZIXJ.mjs");
13351
+ const { CheckProviderRegistry: CheckProviderRegistry2 } = await import("./check-provider-registry-7JPPJHVM.mjs");
13352
13352
  const reg = CheckProviderRegistry2.getInstance();
13353
13353
  const p = reg.getProvider("http_input");
13354
13354
  if (p && typeof p.setWebhookContext === "function") p.setWebhookContext(map);
@@ -13461,7 +13461,7 @@ var init_state_machine_execution_engine = __esm({
13461
13461
  logger.info("[StateMachine] Using state machine engine");
13462
13462
  }
13463
13463
  if (!config) {
13464
- const { ConfigManager } = await import("./config-BVL3KFMB.mjs");
13464
+ const { ConfigManager } = await import("./config-4JMBJKWS.mjs");
13465
13465
  const configManager = new ConfigManager();
13466
13466
  config = await configManager.getDefaultConfig();
13467
13467
  logger.debug("[StateMachine] Using default configuration (no config provided)");
@@ -13471,7 +13471,7 @@ var init_state_machine_execution_engine = __esm({
13471
13471
  tag_filter: tagFilter
13472
13472
  } : config;
13473
13473
  try {
13474
- const { CheckProviderRegistry: CheckProviderRegistry2 } = await import("./check-provider-registry-53C2ZIXJ.mjs");
13474
+ const { CheckProviderRegistry: CheckProviderRegistry2 } = await import("./check-provider-registry-7JPPJHVM.mjs");
13475
13475
  const registry = CheckProviderRegistry2.getInstance();
13476
13476
  registry.setCustomTools(configWithTagFilter.tools || {});
13477
13477
  } catch (error) {
@@ -13512,7 +13512,7 @@ var init_state_machine_execution_engine = __esm({
13512
13512
  logger.debug(
13513
13513
  `[PolicyEngine] Loading enterprise policy engine (engine=${configWithTagFilter.policy.engine})`
13514
13514
  );
13515
- const { loadEnterprisePolicyEngine } = await import("./loader-Q7K76ZIY.mjs");
13515
+ const { loadEnterprisePolicyEngine } = await import("./enterprise/loader");
13516
13516
  context2.policyEngine = await loadEnterprisePolicyEngine(configWithTagFilter.policy);
13517
13517
  logger.debug(
13518
13518
  `[PolicyEngine] Initialized: ${context2.policyEngine?.constructor?.name || "unknown"}`
@@ -13535,7 +13535,7 @@ var init_state_machine_execution_engine = __esm({
13535
13535
  try {
13536
13536
  const webhookData = this.executionContext?.webhookContext?.webhookData;
13537
13537
  if (webhookData instanceof Map) {
13538
- const { extractSlackContext: extractSlackContext2 } = await import("./schedule-tool-handler-MUF5V36L.mjs");
13538
+ const { extractSlackContext: extractSlackContext2 } = await import("./schedule-tool-handler-JGWA4N3C.mjs");
13539
13539
  const slackCtx = extractSlackContext2(webhookData);
13540
13540
  if (slackCtx) {
13541
13541
  const payload = Array.from(webhookData.values())[0];
@@ -13564,7 +13564,7 @@ var init_state_machine_execution_engine = __esm({
13564
13564
  if (Array.isArray(configWithTagFilter.frontends) && configWithTagFilter.frontends.length > 0) {
13565
13565
  try {
13566
13566
  const { EventBus } = await import("./event-bus-5K3Y2FCS.mjs");
13567
- const { FrontendsHost } = await import("./host-LRWIKURZ.mjs");
13567
+ const { FrontendsHost } = await import("./host-6TBS44ER.mjs");
13568
13568
  const bus = new EventBus();
13569
13569
  context2.eventBus = bus;
13570
13570
  frontendsHost = new FrontendsHost(bus, logger);
@@ -16069,6 +16069,9 @@ var init_schedule_tool_handler = __esm({
16069
16069
  // src/providers/mcp-custom-sse-server.ts
16070
16070
  import http from "http";
16071
16071
  import { EventEmitter } from "events";
16072
+ function isHttpClientTool(tool) {
16073
+ return Boolean(tool && tool.type === "http_client" && (tool.base_url || tool.url));
16074
+ }
16072
16075
  var CustomToolsSSEServer;
16073
16076
  var init_mcp_custom_sse_server = __esm({
16074
16077
  "src/providers/mcp-custom-sse-server.ts"() {
@@ -16080,6 +16083,7 @@ var init_mcp_custom_sse_server = __esm({
16080
16083
  init_workflow_registry();
16081
16084
  init_schedule_tool();
16082
16085
  init_schedule_tool_handler();
16086
+ init_env_resolver();
16083
16087
  CustomToolsSSEServer = class _CustomToolsSSEServer {
16084
16088
  server = null;
16085
16089
  port = 0;
@@ -16113,10 +16117,12 @@ var init_mcp_custom_sse_server = __esm({
16113
16117
  }
16114
16118
  }
16115
16119
  for (const [name, tool] of this.tools.entries()) {
16116
- if (!isWorkflowTool(tool)) {
16117
- toolsRecord[name] = tool;
16120
+ if (isWorkflowTool(tool) || isHttpClientTool(tool)) {
16121
+ if (isWorkflowTool(tool)) {
16122
+ workflowToolNames.push(name);
16123
+ }
16118
16124
  } else {
16119
- workflowToolNames.push(name);
16125
+ toolsRecord[name] = tool;
16120
16126
  }
16121
16127
  }
16122
16128
  if (workflowToolNames.length > 0 && !workflowContext) {
@@ -16596,7 +16602,12 @@ var init_mcp_custom_sse_server = __esm({
16596
16602
  description: tool.description || `Execute ${tool.name}`,
16597
16603
  inputSchema: normalizeInputSchema(tool.inputSchema)
16598
16604
  }));
16599
- const allTools = [...regularTools, ...workflowTools];
16605
+ const httpClientTools = Array.from(this.tools.values()).filter(isHttpClientTool).map((tool) => ({
16606
+ name: tool.name,
16607
+ description: tool.description || `Call ${tool.name} HTTP API`,
16608
+ inputSchema: normalizeInputSchema(tool.inputSchema)
16609
+ }));
16610
+ const allTools = [...regularTools, ...workflowTools, ...httpClientTools];
16600
16611
  if (this.debug) {
16601
16612
  logger.debug(
16602
16613
  `[CustomToolsSSEServer:${this.sessionId}] Listing ${allTools.length} tools: ${allTools.map((t) => t.name).join(", ")}`
@@ -16720,6 +16731,8 @@ var init_mcp_custom_sse_server = __esm({
16720
16731
  this.workflowContext,
16721
16732
  workflowTool.__argsOverrides
16722
16733
  );
16734
+ } else if (tool && isHttpClientTool(tool)) {
16735
+ result = await this.executeHttpClientTool(tool, args);
16723
16736
  } else {
16724
16737
  result = await this.toolExecutor.execute(toolName, args);
16725
16738
  }
@@ -16783,6 +16796,83 @@ var init_mcp_custom_sse_server = __esm({
16783
16796
  }
16784
16797
  }
16785
16798
  }
16799
+ /**
16800
+ * Execute an http_client tool — proxy REST API calls through the configured base URL.
16801
+ */
16802
+ async executeHttpClientTool(tool, args) {
16803
+ const baseUrl = (tool.base_url || tool.url).replace(/\/+$/, "");
16804
+ const apiPath = args.path || "";
16805
+ const method = (args.method || "GET").toUpperCase();
16806
+ const queryParams = args.query || {};
16807
+ const body = args.body;
16808
+ const toolHeaders = tool.headers || {};
16809
+ const timeout = tool.timeout || 3e4;
16810
+ let url = apiPath.startsWith("http") ? apiPath : `${baseUrl}/${apiPath.replace(/^\/+/, "")}`;
16811
+ if (Object.keys(queryParams).length > 0) {
16812
+ const qs = new URLSearchParams(queryParams).toString();
16813
+ url += `${url.includes("?") ? "&" : "?"}${qs}`;
16814
+ }
16815
+ const resolvedHeaders = {};
16816
+ for (const [key, value] of Object.entries(toolHeaders)) {
16817
+ resolvedHeaders[key] = String(EnvironmentResolver.resolveValue(value));
16818
+ }
16819
+ if (tool.auth) {
16820
+ const authType = tool.auth.type;
16821
+ if (authType === "bearer" && tool.auth.token) {
16822
+ const token = String(EnvironmentResolver.resolveValue(tool.auth.token));
16823
+ resolvedHeaders["Authorization"] = `Bearer ${token}`;
16824
+ }
16825
+ }
16826
+ if (this.debug) {
16827
+ logger.debug(`[CustomToolsSSEServer:${this.sessionId}] HTTP client: ${method} ${url}`);
16828
+ }
16829
+ const controller = new AbortController();
16830
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
16831
+ try {
16832
+ const requestOptions = {
16833
+ method,
16834
+ headers: resolvedHeaders,
16835
+ signal: controller.signal
16836
+ };
16837
+ if (method !== "GET" && body) {
16838
+ requestOptions.body = typeof body === "string" ? body : JSON.stringify(body);
16839
+ if (!resolvedHeaders["Content-Type"] && !resolvedHeaders["content-type"]) {
16840
+ resolvedHeaders["Content-Type"] = "application/json";
16841
+ }
16842
+ }
16843
+ const response = await fetch(url, requestOptions);
16844
+ clearTimeout(timeoutId);
16845
+ if (!response.ok) {
16846
+ let errorBody = "";
16847
+ try {
16848
+ errorBody = await response.text();
16849
+ } catch {
16850
+ }
16851
+ throw new Error(
16852
+ `HTTP ${response.status}: ${response.statusText}${errorBody ? ` - ${errorBody.substring(0, 500)}` : ""}`
16853
+ );
16854
+ }
16855
+ const contentType = response.headers.get("content-type");
16856
+ if (contentType && contentType.includes("application/json")) {
16857
+ return await response.json();
16858
+ }
16859
+ const text = await response.text();
16860
+ if (text.trim().startsWith("{") || text.trim().startsWith("[")) {
16861
+ try {
16862
+ return JSON.parse(text);
16863
+ } catch {
16864
+ return text;
16865
+ }
16866
+ }
16867
+ return text;
16868
+ } catch (error) {
16869
+ clearTimeout(timeoutId);
16870
+ if (error instanceof Error && error.name === "AbortError") {
16871
+ throw new Error(`HTTP client request timed out after ${timeout}ms`);
16872
+ }
16873
+ throw error;
16874
+ }
16875
+ }
16786
16876
  /**
16787
16877
  * Convert a type: 'workflow' tool definition into a WorkflowToolDefinition marker.
16788
16878
  *
@@ -17866,6 +17956,7 @@ ${preview}`);
17866
17956
  }
17867
17957
  const workflowEntriesFromMcp = [];
17868
17958
  const toolEntriesFromMcp = [];
17959
+ const httpClientEntriesFromMcp = [];
17869
17960
  const mcpEntriesToRemove = [];
17870
17961
  for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
17871
17962
  const cfg = serverConfig;
@@ -17879,6 +17970,12 @@ ${preview}`);
17879
17970
  logger.debug(
17880
17971
  `[AICheckProvider] Extracted workflow tool '${serverName}' (workflow=${cfg.workflow}) from ai_mcp_servers`
17881
17972
  );
17973
+ } else if (cfg.type === "http_client" && (cfg.base_url || cfg.url)) {
17974
+ httpClientEntriesFromMcp.push({ name: serverName, config: cfg });
17975
+ mcpEntriesToRemove.push(serverName);
17976
+ logger.debug(
17977
+ `[AICheckProvider] Extracted http_client tool '${serverName}' (base_url=${cfg.base_url || cfg.url}) from ai_mcp_servers`
17978
+ );
17882
17979
  } else if (cfg.tool && typeof cfg.tool === "string") {
17883
17980
  toolEntriesFromMcp.push(cfg.tool);
17884
17981
  mcpEntriesToRemove.push(serverName);
@@ -17931,7 +18028,7 @@ ${preview}`);
17931
18028
  logger.debug(`[AICheckProvider] Schedule tool requested (${contextInfo})`);
17932
18029
  }
17933
18030
  const scheduleToolEnabled = scheduleToolRequested || config.ai?.enable_scheduler === true && !config.ai?.disableTools;
17934
- if ((customToolsToLoad.length > 0 || scheduleToolEnabled) && (customToolsServerName || scheduleToolEnabled) && !config.ai?.disableTools) {
18031
+ if ((customToolsToLoad.length > 0 || scheduleToolEnabled || httpClientEntriesFromMcp.length > 0) && (customToolsServerName || scheduleToolEnabled || httpClientEntriesFromMcp.length > 0) && !config.ai?.disableTools) {
17935
18032
  if (!customToolsServerName) {
17936
18033
  customToolsServerName = "__tools__";
17937
18034
  }
@@ -17963,6 +18060,48 @@ ${preview}`);
17963
18060
  customTools.set(scheduleTool.name, scheduleTool);
17964
18061
  logger.debug(`[AICheckProvider] Added built-in schedule tool`);
17965
18062
  }
18063
+ for (const entry of httpClientEntriesFromMcp) {
18064
+ const httpTool = {
18065
+ name: entry.name,
18066
+ type: "http_client",
18067
+ description: entry.config.description || `Call ${entry.name} HTTP API (base: ${entry.config.base_url || entry.config.url})`,
18068
+ base_url: entry.config.base_url || entry.config.url,
18069
+ auth: entry.config.auth,
18070
+ headers: entry.config.headers,
18071
+ timeout: entry.config.timeout || 3e4,
18072
+ inputSchema: {
18073
+ type: "object",
18074
+ properties: {
18075
+ path: {
18076
+ type: "string",
18077
+ description: "API path (e.g. /jobs, /candidates/{id})"
18078
+ },
18079
+ method: {
18080
+ type: "string",
18081
+ description: "HTTP method (default: GET)",
18082
+ enum: ["GET", "POST", "PUT", "PATCH", "DELETE"]
18083
+ },
18084
+ query: {
18085
+ type: "object",
18086
+ description: "Query string parameters",
18087
+ additionalProperties: { type: "string" }
18088
+ },
18089
+ body: {
18090
+ type: "object",
18091
+ description: "Request body for POST/PUT/PATCH"
18092
+ }
18093
+ },
18094
+ required: ["path"]
18095
+ }
18096
+ };
18097
+ customTools.set(entry.name, httpTool);
18098
+ logger.debug(
18099
+ `[AICheckProvider] Added http_client tool '${entry.name}' (base_url=${httpTool.base_url})`
18100
+ );
18101
+ }
18102
+ if (httpClientEntriesFromMcp.length > 0 && !customToolsServerName) {
18103
+ customToolsServerName = "__tools__";
18104
+ }
17966
18105
  if (customTools.size > 0) {
17967
18106
  const sessionId = config.checkName || `ai-check-${Date.now()}`;
17968
18107
  const debug = aiConfig.debug || process.env.VISOR_DEBUG === "true";
@@ -41415,8 +41554,8 @@ function buildBuiltinGlobals(opts) {
41415
41554
  const asyncFunctionNames = /* @__PURE__ */ new Set();
41416
41555
  const scheduleFn = async (args = {}) => {
41417
41556
  try {
41418
- const { handleScheduleAction: handleScheduleAction2, buildScheduleToolContext: buildScheduleToolContext2 } = await import("./schedule-tool-5KDBDCFO.mjs");
41419
- const { extractSlackContext: extractSlackContext2 } = await import("./schedule-tool-handler-MUF5V36L.mjs");
41557
+ const { handleScheduleAction: handleScheduleAction2, buildScheduleToolContext: buildScheduleToolContext2 } = await import("./schedule-tool-DF5WUVYV.mjs");
41558
+ const { extractSlackContext: extractSlackContext2 } = await import("./schedule-tool-handler-JGWA4N3C.mjs");
41420
41559
  const parentCtx = opts.sessionInfo?._parentContext;
41421
41560
  const webhookData = parentCtx?.prInfo?.eventContext?.webhookData;
41422
41561
  const visorCfg = parentCtx?.config;
@@ -45013,4 +45152,4 @@ undici/lib/fetch/body.js:
45013
45152
  undici/lib/websocket/frame.js:
45014
45153
  (*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> *)
45015
45154
  */
45016
- //# sourceMappingURL=chunk-GKSSG5IM.mjs.map
45155
+ //# sourceMappingURL=chunk-TAK5HLAR.mjs.map