Skip to main content

lean_ctx/core/
rule_artifacts.rs

1//! The committed `LEAN-CTX.md` rule artifacts as `(relative_path, content)`
2//! pairs — the single source shared by the regenerator (`gen_rules` example)
3//! and the drift gate (`tests/rules_drift.rs`) so the project copy and the
4//! `rust/` copy can never disagree.
5//!
6//! Content is forced to the default profile (non-shadow, compression `Off`) so
7//! the committed bytes are independent of the developer's local lean-ctx config
8//! and stay deterministic (#498). The live writer
9//! (`hooks::ensure_project_agents_integration`) renders with the *user's* config
10//! instead — that is each user's own copy, not this repo's checked-in artifact.
11
12use crate::core::config::CompressionLevel;
13use crate::core::rules_canonical::{self, Wrapper};
14
15/// Project-relative paths of every committed dedicated-rules artifact. Add new
16/// real rule artifacts here — not docs examples or templates.
17pub const ARTIFACT_PATHS: &[&str] = &["LEAN-CTX.md", "rust/LEAN-CTX.md"];
18
19/// Canonical body of a project `LEAN-CTX.md`: the owner banner, the long-form
20/// rules block (non-shadow, compression `Off`), and a trailing newline.
21/// Inverse of what the drift gate reads back. Longform because `LEAN-CTX.md`
22/// is opened on demand (AGENTS.md pointer), never auto-loaded — it can afford
23/// the verbose teaching sections the injected profiles fold away (#578).
24#[must_use]
25pub fn canonical_body() -> String {
26    format!(
27        "{}\n{}\n",
28        rules_canonical::PROJECT_LEAN_CTX_OWNED_MARKER,
29        rules_canonical::render(false, Wrapper::Longform, CompressionLevel::Off)
30    )
31}
32
33/// `(relative_path, content)` for every artifact the generator writes. All
34/// artifacts share one canonical body today; the shape leaves room for
35/// per-path bodies later without changing callers.
36#[must_use]
37pub fn artifacts() -> Vec<(&'static str, String)> {
38    let body = canonical_body();
39    ARTIFACT_PATHS.iter().map(|p| (*p, body.clone())).collect()
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn canonical_body_is_owned_versioned_and_current() {
48        let body = canonical_body();
49        assert!(body.starts_with(rules_canonical::PROJECT_LEAN_CTX_OWNED_MARKER));
50        assert!(body.contains(&format!(
51            "<!-- version: {} -->",
52            rules_canonical::RULES_VERSION
53        )));
54        // The body must carry the v3 guidance it exists to ship.
55        assert!(body.contains("AGENT LOOP"));
56        assert!(body.contains("NAVIGATION PARADOX"));
57        assert!(body.ends_with('\n'));
58    }
59
60    #[test]
61    fn artifacts_cover_every_declared_path() {
62        let arts = artifacts();
63        assert_eq!(arts.len(), ARTIFACT_PATHS.len());
64        for (path, body) in arts {
65            assert!(ARTIFACT_PATHS.contains(&path));
66            assert!(!body.is_empty());
67        }
68    }
69}