Skip to main content

agent_policy/render/
mod.rs

1// Render pipeline — Phase 2
2
3use camino::Utf8PathBuf;
4
5use crate::{error::Result, model::normalized::Policy};
6
7pub mod agents_md;
8pub mod claude_md;
9pub mod cursor_rules;
10
11/// A single rendered output file.
12pub struct RenderedOutput {
13    /// Relative path from the repo root where this file should be written.
14    pub path: Utf8PathBuf,
15    /// The rendered string content.
16    pub content: String,
17}
18
19/// Render all outputs enabled by the policy.
20///
21/// Returns a list of outputs in a deterministic order:
22/// `AGENTS.md` → `CLAUDE.md` → cursor rules.
23///
24/// # Errors
25///
26/// Returns [`crate::Error::Render`] if any template fails to render.
27pub fn render_all(policy: &Policy) -> Result<Vec<RenderedOutput>> {
28    let mut outputs = Vec::new();
29    if policy.outputs.agents_md {
30        outputs.push(agents_md::render(policy)?);
31    }
32    if policy.outputs.claude_md {
33        outputs.push(claude_md::render(policy)?);
34    }
35    if policy.outputs.cursor_rules {
36        // cursor_rules returns Vec — one default.mdc plus one per role
37        outputs.extend(cursor_rules::render(policy)?);
38    }
39    Ok(outputs)
40}