{"version":3,"sources":["../interpreter/eval/pipeline/detector.ts"],"names":["detectPipeline","node","directive","Array","isArray","pipes","length","pipeline","map","convertCondensedPipe","source","isRetryable","withClause","format","type","parallelCap","parallel","delayMs","values","meta","pipe","transform","fields","identifierParts","split","baseIdentifier","resolvedFields","slice","variableRef","valueType","identifier","value","args","rawIdentifier","rawArgs","hasPipeline","extractPipelineMetadata","asSection","debugPipelineDetection","process","env","MLLD_DEBUG","console","log","sources","push","join","detected","p"],"mappings":";;;AAkCO,SAASA,cAAAA,CACdC,MACAC,SAAyB,EAAA;AAKzB,EAAID,IAAAA,IAAAA,IAAQE,MAAMC,OAAQH,CAAAA,IAAAA,CAAKI,KAAK,CAAKJ,IAAAA,IAAAA,CAAKI,KAAMC,CAAAA,MAAAA,GAAS,CAAG,EAAA;AAE9D,IAAA,MAAMC,QAAWN,GAAAA,IAAAA,CAAKI,KAAMG,CAAAA,GAAAA,CAAIC,oBAAAA,CAAAA;AAChC,IAAO,OAAA;AACLF,MAAAA,QAAAA;MACAG,MAAQ,EAAA,YAAA;MACRC,WAAa,EAAA;;AACf,KAAA;AACF;AAGA,EAAA,IAAIV,IAAQA,IAAAA,IAAAA,CAAKW,UAAcX,IAAAA,IAAAA,CAAKW,WAAWL,QAAU,EAAA;AACvD,IAAO,OAAA;AACLA,MAAAA,QAAAA,EAAUN,KAAKW,UAAWL,CAAAA,QAAAA;MAC1BG,MAAQ,EAAA,iBAAA;AACRG,MAAAA,MAAAA,EAAQZ,KAAKW,UAAWC,CAAAA,MAAAA;AACxBF,MAAAA,WAAAA,EAAaV,KAAKa,IAAS,KAAA,gBAAA;AAC3BC,MAAAA,WAAAA,EAAad,KAAKW,UAAWI,CAAAA,QAAAA;AAC7BC,MAAAA,OAAAA,EAAShB,KAAKW,UAAWK,CAAAA;AAC3B,KAAA;AACF;AAGA,EAAA,IAAIf,WAAWgB,MAAQN,EAAAA,UAAAA,IAAcV,SAAUgB,CAAAA,MAAAA,CAAON,WAAWL,QAAU,EAA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AQtC,WAAW,CAAG,EAAA;AACxBoC,IAAAA,OAAAA,CAAQC,IAAI,qBAAA,CAAA;GACP,MAAA;AACLD,IAAAA,OAAAA,CAAQC,GAAI,CAAA,2BAAA,EAA6BC,OAAQE,CAAAA,IAAAA,CAAK,IAAA,CAAA,CAAA;AAEtD,IAAMC,MAAAA,QAAAA,GAAW/C,cAAeC,CAAAA,IAAAA,EAAMC,SAAAA,CAAAA;AACtC,IAAA,IAAI6C,QAAU,EAAA;AACZL,MAAQC,OAAAA,CAAAA,GAAAA,CAAI,oBAAsBI,EAAAA,QAAAA,CAASrC,MAAM,CAAA;AACjDgC,MAAAA,OAAAA,CAAQC,GAAI,CAAA,aAAA,EAAeI,QAASxC,CAAAA,QAAAA,CAASC,GAAIwC,CAAAA,CAAAA,CAAKA,KAAAA,CAAAA,CAAEf,aAAa,CAAA,CAAEa,IAAK,CAAA,KAAA,CAAA,CAAA;AAC5EJ,MAAAA,OAAAA,CAAQC,GAAI,CAAA,WAAA,EAAaI,QAASlC,CAAAA,MAAAA,IAAU,MAAA,CAAA;AAC5C6B,MAAQC,OAAAA,CAAAA,GAAAA,CAAI,cAAgBI,EAAAA,QAAAA,CAASpC,WAAW,CAAA;AAClD;AACF;AACF;AA5BgB2B,MAAAA,CAAAA,sBAAAA,EAAAA,wBAAAA,CAAAA","file":"chunk-JM4XNSW2.mjs","sourcesContent":["/**\n * Central pipeline detection and extraction\n * \n * This module provides a unified way to detect and extract pipelines\n * from various AST node structures and directive contexts.\n */\n\nimport type { DirectiveNode } from '@core/types';\nimport type { PipelineStage } from '@core/types';\n\n// PipelineCommand type is defined centrally in core/types/run.ts\n\n/**\n * Unified pipeline detection result\n */\nexport interface DetectedPipeline {\n  pipeline: PipelineStage[];\n  source: 'node-pipes' | 'node-withClause' | 'directive-values' | 'directive-meta';\n  format?: string;\n  isRetryable?: boolean;\n  parallelCap?: number;\n  delayMs?: number;\n}\n\n/**\n * Extract pipeline from any supported source\n * \n * This function checks all possible locations where a pipeline might be stored\n * in the AST or directive metadata, providing a single point of detection.\n * \n * @param node The AST node that might have a pipeline\n * @param directive The directive context (may contain pipeline in values or meta)\n * @returns Detected pipeline info or null if no pipeline found\n */\nexport function detectPipeline(\n  node: any,\n  directive?: DirectiveNode\n): DetectedPipeline | null {\n  // Priority order matters - check most specific first\n  \n  // 1. Check node.pipes (VariableReference with condensed pipes)\n  if (node && Array.isArray(node.pipes) && node.pipes.length > 0) {\n    // Convert condensed pipe format to standard pipeline format\n    const pipeline = node.pipes.map(convertCondensedPipe);\n    return {\n      pipeline,\n      source: 'node-pipes',\n      isRetryable: false // Variable pipes are not retryable\n    };\n  }\n  \n  // 2. Check node.withClause (ExecInvocation, some VariableReferences)\n  if (node && node.withClause && node.withClause.pipeline) {\n    return {\n      pipeline: node.withClause.pipeline,\n      source: 'node-withClause',\n      format: node.withClause.format,\n      isRetryable: node.type === 'ExecInvocation',\n      parallelCap: node.withClause.parallel,\n      delayMs: node.withClause.delayMs\n    };\n  }\n\n  // 3. Check directive.values.withClause (directive-level pipeline)\n  if (directive?.values?.withClause && directive.values.withClause.pipeline) {\n    return {\n      pipeline: directive.values.withClause.pipeline,\n      source: 'directive-values',\n      format: directive.values.withClause.format,\n      isRetryable: false,\n      parallelCap: directive.values.withClause.parallel,\n      delayMs: directive.values.withClause.delayMs\n    };\n  }\n\n  // 4. Check directive.meta.withClause (fallback for some literal cases)\n  if (directive?.meta?.withClause && directive.meta.withClause.pipeline) {\n    return {\n      pipeline: directive.meta.withClause.pipeline,\n      source: 'directive-meta',\n      format: directive.meta.withClause.format,\n      isRetryable: false,\n      parallelCap: directive.meta.withClause.parallel,\n      delayMs: directive.meta.withClause.delayMs\n    };\n  }\n  \n  // No pipeline found\n  return null;\n}\n\n/**\n * Convert condensed pipe format to standard pipeline command\n * \n * Condensed pipes (from @var|@transform syntax) need to be converted\n * to the standard PipelineCommand format used by executePipeline.\n */\nfunction convertCondensedPipe(pipe: any): PipelineStage {\n  // Handle different condensed pipe formats\n  if (pipe.type === 'CondensedPipe') {\n    const transform = pipe.transform as string;\n    const fields = (pipe.fields as string[] | undefined) ?? [];\n    const identifierParts = transform.split('.');\n    const baseIdentifier = identifierParts[0];\n    const resolvedFields = fields.length > 0 ? fields : identifierParts.slice(1);\n\n    const variableRef: any = {\n      type: 'VariableReference',\n      valueType: 'varIdentifier',\n      identifier: baseIdentifier\n    };\n\n    if (resolvedFields.length > 0) {\n      variableRef.fields = resolvedFields.map((value) => ({ type: 'field', value }));\n    }\n\n    return {\n      identifier: [variableRef],\n      args: pipe.args || [],\n      fields: resolvedFields,\n      rawIdentifier: transform,\n      rawArgs: pipe.args || []\n    };\n  }\n\n  // Already in correct format or unknown format - pass through\n  return pipe;\n}\n\n/**\n * Check if a value might have a pipeline attached\n * \n * Quick check without full extraction - useful for optimization.\n */\nexport function hasPipeline(node: any, directive?: DirectiveNode): boolean {\n  return !!(\n    node?.pipes?.length ||\n    node?.withClause?.pipeline ||\n    directive?.values?.withClause?.pipeline ||\n    directive?.meta?.withClause?.pipeline\n  );\n}\n\n/**\n * Extract all pipeline-related metadata from various sources\n * \n * This includes not just the pipeline commands but also format,\n * dependencies, etc.\n */\nexport function extractPipelineMetadata(\n  node: any,\n  directive?: DirectiveNode\n): {\n  pipeline?: PipelineStage[];\n  format?: string;\n  asSection?: string;\n} | null {\n  // Check all withClause sources\n  const withClause = \n    node?.withClause ||\n    directive?.values?.withClause ||\n    directive?.meta?.withClause;\n    \n  if (withClause) {\n    return {\n      pipeline: withClause.pipeline,\n      format: withClause.format,\n      asSection: withClause.asSection\n    };\n  }\n  \n  // Check condensed pipes (only have pipeline, no other metadata)\n  if (node?.pipes?.length) {\n    return {\n      pipeline: node.pipes.map(convertCondensedPipe)\n    };\n  }\n  \n  return null;\n}\n\n/**\n * Debug helper to log pipeline detection details\n */\nexport function debugPipelineDetection(\n  identifier: string,\n  node: any,\n  directive?: DirectiveNode\n): void {\n  if (process.env.MLLD_DEBUG !== 'true') return;\n  \n  console.log(`\\n=== Pipeline Detection for @${identifier} ===`);\n  \n  const sources = [];\n  if (node?.pipes?.length) sources.push(`node.pipes (${node.pipes.length} pipes)`);\n  if (node?.withClause?.pipeline) sources.push('node.withClause');\n  if (directive?.values?.withClause?.pipeline) sources.push('directive.values.withClause');\n  if (directive?.meta?.withClause?.pipeline) sources.push('directive.meta.withClause');\n  \n  if (sources.length === 0) {\n    console.log('  No pipeline found');\n  } else {\n    console.log('  Pipeline sources found:', sources.join(', '));\n    \n    const detected = detectPipeline(node, directive);\n    if (detected) {\n      console.log('  Selected source:', detected.source);\n      console.log('  Pipeline:', detected.pipeline.map(p => p.rawIdentifier).join(' | '));\n      console.log('  Format:', detected.format || 'none');\n      console.log('  Retryable:', detected.isRetryable);\n    }\n  }\n}\n"]}