use std::path::{Path, PathBuf};
use super::RulesFormat;
use crate::core::config::CompressionLevel;
use crate::core::rules_canonical::{self as rc, Wrapper};
pub(super) fn cursor_wrapper_for_mdc(mdc_path: &Path) -> Wrapper {
let covered = mdc_path
.parent()
.and_then(Path::parent)
.is_some_and(|cursor_dir| {
crate::core::rules_channel::cursor_hooks_json_covers(&cursor_dir.join("hooks.json"))
});
if covered {
Wrapper::HookCovered
} else {
Wrapper::Dedicated
}
}
pub(crate) fn cursor_mdc_document(body: &str) -> String {
format!(
"---\n\
description: \"lean-ctx: context compression layer — \
tool guidance in rule body.\"\n\
globs: **/*\n\
alwaysApply: true\n\
---\n\n\
{body}"
)
}
pub(super) fn rules_content(
format: &RulesFormat,
level: CompressionLevel,
wrapper: Wrapper,
) -> String {
let shadow = crate::core::config::Config::load().shadow_mode;
match format {
RulesFormat::SharedMarkdown => rc::render(shadow, Wrapper::Shared, level),
RulesFormat::DedicatedMarkdown => rc::render(shadow, Wrapper::Dedicated, level),
RulesFormat::CursorMdc => cursor_mdc_document(&rc::render(shadow, wrapper, level)),
}
}
pub fn opencode_dedicated_rules_path(home: &std::path::Path) -> PathBuf {
home.join(".config/opencode/rules/lean-ctx.md")
}
pub fn gemini_dedicated_rules_path(home: &std::path::Path) -> PathBuf {
home.join(".gemini").join(GEMINI_DEDICATED_CONTEXT_FILENAME)
}
pub const GEMINI_DEDICATED_CONTEXT_FILENAME: &str = "LEANCTX.md";