(content: string)
| 46 | * Agent files must have frontmatter with at least a name |
| 47 | */ |
| 48 | export function parseAgentFile(content: string): AgentFile { |
| 49 | const { frontmatter, markdown } = parseMarkdownRule(content); |
| 50 | |
| 51 | if (!frontmatter.name) { |
| 52 | throw new Error( |
| 53 | "Agent file must contain YAML frontmatter with a 'name' field", |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | const validationResult = agentFileFrontmatterSchema.safeParse(frontmatter); |
| 58 | |
| 59 | if (!validationResult.success) { |
| 60 | const errorDetails = validationResult.error.issues |
| 61 | .map((issue) => `${issue.path.join(".")}: ${issue.message}`) |
| 62 | .join(", "); |
| 63 | throw new Error(`Invalid agent file frontmatter: ${errorDetails}`); |
| 64 | } |
| 65 | |
| 66 | return { |
| 67 | ...validationResult.data, |
| 68 | prompt: markdown, |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Serializes an Agent file back to markdown with YAML frontmatter |
no test coverage detected