前言¶
在 DeepSeek Harness(DSH)裏做代碼相關任務時,Agent 往往只能靠 grep、glob 猜關鍵詞,尤其在「用中文描述行爲、答案藏在英文標識符裏」的場景,容易反覆試探仍定位失敗。社區插件 dsh-coderag(維護者 VermilionPasvikin)以 MCP 服務器形態提供只讀的代碼庫檢索:建索引、按自然語言或標識符查符號,返回文件路徑、行號與符號名,供 Agent 再按行讀原文。下面介紹它的能力、安裝步驟與使用注意。
這是什麼¶
dsh-coderag 是給 DSH 用的代碼庫檢索引擎,默認不聯網、不採集遙測;只讀代碼,不改倉庫。插件通過 Cordis patch 向 Agent 暴露 4 個固定 MCP 工具(DSH 側名稱帶 mcp__coderag__ 前綴):
| 工具 | 作用 |
|---|---|
code_search |
按自然語言或標識符檢索,返回文件路徑、行號、符號名 |
code_outline |
單文件的符號大綱 |
code_index |
建立或刷新索引,立即返回 taskId,後臺執行 |
index_status |
查看索引狀態與跳過統計 |
索引落在工作區 <工作區>/.coderag/index.sqlite3,採用 SQLite FTS5、中文 bigram,並用 tree-sitter 按函數/類/接口等邊界分塊;支持增量索引。檢索使用 BM25,同一批命中按源碼順序輸出,便於模型按行號讀文件。索引未就緒、無結果或後端不可用時,會返回結構化 status,避免 Agent 把「沒查到」誤當成「不存在」。
當前發佈版本爲 2.1.1(僅 GitHub tag/release,無 PyPI/npm 包)。SkillHub 分類爲「聯網工具」;項目自述側重本地索引與檢索。
核心功能(已文檔說明的部分)¶
- 索引與安全:三層過濾(內置密鑰黑名單、
.gitignore/.coderagignore、內容級正則),命中 chunk 不入庫,跳過原因對模型可見(skipped: {count, reasons})。 - 檢索策略:召回精度遞進(全詞元 → 僅標識符 → 含 CJK bigram);純標點/過短符號查詢會提示改用
grep,避免全表掃描。 - 異步與預算:
code_index立即返回、後臺建索引(規避工具調用約 60 秒超時);單次檢索有 token 預算,超出部分會報告省略條數。 - 實測對比(README 口徑):在 DSH 源碼副本上 13 個「找代碼」任務、各 3 次會話的對比中,僅多掛本插件 patch 的一組任務成功率由約 28.2% 升至約 82.1%;「用中文問、答案在英文代碼裏」的定位/跨文件類嘗試改善明顯,直查標識符類未變差。樣本偏檢索型題目,不宜直接外推爲全量提問的提升幅度;詳見倉庫
eval/runs/報告。
安裝與啓用¶
前置:Python 3.10–3.12、已安裝 DSH、Git。README 註明 macOS、Windows 10 已實測;Linux 尚未實測,項目不聲稱支持 Linux。
安裝需克隆倉庫(cordis.patch.yml 在倉庫內),不能使用 pip install dsh-coderag 或 npm i dsh-coderag。
macOS / Linux(POSIX)¶
先進入希望存放倉庫的目錄,再執行:
cd ~
git clone https://github.com/VermilionPasvikin/dsh-coderag.git
cd dsh-coderag
bash scripts/install.sh
自檢引擎(不涉及 DSH):
"$CODERAG_PYTHON" -m dsh_coderag doctor
"$CODERAG_PYTHON" -m dsh_coderag index /path/to/repo
"$CODERAG_PYTHON" -m dsh_coderag search "用戶令牌在哪裏校驗" --root /path/to/repo
掛到 DSH 的 web profile 並確認:
./scripts/dsh plugin --profile web add .
./scripts/dsh --profile web --dump-config | grep -A2 '== dsh-coderag'
期望輸出中出現 # == dsh-coderag 與 id: mcp-coderag。啓動:
./scripts/dsh --profile web
受限網絡可在安裝依賴時使用:CODERAG_PIP_ARGS="--index-url <鏡像>" bash scripts/install.sh。
Windows(PowerShell)¶
需使用真實 Python 3.10–3.12(可用 py -0p 查看),並確認當前使用的 DSH profile(桌面版多爲 desktop)。克隆、安裝與驗證示例:
git clone https://github.com/VermilionPasvikin/dsh-coderag.git
Set-Location dsh-coderag
& $py -m pip install .
& $py -m dsh_coderag doctor
$repo = "C:\path\to\your\repo"
& $py -m dsh_coderag index $repo
& $py -m dsh_coderag search "用戶令牌在哪裏校驗" --root $repo
將 CODERAG_PYTHON 寫入 profile 的 cordis.patch.yml 更可靠(桌面版快捷方式通常繼承不到終端環境變量)。修改 profile 前需完全退出 DeepSeek Harness 桌面版,否則 dsh plugin add 可能被拒絕。再用本機 dsh.cmd 或全局 dsh:
& $dsh plugin --profile $profile add .
詳細 Windows 路徑與 ZIP 離線解壓說明見 GitHub README。
典型用法¶
- Agent 側:在工作區對話中先觸發
code_index(或 CLI 預建索引),用index_status確認就緒,再用code_search查行爲描述或符號;需要單文件結構時用code_outline。 - CLI 側(調試或與 DSH 無關的批處理):
dsh_coderag index <repo>、dsh_coderag search "<query>" --root <repo>,與 MCP 共用同一套索引目錄。
大倉庫首次索引在後臺進行;文件數超過上限時會顯式失敗並報告實際數量。
適用場景與注意¶
適合:中大型倉庫裏「描述行爲找實現」「跨文件跟鏈路」、中英文混查檢索;希望減少 Agent 盲目 grep 的會話。
務必閱讀的安全聲明(README 原文要點):安裝本插件等於授予其與當前 DSH 進程相近的本機權限;DSH 的 read-only / workspace-write / danger-full-access 不約束插件。請只在信任的倉庫與本機上安裝,安裝前閱讀源碼與 MIT 許可證。
插件默認不聯網;索引與查詢均在本地完成。
結尾¶
dsh-coderag 把「語義 + 結構」檢索做成 DSH 可調用的 MCP 工具,與 grep 互補:複雜定位交給檢索,精確符號仍可直接查。目錄與詳情可在 SkillHub 與 GitHub 查看:
- 目錄頁:https://www.skillhub.cn/plugins/VermilionPasvikin/dsh-coderag
- 倉庫:https://github.com/VermilionPasvikin/dsh-coderag