trae-rules-writer
Trae Rules Writer
Create rules that solve specific problems — not generic rules. Analyzes a project's structure and conventions, then designs a rule to constrain AI behavior. Always confirms with the user via AskUserQuestion before generating any files.
Core Principle: Understand the problem first, analyze the project second, design the rule third, generate only after user confirms.
When to Use
Invoke when:
- User says "create a rule", "create rules for...", "set up code style"
- User says "make AI always...", "enforce naming convention", "configure AI behavior"
- User references
.trae/rules/...or uses#RuleNamesyntax - User wants to constrain AI behavior for a specific project or file pattern
Do NOT invoke when:
- User wants to create a skill → delegate to
project-skill-writer - User wants to create an agent → delegate to
project-agent-writer - User wants to install an existing skill → delegate to
project-skill-installer - User is asking about Trae rules documentation (answer directly, no generation needed)
Prerequisites
- Node.js >= 18
- Trae IDE (with
.trae/rules/support)
Workflow
[L1: Problem Understanding]
↓
[L2: Project Analysis] ← parallel sub-agents
↓
[L3: Rule Design]
↓
[L4: Confirmation] ← AskUserQuestion (MUST confirm)
↓
[L5: Generation & Verification]
L1: Problem Understanding
Extract what the user needs — do NOT ask "what rule do you want?" Instead, infer from their problem:
Problem Classification
| Problem Pattern | Rule Type | Application Mode | Example |
|---|---|---|---|
| "AI keeps using wrong naming" | Convention | File-Specific (globs) |
camelCase for .ts, snake_case for .py |
| "AI should always do X" | Behavioral | Always (alwaysApply: true) |
Always use project's logging library |
| "AI ignores our architecture" | Structural | Intelligent (description) |
Enforce layered architecture boundaries |
| "AI generates wrong imports" | Style | File-Specific (globs) |
Use @/ path aliases in .tsx files |
| "I want to toggle a rule manually" | Manual | Manual (#RuleName) |
Ad-hoc code review checklist |
Extract Rule Specifications
From the user's problem, extract:
- Problem: What the AI is doing wrong (or should start doing)
- Scope: Which files or contexts the rule applies to
- Behavior: What the AI should do differently
- Exceptions: Any cases where the rule should NOT apply
L2: Project Analysis
Scan the project to understand context. Launch these agents in parallel via the Task tool:
| Agent | Purpose | Tool Invocation |
|---|---|---|
| Project Scanner | Structure, existing rules, patterns | Task(subagent_type="search", query="...") |
| Convention Detector | Naming, style, and pattern conventions | Task(subagent_type="search", query="...") |
Detection Targets
| Signal | What to Look For | Tool |
|---|---|---|
| Language | File extensions (.ts, .py, .swift, .go) |
Glob |
| Framework | package.json deps, Podfile, go.mod, Cargo.toml | Read |
| Existing Rules | .trae/rules/*.md files and their frontmatter |
Glob + Read |
| Code Style | ESLint, Prettier, EditorConfig, Ruff configs | Glob |
| Naming Patterns | Variable casing, file naming, directory structure | Grep |
| Architecture | Layering, module boundaries, import patterns | LS + Grep |
Analysis Output
Project: {name}
Languages: {detected languages}
Existing Rules: {list with application modes, or "none"}
Code Style Tools: {linters, formatters}
Conventions: {naming, imports, architecture patterns}
Conflicts: {any existing rules that overlap with the proposed rule}
L3: Rule Design
Based on Problem (L1) + Analysis (L2), design the rule:
Application Mode Selection
Refer to Application Modes and Rule Types for detailed guidance.
| Mode | When to Use | Frontmatter |
|---|---|---|
| Always | Rule applies to every AI interaction | alwaysApply: true |
| File-Specific | Rule applies only to certain file types | globs: *.tsx,*.ts + alwaysApply: false |
| Intelligent | AI decides when rule is relevant based on description | description: "..." + alwaysApply: false |
| Manual | User explicitly invokes with #RuleName |
No frontmatter, use #RuleName |
Design Spec
Rule: {name}
Problem: {user's problem in their words}
Application Mode: {Always|File-Specific|Intelligent|Manual}
Scope: {which files/contexts}
Content Summary:
- {constraint 1}
- {constraint 2}
Frontmatter:
description: {when this rule applies}
globs: {file patterns, if applicable}
alwaysApply: {true|false}
File to create:
- .trae/rules/{rule-name}.md
Design Principles
- Single Problem — one rule = one problem solved
- Convention-Aligned — use project's existing style tools as the source of truth
- Minimal Scope — apply rule to the narrowest file set that covers the problem
- No Conflicts — verify the new rule does not contradict existing rules
Critical Format Rules
| Wrong | Correct |
|---|---|
globs: "*.ts" |
globs: *.ts,*.tsx |
globs: ["*.ts"] |
globs: *.ts |
/Users/.../src/ |
src/ |
Missing description |
Always include description |
Both alwaysApply: true AND globs: active |
Use one or the other |
L4: Confirmation (MUST USE AskUserQuestion)
CRITICAL: Before generating ANY files, present the design via AskUserQuestion.
AskUserQuestion Call
Use AskUserQuestion with:
{
"questions": [{
"question": "I've designed this rule based on your project. Should I create it?",
"header": "Rule",
"multiSelect": false,
"options": [
{
"label": "Create {rule-name} (Recommended)",
"description": "{application-mode} rule — {1-sentence behavior}. Output: .trae/rules/{rule-name}.md"
},
{
"label": "Adjust design",
"description": "Let me refine the rule design before generating"
},
{
"label": "Skip",
"description": "Don't create a rule right now"
}
]
}]
}
Rules:
- Always show the designed rule name and application mode
- Include the output path so user knows where the file goes
- If multiple application modes are valid, offer alternatives:
{
"questions": [{
"question": "This rule could work in different modes. Which fits best?",
"header": "Application mode",
"multiSelect": false,
"options": [
{
"label": "Always-on rule (Recommended)",
"description": "alwaysApply: true — active in every AI interaction"
},
{
"label": "File-specific rule",
"description": "globs: *.tsx — only active when matching files are open"
},
{
"label": "Skip",
"description": "Don't create a rule right now"
}
]
}]
}
- Never generate files without user confirmation
- If user says "Adjust design", loop back to L3 with feedback
L5: Generation & Verification
After user confirms:
Generation
- Determine output path:
.trae/rules/in the target project root - Create rule file using
scripts/init_rule.cjsor rule.md.template - Fill in frontmatter (
description,globs,alwaysApply) from L3 design - Write rule content — actionable constraints, not vague guidelines
- Ensure all paths in rule content are project-relative, never absolute
Generation Command
node scripts/init_rule.cjs \
--skill-dir <this-skill-dir> \
--name <rule-name> \
--description "<when-this-rule-applies>" \
--output-dir <project>/.trae/rules/
Fallback: If init_rule.cjs fails or the template doesn't fit, write the .md file directly following the template structure.
Verification
Run Quality Validator against the generated rule.
Minimum checks before delivery:
-
globsformat: comma-separated, no quotes, no arrays - No absolute paths anywhere in the rule
-
descriptionis present and describes when the rule applies -
alwaysApplyandglobsare not both active simultaneously - No conflicts with existing rules (from L2 analysis)
- Rule content is actionable (specific constraints, not vague advice)
- Content is in English
Delivery Report
Created rule:
Name: {rule-name}
Mode: {Always|File-Specific|Intelligent|Manual}
Path: {project-relative path}
Frontmatter:
description: {value}
globs: {value, if applicable}
alwaysApply: {value}
To use: {instructions based on application mode}
Error Handling
| Issue | Solution |
|---|---|
| User's problem is too vague | Infer the most likely rule type from context, confirm at L4 |
| Multiple valid application modes | Show alternatives in AskUserQuestion, let user pick |
No .trae/rules/ directory exists |
Create .trae/rules/ in the project root |
| User requests skill/agent creation | Route to project-skill-writer or project-agent-writer |
| User says "Adjust design" at L4 | Loop back to L3, incorporate feedback |
| Rule contains absolute paths | Reject, convert to project-relative paths |
| Rule conflicts with existing rule | Show comparison, ask user whether to merge, replace, or rename |
globs format is wrong |
Auto-fix: remove quotes, flatten arrays, use comma separation |
| Project has no detectable conventions | Fall back to language defaults, note assumptions in delivery report |
Boundary Enforcement
This skill ONLY handles:
- Analyzing project for rule design context
- Designing rules based on user problems
- Confirming design via AskUserQuestion
- Generating
.trae/rules/*.mdfiles to project-relative paths - Verifying generated rules against quality gates
This skill does NOT handle:
- Creating skills →
project-skill-writer - Creating agents →
project-agent-writer - Installing skills →
project-skill-installer - Global rule installation (always project-scoped)
- Editing Trae IDE settings or configuration files
Agents
- Project Scanner: Structure, existing rules, and pattern analysis
- Convention Detector: Naming, style, and convention extraction
- Quality Validator: Post-generation rule validation
References
- Rule Types: Choose rule type based on problem
- Application Modes: All mode examples with frontmatter
- Rule Template: Scaffold for new rules
- Trae Rules Docs: Official documentation snapshot
More from learnwy/skills
knowledge-consolidation
Use this skill when the user wants to save, summarize, or persist knowledge from the current AI conversation into structured documents. Captures debugging breakthroughs, architecture decisions, patterns, and lessons learned. Triggers on: '总结一下', '记录下来', 'save this knowledge', 'document this', 'we figured it out', 'that was hard to solve', 'remember this', 'write this down', or when a hard-won insight should be preserved for future sessions. Saves to .trae/knowledges/, .claude/knowledges/, or .cursor/knowledges/ based on AI IDE.
59trae-skill-writer
Create Trae IDE skills (SKILL.md files) for reusable AI capabilities. Use when user wants to: create a skill, make a reusable workflow, automate repetitive tasks, turn a conversation into a skill, or encapsulate a process for AI to follow. Triggers on: '创建 skill', 'write a SKILL.md', 'make this reusable', '.trae/skills/', 'I keep doing the same thing every time'. Do NOT use for rules (use trae-rules-writer) or agents (use trae-agent-writer).
31english-prompt-optimizer
Optimize and restructure user prompts for better AI responses. Use when user writes in non-English (Chinese, Japanese, Korean, etc.), request is vague/unclear, or user asks to improve their prompt. Triggers on: '帮我', '请帮忙', 'お願い', any non-English complex request. Translates, restructures, and shows optimized prompt before proceeding.
29trae-agent-writer
Create subagent definitions (agent.md files) for independent AI workers. Use when user wants to: create an agent, build a grader/evaluator, make an A/B comparator, spawn independent workers, or create something that runs in isolation. Triggers on: '创建 agent', 'subagent', 'grade outputs independently', 'blind comparison', 'run this in parallel'. Do NOT use for skills (use trae-skill-writer) or rules (use trae-rules-writer).
29skill-finder
Discover, install, and manage AI assistant skills using npx skills CLI. Use when user wants to find a skill, install a skill, remove skills, list installed skills, or create new skills. Triggers on: 'find a skill', 'install skill', 'remove skill', 'list skills', 'how do I do X', 'is there a skill for'.
24ai-brain
Adaptive AI memory system. Triggers on: session start, 'remember', 'learn', 'what do you know about'. Combines episodic (sessions), semantic (facts/preferences), and procedural (patterns) memory. Gets smarter with use.
22