dsh-lan-guard 0.3.6 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,147 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.3] — 2026-09-28(改用 dsh-mobile 式「高度链」修正,移除自建补丁)
4
+
5
+ ### 方向修正 — 不再给内容层打 overflow 补丁
6
+
7
+ **对照实验(用户实测)**:3080 直连(本插件注入不生效)**能正常拖动**;3081 经代理(注入生效)**拖不动**;而 dsh-mobile 在**同一套官方 UI、同一台手机**上可用。
8
+
9
+ **dsh-mobile 的做法是移动端「高度链」**(`src/mobile-layout.ts`):
10
+
11
+ ```css
12
+ html, body, #root { height:100%; overflow:hidden }
13
+ .dshm-shell { height:100dvh } /* dvh,不是 vh */
14
+ .dshm-main { min-height:0 } /* flex/grid 子项允许收缩 */
15
+ ```
16
+
17
+ **根因**:官方外壳在窄屏 iOS 下高度链断裂——实测内容 1688 被裁在 844 的层里,而官方认定的滚动层 `[data-conversation-scroll]` 永远 754/754(内容没进它的流)。后果:手指拖不动、官方「回到底部」点了没反应、**打开会话也不会停在最新消息**。0.4.1/0.4.2 给内容层打 `overflow-y:auto !important` 是治标,并引发了白屏与抽屉遮罩两个副作用。
18
+
19
+ **0.4.3 的做法**(`mobileScrollFix`):
20
+
21
+ 1. 给 `html/body/#root` 一个确定高度(`100%`,支持时 `100dvh`)并锁住页面滚动;
22
+ 2. 沿「被裁且内容溢出」的那一层,给链上所有 flex/grid 容器补 `min-height:0`;
23
+ 3. **立刻验证**官方认定的滚动层是否真的能滚:能 → 保留;**不能 → 全部撤销**,页面回到与官方逐字节一致(宁可不动,也不引入第二个滚动层);
24
+ 4. 遮罩/对话框打开时同样先撤销(0.4.2 遮罩事故的教训)。
25
+
26
+ **移除**:自建「回到底部」按钮(官方按钮恢复工作,且打开会话会自动停在最新)、内容层 `overflow-y`/`touch-action` 补丁、`-webkit-overflow-scrolling`。
27
+
28
+ ### 补充(同日真机诊断后)— 触摸放行
29
+
30
+ 真机 `?lgdiag=1` 的决定性数据:`official scroll layer already works`——官方滚动层**是可滚的**,但手指拖不动。结论:**触摸被全屏视觉层吃掉**(`pI_x6G_overlayLayer` / `dsh-sc-layer` 这类 `position:absolute/fixed` 的全屏层,在 iOS 上 `pointer-events:auto` 会拦截触摸;桌面 Chrome 的滚轮走另一条路径,所以本地一直"能拖")。
31
+
32
+ 新增 `touchPassThrough()`:只对**纯视觉容器**放行触摸(全屏覆盖、`pointer-events` 非 none、不含 button/input/textarea/select/[contenteditable]、文本 <40 字符),设 `pointer-events:none !important`;真正的交互层一律不碰。
33
+
34
+ ### 兼容性声明 — DSH 0.2.0-rc.1
35
+
36
+ - `dsh.engines.dsh`、`peerDependencies['@deepseek-ai/dsh-client-connection']` 与 `peerDependencies['@deepseek-ai/dsh-host-webserver']` 的上界由 `<0.2.0` 放宽为 `<0.3.0`,`dsh.compatibility.dshReleases` 新增 `0.2.0-rc.1: compatible`。旧上界是一颗定时炸弹:profile 加载会拒绝范围不含运行版本的 bundle,而裸的 `<0.2.0` 恰好排除 DSH `0.2.0` 正式版——正式版发布当天本插件会被静默丢弃。
37
+ - 依据:本插件正以 link 方式运行在当前 DSH `0.2.0-rc.1` profile 中(无 skipping 警告);`dsh.client.inject` 涉及的宿主包(`dsh-client-ui-renderer`、`dsh-client-ui-layout`、`dsh-client-ui-settings(-general)`)与 peer 包(`dsh-client-connection`、`dsh-host-webserver`)在 `dsh-v0.1.7-rc.2` → `dsh-v0.2.0-rc.1` 之间仅有版本号改动,本插件用到的接口面(`webServer.register` / `tapIndex`、`connection.requestRejection`、`connection.authenticatedUrl`、`settings.section` seat)无一变化。仅声明,零代码。
38
+
39
+ ### 升级
40
+
41
+ ```sh
42
+ dsh plugin --profile web add dsh-lan-guard@latest
43
+ ```
44
+
45
+ 重启一次 dsh 生效。
46
+
47
+ ## [0.4.2] — 2026-09-28(手机端补上「回到底部」按钮)
48
+
49
+ ### 修复 — 手机上滚动到中间时没有回到底部的按钮
50
+
51
+ **症状**(2026-09-28 用户报告):0.4.1 之后手机已经能滚动、也能看到最新内容,但**滚到消息中间时右下角没有「回到底部」的下箭头**,只能手动往回滑。
52
+
53
+ **根因(官方源码 + 真机视口诊断)**:官方自带这个按钮(`chat.toBottom`),显示条件是「不在尾部」(`!scroll.followingTail`),而这个判断基于官方认定的滚动层。窄屏下官方布局(`dsh-client-ui-layout` 的 `pI_x6G_frame`)承担了实际滚动,而 conversation 的 `[data-conversation-scroll]` 层内容高度并没有跟着涨——实测 `convScroll 754/754`,同时 `pI_x6G_frame 844/1688`。两边不一致 → 官方永远以为还在尾部 → 按钮不出现。
54
+
55
+ **改动**(并入 `mobileScrollFix`,窄屏 + 移动端生效):网关侧自带一个「回到底部」按钮:
56
+ - 不依赖官方内部状态:每次滚动/尺寸变化后,找出**当前真正在滚动的容器**(滚动量最大且可见者),不在尾部时显示 36px 圆形浮动按钮,点击平滑滚到底;
57
+ - **自动避让**:一旦检测到官方按钮(`aria-label` 含「底部」或 `bottom`)出现,自己的按钮立即移除,不会出现两个;
58
+ - **自动避开输入框**:按输入框位置动态计算按钮的 `bottom`(键盘弹出、快捷回复展开时不会压住输入区)。
59
+
60
+ ### 修复 — 打开左侧边栏被遮罩盖住(0.4.2 内的回归修复)
61
+
62
+ **症状**:0.4.2 的滚动矫正上线后,手机上打开左侧边栏会被一层灰雾盖住、点不动。
63
+ **根因(用户 A/B 实测确认)**:矫正给内容滚动层加了 `overflow-y:auto !important`(以及 `-webkit-overflow-scrolling:touch`),与官方抽屉打开时的滚动锁定/层级互相打架;把 `mobileScrollFix` 关掉即恢复正常。
64
+ **改动**:检测到全屏遮罩/对话框(`[aria-modal=true]` / `[role=dialog]` / `[data-conversation-overlay]`,或命中点上方有覆盖 ≥85% 视口的定位层)时,**完全撤销**自己加过的样式并隐藏自己的按钮,把页面还给官方;抽屉关闭后再应用。同时**去掉 `-webkit-overflow-scrolling`**(iOS 会为它强制合成层,正是层级错乱的来源)。
65
+
66
+ ### 升级
67
+
68
+ ```sh
69
+ dsh plugin --profile web add dsh-lan-guard@latest
70
+ ```
71
+
72
+ 重启一次 dsh 生效。
73
+
74
+ ## [0.4.1] — 2026-09-28(修掉手机端「聊天区滑不动」)
75
+
76
+ ### 修复 — 手机上会话内容可见但无法上下滑动
77
+
78
+ **症状**(2026-09-28 用户报告):手机上打开会话,最新内容能看到一部分,但**无法上下滑动**;底部固定的「目标条 / 快捷回复 / 输入框」压住内容,右侧滚动条停在中途。
79
+
80
+ **定位(诊断数据来自真实 iPhone 视口)**:DSH 官方外壳在**窄屏 + 移动端**下的根层 `pI_x6G_frame` 是 `overflow:hidden` 且内容溢出——实测 `clientHeight=844 / scrollHeight=1688`,同时**整页也不可滚**(`pageScrolls=false`)。内容被裁在容器里,手指自然滑不动。同一视口在桌面 Chrome 上滚动正常,因此这是 iOS/窄屏的布局差异,**与反向代理无关**(页面 DOM/CSS 全部来自官方 UI)。
81
+
82
+ **改动**:新增默认开启的 `mobileScrollFix`。注入的脚本**只在四个条件同时成立时**才动手:窄屏(≤1023px)、移动端 UA、**整页不可滚**、且**确实找到被裁剪且内容溢出的层**;然后只把那几层改为可触摸滚动(`overflow-y:auto`、`-webkit-overflow-scrolling:touch`、`touch-action:pan-y`)。能正常滚动的页面一律不碰(实测:桌面视口与健康页面下 no-op)。诊断:页面 URL 加 `?lgdiag=1` 会显示一屏布局数据(`narrow/mobile/innerH/pageScrolls/clippingLayers/是否已修`)。
83
+
84
+ ### 真机验收(2026-09-28 用户实测通过)
85
+
86
+ 同一台 iPhone(16 Pro Max)上验证:
87
+
88
+ | 场景 | 结果 |
89
+ | --- | --- |
90
+ | 打开长会话 | 能看到最新内容、可上下滑动(修复前内容被裁、滑不动) |
91
+ | **锁屏 60 秒后回来** | 会话仍在、**无需重连**,回来后直接发消息成功 |
92
+ | 代理侧记录(同轮) | 最长一条连接存活 **86.4 秒**且**正常 Close**;整轮**无 `1006` 异常断开**;代答心跳累计 **274 次**。对照 0.3.6 基线:静默客户端 ~6 秒即被 `1006` 切断 |
93
+
94
+ ### 同时
95
+
96
+ - `mobileCompat`(垫片)与 `socketWatchdog`(看门狗)**保持关闭**:`0.4.0` 曾让手机整页空白,在确认到具体成因前不默认开启。代理代答心跳 `answerHeartbeat` 保持开启(本次问题的另一处真修复,不碰页面)。
97
+
98
+ ### 升级
99
+
100
+ ```sh
101
+ dsh plugin --profile web add dsh-lan-guard@latest
102
+ ```
103
+
104
+ 重启一次 dsh 生效。
105
+
106
+ ## [0.4.0] — 2026-09-28(手机长连接自愈:代理代答心跳 + 页面看门狗 + 兼容垫片)
107
+
108
+ ### 修复 — 手机端「会话载入不全,甚至断开」
109
+
110
+ **症状**(2026-09-28 用户报告,附手机截图):手机上打开会话,界面、目标条、统计数字都在,唯独对话区永久停在「载入历史…」,并反复断开;同一网络下别的局域网入口却看不出来。
111
+
112
+ **定位(实测,不是推测)**:会话记录**只走 WebSocket**(`/api/remote.mux` 上的 `session/follow`),会话列表/goal/统计则来自 HTTP——所以症状的形状是「界面在、对话空」。
113
+
114
+ 1. 宿主每 2 秒 Ping 一次,连续两次没被回应就 `terminate`(`websocketHeartbeatIntervalMs: 2000`、`MAX_MISSED_HEARTBEATS: 2`)。
115
+ 2. 用真实 DSH 实测:客户端停止回 Pong 后 **6.0 秒**被切断,`close 1006`(连 Close 帧都没有),三处独立复现(直连 3081、经转发、浏览器冻结主线程各一次)。
116
+ 3. 手机锁屏/切走时页面被系统挂起,回不了心跳;WebKit 另有一类已知问题:后台恢复后 `new WebSocket()` 永久停在 CONNECTING,而 HTTP 一切正常。
117
+ 4. 缺现代 API 的引擎(`AbortSignal.any` 等)会在 DSH 的会话流里抛错,而 `Session.doOpen` 会把非传输类异常原样抛出——界面上就只剩「载入历史…」,**连报错都没有**。
118
+
119
+ **改动**(三层,默认全开、可逐项关闭):
120
+
121
+ - **`answerHeartbeat`(代理代答心跳)**:新增 `src/ws-heartbeat.ts`,在中转时只读地解析上游→浏览器方向的 WS 控制帧,遇到 Ping 立刻以客户端身份回一个掩码 Pong。RFC 6455 允许未经请求的 Pong,宿主只按「收到过 Pong」重置计数,手机自己回的重复包无害。**实测:停回心跳 6 秒被切断 → 代答后 20 秒以上存活。** 转发仍是纯字节管道,观察器最多只累积 14 字节头(Ping 再多 125 字节),异常即永久退出(fail-open)。
122
+ - **`socketWatchdog`(断线看门狗)**:服务端注入的页面补丁。卡在 CONNECTING 超过 8 秒的 socket 会被关掉;从后台回来 10 秒后仍一条都没连上时重载一次(每标签连续最多 3 次,冷却 20 秒起、成功连上即清零)。从未建过 socket 的页面永远不会被重载。
123
+ - **`mobileCompat`(移动端兼容垫片)**:补 `AbortSignal.any`/`AbortSignal.timeout`/`Promise.withResolvers`/`Iterator`,并把 viewport 换成带 `viewport-fit=cover` 的那一条、补 `apple-mobile-web-app-*` 与 `theme-color`。每个垫片都只在缺失时安装;**不禁用缩放**(本插件的移动端契约不是拿走用户的捏合手势)。
124
+
125
+ ### 新增 — 「连接与证书 → 手机连接与自愈」+ 连接体检
126
+
127
+ - 三个开关的控件都在这里,每个都写明「为什么需要它」。
128
+ - **连接体检**在这个浏览器里跑:缺哪些 API、页面拿到了哪些补丁、对当前地址做一次真实 WebSocket 握手(12 秒超时会把「卡在 CONNECTING」单独报出来)。
129
+ - 代理侧计数:在活连接、累计升级、被拒次数、**代答心跳次数**,以及最近 12 条连接的时长、上下行字节、是否异常断开(无 Close 帧)。计数器是有界环形缓冲,不写日志文件。
130
+
131
+ ### 验证
132
+
133
+ - 新增/更新用例,测试套件 **349 项**全绿(0.3.6 为 330)。
134
+ - 心跳代答有端到端用例:上游按 40ms 心跳、漏 2 次即 destroy —— **关掉代答必被回收、打开代答连接存活**。
135
+ - 注入的页面脚本在测试里被执行(假环境 + 假时钟):超时关 socket、有 OPEN 不重载、无 socket 不重载、后台恢复才重载一次并按冷却与上限退避、隐藏时不重载。
136
+ - 浏览器实测(Chrome 154,经临时回环转发走完整插件链路):WS 握手 3ms、首帧 2.1MB 单帧 43–110ms、12 秒 310 帧无中断;无代答的连接在页面冻结 12 秒后收到 `close 1006`。
137
+ - 真实 DSH 上的装机验证在发布后进行(本机运行的是已安装的 0.3.6,需重装 + 重启 dsh 才生效)。
138
+
139
+ ### 升级
140
+
141
+ ```sh
142
+ dsh plugin --profile web add dsh-lan-guard@latest
143
+ ```
144
+
3
145
  ## [0.3.6] — 2026-09-26(远程也能添加工作区:修掉让远程管理台永远锁定的代理缺陷)
4
146
 
5
147
  ### 新增 — 远程设备可以添加工作区(智能分流 + 页面内目录浏览器)
package/README.md CHANGED
@@ -82,7 +82,7 @@ Then **restart DSH once** and open **Settings → 局域网访问**. After that
82
82
 
83
83
  ## Settings
84
84
 
85
- Everything lives under **Settings → 局域网访问**, in four tabs. The non-sensitive switches (`enabled`, `listenPort`, `listenHost`, `networkInterface`, `settingsUnlock`, `auth.mode`, `auth.adminPolicy`, `auth.adminProtection`, `auth.allowLoopback`, `auth.requirePairing`, `auth.requireApproval`) are editable directly; `listenPort` and `listenHost` take effect on the next DSH restart; `settingsUnlock` takes effect on the next page load; `dataDir` and `tls.*` are startup fields that need a profile-patch edit.
85
+ Everything lives under **Settings → 局域网访问**, in four tabs. The non-sensitive switches (`enabled`, `listenPort`, `listenHost`, `networkInterface`, `settingsUnlock`, `answerHeartbeat`, `socketWatchdog`, `mobileCompat`, `auth.mode`, `auth.adminPolicy`, `auth.adminProtection`, `auth.allowLoopback`, `auth.requirePairing`, `auth.requireApproval`) are editable directly; `listenPort` and `listenHost` take effect on the next DSH restart; `settingsUnlock`, `socketWatchdog` and `mobileCompat` take effect on the next page load while `answerHeartbeat` also applies to connections that are already open; `dataDir` and `tls.*` are startup fields that need a profile-patch edit.
86
86
 
87
87
  | Setting | Default | Effect |
88
88
  | --- | --- | --- |
@@ -96,6 +96,10 @@ Everything lives under **Settings → 局域网访问**, in four tabs. The non-s
96
96
  | Remote management rights | **this machine only** | Whether LAN devices may manage: "this machine only" is read-only; "password unlock" needs an unlock first; "not locked" adds no requirement. **Browsing directories and adding a workspace remotely needs one of the latter two.** |
97
97
  | Management needs an unlock | **on** | Turned off, a remote session that satisfies the policy may change settings directly — except under "this machine only", which never allows remote management. |
98
98
  | Official settings page on the LAN | **on** | DSH opens its official settings surface only to loopback pages, so a LAN device opening **Settings → Models** reports `settings are unavailable in this browser`. With this on, any device that passes the gate (phones included) can use those pages after a page refresh. It is a UI unlock, not a new privilege: the settings RPC is gated by the visitor gate either way, and DSH still redacts secret reads. Refresh the page to apply; no restart needed. |
99
+ | Answer the host heartbeat | **on** | DSH pings every WebSocket every 2 s and drops it after two unanswered pings (measured: 6 s). A suspended phone cannot answer, and the **session transcript** — the only part of the UI that rides that socket — then loads incompletely or disconnects. With this on the proxy answers instead; the phone's own Pong, when it arrives, is a harmless duplicate. Applies immediately, including to open connections. |
100
+ | Socket watchdog | **on** | Page patch: a WebSocket still in CONNECTING after 8 s is closed, and a page resumed with nothing open reloads itself once (at most three in a row per tab, backing off from 20 s). Only a page that genuinely cannot connect is affected. Applies on page refresh. |
101
+ | Mobile compatibility shims | **on** | Page patch: fills in `AbortSignal.any`/`AbortSignal.timeout`/`Promise.withResolvers`/`Iterator` and the mobile metas. Without those APIs DSH's client throws inside its session-stream path and the UI just sits on 「载入历史…」 with no error at all. On a modern engine every branch is a no-op. Applies on page refresh. |
102
+ | Narrow-screen scroll fix | **on** | DSH's own shell clips the conversation column on a phone (`pI_x6G_frame`, measured 844/1688) and the page cannot scroll, so content is visible but cannot be dragged. The patch only acts when narrow screen + mobile UA + page cannot scroll + a clipping overflowing layer exists; healthy pages are untouched. `?lgdiag=1` prints a layout report. Applies on page refresh. |
99
103
  | Require naming | **on** | A new device must name itself once before it appears in the device list. |
100
104
  | Require approval | off | When on, a named device still needs your **批准** before it is let in. |
101
105
  | TLS | **self-signed HTTPS** | Turning it off sends the gate password in clear; a non-loopback bind with TLS off is **refused at startup** unless you set `tls.allowInsecureLan: true`. |
@@ -114,6 +118,9 @@ The plugin reads its config from its Cordis entry. **Every key has a usable defa
114
118
  listenPort: 3081 # DSH port + 1; auto-walks up to 10 ports when taken
115
119
  networkInterface: en0 # optional: publish on one NIC (empty = automatic)
116
120
  settingsUnlock: true # LAN devices may use the official settings page (default on)
121
+ answerHeartbeat: true # proxy answers the WebSocket heartbeat (default on)
122
+ socketWatchdog: true # page-side socket watchdog (default on)
123
+ mobileCompat: true # mobile compatibility shims (default on)
117
124
  dataDir: ~/.dsh/profiles/web/data/dsh-lan-guard # optional; this is the derived default
118
125
  tls:
119
126
  mode: self-signed # 'self-signed' (default) | 'provided' | 'off'
@@ -140,10 +147,11 @@ The plugin reads its config from its Cordis entry. **Every key has a usable defa
140
147
 
141
148
  ## Compatibility
142
149
 
143
- Current version: plugin **`0.3.6`**; adding a workspace from a remote device, plus the proxy defect that kept the remote console locked forever (verified on DeepSeek Harness **`0.1.7-rc.2`**).
150
+ Current version: plugin **`0.4.0`**; mobile long-connection self-healing — the proxy answers DSH's WebSocket heartbeat, and the served page carries a socket watchdog plus mobile compatibility shims (verified on DeepSeek Harness **`0.1.7-rc.2`**).
144
151
 
145
152
  | Plugin | Verified DeepSeek Harness | What this version is |
146
153
  | --- | --- | --- |
154
+ | **`0.4.0`** | **`0.1.7-rc.2`**, `0.1.7-rc.1` | Mobile long-connection self-healing: the proxy answers DSH's WebSocket heartbeat (measured: 6 s reap without it, 20 s+ survival with it); page patches adding a socket watchdog and mobile compatibility shims; a connection health check and relay counters on the "connection" tab |
147
155
  | **`0.3.6`** | **`0.1.7-rc.2`**, `0.1.7-rc.1` | Adding a workspace from a remote device: the browser half shadows the official directory flow (the local browser keeps the OS dialog, a remote device gets an in-page browser and can unlock inside it); fixes the proxy dropping the plugin's admin cookie in both directions, which made `password_unlock` meaningless remotely; adds the missing "remote management rights" control; moves the "saved" confirmation to a top-right notification; reworks status-surface colours against measured contrast; fixes the picker's crushed breadcrumb/shortcut rows |
148
156
  | **`0.3.5`** | **`0.1.7-rc.2`**, `0.1.7-rc.1` | Connection-level visibility: an `http://` request to the TLS port goes from "blank page + no log" to a 301 onto `https` with a log line; a deleted device record no longer locks that browser out (revoked/blocked still refuse); the removal-page copy follows |
149
157
  | **`0.3.4`** | **`0.1.7-rc.2`**, `0.1.7-rc.1` | Official settings page on the LAN: a new `settingsUnlock` switch (on by default) that injects the host-surface marker into the index; applies on page refresh; a UI unlock, not a new privilege |
@@ -155,9 +163,33 @@ Current version: plugin **`0.3.6`**; adding a workspace from a remote device, pl
155
163
  | `0.1.1` | `0.1.7-rc.1` | Documentation release: bilingual user READMEs |
156
164
  | `0.1.0` | `0.1.7-rc.1` | First release: gated reverse proxy, self-signed HTTPS, device pairing, settings page, QR access |
157
165
 
158
- - Declared range `>=0.1.7-rc.1 <0.2.0` (`dsh.engines.dsh`); DSH versions not listed are **unverified** — verify them yourself before use.
166
+ - Declared range `>=0.1.7-rc.1 <0.3.0` (`dsh.engines.dsh`); verified releases: `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`. DSH versions not listed are **unverified** — verify them yourself before use. The upper bound was widened from `<0.2.0` in `0.4.3` because profile load refuses a bundle whose range excludes the running release, and a plain `<0.2.0` would exclude the `0.2.0` stable.
159
167
  - Host/client interfaces this plugin uses: `webServer.register` / `webServer.tapIndex` (indexTaps), `connection.requestRejection`, `connection.authenticatedUrl`, the additive `settings.section` seat, `@deepseek-ai/schemastery`, and `profileContext` (for deriving the default data directory).
160
168
  - **Breaking default change (from `0.3.2`)**: `listenHost` now defaults to `0.0.0.0` instead of `127.0.0.1`, so one restart after install is enough; `0.3.1` and earlier default to loopback only. The gate and self-signed TLS defaults are unchanged (with no password the gate still refuses every device). See the [CHANGELOG](CHANGELOG.md).
169
+ - **`0.4.0` verification status**: all three changes carry measurements, not just specs.
170
+ 1. **Proxy answers the heartbeat**: a Node client against the **real DSH** measured a **6.0 s** reap after it stopped sending Pongs (`close 1006`, no Close frame); with the answerer on the same link **survived 20 s** (10 pings answered). An end-to-end spec reproduces the pair against a DSH-shaped upstream (40 ms pings, destroy after two misses): **reaps without the answerer, survives with it**.
171
+ 2. **Page patches**: the injected scripts are **executed** in the suite against a fake environment and clock — "a socket stuck in CONNECTING is closed after 8 s", "never reloads while one socket is OPEN", "never reloads a page that created no socket", "reloads once after a resume with nothing open, then backs off within the cooldown and cap", "never reloads while hidden".
172
+ 3. **Browser verification** (BrowserSkill, Chrome 154, through a temporary loopback forward that still traverses the whole plugin path): `/api/remote.mux` handshake 3 ms; the `session/follow` snapshot arrives in 43–110 ms as a single 2.1 MB frame; 310 frames over 12 s with no interruption; and with the page's main thread frozen for 12 s a connection without the answerer received `close 1006`.
173
+ The suite is green at **349** specs (330 in 0.3.6). The real-DSH install verification follows the release (this machine runs the installed 0.3.6, so the code takes effect after a reinstall plus a DSH restart).
174
+
175
+ ### Why a phone's session socket dies (measured 2026-09-28)
176
+
177
+ The session transcript — the 「载入历史…」 part of the UI — **rides the WebSocket only**; the session list, the goal chip and the statistics arrive over HTTP, which is why the failure looks like "everything is there except the conversation". Three facts define it:
178
+
179
+ | Fact | Source |
180
+ | --- | --- |
181
+ | The host pings every 2 s and drops a socket after two unanswered pings | `websocketHeartbeatIntervalMs: 2000`, `MAX_MISSED_HEARTBEATS: 2` |
182
+ | A client that stops sending Pongs is dropped after **6.0 s** (`close 1006`, no Close frame) | measured three ways: direct on 3081, through a forward, and with a frozen browser main thread |
183
+ | A phone that switches away or locks its screen cannot answer | iOS suspends the page; WebKit additionally has a case where `new WebSocket()` stays in CONNECTING forever after a resume while HTTP keeps working |
184
+
185
+ Three layers ship in this release, all on by default and each individually switchable:
186
+
187
+ 1. **`answerHeartbeat`** — while relaying, the proxy reads the upstream→browser control frames and answers a Ping with a masked Pong on the client's behalf. RFC 6455 allows an unsolicited Pong and the host only resets its counter on "a Pong arrived", so the phone's own duplicate is harmless. This is the only layer that stops the host from reaping a suspended phone.
188
+ 2. **`socketWatchdog`** — the page-side half: close a socket that is stuck in CONNECTING, and reload once when a resume leaves nothing open.
189
+ 3. **`mobileCompat`** — `AbortSignal.any`/`timeout`, `Promise.withResolvers`, `Iterator` and the mobile metas. DSH's client calls `AbortSignal.any` on its session-stream path, and `Session.doOpen` re-throws non-transport errors, so a missing API shows up as a permanent 「载入历史…」 with no error text.
190
+
191
+ **Settings → 局域网访问 → 连接与证书 → 手机连接与自愈** carries a connection health check: it inspects which APIs this browser lacks, which patches the page received, runs a real WebSocket handshake against the current origin, and shows the proxy-side counters (open connections, upgrades, refusals, answered heartbeats) plus the last connection's duration, bytes and whether it died abnormally.
192
+
161
193
  - **`0.3.6` verification status**: the change spans the host side (a new directory-listing route and cookie relaying) and the client side (the directory browser, the settings controls, the notification and the colour rework). The suite is green at **330** specs (+57); all three commits were verified in isolation in their own worktrees (278 / 304 / 330 each passing); it was falsified (reverting the cookie relay, the no-shrink rule, or the hover-tint surface each fails its specs); and contrast was computed from DSH's real token values, 10/10 passing in light and dark. The real-DSH install verification follows the release.
162
194
  - **`0.3.5` verification status**: the changes touch only the proxy's connection-level handling and the gate's verdict; no host/client interface changed; the suite is green at **273** specs (+10) and was falsified (reverting a fix fails its specs); the real-DSH install verification follows the release.
163
195
  - **`0.3.4` verification status**: the change adds one host-side switch, one index injection and a switch on the plugin's own settings page (`webServer.tapIndex` is a declared host interface); the suite is green at **263** specs; the injected script was exercised in a real Chrome over a non-loopback address in three states; the real-DSH install verification follows the release.
@@ -169,6 +201,19 @@ The official UI is reused with zero modifications and adapts on a phone viewport
169
201
  <img src="./assets/mobile.png" width="30%" alt="The official DSH UI at a 390px phone viewport: the plugin only proxies, the interface is the official one">
170
202
  </p>
171
203
 
204
+ ### Why a phone "cannot see all messages" / cannot scroll (measured 2026-09-28)
205
+
206
+ **Symptom**: on a phone the newest content is partly visible but the column cannot be dragged, while the fixed goal / quick-reply / composer floats cover the text.
207
+
208
+ **Root cause (measured on the device viewport)**: on narrow screens DSH's own shell keeps the conversation in `pI_x6G_frame` with `overflow:hidden` while the content is taller — measured `clientHeight=844 / scrollHeight=1688` — and the page as a whole cannot scroll either (`pageScrolls=false`). The content is clipped, so it is visible but not draggable. The same viewport scrolls fine in desktop Chrome, so this is an iOS/narrow-screen layout difference, **not the reverse proxy** (all DOM/CSS comes from the official shell and the installed plugins).
209
+
210
+ **Fix (`mobileScrollFix`, on by default)**: the injected script only acts when narrow screen AND mobile UA AND the page cannot scroll AND it actually finds a layer clipping overflowing content; it then makes exactly those layers touch-scrollable (`overflow-y:auto`, `-webkit-overflow-scrolling:touch`, `touch-action:pan-y`). Healthy pages are never touched.
211
+
212
+ **"Back to bottom" button (from 0.4.2)**: on narrow screens the official button shows only when not at the tail, judged against the scroll layer the official code believes in — which is not the layer that actually scrolls, so it never appears. The gateway therefore ships an equivalent floating button (shown whenever the view is not at the bottom, smooth-scrolls on click, yields to the official button once that appears, and positions itself above the composer).
213
+
214
+ **Self-check**: append `?lgdiag=1` to the page URL for an on-screen report (`narrow / mobile / innerHeight / visualViewport / pageScrolls / clippingLayers / patched`). That report is exactly the data that located this bug.
215
+
216
+
172
217
  ## Security boundary
173
218
 
174
219
  - DSH's own listen address is never changed; the plugin modifies no DSH configuration, session data, or official UI.
package/README.zh.md CHANGED
@@ -82,7 +82,7 @@ dsh plugin --profile web add "link:$(pwd)"
82
82
 
83
83
  ## 设置
84
84
 
85
- 设置项集中在 **设置 → 局域网访问** 的四个 tab 里。非敏感开关(`enabled`、`listenPort`、`listenHost`、`networkInterface`、`settingsUnlock`、`auth.mode`、`auth.adminPolicy`、`auth.adminProtection`、`auth.allowLoopback`、`auth.requirePairing`、`auth.requireApproval`)可直接改;`listenPort` 与 `listenHost` 需重启 dsh 生效;`settingsUnlock` 刷新页面即可生效;`dataDir` 与 `tls.*` 属启动期字段,需在 profile patch 里改。
85
+ 设置项集中在 **设置 → 局域网访问** 的四个 tab 里。非敏感开关(`enabled`、`listenPort`、`listenHost`、`networkInterface`、`settingsUnlock`、`answerHeartbeat`、`socketWatchdog`、`mobileCompat`、`auth.mode`、`auth.adminPolicy`、`auth.adminProtection`、`auth.allowLoopback`、`auth.requirePairing`、`auth.requireApproval`)可直接改;`listenPort` 与 `listenHost` 需重启 dsh 生效;`settingsUnlock` / `socketWatchdog` / `mobileCompat` / `mobileScrollFix` 刷新页面即可生效,`answerHeartbeat` 立即对**已打开**的连接生效;`dataDir` 与 `tls.*` 属启动期字段,需在 profile patch 里改。
86
86
 
87
87
  | 设置项 | 默认 | 作用 |
88
88
  | --- | --- | --- |
@@ -96,6 +96,10 @@ dsh plugin --profile web add "link:$(pwd)"
96
96
  | 远程设备管理权限 | **仅本机** | 决定局域网设备能否管理:「仅本机」只读;「密码解锁」需先解锁;「不锁定」不额外要求。**远程浏览目录并添加工作区需要后两者之一**。 |
97
97
  | 管理操作需要先解锁 | **开** | 关闭后,符合策略的远程会话可直接修改设置(`local_only` 除外,它永远只允许本机)。 |
98
98
  | 局域网设备可用官方设置页 | **开** | DSH 官方设置面默认只对回环页面开放,局域网设备打开「设置 → 模型」会提示 `settings are unavailable in this browser`。开启后,通过门禁的设备(含手机)刷新页面即可使用官方设置页;这是界面解锁,不是新增权限——设置接口本来就只由门禁把关,读取密钥仍由 DSH 脱敏。刷新页面生效,无需重启。 |
99
+ | 代理代答心跳 | **开** | DSH 每 2 秒给每条 WebSocket 发心跳,连续两次没被回应就断开(实测 6 秒)。手机锁屏/切走时页面被系统挂起、回不了心跳,于是只走 WebSocket 的**会话记录**就会「载入不全、甚至断开」。开启后由代理替手机回心跳,手机自己回的那次是重复包,无副作用。立即生效(含已打开的连接)。 |
100
+ | 断线看门狗 | **开** | 页面补丁:卡在「连接中」超过 8 秒的 WebSocket 会被关掉;从后台回来 10 秒后仍一条都没连上时自动重载一次(每标签最多连续 3 次,冷却 20 秒起)。只对真的连不上的页面生效。刷新页面生效。 |
101
+ | 移动端兼容垫片 | **开** | 页面补丁:补 `AbortSignal.any`/`AbortSignal.timeout`/`Promise.withResolvers`/`Iterator` 与移动端 meta。缺这些 API 时 DSH 客户端在会话流里抛错,界面只会一直显示「载入历史…」且没有报错。现代浏览器上这些分支不生效。刷新页面生效。 |
102
+ | 手机滚动矫正(窄屏) | **开** | 手机端 DSH 外壳在窄屏下把对话列裁在 `overflow:hidden` 的层里(实测 844/1688),整页也不可滚 → 内容可见但**滑不动**。开启后只在「窄屏 + 移动端 + 整页不可滚 + 找到被裁剪溢出的层」四条同时成立时,把那几层改成可触摸滚动;正常页面不碰。页面加 `?lgdiag=1` 可看布局诊断。刷新页面生效。 |
99
103
  | 新设备需要命名确认 | **开** | 新设备首次通过门禁时要自己命名一次,之后才出现在设备列表里。 |
100
104
  | 新设备需要管理员批准 | 关 | 开启后,命名完还要你在设备列表点「批准」才能进入。 |
101
105
  | TLS | **自签 HTTPS** | 关闭会明文传输门禁密码;非回环 + 关闭 TLS 必须显式设置 `tls.allowInsecureLan: true`,否则**拒绝启动**。 |
@@ -114,6 +118,9 @@ dsh plugin --profile web add "link:$(pwd)"
114
118
  listenPort: 3081 # DSH 端口 + 1;被占用时自动顺延
115
119
  networkInterface: en0 # 可选:只在一个网卡上公布(留空 = 自动)
116
120
  settingsUnlock: true # 局域网设备可用官方设置页(默认开;关闭恢复 DSH 默认)
121
+ answerHeartbeat: true # 代理代答 WebSocket 心跳(默认开;手机挂起时不被宿主回收)
122
+ socketWatchdog: true # 页面断线看门狗(默认开)
123
+ mobileCompat: true # 移动端兼容垫片(默认开)
117
124
  dataDir: ~/.dsh/profiles/web/data/dsh-lan-guard # 可选;缺省即用这个推导路径
118
125
  tls:
119
126
  mode: self-signed # 'self-signed'(默认)| 'provided' | 'off'
@@ -144,6 +151,7 @@ dsh plugin --profile web add "link:$(pwd)"
144
151
 
145
152
  | 插件 | 已验证的 DeepSeek Harness | 这个版本是什么 |
146
153
  | --- | --- | --- |
154
+ | **`0.4.0`** | **`0.1.7-rc.2`**、`0.1.7-rc.1` | 手机长连接自愈:代理代答 DSH 的 WebSocket 心跳(实测把「停回心跳 6 秒被切断」变成「20 秒以上存活」);页面补丁加入断线看门狗与移动端兼容垫片;「连接与证书」新增连接体检与代理侧计数 |
147
155
  | **`0.3.6`** | **`0.1.7-rc.2`**、`0.1.7-rc.1` | 远程也能添加工作区:浏览器侧遮蔽官方目录流程(本机仍走系统对话框,远程改用页面内目录浏览器,可在弹层内解锁);修掉代理双向丢弃插件管理 cookie 导致 `password_unlock` 对远程形同虚设;补上一直缺失的「远程设备管理权限」控件;「已保存」改为右上角提示;状态表面配色按实测重做;弹层两行被压扁重叠 |
148
156
  | **`0.3.5`** | **`0.1.7-rc.2`**、`0.1.7-rc.1` | 连接层可见性:`http://` 访问 TLS 端口由「空白页 + 无日志」改为 301 跳 `https` 并记日志;删除设备记录后旧 cookie 不再把浏览器锁死(吊销/拉黑仍拒绝);移除页文案同步修正 |
149
157
  | **`0.3.4`** | **`0.1.7-rc.2`**、`0.1.7-rc.1` | 局域网设备可用官方设置页:新增默认开启的 `settingsUnlock` 开关(index 注入宿主界面标记,刷新页面生效;界面解锁而非新增权限) |
@@ -155,9 +163,33 @@ dsh plugin --profile web add "link:$(pwd)"
155
163
  | `0.1.1` | `0.1.7-rc.1` | 文档版:中英双语用户 README |
156
164
  | `0.1.0` | `0.1.7-rc.1` | 首个版本:门禁反向代理、自签 HTTPS、设备配对、设置页、扫码访问 |
157
165
 
158
- - 声明范围 `>=0.1.7-rc.1 <0.2.0`(`dsh.engines.dsh`);未列入的 DSH 版本属**未验证**,请自行验证后再使用。
166
+ - 声明范围 `>=0.1.7-rc.1 <0.3.0`(`dsh.engines.dsh`);已验证版本:`0.1.7-rc.1`、`0.1.7-rc.2`、`0.2.0-rc.1`。未列入的 DSH 版本属**未验证**,请自行验证后再使用。上界在 `0.4.3` 从 `<0.2.0` 放宽:profile 加载会拒绝范围不含运行版本的 bundle,而裸的 `<0.2.0` 恰好排除 `0.2.0` 正式版。
159
167
  - 本插件用到的宿主/客户端接口:`webServer.register` / `webServer.tapIndex`(indexTaps)、`connection.requestRejection`、`connection.authenticatedUrl`、追加型 `settings.section` seat、`@deepseek-ai/schemastery`,以及 `profileContext`(用于推导默认数据目录)。
160
168
  - **破坏性默认值变更(`0.3.2` 起)**:`listenHost` 默认由 `127.0.0.1` 改为 `0.0.0.0`,装完重启一次即可用;`0.3.1` 及更早默认仅回环。门禁与自签 TLS 的默认值未变(未设密码仍拒绝所有设备)。详见 [CHANGELOG](CHANGELOG.md)。
169
+ - **`0.4.0` 的验证状态**:三处改动都做了实测,不只跑用例。
170
+ 1. **代理代答心跳**:先用 Node 客户端对**真实 DSH** 测得「停止回 Pong 后 **6.0 秒**被切断,`close 1006`(无 Close 帧)」;再加上代答后同一条链路 **20 秒仍存活**(收到 10 次 Ping)。仓库里有一条端到端用例复现同一对行为(上游按 40ms 心跳、漏 2 次即 destroy):**关掉代答必被回收、打开代答连接存活**。
171
+ 2. **页面补丁**:注入的脚本在测试里**被执行**(假环境 + 假时钟),断言「卡在 CONNECTING 8 秒被关掉」「有一条 OPEN 就不重载」「从未建过 socket 不重载」「后台回来无 OPEN 才重载一次、并按冷却与上限退避」「隐藏状态不重载」。
172
+ 3. **浏览器实测**(BrowserSkill,Chrome 154,经临时回环转发走完整插件链路):`/api/remote.mux` 握手 3ms、`session/follow` 首帧 2.1MB 单帧 43–110ms、12 秒 310 帧无中断;同一页面把主线程冻结 12 秒时,无代答的连接收到 `close 1006`。
173
+ 测试套件 **349 项**全绿(0.3.6 为 330)。真实 DSH 上的装机验证在发布后进行(本机运行的是已安装的 0.3.6,需重装 + 重启 dsh 才生效)。
174
+
175
+ ### 手机长连接为什么会断(实测,2026-09-28)
176
+
177
+ 会话记录(就是界面上的「载入历史…」那一段)**只走 WebSocket**:会话列表、目标条、统计数字都来自 HTTP,所以 WS 一断就会呈现「界面都在、对话区空白」的形状。三个事实决定了这个失效模式:
178
+
179
+ | 事实 | 实测/来源 |
180
+ | --- | --- |
181
+ | 宿主每 2 秒 Ping 一次,连续两次没被回应才回收 | `websocketHeartbeatIntervalMs: 2000`、`MAX_MISSED_HEARTBEATS: 2` |
182
+ | 停止回 Pong 后 **6.0 秒**被切断(`close 1006`,无 Close 帧),三处独立复现 | 直连 3081、经转发、浏览器冻结主线程 |
183
+ | 手机切走/锁屏时页面被系统挂起,回不了心跳 | iOS 行为;WebKit 另有「后台恢复后 `new WebSocket()` 永久卡 CONNECTING 而 HTTP 正常」的已知问题 |
184
+
185
+ 因此本版本提供三层兜底,默认全开、可逐项关闭:
186
+
187
+ 1. **代理代答心跳(`answerHeartbeat`)**:代理在中转时读取上游→浏览器方向的 WS 控制帧,遇到 Ping 立刻以客户端身份回一个掩码 Pong。RFC 6455 允许未经请求的 Pong,宿主只按「收到过 Pong」重置计数,所以手机自己回的重复包无害。这是唯一能阻止宿主回收挂起手机连接的一层。
188
+ 2. **断线看门狗(`socketWatchdog`)**:页面侧兜住 WebKit 的「卡 CONNECTING」——超时关掉卡住的 socket,从后台回来仍连不上时限流重载一次。
189
+ 3. **移动端兼容垫片(`mobileCompat`)**:补 `AbortSignal.any`/`timeout`、`Promise.withResolvers`、`Iterator` 与移动端 meta。DSH 客户端在会话流里直接调用 `AbortSignal.any`,而 `Session.doOpen` 会把**非传输类异常原样抛出**——缺 API 时的表现就是「永久载入历史…、连报错都没有」。
190
+
191
+ 「连接与证书 → 手机连接与自愈」里有一个**连接体检**:它在这个浏览器里检查缺哪些 API、页面拿到了哪些补丁,并对当前地址做一次真实 WebSocket 握手,同时显示代理侧的计数(在活连接 / 累计升级 / 被拒 / 代答心跳次数)与最近一条连接的时长、上下行字节、是否异常断开。
192
+
161
193
  - **`0.3.6` 的验证状态**:改动包含宿主侧(新增目录列举路由与 cookie 中转)与客户端(目录浏览器、设置页控件、提示层与配色)。测试套件 **330 项**全绿(+57);三个提交在独立 worktree 里逐提交验证(278 / 304 / 330 各自通过);并做过反证(回退 cookie 中转、固定行不收缩、hover 染当背景,各自让对应用例失败);配色对比度按 DSH 真实 token 逐项计算,浅色/深色 10/10 通过。真实 DSH 上的装机验证在发布后进行。
162
194
  - **`0.3.5` 的验证状态**:改动只在代理的连接层处理与门禁判定,未改动任何宿主/客户端接口;测试套件 **273 项**全绿(+10),并做过反证(回退修复后对应用例失败);真实 DSH 上的装机验证在发布后进行。
163
195
  - **`0.3.4` 的验证状态**:改动只新增一个宿主侧开关、一行 index 注入与插件自己的设置页开关(`webServer.tapIndex` 是已声明的宿主接口);测试套件 **263 项**全绿;注入脚本已在真实 Chrome + 非回环地址实测三种状态;真实 DSH 上的装机验证在发布后进行。
@@ -169,6 +201,18 @@ dsh plugin --profile web add "link:$(pwd)"
169
201
  <img src="./assets/mobile.png" width="30%" alt="390px 手机视口下的官方 DSH 界面:插件只做代理,界面由官方原样提供">
170
202
  </p>
171
203
 
204
+ ### 手机上为什么「看不到全部消息」/ 滑不动(实测,2026-09-28)
205
+
206
+ **症状**:手机上打开会话,最新内容能看到一部分,但**手指滑不动**;底部固定的「目标条 / 快捷回复 / 输入框」压住正文,右侧滚动条停在中途。
207
+
208
+ **根因(真机视口实测)**:DSH 官方外壳在**窄屏**下的根层 `pI_x6G_frame` 是 `overflow:hidden`,而内容高于它——实测 `clientHeight=844 / scrollHeight=1688`,同时**整页也不可滚**(`pageScrolls=false`)。内容被裁在容器里,所以"看得见、滑不动"。同一视口在桌面 Chrome 上正常,因此这是 iOS/窄屏的布局差异,**与反向代理无关**(DOM/CSS 全部来自官方 UI 与已装插件)。
209
+
210
+ **修复(`mobileScrollFix`,默认开)**:注入脚本**只在四条同时成立时**才动手——窄屏(≤1023px)、移动端 UA、**整页不可滚**、且**确实找到被裁剪且内容溢出的层**;然后只把那几层改成可触摸滚动(`overflow-y:auto`、`-webkit-overflow-scrolling:touch`、`touch-action:pan-y`)。能正常滚动的页面一律不碰。
211
+
212
+ **「回到底部」按钮(0.4.2 起)**:窄屏下官方按钮的显示条件是「不在尾部」,而它判断的是官方认定的滚动层,与实际滚动层不一致,于是永远不出现;网关侧因此自带一个等价的浮动按钮(不在尾部时显示、点击平滑到底、官方按钮出现即让位、位置按输入框动态计算)。
213
+
214
+ **自检**:在页面地址后加 `?lgdiag=1`,顶部会出现一屏诊断(`narrow / mobile / innerHeight / visualViewport / pageScrolls / clippingLayers / 是否已修`)。这一屏就是本次定位所用的数据,以后复现同类问题不必连 Mac 调试。
215
+
172
216
  ## 安全边界
173
217
 
174
218
  - DSH 自身的监听地址不被改动;本插件从不修改 DSH 配置、会话数据或官方 UI。
package/lib/client.js CHANGED
@@ -1139,6 +1139,8 @@ window.__ModuleLoader__.load({
1139
1139
  const [portCheck, setPortCheck] = (0, react.useState)(null);
1140
1140
  const [update, setUpdate] = (0, react.useState)(null);
1141
1141
  const [updateBusy, setUpdateBusy] = (0, react.useState)(false);
1142
+ const [doctor, setDoctor] = (0, react.useState)(null);
1143
+ const [doctorBusy, setDoctorBusy] = (0, react.useState)(false);
1142
1144
  const noticeTimer = (0, react.useRef)(null);
1143
1145
  const clearNoticeTimer = (0, react.useCallback)(() => {
1144
1146
  if (noticeTimer.current !== null) {
@@ -1272,6 +1274,72 @@ window.__ModuleLoader__.load({
1272
1274
  setPortCheck("检查失败");
1273
1275
  }
1274
1276
  }, []);
1277
+ /**
1278
+ * Run the on-page half of the connection health check (P5).
1279
+ *
1280
+ * Everything here is measured in the VISITOR's own browser, which is the only
1281
+ * place the interesting facts live: which APIs this engine lacks (that is what
1282
+ * leaves a session stuck on 「载入历史…」 with no error), whether the injected
1283
+ * patches are present, and how long a real WebSocket handshake to this origin
1284
+ * takes. The host's own counters come from the snapshot, not from here.
1285
+ */
1286
+ const runDoctor = (0, react.useCallback)(async () => {
1287
+ setDoctorBusy(true);
1288
+ const lines = [];
1289
+ try {
1290
+ const patches = globalThis.__DSH_LAN_GUARD__ ?? {};
1291
+ lines.push(`页面补丁:官方设置页解锁 ${patches.settingsUnlock === true ? "✓" : "—"} · 移动端兼容垫片 ${patches.mobileCompat === true ? "✓" : "—"} · 断线看门狗 ${patches.socketWatchdog === true ? "✓" : "—"}`);
1292
+ const missing = [];
1293
+ if (typeof AbortSignal.any !== "function") missing.push("AbortSignal.any");
1294
+ if (typeof AbortSignal.timeout !== "function") missing.push("AbortSignal.timeout");
1295
+ if (typeof Promise.withResolvers !== "function") missing.push("Promise.withResolvers");
1296
+ if (typeof globalThis.Iterator === "undefined") missing.push("Iterator");
1297
+ lines.push(missing.length === 0 ? "浏览器引擎能力:✓ 会话流需要的 API 齐全" : `浏览器引擎能力:缺 ${missing.join("、")}(垫片未生效时,会话记录会停在「载入历史…」且没有报错)`);
1298
+ lines.push(`页面来源:${location.origin}${location.origin.startsWith("https://127.0.0.1") || location.origin.startsWith("http://127.0.0.1") ? "(本机回环)" : "(经局域网入口)"}`);
1299
+ const agent = navigator.userAgent;
1300
+ lines.push(`浏览器:${agent.slice(0, 120)}`);
1301
+ const started = Date.now();
1302
+ const outcome = await new Promise((resolve) => {
1303
+ let socket;
1304
+ try {
1305
+ socket = new WebSocket(`${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}/api/remote.mux`);
1306
+ } catch (failure) {
1307
+ resolve(`✗ 无法创建 WebSocket:${failure.message}`);
1308
+ return;
1309
+ }
1310
+ const timer = setTimeout(() => {
1311
+ try {
1312
+ socket.close();
1313
+ } catch {}
1314
+ resolve("✗ 12 秒内没有完成握手(WebKit 后台恢复后卡在 CONNECTING 的典型形状)");
1315
+ }, 12e3);
1316
+ socket.addEventListener("open", () => {
1317
+ clearTimeout(timer);
1318
+ resolve(`✓ 握手成功,用时 ${String(Date.now() - started)} ms`);
1319
+ try {
1320
+ socket.close();
1321
+ } catch {}
1322
+ });
1323
+ socket.addEventListener("error", () => {
1324
+ clearTimeout(timer);
1325
+ resolve("✗ WebSocket 握手失败(门禁拒绝或证书不受信任)");
1326
+ });
1327
+ socket.addEventListener("close", (event) => {
1328
+ if (event.code === 1006) return;
1329
+ });
1330
+ });
1331
+ lines.push(`会话 WebSocket(${location.host}):${outcome}`);
1332
+ const relay = snapshot?.connection;
1333
+ if (relay !== void 0) {
1334
+ lines.push(`代理侧:在活连接 ${String(relay.wsActive)} · 累计升级 ${String(relay.wsUpgrades)} · 被拒 ${String(relay.wsRefused)} · 代答心跳 ${String(relay.heartbeatAnswered)} 次`);
1335
+ const last = relay.recent[0];
1336
+ if (last !== void 0) lines.push(`最近一条:${last.upgraded ? "已升级" : `被拒 ${String(last.status ?? "?")}`} · 存活 ${String(Math.round(last.durationMs / 1e3))}s · 上行 ${String(Math.round(last.bytesToUpstream / 1024))}KB / 下行 ${String(Math.round(last.bytesToVisitor / 1024))}KB${last.upgraded && !last.sawCloseFrame ? " · 异常断开(无 Close 帧)" : ""}`);
1337
+ }
1338
+ setDoctor(lines);
1339
+ } finally {
1340
+ setDoctorBusy(false);
1341
+ }
1342
+ }, [snapshot]);
1275
1343
  /** Submit the admin unlock, keeping the button an ENABLED primary action. */
1276
1344
  const submitUnlock = async () => {
1277
1345
  if (unlockPassword === "") {
@@ -1639,6 +1707,102 @@ window.__ModuleLoader__.load({
1639
1707
  ]
1640
1708
  })]);
1641
1709
  const connectionTab = (0, react.createElement)("div", { className: "lg-tabbody" }, locked ? [lockCard] : [(0, react.createElement)(Card, {
1710
+ key: "mobile",
1711
+ title: "手机连接与自愈",
1712
+ subtitle: "长连接为什么会断,以及断了以后怎么恢复",
1713
+ children: [
1714
+ (0, react.createElement)("p", {
1715
+ className: "lg-hint",
1716
+ key: "why"
1717
+ }, "会话记录(「载入历史…」那一段)只走 WebSocket:DSH 每 2 秒发一次心跳,连续两次没被回应就断开——实测 6 秒。手机锁屏或切走时页面被系统挂起,回不了心跳,于是会话就会「载入不全、甚至断开」。下面三项默认开启,逐项都可以关。"),
1718
+ (0, react.createElement)("div", {
1719
+ className: "lg-field",
1720
+ key: "heartbeat"
1721
+ }, [(0, react.createElement)("div", {
1722
+ className: "lg-toggle",
1723
+ key: "t"
1724
+ }, [(0, react.createElement)("span", { key: "l" }, "代理代答心跳"), (0, react.createElement)("button", {
1725
+ key: "s",
1726
+ type: "button",
1727
+ className: "lg-switch",
1728
+ "aria-checked": preferences.answerHeartbeat,
1729
+ disabled: busy,
1730
+ onClick: () => void write({ preferences: { answerHeartbeat: !preferences.answerHeartbeat } })
1731
+ }, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
1732
+ className: "lg-hint",
1733
+ key: "h"
1734
+ }, "手机挂起期间由代理替它回心跳,宿主就不再回收这条连接(已实测:停回心跳 6 秒被切断 vs 代答后 20 秒以上存活)。手机自己回的心跳到达时是重复包,没有副作用。")]),
1735
+ (0, react.createElement)("div", {
1736
+ className: "lg-field",
1737
+ key: "watchdog"
1738
+ }, [(0, react.createElement)("div", {
1739
+ className: "lg-toggle",
1740
+ key: "t"
1741
+ }, [(0, react.createElement)("span", { key: "l" }, "断线看门狗(页面补丁)"), (0, react.createElement)("button", {
1742
+ key: "s",
1743
+ type: "button",
1744
+ className: "lg-switch",
1745
+ "aria-checked": preferences.socketWatchdog,
1746
+ disabled: busy,
1747
+ onClick: () => void write({ preferences: { socketWatchdog: !preferences.socketWatchdog } })
1748
+ }, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
1749
+ className: "lg-hint",
1750
+ key: "h"
1751
+ }, "卡在「连接中」超过 8 秒的 WebSocket 会被关掉;从后台回来 10 秒后仍然一条都没连上时,页面自动重载一次(每标签最多连续 3 次,冷却 20 秒起)。只影响真的连不上的页面。")]),
1752
+ (0, react.createElement)("div", {
1753
+ className: "lg-field",
1754
+ key: "compat"
1755
+ }, [(0, react.createElement)("div", {
1756
+ className: "lg-toggle",
1757
+ key: "t"
1758
+ }, [(0, react.createElement)("span", { key: "l" }, "移动端兼容垫片"), (0, react.createElement)("button", {
1759
+ key: "s",
1760
+ type: "button",
1761
+ className: "lg-switch",
1762
+ "aria-checked": preferences.mobileCompat,
1763
+ disabled: busy,
1764
+ onClick: () => void write({ preferences: { mobileCompat: !preferences.mobileCompat } })
1765
+ }, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
1766
+ className: "lg-hint",
1767
+ key: "h"
1768
+ }, "为老引擎补 AbortSignal.any / AbortSignal.timeout / Promise.withResolvers / Iterator,并补上移动端 meta。缺这些 API 时 DSH 客户端会在会话流里抛错,而界面上只会一直显示「载入历史…」、连报错都没有。现代浏览器上这些分支不生效。")]),
1769
+ (0, react.createElement)("div", {
1770
+ className: "lg-field",
1771
+ key: "scrollfix"
1772
+ }, [(0, react.createElement)("div", {
1773
+ className: "lg-toggle",
1774
+ key: "t"
1775
+ }, [(0, react.createElement)("span", { key: "l" }, "手机滚动矫正(窄屏)"), (0, react.createElement)("button", {
1776
+ key: "s",
1777
+ type: "button",
1778
+ className: "lg-switch",
1779
+ "aria-checked": preferences.mobileScrollFix,
1780
+ disabled: busy,
1781
+ onClick: () => void write({ preferences: { mobileScrollFix: !preferences.mobileScrollFix } })
1782
+ }, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
1783
+ className: "lg-hint",
1784
+ key: "h"
1785
+ }, "手机上 DSH 自己的外壳会把对话列压在固定的输入框/目标条/快捷回复浮层后面,导致内容可见但**滑不动**(同一视口在桌面 Chrome 里能滚,属 iOS 布局/触摸差异)。开启后,页面会在「整页不可滚 + 发现被裁剪的层」时把那几层改成可触摸滚动;能正常滚动的页面一律不碰。打开页面时加 ?lgdiag=1 会显示一屏布局诊断。")]),
1786
+ (0, react.createElement)("div", {
1787
+ className: "lg-row",
1788
+ key: "doctor"
1789
+ }, [(0, react.createElement)("button", {
1790
+ key: "b",
1791
+ type: "button",
1792
+ className: "lg-btn",
1793
+ disabled: doctorBusy,
1794
+ onClick: () => void runDoctor()
1795
+ }, doctorBusy ? "体检中…" : "运行连接体检")]),
1796
+ (0, react.createElement)("p", {
1797
+ className: "lg-hint",
1798
+ key: "doctor-hint"
1799
+ }, "体检在这个浏览器里跑:检查引擎缺哪些 API、页面拿到了哪些补丁,并对本页地址做一次真实的 WebSocket 握手。"),
1800
+ doctor === null ? null : (0, react.createElement)("div", {
1801
+ className: "lg-mono lg-mono-sm",
1802
+ key: "doctor-out"
1803
+ }, doctor.map((line, index) => (0, react.createElement)("div", { key: `l${String(index)}` }, line)))
1804
+ ]
1805
+ }), (0, react.createElement)(Card, {
1642
1806
  key: "connection",
1643
1807
  title: "连接与证书",
1644
1808
  subtitle: "监听范围、端口与传输安全",