home / skills / toilahuongg / shopify-agents-kit / rule-creator

rule-creator skill

/.claude/skills/rule-creator

This skill helps you create, update and organize AI behavior rules with concrete templates, examples, and validation guidance.

npx playbooks add skill toilahuongg/shopify-agents-kit --skill rule-creator

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
6.0 KB
---
name: rule-creator
description: Create and manage user rules that customize AI behavior. Use this skill when users want to create new rules, update existing rules, organize rules, or need guidance on writing effective rules for their projects or personal preferences.
---

# Rule Creator

Create effective user rules that customize AI behavior for projects and personal preferences.

## What Are User Rules?

User rules are custom instructions that modify how the AI assistant behaves. They can define:

- **Coding standards** - Style, patterns, and conventions
- **Language preferences** - Response language, terminology
- **Project configuration** - Framework choices, file structure
- **Workflow guidelines** - Git, testing, documentation practices

## Rule Creation Workflow

### Step 1: Identify Rule Purpose

Ask the user:
1. What behavior do you want to modify?
2. Is this a project rule (shared) or personal preference?
3. Are there exceptions to this rule?

### Step 2: Choose Rule Category

Common categories:
- `coding-style` - Code formatting, syntax preferences
- `language` - Response language, communication style
- `project` - Framework-specific, architecture decisions
- `git` - Commit messages, branching, PR guidelines
- `naming` - Variable, function, file naming conventions
- `security` - Authentication, secrets, input validation
- `testing` - Test coverage, naming, mocking practices
- `documentation` - Comments, README, JSDoc requirements

For templates and examples, see [references/rule-patterns.md](references/rule-patterns.md).

### Step 3: Write the Rule

Follow these principles:

1. **Be specific** - Use concrete examples
2. **Be actionable** - Clear instructions, not vague guidance
3. **Include examples** - Show correct usage
4. **Define exceptions** - When the rule doesn't apply

For detailed writing guidelines, see [references/best-practices.md](references/best-practices.md).

### Step 4: Format the Rule

Use this format:

```
## [Category]: [Short Title]

[Clear instruction in imperative form]

Example:
[Code or text example showing correct usage]

Exception: [When this rule doesn't apply, if any]
```

### Step 5: Validate the Rule

Check against this list:
- [ ] Clear and unambiguous?
- [ ] Specific context defined?
- [ ] Actionable instruction?
- [ ] Example included (if complex)?
- [ ] Exceptions documented?
- [ ] No conflicts with existing rules?

## Quick Templates

### Coding Style Rule

```
## Coding: [Title]

[What to do and how to do it]

✅ Correct:
[good example]

❌ Avoid:
[bad example]
```

### Project Configuration Rule

```
## Project: [Title]

Use [technology/pattern] for [purpose].

Configuration:
[relevant settings or file structure]
```

### Workflow Rule

```
## Workflow: [Title]

[Step-by-step process or checklist]

1. [First step]
2. [Second step]
3. [Third step]
```

## Managing Rules

### Adding Rules

Create or append to the user's rules file. Group related rules under clear headers.

### Updating Rules

When updating, preserve existing rules unless explicitly asked to replace them.

### Organizing Rules

Suggest organizing rules by:
1. Priority (security > performance > style)
2. Category (coding, git, testing, etc.)
3. Scope (project-wide vs file-specific)

## Output Location

Rules must be saved in the `.agent/rules/` directory with one file per rule category:

```
.agent/rules/
├── git-commit.md          # Git commit format rules
├── coding-style.md        # Coding style rules
├── naming-conventions.md  # Naming rules
├── security.md            # Security rules
└── testing.md             # Testing rules
```

### File Naming

- Use kebab-case: `{rule-name}.md`
- Name should reflect the rule category or purpose
- Examples: `git-commit.md`, `coding-style.md`, `api-design.md`

### File Structure

Each rule file should include YAML frontmatter with activation mode, followed by the rule content:

```markdown
---
activation: always_on  # or: manual, model_decision, glob
description: Brief description for model decision mode
globs: ["*.ts", "src/**/*.tsx"]  # only for glob activation
---

# [Rule Category Title]

Brief description of what this rule covers.

## Rule 1: [Title]

[Rule content with examples]

## Rule 2: [Title]

[Rule content with examples]
```

### Activation Modes

Rules can be activated in different ways:

| Mode | Frontmatter | Description |
|------|-------------|-------------|
| **Manual** | `activation: manual` | Activated via @mention in input (e.g., `@git-commit`) |
| **Always On** | `activation: always_on` | Always applied to all conversations |
| **Model Decision** | `activation: model_decision` | Model decides based on `description` field |
| **Glob** | `activation: glob` | Applied to files matching `globs` patterns |

#### Examples

**Always On** (recommended for general rules):
```yaml
---
activation: always_on
---
```

**Manual** (for specific workflows):
```yaml
---
activation: manual
---
```

**Model Decision** (context-dependent):
```yaml
---
activation: model_decision
description: Apply when working with git commits or version control
---
```

**Glob** (file-type specific):
```yaml
---
activation: glob
globs: ["*.ts", "*.tsx", "src/**/*.js"]
---
```

### @Mentions (File References)

Reference other files in rules using `@filename`:

| Path Type | Example | Resolution |
|-----------|---------|------------|
| Relative | `@../shared/common.md` | Relative to rule file location |
| Absolute | `@/docs/api.md` | First tries true absolute path, then workspace-relative |
| Workspace | `@app/types.ts` | Relative to workspace/repository root |

#### Use Cases

**Referencing shared documentation:**
```markdown
For API conventions, see @/docs/api-guidelines.md
```

**Including type definitions:**
```markdown
All API responses must follow the types in @app/types/api.types.ts
```

**Linking related rules:**
```markdown
See also: @coding-style.md for naming conventions
```

### Creating Rules

1. Check if `.agent/rules/` directory exists, create if not
2. Check if a file for this category already exists
3. If exists: append new rules to the file
4. If not: create new file with proper structure

Overview

This skill helps you create, edit, validate, and organize user rules that customize AI behavior for projects and personal preferences. It produces clear, actionable rule files, formats them with metadata, and places them in the .agent/rules/ directory for consistent application. Use it to enforce coding standards, workflow practices, naming, security, and documentation rules.

How this skill works

The skill guides you through a short workflow: define the rule purpose, pick a category, draft a specific actionable instruction with examples and exceptions, and choose an activation mode. It validates rules against a checklist (clarity, scope, examples, exceptions, and conflicts), formats the rule with YAML frontmatter, and saves or appends the file under .agent/rules/ using kebab-case filenames. It also suggests organization strategies and activation modes like always_on, manual, model_decision, or glob.

When to use it

  • You want to create a new project-wide policy (coding style, testing, or security).
  • You need a personal preference rule for AI responses (tone, terminology, or language).
  • You must update or append an existing rule without overwriting others.
  • You want to validate a rule for clarity, scope, and exceptions before saving.
  • You need to organize many rules by category, priority, or scope.

Best practices

  • Write rules in imperative form and keep instructions specific and actionable.
  • Include a short example of correct usage and a counterexample when helpful.
  • Define exceptions explicitly and note the rule's applicable scope or file globs.
  • Use YAML frontmatter with activation mode and an optional description for model_decision.
  • Name files in kebab-case and group related rules under clear headers in one file per category.

Example use cases

  • Create a coding-style rule that enforces 2-space indentation and includes a correct/incorrect snippet.
  • Add a git-commit.md rule that prescribes commit message structure and examples.
  • Append a security.md rule requiring input validation and secrets handling guidance.
  • Create a language preference rule forcing responses in plain English with specific terminology.
  • Set a glob-activated rule for TypeScript files to enforce filename and export conventions.

FAQ

Where are rules stored?

Rules are saved under the .agent/rules/ directory with one file per rule category using kebab-case filenames.

How do I make a rule always applied?

Set activation: always_on in the YAML frontmatter so the rule is applied to all conversations.