dsh-wakatime 1.2.1 → 1.2.2

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.en.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [中文](./README.md) | **English**
8
8
 
9
- [![version](https://img.shields.io/badge/version-1.2.1-0EA5E9)](https://github.com/dsh-plugin-collection/dsh-wakatime)
9
+ [![version](https://img.shields.io/badge/version-1.2.2-0EA5E9)](https://github.com/dsh-plugin-collection/dsh-wakatime)
10
10
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
11
11
  [![DSH](https://img.shields.io/badge/DeepSeek%20Harness-0.2.2--rc.1-4D6BFE)](https://github.com/deepseek-ai/deepseek-harness)
12
12
 
@@ -43,7 +43,19 @@ All four panels are fed by this plugin:
43
43
  | **Operating Systems** | Also from the `User-Agent` parenthesised section `(linux-<kernel>-<arch>)` |
44
44
  | **Models** | Also from the model token inside `User-Agent` (e.g. `deepseek/4.1-flash-eco`) — WakaTime has **no** `ai_model` heartbeat field; this panel reads the UA only |
45
45
 
46
- > **Why the UA follows the official template**: the Editors, Operating Systems and Models panels are all derived from `User-Agent`. This plugin emits `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <model?> <editor>`; the model comes from the host message's `message.source.model` and is normalised with the official `aiModelUserAgentToken` rules. A real sample: `wakatime/1.2.1 (linux-6.18.58-x86_64) node/24.22.0 deepseek/4.1-flash-eco dsh/0.2.2-rc.5`. When a model id has no recognisable version segment (`dsh-opendesign-go`), that part is omitted rather than polluting the `user_agents` table.
46
+ > **Why the model token comes first (instead of copying the official template)**
47
+ >
48
+ > The official `wakatime-cli` template is `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <plugin>`, and this plugin copied it at first. But the `user_agents` endpoint returns **the server's parse result for each UA** (`ai_model` / `ai_model_version` / `editor`), and after testing a dozen variants the finding is: **when a UA starts with `wakatime/<ver>`, the server treats wakatime itself as the model** — `ai_model='Wakatime'`, `ai_model_version=<plugin version>` — and ignores the real model token after it. Copying the official template therefore always makes the Models panel show `Wakatime`.
49
+ >
50
+ > Putting the model token first is the shape that measurably works:
51
+ >
52
+ > | UA | ai_model | ai_model_version | editor |
53
+ > |---|---|---|---|
54
+ > | `wakatime/1.2.1 (…) node/… deepseek/… dsh/…` | ❌ `Wakatime` | `1.2.1` | None |
55
+ > | `deepseek/4.1-flash-eco dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.2` | ✅ `DeepSeek` | `4.1-flash-eco` | ✅ `Dsh` |
56
+ > | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.2` (when the model is not recognised) | ✅ `None` | None | ✅ `Dsh` |
57
+ >
58
+ > The cost is losing the `wakatime/` header. The parenthesised section is still recognised (the server substring-matches `(linux-…-x86_64)`), but `editor` only resolves to `Dsh` because of the trailing `dsh-wakatime/<ver>` token — **that token cannot be dropped**. OS names are lowercase and arch uses `x86_64` / `aarch64`, taken from 50 real official-CLI UAs in this account.
47
59
 
48
60
  ## Install
49
61
 
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  **中文** | [English](./README.en.md)
8
8
 
9
- [![version](https://img.shields.io/badge/version-1.2.1-0EA5E9)](https://github.com/dsh-plugin-collection/dsh-wakatime)
9
+ [![version](https://img.shields.io/badge/version-1.2.2-0EA5E9)](https://github.com/dsh-plugin-collection/dsh-wakatime)
10
10
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
11
11
  [![DSH](https://img.shields.io/badge/DeepSeek%20Harness-0.2.2--rc.1-4D6BFE)](https://github.com/deepseek-ai/deepseek-harness)
12
12
 
@@ -40,10 +40,22 @@ DSH 里的活动原本不会出现在 WakaTime 上:[WakaTime](https://wakatime
40
40
  | **Categories** | 工具调用映射(见[类别映射](#类别映射))——`coding` / `browsing` / `researching` 等 |
41
41
  | **Languages** | 按文件扩展名推断 |
42
42
  | **Editors** | 由心跳的 `User-Agent` 推出,所以「在 DSH 里干活」在面板上单独成了一类 |
43
- | **Operating Systems** | 同样来自 `User-Agent` 的括号段 `(linux-<内核>-<arch>)` |
43
+ | **Operating Systems** | 同样来自 `User-Agent` 的括号段 `(linux-<内核>-<arch>)`(实测服务端对括号段做子串识别,不依赖 `wakatime/` 头) |
44
44
  | **Models** | 同样来自 `User-Agent` 里的模型 token(如 `deepseek/4.1-flash-eco`)——WakaTime **没有** `ai_model` 心跳字段,这个面板只认 UA |
45
45
 
46
- > **为什么 UA 要照官方模板拼**:Editors / Operating Systems / Models 三个面板都从 `User-Agent` 解析。本插件按 `wakatime-cli` 的模板 `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <model?> <editor>` 生成;模型取自宿主消息的 `message.source.model`,并按官方的 `aiModelUserAgentToken` 规则归一化。一条实测样本:`wakatime/1.2.1 (linux-6.18.58-x86_64) node/24.22.0 deepseek/4.1-flash-eco dsh/0.2.2-rc.5`。模型识别不出时该段省略,不会把 `dsh-opendesign-go` 这类没有版本号的 id 硬塞进去污染 `user_agents` 表。
46
+ > **为什么 UA 的模型 token 在最前面(而不是照抄官方模板)**
47
+ >
48
+ > 官方 `wakatime-cli` 的模板是 `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <plugin>`,本插件最初也照抄了。但 `user_agents` 端点会返回**服务端对每条 UA 的解析结果**(`ai_model` / `ai_model_version` / `editor`),实测十几种变体后发现:**UA 以 `wakatime/<ver>` 开头时,服务端会把 wakatime 自己当成模型**——`ai_model='Wakatime'`、`ai_model_version=<插件版本>`,后面真正的模型 token 全被忽略。照抄官方模板必然得到 Models 面板显示 `Wakatime` 的结果。
49
+ >
50
+ > 把模型 token 提到首位则是实测可用的形状:
51
+ >
52
+ > | UA | ai_model | ai_model_version | editor |
53
+ > |---|---|---|---|
54
+ > | `wakatime/1.2.1 (…) node/… deepseek/… dsh/…` | ❌ `Wakatime` | `1.2.1` | None |
55
+ > | `deepseek/4.1-flash-eco dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.2` | ✅ `DeepSeek` | `4.1-flash-eco` | ✅ `Dsh` |
56
+ > | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.2`(模型识别不出时) | ✅ `None` | None | ✅ `Dsh` |
57
+ >
58
+ > 代价是没有 `wakatime/` 头。实测括号段仍被服务端识别(它对 `(linux-…-x86_64)` 做子串匹配),`editor` 则靠在末尾放 `dsh-wakatime/<ver>` 才回落成 `Dsh`——末尾那个 token **不能省**。OS 名用小写、arch 用 `x86_64` / `aarch64`,取自本账号里官方 CLI 的 50 条 UA 样本。
47
59
 
48
60
  ## 安装
49
61
 
@@ -75,31 +75,37 @@ export interface UserAgentParts {
75
75
  kernelRelease?: string;
76
76
  }
77
77
  /**
78
- * 按官方模板拼 User-Agent。
78
+ * 拼 User-Agent。
79
79
  *
80
- * 形状与 `wakatime-cli` 的 `UserAgent()`(以及注入模型后的
81
- * `aiUserAgentWithModelTokenAndEditor`)输出同构:
80
+ * 形状(**实测形状**,不是照抄官方模板,原因见下):
82
81
  *
83
82
  * ```
84
- * wakatime/<pluginVer> (<OS>-<core>-<platform>) <runtime> <modelToken?> <editorChain>
83
+ * <modelToken|dsh/0.0.0> dsh/<hostVer> (<OS>-<core>-<platform>) node/<ver> dsh-wakatime/<pluginVer>
85
84
  * ```
86
85
  *
87
- * 逐项对齐官方模板 `"wakatime/%s (%s-%s-%s) %s %s"`:
88
- *
89
- * - **`wakatime/<本插件版本>`**:这个前缀是硬要求(`splitUserAgent` 靠它切
90
- * header/products;没有它,含 OS 的括号段会被当 products,OS 就解析不出来)。
91
- * 填本插件版本而非宿主版本,`user_agents` 里才能反查是哪个插件发的。
92
- * - **括号段 `OS-core-platform`**:官方三项依次是 OS 名、CPU 核信息、平台架构;
93
- * 只有 OS 参与面板归类,后两项仅用于区分机器,这里用内核 release 与 Node
94
- * 版本充当(不引入新的系统信息采集)。
95
- * - **products 段**:官方是 `<runtime> <plugin 链>`;模型 token 由
96
- * `userAgentWithPrependedAgent` **前置**到 products 首位,故这里同样放在
97
- * runtime 之前。识别不出的模型一律不拼——发出一个解析不了的 token 只会
98
- * 污染 `user_agents` 表,不会点亮任何面板。
99
- *
100
- * 关于验证边界:服务端解析 UA 的代码不开源,且 `user_agents` 读端点对本插件
101
- * 的 key 返回 403,**无法在本机实测「面板是否点亮」**。因此这里只保证「与官方
102
- * CLI 产出的形状一致」,而不是「已验证服务端会按预期归类」。
86
+ * ## 为什么不是官方模板
87
+ *
88
+ * 官方 `wakatime-cli` 的模板是 `wakatime/%s (%s-%s-%s) %s %s`,本插件最初也照抄了
89
+ * 它。但 `user_agents` 端点会返回**服务端对每条 UA 的解析结果**(`ai_model` /
90
+ * `ai_model_version` / `editor`),实测十几种变体后得到两条硬结论:
91
+ *
92
+ * 1. **UA 以 `wakatime/<ver>` 开头时,服务端把 wakatime 自己当成模型**:
93
+ * `ai_model='Wakatime'`、`ai_model_version=<插件版本>`,后面的模型 token 全被
94
+ * 忽略。照抄官方模板必然得到这个结果——Models 面板显示的会是 `Wakatime`。
95
+ * 2. **模型 token 放在首位才能被识别**:
96
+ * `deepseek/4.1-flash-eco dsh/<v> (linux-…) node/<v> dsh-wakatime/<v>`
97
+ * → `ai_model='DeepSeek'`、`ai_model_version='4.1-flash-eco'`、`editor='Dsh'`。
98
+ *
99
+ * 代价:没有 `wakatime/` 头,官方 `splitUserAgent` 切不出 header;但实测括号段
100
+ * 仍被服务端识别(它对 `(linux-…-x86_64)` 做子串匹配),`editor` 则要靠在末尾
101
+ * 放 `dsh-wakatime/<ver>` 才回落成 `Dsh`——所以末尾那个 token **不能省**。
102
+ *
103
+ * ## 无模型时
104
+ *
105
+ * 模型识别不出(如 `dsh-opendesign-go` 没有版本号)时,首位放 `dsh/<hostVer>`:
106
+ * 宁可让这条心跳不计入任何模型,也不发一个解析不了的 token(那只会往
107
+ * `user_agents` 表里灌垃圾条目)。宿主版本探测不到时用 `0.0.0` 占位——它必须
108
+ * 占住首位(否则括号段会落到首位、被当成模型名),又明显不是真版本号。
103
109
  *
104
110
  * @param parts - 见 {@link UserAgentParts}。
105
111
  * @returns 单行 UA 字符串。
package/lib/user-agent.js CHANGED
@@ -199,31 +199,37 @@ export function currentUserAgent(model) {
199
199
  });
200
200
  }
201
201
  /**
202
- * 按官方模板拼 User-Agent。
202
+ * 拼 User-Agent。
203
203
  *
204
- * 形状与 `wakatime-cli` 的 `UserAgent()`(以及注入模型后的
205
- * `aiUserAgentWithModelTokenAndEditor`)输出同构:
204
+ * 形状(**实测形状**,不是照抄官方模板,原因见下):
206
205
  *
207
206
  * ```
208
- * wakatime/<pluginVer> (<OS>-<core>-<platform>) <runtime> <modelToken?> <editorChain>
207
+ * <modelToken|dsh/0.0.0> dsh/<hostVer> (<OS>-<core>-<platform>) node/<ver> dsh-wakatime/<pluginVer>
209
208
  * ```
210
209
  *
211
- * 逐项对齐官方模板 `"wakatime/%s (%s-%s-%s) %s %s"`:
210
+ * ## 为什么不是官方模板
212
211
  *
213
- * - **`wakatime/<本插件版本>`**:这个前缀是硬要求(`splitUserAgent` 靠它切
214
- * header/products;没有它,含 OS 的括号段会被当 products,OS 就解析不出来)。
215
- * 填本插件版本而非宿主版本,`user_agents` 里才能反查是哪个插件发的。
216
- * - **括号段 `OS-core-platform`**:官方三项依次是 OS 名、CPU 核信息、平台架构;
217
- * 只有 OS 参与面板归类,后两项仅用于区分机器,这里用内核 release 与 Node
218
- * 版本充当(不引入新的系统信息采集)。
219
- * - **products 段**:官方是 `<runtime> <plugin 链>`;模型 token 由
220
- * `userAgentWithPrependedAgent` **前置**到 products 首位,故这里同样放在
221
- * runtime 之前。识别不出的模型一律不拼——发出一个解析不了的 token 只会
222
- * 污染 `user_agents` 表,不会点亮任何面板。
212
+ * 官方 `wakatime-cli` 的模板是 `wakatime/%s (%s-%s-%s) %s %s`,本插件最初也照抄了
213
+ * 它。但 `user_agents` 端点会返回**服务端对每条 UA 的解析结果**(`ai_model` /
214
+ * `ai_model_version` / `editor`),实测十几种变体后得到两条硬结论:
223
215
  *
224
- * 关于验证边界:服务端解析 UA 的代码不开源,且 `user_agents` 读端点对本插件
225
- * 的 key 返回 403,**无法在本机实测「面板是否点亮」**。因此这里只保证「与官方
226
- * CLI 产出的形状一致」,而不是「已验证服务端会按预期归类」。
216
+ * 1. **UA 以 `wakatime/<ver>` 开头时,服务端把 wakatime 自己当成模型**:
217
+ * `ai_model='Wakatime'`、`ai_model_version=<插件版本>`,后面的模型 token 全被
218
+ * 忽略。照抄官方模板必然得到这个结果——Models 面板显示的会是 `Wakatime`。
219
+ * 2. **模型 token 放在首位才能被识别**:
220
+ * `deepseek/4.1-flash-eco dsh/<v> (linux-…) node/<v> dsh-wakatime/<v>`
221
+ * → `ai_model='DeepSeek'`、`ai_model_version='4.1-flash-eco'`、`editor='Dsh'`。
222
+ *
223
+ * 代价:没有 `wakatime/` 头,官方 `splitUserAgent` 切不出 header;但实测括号段
224
+ * 仍被服务端识别(它对 `(linux-…-x86_64)` 做子串匹配),`editor` 则要靠在末尾
225
+ * 放 `dsh-wakatime/<ver>` 才回落成 `Dsh`——所以末尾那个 token **不能省**。
226
+ *
227
+ * ## 无模型时
228
+ *
229
+ * 模型识别不出(如 `dsh-opendesign-go` 没有版本号)时,首位放 `dsh/<hostVer>`:
230
+ * 宁可让这条心跳不计入任何模型,也不发一个解析不了的 token(那只会往
231
+ * `user_agents` 表里灌垃圾条目)。宿主版本探测不到时用 `0.0.0` 占位——它必须
232
+ * 占住首位(否则括号段会落到首位、被当成模型名),又明显不是真版本号。
227
233
  *
228
234
  * @param parts - 见 {@link UserAgentParts}。
229
235
  * @returns 单行 UA 字符串。
@@ -234,22 +240,28 @@ export function buildUserAgent(parts) {
234
240
  const nodeVersion = parts.nodeVersion ?? process.versions.node;
235
241
  const arch = archName(parts.arch ?? process.arch);
236
242
  const os = osName(platform);
237
- // header 段 = `wakatime/<ver> (<OS>-…>) <runtime>`;官方 splitUserAgent 把
238
- // 括号后第一个空格前的内容归入 header,其余才是 products,所以 runtime 必须
239
- // 紧跟括号,不能落进 products。
240
- const header = `wakatime/${parts.pluginVersion} (${os}-${kernel}-${arch}) node/${nodeVersion}`;
241
- // products = [模型 token?] + editor 链。模型放首位是照官方
242
- // `userAgentWithPrependedAgent` 的输出顺序(模型 → editor → 其余)。
243
- // 探测不到宿主版本时省略 `dsh/` 段:宁可少一个 token,也不发一个编出来的版本
244
- // (Editors 面板此时回退到 `node/…`,仍能归类,不会污染 user_agents 表)。
245
- const products = [];
243
+ // 宿主版本探测不到时用 `0.0.0`:必须占住首 token 的位置(否则括号段会落到
244
+ // 首位、被服务端当成模型名),同时它明显不是真实版本,不会冒充具体版本号。
245
+ const host = parts.hostVersion === '' ? '0.0.0' : parts.hostVersion;
246
246
  const token = parts.model === undefined ? '' : aiModelToken(parts.model, parts.complexity ?? '');
247
- if (token !== '')
248
- products.push(token);
249
- if (parts.hostVersion !== '')
250
- products.push(`dsh/${parts.hostVersion}`);
251
- // products 可能为空(探测不到宿主版本且模型识别不出)——此时不能留尾随空格。
252
- return products.length === 0 ? header : `${header} ${products.join(' ')}`;
247
+ // ── 为什么模型在最前面、而不是官方那样跟在 `wakatime/` 头之后 ──
248
+ //
249
+ // 实测(`user_agents` 端点会返回服务端解析结果,见 1.2.2 的 CHANGELOG):
250
+ // 只要串以 `wakatime/<ver>` 开头,服务端就把**那个 wakatime 自己**当成模型
251
+ // (`ai_model='Wakatime'`、`ai_model_version=<插件版本>`),后面的模型 token
252
+ // 一律忽略。这正是面板里出现 `Wakatime 100%` 的原因。
253
+ //
254
+ // 把模型 token 提到首位则是实测可用的形状:
255
+ // deepseek/4.1-flash-eco dsh/0.2.2-rc.5 (linux-…) node/24.22.0 dsh-wakatime/1.2.2
256
+ // → ai_model='DeepSeek' ai_model_version='4.1-flash-eco' editor='Dsh'
257
+ // 代价是丢了 `wakatime/` 头——官方 `splitUserAgent` 靠它切 header/products,
258
+ // 没有它 OS 括号段理论上解析不到。**但实测括号段仍在**(服务端自己对
259
+ // `(linux-…-x86_64)` 做子串识别),代价是 `editor` 字段要靠末尾的
260
+ // `dsh-wakatime/<ver>` 才回落成 `Dsh`——所以这个 token 不能省。
261
+ const head = token === '' ? `dsh/${host}` : `${token} dsh/${host}`;
262
+ const system = `(${os}-${kernel}-${arch})`;
263
+ const tail = `node/${nodeVersion} dsh-wakatime/${parts.pluginVersion}`;
264
+ return `${head} ${system} ${tail}`;
253
265
  }
254
266
  /**
255
267
  * 构建期注入的本插件版本占位。
@@ -258,7 +270,7 @@ export function buildUserAgent(parts) {
258
270
  * 源码里**绝不手写版本号**——UA 曾长期停在 `1.0.0`,而包已经发到 `1.1.0`,
259
271
  * 就是手写造成的脱钩。未注入时(vitest 直接跑源码)为 undefined。
260
272
  */
261
- const INJECTED_PLUGIN_VERSION = "1.2.1";
273
+ const INJECTED_PLUGIN_VERSION = "1.2.2";
262
274
  /** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
263
275
  export function pluginVersion() {
264
276
  return typeof INJECTED_PLUGIN_VERSION === 'string' && INJECTED_PLUGIN_VERSION !== ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-wakatime",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "WakaTime heartbeat reporting for DeepSeek Harness",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",