Skip to main content

Module rules_dedup

Module rules_dedup 

Source
Expand description

Collapse duplicated lean-ctx guidance (#578): the planner and fixer behind lean-ctx rules dedup, setup, doctor --fix and the hook refresh.

A client should pay for lean-ctx rules exactly once per session. Older installs (and parent-directory walks in monorepos) left full rule copies in several auto-loaded files; doctor overhead detects the duplication, this module repairs it:

  1. lean-ctx-OWNED dedicated rule files outside the canonical global location (project/parent .cursor/rules/lean-ctx.mdc, .claude/rules/lean-ctx.md, …) → deleted.
  2. .cursorrules lean-ctx blocks → removed when the canonical global Cursor mdc exists (Cursor auto-loads both; pointer lives in AGENTS.md).
  3. Stale compression blocks in .cursorrules → removed under the same condition (the global mdc carries the block).
  4. Compression block in a shared AGENTS.md (#684) → removed (pointer kept) once every AGENTS.md reader is covered by its own canonical carrier; otherwise reported and left as the carrier.

Only lean-ctx-owned files and lean-ctx-marked blocks are ever touched. Unmarked user content is reported, never modified. Default is a dry-run report; --apply executes with .bak backups for partial edits.

Enums§

Action
One planned dedup action.

Functions§

apply
Executes one action. Returns a human-readable result line.
auto_apply
Non-interactive auto-heal used by lean-ctx setup and doctor --fix (#578): applies every fixable dedup action (owned duplicates deleted, marked blocks stripped with .bak backups) and returns one result line per action. Report-only findings (user-maintained content) are never touched.
plan
Plans the dedup for project (walking parents up to, excluding, home).
retire_rules_file
Retire a lean-ctx rules file that duplicates a host’s single rules channel (A3): a wholly lean-ctx-owned file is deleted; a file a user extended keeps every line outside the lean-ctx markers (backup at <file>.bak). Returns a result line when something changed. Shared by setup/init writers and rules dedup, so no path ever deletes user text.