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