dsh-light-guard 0.7.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@
6
6
 
7
7
  ---
8
8
 
9
+ ## v0.7.1 (2026-11-27)
10
+ - **发现的问题**:在 DSH 桌面端(`dsh-app:`)装有多个第三方插件时,直接点击「软刷新前端界面」可能触发某些不兼容前端重载的第三方插件(例如 `dsh-notify-say`)在 `web-boot` 阶段报 `import failed` 弹窗,容易让不了解情况的用户误以为数据损坏而紧张。
11
+ - **改了什么**:
12
+ - 为「软刷新前端界面」增加**事前 3 条清晰确认提示**(明确说明:先保存未发草稿、个别第三方插件可能弹窗、万一弹窗数据绝不丢失且点「重启」即可秒恢复);
13
+ - 新增**自动熔断自学习机制**:刷新后 20 秒内顺利回到页面则自动标记「本机已验证可用 ✓」并展示**软刷新前后真实堆内存 / DOM 减负回执**;若上次未正常完成则自动降级标黄提醒「不建议在当前插件组合下使用」,避免反复踩坑。
14
+
9
15
  ## v0.7.0 (2026-11-27)
10
16
  - **发现的问题**:用户反馈“单个会话工作时间长了会变卡,必须重启 DSH 才能恢复”,但此前无法一眼判断内存压力来自前端 Chromium 渲染进程还是后端 Node 宿主进程,导致很多只需要刷新前端视图的情况也被迫重启整个 DSH、打断后台任务。
11
17
  - **改了什么**:
package/lib/client.js CHANGED
@@ -19,13 +19,73 @@ window.__ModuleLoader__.load({
19
19
  var h = React.createElement;
20
20
 
21
21
  var PLUGIN_NAME = "dsh-light-guard";
22
- var VERSION = "0.7.0";
22
+ var VERSION = "0.7.1";
23
23
  var API_PREFIX = "dsh-light-guard";
24
24
  var LOCAL_CACHE_KEY = "dsh.lightGuard.config.v1";
25
+ var SOFT_RELOAD_KEY = "dsh.lightGuard.softReload.v1";
25
26
  var STYLE_ELEMENT_ID = "dsh-light-guard-style";
26
27
  var PATCHED_SELF = Symbol.for("dsh-light-guard.stream-patched.v1");
27
28
  var PATCHED_LAG_GUARD = Symbol.for("dsh-lag-guard.patched.v1");
28
29
 
30
+ function readRendererMemoryNow() {
31
+ var domNodes = typeof document !== "undefined" ? document.querySelectorAll("*").length : 0;
32
+ var m = typeof performance !== "undefined" && performance.memory ? performance.memory : null;
33
+ return {
34
+ domNodes: domNodes,
35
+ jsHeapUsedMB: m ? Math.round((m.usedJSHeapSize / 1048576) * 10) / 10 : null,
36
+ jsHeapTotalMB: m ? Math.round((m.totalJSHeapSize / 1048576) * 10) / 10 : null,
37
+ jsHeapLimitMB: m ? Math.round((m.jsHeapSizeLimit / 1048576) * 10) / 10 : null
38
+ };
39
+ }
40
+
41
+ function readSoftReloadState() {
42
+ try {
43
+ if (typeof localStorage !== "undefined") {
44
+ var raw = localStorage.getItem(SOFT_RELOAD_KEY);
45
+ if (raw) {
46
+ var parsed = JSON.parse(raw);
47
+ if (parsed && typeof parsed === "object") return parsed;
48
+ }
49
+ }
50
+ } catch {}
51
+ return { status: "untested" };
52
+ }
53
+
54
+ function writeSoftReloadState(st) {
55
+ try {
56
+ if (typeof localStorage !== "undefined") {
57
+ localStorage.setItem(SOFT_RELOAD_KEY, JSON.stringify(st));
58
+ }
59
+ } catch {}
60
+ }
61
+
62
+ // Circuit breaker: settle any pending soft-reload attempt on module boot
63
+ (function settleSoftReloadOnBoot() {
64
+ var st = readSoftReloadState();
65
+ if (st && st.status === "pending" && typeof st.attemptAt === "number") {
66
+ var elapsed = Date.now() - st.attemptAt;
67
+ if (elapsed >= 0 && elapsed <= 20000) {
68
+ // Wait briefly for initial render so afterDom/afterHeap reflect real post-reload state
69
+ var finalize = function () {
70
+ var after = readRendererMemoryNow();
71
+ writeSoftReloadState(Object.assign({}, st, {
72
+ status: "verified",
73
+ afterHeapMB: after.jsHeapUsedMB,
74
+ afterDom: after.domNodes,
75
+ verifiedAt: Date.now()
76
+ }));
77
+ };
78
+ if (typeof setTimeout === "function") setTimeout(finalize, 1200);
79
+ else finalize();
80
+ } else {
81
+ writeSoftReloadState(Object.assign({}, st, {
82
+ status: "failed",
83
+ failedAt: Date.now()
84
+ }));
85
+ }
86
+ }
87
+ })();
88
+
29
89
  var DEFAULT_CFG = {
30
90
  preset: "heavy",
31
91
  cssOffscreenEnabled: true,
@@ -624,6 +684,10 @@ window.__ModuleLoader__.load({
624
684
  var snapLabel = _snapLabel[0], setSnapLabel = _snapLabel[1];
625
685
  var _liveDom = React.useState({ domNodes: 0, longTasks: 0, maxLtMs: 0 });
626
686
  var liveDom = _liveDom[0], setLiveDom = _liveDom[1];
687
+ var _srConfirm = React.useState(false);
688
+ var srConfirm = _srConfirm[0], setSrConfirm = _srConfirm[1];
689
+ var _srState = React.useState(readSoftReloadState);
690
+ var srState = _srState[0], setSrState = _srState[1];
627
691
 
628
692
  React.useEffect(function () {
629
693
  var alive = true;
@@ -861,14 +925,22 @@ window.__ModuleLoader__.load({
861
925
  }
862
926
 
863
927
  function readRendererMemory() {
864
- var domNodes = typeof document !== "undefined" ? document.querySelectorAll("*").length : 0;
865
- var m = typeof performance !== "undefined" && performance.memory ? performance.memory : null;
866
- return {
867
- domNodes: domNodes,
868
- jsHeapUsedMB: m ? Math.round((m.usedJSHeapSize / 1048576) * 10) / 10 : null,
869
- jsHeapTotalMB: m ? Math.round((m.totalJSHeapSize / 1048576) * 10) / 10 : null,
870
- jsHeapLimitMB: m ? Math.round((m.jsHeapSizeLimit / 1048576) * 10) / 10 : null
928
+ return readRendererMemoryNow();
929
+ }
930
+
931
+ function executeSoftReload() {
932
+ var before = readRendererMemoryNow();
933
+ var next = {
934
+ status: "pending",
935
+ attemptAt: Date.now(),
936
+ beforeHeapMB: before.jsHeapUsedMB,
937
+ beforeDom: before.domNodes
871
938
  };
939
+ writeSoftReloadState(next);
940
+ setSrState(next);
941
+ if (typeof window !== "undefined" && window.location) {
942
+ window.location.reload();
943
+ }
872
944
  }
873
945
 
874
946
  function diagnoseMemory(rMem, hMem) {
@@ -1339,23 +1411,29 @@ window.__ModuleLoader__.load({
1339
1411
  var rMem = readRendererMemory();
1340
1412
  var hMem = scan && scan.hostMemory ? scan.hostMemory : null;
1341
1413
  var memDiag = diagnoseMemory(rMem, hMem);
1414
+ var isDesktop = typeof window !== "undefined" && window.location && window.location.protocol === "dsh-app:";
1415
+ var curSr = readSoftReloadState();
1416
+ var srFailed = curSr && curSr.status === "failed";
1417
+ var srVerified = curSr && curSr.status === "verified";
1342
1418
  return h("div", null,
1343
- // Memory Attribution & Soft UI Reload Card (zero-polling, on-demand)
1419
+ // Memory Attribution & Soft UI Reload Card (zero-polling, on-demand + circuit breaker)
1344
1420
  h("div", { style: surfaceCard },
1345
1421
  h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: "8px", flexWrap: "wrap", marginBottom: "8px" } },
1346
- h("div", { style: { display: "flex", alignItems: "center", gap: "8px" } },
1422
+ h("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" } },
1347
1423
  h("span", { style: { fontWeight: 600 } }, "前后端内存归因(按需读数 · 零轮询)"),
1348
- h(Pill, { bg: memDiag.bg, color: memDiag.color }, memDiag.badge)
1424
+ h(Pill, { bg: memDiag.bg, color: memDiag.color }, memDiag.badge),
1425
+ srVerified
1426
+ ? h(Pill, { bg: "rgba(16,185,129,0.14)", color: "#10b981" }, "软刷新本机已验证 ✓")
1427
+ : srFailed
1428
+ ? h(Pill, { bg: "rgba(245,158,11,0.16)", color: "#d97706" }, "上次软刷新异常 · 不推荐")
1429
+ : isDesktop
1430
+ ? h(Pill, null, "桌面端首次使用需确认")
1431
+ : null
1349
1432
  ),
1350
1433
  h("button", {
1351
- style: memDiag.suggestSoftReload ? btnPrimary : btnBase,
1352
- title: "仅刷新前端界面释放 Chromium 渲染内存,不重启后端、不中断后台 Agent 任务(未发送的输入草稿建议先保存)",
1353
- onClick: function () {
1354
- if (typeof window !== "undefined" && window.location) {
1355
- window.location.reload();
1356
- }
1357
- }
1358
- }, "软刷新前端界面(不中断后台)")
1434
+ style: (!srFailed && memDiag.suggestSoftReload) ? btnPrimary : btnBase,
1435
+ onClick: function () { setSrConfirm(!srConfirm); }
1436
+ }, srFailed ? "重新测试软刷新" : "软刷新前端界面")
1359
1437
  ),
1360
1438
  h("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: "8px", marginBottom: "8px", fontSize: "12px" } },
1361
1439
  h("div", { style: { padding: "8px 10px", borderRadius: "8px", background: "rgba(128,128,128,0.06)" } },
@@ -1375,7 +1453,43 @@ window.__ModuleLoader__.load({
1375
1453
  ),
1376
1454
  h("div", { style: { fontSize: "12px", padding: "7px 10px", borderRadius: "7px", background: memDiag.bg, color: memDiag.color, lineHeight: 1.5 } },
1377
1455
  memDiag.advice
1378
- )
1456
+ ),
1457
+ // Before/After relief receipt after a verified soft reload
1458
+ srVerified && typeof curSr.beforeDom === "number" && typeof curSr.afterDom === "number"
1459
+ ? h("div", { style: { marginTop: "8px", fontSize: "11px", padding: "6px 10px", borderRadius: "7px", background: "rgba(16,185,129,0.08)", color: "#059669" } },
1460
+ "✓ 上次软刷新实测回执:" +
1461
+ (curSr.beforeHeapMB !== null && curSr.afterHeapMB !== null ? ("前端堆 " + curSr.beforeHeapMB + " MB → " + curSr.afterHeapMB + " MB · ") : "") +
1462
+ "DOM " + curSr.beforeDom.toLocaleString() + " → " + curSr.afterDom.toLocaleString()
1463
+ )
1464
+ : null,
1465
+ // Circuit breaker warning when a previous soft reload did not settle cleanly
1466
+ srFailed
1467
+ ? h("div", { style: { marginTop: "8px", fontSize: "12px", padding: "8px 10px", borderRadius: "7px", background: "rgba(245,158,11,0.12)", border: "1px solid rgba(245,158,11,0.35)", lineHeight: 1.55 } },
1468
+ h("b", { style: { color: "#d97706" } }, "⚠️ 检测到上次软刷新未正常完成(不建议在当前插件组合下使用)"),
1469
+ h("div", { style: { marginTop: "3px", opacity: 0.9 } },
1470
+ "这通常是您安装的其他第三方插件不支持桌面端前端重载导致的(您的数据、会话和插件不会受损)。建议改用「等当前任务结束后正常重启 DSH」;若后续调整过插件列表,可点右上角「重新测试软刷新」。"
1471
+ )
1472
+ )
1473
+ : null,
1474
+ // Clear, reassuring 2-step confirmation panel before triggering reload
1475
+ srConfirm
1476
+ ? h("div", { style: { marginTop: "8px", fontSize: "12px", padding: "10px 12px", borderRadius: "8px", background: "rgba(245,158,11,0.1)", border: "1px solid rgba(245,158,11,0.4)", lineHeight: 1.6 } },
1477
+ h("div", { style: { fontWeight: 700, marginBottom: "4px", color: "#b45309" } },
1478
+ isDesktop && !srVerified ? "使用前必看(请花 3 秒确认,别担心数据安全)" : "确认立即软刷新前端界面?"
1479
+ ),
1480
+ h("div", null, "1. 作用:仅重载前端界面释放 Chromium 渲染内存,不重启后端、不中断后台正在运行的 Agent 任务;输入栏未发送的草稿请先复制保存。"),
1481
+ isDesktop && !srVerified
1482
+ ? h("div", null, "2. 兼容提醒:如果您装了多个第三方插件,个别插件在桌面端重载时可能触发 web-boot 报错弹窗。")
1483
+ : null,
1484
+ isDesktop && !srVerified
1485
+ ? h("div", null, "3. 万一弹窗别慌:您的数据、会话和插件绝对不会丢失——直接点弹窗里的「重启」(不要点「禁用第三方插件」),几秒即可恢复正常;本插件会自动记住冲突,后续不再推荐。")
1486
+ : null,
1487
+ h("div", { style: { display: "flex", gap: "8px", marginTop: "8px" } },
1488
+ h("button", { style: btnPrimary, onClick: executeSoftReload }, "我已知晓,开始软刷新"),
1489
+ h("button", { style: btnBase, onClick: function () { setSrConfirm(false); } }, "取消")
1490
+ )
1491
+ )
1492
+ : null
1379
1493
  ),
1380
1494
 
1381
1495
  h("div", { style: surfaceCard },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-light-guard",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "author": "unifilitence",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",