dsh-light-guard 0.7.0 → 0.7.2
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 +14 -0
- package/lib/client.js +152 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## v0.7.2 (2026-11-27)
|
|
10
|
+
- **发现的问题**:在 DSH 桌面端的 combo bundle 启动机制中,同一批次内任一插件如果在顶层注册或激活阶段同步抛错(例如重复执行触发 `duplicate factory registration`),会阻断同批排在后面的其他插件注册并引发 `web-boot` 致命弹窗。
|
|
11
|
+
- **改了什么**:
|
|
12
|
+
- 为 `lib/client.js` 顶层 `window.__ModuleLoader__.load(...)` 增加双层守卫:`duplicate factory registration` 静默幂等跳过,其他非重复错误通过 `queueMicrotask` 异步重抛(既保留真实报错可观测性,又绝不阻断同批后续插件注册);
|
|
13
|
+
- 为 `apply(ctx)` 出口补齐 `try/catch` 兜底;
|
|
14
|
+
- 软刷新前端前增加优雅收尾(先停 LoAF 采样器、清理本插件样式节点,再延迟 60ms 触发 `location.reload()`,让其他插件的 `beforeunload`/`pagehide` 钩子体面退场);
|
|
15
|
+
- 新增 `client.js` 契约单测(`new Function` 经典脚本解析门 + 假 loader 重复注册不抛错验证)。
|
|
16
|
+
|
|
17
|
+
## v0.7.1 (2026-11-27)
|
|
18
|
+
- **发现的问题**:在 DSH 桌面端(`dsh-app:`)装有多个第三方插件时,直接点击「软刷新前端界面」可能触发某些不兼容前端重载的第三方插件(例如 `dsh-notify-say`)在 `web-boot` 阶段报 `import failed` 弹窗,容易让不了解情况的用户误以为数据损坏而紧张。
|
|
19
|
+
- **改了什么**:
|
|
20
|
+
- 为「软刷新前端界面」增加**事前 3 条清晰确认提示**(明确说明:先保存未发草稿、个别第三方插件可能弹窗、万一弹窗数据绝不丢失且点「重启」即可秒恢复);
|
|
21
|
+
- 新增**自动熔断自学习机制**:刷新后 20 秒内顺利回到页面则自动标记「本机已验证可用 ✓」并展示**软刷新前后真实堆内存 / DOM 减负回执**;若上次未正常完成则自动降级标黄提醒「不建议在当前插件组合下使用」,避免反复踩坑。
|
|
22
|
+
|
|
9
23
|
## v0.7.0 (2026-11-27)
|
|
10
24
|
- **发现的问题**:用户反馈“单个会话工作时间长了会变卡,必须重启 DSH 才能恢复”,但此前无法一眼判断内存压力来自前端 Chromium 渲染进程还是后端 Node 宿主进程,导致很多只需要刷新前端视图的情况也被迫重启整个 DSH、打断后台任务。
|
|
11
25
|
- **改了什么**:
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 3. "Performance Cockpit" settings section ("性能护航") with SVG health gauge, 2x2 preset cards,
|
|
9
9
|
* 3 segmented tabs, visual storage bars, before/after delta snapshots, and reversible cold archiver.
|
|
10
10
|
*/
|
|
11
|
+
try {
|
|
11
12
|
window.__ModuleLoader__.load({
|
|
12
13
|
id: "dsh-light-guard",
|
|
13
14
|
factory: (require) => {
|
|
@@ -19,13 +20,73 @@ window.__ModuleLoader__.load({
|
|
|
19
20
|
var h = React.createElement;
|
|
20
21
|
|
|
21
22
|
var PLUGIN_NAME = "dsh-light-guard";
|
|
22
|
-
var VERSION = "0.7.
|
|
23
|
+
var VERSION = "0.7.2";
|
|
23
24
|
var API_PREFIX = "dsh-light-guard";
|
|
24
25
|
var LOCAL_CACHE_KEY = "dsh.lightGuard.config.v1";
|
|
26
|
+
var SOFT_RELOAD_KEY = "dsh.lightGuard.softReload.v1";
|
|
25
27
|
var STYLE_ELEMENT_ID = "dsh-light-guard-style";
|
|
26
28
|
var PATCHED_SELF = Symbol.for("dsh-light-guard.stream-patched.v1");
|
|
27
29
|
var PATCHED_LAG_GUARD = Symbol.for("dsh-lag-guard.patched.v1");
|
|
28
30
|
|
|
31
|
+
function readRendererMemoryNow() {
|
|
32
|
+
var domNodes = typeof document !== "undefined" ? document.querySelectorAll("*").length : 0;
|
|
33
|
+
var m = typeof performance !== "undefined" && performance.memory ? performance.memory : null;
|
|
34
|
+
return {
|
|
35
|
+
domNodes: domNodes,
|
|
36
|
+
jsHeapUsedMB: m ? Math.round((m.usedJSHeapSize / 1048576) * 10) / 10 : null,
|
|
37
|
+
jsHeapTotalMB: m ? Math.round((m.totalJSHeapSize / 1048576) * 10) / 10 : null,
|
|
38
|
+
jsHeapLimitMB: m ? Math.round((m.jsHeapSizeLimit / 1048576) * 10) / 10 : null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function readSoftReloadState() {
|
|
43
|
+
try {
|
|
44
|
+
if (typeof localStorage !== "undefined") {
|
|
45
|
+
var raw = localStorage.getItem(SOFT_RELOAD_KEY);
|
|
46
|
+
if (raw) {
|
|
47
|
+
var parsed = JSON.parse(raw);
|
|
48
|
+
if (parsed && typeof parsed === "object") return parsed;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
return { status: "untested" };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function writeSoftReloadState(st) {
|
|
56
|
+
try {
|
|
57
|
+
if (typeof localStorage !== "undefined") {
|
|
58
|
+
localStorage.setItem(SOFT_RELOAD_KEY, JSON.stringify(st));
|
|
59
|
+
}
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Circuit breaker: settle any pending soft-reload attempt on module boot
|
|
64
|
+
(function settleSoftReloadOnBoot() {
|
|
65
|
+
var st = readSoftReloadState();
|
|
66
|
+
if (st && st.status === "pending" && typeof st.attemptAt === "number") {
|
|
67
|
+
var elapsed = Date.now() - st.attemptAt;
|
|
68
|
+
if (elapsed >= 0 && elapsed <= 20000) {
|
|
69
|
+
// Wait briefly for initial render so afterDom/afterHeap reflect real post-reload state
|
|
70
|
+
var finalize = function () {
|
|
71
|
+
var after = readRendererMemoryNow();
|
|
72
|
+
writeSoftReloadState(Object.assign({}, st, {
|
|
73
|
+
status: "verified",
|
|
74
|
+
afterHeapMB: after.jsHeapUsedMB,
|
|
75
|
+
afterDom: after.domNodes,
|
|
76
|
+
verifiedAt: Date.now()
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
if (typeof setTimeout === "function") setTimeout(finalize, 1200);
|
|
80
|
+
else finalize();
|
|
81
|
+
} else {
|
|
82
|
+
writeSoftReloadState(Object.assign({}, st, {
|
|
83
|
+
status: "failed",
|
|
84
|
+
failedAt: Date.now()
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
|
|
29
90
|
var DEFAULT_CFG = {
|
|
30
91
|
preset: "heavy",
|
|
31
92
|
cssOffscreenEnabled: true,
|
|
@@ -624,6 +685,10 @@ window.__ModuleLoader__.load({
|
|
|
624
685
|
var snapLabel = _snapLabel[0], setSnapLabel = _snapLabel[1];
|
|
625
686
|
var _liveDom = React.useState({ domNodes: 0, longTasks: 0, maxLtMs: 0 });
|
|
626
687
|
var liveDom = _liveDom[0], setLiveDom = _liveDom[1];
|
|
688
|
+
var _srConfirm = React.useState(false);
|
|
689
|
+
var srConfirm = _srConfirm[0], setSrConfirm = _srConfirm[1];
|
|
690
|
+
var _srState = React.useState(readSoftReloadState);
|
|
691
|
+
var srState = _srState[0], setSrState = _srState[1];
|
|
627
692
|
|
|
628
693
|
React.useEffect(function () {
|
|
629
694
|
var alive = true;
|
|
@@ -861,14 +926,25 @@ window.__ModuleLoader__.load({
|
|
|
861
926
|
}
|
|
862
927
|
|
|
863
928
|
function readRendererMemory() {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
929
|
+
return readRendererMemoryNow();
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function executeSoftReload() {
|
|
933
|
+
var before = readRendererMemoryNow();
|
|
934
|
+
var next = {
|
|
935
|
+
status: "pending",
|
|
936
|
+
attemptAt: Date.now(),
|
|
937
|
+
beforeHeapMB: before.jsHeapUsedMB,
|
|
938
|
+
beforeDom: before.domNodes
|
|
871
939
|
};
|
|
940
|
+
writeSoftReloadState(next);
|
|
941
|
+
setSrState(next);
|
|
942
|
+
// Clean teardown of our own resources before triggering reload
|
|
943
|
+
try { if (loafController && typeof loafController.stop === "function") loafController.stop(); } catch {}
|
|
944
|
+
try { var stEl = typeof document !== "undefined" && document.getElementById(STYLE_ELEMENT_ID); if (stEl && stEl.parentNode) stEl.parentNode.removeChild(stEl); } catch {}
|
|
945
|
+
if (typeof window !== "undefined" && window.location) {
|
|
946
|
+
setTimeout(function () { window.location.reload(); }, 60);
|
|
947
|
+
}
|
|
872
948
|
}
|
|
873
949
|
|
|
874
950
|
function diagnoseMemory(rMem, hMem) {
|
|
@@ -1339,23 +1415,29 @@ window.__ModuleLoader__.load({
|
|
|
1339
1415
|
var rMem = readRendererMemory();
|
|
1340
1416
|
var hMem = scan && scan.hostMemory ? scan.hostMemory : null;
|
|
1341
1417
|
var memDiag = diagnoseMemory(rMem, hMem);
|
|
1418
|
+
var isDesktop = typeof window !== "undefined" && window.location && window.location.protocol === "dsh-app:";
|
|
1419
|
+
var curSr = readSoftReloadState();
|
|
1420
|
+
var srFailed = curSr && curSr.status === "failed";
|
|
1421
|
+
var srVerified = curSr && curSr.status === "verified";
|
|
1342
1422
|
return h("div", null,
|
|
1343
|
-
// Memory Attribution & Soft UI Reload Card (zero-polling, on-demand)
|
|
1423
|
+
// Memory Attribution & Soft UI Reload Card (zero-polling, on-demand + circuit breaker)
|
|
1344
1424
|
h("div", { style: surfaceCard },
|
|
1345
1425
|
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" } },
|
|
1426
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" } },
|
|
1347
1427
|
h("span", { style: { fontWeight: 600 } }, "前后端内存归因(按需读数 · 零轮询)"),
|
|
1348
|
-
h(Pill, { bg: memDiag.bg, color: memDiag.color }, memDiag.badge)
|
|
1428
|
+
h(Pill, { bg: memDiag.bg, color: memDiag.color }, memDiag.badge),
|
|
1429
|
+
srVerified
|
|
1430
|
+
? h(Pill, { bg: "rgba(16,185,129,0.14)", color: "#10b981" }, "软刷新本机已验证 ✓")
|
|
1431
|
+
: srFailed
|
|
1432
|
+
? h(Pill, { bg: "rgba(245,158,11,0.16)", color: "#d97706" }, "上次软刷新异常 · 不推荐")
|
|
1433
|
+
: isDesktop
|
|
1434
|
+
? h(Pill, null, "桌面端首次使用需确认")
|
|
1435
|
+
: null
|
|
1349
1436
|
),
|
|
1350
1437
|
h("button", {
|
|
1351
|
-
style: memDiag.suggestSoftReload ? btnPrimary : btnBase,
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
if (typeof window !== "undefined" && window.location) {
|
|
1355
|
-
window.location.reload();
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
}, "软刷新前端界面(不中断后台)")
|
|
1438
|
+
style: (!srFailed && memDiag.suggestSoftReload) ? btnPrimary : btnBase,
|
|
1439
|
+
onClick: function () { setSrConfirm(!srConfirm); }
|
|
1440
|
+
}, srFailed ? "重新测试软刷新" : "软刷新前端界面")
|
|
1359
1441
|
),
|
|
1360
1442
|
h("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: "8px", marginBottom: "8px", fontSize: "12px" } },
|
|
1361
1443
|
h("div", { style: { padding: "8px 10px", borderRadius: "8px", background: "rgba(128,128,128,0.06)" } },
|
|
@@ -1375,7 +1457,43 @@ window.__ModuleLoader__.load({
|
|
|
1375
1457
|
),
|
|
1376
1458
|
h("div", { style: { fontSize: "12px", padding: "7px 10px", borderRadius: "7px", background: memDiag.bg, color: memDiag.color, lineHeight: 1.5 } },
|
|
1377
1459
|
memDiag.advice
|
|
1378
|
-
)
|
|
1460
|
+
),
|
|
1461
|
+
// Before/After relief receipt after a verified soft reload
|
|
1462
|
+
srVerified && typeof curSr.beforeDom === "number" && typeof curSr.afterDom === "number"
|
|
1463
|
+
? h("div", { style: { marginTop: "8px", fontSize: "11px", padding: "6px 10px", borderRadius: "7px", background: "rgba(16,185,129,0.08)", color: "#059669" } },
|
|
1464
|
+
"✓ 上次软刷新实测回执:" +
|
|
1465
|
+
(curSr.beforeHeapMB !== null && curSr.afterHeapMB !== null ? ("前端堆 " + curSr.beforeHeapMB + " MB → " + curSr.afterHeapMB + " MB · ") : "") +
|
|
1466
|
+
"DOM " + curSr.beforeDom.toLocaleString() + " → " + curSr.afterDom.toLocaleString()
|
|
1467
|
+
)
|
|
1468
|
+
: null,
|
|
1469
|
+
// Circuit breaker warning when a previous soft reload did not settle cleanly
|
|
1470
|
+
srFailed
|
|
1471
|
+
? 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 } },
|
|
1472
|
+
h("b", { style: { color: "#d97706" } }, "⚠️ 检测到上次软刷新未正常完成(不建议在当前插件组合下使用)"),
|
|
1473
|
+
h("div", { style: { marginTop: "3px", opacity: 0.9 } },
|
|
1474
|
+
"这通常是您安装的其他第三方插件不支持桌面端前端重载导致的(您的数据、会话和插件不会受损)。建议改用「等当前任务结束后正常重启 DSH」;若后续调整过插件列表,可点右上角「重新测试软刷新」。"
|
|
1475
|
+
)
|
|
1476
|
+
)
|
|
1477
|
+
: null,
|
|
1478
|
+
// Clear, reassuring 2-step confirmation panel before triggering reload
|
|
1479
|
+
srConfirm
|
|
1480
|
+
? 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 } },
|
|
1481
|
+
h("div", { style: { fontWeight: 700, marginBottom: "4px", color: "#b45309" } },
|
|
1482
|
+
isDesktop && !srVerified ? "使用前必看(请花 3 秒确认,别担心数据安全)" : "确认立即软刷新前端界面?"
|
|
1483
|
+
),
|
|
1484
|
+
h("div", null, "1. 作用:仅重载前端界面释放 Chromium 渲染内存,不重启后端、不中断后台正在运行的 Agent 任务;输入栏未发送的草稿请先复制保存。"),
|
|
1485
|
+
isDesktop && !srVerified
|
|
1486
|
+
? h("div", null, "2. 兼容提醒:如果您装了多个第三方插件,个别插件在桌面端重载时可能触发 web-boot 报错弹窗。")
|
|
1487
|
+
: null,
|
|
1488
|
+
isDesktop && !srVerified
|
|
1489
|
+
? h("div", null, "3. 万一弹窗别慌:您的数据、会话和插件绝对不会丢失——直接点弹窗里的「重启」(不要点「禁用第三方插件」),几秒即可恢复正常;本插件会自动记住冲突,后续不再推荐。")
|
|
1490
|
+
: null,
|
|
1491
|
+
h("div", { style: { display: "flex", gap: "8px", marginTop: "8px" } },
|
|
1492
|
+
h("button", { style: btnPrimary, onClick: executeSoftReload }, "我已知晓,开始软刷新"),
|
|
1493
|
+
h("button", { style: btnBase, onClick: function () { setSrConfirm(false); } }, "取消")
|
|
1494
|
+
)
|
|
1495
|
+
)
|
|
1496
|
+
: null
|
|
1379
1497
|
),
|
|
1380
1498
|
|
|
1381
1499
|
h("div", { style: surfaceCard },
|
|
@@ -1585,9 +1703,14 @@ window.__ModuleLoader__.load({
|
|
|
1585
1703
|
}
|
|
1586
1704
|
|
|
1587
1705
|
function apply(ctx) {
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1706
|
+
var disposeSection = null;
|
|
1707
|
+
try {
|
|
1708
|
+
installStreamGuard();
|
|
1709
|
+
applyCssOptimization(runtimeConfig);
|
|
1710
|
+
disposeSection = registerSettingsSection(ctx);
|
|
1711
|
+
} catch (err) {
|
|
1712
|
+
try { console.error("[dsh-light-guard] apply failed:", err); } catch {}
|
|
1713
|
+
}
|
|
1591
1714
|
return function () {
|
|
1592
1715
|
try { if (typeof disposeSection === "function") disposeSection(); } catch {}
|
|
1593
1716
|
};
|
|
@@ -1599,3 +1722,9 @@ window.__ModuleLoader__.load({
|
|
|
1599
1722
|
return module.exports;
|
|
1600
1723
|
}
|
|
1601
1724
|
});
|
|
1725
|
+
} catch (err) {
|
|
1726
|
+
if (!/duplicate factory registration/i.test(String(err && err.message || err))) {
|
|
1727
|
+
if (typeof queueMicrotask === "function") queueMicrotask(function () { throw err; });
|
|
1728
|
+
else setTimeout(function () { throw err; }, 0);
|
|
1729
|
+
}
|
|
1730
|
+
}
|