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,112 +0,0 @@
1
- import { SHORTCUTS_ROUTE, SHORTCUT_ADD_ROUTE, SHORTCUT_REMOVE_ROUTE } from '../../assets/browser-policy.mjs'
2
- /**
3
- * HTTP face of the shared start-page shortcut list.
4
- *
5
- * Three exact paths, deliberately minimal: the sidebar keeps editing the section
6
- * through the settings RPC (its own UI), while this face exists so an agent — which
7
- * has no sidebar and no settings form — can list, add and drop shortcuts on the same
8
- * data. Both writers go through `ctx.settings`, so there is exactly one list.
9
- * @module dsh-browser/browser-electron/shortcuts-route
10
- */
11
- import type { IncomingMessage, ServerResponse } from 'node:http'
12
- import type { BrowserHttpHandler } from './authenticated-route.ts'
13
- import { isDirectLoopback } from './authenticated-route.ts'
14
- import { readJsonBody } from './http-body.ts'
15
- import { replyJson } from './json-reply.ts'
16
- import { sameOrigin } from './settings-route.ts'
17
- import { ShortcutError, type createShortcutStore } from './startpage-shortcuts.ts'
18
-
19
- /** Read the shared shortcut list. */
20
- export { SHORTCUTS_ROUTE }
21
- /** Append one shortcut. */
22
- export { SHORTCUT_ADD_ROUTE }
23
- /** Drop one shortcut by id. */
24
- export { SHORTCUT_REMOVE_ROUTE }
25
-
26
- type Store = ReturnType<typeof createShortcutStore>
27
-
28
- /** The handlers, one per registered exact path. */
29
- export interface ShortcutRouteHandlers {
30
- readonly list: BrowserHttpHandler
31
- readonly add: BrowserHttpHandler
32
- readonly remove: BrowserHttpHandler
33
- }
34
-
35
- function requireWrite(request: IncomingMessage, response: ServerResponse): boolean {
36
- if (request.method !== 'POST') { replyJson(response, 405, { ok: false, error: 'method-not-allowed' }); return false }
37
- if (!sameOrigin(request, true)) { replyJson(response, 403, { ok: false, error: 'not-same-origin' }); return false }
38
- if (!isDirectLoopback(request)) { replyJson(response, 403, { ok: false, error: 'local-request-required' }); return false }
39
- return true
40
- }
41
-
42
- /**
43
- * Turn a refusal into a status a caller can branch on.
44
- * @param error - anything a handler threw.
45
- * @param response - the response to write when it is a known refusal.
46
- * @returns true when the error was answered.
47
- */
48
- function refuse(error: unknown, response: ServerResponse): boolean {
49
- if (!(error instanceof ShortcutError)) return false
50
- const status = error.code === 'unavailable' ? 503
51
- : error.code === 'conflict' ? 409
52
- : error.code === 'limit' ? 422
53
- : 400
54
- replyJson(response, status, { ok: false, error: error.code, message: error.message })
55
- return true
56
- }
57
-
58
- /** Build every shortcut handler over one store. */
59
- export function createShortcutRouteHandlers(store: Store): ShortcutRouteHandlers {
60
- const list: BrowserHttpHandler = (request, response) => {
61
- if (request.method !== 'GET') { replyJson(response, 405, { ok: false, error: 'method-not-allowed' }); return }
62
- try {
63
- const reading = store.list()
64
- replyJson(response, 200, { ok: true, shortcuts: reading.shortcuts, revision: reading.revision })
65
- } catch (error) {
66
- if (refuse(error, response)) return
67
- replyJson(response, 500, { ok: false, error: String(error) })
68
- }
69
- }
70
-
71
- const add: BrowserHttpHandler = async (request, response) => {
72
- if (!requireWrite(request, response)) return
73
- let body: Record<string, unknown>
74
- try {
75
- body = await readJsonBody<Record<string, unknown>>(request)
76
- } catch (error) {
77
- replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` })
78
- return
79
- }
80
- try {
81
- const result = await store.add({ title: body.title, url: body.url, iconKey: body.iconKey })
82
- replyJson(response, 200, { ok: true, shortcut: result.shortcut, shortcuts: result.shortcuts })
83
- } catch (error) {
84
- if (refuse(error, response)) return
85
- replyJson(response, 500, { ok: false, error: String(error) })
86
- }
87
- }
88
-
89
- const remove: BrowserHttpHandler = async (request, response) => {
90
- if (!requireWrite(request, response)) return
91
- let body: Record<string, unknown>
92
- try {
93
- body = await readJsonBody<Record<string, unknown>>(request)
94
- } catch (error) {
95
- replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` })
96
- return
97
- }
98
- if (typeof body.id !== 'string' || body.id === '') {
99
- replyJson(response, 400, { ok: false, error: 'id is required' })
100
- return
101
- }
102
- try {
103
- const result = await store.remove(body.id)
104
- replyJson(response, result.removed ? 200 : 404, { ok: result.removed, shortcuts: result.shortcuts })
105
- } catch (error) {
106
- if (refuse(error, response)) return
107
- replyJson(response, 500, { ok: false, error: String(error) })
108
- }
109
- }
110
-
111
- return { list, add, remove }
112
- }
@@ -1,298 +0,0 @@
1
- /** A lazy, reconnectable sidebar carrier that preserves the provider's view handles. */
2
- import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId, type BrowserSessionWireId, type BrowserTabWireId } from '../browser/handles.ts'
3
- import type { CarrierLossReason, CarrierPage } from '../browser/types.ts'
4
- import type {
5
- CommandOptions, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions,
6
- } from './provider.ts'
7
-
8
- interface HostLease {
9
- readonly host: ElectronBrowserViewHost
10
- }
11
-
12
- interface BoundView {
13
- readonly lease: HostLease
14
- readonly handle: ElectronViewHandle
15
- }
16
-
17
- interface SidebarView {
18
- readonly handle: ElectronViewHandle
19
- readonly scope: BrowserSessionWireId
20
- bound?: BoundView
21
- pending?: Promise<BoundView>
22
- /**
23
- * The shell's own page id this view was adopted from.
24
- *
25
- * Kept across a bridge reconnect so rebinding adopts the SAME page again. A
26
- * plain `createView` would open a fresh blank page and the next capture would
27
- * silently read the wrong document.
28
- */
29
- adoptedId?: BrowserTabWireId
30
- }
31
-
32
- /**
33
- * Keep an explicit sidebar selection while its bridge starts or reconnects.
34
- * Discovery is deferred until a command needs the bridge; it never selects another carrier.
35
- */
36
- export class SidebarOnlyHost implements ElectronBrowserViewHost {
37
- readonly referenceOverlayOwner = 'client' as const
38
- private readonly views = new Map<string, SidebarView>()
39
- private readonly retiredSessions = new Set<BrowserSessionWireId>()
40
- private lease: HostLease | undefined
41
- private loading: Promise<HostLease> | undefined
42
- private disposed = false
43
- private readonly discovery = new AbortController()
44
- private lostListener: ((reason: CarrierLossReason) => void) | undefined
45
-
46
- constructor(private readonly loader: (signal: AbortSignal) => Promise<ElectronBrowserViewHost>) {}
47
-
48
- /** Keep the explicit selection available so discovery failures reach the caller unchanged. */
49
- available(): boolean { return !this.disposed }
50
-
51
- /** Return a stable handle without opening a sidebar or discovering a bridge. */
52
- createView(identity: BrowserTabWireId): ElectronViewHandle {
53
- this.assertOpen()
54
- const scope = sessionWireId(readTabHandle(identity))
55
- if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
56
- if (this.views.has(identity)) throw new Error('dsh-builtin-browser: sidebar view is already bound')
57
- const handle: ElectronViewHandle = {
58
- id: identity,
59
- sendCommand: (method, params, options) => this.send(view, method, params, options),
60
- download: async (url, savePath) => {
61
- const bound = await this.bind(view)
62
- this.assertView(view)
63
- this.assertLease(bound.lease)
64
- if (bound.handle.download === undefined) throw new Error('dsh-builtin-browser: update the desktop bridge for sidebar downloads')
65
- await bound.handle.download(url, savePath)
66
- },
67
- }
68
- const view: SidebarView = { handle, scope }
69
- this.views.set(handle.id, view)
70
- return handle
71
- }
72
-
73
- destroyView(handle: ElectronViewHandle): void {
74
- const view = this.views.get(handle.id)
75
- if (view?.handle !== handle) return
76
- this.views.delete(handle.id)
77
- if (view.bound !== undefined) view.bound.lease.host.destroyView(view.bound.handle)
78
- view.bound = undefined
79
- }
80
-
81
- /** Presentation must not turn the provider's initial show into a blank-page navigation. */
82
- showView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void {
83
- const view = this.views.get(handle.id)
84
- const bound = view?.handle === handle ? view.bound : undefined
85
- if (!this.disposed && bound !== undefined && bound.lease === this.lease) {
86
- bound.lease.host.showView?.(bound.handle, label, options)
87
- }
88
- }
89
-
90
- async presentView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void> {
91
- const view = this.views.get(handle.id)
92
- if (view?.handle !== handle) throw new Error('dsh-builtin-browser: sidebar view is destroyed')
93
- const bound = await this.bind(view)
94
- if (bound.lease.host.presentView === undefined) throw new Error('dsh-builtin-browser: sidebar bridge cannot acknowledge selection')
95
- await bound.lease.host.presentView(bound.handle, label, options)
96
- this.assertView(view)
97
- this.assertLease(bound.lease)
98
- }
99
-
100
- async listPages(scope: BrowserSessionWireId, options?: { readonly requireRunning?: boolean }): Promise<readonly CarrierPage[]> {
101
- resolveSessionHandle(scope)
102
- const lease = await this.load()
103
- this.assertLease(lease)
104
- if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
105
- const pages = await lease.host.listPages?.(scope, options) ?? []
106
- for (const page of pages) resolveTabHandle(resolveSessionHandle(scope), page.id)
107
- return pages
108
- }
109
-
110
- /**
111
- * Bind a page the SHELL opened to a handle the provider can drive.
112
- *
113
- * The delegation is the point: discovery happens at the first command, so a page
114
- * adopted before the bridge is up must still bind later. The adopted handle is
115
- * stored as this view's binding, which is exactly what `bind` would have created —
116
- * the difference is only which guest it points at.
117
- * @param id - the sidebar page id reported by {@link listPages}.
118
- * @param owner - the conversation the page belongs to.
119
- * @returns a handle whose commands target that page.
120
- */
121
- async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<ElectronViewHandle> {
122
- resolveTabHandle(resolveSessionHandle(scope), id)
123
- if (this.retiredSessions.has(scope)) throw new Error('dsh-builtin-browser: sidebar session was released')
124
- const lease = await this.load()
125
- this.assertLease(lease)
126
- if (lease.host.adoptPage === undefined) throw new Error('dsh-builtin-browser: this sidebar bridge cannot hand over a page it did not open')
127
- const adopted = await lease.host.adoptPage(id, scope)
128
- this.assertLease(lease)
129
- if (adopted.id !== id) {
130
- lease.host.destroyView(adopted)
131
- throw new Error('dsh-builtin-browser: sidebar returned a different tab handle')
132
- }
133
- const handle: ElectronViewHandle = {
134
- id: adopted.id,
135
- sendCommand: (method, params, options) => this.send(view, method, params, options),
136
- download: async (url, savePath) => {
137
- const bound = await this.bind(view)
138
- this.assertView(view)
139
- this.assertLease(bound.lease)
140
- if (bound.handle.download === undefined) throw new Error('dsh-builtin-browser: update the desktop bridge for sidebar downloads')
141
- await bound.handle.download(url, savePath)
142
- },
143
- }
144
- const view: SidebarView = { handle, scope, bound: { lease, handle: adopted }, adoptedId: id }
145
- this.views.set(handle.id, view)
146
- return handle
147
- }
148
-
149
- async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))): Promise<void> {
150
- resolveTabHandle(resolveSessionHandle(scope), id)
151
- const lease = await this.load()
152
- this.assertLease(lease)
153
- if (lease.host.closePage === undefined) throw new Error('dsh-builtin-browser: this sidebar bridge cannot close pages')
154
- await lease.host.closePage(id, scope)
155
- }
156
-
157
- async retireSession(scope: BrowserSessionWireId): Promise<void> {
158
- resolveSessionHandle(scope)
159
- this.retiredSessions.add(scope)
160
- for (const view of [...this.views.values()]) if (view.scope === scope) this.destroyView(view.handle)
161
- const lease = this.lease ?? await this.loading
162
- if (!this.disposed && lease !== undefined && lease === this.lease) await lease.host.retireSession?.(scope)
163
- }
164
-
165
- /** Retire only this conversation's handles before awaiting an in-flight discovery. */
166
- async releasePage(scope?: BrowserSessionWireId): Promise<void> {
167
- if (scope !== undefined) {
168
- resolveSessionHandle(scope)
169
- this.retiredSessions.add(scope)
170
- }
171
- for (const view of [...this.views.values()]) {
172
- if (scope === undefined || view.scope === scope) this.destroyView(view.handle)
173
- }
174
- const lease = this.lease ?? await this.loading
175
- if (!this.disposed && lease !== undefined && lease === this.lease) await lease.host.releasePage?.(scope)
176
- }
177
-
178
- async collapse(): Promise<void> {
179
- if (!this.disposed) await this.lease?.host.collapse?.()
180
- }
181
-
182
- onLost(listener: (reason: CarrierLossReason) => void): void {
183
- this.lostListener = listener
184
- }
185
-
186
- dispose(): void {
187
- if (this.disposed) return
188
- this.disposed = true
189
- this.discovery.abort()
190
- this.views.clear()
191
- const lease = this.lease
192
- this.lease = undefined
193
- this.lostListener = undefined
194
- lease?.host.dispose?.()
195
- }
196
-
197
- private assertOpen(): void {
198
- if (this.disposed) throw new Error('dsh-builtin-browser: sidebar host is disposed')
199
- }
200
-
201
- private assertView(view: SidebarView): void {
202
- this.assertOpen()
203
- if (this.views.get(view.handle.id) !== view) throw new Error('dsh-builtin-browser: sidebar view is destroyed')
204
- }
205
-
206
- private assertLease(lease: HostLease): void {
207
- this.assertOpen()
208
- if (this.lease !== lease) throw new Error('dsh-builtin-browser: sidebar bridge changed before the operation')
209
- }
210
-
211
- private load(): Promise<HostLease> {
212
- this.assertOpen()
213
- if (this.lease !== undefined) return Promise.resolve(this.lease)
214
- if (this.loading !== undefined) return this.loading
215
- const pending = Promise.resolve().then(() => this.loader(this.discovery.signal)).then(host => {
216
- if (this.disposed) {
217
- host.dispose?.()
218
- this.assertOpen()
219
- }
220
- const lease: HostLease = { host }
221
- this.lease = lease
222
- try {
223
- host.onLost?.(reason => this.lost(lease, reason))
224
- } catch (error) {
225
- if (this.lease === lease) this.lease = undefined
226
- host.dispose?.()
227
- throw error
228
- }
229
- if (this.lease !== lease) throw new Error('dsh-builtin-browser: sidebar bridge was lost during discovery')
230
- return lease
231
- })
232
- this.loading = pending
233
- const clear = (): void => { if (this.loading === pending) this.loading = undefined }
234
- void pending.then(clear, clear)
235
- return pending
236
- }
237
-
238
- private lost(lease: HostLease, reason: CarrierLossReason): void {
239
- if (this.disposed || this.lease !== lease) return
240
- this.lease = undefined
241
- this.loading = undefined
242
- for (const view of this.views.values()) {
243
- view.bound = undefined
244
- view.pending = undefined
245
- }
246
- // A command already in flight keeps its original outcome; the next call rediscovers.
247
- setImmediate(() => {
248
- try { lease.host.dispose?.() } catch { /* The next discovery replaces this failed carrier. */ }
249
- })
250
- try { this.lostListener?.(reason) } catch { /* Transport recovery must survive a listener failure. */ }
251
- }
252
-
253
- private bind(view: SidebarView): Promise<BoundView> {
254
- this.assertView(view)
255
- if (view.bound !== undefined && view.bound.lease === this.lease) return Promise.resolve(view.bound)
256
- if (view.pending !== undefined) return view.pending
257
- const pending = this.load().then(lease => {
258
- this.assertView(view)
259
- if (this.lease !== lease) throw new Error('dsh-builtin-browser: sidebar bridge changed before binding the view')
260
- // An adopted view rebinds to its ORIGINAL page: a bridge reconnect must not
261
- // turn the human's page into a fresh blank one the next capture would read.
262
- const adoptedId = view.adoptedId
263
- if (adoptedId !== undefined) {
264
- if (lease.host.adoptPage === undefined) throw new Error('dsh-builtin-browser: this sidebar bridge cannot hand over a page it did not open')
265
- return lease.host.adoptPage(adoptedId, view.scope).then(handle => {
266
- this.assertView(view)
267
- if (this.lease !== lease || handle.id !== view.handle.id) {
268
- lease.host.destroyView(handle)
269
- throw new Error('dsh-builtin-browser: sidebar bridge changed while binding the view')
270
- }
271
- const bound = { lease, handle }
272
- view.bound = bound
273
- return bound
274
- })
275
- }
276
- const handle = lease.host.createView(view.handle.id as BrowserTabWireId)
277
- if (this.disposed || this.views.get(view.handle.id) !== view || this.lease !== lease) {
278
- lease.host.destroyView(handle)
279
- this.assertView(view)
280
- throw new Error('dsh-builtin-browser: sidebar bridge changed while binding the view')
281
- }
282
- const bound = { lease, handle }
283
- view.bound = bound
284
- return bound
285
- })
286
- view.pending = pending
287
- const clear = (): void => { if (view.pending === pending) view.pending = undefined }
288
- void pending.then(clear, clear)
289
- return pending
290
- }
291
-
292
- private async send(view: SidebarView, method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>> {
293
- const bound = await this.bind(view)
294
- this.assertView(view)
295
- if (this.lease !== bound.lease) throw new Error('dsh-builtin-browser: sidebar bridge changed before the command')
296
- return bound.handle.sendCommand(method, params, options)
297
- }
298
- }
@@ -1,213 +0,0 @@
1
- /**
2
- * Sidebar start-page shortcuts, written through the shared settings section.
3
- *
4
- * WHY THIS LIVES HERE
5
- * The start page belongs to `@deepseek-ai/dsh-client-ui-sidebar-browser`, and its
6
- * preferences are a volatile settings section (`browser-startpage`). A human edits
7
- * them in the sidebar; an agent has no sidebar, so without a seam of its own it can
8
- * never add a shortcut. This module is that seam: it reads and writes the SAME
9
- * section through `ctx.settings`, so both callers see one list — no second store,
10
- * no file of our own, no drift.
11
- *
12
- * The section is validated by its owning entry's schema, so the bounds below exist
13
- * to give a caller a clear error BEFORE the settings layer rejects an opaque one;
14
- * they mirror `startpage-settings.ts` and must stay in step with it.
15
- * @module dsh-browser/browser-electron/startpage-shortcuts
16
- */
17
-
18
- /** Settings entry id of the start page (its Host companion's plugin id). */
19
- export const STARTPAGE_NAMESPACE = 'browser-startpage'
20
-
21
- /** Maximum stored shortcut entries; mirrors the start page schema. */
22
- export const MAX_SHORTCUTS = 48
23
- /** Maximum shortcut display title length. */
24
- export const MAX_TITLE = 80
25
- /** Maximum stored URL length. */
26
- export const MAX_URL = 2048
27
- /** Maximum icon key length. */
28
- export const MAX_ICON_KEY = 32
29
-
30
- /** One stored shortcut. */
31
- export interface ShortcutRecord {
32
- readonly id: string
33
- readonly title: string
34
- readonly url: string
35
- readonly iconKey?: string
36
- }
37
-
38
- /** The outcome of one list/add/remove call. */
39
- export interface ShortcutList {
40
- readonly shortcuts: readonly ShortcutRecord[]
41
- readonly revision: number | undefined
42
- }
43
-
44
- /** A refusal a caller can act on, rather than a stack trace. */
45
- export class ShortcutError extends Error {
46
- readonly code: string
47
-
48
- /** @param code - stable machine-readable reason. @param message - human sentence. */
49
- constructor(code: string, message: string) {
50
- super(message)
51
- this.name = 'ShortcutError'
52
- this.code = code
53
- }
54
- }
55
-
56
- /** The slice of `ctx.settings` this module needs. */
57
- export interface ShortcutSettings {
58
- describe(): readonly { readonly ns: string; readonly revision: number; readonly value: unknown }[]
59
- update(ns: string, patch: object, expectedRevision?: number): Promise<void>
60
- }
61
-
62
- const ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,47}$/u
63
- const URL_PATTERN = /^https?:\/\/\S+$/u
64
-
65
- /** Validate one stored record; a malformed row is dropped rather than rendered. */
66
- export function isShortcutRecord(value: unknown): value is ShortcutRecord {
67
- if (value === null || typeof value !== 'object') return false
68
- const row = value as Record<string, unknown>
69
- return typeof row.id === 'string' && ID_PATTERN.test(row.id)
70
- && typeof row.title === 'string' && row.title.trim() !== '' && row.title.length <= MAX_TITLE
71
- && typeof row.url === 'string' && URL_PATTERN.test(row.url) && row.url.length <= MAX_URL
72
- && (row.iconKey === undefined || (typeof row.iconKey === 'string' && row.iconKey.length <= MAX_ICON_KEY))
73
- }
74
-
75
- /**
76
- * Normalise one caller-supplied shortcut.
77
- * @param draft - untrusted input from a tool call or an HTTP body.
78
- * @returns the record to store.
79
- */
80
- export function normalizeShortcut(draft: { title?: unknown; url?: unknown; iconKey?: unknown; id?: unknown }): ShortcutRecord {
81
- const title = typeof draft.title === 'string' ? draft.title.trim() : ''
82
- const url = typeof draft.url === 'string' ? draft.url.trim() : ''
83
- if (title === '') throw new ShortcutError('title', 'a shortcut needs a title')
84
- if (title.length > MAX_TITLE) throw new ShortcutError('title', `a title may hold at most ${MAX_TITLE} characters`)
85
- if (url === '') throw new ShortcutError('url', 'a shortcut needs an http(s) URL')
86
- if (!URL_PATTERN.test(url)) throw new ShortcutError('url', 'the URL must start with http:// or https:// and contain no spaces')
87
- if (url.length > MAX_URL) throw new ShortcutError('url', `a URL may hold at most ${MAX_URL} characters`)
88
- const iconKey = typeof draft.iconKey === 'string' ? draft.iconKey.trim() : ''
89
- if (iconKey.length > MAX_ICON_KEY) throw new ShortcutError('icon', `an icon key may hold at most ${MAX_ICON_KEY} characters`)
90
- // Milliseconds alone collide when two adds land in the same tick, so a random
91
- // suffix keeps the generated id unique without depending on the clock.
92
- const id = typeof draft.id === 'string' && ID_PATTERN.test(draft.id)
93
- ? draft.id
94
- : `s-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
95
- return { id, title, url, ...iconKey === '' ? {} : { iconKey } }
96
- }
97
-
98
- /**
99
- * Compare addresses by their parsed form, not their literal spelling:
100
- * `https://x.com` and `https://x.com/` (or a differently cased host, or an
101
- * explicit default port) are the same destination. A malformed value falls
102
- * back to its literal form, so the duplicate check can never reject an add.
103
- */
104
- function canonicalUrl(value: string): string {
105
- try { return new URL(value).href } catch { return value }
106
- }
107
-
108
- /**
109
- * Read and write the shared shortcut list.
110
- * @param settings - current settings service, resolved lazily so a late service still works.
111
- */
112
- export function createShortcutStore(settings: () => ShortcutSettings | undefined): {
113
- list: () => ShortcutList
114
- add: (draft: { title?: unknown; url?: unknown; iconKey?: unknown }) => Promise<{ shortcut: ShortcutRecord; shortcuts: readonly ShortcutRecord[] }>
115
- remove: (id: string) => Promise<{ removed: boolean; shortcuts: readonly ShortcutRecord[] }>
116
- } {
117
- const read = (): ShortcutList & { raw: readonly unknown[]; revisionNumber: number } => {
118
- const service = settings()
119
- if (service === undefined) throw new ShortcutError('unavailable', 'the settings service is not available in this host')
120
- const row = service.describe().find(entry => entry.ns === STARTPAGE_NAMESPACE)
121
- if (row === undefined) {
122
- throw new ShortcutError('unavailable', `the "${STARTPAGE_NAMESPACE}" settings entry is not loaded in this profile`)
123
- }
124
- const value = (row.value ?? {}) as { shortcuts?: unknown }
125
- // Keep the RAW array as well as the filtered one. The sidebar deliberately
126
- // keeps rows whose `target` is still being repaired (they fail
127
- // isShortcutRecord but are NOT ours to delete). Writes must be derived from
128
- // `raw` with an id-level edit; `shortcuts` is only for duplicate checks and
129
- // for what a caller sees.
130
- const raw: readonly unknown[] = Array.isArray(value.shortcuts) ? value.shortcuts : []
131
- const shortcuts = raw.filter(isShortcutRecord)
132
- return { raw, shortcuts, revision: row.revision, revisionNumber: row.revision }
133
- }
134
-
135
- /**
136
- * Apply one edit, recomputing it from the CURRENT list on a stale revision.
137
- *
138
- * Retrying with the previously computed array would write a snapshot taken
139
- * before the other writer's change and silently drop it (last writer wins).
140
- * Rebuilding from the fresh list instead re-runs the edit — including its
141
- * limit and duplicate checks — so a concurrent add survives this one.
142
- * @param apply - turns the current list into the next list plus its result.
143
- * @returns the result computed by the attempt that was accepted.
144
- */
145
- interface MutateContext {
146
- /** The raw, UNFILTERED section array — the only safe base for a write. */
147
- readonly raw: readonly unknown[]
148
- /** Filtered records, for duplicate/limit checks and for the returned view. */
149
- readonly shortcuts: readonly ShortcutRecord[]
150
- }
151
- interface MutateEdit<T> {
152
- /** The value to write back, derived from `raw` (never from `shortcuts`). */
153
- readonly next: readonly unknown[]
154
- readonly result: T
155
- }
156
-
157
- const mutate = async <T>(apply: (context: MutateContext) => MutateEdit<T>): Promise<T> => {
158
- let lastError: unknown
159
- for (let attempt = 0; attempt < 3; attempt += 1) {
160
- const service = settings()
161
- if (service === undefined) throw new ShortcutError('unavailable', 'the settings service is not available in this host')
162
- const { raw, shortcuts, revisionNumber } = read()
163
- const { next, result } = apply({ raw, shortcuts })
164
- // `apply` returns the SAME `raw` reference when there is nothing to write
165
- // (a remove for an already-absent id); writing would bump the revision
166
- // for no change. The equality is against raw, not the filtered view.
167
- if (next === raw) return result
168
- try {
169
- await service.update(STARTPAGE_NAMESPACE, { shortcuts: next }, revisionNumber)
170
- return result
171
- } catch (error) {
172
- // Two writers (the sidebar and an agent) can race between read and write.
173
- // Only a revision conflict is retried; anything else is a real failure.
174
- if (!/conflict|revision/iu.test(String(error))) throw error
175
- lastError = error
176
- }
177
- }
178
- throw new ShortcutError('conflict', `the shortcut list kept changing while it was edited: ${String(lastError)}`)
179
- }
180
-
181
- const idOf = (entry: unknown): unknown =>
182
- entry !== null && typeof entry === 'object' ? (entry as Record<string, unknown>).id : undefined
183
-
184
- return {
185
- list: () => {
186
- const { shortcuts, revision } = read()
187
- return { shortcuts, revision }
188
- },
189
- async add(draft) {
190
- const shortcut = normalizeShortcut(draft)
191
- return mutate(({ raw, shortcuts }) => {
192
- if (shortcuts.length >= MAX_SHORTCUTS) {
193
- throw new ShortcutError('limit', `the start page holds at most ${MAX_SHORTCUTS} shortcuts`)
194
- }
195
- if (shortcuts.some(entry => canonicalUrl(entry.url) === canonicalUrl(shortcut.url))) {
196
- throw new ShortcutError('conflict', `a shortcut to ${shortcut.url} already exists`)
197
- }
198
- // id-level minimal edit: push onto a COPY of the raw array, so rows the
199
- // sidebar is still repairing are carried through untouched.
200
- const next = [...raw, shortcut]
201
- return { next, result: { shortcut, shortcuts: next.filter(isShortcutRecord) } }
202
- })
203
- },
204
- async remove(id) {
205
- return mutate<{ removed: boolean; shortcuts: readonly ShortcutRecord[] }>(({ raw, shortcuts }) => {
206
- // Filter a COPY of raw by id; every other row — valid or not — survives.
207
- const next = raw.filter(entry => idOf(entry) !== id)
208
- if (next.length === raw.length) return { next: raw, result: { removed: false, shortcuts } }
209
- return { next, result: { removed: true, shortcuts: next.filter(isShortcutRecord) } }
210
- })
211
- },
212
- }
213
- }