rekipedia 完整教學 — Codebase 變成 AI-Ready 知識庫

一份「裝起來就能用」的 internal tutorial,給團隊內部準備把 rekipedia 跑進工作流的同事看。 目標版本:v0.17.29 (2026-05-28),MIT License。


1. 專案定位

rekipedia 是一套**把任何 codebase 掃成「AI agent 可 query 的知識庫」**的 CLI 工具。它做三件事:

  1. Index:tree-sitter 抽出 symbols + relationships,存進 SQLite (.rekipedia/store.db)
  2. Wiki:用 LLM (optional) 為每個 module / 重要 file 生成 markdown wiki page
  3. Serve:透過 (a) CLI reki ask (b) web UI reki serve (c) MCP stdio server reki mcp 三種介面對外提供 Q&A

與類似專案的差異

工具取向與 rekipedia 差異
GitHub Copilot Workspace雲端、商業rekipedia 本地、開源、可離線
sourcegraph cody程式碼搜尋rekipedia 多了 wiki + impact analysis + MCP server
gitnexus (本專案 Layer 6)程式碼符號圖rekipedia 多了 LLM-generated wiki page + RAG
graphify (本專案 Layer 4)知識圖 + community detectionrekipedia 偏 codebase-only,graphify 是 generic

為什麼要關注:MCP server 直接給 Claude Code / Cursor 用,6 個 tool(ask / search_nodes / get_context / get_relationships / get_hub_nodes / get_impact)讓 agent 在「有 citation」的條件下回答 codebase 問題,理論上可以顯著降低 agent hallucination。


2. 安裝指南

2.1 PyPI 安裝(最簡單)

1pip install rekipedia
2# or
3pipx install rekipedia
4# or one-shot
5npx rekipedia

需求:Python 3.11+。

2.2 從 source 安裝(開發者用)

1git clone --depth 1 https://github.com/unrealandychan/rekipedia.git
2cd rekipedia
3pip install -e ".[dev]"
4# or with uv (推薦)
5uv sync

2.3 LLM 設定(optional but 推薦)

1export REKIPEDIA_API_KEY=sk-...        # OpenAI / Anthropic / OpenAI-compatible
2export REKIPEDIA_MODEL=gpt-4o          # 預設 gpt-4o
3# Ollama 範例
4export REKIPEDIA_API_KEY=ollama
5export REKIPEDIA_MODEL=ollama/llama3

--no-llm 可完全離線跑,只是 wiki 不會有 LLM-generated summary。

2.4 Docker Sandbox(optional,加強 isolation)

1docker build -f Dockerfile.sandbox -t rekipedia-sandbox:latest .

如果 sandbox image 不存在,rekipedia 會 fallback 到 LocalRunner(純 Python,無容器隔離)。

2.5 首次掃描

1cd <your-repo>
2reki scan .          # 全掃,生成 wiki + 知識庫
3reki embed .         # (optional)建立 FAISS 語義索引,啟用 hybrid RAG
4reki ask "what is the entry point of this codebase?"

知識庫位置:.rekipedia/store.db(純本地,不上雲)。


3. 核心架構解析

rekipedia 是個模組化 Python 套件,src/rekipedia/ 下有 17 個子模組。下圖標出主要資料流:


flowchart TD
    A[Codebase] -->|tree-sitter| B[extractors.py]
    B --> C[(SQLite store.db)]
    C --> D[analysis/]
    D -->|graph_analysis| E[hotspots / impact]
    C --> F[synthesis/page_builder]
    F -->|LLM via litellm| G[wiki/ markdown pages]
    G --> H[rag/embedder + FAISS]
    H --> I[orchestrator/run_ask]
    C --> I
    I --> J1[CLI: reki ask]
    I --> J2[Web UI: reki serve]
    I --> J3[MCP Server: reki mcp]
    K[.rekipedia/] -->|store| C
    K -->|wiki/| G
    K -->|embeddings/| H

3.1 子模組職責表

模組功能關鍵檔案
cli/24 個 CLI 子指令scan.py / ask.py / mcp_server.py / refactor.py
extractors/tree-sitter 多語抽取(在 sandbox 內執行)
models/Pydantic dataclass共用資料結構
storage/SQLite schema + migrationmigrations/
analysis/graph 分析 / impact / refactor 偵測graph_analysis.py / refactor_detector.py (12KB)
synthesis/LLM 生成 wiki page / diagrampage_builder.py / diagram_builder.py
rag/FAISS embedding + vector storeembedder.py (33.7KB)
llm/litellm client + token counterclient.py
orchestrator/高階流程編排run_ask.py (17.8KB) / run_digest.py (21KB) / run_update.py (13.6KB)
server/Flask/FastAPI web UIapp.py (37KB)
sandbox/Docker / Local runnerrunner.py + Dockerfile.sandbox
watcher/filesystem watch + auto reindexwatcher.py

3.2 資料流(reki ask 路徑)


flowchart LR
    Q[User Question] --> A[orchestrator/run_ask]
    A --> S1[rag/vector_store FAISS]
    A --> S2[(SQLite store.db)]
    S1 -->|top-k chunks| M[LLM prompt]
    S2 -->|symbol:line| M
    M --> R[LLM via litellm]
    R --> O[Answer + file:line citations]

3.3 MCP Server 架構

src/rekipedia/cli/mcp_server.py(13KB)實作 stdio MCP server,提供 6 個 tool:

MCP Tool對應 reki CLI
askreki ask
search_nodesreki search
get_context(讀 .rekipedia/wiki/<page>.md
get_relationshipsreki impact
get_hub_nodesreki hotspots
get_impactreki diff + impact analysis

Claude Code / Cursor 透過 .mcp.json 自動發現,agent 直接呼叫這 6 個 tool。


4. Helper Scripts 詳細用法

rekipedia 沒有大量 helper script — 主要入口就是 reki CLI(24 個 subcommand)。逐項說明:

4.1 索引 / Build

指令說明常用 flag
reki scan .全掃,建立 store + wiki--no-llm(不呼叫 LLM)
reki update .增量更新(只重跑 changed file)--impact-only(只重生受影響 wiki)
reki embed .建立 / 重建 FAISS 索引
reki watch .filesystem watch → auto reindex

4.2 Query / Read

指令說明常用 flag
reki ask "<q>"Q&A,回 file:line citation--brief(短答案)
reki serve .啟動 web UI http://127.0.0.1:7070
reki search "<keyword>"symbol / file 搜尋
reki tourguided onboarding walkthrough
reki onboard .為新人生成 onboarding doc

4.3 Analysis / Refactor

指令說明
reki hotspots找 hub / bridge node(refactor 前必看)
reki diff顯示 uncommitted change 的 impact
reki impact <file>算某個檔案的下游影響
reki refactor . --dry-run預覽 refactor 建議
reki refactor . --apply套用 safe 的 refactor 建議
reki reviewLLM-powered PR review

4.4 Export / Integration

指令說明
reki export . --format md|zip|json|html匯出 wiki
reki mcp啟動 MCP stdio server
reki hook install安裝 git post-commit hook(commit 後自動 update wiki)
reki note編輯 / 加 note 到某 wiki page

4.5 Makefile(開發者)

1make install       # uv sync
2make dev           # install runtime + dev deps
3make lint          # ruff / mypy / 寫報告
4make test          # pytest
5make test-cov      # pytest --cov
6make build         # Python wheel + npm tarball
7make docker-build  # 編 sandbox image
8make release       # PyPI + npm

4.6 scripts/lint-and-report.sh

唯一的 helper script(11.8KB),跑完整 lint pipeline(ruff / mypy / 整理報告)。make lint 內部呼叫它。


5. 應用場景

5.1 個人 dev 日常

1# 在新專案目錄
2reki scan .
3reki ask "where does database connection get initialized?"
4reki ask "what tests exist for the auth module?"

5.2 New hire 第一週

1reki onboard .      # 生成 onboarding doc
2reki tour           # guided walkthrough
3reki ask "如何在本地起 dev server?"

5.3 Refactor 前 due diligence

1reki hotspots                    # 找關鍵檔案,動之前先看
2reki impact src/core/engine.py   # 算下游影響
3reki refactor . --dry-run        # 預覽建議

5.4 Claude Code / Cursor MCP 整合

在 repo root 放 .mcp.json

1{
2  "mcpServers": {
3    "rekipedia": {
4      "command": "reki",
5      "args": ["mcp"],
6      "cwd": "."
7    }
8  }
9}

Claude Code 啟動時自動發現,agent 之後問 codebase 問題會走 rekipedia 的 grounded answer 路徑。

5.5 CI / CD 整合

1# .github/workflows/wiki.yml
2- name: Update rekipedia wiki
3  uses: unrealandychan/rekipedia/action@v0.17.26
4  with:
5    api-key: ${{ secrets.REKIPEDIA_API_KEY }}

5/27 才剛 release 的官方 GitHub Action,把 reki update . 跑成 CI step,每次 push 自動 reindex wiki。

5.6 在本專案(AI-knowledge_template v1)整合的想法

  • 可能取代 / 補充現有 Layer 4 graphify:rekipedia 更 codebase-centric,graphify 是 generic knowledge graph
  • 可能補充 Layer 6 gitnexus:rekipedia 多了 LLM-generated wiki page + impact analysis
  • 不建議直接取代:rekipedia LLM 呼叫成本不可忽略(每 scan 都會跑 page_builder 用 LLM),graphify / gitnexus 純靜態分析省 API cost

6. 資安掃描報告

6.1 掃描結論

風險級別標的結論
🟢 低subprocess 使用模式全部用 list-form subprocess.run([...])shell=True;命令未拼接使用者輸入
🟢 低Docker sandbox--network none --read-only --tmpfs /tmp -v repo:/repo:ro,網路阻斷 + read-only + tmpfs,符合 isolation best practice
🟢 低LLM 機密處理透過 env var (REKIPEDIA_API_KEY),不寫進 store.db / wiki / 任何輸出
🟢 低pickle 使用只在 wiki 內文字字串中提到 pickle(作為 “可疑模組” 警示),未在程式碼真實使用 pickle.load
🟡 中eval / exec 字串出現出現在 synthesis/page_builder.pydiagram_builder.py 的 “可疑模組黑名單”(給 LLM 提示用),程式碼本身未呼叫 eval/exec — 但 LLM prompt 中夾帶這些字串會被某些 prompt-injection scanner 誤判
🟡 中urllib.urlopen in cli/review.py:142用於 PR review 抓 GitHub API,timeout=30,未驗證 SSL hostname pin(依賴 certifi CA bundle)— 對大多數情境 OK,但若內網有 MITM proxy 需注意
🟡 中subprocess.call([editor, tmp_path]) in cli/note.py:113editor 來自環境變數($EDITOR / $VISUAL),若使用者環境變數被惡意改寫可能被劫持,但這是 Unix 慣用模式,風險可控
🟡 中__import__("os") in run_digest.py:432-435用於 lazy import,無安全問題,但靜態 lint 容易誤報;建議改用直接 import os
🔴 高(未發現)

6.2 整體結論

🟢 GREEN — 可在內部團隊使用

  • 沒有發現任何 RCE / SSRF / SQL injection 等高風險 pattern
  • subprocess 與 Docker sandbox 設計合理,無 shell=True
  • 機密透過 env var 處理,不留 trace
  • 唯一需要注意:啟用 --apply flag 跑 reki refactor 會自動改 source code(5/26 新加的 feature),首次使用務必先 --dry-run 確認

6.3 給 internal 採用的建議

  • 先在 sandbox repo 跑過一次 reki refactor . --dry-run + reki scan . 確認輸出
  • LLM 呼叫透過 internal LiteLLM proxy(已有 REKIPEDIA_MODEL env 可指)
  • 大型 repo 跑 reki scan 前先 du -sh . 預估 token cost(page_builder 對每個 module 都會呼叫 LLM)

7. FAQ

Q1: 沒有 LLM API key 能用嗎? A: 可以。reki scan . --no-llm 跑完整 indexing + symbol graph,只是 wiki 沒有 LLM summary。Hotspots / impact / search 都不需要 LLM。

Q2: 知識庫多大? A: .rekipedia/store.db 通常 5–50 MB(依 repo 大小)。FAISS embedding 額外 ~10–100 MB。

Q3: 支援哪些語言? A: tree-sitter extractors 內建 Python / Go / TypeScript / Rust / Java。其他語言會被當 generic text 處理。

Q4: 跟 RAG 框架(langchain / llamaindex)差別? A: rekipedia 是 codebase-specific,內建 symbol graph + impact analysis;langchain / llamaindex 是 generic RAG framework,需要自己寫 codebase 的 extractor 與 graph 邏輯。

Q5: 可以多人共用一個 store.db 嗎? A: 設計上是 single-user single-machine。團隊共用建議用 reki export . --format zip 把 wiki + store 一起 commit 進 repo,或用 5/28 release 的 GitHub Action 讓 CI 跑 update。

Q6: 跑一次 reki scan 成本? A: 以 gpt-4o 為例,10K 行 codebase ~ $0.5–2 USD。--no-llm 模式 $0。

Q7: 跟本專案 graphify Layer 衝突嗎? A: 不衝突。graphify 偏 generic knowledge graph(適合多 source:code + docs + paper),rekipedia 純 codebase。可以同時用,職責互補。


8. 進階技巧

8.1 對特定 module 跑 ask

1reki ask "explain the orchestrator module" --scope src/rekipedia/orchestrator/

8.2 結合 git hook 自動更新

1reki hook install   # 寫入 .git/hooks/post-commit
2# 之後每次 commit 自動跑 reki update .

8.3 用 Ollama 完全離線

1export REKIPEDIA_API_KEY=ollama
2export REKIPEDIA_MODEL=ollama/qwen2.5-coder:14b
3reki scan .

8.4 把 wiki 變 GitHub Pages

1reki export . --format html --out docs/
2# 然後在 GitHub repo settings 開 Pages 指向 docs/

8.5 在 CI 跑 --impact-only 加速

1reki update . --impact-only --since HEAD~1

只重生最新一個 commit 影響到的 wiki page,CI 時間從幾分鐘降到幾秒。


9. 整合進其他工作流

9.1 與 Claude Code (MCP)

.mcp.json 後,Claude 在問「auth 在哪」前會自動呼叫 reki ask,回答帶 file:line citation。

9.2 與 paper-qa-lite (Layer 10)

paper-qa-lite 處理 paper PDF;rekipedia 處理 codebase。兩者完全互補,可以在同一個 research project 內並用:

  • paper-qa-lite → 回答「論文裡怎麼說 X 演算法」
  • rekipedia → 回答「我們專案哪裡實作了 X 演算法」

9.3 與 graphify (Layer 4)

graphify 跑完 graphify init . 產出 generic knowledge graph;rekipedia 跑完 reki scan . 產出 codebase wiki。兩個 output 都進到 agent context 後,agent 對 codebase 的回答品質會比單獨用任何一個都好(兩者 grounding source 不同)。

9.4 與 gh-tutorial-qd (Layer 12)

本份 tutorial md 即是 gh-tutorial-qd 的產出範例。rekipedia 不在 gh-tutorial-qd 上游 pipeline 內,但 rekipedia 的 README + AGENTS.md 是 gh-tutorial-qd 抓 metadata 的好標的。


10. 重點摘要 Checklist

  • pip install rekipedianpx rekipedia
  • 設定 REKIPEDIA_API_KEYREKIPEDIA_MODEL(或直接 --no-llm
  • cd <repo> && reki scan . 首次掃描
  • reki embed . 建立 FAISS 索引(optional)
  • 試問:reki ask "what is the entry point?"
  • .mcp.json 讓 Claude Code / Cursor 自動發現
  • CI 加 GitHub Action 自動 update(v0.17.26+)
  • Refactor 前先 reki hotspots + reki impact <file>
  • reki refactor . --dry-run 預覽後再 --apply

11. 進一步閱讀

  • 主 README:https://github.com/unrealandychan/rekipedia#readme
  • 中文 README:README.zh-TW.md
  • AGENTS.md(agent 用法詳解):https://github.com/unrealandychan/rekipedia/blob/main/AGENTS.md
  • rekipedia-agent-skill.md(Claude skill 整合範例):repo root
  • GitHub Pages:https://unrealandychan.github.io/rekipedia/
  • PyPI:https://pypi.org/project/rekipedia/
  • MCP 規範:https://modelcontextprotocol.io
  • 本專案相關 Layer:Layer 4 graphify、Layer 6 gitnexus、Layer 10 paper-qa-lite、Layer 12 gh-tutorial-qd