feat(diag): 增加现场诊断上报通道 (v0.5.3-local.15)

内嵌视图(DS Bot 等)没有 DevTools,无法读取插件运行现场。新增:
- 服务端 /api/worktable/diag(需鉴权):把客户端上报的 JSON 追加到
  <DSH_HOME>/logs/worktable-diag.log
- 客户端 apply() 在 1.5s/5s 各上报一次:href、__ModuleLoader__ 类型、
  style[data-dsh-plugin] 数量、.dsh-wt_section/.dsh-wt_edgeStrip 数量、
  sidebar/overlayHost 是否存在、body 子元素数、窗口宽度、最近 5 条 window 错误

用途:确认 DS Bot 视图里插件 client 是否加载、哪个座位渲染,据此再修复。
验证:npm run pack 全绿,双资产同源 aafb7ab2…。
This commit is contained in:
wangheng
2026-12-04 09:19:49 +08:00
parent 64a1d46b46
commit 3e7e2799c4
8 changed files with 120 additions and 12 deletions
+22 -1
View File
@@ -382,7 +382,7 @@ function resolveDshHomeSafe() {
cachedDshHome = baseDshHome();
return cachedDshHome;
}
var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.14";
var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.15";
var name = "dsh-worktable";
var inject = ["webServer", "sessions"];
var HEALTH_PATH = "/api/worktable/health";
@@ -1141,6 +1141,27 @@ function apply(ctx) {
}
}
});
register({
kind: "exact",
path: "/api/worktable/diag",
handler: async (req, res) => {
if (req.method !== "POST") {
json(res, 405, { error: "method not allowed" });
return;
}
try {
const body = await readJsonBody(req);
const line = (/* @__PURE__ */ new Date()).toISOString() + " " + JSON.stringify(body ?? null).slice(0, 4e3);
const fsx = await import("node:fs/promises");
const dir = pathResolve(resolveDshHomeSafe(), "logs");
await fsx.mkdir(dir, { recursive: true });
await fsx.appendFile(pathResolve(dir, "worktable-diag.log"), line + String.fromCharCode(10), "utf8");
json(res, 200, { ok: true });
} catch (err) {
json(res, 500, { error: String(err?.message ?? err) });
}
}
});
setupTerminal(webServer, ctx);
}
export {