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
instructionsblock (sent on everyinitialize).
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 withcore::rules_overhead::collect_rules_files, which attributesAGENTS.mdto the same set.
Functions§
- agents_
md_ can_ thin - Decide whether the shared project
AGENTS.mdmay drop its compression block (keeping only the<!-- lean-ctx -->pointer). Safe ⇔ EVERYAGENTS.mdreader present on this machine already receives the compression payload from its own canonical file. - carries_
full_ rules - True when
contentcarries a full lean-ctx payload — the canonical rule set (theRULES_MARKERheader) or the compression/output-style block — rather than just the lightweight<!-- lean-ctx -->cross-reference pointer. - client_
autoloads_ compression - For the MCP
instructionsblock: doesclient_namealready 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
instructionsblock: doesclient_namealready 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
instructionsblock: isclient_namea 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.jsoncarries lean-ctxpreToolUseentries 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
contentcontains a lean-ctx block but only the lightweight pointer (no canonical rules, no compression payload).