awaitly-analyze 2.0.0 → 4.0.0

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/browser.ts","../src/tree-sitter-loader-browser.ts","../src/renderers/mermaid.ts","../src/renderers/json.ts"],"sourcesContent":["/**\n * Browser Entry Point for Static Workflow Analysis\n *\n * This module provides static workflow analysis for browser environments.\n * It uses fetch() to load WASM files instead of Node.js fs APIs.\n *\n * Usage:\n * ```typescript\n * import {\n * setWasmBasePath,\n * analyzeWorkflowSource,\n * renderStaticMermaid\n * } from 'awaitly-analyze/browser';\n *\n * // Configure WASM path before first use\n * setWasmBasePath('/wasm/');\n *\n * // Analyze workflow source code\n * const results = await analyzeWorkflowSource(code, { assumeImported: true });\n * if (results.length > 0) {\n * const diagram = renderStaticMermaid(results[0]);\n * console.log(diagram);\n * }\n * ```\n */\n\nimport {\n setWasmBasePath,\n getWasmBasePath,\n loadTreeSitterBrowser,\n clearTreeSitterBrowserCache,\n} from \"./tree-sitter-loader-browser\";\nimport type { SyntaxNode } from \"./tree-sitter-loader\";\nimport type {\n StaticWorkflowIR,\n StaticWorkflowNode,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticLoopNode,\n StaticWorkflowRefNode,\n StaticRetryConfig,\n StaticTimeoutConfig,\n StaticAnalysisMetadata,\n SourceLocation,\n AnalysisWarning,\n AnalysisStats,\n AnalyzerOptions,\n} from \"./types\";\n\n// Re-export WASM configuration\nexport { setWasmBasePath, getWasmBasePath, clearTreeSitterBrowserCache };\n\n// Re-export renderers\nexport {\n renderStaticMermaid,\n renderPathsMermaid,\n renderStaticJSON,\n renderMultipleStaticJSON,\n type MermaidOptions,\n type MermaidStyles,\n type JSONRenderOptions,\n} from \"./renderers\";\n\n// Re-export types\nexport type {\n StaticWorkflowIR,\n StaticWorkflowNode,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticLoopNode,\n AnalysisWarning,\n AnalysisStats,\n AnalyzerOptions,\n};\n\n// =============================================================================\n// Types (duplicated to avoid importing from static-analyzer.ts which uses Node APIs)\n// =============================================================================\n\ninterface AnalyzerContext {\n sourceCode: string;\n filePath: string;\n opts: Required<AnalyzerOptions>;\n warnings: AnalysisWarning[];\n stats: AnalysisStats;\n workflowNames: Set<string>;\n currentWorkflow?: string;\n stepParameterName?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<AnalyzerOptions> = {\n tsConfigPath: \"./tsconfig.json\",\n resolveReferences: false,\n maxReferenceDepth: 5,\n includeLocations: true,\n detect: \"all\",\n assumeImported: false,\n};\n\n// =============================================================================\n// Public API\n// =============================================================================\n\nlet idCounter = 0;\n\n/**\n * Reset the ID counter (for testing).\n */\nexport function resetIdCounter(): void {\n idCounter = 0;\n}\n\n/**\n * Generate a unique ID.\n */\nfunction generateId(): string {\n return `ts-${++idCounter}`;\n}\n\n/**\n * Parse source code directly (browser-compatible).\n *\n * Note: This does NOT support file-based analysis - use analyzeWorkflowSource\n * with source code strings only.\n */\nexport async function analyzeWorkflowSource(\n sourceCode: string,\n options: AnalyzerOptions = {}\n): Promise<StaticWorkflowIR[]> {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const { parser } = await loadTreeSitterBrowser();\n const tree = parser.parse(sourceCode);\n\n if (!tree) {\n throw new Error(\"Failed to parse source code\");\n }\n\n const ctx: AnalyzerContext = {\n sourceCode,\n filePath: \"<source>\",\n opts,\n warnings: [],\n stats: createEmptyStats(),\n workflowNames: new Set(),\n };\n\n // Find all workflow definitions first to track names\n const definitions = findWorkflowDefinitions(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n definitions.forEach((d) => ctx.workflowNames.add(d.name));\n\n const results: StaticWorkflowIR[] = [];\n\n // Find and analyze createWorkflow calls (unless filtered to run only)\n if (opts.detect === \"all\" || opts.detect === \"createWorkflow\") {\n const workflowCalls = findWorkflowCalls(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n for (const call of workflowCalls) {\n const ir = analyzeWorkflowCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n // Find and analyze run() calls (unless filtered to createWorkflow only)\n if (opts.detect === \"all\" || opts.detect === \"run\") {\n const runCalls = findRunCalls(tree.rootNode as unknown as SyntaxNode, ctx);\n for (const call of runCalls) {\n const ir = analyzeRunCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n return results;\n}\n\n// =============================================================================\n// The following is a copy of the analysis logic from static-analyzer.ts\n// This duplication is necessary because static-analyzer.ts imports from\n// tree-sitter-loader.ts which uses Node.js APIs (fs, path, etc.)\n// =============================================================================\n\ninterface WorkflowDefinition {\n name: string;\n createWorkflowCall: SyntaxNode;\n /** Short description for labels/tooltips */\n description?: string;\n /** Full markdown documentation */\n markdown?: string;\n}\n\n/**\n * Extracted workflow options from createWorkflow call.\n */\ninterface WorkflowOptionsExtracted {\n description?: string;\n markdown?: string;\n}\n\n/**\n * Extract workflow options (description, markdown) from an options object literal.\n */\nfunction extractWorkflowOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): WorkflowOptionsExtracted {\n const result: WorkflowOptionsExtracted = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n if (key === \"description\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.description = value;\n } else if (key === \"markdown\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.markdown = value;\n }\n }\n }\n }\n\n return result;\n}\n\nfunction findWorkflowDefinitions(\n root: SyntaxNode,\n ctx: AnalyzerContext\n): WorkflowDefinition[] {\n const results: WorkflowDefinition[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (funcText === \"createWorkflow\") {\n const workflowName = extractWorkflowName(node, ctx);\n if (workflowName) {\n // Extract documentation options from second argument\n const args = node.childForFieldName(\"arguments\");\n const optionsNode = args?.namedChildren[1]; // Second arg is options\n const options = optionsNode\n ? extractWorkflowOptions(optionsNode, ctx)\n : {};\n\n results.push({\n name: workflowName,\n createWorkflowCall: node,\n description: options.description,\n markdown: options.markdown,\n });\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findWorkflowCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const definitions = findWorkflowDefinitions(root, ctx);\n const workflowNames = new Set(definitions.map((d) => d.name));\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (workflowNames.has(funcText)) {\n const args = node.childForFieldName(\"arguments\");\n if (args) {\n const firstArg = args.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findAwaitlyImports(\n root: SyntaxNode,\n exportName: string,\n ctx: AnalyzerContext\n): Set<string> {\n const importedNames = new Set<string>();\n\n traverseNode(root, (node) => {\n if (node.type === \"import_statement\") {\n let isTypeOnly = false;\n for (let i = 0; i < node.childCount; i++) {\n const child = node.children[i];\n if (child && child.type === \"type\") {\n isTypeOnly = true;\n break;\n }\n }\n if (isTypeOnly) {\n return;\n }\n\n const sourceNode = node.childForFieldName(\"source\");\n if (sourceNode) {\n const sourceText = getText(sourceNode, ctx);\n const modulePath = sourceText.slice(1, -1);\n if (modulePath === \"awaitly\" || modulePath.startsWith(\"@awaitly/\")) {\n for (const child of node.namedChildren) {\n if (child.type === \"import_clause\") {\n for (const clauseChild of child.namedChildren) {\n if (clauseChild.type === \"named_imports\") {\n for (const specifier of clauseChild.namedChildren) {\n if (specifier.type === \"import_specifier\") {\n let isTypeOnlySpecifier = false;\n for (const specChild of specifier.children) {\n if (specChild.type === \"type\") {\n isTypeOnlySpecifier = true;\n break;\n }\n }\n if (isTypeOnlySpecifier) {\n continue;\n }\n\n const nameNode = specifier.childForFieldName(\"name\");\n const aliasNode = specifier.childForFieldName(\"alias\");\n\n if (nameNode) {\n const importedName = getText(nameNode, ctx);\n if (importedName === exportName) {\n const localName = aliasNode\n ? getText(aliasNode, ctx)\n : importedName;\n importedNames.add(localName);\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n });\n\n return importedNames;\n}\n\n/**\n * Check if an identifier at a given node is shadowed by a local declaration.\n */\nfunction isIdentifierShadowed(\n node: SyntaxNode,\n identifierName: string,\n ctx: AnalyzerContext\n): boolean {\n let current: SyntaxNode | null = node.parent;\n\n while (current) {\n if (\n current.type === \"statement_block\" ||\n current.type === \"program\"\n ) {\n for (const child of current.namedChildren) {\n if (child.startIndex >= node.startIndex) break;\n\n if (child.type === \"lexical_declaration\" || child.type === \"variable_declaration\") {\n for (const declarator of child.namedChildren) {\n if (declarator.type === \"variable_declarator\") {\n const nameNode = declarator.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n } else if (child.type === \"function_declaration\") {\n const nameNode = child.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n }\n\n if (\n current.type === \"arrow_function\" ||\n current.type === \"function_expression\" ||\n current.type === \"function_declaration\" ||\n current.type === \"method_definition\"\n ) {\n const params = current.childForFieldName(\"parameters\");\n if (params) {\n for (const param of params.namedChildren) {\n if (param.type === \"identifier\" && getText(param, ctx) === identifierName) {\n return true;\n }\n if (param.type === \"object_pattern\" || param.type === \"array_pattern\") {\n let found = false;\n traverseNode(param, (n) => {\n if (n.type === \"identifier\" && getText(n, ctx) === identifierName) {\n found = true;\n }\n });\n if (found) return true;\n }\n if (param.type === \"assignment_pattern\") {\n const left = param.childForFieldName(\"left\");\n if (left?.type === \"identifier\" && getText(left, ctx) === identifierName) {\n return true;\n }\n }\n }\n }\n }\n\n if (current.type === \"program\") break;\n current = current.parent;\n }\n\n return false;\n}\n\nfunction findRunCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const runImportNames = findAwaitlyImports(root, \"run\", ctx);\n\n if (ctx.opts.assumeImported) {\n runImportNames.add(\"run\");\n }\n\n if (runImportNames.size === 0) {\n return [];\n }\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode && funcNode.type === \"identifier\") {\n const funcText = getText(funcNode, ctx);\n if (runImportNames.has(funcText)) {\n // Check if the identifier is shadowed by a local declaration\n if (isIdentifierShadowed(node, funcText, ctx)) {\n return; // Skip - this is a shadowed local variable\n }\n\n const args = node.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction generateRunName(callNode: SyntaxNode, ctx: AnalyzerContext): string {\n const line = callNode.startPosition.row + 1;\n const filePath = ctx.filePath;\n const fileName = filePath.includes(\"/\")\n ? filePath.split(\"/\").pop() || filePath\n : filePath.includes(\"\\\\\")\n ? filePath.split(\"\\\\\").pop() || filePath\n : filePath;\n return `run@${fileName}:${line}`;\n}\n\nfunction analyzeRunCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: \"Could not find callback for run()\",\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const workflowName = generateRunName(callNode, ctx);\n const stepParamName = extractStepParameterName(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n ctx.stepParameterName = stepParamName;\n\n const children = analyzeCallback(callbackNode, ctx);\n\n ctx.stepParameterName = prevStepParamName;\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"run\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n location: ctx.opts.includeLocations ? getLocation(callNode, ctx) : undefined,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction analyzeWorkflowCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const funcNode = callNode.childForFieldName(\"function\");\n const workflowName = funcNode ? getText(funcNode, parentCtx) : \"<unknown>\";\n\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: `Could not find callback for workflow ${workflowName}`,\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const prevWorkflow = ctx.currentWorkflow;\n ctx.currentWorkflow = workflowName;\n\n const stepParamName = extractStepParameterName(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n ctx.stepParameterName = stepParamName;\n\n const children = analyzeCallback(callbackNode, ctx);\n\n ctx.currentWorkflow = prevWorkflow;\n ctx.stepParameterName = prevStepParamName;\n\n // Find the definition to get documentation\n const definitions = findWorkflowDefinitions(\n (callNode as unknown as { tree?: { rootNode: SyntaxNode } }).tree?.rootNode || callNode,\n parentCtx\n );\n const definition = definitions.find((d) => d.name === workflowName);\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"createWorkflow\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n description: definition?.description,\n markdown: definition?.markdown,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction extractWorkflowName(\n callNode: SyntaxNode,\n ctx: AnalyzerContext\n): string | null {\n let current: SyntaxNode | null = callNode;\n while (current) {\n if (current.type === \"variable_declarator\") {\n const nameNode = current.childForFieldName(\"name\");\n if (nameNode) {\n return getText(nameNode, ctx);\n }\n }\n current = current.parent;\n }\n return null;\n}\n\nfunction extractStepParameterName(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n const params = callbackNode.childForFieldName(\"parameters\");\n if (!params) return undefined;\n\n const firstParam = params.namedChildren[0];\n if (!firstParam) return undefined;\n\n if (firstParam.type === \"identifier\") {\n return getText(firstParam, ctx);\n }\n\n if (firstParam.type === \"required_parameter\") {\n const patternNode = firstParam.childForFieldName(\"pattern\");\n if (patternNode) {\n if (patternNode.type === \"object_pattern\") {\n return extractStepFromObjectPattern(patternNode, ctx);\n }\n return getText(patternNode, ctx);\n }\n }\n\n if (firstParam.type === \"object_pattern\") {\n return extractStepFromObjectPattern(firstParam, ctx);\n }\n\n return undefined;\n}\n\nfunction extractStepFromObjectPattern(\n objectPattern: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n for (const child of objectPattern.namedChildren) {\n if (child.type === \"pair_pattern\") {\n const keyNode = child.childForFieldName(\"key\");\n const valueNode = child.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n if (key === \"step\") {\n if (valueNode.type === \"assignment_pattern\") {\n const left = valueNode.childForFieldName(\"left\");\n if (left) {\n return getText(left, ctx);\n }\n }\n return getText(valueNode, ctx);\n }\n }\n }\n\n if (child.type === \"shorthand_property_identifier_pattern\") {\n const name = getText(child, ctx);\n if (name === \"step\") {\n return \"step\";\n }\n }\n\n if (child.type === \"assignment_pattern\") {\n const left = child.childForFieldName(\"left\");\n if (left) {\n const name = getText(left, ctx);\n if (name === \"step\") {\n return \"step\";\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction analyzeCallback(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const body = callbackNode.childForFieldName(\"body\");\n if (!body) return [];\n\n if (body.type === \"statement_block\") {\n return analyzeStatements(body.namedChildren, ctx);\n }\n\n return analyzeExpression(body, ctx);\n}\n\nfunction analyzeStatements(\n statements: SyntaxNode[],\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const stmt of statements) {\n const nodes = analyzeStatement(stmt, ctx);\n results.push(...nodes);\n }\n\n return results;\n}\n\nfunction analyzeStatement(\n stmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n switch (stmt.type) {\n case \"expression_statement\": {\n const expr = stmt.namedChildren[0];\n if (expr) {\n return analyzeExpression(expr, ctx);\n }\n return [];\n }\n\n case \"variable_declaration\":\n case \"lexical_declaration\":\n return analyzeVariableDeclaration(stmt, ctx);\n\n case \"return_statement\": {\n const returnExpr = stmt.childForFieldName(\"value\");\n if (returnExpr) {\n return analyzeExpression(returnExpr, ctx);\n }\n return [];\n }\n\n case \"if_statement\":\n return analyzeIfStatement(stmt, ctx);\n\n case \"for_statement\":\n return analyzeForStatement(stmt, ctx);\n\n case \"for_in_statement\":\n return analyzeForInStatement(stmt, ctx);\n\n case \"while_statement\":\n return analyzeWhileStatement(stmt, ctx);\n\n default:\n return [];\n }\n}\n\nfunction analyzeExpression(\n expr: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (expr.type === \"await_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"parenthesized_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"call_expression\") {\n return analyzeCallExpression(expr, ctx);\n }\n\n return [];\n}\n\nfunction analyzeVariableDeclaration(\n decl: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const child of decl.namedChildren) {\n if (child.type === \"variable_declarator\") {\n const value = child.childForFieldName(\"value\");\n if (value) {\n results.push(...analyzeExpression(value, ctx));\n }\n }\n }\n\n return results;\n}\n\nfunction analyzeCallExpression(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const funcNode = call.childForFieldName(\"function\");\n if (!funcNode) return [];\n\n const funcText = getText(funcNode, ctx);\n\n const stepParam = ctx.stepParameterName || \"step\";\n if (funcText === stepParam) {\n return [analyzeStepCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.retry`) {\n return [analyzeStepRetryCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.withTimeout`) {\n return [analyzeStepTimeoutCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.parallel`) {\n return analyzeParallelCall(call, ctx);\n }\n\n if (funcText === `${stepParam}.race`) {\n return analyzeRaceCall(call, ctx);\n }\n\n if ([\"when\", \"unless\", \"whenOr\", \"unlessOr\"].includes(funcText)) {\n return analyzeConditionalHelper(\n call,\n funcText as \"when\" | \"unless\" | \"whenOr\" | \"unlessOr\",\n ctx\n );\n }\n\n if (funcText === \"allAsync\" || funcText === \"allSettledAsync\") {\n return analyzeAllAsyncCall(\n call,\n funcText === \"allAsync\" ? \"all\" : \"allSettled\",\n ctx\n );\n }\n\n if (funcText === \"anyAsync\") {\n return analyzeAnyAsyncCall(call, ctx);\n }\n\n if (isLikelyWorkflowCall(call, funcText, ctx)) {\n return analyzeWorkflowRefCall(call, funcText, ctx);\n }\n\n return [];\n}\n\nfunction isLikelyWorkflowCall(\n call: SyntaxNode,\n funcText: string,\n ctx: AnalyzerContext\n): boolean {\n if (funcText === ctx.currentWorkflow) {\n return false;\n }\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg) return false;\n\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n if (ctx.workflowNames.has(funcText)) {\n return true;\n }\n\n const params = firstArg.childForFieldName(\"parameters\");\n if (params) {\n const paramText = getText(params, ctx);\n if (paramText.includes(\"step\") || paramText.includes(\"deps\")) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction analyzeWorkflowRefCall(\n call: SyntaxNode,\n workflowName: string,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.workflowRefCount++;\n\n const refNode: StaticWorkflowRefNode = {\n id: generateId(),\n type: \"workflow-ref\",\n workflowName,\n resolved: false,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [refNode];\n}\n\nfunction extractCalleeFromFunctionBody(\n body: SyntaxNode,\n ctx: AnalyzerContext\n): string {\n if (body.type === \"call_expression\") {\n const funcNode = body.childForFieldName(\"function\");\n if (funcNode) {\n return getText(funcNode, ctx);\n }\n }\n\n if (body.type === \"statement_block\") {\n for (const child of body.namedChildren) {\n if (child.type === \"return_statement\") {\n const returnExpr = child.namedChildren[0];\n if (returnExpr?.type === \"call_expression\") {\n const funcNode = returnExpr.childForFieldName(\"function\");\n if (funcNode) {\n return getText(funcNode, ctx);\n }\n } else if (returnExpr) {\n return getText(returnExpr, ctx);\n }\n }\n }\n }\n\n return getText(body, ctx);\n}\n\nfunction analyzeStepCall(call: SyntaxNode, ctx: AnalyzerContext): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n const secondArg = args?.namedChildren[1];\n\n let callee = \"<unknown>\";\n if (firstArg) {\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n const body = firstArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(firstArg, ctx);\n }\n }\n\n const options = secondArg ? extractStepOptions(secondArg, ctx) : {};\n\n const stepNode: StaticStepNode = {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry: options.retry,\n timeout: options.timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return stepNode;\n}\n\nfunction analyzeStepRetryCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const funcArg = argList[0];\n let callee = \"<unknown>\";\n if (funcArg) {\n if (\n funcArg.type === \"arrow_function\" ||\n funcArg.type === \"function_expression\"\n ) {\n const body = funcArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(funcArg, ctx);\n }\n }\n\n const optionsArg = argList[1];\n const options = optionsArg ? extractStepOptions(optionsArg, ctx) : {};\n\n const retry = optionsArg ? extractRetryConfig(optionsArg, ctx) : undefined;\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry,\n timeout: options.timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction analyzeStepTimeoutCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const funcArg = argList[0];\n let callee = \"<unknown>\";\n if (funcArg) {\n if (\n funcArg.type === \"arrow_function\" ||\n funcArg.type === \"function_expression\"\n ) {\n const body = funcArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(funcArg, ctx);\n }\n }\n\n const optionsArg = argList[1];\n const options = optionsArg ? extractStepOptions(optionsArg, ctx) : {};\n\n const timeout = optionsArg ? extractTimeoutConfig(optionsArg, ctx) : undefined;\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry: options.retry,\n timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\ninterface StepOptions {\n key?: string;\n name?: string;\n retry?: StaticRetryConfig;\n timeout?: StaticTimeoutConfig;\n}\n\nfunction extractStepOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): StepOptions {\n const result: StepOptions = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"key\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.key = value;\n } else if (key === \"name\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.name = value;\n } else if (key === \"retry\") {\n result.retry = extractRetryConfig(valueNode, ctx);\n } else if (key === \"timeout\") {\n result.timeout = extractTimeoutConfig(valueNode, ctx);\n }\n }\n }\n }\n\n return result;\n}\n\nfunction extractRetryConfig(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticRetryConfig {\n const config: StaticRetryConfig = {};\n\n if (node.type !== \"object\") {\n return config;\n }\n\n for (const prop of node.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"attempts\") {\n const value = extractNumberValue(valueNode, ctx);\n config.attempts = value;\n } else if (key === \"backoff\") {\n const value = extractStringValue(valueNode, ctx);\n if (value === \"fixed\" || value === \"linear\" || value === \"exponential\") {\n config.backoff = value;\n } else {\n config.backoff = \"<dynamic>\";\n }\n } else if (key === \"baseDelay\") {\n const value = extractNumberValue(valueNode, ctx);\n config.baseDelay = value;\n } else if (key === \"retryOn\") {\n config.retryOn = getText(valueNode, ctx);\n }\n }\n }\n }\n\n return config;\n}\n\nfunction extractTimeoutConfig(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticTimeoutConfig {\n const config: StaticTimeoutConfig = {};\n\n if (node.type !== \"object\") {\n return config;\n }\n\n for (const prop of node.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"ms\") {\n const value = extractNumberValue(valueNode, ctx);\n config.ms = value;\n }\n }\n }\n }\n\n return config;\n}\n\nfunction extractNumberValue(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): number | \"<dynamic>\" {\n const text = getText(node, ctx);\n\n if (node.type === \"number\") {\n const num = parseFloat(text);\n return isNaN(num) ? \"<dynamic>\" : num;\n }\n\n return \"<dynamic>\";\n}\n\nfunction analyzeParallelCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg) {\n return [];\n }\n\n if (\n firstArg.type === \"string\" ||\n firstArg.type === \"identifier\" ||\n firstArg.type === \"member_expression\"\n ) {\n const parallelName =\n firstArg.type === \"string\"\n ? extractStringValue(firstArg, ctx)\n : getText(firstArg, ctx);\n\n const secondArg = args?.namedChildren[1];\n if (\n secondArg &&\n (secondArg.type === \"arrow_function\" ||\n secondArg.type === \"function_expression\")\n ) {\n const analyzed = analyzeCallbackBody(secondArg, ctx);\n if (analyzed.length > 0) {\n for (const node of analyzed) {\n if (node.type === \"parallel\" && parallelName) {\n (node as StaticParallelNode).name = parallelName;\n }\n }\n return analyzed;\n }\n }\n return [];\n }\n\n if (firstArg.type !== \"object\") {\n return [];\n }\n\n ctx.stats.parallelCount++;\n\n const children: StaticFlowNode[] = [];\n\n for (const prop of firstArg.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const stepNode = analyzeParallelItem(keyNode, valueNode, ctx);\n if (stepNode) {\n children.push(stepNode);\n }\n }\n }\n }\n\n const secondArg = args?.namedChildren[1];\n const options = secondArg ? extractStepOptions(secondArg, ctx) : {};\n\n return [\n {\n id: generateId(),\n type: \"parallel\",\n mode: \"all\",\n name: options.name,\n children,\n callee: \"step.parallel\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeParallelItem(\n keyNode: SyntaxNode,\n valueNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode | null {\n ctx.stats.totalSteps++;\n\n const name = getText(keyNode, ctx);\n\n let callee = \"<unknown>\";\n if (\n valueNode.type === \"arrow_function\" ||\n valueNode.type === \"function_expression\"\n ) {\n const body = valueNode.childForFieldName(\"body\");\n if (body?.type === \"call_expression\") {\n const funcNode = body.childForFieldName(\"function\");\n if (funcNode) {\n callee = getText(funcNode, ctx);\n }\n }\n }\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n name,\n location: ctx.opts.includeLocations ? getLocation(valueNode, ctx) : undefined,\n };\n}\n\nfunction analyzeRaceCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.raceCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"object\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const prop of firstArg.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const stepNode = analyzeParallelItem(keyNode, valueNode, ctx);\n if (stepNode) {\n children.push(stepNode);\n }\n }\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"race\",\n children,\n callee: \"step.race\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeIfStatement(\n ifStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.conditionalCount++;\n\n const conditionNode = ifStmt.childForFieldName(\"condition\");\n const consequentNode = ifStmt.childForFieldName(\"consequence\");\n const alternateNode = ifStmt.childForFieldName(\"alternative\");\n\n const condition = conditionNode\n ? getText(conditionNode, ctx).replace(/^\\(|\\)$/g, \"\")\n : \"<unknown>\";\n\n const consequent = consequentNode ? analyzeBlock(consequentNode, ctx) : [];\n\n let alternate: StaticFlowNode[] | undefined;\n if (alternateNode) {\n if (alternateNode.type === \"else_clause\") {\n const elseContent = alternateNode.namedChildren[0];\n if (elseContent) {\n alternate = analyzeBlock(elseContent, ctx);\n }\n } else {\n alternate = analyzeBlock(alternateNode, ctx);\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"conditional\",\n condition,\n helper: null,\n consequent,\n alternate: alternate?.length ? alternate : undefined,\n location: ctx.opts.includeLocations ? getLocation(ifStmt, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeBlock(node: SyntaxNode, ctx: AnalyzerContext): StaticFlowNode[] {\n if (node.type === \"statement_block\") {\n return analyzeStatements(node.namedChildren, ctx);\n }\n return analyzeStatement(node, ctx);\n}\n\nfunction analyzeConditionalHelper(\n call: SyntaxNode,\n helper: \"when\" | \"unless\" | \"whenOr\" | \"unlessOr\",\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.conditionalCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const conditionNode = argList[0];\n const condition = conditionNode ? getText(conditionNode, ctx) : \"<unknown>\";\n\n const callbackNode = argList[1];\n const consequent = callbackNode ? analyzeCallbackBody(callbackNode, ctx) : [];\n\n let defaultValue: string | undefined;\n if ((helper === \"whenOr\" || helper === \"unlessOr\") && argList[2]) {\n defaultValue = getText(argList[2], ctx);\n }\n\n const conditionalNode: StaticConditionalNode = {\n id: generateId(),\n type: \"conditional\",\n condition,\n helper,\n consequent,\n defaultValue,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [conditionalNode];\n}\n\nfunction analyzeCallbackBody(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (node.type === \"arrow_function\" || node.type === \"function_expression\") {\n const body = node.childForFieldName(\"body\");\n if (body) {\n if (body.type === \"statement_block\") {\n return analyzeStatements(body.namedChildren, ctx);\n }\n return analyzeExpression(body, ctx);\n }\n }\n return analyzeExpression(node, ctx);\n}\n\nfunction analyzeAllAsyncCall(\n call: SyntaxNode,\n mode: \"all\" | \"allSettled\",\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.parallelCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"array\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const element of firstArg.namedChildren) {\n if (element.type === \"call_expression\") {\n const analyzed = analyzeCallExpression(element, ctx);\n if (analyzed.length > 0) {\n children.push(...wrapInSequence(analyzed));\n } else {\n const implicitStep = createImplicitStepFromCall(element, ctx);\n if (implicitStep) {\n children.push(implicitStep);\n }\n }\n } else {\n const analyzed = analyzeCallbackBody(element, ctx);\n children.push(...wrapInSequence(analyzed));\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"parallel\",\n mode,\n children,\n callee: mode === \"all\" ? \"allAsync\" : \"allSettledAsync\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeAnyAsyncCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.raceCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"array\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const element of firstArg.namedChildren) {\n if (element.type === \"call_expression\") {\n const analyzed = analyzeCallExpression(element, ctx);\n if (analyzed.length > 0) {\n children.push(...wrapInSequence(analyzed));\n } else {\n const implicitStep = createImplicitStepFromCall(element, ctx);\n if (implicitStep) {\n children.push(implicitStep);\n }\n }\n } else {\n const analyzed = analyzeCallbackBody(element, ctx);\n children.push(...wrapInSequence(analyzed));\n }\n }\n\n const raceNode: StaticRaceNode = {\n id: generateId(),\n type: \"race\",\n children,\n callee: \"anyAsync\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [raceNode];\n}\n\nfunction createImplicitStepFromCall(\n callNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode | null {\n ctx.stats.totalSteps++;\n\n const funcNode = callNode.childForFieldName(\"function\");\n const callee = funcNode ? getText(funcNode, ctx) : \"<unknown>\";\n\n const name = callee.includes(\".\") ? callee.split(\".\").pop() : callee;\n\n return {\n id: generateId(),\n type: \"step\",\n name,\n callee,\n location: ctx.opts.includeLocations ? getLocation(callNode, ctx) : undefined,\n };\n}\n\nfunction analyzeForStatement(\n forStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = forStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: \"for\",\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(forStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction analyzeForInStatement(\n forStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = forStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const stmtText = getText(forStmt, ctx);\n const isForOf = stmtText.includes(\" of \");\n\n const rightNode = forStmt.childForFieldName(\"right\");\n const iterSource = rightNode ? getText(rightNode, ctx) : undefined;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: isForOf ? \"for-of\" : \"for-in\",\n iterSource,\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(forStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction analyzeWhileStatement(\n whileStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = whileStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: \"while\",\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(whileStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction getText(node: SyntaxNode, ctx: AnalyzerContext): string {\n return ctx.sourceCode.slice(node.startIndex, node.endIndex);\n}\n\nfunction extractStringValue(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n const text = getText(node, ctx);\n\n if (node.type === \"string\") {\n return text.slice(1, -1);\n }\n\n if (node.type === \"template_string\") {\n return \"<dynamic>\";\n }\n\n return text;\n}\n\nfunction getLocation(node: SyntaxNode, ctx: AnalyzerContext): SourceLocation {\n return {\n filePath: ctx.filePath,\n line: node.startPosition.row + 1,\n column: node.startPosition.column,\n endLine: node.endPosition.row + 1,\n endColumn: node.endPosition.column,\n };\n}\n\nfunction traverseNode(\n node: SyntaxNode,\n callback: (node: SyntaxNode) => void\n): void {\n callback(node);\n for (const child of node.namedChildren) {\n traverseNode(child, callback);\n }\n}\n\nfunction wrapInSequence(nodes: StaticFlowNode[]): StaticFlowNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n return [\n {\n id: generateId(),\n type: \"sequence\",\n children: nodes,\n } as StaticSequenceNode,\n ];\n}\n\nfunction createEmptyStats(): AnalysisStats {\n return {\n totalSteps: 0,\n conditionalCount: 0,\n parallelCount: 0,\n raceCount: 0,\n loopCount: 0,\n workflowRefCount: 0,\n unknownCount: 0,\n };\n}\n","/**\n * Tree-sitter WASM Loader (Browser)\n *\n * Browser-compatible loader that uses fetch() to load WASM files.\n * web-tree-sitter v0.26+ bundles its own core WASM runtime and uses named exports.\n */\n\n// Re-export types from the Node.js loader\nexport type {\n SyntaxTree,\n SyntaxNode,\n Language,\n TreeSitterParser,\n} from \"./tree-sitter-loader\";\n\n// Import types from web-tree-sitter (these are the actual runtime types)\nimport type {\n Parser as WebTreeSitterParser,\n Language as WebTreeSitterLanguage,\n} from \"web-tree-sitter\";\n\n// Configurable WASM base path (default: /wasm/)\nlet wasmBasePath = \"/wasm/\";\n\n/**\n * Set the base path for loading WASM files.\n * Call this before loadTreeSitterBrowser() if WASM files are served from a different location.\n *\n * @example\n * ```ts\n * setWasmBasePath('/awaitly/wasm/');\n * ```\n */\nexport function setWasmBasePath(path: string): void {\n // Ensure path ends with /\n wasmBasePath = path.endsWith(\"/\") ? path : `${path}/`;\n}\n\n/**\n * Get the current WASM base path.\n */\nexport function getWasmBasePath(): string {\n return wasmBasePath;\n}\n\n// Singleton cache for parser and language\nlet cached: { parser: WebTreeSitterParser; language: WebTreeSitterLanguage } | null = null;\n\n/**\n * Load TypeScript grammar WASM from configured path using fetch.\n */\nasync function loadTypescriptGrammar(): Promise<Uint8Array> {\n const wasmUrl = `${wasmBasePath}tree-sitter-typescript.wasm`;\n\n const response = await fetch(wasmUrl);\n\n if (!response.ok) {\n throw new Error(\n `Failed to load TypeScript grammar WASM from: ${wasmUrl}\\n` +\n `HTTP ${response.status}: ${response.statusText}\\n\\n` +\n \"Make sure the WASM file is available at this path. \" +\n \"You can configure the path using setWasmBasePath().\"\n );\n }\n\n const buffer = await response.arrayBuffer();\n return new Uint8Array(buffer);\n}\n\n/**\n * Load and initialize tree-sitter with the TypeScript grammar.\n *\n * Uses fetch to load WASM files from the configured base path.\n * Subsequent calls return the cached parser instance.\n *\n * @returns Parser instance with TypeScript language loaded\n */\nexport async function loadTreeSitterBrowser(): Promise<{\n parser: WebTreeSitterParser;\n language: WebTreeSitterLanguage;\n}> {\n if (cached) return cached;\n\n // Dynamic import web-tree-sitter (v0.26+ uses named exports)\n const { Parser, Language } = await import(\"web-tree-sitter\");\n\n // Initialize the Parser with locateFile to find web-tree-sitter.wasm\n // The WASM file should be placed alongside tree-sitter-typescript.wasm\n await Parser.init({\n locateFile: (scriptName: string) => {\n // web-tree-sitter looks for web-tree-sitter.wasm\n return `${wasmBasePath}${scriptName}`;\n },\n });\n\n // Load TypeScript grammar from configured WASM path\n const typescriptWasm = await loadTypescriptGrammar();\n const language = await Language.load(typescriptWasm);\n\n // Create and configure parser\n const parser = new Parser();\n parser.setLanguage(language);\n\n cached = { parser, language };\n return cached;\n}\n\n/**\n * Clear the cached parser instance.\n * Useful for testing or forcing re-initialization.\n */\nexport function clearTreeSitterBrowserCache(): void {\n cached = null;\n}\n","/**\n * Mermaid Diagram Generator\n *\n * Generates Mermaid flowchart diagrams from static workflow analysis.\n * Shows all possible paths, not just executed ones.\n */\n\nimport type {\n StaticWorkflowIR,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticLoopNode,\n StaticWorkflowRefNode,\n} from \"../types\";\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface MermaidOptions {\n /** Diagram direction: TB (top-bottom), LR (left-right), etc. */\n direction?: \"TB\" | \"LR\" | \"BT\" | \"RL\";\n /** Show step keys in labels */\n showKeys?: boolean;\n /** Show condition labels on edges */\n showConditions?: boolean;\n /** Use subgraphs for parallel/race blocks */\n useSubgraphs?: boolean;\n /** Custom node styles */\n styles?: MermaidStyles;\n /** Max markdown lines to include as comments (default: 10) */\n maxMarkdownLines?: number;\n /** Include markdown in output (default: true) */\n includeMarkdown?: boolean;\n}\n\nexport interface MermaidStyles {\n step?: string;\n parallel?: string;\n race?: string;\n conditional?: string;\n loop?: string;\n workflowRef?: string;\n start?: string;\n end?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<MermaidOptions> = {\n direction: \"TB\",\n showKeys: false,\n showConditions: true,\n useSubgraphs: true,\n styles: {\n step: \"fill:#e1f5fe,stroke:#01579b,color:#01579b\",\n parallel: \"fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20\",\n race: \"fill:#fff3e0,stroke:#e65100,color:#bf360c\",\n conditional: \"fill:#fce4ec,stroke:#880e4f,color:#880e4f\",\n loop: \"fill:#f3e5f5,stroke:#4a148c,color:#4a148c\",\n workflowRef: \"fill:#e0f2f1,stroke:#004d40,color:#004d40\",\n start: \"fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20\",\n end: \"fill:#ffcdd2,stroke:#c62828,color:#b71c1c\",\n },\n maxMarkdownLines: 10,\n includeMarkdown: true,\n};\n\n// =============================================================================\n// Main Generator\n// =============================================================================\n\n/**\n * Generate a Mermaid flowchart from static workflow IR.\n */\nexport function renderStaticMermaid(\n ir: StaticWorkflowIR,\n options: MermaidOptions = {}\n): string {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const context: RenderContext = {\n opts,\n nodeCounter: 0,\n edges: [],\n subgraphs: [],\n styleClasses: new Map(),\n };\n\n const lines: string[] = [];\n\n // Flowchart header\n lines.push(`flowchart ${opts.direction}`);\n lines.push(\"\");\n\n // Add workflow title as comment\n lines.push(` %% Workflow: ${ir.root.workflowName}`);\n\n // Description (short) - always show if present\n if (ir.root.description) {\n lines.push(` %% ${ir.root.description}`);\n }\n\n // Markdown (full docs) - first N lines as comments\n if (opts.includeMarkdown && ir.root.markdown) {\n lines.push(` %%`);\n const markdownLines = ir.root.markdown.trim().split(\"\\n\");\n const maxLines = opts.maxMarkdownLines;\n const displayLines = markdownLines.slice(0, maxLines);\n for (const line of displayLines) {\n lines.push(` %% ${line}`);\n }\n if (markdownLines.length > maxLines) {\n lines.push(` %% ... (${markdownLines.length - maxLines} more lines)`);\n }\n }\n\n lines.push(\"\");\n\n // Add start node\n const startId = \"start\";\n lines.push(` ${startId}((Start))`);\n\n // Process workflow body\n const { firstNodeId, lastNodeIds } = renderNodes(\n ir.root.children,\n context,\n lines\n );\n\n // Connect start to first node\n if (firstNodeId) {\n context.edges.push({ from: startId, to: firstNodeId });\n }\n\n // Add end node and connect last nodes to it\n const endId = \"end_node\";\n lines.push(` ${endId}((End))`);\n\n for (const lastId of lastNodeIds) {\n context.edges.push({ from: lastId, to: endId });\n }\n\n // Add subgraphs\n for (const subgraph of context.subgraphs) {\n lines.push(\"\");\n lines.push(` subgraph ${subgraph.id}[${subgraph.label}]`);\n for (const line of subgraph.content) {\n lines.push(` ${line}`);\n }\n lines.push(\" end\");\n }\n\n // Add edges\n lines.push(\"\");\n lines.push(\" %% Edges\");\n for (const edge of context.edges) {\n if (edge.label && opts.showConditions) {\n lines.push(` ${edge.from} -->|${escapeLabel(edge.label)}| ${edge.to}`);\n } else {\n lines.push(` ${edge.from} --> ${edge.to}`);\n }\n }\n\n // Add styles\n lines.push(\"\");\n lines.push(\" %% Styles\");\n lines.push(` classDef stepStyle ${opts.styles.step}`);\n lines.push(` classDef parallelStyle ${opts.styles.parallel}`);\n lines.push(` classDef raceStyle ${opts.styles.race}`);\n lines.push(` classDef conditionalStyle ${opts.styles.conditional}`);\n lines.push(` classDef loopStyle ${opts.styles.loop}`);\n lines.push(` classDef workflowRefStyle ${opts.styles.workflowRef}`);\n lines.push(` classDef startStyle ${opts.styles.start}`);\n lines.push(` classDef endStyle ${opts.styles.end}`);\n\n // Apply styles\n lines.push(` class ${startId} startStyle`);\n lines.push(` class ${endId} endStyle`);\n\n for (const [nodeId, styleClass] of context.styleClasses) {\n lines.push(` class ${nodeId} ${styleClass}`);\n }\n\n return lines.join(\"\\n\");\n}\n\n// =============================================================================\n// Internal Types\n// =============================================================================\n\ninterface RenderContext {\n opts: Required<MermaidOptions>;\n nodeCounter: number;\n edges: Edge[];\n subgraphs: Subgraph[];\n styleClasses: Map<string, string>;\n}\n\ninterface Edge {\n from: string;\n to: string;\n label?: string;\n}\n\ninterface Subgraph {\n id: string;\n label: string;\n content: string[];\n}\n\ninterface RenderResult {\n firstNodeId: string | null;\n lastNodeIds: string[];\n}\n\n// =============================================================================\n// Node Rendering\n// =============================================================================\n\nfunction renderNodes(\n nodes: StaticFlowNode[],\n context: RenderContext,\n lines: string[]\n): RenderResult {\n if (nodes.length === 0) {\n return { firstNodeId: null, lastNodeIds: [] };\n }\n\n let firstNodeId: string | null = null;\n let prevLastNodeIds: string[] = [];\n\n for (const node of nodes) {\n const result = renderNode(node, context, lines);\n\n // Track first node\n if (firstNodeId === null && result.firstNodeId) {\n firstNodeId = result.firstNodeId;\n }\n\n // Connect previous nodes to current first node\n if (result.firstNodeId) {\n for (const prevId of prevLastNodeIds) {\n context.edges.push({ from: prevId, to: result.firstNodeId });\n }\n }\n\n prevLastNodeIds = result.lastNodeIds;\n }\n\n return {\n firstNodeId,\n lastNodeIds: prevLastNodeIds,\n };\n}\n\nfunction renderNode(\n node: StaticFlowNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n switch (node.type) {\n case \"step\":\n return renderStepNode(node, context, lines);\n\n case \"sequence\":\n return renderSequenceNode(node, context, lines);\n\n case \"parallel\":\n return renderParallelNode(node, context, lines);\n\n case \"race\":\n return renderRaceNode(node, context, lines);\n\n case \"conditional\":\n return renderConditionalNode(node, context, lines);\n\n case \"loop\":\n return renderLoopNode(node, context, lines);\n\n case \"workflow-ref\":\n return renderWorkflowRefNode(node, context, lines);\n\n case \"unknown\":\n return renderUnknownNode(node, context, lines);\n\n default:\n return { firstNodeId: null, lastNodeIds: [] };\n }\n}\n\nfunction renderStepNode(\n node: StaticStepNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `step_${++context.nodeCounter}`;\n let label = node.name ?? node.callee ?? \"step\";\n\n if (context.opts.showKeys && node.key) {\n label = `${label}\\\\n[${node.key}]`;\n }\n\n // Add retry/timeout indicators\n if (node.retry) {\n label += \"\\\\n(retry)\";\n }\n if (node.timeout) {\n label += \"\\\\n(timeout)\";\n }\n\n lines.push(` ${nodeId}[${escapeLabel(label)}]`);\n context.styleClasses.set(nodeId, \"stepStyle\");\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\nfunction renderSequenceNode(\n node: StaticSequenceNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n return renderNodes(node.children, context, lines);\n}\n\nfunction renderParallelNode(\n node: StaticParallelNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const forkId = `parallel_fork_${++context.nodeCounter}`;\n const joinId = `parallel_join_${++context.nodeCounter}`;\n\n // Fork node (diamond shape for parallel)\n const parallelLabel = node.name ? `${node.name} (${node.mode})` : `Parallel (${node.mode})`;\n lines.push(` ${forkId}{{\"${parallelLabel}\"}}`);\n context.styleClasses.set(forkId, \"parallelStyle\");\n\n // Join node\n lines.push(` ${joinId}{{\"Join\"}}`);\n context.styleClasses.set(joinId, \"parallelStyle\");\n\n // Render each branch\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const branchResult = renderNode(child, context, lines);\n\n // Connect fork to branch start\n if (branchResult.firstNodeId) {\n context.edges.push({\n from: forkId,\n to: branchResult.firstNodeId,\n label: `branch ${i + 1}`,\n });\n }\n\n // Connect branch end to join\n for (const lastId of branchResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: joinId });\n }\n }\n\n return {\n firstNodeId: forkId,\n lastNodeIds: [joinId],\n };\n}\n\nfunction renderRaceNode(\n node: StaticRaceNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const forkId = `race_fork_${++context.nodeCounter}`;\n const joinId = `race_join_${++context.nodeCounter}`;\n\n // Fork node (hexagon for race)\n const raceLabel = node.name ? node.name : \"Race\";\n lines.push(` ${forkId}{{{\"${raceLabel}\"}}}`);\n context.styleClasses.set(forkId, \"raceStyle\");\n\n // Join node\n lines.push(` ${joinId}{{{\"Winner\"}}}`);\n context.styleClasses.set(joinId, \"raceStyle\");\n\n // Render each competing branch\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const branchResult = renderNode(child, context, lines);\n\n // Connect fork to branch start\n if (branchResult.firstNodeId) {\n context.edges.push({\n from: forkId,\n to: branchResult.firstNodeId,\n label: `racer ${i + 1}`,\n });\n }\n\n // Connect branch end to join (dashed - only winner proceeds)\n for (const lastId of branchResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: joinId });\n }\n }\n\n return {\n firstNodeId: forkId,\n lastNodeIds: [joinId],\n };\n}\n\nfunction renderConditionalNode(\n node: StaticConditionalNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const decisionId = `decision_${++context.nodeCounter}`;\n\n // Decision diamond\n const conditionLabel = truncate(node.condition, 30);\n lines.push(` ${decisionId}{${escapeLabel(conditionLabel)}}`);\n context.styleClasses.set(decisionId, \"conditionalStyle\");\n\n const lastNodeIds: string[] = [];\n\n // True/consequent branch\n const trueResult = renderNodes(node.consequent, context, lines);\n if (trueResult.firstNodeId) {\n const trueLabel =\n node.helper === \"unless\" || node.helper === \"unlessOr\" ? \"false\" : \"true\";\n context.edges.push({\n from: decisionId,\n to: trueResult.firstNodeId,\n label: trueLabel,\n });\n lastNodeIds.push(...trueResult.lastNodeIds);\n }\n\n // False/alternate branch\n if (node.alternate && node.alternate.length > 0) {\n const falseResult = renderNodes(node.alternate, context, lines);\n if (falseResult.firstNodeId) {\n const falseLabel =\n node.helper === \"unless\" || node.helper === \"unlessOr\"\n ? \"true\"\n : \"false\";\n context.edges.push({\n from: decisionId,\n to: falseResult.firstNodeId,\n label: falseLabel,\n });\n lastNodeIds.push(...falseResult.lastNodeIds);\n }\n } else {\n // No alternate - decision can skip directly\n lastNodeIds.push(decisionId);\n }\n\n return {\n firstNodeId: decisionId,\n lastNodeIds,\n };\n}\n\nfunction renderLoopNode(\n node: StaticLoopNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const loopStartId = `loop_start_${++context.nodeCounter}`;\n const loopEndId = `loop_end_${++context.nodeCounter}`;\n\n // Loop start (stadium shape)\n const loopLabel = node.iterSource\n ? `${node.loopType}: ${truncate(node.iterSource, 20)}`\n : node.loopType;\n lines.push(` ${loopStartId}([${escapeLabel(loopLabel)}])`);\n context.styleClasses.set(loopStartId, \"loopStyle\");\n\n // Loop body\n const bodyResult = renderNodes(node.body, context, lines);\n\n // Connect loop start to body\n if (bodyResult.firstNodeId) {\n context.edges.push({\n from: loopStartId,\n to: bodyResult.firstNodeId,\n label: \"iterate\",\n });\n }\n\n // Loop end check\n lines.push(` ${loopEndId}([Continue?])`);\n context.styleClasses.set(loopEndId, \"loopStyle\");\n\n // Connect body end to loop check\n for (const lastId of bodyResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: loopEndId });\n }\n\n // Loop back\n context.edges.push({\n from: loopEndId,\n to: loopStartId,\n label: \"next\",\n });\n\n return {\n firstNodeId: loopStartId,\n lastNodeIds: [loopEndId],\n };\n}\n\nfunction renderWorkflowRefNode(\n node: StaticWorkflowRefNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `workflow_ref_${++context.nodeCounter}`;\n\n // Subroutine shape for workflow reference\n const label = `[[${node.workflowName}]]`;\n lines.push(` ${nodeId}${label}`);\n context.styleClasses.set(nodeId, \"workflowRefStyle\");\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\nfunction renderUnknownNode(\n node: StaticFlowNode & { type: \"unknown\" },\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `unknown_${++context.nodeCounter}`;\n\n lines.push(` ${nodeId}[/\"Unknown: ${escapeLabel(node.reason)}\"/]`);\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nfunction escapeLabel(label: string): string {\n return label\n .replace(/\"/g, \"'\")\n .replace(/\\[/g, \"(\")\n .replace(/\\]/g, \")\")\n .replace(/\\{/g, \"(\")\n .replace(/\\}/g, \")\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n\nfunction truncate(str: string, maxLength: number): string {\n if (str.length <= maxLength) return str;\n return str.slice(0, maxLength - 3) + \"...\";\n}\n\n// =============================================================================\n// Simplified Mermaid (Path-based)\n// =============================================================================\n\n/**\n * Generate a simplified Mermaid diagram showing just the paths.\n */\nexport function renderPathsMermaid(\n paths: Array<{\n id: string;\n steps: Array<{ name?: string; nodeId: string }>;\n conditions: Array<{ expression: string; mustBe: boolean }>;\n }>,\n options: MermaidOptions = {}\n): string {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const lines: string[] = [];\n\n lines.push(`flowchart ${opts.direction}`);\n lines.push(\"\");\n\n // Create unique node IDs for each step across all paths\n // Key by nodeId (unique), store both the generated ID and display label\n const stepNodes = new Map<string, { id: string; label: string }>();\n let nodeCounter = 0;\n\n for (const path of paths) {\n for (const step of path.steps) {\n // Use nodeId as unique key to prevent merging distinct steps with same name\n if (!stepNodes.has(step.nodeId)) {\n stepNodes.set(step.nodeId, {\n id: `step_${++nodeCounter}`,\n label: step.name ?? step.nodeId,\n });\n }\n }\n }\n\n // Add start and end nodes\n lines.push(\" start((Start))\");\n lines.push(\" end_node((End))\");\n lines.push(\"\");\n\n // Add all step nodes\n for (const [, { id, label }] of stepNodes) {\n lines.push(` ${id}[${escapeLabel(label)}]`);\n }\n lines.push(\"\");\n\n // Add edges for each path\n const edges = new Set<string>();\n\n for (const path of paths) {\n if (path.steps.length === 0) continue;\n\n // Start to first step\n const firstStep = path.steps[0];\n const firstStepId = stepNodes.get(firstStep.nodeId)!.id;\n edges.add(`start --> ${firstStepId}`);\n\n // Between steps\n for (let i = 0; i < path.steps.length - 1; i++) {\n const current = path.steps[i];\n const next = path.steps[i + 1];\n const currentId = stepNodes.get(current.nodeId)!.id;\n const nextId = stepNodes.get(next.nodeId)!.id;\n edges.add(`${currentId} --> ${nextId}`);\n }\n\n // Last step to end\n const lastStep = path.steps[path.steps.length - 1];\n const lastStepId = stepNodes.get(lastStep.nodeId)!.id;\n edges.add(`${lastStepId} --> end_node`);\n }\n\n // Add edges\n lines.push(\" %% Edges\");\n for (const edge of edges) {\n lines.push(` ${edge}`);\n }\n\n return lines.join(\"\\n\");\n}\n","/**\n * JSON Renderer for Static Workflow Analysis\n *\n * Serializes StaticWorkflowIR to JSON format.\n */\n\nimport type { StaticWorkflowIR } from \"../types\";\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface JSONRenderOptions {\n /** Pretty print with indentation (default: true) */\n pretty?: boolean;\n /** Include analysis metadata (default: true) */\n includeMetadata?: boolean;\n}\n\n// =============================================================================\n// Main Renderer\n// =============================================================================\n\n/**\n * Render a single workflow IR to JSON.\n */\nexport function renderStaticJSON(\n ir: StaticWorkflowIR,\n options: JSONRenderOptions = {}\n): string {\n const { pretty = true, includeMetadata = true } = options;\n\n const serializable = {\n root: ir.root,\n metadata: includeMetadata ? ir.metadata : undefined,\n // Convert Map to object for JSON serialization\n references:\n ir.references.size > 0\n ? Object.fromEntries(\n Array.from(ir.references.entries()).map(([key, value]) => [\n key,\n {\n root: value.root,\n metadata: includeMetadata ? value.metadata : undefined,\n },\n ])\n )\n : undefined,\n };\n\n return pretty\n ? JSON.stringify(serializable, null, 2)\n : JSON.stringify(serializable);\n}\n\n/**\n * Render multiple workflow IRs to JSON.\n */\nexport function renderMultipleStaticJSON(\n workflows: StaticWorkflowIR[],\n filePath: string,\n options: JSONRenderOptions = {}\n): string {\n const { pretty = true, includeMetadata = true } = options;\n\n const serializable = {\n file: filePath,\n analyzedAt: Date.now(),\n workflowCount: workflows.length,\n workflows: workflows.map((ir) => ({\n root: ir.root,\n metadata: includeMetadata ? ir.metadata : undefined,\n references:\n ir.references.size > 0\n ? Object.fromEntries(\n Array.from(ir.references.entries()).map(([key, value]) => [\n key,\n {\n root: value.root,\n metadata: includeMetadata ? value.metadata : undefined,\n },\n ])\n )\n : undefined,\n })),\n };\n\n return pretty\n ? JSON.stringify(serializable, null, 2)\n : JSON.stringify(serializable);\n}\n"],"mappings":"ukBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,2BAAAE,GAAA,gCAAAC,EAAA,oBAAAC,EAAA,6BAAAC,EAAA,uBAAAC,EAAA,qBAAAC,EAAA,wBAAAC,EAAA,mBAAAC,GAAA,oBAAAC,IAAA,eAAAC,GAAAX,ICsBA,IAAIY,EAAe,SAWZ,SAASC,EAAgBC,EAAoB,CAElDF,EAAeE,EAAK,SAAS,GAAG,EAAIA,EAAO,GAAGA,CAAI,GACpD,CAKO,SAASC,GAA0B,CACxC,OAAOH,CACT,CAGA,IAAII,EAAkF,KAKtF,eAAeC,IAA6C,CAC1D,IAAMC,EAAU,GAAGN,CAAY,8BAEzBO,EAAW,MAAM,MAAMD,CAAO,EAEpC,GAAI,CAACC,EAAS,GACZ,MAAM,IAAI,MACR,gDAAgDD,CAAO;AAAA,OAC7CC,EAAS,MAAM,KAAKA,EAAS,UAAU;AAAA;AAAA,uGAGnD,EAGF,IAAMC,EAAS,MAAMD,EAAS,YAAY,EAC1C,OAAO,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AClB,aAAc,CAChB,CACF","names":["browser_exports","__export","analyzeWorkflowSource","clearTreeSitterBrowserCache","getWasmBasePath","renderMultipleStaticJSON","renderPathsMermaid","renderStaticJSON","renderStaticMermaid","resetIdCounter","setWasmBasePath","__toCommonJS","wasmBasePath","setWasmBasePath","path","getWasmBasePath","cached","loadTypescriptGrammar","wasmUrl","response","buffer","loadTreeSitterBrowser","Parser","Language","scriptName","typescriptWasm","language","parser","clearTreeSitterBrowserCache","DEFAULT_OPTIONS","renderStaticMermaid","ir","options","opts","context","lines","markdownLines","maxLines","displayLines","line","startId","firstNodeId","lastNodeIds","renderNodes","endId","lastId","subgraph","edge","escapeLabel","nodeId","styleClass","nodes","prevLastNodeIds","node","result","renderNode","prevId","renderStepNode","renderSequenceNode","renderParallelNode","renderRaceNode","renderConditionalNode","renderLoopNode","renderWorkflowRefNode","renderUnknownNode","label","forkId","joinId","parallelLabel","i","child","branchResult","raceLabel","decisionId","conditionLabel","truncate","trueResult","trueLabel","falseResult","falseLabel","loopStartId","loopEndId","loopLabel","bodyResult","str","maxLength","renderPathsMermaid","paths","stepNodes","nodeCounter","path","step","id","edges","firstStep","firstStepId","current","next","currentId","nextId","lastStep","lastStepId","renderStaticJSON","ir","options","pretty","includeMetadata","serializable","key","value","renderMultipleStaticJSON","workflows","filePath","DEFAULT_OPTIONS","idCounter","resetIdCounter","generateId","analyzeWorkflowSource","sourceCode","options","opts","parser","loadTreeSitterBrowser","tree","ctx","createEmptyStats","findWorkflowDefinitions","d","results","workflowCalls","findWorkflowCalls","call","ir","analyzeWorkflowCall","runCalls","findRunCalls","analyzeRunCall","extractWorkflowOptions","optionsNode","result","prop","keyNode","valueNode","key","getText","value","extractStringValue","root","traverseNode","node","funcNode","workflowName","extractWorkflowName","definitions","workflowNames","funcText","args","firstArg","findAwaitlyImports","exportName","importedNames","isTypeOnly","child","sourceNode","modulePath","clauseChild","specifier","isTypeOnlySpecifier","specChild","nameNode","aliasNode","importedName","localName","isIdentifierShadowed","identifierName","current","declarator","params","param","found","n","left","runImportNames","generateRunName","callNode","line","filePath","parentCtx","callbackNode","workflowWarnings","workflowStats","getLocation","stepParamName","extractStepParameterName","prevStepParamName","children","analyzeCallback","rootNode","wrapInSequence","metadata","prevWorkflow","definition","firstParam","patternNode","extractStepFromObjectPattern","objectPattern","body","analyzeStatements","analyzeExpression","statements","stmt","nodes","analyzeStatement","expr","analyzeVariableDeclaration","returnExpr","analyzeIfStatement","analyzeForStatement","analyzeForInStatement","analyzeWhileStatement","inner","analyzeCallExpression","decl","stepParam","analyzeStepCall","analyzeStepRetryCall","analyzeStepTimeoutCall","analyzeParallelCall","analyzeRaceCall","analyzeConditionalHelper","analyzeAllAsyncCall","analyzeAnyAsyncCall","isLikelyWorkflowCall","analyzeWorkflowRefCall","paramText","extractCalleeFromFunctionBody","secondArg","callee","extractStepOptions","argList","funcArg","optionsArg","retry","extractRetryConfig","timeout","extractTimeoutConfig","config","extractNumberValue","text","num","parallelName","analyzed","analyzeCallbackBody","stepNode","analyzeParallelItem","name","ifStmt","conditionNode","consequentNode","alternateNode","condition","consequent","analyzeBlock","alternate","elseContent","helper","defaultValue","mode","element","implicitStep","createImplicitStepFromCall","forStmt","bodyNode","bodyChildren","isForOf","rightNode","iterSource","whileStmt","callback"]}
1
+ {"version":3,"sources":["../src/browser.ts","../src/tree-sitter-loader-browser.ts","../src/renderers/mermaid.ts","../src/renderers/json.ts"],"sourcesContent":["/**\n * Browser Entry Point for Static Workflow Analysis\n *\n * This module provides static workflow analysis for browser environments.\n * It uses fetch() to load WASM files instead of Node.js fs APIs.\n *\n * Usage:\n * ```typescript\n * import {\n * setWasmBasePath,\n * analyzeWorkflowSource,\n * renderStaticMermaid\n * } from 'awaitly-analyze/browser';\n *\n * // Configure WASM path before first use\n * setWasmBasePath('/wasm/');\n *\n * // Analyze workflow source code\n * const results = await analyzeWorkflowSource(code, { assumeImported: true });\n * if (results.length > 0) {\n * const diagram = renderStaticMermaid(results[0]);\n * console.log(diagram);\n * }\n * ```\n */\n\nimport {\n setWasmBasePath,\n getWasmBasePath,\n loadTreeSitterBrowser,\n clearTreeSitterBrowserCache,\n} from \"./tree-sitter-loader-browser\";\nimport type { SyntaxNode } from \"./tree-sitter-loader\";\nimport type {\n StaticWorkflowIR,\n StaticWorkflowNode,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticSwitchNode,\n StaticSwitchCase,\n StaticLoopNode,\n StaticWorkflowRefNode,\n StaticRetryConfig,\n StaticTimeoutConfig,\n StaticAnalysisMetadata,\n SourceLocation,\n AnalysisWarning,\n AnalysisStats,\n AnalyzerOptions,\n StaticSagaStepNode,\n StaticStreamNode,\n} from \"./types\";\n\n// Re-export WASM configuration\nexport { setWasmBasePath, getWasmBasePath, clearTreeSitterBrowserCache };\n\n// Re-export renderers\nexport {\n renderStaticMermaid,\n renderPathsMermaid,\n renderStaticJSON,\n renderMultipleStaticJSON,\n type MermaidOptions,\n type MermaidStyles,\n type JSONRenderOptions,\n} from \"./renderers\";\n\n// Re-export types\nexport type {\n StaticWorkflowIR,\n StaticWorkflowNode,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticLoopNode,\n AnalysisWarning,\n AnalysisStats,\n AnalyzerOptions,\n};\n\n// =============================================================================\n// Types (duplicated to avoid importing from static-analyzer.ts which uses Node APIs)\n// =============================================================================\n\ninterface AnalyzerContext {\n sourceCode: string;\n filePath: string;\n opts: Required<AnalyzerOptions>;\n warnings: AnalysisWarning[];\n stats: AnalysisStats;\n workflowNames: Set<string>;\n currentWorkflow?: string;\n stepParameterName?: string;\n /** Whether the saga context is destructured (e.g., `({ step })` instead of `saga`) */\n isSagaDestructured?: boolean;\n /** The alias for `step` when saga is destructured */\n sagaStepAlias?: string;\n /** The alias for `tryStep` when saga is destructured */\n sagaTryStepAlias?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<AnalyzerOptions> = {\n tsConfigPath: \"./tsconfig.json\",\n resolveReferences: false,\n maxReferenceDepth: 5,\n includeLocations: true,\n detect: \"all\",\n assumeImported: false,\n};\n\n// =============================================================================\n// Public API\n// =============================================================================\n\nlet idCounter = 0;\n\n/**\n * Reset the ID counter (for testing).\n */\nexport function resetIdCounter(): void {\n idCounter = 0;\n}\n\n/**\n * Generate a unique ID.\n */\nfunction generateId(): string {\n return `ts-${++idCounter}`;\n}\n\n/**\n * Parse source code directly (browser-compatible).\n *\n * Note: This does NOT support file-based analysis - use analyzeWorkflowSource\n * with source code strings only.\n */\nexport async function analyzeWorkflowSource(\n sourceCode: string,\n options: AnalyzerOptions = {}\n): Promise<StaticWorkflowIR[]> {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const { parser } = await loadTreeSitterBrowser();\n const tree = parser.parse(sourceCode);\n\n if (!tree) {\n throw new Error(\"Failed to parse source code\");\n }\n\n const ctx: AnalyzerContext = {\n sourceCode,\n filePath: \"<source>\",\n opts,\n warnings: [],\n stats: createEmptyStats(),\n workflowNames: new Set(),\n };\n\n // Find all workflow definitions first to track names\n const definitions = findWorkflowDefinitions(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n definitions.forEach((d) => ctx.workflowNames.add(d.name));\n\n const results: StaticWorkflowIR[] = [];\n\n // Find and analyze createWorkflow calls (unless filtered to run only)\n if (opts.detect === \"all\" || opts.detect === \"createWorkflow\") {\n const workflowCalls = findWorkflowCalls(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n for (const call of workflowCalls) {\n const ir = analyzeWorkflowCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n // Find and analyze run() calls (unless filtered to createWorkflow only)\n if (opts.detect === \"all\" || opts.detect === \"run\") {\n const runCalls = findRunCalls(tree.rootNode as unknown as SyntaxNode, ctx);\n for (const call of runCalls) {\n const ir = analyzeRunCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n // Find and analyze createSagaWorkflow calls\n if (opts.detect === \"all\" || opts.detect === \"createSagaWorkflow\") {\n const sagaDefinitions = findSagaWorkflowDefinitions(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n sagaDefinitions.forEach((d) => ctx.workflowNames.add(d.name));\n const sagaCalls = findSagaWorkflowCalls(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n for (const call of sagaCalls) {\n const ir = analyzeSagaWorkflowCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n // Find and analyze runSaga() calls\n if (opts.detect === \"all\" || opts.detect === \"runSaga\") {\n const runSagaCalls = findRunSagaCalls(\n tree.rootNode as unknown as SyntaxNode,\n ctx\n );\n for (const call of runSagaCalls) {\n const ir = analyzeRunSagaCall(call, ctx);\n if (ir) {\n results.push(ir);\n }\n }\n }\n\n return results;\n}\n\n// =============================================================================\n// The following is a copy of the analysis logic from static-analyzer.ts\n// This duplication is necessary because static-analyzer.ts imports from\n// tree-sitter-loader.ts which uses Node.js APIs (fs, path, etc.)\n// =============================================================================\n\ninterface WorkflowDefinition {\n name: string;\n createWorkflowCall: SyntaxNode;\n /** Short description for labels/tooltips */\n description?: string;\n /** Full markdown documentation */\n markdown?: string;\n}\n\n/**\n * Extracted workflow options from createWorkflow call.\n */\ninterface WorkflowOptionsExtracted {\n description?: string;\n markdown?: string;\n}\n\n/**\n * Saga workflow definition found in the source.\n */\ninterface SagaWorkflowDefinition {\n name: string;\n createSagaWorkflowCall: SyntaxNode;\n description?: string;\n markdown?: string;\n}\n\n/**\n * Extract workflow options (description, markdown) from an options object literal.\n */\nfunction extractWorkflowOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): WorkflowOptionsExtracted {\n const result: WorkflowOptionsExtracted = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n if (key === \"description\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.description = value;\n } else if (key === \"markdown\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.markdown = value;\n }\n }\n }\n }\n\n return result;\n}\n\nfunction findWorkflowDefinitions(\n root: SyntaxNode,\n ctx: AnalyzerContext\n): WorkflowDefinition[] {\n const results: WorkflowDefinition[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (funcText === \"createWorkflow\") {\n const workflowName = extractWorkflowName(node, ctx);\n if (workflowName) {\n // Extract documentation options from second argument\n const args = node.childForFieldName(\"arguments\");\n const optionsNode = args?.namedChildren[1]; // Second arg is options\n const options = optionsNode\n ? extractWorkflowOptions(optionsNode, ctx)\n : {};\n\n results.push({\n name: workflowName,\n createWorkflowCall: node,\n description: options.description,\n markdown: options.markdown,\n });\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findWorkflowCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const definitions = findWorkflowDefinitions(root, ctx);\n const workflowNames = new Set(definitions.map((d) => d.name));\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (workflowNames.has(funcText)) {\n const args = node.childForFieldName(\"arguments\");\n if (args) {\n const firstArg = args.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findAwaitlyImports(\n root: SyntaxNode,\n exportName: string,\n ctx: AnalyzerContext\n): Set<string> {\n const importedNames = new Set<string>();\n\n traverseNode(root, (node) => {\n if (node.type === \"import_statement\") {\n let isTypeOnly = false;\n for (let i = 0; i < node.childCount; i++) {\n const child = node.children[i];\n if (child && child.type === \"type\") {\n isTypeOnly = true;\n break;\n }\n }\n if (isTypeOnly) {\n return;\n }\n\n const sourceNode = node.childForFieldName(\"source\");\n if (sourceNode) {\n const sourceText = getText(sourceNode, ctx);\n const modulePath = sourceText.slice(1, -1);\n if (modulePath === \"awaitly\" || modulePath.startsWith(\"@awaitly/\")) {\n for (const child of node.namedChildren) {\n if (child.type === \"import_clause\") {\n for (const clauseChild of child.namedChildren) {\n if (clauseChild.type === \"named_imports\") {\n for (const specifier of clauseChild.namedChildren) {\n if (specifier.type === \"import_specifier\") {\n let isTypeOnlySpecifier = false;\n for (const specChild of specifier.children) {\n if (specChild.type === \"type\") {\n isTypeOnlySpecifier = true;\n break;\n }\n }\n if (isTypeOnlySpecifier) {\n continue;\n }\n\n const nameNode = specifier.childForFieldName(\"name\");\n const aliasNode = specifier.childForFieldName(\"alias\");\n\n if (nameNode) {\n const importedName = getText(nameNode, ctx);\n if (importedName === exportName) {\n const localName = aliasNode\n ? getText(aliasNode, ctx)\n : importedName;\n importedNames.add(localName);\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n });\n\n return importedNames;\n}\n\n/**\n * Recursively search for var declarations within a node.\n * Used to find function-scoped var declarations in nested blocks.\n */\nfunction hasVarDeclaration(\n node: SyntaxNode,\n identifierName: string,\n ctx: AnalyzerContext\n): boolean {\n // Check if this node is a var declaration\n if (node.type === \"variable_declaration\") {\n for (const declarator of node.namedChildren) {\n if (declarator.type === \"variable_declarator\") {\n const nameNode = declarator.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n }\n\n // Don't recurse into nested functions (they have their own scope)\n if (\n node.type === \"arrow_function\" ||\n node.type === \"function_expression\" ||\n node.type === \"function_declaration\"\n ) {\n return false;\n }\n\n // Recursively check children\n for (const child of node.namedChildren) {\n if (hasVarDeclaration(child, identifierName, ctx)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Check if an identifier at a given node is shadowed by a local declaration.\n * Walks up the AST looking for variable/function declarations or parameters\n * that would shadow the identifier before reaching module scope.\n */\nfunction isIdentifierShadowed(\n node: SyntaxNode,\n identifierName: string,\n ctx: AnalyzerContext\n): boolean {\n let current: SyntaxNode | null = node.parent;\n\n while (current) {\n // Check for variable declarations in statement blocks\n if (\n current.type === \"statement_block\" ||\n current.type === \"program\"\n ) {\n // Check ALL declarations in the scope (not just before the call site)\n // because const/let create TDZ and function declarations are hoisted\n for (const child of current.namedChildren) {\n // Check let/const (block-scoped) at this level only\n if (child.type === \"lexical_declaration\") {\n for (const declarator of child.namedChildren) {\n if (declarator.type === \"variable_declarator\") {\n const nameNode = declarator.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n }\n // Check var (function-scoped) at this level only - nested vars handled below\n else if (child.type === \"variable_declaration\") {\n for (const declarator of child.namedChildren) {\n if (declarator.type === \"variable_declarator\") {\n const nameNode = declarator.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n } else if (child.type === \"function_declaration\") {\n const nameNode = child.childForFieldName(\"name\");\n if (nameNode && getText(nameNode, ctx) === identifierName) {\n return true;\n }\n }\n }\n\n // At program scope, search nested blocks for var declarations (they're program-scoped)\n if (current.type === \"program\") {\n if (hasVarDeclaration(current, identifierName, ctx)) {\n return true;\n }\n }\n }\n\n // Check function parameters and search entire function body for var declarations\n if (\n current.type === \"arrow_function\" ||\n current.type === \"function_expression\" ||\n current.type === \"function_declaration\" ||\n current.type === \"method_definition\"\n ) {\n const params = current.childForFieldName(\"parameters\");\n if (params) {\n for (const param of params.namedChildren) {\n // Handle simple identifier parameters\n if (param.type === \"identifier\" && getText(param, ctx) === identifierName) {\n return true;\n }\n // Handle destructuring patterns\n if (param.type === \"object_pattern\" || param.type === \"array_pattern\") {\n // For simplicity, check if the identifier appears anywhere in the pattern\n let found = false;\n traverseNode(param, (n) => {\n if (n.type === \"identifier\" && getText(n, ctx) === identifierName) {\n found = true;\n }\n });\n if (found) return true;\n }\n // Handle assignment patterns (default values)\n if (param.type === \"assignment_pattern\") {\n const left = param.childForFieldName(\"left\");\n if (left?.type === \"identifier\" && getText(left, ctx) === identifierName) {\n return true;\n }\n }\n }\n }\n\n // Search entire function body for var declarations (they're function-scoped)\n const body = current.childForFieldName(\"body\");\n if (body && hasVarDeclaration(body, identifierName, ctx)) {\n return true;\n }\n }\n\n // Stop at program level (module scope)\n if (current.type === \"program\") break;\n\n current = current.parent;\n }\n\n return false;\n}\n\nfunction findRunCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const runImportNames = findAwaitlyImports(root, \"run\", ctx);\n\n if (ctx.opts.assumeImported) {\n runImportNames.add(\"run\");\n }\n\n if (runImportNames.size === 0) {\n return [];\n }\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode && funcNode.type === \"identifier\") {\n const funcText = getText(funcNode, ctx);\n if (runImportNames.has(funcText)) {\n // Check if the identifier is shadowed by a local declaration\n if (isIdentifierShadowed(node, funcText, ctx)) {\n return; // Skip - this is a shadowed local variable\n }\n\n const args = node.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findSagaWorkflowDefinitions(\n root: SyntaxNode,\n ctx: AnalyzerContext\n): SagaWorkflowDefinition[] {\n const results: SagaWorkflowDefinition[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (funcText === \"createSagaWorkflow\") {\n const workflowName = extractWorkflowName(node, ctx);\n if (workflowName) {\n const args = node.childForFieldName(\"arguments\");\n const optionsNode = args?.namedChildren[1];\n const options = optionsNode\n ? extractWorkflowOptions(optionsNode, ctx)\n : {};\n\n results.push({\n name: workflowName,\n createSagaWorkflowCall: node,\n description: options.description,\n markdown: options.markdown,\n });\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findSagaWorkflowCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const definitions = findSagaWorkflowDefinitions(root, ctx);\n const sagaNames = new Set(definitions.map((d) => d.name));\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode) {\n const funcText = getText(funcNode, ctx);\n if (sagaNames.has(funcText)) {\n const args = node.childForFieldName(\"arguments\");\n if (args) {\n const firstArg = args.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction findRunSagaCalls(root: SyntaxNode, ctx: AnalyzerContext): SyntaxNode[] {\n const runSagaImportNames = findAwaitlyImports(root, \"runSaga\", ctx);\n\n if (ctx.opts.assumeImported) {\n runSagaImportNames.add(\"runSaga\");\n }\n\n if (runSagaImportNames.size === 0) {\n return [];\n }\n\n const results: SyntaxNode[] = [];\n\n traverseNode(root, (node) => {\n if (node.type === \"call_expression\") {\n const funcNode = node.childForFieldName(\"function\");\n if (funcNode && funcNode.type === \"identifier\") {\n const funcText = getText(funcNode, ctx);\n if (runSagaImportNames.has(funcText)) {\n if (isIdentifierShadowed(node, funcText, ctx)) {\n return;\n }\n\n const args = node.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n if (\n firstArg?.type === \"arrow_function\" ||\n firstArg?.type === \"function_expression\"\n ) {\n results.push(node);\n }\n }\n }\n }\n });\n\n return results;\n}\n\nfunction analyzeSagaWorkflowCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const funcNode = callNode.childForFieldName(\"function\");\n const workflowName = funcNode ? getText(funcNode, parentCtx) : \"<unknown>\";\n\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n workflowStats.sagaWorkflowCount = 1;\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: `Could not find callback for saga workflow ${workflowName}`,\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const prevWorkflow = ctx.currentWorkflow;\n ctx.currentWorkflow = workflowName;\n\n const sagaParamInfo = extractSagaParameterInfo(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n const prevIsSagaDestructured = ctx.isSagaDestructured;\n const prevSagaStepAlias = ctx.sagaStepAlias;\n const prevSagaTryStepAlias = ctx.sagaTryStepAlias;\n ctx.stepParameterName = sagaParamInfo?.name;\n ctx.isSagaDestructured = sagaParamInfo?.isDestructured;\n ctx.sagaStepAlias = sagaParamInfo?.stepAlias;\n ctx.sagaTryStepAlias = sagaParamInfo?.tryStepAlias;\n\n const children = analyzeSagaCallback(callbackNode, ctx);\n\n ctx.currentWorkflow = prevWorkflow;\n ctx.stepParameterName = prevStepParamName;\n ctx.isSagaDestructured = prevIsSagaDestructured;\n ctx.sagaStepAlias = prevSagaStepAlias;\n ctx.sagaTryStepAlias = prevSagaTryStepAlias;\n\n const treeRoot = (callNode as unknown as { tree?: { rootNode: SyntaxNode } })\n .tree?.rootNode;\n const definitions = treeRoot\n ? findSagaWorkflowDefinitions(treeRoot, parentCtx)\n : [];\n const definition = definitions.find((d) => d.name === workflowName);\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"createSagaWorkflow\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n description: definition?.description,\n markdown: definition?.markdown,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction analyzeRunSagaCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n workflowStats.sagaWorkflowCount = 1;\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: \"Could not find callback for runSaga()\",\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const workflowName = generateRunSagaName(callNode, ctx);\n\n const sagaParamInfo = extractSagaParameterInfo(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n const prevIsSagaDestructured = ctx.isSagaDestructured;\n const prevSagaStepAlias = ctx.sagaStepAlias;\n const prevSagaTryStepAlias = ctx.sagaTryStepAlias;\n ctx.stepParameterName = sagaParamInfo?.name;\n ctx.isSagaDestructured = sagaParamInfo?.isDestructured;\n ctx.sagaStepAlias = sagaParamInfo?.stepAlias;\n ctx.sagaTryStepAlias = sagaParamInfo?.tryStepAlias;\n\n const children = analyzeSagaCallback(callbackNode, ctx);\n\n ctx.stepParameterName = prevStepParamName;\n ctx.isSagaDestructured = prevIsSagaDestructured;\n ctx.sagaStepAlias = prevSagaStepAlias;\n ctx.sagaTryStepAlias = prevSagaTryStepAlias;\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"runSaga\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n location: ctx.opts.includeLocations ? getLocation(callNode, ctx) : undefined,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction generateRunSagaName(callNode: SyntaxNode, ctx: AnalyzerContext): string {\n const line = callNode.startPosition.row + 1;\n const filePath = ctx.filePath;\n const fileName = filePath.includes(\"/\")\n ? filePath.split(\"/\").pop() || filePath\n : filePath.includes(\"\\\\\")\n ? filePath.split(\"\\\\\").pop() || filePath\n : filePath;\n return `runSaga@${fileName}:${line}`;\n}\n\n/**\n * Result of extracting saga parameter info.\n */\ninterface SagaParameterInfo {\n /** The saga parameter name (when not destructured) */\n name?: string;\n /** Whether the saga context is destructured (e.g., `({ step })` instead of `saga`) */\n isDestructured: boolean;\n /** The alias for `step` when destructured (e.g., \"step\" or \"s\" from `{ step: s }`) */\n stepAlias?: string;\n /** The alias for `tryStep` when destructured */\n tryStepAlias?: string;\n}\n\n/**\n * Extract the saga parameter info from a saga workflow callback.\n * e.g., `async (saga, deps) => {...}` -> { name: \"saga\", isDestructured: false }\n * e.g., `async ({ step }, deps) => {...}` -> { isDestructured: true, stepAlias: \"step\" }\n * e.g., `async ({ step: s, tryStep }, deps) => {...}` -> { isDestructured: true, stepAlias: \"s\", tryStepAlias: \"tryStep\" }\n */\nfunction extractSagaParameterInfo(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): SagaParameterInfo | undefined {\n const params = callbackNode.childForFieldName(\"parameters\");\n if (!params) return undefined;\n\n const firstParam = params.namedChildren[0];\n if (!firstParam) return undefined;\n\n if (firstParam.type === \"identifier\") {\n return { name: getText(firstParam, ctx), isDestructured: false };\n }\n\n if (firstParam.type === \"required_parameter\") {\n const patternNode = firstParam.childForFieldName(\"pattern\");\n if (patternNode) {\n if (patternNode.type === \"object_pattern\") {\n const aliases = extractSagaAliasesFromObjectPattern(patternNode, ctx);\n if (aliases.stepAlias || aliases.tryStepAlias) {\n return { isDestructured: true, ...aliases };\n }\n }\n return { name: getText(patternNode, ctx), isDestructured: false };\n }\n }\n\n // Handle direct object_pattern (no type annotation)\n if (firstParam.type === \"object_pattern\") {\n const aliases = extractSagaAliasesFromObjectPattern(firstParam, ctx);\n if (aliases.stepAlias || aliases.tryStepAlias) {\n return { isDestructured: true, ...aliases };\n }\n }\n\n return undefined;\n}\n\n/**\n * Extract step and tryStep aliases from a saga destructuring pattern.\n * e.g., `{ step }` -> { stepAlias: \"step\" }\n * e.g., `{ step: s, tryStep: ts }` -> { stepAlias: \"s\", tryStepAlias: \"ts\" }\n */\nfunction extractSagaAliasesFromObjectPattern(\n objectPattern: SyntaxNode,\n ctx: AnalyzerContext\n): { stepAlias?: string; tryStepAlias?: string } {\n const result: { stepAlias?: string; tryStepAlias?: string } = {};\n\n for (const child of objectPattern.namedChildren) {\n // Handle pair_pattern: `step: s` or `step: s = fallback`\n if (child.type === \"pair_pattern\") {\n const keyNode = child.childForFieldName(\"key\");\n const valueNode = child.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n if (key === \"step\" || key === \"tryStep\") {\n let alias: string;\n // Handle assignment_pattern: `step: s = fallback`\n if (valueNode.type === \"assignment_pattern\") {\n const left = valueNode.childForFieldName(\"left\");\n alias = left ? getText(left, ctx) : getText(valueNode, ctx);\n } else {\n alias = getText(valueNode, ctx);\n }\n if (key === \"step\") {\n result.stepAlias = alias;\n } else {\n result.tryStepAlias = alias;\n }\n }\n }\n }\n\n // Handle shorthand_property_identifier_pattern: `{ step }` or `{ tryStep }`\n if (child.type === \"shorthand_property_identifier_pattern\") {\n const name = getText(child, ctx);\n if (name === \"step\") {\n result.stepAlias = \"step\";\n } else if (name === \"tryStep\") {\n result.tryStepAlias = \"tryStep\";\n }\n }\n\n // Handle assignment_pattern: `{ step = fallback }` or `{ tryStep = fallback }`\n if (child.type === \"assignment_pattern\") {\n const left = child.childForFieldName(\"left\");\n if (left) {\n const name = getText(left, ctx);\n if (name === \"step\") {\n result.stepAlias = \"step\";\n } else if (name === \"tryStep\") {\n result.tryStepAlias = \"tryStep\";\n }\n }\n }\n }\n\n return result;\n}\n\nfunction analyzeSagaCallback(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const body = callbackNode.childForFieldName(\"body\");\n if (!body) return [];\n\n if (body.type === \"statement_block\") {\n return analyzeSagaStatements(body.namedChildren, ctx);\n }\n\n return analyzeSagaExpression(body, ctx);\n}\n\nfunction analyzeSagaStatements(\n statements: SyntaxNode[],\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const stmt of statements) {\n const nodes = analyzeSagaStatement(stmt, ctx);\n results.push(...nodes);\n }\n\n return results;\n}\n\nfunction analyzeSagaStatement(\n stmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n switch (stmt.type) {\n case \"expression_statement\": {\n const expr = stmt.namedChildren[0];\n if (expr) {\n return analyzeSagaExpression(expr, ctx);\n }\n return [];\n }\n\n case \"variable_declaration\":\n case \"lexical_declaration\":\n return analyzeSagaVariableDeclaration(stmt, ctx);\n\n case \"return_statement\": {\n const returnExpr = stmt.childForFieldName(\"value\");\n if (returnExpr) {\n return analyzeSagaExpression(returnExpr, ctx);\n }\n return [];\n }\n\n case \"if_statement\":\n return analyzeSagaIfStatement(stmt, ctx);\n\n case \"for_statement\":\n case \"for_in_statement\":\n case \"while_statement\":\n return analyzeSagaLoopStatement(stmt, ctx);\n\n case \"switch_statement\":\n return analyzeSagaSwitchStatement(stmt, ctx);\n\n default:\n return [];\n }\n}\n\nfunction analyzeSagaExpression(\n expr: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (expr.type === \"await_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeSagaExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"parenthesized_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeSagaExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"call_expression\") {\n return analyzeSagaCallExpression(expr, ctx);\n }\n\n return [];\n}\n\nfunction analyzeSagaVariableDeclaration(\n decl: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const child of decl.namedChildren) {\n if (child.type === \"variable_declarator\") {\n const value = child.childForFieldName(\"value\");\n if (value) {\n results.push(...analyzeSagaExpression(value, ctx));\n }\n }\n }\n\n return results;\n}\n\nfunction analyzeSagaIfStatement(\n ifStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.conditionalCount++;\n\n const conditionNode = ifStmt.childForFieldName(\"condition\");\n const consequentNode = ifStmt.childForFieldName(\"consequence\");\n const alternateNode = ifStmt.childForFieldName(\"alternative\");\n\n const condition = conditionNode\n ? getText(conditionNode, ctx).replace(/^\\(|\\)$/g, \"\")\n : \"<unknown>\";\n\n const consequent = consequentNode\n ? analyzeSagaBlock(consequentNode, ctx)\n : [];\n\n let alternate: StaticFlowNode[] | undefined;\n if (alternateNode) {\n if (alternateNode.type === \"else_clause\") {\n const elseContent = alternateNode.namedChildren[0];\n if (elseContent) {\n alternate = analyzeSagaBlock(elseContent, ctx);\n }\n } else {\n alternate = analyzeSagaBlock(alternateNode, ctx);\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"conditional\",\n condition,\n helper: null,\n consequent,\n alternate: alternate?.length ? alternate : undefined,\n location: ctx.opts.includeLocations ? getLocation(ifStmt, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeSagaBlock(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (node.type === \"statement_block\") {\n return analyzeSagaStatements(node.namedChildren, ctx);\n }\n return analyzeSagaStatement(node, ctx);\n}\n\nfunction analyzeSagaLoopStatement(\n loopStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = loopStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeSagaBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n let loopType: \"for\" | \"while\" | \"for-of\" | \"for-in\" = \"for\";\n if (loopStmt.type === \"while_statement\") {\n loopType = \"while\";\n } else if (loopStmt.type === \"for_in_statement\") {\n const stmtText = getText(loopStmt, ctx);\n loopType = stmtText.includes(\" of \") ? \"for-of\" : \"for-in\";\n }\n\n const rightNode = loopStmt.childForFieldName(\"right\");\n const iterSource = rightNode ? getText(rightNode, ctx) : undefined;\n\n return [\n {\n id: generateId(),\n type: \"loop\",\n loopType,\n iterSource,\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(loopStmt, ctx) : undefined,\n } as StaticLoopNode,\n ];\n}\n\nfunction analyzeSagaSwitchStatement(\n switchStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const valueNode = switchStmt.childForFieldName(\"value\");\n const bodyNode = switchStmt.childForFieldName(\"body\");\n\n const expression = valueNode\n ? getText(valueNode, ctx).replace(/^\\(|\\)$/g, \"\")\n : \"<unknown>\";\n\n const cases: StaticSwitchCase[] = [];\n let hasStepCalls = false;\n\n if (bodyNode) {\n for (const caseNode of bodyNode.namedChildren) {\n if (caseNode.type === \"switch_case\" || caseNode.type === \"switch_default\") {\n const caseValueNode = caseNode.childForFieldName(\"value\");\n const isDefault = caseNode.type === \"switch_default\" || !caseValueNode;\n const caseValue = caseValueNode ? getText(caseValueNode, ctx) : undefined;\n\n // Analyze statements in the case body (all named children except the value)\n const bodyStatements = caseNode.namedChildren.filter(\n (n) => n !== caseValueNode\n );\n const body = analyzeSagaStatements(bodyStatements, ctx);\n\n if (body.length > 0) {\n hasStepCalls = true;\n }\n\n cases.push({\n value: caseValue,\n isDefault,\n body,\n });\n }\n }\n }\n\n // Only count if there are step calls inside\n if (hasStepCalls) {\n ctx.stats.conditionalCount++;\n }\n\n // If no step calls, return empty\n if (!hasStepCalls) {\n return [];\n }\n\n const switchNode: StaticSwitchNode = {\n id: generateId(),\n type: \"switch\",\n expression,\n cases,\n location: ctx.opts.includeLocations ? getLocation(switchStmt, ctx) : undefined,\n };\n\n return [switchNode];\n}\n\n/**\n * Analyze a saga call expression for saga.step() and saga.tryStep() calls.\n * Handles both forms:\n * - `saga.step()` when saga context is passed as identifier (e.g., `async (saga) => ...`)\n * - `step()` when saga context is destructured (e.g., `async ({ step }) => ...`)\n */\nfunction analyzeSagaCallExpression(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const funcNode = call.childForFieldName(\"function\");\n if (!funcNode) return [];\n\n const funcText = getText(funcNode, ctx);\n const sagaParam = ctx.stepParameterName || \"saga\";\n\n // When saga context is destructured, match against the destructured aliases\n if (ctx.isSagaDestructured) {\n // Check for step() calls (destructured from saga context)\n if (ctx.sagaStepAlias && funcText === ctx.sagaStepAlias) {\n return [analyzeSagaStepCall(call, ctx)];\n }\n\n // Check for tryStep() calls (destructured from saga context)\n if (ctx.sagaTryStepAlias && funcText === ctx.sagaTryStepAlias) {\n return [analyzeSagaTryStepCall(call, ctx)];\n }\n\n return [];\n }\n\n if (funcText === `${sagaParam}.step`) {\n return [analyzeSagaStepCall(call, ctx)];\n }\n\n if (funcText === `${sagaParam}.tryStep`) {\n return [analyzeSagaTryStepCall(call, ctx)];\n }\n\n return [];\n}\n\nfunction analyzeSagaStepCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticSagaStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n const secondArg = args?.namedChildren[1];\n\n let callee = \"<unknown>\";\n if (firstArg) {\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n const body = firstArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(firstArg, ctx);\n }\n }\n\n const { hasCompensation, compensationCallee, name, description, markdown } =\n extractSagaStepOptions(secondArg, ctx);\n\n if (hasCompensation) {\n ctx.stats.compensatedStepCount = (ctx.stats.compensatedStepCount || 0) + 1;\n }\n\n return {\n id: generateId(),\n type: \"saga-step\",\n callee,\n name,\n description,\n markdown,\n hasCompensation,\n compensationCallee,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction analyzeSagaTryStepCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticSagaStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n const secondArg = args?.namedChildren[1];\n\n let callee = \"<unknown>\";\n if (firstArg) {\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n const body = firstArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(firstArg, ctx);\n }\n }\n\n const { hasCompensation, compensationCallee, name, description, markdown } =\n extractSagaStepOptions(secondArg, ctx);\n\n if (hasCompensation) {\n ctx.stats.compensatedStepCount = (ctx.stats.compensatedStepCount || 0) + 1;\n }\n\n return {\n id: generateId(),\n type: \"saga-step\",\n callee,\n name,\n description,\n markdown,\n hasCompensation,\n compensationCallee,\n isTryStep: true,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction extractSagaStepOptions(\n optionsNode: SyntaxNode | undefined,\n ctx: AnalyzerContext\n): {\n hasCompensation: boolean;\n compensationCallee?: string;\n name?: string;\n description?: string;\n markdown?: string;\n} {\n const result = {\n hasCompensation: false,\n compensationCallee: undefined as string | undefined,\n name: undefined as string | undefined,\n description: undefined as string | undefined,\n markdown: undefined as string | undefined,\n };\n\n if (!optionsNode || optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"compensate\") {\n result.hasCompensation = true;\n if (\n valueNode.type === \"arrow_function\" ||\n valueNode.type === \"function_expression\"\n ) {\n const body = valueNode.childForFieldName(\"body\");\n if (body) {\n result.compensationCallee = extractCalleeFromFunctionBody(body, ctx);\n }\n }\n } else if (key === \"name\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.name = value;\n } else if (key === \"description\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.description = value;\n } else if (key === \"markdown\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.markdown = value;\n }\n }\n }\n }\n\n return result;\n}\n\nfunction generateRunName(callNode: SyntaxNode, ctx: AnalyzerContext): string {\n const line = callNode.startPosition.row + 1;\n const filePath = ctx.filePath;\n const fileName = filePath.includes(\"/\")\n ? filePath.split(\"/\").pop() || filePath\n : filePath.includes(\"\\\\\")\n ? filePath.split(\"\\\\\").pop() || filePath\n : filePath;\n return `run@${fileName}:${line}`;\n}\n\nfunction analyzeRunCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: \"Could not find callback for run()\",\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const workflowName = generateRunName(callNode, ctx);\n const stepParamName = extractStepParameterName(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n ctx.stepParameterName = stepParamName;\n\n const children = analyzeCallback(callbackNode, ctx);\n\n ctx.stepParameterName = prevStepParamName;\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"run\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n location: ctx.opts.includeLocations ? getLocation(callNode, ctx) : undefined,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction analyzeWorkflowCall(\n callNode: SyntaxNode,\n parentCtx: AnalyzerContext\n): StaticWorkflowIR | null {\n const funcNode = callNode.childForFieldName(\"function\");\n const workflowName = funcNode ? getText(funcNode, parentCtx) : \"<unknown>\";\n\n const args = callNode.childForFieldName(\"arguments\");\n const callbackNode = args?.namedChildren[0];\n\n const workflowWarnings: AnalysisWarning[] = [];\n const workflowStats = createEmptyStats();\n\n const ctx: AnalyzerContext = {\n ...parentCtx,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n if (\n !callbackNode ||\n (callbackNode.type !== \"arrow_function\" &&\n callbackNode.type !== \"function_expression\")\n ) {\n workflowWarnings.push({\n code: \"CALLBACK_NOT_FOUND\",\n message: `Could not find callback for workflow ${workflowName}`,\n location: getLocation(callNode, ctx),\n });\n return null;\n }\n\n const prevWorkflow = ctx.currentWorkflow;\n ctx.currentWorkflow = workflowName;\n\n const stepParamName = extractStepParameterName(callbackNode, ctx);\n const prevStepParamName = ctx.stepParameterName;\n ctx.stepParameterName = stepParamName;\n\n const children = analyzeCallback(callbackNode, ctx);\n\n ctx.currentWorkflow = prevWorkflow;\n ctx.stepParameterName = prevStepParamName;\n\n // Find the definition to get documentation\n const definitions = findWorkflowDefinitions(\n (callNode as unknown as { tree?: { rootNode: SyntaxNode } }).tree?.rootNode || callNode,\n parentCtx\n );\n const definition = definitions.find((d) => d.name === workflowName);\n\n const rootNode: StaticWorkflowNode = {\n id: generateId(),\n type: \"workflow\",\n workflowName,\n source: \"createWorkflow\",\n dependencies: [],\n errorTypes: [],\n children: wrapInSequence(children),\n description: definition?.description,\n markdown: definition?.markdown,\n };\n\n const metadata: StaticAnalysisMetadata = {\n analyzedAt: Date.now(),\n filePath: ctx.filePath,\n warnings: workflowWarnings,\n stats: workflowStats,\n };\n\n return {\n root: rootNode,\n metadata,\n references: new Map(),\n };\n}\n\nfunction extractWorkflowName(\n callNode: SyntaxNode,\n ctx: AnalyzerContext\n): string | null {\n let current: SyntaxNode | null = callNode;\n while (current) {\n if (current.type === \"variable_declarator\") {\n const nameNode = current.childForFieldName(\"name\");\n if (nameNode) {\n return getText(nameNode, ctx);\n }\n }\n current = current.parent;\n }\n return null;\n}\n\nfunction extractStepParameterName(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n const params = callbackNode.childForFieldName(\"parameters\");\n if (!params) return undefined;\n\n const firstParam = params.namedChildren[0];\n if (!firstParam) return undefined;\n\n if (firstParam.type === \"identifier\") {\n return getText(firstParam, ctx);\n }\n\n if (firstParam.type === \"required_parameter\") {\n const patternNode = firstParam.childForFieldName(\"pattern\");\n if (patternNode) {\n if (patternNode.type === \"object_pattern\") {\n return extractStepFromObjectPattern(patternNode, ctx);\n }\n return getText(patternNode, ctx);\n }\n }\n\n if (firstParam.type === \"object_pattern\") {\n return extractStepFromObjectPattern(firstParam, ctx);\n }\n\n return undefined;\n}\n\nfunction extractStepFromObjectPattern(\n objectPattern: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n for (const child of objectPattern.namedChildren) {\n if (child.type === \"pair_pattern\") {\n const keyNode = child.childForFieldName(\"key\");\n const valueNode = child.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n if (key === \"step\") {\n if (valueNode.type === \"assignment_pattern\") {\n const left = valueNode.childForFieldName(\"left\");\n if (left) {\n return getText(left, ctx);\n }\n }\n return getText(valueNode, ctx);\n }\n }\n }\n\n if (child.type === \"shorthand_property_identifier_pattern\") {\n const name = getText(child, ctx);\n if (name === \"step\") {\n return \"step\";\n }\n }\n\n if (child.type === \"assignment_pattern\") {\n const left = child.childForFieldName(\"left\");\n if (left) {\n const name = getText(left, ctx);\n if (name === \"step\") {\n return \"step\";\n }\n }\n }\n }\n\n return undefined;\n}\n\nfunction analyzeCallback(\n callbackNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const body = callbackNode.childForFieldName(\"body\");\n if (!body) return [];\n\n if (body.type === \"statement_block\") {\n return analyzeStatements(body.namedChildren, ctx);\n }\n\n return analyzeExpression(body, ctx);\n}\n\nfunction analyzeStatements(\n statements: SyntaxNode[],\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const stmt of statements) {\n const nodes = analyzeStatement(stmt, ctx);\n results.push(...nodes);\n }\n\n return results;\n}\n\nfunction analyzeStatement(\n stmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n switch (stmt.type) {\n case \"expression_statement\": {\n const expr = stmt.namedChildren[0];\n if (expr) {\n return analyzeExpression(expr, ctx);\n }\n return [];\n }\n\n case \"variable_declaration\":\n case \"lexical_declaration\":\n return analyzeVariableDeclaration(stmt, ctx);\n\n case \"return_statement\": {\n const returnExpr = stmt.childForFieldName(\"value\");\n if (returnExpr) {\n return analyzeExpression(returnExpr, ctx);\n }\n return [];\n }\n\n case \"if_statement\":\n return analyzeIfStatement(stmt, ctx);\n\n case \"for_statement\":\n return analyzeForStatement(stmt, ctx);\n\n case \"for_in_statement\":\n return analyzeForInStatement(stmt, ctx);\n\n case \"while_statement\":\n return analyzeWhileStatement(stmt, ctx);\n\n case \"switch_statement\":\n return analyzeSwitchStatement(stmt, ctx);\n\n default:\n return [];\n }\n}\n\nfunction analyzeExpression(\n expr: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (expr.type === \"await_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"parenthesized_expression\") {\n const inner = expr.namedChildren[0];\n if (inner) {\n return analyzeExpression(inner, ctx);\n }\n return [];\n }\n\n if (expr.type === \"call_expression\") {\n return analyzeCallExpression(expr, ctx);\n }\n\n return [];\n}\n\nfunction analyzeVariableDeclaration(\n decl: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const results: StaticFlowNode[] = [];\n\n for (const child of decl.namedChildren) {\n if (child.type === \"variable_declarator\") {\n const value = child.childForFieldName(\"value\");\n if (value) {\n results.push(...analyzeExpression(value, ctx));\n }\n }\n }\n\n return results;\n}\n\nfunction analyzeStreamWritableCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStreamNode {\n ctx.stats.streamCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const optionsArg = args?.namedChildren[0];\n\n const options = optionsArg ? extractStreamOptions(optionsArg, ctx) : {};\n\n return {\n id: generateId(),\n type: \"stream\",\n streamType: \"write\",\n namespace: options.namespace,\n options: options.highWaterMark !== undefined ? { highWaterMark: options.highWaterMark } : undefined,\n callee: \"step.getWritable\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction analyzeStreamReadableCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStreamNode {\n ctx.stats.streamCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const optionsArg = args?.namedChildren[0];\n\n const options = optionsArg ? extractStreamOptions(optionsArg, ctx) : {};\n\n return {\n id: generateId(),\n type: \"stream\",\n streamType: \"read\",\n namespace: options.namespace,\n options: options.startIndex !== undefined ? { startIndex: options.startIndex } : undefined,\n callee: \"step.getReadable\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction analyzeStreamForEachCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStreamNode {\n ctx.stats.streamCount++;\n\n const args = call.childForFieldName(\"arguments\");\n // streamForEach(source, processor, options?)\n const optionsArg = args?.namedChildren[2];\n\n const options = optionsArg ? extractStreamForEachOptions(optionsArg, ctx) : {};\n\n return {\n id: generateId(),\n type: \"stream\",\n streamType: \"forEach\",\n options: {\n ...(options.concurrency !== undefined ? { concurrency: options.concurrency } : {}),\n ...(options.checkpointInterval !== undefined ? { checkpointInterval: options.checkpointInterval } : {}),\n },\n callee: \"step.streamForEach\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction extractStreamOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): { namespace?: string; highWaterMark?: number | \"<dynamic>\"; startIndex?: number | \"<dynamic>\" } {\n const result: { namespace?: string; highWaterMark?: number | \"<dynamic>\"; startIndex?: number | \"<dynamic>\" } = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"namespace\") {\n const value = extractStringValue(valueNode, ctx);\n if (value && value !== \"<dynamic>\") result.namespace = value;\n } else if (key === \"highWaterMark\") {\n result.highWaterMark = extractNumberValue(valueNode, ctx);\n } else if (key === \"startIndex\") {\n result.startIndex = extractNumberValue(valueNode, ctx);\n }\n }\n }\n }\n\n return result;\n}\n\nfunction extractStreamForEachOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): { concurrency?: number | \"<dynamic>\"; checkpointInterval?: number | \"<dynamic>\" } {\n const result: { concurrency?: number | \"<dynamic>\"; checkpointInterval?: number | \"<dynamic>\" } = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"concurrency\") {\n result.concurrency = extractNumberValue(valueNode, ctx);\n } else if (key === \"checkpointInterval\") {\n result.checkpointInterval = extractNumberValue(valueNode, ctx);\n }\n }\n }\n }\n\n return result;\n}\n\nfunction analyzeCallExpression(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const funcNode = call.childForFieldName(\"function\");\n if (!funcNode) return [];\n\n const funcText = getText(funcNode, ctx);\n\n const stepParam = ctx.stepParameterName || \"step\";\n if (funcText === stepParam) {\n return [analyzeStepCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.retry`) {\n return [analyzeStepRetryCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.withTimeout`) {\n return [analyzeStepTimeoutCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.parallel`) {\n return analyzeParallelCall(call, ctx);\n }\n\n if (funcText === `${stepParam}.race`) {\n return analyzeRaceCall(call, ctx);\n }\n\n // Stream operations\n if (funcText === `${stepParam}.getWritable`) {\n return [analyzeStreamWritableCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.getReadable`) {\n return [analyzeStreamReadableCall(call, ctx)];\n }\n\n if (funcText === `${stepParam}.streamForEach`) {\n return [analyzeStreamForEachCall(call, ctx)];\n }\n\n if ([\"when\", \"unless\", \"whenOr\", \"unlessOr\"].includes(funcText)) {\n return analyzeConditionalHelper(\n call,\n funcText as \"when\" | \"unless\" | \"whenOr\" | \"unlessOr\",\n ctx\n );\n }\n\n if (funcText === \"allAsync\" || funcText === \"allSettledAsync\") {\n return analyzeAllAsyncCall(\n call,\n funcText === \"allAsync\" ? \"all\" : \"allSettled\",\n ctx\n );\n }\n\n if (funcText === \"anyAsync\") {\n return analyzeAnyAsyncCall(call, ctx);\n }\n\n if (isLikelyWorkflowCall(call, funcText, ctx)) {\n return analyzeWorkflowRefCall(call, funcText, ctx);\n }\n\n return [];\n}\n\nfunction isLikelyWorkflowCall(\n call: SyntaxNode,\n funcText: string,\n ctx: AnalyzerContext\n): boolean {\n if (funcText === ctx.currentWorkflow) {\n return false;\n }\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg) return false;\n\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n if (ctx.workflowNames.has(funcText)) {\n return true;\n }\n\n const params = firstArg.childForFieldName(\"parameters\");\n if (params) {\n const paramText = getText(params, ctx);\n if (paramText.includes(\"step\") || paramText.includes(\"deps\")) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction analyzeWorkflowRefCall(\n call: SyntaxNode,\n workflowName: string,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.workflowRefCount++;\n\n const refNode: StaticWorkflowRefNode = {\n id: generateId(),\n type: \"workflow-ref\",\n workflowName,\n resolved: false,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [refNode];\n}\n\nfunction extractCalleeFromFunctionBody(\n body: SyntaxNode,\n ctx: AnalyzerContext\n): string {\n if (body.type === \"call_expression\") {\n const funcNode = body.childForFieldName(\"function\");\n if (funcNode) {\n return getText(funcNode, ctx);\n }\n }\n\n if (body.type === \"statement_block\") {\n for (const child of body.namedChildren) {\n if (child.type === \"return_statement\") {\n const returnExpr = child.namedChildren[0];\n if (returnExpr?.type === \"call_expression\") {\n const funcNode = returnExpr.childForFieldName(\"function\");\n if (funcNode) {\n return getText(funcNode, ctx);\n }\n } else if (returnExpr) {\n return getText(returnExpr, ctx);\n }\n }\n }\n }\n\n return getText(body, ctx);\n}\n\nfunction analyzeStepCall(call: SyntaxNode, ctx: AnalyzerContext): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n const secondArg = args?.namedChildren[1];\n\n let callee = \"<unknown>\";\n if (firstArg) {\n if (\n firstArg.type === \"arrow_function\" ||\n firstArg.type === \"function_expression\"\n ) {\n const body = firstArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(firstArg, ctx);\n }\n }\n\n const options = secondArg ? extractStepOptions(secondArg, ctx) : {};\n\n const stepNode: StaticStepNode = {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry: options.retry,\n timeout: options.timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return stepNode;\n}\n\nfunction analyzeStepRetryCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const funcArg = argList[0];\n let callee = \"<unknown>\";\n if (funcArg) {\n if (\n funcArg.type === \"arrow_function\" ||\n funcArg.type === \"function_expression\"\n ) {\n const body = funcArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(funcArg, ctx);\n }\n }\n\n const optionsArg = argList[1];\n const options = optionsArg ? extractStepOptions(optionsArg, ctx) : {};\n\n const retry = optionsArg ? extractRetryConfig(optionsArg, ctx) : undefined;\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry,\n timeout: options.timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\nfunction analyzeStepTimeoutCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode {\n ctx.stats.totalSteps++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const funcArg = argList[0];\n let callee = \"<unknown>\";\n if (funcArg) {\n if (\n funcArg.type === \"arrow_function\" ||\n funcArg.type === \"function_expression\"\n ) {\n const body = funcArg.childForFieldName(\"body\");\n if (body) {\n callee = extractCalleeFromFunctionBody(body, ctx);\n }\n } else {\n callee = getText(funcArg, ctx);\n }\n }\n\n const optionsArg = argList[1];\n const options = optionsArg ? extractStepOptions(optionsArg, ctx) : {};\n\n const timeout = optionsArg ? extractTimeoutConfig(optionsArg, ctx) : undefined;\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n key: options.key,\n name: options.name,\n retry: options.retry,\n timeout,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n}\n\ninterface StepOptions {\n key?: string;\n name?: string;\n retry?: StaticRetryConfig;\n timeout?: StaticTimeoutConfig;\n}\n\nfunction extractStepOptions(\n optionsNode: SyntaxNode,\n ctx: AnalyzerContext\n): StepOptions {\n const result: StepOptions = {};\n\n if (optionsNode.type !== \"object\") {\n return result;\n }\n\n for (const prop of optionsNode.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"key\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.key = value;\n } else if (key === \"name\") {\n const value = extractStringValue(valueNode, ctx);\n if (value) result.name = value;\n } else if (key === \"retry\") {\n result.retry = extractRetryConfig(valueNode, ctx);\n } else if (key === \"timeout\") {\n result.timeout = extractTimeoutConfig(valueNode, ctx);\n }\n }\n }\n }\n\n return result;\n}\n\nfunction extractRetryConfig(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticRetryConfig {\n const config: StaticRetryConfig = {};\n\n if (node.type !== \"object\") {\n return config;\n }\n\n for (const prop of node.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"attempts\") {\n const value = extractNumberValue(valueNode, ctx);\n config.attempts = value;\n } else if (key === \"backoff\") {\n const value = extractStringValue(valueNode, ctx);\n if (value === \"fixed\" || value === \"linear\" || value === \"exponential\") {\n config.backoff = value;\n } else {\n config.backoff = \"<dynamic>\";\n }\n } else if (key === \"baseDelay\") {\n const value = extractNumberValue(valueNode, ctx);\n config.baseDelay = value;\n } else if (key === \"retryOn\") {\n config.retryOn = getText(valueNode, ctx);\n }\n }\n }\n }\n\n return config;\n}\n\nfunction extractTimeoutConfig(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticTimeoutConfig {\n const config: StaticTimeoutConfig = {};\n\n if (node.type !== \"object\") {\n return config;\n }\n\n for (const prop of node.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const key = getText(keyNode, ctx);\n\n if (key === \"ms\") {\n const value = extractNumberValue(valueNode, ctx);\n config.ms = value;\n }\n }\n }\n }\n\n return config;\n}\n\nfunction extractNumberValue(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): number | \"<dynamic>\" {\n const text = getText(node, ctx);\n\n if (node.type === \"number\") {\n const num = parseFloat(text);\n return isNaN(num) ? \"<dynamic>\" : num;\n }\n\n return \"<dynamic>\";\n}\n\nfunction analyzeParallelCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg) {\n return [];\n }\n\n if (\n firstArg.type === \"string\" ||\n firstArg.type === \"identifier\" ||\n firstArg.type === \"member_expression\"\n ) {\n const parallelName =\n firstArg.type === \"string\"\n ? extractStringValue(firstArg, ctx)\n : getText(firstArg, ctx);\n\n const secondArg = args?.namedChildren[1];\n if (\n secondArg &&\n (secondArg.type === \"arrow_function\" ||\n secondArg.type === \"function_expression\")\n ) {\n const analyzed = analyzeCallbackBody(secondArg, ctx);\n if (analyzed.length > 0) {\n for (const node of analyzed) {\n if (node.type === \"parallel\" && parallelName) {\n (node as StaticParallelNode).name = parallelName;\n }\n }\n return analyzed;\n }\n }\n return [];\n }\n\n if (firstArg.type !== \"object\") {\n return [];\n }\n\n ctx.stats.parallelCount++;\n\n const children: StaticFlowNode[] = [];\n\n for (const prop of firstArg.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const stepNode = analyzeParallelItem(keyNode, valueNode, ctx);\n if (stepNode) {\n children.push(stepNode);\n }\n }\n }\n }\n\n const secondArg = args?.namedChildren[1];\n const options = secondArg ? extractStepOptions(secondArg, ctx) : {};\n\n return [\n {\n id: generateId(),\n type: \"parallel\",\n mode: \"all\",\n name: options.name,\n children,\n callee: \"step.parallel\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeParallelItem(\n keyNode: SyntaxNode,\n valueNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode | null {\n ctx.stats.totalSteps++;\n\n const name = getText(keyNode, ctx);\n\n let callee = \"<unknown>\";\n if (\n valueNode.type === \"arrow_function\" ||\n valueNode.type === \"function_expression\"\n ) {\n const body = valueNode.childForFieldName(\"body\");\n if (body?.type === \"call_expression\") {\n const funcNode = body.childForFieldName(\"function\");\n if (funcNode) {\n callee = getText(funcNode, ctx);\n }\n }\n }\n\n return {\n id: generateId(),\n type: \"step\",\n callee,\n name,\n location: ctx.opts.includeLocations ? getLocation(valueNode, ctx) : undefined,\n };\n}\n\nfunction analyzeRaceCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.raceCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"object\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const prop of firstArg.namedChildren) {\n if (prop.type === \"pair\") {\n const keyNode = prop.childForFieldName(\"key\");\n const valueNode = prop.childForFieldName(\"value\");\n\n if (keyNode && valueNode) {\n const stepNode = analyzeParallelItem(keyNode, valueNode, ctx);\n if (stepNode) {\n children.push(stepNode);\n }\n }\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"race\",\n children,\n callee: \"step.race\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeIfStatement(\n ifStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.conditionalCount++;\n\n const conditionNode = ifStmt.childForFieldName(\"condition\");\n const consequentNode = ifStmt.childForFieldName(\"consequence\");\n const alternateNode = ifStmt.childForFieldName(\"alternative\");\n\n const condition = conditionNode\n ? getText(conditionNode, ctx).replace(/^\\(|\\)$/g, \"\")\n : \"<unknown>\";\n\n const consequent = consequentNode ? analyzeBlock(consequentNode, ctx) : [];\n\n let alternate: StaticFlowNode[] | undefined;\n if (alternateNode) {\n if (alternateNode.type === \"else_clause\") {\n const elseContent = alternateNode.namedChildren[0];\n if (elseContent) {\n alternate = analyzeBlock(elseContent, ctx);\n }\n } else {\n alternate = analyzeBlock(alternateNode, ctx);\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"conditional\",\n condition,\n helper: null,\n consequent,\n alternate: alternate?.length ? alternate : undefined,\n location: ctx.opts.includeLocations ? getLocation(ifStmt, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeBlock(node: SyntaxNode, ctx: AnalyzerContext): StaticFlowNode[] {\n if (node.type === \"statement_block\") {\n return analyzeStatements(node.namedChildren, ctx);\n }\n return analyzeStatement(node, ctx);\n}\n\nfunction analyzeSwitchStatement(\n switchStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const valueNode = switchStmt.childForFieldName(\"value\");\n const bodyNode = switchStmt.childForFieldName(\"body\");\n\n const expression = valueNode\n ? getText(valueNode, ctx).replace(/^\\(|\\)$/g, \"\")\n : \"<unknown>\";\n\n const cases: StaticSwitchCase[] = [];\n let hasStepCalls = false;\n\n if (bodyNode) {\n for (const caseNode of bodyNode.namedChildren) {\n if (caseNode.type === \"switch_case\" || caseNode.type === \"switch_default\") {\n const caseValueNode = caseNode.childForFieldName(\"value\");\n const isDefault = caseNode.type === \"switch_default\" || !caseValueNode;\n const caseValue = caseValueNode ? getText(caseValueNode, ctx) : undefined;\n\n // Analyze statements in the case body (all named children except the value)\n const bodyStatements = caseNode.namedChildren.filter(\n (n) => n !== caseValueNode\n );\n const body = analyzeStatements(bodyStatements, ctx);\n\n if (body.length > 0) {\n hasStepCalls = true;\n }\n\n cases.push({\n value: caseValue,\n isDefault,\n body,\n });\n }\n }\n }\n\n // Only count if there are step calls inside\n if (hasStepCalls) {\n ctx.stats.conditionalCount++;\n }\n\n // If no step calls, return empty\n if (!hasStepCalls) {\n return [];\n }\n\n const switchNode: StaticSwitchNode = {\n id: generateId(),\n type: \"switch\",\n expression,\n cases,\n location: ctx.opts.includeLocations ? getLocation(switchStmt, ctx) : undefined,\n };\n\n return [switchNode];\n}\n\nfunction analyzeConditionalHelper(\n call: SyntaxNode,\n helper: \"when\" | \"unless\" | \"whenOr\" | \"unlessOr\",\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.conditionalCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const argList = args?.namedChildren || [];\n\n const conditionNode = argList[0];\n const condition = conditionNode ? getText(conditionNode, ctx) : \"<unknown>\";\n\n const callbackNode = argList[1];\n const consequent = callbackNode ? analyzeCallbackBody(callbackNode, ctx) : [];\n\n let defaultValue: string | undefined;\n if ((helper === \"whenOr\" || helper === \"unlessOr\") && argList[2]) {\n defaultValue = getText(argList[2], ctx);\n }\n\n const conditionalNode: StaticConditionalNode = {\n id: generateId(),\n type: \"conditional\",\n condition,\n helper,\n consequent,\n defaultValue,\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [conditionalNode];\n}\n\nfunction analyzeCallbackBody(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n if (node.type === \"arrow_function\" || node.type === \"function_expression\") {\n const body = node.childForFieldName(\"body\");\n if (body) {\n if (body.type === \"statement_block\") {\n return analyzeStatements(body.namedChildren, ctx);\n }\n return analyzeExpression(body, ctx);\n }\n }\n return analyzeExpression(node, ctx);\n}\n\nfunction analyzeAllAsyncCall(\n call: SyntaxNode,\n mode: \"all\" | \"allSettled\",\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.parallelCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"array\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const element of firstArg.namedChildren) {\n if (element.type === \"call_expression\") {\n const analyzed = analyzeCallExpression(element, ctx);\n if (analyzed.length > 0) {\n children.push(...wrapInSequence(analyzed));\n } else {\n const implicitStep = createImplicitStepFromCall(element, ctx);\n if (implicitStep) {\n children.push(implicitStep);\n }\n }\n } else {\n const analyzed = analyzeCallbackBody(element, ctx);\n children.push(...wrapInSequence(analyzed));\n }\n }\n\n return [\n {\n id: generateId(),\n type: \"parallel\",\n mode,\n children,\n callee: mode === \"all\" ? \"allAsync\" : \"allSettledAsync\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n },\n ];\n}\n\nfunction analyzeAnyAsyncCall(\n call: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n ctx.stats.raceCount++;\n\n const args = call.childForFieldName(\"arguments\");\n const firstArg = args?.namedChildren[0];\n\n if (!firstArg || firstArg.type !== \"array\") {\n return [];\n }\n\n const children: StaticFlowNode[] = [];\n\n for (const element of firstArg.namedChildren) {\n if (element.type === \"call_expression\") {\n const analyzed = analyzeCallExpression(element, ctx);\n if (analyzed.length > 0) {\n children.push(...wrapInSequence(analyzed));\n } else {\n const implicitStep = createImplicitStepFromCall(element, ctx);\n if (implicitStep) {\n children.push(implicitStep);\n }\n }\n } else {\n const analyzed = analyzeCallbackBody(element, ctx);\n children.push(...wrapInSequence(analyzed));\n }\n }\n\n const raceNode: StaticRaceNode = {\n id: generateId(),\n type: \"race\",\n children,\n callee: \"anyAsync\",\n location: ctx.opts.includeLocations ? getLocation(call, ctx) : undefined,\n };\n\n return [raceNode];\n}\n\nfunction createImplicitStepFromCall(\n callNode: SyntaxNode,\n ctx: AnalyzerContext\n): StaticStepNode | null {\n ctx.stats.totalSteps++;\n\n const funcNode = callNode.childForFieldName(\"function\");\n const callee = funcNode ? getText(funcNode, ctx) : \"<unknown>\";\n\n const name = callee.includes(\".\") ? callee.split(\".\").pop() : callee;\n\n return {\n id: generateId(),\n type: \"step\",\n name,\n callee,\n location: ctx.opts.includeLocations ? getLocation(callNode, ctx) : undefined,\n };\n}\n\nfunction analyzeForStatement(\n forStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = forStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: \"for\",\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(forStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction analyzeForInStatement(\n forStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = forStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const stmtText = getText(forStmt, ctx);\n const isForOf = stmtText.includes(\" of \");\n\n const rightNode = forStmt.childForFieldName(\"right\");\n const iterSource = rightNode ? getText(rightNode, ctx) : undefined;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: isForOf ? \"for-of\" : \"for-in\",\n iterSource,\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(forStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction analyzeWhileStatement(\n whileStmt: SyntaxNode,\n ctx: AnalyzerContext\n): StaticFlowNode[] {\n const bodyNode = whileStmt.childForFieldName(\"body\");\n if (!bodyNode) return [];\n\n const bodyChildren = analyzeBlock(bodyNode, ctx);\n if (bodyChildren.length === 0) return [];\n\n ctx.stats.loopCount++;\n\n const loopNode: StaticLoopNode = {\n id: generateId(),\n type: \"loop\",\n loopType: \"while\",\n body: bodyChildren,\n boundKnown: false,\n location: ctx.opts.includeLocations ? getLocation(whileStmt, ctx) : undefined,\n };\n\n return [loopNode];\n}\n\nfunction getText(node: SyntaxNode, ctx: AnalyzerContext): string {\n return ctx.sourceCode.slice(node.startIndex, node.endIndex);\n}\n\nfunction extractStringValue(\n node: SyntaxNode,\n ctx: AnalyzerContext\n): string | undefined {\n const text = getText(node, ctx);\n\n if (node.type === \"string\") {\n return text.slice(1, -1);\n }\n\n if (node.type === \"template_string\") {\n return \"<dynamic>\";\n }\n\n return text;\n}\n\nfunction getLocation(node: SyntaxNode, ctx: AnalyzerContext): SourceLocation {\n return {\n filePath: ctx.filePath,\n line: node.startPosition.row + 1,\n column: node.startPosition.column,\n endLine: node.endPosition.row + 1,\n endColumn: node.endPosition.column,\n };\n}\n\nfunction traverseNode(\n node: SyntaxNode,\n callback: (node: SyntaxNode) => void\n): void {\n callback(node);\n for (const child of node.namedChildren) {\n traverseNode(child, callback);\n }\n}\n\nfunction wrapInSequence(nodes: StaticFlowNode[]): StaticFlowNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n return [\n {\n id: generateId(),\n type: \"sequence\",\n children: nodes,\n } as StaticSequenceNode,\n ];\n}\n\nfunction createEmptyStats(): AnalysisStats {\n return {\n totalSteps: 0,\n conditionalCount: 0,\n parallelCount: 0,\n raceCount: 0,\n loopCount: 0,\n streamCount: 0,\n workflowRefCount: 0,\n unknownCount: 0,\n sagaWorkflowCount: 0,\n };\n}\n","/**\n * Tree-sitter WASM Loader (Browser)\n *\n * Browser-compatible loader that uses fetch() to load WASM files.\n * web-tree-sitter v0.26+ bundles its own core WASM runtime and uses named exports.\n */\n\n// Re-export types from the Node.js loader\nexport type {\n SyntaxTree,\n SyntaxNode,\n Language,\n TreeSitterParser,\n} from \"./tree-sitter-loader\";\n\n// Import types from web-tree-sitter (these are the actual runtime types)\nimport type {\n Parser as WebTreeSitterParser,\n Language as WebTreeSitterLanguage,\n} from \"web-tree-sitter\";\n\n// Configurable WASM base path (default: /wasm/)\nlet wasmBasePath = \"/wasm/\";\n\n/**\n * Set the base path for loading WASM files.\n * Call this before loadTreeSitterBrowser() if WASM files are served from a different location.\n *\n * @example\n * ```ts\n * setWasmBasePath('/awaitly/wasm/');\n * ```\n */\nexport function setWasmBasePath(path: string): void {\n // Ensure path ends with /\n wasmBasePath = path.endsWith(\"/\") ? path : `${path}/`;\n}\n\n/**\n * Get the current WASM base path.\n */\nexport function getWasmBasePath(): string {\n return wasmBasePath;\n}\n\n// Singleton cache for parser and language\nlet cached: { parser: WebTreeSitterParser; language: WebTreeSitterLanguage } | null = null;\n\n/**\n * Load TypeScript grammar WASM from configured path using fetch.\n */\nasync function loadTypescriptGrammar(): Promise<Uint8Array> {\n const wasmUrl = `${wasmBasePath}tree-sitter-typescript.wasm`;\n\n const response = await fetch(wasmUrl);\n\n if (!response.ok) {\n throw new Error(\n `Failed to load TypeScript grammar WASM from: ${wasmUrl}\\n` +\n `HTTP ${response.status}: ${response.statusText}\\n\\n` +\n \"Make sure the WASM file is available at this path. \" +\n \"You can configure the path using setWasmBasePath().\"\n );\n }\n\n const buffer = await response.arrayBuffer();\n return new Uint8Array(buffer);\n}\n\n/**\n * Load and initialize tree-sitter with the TypeScript grammar.\n *\n * Uses fetch to load WASM files from the configured base path.\n * Subsequent calls return the cached parser instance.\n *\n * @returns Parser instance with TypeScript language loaded\n */\nexport async function loadTreeSitterBrowser(): Promise<{\n parser: WebTreeSitterParser;\n language: WebTreeSitterLanguage;\n}> {\n if (cached) return cached;\n\n // Dynamic import web-tree-sitter (v0.26+ uses named exports)\n const { Parser, Language } = await import(\"web-tree-sitter\");\n\n // Initialize the Parser with locateFile to find web-tree-sitter.wasm\n // The WASM file should be placed alongside tree-sitter-typescript.wasm\n await Parser.init({\n locateFile: (scriptName: string) => {\n // web-tree-sitter looks for web-tree-sitter.wasm\n return `${wasmBasePath}${scriptName}`;\n },\n });\n\n // Load TypeScript grammar from configured WASM path\n const typescriptWasm = await loadTypescriptGrammar();\n const language = await Language.load(typescriptWasm);\n\n // Create and configure parser\n const parser = new Parser();\n parser.setLanguage(language);\n\n cached = { parser, language };\n return cached;\n}\n\n/**\n * Clear the cached parser instance.\n * Useful for testing or forcing re-initialization.\n */\nexport function clearTreeSitterBrowserCache(): void {\n cached = null;\n}\n","/**\n * Mermaid Diagram Generator\n *\n * Generates Mermaid flowchart diagrams from static workflow analysis.\n * Shows all possible paths, not just executed ones.\n */\n\nimport type {\n StaticWorkflowIR,\n StaticFlowNode,\n StaticStepNode,\n StaticSequenceNode,\n StaticParallelNode,\n StaticRaceNode,\n StaticConditionalNode,\n StaticSwitchNode,\n StaticLoopNode,\n StaticWorkflowRefNode,\n StaticSagaStepNode,\n} from \"../types\";\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface MermaidOptions {\n /** Diagram direction: TB (top-bottom), LR (left-right), etc. */\n direction?: \"TB\" | \"LR\" | \"BT\" | \"RL\";\n /** Show step keys in labels */\n showKeys?: boolean;\n /** Show step descriptions in labels (default: false) */\n showStepDescriptions?: boolean;\n /** Include step markdown as Mermaid comments (default: false) */\n includeStepMarkdown?: boolean;\n /** Show condition labels on edges */\n showConditions?: boolean;\n /** Use subgraphs for parallel/race blocks */\n useSubgraphs?: boolean;\n /** Custom node styles */\n styles?: MermaidStyles;\n /** Max markdown lines to include as comments (default: 10) */\n maxMarkdownLines?: number;\n /** Include markdown in output (default: true) */\n includeMarkdown?: boolean;\n}\n\nexport interface MermaidStyles {\n step?: string;\n parallel?: string;\n race?: string;\n conditional?: string;\n loop?: string;\n workflowRef?: string;\n sagaStep?: string;\n sagaCompensation?: string;\n start?: string;\n end?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<MermaidOptions> = {\n direction: \"TB\",\n showKeys: false,\n showStepDescriptions: false,\n includeStepMarkdown: false,\n showConditions: true,\n useSubgraphs: true,\n styles: {\n step: \"fill:#e1f5fe,stroke:#01579b,color:#01579b\",\n parallel: \"fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20\",\n race: \"fill:#fff3e0,stroke:#e65100,color:#bf360c\",\n conditional: \"fill:#fce4ec,stroke:#880e4f,color:#880e4f\",\n loop: \"fill:#f3e5f5,stroke:#4a148c,color:#4a148c\",\n workflowRef: \"fill:#e0f2f1,stroke:#004d40,color:#004d40\",\n sagaStep: \"fill:#fff8e1,stroke:#ff6f00,color:#e65100\",\n sagaCompensation: \"fill:#ffebee,stroke:#c62828,color:#b71c1c\",\n start: \"fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20\",\n end: \"fill:#ffcdd2,stroke:#c62828,color:#b71c1c\",\n },\n maxMarkdownLines: 10,\n includeMarkdown: true,\n};\n\n// =============================================================================\n// Main Generator\n// =============================================================================\n\n/**\n * Generate a Mermaid flowchart from static workflow IR.\n */\nexport function renderStaticMermaid(\n ir: StaticWorkflowIR,\n options: MermaidOptions = {}\n): string {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const context: RenderContext = {\n opts,\n nodeCounter: 0,\n edges: [],\n subgraphs: [],\n styleClasses: new Map(),\n };\n\n const lines: string[] = [];\n\n // Flowchart header\n lines.push(`flowchart ${opts.direction}`);\n lines.push(\"\");\n\n // Add workflow title as comment\n lines.push(` %% Workflow: ${ir.root.workflowName}`);\n\n // Description (short) - always show if present\n if (ir.root.description) {\n lines.push(` %% ${ir.root.description}`);\n }\n\n // Markdown (full docs) - first N lines as comments\n if (opts.includeMarkdown && ir.root.markdown) {\n lines.push(` %%`);\n const markdownLines = ir.root.markdown.trim().split(\"\\n\");\n const maxLines = opts.maxMarkdownLines;\n const displayLines = markdownLines.slice(0, maxLines);\n for (const line of displayLines) {\n lines.push(` %% ${line}`);\n }\n if (markdownLines.length > maxLines) {\n lines.push(` %% ... (${markdownLines.length - maxLines} more lines)`);\n }\n }\n\n lines.push(\"\");\n\n // Add start node\n const startId = \"start\";\n lines.push(` ${startId}((Start))`);\n\n // Process workflow body\n const { firstNodeId, lastNodeIds } = renderNodes(\n ir.root.children,\n context,\n lines\n );\n\n // Connect start to first node\n if (firstNodeId) {\n context.edges.push({ from: startId, to: firstNodeId });\n }\n\n // Add end node and connect last nodes to it\n const endId = \"end_node\";\n lines.push(` ${endId}((End))`);\n\n for (const lastId of lastNodeIds) {\n context.edges.push({ from: lastId, to: endId });\n }\n\n // Add subgraphs\n for (const subgraph of context.subgraphs) {\n lines.push(\"\");\n lines.push(` subgraph ${subgraph.id}[${subgraph.label}]`);\n for (const line of subgraph.content) {\n lines.push(` ${line}`);\n }\n lines.push(\" end\");\n }\n\n // Add edges\n lines.push(\"\");\n lines.push(\" %% Edges\");\n for (const edge of context.edges) {\n if (edge.label && opts.showConditions) {\n lines.push(` ${edge.from} -->|${escapeLabel(edge.label)}| ${edge.to}`);\n } else {\n lines.push(` ${edge.from} --> ${edge.to}`);\n }\n }\n\n // Add styles\n lines.push(\"\");\n lines.push(\" %% Styles\");\n lines.push(` classDef stepStyle ${opts.styles.step}`);\n lines.push(` classDef parallelStyle ${opts.styles.parallel}`);\n lines.push(` classDef raceStyle ${opts.styles.race}`);\n lines.push(` classDef conditionalStyle ${opts.styles.conditional}`);\n lines.push(` classDef loopStyle ${opts.styles.loop}`);\n lines.push(` classDef workflowRefStyle ${opts.styles.workflowRef}`);\n lines.push(` classDef sagaStepStyle ${opts.styles.sagaStep}`);\n lines.push(` classDef sagaCompensationStyle ${opts.styles.sagaCompensation}`);\n lines.push(` classDef startStyle ${opts.styles.start}`);\n lines.push(` classDef endStyle ${opts.styles.end}`);\n\n // Apply styles\n lines.push(` class ${startId} startStyle`);\n lines.push(` class ${endId} endStyle`);\n\n for (const [nodeId, styleClass] of context.styleClasses) {\n lines.push(` class ${nodeId} ${styleClass}`);\n }\n\n return lines.join(\"\\n\");\n}\n\n// =============================================================================\n// Internal Types\n// =============================================================================\n\ninterface RenderContext {\n opts: Required<MermaidOptions>;\n nodeCounter: number;\n edges: Edge[];\n subgraphs: Subgraph[];\n styleClasses: Map<string, string>;\n}\n\ninterface Edge {\n from: string;\n to: string;\n label?: string;\n}\n\ninterface Subgraph {\n id: string;\n label: string;\n content: string[];\n}\n\ninterface RenderResult {\n firstNodeId: string | null;\n lastNodeIds: string[];\n}\n\n// =============================================================================\n// Node Rendering\n// =============================================================================\n\nfunction renderNodes(\n nodes: StaticFlowNode[],\n context: RenderContext,\n lines: string[]\n): RenderResult {\n if (nodes.length === 0) {\n return { firstNodeId: null, lastNodeIds: [] };\n }\n\n let firstNodeId: string | null = null;\n let prevLastNodeIds: string[] = [];\n\n for (const node of nodes) {\n const result = renderNode(node, context, lines);\n\n // Track first node\n if (firstNodeId === null && result.firstNodeId) {\n firstNodeId = result.firstNodeId;\n }\n\n // Connect previous nodes to current first node\n if (result.firstNodeId) {\n for (const prevId of prevLastNodeIds) {\n context.edges.push({ from: prevId, to: result.firstNodeId });\n }\n }\n\n prevLastNodeIds = result.lastNodeIds;\n }\n\n return {\n firstNodeId,\n lastNodeIds: prevLastNodeIds,\n };\n}\n\nfunction renderNode(\n node: StaticFlowNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n switch (node.type) {\n case \"step\":\n return renderStepNode(node, context, lines);\n\n case \"sequence\":\n return renderSequenceNode(node, context, lines);\n\n case \"parallel\":\n return renderParallelNode(node, context, lines);\n\n case \"race\":\n return renderRaceNode(node, context, lines);\n\n case \"conditional\":\n return renderConditionalNode(node, context, lines);\n\n case \"switch\":\n return renderSwitchNode(node as StaticSwitchNode, context, lines);\n\n case \"loop\":\n return renderLoopNode(node, context, lines);\n\n case \"workflow-ref\":\n return renderWorkflowRefNode(node, context, lines);\n\n case \"saga-step\":\n return renderSagaStepNode(node as StaticSagaStepNode, context, lines);\n\n case \"unknown\":\n return renderUnknownNode(node, context, lines);\n\n default:\n return { firstNodeId: null, lastNodeIds: [] };\n }\n}\n\nfunction renderStepNode(\n node: StaticStepNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `step_${++context.nodeCounter}`;\n let label = node.name ?? node.callee ?? \"step\";\n\n if (context.opts.showKeys && node.key) {\n label = `${label}\\\\n[${node.key}]`;\n }\n\n // Add description to label when showStepDescriptions is enabled\n if (context.opts.showStepDescriptions && node.description) {\n label = `${label}\\\\n${truncate(node.description, 40)}`;\n }\n\n // Add retry/timeout indicators\n if (node.retry) {\n label += \"\\\\n(retry)\";\n }\n if (node.timeout) {\n label += \"\\\\n(timeout)\";\n }\n\n // Add markdown as Mermaid comments when includeStepMarkdown is enabled\n if (context.opts.includeStepMarkdown && node.markdown) {\n const markdownLines = node.markdown.trim().split(\"\\n\");\n const maxLines = context.opts.maxMarkdownLines;\n const displayLines = markdownLines.slice(0, maxLines);\n lines.push(` %% Step: ${node.name ?? node.callee ?? \"step\"}`);\n for (const line of displayLines) {\n lines.push(` %% ${line}`);\n }\n if (markdownLines.length > maxLines) {\n lines.push(` %% ... (${markdownLines.length - maxLines} more lines)`);\n }\n }\n\n lines.push(` ${nodeId}[${escapeLabel(label)}]`);\n context.styleClasses.set(nodeId, \"stepStyle\");\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\nfunction renderSequenceNode(\n node: StaticSequenceNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n return renderNodes(node.children, context, lines);\n}\n\nfunction renderParallelNode(\n node: StaticParallelNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const forkId = `parallel_fork_${++context.nodeCounter}`;\n const joinId = `parallel_join_${++context.nodeCounter}`;\n\n // Fork node (diamond shape for parallel)\n const parallelLabel = node.name ? `${node.name} (${node.mode})` : `Parallel (${node.mode})`;\n lines.push(` ${forkId}{{\"${parallelLabel}\"}}`);\n context.styleClasses.set(forkId, \"parallelStyle\");\n\n // Join node\n lines.push(` ${joinId}{{\"Join\"}}`);\n context.styleClasses.set(joinId, \"parallelStyle\");\n\n // Render each branch\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const branchResult = renderNode(child, context, lines);\n\n // Connect fork to branch start\n if (branchResult.firstNodeId) {\n context.edges.push({\n from: forkId,\n to: branchResult.firstNodeId,\n label: `branch ${i + 1}`,\n });\n }\n\n // Connect branch end to join\n for (const lastId of branchResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: joinId });\n }\n }\n\n return {\n firstNodeId: forkId,\n lastNodeIds: [joinId],\n };\n}\n\nfunction renderRaceNode(\n node: StaticRaceNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const forkId = `race_fork_${++context.nodeCounter}`;\n const joinId = `race_join_${++context.nodeCounter}`;\n\n // Fork node (hexagon for race)\n const raceLabel = node.name ? node.name : \"Race\";\n lines.push(` ${forkId}{{{\"${raceLabel}\"}}}`);\n context.styleClasses.set(forkId, \"raceStyle\");\n\n // Join node\n lines.push(` ${joinId}{{{\"Winner\"}}}`);\n context.styleClasses.set(joinId, \"raceStyle\");\n\n // Render each competing branch\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const branchResult = renderNode(child, context, lines);\n\n // Connect fork to branch start\n if (branchResult.firstNodeId) {\n context.edges.push({\n from: forkId,\n to: branchResult.firstNodeId,\n label: `racer ${i + 1}`,\n });\n }\n\n // Connect branch end to join (dashed - only winner proceeds)\n for (const lastId of branchResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: joinId });\n }\n }\n\n return {\n firstNodeId: forkId,\n lastNodeIds: [joinId],\n };\n}\n\nfunction renderConditionalNode(\n node: StaticConditionalNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const decisionId = `decision_${++context.nodeCounter}`;\n\n // Decision diamond\n const conditionLabel = truncate(node.condition, 30);\n lines.push(` ${decisionId}{${escapeLabel(conditionLabel)}}`);\n context.styleClasses.set(decisionId, \"conditionalStyle\");\n\n const lastNodeIds: string[] = [];\n\n // True/consequent branch\n const trueResult = renderNodes(node.consequent, context, lines);\n if (trueResult.firstNodeId) {\n const trueLabel =\n node.helper === \"unless\" || node.helper === \"unlessOr\" ? \"false\" : \"true\";\n context.edges.push({\n from: decisionId,\n to: trueResult.firstNodeId,\n label: trueLabel,\n });\n lastNodeIds.push(...trueResult.lastNodeIds);\n }\n\n // False/alternate branch\n if (node.alternate && node.alternate.length > 0) {\n const falseResult = renderNodes(node.alternate, context, lines);\n if (falseResult.firstNodeId) {\n const falseLabel =\n node.helper === \"unless\" || node.helper === \"unlessOr\"\n ? \"true\"\n : \"false\";\n context.edges.push({\n from: decisionId,\n to: falseResult.firstNodeId,\n label: falseLabel,\n });\n lastNodeIds.push(...falseResult.lastNodeIds);\n }\n } else {\n // No alternate - decision can skip directly\n lastNodeIds.push(decisionId);\n }\n\n return {\n firstNodeId: decisionId,\n lastNodeIds,\n };\n}\n\nfunction renderSwitchNode(\n node: StaticSwitchNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const decisionId = `switch_${++context.nodeCounter}`;\n\n // Diamond shape for switch expression\n const expressionLabel = truncate(node.expression, 30);\n lines.push(` ${decisionId}{${escapeLabel(expressionLabel)}}`);\n context.styleClasses.set(decisionId, \"conditionalStyle\");\n\n const lastNodeIds: string[] = [];\n\n for (const switchCase of node.cases) {\n const caseLabel = switchCase.isDefault ? \"default\" : (switchCase.value || \"?\");\n\n if (switchCase.body.length > 0) {\n const branchResult = renderNodes(switchCase.body, context, lines);\n if (branchResult.firstNodeId) {\n context.edges.push({\n from: decisionId,\n to: branchResult.firstNodeId,\n label: truncate(caseLabel, 20),\n });\n lastNodeIds.push(...branchResult.lastNodeIds);\n }\n } else {\n // Empty case - falls through or skip\n lastNodeIds.push(decisionId);\n }\n }\n\n // If no cases matched anything, decision is exit\n if (lastNodeIds.length === 0) {\n lastNodeIds.push(decisionId);\n }\n\n return {\n firstNodeId: decisionId,\n lastNodeIds,\n };\n}\n\nfunction renderLoopNode(\n node: StaticLoopNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const loopStartId = `loop_start_${++context.nodeCounter}`;\n const loopEndId = `loop_end_${++context.nodeCounter}`;\n\n // Loop start (stadium shape)\n const loopLabel = node.iterSource\n ? `${node.loopType}: ${truncate(node.iterSource, 20)}`\n : node.loopType;\n lines.push(` ${loopStartId}([${escapeLabel(loopLabel)}])`);\n context.styleClasses.set(loopStartId, \"loopStyle\");\n\n // Loop body\n const bodyResult = renderNodes(node.body, context, lines);\n\n // Connect loop start to body\n if (bodyResult.firstNodeId) {\n context.edges.push({\n from: loopStartId,\n to: bodyResult.firstNodeId,\n label: \"iterate\",\n });\n }\n\n // Loop end check\n lines.push(` ${loopEndId}([Continue?])`);\n context.styleClasses.set(loopEndId, \"loopStyle\");\n\n // Connect body end to loop check\n for (const lastId of bodyResult.lastNodeIds) {\n context.edges.push({ from: lastId, to: loopEndId });\n }\n\n // Loop back\n context.edges.push({\n from: loopEndId,\n to: loopStartId,\n label: \"next\",\n });\n\n return {\n firstNodeId: loopStartId,\n lastNodeIds: [loopEndId],\n };\n}\n\nfunction renderWorkflowRefNode(\n node: StaticWorkflowRefNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `workflow_ref_${++context.nodeCounter}`;\n\n // Subroutine shape for workflow reference\n const label = `[[${node.workflowName}]]`;\n lines.push(` ${nodeId}${label}`);\n context.styleClasses.set(nodeId, \"workflowRefStyle\");\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\nfunction renderSagaStepNode(\n node: StaticSagaStepNode,\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `saga_step_${++context.nodeCounter}`;\n let label = node.name ?? node.callee ?? \"saga step\";\n\n if (context.opts.showKeys && node.key) {\n label = `${label}\\\\n[${node.key}]`;\n }\n\n // Add description to label when showStepDescriptions is enabled\n if (context.opts.showStepDescriptions && node.description) {\n label = `${label}\\\\n${truncate(node.description, 40)}`;\n }\n\n // Add compensation indicator\n if (node.hasCompensation) {\n const compensationLabel = node.compensationCallee\n ? `🔄 ${node.compensationCallee}`\n : \"🔄 compensated\";\n label = `${label}\\\\n${compensationLabel}`;\n }\n\n // Add tryStep indicator\n if (node.isTryStep) {\n label = `${label}\\\\n(try)`;\n }\n\n // Add markdown as Mermaid comments when includeStepMarkdown is enabled\n if (context.opts.includeStepMarkdown && node.markdown) {\n const markdownLines = node.markdown.trim().split(\"\\n\");\n const maxLines = context.opts.maxMarkdownLines;\n const displayLines = markdownLines.slice(0, maxLines);\n lines.push(` %% Saga Step: ${node.name ?? node.callee ?? \"saga step\"}`);\n for (const line of displayLines) {\n lines.push(` %% ${line}`);\n }\n if (markdownLines.length > maxLines) {\n lines.push(` %% ... (${markdownLines.length - maxLines} more lines)`);\n }\n }\n\n lines.push(` ${nodeId}[${escapeLabel(label)}]`);\n\n // Use compensation style if step has compensation, otherwise saga step style\n const styleClass = node.hasCompensation ? \"sagaCompensationStyle\" : \"sagaStepStyle\";\n context.styleClasses.set(nodeId, styleClass);\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\nfunction renderUnknownNode(\n node: StaticFlowNode & { type: \"unknown\" },\n context: RenderContext,\n lines: string[]\n): RenderResult {\n const nodeId = `unknown_${++context.nodeCounter}`;\n\n lines.push(` ${nodeId}[/\"Unknown: ${escapeLabel(node.reason)}\"/]`);\n\n return {\n firstNodeId: nodeId,\n lastNodeIds: [nodeId],\n };\n}\n\n// =============================================================================\n// Utilities\n// =============================================================================\n\nfunction escapeLabel(label: string): string {\n return label\n .replace(/\"/g, \"'\")\n .replace(/\\[/g, \"(\")\n .replace(/\\]/g, \")\")\n .replace(/\\{/g, \"(\")\n .replace(/\\}/g, \")\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n\nfunction truncate(str: string, maxLength: number): string {\n if (str.length <= maxLength) return str;\n return str.slice(0, maxLength - 3) + \"...\";\n}\n\n// =============================================================================\n// Simplified Mermaid (Path-based)\n// =============================================================================\n\n/**\n * Generate a simplified Mermaid diagram showing just the paths.\n */\nexport function renderPathsMermaid(\n paths: Array<{\n id: string;\n steps: Array<{ name?: string; nodeId: string }>;\n conditions: Array<{ expression: string; mustBe: boolean }>;\n }>,\n options: MermaidOptions = {}\n): string {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const lines: string[] = [];\n\n lines.push(`flowchart ${opts.direction}`);\n lines.push(\"\");\n\n // Create unique node IDs for each step across all paths\n // Key by nodeId (unique), store both the generated ID and display label\n const stepNodes = new Map<string, { id: string; label: string }>();\n let nodeCounter = 0;\n\n for (const path of paths) {\n for (const step of path.steps) {\n // Use nodeId as unique key to prevent merging distinct steps with same name\n if (!stepNodes.has(step.nodeId)) {\n stepNodes.set(step.nodeId, {\n id: `step_${++nodeCounter}`,\n label: step.name ?? step.nodeId,\n });\n }\n }\n }\n\n // Add start and end nodes\n lines.push(\" start((Start))\");\n lines.push(\" end_node((End))\");\n lines.push(\"\");\n\n // Add all step nodes\n for (const [, { id, label }] of stepNodes) {\n lines.push(` ${id}[${escapeLabel(label)}]`);\n }\n lines.push(\"\");\n\n // Add edges for each path\n const edges = new Set<string>();\n\n for (const path of paths) {\n if (path.steps.length === 0) continue;\n\n // Start to first step\n const firstStep = path.steps[0];\n const firstStepId = stepNodes.get(firstStep.nodeId)!.id;\n edges.add(`start --> ${firstStepId}`);\n\n // Between steps\n for (let i = 0; i < path.steps.length - 1; i++) {\n const current = path.steps[i];\n const next = path.steps[i + 1];\n const currentId = stepNodes.get(current.nodeId)!.id;\n const nextId = stepNodes.get(next.nodeId)!.id;\n edges.add(`${currentId} --> ${nextId}`);\n }\n\n // Last step to end\n const lastStep = path.steps[path.steps.length - 1];\n const lastStepId = stepNodes.get(lastStep.nodeId)!.id;\n edges.add(`${lastStepId} --> end_node`);\n }\n\n // Add edges\n lines.push(\" %% Edges\");\n for (const edge of edges) {\n lines.push(` ${edge}`);\n }\n\n return lines.join(\"\\n\");\n}\n","/**\n * JSON Renderer for Static Workflow Analysis\n *\n * Serializes StaticWorkflowIR to JSON format.\n */\n\nimport type { StaticWorkflowIR } from \"../types\";\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface JSONRenderOptions {\n /** Pretty print with indentation (default: true) */\n pretty?: boolean;\n /** Include analysis metadata (default: true) */\n includeMetadata?: boolean;\n}\n\n// =============================================================================\n// Main Renderer\n// =============================================================================\n\n/**\n * Render a single workflow IR to JSON.\n */\nexport function renderStaticJSON(\n ir: StaticWorkflowIR,\n options: JSONRenderOptions = {}\n): string {\n const { pretty = true, includeMetadata = true } = options;\n\n const serializable = {\n root: ir.root,\n metadata: includeMetadata ? ir.metadata : undefined,\n // Convert Map to object for JSON serialization\n references:\n ir.references.size > 0\n ? Object.fromEntries(\n Array.from(ir.references.entries()).map(([key, value]) => [\n key,\n {\n root: value.root,\n metadata: includeMetadata ? value.metadata : undefined,\n },\n ])\n )\n : undefined,\n };\n\n return pretty\n ? JSON.stringify(serializable, null, 2)\n : JSON.stringify(serializable);\n}\n\n/**\n * Render multiple workflow IRs to JSON.\n */\nexport function renderMultipleStaticJSON(\n workflows: StaticWorkflowIR[],\n filePath: string,\n options: JSONRenderOptions = {}\n): string {\n const { pretty = true, includeMetadata = true } = options;\n\n const serializable = {\n file: filePath,\n analyzedAt: Date.now(),\n workflowCount: workflows.length,\n workflows: workflows.map((ir) => ({\n root: ir.root,\n metadata: includeMetadata ? ir.metadata : undefined,\n references:\n ir.references.size > 0\n ? Object.fromEntries(\n Array.from(ir.references.entries()).map(([key, value]) => [\n key,\n {\n root: value.root,\n metadata: includeMetadata ? value.metadata : undefined,\n },\n ])\n )\n : undefined,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AhC,EACoB,CACpB,IAAMgM,EAAOrK,EAAQK,EAAMhC,CAAG,EAE9B,OAAIgC,EAAK,OAAS,SACTgK,EAAK,MAAM,EAAG,EAAE,EAGrBhK,EAAK,OAAS,kBACT,YAGFgK,CACT,CAEA,SAASrH,EAAY3C,EAAkBhC,EAAsC,CAC3E,MAAO,CACL,SAAUA,EAAI,SACd,KAAMgC,EAAK,cAAc,IAAM,EAC/B,OAAQA,EAAK,cAAc,OAC3B,QAASA,EAAK,YAAY,IAAM,EAChC,UAAWA,EAAK,YAAY,MAC9B,CACF,CAEA,SAASD,EACPC,EACAiL,EACM,CACNA,EAASjL,CAAI,EACb,QAAWa,KAASb,EAAK,cACvBD,EAAac,EAAOoK,CAAQ,CAEhC,CAEA,SAASzH,EAAegB,EAA2C,CACjE,OAAIA,EAAM,QAAU,EACXA,EAGF,CACL,CACE,GAAIhH,EAAW,EACf,KAAM,WACN,SAAUgH,CACZ,CACF,CACF,CAEA,SAASvG,GAAkC,CACzC,MAAO,CACL,WAAY,EACZ,iBAAkB,EAClB,cAAe,EACf,UAAW,EACX,UAAW,EACX,YAAa,EACb,iBAAkB,EAClB,aAAc,EACd,kBAAmB,CACrB,CACF","names":["browser_exports","__export","analyzeWorkflowSource","clearTreeSitterBrowserCache","getWasmBasePath","renderMultipleStaticJSON","renderPathsMermaid","renderStaticJSON","renderStaticMermaid","resetIdCounter","setWasmBasePath","__toCommonJS","wasmBasePath","setWasmBasePath","path","getWasmBasePath","cached","loadTypescriptGrammar","wasmUrl","response","buffer","loadTreeSitterBrowser","Parser","Language","scriptName","typescriptWasm","language","parser","clearTreeSitterBrowserCache","DEFAULT_OPTIONS","renderStaticMermaid","ir","options","opts","context","lines","markdownLines","maxLines","displayLines","line","startId","firstNodeId","lastNodeIds","renderNodes","endId","lastId","subgraph","edge","escapeLabel","nodeId","styleClass","nodes","prevLastNodeIds","node","result","renderNode","prevId","renderStepNode","renderSequenceNode","renderParallelNode","renderRaceNode","renderConditionalNode","renderSwitchNode","renderLoopNode","renderWorkflowRefNode","renderSagaStepNode","renderUnknownNode","label","truncate","forkId","joinId","parallelLabel","i","child","branchResult","raceLabel","decisionId","conditionLabel","trueResult","trueLabel","falseResult","falseLabel","expressionLabel","switchCase","caseLabel","loopStartId","loopEndId","loopLabel","bodyResult","compensationLabel","str","maxLength","renderPathsMermaid","paths","stepNodes","nodeCounter","path","step","id","edges","firstStep","firstStepId","current","next","currentId","nextId","lastStep","lastStepId","renderStaticJSON","ir","options","pretty","includeMetadata","serializable","key","value","renderMultipleStaticJSON","workflows","filePath","DEFAULT_OPTIONS","idCounter","resetIdCounter","generateId","analyzeWorkflowSource","sourceCode","options","opts","parser","loadTreeSitterBrowser","tree","ctx","createEmptyStats","findWorkflowDefinitions","d","results","workflowCalls","findWorkflowCalls","call","ir","analyzeWorkflowCall","runCalls","findRunCalls","analyzeRunCall","findSagaWorkflowDefinitions","sagaCalls","findSagaWorkflowCalls","analyzeSagaWorkflowCall","runSagaCalls","findRunSagaCalls","analyzeRunSagaCall","extractWorkflowOptions","optionsNode","result","prop","keyNode","valueNode","key","getText","value","extractStringValue","root","traverseNode","node","funcNode","workflowName","extractWorkflowName","definitions","workflowNames","funcText","args","firstArg","findAwaitlyImports","exportName","importedNames","isTypeOnly","child","sourceNode","modulePath","clauseChild","specifier","isTypeOnlySpecifier","specChild","nameNode","aliasNode","importedName","localName","hasVarDeclaration","identifierName","declarator","isIdentifierShadowed","current","params","param","found","n","left","body","runImportNames","sagaNames","runSagaImportNames","callNode","parentCtx","callbackNode","workflowWarnings","workflowStats","getLocation","prevWorkflow","sagaParamInfo","extractSagaParameterInfo","prevStepParamName","prevIsSagaDestructured","prevSagaStepAlias","prevSagaTryStepAlias","children","analyzeSagaCallback","treeRoot","definition","rootNode","wrapInSequence","metadata","generateRunSagaName","line","filePath","firstParam","patternNode","aliases","extractSagaAliasesFromObjectPattern","objectPattern","alias","name","analyzeSagaStatements","analyzeSagaExpression","statements","stmt","nodes","analyzeSagaStatement","expr","analyzeSagaVariableDeclaration","returnExpr","analyzeSagaIfStatement","analyzeSagaLoopStatement","analyzeSagaSwitchStatement","inner","analyzeSagaCallExpression","decl","ifStmt","conditionNode","consequentNode","alternateNode","condition","consequent","analyzeSagaBlock","alternate","elseContent","loopStmt","bodyNode","bodyChildren","loopType","rightNode","iterSource","switchStmt","expression","cases","hasStepCalls","caseNode","caseValueNode","isDefault","caseValue","bodyStatements","sagaParam","analyzeSagaStepCall","analyzeSagaTryStepCall","secondArg","callee","extractCalleeFromFunctionBody","hasCompensation","compensationCallee","description","markdown","extractSagaStepOptions","generateRunName","stepParamName","extractStepParameterName","analyzeCallback","extractStepFromObjectPattern","analyzeStatements","analyzeExpression","analyzeStatement","analyzeVariableDeclaration","analyzeIfStatement","analyzeForStatement","analyzeForInStatement","analyzeWhileStatement","analyzeSwitchStatement","analyzeCallExpression","analyzeStreamWritableCall","optionsArg","extractStreamOptions","analyzeStreamReadableCall","analyzeStreamForEachCall","extractStreamForEachOptions","extractNumberValue","stepParam","analyzeStepCall","analyzeStepRetryCall","analyzeStepTimeoutCall","analyzeParallelCall","analyzeRaceCall","analyzeConditionalHelper","analyzeAllAsyncCall","analyzeAnyAsyncCall","isLikelyWorkflowCall","analyzeWorkflowRefCall","paramText","extractStepOptions","argList","funcArg","retry","extractRetryConfig","timeout","extractTimeoutConfig","config","text","num","parallelName","analyzed","analyzeCallbackBody","stepNode","analyzeParallelItem","analyzeBlock","helper","defaultValue","mode","element","implicitStep","createImplicitStepFromCall","forStmt","isForOf","whileStmt","callback"]}