rule-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRule Creator
规则创建器
Create rule files in . Rules are auto-discovered by Claude Code and loaded into agent context.
.claude/rules/在.claude/rules/目录下创建规则文件。规则会被Claude Code自动发现并加载到Agent上下文环境中。
Step 0: Check for Existing Rule
步骤0:检查现有规则
Before creating, check if rule already exists:
bash
test -f .claude/rules/<rule-name>.md && echo "EXISTS" || echo "NEW"If EXISTS → invoke
Skill({ skill: "artifact-updater", args: "--type rule --path .claude/rules/<rule-name>.md --changes '...'" })If NEW → continue with Step 0.5.
创建前,请检查规则是否已存在:
bash
test -f .claude/rules/<rule-name>.md && echo "EXISTS" || echo "NEW"如果显示EXISTS → 调用
Skill({ skill: "artifact-updater", args: "--type rule --path .claude/rules/<rule-name>.md --changes '...'" })如果显示NEW → 继续步骤0.5。
Step 0.5: Companion Check
步骤0.5:配套检查
Before proceeding with creation, run the ecosystem companion check:
- Use from
companion-check.cjs.claude/lib/creators/companion-check.cjs - Call to identify companion artifacts
checkCompanions("rule", "{rule-name}") - Review the companion checklist — note which required/recommended companions are missing
- Plan to create or verify missing companions after this artifact is complete
- Include companion findings in post-creation integration notes
This step is informational (does not block creation) but ensures the full artifact ecosystem is considered.
在开始创建前,运行生态系统配套检查:
- 使用.claude/lib/creators/companion-check.cjs中的
companion-check.cjs - 调用来识别配套工件
checkCompanions("rule", "{rule-name}") - 查看配套检查清单——记录缺失的必需/推荐配套项
- 计划在完成此工件后创建或验证缺失的配套项
- 在创建后集成说明中包含配套检查结果
此步骤为信息性步骤(不会阻止创建),但确保考虑到完整的工件生态系统。
When to Use
使用场景
- Creating project-specific coding guidelines
- Documenting framework conventions
- Establishing team standards
- Defining workflow protocols
- 创建项目特定的编码指南
- 记录框架约定
- 建立团队标准
- 定义工作流协议
Rule File Format
规则文件格式
Rules are simple markdown files:
markdown
undefined规则是简单的Markdown文件:
markdown
undefinedRule Name
规则名称
Section 1
章节1
- Guideline 1
- Guideline 2
- 指南1
- 指南2
Section 2
章节2
- Guideline 3
- Guideline 4
**Example: testing.md**
```markdown- 指南3
- 指南4
**示例:testing.md**
```markdownTesting
测试
Test-Driven Development
测试驱动开发
- Use TDD for new features and bug fixes (Red-Green-Refactor cycle)
- Write failing test first, then minimal code to pass, then refactor
- Never write production code without a failing test first
- 对新功能和错误修复使用TDD(红-绿-重构循环)
- 先编写失败的测试,再编写最小化代码使其通过,最后进行重构
- 绝不先编写生产代码而不先编写失败的测试
Test Organization
测试组织
- Add unit tests for utilities and business logic
- Add integration tests for API boundaries
- Keep tests deterministic and isolated (no shared state)
- Place test files in directory mirroring source structure
tests/
undefined- 为工具类和业务逻辑添加单元测试
- 为API边界添加集成测试
- 保持测试的确定性和隔离性(无共享状态)
- 将测试文件放在与源代码结构镜像的tests/目录中
undefinedCreation Workflow
创建工作流
Step 1: Validate Inputs
步骤1:验证输入
javascript
// Validate rule name (lowercase, hyphens only)
const ruleName = args.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
// Validate content is not empty
if (!args.content || args.content.trim().length === 0) {
throw new Error('Rule content cannot be empty');
}javascript
// 验证规则名称(仅小写字母、连字符)
const ruleName = args.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
// 验证内容不为空
if (!args.content || args.content.trim().length === 0) {
throw new Error('Rule content cannot be empty');
}Step 2: Create Rule File
步骤2:创建规则文件
javascript
const rulePath = `.claude/rules/${ruleName}.md`;
// Format content as markdown
const content = args.content.startsWith('#')
? args.content
: `# ${ruleName.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}\n\n${args.content}`;
await writeFile(rulePath, content);javascript
const rulePath = `.claude/rules/${ruleName}.md`;
// 将内容格式化为Markdown
const content = args.content.startsWith('#')
? args.content
: `# ${ruleName.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}\n\n${args.content}`;
await writeFile(rulePath, content);Step 3: Verify Auto-Discovery
步骤3:验证自动发现
Rules in are automatically loaded by Claude Code. No manual registration needed.
.claude/rules/javascript
// Verify file was created
const fileExists = await exists(rulePath);
if (!fileExists) {
throw new Error('Rule file creation failed');
}.claude/rules/目录下的规则会被Claude Code自动加载,无需手动注册。
javascript
// 验证文件是否创建成功
const fileExists = await exists(rulePath);
if (!fileExists) {
throw new Error('Rule file creation failed');
}Step 4: Run Post-Creation Integration
步骤4:运行创建后集成
javascript
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
await runIntegrationChecklist('rule', rulePath);
await queueCrossCreatorReview('rule', rulePath, {
artifactName: ruleName,
createdBy: 'rule-creator',
});javascript
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
await runIntegrationChecklist('rule', rulePath);
await queueCrossCreatorReview('rule', rulePath, {
artifactName: ruleName,
createdBy: 'rule-creator',
});Post-Creation Integration
创建后集成
After rule creation, run integration checklist:
javascript
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
// 1. Run integration checklist
const result = await runIntegrationChecklist('rule', '.claude/rules/<rule-name>.md');
// 2. Queue cross-creator review
await queueCrossCreatorReview('rule', '.claude/rules/<rule-name>.md', {
artifactName: '<rule-name>',
createdBy: 'rule-creator',
});
// 3. Review impact report
// Check result.mustHave for failures - address before marking completeIntegration verification:
- Rule file created in
.claude/rules/ - Rule is auto-discovered by Claude Code
- Rule content is clear and actionable
- No conflicts with existing rules
规则创建完成后,运行集成检查清单:
javascript
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
// 1. 运行集成检查清单
const result = await runIntegrationChecklist('rule', '.claude/rules/<rule-name>.md');
// 2. 排队跨创建器审核
await queueCrossCreatorReview('rule', '.claude/rules/<rule-name>.md', {
artifactName: '<rule-name>',
createdBy: 'rule-creator',
});
// 3. 查看影响报告
// 检查result.mustHave中的失败项 - 在标记完成前解决集成验证:
- 规则文件已在.claude/rules/目录下创建
- 规则已被Claude Code自动发现
- 规则内容清晰且可操作
- 与现有规则无冲突
Usage Examples
使用示例
Create Code Standards Rule
创建代码标准规则
javascript
Skill({
skill: 'rule-creator',
args: `--name code-standards --content "# Code Standardsjavascript
Skill({
skill: 'rule-creator',
args: `--name code-standards --content "# Code StandardsOrganization
Organization
- Prefer small, cohesive files over large ones
- Keep interfaces narrow; separate concerns by feature
- Prefer small, cohesive files over large ones
- Keep interfaces narrow; separate concerns by feature
Style
Style
- Favor immutability; avoid in-place mutation
- Validate inputs and handle errors explicitly"`, });
undefined- Favor immutability; avoid in-place mutation
- Validate inputs and handle errors explicitly"`, });
undefinedCreate Git Workflow Rule
创建Git工作流规则
javascript
Skill({
skill: 'rule-creator',
args: `--name git-workflow --content "# Git Workflowjavascript
Skill({
skill: 'rule-creator',
args: `--name git-workflow --content "# Git WorkflowCommit Guidelines
Commit Guidelines
- Keep changes scoped and reviewable
- Use conventional commits: feat:, fix:, refactor:, docs:, chore:
- Keep changes scoped and reviewable
- Use conventional commits: feat:, fix:, refactor:, docs:, chore:
Branch Workflow
Branch Workflow
- Create feature branches from main
- Never force-push to main/master"`, });
undefined- Create feature branches from main
- Never force-push to main/master"`, });
undefinedRelated Skills
相关技能
- - Update existing rules
artifact-updater - - Create detailed workflows (for complex guidance)
skill-creator
- - 更新现有规则
artifact-updater - - 创建详细工作流(用于复杂指导)
skill-creator
Memory Protocol (MANDATORY)
内存协议(强制性)
Before starting:
Read
.claude/context/memory/learnings.mdAfter completing:
- New rule pattern →
.claude/context/memory/learnings.md - Rule creation issue →
.claude/context/memory/issues.md - Guideline decision →
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
开始前:
读取.claude/context/memory/learnings.md
完成后:
- 新规则模式 → .claude/context/memory/learnings.md
- 规则创建问题 → .claude/context/memory/issues.md
- 指南决策 → .claude/context/memory/decisions.md
假设会被中断:如果未记录在内存中,则视为未发生。
Ecosystem Alignment Contract (MANDATORY)
生态系统对齐协议(强制性)
This creator skill is part of a coordinated creator ecosystem. Any artifact created here must align with and validate against related creators:
- for ownership and execution paths
agent-creator - for capability packaging and assignment
skill-creator - for executable automation surfaces
tool-creator - for enforcement and guardrails
hook-creator - and
rule-creatorfor policy and static checkssemgrep-rule-creator - for standardized scaffolds
template-creator - for orchestration and phase gating
workflow-creator - for user/operator command UX
command-creator
此创建器技能是协调创建器生态系统的一部分。在此创建的任何工件必须与相关创建器对齐并验证:
- 用于所有权和执行路径
agent-creator - 用于能力打包和分配
skill-creator - 用于可执行自动化界面
tool-creator - 用于实施和防护措施
hook-creator - 和
rule-creator用于策略和静态检查semgrep-rule-creator - 用于标准化脚手架
template-creator - 用于编排和阶段门控
workflow-creator - 用于用户/操作员命令UX
command-creator
Cross-Creator Handshake (Required)
跨创建器握手(必需)
Before completion, verify all relevant handshakes:
- Artifact route exists in and related routing docs.
.claude/CLAUDE.md - Discovery/registry entries are updated (catalog/index/registry as applicable).
- Companion artifacts are created or explicitly waived with reason.
- passes for the created artifact.
validate-integration.cjs - Skill index is regenerated when skill metadata changes.
完成前,验证所有相关握手:
- 工件路由在.claude/CLAUDE.md和相关路由文档中存在。
- 发现/注册表项已更新(适用的目录/索引/注册表)。
- 配套工件已创建或明确说明理由后豁免。
- 所创建的工件通过验证。
validate-integration.cjs - 当技能元数据更改时重新生成技能索引。
Research Gate (Exa First, arXiv Fallback)
研究门(优先使用Exa,arXiv作为备选)
For new patterns, templates, or workflows, research is mandatory:
- Use Exa first for implementation and ecosystem patterns.
- If Exa is insufficient, use plus arXiv references.
WebFetch - Record decisions, constraints, and non-goals in artifact references/docs.
- Keep updates minimal and avoid overengineering.
对于新模式、模板或工作流,研究是强制性的:
- 优先使用Exa查找实现和生态系统模式。
- 如果Exa不足,使用加上arXiv参考资料。
WebFetch - 在工件参考/文档中记录决策、约束和非目标。
- 保持更新最小化,避免过度工程。
Regression-Safe Delivery
回归安全交付
- Follow strict RED -> GREEN -> REFACTOR for behavior changes.
- Run targeted tests for changed modules.
- Run lint/format on changed files.
- Keep commits scoped by concern (logic/docs/generated artifacts).
- 对行为更改严格遵循RED -> GREEN -> REFACTOR。
- 对更改的模块运行针对性测试。
- 对更改的文件运行lint/格式化。
- 按关注点(逻辑/文档/生成的工件)保持提交的范围。