dsh-budget 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.zh.md CHANGED
@@ -1,192 +1,192 @@
1
- <div align="center">
2
-
3
- # 💰 dsh-budget
4
- - **1024 商店渠道**:先 `npm i -g dsh1024`,再 `dsh1024 plugin --profile web add dsh-budget`(计入 [deepseek1024.com](https://deepseek1024.com) 安装排行)。
5
-
6
- **DeepSeek Harness 的成本治理:预算、碳足迹与延迟,一个面板全览。**
7
-
8
- *让每次会话的成本在超支之前就被看清。*
9
-
10
- > **官方仓库。** 本仓库是 dsh-budget 的唯一官方仓库,由 PerryLink 维护。其他账号下的同名仓库与本项目无关。
11
-
12
- [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
13
- [![DSH plugin](https://img.shields.io/badge/dsh--plugin-✅-green)](https://github.com/topics/dsh-plugin)
14
- [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24-brightgreen.svg)](#)
15
- [![CI](https://img.shields.io/github/actions/workflow/status/PerryLink/dsh-budget/ci.yml?branch=main&label=CI)](https://github.com/PerryLink/dsh-budget/actions)
16
- [![Version](https://img.shields.io/github/v/tag/PerryLink/dsh-budget?label=version)](https://github.com/PerryLink/dsh-budget/releases)
17
- [![npm version](https://img.shields.io/npm/v/dsh-budget)](https://www.npmjs.com/package/dsh-budget)
18
- [![npm downloads](https://img.shields.io/npm/dm/dsh-budget)](https://www.npmjs.com/package/dsh-budget)
19
-
20
- [English](README.md) · [简体中文](README.zh.md) · [Español](README.es.md) · [Português](README.pt.md) · [हिन्दी](README.hi.md)
21
-
22
- </div>
23
-
24
- ---
25
-
26
- ## 兼容性
27
-
28
- | 方面 | 状态 |
29
- |---|---|
30
- | Harness | DeepSeek Harness `dsh-v0.1.3-alpha.1`(GitHub tag,2026-09-06 核验;npm 钉号 `0.1.2-rc.1`,2026-09-02 已适配;peer 范围 `>=0.1.2-rc.1 <0.2.0`):会话信封保留 ignorable 字段但仅用于存量日志读取兼容——Session.append 仍无法盖章,门控行为不变。已于 2026-09-06 对照 dsh-v0.1.3-alpha.1 master 检出核验(完整门禁链 + profile 安装冒烟)。 |
31
-
32
- | 审计事件 | `0.1.2-rc.1` 之前的宿主上写入;在 `0.1.2-rc.1` 及以后抑制并记录降级原因(fail-closed 会话事件词表,无外部注册面) || Node | `^22.19.0 \|\| >=24.0.0` |
33
- | 界面 | Host + Web 客户端(设置页预算页签);`/budget` 命令 |
34
-
35
- ## 你能得到什么
36
-
37
- `dsh-budget` 把会话事件流变成四合一成本治理闭环:
38
-
39
- - **聚合计量** —— token(未缓存输入 / 输出 / 缓存读 / 缓存写)、估算 USD 成本与碳足迹,按模型/会话/天聚合;内置 USD/百万 token 价目表与 `config.prices` 合并定价。
40
- - **预算治理** —— 会话/日/月三档封顶;warnRatio 阈值告警(webhook POST + 桌面通知开关)与三种超限策略:`alert`(仅告警)、`block`(在用户解除前短路新模型请求)、`degrade`(阻断并给出指向 `degradation` 映射中更便宜模型的修正提示)。
41
- - **碳足迹与延迟** —— token→碳桥接(tokens × kWh/token × PUE × 区域电网强度,移植自 AI-Carbon-Footprint-Calculator)与按模型延迟百分位。
42
- - **界面** —— 设置页预算页签(用量条、按天用量曲线、模型明细、告警、上限编辑、解除阻断按钮)与 `/budget` 命令(`/budget`、`/budget models`、`/budget unblock <scope>`)。
43
-
44
- ## 快速开始
45
-
46
- ```sh
47
- # 1. 把 bundle 装进你的 profile
48
- dsh plugin --profile web add "github:PerryLink/dsh-budget#main"
49
-
50
- # 或从 npm 安装(正式发布版)
51
- dsh plugin --profile web add dsh-budget
52
-
53
- # 2. 重启并核实行
54
- dsh --profile web --dump-config | grep -A2 'id: budget'
55
- ```
56
-
57
- 然后在会话里输入 `/budget`,并在设置页查看预算页签。
58
-
59
- ## 安装与卸载
60
-
61
- - **git 通道**(最新 `main`):`dsh plugin --profile web add "github:PerryLink/dsh-budget#main"` —— `prepare` 脚本仅用生产依赖构建。
62
- - **npm 通道**(正式发布版):`dsh plugin --profile web add dsh-budget`。
63
- - **tarball 通道**:在本仓库执行 `pnpm pack`,然后 `dsh plugin --profile web add ./dsh-budget-<version>.tgz`。
64
- - **卸载**:`dsh plugin --profile web remove dsh-budget`。
65
-
66
- > 如果 pnpm 对本包报 `ERR_PNPM_IGNORED_BUILDS`(esbuild 的平台二进制无害校验),在你的 `pnpm-workspace.yaml` 中加入 `allowBuilds: { esbuild: true }` —— `dsh` CLI 会打印确切片段。
67
-
68
- ## 配置
69
-
70
- 所有可调项都是 Schemastery `Config` 字段(可在 cordis.yml 中修改)。`cordis.patch.yml` 内联说明每个键。
71
-
72
- | 键 | 默认值 | 含义 |
73
- |---|---|---|
74
- | `prices` | `{}` | 每模型 USD/百万 token 价格,合并覆盖内置价目表 |
75
- | `defaultPrice` | `{input: 1.0, output: 3.0}` | 两表均无该模型时的回退价格 |
76
- | `budgets.session` / `daily` / `monthly` | `10` / `50` / `500` | 各作用域 USD 预算上限;缺省表示不限 |
77
- | `warnRatio` | `0.8` | 用量达到上限该比例时告警(0..1) |
78
- | `overLimit` | `alert` | 超限后策略:`alert` / `block` / `degrade` |
79
- | `degradation` | `{}` | 模型 id → 同厂商更便宜模型 id 的映射 |
80
- | `webhookUrl` | *(无)* | 可选阈值告警 webhook URL(POST JSON) |
81
- | `webhookTimeoutMs` | `5000` | webhook 请求超时 |
82
- | `alertsEnabled` | `true` | 阈值告警总开关 |
83
- | `alertCooldownMs` | `3600000` | 同一作用域两次告警的最小间隔(ms) |
84
- | `desktopNotifications` | `false` | 页签打开时的浏览器桌面通知 |
85
- | `refreshIntervalMs` | `5000` | 设置页签轮询间隔 |
86
- | `carbon.enabled` / `region` / `pue` / `energyKwhPerToken` | `true` / `global` / `1.58` / `0.000007` | 碳桥接(区域:global, us, eu, china, india, uk, france, iceland) |
87
- | `latency.enabled` / `windowSize` | `true` / `200` | 按模型延迟百分位与其窗口 |
88
- | `currency` | `{code: USD, rate: 1.0, decimals: 2}` | 展示货币(成本以 USD 计算,仅展示换算) |
89
- | `outputLanguage` | `en` | `/budget` 输出语言:`en` / `zh` |
90
- | `historyDays` | `30` | 面板快照保留的按天用量历史天数 |
91
- | `persistence.enabled` / `intervalMs` | `true` / `10000` | 日/月用量跨重启持久化(storage 域);域缺失时降级为进程内聚合 |
92
-
93
- ## 工具与界面
94
-
95
- | 界面 | 类型 | 说明 |
96
- |---|---|---|
97
- | `/budget` | 命令 | 各作用域概览(用量、比例、碳足迹、阻断状态) |
98
- | `/budget models` | 命令 | 按模型明细 + 延迟百分位 |
99
- | `/budget unblock <scope>` | 命令 | 解除某作用域阻断(`session` / `daily` / `monthly`) |
100
- | 设置 → 插件 → 预算 | 设置页签 | 用量条、按天用量曲线、模型明细、告警、上限编辑、解除阻断按钮 |
101
- | `budget/status`、`budget/setSettings`、`budget/unblock` | Typert Remote | 客户端通道(页签消费这些方法) |
102
-
103
- ## 权限与数据
104
-
105
- - **权限**:`network:outbound`(仅可选告警 webhook)、`session:append`(审计事件)、`native-code:none`。
106
- - **数据**:展示内容全部来自会话事件流;主机侧唯一网络调用是配置的 webhook,URL 在加载时校验、入日志前剥离凭据。任何 prompt/载荷都不会离开主机。
107
- - **会话日志**:`budget/alert` 与 `budget/block` 是仅日志审计事件,只携带作用域名与 USD 金额(微任务延后以绕过会话 append 重入保护)。在 `0.1.2-rc.1` 及以后的宿主上不再写入——fail-closed 事件词表会拒绝含未注册事件类型的日志,且没有外部注册面——审计轨迹因此仅降级到预算日志与 webhook。
108
-
109
- ## 安全边界
110
-
111
- - **不伪造数据**:预算阻断在 `llm/stream` 瀑布上产出修正性错误 finish —— 插件绝不编造模型输出。
112
- - **不改写请求**:loop 构建的请求被冻结;`degrade` 因此在修正消息中点名目标模型,而非替换请求。
113
- - **失败大声**:非法价格、URL、比例、区域与边界在挂载时即失败。
114
- - **如实作用域**:面板的运行时编辑仅会话级生效;重载后恢复 cordis.yml 配置。
115
-
116
- ## 已知限制
117
-
118
- - 聚合为进程本地:harness 重启后用量清零(日/月桶从当前会话日志视图重建)。
119
- - `block`/`degrade` 依赖 `llm/stream` 瀑布;无此 seam 的构建无法阻断请求(告警仍有效)。
120
- - 内置价目会漂移;用 `config.prices` 覆盖条目。
121
-
122
- ## 开发
123
-
124
- ```sh
125
- pnpm install # node ^22.19 || >=24
126
- pnpm run typecheck # tsc:src + tests,对照本地 harness checkout
127
- pnpm run typecheck:ci # tsc:对照已发布的 0.1.2-rc.1 类型(无 paths)
128
- pnpm test # vitest
129
- pnpm run build # tsc 声明 + tsdown bundles(lib/)
130
- pnpm run verify:self-contained # 依赖声明全部来自 registry
131
- pnpm run verify:artifacts # 构建产物 ESM 面 + typert manifest + 客户端 bundle
132
- pnpm pack # 发布用 tarball
133
- ```
134
-
135
- ## Topics
136
-
137
- `dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `budget`, `cost-tracking`, `carbon-footprint`, `latency-benchmark`, `token-usage`
138
-
139
- ## Contributors
140
-
141
- - [@PerryLink](https://github.com/PerryLink) —— 创建者与维护者:聚合、预算治理、碳足迹与延迟移植、设置页签与五语文档。
142
-
143
- ## PerryLink DSH Plugin Family
144
-
145
- 这是 [PerryLink](https://github.com/PerryLink) 维护的 [37 个 DeepSeek Harness 插件](https://github.com/PerryLink) 之一。如果它能帮到你,其他的也会:
146
-
147
- | Plugin | One-liner |
148
- |---|---|
149
- | **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | 审批链上的第二模型自动审查,默认失败关闭 | |
150
- | **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | 带 Web UI 侧栏、消息与中断的持久后台子代理 | |
151
- | **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | Claude Code /rewind 等价:快照、会话 fork、一次性恢复 | |
152
- | **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | 把 Claude Code 会话、记忆、技能与 CLAUDE.md 迁入 DSH | |
153
- | **[dsh-click](https://github.com/PerryLink/dsh-click)** | 跨平台原生桌面控制(DeepSeek Harness),Windows 优先。 | |
154
- | **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | Web 输入框的终端式历史:方向键、Ctrl+R 搜索 | |
155
- | **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | 数据集质量检查与引文核查(本插件可选消费的数字核查桥) | |
156
- | **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | DeepSeek Harness 的提示注入、越狱与密钥泄露防护。 | |
157
- | **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | 工程纪律守卫:需求质询、测试门禁、对手评审 | |
158
- | **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | DeepSeek Harness 的统一静态图像生成路由。 | |
159
- | **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | DeepSeek Harness 只读性能诊断。 | |
160
- | **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | 面向中国公募基金的确定性研究报告 | |
161
- | **[dsh-github](https://github.com/PerryLink/dsh-github)** | 面向 DSH 的 GitHub PR/issues 集成,每次写入经审批门控 | |
162
- | **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | 行业研究编排,经本插件的 `ctx.researchReport.assemble` 封存交付物 | |
163
- | **[dsh-library](https://github.com/PerryLink/dsh-library)** | DeepSeek Harness 的本地文档知识库。 | |
164
- | **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | DeepSeek Harness 的本地模型(Ollama)接入。 | |
165
- | **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | 通过语言服务器的 LSP 诊断、格式化、补全、代码操作与重命名 | |
166
- | **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | PII 脱敏中间件:模型边界匿名化、展示层还原 | |
167
- | **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | 只读 MCP 运行时面板:/mcp 命令 + 带状态、工具与错误的 Settings 标签页 | |
168
- | **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | 审批门控的跨会话记忆:ctx.memory 接缝 + SQLite + 记忆工具 | |
169
- | **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | DeepSeek Harness 的 OpenTelemetry 与 Langfuse 可观测导出器。 | |
170
- | **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | Claude Code outputStyles 等价的运行时风格切换 | |
171
- | **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | Claude Code 风格声明式 allow/deny/ask 权限规则,带审计 | |
172
- | **[dsh-personal-directive](https://github.com/PerryLink/dsh-personal-directive)** | 个人指令注入器:顶栏开关(框架版) |
173
- | **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | 作为按需代理技能的插件开发知识库 | |
174
- | **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | 多渠道审批/提问桥接:微信/Telegram/飞书,会话控制台 |
175
- | **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | 可验证研究报告引擎:内容寻址证据账本与封存版本 | |
176
- | **[dsh-score](https://github.com/PerryLink/dsh-score)** | DeepSeek Harness 插件的多维质量评分。 | |
177
- | **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | 在 Web 侧栏置顶会话,带持久排序 | |
178
- | **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | DeepSeek Harness 的跨设备会话同步——会话存储的专用 git 镜像。 | |
179
- | **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | 安全审计技能包:密钥扫描、依赖与供应链审查 | |
180
- | **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | DeepSeek Harness 的语音优先会话闭环:对它说,听它答。 | |
181
- | **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | DeepSeek Harness 插件的隔离试装冒烟。 | |
182
- | **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | TickTick/滴答清单任务桥接:会话头面板 + 11 个工具 |
183
- | **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | DeepSeek Harness 的厂商参数翻译与确定性 JSON 修复。 | |
184
- | **[dsh-wechat](https://github.com/PerryLink/dsh-wechat)** | 微信 ↔ DSH 桥接(Tencent iLink 机器人):文本/图片/文件/语音,聊天内审批卡片 |
185
-
186
- ## License
187
-
188
- [Apache License 2.0](LICENSE) © 2026 dsh-budget contributors
189
-
190
- ### 从 DSH Desktop 市场安装
191
-
192
- 所有 PerryLink 插件均可在 DSH Desktop 内置市场中浏览:**市场 → 来源 → 添加来源 → 粘贴** `https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json` **→ 选中**。安装仍需通过市场的 npm 身份校验与你的确认。
1
+ <div align="center">
2
+
3
+ # 💰 dsh-budget
4
+ - **1024 商店渠道**:先 `npm i -g dsh1024`,再 `dsh1024 plugin --profile web add dsh-budget`(计入 [deepseek1024.com](https://deepseek1024.com) 安装排行)。
5
+
6
+ **DeepSeek Harness 的成本治理:预算、碳足迹与延迟,一个面板全览。**
7
+
8
+ *让每次会话的成本在超支之前就被看清。*
9
+
10
+ > **官方仓库。** 本仓库是 dsh-budget 的唯一官方仓库,由 PerryLink 维护。其他账号下的同名仓库与本项目无关。
11
+
12
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
13
+ [![DSH plugin](https://img.shields.io/badge/dsh--plugin-✅-green)](https://github.com/topics/dsh-plugin)
14
+ [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24-brightgreen.svg)](#)
15
+ [![CI](https://img.shields.io/github/actions/workflow/status/PerryLink/dsh-budget/ci.yml?branch=main&label=CI)](https://github.com/PerryLink/dsh-budget/actions)
16
+ [![Version](https://img.shields.io/github/v/tag/PerryLink/dsh-budget?label=version)](https://github.com/PerryLink/dsh-budget/releases)
17
+ [![npm version](https://img.shields.io/npm/v/dsh-budget)](https://www.npmjs.com/package/dsh-budget)
18
+ [![npm downloads](https://img.shields.io/npm/dm/dsh-budget)](https://www.npmjs.com/package/dsh-budget)
19
+
20
+ [English](README.md) · [简体中文](README.zh.md) · [Español](README.es.md) · [Português](README.pt.md) · [हिन्दी](README.hi.md)
21
+
22
+ </div>
23
+
24
+ ---
25
+
26
+ ## 兼容性
27
+
28
+ | 方面 | 状态 |
29
+ |---|---|
30
+ | Harness | DeepSeek Harness `dsh-v0.1.5-alpha.1`(GitHub tag,2026-09-09 核验;npm 钉号 `0.1.5-alpha.1`,2026-09-09 已适配;peer 范围 `>=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0`):会话信封保留 ignorable 字段但仅用于存量日志读取兼容——Session.append 仍无法盖章,门控行为不变。已于 2026-09-09 对照 dsh-v0.1.5-alpha.1 master 检出核验(完整门禁链 + profile 安装冒烟)。 |
31
+
32
+ | 审计事件 | `0.1.2-rc.1` 之前的宿主上写入;在 `0.1.2-rc.1` 及以后抑制并记录降级原因(fail-closed 会话事件词表,无外部注册面) || Node | `^22.19.0 \|\| >=24.0.0` |
33
+ | 界面 | Host + Web 客户端(设置页预算页签);`/budget` 命令 |
34
+
35
+ ## 你能得到什么
36
+
37
+ `dsh-budget` 把会话事件流变成四合一成本治理闭环:
38
+
39
+ - **聚合计量** —— token(未缓存输入 / 输出 / 缓存读 / 缓存写)、估算 USD 成本与碳足迹,按模型/会话/天聚合;内置 USD/百万 token 价目表与 `config.prices` 合并定价。
40
+ - **预算治理** —— 会话/日/月三档封顶;warnRatio 阈值告警(webhook POST + 桌面通知开关)与三种超限策略:`alert`(仅告警)、`block`(在用户解除前短路新模型请求)、`degrade`(阻断并给出指向 `degradation` 映射中更便宜模型的修正提示)。
41
+ - **碳足迹与延迟** —— token→碳桥接(tokens × kWh/token × PUE × 区域电网强度,移植自 AI-Carbon-Footprint-Calculator)与按模型延迟百分位。
42
+ - **界面** —— 设置页预算页签(用量条、按天用量曲线、模型明细、告警、上限编辑、解除阻断按钮)与 `/budget` 命令(`/budget`、`/budget models`、`/budget unblock <scope>`)。
43
+
44
+ ## 快速开始
45
+
46
+ ```sh
47
+ # 1. 把 bundle 装进你的 profile
48
+ dsh plugin --profile web add "github:PerryLink/dsh-budget#main"
49
+
50
+ # 或从 npm 安装(正式发布版)
51
+ dsh plugin --profile web add dsh-budget
52
+
53
+ # 2. 重启并核实行
54
+ dsh --profile web --dump-config | grep -A2 'id: budget'
55
+ ```
56
+
57
+ 然后在会话里输入 `/budget`,并在设置页查看预算页签。
58
+
59
+ ## 安装与卸载
60
+
61
+ - **git 通道**(最新 `main`):`dsh plugin --profile web add "github:PerryLink/dsh-budget#main"` —— `prepare` 脚本仅用生产依赖构建。
62
+ - **npm 通道**(正式发布版):`dsh plugin --profile web add dsh-budget`。
63
+ - **tarball 通道**:在本仓库执行 `pnpm pack`,然后 `dsh plugin --profile web add ./dsh-budget-<version>.tgz`。
64
+ - **卸载**:`dsh plugin --profile web remove dsh-budget`。
65
+
66
+ > 如果 pnpm 对本包报 `ERR_PNPM_IGNORED_BUILDS`(esbuild 的平台二进制无害校验),在你的 `pnpm-workspace.yaml` 中加入 `allowBuilds: { esbuild: true }` —— `dsh` CLI 会打印确切片段。
67
+
68
+ ## 配置
69
+
70
+ 所有可调项都是 Schemastery `Config` 字段(可在 cordis.yml 中修改)。`cordis.patch.yml` 内联说明每个键。
71
+
72
+ | 键 | 默认值 | 含义 |
73
+ |---|---|---|
74
+ | `prices` | `{}` | 每模型 USD/百万 token 价格,合并覆盖内置价目表 |
75
+ | `defaultPrice` | `{input: 1.0, output: 3.0}` | 两表均无该模型时的回退价格 |
76
+ | `budgets.session` / `daily` / `monthly` | `10` / `50` / `500` | 各作用域 USD 预算上限;缺省表示不限 |
77
+ | `warnRatio` | `0.8` | 用量达到上限该比例时告警(0..1) |
78
+ | `overLimit` | `alert` | 超限后策略:`alert` / `block` / `degrade` |
79
+ | `degradation` | `{}` | 模型 id → 同厂商更便宜模型 id 的映射 |
80
+ | `webhookUrl` | *(无)* | 可选阈值告警 webhook URL(POST JSON) |
81
+ | `webhookTimeoutMs` | `5000` | webhook 请求超时 |
82
+ | `alertsEnabled` | `true` | 阈值告警总开关 |
83
+ | `alertCooldownMs` | `3600000` | 同一作用域两次告警的最小间隔(ms) |
84
+ | `desktopNotifications` | `false` | 页签打开时的浏览器桌面通知 |
85
+ | `refreshIntervalMs` | `5000` | 设置页签轮询间隔 |
86
+ | `carbon.enabled` / `region` / `pue` / `energyKwhPerToken` | `true` / `global` / `1.58` / `0.000007` | 碳桥接(区域:global, us, eu, china, india, uk, france, iceland) |
87
+ | `latency.enabled` / `windowSize` | `true` / `200` | 按模型延迟百分位与其窗口 |
88
+ | `currency` | `{code: USD, rate: 1.0, decimals: 2}` | 展示货币(成本以 USD 计算,仅展示换算) |
89
+ | `outputLanguage` | `en` | `/budget` 输出语言:`en` / `zh` |
90
+ | `historyDays` | `30` | 面板快照保留的按天用量历史天数 |
91
+ | `persistence.enabled` / `intervalMs` | `true` / `10000` | 日/月用量跨重启持久化(storage 域);域缺失时降级为进程内聚合 |
92
+
93
+ ## 工具与界面
94
+
95
+ | 界面 | 类型 | 说明 |
96
+ |---|---|---|
97
+ | `/budget` | 命令 | 各作用域概览(用量、比例、碳足迹、阻断状态) |
98
+ | `/budget models` | 命令 | 按模型明细 + 延迟百分位 |
99
+ | `/budget unblock <scope>` | 命令 | 解除某作用域阻断(`session` / `daily` / `monthly`) |
100
+ | 设置 → 插件 → 预算 | 设置页签 | 用量条、按天用量曲线、模型明细、告警、上限编辑、解除阻断按钮 |
101
+ | `budget/status`、`budget/setSettings`、`budget/unblock` | Typert Remote | 客户端通道(页签消费这些方法) |
102
+
103
+ ## 权限与数据
104
+
105
+ - **权限**:`network:outbound`(仅可选告警 webhook)、`session:append`(审计事件)、`native-code:none`。
106
+ - **数据**:展示内容全部来自会话事件流;主机侧唯一网络调用是配置的 webhook,URL 在加载时校验、入日志前剥离凭据。任何 prompt/载荷都不会离开主机。
107
+ - **会话日志**:`budget/alert` 与 `budget/block` 是仅日志审计事件,只携带作用域名与 USD 金额(微任务延后以绕过会话 append 重入保护)。在 `0.1.2-rc.1` 及以后的宿主上不再写入——fail-closed 事件词表会拒绝含未注册事件类型的日志,且没有外部注册面——审计轨迹因此仅降级到预算日志与 webhook。
108
+
109
+ ## 安全边界
110
+
111
+ - **不伪造数据**:预算阻断在 `llm/stream` 瀑布上产出修正性错误 finish —— 插件绝不编造模型输出。
112
+ - **不改写请求**:loop 构建的请求被冻结;`degrade` 因此在修正消息中点名目标模型,而非替换请求。
113
+ - **失败大声**:非法价格、URL、比例、区域与边界在挂载时即失败。
114
+ - **如实作用域**:面板的运行时编辑仅会话级生效;重载后恢复 cordis.yml 配置。
115
+
116
+ ## 已知限制
117
+
118
+ - 聚合为进程本地:harness 重启后用量清零(日/月桶从当前会话日志视图重建)。
119
+ - `block`/`degrade` 依赖 `llm/stream` 瀑布;无此 seam 的构建无法阻断请求(告警仍有效)。
120
+ - 内置价目会漂移;用 `config.prices` 覆盖条目。
121
+
122
+ ## 开发
123
+
124
+ ```sh
125
+ pnpm install # node ^22.19 || >=24
126
+ pnpm run typecheck # tsc:src + tests,对照本地 harness checkout
127
+ pnpm run typecheck:ci # tsc:对照已发布的 0.1.2-rc.1 类型(无 paths)
128
+ pnpm test # vitest
129
+ pnpm run build # tsc 声明 + tsdown bundles(lib/)
130
+ pnpm run verify:self-contained # 依赖声明全部来自 registry
131
+ pnpm run verify:artifacts # 构建产物 ESM 面 + typert manifest + 客户端 bundle
132
+ pnpm pack # 发布用 tarball
133
+ ```
134
+
135
+ ## Topics
136
+
137
+ `dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `budget`, `cost-tracking`, `carbon-footprint`, `latency-benchmark`, `token-usage`
138
+
139
+ ## Contributors
140
+
141
+ - [@PerryLink](https://github.com/PerryLink) —— 创建者与维护者:聚合、预算治理、碳足迹与延迟移植、设置页签与五语文档。
142
+
143
+ ## PerryLink DSH Plugin Family
144
+
145
+ 这是 [PerryLink](https://github.com/PerryLink) 维护的 [37 个 DeepSeek Harness 插件](https://github.com/PerryLink) 之一。如果它能帮到你,其他的也会:
146
+
147
+ | Plugin | One-liner |
148
+ |---|---|
149
+ | **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | 审批链上的第二模型自动审查,默认失败关闭 | |
150
+ | **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | 带 Web UI 侧栏、消息与中断的持久后台子代理 | |
151
+ | **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | Claude Code /rewind 等价:快照、会话 fork、一次性恢复 | |
152
+ | **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | 把 Claude Code 会话、记忆、技能与 CLAUDE.md 迁入 DSH | |
153
+ | **[dsh-click](https://github.com/PerryLink/dsh-click)** | 跨平台原生桌面控制(DeepSeek Harness),Windows 优先。 | |
154
+ | **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | Web 输入框的终端式历史:方向键、Ctrl+R 搜索 | |
155
+ | **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | 数据集质量检查与引文核查(本插件可选消费的数字核查桥) | |
156
+ | **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | DeepSeek Harness 的提示注入、越狱与密钥泄露防护。 | |
157
+ | **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | 工程纪律守卫:需求质询、测试门禁、对手评审 | |
158
+ | **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | DeepSeek Harness 的统一静态图像生成路由。 | |
159
+ | **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | DeepSeek Harness 只读性能诊断。 | |
160
+ | **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | 面向中国公募基金的确定性研究报告 | |
161
+ | **[dsh-github](https://github.com/PerryLink/dsh-github)** | 面向 DSH 的 GitHub PR/issues 集成,每次写入经审批门控 | |
162
+ | **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | 行业研究编排,经本插件的 `ctx.researchReport.assemble` 封存交付物 | |
163
+ | **[dsh-library](https://github.com/PerryLink/dsh-library)** | DeepSeek Harness 的本地文档知识库。 | |
164
+ | **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | DeepSeek Harness 的本地模型(Ollama)接入。 | |
165
+ | **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | 通过语言服务器的 LSP 诊断、格式化、补全、代码操作与重命名 | |
166
+ | **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | PII 脱敏中间件:模型边界匿名化、展示层还原 | |
167
+ | **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | 只读 MCP 运行时面板:/mcp 命令 + 带状态、工具与错误的 Settings 标签页 | |
168
+ | **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | 审批门控的跨会话记忆:ctx.memory 接缝 + SQLite + 记忆工具 | |
169
+ | **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | DeepSeek Harness 的 OpenTelemetry 与 Langfuse 可观测导出器。 | |
170
+ | **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | Claude Code outputStyles 等价的运行时风格切换 | |
171
+ | **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | Claude Code 风格声明式 allow/deny/ask 权限规则,带审计 | |
172
+ | **[dsh-personal-directive](https://github.com/PerryLink/dsh-personal-directive)** | 个人指令注入器:顶栏开关(框架版) |
173
+ | **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | 作为按需代理技能的插件开发知识库 | |
174
+ | **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | 多渠道审批/提问桥接:微信/Telegram/飞书,会话控制台 |
175
+ | **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | 可验证研究报告引擎:内容寻址证据账本与封存版本 | |
176
+ | **[dsh-score](https://github.com/PerryLink/dsh-score)** | DeepSeek Harness 插件的多维质量评分。 | |
177
+ | **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | 在 Web 侧栏置顶会话,带持久排序 | |
178
+ | **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | DeepSeek Harness 的跨设备会话同步——会话存储的专用 git 镜像。 | |
179
+ | **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | 安全审计技能包:密钥扫描、依赖与供应链审查 | |
180
+ | **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | DeepSeek Harness 的语音优先会话闭环:对它说,听它答。 | |
181
+ | **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | DeepSeek Harness 插件的隔离试装冒烟。 | |
182
+ | **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | TickTick/滴答清单任务桥接:会话头面板 + 11 个工具 |
183
+ | **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | DeepSeek Harness 的厂商参数翻译与确定性 JSON 修复。 | |
184
+ | **[dsh-wechat](https://github.com/PerryLink/dsh-wechat)** | 微信 ↔ DSH 桥接(Tencent iLink 机器人):文本/图片/文件/语音,聊天内审批卡片 |
185
+
186
+ ## License
187
+
188
+ [Apache License 2.0](LICENSE) © 2026 dsh-budget contributors
189
+
190
+ ### 从 DSH Desktop 市场安装
191
+
192
+ 所有 PerryLink 插件均可在 DSH Desktop 内置市场中浏览:**市场 → 来源 → 添加来源 → 粘贴** `https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json` **→ 选中**。安装仍需通过市场的 npm 身份校验与你的确认。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-budget",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Cost governance for DeepSeek Harness: aggregated token/cost metering per model, session and day, session/daily/monthly budget caps with threshold alerts (desktop notification + webhook) and alert/block/degrade over-limit policies, built-in carbon footprint estimation and per-model latency benchmarks, a Settings budget tab, and the /budget command",
5
5
  "repository": {
6
6
  "type": "git",
@@ -79,9 +79,7 @@
79
79
  "native-code:none"
80
80
  ],
81
81
  "compatibility": {
82
- "dshVersions": [
83
- "0.1.2-rc.1"
84
- ]
82
+ "dshVersions": ["0.1.2-rc.1","0.1.5-alpha.1"]
85
83
  },
86
84
  "capability": {
87
85
  "id": "budget-governance",
@@ -114,18 +112,18 @@
114
112
  "packageManager": "pnpm@11.7.0",
115
113
  "peerDependencies": {
116
114
  "@deepseek-ai/cordis": "^4.0.2",
117
- "@deepseek-ai/dsh-agent": ">=0.1.2-rc.1 <0.2.0",
118
- "@deepseek-ai/dsh-commands": ">=0.1.2-rc.1 <0.2.0",
119
- "@deepseek-ai/dsh-llm": ">=0.1.2-rc.1 <0.2.0",
120
- "@deepseek-ai/dsh-session": ">=0.1.2-rc.1 <0.2.0",
121
- "@deepseek-ai/dsh-storage-domain": ">=0.1.2-rc.1 <0.2.0",
122
- "@deepseek-ai/dsh-token-meter": ">=0.1.2-rc.1 <0.2.0",
123
- "@deepseek-ai/dsh-tools": ">=0.1.2-rc.1 <0.2.0",
124
- "@deepseek-ai/dsh-typert-protocol": ">=0.1.2-rc.1 <0.2.0",
115
+ "@deepseek-ai/dsh-agent": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
116
+ "@deepseek-ai/dsh-commands": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
117
+ "@deepseek-ai/dsh-llm": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
118
+ "@deepseek-ai/dsh-session": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
119
+ "@deepseek-ai/dsh-storage-domain": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
120
+ "@deepseek-ai/dsh-token-meter": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
121
+ "@deepseek-ai/dsh-tools": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
122
+ "@deepseek-ai/dsh-typert-protocol": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
125
123
  "@deepseek-ai/schemastery": "^3.18.2",
126
- "@deepseek-ai/dsh-client-connection": ">=0.1.2-rc.1 <0.2.0",
127
- "@deepseek-ai/dsh-client-locale": ">=0.1.2-rc.1 <0.2.0",
128
- "@deepseek-ai/dsh-client-ui-settings": ">=0.1.2-rc.1 <0.2.0"
124
+ "@deepseek-ai/dsh-client-connection": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
125
+ "@deepseek-ai/dsh-client-locale": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0",
126
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.2-rc.1 <0.2.0 || >=0.1.5-alpha.1 <0.2.0"
129
127
  },
130
128
  "peerDependenciesMeta": {
131
129
  "@deepseek-ai/dsh-client-connection": {
@@ -144,23 +142,23 @@
144
142
  "zod": "^4.4.3"
145
143
  },
146
144
  "devDependencies": {
147
- "@deepseek-ai/dsh-api-remotes": "0.1.2-rc.1",
148
- "@deepseek-ai/dsh-attachment": "0.1.2-rc.1",
145
+ "@deepseek-ai/dsh-api-remotes": "0.1.5-alpha.1",
146
+ "@deepseek-ai/dsh-attachment": "0.1.5-alpha.1",
149
147
  "@deepseek-ai/cordis": "^4.0.2",
150
148
  "@deepseek-ai/cordis-plugin-include": "^1.0.7",
151
149
  "@deepseek-ai/cordis-plugin-loader": "^1.0.3",
152
- "@deepseek-ai/dsh-agent": "0.1.2-rc.1",
153
- "@deepseek-ai/dsh-client-connection": "0.1.2-rc.1",
154
- "@deepseek-ai/dsh-client-locale": "0.1.2-rc.1",
155
- "@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
156
- "@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
157
- "@deepseek-ai/dsh-commands": "0.1.2-rc.1",
158
- "@deepseek-ai/dsh-llm": "0.1.2-rc.1",
159
- "@deepseek-ai/dsh-session": "0.1.2-rc.1",
160
- "@deepseek-ai/dsh-storage-domain": "0.1.2-rc.1",
161
- "@deepseek-ai/dsh-token-meter": "0.1.2-rc.1",
162
- "@deepseek-ai/dsh-tools": "0.1.2-rc.1",
163
- "@deepseek-ai/dsh-typert-protocol": "0.1.2-rc.1",
150
+ "@deepseek-ai/dsh-agent": "0.1.5-alpha.1",
151
+ "@deepseek-ai/dsh-client-connection": "0.1.5-alpha.1",
152
+ "@deepseek-ai/dsh-client-locale": "0.1.5-alpha.1",
153
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.5-alpha.1",
154
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.5-alpha.1",
155
+ "@deepseek-ai/dsh-commands": "0.1.5-alpha.1",
156
+ "@deepseek-ai/dsh-llm": "0.1.5-alpha.1",
157
+ "@deepseek-ai/dsh-session": "0.1.5-alpha.1",
158
+ "@deepseek-ai/dsh-storage-domain": "0.1.5-alpha.1",
159
+ "@deepseek-ai/dsh-token-meter": "0.1.5-alpha.1",
160
+ "@deepseek-ai/dsh-tools": "0.1.5-alpha.1",
161
+ "@deepseek-ai/dsh-typert-protocol": "0.1.5-alpha.1",
164
162
  "@deepseek-ai/schemastery": "^3.18.2",
165
163
  "@types/node": "^22.19.0",
166
164
  "@types/react": "18.3.31",