Skip to main content

lean_ctx/rules_inject/
content.rs

1//! The rules/skill payloads lean-ctx injects: shared + dedicated markdown,
2//! Cursor MDC frontmatter, and per-agent rule paths.
3//!
4//! Rule CONTENT is delegated to `core::rules_canonical` — this module only
5//! handles format dispatch and the Cursor-specific frontmatter.
6
7use std::path::PathBuf;
8
9use super::RulesFormat;
10use crate::core::config::CompressionLevel;
11use crate::core::rules_canonical::{self as rc, Wrapper};
12
13pub(super) fn rules_content(format: &RulesFormat, level: CompressionLevel) -> String {
14    let shadow = crate::core::config::Config::load().shadow_mode;
15    match format {
16        RulesFormat::SharedMarkdown => rc::render(shadow, Wrapper::Shared, level),
17        RulesFormat::DedicatedMarkdown => rc::render(shadow, Wrapper::Dedicated, level),
18        RulesFormat::CursorMdc => {
19            let body = rc::render(shadow, Wrapper::Dedicated, level);
20            format!(
21                "---\n\
22                 description: \"lean-ctx: context compression layer. \
23                 Tools replace native Read/Grep/Shell — see rule body.\"\n\
24                 globs: **/*\n\
25                 alwaysApply: true\n\
26                 ---\n\n\
27                 {body}"
28            )
29        }
30    }
31}
32
33pub fn opencode_dedicated_rules_path(home: &std::path::Path) -> PathBuf {
34    home.join(".config/opencode/rules/lean-ctx.md")
35}
36
37pub fn gemini_dedicated_rules_path(home: &std::path::Path) -> PathBuf {
38    home.join(".gemini").join(GEMINI_DEDICATED_CONTEXT_FILENAME)
39}
40
41/// The `context.fileName` entry registered for Gemini in dedicated mode.
42pub const GEMINI_DEDICATED_CONTEXT_FILENAME: &str = "LEANCTX.md";