用 graphify 分析 codebase-memory-mcp

meta 示範:用「另一個知識圖譜工具」掃描 CBM 自己的源碼
語料:src/ + tests/(440 檔)· 對齊 commit 2c50c77 · graphify 0.9.36
產出出處:本案例的互動圖與報告由 graphify(Apache-2.0)產生。graphify 是另一個開源知識圖譜工具(Leiden 社群偵測、EXTRACTED/INFERRED 信任標籤、互動 HTML 輸出);本站用它來分析 codebase-memory-mcp 自己,呈現「知識圖譜工具 × 知識圖譜工具」的對照。產出資料在 worked/cbm-source/

為什麼做這個案例

codebase-memory-mcp(CBM)本身就是一個把 codebase 變知識圖譜的工具。用 graphify 再掃一次 CBM 的源碼,有幾個教學價值:

語料

上游 main @ 2c50c77(2026-08-08)的第一方程式碼:

部分內容檔案數
src/CBM 主體 C 源碼(main/mcp/store/cypher/cli/pipeline/daemon/discover/semantic/ui…)193
tests/測試(6,768 tests 的 C 測試碼、Hybrid LSP 各語系測試)247
合計純 C 語料(--code-only,零 LLM 成本)440

刻意排除 internal/cbm/vendored/(974 檔第三方 tree-sitter grammars 生成碼)與 docs/assets——圖要呈現「CBM 自己的工程」,不是第三方生成碼。

本站跑的數字

指標本站實測
語料檔案數440
節點15,815
61,988
社群343(最大社群 602 節點 = C++ Hybrid LSP tests)
互動圖社群聚合檢視(343 社群節點 / 1,977 跨社群邊)
LLM / API 成本0(純 AST,本機執行)
工具版本graphify 0.9.36

God Nodes(核心抽象)

graphify 報告指出連接最多邊的「樞紐節點」——正是 CBM 架構中最關鍵的函式:

函式邊數位置
find_resolved()679LSP 解析核心(各語系共用)
extract_cpp()609C++ AST 抽取器
cbm_store_close()568SQLite 圖儲存關閉(全域生命週期)
cbm_mkdtemp()522平台相容的臨時目錄(跨模組共用)
extract_rust()498Rust AST 抽取器

社群對應模組

343 個社群,最大的幾個直接對應 CBM 的模組:

社群(graphify 命名)節點對應 CBM 模組
C++ Hybrid LSP tests602tests/test_c_lsp.c
Rust LSP resolution tests355tests/test_rust_lsp.c
Agent registry & profiles287src/cli/agent_profiles.c
MCP JSON-RPC server219src/mcp/mcp.c
Daemon IPC & sockets196src/daemon/ipc.c
Cypher query engine136src/cypher/cypher.c
File discovery & gitignore147src/discover/

完整 343 社群清單見 GRAPH_REPORT.md

互動圖

CBM 源碼知識圖譜(社群聚合檢視) 英文界面 ↗中文界面 ↗

因為全圖 15,815 節點超過 graphify 的 5,000 節點視覺化上限,自動聚合為社群檢視——這反而是好事:一眼看到整個 CBM 的模組結構與跨模組呼叫。

如何重現

# 0. 安裝 graphify(PyPI 套件名 graphifyy,雙 y)
uv tool install graphifyy

# 1. 準備語料(只保留第一方程式碼)
git clone https://github.com/DeusData/codebase-memory-mcp.git cbm
git -C cbm checkout 2c50c7741ec89dbcf43c2c85e005c0b58a4dbbf3
mkdir corpus && cp -R cbm/src corpus/ && cp -R cbm/tests corpus/

# 2. 跑完整 pipeline(code-only,零 API key)
graphify corpus --code-only

# 3. 產出在 graphify-out/
#    graph.html  互動圖(社群聚合檢視)
#    graph.json  全量圖資料(15,815 nodes / 61,988 edges)
#    GRAPH_REPORT.md  審計報告

# 4. 中文化 UI(選擇性)
cp graphify-out/graph.html graphify-out/graph-zh.html
# 替換 lang="en" → lang="zh-Hant" 及 UI 字串(Search / Node Info / Communities…)

已知限制

看完這個案例你應該能說出:CBM 的模組邊界在哪、為什麼 cbm_store_close() 是所有模組的生命週期樞紐、以及 graphify 與 CBM 兩種知識圖譜工具的哲學差異。