dsh-builtin-browser 1.0.0 → 1.0.3

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 (364) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/pr64-maintenance.md +1 -1
  19. package/docs/tool-reference.md +1 -1
  20. package/docs/user-guide.md +1 -1
  21. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  22. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  23. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  24. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  25. package/dsh-host-patch/README.md +4 -0
  26. package/dsh-host-patch/apply.mjs +61 -13
  27. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  28. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  29. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  45. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  46. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  47. package/dsh-host-patch/sources/manifest.json +218 -0
  48. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  82. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  83. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  84. package/dsh-host-patch/sources/series.json +260 -0
  85. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  86. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  87. package/dsh-host-patch/tauri-revision1.json +39 -0
  88. package/dsh-host-patch/tauri.json +43 -0
  89. package/dsh-host-patch/v023-alpha2.json +153 -0
  90. package/lib/browser/anti-bot.js +215 -0
  91. package/lib/browser/deep-dom.js +39 -0
  92. package/lib/browser/runtime.js +15 -0
  93. package/lib/browser/takeover-target.js +13 -6
  94. package/lib/browser/types.js +30 -1
  95. package/lib/browser-electron/authenticated-route.js +16 -2
  96. package/lib/browser-electron/automatic-maintenance.js +16 -10
  97. package/lib/browser-electron/bridge-connection.js +3 -8
  98. package/lib/browser-electron/bridge-install.js +2 -1
  99. package/lib/browser-electron/bridge-status.js +55 -26
  100. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  101. package/lib/browser-electron/desktop-identity.js +28 -5
  102. package/lib/browser-electron/desktop-shell.js +64 -0
  103. package/lib/browser-electron/electron-provision.js +105 -18
  104. package/lib/browser-electron/entry.js +129 -46
  105. package/lib/browser-electron/extension-browser.js +4 -4
  106. package/lib/browser-electron/foreground-watch.js +134 -0
  107. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  108. package/lib/browser-electron/guest-route.js +181 -32
  109. package/lib/browser-electron/guest-runtime.js +61 -10
  110. package/lib/browser-electron/guest-storage.js +2 -2
  111. package/lib/browser-electron/history-store.js +1 -5
  112. package/lib/browser-electron/host-main.js +8 -4
  113. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  114. package/lib/browser-electron/maintenance-route.js +2 -1
  115. package/lib/browser-electron/missing-system-browser.js +5 -9
  116. package/lib/browser-electron/preferred-browser.js +7 -3
  117. package/lib/browser-electron/preview-route.js +9 -13
  118. package/lib/browser-electron/process-ownership.js +1 -1
  119. package/lib/browser-electron/profile-command.js +2 -1
  120. package/lib/browser-electron/profile-extension.js +5 -0
  121. package/lib/browser-electron/profile-lease.js +152 -47
  122. package/lib/browser-electron/provider-core.js +527 -0
  123. package/lib/browser-electron/provider-interaction.js +963 -0
  124. package/lib/browser-electron/provider-media.js +518 -0
  125. package/lib/browser-electron/provider-navigation.js +301 -0
  126. package/lib/browser-electron/provider-observation.js +623 -0
  127. package/lib/browser-electron/provider-tabs.js +372 -0
  128. package/lib/browser-electron/provider.js +150 -3301
  129. package/lib/browser-electron/reference-route.js +9 -18
  130. package/lib/browser-electron/remote-host.js +79 -34
  131. package/lib/browser-electron/runtime-status.js +56 -6
  132. package/lib/browser-electron/settings-store.js +3 -6
  133. package/lib/browser-electron/sidebar-only-host.js +1 -1
  134. package/lib/browser-electron/system-browser.js +539 -172
  135. package/lib/browser-electron/tauri-host.js +208 -0
  136. package/lib/browser-electron/virtual-cursor.js +23 -13
  137. package/lib/browser-reference/service.js +22 -4
  138. package/lib/browser-reference/web-sources.js +1 -1
  139. package/lib/client.js +43409 -0
  140. package/lib/compat/host-features.js +75 -0
  141. package/lib/reference-source.js +1 -1
  142. package/lib/reference-text.js +23 -1
  143. package/lib/takeover-protocol.js +1 -1
  144. package/lib/tool-browser/block-recovery.js +69 -0
  145. package/lib/tool-browser/code-tool.js +170 -19
  146. package/lib/tool-browser/code-worker.js +115 -20
  147. package/lib/tool-browser/errors.js +34 -0
  148. package/lib/tool-browser/index.js +66 -3593
  149. package/lib/tool-browser/page-probe.js +227 -28
  150. package/lib/tool-browser/panel-page.js +2 -1
  151. package/lib/tool-browser/probe-client.js +157 -0
  152. package/lib/tool-browser/screenshot-annotations.js +108 -0
  153. package/lib/tool-browser/state.js +337 -0
  154. package/lib/tool-browser/takeover.js +1 -1
  155. package/lib/tool-browser/tools-debug.js +862 -0
  156. package/lib/tool-browser/tools-interaction.js +993 -0
  157. package/lib/tool-browser/tools-navigation.js +807 -0
  158. package/lib/tool-browser/tools-observation.js +461 -0
  159. package/lib/tool-browser/tools-reference.js +293 -0
  160. package/lib/web-guest.js +1 -0
  161. package/package.json +16 -54
  162. package/README.en.md +0 -89
  163. package/browser-extension/constants.mjs +0 -20
  164. package/browser-extension/controller.mjs +0 -293
  165. package/browser-extension/locales.mjs +0 -15
  166. package/browser-extension/manifest.json +0 -12
  167. package/browser-extension/options.html +0 -14
  168. package/browser-extension/options.mjs +0 -9
  169. package/browser-extension/permission-guard.mjs +0 -13
  170. package/browser-extension/worker.mjs +0 -74
  171. package/dist/client.cjs +0 -43167
  172. package/lib/browser-electron/package-removal.js +0 -5
  173. package/lib/browser-reference/submission-receipts.js +0 -139
  174. package/scripts/build.mjs +0 -66
  175. package/scripts/bundle-host.mjs +0 -28
  176. package/scripts/fix-exports.mjs +0 -50
  177. package/scripts/install-electron.mjs +0 -51
  178. package/scripts/verify-exports.mjs +0 -47
  179. package/scripts/verify-preview-sdk.mjs +0 -93
  180. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  181. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  182. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  183. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  184. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  185. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  186. package/skills/dsh-debug-host/SKILL.md +0 -56
  187. package/skills/dsh-debug-self/SKILL.md +0 -50
  188. package/src/bridge-compatibility.ts +0 -39
  189. package/src/browser/handles.ts +0 -89
  190. package/src/browser/runtime.ts +0 -560
  191. package/src/browser/takeover-target.ts +0 -36
  192. package/src/browser/types.ts +0 -817
  193. package/src/browser-electron/authenticated-route.ts +0 -84
  194. package/src/browser-electron/automatic-maintenance.ts +0 -726
  195. package/src/browser-electron/bridge-auto.ts +0 -159
  196. package/src/browser-electron/bridge-connection.ts +0 -385
  197. package/src/browser-electron/bridge-endpoint.ts +0 -129
  198. package/src/browser-electron/bridge-install.ts +0 -289
  199. package/src/browser-electron/bridge-maintenance.ts +0 -189
  200. package/src/browser-electron/bridge-status.ts +0 -347
  201. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  202. package/src/browser-electron/desktop-identity.ts +0 -320
  203. package/src/browser-electron/document-readiness.ts +0 -45
  204. package/src/browser-electron/electron-provision.ts +0 -261
  205. package/src/browser-electron/entry.ts +0 -1301
  206. package/src/browser-electron/ephemeral-profile.ts +0 -189
  207. package/src/browser-electron/extension-browser.ts +0 -223
  208. package/src/browser-electron/extension-setup.ts +0 -67
  209. package/src/browser-electron/file-write.ts +0 -31
  210. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  211. package/src/browser-electron/guest-cookie-store.ts +0 -59
  212. package/src/browser-electron/guest-css-runtime.ts +0 -76
  213. package/src/browser-electron/guest-css.ts +0 -68
  214. package/src/browser-electron/guest-route.ts +0 -568
  215. package/src/browser-electron/guest-runtime.ts +0 -357
  216. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  217. package/src/browser-electron/guest-storage.ts +0 -117
  218. package/src/browser-electron/history-store.ts +0 -227
  219. package/src/browser-electron/host-main.ts +0 -1381
  220. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  221. package/src/browser-electron/http-body.ts +0 -65
  222. package/src/browser-electron/json-reply.ts +0 -47
  223. package/src/browser-electron/maintenance-broker.ts +0 -166
  224. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  225. package/src/browser-electron/maintenance-route.ts +0 -67
  226. package/src/browser-electron/missing-system-browser.ts +0 -113
  227. package/src/browser-electron/open-slot.ts +0 -49
  228. package/src/browser-electron/package-removal.ts +0 -4
  229. package/src/browser-electron/paths.ts +0 -25
  230. package/src/browser-electron/preferred-browser.ts +0 -120
  231. package/src/browser-electron/preview-route.ts +0 -218
  232. package/src/browser-electron/process-ownership.ts +0 -168
  233. package/src/browser-electron/process.ts +0 -23
  234. package/src/browser-electron/profile-checkpoint.ts +0 -187
  235. package/src/browser-electron/profile-command.ts +0 -46
  236. package/src/browser-electron/profile-extension.ts +0 -124
  237. package/src/browser-electron/profile-lease.ts +0 -115
  238. package/src/browser-electron/profile-residue.ts +0 -49
  239. package/src/browser-electron/provider.ts +0 -4571
  240. package/src/browser-electron/reference-route.ts +0 -608
  241. package/src/browser-electron/remote-host.ts +0 -1462
  242. package/src/browser-electron/rpc-input.ts +0 -13
  243. package/src/browser-electron/rpc-ops.ts +0 -41
  244. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  245. package/src/browser-electron/runtime-route.ts +0 -105
  246. package/src/browser-electron/runtime-status.ts +0 -242
  247. package/src/browser-electron/settings-route.ts +0 -64
  248. package/src/browser-electron/settings-store.ts +0 -589
  249. package/src/browser-electron/shortcuts-route.ts +0 -112
  250. package/src/browser-electron/sidebar-only-host.ts +0 -298
  251. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  252. package/src/browser-electron/system-browser.ts +0 -1497
  253. package/src/browser-electron/timing.ts +0 -16
  254. package/src/browser-electron/virtual-cursor.ts +0 -152
  255. package/src/browser-electron/windows-system.ts +0 -24
  256. package/src/browser-reference/delivery.ts +0 -384
  257. package/src/browser-reference/entry.ts +0 -631
  258. package/src/browser-reference/export.ts +0 -339
  259. package/src/browser-reference/import.ts +0 -303
  260. package/src/browser-reference/page-script.ts +0 -1537
  261. package/src/browser-reference/service.ts +0 -1315
  262. package/src/browser-reference/store.ts +0 -172
  263. package/src/browser-reference/submission-receipts.ts +0 -122
  264. package/src/browser-reference/text-quote.ts +0 -219
  265. package/src/browser-reference/types.ts +0 -195
  266. package/src/browser-reference/visible.ts +0 -367
  267. package/src/browser-reference/web-sources.ts +0 -103
  268. package/src/client/browser/BrowserController.ts +0 -693
  269. package/src/client/browser/BrowserFrame.ts +0 -78
  270. package/src/client/browser/BrowserNavigation.ts +0 -169
  271. package/src/client/browser/BrowserPage.ts +0 -23
  272. package/src/client/browser/BrowserPersistence.ts +0 -44
  273. package/src/client/browser/IframeImpl.ts +0 -176
  274. package/src/client/browser/child-tabs.ts +0 -14
  275. package/src/client/browser/iframe-reference.ts +0 -67
  276. package/src/client/browser/initialization.ts +0 -262
  277. package/src/client/browser/omnibox.ts +0 -243
  278. package/src/client/browser/store.ts +0 -38
  279. package/src/client/browser/takeover-channel.ts +0 -72
  280. package/src/client/browser/url.ts +0 -46
  281. package/src/client/browser/web-reference-source.ts +0 -52
  282. package/src/client/css-modules.d.ts +0 -4
  283. package/src/client/definition.tsx +0 -30
  284. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  285. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  286. package/src/client/electron/NativeChildPresentation.ts +0 -45
  287. package/src/client/electron/NativeViewPage.ts +0 -251
  288. package/src/client/electron/pages.ts +0 -23
  289. package/src/client/electron/reference-overlay.ts +0 -53
  290. package/src/client/electron/workspace.ts +0 -33
  291. package/src/client/index.ts +0 -293
  292. package/src/client/locales.ts +0 -857
  293. package/src/client/pages.ts +0 -28
  294. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  295. package/src/client/reference/client/draft-reference.ts +0 -167
  296. package/src/client/reference/client/index.ts +0 -7
  297. package/src/client/reference/client/ordered-submission.ts +0 -108
  298. package/src/client/reference/client/pending-delivery.ts +0 -216
  299. package/src/client/reference/client/plugin.ts +0 -189
  300. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  301. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  302. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  303. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  304. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  305. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  306. package/src/client/reference/client/production/assembly.ts +0 -471
  307. package/src/client/reference/client/production/asset-store.ts +0 -144
  308. package/src/client/reference/client/production/availability.ts +0 -74
  309. package/src/client/reference/client/production/bytes.ts +0 -36
  310. package/src/client/reference/client/production/delivery-client.ts +0 -211
  311. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  312. package/src/client/reference/client/production/http-transport.ts +0 -217
  313. package/src/client/reference/client/production/production-submission.ts +0 -310
  314. package/src/client/reference/client/production/protocol.ts +0 -231
  315. package/src/client/reference/client/production/reference-card.ts +0 -240
  316. package/src/client/reference/client/production/reference-labels.ts +0 -29
  317. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  318. package/src/client/reference/client/production/reveal.ts +0 -215
  319. package/src/client/reference/client/production/runtime.ts +0 -1101
  320. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  321. package/src/client/reference/client/production/source-marker.ts +0 -63
  322. package/src/client/reference/client/production/source-opener.ts +0 -55
  323. package/src/client/reference/client/production/styles.ts +0 -104
  324. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  325. package/src/client/reference/client/reveal.ts +0 -107
  326. package/src/client/reference/client/scheme.ts +0 -114
  327. package/src/client/reference/client/types.ts +0 -168
  328. package/src/client/reference/css-modules.d.ts +0 -4
  329. package/src/client/reference/index.ts +0 -11
  330. package/src/client/reference-capture-owner.ts +0 -162
  331. package/src/client/reference-intents.ts +0 -36
  332. package/src/client/settings/index.ts +0 -34
  333. package/src/client/settings/panel.ts +0 -2657
  334. package/src/client/shortcut-open.ts +0 -30
  335. package/src/client/startpage/binding.ts +0 -99
  336. package/src/client/startpage/controller.ts +0 -303
  337. package/src/client/startpage/model.ts +0 -279
  338. package/src/client/view/Browser.module.css +0 -751
  339. package/src/client/view/BrowserBody.tsx +0 -314
  340. package/src/client/view/BrowserPresentation.ts +0 -9
  341. package/src/client/view/BrowserTitle.tsx +0 -17
  342. package/src/client/view/IframePresentation.ts +0 -344
  343. package/src/client/view/StartPage.tsx +0 -597
  344. package/src/client/view/TakeoverBanner.tsx +0 -21
  345. package/src/index.ts +0 -110
  346. package/src/reference-owner.ts +0 -5
  347. package/src/reference-page.ts +0 -9
  348. package/src/reference-source.ts +0 -3
  349. package/src/reference-text.ts +0 -197
  350. package/src/startpage-settings.ts +0 -103
  351. package/src/startpage.ts +0 -71
  352. package/src/takeover-protocol.ts +0 -19
  353. package/src/tool-browser/code-tool.ts +0 -401
  354. package/src/tool-browser/code-worker.ts +0 -639
  355. package/src/tool-browser/element-fields.ts +0 -167
  356. package/src/tool-browser/index.ts +0 -3733
  357. package/src/tool-browser/page-probe.ts +0 -474
  358. package/src/tool-browser/panel-page.ts +0 -124
  359. package/src/tool-browser/screenshot-image.ts +0 -49
  360. package/src/tool-browser/takeover.ts +0 -198
  361. package/src/types/electron-shim.d.ts +0 -144
  362. package/src/types.ts +0 -85
  363. package/src/web-guest.ts +0 -34
  364. package/tools/accept-desktop.mjs +0 -148
@@ -1,589 +0,0 @@
1
- import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
2
- /**
3
- * Plugin-owned settings document — the switches the browser settings panel
4
- * exposes, stored next to the browsing history so both follow the same rules:
5
- * they survive the browser process and DSH restarts.
6
- *
7
- * Every field is optional on disk and falls back to a default, so a hand-edited
8
- * or older file never breaks startup; an unreadable document refuses capability
9
- * gates while retaining the defaults for presentation and other conveniences.
10
- * @module dsh-browser/browser-electron/settings-store
11
- */
12
-
13
- import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
14
- import { dirname, join } from 'node:path'
15
- import { dshHome } from './paths.ts'
16
- import type { BrowserChannel } from './system-browser.ts'
17
-
18
- /** Vision/operation strategy the provider prefers when the model can see. */
19
- export type VisionStrategy = 'auto' | 'nonVisual'
20
-
21
- /**
22
- * Whether a launched browser gets a window.
23
- *
24
- * Split from {@link VisionStrategy} because these answer different questions: that one is how the
25
- * agent examines a page, this one is whether the browser has anywhere to draw.
26
- */
27
- export type HeadlessMode = 'auto' | 'headless' | 'windowed'
28
-
29
- /** Every value {@link HeadlessMode} accepts, for validation and the settings UI. */
30
- export const HEADLESS_MODES = ['auto', 'headless', 'windowed'] as const
31
-
32
- /**
33
- * Which profile the browser runs on.
34
- *
35
- * `plugin` 是插件自己的目录(默认):不碰用户的窗口、书签与登录态,也不会因为用户开着浏览器而启动失败。
36
- * `user` 复用用户自己的 profile,登录态天然可用,但要求用户的浏览器先关掉——否则 Chromium 以
37
- * exit 21(`PROFILE_IN_USE`)退出。
38
- */
39
- export type SystemProfile = 'user' | 'plugin'
40
-
41
- /** Every value {@link SystemProfile} accepts, for validation and the settings UI. */
42
- export const SYSTEM_PROFILES = ['user', 'plugin'] as const
43
-
44
- /** The full settings document, with every field resolved. */
45
- export interface BrowserSettings {
46
- /** Persistent browsing history (visited pages). */
47
- readonly history: {
48
- readonly enabled: boolean
49
- readonly maxEntries: number
50
- readonly maxAgeDays: number
51
- }
52
- /** Login-state retention: cookies and the browser profile. */
53
- readonly cookies: {
54
- readonly persist: boolean
55
- }
56
- /** Presentation behaviour. */
57
- readonly ui: {
58
- /** Auto-expand the side panel once per task, then leave the user alone. */
59
- readonly autoExpandOnce: boolean
60
- /** Release the browser when its session ends, instead of waiting for a close. */
61
- readonly closeWithSession: boolean
62
- /** Show the synthetic cursor/click feedback while the agent operates. */
63
- readonly virtualCursor: boolean
64
- /**
65
- * Quiet mode: drive the page without taking over the screen.
66
- *
67
- * Off (the default) keeps the contract this plugin is built on — human and agent share one
68
- * window, so an operation raises it and the user can see what is being driven. On, the
69
- * carrier never activates the application and never steals keyboard focus:
70
- * - screenshots of a minimized or hidden window go through CDP `Page.captureScreenshot`
71
- * instead of `capturePage()`, so grabbing an image stops being a reason to show a window;
72
- * - navigation and tab switching only change which view is visible INSIDE the window; a
73
- * minimized window stays minimized;
74
- * - synthesized input still needs a display surface (Chromium drops `Input.*` for a view
75
- * without one), so that one barrier may restore a minimized window — with
76
- * `showInactive()`, which shows it without becoming the key window, and without
77
- * `moveTop()`.
78
- *
79
- * Reported as issue #35: a minimized browser window was restored and focused by the next
80
- * screenshot or click, pulling the user out of whatever they were typing in.
81
- */
82
- readonly quiet: boolean
83
- }
84
- /** Visual vs non-visual operation strategy. */
85
- readonly vision: {
86
- readonly strategy: VisionStrategy
87
- }
88
- /** Which browser binary carries the agent's pages. */
89
- readonly browser: {
90
- readonly channel: BrowserChannel
91
- /**
92
- * Whether the browser gets a window.
93
- *
94
- * `auto` (the default) launches headless when the process has no display — no `DISPLAY` and no
95
- * `WAYLAND_DISPLAY` — and with a window otherwise. That combination is what makes the plugin
96
- * work under systemd, in a container, or on an SSH-only server while leaving desktop users
97
- * with the visible window they expect. `true` forces headless (CI, screenshot-only servers);
98
- * `false` forces a window, so a misconfigured display fails loudly instead of silently
99
- * degrading into a browser nobody can see.
100
- *
101
- * Reported as issue #32: as a systemd service there is no display, Chromium exits with
102
- * "could not connect to display", and every `dsh_browser_*` call failed with "exited
103
- * immediately after launch".
104
- */
105
- readonly headless: HeadlessMode
106
- /**
107
- * `plugin` (default) launches a separate DSH-owned persistent profile.
108
- * Explicit `user` attaches to the running, paired extension profile; never launches it.
109
- */
110
- readonly systemProfile: SystemProfile
111
- }
112
- /** Whether the agent may read cookies / export login state. */
113
- readonly credentials: {
114
- readonly allowRead: boolean
115
- }
116
- /**
117
- * Live view of the browser for a remote operator (issue #34).
118
- *
119
- * OFF by default, and that default is the feature's main safety property: a live browser frame can
120
- * contain a CAPTCHA, an account name, or logged-in content, so nobody should be able to watch
121
- * without the host having said yes first. The remote side also cannot turn it on: this file is
122
- * written through the plugin's own settings route, which admits only same-origin requests from the
123
- * host's own UI, and the frame endpoint refuses everything when this is false.
124
- */
125
- readonly remoteView: {
126
- /** Serve browser frames to a remote viewer. */
127
- readonly enabled: boolean
128
- }
129
- /**
130
- * What the agent is allowed to DO, as opposed to what it may look at.
131
- *
132
- * These are OPERATOR switches: the settings panel is not reachable from the model, so a
133
- * value here refuses whatever the model asks for, and no tool can lift it. That is what
134
- * separates them from `dsh_browser_restrict`, which is the model's own soft guardrail. All
135
- * three default to on, which is the documented out-of-the-box behaviour.
136
- */
137
- readonly actions: {
138
- /** Run arbitrary page scripts in the active tab (`dsh_browser_execute`). */
139
- readonly allowExecute: boolean
140
- /** Download a URL to disk (`dsh_browser_download`). */
141
- readonly allowDownload: boolean
142
- /** Write cookies — importing login state (`dsh_browser_auth` restore). */
143
- readonly allowCredentialWrite: boolean
144
- }
145
- /**
146
- * Where a downloaded file goes after it lands on disk.
147
- *
148
- * An ATTRIBUTE of a download, not a new concept: an empty `tool` means the behaviour is exactly
149
- * what it was before this existed. The user owns the field, can point it at any MCP tool that
150
- * takes a path (Feishu drive, Baidu Netdisk), and can empty it again at any time.
151
- */
152
- /**
153
- * Desktop bridge handled without asking.
154
- *
155
- * Historical automatic-install preference retained when reading existing settings documents.
156
- * Runtime automatic installation is disabled; bridge maintenance is an explicit action after
157
- * DSH Desktop is closed, even when an older document contains autoInstall=true.
158
- */
159
- readonly bridge: {
160
- /** Legacy preference; it does not trigger installation at runtime. Default false. */
161
- readonly autoInstall: boolean
162
- }
163
- readonly delivery: {
164
- /** MCP tool that receives the saved file. Empty = save locally and stop there. */
165
- readonly tool: string
166
- /** Flat argument template; {path}, {name} and {size} are substituted into string values. */
167
- readonly args: Readonly<Record<string, string>>
168
- /** `keep-local` reports both outcomes; `stop` reports the handoff failure as the result. */
169
- readonly onFail: 'keep-local' | 'stop'
170
- /** Per-site override: page host → tool name. */
171
- readonly sites: Readonly<Record<string, string>>
172
- }
173
- }
174
-
175
- /** Defaults for every switch: the documented out-of-the-box behaviour. */
176
- export const DEFAULT_SETTINGS: BrowserSettings = {
177
- history: { enabled: true, maxEntries: 5_000, maxAgeDays: 90 },
178
- cookies: { persist: true },
179
- ui: { autoExpandOnce: true, closeWithSession: false, virtualCursor: true, quiet: false },
180
- vision: { strategy: 'auto' },
181
- // External browsers require an explicit choice; automatic modes never open native windows.
182
- browser: { channel: 'sidebar', headless: 'auto', systemProfile: 'plugin' },
183
- credentials: { allowRead: true },
184
- // Off unless the host turns it on. A frame can show a CAPTCHA, an account name, or logged-in
185
- // content, so watching is an explicit decision rather than something a remote client can arrange.
186
- remoteView: { enabled: false },
187
- bridge: { autoInstall: false },
188
- actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true },
189
- // Local by default: the file lands in downloadDir and nothing leaves the machine until the user
190
- // names a tool here. {file_path} is the argument name both Feishu's and Netdisk's upload tools use.
191
- delivery: { tool: '', args: { file_path: '{path}' }, onFail: 'keep-local', sites: {} },
192
- }
193
-
194
- /**
195
- * Absolute path of the settings file, beside the browser profile and the
196
- * browsing history.
197
- * @returns the settings file path.
198
- */
199
- export function settingsPath(): string {
200
- const home = dshHome()
201
- return join(home, BROWSER_PROFILE_DIR, 'settings.json')
202
- }
203
-
204
- /** Coerce one boolean field, keeping the default when absent or mistyped. */
205
- function bool(value: unknown, fallback: boolean): boolean {
206
- return typeof value === 'boolean' ? value : fallback
207
- }
208
-
209
- /**
210
- * Coerce one boolean field that GATES A CAPABILITY.
211
- *
212
- * The difference from {@link bool} is what a mistyped value means. Absent still takes the
213
- * default — a document written before the switch existed is the documented behaviour. But
214
- * present-and-not-a-boolean is a document this code cannot read, and for a switch that gates
215
- * something the operator chose to limit, unreadable resolves to OFF. `bool`'s fallback made
216
- * `"false"` (a string), `null` (a truncated write) and `1` all mean the same as `true`, so a
217
- * single dropped byte reopened every capability that had been turned off.
218
- * @param value - the raw value from the settings document.
219
- * @param fallback - the default, used only when the field is absent.
220
- * @returns the value when it is a boolean, `false` when it is anything else.
221
- */
222
- function gate(value: unknown, fallback: boolean): boolean {
223
- if (value === undefined) return fallback
224
- return value === true
225
- }
226
-
227
- /**
228
- * What an unreadable document resolves to.
229
- *
230
- * Only the capability gates are refused; everything else keeps its default. The distinction is
231
- * deliberate: refusing history, presentation or browser choice would punish the user for a
232
- * corrupt file without protecting anything, while refusing the gates is the whole point —
233
- * "the operator's intent cannot be read" must not resolve to "the operator permits".
234
- */
235
- const SETTINGS_WHEN_UNREADABLE: BrowserSettings = {
236
- ...DEFAULT_SETTINGS,
237
- credentials: { allowRead: false },
238
- actions: { allowExecute: false, allowDownload: false, allowCredentialWrite: false },
239
- }
240
-
241
- /**
242
- * The channels a settings document may name.
243
- *
244
- * Exported so the log line and the error message can quote the same set the parser accepts: a
245
- * message that lists a value the code rejects (or omits one it takes) is worse than no message.
246
- */
247
- export const BROWSER_CHANNELS = ['chrome', 'edge', 'auto', 'bundled', 'sidebar'] as const
248
-
249
- /**
250
- * Coerce the headless mode, keeping `auto` when the value is not one of the known choices.
251
- *
252
- * Booleans are accepted as a convenience because "headless: true" is what anyone writing this by
253
- * hand would try first, and rejecting it over a type difference would be pedantry: `true` maps to
254
- * `headless`, `false` to `windowed`. Anything else is reported rather than silently defaulted,
255
- * for the same reason as {@link resolveChannel}: a discarded value and an honoured one must not
256
- * look alike.
257
- * @param value - the raw value from the settings document.
258
- * @param warn - where to report a discarded value.
259
- * @returns a valid mode.
260
- */
261
- function resolveHeadless(value: unknown, warn?: (message: string) => void): HeadlessMode {
262
- if (value === undefined) return DEFAULT_SETTINGS.browser.headless
263
- if (value === true) return 'headless'
264
- if (value === false) return 'windowed'
265
- if (typeof value === 'string' && (HEADLESS_MODES as readonly string[]).includes(value)) {
266
- return value as HeadlessMode
267
- }
268
- warn?.(
269
- `dsh-builtin-browser: browser.headless ${JSON.stringify(value)} is not a known mode, so the `
270
- + `default "${DEFAULT_SETTINGS.browser.headless}" was used instead. Expected one of: `
271
- + `${HEADLESS_MODES.join(', ')} (or a boolean).`,
272
- )
273
- return DEFAULT_SETTINGS.browser.headless
274
- }
275
-
276
- /**
277
- * Coerce the browser channel, keeping the default when it is not one of the
278
- * known choices. A hand-edited typo must not silently select a different browser.
279
- *
280
- * Coercing is right; coercing QUIETLY is not. A typo and "the setting did nothing" look exactly
281
- * the same to whoever typed it, which is why every discarded value is reported.
282
- * @param value - the raw value from the settings document.
283
- * @param warn - where to report a discarded value, when the caller has somewhere to put it.
284
- * @returns a valid channel.
285
- */
286
- function resolveChannel(value: unknown, warn?: (message: string) => void): BrowserChannel {
287
- // Absent is the ordinary case, not a mistake: a document that never mentioned the channel gets
288
- // the default without a word.
289
- if (value === undefined) return DEFAULT_SETTINGS.browser.channel
290
- if ((BROWSER_CHANNELS as readonly unknown[]).includes(value)) return value as BrowserChannel
291
- warn?.(
292
- `dsh-builtin-browser: browser.channel ${JSON.stringify(value)} is not a known channel, so the `
293
- + `default "${DEFAULT_SETTINGS.browser.channel}" was used instead. Expected one of: `
294
- + `${BROWSER_CHANNELS.join(', ')}.`,
295
- )
296
- return DEFAULT_SETTINGS.browser.channel
297
- }
298
-
299
- /** Coerce one positive-integer field, keeping the default when invalid. */
300
- function count(value: unknown, fallback: number): number {
301
- if (typeof value !== 'number' || !Number.isFinite(value)) return fallback
302
- const floored = Math.floor(value)
303
- // A fractional value below 1 floors to 0, and 0 is not "very few" in either place these are
304
- // used: as a history entry cap it means `slice(len - 0)`, i.e. keep nothing, so a hand-typed
305
- // `0.5` silently wiped the history file on the next rewrite. Anything that survives the
306
- // floor has to still be a usable limit.
307
- return floored > 0 ? floored : fallback
308
- }
309
-
310
- /** Read one nested section of an unknown document, or an empty object. */
311
- /**
312
- * Read one section of the document, distinguishing ABSENT from UNREADABLE.
313
- *
314
- * Absent (the key is not there at all) is a document written before the section existed, and
315
- * the defaults apply — that is the documented behaviour. Present-but-not-an-object
316
- * (`"actions": false`, `null` from a truncated write, a stray string) is a document this code
317
- * cannot read, and returning `{}` for it made every gate inside look absent, so each one took
318
- * its permissive default. A whole section mistyped is exactly the shape a careless hand edit
319
- * produces, and it opened every capability the section was there to bound.
320
- * @param source - the parsed document.
321
- * @param key - the section name.
322
- * @returns the section, or undefined when it is present but not an object.
323
- */
324
- function section(source: Record<string, unknown>, key: string): Record<string, unknown> | undefined {
325
- const value = source[key]
326
- if (value === undefined) return {}
327
- return typeof value === 'object' && value !== null && !Array.isArray(value)
328
- ? value as Record<string, unknown>
329
- : undefined
330
- }
331
-
332
- /**
333
- * Resolve a raw settings document (already parsed, shape unknown) into the full
334
- * document, field by field. Unknown keys are dropped: the file is not a place to
335
- * smuggle configuration.
336
- * @param raw - the parsed file contents.
337
- * @returns the resolved settings.
338
- */
339
- export function resolveSettings(raw: unknown, warn?: (message: string) => void): BrowserSettings {
340
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return SETTINGS_WHEN_UNREADABLE
341
- const source = raw as Record<string, unknown>
342
- const history = section(source, 'history')
343
- const cookies = section(source, 'cookies')
344
- const ui = section(source, 'ui')
345
- const vision = section(source, 'vision')
346
- const credentials = section(source, 'credentials')
347
- const browser = section(source, 'browser')
348
- const actions = section(source, 'actions')
349
- const remoteView = section(source, 'remoteView')
350
- // Read defensively: this section is hand-editable, and a bad value must fall back to "local only"
351
- // rather than fail the whole document.
352
- const deliverySection = (section(source, 'delivery') ?? {}) as { tool?: unknown; args?: unknown; onFail?: unknown; sites?: unknown }
353
- const strings = (value: unknown, fallback: Record<string, string>): Record<string, string> => {
354
- if (value === null || typeof value !== 'object' || Array.isArray(value)) return { ...fallback }
355
- const out: Record<string, string> = {}
356
- for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
357
- if (typeof entry === 'string') out[key] = entry
358
- }
359
- return Object.keys(out).length === 0 ? { ...fallback } : out
360
- }
361
- // A section that is present but unreadable refuses its gates rather than defaulting them
362
- // open. The rest of a broken section keeps its defaults: refusing history or presentation
363
- // would punish the user for a bad file without protecting anything.
364
- const credentialsUsable = credentials ?? {}
365
- const actionsUsable = actions ?? {}
366
- return {
367
- history: {
368
- enabled: bool(history?.enabled, DEFAULT_SETTINGS.history.enabled),
369
- maxEntries: count(history?.maxEntries, DEFAULT_SETTINGS.history.maxEntries),
370
- maxAgeDays: count(history?.maxAgeDays, DEFAULT_SETTINGS.history.maxAgeDays),
371
- },
372
- cookies: { persist: bool(cookies?.persist, DEFAULT_SETTINGS.cookies.persist) },
373
- ui: {
374
- autoExpandOnce: bool(ui?.autoExpandOnce, DEFAULT_SETTINGS.ui.autoExpandOnce),
375
- closeWithSession: bool(ui?.closeWithSession, DEFAULT_SETTINGS.ui.closeWithSession),
376
- virtualCursor: bool(ui?.virtualCursor, DEFAULT_SETTINGS.ui.virtualCursor),
377
- // Presentation preference, not a capability gate: a mistyped value keeps the documented
378
- // default (off) instead of being read as "on", because quiet mode changes how every
379
- // operation presents itself and should never be the accidental result of a bad edit.
380
- quiet: bool(ui?.quiet, DEFAULT_SETTINGS.ui.quiet),
381
- },
382
- vision: { strategy: vision?.strategy === 'nonVisual' ? 'nonVisual' : DEFAULT_SETTINGS.vision.strategy },
383
- browser: {
384
- channel: resolveChannel(browser?.channel, warn),
385
- headless: resolveHeadless(browser?.headless, warn),
386
- // 不认识的值退回 `plugin`:这一侧不会与用户正在运行的浏览器抢 profile,是"装好即用"的前提。
387
- // 之前这一层不产出该字段,`entry.ts` 的 `systemProfile !== 'plugin'` 恒成立,浏览器总是跑在用户
388
- // profile 上——用户开着 Edge 时 Chromium 以 exit 21 退出,插件报"引擎起不来"。
389
- systemProfile: (browser as { systemProfile?: unknown } | undefined)?.systemProfile === 'user' ? 'user' : 'plugin',
390
- },
391
- credentials: {
392
- // `gate` returns false for anything present-and-not-a-boolean, so an unreadable section
393
- // is refused here for free: the section itself is the "present but wrong" value.
394
- allowRead: credentials === undefined
395
- ? false
396
- : gate(credentialsUsable.allowRead, DEFAULT_SETTINGS.credentials.allowRead),
397
- },
398
- actions: {
399
- allowExecute: actions === undefined
400
- ? false
401
- : gate(actionsUsable.allowExecute, DEFAULT_SETTINGS.actions.allowExecute),
402
- allowDownload: actions === undefined
403
- ? false
404
- : gate(actionsUsable.allowDownload, DEFAULT_SETTINGS.actions.allowDownload),
405
- allowCredentialWrite: actions === undefined
406
- ? false
407
- : gate(actionsUsable.allowCredentialWrite, DEFAULT_SETTINGS.actions.allowCredentialWrite),
408
- },
409
- // Fail-closed, and stated separately from `gate`'s fallback so the intent is visible: an
410
- // unreadable or absent section means nobody watches. Unlike the other switches, whose defaults
411
- // are "on", this one has no safe default other than off.
412
- bridge: {
413
- autoInstall: section(source, 'bridge') === undefined
414
- ? DEFAULT_SETTINGS.bridge.autoInstall
415
- : gate((section(source, 'bridge') as { autoInstall?: unknown }).autoInstall, DEFAULT_SETTINGS.bridge.autoInstall),
416
- },
417
- remoteView: {
418
- enabled: remoteView === undefined
419
- ? false
420
- : gate((remoteView as { enabled?: unknown }).enabled, false),
421
- },
422
- delivery: {
423
- tool: typeof deliverySection.tool === 'string' && /^[A-Za-z0-9_.-]+$/.test(deliverySection.tool)
424
- ? deliverySection.tool
425
- : '',
426
- args: strings(deliverySection.args, DEFAULT_SETTINGS.delivery.args),
427
- onFail: deliverySection.onFail === 'stop' ? 'stop' : 'keep-local',
428
- sites: strings(deliverySection.sites, {}),
429
- },
430
- }
431
- }
432
-
433
- /**
434
- * File-backed settings with an in-memory snapshot. Reads re-stat the file so an
435
- * edit from another process (or the settings panel writing through a second
436
- * code path) is picked up without a restart; writes are atomic enough for a
437
- * single-writer plugin and never throw at the caller.
438
- */
439
- export class SettingsStore {
440
- private cached: BrowserSettings | undefined
441
- /** Last observed mtime, used to invalidate the cache on external edits. */
442
- private cachedMtimeMs = -1
443
-
444
- /**
445
- * @param file - settings file path (defaults beside the browser profile).
446
- */
447
- constructor(private readonly file: string = settingsPath(), private readonly log?: (message: string) => void) {}
448
-
449
- /** Path this store reads and writes. */
450
- path(): string {
451
- return this.file
452
- }
453
-
454
- /**
455
- * Current settings, re-read when the file changed on disk.
456
- * @returns the resolved settings document.
457
- */
458
- get(): BrowserSettings {
459
- let mtimeMs = -1
460
- try {
461
- // stat directly: existsSync costs about thirteen times what the stat does, and the
462
- // stat already throws when the file is missing — which the catch below handles.
463
- mtimeMs = statSync(this.file).mtimeMs
464
- } catch (error) {
465
- // Only an absent document means first-run defaults. Access/storage errors do not
466
- // erase the operator's decisions, even when an earlier read was cached.
467
- if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
468
- this.cached = undefined
469
- this.cachedMtimeMs = -1
470
- return SETTINGS_WHEN_UNREADABLE
471
- }
472
- mtimeMs = -1
473
- }
474
- // Return the cache BEFORE reading. The read used to happen first "just in case", which
475
- // made the cache pointless: every call paid for a synchronous read of the whole file and
476
- // then discarded it. This is on the path of every tool call that consults a setting, so
477
- // it was a stat plus a read per call where a single stat will do.
478
- if (this.cached !== undefined && mtimeMs === this.cachedMtimeMs) return this.cached
479
-
480
- let text: string | undefined
481
- if (mtimeMs !== -1) {
482
- try {
483
- text = readFileSync(this.file, 'utf8')
484
- } catch {
485
- // It was there a moment ago (the stat above) and cannot be read now: permissions, a
486
- // lock, a directory in the way. That is not "no document" — the file is not absent, so
487
- // what it said is unknown, and unknown resolves to the refusing document.
488
- this.cached = SETTINGS_WHEN_UNREADABLE
489
- this.cachedMtimeMs = mtimeMs
490
- return this.cached
491
- }
492
- }
493
- try {
494
- // A leading BOM is what ordinary Windows editors (Notepad, PowerShell's
495
- // `Set-Content -Encoding utf8`) leave behind, and `JSON.parse` rejects it.
496
- // Without this strip, hand-editing the settings file silently discarded every
497
- // value in it: the document looked correct, and the plugin quietly ran on
498
- // defaults — including switches the user had just turned off.
499
- const body = text?.replace(/^\uFEFF/, '')
500
- this.cached = body === undefined ? DEFAULT_SETTINGS : resolveSettings(JSON.parse(body), m => this.log?.(m))
501
- } catch {
502
- // A document that EXISTS but cannot be parsed is not the same as no document at all: the
503
- // first is a corrupted or half-written file whose contents were the operator's decisions,
504
- // the second is a first run. Resolving both to the defaults meant a kill during the write,
505
- // or one stray character, silently reopened the capabilities that had been switched off —
506
- // so this side refuses them instead (see SETTINGS_WHEN_UNREADABLE).
507
- this.cached = SETTINGS_WHEN_UNREADABLE
508
- }
509
- this.cachedMtimeMs = mtimeMs
510
- return this.cached
511
- }
512
-
513
- /**
514
- * Merge a partial patch into the stored document and persist it.
515
- * @param patch - the fields to change (unknown keys are ignored).
516
- * @returns the settings after the merge.
517
- */
518
- update(patch: unknown): BrowserSettings {
519
- const current = this.get()
520
- const merged = resolveSettings(deepMerge(current as unknown as Record<string, unknown>, patch), m => this.log?.(m))
521
- try {
522
- mkdirSync(dirname(this.file), { recursive: true })
523
- writeFileAtomic(this.file, `${JSON.stringify(merged, null, 2)}\n`)
524
- } catch (error) {
525
- // Do NOT publish the new value as cached, and do not pretend the file changed: a
526
- // reader compares the file's mtime against this stamp, so stamping "now" on a failed
527
- // write made the next get() re-read the file and silently revert the user's change.
528
- // Clear the cache before failing: the value on disk is still the old one, so leaving
529
- // the merged document cached would hand the next reader something that does not exist —
530
- // and the stamp would make it look fresh until the mtime comparison rolled it back.
531
- this.cached = undefined
532
- this.cachedMtimeMs = -1
533
- throw new Error(`dsh-builtin-browser: settings could not be saved: ${error instanceof Error ? error.message : String(error)}`)
534
-
535
- }
536
- return merged
537
- }
538
- }
539
-
540
- /**
541
- * Replace a file's contents atomically: write a sibling temporary file, then rename it over
542
- * the target.
543
- *
544
- * `writeFileSync(target, …)` truncates and rewrites in place, so a crash, a full disk or an
545
- * antivirus lock in the middle leaves HALF a JSON document. That used to be silent: the reader
546
- * resolved an unparseable file to the defaults, so a torn write flipped `credentials.allowRead`
547
- * and the action switches back ON, and the next successful update wrote those defaults to disk
548
- * for good. The read side no longer does that (see {@link SETTINGS_WHEN_UNREADABLE}) — but the
549
- * write side still has to stop producing torn files at all, because half a document is not
550
- * something this plugin should ever leave behind.
551
- *
552
- * The rename is the commit point: a reader sees either the old document or the new one,
553
- * never a partial one. It stays in the same directory so the rename is atomic on Windows
554
- * as well as POSIX (`renameSync` maps to MoveFileEx there: same-volume replaces are
555
- * atomic, cross-volume ones are not supported at all).
556
- *
557
- * The temporary is written with a unique suffix rather than a fixed `.tmp`, so two writers
558
- * (the settings panel and a second DSH process) cannot rename each other's half-written
559
- * file into place. Shared with the history store, which had the same hole.
560
- * @param file - the target path.
561
- * @param contents - the complete new document.
562
- */
563
- export function writeFileAtomic(file: string, contents: string): void {
564
- const temporary = `${file}.${process.pid}.${Math.random().toString(36).slice(2, 10)}.tmp`
565
- try {
566
- writeFileSync(temporary, contents)
567
- renameSync(temporary, file)
568
- } catch (error) {
569
- // The rename is the commit point, so a failure before it leaves the target untouched —
570
- // only the temporary has to go, and it must not be left behind as garbage.
571
- try { rmSync(temporary, { force: true }) } catch { /* the temp is already the least of it */ }
572
- throw error
573
- }
574
- }
575
-
576
- /** One-level-deep merge over the settings sections (patch wins). */
577
- function deepMerge(base: Record<string, unknown>, patch: unknown): Record<string, unknown> {
578
- if (typeof patch !== 'object' || patch === null) return base
579
- const result: Record<string, unknown> = { ...base }
580
- for (const [key, value] of Object.entries(patch as Record<string, unknown>)) {
581
- const existing = result[key]
582
- if (typeof value === 'object' && value !== null && typeof existing === 'object' && existing !== null) {
583
- result[key] = { ...existing as Record<string, unknown>, ...value as Record<string, unknown> }
584
- } else {
585
- result[key] = value
586
- }
587
- }
588
- return result
589
- }