dsh-light-guard 0.6.1 → 0.7.0

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,13 @@
6
6
 
7
7
  ---
8
8
 
9
+ ## v0.7.0 (2026-11-27)
10
+ - **发现的问题**:用户反馈“单个会话工作时间长了会变卡,必须重启 DSH 才能恢复”,但此前无法一眼判断内存压力来自前端 Chromium 渲染进程还是后端 Node 宿主进程,导致很多只需要刷新前端视图的情况也被迫重启整个 DSH、打断后台任务。
11
+ - **改了什么**:
12
+ - 在 `GET /api/dsh-light-guard/scan` 中新增按需一次性读取 `process.memoryUsage()`(RSS / Heap / External / 运行时长),依然保持零后台轮询;
13
+ - 在「体检与快照」页顶部新增 **「前后端内存归因与操作建议」** 卡片:并排展示前端 JS 堆 + DOM 与后端 Node RSS,自动分诊给出客观建议(压力偏向前台 vs 偏向后端 vs 正常),并提供一键 **「软刷新前端界面(不中断后台)」** 按钮;
14
+ - 同步将前后端内存读数写入「复制客观摘要(给 AI)」。
15
+
9
16
  ## v0.6.1 (2026-11-27)
10
17
  - **发现的问题**:
11
18
  1. DSH 插件市场中已存在早先收录的同名 GitHub 仓库(`TaoLe-si/dsh-perf-guard`),直接沿用 `dsh-perf-guard` 会导致用户在市场搜索时混淆装错;
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  ### 它能帮你做什么
14
14
  - **给侧边栏瘦身(只移不删)**:把超龄/超大历史会话安全移到冷归档目录,支持**按标题离线搜索**并随时**一键原位还原**。
15
15
  - **给超长会话减负**:在设置页里可调参的流窗口裁剪 + 纯 CSS 离屏跳过渲染 + 挂机减负模式,**不改原始日志、不改模型上下文**。
16
- - **一键揪出卡顿元凶**:点一下「立即体检」扫出爆棚的会话与插件存储目录,提供**一键打开文件夹**和**插件前后对比快照(Δ)**。
16
+ - **一键揪出卡顿元凶 + 前后端内存归因**:点一下「立即体检」即可区分压力来自**前端 Chromium 渲染进程**还是**后端 Node 宿主进程**,并给出客观操作建议(压力在前台可一键**软刷新前端界面、不中断后台任务**;压力在后端则明确提示择机重启),同时扫出爆棚的会话与插件存储目录,支持**一键打开文件夹**和**插件前后对比快照(Δ)**。
17
17
  - **零后台负担**:平时 0 定时器、0 rAF 循环、0 报错心跳;装了 `dsh-lag-guard` 时自动避让共存。
18
18
  - **实验性功能(默认关闭)**:按需开启 GPU 极简合成(禁用毛玻璃/阴影 + 代码块限高)、激进渲染裁剪(≤40 条 / 4KB 截断)、流式输出帧节流(80–250ms),以及 30 秒按需 LoAF 卡顿脚本归因采样器。
19
19
 
package/lib/client.js CHANGED
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({
19
19
  var h = React.createElement;
20
20
 
21
21
  var PLUGIN_NAME = "dsh-light-guard";
22
- var VERSION = "0.6.1";
22
+ var VERSION = "0.7.0";
23
23
  var API_PREFIX = "dsh-light-guard";
24
24
  var LOCAL_CACHE_KEY = "dsh.lightGuard.config.v1";
25
25
  var STYLE_ELEMENT_ID = "dsh-light-guard-style";
@@ -860,14 +860,66 @@ window.__ModuleLoader__.load({
860
860
  });
861
861
  }
862
862
 
863
+ 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
871
+ };
872
+ }
873
+
874
+ function diagnoseMemory(rMem, hMem) {
875
+ var frontHigh = (rMem && rMem.jsHeapUsedMB !== null && rMem.jsHeapUsedMB >= 250) || (rMem && rMem.domNodes >= 6000);
876
+ var backHigh = !!(hMem && (hMem.rssMB >= 1200 || (hMem.uptimeHours >= 24 && hMem.rssMB >= 800)));
877
+ if (frontHigh && !backHigh) {
878
+ return {
879
+ color: "#d97706",
880
+ bg: "rgba(245,158,11,0.12)",
881
+ badge: "压力偏向前台",
882
+ suggestSoftReload: true,
883
+ advice: "前端渲染进程(Chromium)堆内存或 DOM 偏高,而后端 Node 进程正常。点「软刷新前端界面」即可瞬间释放前端内存,无需重启整个 DSH,后台 Agent 任务不会中断。"
884
+ };
885
+ }
886
+ if (!frontHigh && backHigh) {
887
+ return {
888
+ color: "#ef4444",
889
+ bg: "rgba(239,68,68,0.12)",
890
+ badge: "压力偏向后端",
891
+ suggestSoftReload: false,
892
+ advice: "后端 Node 宿主常驻内存(RSS)偏高,单纯刷新前端页面无法释放后端内存。建议等当前任务结束后正常重启一次 DSH,并用下方「插件前后性能对比快照」排查是否有常驻插件持续占用内存。"
893
+ };
894
+ }
895
+ if (frontHigh && backHigh) {
896
+ return {
897
+ color: "#ef4444",
898
+ bg: "rgba(239,68,68,0.12)",
899
+ badge: "前后端均偏高",
900
+ suggestSoftReload: true,
901
+ advice: "前端渲染进程与后端 Node 内存均偏高。建议先冷归档超龄旧会话,并在无活跃任务时正常重启一次 DSH 彻底释放;若当前有后台任务不便重启,可先点「软刷新前端界面」缓解界面卡顿。"
902
+ };
903
+ }
904
+ return {
905
+ color: "#10b981",
906
+ bg: "rgba(16,185,129,0.12)",
907
+ badge: "内存占用正常",
908
+ suggestSoftReload: false,
909
+ advice: "前后端内存占用均处于正常区间,无需为内存重启 DSH。若仍偶发操作卡顿,可到「概览与预设 → 实验性功能」跑一次 30 秒卡顿脚本归因采样。"
910
+ };
911
+ }
912
+
863
913
  function doCopySummaryForAI() {
864
914
  if (!scan) return;
915
+ var rMem = readRendererMemory();
916
+ var hMem = scan.hostMemory || null;
865
917
  var lines = [
866
918
  "[dsh-light-guard 只读体检摘要 v" + VERSION + "]",
867
919
  "注意:以下为客观观测数据;第三方插件 storages/ 与附件目录请勿直接删除,仅可按对应插件说明处理。",
868
920
  "- 体检时间: " + scan.scannedAt,
869
- "- 当前页面 DOM: " + liveDom.domNodes + " | 流守卫状态: " + streamState.status + " | 当前预设: " + cfg.preset,
870
- "- 宿主已运行: " + (hostUptimeSec / 3600).toFixed(1) + " h",
921
+ "- 前端内存与 DOM: DOM=" + rMem.domNodes + (rMem.jsHeapUsedMB !== null ? (" | JS堆=" + rMem.jsHeapUsedMB + " MB") : "") + " | 流守卫=" + streamState.status + " | 当前预设=" + cfg.preset,
922
+ "- 后端宿主内存: " + (hMem ? ("RSS=" + hMem.rssMB + " MB | Node堆=" + hMem.heapUsedMB + " MB | 已运行=" + hMem.uptimeHours + " h") : ("已运行=" + (hostUptimeSec / 3600).toFixed(1) + " h")),
871
923
  "- 活跃会话: " + scan.sessions.totalCount + " 个 (" + scan.sessions.totalMB + " MB),其中 30 天前 " + scan.sessions.buckets.olderThan30d.count + " 个 (" + scan.sessions.buckets.olderThan30d.mb + " MB),近 7 天 " + scan.sessions.buckets.recent7d.count + " 个",
872
924
  "- 冷归档库: " + (archList ? archList.totalCount + " 个 (" + archList.totalMB + " MB)" : "未加载"),
873
925
  "- 插件存储 Top 目录 (只读): " + scan.storages.dirs.slice(0, 6).map(function (d) { return d.name + "=" + d.files + "文件/" + d.mb + "MB"; }).join("; ")
@@ -1283,8 +1335,50 @@ window.__ModuleLoader__.load({
1283
1335
  ) : null,
1284
1336
 
1285
1337
  // ── TAB 2: Doctor & Snapshots ──
1286
- activeTab === "doctor" ? h("div", null,
1287
- h("div", { style: surfaceCard },
1338
+ activeTab === "doctor" ? (function () {
1339
+ var rMem = readRendererMemory();
1340
+ var hMem = scan && scan.hostMemory ? scan.hostMemory : null;
1341
+ var memDiag = diagnoseMemory(rMem, hMem);
1342
+ return h("div", null,
1343
+ // Memory Attribution & Soft UI Reload Card (zero-polling, on-demand)
1344
+ h("div", { style: surfaceCard },
1345
+ 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" } },
1347
+ h("span", { style: { fontWeight: 600 } }, "前后端内存归因(按需读数 · 零轮询)"),
1348
+ h(Pill, { bg: memDiag.bg, color: memDiag.color }, memDiag.badge)
1349
+ ),
1350
+ 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
+ }, "软刷新前端界面(不中断后台)")
1359
+ ),
1360
+ h("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: "8px", marginBottom: "8px", fontSize: "12px" } },
1361
+ h("div", { style: { padding: "8px 10px", borderRadius: "8px", background: "rgba(128,128,128,0.06)" } },
1362
+ h("div", { style: { opacity: 0.72, fontSize: "11px" } }, "前端界面(Chromium 渲染进程)"),
1363
+ h("div", { style: { fontWeight: 700, fontSize: "14px", marginTop: "2px" } },
1364
+ (rMem.jsHeapUsedMB !== null ? (rMem.jsHeapUsedMB + " MB 堆") : "浏览器未暴露堆读数") + " · " + rMem.domNodes.toLocaleString() + " DOM"
1365
+ )
1366
+ ),
1367
+ h("div", { style: { padding: "8px 10px", borderRadius: "8px", background: "rgba(128,128,128,0.06)" } },
1368
+ h("div", { style: { opacity: 0.72, fontSize: "11px" } }, "后端宿主(Node 进程)"),
1369
+ h("div", { style: { fontWeight: 700, fontSize: "14px", marginTop: "2px" } },
1370
+ hMem
1371
+ ? (hMem.rssMB + " MB RSS · " + hMem.heapUsedMB + " MB 堆(已运行 " + hMem.uptimeHours + " h)")
1372
+ : "点击下方「重新体检」读取后端内存"
1373
+ )
1374
+ )
1375
+ ),
1376
+ h("div", { style: { fontSize: "12px", padding: "7px 10px", borderRadius: "7px", background: memDiag.bg, color: memDiag.color, lineHeight: 1.5 } },
1377
+ memDiag.advice
1378
+ )
1379
+ ),
1380
+
1381
+ h("div", { style: surfaceCard },
1288
1382
  h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: "8px", flexWrap: "wrap", marginBottom: "10px" } },
1289
1383
  h("span", { style: { fontWeight: 600 } }, "存储与会话按需体检(只读)"),
1290
1384
  h("div", { style: { display: "flex", gap: "6px" } },
@@ -1382,7 +1476,8 @@ window.__ModuleLoader__.load({
1382
1476
  })
1383
1477
  ) : h("div", { style: { opacity: 0.72, fontSize: "12px" } }, "在增删第三方插件前后各拍一张快照,自动用红/绿徽章标出 DOM 与存储增量。")
1384
1478
  )
1385
- ) : null,
1479
+ );
1480
+ })() : null,
1386
1481
 
1387
1482
  // ── TAB 3: Reversible Cold Archive ──
1388
1483
  activeTab === "archive" ? h("div", null,
package/lib/index.js CHANGED
@@ -143,9 +143,18 @@ export function registerRoutes(
143
143
  );
144
144
  });
145
145
 
146
- // 2. On-demand read-only scan
146
+ // 2. On-demand read-only scan (includes one-shot Node process.memoryUsage() attribution)
147
147
  reg("scan", ["GET"], async (_request, home) => {
148
148
  const report = await mods.scanner.runFullScan(home);
149
+ const mem = process.memoryUsage();
150
+ const toMB = (b) => Math.round((Number(b || 0) / 1048576) * 10) / 10;
151
+ report.hostMemory = {
152
+ rssMB: toMB(mem.rss),
153
+ heapUsedMB: toMB(mem.heapUsed),
154
+ heapTotalMB: toMB(mem.heapTotal),
155
+ externalMB: toMB(mem.external),
156
+ uptimeHours: Math.round((process.uptime() / 3600) * 10) / 10
157
+ };
149
158
  return Response.json({ ok: true, report });
150
159
  });
151
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-light-guard",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "author": "unifilitence",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",