源碼佈局
src/
main.c Entry point(MCP stdio server + CLI + install/update/config)
daemon/ 每帳號的 session 協調:IPC、lifecycle、共享 jobs/watchers
mcp/ MCP server(15 tools、JSON-RPC 2.0、session detection、auto-index)
cli/ install/uninstall/update/config(43 client surfaces、hooks)
store/ SQLite 圖儲存(nodes、edges、traversal、search、Louvain)
pipeline/ 多 pass 索引(structure → definitions → calls → HTTP → config → tests)
cypher/ Cypher query lexer、parser、planner、executor
discover/ 檔案發現(.gitignore、.cbmignore、symlink 處理)
watcher/ 背景 auto-sync(git polling、adaptive intervals)
traces/ Runtime trace ingestion
ui/ Embedded HTTP server + 3D graph visualization
foundation/ 平台抽象(threads、filesystem、logging、memory)
internal/cbm/ Vendored tree-sitter grammars(158 語言)+ AST extraction engine
模組職責表
| 模組 | 職責 | 程式碼對照 |
main.c | 單一二進位入口,分派到 MCP server / CLI / install / update / config | main.c → |
daemon/ | 一帳號一協調 daemon:跨 session 共享 watcher/索引/UI;admission barrier | daemon/ → |
mcp/ | 15 個 MCP 工具的註冊與執行、JSON-RPC 2.0、session detection、auto-index | mcp/mcp.c → |
cli/ | install/uninstall/update/config;43 個 client surface;hooks/instructions 安裝 | cli/cli.c → |
store/ | SQLite 圖儲存:節點/邊、BFS 遍歷、BM25 搜尋、Louvain 社群 | store/store.c → |
pipeline/ | 多 pass 索引調度(pipeline.c)+ pass 註冊(registry.c) | pipeline/ → |
cypher/ | openCypher 唯讀子集的編譯與執行 | cypher/cypher.c → |
discover/ | 收集要索引的檔案:硬編碼模式 → .gitignore → .cbmignore;symlink 永遠跳過 | discover/ → |
watcher/ | 背景檔案監看,偵測變更後自動增量重索引 | watcher → |
traces/ | runtime trace 收納(ingest_traces 工具) | — |
ui/ | 嵌入式 HTTP server + 3D 圖形界面(--ui 變體,localhost:9749) | ui/ → |
foundation/ | 平台抽象:arena 記憶體、執行緒、檔案系統、regex、診斷 | — |
索引 pass 順序
索引不是一個大函式,而是一串 pass,各自職責單一:
| Pass | 做什麼 |
pass_definitions | 抽取函式/類別/方法等定義節點 |
pass_calls | 建 CALLS 邊(import-aware、型別推斷) |
pass_lsp_cross / lsp_surface | Hybrid LSP 跨檔型別解析 |
pass_route_nodes | REST 端點變一級圖實體(Route 節點) |
pass_cross_repo | 跨 repo 的 CROSS_* 邊 |
pass_infrascan / pass_k8s | IaC:Dockerfile、K8s manifests、Kustomize overlays |
pass_pkgmap | 套件解析(package.json / go.mod / Cargo.toml / pyproject.toml…) |
pass_similarity | MinHash + LSH 近複製偵測(SIMILAR_TO) |
pass_semantic* | 語意邊(SEMANTICALLY_RELATED) |
pass_gitdiff / pass_githistory | 變更耦合(detect_changes 用) |
pass_parallel | 平行 worker 調度(worker pool) |
資料流
repo ──discover──▶ 檔案清單 ──tree-sitter AST──▶ 結構節點/邊
│
▼ Hybrid LSP(型別解析)
精煉 CALLS / CALL_REFERENCE
│
store/(SQLite)◀──多 pass 管線──(HTTP routes、IaC、相似度…)
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
15 MCP tools Cypher engine 3D UI (--ui)
看完這頁你應該能說出:CBM 由哪幾個模組組成、索引是「多 pass」而非單一函式、Hybrid LSP 夾在 tree-sitter 與 store 之間做型別精煉、以及哪些 pass 產出 Route / CROSS_* / SIMILAR_TO 邊。