agent_policy/render/
junie_guidelines.rs1use camino::Utf8PathBuf;
4use minijinja::Environment;
5
6use crate::{
7 error::{Error, Result},
8 model::normalized::Policy,
9 render::RenderedOutput,
10};
11
12const TARGET: &str = ".junie/guidelines.md";
13const TEMPLATE_STR: &str = include_str!("../../templates/junie_guidelines.md.j2");
14
15pub fn render(policy: &Policy) -> Result<RenderedOutput> {
21 let mut env = Environment::new();
22 env.add_template("junie_guidelines.md", TEMPLATE_STR)
23 .map_err(|e| Error::Render {
24 target: TARGET.to_owned(),
25 source: e,
26 })?;
27
28 let tmpl = env
29 .get_template("junie_guidelines.md")
30 .map_err(|e| Error::Render {
31 target: TARGET.to_owned(),
32 source: e,
33 })?;
34
35 let commands_defined = !policy.commands.is_empty();
36 let content = tmpl
37 .render(minijinja::context! {
38 project => &policy.project,
39 commands => &policy.commands,
40 commands_defined => commands_defined,
41 paths => &policy.paths,
42 roles => &policy.roles,
43 constraints => &policy.constraints,
44 })
45 .map_err(|e| Error::Render {
46 target: TARGET.to_owned(),
47 source: e,
48 })?;
49
50 Ok(RenderedOutput {
51 path: Utf8PathBuf::from(TARGET),
52 content,
53 })
54}