前言¶
在 DSH 會話中,agent 探索代碼時常依賴 grep 和逐文件讀取。這種做法會把大量文件內容帶入上下文,增加 token 消耗。
Miku196/dsh-tokensave 將 tokensave 的本地語義圖引擎接入 DSH,讓 agent 用語義查詢代替暴力 grep/讀文件,節省 token。
這是什麼¶
Miku196/dsh-tokensave 是一個 DSH 插件,由 Miku196 維護,許可證爲 MIT。
它把 tokensave 的本地語義圖能力接入 DSH,並在 apply 時執行 init/sync,自動索引與同步。0.2.0 起通過 cli 直連提供 tokensave_* 工具,無 serve 進程、無 MCP。
核心能力¶
下面介紹插件的主要能力:
1、在系統提示詞中注入工具指導,引導模型優先使用語義圖工具。
2、提供 search、callers、callees、body、entities、status、dead_code、circular 等語義圖工具。
3、工具調用自動跟隨會話工作目錄,向上查找最近索引,全新目錄自動 init。
4、啓動時檢查 tokensave 新版本並告警。
5、自動把 .tokensave/ 加入 .gitignore。
6、binary 缺失時只告警,不阻塞 profile 啓動,也不注入提示詞。
安裝與啓用¶
以下命令使用 web profile 示例。
前置條件:
1、tokensave 已安裝(cargo install tokensave,或從 GitHub Releases 下載並放入 PATH)。
2、dsh 可用,且 profile 目錄有 pnpm。
從 GitHub 安裝:
dsh plugin --profile web add github:Miku196/dsh-tokensave
本地開發安裝:
dsh plugin --profile web add file:/path/to/dsh-tokensave
更新插件:
dsh plugin --profile web update dsh-tokensaver
該插件爲 bundle 插件,默認零配置。保存配置後 dsh web 會自動熱重載,新會話中模型即可調用 tokensave_search、tokensave_callers 等工具。
不要 insert 同名 tokensaver 條目,重複聲明會導致 dsh 崩潰。
典型用法¶
工具調用形式爲:
tokensave tool <name> --args <json>
新會話中,模型可調用 tokensave_search、tokensave_callers 等工具。工具調用會跟隨會話工作目錄,並向上查找最近索引;全新目錄會自動 init。
tokensave 只在精確目錄找索引;插件會向上查找祖先索引,並在找不到索引時自動 init。主目錄及其直接子目錄永不自動 init,避免誤索引整個主目錄。
需要固定操作根時,在 $DSH_HOME/profiles/web/cordis.patch.yml 中按 id tokensaver 配置 config.binary、config.cwd、config.autoSync:
- id: tokensaver
config:
binary: tokensave
cwd: /path/to/your/project
autoSync: true
config 是整體替換,未寫出的字段會回落到插件 schema 默認值。
0.2.0 起僅支持 cli 直連,MCP 模式已移除;配置 bridge 爲 mcp 會報錯。
適用場景與注意¶
適合在 DSH 會話中需要 agent 通過語義圖查詢理解代碼、降低上下文消耗的場景。
使用注意:
1、插件依賴 tokensave 可執行文件;binary 缺失時只告警,不阻塞 profile 啓動,也不注入提示詞。
2、插件以當前 dsh 進程權限運行,安裝前應檢查源碼與許可證。
3、許可證爲 MIT。
參考鏈接¶
目錄頁:https://www.skillhub.cn/plugins/Miku196/dsh-tokensave
GitHub:https://github.com/Miku196/dsh-tokensave