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,167 @@
1
+ /**
2
+ * The element and node field sets, declared once.
3
+ *
4
+ * WHY THIS FILE EXISTS
5
+ *
6
+ * The same field set used to be written out in four places: the page script produced an
7
+ * object, `types.ts` declared its shape, a tool's `execute` rebuilt it as an explicit list,
8
+ * and the tool's `output.schema` declared the properties. Nothing connected them, and the
9
+ * result is this project's most repeatable bug:
10
+ *
11
+ * - `dsh_browser_a11y`'s `selector` — computed by the provider, declared by the schema,
12
+ * printed by the renderer, and dropped by the projection. 134 tests stayed green.
13
+ * - `dsh_browser_screenshot`'s `width`/`height` — measured by the provider, declared by the
14
+ * schema, and dropped by the projection. 172 tests stayed green. It was found a round
15
+ * later, by reading the three places that agree and noticing the fourth did not.
16
+ *
17
+ * A hand-written allow-list is invisible to the type checker (it is an object literal) and to
18
+ * the tests (nothing ran a tool). The fix is not a careful list; it is one list. Both the
19
+ * schema fragment and the projection are derived from the tables below, so a field cannot be
20
+ * present in one and absent from the other.
21
+ *
22
+ * The schema is the dangerous half: `additionalProperties: false` means a field the schema
23
+ * does NOT declare causes the ENTIRE result to be rejected at run time, while a field the
24
+ * projection forgets is silently dropped. One table cannot get either wrong on its own.
25
+ */
26
+
27
+ /** A single declared field: how the schema describes it, and whether callers always get it. */
28
+ interface FieldSpec {
29
+ /** The JSON Schema fragment for this property. */
30
+ readonly schema: Record<string, unknown>
31
+ /** True when the value is always present, so both the schema and the result promise it. */
32
+ readonly required?: boolean
33
+ }
34
+
35
+ /**
36
+ * The fields of one entry in `dsh_browser_snapshot` / `dsh_browser_open`'s `elements`.
37
+ *
38
+ * `selector` is the reason this file exists; see the header. It was added to the schema and
39
+ * the projection separately, and only one of them landed.
40
+ */
41
+ const ELEMENT_FIELDS = {
42
+ ref: { schema: { type: 'number' }, required: true },
43
+ kind: { schema: { type: 'string' }, required: true },
44
+ label: { schema: { type: 'string' }, required: true },
45
+ selector: { schema: { type: 'string' } },
46
+ x: { schema: { type: 'number' }, required: true },
47
+ y: { schema: { type: 'number' }, required: true },
48
+ frame: { schema: { type: 'boolean' } },
49
+ } as const satisfies Record<string, FieldSpec>
50
+
51
+ /**
52
+ * The fields of one entry in `dsh_browser_a11y`'s `nodes`.
53
+ *
54
+ * Different shape from an element on purpose: a role and an accessible name carry meaning a
55
+ * tag and a label string do not, and `depth` is what renders the tree.
56
+ */
57
+ const NODE_FIELDS = {
58
+ ref: { schema: { type: 'number' }, required: true },
59
+ role: { schema: { type: 'string' }, required: true },
60
+ name: { schema: { type: 'string' }, required: true },
61
+ value: { schema: { type: 'string' } },
62
+ states: { schema: { type: 'array', items: { type: 'string' } }, required: true },
63
+ depth: { schema: { type: 'number' }, required: true },
64
+ tag: { schema: { type: 'string' }, required: true },
65
+ // Always present: the provider derives it for every node and yields an empty string when the
66
+ // element has neither an id nor a name. Declaring it optional described a shape the provider
67
+ // never produced, and the type said required — the same disagreement, one level down.
68
+ selector: { schema: { type: 'string' }, required: true },
69
+ x: { schema: { type: 'number' }, required: true },
70
+ y: { schema: { type: 'number' }, required: true },
71
+ frame: { schema: { type: 'boolean' } },
72
+ } as const satisfies Record<string, FieldSpec>
73
+
74
+ /**
75
+ * Copy the declared fields out of a source value.
76
+ *
77
+ * Reads the table rather than naming fields, so anything the provider produces that the table
78
+ * declares is carried through, and anything the table does not declare is left out — which is
79
+ * what keeps the result and the schema in agreement in both directions.
80
+ * @param fields - the field table to project through.
81
+ * @param source - the value the provider produced.
82
+ * @returns a new object holding exactly the declared fields that are present.
83
+ */
84
+ function project(fields: Record<string, FieldSpec>, source: Record<string, unknown>): Record<string, unknown> {
85
+ const out: Record<string, unknown> = {}
86
+ for (const name of Object.keys(fields)) {
87
+ const value = source[name]
88
+ if (value !== undefined && value !== null) out[name] = value
89
+ }
90
+ return out
91
+ }
92
+
93
+ /**
94
+ * The `elements` item schema for dsh_browser_snapshot and dsh_browser_open.
95
+ *
96
+ * Written as a literal rather than generated, because `defineTool` validates the output schema
97
+ * against its own `ValueSchemaSpec` and a generated `Record<string, …>` is too wide to satisfy
98
+ * it. The field table above remains the single source of truth: `tests/element-fields.test.mjs`
99
+ * asserts that these properties and `projectElement`'s output are exactly the table's keys, so
100
+ * the two cannot drift even though one is typed by hand.
101
+ */
102
+ export const ELEMENT_ITEM_SCHEMA = {
103
+ type: 'object',
104
+ additionalProperties: false,
105
+ properties: {
106
+ ref: { type: 'number', required: true },
107
+ kind: { type: 'string', required: true },
108
+ label: { type: 'string', required: true },
109
+ selector: { type: 'string' },
110
+ x: { type: 'number', required: true },
111
+ y: { type: 'number', required: true },
112
+ frame: { type: 'boolean' },
113
+ },
114
+ } as const
115
+
116
+ /**
117
+ * The `nodes` item schema for dsh_browser_a11y.
118
+ *
119
+ * Same reasoning as {@link ELEMENT_ITEM_SCHEMA}: literal for the type checker, table-backed by
120
+ * test.
121
+ */
122
+ export const NODE_ITEM_SCHEMA = {
123
+ type: 'object',
124
+ additionalProperties: false,
125
+ properties: {
126
+ ref: { type: 'number', required: true },
127
+ role: { type: 'string', required: true },
128
+ name: { type: 'string', required: true },
129
+ value: { type: 'string' },
130
+ states: { type: 'array', required: true, items: { type: 'string' } },
131
+ depth: { type: 'number', required: true },
132
+ tag: { type: 'string', required: true },
133
+ selector: { type: 'string', required: true },
134
+ x: { type: 'number', required: true },
135
+ y: { type: 'number', required: true },
136
+ frame: { type: 'boolean' },
137
+ },
138
+ } as const
139
+
140
+ /**
141
+ * Project one snapshot element into the shape the schema declares.
142
+ *
143
+ * Generic in the source type so the caller keeps the precise shape `defineTool` inferred from
144
+ * the schema: the projection decides which fields survive at run time, and the field table is
145
+ * what guarantees that set matches the schema. Widening the return type here would only move
146
+ * the mismatch to the call site.
147
+ * @param element - the element as the provider produced it.
148
+ * @returns exactly the declared fields.
149
+ */
150
+ export function projectElement<T extends object>(element: T): T {
151
+ return project(ELEMENT_FIELDS as Record<string, FieldSpec>, element as Record<string, unknown>) as T
152
+ }
153
+
154
+ /**
155
+ * Project one accessibility node into the shape the schema declares.
156
+ * @param node - the node as the provider produced it.
157
+ * @returns exactly the declared fields.
158
+ */
159
+ export function projectNode<T extends object>(node: T): T {
160
+ return project(NODE_FIELDS as Record<string, FieldSpec>, node as Record<string, unknown>) as T
161
+ }
162
+
163
+ /** The field names each table declares, for tests that check the two stay in step. */
164
+ export const DECLARED_FIELDS = {
165
+ element: Object.keys(ELEMENT_FIELDS),
166
+ node: Object.keys(NODE_FIELDS),
167
+ } as const
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Structured failures of the dsh_browser_* tools.
3
+ *
4
+ * DSH records `error: { name, code }` on `tool/result` only for a thrown `HarnessError`, and PTC
5
+ * programs see the same class, so every browser tool failure leaves as one.
6
+ * @module dsh-browser/tool-browser/errors
7
+ */
8
+ import { HarnessError } from '@deepseek-ai/dsh-error'
9
+
10
+ export type BrowserToolErrorCode =
11
+ | 'BROWSER_TAKEOVER_PENDING'
12
+ | 'BROWSER_UNKNOWN_TOOL_GROUP'
13
+ | 'BROWSER_TOOL_FAILED'
14
+ | (string & {})
15
+
16
+ /** A browser tool failure with a stable code; the message is what the model sees. */
17
+ export class BrowserToolError extends HarnessError {
18
+ declare readonly code: BrowserToolErrorCode
19
+ constructor(message: string, code: BrowserToolErrorCode, options?: ErrorOptions) {
20
+ super(message, code, options)
21
+ this.name = 'BrowserToolError'
22
+ }
23
+ }
24
+
25
+ /**
26
+ * The error a browser tool rethrows: HarnessErrors and cancellations unchanged, anything else with
27
+ * the same message, the original as `cause`, and its own string `code` (e.g.
28
+ * `BROWSER_BRIDGE_VERSION_MISMATCH`) or `BROWSER_TOOL_FAILED`.
29
+ * @param error - what the tool threw.
30
+ * @param signal - the call's abort signal, if any.
31
+ */
32
+ export function toBrowserToolError(error: unknown, signal?: AbortSignal): unknown {
33
+ if (error instanceof HarnessError) return error
34
+ if (signal?.aborted === true) return error
35
+ if (error instanceof Error && error.name === 'AbortError') return error
36
+ const message = error instanceof Error ? error.message : String(error)
37
+ const own = (error as { code?: unknown } | null)?.code
38
+ const code = typeof own === 'string' && own !== '' ? own : 'BROWSER_TOOL_FAILED'
39
+ return new BrowserToolError(message, code, { cause: error })
40
+ }
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Model-facing browser tools over `ctx.browser`, assembled: config, the prompt guides, safe
3
+ * registration, the `core` surface's loader and the code tool. The tools live in `tools-*.ts`,
4
+ * their shared per-apply state in `state.ts` and the page-probe client in `probe-client.ts`.
5
+ *
6
+ * Session lifecycle is owned at the plugin level: each calling task (a DSH session) gets its own
7
+ * browser session, so concurrent tasks never fight over tabs, history, or navigation state.
8
+ * @module dsh-browser/tool-browser
9
+ */
10
+
11
+ import type { Context } from '@deepseek-ai/cordis'
12
+ import { BrowserTakeovers, installTakeovers } from './takeover.ts'
13
+ import { TAKEOVER_TOOL } from '../takeover-protocol.ts'
14
+ import { defineTool } from '@deepseek-ai/dsh-tools'
15
+ import { BrowserToolError, toBrowserToolError } from './errors.ts'
16
+ import { CODE_PROMPT, CODE_TOOL, createCodeTool, type CatalogTool, type PagePulse } from './code-tool.ts'
17
+ import { pageOperationValue } from './probe-client.ts'
18
+ import { SettingsStore } from '../browser-electron/settings-store.ts'
19
+ import { browserSessionHandle, resolveTabHandle } from '../browser/handles.ts'
20
+ import { readSurface, createState, liveStates, READ_ONLY_TOOLS, taskKey, type ToolScope, maxWaitFor, MAX_FILL_FIELDS, REGISTRATION_ORDER } from './state.ts'
21
+ import { navigationTools } from './tools-navigation.ts'
22
+ import { TOOL_DEFAULT_TIMEOUT_MS } from '../../assets/browser-policy.mjs'
23
+ import { observationTools } from './tools-observation.ts'
24
+ import { interactionTools } from './tools-interaction.ts'
25
+ import { debugTools } from './tools-debug.ts'
26
+ import { referenceTools } from './tools-reference.ts'
27
+ import { ptcRuntimeActive, registerTool } from '../compat/host-features.ts'
28
+
29
+ export { READ_ONLY_TOOLS, internals } from './state.ts'
30
+
31
+ // One line at registration: tool handlers are registered once per host start, and a recomposition does
32
+ // not re-register them. Printing the resolved surface here is the only reliable way to tell WHICH build a
33
+ // live host is actually running, instead of inferring it from behaviour.
34
+ try { console.log('[tool-browser] registered, surface=' + readSurface()) } catch { /* logging only */ }
35
+
36
+ /** Plugin name used by loader diagnostics. */
37
+ export const name = 'tool-browser'
38
+ /** The tool registry, browser seam, and system-prompt registry this tool layer consumes. */
39
+ export const inject = ['tools', 'browser', 'systemPrompt']
40
+
41
+ /** Plugin config: tool timeouts and session defaults. */
42
+ export interface Config {
43
+ /** Cooperative tool-call budget in ms. Default 60000. */
44
+ readonly timeoutMs?: number
45
+ /** Whether to offer tab-management tools. Default true. */
46
+ readonly tabTools?: boolean
47
+ /** Optional initial allow-list of browser tool names; other tools are refused. */
48
+ readonly allowedActions?: readonly string[]
49
+ /**
50
+ * What the model sees. "core" (default): core browser tools, dsh_browser_load_tools and
51
+ * dsh_browser_code (which steps aside under PTC). "code": one dsh_browser_code tool whose
52
+ * script calls every browser action as a helper, plus dsh_browser_request_takeover. "tools":
53
+ * every action as its own tool.
54
+ */
55
+ readonly surface?: 'core' | 'code' | 'tools'
56
+ }
57
+
58
+ /** Tool loaded on demand: registers a group of browser tools for the rest of the run. */
59
+ export const LOAD_TOOL = 'dsh_browser_load_tools'
60
+
61
+ /** Tools the model sees from the start on the default `core` surface. */
62
+ export const CORE_TOOLS: ReadonlySet<string> = new Set([
63
+ 'dsh_browser_open', 'dsh_browser_snapshot', 'dsh_browser_a11y', 'dsh_browser_click', 'dsh_browser_type',
64
+ 'dsh_browser_key', 'dsh_browser_scroll', 'dsh_browser_select', 'dsh_browser_fill', 'dsh_browser_wait',
65
+ 'dsh_browser_content', 'dsh_browser_find', 'dsh_browser_scrape', 'dsh_browser_screenshot',
66
+ 'dsh_browser_execute', 'dsh_browser_do', 'dsh_browser_state', 'dsh_browser_challenge',
67
+ 'dsh_browser_list_tabs', 'dsh_browser_switch_tab', 'dsh_browser_close_tab', 'dsh_browser_back',
68
+ 'dsh_browser_reference_capture', 'dsh_browser_reference_reveal', 'dsh_browser_reference_list',
69
+ 'dsh_browser_request_takeover', 'dsh_browser_help',
70
+ ])
71
+
72
+ /**
73
+ * The rest of the catalog, loaded by group with dsh_browser_load_tools. A loaded tool is never
74
+ * unregistered, so the tool list only grows and the request prefix stays cacheable. Any tool not
75
+ * named here or in CORE_TOOLS belongs to `more`.
76
+ */
77
+ export const TOOL_GROUPS: Readonly<Record<string, readonly string[]>> = {
78
+ forms: ['dsh_browser_check', 'dsh_browser_clear', 'dsh_browser_set_value', 'dsh_browser_get_value', 'dsh_browser_upload', 'dsh_browser_drag', 'dsh_browser_hover', 'dsh_browser_dialog', 'dsh_browser_click_sequence'],
79
+ navigation: ['dsh_browser_forward', 'dsh_browser_refresh', 'dsh_browser_history', 'dsh_browser_replay', 'dsh_browser_visited', 'dsh_browser_download'],
80
+ debug: ['dsh_browser_console', 'dsh_browser_network', 'dsh_browser_wait_for_response', 'dsh_browser_data_sources', 'dsh_browser_fetch_json', 'dsh_browser_assert', 'dsh_browser_doctor'],
81
+ session: ['dsh_browser_session', 'dsh_browser_reset', 'dsh_browser_reset_session', 'dsh_browser_restrict', 'dsh_browser_auth', 'dsh_browser_shortcuts'],
82
+ more: [],
83
+ }
84
+
85
+ /**
86
+ * Minimal static routing hint for the `core` surface. Detailed tool guidance lives in each tool's
87
+ * description, runtime CHALLENGE banners, and SKILL.md so unrelated conversations do not pay for
88
+ * a long global manual or inherit cross-plugin behavior rules.
89
+ */
90
+ const CORE_PROMPT = 'Use dsh_browser_* tools to drive the built-in browser (per-task isolated sessions). Batch fixed steps with dsh_browser_do, or loops/branching/parallel reads with dsh_browser_code (or run_code under PTC); load extra groups via dsh_browser_load_tools and follow any CHALLENGE banner.'
91
+
92
+ /** Minimal static routing hint for the `tools` surface. */
93
+ const TOOLS_PROMPT = 'Use dsh_browser_* tools to drive the built-in browser (per-task isolated sessions). Prefer dsh_browser_a11y or dsh_browser_snapshot to locate targets, dsh_browser_fill for forms, dsh_browser_scrape for lists, dsh_browser_do for multi-step runs, and dsh_browser_assert or dsh_browser_console/network to verify; follow any CHALLENGE banner.'
94
+
95
+ /** Register all browser tools with `ctx.tools`. */
96
+ export function apply(ctx: Context, config: Config = {}): void {
97
+ const timeoutMs = config.timeoutMs ?? TOOL_DEFAULT_TIMEOUT_MS
98
+ const surface = config.surface ?? 'core'
99
+ const maxWaitMs = maxWaitFor(timeoutMs)
100
+ const maxFillFields = MAX_FILL_FIELDS
101
+ // Per-context state: sessions, in-flight opens, and the restriction are
102
+ // scoped to THIS plugin apply, so parallel contexts never share sessions
103
+ // or leak restrictions into each other.
104
+ const state = createState()
105
+ const takeovers = new BrowserTakeovers()
106
+ installTakeovers(ctx, takeovers)
107
+ liveStates.add(state)
108
+ ctx.effect(() => () => { liveStates.delete(state) })
109
+ // Re-apply resets the restriction: an omitted allowedActions lifts it.
110
+ state.configRestrictedTo = config.allowedActions !== undefined ? [...config.allowedActions] : undefined
111
+
112
+ ctx.systemPrompt.section({
113
+ name: 'tool:dsh-browser-reference-presentation',
114
+ order: 151,
115
+ text: 'Browser references are already displayed as interactive capsules. The capsules provide source navigation. Do not repeat browser-reference markers, dsh-browser-ref: URIs, source URLs, or source/citation links in replies; answer using the quoted content instead.',
116
+ })
117
+
118
+ ctx.systemPrompt.section({
119
+ name: 'tool:dsh-builtin-browser',
120
+ // Tool guidance band is 100-199; 150 keeps clear of the common 110/120
121
+ // tool sections so ordering does not depend on plugin load sequence.
122
+ order: 150,
123
+ text: surface === 'code'
124
+ ? CODE_PROMPT
125
+ : surface === 'core'
126
+ ? CORE_PROMPT
127
+ : TOOLS_PROMPT,
128
+ })
129
+
130
+ /**
131
+ * Register one tool, turning a name collision into a warning instead of a dead apply.
132
+ *
133
+ * Registering the tools in sequence without this is how ONE taken name becomes thirty-two
134
+ * missing ones: the throw aborts the rest of the apply, and what the user sees is a plugin that
135
+ * half-exists. That is precisely the shape of the failure reported against a sibling plugin,
136
+ * where the first spec collided and all six vanished behind a `console.warn` a desktop user
137
+ * never sees.
138
+ *
139
+ * A name this plugin cannot have is worth a sentence in the log, not the toolset.
140
+ * @param definition - the tool to register.
141
+ */
142
+ // One store for this apply: it caches by mtime, so reading it per download is a stat, not a parse.
143
+ const settingsStore = new SettingsStore()
144
+
145
+ const catalog = new Map<string, CatalogTool>()
146
+ const loaded = new Set<string>()
147
+ const registerSafely = (definition: ReturnType<typeof defineTool>): void => {
148
+ try {
149
+ const execute = definition.execute.bind(definition)
150
+ const name = definition.name
151
+ definition = { ...definition, execute: async (args, exec) => {
152
+ const owner = taskKey(exec)
153
+ if (name !== TAKEOVER_TOOL && takeovers.blocks(owner)
154
+ && (!READ_ONLY_TOOLS.has(name) || ['dsh_browser_reset', 'dsh_browser_reset_session', 'dsh_browser_reference_reveal'].includes(name))) {
155
+ const requested = (args as { tabId?: string }).tabId
156
+ let tab = requested
157
+ if (requested?.startsWith('dsh-tab:')) {
158
+ const session = state.sessionsByTask.get(owner)
159
+ if (session) tab = resolveTabHandle(browserSessionHandle(owner, session), requested).tab
160
+ }
161
+ if (tab === undefined || takeovers.blocks(owner, tab)) {
162
+ throw new BrowserToolError('Browser tab is awaiting human takeover. Agent browser actions are refused until the human confirms completion or skips the request.', 'BROWSER_TAKEOVER_PENDING')
163
+ }
164
+ }
165
+ try {
166
+ return await execute(args, exec)
167
+ } catch (error) {
168
+ throw toBrowserToolError(error, (exec as { signal?: AbortSignal } | undefined)?.signal)
169
+ }
170
+ } }
171
+ catalog.set(definition.name, definition as unknown as CatalogTool)
172
+ if (surface === 'tools' || definition.name === TAKEOVER_TOOL || (surface === 'core' && CORE_TOOLS.has(definition.name))) {
173
+ ctx.tools.register(definition)
174
+ loaded.add(definition.name)
175
+ }
176
+ } catch (error) {
177
+ ctx.logger?.warn?.(
178
+ `dsh-builtin-browser: could not register ${definition.name} (${String(error)}). Another `
179
+ + 'plugin has probably taken that name — browser tool names are a shared namespace. The '
180
+ + 'rest of this plugin\'s tools are unaffected.',
181
+ )
182
+ }
183
+ }
184
+
185
+ const scope: ToolScope = { ctx, config, state, takeovers, settingsStore, timeoutMs, maxWaitMs, maxFillFields, surface }
186
+ const definitions = new Map([
187
+ ...debugTools(scope), ...navigationTools(scope), ...observationTools(scope),
188
+ ...interactionTools(scope), ...referenceTools(scope),
189
+ ].map(definition => [definition.name, definition] as const))
190
+ for (const toolName of REGISTRATION_ORDER) {
191
+ const definition = definitions.get(toolName)
192
+ if (definition !== undefined) registerSafely(definition)
193
+ }
194
+
195
+ if (surface !== 'tools') {
196
+ try {
197
+ // Reads the page the action left behind without starting a session or installing the probe.
198
+ const pulse = async (exec: never): Promise<PagePulse | undefined> => {
199
+ const browser = ctx.get('browser')
200
+ const session = state.sessionsByTask.get(taskKey(exec))
201
+ if (browser === undefined || session === undefined) return undefined
202
+ try {
203
+ const raw = JSON.parse(await pageOperationValue(browser, session, { operation: 'pulse' }, (exec as { signal?: AbortSignal }).signal)) as Partial<PagePulse> | null
204
+ if (typeof raw?.title !== 'string') return undefined
205
+ return {
206
+ title: raw.title,
207
+ alerts: Array.isArray(raw.alerts) ? raw.alerts.filter(text => typeof text === 'string') : [],
208
+ dialogs: Array.isArray(raw.dialogs) ? raw.dialogs.filter(row => typeof row?.at === 'number' && typeof row.kind === 'string') : [],
209
+ probe: Number(raw.probe) || 0,
210
+ }
211
+ } catch {
212
+ return undefined
213
+ }
214
+ }
215
+ const code = createCodeTool(catalog, pulse)
216
+ // On the code surface it is the only browser tool, so it stays even under PTC; on `core`,
217
+ // DSH's PTC run_code already batches every tool, so the code tool steps aside.
218
+ registerTool(ctx.tools, code.tool, surface === 'core' ? (context?: { readonly agent?: unknown }) => !ptcRuntimeActive(ctx, context) : undefined)
219
+ ctx.effect(() => code.dispose)
220
+ } catch (error) {
221
+ ctx.logger?.warn?.(`dsh-builtin-browser: could not register ${CODE_TOOL} (${String(error)}).`)
222
+ }
223
+ }
224
+ if (surface === 'core') {
225
+ const grouped = new Set(Object.values(TOOL_GROUPS).flat())
226
+ const members = (group: string): string[] => group === 'more'
227
+ ? [...catalog.keys()].filter(name => !CORE_TOOLS.has(name) && !grouped.has(name)).sort()
228
+ : (TOOL_GROUPS[group] ?? []).filter(name => catalog.has(name))
229
+ try {
230
+ const loader = defineTool({
231
+ name: LOAD_TOOL,
232
+ description: `Load more browser tools by group; they stay available for the rest of the run. Groups: ${Object.entries(TOOL_GROUPS).map(([group, names]) => `${group} (${group === 'more' ? 'every other browser tool' : names.map(name => name.slice('dsh_browser_'.length)).join(', ')})`).join('; ')}. dsh_browser_code can already call every tool without loading it.`,
233
+ parameters: {
234
+ groups: { type: 'array', items: { type: 'string', enum: Object.keys(TOOL_GROUPS) }, required: true, description: 'Groups to load.' },
235
+ },
236
+ output: {
237
+ schema: { type: 'object', additionalProperties: false, properties: {
238
+ loaded: { type: 'array', items: { type: 'string' }, required: true },
239
+ available: { type: 'array', items: { type: 'string' }, required: true },
240
+ } },
241
+ render: (_args, value) => [{ type: 'text', text: value.loaded.length > 0 ? `Loaded: ${value.loaded.join(', ')}.` : `Already loaded: ${value.available.join(', ')}.` }],
242
+ },
243
+ isConcurrencySafe: () => false,
244
+ async execute(args) {
245
+ const groups = Array.isArray(args.groups) ? args.groups.map(String) : []
246
+ const unknown = groups.filter(group => !(group in TOOL_GROUPS))
247
+ if (groups.length === 0 || unknown.length > 0) throw new BrowserToolError(`unknown tool group(s): ${unknown.join(', ') || '(none given)'}; groups are ${Object.keys(TOOL_GROUPS).join(', ')}`, 'BROWSER_UNKNOWN_TOOL_GROUP')
248
+ const names = [...new Set(groups.flatMap(members))]
249
+ const fresh: string[] = []
250
+ for (const name of names) {
251
+ const definition = catalog.get(name)
252
+ if (definition === undefined || loaded.has(name)) continue
253
+ ctx.tools.register(definition as unknown as ReturnType<typeof defineTool>)
254
+ loaded.add(name)
255
+ fresh.push(name)
256
+ }
257
+ return { loaded: fresh, available: names }
258
+ },
259
+ })
260
+ ctx.tools.register(loader)
261
+ } catch (error) {
262
+ ctx.logger?.warn?.(`dsh-builtin-browser: could not register ${LOAD_TOOL} (${String(error)}).`)
263
+ }
264
+ }
265
+ }