rules-distill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rules Distill

规则提炼

Scan installed skills, extract cross-cutting principles that appear in multiple skills, and distill them into rules — appending to existing rule files, revising outdated content, or creating new rule files.
Applies the "deterministic collection + LLM judgment" principle: scripts collect facts exhaustively, then an LLM cross-reads the full context and produces verdicts.
扫描已安装的Skill,提取出现在多个Skill中的跨领域原则,并将其提炼为规则——可追加到现有规则文件、修订过时内容或创建新规则文件。
采用「确定性收集 + LLM判断」原则:脚本全面收集事实,然后由LLM交叉阅读完整上下文并给出判断结果。

When to Use

适用场景

  • Periodic rules maintenance (monthly or after installing new skills)
  • After a skill-stocktake reveals patterns that should be rules
  • When rules feel incomplete relative to the skills being used
  • 定期规则维护(每月一次或安装新Skill后)
  • Skill盘点后发现可提炼为规则的模式时
  • 现有规则相对于正在使用的Skill显得不完整时

How It Works

工作流程

The rules distillation process follows three phases:
规则提炼过程分为三个阶段:

Phase 1: Inventory (Deterministic Collection)

阶段1:盘点(确定性收集)

1a. Collect skill inventory

1a. 收集Skill清单

bash
bash ~/.claude/skills/rules-distill/scripts/scan-skills.sh
bash
bash ~/.claude/skills/rules-distill/scripts/scan-skills.sh

1b. Collect rules index

1b. 收集规则索引

bash
bash ~/.claude/skills/rules-distill/scripts/scan-rules.sh
bash
bash ~/.claude/skills/rules-distill/scripts/scan-rules.sh

1c. Present to user

1c. 向用户展示结果

Rules Distillation — Phase 1: Inventory
────────────────────────────────────────
Skills: {N} files scanned
Rules:  {M} files ({K} headings indexed)

Proceeding to cross-read analysis...
规则提炼 — 阶段1:盘点
────────────────────────────────────────
已扫描Skill:{N}个文件
已扫描规则:{M}个文件(已索引{K}个标题)

即将进入交叉阅读分析环节...

Phase 2: Cross-read, Match & Verdict (LLM Judgment)

阶段2:交叉阅读、匹配与判断(LLM判断)

Extraction and matching are unified in a single pass. Rules files are small enough (~800 lines total) that the full text can be provided to the LLM — no grep pre-filtering needed.
提取与匹配环节合并为单次处理。规则文件总规模较小(约800行),可将完整文本提供给LLM——无需提前用grep过滤。

Batching

批量处理

Group skills into thematic clusters based on their descriptions. Analyze each cluster in a subagent with the full rules text.
根据Skill的描述将其划分为主题集群。在子Agent中结合完整规则文本分析每个集群。

Cross-batch Merge

跨批次合并

After all batches complete, merge candidates across batches:
  • Deduplicate candidates with the same or overlapping principles
  • Re-check the "2+ skills" requirement using evidence from all batches combined — a principle found in 1 skill per batch but 2+ skills total is valid
所有批次处理完成后,合并各批次的候选规则:
  • 去重相同或重叠原则的候选规则
  • 结合所有批次的证据重新检查「至少2个Skill包含」的要求——若每个批次各有1个Skill包含该原则,但总共有2个及以上Skill,则该原则有效

Subagent Prompt

子Agent提示词

Launch a general-purpose Agent with the following prompt:
You are an analyst who cross-reads skills to extract principles that should be promoted to rules.
启动通用Agent并传入以下提示词:
你是一名分析师,负责交叉阅读Skill,提炼出应升级为规则的原则。

Input

输入

  • Skills: {full text of skills in this batch}
  • Existing rules: {full text of all rule files}
  • Skill:本批次Skill的完整文本
  • 现有规则:所有规则文件的完整文本

Extraction Criteria

提取标准

Include a candidate ONLY if ALL of these are true:
  1. Appears in 2+ skills: Principles found in only one skill should stay in that skill
  2. Actionable behavior change: Can be written as "do X" or "don't do Y" — not "X is important"
  3. Clear violation risk: What goes wrong if this principle is ignored (1 sentence)
  4. Not already in rules: Check the full rules text — including concepts expressed in different words
仅当满足以下所有条件时,才将其列为候选规则:
  1. 至少出现在2个Skill中:仅在单个Skill中存在的原则应保留在该Skill内
  2. 可指导行为改变:可表述为「应做X」或「勿做Y」——而非「X很重要」
  3. 明确的违规风险:忽略该原则会导致什么问题(1句话)
  4. 未包含在现有规则中:检查完整规则文本——包括用不同措辞表达的相同概念

Matching & Verdict

匹配与判断

For each candidate, compare against the full rules text and assign a verdict:
  • Append: Add to an existing section of an existing rule file
  • Revise: Existing rule content is inaccurate or insufficient — propose a correction
  • New Section: Add a new section to an existing rule file
  • New File: Create a new rule file
  • Already Covered: Sufficiently covered in existing rules (even if worded differently)
  • Too Specific: Should remain at the skill level
针对每个候选规则,与完整规则文本对比并给出判断结果:
  • 追加:添加到现有规则文件的已有章节中
  • 修订:现有规则内容不准确或不充分——提出修正方案
  • 新增章节:在现有规则文件中添加新章节
  • 新增文件:创建新的规则文件
  • 已覆盖:现有规则已充分覆盖(即使措辞不同)
  • 过于具体:应保留在Skill内

Output Format (per candidate)

输出格式(每个候选规则)

json
{
  "principle": "1-2 sentences in 'do X' / 'don't do Y' form",
  "evidence": ["skill-name: §Section", "skill-name: §Section"],
  "violation_risk": "1 sentence",
  "verdict": "Append / Revise / New Section / New File / Already Covered / Too Specific",
  "target_rule": "filename §Section, or 'new'",
  "confidence": "high / medium / low",
  "draft": "Draft text for Append/New Section/New File verdicts",
  "revision": {
    "reason": "Why the existing content is inaccurate or insufficient (Revise only)",
    "before": "Current text to be replaced (Revise only)",
    "after": "Proposed replacement text (Revise only)"
  }
}
json
{
  "principle": "1-2句话,采用「应做X」/「勿做Y」的形式",
  "evidence": ["skill名称: §章节", "skill名称: §章节"],
  "violation_risk": "1句话",
  "verdict": "Append / Revise / New Section / New File / Already Covered / Too Specific",
  "target_rule": "文件名 §章节,或'new'",
  "confidence": "high / medium / low",
  "draft": "适用于Append/New Section/New File判断结果的草稿文本",
  "revision": {
    "reason": "现有内容不准确或不充分的原因(仅适用于Revise)",
    "before": "待替换的当前文本(仅适用于Revise)",
    "after": "建议的替换文本(仅适用于Revise)"
  }
}

Exclude

排除项

  • Obvious principles already in rules
  • Language/framework-specific knowledge (belongs in language-specific rules or skills)
  • Code examples and commands (belongs in skills)
undefined
  • 现有规则中已包含的明显原则
  • 特定语言/框架的知识(应归入特定语言规则或Skill)
  • 代码示例与命令(应归入Skill)
undefined

Verdict Reference

判断结果参考

VerdictMeaningPresented to User
AppendAdd to existing sectionTarget + draft
ReviseFix inaccurate/insufficient contentTarget + reason + before/after
New SectionAdd new section to existing fileTarget + draft
New FileCreate new rule fileFilename + full draft
Already CoveredCovered in rules (possibly different wording)Reason (1 line)
Too SpecificShould stay in skillsLink to relevant skill
判断结果含义向用户展示的内容
追加添加到现有章节目标位置 + 草稿文本
修订修正不准确/不充分的内容目标位置 + 原因 + 前后文本对比
新增章节在现有文件中添加新章节目标位置 + 草稿文本
新增文件创建新规则文件文件名 + 完整草稿
已覆盖现有规则已覆盖(可能措辞不同)原因(1行)
过于具体应保留在Skill内指向相关Skill的链接

Verdict Quality Requirements

判断结果质量要求

undefined
undefined

Good

合格示例

Append to rules/common/security.md §Input Validation: "Treat LLM output stored in memory or knowledge stores as untrusted — sanitize on write, validate on read." Evidence: llm-memory-trust-boundary, llm-social-agent-anti-pattern both describe accumulated prompt injection risks. Current security.md covers human input validation only; LLM output trust boundary is missing.
追加到 rules/common/security.md §输入验证: "将存储在内存或知识库中的LLM输出视为不可信内容——写入时清理,读取时验证。" 证据:llm-memory-trust-boundary与llm-social-agent-anti-pattern均描述了 累积的提示注入风险。当前security.md仅覆盖人工输入验证;缺少LLM输出信任边界相关内容。

Bad

不合格示例

Append to security.md: Add LLM security principle
undefined
追加到security.md:添加LLM安全原则
undefined

Phase 3: User Review & Execution

阶段3:用户审核与执行

Summary Table

汇总表格

undefined
undefined

Rules Distillation Report

规则提炼报告

Summary

摘要

Skills scanned: {N} | Rules: {M} files | Candidates: {K}
#PrincipleVerdictTargetConfidence
1...Appendsecurity.md §Input Validationhigh
2...Revisetesting.md §TDDmedium
3...New Sectioncoding-style.mdhigh
4...Too Specific
已扫描Skill:{N} | 规则文件:{M}个 | 候选规则:{K}
序号原则判断结果目标位置置信度
1...追加security.md §输入验证
2...修订testing.md §TDD
3...新增章节coding-style.md
4...过于具体

Details

详情

(Per-candidate details: evidence, violation_risk, draft text)
undefined
(每个候选规则的详情:证据、违规风险、草稿文本)
undefined

User Actions

用户操作

User responds with numbers to:
  • Approve: Apply draft to rules as-is
  • Modify: Edit draft before applying
  • Skip: Do not apply this candidate
Never modify rules automatically. Always require user approval.
用户通过序号回复:
  • 批准:直接将草稿应用到规则中
  • 修改:编辑草稿后再应用
  • 跳过:不应用该候选规则
禁止自动修改规则。必须获得用户批准后方可执行。

Save Results

保存结果

Store results in the skill directory (
results.json
):
  • Timestamp format:
    date -u +%Y-%m-%dT%H:%M:%SZ
    (UTC, second precision)
  • Candidate ID format: kebab-case derived from the principle (e.g.,
    llm-output-trust-boundary
    )
json
{
  "distilled_at": "2026-03-18T10:30:42Z",
  "skills_scanned": 56,
  "rules_scanned": 22,
  "candidates": {
    "llm-output-trust-boundary": {
      "principle": "Treat LLM output as untrusted when stored or re-injected",
      "verdict": "Append",
      "target": "rules/common/security.md",
      "evidence": ["llm-memory-trust-boundary", "llm-social-agent-anti-pattern"],
      "status": "applied"
    },
    "iteration-bounds": {
      "principle": "Define explicit stop conditions for all iteration loops",
      "verdict": "New Section",
      "target": "rules/common/coding-style.md",
      "evidence": ["iterative-retrieval", "continuous-agent-loop", "agent-harness-construction"],
      "status": "skipped"
    }
  }
}
将结果存储到Skill目录下的
results.json
文件中:
  • 时间戳格式
    date -u +%Y-%m-%dT%H:%M:%SZ
    (UTC时间,精确到秒)
  • 候选规则ID格式:由原则衍生的短横线命名格式(例如:
    llm-output-trust-boundary
json
{
  "distilled_at": "2026-03-18T10:30:42Z",
  "skills_scanned": 56,
  "rules_scanned": 22,
  "candidates": {
    "llm-output-trust-boundary": {
      "principle": "存储或重新注入LLM输出时,将其视为不可信内容",
      "verdict": "Append",
      "target": "rules/common/security.md",
      "evidence": ["llm-memory-trust-boundary", "llm-social-agent-anti-pattern"],
      "status": "applied"
    },
    "iteration-bounds": {
      "principle": "为所有迭代循环定义明确的终止条件",
      "verdict": "New Section",
      "target": "rules/common/coding-style.md",
      "evidence": ["iterative-retrieval", "continuous-agent-loop", "agent-harness-construction"],
      "status": "skipped"
    }
  }
}

Example

示例

End-to-end run

端到端运行

$ /rules-distill

Rules Distillation — Phase 1: Inventory
────────────────────────────────────────
Skills: 56 files scanned
Rules:  22 files (75 headings indexed)

Proceeding to cross-read analysis...

[Subagent analysis: Batch 1 (agent/meta skills) ...]
[Subagent analysis: Batch 2 (coding/pattern skills) ...]
[Cross-batch merge: 2 duplicates removed, 1 cross-batch candidate promoted]
$ /rules-distill

规则提炼 — 阶段1:盘点
────────────────────────────────────────
已扫描Skill:56个文件
已扫描规则:22个文件(已索引75个标题)

即将进入交叉阅读分析环节...

[子Agent分析:批次1(agent/meta类Skill)...]
[子Agent分析:批次2(coding/pattern类Skill)...]
[跨批次合并:移除2个重复项,1个跨批次候选规则通过验证]

Rules Distillation Report

规则提炼报告

Summary

摘要

Skills scanned: 56 | Rules: 22 files | Candidates: 4
#PrincipleVerdictTargetConfidence
1LLM output: normalize, type-check, sanitize before reuseNew Sectioncoding-style.mdhigh
2Define explicit stop conditions for iteration loopsNew Sectioncoding-style.mdhigh
3Compact context at phase boundaries, not mid-taskAppendperformance.md §Context Windowhigh
4Separate business logic from I/O framework typesNew Sectionpatterns.mdhigh
已扫描Skill:56 | 规则文件:22个 | 候选规则:4
序号原则判断结果目标位置置信度
1LLM输出:复用前需标准化、类型检查与清理新增章节coding-style.md
2为迭代循环定义明确的终止条件新增章节coding-style.md
3在阶段边界压缩上下文,而非任务执行中追加performance.md §上下文窗口
4将业务逻辑与I/O框架类型分离新增章节patterns.md

Details

详情

1. LLM Output Validation

1. LLM输出验证

Verdict: New Section in coding-style.md Evidence: parallel-subagent-batch-merge, llm-social-agent-anti-pattern, llm-memory-trust-boundary Violation risk: Format drift, type mismatch, or syntax errors in LLM output crash downstream processing Draft:

LLM Output Validation

Normalize, type-check, and sanitize LLM output before reuse... See skill: parallel-subagent-batch-merge, llm-memory-trust-boundary
[... details for candidates 2-4 ...]
Approve, modify, or skip each candidate by number:
User: Approve 1, 3. Skip 2, 4.
✓ Applied: coding-style.md §LLM Output Validation ✓ Applied: performance.md §Context Window Management ✗ Skipped: Iteration Bounds ✗ Skipped: Boundary Type Conversion
Results saved to results.json
undefined
判断结果:在coding-style.md中新增章节 证据:parallel-subagent-batch-merge、llm-social-agent-anti-pattern、llm-memory-trust-boundary 违规风险:LLM输出的格式偏移、类型不匹配或语法错误会导致下游处理崩溃 草稿:

LLM输出验证

复用LLM输出前需进行标准化、类型检查与清理... 参考Skill:parallel-subagent-batch-merge、llm-memory-trust-boundary
[...候选规则2-4的详情...]
请通过序号选择批准、修改或跳过每个候选规则:
用户:批准1、3。跳过2、4。
✓ 已应用:coding-style.md §LLM输出验证 ✓ 已应用:performance.md §上下文窗口管理 ✗ 已跳过:迭代边界 ✗ 已跳过:边界类型转换
结果已保存至results.json
undefined

Design Principles

设计原则

  • What, not How: Extract principles (rules territory) only. Code examples and commands stay in skills.
  • Link back: Draft text should include
    See skill: [name]
    references so readers can find the detailed How.
  • Deterministic collection, LLM judgment: Scripts guarantee exhaustiveness; the LLM guarantees contextual understanding.
  • Anti-abstraction safeguard: The 3-layer filter (2+ skills evidence, actionable behavior test, violation risk) prevents overly abstract principles from entering rules.
  • 只提炼「做什么」,不涉及「怎么做」:仅提取原则(规则范畴)。代码示例与命令保留在Skill中。
  • 关联溯源:草稿文本应包含「参考Skill:[名称]」的引用,方便读者查看详细的实现方法。
  • 确定性收集,LLM判断:脚本确保全面性;LLM确保上下文理解能力。
  • 防过度抽象保障:三层过滤机制(至少2个Skill的证据、可指导行为、违规风险)避免过于抽象的原则进入规则。