dsh-wakatime 1.2.0 → 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 +14 -2
- package/README.md +15 -3
- package/lib/user-agent.d.ts +26 -20
- package/lib/user-agent.js +58 -43
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[中文](./README.md) | **English**
|
|
8
8
|
|
|
9
|
-
[](https://github.com/dsh-plugin-collection/dsh-wakatime)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
[](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
|
|
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
|
-
[](https://github.com/dsh-plugin-collection/dsh-wakatime)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
[](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
|
|
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
|
|
package/lib/user-agent.d.ts
CHANGED
|
@@ -75,31 +75,37 @@ export interface UserAgentParts {
|
|
|
75
75
|
kernelRelease?: string;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* 拼 User-Agent。
|
|
79
79
|
*
|
|
80
|
-
*
|
|
81
|
-
* `aiUserAgentWithModelTokenAndEditor`)输出同构:
|
|
80
|
+
* 形状(**实测形状**,不是照抄官方模板,原因见下):
|
|
82
81
|
*
|
|
83
82
|
* ```
|
|
84
|
-
*
|
|
83
|
+
* <modelToken|dsh/0.0.0> dsh/<hostVer> (<OS>-<core>-<platform>) node/<ver> dsh-wakatime/<pluginVer>
|
|
85
84
|
* ```
|
|
86
85
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
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
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
*
|
|
27
27
|
* @module dsh-wakatime/user-agent
|
|
28
28
|
*/
|
|
29
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
30
|
+
import { dirname, join } from 'node:path';
|
|
29
31
|
import { release } from 'node:os';
|
|
30
32
|
/**
|
|
31
33
|
* 官方 UA 模板里的 OS 名。
|
|
@@ -152,15 +154,16 @@ function detectHostVersionUncached() {
|
|
|
152
154
|
const entry = process.argv[1];
|
|
153
155
|
if (typeof entry !== 'string' || entry === '')
|
|
154
156
|
return '';
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
// 本插件是 ESM(package.json `"type": "module"`):这里**不能**写 `require`。
|
|
158
|
+
// 实测踩过——TypeScript 不报错、tsc 原样保留、单测(vite 转译)也能过,
|
|
159
|
+
// 但宿主进程里 `typeof require === 'undefined'`,调用直接抛 ReferenceError,
|
|
160
|
+
// 被外层 catch 吞成空串:活心跳的 UA 里就少了 `dsh/<ver>` 这一段。
|
|
161
|
+
// 顶部的静态 import 在 ESM 下才是有效的。
|
|
162
|
+
let dir = dirname(realpathSync(entry));
|
|
160
163
|
for (let depth = 0; depth < 8; depth += 1) {
|
|
161
|
-
const manifest =
|
|
162
|
-
if (
|
|
163
|
-
const parsed = JSON.parse(
|
|
164
|
+
const manifest = join(dir, 'package.json');
|
|
165
|
+
if (existsSync(manifest)) {
|
|
166
|
+
const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
164
167
|
if (typeof parsed === 'object' && parsed !== null) {
|
|
165
168
|
const name = parsed.name;
|
|
166
169
|
const version = parsed.version;
|
|
@@ -169,7 +172,7 @@ function detectHostVersionUncached() {
|
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
|
-
const parent =
|
|
175
|
+
const parent = dirname(dir);
|
|
173
176
|
if (parent === dir)
|
|
174
177
|
break;
|
|
175
178
|
dir = parent;
|
|
@@ -196,31 +199,37 @@ export function currentUserAgent(model) {
|
|
|
196
199
|
});
|
|
197
200
|
}
|
|
198
201
|
/**
|
|
199
|
-
*
|
|
202
|
+
* 拼 User-Agent。
|
|
200
203
|
*
|
|
201
|
-
*
|
|
202
|
-
* `aiUserAgentWithModelTokenAndEditor`)输出同构:
|
|
204
|
+
* 形状(**实测形状**,不是照抄官方模板,原因见下):
|
|
203
205
|
*
|
|
204
206
|
* ```
|
|
205
|
-
*
|
|
207
|
+
* <modelToken|dsh/0.0.0> dsh/<hostVer> (<OS>-<core>-<platform>) node/<ver> dsh-wakatime/<pluginVer>
|
|
206
208
|
* ```
|
|
207
209
|
*
|
|
208
|
-
*
|
|
210
|
+
* ## 为什么不是官方模板
|
|
209
211
|
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* - **括号段 `OS-core-platform`**:官方三项依次是 OS 名、CPU 核信息、平台架构;
|
|
214
|
-
* 只有 OS 参与面板归类,后两项仅用于区分机器,这里用内核 release 与 Node
|
|
215
|
-
* 版本充当(不引入新的系统信息采集)。
|
|
216
|
-
* - **products 段**:官方是 `<runtime> <plugin 链>`;模型 token 由
|
|
217
|
-
* `userAgentWithPrependedAgent` **前置**到 products 首位,故这里同样放在
|
|
218
|
-
* runtime 之前。识别不出的模型一律不拼——发出一个解析不了的 token 只会
|
|
219
|
-
* 污染 `user_agents` 表,不会点亮任何面板。
|
|
212
|
+
* 官方 `wakatime-cli` 的模板是 `wakatime/%s (%s-%s-%s) %s %s`,本插件最初也照抄了
|
|
213
|
+
* 它。但 `user_agents` 端点会返回**服务端对每条 UA 的解析结果**(`ai_model` /
|
|
214
|
+
* `ai_model_version` / `editor`),实测十几种变体后得到两条硬结论:
|
|
220
215
|
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
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
|
+
* 占住首位(否则括号段会落到首位、被当成模型名),又明显不是真版本号。
|
|
224
233
|
*
|
|
225
234
|
* @param parts - 见 {@link UserAgentParts}。
|
|
226
235
|
* @returns 单行 UA 字符串。
|
|
@@ -231,22 +240,28 @@ export function buildUserAgent(parts) {
|
|
|
231
240
|
const nodeVersion = parts.nodeVersion ?? process.versions.node;
|
|
232
241
|
const arch = archName(parts.arch ?? process.arch);
|
|
233
242
|
const os = osName(platform);
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
const header = `wakatime/${parts.pluginVersion} (${os}-${kernel}-${arch}) node/${nodeVersion}`;
|
|
238
|
-
// products = [模型 token?] + editor 链。模型放首位是照官方
|
|
239
|
-
// `userAgentWithPrependedAgent` 的输出顺序(模型 → editor → 其余)。
|
|
240
|
-
// 探测不到宿主版本时省略 `dsh/` 段:宁可少一个 token,也不发一个编出来的版本
|
|
241
|
-
// (Editors 面板此时回退到 `node/…`,仍能归类,不会污染 user_agents 表)。
|
|
242
|
-
const products = [];
|
|
243
|
+
// 宿主版本探测不到时用 `0.0.0`:必须占住首 token 的位置(否则括号段会落到
|
|
244
|
+
// 首位、被服务端当成模型名),同时它明显不是真实版本,不会冒充具体版本号。
|
|
245
|
+
const host = parts.hostVersion === '' ? '0.0.0' : parts.hostVersion;
|
|
243
246
|
const token = parts.model === undefined ? '' : aiModelToken(parts.model, parts.complexity ?? '');
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
|
|
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}`;
|
|
250
265
|
}
|
|
251
266
|
/**
|
|
252
267
|
* 构建期注入的本插件版本占位。
|
|
@@ -255,7 +270,7 @@ export function buildUserAgent(parts) {
|
|
|
255
270
|
* 源码里**绝不手写版本号**——UA 曾长期停在 `1.0.0`,而包已经发到 `1.1.0`,
|
|
256
271
|
* 就是手写造成的脱钩。未注入时(vitest 直接跑源码)为 undefined。
|
|
257
272
|
*/
|
|
258
|
-
const INJECTED_PLUGIN_VERSION = "1.2.
|
|
273
|
+
const INJECTED_PLUGIN_VERSION = "1.2.2";
|
|
259
274
|
/** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
|
|
260
275
|
export function pluginVersion() {
|
|
261
276
|
return typeof INJECTED_PLUGIN_VERSION === 'string' && INJECTED_PLUGIN_VERSION !== ''
|