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,109 @@
1
+ /**
2
+ * Sidebar guest proxy policy — pure helpers, no Electron imports.
3
+ *
4
+ * WHY THIS EXISTS
5
+ * The Sidebar browser uses an in-memory `session.fromPartition(...)` guest
6
+ * session. By default Chromium resolves that session's proxy from the OS. On
7
+ * machines with a system-wide rules proxy (for example 127.0.0.1:7890), every
8
+ * CONNECT goes through the proxy's exit node. Some first-party DeepSeek pages
9
+ * are then rejected by AWS WAF / CloudFront with the "Request blocked" 403
10
+ * page, while the very same URL answers 200 when connected directly. A normal
11
+ * browser on that machine is unaffected because its per-process proxy rules
12
+ * send those hosts direct.
13
+ *
14
+ * POLICY
15
+ * DEFAULT IS DIRECT. A global rules proxy (e.g. 127.0.0.1:7890) is usually
16
+ * slower than a direct connection for ordinary sites, and on this class of
17
+ * machine the sidebar was measurably 15-20x slower when forced through it
18
+ * (baidu load 21.6s via proxy vs 1.1s direct). The guest session therefore
19
+ * does NOT inherit the OS proxy unless the user explicitly asks for it.
20
+ *
21
+ * When a proxy IS wanted, `auto` re-expresses the resolved system proxy as
22
+ * `fixed_servers` plus a bypass list, because Electron ignores
23
+ * `proxyBypassRules` in `system` mode. `system` leaves the OS settings alone.
24
+ * If the machine has no proxy, `auto` leaves the session in `system` mode so a
25
+ * VPN/rules proxy switched on later is picked up without restarting the app.
26
+ *
27
+ * Overrides: DSH_SIDEBAR_PROXY_MODE=direct|auto|system,
28
+ * DSH_SIDEBAR_PROXY_BYPASS=<chromium bypass rules>,
29
+ * DSH_SIDEBAR_PROXY_RULES=<chromium proxyRules>.
30
+ *
31
+ * If a direct connection cannot be established at all (`did-fail-load` with a
32
+ * DNS/connection error), the bridge retries that session once through the
33
+ * system proxy — see `shouldFallbackToSystemProxy`.
34
+ */
35
+
36
+ /** Hosts that must never be forced through the user's global proxy. */
37
+ export const DEFAULT_SIDEBAR_PROXY_BYPASS = 'deepseek.com;*.deepseek.com;localhost;127.0.0.1'
38
+
39
+ /**
40
+ * Chromium net error codes worth retrying through the system proxy: name not
41
+ * resolved, cannot connect, connection closed/timed out, address unreachable.
42
+ * A 404/500 must NOT trigger the fallback — only transport failures.
43
+ */
44
+ const PROXY_FALLBACK_ERRORS = new Set([-105, -106, -109, -118, -130, -137, -138])
45
+
46
+ /** @param {number} errorCode Chromium net error from `did-fail-load`. */
47
+ export function shouldFallbackToSystemProxy(errorCode) {
48
+ return PROXY_FALLBACK_ERRORS.has(Number(errorCode))
49
+ }
50
+
51
+ /**
52
+ * Turn Electron's `session.resolveProxy()` answer into Chromium proxyRules.
53
+ * @param {string} resolved - e.g. "PROXY 127.0.0.1:7890", "SOCKS5 127.0.0.1:7891", "DIRECT".
54
+ * @returns {{ rules: string, authority: string } | undefined}
55
+ */
56
+ export function parseSystemProxy(resolved) {
57
+ const first = String(resolved ?? '').split(';')[0].trim()
58
+ const match = /^(PROXY|HTTPS|HTTP|SOCKS5?|SOCKS)\s+(\S+)$/iu.exec(first)
59
+ if (!match) return undefined
60
+ const scheme = match[1].toUpperCase()
61
+ const authority = match[2]
62
+ // Bare host:port (optionally a scheme-less IPv6 literal is not accepted by
63
+ // Chromium here). Refuse anything else so a malformed answer cannot inject
64
+ // extra proxy rules into the session.
65
+ if (!/^[A-Za-z0-9._:-]+$/u.test(authority)) return undefined
66
+ const rules = scheme.startsWith('SOCKS') ? `socks=${authority}` : `http=${authority};https=${authority}`
67
+ return { rules, authority }
68
+ }
69
+
70
+ /**
71
+ * Strip the Electron/application tokens from a guest's User-Agent.
72
+ *
73
+ * Electron's default UA reads like
74
+ * `Mozilla/5.0 (...) AppleWebKit/537.36 (KHTML, like Gecko) @deepseek-ai/dsh-desktop/0.2.2-rc.1 Chrome/152.0.7977.130 Electron/44.7.0 Safari/537.36`.
75
+ * Site-side bot / risk controls (DeepSeek's "使用环境异常", Baidu's security
76
+ * checks, and similar banners on most sites) key off those tokens and treat
77
+ * the embedded webview as a non-standard client. A stock Chrome UA avoids the
78
+ * false positive while keeping the real Chromium version, so feature detection
79
+ * still works.
80
+ *
81
+ * @param {string} raw - the session's current user agent.
82
+ * @returns {string} a stock-Chrome-shaped user agent.
83
+ */
84
+ export function normalizeGuestUserAgent(raw) {
85
+ return String(raw ?? '')
86
+ // Drop EVERY product token the app injected between the Gecko marker and
87
+ // Chrome/ — Electron can add more than one (app name, build tag), and a
88
+ // single-token regex would leave the rest visible to site-side checks.
89
+ .replace(/(\(KHTML, like Gecko\))(?:\s+\S+)+?(?=\s+Chrome\/)/giu, '$1')
90
+ // Electron / app tokens can also be appended after the Chrome version.
91
+ .replace(/\s+(?:Electron\/[^\s]+|@deepseek-ai\/[^\s]+|DeepSeekHarness\/[^\s]+)/giu, '')
92
+ .trim()
93
+ }
94
+
95
+ /**
96
+ * @param {{ mode?: string, resolved?: string, bypass?: string, rules?: string }} [input]
97
+ * @returns {object | undefined} Electron `session.setProxy` config, or undefined to leave OS settings alone.
98
+ */
99
+ export function sidebarProxyConfig({ mode = 'direct', resolved = '', bypass = DEFAULT_SIDEBAR_PROXY_BYPASS, rules } = {}) {
100
+ const policy = String(mode ?? 'direct').trim().toLowerCase()
101
+ if (policy === 'system') return undefined
102
+ if (policy === 'direct') return { mode: 'direct' }
103
+ const parsed = rules ? { rules } : parseSystemProxy(resolved)
104
+ // No usable proxy: do not override the session at all. Pinning `direct`
105
+ // would freeze the setting and break sites as soon as the user enables a
106
+ // proxy later in the same app session.
107
+ if (!parsed) return undefined
108
+ return { mode: 'fixed_servers', proxyRules: parsed.rules, proxyBypassRules: bypass }
109
+ }
@@ -65,8 +65,14 @@
65
65
  * start the already-closed app after maintenance; it never closes a running application.
66
66
  */
67
67
  import * as nodeFs from 'node:fs'
68
+ import { applyHostPatch, hostPatchStatus, restoreHostPatch } from '../dsh-host-patch/apply.mjs'
69
+ import { renameMaintenanceFileSync } from './maintenance-files.mjs'
70
+ import { isDesktopExecutable } from './desktop-processes.mjs'
71
+ import { conventionalInstallRoots, registeredInstallLocations } from './desktop-discovery.mjs'
72
+ import { legacyBridgeMarker as MARKER, legacyBridgeSnippet as SNIPPET } from '../dsh-host-patch/legacy-bridge.mjs'
68
73
  import { execFileSync, spawn } from 'node:child_process'
69
74
  import { createRequire } from 'node:module'
75
+ import { homedir } from 'node:os'
70
76
 
71
77
  /**
72
78
  * The filesystem used for every installer operation.
@@ -87,7 +93,7 @@ const archiveFs = (() => {
87
93
  })()
88
94
  const { closeSync, copyFileSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readSync,
89
95
  readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } = archiveFs
90
- import { dirname, isAbsolute, join, relative, resolve } from 'node:path'
96
+ import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
91
97
 
92
98
  function isWithin(root, path) {
93
99
  const part = relative(root, path)
@@ -146,11 +152,14 @@ function findDefaultInstall(testRoot) {
146
152
  if (!isWithin(testRoot, resolve(candidate))) return false
147
153
  try { return isWithin(testRoot, realpathSync(candidate)) } catch { return false }
148
154
  }
149
- const looksInstalled = candidate => permitted(candidate) && (existsSync(join(candidate, 'resources', 'app', 'lib', 'main.js'))
150
- || existsSync(join(candidate, 'resources', 'app.asar')))
155
+ const looksInstalled = candidate => {
156
+ if (!permitted(candidate)) return false
157
+ const resources = layoutPaths(candidate)?.resources
158
+ return resources !== undefined && (existsSync(join(resources, 'app', 'lib', 'main.js')) || existsSync(join(resources, 'app.asar')))
159
+ }
151
160
  const probe = (base) => {
152
161
  if (!permitted(base)) return undefined
153
- for (const named of ['DSH Desktop', 'DeepSeek Harness']) {
162
+ for (const named of ['DSH Desktop', 'DeepSeek Harness', 'DSH Desktop.app', 'DeepSeek Harness.app']) {
154
163
  const candidate = join(base, named)
155
164
  if (looksInstalled(candidate)) return candidate
156
165
  }
@@ -167,23 +176,31 @@ function findDefaultInstall(testRoot) {
167
176
  }
168
177
  // Same roots the panel probes: an explicit DSH_DESKTOP_PATH, then the places people actually install
169
178
  // to. An install on another drive used to be invisible to both the panel and this default.
170
- const explicit = process.env.DSH_DESKTOP_PATH
171
- if (explicit !== undefined && explicit !== '') {
172
- if (looksInstalled(explicit)) return explicit
173
- const below = probe(explicit)
174
- if (below !== undefined) return below
179
+ for (const explicit of [process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP]) {
180
+ if (explicit !== undefined && explicit !== '') {
181
+ if (looksInstalled(explicit)) return explicit
182
+ const below = probe(explicit)
183
+ if (below !== undefined) return below
184
+ }
175
185
  }
176
186
  const localAppData = process.env.LOCALAPPDATA ?? ''
177
187
  const roots = [
178
188
  ...(localAppData === '' ? [] : [join(localAppData, 'Programs')]),
179
189
  process.env['ProgramFiles'], process.env['ProgramFiles(x86)'], process.env.APPDATA, process.env.ProgramData,
190
+ ...(process.platform === 'darwin' ? ['/Applications', join(homedir(), 'Applications')] : []),
180
191
  ].filter(base => typeof base === 'string' && base !== '')
181
192
  for (const base of roots) {
182
193
  const found = probe(base)
183
194
  if (found !== undefined) return found
184
195
  }
196
+ for (const source of [registeredInstallLocations, conventionalInstallRoots]) {
197
+ for (const candidate of source()) {
198
+ if (looksInstalled(candidate)) return candidate
199
+ }
200
+ }
185
201
  return testRoot === undefined
186
- ? join(localAppData === '' ? '.' : join(localAppData, 'Programs'), 'DeepSeek Harness')
202
+ ? process.platform === 'darwin' ? '/Applications/DeepSeek Harness.app'
203
+ : join(localAppData === '' ? '.' : join(localAppData, 'Programs'), 'DeepSeek Harness')
187
204
  : join(testRoot, 'no-test-desktop-found')
188
205
  }
189
206
 
@@ -219,14 +236,24 @@ function selectShellProcesses(rows, root, selfPid) {
219
236
  ancestors.add(cursor)
220
237
  cursor = byPid.get(cursor)?.ParentProcessId
221
238
  }
222
- const expectedExe = resolve(root, 'DeepSeek Harness.exe').toLowerCase()
239
+ // Windows compares case-insensitively. Elsewhere the on-disk spelling decides: `realpathSync.native`
240
+ // returns the volume's own case, so `/applications/…` matches the running app on a case-insensitive
241
+ // APFS volume while `Apps` and `apps` stay distinct on a case-sensitive one.
242
+ const fold = process.platform === 'win32' ? value => value.toLowerCase()
243
+ : value => { try { return realpathSync.native(value) } catch { return value } }
244
+ const layout = layoutPaths(root)
245
+ const expectedExe = fold(resolve(layout.executable))
246
+ const expectedName = fold(basename(expectedExe))
247
+ const bundleRoot = process.platform === 'darwin' && layout.name === 'macos-bundle' ? root : undefined
223
248
  const selected = []
224
249
  for (const row of rows) {
225
- if (String(row.Name ?? '').toLowerCase() !== 'deepseek harness.exe') continue
250
+ const namedMain = fold(String(row.Name ?? '')) === expectedName
251
+ if (bundleRoot === undefined && !namedMain) continue
226
252
  if (typeof row.ExecutablePath !== 'string' || row.ExecutablePath === '') {
253
+ if (!namedMain && !/ Helper(?: \([^)]*\))?$/.test(String(row.Name ?? ''))) continue
227
254
  throw new Error('could not identify a running DeepSeek Harness process; refusing to close or patch the application')
228
255
  }
229
- if (resolve(row.ExecutablePath).toLowerCase() !== expectedExe) continue
256
+ if (!isDesktopExecutable(row.ExecutablePath, expectedExe, bundleRoot, process.platform)) continue
230
257
  if (!Number.isSafeInteger(row.ProcessId) || row.ProcessId <= 0 || typeof row.CommandLine !== 'string') {
231
258
  throw new Error('the Desktop process table is incomplete; refusing to close or patch the application')
232
259
  }
@@ -250,6 +277,7 @@ function selectShellProcesses(rows, root, selfPid) {
250
277
  * @returns GUI and Chromium helper process ids.
251
278
  */
252
279
  function shellProcesses(root) {
280
+ if (process.platform === 'darwin') return selectShellProcesses(posixProcessTable(), root, process.pid)
253
281
  const text = runCapture('powershell.exe', [
254
282
  '-NoProfile', '-NonInteractive', '-Command',
255
283
  '[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); '
@@ -266,15 +294,44 @@ function shellProcesses(root) {
266
294
  return selectShellProcesses(rows, root, process.pid)
267
295
  }
268
296
 
297
+ /**
298
+ * The process table on macOS/Linux, in the shape the Windows CIM query returns.
299
+ * `comm` is the full executable path (it may contain spaces, so it is read in its own pass);
300
+ * `args` is the command line the node-mode filter reads.
301
+ * @returns every process row.
302
+ */
303
+ function posixProcessTable() {
304
+ const environment = { ...process.env, LC_ALL: 'C', LANG: 'C' }
305
+ const executables = runCapture('ps', ['-axww', '-o', 'pid=,ppid=,comm='], environment)
306
+ const commands = runCapture('ps', ['-axww', '-o', 'pid=,args='], environment)
307
+ if (executables === undefined || commands === undefined) throw new Error('could not enumerate Desktop processes')
308
+ const byPid = new Map()
309
+ for (const line of commands.split('\n')) {
310
+ const match = /^\s*(\d+)\s(.*)$/.exec(line)
311
+ if (match !== null) byPid.set(Number(match[1]), match[2])
312
+ }
313
+ const rows = []
314
+ for (const line of executables.split('\n')) {
315
+ const match = /^\s*(\d+)\s+(\d+)\s(.*)$/.exec(line)
316
+ if (match === null) continue
317
+ const path = match[3].trim()
318
+ rows.push({ ProcessId: Number(match[1]), ParentProcessId: Number(match[2]), Name: basename(path),
319
+ ExecutablePath: isAbsolute(path) ? path : '', CommandLine: byPid.get(Number(match[1])) ?? '' })
320
+ }
321
+ if (rows.length === 0) throw new Error('the Desktop process table is invalid')
322
+ return rows
323
+ }
324
+
269
325
  /**
270
326
  * Run a command and return its stdout, or undefined when it could not run.
271
327
  * @param command - the executable.
272
328
  * @param argv - its arguments.
273
329
  * @returns stdout text, or undefined.
274
330
  */
275
- function runCapture(command, argv) {
331
+ function runCapture(command, argv, environment) {
276
332
  try {
277
- return execFileSync(command, argv, { encoding: 'utf8', stdio: 'pipe', windowsHide: true, timeout: 30_000 })
333
+ return execFileSync(command, argv, { encoding: 'utf8', stdio: 'pipe', windowsHide: true, timeout: 30_000,
334
+ ...(environment === undefined ? {} : { env: environment }) })
278
335
  } catch {
279
336
  return undefined
280
337
  }
@@ -290,7 +347,7 @@ function runCapture(command, argv) {
290
347
  */
291
348
  let lastStartedPid
292
349
  function startShell(root) {
293
- const exe = join(root, 'DeepSeek Harness.exe')
350
+ const exe = layoutPaths(root).executable
294
351
  if (!existsSync(exe)) {
295
352
  console.error(`could not start DSH Desktop: ${exe} does not exist; start it yourself.`)
296
353
  return false
@@ -339,15 +396,43 @@ const revert = args.includes('--revert')
339
396
  /** Start after maintenance only when the target was already closed; never close a running shell. */
340
397
  const restart = args.includes('--restart')
341
398
 
342
- const resourcesDir = join(installRoot, 'resources')
399
+ const installPaths = layoutPaths(installRoot) ?? process.exit(1)
400
+ const resourcesDir = installPaths.resources
343
401
  const appDir = join(resourcesDir, 'app')
344
402
  const asarPath = join(resourcesDir, 'app.asar')
345
403
  const asarMoved = `${asarPath}.before-bridge`
346
404
  const mainPath = join(appDir, 'lib', 'main.js')
347
405
  const bridgeTarget = join(appDir, 'lib', 'plugin-browser-bridge.js')
348
- const bridgeSource = join(import.meta.dirname, 'plugin-browser-bridge.js')
406
+ const bridgeSource = join(import.meta.dirname, 'profile-loader.mjs')
407
+ const bridgeBackup = bridgeTarget + '.before-profile-loader'
408
+ const bridgeAbsent = bridgeBackup + '.absent'
349
409
  const backupPath = `${mainPath}.before-bridge`
350
410
 
411
+ function validateBridgeLoaderBaseline() {
412
+ if (existsSync(bridgeBackup) && existsSync(bridgeAbsent)) throw new Error('Conflicting bridge loader restore baselines')
413
+ if (!existsSync(bridgeTarget)) return
414
+ const current = readFileSync(bridgeTarget)
415
+ if (current.equals(readFileSync(bridgeSource))) return
416
+ if (existsSync(bridgeAbsent) || (existsSync(bridgeBackup) && !current.equals(readFileSync(bridgeBackup)))) {
417
+ throw new Error('Bridge module differs from its preserved restore baseline')
418
+ }
419
+ }
420
+
421
+ function installBridgeLoader() {
422
+ validateBridgeLoaderBaseline()
423
+ if (!existsSync(bridgeBackup) && !existsSync(bridgeAbsent)) {
424
+ if (existsSync(bridgeTarget)) copyFileSync(bridgeTarget, bridgeBackup)
425
+ else writeFileSync(bridgeAbsent, '')
426
+ }
427
+ copyFileSync(bridgeSource, bridgeTarget)
428
+ }
429
+
430
+ function restoreBridgeLoader() {
431
+ validateBridgeLoaderBaseline()
432
+ if (existsSync(bridgeBackup)) copyFileSync(bridgeBackup, bridgeTarget)
433
+ else if (existsSync(bridgeAbsent)) rmSync(bridgeTarget, { force: true })
434
+ }
435
+
351
436
  // Moving the archive aside breaks two more places that spell `app.asar` out
352
437
  // loud, and both are used by `dsh <args>` (the Desktop CLI launcher and the
353
438
  // plugin manager behind it), so they are patched here and restored by --revert:
@@ -357,7 +442,7 @@ const backupPath = `${mainPath}.before-bridge`
357
442
  //
358
443
  // Without them the CLI dies with MODULE_NOT_FOUND even though the app itself
359
444
  // runs fine (the shell resolves everything through app.getAppPath()).
360
- const cliShimPath = join(resourcesDir, 'runtime', 'cli', 'bin', 'dsh.cmd')
445
+ const cliShimPath = installPaths.cliLauncher
361
446
  const cliShimBackup = `${cliShimPath}.before-bridge`
362
447
  const hostCliPath = join(appDir, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-desktop-host', 'lib', 'cli.js')
363
448
  const hostCliBackup = `${hostCliPath}.before-bridge`
@@ -365,6 +450,7 @@ const CLI_SHIM_MARKER = 'dsh-builtin-browser: resolve the app directory'
365
450
  const HOST_CLI_MARKER = 'dsh-builtin-browser: recognize an unpacked `app` directory'
366
451
 
367
452
  let targetWasClosed = false
453
+ let hostPatch
368
454
  const resultFile = process.env.DSH_BRIDGE_ACTION_RESULT_FILE
369
455
  const installErrors = []
370
456
  if (resultFile !== undefined) {
@@ -392,11 +478,12 @@ process.once('exit', code => {
392
478
  ...lastStartedPid === undefined ? {} : { pid: lastStartedPid },
393
479
  ...installErrors.length === 0 ? {} : { error: installErrors.join('\n').slice(-2400) },
394
480
  completedAt: new Date().toISOString(),
481
+ ...hostPatch === undefined ? {} : { hostPatch },
395
482
  }
396
483
  try {
397
484
  const temporary = `${resultFile}.${process.pid}.tmp`
398
485
  writeFileSync(temporary, JSON.stringify(result))
399
- renameSync(temporary, resultFile)
486
+ renameMaintenanceFileSync(temporary, resultFile, { rename: renameSync })
400
487
  } catch (error) {
401
488
  originalResultError(error)
402
489
  }
@@ -405,50 +492,9 @@ process.once('exit', code => {
405
492
 
406
493
  function originalResultError(error) {
407
494
  console.error('could not record the bridge installer result: ' + String(error))
408
- process.exitCode = 1
495
+ process.exitCode = process.exitCode || 1
409
496
  }
410
497
 
411
- /** The exact block appended to main.js. Keep it recognisable: idempotence and
412
- * reverting both key off this marker. */
413
- const MARKER = '// dsh-builtin-browser: hand the plugin a way to drive the sidebar'
414
- const SNIPPET = `
415
- ${MARKER} pages.
416
- // The plugin runs inside the Node-mode host, where there is no Electron API, so the
417
- // shell is the only process that can own a view. Exposing the existing webview
418
- // guests (and their CDP) is what lets the agent work on the page the human is
419
- // looking at, instead of spawning a second, parallel browser window.
420
- // Installed by apps/desktop/bridge/install.mjs — re-run it after a desktop upgrade.
421
- // A bridge failure is never fatal to the shell.
422
- app.whenReady().then(async () => {
423
- const bridgeUrl = new URL("./plugin-browser-bridge.js", import.meta.url);
424
- const loadBridge = async (why) => {
425
- try {
426
- // A plain import is cached for the process lifetime, so an edited bridge
427
- // would need a shell restart. The stamp makes every load read the current
428
- // bytes; start() itself stops the previous instance, so this reloads in place.
429
- const bridge = await import(bridgeUrl.href + "?v=" + Date.now());
430
- bridge.start();
431
- console.log("[dsh-browser-bridge] started" + (why ? " (" + why + ")" : ""));
432
- } catch (error) {
433
- console.error("[dsh-browser-bridge] start failed:", error);
434
- }
435
- };
436
- await loadBridge();
437
- // Watch the module so an edit reloads it in place instead of forcing a shell
438
- // restart. Debounced; a failure here is never fatal to the shell.
439
- try {
440
- const { watch } = await import("node:fs");
441
- let timer = null;
442
- watch(bridgeUrl, { persistent: false }, () => {
443
- if (timer) clearTimeout(timer);
444
- timer = setTimeout(() => void loadBridge("file changed"), 300);
445
- });
446
- } catch (error) {
447
- console.error("[dsh-browser-bridge] watch failed:", error);
448
- }
449
- });
450
- `
451
-
452
498
  /**
453
499
  * Parse an asar header — a Chromium pickle holding
454
500
  * `[payloadSize][jsonLength][json…]`, preceded by an 8-byte outer pickle.
@@ -538,6 +584,7 @@ function patchCliShim() {
538
584
  if (!existsSync(cliShimPath)) return 'launcher not present (skipped)'
539
585
  const text = readFileSync(cliShimPath, 'utf8')
540
586
  if (text.includes(CLI_SHIM_MARKER)) return 'already patched'
587
+ if (!cliShimPath.endsWith('.cmd')) return patchPosixCliShim(text)
541
588
  if (!/%~dp0(?:\.\.\\)+app\.asar\\dsh\\/.test(text)) return 'unexpected launcher shape (skipped)'
542
589
  if (!existsSync(cliShimBackup)) copyFileSync(cliShimPath, cliShimBackup)
543
590
  const eol = text.includes('\r\n') ? '\r\n' : '\n'
@@ -555,6 +602,27 @@ function patchCliShim() {
555
602
  return 'patched'
556
603
  }
557
604
 
605
+ /**
606
+ * The macOS launcher (`runtime/cli/bin/dsh`, a POSIX shell script) spells
607
+ * `$resources/app.asar/dsh/…` the same way the Windows one does; it gets the same treatment.
608
+ * @param text - the launcher's current text.
609
+ * @returns what happened, for the install log.
610
+ */
611
+ function patchPosixCliShim(text) {
612
+ const resourcesLine = /^resources=.*$/m.exec(text)
613
+ if (resourcesLine === null || !text.includes('"$resources/app.asar/dsh/')) return 'unexpected launcher shape (skipped)'
614
+ if (!existsSync(cliShimBackup)) copyFileSync(cliShimPath, cliShimBackup)
615
+ const injection = [
616
+ `# ${CLI_SHIM_MARKER} ($resources/app when the bridge is installed,`,
617
+ '# $resources/app.asar on a stock installation).',
618
+ 'dsh_app=$resources/app',
619
+ '[ -f "$dsh_app/dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js" ] || dsh_app=$resources/app.asar',
620
+ ].join('\n')
621
+ writeFileSync(cliShimPath, text.replace(resourcesLine[0], () => `${resourcesLine[0]}\n${injection}`)
622
+ .replace('"$resources/app.asar/dsh/', '"$dsh_app/dsh/'))
623
+ return 'patched'
624
+ }
625
+
558
626
  /**
559
627
  * Teach the Desktop CLI where its `runtime` directory is when the app is an
560
628
  * unpacked `app` directory rather than `app.asar`.
@@ -572,8 +640,10 @@ function patchHostCli() {
572
640
  if (!existsSync(hostCliPath)) return 'cli.js not present (skipped)'
573
641
  const text = readFileSync(hostCliPath, 'utf8')
574
642
  if (text.includes(HOST_CLI_MARKER)) return 'already patched'
575
- const before = '\tawait runDesktopCli(runtimeDir, join(dirname(runtimeArchivePath(runtimeDir) ?? runtimeDir), "runtime"));'
576
- if (!text.includes(before)) return 'unexpected cli.js shape (skipped)'
643
+ // Desktop builds differ in what else they pass (`runDesktopCli(runtimeDir, <support>)` in
644
+ // 0.2.2-rc.3, `runDesktopCli(<support>)` in rc.5); only the support-directory expression is ours.
645
+ const call = /^(\t)await runDesktopCli\(((?:runtimeDir, )?)join\(dirname\(runtimeArchivePath\(runtimeDir\) \?\? runtimeDir\), "runtime"\)\);$/m.exec(text)
646
+ if (call === null) return 'unexpected cli.js shape (skipped)'
577
647
  if (!existsSync(hostCliBackup)) copyFileSync(hostCliPath, hostCliBackup)
578
648
  const eol = text.includes('\r\n') ? '\r\n' : '\n'
579
649
  const after = [
@@ -581,9 +651,9 @@ function patchHostCli() {
581
651
  '\t// so an installation whose app.asar was moved aside still finds its runtime.',
582
652
  '\tconst cliOwnerDir = dirname(runtimeDir);',
583
653
  '\tconst cliSupportRoot = basename(cliOwnerDir) === "app" || basename(cliOwnerDir) === "app.asar" ? dirname(cliOwnerDir) : cliOwnerDir;',
584
- '\tawait runDesktopCli(runtimeDir, join(cliSupportRoot, "runtime"));',
654
+ `\tawait runDesktopCli(${call[2]}join(cliSupportRoot, "runtime"));`,
585
655
  ].join(eol)
586
- writeFileSync(hostCliPath, text.replace(before, after))
656
+ writeFileSync(hostCliPath, text.replace(call[0], after))
587
657
  return 'patched'
588
658
  }
589
659
 
@@ -616,18 +686,42 @@ function readIdentityRule() {
616
686
  const raw = JSON.parse(readFileSync(new URL('./desktop-identity.json', import.meta.url), 'utf8'))
617
687
  const names = raw.packageNames
618
688
  const mainEntry = raw.mainEntry
689
+ const layouts = raw.layouts
690
+ const field = value => typeof value === 'string' && value !== ''
619
691
  if (!Array.isArray(names) || names.length === 0 || names.some(name => typeof name !== 'string')
620
- || typeof mainEntry !== 'string' || mainEntry === '') {
621
- console.error('desktop-identity.json is malformed: expected packageNames[] and mainEntry')
692
+ || typeof mainEntry !== 'string' || mainEntry === ''
693
+ || !Array.isArray(layouts) || layouts.length === 0 || layouts.at(-1)?.marker !== undefined
694
+ || layouts.some(l => l === null || typeof l !== 'object' || !field(l.name) || !field(l.resources)
695
+ || !field(l.executable) || !field(l.cliLauncher) || (l.marker !== undefined && !field(l.marker)))) {
696
+ console.error('desktop-identity.json is malformed: expected packageNames[], mainEntry and layouts[]')
622
697
  return undefined
623
698
  }
624
- return { packageNames: names, mainEntry }
699
+ return { packageNames: names, mainEntry, layouts }
625
700
  } catch (error) {
626
701
  console.error(`desktop-identity.json could not be read: ${String(error)}`)
627
702
  return undefined
628
703
  }
629
704
  }
630
705
 
706
+ /**
707
+ * Absolute paths an install keeps, from the first layout (desktop-identity.json) whose marker it
708
+ * has: a macOS `.app` bundle keeps resources in Contents/Resources, a Windows install in resources/.
709
+ * @param root - the install directory.
710
+ * @returns resources directory, GUI executable and CLI launcher, or undefined without a rule.
711
+ */
712
+ function layoutPaths(root) {
713
+ const rule = readIdentityRule()
714
+ if (rule === undefined) return undefined
715
+ const layout = rule.layouts.find(l => l.marker === undefined || existsSync(join(root, ...l.marker.split('/'))))
716
+ const resources = join(root, ...layout.resources.split('/'))
717
+ return {
718
+ name: layout.name,
719
+ resources,
720
+ executable: join(root, ...layout.executable.split('/')),
721
+ cliLauncher: join(resources, ...layout.cliLauncher.split('/')),
722
+ }
723
+ }
724
+
631
725
  /**
632
726
  * Read one file out of an asar archive without extracting anything.
633
727
  *
@@ -745,7 +839,7 @@ function validateArchive(archive) {
745
839
  function verifyDesktopIdentity(root) {
746
840
  const rule = readIdentityRule()
747
841
  if (rule === undefined) return { ok: false, reason: 'the identity rule is unavailable' }
748
- const resources = join(root, 'resources')
842
+ const resources = layoutPaths(root).resources
749
843
  const archive = join(resources, 'app.asar')
750
844
  const appDir = join(resources, 'app')
751
845
  const archivePresent = existsSync(archive)
@@ -842,10 +936,25 @@ if (!existsSync(mainPath) && !existsSync(asarPath)) {
842
936
  }
843
937
 
844
938
  if (revert) {
939
+ validateBridgeLoaderBaseline()
940
+ const targets = [appDir, join(appDir, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-client-ui-sidebar-right')]
941
+ const hasHostBackup = [mainPath, join(targets[1], 'lib', 'client.js')]
942
+ .some(path => existsSync(path + '.before-dsh-host-patch'))
943
+ hostPatch = hasHostBackup ? restoreHostPatch(targets, { fs: archiveFs }) : hostPatchStatus(targets, { fs: archiveFs })
944
+ console.log('DSH host patch: ' + JSON.stringify(hostPatch))
945
+ if (hasHostBackup && hostPatch.status !== 'absent') {
946
+ console.error('refusing to uninstall over a host patch that cannot be safely restored: ' + hostPatch.reason)
947
+ process.exit(1)
948
+ }
949
+ if (hasHostBackup && readFileSync(mainPath, 'utf8').includes(MARKER)) {
950
+ restoreBridgeLoader()
951
+ console.log('restored the pre-install legacy bridge and sidebar; preserving its module copies, CLI and archive layout')
952
+ process.exit(0)
953
+ }
845
954
  // Tracked separately: restoring a CLI launcher or the runtime resolution is NOT an
846
955
  // uninstall. `reverted` only means some component was restored; whether the bridge is
847
956
  // actually gone is decided from the entry Electron loads, at the end of this branch.
848
- let reverted = false
957
+ let reverted = hasHostBackup && hostPatch.status === 'absent'
849
958
  let mainEntrySkipped = false
850
959
  if (existsSync(asarMoved)) {
851
960
  if (existsSync(asarPath)) {
@@ -961,6 +1070,7 @@ if (revert) {
961
1070
  if (packedLayout) {
962
1071
  console.log(`note: ${appDir} is inert while app.asar exists; delete it to reclaim ~350 MB`)
963
1072
  }
1073
+ restoreBridgeLoader()
964
1074
  process.exit(0)
965
1075
  }
966
1076
 
@@ -1009,9 +1119,22 @@ if (packedLayout) {
1009
1119
  }
1010
1120
 
1011
1121
  const current = readFileSync(mainPath, 'utf8')
1122
+ validateBridgeLoaderBaseline()
1123
+ const hostTargets = [appDir, join(appDir, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-client-ui-sidebar-right')]
1124
+ hostPatch = applyHostPatch(hostTargets, {
1125
+ fs: archiveFs,
1126
+ })
1127
+ console.log('DSH host patch: ' + JSON.stringify(hostPatch))
1128
+ if (hostPatch.status === 'applied' || current.includes('//#region lib/types/main-extensions.js')) {
1129
+ installBridgeLoader()
1130
+ console.log('bridge activation: DSH Desktop main extension (profile plugin); no main.js injection')
1131
+ installCliCompatibility()
1132
+ if (!restart) console.log('restart DSH Desktop to activate it.')
1133
+ process.exit(0)
1134
+ }
1012
1135
  if (current.includes(MARKER)) {
1013
- console.log('bridge already installed (main.js carries the marker); refreshing the module copy')
1014
- copyFileSync(bridgeSource, bridgeTarget)
1136
+ console.log('bridge already installed (main.js carries the marker); refreshing the profile loader')
1137
+ installBridgeLoader()
1015
1138
  installCliCompatibility()
1016
1139
  process.exit(0)
1017
1140
  }
@@ -1031,7 +1154,7 @@ if (insertAt === -1) {
1031
1154
  const patched = `${current.slice(0, insertAt)}${SNIPPET}${current.slice(insertAt)}`
1032
1155
  writeFileSync(mainPath, patched)
1033
1156
 
1034
- copyFileSync(bridgeSource, bridgeTarget)
1157
+ installBridgeLoader()
1035
1158
  console.log(`installed bridge into ${appDir}`)
1036
1159
  console.log(` module: ${bridgeTarget}`)
1037
1160
  console.log(` patch: ${mainPath} (+${SNIPPET.split('\n').length} lines)`)
@@ -0,0 +1,11 @@
1
+ import { start as startBridge, stop } from './plugin-browser-bridge.js'
2
+ import { readFileSync } from 'node:fs'
3
+ import { createHash } from 'node:crypto'
4
+
5
+ /** DSH Desktop main extension. The host owns startup and shutdown. */
6
+ export function start(api) {
7
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
8
+ const build = createHash('sha256').update(readFileSync(new URL('./plugin-browser-bridge.js', import.meta.url))).digest('hex')
9
+ startBridge({ ...api, owner: 'desktop-main', bridgeVersion: version, bridgeBuild: build })
10
+ return stop
11
+ }
@@ -0,0 +1,8 @@
1
+ export function renameMaintenanceFile(source: string, target: string, effects?: {
2
+ rename?: (source: string, target: string) => Promise<void>
3
+ pause?: (ms: number) => Promise<unknown>
4
+ }): Promise<void>
5
+ export function renameMaintenanceFileSync(source: string, target: string, effects?: {
6
+ rename?: (source: string, target: string) => void
7
+ pause?: (ms: number) => unknown
8
+ }): void
@@ -0,0 +1,28 @@
1
+ import { renameSync } from 'node:fs'
2
+ import { rename } from 'node:fs/promises'
3
+ import { setTimeout } from 'node:timers/promises'
4
+
5
+ const backoff = [20, 40, 80, 160, 250, 250, 250, 250]
6
+ const transient = error => ['EPERM', 'EBUSY', 'EACCES'].includes(error?.code)
7
+
8
+ export async function renameMaintenanceFile(source, target, effects = {}) {
9
+ const move = effects.rename ?? rename
10
+ const pause = effects.pause ?? setTimeout
11
+ for (let attempt = 0; ; attempt++) {
12
+ try { await move(source, target); return } catch (error) {
13
+ if (!transient(error) || attempt === backoff.length) throw error
14
+ await pause(backoff[attempt])
15
+ }
16
+ }
17
+ }
18
+
19
+ export function renameMaintenanceFileSync(source, target, effects = {}) {
20
+ const move = effects.rename ?? renameSync
21
+ const pause = effects.pause ?? (ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms))
22
+ for (let attempt = 0; ; attempt++) {
23
+ try { move(source, target); return } catch (error) {
24
+ if (!transient(error) || attempt === backoff.length) throw error
25
+ pause(backoff[attempt])
26
+ }
27
+ }
28
+ }
@@ -6,7 +6,7 @@ param(
6
6
  [string]$StatePath,
7
7
 
8
8
  [Parameter(Mandatory = $true)]
9
- [ValidatePattern('^(install|uninstall)-[A-Za-z0-9]+$')]
9
+ [ValidatePattern('^(install|uninstall|reinstall)-[A-Za-z0-9]+$')]
10
10
  [string]$JobId,
11
11
 
12
12
  [ValidateSet('zh', 'en')]
@@ -28,7 +28,7 @@ function Read-ProgressState {
28
28
  $value = [IO.File]::ReadAllText($script:verifiedStatePath) | ConvertFrom-Json
29
29
  if ($null -eq $value -or -not [StringComparer]::Ordinal.Equals([string]$value.id, $JobId) -or
30
30
  @('armed', 'closing', 'installing', 'restarting', 'verifying', 'completed', 'complete', 'failed', 'cancelled') -cnotcontains [string]$value.phase -or
31
- @('install', 'uninstall') -cnotcontains [string]$value.action) { return $null }
31
+ @('install', 'uninstall', 'reinstall') -cnotcontains [string]$value.action) { return $null }
32
32
  return $value
33
33
  } catch { return $null }
34
34
  }