skills/trae-rules-writer/SKILL.md
当用户需要创建或更新 Trae IDE 规则(.trae/rules/*.md)以约束 AI 行为时使用此技能。适用于:代码风格强制、命名约定、提交信息格式,或让 AI 始终遵循特定模式。不适用于技能(请使用 project-skill-writer)或智能体(请使用 project-agent-writer)。触发词:'创建规则'、'添加规则'、'设置代码风格'、'强制约定'、'配置 AI 行为'、'AI 规则'、'始终做 X',或当用户需要跨会话一致的 AI 行为时。
npx skillsauth add learnwy/skills trae-rules-writerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
创建解决具体问题的规则——而非泛化规则。分析项目的结构和约定,然后设计一条约束 AI 行为的规则。始终在生成文件前通过 AskUserQuestion 与用户确认。
核心原则:先理解问题,再分析项目,第三步设计规则,仅在用户确认后生成。
适合调用:
.trae/rules/... 或使用 #RuleName 语法不适合调用:
project-skill-writerproject-agent-writerproject-skill-installer.trae/rules/)[L1: 问题理解]
↓
[L2: 项目分析] ← 并行子智能体
↓
[L3: 规则设计]
↓
[L4: 确认] ← AskUserQuestion(必须确认)
↓
[L5: 生成 & 验证]
提取用户需要什么——不要问"你想要什么规则?"而是从问题推断:
| 问题模式 | 规则类型 | 应用模式 | 示例 |
|---------|---------|---------|------|
| "AI 总用错误的命名" | 约定 | 文件特定(globs) | .ts 用 camelCase,.py 用 snake_case |
| "AI 应该始终做 X" | 行为 | 始终应用(alwaysApply: true) | 始终使用项目的日志库 |
| "AI 忽略我们的架构" | 结构 | 智能(description) | 强制分层架构边界 |
| "AI 生成错误的导入" | 风格 | 文件特定(globs) | 在 .tsx 文件中使用 @/ 路径别名 |
| "我想手动切换规则" | 手动 | 手动(#RuleName) | 临时代码审查清单 |
从用户的问题中提取:
扫描项目以理解上下文。通过 Task 工具并行启动这些智能体:
| 智能体 | 用途 | 工具调用 |
|-------|------|---------|
| 项目扫描器 | 结构、现有规则、模式 | Task(subagent_type="search", query="...") |
| 约定检测器 | 命名、风格和模式约定 | Task(subagent_type="search", query="...") |
| 信号 | 查找内容 | 工具 |
|------|---------|------|
| 语言 | 文件扩展名(.ts、.py、.swift、.go) | Glob |
| 框架 | package.json deps、Podfile、go.mod、Cargo.toml | Read |
| 现有规则 | .trae/rules/*.md 文件及其 frontmatter | Glob + Read |
| 代码风格 | ESLint、Prettier、EditorConfig、Ruff 配置 | Glob |
| 命名模式 | 变量大小写、文件命名、目录结构 | Grep |
| 架构 | 分层、模块边界、导入模式 | LS + Grep |
项目:{name}
语言:{检测到的语言}
现有规则:{列出应用模式,或"无"}
代码风格工具:{检查器、格式化器}
约定:{命名、导入、架构模式}
冲突:{与提议规则重叠的现有规则}
基于问题(L1)+ 分析(L2),设计规则:
参考应用模式和规则类型获取详细指导。
| 模式 | 适用场景 | Frontmatter |
|------|---------|-------------|
| 始终应用 | 规则适用于每次 AI 交互 | alwaysApply: true |
| 文件特定 | 规则仅适用于特定文件类型 | globs: *.tsx,*.ts + alwaysApply: false |
| 智能 | AI 根据描述判断规则是否相关 | description: "..." + alwaysApply: false |
| 手动 | 用户通过 #RuleName 显式调用 | 无 frontmatter,使用 #RuleName |
规则:{name}
问题:{用户原话描述的问题}
应用模式:{始终应用|文件特定|智能|手动}
范围:{哪些文件/上下文}
内容摘要:
- {约束 1}
- {约束 2}
Frontmatter:
description: {此规则何时应用}
globs: {文件模式,如适用}
alwaysApply: {true|false}
要创建的文件:
- .trae/rules/{rule-name}.md
| 错误写法 | 正确写法 |
|---------|---------|
| globs: "*.ts" | globs: *.ts,*.tsx |
| globs: ["*.ts"] | globs: *.ts |
| /Users/.../src/ | src/ |
| 缺少 description | 始终包含 description |
| alwaysApply: true 和 globs: 同时激活 | 只用其一 |
关键:在生成任何文件之前,通过 AskUserQuestion 展示设计。
使用 AskUserQuestion:
{
"questions": [{
"question": "我已根据您的项目设计了此规则。是否创建?",
"header": "规则",
"multiSelect": false,
"options": [
{
"label": "创建 {rule-name}(推荐)",
"description": "{应用模式}规则 — {1 句话行为描述}。输出:.trae/rules/{rule-name}.md"
},
{
"label": "调整设计",
"description": "在生成前让我调整规则设计"
},
{
"label": "跳过",
"description": "暂不创建规则"
}
]
}]
}
规则:
{
"questions": [{
"question": "此规则可以用不同模式运行。哪种最合适?",
"header": "应用模式",
"multiSelect": false,
"options": [
{
"label": "始终启用规则(推荐)",
"description": "alwaysApply: true — 在每次 AI 交互中生效"
},
{
"label": "文件特定规则",
"description": "globs: *.tsx — 仅当匹配文件参与时生效"
},
{
"label": "跳过",
"description": "暂不创建规则"
}
]
}]
}
用户确认后:
.trae/rules/scripts/cli.cjs init 或 rule.md.template 创建规则文件description、globs、alwaysApply)node scripts/cli.cjs init \
--skill-dir <this-skill-dir> \
--name <rule-name> \
--description "<when-this-rule-applies>" \
--output-dir <project>/.trae/rules/
回退方案:如果 cli.cjs init 失败或模板不适用,直接按模板结构编写 .md 文件。
对生成的规则运行质量验证器。
交付前的最低检查:
globs 格式:逗号分隔,无引号,无数组description 存在且描述了规则何时应用alwaysApply 和 globs 不同时激活创建的规则:
名称:{rule-name}
模式:{始终应用|文件特定|智能|手动}
路径:{项目相对路径}
Frontmatter:
description: {value}
globs: {value, 如适用}
alwaysApply: {value}
使用方式:{基于应用模式的说明}
| 问题 | 解决方案 |
|------|---------|
| 用户的问题太模糊 | 从上下文推断最可能的规则类型,在 L4 确认 |
| 多种有效的应用模式 | 在 AskUserQuestion 中展示备选,让用户选择 |
| 不存在 .trae/rules/ 目录 | 在项目根目录创建 .trae/rules/ |
| 用户请求创建技能/智能体 | 转路由到 project-skill-writer 或 project-agent-writer |
| 用户在 L4 说"调整设计" | 回到 L3,纳入反馈 |
| 规则包含绝对路径 | 拒绝,转换为项目相对路径 |
| 规则与现有规则冲突 | 展示对比,询问用户是合并、替换还是重命名 |
| globs 格式错误 | 自动修复:去除引号,展平数组,使用逗号分隔 |
| 项目无可检测的约定 | 回退到语言默认值,在交付报告中注明假设 |
此技能仅处理:
.trae/rules/*.md 文件生成到项目相对路径此技能不处理:
project-skill-writerproject-agent-writerproject-skill-installertools
Fallback skill when no project-specific one matches. Provides 10 battle-tested software-engineering methodology agents: problem-definer (Weinberg), story-mapper (Patton), spec-by-example (Adzic), domain-modeler (DDD/Evans), responsibility-modeler (CRC/Wirfs-Brock), architecture-advisor (Bass), tdd-coach (Beck), refactoring-guide (Fowler), legacy-surgeon (Feathers), test-strategist (Crispin). Use when user asks about DDD, TDD, refactoring, story mapping, test strategy, or software-architecture quality attributes.
development
Use when the user wants to build, implement, or develop a feature. Orchestrates evidence-driven Spec-Driven Development. Default lifecycle is `lite` (INIT → IMPLEMENTING → TESTING → DONE); auto-promote to `standard` or `full` when scope, risk, or AC traceability demands it. Triggers: 'develop feature', 'implement this', 'build feature', 'add module', 'fix bug', '开发功能', '实现这个'.
documentation
当用户需要创建、更新或设计项目级技能(.agents/skills/*/SKILL.md)时使用此技能。Analyzes the user's problem and project context to design reusable skill solutions. 触发词:'创建技能'、'编写技能'、'构建技能'、'添加技能'、'更新技能'、'项目技能'、'新建技能'、'设计技能', or when the user describes a repetitive workflow that should be captured as a reusable AI skill.
tools
Use this skill when the user wants to install, add, or configure a skill in a project. Analyze the project's tech stack and workflow, then recommend and install the best-matching skill. Triggers: 'install skill', 'add skill', 'configure skill', 'set up skill', 'enable skill', 'use skill in project', 'project skill', or when the user asks how to bring an existing skill capability into the current workspace.