dsh-wakatime 1.2.2 → 1.2.3
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 +4 -3
- package/README.md +4 -3
- package/lib/user-agent.js +1 -1
- package/lib/wakatime.d.ts +9 -0
- package/lib/wakatime.js +37 -0
- 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
|
|
|
@@ -42,6 +42,7 @@ All four panels are fed by this plugin:
|
|
|
42
42
|
| **Editors** | Derived from the heartbeat `User-Agent`, so "working in DSH" shows up as its own editor |
|
|
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
|
+
| **Machines** | The `X-Machine-Name` HTTP header (URL-encoded value). The heartbeat JSON has **no** `machine_name` field — this is the same channel the official CLI uses |
|
|
45
46
|
|
|
46
47
|
> **Why the model token comes first (instead of copying the official template)**
|
|
47
48
|
>
|
|
@@ -52,8 +53,8 @@ All four panels are fed by this plugin:
|
|
|
52
53
|
> | UA | ai_model | ai_model_version | editor |
|
|
53
54
|
> |---|---|---|---|
|
|
54
55
|
> | `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.
|
|
56
|
-
> | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.
|
|
56
|
+
> | `deepseek/4.1-flash-eco dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.3` | ✅ `DeepSeek` | `4.1-flash-eco` | ✅ `Dsh` |
|
|
57
|
+
> | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.3` (when the model is not recognised) | ✅ `None` | None | ✅ `Dsh` |
|
|
57
58
|
>
|
|
58
59
|
> 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.
|
|
59
60
|
|
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
|
|
|
@@ -42,6 +42,7 @@ DSH 里的活动原本不会出现在 WakaTime 上:[WakaTime](https://wakatime
|
|
|
42
42
|
| **Editors** | 由心跳的 `User-Agent` 推出,所以「在 DSH 里干活」在面板上单独成了一类 |
|
|
43
43
|
| **Operating Systems** | 同样来自 `User-Agent` 的括号段 `(linux-<内核>-<arch>)`(实测服务端对括号段做子串识别,不依赖 `wakatime/` 头) |
|
|
44
44
|
| **Models** | 同样来自 `User-Agent` 里的模型 token(如 `deepseek/4.1-flash-eco`)——WakaTime **没有** `ai_model` 心跳字段,这个面板只认 UA |
|
|
45
|
+
| **Machines** | HTTP 头 `X-Machine-Name`(值 URL 转义)。心跳 JSON 里**没有** `machine_name` 字段,这是官方 CLI 用的同一个通道 |
|
|
45
46
|
|
|
46
47
|
> **为什么 UA 的模型 token 在最前面(而不是照抄官方模板)**
|
|
47
48
|
>
|
|
@@ -52,8 +53,8 @@ DSH 里的活动原本不会出现在 WakaTime 上:[WakaTime](https://wakatime
|
|
|
52
53
|
> | UA | ai_model | ai_model_version | editor |
|
|
53
54
|
> |---|---|---|---|
|
|
54
55
|
> | `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.
|
|
56
|
-
> | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.
|
|
56
|
+
> | `deepseek/4.1-flash-eco dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.3` | ✅ `DeepSeek` | `4.1-flash-eco` | ✅ `Dsh` |
|
|
57
|
+
> | `dsh/0.2.2-rc.5 (linux-…) node/… dsh-wakatime/1.2.3`(模型识别不出时) | ✅ `None` | None | ✅ `Dsh` |
|
|
57
58
|
>
|
|
58
59
|
> 代价是没有 `wakatime/` 头。实测括号段仍被服务端识别(它对 `(linux-…-x86_64)` 做子串匹配),`editor` 则靠在末尾放 `dsh-wakatime/<ver>` 才回落成 `Dsh`——末尾那个 token **不能省**。OS 名用小写、arch 用 `x86_64` / `aarch64`,取自本账号里官方 CLI 的 50 条 UA 样本。
|
|
59
60
|
|
package/lib/user-agent.js
CHANGED
|
@@ -270,7 +270,7 @@ export function buildUserAgent(parts) {
|
|
|
270
270
|
* 源码里**绝不手写版本号**——UA 曾长期停在 `1.0.0`,而包已经发到 `1.1.0`,
|
|
271
271
|
* 就是手写造成的脱钩。未注入时(vitest 直接跑源码)为 undefined。
|
|
272
272
|
*/
|
|
273
|
-
const INJECTED_PLUGIN_VERSION = "1.2.
|
|
273
|
+
const INJECTED_PLUGIN_VERSION = "1.2.3";
|
|
274
274
|
/** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
|
|
275
275
|
export function pluginVersion() {
|
|
276
276
|
return typeof INJECTED_PLUGIN_VERSION === 'string' && INJECTED_PLUGIN_VERSION !== ''
|
package/lib/wakatime.d.ts
CHANGED
|
@@ -132,6 +132,8 @@ export declare class WakaTimeClient {
|
|
|
132
132
|
private apiKey;
|
|
133
133
|
private baseUrl;
|
|
134
134
|
private userAgent;
|
|
135
|
+
/** 本机名(Machines 面板的归属来源,经 `X-Machine-Name` 头发送)。 */
|
|
136
|
+
private machineName;
|
|
135
137
|
private retryAfter;
|
|
136
138
|
private authFailRetryAfter;
|
|
137
139
|
private proxyUrl;
|
|
@@ -162,6 +164,13 @@ export declare class WakaTimeClient {
|
|
|
162
164
|
* @returns 形如 `经代理 http://host:port(来源:设置页)` 或 `直连(来源:无配置)`。
|
|
163
165
|
*/
|
|
164
166
|
describeProxy(): string;
|
|
167
|
+
/**
|
|
168
|
+
* `X-Machine-Name` 头;机器名取不到时返回空对象(不发这个头)。
|
|
169
|
+
*
|
|
170
|
+
* 值必须 URL 转义:官方 CLI 用 `url.QueryEscape`,主机名里的非 ASCII
|
|
171
|
+
* 字符若不转义会直接破坏请求头。
|
|
172
|
+
*/
|
|
173
|
+
private machineHeader;
|
|
165
174
|
sendHeartbeat(payload: WakaTimeHeartbeat): Promise<HeartbeatSendResult>;
|
|
166
175
|
sendHeartbeats(payloads: WakaTimeHeartbeat[]): Promise<HeartbeatSendResult>;
|
|
167
176
|
/**
|
package/lib/wakatime.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { WakaTimeError, WakaTimeAuthError, WakaTimeRateLimitError } from './types.js';
|
|
2
2
|
import { currentUserAgent } from './user-agent.js';
|
|
3
|
+
import { hostname as osHostname } from 'node:os';
|
|
3
4
|
/** 默认请求超时:挂起的服务端不能让 flush 永不返回、并发请求越积越多。 */
|
|
4
5
|
const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
+
/**
|
|
7
|
+
* 取本机名,供 `X-Machine-Name` 头使用。
|
|
8
|
+
*
|
|
9
|
+
* 官方 CLI 在 `pkg/api/option.go` 的 `WithHostname` 里做同样的事:
|
|
10
|
+
* 把 hostname URL 转义后塞进 `X-Machine-Name` 头。**心跳 JSON 结构里没有
|
|
11
|
+
* machine_name 字段**(`heartbeat.go` 里零命中),所以这是唯一的通道。
|
|
12
|
+
* 取不到就返回空串——调用方据此不发这个头,让服务端继续显示 Unknown
|
|
13
|
+
* Hostname,而不是发一个空字符串上去。
|
|
14
|
+
*/
|
|
15
|
+
function safeHostname() {
|
|
16
|
+
try {
|
|
17
|
+
return osHostname() ?? '';
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
5
23
|
/**
|
|
6
24
|
* 把 fetch 抛出的错误展开成一行可诊断的文本。
|
|
7
25
|
*
|
|
@@ -211,6 +229,8 @@ export class WakaTimeClient {
|
|
|
211
229
|
apiKey;
|
|
212
230
|
baseUrl;
|
|
213
231
|
userAgent;
|
|
232
|
+
/** 本机名(Machines 面板的归属来源,经 `X-Machine-Name` 头发送)。 */
|
|
233
|
+
machineName;
|
|
214
234
|
retryAfter = 0;
|
|
215
235
|
authFailRetryAfter = 0;
|
|
216
236
|
proxyUrl;
|
|
@@ -227,6 +247,10 @@ export class WakaTimeClient {
|
|
|
227
247
|
// HTTP 头只是兜底:真正的归属信息逐条写在心跳的 `user_agent` 字段里
|
|
228
248
|
// (批量上报时一个头无法区分不同会话/不同模型的条目)。构造规则见 user-agent.ts。
|
|
229
249
|
this.userAgent = currentUserAgent();
|
|
250
|
+
// 机器名走 HTTP 头 `X-Machine-Name`(官方 CLI 的 WithHostname 就是这么做的),
|
|
251
|
+
// 心跳结构里没有 machine_name 字段。没有这个头,Machines 面板永远是
|
|
252
|
+
// `Unknown Hostname`。取不到就不发,让服务端继续显示 Unknown 而不是发空串。
|
|
253
|
+
this.machineName = safeHostname();
|
|
230
254
|
const resolved = resolveProxy(process.env, config.cfg_proxy, config.proxy_url);
|
|
231
255
|
this.proxyUrl = resolved.proxy;
|
|
232
256
|
this.noProxy = usableNoProxy(config.no_proxy) ?? process.env.NO_PROXY ?? '';
|
|
@@ -281,6 +305,17 @@ export class WakaTimeClient {
|
|
|
281
305
|
// 必须是脱敏后的地址:这里会进宿主日志,也会被用户贴进 issue。
|
|
282
306
|
return this.proxyUrl === null ? `直连(来源:${sourceLabel})` : `经代理 ${maskProxyUrl(this.proxyUrl)}(来源:${sourceLabel})`;
|
|
283
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* `X-Machine-Name` 头;机器名取不到时返回空对象(不发这个头)。
|
|
310
|
+
*
|
|
311
|
+
* 值必须 URL 转义:官方 CLI 用 `url.QueryEscape`,主机名里的非 ASCII
|
|
312
|
+
* 字符若不转义会直接破坏请求头。
|
|
313
|
+
*/
|
|
314
|
+
machineHeader() {
|
|
315
|
+
if (this.machineName === '')
|
|
316
|
+
return {};
|
|
317
|
+
return { 'X-Machine-Name': encodeURIComponent(this.machineName) };
|
|
318
|
+
}
|
|
284
319
|
async sendHeartbeat(payload) {
|
|
285
320
|
return this.sendHeartbeats([payload]);
|
|
286
321
|
}
|
|
@@ -320,6 +355,7 @@ export class WakaTimeClient {
|
|
|
320
355
|
'Authorization': `Basic ${btoa(this.apiKey + ':')}`,
|
|
321
356
|
'Content-Type': 'application/json',
|
|
322
357
|
'User-Agent': batchUserAgent ?? this.userAgent,
|
|
358
|
+
...this.machineHeader(),
|
|
323
359
|
},
|
|
324
360
|
body,
|
|
325
361
|
signal: AbortSignal.timeout(this.requestTimeoutMs),
|
|
@@ -472,6 +508,7 @@ export class WakaTimeClient {
|
|
|
472
508
|
'Content-Type': 'application/json',
|
|
473
509
|
'Content-Length': String(Buffer.byteLength(body)),
|
|
474
510
|
'User-Agent': userAgent,
|
|
511
|
+
...this.machineHeader(),
|
|
475
512
|
'Host': parsed.host,
|
|
476
513
|
},
|
|
477
514
|
socket,
|