dsh-builtin-browser 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.en.md +89 -0
  3. package/browser-extension/constants.mjs +20 -0
  4. package/browser-extension/controller.mjs +293 -0
  5. package/browser-extension/locales.mjs +15 -0
  6. package/browser-extension/manifest.json +12 -0
  7. package/browser-extension/options.html +14 -0
  8. package/browser-extension/options.mjs +9 -0
  9. package/browser-extension/permission-guard.mjs +13 -0
  10. package/browser-extension/worker.mjs +74 -0
  11. package/desktop-bridge/desktop-identity.json +10 -2
  12. package/desktop-bridge/install.mjs +28 -2
  13. package/docs/issue-replies-2026-11-28.md +141 -0
  14. package/dsh-host-patch/apply.mjs +1 -1
  15. package/dsh-host-patch/rc3.json +4 -4
  16. package/dsh-host-patch/rc5.json +4 -4
  17. package/dsh-host-patch/v023-alpha2.json +2 -2
  18. package/lib/browser-electron/bridge-status.js +24 -1
  19. package/lib/browser-electron/desktop-identity.js +47 -8
  20. package/lib/client.js +2 -1
  21. package/native-host/install.mjs +5 -0
  22. package/package.json +20 -2
  23. package/scripts/build-client.mjs +305 -0
  24. package/scripts/build.mjs +69 -0
  25. package/scripts/bundle-host.mjs +28 -0
  26. package/scripts/fix-exports.mjs +40 -0
  27. package/scripts/install-electron.mjs +101 -0
  28. package/scripts/pack.mjs +99 -0
  29. package/scripts/publish-manifest.mjs +56 -0
  30. package/scripts/verify-exports.mjs +58 -0
  31. package/scripts/verify-preview-sdk.mjs +93 -0
  32. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  33. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  34. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  35. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  36. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  37. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  38. package/skills/dsh-debug-host/SKILL.md +56 -0
  39. package/skills/dsh-debug-self/SKILL.md +50 -0
  40. package/src/bridge-compatibility.ts +39 -0
  41. package/src/browser/anti-bot.ts +251 -0
  42. package/src/browser/deep-dom.ts +40 -0
  43. package/src/browser/handles.ts +89 -0
  44. package/src/browser/runtime.ts +578 -0
  45. package/src/browser/takeover-target.ts +45 -0
  46. package/src/browser/types.ts +870 -0
  47. package/src/browser-electron/authenticated-route.ts +109 -0
  48. package/src/browser-electron/automatic-maintenance.ts +736 -0
  49. package/src/browser-electron/bridge-auto.ts +159 -0
  50. package/src/browser-electron/bridge-connection.ts +386 -0
  51. package/src/browser-electron/bridge-endpoint.ts +129 -0
  52. package/src/browser-electron/bridge-install.ts +290 -0
  53. package/src/browser-electron/bridge-maintenance.ts +189 -0
  54. package/src/browser-electron/bridge-status.ts +412 -0
  55. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  56. package/src/browser-electron/desktop-identity.ts +400 -0
  57. package/src/browser-electron/desktop-shell.ts +100 -0
  58. package/src/browser-electron/document-readiness.ts +45 -0
  59. package/src/browser-electron/electron-provision.ts +347 -0
  60. package/src/browser-electron/entry.ts +1378 -0
  61. package/src/browser-electron/ephemeral-profile.ts +189 -0
  62. package/src/browser-electron/extension-browser.ts +230 -0
  63. package/src/browser-electron/extension-setup.ts +67 -0
  64. package/src/browser-electron/file-write.ts +31 -0
  65. package/src/browser-electron/foreground-watch.ts +142 -0
  66. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  67. package/src/browser-electron/guest-cookie-store.ts +59 -0
  68. package/src/browser-electron/guest-css-runtime.ts +76 -0
  69. package/src/browser-electron/guest-css.ts +68 -0
  70. package/src/browser-electron/guest-route.ts +716 -0
  71. package/src/browser-electron/guest-runtime.ts +408 -0
  72. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  73. package/src/browser-electron/guest-storage.ts +120 -0
  74. package/src/browser-electron/history-store.ts +224 -0
  75. package/src/browser-electron/host-main.ts +1385 -0
  76. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  77. package/src/browser-electron/http-body.ts +65 -0
  78. package/src/browser-electron/json-reply.ts +47 -0
  79. package/src/browser-electron/maintenance-broker.ts +166 -0
  80. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  81. package/src/browser-electron/maintenance-route.ts +68 -0
  82. package/src/browser-electron/missing-system-browser.ts +114 -0
  83. package/src/browser-electron/open-slot.ts +49 -0
  84. package/src/browser-electron/paths.ts +25 -0
  85. package/src/browser-electron/preferred-browser.ts +130 -0
  86. package/src/browser-electron/preview-route.ts +215 -0
  87. package/src/browser-electron/process-ownership.ts +174 -0
  88. package/src/browser-electron/process.ts +23 -0
  89. package/src/browser-electron/profile-checkpoint.ts +187 -0
  90. package/src/browser-electron/profile-command.ts +47 -0
  91. package/src/browser-electron/profile-extension.ts +129 -0
  92. package/src/browser-electron/profile-lease.ts +211 -0
  93. package/src/browser-electron/profile-residue.ts +49 -0
  94. package/src/browser-electron/provider-core.ts +1107 -0
  95. package/src/browser-electron/provider-interaction.ts +1034 -0
  96. package/src/browser-electron/provider-media.ts +589 -0
  97. package/src/browser-electron/provider-navigation.ts +323 -0
  98. package/src/browser-electron/provider-observation.ts +664 -0
  99. package/src/browser-electron/provider-tabs.ts +372 -0
  100. package/src/browser-electron/provider.ts +666 -0
  101. package/src/browser-electron/reference-route.ts +598 -0
  102. package/src/browser-electron/remote-host.ts +1538 -0
  103. package/src/browser-electron/rpc-input.ts +13 -0
  104. package/src/browser-electron/rpc-ops.ts +41 -0
  105. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  106. package/src/browser-electron/runtime-route.ts +105 -0
  107. package/src/browser-electron/runtime-status.ts +309 -0
  108. package/src/browser-electron/settings-route.ts +64 -0
  109. package/src/browser-electron/settings-store.ts +593 -0
  110. package/src/browser-electron/shortcuts-route.ts +112 -0
  111. package/src/browser-electron/sidebar-only-host.ts +300 -0
  112. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  113. package/src/browser-electron/system-browser.ts +1850 -0
  114. package/src/browser-electron/tauri-host.ts +194 -0
  115. package/src/browser-electron/timing.ts +16 -0
  116. package/src/browser-electron/virtual-cursor.ts +162 -0
  117. package/src/browser-electron/windows-system.ts +24 -0
  118. package/src/browser-reference/delivery.ts +384 -0
  119. package/src/browser-reference/entry.ts +631 -0
  120. package/src/browser-reference/export.ts +339 -0
  121. package/src/browser-reference/import.ts +303 -0
  122. package/src/browser-reference/page-script.ts +1537 -0
  123. package/src/browser-reference/service.ts +1346 -0
  124. package/src/browser-reference/store.ts +172 -0
  125. package/src/browser-reference/text-quote.ts +219 -0
  126. package/src/browser-reference/types.ts +195 -0
  127. package/src/browser-reference/visible.ts +367 -0
  128. package/src/browser-reference/web-sources.ts +106 -0
  129. package/src/client/apply-guard.ts +22 -0
  130. package/src/client/browser/BrowserController.ts +693 -0
  131. package/src/client/browser/BrowserFrame.ts +78 -0
  132. package/src/client/browser/BrowserNavigation.ts +169 -0
  133. package/src/client/browser/BrowserPage.ts +23 -0
  134. package/src/client/browser/BrowserPersistence.ts +44 -0
  135. package/src/client/browser/IframeImpl.ts +182 -0
  136. package/src/client/browser/child-tabs.ts +14 -0
  137. package/src/client/browser/frame-history.ts +125 -0
  138. package/src/client/browser/frame-state.ts +27 -0
  139. package/src/client/browser/iframe-reference.ts +67 -0
  140. package/src/client/browser/initialization.ts +262 -0
  141. package/src/client/browser/omnibox.ts +243 -0
  142. package/src/client/browser/store.ts +38 -0
  143. package/src/client/browser/takeover-channel.ts +72 -0
  144. package/src/client/browser/url.ts +46 -0
  145. package/src/client/browser/web-reference-source.ts +56 -0
  146. package/src/client/css-modules.d.ts +4 -0
  147. package/src/client/definition.tsx +36 -0
  148. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  149. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  150. package/src/client/electron/NativeChildPresentation.ts +53 -0
  151. package/src/client/electron/NativeViewPage.ts +265 -0
  152. package/src/client/electron/pages.ts +23 -0
  153. package/src/client/electron/reference-overlay.ts +53 -0
  154. package/src/client/electron/workspace.ts +33 -0
  155. package/src/client/index.ts +333 -0
  156. package/src/client/locales.ts +860 -0
  157. package/src/client/pages.ts +28 -0
  158. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  159. package/src/client/reference/client/draft-reference.ts +167 -0
  160. package/src/client/reference/client/index.ts +7 -0
  161. package/src/client/reference/client/ordered-submission.ts +108 -0
  162. package/src/client/reference/client/pending-delivery.ts +216 -0
  163. package/src/client/reference/client/plugin.ts +208 -0
  164. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  165. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  166. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  167. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  168. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  169. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  170. package/src/client/reference/client/production/assembly.ts +447 -0
  171. package/src/client/reference/client/production/asset-store.ts +144 -0
  172. package/src/client/reference/client/production/availability.ts +72 -0
  173. package/src/client/reference/client/production/bytes.ts +36 -0
  174. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  175. package/src/client/reference/client/production/delivery-client.ts +211 -0
  176. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  177. package/src/client/reference/client/production/http-transport.ts +212 -0
  178. package/src/client/reference/client/production/production-submission.ts +70 -0
  179. package/src/client/reference/client/production/protocol.ts +234 -0
  180. package/src/client/reference/client/production/reference-card.ts +240 -0
  181. package/src/client/reference/client/production/reference-labels.ts +29 -0
  182. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  183. package/src/client/reference/client/production/reveal.ts +215 -0
  184. package/src/client/reference/client/production/runtime.ts +1056 -0
  185. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  186. package/src/client/reference/client/production/source-marker.ts +99 -0
  187. package/src/client/reference/client/production/source-opener.ts +55 -0
  188. package/src/client/reference/client/production/styles.ts +104 -0
  189. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  190. package/src/client/reference/client/reveal.ts +109 -0
  191. package/src/client/reference/client/scheme.ts +114 -0
  192. package/src/client/reference/client/session-schedule.ts +36 -0
  193. package/src/client/reference/client/types.ts +168 -0
  194. package/src/client/reference/css-modules.d.ts +4 -0
  195. package/src/client/reference/index.ts +11 -0
  196. package/src/client/reference-capture-owner.ts +162 -0
  197. package/src/client/reference-intents.ts +36 -0
  198. package/src/client/settings/index.ts +42 -0
  199. package/src/client/settings/mount-guard.ts +31 -0
  200. package/src/client/settings/panel.ts +2773 -0
  201. package/src/client/shortcut-open.ts +30 -0
  202. package/src/client/startpage/binding.ts +99 -0
  203. package/src/client/startpage/controller.ts +300 -0
  204. package/src/client/startpage/model.ts +279 -0
  205. package/src/client/view/Browser.module.css +751 -0
  206. package/src/client/view/BrowserBody.tsx +315 -0
  207. package/src/client/view/BrowserPresentation.ts +9 -0
  208. package/src/client/view/BrowserTitle.tsx +17 -0
  209. package/src/client/view/IframePresentation.ts +365 -0
  210. package/src/client/view/StartPage.tsx +598 -0
  211. package/src/client/view/TakeoverBanner.tsx +21 -0
  212. package/src/compat/host-features.ts +92 -0
  213. package/src/index.ts +110 -0
  214. package/src/reference-owner.ts +5 -0
  215. package/src/reference-page.ts +9 -0
  216. package/src/reference-source.ts +3 -0
  217. package/src/reference-text.ts +219 -0
  218. package/src/startpage-settings.ts +103 -0
  219. package/src/startpage.ts +71 -0
  220. package/src/takeover-protocol.ts +28 -0
  221. package/src/tool-browser/block-recovery.ts +85 -0
  222. package/src/tool-browser/code-tool.ts +555 -0
  223. package/src/tool-browser/code-worker.ts +725 -0
  224. package/src/tool-browser/element-fields.ts +167 -0
  225. package/src/tool-browser/errors.ts +40 -0
  226. package/src/tool-browser/index.ts +265 -0
  227. package/src/tool-browser/page-probe.ts +675 -0
  228. package/src/tool-browser/panel-page.ts +126 -0
  229. package/src/tool-browser/probe-client.ts +183 -0
  230. package/src/tool-browser/screenshot-annotations.ts +131 -0
  231. package/src/tool-browser/screenshot-image.ts +49 -0
  232. package/src/tool-browser/state.ts +375 -0
  233. package/src/tool-browser/takeover.ts +199 -0
  234. package/src/tool-browser/tools-debug.ts +806 -0
  235. package/src/tool-browser/tools-interaction.ts +956 -0
  236. package/src/tool-browser/tools-navigation.ts +786 -0
  237. package/src/tool-browser/tools-observation.ts +474 -0
  238. package/src/tool-browser/tools-reference.ts +294 -0
  239. package/src/types/electron-shim.d.ts +144 -0
  240. package/src/types.ts +85 -0
  241. package/src/web-guest.ts +35 -0
  242. package/tools/accept-desktop.mjs +148 -0
  243. package/dist/client.d.cts +0 -516
  244. package/dist/client.d.mts +0 -516
  245. package/dist/index.cjs +0 -92
  246. package/dist/index.d.mts +0 -2960
  247. package/dist/index.mjs +0 -24
  248. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  249. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  250. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  256. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  257. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  258. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  259. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  260. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  261. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  262. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  263. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  264. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  265. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  266. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  267. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  268. package/dsh-host-patch/sources/manifest.json +0 -218
  269. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  293. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  294. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  295. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  296. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  297. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  298. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  299. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  300. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  301. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  302. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  303. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  304. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  305. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,400 @@
1
+ /**
2
+ * What proves a directory is a DSH Desktop install.
3
+ *
4
+ * Reported as issue #40. Every reader of an install directory used to accept a *generic* Electron
5
+ * layout (`resources/app/lib/main.js` or `resources/app.asar`) as proof, and that is not proof of
6
+ * anything: any Electron app has it. The consequence was measured — a throwaway app in a temp
7
+ * directory, whose own package.json said `unrelated-meeting-app`, was accepted by discovery, got a
8
+ * "bridge not installed" verdict with a ready-to-run installer command aimed at it, and (with that
9
+ * command) had its entry file rewritten and the bridge copied in.
10
+ *
11
+ * So identity is one rule, in one file (`desktop-bridge/desktop-identity.json`), read by both the
12
+ * installer and this module. Nothing else may decide what a DSH Desktop install is.
13
+ *
14
+ * Two properties are load-bearing and are why this is not a one-line `name ===` check:
15
+ *
16
+ * - **The archive wins.** Electron loads `resources/app.asar` in preference to `resources/app`, and
17
+ * a desktop update leaves the old extraction lying around. Reading identity from the extraction
18
+ * while the archive holds a different build would verify the wrong bytes, so when the archive is
19
+ * present that is what is read — and the sibling directory is not consulted at all.
20
+ * - **Unreadable means not DSH.** Every failure path (missing file, truncated pickle, unsupported
21
+ * archive version, malformed JSON, unreadable name) refuses. There is no "assume yes" branch: the
22
+ * caller is about to write into, or delete from, this directory.
23
+ * @module dsh-browser/browser-electron/desktop-identity
24
+ */
25
+ import { closeSync, existsSync, openSync, readFileSync, readSync } from 'node:fs'
26
+ import { createRequire } from 'node:module'
27
+ import { join } from 'node:path'
28
+
29
+ // Electron's patched fs opens an ASAR as a virtual directory. Identity needs the raw archive
30
+ // header and file offsets, including when this reader runs in the Desktop's Node-mode worker.
31
+ const archiveFs: Pick<typeof import('node:fs'), 'openSync' | 'readSync' | 'closeSync' | 'existsSync'> = (() => {
32
+ try { return createRequire(import.meta.url)('original-fs') as typeof import('node:fs') }
33
+ catch { return { openSync, readSync, closeSync, existsSync } }
34
+ })()
35
+
36
+ /** The identity rule, as data. */
37
+ /** Where one kind of install keeps its resources, executable and CLI launcher (all relative). */
38
+ export interface DesktopLayout {
39
+ readonly name: string
40
+ /** The layout applies when this path exists under the install root; the default has none. */
41
+ readonly marker?: string
42
+ readonly resources: string
43
+ readonly executable: string
44
+ readonly cliLauncher: string
45
+ }
46
+
47
+ interface IdentityRule {
48
+ readonly packageNames: readonly string[]
49
+ readonly mainEntry: string
50
+ /** Further accepted entries; each states the dependency that must be present to qualify. */
51
+ readonly mainEntryCandidates?: readonly {
52
+ readonly entry: string
53
+ readonly packageName?: string
54
+ /** Dependency that must appear in the app's own manifest for this entry to be accepted. */
55
+ readonly requiresDependency?: string
56
+ readonly note?: string
57
+ }[]
58
+ /** Main entries of look-alike Desktops that are recognized only to be refused, with the reason. */
59
+ readonly unsupportedMainEntries?: Readonly<Record<string, string>>
60
+ readonly layouts: readonly DesktopLayout[]
61
+ }
62
+
63
+ /**
64
+ * The rule shipped in `desktop-bridge/desktop-identity.json`, used when the file cannot be read.
65
+ *
66
+ * A copy exists here only as a fallback for a broken package layout; the test suite asserts that it
67
+ * equals the JSON, so the two can never drift apart silently.
68
+ */
69
+ export const FALLBACK_RULE: IdentityRule = {
70
+ packageNames: ['@deepseek-ai/dsh-desktop', 'dsh-desktop'],
71
+ mainEntry: 'lib/main.js',
72
+ mainEntryCandidates: [
73
+ {
74
+ entry: 'out/main/index.js',
75
+ packageName: 'dsh-desktop',
76
+ requiresDependency: '@deepseek-ai/dsh',
77
+ note: 'electron-vite layout. The official DSH Desktop 0.14.0 ships this entry with `main: ./out/main/index.js` and no `lib` directory at all (issue #112), while the third-party electron-vite shell (dataelement/dsh-desktop, issue #62) shares the same shape. The `@deepseek-ai/dsh` dependency is what separates them: the official bundle carries it, the third-party shell does not.',
78
+ },
79
+ ],
80
+ unsupportedMainEntries: {
81
+ 'out/main/index.js': 'an electron-vite DSH Desktop without the @deepseek-ai/dsh dependency — the third-party shell from issue #62, which shares the package name but not the DeepSeek Harness Desktop bundle the bridge patches',
82
+ },
83
+ layouts: [
84
+ { name: 'macos-bundle', marker: 'Contents/Info.plist', resources: 'Contents/Resources', executable: 'Contents/MacOS/DeepSeek Harness', cliLauncher: 'runtime/cli/bin/dsh' },
85
+ { name: 'directory', resources: 'resources', executable: 'DeepSeek Harness.exe', cliLauncher: 'runtime/cli/bin/dsh.cmd' },
86
+ ],
87
+ }
88
+
89
+ /** A verified install. */
90
+ export interface DesktopIdentity {
91
+ readonly ok: true
92
+ /** The entry this install actually uses: `mainEntry`, or an accepted candidate. */
93
+ readonly mainEntry: string
94
+ /** The install root that was verified. */
95
+ readonly root: string
96
+ /** Which shape was verified — the archive when it exists, the extraction only without one. */
97
+ readonly layout: 'packed' | 'unpacked'
98
+ /** `name` from the package the caller will actually run. */
99
+ readonly packageName: string
100
+ /** `version`, when the package declares one. */
101
+ readonly version?: string
102
+ }
103
+
104
+ /** A refusal, with a reason a human can act on. */
105
+ export interface IdentityRefusal {
106
+ readonly ok: false
107
+ readonly reason: string
108
+ /**
109
+ * Set once the manifest has named a DSH Desktop package: `third-party-shell` for a layout the rule
110
+ * attributes to another shell, `official-unsupported` for an official package without the patched entry.
111
+ */
112
+ readonly shell?: 'third-party-shell' | 'official-unsupported'
113
+ /** The manifest version, when the refusal came after reading it. */
114
+ readonly version?: string
115
+ }
116
+
117
+ function versionOf(manifest: { version?: unknown }): { version?: string } {
118
+ return typeof manifest.version === 'string' ? { version: manifest.version } : {}
119
+ }
120
+
121
+ /**
122
+ * Read the identity rule.
123
+ *
124
+ * Resolved relative to this module, which in both the repository and the published tarball puts
125
+ * `desktop-bridge/` beside `lib/`. A missing file is not fatal — the fallback is the same rule —
126
+ * but a *malformed* one is an error the caller should not ignore, so it is reported through the
127
+ * refusal path rather than silently swapped for the fallback.
128
+ * @returns the rule, or an error string.
129
+ */
130
+ export function readIdentityRule(): IdentityRule | { readonly error: string } {
131
+ try {
132
+ const path = new URL('../../desktop-bridge/desktop-identity.json', import.meta.url)
133
+ const raw = JSON.parse(readFileSync(path, 'utf8')) as Partial<IdentityRule>
134
+ const names = raw.packageNames
135
+ const main = raw.mainEntry
136
+ if (!Array.isArray(names) || names.length === 0 || names.some(n => typeof n !== 'string')) {
137
+ return { error: 'desktop-identity.json: packageNames must be a non-empty array of strings' }
138
+ }
139
+ if (typeof main !== 'string' || main === '') {
140
+ return { error: 'desktop-identity.json: mainEntry must be a non-empty string' }
141
+ }
142
+ const layouts = raw.layouts
143
+ const field = (value: unknown): boolean => typeof value === 'string' && value !== ''
144
+ if (!Array.isArray(layouts) || layouts.length === 0
145
+ || layouts.some(l => l === null || typeof l !== 'object' || !field(l.name) || !field(l.resources) || !field(l.executable) || !field(l.cliLauncher)
146
+ || (l.marker !== undefined && !field(l.marker)))
147
+ || layouts[layouts.length - 1]?.marker !== undefined) {
148
+ return { error: 'desktop-identity.json: layouts must be a non-empty array whose last entry has no marker' }
149
+ }
150
+ const candidates = raw.mainEntryCandidates
151
+ if (candidates !== undefined && (!Array.isArray(candidates) || candidates.some(c => c === null || typeof c !== 'object'
152
+ || !field(c.entry) || (c.requiresDependency !== undefined && !field(c.requiresDependency))))) {
153
+ return { error: 'desktop-identity.json: mainEntryCandidates must list entries with an optional requiresDependency' }
154
+ }
155
+ const unsupported = raw.unsupportedMainEntries
156
+ if (unsupported !== undefined && (unsupported === null || typeof unsupported !== 'object' || Array.isArray(unsupported)
157
+ || Object.entries(unsupported).some(([entry, reason]) => entry === '' || !field(reason)))) {
158
+ return { error: 'desktop-identity.json: unsupportedMainEntries must map entry paths to reasons' }
159
+ }
160
+ // The candidates are part of the rule; dropping them here is what made a valid candidate entry
161
+ // indistinguishable from an unsupported one.
162
+ const base = candidates === undefined
163
+ ? { packageNames: names, mainEntry: main }
164
+ : { packageNames: names, mainEntry: main, mainEntryCandidates: candidates }
165
+ return unsupported === undefined
166
+ ? { ...base, layouts }
167
+ : { ...base, unsupportedMainEntries: unsupported, layouts }
168
+ } catch (error) {
169
+ if (error instanceof Error && 'code' in error && (error as NodeJS.ErrnoException).code === 'ENOENT') {
170
+ return FALLBACK_RULE
171
+ }
172
+ return { error: `desktop-identity.json could not be read: ${String(error)}` }
173
+ }
174
+ }
175
+
176
+ function layoutOf(rule: IdentityRule, installRoot: string): DesktopLayout {
177
+ return rule.layouts.find(layout => layout.marker === undefined || existsSync(join(installRoot, ...layout.marker.split('/'))))
178
+ ?? rule.layouts[rule.layouts.length - 1] as DesktopLayout
179
+ }
180
+
181
+ /**
182
+ * The layout of an install root: a macOS `.app` bundle or a plain directory (Windows).
183
+ * Decided by the install's own shape rather than the host OS, so every platform reads it the same.
184
+ * @param installRoot - the install directory.
185
+ * @returns the layout, or an error when the identity rule cannot be read.
186
+ */
187
+ export function desktopLayout(installRoot: string): DesktopLayout | { readonly error: string } {
188
+ const rule = readIdentityRule()
189
+ return 'error' in rule ? rule : layoutOf(rule, installRoot)
190
+ }
191
+
192
+ /**
193
+ * Absolute paths an install keeps, from its layout.
194
+ * @param installRoot - the install directory.
195
+ * @returns resources directory, GUI executable and CLI launcher.
196
+ */
197
+ export function desktopPaths(installRoot: string): { readonly resources: string; readonly executable: string; readonly cliLauncher: string } {
198
+ const layout = desktopLayout(installRoot)
199
+ if ('error' in layout) throw new Error(layout.error)
200
+ const resources = join(installRoot, ...layout.resources.split('/'))
201
+ return { resources, executable: join(installRoot, ...layout.executable.split('/')), cliLauncher: join(resources, ...layout.cliLauncher.split('/')) }
202
+ }
203
+
204
+ /**
205
+ * One entry of a Chromium pickle header.
206
+ *
207
+ * `offset` is relative to the content area that follows the header; `unpacked` entries carry no
208
+ * bytes in the archive and live beside it instead.
209
+ */
210
+ interface AsarEntry {
211
+ readonly size: number
212
+ readonly offset?: string
213
+ readonly unpacked?: boolean
214
+ readonly files?: Record<string, AsarEntry>
215
+ }
216
+
217
+ /**
218
+ * Parse an asar header, the same way the installer does.
219
+ *
220
+ * Layout, for the next reader: an 8-byte outer pickle (`[size][jsonLength]`), then the header
221
+ * pickle whose first 4 bytes are the JSON length, then the JSON tree. File content starts right
222
+ * after the header pickle.
223
+ * @param archive - the archive path.
224
+ * @returns the header tree and the offset where content starts, or an error string.
225
+ */
226
+ function readAsarHeader(archive: string): { header: { files?: Record<string, AsarEntry> }; contentBase: number } | { error: string } {
227
+ let fd: number | undefined
228
+ try {
229
+ fd = archiveFs.openSync(archive, 'r')
230
+ const outer = Buffer.alloc(8)
231
+ if (archiveFs.readSync(fd, outer, 0, 8, 0) !== 8) return { error: 'the archive header is truncated' }
232
+ const headerSize = outer.readUInt32LE(4)
233
+ if (headerSize < 8 || headerSize > 64 * 1024 * 1024) return { error: `implausible archive header size (${headerSize})` }
234
+ const header = Buffer.alloc(headerSize)
235
+ if (archiveFs.readSync(fd, header, 0, headerSize, 8) !== headerSize) return { error: 'the archive header is truncated' }
236
+ const jsonLength = header.readUInt32LE(4)
237
+ if (jsonLength <= 0 || jsonLength > headerSize - 8) return { error: 'the archive header has an implausible JSON length' }
238
+ return { header: JSON.parse(header.toString('utf8', 8, 8 + jsonLength)), contentBase: 8 + headerSize }
239
+ } catch (error) {
240
+ return { error: `the archive header could not be read: ${String(error)}` }
241
+ } finally {
242
+ if (fd !== undefined) {
243
+ try { archiveFs.closeSync(fd) } catch { /* already closed */ }
244
+ }
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Walk a slash-separated path inside an asar header tree.
250
+ * @param tree - the header's `files` node.
251
+ * @param path - e.g. `lib/main.js`.
252
+ * @returns the entry, or undefined when the path does not exist.
253
+ */
254
+ function entryAt(tree: Record<string, AsarEntry> | undefined, path: string): AsarEntry | undefined {
255
+ let node: AsarEntry | undefined
256
+ let files: Record<string, AsarEntry> | undefined = tree
257
+ for (const part of path.split('/')) {
258
+ if (files === undefined) return undefined
259
+ node = files[part]
260
+ if (node === undefined) return undefined
261
+ files = node.files
262
+ }
263
+ return node
264
+ }
265
+
266
+ /**
267
+ * Read one file out of an asar archive without extracting the tree.
268
+ * @param archive - the archive path.
269
+ * @param path - a slash-separated path inside the archive.
270
+ * @returns the bytes, or undefined when the entry is absent or unreadable.
271
+ */
272
+ export function readAsarFile(archive: string, path: string): Buffer | undefined {
273
+ const parsed = readAsarHeader(archive)
274
+ if ('error' in parsed) return undefined
275
+ const entry = entryAt(parsed.header.files, path)
276
+ if (entry === undefined || entry.files !== undefined || entry.unpacked === true) return undefined
277
+ if (typeof entry.offset !== 'string' || typeof entry.size !== 'number' || entry.size < 0) return undefined
278
+ let fd: number | undefined
279
+ try {
280
+ fd = archiveFs.openSync(archive, 'r')
281
+ const buffer = Buffer.alloc(entry.size)
282
+ const read = archiveFs.readSync(fd, buffer, 0, entry.size, parsed.contentBase + Number(entry.offset))
283
+ return read === entry.size ? buffer : undefined
284
+ } catch {
285
+ return undefined
286
+ } finally {
287
+ if (fd !== undefined) {
288
+ try { archiveFs.closeSync(fd) } catch { /* already closed */ }
289
+ }
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Whether an install directory is DSH Desktop.
295
+ *
296
+ * Everything the caller does next (stop the app, delete a tree, extract, rename, write) depends on
297
+ * this being right, so every uncertainty resolves to a refusal that names what was found.
298
+ * @param installRoot - the directory a user or the discovery probe named.
299
+ * @returns the verified identity, or a refusal with a reason.
300
+ */
301
+ export function readDesktopIdentity(installRoot: string): DesktopIdentity | IdentityRefusal {
302
+ const rule = readIdentityRule()
303
+ if ('error' in rule) return { ok: false, reason: rule.error }
304
+ const resources = join(installRoot, ...layoutOf(rule, installRoot).resources.split('/'))
305
+ const appDir = join(resources, 'app')
306
+ const archive = join(resources, 'app.asar')
307
+
308
+ let archivePresent: boolean
309
+ try {
310
+ archivePresent = archiveFs.existsSync(archive)
311
+ } catch {
312
+ return { ok: false, reason: `cannot inspect ${archive}` }
313
+ }
314
+
315
+ const layout: 'packed' | 'unpacked' = archivePresent ? 'packed' : 'unpacked'
316
+ let manifestText: string | undefined
317
+ let hasEntry: (entry: string) => boolean
318
+ if (archivePresent) {
319
+ const parsed = readAsarHeader(archive)
320
+ if ('error' in parsed) {
321
+ return { ok: false, reason: `${archive} could not be read: ${parsed.error}` }
322
+ }
323
+ const manifest = entryAt(parsed.header.files, 'package.json')
324
+ if (manifest === undefined || manifest.files !== undefined || manifest.unpacked === true) {
325
+ return { ok: false, reason: `${archive} has no plain package.json; an archive without one is not proof of identity` }
326
+ }
327
+ manifestText = readAsarFile(archive, 'package.json')?.toString('utf8')
328
+ if (manifestText === undefined) {
329
+ return { ok: false, reason: `${archive}: package.json is listed but its bytes cannot be read` }
330
+ }
331
+ hasEntry = entry => entryAt(parsed.header.files, entry) !== undefined
332
+ } else {
333
+ const manifestPath = join(appDir, 'package.json')
334
+ try {
335
+ manifestText = readFileSync(manifestPath, 'utf8')
336
+ } catch (error) {
337
+ // Candidate probe directories routinely do not contain resources/app/package.json (issue #106).
338
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
339
+ console.error(`[dsh-browser] cannot read the package manifest at ${manifestPath}: ${String(error)}`)
340
+ }
341
+ return { ok: false, reason: `${manifestPath} is missing; a directory without a package manifest is not a DSH Desktop install` }
342
+ }
343
+ hasEntry = entry => existsSync(join(appDir, ...entry.split('/')))
344
+ }
345
+
346
+ let manifest: { name?: unknown; version?: unknown }
347
+ try {
348
+ manifest = JSON.parse(manifestText) as { name?: unknown; version?: unknown }
349
+ } catch {
350
+ return { ok: false, reason: 'the package manifest is not valid JSON' }
351
+ }
352
+ const name = typeof manifest.name === 'string' ? manifest.name : ''
353
+ if (!rule.packageNames.includes(name)) {
354
+ return {
355
+ ok: false,
356
+ reason: `the app calls itself ${name === '' ? '(no name)' : JSON.stringify(name)}, which is not one of `
357
+ + `${rule.packageNames.join(' / ')} — refusing to touch a different application`,
358
+ }
359
+ }
360
+
361
+ // The main entry is the file the installer patches and the shell runs. The default name comes
362
+ // first; the candidates cover layouts that later official builds adopted (0.14.0 ships
363
+ // "out/main/index.js" and no "lib" at all), and each candidate is gated on a dependency that the
364
+ // official bundle carries and the look-alike third-party shell does not.
365
+ let mainEntry: string = rule.mainEntry
366
+ let mainPresent = hasEntry(mainEntry)
367
+ if (!mainPresent) {
368
+ const dependencies = (manifest as { dependencies?: Record<string, unknown> }).dependencies
369
+ for (const candidate of rule.mainEntryCandidates ?? []) {
370
+ if (!hasEntry(candidate.entry)) continue
371
+ if (candidate.requiresDependency !== undefined && dependencies?.[candidate.requiresDependency] === undefined) continue
372
+ mainEntry = candidate.entry
373
+ mainPresent = true
374
+ break
375
+ }
376
+ }
377
+ if (!mainPresent) {
378
+ const foreign = Object.entries(rule.unsupportedMainEntries ?? {}).find(([entry]) => hasEntry(entry))
379
+ if (foreign !== undefined) {
380
+ return { ok: false, shell: 'third-party-shell', ...versionOf(manifest), reason: `${foreign[0]} instead of ${rule.mainEntry}: ${foreign[1]}; use DSH Web or DeepSeek Harness Desktop` }
381
+ }
382
+ // A candidate entry is present but its gate was not satisfied: the package name was borrowed by a
383
+ // look-alike shell. Naming that is more useful than reporting the missing default entry.
384
+ const lookAlike = (rule.mainEntryCandidates ?? []).find(candidate => hasEntry(candidate.entry))
385
+ if (lookAlike !== undefined) {
386
+ const gate = lookAlike.requiresDependency === undefined ? 'its identity gate' : `${lookAlike.requiresDependency}`
387
+ return { ok: false, shell: 'third-party-shell', ...versionOf(manifest), reason: `${lookAlike.entry} instead of ${rule.mainEntry}, but ${gate} is absent, so this is not the DSH Desktop bundle (issue #62); use DSH Web or DeepSeek Harness Desktop` }
388
+ }
389
+ return { ok: false, shell: 'official-unsupported', ...versionOf(manifest), reason: `${rule.mainEntry} is not present under ${archivePresent ? archive : appDir}` }
390
+ }
391
+
392
+ return {
393
+ ok: true,
394
+ root: installRoot,
395
+ layout,
396
+ mainEntry,
397
+ packageName: name,
398
+ ...typeof manifest.version === 'string' ? { version: manifest.version } : {},
399
+ }
400
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * What kind of desktop shell an install is, and what the user should do with it.
3
+ *
4
+ * The bridge patches exactly one shell: DeepSeek Harness Desktop with its `lib/main.js` entry. A
5
+ * community shell that reuses the `dsh-desktop` package name (dataelement/dsh-desktop, issue #62)
6
+ * is recognised as such and never patched; the report tells the settings page to hide bridge
7
+ * install / repair and to point at the system browser first.
8
+ * @module dsh-browser/browser-electron/desktop-shell
9
+ */
10
+ import type { DesktopIdentity, IdentityRefusal } from './desktop-identity.ts'
11
+ import type { TauriHostPatch, TauriRuntime } from './tauri-host.ts'
12
+
13
+ export type DesktopShellKind = 'official-supported' | 'tauri' | 'official-unsupported' | 'third-party-shell' | 'none'
14
+ export type RecommendedCarrier = 'sidebar' | 'chrome' | 'edge'
15
+
16
+ /** One desktop shell, classified. `official-supported` takes the bridge; `tauri` takes only its sidebar host patch. */
17
+ export interface DesktopShellReport {
18
+ readonly kind: DesktopShellKind
19
+ readonly patchable: boolean
20
+ readonly reason: string
21
+ readonly recommendedCarrier: RecommendedCarrier
22
+ readonly root?: string
23
+ readonly version?: string
24
+ /** DSH Tauri only: its electron-rs runtime directory, whether it hosts this process, and its host patch. */
25
+ readonly runtime?: string
26
+ readonly running?: boolean
27
+ readonly hostPatch?: TauriHostPatch
28
+ }
29
+
30
+ interface CarrierHints {
31
+ /** The stored `browser.channel`; a system browser the user already chose is the one to recommend. */
32
+ readonly preferredBrowser?: string
33
+ readonly platform?: NodeJS.Platform
34
+ }
35
+
36
+ /**
37
+ * The system browser to recommend when the sidebar cannot carry the browser.
38
+ * @param hints - the user's current channel and platform.
39
+ * @returns `chrome` or `edge`.
40
+ */
41
+ export function systemCarrier(hints: CarrierHints = {}): 'chrome' | 'edge' {
42
+ if (hints.preferredBrowser === 'chrome' || hints.preferredBrowser === 'edge') return hints.preferredBrowser
43
+ return (hints.platform ?? process.platform) === 'win32' ? 'edge' : 'chrome'
44
+ }
45
+
46
+ /**
47
+ * Classify one candidate install from its identity reading.
48
+ * @param root - the install directory.
49
+ * @param identity - `readDesktopIdentity(root)`.
50
+ * @param hints - used for the recommended carrier of an unpatchable shell.
51
+ * @returns the report; `none` when the directory is not a DSH-named shell at all.
52
+ */
53
+ export function classifyDesktopShell(root: string, identity: DesktopIdentity | IdentityRefusal, hints: CarrierHints = {}): DesktopShellReport {
54
+ if (identity.ok) {
55
+ return { kind: 'official-supported', patchable: true, reason: `DeepSeek Harness Desktop ${identity.version} at ${root}`, recommendedCarrier: 'sidebar', root, version: identity.version }
56
+ }
57
+ if (identity.shell === undefined) return { ...noDesktopShell(hints), reason: identity.reason }
58
+ return {
59
+ kind: identity.shell,
60
+ patchable: false,
61
+ reason: identity.reason,
62
+ recommendedCarrier: systemCarrier(hints),
63
+ root,
64
+ ...identity.version === undefined ? {} : { version: identity.version },
65
+ }
66
+ }
67
+
68
+ /**
69
+ * The report when no DSH desktop shell was found.
70
+ * @param hints - used for the recommended carrier.
71
+ * @returns a `none` report.
72
+ */
73
+ export function noDesktopShell(hints: CarrierHints = {}): DesktopShellReport {
74
+ return {
75
+ kind: 'none',
76
+ patchable: false,
77
+ reason: 'no DSH Desktop install found in the usual roots, at DSH_DESKTOP_PATH or DSH_DESKTOP_APP, in the uninstall registry, or at this platform\'s conventional locations',
78
+ recommendedCarrier: systemCarrier(hints),
79
+ }
80
+ }
81
+
82
+ /**
83
+ * The report for DSH Tauri. Its sidebar is driven through its own `dshDesktop.browser`; what the
84
+ * plugin patches is only the sidebar partition (`dsh-host-patch/tauri.json`), never the bridge.
85
+ * @param runtime - the Tauri runtime.
86
+ * @param hostPatch - the runtime's host patch state.
87
+ * @returns a `tauri` report, patchable when the patch can be applied or is applied.
88
+ */
89
+ export function tauriShell(runtime: TauriRuntime, hostPatch: TauriHostPatch): DesktopShellReport {
90
+ return {
91
+ kind: 'tauri',
92
+ patchable: hostPatch.status === 'absent' || hostPatch.status === 'applied',
93
+ reason: `DSH Tauri at ${runtime.root ?? runtime.runtime}; sidebar host patch ${hostPatch.status}${hostPatch.reason === undefined ? '' : `: ${hostPatch.reason}`}`,
94
+ recommendedCarrier: 'sidebar',
95
+ ...runtime.root === undefined ? {} : { root: runtime.root },
96
+ runtime: runtime.runtime,
97
+ running: runtime.running,
98
+ hostPatch,
99
+ }
100
+ }
@@ -0,0 +1,45 @@
1
+ import { BrowserError } from '../browser/types.ts'
2
+ import type { ElectronViewHandle } from './provider.ts'
3
+
4
+ export interface DocumentIdentity {
5
+ readonly id: string
6
+ readonly loaderId: string
7
+ readonly url: string
8
+ readonly unreachableUrl?: string
9
+ }
10
+
11
+ export function mainDocument(value: unknown, options?: { readonly allowErrorDocument?: boolean }): DocumentIdentity {
12
+ const frame = (value as { frameTree?: { frame?: DocumentIdentity } } | undefined)?.frameTree?.frame
13
+ if (typeof frame?.id !== 'string' || frame.id === ''
14
+ || typeof frame.loaderId !== 'string' || frame.loaderId === '' || typeof frame.url !== 'string') {
15
+ throw new BrowserError('browser: the guest did not acknowledge its main document identity', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
16
+ }
17
+ if (frame.unreachableUrl && options?.allowErrorDocument !== true) {
18
+ throw new BrowserError(`browser: failed to load ${frame.unreachableUrl}`, 'BROWSER_NAVIGATION_FAILED')
19
+ }
20
+ return frame
21
+ }
22
+
23
+ /** Check parse readiness in an isolated world bound to the acknowledged main frame. */
24
+ export async function documentReady(handle: ElectronViewHandle, expected: DocumentIdentity, checkCurrent = (): void => {}): Promise<boolean> {
25
+ checkCurrent()
26
+ const world = await handle.sendCommand('Page.createIsolatedWorld', { frameId: expected.id, worldName: 'dsh-browser-readiness' }, { present: false, initialize: false }) as { executionContextId?: number }
27
+ checkCurrent()
28
+ if (!Number.isSafeInteger(world?.executionContextId) || world.executionContextId! <= 0) {
29
+ throw new BrowserError('browser: the guest did not acknowledge a document execution context', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
30
+ }
31
+ const result = await handle.sendCommand('Runtime.evaluate', {
32
+ expression: 'document.readyState', contextId: world.executionContextId, returnByValue: true,
33
+ }, { present: false, initialize: false }) as { result?: { value?: unknown }; exceptionDetails?: unknown }
34
+ checkCurrent()
35
+ const after = mainDocument(await handle.sendCommand('Page.getFrameTree', undefined, { present: false, initialize: false }),
36
+ { allowErrorDocument: !!expected.unreachableUrl })
37
+ checkCurrent()
38
+ if (after.id !== expected.id || after.loaderId !== expected.loaderId) {
39
+ throw new BrowserError('browser: the acknowledged document was superseded', 'BROWSER_NAVIGATION_SUPERSEDED')
40
+ }
41
+ if (result.exceptionDetails !== undefined || !['loading', 'interactive', 'complete'].includes(String(result.result?.value))) {
42
+ throw new BrowserError('browser: the document did not acknowledge its parse state', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
43
+ }
44
+ return result.result?.value !== 'loading'
45
+ }