| 71 | return fm; |
| 72 | } |
| 73 | |
| 74 | function extractAgentBody(content) { |
| 75 | const normalized = content.replace(/\r\n/g, '\n'); |
| 76 | const bodyMatch = normalized.match(/^---\n[\s\S]*?\n---\n([\s\S]*)/); |
| 77 | return bodyMatch ? bodyMatch[1].trim() : normalized.trim(); |
| 78 | } |
| 79 | |
| 80 | function validateParsedAgent(parsedAgent) { |
| 81 | const errors = []; |
| 82 | |
| 83 | for (const field of AGENT_REQUIRED_FRONTMATTER) { |
| 84 | if (!parsedAgent.frontmatter[field]) { |
| 85 | errors.push(`missing frontmatter field: ${field}`); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (!parsedAgent.body) { |
| 90 | errors.push('missing agent instructions body'); |