# pi-mdc-rules

Rules extension for [pi-coding-agent](https://github.com/badlogic/pi-mono).

Loads rules from `.agents/rules/*.md` and applies them based on frontmatter.

## Install

```
npm install pi-mdc-rules
```

## Usage

```
pi --extension pi-mdc-rules
```

Rules are re-read from disk on every turn, so changes are picked up immediately.

## Commands

### `/mdc`

Create a new rule interactively with AI assistance. Run `/mdc` inside pi and it will ask:

1. What the rule should enforce
2. Which trigger type to use
3. Which files to match (if `glob`)
4. A name for the rule file

The AI then generates and writes the rule to `.agents/rules/<name>.md`.

## Writing rules

Rules are Markdown files in `.agents/rules/` with a YAML frontmatter block. The `trigger` field controls when the rule is applied.

### `trigger: always_on`

Injected into the system prompt on every turn.

```markdown
---
trigger: always_on
---

Always use TypeScript strict mode. Never use `any`.
```

### `trigger: glob`

Blocks read/write/edit on matching files until the agent has read the rule. Use `globs` to specify which files trigger it.

```markdown
---
trigger: glob
globs: "*.py"
description: Python file conventions
---

Add an author comment at the top of every Python file. If you don't know the author, ask the user.
```

`globs` accepts a single pattern, a comma-separated list, or a YAML array:

```yaml
globs: "*.ts, *.tsx"
```

```yaml
globs:
  - "*.ts"
  - "*.tsx"
```

### `trigger: model_decision`

Listed in the system prompt as available guidance. The agent reads it on demand when relevant.

```markdown
---
trigger: model_decision
description: Guidelines for writing database migrations
---

All migrations must be reversible. Include both `up` and `down` steps...
```
