dsh-ai-monitor — DeepSeek Harness 插件
AI Monitor 与 DeepSeek Harness 的桥接插件:让 dsh agent 在跑任务前能感知 AI 预算,
任务后能汇报账单。只读本机 AI Monitor SQLite,不改动其数据。
安装(npm 发布后)
# 方式一:直接添加到 dsh profile
cd ~/.dsh/profiles/web
npm install dsh-ai-monitor
# 方式二:dsh CLI(若已支持 plugin add)
dsh plugin add dsh-ai-monitor
然后在 dsh 启动时叠加 bundle(或通过 profile 引用)加载插件。
前置要求
- 本机已安装并运行 AI Monitor,且至少添加了一个账户
- dsh 已配置好模型(Settings → Models 填入 API key)
- 数据库路径:
~/Library/Application Support/com.ai-monitor.app/ai-monitor.db(可用 DSH_AI_MONITOR_DB 环境变量覆盖)
功能
query_ai_balance 工具:查询各 AI 平台账户余额 + 今日 token 用量 + 消耗金额
- 数据来源:AI Monitor 本地 SQLite
- 只读模式(
readonly: true + WAL 兼容),不锁库、不改数据
配合 AI Monitor 代理使用(推荐)
把 dsh 的 LLM 请求也指向 AI Monitor 本地代理(127.0.0.1:8899),可以实现自动记账闭环:
# ~/.dsh/settings.yaml
llm-deepseek:
baseURL: http://127.0.0.1:8899/v1
这样 dsh 的每次调用都会自动进入 AI Monitor 账本,agent 又能通过本插件查询余额——
形成一个「消耗可查、余额可知」的完整闭环。
目录结构
ai-monitor-dsh-plugin/
├── package.json # dsh.bundle manifest(发布用)
├── cordis.patch.yml # 补丁层:把插件插入 web profile
├── tsconfig.json # TS 编译配置(src → .)
├── src/index.ts # 插件源码(TS)
├── index.js # 编译产物(dsh 实际加载的 JS)
└── node_modules/ # better-sqlite3(原生模块)
本地开发 / 加载
# 1. 安装依赖
cd ai-monitor-dsh-plugin
npm install better-sqlite3
npx tsc # 编译 src/index.ts → index.js
# 2. 生成带补丁的启动配置
cat > /tmp/patch-abs.yml << 'EOF'
- insert:
- id: ai-monitor
name: '/绝对路径/ai-monitor-dsh-plugin/index.js'
EOF
# 3. 启动(需先停掉已有 dsh)
pkill -f "dsh" ; sleep 2
cd ai-monitor-dsh-plugin
nohup dsh --profile web --patch /tmp/patch-abs.yml > /tmp/dsh-web-plugin.log 2>&1 &
# 4. 验证加载成功(日志应出现)
tail /tmp/dsh-web-plugin.log
# [ai-monitor] plugin loaded. db=...
验证记录(2026-08-14)
- ✅
dsh --patch xxx --dump-config 确认补丁合成进配置树
- ✅ 带补丁启动,日志出现
[ai-monitor] plugin loaded. db=/Users/chen/Library/Application Support/com.ai-monitor.app/ai-monitor.db
- ✅ 查询 SQL 独立验证:DeepSeek 余额 ¥8.16、今日 27.7 万 tokens / 约 ¥2.15
- ✅ 端到端验证通过(用户实测):在 dsh Web UI 配置 DeepSeek API key 后,agent 成功调用
query_ai_balance,
返回真实数据——DeepSeek 余额 ¥8.07、今日 281K tokens / 约 ¥2.25,并自动附带数据边界说明
发布到 npm(bundle 形式)
- 改
package.json 的 dsh.bundle.patch 指向 ./cordis.patch.yml(已是)
cordis.patch.yml 中插件 name 应为包名(如 dsh-ai-monitor),不要用绝对路径
- 发布:
npm publish(确保 files 包含 index.js、cordis.patch.yml、README.md)
- GitHub 仓库加
dsh-plugin topic,便于社区发现
- 用户安装:
dsh plugin add dsh-ai-monitor
后续方向
数据边界
- 只统计本机经过 AI Monitor 代理(127.0.0.1:8899)的调用;其他机器/直连不计入
- 插件只读,不写 AI Monitor 的任何数据