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iBAA+B,IAAI,wBAAA,EAA0B,CAAA;AAC9F,uBAAA,CAAwB,QAAS,CAAA,YAAA,kBAAgC,IAAI,yBAAA,EAA2B,CAAA;AAKzF,SAAS,uBAAA,CAAwB,eAAwB,OAAwC,EAAA;AACtG,EAAI,IAAA,CAAC,eAAsB,OAAA,SAAA;AAE3B,EAAA,QAAQ,aAAe;AAAA,IACrB,KAAK,KAAA;AACH,MAAA,IAAI,OAAY,KAAA,YAAA,IAAgB,OAAY,KAAA,SAAA,IAAa,YAAY,SAAW,EAAA;AAC9E,QAAO,OAAA,eAAA;AAAA;AAET,MAAA;AAAA,IAEF,KAAK,MAAA;AACH,MAAO,OAAA,eAAA;AAAA,IAET,KAAK,MAAA;AACH,MAAO,OAAA,UAAA;AAAA,IAET,KAAK,MAAA;AACH,MAAO,OAAA,YAAA;AAAA,IAET,KAAK,MAAA;AACH,MAAO,OAAA,WAAA;AAAA,IAET,KAAK,KAAA;AAEH,MAAO,OAAA,UAAA;AAAA;AAGX,EAAO,OAAA,SAAA;AACT;AA5BgB,MAAA,CAAA,uBAAA,EAAA,yBAAA,CAAA","file":"chunk-J5DAGGL3.mjs","sourcesContent":["// String operations are legitimate in this file for security escaping\n// This file implements security-critical escaping strategies for different execution\n// contexts (shell, URL, etc.). String manipulation here prevents injection attacks\n// by properly escaping special characters based on the target context.\n\n/**\n * Interpolation Context System\n * \n * This module defines how values should be escaped/formatted based on\n * where they're being used. This ensures that:\n * - Shell commands get proper shell escaping\n * - URLs get URL encoding\n * - Templates remain literal\n * - Data values are formatted appropriately\n */\n\nexport enum InterpolationContext {\n  /** Default context - no special escaping */\n  Default = 'default',\n  \n  /** Shell command context - requires shell escaping */\n  ShellCommand = 'shell-command',\n  \n  /** Shell code block context - different escaping rules */\n  ShellCode = 'shell-code',\n  \n  /** URL context - requires URL encoding */\n  Url = 'url',\n  \n  /** Template content - values remain literal */\n  Template = 'template',\n  \n  /** Data value context - JSON-like formatting */\n  DataValue = 'data-value',\n  \n  /** File path context - path normalization */\n  FilePath = 'file-path'\n}\n\n/**\n * Escaping strategy interface\n */\nexport interface EscapingStrategy {\n  /**\n   * Escape a value for safe use in this context\n   */\n  escape(value: string): string;\n  \n  /**\n   * Get the context type\n   */\n  getContext(): InterpolationContext;\n}\n\n/**\n * Factory for creating escaping strategies\n */\nexport class EscapingStrategyFactory {\n  private static strategies = new Map<InterpolationContext, EscapingStrategy>();\n  \n  static register(context: InterpolationContext, strategy: EscapingStrategy): void {\n    this.strategies.set(context, strategy);\n  }\n  \n  static getStrategy(context: InterpolationContext): EscapingStrategy {\n    const strategy = this.strategies.get(context);\n    if (!strategy) {\n      // Fallback to default\n      return this.strategies.get(InterpolationContext.Default)!;\n    }\n    return strategy;\n  }\n}\n\n/**\n * Default escaping - no transformation\n */\nclass DefaultEscapingStrategy implements EscapingStrategy {\n  escape(value: string): string {\n    return value;\n  }\n  \n  getContext(): InterpolationContext {\n    return InterpolationContext.Default;\n  }\n}\n\n/**\n * Shell command escaping strategy\n * Properly escapes values for use in shell commands\n */\nclass ShellCommandEscapingStrategy implements EscapingStrategy {\n  escape(value: string): string {\n    if (!value) return '';\n    \n    // For shell commands, we need to handle the fact that the value\n    // will be used within double quotes in the shell command.\n    // The strategy is to escape characters that have special meaning \n    // in double-quoted strings: \\ $ ` \"\n    // This preserves literal values when interpolating mlld variables\n    \n    return value\n      .replace(/\\\\/g, '\\\\\\\\')  // Escape backslashes first\n      .replace(/\"/g, '\\\\\"')    // Escape double quotes\n      .replace(/\\$/g, '\\\\$')   // Escape dollar signs to preserve literal values\n      .replace(/`/g, '\\\\`');   // Escape backticks\n  }\n  \n  getContext(): InterpolationContext {\n    return InterpolationContext.ShellCommand;\n  }\n}\n\n/**\n * Shell code escaping - preserves exact formatting for code blocks\n */\n// REMOVED: ShellCodeEscapingStrategy (revert)\n\n/**\n * Template escaping - values remain completely literal\n */\nclass TemplateEscapingStrategy implements EscapingStrategy {\n  escape(value: string): string {\n    // Templates should never modify the value\n    return value;\n  }\n  \n  getContext(): InterpolationContext {\n    return InterpolationContext.Template;\n  }\n}\n\n/**\n * Data value escaping - for use in data contexts\n */\nclass DataValueEscapingStrategy implements EscapingStrategy {\n  escape(value: string): string {\n    // For data values, we might want to ensure proper JSON escaping\n    // but for now, keep it literal\n    return value;\n  }\n  \n  getContext(): InterpolationContext {\n    return InterpolationContext.DataValue;\n  }\n}\n\n/**\n * Initialize default strategies\n */\nEscapingStrategyFactory.register(InterpolationContext.Default, new DefaultEscapingStrategy());\nEscapingStrategyFactory.register(InterpolationContext.ShellCommand, new ShellCommandEscapingStrategy());\n// Revert: do not register ShellCode strategy\nEscapingStrategyFactory.register(InterpolationContext.Template, new TemplateEscapingStrategy());\nEscapingStrategyFactory.register(InterpolationContext.DataValue, new DataValueEscapingStrategy());\n\n/**\n * Helper to determine the appropriate context based on the directive type and subtype\n */\nexport function getInterpolationContext(directiveType?: string, subtype?: string): InterpolationContext {\n  if (!directiveType) return InterpolationContext.Default;\n  \n  switch (directiveType) {\n    case 'run':\n      if (subtype === 'runCommand' || subtype === 'runExec' || subtype === 'runCode') {\n        return InterpolationContext.ShellCommand;\n      }\n      break;\n      \n    case 'exec':\n      return InterpolationContext.ShellCommand;\n      \n    case 'text':\n      return InterpolationContext.Template;\n      \n    case 'data':\n      return InterpolationContext.DataValue;\n      \n    case 'path':\n      return InterpolationContext.FilePath;\n      \n    case 'add':\n      // Add directives output literal content\n      return InterpolationContext.Template;\n  }\n  \n  return InterpolationContext.Default;\n}\n"]}