dsh-builtin-browser 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  22. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  23. package/dsh-host-patch/README.md +4 -0
  24. package/dsh-host-patch/apply.mjs +61 -13
  25. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  26. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  27. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  28. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  29. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  45. package/dsh-host-patch/sources/manifest.json +218 -0
  46. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  47. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  48. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  82. package/dsh-host-patch/sources/series.json +260 -0
  83. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  84. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  85. package/dsh-host-patch/tauri-revision1.json +39 -0
  86. package/dsh-host-patch/tauri.json +43 -0
  87. package/dsh-host-patch/v023-alpha2.json +153 -0
  88. package/lib/browser/anti-bot.js +215 -0
  89. package/lib/browser/deep-dom.js +39 -0
  90. package/lib/browser/runtime.js +15 -0
  91. package/lib/browser/takeover-target.js +13 -6
  92. package/lib/browser/types.js +30 -1
  93. package/lib/browser-electron/authenticated-route.js +16 -2
  94. package/lib/browser-electron/automatic-maintenance.js +16 -10
  95. package/lib/browser-electron/bridge-connection.js +3 -8
  96. package/lib/browser-electron/bridge-install.js +2 -1
  97. package/lib/browser-electron/bridge-status.js +55 -26
  98. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  99. package/lib/browser-electron/desktop-identity.js +28 -5
  100. package/lib/browser-electron/desktop-shell.js +64 -0
  101. package/lib/browser-electron/electron-provision.js +105 -18
  102. package/lib/browser-electron/entry.js +129 -44
  103. package/lib/browser-electron/extension-browser.js +4 -4
  104. package/lib/browser-electron/foreground-watch.js +134 -0
  105. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  106. package/lib/browser-electron/guest-route.js +181 -32
  107. package/lib/browser-electron/guest-runtime.js +61 -10
  108. package/lib/browser-electron/guest-storage.js +2 -2
  109. package/lib/browser-electron/history-store.js +1 -5
  110. package/lib/browser-electron/host-main.js +8 -4
  111. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  112. package/lib/browser-electron/maintenance-route.js +2 -1
  113. package/lib/browser-electron/missing-system-browser.js +5 -9
  114. package/lib/browser-electron/preferred-browser.js +7 -3
  115. package/lib/browser-electron/preview-route.js +9 -13
  116. package/lib/browser-electron/process-ownership.js +1 -1
  117. package/lib/browser-electron/profile-command.js +2 -1
  118. package/lib/browser-electron/profile-extension.js +5 -0
  119. package/lib/browser-electron/profile-lease.js +152 -47
  120. package/lib/browser-electron/provider-core.js +527 -0
  121. package/lib/browser-electron/provider-interaction.js +963 -0
  122. package/lib/browser-electron/provider-media.js +518 -0
  123. package/lib/browser-electron/provider-navigation.js +301 -0
  124. package/lib/browser-electron/provider-observation.js +623 -0
  125. package/lib/browser-electron/provider-tabs.js +372 -0
  126. package/lib/browser-electron/provider.js +150 -3301
  127. package/lib/browser-electron/reference-route.js +9 -18
  128. package/lib/browser-electron/remote-host.js +79 -34
  129. package/lib/browser-electron/runtime-status.js +56 -6
  130. package/lib/browser-electron/settings-store.js +3 -6
  131. package/lib/browser-electron/sidebar-only-host.js +1 -1
  132. package/lib/browser-electron/system-browser.js +539 -172
  133. package/lib/browser-electron/tauri-host.js +208 -0
  134. package/lib/browser-electron/virtual-cursor.js +23 -13
  135. package/lib/browser-reference/service.js +22 -4
  136. package/lib/browser-reference/web-sources.js +1 -1
  137. package/lib/client.js +43409 -0
  138. package/lib/compat/host-features.js +75 -0
  139. package/lib/reference-source.js +1 -1
  140. package/lib/reference-text.js +23 -1
  141. package/lib/takeover-protocol.js +1 -1
  142. package/lib/tool-browser/block-recovery.js +69 -0
  143. package/lib/tool-browser/code-tool.js +170 -19
  144. package/lib/tool-browser/code-worker.js +115 -20
  145. package/lib/tool-browser/errors.js +34 -0
  146. package/lib/tool-browser/index.js +66 -3593
  147. package/lib/tool-browser/page-probe.js +227 -28
  148. package/lib/tool-browser/panel-page.js +2 -1
  149. package/lib/tool-browser/probe-client.js +157 -0
  150. package/lib/tool-browser/screenshot-annotations.js +108 -0
  151. package/lib/tool-browser/state.js +337 -0
  152. package/lib/tool-browser/takeover.js +1 -1
  153. package/lib/tool-browser/tools-debug.js +862 -0
  154. package/lib/tool-browser/tools-interaction.js +993 -0
  155. package/lib/tool-browser/tools-navigation.js +807 -0
  156. package/lib/tool-browser/tools-observation.js +461 -0
  157. package/lib/tool-browser/tools-reference.js +293 -0
  158. package/lib/web-guest.js +1 -0
  159. package/package.json +15 -53
  160. package/README.en.md +0 -89
  161. package/browser-extension/constants.mjs +0 -20
  162. package/browser-extension/controller.mjs +0 -293
  163. package/browser-extension/locales.mjs +0 -15
  164. package/browser-extension/manifest.json +0 -12
  165. package/browser-extension/options.html +0 -14
  166. package/browser-extension/options.mjs +0 -9
  167. package/browser-extension/permission-guard.mjs +0 -13
  168. package/browser-extension/worker.mjs +0 -74
  169. package/dist/client.cjs +0 -43167
  170. package/lib/browser-reference/submission-receipts.js +0 -139
  171. package/scripts/build.mjs +0 -66
  172. package/scripts/bundle-host.mjs +0 -28
  173. package/scripts/fix-exports.mjs +0 -50
  174. package/scripts/install-electron.mjs +0 -51
  175. package/scripts/verify-exports.mjs +0 -47
  176. package/scripts/verify-preview-sdk.mjs +0 -93
  177. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  178. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  179. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  180. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  181. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  182. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  183. package/skills/dsh-debug-host/SKILL.md +0 -56
  184. package/skills/dsh-debug-self/SKILL.md +0 -50
  185. package/src/bridge-compatibility.ts +0 -39
  186. package/src/browser/handles.ts +0 -89
  187. package/src/browser/runtime.ts +0 -560
  188. package/src/browser/takeover-target.ts +0 -36
  189. package/src/browser/types.ts +0 -817
  190. package/src/browser-electron/authenticated-route.ts +0 -84
  191. package/src/browser-electron/automatic-maintenance.ts +0 -726
  192. package/src/browser-electron/bridge-auto.ts +0 -159
  193. package/src/browser-electron/bridge-connection.ts +0 -385
  194. package/src/browser-electron/bridge-endpoint.ts +0 -129
  195. package/src/browser-electron/bridge-install.ts +0 -289
  196. package/src/browser-electron/bridge-maintenance.ts +0 -189
  197. package/src/browser-electron/bridge-status.ts +0 -347
  198. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  199. package/src/browser-electron/desktop-identity.ts +0 -320
  200. package/src/browser-electron/document-readiness.ts +0 -45
  201. package/src/browser-electron/electron-provision.ts +0 -261
  202. package/src/browser-electron/entry.ts +0 -1299
  203. package/src/browser-electron/ephemeral-profile.ts +0 -189
  204. package/src/browser-electron/extension-browser.ts +0 -223
  205. package/src/browser-electron/extension-setup.ts +0 -67
  206. package/src/browser-electron/file-write.ts +0 -31
  207. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  208. package/src/browser-electron/guest-cookie-store.ts +0 -59
  209. package/src/browser-electron/guest-css-runtime.ts +0 -76
  210. package/src/browser-electron/guest-css.ts +0 -68
  211. package/src/browser-electron/guest-route.ts +0 -568
  212. package/src/browser-electron/guest-runtime.ts +0 -357
  213. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  214. package/src/browser-electron/guest-storage.ts +0 -117
  215. package/src/browser-electron/history-store.ts +0 -227
  216. package/src/browser-electron/host-main.ts +0 -1381
  217. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  218. package/src/browser-electron/http-body.ts +0 -65
  219. package/src/browser-electron/json-reply.ts +0 -47
  220. package/src/browser-electron/maintenance-broker.ts +0 -166
  221. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  222. package/src/browser-electron/maintenance-route.ts +0 -67
  223. package/src/browser-electron/missing-system-browser.ts +0 -113
  224. package/src/browser-electron/open-slot.ts +0 -49
  225. package/src/browser-electron/paths.ts +0 -25
  226. package/src/browser-electron/preferred-browser.ts +0 -120
  227. package/src/browser-electron/preview-route.ts +0 -218
  228. package/src/browser-electron/process-ownership.ts +0 -168
  229. package/src/browser-electron/process.ts +0 -23
  230. package/src/browser-electron/profile-checkpoint.ts +0 -187
  231. package/src/browser-electron/profile-command.ts +0 -46
  232. package/src/browser-electron/profile-extension.ts +0 -124
  233. package/src/browser-electron/profile-lease.ts +0 -115
  234. package/src/browser-electron/profile-residue.ts +0 -49
  235. package/src/browser-electron/provider.ts +0 -4571
  236. package/src/browser-electron/reference-route.ts +0 -608
  237. package/src/browser-electron/remote-host.ts +0 -1462
  238. package/src/browser-electron/rpc-input.ts +0 -13
  239. package/src/browser-electron/rpc-ops.ts +0 -41
  240. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  241. package/src/browser-electron/runtime-route.ts +0 -105
  242. package/src/browser-electron/runtime-status.ts +0 -242
  243. package/src/browser-electron/settings-route.ts +0 -64
  244. package/src/browser-electron/settings-store.ts +0 -589
  245. package/src/browser-electron/shortcuts-route.ts +0 -112
  246. package/src/browser-electron/sidebar-only-host.ts +0 -298
  247. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  248. package/src/browser-electron/system-browser.ts +0 -1497
  249. package/src/browser-electron/timing.ts +0 -16
  250. package/src/browser-electron/virtual-cursor.ts +0 -152
  251. package/src/browser-electron/windows-system.ts +0 -24
  252. package/src/browser-reference/delivery.ts +0 -384
  253. package/src/browser-reference/entry.ts +0 -631
  254. package/src/browser-reference/export.ts +0 -339
  255. package/src/browser-reference/import.ts +0 -303
  256. package/src/browser-reference/page-script.ts +0 -1537
  257. package/src/browser-reference/service.ts +0 -1315
  258. package/src/browser-reference/store.ts +0 -172
  259. package/src/browser-reference/submission-receipts.ts +0 -122
  260. package/src/browser-reference/text-quote.ts +0 -219
  261. package/src/browser-reference/types.ts +0 -195
  262. package/src/browser-reference/visible.ts +0 -367
  263. package/src/browser-reference/web-sources.ts +0 -103
  264. package/src/client/browser/BrowserController.ts +0 -693
  265. package/src/client/browser/BrowserFrame.ts +0 -78
  266. package/src/client/browser/BrowserNavigation.ts +0 -169
  267. package/src/client/browser/BrowserPage.ts +0 -23
  268. package/src/client/browser/BrowserPersistence.ts +0 -44
  269. package/src/client/browser/IframeImpl.ts +0 -176
  270. package/src/client/browser/child-tabs.ts +0 -14
  271. package/src/client/browser/iframe-reference.ts +0 -67
  272. package/src/client/browser/initialization.ts +0 -262
  273. package/src/client/browser/omnibox.ts +0 -243
  274. package/src/client/browser/store.ts +0 -38
  275. package/src/client/browser/takeover-channel.ts +0 -72
  276. package/src/client/browser/url.ts +0 -46
  277. package/src/client/browser/web-reference-source.ts +0 -52
  278. package/src/client/css-modules.d.ts +0 -4
  279. package/src/client/definition.tsx +0 -30
  280. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  281. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  282. package/src/client/electron/NativeChildPresentation.ts +0 -45
  283. package/src/client/electron/NativeViewPage.ts +0 -251
  284. package/src/client/electron/pages.ts +0 -23
  285. package/src/client/electron/reference-overlay.ts +0 -53
  286. package/src/client/electron/workspace.ts +0 -33
  287. package/src/client/index.ts +0 -293
  288. package/src/client/locales.ts +0 -857
  289. package/src/client/pages.ts +0 -28
  290. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  291. package/src/client/reference/client/draft-reference.ts +0 -167
  292. package/src/client/reference/client/index.ts +0 -7
  293. package/src/client/reference/client/ordered-submission.ts +0 -108
  294. package/src/client/reference/client/pending-delivery.ts +0 -216
  295. package/src/client/reference/client/plugin.ts +0 -189
  296. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  297. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  298. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  299. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  300. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  301. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  302. package/src/client/reference/client/production/assembly.ts +0 -471
  303. package/src/client/reference/client/production/asset-store.ts +0 -144
  304. package/src/client/reference/client/production/availability.ts +0 -74
  305. package/src/client/reference/client/production/bytes.ts +0 -36
  306. package/src/client/reference/client/production/delivery-client.ts +0 -211
  307. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  308. package/src/client/reference/client/production/http-transport.ts +0 -217
  309. package/src/client/reference/client/production/production-submission.ts +0 -310
  310. package/src/client/reference/client/production/protocol.ts +0 -231
  311. package/src/client/reference/client/production/reference-card.ts +0 -240
  312. package/src/client/reference/client/production/reference-labels.ts +0 -29
  313. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  314. package/src/client/reference/client/production/reveal.ts +0 -215
  315. package/src/client/reference/client/production/runtime.ts +0 -1101
  316. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  317. package/src/client/reference/client/production/source-marker.ts +0 -63
  318. package/src/client/reference/client/production/source-opener.ts +0 -55
  319. package/src/client/reference/client/production/styles.ts +0 -104
  320. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  321. package/src/client/reference/client/reveal.ts +0 -107
  322. package/src/client/reference/client/scheme.ts +0 -114
  323. package/src/client/reference/client/types.ts +0 -168
  324. package/src/client/reference/css-modules.d.ts +0 -4
  325. package/src/client/reference/index.ts +0 -11
  326. package/src/client/reference-capture-owner.ts +0 -162
  327. package/src/client/reference-intents.ts +0 -36
  328. package/src/client/settings/index.ts +0 -34
  329. package/src/client/settings/panel.ts +0 -2657
  330. package/src/client/shortcut-open.ts +0 -30
  331. package/src/client/startpage/binding.ts +0 -99
  332. package/src/client/startpage/controller.ts +0 -303
  333. package/src/client/startpage/model.ts +0 -279
  334. package/src/client/view/Browser.module.css +0 -751
  335. package/src/client/view/BrowserBody.tsx +0 -314
  336. package/src/client/view/BrowserPresentation.ts +0 -9
  337. package/src/client/view/BrowserTitle.tsx +0 -17
  338. package/src/client/view/IframePresentation.ts +0 -344
  339. package/src/client/view/StartPage.tsx +0 -597
  340. package/src/client/view/TakeoverBanner.tsx +0 -21
  341. package/src/index.ts +0 -110
  342. package/src/reference-owner.ts +0 -5
  343. package/src/reference-page.ts +0 -9
  344. package/src/reference-source.ts +0 -3
  345. package/src/reference-text.ts +0 -197
  346. package/src/startpage-settings.ts +0 -103
  347. package/src/startpage.ts +0 -71
  348. package/src/takeover-protocol.ts +0 -19
  349. package/src/tool-browser/code-tool.ts +0 -401
  350. package/src/tool-browser/code-worker.ts +0 -639
  351. package/src/tool-browser/element-fields.ts +0 -167
  352. package/src/tool-browser/index.ts +0 -3733
  353. package/src/tool-browser/page-probe.ts +0 -474
  354. package/src/tool-browser/panel-page.ts +0 -124
  355. package/src/tool-browser/screenshot-image.ts +0 -49
  356. package/src/tool-browser/takeover.ts +0 -198
  357. package/src/types/electron-shim.d.ts +0 -144
  358. package/src/types.ts +0 -85
  359. package/src/web-guest.ts +0 -34
  360. package/tools/accept-desktop.mjs +0 -148
@@ -1,320 +0,0 @@
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
- readonly layouts: readonly DesktopLayout[]
51
- }
52
-
53
- /**
54
- * The rule shipped in `desktop-bridge/desktop-identity.json`, used when the file cannot be read.
55
- *
56
- * A copy exists here only as a fallback for a broken package layout; the test suite asserts that it
57
- * equals the JSON, so the two can never drift apart silently.
58
- */
59
- export const FALLBACK_RULE: IdentityRule = {
60
- packageNames: ['@deepseek-ai/dsh-desktop', 'dsh-desktop'],
61
- mainEntry: 'lib/main.js',
62
- layouts: [
63
- { name: 'macos-bundle', marker: 'Contents/Info.plist', resources: 'Contents/Resources', executable: 'Contents/MacOS/DeepSeek Harness', cliLauncher: 'runtime/cli/bin/dsh' },
64
- { name: 'directory', resources: 'resources', executable: 'DeepSeek Harness.exe', cliLauncher: 'runtime/cli/bin/dsh.cmd' },
65
- ],
66
- }
67
-
68
- /** A verified install. */
69
- export interface DesktopIdentity {
70
- readonly ok: true
71
- /** The install root that was verified. */
72
- readonly root: string
73
- /** Which shape was verified — the archive when it exists, the extraction only without one. */
74
- readonly layout: 'packed' | 'unpacked'
75
- /** `name` from the package the caller will actually run. */
76
- readonly packageName: string
77
- /** `version`, when the package declares one. */
78
- readonly version?: string
79
- }
80
-
81
- /** A refusal, with a reason a human can act on. */
82
- export interface IdentityRefusal {
83
- readonly ok: false
84
- readonly reason: string
85
- }
86
-
87
- /**
88
- * Read the identity rule.
89
- *
90
- * Resolved relative to this module, which in both the repository and the published tarball puts
91
- * `desktop-bridge/` beside `lib/`. A missing file is not fatal — the fallback is the same rule —
92
- * but a *malformed* one is an error the caller should not ignore, so it is reported through the
93
- * refusal path rather than silently swapped for the fallback.
94
- * @returns the rule, or an error string.
95
- */
96
- export function readIdentityRule(): IdentityRule | { readonly error: string } {
97
- try {
98
- const path = new URL('../../desktop-bridge/desktop-identity.json', import.meta.url)
99
- const raw = JSON.parse(readFileSync(path, 'utf8')) as Partial<IdentityRule>
100
- const names = raw.packageNames
101
- const main = raw.mainEntry
102
- if (!Array.isArray(names) || names.length === 0 || names.some(n => typeof n !== 'string')) {
103
- return { error: 'desktop-identity.json: packageNames must be a non-empty array of strings' }
104
- }
105
- if (typeof main !== 'string' || main === '') {
106
- return { error: 'desktop-identity.json: mainEntry must be a non-empty string' }
107
- }
108
- const layouts = raw.layouts
109
- const field = (value: unknown): boolean => typeof value === 'string' && value !== ''
110
- if (!Array.isArray(layouts) || layouts.length === 0
111
- || layouts.some(l => l === null || typeof l !== 'object' || !field(l.name) || !field(l.resources) || !field(l.executable) || !field(l.cliLauncher)
112
- || (l.marker !== undefined && !field(l.marker)))
113
- || layouts[layouts.length - 1]?.marker !== undefined) {
114
- return { error: 'desktop-identity.json: layouts must be a non-empty array whose last entry has no marker' }
115
- }
116
- return { packageNames: names, mainEntry: main, layouts }
117
- } catch (error) {
118
- if (error instanceof Error && 'code' in error && (error as NodeJS.ErrnoException).code === 'ENOENT') {
119
- return FALLBACK_RULE
120
- }
121
- return { error: `desktop-identity.json could not be read: ${String(error)}` }
122
- }
123
- }
124
-
125
- function layoutOf(rule: IdentityRule, installRoot: string): DesktopLayout {
126
- return rule.layouts.find(layout => layout.marker === undefined || existsSync(join(installRoot, ...layout.marker.split('/'))))
127
- ?? rule.layouts[rule.layouts.length - 1] as DesktopLayout
128
- }
129
-
130
- /**
131
- * The layout of an install root: a macOS `.app` bundle or a plain directory (Windows).
132
- * Decided by the install's own shape rather than the host OS, so every platform reads it the same.
133
- * @param installRoot - the install directory.
134
- * @returns the layout, or an error when the identity rule cannot be read.
135
- */
136
- export function desktopLayout(installRoot: string): DesktopLayout | { readonly error: string } {
137
- const rule = readIdentityRule()
138
- return 'error' in rule ? rule : layoutOf(rule, installRoot)
139
- }
140
-
141
- /**
142
- * Absolute paths an install keeps, from its layout.
143
- * @param installRoot - the install directory.
144
- * @returns resources directory, GUI executable and CLI launcher.
145
- */
146
- export function desktopPaths(installRoot: string): { readonly resources: string; readonly executable: string; readonly cliLauncher: string } {
147
- const layout = desktopLayout(installRoot)
148
- if ('error' in layout) throw new Error(layout.error)
149
- const resources = join(installRoot, ...layout.resources.split('/'))
150
- return { resources, executable: join(installRoot, ...layout.executable.split('/')), cliLauncher: join(resources, ...layout.cliLauncher.split('/')) }
151
- }
152
-
153
- /**
154
- * One entry of a Chromium pickle header.
155
- *
156
- * `offset` is relative to the content area that follows the header; `unpacked` entries carry no
157
- * bytes in the archive and live beside it instead.
158
- */
159
- interface AsarEntry {
160
- readonly size: number
161
- readonly offset?: string
162
- readonly unpacked?: boolean
163
- readonly files?: Record<string, AsarEntry>
164
- }
165
-
166
- /**
167
- * Parse an asar header, the same way the installer does.
168
- *
169
- * Layout, for the next reader: an 8-byte outer pickle (`[size][jsonLength]`), then the header
170
- * pickle whose first 4 bytes are the JSON length, then the JSON tree. File content starts right
171
- * after the header pickle.
172
- * @param archive - the archive path.
173
- * @returns the header tree and the offset where content starts, or an error string.
174
- */
175
- function readAsarHeader(archive: string): { header: { files?: Record<string, AsarEntry> }; contentBase: number } | { error: string } {
176
- let fd: number | undefined
177
- try {
178
- fd = archiveFs.openSync(archive, 'r')
179
- const outer = Buffer.alloc(8)
180
- if (archiveFs.readSync(fd, outer, 0, 8, 0) !== 8) return { error: 'the archive header is truncated' }
181
- const headerSize = outer.readUInt32LE(4)
182
- if (headerSize < 8 || headerSize > 64 * 1024 * 1024) return { error: `implausible archive header size (${headerSize})` }
183
- const header = Buffer.alloc(headerSize)
184
- if (archiveFs.readSync(fd, header, 0, headerSize, 8) !== headerSize) return { error: 'the archive header is truncated' }
185
- const jsonLength = header.readUInt32LE(4)
186
- if (jsonLength <= 0 || jsonLength > headerSize - 8) return { error: 'the archive header has an implausible JSON length' }
187
- return { header: JSON.parse(header.toString('utf8', 8, 8 + jsonLength)), contentBase: 8 + headerSize }
188
- } catch (error) {
189
- return { error: `the archive header could not be read: ${String(error)}` }
190
- } finally {
191
- if (fd !== undefined) {
192
- try { archiveFs.closeSync(fd) } catch { /* already closed */ }
193
- }
194
- }
195
- }
196
-
197
- /**
198
- * Walk a slash-separated path inside an asar header tree.
199
- * @param tree - the header's `files` node.
200
- * @param path - e.g. `lib/main.js`.
201
- * @returns the entry, or undefined when the path does not exist.
202
- */
203
- function entryAt(tree: Record<string, AsarEntry> | undefined, path: string): AsarEntry | undefined {
204
- let node: AsarEntry | undefined
205
- let files: Record<string, AsarEntry> | undefined = tree
206
- for (const part of path.split('/')) {
207
- if (files === undefined) return undefined
208
- node = files[part]
209
- if (node === undefined) return undefined
210
- files = node.files
211
- }
212
- return node
213
- }
214
-
215
- /**
216
- * Read one file out of an asar archive without extracting the tree.
217
- * @param archive - the archive path.
218
- * @param path - a slash-separated path inside the archive.
219
- * @returns the bytes, or undefined when the entry is absent or unreadable.
220
- */
221
- export function readAsarFile(archive: string, path: string): Buffer | undefined {
222
- const parsed = readAsarHeader(archive)
223
- if ('error' in parsed) return undefined
224
- const entry = entryAt(parsed.header.files, path)
225
- if (entry === undefined || entry.files !== undefined || entry.unpacked === true) return undefined
226
- if (typeof entry.offset !== 'string' || typeof entry.size !== 'number' || entry.size < 0) return undefined
227
- let fd: number | undefined
228
- try {
229
- fd = archiveFs.openSync(archive, 'r')
230
- const buffer = Buffer.alloc(entry.size)
231
- const read = archiveFs.readSync(fd, buffer, 0, entry.size, parsed.contentBase + Number(entry.offset))
232
- return read === entry.size ? buffer : undefined
233
- } catch {
234
- return undefined
235
- } finally {
236
- if (fd !== undefined) {
237
- try { archiveFs.closeSync(fd) } catch { /* already closed */ }
238
- }
239
- }
240
- }
241
-
242
- /**
243
- * Whether an install directory is DSH Desktop.
244
- *
245
- * Everything the caller does next (stop the app, delete a tree, extract, rename, write) depends on
246
- * this being right, so every uncertainty resolves to a refusal that names what was found.
247
- * @param installRoot - the directory a user or the discovery probe named.
248
- * @returns the verified identity, or a refusal with a reason.
249
- */
250
- export function readDesktopIdentity(installRoot: string): DesktopIdentity | IdentityRefusal {
251
- const rule = readIdentityRule()
252
- if ('error' in rule) return { ok: false, reason: rule.error }
253
- const resources = join(installRoot, ...layoutOf(rule, installRoot).resources.split('/'))
254
- const appDir = join(resources, 'app')
255
- const archive = join(resources, 'app.asar')
256
-
257
- let archivePresent: boolean
258
- try {
259
- archivePresent = archiveFs.existsSync(archive)
260
- } catch {
261
- return { ok: false, reason: `cannot inspect ${archive}` }
262
- }
263
-
264
- const layout: 'packed' | 'unpacked' = archivePresent ? 'packed' : 'unpacked'
265
- let manifestText: string | undefined
266
- let mainPresent: boolean
267
- if (archivePresent) {
268
- const parsed = readAsarHeader(archive)
269
- if ('error' in parsed) {
270
- return { ok: false, reason: `${archive} could not be read: ${parsed.error}` }
271
- }
272
- const manifest = entryAt(parsed.header.files, 'package.json')
273
- if (manifest === undefined || manifest.files !== undefined || manifest.unpacked === true) {
274
- return { ok: false, reason: `${archive} has no plain package.json; an archive without one is not proof of identity` }
275
- }
276
- manifestText = readAsarFile(archive, 'package.json')?.toString('utf8')
277
- if (manifestText === undefined) {
278
- return { ok: false, reason: `${archive}: package.json is listed but its bytes cannot be read` }
279
- }
280
- mainPresent = entryAt(parsed.header.files, rule.mainEntry) !== undefined
281
- } else {
282
- const manifestPath = join(appDir, 'package.json')
283
- try {
284
- manifestText = readFileSync(manifestPath, 'utf8')
285
- } catch (error) {
286
- console.error(`[dsh-browser] cannot read the package manifest at ${manifestPath}: ${String(error)}`)
287
- return { ok: false, reason: `${manifestPath} is missing; a directory without a package manifest is not a DSH Desktop install` }
288
- }
289
- mainPresent = existsSync(join(appDir, ...rule.mainEntry.split('/')))
290
- }
291
-
292
- let manifest: { name?: unknown; version?: unknown }
293
- try {
294
- manifest = JSON.parse(manifestText) as { name?: unknown; version?: unknown }
295
- } catch {
296
- return { ok: false, reason: 'the package manifest is not valid JSON' }
297
- }
298
- const name = typeof manifest.name === 'string' ? manifest.name : ''
299
- if (!rule.packageNames.includes(name)) {
300
- return {
301
- ok: false,
302
- reason: `the app calls itself ${name === '' ? '(no name)' : JSON.stringify(name)}, which is not one of `
303
- + `${rule.packageNames.join(' / ')} — refusing to touch a different application`,
304
- }
305
- }
306
-
307
- // The main entry is the file the installer patches and the shell runs; if it is not there, this
308
- // is not an install this plugin can reason about even though the manifest looks right.
309
- if (!mainPresent) {
310
- return { ok: false, reason: `${rule.mainEntry} is not present under ${archivePresent ? archive : appDir}` }
311
- }
312
-
313
- return {
314
- ok: true,
315
- root: installRoot,
316
- layout,
317
- packageName: name,
318
- ...typeof manifest.version === 'string' ? { version: manifest.version } : {},
319
- }
320
- }
@@ -1,45 +0,0 @@
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
- }
@@ -1,261 +0,0 @@
1
- /** Prepare an explicitly supplied external Electron runtime, never the plugin generation. */
2
- import { spawn } from 'node:child_process'
3
- import { existsSync, readFileSync } from 'node:fs'
4
- import { isAbsolute, join } from 'node:path'
5
-
6
- import { internals } from './remote-host.ts'
7
-
8
- /** How long a background provision may run before it is abandoned. */
9
- export const PROVISION_TIMEOUT_MS = 180_000
10
-
11
- /** What happened, in terms a log line can carry. */
12
- export interface ProvisionResult {
13
- /** `present` — nothing to do; `ready` — provisioned now; `skipped` — opted out; `failed`. */
14
- readonly status: 'present' | 'ready' | 'skipped' | 'failed'
15
- /** One line for the log; never contains a stack trace a user has to decode. */
16
- readonly detail: string
17
- }
18
-
19
- /**
20
- * The state a settings panel shows, which is one state wider than {@link ProvisionResult}.
21
- *
22
- * `idle` and `preparing` are the two a log line never needs and a user always does: "nothing has
23
- * been asked for yet" and "a ~100 MB download is running right now" are the states in which a first
24
- * browser call is slow, and until this existed neither was visible anywhere in the product — the
25
- * only trace was a log line the panel cannot read.
26
- */
27
- export interface ProvisionSnapshot {
28
- /** `idle` and `preparing` are provisional; the rest are terminal for this attempt. */
29
- readonly state: 'idle' | 'preparing' | 'present' | 'ready' | 'skipped' | 'failed'
30
- /** One line, already user-facing: never a stack trace. */
31
- readonly detail: string
32
- /** When the state last changed, ISO. */
33
- readonly at: string
34
- }
35
-
36
- const IDLE: ProvisionSnapshot = {
37
- state: 'idle',
38
- detail: 'the runtime has not been asked for yet',
39
- at: new Date(0).toISOString(),
40
- }
41
-
42
- let latest: ProvisionSnapshot = IDLE
43
-
44
- /**
45
- * The current provisioning state, for a readiness report.
46
- *
47
- * Deliberately a snapshot rather than a promise: a panel polling this must be able to answer in one
48
- * synchronous read, without awaiting (and thereby echoing) the download it is reporting on.
49
- * @returns the last state written, or the idle state before anything ran.
50
- */
51
- export function provisionSnapshot(): ProvisionSnapshot {
52
- return latest
53
- }
54
-
55
- /** Replace the reported state. Internal: every terminal result is recorded here. */
56
- function record(result: ProvisionResult): ProvisionResult {
57
- latest = { state: result.status, detail: result.detail, at: new Date().toISOString() }
58
- return result
59
- }
60
-
61
- /** Everything this module touches from the outside, so a test can drive it without Electron. */
62
- export interface ProvisionDeps {
63
- /** Whether a spawnable binary already exists. */
64
- readonly hasBinary: () => boolean
65
- /** The installed electron package's own installer script, or undefined when it is not there. */
66
- readonly installerScript: () => string | undefined
67
- /** Runs the installer; resolves to an exit code, or rejects/returns null on failure. */
68
- readonly run: (script: string, signal?: AbortSignal) => Promise<{ code: number | null; detail?: string }>
69
- /** Where the outcome goes. */
70
- readonly log: (message: string) => void
71
- /** Opt-out honoured exactly like the install script honours it. */
72
- readonly skip: () => boolean
73
- /** Budget for one provision. */
74
- readonly timeoutMs: number
75
- }
76
-
77
- /**
78
- * Whether a spawnable Electron binary is already available.
79
- *
80
- * Resolved through the same probe the host uses, so this can never disagree with what a launch
81
- * would find: a second, cheaper-looking check would be the classic way to report "ready" and then
82
- * fail at spawn time.
83
- * @returns true when a launch would find a binary.
84
- */
85
- export function hasElectronRuntime(): boolean {
86
- try {
87
- internals.resolveElectronPath()
88
- return true
89
- } catch {
90
- return false
91
- }
92
- }
93
-
94
- /**
95
- * @returns the explicitly selected external package installer, or undefined.
96
- */
97
- function electronInstallerScript(): string | undefined {
98
- try {
99
- const directory = process.env.DSH_BROWSER_ELECTRON_PACKAGE
100
- if (!directory || !isAbsolute(directory)) return undefined
101
- const metadata = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { name?: unknown }
102
- if (metadata.name !== 'electron') return undefined
103
- const script = join(directory, 'install.js')
104
- return existsSync(script) ? script : undefined
105
- } catch {
106
- return undefined
107
- }
108
- }
109
-
110
- /** The Electron version the installed package asks for, for a log line that names the download. */
111
- function electronVersion(): string {
112
- try {
113
- const directory = process.env.DSH_BROWSER_ELECTRON_PACKAGE
114
- if (!directory || !isAbsolute(directory)) return 'unknown'
115
- const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { version?: unknown }
116
- return typeof manifest.version === 'string' ? manifest.version : 'unknown'
117
- } catch {
118
- return 'unknown'
119
- }
120
- }
121
-
122
- let runningInstaller: Promise<{ code: number | null; detail?: string }> | undefined
123
-
124
- /** The real dependencies: this process's spawn, fs and logger. */
125
- export function defaultDeps(log: (message: string) => void = () => {}): ProvisionDeps {
126
- return {
127
- hasBinary: hasElectronRuntime,
128
- installerScript: electronInstallerScript,
129
- run: (script, signal) => {
130
- if (runningInstaller !== undefined) return runningInstaller
131
- const run = new Promise<{ code: number | null; detail?: string }>(resolve => {
132
- const child = spawn(process.execPath, [script], {
133
- env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
134
- stdio: ['ignore', 'ignore', 'ignore'],
135
- windowsHide: true,
136
- })
137
- let failure: string | undefined
138
- const abort = (): void => { child.kill('SIGKILL') }
139
- signal?.addEventListener('abort', abort, { once: true })
140
- if (signal?.aborted) abort()
141
- child.once('error', error => { failure = String(error) })
142
- child.once('close', code => {
143
- signal?.removeEventListener('abort', abort)
144
- resolve({ code, detail: failure })
145
- })
146
- })
147
- runningInstaller = run
148
- const clear = (): void => { if (runningInstaller === run) runningInstaller = undefined }
149
- void run.then(clear, clear)
150
- return run
151
- },
152
- log,
153
- skip: () => typeof process.env.ELECTRON_SKIP_BINARY_DOWNLOAD === 'string'
154
- && process.env.ELECTRON_SKIP_BINARY_DOWNLOAD !== '',
155
- timeoutMs: PROVISION_TIMEOUT_MS,
156
- }
157
- }
158
-
159
- /**
160
- * Provision the runtime once per process, when it is missing.
161
- *
162
- * Concurrent callers share the first attempt: two tool calls arriving together must not start two
163
- * downloads into the same directory.
164
- * @param deps - the effects, defaulted to this process's.
165
- * @returns what happened. Never throws.
166
- */
167
- export async function ensureElectronRuntime(deps: ProvisionDeps = defaultDeps()): Promise<ProvisionResult> {
168
- if (deps.hasBinary()) return record({ status: 'present', detail: 'an Electron runtime is already available' })
169
- if (deps.skip()) return record({ status: 'skipped', detail: 'ELECTRON_SKIP_BINARY_DOWNLOAD is set' })
170
- const script = deps.installerScript()
171
- if (script === undefined) {
172
- return record({ status: 'failed', detail: 'the installed electron package has no install.js; reinstall the plugin in this profile' })
173
- }
174
- const version = electronVersion()
175
- latest = {
176
- state: 'preparing',
177
- detail: `downloading Electron ${version} (one time, about a minute)`,
178
- at: new Date().toISOString(),
179
- }
180
- deps.log(`preparing Electron ${version} in the background (a missing runtime needs a download)`)
181
- // The bound has to be a REFERENCED timer, and it has to be cleared when the race finishes.
182
- //
183
- // A first version unref'd it — "do not keep the process alive for a download" — which is exactly
184
- // backwards: with nothing else on the loop the timer never fires, the promise never settles, and a
185
- // caller waiting on it hangs with no error at all. CI caught it before a user could: the test for
186
- // this path failed with "Promise resolution is still pending but the event loop has already
187
- // resolved". Keep it referenced, and clear it so a success does not leave a 180 s handle behind.
188
- let timer: ReturnType<typeof setTimeout> | undefined
189
- const controller = new AbortController()
190
- const timeout = new Promise<{ code: number | null; detail: string }>(resolve => {
191
- timer = setTimeout(
192
- () => {
193
- controller.abort()
194
- resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` })
195
- },
196
- deps.timeoutMs,
197
- )
198
- })
199
- let outcome: { code: number | null; detail?: string }
200
- try {
201
- outcome = await Promise.race([deps.run(script, controller.signal), timeout])
202
- } catch (error) {
203
- return record({ status: 'failed', detail: `the download failed: ${String(error)}` })
204
- } finally {
205
- if (timer !== undefined) clearTimeout(timer)
206
- }
207
- if (outcome.code !== 0) {
208
- return record({
209
- status: 'failed',
210
- detail: `Electron provisioning did not finish (${outcome.detail ?? `exit ${String(outcome.code)}`}); `
211
- + 'the browser still works through a sidebar, Chrome or Edge; retry from Settings → Browser → '
212
- + 'Readiness ("Prepare the bundled browser"), or run `npx --no dsh-browser-install-electron`',
213
- })
214
- }
215
- return record({ status: 'ready', detail: 'the Electron runtime is ready' })
216
- }
217
-
218
- /** One attempt per process, shared by every caller. */
219
- let attempt: Promise<ProvisionResult> | undefined
220
- /** Whether {@link attempt} has settled, which is what makes a retry possible. */
221
- let settled = false
222
-
223
- /**
224
- * Start (or join) the single background attempt.
225
- *
226
- * Returns immediately with the shared promise, so a caller that does not care can ignore it and one
227
- * that does can await it — the returned promise never rejects.
228
- *
229
- * `force` is the second half of the settings panel's retry button. Without it the memoised attempt
230
- * made a failed download permanent for the life of the process: the panel could offer a button, the
231
- * button could call this, and the answer would be the failure it was trying to replace. An attempt
232
- * still IN FLIGHT is always joined, never restarted — two downloads into one directory is the one
233
- * outcome worth refusing.
234
- * @param log - where the outcome goes.
235
- * @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
236
- * @param options - `force` discards a settled attempt so a new one may start.
237
- * @returns the shared attempt.
238
- */
239
- export function provisionElectronInBackground(
240
- log: (message: string) => void,
241
- deps: ProvisionDeps = defaultDeps(log),
242
- options: { readonly force?: boolean } = {},
243
- ): Promise<ProvisionResult> {
244
- if (options.force === true && settled) {
245
- attempt = undefined
246
- settled = false
247
- }
248
- attempt ??= ensureElectronRuntime(deps).then(result => {
249
- settled = true
250
- log(`electron runtime: ${result.status} — ${result.detail}`)
251
- return result
252
- })
253
- return attempt
254
- }
255
-
256
- /** Forget the attempt. Tests only: a real process provisions at most once. */
257
- export function resetProvisionStateForTest(): void {
258
- attempt = undefined
259
- settled = false
260
- latest = IDLE
261
- }