dsh-builtin-browser 0.5.8 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (401) hide show
  1. package/CHANGELOG.md +410 -1
  2. package/README.en.md +16 -64
  3. package/README.md +33 -64
  4. package/assets/browser-carriers.svg +20 -0
  5. package/assets/browser-extension-identity.d.mts +2 -0
  6. package/assets/browser-extension-identity.mjs +2 -0
  7. package/assets/browser-messages.d.mts +5 -0
  8. package/assets/browser-messages.mjs +64 -0
  9. package/assets/browser-panel-locales.d.mts +2 -0
  10. package/assets/browser-panel-locales.mjs +380 -0
  11. package/assets/browser-policy.d.mts +37 -0
  12. package/assets/browser-policy.mjs +37 -0
  13. package/assets/browser-products.d.mts +6 -0
  14. package/assets/browser-products.mjs +76 -0
  15. package/assets/screenshots/1-main.png +0 -0
  16. package/assets/screenshots/2-form-fill.png +0 -0
  17. package/assets/screenshots/3-challenge.png +0 -0
  18. package/browser-extension/constants.mjs +20 -0
  19. package/browser-extension/controller.mjs +293 -0
  20. package/browser-extension/locales.mjs +15 -0
  21. package/browser-extension/manifest.json +12 -0
  22. package/browser-extension/options.html +14 -0
  23. package/browser-extension/options.mjs +9 -0
  24. package/browser-extension/permission-guard.mjs +13 -0
  25. package/browser-extension/worker.mjs +74 -0
  26. package/cordis.patch.yml +23 -48
  27. package/desktop-bridge/desktop-discovery.d.mts +2 -0
  28. package/desktop-bridge/desktop-discovery.mjs +36 -0
  29. package/desktop-bridge/desktop-identity.json +17 -1
  30. package/desktop-bridge/desktop-processes.d.mts +1 -0
  31. package/desktop-bridge/desktop-processes.mjs +15 -0
  32. package/desktop-bridge/guest-proxy.mjs +109 -0
  33. package/desktop-bridge/install.mjs +197 -74
  34. package/desktop-bridge/main.mjs +11 -0
  35. package/desktop-bridge/maintenance-files.d.mts +8 -0
  36. package/desktop-bridge/maintenance-files.mjs +28 -0
  37. package/desktop-bridge/maintenance-progress.ps1 +2 -2
  38. package/desktop-bridge/native-guests.mjs +41 -0
  39. package/desktop-bridge/plugin-browser-bridge.js +618 -370
  40. package/desktop-bridge/profile-loader.mjs +26 -0
  41. package/dist/client.cjs +43167 -0
  42. package/dist/client.d.cts +516 -0
  43. package/dist/client.d.mts +516 -0
  44. package/dist/index.cjs +92 -0
  45. package/dist/index.d.mts +2960 -0
  46. package/dist/index.mjs +24 -0
  47. package/docs/HANDOVER-2026-11-15.md +178 -0
  48. package/docs/README.md +10 -19
  49. package/docs/architecture.md +17 -145
  50. package/docs/child-tabs.md +13 -0
  51. package/docs/desktop-acceptance.md +9 -0
  52. package/docs/development.md +88 -18
  53. package/docs/extension-browser.md +44 -0
  54. package/docs/hardcoding-audit.md +64 -0
  55. package/docs/limitations.md +23 -73
  56. package/docs/pr64-extension-status.md +46 -0
  57. package/docs/pr64-maintenance.md +25 -0
  58. package/docs/pr64-native-children.md +52 -0
  59. package/docs/pr64-native-views.md +60 -0
  60. package/docs/tool-reference.md +87 -11
  61. package/docs/user-guide.md +47 -255
  62. package/docs/why-browser.md +6 -39
  63. package/dsh-host-patch/README.md +60 -0
  64. package/dsh-host-patch/apply.mjs +194 -0
  65. package/dsh-host-patch/legacy-bridge.mjs +53 -0
  66. package/dsh-host-patch/rc3-revision1.json +90 -0
  67. package/dsh-host-patch/rc3-revision2.json +112 -0
  68. package/dsh-host-patch/rc3-revision3.json.gz +0 -0
  69. package/dsh-host-patch/rc3-revision4.json.gz +0 -0
  70. package/dsh-host-patch/rc3-revision5.json.gz +0 -0
  71. package/dsh-host-patch/rc3-revision6.json.gz +0 -0
  72. package/dsh-host-patch/rc3-revision7.json.gz +0 -0
  73. package/dsh-host-patch/rc3-revision8.json.gz +0 -0
  74. package/dsh-host-patch/rc3.json +148 -0
  75. package/dsh-host-patch/rc5-revision1.json +90 -0
  76. package/dsh-host-patch/rc5-revision2.json +112 -0
  77. package/dsh-host-patch/rc5-revision3.json.gz +0 -0
  78. package/dsh-host-patch/rc5-revision4.json.gz +0 -0
  79. package/dsh-host-patch/rc5-revision5.json.gz +0 -0
  80. package/dsh-host-patch/rc5-revision6.json.gz +0 -0
  81. package/dsh-host-patch/rc5-revision7.json.gz +0 -0
  82. package/dsh-host-patch/rc5-revision8.json.gz +0 -0
  83. package/dsh-host-patch/rc5.json +148 -0
  84. package/lib/bridge-compatibility.js +38 -0
  85. package/lib/browser/handles.js +78 -0
  86. package/lib/browser/runtime.js +155 -43
  87. package/lib/browser/takeover-target.js +24 -0
  88. package/lib/browser-electron/authenticated-route.js +23 -0
  89. package/lib/browser-electron/automatic-maintenance.js +394 -51
  90. package/lib/browser-electron/bridge-auto.js +2 -1
  91. package/lib/browser-electron/bridge-connection.js +8 -1
  92. package/lib/browser-electron/bridge-install.js +27 -2
  93. package/lib/browser-electron/bridge-maintenance.js +35 -10
  94. package/lib/browser-electron/bridge-status.js +98 -27
  95. package/lib/browser-electron/desktop-bridge-host.js +193 -560
  96. package/lib/browser-electron/desktop-identity.js +40 -2
  97. package/lib/browser-electron/document-readiness.js +34 -0
  98. package/lib/browser-electron/electron-provision.js +14 -44
  99. package/lib/browser-electron/entry.js +659 -252
  100. package/lib/browser-electron/extension-browser.js +234 -0
  101. package/lib/browser-electron/extension-setup.js +69 -0
  102. package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
  103. package/lib/browser-electron/guest-cookie-jar.js +10559 -0
  104. package/lib/browser-electron/guest-cookie-store.js +74 -0
  105. package/lib/browser-electron/guest-css-runtime.js +75 -0
  106. package/lib/browser-electron/guest-css.js +106 -0
  107. package/lib/browser-electron/guest-route.js +603 -0
  108. package/lib/browser-electron/guest-runtime.js +356 -0
  109. package/lib/browser-electron/guest-storage-runtime.js +52 -0
  110. package/lib/browser-electron/guest-storage.js +163 -0
  111. package/lib/browser-electron/history-store.js +2 -1
  112. package/lib/browser-electron/host-main.js +162 -7
  113. package/lib/browser-electron/host-patch-maintenance.js +141 -0
  114. package/lib/browser-electron/http-body.js +22 -0
  115. package/lib/browser-electron/maintenance-broker.js +35 -5
  116. package/lib/browser-electron/maintenance-lifecycle.js +7 -5
  117. package/lib/browser-electron/maintenance-route.js +9 -6
  118. package/lib/browser-electron/open-slot.js +47 -0
  119. package/lib/browser-electron/paths.js +4 -1
  120. package/lib/browser-electron/preferred-browser.js +144 -0
  121. package/lib/browser-electron/preview-route.js +11 -8
  122. package/lib/browser-electron/process-ownership.js +198 -0
  123. package/lib/browser-electron/profile-checkpoint.js +222 -0
  124. package/lib/browser-electron/profile-command.js +60 -0
  125. package/lib/browser-electron/profile-extension.js +126 -0
  126. package/lib/browser-electron/profile-lease.js +157 -0
  127. package/lib/browser-electron/profile-residue.js +61 -0
  128. package/lib/browser-electron/provider.js +719 -262
  129. package/lib/browser-electron/reference-route.js +635 -0
  130. package/lib/browser-electron/remote-host.js +12 -13
  131. package/lib/browser-electron/runtime-route.js +6 -5
  132. package/lib/browser-electron/runtime-status.js +30 -29
  133. package/lib/browser-electron/settings-store.js +10 -5
  134. package/lib/browser-electron/shortcuts-route.js +108 -0
  135. package/lib/browser-electron/sidebar-only-host.js +119 -18
  136. package/lib/browser-electron/startpage-shortcuts.js +172 -0
  137. package/lib/browser-electron/system-browser.js +352 -371
  138. package/lib/browser-electron/windows-system.js +2 -1
  139. package/lib/browser-reference/delivery.js +326 -0
  140. package/lib/browser-reference/entry.js +597 -0
  141. package/lib/browser-reference/export.js +298 -0
  142. package/lib/browser-reference/import.js +295 -0
  143. package/lib/browser-reference/page-script.js +1406 -0
  144. package/lib/browser-reference/service.js +1062 -0
  145. package/lib/browser-reference/store.js +177 -0
  146. package/lib/browser-reference/submission-receipts.js +139 -0
  147. package/lib/browser-reference/text-quote.js +167 -0
  148. package/lib/browser-reference/types.js +11 -0
  149. package/lib/browser-reference/visible.js +311 -0
  150. package/lib/browser-reference/web-sources.js +97 -0
  151. package/lib/index.js +10 -3
  152. package/lib/reference-owner.js +5 -0
  153. package/lib/reference-page.js +12 -0
  154. package/lib/reference-source.js +2 -0
  155. package/lib/reference-text.js +188 -0
  156. package/lib/startpage-settings.js +63 -0
  157. package/lib/startpage.js +44 -0
  158. package/lib/takeover-protocol.js +2 -0
  159. package/lib/tool-browser/code-tool.js +416 -0
  160. package/lib/tool-browser/code-worker.js +872 -0
  161. package/lib/tool-browser/index.js +940 -76
  162. package/lib/tool-browser/page-probe.js +3 -3
  163. package/lib/tool-browser/panel-page.js +95 -0
  164. package/lib/tool-browser/screenshot-image.js +51 -0
  165. package/lib/tool-browser/takeover.js +205 -0
  166. package/lib/types.js +1 -0
  167. package/lib/web-guest.js +26 -0
  168. package/native-host/client.d.mts +17 -0
  169. package/native-host/client.mjs +100 -0
  170. package/native-host/host.mjs +150 -0
  171. package/native-host/identity.d.mts +2 -0
  172. package/native-host/identity.mjs +1 -0
  173. package/native-host/install.mjs +168 -0
  174. package/native-host/protocol.mjs +75 -0
  175. package/package.json +80 -92
  176. package/scripts/build.mjs +66 -0
  177. package/scripts/bundle-host.mjs +28 -0
  178. package/scripts/fix-exports.mjs +50 -0
  179. package/scripts/install-electron.mjs +11 -26
  180. package/scripts/verify-exports.mjs +47 -0
  181. package/scripts/verify-preview-sdk.mjs +93 -0
  182. package/skills/dsh-builtin-browser/SKILL.md +56 -47
  183. package/skills/dsh-builtin-browser/references/batch.md +31 -1
  184. package/skills/dsh-debug-host/SKILL.md +56 -0
  185. package/skills/dsh-debug-self/SKILL.md +50 -0
  186. package/src/bridge-compatibility.ts +39 -0
  187. package/src/browser/handles.ts +89 -0
  188. package/src/browser/runtime.ts +146 -50
  189. package/src/browser/takeover-target.ts +36 -0
  190. package/src/browser/types.ts +19 -7
  191. package/src/browser-electron/authenticated-route.ts +29 -1
  192. package/src/browser-electron/automatic-maintenance.ts +368 -56
  193. package/src/browser-electron/bridge-auto.ts +5 -4
  194. package/src/browser-electron/bridge-connection.ts +20 -2
  195. package/src/browser-electron/bridge-endpoint.ts +3 -3
  196. package/src/browser-electron/bridge-install.ts +40 -4
  197. package/src/browser-electron/bridge-maintenance.ts +42 -14
  198. package/src/browser-electron/bridge-status.ts +94 -23
  199. package/src/browser-electron/desktop-bridge-host.ts +185 -585
  200. package/src/browser-electron/desktop-identity.ts +53 -2
  201. package/src/browser-electron/document-readiness.ts +45 -0
  202. package/src/browser-electron/electron-provision.ts +12 -45
  203. package/src/browser-electron/entry.ts +1299 -882
  204. package/src/browser-electron/ephemeral-profile.ts +1 -1
  205. package/src/browser-electron/extension-browser.ts +223 -0
  206. package/src/browser-electron/extension-setup.ts +67 -0
  207. package/src/browser-electron/guest-cookie-jar.ts +176 -0
  208. package/src/browser-electron/guest-cookie-store.ts +59 -0
  209. package/src/browser-electron/guest-css-runtime.ts +76 -0
  210. package/src/browser-electron/guest-css.ts +68 -0
  211. package/src/browser-electron/guest-route.ts +568 -0
  212. package/src/browser-electron/guest-runtime.ts +357 -0
  213. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  214. package/src/browser-electron/guest-storage.ts +117 -0
  215. package/src/browser-electron/history-store.ts +5 -4
  216. package/src/browser-electron/host-main.ts +156 -11
  217. package/src/browser-electron/host-patch-maintenance.ts +112 -0
  218. package/src/browser-electron/http-body.ts +23 -0
  219. package/src/browser-electron/maintenance-broker.ts +29 -5
  220. package/src/browser-electron/maintenance-lifecycle.ts +14 -9
  221. package/src/browser-electron/maintenance-route.ts +17 -14
  222. package/src/browser-electron/missing-system-browser.ts +2 -2
  223. package/src/browser-electron/open-slot.ts +49 -0
  224. package/src/browser-electron/paths.ts +5 -1
  225. package/src/browser-electron/preferred-browser.ts +120 -0
  226. package/src/browser-electron/preview-route.ts +18 -11
  227. package/src/browser-electron/process-ownership.ts +168 -0
  228. package/src/browser-electron/profile-checkpoint.ts +187 -0
  229. package/src/browser-electron/profile-command.ts +46 -0
  230. package/src/browser-electron/profile-extension.ts +124 -0
  231. package/src/browser-electron/profile-lease.ts +115 -0
  232. package/src/browser-electron/profile-residue.ts +49 -0
  233. package/src/browser-electron/provider.ts +771 -289
  234. package/src/browser-electron/reference-route.ts +608 -0
  235. package/src/browser-electron/remote-host.ts +15 -15
  236. package/src/browser-electron/runtime-route.ts +11 -10
  237. package/src/browser-electron/runtime-status.ts +51 -32
  238. package/src/browser-electron/settings-store.ts +27 -7
  239. package/src/browser-electron/shortcuts-route.ts +112 -0
  240. package/src/browser-electron/sidebar-only-host.ts +118 -19
  241. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  242. package/src/browser-electron/system-browser.ts +309 -338
  243. package/src/browser-electron/windows-system.ts +2 -1
  244. package/src/browser-reference/delivery.ts +384 -0
  245. package/src/browser-reference/entry.ts +631 -0
  246. package/src/browser-reference/export.ts +339 -0
  247. package/src/browser-reference/import.ts +303 -0
  248. package/src/browser-reference/page-script.ts +1537 -0
  249. package/src/browser-reference/service.ts +1315 -0
  250. package/src/browser-reference/store.ts +172 -0
  251. package/src/browser-reference/submission-receipts.ts +122 -0
  252. package/src/browser-reference/text-quote.ts +219 -0
  253. package/src/browser-reference/types.ts +195 -0
  254. package/src/browser-reference/visible.ts +367 -0
  255. package/src/browser-reference/web-sources.ts +103 -0
  256. package/src/client/browser/BrowserController.ts +693 -0
  257. package/src/client/browser/BrowserFrame.ts +78 -0
  258. package/src/client/browser/BrowserNavigation.ts +169 -0
  259. package/src/client/browser/BrowserPage.ts +23 -0
  260. package/src/client/browser/BrowserPersistence.ts +44 -0
  261. package/src/client/browser/IframeImpl.ts +176 -0
  262. package/src/client/browser/child-tabs.ts +14 -0
  263. package/src/client/browser/iframe-reference.ts +67 -0
  264. package/src/client/browser/initialization.ts +262 -0
  265. package/src/client/browser/omnibox.ts +243 -0
  266. package/src/client/browser/store.ts +38 -0
  267. package/src/client/browser/takeover-channel.ts +72 -0
  268. package/src/client/browser/url.ts +46 -0
  269. package/src/client/browser/web-reference-source.ts +52 -0
  270. package/src/client/css-modules.d.ts +4 -0
  271. package/src/client/definition.tsx +30 -0
  272. package/src/client/electron/ElectronWebViewImpl.ts +364 -0
  273. package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
  274. package/src/client/electron/NativeChildPresentation.ts +45 -0
  275. package/src/client/electron/NativeViewPage.ts +251 -0
  276. package/src/client/electron/pages.ts +23 -0
  277. package/src/client/electron/reference-overlay.ts +53 -0
  278. package/src/client/electron/workspace.ts +33 -0
  279. package/src/client/index.ts +293 -0
  280. package/src/client/locales.ts +857 -0
  281. package/src/client/pages.ts +28 -0
  282. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  283. package/src/client/reference/client/draft-reference.ts +167 -0
  284. package/src/client/reference/client/index.ts +7 -0
  285. package/src/client/reference/client/ordered-submission.ts +108 -0
  286. package/src/client/reference/client/pending-delivery.ts +216 -0
  287. package/src/client/reference/client/plugin.ts +189 -0
  288. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  289. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  290. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  291. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  292. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  293. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  294. package/src/client/reference/client/production/assembly.ts +471 -0
  295. package/src/client/reference/client/production/asset-store.ts +144 -0
  296. package/src/client/reference/client/production/availability.ts +74 -0
  297. package/src/client/reference/client/production/bytes.ts +36 -0
  298. package/src/client/reference/client/production/delivery-client.ts +211 -0
  299. package/src/client/reference/client/production/draft-adapter.ts +508 -0
  300. package/src/client/reference/client/production/http-transport.ts +217 -0
  301. package/src/client/reference/client/production/production-submission.ts +310 -0
  302. package/src/client/reference/client/production/protocol.ts +231 -0
  303. package/src/client/reference/client/production/reference-card.ts +240 -0
  304. package/src/client/reference/client/production/reference-labels.ts +29 -0
  305. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  306. package/src/client/reference/client/production/reveal.ts +215 -0
  307. package/src/client/reference/client/production/runtime.ts +1101 -0
  308. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  309. package/src/client/reference/client/production/source-marker.ts +63 -0
  310. package/src/client/reference/client/production/source-opener.ts +55 -0
  311. package/src/client/reference/client/production/styles.ts +104 -0
  312. package/src/client/reference/client/production/user-text-rule.ts +58 -0
  313. package/src/client/reference/client/reveal.ts +107 -0
  314. package/src/client/reference/client/scheme.ts +114 -0
  315. package/src/client/reference/client/types.ts +168 -0
  316. package/src/client/reference/css-modules.d.ts +4 -0
  317. package/src/client/reference/index.ts +11 -0
  318. package/src/client/reference-capture-owner.ts +162 -0
  319. package/src/client/reference-intents.ts +36 -0
  320. package/src/client/settings/index.ts +34 -0
  321. package/{client.js → src/client/settings/panel.ts} +2657 -2231
  322. package/src/client/shortcut-open.ts +30 -0
  323. package/src/client/startpage/binding.ts +99 -0
  324. package/src/client/startpage/controller.ts +303 -0
  325. package/src/client/startpage/model.ts +279 -0
  326. package/src/client/view/Browser.module.css +751 -0
  327. package/src/client/view/BrowserBody.tsx +314 -0
  328. package/src/client/view/BrowserPresentation.ts +9 -0
  329. package/src/client/view/BrowserTitle.tsx +17 -0
  330. package/src/client/view/IframePresentation.ts +344 -0
  331. package/src/client/view/StartPage.tsx +597 -0
  332. package/src/client/view/TakeoverBanner.tsx +21 -0
  333. package/src/index.ts +110 -73
  334. package/src/reference-owner.ts +5 -0
  335. package/src/reference-page.ts +9 -0
  336. package/src/reference-source.ts +3 -0
  337. package/src/reference-text.ts +197 -0
  338. package/src/startpage-settings.ts +103 -0
  339. package/src/startpage.ts +71 -0
  340. package/src/takeover-protocol.ts +19 -0
  341. package/src/tool-browser/code-tool.ts +401 -0
  342. package/src/tool-browser/code-worker.ts +639 -0
  343. package/src/tool-browser/index.ts +908 -77
  344. package/src/tool-browser/page-probe.ts +4 -4
  345. package/src/tool-browser/panel-page.ts +124 -0
  346. package/src/tool-browser/screenshot-image.ts +49 -0
  347. package/src/tool-browser/takeover.ts +198 -0
  348. package/src/types/electron-shim.d.ts +20 -0
  349. package/src/types.ts +85 -0
  350. package/src/web-guest.ts +34 -0
  351. package/tools/accept-desktop.mjs +148 -0
  352. package/lib/browser/runtime.d.ts +0 -175
  353. package/lib/browser/types.d.ts +0 -797
  354. package/lib/browser-electron/authenticated-route.d.ts +0 -27
  355. package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
  356. package/lib/browser-electron/bridge-auto.d.ts +0 -93
  357. package/lib/browser-electron/bridge-connection.d.ts +0 -93
  358. package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
  359. package/lib/browser-electron/bridge-install.d.ts +0 -85
  360. package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
  361. package/lib/browser-electron/bridge-status.d.ts +0 -50
  362. package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
  363. package/lib/browser-electron/desktop-identity.d.ts +0 -58
  364. package/lib/browser-electron/electron-provision.d.ts +0 -92
  365. package/lib/browser-electron/entry.d.ts +0 -64
  366. package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
  367. package/lib/browser-electron/file-write.d.ts +0 -2
  368. package/lib/browser-electron/history-store.d.ts +0 -98
  369. package/lib/browser-electron/host-main.d.ts +0 -26
  370. package/lib/browser-electron/http-body.d.ts +0 -24
  371. package/lib/browser-electron/json-reply.d.ts +0 -33
  372. package/lib/browser-electron/maintenance-broker.d.ts +0 -35
  373. package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
  374. package/lib/browser-electron/maintenance-route.d.ts +0 -18
  375. package/lib/browser-electron/missing-system-browser.d.ts +0 -54
  376. package/lib/browser-electron/paths.d.ts +0 -4
  377. package/lib/browser-electron/preview-route.d.ts +0 -89
  378. package/lib/browser-electron/process.d.ts +0 -14
  379. package/lib/browser-electron/provider.d.ts +0 -959
  380. package/lib/browser-electron/remote-host.d.ts +0 -256
  381. package/lib/browser-electron/rpc-input.d.ts +0 -4
  382. package/lib/browser-electron/rpc-ops.d.ts +0 -18
  383. package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
  384. package/lib/browser-electron/runtime-route.d.ts +0 -55
  385. package/lib/browser-electron/runtime-status.d.ts +0 -116
  386. package/lib/browser-electron/settings-route.d.ts +0 -15
  387. package/lib/browser-electron/settings-store.d.ts +0 -224
  388. package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
  389. package/lib/browser-electron/system-browser.d.ts +0 -367
  390. package/lib/browser-electron/timing.d.ts +0 -8
  391. package/lib/browser-electron/virtual-cursor.d.ts +0 -67
  392. package/lib/browser-electron/windows-system.d.ts +0 -3
  393. package/lib/index.d.ts +0 -30
  394. package/lib/tool-browser/element-fields.d.ts +0 -145
  395. package/lib/tool-browser/index.d.ts +0 -53
  396. package/lib/tool-browser/page-probe.d.ts +0 -86
  397. package/scripts/consumer-install-check.mjs +0 -72
  398. package/scripts/run-tests.mjs +0 -32
  399. package/scripts/verify-host-compat.mjs +0 -195
  400. package/scripts/verify-preview-route.mjs +0 -168
  401. package/scripts/verify-runtime-status.mjs +0 -179
@@ -1,651 +1,251 @@
1
- /**
2
- * Desktop-sidebar browser host: drive the page the desktop shell shows in its
3
- * sidebar, instead of spawning a second, parallel Electron window.
4
- *
5
- * WHY
6
- * The plugin runs inside the desktop's Node-mode host, where there is no Electron
7
- * API — which is why it self-hosts a whole browser today. The shell, however, can
8
- * own views, and its sidebar already displays real web pages. This host borrows
9
- * that page over the shell's bridge (see apps/desktop/bridge/plugin-browser-bridge.js),
10
- * so the agent and the human end up on ONE page instead of two.
11
- *
12
- * CONTRACT
13
- * It implements the same `ElectronBrowserViewHost` seam the self-hosted host does,
14
- * so the provider, the tools, browsing history, the synthetic cursor and the
15
- * teardown rules are all unchanged: only the carrier differs. Everything is
16
- * lazily materialized — a fresh shell has no sidebar guest until something asks
17
- * for a page, and the bridge creates one on demand.
18
- *
19
- * FALLBACK
20
- * `discover()` returns undefined whenever the shell offers no usable bridge
21
- * (older desktop build, plain `dsh web`, bridge not started), and the entry point
22
- * then keeps the self-hosted Electron it has always used.
23
- * @module dsh-browser/browser-electron/desktop-bridge-host
24
- */
25
-
26
- import { BridgeConnection, type BridgeEndpoint } from './bridge-connection.js'
1
+ /** Drive the visible sidebar guest through canonical, bridge-bound handles. */
2
+ import { BridgeConnection, type BridgeEndpoint } from './bridge-connection.ts'
27
3
  import { readFileSync } from 'node:fs'
28
- import { bridgeEndpointPath } from './paths.js'
4
+ import { bridgeEndpointPath } from './paths.ts'
29
5
  import { randomUUID } from 'node:crypto'
30
- import type { CommandOptions, ElectronBrowserViewHost, ElectronViewHandle } from './provider.js'
31
- import type { BrowserUserAction } from './provider.js'
32
- import type { CarrierPage, CarrierLossReason } from '../browser/types.js'
33
-
6
+ import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId, tabWireId, type BrowserSessionWireId, type BrowserTabWireId } from '../browser/handles.ts'
7
+ import type { CommandOptions, ElectronBrowserViewHost, ElectronViewHandle, BrowserUserAction } from './provider.ts'
8
+ import type { CarrierPage, CarrierLossReason } from '../browser/types.ts'
9
+ import { BridgeVersionError, bridgePackageError, isBridgeVersionMismatch } from '../bridge-compatibility.ts'
34
10
 
35
- /** Absolute path of the endpoint file the shell writes. */
36
11
  export { bridgeEndpointPath }
37
12
 
38
- /**
39
- * The error code the bridge uses when the conversation's panel exists but the shell is not showing
40
- * that conversation, so no webview has attached yet (issue #37).
41
- *
42
- * A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
43
- * retried as though a guest had vanished: retrying cannot attach a webview the shell has not
44
- * rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
45
- * blank — losing the page the user had open.
46
- */
47
13
  const PANEL_NOT_DISPLAYED = 'panel-not-displayed'
48
14
  const PANEL_INITIALIZING = 'panel-initializing'
49
15
 
50
- /**
51
- * How many times a display-state refusal is retried, and how long each retry waits.
52
- *
53
- * The retry exists because the same call now asks the shell to SHOW the conversation (the client
54
- * half's `openSession` step). React renders that on the next pass, so the refusal the first call
55
- * sees is true-but-stale. 4 x 400 ms is ~1.6 s: long enough for a render on a busy conversation,
56
- * short enough that a shell which genuinely cannot render a panel still fails inside one tool call
57
- * instead of stalling for the bridge's own 20 s budget.
58
- */
59
- const PANEL_DISPLAY_RETRIES = 4
60
- const PANEL_DISPLAY_RETRY_MS = 400
61
-
62
- /**
63
- * A failure worth showing as-is: the carrier is alive and this is a condition the shell can change.
64
- *
65
- * Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
66
- * browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
67
- * waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
68
- * this host retries while it renders — so reaching here means the shell did not render it at all.
69
- */
70
16
  export class BrowserPanelNotDisplayedError extends Error {
71
17
  readonly code: string
72
-
73
- /**
74
- * @param detail - the bridge's own explanation, appended so the message says why.
75
- */
76
18
  constructor(detail: string, code = PANEL_NOT_DISPLAYED) {
77
- super(
78
- 'dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
79
- + 'show this conversation and its panel still did not render. Nothing was lost, and the page '
80
- + 'appears as soon as the panel mounts. '
81
- + `(${detail})`,
82
- )
19
+ super(`dsh-builtin-browser: this conversation's sidebar page did not attach (${detail})`)
83
20
  this.name = 'BrowserPanelNotDisplayedError'
84
21
  this.code = code
85
22
  }
86
23
  }
87
24
 
88
- /**
89
- * Whether a command failed because the page is no longer there (as opposed to
90
- * failing on its own merits). Only these are worth retrying on a fresh guest.
91
- * @param error - the failure to classify.
92
- */
93
- function isGuestGone(error: unknown): boolean {
94
- // "The conversation is not displayed" is NOT a vanished guest. It is listed here as a negative
95
- // because retrying it wastes the only thing it can produce: the same answer, slower. Issue #37 was
96
- // this classification being too broad.
97
- if (error instanceof BrowserPanelNotDisplayedError) return false
98
- const message = error instanceof Error ? error.message : String(error)
99
- // The panel path reports its own failure when the renderer never produced a page, and that is the
100
- // same class as a vanished guest — worth one retry on a fresh panel — so it is listed here too.
101
- return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message)
25
+ interface View {
26
+ readonly scope: BrowserSessionWireId
27
+ bound: boolean
28
+ adopted?: boolean
102
29
  }
103
30
 
104
- /**
105
- * The desktop sidebar, presented as a browser view host.
106
- *
107
- * One sidebar exists per shell window, so every view this host hands out refers
108
- * to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
109
- * share the visible page. That is the intended behaviour for this carrier — the
110
- * point is a single page both parties can see.
111
- */
112
31
  export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
32
+ readonly referenceOverlayOwner = 'client' as const
113
33
  private readonly connection: BridgeConnection
114
- /**
115
- * One entry per view this host handed out: the conversation it serves, and the guest backing it.
116
- *
117
- * The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
118
- * conversation — DSH runs them all through one host instance — so an owner held on the host
119
- * would be one conversation's id applied to all of them, and a page could still land in
120
- * another's sidebar however carefully the bridge checked it.
121
- */
122
- private readonly views = new Map<string, { guest?: number; owner: string }>()
123
- /**
124
- * This process's identity with the bridge, for tab ownership.
125
- *
126
- * Every DSH session is its own plugin process, and the sidebar is one surface they all share.
127
- * A session can only see its own `views` map, so before the bridge kept a ledger it adopted
128
- * whichever tab it found — including one another session had opened, which is how a URL from
129
- * one session appeared in another's sidebar. The id is per process, so two sessions never
130
- * collide and one session's tabs are never handed to another; it is deliberately not the DSH
131
- * session id, which this layer has no access to and does not need.
132
- *
133
- * The whole ledger rests on that premise, so it was measured rather than assumed: with two
134
- * sessions running, the desktop had TWO host processes (plus one main, two renderers and a
135
- * gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
136
- * compare equal and the bleed would return in a new shape — so a change to how DSH spawns
137
- * sessions invalidates this file, not just this comment.
138
- *
139
- * It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
140
- * same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
141
- * conversation and writes its session id onto each sidebar container (on the React fiber,
142
- * measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
143
- * a comparable id. With an invented uuid it never could, which is how a command came to be typed
144
- * into another conversation's address bar.
145
- *
146
- * Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
147
- * composition. That is no worse than before: the bridge then knows only "this process", and it
148
- * refuses to operate on a sidebar it cannot prove is its own.
149
- */
150
- private readonly owner: string
151
- /**
152
- * Guests whose view is gone but whose page may still be open in the sidebar, with the
153
- * conversation each belongs to.
154
- *
155
- * The provider destroys its view handles before it asks for a release, so the mapping is dropped
156
- * by then — keeping the guest ids here is what lets us close only our own tabs when several
157
- * conversations are running (requirements 搂4: each session gets its own page). The owner rides
158
- * along for the same reason it does in {@link views}: a release names one conversation.
159
- */
160
- private readonly orphaned = new Map<number, string>()
161
- /**
162
- * Registered by the provider, and deliberately never invoked on this carrier.
163
- *
164
- * The sidebar is the shell's own interface: a human clicking inside that page is an
165
- * event the shell owns, and the bridge exposes no operation that reports it. The
166
- * handler is stored anyway so the interface contract holds (a caller may register
167
- * one and must not be surprised) and so a future bridge operation can deliver it
168
- * without changing the provider. Consequently no user-action event is emitted while
169
- * the desktop sidebar is the carrier — by design, not by omission.
170
- */
171
- private userActionHandler: ((action: BrowserUserAction) => void) | undefined
172
- /** Told when the shell behind this bridge exits; see `onLost`. */
34
+ private readonly views = new Map<string, View>()
35
+ private readonly orphaned = new Map<BrowserTabWireId, BrowserSessionWireId>()
36
+ private activeScope: BrowserSessionWireId | undefined
37
+ private readonly retiredSessions = new Set<BrowserSessionWireId>()
173
38
  private lostListener: ((reason: CarrierLossReason) => void) | undefined
39
+ private static refuseIframe = false
40
+ private static versionError: string | undefined
174
41
 
175
- /**
176
- * @param endpoint - the shell's published bridge endpoint.
177
- */
178
- private constructor(endpoint: BridgeEndpoint, sessionId?: string, private readonly _isQuiet: () => boolean = () => false,
179
- private readonly protocol = 2) {
180
- this.owner = sessionId !== undefined && sessionId !== String.fromCharCode(39,39) ? sessionId : randomUUID()
181
- // The transport reaches this only by concluding the shell stopped refreshing its endpoint, which
182
- // is `shell-exited`.
183
- this.connection = new BridgeConnection(endpoint, bridgeEndpointPath(), () => this.reportLost('shell-exited'))
42
+ private constructor(endpoint: BridgeEndpoint, private readonly isQuiet: () => boolean = () => false) {
43
+ this.connection = new BridgeConnection(endpoint, bridgeEndpointPath(), () => this.lostListener?.('shell-exited'))
184
44
  }
185
45
 
186
- /**
187
- * Called when this carrier concludes it cannot serve anything more.
188
- *
189
- * Forwarded rather than acted on here: only the entry point owns the swap back to the self-hosted
190
- * browser, and a host that tried to replace itself would be reaching outside its own contract.
191
- * @param reason - which failure this was, so the fallback can say so accurately.
192
- */
193
- private reportLost(reason: CarrierLossReason): void {
194
- try {
195
- this.lostListener?.(reason)
196
- } catch {
197
- // The listener's failure is not the transport's problem.
198
- }
199
- }
46
+ onLost(listener: (reason: CarrierLossReason) => void): void { this.lostListener = listener }
47
+ available(): boolean { return true }
48
+ static refusedIframePanel(): boolean { return this.refuseIframe }
49
+ static compatibilityError(): string | undefined { return this.versionError }
200
50
 
201
- /** Register the "this carrier is gone" listener (see the interface's `onLost`). */
202
- onLost(listener: (reason: CarrierLossReason) => void): void {
203
- this.lostListener = listener
204
- }
205
-
206
- /**
207
- * Find a usable desktop bridge, if this surface has one.
208
- *
209
- * A stale endpoint (a shell that already exited, leaving its file behind) is
210
- * rejected here rather than surfacing later as a mysterious ECONNREFUSED: the
211
- * caller falls back to self-hosting, which always works.
212
- * @returns the host, or undefined when no bridge is available.
213
- */
214
- static async discover(sessionId?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
51
+ static async discover(_owner?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
52
+ this.refuseIframe = false
53
+ this.versionError = undefined
215
54
  let endpoint: BridgeEndpoint
216
55
  try {
217
56
  const raw = JSON.parse(readFileSync(bridgeEndpointPath(), 'utf8')) as Partial<BridgeEndpoint>
218
57
  if (typeof raw.port !== 'number' || typeof raw.token !== 'string' || typeof raw.pid !== 'number') return undefined
219
- endpoint = { port: raw.port, token: raw.token, pid: raw.pid, ...raw.updatedAt !== undefined ? { updatedAt: raw.updatedAt } : {} }
220
- } catch {
221
- return undefined
222
- }
58
+ endpoint = { port: raw.port, token: raw.token, pid: raw.pid, ...raw.updatedAt === undefined ? {} : { updatedAt: raw.updatedAt } }
59
+ } catch { return undefined }
60
+ const probe = new BridgeConnection(endpoint, bridgeEndpointPath())
223
61
  try {
224
- // A throwaway connection for discovery: the adopted host opens its own, and a
225
- // rejected endpoint must not leave a socket behind.
226
- const probe = new BridgeConnection(endpoint, bridgeEndpointPath())
227
- try {
228
- const answer = await probe.call({ op: 'list' }, 5_000)
229
- if (answer.ok !== true) return undefined
230
- // Refuse a panel this plugin cannot drive, before adopting it.
231
- //
232
- // The sidebar browser renders as a <webview> only where the shell exposes
233
- // `dshDesktop.browser` and enables `webviewTag`. Where it renders as an <iframe> there is
234
- // no webContents, no `getWebContentsId()` and no CDP endpoint — and every tool here is
235
- // built on CDP, so adopting it means failing every call, with no path back to a carrier
236
- // that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
237
- //
238
- // Read here WITHOUT an owner on purpose, because the question is not about a conversation:
239
- // whether the panel is a webview is decided by the shell's preload and window options, so
240
- // it is the same answer for every conversation and needs no session context.
241
- //
242
- // `none` and `unknown` are NOT refusals: a panel that does not exist yet is created by the
243
- // first open, and a probe that could not read the attribute has learned nothing.
244
- if (String(answer.frame ?? 'unknown') === 'iframe') {
245
- DesktopBridgeViewHost.refuseIframe = true
246
- return undefined
247
- }
248
- return new DesktopBridgeViewHost(endpoint, sessionId, isQuiet, Number(answer.protocol ?? 2))
249
- } finally {
250
- probe.close()
62
+ const answer = await probe.call({ op: 'list' }, 5_000)
63
+ if (isBridgeVersionMismatch(answer)) throw new BridgeVersionError()
64
+ if (answer.ok !== true) return undefined
65
+ if (typeof answer.protocol !== 'number' || !Number.isInteger(answer.protocol)) throw new BridgeVersionError()
66
+ if (answer.frame === 'iframe') { this.refuseIframe = true; return undefined }
67
+ return new DesktopBridgeViewHost(endpoint, isQuiet)
68
+ } catch (error) {
69
+ const versionError = bridgePackageError(error) ?? (error instanceof BridgeVersionError ? error : undefined)
70
+ if (versionError !== undefined) {
71
+ this.versionError = versionError.message
72
+ throw versionError
251
73
  }
252
- } catch {
253
- // Dead endpoint or an older bridge: self-hosting remains the answer.
254
74
  return undefined
255
75
  }
76
+ finally { probe.close() }
256
77
  }
257
78
 
258
- /**
259
- * Whether the last discovery refused a bridge because its sidebar panel is an iframe.
260
- *
261
- * Recorded so the entry point can say WHY the plugin is self-hosting on a shell that does have a
262
- * bridge. Otherwise the user sees a second browser window and no explanation, on a machine where
263
- * they just followed instructions to install the bridge.
264
- */
265
- private static refuseIframe = false
266
-
267
- /** Whether discovery refused a bridge for an undrivable sidebar panel (see {@link discover}). */
268
- static refusedIframePanel(): boolean {
269
- return this.refuseIframe
270
- }
271
-
272
- /** Whether this host can back views: the bridge already answered `list`. */
273
- available(): boolean {
274
- return true
275
- }
276
-
277
- /**
278
- * Every page this conversation's sidebar panel currently holds.
279
- *
280
- * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
281
- * new page, and nothing tells the provider. Those pages are real — they are what the human sees
282
- * — but without this the tab model reports only the ones the provider created, so the rest are
283
- * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
284
- *
285
- * The bridge's `list` already answers with the sidebar guests, which is the same information, so
286
- * this asks for it rather than reaching into the shell again.
287
- * @returns the panel's pages, or an empty list when the bridge cannot answer.
288
- */
289
- /**
290
- * Every sidebar page this conversation holds that THIS HOST did not open.
291
- *
292
- * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
293
- * new page, and nothing tells the provider. Those pages are real — they are what the human sees
294
- * — but without this the tab model reports only the ones the provider created, so the rest are
295
- * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
296
- *
297
- * Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
298
- * caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
299
- * guest id, and the two never match. The first version returned everything and relied on the
300
- * caller to filter, which reported the same page twice — the mapping that makes the match
301
- * possible exists only here.
302
- * @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
303
- */
304
- async listPages(owner: string = this.owner): Promise<readonly CarrierPage[]> {
305
- const answer = await this.connection.call({ op: 'list', owner }, 5_000)
79
+ async listPages(scope: BrowserSessionWireId, _options: { readonly requireRunning?: boolean } = {}): Promise<readonly CarrierPage[]> {
80
+ resolveSessionHandle(scope)
81
+ const answer = await this.connection.call({ op: 'list', handle: scope }, 5_000)
306
82
  if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar page listing failed'))
307
- const guests = Array.isArray(answer.sidebar) ? answer.sidebar : []
308
- const ours = new Set<number>()
309
- for (const view of this.views.values()) {
310
- if (typeof view.guest === 'number') ours.add(view.guest)
311
- }
312
- return guests
313
- .filter((guest): guest is { id: number; url?: unknown } => typeof guest?.id === 'number')
314
- .filter(guest => !ours.has(guest.id))
315
- .map(guest => ({
316
- id: String(guest.id),
317
- url: typeof guest.url === 'string' ? guest.url : '',
318
- }))
319
- }
320
-
321
- /**
322
- * Close one sidebar page by the id {@link listPages} reported.
323
- *
324
- * The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
325
- * stopped one conversation's teardown from destroying another's page. So the title is looked up
326
- * through the same listing, and a page that no longer appears is treated as already gone rather
327
- * than as an error: the caller asked for it to be closed, and it is.
328
- * @param id - the sidebar guest id, as a string.
329
- */
330
- async closePage(id: string, owner: string = this.owner): Promise<void> {
331
- const numeric = Number(id)
332
- if (!Number.isSafeInteger(numeric) || numeric <= 0) throw new Error(`not a sidebar page id: ${id}`)
333
- const answer = await this.connection.call({ op: 'closePage', id: numeric, owner }, 10_000)
334
- if (answer.ok !== true || answer.closed !== 1) {
335
- throw new Error(`dsh-builtin-browser: could not close sidebar page ${id}: ${String(answer.error ?? 'the shell did not close the requested page; refresh or upgrade the desktop bridge')}`)
336
- }
337
- }
338
-
339
- /**
340
- * The guest backing a view, materialized on first use.
341
- *
342
- * The conversation that called owns exactly one sidebar page on this carrier — a human and the
343
- * agent look at the same page — so every view resolves to that conversation's own guest, and the
344
- * page does not multiply behind the provider's own tab bookkeeping.
345
- *
346
- * A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
347
- * is established by the command failing instead.
348
- * @param viewId - the view whose guest is wanted.
349
- * @param url - address to use when this conversation has no page yet.
350
- */
351
-
352
- private async guestFor(viewId: string, url?: string, options?: CommandOptions): Promise<number> {
353
- const entry = this.views.get(viewId)
83
+ if (!Array.isArray(answer.sidebar)) throw new Error('invalid sidebar page listing')
84
+ const pages: CarrierPage[] = []
85
+ for (const page of answer.sidebar) {
86
+ if (typeof page?.id !== 'string') throw new Error('invalid sidebar page handle')
87
+ resolveTabHandle(resolveSessionHandle(scope), page.id)
88
+ if (!this.views.has(page.id)) pages.push({ id: page.id, url: String(page.url ?? ''), title: String(page.title ?? '') })
89
+ }
90
+ return pages
91
+ }
92
+
93
+ async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<ElectronViewHandle> {
94
+ const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
95
+ const answer = await this.connection.call({ op: 'adoptPage', handle: identity })
96
+ if (answer.ok !== true || answer.id !== id) throw new Error(String(answer.error ?? 'sidebar page adoption failed'))
97
+ const handle = this.createView(identity)
98
+ const entry = this.views.get(handle.id)!
99
+ entry.bound = true
100
+ entry.adopted = true
101
+ return handle
102
+ }
103
+
104
+ async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<void> {
105
+ const identity = tabWireId(resolveTabHandle(resolveSessionHandle(scope), id))
106
+ const blank = this.views.get(id)?.bound === false
107
+ const answer = await this.connection.call({ op: blank ? 'releaseTab' : 'closePage', handle: identity }, 10_000)
108
+ if (answer.ok !== true || (!blank && answer.closed !== 1)) throw new Error(`dsh-builtin-browser: could not close sidebar page: ${String(answer.error ?? 'close not acknowledged')}`)
109
+ this.views.delete(id)
110
+ this.orphaned.delete(id)
111
+ }
112
+
113
+ private async guestFor(id: BrowserTabWireId, url?: string, options?: CommandOptions, checkNavigation?: () => void): Promise<Record<string, unknown> | undefined> {
114
+ const entry = this.views.get(id)
354
115
  if (entry === undefined) throw new Error('dsh-builtin-browser: sidebar view was released')
355
- const stillOwned = (): void => {
356
- if (this.views.get(viewId) !== entry) throw new Error('dsh-builtin-browser: sidebar view was released')
357
- }
358
- // No liveness check here: verifying the cached guest cost a round-trip on every
359
- // command. A guest that has gone away is detected by the command itself failing,
360
- // and `createView`'s sendCommand then discards the cache and calls back in here.
361
- // Explicit navigation also reopens a folded panel. Cached guests are sufficient for reads
362
- // and input, but not for the user's request to open an address in this conversation's sidebar.
363
- if (entry?.guest !== undefined && url === undefined) return entry.guest
364
- if (options?.initialize === false) {
116
+ const check = (): void => {
117
+ options?.signal?.throwIfAborted()
118
+ checkNavigation?.()
119
+ if (this.views.get(id) !== entry) throw new Error('dsh-builtin-browser: sidebar view was released')
120
+ }
121
+ check()
122
+ if (entry.bound) return undefined
123
+ if (options?.initialize === false || options?.present === false) {
365
124
  throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
366
125
  }
367
-
368
- // The conversation THIS VIEW serves — read from the view, never from the process.
369
- //
370
- // The difference is the whole bug. This host is one instance shared by every conversation, so
371
- // `this.owner` alone can only be "whichever conversation this process happens to name", and
372
- // naming the wrong one is exactly how a page requested in one conversation appeared in
373
- // another. The view was created for a conversation (`createView(owner)`), so that is what it
374
- // asks for its page.
375
- //
376
- // Nothing here asks which conversation is on screen: `ensureSidebar` reaches this
377
- // conversation's own panel by id through the renderer, rather than by pressing the shell's
378
- // shortcut or clicking its card, both of which the shell delivers to whatever it displays.
379
- const owner = entry?.owner ?? this.owner
380
- if (url !== undefined && this.protocol < 3
381
- && [...this.views.entries()].some(([id, view]) => id !== viewId && view.owner === owner && view.guest !== undefined)) {
382
- throw new Error('dsh-builtin-browser: this desktop bridge needs an update for separate sidebar tabs; use Repair and restart in Browser settings')
383
- }
384
- // A command that must not present anything (issue #46: the live preview) takes a read-only path.
385
- // It asks the bridge what this conversation ALREADY has and never enters the retry loop below — // that loop is what asks the shell to display the conversation, which is right for a tool call
386
- // and wrong for "let me look at it". A page that is not on screen therefore reports as a display
387
- // state, and the preview route turns that into the panel's paused state.
388
- if (options?.present === false) {
389
- // A logical view without a binding cannot borrow a neighbouring tab for a preview.
390
- if (this.protocol >= 3) {
391
- throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
392
- }
393
- // `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
394
- // `ensureSidebar` can drive the shell — the current one asks the renderer to display the
395
- // conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
396
- // address bar. `list` is a pure read on every version, so a preview cannot move anything even
397
- // when the installed bridge is old (which is exactly the reporter's environment: the symptom
398
- // appears only once a bridge is installed).
399
- const listed = await this.connection.call({ op: 'list', owner }, 8_000)
400
- const pages = Array.isArray(listed.sidebar)
401
- ? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
402
- : []
403
- const wanted = url !== undefined && url !== '' ? url : undefined
404
- const samePage = (url: string, wanted: string): boolean => url === wanted || url.startsWith(`${wanted}?`) || url.startsWith(`${wanted}#`)
405
- const match = pages.find(page => wanted !== undefined && typeof page.url === 'string' && samePage(page.url, wanted)) ?? pages[0]
406
- const id = match !== undefined ? Number(match.id) : Number.NaN
407
- if (!Number.isFinite(id) || id <= 0) {
408
- throw new BrowserPanelNotDisplayedError(
409
- 'the preview asked for this conversation\'s page without presenting it, and no page is attached '
410
- + `(the shell holds ${pages.length})`,
411
- )
412
- }
413
- stillOwned()
414
- entry.guest = id
415
- return id
416
- }
417
- const ask = (): Promise<Record<string, unknown>> => this.connection.call({
418
- op: 'ensureSidebar',
419
- owner,
420
- viewId,
421
- ...entry?.guest === undefined ? {} : { guestId: entry.guest },
422
- ...url !== undefined && url !== '' ? { url } : {},
423
- }, 30_000)
424
- let answer = await ask()
425
- // A refusal is retried when it describes a DISPLAY state rather than a dead carrier, because the
426
- // plugin's client half asks the shell to show this conversation inside the very call that
427
- // produced it. Two shapes come back from that first round:
428
- // panel-not-displayed - the conversation exists but is not the one on screen;
429
- // "is not mounted" - its surface store was not minted when the tab was placed.
430
- // Both are gone one render later. Measured, this is the whole difference between "the sidebar
431
- // works once I click over to that conversation" and "it works" — the page is real either way,
432
- // and failing the call while the shell is already switching away from it just reported a
433
- // problem the plugin had already fixed.
434
- const displayRefusal = (value: Record<string, unknown>): boolean =>
435
- value.ok !== true
436
- && (String(value.code ?? '') === PANEL_NOT_DISPLAYED
437
- || String(value.error ?? '').includes('not mounted')
438
- // Bridges installed before issue #37 send the same refusal with NO code — the installed copy
439
- // on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
440
- // the code therefore turned a retryable display state into a hard failure for exactly the
441
- // users who had the old bridge, which is the majority until it is reinstalled. The wording
442
- // is stable across both versions; the code is not.
443
- || String(value.error ?? '').includes('can only attach'))
444
- for (let attempt = 0; attempt < PANEL_DISPLAY_RETRIES && displayRefusal(answer); attempt += 1) {
445
- await new Promise(resolve => setTimeout(resolve, PANEL_DISPLAY_RETRY_MS))
446
- stillOwned()
447
- answer = await ask()
448
- }
449
- stillOwned()
126
+ if (entry.adopted) throw new Error('dsh-builtin-browser: the sidebar page this view was adopted from is gone')
127
+ const deadline = options?.deadline ?? Date.now() + 30_000
128
+ const transactionId = randomUUID()
129
+ const cancel = (): void => { void this.connection.call({ op: 'cancelSidebar', handle: id, transactionId }, 2_000).catch(() => {}) }
130
+ options?.signal?.addEventListener('abort', cancel, { once: true })
131
+ let answer: Record<string, unknown>
132
+ try {
133
+ answer = await this.connection.call({ op: 'ensureSidebar', handle: id, deadline, transactionId,
134
+ ...url ? { url, attachOnly: true } : {} }, Math.max(1, deadline - Date.now()))
135
+ } finally { options?.signal?.removeEventListener('abort', cancel) }
136
+ check()
450
137
  if (answer.ok !== true) {
451
- // Reachable only after the retries above have run out, and the code still decides — not the
452
- // wording:
453
- // panel-not-displayed -> the shell was asked to show the conversation (client half's
454
- // `openSession`) and did not render it in ~1.6 s: no loss, no swap.
455
- // A missing guest within a time budget is still initialization, including on old bridges
456
- // that only returned text. It is not evidence that this shell uses an undrivable iframe.
457
- const code = String(answer.code ?? '')
458
- const detail = String(answer.error ?? answer.code ?? 'unknown sidebar failure')
459
- if (code === PANEL_NOT_DISPLAYED) throw new BrowserPanelNotDisplayedError(detail)
460
- if (code === PANEL_INITIALIZING || (code === '' && detail.includes('produced no page'))) {
461
- throw new BrowserPanelNotDisplayedError(detail, PANEL_INITIALIZING)
462
- }
463
- if (code === 'panel-unusable') this.reportLost('panel-unusable')
464
- throw new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`)
465
- }
466
- const id = Number(answer.id)
467
- if (!Number.isFinite(id) || id <= 0) {
468
- throw new Error('dsh-builtin-browser: the sidebar reported no browser page for this conversation')
469
- }
470
- entry.guest = id
471
- return id
472
- }
473
-
474
- /**
475
- * @param owner - the conversation this view serves. Recorded WITH the view: one host instance
476
- * serves every conversation, so the owner cannot live on the host.
477
- */
478
- createView(owner?: string): ElectronViewHandle {
479
- const viewId = randomUUID()
480
- this.views.set(viewId, { owner: owner !== undefined && owner !== '' ? owner : this.owner })
481
- const navigateUrl = (method: string, params?: Record<string, unknown>): string | undefined =>
482
- method === 'Page.navigate' ? String((params as { url?: unknown })?.url ?? '') : undefined
483
- const run = async (guest: number, method: string, params?: Record<string, unknown>): Promise<Record<string, unknown>> => {
484
- const owner = this.views.get(viewId)?.owner ?? this.owner
485
- const answer = await this.connection.call({ op: 'cdp', id: guest, method, params, owner })
486
- if (answer.ok !== true) throw new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`)
487
- // The bridge forwards whatever CDP answered; the seam expects an object.
488
- return (answer.result ?? {}) as Record<string, unknown>
489
- }
138
+ const code = String(answer.code ?? 'panel-initialization-failed')
139
+ const detail = String(answer.error ?? 'sidebar unavailable')
140
+ if (code === PANEL_NOT_DISPLAYED || code === PANEL_INITIALIZING) throw new BrowserPanelNotDisplayedError(detail, code)
141
+ if (code === 'panel-unusable') this.lostListener?.('panel-unusable')
142
+ throw Object.assign(new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`), { code, initialization: answer.initialization })
143
+ }
144
+ if (answer.id !== id) throw new Error('dsh-builtin-browser: sidebar returned a different tab handle')
145
+ entry.bound = true
146
+ return answer.navigation && typeof answer.navigation === 'object' ? answer.navigation as Record<string, unknown> : undefined
147
+ }
148
+
149
+ createView(identity: BrowserTabWireId): ElectronViewHandle {
150
+ const scope = sessionWireId(readTabHandle(identity))
151
+ if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
152
+ const id = identity
153
+ this.activeScope = scope
154
+ if (this.views.has(id)) throw new Error('dsh-builtin-browser: sidebar view is already bound')
155
+ this.views.set(id, { scope, bound: false })
156
+ let latestNavigation = 0
490
157
  return {
491
- id: viewId,
492
- download: async (url: string, savePath: string) => {
493
- if (this.protocol < 3) throw new Error('dsh-builtin-browser: repair and restart the desktop bridge for sidebar downloads')
494
- const guest = await this.guestFor(viewId)
495
- const owner = this.views.get(viewId)?.owner ?? this.owner
496
- const answer = await this.connection.call({ op: 'download', id: guest, owner, url, savePath }, 60_000)
158
+ id,
159
+ download: async (url, savePath) => {
160
+ await this.guestFor(id)
161
+ const answer = await this.connection.call({ op: 'download', handle: id, url, savePath }, 60_000)
497
162
  if (answer.ok !== true) throw new Error(`dsh-builtin-browser: sidebar download failed: ${String(answer.error)}`)
498
163
  },
499
- sendCommand: async (method: string, params?: Record<string, unknown>, options?: CommandOptions) => {
500
- // No liveness probe up front. Checking first cost a whole round-trip on
501
- // every command; instead the command runs and its failure is what triggers
502
- // recovery. Only a genuinely missing guest is retried, so a real error (a
503
- // bad selector, a timeout) still surfaces unchanged.
504
- const url = navigateUrl(method, params)
505
- let guest = await this.guestFor(viewId, url, options)
506
- try {
507
- return await run(guest, method, params)
508
- } catch (error) {
509
- if (!isGuestGone(error)) throw error
510
- // The human closed the tab: the page is gone, so take a fresh one and
511
- // replay the command once. This is the "closing the interface ends the
512
- // session" rule, now paid for only when it actually happens.
513
- // Drop the guest but keep the entry: the conversation it serves is what the retry needs,
514
- // and removing the entry would lose it back to the process-wide fallback owner.
515
- const lost = this.views.get(viewId)
516
- if (lost !== undefined) delete lost.guest
517
- guest = await this.guestFor(viewId, url, options)
518
- return await run(guest, method, params)
164
+ sendCommand: async (method, params, options) => {
165
+ const url = method === 'Page.navigate' ? String(params?.url ?? '') : undefined
166
+ const sequence = url === undefined ? latestNavigation : ++latestNavigation
167
+ const check = (): void => {
168
+ if (sequence !== latestNavigation) throw Object.assign(new Error('a newer navigation was requested for this sidebar view'), { code: 'panel-navigation-superseded' })
519
169
  }
170
+ const navigation = await this.guestFor(id, url, options, check)
171
+ check()
172
+ if (navigation !== undefined) return navigation
173
+ const answer = await this.connection.call({ op: 'cdp', handle: id, method, params })
174
+ if (answer.ok !== true) throw Object.assign(new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`), { code: answer.code })
175
+ return (answer.result ?? {}) as Record<string, unknown>
520
176
  },
521
177
  }
522
178
  }
523
179
 
524
180
  destroyView(handle: ElectronViewHandle): void {
525
181
  const entry = this.views.get(handle.id)
526
- if (entry !== undefined) {
527
- // Remember the page: it outlives our handle, and a later release must be able to name
528
- // exactly the tabs this conversation's views opened. The owner comes along so a release
529
- // naming one conversation does not sweep up another's.
530
- if (entry.guest !== undefined) this.orphaned.set(entry.guest, entry.owner)
531
- this.views.delete(handle.id)
532
- }
182
+ if (entry?.bound && !entry.adopted) this.orphaned.set(tabWireId(readTabHandle(handle.id)), entry.scope)
183
+ this.views.delete(handle.id)
533
184
  }
534
185
 
535
- /**
536
- * Bring this view's tab to the front in the sidebar.
537
- *
538
- * This used to be empty, on the reasoning that the sidebar is already on screen so there is
539
- * nothing to show. That confused "the sidebar is visible" with "this page is the one being
540
- * looked at": opening a page left it behind whatever the human had in front, which is issue
541
- * #23. The other two carriers both do this — the self-hosted window re-adds the view and the
542
- * system browser calls `Page.bringToFront` — so this carrier was the odd one out.
543
- *
544
- * Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
545
- * it must not fail the navigation that has already happened.
546
- * @param handle - the view to bring forward.
547
- */
548
186
  showView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): void {
549
- // Selecting a sidebar tab only changes the task's pane. The bridge never activates the
550
- // desktop window, so explicit tab selection works in quiet mode as well.
551
- if (options?.quiet === true && options.select !== true) return
552
- // `owner` is required: the bridge refuses to bring forward a guest held by another session.
553
- // It comes from the view, not the process — with several conversations live, a process-wide
554
- // owner would raise the wrong conversation's tab.
555
- const owner = this.views.get(handle.id)?.owner ?? this.owner
556
- const guest = this.views.get(handle.id)?.guest
557
- // showActive also runs before a view has navigated; do not materialize a blank page just to
558
- // present it. Once materialized, only the shell's numeric guest id can name its tab.
559
- if (guest === undefined) return
560
- void this.connection.call({ op: 'showTab', viewId: guest, logicalViewId: handle.id, owner }, 5_000).catch(() => undefined)
561
- }
562
-
563
-
564
-
565
-
566
- onUserAction(handler: (action: BrowserUserAction) => void): void {
567
- this.userActionHandler = handler
568
- }
569
-
570
-
571
- /**
572
- * Release the sidebar's browser pages (requirements 搂3, `ui.closeWithSession`).
573
- *
574
- * Destroying our own view handles is not enough on this carrier: the sidebar
575
- * belongs to the shell and would happily keep the page (and its renderer) alive.
576
- * Closing the tabs is what actually ends the page — and only the page: cookies
577
- * live in the partition, history on disk, so both survive.
578
- * @param owner - the conversation whose pages to close. Omit to close every conversation's,
579
- * which is only correct from a teardown that is itself global.
580
- * @returns a promise that settles once the shell has been asked.
581
- */
582
- async releasePage(owner?: string): Promise<void> {
583
- // Only this conversation's tabs. The host is ONE instance shared by every conversation, so a
584
- // release that named none would close pages other conversations are still driving — "every
585
- // webview currently visible" is precisely what must never be used here.
586
- const mine: number[] = []
587
- for (const [viewId, entry] of [...this.views]) {
588
- if (owner !== undefined && entry.owner !== owner) continue
589
- if (entry.guest !== undefined) mine.push(entry.guest)
590
- this.views.delete(viewId)
591
- }
592
- // A view destroyed before the release still owns its page; its guest is collected here.
593
- for (const [guest, holder] of [...this.orphaned]) {
594
- if (owner !== undefined && holder !== owner) continue
595
- mine.push(guest)
596
- this.orphaned.delete(guest)
597
- }
598
- // Nothing of ours is open: release nothing. Falling through to an unfiltered
599
- // release here would close tabs a human opened, or another session's page.
600
- if (mine.length === 0) return
601
- let titles: string[]
602
- try {
603
- // `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
604
- // falls back to a different owner, so the guests this session holds are filtered out of the
605
- // answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
606
- // returns without closing anything — the page stayed open and the human had to close it by
607
- // hand. Adding the ledger to the bridge without updating this call site is exactly the kind
608
- // of half-change that made the ownership work take four rounds.
609
- const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000)
610
- const sidebar = Array.isArray(answer.sidebar) ? answer.sidebar as Array<{ id?: unknown; title?: unknown }> : []
611
- titles = sidebar
612
- .filter(guest => mine.includes(Number(guest.id)))
613
- .map(guest => String(guest.title ?? ''))
614
- .filter(title => title !== '')
615
- } catch {
616
- // Could not read the titles back; releasing nothing is safer than closing
617
- // tabs that belong to somebody else.
618
- return
619
- }
620
- if (titles.length === 0) return
187
+ if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
188
+ if (!this.views.get(handle.id)?.bound) return
189
+ void this.connection.call({ op: 'showTab', handle: tabWireId(readTabHandle(handle.id)) }, 5_000).catch(() => {})
190
+ }
191
+
192
+ onUserAction(_handler: (action: BrowserUserAction) => void): void {}
193
+
194
+ async presentView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean; readonly select?: boolean }): Promise<void> {
195
+ if ((options?.quiet ?? this.isQuiet()) && options?.select !== true) return
196
+ const id = tabWireId(readTabHandle(handle.id))
197
+ await this.guestFor(id)
198
+ const answer = await this.connection.call({ op: 'showTab', handle: id })
199
+ if (answer.ok !== true) throw Object.assign(new Error(String(answer.error ?? 'sidebar selection failed')), { code: answer.code })
200
+ }
201
+
202
+ async retireSession(scope: BrowserSessionWireId): Promise<void> {
203
+ resolveSessionHandle(scope)
204
+ if (this.retiredSessions.has(scope)) return
205
+ this.retiredSessions.add(scope)
206
+ const answer = await this.connection.call({ op: 'releaseSession', handle: scope })
207
+ if (answer.ok !== true) throw new Error(String(answer.error ?? 'sidebar release failed'))
208
+ for (const [id, held] of this.orphaned) if (held === scope) this.orphaned.delete(id)
209
+ }
210
+
211
+ async releasePage(scope?: BrowserSessionWireId): Promise<void> {
212
+ if (scope !== undefined) resolveSessionHandle(scope)
213
+ const mine = new Set<BrowserTabWireId>()
214
+ const scopes = new Set<BrowserSessionWireId>()
215
+ for (const [id, entry] of this.views) {
216
+ if (scope !== undefined && entry.scope !== scope) continue
217
+ scopes.add(entry.scope)
218
+ if (entry.bound && !entry.adopted) mine.add(tabWireId(readTabHandle(id)))
219
+ this.views.delete(id)
220
+ }
221
+ for (const [id, held] of this.orphaned) {
222
+ if (scope !== undefined && held !== scope) continue
223
+ scopes.add(sessionWireId(readTabHandle(id)))
224
+ mine.add(tabWireId(readTabHandle(id)))
225
+ this.orphaned.delete(id)
226
+ }
227
+ if (scope !== undefined) scopes.add(scope)
621
228
  try {
622
- // `owner` is required for the same reason as above: the bridge closes only the guests the
623
- // caller holds, so an owner-less call closes nothing and the page stays open.
624
- await this.connection.call({ op: 'closeSidebarBrowser', titles, owner: owner ?? this.owner }, 10_000)
625
- } catch {
626
- // Best effort: the setting expresses a preference, and a shell that cannot
627
- // be reached is no reason to fail the session teardown that called us.
229
+ const results = await Promise.allSettled([...mine].map(async id => {
230
+ const answer = await this.connection.call({ op: 'closePage', handle: id }, 10_000)
231
+ if (answer.ok !== true || answer.closed !== 1) throw new Error(String(answer.error ?? 'sidebar close not acknowledged'))
232
+ }))
233
+ const failure = results.find(result => result.status === 'rejected')
234
+ if (failure?.status === 'rejected') throw failure.reason
235
+ } finally {
236
+ await Promise.all([...scopes].map(handle => this.retireSession(handle)))
628
237
  }
629
238
  }
630
239
 
631
- /**
632
- * Fold the sidebar away without ending the page (`ui.autoExpandOnce` is off, or
633
- * the caller wants the screen back while work continues).
634
- * @returns a promise that settles once the shell has been asked.
635
- */
636
240
  async collapse(): Promise<void> {
637
- try {
638
- await this.connection.call({ op: 'collapseSidebar', owner: this.owner }, 10_000)
639
- } catch {
640
- // Presentation only; failing to fold is never worth an error.
641
- }
241
+ if (this.activeScope === undefined) return
242
+ await this.connection.call({ op: 'collapseSidebar', handle: this.activeScope }, 10_000).catch(() => {})
642
243
  }
643
244
 
644
- /** No child process of our own to stop; close the shared connection instead. */
645
245
  dispose(): void {
646
246
  this.connection.close()
647
247
  this.views.clear()
648
248
  this.orphaned.clear()
649
- this.userActionHandler = undefined
249
+ this.activeScope = undefined
650
250
  }
651
251
  }