dsh-builtin-browser 0.5.6 → 0.5.7

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 (63) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.en.md +67 -99
  3. package/README.md +67 -100
  4. package/client.js +381 -322
  5. package/desktop-bridge/install.mjs +122 -33
  6. package/desktop-bridge/plugin-browser-bridge.js +9 -4
  7. package/docs/tool-reference.md +20 -1
  8. package/lib/browser/runtime.d.ts +3 -1
  9. package/lib/browser/runtime.js +9 -0
  10. package/lib/browser/types.d.ts +42 -0
  11. package/lib/browser-electron/authenticated-route.d.ts +27 -0
  12. package/lib/browser-electron/authenticated-route.js +39 -0
  13. package/lib/browser-electron/bridge-endpoint.js +7 -0
  14. package/lib/browser-electron/bridge-install.d.ts +48 -0
  15. package/lib/browser-electron/bridge-install.js +98 -0
  16. package/lib/browser-electron/bridge-status.js +21 -2
  17. package/lib/browser-electron/desktop-bridge-host.d.ts +7 -4
  18. package/lib/browser-electron/desktop-bridge-host.js +36 -15
  19. package/lib/browser-electron/electron-provision.d.ts +1 -1
  20. package/lib/browser-electron/electron-provision.js +31 -11
  21. package/lib/browser-electron/entry.js +84 -8
  22. package/lib/browser-electron/host-main.js +48 -27
  23. package/lib/browser-electron/provider.d.ts +9 -2
  24. package/lib/browser-electron/provider.js +76 -6
  25. package/lib/browser-electron/remote-host.js +4 -4
  26. package/lib/browser-electron/runtime-route.d.ts +3 -5
  27. package/lib/browser-electron/runtime-status.js +4 -2
  28. package/lib/browser-electron/settings-route.d.ts +5 -18
  29. package/lib/browser-electron/settings-route.js +4 -14
  30. package/lib/browser-electron/settings-store.d.ts +17 -0
  31. package/lib/browser-electron/settings-store.js +24 -0
  32. package/lib/browser-electron/system-browser.d.ts +5 -2
  33. package/lib/browser-electron/system-browser.js +12 -4
  34. package/lib/tool-browser/index.js +1041 -4
  35. package/lib/tool-browser/page-probe.d.ts +86 -0
  36. package/lib/tool-browser/page-probe.js +460 -0
  37. package/package.json +4 -2
  38. package/scripts/verify-runtime-status.mjs +14 -0
  39. package/skills/dsh-builtin-browser/SKILL.md +64 -0
  40. package/skills/dsh-builtin-browser/references/batch.md +23 -0
  41. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  42. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  43. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  44. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  45. package/src/browser/runtime.ts +11 -0
  46. package/src/browser/types.ts +19 -0
  47. package/src/browser-electron/authenticated-route.ts +56 -0
  48. package/src/browser-electron/bridge-endpoint.ts +7 -0
  49. package/src/browser-electron/bridge-install.ts +122 -0
  50. package/src/browser-electron/bridge-status.ts +22 -2
  51. package/src/browser-electron/desktop-bridge-host.ts +33 -15
  52. package/src/browser-electron/electron-provision.ts +30 -12
  53. package/src/browser-electron/entry.ts +76 -8
  54. package/src/browser-electron/host-main.ts +41 -22
  55. package/src/browser-electron/provider.ts +90 -6
  56. package/src/browser-electron/remote-host.ts +4 -4
  57. package/src/browser-electron/runtime-route.ts +3 -5
  58. package/src/browser-electron/runtime-status.ts +4 -2
  59. package/src/browser-electron/settings-route.ts +9 -32
  60. package/src/browser-electron/settings-store.ts +39 -0
  61. package/src/browser-electron/system-browser.ts +9 -3
  62. package/src/tool-browser/index.ts +991 -7
  63. package/src/tool-browser/page-probe.ts +474 -0
package/client.js CHANGED
@@ -57,66 +57,57 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
57
57
  "watch.noPage": "该任务尚未打开浏览器",
58
58
  "watch.bridgeStale": "桌面端升级后 bridge 已失效,请重跑安装:",
59
59
  "watch.bridgeMissing": "桌面 bridge 未安装,侧栏载体不可用。安装命令:",
60
- title: "浏览器(Browser Use)",
61
- lead: "多数设置立即生效。保留 cookies 与无头模式仅适用于本机 Chrome / Edge,修改后需重新选择载体或重启 DSH。",
60
+ title: "浏览器",
61
+ "settings.advanced": "高级设置",
62
+ "settings.saving": "正在保存…",
63
+ "settings.details": "配置文件",
64
+ "browser.profile": "保留登录状态",
65
+ "browser.headless": "窗口模式",
66
+ "browser.headless.hint": "重启 DSH 后生效",
67
+ "browser.headless.auto": "自动检测显示环境",
68
+ "browser.headless.windowed": "显示窗口",
69
+ "browser.headless.headless": "无头运行",
70
+ "delivery.save": "保存交付设置",
71
+ "delivery.invalid": "检查工具名、参数模板和站点规则。参数必须是字符串值的 JSON 对象,站点规则每行填写一个 host=工具名。",
62
72
  loading: "读取设置…",
63
73
  failed: "读取设置失败:",
64
74
  retry: "重试",
65
75
  saved: "已保存",
66
- path: "设置文件",
67
- "history.title": "浏览历史",
68
76
  "history.enabled": "保留浏览历史",
69
- "history.hint": "记录访问过的页面;关闭浏览器后仍可查询并重新打开,关闭此开关后不再记录新访问。",
70
- "cookies.title": "登录状态",
71
- "cookies.persist": "保留 cookies",
72
- "cookies.hint": "仅控制本机 Chrome / Edge 的独立 profile:关闭后下次启动使用临时 profile;需重新选择载体或重启 DSH。内置 Electron 与桌面侧栏的登录态由各自载体保存。",
73
77
  "ui.title": "展示",
74
78
  "ui.autoExpandOnce": "侧栏自动展开(每轮一次)",
75
- "ui.autoExpandOnce.hint": "Agent 首次操作时自动展开;你手动收起后,本轮不再打扰。",
76
79
  "ui.closeWithSession": "会话结束时关闭浏览器",
77
- "ui.closeWithSession.hint": "关闭会释放浏览器进程;浏览历史与登录状态会保留。",
78
- "ui.virtualCursor": "显示可视化鼠标",
79
- "ui.virtualCursor.hint": "让 Agent 正在操作的位置可见(出现即代表它在接管该标签页)。",
80
+ "ui.virtualCursor": "显示 Agent 光标",
80
81
  "ui.quiet": "安静模式",
81
- "ui.quiet.hint": "Agent 操作时不激活应用、不抢键盘焦点;导航与截图不还原最小化的窗口。真实点击/输入仍需要窗口可见,可能把最小化的窗口恢复,但不会成为前台窗口,也不会盖住你正在用的窗口。",
82
- "vision.title": "视觉策略",
83
- "vision.strategy": "默认策略",
84
- "vision.auto": "Auto(坐标与语义都允许;适合能读图的模型)",
85
- "vision.nonVisual": "纯非视觉(拒绝坐标点击,只用 DOM / 无障碍树定位)",
86
- "vision.hint": "纯非视觉下,坐标点击会被明确拒绝并提示改用语义定位,避免靠猜坐标点错。两种策略下 DOM、无障碍树、文本提取与结构化抓取的能力完全一致 —— 不需要图像输入也能完整操作页面。",
87
- "credentials.title": "凭据",
82
+ "ui.quiet.hint": "保留当前窗口和标签。新启动的 Chrome / Edge 在后台运行。",
83
+ "vision.strategy": "页面定位",
84
+ "vision.auto": "自动",
85
+ "vision.nonVisual": "仅按页面结构",
88
86
  "credentials.allowRead": "允许 Agent 读取 cookies / 导出登录状态",
89
- "browser.title": "浏览器载体",
90
- "browser.channel": "使用哪个浏览器",
91
- "browser.sidebar": "侧栏浏览器(在 DSH 窗口右侧打开,不额外拉窗口)",
92
- "browser.bundled": "内置 Electron(随插件提供,无需安装)",
87
+ "browser.channel": "默认浏览器",
88
+ "browser.sidebar": "DSH 侧栏",
89
+ "browser.bundled": "内置浏览器",
93
90
  "browser.chrome": "本机 Chrome",
94
91
  "browser.edge": "本机 Edge",
95
- "browser.auto": "自动(优先 Chrome,其次 Edge)",
96
- "browser.hint": "选本机浏览器时会以**独立 profile** 启动它:不会打开、占用或修改你日常的窗口、书签与登录状态,关闭也不会关掉你自己的浏览器;代价是它看不到你日常浏览器里已登录的站点,需要时请在那个窗口里登录一次(登录态会留在插件自己的 profile 里)。桌面端默认由官方侧栏承载页面,此选项优先于侧栏。",
97
- "credentials.hint": "关闭后 dsh_browser_auth 的导出会被拒绝,报 BROWSER_AUTH_DISABLED —— 导出读的是整台机器共享的 cookie 罐(按当前页所属站点收敛)。它只管**读**:写入登录状态(restore)归下面「Agent 能做什么」里的写入开关。桌面端请注意:Agent 驱动的是侧栏里那一个页面(人机同页),因此它与该页面共用同一个 partition —— 这也正是它能读到登录态的原因,属于有意接受的沙箱边界变化;关闭本项即拒绝读取。",
98
- "actions.title": "Agent 能做什么",
99
- "actions.lead": "与 dsh_browser_restrict 不同:那一层是模型自己设的软护栏,它随时可以解除;这里的三项由你在设置里决定,模型手里的工具改不了它们。",
92
+ "browser.auto": "自动",
93
+ "actions.title": "Agent 权限",
100
94
  "actions.allowExecute": "允许在页面里执行脚本",
101
- "actions.allowExecute.hint": "dsh_browser_execute 能在当前页面里运行任意 JavaScript —— 它的能力上限就是这个页面能做的事。关闭后该工具一律被拒(BROWSER_EXECUTE_DISABLED),模型手里的工具没有一个能改这项设置。但也别把它当成锁:设置文档由本机 HTTP 端点读写,同源页面可以写它 —— 这不是凭据系统。",
102
95
  "actions.allowDownload": "允许下载文件到磁盘",
103
- "actions.allowDownload.hint": "dsh_browser_download 会把 URL 下载到 downloadDir 内(带登录态;仍需通过目录准入,不覆盖已有文件)。关闭后一律被拒(BROWSER_DOWNLOAD_DISABLED)。截图另存走的是同一套目录准入,不受此项影响。",
104
96
  "actions.allowCredentialWrite": "允许写入登录状态",
105
- "actions.allowCredentialWrite.hint": "dsh_browser_auth 的 restore 会向任意域写入 cookie。关闭后只能导出、不能导入(BROWSER_AUTH_WRITE_DISABLED);读取仍由上面「凭据」那一项控制。",
106
- "remoteView.title": "远程观看",
107
- "remoteView.enabled": "允许从其它设备观看这台机器的浏览器",
108
- "remoteView.enabled.hint": "打开后,本机右下角出现一个只读画面入口:2 fps、JPEG、一帧一请求,不转发点击与键盘。改动**立刻生效**,不需要刷新页面。关闭时入口消失,相关端点也不返回图像。",
97
+ "actions.allowCredentialWrite.hint": "可向任意域写入 cookies。",
98
+ "remoteView.enabled": "允许远程观看",
99
+ "remoteView.enabled.hint": "共享只读画面,可能包含敏感信息。",
109
100
  "readiness.title": "就绪状态",
110
- "readiness.lead": "「装好就能用」的自检:内置浏览器首次使用前要在后台下载一次运行时,桌面侧栏需要装进桌面端的 bridge,本机 Chrome / Edge 需要已经安装。",
111
101
  "readiness.loading": "检测中…",
112
102
  "readiness.failed": "读取就绪状态失败:",
113
- "readiness.channel": "当前载体",
103
+ "readiness.channel": "配置的载体",
104
+ "readiness.details": "诊断",
114
105
  "readiness.electron": "内置浏览器运行时",
115
106
  "readiness.bridge": "桌面侧栏 bridge",
116
107
  "readiness.recheck": "重新检测",
117
108
  "readiness.prepare": "准备内置浏览器",
118
109
  "readiness.preparing": "正在准备…",
119
- "readiness.fix": "修复命令(在终端里跑一次):",
110
+ "readiness.fix": "修复命令",
120
111
  "readiness.carrier.sidebar": "桌面侧栏",
121
112
  "readiness.carrier.bundled": "内置 Electron",
122
113
  "readiness.carrier.system": "本机 Chrome / Edge",
@@ -124,9 +115,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
124
115
  "readiness.state.ready": "可用",
125
116
  "readiness.state.blocked": "尚不可用",
126
117
  "readiness.state.unknown": "需实际启动才能确定",
127
- "readiness.electron.present": "已就绪(本机已有运行时)",
128
- "readiness.electron.ready": "已就绪(刚准备完成)",
129
- "readiness.electron.preparing": "正在下载运行时(首次,约 1–3 分钟)",
118
+ "readiness.electron.present": "已就绪",
119
+ "readiness.electron.ready": "已就绪",
120
+ "readiness.electron.preparing": "正在下载",
130
121
  "readiness.electron.idle": "尚未开始准备",
131
122
  "readiness.electron.skipped": "已跳过(设置了 ELECTRON_SKIP_BINARY_DOWNLOAD)",
132
123
  "readiness.electron.failed": "准备失败",
@@ -136,10 +127,14 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
136
127
  "readiness.bridge.missing": "未安装",
137
128
  "readiness.bridge.stale": "已失效(桌面端升级后需重装)",
138
129
  "readiness.bridge.absent": "本机没有桌面端",
139
- "readiness.hint.sidebar": "侧栏载体把页面放进 DSH 窗口右侧,人机同页;它需要桌面端的 bridge,而且只渲染**当前显示**的那个会话。",
140
- "readiness.hint.bundled": "内置浏览器随插件提供,无需安装;运行时在首次使用前自动下载,期间可以先改用桌面侧栏或本机 Chrome / Edge。",
141
- "readiness.hint.system": "选了本机浏览器:插件用它自己的独立 profile 启动,不需要额外准备。",
142
- "readiness.hint.auto": "自动:内置运行时与桌面侧栏任一可用即可工作。",
130
+ "delivery.title": "交付",
131
+ "delivery.tool": "接手下载的工具(MCP 工具名,留空=只存本地)",
132
+ "delivery.args": "参数模板(JSON)",
133
+ "delivery.args.hint": "占位 {path} {name} {size}。",
134
+ "delivery.onFail": "远程失败时",
135
+ "delivery.onFail.keep": "保留本地文件并报告两边结果",
136
+ "delivery.onFail.stop": "按失败处理",
137
+ "delivery.sites": "按站点覆盖(每行 host=工具名)",
143
138
  }
144
139
 
145
140
  const en = {
@@ -157,66 +152,57 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
157
152
  "watch.noPage": "This task has not opened a browser",
158
153
  "watch.bridgeStale": "A desktop update invalidated the bridge; re-run:",
159
154
  "watch.bridgeMissing": "The desktop bridge is not installed, so the sidebar carrier cannot work:",
160
- title: "Browser (Browser Use)",
161
- lead: "Most settings apply immediately. Cookie persistence and headless mode apply only to installed Chrome / Edge; reselect the carrier or restart DSH after changing them.",
155
+ title: "Browser",
156
+ "settings.advanced": "Advanced settings",
157
+ "settings.saving": "Saving…",
158
+ "settings.details": "Configuration file",
159
+ "browser.profile": "Keep sign-ins",
160
+ "browser.headless": "Window mode",
161
+ "browser.headless.hint": "Requires restarting DSH",
162
+ "browser.headless.auto": "Detect display automatically",
163
+ "browser.headless.windowed": "Show a window",
164
+ "browser.headless.headless": "Run headless",
165
+ "delivery.save": "Save delivery settings",
166
+ "delivery.invalid": "Check tool names, the argument template, and site rules. Use a JSON object with string values and one host=tool rule per line.",
162
167
  loading: "Loading settings…",
163
168
  failed: "Could not load settings:",
164
169
  retry: "Retry",
165
170
  saved: "Saved",
166
- path: "Settings file",
167
- "history.title": "Browsing history",
168
171
  "history.enabled": "Keep browsing history",
169
- "history.hint": "Records visited pages so they can be found and reopened after the browser is closed; off means no new visits are recorded.",
170
- "cookies.title": "Login state",
171
- "cookies.persist": "Keep cookies",
172
- "cookies.hint": "Controls only the separate Chrome / Edge profile: off uses a temporary profile on the next launch. Reselect the carrier or restart DSH. Bundled Electron and the desktop sidebar retain login state through their own carrier.",
173
172
  "ui.title": "Presentation",
174
173
  "ui.autoExpandOnce": "Auto-expand the side panel (once per task)",
175
- "ui.autoExpandOnce.hint": "Expands when the agent first operates; after you collapse it, this task stays quiet.",
176
174
  "ui.closeWithSession": "Close the browser when the session ends",
177
- "ui.closeWithSession.hint": "Closing releases the browser process; history and login state survive.",
178
- "ui.virtualCursor": "Show the synthetic cursor",
179
- "ui.virtualCursor.hint": "Makes the agent's operating position visible (its presence means the agent has taken over that tab).",
175
+ "ui.virtualCursor": "Show agent cursor",
180
176
  "ui.quiet": "Quiet mode",
181
- "ui.quiet.hint": "The agent does not activate the app or steal keyboard focus; navigation and screenshots leave a minimized window minimized. Real clicks and typing still need a visible window, so they may restore it — but never raise it above your work or make it the front window.",
182
- "vision.title": "Vision strategy",
183
- "vision.strategy": "Default strategy",
184
- "vision.auto": "Auto (coordinates and semantics both allowed; for models that read images)",
185
- "vision.nonVisual": "Non-visual only (coordinate clicks refused; locate via DOM / a11y tree)",
186
- "vision.hint": "Under non-visual, a coordinate click is refused outright and the error says to use a semantic target — so nothing is clicked on a guessed position. DOM lookup, the accessibility tree, text extraction and structured scraping behave identically in both strategies: the whole page stays operable without image input.",
187
- "credentials.title": "Credentials",
177
+ "ui.quiet.hint": "Keeps your current window and tab. New Chrome / Edge instances run in the background.",
178
+ "vision.strategy": "Page targeting",
179
+ "vision.auto": "Automatic",
180
+ "vision.nonVisual": "Page structure only",
188
181
  "credentials.allowRead": "Allow the agent to read cookies / export login state",
189
- "browser.title": "Browser",
190
- "browser.channel": "Which browser to use",
191
- "browser.sidebar": "Sidebar browser (opens in the DSH window right pane; no extra window)",
192
- "browser.bundled": "Bundled Electron (ships with the plugin, nothing to install)",
182
+ "browser.channel": "Default browser",
183
+ "browser.sidebar": "DSH sidebar",
184
+ "browser.bundled": "Bundled browser",
193
185
  "browser.chrome": "Installed Chrome",
194
186
  "browser.edge": "Installed Edge",
195
- "browser.auto": "Automatic (Chrome first, then Edge)",
196
- "browser.hint": "Choosing an installed browser launches it with a **separate profile**: your everyday windows, bookmarks and logins are never opened, locked or modified, and closing the plugin never closes your browser. The trade-off is that it does not see sites you are already signed into there — sign in once in that window and the session stays in the plugin's own profile. On the desktop the shell's sidebar normally carries the page; this setting outranks it.",
197
- "credentials.hint": "Off makes dsh_browser_auth refuse the export, reporting BROWSER_AUTH_DISABLED — an export reads the machine-wide shared cookie jar (narrowed to the current page's site). It governs READING only: writing login state (restore) answers to the write switch under \"What the agent may do\" below. On the desktop, note that the agent drives the sidebar's own page (one page for both parties), so it shares that page's partition — which is exactly why it can reach the login state. That is a deliberate sandbox-boundary change; this switch is how you refuse it.",
198
- "actions.title": "What the agent may do",
199
- "actions.lead": "Unlike dsh_browser_restrict, which is the model's own soft guardrail and can be lifted by the model at any time, these three are yours: the model's own tools cannot change them.",
187
+ "browser.auto": "Automatic",
188
+ "actions.title": "Agent permissions",
200
189
  "actions.allowExecute": "Run scripts in the page",
201
- "actions.allowExecute.hint": "dsh_browser_execute runs arbitrary JavaScript in the active tab — its reach is everything that page can do. Off refuses the tool outright (BROWSER_EXECUTE_DISABLED), and no tool the model holds can change this setting. Do not read that as a lock, though: the document is served over a local HTTP endpoint and a same-origin page can write it. This is not a credential system.",
202
190
  "actions.allowDownload": "Download files to disk",
203
- "actions.allowDownload.hint": "dsh_browser_download fetches a URL into downloadDir (with login state; still subject to the directory admission gate, never overwriting an existing file). Off refuses it outright (BROWSER_DOWNLOAD_DISABLED). Saving a screenshot goes through the same directory gate and is not covered by this switch.",
204
191
  "actions.allowCredentialWrite": "Write login state",
205
- "actions.allowCredentialWrite.hint": "dsh_browser_auth's restore writes cookies to arbitrary domains. Off allows export but not import (BROWSER_AUTH_WRITE_DISABLED); reading stays under the Credentials switch above.",
206
- "remoteView.title": "Remote viewing",
207
- "remoteView.enabled": "Let other devices watch this machine's browser",
208
- "remoteView.enabled.hint": "On, a read-only view appears in the bottom-right corner here: 2 fps, JPEG, one frame per request, and no forwarding of clicks or keys. The change applies **immediately** — no page reload needed. Off, the entry disappears and the endpoints return no image.",
192
+ "actions.allowCredentialWrite.hint": "Write cookies to any domain.",
193
+ "remoteView.enabled": "Allow remote viewing",
194
+ "remoteView.enabled.hint": "Shares a read-only view that may contain sensitive information.",
209
195
  "readiness.title": "Readiness",
210
- "readiness.lead": "The \"it works once you install it\" check: the bundled browser downloads its runtime in the background before its first use, the sidebar needs the bridge installed into the desktop app, and an installed Chrome / Edge has to be installed.",
211
196
  "readiness.loading": "Checking…",
212
197
  "readiness.failed": "Could not read readiness:",
213
- "readiness.channel": "Carrier",
198
+ "readiness.channel": "Configured carrier",
199
+ "readiness.details": "Diagnostics",
214
200
  "readiness.electron": "Bundled browser runtime",
215
201
  "readiness.bridge": "Desktop sidebar bridge",
216
202
  "readiness.recheck": "Check again",
217
203
  "readiness.prepare": "Prepare the bundled browser",
218
204
  "readiness.preparing": "Preparing…",
219
- "readiness.fix": "Repair command (run it once in a terminal):",
205
+ "readiness.fix": "Repair command",
220
206
  "readiness.carrier.sidebar": "Desktop sidebar",
221
207
  "readiness.carrier.bundled": "Bundled Electron",
222
208
  "readiness.carrier.system": "Installed Chrome / Edge",
@@ -224,9 +210,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
224
210
  "readiness.state.ready": "Ready",
225
211
  "readiness.state.blocked": "Not ready yet",
226
212
  "readiness.state.unknown": "Only a real launch can tell",
227
- "readiness.electron.present": "Ready (a runtime is already on this machine)",
228
- "readiness.electron.ready": "Ready (just prepared)",
229
- "readiness.electron.preparing": "Downloading the runtime (first time, about 1–3 minutes)",
213
+ "readiness.electron.present": "Ready",
214
+ "readiness.electron.ready": "Ready",
215
+ "readiness.electron.preparing": "Downloading",
230
216
  "readiness.electron.idle": "Not prepared yet",
231
217
  "readiness.electron.skipped": "Skipped (ELECTRON_SKIP_BINARY_DOWNLOAD is set)",
232
218
  "readiness.electron.failed": "Preparation failed",
@@ -236,10 +222,14 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
236
222
  "readiness.bridge.missing": "Not installed",
237
223
  "readiness.bridge.stale": "Stale (a desktop update needs a reinstall)",
238
224
  "readiness.bridge.absent": "No desktop install on this machine",
239
- "readiness.hint.sidebar": "The sidebar carrier puts the page in the right pane of the DSH window, one page for both parties; it needs the desktop's bridge, and it renders only the conversation being **displayed**.",
240
- "readiness.hint.bundled": "The bundled browser ships with the plugin and needs nothing installed; its runtime is downloaded before first use — meanwhile the desktop sidebar or an installed Chrome / Edge works.",
241
- "readiness.hint.system": "An installed browser was chosen: the plugin launches it with its own separate profile, so there is nothing to prepare.",
242
- "readiness.hint.auto": "Automatic: whichever of the bundled runtime and the desktop sidebar works first.",
225
+ "delivery.title": "Delivery",
226
+ "delivery.tool": "Tool that takes the download (MCP tool name; empty = local only)",
227
+ "delivery.args": "Argument template (JSON)",
228
+ "delivery.args.hint": "Placeholders: {path} {name} {size}.",
229
+ "delivery.onFail": "When the remote side fails",
230
+ "delivery.onFail.keep": "Keep the local file and report both outcomes",
231
+ "delivery.onFail.stop": "Treat it as a failure",
232
+ "delivery.sites": "Per-site override (one host=tool per line)",
243
233
  }
244
234
 
245
235
  /**
@@ -277,6 +267,78 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
277
267
  * under a third-party theme, and an unstyled row is worse than a slightly-off one.
278
268
  */
279
269
  const CSS = `
270
+ .dsh-bb-settings .dsh-bb-row {
271
+ min-height: 36px;
272
+ align-items: center;
273
+ justify-content: space-between;
274
+ padding: 8px 0;
275
+ border-bottom: .5px solid var(--dsw-alias-border-l2, GrayText);
276
+ border-radius: 0;
277
+ background: transparent;
278
+ }
279
+ .dsh-bb-settings { font-size: 14px; line-height: 22px; }
280
+ .dsh-bb-settings .dsh-bb-diagnostics { margin-top: 4px; }
281
+ .dsh-bb-diagnostics code { display: block; }
282
+ .dsh-bb-toggle { justify-content: space-between; cursor: pointer; }
283
+ .dsh-bb-toggle:has(:disabled) { cursor: default; }
284
+ .dsh-bb-switch {
285
+ appearance: none;
286
+ position: relative;
287
+ flex: 0 0 36px;
288
+ width: 36px;
289
+ height: 20px;
290
+ margin: 0;
291
+ box-sizing: border-box;
292
+ border: 0;
293
+ border-radius: 999px;
294
+ corner-shape: round;
295
+ background: var(--dsw-alias-border-l3, GrayText);
296
+ color: var(--dsw-alias-switch-thumb, Canvas);
297
+ cursor: inherit;
298
+ }
299
+ .dsh-bb-switch::after {
300
+ content: "";
301
+ position: absolute;
302
+ inset: 2px auto auto 2px;
303
+ width: 16px;
304
+ height: 16px;
305
+ border-radius: 50%;
306
+ corner-shape: round;
307
+ background: currentColor;
308
+ }
309
+ .dsh-bb-switch:checked {
310
+ background: var(--dsw-alias-brand-primary, Highlight);
311
+ color: var(--dsw-alias-label-primary-foreground, HighlightText);
312
+ }
313
+ .dsh-bb-switch:checked::after { transform: translateX(16px); }
314
+ .dsh-bb-switch:disabled { opacity: .6; }
315
+ .dsh-bb-settings :is(button, input, textarea, select, summary):focus-visible {
316
+ outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, Highlight);
317
+ outline-offset: 2px;
318
+ }
319
+ .dsh-bb-settings summary { cursor: pointer; padding: 5px 0; }
320
+ .dsh-bb-settings .dsh-bb-dd { flex: 0 1 auto; margin: 0; }
321
+ .dsh-bb-settings .dsh-bb-dd-btn {
322
+ min-height: 36px;
323
+ padding: 0 14px;
324
+ border: 0;
325
+ border-radius: var(--dsw-radius-md, 8px);
326
+ background: var(--dsw-alias-bg-module-platform, ButtonFace);
327
+ }
328
+ .dsh-bb-settings .dsh-bb-dd-list { left: auto; right: 0; }
329
+ .dsh-bb-settings .dsh-bb-input {
330
+ box-sizing: border-box;
331
+ width: 100%;
332
+ min-height: 34px;
333
+ padding: 6px 8px;
334
+ border: 1px solid var(--dsw-alias-border, GrayText);
335
+ border-radius: 7px;
336
+ background: var(--dsw-alias-bg-layer-1, Canvas);
337
+ color: var(--dsw-alias-label-primary, CanvasText);
338
+ font: inherit;
339
+ }
340
+ .dsh-bb-settings fieldset { min-inline-size: 0; }
341
+ .dsh-bb-settings textarea { resize: vertical; }
280
342
  .dsh-bb-row {
281
343
  border-radius: 8px;
282
344
  padding: 7px 9px;
@@ -433,18 +495,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
433
495
  }
434
496
 
435
497
  const styles = {
436
- wrap: { display: "flex", flexDirection: "column", gap: "14px", padding: "4px 2px", fontSize: "13px" },
498
+ wrap: { display: "flex", flexDirection: "column", gap: "12px" },
437
499
  lead: { opacity: 0.75, lineHeight: 1.6, margin: 0 },
438
- group: { border: "1px solid rgba(128,128,128,.28)", borderRadius: "8px", padding: "10px 12px" },
439
- groupTitle: { margin: "0 0 8px", fontSize: "13px", fontWeight: 600 },
500
+ group: { minWidth: 0 },
501
+ groupTitle: { margin: "0 0 2px", fontSize: "14px", fontWeight: 600, color: "var(--dsw-alias-label-primary, inherit)" },
440
502
  row: { display: "flex", gap: "10px", alignItems: "flex-start" },
441
- box: { marginTop: "2px" },
442
503
  label: { display: "flex", flexDirection: "column", gap: "2px", cursor: "pointer" },
443
- hint: { opacity: 0.68, lineHeight: 1.5 },
504
+ hint: { color: "var(--dsw-alias-label-tertiary, inherit)", fontSize: "12px", lineHeight: 1.5 },
444
505
  status: { opacity: 0.7, minHeight: "18px" },
445
- error: { color: "#e5534b" },
506
+ error: { color: "var(--dsw-alias-label-error, #c9342c)" },
446
507
  pathLine: { opacity: 0.6, wordBreak: "break-all", lineHeight: 1.5 },
447
- button: { padding: "3px 10px", borderRadius: "6px", border: "1px solid rgba(128,128,128,.4)", background: "transparent", color: "inherit", cursor: "pointer" },
508
+ button: { minHeight: "32px", padding: "5px 12px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.4))", background: "transparent", color: "inherit", font: "inherit", cursor: "pointer" },
448
509
  // Readiness: one headline state, three one-line facts, and at most two buttons. The colours are
449
510
  // the only place this panel states an opinion, which is why they carry no text of their own —
450
511
  // the label next to them is always a locale string.
@@ -455,7 +516,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
455
516
  kv: { display: "grid", gridTemplateColumns: "auto 1fr", gap: "3px 12px", margin: "8px 0 0", fontSize: "12px" },
456
517
  kvKey: { opacity: 0.68 },
457
518
  kvVal: { lineHeight: 1.5 },
458
- mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "rgba(0,0,0,.22)", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
519
+ mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "var(--dsw-alias-bg-layer-2, rgba(0,0,0,.22))", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
459
520
  buttons: { display: "flex", gap: "8px", alignItems: "center", marginTop: "10px", flexWrap: "wrap" },
460
521
  }
461
522
 
@@ -525,14 +586,18 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
525
586
  type: "button",
526
587
  ref: buttonRef,
527
588
  className: "dsh-bb-dd-btn",
589
+ "aria-label": props.label + ": " + (current?.label ?? ""),
528
590
  disabled: props.disabled,
529
591
  "aria-haspopup": "listbox",
530
592
  "aria-expanded": open ? "true" : "false",
593
+ onBlur: event => {
594
+ if (!rootRef.current?.contains(event.relatedTarget)) setOpen(false)
595
+ },
531
596
  onClick: () => { setOpen(o => !o); setActive(-1) },
532
597
  onKeyDown,
533
598
  }, [
534
599
  h("span", { key: "v" }, current === undefined ? "" : current.label),
535
- h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "\\u25be"),
600
+ h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "\u25be"),
536
601
  ]),
537
602
  open ? h("div", {
538
603
  key: "l",
@@ -544,7 +609,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
544
609
  type: "button",
545
610
  className: "dsh-bb-dd-opt",
546
611
  role: "option",
612
+ tabIndex: -1,
547
613
  "aria-selected": option.value === props.value ? "true" : "false",
614
+ onMouseDown: event => event.preventDefault(),
548
615
  "data-active": index === active ? "true" : "false",
549
616
  onMouseEnter: () => setActive(index),
550
617
  onClick: () => commit(index),
@@ -555,19 +622,21 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
555
622
  /** One boolean switch bound to a settings path. */
556
623
  function Toggle(props) {
557
624
  const t = translate
558
- return h("div", { style: styles.row, className: "dsh-bb-row" }, [
625
+ return h("label", { style: styles.row, className: "dsh-bb-row dsh-bb-toggle" }, [
626
+ h("span", { key: "l", style: styles.label }, [
627
+ h("span", { key: "t" }, t(props.labelKey)),
628
+ props.hintKey ? h("span", { key: "h", style: styles.hint }, t(props.hintKey)) : null,
629
+ ]),
559
630
  h("input", {
560
631
  key: "i",
561
632
  type: "checkbox",
562
- style: styles.box,
633
+ className: "dsh-bb-switch",
634
+ role: "switch",
635
+ "aria-label": t(props.labelKey),
563
636
  checked: props.checked,
564
637
  disabled: props.busy,
565
638
  onChange: event => props.onChange(event.target.checked),
566
639
  }),
567
- h("label", { key: "l", style: styles.label, onClick: () => props.onChange(!props.checked) }, [
568
- h("span", { key: "t" }, t(props.labelKey)),
569
- h("span", { key: "h", style: styles.hint }, t(props.hintKey)),
570
- ]),
571
640
  ])
572
641
  }
573
642
 
@@ -601,7 +670,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
601
670
  * same one background attempt the plugin makes on its own, which is why pressing it is never
602
671
  * harmful and never starts a second download.
603
672
  */
604
- function Readiness() {
673
+ function Readiness({ channel } = {}) {
605
674
  useLocaleVersion()
606
675
  const t = translate
607
676
  const [runtime, setRuntime] = useState(null)
@@ -640,7 +709,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
640
709
  alive.current = true
641
710
  void read()
642
711
  return () => { alive.current = false }
643
- }, [read])
712
+ }, [read, channel])
644
713
 
645
714
  // Poll only while a download is running: that is the one state that changes on its own, and a
646
715
  // poll in any other state would be a background request per panel per two seconds forever.
@@ -695,45 +764,95 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
695
764
  ? t("readiness.bridge.installedNotRunning")
696
765
  : t("readiness.bridge.installed")
697
766
 
698
- return h("div", { style: styles.wrap }, [
699
- h("p", { key: "head", style: styles.lead }, [
700
- h("span", { key: "b", style: { ...styles.badge, ...tone } }, t(`readiness.state.${runtime.readiness}`)),
701
- h("span", { key: "s" }, ` ${t(`readiness.hint.${runtime.carrier}`)}`),
702
- ]),
703
- h("div", { key: "kv", style: styles.kv }, [
704
- ...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
705
- ...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
706
- ...row("bridge", t("readiness.bridge"), bridgeLabel),
767
+ return h("div", { style: styles.group }, [
768
+ h("div", { key: "head", className: "dsh-bb-row", style: styles.row }, [
769
+ h("span", { key: "title" }, t("readiness.title")),
770
+ h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, t(`readiness.state.${runtime.readiness}`)),
707
771
  ]),
708
- // The provisioning module's own words: shown only where they add something a state label
709
- // cannot carry (what failed, and why), never as a permanent second copy of the state.
710
- runtime.electron.state === "failed" || runtime.electron.state === "skipped"
711
- ? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail)
712
- : null,
713
- // Same rule for the shell: an installed bridge that is not running needs the sentence that says
714
- // so ("pid 1234 is not running"), not a repair command, because there is nothing to repair.
715
- runtime.bridge.state === "installed" && runtime.bridge.running !== true
716
- ? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail)
717
- : null,
718
- runtime.bridge.command !== undefined && runtime.bridge.state !== "installed"
719
- ? h("div", { key: "cmd" }, [
720
- h("p", { key: "l", style: styles.hint }, t("readiness.fix")),
721
- h("code", { key: "c", style: styles.mono }, runtime.bridge.command),
722
- ])
723
- : null,
724
- h("div", { key: "btns", style: styles.buttons }, [
772
+ h("details", { key: "diagnostics", className: "dsh-bb-diagnostics" }, [
773
+ h("summary", { key: "title", style: styles.hint }, t("readiness.details")),
774
+ h("div", { key: "kv", style: styles.kv }, [
775
+ ...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
776
+ ...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
777
+ ...row("bridge", t("readiness.bridge"), bridgeLabel),
778
+ ]),
779
+ runtime.electron.state === "failed" || runtime.electron.state === "skipped"
780
+ ? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail) : null,
781
+ runtime.bridge.state === "installed" && runtime.bridge.running === false
782
+ ? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail) : null,
783
+ runtime.bridge.command && runtime.bridge.state !== "installed"
784
+ ? h("p", { key: "command", style: styles.hint }, [
785
+ h("span", { key: "label" }, t("readiness.fix")),
786
+ h("code", { key: "value", style: styles.mono }, runtime.bridge.command),
787
+ ]) : null,
725
788
  h("button", {
726
789
  key: "recheck",
727
790
  type: "button",
728
791
  style: styles.button,
729
- disabled: busy,
792
+ disabled: busy || preparing,
730
793
  onClick: () => { void read() },
731
- }, preparing ? t("readiness.preparing") : t("readiness.recheck")),
732
- runtime.canProvision
733
- ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: busy, onClick: () => { void prepare() } }, t("readiness.prepare"))
734
- : null,
735
- error !== "" ? h("span", { key: "e", style: styles.error }, `${t("readiness.failed")} ${error}`) : null,
794
+ }, t("readiness.recheck")),
795
+ ]),
796
+ runtime.canProvision || preparing
797
+ ? h("div", { key: "buttons", style: styles.buttons }, [
798
+ preparing ? h("span", { key: "progress", role: "status", style: styles.hint }, t("readiness.preparing")) : null,
799
+ runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: busy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
800
+ ]) : null,
801
+ error !== "" ? h("p", { key: "error", role: "alert", style: styles.error }, t("readiness.failed") + " " + error) : null,
802
+ ])
803
+ }
804
+
805
+ /** Save the delivery fields together so moving focus never writes a partial template. */
806
+ function DeliverySettings({ delivery, busy, onSave }) {
807
+ const t = translate
808
+ const [invalid, setInvalid] = useState(false)
809
+ const toolPattern = /^[A-Za-z0-9_.-]+$/
810
+ const submit = event => {
811
+ event.preventDefault()
812
+ const fields = event.currentTarget.elements
813
+ const tool = fields.namedItem("tool").value.trim()
814
+ const onFail = fields.namedItem("onFail").value
815
+ const rules = fields.namedItem("sites").value.split("\n").filter(line => line.trim() !== "")
816
+ const entries = rules.map(line => line.split("=").map(value => value.trim()))
817
+ let args
818
+ try {
819
+ args = JSON.parse(fields.namedItem("args").value)
820
+ } catch {
821
+ setInvalid(true)
822
+ return
823
+ }
824
+ if ((tool !== "" && !toolPattern.test(tool))
825
+ || args === null || typeof args !== "object" || Array.isArray(args)
826
+ || Object.values(args).some(value => typeof value !== "string")
827
+ || entries.some(entry => entry.length !== 2 || !/^[A-Za-z0-9.-]+$/.test(entry[0]) || !toolPattern.test(entry[1]))) {
828
+ setInvalid(true)
829
+ return
830
+ }
831
+ const sites = Object.fromEntries(entries.map(([host, name]) => [host.toLowerCase(), name]))
832
+ if (Object.keys(sites).length !== entries.length) {
833
+ setInvalid(true)
834
+ return
835
+ }
836
+ setInvalid(false)
837
+ onSave({ tool, args, onFail, sites })
838
+ }
839
+ const field = (name, control) => h("label", { key: name, style: styles.label }, [
840
+ h("span", { key: "label" }, t("delivery." + name)),
841
+ control,
842
+ name === "args" ? h("span", { key: "hint", style: styles.hint }, t("delivery.args.hint")) : null,
843
+ ])
844
+ return h("form", { onSubmit: submit }, [
845
+ h("fieldset", { key: "fields", disabled: busy, style: { border: 0, margin: 0, padding: 0, display: "grid", gap: "10px" } }, [
846
+ field("tool", h("input", { key: "control", name: "tool", className: "dsh-bb-input", defaultValue: delivery?.tool ?? "", placeholder: "lark_drive_upload" })),
847
+ field("args", h("textarea", { key: "control", name: "args", className: "dsh-bb-input", rows: 3, defaultValue: JSON.stringify(delivery?.args ?? { file_path: "{path}" }, null, 2) })),
848
+ field("onFail", h("select", { key: "control", name: "onFail", className: "dsh-bb-input", defaultValue: delivery?.onFail ?? "keep-local" }, [
849
+ h("option", { key: "keep", value: "keep-local" }, t("delivery.onFail.keep")),
850
+ h("option", { key: "stop", value: "stop" }, t("delivery.onFail.stop")),
851
+ ])),
852
+ field("sites", h("textarea", { key: "control", name: "sites", className: "dsh-bb-input", rows: 3, defaultValue: Object.entries(delivery?.sites ?? {}).map(([host, tool]) => host + "=" + tool).join("\n") })),
853
+ h("div", { key: "actions" }, h("button", { type: "submit", style: styles.button }, t("delivery.save"))),
736
854
  ]),
855
+ invalid ? h("p", { key: "error", role: "alert", style: styles.error }, t("delivery.invalid")) : null,
737
856
  ])
738
857
  }
739
858
 
@@ -746,6 +865,8 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
746
865
  const [error, setError] = useState("")
747
866
  const [busy, setBusy] = useState(false)
748
867
  const [saved, setSaved] = useState(false)
868
+ const saving = useRef(false)
869
+ const savedTimer = useRef(null)
749
870
 
750
871
  const load = useCallback(() => {
751
872
  setError("")
@@ -756,22 +877,31 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
756
877
  }, [])
757
878
 
758
879
  useEffect(() => { load() }, [load])
880
+ useEffect(() => () => clearTimeout(savedTimer.current), [])
759
881
 
760
882
  const patch = useCallback(next => {
883
+ if (saving.current) return
884
+ saving.current = true
885
+ clearTimeout(savedTimer.current)
886
+ setSaved(false)
761
887
  setBusy(true)
762
888
  setError("")
763
889
  callSettings(next).then(data => {
764
890
  setSettings(data.settings)
765
891
  setSaved(true)
766
- setTimeout(() => setSaved(false), 1200)
892
+ savedTimer.current = setTimeout(() => setSaved(false), 1800)
767
893
  }).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
768
- .then(() => setBusy(false))
894
+ .finally(() => {
895
+ saving.current = false
896
+ setBusy(false)
897
+ })
769
898
  }, [])
770
899
 
771
900
  if (rawSettings === null) {
772
901
  return h("div", { style: styles.wrap }, [
773
- h("p", { key: "l", style: styles.lead }, t("loading")),
902
+ error === "" ? h("p", { key: "l", role: "status", style: styles.lead }, t("loading")) : null,
774
903
  error !== "" ? h("p", { key: "e", style: styles.error }, `${t("failed")} ${error}`) : null,
904
+ error !== "" ? h("button", { key: "retry", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
775
905
  ])
776
906
  }
777
907
 
@@ -785,181 +915,76 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
785
915
  ? { ...rawSettings, actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true } }
786
916
  : rawSettings
787
917
 
788
- const section = (titleKey, children) => h("div", { key: titleKey, style: styles.group }, [
789
- h("p", { key: "t", style: styles.groupTitle }, t(titleKey)),
918
+ const toggle = (group, key, labelKey = group + "." + key, hintKey) => h(Toggle, {
919
+ key,
920
+ labelKey,
921
+ hintKey,
922
+ checked: settings[group]?.[key] ?? (group === "cookies" && key === "persist"),
923
+ busy,
924
+ onChange: value => patch({ [group]: { [key]: value } }),
925
+ })
926
+ const selector = (labelKey, value, options, onChange, hintKey) => h("div", {
927
+ key: labelKey,
928
+ className: "dsh-bb-row",
929
+ style: styles.row,
930
+ }, [
931
+ h("span", { key: "text", style: styles.label }, [
932
+ h("span", { key: "label" }, t(labelKey)),
933
+ hintKey ? h("span", { key: "hint", style: styles.hint }, t(hintKey)) : null,
934
+ ]),
935
+ h(Dropdown, { key: "select", label: t(labelKey), value, options, disabled: busy, onChange }),
936
+ ])
937
+ const options = (prefix, values) => values.map(value => ({ value, label: t(prefix + value) }))
938
+ const section = (titleKey, children) => h("section", { key: titleKey, style: styles.group }, [
939
+ h("h3", { key: "title", style: styles.groupTitle }, t(titleKey)),
790
940
  ...children,
791
941
  ])
942
+ const systemBrowser = settings.browser.channel === "chrome" || settings.browser.channel === "edge"
792
943
 
793
- return h("div", { style: styles.wrap }, [
794
- h("p", { key: "lead", style: styles.lead }, t("lead")),
795
-
796
- // First, because it answers the question a fresh install raises before any switch matters:
797
- // can this thing open a page right now, and if not, what is it waiting for.
798
- section("readiness.title", [
799
- h("p", { key: "lead", style: styles.hint }, t("readiness.lead")),
800
- h(Readiness, { key: "r" }),
801
- ]),
802
-
803
- section("history.title", [
804
- h(Toggle, {
805
- key: "enabled",
806
- labelKey: "history.enabled",
807
- hintKey: "history.hint",
808
- checked: settings.history.enabled,
809
- busy,
810
- onChange: value => patch({ history: { enabled: value } }),
811
- }),
812
- ]),
813
-
814
- section("cookies.title", [
815
- h(Toggle, {
816
- key: "persist",
817
- labelKey: "cookies.persist",
818
- hintKey: "cookies.hint",
819
- checked: settings.cookies.persist,
820
- busy,
821
- onChange: value => patch({ cookies: { persist: value } }),
822
- }),
823
- ]),
824
-
944
+ return h("div", { style: styles.wrap, className: "dsh-bb-settings" }, [
945
+ selector("browser.channel", settings.browser.channel,
946
+ options("browser.", ["bundled", "sidebar", "auto", "chrome", "edge"]),
947
+ channel => patch({ browser: { channel } })),
948
+ h(Readiness, { key: "readiness", channel: settings.browser.channel }),
825
949
  section("ui.title", [
826
- h(Toggle, {
827
- key: "autoExpandOnce",
828
- labelKey: "ui.autoExpandOnce",
829
- hintKey: "ui.autoExpandOnce.hint",
830
- checked: settings.ui.autoExpandOnce,
831
- busy,
832
- onChange: value => patch({ ui: { autoExpandOnce: value } }),
833
- }),
834
- h(Toggle, {
835
- key: "closeWithSession",
836
- labelKey: "ui.closeWithSession",
837
- hintKey: "ui.closeWithSession.hint",
838
- checked: settings.ui.closeWithSession,
839
- busy,
840
- onChange: value => patch({ ui: { closeWithSession: value } }),
841
- }),
842
- h(Toggle, {
843
- key: "virtualCursor",
844
- labelKey: "ui.virtualCursor",
845
- hintKey: "ui.virtualCursor.hint",
846
- checked: settings.ui.virtualCursor,
847
- busy,
848
- onChange: value => patch({ ui: { virtualCursor: value } }),
849
- }),
850
- h(Toggle, {
851
- key: "quiet",
852
- labelKey: "ui.quiet",
853
- hintKey: "ui.quiet.hint",
854
- checked: settings.ui.quiet,
855
- busy,
856
- onChange: value => patch({ ui: { quiet: value } }),
857
- }),
950
+ toggle("ui", "quiet", "ui.quiet", "ui.quiet.hint"),
951
+ toggle("ui", "autoExpandOnce"),
952
+ toggle("ui", "closeWithSession"),
953
+ toggle("ui", "virtualCursor"),
954
+ toggle("remoteView", "enabled", "remoteView.enabled", "remoteView.enabled.hint"),
858
955
  ]),
859
-
860
- section("vision.title", [
861
- h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
862
- h("label", { key: "l", style: styles.label }, [
863
- h("span", { key: "t" }, t("vision.strategy")),
864
- h(Dropdown, {
865
- key: "s",
866
- label: t("vision.strategy"),
867
- value: settings.vision.strategy,
868
- disabled: busy,
869
- onChange: value => patch({ vision: { strategy: value } }),
870
- options: [
871
- { value: "auto", label: t("vision.auto") },
872
- { value: "nonVisual", label: t("vision.nonVisual") },
873
- ],
874
- }),
875
- h("span", { key: "h", style: styles.hint }, t("vision.hint")),
876
- ]),
877
- ]),
878
- ]),
879
-
880
- section("browser.title", [
881
- h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
882
- h("label", { key: "l", style: styles.label }, [
883
- h("span", { key: "t" }, t("browser.channel")),
884
- h(Dropdown, {
885
- key: "s",
886
- label: t("browser.channel"),
887
- value: settings.browser.channel,
888
- disabled: busy,
889
- onChange: value => patch({ browser: { channel: value } }),
890
- options: [
891
- { value: "sidebar", label: t("browser.sidebar") },
892
- { value: "bundled", label: t("browser.bundled") },
893
- { value: "auto", label: t("browser.auto") },
894
- { value: "chrome", label: t("browser.chrome") },
895
- { value: "edge", label: t("browser.edge") },
896
- ],
897
- }),
898
- h("span", { key: "h", style: styles.hint }, t("browser.hint")),
899
- ]),
900
- ]),
901
- ]),
902
-
903
956
  section("actions.title", [
904
- h("p", { key: "lead", style: styles.hint }, t("actions.lead")),
905
- h(Toggle, {
906
- key: "allowExecute",
907
- labelKey: "actions.allowExecute",
908
- hintKey: "actions.allowExecute.hint",
909
- checked: settings.actions.allowExecute,
910
- busy,
911
- onChange: value => patch({ actions: { allowExecute: value } }),
912
- }),
913
- h(Toggle, {
914
- key: "allowDownload",
915
- labelKey: "actions.allowDownload",
916
- hintKey: "actions.allowDownload.hint",
917
- checked: settings.actions.allowDownload,
918
- busy,
919
- onChange: value => patch({ actions: { allowDownload: value } }),
920
- }),
921
- h(Toggle, {
922
- key: "allowCredentialWrite",
923
- labelKey: "actions.allowCredentialWrite",
924
- hintKey: "actions.allowCredentialWrite.hint",
925
- checked: settings.actions.allowCredentialWrite,
926
- busy,
927
- onChange: value => patch({ actions: { allowCredentialWrite: value } }),
928
- }),
929
- ]),
930
-
931
- section("credentials.title", [
932
- h(Toggle, {
933
- key: "allowRead",
934
- labelKey: "credentials.allowRead",
935
- hintKey: "credentials.hint",
936
- checked: settings.credentials.allowRead,
937
- busy,
938
- onChange: value => patch({ credentials: { allowRead: value } }),
939
- }),
957
+ toggle("actions", "allowExecute"),
958
+ toggle("actions", "allowDownload"),
959
+ toggle("credentials", "allowRead"),
960
+ toggle("actions", "allowCredentialWrite", "actions.allowCredentialWrite", "actions.allowCredentialWrite.hint"),
940
961
  ]),
941
-
942
- // Reported on #46: turning remote viewing on had to be done by editing the settings file and
943
- // reloading the page — and a phone has no keyboard shortcut to reload with. The switch belongs
944
- // here, and flipping it applies immediately (see `callSettings`).
945
- section("remoteView.title", [
946
- h(Toggle, {
947
- key: "remoteViewEnabled",
948
- labelKey: "remoteView.enabled",
949
- hintKey: "remoteView.enabled.hint",
950
- checked: settings.remoteView.enabled,
951
- busy,
952
- onChange: value => patch({ remoteView: { enabled: value } }),
953
- }),
962
+ h("details", { key: "advanced", style: styles.group }, [
963
+ h("summary", { key: "title", style: styles.groupTitle }, t("settings.advanced")),
964
+ toggle("history", "enabled"),
965
+ selector("vision.strategy", settings.vision.strategy, [
966
+ { value: "auto", label: t("vision.auto") },
967
+ { value: "nonVisual", label: t("vision.nonVisual") },
968
+ ], strategy => patch({ vision: { strategy } })),
969
+ systemBrowser ? toggle("cookies", "persist", "browser.profile") : null,
970
+ systemBrowser ? selector("browser.headless", settings.browser.headless ?? "auto",
971
+ options("browser.headless.", ["auto", "windowed", "headless"]),
972
+ headless => patch({ browser: { headless } }), "browser.headless.hint") : null,
973
+ settings.delivery ? section("delivery.title", [
974
+ h(DeliverySettings, {
975
+ key: JSON.stringify(settings.delivery),
976
+ delivery: settings.delivery,
977
+ busy,
978
+ onSave: delivery => patch({ delivery }),
979
+ }),
980
+ ]) : null,
981
+ meta.path !== "" ? h("p", { key: "path", style: styles.pathLine }, t("settings.details") + " · " + meta.path) : null,
954
982
  ]),
955
-
956
- h("div", { key: "status", style: styles.status }, [
957
- saved ? h("span", { key: "s" }, t("saved")) : null,
983
+ h("div", { key: "status", style: styles.status, role: "status" }, [
984
+ busy || saved ? h("span", { key: "s" }, t(busy ? "settings.saving" : "saved")) : null,
958
985
  error !== "" ? h("span", { key: "e", style: styles.error }, ` ${t("failed")} ${error} `) : null,
959
- error !== "" ? h("button", { key: "r", style: styles.button, onClick: load }, t("retry")) : null,
986
+ error !== "" ? h("button", { key: "r", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
960
987
  ]),
961
-
962
- meta.path !== "" ? h("div", { key: "path", style: styles.pathLine }, `${t("path")}: ${meta.path}`) : null,
963
988
  ])
964
989
  }
965
990
 
@@ -1070,10 +1095,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1070
1095
  }
1071
1096
 
1072
1097
  /** Read this conversation's current guest, preferring the one actually drawn. */
1073
- function guestStateFor(sessionId) {
1098
+ function guestStateFor(sessionId, tabId) {
1074
1099
  const roots = panelRootsFor(sessionId)
1075
1100
  if (roots === undefined ? tabStripFor(sessionId) === null : roots.length === 0) return { panel: false, guestId: null, url: "" }
1076
- const guests = guestsInPanel(sessionId)
1101
+ const guests = guestsInPanel(sessionId).filter(view => tabId === undefined
1102
+ || tabIdOfElement(view, new Set([tabId]), roots) === tabId)
1077
1103
  if (guests.length === 0) return { panel: true, guestId: null, url: "" }
1078
1104
  // A sidebar keeps every tab mounted (`keepMounted`), so a background tab's guest is
1079
1105
  // in the tree too. Prefer the one with a drawn box; fall back to the newest.
@@ -1125,6 +1151,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1125
1151
  */
1126
1152
  function installPanelService(ctx) {
1127
1153
  let sidebarRight = null
1154
+ const pendingTabs = new Map()
1128
1155
  /** The shell's own navigation service: `openSession` is how it is asked to DISPLAY a conversation. */
1129
1156
  let uiWorkspace = null
1130
1157
  // `inject` is how a client plugin waits for a service to appear. A host that does not offer it
@@ -1134,9 +1161,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1134
1161
  // with it, which is exactly the shape of regression this file has been bitten by before.
1135
1162
  if (typeof ctx.inject === "function") {
1136
1163
  ctx.inject(["sidebarRight"], (scope) => {
1164
+ if (sidebarRight !== scope.sidebarRight) pendingTabs.clear()
1137
1165
  sidebarRight = scope.sidebarRight
1138
1166
  scope.effect(() => () => {
1139
- if (sidebarRight === scope.sidebarRight) sidebarRight = null
1167
+ if (sidebarRight === scope.sidebarRight) {
1168
+ sidebarRight = null
1169
+ pendingTabs.clear()
1170
+ }
1140
1171
  }, "dsh-builtin-browser: conversation panel binding")
1141
1172
  })
1142
1173
  // A separate inject, deliberately: waiting for both services in one call would take the
@@ -1224,7 +1255,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1224
1255
  * @returns what was asked for, so a caller can tell "expanded" from "already visible", and
1225
1256
  * `displayed` so it can tell "the shell is showing this conversation" from "it is not".
1226
1257
  */
1227
- function revealPlacedPanel(sessionId, state) {
1258
+ function revealPlacedPanel(sessionId, state, tabId) {
1228
1259
  if (state.guestId !== null || sidebarRight === null) return {}
1229
1260
  const done = {}
1230
1261
  // Which conversation is the shell DISPLAYING? `screen()` answers it, and it is the question
@@ -1262,7 +1293,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1262
1293
  }
1263
1294
  try {
1264
1295
  const tabs = typeof sidebarRight.tabsIn === "function" ? sidebarRight.tabsIn(sessionId) : []
1265
- const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser") : undefined
1296
+ const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser" && entry.id === tabId) : undefined
1266
1297
  if (page !== undefined && typeof sidebarRight.focus === "function") {
1267
1298
  sidebarRight.focus(page.id)
1268
1299
  done.focused = String(page.id)
@@ -1283,7 +1314,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1283
1314
  if (sidebarRight === null || typeof sidebarRight.openTabIn !== "function") {
1284
1315
  return { ok: false, reason: "the shell's sidebar service is not available", panel: false, guestId: null }
1285
1316
  }
1286
- const state = guestStateFor(wanted)
1317
+ const address = url ? String(url) : ""
1318
+ const pending = pendingTabs.get(wanted)
1319
+ const state = guestStateFor(wanted, pending?.url === address && pending.scoped ? pending.id : undefined)
1287
1320
  if (state.guestId !== null) {
1288
1321
  return { ok: true, created: false, panel: true, guestId: state.guestId, url: state.url }
1289
1322
  }
@@ -1303,15 +1336,37 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1303
1336
  // (a public method) is what says whether it actually landed: `openTabIn` SILENTLY ignores a
1304
1337
  // conversation whose store was never minted, and a silent no-op must never be reported as
1305
1338
  // success.
1306
- let before = 0
1307
- try { before = sidebarRight.tabsIn(wanted).length } catch (error) { before = 0 }
1308
- try {
1309
- sidebarRight.openTabIn(wanted, "browser", url ? { params: { url: String(url) } } : {})
1310
- } catch (error) {
1311
- return { ok: false, reason: String((error && error.message) || error), panel: state.panel, guestId: null }
1339
+ let beforeTabs = []
1340
+ try { beforeTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
1341
+ const before = beforeTabs.length
1342
+ const beforeIds = new Set(beforeTabs.map(tab => tab.id))
1343
+ const remembered = pending?.url === address
1344
+ ? beforeTabs.find(tab => tab.kind === "browser" && tab.id === pending.id)
1345
+ : undefined
1346
+ if (remembered === undefined) {
1347
+ try {
1348
+ sidebarRight.openTabIn(wanted, "browser", address ? { params: { url: address } } : {})
1349
+ } catch (error) {
1350
+ return { ok: false, reason: String((error && error.message) || error), panel: state.panel, guestId: null }
1351
+ }
1352
+ }
1353
+ let placedTabs = beforeTabs
1354
+ try { placedTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
1355
+ const placed = placedTabs.length
1356
+ const browserTabs = placedTabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser")
1357
+ const added = browserTabs.filter(tab => !beforeIds.has(tab.id))
1358
+ const matching = browserTabs.filter(tab => address !== "" && (tab.params?.url === address || tab.url === address))
1359
+ // Multiple browser tabs use separate ids. Correlate this placement before revealing it.
1360
+ // Older shells deduplicate the browser kind, so their sole browser is unambiguous.
1361
+ const page = remembered
1362
+ ?? (added.length === 1 ? added[0] : undefined)
1363
+ ?? (matching.length === 1 ? matching[0] : undefined)
1364
+ ?? (browserTabs.length === 1 ? browserTabs[0] : undefined)
1365
+ const scoped = browserTabs.length > 1 || panelRootsFor(wanted) !== undefined
1366
+ if (page !== undefined) pendingTabs.set(wanted, { id: page.id, url: address, scoped })
1367
+ if (page === undefined && browserTabs.length > 1) {
1368
+ return { ok: false, reason: "the shell did not identify which browser tab was placed", panel: state.panel, guestId: null }
1312
1369
  }
1313
- let placed = 0
1314
- try { placed = sidebarRight.tabsIn(wanted).length } catch (error) { placed = before }
1315
1370
  // `openTabIn` DEDUPLICATES, so "the count grew" is the wrong test for "is this
1316
1371
  // conversation's surface mounted".
1317
1372
  //
@@ -1346,20 +1401,24 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
1346
1401
  // Placing is not showing: ask the shell to expand the column and focus that tab, so the
1347
1402
  // body (and with it the `<webview>`) actually gets created. Without this the caller polls
1348
1403
  // a panel that can never answer, which is exactly what "produced no page" used to mean.
1349
- const revealed = revealPlacedPanel(wanted, state)
1404
+ const revealed = revealPlacedPanel(wanted, state, page?.id)
1350
1405
  return {
1351
1406
  ok: true,
1352
1407
  created: placed > before,
1353
1408
  panel: state.panel,
1354
1409
  guestId: null,
1355
1410
  tabs: placed,
1411
+ ...page === undefined || !scoped ? {} : { tabId: String(page.id) },
1356
1412
  ...switched ? { switched: true } : {},
1357
1413
  ...revealed,
1358
1414
  }
1359
1415
  },
1360
1416
  /** Read-only: this conversation's current guest, if it has one. */
1361
- panelGuest(sessionId) {
1362
- return guestStateFor(typeof sessionId === "string" ? sessionId : "")
1417
+ panelGuest(sessionId, tabId) {
1418
+ return guestStateFor(
1419
+ typeof sessionId === "string" ? sessionId : "",
1420
+ typeof tabId === "string" && tabId !== "" ? tabId : undefined,
1421
+ )
1363
1422
  },
1364
1423
  /** All guest ids verified inside this conversation, including shell-created popup tabs. */
1365
1424
  panelGuests(sessionId) {