Skip to main content

spec_driven_docs/services/
agents_render.rs

1//! Render the managed documentation block for a root `AGENTS.md`.
2//!
3//! The block is the canonical documentation-routing section plus the
4//! `SimpleEnglish` default directive, wrapped in the `AGENTS.md` markers with
5//! the profile's documentation root substituted. The installer places it;
6//! this only produces the bytes. The content lives in the embedded snippet,
7//! so the block and the snippet cannot drift.
8
9use crate::domain::marker::{AGENTS_BEGIN, AGENTS_END};
10
11/// The embedded documentation snippet, with `{docs_root}` unresolved.
12#[must_use]
13pub fn snippet() -> &'static str {
14    crate::embedded::SNIPPETS
15        .get_file("AGENTS-docs.md")
16        .and_then(include_dir::File::contents_utf8)
17        .unwrap_or_default()
18}
19
20/// The complete marked block for the given documentation root, newline-
21/// terminated.
22#[must_use]
23// sdd: permanent the braces are the block template's placeholder, not a formatting argument
24#[allow(clippy::literal_string_with_formatting_args)]
25pub fn render_block(docs_root: &str) -> String {
26    let body = snippet().replace("{docs_root}", docs_root);
27    let body = body.trim_end_matches('\n');
28    format!("{AGENTS_BEGIN}\n{body}\n{AGENTS_END}\n")
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn the_block_carries_the_markers_and_the_root() {
37        let block = render_block("docs");
38        assert!(block.starts_with("<!-- BEGIN spec-driven-docs docs -->\n"));
39        assert!(block.ends_with("<!-- END spec-driven-docs docs -->\n"));
40        assert!(block.contains("docs/specs/SPEC-simple-english.md"));
41        assert!(!block.contains("{docs_root}"));
42        assert!(block.contains("SimpleEnglish `Plain` mode"));
43    }
44
45    #[test]
46    fn the_underscore_root_reaches_the_block() {
47        let block = render_block("_docs");
48        assert!(block.contains("_docs/specs/SPEC-simple-english.md"));
49    }
50}