dsh-builtin-browser 1.0.3 → 1.1.0

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 (305) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.en.md +89 -0
  3. package/browser-extension/constants.mjs +20 -0
  4. package/browser-extension/controller.mjs +293 -0
  5. package/browser-extension/locales.mjs +15 -0
  6. package/browser-extension/manifest.json +12 -0
  7. package/browser-extension/options.html +14 -0
  8. package/browser-extension/options.mjs +9 -0
  9. package/browser-extension/permission-guard.mjs +13 -0
  10. package/browser-extension/worker.mjs +74 -0
  11. package/desktop-bridge/desktop-identity.json +10 -2
  12. package/desktop-bridge/install.mjs +28 -2
  13. package/docs/issue-replies-2026-11-28.md +141 -0
  14. package/dsh-host-patch/apply.mjs +1 -1
  15. package/dsh-host-patch/rc3.json +4 -4
  16. package/dsh-host-patch/rc5.json +4 -4
  17. package/dsh-host-patch/v023-alpha2.json +2 -2
  18. package/lib/browser-electron/bridge-status.js +24 -1
  19. package/lib/browser-electron/desktop-identity.js +47 -8
  20. package/lib/client.js +2 -1
  21. package/native-host/install.mjs +5 -0
  22. package/package.json +20 -2
  23. package/scripts/build-client.mjs +305 -0
  24. package/scripts/build.mjs +69 -0
  25. package/scripts/bundle-host.mjs +28 -0
  26. package/scripts/fix-exports.mjs +40 -0
  27. package/scripts/install-electron.mjs +101 -0
  28. package/scripts/pack.mjs +99 -0
  29. package/scripts/publish-manifest.mjs +56 -0
  30. package/scripts/verify-exports.mjs +58 -0
  31. package/scripts/verify-preview-sdk.mjs +93 -0
  32. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  33. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  34. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  35. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  36. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  37. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  38. package/skills/dsh-debug-host/SKILL.md +56 -0
  39. package/skills/dsh-debug-self/SKILL.md +50 -0
  40. package/src/bridge-compatibility.ts +39 -0
  41. package/src/browser/anti-bot.ts +251 -0
  42. package/src/browser/deep-dom.ts +40 -0
  43. package/src/browser/handles.ts +89 -0
  44. package/src/browser/runtime.ts +578 -0
  45. package/src/browser/takeover-target.ts +45 -0
  46. package/src/browser/types.ts +870 -0
  47. package/src/browser-electron/authenticated-route.ts +109 -0
  48. package/src/browser-electron/automatic-maintenance.ts +736 -0
  49. package/src/browser-electron/bridge-auto.ts +159 -0
  50. package/src/browser-electron/bridge-connection.ts +386 -0
  51. package/src/browser-electron/bridge-endpoint.ts +129 -0
  52. package/src/browser-electron/bridge-install.ts +290 -0
  53. package/src/browser-electron/bridge-maintenance.ts +189 -0
  54. package/src/browser-electron/bridge-status.ts +412 -0
  55. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  56. package/src/browser-electron/desktop-identity.ts +400 -0
  57. package/src/browser-electron/desktop-shell.ts +100 -0
  58. package/src/browser-electron/document-readiness.ts +45 -0
  59. package/src/browser-electron/electron-provision.ts +347 -0
  60. package/src/browser-electron/entry.ts +1378 -0
  61. package/src/browser-electron/ephemeral-profile.ts +189 -0
  62. package/src/browser-electron/extension-browser.ts +230 -0
  63. package/src/browser-electron/extension-setup.ts +67 -0
  64. package/src/browser-electron/file-write.ts +31 -0
  65. package/src/browser-electron/foreground-watch.ts +142 -0
  66. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  67. package/src/browser-electron/guest-cookie-store.ts +59 -0
  68. package/src/browser-electron/guest-css-runtime.ts +76 -0
  69. package/src/browser-electron/guest-css.ts +68 -0
  70. package/src/browser-electron/guest-route.ts +716 -0
  71. package/src/browser-electron/guest-runtime.ts +408 -0
  72. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  73. package/src/browser-electron/guest-storage.ts +120 -0
  74. package/src/browser-electron/history-store.ts +224 -0
  75. package/src/browser-electron/host-main.ts +1385 -0
  76. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  77. package/src/browser-electron/http-body.ts +65 -0
  78. package/src/browser-electron/json-reply.ts +47 -0
  79. package/src/browser-electron/maintenance-broker.ts +166 -0
  80. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  81. package/src/browser-electron/maintenance-route.ts +68 -0
  82. package/src/browser-electron/missing-system-browser.ts +114 -0
  83. package/src/browser-electron/open-slot.ts +49 -0
  84. package/src/browser-electron/paths.ts +25 -0
  85. package/src/browser-electron/preferred-browser.ts +130 -0
  86. package/src/browser-electron/preview-route.ts +215 -0
  87. package/src/browser-electron/process-ownership.ts +174 -0
  88. package/src/browser-electron/process.ts +23 -0
  89. package/src/browser-electron/profile-checkpoint.ts +187 -0
  90. package/src/browser-electron/profile-command.ts +47 -0
  91. package/src/browser-electron/profile-extension.ts +129 -0
  92. package/src/browser-electron/profile-lease.ts +211 -0
  93. package/src/browser-electron/profile-residue.ts +49 -0
  94. package/src/browser-electron/provider-core.ts +1107 -0
  95. package/src/browser-electron/provider-interaction.ts +1034 -0
  96. package/src/browser-electron/provider-media.ts +589 -0
  97. package/src/browser-electron/provider-navigation.ts +323 -0
  98. package/src/browser-electron/provider-observation.ts +664 -0
  99. package/src/browser-electron/provider-tabs.ts +372 -0
  100. package/src/browser-electron/provider.ts +666 -0
  101. package/src/browser-electron/reference-route.ts +598 -0
  102. package/src/browser-electron/remote-host.ts +1538 -0
  103. package/src/browser-electron/rpc-input.ts +13 -0
  104. package/src/browser-electron/rpc-ops.ts +41 -0
  105. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  106. package/src/browser-electron/runtime-route.ts +105 -0
  107. package/src/browser-electron/runtime-status.ts +309 -0
  108. package/src/browser-electron/settings-route.ts +64 -0
  109. package/src/browser-electron/settings-store.ts +593 -0
  110. package/src/browser-electron/shortcuts-route.ts +112 -0
  111. package/src/browser-electron/sidebar-only-host.ts +300 -0
  112. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  113. package/src/browser-electron/system-browser.ts +1850 -0
  114. package/src/browser-electron/tauri-host.ts +194 -0
  115. package/src/browser-electron/timing.ts +16 -0
  116. package/src/browser-electron/virtual-cursor.ts +162 -0
  117. package/src/browser-electron/windows-system.ts +24 -0
  118. package/src/browser-reference/delivery.ts +384 -0
  119. package/src/browser-reference/entry.ts +631 -0
  120. package/src/browser-reference/export.ts +339 -0
  121. package/src/browser-reference/import.ts +303 -0
  122. package/src/browser-reference/page-script.ts +1537 -0
  123. package/src/browser-reference/service.ts +1346 -0
  124. package/src/browser-reference/store.ts +172 -0
  125. package/src/browser-reference/text-quote.ts +219 -0
  126. package/src/browser-reference/types.ts +195 -0
  127. package/src/browser-reference/visible.ts +367 -0
  128. package/src/browser-reference/web-sources.ts +106 -0
  129. package/src/client/apply-guard.ts +22 -0
  130. package/src/client/browser/BrowserController.ts +693 -0
  131. package/src/client/browser/BrowserFrame.ts +78 -0
  132. package/src/client/browser/BrowserNavigation.ts +169 -0
  133. package/src/client/browser/BrowserPage.ts +23 -0
  134. package/src/client/browser/BrowserPersistence.ts +44 -0
  135. package/src/client/browser/IframeImpl.ts +182 -0
  136. package/src/client/browser/child-tabs.ts +14 -0
  137. package/src/client/browser/frame-history.ts +125 -0
  138. package/src/client/browser/frame-state.ts +27 -0
  139. package/src/client/browser/iframe-reference.ts +67 -0
  140. package/src/client/browser/initialization.ts +262 -0
  141. package/src/client/browser/omnibox.ts +243 -0
  142. package/src/client/browser/store.ts +38 -0
  143. package/src/client/browser/takeover-channel.ts +72 -0
  144. package/src/client/browser/url.ts +46 -0
  145. package/src/client/browser/web-reference-source.ts +56 -0
  146. package/src/client/css-modules.d.ts +4 -0
  147. package/src/client/definition.tsx +36 -0
  148. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  149. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  150. package/src/client/electron/NativeChildPresentation.ts +53 -0
  151. package/src/client/electron/NativeViewPage.ts +265 -0
  152. package/src/client/electron/pages.ts +23 -0
  153. package/src/client/electron/reference-overlay.ts +53 -0
  154. package/src/client/electron/workspace.ts +33 -0
  155. package/src/client/index.ts +333 -0
  156. package/src/client/locales.ts +860 -0
  157. package/src/client/pages.ts +28 -0
  158. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  159. package/src/client/reference/client/draft-reference.ts +167 -0
  160. package/src/client/reference/client/index.ts +7 -0
  161. package/src/client/reference/client/ordered-submission.ts +108 -0
  162. package/src/client/reference/client/pending-delivery.ts +216 -0
  163. package/src/client/reference/client/plugin.ts +208 -0
  164. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  165. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  166. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  167. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  168. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  169. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  170. package/src/client/reference/client/production/assembly.ts +447 -0
  171. package/src/client/reference/client/production/asset-store.ts +144 -0
  172. package/src/client/reference/client/production/availability.ts +72 -0
  173. package/src/client/reference/client/production/bytes.ts +36 -0
  174. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  175. package/src/client/reference/client/production/delivery-client.ts +211 -0
  176. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  177. package/src/client/reference/client/production/http-transport.ts +212 -0
  178. package/src/client/reference/client/production/production-submission.ts +70 -0
  179. package/src/client/reference/client/production/protocol.ts +234 -0
  180. package/src/client/reference/client/production/reference-card.ts +240 -0
  181. package/src/client/reference/client/production/reference-labels.ts +29 -0
  182. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  183. package/src/client/reference/client/production/reveal.ts +215 -0
  184. package/src/client/reference/client/production/runtime.ts +1056 -0
  185. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  186. package/src/client/reference/client/production/source-marker.ts +99 -0
  187. package/src/client/reference/client/production/source-opener.ts +55 -0
  188. package/src/client/reference/client/production/styles.ts +104 -0
  189. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  190. package/src/client/reference/client/reveal.ts +109 -0
  191. package/src/client/reference/client/scheme.ts +114 -0
  192. package/src/client/reference/client/session-schedule.ts +36 -0
  193. package/src/client/reference/client/types.ts +168 -0
  194. package/src/client/reference/css-modules.d.ts +4 -0
  195. package/src/client/reference/index.ts +11 -0
  196. package/src/client/reference-capture-owner.ts +162 -0
  197. package/src/client/reference-intents.ts +36 -0
  198. package/src/client/settings/index.ts +42 -0
  199. package/src/client/settings/mount-guard.ts +31 -0
  200. package/src/client/settings/panel.ts +2773 -0
  201. package/src/client/shortcut-open.ts +30 -0
  202. package/src/client/startpage/binding.ts +99 -0
  203. package/src/client/startpage/controller.ts +300 -0
  204. package/src/client/startpage/model.ts +279 -0
  205. package/src/client/view/Browser.module.css +751 -0
  206. package/src/client/view/BrowserBody.tsx +315 -0
  207. package/src/client/view/BrowserPresentation.ts +9 -0
  208. package/src/client/view/BrowserTitle.tsx +17 -0
  209. package/src/client/view/IframePresentation.ts +365 -0
  210. package/src/client/view/StartPage.tsx +598 -0
  211. package/src/client/view/TakeoverBanner.tsx +21 -0
  212. package/src/compat/host-features.ts +92 -0
  213. package/src/index.ts +110 -0
  214. package/src/reference-owner.ts +5 -0
  215. package/src/reference-page.ts +9 -0
  216. package/src/reference-source.ts +3 -0
  217. package/src/reference-text.ts +219 -0
  218. package/src/startpage-settings.ts +103 -0
  219. package/src/startpage.ts +71 -0
  220. package/src/takeover-protocol.ts +28 -0
  221. package/src/tool-browser/block-recovery.ts +85 -0
  222. package/src/tool-browser/code-tool.ts +555 -0
  223. package/src/tool-browser/code-worker.ts +725 -0
  224. package/src/tool-browser/element-fields.ts +167 -0
  225. package/src/tool-browser/errors.ts +40 -0
  226. package/src/tool-browser/index.ts +265 -0
  227. package/src/tool-browser/page-probe.ts +675 -0
  228. package/src/tool-browser/panel-page.ts +126 -0
  229. package/src/tool-browser/probe-client.ts +183 -0
  230. package/src/tool-browser/screenshot-annotations.ts +131 -0
  231. package/src/tool-browser/screenshot-image.ts +49 -0
  232. package/src/tool-browser/state.ts +375 -0
  233. package/src/tool-browser/takeover.ts +199 -0
  234. package/src/tool-browser/tools-debug.ts +806 -0
  235. package/src/tool-browser/tools-interaction.ts +956 -0
  236. package/src/tool-browser/tools-navigation.ts +786 -0
  237. package/src/tool-browser/tools-observation.ts +474 -0
  238. package/src/tool-browser/tools-reference.ts +294 -0
  239. package/src/types/electron-shim.d.ts +144 -0
  240. package/src/types.ts +85 -0
  241. package/src/web-guest.ts +35 -0
  242. package/tools/accept-desktop.mjs +148 -0
  243. package/dist/client.d.cts +0 -516
  244. package/dist/client.d.mts +0 -516
  245. package/dist/index.cjs +0 -92
  246. package/dist/index.d.mts +0 -2960
  247. package/dist/index.mjs +0 -24
  248. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  249. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  250. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  256. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  257. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  258. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  259. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  260. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  261. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  262. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  263. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  264. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  265. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  266. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  267. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  268. package/dsh-host-patch/sources/manifest.json +0 -218
  269. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  293. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  294. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  295. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  296. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  297. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  298. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  299. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  300. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  301. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  302. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  303. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  304. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  305. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,194 @@
1
+ /**
2
+ * DSH Tauri (dsh-tauri/deepseek-harness-desktop) as a sidebar host.
3
+ *
4
+ * DSH Tauri does not run DeepSeek Harness Desktop's `lib/main.js`: its Electron main process is
5
+ * electron-rs, staged in `runtime/<platform>-<arch>` beside an `electron-rs.json` whose identifier
6
+ * names the app. Its sidebar guests get an in-memory partition, so the sidebar host patch
7
+ * (`dsh-host-patch/tauri.json`) targets `runtime/browser.cjs` there. The plugin's own Node process
8
+ * is that same Electron binary in Node mode, so a running Tauri is recognised from `process.execPath`.
9
+ * @module dsh-browser/browser-electron/tauri-host
10
+ */
11
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
12
+ import { basename, dirname, join } from 'node:path'
13
+ import { fileURLToPath } from 'node:url'
14
+ import { dshHome } from './paths.ts'
15
+ import { registeredInstallLocations } from '../../desktop-bridge/desktop-discovery.mjs'
16
+
17
+ const { hostPatchStatus }: { hostPatchStatus: (directory: string) => TauriHostPatch } = await import(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href)
18
+
19
+ interface TauriRule {
20
+ readonly identifiers: readonly string[]
21
+ readonly metadata: string
22
+ readonly runtimeRoots: readonly string[]
23
+ readonly installNames: readonly string[]
24
+ readonly registryName: string
25
+ }
26
+
27
+ /** One DSH Tauri electron-rs runtime directory. */
28
+ export interface TauriRuntime {
29
+ /** The install root, when the runtime sits at one of the rule's runtime roots. */
30
+ readonly root?: string
31
+ /** `runtime/<platform>-<arch>`: the directory the host patch is applied to. */
32
+ readonly runtime: string
33
+ readonly identifier: string
34
+ readonly appName?: string
35
+ readonly running: boolean
36
+ }
37
+
38
+ /** Host patch state of a Tauri runtime, as `dsh-host-patch/apply.mjs` reports it. */
39
+ export interface TauriHostPatch {
40
+ readonly status: string
41
+ readonly reason?: string
42
+ }
43
+
44
+ /**
45
+ * Read the Tauri part of the shared identity rule.
46
+ * @returns the rule, or undefined when it cannot be read.
47
+ */
48
+ export function readTauriRule(): TauriRule | undefined {
49
+ try {
50
+ const rule = (JSON.parse(readFileSync(new URL('../../desktop-bridge/desktop-identity.json', import.meta.url), 'utf8')) as { tauri?: TauriRule }).tauri
51
+ const strings = (value: unknown): value is readonly string[] => Array.isArray(value) && value.length > 0 && value.every(item => typeof item === 'string' && item !== '')
52
+ if (rule === undefined || !strings(rule.identifiers) || !strings(rule.runtimeRoots) || !strings(rule.installNames)
53
+ || typeof rule.metadata !== 'string' || typeof rule.registryName !== 'string') return undefined
54
+ return rule
55
+ } catch {
56
+ return undefined
57
+ }
58
+ }
59
+
60
+ function metadataOf(directory: string, rule: TauriRule): { identifier: string; appName?: string; target?: string; arch?: string } | undefined {
61
+ try {
62
+ const value = JSON.parse(readFileSync(join(directory, rule.metadata), 'utf8')) as Record<string, unknown>
63
+ if (typeof value.identifier !== 'string' || !rule.identifiers.includes(value.identifier)) return undefined
64
+ return {
65
+ identifier: value.identifier,
66
+ ...typeof value.appName === 'string' ? { appName: value.appName } : {},
67
+ ...typeof value.target === 'string' ? { target: value.target } : {},
68
+ ...typeof value.arch === 'string' ? { arch: value.arch } : {},
69
+ }
70
+ } catch {
71
+ return undefined
72
+ }
73
+ }
74
+
75
+ function rootOf(runtime: string, rule: TauriRule): string | undefined {
76
+ for (const base of [...rule.runtimeRoots].sort((a, b) => b.split('/').length - a.split('/').length)) {
77
+ const parts = base.split('/')
78
+ let directory = dirname(runtime)
79
+ let matches = true
80
+ for (const part of [...parts].reverse()) {
81
+ if (basename(directory) !== part) { matches = false; break }
82
+ directory = dirname(directory)
83
+ }
84
+ if (matches) return directory
85
+ }
86
+ return undefined
87
+ }
88
+
89
+ /**
90
+ * The Tauri runtime this process runs from, when the plugin is hosted by DSH Tauri. On macOS the
91
+ * Electron binary sits in `<runtime>/<name>.app/Contents/MacOS/`, beside which electron-rs keeps
92
+ * `electron-rs.json` and `runtime/`, so the directory holding the `.app` is the runtime.
93
+ * @param execPath - the running executable.
94
+ * @returns the runtime, or undefined outside DSH Tauri.
95
+ */
96
+ export function runningTauriRuntime(execPath: string = process.execPath): TauriRuntime | undefined {
97
+ const rule = readTauriRule()
98
+ if (rule === undefined) return undefined
99
+ const binary = dirname(execPath)
100
+ const bundle = basename(binary) === 'MacOS' && basename(dirname(binary)) === 'Contents' && dirname(dirname(binary)).endsWith('.app')
101
+ ? dirname(dirname(dirname(binary))) : undefined
102
+ const runtime = [binary, bundle].find(directory => directory !== undefined && metadataOf(directory, rule) !== undefined)
103
+ if (runtime === undefined) return undefined
104
+ const metadata = metadataOf(runtime, rule)!
105
+ const root = rootOf(runtime, rule)
106
+ return { ...root === undefined ? {} : { root }, runtime, identifier: metadata.identifier, ...metadata.appName === undefined ? {} : { appName: metadata.appName }, running: true }
107
+ }
108
+
109
+ /**
110
+ * The runtime of a DSH Tauri install root that matches this machine.
111
+ * @param root - a candidate install directory.
112
+ * @param platform - the platform the runtime must target.
113
+ * @param arch - the architecture the runtime must target.
114
+ * @returns the runtime, or undefined when the directory is not DSH Tauri.
115
+ */
116
+ export function tauriRuntimeOf(root: string, platform: string = process.platform, arch: string = process.arch): TauriRuntime | undefined {
117
+ const rule = readTauriRule()
118
+ if (rule === undefined) return undefined
119
+ for (const base of rule.runtimeRoots) {
120
+ const directory = join(root, ...base.split('/'))
121
+ let entries: string[] = []
122
+ try { entries = readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => entry.name) } catch { continue }
123
+ for (const name of entries) {
124
+ const runtime = join(directory, name)
125
+ const metadata = metadataOf(runtime, rule)
126
+ if (metadata === undefined) continue
127
+ if ((metadata.target !== undefined && metadata.target !== platform) || (metadata.arch !== undefined && metadata.arch !== arch)) continue
128
+ return { root, runtime, identifier: metadata.identifier, ...metadata.appName === undefined ? {} : { appName: metadata.appName }, running: false }
129
+ }
130
+ }
131
+ return undefined
132
+ }
133
+
134
+ /**
135
+ * Find DSH Tauri: the running host first, then the usual install locations.
136
+ * @param options - discovery overrides for tests.
137
+ * @returns the runtime, or undefined when no DSH Tauri is found.
138
+ */
139
+ export function findTauriRuntime(options: {
140
+ readonly execPath?: string
141
+ readonly localAppData?: string
142
+ readonly registry?: () => readonly string[]
143
+ } = {}): TauriRuntime | undefined {
144
+ const running = runningTauriRuntime(options.execPath)
145
+ if (running !== undefined) return running
146
+ const rule = readTauriRule()
147
+ if (rule === undefined) return undefined
148
+ const bases = options.localAppData !== undefined ? [options.localAppData]
149
+ : [process.env.LOCALAPPDATA, join(process.env.LOCALAPPDATA ?? '', 'Programs'), process.env.ProgramFiles, process.env['ProgramFiles(x86)']]
150
+ .filter((base): base is string => typeof base === 'string' && base !== '' && base !== 'Programs')
151
+ const candidates = [
152
+ ...[process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP].filter((path): path is string => typeof path === 'string' && path !== ''),
153
+ ...bases.flatMap(base => rule.installNames.map(name => join(base, name))),
154
+ ]
155
+ for (const candidate of candidates) {
156
+ if (!existsSync(candidate)) continue
157
+ const found = tauriRuntimeOf(candidate)
158
+ if (found !== undefined) return found
159
+ }
160
+ let registered: readonly string[] = []
161
+ try { registered = (options.registry ?? (() => registeredInstallLocations(process.platform, undefined, rule.registryName)))() } catch {}
162
+ for (const candidate of registered) {
163
+ const found = tauriRuntimeOf(candidate)
164
+ if (found !== undefined) return found
165
+ }
166
+ return undefined
167
+ }
168
+
169
+ /**
170
+ * Read the sidebar host patch state of a Tauri runtime without writing.
171
+ * @param runtime - the runtime directory.
172
+ * @returns the patch status.
173
+ */
174
+ export function tauriHostPatchStatus(runtime: string): TauriHostPatch {
175
+ try { return hostPatchStatus(runtime) } catch (error) { return { status: 'anchors mismatch', reason: String(error) } }
176
+ }
177
+
178
+ /**
179
+ * Name this plugin's package to the Tauri host patch, which starts its `dsh.desktop.main` (the sidebar
180
+ * bridge) inside electron-rs: Tauri has no Desktop main-extension loader to find it in the profile.
181
+ * @param home - the DSH home the host patch reads.
182
+ * @param root - this plugin's package directory.
183
+ * @returns the pointer file path.
184
+ */
185
+ export function publishTauriDesktopMain(home: string = dshHome(), root: string = fileURLToPath(new URL('../../', import.meta.url))): string {
186
+ const file = join(home, 'dsh-builtin-browser-desktop-main.json')
187
+ const text = JSON.stringify({ root }) + '\n'
188
+ try { if (readFileSync(file, 'utf8') === text) return file } catch { /* absent */ }
189
+ const temporary = `${file}.${process.pid}.tmp`
190
+ mkdirSync(home, { recursive: true })
191
+ writeFileSync(temporary, text, { mode: 0o600 })
192
+ renameSync(temporary, file)
193
+ return file
194
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bound an await with a timeout, without dictating the caller's error wording.
3
+ *
4
+ * The two hosts phrase their timeout errors differently and those strings reach the panel, so
5
+ * the shared primitive takes a factory instead of a message.
6
+ * @module dsh-browser/browser-electron/timing
7
+ */
8
+ export function withTimeoutShared<T>(promise: Promise<T>, ms: number, timedOut: () => Error): Promise<T> {
9
+ return new Promise<T>((resolve, reject) => {
10
+ const timer = setTimeout(() => { reject(timedOut()) }, ms)
11
+ promise.then(
12
+ (value) => { clearTimeout(timer); resolve(value) },
13
+ (error) => { clearTimeout(timer); reject(error) },
14
+ )
15
+ })
16
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Synthetic pointer feedback for a human watching the tab: an overlay drawn
3
+ * INSIDE the page, never the real system pointer. Its presence is the "the agent
4
+ * has taken over this tab" signal, so it also covers DOM-level operations that
5
+ * move no pointer at all.
6
+ *
7
+ * Implementation notes that matter:
8
+ * - The overlay is `position: fixed` and positioned from viewport coordinates,
9
+ * which is exactly what the element locator already computes and what
10
+ * `Input.dispatchMouseEvent` consumes.
11
+ * - All styling is inline and the ripple uses the Web Animations API: a
12
+ * `<style>` element would be subject to the page's `style-src` CSP, an
13
+ * injected script is not. Injected page feedback must never be silently
14
+ * dropped by a strict CSP.
15
+ * - The overlay mounts inside a closed shadow root (keyed via a Symbol on the
16
+ * host node) and translates an inner stage wrapper so neither `innerText`,
17
+ * deep-DOM shadow-root walkers (`content(markdown)`, `findText`, `anti-bot`),
18
+ * nor top-document attribute `MutationObserver`s (`wait_idle`) observe it.
19
+ * - Every call is best-effort: feedback is never allowed to fail an operation.
20
+ * @module dsh-browser/browser-electron/virtual-cursor
21
+ */
22
+
23
+ /** What the pointer is doing at the reported point. */
24
+ export type CursorAction = 'move' | 'click'
25
+
26
+ /** Element id of the overlay root, stable so repeat calls update one node. */
27
+ export const CURSOR_ID = '__dsh_agent_cursor__'
28
+
29
+ /**
30
+ * Where the overlay was last placed, so an unchanged position is not repainted.
31
+ *
32
+ * A single tool call issues several CDP commands (locate, click, cursor), and the
33
+ * cursor is repainted for each one that moves it. Repainting to the same pixel is a
34
+ * wasted round-trip *and* a visible flicker: the transition restarts from the same
35
+ * place, which reads as a stutter rather than as movement.
36
+ */
37
+ const lastPlaced = new WeakMap<object, { x: number; y: number; action: CursorAction }>()
38
+
39
+ /**
40
+ * Whether a paint at this position would change anything on screen.
41
+ * @param handle - the view the overlay belongs to.
42
+ * @param x - viewport x in CSS pixels.
43
+ * @param y - viewport y in CSS pixels.
44
+ * @param action - the action being reported.
45
+ * @param force - paint even when unchanged (a click ripple must always fire).
46
+ * @returns true when the overlay should be painted.
47
+ */
48
+ export function cursorNeedsPaint<TView>(handle: TView, x: number, y: number, action: CursorAction, force = false): boolean {
49
+ if (force) return true
50
+ const key = handle as unknown as object
51
+ if (key === null || typeof key !== 'object') return true
52
+ const previous = lastPlaced.get(key)
53
+ return previous === undefined || previous.x !== x || previous.y !== y || previous.action !== action
54
+ }
55
+
56
+ /**
57
+ * The in-page expression that materializes or moves the overlay. Idempotent: the
58
+ * first call creates the nodes, later calls only move them (and pulse).
59
+ * @param x - viewport x in CSS pixels.
60
+ * @param y - viewport y in CSS pixels.
61
+ * @param action - whether to pulse a click ripple at the point.
62
+ * @param label - optional short description of the operation, shown beside the
63
+ * pointer. The overlay is the only "the agent has taken over this tab" signal, so
64
+ * saying *what* it is doing is what turns it from a decoration into an account of
65
+ * the agent's actions that a human can follow without reading the tool log.
66
+ * @returns a self-contained expression that evaluates to `true`.
67
+ */
68
+ export function cursorScript(x: number, y: number, action: CursorAction, label?: string): string {
69
+ return `(() => {
70
+ const id = ${JSON.stringify(CURSOR_ID)}
71
+ const key = Symbol.for('__dsh_agent_cursor_shadow__')
72
+ let root = document.getElementById(id)
73
+ if (!root) {
74
+ root = document.createElement('div')
75
+ root.id = id
76
+ root.setAttribute('aria-hidden', 'true')
77
+ root.style.cssText = 'position:fixed;left:0;top:0;width:0;height:0;z-index:2147483647;pointer-events:none'
78
+ const svg = '<svg width="22" height="22" viewBox="0 0 22 22" style="position:absolute;left:-2px;top:-2px;filter:drop-shadow(0 1px 2px rgba(0,0,0,.45))">'
79
+ + '<path d="M4 2 L4 18 L8.4 13.8 L11.2 19.6 L13.8 18.4 L11 12.8 L17 12.6 Z" fill="#ffffff" stroke="#111111" stroke-width="1.4" stroke-linejoin="round"/></svg>'
80
+ const ripple = '<span data-dsh-role="ripple" style="position:absolute;left:0;top:0;width:34px;height:34px;margin:-17px 0 0 -17px;border-radius:50%;border:2px solid rgba(64,160,255,.9);opacity:0"></span>'
81
+ // The bubble sits below-right of the pointer tip and is capped in width so a long
82
+ // label cannot cover the page it is describing.
83
+ const bubble = '<span data-dsh-role="bubble" style="position:absolute;left:18px;top:16px;max-width:280px;padding:3px 8px;border-radius:5px;background:rgba(17,17,17,.92);color:#fff;font:12px/1.45 -apple-system,Segoe UI,Roboto,sans-serif;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;opacity:0;box-shadow:0 1px 3px rgba(0,0,0,.4)"></span>'
84
+ const stage = '<div data-dsh-role="stage" style="position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;transition:transform 190ms cubic-bezier(.22,.85,.24,1);will-change:transform">' + svg + ripple + bubble + '</div>'
85
+ const parts = typeof root.attachShadow === 'function' ? root.attachShadow({ mode: 'closed' }) : root
86
+ parts.innerHTML = stage
87
+ root[key] = parts
88
+ ;(document.body || document.documentElement).appendChild(root)
89
+ }
90
+ const parts = root[key] || root
91
+ const stage = parts.querySelector('[data-dsh-role="stage"]') || root
92
+ stage.style.transform = 'translate(${x}px, ${y}px)'
93
+ ${action === 'click' ? `const ripple = parts.querySelector('[data-dsh-role="ripple"]')
94
+ if (ripple && typeof ripple.animate === 'function') {
95
+ ripple.animate(
96
+ [{ transform: 'scale(.25)', opacity: 0.95 }, { transform: 'scale(1.6)', opacity: 0 }],
97
+ { duration: 550, easing: 'ease-out' },
98
+ )
99
+ }` : ''}
100
+ ${label !== undefined && label !== '' ? `const bubble = parts.querySelector('[data-dsh-role="bubble"]')
101
+ if (bubble) {
102
+ bubble.textContent = ${JSON.stringify(label)}
103
+ if (typeof bubble.animate === 'function') {
104
+ // Fade in, hold, fade out: the label is a narration of the action, not a
105
+ // permanent caption, so a stale one never lingers over later work.
106
+ bubble.animate(
107
+ [{ opacity: 0, transform: 'translateY(-3px)' }, { opacity: 1, transform: 'translateY(0)' }, { opacity: 1, offset: 0.6 }, { opacity: 0 }],
108
+ { duration: 2200, easing: 'ease-out', fill: 'forwards' },
109
+ )
110
+ } else {
111
+ bubble.style.opacity = '1'
112
+ }
113
+ }` : ''}
114
+ return true
115
+ })()`
116
+ }
117
+
118
+ /**
119
+ * Forget the remembered position for a view.
120
+ *
121
+ * Called when the document is replaced: the overlay lived in the old document and
122
+ * went with it, so the cache would otherwise claim the pointer is already where it
123
+ * needs to be and skip every later paint — the pointer would simply never return
124
+ * after a navigation.
125
+ * @param handle - the view whose cache should be dropped.
126
+ */
127
+ export function forgetCursor<TView>(handle: TView): void {
128
+ const key = handle as unknown as object
129
+ if (key !== null && typeof key === 'object') lastPlaced.delete(key)
130
+ }
131
+
132
+ /**
133
+ * Draw (or move) the pointer overlay on one view's page.
134
+ *
135
+ * Best-effort: a page that is mid-navigation, cross-origin-blocked, or otherwise
136
+ * unable to answer must not turn a successful operation into a failure. Returns
137
+ * a settled promise so callers like click() can optionally wait briefly for the
138
+ * paint before dispatching mouse events without racing the press/release pair.
139
+ * @param handle - the view to paint into.
140
+ * @param x - viewport x in CSS pixels.
141
+ * @param y - viewport y in CSS pixels.
142
+ * @param action - whether to pulse a click ripple.
143
+ * @param evaluate - the provider's evaluate bridge (keeps the CDP coupling in one place).
144
+ * @param label - optional short description of the operation, shown beside the pointer.
145
+ */
146
+ export function paintCursor<TView>(
147
+ handle: TView,
148
+ x: number,
149
+ y: number,
150
+ action: CursorAction,
151
+ evaluate: (handle: TView, expression: string) => Promise<unknown>,
152
+ label?: string,
153
+ force = false,
154
+ ): Promise<void> {
155
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return Promise.resolve()
156
+ const roundedX = Math.round(x)
157
+ const roundedY = Math.round(y)
158
+ if (!cursorNeedsPaint(handle, roundedX, roundedY, action, force)) return Promise.resolve()
159
+ const key = handle as unknown as object
160
+ if (key !== null && typeof key === 'object') lastPlaced.set(key, { x: roundedX, y: roundedY, action })
161
+ return Promise.resolve(evaluate(handle, cursorScript(roundedX, roundedY, action, label))).then(() => undefined, () => undefined)
162
+ }
@@ -0,0 +1,24 @@
1
+ import { WINDOWS_TOOLS } from '../../assets/browser-products.mjs'
2
+ /** Locate Windows system tools from the running system rather than an assumed system drive. */
3
+ import { existsSync } from 'node:fs'
4
+ import { win32 } from 'node:path'
5
+
6
+ /** PowerShell's `-EncodedCommand` expects a UTF-16LE script encoded as base64. */
7
+ export function encodePowerShellScript(script: string): string {
8
+ return Buffer.from(script, 'utf16le').toString('base64')
9
+ }
10
+
11
+ export function windowsPowerShellPath(
12
+ environment: NodeJS.ProcessEnv = process.env,
13
+ exists: (path: string) => boolean = existsSync,
14
+ ): string {
15
+ const read = (name: string): string | undefined => Object.entries(environment)
16
+ .find(([key]) => key.toUpperCase() === name)?.[1]
17
+ const root = read('SYSTEMROOT') || read('WINDIR')
18
+ if (root === undefined || !/^(?:[A-Za-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+)/.test(root)) {
19
+ throw new Error('Windows system directory is unavailable; SystemRoot or WINDIR must identify the current system')
20
+ }
21
+ const path = win32.join(root, 'System32', 'WindowsPowerShell', 'v1.0', WINDOWS_TOOLS.powershell)
22
+ if (!exists(path)) throw new Error('Windows PowerShell is unavailable in the detected system directory')
23
+ return path
24
+ }