dsh-wakatime 1.2.0 → 1.2.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.en.md +2 -2
- package/README.md +2 -2
- package/lib/user-agent.js +13 -10
- 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,7 @@ 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.
|
|
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.
|
|
47
47
|
|
|
48
48
|
## Install
|
|
49
49
|
|
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
|
|
|
@@ -43,7 +43,7 @@ DSH 里的活动原本不会出现在 WakaTime 上:[WakaTime](https://wakatime
|
|
|
43
43
|
| **Operating Systems** | 同样来自 `User-Agent` 的括号段 `(linux-<内核>-<arch>)` |
|
|
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.
|
|
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` 表。
|
|
47
47
|
|
|
48
48
|
## 安装
|
|
49
49
|
|
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;
|
|
@@ -255,7 +258,7 @@ export function buildUserAgent(parts) {
|
|
|
255
258
|
* 源码里**绝不手写版本号**——UA 曾长期停在 `1.0.0`,而包已经发到 `1.1.0`,
|
|
256
259
|
* 就是手写造成的脱钩。未注入时(vitest 直接跑源码)为 undefined。
|
|
257
260
|
*/
|
|
258
|
-
const INJECTED_PLUGIN_VERSION = "1.2.
|
|
261
|
+
const INJECTED_PLUGIN_VERSION = "1.2.1";
|
|
259
262
|
/** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
|
|
260
263
|
export function pluginVersion() {
|
|
261
264
|
return typeof INJECTED_PLUGIN_VERSION === 'string' && INJECTED_PLUGIN_VERSION !== ''
|