jpskill.com
📦 その他 コミュニティ

icpg

Intent-Augmented Code Property Graph — tracks WHY code exists via ReasonNodes with formal contracts, 6-dimension drift detection, and 3 canonical pre-task queries for autonomous development

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o icpg.zip https://jpskill.com/download/21640.zip && unzip -o icpg.zip && rm icpg.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21640.zip -OutFile "$d\icpg.zip"; Expand-Archive "$d\icpg.zip" -DestinationPath $d -Force; ri "$d\icpg.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して icpg.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → icpg フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[スキル名] icpg

iCPGスキル (Intent-Augmented Code Property Graph)

目的: コード構造の上に理由グラフ層を追加し、すべての関数、クラス、モジュールが、それを作成した目標、それを所有するエージェントまたは人間、そしてそれが本来の目的を果たしているかどうかを追跡できるようにすることです。

┌────────────────────────────────────────────────────────────────┐
│  iCPG = AST + CFG + PDG + RG (理由グラフ)                    │
│  ─────────────────────────────────────────────────────────────│
│  AST  = 抽象構文木 (構造)      ← 既存       │
│  CFG  = 制御フローグラフ (実行パス)  ← 既存       │
│  PDG  = プログラム依存グラフ              ← 既存       │
│  RG   = 理由グラフ (WHY層)              ← このスキル     │
│                                                                │
│  RGはReasonNodes (目標/タスク) を保存し、型付きエッジを介して │
│  コードシンボルにリンクし、契約 (DbC) を強制し、コードが元の │
│  目的から逸脱したときに検出します。                            │
│                                                                │
│  ストレージ: .icpg/reason.db (SQLite、プロジェクトごと、gitignored)   │
│  CLI: icpg init | create | record | query | drift | bootstrap │
└────────────────────────────────────────────────────────────────┘

中核となる原則

意図が最初、コードは二番目。 コードを記述または変更する前に、理由グラフを照会して、既存のコードがなぜ書かれたのか、どのような制約を維持しなければならないのか、そしてあなたの変更が以前の作業と重複しているかどうかを理解してください。


3つの典型的なタスク前クエリ

すべてのエージェントは、コードを記述する前にこれらを実行しなければなりません:

# クエリ コマンド 何に答えるか
1 search_prior_work icpg query prior "<goal>" これは以前に試みられたことがありますか?重複を防ぎます。
2 get_constraints icpg query constraints <file> 触れるファイルに適用される不変条件は何ですか?破損を防ぎます。
3 get_risk_profile icpg query risk <symbol> このシンボルは脆弱ですか?ドリフト履歴、所有権の変更。

ReasonNode — 中核となるプリミティブ

各ReasonNodeは、正式な契約とともに明示された目的を捉えます。

id              UUID
goal            自然言語: 何を達成しようとしているのか
decision_type   business_goal | arch_decision | task | workaround | constraint | patch
scope           触れると予想されるファイル/モジュール
owner           責任を負う人間またはエージェント
status          proposed | executing | fulfilled | drifted | abandoned
source          manual | commit | inferred | agent-session

正式な契約 (Design by Contract):
  preconditions    この意図が実行される前に真でなければならないこと
  postconditions   達成されたときに真でなければならないこと
  invariants       全体を通して、そしてその後も真であり続けなければならないこと

ドリフト = 述語の失敗。 シンボルは、その現在の動作がそれを作成したReasonNodeのpostconditionsを満たさなくなったとき、または不変条件が侵害されたときにドリフトしたと見なされます。


6つのエッジタイプ

CREATES      Reason  → Symbol   (この意図がこの関数を作成した)
MODIFIES     Reason  → Symbol   (この意図がこの関数を変更した)
REQUIRES     Reason  → Reason   (BはAが最初に完了していることに依存する)
DUPLICATES   Reason  → Reason   (これら2つの目標は重複している)
VALIDATED_BY Reason  → Test     (このテストは意図が満たされたことを証明する)
DRIFTS_FROM  Symbol  → Reason   (このシンボルはもはや作成された目的を果たしていない)

6次元ドリフトモデル

次元 意味 検出
Spec drift MODIFIESエッジなしでシンボルのチェックサムが変更された 保存されたチェックサムと現在のチェックサムを比較
Decision drift Postconditionsがもはや保持されない コードベースに対して述語を評価
Ownership drift 一貫した監視なしに3人以上の異なる所有者 エッジ上の固有の所有者の数をカウント
Test drift VALIDATED_BYテストが見つからないか失敗している テストファイルの存在を確認 + 実行
Usage drift シンボルが元のスコープ外で使用されている スコープ外のインポートをgrepで検索
Dependency drift 下流のREQUIRES理由がドリフトしている REQUIRESエッジをたどる

icpg drift check を実行して、すべての次元をスキャンします。それぞれが0-1の深刻度スコアを生成します。


CLIリファレンス

セットアップ

icpg init                          # .icpg/ とデータベースを作成
icpg bootstrap --days 90           # Git履歴からReasonNodesを推論
icpg bootstrap --days 90 --no-llm  # LLMなし (コミットメッセージのみ)

作成と記録

icpg create "Add JWT auth" --scope src/auth/ --owner feature-auth --type task
icpg record --reason <id> --base main         # Git diffからシンボルを記録
icpg record --reason <id> --edge-type MODIFIES # 変更として記録

クエリ (3つの典型的なクエリ)

icpg query prior "user authentication"     # 1. 重複検出
icpg query constraints src/auth/service.ts  # 2. ファイルの不変条件
icpg query risk validateToken              # 3. シンボルのリスクプロファイル
icpg query context src/auth/service.ts     # ファイルのすべての意図
icpg query blast <reason-id>               # 完全な影響範囲

ドリフト

icpg drift check          # 全次元にわたるフルスキャン
icpg drift resolve <id>   # ドリフトイベントを解決済みとしてマーク

ステータス

icpg status               # 統計: 理由、シンボル、エッジ、ドリフト

ストレージ

プロジェクトごと、gitignored、インフラストラクチャ不要:

.icpg/
  reason.db       SQLiteデータベース (4つのテーブル: reasons, symbols, edges, drift_events)
  .gitignore      内容: *
  chroma/         ChromaDBベクトル (chromadbがインストールされている場合)
  tfidf_cache.json  TF-IDFフォールバックキャッシュ
  .current-intent   アクティブな意図を示すマーカーファイル (Stopフックで使用)

インストールオプション:

pip install ./scripts/icpg            # コア (依存関係なし)
pip install "./scripts/icpg[vectors]"  # + 重複検出のためのChromaDB
pip install "./scripts/icpg[all]"      # + ChromaDB + scikit-learn + openai

ワークフロー: コード変更前

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

iCPG Skill (Intent-Augmented Code Property Graph)

Purpose: Add a Reason Graph layer on top of code structure so every function, class, and module is traceable to the goal that created it, the agent or human that owns it, and whether it's still doing what it was supposed to do.

┌────────────────────────────────────────────────────────────────┐
│  iCPG = AST + CFG + PDG + RG (Reason Graph)                    │
│  ─────────────────────────────────────────────────────────────│
│  AST  = Abstract Syntax Tree (structure)      ← existing       │
│  CFG  = Control Flow Graph (execution paths)  ← existing       │
│  PDG  = Program Dependency Graph              ← existing       │
│  RG   = Reason Graph (WHY layer)              ← THIS SKILL     │
│                                                                │
│  The RG stores ReasonNodes (goals/tasks), links them to code   │
│  symbols via typed edges, enforces contracts (DbC), and        │
│  detects when code drifts from its original purpose.           │
│                                                                │
│  Storage: .icpg/reason.db (SQLite, per-project, gitignored)   │
│  CLI: icpg init | create | record | query | drift | bootstrap │
└────────────────────────────────────────────────────────────────┘

Core Principle

Intent first, code second. Before writing or modifying code, query the reason graph to understand WHY existing code was written, WHAT constraints it must preserve, and WHETHER your change duplicates prior work.


The 3 Canonical Pre-Task Queries

Every agent MUST run these before writing code:

# Query Command What It Answers
1 search_prior_work icpg query prior "<goal>" Has this been attempted before? Prevents duplication.
2 get_constraints icpg query constraints <file> What invariants apply to files I'll touch? Prevents breakage.
3 get_risk_profile icpg query risk <symbol> Is this symbol fragile? Drift history, ownership changes.

ReasonNode — The Core Primitive

Each ReasonNode captures a stated purpose with a formal contract:

id              UUID
goal            Natural language: what is this trying to achieve
decision_type   business_goal | arch_decision | task | workaround | constraint | patch
scope           Files/modules expected to be touched
owner           Human or agent accountable
status          proposed | executing | fulfilled | drifted | abandoned
source          manual | commit | inferred | agent-session

FORMAL CONTRACT (Design by Contract):
  preconditions    What must be true before this intent executes
  postconditions   What must be true when fulfilled
  invariants       What must remain true throughout and after

Drift = predicate failure. A symbol has drifted when its current behavior no longer satisfies the postconditions of the ReasonNode that created it, or when an invariant is violated.


Six Edge Types

CREATES      Reason  → Symbol   (this intent created this function)
MODIFIES     Reason  → Symbol   (this intent changed this function)
REQUIRES     Reason  → Reason   (B depends on A being done first)
DUPLICATES   Reason  → Reason   (these two goals overlap)
VALIDATED_BY Reason  → Test     (this test proves the intent was satisfied)
DRIFTS_FROM  Symbol  → Reason   (this symbol no longer does what it was made for)

6-Dimension Drift Model

Dimension What It Means Detection
Spec drift Symbol checksum changed without a MODIFIES edge Compare stored vs current checksum
Decision drift Postconditions no longer hold Evaluate predicates against codebase
Ownership drift >3 different owners without coherent oversight Count unique owners on edges
Test drift VALIDATED_BY tests missing or failing Check test file existence + run
Usage drift Symbol used outside original scope Grep for imports beyond scope
Dependency drift Downstream REQUIRES reasons have drifted Traverse REQUIRES edges

Run icpg drift check to scan all dimensions. Each produces a 0-1 severity score.


CLI Reference

Setup

icpg init                          # Create .icpg/ and database
icpg bootstrap --days 90           # Infer ReasonNodes from git history
icpg bootstrap --days 90 --no-llm  # Without LLM (commit-message only)

Create & Record

icpg create "Add JWT auth" --scope src/auth/ --owner feature-auth --type task
icpg record --reason <id> --base main         # Record symbols from git diff
icpg record --reason <id> --edge-type MODIFIES # Record as modifications

Query (the 3 canonical queries)

icpg query prior "user authentication"     # 1. Duplicate detection
icpg query constraints src/auth/service.ts  # 2. Invariants for file
icpg query risk validateToken              # 3. Symbol risk profile
icpg query context src/auth/service.ts     # All intents for a file
icpg query blast <reason-id>               # Full blast radius

Drift

icpg drift check          # Full scan across all dimensions
icpg drift resolve <id>   # Mark drift event resolved

Status

icpg status               # Stats: reasons, symbols, edges, drift

Storage

Per-project, gitignored, zero infrastructure:

.icpg/
  reason.db       SQLite database (4 tables: reasons, symbols, edges, drift_events)
  .gitignore      Contains: *
  chroma/         ChromaDB vectors (if chromadb installed)
  tfidf_cache.json  TF-IDF fallback cache
  .current-intent   Marker file for active intent (used by Stop hook)

Install options:

pip install ./scripts/icpg            # Core (zero deps)
pip install "./scripts/icpg[vectors]"  # + ChromaDB for duplicate detection
pip install "./scripts/icpg[all]"      # + ChromaDB + scikit-learn + openai

Workflow: Before Any Code Change

0. INTENT       → icpg create (or identify existing intent)
1. DEDUP        → icpg query prior (check for duplicate work)
2. CONSTRAINTS  → icpg query constraints (understand invariants)
3. RISK         → icpg query risk (check fragile symbols)
4. LOCATE       → search_graph to find symbols (code-graph skill)
5. CHANGE       → Make the edit (PreToolUse hook shows context)
6. RECORD       → icpg record (link symbols to intent)
7. DRIFT CHECK  → icpg drift check (verify no unintended drift)
8. VERIFY       → Run tests, lint, typecheck

Step 0 is non-negotiable for autonomous agents. Every change must be linked to a stated purpose. Without an intent, there's nothing to measure drift against.


Hook Integration

PreToolUse Hook (automatic context injection)

Add to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "scripts/icpg-pre-edit.sh",
        "timeout": 3,
        "statusMessage": "Checking intent context..."
      }]
    }]
  }
}

Before every file edit, agents see:

═══ iCPG CONTEXT ═══
INTENTS for src/auth/service.ts:
  [>] a1b2c3d4 — User authentication with JWT tokens
      Owner: feature-auth | Status: executing
      Invariants: 2
CONSTRAINTS for src/auth/service.ts:
  From intent: User authentication with JWT tokens
    INV: file_exists("src/auth/middleware.ts")
    POST: test_exists("src/auth/__tests__/service.test.ts")
PRESERVE function signatures unless your task requires changing them.
═══════════════════

Stop Hook (automatic symbol recording)

After implementation passes tests, auto-records symbols:

{
  "hooks": {
    "Stop": [{
      "hooks": [
        {"type": "command", "command": "scripts/tdd-loop-check.sh", "timeout": 60},
        {"type": "command", "command": "scripts/icpg-stop-record.sh", "timeout": 5}
      ]
    }]
  }
}

Agent Teams Integration

Updated Pipeline (agent-teams + iCPG)

 0. INTENT       Team lead creates ReasonNode from feature spec
 0b. DEDUP       icpg query prior — check for duplicate intents
 1. SPEC         Feature agent writes spec
 2. SPEC-REVIEW  Quality agent reviews spec + intent alignment
 3. TESTS (RED)  Feature agent writes tests
 4. RED-VERIFY   Quality agent verifies tests fail
 5. IMPLEMENT    Feature agent codes (PreEdit hook shows context)
 5b. RECORD      Auto-record symbols → intent (Stop hook)
 5c. DRIFT-CHECK Quality agent verifies no scope drift
 6. GREEN-VERIFY Quality agent verifies tests pass + coverage
 7. VALIDATE     Lint + typecheck + full suite
 8. CODE-REVIEW  Review agent (sees intent context per file)
 9. SECURITY     Security agent
10. BRANCH-PR    Merger agent (PR includes intent traceability)

Agent Responsibilities

Agent iCPG Action
Team Lead icpg create when creating task chains. icpg query prior to check duplicates.
Feature Agent icpg query constraints before implementing. Writes .icpg/.current-intent for auto-recording.
Quality Agent icpg drift check during GREEN verify. Verifies scope alignment.
Review Agent Sees intent context via PreToolUse hook when reviewing files.
Merger Agent Includes intent traceability in PR description.

Bootstrapping from Git History

For existing codebases, infer ReasonNodes from commit history:

icpg bootstrap --days 90 --verbose

This will:

  1. Get commits from last 90 days
  2. Cluster by temporal proximity (2-hour window)
  3. Infer intent via LLM (Claude or OpenAI) or commit message parsing
  4. Create ReasonNodes with source: "inferred", confidence: 0.6-0.8
  5. Extract symbols from changed files, create CREATES edges
  6. Run duplicate detection against existing ReasonNodes

Quality note: Inferred intents are marked low-confidence. Review and promote high-value ones manually.


Contract Predicates

Predicates are structured assertions over codebase state:

file_exists("src/auth/middleware.ts")
test_exists("src/auth/__tests__/service.test.ts")
symbol_count("src/auth/") <= 15
function_signature("validateToken") == "(token: string) => Promise<User>"

Contracts can be:

  • Hand-authored for high-risk ReasonNodes
  • LLM-inferred via icpg create --infer-contracts
  • Heuristic (scope → file_exists, test → test_exists)

Anti-Patterns

Anti-Pattern Do This Instead
Coding without stating intent icpg create before every non-trivial change
Assuming your change is isolated icpg query constraints + icpg query risk first
Rebuilding what already exists icpg query prior to check for prior work
Leaving intent in 'executing' forever Update status to 'fulfilled' when done
Ignoring drift events icpg drift check weekly, resolve or create new intents
Storing full source in symbols Store signature + checksum only — read source from files
Skipping bootstrap on existing repos icpg bootstrap --days 90 to build initial graph