Communitygithub.com

rules-distill

掃描已安裝的技能,提取跨技能的共同原則,並將其提煉為規則 — 可附加到現有規則檔案、修訂過時內容,或建立新規則檔案。

rules-distill 是什麼?

Rules Distill 是一個用於 AI 代理(如 Claude Code)的規則管理工具,旨在自動化從已安裝技能中提取通用原則並推廣為規則的流程。它遵循「確定性收集 + LLM 判斷」的原則:先透過 shell 腳本徹底掃描技能和規則檔案,再由 LLM 進行跨技能比對並給出判決(附加、修訂、新增章節或新建檔案)。該工具支援批次處理:將技能按主題分組,每個批次由子代理分析,最後跨批次合併候選項目以確保原則跨越多個技能(至少兩個)才被納入。其設計重點在於防止過度抽象化,透過三層過濾(證據數量、可操作行為測試、違規風險)確保僅有具體、可操作的通用原則被提升為規則。使用者最終擁有審查與批准權,所有規則修改皆需手動確認,並將結果儲存為 JSON 檔案以供追蹤。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Rules Distill

掃描已安裝的技能,提取在多個技能中出現的跨切面原則,並將其提煉為規則 — 附加到現有規則檔案、修訂過時內容,或建立新規則檔案。

應用「確定性收集 + LLM 判斷」原則:腳本徹底收集事實,然後 LLM 交叉讀取完整上下文並產生判決。

使用時機

  • 定期規則維護(每月一次,或安裝新技能後)
  • 技能盤點後發現應歸為規則的模式
  • 感覺規則相對於所使用的技能不夠完整時

運作方式

規則提煉流程分為三個階段:

第一階段:盤點(確定性收集)

1a. 收集技能清單

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

1b. 收集規則索引

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

1c. 呈現給使用者

Rules Distillation — 第一階段:盤點
────────────────────────────────────────
技能:已掃描 {N} 個檔案
規則:{M} 個檔案(已索引 {K} 個標題)

繼續進行交叉閱讀分析...

第二階段:交叉閱讀、比對與判決(LLM 判斷)

提取與比對合併為單一操作。規則檔案足夠小(總計約 800 行),因此可將完整文字提供給 LLM — 無需使用 grep 預先過濾。

批次處理

根據技能描述將技能分組為主題叢集。在子代理中,搭配完整的規則文字分析每個叢集。

跨批次合併

所有批次完成後,跨批次合併候選項目:

  • 去除具有相同或重疊原則的重複候選
  • 使用所有批次的證據,重新檢查「2+ 技能」的要求 — 如果在一個批次中僅在一個技能中發現,但所有批次合計有 2+ 技能,則該原則仍然有效

子代理提示

使用以下提示啟動通用代理:

你是一名分析師,負責交叉閱讀技能以提取應提升為規則的原則。

## 輸入
- 技能:{此批次中技能的完整文字}
- 現有規則:{所有規則檔案的完整文字}

## 提取標準

**僅在**以下所有條件皆成立時才將候選納入:

1. **出現在 2+ 個技能中**:僅在一個技能中發現的原則應留在該技能中
2. **可促成行為改變**:可以寫成「做 X」或「不做 Y」的形式 — 而不是「X 很重要」
3. **有明確的違規風險**:忽略此原則會導致什麼問題(一句話)
4. **尚未存在於規則中**:檢查完整的規則文字 — 包括以不同詞語表達的概念

## 比對與判決

針對每個候選,將其與完整的規則文字進行比較,並指定判決:

- **Append**:附加到現有規則檔案的現有章節中
- **Revise**:現有規則內容不準確或不夠充分 — 提出修正
- **New Section**:在現有規則檔案中新增章節
- **New File**:建立新的規則檔案
- **Already Covered**:現有規則已充分涵蓋(即使措辭不同)
- **Too Specific**:應保留在技能層級

## 輸出格式(每個候選)

```json
{
  "principle": "1-2 句話,以『做 X』/『不做 Y』的形式表達",
  "evidence": ["skill-name: §Section", "skill-name: §Section"],
  "violation_risk": "一句話",
  "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)"
  }
}
```

## 排除

- 已經存在於規則中的顯而易見原則
- 語言/框架特定的知識(屬於特定語言規則或技能)
- 程式碼範例與指令(屬於技能)

判決參考

判決含義呈現給使用者
Append附加到現有章節目標 + 草稿
Revise修正不準確/不充分的內容目標 + 原因 + 修改前/後
New Section在現有檔案中新增章節目標 + 草稿
New File建立新的規則檔案檔名 + 完整草稿
Already Covered已存在於規則中(可能措辭不同)原因(一行)
Too Specific應保留在技能中連結到相關技能

判決品質要求

# 良好
Append to rules/common/security.md §Input Validation:
「將儲存在記憶體或知識庫中的 LLM 輸出視為不可信任 — 寫入時消毒,讀取時驗證。」
證據:llm-memory-trust-boundary, llm-social-agent-anti-pattern 皆描述了
累積的提示注入風險。目前的 security.md 僅涵蓋人類輸入驗證;LLM 輸出信任邊界遺漏。

# 不良
Append to security.md: 新增 LLM 安全原則

第三階段:使用者審查與執行

摘要表格

# Rules Distillation 報告

## 摘要
已掃描技能:{N} | 規則:{M} 個檔案 | 候選:{K} 個

| # | 原則 | 判決 | 目標 | 信心程度 |
|---|-----------|---------|--------|------------|
| 1 | ... | Append | security.md §Input Validation | high |
| 2 | ... | Revise | testing.md §TDD | medium |
| 3 | ... | New Section | coding-style.md | high |
| 4 | ... | Too Specific | — | — |

## 詳細資料
(每個候選的詳細資料:證據、違規風險、草稿文字)

使用者操作

使用者根據編號回應:

  • Approve:直接將草稿套用到規則
  • Modify:先編輯草稿再套用
  • Skip:不套用此候選

絕不自動修改規則。務必要求使用者核准。

儲存結果

將結果儲存在技能目錄中(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

Rules Distillation — 第一階段:盤點
────────────────────────────────────────
技能:已掃描 56 個檔案
規則:22 個檔案(已索引 75 個標題)

繼續進行交叉閱讀分析...

[子代理分析:批次 1(代理/元技能)...]
[子代理分析:批次 2(編碼/模式技能)...]
[跨批次合併:移除 2 個重複,升級 1 個跨批次候選]

# Rules Distillation 報告

## 摘要
已掃描技能:56 | 規則:22 個檔案 | 候選:4 個

| # | 原則 | 判決 | 目標 | 信心程度 |
|---|-----------|---------|--------|------------|
| 1 | LLM 輸出:在重用前標準化、型別檢查、消毒 | New Section | coding-style.md | high |
| 2 | 為迭代迴圈定義明確的停止條件 | New Section | coding-style.md | high |
| 3 | 在階段邊界壓縮上下文,而非任務中途 | Append | performance.md §Context Window | high |
| 4 | 將業務邏輯與 I/O 框架型別分離 | New Section | patterns.md | high |

## 詳細資料

### 1. LLM 輸出驗證
判決:New Section in 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 的詳細資料 ...]

請根據編號核准、修改或跳過各候選:
> 使用者:Approve 1, 3. Skip 2, 4.

✓ 已套用:coding-style.md §LLM 輸出驗證
✓ 已套用:performance.md §Context Window 管理
✗ 已跳過:迭代界限
✗ 已跳過:邊界型別轉換

結果已儲存至 results.json

設計原則

  • 做什麼,而非怎麼做:僅提取原則(規則領域)。程式碼範例和指令保留在技能中。
  • 反向連結:草稿文字應包含 請參閱技能:[名稱] 的參考,以便讀者找到詳細的「怎麼做」。
  • 確定性收集,LLM 判斷:腳本保證徹底性;LLM 保證上下文理解。
  • 防止過度抽象化:三層過濾(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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能