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,159 +0,0 @@
1
- import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
2
- /**
3
- * Compatibility for historical automatic-install settings and explicit bridge-maintenance intent.
4
- * Runtime automatic installation is disabled. Bridge maintenance requires the user to close DSH
5
- * Desktop before explicitly running the installer; loading a plugin never changes the installation.
6
- * Historical marker readers remain available for diagnostics.
7
- * @module dsh-browser/browser-electron/bridge-auto
8
- */
9
- import { existsSync, mkdirSync, readFileSync } from 'node:fs'
10
- import { dirname, join } from 'node:path'
11
-
12
- import type { BridgeStatus } from './bridge-status.ts'
13
- import type { BrowserChannel } from './system-browser.ts'
14
- import { writeFileAtomic } from './settings-store.ts'
15
-
16
- /** What the last automatic attempt was, and for which desktop build. */
17
- export interface AutoInstallMarker {
18
- /** Desktop build the attempt belonged to (`version` from the identity check when known). */
19
- readonly build: string
20
- /** ISO timestamp of the attempt, recorded BEFORE running, so a crash still counts. */
21
- readonly attemptedAt: string
22
- /** Outcome recorded afterwards, for the panel and for support: `started` / `installed` / a reason. */
23
- readonly outcome: string
24
- }
25
-
26
- /** Everything the decision needs, so it can be tested without a filesystem or a shell. */
27
- export interface AutoInstallInput {
28
- /** The launcher's current profile name, rather than an installed Desktop found on disk. */
29
- readonly profile: string | undefined
30
- /** Only sidebar and automatic selection need the desktop bridge. */
31
- readonly channel: BrowserChannel
32
- /** Quiet mode preserves the current desktop session instead of restarting it implicitly. */
33
- readonly quiet: boolean
34
- /** The desktop install directory, or undefined when this is the web end. */
35
- readonly installRoot: string | undefined
36
- /** Whether the operator left automatic installation on. */
37
- readonly enabled: boolean
38
- /** The reading the panel would show. */
39
- readonly status: BridgeStatus
40
- /** The last attempt, when one is recorded. */
41
- readonly marker: AutoInstallMarker | undefined
42
- /** How long an attempt for the same build suppresses the next one. */
43
- readonly cooldownMs: number
44
- /** Current time, injected. */
45
- readonly now: number
46
- }
47
-
48
- /** Why the automatic install did or did not run, in words a log line can carry. */
49
- export interface AutoInstallDecision {
50
- /** Whether to start the installer now. */
51
- readonly run: boolean
52
- /** The reason, either way. */
53
- readonly why: string
54
- }
55
-
56
- /** Historical attempt-record interval, retained for compatibility with existing diagnostics. */
57
- export const AUTO_INSTALL_COOLDOWN_MS = 24 * 60 * 60 * 1_000
58
-
59
- /**
60
- * Report that runtime bridge installation is deferred to explicit maintenance.
61
- *
62
- * @param input - the readings described by {@link AutoInstallInput}.
63
- * @returns whether to run, and why.
64
- */
65
- export function autoInstallDecision(_input: AutoInstallInput): AutoInstallDecision {
66
- return { run: false, why: 'runtime automatic bridge installation is disabled; close DSH Desktop and run bridge maintenance explicitly' }
67
- }
68
-
69
- /**
70
- * Read the profile identity supplied by DSH's launcher before plugins mount.
71
- * A Desktop installation or Electron executable can also belong to a Web/CLI invocation,
72
- * so neither is used to infer the current surface.
73
- * @param ctx - plugin context; older or custom compositions may omit the profile service.
74
- * @returns the current profile name, or undefined when the launcher did not provide it.
75
- */
76
- export function readAutoInstallProfile(ctx: unknown): string | undefined {
77
- try {
78
- const context = ctx as { get?: (name: string) => unknown }
79
- if (typeof context?.get !== 'function') return undefined
80
- const profile = context.get('profileContext') as { name?: unknown } | undefined
81
- return typeof profile?.name === 'string' ? profile.name : undefined
82
- } catch {
83
- return undefined
84
- }
85
- }
86
-
87
- /** A manual uninstall could not record the operator's automatic-install opt-out. */
88
- export class BridgeAutoInstallPreferenceError extends Error {
89
- constructor(cause: unknown) {
90
- super(`could not save automatic bridge installation preference: ${String(cause)}`, { cause })
91
- this.name = 'BridgeAutoInstallPreferenceError'
92
- }
93
- }
94
-
95
- /**
96
- * Preserve an explicit uninstall as an automatic-install opt-out in historical settings.
97
- * The preference is written before the installer starts, so a failed write cannot launch maintenance.
98
- * A failed uninstall retains the opt-out; an explicit install leaves an existing opt-out unchanged.
99
- * @param action - the authenticated user's selected action.
100
- * @param update - persist the operator's bridge preference.
101
- * @param run - perform the installer action after its preference is durable.
102
- * @returns the installer's result.
103
- */
104
- export async function runWithManualBridgePreference<T>(
105
- action: 'install' | 'uninstall',
106
- update: (patch: { readonly bridge: { readonly autoInstall: false } }) => unknown,
107
- run: () => Promise<T>,
108
- ): Promise<T> {
109
- if (action === 'uninstall') {
110
- try { update({ bridge: { autoInstall: false } }) }
111
- catch (error) { throw new BridgeAutoInstallPreferenceError(error) }
112
- }
113
- return await run()
114
- }
115
-
116
- /** Where the attempt record lives, beside the settings the plugin already owns. */
117
- export function autoInstallMarkerPath(dshHome: string): string {
118
- return join(dshHome, BROWSER_PROFILE_DIR, 'bridge-auto-install.json')
119
- }
120
-
121
- /**
122
- * Read the last attempt.
123
- *
124
- * A record that cannot be parsed is treated as absent: the guard exists to prevent loops, and a single
125
- * extra attempt after a corrupt file is cheaper than refusing to ever install again.
126
- * @param path - marker file path.
127
- * @returns the marker, or undefined.
128
- */
129
- export function readAutoInstallMarker(path: string): AutoInstallMarker | undefined {
130
- if (!existsSync(path)) return undefined
131
- try {
132
- const parsed = JSON.parse(readFileSync(path, 'utf8')) as Partial<AutoInstallMarker>
133
- if (typeof parsed.build !== 'string' || typeof parsed.attemptedAt !== 'string') return undefined
134
- return {
135
- build: parsed.build,
136
- attemptedAt: parsed.attemptedAt,
137
- outcome: typeof parsed.outcome === 'string' ? parsed.outcome : 'unknown',
138
- }
139
- } catch {
140
- return undefined
141
- }
142
- }
143
-
144
- /**
145
- * Record an attempt. Written before the installer runs: if the shell is killed mid-install, the next
146
- * launch must still see that an attempt happened rather than starting another restart.
147
- * @param path - marker file path.
148
- * @param marker - what to record.
149
- * @returns whether the record was saved; callers skip automatic restarts without a durable guard.
150
- */
151
- export function writeAutoInstallMarker(path: string, marker: AutoInstallMarker): boolean {
152
- try {
153
- mkdirSync(dirname(path), { recursive: true })
154
- writeFileAtomic(path, `${JSON.stringify(marker, null, 2)}\n`)
155
- return true
156
- } catch {
157
- return false
158
- }
159
- }
@@ -1,385 +0,0 @@
1
- import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs'
2
- import { readFileSync } from 'node:fs'
3
- /**
4
- * Transport for the desktop shell's browser bridge: one long-lived connection to a
5
- * loopback TCP service.
6
- *
7
- * WHY THIS IS ITS OWN MODULE
8
- * The bridge used to be reached with a fresh connection per request, which measured
9
- * at ~25ms per call (TCP handshake + token exchange) against ~0.2ms when the socket
10
- * is reused. A single browser action issues several CDP commands, so that cost was
11
- * multiplied on every tool call — the difference between a snappy agent and a
12
- * visibly sluggish one. Reuse is therefore a property of the transport, and keeping
13
- * it here means the view host above does not have to think about sockets at all.
14
- *
15
- * PROTOCOL
16
- * The first line on a connection carries the token; the service marks the socket
17
- * authenticated and ignores that line as a command. Requests and answers are then
18
- * newline-delimited JSON, one answer per request, in order.
19
- *
20
- * @module dsh-browser/browser-electron/bridge-connection
21
- */
22
-
23
- import { connect, type Socket } from 'node:net'
24
- import type { BrowserSessionWireId, BrowserTabWireId } from '../browser/handles.ts'
25
- import { bridgePackageError } from '../bridge-compatibility.ts'
26
-
27
- export type BridgeRequest =
28
- | { readonly op: 'version' }
29
- | { readonly op: 'list'; readonly handle?: BrowserSessionWireId }
30
- | { readonly op: 'collapseSidebar' | 'releaseSession'; readonly handle: BrowserSessionWireId }
31
- | { readonly op: 'ensureSidebar'; readonly handle: BrowserTabWireId; readonly deadline: number; readonly transactionId: string; readonly url?: string; readonly attachOnly?: boolean }
32
- | { readonly op: 'cancelSidebar'; readonly handle: BrowserTabWireId; readonly transactionId: string }
33
- | { readonly op: 'adoptPage' | 'closePage' | 'showTab' | 'releaseTab'; readonly handle: BrowserTabWireId }
34
- | { readonly op: 'download'; readonly handle: BrowserTabWireId; readonly url: string; readonly savePath: string }
35
- | { readonly op: 'cdp'; readonly handle: BrowserTabWireId; readonly method: string; readonly params?: Record<string, unknown> }
36
-
37
- /** Where the shell publishes its bridge endpoint. */
38
- export interface BridgeEndpoint {
39
- readonly port: number
40
- readonly token: string
41
- readonly pid: number
42
- readonly updatedAt?: string
43
- }
44
-
45
- /** One queued request, waiting for its answer. */
46
- interface PendingCall {
47
- readonly resolve: (answer: Record<string, unknown>) => void
48
- readonly reject: (error: Error) => void
49
- }
50
-
51
- /**
52
- * Safety cap on one un-answered reply line. CDP answers from the sidebar (a screenshot's
53
- * base64 is the big one) cross this socket, so the cap is generous; what it exists for is a
54
- * peer that never sends a newline — `this.buffer += chunk` grew without bound, unlike the
55
- * same buffer in remote-host.ts, which caps at 512 MiB.
56
- */
57
- const MAX_BUFFER_BYTES = 128 * 1024 * 1024
58
-
59
- /**
60
- * Field this client adds to every request so the shell can echo it back and never relies on
61
- * byte order to pair an answer with its request. Loosely named, and additive on purpose: a
62
- * bridge that does not know it simply ignores it (the current shipped shell does), and the
63
- * client then falls back to arrival order, which is what the protocol guaranteed before.
64
- */
65
- const REQUEST_ID_FIELD = 'bridgeRequestId'
66
-
67
- /**
68
- * How long the published endpoint may go un-refreshed before its shell is presumed gone.
69
- *
70
- * A live shell rewrites the file every fifteen seconds (its keep-alive), so four missed refreshes
71
- * is not a slow shell — it is a shell that exited and left its last write behind. The distinction
72
- * matters because the file is the ONLY thing that says where the bridge is: a tombstone names a
73
- * port nobody owns, and a client that trusts it dials that port for the rest of its life.
74
- */
75
- const ENDPOINT_TTL_MS = 60_000
76
-
77
- /**
78
- * The same window, for the readiness report.
79
- *
80
- * Exported rather than re-stated: "the shell is gone" must mean one thing in this plugin. A second
81
- * copy of the number would drift, and the drift would show up as a panel that says ready while every
82
- * call times out — the exact failure this constant exists to prevent.
83
- */
84
- export const ENDPOINT_STALE_AFTER_MS = ENDPOINT_TTL_MS
85
-
86
- /**
87
- * A reusable connection to the bridge.
88
- *
89
- * Requests may be in flight CONCURRENTLY, so answers are correlated by id rather than by
90
- * position: `call()` stamps a unique {@link REQUEST_ID_FIELD} on the request and `onData()`
91
- * resolves the entry that carries the echoed id. A bridge that does not echo it is still
92
- * supported — its answer is handed to the oldest outstanding request, which is the
93
- * arrival-order rule the protocol states. Once such an answer has been seen, the connection
94
- * stops keeping two requests in flight (a second one re-dials), so position can never be the
95
- * only thing distinguishing two callers' answers. An answer that matches nothing is never
96
- * handed to whichever request happens to be first: the socket is dropped instead.
97
- *
98
- * A broken socket is discarded so the next call dials again — a dead connection must never
99
- * become a dead plugin.
100
- */
101
- export class BridgeConnection {
102
- private socket: Socket | undefined
103
- private buffer = ''
104
- /** Outstanding requests by id. */
105
- private readonly pending = new Map<number, PendingCall>()
106
- /** Ids of the requests sent on the current socket, oldest first. */
107
- private readonly queue: number[] = []
108
- private nextId = 1
109
- /** True once this connection may only have one request in flight at a time. */
110
- private serialisable = false
111
- /** True once the shell behind this connection has been reported gone. */
112
- private lostNotified = false
113
-
114
- /**
115
- * @param endpoint - the shell's published bridge endpoint.
116
- * @param endpointPath - where that endpoint is republished, so a moved port can be followed.
117
- * @param onLost - called once when this connection concludes the shell behind it is gone.
118
- */
119
- constructor(
120
- private endpoint: BridgeEndpoint,
121
- private readonly endpointPath?: string,
122
- private readonly onLost?: () => void,
123
- ) {}
124
-
125
- /**
126
- * Re-read the published endpoint, and adopt it if the shell has moved.
127
- *
128
- * The bridge binds an ephemeral port and picks a NEW one whenever its server is recreated. The
129
- * endpoint file is rewritten every fifteen seconds, but a host that adopted the old one keeps
130
- * dialling a dead port forever: measured here as `connect ECONNREFUSED 127.0.0.1:52276` while
131
- * the live bridge sat on 52411. Discarding the socket is not enough — the comment below says a
132
- * dead connection must never become a dead plugin, and a stale PORT makes exactly that happen.
133
- *
134
- * Cheap and safe: one small file read per call, no socket work.
135
- *
136
- * @returns true when a different endpoint was adopted.
137
- */
138
- private refreshEndpoint(): boolean {
139
- if (this.endpointPath === undefined) return false
140
- try {
141
- const raw = JSON.parse(readFileSync(this.endpointPath, 'utf8')) as Partial<BridgeEndpoint>
142
- if (typeof raw.port !== 'number' || typeof raw.token !== 'string') return false
143
- // A shell that exited stops refreshing the file, and what it left names a port nobody owns.
144
- // Trusting it is how a host ends up dialling a dead port for the rest of the process's life
145
- // — reported as "the browser stopped working and only restarting DSH brought it back".
146
- if (endpointExpired(raw.updatedAt)) {
147
- this.notifyLost()
148
- return false
149
- }
150
- if (raw.port === this.endpoint.port && raw.token === this.endpoint.token) return false
151
- this.endpoint = {
152
- port: raw.port,
153
- token: raw.token,
154
- pid: typeof raw.pid === 'number' ? raw.pid : this.endpoint.pid,
155
- }
156
- // The old socket belongs to the old port.
157
- this.reset(new Error('dsh-builtin-browser: the bridge moved; reconnecting to the new port'))
158
- return true
159
- } catch {
160
- return false
161
- }
162
- }
163
-
164
- /** Report once that the shell is gone, so the surface can fall back instead of dialling it. */
165
- private notifyLost(): void {
166
- if (this.lostNotified) return
167
- this.lostNotified = true
168
- try {
169
- this.onLost?.()
170
- } catch {
171
- // A listener must never break the transport: the caller's error is the one that matters.
172
- }
173
- }
174
-
175
- /**
176
- * Send one request, reusing the socket if it is still healthy.
177
- *
178
- * Requests may overlap: the request is written as soon as it is queued, so two concurrent
179
- * callers have two requests in flight. Each carries a unique {@link REQUEST_ID_FIELD}, and
180
- * `onData()` resolves the entry that carries the echoed id — which is what makes
181
- * correlation independent of arrival order. A bridge that does not echo the field (the
182
- * shipped shell today) still works by arrival order; see {@link onData}.
183
- * @param request - the request body (the token and the request id are added here).
184
- * @param timeoutMs - how long to wait for the answer before dropping the socket.
185
- * @returns the bridge's answer.
186
- */
187
- async call(request: BridgeRequest, timeoutMs = 20_000): Promise<Record<string, unknown>> {
188
- // One re-dial, and only for the case this exists for: a socket that has already carried
189
- // an id-less answer cannot have a second request in flight, because two outstanding
190
- // requests would be matched by position — the swap this correlation prevents. It is a
191
- // straight-line re-dial rather than a retry loop: an earlier revision re-entered call()
192
- // from inside its own promise executor, which left an orphaned pending entry behind and,
193
- // when the condition could not clear, spun until the process ran out of heap.
194
- // Follow the shell if its bridge moved to a new port (see refreshEndpoint).
195
- this.refreshEndpoint()
196
- // The shell behind this connection is gone, and the endpoint file says so. Refusing here is
197
- // what turns a permanent ECONNREFUSED into one named error the surface can act on — by
198
- // falling back to the browser it hosts itself, instead of dialling a dead port until DSH is
199
- // restarted.
200
- if (this.lostNotified) {
201
- throw new Error(
202
- 'dsh-builtin-browser: the desktop shell that backed this browser has exited '
203
- + '(its published endpoint stopped being refreshed)',
204
- )
205
- }
206
- let socket = this.ensureSocket()
207
- if (this.serialisable && this.queue.length > 0) {
208
- this.reset(new Error('dsh-builtin-browser: bridge connection reopened so replies stay attributable'))
209
- socket = this.ensureSocket()
210
- }
211
- const id = this.nextId++
212
- return await new Promise<Record<string, unknown>>((resolve, reject) => {
213
- this.pending.set(id, {
214
- resolve: answer => { clearTimeout(timer); resolve(answer) },
215
- reject: error => { clearTimeout(timer); reject(error) },
216
- })
217
- this.queue.push(id)
218
- const timer = setTimeout(() => {
219
- const error = new Error(`dsh-builtin-browser: bridge timed out after ${timeoutMs}ms`)
220
- // An unanswered request desynchronises the stream for an id-less bridge, and leaves one
221
- // outstanding for one that echoes ids — either way the next call should start on a
222
- // fresh socket. Only when THIS request's socket is still the live one: tearing down the
223
- // REPLACEMENT because an abandoned request timed out would break whatever is using it.
224
- //
225
- // This test used to read `this.pending.has(id) && this.socket === socket`, with
226
- // `forget(id)` on the line above it — and forget() is what removes the entry that `has`
227
- // was looking for, so the condition was false every single time and the rebuild never
228
- // ran. A timed-out call therefore left the desynchronised socket in place, and every
229
- // later call inherited exactly the ambiguity this reset exists to clear. Deciding
230
- // before forgetting is the whole fix; the `else` still drops the stale entry.
231
- if (this.socket === socket) this.reset(error)
232
- else this.forget(id)
233
- // reset() already rejected this entry through its wrapper when it ran, so this is
234
- // either the only rejection or a no-op that guarantees the caller settles.
235
- reject(error)
236
- }, timeoutMs)
237
- try {
238
- // The id is added LAST so a request body can never shadow it, and the token is
239
- // added here rather than by the caller.
240
- socket.write(JSON.stringify({ token: this.endpoint.token, ...request, [REQUEST_ID_FIELD]: id }) + '\n')
241
- } catch (error) {
242
- clearTimeout(timer)
243
- this.forget(id)
244
- const failure = error instanceof Error ? error : new Error(String(error))
245
- if (this.socket === socket) this.reset(failure)
246
- reject(failure)
247
- }
248
- })
249
- }
250
-
251
- /** Close the socket and fail anything still waiting on it. */
252
- close(): void {
253
- this.reset(new Error('dsh-builtin-browser: bridge closed'))
254
- }
255
-
256
- /** The live socket, connecting and authenticating it on first use. */
257
- private ensureSocket(): Socket {
258
- if (this.socket !== undefined) return this.socket
259
- const socket = connect({ host: LOOPBACK_IPV4, port: this.endpoint.port })
260
- socket.setEncoding('utf8')
261
- socket.on('data', chunk => this.onData(String(chunk)))
262
- // Both handlers pass the socket they belong to, so a late event from a socket that was
263
- // already replaced cannot tear down its successor: 'close' still fires for a socket that
264
- // was removed mid-recycle, and acting on it there would kill a perfectly good connection.
265
- socket.on('error', error => this.socketFailed(socket, error))
266
- socket.on('close', () => this.socketFailed(socket, new Error('dsh-builtin-browser: bridge connection closed')))
267
- this.buffer = ''
268
- this.socket = socket
269
- socket.write(JSON.stringify({ token: this.endpoint.token }) + '\n')
270
- return socket
271
- }
272
-
273
- /** Tear the connection down for an event raised by `source`, unless it is already gone. */
274
- private socketFailed(source: Socket, error: Error): void {
275
- if (this.socket !== source) return
276
- this.reset(error)
277
- }
278
-
279
- /** Resolve queued requests by id, or in order when the bridge does not echo one. */
280
- private onData(chunk: string): void {
281
- this.buffer += chunk
282
- // A peer that never sends a newline must not grow this buffer without bound. Failing
283
- // the connection is the honest outcome: the caller gets an error naming the cap, while
284
- // the next call dials a fresh socket.
285
- if (this.buffer.length > MAX_BUFFER_BYTES) {
286
- this.buffer = ''
287
- this.reset(new Error(`dsh-builtin-browser: bridge reply exceeded ${String(MAX_BUFFER_BYTES)} bytes`))
288
- return
289
- }
290
- let newline = this.buffer.indexOf('\n')
291
- while (newline !== -1) {
292
- const line = this.buffer.slice(0, newline).trim()
293
- this.buffer = this.buffer.slice(newline + 1)
294
- newline = this.buffer.indexOf('\n')
295
- if (line === '') continue
296
- const echoed = echoOf(line)
297
- const id = echoed ?? this.queue[0]
298
- if (id === undefined) {
299
- // Nothing is waiting for this answer: the peer is answering something this socket
300
- // never asked (or answered twice). Drop the socket rather than trust the stream.
301
- this.reset(new Error('dsh-builtin-browser: bridge answered with no request outstanding'))
302
- return
303
- }
304
- const index = this.queue.indexOf(id)
305
- if (index !== -1) this.queue.splice(index, 1)
306
- const entry = this.pending.get(id)
307
- if (entry === undefined) continue
308
- this.pending.delete(id)
309
- // Id-less bridges pair by order, so a reply for the WRONG request cannot be told apart
310
- // from the right one. Remember that this bridge does not echo ids, and serialise every
311
- // later call so the ambiguity cannot arise again.
312
- if (echoed === undefined) {
313
- this.serialisable = true
314
- }
315
- try {
316
- const answer = JSON.parse(line) as Record<string, unknown>
317
- const packageError = bridgePackageError(answer)
318
- if (packageError !== undefined) {
319
- entry.reject(packageError)
320
- continue
321
- }
322
- // A rejected token means the shell restarted with a new one, so this socket
323
- // can never succeed again: answer (the caller needs the error) and drop it,
324
- // so the next call dials afresh instead of retrying a doomed credential.
325
- if (answer.ok === false && answer.error === 'bad token') {
326
- entry.resolve(answer)
327
- this.reset(new Error('dsh-builtin-browser: the bridge rejected our token'))
328
- continue
329
- }
330
- entry.resolve(answer)
331
- } catch (error) {
332
- entry.reject(new Error(`dsh-builtin-browser: malformed bridge answer (${String(error)})`))
333
- }
334
- }
335
- }
336
-
337
- /** Forget one request (its answer can no longer be matched). */
338
- private forget(id: number): void {
339
- this.pending.delete(id)
340
- const index = this.queue.indexOf(id)
341
- if (index !== -1) this.queue.splice(index, 1)
342
- }
343
-
344
- /** Tear the socket down, failing pending work. */
345
- private reset(error: Error): void {
346
- if (this.socket !== undefined) {
347
- const socket = this.socket
348
- this.socket = undefined
349
- socket.removeAllListeners()
350
- socket.destroy()
351
- }
352
- this.buffer = ''
353
- this.queue.length = 0
354
- const pending = [...this.pending.values()]
355
- this.pending.clear()
356
- for (const entry of pending) entry.reject(error)
357
- }
358
- }
359
-
360
- /**
361
- * Whether a published endpoint has gone un-refreshed long enough to be a tombstone.
362
- *
363
- * A missing or unparseable stamp is NOT expired: an older bridge that never wrote one must keep
364
- * working, and guessing "stale" from absence would break every shell that predates the field.
365
- * @param updatedAt - the file's own refresh stamp, when it carries one.
366
- */
367
- function endpointExpired(updatedAt: unknown): boolean {
368
- if (typeof updatedAt !== 'string') return false
369
- const at = Date.parse(updatedAt)
370
- if (!Number.isFinite(at)) return false
371
- return Date.now() - at > ENDPOINT_TTL_MS
372
- }
373
-
374
- /** The request id a raw answer line echoes back, when it carries one. */
375
- function echoOf(line: string): number | undefined {
376
- try {
377
- const answer = JSON.parse(line) as Record<string, unknown>
378
- const value = answer[REQUEST_ID_FIELD]
379
- return typeof value === 'number' && Number.isSafeInteger(value) ? value : undefined
380
- } catch {
381
- // A malformed line cannot be matched by id; the caller consumes it in order and
382
- // reports the parse failure itself.
383
- return undefined
384
- }
385
- }
@@ -1,129 +0,0 @@
1
- /**
2
- * Whether the desktop shell is RUNNING, as opposed to whether its bridge is installed.
3
- *
4
- * The two questions are constantly confused, and the confusion is the reason a user on
5
- * `channel: sidebar` sees "another window opened instead" and cannot tell why:
6
- *
7
- * - `bridge-status.ts` reads the INSTALL TREE: does the shell's main entry carry our patch, and is
8
- * the archive out of the way. It survives a reboot; it says nothing about a process.
9
- * - This module reads the ENDPOINT the shell publishes while it runs: a port, a token, a pid and a
10
- * refresh stamp. It says nothing about the install tree.
11
- *
12
- * "Installed" plus "not running" is the single most common broken state (the desktop app is simply
13
- * closed), and a readiness report that stops at the install tree calls it ready — then every call
14
- * dials a port nobody owns. So both readings are taken, and the sidebar carrier is only ready when
15
- * BOTH are true.
16
- *
17
- * Two independent signals, because each alone has a false-positive:
18
- * - the refresh stamp (the shell rewrites the file every ~15 s, so a stale stamp means a shell that
19
- * exited and left its last write behind — a tombstone naming a dead port);
20
- * - the pid, checked with signal 0 (kills nothing, and works across platforms).
21
- * @module dsh-browser/browser-electron/bridge-endpoint
22
- */
23
- import { existsSync, readFileSync, statSync } from 'node:fs'
24
-
25
- import { ENDPOINT_STALE_AFTER_MS } from './bridge-connection.ts'
26
- import { bridgeEndpointPath } from './desktop-bridge-host.ts'
27
- import { pidAlive } from './process.ts'
28
-
29
- /** What the panel needs to know about the running shell. */
30
- export interface BridgeEndpointState {
31
- /** Whether a published endpoint file exists at all. */
32
- readonly present: boolean
33
- /** Whether the shell behind it looks alive right now: a fresh stamp AND a live pid. */
34
- readonly alive: boolean
35
- /** One line, already user-facing. */
36
- readonly detail: string
37
- /** When the shell said it last refreshed the file, ISO, when the file carries a stamp. */
38
- readonly updatedAt?: string
39
- }
40
-
41
- /**
42
- * Read the endpoint the shell publishes.
43
- *
44
- * Never throws: a settings panel must get an answer even when the file is mid-write, unreadable, or
45
- * belongs to a shell that exited an hour ago.
46
- * @param path - the endpoint file; defaults to the one location the shell writes.
47
- * @param now - the clock, injected so a test can age a stamp without sleeping.
48
- * @returns what the panel shows.
49
- */
50
- export function readBridgeEndpoint(
51
- path: string = bridgeEndpointPath(),
52
- now: number = Date.now(),
53
- ): BridgeEndpointState {
54
- if (!existsSync(path)) {
55
- return {
56
- present: false,
57
- alive: false,
58
- detail: 'no desktop shell has published a bridge endpoint',
59
- }
60
- }
61
- let raw: { port?: unknown; token?: unknown; pid?: unknown; updatedAt?: unknown }
62
- try {
63
- raw = JSON.parse(readFileSync(path, 'utf8')) as typeof raw
64
- if (raw === null || typeof raw !== 'object' || Array.isArray(raw)
65
- || !Number.isInteger(raw.port) || Number(raw.port) < 1 || Number(raw.port) > 65535
66
- || typeof raw.token !== 'string' || raw.token.trim() === ''
67
- || !Number.isSafeInteger(raw.pid) || Number(raw.pid) <= 0
68
- || (raw.updatedAt !== undefined && (typeof raw.updatedAt !== 'string' || !Number.isFinite(Date.parse(raw.updatedAt))))) {
69
- throw new Error('expected a port, a nonempty token, a positive pid and an optional timestamp')
70
- }
71
- } catch (error) {
72
- return {
73
- present: true,
74
- alive: false,
75
- detail: `the published endpoint is unreadable: ${String(error)}`,
76
- }
77
- }
78
- const updatedAt = typeof raw.updatedAt === 'string' ? raw.updatedAt : undefined
79
- const pid = typeof raw.pid === 'number' ? raw.pid : undefined
80
-
81
- // A stamp older than the refresh window is a tombstone, not a slow shell (see
82
- // ENDPOINT_STALE_AFTER_MS). An ABSENT stamp is not expired on purpose: an older bridge never wrote
83
- // one, and that shell deserves to be checked by its pid instead of being declared gone.
84
- if (updatedAt !== undefined) {
85
- const at = Date.parse(updatedAt)
86
- if (Number.isFinite(at)) {
87
- const ageMs = now - at
88
- if (ageMs > ENDPOINT_STALE_AFTER_MS) {
89
- return {
90
- present: true,
91
- alive: false,
92
- updatedAt,
93
- detail: `the published endpoint has not been refreshed for ${Math.round(ageMs / 1000)}s, `
94
- + 'so the shell that wrote it has most likely exited',
95
- }
96
- }
97
- }
98
- }
99
- if (pid !== undefined && !pidAlive(pid)) {
100
- return {
101
- present: true,
102
- alive: false,
103
- ...updatedAt === undefined ? {} : { updatedAt },
104
- detail: `the shell that published the endpoint (pid ${pid}) is not running`,
105
- }
106
- }
107
- return {
108
- present: true,
109
- alive: true,
110
- ...updatedAt === undefined ? {} : { updatedAt },
111
- detail: 'a desktop shell is running and answering on its published endpoint',
112
- }
113
- }
114
-
115
- /**
116
- * The endpoint file's mtime, for diagnostics that want to say "written at".
117
- *
118
- * Separate and optional: the readiness report does not need it, and a caller that does can fail
119
- * without disturbing anything else.
120
- * @param path - the endpoint file.
121
- * @returns the mtime as ISO, or undefined.
122
- */
123
- export function bridgeEndpointWrittenAt(path: string = bridgeEndpointPath()): string | undefined {
124
- try {
125
- return statSync(path).mtime.toISOString()
126
- } catch {
127
- return undefined
128
- }
129
- }