|
| 1 | +<!doctype html> |
| 2 | +<html lang="ja"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <title>CodeGraphとは何か</title> |
| 7 | + <link rel="stylesheet" href="../styles/site.css"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + <main class="article-page"> |
| 11 | + <a class="back-link" href="../index.html">← 一覧へ戻る</a> |
| 12 | + |
| 13 | + <article class="article-shell"> |
| 14 | + <p class="eyebrow">AI / コード探索</p> |
| 15 | + <h1>CodeGraphとは何か</h1> |
| 16 | + <p class="article-date">作成日: 2026年6月14日</p> |
| 17 | + |
| 18 | + <section> |
| 19 | + <h2>要点</h2> |
| 20 | + <ul> |
| 21 | + <li>CodeGraph は、コードベースをローカルで索引化して、エージェントが構造質問へ直接答えやすくするためのコードインテリジェンス基盤です。</li> |
| 22 | + <li>価値は「検索できること」だけではなく、MCP ツール経由で symbol、caller、callee、impact、explore をまとめて返せることにあります。</li> |
| 23 | + <li>README では auto-sync、framework-aware routes、20以上の言語対応を前面に出しており、実装上も `CodeGraph` クラスが抽出、解決、探索、文脈生成、DB を束ねています。</li> |
| 24 | + </ul> |
| 25 | + </section> |
| 26 | + |
| 27 | + <section> |
| 28 | + <h2>何をするツールか</h2> |
| 29 | + <p>CodeGraph は、`grep` とファイル読みを何度も繰り返す代わりに、あらかじめ構築したローカル索引からコード構造を返すための仕組みです。README では「semantic code intelligence」「100% local」を打ち出していて、エージェントに MCP server をつなぐ形で使います。</p> |
| 30 | + <figure class="diagram-card"> |
| 31 | + <svg viewBox="0 0 920 230" role="img" aria-label="CodeGraphの基本フロー"> |
| 32 | + <rect x="20" y="55" width="190" height="120" rx="22" fill="#fff7ed" stroke="#c2410c" stroke-width="2"/> |
| 33 | + <text x="115" y="98" text-anchor="middle" font-size="28" font-weight="700" fill="#9a3412">コードベース</text> |
| 34 | + <text x="115" y="132" text-anchor="middle" font-size="20" fill="#7c2d12">TypeScript</text> |
| 35 | + <text x="115" y="158" text-anchor="middle" font-size="20" fill="#7c2d12">Python / Go / Rust...</text> |
| 36 | + |
| 37 | + <path d="M210 115 H330" stroke="#9ca3af" stroke-width="4" stroke-linecap="round"/> |
| 38 | + <polygon points="330,115 312,105 312,125" fill="#9ca3af"/> |
| 39 | + |
| 40 | + <rect x="330" y="35" width="240" height="160" rx="22" fill="#fafaf9" stroke="#57534e" stroke-width="2"/> |
| 41 | + <text x="450" y="78" text-anchor="middle" font-size="28" font-weight="700" fill="#1c1917">CodeGraph</text> |
| 42 | + <text x="450" y="112" text-anchor="middle" font-size="20" fill="#44403c">index</text> |
| 43 | + <text x="450" y="138" text-anchor="middle" font-size="20" fill="#44403c">reference resolve</text> |
| 44 | + <text x="450" y="164" text-anchor="middle" font-size="20" fill="#44403c">context build</text> |
| 45 | + |
| 46 | + <path d="M570 115 H690" stroke="#9ca3af" stroke-width="4" stroke-linecap="round"/> |
| 47 | + <polygon points="690,115 672,105 672,125" fill="#9ca3af"/> |
| 48 | + |
| 49 | + <rect x="690" y="35" width="210" height="54" rx="18" fill="#eff6ff" stroke="#2563eb" stroke-width="2"/> |
| 50 | + <text x="795" y="68" text-anchor="middle" font-size="20" font-weight="700" fill="#1d4ed8">MCP tools</text> |
| 51 | + |
| 52 | + <rect x="690" y="103" width="210" height="54" rx="18" fill="#f0fdfa" stroke="#0f766e" stroke-width="2"/> |
| 53 | + <text x="795" y="136" text-anchor="middle" font-size="20" font-weight="700" fill="#0f766e">codegraph_explore</text> |
| 54 | + |
| 55 | + <rect x="690" y="171" width="210" height="34" rx="16" fill="#f5f3ff" stroke="#7c3aed" stroke-width="2"/> |
| 56 | + <text x="795" y="193" text-anchor="middle" font-size="16" font-weight="700" fill="#6d28d9">search / callers / impact</text> |
| 57 | + </svg> |
| 58 | + <figcaption class="diagram-caption">コードを前もって索引化し、その結果を MCP ツールとしてエージェントへ返す構造です。</figcaption> |
| 59 | + </figure> |
| 60 | + </section> |
| 61 | + |
| 62 | + <section> |
| 63 | + <h2>何がうれしいか</h2> |
| 64 | + <div class="mini-grid"> |
| 65 | + <div class="mini-card"> |
| 66 | + <h3>探索が短い</h3> |
| 67 | + <p>構造質問を `codegraph_explore` などで直接引けるので、探索用の grep が減ります。</p> |
| 68 | + </div> |
| 69 | + <div class="mini-card"> |
| 70 | + <h3>ローカル完結</h3> |
| 71 | + <p>README では SQLite ベースの 100% local を前面に出しています。</p> |
| 72 | + </div> |
| 73 | + <div class="mini-card"> |
| 74 | + <h3>編集後も追随</h3> |
| 75 | + <p>watcher と connect-time catch-up により索引の古さを抑えます。</p> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + <figure class="diagram-card"> |
| 79 | + <svg viewBox="0 0 920 250" role="img" aria-label="通常探索とCodeGraph利用の違い"> |
| 80 | + <rect x="30" y="25" width="380" height="190" rx="24" fill="#fff7ed" stroke="#c2410c" stroke-width="2"/> |
| 81 | + <text x="220" y="62" text-anchor="middle" font-size="28" font-weight="700" fill="#9a3412">CodeGraphなし</text> |
| 82 | + <text x="220" y="102" text-anchor="middle" font-size="20" fill="#7c2d12">find / grep / read</text> |
| 83 | + <text x="220" y="130" text-anchor="middle" font-size="20" fill="#7c2d12">↓</text> |
| 84 | + <text x="220" y="158" text-anchor="middle" font-size="20" fill="#7c2d12">候補を何度も絞る</text> |
| 85 | + <text x="220" y="186" text-anchor="middle" font-size="20" fill="#7c2d12">探索コストが増える</text> |
| 86 | + |
| 87 | + <rect x="510" y="25" width="380" height="190" rx="24" fill="#f0fdfa" stroke="#0f766e" stroke-width="2"/> |
| 88 | + <text x="700" y="62" text-anchor="middle" font-size="28" font-weight="700" fill="#0f766e">CodeGraphあり</text> |
| 89 | + <text x="700" y="102" text-anchor="middle" font-size="20" fill="#115e59">explore / node / callers</text> |
| 90 | + <text x="700" y="130" text-anchor="middle" font-size="20" fill="#115e59">↓</text> |
| 91 | + <text x="700" y="158" text-anchor="middle" font-size="20" fill="#115e59">構造化された答えを返す</text> |
| 92 | + <text x="700" y="186" text-anchor="middle" font-size="20" fill="#115e59">探索回数を減らせる</text> |
| 93 | + </svg> |
| 94 | + <figcaption class="diagram-caption">価値の中心は「検索が少し速い」ではなく、「構造質問の入口が直接用意される」ことです。</figcaption> |
| 95 | + </figure> |
| 96 | + </section> |
| 97 | + |
| 98 | + <section> |
| 99 | + <h2>公開されている主なツール面</h2> |
| 100 | + <ul> |
| 101 | + <li><code>codegraph_explore</code>: 構造質問の主入口</li> |
| 102 | + <li><code>codegraph_search</code>: symbol を探す</li> |
| 103 | + <li><code>codegraph_callers</code> / <code>codegraph_callees</code>: 呼び出し関係を辿る</li> |
| 104 | + <li><code>codegraph_impact</code>: 変更影響をみる</li> |
| 105 | + <li><code>codegraph_node</code>: 特定 symbol のソースを引く</li> |
| 106 | + <li><code>codegraph_status</code> / <code>codegraph_files</code>: 索引状態や対象ファイルを確認する</li> |
| 107 | + </ul> |
| 108 | + </section> |
| 109 | + |
| 110 | + <section> |
| 111 | + <h2>内部はどう分かれているか</h2> |
| 112 | + <p>メモと `src/index.ts` を見る限り、`CodeGraph` クラスが主要コンポーネントを束ねる構造です。説明しやすい分け方は、抽出、参照解決、探索、文脈生成、保存の5つです。</p> |
| 113 | + <figure class="diagram-card"> |
| 114 | + <svg viewBox="0 0 920 300" role="img" aria-label="CodeGraphの内部構成"> |
| 115 | + <rect x="300" y="20" width="320" height="62" rx="22" fill="#fafaf9" stroke="#57534e" stroke-width="2"/> |
| 116 | + <text x="460" y="58" text-anchor="middle" font-size="28" font-weight="700" fill="#1c1917">CodeGraph class</text> |
| 117 | + |
| 118 | + <rect x="40" y="120" width="240" height="58" rx="18" fill="#fff7ed" stroke="#c2410c" stroke-width="2"/> |
| 119 | + <text x="160" y="155" text-anchor="middle" font-size="20" font-weight="700" fill="#9a3412">ExtractionOrchestrator</text> |
| 120 | + |
| 121 | + <rect x="340" y="120" width="240" height="58" rx="18" fill="#fefce8" stroke="#ca8a04" stroke-width="2"/> |
| 122 | + <text x="460" y="155" text-anchor="middle" font-size="20" font-weight="700" fill="#a16207">ReferenceResolver</text> |
| 123 | + |
| 124 | + <rect x="640" y="120" width="240" height="58" rx="18" fill="#eff6ff" stroke="#2563eb" stroke-width="2"/> |
| 125 | + <text x="760" y="155" text-anchor="middle" font-size="20" font-weight="700" fill="#1d4ed8">GraphQueryManager</text> |
| 126 | + |
| 127 | + <rect x="190" y="220" width="240" height="58" rx="18" fill="#f0fdfa" stroke="#0f766e" stroke-width="2"/> |
| 128 | + <text x="310" y="255" text-anchor="middle" font-size="20" font-weight="700" fill="#0f766e">GraphTraverser</text> |
| 129 | + |
| 130 | + <rect x="490" y="220" width="240" height="58" rx="18" fill="#f5f3ff" stroke="#7c3aed" stroke-width="2"/> |
| 131 | + <text x="610" y="255" text-anchor="middle" font-size="20" font-weight="700" fill="#6d28d9">ContextBuilder</text> |
| 132 | + |
| 133 | + <rect x="720" y="220" width="160" height="58" rx="18" fill="#ecfeff" stroke="#0891b2" stroke-width="2"/> |
| 134 | + <text x="800" y="255" text-anchor="middle" font-size="20" font-weight="700" fill="#0e7490">DB</text> |
| 135 | + |
| 136 | + <line x1="460" y1="82" x2="160" y2="120" stroke="#9ca3af" stroke-width="3"/> |
| 137 | + <line x1="460" y1="82" x2="460" y2="120" stroke="#9ca3af" stroke-width="3"/> |
| 138 | + <line x1="460" y1="82" x2="760" y2="120" stroke="#9ca3af" stroke-width="3"/> |
| 139 | + <line x1="460" y1="178" x2="310" y2="220" stroke="#9ca3af" stroke-width="3"/> |
| 140 | + <line x1="460" y1="178" x2="610" y2="220" stroke="#9ca3af" stroke-width="3"/> |
| 141 | + <line x1="760" y1="178" x2="800" y2="220" stroke="#9ca3af" stroke-width="3"/> |
| 142 | + </svg> |
| 143 | + <figcaption class="diagram-caption">抽出して、参照を解決し、問い合わせや文脈生成に使い、その結果をローカル DB に載せる構造です。</figcaption> |
| 144 | + </figure> |
| 145 | + </section> |
| 146 | + |
| 147 | + <section> |
| 148 | + <h2>扱うデータの考え方</h2> |
| 149 | + <ul> |
| 150 | + <li><strong>nodes</strong>: file、class、function、route、component などのコード要素</li> |
| 151 | + <li><strong>edges</strong>: contains、calls、imports、references などの関係</li> |
| 152 | + <li><strong>unresolved_refs</strong>: まだ解決しきれていない参照</li> |
| 153 | + </ul> |
| 154 | + <div class="compare-box"> |
| 155 | + <p>ただの全文索引ではなく、構造化ノードと関係エッジを持つので、caller や impact のような質問に向いています。</p> |
| 156 | + </div> |
| 157 | + </section> |
| 158 | + |
| 159 | + <section> |
| 160 | + <h2>使い始める流れ</h2> |
| 161 | + <ol> |
| 162 | + <li><code>codegraph install</code> で agent 側の MCP 設定を入れる</li> |
| 163 | + <li>対象リポジトリで <code>codegraph init -i</code> を実行する</li> |
| 164 | + <li>`.codegraph/` ができたら、agent から `codegraph_explore` などを使う</li> |
| 165 | + <li>編集後は watcher と connect-time catch-up で索引を追随させる</li> |
| 166 | + </ol> |
| 167 | + <figure class="diagram-card"> |
| 168 | + <svg viewBox="0 0 920 180" role="img" aria-label="CodeGraphの導入手順"> |
| 169 | + <rect x="20" y="55" width="170" height="70" rx="20" fill="#fff7ed" stroke="#c2410c" stroke-width="2"/> |
| 170 | + <text x="105" y="97" text-anchor="middle" font-size="20" font-weight="700" fill="#9a3412">install</text> |
| 171 | + <path d="M190 90 H260" stroke="#9ca3af" stroke-width="4" stroke-linecap="round"/> |
| 172 | + <polygon points="260,90 242,80 242,100" fill="#9ca3af"/> |
| 173 | + |
| 174 | + <rect x="260" y="55" width="170" height="70" rx="20" fill="#fefce8" stroke="#ca8a04" stroke-width="2"/> |
| 175 | + <text x="345" y="97" text-anchor="middle" font-size="20" font-weight="700" fill="#a16207">init -i</text> |
| 176 | + <path d="M430 90 H500" stroke="#9ca3af" stroke-width="4" stroke-linecap="round"/> |
| 177 | + <polygon points="500,90 482,80 482,100" fill="#9ca3af"/> |
| 178 | + |
| 179 | + <rect x="500" y="55" width="170" height="70" rx="20" fill="#eff6ff" stroke="#2563eb" stroke-width="2"/> |
| 180 | + <text x="585" y="97" text-anchor="middle" font-size="20" font-weight="700" fill="#1d4ed8">explore</text> |
| 181 | + <path d="M670 90 H740" stroke="#9ca3af" stroke-width="4" stroke-linecap="round"/> |
| 182 | + <polygon points="740,90 722,80 722,100" fill="#9ca3af"/> |
| 183 | + |
| 184 | + <rect x="740" y="55" width="160" height="70" rx="20" fill="#f0fdfa" stroke="#0f766e" stroke-width="2"/> |
| 185 | + <text x="820" y="97" text-anchor="middle" font-size="20" font-weight="700" fill="#0f766e">auto-sync</text> |
| 186 | + </svg> |
| 187 | + <figcaption class="diagram-caption">最初に install と init を済ませると、あとは explore 系を入口にして使い続けやすくなります。</figcaption> |
| 188 | + </figure> |
| 189 | + </section> |
| 190 | + |
| 191 | + <section> |
| 192 | + <h2>向いている場面</h2> |
| 193 | + <ul> |
| 194 | + <li>大きめのリポジトリで、毎回 grep と Read を繰り返すのが重いとき</li> |
| 195 | + <li>call flow、route、impact のような構造質問が多いとき</li> |
| 196 | + <li>Claude Code、Codex、Cursor など複数 agent に同じ索引を使わせたいとき</li> |
| 197 | + </ul> |
| 198 | + </section> |
| 199 | + |
| 200 | + <section> |
| 201 | + <h2>まとめ</h2> |
| 202 | + <p>CodeGraph は、コードをローカルで索引化し、エージェントに構造化された入口を与えるための基盤です。強みは単なる検索速度ではなく、`explore`、`callers`、`impact` のようなコード理解用ツール面と、watcher を含む継続運用のしやすさにあります。</p> |
| 203 | + </section> |
| 204 | + |
| 205 | + <section> |
| 206 | + <h2>参考URL</h2> |
| 207 | + <ul> |
| 208 | + <li><a href="https://github.com/colbymchenry/codegraph">CodeGraph GitHub repository</a></li> |
| 209 | + <li><a href="https://colbymchenry.github.io/codegraph/">CodeGraph documentation site</a></li> |
| 210 | + </ul> |
| 211 | + </section> |
| 212 | + </article> |
| 213 | + </main> |
| 214 | +</body> |
| 215 | +</html> |
0 commit comments