dsh-cost-meter 1.8.36 → 1.9.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 dsh-cost-meter contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-cost-meter contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,20 +8,20 @@ Community and feedback: [Join the WeChat group →](#community). The WeChat grou
8
8
 
9
9
  **Session cost tracking plugin for the DeepSeek Harness web GUI (bilingual UI)**
10
10
 
11
- Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00; weekends and Chinese public holidays are off-peak all day, with separate labels) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo / Factory Droid) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
11
+ Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00; weekends and Chinese public holidays are off-peak all day, with separate labels) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo / Factory Droid) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · subscription plugin compatibility (Codex / ChatGPT subscription plans) · mobile layout (dsh-pocket) · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
12
12
 
13
- [![version](https://img.shields.io/badge/version-1.8.36-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
13
+ [![version](https://img.shields.io/badge/version-1.9.0-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
14
14
 
15
15
  **Minimum supported host: DSH 0.2.0.** The plugin declares the floor in `engines.dsh`, the host's admission gate for plugins, and no longer supports any DSH 0.1.x release; the adaptation target is the npm `next` release **0.2.1-rc.2**. Exact ranges and how the host reads them: [compatibility declaration](docs/dsh-0.2.1-compatibility.md#english).
16
16
 
17
17
  Supports [official Search/Fetch request fees](docs/web-request-fees.md#english), separately from model tokens.
18
18
 
19
- **v1.8.36** fixes pre-upgrade sessions showing ¥0 ([#300](https://github.com/Han-1413141/dsh-cost-meter/issues/300)), stops false balance-drift warnings when a granted balance partially expires ([#302](https://github.com/Han-1413141/dsh-cost-meter/issues/302)), and documents pnpm supply-chain install/uninstall failures on DSH 0.2.1-rc.x ([troubleshooting](docs/pnpm-supply-chain-policy.md#english)). USD ledger data, historical amounts and pricing rules are unchanged.
19
+ **v1.9.0** adds compatibility with the Codex and ChatGPT subscription plugins (subscription calls classified as Plan quota instead of API spend, with a one-time dismissible history prompt), supports better-session's SQLite session storage, adapts every cost UI to dsh-pocket mobile layouts, and restores OpenDesign coding-plan quota queries via a Control-Key `/billing/preflight` fallback with independent window/wallet degradation ([#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566)). The ledger format is unchanged and historical amounts are not recalculated automatically.
20
20
 
21
21
 
22
22
  Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
23
23
 
24
- Release notes: [v1.8.36](docs/update-notes-1.8.36.md#english). Fully restart DSH after updating.
24
+ Release notes: [v1.9.0](docs/update-notes-1.9.0.md#english). Fully restart DSH after updating.
25
25
 
26
26
  Host records inside the declared range, and the earlier 0.1.x history, are in the [compatibility record](docs/host-compatibility.md); the per-release list lives in `package.json` (`dsh.compatibility.dshReleases`).
27
27
 
@@ -51,6 +51,10 @@ If startup reports **Ledger is busy** and the cost widgets are missing, see [led
51
51
  | Custom provider balance | Sidebar / Settings page (configurable) | Configurable HTTP balance lookup (e.g. LiteLLM); bilingual labels, currency, extract rules (dot path / number / add / subtract / divide — use divide for NewApi-style quota endpoints, see [example](#custom-provider-balance-example-newapi-template)); collapsible panel alongside Coding Plan quotas |
52
52
  | OpenCode Go quota | Sidebar / Settings / bottom-right dock (configurable) | Rolling-5h / weekly / monthly usage percent and reset times, each window toggleable independently, budget used % can show alongside; key auto-discovered (dedicated ref / official Go route apiKeyEnv / env / opencode login) or entered manually |
53
53
  | Coding plan quotas | Sidebar / Settings page (per vendor) | Multi-vendor coding-plan quota queries (Anthropic Claude Pro/Max, Z.ai / Zhipu GLM Coding Plan, MiniMax Token Plan, Kimi Code weekly + 5-hour quotas with PAYG balance fallback when no subscription key, OpenRouter credits, SiliconFlow balance, CommandCode 5h/weekly windows + monthly credits balance, Xiaomi MiMo Token Plan plan/compensation credit windows + period-end reset + balance via console cookie); per-vendor enable switch, key, display position and refresh interval (sidebar card in the same box style as the Go quota; the collapsed rail shows percentages), official endpoints by default, with a [configurable trusted MiniMax origin](docs/minimax-quota-endpoint.md#english); neutral hints when no credentials/subscription; SCNet Token Plan supports [external console snapshots](docs/scnet-official-snapshot.md#english); without a valid snapshot, monthly usage is estimated from the local ledger via the official credits deduction table (no credentials needed) |
54
+ | Subscription plugin compatibility | Settings → Cost → Codex / sidebar & quota cards | Detects installed Codex / ChatGPT subscription plugins and classifies their subscription calls as Plan quota instead of pay-as-you-go API spend; new usage is classified at record time, and a one-time dismissible prompt decides whether historical Codex billing is reclassified (idempotent). Explicit plan/API choices are never overridden. [Details](docs/update-notes-1.9.0.md#english) |
55
+ | SQLite session storage (better-session) | Host integration | Auto-detects the host session backend; with `@morlay/better-session` / `@morlay/session-rdb` (SQLite) storage, historical backfill, legacy import, history repricing, hour-bucket repair, fork cleanup and per-session cost/trajectory/call details keep working. The JSONL path is unchanged; old JSONL and RDB histories are not merged automatically. [Guide](docs/better-session.md) |
56
+ | OpenDesign quota | Sidebar / Settings (OpenDesign vendor) | Workspace coding-plan windows from the console API; with a Control Key, a 401/403 from the primary endpoint triggers one conservative `/billing/preflight` Bearer fallback, and window/wallet reads degrade independently. [Troubleshooting](docs/opendesign-billing.md#english) |
57
+ | Mobile / dsh-pocket layout | All cost UIs | On screens ≤1023px and dsh-pocket mobile layouts: single-column cards, horizontally scrolling tabs, 36px touch targets, dialogs capped at 90vh with safe-area padding and scrolling wide tables; desktop layout unchanged |
54
58
  | Quota strip | Above the input box (toggle in Display settings) | One compact chip row for budget used % / the Go main window / each enabled coding-plan usage window (short label + mini progress bar, ≥80% warn, ≥100% over, hover for reset times); click any chip to refresh its data source (budget → state, Go → Go quota, vendor → all its windows); multiple windows of one vendor merge into a single segmented chip; a first-run guide card lets you decide whether to enable it; hides itself when there is no quota data |
55
59
  | Click to refresh | Sidebar balance/quota boxes | Click the official balance / custom balance / coding-plan box (collapsed rail included) to fetch the latest data immediately; the box pulses while refreshing, failures keep the previous value and surface the reason in the hover tooltip; keyboard Enter/Space also triggers; a one-time guide card appears after the update |
56
60
  | Simple sidebar display | Settings → Cost → Display | Optional, with a one-time choice after updating. Condenses cards and caps panel height at 38% of the viewport and 320 px, while preserving amounts, quotas, refresh actions and hover details. Turn off to restore your layout. [Guide](docs/sidebar-simple.md#english) |
@@ -334,22 +338,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
334
338
  dsh plugin --profile web add dsh-cost-meter
335
339
  ```
336
340
 
337
- **PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.8.36`** — review the script before running):
341
+ **PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.9.0`** — review the script before running):
338
342
 
339
343
  ```powershell
340
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.36/install.ps1 | iex
344
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.0/install.ps1 | iex
341
345
  ```
342
346
 
343
347
  **Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
344
348
 
345
349
  ```sh
346
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.36
350
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.0
347
351
  ```
348
352
 
349
353
  Without git, use the GitHub tag archive:
350
354
 
351
355
  ```sh
352
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.36.tar.gz
356
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.9.0.tar.gz
353
357
  ```
354
358
 
355
359
  After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
@@ -414,7 +418,7 @@ Workarounds:
414
418
 
415
419
  ```yaml
416
420
  minimumReleaseAgeExclude:
417
- - dsh-cost-meter@1.8.36
421
+ - dsh-cost-meter@1.9.0
418
422
  ```
419
423
 
420
424
  3. For a one-off CLI operation, forward the pnpm flag: `dsh plugin --profile desktop remove dsh-cost-meter --config.minimum-release-age=0` (or add `--trust-lockfile` when only lockfile verification fails). Both flags were verified against pnpm 11.28.5 in a temporary profile.
@@ -455,7 +459,7 @@ dsh plugin --profile web add link:./dsh-cost-meter # symlink; edit lib/client.j
455
459
  - **Historical pricing**: changing pricing currency, rates or mappings affects subsequent calls. Saved price versions preserve older details; explicit recalculation requires confirmation and retains original amounts, price versions and a full ledger backup. See the [update notes](docs/update-notes-2026-10-15.md#english).
456
460
  - **Aligning with official bills**: ① minute-level lag vs live official numbers is expected — the ledger flushes on a 2s debounce, and streams still in flight at shutdown are billed server-side while their usage block is never received (the gap concentrates in cache-hit columns); ② reasoning tokens are reported separately by the API and are **not billed** — the token columns sum five buckets and will never line up with the official three columns, so **reconcile by amount**; ③ with pricing currency set to CNY, entries are recorded directly on the official CNY price list (recommended for CNY-billed accounts); with USD, displayed amounts go through a fixed FX rate and carry a small structural difference (the two lists' per-column ratios are not uniform); ④ granted-balance expiry or reclaim is not consumption: when the day's balance drop is confined to the granted bucket (top-up balance unchanged) and local official-channel usage explains at most a quarter of it, the reconciliation baseline is reset with an informational expiry/reclaim notice instead of a consumption-drift warning;
457
461
  - Budget and over-budget warnings **only warn — they never block calls**.
458
- - **Plan/API dual-track billing** (issue #64): calls on subscription-style channels (MiniMax, manually-marked Codex, etc.) are recorded as catalog-price equivalents only; budget/today-cost/overview cards count the pay-as-you-go (API) channel exclusively.
462
+ - **Plan/API dual-track billing** (issue #64): calls on subscription-style channels (MiniMax, Codex / ChatGPT subscription plugins, etc.) are recorded as catalog-price equivalents only; budget/today-cost/overview cards count the pay-as-you-go (API) channel exclusively.
459
463
  - **Full-repo security audit fixes**: resolved 3 high-risk findings — ledger writes lost on exit (close/flush ordering), command injection in the release script, panel null-pointer crash on null Go monthly window — plus 30+ medium/low issues including missing hour-bucket entries for routed calls, dead balance-reconciliation warnings, failed custom-balance extraction silently showing $0, and leaked upstream streams on consumer abort; ledger corruption auto-backup, write-failure retry, config-patch atomicity and prototype-chain hardening included. Itemized list: [CHANGELOG.md](CHANGELOG.md).
460
464
  - **"Include plan totals" toggle** under the overview cards switches every amount between real-money (API channels only, default) and total equivalent cost (plan subscriptions included); routed calls with a missing provider whose models match third-party catalogs are auto-classified into the matching plan, and legacy per-day residuals without model details count toward the API scope; The Token Plan stats panel in Settings → Usage provides per-1% and full-window token/equivalent-cost estimates plus daily/weekly/monthly usage curves; classification is configurable per vendor and per provider:model.
461
465
 
package/README.zh-CN.md CHANGED
@@ -8,20 +8,20 @@
8
8
 
9
9
  **DeepSeek Harness 会话费用统计插件(界面中英双语)**
10
10
 
11
- 本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
11
+ 本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 订阅插件兼容(Codex / ChatGPT 订阅) · 手机端适配(dsh-pocket) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
12
12
 
13
- [![version](https://img.shields.io/badge/version-1.8.36-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
13
+ [![version](https://img.shields.io/badge/version-1.9.0-4176E6)](https://github.com/Han-1413141/dsh-cost-meter)
14
14
 
15
15
  **最低支持宿主:DSH 0.2.0。** 插件把下限声明在 `engines.dsh`(宿主准入插件的闸门),不再支持任何 DSH 0.1.x 版本;本轮适配目标为 npm `next` 标签的 **0.2.1-rc.2**。具体范围与宿主的读取方式见[兼容声明](docs/dsh-0.2.1-compatibility.md#中文)。
16
16
 
17
17
  新增 [DeepSeek Search/Fetch API 次数费](docs/web-request-fees.md#中文),只计有结果的成功请求,并将网页抓取独立分类。
18
18
 
19
- **v1.8.36** 修复升级后老会话费用显示 ¥0([#300](https://github.com/Han-1413141/dsh-cost-meter/issues/300)),赠送余额部分到期/回收不再误报消费偏差([#302](https://github.com/Han-1413141/dsh-cost-meter/issues/302)),并补充 DSH 0.2.1-rc.x 宿主内置 pnpm 供应链策略导致的安装/卸载失败排障([说明](docs/pnpm-supply-chain-policy.md))。USD 账本数据、历史金额与计价规则不变。
19
+ **v1.9.0** 新增 Codex / ChatGPT 订阅插件兼容(订阅调用归为 Plan 订阅额度、不计入 API 花费,首次检测弹出一次性可关闭提示处理历史归类)、better-session 的 SQLite 会话存储兼容、全部费用界面的 dsh-pocket 手机端适配,并按 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566) 为 OpenDesign 增加 Control Key `/billing/preflight` 回退与窗口/钱包独立降级。账本格式不变,不自动重算历史金额。
20
20
 
21
21
 
22
22
  桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
23
23
 
24
- 更新说明:[v1.8.36](docs/update-notes-1.8.36.md#中文)。更新后完全重启 DSH。
24
+ 更新说明:[v1.9.0](docs/update-notes-1.9.0.md#中文)。更新后完全重启 DSH。
25
25
 
26
26
  声明范围内的宿主记录与此前的 0.1.x 历史见[兼容记录](docs/host-compatibility.md);逐版本清单在 `package.json` 的 `dsh.compatibility.dshReleases`。
27
27
 
@@ -51,6 +51,10 @@
51
51
  | 自定义 Provider 余额 | 侧边栏 / 设置页(可配) | 可配置 HTTP 查询任意 Provider 余额(LiteLLM 等);中/英名称、币种、extract 规则(点路径 / 数字常量 / add / subtract / divide,divide 适配 NewApi 等 quota 端点,见下方[示例](#自定义-provider-余额配置示例newapi-模板));与 Coding Plan 同区可折叠配置 |
52
52
  | OpenCode Go 额度 | 侧边栏 / 设置页 / 右下角(dock,可配) | 滚动 5 小时 / 本周 / 本月用量百分比与重置时间,三档可分别开关,可同时显示预算已用%;Key 自动发现(专用引用 / 官方 Go 路由 apiKeyEnv / 环境变量 / opencode 登录态)或手动填写 |
53
53
  | Coding Plan 额度 | 侧边栏 / 设置页(每家可配) | 多厂商 coding plan 订阅额度查询(Anthropic Claude Pro/Max、Z.ai/智谱 GLM、MiniMax Token Plan、Kimi Code 本周/5 小时配额(无订阅 Key 时回落 PAYG 余额)、OpenRouter credits、SiliconFlow 余额、CommandCode 5h/周窗口与月度 Credits 余额、小米 MiMo Token Plan 套餐/补偿积分窗口与周期截止重置、余额(控制台 Cookie 凭据)、火山方舟 Volcano Ark 5h/周/月三档(需 AK/SK 管控面 HMAC 签名,需 ArkReadOnlyAccess + BillingCenterReadOnlyAccess)),各家独立启用开关、凭据、显示位置与刷新间隔(侧边栏卡片与 Go 额度同款,收起窄栏显示百分比),默认使用官方端点,MiniMax 可[配置可信查询域名](docs/minimax-quota-endpoint.md);无凭据/无订阅为中性提示;SCNet 超算互联网 Token Plan 支持[外部控制台额度快照](docs/scnet-official-snapshot.md),无有效快照时按官方 Credits 抵扣表由本地账本估算月度用量(无需凭据) |
54
+ | 订阅插件兼容 | 设置 → 费用 → Codex / 侧边栏与额度卡片 | 自动检测已安装的 Codex / ChatGPT 订阅插件,把其订阅调用归为 Plan 订阅额度、不计入 API 按量花费;新用量在记账时直接归类,历史 Codex 计费由一次性可关闭提示确认后重算(幂等)。显式 plan/API 配置不被覆盖。[说明](docs/update-notes-1.9.0.md#中文) |
55
+ | SQLite 会话存储(better-session) | 宿主集成 | 自动探测宿主会话后端;当 `@morlay/better-session` / `@morlay/session-rdb`(SQLite)接管存储时,历史回填、旧账本导入、历史重定价、小时桶修复、fork 清洗与逐会话费用/轨迹/调用详情继续可用。JSONL 路径行为不变;旧 JSONL 与 RDB 历史不自动合并。[说明](docs/better-session.md) |
56
+ | OpenDesign 额度 | 侧边栏 / 设置页(OpenDesign 厂商) | 从控制台 API 读取工作区 coding plan 窗口;使用 Control Key 时主端点 401/403 会保守回退一次 `/billing/preflight`,窗口与钱包读取独立降级。[排查说明](docs/opendesign-billing.md#中文) |
57
+ | 手机端适配(dsh-pocket) | 全部费用界面 | ≤1023px 窄屏与 dsh-pocket 移动布局下:卡片单列、标签横向滚动、36px 触控高度、对话框不超过 90vh 并避开安全区、宽表横向滚动;桌面布局不变 |
54
58
  | 额度横条 | 输入框上方(显示设置可开关) | 一条横排 chips 实时显示预算已用% / Go 主窗口 / 各已启用 Coding Plan 用量窗口(短标签+迷你进度条,≥80% 预警、≥100% 超支,悬停见重置时刻);点击任意 chip 即刷新对应数据源(budget→状态、Go→Go 额度、厂商→该家全部窗口),同一厂商多窗口融合为一条 chip 分段显示;首次更新弹引导卡由用户自主决定开关;无可用数据自动隐藏 |
55
59
  | 点击立即刷新 | 侧边栏余额/额度图框 | 官方余额 / 自定义余额 / Coding Plan 图框(含窄栏收起态)点击即触发一次查询,刷新中呼吸闪烁,失败保持原值并在悬停提示说明;键盘 Enter/Space 可触发;更新后首次进入有引导提示 |
56
60
  | 简化侧栏显示 | 设置 → 费用 → 显示 | 可选开启;更新首次提示选择,压缩卡片和明细,面板高度限制为视口的 38% 且不超过 320 像素;保留金额、额度、点击刷新与悬停详情,关闭后恢复原布局。[使用说明](docs/sidebar-simple.md) |
@@ -334,22 +338,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
334
338
  dsh plugin --profile web add dsh-cost-meter
335
339
  ```
336
340
 
337
- **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.36`**,建议先下载审阅再运行):
341
+ **PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.9.0`**,建议先下载审阅再运行):
338
342
 
339
343
  ```powershell
340
- irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.36/install.ps1 | iex
344
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.0/install.ps1 | iex
341
345
  ```
342
346
 
343
347
  **或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
344
348
 
345
349
  ```sh
346
- dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.36
350
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.0
347
351
  ```
348
352
 
349
353
  没有 git 时可用 GitHub tag 打包直链:
350
354
 
351
355
  ```sh
352
- dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.36.tar.gz
356
+ dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.9.0.tar.gz
353
357
  ```
354
358
 
355
359
  安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
@@ -414,7 +418,7 @@ DSH **0.2.1-rc.1 / 0.2.1-rc.2** 宿主自带 pnpm **11.28.5**,默认启用内
414
418
 
415
419
  ```yaml
416
420
  minimumReleaseAgeExclude:
417
- - dsh-cost-meter@1.8.36
421
+ - dsh-cost-meter@1.9.0
418
422
  ```
419
423
 
420
424
  3. 仅本次操作用 CLI 透传 pnpm 参数:`dsh plugin --profile desktop remove dsh-cost-meter --config.minimum-release-age=0`;若只是 lockfile 校验阶段失败,可改用 `--trust-lockfile`。这两个参数已在本机 pnpm 11.28.5 临时 Profile 上实测可用。
@@ -455,7 +459,7 @@ dsh plugin --profile web add link:./dsh-cost-meter # 符号链接,改 lib/clien
455
459
  - **历史价格保护**:「价格币种」、单价和价格映射的修改只影响后续调用,旧明细使用已保存的价格版本。主动重算前需要确认,并保留原金额、价格版本和完整账本备份。详见[更新说明](docs/update-notes-2026-10-15.md#中文)。
456
460
  - **官方账单对齐口径**:① 与官方实时数字存在**分钟级时差**属预期——账本 2 秒防抖落盘,关停瞬间仍在途的流会被服务端照常扣费而 usage 块无人接收(缺口集中在缓存命中列);② reasoning tokens 由 API 单独上报且**不计费**,token 列为五桶合计,与官方「三列」天然对不齐,**对账请以金额为准**;③ 「价格币种」设为人民币时按官方 CNY 价目直计入账,与人民币账单币种一致(CNY 计价账号推荐);设为 USD 时显示金额经固定汇率折算,与 CNY 直计存在结构性细差(两套价目比值非均匀);④ 赠送余额到期/回收不算消费:当日余额减少只发生在赠送桶(充值余额不变)、且本地官方渠道费用最多只能解释减量的 1/4 时,重置对账基准并给出「可能是赠送余额到期/回收」的说明,不再按消费偏差告警;
457
461
  - 预算与超支提示**仅提醒,不阻止调用**。
458
- - **Plan/API 双轨计费**(issue #64):订阅制渠道(MiniMax / Codex 手动标记等)的调用金额只记「等值」,预算/今日费用/概览卡片等金额展示仅统计按量计费(API)部分;
462
+ - **Plan/API 双轨计费**(issue #64):订阅制渠道(MiniMax / Codex、ChatGPT 订阅插件等)的调用金额只记「等值」,预算/今日费用/概览卡片等金额展示仅统计按量计费(API)部分;
459
463
  - **「含 Plan 总额」开关**:概览页汇总卡片下的快捷开关切换全部金额展示口径——关闭时仅计真金白银(API 渠道),开启后显示含 Plan 等值的总金额;网关路由(provider 缺失)调用的第三方目录模型自动归入对应订阅归类,无模型明细的历史残差计入 API 口径;设置 → 用量 的 Token Plan 统计面板提供每 1% 额度与满窗的 token/等值金额估算与日/周/月曲线;分类可在配置中按厂商或 provider:model 级覆盖。
460
464
  - **全仓安全审计修复**:账本退出丢写(close/flush 次序)、发版脚本命令注入、面板空指针崩溃(Go 月窗空值)3 项高危,及路由调用小时桶漏记、官方余额对账告警失效、自定义余额提取失败误显 $0、计费流中断泄漏等 30 余项中低危问题全量修复;账本损坏自动备份、写失败重试、配置补丁原子性、原型链与凭据处理加固。逐项清单见 [CHANGELOG.md](CHANGELOG.md)。
461
465
 
@@ -0,0 +1,74 @@
1
+ # better-session / SQLite 会话存储兼容
2
+
3
+ DSH 可安装 [`@morlay/better-session`](https://www.npmjs.com/package/@morlay/better-session)
4
+ 把会话持久化到 SQLite(`@morlay/session-rdb`),此时会话记录不再写入
5
+ `$DSH_HOME/sessions` 下的 JSONL 文件。本插件通过统一的会话记录源读取会话:
6
+ JSONL 后端仍读文件,SQLite 后端经宿主 `sessionPersistence` 服务读数据库。
7
+
8
+ ## 已适配的行为
9
+
10
+ - **回填 / 导入安装前历史**:`backfillLegacyLedger` / `importLegacyHistory` /
11
+ `repairPlanHourBuckets` / `recomputeLedgerPricingBasis` / `repairForkSeed`
12
+ 都通过同一记录源枚举会话;SQLite 下自动切到数据库读取。
13
+ - **一次性迁移标记**:`fork-seed-dedup-v1`、`currency-basis-recompute-v1`、
14
+ `holiday-offpeak-recompute-v1`、`plan-hours-attribution-v1`、
15
+ `legacyAutoImportedAt` 与默认价格迁移,在 SQLite 空扫描时**不消费**,下次
16
+ 启动会重试;JSONL 后端语义不变(空扫描照旧视为已完成)。
17
+ - **启动日志**:启动时会打印一行当前后端,例如
18
+ `[dsh-cost-meter] 会话存储后端: session-rdb (SQLite);回填/导入/重定价已切数据库读取;JSONL 修复工具不适用`。
19
+ - **手动导入的提示**:SQLite 下扫描 0 条时,导入结果会明确说明「当前宿主使用
20
+ SQLite 会话存储」,避免与「确实没有安装前历史」混淆。
21
+ - **`dsh-cost-meter-repair-sessions` 修复工具**:检测到 SQLite 后端时提示不适用
22
+ 并以退出码 `2` 结束,不执行任何写入(该工具只修复 JSONL 日志)。
23
+
24
+ ## 已知限制
25
+
26
+ - **跨后端历史并集未实现**:JSONL 模式下记录源只枚举现有的 JSONL 日志文件,
27
+ 不会再去数据库里合并历史。若你曾在 JSONL 后端产生会话、之后又切到
28
+ better-session/SQLite,旧 JSONL 文件里的历史不会自动出现在导入结果中——请
29
+ 保留原 `sessions/` 目录并用 JSONL 修复工具/旧版插件完成一次导入,或先用
30
+ better-session 自带工具把旧会话迁移进 SQLite。
31
+ - **降级暴露仅为第一阶段**:目前只提供启动日志、导入文案与修复 CLI 退出码,
32
+ 暂不在设置页/状态 schema 中展示后端信息。
33
+ - `repair-sessions-cli` 只适用于 JSONL 会话日志;SQLite 不需要修复工具。
34
+
35
+ ---
36
+
37
+ # better-session / SQLite session storage compatibility
38
+
39
+ DSH may install [`@morlay/better-session`](https://www.npmjs.com/package/@morlay/better-session)
40
+ to persist sessions in SQLite (`@morlay/session-rdb`); session records are then no
41
+ longer written as JSONL files under `$DSH_HOME/sessions`. dsh-cost-meter reads
42
+ sessions through a unified record source: JSONL files for the JSONL backend, and
43
+ the host `sessionPersistence` service for the SQLite backend.
44
+
45
+ ## What is adapted
46
+
47
+ - **Backfill / pre-install history import**: `backfillLegacyLedger`,
48
+ `importLegacyHistory`, `repairPlanHourBuckets`,
49
+ `recomputeLedgerPricingBasis` and `repairForkSeed` all enumerate sessions via
50
+ the same record source, so SQLite hosts read from the database.
51
+ - **One-shot migration markers**: `fork-seed-dedup-v1`,
52
+ `currency-basis-recompute-v1`, `holiday-offpeak-recompute-v1`,
53
+ `plan-hours-attribution-v1`, `legacyAutoImportedAt` and the default-price
54
+ migration are **not** consumed on an empty SQLite scan (they retry on the next
55
+ start); JSONL semantics are unchanged (an empty scan still counts as done).
56
+ - **Startup log**: one line reports the active backend, e.g.
57
+ `[dsh-cost-meter] 会话存储后端: session-rdb (SQLite);回填/导入/重定价已切数据库读取;JSONL 修复工具不适用`.
58
+ - **Manual import message**: on SQLite an empty scan says "This host uses SQLite
59
+ session storage", so it is not confused with "no pre-install history".
60
+ - **`dsh-cost-meter-repair-sessions`**: when SQLite is detected the tool says it
61
+ is not applicable and exits with code `2` without writing anything.
62
+
63
+ ## Known limitations
64
+
65
+ - **No cross-backend history union yet**: in JSONL mode the record source only
66
+ enumerates existing JSONL log files; it does not merge database history. If you
67
+ used the JSONL backend and later switched to better-session/SQLite, old JSONL
68
+ history is not included automatically. Keep the original `sessions/` directory
69
+ and import it once with the JSONL tool/older plugin, or migrate old sessions
70
+ into SQLite with better-session's own tooling first.
71
+ - **Phase 1 degradation visibility only**: startup log, import message and CLI
72
+ exit code; the backend is not exposed in the settings UI or state schema yet.
73
+ - `repair-sessions-cli` only applies to JSONL session logs; SQLite needs no
74
+ repair tool.
@@ -4,6 +4,8 @@
4
4
 
5
5
  This release addresses [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274), requested by @playgithub. It adds an OpenDesign price channel and read-only workspace quota queries; it is included in version 1.8.27. It does not install OpenDesign, create an account or change a model route.
6
6
 
7
+ The quota query also implements the Bearer-only fallback discovered by @yunjuanhuakai in the [#274 follow-up comments](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566): on accounts whose usage route rejects a Control Key, the plugin retries the `billing/preflight` endpoint with the same credential. @codeforker654's [401 report](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) is the reproduction behind the fallback.
8
+
7
9
  ### Conversation costs
8
10
 
9
11
  - The offline catalog contains 35 token-priced models checked on **2026-10-15**, from the [official public API](https://amr-api.open-design.ai/api/v1/public/model-prices). Prices are **USD per 1M tokens**, with cache read/write rates and long-context tiers where provided. The long tier applies to the entire request only above its input threshold, including cached input.
@@ -23,23 +25,37 @@ OpenDesign uses shared subscription allowances and can fall back to its wallet;
23
25
  The host issues only these authenticated GET requests to the fixed official HTTPS origin:
24
26
 
25
27
  ```text
26
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/coding-plan-usage
27
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance
28
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/coding-plan-usage # primary window query
29
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # Bearer-only fallback, only after a 401/403
30
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # wallet, read independently
28
31
  ```
29
32
 
30
- Quota and wallet responses must match the requested workspace. The wallet must identify its member; if the quota response provides a member identity, both must match. Credentials are never forwarded through a redirect. They use the existing DSH credential store and are excluded from the ledger and client snapshot.
33
+ #### Endpoint permissions, Bearer-only fallback and 401 troubleshooting
34
+
35
+ - The usage endpoint is not always scoped to a Control Key: for some plans/accounts it only accepts a **browser session cookie**, so a Control Key can return `401`/`403` for `billing/coding-plan-usage` while `/billing/preflight`, `/wallet/balance` and other API endpoints still answer `200` with the same key. The plugin never sends a browser cookie. It first queries the usage route with `Authorization: Bearer ...`; when that route answers `401`/`403`, it retries `billing/preflight` once with the same header. `preflight` returns the identical window packet nested under `codingPlan`, so the same parser and percentage rules apply.
36
+ - A `200`, a malformed body or any other HTTP status on the primary route never triggers the fallback. The wallet route is read independently and in parallel: when only one side is rejected, the other value is still displayed, the rejected side is omitted rather than fabricated as zero, and its cause (credential rejected / no subscription / invalid response / network) is kept in the refresh trace. Only when both sides fail does the card show an error state.
37
+ - A successful fallback keeps the standard `{ windows, endpoint }` answer, with `endpoint` naming the route that actually answered. A fallback response that is itself rejected, malformed or unreachable is reported as the window side's failure cause, not as a wallet failure.
38
+ - `preflight` also carries `workspaceMemberId` and `balanceUsd`. The member is checked against the wallet member; `balanceUsd` is only used as the displayed balance when `/wallet/balance` cannot be read, and never adds to or replaces a readable wallet value.
39
+ - The workspace ID must be the `workspaceId` field of `items[]` from `GET https://amr-api.open-design.ai/api/v1/workspaces`. It is **not** `profiles.prod.user.id` from `~/.amr/config.json`: that user id authenticates but scopes the request to the wrong resource, and the server replies `403 workspace_billing_scope_forbidden`.
40
+ - Troubleshooting a `401`/`403` on the quota endpoint:
41
+ 1. Confirm the stored credential is a **Control Key**, not an inference API key from the Cloud API Keys page.
42
+ 2. Call `GET /api/v1/workspaces` with the same credential and copy the exact `items[].workspaceId`.
43
+ 3. If `/workspaces` succeeds but `/billing/coding-plan-usage` returns `401`/`403`, the automatic `preflight` fallback normally covers this account and needs no browser session. If `preflight` also returns `401`/`403` for the same key, that account does not expose a Control-Key window read; log in to the OpenDesign Cloud console to check usage there. The wallet endpoint may still be readable, and is shown on its own.
44
+ 4. Verify the key and workspace belong to the same account and that the key was not rotated or revoked.
45
+
46
+ Quota and wallet responses must match the requested workspace. The wallet must identify its member; if the quota response provides a member identity, both must match. A preflight response that omits the redundant outer `workspaceId` is accepted only after the requested workspace has scoped the request; a body naming a different workspace is rejected. Credentials are never forwarded through a redirect and no cookie is attached. They use the existing DSH credential store and are excluded from the ledger and client snapshot.
31
47
 
32
- Each returned allowance window has its own used percentage and reset time. Simultaneous windows are not added together or called unlimited. Wallet credit remains a separate USD-equivalent value, including a real zero. Invalid, unauthorized or missing responses show an error/unavailable state, never a fabricated zero allowance. The workspace setting is kept across restarts and invalidates the previous query when changed.
48
+ Each returned allowance window has its own used percentage and reset time. Simultaneous windows are not added together or called unlimited. Wallet credit remains a separate USD-equivalent value, including a real zero. Quota and wallet are fetched independently, so a failure on one side keeps the other side visible; an `eligible: false` / empty-window answer (from the primary route or the fallback) is reported as **no active subscription** instead of a credential failure. Invalid, unauthorized or missing responses never fabricate a zero allowance; when both sides fail, the card shows an error/unavailable state. The workspace setting is kept across restarts and invalidates the previous query when changed.
33
49
 
34
50
  ### Evidence and limits
35
51
 
36
- The public catalog was fetched without authentication. The authenticated adapter and bilingual settings were verified with synthetic responses, including large credit counts, zero balances, mismatched identities, authorization failure and price-refresh persistence. **No live account query or paid model request was made.** Production Control Key permissions and response availability still require a configured account.
52
+ The public catalog was fetched without authentication. The authenticated adapter, the Bearer-only `billing/preflight` fallback and bilingual settings were verified with synthetic responses, including large credit counts, zero balances, mismatched identities, authorization failures on either side, a preflight-shaped `codingPlan` body, and price-refresh persistence. **No live account query or paid model request was made.** Production Control Key permissions and response availability still require a configured account.
37
53
 
38
- Endpoint provenance: the official Cloud bundles `cloud-root-B21Emo2w.js` and `pricing-refund-policy-BDFJHl33.js` served on 2026-10-15; the [workspace-wallet contract](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts) and [Vela billing adapter](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts) at the inspected commit. The [official guide](https://open-design.ai/zh/model-credits/) explicitly lists DSH as a supported API client; the issue has a usable integration request. Its short promotional wording alone does not establish advertising or spam.
54
+ Endpoint provenance: the official Cloud bundles `cloud-root-B21Emo2w.js` and `pricing-refund-policy-BDFJHl33.js` served on 2026-10-15; the [workspace-wallet contract](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts) and [Vela billing adapter](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts) at the inspected commit. The exact `billing/preflight` shape (`codingPlan`-nested windows, `workspaceMemberId`, `balanceUsd`) comes from @yunjuanhuakai's [#274 comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566); the 401 reproduction and attached report come from @codeforker654's [comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870). The [official guide](https://open-design.ai/zh/model-credits/) explicitly lists DSH as a supported API client; the issue has a usable integration request. Its short promotional wording alone does not establish advertising or spam.
39
55
 
40
56
  ## 中文
41
57
 
42
- 本版本实现了 @playgithub 在 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274) 提出的接入需求,随 1.8.27 发布。不会安装 OpenDesign、注册账户或改变模型路由。
58
+ 本版本实现了 @playgithub 在 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274) 提出的接入需求,随 1.8.27 发布。同时落实 #274 后续评论中 @yunjuanhuakai 发现的纯 Bearer 回退端点([评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566)),并以 @codeforker654 的 [401 复现报告](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) 为验证案例。不会安装 OpenDesign、注册账户或改变模型路由。
43
59
 
44
60
  ### 会话计费
45
61
 
@@ -57,10 +73,31 @@ OpenDesign 的 API 与客户端共用套餐,套餐用尽后可以继续扣钱
57
73
  3. 在凭据编辑器中配置 **Control Key**,或向 DSH 宿主提供 `OPENDESIGN_CONTROL_KEY` / `VELA_CONTROL_KEY`。Cloud API Keys 页生成的推理密钥与查询凭据不同,不能混用。已有 OpenDesign/Vela 登录将控制端凭据保存在其自身配置中,本插件不会自动读取或修改那个配置。
58
74
  4. 开启并刷新,可选择在侧栏或额度横条显示。
59
75
 
60
- 查询只访问上文列出的固定官方 HTTPS GET 端点;核对工作区,钱包必须提供成员身份,额度响应提供成员身份时再核对二者一致。凭据由 DSH 凭据库管理,不回显、不写入账本,不跟随重定向。
76
+ 查询只访问以下固定官方 HTTPS GET 端点,并在凭据/工作区校验之后才发起:
77
+
78
+ ```text
79
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/coding-plan-usage # 优先窗口端点
80
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # 纯 Bearer 回退,仅在 401/403 后尝试一次
81
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # 钱包端点,独立读取
82
+ ```
83
+
84
+ #### 端点权限、Bearer 回退与 401 排查
85
+
86
+ - 用量端点并非总是接受 Control Key:部分套餐/账户只接受**浏览器会话 Cookie**,因此同一个 Control Key 可能在 `billing/coding-plan-usage` 返回 `401`/`403`,而 `/billing/preflight`、`/wallet/balance` 等其它端点仍返回 `200`。插件从不发送浏览器 Cookie:先以 `Authorization: Bearer ...` 查询用量端点;若返回 `401`/`403`,再用同一请求头重试一次 `billing/preflight`。后者把同样的窗口数据嵌套在 `codingPlan` 下,解析与百分比规则完全一致。
87
+ - 主端点返回 `200`、响应格式错误或其它 HTTP 状态时都不会触发回退。钱包端点独立并行读取:只有一侧失败时仍显示另一侧数值,失败侧留空而不是编造为零,失败原因(凭据被拒/无订阅/响应无效/网络失败)保留在刷新记录中;两侧都失败才显示错误状态。
88
+ - 回退成功仍返回标准 `{ windows, endpoint }`,`endpoint` 指向实际返回数据的端点。回退端点本身被拒、格式错误或网络失败时,记为窗口侧失败原因,而不是钱包失败。
89
+ - `preflight` 同时返回 `workspaceMemberId` 与 `balanceUsd`。成员身份会与钱包成员核对;`balanceUsd` 只在 `/wallet/balance` 不可读时作为显示余额的兜底,不会与可读的钱包金额相加或覆盖它。
90
+ - 工作区 ID 必须取 `GET https://amr-api.open-design.ai/api/v1/workspaces` 返回的 `items[].workspaceId`;**不能**使用 `~/.amr/config.json` 里的 `profiles.prod.user.id`。后者虽然能通过认证,却会把请求指向错误的资源范围,服务端返回 `403 workspace_billing_scope_forbidden`。
91
+ - 额度端点返回 `401`/`403` 时的排查步骤:
92
+ 1. 确认保存的是 **Control Key**,不是 Cloud API Keys 页生成的推理密钥。
93
+ 2. 用同一凭据调用 `GET /api/v1/workspaces`,复制准确的 `items[].workspaceId`。
94
+ 3. 若 `/workspaces` 成功而 `/billing/coding-plan-usage` 返回 `401`/`403`,自动 `preflight` 回退通常已覆盖该账户,不需要浏览器会话。若同一凭据在 `preflight` 也返回 `401`/`403`,说明该账户没有开放 Control Key 的窗口读取;请登录 OpenDesign Cloud 控制台查看用量。钱包端点可能仍可读取,会单独显示。
95
+ 4. 核对密钥与工作区属于同一账户,并确认密钥未被轮换或撤销。
96
+
97
+ 查询只访问上文列出的固定官方 HTTPS GET 端点;核对工作区,钱包必须提供成员身份,额度响应提供成员身份时再核对二者一致。回退响应省略外层冗余 `workspaceId` 时,在已由请求范围校验工作区的前提下仍接受;若响应指向不同工作区则拒绝。凭据由 DSH 凭据库管理,不回显、不写入账本,不跟随重定向,也不附带浏览器 Cookie。
61
98
 
62
- 所有实际返回的窗口分别显示已用百分比和重置时间,不相加、不标成无限。钱包作为独立的美元等值额度显示,真实零余额保留。认证失败、缺失回执或身份不匹配显示不可用,不显示虚构的零额度。工作区配置跨重启保留,改变后清理原查询缓存。
99
+ 所有实际返回的窗口分别显示已用百分比和重置时间,不相加、不标成无限。钱包作为独立的美元等值额度显示,真实零余额保留。额度与钱包独立查询:一侧失败时另一侧仍照常显示;`eligible: false`/空窗口回执(无论来自主端点还是回退端点)会明确报告为**无生效订阅**,不再与凭据失效混为一谈。认证失败、缺失回执或身份不匹配不显示虚构的零额度,两侧都失败时才显示错误/不可用状态。工作区配置跨重启保留,改变后清理原查询缓存。
63
100
 
64
- 公开价表已经直接读取;认证查询与中英文设置使用模拟数据验证,覆盖大整数、零余额、串工作区/成员、认证失败、价格持久化等情况。**没有真实账户验证,没有调用付费模型。**真实账户的 Control Key 权限与服务端响应需要在配置后核对。
101
+ 公开价表已经直接读取;认证查询、Bearer-only `preflight` 回退与中英文设置使用模拟数据验证,覆盖大整数、零余额、串工作区/成员、单侧认证失败、preflight 形状的 `codingPlan` 回执、价格持久化等情况。**没有真实账户验证,没有调用付费模型。**真实账户的 Control Key 权限与服务端响应需要在配置后核对。
65
102
 
66
- 官方明确支持 DSH,说明这条 issue 有可执行的接入需求;仅凭“便宜、可能流行”的一句话,不能认定为广告。
103
+ 端点来源:官方 Cloud bundle `cloud-root-B21Emo2w.js` 与 `pricing-refund-policy-BDFJHl33.js`(2026-10-15 读取);[工作区钱包契约](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts)与 [Vela 计费适配器](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts)(上述 commit)。`billing/preflight` 的准确回执形状(`codingPlan` 内嵌窗口、`workspaceMemberId`、`balanceUsd`)来自 @yunjuanhuakai 的 [#274 评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566);401 复现与附件来自 @codeforker654 的 [评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870)。官方明确支持 DSH,说明这条 issue 有可执行的接入需求;仅凭“便宜、可能流行”的一句话,不能认定为广告。
@@ -35,7 +35,7 @@
35
35
  ```yaml
36
36
  minimumReleaseAgeExclude:
37
37
  # 保留宿主已经写入的其他条目
38
- - dsh-cost-meter@1.8.36
38
+ - dsh-cost-meter@1.9.0
39
39
  ```
40
40
 
41
41
  只影响列出的 `名称@版本`;不要删除文件里已有的其他排除项。修改后完全退出并重新打开 DSH,再在插件页重试。
@@ -49,7 +49,7 @@ minimumReleaseAgeExclude:
49
49
  dsh plugin --profile desktop remove dsh-cost-meter --config.minimum-release-age=0
50
50
 
51
51
  # 安装 / 升级
52
- dsh plugin --profile desktop add dsh-cost-meter@1.8.36 --config.minimum-release-age=0
52
+ dsh plugin --profile desktop add dsh-cost-meter@1.9.0 --config.minimum-release-age=0
53
53
  ```
54
54
 
55
55
  如果是 lockfile 校验阶段失败(`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`),也可以加 `--trust-lockfile` 跳过校验并重试。以上两个参数已在本机 pnpm 11.28.5 的临时 Profile 上实测可用。
@@ -83,6 +83,6 @@ This page explains the pnpm `minimumReleaseAge` (supply-chain) policy shipped in
83
83
 
84
84
  - **Scope** — DSH 0.2.1-rc.1 / 0.2.1-rc.2 bundle pnpm **11.28.5**, which enables a built-in **24-hour** `minimumReleaseAge`. Packages published less than 24 hours ago can produce a resolution-policy violation.
85
85
  - **Symptoms** — the plugin page reports uninstall/install failure with lines such as `✓ Lockfile passes supply-chain policies (verified 28m ago)`, then `ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION` (lockfile verification) or `ERR_PNPM_RESOLUTION_POLICY_VIOLATIONS_UNHANDLED` (dependency resolution during `pnpm remove`). The unhandled-callback case is a defect of the host's bundled pnpm; the plugin cannot patch it.
86
- - **Workarounds** — (1) wait until the package/version is 24 hours old, then retry; (2) add an exact `minimumReleaseAgeExclude` entry (`- dsh-cost-meter@1.8.36`) to the profile's `pnpm-workspace.yaml` (`%USERPROFILE%\.dsh\profiles\<profile>\pnpm-workspace.yaml` on Windows, `~/.dsh/profiles/<profile>/pnpm-workspace.yaml` elsewhere), keep existing entries, restart DSH and retry; (3) forward pnpm flags for one operation via the CLI, for example `dsh plugin --profile desktop remove dsh-cost-meter --config.minimum-release-age=0` (or `--trust-lockfile` when only lockfile verification fails). Both flags were verified against pnpm 11.28.5 in a temporary profile.
86
+ - **Workarounds** — (1) wait until the package/version is 24 hours old, then retry; (2) add an exact `minimumReleaseAgeExclude` entry (`- dsh-cost-meter@1.9.0`) to the profile's `pnpm-workspace.yaml` (`%USERPROFILE%\.dsh\profiles\<profile>\pnpm-workspace.yaml` on Windows, `~/.dsh/profiles/<profile>/pnpm-workspace.yaml` elsewhere), keep existing entries, restart DSH and retry; (3) forward pnpm flags for one operation via the CLI, for example `dsh plugin --profile desktop remove dsh-cost-meter --config.minimum-release-age=0` (or `--trust-lockfile` when only lockfile verification fails). Both flags were verified against pnpm 11.28.5 in a temporary profile.
87
87
  - **Diagnostics** — read the first `ERR_PNPM_*` line in `<profile>/.plugin-manager/logs/operation-*/pnpm.log`; remove credentials before sharing. Do not delete the profile or the ledger.
88
88
  - **Upstream** — DSH's repository restricts external pull requests, so this cannot be patched from the plugin side; the workarounds above are the supported mitigation until a DSH release updates the bundled pnpm. See also issue [#250](https://github.com/Han-1413141/dsh-cost-meter/issues/250).
@@ -0,0 +1,83 @@
1
+ # v1.9.0
2
+
3
+ ## 中文
4
+
5
+ 本版新增三类外部插件/存储的兼容:Codex 订阅插件、ChatGPT 订阅插件与 better-session 的 SQLite 会话存储;为全部费用界面适配 dsh-pocket 手机端;并按 #274 的社区反馈为 OpenDesign 增加 Control Key 直连的 preflight 回退与窗口/钱包独立降级。账本格式不变;除用户主动确认的「历史 Codex 归类」外,不自动重算历史金额。
6
+
7
+ ### Codex 订阅插件兼容(dsh-codex-subscription)
8
+
9
+ - 安装 dsh-codex-subscription 后,插件启动时从 Profile 的 `node_modules` 检测它,并自动把该插件产生的 Codex 订阅调用归类为 Plan 订阅额度,不再计入 API 按量花费;新产生的用量在记账时直接按 Plan 处理。
10
+ - 升级后首次检测到该插件时,弹出一次「兼容修复」提示:是否把升级前已记录的历史 Codex 类模型计费统一归类为 Plan。选择「统一归类为 Plan」后立即重算本地账本中的历史 Codex 用量(`apiCost` 归零、Plan 等值保留),可重复执行且幂等;选择「保持现状」或关闭提示不会改动历史金额,并永久记住该选择。
11
+ - 提示可随时从「设置 → 费用 → Codex」重新操作:设置页新增「Codex 订阅兼容」面板,展示检测到的版本、当前计费方式、历史 Codex 用量(调用数 / 金额 / 天数 / 来源 Provider)与归类状态,并提供「统一归类为 Plan」按钮;未安装该插件时不显示该区块。
12
+ - 判定沿用 Plan/API 双轨与 `provider:model` 覆盖机制;用户已显式选择 plan/api 的厂商不会被覆盖。
13
+
14
+ ### ChatGPT 订阅插件兼容(@eddyskywalker/dsh-chatgpt-subscription)
15
+
16
+ - 检测该插件的 9 条订阅线路并映射到对应 Plan 家族:`codex-chatgpt` → Codex、`kimi-code` → Kimi、`command-code` → CommandCode、`claude-subscription` → Anthropic、`minimax-code` → MiniMax、`glm-coding-plan` → Z.AI、`workbuddy-subscription` → WorkBuddy(新增)、`antigravity` → Antigravity(新增)、`step-code` → StepFun(新增)。
17
+ - 启动时对计费分类仍为「自动」的上述厂商自动归为 Plan,不覆盖用户显式选择的 plan/API,使其订阅调用不再计入 API 花费。
18
+ - 该插件自身的登录、额度卡片与 Provider 功能不受影响;本插件只读取本地账本记账口径,不发起任何订阅插件的网络请求。
19
+
20
+ ### better-session SQLite 会话存储兼容
21
+
22
+ - 新增会话存储适配层:自动探测宿主后端(`session-rdb` / `sessionPersistence` / `sessionQuery` 或 `@morlay/better-session`、`@morlay/session-rdb` 安装),当 better-session 接管会话存储、不再产生 JSONL 日志时,历史回填、旧账本导入、按模型历史重定价、小时桶修复、fork 种子清洗,以及逐会话费用、轨迹、调用详情、标题与统计缓存仍可正常工作。
23
+ - JSONL 存储路径逐字节保持原有行为;RDB 模式走宿主的会话持久化/查询接口,不直接读 SQLite 文件,也不自动合并旧 JSONL 与 RDB 历史(旧日志可用「导入旧版历史」补录,[说明](better-session.md))。
24
+ - 修正 5 个一次性迁移标记在 RDB 空扫描时被误消费的问题,避免误以为旧会话已处理;首次全量回放增加单会话顺序与事件上限保护。
25
+ - 启动日志会打印当前会话存储后端(`session-rdb` / `jsonl` / `unknown`);会话修复 CLI 检测到 RDB 时明确提示不支持并返回退出码 2,不假装修复成功。
26
+
27
+ ### dsh-pocket 手机端适配
28
+
29
+ - 主设置面板、侧栏卡片、额度横条、预算框、统计页、显示设置、定价页、OpenRouter 与社区面板、Codex 兼容面板均适配窄屏(≤1023px)与 dsh-pocket 强制移动布局:卡片单列、标签横向滚动、按钮/标签 36px 触控高度、对话框不超过 90vh 并避开安全区、宽表横向滚动。
30
+ - 桌面布局不变;新增样式全部包在 `@media (max-width: 1023px)` 或 `body[data-dsh-pocket-layout="mobile"]` 下。
31
+
32
+ ### OpenDesign 额度查询:Control Key preflight 回退与独立降级(#274)
33
+
34
+ - 按 [@yunjuanhuakai 的实测](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566):同一把 Control Key 用 Bearer 调用 `/billing/coding-plan-usage` 会 401,但可正常读取 `/billing/preflight`(返回 `codingPlan.windows` 与 `balanceUsd`)。本版在主端点返回 401/403 时保守回退一次 preflight;主端点非 401/403 不触发回退,避免掩盖真实故障。
35
+ - 解析器支持解包 preflight 的 `codingPlan` 结构;preflight 的 `balanceUsd` 仅在钱包接口不可读时兜底显示,不覆盖可读钱包。
36
+ - 窗口与钱包读取完全独立并行:一方失败只降级该部分(窗口失败 → 仅显示钱包余额并标记 partial;钱包失败 → 保留窗口),只有两者都失败才报错;错误区分鉴权失败、无生效订阅、响应无效与网络失败,不再混同。
37
+ - 文档补充端点权限、Control Key 只能用于部分端点、`workspaceId` 必须取 `GET /api/v1/workspaces` 的 `items[].workspaceId`(误用用户 id 会 403 `workspace_billing_scope_forbidden`)以及 401 排查步骤,见 [OpenDesign 计费与排查](opendesign-billing.md)。
38
+ - 感谢 [@playgithub](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6215322540) 提出 OpenDesign 支持需求并复现入口问题、[@codeforker654](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) 复现并提交 401 报告、[@yunjuanhuakai](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566) 发现 `/billing/preflight` 可接受 Control Key 并提供回执样例。
39
+
40
+ ### 升级方式
41
+
42
+ 重跑新版 `install.ps1` 或从插件市场更新(npm 用户执行 `dsh plugin --profile web add dsh-cost-meter@latest`),升级后完全退出并重新打开 DSH。账本格式不变;除主动确认的历史 Codex 归类外不自动重算历史金额。
43
+
44
+ ## English
45
+
46
+ This release adds compatibility for three external integrations: the Codex subscription plugin, the ChatGPT subscription plugin, and better-session's SQLite session storage. Every cost UI now adapts to dsh-pocket mobile layouts. Following the #274 community feedback, OpenDesign gains a Control-Key-only `/billing/preflight` fallback plus independent window/wallet degradation. The ledger format is unchanged; historical amounts are never recalculated automatically except for the explicitly confirmed "historical Codex reclassification".
47
+
48
+ ### Codex subscription plugin compatibility (dsh-codex-subscription)
49
+
50
+ - When dsh-codex-subscription is installed, the plugin is detected from the Profile's `node_modules` at startup. Codex subscription calls it makes are classified as Plan subscription quota instead of pay-as-you-go API spend, and new usage is recorded as Plan immediately.
51
+ - On the first detection after upgrading, a one-time "Compatibility fix" prompt asks whether to reclassify historical Codex models recorded before the upgrade as Plan. Choosing "Reclassify as Plan" recomputes the local ledger immediately (`apiCost` zeroed, Plan equivalents kept); it is idempotent. Choosing "Keep as is" or closing the prompt leaves historical amounts untouched and remembers the decision permanently.
52
+ - The action is always reachable in Settings → Cost → Codex: the new "Codex subscription compatibility" panel shows the detected version, current billing class, historical Codex usage (calls / cost / days / source providers) and the reclassification state, with a "Reclassify as Plan" button. The section is hidden when the plugin is not installed.
53
+ - Classification follows the existing Plan/API dual-track and `provider:model` overrides; vendors explicitly set to plan/api are never overwritten.
54
+
55
+ ### ChatGPT subscription plugin compatibility (@eddyskywalker/dsh-chatgpt-subscription)
56
+
57
+ - Detects the plugin's nine subscription routes and maps them to Plan families: `codex-chatgpt` → Codex, `kimi-code` → Kimi, `command-code` → CommandCode, `claude-subscription` → Anthropic, `minimax-code` → MiniMax, `glm-coding-plan` → Z.AI, `workbuddy-subscription` → WorkBuddy (new), `antigravity` → Antigravity (new), `step-code` → StepFun (new).
58
+ - At startup, vendors still set to "auto" are classified as Plan without overriding explicit plan/API choices, so subscription calls no longer count as API spend.
59
+ - The plugin's own login, quota cards and providers are untouched; this plugin reads only the local ledger billing class and makes no network requests on behalf of subscription plugins.
60
+
61
+ ### better-session SQLite session storage compatibility
62
+
63
+ - New session-storage adapter: the host backend is detected automatically (`session-rdb` / `sessionPersistence` / `sessionQuery`, or installed `@morlay/better-session` / `@morlay/session-rdb`). When better-session takes over storage and no JSONL logs are produced, historical backfill, legacy-ledger import, per-model history repricing, hour-bucket repair, fork-seed cleanup, per-session cost, trajectory, call inspection, titles and statistics caches keep working.
64
+ - The JSONL path remains byte-for-byte unchanged; RDB mode goes through the host's session persistence/query APIs instead of reading SQLite files directly, and does not merge old JSONL with RDB history automatically (use "Import legacy history" for old logs; see [guide](better-session.md)).
65
+ - Five one-time migration markers are no longer consumed by an empty RDB scan (previously they could mark old sessions as processed). The first full replay now runs one session at a time with an event cap.
66
+ - Startup logs the current session storage backend (`session-rdb` / `jsonl` / `unknown`); the session repair CLI detects RDB, explains that it is unsupported and exits with code 2 instead of pretending to repair.
67
+
68
+ ### dsh-pocket mobile layout
69
+
70
+ - The main settings panel, sidebar cards, quota strip, budget box, statistics, display settings, pricing, OpenRouter and community panels, and the Codex compatibility panel now adapt to narrow screens (≤1023px) and dsh-pocket's forced mobile layout: single-column cards, horizontally scrolling tabs, 36px touch targets, dialogs capped at 90vh with safe-area padding, and horizontally scrolling wide tables.
71
+ - Desktop layout is unchanged; all new styles live under `@media (max-width: 1023px)` or `body[data-dsh-pocket-layout="mobile"]`.
72
+
73
+ ### OpenDesign quota: Control-Key preflight fallback and independent degradation (#274)
74
+
75
+ - Based on [the measurements shared by @yunjuanhuakai](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566): the same Control Key returns 401 from `/billing/coding-plan-usage` as a Bearer token, but `/billing/preflight` works and returns `codingPlan.windows` plus `balanceUsd`. This release falls back once to preflight only when the primary endpoint returns 401/403; other failures never trigger the fallback, so real outages are not masked.
76
+ - The parser unwraps preflight's `codingPlan` structure; preflight `balanceUsd` is used as a fallback display only when the wallet endpoint is unreadable, never overriding a readable wallet.
77
+ - Window and wallet reads are fully independent and parallel: a single failure degrades only that part (window failure → wallet balance only, marked partial; wallet failure → windows kept), and only two failures raise. Errors distinguish authentication failure, no active subscription, invalid responses and network failures.
78
+ - Docs now cover endpoint permissions, which endpoints accept a Control Key, why `workspaceId` must come from `items[].workspaceId` of `GET /api/v1/workspaces` (a user id yields 403 `workspace_billing_scope_forbidden`) and a 401 troubleshooting checklist: [OpenDesign billing and troubleshooting](opendesign-billing.md).
79
+ - Thanks to [@playgithub](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6215322540) for requesting OpenDesign support and reproducing the entry problem, [@codeforker654](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) for reproducing and reporting the 401, and [@yunjuanhuakai](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566) for discovering that `/billing/preflight` accepts the Control Key and providing sample responses.
80
+
81
+ ### Upgrade
82
+
83
+ Re-run the new `install.ps1` or update from the plugin marketplace (`dsh plugin --profile web add dsh-cost-meter@latest` for npm), then fully quit and reopen DSH. The ledger format is unchanged; historical amounts are not recalculated automatically except for the confirmed historical Codex reclassification.