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
@@ -29,11 +29,18 @@ export function sourceMarker(referenceId: string, index: number, title?: string)
29
29
  const displayTitle = Array.from(cleaned).slice(0, 80).join('').trim()
30
30
  const rawLabel = `${SOURCE_LINK_LABEL} ${index + 1}${displayTitle === '' ? '' : `:${displayTitle}`}`
31
31
  const label = typeof rawLabel.toWellFormed === 'function' ? rawLabel.toWellFormed() : rawLabel
32
- return `<dsh-browser-reference uri="${encodeBrowserRefUri({ referenceId })}" label="${encodeURIComponent(label)}"/>`
32
+ // The label travels readable: the host renders this attribute as the capsule's visible text and
33
+ // does not decode it, so percent-encoding showed `%E5%BC%95…` instead of the source title. The
34
+ // sanitizer above removed every character that could close the attribute (`"`, `<`, `>`, `\`,
35
+ // newlines); spaces are allowed by the reader below. A literal `%` is the one sequence the reader
36
+ // still decodes, so it is escaped here and restored on read.
37
+ return `<dsh-browser-reference uri="${encodeBrowserRefUri({ referenceId })}" label="${label.replaceAll('%', '%25')}"/>`
33
38
  }
34
39
 
35
40
  export function readSourceMarker(text: string, from: number) {
36
- const marker = /<dsh-browser-reference uri="(dsh-browser-ref:[^"\s]+)" label="([^"\s]*)"\/>|\[([^\]\r\n]*)\]\((dsh-browser-ref:[^()\s]+)\)/gu
41
+ // `[^"\s]*` used to be enough while labels were percent-encoded; a readable label contains
42
+ // spaces, so the body allows any non-quote character and percent-decodes only legacy labels.
43
+ const marker = /<dsh-browser-reference uri="(dsh-browser-ref:[^"\s]+)" label="([^"]*)"\/>|\[([^\]\r\n]*)\]\((dsh-browser-ref:[^()\s]+)\)/gu
37
44
  marker.lastIndex = from
38
45
  for (let candidate = marker.exec(text); candidate !== null; candidate = marker.exec(text)) {
39
46
  const uri = (candidate[1] ?? candidate[4])!
@@ -41,7 +48,14 @@ export function readSourceMarker(text: string, from: number) {
41
48
  if (reference === undefined) continue
42
49
  let label = candidate[3] ?? uri
43
50
  if (candidate[2] !== undefined) {
44
- try { label = decodeURIComponent(candidate[2]) } catch { continue }
51
+ const raw = candidate[2]
52
+ // Earlier builds wrote encodeURIComponent(label); decode only that shape so a title that
53
+ // happens to contain a percent sign is not mangled.
54
+ if (/%[0-9A-Fa-f]{2}/u.test(raw)) {
55
+ try { label = decodeURIComponent(raw) } catch { continue }
56
+ } else {
57
+ label = raw
58
+ }
45
59
  }
46
60
  return { start: candidate.index, end: candidate.index + candidate[0].length,
47
61
  uri, label, ...reference }
@@ -49,15 +63,37 @@ export function readSourceMarker(text: string, from: number) {
49
63
  return undefined
50
64
  }
51
65
 
52
- /** Attached markers are editor tokens; submission projects their groups once. */
53
- export function composerText(text: string, attachedIds: ReadonlySet<string>): string {
54
- let output = ''
55
- let from = 0
56
- for (let marker = readSourceMarker(text, from); marker !== undefined; marker = readSourceMarker(text, from)) {
57
- output += text.slice(from, marker.start)
58
- if (!attachedIds.has(marker.referenceId) || marker.partId !== undefined) output += text.slice(marker.start, marker.end)
59
- else output = output.replace(/(^|\n)> $/u, '$1')
60
- from = marker.end
66
+ const COMPOSER_OPEN = '<dsh-browser-quote>'
67
+ const COMPOSER_CLOSE = '</dsh-browser-quote>'
68
+ const QUOTE_PREFIX = /^ {0,3}>[ \t]?/u
69
+
70
+ /** The editor quote for one reference: its projected body framed by tags, then its source marker. */
71
+ export function composerQuote(body: string, marker: string): string {
72
+ const normalized = body.replace(/\r\n?/gu, '\n').replace(/\n+$/u, '')
73
+ return `${COMPOSER_OPEN}\n${normalized}\n${COMPOSER_CLOSE}\n${marker}`
74
+ }
75
+
76
+ /**
77
+ * Find a composer quote in sent text. The host prefixes every quoted line with `> `, so the frame
78
+ * lines, the body lines and the marker line are matched with or without that prefix.
79
+ */
80
+ export function readComposerQuote(text: string, from: number) {
81
+ const open = /(^|\n)( {0,3}>[ \t]?)?<dsh-browser-quote>\n/gu
82
+ open.lastIndex = Math.max(0, from - 1)
83
+ for (let match = open.exec(text); match !== null; match = open.exec(text)) {
84
+ const start = match.index + match[1]!.length
85
+ const bodyStart = open.lastIndex
86
+ open.lastIndex = bodyStart - 1
87
+ if (start < from) continue
88
+ const close = /\n( {0,3}>[ \t]?)?<\/dsh-browser-quote>\n/gu
89
+ close.lastIndex = bodyStart - 1
90
+ const closed = close.exec(text)
91
+ if (closed === null) return undefined
92
+ const marker = readSourceMarker(text, close.lastIndex)
93
+ if (marker === undefined || !/^( {0,3}>[ \t]?)?$/u.test(text.slice(close.lastIndex, marker.start))) continue
94
+ const body = text.slice(bodyStart, closed.index).split('\n').map(line => line.replace(QUOTE_PREFIX, '')).join('\n')
95
+ const markerLine = text.lastIndexOf('\n', marker.start - 1) + 1
96
+ return { start, end: marker.end, markerLine, body, marker }
61
97
  }
62
- return output + text.slice(from)
98
+ return undefined
63
99
  }
@@ -1,6 +1,6 @@
1
1
  /** Browser-source markers are parsed by the host text registry, preserving React-owned nodes. */
2
2
  import type { UserTextRule } from '@deepseek-ai/dsh-client-ui-conversation/client'
3
- import { readSourceMarker, readSubmissionQuote } from './source-marker.ts'
3
+ import { readComposerQuote, readSourceMarker, readSubmissionQuote } from './source-marker.ts'
4
4
 
5
5
  declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
6
6
  interface UserTextDataMap {
@@ -31,6 +31,15 @@ export function createBrowserSourceRule(
31
31
  order: -20,
32
32
  match(text, from) {
33
33
  const marker = readSourceMarker(text, from)
34
+ const composed = readComposerQuote(text, from)
35
+ if (composed !== undefined && (marker === undefined || composed.start <= marker.start)) {
36
+ if (hasDetail !== undefined && !hasDetail(composed.marker.referenceId)) {
37
+ return { id: 'text', start: composed.start, end: composed.markerLine,
38
+ data: { text: text.slice(composed.start, composed.markerLine), display: composed.body } }
39
+ }
40
+ return { id: 'browser-ref', start: composed.start, end: composed.end,
41
+ data: { uri: composed.marker.uri, label: composed.marker.label } }
42
+ }
34
43
  const quote = readSubmissionQuote(text, from)
35
44
  if (quote !== undefined && (marker === undefined || quote.start < marker.start)) {
36
45
  let display = ''
@@ -44,8 +44,10 @@ export interface RevealerOptions {
44
44
  * broken".
45
45
  */
46
46
  export class RevealFailed extends Error {
47
- constructor(readonly status: RevealStatus, message?: string) {
47
+ readonly status: RevealStatus
48
+ constructor(status: RevealStatus, message?: string) {
48
49
  super(message ?? status)
50
+ this.status = status
49
51
  this.name = 'RevealFailed'
50
52
  }
51
53
  }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Collapse the dock's session reports into one switch per tick (issue #127).
3
+ *
4
+ * Two dock components can be alive at once (one per kept-alive conversation), and each one's render
5
+ * reports its own Session. Applying those reports synchronously during render made the runtime notify
6
+ * the other dock, whose render reported back, switching the session again — an unbounded
7
+ * render↔publish cycle that React reports as "Maximum update depth exceeded". Reporting through this
8
+ * scheduler moves the switch out of render and keeps only the last report of a tick.
9
+ */
10
+
11
+ /**
12
+ * Build the scheduler used by the dock.
13
+ * @param apply - the real switch (normally `runtime.setSession`).
14
+ * @param schedule - how a task is deferred; `queueMicrotask` in the page, a collector in tests.
15
+ * @returns a function to report the Session that is currently being rendered.
16
+ */
17
+ export function createSessionScheduler(
18
+ apply: (sessionId: string) => void,
19
+ schedule: (task: () => void) => void,
20
+ ): (sessionId: string) => void {
21
+ let pending: string | undefined
22
+ let applied: string | undefined
23
+ return sessionId => {
24
+ // Coalesce within a tick, and never re-apply the session already in effect: a dock that renders
25
+ // again for the same conversation must not schedule a switch at all.
26
+ if (pending === sessionId || applied === sessionId) return
27
+ pending = sessionId
28
+ schedule(() => {
29
+ const next = pending
30
+ pending = undefined
31
+ if (next === undefined || next === applied) return
32
+ applied = next
33
+ apply(next)
34
+ })
35
+ }
36
+ }
@@ -14,6 +14,7 @@
14
14
  import type { Context } from '@deepseek-ai/cordis'
15
15
  import * as React from 'react'
16
16
  import { loadSettingsPanel } from './panel.ts'
17
+ import { claimSettingsMount, markSettingsMounted } from './mount-guard.ts'
17
18
 
18
19
  /** 旧面板在运行期需要的模块;它只 require('react') 一个。 */
19
20
  function panelRequire(id: string): unknown {
@@ -26,8 +27,15 @@ function panelRequire(id: string): unknown {
26
27
  * @param ctx - 客户端上下文(`slots` 与 `locale` 由面板自己使用)。
27
28
  */
28
29
  export function applySettingsSection(ctx: Context): void {
30
+ // The host keeps the slot registration from the first apply, and HMR replaces this module in
31
+ // place, so a re-apply would register the same `settings.section` id twice — the host then fails
32
+ // the whole client registration and the panel disappears (issue #132). The flag is per page and
33
+ // is set only after a successful mount, so a genuinely failed mount still retries.
34
+ const scope = globalThis as unknown as Record<string, unknown>
35
+ if (!claimSettingsMount(scope)) return
29
36
  try {
30
37
  loadSettingsPanel(panelRequire).apply(ctx as never)
38
+ markSettingsMounted(scope)
31
39
  } catch (error) {
32
40
  console.warn('[dsh-builtin-browser] settings section failed to mount', error)
33
41
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * "Has this page already mounted the settings section?" (issue #132)
3
+ *
4
+ * The host keeps a slot registration for the lifetime of the page, while HMR replaces this module
5
+ * in place. A hot re-apply therefore reaches the same `settings.section` id twice, the host refuses
6
+ * the duplicate, and because that refusal used to happen inside the panel's own registration the
7
+ * whole client registration was lost — the browser entry and the settings page disappeared together.
8
+ *
9
+ * The claim is per page (a global), and it is taken only AFTER a successful mount, so a genuinely
10
+ * failed mount still retries on the next apply.
11
+ */
12
+
13
+ /** The page-global key holding the claim. */
14
+ export const SETTINGS_MOUNTED_KEY = '__dshBuiltinBrowserSettingsMounted'
15
+
16
+ /**
17
+ * Decide whether this apply still needs to mount the settings section.
18
+ * @param scope - the page global object.
19
+ * @returns true when the section has not been mounted on this page yet.
20
+ */
21
+ export function claimSettingsMount(scope: Record<string, unknown>): boolean {
22
+ return scope[SETTINGS_MOUNTED_KEY] !== true
23
+ }
24
+
25
+ /**
26
+ * Record a successful mount so a later apply on the same page is a no-op.
27
+ * @param scope - the page global object.
28
+ */
29
+ export function markSettingsMounted(scope: Record<string, unknown>): void {
30
+ scope[SETTINGS_MOUNTED_KEY] = true
31
+ }