dsh-builtin-browser 0.5.8 → 1.0.1

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 (401) hide show
  1. package/CHANGELOG.md +410 -1
  2. package/README.en.md +16 -64
  3. package/README.md +33 -64
  4. package/assets/browser-carriers.svg +20 -0
  5. package/assets/browser-extension-identity.d.mts +2 -0
  6. package/assets/browser-extension-identity.mjs +2 -0
  7. package/assets/browser-messages.d.mts +5 -0
  8. package/assets/browser-messages.mjs +64 -0
  9. package/assets/browser-panel-locales.d.mts +2 -0
  10. package/assets/browser-panel-locales.mjs +380 -0
  11. package/assets/browser-policy.d.mts +37 -0
  12. package/assets/browser-policy.mjs +37 -0
  13. package/assets/browser-products.d.mts +6 -0
  14. package/assets/browser-products.mjs +76 -0
  15. package/assets/screenshots/1-main.png +0 -0
  16. package/assets/screenshots/2-form-fill.png +0 -0
  17. package/assets/screenshots/3-challenge.png +0 -0
  18. package/browser-extension/constants.mjs +20 -0
  19. package/browser-extension/controller.mjs +293 -0
  20. package/browser-extension/locales.mjs +15 -0
  21. package/browser-extension/manifest.json +12 -0
  22. package/browser-extension/options.html +14 -0
  23. package/browser-extension/options.mjs +9 -0
  24. package/browser-extension/permission-guard.mjs +13 -0
  25. package/browser-extension/worker.mjs +74 -0
  26. package/cordis.patch.yml +23 -48
  27. package/desktop-bridge/desktop-discovery.d.mts +2 -0
  28. package/desktop-bridge/desktop-discovery.mjs +36 -0
  29. package/desktop-bridge/desktop-identity.json +17 -1
  30. package/desktop-bridge/desktop-processes.d.mts +1 -0
  31. package/desktop-bridge/desktop-processes.mjs +15 -0
  32. package/desktop-bridge/guest-proxy.mjs +109 -0
  33. package/desktop-bridge/install.mjs +197 -74
  34. package/desktop-bridge/main.mjs +11 -0
  35. package/desktop-bridge/maintenance-files.d.mts +8 -0
  36. package/desktop-bridge/maintenance-files.mjs +28 -0
  37. package/desktop-bridge/maintenance-progress.ps1 +2 -2
  38. package/desktop-bridge/native-guests.mjs +41 -0
  39. package/desktop-bridge/plugin-browser-bridge.js +618 -370
  40. package/desktop-bridge/profile-loader.mjs +26 -0
  41. package/dist/client.cjs +43167 -0
  42. package/dist/client.d.cts +516 -0
  43. package/dist/client.d.mts +516 -0
  44. package/dist/index.cjs +92 -0
  45. package/dist/index.d.mts +2960 -0
  46. package/dist/index.mjs +24 -0
  47. package/docs/HANDOVER-2026-11-15.md +178 -0
  48. package/docs/README.md +10 -19
  49. package/docs/architecture.md +17 -145
  50. package/docs/child-tabs.md +13 -0
  51. package/docs/desktop-acceptance.md +9 -0
  52. package/docs/development.md +88 -18
  53. package/docs/extension-browser.md +44 -0
  54. package/docs/hardcoding-audit.md +64 -0
  55. package/docs/limitations.md +23 -73
  56. package/docs/pr64-extension-status.md +46 -0
  57. package/docs/pr64-maintenance.md +25 -0
  58. package/docs/pr64-native-children.md +52 -0
  59. package/docs/pr64-native-views.md +60 -0
  60. package/docs/tool-reference.md +87 -11
  61. package/docs/user-guide.md +47 -255
  62. package/docs/why-browser.md +6 -39
  63. package/dsh-host-patch/README.md +60 -0
  64. package/dsh-host-patch/apply.mjs +194 -0
  65. package/dsh-host-patch/legacy-bridge.mjs +53 -0
  66. package/dsh-host-patch/rc3-revision1.json +90 -0
  67. package/dsh-host-patch/rc3-revision2.json +112 -0
  68. package/dsh-host-patch/rc3-revision3.json.gz +0 -0
  69. package/dsh-host-patch/rc3-revision4.json.gz +0 -0
  70. package/dsh-host-patch/rc3-revision5.json.gz +0 -0
  71. package/dsh-host-patch/rc3-revision6.json.gz +0 -0
  72. package/dsh-host-patch/rc3-revision7.json.gz +0 -0
  73. package/dsh-host-patch/rc3-revision8.json.gz +0 -0
  74. package/dsh-host-patch/rc3.json +148 -0
  75. package/dsh-host-patch/rc5-revision1.json +90 -0
  76. package/dsh-host-patch/rc5-revision2.json +112 -0
  77. package/dsh-host-patch/rc5-revision3.json.gz +0 -0
  78. package/dsh-host-patch/rc5-revision4.json.gz +0 -0
  79. package/dsh-host-patch/rc5-revision5.json.gz +0 -0
  80. package/dsh-host-patch/rc5-revision6.json.gz +0 -0
  81. package/dsh-host-patch/rc5-revision7.json.gz +0 -0
  82. package/dsh-host-patch/rc5-revision8.json.gz +0 -0
  83. package/dsh-host-patch/rc5.json +148 -0
  84. package/lib/bridge-compatibility.js +38 -0
  85. package/lib/browser/handles.js +78 -0
  86. package/lib/browser/runtime.js +155 -43
  87. package/lib/browser/takeover-target.js +24 -0
  88. package/lib/browser-electron/authenticated-route.js +23 -0
  89. package/lib/browser-electron/automatic-maintenance.js +394 -51
  90. package/lib/browser-electron/bridge-auto.js +2 -1
  91. package/lib/browser-electron/bridge-connection.js +8 -1
  92. package/lib/browser-electron/bridge-install.js +27 -2
  93. package/lib/browser-electron/bridge-maintenance.js +35 -10
  94. package/lib/browser-electron/bridge-status.js +98 -27
  95. package/lib/browser-electron/desktop-bridge-host.js +193 -560
  96. package/lib/browser-electron/desktop-identity.js +40 -2
  97. package/lib/browser-electron/document-readiness.js +34 -0
  98. package/lib/browser-electron/electron-provision.js +14 -44
  99. package/lib/browser-electron/entry.js +659 -252
  100. package/lib/browser-electron/extension-browser.js +234 -0
  101. package/lib/browser-electron/extension-setup.js +69 -0
  102. package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
  103. package/lib/browser-electron/guest-cookie-jar.js +10559 -0
  104. package/lib/browser-electron/guest-cookie-store.js +74 -0
  105. package/lib/browser-electron/guest-css-runtime.js +75 -0
  106. package/lib/browser-electron/guest-css.js +106 -0
  107. package/lib/browser-electron/guest-route.js +603 -0
  108. package/lib/browser-electron/guest-runtime.js +356 -0
  109. package/lib/browser-electron/guest-storage-runtime.js +52 -0
  110. package/lib/browser-electron/guest-storage.js +163 -0
  111. package/lib/browser-electron/history-store.js +2 -1
  112. package/lib/browser-electron/host-main.js +162 -7
  113. package/lib/browser-electron/host-patch-maintenance.js +141 -0
  114. package/lib/browser-electron/http-body.js +22 -0
  115. package/lib/browser-electron/maintenance-broker.js +35 -5
  116. package/lib/browser-electron/maintenance-lifecycle.js +7 -5
  117. package/lib/browser-electron/maintenance-route.js +9 -6
  118. package/lib/browser-electron/open-slot.js +47 -0
  119. package/lib/browser-electron/paths.js +4 -1
  120. package/lib/browser-electron/preferred-browser.js +144 -0
  121. package/lib/browser-electron/preview-route.js +11 -8
  122. package/lib/browser-electron/process-ownership.js +198 -0
  123. package/lib/browser-electron/profile-checkpoint.js +222 -0
  124. package/lib/browser-electron/profile-command.js +60 -0
  125. package/lib/browser-electron/profile-extension.js +126 -0
  126. package/lib/browser-electron/profile-lease.js +157 -0
  127. package/lib/browser-electron/profile-residue.js +61 -0
  128. package/lib/browser-electron/provider.js +719 -262
  129. package/lib/browser-electron/reference-route.js +635 -0
  130. package/lib/browser-electron/remote-host.js +12 -13
  131. package/lib/browser-electron/runtime-route.js +6 -5
  132. package/lib/browser-electron/runtime-status.js +30 -29
  133. package/lib/browser-electron/settings-store.js +10 -5
  134. package/lib/browser-electron/shortcuts-route.js +108 -0
  135. package/lib/browser-electron/sidebar-only-host.js +119 -18
  136. package/lib/browser-electron/startpage-shortcuts.js +172 -0
  137. package/lib/browser-electron/system-browser.js +352 -371
  138. package/lib/browser-electron/windows-system.js +2 -1
  139. package/lib/browser-reference/delivery.js +326 -0
  140. package/lib/browser-reference/entry.js +597 -0
  141. package/lib/browser-reference/export.js +298 -0
  142. package/lib/browser-reference/import.js +295 -0
  143. package/lib/browser-reference/page-script.js +1406 -0
  144. package/lib/browser-reference/service.js +1062 -0
  145. package/lib/browser-reference/store.js +177 -0
  146. package/lib/browser-reference/submission-receipts.js +139 -0
  147. package/lib/browser-reference/text-quote.js +167 -0
  148. package/lib/browser-reference/types.js +11 -0
  149. package/lib/browser-reference/visible.js +311 -0
  150. package/lib/browser-reference/web-sources.js +97 -0
  151. package/lib/index.js +10 -3
  152. package/lib/reference-owner.js +5 -0
  153. package/lib/reference-page.js +12 -0
  154. package/lib/reference-source.js +2 -0
  155. package/lib/reference-text.js +188 -0
  156. package/lib/startpage-settings.js +63 -0
  157. package/lib/startpage.js +44 -0
  158. package/lib/takeover-protocol.js +2 -0
  159. package/lib/tool-browser/code-tool.js +416 -0
  160. package/lib/tool-browser/code-worker.js +872 -0
  161. package/lib/tool-browser/index.js +940 -76
  162. package/lib/tool-browser/page-probe.js +3 -3
  163. package/lib/tool-browser/panel-page.js +95 -0
  164. package/lib/tool-browser/screenshot-image.js +51 -0
  165. package/lib/tool-browser/takeover.js +205 -0
  166. package/lib/types.js +1 -0
  167. package/lib/web-guest.js +26 -0
  168. package/native-host/client.d.mts +17 -0
  169. package/native-host/client.mjs +100 -0
  170. package/native-host/host.mjs +150 -0
  171. package/native-host/identity.d.mts +2 -0
  172. package/native-host/identity.mjs +1 -0
  173. package/native-host/install.mjs +168 -0
  174. package/native-host/protocol.mjs +75 -0
  175. package/package.json +80 -92
  176. package/scripts/build.mjs +66 -0
  177. package/scripts/bundle-host.mjs +28 -0
  178. package/scripts/fix-exports.mjs +50 -0
  179. package/scripts/install-electron.mjs +11 -26
  180. package/scripts/verify-exports.mjs +47 -0
  181. package/scripts/verify-preview-sdk.mjs +93 -0
  182. package/skills/dsh-builtin-browser/SKILL.md +56 -47
  183. package/skills/dsh-builtin-browser/references/batch.md +31 -1
  184. package/skills/dsh-debug-host/SKILL.md +56 -0
  185. package/skills/dsh-debug-self/SKILL.md +50 -0
  186. package/src/bridge-compatibility.ts +39 -0
  187. package/src/browser/handles.ts +89 -0
  188. package/src/browser/runtime.ts +146 -50
  189. package/src/browser/takeover-target.ts +36 -0
  190. package/src/browser/types.ts +19 -7
  191. package/src/browser-electron/authenticated-route.ts +29 -1
  192. package/src/browser-electron/automatic-maintenance.ts +368 -56
  193. package/src/browser-electron/bridge-auto.ts +5 -4
  194. package/src/browser-electron/bridge-connection.ts +20 -2
  195. package/src/browser-electron/bridge-endpoint.ts +3 -3
  196. package/src/browser-electron/bridge-install.ts +40 -4
  197. package/src/browser-electron/bridge-maintenance.ts +42 -14
  198. package/src/browser-electron/bridge-status.ts +94 -23
  199. package/src/browser-electron/desktop-bridge-host.ts +185 -585
  200. package/src/browser-electron/desktop-identity.ts +53 -2
  201. package/src/browser-electron/document-readiness.ts +45 -0
  202. package/src/browser-electron/electron-provision.ts +12 -45
  203. package/src/browser-electron/entry.ts +1299 -882
  204. package/src/browser-electron/ephemeral-profile.ts +1 -1
  205. package/src/browser-electron/extension-browser.ts +223 -0
  206. package/src/browser-electron/extension-setup.ts +67 -0
  207. package/src/browser-electron/guest-cookie-jar.ts +176 -0
  208. package/src/browser-electron/guest-cookie-store.ts +59 -0
  209. package/src/browser-electron/guest-css-runtime.ts +76 -0
  210. package/src/browser-electron/guest-css.ts +68 -0
  211. package/src/browser-electron/guest-route.ts +568 -0
  212. package/src/browser-electron/guest-runtime.ts +357 -0
  213. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  214. package/src/browser-electron/guest-storage.ts +117 -0
  215. package/src/browser-electron/history-store.ts +5 -4
  216. package/src/browser-electron/host-main.ts +156 -11
  217. package/src/browser-electron/host-patch-maintenance.ts +112 -0
  218. package/src/browser-electron/http-body.ts +23 -0
  219. package/src/browser-electron/maintenance-broker.ts +29 -5
  220. package/src/browser-electron/maintenance-lifecycle.ts +14 -9
  221. package/src/browser-electron/maintenance-route.ts +17 -14
  222. package/src/browser-electron/missing-system-browser.ts +2 -2
  223. package/src/browser-electron/open-slot.ts +49 -0
  224. package/src/browser-electron/paths.ts +5 -1
  225. package/src/browser-electron/preferred-browser.ts +120 -0
  226. package/src/browser-electron/preview-route.ts +18 -11
  227. package/src/browser-electron/process-ownership.ts +168 -0
  228. package/src/browser-electron/profile-checkpoint.ts +187 -0
  229. package/src/browser-electron/profile-command.ts +46 -0
  230. package/src/browser-electron/profile-extension.ts +124 -0
  231. package/src/browser-electron/profile-lease.ts +115 -0
  232. package/src/browser-electron/profile-residue.ts +49 -0
  233. package/src/browser-electron/provider.ts +771 -289
  234. package/src/browser-electron/reference-route.ts +608 -0
  235. package/src/browser-electron/remote-host.ts +15 -15
  236. package/src/browser-electron/runtime-route.ts +11 -10
  237. package/src/browser-electron/runtime-status.ts +51 -32
  238. package/src/browser-electron/settings-store.ts +27 -7
  239. package/src/browser-electron/shortcuts-route.ts +112 -0
  240. package/src/browser-electron/sidebar-only-host.ts +118 -19
  241. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  242. package/src/browser-electron/system-browser.ts +309 -338
  243. package/src/browser-electron/windows-system.ts +2 -1
  244. package/src/browser-reference/delivery.ts +384 -0
  245. package/src/browser-reference/entry.ts +631 -0
  246. package/src/browser-reference/export.ts +339 -0
  247. package/src/browser-reference/import.ts +303 -0
  248. package/src/browser-reference/page-script.ts +1537 -0
  249. package/src/browser-reference/service.ts +1315 -0
  250. package/src/browser-reference/store.ts +172 -0
  251. package/src/browser-reference/submission-receipts.ts +122 -0
  252. package/src/browser-reference/text-quote.ts +219 -0
  253. package/src/browser-reference/types.ts +195 -0
  254. package/src/browser-reference/visible.ts +367 -0
  255. package/src/browser-reference/web-sources.ts +103 -0
  256. package/src/client/browser/BrowserController.ts +693 -0
  257. package/src/client/browser/BrowserFrame.ts +78 -0
  258. package/src/client/browser/BrowserNavigation.ts +169 -0
  259. package/src/client/browser/BrowserPage.ts +23 -0
  260. package/src/client/browser/BrowserPersistence.ts +44 -0
  261. package/src/client/browser/IframeImpl.ts +176 -0
  262. package/src/client/browser/child-tabs.ts +14 -0
  263. package/src/client/browser/iframe-reference.ts +67 -0
  264. package/src/client/browser/initialization.ts +262 -0
  265. package/src/client/browser/omnibox.ts +243 -0
  266. package/src/client/browser/store.ts +38 -0
  267. package/src/client/browser/takeover-channel.ts +72 -0
  268. package/src/client/browser/url.ts +46 -0
  269. package/src/client/browser/web-reference-source.ts +52 -0
  270. package/src/client/css-modules.d.ts +4 -0
  271. package/src/client/definition.tsx +30 -0
  272. package/src/client/electron/ElectronWebViewImpl.ts +364 -0
  273. package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
  274. package/src/client/electron/NativeChildPresentation.ts +45 -0
  275. package/src/client/electron/NativeViewPage.ts +251 -0
  276. package/src/client/electron/pages.ts +23 -0
  277. package/src/client/electron/reference-overlay.ts +53 -0
  278. package/src/client/electron/workspace.ts +33 -0
  279. package/src/client/index.ts +293 -0
  280. package/src/client/locales.ts +857 -0
  281. package/src/client/pages.ts +28 -0
  282. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  283. package/src/client/reference/client/draft-reference.ts +167 -0
  284. package/src/client/reference/client/index.ts +7 -0
  285. package/src/client/reference/client/ordered-submission.ts +108 -0
  286. package/src/client/reference/client/pending-delivery.ts +216 -0
  287. package/src/client/reference/client/plugin.ts +189 -0
  288. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  289. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  290. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  291. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  292. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  293. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  294. package/src/client/reference/client/production/assembly.ts +471 -0
  295. package/src/client/reference/client/production/asset-store.ts +144 -0
  296. package/src/client/reference/client/production/availability.ts +74 -0
  297. package/src/client/reference/client/production/bytes.ts +36 -0
  298. package/src/client/reference/client/production/delivery-client.ts +211 -0
  299. package/src/client/reference/client/production/draft-adapter.ts +508 -0
  300. package/src/client/reference/client/production/http-transport.ts +217 -0
  301. package/src/client/reference/client/production/production-submission.ts +310 -0
  302. package/src/client/reference/client/production/protocol.ts +231 -0
  303. package/src/client/reference/client/production/reference-card.ts +240 -0
  304. package/src/client/reference/client/production/reference-labels.ts +29 -0
  305. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  306. package/src/client/reference/client/production/reveal.ts +215 -0
  307. package/src/client/reference/client/production/runtime.ts +1101 -0
  308. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  309. package/src/client/reference/client/production/source-marker.ts +63 -0
  310. package/src/client/reference/client/production/source-opener.ts +55 -0
  311. package/src/client/reference/client/production/styles.ts +104 -0
  312. package/src/client/reference/client/production/user-text-rule.ts +58 -0
  313. package/src/client/reference/client/reveal.ts +107 -0
  314. package/src/client/reference/client/scheme.ts +114 -0
  315. package/src/client/reference/client/types.ts +168 -0
  316. package/src/client/reference/css-modules.d.ts +4 -0
  317. package/src/client/reference/index.ts +11 -0
  318. package/src/client/reference-capture-owner.ts +162 -0
  319. package/src/client/reference-intents.ts +36 -0
  320. package/src/client/settings/index.ts +34 -0
  321. package/{client.js → src/client/settings/panel.ts} +2657 -2231
  322. package/src/client/shortcut-open.ts +30 -0
  323. package/src/client/startpage/binding.ts +99 -0
  324. package/src/client/startpage/controller.ts +303 -0
  325. package/src/client/startpage/model.ts +279 -0
  326. package/src/client/view/Browser.module.css +751 -0
  327. package/src/client/view/BrowserBody.tsx +314 -0
  328. package/src/client/view/BrowserPresentation.ts +9 -0
  329. package/src/client/view/BrowserTitle.tsx +17 -0
  330. package/src/client/view/IframePresentation.ts +344 -0
  331. package/src/client/view/StartPage.tsx +597 -0
  332. package/src/client/view/TakeoverBanner.tsx +21 -0
  333. package/src/index.ts +110 -73
  334. package/src/reference-owner.ts +5 -0
  335. package/src/reference-page.ts +9 -0
  336. package/src/reference-source.ts +3 -0
  337. package/src/reference-text.ts +197 -0
  338. package/src/startpage-settings.ts +103 -0
  339. package/src/startpage.ts +71 -0
  340. package/src/takeover-protocol.ts +19 -0
  341. package/src/tool-browser/code-tool.ts +401 -0
  342. package/src/tool-browser/code-worker.ts +639 -0
  343. package/src/tool-browser/index.ts +908 -77
  344. package/src/tool-browser/page-probe.ts +4 -4
  345. package/src/tool-browser/panel-page.ts +124 -0
  346. package/src/tool-browser/screenshot-image.ts +49 -0
  347. package/src/tool-browser/takeover.ts +198 -0
  348. package/src/types/electron-shim.d.ts +20 -0
  349. package/src/types.ts +85 -0
  350. package/src/web-guest.ts +34 -0
  351. package/tools/accept-desktop.mjs +148 -0
  352. package/lib/browser/runtime.d.ts +0 -175
  353. package/lib/browser/types.d.ts +0 -797
  354. package/lib/browser-electron/authenticated-route.d.ts +0 -27
  355. package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
  356. package/lib/browser-electron/bridge-auto.d.ts +0 -93
  357. package/lib/browser-electron/bridge-connection.d.ts +0 -93
  358. package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
  359. package/lib/browser-electron/bridge-install.d.ts +0 -85
  360. package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
  361. package/lib/browser-electron/bridge-status.d.ts +0 -50
  362. package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
  363. package/lib/browser-electron/desktop-identity.d.ts +0 -58
  364. package/lib/browser-electron/electron-provision.d.ts +0 -92
  365. package/lib/browser-electron/entry.d.ts +0 -64
  366. package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
  367. package/lib/browser-electron/file-write.d.ts +0 -2
  368. package/lib/browser-electron/history-store.d.ts +0 -98
  369. package/lib/browser-electron/host-main.d.ts +0 -26
  370. package/lib/browser-electron/http-body.d.ts +0 -24
  371. package/lib/browser-electron/json-reply.d.ts +0 -33
  372. package/lib/browser-electron/maintenance-broker.d.ts +0 -35
  373. package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
  374. package/lib/browser-electron/maintenance-route.d.ts +0 -18
  375. package/lib/browser-electron/missing-system-browser.d.ts +0 -54
  376. package/lib/browser-electron/paths.d.ts +0 -4
  377. package/lib/browser-electron/preview-route.d.ts +0 -89
  378. package/lib/browser-electron/process.d.ts +0 -14
  379. package/lib/browser-electron/provider.d.ts +0 -959
  380. package/lib/browser-electron/remote-host.d.ts +0 -256
  381. package/lib/browser-electron/rpc-input.d.ts +0 -4
  382. package/lib/browser-electron/rpc-ops.d.ts +0 -18
  383. package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
  384. package/lib/browser-electron/runtime-route.d.ts +0 -55
  385. package/lib/browser-electron/runtime-status.d.ts +0 -116
  386. package/lib/browser-electron/settings-route.d.ts +0 -15
  387. package/lib/browser-electron/settings-store.d.ts +0 -224
  388. package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
  389. package/lib/browser-electron/system-browser.d.ts +0 -367
  390. package/lib/browser-electron/timing.d.ts +0 -8
  391. package/lib/browser-electron/virtual-cursor.d.ts +0 -67
  392. package/lib/browser-electron/windows-system.d.ts +0 -3
  393. package/lib/index.d.ts +0 -30
  394. package/lib/tool-browser/element-fields.d.ts +0 -145
  395. package/lib/tool-browser/index.d.ts +0 -53
  396. package/lib/tool-browser/page-probe.d.ts +0 -86
  397. package/scripts/consumer-install-check.mjs +0 -72
  398. package/scripts/run-tests.mjs +0 -32
  399. package/scripts/verify-host-compat.mjs +0 -195
  400. package/scripts/verify-preview-route.mjs +0 -168
  401. package/scripts/verify-runtime-status.mjs +0 -179
@@ -1,3 +1,5 @@
1
+ import { hostMessages } from '../../assets/browser-messages.mjs'
2
+ import { LOOPBACK_IPV4, BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
1
3
  /**
2
4
  * Self-hosted Electron browser host (child side): the Electron main process
3
5
  * spawned by {@link RemoteElectronViewHost}. Owns one `BrowserWindow` PER
@@ -24,16 +26,27 @@
24
26
  * @module dsh-browser/browser-electron/host-main
25
27
  */
26
28
 
27
- import { app, BrowserWindow, WebContentsView } from 'electron'
29
+ import { app, BrowserWindow, Menu, session, WebContentsView } from 'electron'
30
+ import {
31
+ overlayScript,
32
+ overlayDisposeScript,
33
+ referenceMenuTemplate,
34
+ standaloneScript,
35
+ REFERENCE_INTENT_CHANNEL,
36
+ MAX_REFERENCE_COMMENT,
37
+ MAX_REFERENCE_TEXT,
38
+ } from '../browser-reference/entry.ts'
39
+ import { validateFrozenCapture } from '../browser-reference/page-script.ts'
28
40
  import { createInterface } from 'node:readline'
29
41
  import { createConnection } from 'node:net'
30
42
  import { mkdirSync, writeFileSync } from 'node:fs'
31
- import { writeFileNoReplace } from './file-write.js'
32
- import { electronRuntimeDiagnosticLines } from './runtime-diagnostics.js'
33
- import { createRpcLineReader } from './rpc-input.js'
43
+ import { writeFileNoReplace } from './file-write.ts'
44
+ import { electronRuntimeDiagnosticLines } from './runtime-diagnostics.ts'
45
+ import { createRpcLineReader } from './rpc-input.ts'
34
46
  import { tmpdir } from 'node:os'
35
47
  import { join } from 'node:path'
36
- import { withTimeoutShared } from './timing.js'
48
+ import { withTimeoutShared } from './timing.ts'
49
+ import { dshHome } from './paths.ts'
37
50
 
38
51
  // Report the binary actually running this child, even when ELECTRON_PATH
39
52
  // intentionally selects a different version from the plugin's dependency.
@@ -54,8 +67,8 @@ for (const line of electronRuntimeDiagnosticLines(process.versions)) {
54
67
  // (capturePage then fails). A dedicated userData also persists cookies across
55
68
  // host restarts (on top of dsh_browser_auth). Must run before app is ready.
56
69
  try {
57
- const base = process.env.DSH_HOME ?? app.getPath('appData')
58
- app.setPath('userData', join(base, 'dsh-builtin-browser-host'))
70
+ const base = dshHome()
71
+ app.setPath('userData', join(base, BROWSER_PROFILE_DIR))
59
72
  } catch (error) {
60
73
  process.stderr.write(`[dsh-browser host] userData setup failed: ${String(error)}\n`)
61
74
  }
@@ -411,6 +424,7 @@ function windowFor(windowId: string | undefined): HostWindow {
411
424
  // (measured: the setting was on and the window still popped up). The first presentation decides:
412
425
  // quiet shows it inactive, a normal call shows it normally.
413
426
  const w = new BrowserWindow({ width: 1400, height: 900, show: false, title: 'dsh-browser' })
427
+ w.webContents.setWindowOpenHandler(() => ({ action: 'deny' }))
414
428
  w.on('closed', () => {
415
429
  const closing = windows.get(key)
416
430
  windows.delete(key)
@@ -710,9 +724,7 @@ async function handle(op: string, msg: { id: number; viewId?: string; windowId?:
710
724
  }
711
725
  return { action: 'deny' }
712
726
  }
713
- // Non-HTTP popups (OAuth redirects, mailto:, custom schemes):
714
- // allow the native window so OAuth flows and deep links work.
715
- return { action: 'allow' }
727
+ return { action: 'deny' }
716
728
  })
717
729
  // Attach the debugger BEFORE the view can be seen: an attach failure
718
730
  // then leaves nothing in the window (no visible ghost view).
@@ -1146,6 +1158,125 @@ function keepWindowsNonOccluding(): void {
1146
1158
  }
1147
1159
  keepWindowsNonOccluding()
1148
1160
 
1161
+
1162
+ // ---------------------------------------------------------------------------
1163
+ // Human reference entries (design §3.1 / §11.3): ONE owner per page.
1164
+ // A typed preload gives the page a narrow intent channel; the page-side
1165
+ // overlay is low-trust and never receives activeTab/screenshot authority.
1166
+ // ---------------------------------------------------------------------------
1167
+ const REFERENCE_PRELOAD = `const { contextBridge, ipcRenderer } = require('electron')
1168
+ try {
1169
+ contextBridge.exposeInMainWorld('__dshRef', {
1170
+ intent: payload => ipcRenderer.send('dsh-reference-intent', payload),
1171
+ })
1172
+ } catch (error) { /* another preload already owns this name */ }
1173
+ `
1174
+ const REFERENCE_PRELOAD_PATH = join(TOOLBAR_DIR, 'reference-preload.js')
1175
+
1176
+ function isToolbarContents(contents: import('electron').WebContents): boolean {
1177
+ try { return contents.getURL().endsWith('/toolbar.html') } catch { return false }
1178
+ }
1179
+
1180
+ /** Find the session/window id whose view owns these webContents. */
1181
+ function windowIdForContents(contents: import('electron').WebContents): string | undefined {
1182
+ for (const [key, win] of windows) {
1183
+ for (const entry of win.views.values()) {
1184
+ try {
1185
+ if (entry.webContentsView.webContents === contents) return key
1186
+ } catch { /* view was destroyed mid-iteration */ }
1187
+ }
1188
+ }
1189
+ return undefined
1190
+ }
1191
+
1192
+ /** Install the single merged context menu and the resident selection entry. */
1193
+ function attachReferenceEntry(contents: import('electron').WebContents): void {
1194
+ if (isToolbarContents(contents)) return
1195
+ contents.on('context-menu', (_event, params) => {
1196
+ const windowId = windowIdForContents(contents)
1197
+ if (windowId === undefined) return
1198
+ // The browser's ordinary edit items are kept in the SAME menu, so no second
1199
+ // adapter can pop another one over it (design §3.1:59). The real params
1200
+ // decide which reference actions exist, and the target travels with the
1201
+ // action so a collapsed selection cannot change what was clicked (§3.2/§3.3).
1202
+ const hasSelection = typeof params.selectionText === 'string' && params.selectionText.trim() !== ''
1203
+ const mediaType = typeof params.mediaType === 'string' ? params.mediaType : undefined
1204
+ const template = referenceMenuTemplate({
1205
+ hasSelection,
1206
+ ...mediaType !== undefined ? { mediaType } : {},
1207
+ }).map(item => {
1208
+ if (item.kind === 'separator') return { type: 'separator' as const }
1209
+ if (item.kind === 'role') {
1210
+ if (item.role === undefined) return { type: 'separator' as const }
1211
+ return { role: item.role, label: item.label }
1212
+ }
1213
+ const target = item.target === undefined ? undefined : {
1214
+ kind: item.target,
1215
+ ...item.target === 'image' && typeof params.srcURL === 'string' && params.srcURL !== ''
1216
+ ? { srcUrl: params.srcURL } : {},
1217
+ ...Number.isFinite(params.x) ? { x: params.x } : {},
1218
+ ...Number.isFinite(params.y) ? { y: params.y } : {},
1219
+ }
1220
+ return {
1221
+ id: item.id,
1222
+ label: item.label,
1223
+ click: () => sendUserAction({
1224
+ type: 'capture-reference', windowId, entry: 'native-menu',
1225
+ ...target !== undefined ? { target } : {},
1226
+ }),
1227
+ }
1228
+ })
1229
+ try { Menu.buildFromTemplate(template).popup() } catch (error) {
1230
+ process.stderr.write(`[dsh-browser host] reference menu failed: ${String(error)}\n`)
1231
+ }
1232
+ })
1233
+ contents.on('ipc-message', (_event, channel, ...args) => {
1234
+ if (channel !== 'dsh-reference-intent') return
1235
+ const intent = args[0] as Record<string, unknown> | undefined
1236
+ if (intent === undefined || intent.type !== REFERENCE_INTENT_CHANNEL) return
1237
+ // isTrusted is deliberately NOT read: a page overlay is a low-trust entry.
1238
+ const windowId = windowIdForContents(contents)
1239
+ if (windowId === undefined) return
1240
+ // The page trims its own note; the host re-bounds it because a page is
1241
+ // low-trust, and ignores anything that is not a string.
1242
+ const rawComment = typeof intent.comment === 'string' ? intent.comment.trim() : ''
1243
+ const comment = rawComment.slice(0, MAX_REFERENCE_COMMENT)
1244
+ // The bar freezes the selection text before the comment field takes focus
1245
+ // (focusing it collapses the page selection). Re-bound here: a page is
1246
+ // low-trust, and this string becomes the locator when the live selection is
1247
+ // already gone.
1248
+ const rawSelection = typeof intent.selectionText === 'string' ? intent.selectionText : ''
1249
+ const selectionText = rawSelection.trim().slice(0, MAX_REFERENCE_TEXT)
1250
+ // The bar freezes the complete ordered capture before its comment field
1251
+ // takes focus. Bound and shape-check it here: a page is low-trust.
1252
+ const capture = validateFrozenCapture(intent.capture)
1253
+ sendUserAction({
1254
+ type: 'capture-reference', windowId, entry: 'page-overlay',
1255
+ ...comment !== '' ? { comment } : {},
1256
+ ...selectionText !== '' ? { selectionText } : {},
1257
+ ...capture !== undefined ? { capture } : {},
1258
+ })
1259
+ })
1260
+ contents.on('dom-ready', () => {
1261
+ if (isToolbarContents(contents)) return
1262
+ void contents.executeJavaScript(standaloneScript(overlayScript(), { label: hostMessages.zh.referenceLabel }))
1263
+ .catch(() => { /* an extension-managed page owns its own entry */ })
1264
+ })
1265
+ }
1266
+
1267
+ app.on('web-contents-created', (_event, contents) => {
1268
+ try { attachReferenceEntry(contents) } catch (error) {
1269
+ process.stderr.write(`[dsh-browser host] reference entry failed: ${String(error)}\n`)
1270
+ }
1271
+ })
1272
+
1273
+ /** Remove the overlay on plugin shutdown; the disposer clears every listener. */
1274
+ export function disposeReferenceEntries(views: Iterable<import('electron').WebContents>): void {
1275
+ for (const contents of views) {
1276
+ try { void contents.executeJavaScript(standaloneScript(overlayDisposeScript())) } catch { /* gone */ }
1277
+ }
1278
+ }
1279
+
1149
1280
  /**
1150
1281
  * Electron entry: connect back to the parent's RPC server (port from
1151
1282
  * `--rpc-port`) and serve line-delimited JSON-RPC. `ELECTRON_RUN_AS_NODE` is
@@ -1153,6 +1284,20 @@ keepWindowsNonOccluding()
1153
1284
  * the app entry so `app` is available immediately.
1154
1285
  */
1155
1286
  void app.whenReady().then(() => {
1287
+ // One narrow preload for every webContents in this session. It only exposes
1288
+ // an intent sender; no file, command or CDP capability crosses the boundary.
1289
+ try {
1290
+ mkdirSync(TOOLBAR_DIR, { recursive: true })
1291
+ writeFileSync(REFERENCE_PRELOAD_PATH, REFERENCE_PRELOAD)
1292
+ // APPEND, never replace: another part of the shell may already own a
1293
+ // preload, and `setPreloads` takes the whole list.
1294
+ const existing = session.defaultSession.getPreloads()
1295
+ if (!existing.includes(REFERENCE_PRELOAD_PATH)) {
1296
+ session.defaultSession.setPreloads([...existing, REFERENCE_PRELOAD_PATH])
1297
+ }
1298
+ } catch (error) {
1299
+ process.stderr.write(`[dsh-browser host] reference preload unavailable: ${String(error)}\n`)
1300
+ }
1156
1301
  const portArg = process.argv.indexOf('--rpc-port')
1157
1302
  const port = portArg >= 0 ? Number(process.argv[portArg + 1]) : NaN
1158
1303
  if (!Number.isFinite(port)) {
@@ -1160,7 +1305,7 @@ void app.whenReady().then(() => {
1160
1305
  app.exit(1)
1161
1306
  return
1162
1307
  }
1163
- const socket = createConnection({ host: '127.0.0.1', port })
1308
+ const socket = createConnection({ host: LOOPBACK_IPV4, port })
1164
1309
  rpcSocket = socket
1165
1310
  socket.setEncoding('utf8')
1166
1311
  // Prove we know the parent's spawn token before anything else; the parent
@@ -0,0 +1,112 @@
1
+ /** Explicit Web maintenance for the sidebar bundle selected by DSH's client module registry. */
2
+ import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
3
+ import { dirname, join } from 'node:path'
4
+ import type { IncomingMessage, ServerResponse } from 'node:http'
5
+ import type { HostPatchResult } from './bridge-install.ts'
6
+ import { sameOrigin } from './settings-route.ts'
7
+ import { isDirectLoopback } from './authenticated-route.ts'
8
+ import { readJsonBody } from './http-body.ts'
9
+ import { replyJson } from './json-reply.ts'
10
+
11
+ export const HOST_PATCH_ROUTE = '/dsh-builtin-browser/host-patch-maintenance'
12
+ const sidebar = '@deepseek-ai/dsh-client-ui-sidebar-right'
13
+
14
+ /** The registry owns the exact npm or source-checkout bundle served by this Host. */
15
+ export interface ServedClientModules {
16
+ clientPath(id: string): string | undefined
17
+ rebuilt?(id: string): unknown
18
+ }
19
+
20
+ interface PatchState extends HostPatchResult {
21
+ readonly surface: 'web' | 'desktop'
22
+ readonly canInstall: boolean
23
+ readonly canRestore: boolean
24
+ readonly restartRequired: boolean
25
+ }
26
+
27
+ /** Bind to the live optional service, never resolve a second copy relative to the plugin. */
28
+ export function servedClientModules(value: unknown): ServedClientModules | undefined {
29
+ if (value !== null && typeof value === 'object' && 'clientPath' in value && typeof value.clientPath === 'function') {
30
+ return value as ServedClientModules
31
+ }
32
+ return undefined
33
+ }
34
+
35
+ /** Locate only the package whose lib/client.js the running registry actually advertises. */
36
+ export function servedSidebarPackage(modules: ServedClientModules | undefined): string {
37
+ const path = modules?.clientPath(sidebar)
38
+ if (path === undefined) throw new Error('The running DSH client registry has no sidebar bundle; host patch maintenance is unavailable.')
39
+ const file = realpathSync(path)
40
+ const directory = dirname(dirname(file))
41
+ const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'))
42
+ if (manifest.name !== sidebar || realpathSync(join(directory, 'lib/client.js')) !== file) {
43
+ throw new Error('The served sidebar bundle is not the supported package lib/client.js.')
44
+ }
45
+ return directory
46
+ }
47
+
48
+ /** Same authenticated, same-origin, local-only maintenance admission as Desktop settings. */
49
+ export function createHostPatchMaintenance(deps: {
50
+ readonly modules: () => ServedClientModules | undefined
51
+ readonly desktop: () => boolean
52
+ }): (request: IncomingMessage, response: ServerResponse) => Promise<void> {
53
+ let running = false
54
+ return async (request, response) => {
55
+ if (request.method !== 'GET' && request.method !== 'POST') { replyJson(response, 405, { ok: false, error: 'method-not-allowed' }); return }
56
+ if (!sameOrigin(request, request.method === 'POST') || !isDirectLoopback(request)) {
57
+ replyJson(response, 403, { ok: false, error: 'same-origin-local-request-required' }); return
58
+ }
59
+ if (deps.desktop()) {
60
+ replyJson(response, request.method === 'GET' ? 200 : 409, { ok: request.method === 'GET', hostPatch: { surface: 'desktop', status: 'absent', canInstall: false, canRestore: false,
61
+ restartRequired: false, reason: 'Use Desktop bridge maintenance to change host files after Desktop exits.' } }); return
62
+ }
63
+ let directory: string
64
+ const modules = deps.modules()
65
+ try { directory = servedSidebarPackage(modules) }
66
+ catch (error) {
67
+ replyJson(response, request.method === 'GET' ? 200 : 409, { ok: request.method === 'GET', hostPatch: {
68
+ surface: 'web', status: 'anchors mismatch', canInstall: false, canRestore: false, restartRequired: false, reason: String(error),
69
+ } }); return
70
+ }
71
+ const patcher = await import(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href)
72
+ const read = (): PatchState => {
73
+ const result: HostPatchResult = patcher.hostPatchStatus(directory)
74
+ let writable = true
75
+ let reason = result.reason
76
+ try {
77
+ for (const path of [join(directory, 'lib'), join(directory, 'lib/client.js')]) {
78
+ if ((statSync(path).mode & 0o222) === 0) throw new Error('read-only permissions')
79
+ accessSync(path, constants.W_OK)
80
+ }
81
+ } catch (error) { writable = false; reason = 'The served sidebar package is not writable: ' + String(error) }
82
+ return { ...result, ...(reason === undefined ? {} : { reason }), surface: 'web',
83
+ canInstall: writable && result.status === 'absent',
84
+ canRestore: writable && result.status === 'applied' && existsSync(join(directory, 'lib/client.js.before-dsh-host-patch')),
85
+ restartRequired: false }
86
+ }
87
+ if (request.method === 'GET') { replyJson(response, 200, { ok: true, hostPatch: read() }); return }
88
+ if (running) { replyJson(response, 409, { ok: false, error: 'host patch maintenance is already running' }); return }
89
+ let action: 'install' | 'restore'
90
+ try {
91
+ const input = await readJsonBody<{ action?: unknown }>(request, 4096)
92
+ if (input?.action !== 'install' && input?.action !== 'restore') throw new Error('action must be install or restore')
93
+ action = input.action
94
+ } catch (error) { replyJson(response, 400, { ok: false, error: String(error) }); return }
95
+ const before = read()
96
+ if (action === 'install' ? !before.canInstall : !before.canRestore) {
97
+ replyJson(response, 409, { ok: false, hostPatch: before, error: before.reason ?? 'This action is not available for the served sidebar package.' }); return
98
+ }
99
+ running = true
100
+ try {
101
+ const result: HostPatchResult = action === 'install' ? patcher.applyHostPatch(directory) : patcher.restoreHostPatch(directory)
102
+ const ok = result.status === (action === 'install' ? 'applied' : 'absent')
103
+ let restartRequired = ok && result.changed === true
104
+ let reason = result.reason
105
+ if (restartRequired && typeof modules?.rebuilt === 'function') {
106
+ try { modules.rebuilt(sidebar); restartRequired = false }
107
+ catch (error) { reason = 'Files changed, but DSH could not refresh its bundle cache: ' + String(error) }
108
+ }
109
+ replyJson(response, ok ? 200 : 409, { ok, hostPatch: { ...read(), ...result, ...(reason === undefined ? {} : { reason }), restartRequired } })
110
+ } finally { running = false }
111
+ }
112
+ }
@@ -29,6 +29,29 @@ export async function readTextBody(request: IncomingMessage, limit = 64 * 1024):
29
29
  return Buffer.concat(chunks).toString('utf8')
30
30
  }
31
31
 
32
+ /**
33
+ * Read a bounded binary body. The reference-import route takes ZIP bytes directly instead of a
34
+ * base64 JSON wrapper: a wrapper would inflate the limit by a third and add a decoding step that
35
+ * can hide an oversize body until after it has been allocated.
36
+ * @param request - the incoming request.
37
+ * @param limit - maximum accepted bytes.
38
+ * @returns the raw body.
39
+ */
40
+ export async function readBinaryBody(request: IncomingMessage, limit = 32 * 1024 * 1024): Promise<Buffer> {
41
+ const chunks: Buffer[] = []
42
+ let size = 0
43
+ for await (const chunk of request) {
44
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))
45
+ size += buffer.length
46
+ if (size > limit) {
47
+ request.destroy()
48
+ throw new Error(`request body exceeds ${limit} bytes`)
49
+ }
50
+ chunks.push(buffer)
51
+ }
52
+ return Buffer.concat(chunks)
53
+ }
54
+
32
55
  /**
33
56
  * Read and parse a JSON body. An empty body is an empty object, matching the settings route's
34
57
  * long-standing behaviour.
@@ -1,13 +1,14 @@
1
1
  /**
2
- * Start a local Windows maintenance coordinator through WMI, outside the requesting app's tree.
2
+ * Start a local maintenance coordinator outside the requesting app's tree: through WMI on Windows,
3
+ * as a detached session leader on macOS (which survives the app quitting).
3
4
  * This primitive only creates the requested process; its caller owns maintenance authorization,
4
5
  * the coordinator's plan, readiness handshake and normal application shutdown.
5
6
  * @module dsh-browser/browser-electron/maintenance-broker
6
7
  */
7
- import { execFile } from 'node:child_process'
8
+ import { execFile, spawn } from 'node:child_process'
8
9
  import { statSync } from 'node:fs'
9
- import { win32 } from 'node:path'
10
- import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.js'
10
+ import { isAbsolute, posix, win32 } from 'node:path'
11
+ import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.ts'
11
12
 
12
13
  export interface MaintenanceBrokerOptions {
13
14
  readonly runtimePath: string
@@ -86,6 +87,27 @@ const defaultExecutor: MaintenanceBrokerExecutor = (file, args, options) => new
86
87
  })
87
88
  })
88
89
 
90
+ /** macOS: a new session (setsid) with no inherited stdio, so the coordinator outlives Desktop. */
91
+ async function launchDetached(options: MaintenanceBrokerOptions, environment: NodeJS.ProcessEnv): Promise<MaintenanceBrokerResult> {
92
+ for (const [label, value] of [['runtimePath', options.runtimePath], ['cwd', options.cwd]] as const) {
93
+ if (typeof value !== 'string' || value.includes('\0') || !isAbsolute(value)) throw new Error(`${label} must be an absolute path without NUL`)
94
+ }
95
+ const runtimePath = posix.normalize(options.runtimePath)
96
+ const cwd = posix.normalize(options.cwd)
97
+ if (!statSync(runtimePath).isFile()) throw new Error('the maintenance runtime is not a file')
98
+ if (!statSync(cwd).isDirectory()) throw new Error('the maintenance working directory is not a directory')
99
+ if (!Array.isArray(options.args)) throw new Error('maintenance arguments must be an array')
100
+ return await new Promise((resolve, reject) => {
101
+ const child = spawn(runtimePath, [...options.args], { cwd, env: environment, detached: true, stdio: 'ignore', shell: false })
102
+ child.once('error', error => { reject(new Error(`maintenance broker failed: ${String(error)}`)) })
103
+ child.once('spawn', () => {
104
+ child.unref()
105
+ if (!Number.isSafeInteger(child.pid) || Number(child.pid) <= 0) reject(new Error('the maintenance broker returned no valid process id'))
106
+ else resolve({ pid: Number(child.pid) })
107
+ })
108
+ })
109
+ }
110
+
89
111
  /**
90
112
  * Create a hidden, independent local process. No shell evaluates runtime paths or arguments.
91
113
  * WMI receives an explicit environment copied from this process, including any plan overrides;
@@ -99,7 +121,9 @@ export async function launchMaintenanceBroker(
99
121
  if (deps.execFile === undefined && (underTest(process.env) || underTest(environment))) {
100
122
  throw new Error('the real Windows maintenance broker is disabled in tests; inject a fake executor')
101
123
  }
102
- if ((deps.platform ?? process.platform) !== 'win32') throw new Error('the maintenance broker requires Windows')
124
+ const platform = deps.platform ?? process.platform
125
+ if (platform === 'darwin') return await launchDetached(options, environment)
126
+ if (platform !== 'win32') throw new Error('the maintenance broker requires Windows or macOS')
103
127
  const runtimePath = absolutePath(options.runtimePath, 'runtimePath')
104
128
  const cwd = absolutePath(options.cwd, 'cwd')
105
129
  if (!statSync(runtimePath).isFile()) throw new Error('the maintenance runtime is not a file')
@@ -1,17 +1,22 @@
1
1
  /** Explicit bridge maintenance lifecycle, independent of the Desktop-owned HTTP request. */
2
- import type { BridgeAction, BridgeActionResult } from './bridge-install.js'
2
+ import type { BridgeAction, BridgeActionResult } from './bridge-install.ts'
3
3
 
4
4
  export type MaintenancePhase = 'armed' | 'closing' | 'installing' | 'restarting' | 'verifying' | 'completed' | 'cancelled' | 'failed'
5
+ export type MaintenanceAction = BridgeAction | 'reinstall'
6
+
7
+ export class MaintenanceRecoveryError extends Error {}
5
8
 
6
9
  export interface MaintenanceState {
7
10
  readonly phase: MaintenancePhase
8
- readonly action: BridgeAction
11
+ readonly action: MaintenanceAction
9
12
  readonly at: string
10
13
  readonly ok?: boolean
11
14
  readonly restarted?: boolean
12
15
  readonly pid?: number
13
16
  readonly error?: string
17
+ readonly progressError?: string
14
18
  readonly output?: string
19
+ readonly hostPatch?: BridgeActionResult['hostPatch']
15
20
  }
16
21
 
17
22
  /** Effects are supplied by the independent worker; tests cannot close or start an application. */
@@ -25,7 +30,7 @@ export interface MaintenanceLifecycleDeps {
25
30
  /** Reopen exactly the verified installation after it has exited. */
26
31
  readonly restart: () => Promise<number>
27
32
  /** Installation verifies the new authenticated bridge; uninstall verifies the process. */
28
- readonly verify: (pid: number, action: BridgeAction) => Promise<void>
33
+ readonly verify: (pid: number, action: MaintenanceAction) => Promise<void>
29
34
  readonly publish: (state: MaintenanceState) => Promise<void>
30
35
  }
31
36
 
@@ -33,7 +38,7 @@ export interface MaintenanceLifecycleDeps {
33
38
  * A cancelled/failed quit never reaches the installer. After a confirmed exit, reopen Desktop even
34
39
  * when maintenance fails, and retain that failure instead of reporting a successful installation.
35
40
  */
36
- export async function runMaintenanceLifecycle(action: BridgeAction, deps: MaintenanceLifecycleDeps): Promise<MaintenanceState> {
41
+ export async function runMaintenanceLifecycle(action: MaintenanceAction, deps: MaintenanceLifecycleDeps): Promise<MaintenanceState> {
37
42
  let closed = false
38
43
  let restarted = false
39
44
  let pid: number | undefined
@@ -46,8 +51,9 @@ export async function runMaintenanceLifecycle(action: BridgeAction, deps: Mainte
46
51
  // prevent reopening a Desktop that already exited normally.
47
52
  if (phase === 'armed') throw error
48
53
  publicationFailure ??= error
54
+ console.error(`[dsh-browser maintenance] cannot publish ${phase} progress: ${String(error)}`)
49
55
  }
50
- return state
56
+ return publicationFailure === undefined ? state : { ...state, progressError: String(publicationFailure) }
51
57
  }
52
58
  await publish('armed')
53
59
  try {
@@ -76,10 +82,9 @@ export async function runMaintenanceLifecycle(action: BridgeAction, deps: Mainte
76
82
  } catch (error) {
77
83
  failure = failure === undefined ? error : new Error(`${String(failure)}; Desktop recovery: ${String(error)}`)
78
84
  }
79
- if (failure === undefined && publicationFailure !== undefined) {
80
- failure = new Error(`Desktop maintenance finished, but progress could not be saved: ${String(publicationFailure)}`)
81
- }
82
- const details = { restarted, ...pid === undefined ? {} : { pid }, ...outcome?.output ? { output: outcome.output } : {} }
85
+ const details = { restarted, ...pid === undefined ? {} : { pid }, ...outcome?.output ? { output: outcome.output } : {},
86
+ ...publicationFailure === undefined ? {} : { progressError: String(publicationFailure) },
87
+ ...outcome?.hostPatch === undefined ? {} : { hostPatch: outcome.hostPatch } }
83
88
  return failure === undefined
84
89
  ? await publish('completed', { ...details, ok: true })
85
90
  : await publish('failed', { ...details, ok: false, error: String(failure) })
@@ -1,17 +1,18 @@
1
1
  /** Authenticated explicit maintenance protocol; older hosts cannot mistake it for direct install. */
2
2
  import type { IncomingMessage, ServerResponse } from 'node:http'
3
- import { sameOrigin } from './settings-route.js'
4
- import { isDirectLoopback } from './authenticated-route.js'
5
- import { replyJson } from './json-reply.js'
6
- import { readJsonBody } from './http-body.js'
7
- import type { BridgeAction } from './bridge-install.js'
8
- import type { AutomaticMaintenanceJob } from './automatic-maintenance.js'
3
+ import { sameOrigin } from './settings-route.ts'
4
+ import { isDirectLoopback } from './authenticated-route.ts'
5
+ import { replyJson } from './json-reply.ts'
6
+ import { readJsonBody } from './http-body.ts'
7
+ import type { AutomaticMaintenanceJob, AutomaticMaintenanceOptions } from './automatic-maintenance.ts'
9
8
 
10
9
  export const AUTOMATIC_MAINTENANCE_ROUTE = '/dsh-builtin-browser/bridge-maintenance'
11
10
  export interface AutomaticMaintenanceRouteDeps {
12
11
  readonly supported: () => boolean
12
+ /** How Desktop is asked to quit: `menu` waits for the panel to open the native menu, `self` needs nothing from it. */
13
+ readonly quit?: () => 'menu' | 'self'
13
14
  readonly read: () => AutomaticMaintenanceJob | undefined
14
- readonly start: (action: BridgeAction, options?: { readonly locale?: 'zh' | 'en' }) => Promise<AutomaticMaintenanceJob>
15
+ readonly start: (action: 'reinstall', options?: AutomaticMaintenanceOptions) => Promise<AutomaticMaintenanceJob>
15
16
  /** Commit only after the accepted response has been flushed to the client. */
16
17
  readonly commit?: (id: string) => Promise<void>
17
18
  /** True while the legacy bridge-action route is running an installer. */
@@ -30,12 +31,13 @@ export function createAutomaticMaintenanceHandler(deps: AutomaticMaintenanceRout
30
31
  replyJson(response, 200, { ok: true, protocol: 1, supported: deps.supported(), ...job === undefined ? {} : { job } })
31
32
  return
32
33
  }
33
- if (!deps.supported()) { replyJson(response, 409, { ok: false, error: 'automatic bridge maintenance requires Windows Desktop' }); return }
34
- let action: BridgeAction
34
+ if (!deps.supported()) { replyJson(response, 409, { ok: false, error: 'automatic bridge maintenance requires DSH Desktop on Windows or macOS' }); return }
35
+ let action: 'reinstall'
35
36
  let locale: 'zh' | 'en' | undefined
36
37
  try {
37
- const value = await readJsonBody<{ action?: unknown; locale?: unknown }>(request, 4096)
38
- if (value?.action !== 'install' && value?.action !== 'uninstall') throw new Error('action must be install or uninstall')
38
+ const value = await readJsonBody<{ action?: unknown; locale?: unknown; mode?: unknown; hostStatus?: unknown }>(request, 4096)
39
+ if (value?.action !== 'reinstall') throw new Error('action must be reinstall')
40
+ if (value.mode !== undefined || value.hostStatus !== undefined) throw new Error('mode and hostStatus are no longer supported')
39
41
  if (value.locale !== undefined && value.locale !== 'zh' && value.locale !== 'en') throw new Error('locale must be zh or en')
40
42
  action = value.action
41
43
  locale = value.locale
@@ -43,7 +45,8 @@ export function createAutomaticMaintenanceHandler(deps: AutomaticMaintenanceRout
43
45
  if (starting || deps.busy?.() === true) { replyJson(response, 409, { ok: false, error: 'bridge maintenance is already starting' }); return }
44
46
  starting = true
45
47
  try {
46
- const job = await deps.start(action, locale === undefined ? undefined : { locale })
48
+ const options = { ...locale === undefined ? {} : { locale } }
49
+ const job = await deps.start(action, Object.keys(options).length === 0 ? undefined : options)
47
50
  if (deps.commit !== undefined) {
48
51
  let fired = false
49
52
  const commitOnce = (): void => {
@@ -56,9 +59,9 @@ export function createAutomaticMaintenanceHandler(deps: AutomaticMaintenanceRout
56
59
  response.once('finish', commitOnce)
57
60
  response.once('close', commitOnce)
58
61
  }
59
- replyJson(response, 202, { ok: true, accepted: true, protocol: 1, job })
62
+ replyJson(response, 202, { ok: true, accepted: true, protocol: 1, quit: deps.quit?.() ?? 'menu', job })
60
63
  } catch (error) {
61
- replyJson(response, 409, { ok: false, error: String(error) })
64
+ replyJson(response, 409, { ok: false, error: String(error), ...(error instanceof Error && 'code' in error ? { code: error.code } : {}) })
62
65
  } finally { starting = false }
63
66
  }
64
67
  }
@@ -18,8 +18,8 @@
18
18
  * `available()` reports true on purpose. Reporting false would make the provider pick
19
19
  * a different carrier and hide the problem again, which is exactly the bug.
20
20
  */
21
- import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.js'
22
- import type { BrowserChannel } from './system-browser.js'
21
+ import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.ts'
22
+ import type { BrowserChannel } from './system-browser.ts'
23
23
 
24
24
  /**
25
25
  * How each product is named in the message, and what to install.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The last page a tool opened, shared by the provider and the HTTP surface.
3
+ *
4
+ * The provider instance that runs a tool and the one that answers routes are not guaranteed to be the
5
+ * same object (a surface can be built per context), so an instance field read back `null`. A module-level
6
+ * slot is what both sides can see — and it is what lets the Web sidebar place a tool-opened page with one
7
+ * call instead of a manual address-bar dance.
8
+ * @module dsh-builtin-browser/browser-electron/open-slot
9
+ */
10
+
11
+ /**
12
+ * The slot lives on \`globalThis\`: the plugin's lib can be imported by more than one module instance in the
13
+ * same process (tools and the HTTP surface), and module-level state is per instance — which read back as
14
+ * \`null\` even after an open.
15
+ */
16
+ const SLOT = '__dshBuiltinBrowserLastOpen'
17
+
18
+ /**
19
+ * Record an open request.
20
+ * @param url - the page a tool asked to open.
21
+ * @param at - arrival time in epoch milliseconds.
22
+ */
23
+ export function setLastOpen(url: string, at: number, owner?: string): void {
24
+ (globalThis as unknown as Record<string, unknown>)[SLOT] = { url, at, ...owner === undefined ? {} : { owner } }
25
+ }
26
+
27
+ /**
28
+ * Read the most recent open request.
29
+ * @returns the request, or undefined when nothing was opened since start.
30
+ */
31
+ export function getLastOpen(): { readonly url: string; readonly at: number; readonly owner?: string } | undefined {
32
+ return (globalThis as unknown as Record<string, { url: string; at: number; owner?: string } | undefined>)[SLOT]
33
+ }
34
+
35
+ /**
36
+ * 清空 open 记录(客户端摆放完侧栏标签后回执)。
37
+ *
38
+ * 「最后一次 open」如果一直留着,刷新页面或换一个标签页打开 DSH 时就会被重放,把用户已经关掉的
39
+ * 侧栏与网页重新拉起来。拿到回执即清空,这条记录就变成一次性事件。
40
+ * @param at - 只有记录的到达时间与之一致时才清空;省略则无条件清空。
41
+ * @returns 是否真的清掉了。
42
+ */
43
+ export function clearLastOpen(at?: number): boolean {
44
+ const current = getLastOpen()
45
+ if (current === undefined) return false
46
+ if (at !== undefined && current.at !== at) return false
47
+ delete (globalThis as unknown as Record<string, unknown>)[SLOT]
48
+ return true
49
+ }
@@ -12,7 +12,11 @@ import { join } from 'node:path'
12
12
 
13
13
  /** Absolute path of the DSH home directory; DSH_HOME overrides the per-user default. */
14
14
  export function dshHome(): string {
15
- return process.env.DSH_HOME ?? join(homedir(), '.dsh')
15
+ return process.env.DSH_HOME || join(homedir(), '.dsh')
16
+ }
17
+
18
+ export function browserHostLogPath(): string {
19
+ return join(dshHome(), 'logs', 'dsh-builtin-browser-host.log')
16
20
  }
17
21
 
18
22
  /** Absolute path of the endpoint file the running desktop shell publishes. */