# `SuperPi.Plugins.Rules`
[🔗](https://github.com/oleksandr/super-pi-beam/blob/v0.1.0/lib/super_pi/plugins/rules.ex#L1)

Project & Agent Rules Plugin (`SuperPi.Extension` behaviour).

Implements rule loading and injection semantics:
- Walks up from workspace directories to the repository root discovering `AGENTS.md`, `GEMINI.md`,
  and `.agents/rules/*.md`, plus global config rules (`<global config>/AGENTS.md`).
- Deduplicates all rules by canonical resolved path so a rule file is never injected twice.
- Enforces the **Per-File Limit (`24,000` bytes)**, truncating cleanly on line boundaries when a rule
  file exceeds `24,000` bytes.
- Enforces the **Aggregate Rules Budget (`20,000` tokens / `~80,000` bytes)**: rules within budget are
  inlined as `<RULE[path]>` blocks inside a `pi.system` section (`id: "user_rules"`); over-budget
  rules are demoted to file-path pointers so the agent can read them on demand.

# `build_rules_section`

Formats discovered rule files under `token_budget` (`20,000` tokens), demoting over-budget files
to path pointers.

# `description`

# `id`

# `name`

# `truncate_rule_to_limit`

Truncates raw rule text to `@per_file_byte_limit` (`24,000` bytes) on a line boundary.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
