dsh-cost-meter 1.9.2 → 1.9.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.
@@ -1,58 +1,58 @@
1
- # 2026-10-18 性能与透明度验证
2
-
3
- 基线 commit:`9725581bdbd19cf6a2ad2e7c02e0557f2e045771`,版本 1.9.0。测试使用同一台 Windows 主机、Node.js 24.19.0、AMD Ryzen 7 5800H。两版均使用锁文件中的 acorn 8.15.0、zod 4.6.5 和 esbuild 0.28.2。原始数据见 [JSON 记录](performance-2026-10-18.json)。
4
-
5
- ## 自动语言模式的费用查询
6
-
7
- [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 指出的开销来自:宿主没有可用 locale 服务时,每个费用方法都通过 `settings.describe({ redactSecrets: true })` 构建全部插件设置,只为读取语言偏好。
8
-
9
- 现在只缓存解析出的语言,设置或语言事件立即使缓存失效。没有事件的旧宿主最多每秒探测一次,在下一次费用读取时更新;明确选择中文或英文仍直接使用指定语言。缓存不保留设置描述和凭据,插件卸载时清理。另处理了 `describe()` 自身触发设置事件的重入情况,避免递归调用。
10
-
11
- 基准调用真实的 `costMeter.getSessionCost()`,使用空账本和合成设置描述:64 个插件、每个 20 个字段,加一个语言设置条目。预热 100 次,随后执行 5 轮,每轮 2,000 次读取;两版均使用同一数据和禁网条件。
12
-
13
- | 指标 | 修改前 | 修改后 |
14
- | --- | ---: | ---: |
15
- | 10,000 次读取中的全量设置描述次数 | 10,000 | 0 |
16
- | 每轮耗时中位数 | 1,719.58 ms | 40.19 ms |
17
- | 每轮 CPU 时间中位数 | 1,719 ms | 47 ms |
18
- | 外部网络请求 | 0 | 0 |
19
-
20
- 这次测量中,该调用路径的耗时降低 **97.7%**。这是隔离基准,不是整个 DSH 的 CPU 降幅,也不将报告者旧版采样中的 11.3% 当成新版实测结果。修改后全部计时轮次在缓存期限内完成;长期运行的无事件宿主仍保留每秒最多一次的检查。
21
-
22
- 复现命令:
23
-
24
- ```powershell
25
- # 两个 checkout 使用相同依赖;第一个参数是被测仓库根目录。
26
- node test/host-locale-performance.mjs <baseline-checkout> before.json
27
- node test/host-locale-performance.mjs <updated-checkout> after.json
28
- ```
29
-
30
- ## OpenDesign 请求数量
31
-
32
- 同一份合成 Control Key 场景中,旧路径请求 `coding-plan-usage` 收到 401 后,再请求 preflight,同时读取钱包,共 **3 次 GET**。新路径直接并行读取 preflight 和钱包,共 **2 次 GET**,减少一次必然失败的请求和串行等待。身份校验、大整数额度校验和单侧失败处理保留。未用真实账户测量网络延迟。
33
-
34
- ## 客户端体积
35
-
36
- 构建时根据实际重复次数压缩 CSS 声明、选择器与主题变量;客户端加载时解码一次。构建过程逐字节核对解码结果与 esbuild 输出一致。
37
-
38
- 主客户端从 **261,676 字节**变为 **260,671 字节**,新增功能后仍减少 **1,005 字节**。统计和定价继续按需加载。没有通过删除界面内容满足 DSH STORE 的 262,144 字节限制。
39
-
40
- ## 透明度
41
-
42
- 主题背景色中含透明度时,费用设置页、统计页、价格下拉框、费用详情、上下文引导、兼容提醒、峰谷提醒和侧栏固定区域使用相同 RGB 颜色的不透明背景;不修改宿主或其它插件的主题变量。统计内容和费用弹窗使用皮肤的弹窗表面色,避免把深色壁纸遮罩当成浅色界面的正文底色。
43
-
44
- Chromium 测试覆盖 11 类区域、3 种主题、4 档透明度,共 **132 个场景**。每个场景只切换后方页面的颜色,比较区域内部的截图像素:
45
-
46
- - 基线有 **105 个场景**的内部像素随后方内容变化,复现透出。
47
- - 修改后 **132 个场景全部保持相同**,浏览器无脚本错误。
48
- - 主题包含浅色、深色、浅色宿主配深色皮肤;透明度为 0、0.2、0.65、1。
49
-
50
- ```powershell
51
- $env:DSH_TEST_UI_MODULES = '<含 react、react-dom、playwright-core 的 node_modules>'
52
- node test/skin-opacity-browser.mjs 9725581
53
- node test/skin-opacity-browser.mjs
54
- ```
55
-
56
- 测试使用真实客户端和按需模块的 CSS,以及真实 React 费用详情和兼容提示组件。测试范围是背景色透明度;没有把任意第三方插件直接修改父元素 `opacity` 的行为纳入已验证范围。
57
-
58
- 贡献:@XHPAN 提供 [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 的 CPU profile 归因、环境和优化建议;本文的数据是本轮另行运行的隔离基准。
1
+ # 2026-10-18 性能与透明度验证
2
+
3
+ 基线 commit:`9725581bdbd19cf6a2ad2e7c02e0557f2e045771`,版本 1.9.0。测试使用同一台 Windows 主机、Node.js 24.19.0、AMD Ryzen 7 5800H。两版均使用锁文件中的 acorn 8.15.0、zod 4.6.5 和 esbuild 0.28.2。原始数据见 [JSON 记录](performance-2026-10-18.json)。
4
+
5
+ ## 自动语言模式的费用查询
6
+
7
+ [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 指出的开销来自:宿主没有可用 locale 服务时,每个费用方法都通过 `settings.describe({ redactSecrets: true })` 构建全部插件设置,只为读取语言偏好。
8
+
9
+ 现在只缓存解析出的语言,设置或语言事件立即使缓存失效。没有事件的旧宿主最多每秒探测一次,在下一次费用读取时更新;明确选择中文或英文仍直接使用指定语言。缓存不保留设置描述和凭据,插件卸载时清理。另处理了 `describe()` 自身触发设置事件的重入情况,避免递归调用。
10
+
11
+ 基准调用真实的 `costMeter.getSessionCost()`,使用空账本和合成设置描述:64 个插件、每个 20 个字段,加一个语言设置条目。预热 100 次,随后执行 5 轮,每轮 2,000 次读取;两版均使用同一数据和禁网条件。
12
+
13
+ | 指标 | 修改前 | 修改后 |
14
+ | --- | ---: | ---: |
15
+ | 10,000 次读取中的全量设置描述次数 | 10,000 | 0 |
16
+ | 每轮耗时中位数 | 1,719.58 ms | 40.19 ms |
17
+ | 每轮 CPU 时间中位数 | 1,719 ms | 47 ms |
18
+ | 外部网络请求 | 0 | 0 |
19
+
20
+ 这次测量中,该调用路径的耗时降低 **97.7%**。这是隔离基准,不是整个 DSH 的 CPU 降幅,也不将报告者旧版采样中的 11.3% 当成新版实测结果。修改后全部计时轮次在缓存期限内完成;长期运行的无事件宿主仍保留每秒最多一次的检查。
21
+
22
+ 复现命令:
23
+
24
+ ```powershell
25
+ # 两个 checkout 使用相同依赖;第一个参数是被测仓库根目录。
26
+ node test/host-locale-performance.mjs <baseline-checkout> before.json
27
+ node test/host-locale-performance.mjs <updated-checkout> after.json
28
+ ```
29
+
30
+ ## OpenDesign 请求数量
31
+
32
+ 同一份合成 Control Key 场景中,旧路径请求 `coding-plan-usage` 收到 401 后,再请求 preflight,同时读取钱包,共 **3 次 GET**。新路径直接并行读取 preflight 和钱包,共 **2 次 GET**,减少一次必然失败的请求和串行等待。身份校验、大整数额度校验和单侧失败处理保留。未用真实账户测量网络延迟。
33
+
34
+ ## 客户端体积
35
+
36
+ 构建时根据实际重复次数压缩 CSS 声明、选择器与主题变量;客户端加载时解码一次。构建过程逐字节核对解码结果与 esbuild 输出一致。
37
+
38
+ 主客户端从 **261,676 字节**变为 **260,671 字节**,新增功能后仍减少 **1,005 字节**。统计和定价继续按需加载。没有通过删除界面内容满足 DSH STORE 的 262,144 字节限制。
39
+
40
+ ## 透明度
41
+
42
+ 主题背景色中含透明度时,费用设置页、统计页、价格下拉框、费用详情、上下文引导、兼容提醒、峰谷提醒和侧栏固定区域使用相同 RGB 颜色的不透明背景;不修改宿主或其它插件的主题变量。统计内容和费用弹窗使用皮肤的弹窗表面色,避免把深色壁纸遮罩当成浅色界面的正文底色。
43
+
44
+ Chromium 测试覆盖 11 类区域、3 种主题、4 档透明度,共 **132 个场景**。每个场景只切换后方页面的颜色,比较区域内部的截图像素:
45
+
46
+ - 基线有 **105 个场景**的内部像素随后方内容变化,复现透出。
47
+ - 修改后 **132 个场景全部保持相同**,浏览器无脚本错误。
48
+ - 主题包含浅色、深色、浅色宿主配深色皮肤;透明度为 0、0.2、0.65、1。
49
+
50
+ ```powershell
51
+ $env:DSH_TEST_UI_MODULES = '<含 react、react-dom、playwright-core 的 node_modules>'
52
+ node test/skin-opacity-browser.mjs 9725581
53
+ node test/skin-opacity-browser.mjs
54
+ ```
55
+
56
+ 测试使用真实客户端和按需模块的 CSS,以及真实 React 费用详情和兼容提示组件。测试范围是背景色透明度;没有把任意第三方插件直接修改父元素 `opacity` 的行为纳入已验证范围。
57
+
58
+ 贡献:@XHPAN 提供 [#312](https://github.com/Han-1413141/dsh-cost-meter/issues/312) 的 CPU profile 归因、环境和优化建议;本文的数据是本轮另行运行的隔离基准。
@@ -0,0 +1,19 @@
1
+ # v1.9.3
2
+
3
+ ## 中文
4
+
5
+ - 修复 Codex 兼容提示关闭失败。×、Esc 和“保持现状”立即关闭弹窗,即使归类请求尚未返回或保存接口报错;关闭后不反复弹出,历史归类仍可在设置页手动执行。
6
+ - 修复热更新后 Codex 历史归类接口返回 HTTP 404。宿主保留旧接口清单时,只补注册缺失的兼容接口;卸载时撤销补注册,保留宿主原有注册。
7
+ - 修复 Codex 标签页空白,恢复版本、计费方式、历史用量和归类入口;加载失败可以重试,归类失败会显示错误。
8
+ - 概览卡片移除多余底部留白,保存状态靠右;计费统计先显示标题和数据,兼容说明及 dsh-context 设置合并为默认折叠的一行。
9
+
10
+ 历史归类读取本地账本,不依赖 Codex API Key。安装本版不会自动重算历史费用。更新后完全退出并重新打开 DSH,以加载完整的宿主与前端代码。
11
+
12
+ ## English
13
+
14
+ - The Codex compatibility prompt closes immediately with ×, Esc, or Keep status quo, including while a request is pending or fails. Dismissal is retained locally; historical reclassification remains available in settings.
15
+ - Fixed HTTP 404 after hot updates when the host retains an older RPC manifest. Only missing compatibility endpoints are registered, with cleanup tied to the plugin lifetime.
16
+ - Fixed the blank Codex tab, restored usage and reclassification controls, and added visible action errors and load retry.
17
+ - Removed excess spacing from overview cards and placed optional compatibility controls in a collapsed row below the statistics heading.
18
+
19
+ Historical reclassification uses the local ledger and does not require a Codex API key. Updating does not automatically recalculate historical costs. Fully quit and reopen DSH after updating.
@@ -1 +1 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:g=>{const f=g("react"),{createElement:e,useState:C,useEffect:h,useRef:v}=f,N="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const s=document.createElement("style");s.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}",s.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw - 32px)}.cm-codex-compat{padding:0 2px}}body[data-dsh-pocket-layout="mobile"] .cm-codex-compat-dialog{width:calc(100vw - 32px)}',document.head.appendChild(s)}function P(){const[s,u]=C(!1),[a,c]=C(null);return[s,a,o=>{s||(u(!0),c(null),o().catch(t=>c(t?.message??String(t))).finally(()=>u(!1)))}]}function y(s){const a=s.state?.codexCompat,c=s.api,i=s.locale==="en",o=(x,A)=>i?A:x,t=v(null),[l,n,p]=P(),r=a?.promptDue===!0;if(h(()=>{r&&t.current&&!t.current.open&&t.current.showModal()},[r]),!r)return null;const d=a.usage??{},m=()=>p(c.dismissCodexCompat);return e("dialog",{ref:t,className:N,"aria-label":o("兼容修复","Compatibility fix"),onCancel:x=>{x.preventDefault(),m()}},e("header",{className:"cm-stat-dialog-head"},o("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":o("关闭","Close"),disabled:l,onClick:m},"×")),e("div",{className:"cm-stat-dialog-body"},e("p",null,o("检测到 dsh-codex-subscription {version}。Codex 订阅用量不计入 API 费用;为兼容本插件,新产生的 Codex 用量已自动归类为 Plan。是否将历史 codex 类模型的计费统一归类为 Plan(订阅额度,不计入 API 费用)?","Detected dsh-codex-subscription {version}. Codex subscription usage is not billed as API usage; for compatibility this plugin now defaults new Codex usage to Plan. Reclassify the billing of historical codex-class models as Plan (subscription quota, excluded from API usage)?").replace("{version}","v"+(a.version??""))),d.calls>0?e("p",{className:"cm-note"},o("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",d.calls).replace("{cost}","$"+Number(d.cost??0).toFixed(2)).replace("{days}",d.days)):null,n?e("div",{className:"cm-msg err"},o("失败:","Failed: ")+n):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:l,onClick:m},o("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:l,onClick:()=>p(c.applyCodexCompatHistory)},o("统一归类为 Plan","Reclassify as Plan"))),e("p",{className:"cm-note"},o("之后可在 设置 → 费用 → Codex 订阅兼容 中处理。","You can change this later in Settings → Cost → Codex subscription compatibility."))))}function b(s){const a=s.state?.codexCompat;if(a?.installed!==!0)return null;const c=s.api,i=s.t,o=s.locale==="en",t=(r,d)=>o?d:r,l=a.usage??{},n=a.historyAppliedAt>0,p=a.planClass==="plan"?i("billingClassPlan"):a.planClass==="api"?i("billingClassApi"):i("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,t("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,t("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(a.version??""))),e("p",null,t("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",p)),e("p",null,t("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",l.calls).replace("{cost}","$"+Number(l.cost??0).toFixed(2)).replace("{tokens}",Number(l.tokens??0).toLocaleString(o?"en-US":"zh-CN")).replace("{days}",l.days)),n?e("p",{className:"cm-note"},t("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(a.historyAppliedAt).toLocaleString())):e("p",null,t("历史用量未归类。","Historical usage is not reclassified yet.")),!n&&l.providers?.length?e("p",{className:"cm-note"},t("来源:{providers}","Sources: {providers}").replace("{providers}",l.providers.join(", "))):null,n?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",onClick:()=>c.applyCodexCompatHistory().catch(()=>{})},t("统一归类为 Plan","Reclassify as Plan"))),!n&&a.promptDismissed===!0?e("p",{className:"cm-note"},t("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function w(){return{CodexCompatPrompt:y,CodexCompatPanel:b}}return{mount:w,CodexCompatPrompt:y,CodexCompatPanel:b}}});
1
+ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:A=>{const k=A("react"),{createElement:e,useState:C,useEffect:g,useRef:h}=k,D="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const t=document.createElement("style");t.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}.cm-codex-compat :is(h3,p){margin:0}.cm-codex-compat h3{font-size:14px;font-weight:600}",t.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw - 32px)}.cm-codex-compat{padding:0 2px}}body[data-dsh-pocket-layout="mobile"] .cm-codex-compat-dialog{width:calc(100vw - 32px)}',document.head.appendChild(t)}const v="dsh-cost-meter:codex-compat-prompt-dismissed",b=new Set;let w=!1;function I(){if(w)return!0;try{return window.localStorage.getItem(v)==="1"}catch{return!1}}function _(){w=!0;try{window.localStorage.setItem(v,"1")}catch{}for(const t of b)t(!0)}function N(){const[t,y]=C(!1),[s,d]=C(null),c=h(!1);return[t,s,l=>{c.current||(c.current=!0,y(!0),d(null),Promise.resolve().then(l).catch(n=>d(n?.message??String(n))).finally(()=>{c.current=!1,y(!1)}))}]}function P(t){const s=t.state?.codexCompat,d=t.api,c=t.locale==="en",a=(f,L)=>c?L:f,l=h(null),[n,m,o]=N(),[i,r]=C(I),p=s?.promptDue===!0&&!i;if(g(()=>(b.add(r),()=>b.delete(r)),[]),g(()=>{p&&l.current&&!l.current.open&&l.current.showModal()},[p]),!p)return null;const u=s.usage??{},x=()=>{l.current?.close(),r(!0),_(),Promise.resolve().then(()=>d.dismissCodexCompat()).catch(()=>{})};return e("dialog",{ref:l,className:D,"aria-label":a("兼容修复","Compatibility fix"),onCancel:f=>{f.preventDefault(),x()}},e("header",{className:"cm-stat-dialog-head"},a("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":a("关闭","Close"),onClick:x},"×")),e("div",{className:"cm-stat-dialog-body"},e("p",null,a("检测到 dsh-codex-subscription {version}。Codex 订阅用量不计入 API 费用;为兼容本插件,新产生的 Codex 用量已自动归类为 Plan。是否将历史 codex 类模型的计费统一归类为 Plan(订阅额度,不计入 API 费用)?","Detected dsh-codex-subscription {version}. Codex subscription usage is not billed as API usage; for compatibility this plugin now defaults new Codex usage to Plan. Reclassify the billing of historical codex-class models as Plan (subscription quota, excluded from API usage)?").replace("{version}","v"+(s.version??""))),u.calls>0?e("p",{className:"cm-note"},a("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",u.calls).replace("{cost}","$"+Number(u.cost??0).toFixed(2)).replace("{days}",u.days)):null,m?e("div",{className:"cm-msg err"},a("失败:","Failed: ")+m):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",onClick:x},a("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:n,onClick:()=>o(d.applyCodexCompatHistory)},a("统一归类为 Plan","Reclassify as Plan"))),e("p",{className:"cm-note"},a("之后可在 设置 → 费用 → Codex 订阅兼容 中处理。","You can change this later in Settings → Cost → Codex subscription compatibility."))))}function S(t){const s=t.state?.codexCompat,[d,c,a]=N();if(s?.installed!==!0)return null;const l=t.api,n=t.t,m=t.locale==="en",o=(u,x)=>m?x:u,i=s.usage??{},r=s.historyAppliedAt>0,p=s.planClass==="plan"?n("billingClassPlan"):s.planClass==="api"?n("billingClassApi"):n("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,o("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,o("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(s.version??""))),e("p",null,o("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",p)),e("p",null,o("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",i.calls).replace("{cost}","$"+Number(i.cost??0).toFixed(2)).replace("{tokens}",Number(i.tokens??0).toLocaleString(m?"en-US":"zh-CN")).replace("{days}",i.days)),c?e("div",{className:"cm-msg err",role:"alert"},o("失败:","Failed: ")+c):null,r?e("p",{className:"cm-note"},o("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(s.historyAppliedAt).toLocaleString())):e("p",null,o("历史用量未归类。","Historical usage is not reclassified yet.")),!r&&i.providers?.length?e("p",{className:"cm-note"},o("来源:{providers}","Sources: {providers}").replace("{providers}",i.providers.join(", "))):null,r?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",disabled:d,onClick:()=>a(l.applyCodexCompatHistory)},o("统一归类为 Plan","Reclassify as Plan"))),!r&&s.promptDismissed===!0?e("p",{className:"cm-note"},o("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function E(){return t=>e(t.view==="prompt"?P:S,t)}return{mount:E,CodexCompatPrompt:P,CodexCompatPanel:S}}});