前言¶
在 DeepSeek Harness(DSH)裏用 codebase-memory 做代碼圖與檢索時,Harness 往往只爲整個應用維持一條 MCP 連接,codebase-memory 側難以知道「當前 Session 實際在哪個 workspace」。結果是各項目常見 watch.reason: not_session_project,索引不會隨 Session 自動更新。若你依賴已建好的 codebase-memory 索引、又會在 DSH 裏開多個 Session 或頻繁切換工作目錄,就需要在 Session 生命週期裏顯式把「當前目錄」對應的索引刷新到最新。
下面介紹社區插件 dsh-cbm-autorefresh(維護者 xingbei437,SkillHub 分類爲「記憶」):在 Session 創建、工作目錄變更以及插件熱加載時,針對該 Session 自己的工作目錄調用 codebase-memory CLI 執行 refresh,而不常駐額外後臺進程。
這是什麼¶
dsh-cbm-autorefresh 是 DeepSeek Harness 插件,描述爲:爲每個 Session 在其自身 working directory 上刷新 codebase-memory 索引。源碼與說明見 GitHub 倉庫,社區目錄頁爲 SkillHub。許可證 MIT;package.json 標明版本 0.1.0,運行環境要求 dsh >=0.2.0 且 <0.4.0、Node >=20。
它與「首次全量建索引」分工不同:插件不創建新索引,只刷新已存在且與 git 倉庫根路徑匹配的項目。
核心功能¶
根據 README,插件在以下時機觸發刷新(每次爲短時 CLI 調用,無變更時約 1–3 秒;重度索引由 codebase-memory 共享 daemon 承擔,N 個 Session 不會對應 N 個常駐進程):
session/created:刷新該 Session 當前工作目錄對應的索引。working-directory/change:刷新切換到的新目錄對應索引。- 插件 (re)load:對當時已存在的 Session 做補償刷新。
內部流程概覽:從 Session 工作目錄用 git rev-parse --show-toplevel 取倉庫根;用 codebase-memory-mcp cli list_projects --format json 找 root_path 匹配的項目;再執行 codebase-memory-mcp cli index_repository --repo-path <root>。
行爲與邊界(節選):
| 情況 | 結果 |
|---|---|
| Session 落在已索引倉庫 | 刷新索引(無變更時約 1–3 s) |
| Session 切換到另一已索引倉庫 | 刷新該倉庫索引 |
| 倉庫尚未建索引 | 跳過並記日誌(首次索引需人工 deliberate) |
| 非 git 工作目錄 | 跳過並記日誌 |
同目錄在 minIntervalMs 內 |
節流跳過 |
| 同倉庫已在刷新中 | single-flight 跳過 |
已知限制:長時間在同一目錄大量編輯、且既不新開會話也不換目錄時,主要靠 session 開始時刷新;若需更密觸發需自行擴展。本機須已安裝 codebase-memory-mcp(配置項 binary 或環境變量 $CBM_BIN)。
安裝與啓用¶
在 DSH profile 目錄(示例 ~/.dsh/profiles/desktop)安裝依賴:
# in your DSH profile directory, e.g. ~/.dsh/profiles/desktop
pnpm add dsh-cbm-autorefresh
在 profile 的 package.json 裏把 bundle 加入清單後重載 profile:
// package.json
{
"dsh": {
"profile": {
"bundles": ["@deepseek-ai/dsh-base", "dsh-cbm-autorefresh"]
}
}
}
包內自帶 cordis.patch.yml 會自動掛載;若要在 profile patch 裏關閉:
- id: cbm-autorefresh
disabled: true
配置¶
在 profile patch 中可覆蓋插件配置(字段以 README 爲準):
- id: cbm-autorefresh
name: dsh-cbm-autorefresh
config:
enabled: true # false turns every trigger off
binary: /path/to/codebase-memory-mcp # default: $CBM_BIN, then ~/.local/bin/codebase-memory-mcp
minIntervalMs: 300000 # per-directory throttle (default 5 minutes)
timeoutMs: 600000 # per CLI call timeout (default 10 minutes)
logFile: /tmp/cbm-autorefresh.log # optional: also append every refresh line to a file
enabled: false 會關閉全部觸發;minIntervalMs 默認 5 分鐘,用於按目錄節流;單次 CLI 超時默認 10 分鐘。
典型用法¶
啓用 bundle 並保證 codebase-memory-mcp 在 PATH 或通過 binary / $CBM_BIN 指定後,無需額外 API 調用:打開 DSH Session 或切換工作目錄到已經納入 codebase-memory 的 git 倉庫時,插件會自動嘗試 refresh。若目錄未索引或非 git 倉庫,可在日誌或可選的 logFile 中查看跳過原因。
開發與自測方面,倉庫提供:
npm test
適用場景與注意¶
適合:已在機器上爲各項目建好 codebase-memory 索引,並在 DSH 中多 Session、多倉庫切換,希望索引跟當前 Session 目錄對齊而非長期 not_session_project 的場景。
安裝前建議閱讀 GitHub 源碼 與 MIT 許可證;插件以當前 DSH 進程權限執行 git 與 codebase-memory CLI,profile 與 binary 路徑應與你本機安全策略一致。SkillHub 等社區目錄爲獨立站點,與 DeepSeek / 幻方無官方從屬關係,插件也不代表官方應用商店條目。
星標等目錄元數據以 SkillHub 頁面爲準(抓取時爲 0)。
結尾¶
dsh-cbm-autorefresh 補齊 Harness 單連接 MCP 下 codebase-memory 無法感知 Session 工作區的問題:按 Session 與工作目錄刷新已有索引,短生命週期 CLI、共享 daemon 索引,適合作爲 DSH「記憶」類能力鏈中的一環。