前言¶
在 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