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 hook)以及一次性的 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.
