Skip to main content

Module rules_channel

Module rules_channel 

Source
Expand description

Cross-channel rule deduplication policy (#684).

lean-ctx publishes its guidance through several “channels”:

  • per-client global rule files (~/.cursor/rules/lean-ctx.mdc, …),
  • the shared project AGENTS.md (Cursor, Codex and other agents all auto-load it),
  • the MCP server instructions block (sent on every initialize).

Several agents read more than one channel, so the same guidance can be billed two or three times per session. This module centralises the policy that decides, per client, which channel is the single canonical carrier — so the writers (compression inject, hooks), the repair command (lean-ctx rules dedup) and the honest accounting (doctor overhead) all agree on one source of truth.

Re-exports§

pub use crate::core::rules_canonical::COMPRESSION_BLOCK_END;
pub use crate::core::rules_canonical::COMPRESSION_BLOCK_START;

Constants§

AGENTS_MD_READERS
The agents that auto-load the shared project AGENTS.md. Kept in sync with core::rules_overhead::collect_rules_files, which attributes AGENTS.md to the same set.

Functions§

agents_md_can_thin
Decide whether the shared project AGENTS.md may drop its compression block (keeping only the <!-- lean-ctx --> pointer). Safe ⇔ EVERY AGENTS.md reader present on this machine already receives the compression payload from its own canonical file.
carries_full_rules
True when content carries a full lean-ctx payload — the canonical rule set (the RULES_MARKER header) or the compression/output-style block — rather than just the lightweight <!-- lean-ctx --> cross-reference pointer.
client_autoloads_compression
For the MCP instructions block: does client_name already auto-load the compression payload from a rule file? If so, repeating the output-style block in the per-session instructions is pure cross-channel duplication and can be dropped (the file copy governs).
client_autoloads_rules
For the MCP instructions block: does client_name already auto-load the canonical rules block (tool mapping, intent playbook, recovery line, …) from its own rule file? If so, repeating the whole skeleton in the per-session instructions bills the same guidance twice on every session (#578) — the builder collapses it to a one-line anchor instead.
client_hook_covered
For the MCP instructions block: is client_name a host whose installed lean-ctx hooks already compress the native tools? Drives the hook-aware anchor wording (GL #1153) — repeating “ctx_* replaces native tools” to a hook-covered Cursor re-creates exactly the instruction dissonance the HookCovered profile removes.
codex_compression_covered
Codex auto-loads ~/.codex/AGENTS.md; covered once it carries the block.
codex_present
Codex is present on this machine when its config dir exists.
cursor_compression_covered
Cursor auto-loads ~/.cursor/rules/lean-ctx.mdc; it is “covered” for the compression payload once that canonical file carries the block.
cursor_hooks_cover_native_tools
True when the installed Cursor hooks already compress the native tools (GL #1153): ~/.cursor/hooks.json carries lean-ctx preToolUse entries for BOTH the Shell rewrite and the Read/Grep redirect. Only then is the “use ctx_* instead of native” mapping dead weight — with partial or no hook coverage the full guidance stays.
cursor_hooks_json_covers
Path-based core of cursor_hooks_cover_native_tools, so the rules injector can derive the hooks.json location from the mdc target path (the two always live under the same .cursor/ dir).
is_pointer_only
True when content contains a lean-ctx block but only the lightweight pointer (no canonical rules, no compression payload).