dsh-usage-peak 1.4.1 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.0
4
+
5
+ - 图表新增自定义详情浮层:悬停或聚焦小时图 / 每日趋势,显示该时段的花费、请求、tokens、缓存命中率与峰谷;浮层按列居中并 clamp 在图表内,窄侧栏也不溢出,原生 title 双提示已移除。
6
+ - 图表支持键盘浏览:Tab 聚焦后 `←` `→` 循环、`Home` / `End` 跳首尾、`Esc` 关闭;浮层内容通过 `aria-live` 播报,聚焦时有可见描边。
7
+ - 小时数据补充 tokens 与命中率:host 的小时桶新增 input/cache/output tokens,`hoursOf` 输出 `tokens` 与 `hitRate`,用于浮层明细。
8
+ - 窄侧栏适配:图表从固定两列改为 flex 换行,24 根柱子收窄到 minWidth 3;每日趋势按可用宽度进入 dense 模式(隐藏柱顶金额、日期标签稀疏);KPI 网格改为 `minmax(min(100%, 140px), 1fr)`。
9
+ - 自定义价目表改为每个模型一组、字段自动换行(缓存命中 / 输入 / 输出各自谷峰两输入),窄宽度下不再横向溢出;价目表与模型表加横向滚动容器,价目表当前时段用加粗和底色标记。
10
+ - 侧栏胶囊的 tokens 段改为可收缩省略,窄侧栏下优先保住倒计时。
11
+ - 新增 `tipAnchor` 与小时 tokens/命中率测试,测试从 43 条增至 45 条。
12
+
13
+ ## 1.5.0
14
+
15
+ - 峰谷改为按请求开始时刻判断:取每条 `assistant/message` 第一个流式 chunk 的时间,而不是回复完成时间,跨切价点的回复不再整条算到错误的时段。
16
+ - 新增自定义价目表:面板里可编辑 Flash / Pro 的缓存命中、输入、输出单价(谷 / 峰),保存后所有金额与 CSV 立即重算;只存当前浏览器,可一键恢复默认。
17
+ - `/data` 与 `/export.csv` 新增 `pricing` 参数;服务端校验长度、模型集合与价格范围,非法值回退默认价目并返回 `pricing-invalid` 警告。快照缓存按价目隔离。
18
+ - 「谷时更省」改为逐条累计峰时花费与同样用量按谷价计算的差额,自定义价目下仍然准确;默认价目下仍等于峰时花费的一半。
19
+ - 新增请求开始时间、价目规范化/编码/解析、自定义价目聚合、快照缓存隔离与 HTTP 参数测试(从 34 条增至 43 条)。
20
+
3
21
  ## 1.4.1
4
22
 
5
23
  - 修复侧栏余额/预算预警激活后,峰谷倒计时被警告文案替换、看不到「还有多久转峰/转谷」的问题:现在倒计时始终保留,前面加 `⚠` 并在 tooltip 中补充预警原因。
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 用量峰谷仪表盘(DSH Usage Dashboard)
2
2
 
3
- 给 DeepSeek Harness 用的用量/花费仪表盘:一眼看清现在是不是**峰时**、今天花了多少钱、烧了多少 tokens、钱花在哪个项目,以及余额还能撑几天。
3
+ 给 DeepSeek Harness 用的用量/花费仪表盘:一眼看清现在是不是**峰时**、今天花了多少钱、烧了多少 tokens、钱花在哪个项目,以及余额还能撑几天。支持按请求开始时刻判断峰谷,并可在面板里改价目表。
4
4
 
5
5
  全部在本地读取 DSH 自己的会话日志,不联网、不上报。
6
6
 
@@ -15,7 +15,8 @@
15
15
  - **侧栏常驻胶囊**:`● 峰 ¥14.70 · 12.8M tok · 2:43 后转谷`,点一下打开完整面板。侧栏折叠时收成一个小圆点。默认可撑天数不足 7 天时胶囊转琥珀色,不足 3 天转红色;可在面板调整阈值。
16
16
  - **峰谷状态**:当前时段、距离下次切换的倒计时、当前时段单价(缓存命中 / 全价输入 / 输出)。
17
17
  - **今日概况**:花费、请求数、tokens、缓存命中率、峰时花费占比、**谷时更省**(把这些峰时用量挪到谷时能省下的钱)、余额、**余额可撑天数**(余额 ÷ 近 7 天日均花费)。
18
- - **今日 24 小时分布**:每小时花费柱状,峰时与谷时用不同颜色,当前小时高亮。
18
+ - **今日 24 小时分布**:每小时花费柱状,峰时与谷时用不同颜色,当前小时高亮;悬停或聚焦柱子可看该小时的花费、请求、tokens 与缓存命中率,键盘 `←` `→` / `Home` / `End` 浏览、`Esc` 关闭。
19
+ - **窄侧栏自适应**:侧栏变窄或窗口变小时,图表自动换行、24 根柱子收窄、每日趋势的日期标签按宽度变稀疏;价目表按模型分组、单价输入自动换行,过宽的表格可横向滚动,胶囊的 tokens 段优先省略而不挤掉倒计时。
19
20
  - **花费构成**:缓存命中 / 全价输入 / 输出 三段占比,直接看出钱花在哪。
20
21
  - **近 7 / 14 / 30 天趋势**:右上角切换窗口,按天堆叠柱状,缺数据的日期补零,列数恒定;可对照峰时占比判断"贵在哪天"。
21
22
  - **按项目与下钻**:按会话头里的工作目录(`cwd`)聚合,倒序列出每个项目的请求数、tokens、花费与占比条。点击项目可只看该项目的概况、24 小时、趋势和模型明细,通过顶部「全部项目」恢复。
@@ -23,7 +24,8 @@
23
24
  - **全局钱包口径**:余额、余额可撑天数和每日预算始终按所有项目计算,不会因为筛选一个低花费项目而误判余额充足。
24
25
  - **按模型**:Flash / Pro 各自的请求数、tokens、花费。
25
26
  - **导出 CSV**:每日数据与项目数据都能导出(UTF-8 BOM,Excel 直接打开不乱码;单元格做了公式注入防护)。
26
- - **价目表**:当前时段那一行高亮,方便解释账单。
27
+ - **价目表**:当前时段那一行高亮,方便解释账单;下方可编辑 Flash / Pro 的缓存命中、输入、输出单价(谷 / 峰),保存后所有金额与 CSV 立即按新价目重算,只存在当前浏览器,可一键恢复默认。
28
+ - **按请求开始时刻计价**:会话日志里一条回复可能跨过切价点,峰谷按第一个流式 chunk 的时间判断,而不是回复完成时间。
27
29
  - **节假日与调休**:按国务院办公厅公布的安排判断——法定节假日全天谷时,调休上班的周末按工作日峰谷计算;当前覆盖 2026–2027 年,缺失年份会在面板给出提示并回落到周一至周五规则。
28
30
  - **页脚**:GitHub 仓库链接(可顺手点个 Star)、当前版本号与日历覆盖年份。
29
31
 
@@ -31,29 +33,31 @@
31
33
 
32
34
  ## 价格模型
33
35
 
34
- 单位:元 / 百万 tokens,`[谷时, 峰时]`。
36
+ 单位为元 / 百万 tokens,`[谷时, 峰时]`。下表是默认价目;面板里的「自定义价目表」可以改成实际合同价,保存在当前浏览器。
35
37
 
36
38
  | 模型 | 缓存命中 | 全价输入 | 输出 |
37
39
  | --- | --- | --- | --- |
38
40
  | DeepSeek Flash | 0.02 / 0.04 | 1 / 2 | 4 / 8 |
39
41
  | DeepSeek Pro | 0.15 / 0.30 | 4.5 / 9 | 13.5 / 27 |
40
42
 
41
- 峰时 = 工作日 09:00–12:00、14:00–18:00(北京时间);其余时间、周末与法定节假日为谷时,单价减半。调休上班日(包括周末)按工作日的峰谷窗口计算。
43
+ 峰时 = 工作日 09:00–12:00、14:00–18:00(北京时间);其余时间、周末与法定节假日为谷时。默认价目峰时单价是谷时的 2 倍;调休上班日(包括周末)按工作日的峰谷窗口计算。
42
44
 
43
45
  节假日数据在 [`holidays.js`](holidays.js),来源为国务院办公厅 [2026 年](https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm)、[2027 年](https://www.gov.cn/zhengce/zhengceku/202611/content_7085102.htm) 放假安排通知,并与 [holiday-cn](https://github.com/NateScarlet/holiday-cn) 交叉核对。新一年安排公布后,补一组日期并把年份加进 `CALENDAR_YEARS` 即可。
44
46
 
45
47
  ## 数据来源
46
48
 
47
- - `~/.dsh/sessions/<项目 slug>/<会话 id>/session.v4.jsonl.zstd`:每条 `assistant/message` 的 `usage`(输入、缓存读取、输出)与模型,按请求发生的时刻判断峰谷;项目归属取会话头里的绝对 `cwd`,没有会话头时才回落到目录 slug。
49
+ - `~/.dsh/sessions/<项目 slug>/<会话 id>/session.v4.jsonl.zstd`:每条 `assistant/message` 的 `usage`(输入、缓存读取、输出)与模型,按该条回复第一个流式 chunk 的时间(请求开始)判断峰谷;项目归属取会话头里的绝对 `cwd`,没有会话头时才回落到目录 slug。
48
50
  - `~/.dsh/.dshw-usage.json`:鲸鱼记账本的余额与当日花费,用作交叉校验。
49
51
 
50
52
  日志是**多帧 zstd**,Node 自带的 `zlib.zstdDecompressSync` 只解第一帧,所以插件内部按 zstd magic 切帧、逐帧解压再拼接(不需要 `zstd` 命令行)。
51
53
 
52
54
  - 数据接口支持 `?days=7|14|30` 选择统计窗口(默认 14,白名单之外的取值回落到 14);快照按窗口与项目分别缓存 15 秒,面板上的「刷新」按钮会带 `?fresh=1` 强制重算。
53
55
  - `/data` 和 `/export.csv` 均接受可选 `project` 参数(项目的精确 key,真实会话通常是绝对 `cwd`;必须 URL 编码)。不传或空字符串表示全部项目,未知 key 返回空项目数据而不是退回全量。项目列表来自全局窗口,方便切换。
54
- - 导出接口为 `/plugin/dsh-usage-peak/export.csv?days=7|14|30&scope=days|projects&project=...`,带 `Content-Disposition: attachment` 与 UTF-8 BOM。页面的每日和项目 CSV 都跟随当前筛选。
56
+ - `/data` 与 `/export.csv` 还接受可选 `pricing` 参数(`flash:hitV,hitP,missV,missP,outV,outP|pro:...`,由面板自动附带);非法参数回退默认价目并在 `warnings` 里给出 `pricing-invalid`。
55
57
 
56
- 峰时单价恰为谷时 2 倍,所以「谷时更省」= 峰时花费 ÷ 2:它衡量的是这些峰时用量如果改在谷时发生能省多少,而不是已经省下的钱。
58
+ 导出接口为 `/plugin/dsh-usage-peak/export.csv?days=7|14|30&scope=days|projects&project=...`,带 `Content-Disposition: attachment` 与 UTF-8 BOM。页面的每日和项目 CSV 都跟随当前筛选与价目。
59
+
60
+ 默认价目峰时单价恰为谷时 2 倍,所以「谷时更省」等于峰时花费的一半;自定义价目下按「峰时花费 − 同样用量按谷价计算的金额」逐项重算。它衡量的是这些峰时用量如果改在谷时发生能省多少,而不是已经省下的钱。
57
61
 
58
62
  ## 安装
59
63
 
@@ -77,7 +81,7 @@ dsh plugin add dsh-usage-peak
77
81
  ## 已知限制
78
82
 
79
83
  - 依赖 DSH 会话日志的**内部格式**(`session.v4.jsonl.zstd` 与 `assistant/message.data.usage`)。DSH 改格式时需要跟进;读不到数据时面板会显示为空态而不是报错。
80
- - 每日预算基于本机会话日志估算的北京时间「今日」总花费,不代表平台实时账单;预警配置只存当前浏览器,不跨设备同步。宿主功能升级后需重启 DSH,客户端重新加载后使用新界面。
84
+ - 每日预算基于本机会话日志估算的北京时间「今日」总花费,不代表平台实时账单;预警配置与自定义价目只存当前浏览器,不跨设备同步。宿主功能升级后需重启 DSH,客户端重新加载后使用新界面。
81
85
  - 只统计本机会话日志覆盖到的历史,鲸鱼记账本从 2026-11-02 才开始记账。
82
86
  - 项目归属依赖会话头中的 `cwd`;极少数没有会话头的旧日志会回落到 workspace slug,slug 会转义部分字节,显示名可能不如真实路径精确。
83
87
 
@@ -94,14 +98,19 @@ A usage and cost dashboard for DeepSeek Harness. It reads the local session logs
94
98
  ![Sidebar pill: valley ¥17.10 · 170.3M tok · switching to peak in 13:56](assets/sidebar-pill.webp)
95
99
 
96
100
  - a persistent sidebar pill with peak/valley state, today's spend, tokens and the countdown to the next price switch; the pill turns amber when the balance runway is under 7 days and red under 3 days;
101
+ - request-start billing: peak/valley is decided by the first stream chunk of a reply, not by its completion time;
102
+ - an editable Flash/Pro price list (cache hit, input, output, valley/peak). Saved prices apply to every figure and CSV immediately, live only in this browser, and can be reset to the defaults;
97
103
  - China public holidays and makeup workdays: holidays are valley all day, makeup weekend workdays follow the weekday windows (2026–2027 calendars shipped; missing years fall back to Mon-Fri with a visible warning);
98
104
  - a footer with the GitHub repository link, the running version and the covered calendar years;
99
105
  - a details page (Settings → Usage dashboard) with KPIs (including balance runway), an hourly breakdown, cost composition, a 7/14/30-day trend switch, spend by project, a per-model table, CSV export and the price list;
106
+ - hover or keyboard focus on the hourly/daily charts for that bucket's spend, requests, tokens and cache-hit rate (arrows/Home/End to browse, Esc to close), with a clamped tooltip that fits narrow panels;
107
+ - narrow sidebars and small windows: charts wrap, the 24 hourly bars compress, day labels thin out, the custom price form stacks its fields and wide tables scroll horizontally;
108
+ - a custom price parameter (`pricing=`) on `/data` and `/export.csv`; malformed values fall back to the defaults with a `pricing-invalid` warning;
100
109
  - project drilldown: select a project to filter KPIs, hourly/daily charts, models and both CSV exports; clear the filter to return to all projects;
101
110
  - configurable browser-local runway thresholds (warning 7 days / critical 3 days by default) and an optional daily budget (warning above 100%, critical at 120%); settings sync between the sidebar and dashboard;
102
111
  - balance runway and daily-budget alerts always use global spend, even while a project is selected;
103
- - a "valley saving" KPI: since peak costs exactly 2x valley, moving the same peak usage to valley time would have saved half of the peak spend.
112
+ - a "valley saving" KPI: with the default prices (peak = 2x valley) it is half of the peak spend; with custom prices it is recomputed per bucket as peak cost minus the same usage at valley prices.
104
113
 
105
- Pricing (`[valley, peak]`, CNY per million tokens): Flash cache-hit 0.02/0.04, miss 1/2, output 4/8; Pro cache-hit 0.15/0.30, miss 4.5/9, output 13.5/27. Peak hours are 09:00–12:00 and 14:00–18:00 Beijing time on weekdays; everything else is valley (half price).
114
+ Default pricing (`[valley, peak]`, CNY per million tokens): Flash cache-hit 0.02/0.04, miss 1/2, output 4/8; Pro cache-hit 0.15/0.30, miss 4.5/9, output 13.5/27. They can be edited in the panel; custom prices stay in this browser. Peak hours are 09:00–12:00 and 14:00–18:00 Beijing time on weekdays; everything else is valley.
106
115
 
107
116
  Everything stays local — no network calls, no telemetry. Multi-frame zstd logs are decoded frame by frame with Node's built-in `zlib`, so no `zstd` binary is required.