{"record":{"id":"93e843923c1b1bd7","repo":"davila7/claude-code-templates","slug":"warning-could-not-parse-agent-file-filepath","errorCode":null,"errorMessage":"Warning: Could not parse agent file ${filePath}:","messagePattern":"Warning: Could not parse agent file (.+?):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-tool/src/analytics.js","lineNumber":1841,"sourceCode":"      \n      // Use color from frontmatter if available, otherwise generate one\n      const color = frontmatter.color ? this.convertColorToHex(frontmatter.color) : this.generateAgentColor(frontmatter.name);\n      \n      return {\n        name: frontmatter.name,\n        description: frontmatter.description,\n        systemPrompt,\n        tools,\n        level,\n        projectName,\n        filePath,\n        lastModified: stats.mtime,\n        color,\n        isActive: true // All loaded agents are considered active\n      };\n      \n    } catch (error) {\n      console.warn(chalk.yellow(`Warning: Could not parse agent file ${filePath}:`, error.message));\n      return null;\n    }\n  }\n\n  /**\n   * Generate consistent color for agent based on name\n   * @param {string} agentName - Name of the agent\n   * @returns {string} Hex color code\n   */\n  generateAgentColor(agentName) {\n    // Simple hash function to generate consistent colors\n    let hash = 0;\n    for (let i = 0; i < agentName.length; i++) {\n      const char = agentName.charCodeAt(i);\n      hash = ((hash << 5) - hash) + char;\n      hash = hash & hash; // Convert to 32-bit integer\n    }\n    ","sourceCodeStart":1823,"sourceCodeEnd":1859,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics.js#L1823-L1859","documentation":"Parsing a single agent markdown/JSON file failed (frontmatter YAML invalid, missing fields after parse, or read error), so loadAgentFile returns null and that agent is skipped.","triggerScenarios":"An agent file in the agents directory with malformed YAML frontmatter (tabs, unclosed quotes), a BOM, or a JSON agent file that isn't valid JSON; the per-file try/catch catches and skips it.","commonSituations":"Hand-edited agent files with YAML syntax errors; files copied from web with smart quotes; frontmatter delimiter typo (--- vs –––).","solutions":["Open the file named in the warning and validate its frontmatter (npx js-yaml or yamllint)","Fix YAML syntax: spaces not tabs, matching quotes, closing --- delimiter","Remove or rename the broken file so scans skip it cleanly","Check for a stray BOM: file starts with \\uFEFF before ---"],"exampleFix":"# before (broken)\n---\nname: \"My Agent\nrole: tester\n---\n# after\n---\nname: \"My Agent\"\nrole: tester\n---","handlingStrategy":"validation","validationCode":"const yaml = require('js-yaml');\nfunction validAgentFile(text) {\n  const m = text.match(/^---\\n([\\s\\S]*?)\\n---/);\n  if (!m) return false;\n  try { return typeof yaml.load(m[1]) === 'object'; } catch { return false; }\n}","typeGuard":"function isValidAgent(doc) {\n  return !!doc && typeof doc === 'object' && typeof doc.name === 'string';\n}","tryCatchPattern":"try { return parseAgent(text); }\ncatch (error) { console.warn(`Could not parse agent file ${filePath}:`, error.message); return null; }","preventionTips":["Lint agent frontmatter (yamllint) when authoring","Reject tabs in YAML; use spaces","Test new agent files with a quick parse before dropping them into the agents dir"],"tags":["yaml","frontmatter","agents","parsing"],"backgroundTag":"yaml-frontmatter-parse-error","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}