@angelyeye/dsh-cost-tracker 1.9.4 → 1.9.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,82 @@
2
2
 
3
3
  本文件用中文记录 dsh-cost-tracker 的版本变更。
4
4
 
5
+ ## v1.9.5(2026-10-07)
6
+
7
+ **修复「桌面端(Electron 外壳)花费统计整块看板变成无样式原生控件」—— 自建 `<style>` 缺 `data-plugin` 归属标记,被 DSH 客户端模块系统认领给别的模块后在 HMR 清理时连带删除**
8
+
9
+ ### 一、根因(已复现并逐帧比对)
10
+
11
+ DSH 0.2 的客户端模块系统 `@deepseek-ai/dsh-client-modules/lib/client.js` 用两个函数管理插件样式表:
12
+
13
+ ```js
14
+ // 物化(materialize)一个模块的 factory 之后立刻盘点样式
15
+ const claimStyles = (id) => {
16
+ for (const el of document.querySelectorAll("style:not([data-plugin])")) el.setAttribute("data-plugin", id); // ← 无主的全认领
17
+ ...
18
+ };
19
+ // 某个模块被 HMR 失效 / 重载 / 剪枝时清理它的样式
20
+ function removeOwnedStyles(id) {
21
+ for (const el of document.querySelectorAll("style[data-plugin]")) if (el.getAttribute("data-plugin") === id) el.remove();
22
+ }
23
+ ```
24
+
25
+ **没打 `data-plugin` 的 `<style>` 会被「当时正在物化的那个模块」认领走。** 插件旧实现只打了
26
+ `data-plugin-css`,于是自己的样式表被登记在别的模块名下(本机实测被
27
+ `@deepseek-ai/dsh-api-remotes` 认领)。该模块一旦走到 `removeOwnedStyles(id)`
28
+ (HMR 清单里 `rev` 变化 → `updateManifest` 的 invalidate 分支、`reload()` 的非托管分支、
29
+ entry 重载、`prune()` 剪枝、factory 抛错的 catch),**连带把整块花费统计看板的 170 条
30
+ CSS 规则一起删掉**,界面退化成浏览器默认的 `<select>`/`<button>`/复选框排版:卡片边框、
31
+ 38 处自定义控件皮肤、图表网格与图例全部消失。
32
+
33
+ 为什么只在桌面端出现:Electron 外壳把 `apps/web` 的**原始 vite dist** 从
34
+ `dsh-app://app/` 提供(`resources/app.asar/dsh/node_modules/@deepseek-ai/dsh-web-frontend/dist`),
35
+ 启动图(`__ModuleLoader__` 队列引导、插件 `<link rel=preload>`、`__DSH_CONTACT_CONFIG__`)
36
+ 改由 IPC 取回 `ctx.webServer.collectIndexInjections()` 后**在运行期注入**;`dsh-client-hmr`
37
+ 随后推送的清单会让若干非托管行的 `rev` 与初始值不一致,触发上面那条清理路径。
38
+ 浏览器里的 `dsh web` 是宿主直接把启动图内联进 index.html,物化顺序不同、清单 rev 与本次启动一致,
39
+ 所以看不到 —— 这也解释了「同一个插件、同一份 client.js,网页版正常、桌面端无样式」。
40
+
41
+ **归属标记在插入前就要写好**:`claimStyles` 只认「当前是否已带 `data-plugin`」,
42
+ 插入后再补标会留下一个未被认领的窗口。
43
+
44
+ ### 二、修法(`client.js`)
45
+
46
+ 1. 新增模块 id 单一事实源 `var DSH_BUNDLE_ID = "@angelyeye/dsh-cost-tracker"`,
47
+ `__ModuleLoader__.load({ id })` 与样式归属标记共用它;
48
+ 2. `applyStyles()` 改为**先打标再插入**:
49
+ ```js
50
+ tag.setAttribute("data-plugin", DSH_BUNDLE_ID);
51
+ tag.setAttribute("data-plugin-css", DSH_STYLE_TAG_ID);
52
+ ```
53
+ 与宿主自带包的写法(`tag.dataset.plugin = "<包名>"`)逐字对齐;
54
+ 3. 顺带加上宿主同款去重护栏(`style[data-plugin-css="cost-tracker-plugin"]` 已存在就不再插第二张);
55
+ 4. 文件末尾注册名护栏保留它**刻意独立**的字面量副本(若与 `DSH_BUNDLE_ID` 同源,
56
+ 故障注入测试就永远测不出「注册名 ≠ 包名」了)。
57
+
58
+ ### 三、验证
59
+
60
+ - 真机复现(桌面端 profile 的等价宿主 + 无头 Edge/CDP,1280×820,与用户截图同视口):
61
+ - 修复前:插件样式表 `data-plugin = "@deepseek-ai/dsh-api-remotes"`(被误认领),
62
+ 模拟该模块的 `removeOwnedStyles` → 样式标签 1 张被删、看板立刻变成无样式原生控件,
63
+ 与用户截图逐项一致;
64
+ - 修复后:`data-plugin = "@angelyeye/dsh-cost-tracker"`,同样触发
65
+ `@deepseek-ai/dsh-api-remotes` 的清理 → 标签存活、`sheet.cssRules.length = 170`、
66
+ 6 张卡片仍在(`border-radius: 10px`、数值 `font-size: 24px`),截图正常。
67
+ - 极端对照:把 47 个无关模块的 168 张样式全删,本插件看板依然保持有样式。
68
+ - `test/client-render.test.js` 新增 [11](7 条断言):恰好注入一张样式表、
69
+ `data-plugin` 等于 bundle 注册名、`data-plugin-css` 保留、正文含关键规则、
70
+ 打标早于 `head.appendChild`、注册 id 与归属标记同源;
71
+ - `test/client-registration.test.js` 新增 [3b](5 条断言)钉住单一事实源与独立护栏副本,
72
+ 故障注入改为改写 `DSH_BUNDLE_ID`(同时覆盖注册与归属标记两个消费点);
73
+ - 全量 19 个测试文件通过。
74
+
75
+ ### 四、说明
76
+
77
+ - 只改客户端半端 `client.js`:不动任何计费/同步口径,HTTP 面、配置键、落盘路径、云端契约零改动;
78
+ - 客户端半端换版后**浏览器硬刷新**即可生效;另需确认宿主半端也已是新版(`index.js`/`PLUGIN_VERSION`);
79
+ - 同生态插件若自建 `<style>` 且只打 `data-plugin-css`,会踩同一个坑(本仓库的 `dshmarket` 已按约定打标)。
80
+
5
81
  ## v1.9.4(2026-09-24)
6
82
 
7
83
  **修复「配额查询不可用:火山方舟配额响应不是合法 JSON(GetCodingPlanUsage)」—— 宿主全局 fetch 被 undici 包污染后不解压 gzip,插件改为自带解压兜底**
package/README.en.md CHANGED
@@ -340,6 +340,32 @@ Example: `curl -X POST http://127.0.0.1:3080/api/cost-tracker/summary -d '{}'`
340
340
 
341
341
  > Highlights only — the full version-by-version history lives in [`CHANGELOG.md`](./CHANGELOG.md) (Chinese).
342
342
 
343
+ ### v1.9.5 (2026-10-07)
344
+
345
+ **Fix "the whole Cost dashboard renders as unstyled native controls in the Desktop (Electron) app": the plugin's own `<style>` lacked a `data-plugin` ownership tag, so another module claimed it and HMR cleanup deleted it along with its own styles**
346
+
347
+ - **Root cause (reproduced)**: DSH 0.2's `@deepseek-ai/dsh-client-modules` calls `claimStyles(ownerId)`,
348
+ which claims **every `<style>` that has no `data-plugin`** for whichever module is materializing at that
349
+ moment, and `removeOwnedStyles(id)` deletes all tags tagged `id` when that module is invalidated,
350
+ reloaded or pruned. The plugin only set `data-plugin-css`, so its stylesheet was claimed by
351
+ `@deepseek-ai/dsh-api-remotes` — and when that module's styles were torn down, all 170 dashboard CSS
352
+ rules went with it: card borders, control skins and chart grid vanished, leaving raw
353
+ `<select>`/`<button>` chrome;
354
+ - **Why Desktop only**: the Electron shell serves the raw `apps/web` vite dist from `dsh-app://app/` and
355
+ applies the boot graph (ModuleLoader bootstrap, plugin preloads, contact config) **at runtime** over IPC;
356
+ the manifest `dsh-client-hmr` then pushes gives non-managed rows a different `rev`, which is exactly what
357
+ triggers that teardown path. `dsh web` inlines the boot graph into index.html, so materialization order
358
+ and revisions differ and the bug never fires there;
359
+ - **Fix**: `client.js` now has a single source of truth `DSH_BUNDLE_ID`, and `applyStyles()` sets
360
+ `data-plugin` **before** appending the tag (byte-for-byte the convention the host's own packages use),
361
+ plus the host's duplicate-tag guard;
362
+ - **Verification**: desktop-equivalent host + headless Edge/CDP at the same viewport as the report — before
363
+ the fix the emulated teardown removed the stylesheet and the dashboard became native controls; after the
364
+ fix the tag survives, `cssRules.length = 170` and all 6 cards keep their styling. 12 new assertions in
365
+ `client-render` [11] and `client-registration` [3b]; all 19 test files pass;
366
+ - **How it takes effect**: client half only — a **hard refresh** is enough; the host half's version is
367
+ bumped to 1.9.5 as well.
368
+
343
369
  ### v1.9.4 (2026-09-24)
344
370
 
345
371
  **Fix "Volcengine Ark quota response is not valid JSON": the host's global fetch stops decompressing gzip once the `undici` package is loaded, so the plugin now decodes bodies itself**
package/README.md CHANGED
@@ -341,6 +341,28 @@ POST /api/cost-tracker/export 导出 CSV
341
341
 
342
342
  > 这里只列重要版本;逐版完整记录见 [`CHANGELOG.md`](./CHANGELOG.md)。
343
343
 
344
+ ### v1.9.5(2026-10-07)
345
+
346
+ **修复「桌面端(Electron 外壳)花费统计整块看板变成无样式原生控件」:自建 `<style>` 缺 `data-plugin` 归属标记,被别的模块认领后在 HMR 清理时连带删除**
347
+
348
+ - **根因(已复现)**:DSH 0.2 的 `@deepseek-ai/dsh-client-modules` 用
349
+ `claimStyles(ownerId)` 把**所有没带 `data-plugin` 的 `<style>` 认领给当时正在物化的模块**,
350
+ 再用 `removeOwnedStyles(id)` 在该模块 HMR 失效 / 重载 / 剪枝时整片删除。
351
+ 插件旧实现只打了 `data-plugin-css`,实测样式表被 `@deepseek-ai/dsh-api-remotes` 认领,
352
+ 该模块一被清理就带走看板的 170 条 CSS 规则 —— 卡片边框、控件皮肤、图表网格全部消失,
353
+ 界面退化成浏览器默认的 `<select>`/`<button>` 排版;
354
+ - **为什么只在桌面端**:Electron 外壳把 `apps/web` 的原始 vite dist 从 `dsh-app://app/` 提供,
355
+ 启动图(ModuleLoader 引导、插件 preload、contact config)改由 IPC 取回后在**运行期注入**,
356
+ 随后 `dsh-client-hmr` 推送的清单让非托管行的 `rev` 与初始值不一致,正好命中那条清理路径;
357
+ 浏览器里的 `dsh web` 把启动图内联在 index.html 里,物化顺序与 rev 都不同,所以看不到;
358
+ - **修法**:`client.js` 新增模块 id 单一事实源 `DSH_BUNDLE_ID`,`applyStyles()` 改为
359
+ **先 `setAttribute("data-plugin", DSH_BUNDLE_ID)` 再插入**(与宿主自带包 `tag.dataset.plugin = "<包名>"`
360
+ 的约定逐字对齐),并补上宿主同款去重护栏;
361
+ - **验证**:桌面端等价宿主 + 无头 Edge/CDP(与用户截图同视口)—— 修复前模拟该模块清理后样式表被删、
362
+ 看板变原生控件;修复后同样清理,标签存活、`cssRules.length = 170`、6 张卡片样式完好。
363
+ 新增 `client-render` [11] 与 `client-registration` [3b] 共 12 条断言,全量 19 个测试文件通过;
364
+ - **生效条件**:只改客户端半端,**浏览器硬刷新**即可;宿主半端版本号同步升到 1.9.5。
365
+
344
366
  ### v1.9.4(2026-09-24)
345
367
 
346
368
  **修复「火山方舟配额响应不是合法 JSON」:宿主全局 fetch 被 undici 包污染后不解压 gzip,插件改为自带解压兜底**
package/client.js CHANGED
@@ -6,8 +6,28 @@
6
6
  // React → require('react')
7
7
  // 输出为浏览器 ModuleLoader bundle:exports.apply / exports.inject
8
8
  // ============================================================
9
+ /**
10
+ * 单一事实源:本 bundle 的模块 id(= package.json 的 name)。
11
+ * 两处消费它:
12
+ * 1. `__ModuleLoader__.load({ id })` —— 加载器按模块图里的 row.id 取 bundle,
13
+ * 注册名必须逐字一致(见文件末尾的注册名护栏)。
14
+ * 2. 运行时注入的 <style> 上的 `data-plugin` 归属标记(见 applyStyles)。
15
+ * DSH 0.2 的客户端模块系统(@deepseek-ai/dsh-client-modules)用
16
+ * `claimStyles(ownerId)` 认领样式:「已带 data-plugin 的按标注归属,
17
+ * 没带的一律算到当前正在物化的那个插件头上(HMR 记账)」,随后
18
+ * `removeOwnedStyles(id)` 会把这些标记为 id 的 <style> 整片删除。
19
+ * 所以自建 <style> 必须**先**打上自己的 data-plugin 再插入,否则会被
20
+ * 别的模块认领,并在该模块 HMR/失效时连同我们自己的样式一起被删掉
21
+ * (桌面端 Electron 外壳就是这条路径:启动期内核注入 + HMR 清单同步,
22
+ * 导致样式被连带清除 —— 整块看板退化为无样式的原生控件)。
23
+ * 注:文件末尾的注册名护栏另有一份**刻意独立**的字面量副本,见那里的说明。
24
+ */
25
+ var DSH_BUNDLE_ID = "@angelyeye/dsh-cost-tracker";
26
+ /** 本插件样式表的稳定标识(data-plugin-css 值,用于去重与盘点)。 */
27
+ var DSH_STYLE_TAG_ID = "cost-tracker-plugin";
28
+
9
29
  window.__ModuleLoader__.load({
10
- id: "@angelyeye/dsh-cost-tracker",
30
+ id: DSH_BUNDLE_ID,
11
31
  factory: (require) => {
12
32
  var module = { exports: {} };
13
33
  var exports = module.exports;
@@ -283,8 +303,13 @@ window.__ModuleLoader__.load({
283
303
  .cost-subblock { border-top: .5px dashed var(--dsw-alias-border-l2, #e5e7eb); margin-top: 10px; padding-top: 10px; }
284
304
  .cost-list { font-size: 12px; color: var(--dsw-alias-label-secondary, #5b6472); line-height: 1.7; }
285
305
  `;
306
+ // 先打归属标记再插入:宿主在 style[data-plugin] 上做归属记账,
307
+ // 未标注的标签会被下一个物化的模块用 claimStyles() 认领走
308
+ // (随后 removeOwnedStyles() 会在该模块失效时连带删除)。
309
+ if (document.querySelector('style[data-plugin-css="' + DSH_STYLE_TAG_ID + '"]') !== null) return;
286
310
  const tag = document.createElement("style");
287
- tag.setAttribute("data-plugin-css", "cost-tracker-plugin");
311
+ tag.setAttribute("data-plugin", DSH_BUNDLE_ID);
312
+ tag.setAttribute("data-plugin-css", DSH_STYLE_TAG_ID);
288
313
  tag.textContent = css;
289
314
  document.head.appendChild(tag);
290
315
  ctx.effect(() => () => { tag.remove(); }, "cost-tracker: styles");
@@ -2955,7 +2980,15 @@ window.__ModuleLoader__.load({
2955
2980
  // 同时若宿主将来改变约定,也能在控制台给出明确指引,而不是只留一句加载器报错。
2956
2981
  // ------------------------------------------------------------
2957
2982
  (function () {
2958
- /** 单一事实源:必须与 package.json 的 name 完全一致。 */
2983
+ /**
2984
+ * 护栏自己的**独立**期望值:刻意不从 DSH_BUNDLE_ID 派生。
2985
+ *
2986
+ * 这里必须是第二份字面量:护栏的职责正是「注册名 ≠ 包名」时报警,
2987
+ * 若两个值来自同一个变量,注入故障后两者一起变错,护栏永远不会响
2988
+ * (test/client-registration.test.js 的 [4]/[5] 就是靠改写 DSH_BUNDLE_ID
2989
+ * 来注入故障,没有这份独立副本就测不出来)。
2990
+ * 三处必须逐字一致:本行、DSH_BUNDLE_ID、package.json 的 name。
2991
+ */
2959
2992
  var _DSH_BUNDLE_ID = "@angelyeye/dsh-cost-tracker";
2960
2993
  /** v1.7.0 发布时用过的旧裸名,仅用于给出针对性提示。 */
2961
2994
  var _DSH_LEGACY_BARE_ID = "dsh-cost-tracker";
package/index.js CHANGED
@@ -33,7 +33,7 @@ import { createCredSeam, migrateLegacySecrets, safeFetch, CRED_REFS, hostnameOf
33
33
  import { listSessionLogs, planAndBuildImports, loadManifest, IMPORT_SOURCE } from './import.js'
34
34
 
35
35
  /** 插件版本(写入上报信封,便于云端排查版本差异) */
36
- const PLUGIN_VERSION = '1.9.4'
36
+ const PLUGIN_VERSION = '1.9.5'
37
37
  setPluginVersion(PLUGIN_VERSION)
38
38
 
39
39
  /** 配置面板可写的字段(与 settings 命名空间一致)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angelyeye/dsh-cost-tracker",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "DeepSeek Harness (DSH) plugin: LLM token usage & cost tracking with a settings dashboard, agent tools, HTTP API, persistent storage, multi-device cloud sync, session-log history import, official price sync and a multi-vendor price catalog.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -33,7 +33,7 @@
33
33
  "./package.json": "./package.json"
34
34
  },
35
35
  "scripts": {
36
- "test": "node test/storage.test.js && node test/pricing.test.js && node test/peak-holidays.test.js && node test/volcengine-plan.test.js && node test/volcengine-host.test.js && node test/config.test.js && node test/recompute.test.js && node test/credstore.test.js && node test/vendor-catalog.test.js && node test/price-sync.test.js && node test/import.test.js && node test/client-registration.test.js && node test/ui-display.test.js && node test/client-render.test.js && node test/cloud-read.test.js && node --no-warnings test/cloud-view-e2e.test.js && node test/sync.test.js && node test/view.test.js"
36
+ "test": "node test/storage.test.js && node test/pricing.test.js && node test/peak-holidays.test.js && node test/volcengine-plan.test.js && node test/volcengine-host.test.js && node test/config.test.js && node test/recompute.test.js && node test/credstore.test.js && node test/vendor-catalog.test.js && node test/price-sync.test.js && node test/import.test.js && node test/client-registration.test.js && node test/ui-display.test.js && node test/client-render.test.js && node test/cloud-read.test.js && node --no-warnings test/cloud-view-e2e.test.js && node test/sync.test.js && node test/view.test.js && node test/release-notes.test.js"
37
37
  },
38
38
  "keywords": [
39
39
  "dsh-plugin",