dsh-token-dash 1.1.2 → 1.3.0

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/AGENTS.md CHANGED
@@ -1,90 +1,105 @@
1
1
  # AGENTS.md
2
2
 
3
- ## 文档定位
3
+ > 本文件只放协作与执行规则,不承担开发总览、目录索引或版本现状;验证命令以 `package.json` 的 scripts 为准,不复述测试规模与版本号。
4
4
 
5
- - 本文件只保留仓库协作与执行规则,不承担开发总览、目录索引或版本现状。
6
- - 开发/架构入口:`docs/design.md`;先读架构、Provider/VM/UI 边界、模块职责,再看代码。
7
- - 验证命令以 `package.json` 的 scripts 为准;不要在本文件复制测试规模、构建命令或版本号。
8
-
9
- ### 重点文档读取位置
5
+ ## 1. 读取入口
10
6
 
11
7
  | 场景 | 先读 | 再看 |
12
8
  |---|---|---|
13
9
  | 改代码 / 架构 | `docs/design.md` | `src/`、`client.js`、`test/unit/`、对应 active plan |
14
- | 需求 / 规划 | `docs/plan/AGENTS.md` | `docs/plan/active/`(先看文件头状态)、`docs/plan/archived/`(历史) |
15
- | 施工 / 走查 | `docs/checklist/AGENTS.md` | `docs/checklist/active/dsh/`、`docs/checklist/archived/dsh/` |
16
- | 发布 / 版本 | `docs/release.md` | `.agents/skills/dsh-token-dash-release/SKILL.md`、版本记录 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` |
10
+ | 需求 / 规划 | `docs/plan/AGENTS.md` | `docs/plan/active/`(先看文件头状态)、`docs/plan/archived/` |
11
+ | 施工 / 走查 | `docs/checklist/AGENTS.md` | `docs/checklist/active/`、`docs/checklist/archived/` |
12
+ | 发布 / 版本 | `docs/release.md` | `.agents/skills/dsh-token-dash-release/SKILL.md`、`references/official-release-version.md` |
17
13
  | 用户说明 / 变更历史 | `README.md` / `README.en.md` | `CHANGELOG.md`、`docs/pic/` |
18
- | Skill 维护 | `.agents/skills/`(项目 skill) | `D:\Projects\Context-Engineer\skills\`(全局 skill 真源) |
14
+ | 组件预览 / 草图 | `tools/preview/README.md` | `tools/preview/spec.mjs`、`tools/preview/templates/` |
15
+ | 假数据 / 截图 | `tools/mock/AGENTS.md` | `tools/mock/fixtures.mjs`、`tools/mock/shots.mjs` |
16
+ | Skill 维护 | `.agents/skills/`(项目) | `D:\Projects\Context-Engineer\skills\`(全局真源) |
19
17
 
20
- - 当前 active plan / checklist 不在此复制;进入目录后按文件头状态判断,避免本文件与文档状态漂移。
18
+ - active plan / checklist 不在此复制,进目录后按文件头状态判断,避免本文件与文档状态漂移。
21
19
 
22
- ## 变更授权
20
+ ## 2. 授权边界
23
21
 
24
- - **未获用户明确授权,不得直接修改代码**。用户只要求“更新文档 / 记 issue / 完善设计 / 检查文档”时,只允许修改 `docs/`、`AGENTS.md`、`README*` 等文档;禁止编辑 `client.js`、`index.js`、`src/`、`test/`、`scripts/`、`package.json`、`locale/`,也不得测试、打包或安装插件。
25
- - 代码修改必须等待用户明确说“开始修改 / 可以改代码 / 执行 / 开始开发”等授权。文档确认与代码实施分开进行,禁止把文档和代码改动混在同一轮。
26
- - plan / checklist 记录本身不等同于代码实施授权;即使文档已确认,也必须再收到用户明确的开始实施指令。发现文档与代码不一致时先报告,未获授权不得顺手修代码。
22
+ - **未获明确授权不得改代码**。用户只要求“更新文档 / 记 issue / 完善设计 / 检查文档”时,仅可改 `docs/`、`AGENTS.md`、`README*`;禁止编辑 `client.js`、`index.js`、`src/`、`test/`、`scripts/`、`tools/`、`package.json`、`locale/`,也不得测试、打包或安装插件。
23
+ - 代码实施需明确口令(“开始修改 / 可以改代码 / 执行 / 开始开发”);文档确认与代码实施分轮进行,不混在同一轮。
24
+ - plan / checklist 记录不等于实施授权;发现文档与代码不一致时先报告,未获授权不得顺手修。
27
25
 
28
- ## 修改原则
26
+ ## 3. 代码与架构约束
29
27
 
30
- - 纯 ESM、零构建;宿主编排入口 `index.js`,客户端 `client.js`;client bundle id 必须等于包名。
28
+ - 纯 ESM、零构建;宿主入口 `index.js`,客户端 `client.js`;client bundle id 必须等于包名。
31
29
  - 源码即产物,不提交 `lib/`;npm 包内容由 `package.json#files` 控制。
32
- - 保持现有五家 provider 边界:adapter 只输出 `ProviderSnapshot`,VM 只输出 `SummaryVM`,UI 只消费 VM;不引入 provider 插件系统或 per-provider 文件拆分。
33
- - 不做无关重构;改动范围以 plan / checklist 声明为准,越界先更新文档并确认。
30
+ - Provider 边界:adapter 只输出 `ProviderSnapshot`,VM 只输出 `SummaryVM`,UI 只消费 VM;不做 provider 插件化或 per-provider 拆分(当前五家)。
31
+ - 不做无关重构;改动范围以 plan / checklist 声明为准,越界先改文档并确认。
34
32
  - 日志用 `[TD:<module>]` 语义前缀;错误不吞,关键链路带 `errorKind` / `httpStatus`。
35
- - 临时产物、一次性脚本和 MCP 输出统一放 `.tmp/`;不在仓库根或 `src/` 下新建临时文件。
36
33
 
37
- ## Skill 归属
34
+ ## 4. 流程与工具
35
+
36
+ ### 4.1 规划与施工
37
+
38
+ - 复杂功能、跨模块修改、架构调整先用 `plan-workflow` skill 维护 `docs/plan/active/`;归档内容只读,重开走受控流程。
39
+ - 同一时间只推进一个主 feature;优先恢复已有 plan,不新建重复计划。
40
+ - 施工与走查用 `checklist` skill 维护 `docs/checklist/active/`(单层,不建项目域子目录);回写完成 + 用户明确指令后才归档。
41
+ - 每次实现完成、测试通过或发布后,回写 plan 的 §3.0/§5 与 checklist 的阶段 / 测试 / 执行日志,避免状态只留在对话里。
42
+
43
+ ### 4.2 预览与原型
44
+
45
+ - 四层分离:`tools/preview/templates/`(定稿原型)与 `drafts/`(探索稿)入库;`.tmp/preview/` 只放渲染器产出的 HTML(PNG 仅在 `--png` 时生成);`docs/pic/` 只放定稿图,仅 `preview:publish` 写入。
46
+ - **手写 HTML 不落 `.tmp/`**:探索写 `tools/preview/drafts/<name>.html`,跑 `npm run preview drafts/<name>`;定稿时把数值搬进 `spec.mjs`、改用变量后再移入 `templates/`。
47
+ - 默认只生成 `.tmp/preview/<name>.html`,**在 IDE 里直接预览**(比截图更接近真实渲染);需要静态图才加 `--png`,进 README / 设计文档才 `preview:publish`。
48
+ - 尺寸、字号、间距只在 `tools/preview/spec.mjs` 定义一次;预览模板与后续 E2E 尺寸断言共用,禁止各写一份。
49
+ - 设计文档引用 `templates/` 的稳定路径或 `npm run preview` 命令,不引用 `.tmp/`;组件形态以原型为准,不维护 ASCII 草图。
38
50
 
39
- - 项目 skill 只放在仓库 `.agents/skills/`,Codex 与 DSH 原生识别,不复制到用户层。
40
- - 全局 skill 真源只放在 `D:\Projects\Context-Engineer\skills\`;`~/.agents/skills/<name>` 用 junction 指向 CE,不保留副本。
41
- - 新增或修改全局 skill 在 CE 内完成,再建 junction;项目 skill 与全局 skill 不混放。
51
+ ### 4.3 Skill 归属
42
52
 
43
- ## 提交前规则
53
+ - 项目 skill 只放仓库 `.agents/skills/`,不复制到用户层。
54
+ - 全局 skill 真源只放 `D:\Projects\Context-Engineer\skills\`;`~/.agents/skills/<name>` 用 junction 指向 CE,不保留副本。
55
+ - 新增或修改全局 skill 在 CE 内完成再建 junction;项目 skill 与全局 skill 不混放。
56
+
57
+ ## 5. 验证、提交与版本
58
+
59
+ ### 5.1 提交前
44
60
 
45
61
  1. 更新相关文档:plan / checklist / design / README,以改动范围为准。
46
- 2. 执行受影响验证:L1 `npm test`,涉及 UI/宿主链路时加 `npm run e2e`。
47
- 3. 涉及发布时再执行 `npm run pack`,确认 tarball 内容。
62
+ 2. 执行受影响验证:L1 `npm test`;涉及 UI 或宿主链路时加 `npm run e2e`。
63
+ 3. 仅当用户显式要求本地打包或发布时执行 `npm run pack`,并核对 tarball 内容。
48
64
  4. 确认无 `.tmp/`、`build/`、真实会话或凭证进入提交。
49
- 5. 再 `commit` + `push`;用户说“提交”默认包含推送,除非明确“只本地提交”。
65
+ 5. `commit` + `push`;用户说“提交”默认含推送,除非明确“只本地提交”。
50
66
 
51
- - 纯文档更新且不涉及代码、测试脚本、发布资产时,可跳过测试和打包,但提交说明必须写明“仅文档更新,未启动测试/打包”。
67
+ - 纯文档更新且不涉及代码、测试脚本、发布资产时可跳过测试与打包,但提交说明必须写明“仅文档更新,未启动测试/打包”。
52
68
  - 文档互引使用以仓库根为基准的相对路径。
53
- - 完成本地打包后,立即回写当前 active plan 的进度;本地打包本身必须先有用户显式指令。
54
69
 
55
- ## 版本与发布
70
+ ### 5.2 版本号
56
71
 
57
- - 版本号遵循 `MAJOR.MINOR.PATCH`;当前正式版本以 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` 为准,不在此复制。
58
- - 发版流程唯一来源:`docs/release.md` + `.agents/skills/dsh-token-dash-release/SKILL.md`;GitHub Release、npm Trusted Publishing 均由 tag 触发。
59
- - **本地打包必须由用户显式指令触发**(`本地打包` / `本地版本` / `候选包`)。完成 issue、修复、测试或提交后,不得自动改版本号、写 CHANGELOG local 块、`npm run pack` 或安装本地包。
60
- - 本地构建记录写 `CHANGELOG.md` 顶部 `## [X.Y.Z-local.N]`,标题下加 `> 本地构建,未发布`;不 tag、不发布。正式发布时合并进正式块并删除,最终历史不保留 local 块。
61
- - 正式发布:确认版本 → CHANGELOG 正式块 → L1 + E2E → pack → commit/push → tag → 双 workflow → 核验 npm latest 与 Release body;随后更新 `official-release-version.md`。
62
- - Release body 按 tag 版本从 CHANGELOG 提取,不按“文件第一块”提取;local 块不得进入 Release body。
63
- - 未获用户明确授权,不执行 `npm publish`、不推 tag、不声称已上线。
72
+ - 遵循 `MAJOR.MINOR.PATCH`;当前正式版本以 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` 为准,不在此复制。
64
73
 
65
- ## 规划工作流
74
+ ### 5.3 正式发布
66
75
 
67
- - 复杂功能、跨模块修改、架构调整先用 `plan-workflow` skill 维护 `docs/plan/active/`;已归档内容只读,重开走受控流程。
68
- - 同一时间只推进一个主 feature;优先恢复已有 plan,不新建重复计划。
69
- - 施工与走查用 `checklist` skill 维护 `docs/checklist/active/dsh/`;回写完成 + 用户明确指令后才归档。
70
- - 每次实现完成、测试通过或发布后,回写 plan 的 §3.0/§5 与 checklist 的阶段/测试/执行日志,避免状态只在对话里。
76
+ - 唯一来源:`docs/release.md` + `.agents/skills/dsh-token-dash-release/SKILL.md`;GitHub Release 与 npm Trusted Publishing 均由 tag 触发。
77
+ - 流程:确认版本 → CHANGELOG 正式块 → L1 + E2E → pack → commit/push → tag → 双 workflow → 核验 npm latest 与 Release body;随后更新 `official-release-version.md`。
78
+ - Release body 按 tag 版本从 CHANGELOG 提取,不按“文件第一块”;local 块不得进入 Release body。
79
+ - 未获明确授权,不执行 `npm publish`、不推 tag、不声称已上线。
71
80
 
72
- ## Git 管理与临时文件
81
+ ### 5.4 本地构建
73
82
 
74
- - 入库:`src/`、`client.js`、`index.js`、`test/`、`scripts/`、`docs/`、`locale/`、`.agents/`、`.github/`、`README*`、`CHANGELOG.md`、`AGENTS.md`、`package.json`、`pnpm-lock.yaml`、`cordis.patch.yml`。
83
+ - **必须由用户显式指令触发**(“本地打包 / 本地版本 / 候选包”);完成 issue、修复、测试或提交后,不得自动改版本号、写 local 块、pack 或安装。
84
+ - 记录写 `CHANGELOG.md` 顶部 `## [X.Y.Z-local.N]`,标题下加 `> 本地构建,未发布`;不 tag、不发布;正式发布时合并进正式块并删除,最终历史不保留 local 块。
85
+ - 打包完成后立即回写当前 active plan 的进度。
86
+
87
+ ## 6. 仓库卫生
88
+
89
+ - 入库:`src/`、`client.js`、`index.js`、`test/`、`tools/`、`scripts/`、`docs/`、`locale/`、`.agents/`、`.github/`、`README*`、`CHANGELOG.md`、`AGENTS.md`、`package.json`、`pnpm-lock.yaml`、`cordis.patch.yml`。
75
90
  - 不入库:`node_modules/`、`build/`、`.tmp/`、`artifacts/`、`coverage/`、`playwright-report/`、`test-results/`、`*.tgz`、`*.log`、真实会话 JSONL、凭证与密钥。
91
+ - 临时产物、一次性脚本、MCP 输出统一放 `.tmp/`(预览图 `.tmp/preview/`);不在仓库根或 `src/` 下新建临时文件。
76
92
  - E2E 测试脚本与合成 fixture 必须入库;截图、日志、报告、trace 一律忽略。
77
93
  - `pnpm-lock.yaml` 必须提交,保证可复现安装。
78
94
 
79
- ## 安全
95
+ ## 7. 安全
80
96
 
81
97
  - 不读取 `~/.dsh/.credentials.yaml`;凭据只经宿主 `ctx.credentials.resolve(...)`。
82
98
  - 余额查询仅限 DeepSeek / Kimi / GLM / OpenRouter / Qwen 官方接口;第三方显示“第三方不支持”且不请求。
83
99
  - 密钥、cookie、token 不得出现在源码、日志、fixture 或提交信息中。
84
100
 
85
- ## 完成后的汇报
86
-
87
- - 汇报“本次改了什么 / 测试改了什么”前,先读取对应 commit:`git show --stat <commit>`、`git show --name-status <commit>`,并核对受影响测试与文档 diff。
88
- - 已提交内容、未提交工作区、运行态结果分开说明;不能用记忆或推测代替 commit 事实。
89
- - 本轮尚未形成 commit 时,明确标注“未提交”,不得说成“已完成修改”。
101
+ ## 8. 汇报
90
102
 
103
+ - 汇报“改了什么 / 测试改了什么”前,先读对应 commit:`git show --stat`、`git show --name-status`,并核对测试与文档 diff。
104
+ - 已提交内容、未提交工作区、运行态结果分开说明,不能用记忆或推测代替 commit 事实。
105
+ - 尚未形成 commit 时明确标注“未提交”,不得说成“已完成修改”。
package/README.en.md CHANGED
@@ -9,9 +9,9 @@
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- Track daily/monthly model spend and budget headroom right next to the DSH input box:<br />
13
- paste an API Key and the plan is auto-detected (subscription or pay-as-you-go), set a monthly budget, and consumption is estimated locally in real time;<br />
14
- export the current month as a backup and import it back after switching machines or reinstalling.
12
+ See today's model spend, monthly budget headroom, and subscription windows for 7 providers right next to the DSH input box.<br />
13
+ Paste a key and the billing mode is detected automatically; cost, Tokens and cache hits are estimated locally;<br />
14
+ export the current month and import it back after switching machines or reinstalling.
15
15
  </p>
16
16
 
17
17
  <p align="center">
@@ -26,41 +26,34 @@
26
26
  <img src="https://img.shields.io/github/downloads/spartawhy117/dsh-token-dash/total?label=downloads" alt="downloads" />
27
27
  <img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
28
28
  <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
29
+ <img src="https://img.shields.io/badge/DSH-0.2.2--rc.1_tested-4c8bf5" alt="DSH tested" />
29
30
  <a href="https://awesome-dsh-plugin.com/p/spartawhy117/dsh-token-dash"><img src="https://img.shields.io/badge/awesome--dsh--plugin-listed-6ea8ff" alt="awesome-dsh-plugin" /></a>
30
31
  </p>
31
32
 
32
- - **Providers**: DeepSeek (DS account / API key), GLM Coding (subscription), Kimi Coding (subscription), Kimi / OpenRouter / Qwen (pay-as-you-go; OpenRouter in USD, Qwen CNY domestic / USD international) — paste a key and the billing mode is detected automatically
33
- - **Pages**: bottom bar Pill → floating dashboard (usage / settings tabs); click the pill to expand, click outside to collapse
34
- - **Dashboard data**: time range (today / last 7 days / last 30 days / all), per-provider monthly budget progress (used / total / percent), today's spend, account balance, subscription 5h / weekly windows with reset times; two tiles for **total cost by currency** and **real Tokens (including cache read/write)**; per provider/model cost, requests and hit rate below
35
- - **Settings**: per-provider monthly budget (with currency, defaults to 100 when empty), three refresh intervals, balance toggle, logs, data export / import, check for updates
36
- - **Data**: daily / monthly usage estimated locally (built-in price catalog + community price table), three-layer model attribution, read-only local sessions; subscription models count toward Tokens but not cost, and the billing mode is pinned per key instead of following quota flakiness
33
+ **Three entry points, one local ledger**: the Pill shows the current model; the floating panel shows budget, balance and the usage table; the full dashboard shows every provider card and model breakdown. No duplicated accounting between pages.
37
34
 
38
- ---
35
+ ## Provider matrix
39
36
 
40
- ## Install
41
-
42
- Requires DSH `0.2.1` or newer. Three options:
43
-
44
- ```bash
45
- # Option 1: install from npm (recommended)
46
- dsh plugin --profile desktop add dsh-token-dash
47
-
48
- # Option 2: install straight from the GitHub repo (plain JS, no build step)
49
- dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
50
-
51
- # Option 3: download dsh-token-dash-x.y.z.tgz from Releases and install locally (offline)
52
- dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
53
- ```
37
+ | Provider | Billing | Credential | What you get |
38
+ |---|---|---|---|
39
+ | DeepSeek | Pay-as-you-go | DS account wallet / `DEEPSEEK_API_KEY` | Balance, month-to-date spend, budget |
40
+ | Zhipu GLM Coding | Subscription / API | `ZHIPU_API_KEY` / `GLM_API_KEY` / `ZAI_API_KEY` | 5h + weekly windows |
41
+ | Kimi Coding | Subscription / API | `KIMI_API_KEY` / `KIMI_CODING_API_KEY`, optional `MOONSHOT_API_KEY` | 5h + weekly/monthly windows; falls back to balance |
42
+ | OpenRouter | Pay-as-you-go | `OPENROUTER_API_KEY` | Credits (USD) |
43
+ | Qwen | Pay-as-you-go | `DASHSCOPE_API_KEY` (CNY) / `DASHSCOPE_INTL_API_KEY` (USD) | Usage only; balance unsupported |
44
+ | OpenCode Go | Subscription | `OPENCODE_GO_API_KEY` | 5h / weekly / monthly windows (USD) |
45
+ | Command Code | Subscription | `COMMAND_CODE_API_KEY` + `COMMAND_CODE_ORG_ID` | 5h + weekly windows, credits (CNY) |
54
46
 
55
- Update: run `update` with the same name, or use the `⤓` button on the right of “Pricing & version” in settings. Remove: run `remove` with the same name; data stays in `$DSH_HOME/dsh-token-dash/`.
56
-
57
- ---
47
+ - Save keys under the names above in DSH's credential settings; the plugin reads them through the host `credentials` service, not environment variables or local login files.
48
+ - Keys are detected automatically; GLM / Kimi / OpenCode Go / Command Code can be re-detected from the dashboard footer.
49
+ - Subscription models count toward Tokens but not cost; billing mode is pinned per key instead of following quota flakiness.
50
+ - Balance, quota and usage are separate; a balance failure never resets today's Token ledger to zero.
58
51
 
59
52
  ## Interface
60
53
 
61
- Screenshots below use mock data so the full layout is visible at once:
54
+ Screenshots use mock data so the full layout is visible at once.
62
55
 
63
- **P1 · Bottom bar pill** (pay-as-you-go and subscription variants; click to open the panel, click outside or `×` to close)
56
+ **P1 · Bottom bar Pill**: pay-as-you-go / subscription variants; click to open, click outside, `×` or `Esc` to close.
64
57
 
65
58
  <p align="center">
66
59
  <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-api.png" alt="Pay-as-you-go pill" />
@@ -70,45 +63,94 @@ Screenshots below use mock data so the full layout is visible at once:
70
63
  <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-sub.png" alt="Subscription pill" />
71
64
  </p>
72
65
 
73
- **P2 · Floating dashboard (usage tab)**: monthly budgets and subscriptions, time range, two summary tiles, per-model breakdown
66
+ **P2 · Floating panel (current model)**: fixed 380, one row with four groups — used ring / used-budget / real balance / month-to-date spend — a full-width range control and the usage table.
67
+
68
+ <p align="center">
69
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-api.png" alt="Floating panel - pay-as-you-go" />
70
+ </p>
71
+
72
+ <p align="center">
73
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-2.png" alt="Floating panel - two subscription windows" />
74
+ </p>
74
75
 
75
76
  <p align="center">
76
- <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-dashboard.png" alt="Dashboard" />
77
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-3.png" alt="Floating panel - three subscription windows" />
77
78
  </p>
78
79
 
79
- **P3 · Settings tab**: API billing, subscriptions, display, data & logs, pricing & version
80
+ - Subscription windows use three slots: first left, second center, third right; two windows occupy the first two slots.
81
+ - Model column is capped at 150; Tokens / requests / hit rate are right-aligned.
82
+
83
+ **P3 · Full dashboard**: cards for 7 providers, summary band, 8-column model breakdown and a settings capsule; the page owns its scrollbar at the window edge.
80
84
 
81
85
  <p align="center">
82
- <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="Settings" />
86
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="Full dashboard" />
83
87
  </p>
84
88
 
85
- ---
89
+ - Pay-as-you-go card: budget input, planned balance, real balance, month-to-date spend; subscription card: one ring per window with remaining percentage and countdown.
90
+ - Breakdown: model / Tokens / input / cache / output / requests / hit rate / cost; everything except the model column is right-aligned.
91
+ - Settings capsule: refresh interval + account-balance toggle; logs, export/import, price table and version below.
92
+ - Spacing uses only 4 / 8 / 12 / 16 / 24 / 32; P2 and P3 share the same tokens.
86
93
 
87
- ## Logs & privacy
94
+ ## Install
88
95
 
89
- When filing a bug, attach `$DSH_HOME/logs/dsh-token-dash/` (already redacted). Error log entries carry `errorKind` (http/timeout/network/parse) and `httpStatus`, which usually pinpoints the cause:
96
+ Requires DSH `0.2.1` or newer; tested on **DSH 0.2.2-rc.1**. DSH 0.2.2 itself requires Node **24.9+**.
90
97
 
91
98
  ```bash
92
- npm run logs -- --tail 50 # tail recent logs
93
- npm run logs -- --module slot,adapter.* # filter by module
99
+ # Option 1: install from npm (recommended)
100
+ dsh plugin --profile desktop add dsh-token-dash
101
+
102
+ # Option 2: install straight from the GitHub repo (plain JS, no build step)
103
+ dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
104
+
105
+ # Option 3: download dsh-token-dash-x.y.z.tgz from Releases and install locally (offline)
106
+ dsh plugin --profile desktop add /path/to/dsh-token-dash-x.y.z.tgz
94
107
  ```
95
108
 
96
- Reads only local session `usage` (title-generation overhead excluded); balances come from official endpoints only, with credentials resolved by the host and never written to disk; costs are local estimates — no billing requests are ever made.
109
+ Update: run `update` with the same name, or use the `⤓` button on the right of “Pricing & version” in settings. Remove: run `remove` with the same name; data stays in `$DSH_HOME/dsh-token-dash/`.
110
+
111
+ > If the plugin disappears from the profile after a DSH 0.2.2 upgrade, reinstall the same tarball. The ledger and settings are not deleted with the plugin package.
112
+
113
+ ## Compatibility & limitations
114
+
115
+ - DSH `0.2.1+`; verified on `0.2.2-rc.1`. DSH 0.2.2 is a pre-release and itself requires Node 24.9.
116
+ - After a DSH upgrade the plugin may disappear from the profile; reinstall the same tarball — the ledger is not deleted.
117
+ - Qwen tracks usage only; its balance endpoint is unsupported. Other balances/quotas follow what each API returns.
118
+ - Upstream APIs are rate-limited; successful results are cached for 60s, failures for 10s, and concurrent requests are coalesced.
119
+
120
+ ## Data & privacy
121
+
122
+ - Reads only local session `usage` (title-generation overhead excluded); cost and Tokens are local estimates — no billing requests.
123
+ - Balances come from official endpoints only; credentials are resolved by the host and are never written to disk or logs.
124
+ - Data lives in `$DSH_HOME/dsh-token-dash/`: `daily.json`, `months/`, `prefs.json`.
125
+ - Export/import is local: settings + current-month usage, without quotas, balances or logs; the existing files are backed up before an import overwrites them.
126
+
127
+ ## Logs & troubleshooting
128
+
129
+ Logs live in `$DSH_HOME/logs/dsh-token-dash/` as JSONL; every line carries `prefix: "[TD:<module>]"` and `module`:
130
+
131
+ ```bash
132
+ npm run logs -- --tail 50 # recent 50 lines
133
+ npm run logs -- --module adapter.* # provider detection only
134
+ npm run logs -- --module provider,route # cache / routing issues
135
+ ```
97
136
 
98
- Backups happen entirely on disk: `Export data` writes one JSON file (settings + current-month usage, without subscription quotas or balances), `Import data` only parses that file, and the existing files are backed up before the current month is overwritten. No network involved.
137
+ Common events:
99
138
 
100
- ---
139
+ - `[TD:adapter.*]`: `quota.ok` / `quota.fail` / `quota.parse` / `balance.*` / `detect.fail`
140
+ - `[TD:provider]`: `probe.miss` (none / hidden / error), `subscriptions.refreshed`, `cache.state`
141
+ - `[TD:route]`: `forbidden` (non-loopback), `failed`
142
+ - Errors carry `errorKind` (http / timeout / network / parse) and `httpStatus`; 5xx adds `upstream: true`.
101
143
 
102
144
  ## Development
103
145
 
104
146
  ```bash
105
- npm test # unit tests
147
+ npm test # unit tests (79 passing)
106
148
  npm run e2e # end-to-end (temp DSH_HOME + web profile + Playwright)
107
- npm run shots # regenerate the P1/P2/P3 screenshots in docs/pic from mock data (tools/mock)
149
+ npm run shots # regenerate the P1/P2/P3 screenshots in docs/pic from mock data
108
150
  npm run pack # build the release tarball into build/
109
151
  ```
110
152
 
111
- Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and a direct npm publish automatically (Trusted Publishing via OIDC, with provenance — no manual approval step); see [docs/release.md](./docs/release.md) for the full checklist.
153
+ Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and a direct npm publish automatically (Trusted Publishing via OIDC, with provenance); see [docs/release.md](./docs/release.md) for the full checklist.
112
154
 
113
155
  ## Acknowledgements
114
156
 
@@ -120,3 +162,5 @@ Attribution and billing semantics learned from these community plugins:
120
162
  - [dsh-spend](https://github.com/nonewind/dsh-spend)
121
163
  - [dsh-stats-panel](https://github.com/zhang-jiazhi/dsh-stats-panel)
122
164
  - [DshCockpit](https://github.com/Lxiayu/DshCockpit)
165
+ - [shy3130/dsh-quota](https://github.com/shy3130/dsh-quota) (OpenCode Go / cache structure reference)
166
+ - [InvisibleSirius/dsh-quota-dashboard](https://github.com/InvisibleSirius/dsh-quota-dashboard) (multi-provider table reference)
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- 在 DSH 输入框旁看清每日/每月模型消耗与预算余量:<br />
13
- API Key 一填即自动识别订阅还是按量计费,月度预算可设、消耗实时估算;<br />
12
+ 在 DSH 输入框旁看清今天的模型消耗、本月的预算余量,以及 7 家供应商的订阅窗口。<br />
13
+ 填 Key 自动识别订阅或按量计费;费用、Tokens、缓存命中全部在本地估算;<br />
14
14
  当月数据可导出备份,换机或重装后一键导入恢复。
15
15
  </p>
16
16
 
@@ -26,41 +26,34 @@
26
26
  <img src="https://img.shields.io/github/downloads/spartawhy117/dsh-token-dash/total?label=downloads" alt="downloads" />
27
27
  <img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
28
28
  <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
29
+ <img src="https://img.shields.io/badge/DSH-0.2.2--rc.1_tested-4c8bf5" alt="DSH tested" />
29
30
  <a href="https://awesome-dsh-plugin.com/zh/p/spartawhy117/dsh-token-dash"><img src="https://img.shields.io/badge/awesome--dsh--plugin-listed-6ea8ff" alt="awesome-dsh-plugin" /></a>
30
31
  </p>
31
32
 
32
- - **厂商支持**:DeepSeek(DS 账号 / API Key)、GLM Coding(订阅)、Kimi Coding(订阅)、Kimi / OpenRouter / Qwen(按量,OpenRouter USD、Qwen 国内 CNY / 国际 USD)——填 Key 自动识别订阅或按量计费
33
- - **页面**:底栏 Pill → 浮层看板(用量 / 设置双 tab);Pill 点击展开、点击浮层外收起
34
- - **看板数据**:时间范围(当天 / 近 7 天 / 近 30 天 / 全部)、本月预算进度(已用 / 总额 / 百分比)、今日消耗、账户余额、订阅 5h / 周窗口与重置时间;两格卡显示**总费用(按币种)**与**真实 Tokens(含缓存读写)**;下方按 provider / 模型列出费用、请求数与命中率
35
- - **设置**:按供应商的月度预算(带币种,未填写默认 100)、刷新间隔三档、账户余额开关、日志、数据导出 / 导入、检查更新
36
- - **数据口径**:每日 / 每月用量本地估算(内置价格表 + 社区价格表),三层模型归属,只读本地会话;订阅模型计入 Tokens 但不计费用,计费形态按 Key 固化,不随配额接口抖动
33
+ **三个入口,一份数据**:底栏 Pill 看当前模型;浮层看预算、余额与用量表;整页看 7 家供应商的全量卡片与模型明细。所有页面共用同一份本地账本,不重复计算。
37
34
 
38
- ---
35
+ ## 支持矩阵
39
36
 
40
- ## 安装
41
-
42
- 需要 DSH `0.2.1` 或更新版本,三种方式任选:
43
-
44
- ```bash
45
- # 方式一:npm 安装(推荐)
46
- dsh plugin --profile desktop add dsh-token-dash
47
-
48
- # 方式二:GitHub 仓库直装(纯 JS 无构建,源码即产物)
49
- dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
50
-
51
- # 方式三:从 Releases 下载 dsh-token-dash-x.y.z.tgz 后本地安装(离线场景)
52
- dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
53
- ```
37
+ | 供应商 | 计费形态 | 凭据 | 能看到什么 |
38
+ |---|---|---|---|
39
+ | DeepSeek | 按量 | DS 账号钱包 / `DEEPSEEK_API_KEY` | 账户余额、本月已花、预算 |
40
+ | 智谱 GLM Coding | 订阅 / 按量 | `ZHIPU_API_KEY` / `GLM_API_KEY` / `ZAI_API_KEY` | 5h + 周窗口 |
41
+ | Kimi Coding | 订阅 / 按量 | `KIMI_API_KEY` / `KIMI_CODING_API_KEY`,可选 `MOONSHOT_API_KEY` | 5h + 周/月窗口;订阅查询失败可回落余额 |
42
+ | OpenRouter | 按量 | `OPENROUTER_API_KEY` | Credits(USD) |
43
+ | 通义千问 | 按量 | `DASHSCOPE_API_KEY`(CNY)/ `DASHSCOPE_INTL_API_KEY`(USD) | 仅用量;余额不支持 |
44
+ | OpenCode Go | 订阅 | `OPENCODE_GO_API_KEY` | 5h / 周 / 月窗口(USD) |
45
+ | Command Code | 订阅 | `COMMAND_CODE_API_KEY` + `COMMAND_CODE_ORG_ID` | 5h + 周窗口、Credits(CNY) |
54
46
 
55
- 更新:`update` 同名命令(npm / github: 各自同名),或在插件设置页「价格与版本」右侧的 `⤓` 内完成。卸载:`remove` 同名命令,数据保留在 `$DSH_HOME/dsh-token-dash/`。
56
-
57
- ---
47
+ - 在 DSH 的凭据设置中按上表名称保存 Key;插件只通过宿主 `credentials` 读取,不读环境变量或本机登录文件。
48
+ - 填 Key 后自动探测;GLM / Kimi / OpenCode Go / Command Code 可在「全量看板」底部重新检测订阅。
49
+ - 订阅模型计入 Tokens,但不计费用;计费形态按 Key 固化,不随配额接口抖动。
50
+ - 余额、配额、用量分开展示;余额失败不会把当天的 Token 记账清零。
58
51
 
59
52
  ## 界面
60
53
 
61
- 以下截图使用假数据演示,便于一次看到完整效果:
54
+ 以下截图使用假数据演示,便于一次看到完整效果。
62
55
 
63
- **P1 · 底栏 Pill**(按量 / 订阅两种形态;点击展开看板,点击浮层外或 `×` 收起)
56
+ **P1 · 底栏 Pill**:按量 / 订阅两种形态,点击展开浮层,点击外部、`×` 或 `Esc` 收起。
64
57
 
65
58
  <p align="center">
66
59
  <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-api.png" alt="按量 Pill" />
@@ -70,45 +63,94 @@ dsh plugin --profile desktop add /path/to/dsh-token-dash-1.1.0.tgz
70
63
  <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/pill-sub.png" alt="订阅 Pill" />
71
64
  </p>
72
65
 
73
- **P2 · 浮层看板(用量 tab)**:本月预算与订阅、时间范围、两格统计卡、按模型明细
66
+ **P2 · 浮层(当前模型)**:固定 380,单行四组「已用环 / 已用·预算 / 真实余额 / 本月已花」;时间范围撑满,下面是用量表。
67
+
68
+ <p align="center">
69
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-api.png" alt="浮层 · 按量形态" />
70
+ </p>
71
+
72
+ <p align="center">
73
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-2.png" alt="浮层 · 订阅两窗" />
74
+ </p>
74
75
 
75
76
  <p align="center">
76
- <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-dashboard.png" alt="浮层看板" />
77
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/panel-sub-3.png" alt="浮层 · 订阅三窗" />
77
78
  </p>
78
79
 
79
- **P3 · 设置 tab**:API 计费、订阅、显示、数据与日志、价格与版本
80
+ - 订阅窗口固定三槽位:第 1 窗左、第 2 窗中、第 3 窗右;只有两窗时占前两个槽位。
81
+ - 模型列上限 150,Tokens / 请求 / 命中右对齐;长模型名用省略号,悬浮可看全名。
82
+
83
+ **P3 · 整页看板**:7 家供应商卡片、摘要带、8 列模型明细、底部设置胶囊;页面自己滚动,滚动条贴窗口右缘。
80
84
 
81
85
  <p align="center">
82
- <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="设置" />
86
+ <img src="https://raw.githubusercontent.com/spartawhy117/dsh-token-dash/main/docs/pic/settings.png" alt="整页看板" />
83
87
  </p>
84
88
 
85
- ---
89
+ - 按量卡:预算输入、计划余额、真实余额、本月已花;订阅卡:每个窗口一个环 + 剩余百分比 + 倒计时。
90
+ - 明细表:模型 / Tokens / 输入 / 缓存 / 输出 / 请求 / 命中 / 费用;除模型列外全部右对齐。
91
+ - 设置胶囊:第一行刷新间隔 + 账户余额开关;下面是日志、导出导入、价格表与版本。
92
+ - 间距只使用 4 / 8 / 12 / 16 / 24 / 32 六档,P2 / P3 同一套 token。
86
93
 
87
- ## 日志与隐私
94
+ ## 安装
88
95
 
89
- 报障时附上 `$DSH_HOME/logs/dsh-token-dash/`(已脱敏),错误日志带 `errorKind`(http/timeout/network/parse)与 `httpStatus`,可直接定位原因:
96
+ 需要 DSH `0.2.1` 或更新版本;已在 **DSH 0.2.2-rc.1** 上验证。DSH 0.2.2 自身要求 Node **24.9+**。
90
97
 
91
98
  ```bash
92
- npm run logs -- --tail 50 # 查看最近日志
93
- npm run logs -- --module slot,adapter.* # 按模块过滤
99
+ # 方式一:npm 安装(推荐)
100
+ dsh plugin --profile desktop add dsh-token-dash
101
+
102
+ # 方式二:GitHub 仓库直装(纯 JS 无构建,源码即产物)
103
+ dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
104
+
105
+ # 方式三:从 Releases 下载 dsh-token-dash-x.y.z.tgz 后本地安装(离线场景)
106
+ dsh plugin --profile desktop add /path/to/dsh-token-dash-x.y.z.tgz
94
107
  ```
95
108
 
96
- 只读本地会话 `usage`,不统计标题生成开销;余额仅访问官方接口,凭据经宿主解析不落盘;费用为本地估算,不发起计费请求。
109
+ 更新:`update` 同名命令(npm / github: 各自同名),或在插件设置页「价格与版本」右侧的 `⤓` 内完成。卸载:`remove` 同名命令,数据保留在 `$DSH_HOME/dsh-token-dash/`。
110
+
111
+ > DSH 0.2.2 升级后如果插件从 profile 消失,重装同一个 tarball 即可;账本与设置不随插件包删除。
112
+
113
+ ## 兼容与限制
114
+
115
+ - DSH `0.2.1+`;已在 `0.2.2-rc.1` 上验证。DSH 0.2.2 是预发布版,且自身要求 Node 24.9。
116
+ - 升级 DSH 后插件可能从 profile 消失,重装同一个 tarball 即可,账本不会被删。
117
+ - 通义千问只统计用量,余额接口不支持;其余供应商的余额/配额以接口实际返回为准。
118
+ - 上游接口有速率限制;成功结果缓存 60s、失败结果缓存 10s,并发请求会合并。
119
+
120
+ ## 数据与隐私
121
+
122
+ - 只读本地会话 `usage`,不统计标题生成;费用与 Tokens 在本地按价格表估算,不发起计费请求。
123
+ - 余额只访问官方接口;凭据经宿主解析,不落盘、不写日志。
124
+ - 数据默认在 `$DSH_HOME/dsh-token-dash/`:`daily.json`、`months/`、`prefs.json`。
125
+ - 导出 / 导入都在本地完成:导出设置 + 当月使用数据,不含配额、余额与日志;导入覆盖前会备份原文件。
126
+
127
+ ## 日志与排障
128
+
129
+ 日志在 `$DSH_HOME/logs/dsh-token-dash/`,JSONL,每行带 `prefix: "[TD:<module>]"` 与 `module`:
130
+
131
+ ```bash
132
+ npm run logs -- --tail 50 # 最近 50 条
133
+ npm run logs -- --module adapter.* # 只看供应商侦测
134
+ npm run logs -- --module provider,route # 缓存 / 路由异常
135
+ ```
97
136
 
98
- 数据备份在本地完成:`导出数据` 生成一个 JSON 文件(设置 + 当月使用数据,不含订阅配额与余额),`导入数据` 只解析该文件,覆盖当月前自动备份原文件,全过程不经过网络。
137
+ 常见事件:
99
138
 
100
- ---
139
+ - `[TD:adapter.*]`:`quota.ok` / `quota.fail` / `quota.parse` / `balance.*` / `detect.fail`
140
+ - `[TD:provider]`:`probe.miss`(未配置 / 隐藏 / 失败)、`subscriptions.refreshed`、`cache.state`
141
+ - `[TD:route]`:`forbidden`(非回环请求)、`failed`
142
+ - 错误带 `errorKind`(http / timeout / network / parse)与 `httpStatus`;5xx 额外 `upstream: true`
101
143
 
102
144
  ## 开发
103
145
 
104
146
  ```bash
105
- npm test # 单元测试
147
+ npm test # 单元测试(79 通过)
106
148
  npm run e2e # 端到端(临时 DSH_HOME + web profile + Playwright)
107
- npm run shots # 用假数据重新生成 docs/pic 的 P1/P2/P3 截图(tools/mock)
149
+ npm run shots # 用假数据重新生成 docs/pic 的 P1/P2/P3 截图
108
150
  npm run pack # 发布 tarball 生成到 build/
109
151
  ```
110
152
 
111
- 发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 直发(Trusted Publishing / OIDC,含 provenance 溯源,无需人工审批);完整流程见 [docs/release.md](./docs/release.md)。
153
+ 发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 直发(Trusted Publishing / OIDC,含 provenance);完整流程见 [docs/release.md](./docs/release.md)。
112
154
 
113
155
  ## 致谢
114
156
 
@@ -120,3 +162,5 @@ npm run pack # 发布 tarball 生成到 build/
120
162
  - [dsh-spend](https://github.com/nonewind/dsh-spend)
121
163
  - [dsh-stats-panel](https://github.com/zhang-jiazhi/dsh-stats-panel)
122
164
  - [DshCockpit](https://github.com/Lxiayu/DshCockpit)
165
+ - [shy3130/dsh-quota](https://github.com/shy3130/dsh-quota)(OpenCode Go / 缓存结构参考)
166
+ - [InvisibleSirius/dsh-quota-dashboard](https://github.com/InvisibleSirius/dsh-quota-dashboard)(多 provider 源表参考)