dsh-builtin-browser 0.5.5 → 0.5.6

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/README.en.md +5 -3
  3. package/README.md +4 -2
  4. package/client.js +300 -4
  5. package/docs/development.md +10 -0
  6. package/docs/user-guide.md +16 -4
  7. package/lib/browser-electron/bridge-connection.d.ts +8 -0
  8. package/lib/browser-electron/bridge-connection.js +8 -0
  9. package/lib/browser-electron/bridge-endpoint.d.ts +30 -0
  10. package/lib/browser-electron/bridge-endpoint.js +123 -0
  11. package/lib/browser-electron/desktop-bridge-host.d.ts +23 -23
  12. package/lib/browser-electron/desktop-bridge-host.js +35 -35
  13. package/lib/browser-electron/electron-provision.d.ts +34 -1
  14. package/lib/browser-electron/electron-provision.js +52 -9
  15. package/lib/browser-electron/entry.js +62 -1
  16. package/lib/browser-electron/json-reply.d.ts +21 -0
  17. package/lib/browser-electron/json-reply.js +17 -0
  18. package/lib/browser-electron/preview-route.js +1 -12
  19. package/lib/browser-electron/remote-host.js +6 -5
  20. package/lib/browser-electron/runtime-route.d.ts +57 -0
  21. package/lib/browser-electron/runtime-route.js +66 -0
  22. package/lib/browser-electron/runtime-status.d.ts +102 -0
  23. package/lib/browser-electron/runtime-status.js +86 -0
  24. package/package.json +2 -2
  25. package/scripts/consumer-install-check.mjs +72 -0
  26. package/scripts/verify-runtime-status.mjs +165 -0
  27. package/src/browser-electron/bridge-connection.ts +9 -0
  28. package/src/browser-electron/bridge-endpoint.ts +139 -0
  29. package/src/browser-electron/desktop-bridge-host.ts +35 -35
  30. package/src/browser-electron/electron-provision.ts +73 -8
  31. package/src/browser-electron/entry.ts +67 -1
  32. package/src/browser-electron/json-reply.ts +32 -0
  33. package/src/browser-electron/preview-route.ts +1 -12
  34. package/src/browser-electron/remote-host.ts +6 -5
  35. package/src/browser-electron/runtime-route.ts +106 -0
  36. package/src/browser-electron/runtime-status.ts +186 -0
package/CHANGELOG.md CHANGED
@@ -2,9 +2,69 @@
2
2
 
3
3
  本文件记录各轮功能开发与问题修复(由仓库外独立文档迁入,随仓库管理)。
4
4
 
5
+ ## 0.5.6(2026-11-03)
6
+
7
+ > 主题:**"装好即可用"变得可见、可修**。0.5.3 把 Electron 运行时下载从安装里搬到了首次需要时,这是对的(否则默认 pnpm 的 profile 直接装不上);代价是**新装后的头一分钟里,第一个浏览器调用可能撞上仍在进行的下载而失败,而这件事在界面上没有任何痕迹**——只有一行日志。这个版本把"现在能不能用"变成一个可读的状态,并给了唯一的那个修复按钮。
8
+
9
+ ### 设置页顶部新增「就绪状态」
10
+
11
+ - 一条结论 + 三行事实:**当前载体**(channel 解析成什么)、**内置浏览器运行时**(`present` / `preparing` / `idle` / `skipped` / `failed`,附原因)、**桌面侧栏 bridge**(`installed` / `missing` / `stale` / `absent`,并且**已安装还要分在不在跑**)。
12
+ - 判定按**载体**给,不按插件给:`bundled` 看运行时,`sidebar` 看 bridge,`auto` 二者其一即可。把"插件就绪"当成一个统一状态,正是面板会显示绿色而浏览器打不开的原因。
13
+ - 只有 `failed` / `skipped` 才把编排模块自己的那句话显示出来(它带原因),其余状态只给标签 —— 状态标签已经说完了,再复制一遍是噪音。
14
+ - 轮询**只在 `preparing` 时发生**:那是唯一会自己变化的状态;其他状态下每两秒发一次请求是白烧。
15
+
16
+ ### 「已安装」不等于「在运行」
17
+
18
+ 这是同一个绿色的另一半,而且是最常被踩的那一半:**桌面端没开**。
19
+
20
+ `bridge-status` 读的是**安装树**(shell 的 main 里有没有我们的 marker、`app.asar` 有没有让位),它在重启之后依然成立,却完全不知道进程;真正说明"现在有人应答"的是 shell 运行时发布的**端点文件**(port / token / pid / 刷新时间戳)。两者都看,才叫就绪:
21
+
22
+ - 刷新戳超过 60 s(与 `bridge-connection` 的 `ENDPOINT_STALE_AFTER_MS` 同一个常量,不复制第二份)⇒ 那是墓碑,不是慢 shell;
23
+ - `pid` 用 signal 0 探活(什么也不发,`EPERM` 也算活着);
24
+ - **没有时间戳不算过期**:老桥从不写它,那种 shell 该按 pid 判,而不是被判死。
25
+
26
+ 于是面板那一行有三种说法:`已安装(桌面端正在运行)` / `已安装,但桌面端没在运行` / `未安装`。第二种下面跟一句说清是哪个 pid 不在了,**不给修复命令** —— 没有东西需要修,需要的是把桌面端打开。
27
+
28
+ 真机复核时抓到的缺陷:初版报告**只按安装树判定**,因此在桌面端已经关掉的情况下仍会说 `ready` —— 那条路径是代码事实,不是推断。现在 `installed + 未运行 ⇒ blocked` 由测试守着。
29
+
30
+ ### 两个新端点,读与写分开
31
+
32
+ - `GET /dsh-builtin-browser/runtime-status`:与设置文档同级(读开放给普通客户端),返回整份报告。**每个响应都是完整替换**,所以一次迟到的轮询不会在屏幕上留下过期状态。
33
+ - `POST /dsh-builtin-browser/runtime-provision`:**按写操作准入**(`sameOrigin(request, true)`)。它启动的是约 100 MB 的网络下载,不该和一次读取同一把尺子。
34
+ - POST **立即返回** `preparing`,不等待下载:等待会在慢网络下先让浏览器超时,而面板本来就能轮询。
35
+
36
+ ### 「准备内置浏览器」按钮真的能重试
37
+
38
+ 编排的尝试是每进程记忆化的(`attempt ??=`)。只加重试按钮等于给用户一个摆设:**失败一次之后,按钮的答案永远是那次失败**。`provisionElectronInBackground` 新增 `force`,只作废**已结算**的尝试;**在飞的那次永远被加入**(往同目录放两个下载是唯一必须拒绝的结果)。这条有测试,含"在飞时 force 不重启"。
39
+
40
+ ### 设置页的文案跟随运行时切换语言
41
+
42
+ `translate` 是模块级绑定,`apply()` 在每次 locale 快照时重新绑定它 —— 但 React 不知道这件事,已经渲染的标签会一直停在旧语言。`666cbff` 修的是浮标(原生 DOM,自己改写文本),这一版补上 React 侧:locale 订阅同时**递增版本号并通知订阅者**,设置分区与就绪区因此重新渲染。两种受众一次通知。
43
+
44
+ ### 顺手修掉的用户可见乱码
45
+
46
+ - `package.json` 的 `description`(npm 页与市场列表上就是这一行)里,破折号曾经过一次有损 GBK 往返,变成 `閳?`;现在恢复为 `—`。
47
+ - 桌面桥里 37 处 `鈥?` 同类乱码(其中一处是**运行时会打印给人看的消息**,其余是注释)。
48
+
49
+ 两处都是同一个成因:`—`(E2 80 94)被按 GBK 解码成"一个汉字 + `?`",而那个 `?` 吃掉了后面的空格 —— 所以修复是 `— `(破折号 + 空格),不是 `—`。
50
+
51
+ ### 测试
52
+
53
+ 全量从 **469 → 510**(509 过 / 1 跳过 / 0 失败,62.9 s,`tsc` 干净),新增 41 条落在五个文件:
54
+
55
+ - `runtime-status.test.mjs`(13,新):就绪报告按载体逐条 —— bundled 看运行时、sidebar 看 bridge、auto 二者其一、显式 Chrome/Edge 一律 `unknown`;`installed + 未运行 ⇒ blocked`;「已安装但端点过期/pid 已死」两种墓碑;以及 `present` 时那句说明必须与状态一致。
56
+ - `bridge-endpoint.test.mjs`(8,新):缺文件 / 目录冒充文件 / 坏 JSON / 新鲜戳 + 活 pid / 超 60 s 墓碑 / 窗口内慢刷新 / 活戳死 pid / 无戳老桥按 pid 判。
57
+ - `runtime-route.test.mjs`(8,新):读开放给普通客户端、跨站读 403、**无浏览器头的 POST 403 且不启动任何东西**、面板式 POST 200 拿到 `preparing`、失败是 200 带原因、`provision` 抛错仍给报告、两条路由互相拒绝错误动词。
58
+ - `electron-provision.test.mjs`(+4):`idle` 初值、下载中可见 `preparing`、结算后可重试而**在飞时不可重启**、失败信息同时指向面板与命令行。
59
+ - `client-panel.test.mjs`(+8):真跑 React 分区 —— 三行事实与徽标、`failed` 时才出现的「准备内置浏览器」、下载中不提供第二个、点按钮确实 POST 到 `runtime-provision`、**老宿主 404 时整段不渲染**(版本错配不该报成用户的错)、语言切换重绘已挂载标签、「已安装未运行」与「已安装运行中」两种说法。
60
+
61
+ 两条是**防漂移**的:面板本地化的状态词表必须与宿主导出的联合类型一致;每个状态/载体/两种 bridge 说法在 zh 与 en 两张表里都要有标签 —— 模板字符串拼出来的键,`client-locale` 那条按 `t("…")` 扫描的用例看不见。
62
+
5
63
  ## 0.5.5(2026-11-03)
6
64
 
7
- > 与 `0.5.4` **内容相同**。`0.5.4` 这个版本号被 npm 侧一条 staged 记录占住:首次发布返回"正在处理"但从未出现在 registry,随后每次发布都被 `E409 Cannot publish over previously staged version "0.5.4"` 拒绝,而 `npm stage list` 为空、`npm unpublish --force` 也清不掉。与其等一条看不见的记录过期,换号发布。
65
+ > 与 `0.5.4` **内容相同**。当时 `0.5.4` 这个版本号发布返回"正在处理"却迟迟不出现,随后报 `E409 Cannot publish over previously staged version "0.5.4"`,而 `npm stage list` 为空、`npm unpublish --force` 也清不掉,于是换了号。
66
+ >
67
+ > **更正(0.5.6 复核)**:`0.5.4` **最终在 registry 上成立了**(`2026-11-03T14:43:09Z`,tarball 可下载,解开后 `version=0.5.4`),只是本仓库没有为它建 GitHub release。E409 当场报错并不等于版本号被永久占住 —— 下一次先查 `registry.npmjs.org/<pkg>/<version>` 与 tarball `HEAD`,再决定换不换号。
8
68
 
9
69
  ### 预览是只读动作,不该改动读者的布局
10
70
 
package/README.en.md CHANGED
@@ -27,7 +27,7 @@ Updating an installed plugin takes two steps (since DSH 0.2.1-alpha.2 a second `
27
27
 
28
28
  ```sh
29
29
  dsh plugin --profile <profile> remove dsh-builtin-browser
30
- dsh plugin --profile <profile> add dsh-builtin-browser@0.5.2
30
+ dsh plugin --profile <profile> add dsh-builtin-browser@0.5.6
31
31
  ```
32
32
 
33
33
  ### Desktop
@@ -53,7 +53,7 @@ dsh plugin --profile web add dsh-builtin-browser
53
53
 
54
54
  The web surface has no sidebar and no bridge: the plugin hosts its own window (titled `dsh-browser`) with an address bar, back/forward/reload and a tab strip — usable as an ordinary browser.
55
55
 
56
- > The Electron binary is normally prepared by the install script. A host using `strict-dep-builds` needs the build script approved first; otherwise run `npx --no dsh-browser-install-electron` inside the profile directory. See the [user guide](docs/user-guide.md).
56
+ > **Nothing has to be prepared by hand.** Since 0.5.3 the package carries no install-time script: the Electron runtime is fetched the first time it is actually needed, and a failed fetch only affects the bundled carrier — the desktop sidebar and an installed Chrome / Edge keep working. Since 0.5.6 the settings page opens with a **Readiness** section that says which carrier is in use, whether the runtime is ready / downloading / failed (with the reason), and what state the desktop bridge is in; when preparation failed, the **Prepare the bundled browser** button there retries it — no terminal needed. `npx --no dsh-browser-install-electron` (inside the profile directory) is for pre-provisioning an offline image or CI. See the [user guide](docs/user-guide.md).
57
57
 
58
58
  ### Then
59
59
 
@@ -120,7 +120,9 @@ Full detail, round by round, with the reasoning and evidence behind each fix: [C
120
120
 
121
121
  | Version | Date | Theme |
122
122
  | --- | --- | --- |
123
- | **0.5.5** | 2026-11-03 | Same content as 0.5.4 (the 0.5.4 version number is held by a staged record on npm's side). **The preview is read-only**: a frame no longer goes through `ensureSidebar` (older bridges pressed keys and typed into the address bar) but through `list`, so the sidebar panel is no longer pulled to the front; overlay geometry, close control, stacking and `img[hidden]` fixed (#46); **remote viewing is a settings switch that applies immediately** (a phone has no shortcut); the bridge repair command names the copy inside the installed package (#40, fourth item) |
123
+ | **0.5.6** | 2026-11-03 | **"It works once you install it", made visible and repairable**: a **Readiness** section at the top of the settings page (current carrier / bundled runtime / desktop bridge, judged per carrier, with **installed kept separate from running** — a closed desktop app is the most common broken state); when preparation failed, a **Prepare the bundled browser** button that can actually retry (the memoised attempt used to make one failure final); new `runtime-status` (read) and `runtime-provision` (admitted as a write, answers immediately, the panel polls); the settings page follows a runtime language switch; the `description` and 38 mojibake characters in the desktop bridge repaired |
124
+ | **0.5.5** | 2026-11-03 | **The preview is read-only**: a frame no longer goes through `ensureSidebar` (older bridges pressed keys and typed into the address bar) but through `list`, so the sidebar panel is no longer pulled to the front; overlay geometry, close control, stacking and `img[hidden]` fixed (#46); **remote viewing is a settings switch that applies immediately** (a phone has no shortcut); the bridge repair command names the copy inside the installed package (#40, fourth item). Same content as 0.5.4 |
125
+ | **0.5.4** | 2026-11-03 | A second publication of the same content as 0.5.5 (published to npm; no GitHub release was cut for it) |
124
126
  | **0.5.3** | 2026-11-03 | **Installation no longer needs the network**: the `postinstall` is gone and the Electron runtime is prepared the first time it is actually needed, never failing an install (fixes the market install failures in #41/#42); the installer proves the app's identity before touching anything and validates before deleting (#40); the live-view entry mounts on demand, with its labels translated and a theme token that exists |
125
127
  | **0.5.2** | 2026-11-01 | A sidebar page no longer waits for a human: the column is opened when it was never opened, and the shell is asked to display a conversation requested from the background, with a bounded retry. Adds `click_sequence`. Recognises the pre-#37 bridge refusal that carries no code |
126
128
  | **0.5.1** | 2026-10-31 | Adopt the page the browser already shows: `switch_tab` and `open` land on it; canvas detection no longer requires an empty element list; a blank page is judged by its own URL |
package/README.md CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  ```sh
29
29
  dsh plugin --profile <profile> remove dsh-builtin-browser
30
- dsh plugin --profile <profile> add dsh-builtin-browser@0.5.2
30
+ dsh plugin --profile <profile> add dsh-builtin-browser@0.5.6
31
31
  ```
32
32
 
33
33
  ### 桌面端
@@ -121,7 +121,9 @@ Web 端没有侧栏也没有 bridge:插件自托管一个独立窗口(标题 `ds
121
121
 
122
122
  | 版本 | 日期 | 主题 |
123
123
  | --- | --- | --- |
124
- | **0.5.5** | 2026-11-03 | 与 0.5.4 同内容(`0.5.4` 的版本号被 npm 侧 staged 记录占用)。**预览是只读的**:取帧不再经 `ensureSidebar`(旧桥会按键+打字),只读 `list`,面板不再被顶到前台;浮标几何、关闭键、层级与 `img[hidden]` 修正(修 #46);**远程观看改为设置里的开关,点了立刻生效**(手机没有快捷键);bridge 修复命令指向包内真实路径(修 #40 第四项) |
124
+ | **0.5.6** | 2026-11-03 | **「装好即可用」可见、可修**:设置页顶部新增**就绪状态**(当前载体 / 内置运行时 / 桌面桥,按载体给结论,且**已安装与在运行分开**——桌面端没开是最常见的坏状态),`failed` 时给「准备内置浏览器」按钮且**真能重试**(此前的记忆化尝试让失败一次就成了终局);新端点 `runtime-status`(读)与 `runtime-provision`(按写操作准入,立即返回,面板轮询);设置页文案跟随运行时切换语言;修掉 `description` 与桌面桥里 38 处 `閳?`/`鈥?` 乱码 |
125
+ | **0.5.5** | 2026-11-03 | **预览是只读的**:取帧不再经 `ensureSidebar`(旧桥会按键+打字),只读 `list`,面板不再被顶到前台;浮标几何、关闭键、层级与 `img[hidden]` 修正(修 #46);**远程观看改为设置里的开关,点了立刻生效**(手机没有快捷键);bridge 修复命令指向包内真实路径(修 #40 第四项)。内容与 0.5.4 相同 |
126
+ | **0.5.4** | 2026-11-03 | 与 0.5.5 同内容的另一份发布(npm 上可取到;本仓库没有为它建 release) |
125
127
  | **0.5.3** | 2026-11-03 | **安装不再依赖网络**:去掉 `postinstall`,Electron 运行时改为首次需要时才准备且永不失败安装(修 #41/#42 的市场安装失败);安装器先验应用身份再动手,校验先于删除(修 #40);观看入口按需挂载、翻译与主题令牌修正 |
126
128
  | **0.5.2** | 2026-11-01 | 侧栏页面不再需要人先动手:列没打开就展开,会话不在前台就请求外壳显示它并做有界重试;新增批量坐标点击 `click_sequence`;旧 bridge 的无 code 拒绝也按显示状态处理 |
127
129
  | **0.5.1** | 2026-10-31 | 接管浏览器自己打开的页面:`switch_tab` 与 `open` 落到你正在看的那一页;canvas 检测不再要求元素列表为空;空白页由页面自身 URL 判定 |
package/client.js CHANGED
@@ -34,6 +34,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
34
34
  * host without one.
35
35
  */
36
36
  let refreshWatchEntry = () => {}
37
+ /**
38
+ * Re-apply the locale to the watch panel's static labels.
39
+ *
40
+ * Set by `installWatchPanel`, called from the locale subscription in `apply()`. Separate from
41
+ * {@link refreshWatchEntry} because a language switch must not re-probe or re-mount anything.
42
+ */
43
+ let refreshWatchLabels = () => {}
37
44
 
38
45
  const zh = {
39
46
  nav: "浏览器",
@@ -99,6 +106,40 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
99
106
  "remoteView.title": "远程观看",
100
107
  "remoteView.enabled": "允许从其它设备观看这台机器的浏览器",
101
108
  "remoteView.enabled.hint": "打开后,本机右下角出现一个只读画面入口:2 fps、JPEG、一帧一请求,不转发点击与键盘。改动**立刻生效**,不需要刷新页面。关闭时入口消失,相关端点也不返回图像。",
109
+ "readiness.title": "就绪状态",
110
+ "readiness.lead": "「装好就能用」的自检:内置浏览器首次使用前要在后台下载一次运行时,桌面侧栏需要装进桌面端的 bridge,本机 Chrome / Edge 需要已经安装。",
111
+ "readiness.loading": "检测中…",
112
+ "readiness.failed": "读取就绪状态失败:",
113
+ "readiness.channel": "当前载体",
114
+ "readiness.electron": "内置浏览器运行时",
115
+ "readiness.bridge": "桌面侧栏 bridge",
116
+ "readiness.recheck": "重新检测",
117
+ "readiness.prepare": "准备内置浏览器",
118
+ "readiness.preparing": "正在准备…",
119
+ "readiness.fix": "修复命令(在终端里跑一次):",
120
+ "readiness.carrier.sidebar": "桌面侧栏",
121
+ "readiness.carrier.bundled": "内置 Electron",
122
+ "readiness.carrier.system": "本机 Chrome / Edge",
123
+ "readiness.carrier.auto": "自动",
124
+ "readiness.state.ready": "可用",
125
+ "readiness.state.blocked": "尚不可用",
126
+ "readiness.state.unknown": "需实际启动才能确定",
127
+ "readiness.electron.present": "已就绪(本机已有运行时)",
128
+ "readiness.electron.ready": "已就绪(刚准备完成)",
129
+ "readiness.electron.preparing": "正在下载运行时(首次,约 1–3 分钟)",
130
+ "readiness.electron.idle": "尚未开始准备",
131
+ "readiness.electron.skipped": "已跳过(设置了 ELECTRON_SKIP_BINARY_DOWNLOAD)",
132
+ "readiness.electron.failed": "准备失败",
133
+ "readiness.bridge.installed": "已安装",
134
+ "readiness.bridge.installedRunning": "已安装(桌面端正在运行)",
135
+ "readiness.bridge.installedNotRunning": "已安装,但桌面端没在运行",
136
+ "readiness.bridge.missing": "未安装",
137
+ "readiness.bridge.stale": "已失效(桌面端升级后需重装)",
138
+ "readiness.bridge.absent": "本机没有桌面端",
139
+ "readiness.hint.sidebar": "侧栏载体把页面放进 DSH 窗口右侧,人机同页;它需要桌面端的 bridge,而且只渲染**当前显示**的那个会话。",
140
+ "readiness.hint.bundled": "内置浏览器随插件提供,无需安装;运行时在首次使用前自动下载,期间可以先改用桌面侧栏或本机 Chrome / Edge。",
141
+ "readiness.hint.system": "选了本机浏览器:插件用它自己的独立 profile 启动,不需要额外准备。",
142
+ "readiness.hint.auto": "自动:内置运行时与桌面侧栏任一可用即可工作。",
102
143
  }
103
144
 
104
145
  const en = {
@@ -165,6 +206,40 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
165
206
  "remoteView.title": "Remote viewing",
166
207
  "remoteView.enabled": "Let other devices watch this machine's browser",
167
208
  "remoteView.enabled.hint": "On, a read-only view appears in the bottom-right corner here: 2 fps, JPEG, one frame per request, and no forwarding of clicks or keys. The change applies **immediately** — no page reload needed. Off, the entry disappears and the endpoints return no image.",
209
+ "readiness.title": "Readiness",
210
+ "readiness.lead": "The \"it works once you install it\" check: the bundled browser downloads its runtime in the background before its first use, the sidebar needs the bridge installed into the desktop app, and an installed Chrome / Edge has to be installed.",
211
+ "readiness.loading": "Checking…",
212
+ "readiness.failed": "Could not read readiness:",
213
+ "readiness.channel": "Carrier",
214
+ "readiness.electron": "Bundled browser runtime",
215
+ "readiness.bridge": "Desktop sidebar bridge",
216
+ "readiness.recheck": "Check again",
217
+ "readiness.prepare": "Prepare the bundled browser",
218
+ "readiness.preparing": "Preparing…",
219
+ "readiness.fix": "Repair command (run it once in a terminal):",
220
+ "readiness.carrier.sidebar": "Desktop sidebar",
221
+ "readiness.carrier.bundled": "Bundled Electron",
222
+ "readiness.carrier.system": "Installed Chrome / Edge",
223
+ "readiness.carrier.auto": "Automatic",
224
+ "readiness.state.ready": "Ready",
225
+ "readiness.state.blocked": "Not ready yet",
226
+ "readiness.state.unknown": "Only a real launch can tell",
227
+ "readiness.electron.present": "Ready (a runtime is already on this machine)",
228
+ "readiness.electron.ready": "Ready (just prepared)",
229
+ "readiness.electron.preparing": "Downloading the runtime (first time, about 1–3 minutes)",
230
+ "readiness.electron.idle": "Not prepared yet",
231
+ "readiness.electron.skipped": "Skipped (ELECTRON_SKIP_BINARY_DOWNLOAD is set)",
232
+ "readiness.electron.failed": "Preparation failed",
233
+ "readiness.bridge.installed": "Installed",
234
+ "readiness.bridge.installedRunning": "Installed (the desktop app is running)",
235
+ "readiness.bridge.installedNotRunning": "Installed, but the desktop app is not running",
236
+ "readiness.bridge.missing": "Not installed",
237
+ "readiness.bridge.stale": "Stale (a desktop update needs a reinstall)",
238
+ "readiness.bridge.absent": "No desktop install on this machine",
239
+ "readiness.hint.sidebar": "The sidebar carrier puts the page in the right pane of the DSH window, one page for both parties; it needs the desktop's bridge, and it renders only the conversation being **displayed**.",
240
+ "readiness.hint.bundled": "The bundled browser ships with the plugin and needs nothing installed; its runtime is downloaded before first use — meanwhile the desktop sidebar or an installed Chrome / Edge works.",
241
+ "readiness.hint.system": "An installed browser was chosen: the plugin launches it with its own separate profile, so there is nothing to prepare.",
242
+ "readiness.hint.auto": "Automatic: whichever of the bundled runtime and the desktop sidebar works first.",
168
243
  }
169
244
 
170
245
  /**
@@ -370,6 +445,18 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
370
445
  error: { color: "#e5534b" },
371
446
  pathLine: { opacity: 0.6, wordBreak: "break-all", lineHeight: 1.5 },
372
447
  button: { padding: "3px 10px", borderRadius: "6px", border: "1px solid rgba(128,128,128,.4)", background: "transparent", color: "inherit", cursor: "pointer" },
448
+ // Readiness: one headline state, three one-line facts, and at most two buttons. The colours are
449
+ // the only place this panel states an opinion, which is why they carry no text of their own —
450
+ // the label next to them is always a locale string.
451
+ badge: { display: "inline-block", padding: "1px 8px", marginRight: "8px", borderRadius: "10px", fontSize: "11px", lineHeight: 1.6, border: "1px solid transparent" },
452
+ badgeOk: { color: "#2f9e44", borderColor: "rgba(47,158,68,.5)", background: "rgba(47,158,68,.12)" },
453
+ badgeWarn: { color: "#e5534b", borderColor: "rgba(229,83,75,.5)", background: "rgba(229,83,75,.12)" },
454
+ badgeUnknown: { color: "#a0a0a8", borderColor: "rgba(160,160,168,.5)", background: "rgba(160,160,168,.12)" },
455
+ kv: { display: "grid", gridTemplateColumns: "auto 1fr", gap: "3px 12px", margin: "8px 0 0", fontSize: "12px" },
456
+ kvKey: { opacity: 0.68 },
457
+ kvVal: { lineHeight: 1.5 },
458
+ mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "rgba(0,0,0,.22)", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
459
+ buttons: { display: "flex", gap: "8px", alignItems: "center", marginTop: "10px", flexWrap: "wrap" },
373
460
  }
374
461
 
375
462
  /**
@@ -484,8 +571,175 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
484
571
  ])
485
572
  }
486
573
 
574
+ /**
575
+ * Re-render this component when the interface language changes at run time.
576
+ *
577
+ * `translate` is a module-level binding that `apply()` re-binds on every locale snapshot, but
578
+ * React has no idea that happened: every label rendered so far keeps the language it was rendered
579
+ * in, which is exactly the defect the watch panel hit (#40) and the one commit `666cbff` fixed for
580
+ * that panel's DOM. The settings section is rendered by React, so it needs the notification rather
581
+ * than a text pass.
582
+ */
583
+ let localeVersion = 0
584
+ const localeWatchers = new Set()
585
+ function useLocaleVersion() {
586
+ const [, setVersion] = useState(localeVersion)
587
+ useEffect(() => {
588
+ const update = () => setVersion(localeVersion)
589
+ localeWatchers.add(update)
590
+ return () => { localeWatchers.delete(update) }
591
+ }, [])
592
+ }
593
+
594
+ /**
595
+ * Readiness: can the browser serve a call right now, and what is missing if not.
596
+ *
597
+ * This is the "it works once you install it" promise, made visible. The bundled runtime downloads
598
+ * on first need (issue #41 moved the download out of `postinstall`), so on a fresh install the
599
+ * honest answer for the first minute is "a download is running" — a state that used to exist only
600
+ * in a log line. Everything shown here comes from `GET /runtime-status`; the button starts the
601
+ * same one background attempt the plugin makes on its own, which is why pressing it is never
602
+ * harmful and never starts a second download.
603
+ */
604
+ function Readiness() {
605
+ useLocaleVersion()
606
+ const t = translate
607
+ const [runtime, setRuntime] = useState(null)
608
+ const [error, setError] = useState("")
609
+ const [unsupported, setUnsupported] = useState(false)
610
+ const [busy, setBusy] = useState(false)
611
+ const alive = useRef(true)
612
+
613
+ const read = useCallback(async () => {
614
+ try {
615
+ const response = await fetch("/dsh-builtin-browser/runtime-status", { headers: { accept: "application/json" } })
616
+ // A host that predates this route answers 404, and that is a version skew rather than a
617
+ // fault: after an update the client bundle is read at request time while the host's code is
618
+ // what started with the process. Rendering "could not read readiness: HTTP 404" at a user who
619
+ // simply has not restarted yet would be reporting the skew as their problem — so the section
620
+ // stays out of the way, exactly like a document with no `actions` section.
621
+ if (response.status === 404) {
622
+ if (alive.current) { setUnsupported(true); setRuntime(null); setError("") }
623
+ return null
624
+ }
625
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
626
+ const data = await response.json()
627
+ if (!alive.current) return null
628
+ setUnsupported(false)
629
+ setRuntime(data && data.runtime ? data.runtime : null)
630
+ setError("")
631
+ return data && data.runtime ? data.runtime : null
632
+ } catch (failure) {
633
+ if (!alive.current) return null
634
+ setError(String(failure && failure.message ? failure.message : failure))
635
+ return null
636
+ }
637
+ }, [])
638
+
639
+ useEffect(() => {
640
+ alive.current = true
641
+ void read()
642
+ return () => { alive.current = false }
643
+ }, [read])
644
+
645
+ // Poll only while a download is running: that is the one state that changes on its own, and a
646
+ // poll in any other state would be a background request per panel per two seconds forever.
647
+ const preparing = runtime !== null && runtime.electron.state === "preparing"
648
+ useEffect(() => {
649
+ if (!preparing) return undefined
650
+ const timer = setTimeout(() => { void read() }, 2000)
651
+ return () => clearTimeout(timer)
652
+ }, [preparing, runtime, read])
653
+
654
+ const prepare = async () => {
655
+ setBusy(true)
656
+ setError("")
657
+ try {
658
+ const response = await fetch("/dsh-builtin-browser/runtime-provision", {
659
+ method: "POST",
660
+ headers: { accept: "application/json" },
661
+ })
662
+ const data = await response.json().catch(() => ({}))
663
+ if (!response.ok) throw new Error((data && data.error) || `HTTP ${response.status}`)
664
+ if (alive.current && data && data.runtime) setRuntime(data.runtime)
665
+ } catch (failure) {
666
+ if (alive.current) setError(String(failure && failure.message ? failure.message : failure))
667
+ } finally {
668
+ if (alive.current) setBusy(false)
669
+ void read()
670
+ }
671
+ }
672
+
673
+ if (unsupported) return null
674
+ if (runtime === null) {
675
+ return h("div", { style: styles.wrap }, [
676
+ h("p", { key: "l", style: styles.lead }, error === "" ? t("readiness.loading") : `${t("readiness.failed")} ${error}`),
677
+ ])
678
+ }
679
+
680
+ const tone = runtime.readiness === "ready" ? styles.badgeOk
681
+ : runtime.readiness === "blocked" ? styles.badgeWarn : styles.badgeUnknown
682
+ const row = (key, label, value) => [
683
+ h("span", { key: `${key}-k`, style: styles.kvKey }, label),
684
+ h("span", { key: `${key}-v`, style: styles.kvVal }, value),
685
+ ]
686
+ // "Installed" and "running" are different facts, and the gap between them is the most common
687
+ // broken state there is (the desktop app is simply closed). The row says which one it means —
688
+ // and when the host does not report the running half at all, it says the plain truth rather
689
+ // than inferring "not running" from an absent field.
690
+ const bridgeLabel = runtime.bridge.state !== "installed"
691
+ ? t(`readiness.bridge.${runtime.bridge.state}`)
692
+ : runtime.bridge.running === true
693
+ ? t("readiness.bridge.installedRunning")
694
+ : runtime.bridge.running === false
695
+ ? t("readiness.bridge.installedNotRunning")
696
+ : t("readiness.bridge.installed")
697
+
698
+ return h("div", { style: styles.wrap }, [
699
+ h("p", { key: "head", style: styles.lead }, [
700
+ h("span", { key: "b", style: { ...styles.badge, ...tone } }, t(`readiness.state.${runtime.readiness}`)),
701
+ h("span", { key: "s" }, ` ${t(`readiness.hint.${runtime.carrier}`)}`),
702
+ ]),
703
+ h("div", { key: "kv", style: styles.kv }, [
704
+ ...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
705
+ ...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
706
+ ...row("bridge", t("readiness.bridge"), bridgeLabel),
707
+ ]),
708
+ // The provisioning module's own words: shown only where they add something a state label
709
+ // cannot carry (what failed, and why), never as a permanent second copy of the state.
710
+ runtime.electron.state === "failed" || runtime.electron.state === "skipped"
711
+ ? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail)
712
+ : null,
713
+ // Same rule for the shell: an installed bridge that is not running needs the sentence that says
714
+ // so ("pid 1234 is not running"), not a repair command, because there is nothing to repair.
715
+ runtime.bridge.state === "installed" && runtime.bridge.running !== true
716
+ ? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail)
717
+ : null,
718
+ runtime.bridge.command !== undefined && runtime.bridge.state !== "installed"
719
+ ? h("div", { key: "cmd" }, [
720
+ h("p", { key: "l", style: styles.hint }, t("readiness.fix")),
721
+ h("code", { key: "c", style: styles.mono }, runtime.bridge.command),
722
+ ])
723
+ : null,
724
+ h("div", { key: "btns", style: styles.buttons }, [
725
+ h("button", {
726
+ key: "recheck",
727
+ type: "button",
728
+ style: styles.button,
729
+ disabled: busy,
730
+ onClick: () => { void read() },
731
+ }, preparing ? t("readiness.preparing") : t("readiness.recheck")),
732
+ runtime.canProvision
733
+ ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: busy, onClick: () => { void prepare() } }, t("readiness.prepare"))
734
+ : null,
735
+ error !== "" ? h("span", { key: "e", style: styles.error }, `${t("readiness.failed")} ${error}`) : null,
736
+ ]),
737
+ ])
738
+ }
739
+
487
740
  /** The settings page section. */
488
741
  function SettingsRoot() {
742
+ useLocaleVersion()
489
743
  const t = translate
490
744
  const [rawSettings, setSettings] = useState(null)
491
745
  const [meta, setMeta] = useState({ path: "" })
@@ -539,6 +793,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
539
793
  return h("div", { style: styles.wrap }, [
540
794
  h("p", { key: "lead", style: styles.lead }, t("lead")),
541
795
 
796
+ // First, because it answers the question a fresh install raises before any switch matters:
797
+ // can this thing open a page right now, and if not, what is it waiting for.
798
+ section("readiness.title", [
799
+ h("p", { key: "lead", style: styles.hint }, t("readiness.lead")),
800
+ h(Readiness, { key: "r" }),
801
+ ]),
802
+
542
803
  section("history.title", [
543
804
  h(Toggle, {
544
805
  key: "enabled",
@@ -1224,16 +1485,22 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1224
1485
  // control and a permanent diagnostic call.
1225
1486
 
1226
1487
  /** Localized text, falling back to the key so a missing entry is visible rather than blank. */
1488
+ // Localized text.
1489
+ //
1490
+ // The try/catch that used to sit here was dead code, as Mzy123l pointed out on #40: the locale
1491
+ // service does not throw on a missing entry — it returns the key. So a miss shows the key, which
1492
+ // is diagnostic, and an empty answer is the only case worth substituting.
1227
1493
  const say = key => {
1228
- try { return translate(key) } catch { return key }
1494
+ const text = translate(key)
1495
+ return typeof text === "string" && text !== "" ? text : key
1229
1496
  }
1230
1497
 
1231
1498
  /**
1232
1499
  * Apply the current locale to every static label.
1233
1500
  *
1234
- * Called at mount and again once the dictionaries are bound. The panel used to set these exactly
1235
- * once, inside `apply()`, *before* `locale.register` had run — so the shipped build showed
1236
- * `watch.title` as its title and the key was never replaced (issue #40).
1501
+ * Called at mount, after a locale change, and again once the dictionaries are bound. The panel
1502
+ * used to set these exactly once, inside `apply()`, *before* `locale.register` had run — so the
1503
+ * shipped build showed `watch.title` as its title and the key was never replaced (issue #40).
1237
1504
  */
1238
1505
  const relabel = () => {
1239
1506
  openLabel.textContent = say("watch.open")
@@ -1243,6 +1510,10 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1243
1510
  openButton.title = say("watch.open")
1244
1511
  }
1245
1512
  relabel()
1513
+ // A runtime language switch must reach labels that are already on screen. `subscribe` fires on
1514
+ // every locale snapshot change — a switch, and also a late dictionary registration — which is
1515
+ // exactly the set of moments these four strings can go stale.
1516
+ refreshWatchLabels = () => { relabel() }
1246
1517
 
1247
1518
  let mounted = false
1248
1519
  /** Put the entry on the page. Idempotent, so a second enable cannot stack copies. */
@@ -1391,6 +1662,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1391
1662
  stop()
1392
1663
  unmount()
1393
1664
  refreshWatchEntry = () => {}
1665
+ refreshWatchLabels = () => {}
1394
1666
  }, "dsh-builtin-browser: live view panel")
1395
1667
 
1396
1668
  /**
@@ -1468,7 +1740,31 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1468
1740
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-builtin-browser: dictionaries")
1469
1741
  const t = ctx.locale.bind(NS)
1470
1742
  translate = t
1743
+ // A language switch has to reach text that is already on screen. `subscribe` fires on every
1744
+ // locale snapshot change (switch, and late dictionary registration); guarded, because a host
1745
+ // without it must still get the panel — the labels then simply keep their first language.
1746
+ if (typeof ctx.locale.subscribe === "function") {
1747
+ ctx.effect(() => {
1748
+ const off = ctx.locale.subscribe(() => {
1749
+ translate = ctx.locale.bind(NS)
1750
+ // Two audiences, one notification: the vanilla watch panel rewrites its own text, and the
1751
+ // React settings section re-renders (see `useLocaleVersion`). Bumping the counter here is
1752
+ // what makes `t()` inside a mounted component return the new language at all.
1753
+ localeVersion += 1
1754
+ for (const update of localeWatchers) update()
1755
+ refreshWatchLabels()
1756
+ })
1757
+ return () => { if (typeof off === "function") off() }
1758
+ }, "dsh-builtin-browser: locale changes")
1759
+ }
1471
1760
  installWatchPanel(ctx)
1761
+ // Test seam. The readiness section is composed by the settings component, so a harness that
1762
+ // renders that component can see the element but never run it — and running it is what proves a
1763
+ // user reads a state label rather than `readiness.electron.failed`. Exported on the module rather
1764
+ // than published on `globalThis` (where the product's own `__dshBuiltinBrowser` lives, for the
1765
+ // shell's benefit): nothing in the product reads this name, and a page-level global would be a
1766
+ // side effect of shipping a test.
1767
+ exports.__readinessSection = Readiness
1472
1768
  ctx.slots.inject("settings.section", () => ctx.slots.register({
1473
1769
  name: "settings.section",
1474
1770
  id: "dsh-builtin-browser",
@@ -50,6 +50,16 @@ node scripts/verify-host-compat.mjs
50
50
 
51
51
  它用某个 profile 里**真实安装**的 `@deepseek-ai/*` 包组装一个宿主,加载本插件的编译产物、经宿主自己的 `defineTool` 注册工具、再用一个假 provider 真调两个工具(`dsh_browser_session` / `dsh_browser_a11y`)。默认读 `$DSH_HOME/profiles` 下的 profile,可用 `DSH_PROFILE` / `DSH_HOME` 指定。
52
52
 
53
+ ### 复验设置页的两个新端点(0.5.6)
54
+
55
+ ```sh
56
+ node scripts/verify-runtime-status.mjs # 与上面同一个 profile 解析规则
57
+ ```
58
+
59
+ 单元测试覆盖了处理器与判定逻辑,但覆盖不到**接线**:`ctx.inject(['webServer'])` 里注册的两个路径、以及把设置文档与安装树读进报告的 deps。路由没有注册与路由返回空,看起来是一样的 —— 这个探针用真实宿主包组装 cordis context、注册一个记录式 `webServer`、把插件注册的处理器挂到真实 loopback HTTP 上再发请求,断言四件事:两个路径都注册了、`GET` 返回可渲染的报告、无浏览器头的 `POST` 被 403 拒绝、面板式请求能拿到 `provision` 状态。它在**临时 `DSH_HOME`** 里跑,并固定 `ELECTRON_SKIP_BINARY_DOWNLOAD`,所以不会碰用户的设置文件,也不会触发 100 MB 下载。
60
+
61
+ `node scripts/consumer-install-check.mjs <tgz> <空目录>` 则是安装侧的那一条:默认 pnpm 下装 tarball,**无 `Ignored build scripts`**、`scripts` 恰好是 `build,prepack,test`、就绪端点所在的两个 `lib/` 文件在装出来的树里。
62
+
53
63
  ## 关于 DSH 版本范围
54
64
 
55
65
  插件在 **`engines.dsh`** 里声明 `>=0.1.1-rc.2 <0.3.0`。
@@ -30,17 +30,29 @@ dsh plugin --profile web add <本仓库路径>
30
30
 
31
31
  ### 准备 Electron 二进制
32
32
 
33
- Electron 44 将二进制下载改为懒下载,仅安装 npm 包并不保证已有可执行文件。0.4.16 增加本插件的 `postinstall`:宿主允许安装脚本且下载可用时,明确运行所依赖 electron 包的 `install.js`,通常在安装阶段就准备好二进制。下载失败会保留错误并返回非零退出码,应先处理错误再重试。
33
+ **0.5.3 起,安装本身不需要网络,也不含任何安装期脚本**(去掉了 `postinstall`:默认 pnpm 的 `strict-dep-builds` 会因此直接拒绝安装,而下载失败又会让整个安装失败)。Electron 44 的二进制改为**首次需要时才准备**:选了内置载体(默认)时,插件启动就在后台准备运行时,失败只影响内置载体,侧栏与 Chrome / Edge 不受影响。
34
34
 
35
- **DSH rc.5 使用 pnpm 11.7 的 `strict-dep-builds`。** 首次安装若提示构建脚本尚未批准,请在宿主原生插件管理器中审阅并批准 `dsh-builtin-browser` 的构建脚本,再按宿主提示重试安装或构建。插件不会自行改写 `allowBuilds`;审批和宿主策略仍由用户控制。
35
+ 看它在做什么、缺什么、要不要重试,都在**设置 → 浏览器 → 就绪状态**(0.5.6):三行事实(当前载体 / 内置浏览器运行时 / 桌面侧栏 bridge)+ 一条结论。运行时准备失败时那里会出现「准备内置浏览器」按钮,点一下就是重试 —— 不必开终端。
36
36
 
37
- 使用 `--ignore-scripts`、明确跳过下载,或需要重试下载时,进入**安装本插件的 profile 目录**(通常为 `$DSH_HOME/profiles/web` 或 `$DSH_HOME/profiles/desktop`),运行本插件已经安装的本地命令:
37
+ 桌面桥那一行**把「已安装」和「在运行」分开**:
38
+
39
+ | 说法 | 含义 | 该做什么 |
40
+ | --- | --- | --- |
41
+ | 已安装(桌面端正在运行) | 补丁在,进程也在应答 | 无 |
42
+ | 已安装,但桌面端没在运行 | 补丁在,进程不在 —— **最常见** | 打开桌面端 |
43
+ | 未安装 / 已失效 | 补丁不在,或被桌面端升级冲掉 | 跑那一行给出的修复命令,再重开桌面端 |
44
+
45
+ 差别是实打实的:安装状态写在磁盘上,重启也不会变;能应答的是**此刻在跑的那个进程**,它发布的端点(端口 + pid + 每 15 秒一次的刷新)才是活的证据。只按磁盘判,面板会在桌面端早已关掉时说"可用"。
46
+
47
+ **DSH rc.5 使用 pnpm 11.7 的 `strict-dep-builds`。** 本插件不再声明 `postinstall`,所以正常安装不会出现构建脚本审批提示;若仍有别的包需要审批,请在宿主原生插件管理器中审阅。插件不会自行改写 `allowBuilds`。
48
+
49
+ 需要在安装阶段就把运行时准备好(离线部署、CI 镜像),或要手工重试下载时,进入**安装本插件的 profile 目录**(通常为 `$DSH_HOME/profiles/web` 或 `$DSH_HOME/profiles/desktop`),运行本插件已经安装的本地命令:
38
50
 
39
51
  ```sh
40
52
  npx --no dsh-browser-install-electron
41
53
  ```
42
54
 
43
- `--no` 用于拒绝临时下载缺失命令;命令不存在时先检查 profile 与插件安装,不要改用同名第三方包。该命令与安装脚本都遵守 `ELECTRON_SKIP_BINARY_DOWNLOAD`:若之前有意设置该变量,需要下载时先撤销跳过设置,否则继续跳过。离线部署可保留跳过设置并预装合适的裸 Electron,通过 `ELECTRON_PATH` 指向它。只有明确知道本插件所依赖 electron 包目录时,才可改用 `node "<已安装的 electron 包目录>/install.js"`。
55
+ `--no` 用于拒绝临时下载缺失命令;命令不存在时先检查 profile 与插件安装,不要改用同名第三方包。该命令遵守 `ELECTRON_SKIP_BINARY_DOWNLOAD`:若之前有意设置该变量,需要下载时先撤销跳过设置,否则就绪状态会显示「已跳过」。离线部署可保留跳过设置并预装合适的裸 Electron,通过 `ELECTRON_PATH` 指向它。只有明确知道本插件所依赖 electron 包目录时,才可改用 `node "<已安装的 electron 包目录>/install.js"`。
44
56
 
45
57
  ## 配置
46
58
 
@@ -5,6 +5,14 @@ export interface BridgeEndpoint {
5
5
  readonly pid: number;
6
6
  readonly updatedAt?: string;
7
7
  }
8
+ /**
9
+ * The same window, for the readiness report.
10
+ *
11
+ * Exported rather than re-stated: "the shell is gone" must mean one thing in this plugin. A second
12
+ * copy of the number would drift, and the drift would show up as a panel that says ready while every
13
+ * call times out — the exact failure this constant exists to prevent.
14
+ */
15
+ export declare const ENDPOINT_STALE_AFTER_MS = 60000;
8
16
  /**
9
17
  * A reusable connection to the bridge.
10
18
  *
@@ -42,6 +42,14 @@ const REQUEST_ID_FIELD = 'bridgeRequestId';
42
42
  * port nobody owns, and a client that trusts it dials that port for the rest of its life.
43
43
  */
44
44
  const ENDPOINT_TTL_MS = 60_000;
45
+ /**
46
+ * The same window, for the readiness report.
47
+ *
48
+ * Exported rather than re-stated: "the shell is gone" must mean one thing in this plugin. A second
49
+ * copy of the number would drift, and the drift would show up as a panel that says ready while every
50
+ * call times out — the exact failure this constant exists to prevent.
51
+ */
52
+ export const ENDPOINT_STALE_AFTER_MS = ENDPOINT_TTL_MS;
45
53
  /**
46
54
  * A reusable connection to the bridge.
47
55
  *
@@ -0,0 +1,30 @@
1
+ /** What the panel needs to know about the running shell. */
2
+ export interface BridgeEndpointState {
3
+ /** Whether a published endpoint file exists at all. */
4
+ readonly present: boolean;
5
+ /** Whether the shell behind it looks alive right now: a fresh stamp AND a live pid. */
6
+ readonly alive: boolean;
7
+ /** One line, already user-facing. */
8
+ readonly detail: string;
9
+ /** When the shell said it last refreshed the file, ISO, when the file carries a stamp. */
10
+ readonly updatedAt?: string;
11
+ }
12
+ /**
13
+ * Read the endpoint the shell publishes.
14
+ *
15
+ * Never throws: a settings panel must get an answer even when the file is mid-write, unreadable, or
16
+ * belongs to a shell that exited an hour ago.
17
+ * @param path - the endpoint file; defaults to the one location the shell writes.
18
+ * @param now - the clock, injected so a test can age a stamp without sleeping.
19
+ * @returns what the panel shows.
20
+ */
21
+ export declare function readBridgeEndpoint(path?: string, now?: number): BridgeEndpointState;
22
+ /**
23
+ * The endpoint file's mtime, for diagnostics that want to say "written at".
24
+ *
25
+ * Separate and optional: the readiness report does not need it, and a caller that does can fail
26
+ * without disturbing anything else.
27
+ * @param path - the endpoint file.
28
+ * @returns the mtime as ISO, or undefined.
29
+ */
30
+ export declare function bridgeEndpointWrittenAt(path?: string): string | undefined;