dsh-builtin-browser 1.0.1 → 1.0.4

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 (222) hide show
  1. package/CHANGELOG.md +55 -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/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-host-patch/README.md +4 -0
  22. package/dsh-host-patch/apply.mjs +61 -13
  23. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  24. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  25. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  26. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  27. package/dsh-host-patch/tauri-revision1.json +39 -0
  28. package/dsh-host-patch/tauri.json +43 -0
  29. package/dsh-host-patch/v023-alpha2.json +153 -0
  30. package/lib/browser/anti-bot.js +215 -0
  31. package/lib/browser/deep-dom.js +39 -0
  32. package/lib/browser/runtime.js +15 -0
  33. package/lib/browser/takeover-target.js +13 -6
  34. package/lib/browser/types.js +30 -1
  35. package/lib/browser-electron/authenticated-route.js +16 -2
  36. package/lib/browser-electron/automatic-maintenance.js +16 -10
  37. package/lib/browser-electron/bridge-connection.js +3 -8
  38. package/lib/browser-electron/bridge-install.js +2 -1
  39. package/lib/browser-electron/bridge-status.js +55 -26
  40. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  41. package/lib/browser-electron/desktop-identity.js +28 -5
  42. package/lib/browser-electron/desktop-shell.js +64 -0
  43. package/lib/browser-electron/electron-provision.js +105 -18
  44. package/lib/browser-electron/entry.js +129 -44
  45. package/lib/browser-electron/extension-browser.js +4 -4
  46. package/lib/browser-electron/foreground-watch.js +134 -0
  47. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  48. package/lib/browser-electron/guest-route.js +181 -32
  49. package/lib/browser-electron/guest-runtime.js +61 -10
  50. package/lib/browser-electron/guest-storage.js +2 -2
  51. package/lib/browser-electron/history-store.js +1 -5
  52. package/lib/browser-electron/host-main.js +8 -4
  53. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  54. package/lib/browser-electron/maintenance-route.js +2 -1
  55. package/lib/browser-electron/missing-system-browser.js +5 -9
  56. package/lib/browser-electron/preferred-browser.js +7 -3
  57. package/lib/browser-electron/preview-route.js +9 -13
  58. package/lib/browser-electron/process-ownership.js +1 -1
  59. package/lib/browser-electron/profile-command.js +2 -1
  60. package/lib/browser-electron/profile-extension.js +5 -0
  61. package/lib/browser-electron/profile-lease.js +152 -47
  62. package/lib/browser-electron/provider-core.js +527 -0
  63. package/lib/browser-electron/provider-interaction.js +963 -0
  64. package/lib/browser-electron/provider-media.js +518 -0
  65. package/lib/browser-electron/provider-navigation.js +301 -0
  66. package/lib/browser-electron/provider-observation.js +623 -0
  67. package/lib/browser-electron/provider-tabs.js +372 -0
  68. package/lib/browser-electron/provider.js +150 -3301
  69. package/lib/browser-electron/reference-route.js +9 -18
  70. package/lib/browser-electron/remote-host.js +79 -34
  71. package/lib/browser-electron/runtime-status.js +56 -6
  72. package/lib/browser-electron/settings-store.js +3 -6
  73. package/lib/browser-electron/sidebar-only-host.js +1 -1
  74. package/lib/browser-electron/system-browser.js +539 -172
  75. package/lib/browser-electron/tauri-host.js +208 -0
  76. package/lib/browser-electron/virtual-cursor.js +23 -13
  77. package/lib/browser-reference/service.js +22 -4
  78. package/lib/browser-reference/web-sources.js +1 -1
  79. package/lib/client.js +43409 -0
  80. package/lib/compat/host-features.js +75 -0
  81. package/lib/reference-source.js +1 -1
  82. package/lib/reference-text.js +23 -1
  83. package/lib/takeover-protocol.js +1 -1
  84. package/lib/tool-browser/block-recovery.js +69 -0
  85. package/lib/tool-browser/code-tool.js +170 -19
  86. package/lib/tool-browser/code-worker.js +115 -20
  87. package/lib/tool-browser/errors.js +34 -0
  88. package/lib/tool-browser/index.js +66 -3593
  89. package/lib/tool-browser/page-probe.js +227 -28
  90. package/lib/tool-browser/panel-page.js +2 -1
  91. package/lib/tool-browser/probe-client.js +157 -0
  92. package/lib/tool-browser/screenshot-annotations.js +108 -0
  93. package/lib/tool-browser/state.js +337 -0
  94. package/lib/tool-browser/takeover.js +1 -1
  95. package/lib/tool-browser/tools-debug.js +862 -0
  96. package/lib/tool-browser/tools-interaction.js +993 -0
  97. package/lib/tool-browser/tools-navigation.js +807 -0
  98. package/lib/tool-browser/tools-observation.js +461 -0
  99. package/lib/tool-browser/tools-reference.js +293 -0
  100. package/lib/web-guest.js +1 -0
  101. package/package.json +16 -36
  102. package/scripts/build-client.mjs +305 -0
  103. package/scripts/build.mjs +15 -12
  104. package/scripts/fix-exports.mjs +6 -16
  105. package/scripts/install-electron.mjs +55 -5
  106. package/scripts/pack.mjs +99 -0
  107. package/scripts/publish-manifest.mjs +56 -0
  108. package/scripts/verify-exports.mjs +26 -15
  109. package/skills/dsh-builtin-browser/SKILL.md +27 -2
  110. package/skills/dsh-builtin-browser/references/batch.md +15 -0
  111. package/src/browser/anti-bot.ts +251 -0
  112. package/src/browser/deep-dom.ts +40 -0
  113. package/src/browser/runtime.ts +18 -0
  114. package/src/browser/takeover-target.ts +16 -7
  115. package/src/browser/types.ts +56 -3
  116. package/src/browser-electron/authenticated-route.ts +29 -4
  117. package/src/browser-electron/automatic-maintenance.ts +23 -13
  118. package/src/browser-electron/bridge-connection.ts +11 -10
  119. package/src/browser-electron/bridge-install.ts +2 -1
  120. package/src/browser-electron/bridge-status.ts +61 -22
  121. package/src/browser-electron/desktop-bridge-host.ts +9 -7
  122. package/src/browser-electron/desktop-identity.ts +38 -5
  123. package/src/browser-electron/desktop-shell.ts +100 -0
  124. package/src/browser-electron/electron-provision.ts +104 -18
  125. package/src/browser-electron/entry.ts +1378 -1299
  126. package/src/browser-electron/extension-browser.ts +11 -4
  127. package/src/browser-electron/foreground-watch.ts +142 -0
  128. package/src/browser-electron/guest-cookie-jar.ts +3 -2
  129. package/src/browser-electron/guest-route.ts +180 -32
  130. package/src/browser-electron/guest-runtime.ts +61 -10
  131. package/src/browser-electron/guest-storage.ts +5 -2
  132. package/src/browser-electron/history-store.ts +3 -6
  133. package/src/browser-electron/host-main.ts +8 -4
  134. package/src/browser-electron/host-patch-maintenance.ts +18 -9
  135. package/src/browser-electron/maintenance-route.ts +2 -1
  136. package/src/browser-electron/missing-system-browser.ts +11 -10
  137. package/src/browser-electron/preferred-browser.ts +13 -3
  138. package/src/browser-electron/preview-route.ts +9 -12
  139. package/src/browser-electron/process-ownership.ts +9 -3
  140. package/src/browser-electron/profile-command.ts +2 -1
  141. package/src/browser-electron/profile-extension.ts +5 -0
  142. package/src/browser-electron/profile-lease.ts +131 -35
  143. package/src/browser-electron/provider-core.ts +1107 -0
  144. package/src/browser-electron/provider-interaction.ts +1034 -0
  145. package/src/browser-electron/provider-media.ts +589 -0
  146. package/src/browser-electron/provider-navigation.ts +323 -0
  147. package/src/browser-electron/provider-observation.ts +664 -0
  148. package/src/browser-electron/provider-tabs.ts +372 -0
  149. package/src/browser-electron/provider.ts +158 -4063
  150. package/src/browser-electron/reference-route.ts +598 -608
  151. package/src/browser-electron/remote-host.ts +118 -42
  152. package/src/browser-electron/runtime-status.ts +80 -13
  153. package/src/browser-electron/settings-store.ts +10 -6
  154. package/src/browser-electron/sidebar-only-host.ts +4 -2
  155. package/src/browser-electron/system-browser.ts +537 -184
  156. package/src/browser-electron/tauri-host.ts +194 -0
  157. package/src/browser-electron/virtual-cursor.ts +24 -14
  158. package/src/browser-reference/service.ts +38 -7
  159. package/src/browser-reference/web-sources.ts +4 -1
  160. package/src/client/apply-guard.ts +22 -0
  161. package/src/client/browser/BrowserController.ts +3 -3
  162. package/src/client/browser/IframeImpl.ts +182 -176
  163. package/src/client/browser/frame-history.ts +125 -0
  164. package/src/client/browser/frame-state.ts +27 -0
  165. package/src/client/browser/web-reference-source.ts +5 -1
  166. package/src/client/definition.tsx +36 -30
  167. package/src/client/electron/ElectronWebViewImpl.ts +20 -13
  168. package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
  169. package/src/client/electron/NativeChildPresentation.ts +11 -3
  170. package/src/client/electron/NativeViewPage.ts +19 -5
  171. package/src/client/index.ts +333 -293
  172. package/src/client/locales.ts +9 -6
  173. package/src/client/reference/client/plugin.ts +21 -2
  174. package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
  175. package/src/client/reference/client/production/assembly.ts +4 -28
  176. package/src/client/reference/client/production/availability.ts +0 -2
  177. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  178. package/src/client/reference/client/production/draft-adapter.ts +4 -0
  179. package/src/client/reference/client/production/http-transport.ts +0 -5
  180. package/src/client/reference/client/production/production-submission.ts +50 -290
  181. package/src/client/reference/client/production/protocol.ts +7 -4
  182. package/src/client/reference/client/production/runtime.ts +41 -86
  183. package/src/client/reference/client/production/source-marker.ts +49 -13
  184. package/src/client/reference/client/production/user-text-rule.ts +10 -1
  185. package/src/client/reference/client/reveal.ts +3 -1
  186. package/src/client/reference/client/session-schedule.ts +36 -0
  187. package/src/client/settings/index.ts +8 -0
  188. package/src/client/settings/mount-guard.ts +31 -0
  189. package/src/client/settings/panel.ts +163 -52
  190. package/src/client/startpage/controller.ts +3 -6
  191. package/src/client/view/BrowserBody.tsx +2 -1
  192. package/src/client/view/IframePresentation.ts +37 -16
  193. package/src/client/view/StartPage.tsx +2 -1
  194. package/src/compat/host-features.ts +92 -0
  195. package/src/reference-source.ts +1 -1
  196. package/src/reference-text.ts +23 -1
  197. package/src/takeover-protocol.ts +11 -2
  198. package/src/tool-browser/block-recovery.ts +85 -0
  199. package/src/tool-browser/code-tool.ts +173 -19
  200. package/src/tool-browser/code-worker.ts +101 -15
  201. package/src/tool-browser/errors.ts +40 -0
  202. package/src/tool-browser/index.ts +66 -3534
  203. package/src/tool-browser/page-probe.ts +229 -28
  204. package/src/tool-browser/panel-page.ts +3 -1
  205. package/src/tool-browser/probe-client.ts +183 -0
  206. package/src/tool-browser/screenshot-annotations.ts +131 -0
  207. package/src/tool-browser/state.ts +375 -0
  208. package/src/tool-browser/takeover.ts +3 -2
  209. package/src/tool-browser/tools-debug.ts +806 -0
  210. package/src/tool-browser/tools-interaction.ts +956 -0
  211. package/src/tool-browser/tools-navigation.ts +786 -0
  212. package/src/tool-browser/tools-observation.ts +474 -0
  213. package/src/tool-browser/tools-reference.ts +294 -0
  214. package/src/web-guest.ts +35 -34
  215. package/dist/client.cjs +0 -43167
  216. package/dist/client.d.cts +0 -516
  217. package/dist/client.d.mts +0 -516
  218. package/dist/index.cjs +0 -92
  219. package/dist/index.d.mts +0 -2960
  220. package/dist/index.mjs +0 -24
  221. package/lib/browser-reference/submission-receipts.js +0 -139
  222. package/src/browser-reference/submission-receipts.ts +0 -122
@@ -1,4 +1,4 @@
1
- import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs'
1
+ import { BROWSER_PROFILE_DIR, LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs'
2
2
  /**
3
3
  * Legacy standalone Electron browser host (not a supported package export): an
4
4
  * {@link ElectronBrowserViewHost} implementation that spawns the plugin's own
@@ -27,14 +27,14 @@ import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs'
27
27
  */
28
28
 
29
29
  import { execFileSync, spawn } from 'node:child_process'
30
- import { appendFileSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
30
+ import { appendFileSync, mkdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
31
31
  import { randomBytes, randomUUID } from 'node:crypto'
32
32
  import { createRequire } from 'node:module'
33
33
  import { existsSync, readFileSync, readdirSync, readlinkSync } from 'node:fs'
34
34
  import { basename, dirname, isAbsolute, join } from 'node:path'
35
35
  import { createServer, type Server, type Socket } from 'node:net'
36
36
  import { withTimeoutShared } from './timing.ts'
37
- import { browserHostLogPath } from './paths.ts'
37
+ import { browserHostLogPath, dshHome } from './paths.ts'
38
38
  import { fileURLToPath } from 'node:url'
39
39
  import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions, ScreenshotOptions } from './provider.ts'
40
40
  import type { ExportedCookie } from '../browser/types.ts'
@@ -53,23 +53,25 @@ const MAX_RPC_BUFFER_BYTES = 512 * 1024 * 1024
53
53
  * Locate a SPAWNABLE Electron binary — one that runs a script given as an
54
54
  * argument, i.e. a BARE electron, never a packaged app executable:
55
55
  * 0. ELECTRON_PATH (explicit override — user intent beats auto-discovery),
56
- * 1. the plugin's own electron package (a real dependency since 0.1.18),
56
+ * 1. the plugin-managed runtime directory (`$DSH_HOME/dsh-builtin-browser-host/electron-runtime`),
57
+ * isolated from DSH profile node_modules so upgrades never wipe it,
58
+ * 2. the plugin's own electron package (or a prior install's node_modules / pnpm store),
57
59
  * found by a pure filesystem walk — never require(), whose semantics
58
60
  * differ inside an Electron main process (there it is the built-in API
59
61
  * module, not the npm package) and which would trigger electron 44+'s
60
62
  * lazy binary download;
61
- * 2. every DSH install anchor (electron installed separately, e.g.
63
+ * 3. every DSH install anchor (electron installed separately, e.g.
62
64
  * `dsh plugin add electron` into the profile or a global prefix),
63
65
  * choosing the NEWEST version found. Older Electron releases (e.g.
64
66
  * 33.x) have a compositor defect that intermittently breaks page
65
67
  * capture, so prefer the newest binary available in the environment,
66
- * 3. the current process, when it IS a bare Electron (dev hosts, e.g.
68
+ * 4. the current process, when it IS a bare Electron (dev hosts, e.g.
67
69
  * `electron .`): reuse the host binary. Packaged app executables
68
70
  * (resources/app.asar beside the exe) are never reused — they ignore
69
71
  * the script argument and launch the app itself, typically exiting
70
72
  * immediately via the single-instance lock, which is exactly the
71
73
  * "browser host exited (code=0)" failure on DSH Desktop;
72
- * 4. last resort: the process ancestry, for hosts that run this plugin in a
74
+ * 5. last resort: the process ancestry, for hosts that run this plugin in a
73
75
  * child Node process of their own bare-Electron main process.
74
76
  * @returns the path to the Electron executable.
75
77
  */
@@ -81,6 +83,8 @@ interface ElectronPathInputs {
81
83
  readonly inElectron: boolean
82
84
  /** process.execPath (candidate for in-process host reuse). */
83
85
  readonly execPath: string
86
+ /** The plugin-managed runtime probe (`$DSH_HOME/dsh-builtin-browser-host/electron-runtime`). */
87
+ readonly managed?: () => string | undefined
84
88
  /** The plugin's own electron package probe (bundled). */
85
89
  readonly bundled: () => string | undefined
86
90
  /** The DSH install-anchor probe. */
@@ -89,11 +93,26 @@ interface ElectronPathInputs {
89
93
  readonly ancestry: () => string | undefined
90
94
  }
91
95
 
96
+ /**
97
+ * Plugin-owned runtime root (`$DSH_HOME/dsh-builtin-browser-host/electron-runtime`).
98
+ * Lives outside DSH profile `node_modules` so plugin upgrades do not delete it
99
+ * as unreferenced residue and pnpm never blocks its postinstall.
100
+ */
101
+ export function managedElectronDir(home: string = dshHome()): string {
102
+ return join(home, BROWSER_PROFILE_DIR, 'electron-runtime')
103
+ }
104
+
105
+ function managedElectronBinary(): string | undefined {
106
+ const pkgRoot = join(managedElectronDir(), 'node_modules', 'electron')
107
+ return electronDistExe(pkgRoot)
108
+ }
109
+
92
110
  function resolveElectronPath(): string {
93
111
  return resolveElectronPathImpl({
94
112
  override: process.env.ELECTRON_PATH,
95
113
  inElectron: typeof process.versions.electron === 'string',
96
114
  execPath: process.execPath,
115
+ managed: managedElectronBinary,
97
116
  bundled: bundledElectronBinary,
98
117
  anchored: anchoredElectronBinary,
99
118
  ancestry: hostElectronViaProcessTree,
@@ -102,9 +121,9 @@ function resolveElectronPath(): string {
102
121
 
103
122
  /**
104
123
  * Pure selection over the discovery probes, in order:
105
- * 0. override (user intent) → 1. bundled package → 2. anchors (newest) →
106
- * 3. in-process BARE host → 4. process ancestry → throw.
107
- * Packaged app executables are never reused (steps 3/4 skip them).
124
+ * 0. override (user intent) → 1. managed runtime → 2. bundled package → 3. anchors (newest) →
125
+ * 4. in-process BARE host → 5. process ancestry → throw.
126
+ * Packaged app executables are never reused (steps 4/5 skip them).
108
127
  */
109
128
  function resolveElectronPathImpl(inputs: ElectronPathInputs): string {
110
129
  // 0. Explicit override first: a user-set ELECTRON_PATH is a deliberate
@@ -112,20 +131,23 @@ function resolveElectronPathImpl(inputs: ElectronPathInputs): string {
112
131
  // package) — auto-discovery is a fallback, not an override.
113
132
  const override = inputs.override
114
133
  if (typeof override === 'string' && override.length > 0 && existsSync(override)) return override
115
- // 1. The plugin's own electron package (filesystem probe). Never require():
134
+ // 1. Plugin-managed standalone runtime (on-demand download target).
135
+ const managed = inputs.managed?.()
136
+ if (managed !== undefined) return managed
137
+ // 2. The plugin's own electron package (filesystem probe). Never require():
116
138
  // inside an Electron main process require('electron') is the built-in
117
139
  // API module, not the npm package, and electron 44+ downloads its binary
118
140
  // on first require — probing must stay side-effect free (available()
119
141
  // would otherwise block DSH startup on the download).
120
142
  const bundled = inputs.bundled()
121
143
  if (bundled !== undefined) return bundled
122
- // 2. DSH install anchors, newest wins. (The plugin's own tree — plain and
123
- // pnpm store layouts — was already scanned in step 1; the anchors cover
144
+ // 3. DSH install anchors, newest wins. (The plugin's own tree — plain and
145
+ // pnpm store layouts — was already scanned in step 2; the anchors cover
124
146
  // electron installed separately, e.g. `dsh plugin add electron` into the
125
147
  // profile or a global prefix.)
126
148
  const anchored = inputs.anchored()
127
149
  if (anchored !== undefined) return anchored
128
- // 3. The current process IS a bare Electron (dev hosts, e.g. `electron .`):
150
+ // 4. The current process IS a bare Electron (dev hosts, e.g. `electron .`):
129
151
  // reuse the host binary — it cannot be missing because we are running on
130
152
  // it. A PACKAGED app executable (resources/app.asar beside it, e.g. DSH
131
153
  // Desktop.exe) is NOT spawnable as bare electron: it ignores the script
@@ -135,20 +157,16 @@ function resolveElectronPathImpl(inputs: ElectronPathInputs): string {
135
157
  const exe = inputs.execPath
136
158
  if (typeof exe === 'string' && exe.length > 0 && existsSync(exe) && isBareElectron(exe)) return exe
137
159
  }
138
- // 4. Last resort for bare-Electron hosts: walk the process ancestry (the
160
+ // 5. Last resort for bare-Electron hosts: walk the process ancestry (the
139
161
  // plugin may run in a child Node process of an Electron main process).
140
162
  const hostExe = inputs.ancestry()
141
163
  if (hostExe !== undefined) return hostExe
142
164
  throw new Error(
143
165
  'dsh-builtin-browser: cannot locate a spawnable Electron binary. ' +
144
- 'The electron package ships with the plugin and its binary is downloaded on first use, not at install time ' +
145
- '(issue #41: an install-time download made default profiles refuse the plugin). The plugin prepares it ' +
146
- 'automatically when the bundled carrier is selected, so right after an install this can mean the ' +
147
- 'download is still running: Settings → Browser → Readiness shows that state and can retry it. To do it ' +
148
- 'by hand instead, run `npx --no dsh-browser-install-electron` in the profile that installed the ' +
149
- 'plugin, then retry. Alternatively set ELECTRON_PATH to an electron executable. Note: the host\'s own ' +
150
- 'executable cannot be reused when it is a packaged Electron app (e.g. DSH Desktop.exe) — only a real ' +
151
- 'electron binary can be spawned.',
166
+ 'Select "Standalone Electron window" in Settings → Browser and click "Prepare the bundled browser" ' +
167
+ '(or run `npx --no dsh-browser-install-electron`) to download it once into your DSH data directory, ' +
168
+ 'or set ELECTRON_PATH to an existing electron executable. Note: a packaged Electron app executable ' +
169
+ '(e.g. DSH Desktop.exe) cannot be reused — only a bare electron binary can be spawned.',
152
170
  )
153
171
  }
154
172
 
@@ -439,23 +457,40 @@ class ElectronChildClient {
439
457
  */
440
458
  private awaitingHello = true
441
459
  private helloTimer: ReturnType<typeof setTimeout> | undefined
442
-
460
+ private readonly hostMainPath: string
461
+ private readonly port: number
462
+ private readonly token: string
463
+ private readonly onExit?: () => void
464
+ private readonly onUserAction?: (action: BrowserUserAction) => void
465
+ private readonly onViewClosed?: (windowId: string) => void
466
+ private readonly executable?: string
467
+ private readonly userDataDir?: string
443
468
  constructor(
444
- private readonly hostMainPath: string,
445
- private readonly port: number,
446
- private readonly token: string,
447
- private readonly onExit?: () => void,
448
- private readonly onUserAction?: (action: BrowserUserAction) => void,
469
+ hostMainPath: string,
470
+ port: number,
471
+ token: string,
472
+ onExit?: () => void,
473
+ onUserAction?: (action: BrowserUserAction) => void,
449
474
  /**
450
475
  * Called when the human closes a browser window. The session it showed is
451
476
  * over: the provider releases it, while history and login state stay on disk
452
477
  * so the next open is a clean session rather than a resurrected one.
453
478
  */
454
- private readonly onViewClosed?: (windowId: string) => void,
479
+ onViewClosed?: (windowId: string) => void,
455
480
  /** Test seam: the executable to spawn instead of the resolved Electron
456
481
  * binary. Absent -> resolveElectronPath() (production behavior). */
457
- private readonly executable?: string,
482
+ executable?: string,
483
+ /** Optional ephemeral userData dir when cookies.persist is false. */
484
+ userDataDir?: string,
458
485
  ) {
486
+ this.hostMainPath = hostMainPath
487
+ this.port = port
488
+ this.token = token
489
+ this.onExit = onExit
490
+ this.onUserAction = onUserAction
491
+ this.onViewClosed = onViewClosed
492
+ this.executable = executable
493
+ this.userDataDir = userDataDir
459
494
  const electron = this.executable ?? resolveElectronPath()
460
495
  const source = this.executable !== undefined
461
496
  ? 'provided'
@@ -484,6 +519,7 @@ class ElectronChildClient {
484
519
  // expose argv, and preferred over stdin only when stdin cannot deliver):
485
520
  // the child reads env only as a fallback after stdin yields nothing.
486
521
  env.DSH_BROWSER_RPC_TOKEN = token
522
+ if (this.userDataDir !== undefined) env.DSH_BROWSER_USER_DATA_DIR = this.userDataDir
487
523
  this.child = spawn(electron, [hostMainPath, '--rpc-port', String(port)], {
488
524
  stdio: ['pipe', 'pipe', 'pipe'],
489
525
  windowsHide: false,
@@ -767,7 +803,12 @@ class ElectronChildClient {
767
803
 
768
804
  /** One view in the child: its id, used for every command. */
769
805
  class RemoteView implements ElectronViewHandle {
770
- constructor(readonly id: string, private readonly client: ElectronChildClient) {}
806
+ readonly id: string
807
+ private readonly client: ElectronChildClient
808
+ constructor(id: string, client: ElectronChildClient) {
809
+ this.id = id
810
+ this.client = client
811
+ }
771
812
 
772
813
  sendCommand(method: string, params?: Record<string, unknown>): Promise<Record<string, unknown>> {
773
814
  return this.client.call<Record<string, unknown>>('command', {
@@ -873,16 +914,26 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
873
914
  * next open starts clean instead of resuming a window nobody can see.
874
915
  */
875
916
  private viewClosedHandler: ((windowId: string) => void) | undefined
876
-
917
+ private readonly hostMainPath: string
918
+ private readonly spawnExecutable?: string
919
+ private readonly probe: () => void
920
+ private readonly ephemeralUserDataDir?: string
877
921
  constructor(
878
- private readonly hostMainPath: string,
922
+ hostMainPath: string,
879
923
  /** Test seam: the executable to spawn instead of the resolved Electron
880
924
  * binary. Absent -> resolveElectronPath() (production behavior). */
881
- private readonly spawnExecutable?: string,
925
+ spawnExecutable?: string,
882
926
  /** Test seam: the binary probe behind `available()`. Absent ->
883
927
  * resolveElectronPath(). */
884
- private readonly probe: () => void = resolveElectronPath,
885
- ) {}
928
+ probe: () => void = resolveElectronPath,
929
+ /** Optional ephemeral userData directory when cookies.persist is false; removed on dispose(). */
930
+ ephemeralUserDataDir?: string,
931
+ ) {
932
+ this.hostMainPath = hostMainPath
933
+ this.spawnExecutable = spawnExecutable
934
+ this.probe = probe
935
+ this.ephemeralUserDataDir = ephemeralUserDataDir
936
+ }
886
937
 
887
938
  /**
888
939
  * Cheap usability probe: can we find an Electron binary to spawn? The scan
@@ -914,6 +965,18 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
914
965
  return this.electronAvailable
915
966
  }
916
967
 
968
+ /**
969
+ * Retire a negative binary-probe cache immediately after on-demand provisioning
970
+ * finishes so the very next call sees the new binary without waiting out the
971
+ * cooldown or restarting DSH.
972
+ */
973
+ refreshAvailability(): void {
974
+ if (this.electronAvailable === false) {
975
+ this.electronAvailable = undefined
976
+ this.nextProbeAt = 0
977
+ }
978
+ }
979
+
917
980
  /**
918
981
  * Retire the cached "an Electron binary is here" answer.
919
982
  *
@@ -1111,6 +1174,7 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
1111
1174
  action => this.userActionHandler?.(action),
1112
1175
  windowId => this.viewClosedHandler?.(windowId),
1113
1176
  this.spawnExecutable,
1177
+ this.ephemeralUserDataDir,
1114
1178
  )
1115
1179
  if (this.pendingSocket !== undefined) {
1116
1180
  this.client.attach(this.pendingSocket)
@@ -1225,7 +1289,8 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
1225
1289
  * - showing a view that does not exist yet is a no-op in the child, so the
1226
1290
  * view must be materialized first (a fresh tab's createView races the
1227
1291
  * provider's showActive);
1228
- * - a view whose renderer was replaced by a navigation is \"already\n * visible\" and therefore skipped by the child's flicker-avoidance fast
1292
+ * - a view whose renderer was replaced by a navigation is "already
1293
+ * visible" and therefore skipped by the child's flicker-avoidance fast
1229
1294
  * path, leaving the new renderer without a surface.
1230
1295
  *
1231
1296
  * The barrier ping is meaningful because the child handles messages strictly
@@ -1305,17 +1370,27 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
1305
1370
  this.pendingSocket = undefined
1306
1371
  this.readyPromise = undefined
1307
1372
  this.views.clear()
1373
+ if (this.ephemeralUserDataDir !== undefined) {
1374
+ const dir = this.ephemeralUserDataDir
1375
+ setTimeout(() => {
1376
+ try { rmSync(dir, { recursive: true, force: true }) } catch { /* best-effort cleanup */ }
1377
+ }, 600).unref?.()
1378
+ }
1308
1379
  }
1309
1380
  }
1310
1381
 
1311
1382
  /** A view handle that waits for child readiness before issuing commands. */
1312
1383
  class DeferredRemoteView implements ElectronViewHandle {
1313
1384
  private materialized: Promise<RemoteView> | undefined
1314
-
1385
+ readonly id: string
1386
+ private readonly materialize: () => Promise<RemoteView>
1315
1387
  constructor(
1316
- readonly id: string,
1317
- private readonly materialize: () => Promise<RemoteView>,
1318
- ) {}
1388
+ id: string,
1389
+ materialize: () => Promise<RemoteView>,
1390
+ ) {
1391
+ this.id = id
1392
+ this.materialize = materialize
1393
+ }
1319
1394
 
1320
1395
  /**
1321
1396
  * Materialize once and cache: every operation on the same handle must
@@ -1457,6 +1532,7 @@ export const internals = {
1457
1532
  electronDistExe,
1458
1533
  electronExeBeside,
1459
1534
  isBareElectron,
1535
+ managedElectronBinary,
1460
1536
  resolveElectronPath,
1461
1537
  resolveElectronPathImpl,
1462
1538
  }
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * WHY THIS EXISTS
5
5
  * Installing this plugin made the browser work with no setup, and that property got silently
6
- * weaker as the carriers were added: the bundled carrier downloads a ~100 MB Electron runtime on
7
- * first need (issue #41 — the download had to leave `postinstall`), so on a fresh install the first
8
- * browser call can arrive while that download is still running, and the only trace anywhere in the
6
+ * weaker as the carriers were added: the standalone Electron runtime downloads on first need
7
+ * (issue #41 — the download had to leave `postinstall`), so on a fresh install the first browser
8
+ * call can arrive before or while that download is running, and the only trace anywhere in the
9
9
  * product was a log line the settings panel cannot read. A user who saw "cannot locate a spawnable
10
- * Electron binary" had no way to learn that the plugin was already fetching one, and no button to
10
+ * Electron binary" had no way to learn that they could prepare it from the panel, and no button to
11
11
  * retry it once it failed.
12
12
  *
13
13
  * So the readiness of each part is computed ONCE here, in a pure function over injectable readers:
@@ -15,18 +15,31 @@
15
15
  * or the file system.
16
16
  *
17
17
  * Everything here is a cheap environment check. The launch path's own binary probes resolve the
18
- * bundled runtime and installed system browsers; bridge readers inspect the installation and its
19
- * published endpoint. Available files establish availability, while browser calls establish whether
20
- * a particular page can be driven. Nothing spawns anything.
18
+ * bundled/managed runtime and installed system browsers; bridge readers inspect the installation
19
+ * and its published endpoint. Available files establish availability, while browser calls establish
20
+ * whether a particular page can be driven. Nothing spawns anything.
21
21
  * @module dsh-browser/browser-electron/runtime-status
22
22
  */
23
23
  import type { BridgeStatus } from './bridge-status.ts'
24
+ import type { DesktopShellReport } from './desktop-shell.ts'
24
25
  import type { BridgeEndpointState } from './bridge-endpoint.ts'
25
26
  import type { ProvisionSnapshot } from './electron-provision.ts'
26
27
  import type { ExtensionConnectionStatus } from '../../native-host/client.mjs'
27
28
  import type { extensionInstallHelp } from './extension-browser.ts'
29
+ import { createRequire } from 'node:module'
28
30
  import { detectBrowser, type BrowserChannel, type DetectedBrowser, type SystemBrowserLaunchDiagnostic } from './system-browser.ts'
29
31
 
32
+ /** This plugin's own resolver, used when a caller does not inject one. */
33
+ const pluginRequire = createRequire(import.meta.url)
34
+
35
+ /** The host peers this plugin imports; read from the manifest so the list cannot drift. */
36
+ const HOST_PEERS: readonly string[] = (() => {
37
+ try {
38
+ const manifest = pluginRequire('../../package.json') as { peerDependencies?: Record<string, string> }
39
+ return Object.freeze(Object.keys(manifest.peerDependencies ?? {}))
40
+ } catch { return Object.freeze([] as string[]) }
41
+ })()
42
+
30
43
  /** The part of the carrier the channel names, in the terms the panel has to explain. */
31
44
  export type CarrierKind = 'sidebar' | 'bundled' | 'system' | 'extension' | 'cdp' | 'auto'
32
45
 
@@ -99,8 +112,27 @@ export interface RuntimeStatusReport {
99
112
  readonly executable?: string
100
113
  readonly electron: ElectronReadiness
101
114
  readonly bridge: BridgeReadiness
115
+ /** The desktop shell found on this machine; only a patchable one gets bridge install / repair. */
116
+ readonly shell?: DesktopShellReport
102
117
  /** Whether "Prepare the bundled browser" is worth offering (it is not while one is running). */
103
118
  readonly canProvision: boolean
119
+ /**
120
+ * Whether each host peer (`@deepseek-ai/*`) resolves from this plugin (issue #59). A Desktop app
121
+ * that ships the plugin without its peers makes the plugin's own imports fail at the first use,
122
+ * and the four entries simply stay inactive; this turns that into a named list the diagnostics
123
+ * block can show and a reporter can paste.
124
+ */
125
+ readonly peers?: readonly PeerResolution[]
126
+ /** Why the carrier was adopted, newest last (issue #106). */
127
+ readonly carrierHistory?: readonly string[]
128
+ }
129
+
130
+ /** One host peer's resolution result. */
131
+ export interface PeerResolution {
132
+ readonly name: string
133
+ readonly resolved: boolean
134
+ /** The resolver's own words when it failed. */
135
+ readonly error?: string
104
136
  }
105
137
 
106
138
  /** Everything the report reads, so a test can answer without any of the real machinery. */
@@ -118,6 +150,8 @@ export interface RuntimeStatusDeps {
118
150
  /** The desktop install's bridge state, or undefined when there is no desktop install. */
119
151
  readonly bridge: () => BridgeStatus | undefined
120
152
  readonly bridgeError?: () => string | undefined
153
+ /** The desktop shell classification; omitted by hosts that only report the bridge. */
154
+ readonly shell?: () => DesktopShellReport
121
155
  /** The endpoint the shell publishes while it runs; undefined when nothing published one. */
122
156
  readonly endpoint: () => BridgeEndpointState | undefined
123
157
  /** The launch path's filesystem-only browser discovery; defaults to the production reader. */
@@ -125,19 +159,26 @@ export interface RuntimeStatusDeps {
125
159
  /** The provider's current carrier, including a fallback selected after sidebar loss. */
126
160
  readonly selectedCarrier?: () => Exclude<CarrierKind, 'auto'> | undefined
127
161
  readonly systemConnection?: () => { connected: boolean; detail: string; launch?: SystemBrowserLaunchDiagnostic } | undefined
162
+ /** Resolve one host peer; defaults to this plugin's own `require.resolve` (issue #59). */
163
+ readonly resolvePeer?: (name: string) => string
164
+ /** The last carrier decisions, newest last (issue #106). */
165
+ readonly carrierHistory?: () => readonly string[]
128
166
  }
129
167
 
130
168
  /** Which carrier a channel names. */
131
169
  function carrierOf(channel: BrowserChannel): CarrierKind {
132
- return channel === 'chrome' || channel === 'edge' ? 'system' : 'sidebar'
170
+ if (channel === 'chrome' || channel === 'edge') return 'system'
171
+ if (channel === 'electron') return 'bundled'
172
+ return 'sidebar'
133
173
  }
134
174
 
135
175
  /**
136
176
  * Assemble the report.
137
177
  *
138
178
  * The `readiness` field is per carrier on purpose: "the browser is ready" is not a property of this
139
- * plugin, it is a property of the carrier the user chose. A bundled carrier with a finished download
140
- * is ready; the sidebar carrier with no bridge is not, however healthy the bundled runtime is.
179
+ * plugin, it is a property of the carrier the user chose. A standalone Electron carrier with a
180
+ * finished download is ready; the sidebar carrier with no bridge is not, however healthy the
181
+ * Electron runtime is.
141
182
  * @param deps - the readers; every one of them is a cheap, side-effect-free read.
142
183
  * @returns the report the panel renders.
143
184
  */
@@ -192,7 +233,10 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
192
233
 
193
234
  // The sidebar needs BOTH halves: our patch inside the shell it will be driven through, and that
194
235
  // shell actually running. Either one alone is the false green this report exists to prevent.
195
- const sidebarReady = bridge.state === 'installed' && bridge.running
236
+ // On DSH Tauri the patch is the host patch, which starts the same bridge inside electron-rs.
237
+ const shell = deps.shell?.()
238
+ const sidebarReady = bridge.running && (bridge.state === 'installed'
239
+ || (shell?.kind === 'tauri' && shell.running === true && shell.hostPatch?.status === 'applied'))
196
240
 
197
241
  const selected = preferExtension ? deps.selectedCarrier?.() ?? (extension?.connected ? 'extension' : 'cdp') : undefined
198
242
  const checkSystemBrowser = carrier === 'system' || selected === 'cdp'
@@ -213,6 +257,9 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
213
257
  if (carrier === 'sidebar') {
214
258
  resolvedCarrier = 'sidebar'
215
259
  readiness = sidebarReady ? 'ready' : 'blocked'
260
+ } else if (carrier === 'bundled') {
261
+ resolvedCarrier = 'bundled'
262
+ readiness = runnable ? 'ready' : 'blocked'
216
263
  } else if (selected === 'cdp') {
217
264
  resolvedCarrier = 'cdp'
218
265
  readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked'
@@ -226,7 +273,7 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
226
273
 
227
274
  return {
228
275
  ...deps.nativeHostRegistration ? { nativeHostRegistration: deps.nativeHostRegistration() } : {},
229
- controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' ? 'plugin' : 'sidebar',
276
+ controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' || resolvedCarrier === 'bundled' ? 'plugin' : 'sidebar',
230
277
  ...(preferExtension && resolvedCarrier === 'cdp' ? { fallbackReason: deps.fallbackReason?.() ?? (extension?.state === 'disabled' ? 'disabled' : 'not-connected') } : {}),
231
278
  ...extension === undefined ? {} : { extension },
232
279
  channel,
@@ -237,6 +284,26 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
237
284
  ...resolvedCarrier === 'system' && detected !== undefined ? { executable: detected.path } : {},
238
285
  electron,
239
286
  bridge,
240
- canProvision: false,
287
+ ...shell === undefined ? {} : { shell },
288
+ canProvision: resolvedCarrier === 'bundled' && !runnable && snapshot.state !== 'preparing',
289
+ ...peerReport(deps.resolvePeer),
290
+ ...deps.carrierHistory === undefined ? {} : { carrierHistory: deps.carrierHistory() },
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Resolve every host peer and report the failures (#59). Never throws: an unresolvable peer is a
296
+ * fact to display, not a reason to break the readiness report that needs it.
297
+ * @param resolve - the resolver to use; defaults to this plugin's own.
298
+ * @returns the report field, empty when the manifest declared no peers.
299
+ */
300
+ function peerReport(resolve?: (name: string) => string): { peers: PeerResolution[] } | Record<string, never> {
301
+ if (HOST_PEERS.length === 0) return {}
302
+ const lookup = resolve ?? ((name: string) => pluginRequire.resolve(name))
303
+ return {
304
+ peers: HOST_PEERS.map(name => {
305
+ try { lookup(name); return { name, resolved: true } }
306
+ catch (error) { return { name, resolved: false, error: error instanceof Error ? error.message : String(error) } }
307
+ }),
241
308
  }
242
309
  }
@@ -71,6 +71,9 @@ export interface BrowserSettings {
71
71
  * instead of `capturePage()`, so grabbing an image stops being a reason to show a window;
72
72
  * - navigation and tab switching only change which view is visible INSIDE the window; a
73
73
  * minimized window stays minimized;
74
+ * - Installed Chrome / Edge opens its first window off-screen in the normal state (a minimized
75
+ * window would stop rAF); agent navigation and tab switches never move it; the user selecting
76
+ * its tab, or a takeover, moves it onto the primary display once without activating it;
74
77
  * - synthesized input still needs a display surface (Chromium drops `Input.*` for a view
75
78
  * without one), so that one barrier may restore a minimized window — with
76
79
  * `showInactive()`, which shows it without becoming the key window, and without
@@ -244,7 +247,7 @@ const SETTINGS_WHEN_UNREADABLE: BrowserSettings = {
244
247
  * Exported so the log line and the error message can quote the same set the parser accepts: a
245
248
  * message that lists a value the code rejects (or omits one it takes) is worse than no message.
246
249
  */
247
- export const BROWSER_CHANNELS = ['chrome', 'edge', 'auto', 'bundled', 'sidebar'] as const
250
+ export const BROWSER_CHANNELS = ['chrome', 'edge', 'electron', 'auto', 'bundled', 'sidebar'] as const
248
251
 
249
252
  /**
250
253
  * Coerce the headless mode, keeping `auto` when the value is not one of the known choices.
@@ -440,11 +443,12 @@ export class SettingsStore {
440
443
  private cached: BrowserSettings | undefined
441
444
  /** Last observed mtime, used to invalidate the cache on external edits. */
442
445
  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) {}
446
+ private readonly file: string
447
+ private readonly log?: (message: string) => void
448
+ constructor(file: string = settingsPath(), log?: (message: string) => void) {
449
+ this.file = file
450
+ this.log = log
451
+ }
448
452
 
449
453
  /** Path this store reads and writes. */
450
454
  path(): string {
@@ -42,8 +42,10 @@ export class SidebarOnlyHost implements ElectronBrowserViewHost {
42
42
  private disposed = false
43
43
  private readonly discovery = new AbortController()
44
44
  private lostListener: ((reason: CarrierLossReason) => void) | undefined
45
-
46
- constructor(private readonly loader: (signal: AbortSignal) => Promise<ElectronBrowserViewHost>) {}
45
+ private readonly loader: (signal: AbortSignal) => Promise<ElectronBrowserViewHost>
46
+ constructor(loader: (signal: AbortSignal) => Promise<ElectronBrowserViewHost>) {
47
+ this.loader = loader
48
+ }
47
49
 
48
50
  /** Keep the explicit selection available so discovery failures reach the caller unchanged. */
49
51
  available(): boolean { return !this.disposed }