Communitygithub.com

レガシースタイル継承

レガシープロジェクトの暗黙的なコーディング規約を自動スキャン・抽出し、AIによるコードスタイルの逸脱を防止する`.ai-style-rules.md`を生成するスキルです。

レガシースタイル継承 とは?

このスキルは、AIエージェント(Claude Code、Cursor、Codex等)を手書きのレガシープロジェクトに導入する際に、AIが生成するコードが既存のプロジェクトスタイルから逸脱する「スタイルドリフト」を防止します。コードベースを4つのメタアーキテクチャ次元(ファイル構造、状態/制御フロー、インフラストラクチャ、エラーハンドリング)に沿ってスキャンし、暗黙的なコーディング規約を抽出。ユーザーと1対1でコンフリクトを解決しながら、合意事項を`.ai-style-rules.md`に結晶化します。初回実行時はフルスキャン、既存ルールファイルがある場合はインクリメンタル更新(Git差分ベース)に対応。言語・フレームワーク非依存で、出力ルールファイルをCLAUDE.mdから参照させるソフトフック、またはPreToolUseを利用したハードフックによる永続的な適用が可能です。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/inherit-legacy-style

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

レガシースタイル継承 は何をしますか?

AIコードのスタイルドリフトを防止します。コードベースをスキャンして4つのメタアーキテクチャ次元にわたる暗黙的な規約を抽出し、ユーザーと1対1でコンフリクトを解決しながら、合意事項を強制力のある.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 — インクリメンタルスニフ

モードを1行でアナウンスし、続行します。ユーザーに選択させることは絶対にしないでください。

ブランチ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. ファイル構造 — ファイル内の宣言順序(インポート → 型 → メインロジック → ヘルパー → エクスポート)
  2. 状態と制御フロー — 非同期状態、ページネーション、フラグの命名規則
  3. インフラストラクチャ — 横断的ユーティリティの配置場所(インターセプター、フォーマッター、ミドルウェア)
  4. エラーハンドリング — try/catch vs グローバルインターセプター vs Result返却。nullチェック習慣

3. シグナル閾値によるノイズ低減を適用

ユーザーに割り込む前に、シグナル強度を評価:

  • 弱いシグナル → 自動抑制: 少数派 <5% かつ 件数 <10 → 多数派のルールを採用し、少数派をDONTsへ
  • 強いシグナル → グリル: ほぼ半々の分割、またはコア次元での意味論的分岐
  • 小規模プロジェクト例外: ソース数 ≲50 で「3対2」は多数派とはみなさない → グリル対象

4. コンフリクトを1つずつ解決(グリリングプロトコル)

強いシグナルのコンフリクトごとに、正確に1つの質問を4択で提示:

証拠: pathA はスタイルXを使用、pathB はスタイルYを使用 警告: リスク: 両方を混在させるとプロジェクトスタイルが分裂します 選択: 1 Xに従う 2 Yに従う 3 これは進化なのでルールを更新 4 新しいルールを提示

ユーザーの回答があるまで中断し、その後次のコンフリクトに進みます。質問を重ねてはいけません。

5. .ai-style-rules.md を生成 — 以下の3つの必須セクションを含む:

  • [ゴールデンファイル] — 実際の模範ファイルパスと、それが示す内容の注釈
  • [命名・状態制御ルール] — 具体的でチェック可能な規約
  • [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経由でロード)、すべてのコード作成タスクは思考連鎖の中で 遵守宣言 を開始し、従う模範ファイルと回避するDONTsを明示しなければなりません。

仕組み

このスキルは、.ai-style-rules.md の有無に応じて初回実行かインクリメンタル実行かを自動検出します:

  • 初回(ブランチA) — プロジェクト規模を測定し、4つのメタアーキテクチャ次元(ファイル構造、状態・制御フロー、インフラストラクチャ、エラーハンドリング)でコードベースをスキャンし、弱いコンフリクトを抑制するシグナル閾値ノイズ低減を適用し、強いシグナルのコンフリクトをユーザーと1対1で解決し、ゴールデンファイル/命名ルール/DONTsを含む .ai-style-rules.md を生成し、オプションの強制フックを提供します。
  • インクリメンタル(ブランチB) — 既存のルールを読み、最近のGit差分をチェックし、新しいパターンや競合パターンがないか確認し、見つかったコンフリクトに対して1対1のグリリングプロトコルを実行し、既存のルールを上書きせずに進化ログを追記します。
  • ターンごとの強制 — CLAUDE.md経由でフックされると、すべてのコード作成タスクは従う模範ファイルと回避するDONTsを明示した遵守宣言で開始されます。

出力仕様

  • プロジェクトルートに .ai-style-rules.md(ヘッダーにコミットフィンガープリントとスケールティアを含む)
  • 必要に応じて @.ai-style-rules.md 参照を含む CLAUDE.md
  • ### [YYYY-MM-DD] Style Evolution Log エントリとして進化ログを追記

アンチパターン

  • 失敗: 規模測定ステップをスキップしないこと — 30ファイルのプロジェクトをサンプリングすると「飢餓」状態に、5000ファイルのリポジトリをフルスキャンすると爆発します
  • 失敗: 複数のコンフリクト質問を同時に提示しないこと — グリリングは厳密に1対1です
  • 失敗: インクリメンタルモードで古いルールを上書きしないこと — 常に進化ログを追記します
  • 失敗: ユーザーに確認せずに「ハードフック」をデフォルトにしないこと — 強制強度はユーザーが決定します
  • 失敗: 構文や技術スタックの品質を判断しないこと — このスキルはメタアーキテクチャのみを対象とします
  • 失敗: 模範ファイルからバグをコピーしないこと — 構造を再利用し、欠陥は報告します

ベストプラクティス

  • スキャン前に、検出されたモード(初回 vs インクリメンタル)とスケールティアを1行でアナウンスする
  • 大規模プロジェクトでは、まず --stat サマリーを読み、次に対象を絞って Read する
  • シグナル閾値にノイズ処理を任せる — 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によるDONTsの強制

    • ユーザー: 「新しいコードがすべてプロジェクトのルールと一貫性を保つようにして。」
    • アクション: ソフトフックをインストール → .ai-style-rules.md が毎セッションで自動ロード → すべてのコード作成タスクが遵守宣言で開始され、模範ファイルのパターンを再利用し、DONTsを回避。

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.

関連スキル