|
| 1 | +--- |
| 2 | +name: rule-editor |
| 3 | +description: "Use this skill whenever the user wants to add, create, or capture a single agent rule into `.agents/rules/`. Triggers on phrases like 'add a rule', 'capture this as a rule', 'this should be a rule', 'turn this into a rule', 'I need a rule for X', or any time the user formulates a single standing guideline they want the agent to follow across sessions. Also use when the user asks whether a fact belongs in a hook, `AGENTS.md`, a rule, or a skill. Knows the classification (hook vs AGENTS.md vs rule vs skill) and the path-scoping conventions for `.agents/rules/`." |
| 4 | +--- |
| 5 | + |
| 6 | +# Rule Editor |
| 7 | + |
| 8 | +Add one agent rule to `.agents/rules/`, with the right scope (project vs global) and the right home (hook vs `AGENTS.md` vs rule vs skill). |
| 9 | + |
| 10 | +## What rules are (and aren't) |
| 11 | + |
| 12 | +Rules are modular markdown instructions, optionally scoped to file paths via YAML frontmatter. They're one of four homes for "things the agent should do": |
| 13 | + |
| 14 | +| Mechanism | Loads | Best for | |
| 15 | +| --- | --- | --- | |
| 16 | +| Hook (`settings.json`) | On tool events | Automated behaviors ("whenever X", "before/after Y") | |
| 17 | +| `AGENTS.md` | Every session | Always-true single-file project facts | |
| 18 | +| Rules (unscoped) | Every session | Always-on facts split by topic | |
| 19 | +| Rules (path-scoped) | When matching files are touched | Subsystem-specific guidance | |
| 20 | +| Skills | On invocation or detected relevance | Multi-step procedures | |
| 21 | + |
| 22 | +Hooks are deterministic harness-level enforcement. The other three are probabilistic in-context instructions the agent reads and tries to follow. When a behavior can be a hook, prefer that. |
| 23 | + |
| 24 | +## Where rules live |
| 25 | + |
| 26 | +`.agents/rules/` is the canonical home for rules, in two scopes: |
| 27 | + |
| 28 | +- **Project**: `<repo-root>/.agents/rules/` is checked into version control and applies to this repo only. Always write to the git repo root, not a subdirectory. |
| 29 | +- **Global**: `~/.agents/rules/` applies to every project. Personal preferences only. |
| 30 | + |
| 31 | +Always ask the user which scope they want. Don't guess. |
| 32 | + |
| 33 | +## Anatomy of a rule |
| 34 | + |
| 35 | +A rule is a markdown file with optional YAML frontmatter. |
| 36 | + |
| 37 | +```markdown |
| 38 | +--- |
| 39 | +paths: |
| 40 | + - "src/api/**/*.ts" |
| 41 | +--- |
| 42 | + |
| 43 | +# API rules |
| 44 | + |
| 45 | +- Validate all input with Zod schemas. |
| 46 | +- Wrap handlers in `withErrorBoundary`. |
| 47 | +- Return `{ ok: false, error }` on failure, never throw. |
| 48 | +``` |
| 49 | + |
| 50 | +Rules without `paths` load every session. Rules with `paths` load only when matching files are touched. |
| 51 | + |
| 52 | +## When to scope vs leave unscoped |
| 53 | + |
| 54 | +Scope (`paths:` frontmatter) when the rule applies to one subsystem. Examples: API conventions only matter under `src/api/**`, Tailwind class ordering only matters in `.tsx`, SQL migrations only matter in `migrations/**`. |
| 55 | + |
| 56 | +Leave unscoped only for project-wide facts that don't already live in `AGENTS.md`. If the fact fits in `AGENTS.md` and `AGENTS.md` is still short, put it there instead. |
| 57 | + |
| 58 | +## Workflow |
| 59 | + |
| 60 | +One rule per invocation. Walk these steps in order, stopping early if classification routes elsewhere. |
| 61 | + |
| 62 | +1. **Check if it's a hook**. Is this an automated behavior pattern ("whenever X, do Y", "each time X happens", "before/after tool Z")? If yes, this is harness work, not rule work. Tell the user this looks like a hook, recommend invoking `update-config` to set it up in `settings.json`, and stop. Hooks are deterministic, rules are probabilistic. Always prefer the deterministic route when it fits. |
| 63 | +2. **Check if it's `AGENTS.md`**. Is this a single always-true fact about the project (e.g., "build with `pnpm`", "main branch is `develop`")? If yes, recommend editing `AGENTS.md` directly and stop. |
| 64 | +3. **Check if it's a skill**. Is this a multi-step workflow with its own context, branching logic, or generated output? If yes, recommend invoking `skill-creator` and stop. |
| 65 | +4. **Ask scope**. Confirmed it's a rule. Ask: "Project (`<repo-root>/.agents/rules/`) or global (`~/.agents/rules/`)?" |
| 66 | +5. **Pick a topic file**. One topic per file. Reuse an existing file (e.g., `testing.md`, `api.md`, `styling.md`) if the topic has one. Create a new descriptive filename only for genuinely new topics. |
| 67 | +6. **Decide on path scoping**. Subsystem-only: ask the user for the glob and add `paths:` frontmatter. Project-wide: leave unscoped. |
| 68 | +7. **Write the body**. Imperative bullets, brief. Explain the *why* when the rule itself doesn't make the reason obvious. Agents make better judgment calls when they understand intent. |
| 69 | +8. **Show, then write**. Show the proposed file (frontmatter + body + target path) before writing to disk so the user can validate topic, scoping, and content. |
| 70 | + |
| 71 | +## Anti-patterns |
| 72 | + |
| 73 | +- Multi-paragraph prose. Use bullets. |
| 74 | +- ALL-CAPS ALWAYS / NEVER as a substitute for explanation. Agents follow reasoning better than rigid commands. |
| 75 | +- Duplicating content between `AGENTS.md` and rules. Pick one home per fact. |
| 76 | +- Putting "how to do X" procedures in a rule file. Those are skills. |
| 77 | +- Writing a rule for an automated behavior that could be a hook. Hooks are more reliable. |
| 78 | +- Adding `paths:` to every rule reflexively. Some rules are genuinely project-wide. |
| 79 | +- Creating a new topic file when an existing one would fit. Reuse over fragmentation. |
0 commit comments