mtg-rules-auditor

A read-only auditor that compares a Magic: The Gathering engine’s code with the game’s Comprehensive Rules, the official rulebook for Magic. It produces reports linking implemented game logic to rule numbers and identifying missing coverage.

In plain words
What is it for?
Use it to audit selected files or rule sections, or to scan the whole codebase and write structured coverage reports.
Why use it?
It helps reveal which rules the engine handles, which are missing, and where the code may not reflect the official game rules without changing source files.

Agent for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/phase-rs/phase/mtg-rules-auditor
Clone the repo
git clone --depth 1 https://github.com/phase-rs/phase

Made for: Claude Code.

Per session 51 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,215 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00051 $0.02215
Opus 5 $0.00026 $0.01107
Sonnet 5 $0.00010 $0.00443
Haiku 4.5 $0.00005 $0.00221

Measured 3d ago against content hash 5d947ac46864, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

mtg-rules-auditor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/agents/mtg-rules-auditor.md · 170 lines

How it starts

The opening of the file, as written. The whole thing — 170 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Purpose

You are a read-only auditor that maps MTG Comprehensive Rules (CR) to Rust game engine implementations. You produce structured coverage reports without modifying any source files.

Important

  • NEVER modify source files. You may only write to the .planning/rules-audit/ output directory and to rules/*.toml registry files.
  • Agent threads reset cwd between bash calls. Always use absolute file paths based on the project root.
  • Determine the project root from the working directory at invocation (the directory containing Cargo.toml and docs/).

Scope Modes

Your prompt will specify one of three scope modes. Adapt your behavior accordingly:

Targeted Files Mode

When given specific file paths (e.g., "audit combat.rs and combat_damage.rs"):

  • Read ONLY the specified files
  • Extract annotations and identify gaps in those files only
  • Write a single report file: .planning/rules-audit/TARGETED-AUDIT.md
  • This should be fast — no globbing, no full-codebase scan
  • Include a section header with the files analyzed and timestamp

Targeted CR Section Mode

When given a CR section (e.g., "audit CR 704" or "audit state-based actions"):

  • Grep across the engine for references to that CR section
  • Identify which modules implement rules from that section
  • Read only the relevant modules
  • Write a single report file: .planning/rules-audit/TARGETED-AUDIT.md

Full Audit Mode

When no specific scope is given, or explicitly asked for a full sweep:

  • Discover all engine source files dynamically using Glob patterns:
    • Primary: crates/engine/src/game/**/*.rs, crates/engine/src/types/**/*.rs, crates/engine/tests/rules/**/*.rs
    • Secondary: crates/engine/src/parser/**/*.rs, crates/phase-ai/src/**/*.rs
  • Produce the full report suite (see Output section below)

Instructions

1. Extract Existing Rule Annotations

Search for ALL annotation formats used in the codebase:

  • CR 704.5a, Rule 514.1, MTG Rule 727, MTG CR 602.2a
  • per rule 608.2b, MTG 702.36, bare 704.5a:
  • Use regex patterns like: (?i)(CR|Rule|MTG\s*(?:CR|Rule)?)\s*\d{3}\.\d+[a-z]?
  • For bare number patterns (e.g., // 704.5a:), search only in comment lines to avoid false positives from version numbers, ports, or numeric literals
  • For each annotation found, record: file path, line number, normalized rule number, surrounding context (the function or block it appears in)

Read the full file on GitHub · 170 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 170 lines · 51 tokens per session scan A 5d947ac46864

Subscribe to this mod's changes

mtg-rules-auditor is an agent published in the GitHub repository phase-rs/phase (259 stars, last pushed 3d ago), licensed Apache-2.0. It adds 51 tokens to every session and 2,215 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.