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,WAAA,CAAK,KAAM,CAAA,CAAC,CAAC,CAAA;AACjC,MAAA,IAAI,OAAO,WAAA,KAAgB,QAAY,IAAA,WAAA,KAAgB,IAAM,EAAA;AAC3D,QAAO,OAAA;AAAA,UACL,KAAO,EAAA,KAAA;AAAA,UACP,MAAA,EAAQ,CAAC,+BAA+B,CAAA;AAAA,UACxC,UAAU;AAAC,SACb;AAAA;AACF,aACO,KAAY,EAAA;AACnB,MAAO,OAAA;AAAA,QACL,KAAO,EAAA,KAAA;AAAA,QACP,MAAQ,EAAA,CAAC,CAAgC,6BAAA,EAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA;AAAA,QACxD,UAAU;AAAC,OACb;AAAA;AAGF,IAAO,OAAA;AAAA,MACL,KAAO,EAAA,IAAA;AAAA,MACP,QAAQ,EAAC;AAAA,MACT,UAAU;AAAC,KACb;AAAA;AAEJ","file":"file-format-validator.cjs","sourcesContent":["import { ValidationResult, FrontmatterMetadata } from '../types.js';\nimport { load } from 'js-yaml';\n\nexport class FileFormatValidator {\n  // More permissive regex that allows for extra spaces and newlines\n  private readonly FRONTMATTER_REGEX = /^-{3,}[\\r\\n\\s]+([\\s\\S]*?)[\\r\\n\\s]+-{3,}[\\r\\n\\s]*([\\s\\S]*)$/;\n\n  /**\n   * Validates that a file has the correct format:\n   * - Must be a markdown file\n   * - Must have frontmatter section that can be parsed as YAML\n   * - Must have some content (even if just whitespace)\n   */\n  validateFileFormat(filePath: string, content: string): ValidationResult {\n    const errors: string[] = [];\n\n    // Check file extension - case insensitive\n    if (!filePath.toLowerCase().endsWith('.md')) {\n      errors.push('File must be a markdown file');\n      return { valid: false, errors, warnings: [] };\n    }\n\n    // Check frontmatter structure - more permissive now\n    const match = content.match(this.FRONTMATTER_REGEX);\n    if (!match) {\n      errors.push('File must have frontmatter section marked with ---');\n      return { valid: false, errors, warnings: [] };\n    }\n\n    // Get frontmatter content, allowing for whitespace\n    const frontmatter = match[1].trim();\n    \n    // Validate YAML - only care if it parses\n    try {\n      const parsed = load(frontmatter);\n      if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n        errors.push('Frontmatter must be a valid YAML object');\n        return { valid: false, errors, warnings: [] };\n      }\n    } catch (err) {\n      errors.push('Frontmatter must be valid YAML');\n      return { valid: false, errors, warnings: [] };\n    }\n\n    return {\n      valid: true,\n      errors,\n      warnings: []\n    };\n  }\n\n  /**\n   * Parse frontmatter from content string\n   * Returns null if no valid frontmatter found\n   */\n  parseFrontmatter(content: string): Record<string, any> | null {\n    const match = content.match(this.FRONTMATTER_REGEX);\n    if (!match) {\n      return null;\n    }\n\n    try {\n      const frontmatter = match[1].trim();\n      const parsed = load(frontmatter);\n      if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n        return null;\n      }\n      return parsed as Record<string, any>;\n    } catch (err) {\n      return null;\n    }\n  }\n\n  validateFrontmatterFormat(content: string): ValidationResult {\n    // Check for empty content\n    if (!content.trim()) {\n      return {\n        valid: false,\n        errors: ['Content is empty'],\n        warnings: []\n      };\n    }\n\n    // Check for frontmatter delimiters\n    const match = content.match(/^---\\n([\\s\\S]*?\\n)---\\n/);\n    if (!match) {\n      return {\n        valid: false,\n        errors: ['Content must start with frontmatter delimiters (---)'],\n        warnings: []\n      };\n    }\n\n    try {\n      // Parse YAML content\n      const frontmatter = load(match[1]);\n      if (typeof frontmatter !== 'object' || frontmatter === null) {\n        return {\n          valid: false,\n          errors: ['Frontmatter must be an object'],\n          warnings: []\n        };\n      }\n    } catch (error: any) {\n      return {\n        valid: false,\n        errors: [`Failed to parse frontmatter: ${error.message}`],\n        warnings: []\n      };\n    }\n\n    return {\n      valid: true,\n      errors: [],\n      warnings: []\n    };\n  }\n} "]}