josippapez/ai-setup/tree/main/claude/plugins/repo-docs
repo-docs
為單一儲存庫提供本機語意文件搜尋、已安裝套件查詢與 JS/TS 檔案影響範圍工具。由 dev-core 和 orchestrate 共用。
關於這個 mod
這是單一儲存庫的本機語意文件搜尋、已安裝套件查詢,以及 JS/TS 檔案影響範圍工具。它從 dev-core 拆出,讓 dev-core 和 orchestrate 共用同一個 MCP 伺服器與工具命名空間,不必各自綁定相同副本。
使用這些工具的每個外掛,都必須在自己的 README/skill 宣告 repo-docs 為相依項目;若 mcp__plugin_repo-docs_repo-docs__ 無法呼叫,也必須告訴使用者安裝它。* claude/install.sh 會和 dev-core、orchestrate 一起自動安裝。
版面
- .mcp.json — repo-docs 伺服器(runtime/):find_docs、list_docs、read_doc、find_libs、get_file_dependents、get_blast_radius。內容涵蓋 Markdown 慣例、已安裝套件,以及哪些 JS/TS 檔案直接或傳遞式匯入某個檔案,也會解析 tsconfig 的 paths 別名與工作區套件名稱。
- hooks/ — 相依設定、索引生命週期。
- commands/ — /reindex 與 /repo-docs-ignore。
自動安裝相依套件
不需要手動執行 npm install。SessionStart hook(hooks/hooks.json)會在第一次工作階段把 npm install 安裝到外掛的持久化資料目錄(${CLAUDE_PLUGIN_DATA}/node_modules),每當 package.json 變更時也會再次執行;MCP 伺服器透過 NODE_PATH 解析相依套件。第一次工作階段安裝 @huggingface/transformers 時可能需要等待(bge-small 模型約 128 MB);後續相依套件會在外掛更新間保留,工作階段會立即啟動。Embedding/reranker 模型預設快取在共用目錄 ~/.claude/repo-docs-models,也可用 REPO_DOCS_MODELS_DIR 覆寫。
連線時預熱文件索引
MCP 連線時會在背景預先嵌入儲存庫的 Markdown(fire-and-forget,透過 mtime 快取增量執行),因此第一次 find_docs 不必承擔索引成本。find_docs 會執行分塊混合搜尋(BM25 關鍵字 + 密集 bge-small 嵌入),按檔案回傳最符合的區塊、區段錨點與摘要。每個區塊會獨立嵌入一次,再把文件路徑與標題階層線索放在前面嵌入第二次;兩種排名融合後,交叉編碼器(bge-reranker-base)會為前 10 名投票。投票每次呼叫約增加半秒;傳入 rerank: false,或為每次呼叫設定 RERANK_ENABLED=0,即可略過。模型仍在載入,或第一次索引尚未建立時,find_docs 會用關鍵字評分器回答,並在標頭說明。預設 read_doc 回傳原始檔案,因此 find_docs 的行號能對應;compact: true 會回傳精簡的讀取結果。任何時候都可以用 /reindex 或 node runtime/tools/build-semantic-index.cjs <repo-root> 強制重建變更檔案的索引(完整重建前先刪除 .claude/repo-docs/)。
每次觸及 Markdown 檔案的工作階段結束時,hooks/reindex.ts 的外掛會執行 hooks/reindex-on-edit.cjs,透過本機 socket(.claude/repo-docs/inject.sock)要求執行中的伺服器重新嵌入變更文件,因此不用重新連線,中途編輯的文件也能搜尋。
在 0.3.0 移除
get_file_dependents 和 get_blast_radius 在 CodeGraph 取代它們後被移除,並在 0.5.0 恢復。在一次 TypeScript 單一儲存庫的實測影響任務中,CodeGraph 列出 16 個受影響檔案中的 9 個,get_blast_radius 則列出全部 16 個。搬移、重新命名、刪除或變更 API 前,使用它們取得檔案清單。CodeGraph 本身在 0.6.0 從外掛移除。主動文件指標注入(UserPromptSubmit 與 PostToolBatch hooks)及一次性的 Grep/Glob 提醒,在 39 個工作階段注入 1,879 次卻沒有任何後續 read_doc 使用後被移除。
結束時回收
SessionEnd hook(hooks/reap-mcp-on-exit.cjs)會在結束時終止本工作階段自己的 standalone-mcp.cjs 程序——Claude Code 不一定會回收外掛 MCP 伺服器,否則它們會持續累積。
測試
node --test claude/plugins/repo-docs/hooks/*.test.cjs claude/plugins/repo-docs/runtime/lib/*.test.cjs claude/plugins/repo-docs/runtime/tools/*.test.cjs
Mod
hooks/status.ts 會在 .claude/repo-docs/index-build.lock 存在時顯示「repo-docs: indexing docs…」和建置百分比,建置完成時顯示 toast。
- hooks/transcript.tsx 將 /repo-docs:reindex Bash 呼叫畫成「Reindex repo docs」,並將結果顯示為一行重新嵌入、未變更與略過文件的數量。
- hooks/reindex.ts 取代舊的 PostToolUse 重新索引 hook:一輪結束時,若該輪透過 Edit、Write 或點名某個 Markdown 檔案的 Bash 指令觸及它,就要求執行中的伺服器重新嵌入變更文件一次。
安裝
請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。
claude plugin marketplace add josippapez/ai-setup claude plugin install repo-docs
原文 / README
repo-docs
Local semantic doc search, installed-package lookup and JS/TS file-impact tools for one repository. Split out of dev-core so dev-core and orchestrate share one MCP server and one tool namespace instead of each bundling an identical copy.
Any plugin that uses its tools must declare repo-docs as a dependency in its own README/skill and tell the user to install it if mcp__plugin_repo-docs_repo-docs__* is not callable. claude/install.sh installs it automatically alongside dev-core and orchestrate.
Layout
.mcp.json— therepo-docsserver (runtime/):find_docs,list_docs,read_doc,find_libs,get_file_dependents,get_blast_radius. Markdown conventions, installed packages, and which JS/TS files import a file (directly or transitively, resolving tsconfigpathsaliases and workspace package names).hooks/— dependency setup, index lifecycle.commands/—/reindexand/repo-docs-ignore.
Dependencies auto-install
No manual npm install. A SessionStart hook (hooks/hooks.json) runs npm install into the plugin's persistent data dir (${CLAUDE_PLUGIN_DATA}/node_modules) on first session and again whenever package.json changes; the MCP server resolves them via NODE_PATH. The first session may take a moment while @huggingface/transformers installs (the bge-small model is ~128 MB); later sessions are instant (deps persist across plugin updates). Embedding/reranker models are cached in a shared dir — ~/.claude/repo-docs-models by default, override with the REPO_DOCS_MODELS_DIR env var.
Docs index warms on connect
The MCP pre-embeds the repo's Markdown in the background when it connects (fire-and-forget, incremental via an mtime cache), so the first find_docs doesn't pay the indexing cost. find_docs runs a chunked hybrid search (BM25 keyword + dense bge-small embeddings) and returns, per file, the best-matching chunk with its section anchor and a snippet. Each chunk is embedded twice, on its own and with its doc path and heading breadcrumb in front; the two rankings are fused, and a cross-encoder (bge-reranker-base) votes on the top 10. The vote adds about half a second per call; pass rerank: false, or set RERANK_ENABLED=0 for every call, to skip it. While the model is still loading or before the first index build, find_docs answers with a keyword scorer and says so in its header. read_doc returns the raw file by default, so find_docs line numbers line up; compact: true returns a minified read. Force a rebuild of changed files any time with /reindex or node runtime/tools/build-semantic-index.cjs <repo-root> (delete .claude/repo-docs/ first for a full rebuild).
At the end of a turn that touched a Markdown file, the mod in hooks/reindex.ts runs hooks/reindex-on-edit.cjs, which asks the running server, over a local socket (.claude/repo-docs/inject.sock), to re-embed changed docs, so mid-session doc edits are searchable without a reconnect.
Removed in 0.3.0
get_file_dependents and get_blast_radius came back in 0.5.0 after CodeGraph replaced them: on a measured impact task in a TypeScript monorepo, CodeGraph listed 9 of 16 affected files and get_blast_radius listed all 16. Use them for the file list before a move, rename, delete or API change. CodeGraph itself was dropped from the plugin in 0.6.0. The proactive doc-pointer injection (UserPromptSubmit and PostToolBatch hooks) and the one-shot Grep/Glob reminder were removed after measuring 1,879 injections across 39 sessions with zero read_doc follow-ups.
Reap on exit
A SessionEnd hook (hooks/reap-mcp-on-exit.cjs) kills this session's own standalone-mcp.cjs process on exit — Claude Code doesn't always reap plugin MCP servers, so they'd otherwise accumulate across sessions.
Tests
node --test claude/plugins/repo-docs/hooks/*.test.cjs claude/plugins/repo-docs/runtime/lib/*.test.cjs claude/plugins/repo-docs/runtime/tools/*.test.cjs
Mod
hooks/status.ts shows "repo-docs: indexing docs…" with the build percentage while .claude/repo-docs/index-build.lock exists, and a toast when the build finishes.
hooks/transcript.tsxdraws the/repo-docs:reindexBash call as "Reindex repo docs" and its result as a one-line count of re-embedded, unchanged and skipped docs.hooks/reindex.tsreplaces the oldPostToolUsereindex hook: when a turn ends, if it touched a markdown file through Edit, Write or a Bash command naming one, it asks the running server to re-embed changed docs once.
