dsh-pulse-overview 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,23 +1,9 @@
1
- # dsh-pulse
1
+ # dsh-pulse-overview
2
2
 
3
- > **包名是 `dsh-pulse-overview`,不是 `dsh-pulse`。** npm 上的 `dsh-pulse` 已被他人占用
4
- > (`lightgrey/dsh-pulse`,功能重叠)。仓库名仍是 `dsh-pulse` —— 这个不一致是刻意的:
5
- > 仓库名描述「这是什么」,包名必须唯一。
6
- >
7
- > ```bash
8
- > dsh plugin --profile web add dsh-pulse-overview
9
- > ```
3
+ 给 [DeepSeek Harness](https://github.com/deepseek-ai) 的**新会话页面**加两块统计:
10
4
 
11
- 为 [DeepSeek Harness](https://github.com/deepseek-ai) 的**会话欢迎页**加两块东西:
12
-
13
- 1. **活动概览** —— 会话数 / 消息数 / 总 Token / 活跃天数 / 当前连续 / 最长连续 /
14
- 活跃时段 / 常用模型,八项指标一张 2 × 4 栅格,支持全部 / 365 / 30 / 7 天四个时间范围;
15
- 2. **活跃度热力图** —— 最近一年每天活跃度的方块网格,**会话数**与 **Token 用量**
16
- 两个指标共用同一张网格。
17
-
18
- 视觉与宿主统一:卡片与下方输入框共用同一套设计 token(底色 / 发丝描边 / 圆角 / 投影),
19
- 配色遵循宿主「无色相 chrome」的原则 —— 概览与网格的强调色是 DeepSeek 品牌蓝,
20
- 0 档是宿主的骨架屏灰。
5
+ 1. **活动概览** —— 一张 2 × 4 的指标卡,八项数据一眼看完;
6
+ 2. **活跃度热力图** —— 最近一年每天有多活跃,像 GitHub 的贡献格子。
21
7
 
22
8
  ![活动概览 + 热力图预览(浅色 / 深色,真实数据)](docs/overview-preview.png)
23
9
 
@@ -41,112 +27,49 @@
41
27
 
42
28
  ## 活动概览
43
29
 
44
- - **八项指标**:会话数 / 消息数 / 总 Token / 活跃天数 / 当前连续 / 最长连续 /
45
- 活跃时段 / 常用模型,与主流 coding 客户端首页的概览集合对齐。
46
- - **时间范围**:全部 / 365 / 30 / 7 天四档,**默认「全部」**。理由:「总 Token」「最长连续」
47
- 「活跃天数」天然是全时段概念,套上半年窗口会名不副实(最长连续会被截断成「窗口内最长」);
48
- 放开窗口不增加任何成本(mtime 全量扫描、索引本就存了所有日期)。365 那一档与下方热力图
49
- 的一年网格对齐。非法值回退「全部」,有限窗口的数值夹到最近一档。
50
- - **「全部」档的活跃天数**副标题显示实际跨度(最早一条数据到今天,如「共 108 天」),
51
- 而不是一个恒定的窗口长度。
52
-
53
- ### 「≈ N 部书」怎么算
54
-
55
- 换算基准 **1 汉字 ≈ 1.5 token**,可由参考实现反向验证(它显示「4.1M token ≈
56
- 9.1 部《三体·地球往事》」,而该书约 30 万字 → 30 万 × 1.5 = 45 万 token,
57
- 4.1M / 45 万 ≈ 9.1)。
58
-
59
- 选书规则:只考虑倍数 ≥ 1 的作品(不说「0.3 部红楼梦」),在候选里挑倍数最接近
60
- **8** 的一本 —— 用对数距离而不是线性距离,因为「1.5 倍」和「8 倍」的观感差距
61
- 应该按比例算。三档措辞:
62
-
63
- | 档位 | 条件 | 文案 |
64
- | --- | --- | --- |
65
- | 常规 | 1 ≤ 倍数 ≤ 20 | `≈ 8.9 部《二十四史》` |
66
- | under | 倍数 < 1 | `不到 1 部《活着》` |
67
- | beyond | 倍数 > 20 | `超过 83 部《四库全书》的体量` |
68
-
69
- beyond 不是缺陷:现存最大的中文丛书(《四库全书》约 8 亿字 ≈ 12 亿 token)也就
70
- 这么多,再往上人类没有更大的作品可比。表按 token 当量排序,覆盖 15 万 – 1200 亿,
71
- 相邻作品差控制在 2 倍以内,倍数才能稳定落在可读区间。
72
-
73
- 书目共 **58 部**,分计算机 / 科学 / 科幻 / 历史 / 小说 / 传记 / 参考七类。
74
- 只用**中文著作**做基准:英文 1 词 ≈ 1.3 token 与中文 1 字 ≈ 1.5 token 不同量纲,
75
- 混在同一张表里会让倍数失去可比性(所以是《中国大百科全书》而不是《大英百科全书》)。
76
- 每部作品标注字数可信度(`high` = 通行且稳定,`mid` = 随译本/版本浮动)。
77
- - **页脚(DSH 特有)**:24 小时消息直方图(峰值柱实心)+「≈ N 部书」换算 ——
78
- token 数字没有直觉,换算成「相当于读了多少部书」之后第一次有了参照。
79
- 换算用 **「新内容」口径**(input + output,不含 cacheRead),两种口径的差异
80
- 在 hover 时给出:重度使用时 cacheRead 可占 96%(同一段上下文被反复读),
81
- 拿含重复的总量比作「读了多少书」会严重虚高。
82
- - **口径**:会话数 / 活跃天数 / 连续天数来自会话目录的 mtime(与热力图同源);
83
- 消息数 / Token / 活跃时段 / 常用模型来自 token 索引的 v2 日桶(见下文),
84
- 口径与宿主 `token-meter` 完全一致。
85
- - **活跃时段**用**消息数**做直方图权重,而不是 token:凌晨挂一个大任务会把
86
- token 直方图整个拉偏,消息数更接近「人在什么时间用」。
87
- - **常用模型**取自 assistant 消息的 `message.source`(实际结算用的 provider/model),
88
- 而不是 `request/header`(那只是请求配置,重试/换模型后与结算不一致);
89
- 窗口内按累计 token 排序取前三,格子里显示模型段,完整 `provider/model`
90
- 悬停可见。
91
- - **开关**:设置页「显示活动概览」,默认开启;关闭后槽位注销、不发请求、
92
- 不扫目录,与热力图开关同语义。
93
-
94
- ## 显示在哪一屏
30
+ 八项指标,一张 2 × 4 的栅格:
95
31
 
96
- **新会话 / 空态页**,大标题「探索未至之境」的**正下方**(工作区选项行之上、输入框之上),
97
- 水平居中,是**与下方输入框同宽**的两张圆角卡片(运行时量 `[data-composer-card]` 的宽度,
98
- 窗口缩放时跟随):活动概览在上(order 15)、热力图在下(order 20);概览卡是
99
- 标题与范围切换在左、说明行贴在指标栅格上方、24 小时火花线与当量换算在底部;
100
- 热力图卡是标题与指标切换在左、总数与图例在右、月份贴在网格下方。
101
-
102
- 宿主的槽位体系里没有「标题下方」这个位置,`conversation.hero.options` 只出现在下面那行
103
- 工作区选项里;所以插件注册槽位只作为「何时显示」的开关,内容用 portal 挂进 HeroShell
104
- 标题之后的容器。宿主改结构导致挂载点找不到时,会在 1.5 秒后回退到槽位内联(右侧那一行),
105
- 功能不丢,只是位置不同。
106
-
107
- 第一轮对话开始后 hero 区消失,两张卡也随之不显示 —— 这是宿主本来的行为,插件不另做入口。
108
-
109
- 设置页(**设置 → 活跃度**)有两个开关(热力图 / 活动概览)、一个「默认指标」选择,
110
- 以及说明。没有侧栏图标,不占任何常驻空间。
32
+ | 指标 | 说明 |
33
+ | --- | --- |
34
+ | 会话数 | 一共开过多少个会话 |
35
+ | 消息数 | 实际结算过的消息条数 |
36
+ | 总 Token | 累计消耗的 token |
37
+ | 活跃天数 | 有记录的天数 |
38
+ | 当前连续 | 到今天为止连续活跃了几天 |
39
+ | 最长连续 | 历史最长连续活跃记录 |
40
+ | 活跃时段 | 你最常在一天里的哪个小时干活 |
41
+ | 常用模型 | 用得最多的那个模型 |
111
42
 
112
- ## 两个指标
43
+ 上方可以切换 **全部 / 365 天 / 30 天 / 7 天** 四个时间范围,默认「全部」。
44
+ 「总 Token」「最长连续」「活跃天数」本来就是全时段的概念,所以默认不设窗口;
45
+ 需要看近期状态时切到 30 天或 7 天。
113
46
 
114
- | | 会话 | Token |
115
- | --- | --- | --- |
116
- | 数据来源 | 会话文件 mtime | 会话日志内的 `usage` 事件 |
117
- | 是否解压 | 否 | **是**(zstd 帧) |
118
- | 首屏成本 | 毫秒级 | 后台增量索引,就绪前显示进度 |
119
- | 分档 | `0` / `1-2` / `3-5` / `6-9` / `10+` | `0` / `≥10M` / `≥50M` / `≥150M` / `≥500M` |
47
+ 底部有一条 **24 小时消息分布**,最高那根柱子实心显示,一眼看出你的作息。
120
48
 
121
- 切换只改本卡的显示,不写回配置;「默认指标」在设置页里改。
49
+ ## 活跃度热力图
122
50
 
123
- ### 为什么 Token 要建索引
51
+ 最近一年每天一个格子,颜色越深当天越活跃。
124
52
 
125
- 会话日志是 zstd 压缩的,读 token 必须解压。本机实测:151 个会话 / 276 MB 压缩数据 /
126
- 200457 个 zstd 帧 / 解压后 1.17 GB,**冷扫一次约 20 秒**(解压是 CPU 与内存带宽瓶颈,
127
- worker 并行实测更慢:115 秒 vs 20 秒)。
53
+ 顶部可切换 **会话数 / Token 用量** 两种口径,共用同一张网格与日期轴,切换时格子位置不动。
54
+ 鼠标悬停显示具体日期与数值。
128
55
 
129
- 所以插件不做「请求时现算」,而是:
56
+ ## 「≈ N 部书」
130
57
 
131
- 1. **请求永远只读内存里当前已知的按天数据** —— 实测热路径 0.15 ms;
132
- 2. **后台按 zstd 帧增量索引**,只解压新增的帧(索引记录每个文件已消费的字节偏移);
133
- 3. **索引落盘**到 `<DSH_HOME>/pulse-overview-token-index.json`,进程重启不必重扫;
134
- 4. 索引补进新数据后立刻让活跃度缓存失效,用户不必等 60 秒。
58
+ Token 总量换算成「相当于读了多少部书」—— token 数字没有直觉,书有。
135
59
 
136
- 首次进入 Token 视图时,网格上方会显示 `正在建立索引 102/139` 这样的进度,已有部分照常画出来。
60
+ 换算基于**新内容**(你实际读入的与模型生成的部分),不把重复读取的上下文算进去:
61
+ 重度使用时重复读取能占到九成以上,拿它比作「读了多少书」会严重虚高。
62
+ 悬停可以看到两种口径的完整数字。
137
63
 
138
- ### Token 口径与宿主一致
64
+ 书目 58 部,覆盖计算机、科学、科幻、历史、小说、传记与大型参考书,
65
+ 按用量自动挑最贴切的那一部。
139
66
 
140
- 聚合规则照抄宿主 `packages/llm/token-meter/src/usage-projection.ts`:
67
+ ## 显示在哪
141
68
 
142
- - 只有 `assistant/message` / `assistant/attempt` 事件贡献用量;
143
- - 用量取 `data.usage`,没有则取 `data.stream` 里**最后一个** `type:'usage'` 分片;
144
- - `llm/retry-started` 清掉同 turn/step 的上一次采样;
145
- - 同一 turn/step 的重复结算**替换**而非累加。
69
+ **新会话页面**大标题的正下方,与输入框同宽的两张卡片,上下排列:活动概览在上,热力图在下。
70
+ 窗口缩放时跟着变宽变窄。
146
71
 
147
- 这不是可选的实现细节:直接累加所有 `type:'usage'` 分片会把流式增量重复计一遍。
148
- 实测某个会话会从 18.6M 虚增到 1.9B。本插件用 45 个真实会话与宿主的 `tokenUsage` 投影逐条比对,
149
- **45/45 完全一致**。
72
+ 开始第一轮对话后,这个区域会随宿主一起消失 —— 这是宿主本来的行为。
150
73
 
151
74
  ## 安装
152
75
 
@@ -154,223 +77,25 @@ worker 并行实测更慢:115 秒 vs 20 秒)。
154
77
  dsh plugin --profile web add dsh-pulse-overview
155
78
  ```
156
79
 
157
- 本地开发时可以直接装目录(把 `<path>` 换成 `dsh-pulse-overview` 的路径):
158
-
159
- ```bash
160
- dsh plugin --profile web add <path>/dsh-pulse
161
- ```
162
-
163
- 装完刷新 DSH Web 页面,新开一个会话即可看到。
80
+ 装完刷新页面,新开一个会话即可看到。
164
81
 
165
- ## 开关
82
+ ## 设置
166
83
 
167
- 设置页里的「显示会话热力图」默认**开启**——这是插件唯一的功能。
84
+ **设置 → 活跃度**:
168
85
 
169
- 关闭后不是用 CSS 把它藏起来,而是:
170
-
171
- - 热力图槽位**注销**(宿主不再渲染,组件不会挂载);
172
- - 不再请求 `GET /api/pulse/activity`;
173
- - 服务端即使收到请求也直接返回空数据,**不扫描**本地会话目录,也不跑 token 索引。
86
+ - **显示活动概览** —— 开关,默认开
87
+ - **显示会话热力图** —— 开关,默认开
88
+ - **默认指标** —— 热力图默认按会话数还是 Token 显示
174
89
 
90
+ 两个开关相互独立,可以只留其中一张卡。关掉之后不做任何统计,也不占位置。
175
91
  重新打开即时生效,不需要重启。
176
92
 
177
- ## 数据来源
178
-
179
- ```text
180
- <DSH_HOME or ~/.dsh>/sessions/<project>/<sessionDir>/session*.jsonl.zstd
181
- ```
182
-
183
- - `<sessionDir>` 有两种命名:`session-<uuid>` 与裸 `<uuid>`,都识别。
184
- - 会话文件名带版本号(实测 `session.v4.jsonl.zstd`)。
185
- - **同一目录里会同时存在多个世代**(实测某目录有 `session.jsonl.zstd` + `session.v3` + `session.v4`),
186
- 旧世代是升级残留。插件只读**版本号最大**的那个 —— 两个都读会把同一批事件算两遍。
187
- 会话的 mtime 与 token 两条链路用同一个选择,不会出现「mtime 按 v4 算、token 按 v3 算」。
188
- - 会话视图**只读文件的 mtime,不解压、不解析**。
189
- - mtime 是 UTC 时刻,聚合时按**本地时区**换算成日历日(不是取 ISO 字符串前 10 位——
190
- 北京时间每天 0:00–8:00 的会话会被算到昨天)。
191
- - 目录不存在、权限不足、单个项目读失败:跳过,返回已有数据,不报错。
192
-
193
- 统计口径:
194
-
195
- | 值 | 含义 |
196
- | --- | --- |
197
- | 每天的值 | 当天有 mtime 落在该本地日历日的会话数(每个会话目录算一次) |
198
- | 默认窗口 | 最近 53 周(371 天,一年),周一为每列第一行 |
199
- | 最后一列 | 本周;未来日期渲染成透明占位,不参与计数 |
200
-
201
- ## HTTP 接口
202
-
203
- 插件通过宿主的 `webServer` 注册三条精确路由。
204
-
205
- ### `GET /api/pulse/overview?range=all`
206
-
207
- 活动概览的聚合数据。`range` 取 `all`(默认,也接受 `0`)/ `365` / `30` / `7`;
208
- 非法值回退 `all`,有限窗口的数值夹到最近一档。
209
-
210
- ```json
211
- {
212
- "ok": true,
213
- "enabled": true,
214
- "range": 0,
215
- "spanDays": 108,
216
- "today": "2026-11-29",
217
- "sessions": 139,
218
- "messages": 48516,
219
- "tokens": 14887600000,
220
- "activeDays": 58,
221
- "currentStreak": 7,
222
- "longestStreak": 8,
223
- "peakHour": "17:00",
224
- "topModels": [{ "model": "workbuddy/deepseek-v4.1-flash", "tokens": 2940900000 }],
225
- "hours": [0, 0, ..., 8741, ...],
226
- "index": { "ready": true, "running": false, "scanned": 139, "total": 139, "partial": false }
227
- }
228
- ```
229
-
230
- - `range: 0` 表示「全部」;`spanDays` 是最早一条记录到今天的天数(实际跨度)。
231
- - `hours` 是 24 个小时桶(本地时间 0–23 点)的消息数直方图;`peakHour` 是其中的峰值桶。
232
- - 消息数 / Token / 时段 / 模型依赖 token 索引:请求会触发后台索引(有 30 秒节流),
233
- 索引没就绪时数字照常返回、只是可能偏小,`index.partial` 为 true 时客户端轮询补齐。
234
- - 连续天数「今天还没活跃」不断链:当前连续数到昨天为止,今天结束后自然续上。
235
- - 开关关闭时返回 `{ ok: true, enabled: false }`,不扫目录、不读缓存。
236
-
237
- ### `GET /api/pulse/activity?weeks=53&metric=sessions`
238
-
239
- `metric` 取 `sessions`(默认)或 `tokens`;非法值回退 `sessions`。
240
-
241
- ```json
242
- {
243
- "ok": true,
244
- "enabled": true,
245
- "metric": "sessions",
246
- "weeks": 53,
247
- "days": [{ "date": "2026-11-27", "count": 3, "level": 1, "tokens": 42000000, "tokenLevel": 2 }],
248
- "max": 12,
249
- "total": 139,
250
- "tokenMax": 1753075386,
251
- "tokenTotal": 14827865992,
252
- "today": "2026-11-27",
253
- "index": { "ready": true, "running": false, "scanned": 139, "total": 139, "partial": false }
254
- }
255
- ```
256
-
257
- - `days` 固定为 `weeks * 7` 条,从第一列周一到最后一列周日;每条同时带 `level`(会话档)
258
- 与 `tokenLevel`(token 档),客户端按数组顺序渲染,不做日期换算。
259
- - 两个指标共用同一个日期轴,切换时网格位置不动。
260
- - `today` 用于把未来日期画成透明占位。
261
- - 服务端缓存 **60 秒**;`weeks` 非法回退 53,超出 1–53 夹取。
262
- - `index.partial` 为 true 表示 token 数据仍在补齐,客户端据此显示进度并轮询。
263
- - 开关关闭时返回 `{ ok: true, enabled: false, metric, weeks: 0, days: [], ... }`,
264
- 且**不扫描目录、不跑索引**。
265
-
266
- ### `GET /api/pulse/config` / `POST /api/pulse/config`
267
-
268
- ```json
269
- { "ok": true, "config": { "heatmapEnabled": true, "metric": "sessions", "overviewEnabled": true }, "configError": null }
270
- ```
271
-
272
- `POST` 只接受 `application/json`,字段按白名单校验(非法值整单拒绝):
273
-
274
- ```bash
275
- curl -X POST http://127.0.0.1:<port>/api/pulse/config \
276
- -H 'content-type: application/json' \
277
- -d '{"heatmapEnabled": false, "metric": "tokens"}'
278
- ```
279
-
280
- ## 配置
281
-
282
- `<DSH_HOME>/pulse-overview-config.json`,与 `soul-config.json` 同级但**不共用**:
283
-
284
- ```json
285
- {
286
- "heatmapEnabled": true,
287
- "metric": "sessions",
288
- "overviewEnabled": true
289
- }
290
- ```
291
-
292
- 文件损坏时按默认值(全部开启 / 会话视图)运行,并在设置页返回 `configError`;修好文件后下一次读取自动恢复,不必重启。
293
-
294
- Token 索引是**可再生的缓存**,单独放在 `<DSH_HOME>/pulse-overview-token-index.json`;
295
- 删掉它只会让下一次 Token 视图重建索引,不影响任何配置。索引文件格式版本是 **2**
296
- (v1 没有 messages / hours / models 维度,读到 v1 会整体丢弃重建);
297
- 重建成本见下文「为什么 Token 要建索引」。
298
-
299
- ## 配色与主题
300
-
301
- 全部取主题 token,明暗主题自动适配,**没有一个字面颜色值**:
302
-
303
- - 卡片:`--dsw-specific-input-major` 底色 + `--dsw-elevation-stroke` 发丝描边 +
304
- `--dsw-shadow-lv1` 投影 + `--dsw-radius-lg` 圆角 —— 与 InputBar 的 `.card` 完全同一套;
305
- - `0` 档:`var(--dsw-alias-bg-skeleton)`(宿主骨架屏灰)
306
- - `1`–`3` 档:`color-mix(in srgb, var(--dsw-static-deepseek-500) N%, transparent)`,N = 26 / 48 / 72
307
- - `4` 档:`var(--dsw-static-deepseek-500)`
308
-
309
- 为什么不是绿色:绿色在宿主里是「成功状态」的语义,一张 371 格的绿网格会让整个首页
310
- 看起来在报成功事件;品牌蓝既符合宿主的无色相 chrome,又让「这是 DeepSeek Harness 的数据」成立。
311
-
312
- 格子是正方形(`aspect-ratio: 1`)、2px 圆角、3px 间距;hover 放大到 128% 并描边,
313
- 弹出日期 + 当前指标数值的浮层(不用原生 `title`)。
314
-
315
- ## 开发
316
-
317
- ```bash
318
- npm run verify # 九个校验脚本,全部离线,无依赖
319
- npm run verify:strict # 跳过即失败(本仓库目前没有会跳过的校验)
320
- ```
321
-
322
- | 脚本 | 覆盖 |
323
- | --- | --- |
324
- | `verify-config` | 默认配置、脏数据回退、输入校验、插件清单契约 |
325
- | `verify-activity` | 本地时区聚合、周一对齐、五档边界、世代选择、真实 mtime 目录扫描、60 秒缓存 |
326
- | `verify-token-index` | zstd 帧扫描、用量归集规则、跨日替换、增量续读、torn 尾帧、落盘复用、v2 维度(消息数 / 小时 / 模型)与同日追加回归 |
327
- | `verify-books` | 换算系数反验、选书算法(含 under/beyond 两档)、倍数格式化、58 部表的量级覆盖无断层 |
328
- | `verify-overview` | 范围夹取、窗口裁剪、连续天数、峰值时段(含并列中位)、常用模型排序、TTL 缓存、直方图契约 |
329
- | `verify-host` | 真的跑 `apply()`,断言三条路由响应、开关语义、配置落盘 |
330
- | `verify-client` | 真的跑 `apply(ctx)`,断言词典键集(40 键 × 8 语言)、槽位 order、关掉开关时注销槽位、样式契约 |
331
- | `verify-render` | 迷你 React 真渲染两个组件:指标切换、档位、进度、浮层、概览八格 / 火花线 / 说明行 / 空态 |
332
- | `verify-placement` | 假 hero DOM:portal 挂到标题下方、卸载清理、找不到挂载点时的回退 |
333
-
334
- 目录结构:
335
-
336
- ```text
337
- dsh-pulse/
338
- index.mjs # host:配置读写 + 三条路由 + 后台索引调度
339
- client/index.mjs # 客户端:词典、槽位、两个组件、样式
340
- lib/config.mjs # 默认配置、迁移、校验
341
- lib/activity.mjs # 双指标聚合(纯函数)+ 60 秒缓存读取器 + HOUR_BUCKETS
342
- lib/overview.mjs # 活动概览聚合(纯函数)+ 按范围分键的 TTL 读取器
343
- lib/books.mjs # 「≈ N 部书」的参照表(58 部)与选书算法
344
- lib/sessions.mjs # 会话目录扫描 + 世代选择
345
- lib/token-index.mjs # token 归集规则 + 增量索引 + 落盘(v2:messages/hours/models)
346
- lib/zstd-frames.mjs # zstd 拼接帧的结构扫描(不解压)
347
- scripts/ # 九个零依赖校验脚本
348
- scripts/render-preview.py # 用真实数据 + 真实 token 值渲染预览图
349
- ```
350
-
351
- 预览图由 `scripts/render-preview.py` 生成(读真实 payload 与真实主题 token);
352
- 沙箱禁止 Chrome 的 mojo IPC 时,这是唯一能核对视觉的路径。
353
-
354
- ## 已知限制
355
-
356
- - 会话视图按 mtime 计数:一个会话目录无论多少轮对话,都只算「当天 1 个会话」。
357
- - Token 索引首次建立约 30–45 秒(取决于历史会话体积与机器;151 会话 / 277 MB 实测
358
- 46.8 秒,其中 JSON 解析占大头,v2 的消息 / 时段 / 模型归集只增加约 2%),
359
- 期间显示进度;之后增量更新几乎无感。
360
- - Token 分档阈值是按一台重度使用机器标定的固定值(10M/50M/150M/500M)。
361
- 用量差异极大的机器上四档分布会偏斜 —— 目前不提供按个人分位数自适应的选项。
362
- - 「常用模型」的模型名超过格宽时截断(完整名 hover 可见);不提供按项目的细分统计,
363
- 也没有独立的报告页。
364
- - 「≈ N 部书」的书目字数为通行引用值,随译本 / 版本浮动(表中用 conf 标注可信度)。
365
- 超过 200 亿 token 时倍数会超出「部」能表达的量级,改用 beyond 措辞。
366
- - 不注册侧栏图标,不引入任何图表库。
367
-
368
93
  ## 隐私
369
94
 
370
- 全部在本地完成:插件读取 `<DSH_HOME>/sessions` 下文件的 **mtime**,以及在需要 Token 视图
371
- 或活动概览时**在本地解压**会话日志、只提取 `usage` 里的 token 计数与
372
- `message.source` 的模型标识。不上传任何内容,不解析、不保存对话正文;
373
- 索引文件只记录「某天多少 token / 多少条消息 / 哪个小时 / 哪个模型」。
95
+ 全部在本地完成。
96
+
97
+ 插件读取本地会话文件的时间戳;在需要 Token 与模型数据时,**在本地**解压会话日志,
98
+ 只取出用量计数与模型名。不上传任何内容,不解析、不保存对话正文。
374
99
 
375
100
  ## 许可证
376
101
 
package/README_EN.md CHANGED
@@ -1,29 +1,23 @@
1
- # dsh-pulse
1
+ # dsh-pulse-overview
2
2
 
3
- Two additions to [DeepSeek Harness](https://github.com/deepseek-ai)'s New Session screen:
3
+ Two statistics panels for [DeepSeek Harness](https://github.com/deepseek-ai)'s **New Session** screen:
4
4
 
5
- 1. **Activity overview** — sessions / messages / total tokens / active days / current streak /
6
- longest streak / peak hours / top model in a 2 × 4 metric grid, with all / 365 / 30 / 7-day ranges;
7
- 2. **Activity heat map** — how active each day of the past year was, with **session count** and
8
- **token usage** sharing one grid.
9
-
10
- The cards are built from the host's own design tokens (same fill, hairline stroke, corners and shadow
11
- as the composer below them), and the palette follows the host's achromatic-chrome rule: accents are
12
- DeepSeek brand blue, level 0 is the host's skeleton grey.
5
+ 1. **Activity overview** — a 2 × 4 metric grid, eight numbers at a glance;
6
+ 2. **Activity heat map** — how active each day of the past year was, like GitHub's contribution graph.
13
7
 
14
8
  ![Overview + heat map preview (light / dark, real data)](docs/overview-preview.png)
15
9
 
16
10
  ```
17
11
  ┌ Overview [All] [365 days] [30 days] [7 days] ┐
18
- │ All 140 sessions │
12
+ │ All 140 sessions │
19
13
  │ ┌Sessions┐ ┌Messages┐ ┌Tokens┐ ┌Active days┐ │
20
- │ │ 140 │ │ 48,589 │ │ 1.49B │ │ 58 d │ │
14
+ │ │ 140 │ │ 48,668 │ │ 1.49B │ │ 58 d │ │
21
15
  │ └────────┘ └────────┘ └───────┘ └───────────┘ │
22
16
  │ ┌Streak┐ ┌Longest┐ ┌Peak hour┐ ┌Top model┐ │
23
17
  │ │ 7 d │ │ 8 d │ │ 17:00 │ │ v4.1-… │ │
24
18
  │ └──────┘ └────────┘ └──────────┘ └─────────┘ │
25
19
  │ 00:00 ▁▁▂▂▅▃▁▁▂▃▃▃▆▂▂▂▁▂▃▃▁▁▂▁ 23:00 │
26
- │ ≈ 8.9 × 《二十四史》 │
20
+ │ ≈ 8.9 × 《二十四史》 │
27
21
  └─────────────────────────────────────────────────────────────────┘
28
22
  ┌ Activity [Sessions] [Tokens] 139 sessions Less ▢ ▢ ▣ ▣ ▣ More ┐
29
23
  │ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▢ ▣ ▣ ▢ ▣ ▣ ▣ ▣ ▣ ▣ ▣ ▣ ▣ ▣ … │
@@ -33,256 +27,82 @@ DeepSeek brand blue, level 0 is the host's skeleton grey.
33
27
 
34
28
  ## Activity overview
35
29
 
36
- - **Eight metrics** aligned with mainstream coding clients' home dashboards.
37
- - **Time range**: all / 365 / 30 / 7 days, defaulting to **all**. Total tokens, longest streak
38
- and active days are whole-history concepts; a half-year window silently truncates them.
39
- Widening costs nothing (mtimes are scanned in full and the index already stores every date).
40
- The 365 tier lines up with the heat map's one-year grid. Invalid values fall back to "all".
41
- - **Active days under "all"** shows the real span (earliest data through today) as its subtitle
42
- instead of a constant window length.
43
- - **Footer (DSH-specific)**: a 24-hour message histogram (peak bar solid) plus an
44
- "≈ N books" conversion — token counts have no intuition until expressed as how many
45
- books that would be. It uses the **new-content** basis (input + output, excluding
46
- cacheRead); the difference between the two bases appears on hover. Under heavy use
47
- cacheRead can be 96% (the same context re-read), so comparing the repeat-inclusive
48
- total to "books read" would be badly inflated.
49
- - **Sources**: sessions / active days / streaks come from session mtimes (same source as the
50
- heat map); messages / tokens / peak hours / top model come from the token index's v2 day
51
- buckets, whose accounting matches the host's `token-meter` exactly.
52
- - **Peak hours** weight by **messages**, not tokens: one large overnight task would skew a
53
- token histogram entirely; message counts track "when a human uses it".
54
- - **Top model** comes from `message.source` on assistant messages (the provider/model that
55
- actually settled), not `request/header` (request config, which drifts after retries or
56
- model switches); ranked by windowed tokens, top three, the cell shows the model segment
57
- with the full `provider/model` on hover.
58
- - **Switch**: "Show the activity overview" in settings, on by default; when off, the slot is
59
- unregistered, no requests are sent, and the session folder is not scanned — same semantics
60
- as the heat map switch.
61
-
62
- ## Where it appears
63
-
64
- The **New Session / empty state** screen — directly below the big headline ("Into the Unknown"),
65
- above the workspace options row and the composer, horizontally centered. It is a rounded card **as wide as the composer
66
- below** (measured from `[data-composer-card]` at runtime, so it follows window resizes): title on
67
- the left, total and legend on the right, month labels under the grid.
68
-
69
- The host exposes no slot in that position (`conversation.hero.options` lives in the workspace
70
- row below), so the plugin uses its slot registration only as a "when to show" switch and portals
71
- the content into the container right after the hero headline. If the host structure changes and
72
- the mount point cannot be found, it falls back to inline rendering in the workspace row after
73
- 1.5 s — still functional, just in the old spot.
74
-
75
- Once the first turn starts the hero area disappears and the heat map goes with it (that is the
76
- host's own behavior; this plugin adds no other entry point).
77
-
78
- Settings (**Settings → Activity**) has a single switch and one line of explanation.
79
- No sidebar icon, no permanent space taken.
80
-
81
- ## Install
82
-
83
- ```bash
84
- dsh plugin --profile web add dsh-pulse-overview
85
- ```
30
+ Eight metrics in a 2 × 4 grid:
86
31
 
87
- For local development you can install the directory directly:
88
-
89
- ```bash
90
- dsh plugin --profile web add <path>/dsh-pulse
91
- ```
92
-
93
- Reload the DSH web page and open a new session.
94
-
95
- ## The switch
96
-
97
- "Show the session heat map" is **on** by default — it is the plugin's only feature.
98
-
99
- Turning it off does not hide the widget with CSS. It:
100
-
101
- - **unregisters** the heat map slot (the host no longer renders it, the component never mounts);
102
- - stops requesting `GET /api/pulse/activity`;
103
- - makes the server return an empty payload without **scanning** the session folder, even if asked.
104
-
105
- Turning it back on takes effect immediately; no restart.
106
-
107
- ## Data source
108
-
109
- ```text
110
- <DSH_HOME or ~/.dsh>/sessions/<project>/<sessionDir>/session*.jsonl.zstd
111
- ```
112
-
113
- - `<sessionDir>` comes in two shapes: `session-<uuid>` and bare `<uuid>`. Both are recognized.
114
- - Session files carry a version segment (observed: `session.v4.jsonl.zstd`); the plugin matches
115
- `session*.jsonl.zstd` so both names work.
116
- - **Only the file mtime is read** — nothing is decompressed or parsed. One session directory
117
- contributes one cell on one day.
118
- - mtime is a UTC instant, so it is converted to a **local** calendar day. (Taking the first 10
119
- characters of an ISO string would push sessions between 00:00 and 08:00 in UTC+8 onto the
120
- previous day.)
121
- - Missing folder, permission errors, a single unreadable project: skipped, partial data is
122
- returned, nothing throws.
123
-
124
- Counting rules:
125
-
126
- | Value | Meaning |
32
+ | Metric | Meaning |
127
33
  | --- | --- |
128
- | Per-day value | Number of session directories whose newest file mtime falls on that local day |
129
- | Default window | Last 53 weeks (371 days, one year), Monday on the first row of each column |
130
- | Last column | The current week; future days render as transparent placeholders and never count |
131
- | Levels | `0` / `1-2` / `3-5` / `6-9` / `10+` |
132
-
133
- ## HTTP API
134
-
135
- ### "≈ N books"
136
-
137
- The basis is **1 Chinese character ≈ 1.5 tokens**, verifiable against the reference
138
- implementation (it shows "4.1M tokens ≈ 9.1 × 《三体·地球往事》", and that book is
139
- about 300k characters → 300k × 1.5 = 450k tokens, 4.1M / 450k ≈ 9.1).
34
+ | Sessions | How many conversations you have started |
35
+ | Messages | How many messages actually settled |
36
+ | Tokens | Cumulative token spend |
37
+ | Active days | Days with any activity |
38
+ | Current streak | Consecutive active days up to today |
39
+ | Longest streak | Your all-time longest run |
40
+ | Peak hours | The hour of day you work most |
41
+ | Top model | The model you reach for most |
140
42
 
141
- Selection: only works with a multiple ≥ 1 are considered (never "0.3 × 红楼梦"), and
142
- the pick minimizes log-distance to **8** — perceptual gaps between 1.5× and 8× are
143
- proportional, not additive. Three wordings: regular (`≈ 8.9 × 《二十四史》`),
144
- under (`Less than one 《活着》`), and beyond (`More than 83 × 《四库全书》`).
43
+ Switch the range with **All / 365 / 30 / 7 days**; the default is **All**.
44
+ Total tokens, longest streak and active days are whole-history concepts, so no
45
+ window is applied by default — drop to 30 or 7 days when you want the recent picture.
145
46
 
146
- The table holds **58 works** across CS / science / sci-fi / history / fiction /
147
- biography / reference. Only **Chinese works** set the basis: English words
148
- (≈ 1.3 tokens each) and Chinese characters (≈ 1.5) are different units, and mixing
149
- them makes multiples incomparable — hence 《中国大百科全书》 rather than the
150
- Britannica. Each work carries a character-count confidence mark.
47
+ A **24-hour message histogram** sits at the bottom, peak bar filled solid, so your
48
+ daily rhythm is visible at a glance.
151
49
 
152
- ### `GET /api/pulse/overview?range=all`
50
+ ## Activity heat map
153
51
 
154
- Aggregated overview data. `range` accepts `all` (default, also `0`) / `365` / `30` / `7`; invalid values fall back to
155
- `all`, finite windows snap to the nearest tier.
52
+ One cell per day for the past year; darker means more active that day.
156
53
 
157
- ```json
158
- {
159
- "ok": true,
160
- "enabled": true,
161
- "range": 0,
162
- "spanDays": 108,
163
- "today": "2026-11-29",
164
- "sessions": 139,
165
- "messages": 48668,
166
- "tokens": 14940000000,
167
- "freshTokens": 536000000,
168
- "books": { "count": "8.9", "name": "《二十四史》", "under": false, "beyond": false },
169
- "activeDays": 58,
170
- "currentStreak": 7,
171
- "longestStreak": 8,
172
- "peakHour": "17:00",
173
- "topModels": [{ "model": "workbuddy/deepseek-v4.1-flash", "tokens": 2940900000 }],
174
- "hours": [0, 0, "...", 8741],
175
- "index": { "ready": true, "running": false, "scanned": 139, "total": 139, "partial": false }
176
- }
177
- ```
178
-
179
- - `range: 0` means "all time"; `spanDays` is the real span from the earliest record through today.
180
- - `hours` is a 24-bucket histogram of settled messages per local hour; `peakHour` is the peak bucket.
181
- - Messages / tokens / hours / models depend on the token index: requests kick it in the
182
- background (throttled), numbers are returned as known while `index.partial` is true and the
183
- client polls until the index is ready.
184
- - A streak does not break just because today has no activity yet: the current streak counts
185
- back from yesterday and resumes naturally after today ends.
186
- - When the overview switch is off the route returns `{ "ok": true, "enabled": false }` and
187
- scans nothing.
54
+ Toggle between **session counts** and **token usage** at the top — both share the same
55
+ grid and date axis, so cells never move when you switch. Hover shows the exact date
56
+ and value.
188
57
 
189
- ### `GET /api/pulse/activity?weeks=53`
58
+ ## "≈ N books"
190
59
 
191
- ```json
192
- {
193
- "ok": true,
194
- "enabled": true,
195
- "weeks": 53,
196
- "days": [{ "date": "2026-11-27", "count": 3, "level": 1 }],
197
- "max": 12,
198
- "total": 88,
199
- "today": "2026-11-27"
200
- }
201
- ```
60
+ Total tokens expressed as how many books that would fill — raw token counts have no
61
+ intuition, books do.
202
62
 
203
- - `days` always has `weeks * 7` entries, from the Monday of the first column to the Sunday of
204
- the last. Each entry carries `level` (0–4), so the client renders in array order without any
205
- date math.
206
- - `today` lets the client draw future cells as transparent placeholders.
207
- - Results are cached server-side for **60 seconds**. Invalid `weeks` falls back to 53; values
208
- outside 1–53 are clamped.
209
- - When the switch is off the route returns
210
- `{ "ok": true, "enabled": false, "weeks": 0, "days": [], "max": 0, "total": 0, "today": null }`
211
- and does **not** scan anything.
63
+ The conversion uses **new content** (what you actually read in and what the model
64
+ generated), excluding repeated context reads: under heavy use, re-reads can account
65
+ for more than ninety percent, and counting them would badly inflate "books read".
66
+ Hover to see both figures.
212
67
 
213
- ### `GET /api/pulse/config` / `POST /api/pulse/config`
68
+ The shelf holds 58 works across computer science, science, sci-fi, history, fiction,
69
+ biography and large reference collections; the closest-fitting one is picked
70
+ automatically from your volume.
214
71
 
215
- ```json
216
- { "ok": true, "config": { "heatmapEnabled": true, "overviewEnabled": true }, "configError": null }
217
- ```
72
+ ## Where it appears
218
73
 
219
- `POST` requires `application/json`; booleans `heatmapEnabled` / `overviewEnabled` and the
220
- `metric` enum are whitelist-validated.
74
+ Directly beneath the big heading on the **New Session** screen: two cards stacked
75
+ vertically, as wide as the composer below them, resizing with the window.
221
76
 
222
- ## Configuration
77
+ Once the first exchange begins, this area disappears along with the host's own
78
+ hero region — that is the host's behaviour, not something this plugin adds.
223
79
 
224
- `<DSH_HOME>/pulse-overview-config.json` (sibling of, and separate from, `soul-config.json`):
80
+ ## Install
225
81
 
226
- ```json
227
- {
228
- "heatmapEnabled": true
229
- }
82
+ ```bash
83
+ dsh plugin --profile web add dsh-pulse-overview
230
84
  ```
231
85
 
232
- A corrupt file falls back to the defaults (enabled) and reports `configError` to the settings
233
- page; fixing the file recovers on the next read without a restart.
234
-
235
- ## Colors
236
-
237
- Everything comes from theme tokens, so light and dark themes both work with no literal colors:
238
-
239
- - card: `--dsw-specific-input-major` fill + `--dsw-elevation-stroke` hairline +
240
- `--dsw-shadow-lv1` shadow + `--dsw-radius-lg` corners — the exact same set as InputBar's `.card`;
241
- - level `0`: `var(--dsw-alias-bg-skeleton)` (the host's own skeleton grey)
242
- - levels `1`–`3`: `color-mix(in srgb, var(--dsw-static-deepseek-500) N%, transparent)`
243
- with N = 26 / 48 / 72
244
- - level `4`: `var(--dsw-static-deepseek-500)`
245
-
246
- Not green: green carries the "success state" meaning in the host, and a 371-cell green grid makes
247
- the whole New Session screen read as a stream of success events. Brand blue keeps the host's
248
- achromatic chrome and still says "this is DeepSeek Harness data".
86
+ Refresh the page and open a new session.
249
87
 
250
- Cells are square (`aspect-ratio: 1`) with 2px corners and a 3px gap; hovering scales a cell to
251
- 128% with an outline and opens a card with the date and the current metric's value (no native `title`).
88
+ ## Settings
252
89
 
253
- ## Development
90
+ **Settings → Activity**:
254
91
 
255
- ```bash
256
- npm run verify # seven offline, dependency-free checks
257
- npm run verify:strict # skip = failure (nothing skips today)
258
- ```
259
-
260
- | Script | Covers |
261
- | --- | --- |
262
- | `verify-config` | defaults, dirty-data fallback, input validation, manifest contract |
263
- | `verify-activity` | local-timezone aggregation, Monday alignment, level boundaries, generation choice, real mtime scan, 60s cache |
264
- | `verify-token-index` | zstd frame scan, usage fold rules, cross-day replacement, incremental resume, torn frames, persisted reuse |
265
- | `verify-host` | runs `apply()` for real and asserts route responses, switch semantics, config on disk |
266
- | `verify-client` | runs `apply(ctx)` for real and asserts 8 dictionaries, slot order, unregistration when off, style contract |
267
- | `verify-render` | renders the component with a mini React: metric switch, levels, progress, tooltip, styles |
268
- | `verify-placement` | fake hero DOM: portal under the headline, cleanup on unmount, fallback when the mount point is missing |
269
-
270
- ## Limitations (v0.2)
92
+ - **Show the activity overview** — on by default
93
+ - **Show the session heat map** — on by default
94
+ - **Default metric** — whether the heat map opens on sessions or tokens
271
95
 
272
- - Sessions count by mtime: a session with hundreds of turns still counts as one session that day.
273
- - The token index takes ~20s to build the first time (depends on history size); progress is shown
274
- meanwhile, and later updates are incremental.
275
- - Token level thresholds (10M/50M/150M/500M per day) are fixed values calibrated on one heavily-used
276
- machine. Usage profiles that differ by orders of magnitude will see a skewed histogram; there is no
277
- per-user quantile adaptation yet.
278
- - No per-project / per-model breakdown, no separate report page.
279
- - No sidebar icon, no chart library.
96
+ The two switches are independent; either card can be turned off alone. Turning one
97
+ off does no computation and frees the space. Changes apply immediately, no restart.
280
98
 
281
99
  ## Privacy
282
100
 
283
- Everything is local. The plugin reads **mtimes** under `<DSH_HOME>/sessions`; for the token view it
284
- decompresses session logs locally and extracts only the `usage` counters — it never uploads anything,
285
- never parses or stores conversation text, and the index only records how many tokens a day had.
101
+ Everything stays local.
102
+
103
+ The plugin reads timestamps from your local session files; when token and model data
104
+ are needed it **decompresses those logs locally** and takes only usage counts and
105
+ model names. Nothing is uploaded, and no conversation text is parsed or stored.
286
106
 
287
107
  ## License
288
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pulse-overview",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "为 DeepSeek Harness 的会话欢迎页添加活动概览与最近一年的会话 / Token 活跃度热力图。",
5
5
  "icon": "./assets/icon.svg",
6
6
  "keywords": [
@@ -174,7 +174,9 @@ check('包名与版本', () => {
174
174
  // 包名是 dsh-pulse-overview 而不是 dsh-pulse:npm 上的 dsh-pulse 已被他人占用
175
175
  // (lightgrey/dsh-pulse,功能重叠)。仓库名仍是 dsh-pulse —— 这个不一致是刻意的。
176
176
  assert.equal(pkg.name, 'dsh-pulse-overview')
177
- assert.equal(pkg.version, '0.3.0')
177
+ // 版本号只断言形状,不钉死具体值 —— 钉死会让每次发版都得改测试,
178
+ // 而「版本号是不是 semver」才是真正值得守的约束(npm 拒绝非法版本号)。
179
+ assert.match(pkg.version, /^\d+\.\d+\.\d+$/)
178
180
  })
179
181
 
180
182
  check('入口是 index.mjs(ESM)', () => {