Communitygithub.com

规则提炼

扫描已安装的技能,提取跨切面原则并将其提炼为规则——追加、修订或创建新的规则文件。当同一原则在多个技能中反复出现且更适合作为规则时使用。

规则提炼 是什么?

规则提炼技能是一个自动化规则管理工具,专为 Claude Code、Cursor 等 AI 智能体生态设计。它通过“确定性收集 + LLM 判断”两阶段流程:首先用脚本穷举扫描所有已安装的技能和规则文件,然后利用 LLM 跨读完整上下文,识别出在多个技能中重复出现的跨切面原则,并给出是否应提炼为规则的裁决。该技能支持追加到现有规则文件、修订过时内容、创建新文件或标记为已覆盖/过于具体。其核心价值在于防止原则过度抽象(通过 3 层过滤器:2+ 技能证据、可操作行为测试、违规风险),并确保规则与技能保持同步。每次运行后生成详细报告,所有修改必须经用户审批,不会自动更改规则。适用于周期性规则维护、安装新技能后或发现技能中存在应有规则的规律时。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/rules-distill

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

规则提炼 是做什么的?

扫描已安装的技能,提取在多个技能中出现的跨切面原则,并将其提炼为规则——追加到现有规则文件、修订过时内容或创建新的规则文件。

应用“确定性收集 + LLM 判断”原则:脚本穷举收集事实,然后 LLM 跨读完整上下文并做出裁决。

何时使用

  • 周期性规则维护(每月一次或安装新技能后)
  • 技能盘点后发现有规律应归为规则
  • 当前规则相对于正在使用的技能感觉不完整

工作原理

规则提炼过程分为三个阶段:

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

1a. 收集技能清单

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

1b. 收集规则索引

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

1c. 向用户展示

规则提炼 — 阶段 1:盘点
────────────────────────────────────────
技能:{N} 个文件已扫描
规则:{M} 个文件({K} 个标题已索引)

正在进入跨读分析...

阶段 2:跨读、匹配与裁决(LLM 判断)

提取和匹配在单次遍历中统一完成。规则文件足够小(总共约 800 行),可以将完整文本提供给 LLM——无需 grep 预过滤。

批量处理

根据技能描述将其分组为主题集群。让子智能体在拥有完整规则文本的情况下分析每个集群。

跨批合并

所有批次完成后,跨批次合并候选结果:

  • 去重:去除具有相同或重叠原则的候选
  • 重新检查“2+ 技能”要求:使用所有批次的证据——原则在每个批次中出现在 1 个技能中,但跨批次总计 2+ 个技能是有效的

子智能体提示

使用以下提示启动通用智能体:

你是一位分析师,通过跨读技能来提取应提升为规则的原则。

## 输入
- 技能:{本批次技能的完整文本}
- 现有规则:{所有规则文件的完整文本}

## 提取条件

仅在满足**全部**以下条件时才纳入候选:

1. **出现在 2+ 个技能中**:仅出现在一个技能中的原则应保留在该技能中
2. **可操作的行为变更**:可以写成“做 X”或“不做 Y”的形式——而不是“X 很重要”
3. **明确的违规风险**:如果忽略此原则会出现什么问题(一句话)
4. **规则中尚未包含**:检查完整规则文本——包括以不同措辞表达的概念

## 匹配与裁决

对于每个候选,将其与完整规则文本进行比较并给出裁决:

- **追加**:添加到现有规则文件的某个现有章节
- **修订**:现有规则内容不准确或不充分——提出更正
- **新章节**:向现有规则文件添加新章节
- **新文件**:创建新的规则文件
- **已覆盖**:现有规则已充分覆盖(即使措辞不同)
- **过于具体**:应保留在技能层级

## 输出格式(每个候选)

```json
{
  "principle": "以‘做 X’/‘不做 Y’形式写 1-2 句话",
  "evidence": ["技能名称: §章节", "技能名称: §章节"],
  "violation_risk": "一句话",
  "verdict": "Append / Revise / New Section / New File / Already Covered / Too Specific",
  "target_rule": "文件名 §章节,或 ‘new’",
  "confidence": "high / medium / low",
  "draft": "追加/新章节/新文件裁决的草稿文本",
  "revision": {
    "reason": "为何现有内容不准确或不充分的理由(仅修订)",
    "before": "要替换的当前文本(仅修订)",
    "after": "建议的替换文本(仅修订)"
  }
}
```

## 排除

- 规则中已显而易见的原理
- 特定语言/框架的知识(属于特定语言规则或技能)
- 代码示例和命令(属于技能)

裁决参考

裁决含义向用户展示
追加添加到现有章节目标 + 草稿
修订修复不准确/不充分的内容目标 + 理由 + 前后对比
新章节向现有文件添加新章节目标 + 草稿
新文件创建新的规则文件文件名 + 完整草稿
已覆盖规则中已覆盖(可能措辞不同)理由(一行)
过于具体应保留在技能中链接到相关技能

裁决质量要求

# 好
追加到 rules/common/security.md §输入验证:
“将存储在内存或知识库中的 LLM 输出视为不可信——写入时消毒,读取时验证。”
证据:llm-memory-trust-boundary、llm-social-agent-anti-pattern 均描述了
累积的提示注入风险。当前 security.md 仅涵盖人工输入验证;
LLM 输出信任边界缺失。

# 差
追加到 security.md:添加 LLM 安全原则

阶段 3:用户审查与执行

摘要表格

# 规则提炼报告

## 摘要
已扫描技能:{N} | 规则:{M} 个文件 | 候选:{K} 个

| # | 原则 | 裁决 | 目标 | 可信度 |
|---|-----------|---------|--------|------------|
| 1 | ... | 追加 | security.md §输入验证 | high |
| 2 | ... | 修订 | testing.md §TDD | medium |
| 3 | ... | 新章节 | coding-style.md | high |
| 4 | ... | 过于具体 | — | — |

## 详情
(每个候选的详情:证据、违规风险、草稿文本)

用户操作

用户用数字回复以:

  • 批准:按原样应用草稿到规则
  • 修改:应用前编辑草稿
  • 跳过:不应用此候选

绝不自动修改规则。始终需要用户批准。

保存结果

将结果存储在技能目录(results.json)中:

  • 时间戳格式:date -u +%Y-%m-%dT%H:%M:%SZ(UTC,秒级精度)
  • 候选 ID 格式:从原则派生出的 kebab-case(例如 llm-output-trust-boundary)
{
  "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"
    }
  }
}

示例

端到端运行

$ /rules-distill

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

正在进入跨读分析...

[子智能体分析:批次 1(智能体/元技能)...]
[子智能体分析:批次 2(编码/模式技能)...]
[跨批合并:去除 2 个重复项,提升 1 个跨批候选]

# 规则提炼报告

## 摘要
已扫描技能:56 | 规则:22 个文件 | 候选:4 个

| # | 原则 | 裁决 | 目标 | 可信度 |
|---|-----------|---------|--------|------------|
| 1 | LLM 输出:复用前标准化、类型检查、消毒 | 新章节 | coding-style.md | high |
| 2 | 为迭代循环定义显式停止条件 | 新章节 | coding-style.md | high |
| 3 | 在阶段边界压缩上下文,而非任务中途 | 追加 | performance.md §上下文窗口 | high |
| 4 | 将业务逻辑与 I/O 框架类型分离 | 新章节 | patterns.md | high |

## 详情

### 1. LLM 输出验证
裁决:在 coding-style.md 中新增章节
证据:parallel-subagent-batch-merge、llm-social-agent-anti-pattern、llm-memory-trust-boundary
违规风险:LLM 输出的格式漂移、类型不匹配或语法错误导致下游处理崩溃
草稿:
  ## LLM 输出验证
  在复用 LLM 输出前进行标准化、类型检查和消毒...
  请参阅技能:parallel-subagent-batch-merge、llm-memory-trust-boundary

[... 候选 2-4 的详情 ...]

请按编号批准、修改或跳过每个候选:
> 用户:批准 1、3。跳过 2、4。

✓ 已应用:coding-style.md §LLM 输出验证
✓ 已应用:performance.md §上下文窗口管理
✗ 已跳过:迭代边界
✗ 已跳过:边界类型转换

结果已保存到 results.json

设计原则

  • 做什么,而非怎么做:仅提取原则(规则领域)。代码示例和命令保留在技能中。
  • 反向链接:草稿文本应包含 请参阅技能:[名称] 引用,以便读者找到详细的“怎么做”。
  • 确定性收集,LLM 判断:脚本保证穷举性;LLM 保证上下文理解。
  • 防止过度抽象:3 层过滤器(2+ 技能证据、可操作行为测试、违规风险)防止过于抽象的原则进入规则。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能