Communitygithub.com

inherit-legacy-style

Legacy-project style inheritance skill. Use when the user types /inherit-legacy-style, or when onboarding an AI coding agent onto a hand-written legacy project and you need to prevent

inherit-legacy-style 是什麼?

這個技能用於防止 AI 在遺留專案中產生程式碼風格漂移。它會掃描整個程式碼庫,從四個後設架構維度(檔案結構、狀態與控制流程、基礎設施、錯誤處理)中發掘隱含的慣例,逐一與使用者解決衝突,並將共識濃縮成可強制執行的 `.ai-style-rules.md` 檔案。此技能完全語言與框架無關。支援第一次完整掃描(Branch A)與增量嗅探(Branch B)兩種模式,並可透過 `CLAUDE.md` 掛鉤實現每次任務的合規性檢查。使用者可選擇軟性掛鉤、硬性掛鉤或不掛鉤,以控制規則的執行強度。技能內建訊號強度閾值機制,可自動壓制弱衝突,僅在出現強烈分歧時才逐一詢問使用者。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/inherit-legacy-style

在你喜歡的 AI 中提問

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

說明文件

繼承遺留風格 (Inherit Legacy Style)

防止 AI 在遺留專案中產生程式碼風格漂移。透過掃描程式碼庫,從四個後設架構維度發掘隱含慣例,逐一與使用者解決衝突,並將共識濃縮成可強制執行的 .ai-style-rules.md 檔案。完全語言與框架無關。

何時啟用

  • 使用者輸入 /inherit-legacy-style
  • 使用者提到要將 AI 導入到手寫的遺留專案中
  • 使用者擔心 AI 生成的程式碼會偏離現有專案慣例
  • 使用者想要萃取並編纂專案的隱含編碼規則

使用時機

當您需要保留遺留專案風格並防止 AI 造成的風格漂移時使用此技能。請參閱上方何時啟用以了解觸發條件。

先決條件

  • Git(建議;非 Git 專案則回退使用檔案時間戳記進行增量模式)
  • 對專案根目錄的讀寫權限(會產生 .ai-style-rules.md 以及可選的 CLAUDE.md)

工作流程

步驟 0 — 自動偵測模式

靜默檢查專案根目錄是否存在 .ai-style-rules.md:

檔案存在?模式
否分支 A — 首次完整掃描
是分支 B — 增量嗅探

用一行文字宣布模式,然後繼續執行——絕不要讓使用者選擇。

分支 A — 首次完整掃描

1. 衡量規模,選擇掃描層級

git ls-files | grep -cE '\.(js|ts|jsx|tsx|vue|py|go|rs|java|kt|rb|php|cs|swift|c|cpp|h)$'
層級原始檔數量策略
小型≲ 50完整細讀每個原始檔
中型50–500基礎層 = 完整讀取;業務層 = 每個維度取樣 2–3 個
大型≳ 500嚴格取樣 + 預算上限;先 --stat 摘要,再針對性讀取

2. 沿 4 個維度掃描

  1. 檔案結構 (File Anatomy) — 檔案內宣告順序(匯入 → 型別 → 主要邏輯 → 輔助函式 → 匯出)
  2. 狀態與控制流程 (State & Control Flow) — 非同步狀態、分頁、旗標的命名慣例
  3. 基礎設施 (Infrastructure) — 跨橫切面工具(攔截器、格式化器、中介軟體)的存放位置
  4. 錯誤處理 (Error Handling) — try/catch 與全域攔截器與 Result 回傳的取捨;null 檢查習慣

3. 應用訊號強度雜訊抑制

在打斷使用者之前,評估訊號強度:

  • 弱訊號 → 自動壓制:少數 <5% 且總數 <10 → 多數獲勝,少數歸入「禁止事項」
  • 強訊號 → 詳細詢問:接近持平的分裂,或核心維度上的語意分歧
  • 小型專案例外:原始檔 ≲50,「3 比 2」並非多數 → 應詳細詢問

4. 一次解決一個衝突(詳細詢問協議)

對於每個強訊號衝突,僅提出一個問題,附帶 4 個選項:

證據:pathA 使用風格 X,pathB 使用風格 Y 警告:風險:混用兩者會破壞專案風格 選擇:1 遵循 X 2 遵循 Y 3 這是演化,更新規則 4 我有一個新規則

暫停直到使用者回答,然後繼續下一個衝突。絕不要堆疊問題。

5. 產生 .ai-style-rules.md,包含三個必要章節:

  • [黃金檔案 (Golden Files)] — 真實的範例路徑,並附帶其示範內容的說明
  • [命名與狀態控制規則 (Naming & State-Control Rules)] — 具體、可檢查的慣例
  • [禁止事項 (DONTs)] — 不得擴散的反模式

6. 安裝持久掛鉤

詢問使用者強制執行強度(使用 AskUserQuestion):

選項機制
1 軟掛鉤(建議)將 @.ai-style-rules.md 引用寫入專案 CLAUDE.md
2 硬掛鉤軟掛鉤 + settings.json 中的 `PreToolUse[Write
3 不掛鉤保留規則檔案;使用者手動參考

分支 B — 增量嗅探

  1. 讀取現有 .ai-style-rules.md;若包含提交指紋,則執行 git diff <last_hash> HEAD --stat 以精確找出變更範圍
  2. 讀取最近的 Git 變更(git log -3 --stat → 按需求檢查可疑檔案)
  3. 對於過大的差異(>數百個檔案):僅使用 --stat 摘要 + 取樣最大變更檔案
  4. 將新程式碼與記錄的規則進行比對 → 衝突則進入詳細詢問協議
  5. 在 .ai-style-rules.md 末尾附加演化日誌(絕不覆蓋舊規則)

每次任務的強制執行

當 .ai-style-rules.md 在上下文中(透過 CLAUDE.md 載入)時,每個撰寫程式碼的任務必須在推理鏈中以合規性宣告開場,說明正在遵循的範例以及正在避免的禁止事項。

運作方式

此技能透過 .ai-style-rules.md 的存在與否自動偵測是首次執行還是增量執行:

  • 首次執行(分支 A) — 衡量專案規模,在 4 個後設架構維度(檔案結構、狀態與控制流程、基礎設施、錯誤處理)掃描程式碼庫,應用訊號強度雜訊抑制來壓制弱衝突,逐一與使用者解決強訊號衝突,產生包含黃金檔案/命名規則/禁止事項的 .ai-style-rules.md,並提供可選的強制執行掛鉤。
  • 增量執行(分支 B) — 讀取現有規則,檢查最近的 Git 差異以找出新或衝突的模式,對任何發現的衝突執行相同的逐一詳細詢問協議,並附加演化日誌而不覆蓋現有規則。
  • 每次任務強制執行 — 當透過 CLAUDE.md 掛鉤時,每個撰寫程式碼的任務以合規性宣告開場,說明遵循的範例和避免的禁止事項。

輸出規範

  • 專案根目錄下的 .ai-style-rules.md(標頭中包含提交指紋 + 規模層級)
  • 可選的 CLAUDE.md,內含 @.ai-style-rules.md 引用
  • 演化日誌以 ### [YYYY-MM-DD] 風格演化日誌 條目附加

反模式

  • 失敗:請勿跳過規模衡量步驟——對一個 30 個檔案的專案進行取樣是「饑餓」的;對一個 5,000 個檔案的儲存庫進行完整掃描則會爆炸
  • 失敗:請勿一次堆疊多個衝突問題——詳細詢問必須嚴格逐一進行
  • 失敗:請勿在增量模式下覆蓋舊規則——務必附加演化日誌
  • 失敗:請勿未經詢問就預設使用「硬掛鉤」——強制執行強度由使用者決定
  • 失敗:請勿評判語法或技術棧品質——此技能僅校準後設架構
  • 失敗:請勿從範例檔案中複製錯誤——應重用結構,標記缺陷

最佳實務

  • 在掃描前先用一行文字宣布偵測到的模式(首次 vs. 增量)和規模層級
  • 對於大型專案,先讀取 --stat 摘要,再針對性讀取可疑檔案
  • 讓訊號強度閾值處理雜訊——843 比 8 的命名分歧應自動解決,無需使用者干預
  • 若對訊號強度有疑慮,傾向於提出問題
  • CLAUDE.md 軟掛鉤(@.ai-style-rules.md)通常已足夠;僅在使用者想要機械式強制執行時才使用硬掛鉤

相關技能

  • init — 使用程式碼庫文件初始化新的 CLAUDE.md
  • code-review — 審查差異以檢查正確性和風格問題
  • simplify — 審查程式碼以尋找重複使用和簡化的機會

範例

  1. 首次導入

    • 使用者:「幫我把 AI 導入這個舊程式碼庫,但不改變它的風格。」
    • 動作:執行分支 A 完整掃描 → 衡量規模 → 掃描 4 個維度 → 詳細詢問衝突 → 產生 .ai-style-rules.md → 提供掛鉤強度(軟/硬/無)。
  2. 團隊變更後的增量更新

    • 使用者:「我們新增了一個模組;保持現有風格規則不變。」
    • 動作:執行分支 B 增量嗅探 → 將 Git 差異與記錄規則比對 → 對任何新衝突進行詳細詢問 → 附加演化日誌而不覆蓋。
  3. 透過 CLAUDE.md 強制執行禁止事項

    • 使用者:「確保所有新程式碼都與專案規則保持一致。」
    • 動作:安裝軟掛鉤 → .ai-style-rules.md 在每次會話自動載入 → 每個撰寫程式碼的任務以合規性宣告開場,重複使用範例模式並避免禁止事項。

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.

相關技能