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 copilot_instructions;
10pub mod cursor_rules;
11pub mod gemini_md;
12
13/// A single rendered output file.
14pub struct RenderedOutput {
15    /// Relative path from the repo root where this file should be written.
16    pub path: Utf8PathBuf,
17    /// The rendered string content.
18    pub content: String,
19}
20
21/// Render all outputs enabled by the policy.
22///
23/// Returns a list of outputs in a deterministic order:
24/// `AGENTS.md` → `CLAUDE.md` → cursor rules → `GEMINI.md` → copilot instructions.
25///
26/// # Errors
27///
28/// Returns [`crate::Error::Render`] if any template fails to render.
29pub fn render_all(policy: &Policy) -> Result<Vec<RenderedOutput>> {
30    let mut outputs = Vec::new();
31    if policy.outputs.agents_md {
32        outputs.push(agents_md::render(policy)?);
33    }
34    if policy.outputs.claude_md {
35        outputs.push(claude_md::render(policy)?);
36    }
37    if policy.outputs.cursor_rules {
38        // cursor_rules returns Vec — one default.mdc plus one per role
39        outputs.extend(cursor_rules::render(policy)?);
40    }
41    if policy.outputs.gemini_md {
42        outputs.push(gemini_md::render(policy)?);
43    }
44    if policy.outputs.copilot_instructions {
45        outputs.push(copilot_instructions::render(policy)?);
46    }
47    Ok(outputs)
48}