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
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Explicit lifecycle protocol for one Sidebar Browser initialization.
3
+ *
4
+ * Issue #55 reported a single symptom — "produced no page" — for several very
5
+ * different failures: no tab, no Controller, a Controller that never consumed
6
+ * the URL, and a guest that never attached. Collapsing them into one message
7
+ * made the failure unrecoverable and undiagnosable.
8
+ *
9
+ * This journal keeps the exact `(session, tab, occurrence, navigation revision)`
10
+ * a request was aimed at, the stage it reached, and — on failure — the stage
11
+ * plus the raw reason. It is deliberately carrier-neutral: the Controller and
12
+ * the Electron/iframe frame both advance it, and tests drive it directly.
13
+ *
14
+ * Stages:
15
+ * - `accepted`: the navigation record was written for THIS occurrence/revision.
16
+ * - `mounted`: the Controller for that occurrence exists.
17
+ * - `navigating`: the Controller handed the URL to its frame (URL consumed).
18
+ * - `attached`: the guest/iframe document is ready.
19
+ * - `failed`: carries the stage transition that failed and why.
20
+ *
21
+ * @module dsh-client-ui-sidebar-browser/browser/initialization
22
+ */
23
+ import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
24
+
25
+ /** How far one initialization got. */
26
+ export type BrowserInitStage = 'accepted' | 'mounted' | 'navigating' | 'attached' | 'failed'
27
+
28
+ /** Machine reason carried by a failed receipt; the UI localizes it. */
29
+ export type BrowserInitFailure =
30
+ | 'occurrence-aborted'
31
+ | 'controller-missing'
32
+ | 'workspace-unavailable'
33
+ | 'acquire-failed'
34
+ | 'guest-bootstrap-failed'
35
+ | 'navigation-failed'
36
+ | 'navigation-rejected'
37
+ | 'timeout'
38
+
39
+ /** One immutable observation of an initialization attempt. */
40
+ export interface BrowserInitReceipt {
41
+ readonly generation?: string
42
+ readonly frameId?: string
43
+ readonly loaderId?: string
44
+ readonly requestId: string
45
+ readonly sessionId: string
46
+ readonly tabId: TabId
47
+ /** Distinguishes a reopened tab from its previous lifetime. */
48
+ readonly occurrenceId: string
49
+ /** The navigation record this request was aimed at. */
50
+ readonly navigationRevision: number
51
+ readonly url: string
52
+ readonly stage: BrowserInitStage
53
+ /** Present once the carrier reports an attached guest/document. */
54
+ readonly guestId?: string
55
+ /** Present only when `stage === 'failed'`. */
56
+ readonly reason?: BrowserInitFailure
57
+ /** Original carrier failure text, when the failed stage supplied it. */
58
+ readonly detail?: string
59
+ /** Epoch milliseconds; diagnostic only, never used for ordering. */
60
+ readonly at: number
61
+ }
62
+
63
+ /** Identity half of a receipt, supplied when a request starts. */
64
+ export interface BrowserInitRequest {
65
+ readonly requestId?: string
66
+ readonly sessionId: string
67
+ readonly tabId: TabId
68
+ readonly occurrenceId: string
69
+ readonly navigationRevision: number
70
+ readonly url: string
71
+ }
72
+
73
+ /** A stage transition may carry the guest id observed by the carrier. */
74
+ export interface BrowserInitPatch {
75
+ readonly generation?: string
76
+ readonly frameId?: string
77
+ readonly loaderId?: string
78
+ readonly detail?: string
79
+ readonly guestId?: string
80
+ readonly navigationRevision?: number
81
+ readonly url?: string
82
+ }
83
+
84
+ export interface BrowserInitializationJournal {
85
+ /** Start (or restart) the request for one tab; a dead occurrence fails immediately. */
86
+ begin(request: BrowserInitRequest, options?: { readonly aborted?: boolean }): BrowserInitReceipt
87
+ /** Advance a live request; a request that already failed is not revived. */
88
+ advance(tabId: TabId, stage: Exclude<BrowserInitStage, 'failed'>, patch?: BrowserInitPatch): BrowserInitReceipt | undefined
89
+ /** Fail a live request with a machine reason, preserving its last reached stage. */
90
+ fail(tabId: TabId, reason: BrowserInitFailure, patch?: BrowserInitPatch): BrowserInitReceipt | undefined
91
+ get(tabId: TabId): BrowserInitReceipt | undefined
92
+ /** Newest first, bounded: this is a diagnostic ring, not a durable log. */
93
+ all(): readonly BrowserInitReceipt[]
94
+ forget(tabId: TabId): void
95
+ dispose(): void
96
+ }
97
+
98
+ /** Ready document observed in the live frame, independent of its last requested URL. */
99
+ export interface BrowserObservedPage {
100
+ readonly generation?: string
101
+ readonly frameId?: string
102
+ readonly loaderId?: string
103
+ readonly url: string
104
+ readonly guestId?: string
105
+ }
106
+
107
+ export interface BrowserInitializationReader {
108
+ readonly protocolVersion: 1
109
+ navigate?(query: { readonly sessionId: string; readonly tabId: TabId; readonly url: string }): boolean
110
+ current(query: { readonly sessionId: string; readonly tabId: TabId }): BrowserObservedPage | undefined
111
+ read(query: { readonly sessionId: string; readonly tabId: TabId; readonly url: string; readonly requestId?: string; readonly afterRequestId?: string }): BrowserInitReceipt | undefined
112
+ wait(query: { readonly sessionId: string; readonly tabId: TabId; readonly url: string; readonly requestId?: string; readonly afterRequestId?: string }, signal: AbortSignal): Promise<BrowserInitReceipt>
113
+ }
114
+
115
+ /** Scope reads to a Session/tab and the requested document before exposing a receipt. */
116
+ export function createBrowserInitializationReader(
117
+ lookup: (sessionId: string, tabId: TabId) => BrowserInitReceipt | undefined,
118
+ subscribe?: (listener: () => void) => () => void,
119
+ observe?: (sessionId: string, tabId: TabId) => BrowserObservedPage | undefined,
120
+ navigate?: (sessionId: string, tabId: TabId, url: string) => boolean,
121
+ ): BrowserInitializationReader {
122
+ const canonical = (value: string): string => {
123
+ try { return new URL(value).href } catch { return value }
124
+ }
125
+ const reader: BrowserInitializationReader = {
126
+ protocolVersion: 1,
127
+ ...(navigate === undefined ? {} : { navigate: (query: { readonly sessionId: string; readonly tabId: TabId; readonly url: string }) => navigate(query.sessionId, query.tabId, query.url) }),
128
+ current: query => observe?.(query.sessionId, query.tabId),
129
+ read(query) {
130
+ const receipt = lookup(query.sessionId, query.tabId)
131
+ if (receipt?.sessionId !== query.sessionId || receipt.tabId !== query.tabId
132
+ || canonical(receipt.url) !== canonical(query.url)
133
+ || (query.requestId !== undefined && receipt.requestId !== query.requestId)
134
+ || receipt.requestId === query.afterRequestId) return undefined
135
+ return receipt
136
+ },
137
+ wait(query, signal) {
138
+ if (subscribe === undefined) return Promise.reject(new Error('initialization subscriptions unavailable'))
139
+ return new Promise((resolve, reject) => {
140
+ let done = false
141
+ let requestId = query.requestId
142
+ let unsubscribe = (): void => {}
143
+ const finish = (error?: Error, receipt?: BrowserInitReceipt): void => {
144
+ if (done) return
145
+ done = true
146
+ unsubscribe()
147
+ signal.removeEventListener('abort', abort)
148
+ if (error !== undefined) reject(error)
149
+ else resolve(receipt!)
150
+ }
151
+ const abort = (): void => finish(signal.reason ?? new Error('source initialization aborted'))
152
+ const check = (): void => {
153
+ if (signal.aborted) { abort(); return }
154
+ const latest = lookup(query.sessionId, query.tabId)
155
+ if (requestId !== undefined && latest !== undefined && latest.requestId !== requestId) {
156
+ finish(Object.assign(new Error('source initialization superseded'), { code: 'panel-navigation-superseded' }))
157
+ return
158
+ }
159
+ const receipt = reader.read(query)
160
+ if (receipt !== undefined) requestId ??= receipt.requestId
161
+ if (receipt?.stage === 'failed') {
162
+ const code = receipt.reason === 'timeout' ? 'BROWSER_DOCUMENT_TIMEOUT'
163
+ : receipt.reason === 'occurrence-aborted' ? 'BROWSER_NAVIGATION_CANCELLED'
164
+ : receipt.reason === 'navigation-failed' || receipt.reason === 'navigation-rejected' ? 'BROWSER_NAVIGATION_FAILED'
165
+ : 'panel-initialization-failed'
166
+ finish(Object.assign(new Error(receipt.detail ?? receipt.reason ?? 'source initialization failed'), { code }))
167
+ }
168
+ else if (receipt?.stage === 'attached') finish(undefined, receipt)
169
+ }
170
+ unsubscribe = subscribe(check)
171
+ if (done) { unsubscribe(); return }
172
+ signal.addEventListener('abort', abort, { once: true })
173
+ check()
174
+ })
175
+ },
176
+ }
177
+ return reader
178
+ }
179
+
180
+ const HISTORY_LIMIT = 200
181
+
182
+ /**
183
+ * Build a journal. `now` is injectable so tests get stable receipts.
184
+ * @param options - clock and history bound.
185
+ * @returns the journal.
186
+ */
187
+ export function createBrowserInitializationJournal(
188
+ options: { readonly now?: () => number; readonly historyLimit?: number; readonly onChange?: () => void } = {},
189
+ ): BrowserInitializationJournal {
190
+ const now = options.now ?? (() => Date.now())
191
+ const limit = options.historyLimit ?? HISTORY_LIMIT
192
+ const latest = new Map<TabId, BrowserInitReceipt>()
193
+ let history: BrowserInitReceipt[] = []
194
+ let serial = 0
195
+ let disposed = false
196
+
197
+ const publish = (receipt: BrowserInitReceipt): BrowserInitReceipt => {
198
+ latest.set(receipt.tabId, receipt)
199
+ history.push(receipt)
200
+ if (history.length > limit) history = history.slice(history.length - limit)
201
+ options.onChange?.()
202
+ return receipt
203
+ }
204
+
205
+ return {
206
+ begin(request, beginOptions = {}) {
207
+ const receipt: BrowserInitReceipt = {
208
+ requestId: request.requestId ?? `browser-init-${++serial}`,
209
+ sessionId: request.sessionId,
210
+ tabId: request.tabId,
211
+ occurrenceId: request.occurrenceId,
212
+ navigationRevision: request.navigationRevision,
213
+ url: request.url,
214
+ stage: beginOptions.aborted === true ? 'failed' : 'accepted',
215
+ ...beginOptions.aborted === true ? { reason: 'occurrence-aborted' as const } : {},
216
+ at: now(),
217
+ }
218
+ return publish(receipt)
219
+ },
220
+ advance(tabId, stage, patch = {}) {
221
+ if (disposed) return undefined
222
+ const current = latest.get(tabId)
223
+ if (current === undefined || current.stage === 'failed') return undefined
224
+ return publish({
225
+ ...current,
226
+ ...patch.navigationRevision === undefined ? {} : { navigationRevision: patch.navigationRevision },
227
+ ...patch.url === undefined ? {} : { url: patch.url },
228
+ ...patch.guestId === undefined ? {} : { guestId: patch.guestId },
229
+ ...patch.generation === undefined ? {} : { generation: patch.generation, frameId: patch.frameId, loaderId: patch.loaderId },
230
+ stage,
231
+ at: now(),
232
+ })
233
+ },
234
+ fail(tabId, reason, patch = {}) {
235
+ if (disposed) return undefined
236
+ const current = latest.get(tabId)
237
+ if (current === undefined) return undefined
238
+ if (current.stage === 'failed') return current
239
+ return publish({
240
+ ...current,
241
+ ...patch.navigationRevision === undefined ? {} : { navigationRevision: patch.navigationRevision },
242
+ ...patch.url === undefined ? {} : { url: patch.url },
243
+ ...patch.guestId === undefined ? {} : { guestId: patch.guestId },
244
+ ...patch.generation === undefined ? {} : { generation: patch.generation, frameId: patch.frameId, loaderId: patch.loaderId },
245
+ stage: 'failed',
246
+ reason,
247
+ ...patch.detail === undefined ? {} : { detail: patch.detail },
248
+ at: now(),
249
+ })
250
+ },
251
+ get: tabId => latest.get(tabId),
252
+ all: () => [...history].reverse(),
253
+ forget(tabId) {
254
+ latest.delete(tabId)
255
+ },
256
+ dispose() {
257
+ disposed = true
258
+ latest.clear()
259
+ history = []
260
+ },
261
+ }
262
+ }
@@ -0,0 +1,243 @@
1
+ /** Manual address-bar intent resolution; strict navigation stays in url.ts. */
2
+ import { MAX_BROWSER_URL_LENGTH, parseBrowserAddress } from './url.ts'
3
+ import type { BrowserAddressFailure, BrowserTarget } from './url.ts'
4
+
5
+ /** One search endpoint whose address is stored without template syntax. */
6
+ export interface SearchEngine {
7
+ readonly id: string
8
+ readonly label: string
9
+ readonly homeUrl: string
10
+ readonly searchUrl: string
11
+ readonly queryParameter: string
12
+ readonly extraParameters?: Readonly<Record<string, string>>
13
+ }
14
+
15
+ /** Locally shared search selection used to resolve keyword input. */
16
+ export interface OmniboxPreferences {
17
+ readonly defaultSearchEngineId: string
18
+ readonly searchEngines: readonly SearchEngine[]
19
+ }
20
+
21
+ /** Why manual input produced no navigation; address failures keep their strict meaning. */
22
+ export type OmniboxRefusal = BrowserAddressFailure | 'path' | 'engine-unavailable'
23
+
24
+ /** A validated HTTP(S) navigation resolved from manual input. */
25
+ export interface OmniboxNavigation {
26
+ readonly kind: 'navigate'
27
+ readonly target: BrowserTarget
28
+ /** Whether the typed input already named its scheme or was completed as a host. */
29
+ readonly source: 'explicit' | 'host'
30
+ }
31
+
32
+ /** A validated search-result address built from the selected engine. */
33
+ export interface OmniboxSearch {
34
+ readonly kind: 'search'
35
+ readonly engineId: string
36
+ readonly query: string
37
+ readonly target: BrowserTarget
38
+ }
39
+
40
+ /** One action a manual submission can take. */
41
+ export type OmniboxAction = OmniboxNavigation | OmniboxSearch
42
+
43
+ /** Primary action plus the explicit alternative offered for ambiguous input. */
44
+ export type OmniboxResolution =
45
+ | { readonly kind: 'resolved'; readonly primary: OmniboxAction; readonly alternative?: OmniboxAction }
46
+ | { readonly kind: 'refused'; readonly reason: OmniboxRefusal }
47
+
48
+ /** Inputs needed to resolve one address-bar submission. */
49
+ export interface OmniboxOptions extends OmniboxPreferences {
50
+ readonly applicationOrigin?: string
51
+ }
52
+
53
+ const CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/u
54
+ const SCHEME_PREFIX = /^([A-Za-z][A-Za-z\d+.-]*):/u
55
+ const HOST_AUTHORITY = /^(\[[0-9A-Fa-f:.]+\]|[^:@/?#\[\]\s]+)(?::(\d{1,5}))?$/u
56
+ const CREDENTIALS = /^[^\s/?#]*:[^\s/?#]*@/u
57
+ const IPV4_OR_VERSION = /^\d+(?:\.\d+)*$/u
58
+ const DISABLED_SCHEMES = new Set([
59
+ 'about', 'blob', 'chrome', 'data', 'file', 'ftp', 'ftps', 'javascript', 'mailto',
60
+ 'tel', 'vbscript', 'view-source', 'ws', 'wss',
61
+ ])
62
+
63
+ /**
64
+ * Resolve text typed into the manual address bar into navigation or search.
65
+ * Explicit URLs still pass the strict HTTP(S) admission; no failure falls back
66
+ * to a search engine.
67
+ * @param input - raw address-bar value.
68
+ * @param options - shared search selection and the current application origin.
69
+ * @returns the action to take or the refusal to display.
70
+ */
71
+ export function resolveOmniboxInput(input: string, options: OmniboxOptions): OmniboxResolution {
72
+ const classified = classifyInput(input)
73
+ switch (classified.kind) {
74
+ case 'refused':
75
+ return { kind: 'refused', reason: classified.reason }
76
+ case 'keyword':
77
+ return resolveSearch(classified.query, options)
78
+ case 'credentials':
79
+ return strictNavigation(`https://${classified.value}`, 'host', options)
80
+ case 'explicit':
81
+ return strictNavigation(classified.value, 'explicit', options)
82
+ case 'host': {
83
+ const primary = strictNavigation(classified.url, 'host', options)
84
+ if (primary.kind === 'refused') return primary
85
+ const alternative = resolveSearch(classified.query, options)
86
+ return alternative.kind === 'resolved'
87
+ ? { kind: 'resolved', primary: primary.primary, alternative: alternative.primary }
88
+ : primary
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Resolve only the address branch of manual input, for shortcut forms that must
95
+ * not turn ordinary keywords into an implicit search.
96
+ * @param input - user-supplied website address.
97
+ * @param applicationOrigin - current DSH origin, refused by strict admission.
98
+ * @returns a validated target or the refusal to display.
99
+ */
100
+ export function resolveAddressInput(input: string, applicationOrigin?: string):
101
+ | { readonly ok: true; readonly target: BrowserTarget }
102
+ | { readonly ok: false; readonly reason: OmniboxRefusal } {
103
+ const classified = classifyInput(input)
104
+ switch (classified.kind) {
105
+ case 'refused': return { ok: false, reason: classified.reason }
106
+ case 'keyword': return { ok: false, reason: 'invalid' }
107
+ case 'credentials': return addressTarget(`https://${classified.value}`, applicationOrigin)
108
+ case 'explicit': return addressTarget(classified.value, applicationOrigin)
109
+ case 'host': return addressTarget(classified.url, applicationOrigin)
110
+ }
111
+ }
112
+
113
+ type ClassifiedInput =
114
+ | { readonly kind: 'refused'; readonly reason: OmniboxRefusal }
115
+ | { readonly kind: 'keyword'; readonly query: string }
116
+ | { readonly kind: 'credentials'; readonly value: string }
117
+ | { readonly kind: 'explicit'; readonly value: string }
118
+ | { readonly kind: 'host'; readonly url: string; readonly query: string }
119
+
120
+ function classifyInput(input: string): ClassifiedInput {
121
+ const trimmed = input.trim()
122
+ if (trimmed === '') return { kind: 'refused', reason: 'empty' }
123
+ if (trimmed.length > MAX_BROWSER_URL_LENGTH) return { kind: 'refused', reason: 'invalid' }
124
+ if (CONTROL_CHARACTER.test(trimmed)) return { kind: 'refused', reason: 'invalid' }
125
+ // Local paths belong to document and resource providers, never to an address or a search.
126
+ if (/^[A-Za-z]:[\\/]/u.test(trimmed) || trimmed.startsWith('\\\\')) {
127
+ return { kind: 'refused', reason: 'path' }
128
+ }
129
+ // A single leading slash without a host is a POSIX absolute path; a lone
130
+ // slash-prefixed word such as "/help" can still be an ordinary search.
131
+ if (/^\/(?!\/)(?:[^/\s]+\/)+[^/\s]*$/u.test(trimmed)) {
132
+ return { kind: 'refused', reason: 'path' }
133
+ }
134
+ const scheme = SCHEME_PREFIX.exec(trimmed)?.[1]?.toLowerCase()
135
+ if (scheme === 'http' || scheme === 'https') return { kind: 'explicit', value: trimmed }
136
+ if (scheme !== undefined && (DISABLED_SCHEMES.has(scheme) || trimmed.includes('://'))) {
137
+ return { kind: 'refused', reason: 'protocol' }
138
+ }
139
+ // Scheme-less userinfo still names a URL; strict admission reports the credential refusal.
140
+ if (CREDENTIALS.test(trimmed)) return { kind: 'credentials', value: trimmed }
141
+ const normalized = normalizeHostInput(trimmed)
142
+ return normalized === undefined
143
+ ? { kind: 'keyword', query: trimmed }
144
+ : { kind: 'host', url: normalized, query: trimmed }
145
+ }
146
+
147
+ function addressTarget(value: string, applicationOrigin?: string):
148
+ | { readonly ok: true; readonly target: BrowserTarget }
149
+ | { readonly ok: false; readonly reason: OmniboxRefusal } {
150
+ const parsed = parseBrowserAddress(value, applicationOrigin)
151
+ return parsed.ok ? { ok: true, target: parsed.target } : { ok: false, reason: parsed.reason }
152
+ }
153
+
154
+ /**
155
+ * Build one engine's result address.
156
+ * @param engine - validated search endpoint.
157
+ * @param query - keyword text encoded once through URLSearchParams.
158
+ * @param applicationOrigin - current DSH origin, refused by strict admission.
159
+ * @returns the target, or undefined when the engine cannot be used safely.
160
+ */
161
+ export function buildSearchTarget(engine: SearchEngine, query: string,
162
+ applicationOrigin?: string): BrowserTarget | undefined {
163
+ if (engine.queryParameter === '') return undefined
164
+ let url: URL
165
+ try { url = new URL(engine.searchUrl) } catch { return undefined }
166
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return undefined
167
+ try {
168
+ for (const [name, value] of Object.entries(engine.extraParameters ?? {})) url.searchParams.set(name, value)
169
+ url.searchParams.set(engine.queryParameter, query)
170
+ } catch { return undefined }
171
+ const parsed = parseBrowserAddress(url.href, applicationOrigin)
172
+ if (!parsed.ok) return undefined
173
+ return { ...parsed.target, title: query }
174
+ }
175
+
176
+ function strictNavigation(value: string, source: 'explicit' | 'host',
177
+ options: OmniboxOptions): OmniboxResolution {
178
+ const parsed = parseBrowserAddress(value, options.applicationOrigin)
179
+ if (!parsed.ok) return { kind: 'refused', reason: parsed.reason }
180
+ return { kind: 'resolved', primary: { kind: 'navigate', target: parsed.target, source } }
181
+ }
182
+
183
+ function resolveSearch(query: string, options: OmniboxOptions): OmniboxResolution {
184
+ const engine = options.searchEngines.find(candidate => candidate.id === options.defaultSearchEngineId)
185
+ if (engine === undefined) return { kind: 'refused', reason: 'engine-unavailable' }
186
+ const target = buildSearchTarget(engine, query, options.applicationOrigin)
187
+ if (target === undefined) return { kind: 'refused', reason: 'engine-unavailable' }
188
+ return { kind: 'resolved', primary: { kind: 'search', engineId: engine.id, query, target } }
189
+ }
190
+
191
+ /**
192
+ * Complete host-like input into an address; keyword-like input returns undefined.
193
+ * Local loopback services use HTTP, public hosts HTTPS, and a single intranet
194
+ * label needs an explicit scheme unless it names a port.
195
+ */
196
+ function normalizeHostInput(input: string): string | undefined {
197
+ if (/\s/u.test(input)) return undefined
198
+ const protocolRelative = input.startsWith('//')
199
+ const value = protocolRelative ? input.slice(2) : input
200
+ if (value === '') return undefined
201
+ const boundary = value.search(/[/?#]/u)
202
+ const authority = boundary === -1 ? value : value.slice(0, boundary)
203
+ const suffix = boundary === -1 ? '' : value.slice(boundary)
204
+ if (authority === '') return undefined
205
+ const match = HOST_AUTHORITY.exec(authority)
206
+ if (match === null) return undefined
207
+ const host = match[1]
208
+ if (host === undefined) return undefined
209
+ const port = match[2]
210
+ const ipv6 = host.startsWith('[')
211
+ const bare = ipv6 ? host.slice(1, -1) : host
212
+ const local = isLoopbackHost(bare)
213
+ if (!local && !ipv6) {
214
+ if (IPV4_OR_VERSION.test(bare)) {
215
+ const octets = bare.split('.')
216
+ // A dotted number without exactly four in-range octets is a version, not a host.
217
+ if (octets.length !== 4 || octets.some(octet => Number(octet) > 255)) return undefined
218
+ } else if (!bare.includes('.')) {
219
+ if (port === undefined) return undefined
220
+ // A single intranet label with an explicit port is an HTTP service.
221
+ return validHttpUrl(`http://${authority}${suffix}`) ? `http://${authority}${suffix}` : undefined
222
+ }
223
+ }
224
+ const completed = `${local ? 'http' : 'https'}://${authority}${suffix}`
225
+ return validHttpUrl(completed) ? completed : undefined
226
+ }
227
+
228
+ function isLoopbackHost(host: string): boolean {
229
+ const normalized = host.toLowerCase()
230
+ if (normalized === 'localhost' || normalized.endsWith('.localhost')) return true
231
+ if (IPV4_OR_VERSION.test(normalized) && normalized.includes('.')) {
232
+ const octets = normalized.split('.')
233
+ if (octets.length === 4 && octets.every(octet => Number(octet) <= 255)) return octets[0] === '127'
234
+ }
235
+ return normalized === '::1' || normalized === '0:0:0:0:0:0:0:1'
236
+ }
237
+
238
+ function validHttpUrl(value: string): boolean {
239
+ try {
240
+ const url = new URL(value)
241
+ return (url.protocol === 'http:' || url.protocol === 'https:') && url.username === '' && url.password === ''
242
+ } catch { return false }
243
+ }
@@ -0,0 +1,38 @@
1
+ /** Persisted Browser tab snapshots shared by the body and title slots. */
2
+ import { defineStore, type EngineStoreHandle } from '@deepseek-ai/dsh-client-store'
3
+ import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
4
+ import type { BrowserTabState } from './BrowserPersistence.ts'
5
+
6
+ /** All Browser tabs in one Session-scoped store. */
7
+ export interface BrowserState {
8
+ byTab: Record<TabId, BrowserTabState>
9
+ }
10
+
11
+ type BrowserActions = {
12
+ replace: (draft: BrowserState, tabId: TabId, state: BrowserTabState) => void
13
+ forget: (draft: BrowserState, tabId: TabId) => void
14
+ }
15
+
16
+ /**
17
+ * Declare the Session-scoped Browser persistence store.
18
+ * @returns a fresh store handle for Slot registration.
19
+ */
20
+ export function createBrowserStore(): EngineStoreHandle<BrowserState, BrowserActions> {
21
+ return defineStore({
22
+ init: (): BrowserState => ({ byTab: {} }),
23
+ persist: 'dsh.sidebar-browser.v1',
24
+ actions: {
25
+ replace: (draft, tabId: TabId, state: BrowserTabState) => { draft.byTab[tabId] = state },
26
+ forget: (draft, tabId: TabId) => {
27
+ const byTab: BrowserState['byTab'] = {}
28
+ for (const [id, state] of Object.entries(draft.byTab) as [TabId, BrowserTabState][]) {
29
+ if (id !== tabId) byTab[id] = state
30
+ }
31
+ draft.byTab = byTab
32
+ },
33
+ },
34
+ })
35
+ }
36
+
37
+ /** Browser store handle shared by body and title registrations. */
38
+ export type BrowserStore = ReturnType<typeof createBrowserStore>
@@ -0,0 +1,72 @@
1
+ import { referenceOwnerKey } from '../../reference-owner.ts'
2
+ import { TAKEOVER_ROUTE, type TakeoverNotice, type TakeoverSummary } from '../../takeover-protocol.ts'
3
+
4
+ const readers = new Map<string, { owner: string; read: (signal: AbortSignal) => Promise<TakeoverSummary> }>()
5
+
6
+ export function registerTakeoverSummary(pageId: string, owner: string, read: (signal: AbortSignal) => Promise<TakeoverSummary>): () => void {
7
+ const reader = { owner: referenceOwnerKey(owner), read }
8
+ readers.set(pageId, reader)
9
+ return () => { if (readers.get(pageId) === reader) readers.delete(pageId) }
10
+ }
11
+
12
+ export async function readTakeoverSummary(pageId: string, owner: string, signal: AbortSignal): Promise<TakeoverSummary> {
13
+ const reader = readers.get(pageId)
14
+ if (!reader || reader.owner !== referenceOwnerKey(owner)) throw new Error('takeover source is unavailable')
15
+ return reader.read(signal)
16
+ }
17
+
18
+ export function connectBrowserTakeover(options: {
19
+ readonly owner: string
20
+ readonly tabId: string
21
+ readonly pageId: string
22
+ readonly current: () => { url: string; active: boolean; navigationUrl?: string }
23
+ readonly changed: (notice?: TakeoverNotice, error?: boolean) => void
24
+ }, signal: AbortSignal): { answer(outcome: 'done' | 'skipped'): Promise<void> } {
25
+ let lease: string | undefined, notice: TakeoverNotice | undefined, timer: ReturnType<typeof setTimeout> | undefined
26
+ let answering = false
27
+ const post = async (body: object): Promise<{ lease?: string; notice?: TakeoverNotice }> => {
28
+ const response = await fetch(TAKEOVER_ROUTE, { method: 'POST', credentials: 'include',
29
+ headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), signal })
30
+ if (!response.ok) {
31
+ if (response.status === 400) lease = undefined
32
+ throw new Error('browser takeover channel unavailable')
33
+ }
34
+ return response.json()
35
+ }
36
+ const poll = async (): Promise<void> => {
37
+ try {
38
+ if (!lease) {
39
+ const registered = await post({ operation: 'register', owner: options.owner, tabId: options.tabId, pageId: options.pageId, ...options.current() })
40
+ lease = registered.lease
41
+ if (!lease) throw new Error('browser takeover lease missing')
42
+ }
43
+ const result = await post({ operation: 'poll', lease, ...options.current() })
44
+ notice = result.notice
45
+ if (!signal.aborted) options.changed(notice?.phase === 'waiting' && !answering ? notice : undefined)
46
+ if (notice?.phase === 'summary' && options.pageId.startsWith('iframe:')) {
47
+ const summary = await readTakeoverSummary(options.pageId, options.owner, AbortSignal.any([signal, AbortSignal.timeout(5000)]))
48
+ await post({ operation: 'summary', lease, id: notice.id, summary })
49
+ }
50
+ } catch {
51
+ if (!signal.aborted) options.changed(undefined)
52
+ }
53
+ if (!signal.aborted) timer = setTimeout(() => { void poll() }, 400)
54
+ }
55
+ const stop = (): void => {
56
+ clearTimeout(timer)
57
+ options.changed(undefined)
58
+ if (lease) void fetch(TAKEOVER_ROUTE, { method: 'POST', credentials: 'include', keepalive: true,
59
+ headers: { 'content-type': 'application/json' }, body: JSON.stringify({ operation: 'remove', lease }) }).catch(() => {})
60
+ }
61
+ signal.addEventListener('abort', stop, { once: true })
62
+ if (!signal.aborted) void poll()
63
+ return { async answer(outcome) {
64
+ if (!notice || notice.phase !== 'waiting' || answering || signal.aborted) return
65
+ answering = true
66
+ const current = notice
67
+ options.changed(undefined)
68
+ try { await post({ operation: 'answer', lease, id: current.id, outcome }) }
69
+ catch { if (!signal.aborted) options.changed(current, true) }
70
+ finally { answering = false }
71
+ } }
72
+ }
@@ -0,0 +1,46 @@
1
+ /** Address parsing for the Sidebar browser's HTTP(S) allowlist. */
2
+
3
+ /** Maximum accepted address length; this bounds persisted navigation state. */
4
+ export const MAX_BROWSER_URL_LENGTH = 16 * 1024
5
+
6
+ /** A normalized Browser navigation target. */
7
+ export type BrowserTarget =
8
+ | { readonly kind: 'blank'; readonly url: 'about:blank'; readonly title: string }
9
+ | { readonly kind: 'https'; readonly url: string; readonly title: string }
10
+ | { readonly kind: 'http'; readonly url: string; readonly title: string }
11
+
12
+ /** Why an address was refused before navigation. */
13
+ export type BrowserAddressFailure = 'empty' | 'invalid' | 'protocol' | 'credentials' | 'application-origin'
14
+
15
+ /** Result of parsing an address-bar value. */
16
+ export type BrowserAddressResult =
17
+ | { readonly ok: true; readonly target: BrowserTarget }
18
+ | { readonly ok: false; readonly reason: BrowserAddressFailure }
19
+
20
+ /**
21
+ * Parse one address-bar value into the fixed protocol allowlist.
22
+ * @param input - user or typed-open input.
23
+ * @param applicationOrigin - current DSH document origin, blocked for HTTPS.
24
+ * @returns a canonical target or the refusal reason.
25
+ */
26
+ export function parseBrowserAddress(input: string, applicationOrigin?: string): BrowserAddressResult {
27
+ const trimmed = input.trim()
28
+ if (trimmed === '') return { ok: false, reason: 'empty' }
29
+ if (trimmed.length > MAX_BROWSER_URL_LENGTH) return { ok: false, reason: 'invalid' }
30
+ const explicitScheme = /^[A-Za-z][A-Za-z\d+.-]*:(?!\d+(?:[/?#]|$))/u.test(trimmed)
31
+ const candidate = explicitScheme ? trimmed : `https://${trimmed}`
32
+ let url: URL
33
+ try { url = new URL(candidate) } catch { return { ok: false, reason: 'invalid' } }
34
+ if (url.username !== '' || url.password !== '') return { ok: false, reason: 'credentials' }
35
+ if (url.protocol === 'https:' || url.protocol === 'http:') {
36
+ if (applicationOrigin !== undefined && applicationOrigin !== 'null') {
37
+ try {
38
+ if (url.origin === new URL(applicationOrigin).origin) return { ok: false, reason: 'application-origin' }
39
+ } catch {
40
+ // An unavailable application origin cannot grant access to a target.
41
+ }
42
+ }
43
+ return { ok: true, target: { kind: url.protocol === 'https:' ? 'https' : 'http', url: url.href, title: url.hostname } }
44
+ }
45
+ return { ok: false, reason: 'protocol' }
46
+ }